// Code generated for windows/386 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 -DHAVE_USLEEP -DLONGDOUBLE_TYPE=double -DNDEBUG -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_ENABLE_COLUMN_METADATA -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 -Dpread64=pread -Dpwrite64=pwrite -I /home/jnml/src/modernc.org/libz/include/windows/386 -I /home/jnml/src/modernc.org/libtcl8.6/include/windows/386 -extended-errors -o sqlite3.go sqlite3.c --cpp /usr/bin/i686-w64-mingw32-gcc --goarch 386 --goos windows -DSQLITE_HAVE_C99_MATH_FUNCS=(1) -DSQLITE_OS_WIN=1 -DSQLITE_OMIT_SEH -map gcc=i686-w64-mingw32-gcc -eval-all-macros', DO NOT EDIT.

//go:build windows && 386

package sqlite3

import (
	"reflect"
	"unsafe"

	"modernc.org/libc"
)

var (
	_ reflect.Type
	_ unsafe.Pointer
)

const ABE_BOTTOM = 3
const ABE_LEFT = 0
const ABE_RIGHT = 2
const ABE_TOP = 1
const ABM_ACTIVATE = 6
const ABM_GETAUTOHIDEBAR = 7
const ABM_GETAUTOHIDEBAREX = 11
const ABM_GETSTATE = 4
const ABM_GETTASKBARPOS = 5
const ABM_NEW = 0
const ABM_QUERYPOS = 2
const ABM_REMOVE = 1
const ABM_SETAUTOHIDEBAR = 8
const ABM_SETAUTOHIDEBAREX = 12
const ABM_SETPOS = 3
const ABM_SETSTATE = 10
const ABM_WINDOWPOSCHANGED = 9
const ABN_FULLSCREENAPP = 2
const ABN_POSCHANGED = 1
const ABN_STATECHANGE = 0
const ABN_WINDOWARRANGE = 3
const ABORTDOC = 2
const ABOVE_NORMAL_PRIORITY_CLASS = 32768
const ABSOLUTE = 1
const ABS_ALWAYSONTOP = 2
const ABS_AUTOHIDE = 1
const ACCESS_ALLOWED_ACE_TYPE = 0
const ACCESS_ALLOWED_CALLBACK_ACE_TYPE = 9
const ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = 11
const ACCESS_ALLOWED_COMPOUND_ACE_TYPE = 4
const ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5
const ACCESS_DENIED_ACE_TYPE = 1
const ACCESS_DENIED_CALLBACK_ACE_TYPE = 10
const ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = 12
const ACCESS_DENIED_OBJECT_ACE_TYPE = 6
const ACCESS_DS_OBJECT_TYPE_NAME_A = "Directory Service Object"
const ACCESS_DS_OBJECT_TYPE_NAME_W = "Directory Service Object"
const ACCESS_DS_SOURCE_A = "DS"
const ACCESS_DS_SOURCE_W = "DS"
const ACCESS_FILTERKEYS = 2
const ACCESS_MAX_LEVEL = 4
const ACCESS_MAX_MS_ACE_TYPE = 8
const ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8
const ACCESS_MAX_MS_V2_ACE_TYPE = 3
const ACCESS_MAX_MS_V3_ACE_TYPE = 4
const ACCESS_MAX_MS_V4_ACE_TYPE = 8
const ACCESS_MAX_MS_V5_ACE_TYPE = 19
const ACCESS_MIN_MS_ACE_TYPE = 0
const ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5
const ACCESS_MOUSEKEYS = 3
const ACCESS_OBJECT_GUID = 0
const ACCESS_PROPERTY_GUID = 2
const ACCESS_PROPERTY_SET_GUID = 1
const ACCESS_REASON_DATA_MASK = 65535
const ACCESS_REASON_EXDATA_MASK = 2130706432
const ACCESS_REASON_STAGING_MASK = 2147483648
const ACCESS_REASON_TYPE_MASK = 16711680
const ACCESS_STICKYKEYS = 1
const ACCESS_SYSTEM_SECURITY = 16777216
const ACE_INHERITED_OBJECT_TYPE_PRESENT = 2
const ACE_OBJECT_TYPE_PRESENT = 1
const ACL_REVISION = 2
const ACL_REVISION1 = 1
const ACL_REVISION2 = 2
const ACL_REVISION3 = 3
const ACL_REVISION4 = 4
const ACL_REVISION_DS = 4
const ACPI_PPM_HARDWARE_ALL = 254
const ACPI_PPM_SOFTWARE_ALL = 252
const ACPI_PPM_SOFTWARE_ANY = 253
const ACTCTX_FLAG_APPLICATION_NAME_VALID = 32
const ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID = 4
const ACTCTX_FLAG_HMODULE_VALID = 128
const ACTCTX_FLAG_LANGID_VALID = 2
const ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID = 1
const ACTCTX_FLAG_RESOURCE_NAME_VALID = 8
const ACTCTX_FLAG_SET_PROCESS_DEFAULT = 16
const ACTCTX_FLAG_SOURCE_IS_ASSEMBLYREF = 64
const ACTIVATIONCONTEXTINFOCLASS = 0
const ACTIVATION_CONTEXT_BASIC_INFORMATION_DEFINED = 1
const ACTIVATION_CONTEXT_PATH_TYPE_ASSEMBLYREF = 4
const ACTIVATION_CONTEXT_PATH_TYPE_NONE = 1
const ACTIVATION_CONTEXT_PATH_TYPE_URL = 3
const ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE = 2
const ACTIVATION_CONTEXT_SECTION_APPLICATION_SETTINGS = 10
const ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION = 1
const ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES = 9
const ACTIVATION_CONTEXT_SECTION_COMPATIBILITY_INFO = 11
const ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION = 5
const ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION = 7
const ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION = 4
const ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION = 6
const ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION = 2
const ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE = 8
const ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION = 3
const ACTIVEOBJECT_STRONG = 0
const ACTIVEOBJECT_WEAK = 1
const AC_LINE_BACKUP_POWER = 2
const AC_LINE_OFFLINE = 0
const AC_LINE_ONLINE = 1
const AC_LINE_UNKNOWN = 255
const AC_SRC_ALPHA = 1
const AC_SRC_OVER = 0
const ADDRESS_TAG_BIT = 2147483648
const AD_CLOCKWISE = 2
const AD_COUNTERCLOCKWISE = 1
const AF_APPLETALK = 16
const AF_BAN = 21
const AF_CCITT = 10
const AF_CHAOS = 5
const AF_DATAKIT = 9
const AF_DECnet = 12
const AF_DLI = 13
const AF_ECMA = 8
const AF_FIREFOX = 19
const AF_HYLINK = 15
const AF_IMPLINK = 3
const AF_INET = 2
const AF_IPX = 6
const AF_ISO = 7
const AF_LAT = 14
const AF_MAX = 22
const AF_NETBIOS = 17
const AF_NS = 6
const AF_OSI = 7
const AF_PUP = 4
const AF_SNA = 11
const AF_UNIX = 1
const AF_UNKNOWN1 = 20
const AF_UNSPEC = 0
const AF_VOICEVIEW = 18
const ALERT_SYSTEM_CRITICAL = 5
const ALERT_SYSTEM_ERROR = 3
const ALERT_SYSTEM_INFORMATIONAL = 1
const ALERT_SYSTEM_QUERY = 4
const ALERT_SYSTEM_WARNING = 2
const ALG_CLASS_ALL = 57344
const ALG_CLASS_ANY = 0
const ALG_CLASS_DATA_ENCRYPT = 24576
const ALG_CLASS_HASH = 32768
const ALG_CLASS_KEY_EXCHANGE = 40960
const ALG_CLASS_MSG_ENCRYPT = 16384
const ALG_CLASS_SIGNATURE = 8192
const ALG_SID_3DES = 3
const ALG_SID_3DES_112 = 9
const ALG_SID_AES = 17
const ALG_SID_AES_128 = 14
const ALG_SID_AES_192 = 15
const ALG_SID_AES_256 = 16
const ALG_SID_AGREED_KEY_ANY = 3
const ALG_SID_ANY = 0
const ALG_SID_CAST = 6
const ALG_SID_CYLINK_MEK = 12
const ALG_SID_DES = 1
const ALG_SID_DESX = 4
const ALG_SID_DH_EPHEM = 2
const ALG_SID_DH_SANDF = 1
const ALG_SID_DSS_ANY = 0
const ALG_SID_DSS_DMS = 2
const ALG_SID_DSS_PKCS = 1
const ALG_SID_ECDH = 5
const ALG_SID_ECDH_EPHEM = 6
const ALG_SID_ECDSA = 3
const ALG_SID_ECMQV = 1
const ALG_SID_EXAMPLE = 80
const ALG_SID_HASH_REPLACE_OWF = 11
const ALG_SID_HMAC = 9
const ALG_SID_IDEA = 5
const ALG_SID_KEA = 4
const ALG_SID_MAC = 5
const ALG_SID_MD2 = 1
const ALG_SID_MD4 = 2
const ALG_SID_MD5 = 3
const ALG_SID_PCT1_MASTER = 4
const ALG_SID_RC2 = 2
const ALG_SID_RC4 = 1
const ALG_SID_RC5 = 13
const ALG_SID_RIPEMD = 6
const ALG_SID_RIPEMD160 = 7
const ALG_SID_RSA_ANY = 0
const ALG_SID_RSA_ENTRUST = 3
const ALG_SID_RSA_MSATWORK = 2
const ALG_SID_RSA_PGP = 4
const ALG_SID_RSA_PKCS = 1
const ALG_SID_SAFERSK128 = 8
const ALG_SID_SAFERSK64 = 7
const ALG_SID_SCHANNEL_ENC_KEY = 7
const ALG_SID_SCHANNEL_MAC_KEY = 3
const ALG_SID_SCHANNEL_MASTER_HASH = 2
const ALG_SID_SEAL = 2
const ALG_SID_SHA = 4
const ALG_SID_SHA1 = 4
const ALG_SID_SHA_256 = 12
const ALG_SID_SHA_384 = 13
const ALG_SID_SHA_512 = 14
const ALG_SID_SKIPJACK = 10
const ALG_SID_SSL2_MASTER = 5
const ALG_SID_SSL3SHAMD5 = 8
const ALG_SID_SSL3_MASTER = 1
const ALG_SID_TEK = 11
const ALG_SID_TLS1PRF = 10
const ALG_SID_TLS1_MASTER = 6
const ALG_TYPE_ANY = 0
const ALG_TYPE_BLOCK = 1536
const ALG_TYPE_DH = 2560
const ALG_TYPE_DSS = 512
const ALG_TYPE_ECDH = 3584
const ALG_TYPE_RSA = 1024
const ALG_TYPE_SECURECHANNEL = 3072
const ALG_TYPE_STREAM = 2048
const ALLBITS = -1
const ALL_PROCESSOR_GROUPS = 65535
const ALL_TRANSPORTS = "M\\0\\0\\0"
const ALTERNATE = 1
const ALTNUMPAD_BIT = 67108864
const ANSI_CHARSET = 0
const ANSI_FIXED_FONT = 11
const ANSI_VAR_FONT = 12
const ANTIALIASED_QUALITY = 4
const ANYSIZE_ARRAY = 1
const APD_COPY_ALL_FILES = 4
const APD_COPY_FROM_DIRECTORY = 16
const APD_COPY_NEW_FILES = 8
const APD_STRICT_DOWNGRADE = 2
const APD_STRICT_UPGRADE = 1
const APIENTRY = "WINAPI"
const APIPRIVATE = "__stdcall"
const API_SET_EXTENSION_NAME_A = "EXT-"
const API_SET_EXTENSION_NAME_U = "EXT-"
const API_SET_HELPER_NAME = 0
const API_SET_LOAD_SCHEMA_ORDINAL = 1
const API_SET_LOOKUP_ORDINAL = 2
const API_SET_PREFIX_NAME_A = "API-"
const API_SET_PREFIX_NAME_U = "API-"
const API_SET_RELEASE_SCHEMA_ORDINAL = 3
const API_SET_SCHEMA_NAME = 0
const API_SET_SCHEMA_SUFFIX = ".sys"
const API_SET_SCHEMA_VERSION = 2
const API_SET_SECTION_NAME = ".apiset"
const APPCLASS_MASK = 15
const APPCLASS_MONITOR = 1
const APPCLASS_STANDARD = 0
const APPCMD_CLIENTONLY = 16
const APPCMD_FILTERINITS = 32
const APPCMD_MASK = 4080
const APPCOMMAND_BASS_BOOST = 20
const APPCOMMAND_BASS_DOWN = 19
const APPCOMMAND_BASS_UP = 21
const APPCOMMAND_BROWSER_BACKWARD = 1
const APPCOMMAND_BROWSER_FAVORITES = 6
const APPCOMMAND_BROWSER_FORWARD = 2
const APPCOMMAND_BROWSER_HOME = 7
const APPCOMMAND_BROWSER_REFRESH = 3
const APPCOMMAND_BROWSER_SEARCH = 5
const APPCOMMAND_BROWSER_STOP = 4
const APPCOMMAND_CLOSE = 31
const APPCOMMAND_COPY = 36
const APPCOMMAND_CORRECTION_LIST = 45
const APPCOMMAND_CUT = 37
const APPCOMMAND_DELETE = 53
const APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE = 43
const APPCOMMAND_DWM_FLIP3D = 54
const APPCOMMAND_FIND = 28
const APPCOMMAND_FORWARD_MAIL = 40
const APPCOMMAND_HELP = 27
const APPCOMMAND_LAUNCH_APP1 = 17
const APPCOMMAND_LAUNCH_APP2 = 18
const APPCOMMAND_LAUNCH_MAIL = 15
const APPCOMMAND_LAUNCH_MEDIA_SELECT = 16
const APPCOMMAND_MEDIA_CHANNEL_DOWN = 52
const APPCOMMAND_MEDIA_CHANNEL_UP = 51
const APPCOMMAND_MEDIA_FAST_FORWARD = 49
const APPCOMMAND_MEDIA_NEXTTRACK = 11
const APPCOMMAND_MEDIA_PAUSE = 47
const APPCOMMAND_MEDIA_PLAY = 46
const APPCOMMAND_MEDIA_PLAY_PAUSE = 14
const APPCOMMAND_MEDIA_PREVIOUSTRACK = 12
const APPCOMMAND_MEDIA_RECORD = 48
const APPCOMMAND_MEDIA_REWIND = 50
const APPCOMMAND_MEDIA_STOP = 13
const APPCOMMAND_MICROPHONE_VOLUME_DOWN = 25
const APPCOMMAND_MICROPHONE_VOLUME_MUTE = 24
const APPCOMMAND_MICROPHONE_VOLUME_UP = 26
const APPCOMMAND_MIC_ON_OFF_TOGGLE = 44
const APPCOMMAND_NEW = 29
const APPCOMMAND_OPEN = 30
const APPCOMMAND_PASTE = 38
const APPCOMMAND_PRINT = 33
const APPCOMMAND_REDO = 35
const APPCOMMAND_REPLY_TO_MAIL = 39
const APPCOMMAND_SAVE = 32
const APPCOMMAND_SEND_MAIL = 41
const APPCOMMAND_SPELL_CHECK = 42
const APPCOMMAND_TREBLE_DOWN = 22
const APPCOMMAND_TREBLE_UP = 23
const APPCOMMAND_UNDO = 34
const APPCOMMAND_VOLUME_DOWN = 9
const APPCOMMAND_VOLUME_MUTE = 8
const APPCOMMAND_VOLUME_UP = 10
const APPIDREGFLAGS_ACTIVATE_IUSERVER_INDESKTOP = 1
const APPIDREGFLAGS_ISSUE_ACTIVATION_RPC_AT_IDENTIFY = 4
const APPIDREGFLAGS_IUSERVER_ACTIVATE_IN_CLIENT_SESSION_ONLY = 32
const APPIDREGFLAGS_IUSERVER_SELF_SID_IN_LAUNCH_PERMISSION = 16
const APPIDREGFLAGS_IUSERVER_UNMODIFIED_LOGON_TOKEN = 8
const APPIDREGFLAGS_RESERVED1 = 64
const APPIDREGFLAGS_SECURE_SERVER_PROCESS_SD_AND_BIND = 2
const APPLICATION_ERROR_MASK = 536870912
const APPLICATION_VERIFIER_ACCESS_VIOLATION = 2
const APPLICATION_VERIFIER_BAD_HEAP_HANDLE = 5
const APPLICATION_VERIFIER_COM_API_IN_DLLMAIN = 1025
const APPLICATION_VERIFIER_COM_CF_SUCCESS_WITH_NULL = 1034
const APPLICATION_VERIFIER_COM_ERROR = 1024
const APPLICATION_VERIFIER_COM_GCO_SUCCESS_WITH_NULL = 1035
const APPLICATION_VERIFIER_COM_HOLDING_LOCKS_ON_CALL = 1040
const APPLICATION_VERIFIER_COM_NULL_DACL = 1030
const APPLICATION_VERIFIER_COM_OBJECT_IN_FREED_MEMORY = 1036
const APPLICATION_VERIFIER_COM_OBJECT_IN_UNLOADED_DLL = 1037
const APPLICATION_VERIFIER_COM_SMUGGLED_PROXY = 1033
const APPLICATION_VERIFIER_COM_SMUGGLED_WRAPPER = 1032
const APPLICATION_VERIFIER_COM_UNBALANCED_COINIT = 1027
const APPLICATION_VERIFIER_COM_UNBALANCED_OLEINIT = 1028
const APPLICATION_VERIFIER_COM_UNBALANCED_SWC = 1029
const APPLICATION_VERIFIER_COM_UNHANDLED_EXCEPTION = 1026
const APPLICATION_VERIFIER_COM_UNSAFE_IMPERSONATION = 1031
const APPLICATION_VERIFIER_COM_VTBL_IN_FREED_MEMORY = 1038
const APPLICATION_VERIFIER_COM_VTBL_IN_UNLOADED_DLL = 1039
const APPLICATION_VERIFIER_CONTINUABLE_BREAK = 268435456
const APPLICATION_VERIFIER_CORRUPTED_FREED_HEAP_BLOCK = 14
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK = 8
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_END_STAMP = 17
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_EXCEPTION_RAISED_FOR_HEADER = 11
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_EXCEPTION_RAISED_FOR_PROBING = 12
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_HEADER = 13
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_PREFIX = 18
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_START_STAMP = 16
const APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_SUFFIX = 15
const APPLICATION_VERIFIER_CORRUPTED_HEAP_LIST = 20
const APPLICATION_VERIFIER_DESTROY_PROCESS_HEAP = 9
const APPLICATION_VERIFIER_DOUBLE_FREE = 7
const APPLICATION_VERIFIER_EXIT_THREAD_OWNS_LOCK = 512
const APPLICATION_VERIFIER_EXTREME_SIZE_REQUEST = 4
const APPLICATION_VERIFIER_FIRST_CHANCE_ACCESS_VIOLATION = 19
const APPLICATION_VERIFIER_INCORRECT_WAIT_CALL = 770
const APPLICATION_VERIFIER_INTERNAL_ERROR = 2147483648
const APPLICATION_VERIFIER_INTERNAL_WARNING = 1073741824
const APPLICATION_VERIFIER_INVALID_ALLOCMEM = 1537
const APPLICATION_VERIFIER_INVALID_EXIT_PROCESS_CALL = 258
const APPLICATION_VERIFIER_INVALID_FREEMEM = 1536
const APPLICATION_VERIFIER_INVALID_HANDLE = 768
const APPLICATION_VERIFIER_INVALID_MAPVIEW = 1538
const APPLICATION_VERIFIER_INVALID_TLS_VALUE = 769
const APPLICATION_VERIFIER_LOCK_ALREADY_INITIALIZED = 529
const APPLICATION_VERIFIER_LOCK_CORRUPTED = 517
const APPLICATION_VERIFIER_LOCK_DOUBLE_INITIALIZE = 515
const APPLICATION_VERIFIER_LOCK_INVALID_LOCK_COUNT = 520
const APPLICATION_VERIFIER_LOCK_INVALID_OWNER = 518
const APPLICATION_VERIFIER_LOCK_INVALID_RECURSION_COUNT = 519
const APPLICATION_VERIFIER_LOCK_IN_FREED_HEAP = 514
const APPLICATION_VERIFIER_LOCK_IN_FREED_MEMORY = 516
const APPLICATION_VERIFIER_LOCK_IN_FREED_VMEM = 530
const APPLICATION_VERIFIER_LOCK_IN_UNLOADED_DLL = 513
const APPLICATION_VERIFIER_LOCK_IN_UNMAPPED_MEM = 531
const APPLICATION_VERIFIER_LOCK_NOT_INITIALIZED = 528
const APPLICATION_VERIFIER_LOCK_OVER_RELEASED = 521
const APPLICATION_VERIFIER_NO_BREAK = 536870912
const APPLICATION_VERIFIER_NULL_HANDLE = 771
const APPLICATION_VERIFIER_PROBE_FREE_MEM = 1540
const APPLICATION_VERIFIER_PROBE_GUARD_PAGE = 1541
const APPLICATION_VERIFIER_PROBE_INVALID_ADDRESS = 1539
const APPLICATION_VERIFIER_PROBE_INVALID_START_OR_SIZE = 1543
const APPLICATION_VERIFIER_PROBE_NULL = 1542
const APPLICATION_VERIFIER_RPC_ERROR = 1280
const APPLICATION_VERIFIER_SIZE_HEAP_UNEXPECTED_EXCEPTION = 1560
const APPLICATION_VERIFIER_STACK_OVERFLOW = 257
const APPLICATION_VERIFIER_SWITCHED_HEAP_HANDLE = 6
const APPLICATION_VERIFIER_TERMINATE_THREAD_CALL = 256
const APPLICATION_VERIFIER_THREAD_NOT_LOCK_OWNER = 532
const APPLICATION_VERIFIER_UNEXPECTED_EXCEPTION = 10
const APPLICATION_VERIFIER_UNKNOWN_ERROR = 1
const APPLICATION_VERIFIER_UNSYNCHRONIZED_ACCESS = 3
const APPLICATION_VERIFIER_WAIT_IN_DLLMAIN = 772
const APPMODEL_ERROR_NO_APPLICATION = 15703
const APPMODEL_ERROR_NO_PACKAGE = 15700
const APPMODEL_ERROR_PACKAGE_IDENTITY_CORRUPT = 15702
const APPMODEL_ERROR_PACKAGE_RUNTIME_CORRUPT = 15701
const APP_LOCAL_DEVICE_ID_SIZE = 32
const ARABIC_CHARSET = 178
const ARW_BOTTOMLEFT = 0
const ARW_BOTTOMRIGHT = 1
const ARW_DOWN = 4
const ARW_HIDE = 8
const ARW_LEFT = 0
const ARW_RIGHT = 0
const ARW_STARTMASK = 3
const ARW_STARTRIGHT = 1
const ARW_STARTTOP = 2
const ARW_TOPLEFT = 2
const ARW_TOPRIGHT = 3
const ARW_UP = 4
const ASFW_ANY = -1
const ASPECTX = 40
const ASPECTXY = 44
const ASPECTY = 42
const ASPECT_FILTERING = 1
const ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = 0
const ASSERT_ALTERNATE = 9
const ASSERT_PRIMARY = 8
const ASYNCH = 128
const ASYNC_MODE_COMPATIBILITY = 1
const ASYNC_MODE_DEFAULT = 0
const ATAPI_ID_CMD = 161
const ATF_ONOFFFEEDBACK = 2
const ATF_TIMEOUTON = 1
const ATOM_FLAG_GLOBAL = 2
const ATTACH_PARENT_PROCESS = -1
const ATTRIBUTE_SECURITY_INFORMATION = 32
const ATTR_CONVERTED = 2
const ATTR_FIXEDCONVERTED = 5
const ATTR_INPUT = 0
const ATTR_INPUT_ERROR = 4
const ATTR_TARGET_CONVERTED = 1
const ATTR_TARGET_NOTCONVERTED = 3
const AT_KEYEXCHANGE = 1
const AT_SIGNATURE = 2
const AUDIT_ALLOW_NO_PRIVILEGE = 1
const AUTHTYPE_CLIENT = 1
const AUTHTYPE_SERVER = 2
const AUXCAPS_AUXIN = 2
const AUXCAPS_CDAUDIO = 1
const AUXCAPS_LRVOLUME = 2
const AUXCAPS_VOLUME = 1
const AUX_MAPPER = -1
const AW_ACTIVATE = 131072
const AW_BLEND = 524288
const AW_CENTER = 16
const AW_HIDE = 65536
const AW_HOR_NEGATIVE = 2
const AW_HOR_POSITIVE = 1
const AW_SLIDE = 262144
const AW_VER_NEGATIVE = 8
const AW_VER_POSITIVE = 4
const AbnormalTermination = 0
const AbortSystemShutdown = 0
const AccessCheckAndAuditAlarm = 0
const AccessCheckByTypeAndAuditAlarm = 0
const AccessCheckByTypeResultListAndAuditAlarm = 0
const AccessCheckByTypeResultListAndAuditAlarmByHandle = 0
const AddAtom = 0
const AddConsoleAlias = 0
const AddFontResource = 0
const AddFontResourceEx = 0
const AddForm = 0
const AddJob = 0
const AddMonitor = 0
const AddPort = 0
const AddPrintProcessor = 0
const AddPrintProvidor = 0
const AddPrinter = 0
const AddPrinterConnection = 0
const AddPrinterConnection2 = 0
const AddPrinterDriver = 0
const AddPrinterDriverEx = 0
const AdvancedDocumentProperties = 0
const AnsiLower = 0
const AnsiLowerBuff = 0
const AnsiNext = 0
const AnsiPrev = 0
const AnsiToOem = 0
const AnsiToOemBuff = 0
const AnsiUpper = 0
const AnsiUpperBuff = 0
const AppendMenu = 0
const BACKGROUND_BLUE = 16
const BACKGROUND_GREEN = 32
const BACKGROUND_INTENSITY = 128
const BACKGROUND_RED = 64
const BACKUP_ALTERNATE_DATA = 4
const BACKUP_DATA = 1
const BACKUP_EA_DATA = 2
const BACKUP_GHOSTED_FILE_EXTENTS = 11
const BACKUP_INVALID = 0
const BACKUP_LINK = 5
const BACKUP_OBJECT_ID = 7
const BACKUP_PROPERTY_DATA = 6
const BACKUP_REPARSE_DATA = 8
const BACKUP_SECURITY_DATA = 3
const BACKUP_SECURITY_INFORMATION = 65536
const BACKUP_SPARSE_BLOCK = 9
const BACKUP_TXFS_DATA = 10
const BALTIC_CHARSET = 186
const BANDINFO = 24
const BASE_SEARCH_PATH_DISABLE_SAFE_SEARCHMODE = 65536
const BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE = 1
const BASE_SEARCH_PATH_INVALID_FLAGS = -98306
const BASE_SEARCH_PATH_PERMANENT = 32768
const BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_CA_FLAG = 2147483648
const BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_END_ENTITY_FLAG = 1073741824
const BATTERY_DISCHARGE_FLAGS_ENABLE = 2147483648
const BATTERY_DISCHARGE_FLAGS_EVENTCODE_MASK = 7
const BATTERY_FLAG_CHARGING = 8
const BATTERY_FLAG_CRITICAL = 4
const BATTERY_FLAG_HIGH = 1
const BATTERY_FLAG_LOW = 2
const BATTERY_FLAG_NO_BATTERY = 128
const BATTERY_FLAG_UNKNOWN = 255
const BATTERY_LIFE_UNKNOWN = 4294967295
const BATTERY_PERCENTAGE_UNKNOWN = 255
const BCRYPTBUFFER_VERSION = 0
const BCRYPT_3DES_112_ALGORITHM = "3DES_112"
const BCRYPT_3DES_ALGORITHM = "3DES"
const BCRYPT_AES_ALGORITHM = "AES"
const BCRYPT_AES_CMAC_ALGORITHM = "AES-CMAC"
const BCRYPT_AES_GMAC_ALGORITHM = "AES-GMAC"
const BCRYPT_AES_WRAP_KEY_BLOB = "Rfc3565KeyWrapBlob"
const BCRYPT_ALGORITHM_NAME = "AlgorithmName"
const BCRYPT_ALG_HANDLE_HMAC_FLAG = 8
const BCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE = 3
const BCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION = 4
const BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION = 1
const BCRYPT_AUTH_MODE_CHAIN_CALLS_FLAG = 1
const BCRYPT_AUTH_MODE_IN_PROGRESS_FLAG = 2
const BCRYPT_AUTH_TAG_LENGTH = "AuthTagLength"
const BCRYPT_BLOCK_LENGTH = "BlockLength"
const BCRYPT_BLOCK_PADDING = 1
const BCRYPT_BLOCK_SIZE_LIST = "BlockSizeList"
const BCRYPT_BUFFERS_LOCKED_FLAG = 64
const BCRYPT_CAPI_AES_FLAG = 16
const BCRYPT_CAPI_KDF_ALGORITHM = "CAPI_KDF"
const BCRYPT_CHAINING_MODE = "ChainingMode"
const BCRYPT_CHAIN_MODE_CBC = "ChainingModeCBC"
const BCRYPT_CHAIN_MODE_CCM = "ChainingModeCCM"
const BCRYPT_CHAIN_MODE_CFB = "ChainingModeCFB"
const BCRYPT_CHAIN_MODE_ECB = "ChainingModeECB"
const BCRYPT_CHAIN_MODE_GCM = "ChainingModeGCM"
const BCRYPT_CHAIN_MODE_NA = "ChainingModeN/A"
const BCRYPT_CIPHER_INTERFACE = 1
const BCRYPT_CIPHER_OPERATION = 1
const BCRYPT_DESX_ALGORITHM = "DESX"
const BCRYPT_DES_ALGORITHM = "DES"
const BCRYPT_DH_ALGORITHM = "DH"
const BCRYPT_DH_PARAMETERS = "DHParameters"
const BCRYPT_DH_PARAMETERS_MAGIC = 1297107012
const BCRYPT_DH_PRIVATE_BLOB = "DHPRIVATEBLOB"
const BCRYPT_DH_PRIVATE_MAGIC = 1448101956
const BCRYPT_DH_PUBLIC_BLOB = "DHPUBLICBLOB"
const BCRYPT_DH_PUBLIC_MAGIC = 1112557636
const BCRYPT_DSA_ALGORITHM = "DSA"
const BCRYPT_DSA_PARAMETERS = "DSAParameters"
const BCRYPT_DSA_PARAMETERS_MAGIC = 1297109828
const BCRYPT_DSA_PARAMETERS_MAGIC_V2 = 843927620
const BCRYPT_DSA_PRIVATE_BLOB = "DSAPRIVATEBLOB"
const BCRYPT_DSA_PRIVATE_MAGIC = 1448104772
const BCRYPT_DSA_PRIVATE_MAGIC_V2 = 844517444
const BCRYPT_DSA_PUBLIC_BLOB = "DSAPUBLICBLOB"
const BCRYPT_DSA_PUBLIC_MAGIC = 1112560452
const BCRYPT_DSA_PUBLIC_MAGIC_V2 = 843206724
const BCRYPT_ECCFULLPRIVATE_BLOB = "ECCFULLPRIVATEBLOB"
const BCRYPT_ECCFULLPUBLIC_BLOB = "ECCFULLPUBLICBLOB"
const BCRYPT_ECCPRIVATE_BLOB = "ECCPRIVATEBLOB"
const BCRYPT_ECCPUBLIC_BLOB = "ECCPUBLICBLOB"
const BCRYPT_ECDH_P256_ALGORITHM = "ECDH_P256"
const BCRYPT_ECDH_P384_ALGORITHM = "ECDH_P384"
const BCRYPT_ECDH_P521_ALGORITHM = "ECDH_P521"
const BCRYPT_ECDH_PRIVATE_GENERIC_MAGIC = 1447772997
const BCRYPT_ECDH_PRIVATE_P256_MAGIC = 843793221
const BCRYPT_ECDH_PRIVATE_P384_MAGIC = 877347653
const BCRYPT_ECDH_PRIVATE_P521_MAGIC = 910902085
const BCRYPT_ECDH_PUBLIC_GENERIC_MAGIC = 1347109701
const BCRYPT_ECDH_PUBLIC_P256_MAGIC = 827016005
const BCRYPT_ECDH_PUBLIC_P384_MAGIC = 860570437
const BCRYPT_ECDH_PUBLIC_P521_MAGIC = 894124869
const BCRYPT_ECDSA_P256_ALGORITHM = "ECDSA_P256"
const BCRYPT_ECDSA_P384_ALGORITHM = "ECDSA_P384"
const BCRYPT_ECDSA_P521_ALGORITHM = "ECDSA_P521"
const BCRYPT_ECDSA_PRIVATE_GENERIC_MAGIC = 1447314245
const BCRYPT_ECDSA_PRIVATE_P256_MAGIC = 844317509
const BCRYPT_ECDSA_PRIVATE_P384_MAGIC = 877871941
const BCRYPT_ECDSA_PRIVATE_P521_MAGIC = 911426373
const BCRYPT_ECDSA_PUBLIC_GENERIC_MAGIC = 1346650949
const BCRYPT_ECDSA_PUBLIC_P256_MAGIC = 827540293
const BCRYPT_ECDSA_PUBLIC_P384_MAGIC = 861094725
const BCRYPT_ECDSA_PUBLIC_P521_MAGIC = 894649157
const BCRYPT_EFFECTIVE_KEY_LENGTH = "EffectiveKeyLength"
const BCRYPT_GLOBAL_PARAMETERS = "SecretAgreementParam"
const BCRYPT_HASH_BLOCK_LENGTH = "HashBlockLength"
const BCRYPT_HASH_INTERFACE = 2
const BCRYPT_HASH_LENGTH = "HashDigestLength"
const BCRYPT_HASH_OID_LIST = "HashOIDList"
const BCRYPT_HASH_OPERATION = 2
const BCRYPT_HASH_REUSABLE_FLAG = 32
const BCRYPT_INITIALIZATION_VECTOR = "IV"
const BCRYPT_IS_KEYED_HASH = "IsKeyedHash"
const BCRYPT_IS_REUSABLE_HASH = "IsReusableHash"
const BCRYPT_KDF_HASH = "HASH"
const BCRYPT_KDF_HMAC = "HMAC"
const BCRYPT_KDF_RAW_SECRET = "TRUNCATE"
const BCRYPT_KDF_SP80056A_CONCAT = "SP800_56A_CONCAT"
const BCRYPT_KDF_TLS_PRF = "TLS_PRF"
const BCRYPT_KEY_DATA_BLOB = "KeyDataBlob"
const BCRYPT_KEY_DATA_BLOB_MAGIC = 1296188491
const BCRYPT_KEY_DATA_BLOB_VERSION1 = 1
const BCRYPT_KEY_DERIVATION_INTERFACE = 7
const BCRYPT_KEY_DERIVATION_OPERATION = 64
const BCRYPT_KEY_LENGTH = "KeyLength"
const BCRYPT_KEY_LENGTHS = "KeyLengths"
const BCRYPT_KEY_OBJECT_LENGTH = "KeyObjectLength"
const BCRYPT_KEY_STRENGTH = "KeyStrength"
const BCRYPT_MD2_ALGORITHM = "MD2"
const BCRYPT_MD4_ALGORITHM = "MD4"
const BCRYPT_MD5_ALGORITHM = "MD5"
const BCRYPT_MESSAGE_BLOCK_LENGTH = "MessageBlockLength"
const BCRYPT_MULTI_OBJECT_LENGTH = "MultiObjectLength"
const BCRYPT_NO_KEY_VALIDATION = 8
const BCRYPT_OBJECT_ALIGNMENT = 16
const BCRYPT_OBJECT_LENGTH = "ObjectLength"
const BCRYPT_OPAQUE_KEY_BLOB = "OpaqueKeyBlob"
const BCRYPT_PADDING_SCHEMES = "PaddingSchemes"
const BCRYPT_PAD_NONE = 1
const BCRYPT_PAD_OAEP = 4
const BCRYPT_PAD_PKCS1 = 2
const BCRYPT_PAD_PKCS1_OPTIONAL_HASH_OID = 16
const BCRYPT_PAD_PSS = 8
const BCRYPT_PBKDF2_ALGORITHM = "PBKDF2"
const BCRYPT_PCP_PLATFORM_TYPE_PROPERTY = "PCP_PLATFORM_TYPE"
const BCRYPT_PCP_PROVIDER_VERSION_PROPERTY = "PCP_PROVIDER_VERSION"
const BCRYPT_PRIMITIVE_TYPE = "PrimitiveType"
const BCRYPT_PRIVATE_KEY = "PrivKeyVal"
const BCRYPT_PRIVATE_KEY_BLOB = "PRIVATEBLOB"
const BCRYPT_PRIVATE_KEY_FLAG = 2
const BCRYPT_PROVIDER_HANDLE = "ProviderHandle"
const BCRYPT_PROV_DISPATCH = 1
const BCRYPT_PUBLIC_KEY_BLOB = "PUBLICBLOB"
const BCRYPT_PUBLIC_KEY_FLAG = 1
const BCRYPT_PUBLIC_KEY_LENGTH = "PublicKeyLength"
const BCRYPT_RC2_ALGORITHM = "RC2"
const BCRYPT_RC4_ALGORITHM = "RC4"
const BCRYPT_RNG_ALGORITHM = "RNG"
const BCRYPT_RNG_DUAL_EC_ALGORITHM = "DUALECRNG"
const BCRYPT_RNG_FIPS186_DSA_ALGORITHM = "FIPS186DSARNG"
const BCRYPT_RNG_INTERFACE = 6
const BCRYPT_RNG_OPERATION = 32
const BCRYPT_RNG_USE_ENTROPY_IN_BUFFER = 1
const BCRYPT_RSAFULLPRIVATE_BLOB = "RSAFULLPRIVATEBLOB"
const BCRYPT_RSAFULLPRIVATE_MAGIC = 859919186
const BCRYPT_RSAPRIVATE_BLOB = "RSAPRIVATEBLOB"
const BCRYPT_RSAPRIVATE_MAGIC = 843141970
const BCRYPT_RSAPUBLIC_BLOB = "RSAPUBLICBLOB"
const BCRYPT_RSAPUBLIC_MAGIC = 826364754
const BCRYPT_RSA_ALGORITHM = "RSA"
const BCRYPT_RSA_SIGN_ALGORITHM = "RSA_SIGN"
const BCRYPT_SECRET_AGREEMENT_INTERFACE = 4
const BCRYPT_SECRET_AGREEMENT_OPERATION = 8
const BCRYPT_SHA1_ALGORITHM = "SHA1"
const BCRYPT_SHA256_ALGORITHM = "SHA256"
const BCRYPT_SHA384_ALGORITHM = "SHA384"
const BCRYPT_SHA512_ALGORITHM = "SHA512"
const BCRYPT_SIGNATURE_INTERFACE = 5
const BCRYPT_SIGNATURE_LENGTH = "SignatureLength"
const BCRYPT_SIGNATURE_OPERATION = 16
const BCRYPT_SP800108_CTR_HMAC_ALGORITHM = "SP800_108_CTR_HMAC"
const BCRYPT_SP80056A_CONCAT_ALGORITHM = "SP800_56A_CONCAT"
const BCRYPT_SUPPORTED_PAD_OAEP = 8
const BCRYPT_SUPPORTED_PAD_PKCS1_ENC = 2
const BCRYPT_SUPPORTED_PAD_PKCS1_SIG = 4
const BCRYPT_SUPPORTED_PAD_PSS = 16
const BCRYPT_SUPPORTED_PAD_ROUTER = 1
const BCRYPT_USE_SYSTEM_PREFERRED_RNG = 2
const BDR_INNER = 12
const BDR_OUTER = 3
const BDR_RAISED = 5
const BDR_RAISEDINNER = 4
const BDR_RAISEDOUTER = 1
const BDR_SUNKEN = 10
const BDR_SUNKENINNER = 8
const BDR_SUNKENOUTER = 2
const BEGIN_PATH = 4096
const BELOW_NORMAL_PRIORITY_CLASS = 16384
const BF_ADJUST = 8192
const BF_BOTTOM = 8
const BF_BOTTOMLEFT = 9
const BF_BOTTOMRIGHT = 12
const BF_DIAGONAL = 16
const BF_DIAGONAL_ENDBOTTOMLEFT = 25
const BF_DIAGONAL_ENDBOTTOMRIGHT = 28
const BF_DIAGONAL_ENDTOPLEFT = 19
const BF_DIAGONAL_ENDTOPRIGHT = 22
const BF_FLAT = 16384
const BF_LEFT = 1
const BF_MIDDLE = 2048
const BF_MONO = 32768
const BF_RECT = 15
const BF_RIGHT = 4
const BF_SOFT = 4096
const BF_TOP = 2
const BF_TOPLEFT = 3
const BF_TOPRIGHT = 6
const BIDI_ACCESS_ADMINISTRATOR = 1
const BIDI_ACCESS_USER = 2
const BIDI_ACTION_ENUM_SCHEMA = "EnumSchema"
const BIDI_ACTION_GET = "Get"
const BIDI_ACTION_GET_ALL = "GetAll"
const BIDI_ACTION_SET = "Set"
const BINDF_DONTPUTINCACHE = 0
const BINDF_DONTUSECACHE = 0
const BINDF_NOCOPYDATA = 0
const BITSPIXEL = 12
const BITVEC_MXHASH = 0
const BITVEC_NBIT = 0
const BITVEC_NELEM = 0
const BITVEC_NINT = 0
const BITVEC_NPTR = 0
const BITVEC_SZ = 512
const BITVEC_SZELEM = 8
const BITVEC_TELEM = 0
const BITVEC_USIZE = 0
const BI_BITFIELDS = 3
const BI_JPEG = 4
const BI_PNG = 5
const BI_RGB = 0
const BI_RLE4 = 2
const BI_RLE8 = 1
const BKMODE_LAST = 2
const BLACKONWHITE = 1
const BLACK_BRUSH = 4
const BLACK_PEN = 7
const BLTALIGNMENT = 119
const BM_CLICK = 245
const BM_GETCHECK = 240
const BM_GETIMAGE = 246
const BM_GETSTATE = 242
const BM_SETCHECK = 241
const BM_SETDONTCLICK = 248
const BM_SETIMAGE = 247
const BM_SETSTATE = 243
const BM_SETSTYLE = 244
const BN_CLICKED = 0
const BN_DBLCLK = 5
const BN_DISABLE = 4
const BN_DOUBLECLICKED = 5
const BN_HILITE = 2
const BN_KILLFOCUS = 7
const BN_PAINT = 1
const BN_PUSHED = 2
const BN_SETFOCUS = 6
const BN_UNHILITE = 3
const BN_UNPUSHED = 3
const BOLD_FONTTYPE = 256
const BROADCAST_QUERY_DENY = 1112363332
const BSF_ALLOWSFW = 128
const BSF_FLUSHDISK = 4
const BSF_FORCEIFHUNG = 32
const BSF_IGNORECURRENTTASK = 2
const BSF_LUID = 1024
const BSF_NOHANG = 8
const BSF_NOTIMEOUTIFNOTHUNG = 64
const BSF_POSTMESSAGE = 16
const BSF_QUERY = 1
const BSF_RETURNHDESK = 512
const BSF_SENDNOTIFYMESSAGE = 256
const BSM_ALLCOMPONENTS = 0
const BSM_ALLDESKTOPS = 16
const BSM_APPLICATIONS = 8
const BSM_INSTALLABLEDRIVERS = 4
const BSM_NETDRIVER = 2
const BSM_VXDS = 1
const BST_CHECKED = 1
const BST_FOCUS = 8
const BST_INDETERMINATE = 2
const BST_PUSHED = 4
const BST_UNCHECKED = 0
const BS_3STATE = 5
const BS_AUTO3STATE = 6
const BS_AUTOCHECKBOX = 3
const BS_AUTORADIOBUTTON = 9
const BS_BITMAP = 128
const BS_BOTTOM = 2048
const BS_CENTER = 768
const BS_CHECKBOX = 2
const BS_DEFPUSHBUTTON = 1
const BS_DIBPATTERN = 5
const BS_DIBPATTERN8X8 = 8
const BS_DIBPATTERNPT = 6
const BS_FLAT = 32768
const BS_GROUPBOX = 7
const BS_HATCHED = 2
const BS_HOLLOW = 1
const BS_ICON = 64
const BS_INDEXED = 4
const BS_LEFT = 256
const BS_LEFTTEXT = 32
const BS_MONOPATTERN = 9
const BS_MULTILINE = 8192
const BS_NOTIFY = 16384
const BS_NULL = 1
const BS_OWNERDRAW = 11
const BS_PATTERN = 3
const BS_PATTERN8X8 = 7
const BS_PUSHBOX = 10
const BS_PUSHBUTTON = 0
const BS_PUSHLIKE = 4096
const BS_RADIOBUTTON = 4
const BS_RIGHT = 512
const BS_RIGHTBUTTON = 32
const BS_SOLID = 0
const BS_TEXT = 0
const BS_TOP = 1024
const BS_TYPEMASK = 15
const BS_USERBUTTON = 8
const BS_VCENTER = 3072
const BTALLOC_ANY = 0
const BTALLOC_EXACT = 1
const BTALLOC_LE = 2
const BTCF_AtLast = 8
const BTCF_Incrblob = 16
const BTCF_Multiple = 32
const BTCF_Pinned = 64
const BTCF_ValidNKey = 2
const BTCF_ValidOvfl = 4
const BTCF_WriteFlag = 1
const BTCURSOR_FIRST_UNINIT = 0
const BTCURSOR_MAX_DEPTH = 20
const BTREE_APPEND = 8
const BTREE_APPLICATION_ID = 8
const BTREE_AUTOVACUUM_FULL = 1
const BTREE_AUTOVACUUM_INCR = 2
const BTREE_AUTOVACUUM_NONE = 0
const BTREE_AUXDELETE = 4
const BTREE_BLOBKEY = 2
const BTREE_BULKLOAD = 1
const BTREE_DATA_VERSION = 15
const BTREE_DEFAULT_CACHE_SIZE = 3
const BTREE_FILE_FORMAT = 2
const BTREE_FORDELETE = 8
const BTREE_FREE_PAGE_COUNT = 0
const BTREE_HINT_RANGE = 0
const BTREE_INCR_VACUUM = 7
const BTREE_INTKEY = 1
const BTREE_LARGEST_ROOT_PAGE = 4
const BTREE_MEMORY = 2
const BTREE_OMIT_JOURNAL = 1
const BTREE_PREFORMAT = 128
const BTREE_SAVEPOSITION = 2
const BTREE_SCHEMA_VERSION = 1
const BTREE_SEEK_EQ = 2
const BTREE_SINGLE = 4
const BTREE_TEXT_ENCODING = 5
const BTREE_UNORDERED = 8
const BTREE_USER_VERSION = 6
const BTREE_WRCSR = 4
const BTS_EXCLUSIVE = 64
const BTS_FAST_SECURE = 12
const BTS_INITIALLY_EMPTY = 16
const BTS_NO_WAL = 32
const BTS_OVERWRITE = 8
const BTS_PAGESIZE_FIXED = 2
const BTS_PENDING = 128
const BTS_READ_ONLY = 1
const BTS_SECURE_DELETE = 4
const BUFSIZ = 512
const BackupEventLog = 0
const BeginUpdateResource = 0
const BitScanForward = 0
const BitScanReverse = 0
const BitTest = 0
const BitTestAndComplement = 0
const BitTestAndReset = 0
const BitTestAndSet = 0
const BroadcastSystemMessage = 0
const BroadcastSystemMessageEx = 0
const BuildCommDCB = 0
const BuildCommDCBAndTimeouts = 0
const C1_ALPHA = 256
const C1_BLANK = 64
const C1_CNTRL = 32
const C1_DEFINED = 512
const C1_DIGIT = 4
const C1_LOWER = 2
const C1_PUNCT = 16
const C1_SPACE = 8
const C1_UPPER = 1
const C1_XDIGIT = 128
const C2_ARABICNUMBER = 6
const C2_BLOCKSEPARATOR = 8
const C2_COMMONSEPARATOR = 7
const C2_EUROPENUMBER = 3
const C2_EUROPESEPARATOR = 4
const C2_EUROPETERMINATOR = 5
const C2_LEFTTORIGHT = 1
const C2_NOTAPPLICABLE = 0
const C2_OTHERNEUTRAL = 11
const C2_RIGHTTOLEFT = 2
const C2_SEGMENTSEPARATOR = 9
const C2_WHITESPACE = 10
const C3_ALPHA = 32768
const C3_DIACRITIC = 2
const C3_FULLWIDTH = 128
const C3_HALFWIDTH = 64
const C3_HIGHSURROGATE = 2048
const C3_HIRAGANA = 32
const C3_IDEOGRAPH = 256
const C3_KASHIDA = 512
const C3_KATAKANA = 16
const C3_LEXICAL = 1024
const C3_LOWSURROGATE = 4096
const C3_NONSPACING = 1
const C3_NOTAPPLICABLE = 0
const C3_SYMBOL = 8
const C3_VOWELMARK = 4
const CACHE_E_FIRST = 2147746160
const CACHE_E_LAST = 2147746175
const CACHE_FULLY_ASSOCIATIVE = 255
const CACHE_STALE = 0
const CACHE_S_FIRST = 262512
const CACHE_S_LAST = 262527
const CADV_LATEACK = 65535
const CALERT_SYSTEM = 6
const CALG_3DES = 26115
const CALG_3DES_112 = 26121
const CALG_AES = 26129
const CALG_AES_128 = 26126
const CALG_AES_192 = 26127
const CALG_AES_256 = 26128
const CALG_AGREEDKEY_ANY = 43523
const CALG_CYLINK_MEK = 26124
const CALG_DES = 26113
const CALG_DESX = 26116
const CALG_DH_EPHEM = 43522
const CALG_DH_SF = 43521
const CALG_DSS_SIGN = 8704
const CALG_ECDH = 43525
const CALG_ECDH_EPHEM = 44550
const CALG_ECDSA = 8707
const CALG_ECMQV = 40961
const CALG_HASH_REPLACE_OWF = 32779
const CALG_HMAC = 32777
const CALG_HUGHES_MD5 = 40963
const CALG_KEA_KEYX = 43524
const CALG_MAC = 32773
const CALG_MD2 = 32769
const CALG_MD4 = 32770
const CALG_MD5 = 32771
const CALG_NO_SIGN = 8192
const CALG_NULLCIPHER = 24576
const CALG_OID_INFO_CNG_ONLY = 4294967295
const CALG_OID_INFO_PARAMETERS = 4294967294
const CALG_PCT1_MASTER = 19460
const CALG_RC2 = 26114
const CALG_RC4 = 26625
const CALG_RC5 = 26125
const CALG_RSA_KEYX = 41984
const CALG_RSA_SIGN = 9216
const CALG_SCHANNEL_ENC_KEY = 19463
const CALG_SCHANNEL_MAC_KEY = 19459
const CALG_SCHANNEL_MASTER_HASH = 19458
const CALG_SEAL = 26626
const CALG_SHA = 32772
const CALG_SHA1 = 32772
const CALG_SHA_256 = 32780
const CALG_SHA_384 = 32781
const CALG_SHA_512 = 32782
const CALG_SKIPJACK = 26122
const CALG_SSL2_MASTER = 19461
const CALG_SSL3_MASTER = 19457
const CALG_SSL3_SHAMD5 = 32776
const CALG_TEK = 26123
const CALG_TLS1PRF = 32778
const CALG_TLS1_MASTER = 19462
const CALINFO_ENUMPROC = 0
const CALINFO_ENUMPROCEX = 0
const CALLBACK = "__stdcall"
const CALLBACK_CHUNK_FINISHED = 0
const CALLBACK_EVENT = 327680
const CALLBACK_FUNCTION = 196608
const CALLBACK_NULL = 0
const CALLBACK_STREAM_SWITCH = 1
const CALLBACK_TASK = 131072
const CALLBACK_THREAD = 131072
const CALLBACK_TYPEMASK = 458752
const CALLBACK_WINDOW = 65536
const CALL_PENDING = 2
const CAL_GREGORIAN = 1
const CAL_GREGORIAN_ARABIC = 10
const CAL_GREGORIAN_ME_FRENCH = 9
const CAL_GREGORIAN_US = 2
const CAL_GREGORIAN_XLIT_ENGLISH = 11
const CAL_GREGORIAN_XLIT_FRENCH = 12
const CAL_HEBREW = 8
const CAL_HIJRI = 6
const CAL_ICALINTVALUE = 1
const CAL_ITWODIGITYEARMAX = 48
const CAL_IYEAROFFSETRANGE = 3
const CAL_JAPAN = 3
const CAL_KOREA = 5
const CAL_NOUSEROVERRIDE = 2147483648
const CAL_RETURN_GENITIVE_NAMES = 268435456
const CAL_RETURN_NUMBER = 536870912
const CAL_SABBREVDAYNAME1 = 14
const CAL_SABBREVDAYNAME2 = 15
const CAL_SABBREVDAYNAME3 = 16
const CAL_SABBREVDAYNAME4 = 17
const CAL_SABBREVDAYNAME5 = 18
const CAL_SABBREVDAYNAME6 = 19
const CAL_SABBREVDAYNAME7 = 20
const CAL_SABBREVERASTRING = 57
const CAL_SABBREVMONTHNAME1 = 34
const CAL_SABBREVMONTHNAME10 = 43
const CAL_SABBREVMONTHNAME11 = 44
const CAL_SABBREVMONTHNAME12 = 45
const CAL_SABBREVMONTHNAME13 = 46
const CAL_SABBREVMONTHNAME2 = 35
const CAL_SABBREVMONTHNAME3 = 36
const CAL_SABBREVMONTHNAME4 = 37
const CAL_SABBREVMONTHNAME5 = 38
const CAL_SABBREVMONTHNAME6 = 39
const CAL_SABBREVMONTHNAME7 = 40
const CAL_SABBREVMONTHNAME8 = 41
const CAL_SABBREVMONTHNAME9 = 42
const CAL_SCALNAME = 2
const CAL_SDAYNAME1 = 7
const CAL_SDAYNAME2 = 8
const CAL_SDAYNAME3 = 9
const CAL_SDAYNAME4 = 10
const CAL_SDAYNAME5 = 11
const CAL_SDAYNAME6 = 12
const CAL_SDAYNAME7 = 13
const CAL_SERASTRING = 4
const CAL_SJAPANESEERAFIRSTYEAR = 61
const CAL_SLONGDATE = 6
const CAL_SMONTHDAY = 56
const CAL_SMONTHNAME1 = 21
const CAL_SMONTHNAME10 = 30
const CAL_SMONTHNAME11 = 31
const CAL_SMONTHNAME12 = 32
const CAL_SMONTHNAME13 = 33
const CAL_SMONTHNAME2 = 22
const CAL_SMONTHNAME3 = 23
const CAL_SMONTHNAME4 = 24
const CAL_SMONTHNAME5 = 25
const CAL_SMONTHNAME6 = 26
const CAL_SMONTHNAME7 = 27
const CAL_SMONTHNAME8 = 28
const CAL_SMONTHNAME9 = 29
const CAL_SRELATIVELONGDATE = 58
const CAL_SSHORTDATE = 5
const CAL_SSHORTESTDAYNAME1 = 49
const CAL_SSHORTESTDAYNAME2 = 50
const CAL_SSHORTESTDAYNAME3 = 51
const CAL_SSHORTESTDAYNAME4 = 52
const CAL_SSHORTESTDAYNAME5 = 53
const CAL_SSHORTESTDAYNAME6 = 54
const CAL_SSHORTESTDAYNAME7 = 55
const CAL_SYEARMONTH = 47
const CAL_TAIWAN = 4
const CAL_THAI = 7
const CAL_UMALQURA = 23
const CAL_USE_CP_ACP = 1073741824
const CAPSLOCK_ON = 128
const CAP_ATAPI_ID_CMD = 2
const CAP_ATA_ID_CMD = 1
const CAP_SMART_CMD = 4
const CAT_E_FIRST = 2147746144
const CAT_E_LAST = 2147746145
const CA_LOG_FILTER = 2
const CA_NEGATIVE = 1
const CBF_FAIL_ADVISES = 16384
const CBF_FAIL_ALLSVRXACTIONS = 258048
const CBF_FAIL_CONNECTIONS = 8192
const CBF_FAIL_EXECUTES = 32768
const CBF_FAIL_POKES = 65536
const CBF_FAIL_REQUESTS = 131072
const CBF_FAIL_SELFCONNECTIONS = 4096
const CBF_SKIP_ALLNOTIFICATIONS = 3932160
const CBF_SKIP_CONNECT_CONFIRMS = 262144
const CBF_SKIP_DISCONNECTS = 2097152
const CBF_SKIP_REGISTRATIONS = 524288
const CBF_SKIP_UNREGISTRATIONS = 1048576
const CBM_INIT = 4
const CBN_CLOSEUP = 8
const CBN_DBLCLK = 2
const CBN_DROPDOWN = 7
const CBN_EDITCHANGE = 5
const CBN_EDITUPDATE = 6
const CBN_ERRSPACE = -1
const CBN_KILLFOCUS = 4
const CBN_SELCHANGE = 1
const CBN_SELENDCANCEL = 10
const CBN_SELENDOK = 9
const CBN_SETFOCUS = 3
const CBR_110 = 110
const CBR_115200 = 115200
const CBR_1200 = 1200
const CBR_128000 = 128000
const CBR_14400 = 14400
const CBR_19200 = 19200
const CBR_2400 = 2400
const CBR_256000 = 256000
const CBR_300 = 300
const CBR_38400 = 38400
const CBR_4800 = 4800
const CBR_56000 = 56000
const CBR_57600 = 57600
const CBR_600 = 600
const CBR_9600 = 9600
const CBR_BLOCK = -1
const CBS_AUTOHSCROLL = 64
const CBS_DISABLENOSCROLL = 2048
const CBS_DROPDOWN = 2
const CBS_DROPDOWNLIST = 3
const CBS_HASSTRINGS = 512
const CBS_LOWERCASE = 16384
const CBS_NOINTEGRALHEIGHT = 1024
const CBS_OEMCONVERT = 128
const CBS_OWNERDRAWFIXED = 16
const CBS_OWNERDRAWVARIABLE = 32
const CBS_SIMPLE = 1
const CBS_SORT = 256
const CBS_UPPERCASE = 8192
const CB_ADDSTRING = 323
const CB_DELETESTRING = 324
const CB_DIR = 325
const CB_ERR = -1
const CB_ERRSPACE = -2
const CB_FINDSTRING = 332
const CB_FINDSTRINGEXACT = 344
const CB_GETCOMBOBOXINFO = 356
const CB_GETCOUNT = 326
const CB_GETCURSEL = 327
const CB_GETDROPPEDCONTROLRECT = 338
const CB_GETDROPPEDSTATE = 343
const CB_GETDROPPEDWIDTH = 351
const CB_GETEDITSEL = 320
const CB_GETEXTENDEDUI = 342
const CB_GETHORIZONTALEXTENT = 349
const CB_GETITEMDATA = 336
const CB_GETITEMHEIGHT = 340
const CB_GETLBTEXT = 328
const CB_GETLBTEXTLEN = 329
const CB_GETLOCALE = 346
const CB_GETTOPINDEX = 347
const CB_INITSTORAGE = 353
const CB_INSERTSTRING = 330
const CB_LIMITTEXT = 321
const CB_MSGMAX = 357
const CB_OKAY = 0
const CB_RESETCONTENT = 331
const CB_SELECTSTRING = 333
const CB_SETCURSEL = 334
const CB_SETDROPPEDWIDTH = 352
const CB_SETEDITSEL = 322
const CB_SETEXTENDEDUI = 341
const CB_SETHORIZONTALEXTENT = 350
const CB_SETITEMDATA = 337
const CB_SETITEMHEIGHT = 339
const CB_SETLOCALE = 345
const CB_SETTOPINDEX = 348
const CB_SHOWDROPDOWN = 335
const CCERR_CHOOSECOLORCODES = 20480
const CCHDEVICENAME = 32
const CCHFORMNAME = 32
const CCHILDREN_SCROLLBAR = 5
const CCHILDREN_TITLEBAR = 5
const CCH_MAX_PROPSTG_NAME = 31
const CC_AND = 24
const CC_ANYCOLOR = 256
const CC_BANG = 15
const CC_BOM = 30
const CC_CHORD = 4
const CC_CIRCLES = 1
const CC_COMMA = 23
const CC_DIGIT = 3
const CC_DOLLAR = 4
const CC_DOT = 26
const CC_ELLIPSES = 8
const CC_ENABLEHOOK = 16
const CC_ENABLETEMPLATE = 32
const CC_ENABLETEMPLATEHANDLE = 64
const CC_EQ = 14
const CC_FULLOPEN = 2
const CC_GT = 13
const CC_ID = 27
const CC_ILLEGAL = 28
const CC_INTERIORS = 128
const CC_KYWD = 2
const CC_KYWD0 = 1
const CC_LP = 17
const CC_LT = 12
const CC_MINUS = 11
const CC_NONE = 0
const CC_NUL = 29
const CC_PERCENT = 22
const CC_PIE = 2
const CC_PIPE = 10
const CC_PLUS = 20
const CC_PREVENTFULLOPEN = 4
const CC_QUOTE = 8
const CC_QUOTE2 = 9
const CC_RGBINIT = 1
const CC_ROUNDRECT = 256
const CC_RP = 18
const CC_SEMI = 19
const CC_SHOWHELP = 8
const CC_SLASH = 16
const CC_SOLIDCOLOR = 128
const CC_SPACE = 7
const CC_STAR = 21
const CC_STYLED = 32
const CC_TILDA = 25
const CC_VARALPHA = 5
const CC_VARNUM = 6
const CC_WIDE = 16
const CC_WIDESTYLED = 64
const CC_X = 0
const CDERR_DIALOGFAILURE = 65535
const CDERR_FINDRESFAILURE = 6
const CDERR_GENERALCODES = 0
const CDERR_INITIALIZATION = 2
const CDERR_LOADRESFAILURE = 7
const CDERR_LOADSTRFAILURE = 5
const CDERR_LOCKRESFAILURE = 8
const CDERR_MEMALLOCFAILURE = 9
const CDERR_MEMLOCKFAILURE = 10
const CDERR_NOHINSTANCE = 4
const CDERR_NOHOOK = 11
const CDERR_NOTEMPLATE = 3
const CDERR_REGISTERMSGFAIL = 12
const CDERR_STRUCTSIZE = 1
const CDM_FIRST = 1124
const CDM_GETFILEPATH = 1125
const CDM_GETFOLDERIDLIST = 1127
const CDM_GETFOLDERPATH = 1126
const CDM_GETSPEC = 1124
const CDM_HIDECONTROL = 1129
const CDM_LAST = 1224
const CDM_SETCONTROLTEXT = 1128
const CDM_SETDEFEXT = 1130
const CDN_FILEOK = 18446744073709551010
const CDN_FIRST = 18446744073709551015
const CDN_FOLDERCHANGE = 18446744073709551013
const CDN_HELP = 18446744073709551011
const CDN_INCLUDEITEM = 18446744073709551008
const CDN_INITDONE = 18446744073709551015
const CDN_LAST = 18446744073709550917
const CDN_SELCHANGE = 18446744073709551014
const CDN_SHAREVIOLATION = 18446744073709551012
const CDN_TYPECHANGE = 18446744073709551009
const CDS_DISABLE_UNSAFE_MODES = 512
const CDS_ENABLE_UNSAFE_MODES = 256
const CDS_FULLSCREEN = 4
const CDS_GLOBAL = 8
const CDS_NORESET = 268435456
const CDS_RESET = 1073741824
const CDS_RESET_EX = 536870912
const CDS_SET_PRIMARY = 16
const CDS_TEST = 2
const CDS_UPDATEREGISTRY = 1
const CDS_VIDEOPARAMETERS = 32
const CD_LBSELADD = 2
const CD_LBSELCHANGE = 0
const CD_LBSELNOITEMS = -1
const CD_LBSELSUB = 1
const CERT_ACCESS_STATE_GP_SYSTEM_STORE_FLAG = 8
const CERT_ACCESS_STATE_LM_SYSTEM_STORE_FLAG = 4
const CERT_ACCESS_STATE_PROP_ID = 14
const CERT_ACCESS_STATE_SHARED_USER_FLAG = 16
const CERT_ACCESS_STATE_SYSTEM_STORE_FLAG = 2
const CERT_ACCESS_STATE_WRITE_PERSIST_FLAG = 1
const CERT_AIA_URL_RETRIEVED_PROP_ID = 67
const CERT_ALT_NAME_DIRECTORY_NAME = 5
const CERT_ALT_NAME_DNS_NAME = 3
const CERT_ALT_NAME_EDI_PARTY_NAME = 6
const CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK = 255
const CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT = 16
const CERT_ALT_NAME_IP_ADDRESS = 8
const CERT_ALT_NAME_OTHER_NAME = 1
const CERT_ALT_NAME_REGISTERED_ID = 9
const CERT_ALT_NAME_RFC822_NAME = 2
const CERT_ALT_NAME_URL = 7
const CERT_ALT_NAME_VALUE_ERR_INDEX_MASK = 65535
const CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT = 0
const CERT_ALT_NAME_X400_ADDRESS = 4
const CERT_ARCHIVED_KEY_HASH_PROP_ID = 65
const CERT_ARCHIVED_PROP_ID = 19
const CERT_AUTHORITY_INFO_ACCESS_PROP_ID = 68
const CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_PARTIAL_CHAIN_LOGGING_FLAG = 2
const CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_UNTRUSTED_ROOT_LOGGING_FLAG = 1
const CERT_AUTH_ROOT_AUTO_UPDATE_ENCODED_CTL_VALUE_NAME = "EncodedCtl"
const CERT_AUTH_ROOT_AUTO_UPDATE_FLAGS_VALUE_NAME = "Flags"
const CERT_AUTH_ROOT_AUTO_UPDATE_LAST_SYNC_TIME_VALUE_NAME = "LastSyncTime"
const CERT_AUTH_ROOT_AUTO_UPDATE_LOCAL_MACHINE_REGPATH = "CERT_AUTO_UPDATE_LOCAL_MACHINE_REGPATH"
const CERT_AUTH_ROOT_AUTO_UPDATE_ROOT_DIR_URL_VALUE_NAME = "CERT_AUTO_UPDATE_ROOT_DIR_URL_VALUE_NAME"
const CERT_AUTH_ROOT_AUTO_UPDATE_SYNC_DELTA_TIME_VALUE_NAME = "SyncDeltaTime"
const CERT_AUTH_ROOT_CAB_FILENAME = "authrootstl.cab"
const CERT_AUTH_ROOT_CERT_EXT = ".crt"
const CERT_AUTH_ROOT_CTL_FILENAME = "authroot.stl"
const CERT_AUTH_ROOT_CTL_FILENAME_A = "authroot.stl"
const CERT_AUTH_ROOT_SEQ_FILENAME = "authrootseq.txt"
const CERT_AUTH_ROOT_SHA256_HASH_PROP_ID = 98
const CERT_AUTO_ENROLL_PROP_ID = 21
const CERT_AUTO_ENROLL_RETRY_PROP_ID = 66
const CERT_AUTO_UPDATE_DISABLE_RANDOM_QUERY_STRING_FLAG = 4
const CERT_AUTO_UPDATE_ROOT_DIR_URL_VALUE_NAME = "RootDirUrl"
const CERT_AUTO_UPDATE_SYNC_FROM_DIR_URL_VALUE_NAME = "SyncFromDirUrl"
const CERT_BACKED_UP_PROP_ID = 69
const CERT_BIOMETRIC_OID_DATA_CHOICE = 2
const CERT_BIOMETRIC_PICTURE_TYPE = 0
const CERT_BIOMETRIC_PREDEFINED_DATA_CHOICE = 1
const CERT_BIOMETRIC_SIGNATURE_TYPE = 1
const CERT_BUNDLE_CERTIFICATE = 0
const CERT_BUNDLE_CRL = 1
const CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG = 2
const CERT_CA_DISABLE_CRL_PROP_ID = 82
const CERT_CA_OCSP_AUTHORITY_INFO_ACCESS_PROP_ID = 81
const CERT_CA_SUBJECT_FLAG = 128
const CERT_CEP_PROP_ID = 87
const CERT_CHAIN_AUTO_CURRENT_USER = 1
const CERT_CHAIN_AUTO_FLAGS_VALUE_NAME = "AutoFlags"
const CERT_CHAIN_AUTO_FLUSH_DISABLE_FLAG = 1
const CERT_CHAIN_AUTO_FLUSH_FIRST_DELTA_SECONDS_DEFAULT = 300
const CERT_CHAIN_AUTO_FLUSH_FIRST_DELTA_SECONDS_VALUE_NAME = "AutoFlushFirstDeltaSeconds"
const CERT_CHAIN_AUTO_FLUSH_NEXT_DELTA_SECONDS_DEFAULT = 1800
const CERT_CHAIN_AUTO_FLUSH_NEXT_DELTA_SECONDS_VALUE_NAME = "AutoFlushNextDeltaSeconds"
const CERT_CHAIN_AUTO_HPKP_RULE_INFO = 8
const CERT_CHAIN_AUTO_IMPERSONATED = 3
const CERT_CHAIN_AUTO_LOCAL_MACHINE = 2
const CERT_CHAIN_AUTO_LOG_CREATE_FLAG = 2
const CERT_CHAIN_AUTO_LOG_FILE_NAME_VALUE_NAME = "AutoLogFileName"
const CERT_CHAIN_AUTO_LOG_FLAGS = 14
const CERT_CHAIN_AUTO_LOG_FLUSH_FLAG = 8
const CERT_CHAIN_AUTO_LOG_FREE_FLAG = 4
const CERT_CHAIN_AUTO_NETWORK_INFO = 6
const CERT_CHAIN_AUTO_PINRULE_INFO = 5
const CERT_CHAIN_AUTO_PROCESS_INFO = 4
const CERT_CHAIN_AUTO_SERIAL_LOCAL_MACHINE = 7
const CERT_CHAIN_CACHE_END_CERT = 1
const CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL = 4
const CERT_CHAIN_CACHE_RESYNC_FILETIME_VALUE_NAME = "ChainCacheResyncFiletime"
const CERT_CHAIN_CONFIG_REGPATH = "Software\\\\Microsoft\\\\Cryptography\\\\OID\\\\EncodingType 0\\\\CertDllCreateCertificateChainEngine\\\\Config"
const CERT_CHAIN_CRL_VALIDITY_EXT_PERIOD_HOURS_DEFAULT = 12
const CERT_CHAIN_CRL_VALIDITY_EXT_PERIOD_HOURS_VALUE_NAME = "CRLValidityExtensionPeriod"
const CERT_CHAIN_CROSS_CERT_DOWNLOAD_INTERVAL_HOURS_DEFAULT = 168
const CERT_CHAIN_CROSS_CERT_DOWNLOAD_INTERVAL_HOURS_VALUE_NAME = "CrossCertDownloadIntervalHours"
const CERT_CHAIN_DEFAULT_CONFIG_SUBDIR = "Default"
const CERT_CHAIN_DISABLE_AIA = 8192
const CERT_CHAIN_DISABLE_AIA_URL_RETRIEVAL_VALUE_NAME = "DisableAIAUrlRetrieval"
const CERT_CHAIN_DISABLE_ALL_EKU_WEAK_FLAG = 65536
const CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE = 256
const CERT_CHAIN_DISABLE_AUTO_FLUSH_PROCESS_NAME_LIST_VALUE_NAME = "DisableAutoFlushProcessNameList"
const CERT_CHAIN_DISABLE_CA_NAME_CONSTRAINTS_VALUE_NAME = "DisableCANameConstraints"
const CERT_CHAIN_DISABLE_CODE_SIGNING_WEAK_FLAG = 4194304
const CERT_CHAIN_DISABLE_FILE_HASH_WEAK_FLAG = 4096
const CERT_CHAIN_DISABLE_FILE_HASH_WEAK_FLAGS = 12288
const CERT_CHAIN_DISABLE_MANDATORY_BASIC_CONSTRAINTS_VALUE_NAME = "DisableMandatoryBasicConstraints"
const CERT_CHAIN_DISABLE_MD2_MD4 = 4096
const CERT_CHAIN_DISABLE_MOTW_CODE_SIGNING_WEAK_FLAG = 8388608
const CERT_CHAIN_DISABLE_MOTW_FILE_HASH_WEAK_FLAG = 8192
const CERT_CHAIN_DISABLE_MOTW_TIMESTAMP_HASH_WEAK_FLAG = 32768
const CERT_CHAIN_DISABLE_MOTW_TIMESTAMP_WEAK_FLAG = 134217728
const CERT_CHAIN_DISABLE_MY_PEER_TRUST = 2048
const CERT_CHAIN_DISABLE_OPT_IN_SERVER_AUTH_WEAK_FLAG = 262144
const CERT_CHAIN_DISABLE_PASS1_QUALITY_FILTERING = 64
const CERT_CHAIN_DISABLE_SERIAL_CHAIN_VALUE_NAME = "DisableSerialChain"
const CERT_CHAIN_DISABLE_SERVER_AUTH_WEAK_FLAG = 1048576
const CERT_CHAIN_DISABLE_SYNC_WITH_SSL_TIME_VALUE_NAME = "DisableSyncWithSslTime"
const CERT_CHAIN_DISABLE_TIMESTAMP_HASH_WEAK_FLAG = 16384
const CERT_CHAIN_DISABLE_TIMESTAMP_HASH_WEAK_FLAGS = 49152
const CERT_CHAIN_DISABLE_TIMESTAMP_WEAK_FLAG = 67108864
const CERT_CHAIN_DISABLE_UNSUPPORTED_CRITICAL_EXTENSIONS_VALUE_NAME = "DisableUnsupportedCriticalExtensions"
const CERT_CHAIN_DISABLE_WEAK_FLAGS = 215285760
const CERT_CHAIN_ENABLE_ALL_EKU_HYGIENE_FLAG = 131072
const CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE = 16
const CERT_CHAIN_ENABLE_CODE_SIGNING_HYGIENE_FLAG = 16777216
const CERT_CHAIN_ENABLE_HYGIENE_FLAGS = 857866240
const CERT_CHAIN_ENABLE_MD2_MD4_FLAG = 1
const CERT_CHAIN_ENABLE_MOTW_CODE_SIGNING_HYGIENE_FLAG = 33554432
const CERT_CHAIN_ENABLE_MOTW_TIMESTAMP_HYGIENE_FLAG = 536870912
const CERT_CHAIN_ENABLE_ONLY_WEAK_LOGGING_FLAG = 8
const CERT_CHAIN_ENABLE_PEER_TRUST = 1024
const CERT_CHAIN_ENABLE_SERVER_AUTH_HYGIENE_FLAG = 2097152
const CERT_CHAIN_ENABLE_SHARE_STORE = 32
const CERT_CHAIN_ENABLE_TIMESTAMP_HYGIENE_FLAG = 268435456
const CERT_CHAIN_ENABLE_WEAK_LOGGING_FLAG = 4
const CERT_CHAIN_ENABLE_WEAK_RSA_ROOT_FLAG = 2
const CERT_CHAIN_ENABLE_WEAK_SETTINGS_FLAG = 2147483648
const CERT_CHAIN_ENABLE_WEAK_SIGNATURE_FLAGS_VALUE_NAME = "EnableWeakSignatureFlags"
const CERT_CHAIN_EXCLUSIVE_ENABLE_CA_FLAG = 1
const CERT_CHAIN_FIND_BY_ISSUER = 1
const CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG = 32768
const CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG = 4
const CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG = 1
const CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG = 2
const CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG = 8
const CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG = 16384
const CERT_CHAIN_HAS_MOTW = 16384
const CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_DEFAULT = 5
const CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_VALUE_NAME = "MaxAIAUrlCountInCert"
const CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_DEFAULT = 100000
const CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_VALUE_NAME = "MaxAIAUrlRetrievalByteCount"
const CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_DEFAULT = 10
const CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_VALUE_NAME = "MaxAIAUrlRetrievalCertCount"
const CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_DEFAULT = 3
const CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_VALUE_NAME = "MaxAIAUrlRetrievalCountPerChain"
const CERT_CHAIN_MAX_SSL_TIME_UPDATED_EVENT_COUNT_DEFAULT = 5
const CERT_CHAIN_MAX_SSL_TIME_UPDATED_EVENT_COUNT_DISABLE = 4294967295
const CERT_CHAIN_MAX_SSL_TIME_UPDATED_EVENT_COUNT_VALUE_NAME = "MaxSslTimeUpdatedEventCount"
const CERT_CHAIN_MAX_URL_RETRIEVAL_BYTE_COUNT_DEFAULT = 104857600
const CERT_CHAIN_MAX_URL_RETRIEVAL_BYTE_COUNT_VALUE_NAME = "MaxUrlRetrievalByteCount"
const CERT_CHAIN_MIN_PUB_KEY_BIT_LENGTH_DISABLE = 4294967295
const CERT_CHAIN_MIN_RSA_PUB_KEY_BIT_LENGTH_DEFAULT = 1023
const CERT_CHAIN_MIN_RSA_PUB_KEY_BIT_LENGTH_DISABLE = 4294967295
const CERT_CHAIN_MIN_RSA_PUB_KEY_BIT_LENGTH_VALUE_NAME = "MinRsaPubKeyBitLength"
const CERT_CHAIN_MOTW_IGNORE_AFTER_TIME_WEAK_FLAG = 1073741824
const CERT_CHAIN_MOTW_WEAK_FLAGS = 1786773504
const CERT_CHAIN_OCSP_VALIDITY_SECONDS_DEFAULT = 43200
const CERT_CHAIN_OCSP_VALIDITY_SECONDS_VALUE_NAME = "OcspValiditySeconds"
const CERT_CHAIN_ONLY_ADDITIONAL_AND_AUTH_ROOT = 32768
const CERT_CHAIN_OPTIONS_VALUE_NAME = "Options"
const CERT_CHAIN_OPTION_DISABLE_AIA_URL_RETRIEVAL = 2
const CERT_CHAIN_OPTION_ENABLE_SIA_URL_RETRIEVAL = 4
const CERT_CHAIN_OPT_IN_WEAK_FLAGS = 262144
const CERT_CHAIN_OPT_IN_WEAK_SIGNATURE = 65536
const CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG = 32768
const CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG = 16
const CERT_CHAIN_POLICY_IGNORE_ALL_NOT_TIME_VALID_FLAGS = 7
const CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS = 3840
const CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG = 1024
const CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG = 2
const CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG = 512
const CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG = 256
const CERT_CHAIN_POLICY_IGNORE_INVALID_BASIC_CONSTRAINTS_FLAG = 8
const CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG = 64
const CERT_CHAIN_POLICY_IGNORE_INVALID_POLICY_FLAG = 128
const CERT_CHAIN_POLICY_IGNORE_NOT_SUPPORTED_CRITICAL_EXT_FLAG = 8192
const CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG = 4
const CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG = 1
const CERT_CHAIN_POLICY_IGNORE_PEER_TRUST_FLAG = 4096
const CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG = 2048
const CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG = 32
const CERT_CHAIN_POLICY_SSL_F12_ERROR_LEVEL = 2
const CERT_CHAIN_POLICY_SSL_F12_NONE_CATEGORY = 0
const CERT_CHAIN_POLICY_SSL_F12_ROOT_PROGRAM_CATEGORY = 2
const CERT_CHAIN_POLICY_SSL_F12_SUCCESS_LEVEL = 0
const CERT_CHAIN_POLICY_SSL_F12_WARNING_LEVEL = 1
const CERT_CHAIN_POLICY_SSL_F12_WEAK_CRYPTO_CATEGORY = 1
const CERT_CHAIN_POLICY_SSL_KEY_PIN_MISMATCH_ERROR = -2
const CERT_CHAIN_POLICY_SSL_KEY_PIN_MISMATCH_WARNING = 2
const CERT_CHAIN_POLICY_SSL_KEY_PIN_MITM_ERROR = -1
const CERT_CHAIN_POLICY_SSL_KEY_PIN_MITM_WARNING = 1
const CERT_CHAIN_POLICY_SSL_KEY_PIN_SUCCESS = 0
const CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG = 16384
const CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS = 128
const CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT = 134217728
const CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY = 2147483648
const CERT_CHAIN_REVOCATION_CHECK_CHAIN = 536870912
const CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = 1073741824
const CERT_CHAIN_REVOCATION_CHECK_END_CERT = 268435456
const CERT_CHAIN_REVOCATION_CHECK_OCSP_CERT = 67108864
const CERT_CHAIN_REV_ACCUMULATIVE_URL_RETRIEVAL_TIMEOUT_MILLISECONDS_DEFAULT = 20000
const CERT_CHAIN_REV_ACCUMULATIVE_URL_RETRIEVAL_TIMEOUT_MILLISECONDS_VALUE_NAME = "ChainRevAccumulativeUrlRetrievalTimeoutMilliseconds"
const CERT_CHAIN_SERIAL_CHAIN_LOG_FILE_NAME_VALUE_NAME = "SerialChainLogFileName"
const CERT_CHAIN_SSL_HANDSHAKE_LOG_FILE_NAME_VALUE_NAME = "SslHandshakeLogFileName"
const CERT_CHAIN_STRONG_SIGN_DISABLE_END_CHECK_FLAG = 1
const CERT_CHAIN_THREAD_STORE_SYNC = 2
const CERT_CHAIN_TIMESTAMP_TIME = 512
const CERT_CHAIN_URL_RETRIEVAL_TIMEOUT_MILLISECONDS_DEFAULT = 15000
const CERT_CHAIN_URL_RETRIEVAL_TIMEOUT_MILLISECONDS_VALUE_NAME = "ChainUrlRetrievalTimeoutMilliseconds"
const CERT_CHAIN_USE_LOCAL_MACHINE_STORE = 8
const CERT_CHAIN_WEAK_AFTER_TIME_NAME = "AfterTime"
const CERT_CHAIN_WEAK_ALL_CONFIG_NAME = "All"
const CERT_CHAIN_WEAK_FILE_HASH_AFTER_TIME_NAME = "FileHashAfterTime"
const CERT_CHAIN_WEAK_FLAGS_NAME = "Flags"
const CERT_CHAIN_WEAK_HYGIENE_NAME = "Hygiene"
const CERT_CHAIN_WEAK_MIN_BIT_LENGTH_NAME = "MinBitLength"
const CERT_CHAIN_WEAK_PREFIX_NAME = "Weak"
const CERT_CHAIN_WEAK_RSA_PUB_KEY_TIME_DEFAULT = 129067776000000000
const CERT_CHAIN_WEAK_RSA_PUB_KEY_TIME_VALUE_NAME = "WeakRsaPubKeyTime"
const CERT_CHAIN_WEAK_SHA256_ALLOW_NAME = "Sha256Allow"
const CERT_CHAIN_WEAK_SIGNATURE_LOG_DIR_VALUE_NAME = "WeakSignatureLogDir"
const CERT_CHAIN_WEAK_THIRD_PARTY_CONFIG_NAME = "ThirdParty"
const CERT_CHAIN_WEAK_TIMESTAMP_HASH_AFTER_TIME_NAME = "TimestampHashAfterTime"
const CERT_CLOSE_STORE_CHECK_FLAG = 2
const CERT_CLOSE_STORE_FORCE_FLAG = 1
const CERT_CLR_DELETE_KEY_PROP_ID = 125
const CERT_COMPARE_ANY = 0
const CERT_COMPARE_ATTR = 3
const CERT_COMPARE_CERT_ID = 16
const CERT_COMPARE_CROSS_CERT_DIST_POINTS = 17
const CERT_COMPARE_CTL_USAGE = 10
const CERT_COMPARE_ENHKEY_USAGE = 10
const CERT_COMPARE_EXISTING = 13
const CERT_COMPARE_HASH = 1
const CERT_COMPARE_HASH_STR = 20
const CERT_COMPARE_HAS_PRIVATE_KEY = 21
const CERT_COMPARE_ISSUER_OF = 12
const CERT_COMPARE_KEY_IDENTIFIER = 15
const CERT_COMPARE_KEY_SPEC = 9
const CERT_COMPARE_MASK = 65535
const CERT_COMPARE_MD5_HASH = 4
const CERT_COMPARE_NAME = 2
const CERT_COMPARE_NAME_STR_A = 7
const CERT_COMPARE_NAME_STR_W = 8
const CERT_COMPARE_PROPERTY = 5
const CERT_COMPARE_PUBKEY_MD5_HASH = 18
const CERT_COMPARE_PUBLIC_KEY = 6
const CERT_COMPARE_SHA1_HASH = 1
const CERT_COMPARE_SHIFT = 16
const CERT_COMPARE_SIGNATURE_HASH = 14
const CERT_COMPARE_SUBJECT_CERT = 11
const CERT_COMPARE_SUBJECT_INFO_ACCESS = 19
const CERT_CONTEXT_REVOCATION_TYPE = 1
const CERT_CREATE_CONTEXT_NOCOPY_FLAG = 1
const CERT_CREATE_CONTEXT_NO_ENTRY_FLAG = 8
const CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG = 4
const CERT_CREATE_CONTEXT_SORTED_FLAG = 2
const CERT_CREATE_SELFSIGN_NO_KEY_INFO = 2
const CERT_CREATE_SELFSIGN_NO_SIGN = 1
const CERT_CRL_SIGN_KEY_USAGE = 2
const CERT_CROSS_CERT_DIST_POINTS_PROP_ID = 23
const CERT_CTL_USAGE_PROP_ID = 9
const CERT_DATA_ENCIPHERMENT_KEY_USAGE = 16
const CERT_DATE_STAMP_PROP_ID = 27
const CERT_DECIPHER_ONLY_KEY_USAGE = 128
const CERT_DEFAULT_OID_PUBLIC_KEY_SIGN = "szOID_RSA_RSA"
const CERT_DEFAULT_OID_PUBLIC_KEY_XCHG = "szOID_RSA_RSA"
const CERT_DESCRIPTION_PROP_ID = 13
const CERT_DIGITAL_SIGNATURE_KEY_USAGE = 128
const CERT_DISABLE_PIN_RULES_AUTO_UPDATE_VALUE_NAME = "DisablePinRulesAutoUpdate"
const CERT_DISABLE_ROOT_AUTO_UPDATE_VALUE_NAME = "DisableRootAutoUpdate"
const CERT_DISALLOWED_CERT_AUTO_UPDATE_ENCODED_CTL_VALUE_NAME = "DisallowedCertEncodedCtl"
const CERT_DISALLOWED_CERT_AUTO_UPDATE_LAST_SYNC_TIME_VALUE_NAME = "DisallowedCertLastSyncTime"
const CERT_DISALLOWED_CERT_AUTO_UPDATE_LIST_IDENTIFIER = "DisallowedCert_AutoUpdate_1"
const CERT_DISALLOWED_CERT_AUTO_UPDATE_SYNC_DELTA_TIME_VALUE_NAME = "DisallowedCertSyncDeltaTime"
const CERT_DISALLOWED_CERT_CAB_FILENAME = "disallowedcertstl.cab"
const CERT_DISALLOWED_CERT_CTL_FILENAME = "disallowedcert.stl"
const CERT_DISALLOWED_CERT_CTL_FILENAME_A = "disallowedcert.stl"
const CERT_DISALLOWED_ENHKEY_USAGE_PROP_ID = 122
const CERT_DISALLOWED_FILETIME_PROP_ID = 104
const CERT_DSS_R_LEN = 20
const CERT_DSS_SIGNATURE_LEN = 40
const CERT_DSS_S_LEN = 20
const CERT_EFSBLOB_VALUE_NAME = "EFSBlob"
const CERT_EFS_PROP_ID = 17
const CERT_ENABLE_DISALLOWED_CERT_AUTO_UPDATE_VALUE_NAME = "EnableDisallowedCertAutoUpdate"
const CERT_ENCIPHER_ONLY_KEY_USAGE = 1
const CERT_ENCODING_TYPE_MASK = 65535
const CERT_END_ENTITY_SUBJECT_FLAG = 64
const CERT_ENHKEY_USAGE_PROP_ID = 9
const CERT_ENROLLMENT_PROP_ID = 26
const CERT_EXCLUDED_SUBTREE_BIT = 2147483648
const CERT_EXTENDED_ERROR_INFO_PROP_ID = 30
const CERT_FILE_HASH_USE_TYPE = 1
const CERT_FILE_STORE_COMMIT_ENABLE_FLAG = 65536
const CERT_FIND_ANY = 0
const CERT_FIND_CERT_ID = 1048576
const CERT_FIND_CROSS_CERT_DIST_POINTS = 1114112
const CERT_FIND_CTL_USAGE = 655360
const CERT_FIND_ENHKEY_USAGE = 655360
const CERT_FIND_EXISTING = 851968
const CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG = 2
const CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG = 2
const CERT_FIND_HASH = 65536
const CERT_FIND_HASH_STR = 1310720
const CERT_FIND_HAS_PRIVATE_KEY = 1376256
const CERT_FIND_ISSUER_ATTR = 196612
const CERT_FIND_ISSUER_NAME = 131076
const CERT_FIND_ISSUER_OF = 786432
const CERT_FIND_ISSUER_STR = 524292
const CERT_FIND_ISSUER_STR_A = 458756
const CERT_FIND_ISSUER_STR_W = 524292
const CERT_FIND_KEY_IDENTIFIER = 983040
const CERT_FIND_KEY_SPEC = 589824
const CERT_FIND_MD5_HASH = 262144
const CERT_FIND_NO_CTL_USAGE_FLAG = 8
const CERT_FIND_NO_ENHKEY_USAGE_FLAG = 8
const CERT_FIND_OPTIONAL_CTL_USAGE_FLAG = 1
const CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG = 1
const CERT_FIND_OR_CTL_USAGE_FLAG = 16
const CERT_FIND_OR_ENHKEY_USAGE_FLAG = 16
const CERT_FIND_PROPERTY = 327680
const CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG = 4
const CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG = 4
const CERT_FIND_PUBKEY_MD5_HASH = 1179648
const CERT_FIND_PUBLIC_KEY = 393216
const CERT_FIND_SHA1_HASH = 65536
const CERT_FIND_SIGNATURE_HASH = 917504
const CERT_FIND_SUBJECT_ATTR = 196615
const CERT_FIND_SUBJECT_CERT = 720896
const CERT_FIND_SUBJECT_INFO_ACCESS = 1245184
const CERT_FIND_SUBJECT_NAME = 131079
const CERT_FIND_SUBJECT_STR = 524295
const CERT_FIND_SUBJECT_STR_A = 458759
const CERT_FIND_SUBJECT_STR_W = 524295
const CERT_FIND_VALID_CTL_USAGE_FLAG = 32
const CERT_FIND_VALID_ENHKEY_USAGE_FLAG = 32
const CERT_FIRST_RESERVED_PROP_ID = 107
const CERT_FIRST_USER_PROP_ID = 32768
const CERT_FORTEZZA_DATA_PROP_ID = 18
const CERT_FRIENDLY_NAME_PROP_ID = 11
const CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH = "Software\\\\Policies\\\\Microsoft\\\\SystemCertificates"
const CERT_HASH_PROP_ID = 3
const CERT_HCRYPTPROV_OR_NCRYPT_KEY_HANDLE_PROP_ID = 79
const CERT_HCRYPTPROV_TRANSFER_PROP_ID = 100
const CERT_ID_ISSUER_SERIAL_NUMBER = 1
const CERT_ID_KEY_IDENTIFIER = 2
const CERT_ID_SHA1_HASH = 3
const CERT_IE30_RESERVED_PROP_ID = 7
const CERT_IE_DIRTY_FLAGS_REGPATH = "Software\\\\Microsoft\\\\Cryptography\\\\IEDirtyFlags"
const CERT_INFO_EXTENSION_FLAG = 11
const CERT_INFO_ISSUER_FLAG = 4
const CERT_INFO_ISSUER_UNIQUE_ID_FLAG = 9
const CERT_INFO_NOT_AFTER_FLAG = 6
const CERT_INFO_NOT_BEFORE_FLAG = 5
const CERT_INFO_SERIAL_NUMBER_FLAG = 2
const CERT_INFO_SIGNATURE_ALGORITHM_FLAG = 3
const CERT_INFO_SUBJECT_FLAG = 7
const CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG = 8
const CERT_INFO_SUBJECT_UNIQUE_ID_FLAG = 10
const CERT_INFO_VERSION_FLAG = 1
const CERT_ISOLATED_KEY_PROP_ID = 118
const CERT_ISSUER_CHAIN_PUB_KEY_CNG_ALG_BIT_LENGTH_PROP_ID = 96
const CERT_ISSUER_CHAIN_SIGN_HASH_CNG_ALG_PROP_ID = 95
const CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID = 24
const CERT_ISSUER_PUB_KEY_BIT_LENGTH_PROP_ID = 94
const CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID = 28
const CERT_KEYGEN_REQUEST_V1 = 0
const CERT_KEY_AGREEMENT_KEY_USAGE = 8
const CERT_KEY_CERT_SIGN_KEY_USAGE = 4
const CERT_KEY_CLASSIFICATION_PROP_ID = 120
const CERT_KEY_CONTEXT_PROP_ID = 5
const CERT_KEY_ENCIPHERMENT_KEY_USAGE = 32
const CERT_KEY_IDENTIFIER_PROP_ID = 20
const CERT_KEY_PROV_HANDLE_PROP_ID = 1
const CERT_KEY_PROV_INFO_PROP_ID = 2
const CERT_KEY_REPAIR_ATTEMPTED_PROP_ID = 103
const CERT_KEY_SPEC_PROP_ID = 6
const CERT_LAST_RESERVED_PROP_ID = 32767
const CERT_LAST_USER_PROP_ID = 65535
const CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG = 131072
const CERT_LDAP_STORE_OPENED_FLAG = 262144
const CERT_LDAP_STORE_SIGN_FLAG = 65536
const CERT_LDAP_STORE_UNBIND_FLAG = 524288
const CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH = "Software\\\\Microsoft\\\\SystemCertificates"
const CERT_LOGOTYPE_BITS_IMAGE_RESOLUTION_CHOICE = 1
const CERT_LOGOTYPE_COLOR_IMAGE_INFO_CHOICE = 2
const CERT_LOGOTYPE_DIRECT_INFO_CHOICE = 1
const CERT_LOGOTYPE_GRAY_SCALE_IMAGE_INFO_CHOICE = 1
const CERT_LOGOTYPE_INDIRECT_INFO_CHOICE = 2
const CERT_LOGOTYPE_NO_IMAGE_RESOLUTION_CHOICE = 0
const CERT_LOGOTYPE_TABLE_SIZE_IMAGE_RESOLUTION_CHOICE = 2
const CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN = 48
const CERT_MD5_HASH_PROP_ID = 4
const CERT_NAME_ATTR_TYPE = 3
const CERT_NAME_DISABLE_IE4_UTF8_FLAG = 65536
const CERT_NAME_DNS_TYPE = 6
const CERT_NAME_EMAIL_TYPE = 1
const CERT_NAME_FRIENDLY_DISPLAY_TYPE = 5
const CERT_NAME_ISSUER_FLAG = 1
const CERT_NAME_RDN_TYPE = 2
const CERT_NAME_SEARCH_ALL_NAMES_FLAG = 2
const CERT_NAME_SIMPLE_DISPLAY_TYPE = 4
const CERT_NAME_STR_COMMA_FLAG = 67108864
const CERT_NAME_STR_CRLF_FLAG = 134217728
const CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG = 65536
const CERT_NAME_STR_DISABLE_UTF8_DIR_STR_FLAG = 1048576
const CERT_NAME_STR_ENABLE_PUNYCODE_FLAG = 2097152
const CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG = 131072
const CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG = 262144
const CERT_NAME_STR_FORCE_UTF8_DIR_STR_FLAG = 524288
const CERT_NAME_STR_FORWARD_FLAG = 16777216
const CERT_NAME_STR_NO_PLUS_FLAG = 536870912
const CERT_NAME_STR_NO_QUOTING_FLAG = 268435456
const CERT_NAME_STR_REVERSE_FLAG = 33554432
const CERT_NAME_STR_SEMICOLON_FLAG = 1073741824
const CERT_NAME_UPN_TYPE = 8
const CERT_NAME_URL_TYPE = 7
const CERT_NCRYPT_KEY_HANDLE_PROP_ID = 78
const CERT_NCRYPT_KEY_HANDLE_TRANSFER_PROP_ID = 99
const CERT_NCRYPT_KEY_SPEC = 4294967295
const CERT_NEW_KEY_PROP_ID = 74
const CERT_NEXT_UPDATE_LOCATION_PROP_ID = 10
const CERT_NONCOMPLIANT_ROOT_URL_PROP_ID = 123
const CERT_NON_REPUDIATION_KEY_USAGE = 64
const CERT_NOT_BEFORE_ENHKEY_USAGE_PROP_ID = 127
const CERT_NOT_BEFORE_FILETIME_PROP_ID = 126
const CERT_NO_AUTO_EXPIRE_CHECK_PROP_ID = 77
const CERT_NO_EXPIRE_NOTIFICATION_PROP_ID = 97
const CERT_OCM_SUBCOMPONENTS_LOCAL_MACHINE_REGPATH = "SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Setup\\\\OC Manager\\\\Subcomponents"
const CERT_OCM_SUBCOMPONENTS_ROOT_AUTO_UPDATE_VALUE_NAME = "RootAutoUpdate"
const CERT_OCSP_CACHE_PREFIX_PROP_ID = 75
const CERT_OCSP_MUST_STAPLE_PROP_ID = 121
const CERT_OCSP_RESPONSE_PROP_ID = 70
const CERT_OFFLINE_CRL_SIGN_KEY_USAGE = 2
const CERT_OID_NAME_STR = 2
const CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG = 1
const CERT_PHYSICAL_STORE_AUTH_ROOT_NAME = ".AuthRoot"
const CERT_PHYSICAL_STORE_DEFAULT_NAME = ".Default"
const CERT_PHYSICAL_STORE_DS_USER_CERTIFICATE_NAME = ".UserCertificate"
const CERT_PHYSICAL_STORE_ENTERPRISE_NAME = ".Enterprise"
const CERT_PHYSICAL_STORE_GROUP_POLICY_NAME = ".GroupPolicy"
const CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG = 8
const CERT_PHYSICAL_STORE_LOCAL_MACHINE_GROUP_POLICY_NAME = ".LocalMachineGroupPolicy"
const CERT_PHYSICAL_STORE_LOCAL_MACHINE_NAME = ".LocalMachine"
const CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG = 2
const CERT_PHYSICAL_STORE_PREDEFINED_ENUM_FLAG = 1
const CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG = 4
const CERT_PHYSICAL_STORE_SMART_CARD_NAME = ".SmartCard"
const CERT_PIN_RULES_AUTO_UPDATE_ENCODED_CTL_VALUE_NAME = "PinRulesEncodedCtl"
const CERT_PIN_RULES_AUTO_UPDATE_LAST_SYNC_TIME_VALUE_NAME = "PinRulesLastSyncTime"
const CERT_PIN_RULES_AUTO_UPDATE_LIST_IDENTIFIER = "PinRules_AutoUpdate_1"
const CERT_PIN_RULES_AUTO_UPDATE_SYNC_DELTA_TIME_VALUE_NAME = "PinRulesSyncDeltaTime"
const CERT_PIN_RULES_CAB_FILENAME = "pinrulesstl.cab"
const CERT_PIN_RULES_CTL_FILENAME = "pinrules.stl"
const CERT_PIN_RULES_CTL_FILENAME_A = "pinrules.stl"
const CERT_PIN_SHA256_HASH_PROP_ID = 124
const CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG = 1
const CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG = 8
const CERT_PROT_ROOT_DISABLE_NOT_DEFINED_NAME_CONSTRAINT_FLAG = 32
const CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG = 16
const CERT_PROT_ROOT_DISABLE_PEER_TRUST = 65536
const CERT_PROT_ROOT_FLAGS_VALUE_NAME = "Flags"
const CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG = 2
const CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG = 4
const CERT_PROT_ROOT_ONLY_LM_GPT_FLAG = 8
const CERT_PROT_ROOT_PEER_USAGES_VALUE_NAME = "PeerUsages"
const CERT_PROT_ROOT_PEER_USAGES_VALUE_NAME_A = "PeerUsages"
const CERT_PUBKEY_ALG_PARA_PROP_ID = 22
const CERT_PUBKEY_HASH_RESERVED_PROP_ID = 8
const CERT_PUB_KEY_CNG_ALG_BIT_LENGTH_PROP_ID = 93
const CERT_PVK_FILE_PROP_ID = 12
const CERT_QUERY_CONTENT_CERT = 1
const CERT_QUERY_CONTENT_CERT_PAIR = 13
const CERT_QUERY_CONTENT_CRL = 3
const CERT_QUERY_CONTENT_CTL = 2
const CERT_QUERY_CONTENT_FLAG_ALL = 16382
const CERT_QUERY_CONTENT_FLAG_ALL_ISSUER_CERT = 818
const CERT_QUERY_CONTENT_FLAG_CERT = 2
const CERT_QUERY_CONTENT_FLAG_CERT_PAIR = 8192
const CERT_QUERY_CONTENT_FLAG_CRL = 8
const CERT_QUERY_CONTENT_FLAG_CTL = 4
const CERT_QUERY_CONTENT_FLAG_PFX = 4096
const CERT_QUERY_CONTENT_FLAG_PFX_AND_LOAD = 16384
const CERT_QUERY_CONTENT_FLAG_PKCS10 = 2048
const CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED = 256
const CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED = 1024
const CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED = 512
const CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT = 32
const CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL = 128
const CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL = 64
const CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE = 16
const CERT_QUERY_CONTENT_PFX = 12
const CERT_QUERY_CONTENT_PFX_AND_LOAD = 14
const CERT_QUERY_CONTENT_PKCS10 = 11
const CERT_QUERY_CONTENT_PKCS7_SIGNED = 8
const CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED = 10
const CERT_QUERY_CONTENT_PKCS7_UNSIGNED = 9
const CERT_QUERY_CONTENT_SERIALIZED_CERT = 5
const CERT_QUERY_CONTENT_SERIALIZED_CRL = 7
const CERT_QUERY_CONTENT_SERIALIZED_CTL = 6
const CERT_QUERY_CONTENT_SERIALIZED_STORE = 4
const CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED = 3
const CERT_QUERY_FORMAT_BASE64_ENCODED = 2
const CERT_QUERY_FORMAT_BINARY = 1
const CERT_QUERY_FORMAT_FLAG_ALL = 14
const CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED = 8
const CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED = 4
const CERT_QUERY_FORMAT_FLAG_BINARY = 2
const CERT_QUERY_OBJECT_BLOB = 2
const CERT_QUERY_OBJECT_FILE = 1
const CERT_RDN_ANY_TYPE = 0
const CERT_RDN_BMP_STRING = 12
const CERT_RDN_DISABLE_CHECK_TYPE_FLAG = 1073741824
const CERT_RDN_DISABLE_IE4_UTF8_FLAG = 16777216
const CERT_RDN_ENABLE_PUNYCODE_FLAG = 33554432
const CERT_RDN_ENABLE_T61_UNICODE_FLAG = 2147483648
const CERT_RDN_ENABLE_UTF8_UNICODE_FLAG = 536870912
const CERT_RDN_ENCODED_BLOB = 1
const CERT_RDN_FLAGS_MASK = 4278190080
const CERT_RDN_FORCE_UTF8_UNICODE_FLAG = 268435456
const CERT_RDN_GENERAL_STRING = 10
const CERT_RDN_GRAPHIC_STRING = 8
const CERT_RDN_IA5_STRING = 7
const CERT_RDN_INT4_STRING = 11
const CERT_RDN_ISO646_STRING = 9
const CERT_RDN_NUMERIC_STRING = 3
const CERT_RDN_OCTET_STRING = 2
const CERT_RDN_PRINTABLE_STRING = 4
const CERT_RDN_T61_STRING = 5
const CERT_RDN_TELETEX_STRING = 5
const CERT_RDN_TYPE_MASK = 255
const CERT_RDN_UNICODE_STRING = 12
const CERT_RDN_UNIVERSAL_STRING = 11
const CERT_RDN_UTF8_STRING = 13
const CERT_RDN_VIDEOTEX_STRING = 6
const CERT_RDN_VISIBLE_STRING = 9
const CERT_REGISTRY_STORE_CLIENT_GPT_FLAG = 2147483648
const CERT_REGISTRY_STORE_EXTERNAL_FLAG = 1048576
const CERT_REGISTRY_STORE_LM_GPT_FLAG = 16777216
const CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG = 524288
const CERT_REGISTRY_STORE_REMOTE_FLAG = 65536
const CERT_REGISTRY_STORE_ROAMING_FLAG = 262144
const CERT_REGISTRY_STORE_SERIALIZED_FLAG = 131072
const CERT_RENEWAL_PROP_ID = 64
const CERT_REQUEST_ORIGINATOR_PROP_ID = 71
const CERT_REQUEST_V1 = 0
const CERT_RETR_BEHAVIOR_FILE_VALUE_NAME = "AllowFileUrlScheme"
const CERT_RETR_BEHAVIOR_INET_AUTH_VALUE_NAME = "EnableInetUnknownAuth"
const CERT_RETR_BEHAVIOR_INET_STATUS_VALUE_NAME = "EnableInetLocal"
const CERT_RETR_BEHAVIOR_LDAP_VALUE_NAME = "DisableLDAPSignAndEncrypt"
const CERT_ROOT_PROGRAM_CERT_POLICIES_PROP_ID = 83
const CERT_ROOT_PROGRAM_CHAIN_POLICIES_PROP_ID = 105
const CERT_ROOT_PROGRAM_FLAG_ADDRESS = 8
const CERT_ROOT_PROGRAM_FLAG_LSC = 64
const CERT_ROOT_PROGRAM_FLAG_ORG = 128
const CERT_ROOT_PROGRAM_FLAG_OU = 16
const CERT_ROOT_PROGRAM_FLAG_SUBJECT_LOGO = 32
const CERT_ROOT_PROGRAM_NAME_CONSTRAINTS_PROP_ID = 84
const CERT_RSA_PUBLIC_KEY_OBJID = "szOID_RSA_RSA"
const CERT_SCARD_PIN_ID_PROP_ID = 90
const CERT_SCARD_PIN_INFO_PROP_ID = 91
const CERT_SCEP_CA_CERT_PROP_ID = 111
const CERT_SCEP_ENCRYPT_HASH_CNG_ALG_PROP_ID = 114
const CERT_SCEP_FLAGS_PROP_ID = 115
const CERT_SCEP_GUID_PROP_ID = 116
const CERT_SCEP_NONCE_PROP_ID = 113
const CERT_SCEP_RA_ENCRYPTION_CERT_PROP_ID = 110
const CERT_SCEP_RA_SIGNATURE_CERT_PROP_ID = 109
const CERT_SCEP_SERVER_CERTS_PROP_ID = 108
const CERT_SCEP_SIGNER_CERT_PROP_ID = 112
const CERT_SELECT_ALLOW_DUPLICATES = 128
const CERT_SELECT_ALLOW_EXPIRED = 1
const CERT_SELECT_BY_ENHKEY_USAGE = 1
const CERT_SELECT_BY_EXTENSION = 5
const CERT_SELECT_BY_FRIENDLYNAME = 13
const CERT_SELECT_BY_ISSUER_ATTR = 7
const CERT_SELECT_BY_ISSUER_DISPLAYNAME = 12
const CERT_SELECT_BY_ISSUER_NAME = 9
const CERT_SELECT_BY_KEY_USAGE = 2
const CERT_SELECT_BY_POLICY_OID = 3
const CERT_SELECT_BY_PROV_NAME = 4
const CERT_SELECT_BY_PUBLIC_KEY = 10
const CERT_SELECT_BY_SUBJECT_ATTR = 8
const CERT_SELECT_BY_SUBJECT_HOST_NAME = 6
const CERT_SELECT_BY_THUMBPRINT = 14
const CERT_SELECT_BY_TLS_SIGNATURES = 11
const CERT_SELECT_DISALLOW_SELFSIGNED = 4
const CERT_SELECT_HARDWARE_ONLY = 64
const CERT_SELECT_HAS_KEY_FOR_KEY_EXCHANGE = 32
const CERT_SELECT_HAS_KEY_FOR_SIGNATURE = 16
const CERT_SELECT_HAS_PRIVATE_KEY = 8
const CERT_SELECT_IGNORE_AUTOSELECT = 256
const CERT_SELECT_LAST = 11
const CERT_SELECT_MAX = 33
const CERT_SELECT_MAX_PARA = 500
const CERT_SELECT_TRUSTED_ROOT = 2
const CERT_SEND_AS_TRUSTED_ISSUER_PROP_ID = 102
const CERT_SERIALIZABLE_KEY_CONTEXT_PROP_ID = 117
const CERT_SERIAL_CHAIN_PROP_ID = 119
const CERT_SERVER_OCSP_RESPONSE_ASYNC_FLAG = 1
const CERT_SERVER_OCSP_RESPONSE_OPEN_PARA_READ_FLAG = 1
const CERT_SERVER_OCSP_RESPONSE_OPEN_PARA_WRITE_FLAG = 2
const CERT_SET_KEY_CONTEXT_PROP_ID = 1
const CERT_SET_KEY_PROV_HANDLE_PROP_ID = 1
const CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG = 2147483648
const CERT_SET_PROPERTY_INHIBIT_PERSIST_FLAG = 1073741824
const CERT_SHA1_HASH_PROP_ID = 3
const CERT_SHA256_HASH_PROP_ID = 107
const CERT_SIGNATURE_HASH_PROP_ID = 15
const CERT_SIGN_HASH_CNG_ALG_PROP_ID = 89
const CERT_SIMPLE_NAME_STR = 1
const CERT_SMART_CARD_DATA_PROP_ID = 16
const CERT_SMART_CARD_READER_NON_REMOVABLE_PROP_ID = 106
const CERT_SMART_CARD_READER_PROP_ID = 101
const CERT_SMART_CARD_ROOT_INFO_PROP_ID = 76
const CERT_SOURCE_LOCATION_PROP_ID = 72
const CERT_SOURCE_URL_PROP_ID = 73
const CERT_SRV_OCSP_RESP_MAX_BEFORE_NEXT_UPDATE_SECONDS_DEFAULT = 14400
const CERT_SRV_OCSP_RESP_MAX_BEFORE_NEXT_UPDATE_SECONDS_VALUE_NAME = "SrvOcspRespMaxBeforeNextUpdateSeconds"
const CERT_SRV_OCSP_RESP_MAX_SYNC_CERT_FILE_SECONDS_DEFAULT = 3600
const CERT_SRV_OCSP_RESP_MAX_SYNC_CERT_FILE_SECONDS_VALUE_NAME = "SrvOcspRespMaxSyncCertFileSeconds"
const CERT_SRV_OCSP_RESP_MIN_AFTER_NEXT_UPDATE_SECONDS_DEFAULT = 60
const CERT_SRV_OCSP_RESP_MIN_AFTER_NEXT_UPDATE_SECONDS_VALUE_NAME = "SrvOcspRespMinAfterNextUpdateSeconds"
const CERT_SRV_OCSP_RESP_MIN_BEFORE_NEXT_UPDATE_SECONDS_DEFAULT = 120
const CERT_SRV_OCSP_RESP_MIN_BEFORE_NEXT_UPDATE_SECONDS_VALUE_NAME = "SrvOcspRespMinBeforeNextUpdateSeconds"
const CERT_SRV_OCSP_RESP_MIN_SYNC_CERT_FILE_SECONDS_DEFAULT = 5
const CERT_SRV_OCSP_RESP_MIN_SYNC_CERT_FILE_SECONDS_VALUE_NAME = "SrvOcspRespMinSyncCertFileSeconds"
const CERT_SRV_OCSP_RESP_MIN_VALIDITY_SECONDS_DEFAULT = 600
const CERT_SRV_OCSP_RESP_MIN_VALIDITY_SECONDS_VALUE_NAME = "SrvOcspRespMinValiditySeconds"
const CERT_SRV_OCSP_RESP_URL_RETRIEVAL_TIMEOUT_MILLISECONDS_DEFAULT = 15000
const CERT_SRV_OCSP_RESP_URL_RETRIEVAL_TIMEOUT_MILLISECONDS_VALUE_NAME = "SrvOcspRespUrlRetrievalTimeoutMilliseconds"
const CERT_STORE_ADD_ALWAYS = 4
const CERT_STORE_ADD_NEW = 1
const CERT_STORE_ADD_NEWER = 6
const CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES = 7
const CERT_STORE_ADD_REPLACE_EXISTING = 3
const CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES = 5
const CERT_STORE_ADD_USE_EXISTING = 2
const CERT_STORE_ALL_CONTEXT_FLAG = 18446744073709551615
const CERT_STORE_BACKUP_RESTORE_FLAG = 2048
const CERT_STORE_BASE_CRL_FLAG = 256
const CERT_STORE_CERTIFICATE_CONTEXT = 1
const CERT_STORE_CERTIFICATE_CONTEXT_FLAG = 2
const CERT_STORE_CREATE_NEW_FLAG = 8192
const CERT_STORE_CRL_CONTEXT = 2
const CERT_STORE_CRL_CONTEXT_FLAG = 4
const CERT_STORE_CTL_CONTEXT = 3
const CERT_STORE_CTL_CONTEXT_FLAG = 8
const CERT_STORE_CTRL_AUTO_RESYNC = 4
const CERT_STORE_CTRL_CANCEL_NOTIFY = 5
const CERT_STORE_CTRL_COMMIT = 3
const CERT_STORE_CTRL_COMMIT_CLEAR_FLAG = 2
const CERT_STORE_CTRL_COMMIT_FORCE_FLAG = 1
const CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG = 1
const CERT_STORE_CTRL_NOTIFY_CHANGE = 2
const CERT_STORE_CTRL_RESYNC = 1
const CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 4
const CERT_STORE_DELETE_FLAG = 16
const CERT_STORE_DELTA_CRL_FLAG = 512
const CERT_STORE_ENUM_ARCHIVED_FLAG = 512
const CERT_STORE_LOCALIZED_NAME_PROP_ID = 4096
const CERT_STORE_MANIFOLD_FLAG = 256
const CERT_STORE_MAXIMUM_ALLOWED_FLAG = 4096
const CERT_STORE_NO_CRL_FLAG = 65536
const CERT_STORE_NO_CRYPT_RELEASE_FLAG = 1
const CERT_STORE_NO_ISSUER_FLAG = 131072
const CERT_STORE_OPEN_EXISTING_FLAG = 16384
const CERT_STORE_PROV_CLOSE_FUNC = 0
const CERT_STORE_PROV_CONTROL_FUNC = 13
const CERT_STORE_PROV_DELETED_FLAG = 2
const CERT_STORE_PROV_DELETE_CERT_FUNC = 3
const CERT_STORE_PROV_DELETE_CRL_FUNC = 7
const CERT_STORE_PROV_DELETE_CTL_FUNC = 11
const CERT_STORE_PROV_EXTERNAL_FLAG = 1
const CERT_STORE_PROV_FILENAME = "CERT_STORE_PROV_FILENAME_W"
const CERT_STORE_PROV_FIND_CERT_FUNC = 14
const CERT_STORE_PROV_FIND_CRL_FUNC = 17
const CERT_STORE_PROV_FIND_CTL_FUNC = 20
const CERT_STORE_PROV_FREE_FIND_CERT_FUNC = 15
const CERT_STORE_PROV_FREE_FIND_CRL_FUNC = 18
const CERT_STORE_PROV_FREE_FIND_CTL_FUNC = 21
const CERT_STORE_PROV_GET_CERT_PROPERTY_FUNC = 16
const CERT_STORE_PROV_GET_CRL_PROPERTY_FUNC = 19
const CERT_STORE_PROV_GET_CTL_PROPERTY_FUNC = 22
const CERT_STORE_PROV_GP_SYSTEM_STORE_FLAG = 32
const CERT_STORE_PROV_LDAP = "CERT_STORE_PROV_LDAP_W"
const CERT_STORE_PROV_LM_SYSTEM_STORE_FLAG = 16
const CERT_STORE_PROV_NO_PERSIST_FLAG = 4
const CERT_STORE_PROV_PHYSICAL = "CERT_STORE_PROV_PHYSICAL_W"
const CERT_STORE_PROV_READ_CERT_FUNC = 1
const CERT_STORE_PROV_READ_CRL_FUNC = 5
const CERT_STORE_PROV_READ_CTL_FUNC = 9
const CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC = 4
const CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC = 8
const CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC = 12
const CERT_STORE_PROV_SHARED_USER_FLAG = 64
const CERT_STORE_PROV_SMART_CARD = "CERT_STORE_PROV_SMART_CARD_W"
const CERT_STORE_PROV_SYSTEM = "CERT_STORE_PROV_SYSTEM_W"
const CERT_STORE_PROV_SYSTEM_REGISTRY = "CERT_STORE_PROV_SYSTEM_REGISTRY_W"
const CERT_STORE_PROV_SYSTEM_STORE_FLAG = 8
const CERT_STORE_PROV_WRITE_ADD_FLAG = 1
const CERT_STORE_PROV_WRITE_CERT_FUNC = 2
const CERT_STORE_PROV_WRITE_CRL_FUNC = 6
const CERT_STORE_PROV_WRITE_CTL_FUNC = 10
const CERT_STORE_READONLY_FLAG = 32768
const CERT_STORE_REVOCATION_FLAG = 4
const CERT_STORE_SAVE_AS_PKCS12 = 3
const CERT_STORE_SAVE_AS_PKCS7 = 2
const CERT_STORE_SAVE_AS_STORE = 1
const CERT_STORE_SAVE_TO_FILE = 1
const CERT_STORE_SAVE_TO_FILENAME = 4
const CERT_STORE_SAVE_TO_FILENAME_A = 3
const CERT_STORE_SAVE_TO_FILENAME_W = 4
const CERT_STORE_SAVE_TO_MEMORY = 2
const CERT_STORE_SET_LOCALIZED_NAME_FLAG = 2
const CERT_STORE_SHARE_CONTEXT_FLAG = 128
const CERT_STORE_SHARE_STORE_FLAG = 64
const CERT_STORE_SIGNATURE_FLAG = 1
const CERT_STORE_TIME_VALIDITY_FLAG = 2
const CERT_STORE_UNSAFE_PHYSICAL_FLAG = 32
const CERT_STORE_UPDATE_KEYID_FLAG = 1024
const CERT_STRONG_SIGN_ECDSA_ALGORITHM = "ECDSA"
const CERT_STRONG_SIGN_ENABLE_CRL_CHECK = 1
const CERT_STRONG_SIGN_ENABLE_OCSP_CHECK = 2
const CERT_STRONG_SIGN_OID_INFO_CHOICE = 2
const CERT_STRONG_SIGN_SERIALIZED_INFO_CHOICE = 1
const CERT_SUBJECT_DISABLE_CRL_PROP_ID = 86
const CERT_SUBJECT_INFO_ACCESS_PROP_ID = 80
const CERT_SUBJECT_NAME_MD5_HASH_PROP_ID = 29
const CERT_SUBJECT_OCSP_AUTHORITY_INFO_ACCESS_PROP_ID = 85
const CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID = 25
const CERT_SUBJECT_PUB_KEY_BIT_LENGTH_PROP_ID = 92
const CERT_SYSTEM_STORE_CURRENT_SERVICE = 262144
const CERT_SYSTEM_STORE_CURRENT_SERVICE_ID = 4
const CERT_SYSTEM_STORE_CURRENT_USER = 65536
const CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY = 458752
const CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID = 7
const CERT_SYSTEM_STORE_CURRENT_USER_ID = 1
const CERT_SYSTEM_STORE_DEFER_READ_FLAG = 536870912
const CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072
const CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE = 589824
const CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID = 9
const CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY = 524288
const CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID = 8
const CERT_SYSTEM_STORE_LOCAL_MACHINE_ID = 2
const CERT_SYSTEM_STORE_LOCAL_MACHINE_WCOS = 655360
const CERT_SYSTEM_STORE_LOCAL_MACHINE_WCOS_ID = 10
const CERT_SYSTEM_STORE_LOCATION_MASK = 16711680
const CERT_SYSTEM_STORE_LOCATION_SHIFT = 16
const CERT_SYSTEM_STORE_MASK = 4294901760
const CERT_SYSTEM_STORE_RELOCATE_FLAG = 2147483648
const CERT_SYSTEM_STORE_SERVICES = 327680
const CERT_SYSTEM_STORE_SERVICES_ID = 5
const CERT_SYSTEM_STORE_UNPROTECTED_FLAG = 1073741824
const CERT_SYSTEM_STORE_USERS = 393216
const CERT_SYSTEM_STORE_USERS_ID = 6
const CERT_TIMESTAMP_HASH_USE_TYPE = 2
const CERT_TRUST_AUTO_UPDATE_CA_REVOCATION = 16
const CERT_TRUST_AUTO_UPDATE_END_REVOCATION = 32
const CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID = 262144
const CERT_TRUST_CTL_IS_NOT_TIME_VALID = 131072
const CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE = 524288
const CERT_TRUST_HAS_ALLOW_WEAK_SIGNATURE = 131072
const CERT_TRUST_HAS_AUTO_UPDATE_WEAK_SIGNATURE = 32768
const CERT_TRUST_HAS_CRL_VALIDITY_EXTENDED = 4096
const CERT_TRUST_HAS_EXACT_MATCH_ISSUER = 1
const CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT = 32768
const CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY = 512
const CERT_TRUST_HAS_KEY_MATCH_ISSUER = 2
const CERT_TRUST_HAS_NAME_MATCH_ISSUER = 4
const CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT = 8192
const CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 16384
const CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT = 134217728
const CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT = 4096
const CERT_TRUST_HAS_PREFERRED_ISSUER = 256
const CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS = 1024
const CERT_TRUST_HAS_WEAK_SIGNATURE = 1048576
const CERT_TRUST_INVALID_BASIC_CONSTRAINTS = 1024
const CERT_TRUST_INVALID_EXTENSION = 256
const CERT_TRUST_INVALID_NAME_CONSTRAINTS = 2048
const CERT_TRUST_INVALID_POLICY_CONSTRAINTS = 512
const CERT_TRUST_IS_CA_TRUSTED = 16384
const CERT_TRUST_IS_COMPLEX_CHAIN = 65536
const CERT_TRUST_IS_CYCLIC = 128
const CERT_TRUST_IS_EXPLICIT_DISTRUST = 67108864
const CERT_TRUST_IS_FROM_EXCLUSIVE_TRUST_STORE = 8192
const CERT_TRUST_IS_KEY_ROLLOVER = 128
const CERT_TRUST_IS_NOT_SIGNATURE_VALID = 8
const CERT_TRUST_IS_NOT_TIME_NESTED = 2
const CERT_TRUST_IS_NOT_TIME_VALID = 1
const CERT_TRUST_IS_NOT_VALID_FOR_USAGE = 16
const CERT_TRUST_IS_OFFLINE_REVOCATION = 16777216
const CERT_TRUST_IS_PARTIAL_CHAIN = 65536
const CERT_TRUST_IS_PEER_TRUSTED = 2048
const CERT_TRUST_IS_REVOKED = 4
const CERT_TRUST_IS_SELF_SIGNED = 8
const CERT_TRUST_IS_UNTRUSTED_ROOT = 32
const CERT_TRUST_NO_ERROR = 0
const CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY = 33554432
const CERT_TRUST_NO_OCSP_FAILOVER_TO_CRL = 64
const CERT_TRUST_NO_TIME_CHECK = 33554432
const CERT_TRUST_PUB_ALLOW_END_USER_TRUST = 0
const CERT_TRUST_PUB_ALLOW_ENTERPRISE_ADMIN_TRUST = 2
const CERT_TRUST_PUB_ALLOW_MACHINE_ADMIN_TRUST = 1
const CERT_TRUST_PUB_ALLOW_TRUST_MASK = 3
const CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME = "AuthenticodeFlags"
const CERT_TRUST_PUB_CHECK_PUBLISHER_REV_FLAG = 256
const CERT_TRUST_PUB_CHECK_TIMESTAMP_REV_FLAG = 512
const CERT_TRUST_REVOCATION_STATUS_UNKNOWN = 64
const CERT_TRUST_SSL_HANDSHAKE_OCSP = 262144
const CERT_TRUST_SSL_RECONNECT_OCSP = 1048576
const CERT_TRUST_SSL_TIME_VALID = 16777216
const CERT_TRUST_SSL_TIME_VALID_OCSP = 524288
const CERT_UNICODE_ATTR_ERR_INDEX_MASK = 63
const CERT_UNICODE_ATTR_ERR_INDEX_SHIFT = 16
const CERT_UNICODE_IS_RDN_ATTRS_FLAG = 1
const CERT_UNICODE_RDN_ERR_INDEX_MASK = 1023
const CERT_UNICODE_RDN_ERR_INDEX_SHIFT = 22
const CERT_UNICODE_VALUE_ERR_INDEX_MASK = 65535
const CERT_UNICODE_VALUE_ERR_INDEX_SHIFT = 0
const CERT_V1 = 0
const CERT_V2 = 1
const CERT_V3 = 2
const CERT_VERIFY_ALLOW_MORE_USAGE_FLAG = 8
const CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION = 2
const CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG = 1
const CERT_VERIFY_NO_TIME_CHECK_FLAG = 4
const CERT_VERIFY_REV_ACCUMULATIVE_TIMEOUT_FLAG = 4
const CERT_VERIFY_REV_CHAIN_FLAG = 1
const CERT_VERIFY_REV_NO_OCSP_FAILOVER_TO_CRL_FLAG = 16
const CERT_VERIFY_REV_SERVER_OCSP_FLAG = 8
const CERT_VERIFY_TRUSTED_SIGNERS_FLAG = 2
const CERT_VERIFY_UPDATED_CTL_FLAG = 1
const CERT_X500_NAME_STR = 3
const CERT_XML_NAME_STR = 4
const CE_BREAK = 16
const CE_DNS = 2048
const CE_FRAME = 8
const CE_IOE = 1024
const CE_MODE = 32768
const CE_OOP = 4096
const CE_OVERRUN = 2
const CE_PTO = 512
const CE_RXOVER = 1
const CE_RXPARITY = 4
const CE_TXFULL = 256
const CFERR_CHOOSEFONTCODES = 8192
const CFERR_MAXLESSTHANMIN = 8194
const CFERR_NOFONTS = 8193
const CFG_CALL_TARGET_CONVERT_EXPORT_SUPPRESSED_TO_VALID = 4
const CFG_CALL_TARGET_PROCESSED = 2
const CFG_CALL_TARGET_VALID = 1
const CFSEPCHAR = 43
const CFSTR_MIME_NULL = "NULL"
const CFS_CANDIDATEPOS = 64
const CFS_DEFAULT = 0
const CFS_EXCLUDE = 128
const CFS_FORCE_POSITION = 32
const CFS_POINT = 2
const CFS_RECT = 1
const CF_ANSIONLY = 1024
const CF_APPLY = 512
const CF_BITMAP = 2
const CF_BOTH = 3
const CF_DIB = 8
const CF_DIBV5 = 17
const CF_DIF = 5
const CF_DSPBITMAP = 130
const CF_DSPENHMETAFILE = 142
const CF_DSPMETAFILEPICT = 131
const CF_DSPTEXT = 129
const CF_EFFECTS = 256
const CF_ENABLEHOOK = 8
const CF_ENABLETEMPLATE = 16
const CF_ENABLETEMPLATEHANDLE = 32
const CF_ENHMETAFILE = 14
const CF_FIXEDPITCHONLY = 16384
const CF_FORCEFONTEXIST = 65536
const CF_GDIOBJFIRST = 768
const CF_GDIOBJLAST = 1023
const CF_HDROP = 15
const CF_INACTIVEFONTS = 33554432
const CF_INITTOLOGFONTSTRUCT = 64
const CF_LIMITSIZE = 8192
const CF_LOCALE = 16
const CF_MAX = 18
const CF_METAFILEPICT = 3
const CF_NOFACESEL = 524288
const CF_NOOEMFONTS = 2048
const CF_NOSCRIPTSEL = 8388608
const CF_NOSIMULATIONS = 4096
const CF_NOSIZESEL = 2097152
const CF_NOSTYLESEL = 1048576
const CF_NOVECTORFONTS = 2048
const CF_NOVERTFONTS = 16777216
const CF_NULL = 0
const CF_OEMTEXT = 7
const CF_OWNERDISPLAY = 128
const CF_PALETTE = 9
const CF_PENDATA = 10
const CF_PRINTERFONTS = 2
const CF_PRIVATEFIRST = 512
const CF_PRIVATELAST = 767
const CF_RIFF = 11
const CF_SCALABLEONLY = 131072
const CF_SCREENFONTS = 1
const CF_SCRIPTSONLY = 1024
const CF_SELECTSCRIPT = 4194304
const CF_SHOWHELP = 4
const CF_SYLK = 4
const CF_TEXT = 1
const CF_TIFF = 6
const CF_TTONLY = 262144
const CF_UNICODETEXT = 13
const CF_USESTYLE = 128
const CF_WAVE = 12
const CF_WYSIWYG = 32768
const CHANGER_BAR_CODE_SCANNER_INSTALLED = 1
const CHANGER_CARTRIDGE_MAGAZINE = 256
const CHANGER_CLEANER_ACCESS_NOT_VALID = 262144
const CHANGER_CLEANER_AUTODISMOUNT = 2147483652
const CHANGER_CLEANER_OPS_NOT_SUPPORTED = 2147483712
const CHANGER_CLEANER_SLOT = 64
const CHANGER_CLOSE_IEPORT = 4
const CHANGER_DEVICE_REINITIALIZE_CAPABLE = 134217728
const CHANGER_DRIVE_CLEANING_REQUIRED = 65536
const CHANGER_DRIVE_EMPTY_ON_DOOR_ACCESS = 536870912
const CHANGER_EXCHANGE_MEDIA = 32
const CHANGER_IEPORT_USER_CONTROL_CLOSE = 2147483904
const CHANGER_IEPORT_USER_CONTROL_OPEN = 2147483776
const CHANGER_INIT_ELEM_STAT_WITH_RANGE = 2
const CHANGER_KEYPAD_ENABLE_DISABLE = 268435456
const CHANGER_LOCK_UNLOCK = 128
const CHANGER_MEDIUM_FLIP = 512
const CHANGER_MOVE_EXTENDS_IEPORT = 2147484160
const CHANGER_MOVE_RETRACTS_IEPORT = 2147484672
const CHANGER_OPEN_IEPORT = 8
const CHANGER_POSITION_TO_ELEMENT = 1024
const CHANGER_PREDISMOUNT_ALIGN_TO_DRIVE = 2147483650
const CHANGER_PREDISMOUNT_ALIGN_TO_SLOT = 2147483649
const CHANGER_PREDISMOUNT_EJECT_REQUIRED = 131072
const CHANGER_PREMOUNT_EJECT_REQUIRED = 524288
const CHANGER_REPORT_IEPORT_STATE = 2048
const CHANGER_RESERVED_BIT = 2147483648
const CHANGER_RTN_MEDIA_TO_ORIGINAL_ADDR = 2147483680
const CHANGER_SERIAL_NUMBER_VALID = 67108864
const CHANGER_SLOTS_USE_TRAYS = 2147483664
const CHANGER_STATUS_NON_VOLATILE = 16
const CHANGER_STORAGE_DRIVE = 4096
const CHANGER_STORAGE_IEPORT = 8192
const CHANGER_STORAGE_SLOT = 16384
const CHANGER_STORAGE_TRANSPORT = 32768
const CHANGER_TO_DRIVE = 8
const CHANGER_TO_IEPORT = 4
const CHANGER_TO_SLOT = 2
const CHANGER_TO_TRANSPORT = 1
const CHANGER_TRUE_EXCHANGE_CAPABLE = 2147483656
const CHANGER_VOLUME_ASSERT = 4194304
const CHANGER_VOLUME_IDENTIFICATION = 1048576
const CHANGER_VOLUME_REPLACE = 8388608
const CHANGER_VOLUME_SEARCH = 2097152
const CHANGER_VOLUME_UNDEFINE = 16777216
const CHECKJPEGFORMAT = 4119
const CHECKPNGFORMAT = 4120
const CHILDID_SELF = 0
const CHINESEBIG5_CHARSET = 136
const CKCNSTRNT_COLUMN = 1
const CKCNSTRNT_ROWID = 2
const CLAIM_SECURITY_ATTRIBUTES_INFORMATION_VERSION = 1
const CLAIM_SECURITY_ATTRIBUTES_INFORMATION_VERSION_V1 = 1
const CLAIM_SECURITY_ATTRIBUTE_CUSTOM_FLAGS = 4294901760
const CLAIM_SECURITY_ATTRIBUTE_DISABLED = 16
const CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT = 8
const CLAIM_SECURITY_ATTRIBUTE_MANDATORY = 32
const CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE = 1
const CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN = 6
const CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN = 4
const CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64 = 1
const CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID = 0
const CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING = 16
const CLAIM_SECURITY_ATTRIBUTE_TYPE_SID = 5
const CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING = 3
const CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64 = 2
const CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY = 4
const CLAIM_SECURITY_ATTRIBUTE_VALID_FLAGS = 63
const CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE = 2
const CLASSFACTORY_E_FIRST = 2147746064
const CLASSFACTORY_E_LAST = 2147746079
const CLASSFACTORY_S_FIRST = 262416
const CLASSFACTORY_S_LAST = 262431
const CLEARTYPE_NATURAL_QUALITY = 6
const CLEARTYPE_QUALITY = 5
const CLIENTSITE_E_FIRST = 2147746192
const CLIENTSITE_E_LAST = 2147746207
const CLIENTSITE_S_FIRST = 262544
const CLIENTSITE_S_LAST = 262559
const CLIPBRD_E_FIRST = 2147746256
const CLIPBRD_E_LAST = 2147746271
const CLIPBRD_S_FIRST = 262608
const CLIPBRD_S_LAST = 262623
const CLIPCAPS = 36
const CLIP_CHARACTER_PRECIS = 1
const CLIP_DEFAULT_PRECIS = 0
const CLIP_DFA_DISABLE = 64
const CLIP_EMBEDDED = 128
const CLIP_LH_ANGLES = 16
const CLIP_MASK = 15
const CLIP_STROKE_PRECIS = 2
const CLIP_TO_PATH = 4097
const CLIP_TT_ALWAYS = 32
const CLK_TCK = 1000
const CLOCKS_PER_SEC = 1000
const CLOCK_MONOTONIC = 1
const CLOCK_PROCESS_CPUTIME_ID = 2
const CLOCK_REALTIME = 0
const CLOCK_REALTIME_COARSE = 4
const CLOCK_THREAD_CPUTIME_ID = 3
const CLOSECHANNEL = 4112
const CLRBREAK = 9
const CLRDTR = 6
const CLRRTS = 4
const CLR_INVALID = 4294967295
const CLSCTX_ALL = 0
const CLSCTX_INPROC = 0
const CLSCTX_SERVER = 0
const CLSCTX_VALID_MASK = 0
const CLSID_NULL = 0
const CMAPI = "DECLSPEC_IMPORT"
const CMC_FAIL_BAD_ALG = 0
const CMC_FAIL_BAD_CERT_ID = 4
const CMC_FAIL_BAD_IDENTITY = 7
const CMC_FAIL_BAD_MESSAGE_CHECK = 1
const CMC_FAIL_BAD_REQUEST = 2
const CMC_FAIL_BAD_TIME = 3
const CMC_FAIL_INTERNAL_CA_ERROR = 11
const CMC_FAIL_MUST_ARCHIVE_KEYS = 6
const CMC_FAIL_NO_KEY_REUSE = 10
const CMC_FAIL_POP_FAILED = 9
const CMC_FAIL_POP_REQUIRED = 8
const CMC_FAIL_TRY_LATER = 12
const CMC_FAIL_UNSUPORTED_EXT = 5
const CMC_OTHER_INFO_FAIL_CHOICE = 1
const CMC_OTHER_INFO_NO_CHOICE = 0
const CMC_OTHER_INFO_PEND_CHOICE = 2
const CMC_STATUS_CONFIRM_REQUIRED = 5
const CMC_STATUS_FAILED = 2
const CMC_STATUS_NO_SUPPORT = 4
const CMC_STATUS_PENDING = 3
const CMC_STATUS_SUCCESS = 0
const CMC_TAGGED_CERT_REQUEST_CHOICE = 1
const CMSG_ALL_FLAGS = 18446744073709551615
const CMSG_ATTR_CERT_COUNT_PARAM = 31
const CMSG_ATTR_CERT_PARAM = 32
const CMSG_AUTHENTICATED_ATTRIBUTES_FLAG = 8
const CMSG_BARE_CONTENT_FLAG = 1
const CMSG_BARE_CONTENT_PARAM = 3
const CMSG_CERT_COUNT_PARAM = 11
const CMSG_CERT_PARAM = 12
const CMSG_CMS_ENCAPSULATED_CONTENT_FLAG = 64
const CMSG_CMS_ENCAPSULATED_CTL_FLAG = 32768
const CMSG_CMS_RECIPIENT_COUNT_PARAM = 33
const CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM = 35
const CMSG_CMS_RECIPIENT_INDEX_PARAM = 34
const CMSG_CMS_RECIPIENT_INFO_PARAM = 36
const CMSG_CMS_SIGNER_INFO_PARAM = 39
const CMSG_COMPUTED_HASH_PARAM = 22
const CMSG_CONTENTS_OCTETS_FLAG = 16
const CMSG_CONTENT_ENCRYPT_FREE_OBJID_FLAG = 2
const CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG = 1
const CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG = 1
const CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG = 32768
const CMSG_CONTENT_PARAM = 2
const CMSG_CRL_COUNT_PARAM = 13
const CMSG_CRL_PARAM = 14
const CMSG_CRYPT_RELEASE_CONTEXT_FLAG = 32768
const CMSG_CTRL_ADD_ATTR_CERT = 14
const CMSG_CTRL_ADD_CERT = 10
const CMSG_CTRL_ADD_CMS_SIGNER_INFO = 20
const CMSG_CTRL_ADD_CRL = 12
const CMSG_CTRL_ADD_SIGNER = 6
const CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR = 8
const CMSG_CTRL_DECRYPT = 2
const CMSG_CTRL_DEL_ATTR_CERT = 15
const CMSG_CTRL_DEL_CERT = 11
const CMSG_CTRL_DEL_CRL = 13
const CMSG_CTRL_DEL_SIGNER = 7
const CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR = 9
const CMSG_CTRL_ENABLE_STRONG_SIGNATURE = 21
const CMSG_CTRL_KEY_AGREE_DECRYPT = 17
const CMSG_CTRL_KEY_TRANS_DECRYPT = 16
const CMSG_CTRL_MAIL_LIST_DECRYPT = 18
const CMSG_CTRL_VERIFY_HASH = 5
const CMSG_CTRL_VERIFY_SIGNATURE = 1
const CMSG_CTRL_VERIFY_SIGNATURE_EX = 19
const CMSG_DATA = 1
const CMSG_DATA_FLAG = 2
const CMSG_DETACHED_FLAG = 4
const CMSG_ENCODED_MESSAGE = 29
const CMSG_ENCODED_SIGNER = 28
const CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG = 2
const CMSG_ENCODE_SORTED_CTL_FLAG = 1
const CMSG_ENCODING_TYPE_MASK = 4294901760
const CMSG_ENCRYPTED = 6
const CMSG_ENCRYPTED_DIGEST = 27
const CMSG_ENCRYPTED_FLAG = 64
const CMSG_ENCRYPT_PARAM = 26
const CMSG_ENVELOPED = 3
const CMSG_ENVELOPED_DATA_CMS_VERSION = 2
const CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION = 0
const CMSG_ENVELOPED_DATA_V0 = 0
const CMSG_ENVELOPED_DATA_V2 = 2
const CMSG_ENVELOPED_FLAG = 8
const CMSG_ENVELOPED_RECIPIENT_V0 = 0
const CMSG_ENVELOPED_RECIPIENT_V2 = 2
const CMSG_ENVELOPED_RECIPIENT_V3 = 3
const CMSG_ENVELOPED_RECIPIENT_V4 = 4
const CMSG_ENVELOPE_ALGORITHM_PARAM = 15
const CMSG_HASHED = 5
const CMSG_HASHED_DATA_CMS_VERSION = 2
const CMSG_HASHED_DATA_PKCS_1_5_VERSION = 0
const CMSG_HASHED_DATA_V0 = 0
const CMSG_HASHED_DATA_V2 = 2
const CMSG_HASHED_FLAG = 32
const CMSG_HASH_ALGORITHM_PARAM = 20
const CMSG_HASH_DATA_PARAM = 21
const CMSG_INDEFINITE_LENGTH = 4294967295
const CMSG_INNER_CONTENT_TYPE_PARAM = 4
const CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG = 2
const CMSG_KEY_AGREE_ENCRYPT_FREE_OBJID_FLAG = 32
const CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG = 1
const CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG = 4
const CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG = 16
const CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG = 8
const CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE = 1
const CMSG_KEY_AGREE_ORIGINATOR_CERT = 1
const CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY = 2
const CMSG_KEY_AGREE_RECIPIENT = 2
const CMSG_KEY_AGREE_STATIC_KEY_CHOICE = 2
const CMSG_KEY_AGREE_VERSION = 3
const CMSG_KEY_TRANS_CMS_VERSION = 2
const CMSG_KEY_TRANS_ENCRYPT_FREE_OBJID_FLAG = 2
const CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG = 1
const CMSG_KEY_TRANS_PKCS_1_5_VERSION = 0
const CMSG_KEY_TRANS_RECIPIENT = 1
const CMSG_LENGTH_ONLY_FLAG = 2
const CMSG_MAIL_LIST_ENCRYPT_FREE_OBJID_FLAG = 2
const CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG = 1
const CMSG_MAIL_LIST_HANDLE_KEY_CHOICE = 1
const CMSG_MAIL_LIST_RECIPIENT = 3
const CMSG_MAIL_LIST_VERSION = 4
const CMSG_MAX_LENGTH_FLAG = 32
const CMSG_OID_CAPI1_EXPORT_KEY_AGREE_FUNC = "CMSG_OID_EXPORT_KEY_AGREE_FUNC"
const CMSG_OID_CAPI1_EXPORT_KEY_TRANS_FUNC = "CMSG_OID_EXPORT_KEY_TRANS_FUNC"
const CMSG_OID_CAPI1_EXPORT_MAIL_LIST_FUNC = "CMSG_OID_EXPORT_MAIL_LIST_FUNC"
const CMSG_OID_CAPI1_GEN_CONTENT_ENCRYPT_KEY_FUNC = "CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC"
const CMSG_OID_CAPI1_IMPORT_KEY_AGREE_FUNC = "CMSG_OID_IMPORT_KEY_AGREE_FUNC"
const CMSG_OID_CAPI1_IMPORT_KEY_TRANS_FUNC = "CMSG_OID_IMPORT_KEY_TRANS_FUNC"
const CMSG_OID_CAPI1_IMPORT_MAIL_LIST_FUNC = "CMSG_OID_IMPORT_MAIL_LIST_FUNC"
const CMSG_OID_CNG_EXPORT_KEY_AGREE_FUNC = "CryptMsgDllCNGExportKeyAgree"
const CMSG_OID_CNG_EXPORT_KEY_TRANS_FUNC = "CryptMsgDllCNGExportKeyTrans"
const CMSG_OID_CNG_GEN_CONTENT_ENCRYPT_KEY_FUNC = "CryptMsgDllCNGGenContentEncryptKey"
const CMSG_OID_CNG_IMPORT_CONTENT_ENCRYPT_KEY_FUNC = "CryptMsgDllCNGImportContentEncryptKey"
const CMSG_OID_CNG_IMPORT_KEY_AGREE_FUNC = "CryptMsgDllCNGImportKeyAgree"
const CMSG_OID_CNG_IMPORT_KEY_TRANS_FUNC = "CryptMsgDllCNGImportKeyTrans"
const CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC = "CryptMsgDllExportEncryptKey"
const CMSG_OID_EXPORT_KEY_AGREE_FUNC = "CryptMsgDllExportKeyAgree"
const CMSG_OID_EXPORT_KEY_TRANS_FUNC = "CryptMsgDllExportKeyTrans"
const CMSG_OID_EXPORT_MAIL_LIST_FUNC = "CryptMsgDllExportMailList"
const CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC = "CryptMsgDllGenContentEncryptKey"
const CMSG_OID_GEN_ENCRYPT_KEY_FUNC = "CryptMsgDllGenEncryptKey"
const CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC = "CryptMsgDllImportEncryptKey"
const CMSG_OID_IMPORT_KEY_AGREE_FUNC = "CryptMsgDllImportKeyAgree"
const CMSG_OID_IMPORT_KEY_TRANS_FUNC = "CryptMsgDllImportKeyTrans"
const CMSG_OID_IMPORT_MAIL_LIST_FUNC = "CryptMsgDllImportMailList"
const CMSG_RC4_NO_SALT_FLAG = 1073741824
const CMSG_RECIPIENT_COUNT_PARAM = 17
const CMSG_RECIPIENT_INDEX_PARAM = 18
const CMSG_RECIPIENT_INFO_PARAM = 19
const CMSG_SIGNED = 2
const CMSG_SIGNED_AND_ENVELOPED = 4
const CMSG_SIGNED_AND_ENVELOPED_FLAG = 16
const CMSG_SIGNED_DATA_CMS_VERSION = 3
const CMSG_SIGNED_DATA_NO_SIGN_FLAG = 128
const CMSG_SIGNED_DATA_PKCS_1_5_VERSION = 1
const CMSG_SIGNED_DATA_V1 = 1
const CMSG_SIGNED_DATA_V3 = 3
const CMSG_SIGNED_FLAG = 4
const CMSG_SIGNER_AUTH_ATTR_PARAM = 9
const CMSG_SIGNER_CERT_ID_PARAM = 38
const CMSG_SIGNER_CERT_INFO_PARAM = 7
const CMSG_SIGNER_COUNT_PARAM = 5
const CMSG_SIGNER_HASH_ALGORITHM_PARAM = 8
const CMSG_SIGNER_INFO_CMS_VERSION = 3
const CMSG_SIGNER_INFO_PARAM = 6
const CMSG_SIGNER_INFO_PKCS_1_5_VERSION = 1
const CMSG_SIGNER_INFO_V1 = 1
const CMSG_SIGNER_INFO_V3 = 3
const CMSG_SIGNER_ONLY_FLAG = 2
const CMSG_SIGNER_UNAUTH_ATTR_PARAM = 10
const CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG = 2147483648
const CMSG_TRUSTED_SIGNER_FLAG = 1
const CMSG_TYPE_PARAM = 1
const CMSG_UNPROTECTED_ATTR_PARAM = 37
const CMSG_USE_SIGNER_INDEX_FLAG = 4
const CMSG_VERIFY_COUNTER_SIGN_ENABLE_STRONG_FLAG = 1
const CMSG_VERIFY_SIGNER_CERT = 2
const CMSG_VERIFY_SIGNER_CHAIN = 3
const CMSG_VERIFY_SIGNER_NULL = 4
const CMSG_VERIFY_SIGNER_PUBKEY = 1
const CMSG_VERSION_PARAM = 30
const CM_CMYK_COLOR = 4
const CM_DEVICE_ICM = 1
const CM_GAMMA_RAMP = 2
const CM_IN_GAMUT = 0
const CM_NONE = 0
const CM_OUT_OF_GAMUT = 255
const CM_SERVICE_MEASURED_BOOT_LOAD = 32
const CM_SERVICE_NETWORK_BOOT_LOAD = 1
const CM_SERVICE_SD_DISK_BOOT_LOAD = 8
const CM_SERVICE_USB3_DISK_BOOT_LOAD = 16
const CM_SERVICE_USB_DISK_BOOT_LOAD = 4
const CM_SERVICE_VALID_PROMOTION_MASK = 255
const CM_SERVICE_VERIFIER_BOOT_LOAD = 64
const CM_SERVICE_VIRTUAL_DISK_BOOT_LOAD = 2
const CM_SERVICE_WINPE_BOOT_LOAD = 128
const CODEPAGE_ENUMPROC = 0
const COLFLAG_BUSY = 256
const COLFLAG_GENERATED = 96
const COLFLAG_HASCOLL = 512
const COLFLAG_HASTYPE = 4
const COLFLAG_HIDDEN = 2
const COLFLAG_NOEXPAND = 1024
const COLFLAG_NOINSERT = 98
const COLFLAG_NOTAVAIL = 128
const COLFLAG_PRIMKEY = 1
const COLFLAG_SORTERREF = 16
const COLFLAG_STORED = 64
const COLFLAG_UNIQUE = 8
const COLFLAG_VIRTUAL = 32
const COLNAME_COLUMN = 4
const COLNAME_DATABASE = 2
const COLNAME_DECLTYPE = 1
const COLNAME_N = 5
const COLNAME_NAME = 0
const COLNAME_TABLE = 3
const COLORMATCHTOTARGET_EMBEDED = 1
const COLORMGMTCAPS = 121
const COLORMGMTDLGORD = 1551
const COLOROKSTRINGA = "commdlg_ColorOK"
const COLOROKSTRINGW = "commdlg_ColorOK"
const COLORONCOLOR = 3
const COLORRES = 108
const COLOR_3DDKSHADOW = 21
const COLOR_3DFACE = 15
const COLOR_3DHIGHLIGHT = 20
const COLOR_3DHILIGHT = 20
const COLOR_3DLIGHT = 22
const COLOR_3DSHADOW = 16
const COLOR_ACTIVEBORDER = 10
const COLOR_ACTIVECAPTION = 2
const COLOR_ADJ_MIN = -100
const COLOR_APPWORKSPACE = 12
const COLOR_BACKGROUND = 1
const COLOR_BTNFACE = 15
const COLOR_BTNHIGHLIGHT = 20
const COLOR_BTNHILIGHT = 20
const COLOR_BTNSHADOW = 16
const COLOR_BTNTEXT = 18
const COLOR_CAPTIONTEXT = 9
const COLOR_DESKTOP = 1
const COLOR_GRADIENTACTIVECAPTION = 27
const COLOR_GRADIENTINACTIVECAPTION = 28
const COLOR_GRAYTEXT = 17
const COLOR_HIGHLIGHT = 13
const COLOR_HIGHLIGHTTEXT = 14
const COLOR_HOTLIGHT = 26
const COLOR_INACTIVEBORDER = 11
const COLOR_INACTIVECAPTION = 3
const COLOR_INACTIVECAPTIONTEXT = 19
const COLOR_INFOBK = 24
const COLOR_INFOTEXT = 23
const COLOR_MENU = 4
const COLOR_MENUBAR = 30
const COLOR_MENUHILIGHT = 29
const COLOR_MENUTEXT = 7
const COLOR_SCROLLBAR = 0
const COLOR_WINDOW = 5
const COLOR_WINDOWFRAME = 6
const COLOR_WINDOWTEXT = 8
const COLTYPE_ANY = 1
const COLTYPE_BLOB = 2
const COLTYPE_CUSTOM = 0
const COLTYPE_INT = 3
const COLTYPE_INTEGER = 4
const COLTYPE_REAL = 5
const COLTYPE_TEXT = 6
const COMMON_LVB_GRID_HORIZONTAL = 1024
const COMMON_LVB_GRID_LVERTICAL = 2048
const COMMON_LVB_GRID_RVERTICAL = 4096
const COMMON_LVB_LEADING_BYTE = 256
const COMMON_LVB_REVERSE_VIDEO = 16384
const COMMON_LVB_SBCSDBCS = 768
const COMMON_LVB_TRAILING_BYTE = 512
const COMMON_LVB_UNDERSCORE = 32768
const COMPLEXREGION = 3
const COMPONENT_KTM = 1
const COMPONENT_VALID_FLAGS = 1
const COMPRESSION_ENGINE_HIBER = 512
const COMPRESSION_ENGINE_MAXIMUM = 256
const COMPRESSION_ENGINE_STANDARD = 0
const COMPRESSION_FORMAT_DEFAULT = 1
const COMPRESSION_FORMAT_LZNT1 = 2
const COMPRESSION_FORMAT_NONE = 0
const COMPRESSION_FORMAT_SPARSE = 16384
const COMPRESSION_FORMAT_XPRESS = 3
const COMPRESSION_FORMAT_XPRESS_HUFF = 4
const COM_RIGHTS_ACTIVATE_LOCAL = 8
const COM_RIGHTS_ACTIVATE_REMOTE = 16
const COM_RIGHTS_EXECUTE = 1
const COM_RIGHTS_EXECUTE_LOCAL = 2
const COM_RIGHTS_EXECUTE_REMOTE = 4
const CONDITION_VARIABLE_INIT = "RTL_CONDITION_VARIABLE_INIT"
const CONDITION_VARIABLE_LOCKMODE_SHARED = 1
const CONFIRMSAFETYACTION_LOADOBJECT = 1
const CONNDLG_CONN_POINT = 2
const CONNDLG_HIDE_BOX = 8
const CONNDLG_NOT_PERSIST = 32
const CONNDLG_PERSIST = 16
const CONNDLG_RO_PATH = 1
const CONNDLG_USE_MRU = 4
const CONNECT_CMD_SAVECRED = 4096
const CONNECT_COMMANDLINE = 2048
const CONNECT_CRED_RESET = 8192
const CONNECT_CURRENT_MEDIA = 512
const CONNECT_DEFERRED = 1024
const CONNECT_INTERACTIVE = 8
const CONNECT_LOCALDRIVE = 256
const CONNECT_NEED_DRIVE = 32
const CONNECT_PROMPT = 16
const CONNECT_REDIRECT = 128
const CONNECT_REFCOUNT = 64
const CONNECT_RESERVED = 4278190080
const CONNECT_TEMPORARY = 4
const CONNECT_UPDATE_PROFILE = 1
const CONNECT_UPDATE_RECENT = 2
const CONSOLE_APPLICATION_16BIT = 1
const CONSOLE_CARET_SELECTION = 1
const CONSOLE_CARET_VISIBLE = 2
const CONSOLE_FULLSCREEN = 1
const CONSOLE_FULLSCREEN_HARDWARE = 2
const CONSOLE_FULLSCREEN_MODE = 1
const CONSOLE_MOUSE_DOWN = 8
const CONSOLE_MOUSE_SELECTION = 4
const CONSOLE_NO_SELECTION = 0
const CONSOLE_SELECTION_IN_PROGRESS = 1
const CONSOLE_SELECTION_NOT_EMPTY = 2
const CONSOLE_TEXTMODE_BUFFER = 1
const CONSOLE_WINDOWED_MODE = 2
const CONST = 0
const CONTACTVISUALIZATION_OFF = 0
const CONTACTVISUALIZATION_ON = 1
const CONTACTVISUALIZATION_PRESENTATIONMODE = 2
const CONTAINER_INHERIT_ACE = 2
const CONTEXT_ALL = 65599
const CONTEXT_CONTROL = 65537
const CONTEXT_DEBUG_REGISTERS = 65552
const CONTEXT_EXTENDED_REGISTERS = 65568
const CONTEXT_E_FIRST = 2147803136
const CONTEXT_E_LAST = 2147803183
const CONTEXT_FLOATING_POINT = 65544
const CONTEXT_FULL = 65543
const CONTEXT_INTEGER = 65538
const CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC = "ContextDllCreateObjectContext"
const CONTEXT_SEGMENTS = 65540
const CONTEXT_S_FIRST = 319488
const CONTEXT_S_LAST = 319535
const CONTEXT_i386 = 65536
const CONTEXT_i486 = 65536
const CONTROL_C_EXIT = "STATUS_CONTROL_C_EXIT"
const CONVERT10_E_FIRST = 2147746240
const CONVERT10_E_LAST = 2147746255
const CONVERT10_S_FIRST = 262592
const CONVERT10_S_LAST = 262607
const COPYFILE2_MESSAGE_COPY_OFFLOAD = 1
const COPYFILE_SIS_FLAGS = 3
const COPYFILE_SIS_LINK = 1
const COPYFILE_SIS_REPLACE = 2
const COPY_FILE_ALLOW_DECRYPTED_DESTINATION = 8
const COPY_FILE_COPY_SYMLINK = 2048
const COPY_FILE_DONT_REQUEST_DEST_WRITE_DAC = 33554432
const COPY_FILE_FAIL_IF_EXISTS = 1
const COPY_FILE_IGNORE_EDP_BLOCK = 4194304
const COPY_FILE_IGNORE_SOURCE_ENCRYPTION = 8388608
const COPY_FILE_NO_BUFFERING = 4096
const COPY_FILE_NO_OFFLOAD = 262144
const COPY_FILE_OPEN_SOURCE_FOR_WRITE = 4
const COPY_FILE_REQUEST_COMPRESSED_TRAFFIC = 268435456
const COPY_FILE_REQUEST_SECURITY_PRIVILEGES = 8192
const COPY_FILE_RESTARTABLE = 2
const COPY_FILE_RESUME_FROM_PAUSE = 16384
const CORE_PARKING_POLICY_CHANGE_IDEAL = 0
const CORE_PARKING_POLICY_CHANGE_MAX = 3
const CORE_PARKING_POLICY_CHANGE_MULTISTEP = 3
const CORE_PARKING_POLICY_CHANGE_ROCKET = 2
const CORE_PARKING_POLICY_CHANGE_SINGLE = 1
const CO_E_FIRST = 2147746288
const CO_E_LAST = 2147746303
const CO_S_FIRST = 262640
const CO_S_LAST = 262655
const CPS_CANCEL = 4
const CPS_COMPLETE = 1
const CPS_CONVERT = 2
const CPS_REVERT = 3
const CP_ACP = 0
const CP_INSTALLED = 1
const CP_MACCP = 2
const CP_NONE = 0
const CP_OEMCP = 1
const CP_RECTANGLE = 1
const CP_REGION = 2
const CP_SUPPORTED = 2
const CP_SYMBOL = 42
const CP_THREAD_ACP = 3
const CP_UTF7 = 65000
const CP_UTF8 = 65001
const CP_WINANSI = 1004
const CP_WINNEUTRAL = 1004
const CP_WINUNICODE = 1200
const CREATECOLORSPACE_EMBEDED = 1
const CREATE_ALWAYS = 2
const CREATE_BOUNDARY_DESCRIPTOR_ADD_APPCONTAINER_SID = 1
const CREATE_BREAKAWAY_FROM_JOB = 16777216
const CREATE_DEFAULT_ERROR_MODE = 67108864
const CREATE_EVENT_INITIAL_SET = 2
const CREATE_EVENT_MANUAL_RESET = 1
const CREATE_FORCEDOS = 8192
const CREATE_FOR_DIR = 2
const CREATE_FOR_IMPORT = 1
const CREATE_IGNORE_SYSTEM_DEFAULT = 2147483648
const CREATE_MUTEX_INITIAL_OWNER = 1
const CREATE_NEW = 1
const CREATE_NEW_CONSOLE = 16
const CREATE_NEW_PROCESS_GROUP = 512
const CREATE_NO_WINDOW = 134217728
const CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 33554432
const CREATE_PROCESS_DEBUG_EVENT = 3
const CREATE_PROTECTED_PROCESS = 262144
const CREATE_SECURE_PROCESS = 4194304
const CREATE_SEPARATE_WOW_VDM = 2048
const CREATE_SHARED_WOW_VDM = 4096
const CREATE_SUSPENDED = 4
const CREATE_THREAD_DEBUG_EVENT = 2
const CREATE_UNICODE_ENVIRONMENT = 1024
const CREATE_WAITABLE_TIMER_MANUAL_RESET = 1
const CREDUIAPI = "DECLSPEC_IMPORT"
const CRITICAL_SECTION_NO_DEBUG_INFO = 16777216
const CRL_DIST_POINT_ERR_CRL_ISSUER_BIT = 2147483648
const CRL_DIST_POINT_ERR_INDEX_MASK = 127
const CRL_DIST_POINT_ERR_INDEX_SHIFT = 24
const CRL_DIST_POINT_FULL_NAME = 1
const CRL_DIST_POINT_ISSUER_RDN_NAME = 2
const CRL_DIST_POINT_NO_NAME = 0
const CRL_FIND_ANY = 0
const CRL_FIND_EXISTING = 2
const CRL_FIND_ISSUED_BY = 1
const CRL_FIND_ISSUED_BY_AKI_FLAG = 1
const CRL_FIND_ISSUED_BY_BASE_FLAG = 8
const CRL_FIND_ISSUED_BY_DELTA_FLAG = 4
const CRL_FIND_ISSUED_BY_SIGNATURE_FLAG = 2
const CRL_FIND_ISSUED_FOR = 3
const CRL_FIND_ISSUED_FOR_SET_STRONG_PROPERTIES_FLAG = 16
const CRL_REASON_AA_COMPROMISE = 10
const CRL_REASON_AA_COMPROMISE_FLAG = 128
const CRL_REASON_AFFILIATION_CHANGED = 3
const CRL_REASON_AFFILIATION_CHANGED_FLAG = 16
const CRL_REASON_CA_COMPROMISE = 2
const CRL_REASON_CA_COMPROMISE_FLAG = 32
const CRL_REASON_CERTIFICATE_HOLD = 6
const CRL_REASON_CERTIFICATE_HOLD_FLAG = 2
const CRL_REASON_CESSATION_OF_OPERATION = 5
const CRL_REASON_CESSATION_OF_OPERATION_FLAG = 4
const CRL_REASON_KEY_COMPROMISE = 1
const CRL_REASON_KEY_COMPROMISE_FLAG = 64
const CRL_REASON_PRIVILEGE_WITHDRAWN = 9
const CRL_REASON_PRIVILEGE_WITHDRAWN_FLAG = 1
const CRL_REASON_REMOVE_FROM_CRL = 8
const CRL_REASON_SUPERSEDED = 4
const CRL_REASON_SUPERSEDED_FLAG = 8
const CRL_REASON_UNSPECIFIED = 0
const CRL_REASON_UNUSED_FLAG = 128
const CRL_V1 = 0
const CRL_V2 = 1
const CRM_PROTOCOL_DYNAMIC_MARSHAL_INFO = 2
const CRM_PROTOCOL_EXPLICIT_MARSHAL_ONLY = 1
const CRM_PROTOCOL_MAXIMUM_OPTION = 3
const CROSS_CERT_DIST_POINT_ERR_INDEX_MASK = 255
const CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT = 24
const CRYPTNET_CACHED_OCSP_SWITCH_TO_CRL_COUNT_DEFAULT = 50
const CRYPTNET_CACHED_OCSP_SWITCH_TO_CRL_COUNT_VALUE_NAME = "CryptnetCachedOcspSwitchToCrlCount"
const CRYPTNET_CRL_BEFORE_OCSP_ENABLE = 4294967295
const CRYPTNET_CRL_PRE_FETCH_DISABLE_INFORMATION_EVENTS_VALUE_NAME = "DisableInformationEvents"
const CRYPTNET_CRL_PRE_FETCH_LOG_FILE_NAME_VALUE_NAME = "LogFileName"
const CRYPTNET_CRL_PRE_FETCH_MAX_AGE_SECONDS_DEFAULT = 7200
const CRYPTNET_CRL_PRE_FETCH_MAX_AGE_SECONDS_MIN = 300
const CRYPTNET_CRL_PRE_FETCH_MAX_AGE_SECONDS_VALUE_NAME = "MaxAgeSeconds"
const CRYPTNET_CRL_PRE_FETCH_MIN_AFTER_NEXT_UPDATE_SECONDS_DEFAULT = 300
const CRYPTNET_CRL_PRE_FETCH_MIN_AFTER_NEXT_UPDATE_SECONDS_VALUE_NAME = "MinAfterNextUpdateSeconds"
const CRYPTNET_CRL_PRE_FETCH_MIN_BEFORE_NEXT_UPDATE_SECONDS_DEFAULT = 300
const CRYPTNET_CRL_PRE_FETCH_MIN_BEFORE_NEXT_UPDATE_SECONDS_VALUE_NAME = "MinBeforeNextUpdateSeconds"
const CRYPTNET_CRL_PRE_FETCH_PROCESS_NAME_LIST_VALUE_NAME = "ProcessNameList"
const CRYPTNET_CRL_PRE_FETCH_PUBLISH_BEFORE_NEXT_UPDATE_SECONDS_DEFAULT = 3600
const CRYPTNET_CRL_PRE_FETCH_PUBLISH_BEFORE_NEXT_UPDATE_SECONDS_VALUE_NAME = "PublishBeforeNextUpdateSeconds"
const CRYPTNET_CRL_PRE_FETCH_PUBLISH_RANDOM_INTERVAL_SECONDS_DEFAULT = 300
const CRYPTNET_CRL_PRE_FETCH_PUBLISH_RANDOM_INTERVAL_SECONDS_VALUE_NAME = "PublishRandomIntervalSeconds"
const CRYPTNET_CRL_PRE_FETCH_TIMEOUT_SECONDS_DEFAULT = 300
const CRYPTNET_CRL_PRE_FETCH_TIMEOUT_SECONDS_VALUE_NAME = "TimeoutSeconds"
const CRYPTNET_CRL_PRE_FETCH_URL_LIST_VALUE_NAME = "PreFetchUrlList"
const CRYPTNET_MAX_CACHED_OCSP_PER_CRL_COUNT_DEFAULT = 500
const CRYPTNET_MAX_CACHED_OCSP_PER_CRL_COUNT_VALUE_NAME = "CryptnetMaxCachedOcspPerCrlCount"
const CRYPTNET_OCSP_AFTER_CRL_DISABLE = 4294967295
const CRYPTNET_PRE_FETCH_AFTER_CURRENT_TIME_PRE_FETCH_PERIOD_SECONDS_DEFAULT = 1800
const CRYPTNET_PRE_FETCH_AFTER_CURRENT_TIME_PRE_FETCH_PERIOD_SECONDS_VALUE_NAME = "CryptnetPreFetchAfterCurrentTimePreFetchPeriodSeconds"
const CRYPTNET_PRE_FETCH_AFTER_PUBLISH_PRE_FETCH_DIVISOR_DEFAULT = 10
const CRYPTNET_PRE_FETCH_AFTER_PUBLISH_PRE_FETCH_DIVISOR_VALUE_NAME = "CryptnetPreFetchAfterPublishPreFetchDivisor"
const CRYPTNET_PRE_FETCH_BEFORE_NEXT_UPDATE_PRE_FETCH_DIVISOR_DEFAULT = 20
const CRYPTNET_PRE_FETCH_BEFORE_NEXT_UPDATE_PRE_FETCH_DIVISOR_VALUE_NAME = "CryptnetPreFetchBeforeNextUpdatePreFetchDivisor"
const CRYPTNET_PRE_FETCH_MAX_AFTER_NEXT_UPDATE_PRE_FETCH_PERIOD_SECONDS_DEFAULT = 14400
const CRYPTNET_PRE_FETCH_MAX_AFTER_NEXT_UPDATE_PRE_FETCH_PERIOD_SECONDS_VALUE_NAME = "CryptnetPreFetchMaxAfterNextUpdatePreFetchPeriodSeconds"
const CRYPTNET_PRE_FETCH_MAX_MAX_AGE_SECONDS_DEFAULT = 1209600
const CRYPTNET_PRE_FETCH_MAX_MAX_AGE_SECONDS_VALUE_NAME = "CryptnetPreFetchMaxMaxAgeSeconds"
const CRYPTNET_PRE_FETCH_MIN_AFTER_NEXT_UPDATE_PRE_FETCH_PERIOD_SECONDS_DEFAULT = 1800
const CRYPTNET_PRE_FETCH_MIN_AFTER_NEXT_UPDATE_PRE_FETCH_PERIOD_SECONDS_VALUE_NAME = "CryptnetPreFetchMinAfterNextUpdatePreFetchPeriodSeconds"
const CRYPTNET_PRE_FETCH_MIN_BEFORE_NEXT_UPDATE_PRE_FETCH_PERIOD_SECONDS_DEFAULT = 3600
const CRYPTNET_PRE_FETCH_MIN_BEFORE_NEXT_UPDATE_PRE_FETCH_PERIOD_SECONDS_VALUE_NAME = "CryptnetPreFetchMinBeforeNextUpdatePreFetchSeconds"
const CRYPTNET_PRE_FETCH_MIN_MAX_AGE_SECONDS_DEFAULT = 3600
const CRYPTNET_PRE_FETCH_MIN_MAX_AGE_SECONDS_VALUE_NAME = "CryptnetPreFetchMinMaxAgeSeconds"
const CRYPTNET_PRE_FETCH_MIN_OCSP_VALIDITY_PERIOD_SECONDS_DEFAULT = 1209600
const CRYPTNET_PRE_FETCH_MIN_OCSP_VALIDITY_PERIOD_SECONDS_VALUE_NAME = "CryptnetPreFetchMinOcspValidityPeriodSeconds"
const CRYPTNET_PRE_FETCH_RETRIEVAL_TIMEOUT_SECONDS_DEFAULT = 300
const CRYPTNET_PRE_FETCH_RETRIEVAL_TIMEOUT_SECONDS_VALUE_NAME = "CryptnetPreFetchRetrievalTimeoutSeconds"
const CRYPTNET_PRE_FETCH_SCAN_AFTER_TRIGGER_DELAY_SECONDS_DEFAULT = 30
const CRYPTNET_PRE_FETCH_SCAN_AFTER_TRIGGER_DELAY_SECONDS_VALUE_NAME = "CryptnetPreFetchScanAfterTriggerDelaySeconds"
const CRYPTNET_PRE_FETCH_TRIGGER_DISABLE = 4294967295
const CRYPTNET_PRE_FETCH_TRIGGER_PERIOD_SECONDS_DEFAULT = 600
const CRYPTNET_PRE_FETCH_TRIGGER_PERIOD_SECONDS_VALUE_NAME = "CryptnetPreFetchTriggerPeriodSeconds"
const CRYPTNET_PRE_FETCH_VALIDITY_PERIOD_AFTER_NEXT_UPDATE_PRE_FETCH_DIVISOR_DEFAULT = 10
const CRYPTNET_PRE_FETCH_VALIDITY_PERIOD_AFTER_NEXT_UPDATE_PRE_FETCH_DIVISOR_VALUE_NAME = "CryptnetPreFetchValidityPeriodAfterNextUpdatePreFetchDivisor"
const CRYPTNET_URL_CACHE_DEFAULT_FLUSH = 0
const CRYPTNET_URL_CACHE_DEFAULT_FLUSH_EXEMPT_SECONDS_DEFAULT = 2419200
const CRYPTNET_URL_CACHE_DEFAULT_FLUSH_EXEMPT_SECONDS_VALUE_NAME = "CryptnetDefaultFlushExemptSeconds"
const CRYPTNET_URL_CACHE_DISABLE_FLUSH = 4294967295
const CRYPTNET_URL_CACHE_PRE_FETCH_AUTOROOT_CAB = 5
const CRYPTNET_URL_CACHE_PRE_FETCH_BLOB = 1
const CRYPTNET_URL_CACHE_PRE_FETCH_CRL = 2
const CRYPTNET_URL_CACHE_PRE_FETCH_DISALLOWED_CERT_CAB = 6
const CRYPTNET_URL_CACHE_PRE_FETCH_NONE = 0
const CRYPTNET_URL_CACHE_PRE_FETCH_OCSP = 3
const CRYPTNET_URL_CACHE_PRE_FETCH_PIN_RULES_CAB = 7
const CRYPTNET_URL_CACHE_RESPONSE_HTTP = 1
const CRYPTNET_URL_CACHE_RESPONSE_NONE = 0
const CRYPTNET_URL_CACHE_RESPONSE_VALIDATED = 32768
const CRYPTPROTECTMEMORY_BLOCK_SIZE = 16
const CRYPTPROTECTMEMORY_CROSS_PROCESS = 1
const CRYPTPROTECTMEMORY_SAME_LOGON = 2
const CRYPTPROTECTMEMORY_SAME_PROCESS = 0
const CRYPTPROTECT_AUDIT = 16
const CRYPTPROTECT_CRED_REGENERATE = 128
const CRYPTPROTECT_CRED_SYNC = 8
const CRYPTPROTECT_FIRST_RESERVED_FLAGVAL = 268435455
const CRYPTPROTECT_LAST_RESERVED_FLAGVAL = 4294967295
const CRYPTPROTECT_LOCAL_MACHINE = 4
const CRYPTPROTECT_NO_RECOVERY = 32
const CRYPTPROTECT_PROMPT_ON_PROTECT = 2
const CRYPTPROTECT_PROMPT_ON_UNPROTECT = 1
const CRYPTPROTECT_PROMPT_REQUIRE_STRONG = 16
const CRYPTPROTECT_PROMPT_RESERVED = 4
const CRYPTPROTECT_PROMPT_STRONG = 8
const CRYPTPROTECT_UI_FORBIDDEN = 1
const CRYPTPROTECT_VERIFY_PROTECTION = 64
const CRYPT_ACCUMULATIVE_TIMEOUT = 2048
const CRYPT_ACQUIRE_ALLOW_NCRYPT_KEY_FLAG = 65536
const CRYPT_ACQUIRE_CACHE_FLAG = 1
const CRYPT_ACQUIRE_COMPARE_KEY_FLAG = 4
const CRYPT_ACQUIRE_NCRYPT_KEY_FLAGS_MASK = 458752
const CRYPT_ACQUIRE_NO_HEALING = 8
const CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG = 262144
const CRYPT_ACQUIRE_PREFER_NCRYPT_KEY_FLAG = 131072
const CRYPT_ACQUIRE_SILENT_FLAG = 64
const CRYPT_ACQUIRE_USE_PROV_INFO_FLAG = 2
const CRYPT_ACQUIRE_WINDOW_HANDLE_FLAG = 128
const CRYPT_AIA_RETRIEVAL = 524288
const CRYPT_ALL_FUNCTIONS = 1
const CRYPT_ALL_PROVIDERS = 2
const CRYPT_ANY = 4
const CRYPT_ARCHIVABLE = 16384
const CRYPT_ARCHIVE = 256
const CRYPT_ASN_ENCODING = 1
const CRYPT_ASYNC_RETRIEVAL = 16
const CRYPT_BLOB_VER3 = 128
const CRYPT_CACHE_ONLY_RETRIEVAL = 2
const CRYPT_CHECK_FRESHNESS_TIME_VALIDITY = 1024
const CRYPT_CREATE_IV = 512
const CRYPT_CREATE_NEW_FLUSH_ENTRY = 268435456
const CRYPT_CREATE_SALT = 4
const CRYPT_DATA_KEY = 2048
const CRYPT_DECODE_ALLOC_FLAG = 32768
const CRYPT_DECODE_ENABLE_IA5CONVERSION_FLAG = 100663296
const CRYPT_DECODE_ENABLE_PUNYCODE_FLAG = 33554432
const CRYPT_DECODE_ENABLE_UTF8PERCENT_FLAG = 67108864
const CRYPT_DECODE_NOCOPY_FLAG = 1
const CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG = 8
const CRYPT_DECODE_SHARE_OID_STRING_FLAG = 4
const CRYPT_DECODE_TO_BE_SIGNED_FLAG = 2
const CRYPT_DECRYPT = 2
const CRYPT_DECRYPT_RSA_NO_PADDING_CHECK = 32
const CRYPT_DEFAULT_CONTAINER_OPTIONAL = 128
const CRYPT_DEFAULT_CONTEXT = "Default"
const CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG = 1
const CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID = 1
const CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID = 2
const CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG = 2
const CRYPT_DEFAULT_OID = "DEFAULT"
const CRYPT_DELETEKEYSET = 16
const CRYPT_DELETE_DEFAULT = 4
const CRYPT_DELETE_KEYSET = 16
const CRYPT_DESTROYKEY = 4
const CRYPT_DOMAIN = 2
const CRYPT_DONT_CACHE_RESULT = 8
const CRYPT_DONT_CHECK_TIME_VALIDITY = 512
const CRYPT_DONT_VERIFY_SIGNATURE = 256
const CRYPT_ECC_CMS_SHARED_INFO_SUPPPUBINFO_BYTE_LENGTH = 4
const CRYPT_ECC_PRIVATE_KEY_INFO_v1 = 1
const CRYPT_ENABLE_FILE_RETRIEVAL = 134217728
const CRYPT_ENABLE_SSL_REVOCATION_RETRIEVAL = 8388608
const CRYPT_ENCODE_ALLOC_FLAG = 32768
const CRYPT_ENCODE_DECODE_NONE = 0
const CRYPT_ENCODE_ENABLE_IA5CONVERSION_FLAG = 393216
const CRYPT_ENCODE_ENABLE_PUNYCODE_FLAG = 131072
const CRYPT_ENCODE_ENABLE_UTF8PERCENT_FLAG = 262144
const CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG = 8
const CRYPT_ENCRYPT = 1
const CRYPT_ENCRYPT_ALG_OID_GROUP_ID = 2
const CRYPT_ENHKEY_USAGE_OID_GROUP_ID = 7
const CRYPT_EXCLUSIVE = 1
const CRYPT_EXPORT = 4
const CRYPT_EXPORTABLE = 1
const CRYPT_EXPORT_KEY = 64
const CRYPT_EXT_OR_ATTR_OID_GROUP_ID = 6
const CRYPT_FAILED = 0
const CRYPT_FASTSGC = 2
const CRYPT_FIND_MACHINE_KEYSET_FLAG = 2
const CRYPT_FIND_SILENT_KEYSET_FLAG = 64
const CRYPT_FIND_USER_KEYSET_FLAG = 1
const CRYPT_FIRST = 1
const CRYPT_FIRST_ALG_OID_GROUP_ID = 1
const CRYPT_FLAG_IPSEC = 16
const CRYPT_FLAG_PCT1 = 1
const CRYPT_FLAG_SIGNING = 32
const CRYPT_FLAG_SSL2 = 2
const CRYPT_FLAG_SSL3 = 4
const CRYPT_FLAG_TLS1 = 8
const CRYPT_FORCE_KEY_PROTECTION_HIGH = 32768
const CRYPT_FORMAT_COMMA = 4096
const CRYPT_FORMAT_CRLF = 512
const CRYPT_FORMAT_OID = 4
const CRYPT_FORMAT_RDN_CRLF = 512
const CRYPT_FORMAT_RDN_REVERSE = 2048
const CRYPT_FORMAT_RDN_SEMICOLON = 256
const CRYPT_FORMAT_RDN_UNQUOTE = 1024
const CRYPT_FORMAT_SEMICOLON = 256
const CRYPT_FORMAT_SIMPLE = 1
const CRYPT_FORMAT_STR_MULTI_LINE = 1
const CRYPT_FORMAT_STR_NO_HEX = 16
const CRYPT_FORMAT_X509 = 2
const CRYPT_GET_INSTALLED_OID_FUNC_FLAG = 1
const CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE = 8
const CRYPT_GET_URL_FROM_EXTENSION = 2
const CRYPT_GET_URL_FROM_PROPERTY = 1
const CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE = 4
const CRYPT_HASH_ALG_OID_GROUP_ID = 1
const CRYPT_HTTP_POST_RETRIEVAL = 1048576
const CRYPT_IMPL_HARDWARE = 1
const CRYPT_IMPL_MIXED = 3
const CRYPT_IMPL_REMOVABLE = 8
const CRYPT_IMPL_SOFTWARE = 2
const CRYPT_IMPL_UNKNOWN = 4
const CRYPT_IMPORT_KEY = 128
const CRYPT_INITIATOR = 64
const CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG = 1
const CRYPT_INSTALL_OID_INFO_BEFORE_FLAG = 1
const CRYPT_IPSEC_HMAC_KEY = 256
const CRYPT_KDF_OID_GROUP_ID = 10
const CRYPT_KEEP_TIME_VALID = 128
const CRYPT_KEK = 1024
const CRYPT_KEYID_ALLOC_FLAG = 32768
const CRYPT_KEYID_DELETE_FLAG = 16
const CRYPT_KEYID_MACHINE_FLAG = 32
const CRYPT_KEYID_SET_NEW_FLAG = 8192
const CRYPT_KM = 2
const CRYPT_LAST_ALG_OID_GROUP_ID = 4
const CRYPT_LAST_OID_GROUP_ID = 10
const CRYPT_LDAP_AREC_EXCLUSIVE_RETRIEVAL = 262144
const CRYPT_LDAP_INSERT_ENTRY_ATTRIBUTE = 32768
const CRYPT_LDAP_SCOPE_BASE_ONLY_RETRIEVAL = 8192
const CRYPT_LDAP_SIGN_RETRIEVAL = 65536
const CRYPT_LITTLE_ENDIAN = 1
const CRYPT_LOCAL = 1
const CRYPT_LOCALIZED_NAME_ENCODING_TYPE = 0
const CRYPT_LOCALIZED_NAME_OID = "LocalizedNames"
const CRYPT_MAC = 32
const CRYPT_MACHINE_DEFAULT = 1
const CRYPT_MACHINE_KEYSET = 32
const CRYPT_MATCH_ANY_ENCODING_TYPE = 4294967295
const CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG = 1
const CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG = 2
const CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG = 4
const CRYPT_MESSAGE_KEYID_SIGNER_FLAG = 4
const CRYPT_MESSAGE_SILENT_KEYSET_FLAG = 64
const CRYPT_MIN_DEPENDENCIES = 1
const CRYPT_MM = 3
const CRYPT_MODE_CBC = 1
const CRYPT_MODE_CBCI = 6
const CRYPT_MODE_CBCOFM = 9
const CRYPT_MODE_CBCOFMI = 10
const CRYPT_MODE_CFB = 4
const CRYPT_MODE_CFBP = 7
const CRYPT_MODE_CTS = 5
const CRYPT_MODE_ECB = 2
const CRYPT_MODE_OFB = 3
const CRYPT_MODE_OFBP = 8
const CRYPT_NDR_ENCODING = 2
const CRYPT_NEWKEYSET = 8
const CRYPT_NEXT = 2
const CRYPT_NOHASHOID = 1
const CRYPT_NOT_MODIFIED_RETRIEVAL = 4194304
const CRYPT_NO_AUTH_RETRIEVAL = 131072
const CRYPT_NO_OCSP_FAILOVER_TO_CRL_RETRIEVAL = 33554432
const CRYPT_NO_SALT = 16
const CRYPT_OAEP = 64
const CRYPT_OBJECT_LOCATOR_FIRST_RESERVED_USER_NAME_TYPE = 33
const CRYPT_OBJECT_LOCATOR_LAST_RESERVED_NAME_TYPE = 32
const CRYPT_OBJECT_LOCATOR_LAST_RESERVED_USER_NAME_TYPE = 65535
const CRYPT_OBJECT_LOCATOR_RELEASE_DLL_UNLOAD = 4
const CRYPT_OBJECT_LOCATOR_RELEASE_PROCESS_EXIT = 3
const CRYPT_OBJECT_LOCATOR_RELEASE_SERVICE_STOP = 2
const CRYPT_OBJECT_LOCATOR_RELEASE_SYSTEM_SHUTDOWN = 1
const CRYPT_OBJECT_LOCATOR_SPN_NAME_TYPE = 1
const CRYPT_OCSP_ONLY_RETRIEVAL = 16777216
const CRYPT_OFFLINE_CHECK_RETRIEVAL = 16384
const CRYPT_OID_CREATE_COM_OBJECT_FUNC = "CryptDllCreateCOMObject"
const CRYPT_OID_DECODE_OBJECT_EX_FUNC = "CryptDllDecodeObjectEx"
const CRYPT_OID_DECODE_OBJECT_FUNC = "CryptDllDecodeObject"
const CRYPT_OID_DISABLE_SEARCH_DS_FLAG = 2147483648
const CRYPT_OID_ENCODE_OBJECT_EX_FUNC = "CryptDllEncodeObjectEx"
const CRYPT_OID_ENCODE_OBJECT_FUNC = "CryptDllEncodeObject"
const CRYPT_OID_ENUM_PHYSICAL_STORE_FUNC = "CertDllEnumPhysicalStore"
const CRYPT_OID_ENUM_SYSTEM_STORE_FUNC = "CertDllEnumSystemStore"
const CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC = "CryptDllExportPrivateKeyInfoEx"
const CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_EX2_FUNC = "CryptDllExportPublicKeyInfoEx2"
const CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FROM_BCRYPT_HANDLE_FUNC = "CryptDllExportPublicKeyInfoFromBCryptKeyHandle"
const CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC = "CryptDllExportPublicKeyInfoEx"
const CRYPT_OID_EXTRACT_ENCODED_SIGNATURE_PARAMETERS_FUNC = "CryptDllExtractEncodedSignatureParameters"
const CRYPT_OID_FIND_LOCALIZED_NAME_FUNC = "CryptDllFindLocalizedName"
const CRYPT_OID_FIND_OID_INFO_FUNC = "CryptDllFindOIDInfo"
const CRYPT_OID_FORMAT_OBJECT_FUNC = "CryptDllFormatObject"
const CRYPT_OID_IMPORT_PRIVATE_KEY_INFO_FUNC = "CryptDllImportPrivateKeyInfoEx"
const CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_EX2_FUNC = "CryptDllImportPublicKeyInfoEx2"
const CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC = "CryptDllImportPublicKeyInfoEx"
const CRYPT_OID_INFO_ALGID_KEY = 3
const CRYPT_OID_INFO_CNG_ALGID_KEY = 5
const CRYPT_OID_INFO_CNG_SIGN_KEY = 6
const CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM = "CryptOIDInfoECCParameters"
const CRYPT_OID_INFO_ECC_WRAP_PARAMETERS_ALGORITHM = "CryptOIDInfoECCWrapParameters"
const CRYPT_OID_INFO_HASH_PARAMETERS_ALGORITHM = "CryptOIDInfoHashParameters"
const CRYPT_OID_INFO_MGF1_PARAMETERS_ALGORITHM = "CryptOIDInfoMgf1Parameters"
const CRYPT_OID_INFO_NAME_KEY = 2
const CRYPT_OID_INFO_NO_PARAMETERS_ALGORITHM = "CryptOIDInfoNoParameters"
const CRYPT_OID_INFO_NO_SIGN_ALGORITHM = "CryptOIDInfoNoSign"
const CRYPT_OID_INFO_OAEP_PARAMETERS_ALGORITHM = "CryptOIDInfoOAEPParameters"
const CRYPT_OID_INFO_OID_GROUP_BIT_LEN_MASK = 268369920
const CRYPT_OID_INFO_OID_GROUP_BIT_LEN_SHIFT = 16
const CRYPT_OID_INFO_OID_KEY = 1
const CRYPT_OID_INFO_OID_KEY_FLAGS_MASK = 4294901760
const CRYPT_OID_INFO_PUBKEY_ENCRYPT_KEY_FLAG = 1073741824
const CRYPT_OID_INFO_PUBKEY_SIGN_KEY_FLAG = 2147483648
const CRYPT_OID_INFO_SIGN_KEY = 4
const CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG = 1
const CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG = 4
const CRYPT_OID_OPEN_STORE_PROV_FUNC = "CertDllOpenStoreProv"
const CRYPT_OID_OPEN_SYSTEM_STORE_PROV_FUNC = "CertDllOpenSystemStoreProv"
const CRYPT_OID_PUBKEY_ENCRYPT_ONLY_FLAG = 1073741824
const CRYPT_OID_PUBKEY_SIGN_ONLY_FLAG = 2147483648
const CRYPT_OID_REGISTER_PHYSICAL_STORE_FUNC = "CertDllRegisterPhysicalStore"
const CRYPT_OID_REGISTER_SYSTEM_STORE_FUNC = "CertDllRegisterSystemStore"
const CRYPT_OID_REGPATH = "Software\\\\Microsoft\\\\Cryptography\\\\OID"
const CRYPT_OID_REG_DLL_VALUE_NAME = "Dll"
const CRYPT_OID_REG_ENCODING_TYPE_PREFIX = "EncodingType "
const CRYPT_OID_REG_FLAGS_VALUE_NAME = "CryptFlags"
const CRYPT_OID_REG_FUNC_NAME_VALUE_NAME = "FuncName"
const CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A = "FuncName"
const CRYPT_OID_SIGN_AND_ENCODE_HASH_FUNC = "CryptDllSignAndEncodeHash"
const CRYPT_OID_SYSTEM_STORE_LOCATION_VALUE_NAME = "SystemStoreLocation"
const CRYPT_OID_UNREGISTER_PHYSICAL_STORE_FUNC = "CertDllUnregisterPhysicalStore"
const CRYPT_OID_UNREGISTER_SYSTEM_STORE_FUNC = "CertDllUnregisterSystemStore"
const CRYPT_OID_USE_CURVE_NAME_FOR_ENCODE_FLAG = 536870912
const CRYPT_OID_USE_CURVE_PARAMETERS_FOR_ENCODE_FLAG = 268435456
const CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG = 2
const CRYPT_OID_VERIFY_CERTIFICATE_CHAIN_POLICY_FUNC = "CertDllVerifyCertificateChainPolicy"
const CRYPT_OID_VERIFY_CTL_USAGE_FUNC = "CertDllVerifyCTLUsage"
const CRYPT_OID_VERIFY_ENCODED_SIGNATURE_FUNC = "CryptDllVerifyEncodedSignature"
const CRYPT_OID_VERIFY_REVOCATION_FUNC = "CertDllVerifyRevocation"
const CRYPT_ONLINE = 128
const CRYPT_OVERRIDE = 65536
const CRYPT_OVERWRITE = 1
const CRYPT_OWF_REPL_LM_HASH = 1
const CRYPT_POLICY_OID_GROUP_ID = 8
const CRYPT_PREGEN = 64
const CRYPT_PRIORITY_BOTTOM = 4294967295
const CRYPT_PRIORITY_TOP = 0
const CRYPT_PROCESS_ISOLATE = 65536
const CRYPT_PROXY_CACHE_RETRIEVAL = 2097152
const CRYPT_PSTORE = 2
const CRYPT_PUBKEY_ALG_OID_GROUP_ID = 3
const CRYPT_RANDOM_QUERY_STRING_RETRIEVAL = 67108864
const CRYPT_RC2_128BIT_VERSION = 58
const CRYPT_RC2_40BIT_VERSION = 160
const CRYPT_RC2_56BIT_VERSION = 52
const CRYPT_RC2_64BIT_VERSION = 120
const CRYPT_RDN_ATTR_OID_GROUP_ID = 5
const CRYPT_READ = 8
const CRYPT_RECIPIENT = 16
const CRYPT_REGISTER_FIRST_INDEX = 0
const CRYPT_REGISTER_LAST_INDEX = 4294967295
const CRYPT_RETRIEVE_MAX_ERROR_CONTENT_LENGTH = 4096
const CRYPT_RETRIEVE_MULTIPLE_OBJECTS = 1
const CRYPT_SECRETDIGEST = 1
const CRYPT_SEC_DESCR = 1
const CRYPT_SERVER = 1024
const CRYPT_SF = 256
const CRYPT_SGC = 1
const CRYPT_SGCKEY = 8192
const CRYPT_SGC_ENUM = 4
const CRYPT_SIGN_ALG_OID_GROUP_ID = 4
const CRYPT_SILENT = 64
const CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG = 65536
const CRYPT_SSL2_FALLBACK = 2
const CRYPT_STICKY_CACHE_RETRIEVAL = 4096
const CRYPT_STRING_ANY = 7
const CRYPT_STRING_BASE64 = 1
const CRYPT_STRING_BASE64HEADER = 0
const CRYPT_STRING_BASE64REQUESTHEADER = 3
const CRYPT_STRING_BASE64URI = 13
const CRYPT_STRING_BASE64X509CRLHEADER = 9
const CRYPT_STRING_BASE64_ANY = 6
const CRYPT_STRING_BINARY = 2
const CRYPT_STRING_ENCODEMASK = 255
const CRYPT_STRING_HASHDATA = 268435456
const CRYPT_STRING_HEX = 4
const CRYPT_STRING_HEXADDR = 10
const CRYPT_STRING_HEXASCII = 5
const CRYPT_STRING_HEXASCIIADDR = 11
const CRYPT_STRING_HEXRAW = 12
const CRYPT_STRING_HEX_ANY = 8
const CRYPT_STRING_NOCR = 2147483648
const CRYPT_STRING_NOCRLF = 1073741824
const CRYPT_STRING_PERCENTESCAPE = 134217728
const CRYPT_STRING_RESERVED100 = 256
const CRYPT_STRING_RESERVED200 = 512
const CRYPT_STRING_STRICT = 536870912
const CRYPT_SUCCEED = 1
const CRYPT_TEMPLATE_OID_GROUP_ID = 9
const CRYPT_TYPE2_FORMAT = 2
const CRYPT_UI_PROMPT = 4
const CRYPT_UM = 1
const CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG = 16777216
const CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG = 1073741824
const CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG = 2147483648
const CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG = 536870912
const CRYPT_UNICODE_NAME_ENCODE_FORCE_UTF8_UNICODE_FLAG = 268435456
const CRYPT_UPDATE_KEY = 8
const CRYPT_USERDATA = 1
const CRYPT_USER_DEFAULT = 2
const CRYPT_USER_KEYSET = 4096
const CRYPT_USER_PROTECTED = 2
const CRYPT_USER_PROTECTED_STRONG = 1048576
const CRYPT_VERIFYCONTEXT = 4026531840
const CRYPT_VERIFY_CERT_SIGN_DISABLE_MD2_MD4_FLAG = 1
const CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT = 2
const CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN = 3
const CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL = 4
const CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY = 1
const CRYPT_VERIFY_CERT_SIGN_RETURN_STRONG_PROPERTIES_FLAG = 4
const CRYPT_VERIFY_CERT_SIGN_SET_STRONG_PROPERTIES_FLAG = 2
const CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB = 1
const CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT = 2
const CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL = 3
const CRYPT_VERIFY_CERT_SIGN_SUBJECT_OCSP_BASIC_SIGNED_RESPONSE = 4
const CRYPT_VERIFY_CONTEXT_SIGNATURE = 32
const CRYPT_VERIFY_DATA_HASH = 64
const CRYPT_VOLATILE = 4096
const CRYPT_WIRE_ONLY_RETRIEVAL = 4
const CRYPT_WRITE = 16
const CRYPT_X931_FORMAT = 4
const CRYPT_X942_COUNTER_BYTE_LENGTH = 4
const CRYPT_X942_KEY_LENGTH_BYTE_LENGTH = 4
const CRYPT_X942_PUB_INFO_BYTE_LENGTH = 64
const CRYPT_Y_ONLY = 1
const CSOUND_SYSTEM = 16
const CSTR_EQUAL = 2
const CSTR_GREATER_THAN = 3
const CSTR_LESS_THAN = 1
const CSV_INVALID_DEVICE_NUMBER = 4294967295
const CSV_NAMESPACE_INFO_V1 = 0
const CS_BYTEALIGNCLIENT = 4096
const CS_BYTEALIGNWINDOW = 8192
const CS_CLASSDC = 64
const CS_DBLCLKS = 8
const CS_DELETE_TRANSFORM = 3
const CS_DISABLE = 2
const CS_DROPSHADOW = 131072
const CS_ENABLE = 1
const CS_E_FIRST = 2147746148
const CS_E_LAST = 2147746159
const CS_GLOBALCLASS = 16384
const CS_HREDRAW = 2
const CS_IME = 65536
const CS_INSERTCHAR = 8192
const CS_NOCLOSE = 512
const CS_NOMOVECARET = 16384
const CS_OWNDC = 32
const CS_PARENTDC = 128
const CS_SAVEBITS = 2048
const CS_VREDRAW = 1
const CTLCOLOR_BTN = 3
const CTLCOLOR_DLG = 4
const CTLCOLOR_EDIT = 1
const CTLCOLOR_LISTBOX = 2
const CTLCOLOR_MAX = 7
const CTLCOLOR_MSGBOX = 0
const CTLCOLOR_SCROLLBAR = 5
const CTLCOLOR_STATIC = 6
const CTL_ANY_SUBJECT_TYPE = 1
const CTL_CERT_SUBJECT_TYPE = 2
const CTL_ENTRY_FROM_PROP_CHAIN_FLAG = 1
const CTL_FIND_ANY = 0
const CTL_FIND_EXISTING = 5
const CTL_FIND_MD5_HASH = 2
const CTL_FIND_NO_LIST_ID_CBDATA = 4294967295
const CTL_FIND_NO_SIGNER_PTR = -1
const CTL_FIND_SAME_USAGE_FLAG = 1
const CTL_FIND_SHA1_HASH = 1
const CTL_FIND_SUBJECT = 4
const CTL_FIND_USAGE = 3
const CTL_V1 = 0
const CTMF_INCLUDE_APPCONTAINER = 1
const CTMF_VALID_FLAGS = 1
const CTRL_BREAK_EVENT = 1
const CTRL_CLOSE_EVENT = 2
const CTRL_C_EVENT = 0
const CTRL_LOGOFF_EVENT = 5
const CTRL_SHUTDOWN_EVENT = 6
const CTRY_ALBANIA = 355
const CTRY_ALGERIA = 213
const CTRY_ARGENTINA = 54
const CTRY_ARMENIA = 374
const CTRY_AUSTRALIA = 61
const CTRY_AUSTRIA = 43
const CTRY_AZERBAIJAN = 994
const CTRY_BAHRAIN = 973
const CTRY_BELARUS = 375
const CTRY_BELGIUM = 32
const CTRY_BELIZE = 501
const CTRY_BOLIVIA = 591
const CTRY_BRAZIL = 55
const CTRY_BRUNEI_DARUSSALAM = 673
const CTRY_BULGARIA = 359
const CTRY_CANADA = 2
const CTRY_CARIBBEAN = 1
const CTRY_CHILE = 56
const CTRY_COLOMBIA = 57
const CTRY_COSTA_RICA = 506
const CTRY_CROATIA = 385
const CTRY_CZECH = 420
const CTRY_DEFAULT = 0
const CTRY_DENMARK = 45
const CTRY_DOMINICAN_REPUBLIC = 1
const CTRY_ECUADOR = 593
const CTRY_EGYPT = 20
const CTRY_EL_SALVADOR = 503
const CTRY_ESTONIA = 372
const CTRY_FAEROE_ISLANDS = 298
const CTRY_FINLAND = 358
const CTRY_FRANCE = 33
const CTRY_GEORGIA = 995
const CTRY_GERMANY = 49
const CTRY_GREECE = 30
const CTRY_GUATEMALA = 502
const CTRY_HONDURAS = 504
const CTRY_HONG_KONG = 852
const CTRY_HUNGARY = 36
const CTRY_ICELAND = 354
const CTRY_INDIA = 91
const CTRY_INDONESIA = 62
const CTRY_IRAN = 981
const CTRY_IRAQ = 964
const CTRY_IRELAND = 353
const CTRY_ISRAEL = 972
const CTRY_ITALY = 39
const CTRY_JAMAICA = 1
const CTRY_JAPAN = 81
const CTRY_JORDAN = 962
const CTRY_KAZAKSTAN = 7
const CTRY_KENYA = 254
const CTRY_KUWAIT = 965
const CTRY_KYRGYZSTAN = 996
const CTRY_LATVIA = 371
const CTRY_LEBANON = 961
const CTRY_LIBYA = 218
const CTRY_LIECHTENSTEIN = 41
const CTRY_LITHUANIA = 370
const CTRY_LUXEMBOURG = 352
const CTRY_MACAU = 853
const CTRY_MACEDONIA = 389
const CTRY_MALAYSIA = 60
const CTRY_MALDIVES = 960
const CTRY_MEXICO = 52
const CTRY_MONACO = 33
const CTRY_MONGOLIA = 976
const CTRY_MOROCCO = 212
const CTRY_NETHERLANDS = 31
const CTRY_NEW_ZEALAND = 64
const CTRY_NICARAGUA = 505
const CTRY_NORWAY = 47
const CTRY_OMAN = 968
const CTRY_PAKISTAN = 92
const CTRY_PANAMA = 507
const CTRY_PARAGUAY = 595
const CTRY_PERU = 51
const CTRY_PHILIPPINES = 63
const CTRY_POLAND = 48
const CTRY_PORTUGAL = 351
const CTRY_PRCHINA = 86
const CTRY_PUERTO_RICO = 1
const CTRY_QATAR = 974
const CTRY_ROMANIA = 40
const CTRY_RUSSIA = 7
const CTRY_SAUDI_ARABIA = 966
const CTRY_SERBIA = 381
const CTRY_SINGAPORE = 65
const CTRY_SLOVAK = 421
const CTRY_SLOVENIA = 386
const CTRY_SOUTH_AFRICA = 27
const CTRY_SOUTH_KOREA = 82
const CTRY_SPAIN = 34
const CTRY_SWEDEN = 46
const CTRY_SWITZERLAND = 41
const CTRY_SYRIA = 963
const CTRY_TAIWAN = 886
const CTRY_TATARSTAN = 7
const CTRY_THAILAND = 66
const CTRY_TRINIDAD_Y_TOBAGO = 1
const CTRY_TUNISIA = 216
const CTRY_TURKEY = 90
const CTRY_UAE = 971
const CTRY_UKRAINE = 380
const CTRY_UNITED_KINGDOM = 44
const CTRY_UNITED_STATES = 1
const CTRY_URUGUAY = 598
const CTRY_UZBEKISTAN = 7
const CTRY_VENEZUELA = 58
const CTRY_VIET_NAM = 84
const CTRY_YEMEN = 967
const CTRY_ZIMBABWE = 263
const CT_CTYPE1 = 1
const CT_CTYPE2 = 2
const CT_CTYPE3 = 4
const CURRENT_IMPORT_REDIRECTION_VERSION = 1
const CURSOR_FAULT = 4
const CURSOR_INVALID = 1
const CURSOR_REQUIRESEEK = 3
const CURSOR_SHOWING = 1
const CURSOR_SKIPNEXT = 2
const CURSOR_SUPPRESSED = 2
const CURSOR_VALID = 0
const CURTYPE_BTREE = 0
const CURTYPE_PSEUDO = 3
const CURTYPE_SORTER = 1
const CURTYPE_VTAB = 2
const CURVECAPS = 28
const CUR_BLOB_VERSION = 2
const CWCSTORAGENAME = 32
const CWF_CREATE_ONLY = 1
const CWMO_MAX_HANDLES = 56
const CWP_ALL = 0
const CWP_SKIPDISABLED = 2
const CWP_SKIPINVISIBLE = 1
const CWP_SKIPTRANSPARENT = 4
const CallMsgFilter = 0
const CallNamedPipe = 0
const CallWindowProc = 0
const CaptureStackBackTrace = 0
const CdChangerClassGuid = 0
const CdRomClassGuid = 0
const CertAddEncodedCertificateToSystemStore = 0
const CertGetNameString = 0
const CertNameToStr = 0
const CertOpenSystemStore = 0
const CertRDNValueToStr = 0
const CertStrToName = 0
const ChangeDisplaySettings = 0
const ChangeDisplaySettingsEx = 0
const ChangeMenu = 0
const ChangeServiceConfig = 0
const ChangeServiceConfig2 = 0
const CharLower = 0
const CharLowerBuff = 0
const CharNext = 0
const CharPrev = 0
const CharToOem = 0
const CharToOemBuff = 0
const CharUpper = 0
const CharUpperBuff = 0
const CheckNameLegalDOS8Dot3 = 0
const ChooseColor = 0
const ChooseFont = 0
const ClearEventLog = 0
const CommConfigDialog = 0
const CommDlg_OpenSave_GetFilePath = 0
const CommDlg_OpenSave_GetFolderPath = 0
const CommDlg_OpenSave_GetSpec = 0
const CompareString = 0
const ConfigurePort = 0
const ControlServiceEx = 0
const CopyAcceleratorTable = 0
const CopyEnhMetaFile = 0
const CopyFile = 0
const CopyFileEx = 0
const CopyFileTransacted = 0
const CopyMemory = 0
const CopyMetaFile = 0
const CreateAcceleratorTable = 0
const CreateActCtx = 0
const CreateBoundaryDescriptor = 0
const CreateColorSpace = 0
const CreateDC = 0
const CreateDesktop = 0
const CreateDesktopEx = 0
const CreateDialog = 0
const CreateDialogIndirect = 0
const CreateDialogIndirectParam = 0
const CreateDialogParam = 0
const CreateDirectory = 0
const CreateDirectoryEx = 0
const CreateDirectoryTransacted = 0
const CreateEnhMetaFile = 0
const CreateEvent = 0
const CreateEventEx = 0
const CreateFile = 0
const CreateFileMapping = 0
const CreateFileMappingNuma = 0
const CreateFileTransacted = 0
const CreateFont = 0
const CreateFontIndirect = 0
const CreateFontIndirectEx = 0
const CreateHardLink = 0
const CreateHardLinkTransacted = 0
const CreateIC = 0
const CreateJobObject = 0
const CreateMDIWindow = 0
const CreateMailslot = 0
const CreateMetaFile = 0
const CreateMutex = 0
const CreateMutexEx = 0
const CreateNamedPipe = 0
const CreatePrivateNamespace = 0
const CreateProcess = 0
const CreateProcessAsUser = 0
const CreatePropertySheetPage = 0
const CreateScalableFontResource = 0
const CreateSemaphore = 0
const CreateSemaphoreEx = 0
const CreateService = 0
const CreateSymbolicLink = 0
const CreateSymbolicLinkTransacted = 0
const CreateWaitableTimer = 0
const CreateWaitableTimerEx = 0
const CreateWindow = 0
const CreateWindowEx = 0
const CreateWindowStation = 0
const CryptAcquireContext = 0
const CryptBinaryToString = 0
const CryptEnumProviderTypes = 0
const CryptEnumProviders = 0
const CryptGetDefaultProvider = 0
const CryptRetrieveObjectByUrl = 0
const CryptSetProvider = 0
const CryptSetProviderEx = 0
const CryptSignHash = 0
const CryptStringToBinary = 0
const CryptVerifySignature = 0
const DACL_SECURITY_INFORMATION = 4
const DATA_E_FIRST = 2147746096
const DATA_E_FORMATETC = "DV_E_FORMATETC"
const DATA_E_LAST = 2147746111
const DATA_S_FIRST = 262448
const DATA_S_LAST = 262463
const DATEFMT_ENUMPROC = 0
const DATEFMT_ENUMPROCEX = 0
const DATE_AUTOLAYOUT = 64
const DATE_LONGDATE = 2
const DATE_LTRREADING = 16
const DATE_MONTHDAY = 128
const DATE_RTLREADING = 32
const DATE_SHORTDATE = 1
const DATE_USE_ALT_CALENDAR = 4
const DATE_YEARMONTH = 8
const DBFLAG_EncodingFixed = 64
const DBFLAG_InternalFunc = 32
const DBFLAG_PreferBuiltin = 2
const DBFLAG_SchemaChange = 1
const DBFLAG_SchemaKnownOk = 16
const DBFLAG_Vacuum = 4
const DBFLAG_VacuumInto = 8
const DBSTAT_PAGE_PADDING_BYTES = 256
const DB_ResetWanted = 8
const DB_SchemaLoaded = 1
const DB_UnresetViews = 2
const DCBA_FACEDOWNCENTER = 257
const DCBA_FACEDOWNLEFT = 258
const DCBA_FACEDOWNNONE = 256
const DCBA_FACEDOWNRIGHT = 259
const DCBA_FACEUPCENTER = 1
const DCBA_FACEUPLEFT = 2
const DCBA_FACEUPNONE = 0
const DCBA_FACEUPRIGHT = 3
const DCB_ACCUMULATE = 2
const DCB_DIRTY = 2
const DCB_DISABLE = 8
const DCB_ENABLE = 4
const DCB_RESET = 1
const DCB_SET = 3
const DCE_C_ERROR_STRING_LEN = 256
const DCOMSCM_ACTIVATION_DISALLOW_UNSECURE_CALL = 2
const DCOMSCM_ACTIVATION_USE_ALL_AUTHNSERVICES = 1
const DCOMSCM_PING_DISALLOW_UNSECURE_CALL = 32
const DCOMSCM_PING_USE_MID_AUTHNSERVICE = 16
const DCOMSCM_RESOLVE_DISALLOW_UNSECURE_CALL = 8
const DCOMSCM_RESOLVE_USE_ALL_AUTHNSERVICES = 4
const DCTT_BITMAP = 1
const DCTT_DOWNLOAD = 2
const DCTT_DOWNLOAD_OUTLINE = 8
const DCTT_SUBDEV = 4
const DCX_CACHE = 2
const DCX_CLIPCHILDREN = 8
const DCX_CLIPSIBLINGS = 16
const DCX_EXCLUDERGN = 64
const DCX_EXCLUDEUPDATE = 256
const DCX_INTERSECTRGN = 128
const DCX_INTERSECTUPDATE = 512
const DCX_LOCKWINDOWUPDATE = 1024
const DCX_NORESETATTRS = 4
const DCX_PARENTCLIP = 32
const DCX_VALIDATE = 2097152
const DCX_WINDOW = 1
const DC_ACTIVE = 1
const DC_BINADJUST = 19
const DC_BINNAMES = 12
const DC_BINS = 6
const DC_BRUSH = 18
const DC_BUTTONS = 4096
const DC_COLLATE = 22
const DC_COLORDEVICE = 32
const DC_COPIES = 18
const DC_DATATYPE_PRODUCED = 21
const DC_DRIVER = 11
const DC_DUPLEX = 7
const DC_EMF_COMPLIANT = 20
const DC_ENUMRESOLUTIONS = 13
const DC_EXTRA = 9
const DC_FIELDS = 1
const DC_FILEDEPENDENCIES = 14
const DC_GRADIENT = 32
const DC_HASDEFID = 21323
const DC_ICON = 4
const DC_INBUTTON = 16
const DC_MANUFACTURER = 23
const DC_MAXEXTENT = 5
const DC_MEDIAREADY = 29
const DC_MEDIATYPENAMES = 34
const DC_MEDIATYPES = 35
const DC_MINEXTENT = 4
const DC_MODEL = 24
const DC_NUP = 33
const DC_ORIENTATION = 17
const DC_PAPERNAMES = 16
const DC_PAPERS = 2
const DC_PAPERSIZE = 3
const DC_PEN = 19
const DC_PERSONALITY = 25
const DC_PRINTERMEM = 28
const DC_PRINTRATE = 26
const DC_PRINTRATEPPM = 31
const DC_PRINTRATEUNIT = 27
const DC_SIZE = 8
const DC_SMALLCAP = 2
const DC_STAPLE = 30
const DC_TEXT = 8
const DC_TRUETYPE = 15
const DC_VERSION = 10
const DDD_EXACT_MATCH_ON_REMOVE = 4
const DDD_LUID_BROADCAST_DRIVE = 16
const DDD_NO_BROADCAST_SYSTEM = 8
const DDD_RAW_TARGET_PATH = 1
const DDD_REMOVE_DEFINITION = 2
const DDE_FACK = 32768
const DDE_FACKREQ = 32768
const DDE_FACKRESERVED = -49408
const DDE_FADVRESERVED = -49153
const DDE_FAPPSTATUS = 255
const DDE_FBUSY = 16384
const DDE_FDATRESERVED = -45057
const DDE_FDEFERUPD = 16384
const DDE_FNOTPROCESSED = 0
const DDE_FPOKRESERVED = -8193
const DDE_FRELEASE = 8192
const DDE_FREQUESTED = 4096
const DDL_ARCHIVE = 32
const DDL_DIRECTORY = 16
const DDL_DRIVES = 16384
const DDL_EXCLUSIVE = 32768
const DDL_HIDDEN = 2
const DDL_POSTMSGS = 8192
const DDL_READONLY = 1
const DDL_READWRITE = 0
const DDL_SYSTEM = 4
const DD_DEFDRAGDELAY = 200
const DD_DEFDRAGMINDIST = 2
const DD_DEFSCROLLDELAY = 50
const DD_DEFSCROLLINSET = 11
const DD_DEFSCROLLINTERVAL = 50
const DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION = 1
const DEBUG_ONLY_THIS_PROCESS = 2
const DEBUG_PROCESS = 1
const DEFAULT_CHARSET = 1
const DEFAULT_GUI_FONT = 17
const DEFAULT_IMPERSONATION_LEVEL = 0
const DEFAULT_PALETTE = 15
const DEFAULT_PITCH = 0
const DEFAULT_QUALITY = 0
const DEF_PRIORITY = 1
const DELETE = 65536
const DEREGISTERED = 5
const DESKTOPHORZRES = 118
const DESKTOPVERTRES = 117
const DESKTOP_CREATEMENU = 4
const DESKTOP_CREATEWINDOW = 2
const DESKTOP_ENUMERATE = 64
const DESKTOP_HOOKCONTROL = 8
const DESKTOP_JOURNALPLAYBACK = 32
const DESKTOP_JOURNALRECORD = 16
const DESKTOP_READOBJECTS = 1
const DESKTOP_SWITCHDESKTOP = 256
const DESKTOP_WRITEOBJECTS = 128
const DETACHED_PROCESS = 8
const DEVICEDATA = 19
const DEVICE_DEFAULT_FONT = 14
const DEVICE_DSM_FLAG_ENTIRE_DATA_SET_RANGE = 1
const DEVICE_DSM_NOTIFY_FLAG_BEGIN = 1
const DEVICE_DSM_NOTIFY_FLAG_END = 2
const DEVICE_FONTTYPE = 2
const DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 4
const DEVICE_NOTIFY_SERVICE_HANDLE = 1
const DEVICE_NOTIFY_WINDOW_HANDLE = 0
const DEVICE_TYPE = 0
const DFCS_ADJUSTRECT = 8192
const DFCS_BUTTON3STATE = 8
const DFCS_BUTTONCHECK = 0
const DFCS_BUTTONPUSH = 16
const DFCS_BUTTONRADIO = 4
const DFCS_BUTTONRADIOIMAGE = 1
const DFCS_BUTTONRADIOMASK = 2
const DFCS_CAPTIONCLOSE = 0
const DFCS_CAPTIONHELP = 4
const DFCS_CAPTIONMAX = 2
const DFCS_CAPTIONMIN = 1
const DFCS_CAPTIONRESTORE = 3
const DFCS_CHECKED = 1024
const DFCS_FLAT = 16384
const DFCS_HOT = 4096
const DFCS_INACTIVE = 256
const DFCS_MENUARROW = 0
const DFCS_MENUARROWRIGHT = 4
const DFCS_MENUBULLET = 2
const DFCS_MENUCHECK = 1
const DFCS_MONO = 32768
const DFCS_PUSHED = 512
const DFCS_SCROLLCOMBOBOX = 5
const DFCS_SCROLLDOWN = 1
const DFCS_SCROLLLEFT = 2
const DFCS_SCROLLRIGHT = 3
const DFCS_SCROLLSIZEGRIP = 8
const DFCS_SCROLLSIZEGRIPRIGHT = 16
const DFCS_SCROLLUP = 0
const DFCS_TRANSPARENT = 2048
const DFC_BUTTON = 4
const DFC_CAPTION = 1
const DFC_MENU = 2
const DFC_POPUPMENU = 5
const DFC_SCROLL = 3
const DF_ALLOWOTHERACCOUNTHOOK = 1
const DIAGNOSTIC_REASON_DETAILED_STRING = 2
const DIAGNOSTIC_REASON_INVALID_FLAGS = -2147483652
const DIAGNOSTIC_REASON_NOT_SPECIFIED = 2147483648
const DIAGNOSTIC_REASON_SIMPLE_STRING = 1
const DIAGNOSTIC_REASON_VERSION = 0
const DIALOPTION_BILLING = 64
const DIALOPTION_DIALTONE = 256
const DIALOPTION_QUIET = 128
const DIB_PAL_COLORS = 1
const DIB_RGB_COLORS = 0
const DIFFERENCE = 11
const DIRECT_MODE = 0
const DISABLE_MAX_PRIVILEGE = 1
const DISABLE_NEWLINE_AUTO_RETURN = 8
const DISABLE_SMART = 217
const DISCHARGE_POLICY_CRITICAL = 0
const DISCHARGE_POLICY_LOW = 1
const DISC_NO_FORCE = 64
const DISC_UPDATE_PROFILE = 1
const DISK_BINNING = 3
const DISK_HISTOGRAM_SIZE = 0
const DISK_LOGGING_DUMP = 2
const DISK_LOGGING_START = 0
const DISK_LOGGING_STOP = 1
const DISPATCH_METHOD = 1
const DISPATCH_PROPERTYGET = 2
const DISPATCH_PROPERTYPUT = 4
const DISPATCH_PROPERTYPUTREF = 8
const DISPID_COLLECT = -8
const DISPID_CONSTRUCTOR = -6
const DISPID_DESTRUCTOR = -7
const DISPID_EVALUATE = -5
const DISPID_NEWENUM = -4
const DISPID_PROPERTYPUT = -3
const DISPID_UNKNOWN = -1
const DISPID_VALUE = 0
const DISPLAYCONFIG_MAXPATH = 1024
const DISPLAYCONFIG_PATH_ACTIVE = 1
const DISPLAYCONFIG_PATH_CLONE_GROUP_INVALID = 65535
const DISPLAYCONFIG_PATH_DESKTOP_IMAGE_IDX_INVALID = 65535
const DISPLAYCONFIG_PATH_MODE_IDX_INVALID = 4294967295
const DISPLAYCONFIG_PATH_PREFERRED_UNSCALED = 4
const DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID = 65535
const DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE = 8
const DISPLAYCONFIG_PATH_TARGET_MODE_IDX_INVALID = 65535
const DISPLAYCONFIG_PATH_VALID_FLAGS = 13
const DISPLAYCONFIG_SOURCE_IN_USE = 1
const DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_BOOT = 4
const DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_PATH = 8
const DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_SYSTEM = 16
const DISPLAYCONFIG_TARGET_FORCIBLE = 2
const DISPLAYCONFIG_TARGET_IN_USE = 1
const DISPLAYCONFIG_TARGET_IS_HMD = 32
const DISPLAY_DEVICE_ACC_DRIVER = 64
const DISPLAY_DEVICE_ACTIVE = 1
const DISPLAY_DEVICE_ATTACHED = 2
const DISPLAY_DEVICE_ATTACHED_TO_DESKTOP = 1
const DISPLAY_DEVICE_DISCONNECT = 33554432
const DISPLAY_DEVICE_MIRRORING_DRIVER = 8
const DISPLAY_DEVICE_MODESPRUNED = 134217728
const DISPLAY_DEVICE_MULTI_DRIVER = 2
const DISPLAY_DEVICE_PRIMARY_DEVICE = 4
const DISPLAY_DEVICE_RDPUDD = 16777216
const DISPLAY_DEVICE_REMOTE = 67108864
const DISPLAY_DEVICE_REMOVABLE = 32
const DISPLAY_DEVICE_TS_COMPATIBLE = 2097152
const DISPLAY_DEVICE_UNSAFE_MODES_ON = 524288
const DISPLAY_DEVICE_VGA_COMPATIBLE = 16
const DISP_CHANGE_BADDUALVIEW = -6
const DISP_CHANGE_BADFLAGS = -4
const DISP_CHANGE_BADMODE = -2
const DISP_CHANGE_BADPARAM = -5
const DISP_CHANGE_FAILED = -1
const DISP_CHANGE_NOTUPDATED = -3
const DISP_CHANGE_RESTART = 1
const DISP_CHANGE_SUCCESSFUL = 0
const DI_APPBANDING = 1
const DI_CHANNEL = 1
const DI_COMPAT = 4
const DI_DEFAULTSIZE = 8
const DI_IMAGE = 2
const DI_MASK = 1
const DI_MEMORYMAP_WRITE = 1
const DI_NOMIRROR = 16
const DI_NORMAL = 3
const DI_READ_SPOOL_JOB = 3
const DI_ROPS_READ_DESTINATION = 2
const DKGRAY_BRUSH = 3
const DLGC_BUTTON = 8192
const DLGC_DEFPUSHBUTTON = 16
const DLGC_HASSETSEL = 8
const DLGC_RADIOBUTTON = 64
const DLGC_STATIC = 256
const DLGC_UNDEFPUSHBUTTON = 32
const DLGC_WANTALLKEYS = 4
const DLGC_WANTARROWS = 1
const DLGC_WANTCHARS = 128
const DLGC_WANTMESSAGE = 4
const DLGC_WANTTAB = 2
const DLGWINDOWEXTRA = 30
const DLL_PROCESS_ATTACH = 1
const DLL_PROCESS_DETACH = 0
const DLL_PROCESS_VERIFIER = 4
const DLL_THREAD_ATTACH = 2
const DLL_THREAD_DETACH = 3
const DMBIN_AUTO = 7
const DMBIN_CASSETTE = 14
const DMBIN_ENVELOPE = 5
const DMBIN_ENVMANUAL = 6
const DMBIN_FIRST = 1
const DMBIN_FORMSOURCE = 15
const DMBIN_LARGECAPACITY = 11
const DMBIN_LARGEFMT = 10
const DMBIN_LAST = 15
const DMBIN_LOWER = 2
const DMBIN_MANUAL = 4
const DMBIN_MIDDLE = 3
const DMBIN_ONLYONE = 1
const DMBIN_SMALLFMT = 9
const DMBIN_TRACTOR = 8
const DMBIN_UPPER = 1
const DMBIN_USER = 256
const DMCOLLATE_FALSE = 0
const DMCOLLATE_TRUE = 1
const DMCOLOR_COLOR = 2
const DMCOLOR_MONOCHROME = 1
const DMDFO_CENTER = 2
const DMDFO_DEFAULT = 0
const DMDFO_STRETCH = 1
const DMDISPLAYFLAGS_TEXTMODE = 4
const DMDITHER_COARSE = 2
const DMDITHER_ERRORDIFFUSION = 5
const DMDITHER_FINE = 3
const DMDITHER_GRAYSCALE = 10
const DMDITHER_LINEART = 4
const DMDITHER_NONE = 1
const DMDITHER_RESERVED6 = 6
const DMDITHER_RESERVED7 = 7
const DMDITHER_RESERVED8 = 8
const DMDITHER_RESERVED9 = 9
const DMDITHER_USER = 256
const DMDO_180 = 2
const DMDO_270 = 3
const DMDO_90 = 1
const DMDO_DEFAULT = 0
const DMDUP_HORIZONTAL = 3
const DMDUP_SIMPLEX = 1
const DMDUP_VERTICAL = 2
const DMICMMETHOD_DEVICE = 4
const DMICMMETHOD_DRIVER = 3
const DMICMMETHOD_NONE = 1
const DMICMMETHOD_SYSTEM = 2
const DMICMMETHOD_USER = 256
const DMICM_ABS_COLORIMETRIC = 4
const DMICM_COLORIMETRIC = 3
const DMICM_CONTRAST = 2
const DMICM_SATURATE = 1
const DMICM_USER = 256
const DMLERR_ADVACKTIMEOUT = 16384
const DMLERR_BUSY = 16385
const DMLERR_DATAACKTIMEOUT = 16386
const DMLERR_DLL_NOT_INITIALIZED = 16387
const DMLERR_DLL_USAGE = 16388
const DMLERR_EXECACKTIMEOUT = 16389
const DMLERR_FIRST = 16384
const DMLERR_INVALIDPARAMETER = 16390
const DMLERR_LAST = 16401
const DMLERR_LOW_MEMORY = 16391
const DMLERR_MEMORY_ERROR = 16392
const DMLERR_NOTPROCESSED = 16393
const DMLERR_NO_CONV_ESTABLISHED = 16394
const DMLERR_NO_ERROR = 0
const DMLERR_POKEACKTIMEOUT = 16395
const DMLERR_POSTMSG_FAILED = 16396
const DMLERR_REENTRANCY = 16397
const DMLERR_SERVER_DIED = 16398
const DMLERR_SYS_ERROR = 16399
const DMLERR_UNADVACKTIMEOUT = 16400
const DMLERR_UNFOUND_QUEUE_ID = 16401
const DMMEDIA_GLOSSY = 3
const DMMEDIA_STANDARD = 1
const DMMEDIA_TRANSPARENCY = 2
const DMMEDIA_USER = 256
const DMNUP_ONEUP = 2
const DMNUP_SYSTEM = 1
const DMORIENT_LANDSCAPE = 2
const DMORIENT_PORTRAIT = 1
const DMPAPER_10X11 = 45
const DMPAPER_10X14 = 16
const DMPAPER_11X17 = 17
const DMPAPER_12X11 = 90
const DMPAPER_15X11 = 46
const DMPAPER_9X11 = 44
const DMPAPER_A2 = 66
const DMPAPER_A3 = 8
const DMPAPER_A3_EXTRA = 63
const DMPAPER_A3_EXTRA_TRANSVERSE = 68
const DMPAPER_A3_ROTATED = 76
const DMPAPER_A3_TRANSVERSE = 67
const DMPAPER_A4 = 9
const DMPAPER_A4SMALL = 10
const DMPAPER_A4_EXTRA = 53
const DMPAPER_A4_PLUS = 60
const DMPAPER_A4_ROTATED = 77
const DMPAPER_A4_TRANSVERSE = 55
const DMPAPER_A5 = 11
const DMPAPER_A5_EXTRA = 64
const DMPAPER_A5_ROTATED = 78
const DMPAPER_A5_TRANSVERSE = 61
const DMPAPER_A6 = 70
const DMPAPER_A6_ROTATED = 83
const DMPAPER_A_PLUS = 57
const DMPAPER_B4 = 12
const DMPAPER_B4_JIS_ROTATED = 79
const DMPAPER_B5 = 13
const DMPAPER_B5_EXTRA = 65
const DMPAPER_B5_JIS_ROTATED = 80
const DMPAPER_B5_TRANSVERSE = 62
const DMPAPER_B6_JIS = 88
const DMPAPER_B6_JIS_ROTATED = 89
const DMPAPER_B_PLUS = 58
const DMPAPER_CSHEET = 24
const DMPAPER_DBL_JAPANESE_POSTCARD = 69
const DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED = 82
const DMPAPER_DSHEET = 25
const DMPAPER_ENV_10 = 20
const DMPAPER_ENV_11 = 21
const DMPAPER_ENV_12 = 22
const DMPAPER_ENV_14 = 23
const DMPAPER_ENV_9 = 19
const DMPAPER_ENV_B4 = 33
const DMPAPER_ENV_B5 = 34
const DMPAPER_ENV_B6 = 35
const DMPAPER_ENV_C3 = 29
const DMPAPER_ENV_C4 = 30
const DMPAPER_ENV_C5 = 28
const DMPAPER_ENV_C6 = 31
const DMPAPER_ENV_C65 = 32
const DMPAPER_ENV_DL = 27
const DMPAPER_ENV_INVITE = 47
const DMPAPER_ENV_ITALY = 36
const DMPAPER_ENV_MONARCH = 37
const DMPAPER_ENV_PERSONAL = 38
const DMPAPER_ESHEET = 26
const DMPAPER_EXECUTIVE = 7
const DMPAPER_FANFOLD_LGL_GERMAN = 41
const DMPAPER_FANFOLD_STD_GERMAN = 40
const DMPAPER_FANFOLD_US = 39
const DMPAPER_FIRST = 1
const DMPAPER_FOLIO = 14
const DMPAPER_ISO_B4 = 42
const DMPAPER_JAPANESE_POSTCARD = 43
const DMPAPER_JAPANESE_POSTCARD_ROTATED = 81
const DMPAPER_JENV_CHOU3 = 73
const DMPAPER_JENV_CHOU3_ROTATED = 86
const DMPAPER_JENV_CHOU4 = 74
const DMPAPER_JENV_CHOU4_ROTATED = 87
const DMPAPER_JENV_KAKU2 = 71
const DMPAPER_JENV_KAKU2_ROTATED = 84
const DMPAPER_JENV_KAKU3 = 72
const DMPAPER_JENV_KAKU3_ROTATED = 85
const DMPAPER_JENV_YOU4 = 91
const DMPAPER_JENV_YOU4_ROTATED = 92
const DMPAPER_LAST = 118
const DMPAPER_LEDGER = 4
const DMPAPER_LEGAL = 5
const DMPAPER_LEGAL_EXTRA = 51
const DMPAPER_LETTER = 1
const DMPAPER_LETTERSMALL = 2
const DMPAPER_LETTER_EXTRA = 50
const DMPAPER_LETTER_EXTRA_TRANSVERSE = 56
const DMPAPER_LETTER_PLUS = 59
const DMPAPER_LETTER_ROTATED = 75
const DMPAPER_LETTER_TRANSVERSE = 54
const DMPAPER_NOTE = 18
const DMPAPER_P16K = 93
const DMPAPER_P16K_ROTATED = 106
const DMPAPER_P32K = 94
const DMPAPER_P32KBIG = 95
const DMPAPER_P32KBIG_ROTATED = 108
const DMPAPER_P32K_ROTATED = 107
const DMPAPER_PENV_1 = 96
const DMPAPER_PENV_10 = 105
const DMPAPER_PENV_10_ROTATED = 118
const DMPAPER_PENV_1_ROTATED = 109
const DMPAPER_PENV_2 = 97
const DMPAPER_PENV_2_ROTATED = 110
const DMPAPER_PENV_3 = 98
const DMPAPER_PENV_3_ROTATED = 111
const DMPAPER_PENV_4 = 99
const DMPAPER_PENV_4_ROTATED = 112
const DMPAPER_PENV_5 = 100
const DMPAPER_PENV_5_ROTATED = 113
const DMPAPER_PENV_6 = 101
const DMPAPER_PENV_6_ROTATED = 114
const DMPAPER_PENV_7 = 102
const DMPAPER_PENV_7_ROTATED = 115
const DMPAPER_PENV_8 = 103
const DMPAPER_PENV_8_ROTATED = 116
const DMPAPER_PENV_9 = 104
const DMPAPER_PENV_9_ROTATED = 117
const DMPAPER_QUARTO = 15
const DMPAPER_RESERVED_48 = 48
const DMPAPER_RESERVED_49 = 49
const DMPAPER_STATEMENT = 6
const DMPAPER_TABLOID = 3
const DMPAPER_TABLOID_EXTRA = 52
const DMPAPER_USER = 256
const DMRES_DRAFT = -1
const DMRES_HIGH = -4
const DMRES_LOW = -2
const DMRES_MEDIUM = -3
const DMTT_BITMAP = 1
const DMTT_DOWNLOAD = 2
const DMTT_DOWNLOAD_OUTLINE = 4
const DMTT_SUBDEV = 3
const DM_BITSPERPEL = 262144
const DM_COLLATE = 32768
const DM_COLOR = 2048
const DM_COPIES = 256
const DM_COPY = 2
const DM_DEFAULTSOURCE = 512
const DM_DISPLAYFIXEDOUTPUT = 536870912
const DM_DISPLAYFLAGS = 2097152
const DM_DISPLAYFREQUENCY = 4194304
const DM_DISPLAYORIENTATION = 128
const DM_DITHERTYPE = 67108864
const DM_DUPLEX = 4096
const DM_FORMNAME = 65536
const DM_GETDEFID = 1024
const DM_ICMINTENT = 16777216
const DM_ICMMETHOD = 8388608
const DM_INTERLACED = 2
const DM_IN_BUFFER = 8
const DM_IN_PROMPT = 4
const DM_LOGPIXELS = 131072
const DM_MEDIATYPE = 33554432
const DM_MODIFY = 8
const DM_NUP = 64
const DM_ORIENTATION = 1
const DM_OUT_BUFFER = 2
const DM_OUT_DEFAULT = 1
const DM_PANNINGHEIGHT = 268435456
const DM_PANNINGWIDTH = 134217728
const DM_PAPERLENGTH = 4
const DM_PAPERSIZE = 2
const DM_PAPERWIDTH = 8
const DM_PELSHEIGHT = 1048576
const DM_PELSWIDTH = 524288
const DM_POINTERHITTEST = 592
const DM_POSITION = 32
const DM_PRINTQUALITY = 1024
const DM_PROMPT = 4
const DM_REPOSITION = 1026
const DM_SCALE = 16
const DM_SETDEFID = 1025
const DM_SPECVERSION = 1025
const DM_TTOPTION = 16384
const DM_UPDATE = 1
const DM_YRESOLUTION = 8192
const DNS_ERROR_AUTOZONE_ALREADY_EXISTS = 9610
const DNS_ERROR_AXFR = 9752
const DNS_ERROR_BAD_PACKET = 9502
const DNS_ERROR_CANNOT_FIND_ROOT_HINTS = 9564
const DNS_ERROR_CNAME_COLLISION = 9709
const DNS_ERROR_CNAME_LOOP = 9707
const DNS_ERROR_DATABASE_BASE = 9700
const DNS_ERROR_DATAFILE_BASE = 9650
const DNS_ERROR_DATAFILE_OPEN_FAILURE = 9653
const DNS_ERROR_DATAFILE_PARSING = 9655
const DNS_ERROR_DP_ALREADY_ENLISTED = 9904
const DNS_ERROR_DP_ALREADY_EXISTS = 9902
const DNS_ERROR_DP_BASE = 9900
const DNS_ERROR_DP_DOES_NOT_EXIST = 9901
const DNS_ERROR_DP_FSMO_ERROR = 9906
const DNS_ERROR_DP_NOT_AVAILABLE = 9905
const DNS_ERROR_DP_NOT_ENLISTED = 9903
const DNS_ERROR_DS_UNAVAILABLE = 9717
const DNS_ERROR_DS_ZONE_ALREADY_EXISTS = 9718
const DNS_ERROR_FILE_WRITEBACK_FAILED = 9654
const DNS_ERROR_FORWARDER_ALREADY_EXISTS = 9619
const DNS_ERROR_GENERAL_API_BASE = 9550
const DNS_ERROR_INCONSISTENT_ROOT_HINTS = 9565
const DNS_ERROR_INVALID_DATA = 13
const DNS_ERROR_INVALID_DATAFILE_NAME = 9652
const DNS_ERROR_INVALID_IP_ADDRESS = 9552
const DNS_ERROR_INVALID_NAME = 123
const DNS_ERROR_INVALID_NAME_CHAR = 9560
const DNS_ERROR_INVALID_PROPERTY = 9553
const DNS_ERROR_INVALID_TYPE = 9551
const DNS_ERROR_INVALID_ZONE_OPERATION = 9603
const DNS_ERROR_INVALID_ZONE_TYPE = 9611
const DNS_ERROR_MASK = 9000
const DNS_ERROR_NAME_DOES_NOT_EXIST = 9714
const DNS_ERROR_NAME_NOT_IN_ZONE = 9706
const DNS_ERROR_NBSTAT_INIT_FAILED = 9617
const DNS_ERROR_NEED_SECONDARY_ADDRESSES = 9614
const DNS_ERROR_NEED_WINS_SERVERS = 9616
const DNS_ERROR_NODE_CREATION_FAILED = 9703
const DNS_ERROR_NODE_IS_CNAME = 9708
const DNS_ERROR_NON_RFC_NAME = 9556
const DNS_ERROR_NOT_ALLOWED_ON_ROOT_SERVER = 9562
const DNS_ERROR_NOT_ALLOWED_UNDER_DELEGATION = 9563
const DNS_ERROR_NOT_UNIQUE = 9555
const DNS_ERROR_NO_BOOTFILE_IF_DS_ZONE = 9719
const DNS_ERROR_NO_CREATE_CACHE_DATA = 9713
const DNS_ERROR_NO_DNS_SERVERS = 9852
const DNS_ERROR_NO_MEMORY = 14
const DNS_ERROR_NO_PACKET = 9503
const DNS_ERROR_NO_TCPIP = 9851
const DNS_ERROR_NO_ZONE_INFO = 9602
const DNS_ERROR_NUMERIC_NAME = 9561
const DNS_ERROR_OPERATION_BASE = 9750
const DNS_ERROR_PACKET_FMT_BASE = 9500
const DNS_ERROR_PRIMARY_REQUIRES_DATAFILE = 9651
const DNS_ERROR_RCODE = 9504
const DNS_ERROR_RCODE_BADKEY = 9017
const DNS_ERROR_RCODE_BADSIG = 9016
const DNS_ERROR_RCODE_BADTIME = 9018
const DNS_ERROR_RCODE_FORMAT_ERROR = 9001
const DNS_ERROR_RCODE_LAST = 9018
const DNS_ERROR_RCODE_NAME_ERROR = 9003
const DNS_ERROR_RCODE_NOTAUTH = 9009
const DNS_ERROR_RCODE_NOTZONE = 9010
const DNS_ERROR_RCODE_NOT_IMPLEMENTED = 9004
const DNS_ERROR_RCODE_NO_ERROR = 0
const DNS_ERROR_RCODE_NXRRSET = 9008
const DNS_ERROR_RCODE_REFUSED = 9005
const DNS_ERROR_RCODE_SERVER_FAILURE = 9002
const DNS_ERROR_RCODE_YXDOMAIN = 9006
const DNS_ERROR_RCODE_YXRRSET = 9007
const DNS_ERROR_RECORD_ALREADY_EXISTS = 9711
const DNS_ERROR_RECORD_DOES_NOT_EXIST = 9701
const DNS_ERROR_RECORD_FORMAT = 9702
const DNS_ERROR_RECORD_ONLY_AT_ZONE_ROOT = 9710
const DNS_ERROR_RECORD_TIMED_OUT = 9705
const DNS_ERROR_RESPONSE_CODES_BASE = 9000
const DNS_ERROR_SECONDARY_DATA = 9712
const DNS_ERROR_SECONDARY_REQUIRES_MASTER_IP = 9612
const DNS_ERROR_SECURE_BASE = 9800
const DNS_ERROR_SETUP_BASE = 9850
const DNS_ERROR_SOA_DELETE_INVALID = 9618
const DNS_ERROR_TRY_AGAIN_LATER = 9554
const DNS_ERROR_UNKNOWN_RECORD_TYPE = 9704
const DNS_ERROR_UNSECURE_PACKET = 9505
const DNS_ERROR_WINS_INIT_FAILED = 9615
const DNS_ERROR_ZONE_ALREADY_EXISTS = 9609
const DNS_ERROR_ZONE_BASE = 9600
const DNS_ERROR_ZONE_CONFIGURATION_ERROR = 9604
const DNS_ERROR_ZONE_CREATION_FAILED = 9608
const DNS_ERROR_ZONE_DOES_NOT_EXIST = 9601
const DNS_ERROR_ZONE_HAS_NO_NS_RECORDS = 9606
const DNS_ERROR_ZONE_HAS_NO_SOA_RECORD = 9605
const DNS_ERROR_ZONE_IS_SHUTDOWN = 9621
const DNS_ERROR_ZONE_LOCKED = 9607
const DNS_ERROR_ZONE_NOT_SECONDARY = 9613
const DNS_ERROR_ZONE_REQUIRES_MASTER_IP = 9620
const DNS_FILTEROFF = 8
const DNS_FILTERON = 4
const DNS_INFO_ADDED_LOCAL_WINS = 9753
const DNS_INFO_AXFR_COMPLETE = 9751
const DNS_INFO_NO_RECORDS = 9501
const DNS_REGISTER = 1
const DNS_STATUS_CONTINUE_NEEDED = 9801
const DNS_STATUS_DOTTED_NAME = 9558
const DNS_STATUS_FQDN = 9557
const DNS_STATUS_PACKET_UNSECURE = 9505
const DNS_STATUS_SINGLE_PART_NAME = 9559
const DNS_UNREGISTER = 2
const DNS_WARNING_DOMAIN_UNDELETED = 9716
const DNS_WARNING_PTR_CREATE_FAILED = 9715
const DN_DEFAULTPRN = 1
const DOCKINFO_DOCKED = 2
const DOCKINFO_UNDOCKED = 1
const DOCKINFO_USER_DOCKED = 6
const DOCKINFO_USER_SUPPLIED = 4
const DOCKINFO_USER_UNDOCKED = 5
const DOF_DIRECTORY = 32771
const DOF_DOCUMENT = 32770
const DOF_EXECUTABLE = 32769
const DOF_MULTIPLE = 32772
const DOF_PROGMAN = 1
const DOF_SHELLDATA = 2
const DOMAIN = 1
const DOMAIN_ALIAS_RID_ACCESS_CONTROL_ASSISTANCE_OPS = 579
const DOMAIN_ALIAS_RID_ACCOUNT_OPS = 548
const DOMAIN_ALIAS_RID_ADMINS = 544
const DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS = 560
const DOMAIN_ALIAS_RID_BACKUP_OPS = 551
const DOMAIN_ALIAS_RID_CACHEABLE_PRINCIPALS_GROUP = 571
const DOMAIN_ALIAS_RID_CERTSVC_DCOM_ACCESS_GROUP = 574
const DOMAIN_ALIAS_RID_CRYPTO_OPERATORS = 569
const DOMAIN_ALIAS_RID_DCOM_USERS = 562
const DOMAIN_ALIAS_RID_EVENT_LOG_READERS_GROUP = 573
const DOMAIN_ALIAS_RID_GUESTS = 546
const DOMAIN_ALIAS_RID_HYPER_V_ADMINS = 578
const DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS = 557
const DOMAIN_ALIAS_RID_IUSERS = 568
const DOMAIN_ALIAS_RID_LOGGING_USERS = 559
const DOMAIN_ALIAS_RID_MONITORING_USERS = 558
const DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS = 556
const DOMAIN_ALIAS_RID_NON_CACHEABLE_PRINCIPALS_GROUP = 572
const DOMAIN_ALIAS_RID_POWER_USERS = 547
const DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 554
const DOMAIN_ALIAS_RID_PRINT_OPS = 550
const DOMAIN_ALIAS_RID_RAS_SERVERS = 553
const DOMAIN_ALIAS_RID_RDS_ENDPOINT_SERVERS = 576
const DOMAIN_ALIAS_RID_RDS_MANAGEMENT_SERVERS = 577
const DOMAIN_ALIAS_RID_RDS_REMOTE_ACCESS_SERVERS = 575
const DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS = 555
const DOMAIN_ALIAS_RID_REMOTE_MANAGEMENT_USERS = 580
const DOMAIN_ALIAS_RID_REPLICATOR = 552
const DOMAIN_ALIAS_RID_SYSTEM_OPS = 549
const DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS = 561
const DOMAIN_ALIAS_RID_USERS = 545
const DOMAIN_GROUP_RID_ADMINS = 512
const DOMAIN_GROUP_RID_AUTHORIZATION_DATA_CONTAINS_CLAIMS = 497
const DOMAIN_GROUP_RID_AUTHORIZATION_DATA_IS_COMPOUNDED = 496
const DOMAIN_GROUP_RID_CERT_ADMINS = 517
const DOMAIN_GROUP_RID_CLONEABLE_CONTROLLERS = 522
const DOMAIN_GROUP_RID_COMPUTERS = 515
const DOMAIN_GROUP_RID_CONTROLLERS = 516
const DOMAIN_GROUP_RID_ENTERPRISE_ADMINS = 519
const DOMAIN_GROUP_RID_ENTERPRISE_READONLY_DOMAIN_CONTROLLERS = 498
const DOMAIN_GROUP_RID_GUESTS = 514
const DOMAIN_GROUP_RID_POLICY_ADMINS = 520
const DOMAIN_GROUP_RID_READONLY_CONTROLLERS = 521
const DOMAIN_GROUP_RID_SCHEMA_ADMINS = 518
const DOMAIN_GROUP_RID_USERS = 513
const DOMAIN_USER_RID_ADMIN = 500
const DOMAIN_USER_RID_GUEST = 501
const DOMAIN_USER_RID_KRBTGT = 502
const DOMAIN_USER_RID_MAX = 999
const DONT_RESOLVE_DLL_REFERENCES = 1
const DOUBLE_CLICK = 2
const DOWNLOADFACE = 514
const DOWNLOADHEADER = 4111
const DO_DROPFILE = 1162627398
const DO_PRINTFILE = 1414419024
const DPAPI_IMP = "DECLSPEC_IMPORT"
const DPD_DELETE_ALL_FILES = 4
const DPD_DELETE_SPECIFIC_VERSION = 2
const DPD_DELETE_UNUSED_FILES = 1
const DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = -3
const DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = -4
const DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = -2
const DPI_AWARENESS_CONTEXT_UNAWARE = -1
const DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = -5
const DRAFTMODE = 7
const DRAFT_QUALITY = 1
const DRAGDROP_E_FIRST = 2147746048
const DRAGDROP_E_LAST = 2147746063
const DRAGDROP_S_FIRST = 262400
const DRAGDROP_S_LAST = 262415
const DRAWPATTERNRECT = 25
const DRIVERVERSION = 0
const DRIVER_KERNELMODE = 1
const DRIVER_USERMODE = 2
const DRIVE_CDROM = 5
const DRIVE_FIXED = 3
const DRIVE_NO_ROOT_DIR = 1
const DRIVE_RAMDISK = 6
const DRIVE_REMOTE = 4
const DRIVE_REMOVABLE = 2
const DRIVE_UNKNOWN = 0
const DROPEFFECT_COPY = 1
const DROPEFFECT_LINK = 4
const DROPEFFECT_MOVE = 2
const DROPEFFECT_NONE = 0
const DROPEFFECT_SCROLL = 2147483648
const DRVCNF_CANCEL = 0
const DRVCNF_OK = 1
const DRVCNF_RESTART = 2
const DRV_CANCEL = 0
const DRV_CLOSE = 4
const DRV_CONFIGURE = 7
const DRV_DISABLE = 5
const DRV_ENABLE = 2
const DRV_EXITSESSION = 11
const DRV_FREE = 6
const DRV_INSTALL = 9
const DRV_LOAD = 1
const DRV_MCI_FIRST = 2048
const DRV_MCI_LAST = 6143
const DRV_OK = 1
const DRV_OPEN = 3
const DRV_POWER = 15
const DRV_QUERYCONFIGURE = 8
const DRV_REMOVE = 10
const DRV_RESERVED = 2048
const DRV_RESTART = 2
const DRV_USER = 16384
const DSPRINT_PENDING = 2147483648
const DSPRINT_PUBLISH = 1
const DSPRINT_REPUBLISH = 8
const DSPRINT_UNPUBLISH = 4
const DSPRINT_UPDATE = 2
const DSS_DISABLED = 32
const DSS_HIDEPREFIX = 512
const DSS_MONO = 128
const DSS_NORMAL = 0
const DSS_PREFIXONLY = 1024
const DSS_RIGHT = 32768
const DSS_UNION = 16
const DST_BITMAP = 4
const DST_COMPLEX = 0
const DST_ICON = 3
const DST_PREFIXTEXT = 2
const DST_TEXT = 1
const DS_3DLOOK = 4
const DS_ABSALIGN = 1
const DS_CENTER = 2048
const DS_CENTERMOUSE = 4096
const DS_CONTEXTHELP = 8192
const DS_CONTROL = 1024
const DS_FIXEDSYS = 8
const DS_LOCALEDIT = 32
const DS_MODALFRAME = 128
const DS_NOFAILCREATE = 16
const DS_NOIDLEMSG = 256
const DS_SETFONT = 64
const DS_SETFOREGROUND = 512
const DS_SHELLFONT = 72
const DS_SYSMODAL = 2
const DS_S_SUCCESS = 0
const DTR_CONTROL_DISABLE = 0
const DTR_CONTROL_ENABLE = 1
const DTR_CONTROL_HANDSHAKE = 2
const DT_BOTTOM = 8
const DT_CALCRECT = 1024
const DT_CENTER = 1
const DT_CHARSTREAM = 4
const DT_DISPFILE = 6
const DT_EDITCONTROL = 8192
const DT_END_ELLIPSIS = 32768
const DT_EXPANDTABS = 64
const DT_EXTERNALLEADING = 512
const DT_HIDEPREFIX = 1048576
const DT_INTERNAL = 4096
const DT_LEFT = 0
const DT_METAFILE = 5
const DT_MODIFYSTRING = 65536
const DT_NOCLIP = 256
const DT_NOFULLWIDTHCHARBREAK = 524288
const DT_NOPREFIX = 2048
const DT_PATH_ELLIPSIS = 16384
const DT_PLOTTER = 0
const DT_PREFIXONLY = 2097152
const DT_RASCAMERA = 3
const DT_RASDISPLAY = 1
const DT_RASPRINTER = 2
const DT_RIGHT = 2
const DT_RTLREADING = 131072
const DT_SINGLELINE = 32
const DT_TABSTOP = 128
const DT_TOP = 0
const DT_VCENTER = 4
const DT_WORDBREAK = 16
const DT_WORD_ELLIPSIS = 262144
const DUPLICATE = 6
const DUPLICATE_CLOSE_SOURCE = 1
const DUPLICATE_DEREG = 7
const DUPLICATE_SAME_ACCESS = 2
const DWLP_DLGPROC = 0
const DWLP_MSGRESULT = 0
const DWLP_USER = 0
const DWL_DLGPROC = 4
const DWL_MSGRESULT = 0
const DWL_USER = 8
const DYNAMIC_EH_CONTINUATION_TARGET_ADD = 1
const DYNAMIC_EH_CONTINUATION_TARGET_PROCESSED = 2
const DYNAMIC_ENFORCED_ADDRESS_RANGE_ADD = 1
const DYNAMIC_ENFORCED_ADDRESS_RANGE_PROCESSED = 2
const DbgRaiseAssertionFailure = 0
const DceErrorInqText = 0
const DdeCreateStringHandle = 0
const DdeInitialize = 0
const DdeQueryString = 0
const DecryptFile = 0
const DefDlgProc = 0
const DefFrameProc = 0
const DefMDIChildProc = 0
const DefWindowProc = 0
const DefineDosDevice = 0
const DeleteFile = 0
const DeleteFileTransacted = 0
const DeleteForm = 0
const DeleteMonitor = 0
const DeletePort = 0
const DeletePrintProcessor = 0
const DeletePrintProvidor = 0
const DeletePrinterConnection = 0
const DeletePrinterData = 0
const DeletePrinterDataEx = 0
const DeletePrinterDriver = 0
const DeletePrinterDriverEx = 0
const DeletePrinterDriverPackage = 0
const DeletePrinterKey = 0
const DeleteVolumeMountPoint = 0
const DeviceCapabilities = 0
const DeviceDsmActionFlag_NonDestructive = 2147483648
const DeviceDsmAction_None = 0
const DeviceDsmAction_Notification = 2147483650
const DeviceDsmAction_Trim = 1
const DialogBox = 0
const DialogBoxIndirect = 0
const DialogBoxIndirectParam = 0
const DialogBoxParam = 0
const DiskClassGuid = 0
const DispatchMessage = 0
const DlgDirList = 0
const DlgDirListComboBox = 0
const DlgDirSelectComboBoxEx = 0
const DlgDirSelectEx = 0
const DnsHostnameToComputerName = 0
const DoEnvironmentSubst = 0
const DocumentEvent = 0
const DocumentProperties = 0
const DragQueryFile = 0
const DrawState = 0
const DrawText = 0
const DrawTextEx = 0
const E2BIG = 7
const EACCES = 13
const EADDRINUSE = 100
const EADDRNOTAVAIL = 101
const EAFNOSUPPORT = 102
const EAGAIN = 11
const EALREADY = 103
const EASTEUROPE_CHARSET = 238
const EBADF = 9
const EBADMSG = 104
const EBUSY = 16
const ECANCELED = 105
const ECHILD = 10
const ECONNABORTED = 106
const ECONNREFUSED = 107
const ECONNRESET = 108
const EC_DISABLE = 8
const EC_ENABLEALL = 0
const EC_ENABLEONE = 128
const EC_LEFTMARGIN = 1
const EC_QUERYWAITING = 2
const EC_RIGHTMARGIN = 2
const EC_USEFONTINFO = 65535
const EDD_GET_DEVICE_INTERFACE_NAME = 1
const EDEADLK = 36
const EDEADLOCK = 36
const EDESTADDRREQ = 109
const EDGE_BUMP = 9
const EDGE_ETCHED = 6
const EDGE_RAISED = 5
const EDGE_SUNKEN = 10
const EDOM = 33
const EDS_RAWMODE = 2
const EDS_ROTATEDMODE = 4
const EEInfoGCCOM = 11
const EEInfoGCFRS = 12
const EEInfoNextRecordsMissing = 2
const EEInfoPreviousRecordsMissing = 1
const EEInfoUseFileTime = 4
const EEXIST = 17
const EFAULT = 14
const EFBIG = 27
const EFSRPC_SECURE_ONLY = 8
const EFS_DROP_ALTERNATE_STREAMS = 16
const EFS_USE_RECOVERY_KEYS = 1
const EHOSTUNREACH = 110
const EIDRM = 111
const EILSEQ = 42
const EIMES_CANCELCOMPSTRINFOCUS = 2
const EIMES_COMPLETECOMPSTRKILLFOCUS = 4
const EIMES_GETCOMPSTRATONCE = 1
const EINPROGRESS = 112
const EINTR = 4
const EINVAL = 22
const EIO = 5
const EISCONN = 113
const EISDIR = 21
const ELEMENT_STATUS_ACCESS = 8
const ELEMENT_STATUS_AVOLTAG = 536870912
const ELEMENT_STATUS_EXCEPT = 4
const ELEMENT_STATUS_EXENAB = 16
const ELEMENT_STATUS_FULL = 1
const ELEMENT_STATUS_ID_VALID = 8192
const ELEMENT_STATUS_IMPEXP = 2
const ELEMENT_STATUS_INENAB = 32
const ELEMENT_STATUS_INVERT = 4194304
const ELEMENT_STATUS_LUN_VALID = 4096
const ELEMENT_STATUS_NOT_BUS = 32768
const ELEMENT_STATUS_PRODUCT_DATA = 64
const ELEMENT_STATUS_PVOLTAG = 268435456
const ELEMENT_STATUS_SVALID = 8388608
const ELF_CULTURE_LATIN = 0
const ELF_VENDOR_SIZE = 4
const ELF_VERSION = 0
const ELOOP = 114
const EMARCH_ENC_I17_IC_INST_WORD_POS_X = 12
const EMARCH_ENC_I17_IC_INST_WORD_X = 3
const EMARCH_ENC_I17_IC_SIZE_X = 1
const EMARCH_ENC_I17_IC_VAL_POS_X = 21
const EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X = 14
const EMARCH_ENC_I17_IMM41a_INST_WORD_X = 1
const EMARCH_ENC_I17_IMM41a_SIZE_X = 10
const EMARCH_ENC_I17_IMM41a_VAL_POS_X = 22
const EMARCH_ENC_I17_IMM41b_INST_WORD_POS_X = 24
const EMARCH_ENC_I17_IMM41b_INST_WORD_X = 1
const EMARCH_ENC_I17_IMM41b_SIZE_X = 8
const EMARCH_ENC_I17_IMM41b_VAL_POS_X = 32
const EMARCH_ENC_I17_IMM41c_INST_WORD_POS_X = 0
const EMARCH_ENC_I17_IMM41c_INST_WORD_X = 2
const EMARCH_ENC_I17_IMM41c_SIZE_X = 23
const EMARCH_ENC_I17_IMM41c_VAL_POS_X = 40
const EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X = 13
const EMARCH_ENC_I17_IMM5C_INST_WORD_X = 3
const EMARCH_ENC_I17_IMM5C_SIZE_X = 5
const EMARCH_ENC_I17_IMM5C_VAL_POS_X = 16
const EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X = 4
const EMARCH_ENC_I17_IMM7B_INST_WORD_X = 3
const EMARCH_ENC_I17_IMM7B_SIZE_X = 7
const EMARCH_ENC_I17_IMM7B_VAL_POS_X = 0
const EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X = 18
const EMARCH_ENC_I17_IMM9D_INST_WORD_X = 3
const EMARCH_ENC_I17_IMM9D_SIZE_X = 9
const EMARCH_ENC_I17_IMM9D_VAL_POS_X = 7
const EMARCH_ENC_I17_SIGN_INST_WORD_POS_X = 27
const EMARCH_ENC_I17_SIGN_INST_WORD_X = 3
const EMARCH_ENC_I17_SIGN_SIZE_X = 1
const EMARCH_ENC_I17_SIGN_VAL_POS_X = 63
const EMBDHLP_CREATENOW = 0
const EMBDHLP_DELAYCREATE = 65536
const EMBDHLP_INPROC_HANDLER = 0
const EMBDHLP_INPROC_SERVER = 1
const EMFILE = 24
const EMLINK = 31
const EMR_ABORTPATH = 68
const EMR_ALPHABLEND = 114
const EMR_ANGLEARC = 41
const EMR_ARC = 45
const EMR_ARCTO = 55
const EMR_BEGINPATH = 59
const EMR_BITBLT = 76
const EMR_CHORD = 46
const EMR_CLOSEFIGURE = 61
const EMR_COLORCORRECTPALETTE = 111
const EMR_COLORMATCHTOTARGETW = 121
const EMR_CREATEBRUSHINDIRECT = 39
const EMR_CREATECOLORSPACE = 99
const EMR_CREATECOLORSPACEW = 122
const EMR_CREATEDIBPATTERNBRUSHPT = 94
const EMR_CREATEMONOBRUSH = 93
const EMR_CREATEPALETTE = 49
const EMR_CREATEPEN = 38
const EMR_DELETECOLORSPACE = 101
const EMR_DELETEOBJECT = 40
const EMR_ELLIPSE = 42
const EMR_ENDPATH = 60
const EMR_EOF = 14
const EMR_EXCLUDECLIPRECT = 29
const EMR_EXTCREATEFONTINDIRECTW = 82
const EMR_EXTCREATEPEN = 95
const EMR_EXTFLOODFILL = 53
const EMR_EXTSELECTCLIPRGN = 75
const EMR_EXTTEXTOUTA = 83
const EMR_EXTTEXTOUTW = 84
const EMR_FILLPATH = 62
const EMR_FILLRGN = 71
const EMR_FLATTENPATH = 65
const EMR_FRAMERGN = 72
const EMR_GDICOMMENT = 70
const EMR_GLSBOUNDEDRECORD = 103
const EMR_GLSRECORD = 102
const EMR_GRADIENTFILL = 118
const EMR_HEADER = 1
const EMR_INTERSECTCLIPRECT = 30
const EMR_INVERTRGN = 73
const EMR_LINETO = 54
const EMR_MASKBLT = 78
const EMR_MAX = 122
const EMR_MIN = 1
const EMR_MODIFYWORLDTRANSFORM = 36
const EMR_MOVETOEX = 27
const EMR_OFFSETCLIPRGN = 26
const EMR_PAINTRGN = 74
const EMR_PIE = 47
const EMR_PIXELFORMAT = 104
const EMR_PLGBLT = 79
const EMR_POLYBEZIER = 2
const EMR_POLYBEZIER16 = 85
const EMR_POLYBEZIERTO = 5
const EMR_POLYBEZIERTO16 = 88
const EMR_POLYDRAW = 56
const EMR_POLYDRAW16 = 92
const EMR_POLYGON = 3
const EMR_POLYGON16 = 86
const EMR_POLYLINE = 4
const EMR_POLYLINE16 = 87
const EMR_POLYLINETO = 6
const EMR_POLYLINETO16 = 89
const EMR_POLYPOLYGON = 8
const EMR_POLYPOLYGON16 = 91
const EMR_POLYPOLYLINE = 7
const EMR_POLYPOLYLINE16 = 90
const EMR_POLYTEXTOUTA = 96
const EMR_POLYTEXTOUTW = 97
const EMR_REALIZEPALETTE = 52
const EMR_RECTANGLE = 43
const EMR_RESERVED_105 = 105
const EMR_RESERVED_106 = 106
const EMR_RESERVED_107 = 107
const EMR_RESERVED_108 = 108
const EMR_RESERVED_109 = 109
const EMR_RESERVED_110 = 110
const EMR_RESERVED_117 = 117
const EMR_RESERVED_119 = 119
const EMR_RESERVED_120 = 120
const EMR_RESIZEPALETTE = 51
const EMR_RESTOREDC = 34
const EMR_ROUNDRECT = 44
const EMR_SAVEDC = 33
const EMR_SCALEVIEWPORTEXTEX = 31
const EMR_SCALEWINDOWEXTEX = 32
const EMR_SELECTCLIPPATH = 67
const EMR_SELECTOBJECT = 37
const EMR_SELECTPALETTE = 48
const EMR_SETARCDIRECTION = 57
const EMR_SETBKCOLOR = 25
const EMR_SETBKMODE = 18
const EMR_SETBRUSHORGEX = 13
const EMR_SETCOLORADJUSTMENT = 23
const EMR_SETCOLORSPACE = 100
const EMR_SETDIBITSTODEVICE = 80
const EMR_SETICMMODE = 98
const EMR_SETICMPROFILEA = 112
const EMR_SETICMPROFILEW = 113
const EMR_SETLAYOUT = 115
const EMR_SETMAPMODE = 17
const EMR_SETMAPPERFLAGS = 16
const EMR_SETMETARGN = 28
const EMR_SETMITERLIMIT = 58
const EMR_SETPALETTEENTRIES = 50
const EMR_SETPIXELV = 15
const EMR_SETPOLYFILLMODE = 19
const EMR_SETROP2 = 20
const EMR_SETSTRETCHBLTMODE = 21
const EMR_SETTEXTALIGN = 22
const EMR_SETTEXTCOLOR = 24
const EMR_SETVIEWPORTEXTEX = 11
const EMR_SETVIEWPORTORGEX = 12
const EMR_SETWINDOWEXTEX = 9
const EMR_SETWINDOWORGEX = 10
const EMR_SETWORLDTRANSFORM = 35
const EMR_STRETCHBLT = 77
const EMR_STRETCHDIBITS = 81
const EMR_STROKEANDFILLPATH = 63
const EMR_STROKEPATH = 64
const EMR_TRANSPARENTBLT = 116
const EMR_WIDENPATH = 66
const EMSGSIZE = 115
const EMSIS_COMPOSITIONSTRING = 1
const EM_CANUNDO = 198
const EM_CHARFROMPOS = 215
const EM_EMPTYUNDOBUFFER = 205
const EM_ENABLEFEATURE = 218
const EM_FMTLINES = 200
const EM_GETFIRSTVISIBLELINE = 206
const EM_GETHANDLE = 189
const EM_GETIMESTATUS = 217
const EM_GETLIMITTEXT = 213
const EM_GETLINE = 196
const EM_GETLINECOUNT = 186
const EM_GETMARGINS = 212
const EM_GETMODIFY = 184
const EM_GETPASSWORDCHAR = 210
const EM_GETRECT = 178
const EM_GETSEL = 176
const EM_GETTHUMB = 190
const EM_GETWORDBREAKPROC = 209
const EM_LIMITTEXT = 197
const EM_LINEFROMCHAR = 201
const EM_LINEINDEX = 187
const EM_LINELENGTH = 193
const EM_LINESCROLL = 182
const EM_POSFROMCHAR = 214
const EM_REPLACESEL = 194
const EM_SCROLL = 181
const EM_SCROLLCARET = 183
const EM_SETHANDLE = 188
const EM_SETIMESTATUS = 216
const EM_SETLIMITTEXT = 197
const EM_SETMARGINS = 211
const EM_SETMODIFY = 185
const EM_SETPASSWORDCHAR = 204
const EM_SETREADONLY = 207
const EM_SETRECT = 179
const EM_SETRECTNP = 180
const EM_SETSEL = 177
const EM_SETTABSTOPS = 203
const EM_SETWORDBREAKPROC = 208
const EM_UNDO = 199
const ENABLEDUPLEX = 28
const ENABLEPAIRKERNING = 769
const ENABLERELATIVEWIDTHS = 768
const ENABLE_AUTO_POSITION = 256
const ENABLE_DISABLE_AUTOSAVE = 210
const ENABLE_DISABLE_AUTO_OFFLINE = 219
const ENABLE_ECHO_INPUT = 4
const ENABLE_EXTENDED_FLAGS = 128
const ENABLE_INSERT_MODE = 32
const ENABLE_LINE_INPUT = 2
const ENABLE_LVB_GRID_WORLDWIDE = 16
const ENABLE_MOUSE_INPUT = 16
const ENABLE_PROCESSED_INPUT = 1
const ENABLE_PROCESSED_OUTPUT = 1
const ENABLE_QUICK_EDIT_MODE = 64
const ENABLE_SMART = 216
const ENABLE_VIRTUAL_TERMINAL_INPUT = 512
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
const ENABLE_WINDOW_INPUT = 8
const ENABLE_WRAP_AT_EOL_OUTPUT = 2
const ENAMETOOLONG = 38
const ENAME_NAME = 0
const ENAME_ROWID = 3
const ENAME_SPAN = 1
const ENAME_TAB = 2
const ENCAPSULATED_POSTSCRIPT = 4116
const ENCRYPTED_DATA_INFO_SPARSE_FILE = 1
const ENCRYPTION_FORMAT_DEFAULT = 1
const ENDDOC = 11
const ENDSESSION_CLOSEAPP = 1
const ENDSESSION_CRITICAL = 1073741824
const ENDSESSION_LOGOFF = 2147483648
const END_PATH = 4098
const ENETDOWN = 116
const ENETRESET = 117
const ENETUNREACH = 118
const ENFILE = 23
const ENHANCED_KEY = 256
const ENHMETA_SIGNATURE = 1179469088
const ENHMETA_STOCK_OBJECT = 2147483648
const ENLISTMENT_ALL_ACCESS = 983071
const ENLISTMENT_GENERIC_EXECUTE = 131100
const ENLISTMENT_GENERIC_READ = 131073
const ENLISTMENT_GENERIC_WRITE = 131102
const ENLISTMENT_MAXIMUM_OPTION = 1
const ENLISTMENT_OBJECT_NAME_LENGTH_IN_BYTES = 0
const ENLISTMENT_OBJECT_PATH = "\\\\Enlistment\\\\"
const ENLISTMENT_QUERY_INFORMATION = 1
const ENLISTMENT_RECOVER = 4
const ENLISTMENT_SET_INFORMATION = 2
const ENLISTMENT_SUBORDINATE_RIGHTS = 8
const ENLISTMENT_SUPERIOR = 1
const ENLISTMENT_SUPERIOR_RIGHTS = 16
const ENOBUFS = 119
const ENODATA = 120
const ENODEV = 19
const ENOENT = 2
const ENOEXEC = 8
const ENOFILE = 2
const ENOLCK = 39
const ENOLINK = 121
const ENOMEM = 12
const ENOMSG = 122
const ENOPROTOOPT = 123
const ENOSPC = 28
const ENOSR = 124
const ENOSTR = 125
const ENOSYS = 40
const ENOTCONN = 126
const ENOTDIR = 20
const ENOTEMPTY = 41
const ENOTRECOVERABLE = 127
const ENOTSOCK = 128
const ENOTSUP = 129
const ENOTTY = 25
const ENUMPAPERBINS = 31
const ENUMPAPERMETRICS = 34
const ENUMRESLANGPROC = 0
const ENUMRESNAMEPROC = 0
const ENUMRESTYPEPROC = 0
const ENUM_ALL_CALENDARS = 4294967295
const ENUM_CURRENT_SETTINGS = -1
const ENUM_E_FIRST = 2147746224
const ENUM_E_LAST = 2147746239
const ENUM_REGISTRY_SETTINGS = -2
const ENUM_S_FIRST = 262576
const ENUM_S_LAST = 262591
const ENXIO = 6
const EN_AFTER_PASTE = 2049
const EN_ALIGN_LTR_EC = 1792
const EN_ALIGN_RTL_EC = 1793
const EN_BEFORE_PASTE = 2048
const EN_CHANGE = 768
const EN_ERRSPACE = 1280
const EN_HSCROLL = 1537
const EN_KILLFOCUS = 512
const EN_MAXTEXT = 1281
const EN_SETFOCUS = 256
const EN_UPDATE = 1024
const EN_VSCROLL = 1538
const EOF = -1
const EOPNOTSUPP = 130
const EOVERFLOW = 132
const EOWNERDEAD = 133
const EPERM = 1
const EPIPE = 32
const EPROTO = 134
const EPROTONOSUPPORT = 135
const EPROTOTYPE = 136
const EPSPRINTING = 33
const EPS_SIGNATURE = 1179865157
const EPT_S_CANT_CREATE = 1899
const EPT_S_CANT_PERFORM_OP = 1752
const EPT_S_INVALID_ENTRY = 1751
const EPT_S_NOT_REGISTERED = 1753
const EP_Agg = 16
const EP_CanBeNull = 2097152
const EP_Collate = 512
const EP_Commuted = 1024
const EP_ConstFunc = 1048576
const EP_DblQuoted = 128
const EP_Distinct = 4
const EP_FixedCol = 32
const EP_FromDDL = 1073741824
const EP_FullSize = 131072
const EP_HasFunc = 8
const EP_IfNullRow = 262144
const EP_Immutable = 2
const EP_InfixFunc = 256
const EP_InnerON = 2
const EP_IntValue = 2048
const EP_IsFalse = 536870912
const EP_IsTrue = 268435456
const EP_Leaf = 8388608
const EP_NoReduce = 1
const EP_OuterON = 1
const EP_Propagate = 4194824
const EP_Quoted = 67108864
const EP_Reduced = 16384
const EP_Skip = 8192
const EP_Static = 134217728
const EP_Subquery = 4194304
const EP_Subrtn = 33554432
const EP_TokenOnly = 65536
const EP_Unlikely = 524288
const EP_VarSelect = 64
const EP_Win = 32768
const EP_WinFunc = 16777216
const EP_xIsSelect = 4096
const ERANGE = 34
const EROFS = 30
const ERROR = 0
const ERROR_ABANDONED_WAIT_0 = 735
const ERROR_ABANDONED_WAIT_63 = 736
const ERROR_ACCESS_DENIED = 5
const ERROR_ACCESS_DISABLED_BY_POLICY = 1260
const ERROR_ACCESS_DISABLED_WEBBLADE = 1277
const ERROR_ACCESS_DISABLED_WEBBLADE_TAMPER = 1278
const ERROR_ACCOUNT_DISABLED = 1331
const ERROR_ACCOUNT_EXPIRED = 1793
const ERROR_ACCOUNT_LOCKED_OUT = 1909
const ERROR_ACCOUNT_RESTRICTION = 1327
const ERROR_ACTIVATION_COUNT_EXCEEDED = 7059
const ERROR_ACTIVE_CONNECTIONS = 2402
const ERROR_ADAP_HDW_ERR = 57
const ERROR_ADDRESS_ALREADY_ASSOCIATED = 1227
const ERROR_ADDRESS_NOT_ASSOCIATED = 1228
const ERROR_ADVANCED_INSTALLER_FAILED = 14099
const ERROR_ALERTED = 739
const ERROR_ALIAS_EXISTS = 1379
const ERROR_ALLOTTED_SPACE_EXCEEDED = 1344
const ERROR_ALL_NODES_NOT_AVAILABLE = 5037
const ERROR_ALL_USER_TRUST_QUOTA_EXCEEDED = 1933
const ERROR_ALREADY_ASSIGNED = 85
const ERROR_ALREADY_EXISTS = 183
const ERROR_ALREADY_FIBER = 1280
const ERROR_ALREADY_INITIALIZED = 1247
const ERROR_ALREADY_REGISTERED = 1242
const ERROR_ALREADY_RUNNING_LKG = 1074
const ERROR_ALREADY_THREAD = 1281
const ERROR_ALREADY_WAITING = 1904
const ERROR_AMBIGUOUS_SYSTEM_DEVICE = 15250
const ERROR_API_UNAVAILABLE = 15841
const ERROR_APPHELP_BLOCK = 1259
const ERROR_APPX_INTEGRITY_FAILURE_CLR_NGEN = 15624
const ERROR_APP_WRONG_OS = 1151
const ERROR_ARENA_TRASHED = 7
const ERROR_ARITHMETIC_OVERFLOW = 534
const ERROR_ATOMIC_LOCKS_NOT_SUPPORTED = 174
const ERROR_AUTHENTICATION_FIREWALL_FAILED = 1935
const ERROR_AUTHIP_FAILURE = 1469
const ERROR_AUTODATASEG_EXCEEDS_64k = 199
const ERROR_BADDB = 1009
const ERROR_BADKEY = 1010
const ERROR_BAD_ARGUMENTS = 160
const ERROR_BAD_COMMAND = 22
const ERROR_BAD_CONFIGURATION = 1610
const ERROR_BAD_DESCRIPTOR_FORMAT = 1361
const ERROR_BAD_DEVICE = 1200
const ERROR_BAD_DEV_TYPE = 66
const ERROR_BAD_DRIVER = 2001
const ERROR_BAD_DRIVER_LEVEL = 119
const ERROR_BAD_ENVIRONMENT = 10
const ERROR_BAD_EXE_FORMAT = 193
const ERROR_BAD_FILE_TYPE = 222
const ERROR_BAD_FORMAT = 11
const ERROR_BAD_IMPERSONATION_LEVEL = 1346
const ERROR_BAD_INHERITANCE_ACL = 1340
const ERROR_BAD_LENGTH = 24
const ERROR_BAD_LOGON_SESSION_STATE = 1365
const ERROR_BAD_NETPATH = 53
const ERROR_BAD_NET_NAME = 67
const ERROR_BAD_NET_RESP = 58
const ERROR_BAD_PATHNAME = 161
const ERROR_BAD_PIPE = 230
const ERROR_BAD_PROFILE = 1206
const ERROR_BAD_PROVIDER = 1204
const ERROR_BAD_QUERY_SYNTAX = 1615
const ERROR_BAD_RECOVERY_POLICY = 6012
const ERROR_BAD_REM_ADAP = 60
const ERROR_BAD_THREADID_ADDR = 159
const ERROR_BAD_TOKEN_TYPE = 1349
const ERROR_BAD_UNIT = 20
const ERROR_BAD_USERNAME = 2202
const ERROR_BAD_USER_PROFILE = 1253
const ERROR_BAD_VALIDATION_CLASS = 1348
const ERROR_BEGINNING_OF_MEDIA = 1102
const ERROR_BIDI_DEVICE_OFFLINE = 13004
const ERROR_BIDI_ERROR_BASE = 13000
const ERROR_BIDI_NOT_SUPPORTED = 50
const ERROR_BIDI_SCHEMA_NOT_SUPPORTED = 13005
const ERROR_BIDI_SCHEMA_READ_ONLY = 13002
const ERROR_BIDI_SERVER_OFFLINE = 13003
const ERROR_BIDI_STATUS_OK = 0
const ERROR_BIDI_STATUS_WARNING = 13001
const ERROR_BOOT_ALREADY_ACCEPTED = 1076
const ERROR_BROKEN_PIPE = 109
const ERROR_BUFFER_OVERFLOW = 111
const ERROR_BUSY = 170
const ERROR_BUSY_DRIVE = 142
const ERROR_BUS_RESET = 1111
const ERROR_CALLBACK_SUPPLIED_INVALID_DATA = 1273
const ERROR_CALL_NOT_IMPLEMENTED = 120
const ERROR_CANCELLED = 1223
const ERROR_CANCEL_VIOLATION = 173
const ERROR_CANNOT_COPY = 266
const ERROR_CANNOT_DETECT_DRIVER_FAILURE = 1080
const ERROR_CANNOT_DETECT_PROCESS_ABORT = 1081
const ERROR_CANNOT_FIND_WND_CLASS = 1407
const ERROR_CANNOT_IMPERSONATE = 1368
const ERROR_CANNOT_MAKE = 82
const ERROR_CANNOT_OPEN_PROFILE = 1205
const ERROR_CANNOT_SWITCH_RUNLEVEL = 15400
const ERROR_CANTOPEN = 1011
const ERROR_CANTREAD = 1012
const ERROR_CANTWRITE = 1013
const ERROR_CANT_ACCESS_DOMAIN_INFO = 1351
const ERROR_CANT_ACCESS_FILE = 1920
const ERROR_CANT_DELETE_LAST_ITEM = 4335
const ERROR_CANT_DISABLE_MANDATORY = 1310
const ERROR_CANT_EVICT_ACTIVE_NODE = 5009
const ERROR_CANT_OPEN_ANONYMOUS = 1347
const ERROR_CANT_RESOLVE_FILENAME = 1921
const ERROR_CAN_NOT_COMPLETE = 1003
const ERROR_CAN_NOT_DEL_LOCAL_WINS = 4001
const ERROR_CASE_DIFFERING_NAMES_IN_DIR = 424
const ERROR_CHECKOUT_REQUIRED = 221
const ERROR_CHILD_MUST_BE_VOLATILE = 1021
const ERROR_CHILD_NOT_COMPLETE = 129
const ERROR_CHILD_WINDOW_MENU = 1436
const ERROR_CIRCULAR_DEPENDENCY = 1059
const ERROR_CLASS_ALREADY_EXISTS = 1410
const ERROR_CLASS_DOES_NOT_EXIST = 1411
const ERROR_CLASS_HAS_WINDOWS = 1412
const ERROR_CLEANER_CARTRIDGE_INSTALLED = 4340
const ERROR_CLEANER_CARTRIDGE_SPENT = 4333
const ERROR_CLEANER_SLOT_NOT_SET = 4332
const ERROR_CLEANER_SLOT_SET = 4331
const ERROR_CLIPBOARD_NOT_OPEN = 1418
const ERROR_CLIPPING_NOT_SUPPORTED = 2005
const ERROR_CLUSCFG_ALREADY_COMMITTED = 5901
const ERROR_CLUSCFG_ROLLBACK_FAILED = 5902
const ERROR_CLUSCFG_SYSTEM_DISK_DRIVE_LETTER_CONFLICT = 5903
const ERROR_CLUSTERLOG_CHKPOINT_NOT_FOUND = 5032
const ERROR_CLUSTERLOG_CORRUPT = 5029
const ERROR_CLUSTERLOG_EXCEEDS_MAXSIZE = 5031
const ERROR_CLUSTERLOG_NOT_ENOUGH_SPACE = 5033
const ERROR_CLUSTERLOG_RECORD_EXCEEDS_MAXSIZE = 5030
const ERROR_CLUSTER_CANT_CREATE_DUP_CLUSTER_NAME = 5900
const ERROR_CLUSTER_DATABASE_SEQMISMATCH = 5083
const ERROR_CLUSTER_EVICT_WITHOUT_CLEANUP = 5896
const ERROR_CLUSTER_GUM_NOT_LOCKER = 5085
const ERROR_CLUSTER_INCOMPATIBLE_VERSIONS = 5075
const ERROR_CLUSTER_INSTANCE_ID_MISMATCH = 5893
const ERROR_CLUSTER_INVALID_NETWORK = 5054
const ERROR_CLUSTER_INVALID_NETWORK_PROVIDER = 5049
const ERROR_CLUSTER_INVALID_NODE = 5039
const ERROR_CLUSTER_INVALID_REQUEST = 5048
const ERROR_CLUSTER_IPADDR_IN_USE = 5057
const ERROR_CLUSTER_JOIN_ABORTED = 5074
const ERROR_CLUSTER_JOIN_IN_PROGRESS = 5041
const ERROR_CLUSTER_JOIN_NOT_IN_PROGRESS = 5053
const ERROR_CLUSTER_LAST_INTERNAL_NETWORK = 5066
const ERROR_CLUSTER_LOCAL_NODE_NOT_FOUND = 5043
const ERROR_CLUSTER_MAXNUM_OF_RESOURCES_EXCEEDED = 5076
const ERROR_CLUSTER_MEMBERSHIP_HALT = 5892
const ERROR_CLUSTER_MEMBERSHIP_INVALID_STATE = 5890
const ERROR_CLUSTER_MISMATCHED_COMPUTER_ACCT_NAME = 5905
const ERROR_CLUSTER_NETINTERFACE_EXISTS = 5046
const ERROR_CLUSTER_NETINTERFACE_NOT_FOUND = 5047
const ERROR_CLUSTER_NETWORK_ALREADY_OFFLINE = 5064
const ERROR_CLUSTER_NETWORK_ALREADY_ONLINE = 5063
const ERROR_CLUSTER_NETWORK_EXISTS = 5044
const ERROR_CLUSTER_NETWORK_HAS_DEPENDENTS = 5067
const ERROR_CLUSTER_NETWORK_NOT_FOUND = 5045
const ERROR_CLUSTER_NETWORK_NOT_FOUND_FOR_IP = 5894
const ERROR_CLUSTER_NETWORK_NOT_INTERNAL = 5060
const ERROR_CLUSTER_NODE_ALREADY_DOWN = 5062
const ERROR_CLUSTER_NODE_ALREADY_HAS_DFS_ROOT = 5088
const ERROR_CLUSTER_NODE_ALREADY_MEMBER = 5065
const ERROR_CLUSTER_NODE_ALREADY_UP = 5061
const ERROR_CLUSTER_NODE_DOWN = 5050
const ERROR_CLUSTER_NODE_EXISTS = 5040
const ERROR_CLUSTER_NODE_NOT_FOUND = 5042
const ERROR_CLUSTER_NODE_NOT_MEMBER = 5052
const ERROR_CLUSTER_NODE_NOT_PAUSED = 5058
const ERROR_CLUSTER_NODE_NOT_READY = 5072
const ERROR_CLUSTER_NODE_PAUSED = 5070
const ERROR_CLUSTER_NODE_SHUTTING_DOWN = 5073
const ERROR_CLUSTER_NODE_UNREACHABLE = 5051
const ERROR_CLUSTER_NODE_UP = 5056
const ERROR_CLUSTER_NO_RPC_PACKAGES_REGISTERED = 5081
const ERROR_CLUSTER_NO_SECURITY_CONTEXT = 5059
const ERROR_CLUSTER_OLD_VERSION = 5904
const ERROR_CLUSTER_OWNER_NOT_IN_PREFLIST = 5082
const ERROR_CLUSTER_PARAMETER_MISMATCH = 5897
const ERROR_CLUSTER_PROPERTY_DATA_TYPE_MISMATCH = 5895
const ERROR_CLUSTER_QUORUMLOG_NOT_FOUND = 5891
const ERROR_CLUSTER_RESNAME_NOT_FOUND = 5080
const ERROR_CLUSTER_RESOURCE_TYPE_NOT_FOUND = 5078
const ERROR_CLUSTER_RESTYPE_NOT_SUPPORTED = 5079
const ERROR_CLUSTER_SHUTTING_DOWN = 5022
const ERROR_CLUSTER_SYSTEM_CONFIG_CHANGED = 5077
const ERROR_CLUSTER_WRONG_OS_VERSION = 5899
const ERROR_COLORSPACE_MISMATCH = 2021
const ERROR_COMMITMENT_LIMIT = 1455
const ERROR_COMMITMENT_MINIMUM = 635
const ERROR_COMPRESSION_NOT_BENEFICIAL = 344
const ERROR_COM_TASK_STOP_PENDING = 15501
const ERROR_CONNECTED_OTHER_PASSWORD = 2108
const ERROR_CONNECTED_OTHER_PASSWORD_DEFAULT = 2109
const ERROR_CONNECTION_ABORTED = 1236
const ERROR_CONNECTION_ACTIVE = 1230
const ERROR_CONNECTION_COUNT_LIMIT = 1238
const ERROR_CONNECTION_INVALID = 1229
const ERROR_CONNECTION_REFUSED = 1225
const ERROR_CONNECTION_UNAVAIL = 1201
const ERROR_CONTEXT_EXPIRED = 1931
const ERROR_CONTINUE = 1246
const ERROR_CONTROLLING_IEPORT = 4329
const ERROR_CONTROL_ID_NOT_FOUND = 1421
const ERROR_CORE_RESOURCE = 5026
const ERROR_COUNTER_TIMEOUT = 1121
const ERROR_CRC = 23
const ERROR_CREATE_FAILED = 1631
const ERROR_CSCSHARE_OFFLINE = 1262
const ERROR_CTX_BAD_VIDEO_MODE = 7025
const ERROR_CTX_CANNOT_MAKE_EVENTLOG_ENTRY = 7005
const ERROR_CTX_CLIENT_LICENSE_IN_USE = 7052
const ERROR_CTX_CLIENT_LICENSE_NOT_SET = 7053
const ERROR_CTX_CLIENT_QUERY_TIMEOUT = 7040
const ERROR_CTX_CLOSE_PENDING = 7007
const ERROR_CTX_CONSOLE_CONNECT = 7042
const ERROR_CTX_CONSOLE_DISCONNECT = 7041
const ERROR_CTX_GRAPHICS_INVALID = 7035
const ERROR_CTX_INVALID_MODEMNAME = 7010
const ERROR_CTX_INVALID_PD = 7002
const ERROR_CTX_INVALID_WD = 7049
const ERROR_CTX_LICENSE_CLIENT_INVALID = 7055
const ERROR_CTX_LICENSE_EXPIRED = 7056
const ERROR_CTX_LICENSE_NOT_AVAILABLE = 7054
const ERROR_CTX_LOGON_DISABLED = 7037
const ERROR_CTX_MODEM_INF_NOT_FOUND = 7009
const ERROR_CTX_MODEM_RESPONSE_BUSY = 7015
const ERROR_CTX_MODEM_RESPONSE_ERROR = 7011
const ERROR_CTX_MODEM_RESPONSE_NO_CARRIER = 7013
const ERROR_CTX_MODEM_RESPONSE_NO_DIALTONE = 7014
const ERROR_CTX_MODEM_RESPONSE_TIMEOUT = 7012
const ERROR_CTX_MODEM_RESPONSE_VOICE = 7016
const ERROR_CTX_NOT_CONSOLE = 7038
const ERROR_CTX_NO_OUTBUF = 7008
const ERROR_CTX_PD_NOT_FOUND = 7003
const ERROR_CTX_SERVICE_NAME_COLLISION = 7006
const ERROR_CTX_SHADOW_DENIED = 7044
const ERROR_CTX_SHADOW_DISABLED = 7051
const ERROR_CTX_SHADOW_ENDED_BY_MODE_CHANGE = 7058
const ERROR_CTX_SHADOW_INVALID = 7050
const ERROR_CTX_SHADOW_NOT_RUNNING = 7057
const ERROR_CTX_TD_ERROR = 7017
const ERROR_CTX_WD_NOT_FOUND = 7004
const ERROR_CTX_WINSTATION_ACCESS_DENIED = 7045
const ERROR_CTX_WINSTATION_ALREADY_EXISTS = 7023
const ERROR_CTX_WINSTATION_BUSY = 7024
const ERROR_CTX_WINSTATION_NAME_INVALID = 7001
const ERROR_CTX_WINSTATION_NOT_FOUND = 7022
const ERROR_CURRENT_DIRECTORY = 16
const ERROR_CURRENT_DOMAIN_NOT_ALLOWED = 1399
const ERROR_DATABASE_BACKUP_CORRUPT = 5087
const ERROR_DATABASE_DOES_NOT_EXIST = 1065
const ERROR_DATABASE_FAILURE = 4313
const ERROR_DATABASE_FULL = 4314
const ERROR_DATATYPE_MISMATCH = 1629
const ERROR_DC_NOT_FOUND = 1425
const ERROR_DDE_FAIL = 1156
const ERROR_DEBUGGER_INACTIVE = 1284
const ERROR_DECRYPTION_FAILED = 6001
const ERROR_DELAY_LOAD_FAILED = 1285
const ERROR_DELETE_PENDING = 303
const ERROR_DELETING_EXISTING_APPLICATIONDATA_STORE_FAILED = 15621
const ERROR_DELETING_ICM_XFORM = 2019
const ERROR_DEPENDENCY_ALREADY_EXISTS = 5003
const ERROR_DEPENDENCY_NOT_ALLOWED = 5069
const ERROR_DEPENDENCY_NOT_FOUND = 5002
const ERROR_DEPENDENT_RESOURCE_EXISTS = 5001
const ERROR_DEPENDENT_SERVICES_RUNNING = 1051
const ERROR_DEPLOYMENT_BLOCKED_BY_POLICY = 15617
const ERROR_DESTINATION_ELEMENT_FULL = 1161
const ERROR_DESTROY_OBJECT_OF_OTHER_THREAD = 1435
const ERROR_DEVICE_ALREADY_REMEMBERED = 1202
const ERROR_DEVICE_DOOR_OPEN = 1166
const ERROR_DEVICE_IN_USE = 2404
const ERROR_DEVICE_NOT_AVAILABLE = 4319
const ERROR_DEVICE_NOT_CONNECTED = 1167
const ERROR_DEVICE_NOT_PARTITIONED = 1107
const ERROR_DEVICE_REINITIALIZATION_NEEDED = 1164
const ERROR_DEVICE_REMOVED = 1617
const ERROR_DEVICE_REQUIRES_CLEANING = 1165
const ERROR_DEV_NOT_EXIST = 55
const ERROR_DHCP_ADDRESS_CONFLICT = 4100
const ERROR_DIFFERENT_SERVICE_ACCOUNT = 1079
const ERROR_DIRECTORY = 267
const ERROR_DIRECT_ACCESS_HANDLE = 130
const ERROR_DIR_EFS_DISALLOWED = 6010
const ERROR_DIR_NOT_EMPTY = 145
const ERROR_DIR_NOT_ROOT = 144
const ERROR_DISCARDED = 157
const ERROR_DISK_CHANGE = 107
const ERROR_DISK_CORRUPT = 1393
const ERROR_DISK_FULL = 112
const ERROR_DISK_OPERATION_FAILED = 1127
const ERROR_DISK_RECALIBRATE_FAILED = 1126
const ERROR_DISK_RESET_FAILED = 1128
const ERROR_DISK_TOO_FRAGMENTED = 302
const ERROR_DLL_INIT_FAILED = 1114
const ERROR_DLL_NOT_FOUND = 1157
const ERROR_DOMAIN_CONTROLLER_EXISTS = 1250
const ERROR_DOMAIN_CONTROLLER_NOT_FOUND = 1908
const ERROR_DOMAIN_EXISTS = 1356
const ERROR_DOMAIN_LIMIT_EXCEEDED = 1357
const ERROR_DOMAIN_TRUST_INCONSISTENT = 1810
const ERROR_DOWNGRADE_DETECTED = 1265
const ERROR_DRIVER_BLOCKED = 1275
const ERROR_DRIVE_LOCKED = 108
const ERROR_DRIVE_MEDIA_MISMATCH = 4303
const ERROR_DRIVE_NOT_INSTALLED = 8
const ERROR_DS_ADD_REPLICA_INHIBITED = 8302
const ERROR_DS_ADMIN_LIMIT_EXCEEDED = 8228
const ERROR_DS_AFFECTS_MULTIPLE_DSAS = 8249
const ERROR_DS_AG_CANT_HAVE_UNIVERSAL_MEMBER = 8578
const ERROR_DS_ALIASED_OBJ_MISSING = 8334
const ERROR_DS_ALIAS_DEREF_PROBLEM = 8244
const ERROR_DS_ALIAS_POINTS_TO_ALIAS = 8336
const ERROR_DS_ALIAS_PROBLEM = 8241
const ERROR_DS_ATTRIBUTE_OR_VALUE_EXISTS = 8205
const ERROR_DS_ATTRIBUTE_OWNED_BY_SAM = 8346
const ERROR_DS_ATTRIBUTE_TYPE_UNDEFINED = 8204
const ERROR_DS_ATT_ALREADY_EXISTS = 8318
const ERROR_DS_ATT_IS_NOT_ON_OBJ = 8310
const ERROR_DS_ATT_NOT_DEF_FOR_CLASS = 8317
const ERROR_DS_ATT_NOT_DEF_IN_SCHEMA = 8303
const ERROR_DS_ATT_SCHEMA_REQ_ID = 8399
const ERROR_DS_ATT_SCHEMA_REQ_SYNTAX = 8416
const ERROR_DS_ATT_VAL_ALREADY_EXISTS = 8323
const ERROR_DS_AUTHORIZATION_FAILED = 8599
const ERROR_DS_AUTH_METHOD_NOT_SUPPORTED = 8231
const ERROR_DS_AUTH_UNKNOWN = 8234
const ERROR_DS_AUX_CLS_TEST_FAIL = 8389
const ERROR_DS_BACKLINK_WITHOUT_LINK = 8482
const ERROR_DS_BAD_ATT_SCHEMA_SYNTAX = 8400
const ERROR_DS_BAD_HIERARCHY_FILE = 8425
const ERROR_DS_BAD_INSTANCE_TYPE = 8313
const ERROR_DS_BAD_NAME_SYNTAX = 8335
const ERROR_DS_BAD_RDN_ATT_ID_SYNTAX = 8392
const ERROR_DS_BUILD_HIERARCHY_TABLE_FAILED = 8426
const ERROR_DS_BUSY = 8206
const ERROR_DS_CANT_ACCESS_REMOTE_PART_OF_AD = 8585
const ERROR_DS_CANT_ADD_ATT_VALUES = 8320
const ERROR_DS_CANT_ADD_SYSTEM_ONLY = 8358
const ERROR_DS_CANT_ADD_TO_GC = 8550
const ERROR_DS_CANT_CACHE_ATT = 8401
const ERROR_DS_CANT_CACHE_CLASS = 8402
const ERROR_DS_CANT_CREATE_IN_NONDOMAIN_NC = 8553
const ERROR_DS_CANT_CREATE_UNDER_SCHEMA = 8510
const ERROR_DS_CANT_DELETE = 8398
const ERROR_DS_CANT_DELETE_DSA_OBJ = 8340
const ERROR_DS_CANT_DEL_MASTER_CROSSREF = 8375
const ERROR_DS_CANT_DEMOTE_WITH_WRITEABLE_NC = 8604
const ERROR_DS_CANT_DEREF_ALIAS = 8337
const ERROR_DS_CANT_DERIVE_SPN_FOR_DELETED_DOMAIN = 8603
const ERROR_DS_CANT_DERIVE_SPN_WITHOUT_SERVER_REF = 8589
const ERROR_DS_CANT_FIND_DC_FOR_SRC_DOMAIN = 8537
const ERROR_DS_CANT_FIND_DSA_OBJ = 8419
const ERROR_DS_CANT_FIND_EXPECTED_NC = 8420
const ERROR_DS_CANT_FIND_NC_IN_CACHE = 8421
const ERROR_DS_CANT_MIX_MASTER_AND_REPS = 8331
const ERROR_DS_CANT_MOD_OBJ_CLASS = 8215
const ERROR_DS_CANT_MOD_PRIMARYGROUPID = 8506
const ERROR_DS_CANT_MOD_SYSTEM_ONLY = 8369
const ERROR_DS_CANT_MOVE_ACCOUNT_GROUP = 8498
const ERROR_DS_CANT_MOVE_APP_BASIC_GROUP = 8608
const ERROR_DS_CANT_MOVE_APP_QUERY_GROUP = 8609
const ERROR_DS_CANT_MOVE_DELETED_OBJECT = 8489
const ERROR_DS_CANT_MOVE_RESOURCE_GROUP = 8499
const ERROR_DS_CANT_ON_NON_LEAF = 8213
const ERROR_DS_CANT_ON_RDN = 8214
const ERROR_DS_CANT_REMOVE_ATT_CACHE = 8403
const ERROR_DS_CANT_REMOVE_CLASS_CACHE = 8404
const ERROR_DS_CANT_REM_MISSING_ATT = 8324
const ERROR_DS_CANT_REM_MISSING_ATT_VAL = 8325
const ERROR_DS_CANT_REPLACE_HIDDEN_REC = 8424
const ERROR_DS_CANT_RETRIEVE_ATTS = 8481
const ERROR_DS_CANT_RETRIEVE_CHILD = 8422
const ERROR_DS_CANT_RETRIEVE_DN = 8405
const ERROR_DS_CANT_RETRIEVE_INSTANCE = 8407
const ERROR_DS_CANT_RETRIEVE_SD = 8526
const ERROR_DS_CANT_START = 8531
const ERROR_DS_CANT_TREE_DELETE_CRITICAL_OBJ = 8560
const ERROR_DS_CANT_WITH_ACCT_GROUP_MEMBERSHPS = 8493
const ERROR_DS_CHILDREN_EXIST = 8332
const ERROR_DS_CLASS_MUST_BE_CONCRETE = 8359
const ERROR_DS_CLASS_NOT_DSA = 8343
const ERROR_DS_CLIENT_LOOP = 8259
const ERROR_DS_CODE_INCONSISTENCY = 8408
const ERROR_DS_COMPARE_FALSE = 8229
const ERROR_DS_COMPARE_TRUE = 8230
const ERROR_DS_CONFIDENTIALITY_REQUIRED = 8237
const ERROR_DS_CONFIG_PARAM_MISSING = 8427
const ERROR_DS_CONSTRAINT_VIOLATION = 8239
const ERROR_DS_CONSTRUCTED_ATT_MOD = 8475
const ERROR_DS_CONTROL_NOT_FOUND = 8258
const ERROR_DS_COULDNT_CONTACT_FSMO = 8367
const ERROR_DS_COULDNT_IDENTIFY_OBJECTS_FOR_TREE_DELETE = 8503
const ERROR_DS_COULDNT_LOCK_TREE_FOR_DELETE = 8502
const ERROR_DS_COULDNT_UPDATE_SPNS = 8525
const ERROR_DS_COUNTING_AB_INDICES_FAILED = 8428
const ERROR_DS_CROSS_DOMAIN_CLEANUP_REQD = 8491
const ERROR_DS_CROSS_DOM_MOVE_ERROR = 8216
const ERROR_DS_CROSS_NC_DN_RENAME = 8368
const ERROR_DS_CROSS_REF_BUSY = 8602
const ERROR_DS_CROSS_REF_EXISTS = 8374
const ERROR_DS_CR_IMPOSSIBLE_TO_VALIDATE = 8495
const ERROR_DS_CR_IMPOSSIBLE_TO_VALIDATE_V2 = 8586
const ERROR_DS_DATABASE_ERROR = 8409
const ERROR_DS_DECODING_ERROR = 8253
const ERROR_DS_DESTINATION_AUDITING_NOT_ENABLED = 8536
const ERROR_DS_DESTINATION_DOMAIN_NOT_IN_FOREST = 8535
const ERROR_DS_DIFFERENT_REPL_EPOCHS = 8593
const ERROR_DS_DISALLOWED_IN_SYSTEM_CONTAINER = 8615
const ERROR_DS_DNS_LOOKUP_FAILURE = 8524
const ERROR_DS_DOMAIN_RENAME_IN_PROGRESS = 8612
const ERROR_DS_DOMAIN_VERSION_TOO_HIGH = 8564
const ERROR_DS_DOMAIN_VERSION_TOO_LOW = 8566
const ERROR_DS_DRA_ABANDON_SYNC = 8462
const ERROR_DS_DRA_ACCESS_DENIED = 8453
const ERROR_DS_DRA_BAD_DN = 8439
const ERROR_DS_DRA_BAD_INSTANCE_TYPE = 8445
const ERROR_DS_DRA_BAD_NC = 8440
const ERROR_DS_DRA_BUSY = 8438
const ERROR_DS_DRA_CONNECTION_FAILED = 8444
const ERROR_DS_DRA_DB_ERROR = 8451
const ERROR_DS_DRA_DN_EXISTS = 8441
const ERROR_DS_DRA_EARLIER_SCHEMA_CONFLICT = 8544
const ERROR_DS_DRA_EXTN_CONNECTION_FAILED = 8466
const ERROR_DS_DRA_GENERIC = 8436
const ERROR_DS_DRA_INCOMPATIBLE_PARTIAL_SET = 8464
const ERROR_DS_DRA_INCONSISTENT_DIT = 8443
const ERROR_DS_DRA_INTERNAL_ERROR = 8442
const ERROR_DS_DRA_INVALID_PARAMETER = 8437
const ERROR_DS_DRA_MAIL_PROBLEM = 8447
const ERROR_DS_DRA_MISSING_PARENT = 8460
const ERROR_DS_DRA_NAME_COLLISION = 8458
const ERROR_DS_DRA_NOT_SUPPORTED = 8454
const ERROR_DS_DRA_NO_REPLICA = 8452
const ERROR_DS_DRA_OBJ_IS_REP_SOURCE = 8450
const ERROR_DS_DRA_OBJ_NC_MISMATCH = 8545
const ERROR_DS_DRA_OUT_OF_MEM = 8446
const ERROR_DS_DRA_OUT_SCHEDULE_WINDOW = 8617
const ERROR_DS_DRA_PREEMPTED = 8461
const ERROR_DS_DRA_REF_ALREADY_EXISTS = 8448
const ERROR_DS_DRA_REF_NOT_FOUND = 8449
const ERROR_DS_DRA_REPL_PENDING = 8477
const ERROR_DS_DRA_RPC_CANCELLED = 8455
const ERROR_DS_DRA_SCHEMA_CONFLICT = 8543
const ERROR_DS_DRA_SCHEMA_INFO_SHIP = 8542
const ERROR_DS_DRA_SCHEMA_MISMATCH = 8418
const ERROR_DS_DRA_SHUTDOWN = 8463
const ERROR_DS_DRA_SINK_DISABLED = 8457
const ERROR_DS_DRA_SOURCE_DISABLED = 8456
const ERROR_DS_DRA_SOURCE_IS_PARTIAL_REPLICA = 8465
const ERROR_DS_DRA_SOURCE_REINSTALLED = 8459
const ERROR_DS_DRS_EXTENSIONS_CHANGED = 8594
const ERROR_DS_DSA_MUST_BE_INT_MASTER = 8342
const ERROR_DS_DST_DOMAIN_NOT_NATIVE = 8496
const ERROR_DS_DST_NC_MISMATCH = 8486
const ERROR_DS_DS_REQUIRED = 8478
const ERROR_DS_DUPLICATE_ID_FOUND = 8605
const ERROR_DS_DUP_LDAP_DISPLAY_NAME = 8382
const ERROR_DS_DUP_LINK_ID = 8468
const ERROR_DS_DUP_MAPI_ID = 8380
const ERROR_DS_DUP_MSDS_INTID = 8597
const ERROR_DS_DUP_OID = 8379
const ERROR_DS_DUP_RDN = 8378
const ERROR_DS_DUP_SCHEMA_ID_GUID = 8381
const ERROR_DS_ENCODING_ERROR = 8252
const ERROR_DS_EPOCH_MISMATCH = 8483
const ERROR_DS_EXISTING_AD_CHILD_NC = 8613
const ERROR_DS_EXISTS_IN_AUX_CLS = 8393
const ERROR_DS_EXISTS_IN_MAY_HAVE = 8386
const ERROR_DS_EXISTS_IN_MUST_HAVE = 8385
const ERROR_DS_EXISTS_IN_POSS_SUP = 8395
const ERROR_DS_EXISTS_IN_RDNATTID = 8598
const ERROR_DS_EXISTS_IN_SUB_CLS = 8394
const ERROR_DS_FILTER_UNKNOWN = 8254
const ERROR_DS_FILTER_USES_CONTRUCTED_ATTRS = 8555
const ERROR_DS_FOREST_VERSION_TOO_HIGH = 8563
const ERROR_DS_FOREST_VERSION_TOO_LOW = 8565
const ERROR_DS_GCVERIFY_ERROR = 8417
const ERROR_DS_GC_NOT_AVAILABLE = 8217
const ERROR_DS_GC_REQUIRED = 8547
const ERROR_DS_GENERIC_ERROR = 8341
const ERROR_DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER = 8519
const ERROR_DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER = 8516
const ERROR_DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER = 8517
const ERROR_DS_GOVERNSID_MISSING = 8410
const ERROR_DS_GROUP_CONVERSION_ERROR = 8607
const ERROR_DS_HAVE_PRIMARY_MEMBERS = 8521
const ERROR_DS_HIERARCHY_TABLE_MALLOC_FAILED = 8429
const ERROR_DS_ILLEGAL_BASE_SCHEMA_MOD = 8507
const ERROR_DS_ILLEGAL_MOD_OPERATION = 8311
const ERROR_DS_ILLEGAL_SUPERIOR = 8345
const ERROR_DS_ILLEGAL_XDOM_MOVE_OPERATION = 8492
const ERROR_DS_INAPPROPRIATE_AUTH = 8233
const ERROR_DS_INAPPROPRIATE_MATCHING = 8238
const ERROR_DS_INCOMPATIBLE_CONTROLS_USED = 8574
const ERROR_DS_INCOMPATIBLE_VERSION = 8567
const ERROR_DS_INCORRECT_ROLE_OWNER = 8210
const ERROR_DS_INIT_FAILURE = 8532
const ERROR_DS_INIT_FAILURE_CONSOLE = 8561
const ERROR_DS_INSTALL_NO_SCH_VERSION_IN_INIFILE = 8512
const ERROR_DS_INSTALL_NO_SRC_SCH_VERSION = 8511
const ERROR_DS_INSTALL_SCHEMA_MISMATCH = 8467
const ERROR_DS_INSUFFICIENT_ATTR_TO_CREATE_OBJECT = 8606
const ERROR_DS_INSUFF_ACCESS_RIGHTS = 8344
const ERROR_DS_INTERNAL_FAILURE = 8430
const ERROR_DS_INVALID_ATTRIBUTE_SYNTAX = 8203
const ERROR_DS_INVALID_DMD = 8360
const ERROR_DS_INVALID_DN_SYNTAX = 8242
const ERROR_DS_INVALID_GROUP_TYPE = 8513
const ERROR_DS_INVALID_LDAP_DISPLAY_NAME = 8479
const ERROR_DS_INVALID_NAME_FOR_SPN = 8554
const ERROR_DS_INVALID_ROLE_OWNER = 8366
const ERROR_DS_INVALID_SCRIPT = 8600
const ERROR_DS_INVALID_SEARCH_FLAG = 8500
const ERROR_DS_IS_LEAF = 8243
const ERROR_DS_KEY_NOT_UNIQUE = 8527
const ERROR_DS_LDAP_SEND_QUEUE_FULL = 8616
const ERROR_DS_LINK_ID_NOT_AVAILABLE = 8577
const ERROR_DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER = 8520
const ERROR_DS_LOCAL_ERROR = 8251
const ERROR_DS_LOCAL_MEMBER_OF_LOCAL_ONLY = 8548
const ERROR_DS_LOOP_DETECT = 8246
const ERROR_DS_LOW_DSA_VERSION = 8568
const ERROR_DS_MACHINE_ACCOUNT_CREATED_PRENT4 = 8572
const ERROR_DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED = 8557
const ERROR_DS_MASTERDSA_REQUIRED = 8314
const ERROR_DS_MAX_OBJ_SIZE_EXCEEDED = 8304
const ERROR_DS_MEMBERSHIP_EVALUATED_LOCALLY = 8201
const ERROR_DS_MISSING_EXPECTED_ATT = 8411
const ERROR_DS_MISSING_FSMO_SETTINGS = 8434
const ERROR_DS_MISSING_INFRASTRUCTURE_CONTAINER = 8497
const ERROR_DS_MISSING_REQUIRED_ATT = 8316
const ERROR_DS_MISSING_SUPREF = 8406
const ERROR_DS_MODIFYDN_DISALLOWED_BY_FLAG = 8581
const ERROR_DS_MODIFYDN_DISALLOWED_BY_INSTANCE_TYPE = 8579
const ERROR_DS_MODIFYDN_WRONG_GRANDPARENT = 8582
const ERROR_DS_MUST_BE_RUN_ON_DST_DC = 8558
const ERROR_DS_NAME_ERROR_DOMAIN_ONLY = 8473
const ERROR_DS_NAME_ERROR_NOT_FOUND = 8470
const ERROR_DS_NAME_ERROR_NOT_UNIQUE = 8471
const ERROR_DS_NAME_ERROR_NO_MAPPING = 8472
const ERROR_DS_NAME_ERROR_NO_SYNTACTICAL_MAPPING = 8474
const ERROR_DS_NAME_ERROR_RESOLVING = 8469
const ERROR_DS_NAME_ERROR_TRUST_REFERRAL = 8583
const ERROR_DS_NAME_NOT_UNIQUE = 8571
const ERROR_DS_NAME_REFERENCE_INVALID = 8373
const ERROR_DS_NAME_TOO_LONG = 8348
const ERROR_DS_NAME_TOO_MANY_PARTS = 8347
const ERROR_DS_NAME_TYPE_UNKNOWN = 8351
const ERROR_DS_NAME_UNPARSEABLE = 8350
const ERROR_DS_NAME_VALUE_TOO_LONG = 8349
const ERROR_DS_NAMING_MASTER_GC = 8523
const ERROR_DS_NAMING_VIOLATION = 8247
const ERROR_DS_NCNAME_MISSING_CR_REF = 8412
const ERROR_DS_NCNAME_MUST_BE_NC = 8357
const ERROR_DS_NC_MUST_HAVE_NC_PARENT = 8494
const ERROR_DS_NC_STILL_HAS_DSAS = 8546
const ERROR_DS_NONEXISTENT_MAY_HAVE = 8387
const ERROR_DS_NONEXISTENT_MUST_HAVE = 8388
const ERROR_DS_NONEXISTENT_POSS_SUP = 8390
const ERROR_DS_NONSAFE_SCHEMA_CHANGE = 8508
const ERROR_DS_NON_BASE_SEARCH = 8480
const ERROR_DS_NOTIFY_FILTER_TOO_COMPLEX = 8377
const ERROR_DS_NOT_AN_OBJECT = 8352
const ERROR_DS_NOT_AUTHORITIVE_FOR_DST_NC = 8487
const ERROR_DS_NOT_CLOSEST = 8588
const ERROR_DS_NOT_INSTALLED = 8200
const ERROR_DS_NOT_ON_BACKLINK = 8362
const ERROR_DS_NOT_SUPPORTED = 8256
const ERROR_DS_NOT_SUPPORTED_SORT_ORDER = 8570
const ERROR_DS_NO_ATTRIBUTE_OR_VALUE = 8202
const ERROR_DS_NO_BEHAVIOR_VERSION_IN_MIXEDDOMAIN = 8569
const ERROR_DS_NO_CHAINED_EVAL = 8328
const ERROR_DS_NO_CHAINING = 8327
const ERROR_DS_NO_CHECKPOINT_WITH_PDC = 8551
const ERROR_DS_NO_CROSSREF_FOR_NC = 8363
const ERROR_DS_NO_DELETED_NAME = 8355
const ERROR_DS_NO_FPO_IN_UNIVERSAL_GROUPS = 8549
const ERROR_DS_NO_MORE_RIDS = 8209
const ERROR_DS_NO_MSDS_INTID = 8596
const ERROR_DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN = 8514
const ERROR_DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN = 8515
const ERROR_DS_NO_OBJECT_MOVE_IN_SCHEMA_NC = 8580
const ERROR_DS_NO_PARENT_OBJECT = 8329
const ERROR_DS_NO_PKT_PRIVACY_ON_CONNECTION = 8533
const ERROR_DS_NO_RDN_DEFINED_IN_SCHEMA = 8306
const ERROR_DS_NO_REF_DOMAIN = 8575
const ERROR_DS_NO_REQUESTED_ATTS_FOUND = 8308
const ERROR_DS_NO_RESULTS_RETURNED = 8257
const ERROR_DS_NO_RIDS_ALLOCATED = 8208
const ERROR_DS_NO_SUCH_OBJECT = 8240
const ERROR_DS_NO_TREE_DELETE_ABOVE_NC = 8501
const ERROR_DS_NTDSCRIPT_PROCESS_ERROR = 8592
const ERROR_DS_NTDSCRIPT_SYNTAX_ERROR = 8591
const ERROR_DS_OBJECT_BEING_REMOVED = 8339
const ERROR_DS_OBJECT_CLASS_REQUIRED = 8315
const ERROR_DS_OBJECT_RESULTS_TOO_LARGE = 8248
const ERROR_DS_OBJ_CLASS_NOT_DEFINED = 8371
const ERROR_DS_OBJ_CLASS_NOT_SUBCLASS = 8372
const ERROR_DS_OBJ_CLASS_VIOLATION = 8212
const ERROR_DS_OBJ_GUID_EXISTS = 8361
const ERROR_DS_OBJ_NOT_FOUND = 8333
const ERROR_DS_OBJ_STRING_NAME_EXISTS = 8305
const ERROR_DS_OBJ_TOO_LARGE = 8312
const ERROR_DS_OFFSET_RANGE_ERROR = 8262
const ERROR_DS_OPERATIONS_ERROR = 8224
const ERROR_DS_OUT_OF_SCOPE = 8338
const ERROR_DS_OUT_OF_VERSION_STORE = 8573
const ERROR_DS_PARAM_ERROR = 8255
const ERROR_DS_PARENT_IS_AN_ALIAS = 8330
const ERROR_DS_PDC_OPERATION_IN_PROGRESS = 8490
const ERROR_DS_PROTOCOL_ERROR = 8225
const ERROR_DS_RANGE_CONSTRAINT = 8322
const ERROR_DS_RDN_DOESNT_MATCH_SCHEMA = 8307
const ERROR_DS_RECALCSCHEMA_FAILED = 8396
const ERROR_DS_REFERRAL = 8235
const ERROR_DS_REFERRAL_LIMIT_EXCEEDED = 8260
const ERROR_DS_REFUSING_FSMO_ROLES = 8433
const ERROR_DS_REMOTE_CROSSREF_OP_FAILED = 8601
const ERROR_DS_REPLICATOR_ONLY = 8370
const ERROR_DS_REPLICA_SET_CHANGE_NOT_ALLOWED_ON_DISABLED_CR = 8595
const ERROR_DS_REPL_LIFETIME_EXCEEDED = 8614
const ERROR_DS_RESERVED_LINK_ID = 8576
const ERROR_DS_RIDMGR_INIT_ERROR = 8211
const ERROR_DS_ROLE_NOT_VERIFIED = 8610
const ERROR_DS_ROOT_CANT_BE_SUBREF = 8326
const ERROR_DS_ROOT_MUST_BE_NC = 8301
const ERROR_DS_ROOT_REQUIRES_CLASS_TOP = 8432
const ERROR_DS_SAM_INIT_FAILURE = 8504
const ERROR_DS_SAM_INIT_FAILURE_CONSOLE = 8562
const ERROR_DS_SAM_NEED_BOOTKEY_FLOPPY = 8530
const ERROR_DS_SAM_NEED_BOOTKEY_PASSWORD = 8529
const ERROR_DS_SCHEMA_ALLOC_FAILED = 8415
const ERROR_DS_SCHEMA_NOT_LOADED = 8414
const ERROR_DS_SCHEMA_UPDATE_DISALLOWED = 8509
const ERROR_DS_SECURITY_CHECKING_ERROR = 8413
const ERROR_DS_SECURITY_ILLEGAL_MODIFY = 8423
const ERROR_DS_SEC_DESC_INVALID = 8354
const ERROR_DS_SEC_DESC_TOO_SHORT = 8353
const ERROR_DS_SEMANTIC_ATT_TEST = 8383
const ERROR_DS_SENSITIVE_GROUP_VIOLATION = 8505
const ERROR_DS_SERVER_DOWN = 8250
const ERROR_DS_SHUTTING_DOWN = 8364
const ERROR_DS_SINGLE_USER_MODE_FAILED = 8590
const ERROR_DS_SINGLE_VALUE_CONSTRAINT = 8321
const ERROR_DS_SIZELIMIT_EXCEEDED = 8227
const ERROR_DS_SORT_CONTROL_MISSING = 8261
const ERROR_DS_SOURCE_AUDITING_NOT_ENABLED = 8552
const ERROR_DS_SOURCE_DOMAIN_IN_FOREST = 8534
const ERROR_DS_SRC_AND_DST_NC_IDENTICAL = 8485
const ERROR_DS_SRC_AND_DST_OBJECT_CLASS_MISMATCH = 8540
const ERROR_DS_SRC_DC_MUST_BE_SP4_OR_GREATER = 8559
const ERROR_DS_SRC_GUID_MISMATCH = 8488
const ERROR_DS_SRC_NAME_MISMATCH = 8484
const ERROR_DS_SRC_OBJ_NOT_GROUP_OR_USER = 8538
const ERROR_DS_SRC_SID_EXISTS_IN_FOREST = 8539
const ERROR_DS_STRING_SD_CONVERSION_FAILED = 8522
const ERROR_DS_STRONG_AUTH_REQUIRED = 8232
const ERROR_DS_SUBREF_MUST_HAVE_PARENT = 8356
const ERROR_DS_SUBTREE_NOTIFY_NOT_NC_HEAD = 8376
const ERROR_DS_SUB_CLS_TEST_FAIL = 8391
const ERROR_DS_SYNTAX_MISMATCH = 8384
const ERROR_DS_THREAD_LIMIT_EXCEEDED = 8587
const ERROR_DS_TIMELIMIT_EXCEEDED = 8226
const ERROR_DS_TREE_DELETE_NOT_FINISHED = 8397
const ERROR_DS_UNABLE_TO_SURRENDER_ROLES = 8435
const ERROR_DS_UNAVAILABLE = 8207
const ERROR_DS_UNAVAILABLE_CRIT_EXTENSION = 8236
const ERROR_DS_UNICODEPWD_NOT_IN_QUOTES = 8556
const ERROR_DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER = 8518
const ERROR_DS_UNKNOWN_ERROR = 8431
const ERROR_DS_UNKNOWN_OPERATION = 8365
const ERROR_DS_UNWILLING_TO_PERFORM = 8245
const ERROR_DS_USER_BUFFER_TO_SMALL = 8309
const ERROR_DS_WKO_CONTAINER_CANNOT_BE_SPECIAL = 8611
const ERROR_DS_WRONG_LINKED_ATT_SYNTAX = 8528
const ERROR_DS_WRONG_OM_OBJ_CLASS = 8476
const ERROR_DUPLICATE_SERVICE_NAME = 1078
const ERROR_DUPLICATE_TAG = 2014
const ERROR_DUP_DOMAINNAME = 1221
const ERROR_DUP_NAME = 52
const ERROR_DYNLINK_FROM_INVALID_RING = 196
const ERROR_EAS_DIDNT_FIT = 275
const ERROR_EAS_NOT_SUPPORTED = 282
const ERROR_EA_ACCESS_DENIED = 994
const ERROR_EA_FILE_CORRUPT = 276
const ERROR_EA_LIST_INCONSISTENT = 255
const ERROR_EA_TABLE_FULL = 277
const ERROR_EC_CIRCULAR_FORWARDING = 15082
const ERROR_EC_CREDSTORE_FULL = 15083
const ERROR_EC_CRED_NOT_FOUND = 15084
const ERROR_EC_LOG_DISABLED = 15081
const ERROR_EC_NO_ACTIVE_CHANNEL = 15085
const ERROR_EC_SUBSCRIPTION_CANNOT_ACTIVATE = 15080
const ERROR_EFS_ALG_BLOB_TOO_BIG = 6013
const ERROR_EFS_DISABLED = 6015
const ERROR_EFS_SERVER_NOT_TRUSTED = 6011
const ERROR_EFS_VERSION_NOT_SUPPORT = 6016
const ERROR_EMPTY = 4306
const ERROR_ENCRYPTION_FAILED = 6000
const ERROR_END_OF_MEDIA = 1100
const ERROR_ENVVAR_NOT_FOUND = 203
const ERROR_EOM_OVERFLOW = 1129
const ERROR_EVENTLOG_CANT_START = 1501
const ERROR_EVENTLOG_FILE_CHANGED = 1503
const ERROR_EVENTLOG_FILE_CORRUPT = 1500
const ERROR_EVT_CANNOT_OPEN_CHANNEL_OF_QUERY = 15036
const ERROR_EVT_CHANNEL_CANNOT_ACTIVATE = 15025
const ERROR_EVT_CHANNEL_NOT_FOUND = 15007
const ERROR_EVT_CONFIGURATION_ERROR = 15010
const ERROR_EVT_EVENT_DEFINITION_NOT_FOUND = 15032
const ERROR_EVT_EVENT_TEMPLATE_NOT_FOUND = 15003
const ERROR_EVT_FILTER_ALREADYSCOPED = 15014
const ERROR_EVT_FILTER_INVARG = 15016
const ERROR_EVT_FILTER_INVTEST = 15017
const ERROR_EVT_FILTER_INVTYPE = 15018
const ERROR_EVT_FILTER_NOTELTSET = 15015
const ERROR_EVT_FILTER_OUT_OF_RANGE = 15038
const ERROR_EVT_FILTER_PARSEERR = 15019
const ERROR_EVT_FILTER_TOO_COMPLEX = 15026
const ERROR_EVT_FILTER_UNEXPECTEDTOKEN = 15021
const ERROR_EVT_FILTER_UNSUPPORTEDOP = 15020
const ERROR_EVT_INVALID_CHANNEL_PATH = 15000
const ERROR_EVT_INVALID_CHANNEL_PROPERTY_VALUE = 15023
const ERROR_EVT_INVALID_EVENT_DATA = 15005
const ERROR_EVT_INVALID_OPERATION_OVER_ENABLED_DIRECT_CHANNEL = 15022
const ERROR_EVT_INVALID_PUBLISHER_NAME = 15004
const ERROR_EVT_INVALID_PUBLISHER_PROPERTY_VALUE = 15024
const ERROR_EVT_INVALID_QUERY = 15001
const ERROR_EVT_MALFORMED_XML_TEXT = 15008
const ERROR_EVT_MAX_INSERTS_REACHED = 15031
const ERROR_EVT_MESSAGE_ID_NOT_FOUND = 15028
const ERROR_EVT_MESSAGE_LOCALE_NOT_FOUND = 15033
const ERROR_EVT_MESSAGE_NOT_FOUND = 15027
const ERROR_EVT_NON_VALIDATING_MSXML = 15013
const ERROR_EVT_PUBLISHER_DISABLED = 15037
const ERROR_EVT_PUBLISHER_METADATA_NOT_FOUND = 15002
const ERROR_EVT_QUERY_RESULT_INVALID_POSITION = 15012
const ERROR_EVT_QUERY_RESULT_STALE = 15011
const ERROR_EVT_SUBSCRIPTION_TO_DIRECT_CHANNEL = 15009
const ERROR_EVT_UNRESOLVED_PARAMETER_INSERT = 15030
const ERROR_EVT_UNRESOLVED_VALUE_INSERT = 15029
const ERROR_EVT_VERSION_TOO_NEW = 15035
const ERROR_EVT_VERSION_TOO_OLD = 15034
const ERROR_EXCEPTION_IN_SERVICE = 1064
const ERROR_EXCL_SEM_ALREADY_OWNED = 101
const ERROR_EXE_CANNOT_MODIFY_SIGNED_BINARY = 217
const ERROR_EXE_CANNOT_MODIFY_STRONG_SIGNED_BINARY = 218
const ERROR_EXE_MACHINE_TYPE_MISMATCH = 216
const ERROR_EXE_MARKED_INVALID = 192
const ERROR_EXTENDED_ERROR = 1208
const ERROR_EXTERNAL_BACKING_PROVIDER_UNKNOWN = 343
const ERROR_FAILED_SERVICE_CONTROLLER_CONNECT = 1063
const ERROR_FAIL_I24 = 83
const ERROR_FILEMARK_DETECTED = 1101
const ERROR_FILENAME_EXCED_RANGE = 206
const ERROR_FILE_CHECKED_OUT = 220
const ERROR_FILE_CORRUPT = 1392
const ERROR_FILE_ENCRYPTED = 6002
const ERROR_FILE_EXISTS = 80
const ERROR_FILE_INVALID = 1006
const ERROR_FILE_NOT_ENCRYPTED = 6007
const ERROR_FILE_NOT_FOUND = 2
const ERROR_FILE_OFFLINE = 4350
const ERROR_FILE_READ_ONLY = 6009
const ERROR_FILE_TOO_LARGE = 223
const ERROR_FLOPPY_BAD_REGISTERS = 1125
const ERROR_FLOPPY_ID_MARK_NOT_FOUND = 1122
const ERROR_FLOPPY_UNKNOWN_ERROR = 1124
const ERROR_FLOPPY_WRONG_CYLINDER = 1123
const ERROR_FORMS_AUTH_REQUIRED = 224
const ERROR_FULLSCREEN_MODE = 1007
const ERROR_FULL_BACKUP = 4004
const ERROR_FUNCTION_FAILED = 1627
const ERROR_FUNCTION_NOT_CALLED = 1626
const ERROR_GENERIC_COMMAND_FAILED = 14109
const ERROR_GENERIC_NOT_MAPPED = 1360
const ERROR_GEN_FAILURE = 31
const ERROR_GLOBAL_ONLY_HOOK = 1429
const ERROR_GPIO_CLIENT_INFORMATION_INVALID = 15322
const ERROR_GPIO_INCOMPATIBLE_CONNECT_MODE = 15326
const ERROR_GPIO_INTERRUPT_ALREADY_UNMASKED = 15327
const ERROR_GPIO_INVALID_REGISTRATION_PACKET = 15324
const ERROR_GPIO_OPERATION_DENIED = 15325
const ERROR_GPIO_VERSION_NOT_SUPPORTED = 15323
const ERROR_GRACEFUL_DISCONNECT = 1226
const ERROR_GROUP_EXISTS = 1318
const ERROR_GROUP_NOT_AVAILABLE = 5012
const ERROR_GROUP_NOT_FOUND = 5013
const ERROR_GROUP_NOT_ONLINE = 5014
const ERROR_HANDLE_DISK_FULL = 39
const ERROR_HANDLE_EOF = 38
const ERROR_HASH_NOT_PRESENT = 15301
const ERROR_HASH_NOT_SUPPORTED = 15300
const ERROR_HOOK_NEEDS_HMOD = 1428
const ERROR_HOOK_NOT_INSTALLED = 1431
const ERROR_HOOK_TYPE_NOT_ALLOWED = 1458
const ERROR_HOST_DOWN = 1256
const ERROR_HOST_NODE_NOT_AVAILABLE = 5005
const ERROR_HOST_NODE_NOT_GROUP_OWNER = 5016
const ERROR_HOST_NODE_NOT_RESOURCE_OWNER = 5015
const ERROR_HOST_UNREACHABLE = 1232
const ERROR_HOTKEY_ALREADY_REGISTERED = 1409
const ERROR_HOTKEY_NOT_REGISTERED = 1419
const ERROR_HWNDS_HAVE_DIFF_PARENT = 1441
const ERROR_ICM_NOT_ENABLED = 2018
const ERROR_IEPORT_FULL = 4341
const ERROR_ILLEGAL_ELEMENT_ADDRESS = 1162
const ERROR_ILL_FORMED_PASSWORD = 1324
const ERROR_INCORRECT_ADDRESS = 1241
const ERROR_INCORRECT_SIZE = 1462
const ERROR_INC_BACKUP = 4003
const ERROR_INDEX_ABSENT = 1611
const ERROR_INDIGENOUS_TYPE = 4338
const ERROR_INFLOOP_IN_RELOC_CHAIN = 202
const ERROR_INIT_STATUS_NEEDED = 17
const ERROR_INSTALL_ALREADY_RUNNING = 1618
const ERROR_INSTALL_CANCEL = 15608
const ERROR_INSTALL_DEREGISTRATION_FAILURE = 15607
const ERROR_INSTALL_FAILED = 15609
const ERROR_INSTALL_FAILURE = 1603
const ERROR_INSTALL_FIREWALL_SERVICE_NOT_RUNNING = 15626
const ERROR_INSTALL_INVALID_PACKAGE = 15602
const ERROR_INSTALL_LANGUAGE_UNSUPPORTED = 1623
const ERROR_INSTALL_LOG_FAILURE = 1622
const ERROR_INSTALL_NETWORK_FAILURE = 15605
const ERROR_INSTALL_NOTUSED = 1634
const ERROR_INSTALL_OPEN_PACKAGE_FAILED = 15600
const ERROR_INSTALL_OUT_OF_DISK_SPACE = 15604
const ERROR_INSTALL_PACKAGE_DOWNGRADE = 15622
const ERROR_INSTALL_PACKAGE_INVALID = 1620
const ERROR_INSTALL_PACKAGE_NOT_FOUND = 15601
const ERROR_INSTALL_PACKAGE_OPEN_FAILED = 1619
const ERROR_INSTALL_PACKAGE_REJECTED = 1625
const ERROR_INSTALL_PACKAGE_VERSION = 1613
const ERROR_INSTALL_PLATFORM_UNSUPPORTED = 1633
const ERROR_INSTALL_POLICY_FAILURE = 15615
const ERROR_INSTALL_PREREQUISITE_FAILED = 15613
const ERROR_INSTALL_REGISTRATION_FAILURE = 15606
const ERROR_INSTALL_REMOTE_DISALLOWED = 1640
const ERROR_INSTALL_REMOTE_PROHIBITED = 1645
const ERROR_INSTALL_RESOLVE_DEPENDENCY_FAILED = 15603
const ERROR_INSTALL_SERVICE_FAILURE = 1601
const ERROR_INSTALL_SOURCE_ABSENT = 1612
const ERROR_INSTALL_SUSPEND = 1604
const ERROR_INSTALL_TEMP_UNWRITABLE = 1632
const ERROR_INSTALL_TRANSFORM_FAILURE = 1624
const ERROR_INSTALL_TRANSFORM_REJECTED = 1644
const ERROR_INSTALL_UI_FAILURE = 1621
const ERROR_INSTALL_USEREXIT = 1602
const ERROR_INSUFFICIENT_BUFFER = 122
const ERROR_INTERNAL_DB_CORRUPTION = 1358
const ERROR_INTERNAL_DB_ERROR = 1383
const ERROR_INTERNAL_ERROR = 1359
const ERROR_INVALID_ACCEL_HANDLE = 1403
const ERROR_INVALID_ACCESS = 12
const ERROR_INVALID_ACCOUNT_NAME = 1315
const ERROR_INVALID_ACL = 1336
const ERROR_INVALID_ADDRESS = 487
const ERROR_INVALID_AT_INTERRUPT_TIME = 104
const ERROR_INVALID_BLOCK = 9
const ERROR_INVALID_BLOCK_LENGTH = 1106
const ERROR_INVALID_CATEGORY = 117
const ERROR_INVALID_CLEANER = 4310
const ERROR_INVALID_CMM = 2010
const ERROR_INVALID_COLORINDEX = 2022
const ERROR_INVALID_COLORSPACE = 2017
const ERROR_INVALID_COMBOBOX_MESSAGE = 1422
const ERROR_INVALID_COMMAND_LINE = 1639
const ERROR_INVALID_COMPUTERNAME = 1210
const ERROR_INVALID_CURSOR_HANDLE = 1402
const ERROR_INVALID_DATA = 13
const ERROR_INVALID_DATATYPE = 1804
const ERROR_INVALID_DLL = 1154
const ERROR_INVALID_DOMAINNAME = 1212
const ERROR_INVALID_DOMAIN_ROLE = 1354
const ERROR_INVALID_DOMAIN_STATE = 1353
const ERROR_INVALID_DRIVE = 15
const ERROR_INVALID_DRIVE_OBJECT = 4321
const ERROR_INVALID_DWP_HANDLE = 1405
const ERROR_INVALID_EA_HANDLE = 278
const ERROR_INVALID_EA_NAME = 254
const ERROR_INVALID_EDIT_HEIGHT = 1424
const ERROR_INVALID_ENVIRONMENT = 1805
const ERROR_INVALID_EVENTNAME = 1211
const ERROR_INVALID_EVENT_COUNT = 151
const ERROR_INVALID_EXE_SIGNATURE = 191
const ERROR_INVALID_FIELD = 1616
const ERROR_INVALID_FILTER_PROC = 1427
const ERROR_INVALID_FLAGS = 1004
const ERROR_INVALID_FLAG_NUMBER = 186
const ERROR_INVALID_FORM_NAME = 1902
const ERROR_INVALID_FORM_SIZE = 1903
const ERROR_INVALID_FUNCTION = 1
const ERROR_INVALID_GROUPNAME = 1209
const ERROR_INVALID_GROUP_ATTRIBUTES = 1345
const ERROR_INVALID_GW_COMMAND = 1443
const ERROR_INVALID_HANDLE = 6
const ERROR_INVALID_HANDLE_STATE = 1609
const ERROR_INVALID_HOOK_FILTER = 1426
const ERROR_INVALID_HOOK_HANDLE = 1404
const ERROR_INVALID_ICON_HANDLE = 1414
const ERROR_INVALID_ID_AUTHORITY = 1343
const ERROR_INVALID_IMPORT_OF_NON_DLL = 1276
const ERROR_INVALID_INDEX = 1413
const ERROR_INVALID_KEYBOARD_HANDLE = 1457
const ERROR_INVALID_LB_MESSAGE = 1432
const ERROR_INVALID_LEVEL = 124
const ERROR_INVALID_LIBRARY = 4301
const ERROR_INVALID_LIST_FORMAT = 153
const ERROR_INVALID_LOGON_HOURS = 1328
const ERROR_INVALID_LOGON_TYPE = 1367
const ERROR_INVALID_MEDIA = 4300
const ERROR_INVALID_MEDIA_POOL = 4302
const ERROR_INVALID_MEMBER = 1388
const ERROR_INVALID_MENU_HANDLE = 1401
const ERROR_INVALID_MESSAGE = 1002
const ERROR_INVALID_MESSAGEDEST = 1218
const ERROR_INVALID_MESSAGENAME = 1217
const ERROR_INVALID_MINALLOCSIZE = 195
const ERROR_INVALID_MODULETYPE = 190
const ERROR_INVALID_MONITOR_HANDLE = 1461
const ERROR_INVALID_MSGBOX_STYLE = 1438
const ERROR_INVALID_NAME = 123
const ERROR_INVALID_NETNAME = 1214
const ERROR_INVALID_OPERATION = 4317
const ERROR_INVALID_OPERATION_ON_QUORUM = 5068
const ERROR_INVALID_OPLOCK_PROTOCOL = 301
const ERROR_INVALID_ORDINAL = 182
const ERROR_INVALID_OWNER = 1307
const ERROR_INVALID_PARAMETER = 87
const ERROR_INVALID_PASSWORD = 86
const ERROR_INVALID_PASSWORDNAME = 1216
const ERROR_INVALID_PIXEL_FORMAT = 2000
const ERROR_INVALID_PRIMARY_GROUP = 1308
const ERROR_INVALID_PRINTER_COMMAND = 1803
const ERROR_INVALID_PRINTER_NAME = 1801
const ERROR_INVALID_PRINTER_STATE = 1906
const ERROR_INVALID_PRINT_MONITOR = 3007
const ERROR_INVALID_PRIORITY = 1800
const ERROR_INVALID_PROFILE = 2011
const ERROR_INVALID_REPARSE_DATA = 4392
const ERROR_INVALID_RUNLEVEL_SETTING = 15401
const ERROR_INVALID_SCROLLBAR_RANGE = 1448
const ERROR_INVALID_SECURITY_DESCR = 1338
const ERROR_INVALID_SEGDPL = 198
const ERROR_INVALID_SEGMENT_NUMBER = 180
const ERROR_INVALID_SEPARATOR_FILE = 1799
const ERROR_INVALID_SERVER_STATE = 1352
const ERROR_INVALID_SERVICENAME = 1213
const ERROR_INVALID_SERVICE_ACCOUNT = 1057
const ERROR_INVALID_SERVICE_CONTROL = 1052
const ERROR_INVALID_SERVICE_LOCK = 1071
const ERROR_INVALID_SHARENAME = 1215
const ERROR_INVALID_SHOWWIN_COMMAND = 1449
const ERROR_INVALID_SID = 1337
const ERROR_INVALID_SIGNAL_NUMBER = 209
const ERROR_INVALID_SPI_VALUE = 1439
const ERROR_INVALID_STACKSEG = 189
const ERROR_INVALID_STAGED_SIGNATURE = 15620
const ERROR_INVALID_STARTING_CODESEG = 188
const ERROR_INVALID_STATE = 5023
const ERROR_INVALID_SUB_AUTHORITY = 1335
const ERROR_INVALID_TABLE = 1628
const ERROR_INVALID_TARGET_HANDLE = 114
const ERROR_INVALID_THREAD_ID = 1444
const ERROR_INVALID_TIME = 1901
const ERROR_INVALID_TOKEN = 315
const ERROR_INVALID_TRANSFORM = 2020
const ERROR_INVALID_USER_BUFFER = 1784
const ERROR_INVALID_VERIFY_SWITCH = 118
const ERROR_INVALID_WINDOW_HANDLE = 1400
const ERROR_INVALID_WINDOW_STYLE = 2002
const ERROR_INVALID_WORKSTATION = 1329
const ERROR_IOPL_NOT_ENABLED = 197
const ERROR_IO_DEVICE = 1117
const ERROR_IO_INCOMPLETE = 996
const ERROR_IO_PENDING = 997
const ERROR_IPSEC_AUTH_FIREWALL_DROP = 13917
const ERROR_IPSEC_BAD_SPI = 13910
const ERROR_IPSEC_CLEAR_TEXT_DROP = 13916
const ERROR_IPSEC_DEFAULT_MM_AUTH_NOT_FOUND = 13014
const ERROR_IPSEC_DEFAULT_MM_POLICY_NOT_FOUND = 13013
const ERROR_IPSEC_DEFAULT_QM_POLICY_NOT_FOUND = 13015
const ERROR_IPSEC_DOSP_BLOCK = 13925
const ERROR_IPSEC_DOSP_INVALID_PACKET = 13927
const ERROR_IPSEC_DOSP_KEYMOD_NOT_ALLOWED = 13930
const ERROR_IPSEC_DOSP_MAX_ENTRIES = 13929
const ERROR_IPSEC_DOSP_MAX_PER_IP_RATELIMIT_QUEUES = 13932
const ERROR_IPSEC_DOSP_NOT_INSTALLED = 13931
const ERROR_IPSEC_DOSP_RECEIVED_MULTICAST = 13926
const ERROR_IPSEC_DOSP_STATE_LOOKUP_FAILED = 13928
const ERROR_IPSEC_IKE_ADD_UPDATE_KEY_FAILED = 13860
const ERROR_IPSEC_IKE_ATTRIB_FAIL = 13802
const ERROR_IPSEC_IKE_AUTHORIZATION_FAILURE = 13905
const ERROR_IPSEC_IKE_AUTHORIZATION_FAILURE_WITH_OPTIONAL_RETRY = 13907
const ERROR_IPSEC_IKE_AUTH_FAIL = 13801
const ERROR_IPSEC_IKE_BENIGN_REINIT = 13878
const ERROR_IPSEC_IKE_CERT_CHAIN_POLICY_MISMATCH = 13887
const ERROR_IPSEC_IKE_CGA_AUTH_FAILED = 13892
const ERROR_IPSEC_IKE_COEXISTENCE_SUPPRESS = 13902
const ERROR_IPSEC_IKE_CRL_FAILED = 13817
const ERROR_IPSEC_IKE_DECRYPT = 13867
const ERROR_IPSEC_IKE_DH_FAIL = 13822
const ERROR_IPSEC_IKE_DH_FAILURE = 13864
const ERROR_IPSEC_IKE_DOS_COOKIE_SENT = 13890
const ERROR_IPSEC_IKE_DROP_NO_RESPONSE = 13813
const ERROR_IPSEC_IKE_ENCRYPT = 13866
const ERROR_IPSEC_IKE_ERROR = 13816
const ERROR_IPSEC_IKE_FAILQUERYSSP = 13854
const ERROR_IPSEC_IKE_FAILSSPINIT = 13853
const ERROR_IPSEC_IKE_GENERAL_PROCESSING_ERROR = 13804
const ERROR_IPSEC_IKE_GETSPIFAIL = 13857
const ERROR_IPSEC_IKE_INNER_IP_ASSIGNMENT_FAILURE = 13899
const ERROR_IPSEC_IKE_INVALID_AUTH_ALG = 13874
const ERROR_IPSEC_IKE_INVALID_AUTH_PAYLOAD = 13889
const ERROR_IPSEC_IKE_INVALID_CERT_KEYLEN = 13881
const ERROR_IPSEC_IKE_INVALID_CERT_TYPE = 13819
const ERROR_IPSEC_IKE_INVALID_COOKIE = 13846
const ERROR_IPSEC_IKE_INVALID_ENCRYPT_ALG = 13873
const ERROR_IPSEC_IKE_INVALID_FILTER = 13858
const ERROR_IPSEC_IKE_INVALID_GROUP = 13865
const ERROR_IPSEC_IKE_INVALID_HASH = 13870
const ERROR_IPSEC_IKE_INVALID_HASH_ALG = 13871
const ERROR_IPSEC_IKE_INVALID_HASH_SIZE = 13872
const ERROR_IPSEC_IKE_INVALID_HEADER = 13824
const ERROR_IPSEC_IKE_INVALID_KEY_USAGE = 13818
const ERROR_IPSEC_IKE_INVALID_MM_FOR_QM = 13894
const ERROR_IPSEC_IKE_INVALID_PAYLOAD = 13843
const ERROR_IPSEC_IKE_INVALID_POLICY = 13861
const ERROR_IPSEC_IKE_INVALID_RESPONDER_LIFETIME_NOTIFY = 13879
const ERROR_IPSEC_IKE_INVALID_SIG = 13875
const ERROR_IPSEC_IKE_INVALID_SIGNATURE = 13826
const ERROR_IPSEC_IKE_INVALID_SITUATION = 13863
const ERROR_IPSEC_IKE_KERBEROS_ERROR = 13827
const ERROR_IPSEC_IKE_KILL_DUMMY_NAP_TUNNEL = 13898
const ERROR_IPSEC_IKE_LOAD_FAILED = 13876
const ERROR_IPSEC_IKE_LOAD_SOFT_SA = 13844
const ERROR_IPSEC_IKE_MM_ACQUIRE_DROP = 13809
const ERROR_IPSEC_IKE_MM_DELAY_DROP = 13814
const ERROR_IPSEC_IKE_MM_EXPIRED = 13885
const ERROR_IPSEC_IKE_MM_LIMIT = 13882
const ERROR_IPSEC_IKE_NEGOTIATION_DISABLED = 13883
const ERROR_IPSEC_IKE_NEGOTIATION_PENDING = 13803
const ERROR_IPSEC_IKE_NEG_STATUS_BEGIN = 13800
const ERROR_IPSEC_IKE_NEG_STATUS_END = 13897
const ERROR_IPSEC_IKE_NEG_STATUS_EXTENDED_END = 13909
const ERROR_IPSEC_IKE_NOTCBPRIV = 13851
const ERROR_IPSEC_IKE_NO_CERT = 13806
const ERROR_IPSEC_IKE_NO_MM_POLICY = 13850
const ERROR_IPSEC_IKE_NO_PEER_CERT = 13847
const ERROR_IPSEC_IKE_NO_POLICY = 13825
const ERROR_IPSEC_IKE_NO_PRIVATE_KEY = 13820
const ERROR_IPSEC_IKE_NO_PUBLIC_KEY = 13828
const ERROR_IPSEC_IKE_OUT_OF_MEMORY = 13859
const ERROR_IPSEC_IKE_PEER_CRL_FAILED = 13848
const ERROR_IPSEC_IKE_PEER_DOESNT_SUPPORT_MOBIKE = 13904
const ERROR_IPSEC_IKE_PEER_MM_ASSUMED_INVALID = 13886
const ERROR_IPSEC_IKE_POLICY_CHANGE = 13849
const ERROR_IPSEC_IKE_POLICY_MATCH = 13868
const ERROR_IPSEC_IKE_PROCESS_ERR = 13829
const ERROR_IPSEC_IKE_PROCESS_ERR_CERT = 13835
const ERROR_IPSEC_IKE_PROCESS_ERR_CERT_REQ = 13836
const ERROR_IPSEC_IKE_PROCESS_ERR_DELETE = 13841
const ERROR_IPSEC_IKE_PROCESS_ERR_HASH = 13837
const ERROR_IPSEC_IKE_PROCESS_ERR_ID = 13834
const ERROR_IPSEC_IKE_PROCESS_ERR_KE = 13833
const ERROR_IPSEC_IKE_PROCESS_ERR_NATOA = 13893
const ERROR_IPSEC_IKE_PROCESS_ERR_NONCE = 13839
const ERROR_IPSEC_IKE_PROCESS_ERR_NOTIFY = 13840
const ERROR_IPSEC_IKE_PROCESS_ERR_PROP = 13831
const ERROR_IPSEC_IKE_PROCESS_ERR_SA = 13830
const ERROR_IPSEC_IKE_PROCESS_ERR_SIG = 13838
const ERROR_IPSEC_IKE_PROCESS_ERR_TRANS = 13832
const ERROR_IPSEC_IKE_PROCESS_ERR_VENDOR = 13842
const ERROR_IPSEC_IKE_QM_ACQUIRE_DROP = 13810
const ERROR_IPSEC_IKE_QM_DELAY_DROP = 13815
const ERROR_IPSEC_IKE_QM_EXPIRED = 13895
const ERROR_IPSEC_IKE_QM_LIMIT = 13884
const ERROR_IPSEC_IKE_QUEUE_DROP_MM = 13811
const ERROR_IPSEC_IKE_QUEUE_DROP_NO_MM = 13812
const ERROR_IPSEC_IKE_RATELIMIT_DROP = 13903
const ERROR_IPSEC_IKE_REQUIRE_CP_PAYLOAD_MISSING = 13900
const ERROR_IPSEC_IKE_RPC_DELETE = 13877
const ERROR_IPSEC_IKE_SA_DELETED = 13807
const ERROR_IPSEC_IKE_SA_REAPED = 13808
const ERROR_IPSEC_IKE_SECLOADFAIL = 13852
const ERROR_IPSEC_IKE_SHUTTING_DOWN = 13891
const ERROR_IPSEC_IKE_SOFT_SA_TORN_DOWN = 13845
const ERROR_IPSEC_IKE_SRVACQFAIL = 13855
const ERROR_IPSEC_IKE_SRVQUERYCRED = 13856
const ERROR_IPSEC_IKE_STRONG_CRED_AUTHORIZATION_AND_CERTMAP_FAILURE = 13908
const ERROR_IPSEC_IKE_STRONG_CRED_AUTHORIZATION_FAILURE = 13906
const ERROR_IPSEC_IKE_TIMED_OUT = 13805
const ERROR_IPSEC_IKE_TOO_MANY_FILTERS = 13896
const ERROR_IPSEC_IKE_UNEXPECTED_MESSAGE_ID = 13888
const ERROR_IPSEC_IKE_UNKNOWN_DOI = 13862
const ERROR_IPSEC_IKE_UNSUPPORTED_ID = 13869
const ERROR_IPSEC_INTEGRITY_CHECK_FAILED = 13915
const ERROR_IPSEC_INVALID_PACKET = 13914
const ERROR_IPSEC_KEY_MODULE_IMPERSONATION_NEGOTIATION_PENDING = 13901
const ERROR_IPSEC_MM_AUTH_EXISTS = 13010
const ERROR_IPSEC_MM_AUTH_IN_USE = 13012
const ERROR_IPSEC_MM_AUTH_NOT_FOUND = 13011
const ERROR_IPSEC_MM_AUTH_PENDING_DELETION = 13022
const ERROR_IPSEC_MM_FILTER_EXISTS = 13006
const ERROR_IPSEC_MM_FILTER_NOT_FOUND = 13007
const ERROR_IPSEC_MM_FILTER_PENDING_DELETION = 13018
const ERROR_IPSEC_MM_POLICY_EXISTS = 13003
const ERROR_IPSEC_MM_POLICY_IN_USE = 13005
const ERROR_IPSEC_MM_POLICY_NOT_FOUND = 13004
const ERROR_IPSEC_MM_POLICY_PENDING_DELETION = 13021
const ERROR_IPSEC_QM_POLICY_EXISTS = 13000
const ERROR_IPSEC_QM_POLICY_IN_USE = 13002
const ERROR_IPSEC_QM_POLICY_NOT_FOUND = 13001
const ERROR_IPSEC_QM_POLICY_PENDING_DELETION = 13023
const ERROR_IPSEC_REPLAY_CHECK_FAILED = 13913
const ERROR_IPSEC_SA_LIFETIME_EXPIRED = 13911
const ERROR_IPSEC_THROTTLE_DROP = 13918
const ERROR_IPSEC_TRANSPORT_FILTER_EXISTS = 13008
const ERROR_IPSEC_TRANSPORT_FILTER_NOT_FOUND = 13009
const ERROR_IPSEC_TRANSPORT_FILTER_PENDING_DELETION = 13019
const ERROR_IPSEC_TUNNEL_FILTER_EXISTS = 13016
const ERROR_IPSEC_TUNNEL_FILTER_NOT_FOUND = 13017
const ERROR_IPSEC_TUNNEL_FILTER_PENDING_DELETION = 13020
const ERROR_IPSEC_WRONG_SA = 13912
const ERROR_IRQ_BUSY = 1119
const ERROR_IS_JOINED = 134
const ERROR_IS_JOIN_PATH = 147
const ERROR_IS_JOIN_TARGET = 133
const ERROR_IS_SUBSTED = 135
const ERROR_IS_SUBST_PATH = 146
const ERROR_IS_SUBST_TARGET = 149
const ERROR_ITERATED_DATA_EXCEEDS_64k = 194
const ERROR_JOIN_TO_JOIN = 138
const ERROR_JOIN_TO_SUBST = 140
const ERROR_JOURNAL_DELETE_IN_PROGRESS = 1178
const ERROR_JOURNAL_ENTRY_DELETED = 1181
const ERROR_JOURNAL_HOOK_SET = 1430
const ERROR_JOURNAL_NOT_ACTIVE = 1179
const ERROR_KERNEL_APC = 738
const ERROR_KEY_DELETED = 1018
const ERROR_KEY_HAS_CHILDREN = 1020
const ERROR_KM_DRIVER_BLOCKED = 1930
const ERROR_LABEL_QUESTIONABLE = 2
const ERROR_LABEL_TOO_LONG = 154
const ERROR_LABEL_UNREADABLE = 1
const ERROR_LAST_ADMIN = 1322
const ERROR_LB_WITHOUT_TABSTOPS = 1434
const ERROR_LIBRARY_FULL = 4322
const ERROR_LIBRARY_OFFLINE = 4305
const ERROR_LICENSE_QUOTA_EXCEEDED = 1395
const ERROR_LISTBOX_ID_NOT_FOUND = 1416
const ERROR_LM_CROSS_ENCRYPTION_REQUIRED = 1390
const ERROR_LOCAL_USER_SESSION_KEY = 1303
const ERROR_LOCKED = 212
const ERROR_LOCK_FAILED = 167
const ERROR_LOCK_VIOLATION = 33
const ERROR_LOGIN_TIME_RESTRICTION = 1239
const ERROR_LOGIN_WKSTA_RESTRICTION = 1240
const ERROR_LOGON_FAILURE = 1326
const ERROR_LOGON_NOT_GRANTED = 1380
const ERROR_LOGON_SESSION_COLLISION = 1366
const ERROR_LOGON_SESSION_EXISTS = 1363
const ERROR_LOGON_TYPE_NOT_GRANTED = 1385
const ERROR_LOG_FILE_FULL = 1502
const ERROR_LUIDS_EXHAUSTED = 1334
const ERROR_MACHINE_LOCKED = 1271
const ERROR_MAGAZINE_NOT_PRESENT = 1163
const ERROR_MALFORMED_SUBSTITUTION_STRING = 14094
const ERROR_MAPPED_ALIGNMENT = 1132
const ERROR_MAX_THRDS_REACHED = 164
const ERROR_MCA_INTERNAL_ERROR = 15205
const ERROR_MCA_INVALID_CAPABILITIES_STRING = 15200
const ERROR_MCA_INVALID_TECHNOLOGY_TYPE_RETURNED = 15206
const ERROR_MCA_INVALID_VCP_VERSION = 15201
const ERROR_MCA_MCCS_VERSION_MISMATCH = 15203
const ERROR_MCA_MONITOR_VIOLATES_MCCS_SPECIFICATION = 15202
const ERROR_MCA_UNSUPPORTED_COLOR_TEMPERATURE = 15207
const ERROR_MCA_UNSUPPORTED_MCCS_VERSION = 15204
const ERROR_MEDIA_CHANGED = 1110
const ERROR_MEDIA_INCOMPATIBLE = 4315
const ERROR_MEDIA_NOT_AVAILABLE = 4318
const ERROR_MEDIA_OFFLINE = 4304
const ERROR_MEDIA_UNAVAILABLE = 4308
const ERROR_MEDIUM_NOT_ACCESSIBLE = 4323
const ERROR_MEMBERS_PRIMARY_GROUP = 1374
const ERROR_MEMBER_IN_ALIAS = 1378
const ERROR_MEMBER_IN_GROUP = 1320
const ERROR_MEMBER_NOT_IN_ALIAS = 1377
const ERROR_MEMBER_NOT_IN_GROUP = 1321
const ERROR_MENU_ITEM_NOT_FOUND = 1456
const ERROR_MESSAGE_EXCEEDS_MAX_SIZE = 4336
const ERROR_MESSAGE_SYNC_ONLY = 1159
const ERROR_METAFILE_NOT_SUPPORTED = 2003
const ERROR_META_EXPANSION_TOO_LONG = 208
const ERROR_MOD_NOT_FOUND = 126
const ERROR_MORE_DATA = 234
const ERROR_MORE_WRITES = 1120
const ERROR_MRM_AUTOMERGE_ENABLED = 15139
const ERROR_MRM_DUPLICATE_ENTRY = 15119
const ERROR_MRM_DUPLICATE_MAP_NAME = 15118
const ERROR_MRM_FILEPATH_TOO_LONG = 15121
const ERROR_MRM_INDETERMINATE_QUALIFIER_VALUE = 15138
const ERROR_MRM_INVALID_FILE_TYPE = 15112
const ERROR_MRM_INVALID_PRICONFIG = 15111
const ERROR_MRM_INVALID_PRI_FILE = 15126
const ERROR_MRM_INVALID_QUALIFIER_OPERATOR = 15137
const ERROR_MRM_INVALID_QUALIFIER_VALUE = 15114
const ERROR_MRM_INVALID_RESOURCE_IDENTIFIER = 15120
const ERROR_MRM_MAP_NOT_FOUND = 15135
const ERROR_MRM_NAMED_RESOURCE_NOT_FOUND = 15127
const ERROR_MRM_NO_CANDIDATE = 15115
const ERROR_MRM_NO_MATCH_OR_DEFAULT_CANDIDATE = 15116
const ERROR_MRM_RESOURCE_TYPE_MISMATCH = 15117
const ERROR_MRM_RUNTIME_NO_DEFAULT_OR_NEUTRAL_RESOURCE = 15110
const ERROR_MRM_TOO_MANY_RESOURCES = 15140
const ERROR_MRM_UNKNOWN_QUALIFIER = 15113
const ERROR_MRM_UNSUPPORTED_DIRECTORY_TYPE = 15122
const ERROR_MRM_UNSUPPORTED_PROFILE_TYPE = 15136
const ERROR_MR_MID_NOT_FOUND = 317
const ERROR_MUI_FILE_NOT_FOUND = 15100
const ERROR_MUI_FILE_NOT_LOADED = 15105
const ERROR_MUI_INTLSETTINGS_INVALID_LOCALE_NAME = 15108
const ERROR_MUI_INTLSETTINGS_UILANG_NOT_INSTALLED = 15107
const ERROR_MUI_INVALID_FILE = 15101
const ERROR_MUI_INVALID_LOCALE_NAME = 15103
const ERROR_MUI_INVALID_RC_CONFIG = 15102
const ERROR_MUI_INVALID_ULTIMATEFALLBACK_NAME = 15104
const ERROR_MUTUAL_AUTH_FAILED = 1397
const ERROR_NEEDS_REMEDIATION = 15612
const ERROR_NEGATIVE_SEEK = 131
const ERROR_NESTING_NOT_ALLOWED = 215
const ERROR_NETLOGON_NOT_STARTED = 1792
const ERROR_NETNAME_DELETED = 64
const ERROR_NETWORK_ACCESS_DENIED = 65
const ERROR_NETWORK_BUSY = 54
const ERROR_NETWORK_NOT_AVAILABLE = 5035
const ERROR_NETWORK_UNREACHABLE = 1231
const ERROR_NET_WRITE_FAULT = 88
const ERROR_NOACCESS = 998
const ERROR_NODE_CANNOT_BE_CLUSTERED = 5898
const ERROR_NODE_CANT_HOST_RESOURCE = 5071
const ERROR_NODE_NOT_AVAILABLE = 5036
const ERROR_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT = 1807
const ERROR_NOLOGON_SERVER_TRUST_ACCOUNT = 1809
const ERROR_NOLOGON_WORKSTATION_TRUST_ACCOUNT = 1808
const ERROR_NONE_MAPPED = 1332
const ERROR_NONPAGED_SYSTEM_RESOURCES = 1451
const ERROR_NON_ACCOUNT_SID = 1257
const ERROR_NON_DOMAIN_SID = 1258
const ERROR_NON_MDICHILD_WINDOW = 1445
const ERROR_NOTIFY_ENUM_DIR = 1022
const ERROR_NOT_ALL_ASSIGNED = 1300
const ERROR_NOT_AUTHENTICATED = 1244
const ERROR_NOT_A_REPARSE_POINT = 4390
const ERROR_NOT_CHILD_WINDOW = 1442
const ERROR_NOT_CONNECTED = 2250
const ERROR_NOT_CONTAINER = 1207
const ERROR_NOT_DOS_DISK = 26
const ERROR_NOT_EMPTY = 4307
const ERROR_NOT_ENOUGH_MEMORY = 8
const ERROR_NOT_ENOUGH_QUOTA = 1816
const ERROR_NOT_ENOUGH_SERVER_MEMORY = 1130
const ERROR_NOT_EXPORT_FORMAT = 6008
const ERROR_NOT_FOUND = 1168
const ERROR_NOT_GUI_PROCESS = 1471
const ERROR_NOT_JOINED = 136
const ERROR_NOT_LOCKED = 158
const ERROR_NOT_LOGGED_ON = 1245
const ERROR_NOT_LOGON_PROCESS = 1362
const ERROR_NOT_OWNER = 288
const ERROR_NOT_QUORUM_CAPABLE = 5021
const ERROR_NOT_QUORUM_CLASS = 5025
const ERROR_NOT_READY = 21
const ERROR_NOT_REGISTRY_FILE = 1017
const ERROR_NOT_SAFEBOOT_SERVICE = 1084
const ERROR_NOT_SAME_DEVICE = 17
const ERROR_NOT_SUBSTED = 137
const ERROR_NOT_SUPPORTED = 50
const ERROR_NOT_SUPPORTED_ON_SBS = 1254
const ERROR_NOT_SUPPORTED_ON_STANDARD_SERVER = 8584
const ERROR_NO_ASSOCIATION = 1155
const ERROR_NO_BROWSER_SERVERS_FOUND = 6118
const ERROR_NO_DATA = 232
const ERROR_NO_DATA_DETECTED = 1104
const ERROR_NO_EFS = 6004
const ERROR_NO_IMPERSONATION_TOKEN = 1309
const ERROR_NO_INHERITANCE = 1391
const ERROR_NO_LOGON_SERVERS = 1311
const ERROR_NO_LOG_SPACE = 1019
const ERROR_NO_MATCH = 1169
const ERROR_NO_MEDIA_IN_DRIVE = 1112
const ERROR_NO_MORE_DEVICES = 1248
const ERROR_NO_MORE_FILES = 18
const ERROR_NO_MORE_ITEMS = 259
const ERROR_NO_MORE_SEARCH_HANDLES = 113
const ERROR_NO_MORE_USER_HANDLES = 1158
const ERROR_NO_NETWORK = 1222
const ERROR_NO_NET_OR_BAD_PATH = 1203
const ERROR_NO_NVRAM_RESOURCES = 1470
const ERROR_NO_PROC_SLOTS = 89
const ERROR_NO_PROMOTION_ACTIVE = 8222
const ERROR_NO_QUOTAS_FOR_ACCOUNT = 1302
const ERROR_NO_RECOVERY_POLICY = 6003
const ERROR_NO_RECOVERY_PROGRAM = 1082
const ERROR_NO_SCROLLBARS = 1447
const ERROR_NO_SECURITY_ON_OBJECT = 1350
const ERROR_NO_SHUTDOWN_IN_PROGRESS = 1116
const ERROR_NO_SIGNAL_SENT = 205
const ERROR_NO_SITENAME = 1919
const ERROR_NO_SPOOL_SPACE = 62
const ERROR_NO_SUCH_ALIAS = 1376
const ERROR_NO_SUCH_DOMAIN = 1355
const ERROR_NO_SUCH_GROUP = 1319
const ERROR_NO_SUCH_LOGON_SESSION = 1312
const ERROR_NO_SUCH_MEMBER = 1387
const ERROR_NO_SUCH_PACKAGE = 1364
const ERROR_NO_SUCH_PRIVILEGE = 1313
const ERROR_NO_SUCH_SITE = 1249
const ERROR_NO_SUCH_USER = 1317
const ERROR_NO_SUPPORTING_DRIVES = 4339
const ERROR_NO_SYSTEM_MENU = 1437
const ERROR_NO_SYSTEM_RESOURCES = 1450
const ERROR_NO_TOKEN = 1008
const ERROR_NO_TRACKING_SERVICE = 1172
const ERROR_NO_TRUST_LSA_SECRET = 1786
const ERROR_NO_TRUST_SAM_ACCOUNT = 1787
const ERROR_NO_UNICODE_TRANSLATION = 1113
const ERROR_NO_USER_KEYS = 6006
const ERROR_NO_USER_SESSION_KEY = 1394
const ERROR_NO_VOLUME_ID = 1173
const ERROR_NO_VOLUME_LABEL = 125
const ERROR_NO_WILDCARD_CHARACTERS = 1417
const ERROR_NT_CROSS_ENCRYPTION_REQUIRED = 1386
const ERROR_NULL_LM_PASSWORD = 1304
const ERROR_OBJECT_ALREADY_EXISTS = 5010
const ERROR_OBJECT_IN_LIST = 5011
const ERROR_OBJECT_NOT_EXTERNALLY_BACKED = 342
const ERROR_OBJECT_NOT_FOUND = 4312
const ERROR_OLD_WIN_VERSION = 1150
const ERROR_ONLY_IF_CONNECTED = 1251
const ERROR_OPEN_FAILED = 110
const ERROR_OPEN_FILES = 2401
const ERROR_OPERATION_ABORTED = 995
const ERROR_OPLOCK_NOT_GRANTED = 300
const ERROR_OUTOFMEMORY = 14
const ERROR_OUT_OF_PAPER = 28
const ERROR_OUT_OF_STRUCTURES = 84
const ERROR_OVERRIDE_NOCHANGES = 1252
const ERROR_PACKAGES_IN_USE = 15618
const ERROR_PACKAGE_ALREADY_EXISTS = 15611
const ERROR_PACKAGE_REPOSITORY_CORRUPTED = 15614
const ERROR_PACKAGE_UPDATING = 15616
const ERROR_PAGED_SYSTEM_RESOURCES = 1452
const ERROR_PAGEFILE_QUOTA = 1454
const ERROR_PARAMETER_QUOTA_EXCEEDED = 1283
const ERROR_PARTIAL_COPY = 299
const ERROR_PARTITION_FAILURE = 1105
const ERROR_PASSWORD_EXPIRED = 1330
const ERROR_PASSWORD_MUST_CHANGE = 1907
const ERROR_PASSWORD_RESTRICTION = 1325
const ERROR_PATCH_PACKAGE_INVALID = 1636
const ERROR_PATCH_PACKAGE_OPEN_FAILED = 1635
const ERROR_PATCH_PACKAGE_REJECTED = 1643
const ERROR_PATCH_PACKAGE_UNSUPPORTED = 1637
const ERROR_PATCH_TARGET_NOT_FOUND = 1642
const ERROR_PATH_BUSY = 148
const ERROR_PATH_NOT_FOUND = 3
const ERROR_PER_USER_TRUST_QUOTA_EXCEEDED = 1932
const ERROR_PIPE_BUSY = 231
const ERROR_PIPE_CONNECTED = 535
const ERROR_PIPE_LISTENING = 536
const ERROR_PIPE_LOCAL = 229
const ERROR_PIPE_NOT_CONNECTED = 233
const ERROR_PKINIT_FAILURE = 1263
const ERROR_POINT_NOT_FOUND = 1171
const ERROR_POLICY_OBJECT_NOT_FOUND = 8219
const ERROR_POLICY_ONLY_IN_DS = 8220
const ERROR_POPUP_ALREADY_ACTIVE = 1446
const ERROR_PORT_UNREACHABLE = 1234
const ERROR_POSSIBLE_DEADLOCK = 1131
const ERROR_POTENTIAL_FILE_FOUND = 1180
const ERROR_PRINTER_ALREADY_EXISTS = 1802
const ERROR_PRINTER_DELETED = 1905
const ERROR_PRINTER_DRIVER_ALREADY_INSTALLED = 1795
const ERROR_PRINTER_DRIVER_BLOCKED = 3014
const ERROR_PRINTER_DRIVER_IN_USE = 3001
const ERROR_PRINTER_DRIVER_WARNED = 3013
const ERROR_PRINTER_HAS_JOBS_QUEUED = 3009
const ERROR_PRINTER_NOT_FOUND = 3012
const ERROR_PRINTQ_FULL = 61
const ERROR_PRINT_CANCELLED = 63
const ERROR_PRINT_MONITOR_ALREADY_INSTALLED = 3006
const ERROR_PRINT_MONITOR_IN_USE = 3008
const ERROR_PRINT_PROCESSOR_ALREADY_INSTALLED = 3005
const ERROR_PRIVATE_DIALOG_INDEX = 1415
const ERROR_PRIVILEGE_NOT_HELD = 1314
const ERROR_PROCESS_ABORTED = 1067
const ERROR_PROC_NOT_FOUND = 127
const ERROR_PRODUCT_UNINSTALLED = 1614
const ERROR_PRODUCT_VERSION = 1638
const ERROR_PROFILE_NOT_ASSOCIATED_WITH_DEVICE = 2015
const ERROR_PROFILE_NOT_FOUND = 2016
const ERROR_PROMOTION_ACTIVE = 8221
const ERROR_PROTOCOL_UNREACHABLE = 1233
const ERROR_QUORUMLOG_OPEN_FAILED = 5028
const ERROR_QUORUM_DISK_NOT_FOUND = 5086
const ERROR_QUORUM_OWNER_ALIVE = 5034
const ERROR_QUORUM_RESOURCE = 5020
const ERROR_QUORUM_RESOURCE_ONLINE_FAILED = 5027
const ERROR_READ_FAULT = 30
const ERROR_RECOVERY_FAILURE = 1279
const ERROR_RECOVERY_FILE_CORRUPT = 15619
const ERROR_REC_NON_EXISTENT = 4005
const ERROR_REDIRECTOR_HAS_OPEN_HANDLES = 1794
const ERROR_REDIR_PAUSED = 72
const ERROR_REGISTRY_CORRUPT = 1015
const ERROR_REGISTRY_IO_FAILED = 1016
const ERROR_REGISTRY_RECOVERED = 1014
const ERROR_REG_NAT_CONSUMPTION = 1261
const ERROR_RELOC_CHAIN_XEEDS_SEGLIM = 201
const ERROR_REMOTE_PRINT_CONNECTIONS_BLOCKED = 1936
const ERROR_REMOTE_SESSION_LIMIT_EXCEEDED = 1220
const ERROR_REMOTE_STORAGE_MEDIA_ERROR = 4352
const ERROR_REMOTE_STORAGE_NOT_ACTIVE = 4351
const ERROR_REMOVE_FAILED = 15610
const ERROR_REM_NOT_LIST = 51
const ERROR_REPARSE_ATTRIBUTE_CONFLICT = 4391
const ERROR_REPARSE_TAG_INVALID = 4393
const ERROR_REPARSE_TAG_MISMATCH = 4394
const ERROR_REQUEST_ABORTED = 1235
const ERROR_REQUEST_REFUSED = 4320
const ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION = 1459
const ERROR_REQ_NOT_ACCEP = 71
const ERROR_RESILIENCY_FILE_CORRUPT = 15625
const ERROR_RESMON_CREATE_FAILED = 5017
const ERROR_RESMON_INVALID_STATE = 5084
const ERROR_RESMON_ONLINE_FAILED = 5018
const ERROR_RESOURCE_DATA_NOT_FOUND = 1812
const ERROR_RESOURCE_DISABLED = 4309
const ERROR_RESOURCE_ENUM_USER_STOP = 15106
const ERROR_RESOURCE_FAILED = 5038
const ERROR_RESOURCE_LANG_NOT_FOUND = 1815
const ERROR_RESOURCE_NAME_NOT_FOUND = 1814
const ERROR_RESOURCE_NOT_AVAILABLE = 5006
const ERROR_RESOURCE_NOT_FOUND = 5007
const ERROR_RESOURCE_NOT_ONLINE = 5004
const ERROR_RESOURCE_NOT_PRESENT = 4316
const ERROR_RESOURCE_ONLINE = 5019
const ERROR_RESOURCE_PROPERTIES_STORED = 5024
const ERROR_RESOURCE_PROPERTY_UNCHANGEABLE = 5089
const ERROR_RESOURCE_TYPE_NOT_FOUND = 1813
const ERROR_RESTART_APPLICATION = 1467
const ERROR_RETRY = 1237
const ERROR_REVISION_MISMATCH = 1306
const ERROR_RING2SEG_MUST_BE_MOVABLE = 200
const ERROR_RING2_STACK_IN_USE = 207
const ERROR_RMODE_APP = 1153
const ERROR_RPL_NOT_ALLOWED = 4006
const ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT = 15403
const ERROR_RUNLEVEL_SWITCH_IN_PROGRESS = 15404
const ERROR_RUNLEVEL_SWITCH_TIMEOUT = 15402
const ERROR_RXACT_COMMIT_FAILURE = 1370
const ERROR_RXACT_INVALID_STATE = 1369
const ERROR_SAME_DRIVE = 143
const ERROR_SAM_INIT_FAILURE = 8541
const ERROR_SCOPE_NOT_FOUND = 318
const ERROR_SCREEN_ALREADY_LOCKED = 1440
const ERROR_SECONDARY_IC_PROVIDER_NOT_REGISTERED = 15321
const ERROR_SECRET_TOO_LONG = 1382
const ERROR_SECTOR_NOT_FOUND = 27
const ERROR_SEEK = 25
const ERROR_SEEK_ON_DEVICE = 132
const ERROR_SEM_IS_SET = 102
const ERROR_SEM_NOT_FOUND = 187
const ERROR_SEM_OWNER_DIED = 105
const ERROR_SEM_TIMEOUT = 121
const ERROR_SEM_USER_LIMIT = 106
const ERROR_SERIAL_NO_DEVICE = 1118
const ERROR_SERVER_DISABLED = 1341
const ERROR_SERVER_HAS_OPEN_HANDLES = 1811
const ERROR_SERVER_NOT_DISABLED = 1342
const ERROR_SERVER_SHUTDOWN_IN_PROGRESS = 1255
const ERROR_SERVICES_FAILED_AUTOSTART = 15405
const ERROR_SERVICE_ALREADY_RUNNING = 1056
const ERROR_SERVICE_CANNOT_ACCEPT_CTRL = 1061
const ERROR_SERVICE_DATABASE_LOCKED = 1055
const ERROR_SERVICE_DEPENDENCY_DELETED = 1075
const ERROR_SERVICE_DEPENDENCY_FAIL = 1068
const ERROR_SERVICE_DISABLED = 1058
const ERROR_SERVICE_DOES_NOT_EXIST = 1060
const ERROR_SERVICE_EXISTS = 1073
const ERROR_SERVICE_LOGON_FAILED = 1069
const ERROR_SERVICE_MARKED_FOR_DELETE = 1072
const ERROR_SERVICE_NEVER_STARTED = 1077
const ERROR_SERVICE_NOT_ACTIVE = 1062
const ERROR_SERVICE_NOT_FOUND = 1243
const ERROR_SERVICE_NOT_IN_EXE = 1083
const ERROR_SERVICE_NO_THREAD = 1054
const ERROR_SERVICE_REQUEST_TIMEOUT = 1053
const ERROR_SERVICE_SPECIFIC_ERROR = 1066
const ERROR_SERVICE_START_HANG = 1070
const ERROR_SESSION_CREDENTIAL_CONFLICT = 1219
const ERROR_SETCOUNT_ON_BAD_LB = 1433
const ERROR_SETMARK_DETECTED = 1103
const ERROR_SET_NOT_FOUND = 1170
const ERROR_SET_POWER_STATE_FAILED = 1141
const ERROR_SET_POWER_STATE_VETOED = 1140
const ERROR_SEVERITY_ERROR = 3221225472
const ERROR_SEVERITY_INFORMATIONAL = 1073741824
const ERROR_SEVERITY_SUCCESS = 0
const ERROR_SEVERITY_WARNING = 2147483648
const ERROR_SHARED_POLICY = 8218
const ERROR_SHARING_BUFFER_EXCEEDED = 36
const ERROR_SHARING_PAUSED = 70
const ERROR_SHARING_VIOLATION = 32
const ERROR_SHUTDOWN_CLUSTER = 5008
const ERROR_SHUTDOWN_IN_PROGRESS = 1115
const ERROR_SIGNAL_PENDING = 162
const ERROR_SIGNAL_REFUSED = 156
const ERROR_SINGLE_INSTANCE_APP = 1152
const ERROR_SLOT_NOT_PRESENT = 4
const ERROR_SMARTCARD_SUBSYSTEM_FAILURE = 1264
const ERROR_SMI_PRIMITIVE_INSTALLER_FAILED = 14108
const ERROR_SOME_NOT_MAPPED = 1301
const ERROR_SOURCE_ELEMENT_EMPTY = 1160
const ERROR_SPECIAL_ACCOUNT = 1371
const ERROR_SPECIAL_GROUP = 1372
const ERROR_SPECIAL_USER = 1373
const ERROR_SPL_NO_ADDJOB = 3004
const ERROR_SPL_NO_STARTDOC = 3003
const ERROR_SPOOL_FILE_NOT_FOUND = 3002
const ERROR_STACK_BUFFER_OVERRUN = 1282
const ERROR_STACK_OVERFLOW = 1001
const ERROR_STATE_COMPOSITE_SETTING_VALUE_SIZE_LIMIT_EXCEEDED = 15815
const ERROR_STATE_CONTAINER_NAME_SIZE_LIMIT_EXCEEDED = 15818
const ERROR_STATE_CREATE_CONTAINER_FAILED = 15805
const ERROR_STATE_DELETE_CONTAINER_FAILED = 15806
const ERROR_STATE_DELETE_SETTING_FAILED = 15809
const ERROR_STATE_ENUMERATE_CONTAINER_FAILED = 15813
const ERROR_STATE_ENUMERATE_SETTINGS_FAILED = 15814
const ERROR_STATE_GET_VERSION_FAILED = 15801
const ERROR_STATE_LOAD_STORE_FAILED = 15800
const ERROR_STATE_OPEN_CONTAINER_FAILED = 15804
const ERROR_STATE_QUERY_SETTING_FAILED = 15810
const ERROR_STATE_READ_COMPOSITE_SETTING_FAILED = 15811
const ERROR_STATE_READ_SETTING_FAILED = 15807
const ERROR_STATE_SETTING_NAME_SIZE_LIMIT_EXCEEDED = 15817
const ERROR_STATE_SETTING_VALUE_SIZE_LIMIT_EXCEEDED = 15816
const ERROR_STATE_SET_VERSION_FAILED = 15802
const ERROR_STATE_STRUCTURED_RESET_FAILED = 15803
const ERROR_STATE_WRITE_COMPOSITE_SETTING_FAILED = 15812
const ERROR_STATE_WRITE_SETTING_FAILED = 15808
const ERROR_STATIC_INIT = 4002
const ERROR_SUBST_TO_JOIN = 141
const ERROR_SUBST_TO_SUBST = 139
const ERROR_SUCCESS = 0
const ERROR_SUCCESS_REBOOT_INITIATED = 1641
const ERROR_SUCCESS_REBOOT_REQUIRED = 3010
const ERROR_SUCCESS_RESTART_REQUIRED = 3011
const ERROR_SWAPERROR = 999
const ERROR_SXS_ACTIVATION_CONTEXT_DISABLED = 14006
const ERROR_SXS_ASSEMBLY_IS_NOT_A_DEPLOYMENT = 14103
const ERROR_SXS_ASSEMBLY_MISSING = 14081
const ERROR_SXS_ASSEMBLY_NOT_FOUND = 14003
const ERROR_SXS_ASSEMBLY_NOT_LOCKED = 14097
const ERROR_SXS_CANT_GEN_ACTCTX = 14001
const ERROR_SXS_COMPONENT_STORE_CORRUPT = 14098
const ERROR_SXS_CORRUPTION = 14083
const ERROR_SXS_CORRUPT_ACTIVATION_STACK = 14082
const ERROR_SXS_DUPLICATE_ASSEMBLY_NAME = 14027
const ERROR_SXS_DUPLICATE_CLSID = 14023
const ERROR_SXS_DUPLICATE_DLL_NAME = 14021
const ERROR_SXS_DUPLICATE_IID = 14024
const ERROR_SXS_DUPLICATE_PROGID = 14026
const ERROR_SXS_DUPLICATE_TLBID = 14025
const ERROR_SXS_DUPLICATE_WINDOWCLASS_NAME = 14022
const ERROR_SXS_EARLY_DEACTIVATION = 14084
const ERROR_SXS_FILE_HASH_MISMATCH = 14028
const ERROR_SXS_FILE_HASH_MISSING = 14110
const ERROR_SXS_FILE_NOT_PART_OF_ASSEMBLY = 14104
const ERROR_SXS_IDENTITIES_DIFFERENT = 14102
const ERROR_SXS_IDENTITY_DUPLICATE_ATTRIBUTE = 14092
const ERROR_SXS_IDENTITY_PARSE_ERROR = 14093
const ERROR_SXS_INCORRECT_PUBLIC_KEY_TOKEN = 14095
const ERROR_SXS_INVALID_ACTCTXDATA_FORMAT = 14002
const ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE = 14017
const ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE_NAME = 14080
const ERROR_SXS_INVALID_DEACTIVATION = 14085
const ERROR_SXS_INVALID_IDENTITY_ATTRIBUTE_NAME = 14091
const ERROR_SXS_INVALID_IDENTITY_ATTRIBUTE_VALUE = 14090
const ERROR_SXS_INVALID_XML_NAMESPACE_URI = 14014
const ERROR_SXS_KEY_NOT_FOUND = 14007
const ERROR_SXS_LEAF_MANIFEST_DEPENDENCY_NOT_INSTALLED = 14016
const ERROR_SXS_MANIFEST_FORMAT_ERROR = 14004
const ERROR_SXS_MANIFEST_IDENTITY_SAME_BUT_CONTENTS_DIFFERENT = 14101
const ERROR_SXS_MANIFEST_INVALID_REQUIRED_DEFAULT_NAMESPACE = 14019
const ERROR_SXS_MANIFEST_MISSING_REQUIRED_DEFAULT_NAMESPACE = 14018
const ERROR_SXS_MANIFEST_PARSE_ERROR = 14005
const ERROR_SXS_MANIFEST_TOO_BIG = 14105
const ERROR_SXS_MISSING_ASSEMBLY_IDENTITY_ATTRIBUTE = 14079
const ERROR_SXS_MULTIPLE_DEACTIVATION = 14086
const ERROR_SXS_POLICY_PARSE_ERROR = 14029
const ERROR_SXS_PRIVATE_MANIFEST_CROSS_PATH_WITH_REPARSE_POINT = 14020
const ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET = 14011
const ERROR_SXS_PROCESS_TERMINATION_REQUESTED = 14087
const ERROR_SXS_PROTECTION_CATALOG_FILE_MISSING = 14078
const ERROR_SXS_PROTECTION_CATALOG_NOT_VALID = 14076
const ERROR_SXS_PROTECTION_PUBLIC_KEY_TOO_SHORT = 14075
const ERROR_SXS_PROTECTION_RECOVERY_FAILED = 14074
const ERROR_SXS_RELEASE_ACTIVATION_CONTEXT = 14088
const ERROR_SXS_ROOT_MANIFEST_DEPENDENCY_NOT_INSTALLED = 14015
const ERROR_SXS_SECTION_NOT_FOUND = 14000
const ERROR_SXS_SETTING_NOT_REGISTERED = 14106
const ERROR_SXS_SYSTEM_DEFAULT_ACTIVATION_CONTEXT_EMPTY = 14089
const ERROR_SXS_THREAD_QUERIES_DISABLED = 14010
const ERROR_SXS_TRANSACTION_CLOSURE_INCOMPLETE = 14107
const ERROR_SXS_UNKNOWN_ENCODING = 14013
const ERROR_SXS_UNKNOWN_ENCODING_GROUP = 14012
const ERROR_SXS_UNTRANSLATABLE_HRESULT = 14077
const ERROR_SXS_VERSION_CONFLICT = 14008
const ERROR_SXS_WRONG_SECTION_TYPE = 14009
const ERROR_SXS_XML_E_BADCHARDATA = 14036
const ERROR_SXS_XML_E_BADCHARINSTRING = 14034
const ERROR_SXS_XML_E_BADNAMECHAR = 14033
const ERROR_SXS_XML_E_BADPEREFINSUBSET = 14059
const ERROR_SXS_XML_E_BADSTARTNAMECHAR = 14032
const ERROR_SXS_XML_E_BADXMLCASE = 14069
const ERROR_SXS_XML_E_BADXMLDECL = 14056
const ERROR_SXS_XML_E_COMMENTSYNTAX = 14031
const ERROR_SXS_XML_E_DUPLICATEATTRIBUTE = 14053
const ERROR_SXS_XML_E_EXPECTINGCLOSEQUOTE = 14045
const ERROR_SXS_XML_E_EXPECTINGTAGEND = 14038
const ERROR_SXS_XML_E_INCOMPLETE_ENCODING = 14043
const ERROR_SXS_XML_E_INTERNALERROR = 14041
const ERROR_SXS_XML_E_INVALIDATROOTLEVEL = 14055
const ERROR_SXS_XML_E_INVALIDENCODING = 14067
const ERROR_SXS_XML_E_INVALIDSWITCH = 14068
const ERROR_SXS_XML_E_INVALID_DECIMAL = 14047
const ERROR_SXS_XML_E_INVALID_HEXIDECIMAL = 14048
const ERROR_SXS_XML_E_INVALID_STANDALONE = 14070
const ERROR_SXS_XML_E_INVALID_UNICODE = 14049
const ERROR_SXS_XML_E_INVALID_VERSION = 14072
const ERROR_SXS_XML_E_MISSINGEQUALS = 14073
const ERROR_SXS_XML_E_MISSINGQUOTE = 14030
const ERROR_SXS_XML_E_MISSINGROOT = 14057
const ERROR_SXS_XML_E_MISSINGSEMICOLON = 14039
const ERROR_SXS_XML_E_MISSINGWHITESPACE = 14037
const ERROR_SXS_XML_E_MISSING_PAREN = 14044
const ERROR_SXS_XML_E_MULTIPLEROOTS = 14054
const ERROR_SXS_XML_E_MULTIPLE_COLONS = 14046
const ERROR_SXS_XML_E_RESERVEDNAMESPACE = 14066
const ERROR_SXS_XML_E_UNBALANCEDPAREN = 14040
const ERROR_SXS_XML_E_UNCLOSEDCDATA = 14065
const ERROR_SXS_XML_E_UNCLOSEDCOMMENT = 14063
const ERROR_SXS_XML_E_UNCLOSEDDECL = 14064
const ERROR_SXS_XML_E_UNCLOSEDENDTAG = 14061
const ERROR_SXS_XML_E_UNCLOSEDSTARTTAG = 14060
const ERROR_SXS_XML_E_UNCLOSEDSTRING = 14062
const ERROR_SXS_XML_E_UNCLOSEDTAG = 14052
const ERROR_SXS_XML_E_UNEXPECTEDENDTAG = 14051
const ERROR_SXS_XML_E_UNEXPECTEDEOF = 14058
const ERROR_SXS_XML_E_UNEXPECTED_STANDALONE = 14071
const ERROR_SXS_XML_E_UNEXPECTED_WHITESPACE = 14042
const ERROR_SXS_XML_E_WHITESPACEORQUESTIONMARK = 14050
const ERROR_SXS_XML_E_XMLDECLSYNTAX = 14035
const ERROR_SYMLINK_CLASS_DISABLED = 1463
const ERROR_SYMLINK_NOT_SUPPORTED = 1464
const ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED = 1274
const ERROR_SYSTEM_DEVICE_NOT_FOUND = 15299
const ERROR_SYSTEM_NEEDS_REMEDIATION = 15623
const ERROR_SYSTEM_TRACE = 150
const ERROR_TAG_NOT_FOUND = 2012
const ERROR_TAG_NOT_PRESENT = 2013
const ERROR_THREAD_1_INACTIVE = 210
const ERROR_TIMEOUT = 1460
const ERROR_TIME_SKEW = 1398
const ERROR_TLW_WITH_WSCHILD = 1406
const ERROR_TOKEN_ALREADY_IN_USE = 1375
const ERROR_TOO_MANY_CMDS = 56
const ERROR_TOO_MANY_CONTEXT_IDS = 1384
const ERROR_TOO_MANY_LINKS = 1142
const ERROR_TOO_MANY_LUIDS_REQUESTED = 1333
const ERROR_TOO_MANY_MODULES = 214
const ERROR_TOO_MANY_MUXWAITERS = 152
const ERROR_TOO_MANY_NAMES = 68
const ERROR_TOO_MANY_OPEN_FILES = 4
const ERROR_TOO_MANY_POSTS = 298
const ERROR_TOO_MANY_SECRETS = 1381
const ERROR_TOO_MANY_SEMAPHORES = 100
const ERROR_TOO_MANY_SEM_REQUESTS = 103
const ERROR_TOO_MANY_SESS = 69
const ERROR_TOO_MANY_SIDS = 1389
const ERROR_TOO_MANY_TCBS = 155
const ERROR_TRANSFORM_NOT_SUPPORTED = 2004
const ERROR_TRANSPORT_FULL = 4328
const ERROR_TRAY_MALFUNCTION = 16
const ERROR_TRUSTED_DOMAIN_FAILURE = 1788
const ERROR_TRUSTED_RELATIONSHIP_FAILURE = 1789
const ERROR_TRUST_FAILURE = 1790
const ERROR_UNABLE_TO_CLEAN = 4311
const ERROR_UNABLE_TO_EJECT_MOUNTED_MEDIA = 4330
const ERROR_UNABLE_TO_INVENTORY_DRIVE = 4325
const ERROR_UNABLE_TO_INVENTORY_SLOT = 4326
const ERROR_UNABLE_TO_INVENTORY_TRANSPORT = 4327
const ERROR_UNABLE_TO_LOAD_MEDIUM = 4324
const ERROR_UNABLE_TO_LOCK_MEDIA = 1108
const ERROR_UNABLE_TO_MOVE_REPLACEMENT = 1176
const ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 = 1177
const ERROR_UNABLE_TO_REMOVE_REPLACED = 1175
const ERROR_UNABLE_TO_UNLOAD_MEDIA = 1109
const ERROR_UNEXPECTED_OMID = 4334
const ERROR_UNEXP_NET_ERR = 59
const ERROR_UNHANDLED_ERROR = 4294967295
const ERROR_UNIDENTIFIED_ERROR = 1287
const ERROR_UNKNOWN_COMPONENT = 1607
const ERROR_UNKNOWN_FEATURE = 1606
const ERROR_UNKNOWN_PORT = 1796
const ERROR_UNKNOWN_PRINTER_DRIVER = 1797
const ERROR_UNKNOWN_PRINTPROCESSOR = 1798
const ERROR_UNKNOWN_PRINT_MONITOR = 3000
const ERROR_UNKNOWN_PRODUCT = 1605
const ERROR_UNKNOWN_PROPERTY = 1608
const ERROR_UNKNOWN_REVISION = 1305
const ERROR_UNMAPPED_SUBSTITUTION_STRING = 14096
const ERROR_UNRECOGNIZED_MEDIA = 1785
const ERROR_UNRECOGNIZED_VOLUME = 1005
const ERROR_UNSUPPORTED_TYPE = 1630
const ERROR_USER_APC = 737
const ERROR_USER_DELETE_TRUST_QUOTA_EXCEEDED = 1934
const ERROR_USER_EXISTS = 1316
const ERROR_USER_MAPPED_FILE = 1224
const ERROR_VC_DISCONNECTED = 240
const ERROR_VDM_DISALLOWED = 1286
const ERROR_VOLUME_CONTAINS_SYS_FILES = 4337
const ERROR_VOLUME_NOT_SIS_ENABLED = 4500
const ERROR_VOLUME_NOT_SUPPORT_EFS = 6014
const ERROR_WAIT_1 = 731
const ERROR_WAIT_2 = 732
const ERROR_WAIT_3 = 733
const ERROR_WAIT_63 = 734
const ERROR_WAIT_NO_CHILDREN = 128
const ERROR_WAKE_SYSTEM = 730
const ERROR_WINDOW_NOT_COMBOBOX = 1423
const ERROR_WINDOW_NOT_DIALOG = 1420
const ERROR_WINDOW_OF_OTHER_THREAD = 1408
const ERROR_WINS_INTERNAL = 4000
const ERROR_WMI_ALREADY_DISABLED = 4212
const ERROR_WMI_ALREADY_ENABLED = 4206
const ERROR_WMI_DP_FAILED = 4209
const ERROR_WMI_DP_NOT_FOUND = 4204
const ERROR_WMI_GUID_DISCONNECTED = 4207
const ERROR_WMI_GUID_NOT_FOUND = 4200
const ERROR_WMI_INSTANCE_NOT_FOUND = 4201
const ERROR_WMI_INVALID_MOF = 4210
const ERROR_WMI_INVALID_REGINFO = 4211
const ERROR_WMI_ITEMID_NOT_FOUND = 4202
const ERROR_WMI_READ_ONLY = 4213
const ERROR_WMI_SERVER_UNAVAILABLE = 4208
const ERROR_WMI_SET_FAILURE = 4214
const ERROR_WMI_TRY_AGAIN = 4203
const ERROR_WMI_UNRESOLVED_INSTANCE_REF = 4205
const ERROR_WORKING_SET_QUOTA = 1453
const ERROR_WRITE_FAULT = 29
const ERROR_WRITE_PROTECT = 19
const ERROR_WRONG_COMPARTMENT = 1468
const ERROR_WRONG_DISK = 34
const ERROR_WRONG_EFS = 6005
const ERROR_WRONG_PASSWORD = 1323
const ERROR_WRONG_TARGET_NAME = 1396
const ERROR_XMLDSIG_ERROR = 1466
const ERROR_XML_ENCODING_MISMATCH = 14100
const ERROR_XML_PARSE_ERROR = 1465
const ESB_DISABLE_BOTH = 3
const ESB_DISABLE_DOWN = 2
const ESB_DISABLE_LEFT = 1
const ESB_DISABLE_LTUP = 1
const ESB_DISABLE_RIGHT = 2
const ESB_DISABLE_RTDN = 2
const ESB_DISABLE_UP = 1
const ESB_ENABLE_BOTH = 0
const ESPIPE = 29
const ESRCH = 3
const ES_AUTOHSCROLL = 128
const ES_AUTOVSCROLL = 64
const ES_CENTER = 1
const ES_LEFT = 0
const ES_LOWERCASE = 16
const ES_MULTILINE = 4
const ES_NOHIDESEL = 256
const ES_NUMBER = 8192
const ES_OEMCONVERT = 1024
const ES_PASSWORD = 32
const ES_READONLY = 2048
const ES_RIGHT = 2
const ES_UPPERCASE = 8
const ES_WANTRETURN = 4096
const ETIME = 137
const ETIMEDOUT = 138
const ETO_CLIPPED = 4
const ETO_GLYPH_INDEX = 16
const ETO_IGNORELANGUAGE = 4096
const ETO_NUMERICSLATIN = 2048
const ETO_NUMERICSLOCAL = 1024
const ETO_OPAQUE = 2
const ETO_PDY = 8192
const ETO_REVERSE_INDEX_MAP = 65536
const ETO_RTLREADING = 128
const ETXTBSY = 139
const EU4_EXPR = 2
const EU4_IDX = 1
const EU4_NONE = 0
const EVENPARITY = 2
const EVENTLOG_AUDIT_FAILURE = 16
const EVENTLOG_AUDIT_SUCCESS = 8
const EVENTLOG_BACKWARDS_READ = 8
const EVENTLOG_END_ALL_PAIRED_EVENTS = 4
const EVENTLOG_END_PAIRED_EVENT = 2
const EVENTLOG_ERROR_TYPE = 1
const EVENTLOG_FORWARDS_READ = 4
const EVENTLOG_FULL_INFO = 0
const EVENTLOG_INFORMATION_TYPE = 4
const EVENTLOG_PAIRED_EVENT_ACTIVE = 8
const EVENTLOG_PAIRED_EVENT_INACTIVE = 16
const EVENTLOG_SEEK_READ = 2
const EVENTLOG_SEQUENTIAL_READ = 1
const EVENTLOG_START_PAIRED_EVENT = 1
const EVENTLOG_SUCCESS = 0
const EVENTLOG_WARNING_TYPE = 2
const EVENT_AIA_END = 45055
const EVENT_AIA_START = 40960
const EVENT_ALL_ACCESS = 2031619
const EVENT_CONSOLE_CARET = 16385
const EVENT_CONSOLE_END = 16639
const EVENT_CONSOLE_END_APPLICATION = 16391
const EVENT_CONSOLE_LAYOUT = 16389
const EVENT_CONSOLE_START_APPLICATION = 16390
const EVENT_CONSOLE_UPDATE_REGION = 16386
const EVENT_CONSOLE_UPDATE_SCROLL = 16388
const EVENT_CONSOLE_UPDATE_SIMPLE = 16387
const EVENT_E_FIRST = 2147746304
const EVENT_E_LAST = 2147746335
const EVENT_MAX = 2147483647
const EVENT_MIN = 1
const EVENT_MODIFY_STATE = 2
const EVENT_OBJECT_ACCELERATORCHANGE = 32786
const EVENT_OBJECT_CLOAKED = 32791
const EVENT_OBJECT_CONTENTSCROLLED = 32789
const EVENT_OBJECT_CREATE = 32768
const EVENT_OBJECT_DEFACTIONCHANGE = 32785
const EVENT_OBJECT_DESCRIPTIONCHANGE = 32781
const EVENT_OBJECT_DESTROY = 32769
const EVENT_OBJECT_DRAGCANCEL = 32802
const EVENT_OBJECT_DRAGCOMPLETE = 32803
const EVENT_OBJECT_DRAGDROPPED = 32806
const EVENT_OBJECT_DRAGENTER = 32804
const EVENT_OBJECT_DRAGLEAVE = 32805
const EVENT_OBJECT_DRAGSTART = 32801
const EVENT_OBJECT_END = 33023
const EVENT_OBJECT_FOCUS = 32773
const EVENT_OBJECT_HELPCHANGE = 32784
const EVENT_OBJECT_HIDE = 32771
const EVENT_OBJECT_HOSTEDOBJECTSINVALIDATED = 32800
const EVENT_OBJECT_IME_CHANGE = 32809
const EVENT_OBJECT_IME_HIDE = 32808
const EVENT_OBJECT_IME_SHOW = 32807
const EVENT_OBJECT_INVOKED = 32787
const EVENT_OBJECT_LIVEREGIONCHANGED = 32793
const EVENT_OBJECT_LOCATIONCHANGE = 32779
const EVENT_OBJECT_NAMECHANGE = 32780
const EVENT_OBJECT_PARENTCHANGE = 32783
const EVENT_OBJECT_REORDER = 32772
const EVENT_OBJECT_SELECTION = 32774
const EVENT_OBJECT_SELECTIONADD = 32775
const EVENT_OBJECT_SELECTIONREMOVE = 32776
const EVENT_OBJECT_SELECTIONWITHIN = 32777
const EVENT_OBJECT_SHOW = 32770
const EVENT_OBJECT_STATECHANGE = 32778
const EVENT_OBJECT_TEXTSELECTIONCHANGED = 32788
const EVENT_OBJECT_UNCLOAKED = 32792
const EVENT_OBJECT_VALUECHANGE = 32782
const EVENT_OEM_DEFINED_END = 511
const EVENT_OEM_DEFINED_START = 257
const EVENT_SYSTEM_ALERT = 2
const EVENT_SYSTEM_ARRANGMENTPREVIEW = 32790
const EVENT_SYSTEM_CAPTUREEND = 9
const EVENT_SYSTEM_CAPTURESTART = 8
const EVENT_SYSTEM_CONTEXTHELPEND = 13
const EVENT_SYSTEM_CONTEXTHELPSTART = 12
const EVENT_SYSTEM_DESKTOPSWITCH = 32
const EVENT_SYSTEM_DIALOGEND = 17
const EVENT_SYSTEM_DIALOGSTART = 16
const EVENT_SYSTEM_DRAGDROPEND = 15
const EVENT_SYSTEM_DRAGDROPSTART = 14
const EVENT_SYSTEM_END = 255
const EVENT_SYSTEM_FOREGROUND = 3
const EVENT_SYSTEM_IME_KEY_NOTIFICATION = 41
const EVENT_SYSTEM_MENUEND = 5
const EVENT_SYSTEM_MENUPOPUPEND = 7
const EVENT_SYSTEM_MENUPOPUPSTART = 6
const EVENT_SYSTEM_MENUSTART = 4
const EVENT_SYSTEM_MINIMIZEEND = 23
const EVENT_SYSTEM_MINIMIZESTART = 22
const EVENT_SYSTEM_MOVESIZEEND = 11
const EVENT_SYSTEM_MOVESIZESTART = 10
const EVENT_SYSTEM_SCROLLINGEND = 19
const EVENT_SYSTEM_SCROLLINGSTART = 18
const EVENT_SYSTEM_SOUND = 1
const EVENT_SYSTEM_SWITCHEND = 21
const EVENT_SYSTEM_SWITCHER_APPDROPPED = 38
const EVENT_SYSTEM_SWITCHER_APPGRABBED = 36
const EVENT_SYSTEM_SWITCHER_APPOVERTARGET = 37
const EVENT_SYSTEM_SWITCHER_CANCELLED = 39
const EVENT_SYSTEM_SWITCHSTART = 20
const EVENT_S_FIRST = 262656
const EVENT_S_LAST = 262687
const EVENT_UIA_EVENTID_END = 20223
const EVENT_UIA_EVENTID_START = 19968
const EVENT_UIA_PROPID_END = 30207
const EVENT_UIA_PROPID_START = 29952
const EV_BREAK = 64
const EV_CTS = 8
const EV_DSR = 16
const EV_ERR = 128
const EV_EVENT1 = 2048
const EV_EVENT2 = 4096
const EV_PERR = 512
const EV_RING = 256
const EV_RLSD = 32
const EV_RX80FULL = 1024
const EV_RXCHAR = 1
const EV_RXFLAG = 2
const EV_TXEMPTY = 4
const EWOULDBLOCK = 140
const EWX_ARSO = 67108864
const EWX_BOOTOPTIONS = 16777216
const EWX_CHECK_SAFE_FOR_SERVER = 134217728
const EWX_FORCE = 4
const EWX_FORCEIFHUNG = 16
const EWX_HYBRID_SHUTDOWN = 4194304
const EWX_LOGOFF = 0
const EWX_POWEROFF = 8
const EWX_QUICKRESOLVE = 32
const EWX_REBOOT = 2
const EWX_RESTARTAPPS = 64
const EWX_SHUTDOWN = 1
const EXCEPTION_ACCESS_VIOLATION = "STATUS_ACCESS_VIOLATION"
const EXCEPTION_ARRAY_BOUNDS_EXCEEDED = "STATUS_ARRAY_BOUNDS_EXCEEDED"
const EXCEPTION_BREAKPOINT = "STATUS_BREAKPOINT"
const EXCEPTION_COLLIDED_UNWIND = 64
const EXCEPTION_CONTINUE_EXECUTION = -1
const EXCEPTION_CONTINUE_SEARCH = 0
const EXCEPTION_DATATYPE_MISALIGNMENT = "STATUS_DATATYPE_MISALIGNMENT"
const EXCEPTION_DEBUG_EVENT = 1
const EXCEPTION_DISPOSITION = 0
const EXCEPTION_EXECUTE_FAULT = 8
const EXCEPTION_EXECUTE_HANDLER = 1
const EXCEPTION_EXIT_UNWIND = 4
const EXCEPTION_FLT_DENORMAL_OPERAND = "STATUS_FLOAT_DENORMAL_OPERAND"
const EXCEPTION_FLT_DIVIDE_BY_ZERO = "STATUS_FLOAT_DIVIDE_BY_ZERO"
const EXCEPTION_FLT_INEXACT_RESULT = "STATUS_FLOAT_INEXACT_RESULT"
const EXCEPTION_FLT_INVALID_OPERATION = "STATUS_FLOAT_INVALID_OPERATION"
const EXCEPTION_FLT_OVERFLOW = "STATUS_FLOAT_OVERFLOW"
const EXCEPTION_FLT_STACK_CHECK = "STATUS_FLOAT_STACK_CHECK"
const EXCEPTION_FLT_UNDERFLOW = "STATUS_FLOAT_UNDERFLOW"
const EXCEPTION_GUARD_PAGE = "STATUS_GUARD_PAGE_VIOLATION"
const EXCEPTION_ILLEGAL_INSTRUCTION = "STATUS_ILLEGAL_INSTRUCTION"
const EXCEPTION_INT_DIVIDE_BY_ZERO = "STATUS_INTEGER_DIVIDE_BY_ZERO"
const EXCEPTION_INT_OVERFLOW = "STATUS_INTEGER_OVERFLOW"
const EXCEPTION_INVALID_DISPOSITION = "STATUS_INVALID_DISPOSITION"
const EXCEPTION_INVALID_HANDLE = "STATUS_INVALID_HANDLE"
const EXCEPTION_IN_PAGE_ERROR = "STATUS_IN_PAGE_ERROR"
const EXCEPTION_MAXIMUM_PARAMETERS = 15
const EXCEPTION_NESTED_CALL = 16
const EXCEPTION_NONCONTINUABLE = 1
const EXCEPTION_NONCONTINUABLE_EXCEPTION = "STATUS_NONCONTINUABLE_EXCEPTION"
const EXCEPTION_POSSIBLE_DEADLOCK = 0
const EXCEPTION_PRIV_INSTRUCTION = "STATUS_PRIVILEGED_INSTRUCTION"
const EXCEPTION_READ_FAULT = 0
const EXCEPTION_SINGLE_STEP = "STATUS_SINGLE_STEP"
const EXCEPTION_STACK_INVALID = 8
const EXCEPTION_STACK_OVERFLOW = "STATUS_STACK_OVERFLOW"
const EXCEPTION_TARGET_UNWIND = 32
const EXCEPTION_UNWIND = 102
const EXCEPTION_UNWINDING = 2
const EXCEPTION_WRITE_FAULT = 1
const EXCLUDED_TABLE_NUMBER = 2
const EXCLUSIVE_LOCK = 4
const EXDEV = 18
const EXECUTE_OFFLINE_DIAGS = 212
const EXIT_FAILURE = 1
const EXIT_PROCESS_DEBUG_EVENT = 5
const EXIT_SUCCESS = 0
const EXIT_THREAD_DEBUG_EVENT = 4
const EXPENTRY = "CALLBACK"
const EXPORT_PRIVATE_KEYS = 4
const EXPO_OFFLOAD_FUNC_NAME = "OffloadModExpo"
const EXPO_OFFLOAD_REG_VALUE = "ExpoOffload"
const EXPRDUP_REDUCE = 1
const EXPR_FULLSIZE = 0
const EXTENDED_STARTUPINFO_PRESENT = 524288
const EXTEND_IEPORT = 2
const EXTERN_C = 0
const EXTTEXTOUT = 512
const EXT_DEVICE_CAPS = 4099
const E_DRAW = "VIEW_E_DRAW"
const EncryptFile = 0
const EndUpdateResource = 0
const EnumCalendarInfo = 0
const EnumCalendarInfoEx = 0
const EnumDateFormats = 0
const EnumDateFormatsEx = 0
const EnumDependentServices = 0
const EnumDesktops = 0
const EnumDisplayDevices = 0
const EnumDisplaySettings = 0
const EnumDisplaySettingsEx = 0
const EnumFontFamilies = 0
const EnumFontFamiliesEx = 0
const EnumFonts = 0
const EnumForms = 0
const EnumICMProfiles = 0
const EnumJobs = 0
const EnumLanguageGroupLocales = 0
const EnumMonitors = 0
const EnumPorts = 0
const EnumPrintProcessorDatatypes = 0
const EnumPrintProcessors = 0
const EnumPrinterData = 0
const EnumPrinterDataEx = 0
const EnumPrinterDrivers = 0
const EnumPrinterKey = 0
const EnumPrinters = 0
const EnumProps = 0
const EnumPropsEx = 0
const EnumResourceLanguages = 0
const EnumResourceLanguagesEx = 0
const EnumResourceNames = 0
const EnumResourceNamesEx = 0
const EnumResourceTypes = 0
const EnumResourceTypesEx = 0
const EnumServicesStatus = 0
const EnumServicesStatusEx = 0
const EnumSystemCodePages = 0
const EnumSystemLanguageGroups = 0
const EnumSystemLocales = 0
const EnumTimeFormats = 0
const EnumUILanguages = 0
const EnumWindowStations = 0
const ExceptionCollidedUnwind = 3
const ExceptionContinueExecution = 0
const ExceptionContinueSearch = 1
const ExceptionExecuteHandler = 4
const ExceptionNestedException = 2
const ExpandEnvironmentStrings = 0
const ExpungeConsoleCommandHistory = 0
const ExtTextOut = 0
const ExtractAssociatedIcon = 0
const ExtractAssociatedIconEx = 0
const ExtractIcon = 0
const ExtractIconEx = 0
const FACILITY_AAF = 18
const FACILITY_ACS = 20
const FACILITY_AUDCLNT = 2185
const FACILITY_BACKGROUNDCOPY = 32
const FACILITY_CERT = 11
const FACILITY_COMPLUS = 17
const FACILITY_CONFIGURATION = 33
const FACILITY_CONTROL = 10
const FACILITY_DIRECTORYSERVICE = 37
const FACILITY_DISPATCH = 2
const FACILITY_DPLAY = 21
const FACILITY_HTTP = 25
const FACILITY_INTERNET = 12
const FACILITY_ITF = 4
const FACILITY_MEDIASERVER = 13
const FACILITY_METADIRECTORY = 35
const FACILITY_MSMQ = 14
const FACILITY_NT_BIT = 268435456
const FACILITY_NULL = 0
const FACILITY_RPC = 1
const FACILITY_SCARD = 16
const FACILITY_SECURITY = 9
const FACILITY_SETUPAPI = 15
const FACILITY_SSPI = 9
const FACILITY_STATE_MANAGEMENT = 34
const FACILITY_STORAGE = 3
const FACILITY_SXS = 23
const FACILITY_UMI = 22
const FACILITY_URT = 19
const FACILITY_USERMODE_FILTER_MANAGER = 31
const FACILITY_WIN32 = 7
const FACILITY_WINDOWS = 8
const FACILITY_WINDOWSUPDATE = 36
const FACILITY_WINDOWS_CE = 24
const FADF_AUTO = 1
const FADF_BSTR = 256
const FADF_DISPATCH = 1024
const FADF_EMBEDDED = 4
const FADF_FIXEDSIZE = 16
const FADF_HAVEIID = 64
const FADF_HAVEVARTYPE = 128
const FADF_RECORD = 32
const FADF_RESERVED = 61448
const FADF_STATIC = 2
const FADF_UNKNOWN = 512
const FADF_VARIANT = 2048
const FAILED_ACCESS_ACE_FLAG = 128
const FAIL_FAST_GENERATE_EXCEPTION_ADDRESS = 1
const FAIL_FAST_NO_HARD_ERROR_DLG = 2
const FALSE = 0
const FALT = 16
const FAPPCOMMAND_KEY = 0
const FAPPCOMMAND_MASK = 61440
const FAPPCOMMAND_MOUSE = 32768
const FAPPCOMMAND_OEM = 4096
const FASTCALL = "__fastcall"
const FAST_FAIL_CORRUPT_LIST_ENTRY = 3
const FAST_FAIL_FATAL_APP_EXIT = 7
const FAST_FAIL_GS_COOKIE_INIT = 6
const FAST_FAIL_INCORRECT_STACK = 4
const FAST_FAIL_INVALID_ARG = 5
const FAST_FAIL_INVALID_FAST_FAIL_CODE = 4294967295
const FAST_FAIL_LEGACY_GS_VIOLATION = 0
const FAST_FAIL_RANGE_CHECK_FAILURE = 8
const FAST_FAIL_STACK_COOKIE_CHECK_FAILURE = 2
const FAST_FAIL_UNSAFE_REGISTRY_ACCESS = 9
const FAST_FAIL_VTGUARD_CHECK_FAILURE = 1
const FCONTROL = 8
const FD_ACCEPT = 8
const FD_CLOSE = 32
const FD_CONNECT = 16
const FD_OOB = 4
const FD_READ = 1
const FD_SETSIZE = 64
const FD_WRITE = 2
const FEATURESETTING_CUSTPAPER = 3
const FEATURESETTING_MIRROR = 4
const FEATURESETTING_NEGATIVE = 5
const FEATURESETTING_NUP = 0
const FEATURESETTING_OUTPUT = 1
const FEATURESETTING_PRIVATE_BEGIN = 4096
const FEATURESETTING_PRIVATE_END = 8191
const FEATURESETTING_PROTOCOL = 6
const FEATURESETTING_PSLEVEL = 2
const FE_FONTSMOOTHINGCLEARTYPE = 2
const FE_FONTSMOOTHINGDOCKING = 32768
const FE_FONTSMOOTHINGORIENTATIONBGR = 0
const FE_FONTSMOOTHINGORIENTATIONRGB = 1
const FE_FONTSMOOTHINGSTANDARD = 1
const FF_DECORATIVE = 80
const FF_DONTCARE = 0
const FF_MODERN = 48
const FF_ROMAN = 16
const FF_SCRIPT = 64
const FF_SWISS = 32
const FIBER_FLAG_FLOAT_SWITCH = 1
const FIEF_FLAG_FORCE_JITUI = 1
const FIEF_FLAG_PEEK = 2
const FIEF_FLAG_SKIP_INSTALLED_VERSION_CHECK = 4
const FILENAME_MAX = 260
const FILEOKSTRINGA = "commdlg_FileNameOK"
const FILEOKSTRINGW = "commdlg_FileNameOK"
const FILEOPENORD = 1536
const FILESYSTEM_STATISTICS_TYPE_EXFAT = 3
const FILESYSTEM_STATISTICS_TYPE_FAT = 2
const FILESYSTEM_STATISTICS_TYPE_NTFS = 1
const FILE_ACTION_ADDED = 1
const FILE_ACTION_MODIFIED = 3
const FILE_ACTION_REMOVED = 2
const FILE_ACTION_RENAMED_NEW_NAME = 5
const FILE_ACTION_RENAMED_OLD_NAME = 4
const FILE_ADD_FILE = 2
const FILE_ADD_SUBDIRECTORY = 4
const FILE_ALL_ACCESS = 2032127
const FILE_ANY_ACCESS = 0
const FILE_APPEND_DATA = 4
const FILE_ATTRIBUTE_ARCHIVE = 32
const FILE_ATTRIBUTE_COMPRESSED = 2048
const FILE_ATTRIBUTE_DEVICE = 64
const FILE_ATTRIBUTE_DIRECTORY = 16
const FILE_ATTRIBUTE_ENCRYPTED = 16384
const FILE_ATTRIBUTE_HIDDEN = 2
const FILE_ATTRIBUTE_MASK = 262135
const FILE_ATTRIBUTE_NORMAL = 128
const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192
const FILE_ATTRIBUTE_OFFLINE = 4096
const FILE_ATTRIBUTE_READONLY = 1
const FILE_ATTRIBUTE_REPARSE_POINT = 1024
const FILE_ATTRIBUTE_SPARSE_FILE = 512
const FILE_ATTRIBUTE_SYSTEM = 4
const FILE_ATTRIBUTE_TEMPORARY = 256
const FILE_ATTRIBUTE_VIRTUAL = 65536
const FILE_BEGIN = 0
const FILE_CACHE_MAX_HARD_DISABLE = 2
const FILE_CACHE_MAX_HARD_ENABLE = 1
const FILE_CACHE_MIN_HARD_DISABLE = 8
const FILE_CACHE_MIN_HARD_ENABLE = 4
const FILE_CASE_PRESERVED_NAMES = 2
const FILE_CASE_SENSITIVE_SEARCH = 1
const FILE_CLEAR_ENCRYPTION = 2
const FILE_COMPLETE_IF_OPLOCKED = 256
const FILE_CREATE = 2
const FILE_CREATE_PIPE_INSTANCE = 4
const FILE_CREATE_TREE_CONNECTION = 128
const FILE_CURRENT = 1
const FILE_DELETE_CHILD = 64
const FILE_DELETE_ON_CLOSE = 4096
const FILE_DEVICE_8042_PORT = 39
const FILE_DEVICE_ACPI = 50
const FILE_DEVICE_BATTERY = 41
const FILE_DEVICE_BEEP = 1
const FILE_DEVICE_BIOMETRIC = 68
const FILE_DEVICE_BLUETOOTH = 65
const FILE_DEVICE_BUS_EXTENDER = 42
const FILE_DEVICE_CD_ROM = 2
const FILE_DEVICE_CD_ROM_FILE_SYSTEM = 3
const FILE_DEVICE_CHANGER = 48
const FILE_DEVICE_CONSOLE = 80
const FILE_DEVICE_CONTROLLER = 4
const FILE_DEVICE_CRYPT_PROVIDER = 63
const FILE_DEVICE_DATALINK = 5
const FILE_DEVICE_DEVAPI = 71
const FILE_DEVICE_DFS = 6
const FILE_DEVICE_DFS_FILE_SYSTEM = 53
const FILE_DEVICE_DFS_VOLUME = 54
const FILE_DEVICE_DISK = 7
const FILE_DEVICE_DISK_FILE_SYSTEM = 8
const FILE_DEVICE_DVD = 51
const FILE_DEVICE_EHSTOR = 70
const FILE_DEVICE_EVENT_COLLECTOR = 95
const FILE_DEVICE_FILE_SYSTEM = 9
const FILE_DEVICE_FIPS = 58
const FILE_DEVICE_FULLSCREEN_VIDEO = 52
const FILE_DEVICE_GPIO = 72
const FILE_DEVICE_HOLOGRAPHIC = 91
const FILE_DEVICE_INFINIBAND = 59
const FILE_DEVICE_INPORT_PORT = 10
const FILE_DEVICE_KEYBOARD = 11
const FILE_DEVICE_KS = 47
const FILE_DEVICE_KSEC = 57
const FILE_DEVICE_MAILSLOT = 12
const FILE_DEVICE_MASS_STORAGE = 45
const FILE_DEVICE_MIDI_IN = 13
const FILE_DEVICE_MIDI_OUT = 14
const FILE_DEVICE_MODEM = 43
const FILE_DEVICE_MOUSE = 15
const FILE_DEVICE_MT_COMPOSITE = 66
const FILE_DEVICE_MT_TRANSPORT = 67
const FILE_DEVICE_MULTI_UNC_PROVIDER = 16
const FILE_DEVICE_NAMED_PIPE = 17
const FILE_DEVICE_NETWORK = 18
const FILE_DEVICE_NETWORK_BROWSER = 19
const FILE_DEVICE_NETWORK_FILE_SYSTEM = 20
const FILE_DEVICE_NETWORK_REDIRECTOR = 40
const FILE_DEVICE_NFP = 81
const FILE_DEVICE_NULL = 21
const FILE_DEVICE_NVDIMM = 90
const FILE_DEVICE_PARALLEL_PORT = 22
const FILE_DEVICE_PERSISTENT_MEMORY = 89
const FILE_DEVICE_PHYSICAL_NETCARD = 23
const FILE_DEVICE_PMI = 69
const FILE_DEVICE_POINT_OF_SERVICE = 84
const FILE_DEVICE_PRINTER = 24
const FILE_DEVICE_PRM = 94
const FILE_DEVICE_SCANNER = 25
const FILE_DEVICE_SCREEN = 28
const FILE_DEVICE_SDFXHCI = 92
const FILE_DEVICE_SERENUM = 55
const FILE_DEVICE_SERIAL_MOUSE_PORT = 26
const FILE_DEVICE_SERIAL_PORT = 27
const FILE_DEVICE_SMARTCARD = 49
const FILE_DEVICE_SMB = 46
const FILE_DEVICE_SOUND = 29
const FILE_DEVICE_SOUNDWIRE = 97
const FILE_DEVICE_STORAGE_REPLICATION = 85
const FILE_DEVICE_STREAMS = 30
const FILE_DEVICE_SYSENV = 82
const FILE_DEVICE_TAPE = 31
const FILE_DEVICE_TAPE_FILE_SYSTEM = 32
const FILE_DEVICE_TERMSRV = 56
const FILE_DEVICE_TRANSPORT = 33
const FILE_DEVICE_TRUST_ENV = 86
const FILE_DEVICE_UCM = 87
const FILE_DEVICE_UCMTCPCI = 88
const FILE_DEVICE_UCMUCSI = 93
const FILE_DEVICE_UNKNOWN = 34
const FILE_DEVICE_USB4 = 96
const FILE_DEVICE_USBEX = 73
const FILE_DEVICE_VDM = 44
const FILE_DEVICE_VIDEO = 35
const FILE_DEVICE_VIRTUAL_BLOCK = 83
const FILE_DEVICE_VIRTUAL_DISK = 36
const FILE_DEVICE_VMBUS = 62
const FILE_DEVICE_WAVE_IN = 37
const FILE_DEVICE_WAVE_OUT = 38
const FILE_DEVICE_WPD = 64
const FILE_DIRECTORY_FILE = 1
const FILE_DIR_DISALLOWED = 9
const FILE_DISALLOW_EXCLUSIVE = 131072
const FILE_DISPOSITION_FLAG_DELETE = 1
const FILE_DISPOSITION_FLAG_DO_NOT_DELETE = 0
const FILE_DISPOSITION_FLAG_FORCE_IMAGE_SECTION_CHECK = 4
const FILE_DISPOSITION_FLAG_IGNORE_READONLY_ATTRIBUTE = 16
const FILE_DISPOSITION_FLAG_ON_CLOSE = 8
const FILE_DISPOSITION_FLAG_POSIX_SEMANTICS = 2
const FILE_ENCRYPTABLE = 0
const FILE_END = 2
const FILE_EXECUTE = 32
const FILE_FILE_COMPRESSION = 16
const FILE_FLAG_BACKUP_SEMANTICS = 33554432
const FILE_FLAG_DELETE_ON_CLOSE = 67108864
const FILE_FLAG_FIRST_PIPE_INSTANCE = 524288
const FILE_FLAG_MASK = 4282122240
const FILE_FLAG_NO_BUFFERING = 536870912
const FILE_FLAG_OPEN_NO_RECALL = 1048576
const FILE_FLAG_OPEN_REPARSE_POINT = 2097152
const FILE_FLAG_OPEN_REQUIRING_OPLOCK = 262144
const FILE_FLAG_OVERLAPPED = 1073741824
const FILE_FLAG_POSIX_SEMANTICS = 16777216
const FILE_FLAG_RANDOM_ACCESS = 268435456
const FILE_FLAG_SEQUENTIAL_SCAN = 134217728
const FILE_FLAG_SESSION_AWARE = 8388608
const FILE_FLAG_WRITE_THROUGH = 2147483648
const FILE_GENERIC_EXECUTE = 1179808
const FILE_GENERIC_READ = 1179785
const FILE_GENERIC_WRITE = 1179926
const FILE_IS_ENCRYPTED = 1
const FILE_LIST_DIRECTORY = 1
const FILE_MAP_ALL_ACCESS = 983071
const FILE_MAP_COPY = 1
const FILE_MAP_EXECUTE = 32
const FILE_MAP_LARGE_PAGES = 536870912
const FILE_MAP_READ = 4
const FILE_MAP_RESERVE = 2147483648
const FILE_MAP_TARGETS_INVALID = 1073741824
const FILE_MAP_WRITE = 2
const FILE_MAXIMUM_DISPOSITION = 5
const FILE_NAMED_STREAMS = 262144
const FILE_NAME_NORMALIZED = 0
const FILE_NAME_OPENED = 8
const FILE_NON_DIRECTORY_FILE = 64
const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
const FILE_NOTIFY_CHANGE_CREATION = 64
const FILE_NOTIFY_CHANGE_DIR_NAME = 2
const FILE_NOTIFY_CHANGE_FILE_NAME = 1
const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32
const FILE_NOTIFY_CHANGE_LAST_WRITE = 16
const FILE_NOTIFY_CHANGE_SECURITY = 256
const FILE_NOTIFY_CHANGE_SIZE = 8
const FILE_NO_COMPRESSION = 32768
const FILE_NO_EA_KNOWLEDGE = 512
const FILE_NO_INTERMEDIATE_BUFFERING = 8
const FILE_OPEN = 1
const FILE_OPEN_BY_FILE_ID = 8192
const FILE_OPEN_FOR_BACKUP_INTENT = 16384
const FILE_OPEN_FOR_FREE_SPACE_QUERY = 8388608
const FILE_OPEN_IF = 3
const FILE_OPEN_NO_RECALL = 4194304
const FILE_OPEN_REMOTE_INSTANCE = 1024
const FILE_OPEN_REPARSE_POINT = 2097152
const FILE_OPEN_REQUIRING_OPLOCK = 65536
const FILE_OVERWRITE = 4
const FILE_OVERWRITE_IF = 5
const FILE_PERSISTENT_ACLS = 8
const FILE_PREFETCH_TYPE_FOR_CREATE = 1
const FILE_PREFETCH_TYPE_FOR_CREATE_EX = 3
const FILE_PREFETCH_TYPE_FOR_DIRENUM = 2
const FILE_PREFETCH_TYPE_FOR_DIRENUM_EX = 4
const FILE_PREFETCH_TYPE_MAX = 4
const FILE_PROVIDER_COMPRESSION_LZX = 1
const FILE_PROVIDER_COMPRESSION_XPRESS16K = 3
const FILE_PROVIDER_COMPRESSION_XPRESS4K = 0
const FILE_PROVIDER_COMPRESSION_XPRESS8K = 2
const FILE_PROVIDER_CURRENT_VERSION = 1
const FILE_RANDOM_ACCESS = 2048
const FILE_READ_ACCESS = 1
const FILE_READ_ATTRIBUTES = 128
const FILE_READ_DATA = 1
const FILE_READ_EA = 8
const FILE_READ_ONLY = 8
const FILE_READ_ONLY_VOLUME = 524288
const FILE_RENAME_FLAG_POSIX_SEMANTICS = 2
const FILE_RENAME_FLAG_REPLACE_IF_EXISTS = 1
const FILE_RENAME_FLAG_SUPPRESS_PIN_STATE_INHERITANCE = 4
const FILE_RESERVE_OPFILTER = 1048576
const FILE_ROOT_DIR = 3
const FILE_SEQUENTIAL_ONLY = 4
const FILE_SEQUENTIAL_WRITE_ONCE = 1048576
const FILE_SET_ENCRYPTION = 1
const FILE_SHARE_DELETE = 4
const FILE_SHARE_READ = 1
const FILE_SHARE_VALID_FLAGS = 7
const FILE_SHARE_WRITE = 2
const FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1
const FILE_SKIP_SET_EVENT_ON_HANDLE = 2
const FILE_SPECIAL_ACCESS = 0
const FILE_SUPERSEDE = 0
const FILE_SUPPORTS_ENCRYPTION = 131072
const FILE_SUPPORTS_EXTENDED_ATTRIBUTES = 8388608
const FILE_SUPPORTS_HARD_LINKS = 4194304
const FILE_SUPPORTS_INTEGRITY_STREAMS = 67108864
const FILE_SUPPORTS_OBJECT_IDS = 65536
const FILE_SUPPORTS_OPEN_BY_FILE_ID = 16777216
const FILE_SUPPORTS_REMOTE_STORAGE = 256
const FILE_SUPPORTS_REPARSE_POINTS = 128
const FILE_SUPPORTS_SPARSE_FILES = 64
const FILE_SUPPORTS_TRANSACTIONS = 2097152
const FILE_SUPPORTS_USN_JOURNAL = 33554432
const FILE_SYNCHRONOUS_IO_ALERT = 16
const FILE_SYNCHRONOUS_IO_NONALERT = 32
const FILE_SYSTEM_ATTR = 2
const FILE_SYSTEM_DIR = 4
const FILE_SYSTEM_NOT_SUPPORT = 6
const FILE_TRAVERSE = 32
const FILE_TYPE_CHAR = 2
const FILE_TYPE_DISK = 1
const FILE_TYPE_NOTIFICATION_FLAG_USAGE_BEGIN = 1
const FILE_TYPE_NOTIFICATION_FLAG_USAGE_END = 2
const FILE_TYPE_PIPE = 3
const FILE_TYPE_REMOTE = 32768
const FILE_TYPE_UNKNOWN = 0
const FILE_UNICODE_ON_DISK = 4
const FILE_UNKNOWN = 5
const FILE_USER_DISALLOWED = 7
const FILE_VER_GET_LOCALISED = 1
const FILE_VER_GET_NEUTRAL = 2
const FILE_VER_GET_PREFETCHED = 4
const FILE_VOLUME_IS_COMPRESSED = 32768
const FILE_VOLUME_QUOTAS = 32
const FILE_WRITE_ACCESS = 2
const FILE_WRITE_ATTRIBUTES = 256
const FILE_WRITE_DATA = 2
const FILE_WRITE_EA = 16
const FILE_WRITE_THROUGH = 2
const FINDDLGORD = 1540
const FINDMSGSTRINGA = "commdlg_FindReplace"
const FINDMSGSTRINGW = "commdlg_FindReplace"
const FIND_ACTCTX_SECTION_KEY_RETURN_ASSEMBLY_METADATA = 4
const FIND_ACTCTX_SECTION_KEY_RETURN_FLAGS = 2
const FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX = 1
const FIND_ENDSWITH = 2097152
const FIND_FIRST_EX_CASE_SENSITIVE = 1
const FIND_FIRST_EX_LARGE_FETCH = 2
const FIND_FROMEND = 8388608
const FIND_FROMSTART = 4194304
const FIND_RESOURCE_DIRECTORY_LANGUAGES = 1024
const FIND_RESOURCE_DIRECTORY_NAMES = 512
const FIND_RESOURCE_DIRECTORY_TYPES = 256
const FIND_STARTSWITH = 1048576
const FIXED_PITCH = 1
const FKF_AVAILABLE = 2
const FKF_CLICKON = 64
const FKF_CONFIRMHOTKEY = 8
const FKF_FILTERKEYSON = 1
const FKF_HOTKEYACTIVE = 4
const FKF_HOTKEYSOUND = 16
const FKF_INDICATOR = 32
const FLAG_SIGNED = 1
const FLAG_STRING = 4
const FLASHW_ALL = 3
const FLASHW_CAPTION = 1
const FLASHW_STOP = 0
const FLASHW_TIMER = 4
const FLASHW_TIMERNOFG = 12
const FLASHW_TRAY = 2
const FLI_GLYPHS = 262144
const FLI_MASK = 4155
const FLOODFILLBORDER = 0
const FLOODFILLSURFACE = 1
const FLS_MAXIMUM_AVAILABLE = 128
const FLUSHOUTPUT = 6
const FMFD_DEFAULT = 0
const FMFD_ENABLEMIMESNIFFING = 2
const FMFD_IGNOREMIMETEXTPLAIN = 4
const FMFD_RESPECTTEXTPLAIN = 16
const FMFD_RETURNUPDATEDIMGMIMES = 32
const FMFD_SERVERMIME = 8
const FMFD_URLASFILENAME = 1
const FMTID_NULL = 0
const FNERR_BUFFERTOOSMALL = 12291
const FNERR_FILENAMECODES = 12288
const FNERR_INVALIDFILENAME = 12290
const FNERR_SUBCLASSFAILURE = 12289
const FNOINVERT = 2
const FOCUS_EVENT = 16
const FOF_ALLOWUNDO = 64
const FOF_CONFIRMMOUSE = 2
const FOF_FILESONLY = 128
const FOF_MULTIDESTFILES = 1
const FOF_NOCONFIRMATION = 16
const FOF_NOCONFIRMMKDIR = 512
const FOF_NOCOPYSECURITYATTRIBS = 2048
const FOF_NOERRORUI = 1024
const FOF_NORECURSEREPARSE = 32768
const FOF_NORECURSION = 4096
const FOF_NO_CONNECTED_ELEMENTS = 8192
const FOF_NO_UI = 1556
const FOF_RENAMEONCOLLISION = 8
const FOF_SILENT = 4
const FOF_SIMPLEPROGRESS = 256
const FOF_WANTMAPPINGHANDLE = 32
const FOF_WANTNUKEWARNING = 16384
const FONTDLGORD = 1542
const FONTMAPPER_MAX = 10
const FOPEN_MAX = 20
const FORCEINLINE = "__forceinline"
const FOREGROUND_BLUE = 1
const FOREGROUND_GREEN = 2
const FOREGROUND_INTENSITY = 8
const FOREGROUND_RED = 4
const FOREST_USER_RID_MAX = 499
const FORMATDLGORD30 = 1544
const FORMATDLGORD31 = 1543
const FORMAT_MESSAGE_ALLOCATE_BUFFER = 256
const FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192
const FORMAT_MESSAGE_FROM_HMODULE = 2048
const FORMAT_MESSAGE_FROM_STRING = 1024
const FORMAT_MESSAGE_FROM_SYSTEM = 4096
const FORMAT_MESSAGE_IGNORE_INSERTS = 512
const FORMAT_MESSAGE_MAX_WIDTH_MASK = 255
const FORM_BUILTIN = 1
const FORM_PRINTER = 2
const FORM_USER = 0
const FO_COPY = 2
const FO_DELETE = 3
const FO_MOVE = 1
const FO_RENAME = 4
const FP_INFINITE = 1280
const FP_NAN = 256
const FP_NDENORM = 16
const FP_NINF = 4
const FP_NNORM = 8
const FP_NORMAL = 1024
const FP_NZERO = 32
const FP_PDENORM = 128
const FP_PINF = 512
const FP_PNORM = 256
const FP_PZERO = 64
const FP_QNAN = 2
const FP_SNAN = 1
const FP_SUBNORMAL = 17408
const FP_ZERO = 16384
const FRAME_FPO = 0
const FRAME_NONFPO = 3
const FRAME_TRAP = 1
const FRAME_TSS = 2
const FRERR_BUFFERLENGTHZERO = 16385
const FRERR_FINDREPLACECODES = 16384
const FROM_LEFT_1ST_BUTTON_PRESSED = 1
const FROM_LEFT_2ND_BUTTON_PRESSED = 4
const FROM_LEFT_3RD_BUTTON_PRESSED = 8
const FROM_LEFT_4TH_BUTTON_PRESSED = 16
const FRS_ERR_AUTHENTICATION = 8008
const FRS_ERR_CHILD_TO_PARENT_COMM = 8011
const FRS_ERR_INSUFFICIENT_PRIV = 8007
const FRS_ERR_INTERNAL = 8005
const FRS_ERR_INTERNAL_API = 8004
const FRS_ERR_INVALID_API_SEQUENCE = 8001
const FRS_ERR_INVALID_SERVICE_PARAMETER = 8017
const FRS_ERR_PARENT_AUTHENTICATION = 8010
const FRS_ERR_PARENT_INSUFFICIENT_PRIV = 8009
const FRS_ERR_PARENT_TO_CHILD_COMM = 8012
const FRS_ERR_SERVICE_COMM = 8006
const FRS_ERR_STARTING_SERVICE = 8002
const FRS_ERR_STOPPING_SERVICE = 8003
const FRS_ERR_SYSVOL_DEMOTE = 8016
const FRS_ERR_SYSVOL_IS_BUSY = 8015
const FRS_ERR_SYSVOL_POPULATE = 8013
const FRS_ERR_SYSVOL_POPULATE_TIMEOUT = 8014
const FR_DIALOGTERM = 64
const FR_DOWN = 1
const FR_ENABLEHOOK = 256
const FR_ENABLETEMPLATE = 512
const FR_ENABLETEMPLATEHANDLE = 8192
const FR_FINDNEXT = 8
const FR_HIDEMATCHCASE = 32768
const FR_HIDEUPDOWN = 16384
const FR_HIDEWHOLEWORD = 65536
const FR_MATCHALEFHAMZA = 2147483648
const FR_MATCHCASE = 4
const FR_MATCHDIAC = 536870912
const FR_MATCHKASHIDA = 1073741824
const FR_NOMATCHCASE = 2048
const FR_NOT_ENUM = 32
const FR_NOUPDOWN = 1024
const FR_NOWHOLEWORD = 4096
const FR_PRIVATE = 16
const FR_RAW = 131072
const FR_REPLACE = 16
const FR_REPLACEALL = 32
const FR_SHOWHELP = 128
const FR_WHOLEWORD = 2
const FSCTL_ALLOW_EXTENDED_DASD_IO = 589955
const FSCTL_CREATE_OR_GET_OBJECT_ID = 590016
const FSCTL_CREATE_USN_JOURNAL = 590055
const FSCTL_CSC_INTERNAL = 590255
const FSCTL_CSV_GET_VOLUME_NAME_FOR_VOLUME_MOUNT_POINT = 590420
const FSCTL_CSV_GET_VOLUME_PATH_NAME = 590416
const FSCTL_CSV_GET_VOLUME_PATH_NAMES_FOR_VOLUME_NAME = 590424
const FSCTL_CSV_TUNNEL_REQUEST = 590404
const FSCTL_DELETE_EXTERNAL_BACKING = 590612
const FSCTL_DELETE_OBJECT_ID = 589984
const FSCTL_DELETE_REPARSE_POINT = 589996
const FSCTL_DELETE_USN_JOURNAL = 590072
const FSCTL_DFSR_SET_GHOST_HANDLE_STATE = 590264
const FSCTL_DISMOUNT_VOLUME = 589856
const FSCTL_ENABLE_UPGRADE = 622800
const FSCTL_ENCRYPTION_FSCTL_IO = 590043
const FSCTL_ENUM_USN_DATA = 590003
const FSCTL_EXTEND_VOLUME = 590064
const FSCTL_FILESYSTEM_GET_STATISTICS = 589920
const FSCTL_FILE_PREFETCH = 590112
const FSCTL_FILE_TYPE_NOTIFICATION = 590340
const FSCTL_FIND_FILES_BY_SID = 589967
const FSCTL_GET_BOOT_AREA_INFO = 590384
const FSCTL_GET_COMPRESSION = 589884
const FSCTL_GET_EXTERNAL_BACKING = 590608
const FSCTL_GET_NTFS_FILE_RECORD = 589928
const FSCTL_GET_NTFS_VOLUME_DATA = 589924
const FSCTL_GET_OBJECT_ID = 589980
const FSCTL_GET_REPAIR = 590236
const FSCTL_GET_REPARSE_POINT = 589992
const FSCTL_GET_RETRIEVAL_POINTERS = 589939
const FSCTL_GET_RETRIEVAL_POINTER_BASE = 590388
const FSCTL_GET_VOLUME_BITMAP = 589935
const FSCTL_HSM_DATA = 639251
const FSCTL_HSM_MSG = 639240
const FSCTL_INITIATE_REPAIR = 590248
const FSCTL_INVALIDATE_VOLUMES = 589908
const FSCTL_IS_CSV_FILE = 590408
const FSCTL_IS_FILE_ON_CSV_VOLUME = 590428
const FSCTL_IS_PATHNAME_VALID = 589868
const FSCTL_IS_VOLUME_DIRTY = 589944
const FSCTL_IS_VOLUME_MOUNTED = 589864
const FSCTL_LOCK_VOLUME = 589848
const FSCTL_LOOKUP_STREAM_FROM_CLUSTER = 590332
const FSCTL_MAKE_MEDIA_COMPATIBLE = 622896
const FSCTL_MARK_AS_SYSTEM_HIVE = 589903
const FSCTL_MARK_HANDLE = 590076
const FSCTL_MARK_VOLUME_DIRTY = 589872
const FSCTL_MOVE_FILE = 589940
const FSCTL_OPBATCH_ACK_CLOSE_PENDING = 589840
const FSCTL_OPLOCK_BREAK_ACKNOWLEDGE = 589836
const FSCTL_OPLOCK_BREAK_ACK_NO_2 = 589904
const FSCTL_OPLOCK_BREAK_NOTIFY = 589844
const FSCTL_QUERY_ALLOCATED_RANGES = 606415
const FSCTL_QUERY_DEPENDENT_VOLUME = 590320
const FSCTL_QUERY_FAT_BPB = 589912
const FSCTL_QUERY_FILE_SYSTEM_RECOGNITION = 590412
const FSCTL_QUERY_ON_DISK_VOLUME_INFO = 590140
const FSCTL_QUERY_PAGEFILE_ENCRYPTION = 590312
const FSCTL_QUERY_PERSISTENT_VOLUME_STATE = 590396
const FSCTL_QUERY_RETRIEVAL_POINTERS = 589883
const FSCTL_QUERY_SPARING_INFO = 590136
const FSCTL_QUERY_USN_JOURNAL = 590068
const FSCTL_READ_FILE_USN_DATA = 590059
const FSCTL_READ_FROM_PLEX = 606494
const FSCTL_READ_RAW_ENCRYPTED = 590051
const FSCTL_READ_USN_JOURNAL = 590011
const FSCTL_RECALL_FILE = 590103
const FSCTL_REQUEST_BATCH_OPLOCK = 589832
const FSCTL_REQUEST_FILTER_OPLOCK = 589916
const FSCTL_REQUEST_OPLOCK = 590400
const FSCTL_REQUEST_OPLOCK_LEVEL_1 = 589824
const FSCTL_REQUEST_OPLOCK_LEVEL_2 = 589828
const FSCTL_RESET_VOLUME_ALLOCATION_HINTS = 590316
const FSCTL_SD_GLOBAL_CHANGE = 590324
const FSCTL_SECURITY_ID_CHECK = 606391
const FSCTL_SET_BOOTLOADER_ACCESSED = 589903
const FSCTL_SET_COMPRESSION = 639040
const FSCTL_SET_DEFECT_MANAGEMENT = 622900
const FSCTL_SET_ENCRYPTION = 590039
const FSCTL_SET_EXTERNAL_BACKING = 590604
const FSCTL_SET_OBJECT_ID = 589976
const FSCTL_SET_OBJECT_ID_EXTENDED = 590012
const FSCTL_SET_PERSISTENT_VOLUME_STATE = 590392
const FSCTL_SET_REPAIR = 590232
const FSCTL_SET_REPARSE_POINT = 589988
const FSCTL_SET_SHORT_NAME_BEHAVIOR = 590260
const FSCTL_SET_SPARSE = 590020
const FSCTL_SET_VOLUME_COMPRESSION_STATE = 590144
const FSCTL_SET_ZERO_DATA = 622792
const FSCTL_SET_ZERO_ON_DEALLOCATION = 590228
const FSCTL_SHRINK_VOLUME = 590256
const FSCTL_SIS_COPYFILE = 590080
const FSCTL_SIS_LINK_FILES = 639236
const FSCTL_TXFS_CREATE_MINIVERSION = 622972
const FSCTL_TXFS_CREATE_SECONDARY_RM = 622952
const FSCTL_TXFS_GET_METADATA_INFO = 606572
const FSCTL_TXFS_GET_TRANSACTED_VERSION = 606576
const FSCTL_TXFS_LIST_TRANSACTIONS = 606692
const FSCTL_TXFS_LIST_TRANSACTION_LOCKED_FILES = 606688
const FSCTL_TXFS_MODIFY_RM = 622916
const FSCTL_TXFS_QUERY_RM_INFORMATION = 606536
const FSCTL_TXFS_READ_BACKUP_INFORMATION = 606560
const FSCTL_TXFS_READ_BACKUP_INFORMATION2 = 590328
const FSCTL_TXFS_ROLLFORWARD_REDO = 622928
const FSCTL_TXFS_ROLLFORWARD_UNDO = 622932
const FSCTL_TXFS_SAVEPOINT_INFORMATION = 622968
const FSCTL_TXFS_SHUTDOWN_RM = 622940
const FSCTL_TXFS_START_RM = 622936
const FSCTL_TXFS_TRANSACTION_ACTIVE = 606604
const FSCTL_TXFS_WRITE_BACKUP_INFORMATION = 622948
const FSCTL_TXFS_WRITE_BACKUP_INFORMATION2 = 590336
const FSCTL_UNLOCK_VOLUME = 589852
const FSCTL_WAIT_FOR_REPAIR = 590240
const FSCTL_WRITE_RAW_ENCRYPTED = 590047
const FSCTL_WRITE_USN_CLOSE_RECORD = 590063
const FSHIFT = 4
const FS_ARABIC = 64
const FS_BALTIC = 128
const FS_CASE_IS_PRESERVED = 2
const FS_CASE_SENSITIVE = 1
const FS_CHINESESIMP = 262144
const FS_CHINESETRAD = 1048576
const FS_CYRILLIC = 4
const FS_FILE_COMPRESSION = 16
const FS_FILE_ENCRYPTION = 131072
const FS_GREEK = 8
const FS_HEBREW = 32
const FS_JISJAPAN = 131072
const FS_JOHAB = 2097152
const FS_LATIN1 = 1
const FS_LATIN2 = 2
const FS_PERSISTENT_ACLS = 8
const FS_SYMBOL = 2147483648
const FS_THAI = 65536
const FS_TURKISH = 16
const FS_UNICODE_STORED_ON_DISK = 4
const FS_VIETNAMESE = 256
const FS_VOL_IS_COMPRESSED = 32768
const FS_WANSUNG = 524288
const FTS5CSR_EOF = 1
const FTS5CSR_FREE_ZRANK = 16
const FTS5CSR_REQUIRE_CONTENT = 2
const FTS5CSR_REQUIRE_DOCSIZE = 4
const FTS5CSR_REQUIRE_INST = 8
const FTS5CSR_REQUIRE_POSLIST = 64
const FTS5CSR_REQUIRE_RESEEK = 32
const FTS5INDEX_QUERY_DESC = 2
const FTS5INDEX_QUERY_NOOUTPUT = 32
const FTS5INDEX_QUERY_NOTOKENDATA = 128
const FTS5INDEX_QUERY_PREFIX = 1
const FTS5INDEX_QUERY_SCAN = 8
const FTS5INDEX_QUERY_SCANONETERM = 256
const FTS5INDEX_QUERY_SKIPEMPTY = 16
const FTS5INDEX_QUERY_SKIPHASH = 64
const FTS5INDEX_QUERY_TEST_NOIDX = 4
const FTS5TOKEN = 0
const FTS5_AND = 2
const FTS5_AVERAGES_ROWID = 1
const FTS5_BI_MATCH = 1
const FTS5_BI_ORDER_DESC = 128
const FTS5_BI_ORDER_RANK = 32
const FTS5_BI_ORDER_ROWID = 64
const FTS5_BI_RANK = 2
const FTS5_BI_ROWID_EQ = 4
const FTS5_BI_ROWID_GE = 16
const FTS5_BI_ROWID_LE = 8
const FTS5_CARET = 12
const FTS5_COLON = 5
const FTS5_COMMA = 13
const FTS5_CONTENT_EXTERNAL = 2
const FTS5_CONTENT_NONE = 1
const FTS5_CONTENT_NORMAL = 0
const FTS5_CORRUPT = 267
const FTS5_CURRENT_VERSION = 4
const FTS5_CURRENT_VERSION_SECUREDELETE = 5
const FTS5_DATA_DLI_B = 1
const FTS5_DATA_HEIGHT_B = 5
const FTS5_DATA_ID_B = 16
const FTS5_DATA_PADDING = 20
const FTS5_DATA_PAGE_B = 31
const FTS5_DATA_ZERO_PADDING = 8
const FTS5_DEFAULT_AUTOMERGE = 4
const FTS5_DEFAULT_CRISISMERGE = 16
const FTS5_DEFAULT_DELETE_AUTOMERGE = 10
const FTS5_DEFAULT_HASHSIZE = 1048576
const FTS5_DEFAULT_NEARDIST = 10
const FTS5_DEFAULT_PAGE_SIZE = 4050
const FTS5_DEFAULT_RANK = "bm25"
const FTS5_DEFAULT_USERMERGE = 4
const FTS5_DETAIL_COLUMNS = 2
const FTS5_DETAIL_FULL = 0
const FTS5_DETAIL_NONE = 1
const FTS5_EOF = 0
const FTS5_LCP = 7
const FTS5_LP = 10
const FTS5_MAIN_PREFIX = 48
const FTS5_MAX_LEVEL = 64
const FTS5_MAX_PAGE_SIZE = 65536
const FTS5_MAX_PREFIX_INDEXES = 31
const FTS5_MAX_SEGMENT = 2000
const FTS5_MAX_TOKEN_SIZE = 32768
const FTS5_MERGE_NLIST = 16
const FTS5_MINUS = 6
const FTS5_MIN_DLIDX_SIZE = 4
const FTS5_NOINLINE = "SQLITE_NOINLINE"
const FTS5_NOT = 3
const FTS5_OPT_WORK_UNIT = 1000
const FTS5_OR = 1
const FTS5_PATTERN_GLOB = 66
const FTS5_PATTERN_LIKE = 65
const FTS5_PATTERN_NONE = 0
const FTS5_PLAN_MATCH = 1
const FTS5_PLAN_ROWID = 6
const FTS5_PLAN_SCAN = 5
const FTS5_PLAN_SORTED_MATCH = 4
const FTS5_PLAN_SOURCE = 2
const FTS5_PLAN_SPECIAL = 3
const FTS5_PLUS = 14
const FTS5_PORTER_MAX_TOKEN = 64
const FTS5_RANK_NAME = "rank"
const FTS5_RCP = 8
const FTS5_REMOVE_DIACRITICS_COMPLEX = 2
const FTS5_REMOVE_DIACRITICS_NONE = 0
const FTS5_REMOVE_DIACRITICS_SIMPLE = 1
const FTS5_ROWID_NAME = "rowid"
const FTS5_RP = 11
const FTS5_SEGITER_ONETERM = 1
const FTS5_SEGITER_REVERSE = 2
const FTS5_STAR = 15
const FTS5_STMT_DELETE_CONTENT = 5
const FTS5_STMT_DELETE_DOCSIZE = 7
const FTS5_STMT_INSERT_CONTENT = 3
const FTS5_STMT_LOOKUP = 2
const FTS5_STMT_LOOKUP_DOCSIZE = 8
const FTS5_STMT_REPLACE_CONFIG = 9
const FTS5_STMT_REPLACE_CONTENT = 4
const FTS5_STMT_REPLACE_DOCSIZE = 6
const FTS5_STMT_SCAN = 10
const FTS5_STMT_SCAN_ASC = 0
const FTS5_STMT_SCAN_DESC = 1
const FTS5_STRING = 9
const FTS5_STRUCTURE_ROWID = 10
const FTS5_STRUCTURE_V2 = "\xff\x00\x00\x01"
const FTS5_TERM = 4
const FTS5_TOKENIZE_AUX = 8
const FTS5_TOKENIZE_DOCUMENT = 4
const FTS5_TOKENIZE_PREFIX = 2
const FTS5_TOKENIZE_QUERY = 1
const FTS5_TOKEN_COLOCATED = 1
const FTS5_VOCAB_COL = 0
const FTS5_VOCAB_COL_SCHEMA = "term, col, doc, cnt"
const FTS5_VOCAB_INSTANCE = 2
const FTS5_VOCAB_INST_SCHEMA = "term, doc, col, offset"
const FTS5_VOCAB_ROW = 1
const FTS5_VOCAB_ROW_SCHEMA = "term, doc, cnt"
const FTS5_VOCAB_TERM_EQ = 1
const FTS5_VOCAB_TERM_GE = 2
const FTS5_VOCAB_TERM_LE = 4
const FTS5_WORK_UNIT = 64
const FULLY_WITHIN = 2
const FUNC_PERFECT_MATCH = 6
const FVIRTKEY = 1
const FW_BLACK = 900
const FW_BOLD = 700
const FW_DEMIBOLD = 600
const FW_DONTCARE = 0
const FW_EXTRABOLD = 800
const FW_EXTRALIGHT = 200
const FW_HEAVY = 900
const FW_LIGHT = 300
const FW_MEDIUM = 500
const FW_NORMAL = 400
const FW_REGULAR = 400
const FW_SEMIBOLD = 600
const FW_THIN = 100
const FW_ULTRABOLD = 800
const FW_ULTRALIGHT = 200
const FatalAppExit = 0
const FileEncryptionStatus = 0
const FillConsoleOutputCharacter = 0
const FillMemory = 0
const FindActCtxSectionString = 0
const FindAtom = 0
const FindExecutable = 0
const FindFirstChangeNotification = 0
const FindFirstFile = 0
const FindFirstFileEx = 0
const FindFirstFileTransacted = 0
const FindFirstVolume = 0
const FindFirstVolumeMountPoint = 0
const FindNextFile = 0
const FindNextVolume = 0
const FindNextVolumeMountPoint = 0
const FindResource = 0
const FindResourceEx = 0
const FindText = 0
const FindWindow = 0
const FindWindowEx = 0
const FloppyClassGuid = 0
const FoldString = 0
const FormatMessage = 0
const FreeEnvironmentStrings = 0
const GA_PARENT = 1
const GA_ROOT = 2
const GA_ROOTOWNER = 3
const GB2312_CHARSET = 134
const GCC_VERSION = 12000000
const GCF_INCLUDE_ANCESTORS = 1
const GCLP_HBRBACKGROUND = -10
const GCLP_HCURSOR = -12
const GCLP_HICON = -14
const GCLP_HICONSM = -34
const GCLP_HMODULE = -16
const GCLP_MENUNAME = -8
const GCLP_WNDPROC = -24
const GCL_CBCLSEXTRA = -20
const GCL_CBWNDEXTRA = -18
const GCL_CONVERSION = 1
const GCL_HBRBACKGROUND = -10
const GCL_HCURSOR = -12
const GCL_HICON = -14
const GCL_HICONSM = -34
const GCL_HMODULE = -16
const GCL_MENUNAME = -8
const GCL_REVERSECONVERSION = 2
const GCL_REVERSE_LENGTH = 3
const GCL_STYLE = -26
const GCL_WNDPROC = -24
const GCPCLASS_ARABIC = 2
const GCPCLASS_HEBREW = 2
const GCPCLASS_LATIN = 1
const GCPCLASS_LATINNUMBER = 5
const GCPCLASS_LATINNUMERICSEPARATOR = 7
const GCPCLASS_LATINNUMERICTERMINATOR = 6
const GCPCLASS_LOCALNUMBER = 4
const GCPCLASS_NEUTRAL = 3
const GCPCLASS_NUMERICSEPARATOR = 8
const GCPCLASS_POSTBOUNDLTR = 32
const GCPCLASS_POSTBOUNDRTL = 16
const GCPCLASS_PREBOUNDLTR = 128
const GCPCLASS_PREBOUNDRTL = 64
const GCPGLYPH_LINKAFTER = 16384
const GCPGLYPH_LINKBEFORE = 32768
const GCP_CLASSIN = 524288
const GCP_DBCS = 1
const GCP_DIACRITIC = 256
const GCP_DISPLAYZWG = 4194304
const GCP_ERROR = 32768
const GCP_GLYPHSHAPE = 16
const GCP_JUSTIFY = 65536
const GCP_JUSTIFYIN = 2097152
const GCP_KASHIDA = 1024
const GCP_LIGATE = 32
const GCP_MAXEXTENT = 1048576
const GCP_NEUTRALOVERRIDE = 33554432
const GCP_NUMERICOVERRIDE = 16777216
const GCP_NUMERICSLATIN = 67108864
const GCP_NUMERICSLOCAL = 134217728
const GCP_REORDER = 2
const GCP_SYMSWAPOFF = 8388608
const GCP_USEKERNING = 8
const GCS_COMPATTR = 16
const GCS_COMPCLAUSE = 32
const GCS_COMPREADATTR = 2
const GCS_COMPREADCLAUSE = 4
const GCS_COMPREADSTR = 1
const GCS_COMPSTR = 8
const GCS_CURSORPOS = 128
const GCS_DELTASTART = 256
const GCS_RESULTCLAUSE = 4096
const GCS_RESULTREADCLAUSE = 1024
const GCS_RESULTREADSTR = 512
const GCS_RESULTSTR = 2048
const GCW_ATOM = -32
const GC_ALLGESTURES = 1
const GC_PAN = 1
const GC_PAN_WITH_GUTTER = 8
const GC_PAN_WITH_INERTIA = 16
const GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY = 4
const GC_PAN_WITH_SINGLE_FINGER_VERTICALLY = 2
const GC_PRESSANDTAP = 1
const GC_ROLLOVER = 1
const GC_ROTATE = 1
const GC_TWOFINGERTAP = 1
const GC_ZOOM = 1
const GDICOMMENT_BEGINGROUP = 2
const GDICOMMENT_ENDGROUP = 3
const GDICOMMENT_IDENTIFIER = 1128875079
const GDICOMMENT_MULTIFORMATS = 1073741828
const GDICOMMENT_UNICODE_END = 128
const GDICOMMENT_UNICODE_STRING = 64
const GDICOMMENT_WINDOWS_METAFILE = 2147483649
const GDIPLUS_TS_QUERYVER = 4122
const GDIPLUS_TS_RECORD = 4123
const GDI_ERROR = 4294967295
const GDI_OBJ_LAST = 14
const GENERIC_ALL = 268435456
const GENERIC_EXECUTE = 536870912
const GENERIC_READ = 2147483648
const GENERIC_WRITE = 1073741824
const GEOID_NOT_AVAILABLE = -1
const GEOPOLY_PI = 3.141592653589793
const GESTURECONFIGMAXCOUNT = 256
const GESTUREVISUALIZATION_DOUBLETAP = 2
const GESTUREVISUALIZATION_OFF = 0
const GESTUREVISUALIZATION_ON = 31
const GESTUREVISUALIZATION_PRESSANDHOLD = 8
const GESTUREVISUALIZATION_PRESSANDTAP = 4
const GESTUREVISUALIZATION_RIGHTTAP = 16
const GESTUREVISUALIZATION_TAP = 1
const GETCOLORTABLE = 5
const GETDEVICEUNITS = 42
const GETEXTENDEDTEXTMETRICS = 256
const GETEXTENTTABLE = 257
const GETFACENAME = 513
const GETPAIRKERNTABLE = 258
const GETPENWIDTH = 16
const GETPHYSPAGESIZE = 12
const GETPRINTINGOFFSET = 13
const GETSCALINGFACTOR = 14
const GETSETPAPERBINS = 29
const GETSETPAPERMETRICS = 35
const GETSETPRINTORIENT = 30
const GETSETSCREENPARAMS = 3072
const GETTECHNOLGY = 20
const GETTECHNOLOGY = 20
const GETTRACKKERNTABLE = 259
const GETVECTORBRUSHSIZE = 27
const GETVECTORPENSIZE = 26
const GET_FEATURE_FROM_PROCESS = 2
const GET_FEATURE_FROM_REGISTRY = 4
const GET_FEATURE_FROM_THREAD = 1
const GET_FEATURE_FROM_THREAD_INTERNET = 64
const GET_FEATURE_FROM_THREAD_INTRANET = 16
const GET_FEATURE_FROM_THREAD_LOCALMACHINE = 8
const GET_FEATURE_FROM_THREAD_RESTRICTED = 128
const GET_FEATURE_FROM_THREAD_TRUSTED = 32
const GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS = 4
const GET_MODULE_HANDLE_EX_FLAG_PIN = 1
const GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = 2
const GET_MOUSEORKEY_LPARAM = 0
const GET_PS_FEATURESETTING = 4121
const GET_SYSTEM_WOW64_DIRECTORY_NAME_A_A = "GetSystemWow64DirectoryA"
const GET_SYSTEM_WOW64_DIRECTORY_NAME_A_W = "GetSystemWow64DirectoryA"
const GET_SYSTEM_WOW64_DIRECTORY_NAME_W_A = "GetSystemWow64DirectoryW"
const GET_SYSTEM_WOW64_DIRECTORY_NAME_W_W = "GetSystemWow64DirectoryW"
const GET_TAPE_DRIVE_INFORMATION = 1
const GET_TAPE_MEDIA_INFORMATION = 0
const GF_BEGIN = 1
const GF_END = 4
const GF_INERTIA = 2
const GGI_MARK_NONEXISTING_GLYPHS = 1
const GGL_INDEX = 2
const GGL_LEVEL = 1
const GGL_PRIVATE = 4
const GGL_STRING = 3
const GGO_BEZIER = 3
const GGO_BITMAP = 1
const GGO_GLYPH_INDEX = 128
const GGO_GRAY2_BITMAP = 4
const GGO_GRAY4_BITMAP = 5
const GGO_GRAY8_BITMAP = 6
const GGO_METRICS = 0
const GGO_NATIVE = 2
const GGO_UNHINTED = 256
const GHND = 66
const GIDC_ARRIVAL = 1
const GIDC_REMOVAL = 2
const GID_BEGIN = 1
const GID_END = 2
const GID_PAN = 4
const GID_PRESSANDTAP = 7
const GID_ROLLOVER = 7
const GID_ROTATE = 5
const GID_TWOFINGERTAP = 6
const GID_ZOOM = 3
const GL_ID_CANNOTSAVE = 17
const GL_ID_CHOOSECANDIDATE = 40
const GL_ID_INPUTCODE = 38
const GL_ID_INPUTRADICAL = 37
const GL_ID_INPUTREADING = 36
const GL_ID_INPUTSYMBOL = 39
const GL_ID_NOCONVERT = 32
const GL_ID_NODICTIONARY = 16
const GL_ID_NOMODULE = 1
const GL_ID_PRIVATE_FIRST = 32768
const GL_ID_PRIVATE_LAST = 65535
const GL_ID_READINGCONFLICT = 35
const GL_ID_REVERSECONVERSION = 41
const GL_ID_TOOMANYSTROKE = 34
const GL_ID_TYPINGERROR = 33
const GL_ID_UNKNOWN = 0
const GL_LEVEL_ERROR = 2
const GL_LEVEL_FATAL = 1
const GL_LEVEL_INFORMATION = 4
const GL_LEVEL_NOGUIDELINE = 0
const GL_LEVEL_WARNING = 3
const GMDI_GOINTOPOPUPS = 2
const GMDI_USEDISABLED = 1
const GMEM_DDESHARE = 8192
const GMEM_DISCARDABLE = 256
const GMEM_DISCARDED = 16384
const GMEM_FIXED = 0
const GMEM_INVALID_HANDLE = 32768
const GMEM_LOCKCOUNT = 255
const GMEM_LOWER = 4096
const GMEM_MODIFY = 128
const GMEM_MOVEABLE = 2
const GMEM_NOCOMPACT = 16
const GMEM_NODISCARD = 32
const GMEM_NOTIFY = 16384
const GMEM_NOT_BANKED = 4096
const GMEM_SHARE = 8192
const GMEM_VALID_FLAGS = 32626
const GMEM_ZEROINIT = 64
const GMMP_USE_DISPLAY_POINTS = 1
const GMMP_USE_HIGH_RESOLUTION_POINTS = 2
const GM_ADVANCED = 2
const GM_COMPATIBLE = 1
const GM_LAST = 2
const GPTR = 64
const GPT_ATTRIBUTE_PLATFORM_REQUIRED = 1
const GPT_BASIC_DATA_ATTRIBUTE_HIDDEN = 4611686018427387904
const GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER = 9223372036854775808
const GPT_BASIC_DATA_ATTRIBUTE_READ_ONLY = 1152921504606846976
const GPT_BASIC_DATA_ATTRIBUTE_SHADOW_COPY = 2305843009213693952
const GRADIENT_FILL_OP_FLAG = 255
const GRADIENT_FILL_RECT_H = 0
const GRADIENT_FILL_RECT_V = 1
const GRADIENT_FILL_TRIANGLE = 2
const GRAY_BRUSH = 2
const GREEK_CHARSET = 161
const GROUP_NAME = 128
const GROUP_SECURITY_INFORMATION = 2
const GR_GDIOBJECTS = 0
const GR_GDIOBJECTS_PEAK = 2
const GR_GLOBAL = -2
const GR_USEROBJECTS = 1
const GR_USEROBJECTS_PEAK = 4
const GSS_ALLOW_INHERITED_COMMON = 1
const GS_8BIT_INDICES = 1
const GUID_CLASS_COMPORT = 0
const GUID_SERENUM_BUS_ENUMERATOR = 0
const GUI_16BITTASK = 32
const GUI_CARETBLINKING = 1
const GUI_INMENUMODE = 4
const GUI_INMOVESIZE = 2
const GUI_POPUPMENUMODE = 16
const GUI_SYSTEMMENUMODE = 8
const GWFS_INCLUDE_ANCESTORS = 1
const GWLP_HINSTANCE = -6
const GWLP_HWNDPARENT = -8
const GWLP_ID = -12
const GWLP_USERDATA = -21
const GWLP_WNDPROC = -4
const GWL_EXSTYLE = -20
const GWL_HINSTANCE = -6
const GWL_HWNDPARENT = -8
const GWL_ID = -12
const GWL_STYLE = -16
const GWL_USERDATA = -21
const GWL_WNDPROC = -4
const GW_CHILD = 5
const GW_ENABLEDPOPUP = 6
const GW_HWNDFIRST = 0
const GW_HWNDLAST = 1
const GW_HWNDNEXT = 2
const GW_HWNDPREV = 3
const GW_MAX = 6
const GW_OWNER = 4
const GetAltTabInfo = 0
const GetAtomName = 0
const GetBinaryType = 0
const GetCPInfoEx = 0
const GetCalendarInfo = 0
const GetCharABCWidths = 0
const GetCharABCWidthsFloat = 0
const GetCharWidth = 0
const GetCharWidth32 = 0
const GetCharWidthFloat = 0
const GetCharacterPlacement = 0
const GetClassInfo = 0
const GetClassInfoEx = 0
const GetClassLong = 0
const GetClassLongPtr = 0
const GetClassLongPtrA = 0
const GetClassLongPtrW = 0
const GetClassName = 0
const GetClipboardFormatName = 0
const GetCommandLine = 0
const GetCompressedFileSize = 0
const GetCompressedFileSizeTransacted = 0
const GetComputerName = 0
const GetComputerNameEx = 0
const GetConsoleAlias = 0
const GetConsoleAliasExes = 0
const GetConsoleAliasExesLength = 0
const GetConsoleAliases = 0
const GetConsoleAliasesLength = 0
const GetConsoleCommandHistory = 0
const GetConsoleCommandHistoryLength = 0
const GetConsoleOriginalTitle = 0
const GetConsoleTitle = 0
const GetCorePrinterDrivers = 0
const GetCurrencyFormat = 0
const GetCurrentDirectory = 0
const GetCurrentHwProfile = 0
const GetDateFormat = 0
const GetDefaultCommConfig = 0
const GetDefaultPrinter = 0
const GetDiskFreeSpace = 0
const GetDiskFreeSpaceEx = 0
const GetDlgItemText = 0
const GetDllDirectory = 0
const GetDriveType = 0
const GetEnhMetaFile = 0
const GetEnhMetaFileDescription = 0
const GetEnvironmentStringsA = 0
const GetEnvironmentVariable = 0
const GetExceptionCode = 0
const GetExpandedName = 0
const GetFileAttributes = 0
const GetFileAttributesEx = 0
const GetFileAttributesTransacted = 0
const GetFileSecurity = 0
const GetFileTitle = 0
const GetFileVersionInfo = 0
const GetFileVersionInfoEx = 0
const GetFileVersionInfoSize = 0
const GetFileVersionInfoSizeEx = 0
const GetFinalPathNameByHandle = 0
const GetFirmwareEnvironmentVariable = 0
const GetFirmwareEnvironmentVariableEx = 0
const GetForm = 0
const GetFullPathName = 0
const GetFullPathNameTransacted = 0
const GetGeoInfo = 0
const GetGlyphIndices = 0
const GetGlyphOutline = 0
const GetICMProfile = 0
const GetIconInfoEx = 0
const GetJob = 0
const GetKerningPairs = 0
const GetKeyNameText = 0
const GetKeyboardLayoutName = 0
const GetLocaleInfo = 0
const GetLogColorSpace = 0
const GetLogicalDriveStrings = 0
const GetLongPathName = 0
const GetLongPathNameTransacted = 0
const GetMenuItemInfo = 0
const GetMenuString = 0
const GetMessage = 0
const GetMetaFile = 0
const GetModuleFileName = 0
const GetModuleHandle = 0
const GetModuleHandleEx = 0
const GetMonitorInfo = 0
const GetNamedPipeClientComputerName = 0
const GetNamedPipeHandleState = 0
const GetNumberFormat = 0
const GetObject = 0
const GetOpenCardName = 0
const GetOpenFileName = 0
const GetOutlineTextMetrics = 0
const GetPrintProcessorDirectory = 0
const GetPrinter = 0
const GetPrinterData = 0
const GetPrinterDataEx = 0
const GetPrinterDriver = 0
const GetPrinterDriver2 = 0
const GetPrinterDriverDirectory = 0
const GetPrinterDriverPackagePath = 0
const GetPrivateProfileInt = 0
const GetPrivateProfileSection = 0
const GetPrivateProfileSectionNames = 0
const GetPrivateProfileString = 0
const GetPrivateProfileStruct = 0
const GetProfileInt = 0
const GetProfileSection = 0
const GetProfileString = 0
const GetProp = 0
const GetRawInputDeviceInfo = 0
const GetSaveFileName = 0
const GetServiceDisplayName = 0
const GetServiceKeyName = 0
const GetShortPathName = 0
const GetSpoolFileHandle = 0
const GetStartupInfo = 0
const GetStringTypeEx = 0
const GetSystemDirectory = 0
const GetSystemWindowsDirectory = 0
const GetSystemWow64Directory = 0
const GetSystemWow64Directory2 = 0
const GetTabbedTextExtent = 0
const GetTempFileName = 0
const GetTempPath = 0
const GetTextExtentExPoint = 0
const GetTextExtentPoint = 0
const GetTextExtentPoint32 = 0
const GetTextFace = 0
const GetTextMetrics = 0
const GetTimeFormat = 0
const GetUserName = 0
const GetUserObjectInformation = 0
const GetVersionEx = 0
const GetVolumeInformation = 0
const GetVolumeNameForVolumeMountPoint = 0
const GetVolumePathName = 0
const GetVolumePathNamesForVolumeName = 0
const GetWindowLong = 0
const GetWindowLongPtr = 0
const GetWindowLongPtrA = 0
const GetWindowLongPtrW = 0
const GetWindowModuleFileName = 0
const GetWindowText = 0
const GetWindowTextLength = 0
const GetWindowsDirectory = 0
const GlobalAddAtom = 0
const GlobalAddAtomEx = 0
const GlobalFindAtom = 0
const GlobalGetAtomName = 0
const GrayString = 0
const HALFTONE = 4
const HANDLE_FLAG_INHERIT = 1
const HANDLE_FLAG_PROTECT_FROM_CLOSE = 2
const HANGEUL_CHARSET = 129
const HANGUL_CHARSET = 129
const HANGUP_COMPLETE = 5
const HANGUP_PENDING = 4
const HASHSIZE = 97
const HASHTABLE_HASH_1 = 383
const HASHTABLE_NPAGE = 4096
const HASHTABLE_NPAGE_ONE = 4096
const HASHTABLE_NSLOT = 8192
const HAVE_FCHOWN = 1
const HAVE_LSTAT = 1
const HAVE_READLINK = 1
const HAVE_USLEEP = 1
const HBMMENU_CALLBACK = -1
const HCBT_ACTIVATE = 5
const HCBT_CLICKSKIPPED = 6
const HCBT_CREATEWND = 3
const HCBT_DESTROYWND = 4
const HCBT_KEYSKIPPED = 7
const HCBT_MINMAX = 1
const HCBT_MOVESIZE = 0
const HCBT_QS = 2
const HCBT_SETFOCUS = 9
const HCBT_SYSCOMMAND = 8
const HCF_AVAILABLE = 2
const HCF_CONFIRMHOTKEY = 8
const HCF_DEFAULTDESKTOP = 512
const HCF_HIGHCONTRASTON = 1
const HCF_HOTKEYACTIVE = 4
const HCF_HOTKEYAVAILABLE = 64
const HCF_HOTKEYSOUND = 16
const HCF_INDICATOR = 32
const HCF_LOGONDESKTOP = 256
const HCF_OPTION_NOTHEMECHANGE = 4096
const HC_ACTION = 0
const HC_GETNEXT = 1
const HC_NOREM = 3
const HC_NOREMOVE = 3
const HC_SKIP = 2
const HC_SYSMODALOFF = 5
const HC_SYSMODALON = 4
const HDATA_APPOWNED = 1
const HEAP_CREATE_ALIGN_16 = 65536
const HEAP_CREATE_ENABLE_EXECUTE = 262144
const HEAP_CREATE_ENABLE_TRACING = 131072
const HEAP_DISABLE_COALESCE_ON_FREE = 128
const HEAP_FREE_CHECKING_ENABLED = 64
const HEAP_GENERATE_EXCEPTIONS = 4
const HEAP_GROWABLE = 2
const HEAP_MAXIMUM_TAG = 4095
const HEAP_NO_SERIALIZE = 1
const HEAP_PSEUDO_TAG_FLAG = 32768
const HEAP_REALLOC_IN_PLACE_ONLY = 16
const HEAP_TAG_SHIFT = 18
const HEAP_TAIL_CHECKING_ENABLED = 32
const HEAP_ZERO_MEMORY = 8
const HEBREW_CHARSET = 177
const HELPINFO_MENUITEM = 2
const HELPINFO_WINDOW = 1
const HELPMSGSTRINGA = "commdlg_help"
const HELPMSGSTRINGW = "commdlg_help"
const HELP_COMMAND = 258
const HELP_CONTENTS = 3
const HELP_CONTEXT = 1
const HELP_CONTEXTMENU = 10
const HELP_CONTEXTPOPUP = 8
const HELP_FINDER = 11
const HELP_FORCEFILE = 9
const HELP_HELPONHELP = 4
const HELP_INDEX = 3
const HELP_KEY = 257
const HELP_MULTIKEY = 513
const HELP_PARTIALKEY = 261
const HELP_QUIT = 2
const HELP_SETCONTENTS = 5
const HELP_SETINDEX = 5
const HELP_SETPOPUP_POS = 13
const HELP_SETWINPOS = 515
const HELP_TCARD = 32768
const HELP_TCARD_DATA = 16
const HELP_TCARD_OTHER_CALLER = 17
const HELP_WM_HELP = 12
const HFILE_ERROR = -1
const HIDE_WINDOW = 0
const HIGH_PRIORITY_CLASS = 128
const HIGH_SURROGATE_END = 56319
const HIGH_SURROGATE_START = 55296
const HINSTANCE_ERROR = 32
const HISTOGRAM_BUCKET_SIZE = 0
const HISTORY_NO_DUP_FLAG = 1
const HIST_NO_OF_BUCKETS = 24
const HKL_NEXT = 1
const HKL_PREV = 0
const HMONITOR_DECLARED = 1
const HOLLOW_BRUSH = 5
const HORZRES = 8
const HORZSIZE = 4
const HOST_NOT_FOUND = 11001
const HOVER_DEFAULT = 4294967295
const HP_ALGID = 1
const HP_HASHSIZE = 4
const HP_HASHVAL = 2
const HP_HMAC_INFO = 5
const HP_TLS1PRF_LABEL = 6
const HP_TLS1PRF_SEED = 7
const HSHELL_ACCESSIBILITYSTATE = 11
const HSHELL_ACTIVATESHELLWINDOW = 3
const HSHELL_APPCOMMAND = 12
const HSHELL_ENDTASK = 10
const HSHELL_FLASH = 32774
const HSHELL_GETMINRECT = 5
const HSHELL_HIGHBIT = 32768
const HSHELL_LANGUAGE = 8
const HSHELL_MONITORCHANGED = 16
const HSHELL_REDRAW = 6
const HSHELL_RUDEAPPACTIVATED = 32772
const HSHELL_SYSMENU = 9
const HSHELL_TASKMAN = 7
const HSHELL_WINDOWACTIVATED = 4
const HSHELL_WINDOWCREATED = 1
const HSHELL_WINDOWDESTROYED = 2
const HSHELL_WINDOWREPLACED = 13
const HSHELL_WINDOWREPLACING = 14
const HS_API_MAX = 12
const HS_BDIAGONAL = 3
const HS_CROSS = 4
const HS_DIAGCROSS = 5
const HS_FDIAGONAL = 2
const HS_HORIZONTAL = 0
const HS_VERTICAL = 1
const HTBORDER = 18
const HTBOTTOM = 15
const HTBOTTOMLEFT = 16
const HTBOTTOMRIGHT = 17
const HTCAPTION = 2
const HTCLIENT = 1
const HTCLOSE = 20
const HTERROR = -2
const HTGROWBOX = 4
const HTHELP = 21
const HTHSCROLL = 6
const HTLEFT = 10
const HTMAXBUTTON = 9
const HTMENU = 5
const HTMINBUTTON = 8
const HTNOWHERE = 0
const HTOBJECT = 19
const HTREDUCE = 8
const HTRIGHT = 11
const HTSIZE = 4
const HTSIZEFIRST = 10
const HTSIZELAST = 17
const HTSYSMENU = 3
const HTTOP = 12
const HTTOPLEFT = 13
const HTTOPRIGHT = 14
const HTTRANSPARENT = -1
const HTVSCROLL = 7
const HTZOOM = 9
const HUGE = 0
const HUGE_VAL = 0
const HUGE_VALF = 0
const HUGE_VALL = 0
const HWND_MESSAGE = -3
const HWND_NOTOPMOST = -2
const HWND_TOPMOST = -1
const HW_PROFILE_GUIDLEN = 39
const HiddenVolumeClassGuid = 0
const IACE_CHILDREN = 1
const IACE_DEFAULT = 16
const IACE_IGNORENOCONTEXT = 32
const ICMENUMPROC = 0
const ICM_ADDPROFILE = 1
const ICM_DELETEPROFILE = 2
const ICM_DONE_OUTSIDEDC = 4
const ICM_OFF = 1
const ICM_ON = 2
const ICM_QUERY = 3
const ICM_QUERYMATCH = 7
const ICM_QUERYPROFILE = 3
const ICM_REGISTERICMATCHER = 5
const ICM_SETDEFAULTPROFILE = 4
const ICM_UNREGISTERICMATCHER = 6
const ICON_BIG = 1
const ICON_SMALL = 0
const ICON_SMALL2 = 2
const IDABORT = 3
const IDANI_CAPTION = 3
const IDANI_OPEN = 1
const IDCANCEL = 2
const IDCLOSE = 8
const IDCONTINUE = 11
const IDENTIFY_BUFFER_SIZE = 512
const IDHELP = 9
const IDHOT_SNAPDESKTOP = -2
const IDHOT_SNAPWINDOW = -1
const IDH_CANCEL = 28444
const IDH_GENERIC_HELP_BUTTON = 28442
const IDH_HELP = 28445
const IDH_MISSING_CONTEXT = 28441
const IDH_NO_HELP = 28440
const IDH_OK = 28443
const IDIGNORE = 5
const IDI_ERROR = "IDI_HAND"
const IDI_INFORMATION = "IDI_ASTERISK"
const IDI_WARNING = "IDI_EXCLAMATION"
const IDLE_PRIORITY_CLASS = 64
const IDLFLAG_FIN = 1
const IDLFLAG_FLCID = 4
const IDLFLAG_FOUT = 2
const IDLFLAG_FRETVAL = 8
const IDLFLAG_NONE = 0
const IDNO = 7
const IDN_ALLOW_UNASSIGNED = 1
const IDN_EMAIL_ADDRESS = 4
const IDN_RAW_PUNYCODE = 8
const IDN_USE_STD3_ASCII_RULES = 2
const IDOK = 1
const IDRETRY = 4
const IDTIMEOUT = 32000
const IDTRYAGAIN = 10
const IDYES = 6
const ID_CMD = 236
const ID_DEFAULTINST = -2
const ID_PSREBOOTSYSTEM = 3
const ID_PSRESTARTWINDOWS = 2
const IE_BADID = -1
const IE_BAUDRATE = -12
const IE_BYTESIZE = -11
const IE_DEFAULT = -5
const IE_HARDWARE = -10
const IE_MEMORY = -4
const IE_NOPEN = -3
const IE_OPEN = -2
const IFACEMETHODIMP = "STDMETHODIMP"
const IFACEMETHODIMPV = "STDMETHODIMPV"
const IGIMIF_RIGHTMENU = 1
const IGIMII_CMODE = 1
const IGIMII_CONFIGURE = 4
const IGIMII_HELP = 16
const IGIMII_INPUTTOOLS = 64
const IGIMII_OTHER = 32
const IGIMII_SMODE = 2
const IGIMII_TOOLS = 8
const IGNORE = 0
const IGP_CONVERSION = 8
const IGP_PROPERTY = 4
const IGP_SELECT = 24
const IGP_SENTENCE = 12
const IGP_SETCOMPSTR = 20
const IGP_UI = 16
const IID_IOInet = 0
const IID_IOInetBindInfo = 0
const IID_IOInetBindInfoEx = 0
const IID_IOInetPriority = 0
const IID_IOInetProtocol = 0
const IID_IOInetProtocolEx = 0
const IID_IOInetProtocolInfo = 0
const IID_IOInetProtocolRoot = 0
const IID_IOInetProtocolSink = 0
const IID_IOInetProtocolSinkStackable = 0
const IID_IOInetSession = 0
const IID_IOInetThreadSwitch = 0
const IID_NULL = 0
const ILLUMINANT_A = 1
const ILLUMINANT_B = 2
const ILLUMINANT_C = 3
const ILLUMINANT_D50 = 4
const ILLUMINANT_D55 = 5
const ILLUMINANT_D65 = 6
const ILLUMINANT_D75 = 7
const ILLUMINANT_DAYLIGHT = 3
const ILLUMINANT_DEVICE_DEFAULT = 0
const ILLUMINANT_F2 = 8
const ILLUMINANT_FLUORESCENT = 8
const ILLUMINANT_MAX_INDEX = 8
const ILLUMINANT_NTSC = 3
const ILLUMINANT_TUNGSTEN = 1
const IMAGE_ARCHIVE_END = "`\\n"
const IMAGE_ARCHIVE_LINKER_MEMBER = "/               "
const IMAGE_ARCHIVE_LONGNAMES_MEMBER = "//              "
const IMAGE_ARCHIVE_PAD = "\\n"
const IMAGE_ARCHIVE_START = "!<arch>\\n"
const IMAGE_ARCHIVE_START_SIZE = 8
const IMAGE_BITMAP = 0
const IMAGE_COMDAT_SELECT_ANY = 2
const IMAGE_COMDAT_SELECT_ASSOCIATIVE = 5
const IMAGE_COMDAT_SELECT_EXACT_MATCH = 4
const IMAGE_COMDAT_SELECT_LARGEST = 6
const IMAGE_COMDAT_SELECT_NEWEST = 7
const IMAGE_COMDAT_SELECT_NODUPLICATES = 1
const IMAGE_COMDAT_SELECT_SAME_SIZE = 3
const IMAGE_CURSOR = 2
const IMAGE_DEBUG_MISC_EXENAME = 1
const IMAGE_DEBUG_TYPE_BORLAND = 9
const IMAGE_DEBUG_TYPE_CLSID = 11
const IMAGE_DEBUG_TYPE_CODEVIEW = 2
const IMAGE_DEBUG_TYPE_COFF = 1
const IMAGE_DEBUG_TYPE_EXCEPTION = 5
const IMAGE_DEBUG_TYPE_FIXUP = 6
const IMAGE_DEBUG_TYPE_FPO = 3
const IMAGE_DEBUG_TYPE_MISC = 4
const IMAGE_DEBUG_TYPE_OMAP_FROM_SRC = 8
const IMAGE_DEBUG_TYPE_OMAP_TO_SRC = 7
const IMAGE_DEBUG_TYPE_RESERVED10 = 10
const IMAGE_DEBUG_TYPE_UNKNOWN = 0
const IMAGE_DIRECTORY_ENTRY_ARCHITECTURE = 7
const IMAGE_DIRECTORY_ENTRY_BASERELOC = 5
const IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11
const IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14
const IMAGE_DIRECTORY_ENTRY_DEBUG = 6
const IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13
const IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3
const IMAGE_DIRECTORY_ENTRY_EXPORT = 0
const IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8
const IMAGE_DIRECTORY_ENTRY_IAT = 12
const IMAGE_DIRECTORY_ENTRY_IMPORT = 1
const IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10
const IMAGE_DIRECTORY_ENTRY_RESOURCE = 2
const IMAGE_DIRECTORY_ENTRY_SECURITY = 4
const IMAGE_DIRECTORY_ENTRY_TLS = 9
const IMAGE_DLLCHARACTERISTICS_APPCONTAINER = 4096
const IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = 64
const IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY = 128
const IMAGE_DLLCHARACTERISTICS_GUARD_CF = 16384
const IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA = 32
const IMAGE_DLLCHARACTERISTICS_NO_BIND = 2048
const IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = 512
const IMAGE_DLLCHARACTERISTICS_NO_SEH = 1024
const IMAGE_DLLCHARACTERISTICS_NX_COMPAT = 256
const IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = 32768
const IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = 8192
const IMAGE_DOS_SIGNATURE = 23117
const IMAGE_ENHMETAFILE = 3
const IMAGE_FILE_32BIT_MACHINE = 256
const IMAGE_FILE_AGGRESIVE_WS_TRIM = 16
const IMAGE_FILE_BYTES_REVERSED_HI = 32768
const IMAGE_FILE_BYTES_REVERSED_LO = 128
const IMAGE_FILE_DEBUG_STRIPPED = 512
const IMAGE_FILE_DLL = 8192
const IMAGE_FILE_EXECUTABLE_IMAGE = 2
const IMAGE_FILE_LARGE_ADDRESS_AWARE = 32
const IMAGE_FILE_LINE_NUMS_STRIPPED = 4
const IMAGE_FILE_LOCAL_SYMS_STRIPPED = 8
const IMAGE_FILE_MACHINE_ALPHA = 388
const IMAGE_FILE_MACHINE_ALPHA64 = 644
const IMAGE_FILE_MACHINE_AM33 = 467
const IMAGE_FILE_MACHINE_AMD64 = 34404
const IMAGE_FILE_MACHINE_ARM = 448
const IMAGE_FILE_MACHINE_ARM64 = 43620
const IMAGE_FILE_MACHINE_ARMNT = 452
const IMAGE_FILE_MACHINE_ARMV7 = 452
const IMAGE_FILE_MACHINE_AXP64 = 644
const IMAGE_FILE_MACHINE_CEE = 49390
const IMAGE_FILE_MACHINE_CEF = 3311
const IMAGE_FILE_MACHINE_EBC = 3772
const IMAGE_FILE_MACHINE_I386 = 332
const IMAGE_FILE_MACHINE_IA64 = 512
const IMAGE_FILE_MACHINE_M32R = 36929
const IMAGE_FILE_MACHINE_MIPS16 = 614
const IMAGE_FILE_MACHINE_MIPSFPU = 870
const IMAGE_FILE_MACHINE_MIPSFPU16 = 1126
const IMAGE_FILE_MACHINE_POWERPC = 496
const IMAGE_FILE_MACHINE_POWERPCFP = 497
const IMAGE_FILE_MACHINE_R10000 = 360
const IMAGE_FILE_MACHINE_R3000 = 354
const IMAGE_FILE_MACHINE_R4000 = 358
const IMAGE_FILE_MACHINE_SH3 = 418
const IMAGE_FILE_MACHINE_SH3DSP = 419
const IMAGE_FILE_MACHINE_SH3E = 420
const IMAGE_FILE_MACHINE_SH4 = 422
const IMAGE_FILE_MACHINE_SH5 = 424
const IMAGE_FILE_MACHINE_THUMB = 450
const IMAGE_FILE_MACHINE_TRICORE = 1312
const IMAGE_FILE_MACHINE_UNKNOWN = 0
const IMAGE_FILE_MACHINE_WCEMIPSV2 = 361
const IMAGE_FILE_NET_RUN_FROM_SWAP = 2048
const IMAGE_FILE_RELOCS_STRIPPED = 1
const IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 1024
const IMAGE_FILE_SYSTEM = 4096
const IMAGE_FILE_UP_SYSTEM_ONLY = 16384
const IMAGE_ICON = 1
const IMAGE_NT_OPTIONAL_HDR32_MAGIC = 267
const IMAGE_NT_OPTIONAL_HDR64_MAGIC = 523
const IMAGE_NT_OPTIONAL_HDR_MAGIC = 267
const IMAGE_NT_SIGNATURE = 17744
const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16
const IMAGE_ORDINAL_FLAG = 2147483648
const IMAGE_ORDINAL_FLAG32 = 2147483648
const IMAGE_ORDINAL_FLAG64 = 9223372036854775808
const IMAGE_OS2_SIGNATURE = 17742
const IMAGE_OS2_SIGNATURE_LE = 17740
const IMAGE_REL_ALPHA_ABSOLUTE = 0
const IMAGE_REL_ALPHA_BRADDR = 7
const IMAGE_REL_ALPHA_GPDISP = 6
const IMAGE_REL_ALPHA_GPREL32 = 3
const IMAGE_REL_ALPHA_GPRELHI = 23
const IMAGE_REL_ALPHA_GPRELLO = 22
const IMAGE_REL_ALPHA_HINT = 8
const IMAGE_REL_ALPHA_INLINE_REFLONG = 9
const IMAGE_REL_ALPHA_LITERAL = 4
const IMAGE_REL_ALPHA_LITUSE = 5
const IMAGE_REL_ALPHA_MATCH = 13
const IMAGE_REL_ALPHA_PAIR = 12
const IMAGE_REL_ALPHA_REFHI = 10
const IMAGE_REL_ALPHA_REFLO = 11
const IMAGE_REL_ALPHA_REFLONG = 1
const IMAGE_REL_ALPHA_REFLONGNB = 16
const IMAGE_REL_ALPHA_REFQ1 = 21
const IMAGE_REL_ALPHA_REFQ2 = 20
const IMAGE_REL_ALPHA_REFQ3 = 19
const IMAGE_REL_ALPHA_REFQUAD = 2
const IMAGE_REL_ALPHA_SECREL = 15
const IMAGE_REL_ALPHA_SECRELHI = 18
const IMAGE_REL_ALPHA_SECRELLO = 17
const IMAGE_REL_ALPHA_SECTION = 14
const IMAGE_REL_AMD64_ABSOLUTE = 0
const IMAGE_REL_AMD64_ADDR32 = 2
const IMAGE_REL_AMD64_ADDR32NB = 3
const IMAGE_REL_AMD64_ADDR64 = 1
const IMAGE_REL_AMD64_PAIR = 15
const IMAGE_REL_AMD64_REL32 = 4
const IMAGE_REL_AMD64_REL32_1 = 5
const IMAGE_REL_AMD64_REL32_2 = 6
const IMAGE_REL_AMD64_REL32_3 = 7
const IMAGE_REL_AMD64_REL32_4 = 8
const IMAGE_REL_AMD64_REL32_5 = 9
const IMAGE_REL_AMD64_SECREL = 11
const IMAGE_REL_AMD64_SECREL7 = 12
const IMAGE_REL_AMD64_SECTION = 10
const IMAGE_REL_AMD64_SREL32 = 14
const IMAGE_REL_AMD64_SSPAN32 = 16
const IMAGE_REL_AMD64_TOKEN = 13
const IMAGE_REL_AM_ABSOLUTE = 0
const IMAGE_REL_AM_ADDR32 = 1
const IMAGE_REL_AM_ADDR32NB = 2
const IMAGE_REL_AM_CALL32 = 3
const IMAGE_REL_AM_FUNCINFO = 4
const IMAGE_REL_AM_REL32_1 = 5
const IMAGE_REL_AM_REL32_2 = 6
const IMAGE_REL_AM_SECREL = 7
const IMAGE_REL_AM_SECTION = 8
const IMAGE_REL_AM_TOKEN = 9
const IMAGE_REL_ARM_ABSOLUTE = 0
const IMAGE_REL_ARM_ADDR32 = 1
const IMAGE_REL_ARM_ADDR32NB = 2
const IMAGE_REL_ARM_BLX11 = 9
const IMAGE_REL_ARM_BLX23T = 21
const IMAGE_REL_ARM_BLX24 = 8
const IMAGE_REL_ARM_BRANCH11 = 4
const IMAGE_REL_ARM_BRANCH20T = 18
const IMAGE_REL_ARM_BRANCH24 = 3
const IMAGE_REL_ARM_BRANCH24T = 20
const IMAGE_REL_ARM_GPREL12 = 6
const IMAGE_REL_ARM_GPREL7 = 7
const IMAGE_REL_ARM_MOV32 = 16
const IMAGE_REL_ARM_MOV32A = 16
const IMAGE_REL_ARM_MOV32T = 17
const IMAGE_REL_ARM_SECREL = 15
const IMAGE_REL_ARM_SECTION = 14
const IMAGE_REL_ARM_TOKEN = 5
const IMAGE_REL_BASED_ABSOLUTE = 0
const IMAGE_REL_BASED_ARM_MOV32 = 5
const IMAGE_REL_BASED_DIR64 = 10
const IMAGE_REL_BASED_HIGH = 1
const IMAGE_REL_BASED_HIGHADJ = 4
const IMAGE_REL_BASED_HIGHLOW = 3
const IMAGE_REL_BASED_IA64_IMM64 = 9
const IMAGE_REL_BASED_LOW = 2
const IMAGE_REL_BASED_MIPS_JMPADDR = 5
const IMAGE_REL_BASED_MIPS_JMPADDR16 = 9
const IMAGE_REL_BASED_THUMB_MOV32 = 7
const IMAGE_REL_CEE_ABSOLUTE = 0
const IMAGE_REL_CEE_ADDR32 = 1
const IMAGE_REL_CEE_ADDR32NB = 3
const IMAGE_REL_CEE_ADDR64 = 2
const IMAGE_REL_CEE_SECREL = 5
const IMAGE_REL_CEE_SECTION = 4
const IMAGE_REL_CEE_TOKEN = 6
const IMAGE_REL_CEF_ABSOLUTE = 0
const IMAGE_REL_CEF_ADDR32 = 1
const IMAGE_REL_CEF_ADDR32NB = 3
const IMAGE_REL_CEF_ADDR64 = 2
const IMAGE_REL_CEF_SECREL = 5
const IMAGE_REL_CEF_SECTION = 4
const IMAGE_REL_CEF_TOKEN = 6
const IMAGE_REL_EBC_ABSOLUTE = 0
const IMAGE_REL_EBC_ADDR32NB = 1
const IMAGE_REL_EBC_REL32 = 2
const IMAGE_REL_EBC_SECREL = 4
const IMAGE_REL_EBC_SECTION = 3
const IMAGE_REL_I386_ABSOLUTE = 0
const IMAGE_REL_I386_DIR16 = 1
const IMAGE_REL_I386_DIR32 = 6
const IMAGE_REL_I386_DIR32NB = 7
const IMAGE_REL_I386_REL16 = 2
const IMAGE_REL_I386_REL32 = 20
const IMAGE_REL_I386_SECREL = 11
const IMAGE_REL_I386_SECREL7 = 13
const IMAGE_REL_I386_SECTION = 10
const IMAGE_REL_I386_SEG12 = 9
const IMAGE_REL_I386_TOKEN = 12
const IMAGE_REL_IA64_ABSOLUTE = 0
const IMAGE_REL_IA64_ADDEND = 31
const IMAGE_REL_IA64_DIR32 = 4
const IMAGE_REL_IA64_DIR32NB = 16
const IMAGE_REL_IA64_DIR64 = 5
const IMAGE_REL_IA64_GPREL22 = 9
const IMAGE_REL_IA64_GPREL32 = 28
const IMAGE_REL_IA64_IMM14 = 1
const IMAGE_REL_IA64_IMM22 = 2
const IMAGE_REL_IA64_IMM64 = 3
const IMAGE_REL_IA64_IMMGPREL64 = 26
const IMAGE_REL_IA64_LTOFF22 = 10
const IMAGE_REL_IA64_PCREL21B = 6
const IMAGE_REL_IA64_PCREL21F = 8
const IMAGE_REL_IA64_PCREL21M = 7
const IMAGE_REL_IA64_PCREL60B = 22
const IMAGE_REL_IA64_PCREL60F = 23
const IMAGE_REL_IA64_PCREL60I = 24
const IMAGE_REL_IA64_PCREL60M = 25
const IMAGE_REL_IA64_PCREL60X = 21
const IMAGE_REL_IA64_SECREL22 = 12
const IMAGE_REL_IA64_SECREL32 = 14
const IMAGE_REL_IA64_SECREL64I = 13
const IMAGE_REL_IA64_SECTION = 11
const IMAGE_REL_IA64_SREL14 = 17
const IMAGE_REL_IA64_SREL22 = 18
const IMAGE_REL_IA64_SREL32 = 19
const IMAGE_REL_IA64_TOKEN = 27
const IMAGE_REL_IA64_UREL32 = 20
const IMAGE_REL_M32R_ABSOLUTE = 0
const IMAGE_REL_M32R_ADDR24 = 3
const IMAGE_REL_M32R_ADDR32 = 1
const IMAGE_REL_M32R_ADDR32NB = 2
const IMAGE_REL_M32R_GPREL16 = 4
const IMAGE_REL_M32R_PAIR = 11
const IMAGE_REL_M32R_PCREL16 = 6
const IMAGE_REL_M32R_PCREL24 = 5
const IMAGE_REL_M32R_PCREL8 = 7
const IMAGE_REL_M32R_REFHALF = 8
const IMAGE_REL_M32R_REFHI = 9
const IMAGE_REL_M32R_REFLO = 10
const IMAGE_REL_M32R_SECREL32 = 13
const IMAGE_REL_M32R_SECTION = 12
const IMAGE_REL_M32R_TOKEN = 14
const IMAGE_REL_MIPS_ABSOLUTE = 0
const IMAGE_REL_MIPS_GPREL = 6
const IMAGE_REL_MIPS_JMPADDR = 3
const IMAGE_REL_MIPS_JMPADDR16 = 16
const IMAGE_REL_MIPS_LITERAL = 7
const IMAGE_REL_MIPS_PAIR = 37
const IMAGE_REL_MIPS_REFHALF = 1
const IMAGE_REL_MIPS_REFHI = 4
const IMAGE_REL_MIPS_REFLO = 5
const IMAGE_REL_MIPS_REFWORD = 2
const IMAGE_REL_MIPS_REFWORDNB = 34
const IMAGE_REL_MIPS_SECREL = 11
const IMAGE_REL_MIPS_SECRELHI = 13
const IMAGE_REL_MIPS_SECRELLO = 12
const IMAGE_REL_MIPS_SECTION = 10
const IMAGE_REL_MIPS_TOKEN = 14
const IMAGE_REL_PPC_ABSOLUTE = 0
const IMAGE_REL_PPC_ADDR14 = 5
const IMAGE_REL_PPC_ADDR16 = 4
const IMAGE_REL_PPC_ADDR24 = 3
const IMAGE_REL_PPC_ADDR32 = 2
const IMAGE_REL_PPC_ADDR32NB = 10
const IMAGE_REL_PPC_ADDR64 = 1
const IMAGE_REL_PPC_BRNTAKEN = 1024
const IMAGE_REL_PPC_BRTAKEN = 512
const IMAGE_REL_PPC_GPREL = 21
const IMAGE_REL_PPC_IFGLUE = 13
const IMAGE_REL_PPC_IMGLUE = 14
const IMAGE_REL_PPC_NEG = 256
const IMAGE_REL_PPC_PAIR = 18
const IMAGE_REL_PPC_REFHI = 16
const IMAGE_REL_PPC_REFLO = 17
const IMAGE_REL_PPC_REL14 = 7
const IMAGE_REL_PPC_REL24 = 6
const IMAGE_REL_PPC_SECREL = 11
const IMAGE_REL_PPC_SECREL16 = 15
const IMAGE_REL_PPC_SECRELHI = 20
const IMAGE_REL_PPC_SECRELLO = 19
const IMAGE_REL_PPC_SECTION = 12
const IMAGE_REL_PPC_TOCDEFN = 2048
const IMAGE_REL_PPC_TOCREL14 = 9
const IMAGE_REL_PPC_TOCREL16 = 8
const IMAGE_REL_PPC_TOKEN = 22
const IMAGE_REL_PPC_TYPEMASK = 255
const IMAGE_REL_SH3_ABSOLUTE = 0
const IMAGE_REL_SH3_DIRECT16 = 1
const IMAGE_REL_SH3_DIRECT32 = 2
const IMAGE_REL_SH3_DIRECT32_NB = 16
const IMAGE_REL_SH3_DIRECT4 = 6
const IMAGE_REL_SH3_DIRECT4_LONG = 8
const IMAGE_REL_SH3_DIRECT4_WORD = 7
const IMAGE_REL_SH3_DIRECT8 = 3
const IMAGE_REL_SH3_DIRECT8_LONG = 5
const IMAGE_REL_SH3_DIRECT8_WORD = 4
const IMAGE_REL_SH3_GPREL4_LONG = 17
const IMAGE_REL_SH3_PCREL12_WORD = 11
const IMAGE_REL_SH3_PCREL8_LONG = 10
const IMAGE_REL_SH3_PCREL8_WORD = 9
const IMAGE_REL_SH3_SECREL = 15
const IMAGE_REL_SH3_SECTION = 14
const IMAGE_REL_SH3_SIZEOF_SECTION = 13
const IMAGE_REL_SH3_STARTOF_SECTION = 12
const IMAGE_REL_SH3_TOKEN = 18
const IMAGE_REL_SHM_PAIR = 24
const IMAGE_REL_SHM_PCRELPT = 19
const IMAGE_REL_SHM_REFHALF = 21
const IMAGE_REL_SHM_REFLO = 20
const IMAGE_REL_SHM_RELHALF = 23
const IMAGE_REL_SHM_RELLO = 22
const IMAGE_REL_SH_NOMODE = 32768
const IMAGE_REL_THUMB_BLX23 = 21
const IMAGE_REL_THUMB_BRANCH20 = 18
const IMAGE_REL_THUMB_BRANCH24 = 20
const IMAGE_REL_THUMB_MOV32 = 17
const IMAGE_RESOURCE_DATA_IS_DIRECTORY = 2147483648
const IMAGE_RESOURCE_NAME_IS_STRING = 2147483648
const IMAGE_ROM_OPTIONAL_HDR_MAGIC = 263
const IMAGE_SCN_ALIGN_1024BYTES = 11534336
const IMAGE_SCN_ALIGN_128BYTES = 8388608
const IMAGE_SCN_ALIGN_16BYTES = 5242880
const IMAGE_SCN_ALIGN_1BYTES = 1048576
const IMAGE_SCN_ALIGN_2048BYTES = 12582912
const IMAGE_SCN_ALIGN_256BYTES = 9437184
const IMAGE_SCN_ALIGN_2BYTES = 2097152
const IMAGE_SCN_ALIGN_32BYTES = 6291456
const IMAGE_SCN_ALIGN_4096BYTES = 13631488
const IMAGE_SCN_ALIGN_4BYTES = 3145728
const IMAGE_SCN_ALIGN_512BYTES = 10485760
const IMAGE_SCN_ALIGN_64BYTES = 7340032
const IMAGE_SCN_ALIGN_8192BYTES = 14680064
const IMAGE_SCN_ALIGN_8BYTES = 4194304
const IMAGE_SCN_ALIGN_MASK = 15728640
const IMAGE_SCN_CNT_CODE = 32
const IMAGE_SCN_CNT_INITIALIZED_DATA = 64
const IMAGE_SCN_CNT_UNINITIALIZED_DATA = 128
const IMAGE_SCN_GPREL = 32768
const IMAGE_SCN_LNK_COMDAT = 4096
const IMAGE_SCN_LNK_INFO = 512
const IMAGE_SCN_LNK_NRELOC_OVFL = 16777216
const IMAGE_SCN_LNK_OTHER = 256
const IMAGE_SCN_LNK_REMOVE = 2048
const IMAGE_SCN_MEM_16BIT = 131072
const IMAGE_SCN_MEM_DISCARDABLE = 33554432
const IMAGE_SCN_MEM_EXECUTE = 536870912
const IMAGE_SCN_MEM_FARDATA = 32768
const IMAGE_SCN_MEM_LOCKED = 262144
const IMAGE_SCN_MEM_NOT_CACHED = 67108864
const IMAGE_SCN_MEM_NOT_PAGED = 134217728
const IMAGE_SCN_MEM_PRELOAD = 524288
const IMAGE_SCN_MEM_PURGEABLE = 131072
const IMAGE_SCN_MEM_READ = 1073741824
const IMAGE_SCN_MEM_SHARED = 268435456
const IMAGE_SCN_MEM_WRITE = 2147483648
const IMAGE_SCN_NO_DEFER_SPEC_EXC = 16384
const IMAGE_SCN_SCALE_INDEX = 1
const IMAGE_SCN_TYPE_NO_PAD = 8
const IMAGE_SEPARATE_DEBUG_FLAGS_MASK = 32768
const IMAGE_SEPARATE_DEBUG_MISMATCH = 32768
const IMAGE_SEPARATE_DEBUG_SIGNATURE = 18756
const IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR = 60
const IMAGE_SIZEOF_AUX_SYMBOL = 18
const IMAGE_SIZEOF_BASE_RELOCATION = 8
const IMAGE_SIZEOF_FILE_HEADER = 20
const IMAGE_SIZEOF_LINENUMBER = 6
const IMAGE_SIZEOF_NT_OPTIONAL32_HEADER = 224
const IMAGE_SIZEOF_NT_OPTIONAL64_HEADER = 240
const IMAGE_SIZEOF_NT_OPTIONAL_HEADER = 224
const IMAGE_SIZEOF_RELOCATION = 10
const IMAGE_SIZEOF_ROM_OPTIONAL_HEADER = 56
const IMAGE_SIZEOF_SECTION_HEADER = 40
const IMAGE_SIZEOF_SHORT_NAME = 8
const IMAGE_SIZEOF_STD_OPTIONAL_HEADER = 28
const IMAGE_SIZEOF_SYMBOL = 18
const IMAGE_SUBSYSTEM_EFI_APPLICATION = 10
const IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11
const IMAGE_SUBSYSTEM_EFI_ROM = 13
const IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12
const IMAGE_SUBSYSTEM_NATIVE = 1
const IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8
const IMAGE_SUBSYSTEM_OS2_CUI = 5
const IMAGE_SUBSYSTEM_POSIX_CUI = 7
const IMAGE_SUBSYSTEM_UNKNOWN = 0
const IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16
const IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9
const IMAGE_SUBSYSTEM_WINDOWS_CUI = 3
const IMAGE_SUBSYSTEM_WINDOWS_GUI = 2
const IMAGE_SUBSYSTEM_XBOX = 14
const IMAGE_SYM_ABSOLUTE = -1
const IMAGE_SYM_CLASS_ARGUMENT = 9
const IMAGE_SYM_CLASS_AUTOMATIC = 1
const IMAGE_SYM_CLASS_BIT_FIELD = 18
const IMAGE_SYM_CLASS_BLOCK = 100
const IMAGE_SYM_CLASS_CLR_TOKEN = 107
const IMAGE_SYM_CLASS_END_OF_FUNCTION = -1
const IMAGE_SYM_CLASS_END_OF_STRUCT = 102
const IMAGE_SYM_CLASS_ENUM_TAG = 15
const IMAGE_SYM_CLASS_EXTERNAL = 2
const IMAGE_SYM_CLASS_EXTERNAL_DEF = 5
const IMAGE_SYM_CLASS_FAR_EXTERNAL = 68
const IMAGE_SYM_CLASS_FILE = 103
const IMAGE_SYM_CLASS_FUNCTION = 101
const IMAGE_SYM_CLASS_LABEL = 6
const IMAGE_SYM_CLASS_MEMBER_OF_ENUM = 16
const IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = 8
const IMAGE_SYM_CLASS_MEMBER_OF_UNION = 11
const IMAGE_SYM_CLASS_NULL = 0
const IMAGE_SYM_CLASS_REGISTER = 4
const IMAGE_SYM_CLASS_REGISTER_PARAM = 17
const IMAGE_SYM_CLASS_SECTION = 104
const IMAGE_SYM_CLASS_STATIC = 3
const IMAGE_SYM_CLASS_STRUCT_TAG = 10
const IMAGE_SYM_CLASS_TYPE_DEFINITION = 13
const IMAGE_SYM_CLASS_UNDEFINED_LABEL = 7
const IMAGE_SYM_CLASS_UNDEFINED_STATIC = 14
const IMAGE_SYM_CLASS_UNION_TAG = 12
const IMAGE_SYM_CLASS_WEAK_EXTERNAL = 105
const IMAGE_SYM_DEBUG = -2
const IMAGE_SYM_DTYPE_ARRAY = 3
const IMAGE_SYM_DTYPE_FUNCTION = 2
const IMAGE_SYM_DTYPE_NULL = 0
const IMAGE_SYM_DTYPE_POINTER = 1
const IMAGE_SYM_SECTION_MAX = 65279
const IMAGE_SYM_SECTION_MAX_EX = 2147483647
const IMAGE_SYM_TYPE_BYTE = 12
const IMAGE_SYM_TYPE_CHAR = 2
const IMAGE_SYM_TYPE_DOUBLE = 7
const IMAGE_SYM_TYPE_DWORD = 15
const IMAGE_SYM_TYPE_ENUM = 10
const IMAGE_SYM_TYPE_FLOAT = 6
const IMAGE_SYM_TYPE_INT = 4
const IMAGE_SYM_TYPE_LONG = 5
const IMAGE_SYM_TYPE_MOE = 11
const IMAGE_SYM_TYPE_NULL = 0
const IMAGE_SYM_TYPE_PCODE = 32768
const IMAGE_SYM_TYPE_SHORT = 3
const IMAGE_SYM_TYPE_STRUCT = 8
const IMAGE_SYM_TYPE_UINT = 14
const IMAGE_SYM_TYPE_UNION = 9
const IMAGE_SYM_TYPE_VOID = 1
const IMAGE_SYM_TYPE_WORD = 13
const IMAGE_VXD_SIGNATURE = 17740
const IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3
const IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2
const IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1
const IMC_CLOSESTATUSWINDOW = 33
const IMC_GETCANDIDATEPOS = 7
const IMC_GETCOMPOSITIONFONT = 9
const IMC_GETCOMPOSITIONWINDOW = 11
const IMC_GETSTATUSWINDOWPOS = 15
const IMC_OPENSTATUSWINDOW = 34
const IMC_SETCANDIDATEPOS = 8
const IMC_SETCOMPOSITIONFONT = 10
const IMC_SETCOMPOSITIONWINDOW = 12
const IMC_SETSTATUSWINDOWPOS = 16
const IMEMENUITEM_STRING_SIZE = 80
const IMEVER_0310 = 196618
const IMEVER_0400 = 262144
const IME_CAND_CODE = 2
const IME_CAND_MEANING = 3
const IME_CAND_RADICAL = 4
const IME_CAND_READ = 1
const IME_CAND_STROKE = 5
const IME_CAND_UNKNOWN = 0
const IME_CHOTKEY_IME_NONIME_TOGGLE = 16
const IME_CHOTKEY_SHAPE_TOGGLE = 17
const IME_CHOTKEY_SYMBOL_TOGGLE = 18
const IME_CMODE_ALPHANUMERIC = 0
const IME_CMODE_CHARCODE = 32
const IME_CMODE_CHINESE = 1
const IME_CMODE_EUDC = 512
const IME_CMODE_FIXED = 2048
const IME_CMODE_FULLSHAPE = 8
const IME_CMODE_HANGEUL = 1
const IME_CMODE_HANGUL = 1
const IME_CMODE_HANJACONVERT = 64
const IME_CMODE_JAPANESE = 1
const IME_CMODE_KATAKANA = 2
const IME_CMODE_LANGUAGE = 3
const IME_CMODE_NATIVE = 1
const IME_CMODE_NOCONVERSION = 256
const IME_CMODE_RESERVED = 4026531840
const IME_CMODE_ROMAN = 16
const IME_CMODE_SOFTKBD = 128
const IME_CMODE_SYMBOL = 1024
const IME_CONFIG_GENERAL = 1
const IME_CONFIG_REGISTERWORD = 2
const IME_CONFIG_SELECTDICTIONARY = 3
const IME_ESC_AUTOMATA = 4105
const IME_ESC_GETHELPFILENAME = 4107
const IME_ESC_GET_EUDC_DICTIONARY = 4099
const IME_ESC_HANJA_MODE = 4104
const IME_ESC_IME_NAME = 4102
const IME_ESC_MAX_KEY = 4101
const IME_ESC_PRIVATE_FIRST = 2048
const IME_ESC_PRIVATE_HOTKEY = 4106
const IME_ESC_PRIVATE_LAST = 4095
const IME_ESC_QUERY_SUPPORT = 3
const IME_ESC_RESERVED_FIRST = 4
const IME_ESC_RESERVED_LAST = 2047
const IME_ESC_SEQUENCE_TO_INTERNAL = 4097
const IME_ESC_SET_EUDC_DICTIONARY = 4100
const IME_ESC_SYNC_HOTKEY = 4103
const IME_HOTKEY_DSWITCH_FIRST = 256
const IME_HOTKEY_DSWITCH_LAST = 287
const IME_HOTKEY_PRIVATE_FIRST = 512
const IME_HOTKEY_PRIVATE_LAST = 543
const IME_ITHOTKEY_PREVIOUS_COMPOSITION = 513
const IME_ITHOTKEY_RECONVERTSTRING = 515
const IME_ITHOTKEY_RESEND_RESULTSTR = 512
const IME_ITHOTKEY_UISTYLE_TOGGLE = 514
const IME_JHOTKEY_CLOSE_OPEN = 48
const IME_KHOTKEY_ENGLISH = 82
const IME_KHOTKEY_HANJACONVERT = 81
const IME_KHOTKEY_SHAPE_TOGGLE = 80
const IME_PROP_AT_CARET = 65536
const IME_PROP_CANDLIST_START_FROM_1 = 262144
const IME_PROP_COMPLETE_ON_UNSELECT = 1048576
const IME_PROP_SPECIAL_UI = 131072
const IME_PROP_UNICODE = 524288
const IME_REGWORD_STYLE_EUDC = 1
const IME_REGWORD_STYLE_USER_FIRST = 2147483648
const IME_REGWORD_STYLE_USER_LAST = 4294967295
const IME_SMODE_AUTOMATIC = 4
const IME_SMODE_CONVERSATION = 16
const IME_SMODE_NONE = 0
const IME_SMODE_PHRASEPREDICT = 8
const IME_SMODE_PLAURALCLAUSE = 1
const IME_SMODE_RESERVED = 61440
const IME_SMODE_SINGLECONVERT = 2
const IME_THOTKEY_IME_NONIME_TOGGLE = 112
const IME_THOTKEY_SHAPE_TOGGLE = 113
const IME_THOTKEY_SYMBOL_TOGGLE = 114
const IMFS_CHECKED = 8
const IMFS_DEFAULT = 4096
const IMFS_DISABLED = 3
const IMFS_ENABLED = 0
const IMFS_GRAYED = 3
const IMFS_HILITE = 128
const IMFS_UNCHECKED = 0
const IMFS_UNHILITE = 0
const IMFT_RADIOCHECK = 1
const IMFT_SEPARATOR = 2
const IMFT_SUBMENU = 4
const IMM_ERROR_GENERAL = -2
const IMM_ERROR_NODATA = -1
const IMN_CHANGECANDIDATE = 3
const IMN_CLOSECANDIDATE = 4
const IMN_CLOSESTATUSWINDOW = 1
const IMN_GUIDELINE = 13
const IMN_OPENCANDIDATE = 5
const IMN_OPENSTATUSWINDOW = 2
const IMN_PRIVATE = 14
const IMN_SETCANDIDATEPOS = 9
const IMN_SETCOMPOSITIONFONT = 10
const IMN_SETCOMPOSITIONWINDOW = 11
const IMN_SETCONVERSIONMODE = 6
const IMN_SETOPENSTATUS = 8
const IMN_SETSENTENCEMODE = 7
const IMN_SETSTATUSWINDOWPOS = 12
const IMPLINK_HIGHEXPER = 158
const IMPLINK_IP = 155
const IMPLINK_LOWEXPER = 156
const IMPLTYPEFLAG_FDEFAULT = 1
const IMPLTYPEFLAG_FDEFAULTVTABLE = 8
const IMPLTYPEFLAG_FRESTRICTED = 4
const IMPLTYPEFLAG_FSOURCE = 2
const IMPORT_OBJECT_HDR_SIG2 = 65535
const IMR_CANDIDATEWINDOW = 2
const IMR_COMPOSITIONFONT = 3
const IMR_COMPOSITIONWINDOW = 1
const IMR_CONFIRMRECONVERTSTRING = 5
const IMR_DOCUMENTFEED = 7
const IMR_QUERYCHARPOSITION = 6
const IMR_RECONVERTSTRING = 4
const INADDR_LOOPBACK = 2130706433
const INADDR_NONE = 4294967295
const INCRINIT_NORMAL = 0
const INCRINIT_ROOT = 2
const INCRINIT_TASK = 1
const INDEXID_CONTAINER = 0
const INDEXID_OBJECT = 0
const INET_E_DEFAULT_ACTION = "INET_E_USE_DEFAULT_PROTOCOLHANDLER"
const INET_E_ERROR_LAST = "INET_E_BLOCKED_PLUGGABLE_PROTOCOL"
const INFINITE = 4294967295
const INFINITY = 0
const INHERITED_ACE = 16
const INHERIT_CALLER_PRIORITY = 131072
const INHERIT_ONLY_ACE = 8
const INHERIT_PARENT_AFFINITY = 65536
const INITFLAG_AlterAdd = 3
const INITFLAG_AlterDrop = 2
const INITFLAG_AlterMask = 3
const INITFLAG_AlterRename = 1
const INIT_ONCE_ASYNC = 2
const INIT_ONCE_CHECK_ONLY = 1
const INIT_ONCE_CTX_RESERVED_BITS = 2
const INIT_ONCE_INIT_FAILED = 4
const INIT_ONCE_STATIC_INIT = "RTL_RUN_ONCE_INIT"
const INLINEFUNC_affinity = 4
const INLINEFUNC_coalesce = 0
const INLINEFUNC_expr_compare = 3
const INLINEFUNC_expr_implies_expr = 2
const INLINEFUNC_iif = 5
const INLINEFUNC_implies_nonnull_row = 1
const INLINEFUNC_sqlite_offset = 6
const INLINEFUNC_unlikely = 99
const INPLACE_E_FIRST = 2147746208
const INPLACE_E_LAST = 2147746223
const INPLACE_S_FIRST = 262560
const INPLACE_S_LAST = 262575
const INPUTLANGCHANGE_BACKWARD = 4
const INPUTLANGCHANGE_FORWARD = 2
const INPUTLANGCHANGE_SYSCHARSET = 1
const INPUT_HARDWARE = 2
const INPUT_KEYBOARD = 1
const INPUT_MOUSE = 0
const INTERNATIONAL_USAGE = 1
const INVALID_FILE_ATTRIBUTES = -1
const INVALID_OS_COUNT = 65535
const INVALID_P_ROOT_SECURITY_ID = -1
const INVALID_SET_FILE_POINTER = -1
const IN_CLASSA_HOST = 16777215
const IN_CLASSA_MAX = 128
const IN_CLASSA_NET = 4278190080
const IN_CLASSA_NSHIFT = 24
const IN_CLASSB_HOST = 65535
const IN_CLASSB_MAX = 65536
const IN_CLASSB_NET = 4294901760
const IN_CLASSB_NSHIFT = 16
const IN_CLASSC_HOST = 255
const IN_CLASSC_NET = 4294967040
const IN_CLASSC_NSHIFT = 8
const IN_INDEX_EPH = 2
const IN_INDEX_INDEX_ASC = 3
const IN_INDEX_INDEX_DESC = 4
const IN_INDEX_LOOP = 4
const IN_INDEX_MEMBERSHIP = 2
const IN_INDEX_NOOP = 5
const IN_INDEX_NOOP_OK = 1
const IN_INDEX_ROWID = 1
const IOCPARM_MASK = 127
const IOCTL_CHANGER_BASE = 48
const IOCTL_CHANGER_EXCHANGE_MEDIUM = 3162144
const IOCTL_CHANGER_GET_ELEMENT_STATUS = 3194900
const IOCTL_CHANGER_GET_PARAMETERS = 3162112
const IOCTL_CHANGER_GET_PRODUCT_DATA = 3162120
const IOCTL_CHANGER_GET_STATUS = 3162116
const IOCTL_CHANGER_INITIALIZE_ELEMENT_STATUS = 3162136
const IOCTL_CHANGER_MOVE_MEDIUM = 3162148
const IOCTL_CHANGER_QUERY_VOLUME_TAGS = 3194924
const IOCTL_CHANGER_REINITIALIZE_TRANSPORT = 3162152
const IOCTL_CHANGER_SET_ACCESS = 3194896
const IOCTL_CHANGER_SET_POSITION = 3162140
const IOCTL_DISK_BASE = 7
const IOCTL_DISK_CHECK_VERIFY = 477184
const IOCTL_DISK_CONTROLLER_NUMBER = 458820
const IOCTL_DISK_CREATE_DISK = 507992
const IOCTL_DISK_DELETE_DRIVE_LAYOUT = 508160
const IOCTL_DISK_EJECT_MEDIA = 477192
const IOCTL_DISK_FIND_NEW_DEVICES = 477208
const IOCTL_DISK_FORMAT_DRIVE = 508876
const IOCTL_DISK_FORMAT_TRACKS = 507928
const IOCTL_DISK_FORMAT_TRACKS_EX = 507948
const IOCTL_DISK_GET_CACHE_INFORMATION = 475348
const IOCTL_DISK_GET_DRIVE_GEOMETRY = 458752
const IOCTL_DISK_GET_DRIVE_GEOMETRY_EX = 458912
const IOCTL_DISK_GET_DRIVE_LAYOUT = 475148
const IOCTL_DISK_GET_DRIVE_LAYOUT_EX = 458832
const IOCTL_DISK_GET_LENGTH_INFO = 475228
const IOCTL_DISK_GET_MEDIA_TYPES = 461824
const IOCTL_DISK_GET_PARTITION_INFO = 475140
const IOCTL_DISK_GET_PARTITION_INFO_EX = 458824
const IOCTL_DISK_GROW_PARTITION = 508112
const IOCTL_DISK_HISTOGRAM_DATA = 458804
const IOCTL_DISK_HISTOGRAM_RESET = 458808
const IOCTL_DISK_HISTOGRAM_STRUCTURE = 458800
const IOCTL_DISK_IS_WRITABLE = 458788
const IOCTL_DISK_LOAD_MEDIA = 477196
const IOCTL_DISK_LOGGING = 458792
const IOCTL_DISK_MEDIA_REMOVAL = 477188
const IOCTL_DISK_PERFORMANCE = 458784
const IOCTL_DISK_PERFORMANCE_OFF = 458848
const IOCTL_DISK_REASSIGN_BLOCKS = 507932
const IOCTL_DISK_REASSIGN_BLOCKS_EX = 508068
const IOCTL_DISK_RELEASE = 477204
const IOCTL_DISK_REQUEST_DATA = 458816
const IOCTL_DISK_REQUEST_STRUCTURE = 458812
const IOCTL_DISK_RESERVE = 477200
const IOCTL_DISK_RESET_SNAPSHOT_INFO = 508432
const IOCTL_DISK_SENSE_DEVICE = 459744
const IOCTL_DISK_SET_CACHE_INFORMATION = 508120
const IOCTL_DISK_SET_DRIVE_LAYOUT = 507920
const IOCTL_DISK_SET_DRIVE_LAYOUT_EX = 507988
const IOCTL_DISK_SET_PARTITION_INFO = 507912
const IOCTL_DISK_SET_PARTITION_INFO_EX = 507980
const IOCTL_DISK_UPDATE_DRIVE_SIZE = 508104
const IOCTL_DISK_UPDATE_PROPERTIES = 459072
const IOCTL_DISK_VERIFY = 458772
const IOCTL_SERENUM_EXPOSE_HARDWARE = 3604992
const IOCTL_SERENUM_GET_PORT_NAME = 3605004
const IOCTL_SERENUM_PORT_DESC = 3605000
const IOCTL_SERENUM_REMOVE_HARDWARE = 3604996
const IOCTL_SERIAL_LSRMST_INSERT = 1769596
const IOCTL_SMARTCARD_CONFISCATE = 3211280
const IOCTL_SMARTCARD_EJECT = 3211288
const IOCTL_SMARTCARD_GET_ATTRIBUTE = 3211272
const IOCTL_SMARTCARD_GET_LAST_ERROR = 3211324
const IOCTL_SMARTCARD_GET_PERF_CNTR = 3211328
const IOCTL_SMARTCARD_GET_STATE = 3211320
const IOCTL_SMARTCARD_IS_ABSENT = 3211308
const IOCTL_SMARTCARD_IS_PRESENT = 3211304
const IOCTL_SMARTCARD_POWER = 3211268
const IOCTL_SMARTCARD_SET_ATTRIBUTE = 3211276
const IOCTL_SMARTCARD_SET_PROTOCOL = 3211312
const IOCTL_SMARTCARD_SWALLOW = 3211292
const IOCTL_SMARTCARD_TRANSMIT = 3211284
const IOCTL_STORAGE_ALLOCATE_BC_STREAM = 3004420
const IOCTL_STORAGE_ATTRIBUTE_MANAGEMENT = 3005596
const IOCTL_STORAGE_BASE = 45
const IOCTL_STORAGE_BC_VERSION = 1
const IOCTL_STORAGE_BREAK_RESERVATION = 2969620
const IOCTL_STORAGE_CHECK_PRIORITY_HINT_SUPPORT = 2955392
const IOCTL_STORAGE_CHECK_VERIFY = 2967552
const IOCTL_STORAGE_CHECK_VERIFY2 = 2951168
const IOCTL_STORAGE_DEVICE_POWER_CAP = 2956436
const IOCTL_STORAGE_DEVICE_TELEMETRY_NOTIFY = 3002820
const IOCTL_STORAGE_DEVICE_TELEMETRY_QUERY_CAPS = 3002824
const IOCTL_STORAGE_DIAGNOSTIC = 2956448
const IOCTL_STORAGE_EJECTION_CONTROL = 2951488
const IOCTL_STORAGE_EJECT_MEDIA = 2967560
const IOCTL_STORAGE_ENABLE_IDLE_POWER = 2956416
const IOCTL_STORAGE_EVENT_NOTIFICATION = 2956432
const IOCTL_STORAGE_FAILURE_PREDICTION_CONFIG = 2953476
const IOCTL_STORAGE_FIND_NEW_DEVICES = 2967576
const IOCTL_STORAGE_FIRMWARE_ACTIVATE = 3005448
const IOCTL_STORAGE_FIRMWARE_DOWNLOAD = 3005444
const IOCTL_STORAGE_FIRMWARE_GET_INFO = 2956288
const IOCTL_STORAGE_FREE_BC_STREAM = 3004424
const IOCTL_STORAGE_GET_BC_PROPERTIES = 2971648
const IOCTL_STORAGE_GET_COUNTERS = 2953480
const IOCTL_STORAGE_GET_DEVICE_INTERNAL_LOG = 2956484
const IOCTL_STORAGE_GET_DEVICE_NUMBER = 2953344
const IOCTL_STORAGE_GET_DEVICE_NUMBER_EX = 2953348
const IOCTL_STORAGE_GET_DEVICE_TELEMETRY = 3002816
const IOCTL_STORAGE_GET_DEVICE_TELEMETRY_RAW = 3002828
const IOCTL_STORAGE_GET_HOTPLUG_INFO = 2952212
const IOCTL_STORAGE_GET_IDLE_POWERUP_REASON = 2956420
const IOCTL_STORAGE_GET_LB_PROVISIONING_MAP_RESOURCES = 2970632
const IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER = 2952208
const IOCTL_STORAGE_GET_MEDIA_TYPES = 2952192
const IOCTL_STORAGE_GET_MEDIA_TYPES_EX = 2952196
const IOCTL_STORAGE_GET_PHYSICAL_ELEMENT_STATUS = 2956452
const IOCTL_STORAGE_LOAD_MEDIA = 2967564
const IOCTL_STORAGE_LOAD_MEDIA2 = 2951180
const IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES = 2987012
const IOCTL_STORAGE_MCN_CONTROL = 2951492
const IOCTL_STORAGE_MEDIA_REMOVAL = 2967556
const IOCTL_STORAGE_PERSISTENT_RESERVE_IN = 2969624
const IOCTL_STORAGE_PERSISTENT_RESERVE_OUT = 3002396
const IOCTL_STORAGE_POWER_ACTIVE = 2956424
const IOCTL_STORAGE_POWER_IDLE = 2956428
const IOCTL_STORAGE_PREDICT_FAILURE = 2953472
const IOCTL_STORAGE_PROTOCOL_COMMAND = 3003328
const IOCTL_STORAGE_QUERY_PROPERTY = 2954240
const IOCTL_STORAGE_READ_CAPACITY = 2969920
const IOCTL_STORAGE_REINITIALIZE_MEDIA = 2987584
const IOCTL_STORAGE_RELEASE = 2967572
const IOCTL_STORAGE_REMOVE_ELEMENT_AND_TRUNCATE = 2956480
const IOCTL_STORAGE_RESERVE = 2967568
const IOCTL_STORAGE_RESET_BUS = 2969600
const IOCTL_STORAGE_RESET_DEVICE = 2969604
const IOCTL_STORAGE_RPMB_COMMAND = 2956440
const IOCTL_STORAGE_SET_HOTPLUG_INFO = 3001368
const IOCTL_STORAGE_SET_PROPERTY = 2987004
const IOCTL_STORAGE_SET_TEMPERATURE_THRESHOLD = 3002880
const IOCTL_STORAGE_START_DATA_INTEGRITY_CHECK = 3004548
const IOCTL_STORAGE_STOP_DATA_INTEGRITY_CHECK = 3004552
const IOC_IN = 2147483648
const IOC_INOUT = 3221225472
const IOC_OUT = 1073741824
const IOC_VOID = 536870912
const IOInet = 0
const IOInetBindInfo = 0
const IOInetBindInfoEx = 0
const IOInetPriority = 0
const IOInetProtocol = 0
const IOInetProtocolEx = 0
const IOInetProtocolInfo = 0
const IOInetProtocolRoot = 0
const IOInetProtocolSink = 0
const IOInetProtocolSinkStackable = 0
const IOInetSession = 0
const IOInetThreadSwitch = 0
const IO_COMPLETION_ALL_ACCESS = 2031619
const IO_COMPLETION_MODIFY_STATE = 2
const IO_REPARSE_TAG_AF_UNIX = 2147483683
const IO_REPARSE_TAG_APPEXECLINK = 2147483675
const IO_REPARSE_TAG_CLOUD = 2415919130
const IO_REPARSE_TAG_CLOUD_1 = 2415923226
const IO_REPARSE_TAG_CLOUD_2 = 2415927322
const IO_REPARSE_TAG_CLOUD_3 = 2415931418
const IO_REPARSE_TAG_CLOUD_4 = 2415935514
const IO_REPARSE_TAG_CLOUD_5 = 2415939610
const IO_REPARSE_TAG_CLOUD_6 = 2415943706
const IO_REPARSE_TAG_CLOUD_7 = 2415947802
const IO_REPARSE_TAG_CLOUD_8 = 2415951898
const IO_REPARSE_TAG_CLOUD_9 = 2415955994
const IO_REPARSE_TAG_CLOUD_A = 2415960090
const IO_REPARSE_TAG_CLOUD_B = 2415964186
const IO_REPARSE_TAG_CLOUD_C = 2415968282
const IO_REPARSE_TAG_CLOUD_D = 2415972378
const IO_REPARSE_TAG_CLOUD_E = 2415976474
const IO_REPARSE_TAG_CLOUD_F = 2415980570
const IO_REPARSE_TAG_CLOUD_MASK = 61440
const IO_REPARSE_TAG_CSV = 2147483657
const IO_REPARSE_TAG_DEDUP = 2147483667
const IO_REPARSE_TAG_DFS = 2147483658
const IO_REPARSE_TAG_DFSR = 2147483666
const IO_REPARSE_TAG_DRIVE_EXTENDER = 2147483653
const IO_REPARSE_TAG_FILE_PLACEHOLDER = 2147483669
const IO_REPARSE_TAG_FILTER_MANAGER = 2147483659
const IO_REPARSE_TAG_GLOBAL_REPARSE = 2684354585
const IO_REPARSE_TAG_HSM = 3221225476
const IO_REPARSE_TAG_HSM2 = 2147483654
const IO_REPARSE_TAG_IIS_CACHE = 2684354576
const IO_REPARSE_TAG_MOUNT_POINT = 2684354563
const IO_REPARSE_TAG_NFS = 2147483668
const IO_REPARSE_TAG_ONEDRIVE = 2147483681
const IO_REPARSE_TAG_PROJFS = 2415919132
const IO_REPARSE_TAG_PROJFS_TOMBSTONE = 2684354594
const IO_REPARSE_TAG_RESERVED_ONE = 1
const IO_REPARSE_TAG_RESERVED_RANGE = 1
const IO_REPARSE_TAG_RESERVED_ZERO = 0
const IO_REPARSE_TAG_SIS = 2147483655
const IO_REPARSE_TAG_STORAGE_SYNC = 2147483678
const IO_REPARSE_TAG_SYMLINK = 2684354572
const IO_REPARSE_TAG_UNHANDLED = 2147483680
const IO_REPARSE_TAG_WCI = 2147483672
const IO_REPARSE_TAG_WCI_1 = 2415923224
const IO_REPARSE_TAG_WCI_TOMBSTONE = 2684354591
const IO_REPARSE_TAG_WIM = 2147483656
const IO_REPARSE_TAG_WOF = 2147483671
const IPPORT_BIFFUDP = 512
const IPPORT_CMDSERVER = 514
const IPPORT_DAYTIME = 13
const IPPORT_DISCARD = 9
const IPPORT_ECHO = 7
const IPPORT_EFSSERVER = 520
const IPPORT_EXECSERVER = 512
const IPPORT_FINGER = 79
const IPPORT_FTP = 21
const IPPORT_LOGINSERVER = 513
const IPPORT_MTP = 57
const IPPORT_NAMESERVER = 42
const IPPORT_NETSTAT = 15
const IPPORT_RESERVED = 1024
const IPPORT_RJE = 77
const IPPORT_ROUTESERVER = 520
const IPPORT_SMTP = 25
const IPPORT_SUPDUP = 95
const IPPORT_SYSTAT = 11
const IPPORT_TELNET = 23
const IPPORT_TFTP = 69
const IPPORT_TIMESERVER = 37
const IPPORT_TTYLINK = 87
const IPPORT_WHOIS = 43
const IPPORT_WHOSERVER = 513
const IPPROTO_GGP = 3
const IPPROTO_ICMP = 1
const IPPROTO_IDP = 22
const IPPROTO_IGMP = 2
const IPPROTO_IP = 0
const IPPROTO_MAX = 256
const IPPROTO_ND = 77
const IPPROTO_PUP = 12
const IPPROTO_RAW = 255
const IPPROTO_TCP = 6
const IPPROTO_UDP = 17
const IP_ADD_MEMBERSHIP = 5
const IP_DEFAULT_MULTICAST_LOOP = 1
const IP_DEFAULT_MULTICAST_TTL = 1
const IP_DONTFRAGMENT = 9
const IP_DROP_MEMBERSHIP = 6
const IP_MAX_MEMBERSHIPS = 20
const IP_MULTICAST_IF = 2
const IP_MULTICAST_LOOP = 4
const IP_MULTICAST_TTL = 3
const IP_OPTIONS = 1
const IP_TOS = 8
const IP_TTL = 7
const ISC_SHOWUIALL = 3221225487
const ISC_SHOWUIALLCANDIDATEWINDOW = 15
const ISC_SHOWUICANDIDATEWINDOW = 1
const ISC_SHOWUICOMPOSITIONWINDOW = 2147483648
const ISC_SHOWUIGUIDELINE = 1073741824
const ISMEX_CALLBACK = 4
const ISMEX_NOSEND = 0
const ISMEX_NOTIFY = 2
const ISMEX_REPLIED = 8
const ISMEX_SEND = 1
const IS_TEXT_UNICODE_ASCII16 = 1
const IS_TEXT_UNICODE_CONTROLS = 4
const IS_TEXT_UNICODE_DBCS_LEADBYTE = 1024
const IS_TEXT_UNICODE_ILLEGAL_CHARS = 256
const IS_TEXT_UNICODE_NOT_ASCII_MASK = 61440
const IS_TEXT_UNICODE_NOT_UNICODE_MASK = 3840
const IS_TEXT_UNICODE_NULL_BYTES = 4096
const IS_TEXT_UNICODE_ODD_LENGTH = 512
const IS_TEXT_UNICODE_REVERSE_ASCII16 = 16
const IS_TEXT_UNICODE_REVERSE_CONTROLS = 64
const IS_TEXT_UNICODE_REVERSE_MASK = 240
const IS_TEXT_UNICODE_REVERSE_SIGNATURE = 128
const IS_TEXT_UNICODE_REVERSE_STATISTICS = 32
const IS_TEXT_UNICODE_SIGNATURE = 8
const IS_TEXT_UNICODE_STATISTICS = 2
const IS_TEXT_UNICODE_UNICODE_MASK = 15
const ITALIC_FONTTYPE = 512
const I_RpcBindingInqDynamicEndpoint = 0
const I_RpcNsBindingSetEntryName = 0
const I_RpcServerUseProtseq2 = 0
const I_RpcServerUseProtseqEp2 = 0
const ImmConfigureIME = 0
const ImmEnumRegisterWord = 0
const ImmEscape = 0
const ImmGetCandidateList = 0
const ImmGetCandidateListCount = 0
const ImmGetCompositionFont = 0
const ImmGetCompositionString = 0
const ImmGetConversionList = 0
const ImmGetDescription = 0
const ImmGetGuideLine = 0
const ImmGetIMEFileName = 0
const ImmGetImeMenuItems = 0
const ImmGetRegisterWordStyle = 0
const ImmInstallIME = 0
const ImmIsUIMessage = 0
const ImmRegisterWord = 0
const ImmSetCompositionFont = 0
const ImmSetCompositionString = 0
const ImmUnregisterWord = 0
const InitiateShutdown = 0
const InitiateSystemShutdown = 0
const InitiateSystemShutdownEx = 0
const InsertMenu = 0
const InsertMenuItem = 0
const InterlockedAdd = 0
const InterlockedAdd64 = 0
const InterlockedAnd = 0
const InterlockedAnd64 = 0
const InterlockedAndAffinity = 0
const InterlockedCompareExchange = 0
const InterlockedCompareExchange16 = 0
const InterlockedCompareExchange64 = 0
const InterlockedCompareExchangeAcquire = 0
const InterlockedCompareExchangeAcquire64 = 0
const InterlockedCompareExchangePointerAcquire = 0
const InterlockedCompareExchangePointerRelease = 0
const InterlockedCompareExchangeRelease = 0
const InterlockedCompareExchangeRelease64 = 0
const InterlockedDecrement = 0
const InterlockedDecrement16 = 0
const InterlockedDecrement64 = 0
const InterlockedDecrementAcquire = 0
const InterlockedDecrementRelease = 0
const InterlockedExchange = 0
const InterlockedExchange64 = 0
const InterlockedExchangeAcquire64 = 0
const InterlockedExchangeAdd = 0
const InterlockedExchangeAdd64 = 0
const InterlockedExchangePointer = 0
const InterlockedIncrement = 0
const InterlockedIncrement16 = 0
const InterlockedIncrement64 = 0
const InterlockedIncrementAcquire = 0
const InterlockedIncrementRelease = 0
const InterlockedOr = 0
const InterlockedOr64 = 0
const InterlockedOrAffinity = 0
const InterlockedPushListSList = 0
const InterlockedXor = 0
const InterlockedXor64 = 0
const IsBadStringPtr = 0
const IsCharAlpha = 0
const IsCharAlphaNumeric = 0
const IsCharLower = 0
const IsCharUpper = 0
const IsDialogMessage = 0
const IsLFNDrive = 0
const IsLoggingEnabled = 0
const IsStat4 = 1
const IsValidDevmode = 0
const JEACH_ATOM = 3
const JEACH_FULLKEY = 6
const JEACH_ID = 4
const JEACH_JSON = 8
const JEACH_KEY = 0
const JEACH_PARENT = 5
const JEACH_PATH = 7
const JEACH_ROOT = 9
const JEACH_TYPE = 2
const JEACH_VALUE = 1
const JEDIT_DEL = 1
const JEDIT_INS = 3
const JEDIT_REPL = 2
const JEDIT_SET = 4
const JOB_ACCESS_ADMINISTER = 16
const JOB_ACCESS_READ = 32
const JOB_ALL_ACCESS = 983088
const JOB_CONTROL_CANCEL = 3
const JOB_CONTROL_DELETE = 5
const JOB_CONTROL_LAST_PAGE_EJECTED = 7
const JOB_CONTROL_PAUSE = 1
const JOB_CONTROL_RESTART = 4
const JOB_CONTROL_RESUME = 2
const JOB_CONTROL_SENT_TO_PRINTER = 6
const JOB_EXECUTE = 131088
const JOB_NOTIFY_FIELD_BYTES_PRINTED = 23
const JOB_NOTIFY_FIELD_DATATYPE = 5
const JOB_NOTIFY_FIELD_DEVMODE = 9
const JOB_NOTIFY_FIELD_DOCUMENT = 13
const JOB_NOTIFY_FIELD_DRIVER_NAME = 8
const JOB_NOTIFY_FIELD_MACHINE_NAME = 1
const JOB_NOTIFY_FIELD_NOTIFY_NAME = 4
const JOB_NOTIFY_FIELD_PAGES_PRINTED = 21
const JOB_NOTIFY_FIELD_PARAMETERS = 7
const JOB_NOTIFY_FIELD_PORT_NAME = 2
const JOB_NOTIFY_FIELD_POSITION = 15
const JOB_NOTIFY_FIELD_PRINTER_NAME = 0
const JOB_NOTIFY_FIELD_PRINT_PROCESSOR = 6
const JOB_NOTIFY_FIELD_PRIORITY = 14
const JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR = 12
const JOB_NOTIFY_FIELD_START_TIME = 17
const JOB_NOTIFY_FIELD_STATUS = 10
const JOB_NOTIFY_FIELD_STATUS_STRING = 11
const JOB_NOTIFY_FIELD_SUBMITTED = 16
const JOB_NOTIFY_FIELD_TIME = 19
const JOB_NOTIFY_FIELD_TOTAL_BYTES = 22
const JOB_NOTIFY_FIELD_TOTAL_PAGES = 20
const JOB_NOTIFY_FIELD_UNTIL_TIME = 18
const JOB_NOTIFY_FIELD_USER_NAME = 3
const JOB_NOTIFY_TYPE = 1
const JOB_OBJECT_ALL_ACCESS = 2031647
const JOB_OBJECT_ASSIGN_PROCESS = 1
const JOB_OBJECT_BASIC_LIMIT_VALID_FLAGS = 255
const JOB_OBJECT_CPU_RATE_CONTROL_ENABLE = 1
const JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP = 4
const JOB_OBJECT_CPU_RATE_CONTROL_NOTIFY = 8
const JOB_OBJECT_CPU_RATE_CONTROL_VALID_FLAGS = 15
const JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED = 2
const JOB_OBJECT_EXTENDED_LIMIT_VALID_FLAGS = 32767
const JOB_OBJECT_LIMIT_ACTIVE_PROCESS = 8
const JOB_OBJECT_LIMIT_AFFINITY = 16
const JOB_OBJECT_LIMIT_BREAKAWAY_OK = 2048
const JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 1024
const JOB_OBJECT_LIMIT_JOB_MEMORY = 512
const JOB_OBJECT_LIMIT_JOB_READ_BYTES = 65536
const JOB_OBJECT_LIMIT_JOB_TIME = 4
const JOB_OBJECT_LIMIT_JOB_WRITE_BYTES = 131072
const JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 8192
const JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME = 64
const JOB_OBJECT_LIMIT_PRIORITY_CLASS = 32
const JOB_OBJECT_LIMIT_PROCESS_MEMORY = 256
const JOB_OBJECT_LIMIT_PROCESS_TIME = 2
const JOB_OBJECT_LIMIT_RATE_CONTROL = 262144
const JOB_OBJECT_LIMIT_RESERVED3 = 32768
const JOB_OBJECT_LIMIT_RESERVED4 = 65536
const JOB_OBJECT_LIMIT_RESERVED5 = 131072
const JOB_OBJECT_LIMIT_RESERVED6 = 262144
const JOB_OBJECT_LIMIT_SCHEDULING_CLASS = 128
const JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = 4096
const JOB_OBJECT_LIMIT_SUBSET_AFFINITY = 16384
const JOB_OBJECT_LIMIT_VALID_FLAGS = 524287
const JOB_OBJECT_LIMIT_WORKINGSET = 1
const JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS = 8
const JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT = 3
const JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO = 4
const JOB_OBJECT_MSG_END_OF_JOB_TIME = 1
const JOB_OBJECT_MSG_END_OF_PROCESS_TIME = 2
const JOB_OBJECT_MSG_EXIT_PROCESS = 7
const JOB_OBJECT_MSG_JOB_CYCLE_TIME_LIMIT = 12
const JOB_OBJECT_MSG_JOB_MEMORY_LIMIT = 10
const JOB_OBJECT_MSG_MAXIMUM = 12
const JOB_OBJECT_MSG_MINIMUM = 1
const JOB_OBJECT_MSG_NEW_PROCESS = 6
const JOB_OBJECT_MSG_NOTIFICATION_LIMIT = 11
const JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT = 9
const JOB_OBJECT_NOTIFICATION_LIMIT_VALID_FLAGS = 459268
const JOB_OBJECT_POST_AT_END_OF_JOB = 1
const JOB_OBJECT_QUERY = 4
const JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS = 524287
const JOB_OBJECT_SECURITY_FILTER_TOKENS = 8
const JOB_OBJECT_SECURITY_NO_ADMIN = 1
const JOB_OBJECT_SECURITY_ONLY_TOKEN = 4
const JOB_OBJECT_SECURITY_RESTRICTED_TOKEN = 2
const JOB_OBJECT_SECURITY_VALID_FLAGS = 15
const JOB_OBJECT_SET_ATTRIBUTES = 2
const JOB_OBJECT_SET_SECURITY_ATTRIBUTES = 16
const JOB_OBJECT_TERMINATE = 8
const JOB_OBJECT_TERMINATE_AT_END_OF_JOB = 0
const JOB_OBJECT_UILIMIT_ALL = 255
const JOB_OBJECT_UILIMIT_DESKTOP = 64
const JOB_OBJECT_UILIMIT_DISPLAYSETTINGS = 16
const JOB_OBJECT_UILIMIT_EXITWINDOWS = 128
const JOB_OBJECT_UILIMIT_GLOBALATOMS = 32
const JOB_OBJECT_UILIMIT_HANDLES = 1
const JOB_OBJECT_UILIMIT_NONE = 0
const JOB_OBJECT_UILIMIT_READCLIPBOARD = 2
const JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS = 8
const JOB_OBJECT_UILIMIT_WRITECLIPBOARD = 4
const JOB_OBJECT_UI_VALID_FLAGS = 255
const JOB_POSITION_UNSPECIFIED = 0
const JOB_READ = 131104
const JOB_STATUS_BLOCKED_DEVQ = 512
const JOB_STATUS_COMPLETE = 4096
const JOB_STATUS_DELETED = 256
const JOB_STATUS_DELETING = 4
const JOB_STATUS_ERROR = 2
const JOB_STATUS_OFFLINE = 32
const JOB_STATUS_PAPEROUT = 64
const JOB_STATUS_PAUSED = 1
const JOB_STATUS_PRINTED = 128
const JOB_STATUS_PRINTING = 16
const JOB_STATUS_RESTART = 2048
const JOB_STATUS_SPOOLING = 8
const JOB_STATUS_USER_INTERVENTION = 1024
const JOB_WRITE = 131088
const JOHAB_CHARSET = 130
const JOYCAPS_HASPOV = 16
const JOYCAPS_HASR = 2
const JOYCAPS_HASU = 4
const JOYCAPS_HASV = 8
const JOYCAPS_HASZ = 1
const JOYCAPS_POV4DIR = 32
const JOYCAPS_POVCTS = 64
const JOYERR_BASE = 160
const JOYERR_NOCANDO = 166
const JOYERR_NOERROR = 0
const JOYERR_PARMS = 165
const JOYERR_UNPLUGGED = 167
const JOYSTICKID1 = 0
const JOYSTICKID2 = 1
const JOY_BUTTON1 = 1
const JOY_BUTTON10 = 512
const JOY_BUTTON11 = 1024
const JOY_BUTTON12 = 2048
const JOY_BUTTON13 = 4096
const JOY_BUTTON14 = 8192
const JOY_BUTTON15 = 16384
const JOY_BUTTON16 = 32768
const JOY_BUTTON17 = 65536
const JOY_BUTTON18 = 131072
const JOY_BUTTON19 = 262144
const JOY_BUTTON1CHG = 256
const JOY_BUTTON2 = 2
const JOY_BUTTON20 = 524288
const JOY_BUTTON21 = 1048576
const JOY_BUTTON22 = 2097152
const JOY_BUTTON23 = 4194304
const JOY_BUTTON24 = 8388608
const JOY_BUTTON25 = 16777216
const JOY_BUTTON26 = 33554432
const JOY_BUTTON27 = 67108864
const JOY_BUTTON28 = 134217728
const JOY_BUTTON29 = 268435456
const JOY_BUTTON2CHG = 512
const JOY_BUTTON3 = 4
const JOY_BUTTON30 = 536870912
const JOY_BUTTON31 = 1073741824
const JOY_BUTTON32 = 2147483648
const JOY_BUTTON3CHG = 1024
const JOY_BUTTON4 = 8
const JOY_BUTTON4CHG = 2048
const JOY_BUTTON5 = 16
const JOY_BUTTON6 = 32
const JOY_BUTTON7 = 64
const JOY_BUTTON8 = 128
const JOY_BUTTON9 = 256
const JOY_CAL_READ3 = 262144
const JOY_CAL_READ4 = 524288
const JOY_CAL_READ5 = 4194304
const JOY_CAL_READ6 = 8388608
const JOY_CAL_READALWAYS = 65536
const JOY_CAL_READRONLY = 33554432
const JOY_CAL_READUONLY = 67108864
const JOY_CAL_READVONLY = 134217728
const JOY_CAL_READXONLY = 1048576
const JOY_CAL_READXYONLY = 131072
const JOY_CAL_READYONLY = 2097152
const JOY_CAL_READZONLY = 16777216
const JOY_POVBACKWARD = 18000
const JOY_POVCENTERED = -1
const JOY_POVFORWARD = 0
const JOY_POVLEFT = 27000
const JOY_POVRIGHT = 9000
const JOY_RETURNALL = 255
const JOY_RETURNBUTTONS = 128
const JOY_RETURNCENTERED = 1024
const JOY_RETURNPOV = 64
const JOY_RETURNPOVCTS = 512
const JOY_RETURNR = 8
const JOY_RETURNRAWDATA = 256
const JOY_RETURNU = 16
const JOY_RETURNV = 32
const JOY_RETURNX = 1
const JOY_RETURNY = 2
const JOY_RETURNZ = 4
const JOY_USEDEADZONE = 2048
const JSONB_ARRAY = 11
const JSONB_FALSE = 2
const JSONB_FLOAT = 5
const JSONB_FLOAT5 = 6
const JSONB_INT = 3
const JSONB_INT5 = 4
const JSONB_NULL = 0
const JSONB_OBJECT = 12
const JSONB_TEXT = 7
const JSONB_TEXT5 = 9
const JSONB_TEXTJ = 8
const JSONB_TEXTRAW = 10
const JSONB_TRUE = 1
const JSON_ABPATH = 3
const JSON_BLOB = 8
const JSON_CACHE_ID = -429938
const JSON_CACHE_SIZE = 4
const JSON_EDITABLE = 1
const JSON_INVALID_CHAR = 629145
const JSON_ISSET = 4
const JSON_JSON = 1
const JSON_KEEPERROR = 2
const JSON_LOOKUP_ERROR = 4294967295
const JSON_LOOKUP_NOTFOUND = 4294967294
const JSON_LOOKUP_PATHERROR = 4294967293
const JSON_MAX_DEPTH = 1000
const JSON_MERGE_BADPATCH = 2
const JSON_MERGE_BADTARGET = 1
const JSON_MERGE_OK = 0
const JSON_MERGE_OOM = 3
const JSON_SQL = 2
const JSON_SUBTYPE = 74
const JSTRING_ERR = 4
const JSTRING_MALFORMED = 2
const JSTRING_OOM = 1
const JT_CROSS = 2
const JT_ERROR = 128
const JT_INNER = 1
const JT_LEFT = 8
const JT_LTORJ = 64
const JT_NATURAL = 4
const JT_OUTER = 32
const JT_RIGHT = 16
const KDF_ALGORITHMID = 8
const KDF_CONTEXT = 14
const KDF_GENERIC_PARAMETER = 17
const KDF_HASH_ALGORITHM = 0
const KDF_HMAC_KEY = 3
const KDF_ITERATION_COUNT = 16
const KDF_KEYBITLENGTH = 18
const KDF_LABEL = 13
const KDF_PARTYUINFO = 9
const KDF_PARTYVINFO = 10
const KDF_SALT = 15
const KDF_SECRET_APPEND = 2
const KDF_SECRET_HANDLE = 6
const KDF_SECRET_PREPEND = 1
const KDF_SUPPPRIVINFO = 12
const KDF_SUPPPUBINFO = 11
const KDF_TLS_PRF_LABEL = 4
const KDF_TLS_PRF_PROTOCOL = 7
const KDF_TLS_PRF_SEED = 5
const KDF_USE_SECRET_AS_HMAC_KEY_FLAG = 1
const KEYBOARD_OVERRUN_MAKE_CODE = 255
const KEYEVENTF_EXTENDEDKEY = 1
const KEYEVENTF_KEYUP = 2
const KEYEVENTF_SCANCODE = 8
const KEYEVENTF_UNICODE = 4
const KEYINFO_ORDER_BIGNULL = 2
const KEYINFO_ORDER_DESC = 1
const KEYSTATEBLOB = 12
const KEY_ALL_ACCESS = 983103
const KEY_CREATE_LINK = 32
const KEY_CREATE_SUB_KEY = 4
const KEY_ENUMERATE_SUB_KEYS = 8
const KEY_EVENT = 1
const KEY_EXECUTE = 131097
const KEY_LENGTH_MASK = 4294901760
const KEY_NOTIFY = 16
const KEY_QUERY_VALUE = 1
const KEY_READ = 131097
const KEY_SET_VALUE = 2
const KEY_WOW64_32KEY = 512
const KEY_WOW64_64KEY = 256
const KEY_WOW64_RES = 768
const KEY_WRITE = 131078
const KF_ALTDOWN = 8192
const KF_DLGMODE = 2048
const KF_EXTENDED = 256
const KF_MENUMODE = 4096
const KF_REPEAT = 16384
const KF_UP = 32768
const KLF_ACTIVATE = 1
const KLF_NOTELLSHELL = 128
const KLF_REORDER = 8
const KLF_REPLACELANG = 16
const KLF_RESET = 1073741824
const KLF_SETFORPROCESS = 256
const KLF_SHIFTLOCK = 65536
const KLF_SUBSTITUTE_OK = 2
const KL_NAMELENGTH = 9
const KP_ADMIN_PIN = 31
const KP_ALGID = 7
const KP_BLOCKLEN = 8
const KP_CERTIFICATE = 26
const KP_CLEAR_KEY = 27
const KP_CLIENT_RANDOM = 21
const KP_CMS_DH_KEY_INFO = 38
const KP_CMS_KEY_INFO = 37
const KP_EFFECTIVE_KEYLEN = 19
const KP_G = 12
const KP_GET_USE_COUNT = 42
const KP_HIGHEST_VERSION = 41
const KP_INFO = 18
const KP_IV = 1
const KP_KEYEXCHANGE_PIN = 32
const KP_KEYLEN = 9
const KP_KEYVAL = 30
const KP_MODE = 4
const KP_MODE_BITS = 5
const KP_OAEP_PARAMS = 36
const KP_P = 11
const KP_PADDING = 3
const KP_PERMISSIONS = 6
const KP_PIN_ID = 43
const KP_PIN_INFO = 44
const KP_PRECOMP_MD5 = 24
const KP_PRECOMP_SHA = 25
const KP_PREHASH = 34
const KP_PUB_EX_LEN = 28
const KP_PUB_EX_VAL = 29
const KP_PUB_PARAMS = 39
const KP_Q = 13
const KP_RA = 16
const KP_RB = 17
const KP_ROUNDS = 35
const KP_RP = 23
const KP_SALT = 2
const KP_SALT_EX = 10
const KP_SCHANNEL_ALG = 20
const KP_SERVER_RANDOM = 22
const KP_SIGNATURE_PIN = 33
const KP_VERIFY_PARAMS = 40
const KP_X = 14
const KP_Y = 15
const KTM_MARSHAL_BLOB_VERSION_MAJOR = 1
const KTM_MARSHAL_BLOB_VERSION_MINOR = 1
const LABEL_SECURITY_INFORMATION = 16
const LANGGROUPLOCALE_ENUMPROC = 0
const LANGUAGEGROUP_ENUMPROC = 0
const LANG_AFRIKAANS = 54
const LANG_ALBANIAN = 28
const LANG_ALSATIAN = 132
const LANG_AMHARIC = 94
const LANG_ARABIC = 1
const LANG_ARMENIAN = 43
const LANG_ASSAMESE = 77
const LANG_AZERBAIJANI = 44
const LANG_AZERI = 44
const LANG_BANGLA = 69
const LANG_BASHKIR = 109
const LANG_BASQUE = 45
const LANG_BELARUSIAN = 35
const LANG_BENGALI = 69
const LANG_BOSNIAN = 26
const LANG_BOSNIAN_NEUTRAL = 30746
const LANG_BRETON = 126
const LANG_BULGARIAN = 2
const LANG_CATALAN = 3
const LANG_CENTRAL_KURDISH = 146
const LANG_CHEROKEE = 92
const LANG_CHINESE = 4
const LANG_CHINESE_SIMPLIFIED = 4
const LANG_CHINESE_TRADITIONAL = 31748
const LANG_CORSICAN = 131
const LANG_CROATIAN = 26
const LANG_CZECH = 5
const LANG_DANISH = 6
const LANG_DARI = 140
const LANG_DIVEHI = 101
const LANG_DUTCH = 19
const LANG_ENGLISH = 9
const LANG_ESTONIAN = 37
const LANG_FAEROESE = 56
const LANG_FARSI = 41
const LANG_FILIPINO = 100
const LANG_FINNISH = 11
const LANG_FRENCH = 12
const LANG_FRISIAN = 98
const LANG_FULAH = 103
const LANG_GALICIAN = 86
const LANG_GEORGIAN = 55
const LANG_GERMAN = 7
const LANG_GREEK = 8
const LANG_GREENLANDIC = 111
const LANG_GUJARATI = 71
const LANG_HAUSA = 104
const LANG_HEBREW = 13
const LANG_HINDI = 57
const LANG_HUNGARIAN = 14
const LANG_ICELANDIC = 15
const LANG_IGBO = 112
const LANG_INDONESIAN = 33
const LANG_INUKTITUT = 93
const LANG_INVARIANT = 127
const LANG_IRISH = 60
const LANG_ITALIAN = 16
const LANG_JAPANESE = 17
const LANG_KANNADA = 75
const LANG_KASHMIRI = 96
const LANG_KAZAK = 63
const LANG_KHMER = 83
const LANG_KICHE = 134
const LANG_KINYARWANDA = 135
const LANG_KONKANI = 87
const LANG_KOREAN = 18
const LANG_KYRGYZ = 64
const LANG_LAO = 84
const LANG_LATVIAN = 38
const LANG_LITHUANIAN = 39
const LANG_LOWER_SORBIAN = 46
const LANG_LUXEMBOURGISH = 110
const LANG_MACEDONIAN = 47
const LANG_MALAY = 62
const LANG_MALAYALAM = 76
const LANG_MALTESE = 58
const LANG_MANIPURI = 88
const LANG_MAORI = 129
const LANG_MAPUDUNGUN = 122
const LANG_MARATHI = 78
const LANG_MOHAWK = 124
const LANG_MONGOLIAN = 80
const LANG_NEPALI = 97
const LANG_NEUTRAL = 0
const LANG_NORWEGIAN = 20
const LANG_OCCITAN = 130
const LANG_ODIA = 72
const LANG_ORIYA = 72
const LANG_PASHTO = 99
const LANG_PERSIAN = 41
const LANG_POLISH = 21
const LANG_PORTUGUESE = 22
const LANG_PULAR = 103
const LANG_PUNJABI = 70
const LANG_QUECHUA = 107
const LANG_ROMANIAN = 24
const LANG_ROMANSH = 23
const LANG_RUSSIAN = 25
const LANG_SAKHA = 133
const LANG_SAMI = 59
const LANG_SANSKRIT = 79
const LANG_SCOTTISH_GAELIC = 145
const LANG_SERBIAN = 26
const LANG_SERBIAN_NEUTRAL = 31770
const LANG_SINDHI = 89
const LANG_SINHALESE = 91
const LANG_SLOVAK = 27
const LANG_SLOVENIAN = 36
const LANG_SOTHO = 108
const LANG_SPANISH = 10
const LANG_SWAHILI = 65
const LANG_SWEDISH = 29
const LANG_SYRIAC = 90
const LANG_TAJIK = 40
const LANG_TAMAZIGHT = 95
const LANG_TAMIL = 73
const LANG_TATAR = 68
const LANG_TELUGU = 74
const LANG_THAI = 30
const LANG_TIBETAN = 81
const LANG_TIGRIGNA = 115
const LANG_TIGRINYA = 115
const LANG_TSWANA = 50
const LANG_TURKISH = 31
const LANG_TURKMEN = 66
const LANG_UIGHUR = 128
const LANG_UKRAINIAN = 34
const LANG_UPPER_SORBIAN = 46
const LANG_URDU = 32
const LANG_UZBEK = 67
const LANG_VALENCIAN = 3
const LANG_VIETNAMESE = 42
const LANG_WELSH = 82
const LANG_WOLOF = 136
const LANG_XHOSA = 52
const LANG_YAKUT = 133
const LANG_YI = 120
const LANG_YORUBA = 106
const LANG_ZULU = 53
const LAYOUT_BITMAPORIENTATIONPRESERVED = 8
const LAYOUT_BTT = 2
const LAYOUT_ORIENTATIONMASK = 7
const LAYOUT_RTL = 1
const LAYOUT_VBH = 4
const LBN_DBLCLK = 2
const LBN_ERRSPACE = -2
const LBN_KILLFOCUS = 5
const LBN_SELCANCEL = 3
const LBN_SELCHANGE = 1
const LBN_SETFOCUS = 4
const LBSELCHSTRINGA = "commdlg_LBSelChangedNotify"
const LBSELCHSTRINGW = "commdlg_LBSelChangedNotify"
const LBS_COMBOBOX = 32768
const LBS_DISABLENOSCROLL = 4096
const LBS_EXTENDEDSEL = 2048
const LBS_HASSTRINGS = 64
const LBS_MULTICOLUMN = 512
const LBS_MULTIPLESEL = 8
const LBS_NODATA = 8192
const LBS_NOINTEGRALHEIGHT = 256
const LBS_NOREDRAW = 4
const LBS_NOSEL = 16384
const LBS_NOTIFY = 1
const LBS_OWNERDRAWFIXED = 16
const LBS_OWNERDRAWVARIABLE = 32
const LBS_SORT = 2
const LBS_STANDARD = 10485763
const LBS_USETABSTOPS = 128
const LBS_WANTKEYBOARDINPUT = 1024
const LB_ADDFILE = 406
const LB_ADDSTRING = 384
const LB_CTLCODE = 0
const LB_DELETESTRING = 386
const LB_DIR = 397
const LB_ERR = -1
const LB_ERRSPACE = -2
const LB_FINDSTRING = 399
const LB_FINDSTRINGEXACT = 418
const LB_GETANCHORINDEX = 413
const LB_GETCARETINDEX = 415
const LB_GETCOUNT = 395
const LB_GETCURSEL = 392
const LB_GETHORIZONTALEXTENT = 403
const LB_GETITEMDATA = 409
const LB_GETITEMHEIGHT = 417
const LB_GETITEMRECT = 408
const LB_GETLISTBOXINFO = 434
const LB_GETLOCALE = 422
const LB_GETSEL = 391
const LB_GETSELCOUNT = 400
const LB_GETSELITEMS = 401
const LB_GETTEXT = 393
const LB_GETTEXTLEN = 394
const LB_GETTOPINDEX = 398
const LB_INITSTORAGE = 424
const LB_INSERTSTRING = 385
const LB_ITEMFROMPOINT = 425
const LB_MSGMAX = 435
const LB_OKAY = 0
const LB_RESETCONTENT = 388
const LB_SELECTSTRING = 396
const LB_SELITEMRANGE = 411
const LB_SELITEMRANGEEX = 387
const LB_SETANCHORINDEX = 412
const LB_SETCARETINDEX = 414
const LB_SETCOLUMNWIDTH = 405
const LB_SETCOUNT = 423
const LB_SETCURSEL = 390
const LB_SETHORIZONTALEXTENT = 404
const LB_SETITEMDATA = 410
const LB_SETITEMHEIGHT = 416
const LB_SETLOCALE = 421
const LB_SETSEL = 389
const LB_SETTABSTOPS = 402
const LB_SETTOPINDEX = 407
const LCID_ALTERNATE_SORTS = 4
const LCID_INSTALLED = 1
const LCID_SUPPORTED = 2
const LCMAP_BYTEREV = 2048
const LCMAP_FULLWIDTH = 8388608
const LCMAP_HALFWIDTH = 4194304
const LCMAP_HASH = 262144
const LCMAP_HIRAGANA = 1048576
const LCMAP_KATAKANA = 2097152
const LCMAP_LINGUISTIC_CASING = 16777216
const LCMAP_LOWERCASE = 256
const LCMAP_SIMPLIFIED_CHINESE = 33554432
const LCMAP_SORTHANDLE = 536870912
const LCMAP_SORTKEY = 1024
const LCMAP_TITLECASE = 768
const LCMAP_TRADITIONAL_CHINESE = 67108864
const LCMAP_UPPERCASE = 512
const LCMapString = 0
const LCS_CALIBRATED_RGB = 0
const LCS_GM_ABS_COLORIMETRIC = 8
const LCS_GM_BUSINESS = 1
const LCS_GM_GRAPHICS = 2
const LCS_GM_IMAGES = 4
const LCS_SIGNATURE = 80
const LCS_WINDOWS_COLOR_SPACE = 87
const LCS_sRGB = 115
const LC_INTERIORS = 128
const LC_MARKER = 4
const LC_NONE = 0
const LC_POLYLINE = 2
const LC_POLYMARKER = 8
const LC_STYLED = 32
const LC_WIDE = 16
const LC_WIDESTYLED = 64
const LEFT_ALT_PRESSED = 2
const LEFT_CTRL_PRESSED = 8
const LEGACY_DH_PRIVATE_BLOB = "CAPIDHPRIVATEBLOB"
const LEGACY_DH_PUBLIC_BLOB = "CAPIDHPUBLICBLOB"
const LEGACY_DSA_PRIVATE_BLOB = "CAPIDSAPRIVATEBLOB"
const LEGACY_DSA_PUBLIC_BLOB = "CAPIDSAPUBLICBLOB"
const LEGACY_DSA_V2_PRIVATE_BLOB = "V2CAPIDSAPRIVATEBLOB"
const LEGACY_DSA_V2_PUBLIC_BLOB = "V2CAPIDSAPUBLICBLOB"
const LEGACY_RSAPRIVATE_BLOB = "CAPIPRIVATEBLOB"
const LEGACY_RSAPUBLIC_BLOB = "CAPIPUBLICBLOB"
const LEGACY_SCHEMA_TABLE = "sqlite_master"
const LEGACY_TEMP_SCHEMA_TABLE = "sqlite_temp_master"
const LF_FACESIZE = 32
const LF_FULLFACESIZE = 64
const LGRPID_ARABIC = 13
const LGRPID_ARMENIAN = 17
const LGRPID_BALTIC = 3
const LGRPID_CENTRAL_EUROPE = 2
const LGRPID_CYRILLIC = 5
const LGRPID_GEORGIAN = 16
const LGRPID_GREEK = 4
const LGRPID_HEBREW = 12
const LGRPID_INDIC = 15
const LGRPID_INSTALLED = 1
const LGRPID_JAPANESE = 7
const LGRPID_KOREAN = 8
const LGRPID_SIMPLIFIED_CHINESE = 10
const LGRPID_SUPPORTED = 2
const LGRPID_THAI = 11
const LGRPID_TRADITIONAL_CHINESE = 9
const LGRPID_TURKIC = 6
const LGRPID_TURKISH = 6
const LGRPID_VIETNAMESE = 14
const LGRPID_WESTERN_EUROPE = 1
const LHND = 66
const LINECAPS = 30
const LINGUISTIC_IGNORECASE = 16
const LINGUISTIC_IGNOREDIACRITIC = 32
const LISTEN_OUTSTANDING = 1
const LLKHF_ALTDOWN = 32
const LLKHF_EXTENDED = 1
const LLKHF_INJECTED = 16
const LLKHF_LOWER_IL_INJECTED = 2
const LLKHF_UP = 128
const LLMHF_INJECTED = 1
const LLMHF_LOWER_IL_INJECTED = 2
const LMEM_DISCARDABLE = 3840
const LMEM_DISCARDED = 16384
const LMEM_FIXED = 0
const LMEM_INVALID_HANDLE = 32768
const LMEM_LOCKCOUNT = 255
const LMEM_MODIFY = 128
const LMEM_MOVEABLE = 2
const LMEM_NOCOMPACT = 16
const LMEM_NODISCARD = 32
const LMEM_VALID_FLAGS = 3954
const LMEM_ZEROINIT = 64
const LOAD_DLL_DEBUG_EVENT = 6
const LOAD_IGNORE_CODE_AUTHZ_LEVEL = 16
const LOAD_LIBRARY_AS_DATAFILE = 2
const LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 64
const LOAD_LIBRARY_AS_IMAGE_RESOURCE = 32
const LOAD_LIBRARY_REQUIRE_SIGNED_TARGET = 128
const LOAD_LIBRARY_SEARCH_APPLICATION_DIR = 512
const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 4096
const LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 256
const LOAD_LIBRARY_SEARCH_SYSTEM32 = 2048
const LOAD_LIBRARY_SEARCH_SYSTEM32_NO_FORWARDER = 2048
const LOAD_LIBRARY_SEARCH_USER_DIRS = 1024
const LOAD_TLB_AS_32BIT = 32
const LOAD_TLB_AS_64BIT = 64
const LOAD_WITH_ALTERED_SEARCH_PATH = 8
const LOCALE_ALL = 0
const LOCALE_ALLOW_NEUTRAL_NAMES = 134217728
const LOCALE_ALTERNATE_SORTS = 4
const LOCALE_ENUMPROC = 0
const LOCALE_FONTSIGNATURE = 88
const LOCALE_ICALENDARTYPE = 4105
const LOCALE_ICENTURY = 36
const LOCALE_ICOUNTRY = 5
const LOCALE_ICURRDIGITS = 25
const LOCALE_ICURRENCY = 27
const LOCALE_IDATE = 33
const LOCALE_IDAYLZERO = 38
const LOCALE_IDEFAULTANSICODEPAGE = 4100
const LOCALE_IDEFAULTCODEPAGE = 11
const LOCALE_IDEFAULTCOUNTRY = 10
const LOCALE_IDEFAULTEBCDICCODEPAGE = 4114
const LOCALE_IDEFAULTLANGUAGE = 9
const LOCALE_IDEFAULTMACCODEPAGE = 4113
const LOCALE_IDIALINGCODE = 5
const LOCALE_IDIGITS = 17
const LOCALE_IDIGITSUBSTITUTION = 4116
const LOCALE_IFIRSTDAYOFWEEK = 4108
const LOCALE_IFIRSTWEEKOFYEAR = 4109
const LOCALE_IGEOID = 91
const LOCALE_IINTLCURRDIGITS = 26
const LOCALE_ILANGUAGE = 1
const LOCALE_ILDATE = 34
const LOCALE_ILZERO = 18
const LOCALE_IMEASURE = 13
const LOCALE_IMONLZERO = 39
const LOCALE_INEGATIVEPERCENT = 116
const LOCALE_INEGCURR = 28
const LOCALE_INEGNUMBER = 4112
const LOCALE_INEGSEPBYSPACE = 87
const LOCALE_INEGSIGNPOSN = 83
const LOCALE_INEGSYMPRECEDES = 86
const LOCALE_INEUTRAL = 113
const LOCALE_IOPTIONALCALENDAR = 4107
const LOCALE_IPAPERSIZE = 4106
const LOCALE_IPOSITIVEPERCENT = 117
const LOCALE_IPOSSEPBYSPACE = 85
const LOCALE_IPOSSIGNPOSN = 82
const LOCALE_IPOSSYMPRECEDES = 84
const LOCALE_IREADINGLAYOUT = 112
const LOCALE_ITIME = 35
const LOCALE_ITIMEMARKPOSN = 4101
const LOCALE_ITLZERO = 37
const LOCALE_NAME_INVARIANT = ""
const LOCALE_NAME_MAX_LENGTH = 85
const LOCALE_NAME_SYSTEM_DEFAULT = "!x-sys-default-locale"
const LOCALE_NAME_USER_DEFAULT = "NULL"
const LOCALE_NEUTRALDATA = 16
const LOCALE_NOUSEROVERRIDE = 2147483648
const LOCALE_REPLACEMENT = 8
const LOCALE_RETURN_GENITIVE_NAMES = 268435456
const LOCALE_RETURN_NUMBER = 536870912
const LOCALE_S1159 = 40
const LOCALE_S2359 = 41
const LOCALE_SABBREVCTRYNAME = 7
const LOCALE_SABBREVDAYNAME1 = 49
const LOCALE_SABBREVDAYNAME2 = 50
const LOCALE_SABBREVDAYNAME3 = 51
const LOCALE_SABBREVDAYNAME4 = 52
const LOCALE_SABBREVDAYNAME5 = 53
const LOCALE_SABBREVDAYNAME6 = 54
const LOCALE_SABBREVDAYNAME7 = 55
const LOCALE_SABBREVLANGNAME = 3
const LOCALE_SABBREVMONTHNAME1 = 68
const LOCALE_SABBREVMONTHNAME10 = 77
const LOCALE_SABBREVMONTHNAME11 = 78
const LOCALE_SABBREVMONTHNAME12 = 79
const LOCALE_SABBREVMONTHNAME13 = 4111
const LOCALE_SABBREVMONTHNAME2 = 69
const LOCALE_SABBREVMONTHNAME3 = 70
const LOCALE_SABBREVMONTHNAME4 = 71
const LOCALE_SABBREVMONTHNAME5 = 72
const LOCALE_SABBREVMONTHNAME6 = 73
const LOCALE_SABBREVMONTHNAME7 = 74
const LOCALE_SABBREVMONTHNAME8 = 75
const LOCALE_SABBREVMONTHNAME9 = 76
const LOCALE_SAM = 40
const LOCALE_SCONSOLEFALLBACKNAME = 110
const LOCALE_SCOUNTRY = 6
const LOCALE_SCURRENCY = 20
const LOCALE_SDATE = 29
const LOCALE_SDAYNAME1 = 42
const LOCALE_SDAYNAME2 = 43
const LOCALE_SDAYNAME3 = 44
const LOCALE_SDAYNAME4 = 45
const LOCALE_SDAYNAME5 = 46
const LOCALE_SDAYNAME6 = 47
const LOCALE_SDAYNAME7 = 48
const LOCALE_SDECIMAL = 14
const LOCALE_SDURATION = 93
const LOCALE_SENGCOUNTRY = 4098
const LOCALE_SENGCURRNAME = 4103
const LOCALE_SENGLANGUAGE = 4097
const LOCALE_SENGLISHCOUNTRYNAME = 4098
const LOCALE_SENGLISHDISPLAYNAME = 114
const LOCALE_SENGLISHLANGUAGENAME = 4097
const LOCALE_SGROUPING = 16
const LOCALE_SINTLSYMBOL = 21
const LOCALE_SISO3166CTRYNAME = 90
const LOCALE_SISO3166CTRYNAME2 = 104
const LOCALE_SISO639LANGNAME = 89
const LOCALE_SISO639LANGNAME2 = 103
const LOCALE_SKEYBOARDSTOINSTALL = 94
const LOCALE_SLANGDISPLAYNAME = 111
const LOCALE_SLANGUAGE = 2
const LOCALE_SLIST = 12
const LOCALE_SLOCALIZEDCOUNTRYNAME = 6
const LOCALE_SLOCALIZEDDISPLAYNAME = 2
const LOCALE_SLOCALIZEDLANGUAGENAME = 111
const LOCALE_SLONGDATE = 32
const LOCALE_SMONDECIMALSEP = 22
const LOCALE_SMONGROUPING = 24
const LOCALE_SMONTHDAY = 120
const LOCALE_SMONTHNAME1 = 56
const LOCALE_SMONTHNAME10 = 65
const LOCALE_SMONTHNAME11 = 66
const LOCALE_SMONTHNAME12 = 67
const LOCALE_SMONTHNAME13 = 4110
const LOCALE_SMONTHNAME2 = 57
const LOCALE_SMONTHNAME3 = 58
const LOCALE_SMONTHNAME4 = 59
const LOCALE_SMONTHNAME5 = 60
const LOCALE_SMONTHNAME6 = 61
const LOCALE_SMONTHNAME7 = 62
const LOCALE_SMONTHNAME8 = 63
const LOCALE_SMONTHNAME9 = 64
const LOCALE_SMONTHOUSANDSEP = 23
const LOCALE_SNAME = 92
const LOCALE_SNAN = 105
const LOCALE_SNATIVECOUNTRYNAME = 8
const LOCALE_SNATIVECTRYNAME = 8
const LOCALE_SNATIVECURRNAME = 4104
const LOCALE_SNATIVEDIGITS = 19
const LOCALE_SNATIVEDISPLAYNAME = 115
const LOCALE_SNATIVELANGNAME = 4
const LOCALE_SNATIVELANGUAGENAME = 4
const LOCALE_SNEGATIVESIGN = 81
const LOCALE_SNEGINFINITY = 107
const LOCALE_SOPENTYPELANGUAGETAG = 122
const LOCALE_SPARENT = 109
const LOCALE_SPECIFICDATA = 32
const LOCALE_SPERCENT = 118
const LOCALE_SPERMILLE = 119
const LOCALE_SPM = 41
const LOCALE_SPOSINFINITY = 106
const LOCALE_SPOSITIVESIGN = 80
const LOCALE_SRELATIVELONGDATE = 124
const LOCALE_SSCRIPTS = 108
const LOCALE_SSHORTDATE = 31
const LOCALE_SSHORTESTAM = 126
const LOCALE_SSHORTESTDAYNAME1 = 96
const LOCALE_SSHORTESTDAYNAME2 = 97
const LOCALE_SSHORTESTDAYNAME3 = 98
const LOCALE_SSHORTESTDAYNAME4 = 99
const LOCALE_SSHORTESTDAYNAME5 = 100
const LOCALE_SSHORTESTDAYNAME6 = 101
const LOCALE_SSHORTESTDAYNAME7 = 102
const LOCALE_SSHORTESTPM = 127
const LOCALE_SSHORTTIME = 121
const LOCALE_SSORTLOCALE = 123
const LOCALE_SSORTNAME = 4115
const LOCALE_STHOUSAND = 15
const LOCALE_STIME = 30
const LOCALE_STIMEFORMAT = 4099
const LOCALE_SUPPLEMENTAL = 2
const LOCALE_SYEARMONTH = 4102
const LOCALE_USE_CP_ACP = 1073741824
const LOCALE_USE_NLS = 268435456
const LOCALE_WINDOWS = 1
const LOCATE_NOERR = 2
const LOCATE_VIEW = 1
const LOCKFILE_EXCLUSIVE_LOCK = 2
const LOCKFILE_FAIL_IMMEDIATELY = 1
const LOCK_ELEMENT = 0
const LOCK_UNLOCK_DOOR = 2
const LOCK_UNLOCK_IEPORT = 1
const LOCK_UNLOCK_KEYPAD = 4
const LOGON32_LOGON_BATCH = 4
const LOGON32_LOGON_INTERACTIVE = 2
const LOGON32_LOGON_NETWORK = 3
const LOGON32_LOGON_NETWORK_CLEARTEXT = 8
const LOGON32_LOGON_NEW_CREDENTIALS = 9
const LOGON32_LOGON_SERVICE = 5
const LOGON32_LOGON_UNLOCK = 7
const LOGON32_PROVIDER_DEFAULT = 0
const LOGON32_PROVIDER_VIRTUAL = 4
const LOGON32_PROVIDER_WINNT35 = 1
const LOGON32_PROVIDER_WINNT40 = 2
const LOGON32_PROVIDER_WINNT50 = 3
const LOGON_NETCREDENTIALS_ONLY = 2
const LOGON_WITH_PROFILE = 1
const LOGON_ZERO_PASSWORD_BUFFER = 2147483648
const LOGPIXELSX = 88
const LOGPIXELSY = 90
const LONGDOUBLE_TYPE = 0
const LOOKASIDE_SMALL = 128
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_ATTRIBUTE_DATA = 16777216
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_ATTRIBUTE_INDEX = 33554432
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_ATTRIBUTE_MASK = 4278190080
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_ATTRIBUTE_SYSTEM = 50331648
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_FLAG_DENY_DEFRAG_SET = 2
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_FLAG_FS_SYSTEM_FILE = 4
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_FLAG_PAGE_FILE = 1
const LOOKUP_STREAM_FROM_CLUSTER_ENTRY_FLAG_TXF_SYSTEM_FILE = 8
const LOW_SURROGATE_END = 57343
const LOW_SURROGATE_START = 56320
const LPCPROPSHEETHEADER = 0
const LPCPROPSHEETPAGE = 0
const LPCPROPSHEETPAGE_LATEST = 0
const LPCPROPSHEETPAGE_V1 = 0
const LPCPROPSHEETPAGE_V2 = 0
const LPCPROPSHEETPAGE_V3 = 0
const LPD_DOUBLEBUFFER = 1
const LPD_SHARE_ACCUM = 256
const LPD_SHARE_DEPTH = 64
const LPD_SHARE_STENCIL = 128
const LPD_STEREO = 2
const LPD_SUPPORT_GDI = 16
const LPD_SUPPORT_OPENGL = 32
const LPD_SWAP_COPY = 1024
const LPD_SWAP_EXCHANGE = 512
const LPD_TRANSPARENT = 4096
const LPD_TYPE_COLORINDEX = 1
const LPD_TYPE_RGBA = 0
const LPFNPSPCALLBACK = 0
const LPOCNCONNPROC = 0
const LPOINET = 0
const LPOINETBINDINFO = 0
const LPOINETPRIORITY = 0
const LPOINETPROTOCOL = 0
const LPOINETPROTOCOLEX = 0
const LPOINETPROTOCOLINFO = 0
const LPOINETPROTOCOLROOT = 0
const LPOINETPROTOCOLSINK = 0
const LPOINETPROTOCOLSINKSTACKABLE = 0
const LPOINETSESSION = 0
const LPOINETTHREADSWITCH = 0
const LPOPENCARDNAMEA_EX = 0
const LPOPENCARDNAMEW_EX = 0
const LPOPENCARDNAME_A = 0
const LPOPENCARDNAME_W = 0
const LPPROPSHEETHEADER = 0
const LPPROPSHEETPAGE = 0
const LPPROPSHEETPAGE_LATEST = 0
const LPPROPSHEETPAGE_V1 = 0
const LPPROPSHEETPAGE_V2 = 0
const LPPROPSHEETPAGE_V3 = 0
const LPSCARD_READERSTATE_A = 0
const LPSCARD_READERSTATE_W = 0
const LPSERVICE_MAIN_FUNCTION = 0
const LPTR = 64
const LPTx = 128
const LR_COLOR = 2
const LR_COPYDELETEORG = 8
const LR_COPYFROMRESOURCE = 16384
const LR_COPYRETURNORG = 4
const LR_CREATEDIBSECTION = 8192
const LR_DEFAULTCOLOR = 0
const LR_DEFAULTSIZE = 64
const LR_LOADFROMFILE = 16
const LR_LOADMAP3DCOLORS = 4096
const LR_LOADTRANSPARENT = 32
const LR_MONOCHROME = 1
const LR_SHARED = 32768
const LR_VGACOLOR = 128
const LSFW_LOCK = 1
const LSFW_UNLOCK = 2
const LTGRAY_BRUSH = 1
const LTP_PC_SMT = 1
const LUA_TOKEN = 4
const LWA_ALPHA = 2
const LWA_COLORKEY = 1
const LZERROR_BADINHANDLE = -1
const LZERROR_BADOUTHANDLE = -2
const LZERROR_BADVALUE = -7
const LZERROR_GLOBALLOC = -5
const LZERROR_GLOBLOCK = -6
const LZERROR_READ = -3
const LZERROR_UNKNOWNALG = -8
const LZERROR_WRITE = -4
const LZOpenFile = 0
const L_tmpnam = 12
const L_tmpnam_s = 12
const LoadAccelerators = 0
const LoadBitmap = 0
const LoadCursor = 0
const LoadCursorFromFile = 0
const LoadIcon = 0
const LoadImage = 0
const LoadKeyboardLayout = 0
const LoadLibrary = 0
const LoadLibraryEx = 0
const LoadMenu = 0
const LoadMenuIndirect = 0
const LoadString = 0
const LogonUser = 0
const LogonUserEx = 0
const LookupAccountName = 0
const LookupAccountNameLocal = 0
const LookupAccountSid = 0
const LookupAccountSidLocal = 0
const LookupPrivilegeDisplayName = 0
const LookupPrivilegeName = 0
const LookupPrivilegeValue = 0
const M10d_Any = 1
const M10d_No = 2
const M10d_Yes = 0
const MAC_CHARSET = 77
const MAILSLOT_NO_MESSAGE = -1
const MAILSLOT_WAIT_FOREVER = -1
const MAKEINTRESOURCE = 0
const MAPVK_VK_TO_CHAR = 2
const MAPVK_VK_TO_VSC = 0
const MAPVK_VK_TO_VSC_EX = 4
const MAPVK_VSC_TO_VK = 1
const MAPVK_VSC_TO_VK_EX = 3
const MAP_COMPOSITE = 64
const MAP_EXPAND_LIGATURES = 8192
const MAP_FOLDCZONE = 16
const MAP_FOLDDIGITS = 128
const MAP_PRECOMPOSED = 32
const MARKPARITY = 3
const MARK_HANDLE_NOT_REALTIME = 64
const MARK_HANDLE_NOT_TXF_SYSTEM_LOG = 8
const MARK_HANDLE_PROTECT_CLUSTERS = 1
const MARK_HANDLE_REALTIME = 32
const MARK_HANDLE_TXF_SYSTEM_LOG = 4
const MARSHALINTERFACE_MIN = 500
const MARSHAL_E_FIRST = 2147746080
const MARSHAL_E_LAST = 2147746095
const MARSHAL_S_FIRST = 262432
const MARSHAL_S_LAST = 262447
const MASK_TO_RESET_TLB_BITS = -97
const MAXBYTE = 255
const MAXCHAR = 127
const MAXDWORD = 4294967295
const MAXERRORLENGTH = 256
const MAXGETHOSTSTRUCT = 1024
const MAXIMUM_ALLOWED = 33554432
const MAXIMUM_ATTR_STRING_LENGTH = 32
const MAXIMUM_ENCRYPTION_VALUE = 4
const MAXIMUM_PROCESSORS = 32
const MAXIMUM_PROC_PER_GROUP = 32
const MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16384
const MAXIMUM_SMARTCARD_READERS = 10
const MAXIMUM_SUPPORTED_EXTENSION = 512
const MAXIMUM_SUSPEND_COUNT = 127
const MAXIMUM_WAIT_OBJECTS = 64
const MAXIMUM_XSTATE_FEATURES = 64
const MAXINTATOM = 49152
const MAXLOGICALLOGNAMESIZE = 256
const MAXLONG = 2147483647
const MAXLONGLONG = 9223372036854775807
const MAXPNAMELEN = 32
const MAXPROPPAGES = 100
const MAXSHORT = 32767
const MAXSTRETCHBLTMODE = 4
const MAXUIDLEN = 64
const MAXWORD = 65535
const MAX_ACL_REVISION = 4
const MAX_COMPUTERNAME_LENGTH = 15
const MAX_DEFAULTCHAR = 2
const MAX_HW_COUNTERS = 16
const MAX_JOYSTICKOEMVXDNAME = 260
const MAX_LANA = 254
const MAX_LEADBYTES = 12
const MAX_LOGICALDPIOVERRIDE = 2
const MAX_MONITORS = 4
const MAX_NATURAL_ALIGNMENT = 0
const MAX_NUM_REASONS = 256
const MAX_PATH = 260
const MAX_PERF_OBJECTS_IN_QUERY_FUNCTION = 64
const MAX_PRIORITY = 99
const MAX_PROFILE_LEN = 80
const MAX_REASON_BUGID_LEN = 32
const MAX_REASON_COMMENT_LEN = 512
const MAX_REASON_DESC_LEN = 256
const MAX_REASON_NAME_LEN = 64
const MAX_RESOURCEMANAGER_DESCRIPTION_LENGTH = 64
const MAX_SECTOR_SIZE = 65536
const MAX_SHUTDOWN_TIMEOUT = 315360000
const MAX_SID_SIZE = 256
const MAX_SIZE_SECURITY_ID = 512
const MAX_STR_BLOCKREASON = 256
const MAX_SUPPORTED_OS_NUM = 4
const MAX_TOUCH_COUNT = 256
const MAX_TOUCH_PREDICTION_FILTER_TAPS = 3
const MAX_TRANSACTION_DESCRIPTION_LENGTH = 64
const MAX_UCSCHAR = 1114111
const MAX_VOLUME_ID_SIZE = 36
const MAX_VOLUME_TEMPLATE_SIZE = 40
const MA_ACTIVATE = 1
const MA_ACTIVATEANDEAT = 2
const MA_NOACTIVATE = 3
const MA_NOACTIVATEANDEAT = 4
const MB_ABORTRETRYIGNORE = 2
const MB_APPLMODAL = 0
const MB_CANCELTRYCONTINUE = 6
const MB_COMPOSITE = 2
const MB_CUR_MAX = 0
const MB_DEFAULT_DESKTOP_ONLY = 131072
const MB_DEFBUTTON1 = 0
const MB_DEFBUTTON2 = 256
const MB_DEFBUTTON3 = 512
const MB_DEFBUTTON4 = 768
const MB_DEFMASK = 3840
const MB_ERR_INVALID_CHARS = 8
const MB_HELP = 16384
const MB_ICONASTERISK = 64
const MB_ICONERROR = 16
const MB_ICONEXCLAMATION = 48
const MB_ICONHAND = 16
const MB_ICONINFORMATION = 64
const MB_ICONMASK = 240
const MB_ICONQUESTION = 32
const MB_ICONSTOP = 16
const MB_ICONWARNING = 48
const MB_LEN_MAX = 5
const MB_MISCMASK = 49152
const MB_MODEMASK = 12288
const MB_NOFOCUS = 32768
const MB_OK = 0
const MB_OKCANCEL = 1
const MB_PRECOMPOSED = 1
const MB_RETRYCANCEL = 5
const MB_RIGHT = 524288
const MB_RTLREADING = 1048576
const MB_SERVICE_NOTIFICATION = 2097152
const MB_SERVICE_NOTIFICATION_NT3X = 262144
const MB_SETFOREGROUND = 65536
const MB_SYSTEMMODAL = 4096
const MB_TASKMODAL = 8192
const MB_TOPMOST = 262144
const MB_TYPEMASK = 15
const MB_USEGLYPHCHARS = 4
const MB_USERICON = 128
const MB_YESNO = 4
const MB_YESNOCANCEL = 3
const MCIERR_BAD_CONSTANT = 290
const MCIERR_BAD_INTEGER = 270
const MCIERR_BAD_TIME_FORMAT = 293
const MCIERR_BASE = 256
const MCIERR_CANNOT_LOAD_DRIVER = 266
const MCIERR_CANNOT_USE_ALL = 279
const MCIERR_CREATEWINDOW = 347
const MCIERR_CUSTOM_DRIVER_BASE = 512
const MCIERR_DEVICE_LENGTH = 310
const MCIERR_DEVICE_LOCKED = 288
const MCIERR_DEVICE_NOT_INSTALLED = 306
const MCIERR_DEVICE_NOT_READY = 276
const MCIERR_DEVICE_OPEN = 265
const MCIERR_DEVICE_ORD_LENGTH = 311
const MCIERR_DEVICE_TYPE_REQUIRED = 287
const MCIERR_DRIVER = 278
const MCIERR_DRIVER_INTERNAL = 272
const MCIERR_DUPLICATE_ALIAS = 289
const MCIERR_DUPLICATE_FLAGS = 295
const MCIERR_EXTENSION_NOT_FOUND = 281
const MCIERR_EXTRA_CHARACTERS = 305
const MCIERR_FILENAME_REQUIRED = 304
const MCIERR_FILE_NOT_FOUND = 275
const MCIERR_FILE_NOT_SAVED = 286
const MCIERR_FILE_READ = 348
const MCIERR_FILE_WRITE = 349
const MCIERR_FLAGS_NOT_COMPATIBLE = 284
const MCIERR_GET_CD = 307
const MCIERR_HARDWARE = 262
const MCIERR_ILLEGAL_FOR_AUTO_OPEN = 303
const MCIERR_INTERNAL = 277
const MCIERR_INVALID_DEVICE_ID = 257
const MCIERR_INVALID_DEVICE_NAME = 263
const MCIERR_INVALID_FILE = 296
const MCIERR_MISSING_COMMAND_STRING = 267
const MCIERR_MISSING_DEVICE_NAME = 292
const MCIERR_MISSING_PARAMETER = 273
const MCIERR_MISSING_STRING_ARGUMENT = 269
const MCIERR_MULTIPLE = 280
const MCIERR_MUST_USE_SHAREABLE = 291
const MCIERR_NEW_REQUIRES_ALIAS = 299
const MCIERR_NONAPPLICABLE_FUNCTION = 302
const MCIERR_NOTIFY_ON_AUTO_OPEN = 300
const MCIERR_NO_CLOSING_QUOTE = 294
const MCIERR_NO_ELEMENT_ALLOWED = 301
const MCIERR_NO_IDENTITY = 350
const MCIERR_NO_INTEGER = 312
const MCIERR_NO_WINDOW = 346
const MCIERR_NULL_PARAMETER_BLOCK = 297
const MCIERR_OUTOFRANGE = 282
const MCIERR_OUT_OF_MEMORY = 264
const MCIERR_PARAM_OVERFLOW = 268
const MCIERR_PARSER_INTERNAL = 271
const MCIERR_SEQ_DIV_INCOMPATIBLE = 336
const MCIERR_SEQ_NOMIDIPRESENT = 343
const MCIERR_SEQ_PORTUNSPECIFIED = 342
const MCIERR_SEQ_PORT_INUSE = 337
const MCIERR_SEQ_PORT_MAPNODEVICE = 339
const MCIERR_SEQ_PORT_MISCERROR = 340
const MCIERR_SEQ_PORT_NONEXISTENT = 338
const MCIERR_SEQ_TIMER = 341
const MCIERR_SET_CD = 308
const MCIERR_SET_DRIVE = 309
const MCIERR_UNNAMED_RESOURCE = 298
const MCIERR_UNRECOGNIZED_COMMAND = 261
const MCIERR_UNRECOGNIZED_KEYWORD = 259
const MCIERR_UNSUPPORTED_FUNCTION = 274
const MCIERR_WAVE_INPUTSINUSE = 322
const MCIERR_WAVE_INPUTSUNSUITABLE = 328
const MCIERR_WAVE_INPUTUNSPECIFIED = 325
const MCIERR_WAVE_OUTPUTSINUSE = 320
const MCIERR_WAVE_OUTPUTSUNSUITABLE = 326
const MCIERR_WAVE_OUTPUTUNSPECIFIED = 324
const MCIERR_WAVE_SETINPUTINUSE = 323
const MCIERR_WAVE_SETINPUTUNSUITABLE = 329
const MCIERR_WAVE_SETOUTPUTINUSE = 321
const MCIERR_WAVE_SETOUTPUTUNSUITABLE = 327
const MCI_ALL_DEVICE_ID = -1
const MCI_ANIM_GETDEVCAPS_CAN_REVERSE = 16385
const MCI_ANIM_GETDEVCAPS_CAN_STRETCH = 16391
const MCI_ANIM_GETDEVCAPS_FAST_RATE = 16386
const MCI_ANIM_GETDEVCAPS_MAX_WINDOWS = 16392
const MCI_ANIM_GETDEVCAPS_NORMAL_RATE = 16388
const MCI_ANIM_GETDEVCAPS_PALETTES = 16390
const MCI_ANIM_GETDEVCAPS_SLOW_RATE = 16387
const MCI_ANIM_INFO_TEXT = 65536
const MCI_ANIM_OPEN_NOSTATIC = 262144
const MCI_ANIM_OPEN_PARENT = 131072
const MCI_ANIM_OPEN_WS = 65536
const MCI_ANIM_PLAY_FAST = 262144
const MCI_ANIM_PLAY_REVERSE = 131072
const MCI_ANIM_PLAY_SCAN = 1048576
const MCI_ANIM_PLAY_SLOW = 524288
const MCI_ANIM_PLAY_SPEED = 65536
const MCI_ANIM_PUT_DESTINATION = 262144
const MCI_ANIM_PUT_SOURCE = 131072
const MCI_ANIM_REALIZE_BKGD = 131072
const MCI_ANIM_REALIZE_NORM = 65536
const MCI_ANIM_RECT = 65536
const MCI_ANIM_STATUS_FORWARD = 16386
const MCI_ANIM_STATUS_HPAL = 16388
const MCI_ANIM_STATUS_HWND = 16387
const MCI_ANIM_STATUS_SPEED = 16385
const MCI_ANIM_STATUS_STRETCH = 16389
const MCI_ANIM_STEP_FRAMES = 131072
const MCI_ANIM_STEP_REVERSE = 65536
const MCI_ANIM_UPDATE_HDC = 131072
const MCI_ANIM_WHERE_DESTINATION = 262144
const MCI_ANIM_WHERE_SOURCE = 131072
const MCI_ANIM_WINDOW_DEFAULT = 0
const MCI_ANIM_WINDOW_DISABLE_STRETCH = 2097152
const MCI_ANIM_WINDOW_ENABLE_STRETCH = 1048576
const MCI_ANIM_WINDOW_HWND = 65536
const MCI_ANIM_WINDOW_STATE = 262144
const MCI_ANIM_WINDOW_TEXT = 524288
const MCI_BREAK = 2065
const MCI_BREAK_HWND = 512
const MCI_BREAK_KEY = 256
const MCI_BREAK_OFF = 1024
const MCI_CDA_STATUS_TYPE_TRACK = 16385
const MCI_CDA_TRACK_AUDIO = 1088
const MCI_CDA_TRACK_OTHER = 1089
const MCI_CD_OFFSET = 1088
const MCI_CLOSE = 2052
const MCI_COPY = 2130
const MCI_CUE = 2096
const MCI_CUT = 2129
const MCI_DELETE = 2134
const MCI_DEVTYPE_ANIMATION = 519
const MCI_DEVTYPE_CD_AUDIO = 516
const MCI_DEVTYPE_DAT = 517
const MCI_DEVTYPE_DIGITAL_VIDEO = 520
const MCI_DEVTYPE_FIRST = 513
const MCI_DEVTYPE_FIRST_USER = 4096
const MCI_DEVTYPE_LAST = 523
const MCI_DEVTYPE_OTHER = 521
const MCI_DEVTYPE_OVERLAY = 515
const MCI_DEVTYPE_SCANNER = 518
const MCI_DEVTYPE_SEQUENCER = 523
const MCI_DEVTYPE_VCR = 513
const MCI_DEVTYPE_VIDEODISC = 514
const MCI_DEVTYPE_WAVEFORM_AUDIO = 522
const MCI_ESCAPE = 2053
const MCI_FIRST = 2048
const MCI_FORMAT_BYTES = 8
const MCI_FORMAT_FRAMES = 3
const MCI_FORMAT_HMS = 1
const MCI_FORMAT_MILLISECONDS = 0
const MCI_FORMAT_MSF = 2
const MCI_FORMAT_SAMPLES = 9
const MCI_FORMAT_SMPTE_24 = 4
const MCI_FORMAT_SMPTE_25 = 5
const MCI_FORMAT_SMPTE_30 = 6
const MCI_FORMAT_SMPTE_30DROP = 7
const MCI_FORMAT_TMSF = 10
const MCI_FREEZE = 2116
const MCI_FROM = 4
const MCI_GETDEVCAPS = 2059
const MCI_GETDEVCAPS_CAN_EJECT = 7
const MCI_GETDEVCAPS_CAN_PLAY = 8
const MCI_GETDEVCAPS_CAN_RECORD = 1
const MCI_GETDEVCAPS_CAN_SAVE = 9
const MCI_GETDEVCAPS_COMPOUND_DEVICE = 6
const MCI_GETDEVCAPS_DEVICE_TYPE = 4
const MCI_GETDEVCAPS_HAS_AUDIO = 2
const MCI_GETDEVCAPS_HAS_VIDEO = 3
const MCI_GETDEVCAPS_ITEM = 256
const MCI_GETDEVCAPS_USES_FILES = 5
const MCI_INFO = 2058
const MCI_INFO_COPYRIGHT = 8192
const MCI_INFO_FILE = 512
const MCI_INFO_MEDIA_IDENTITY = 2048
const MCI_INFO_MEDIA_UPC = 1024
const MCI_INFO_NAME = 4096
const MCI_INFO_PRODUCT = 256
const MCI_LAST = 4095
const MCI_LOAD = 2128
const MCI_LOAD_FILE = 256
const MCI_MODE_NOT_READY = 524
const MCI_MODE_OPEN = 530
const MCI_MODE_PAUSE = 529
const MCI_MODE_PLAY = 526
const MCI_MODE_RECORD = 527
const MCI_MODE_SEEK = 528
const MCI_MODE_STOP = 525
const MCI_NOTIFY = 1
const MCI_NOTIFY_ABORTED = 4
const MCI_NOTIFY_FAILURE = 8
const MCI_NOTIFY_SUCCESSFUL = 1
const MCI_NOTIFY_SUPERSEDED = 2
const MCI_OPEN = 2051
const MCI_OPEN_ALIAS = 1024
const MCI_OPEN_ELEMENT = 512
const MCI_OPEN_ELEMENT_ID = 2048
const MCI_OPEN_SHAREABLE = 256
const MCI_OPEN_TYPE = 8192
const MCI_OPEN_TYPE_ID = 4096
const MCI_OVLY_GETDEVCAPS_CAN_FREEZE = 16386
const MCI_OVLY_GETDEVCAPS_CAN_STRETCH = 16385
const MCI_OVLY_GETDEVCAPS_MAX_WINDOWS = 16387
const MCI_OVLY_INFO_TEXT = 65536
const MCI_OVLY_OPEN_PARENT = 131072
const MCI_OVLY_OPEN_WS = 65536
const MCI_OVLY_PUT_DESTINATION = 262144
const MCI_OVLY_PUT_FRAME = 524288
const MCI_OVLY_PUT_SOURCE = 131072
const MCI_OVLY_PUT_VIDEO = 1048576
const MCI_OVLY_RECT = 65536
const MCI_OVLY_STATUS_HWND = 16385
const MCI_OVLY_STATUS_STRETCH = 16386
const MCI_OVLY_WHERE_DESTINATION = 262144
const MCI_OVLY_WHERE_FRAME = 524288
const MCI_OVLY_WHERE_SOURCE = 131072
const MCI_OVLY_WHERE_VIDEO = 1048576
const MCI_OVLY_WINDOW_DEFAULT = 0
const MCI_OVLY_WINDOW_DISABLE_STRETCH = 2097152
const MCI_OVLY_WINDOW_ENABLE_STRETCH = 1048576
const MCI_OVLY_WINDOW_HWND = 65536
const MCI_OVLY_WINDOW_STATE = 262144
const MCI_OVLY_WINDOW_TEXT = 524288
const MCI_PASTE = 2131
const MCI_PAUSE = 2057
const MCI_PLAY = 2054
const MCI_PUT = 2114
const MCI_REALIZE = 2112
const MCI_RECORD = 2063
const MCI_RECORD_INSERT = 256
const MCI_RECORD_OVERWRITE = 512
const MCI_RESUME = 2133
const MCI_SAVE = 2067
const MCI_SAVE_FILE = 256
const MCI_SEEK = 2055
const MCI_SEEK_TO_END = 512
const MCI_SEEK_TO_START = 256
const MCI_SEQ_DIV_PPQN = 1216
const MCI_SEQ_DIV_SMPTE_24 = 1217
const MCI_SEQ_DIV_SMPTE_25 = 1218
const MCI_SEQ_DIV_SMPTE_30 = 1220
const MCI_SEQ_DIV_SMPTE_30DROP = 1219
const MCI_SEQ_FILE = 16386
const MCI_SEQ_FORMAT_SONGPTR = 16385
const MCI_SEQ_MAPPER = 65535
const MCI_SEQ_MIDI = 16387
const MCI_SEQ_NONE = 65533
const MCI_SEQ_OFFSET = 1216
const MCI_SEQ_SET_MASTER = 524288
const MCI_SEQ_SET_OFFSET = 16777216
const MCI_SEQ_SET_PORT = 131072
const MCI_SEQ_SET_SLAVE = 262144
const MCI_SEQ_SET_TEMPO = 65536
const MCI_SEQ_SMPTE = 16388
const MCI_SEQ_STATUS_COPYRIGHT = 16396
const MCI_SEQ_STATUS_DIVTYPE = 16394
const MCI_SEQ_STATUS_MASTER = 16392
const MCI_SEQ_STATUS_NAME = 16395
const MCI_SEQ_STATUS_OFFSET = 16393
const MCI_SEQ_STATUS_PORT = 16387
const MCI_SEQ_STATUS_SLAVE = 16391
const MCI_SEQ_STATUS_TEMPO = 16386
const MCI_SET = 2061
const MCI_SET_AUDIO = 2048
const MCI_SET_AUDIO_ALL = 0
const MCI_SET_AUDIO_LEFT = 1
const MCI_SET_AUDIO_RIGHT = 2
const MCI_SET_DOOR_CLOSED = 512
const MCI_SET_DOOR_OPEN = 256
const MCI_SET_OFF = 16384
const MCI_SET_ON = 8192
const MCI_SET_TIME_FORMAT = 1024
const MCI_SET_VIDEO = 4096
const MCI_SPIN = 2060
const MCI_STATUS = 2068
const MCI_STATUS_CURRENT_TRACK = 8
const MCI_STATUS_ITEM = 256
const MCI_STATUS_LENGTH = 1
const MCI_STATUS_MEDIA_PRESENT = 5
const MCI_STATUS_MODE = 4
const MCI_STATUS_NUMBER_OF_TRACKS = 3
const MCI_STATUS_POSITION = 2
const MCI_STATUS_READY = 7
const MCI_STATUS_START = 512
const MCI_STATUS_TIME_FORMAT = 6
const MCI_STEP = 2062
const MCI_STOP = 2056
const MCI_STRING_OFFSET = 512
const MCI_SYSINFO = 2064
const MCI_SYSINFO_INSTALLNAME = 2048
const MCI_SYSINFO_NAME = 1024
const MCI_SYSINFO_OPEN = 512
const MCI_SYSINFO_QUANTITY = 256
const MCI_TO = 8
const MCI_TRACK = 16
const MCI_UNFREEZE = 2117
const MCI_UPDATE = 2132
const MCI_USER_MESSAGES = 3072
const MCI_VD_ESCAPE_STRING = 256
const MCI_VD_FORMAT_TRACK = 16385
const MCI_VD_GETDEVCAPS_CAN_REVERSE = 16386
const MCI_VD_GETDEVCAPS_CAV = 131072
const MCI_VD_GETDEVCAPS_CLV = 65536
const MCI_VD_GETDEVCAPS_FAST_RATE = 16387
const MCI_VD_GETDEVCAPS_NORMAL_RATE = 16389
const MCI_VD_GETDEVCAPS_SLOW_RATE = 16388
const MCI_VD_MEDIA_CAV = 1027
const MCI_VD_MEDIA_CLV = 1026
const MCI_VD_MEDIA_OTHER = 1028
const MCI_VD_MODE_PARK = 1025
const MCI_VD_OFFSET = 1024
const MCI_VD_PLAY_FAST = 131072
const MCI_VD_PLAY_REVERSE = 65536
const MCI_VD_PLAY_SCAN = 524288
const MCI_VD_PLAY_SLOW = 1048576
const MCI_VD_PLAY_SPEED = 262144
const MCI_VD_SEEK_REVERSE = 65536
const MCI_VD_SPIN_DOWN = 131072
const MCI_VD_SPIN_UP = 65536
const MCI_VD_STATUS_DISC_SIZE = 16390
const MCI_VD_STATUS_FORWARD = 16387
const MCI_VD_STATUS_MEDIA_TYPE = 16388
const MCI_VD_STATUS_SIDE = 16389
const MCI_VD_STATUS_SPEED = 16386
const MCI_VD_STEP_FRAMES = 65536
const MCI_VD_STEP_REVERSE = 131072
const MCI_WAIT = 2
const MCI_WAVE_GETDEVCAPS_INPUTS = 16385
const MCI_WAVE_GETDEVCAPS_OUTPUTS = 16386
const MCI_WAVE_INPUT = 4194304
const MCI_WAVE_MAPPER = 1153
const MCI_WAVE_OFFSET = 1152
const MCI_WAVE_OPEN_BUFFER = 65536
const MCI_WAVE_OUTPUT = 8388608
const MCI_WAVE_PCM = 1152
const MCI_WAVE_SET_ANYINPUT = 67108864
const MCI_WAVE_SET_ANYOUTPUT = 134217728
const MCI_WAVE_SET_AVGBYTESPERSEC = 524288
const MCI_WAVE_SET_BITSPERSAMPLE = 2097152
const MCI_WAVE_SET_BLOCKALIGN = 1048576
const MCI_WAVE_SET_CHANNELS = 131072
const MCI_WAVE_SET_FORMATTAG = 65536
const MCI_WAVE_SET_SAMPLESPERSEC = 262144
const MCI_WAVE_STATUS_AVGBYTESPERSEC = 16388
const MCI_WAVE_STATUS_BITSPERSAMPLE = 16390
const MCI_WAVE_STATUS_BLOCKALIGN = 16389
const MCI_WAVE_STATUS_CHANNELS = 16386
const MCI_WAVE_STATUS_FORMATTAG = 16385
const MCI_WAVE_STATUS_LEVEL = 16391
const MCI_WAVE_STATUS_SAMPLESPERSEC = 16387
const MCI_WHERE = 2115
const MCI_WINDOW = 2113
const MDIS_ALLCHILDSTYLES = 1
const MDITILE_HORIZONTAL = 1
const MDITILE_SKIPDISABLED = 2
const MDITILE_VERTICAL = 0
const MDITILE_ZORDER = 4
const MDMSPKRFLAG_CALLSETUP = 8
const MDMSPKRFLAG_DIAL = 2
const MDMSPKRFLAG_OFF = 1
const MDMSPKRFLAG_ON = 4
const MDMSPKR_CALLSETUP = 3
const MDMSPKR_DIAL = 1
const MDMSPKR_OFF = 0
const MDMSPKR_ON = 2
const MDMVOLFLAG_HIGH = 4
const MDMVOLFLAG_LOW = 1
const MDMVOLFLAG_MEDIUM = 2
const MDMVOL_HIGH = 2
const MDMVOL_LOW = 0
const MDMVOL_MEDIUM = 1
const MDM_ANALOG_RLP_OFF = 1
const MDM_ANALOG_RLP_ON = 0
const MDM_ANALOG_V34 = 2
const MDM_AUTO_ML_2 = 2
const MDM_AUTO_ML_DEFAULT = 0
const MDM_AUTO_ML_NONE = 1
const MDM_AUTO_SPEED_DEFAULT = 0
const MDM_BEARERMODE_ANALOG = 0
const MDM_BEARERMODE_GSM = 2
const MDM_BEARERMODE_ISDN = 1
const MDM_BLIND_DIAL = 512
const MDM_CCITT_OVERRIDE = 64
const MDM_CELLULAR = 8
const MDM_COMPRESSION = 1
const MDM_DIAGNOSTICS = 2048
const MDM_ERROR_CONTROL = 2
const MDM_FLOWCONTROL_HARD = 16
const MDM_FLOWCONTROL_SOFT = 32
const MDM_FORCED_EC = 4
const MDM_HDLCPPP_AUTH_CHAP = 3
const MDM_HDLCPPP_AUTH_DEFAULT = 0
const MDM_HDLCPPP_AUTH_MSCHAP = 4
const MDM_HDLCPPP_AUTH_NONE = 1
const MDM_HDLCPPP_AUTH_PAP = 2
const MDM_HDLCPPP_ML_2 = 2
const MDM_HDLCPPP_ML_DEFAULT = 0
const MDM_HDLCPPP_ML_NONE = 1
const MDM_HDLCPPP_SPEED_56K = 2
const MDM_HDLCPPP_SPEED_64K = 1
const MDM_HDLCPPP_SPEED_DEFAULT = 0
const MDM_MASK_AUTO_ML = 192
const MDM_MASK_AUTO_SPEED = 7
const MDM_MASK_BEARERMODE = 61440
const MDM_MASK_EXTENDEDINFO = 268431360
const MDM_MASK_HDLCPPP_AUTH = 56
const MDM_MASK_HDLCPPP_ML = 192
const MDM_MASK_HDLCPPP_SPEED = 7
const MDM_MASK_PROTOCOLDATA = 267386880
const MDM_MASK_PROTOCOLID = 983040
const MDM_MASK_PROTOCOLINFO = 268369920
const MDM_MASK_V110_SPEED = 15
const MDM_MASK_V120_ML = 192
const MDM_MASK_V120_SPEED = 7
const MDM_MASK_X75_DATA = 7
const MDM_PIAFS_INCOMING = 0
const MDM_PIAFS_OUTGOING = 1
const MDM_PROTOCOLID_ANALOG = 7
const MDM_PROTOCOLID_AUTO = 6
const MDM_PROTOCOLID_DEFAULT = 0
const MDM_PROTOCOLID_GPRS = 8
const MDM_PROTOCOLID_HDLCPPP = 1
const MDM_PROTOCOLID_PIAFS = 9
const MDM_PROTOCOLID_V110 = 4
const MDM_PROTOCOLID_V120 = 5
const MDM_PROTOCOLID_V128 = 2
const MDM_PROTOCOLID_X75 = 3
const MDM_PROTOCOL_ANALOG_NRLP = 1507328
const MDM_PROTOCOL_ANALOG_RLP = 458752
const MDM_PROTOCOL_ANALOG_V34 = 2555904
const MDM_PROTOCOL_AUTO_1CH = 67502080
const MDM_PROTOCOL_AUTO_2CH = 134610944
const MDM_PROTOCOL_GPRS = 524288
const MDM_PROTOCOL_HDLCPPP_112K = 136380416
const MDM_PROTOCOL_HDLCPPP_112K_CHAP = 161546240
const MDM_PROTOCOL_HDLCPPP_112K_MSCHAP = 169934848
const MDM_PROTOCOL_HDLCPPP_112K_PAP = 153157632
const MDM_PROTOCOL_HDLCPPP_128K = 135331840
const MDM_PROTOCOL_HDLCPPP_128K_CHAP = 160497664
const MDM_PROTOCOL_HDLCPPP_128K_MSCHAP = 168886272
const MDM_PROTOCOL_HDLCPPP_128K_PAP = 152109056
const MDM_PROTOCOL_HDLCPPP_56K = 2162688
const MDM_PROTOCOL_HDLCPPP_64K = 1114112
const MDM_PROTOCOL_PIAFS_INCOMING = 589824
const MDM_PROTOCOL_PIAFS_OUTGOING = 1638400
const MDM_PROTOCOL_V110_12DOT0K = 5505024
const MDM_PROTOCOL_V110_14DOT4K = 6553600
const MDM_PROTOCOL_V110_19DOT2K = 7602176
const MDM_PROTOCOL_V110_1DOT2K = 1310720
const MDM_PROTOCOL_V110_28DOT8K = 8650752
const MDM_PROTOCOL_V110_2DOT4K = 2359296
const MDM_PROTOCOL_V110_38DOT4K = 9699328
const MDM_PROTOCOL_V110_4DOT8K = 3407872
const MDM_PROTOCOL_V110_57DOT6K = 10747904
const MDM_PROTOCOL_V110_9DOT6K = 4456448
const MDM_PROTOCOL_V120_112K = 136642560
const MDM_PROTOCOL_V120_128K = 135593984
const MDM_PROTOCOL_V120_56K = 69533696
const MDM_PROTOCOL_V120_64K = 68485120
const MDM_PROTOCOL_X75_128K = 2293760
const MDM_PROTOCOL_X75_64K = 1245184
const MDM_PROTOCOL_X75_BTX = 4390912
const MDM_PROTOCOL_X75_T_70 = 3342336
const MDM_SHIFT_AUTO_ML = 6
const MDM_SHIFT_AUTO_SPEED = 0
const MDM_SHIFT_BEARERMODE = 12
const MDM_SHIFT_EXTENDEDINFO = 12
const MDM_SHIFT_HDLCPPP_AUTH = 3
const MDM_SHIFT_HDLCPPP_ML = 6
const MDM_SHIFT_HDLCPPP_SPEED = 0
const MDM_SHIFT_PROTOCOLDATA = 20
const MDM_SHIFT_PROTOCOLID = 16
const MDM_SHIFT_PROTOCOLINFO = 16
const MDM_SHIFT_V110_SPEED = 0
const MDM_SHIFT_V120_ML = 6
const MDM_SHIFT_V120_SPEED = 0
const MDM_SHIFT_X75_DATA = 0
const MDM_SPEED_ADJUST = 128
const MDM_TONE_DIAL = 256
const MDM_V110_SPEED_12DOT0K = 5
const MDM_V110_SPEED_14DOT4K = 6
const MDM_V110_SPEED_19DOT2K = 7
const MDM_V110_SPEED_1DOT2K = 1
const MDM_V110_SPEED_28DOT8K = 8
const MDM_V110_SPEED_2DOT4K = 2
const MDM_V110_SPEED_38DOT4K = 9
const MDM_V110_SPEED_4DOT8K = 3
const MDM_V110_SPEED_57DOT6K = 10
const MDM_V110_SPEED_9DOT6K = 4
const MDM_V110_SPEED_DEFAULT = 0
const MDM_V120_ML_2 = 2
const MDM_V120_ML_DEFAULT = 0
const MDM_V120_ML_NONE = 1
const MDM_V120_SPEED_56K = 2
const MDM_V120_SPEED_64K = 1
const MDM_V120_SPEED_DEFAULT = 0
const MDM_V23_OVERRIDE = 1024
const MDM_X75_DATA_128K = 2
const MDM_X75_DATA_64K = 1
const MDM_X75_DATA_BTX = 4
const MDM_X75_DATA_DEFAULT = 0
const MDM_X75_DATA_T_70 = 3
const MEDIA_CURRENTLY_MOUNTED = 2147483648
const MEDIA_ERASEABLE = 1
const MEDIA_READ_ONLY = 4
const MEDIA_READ_WRITE = 8
const MEDIA_WRITE_ONCE = 2
const MEDIA_WRITE_PROTECTED = 256
const MEHC_PATROL_SCRUBBER_PRESENT = 1
const MEMBERID_NIL = -1
const MEMJOURNAL_DFLT_FILECHUNKSIZE = 1024
const MEMORY_ALLOCATION_ALIGNMENT = 8
const MEMORY_PRIORITY_BELOW_NORMAL = 4
const MEMORY_PRIORITY_LOW = 2
const MEMORY_PRIORITY_MEDIUM = 3
const MEMORY_PRIORITY_NORMAL = 5
const MEMORY_PRIORITY_VERY_LOW = 1
const MEMTYPE_HEAP = 1
const MEMTYPE_LOOKASIDE = 2
const MEMTYPE_PCACHE = 4
const MEM_4MB_PAGES = 2147483648
const MEM_64K_PAGES = 541065216
const MEM_AffMask = 63
const MEM_Agg = 32768
const MEM_Blob = 16
const MEM_COMMIT = 4096
const MEM_Cleared = 256
const MEM_DECOMMIT = 16384
const MEM_DIFFERENT_IMAGE_BASE_OK = 8388608
const MEM_Dyn = 4096
const MEM_EXTENDED_PARAMETER_GRAPHICS = 1
const MEM_EXTENDED_PARAMETER_NONPAGED = 2
const MEM_EXTENDED_PARAMETER_NONPAGED_HUGE = 16
const MEM_EXTENDED_PARAMETER_NONPAGED_LARGE = 8
const MEM_EXTENDED_PARAMETER_TYPE_BITS = 8
const MEM_EXTENDED_PARAMETER_ZERO_PAGES_OPTIONAL = 4
const MEM_Ephem = 16384
const MEM_FREE = 65536
const MEM_FromBind = 64
const MEM_IMAGE = 16777216
const MEM_Int = 4
const MEM_IntReal = 32
const MEM_LARGE_PAGES = 536870912
const MEM_MAPPED = 262144
const MEM_Null = 1
const MEM_PHYSICAL = 4194304
const MEM_PRIVATE = 131072
const MEM_RELEASE = 32768
const MEM_RESERVE = 8192
const MEM_RESET = 524288
const MEM_RESET_UNDO = 16777216
const MEM_ROTATE = 8388608
const MEM_Real = 8
const MEM_Static = 8192
const MEM_Str = 2
const MEM_Subtype = 2048
const MEM_TOP_DOWN = 1048576
const MEM_Term = 512
const MEM_TypeMask = 3519
const MEM_UNMAP_WITH_TRANSIENT_BOOST = 1
const MEM_Undefined = 0
const MEM_WRITE_WATCH = 2097152
const MEM_Zero = 1024
const MENU_EVENT = 8
const MESSAGE_RESOURCE_UNICODE = 1
const METAFILE_DRIVER = 2049
const META_ANIMATEPALETTE = 1078
const META_ARC = 2071
const META_BITBLT = 2338
const META_CHORD = 2096
const META_CREATEBRUSHINDIRECT = 764
const META_CREATEFONTINDIRECT = 763
const META_CREATEPALETTE = 247
const META_CREATEPATTERNBRUSH = 505
const META_CREATEPENINDIRECT = 762
const META_CREATEREGION = 1791
const META_DELETEOBJECT = 496
const META_DIBBITBLT = 2368
const META_DIBCREATEPATTERNBRUSH = 322
const META_DIBSTRETCHBLT = 2881
const META_ELLIPSE = 1048
const META_ESCAPE = 1574
const META_EXCLUDECLIPRECT = 1045
const META_EXTFLOODFILL = 1352
const META_EXTTEXTOUT = 2610
const META_FILLREGION = 552
const META_FLOODFILL = 1049
const META_FRAMEREGION = 1065
const META_INTERSECTCLIPRECT = 1046
const META_INVERTREGION = 298
const META_LINETO = 531
const META_MOVETO = 532
const META_OFFSETCLIPRGN = 544
const META_OFFSETVIEWPORTORG = 529
const META_OFFSETWINDOWORG = 527
const META_PAINTREGION = 299
const META_PATBLT = 1565
const META_PIE = 2074
const META_POLYGON = 804
const META_POLYLINE = 805
const META_POLYPOLYGON = 1336
const META_REALIZEPALETTE = 53
const META_RECTANGLE = 1051
const META_RESIZEPALETTE = 313
const META_RESTOREDC = 295
const META_ROUNDRECT = 1564
const META_SAVEDC = 30
const META_SCALEVIEWPORTEXT = 1042
const META_SCALEWINDOWEXT = 1040
const META_SELECTCLIPREGION = 300
const META_SELECTOBJECT = 301
const META_SELECTPALETTE = 564
const META_SETBKCOLOR = 513
const META_SETBKMODE = 258
const META_SETDIBTODEV = 3379
const META_SETLAYOUT = 329
const META_SETMAPMODE = 259
const META_SETMAPPERFLAGS = 561
const META_SETPALENTRIES = 55
const META_SETPIXEL = 1055
const META_SETPOLYFILLMODE = 262
const META_SETRELABS = 261
const META_SETROP2 = 260
const META_SETSTRETCHBLTMODE = 263
const META_SETTEXTALIGN = 302
const META_SETTEXTCHAREXTRA = 264
const META_SETTEXTCOLOR = 521
const META_SETTEXTJUSTIFICATION = 522
const META_SETVIEWPORTEXT = 526
const META_SETVIEWPORTORG = 525
const META_SETWINDOWEXT = 524
const META_SETWINDOWORG = 523
const META_STRETCHBLT = 2851
const META_STRETCHDIB = 3907
const META_TEXTOUT = 1313
const METHOD_BUFFERED = 0
const METHOD_DIRECT_FROM_HARDWARE = 2
const METHOD_DIRECT_TO_HARDWARE = 1
const METHOD_IN_DIRECT = 1
const METHOD_NEITHER = 3
const METHOD_OUT_DIRECT = 2
const METRICS_USEDEFAULT = -1
const MEVT_F_CALLBACK = 1073741824
const MEVT_F_LONG = 2147483648
const MEVT_F_SHORT = 0
const MFCOMMENT = 15
const MFS_CHECKED = 8
const MFS_DEFAULT = 4096
const MFS_DISABLED = 3
const MFS_ENABLED = 0
const MFS_GRAYED = 3
const MFS_HILITE = 128
const MFS_UNCHECKED = 0
const MFS_UNHILITE = 0
const MFT_BITMAP = 4
const MFT_MENUBARBREAK = 32
const MFT_MENUBREAK = 64
const MFT_OWNERDRAW = 256
const MFT_RADIOCHECK = 512
const MFT_RIGHTJUSTIFY = 16384
const MFT_RIGHTORDER = 8192
const MFT_SEPARATOR = 2048
const MFT_STRING = 0
const MF_APPEND = 256
const MF_BITMAP = 4
const MF_BYCOMMAND = 0
const MF_BYPOSITION = 1024
const MF_CALLBACKS = 134217728
const MF_CHANGE = 128
const MF_CHECKED = 8
const MF_CONV = 1073741824
const MF_DEFAULT = 4096
const MF_DELETE = 512
const MF_DISABLED = 2
const MF_ENABLED = 0
const MF_END = 128
const MF_ERRORS = 268435456
const MF_GRAYED = 1
const MF_HELP = 16384
const MF_HILITE = 128
const MF_HSZ_INFO = 16777216
const MF_INSERT = 0
const MF_LINKS = 536870912
const MF_MASK = 4278190080
const MF_MENUBARBREAK = 32
const MF_MENUBREAK = 64
const MF_MOUSESELECT = 32768
const MF_OWNERDRAW = 256
const MF_POPUP = 16
const MF_POSTMSGS = 67108864
const MF_REMOVE = 4096
const MF_RIGHTJUSTIFY = 16384
const MF_SENDMSGS = 33554432
const MF_SEPARATOR = 2048
const MF_STRING = 0
const MF_SYSMENU = 8192
const MF_UNCHECKED = 0
const MF_UNHILITE = 0
const MF_USECHECKBITMAPS = 512
const MHDR_DONE = 1
const MHDR_INQUEUE = 4
const MHDR_ISSTRM = 8
const MHDR_PREPARED = 2
const MH_CLEANUP = 4
const MH_CREATE = 1
const MH_DELETE = 3
const MH_KEEP = 2
const MICROSOFT_ROOT_CERT_CHAIN_POLICY_CHECK_APPLICATION_ROOT_FLAG = 131072
const MICROSOFT_ROOT_CERT_CHAIN_POLICY_DISABLE_FLIGHT_ROOT_FLAG = 262144
const MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG = 65536
const MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS = 1
const MIDICAPS_CACHE = 4
const MIDICAPS_LRVOLUME = 2
const MIDICAPS_STREAM = 8
const MIDICAPS_VOLUME = 1
const MIDIERR_BADOPENMODE = 70
const MIDIERR_BASE = 64
const MIDIERR_DONT_CONTINUE = 71
const MIDIERR_INVALIDSETUP = 69
const MIDIERR_LASTERROR = 71
const MIDIERR_NODEVICE = 68
const MIDIERR_NOMAP = 66
const MIDIERR_NOTREADY = 67
const MIDIERR_STILLPLAYING = 65
const MIDIERR_UNPREPARED = 64
const MIDIMAPPER = -1
const MIDIPATCHSIZE = 128
const MIDIPROP_GET = 1073741824
const MIDIPROP_SET = 2147483648
const MIDIPROP_TEMPO = 2
const MIDIPROP_TIMEDIV = 1
const MIDISTRM_ERROR = -2
const MIDI_CACHE_ALL = 1
const MIDI_CACHE_BESTFIT = 2
const MIDI_CACHE_QUERY = 3
const MIDI_IO_STATUS = 32
const MIDI_MAPPER = -1
const MIDI_UNCACHE = 4
const MIIM_BITMAP = 128
const MIIM_CHECKMARKS = 8
const MIIM_DATA = 32
const MIIM_FTYPE = 256
const MIIM_ID = 2
const MIIM_STATE = 1
const MIIM_STRING = 64
const MIIM_SUBMENU = 4
const MIIM_TYPE = 16
const MILCORE_TS_QUERYVER_RESULT_FALSE = 0
const MILCORE_TS_QUERYVER_RESULT_TRUE = 2147483647
const MIM_APPLYTOSUBMENUS = 2147483648
const MIM_BACKGROUND = 2
const MIM_CLOSE = 962
const MIM_DATA = 963
const MIM_ERROR = 965
const MIM_HELPID = 4
const MIM_LONGDATA = 964
const MIM_LONGERROR = 966
const MIM_MAXHEIGHT = 1
const MIM_MENUDATA = 8
const MIM_MOREDATA = 972
const MIM_OPEN = 961
const MIM_STYLE = 16
const MINCHAR = 128
const MINGW_HAS_DDK_H = 1
const MINGW_HAS_SECURE_API = 1
const MINLONG = 2147483648
const MINSHORT = 32768
const MIN_ACL_REVISION = 2
const MIN_LOGICALDPIOVERRIDE = -2
const MIN_PRIORITY = 1
const MIN_UCSCHAR = 0
const MIXERCONTROL_CONTROLF_DISABLED = 2147483648
const MIXERCONTROL_CONTROLF_MULTIPLE = 2
const MIXERCONTROL_CONTROLF_UNIFORM = 1
const MIXERCONTROL_CONTROLTYPE_BASS = 1342373890
const MIXERCONTROL_CONTROLTYPE_BASS_BOOST = 536945271
const MIXERCONTROL_CONTROLTYPE_BOOLEAN = 536936448
const MIXERCONTROL_CONTROLTYPE_BOOLEANMETER = 268500992
const MIXERCONTROL_CONTROLTYPE_BUTTON = 553713664
const MIXERCONTROL_CONTROLTYPE_CUSTOM = 0
const MIXERCONTROL_CONTROLTYPE_DECIBELS = 805568512
const MIXERCONTROL_CONTROLTYPE_EQUALIZER = 1342373892
const MIXERCONTROL_CONTROLTYPE_FADER = 1342373888
const MIXERCONTROL_CONTROLTYPE_LOUDNESS = 536936452
const MIXERCONTROL_CONTROLTYPE_MICROTIME = 1610809344
const MIXERCONTROL_CONTROLTYPE_MILLITIME = 1627586560
const MIXERCONTROL_CONTROLTYPE_MIXER = 1895890945
const MIXERCONTROL_CONTROLTYPE_MONO = 536936451
const MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT = 1895890944
const MIXERCONTROL_CONTROLTYPE_MUTE = 536936450
const MIXERCONTROL_CONTROLTYPE_MUX = 1879113729
const MIXERCONTROL_CONTROLTYPE_ONOFF = 536936449
const MIXERCONTROL_CONTROLTYPE_PAN = 1073872897
const MIXERCONTROL_CONTROLTYPE_PEAKMETER = 268566529
const MIXERCONTROL_CONTROLTYPE_PERCENT = 805634048
const MIXERCONTROL_CONTROLTYPE_QSOUNDPAN = 1073872898
const MIXERCONTROL_CONTROLTYPE_SIGNED = 805437440
const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = 268566528
const MIXERCONTROL_CONTROLTYPE_SINGLESELECT = 1879113728
const MIXERCONTROL_CONTROLTYPE_SLIDER = 1073872896
const MIXERCONTROL_CONTROLTYPE_STEREOENH = 536936453
const MIXERCONTROL_CONTROLTYPE_TREBLE = 1342373891
const MIXERCONTROL_CONTROLTYPE_UNSIGNED = 805502976
const MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER = 268632064
const MIXERCONTROL_CONTROLTYPE_VOLUME = 1342373889
const MIXERCONTROL_CT_CLASS_CUSTOM = 0
const MIXERCONTROL_CT_CLASS_FADER = 1342177280
const MIXERCONTROL_CT_CLASS_LIST = 1879048192
const MIXERCONTROL_CT_CLASS_MASK = 4026531840
const MIXERCONTROL_CT_CLASS_METER = 268435456
const MIXERCONTROL_CT_CLASS_NUMBER = 805306368
const MIXERCONTROL_CT_CLASS_SLIDER = 1073741824
const MIXERCONTROL_CT_CLASS_SWITCH = 536870912
const MIXERCONTROL_CT_CLASS_TIME = 1610612736
const MIXERCONTROL_CT_SC_LIST_MULTIPLE = 16777216
const MIXERCONTROL_CT_SC_LIST_SINGLE = 0
const MIXERCONTROL_CT_SC_METER_POLLED = 0
const MIXERCONTROL_CT_SC_SWITCH_BOOLEAN = 0
const MIXERCONTROL_CT_SC_SWITCH_BUTTON = 16777216
const MIXERCONTROL_CT_SC_TIME_MICROSECS = 0
const MIXERCONTROL_CT_SC_TIME_MILLISECS = 16777216
const MIXERCONTROL_CT_SUBCLASS_MASK = 251658240
const MIXERCONTROL_CT_UNITS_BOOLEAN = 65536
const MIXERCONTROL_CT_UNITS_CUSTOM = 0
const MIXERCONTROL_CT_UNITS_DECIBELS = 262144
const MIXERCONTROL_CT_UNITS_MASK = 16711680
const MIXERCONTROL_CT_UNITS_PERCENT = 327680
const MIXERCONTROL_CT_UNITS_SIGNED = 131072
const MIXERCONTROL_CT_UNITS_UNSIGNED = 196608
const MIXERLINE_COMPONENTTYPE_DST_DIGITAL = 1
const MIXERLINE_COMPONENTTYPE_DST_FIRST = 0
const MIXERLINE_COMPONENTTYPE_DST_HEADPHONES = 5
const MIXERLINE_COMPONENTTYPE_DST_LAST = 8
const MIXERLINE_COMPONENTTYPE_DST_LINE = 2
const MIXERLINE_COMPONENTTYPE_DST_MONITOR = 3
const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = 4
const MIXERLINE_COMPONENTTYPE_DST_TELEPHONE = 6
const MIXERLINE_COMPONENTTYPE_DST_UNDEFINED = 0
const MIXERLINE_COMPONENTTYPE_DST_VOICEIN = 8
const MIXERLINE_COMPONENTTYPE_DST_WAVEIN = 7
const MIXERLINE_COMPONENTTYPE_SRC_ANALOG = 4106
const MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY = 4105
const MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = 4101
const MIXERLINE_COMPONENTTYPE_SRC_DIGITAL = 4097
const MIXERLINE_COMPONENTTYPE_SRC_FIRST = 4096
const MIXERLINE_COMPONENTTYPE_SRC_LAST = 4106
const MIXERLINE_COMPONENTTYPE_SRC_LINE = 4098
const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = 4099
const MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = 4103
const MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER = 4100
const MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = 4102
const MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED = 4096
const MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = 4104
const MIXERLINE_LINEF_ACTIVE = 1
const MIXERLINE_LINEF_DISCONNECTED = 32768
const MIXERLINE_LINEF_SOURCE = 2147483648
const MIXERLINE_TARGETTYPE_AUX = 5
const MIXERLINE_TARGETTYPE_MIDIIN = 4
const MIXERLINE_TARGETTYPE_MIDIOUT = 3
const MIXERLINE_TARGETTYPE_UNDEFINED = 0
const MIXERLINE_TARGETTYPE_WAVEIN = 2
const MIXERLINE_TARGETTYPE_WAVEOUT = 1
const MIXERR_BASE = 1024
const MIXERR_INVALCONTROL = 1025
const MIXERR_INVALLINE = 1024
const MIXERR_INVALVALUE = 1026
const MIXERR_LASTERROR = 1026
const MIXER_GETCONTROLDETAILSF_LISTTEXT = 1
const MIXER_GETCONTROLDETAILSF_QUERYMASK = 15
const MIXER_GETCONTROLDETAILSF_VALUE = 0
const MIXER_GETLINECONTROLSF_ALL = 0
const MIXER_GETLINECONTROLSF_ONEBYID = 1
const MIXER_GETLINECONTROLSF_ONEBYTYPE = 2
const MIXER_GETLINECONTROLSF_QUERYMASK = 15
const MIXER_GETLINEINFOF_COMPONENTTYPE = 3
const MIXER_GETLINEINFOF_DESTINATION = 0
const MIXER_GETLINEINFOF_LINEID = 2
const MIXER_GETLINEINFOF_QUERYMASK = 15
const MIXER_GETLINEINFOF_SOURCE = 1
const MIXER_GETLINEINFOF_TARGETTYPE = 4
const MIXER_LONG_NAME_CHARS = 64
const MIXER_OBJECTF_AUX = 1342177280
const MIXER_OBJECTF_HANDLE = 2147483648
const MIXER_OBJECTF_HMIDIIN = 3221225472
const MIXER_OBJECTF_HMIDIOUT = 2952790016
const MIXER_OBJECTF_HMIXER = 2147483648
const MIXER_OBJECTF_HWAVEIN = 2684354560
const MIXER_OBJECTF_HWAVEOUT = 2415919104
const MIXER_OBJECTF_MIDIIN = 1073741824
const MIXER_OBJECTF_MIDIOUT = 805306368
const MIXER_OBJECTF_MIXER = 0
const MIXER_OBJECTF_WAVEIN = 536870912
const MIXER_OBJECTF_WAVEOUT = 268435456
const MIXER_SETCONTROLDETAILSF_CUSTOM = 1
const MIXER_SETCONTROLDETAILSF_QUERYMASK = 15
const MIXER_SETCONTROLDETAILSF_VALUE = 0
const MIXER_SHORT_NAME_CHARS = 16
const MKF_AVAILABLE = 2
const MKF_CONFIRMHOTKEY = 8
const MKF_HOTKEYACTIVE = 4
const MKF_HOTKEYSOUND = 16
const MKF_INDICATOR = 32
const MKF_LEFTBUTTONDOWN = 16777216
const MKF_LEFTBUTTONSEL = 268435456
const MKF_MODIFIERS = 64
const MKF_MOUSEKEYSON = 1
const MKF_MOUSEMODE = 2147483648
const MKF_REPLACENUMBERS = 128
const MKF_RIGHTBUTTONDOWN = 33554432
const MKF_RIGHTBUTTONSEL = 536870912
const MKSYS_URLMONIKER = 6
const MK_ALT = 32
const MK_CONTROL = 8
const MK_E_FIRST = 2147746272
const MK_E_LAST = 2147746287
const MK_LBUTTON = 1
const MK_MBUTTON = 16
const MK_RBUTTON = 2
const MK_SHIFT = 4
const MK_S_FIRST = 262624
const MK_S_LAST = 262639
const MK_XBUTTON1 = 32
const MK_XBUTTON2 = 64
const MMIOERR_ACCESSDENIED = 268
const MMIOERR_BASE = 256
const MMIOERR_CANNOTCLOSE = 260
const MMIOERR_CANNOTEXPAND = 264
const MMIOERR_CANNOTOPEN = 259
const MMIOERR_CANNOTREAD = 261
const MMIOERR_CANNOTSEEK = 263
const MMIOERR_CANNOTWRITE = 262
const MMIOERR_CHUNKNOTFOUND = 265
const MMIOERR_FILENOTFOUND = 257
const MMIOERR_INVALIDFILE = 272
const MMIOERR_NETWORKERROR = 270
const MMIOERR_OUTOFMEMORY = 258
const MMIOERR_PATHNOTFOUND = 267
const MMIOERR_SHARINGVIOLATION = 269
const MMIOERR_TOOMANYOPENFILES = 271
const MMIOERR_UNBUFFERED = 266
const MMIOM_CLOSE = 4
const MMIOM_OPEN = 3
const MMIOM_READ = 0
const MMIOM_RENAME = 6
const MMIOM_SEEK = 2
const MMIOM_USER = 32768
const MMIOM_WRITE = 1
const MMIOM_WRITEFLUSH = 5
const MMIO_ALLOCBUF = 65536
const MMIO_COMPAT = 0
const MMIO_CREATE = 4096
const MMIO_CREATELIST = 64
const MMIO_CREATERIFF = 32
const MMIO_DEFAULTBUFFER = 8192
const MMIO_DELETE = 512
const MMIO_DENYNONE = 64
const MMIO_DENYREAD = 48
const MMIO_DENYWRITE = 32
const MMIO_DIRTY = 268435456
const MMIO_EMPTYBUF = 16
const MMIO_EXCLUSIVE = 16
const MMIO_EXIST = 16384
const MMIO_FHOPEN = 16
const MMIO_FINDCHUNK = 16
const MMIO_FINDLIST = 64
const MMIO_FINDPROC = 262144
const MMIO_FINDRIFF = 32
const MMIO_GETTEMP = 131072
const MMIO_GLOBALPROC = 268435456
const MMIO_INSTALLPROC = 65536
const MMIO_PARSE = 256
const MMIO_READ = 0
const MMIO_READWRITE = 2
const MMIO_REMOVEPROC = 131072
const MMIO_RWMODE = 3
const MMIO_SHAREMODE = 112
const MMIO_TOUPPER = 16
const MMIO_UNICODEPROC = 16777216
const MMIO_WRITE = 1
const MMSYSERR_ALLOCATED = 4
const MMSYSERR_BADDB = 14
const MMSYSERR_BADDEVICEID = 2
const MMSYSERR_BADERRNUM = 9
const MMSYSERR_BASE = 0
const MMSYSERR_DELETEERROR = 18
const MMSYSERR_ERROR = 1
const MMSYSERR_HANDLEBUSY = 12
const MMSYSERR_INVALFLAG = 10
const MMSYSERR_INVALHANDLE = 5
const MMSYSERR_INVALIDALIAS = 13
const MMSYSERR_INVALPARAM = 11
const MMSYSERR_KEYNOTFOUND = 15
const MMSYSERR_LASTERROR = 21
const MMSYSERR_MOREDATA = 21
const MMSYSERR_NODRIVER = 6
const MMSYSERR_NODRIVERCB = 20
const MMSYSERR_NOERROR = 0
const MMSYSERR_NOMEM = 7
const MMSYSERR_NOTENABLED = 3
const MMSYSERR_NOTSUPPORTED = 8
const MMSYSERR_READERROR = 16
const MMSYSERR_VALNOTFOUND = 19
const MMSYSERR_WRITEERROR = 17
const MM_ANISOTROPIC = 8
const MM_DRVM_CLOSE = 977
const MM_DRVM_DATA = 978
const MM_DRVM_ERROR = 979
const MM_DRVM_OPEN = 976
const MM_HIENGLISH = 5
const MM_HIMETRIC = 3
const MM_ISOTROPIC = 7
const MM_JOY1BUTTONDOWN = 949
const MM_JOY1BUTTONUP = 951
const MM_JOY1MOVE = 928
const MM_JOY1ZMOVE = 930
const MM_JOY2BUTTONDOWN = 950
const MM_JOY2BUTTONUP = 952
const MM_JOY2MOVE = 929
const MM_JOY2ZMOVE = 931
const MM_LOENGLISH = 4
const MM_LOMETRIC = 2
const MM_MAX = 8
const MM_MAX_AXES_NAMELEN = 16
const MM_MAX_FIXEDSCALE = 6
const MM_MAX_NUMAXES = 16
const MM_MCINOTIFY = 953
const MM_MCISIGNAL = 971
const MM_MIM_CLOSE = 962
const MM_MIM_DATA = 963
const MM_MIM_ERROR = 965
const MM_MIM_LONGDATA = 964
const MM_MIM_LONGERROR = 966
const MM_MIM_MOREDATA = 972
const MM_MIM_OPEN = 961
const MM_MIN = 1
const MM_MIXM_CONTROL_CHANGE = 977
const MM_MIXM_LINE_CHANGE = 976
const MM_MOM_CLOSE = 968
const MM_MOM_DONE = 969
const MM_MOM_OPEN = 967
const MM_MOM_POSITIONCB = 970
const MM_STREAM_CLOSE = 981
const MM_STREAM_DONE = 982
const MM_STREAM_ERROR = 983
const MM_STREAM_OPEN = 980
const MM_TEXT = 1
const MM_TWIPS = 6
const MM_WIM_CLOSE = 959
const MM_WIM_DATA = 960
const MM_WIM_OPEN = 958
const MM_WOM_CLOSE = 956
const MM_WOM_DONE = 957
const MM_WOM_OPEN = 955
const MNC_CLOSE = 1
const MNC_EXECUTE = 2
const MNC_IGNORE = 0
const MNC_SELECT = 3
const MND_CONTINUE = 0
const MND_ENDMENU = 1
const MNGOF_BOTTOMGAP = 2
const MNGOF_TOPGAP = 1
const MNGO_NOERROR = 1
const MNGO_NOINTERFACE = 0
const MNS_AUTODISMISS = 268435456
const MNS_CHECKORBMP = 67108864
const MNS_DRAGDROP = 536870912
const MNS_MODELESS = 1073741824
const MNS_NOCHECK = 2147483648
const MNS_NOTIFYBYPOS = 134217728
const MN_GETHMENU = 481
const MOD_ALT = 1
const MOD_CONTROL = 2
const MOD_FMSYNTH = 4
const MOD_IGNORE_ALL_MODIFIER = 1024
const MOD_LEFT = 32768
const MOD_MAPPER = 5
const MOD_MIDIPORT = 1
const MOD_NOREPEAT = 16384
const MOD_ON_KEYUP = 2048
const MOD_RIGHT = 16384
const MOD_SHIFT = 4
const MOD_SQSYNTH = 3
const MOD_SWSYNTH = 7
const MOD_SYNTH = 2
const MOD_WAVETABLE = 6
const MOD_WIN = 8
const MOM_CLOSE = 968
const MOM_DONE = 969
const MOM_OPEN = 967
const MOM_POSITIONCB = 970
const MONITORINFOF_PRIMARY = 1
const MONITOR_DEFAULTTONEAREST = 2
const MONITOR_DEFAULTTONULL = 0
const MONITOR_DEFAULTTOPRIMARY = 1
const MONO_FONT = 8
const MOUSEEVENTF_ABSOLUTE = 32768
const MOUSEEVENTF_HWHEEL = 4096
const MOUSEEVENTF_LEFTDOWN = 2
const MOUSEEVENTF_LEFTUP = 4
const MOUSEEVENTF_MIDDLEDOWN = 32
const MOUSEEVENTF_MIDDLEUP = 64
const MOUSEEVENTF_MOVE = 1
const MOUSEEVENTF_MOVE_NOCOALESCE = 8192
const MOUSEEVENTF_RIGHTDOWN = 8
const MOUSEEVENTF_RIGHTUP = 16
const MOUSEEVENTF_VIRTUALDESK = 16384
const MOUSEEVENTF_WHEEL = 2048
const MOUSEEVENTF_XDOWN = 128
const MOUSEEVENTF_XUP = 256
const MOUSETRAILS = 39
const MOUSEWHEEL_ROUTING_FOCUS = 0
const MOUSEWHEEL_ROUTING_HYBRID = 1
const MOUSEWHEEL_ROUTING_MOUSE_POS = 2
const MOUSE_ATTRIBUTES_CHANGED = 4
const MOUSE_EVENT = 2
const MOUSE_HWHEELED = 8
const MOUSE_MOVED = 1
const MOUSE_MOVE_ABSOLUTE = 1
const MOUSE_MOVE_NOCOALESCE = 8
const MOUSE_MOVE_RELATIVE = 0
const MOUSE_VIRTUAL_DESKTOP = 2
const MOUSE_WHEELED = 4
const MOVEFILE_COPY_ALLOWED = 2
const MOVEFILE_CREATE_HARDLINK = 16
const MOVEFILE_DELAY_UNTIL_REBOOT = 4
const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32
const MOVEFILE_REPLACE_EXISTING = 1
const MOVEFILE_WRITE_THROUGH = 8
const MSGFLTINFO_ALLOWED_HIGHER = 3
const MSGFLTINFO_ALREADYALLOWED_FORWND = 1
const MSGFLTINFO_ALREADYDISALLOWED_FORWND = 2
const MSGFLTINFO_NONE = 0
const MSGFLT_ADD = 1
const MSGFLT_ALLOW = 1
const MSGFLT_DISALLOW = 2
const MSGFLT_REMOVE = 2
const MSGFLT_RESET = 0
const MSGF_DDEMGR = 32769
const MSGF_DIALOGBOX = 0
const MSGF_MAX = 8
const MSGF_MENU = 2
const MSGF_MESSAGEBOX = 1
const MSGF_NEXTWINDOW = 6
const MSGF_SCROLLBAR = 5
const MSGF_USER = 4096
const MSG_DONTROUTE = 4
const MSG_MAXIOVLEN = 16
const MSG_OOB = 1
const MSG_PARTIAL = 32768
const MSG_PEEK = 2
const MSVC_VERSION = 0
const MS_DEF_DH_SCHANNEL_PROV_A = "Microsoft DH SChannel Cryptographic Provider"
const MS_DEF_DH_SCHANNEL_PROV_W = "Microsoft DH SChannel Cryptographic Provider"
const MS_DEF_DSS_DH_PROV_A = "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
const MS_DEF_DSS_DH_PROV_W = "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
const MS_DEF_DSS_PROV_A = "Microsoft Base DSS Cryptographic Provider"
const MS_DEF_DSS_PROV_W = "Microsoft Base DSS Cryptographic Provider"
const MS_DEF_PROV_A = "Microsoft Base Cryptographic Provider v1.0"
const MS_DEF_PROV_W = "Microsoft Base Cryptographic Provider v1.0"
const MS_DEF_RSA_SCHANNEL_PROV_A = "Microsoft RSA SChannel Cryptographic Provider"
const MS_DEF_RSA_SCHANNEL_PROV_W = "Microsoft RSA SChannel Cryptographic Provider"
const MS_DEF_RSA_SIG_PROV_A = "Microsoft RSA Signature Cryptographic Provider"
const MS_DEF_RSA_SIG_PROV_W = "Microsoft RSA Signature Cryptographic Provider"
const MS_ENHANCED_PROV_A = "Microsoft Enhanced Cryptographic Provider v1.0"
const MS_ENHANCED_PROV_W = "Microsoft Enhanced Cryptographic Provider v1.0"
const MS_ENH_DSS_DH_PROV_A = "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
const MS_ENH_DSS_DH_PROV_W = "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
const MS_ENH_RSA_AES_PROV_A = "Microsoft Enhanced RSA and AES Cryptographic Provider"
const MS_ENH_RSA_AES_PROV_W = "Microsoft Enhanced RSA and AES Cryptographic Provider"
const MS_ENH_RSA_AES_PROV_XP_A = "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
const MS_ENH_RSA_AES_PROV_XP_W = "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
const MS_KEY_STORAGE_PROVIDER = "Microsoft Software Key Storage Provider"
const MS_NBF = "MNBF"
const MS_PLATFORM_CRYPTO_PROVIDER = "Microsoft Platform Crypto Provider"
const MS_PLATFORM_KEY_STORAGE_PROVIDER = "Microsoft Platform Crypto Provider"
const MS_PPM_SOFTWARE_ALL = 1
const MS_PRIMITIVE_PROVIDER = "Microsoft Primitive Provider"
const MS_SCARD_PROV_A = "Microsoft Base Smart Card Crypto Provider"
const MS_SCARD_PROV_W = "Microsoft Base Smart Card Crypto Provider"
const MS_SMART_CARD_KEY_STORAGE_PROVIDER = "Microsoft Smart Card Key Storage Provider"
const MS_STRONG_PROV_A = "Microsoft Strong Cryptographic Provider"
const MS_STRONG_PROV_W = "Microsoft Strong Cryptographic Provider"
const MUI_CALLBACK_ALL_FLAGS = 0
const MUI_COMPLEX_SCRIPT_FILTER = 512
const MUI_CONSOLE_FILTER = 256
const MUI_FILEINFO_VERSION = 1
const MUI_FILETYPE_LANGUAGE_NEUTRAL_MAIN = 2
const MUI_FILETYPE_LANGUAGE_NEUTRAL_MUI = 4
const MUI_FILETYPE_NOT_LANGUAGE_NEUTRAL = 1
const MUI_FORMAT_INF_COMPAT = 2
const MUI_FORMAT_REG_COMPAT = 1
const MUI_FULL_LANGUAGE = 1
const MUI_IMMUTABLE_LOOKUP = 16
const MUI_LANGUAGE_ID = 4
const MUI_LANGUAGE_INSTALLED = 32
const MUI_LANGUAGE_LICENSED = 64
const MUI_LANGUAGE_NAME = 8
const MUI_LANG_NEUTRAL_PE_FILE = 256
const MUI_LIP_LANGUAGE = 4
const MUI_MACHINE_LANGUAGE_SETTINGS = 1024
const MUI_MERGE_SYSTEM_FALLBACK = 16
const MUI_MERGE_USER_FALLBACK = 32
const MUI_NON_LANG_NEUTRAL_FILE = 512
const MUI_PARTIAL_LANGUAGE = 2
const MUI_QUERY_CHECKSUM = 2
const MUI_QUERY_LANGUAGE_NAME = 4
const MUI_QUERY_RESOURCE_TYPES = 8
const MUI_QUERY_TYPE = 1
const MUI_RESET_FILTERS = 1
const MUI_SKIP_STRING_CACHE = 8
const MUI_THREAD_LANGUAGES = 64
const MUI_UI_FALLBACK = 48
const MUI_USER_PREFERRED_UI_LANGUAGES = 16
const MUI_USE_INSTALLED_LANGUAGES = 32
const MUI_USE_SEARCH_ALL_LANGUAGES = 64
const MUI_VERIFY_FILE_EXISTS = 4
const MULTIFILEOPENORD = 1537
const MUTANT_ALL_ACCESS = 2031617
const MUTANT_QUERY_STATE = 1
const MUTEX_ALL_ACCESS = 2031617
const MUTEX_MODIFY_STATE = 1
const MUTZ_ACCEPT_WILDCARD_SCHEME = 128
const MUTZ_DONT_UNESCAPE = 2048
const MUTZ_DONT_USE_CACHE = 4096
const MUTZ_ENFORCERESTRICTED = 256
const MUTZ_FORCE_INTRANET_FLAGS = 8192
const MUTZ_IGNORE_ZONE_MAPPINGS = 16384
const MUTZ_ISFILE = 2
const MUTZ_NOSAVEDFILECHECK = 1
const MUTZ_REQUIRESAVEDFILECHECK = 1024
const MUTZ_RESERVED = 512
const MWMO_ALERTABLE = 2
const MWMO_INPUTAVAILABLE = 4
const MWMO_WAITALL = 1
const MWT_IDENTITY = 1
const MWT_LEFTMULTIPLY = 2
const MWT_MAX = 3
const MWT_MIN = 1
const MWT_RIGHTMULTIPLY = 3
const MX_CLOSE_ATTEMPT = 3
const M_1_PI = 0
const M_2_PI = 0
const M_2_SQRTPI = 0
const M_E = 0
const M_LN10 = 0
const M_LN2 = 0
const M_LOG10E = 0
const M_LOG2E = 0
const M_PI = 3.141592653589793
const M_PI_2 = 0
const M_PI_4 = 0
const M_SQRT1_2 = 0
const M_SQRT2 = 0
const MapVirtualKey = 0
const MapVirtualKeyEx = 0
const MaxNumberOfEEInfoParams = 4
const MediumChangerClassGuid = 0
const MessageBox = 0
const MessageBoxEx = 0
const MessageBoxIndirect = 0
const ModifyMenu = 0
const MoveFile = 0
const MoveFileEx = 0
const MoveFileTransacted = 0
const MoveFileWithProgress = 0
const MoveMemory = 0
const MultinetGetConnectionPerformance = 0
const NAME_FLAGS_MASK = 135
const NAN = 0
const NB = 3
const NCBACTION = 119
const NCBADDGRNAME = 54
const NCBADDNAME = 48
const NCBASTAT = 51
const NCBCALL = 16
const NCBCANCEL = 53
const NCBCHAINSEND = 23
const NCBCHAINSENDNA = 114
const NCBDELNAME = 49
const NCBDGRECV = 33
const NCBDGRECVBC = 35
const NCBDGSEND = 32
const NCBDGSENDBC = 34
const NCBENUM = 55
const NCBFINDNAME = 120
const NCBHANGUP = 18
const NCBLANSTALERT = 115
const NCBLISTEN = 17
const NCBNAMSZ = 16
const NCBRECV = 21
const NCBRECVANY = 22
const NCBRESET = 50
const NCBSEND = 20
const NCBSENDNA = 113
const NCBSSTAT = 52
const NCBTRACE = 121
const NCBUNLINK = 112
const NCM_DISPLAYERRORTIP = 1028
const NCM_GETADDRESS = 1025
const NCM_GETALLOWTYPE = 1027
const NCM_SETALLOWTYPE = 1026
const NCRYPTBUFFER_CERT_BLOB = 47
const NCRYPTBUFFER_DATA = 1
const NCRYPTBUFFER_EMPTY = 0
const NCRYPTBUFFER_PKCS_ALG_ID = 43
const NCRYPTBUFFER_PKCS_ALG_OID = 41
const NCRYPTBUFFER_PKCS_ALG_PARAM = 42
const NCRYPTBUFFER_PKCS_ATTRS = 44
const NCRYPTBUFFER_PKCS_KEY_NAME = 45
const NCRYPTBUFFER_PKCS_OID = 40
const NCRYPTBUFFER_PKCS_SECRET = 46
const NCRYPTBUFFER_PROTECTION_DESCRIPTOR_STRING = 3
const NCRYPTBUFFER_PROTECTION_FLAGS = 4
const NCRYPTBUFFER_SSL_CLEAR_KEY = 23
const NCRYPTBUFFER_SSL_CLIENT_RANDOM = 20
const NCRYPTBUFFER_SSL_HIGHEST_VERSION = 22
const NCRYPTBUFFER_SSL_KEY_ARG_DATA = 24
const NCRYPTBUFFER_SSL_SERVER_RANDOM = 21
const NCRYPTBUFFER_VERSION = 0
const NCRYPT_3DES_112_ALGORITHM = "BCRYPT_3DES_112_ALGORITHM"
const NCRYPT_3DES_ALGORITHM = "BCRYPT_3DES_ALGORITHM"
const NCRYPT_AES_ALGORITHM = "BCRYPT_AES_ALGORITHM"
const NCRYPT_AES_ALGORITHM_GROUP = "NCRYPT_AES_ALGORITHM"
const NCRYPT_ALGORITHM_GROUP_PROPERTY = "Algorithm Group"
const NCRYPT_ALGORITHM_PROPERTY = "Algorithm Name"
const NCRYPT_ALLOW_ALL_USAGES = 16777215
const NCRYPT_ALLOW_ARCHIVING_FLAG = 4
const NCRYPT_ALLOW_DECRYPT_FLAG = 1
const NCRYPT_ALLOW_EXPORT_FLAG = 1
const NCRYPT_ALLOW_KEY_AGREEMENT_FLAG = 4
const NCRYPT_ALLOW_PLAINTEXT_ARCHIVING_FLAG = 8
const NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG = 2
const NCRYPT_ALLOW_SIGNING_FLAG = 2
const NCRYPT_ASSOCIATED_ECDH_KEY = "SmartCardAssociatedECDHKey"
const NCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE = 3
const NCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION = 4
const NCRYPT_AUTH_TAG_LENGTH = "AuthTagLength"
const NCRYPT_BLOCK_LENGTH_PROPERTY = "Block Length"
const NCRYPT_CAPI_KDF_ALGORITHM = "BCRYPT_CAPI_KDF_ALGORITHM"
const NCRYPT_CERTIFICATE_PROPERTY = "SmartCardKeyCertificate"
const NCRYPT_CHAINING_MODE_PROPERTY = "Chaining Mode"
const NCRYPT_CIPHER_BLOCK_PADDING_FLAG = 1
const NCRYPT_CIPHER_INTERFACE = 1
const NCRYPT_CIPHER_KEY_BLOB = "CipherKeyBlob"
const NCRYPT_CIPHER_KEY_BLOB_MAGIC = 1380470851
const NCRYPT_CIPHER_NO_PADDING_FLAG = 0
const NCRYPT_CIPHER_OPERATION = 1
const NCRYPT_CIPHER_OTHER_PADDING_FLAG = 2
const NCRYPT_DESX_ALGORITHM = "BCRYPT_DESX_ALGORITHM"
const NCRYPT_DES_ALGORITHM = "BCRYPT_DES_ALGORITHM"
const NCRYPT_DES_ALGORITHM_GROUP = "DES"
const NCRYPT_DH_ALGORITHM = "BCRYPT_DH_ALGORITHM"
const NCRYPT_DH_ALGORITHM_GROUP = "NCRYPT_DH_ALGORITHM"
const NCRYPT_DH_PARAMETERS_PROPERTY = "BCRYPT_DH_PARAMETERS"
const NCRYPT_DO_NOT_FINALIZE_FLAG = 1024
const NCRYPT_DSA_ALGORITHM = "BCRYPT_DSA_ALGORITHM"
const NCRYPT_DSA_ALGORITHM_GROUP = "NCRYPT_DSA_ALGORITHM"
const NCRYPT_ECDH_ALGORITHM_GROUP = "ECDH"
const NCRYPT_ECDH_P256_ALGORITHM = "BCRYPT_ECDH_P256_ALGORITHM"
const NCRYPT_ECDH_P384_ALGORITHM = "BCRYPT_ECDH_P384_ALGORITHM"
const NCRYPT_ECDH_P521_ALGORITHM = "BCRYPT_ECDH_P521_ALGORITHM"
const NCRYPT_ECDSA_ALGORITHM_GROUP = "ECDSA"
const NCRYPT_ECDSA_P256_ALGORITHM = "BCRYPT_ECDSA_P256_ALGORITHM"
const NCRYPT_ECDSA_P384_ALGORITHM = "BCRYPT_ECDSA_P384_ALGORITHM"
const NCRYPT_ECDSA_P521_ALGORITHM = "BCRYPT_ECDSA_P521_ALGORITHM"
const NCRYPT_EXPORT_LEGACY_FLAG = 2048
const NCRYPT_EXPORT_POLICY_PROPERTY = "Export Policy"
const NCRYPT_HASH_INTERFACE = 2
const NCRYPT_HASH_OPERATION = 2
const NCRYPT_IMPL_HARDWARE_FLAG = 1
const NCRYPT_IMPL_HARDWARE_RNG_FLAG = 16
const NCRYPT_IMPL_REMOVABLE_FLAG = 8
const NCRYPT_IMPL_SOFTWARE_FLAG = 2
const NCRYPT_IMPL_TYPE_PROPERTY = "Impl Type"
const NCRYPT_INITIALIZATION_VECTOR = "BCRYPT_INITIALIZATION_VECTOR"
const NCRYPT_KDF_SECRET_VALUE = "KDFKeySecret"
const NCRYPT_KEY_DERIVATION_GROUP = "KEY_DERIVATION"
const NCRYPT_KEY_DERIVATION_INTERFACE = 7
const NCRYPT_KEY_DERIVATION_OPERATION = 64
const NCRYPT_KEY_PROTECTION_INTERFACE = 65540
const NCRYPT_KEY_STORAGE_ALGORITHM = "KEY_STORAGE"
const NCRYPT_KEY_STORAGE_INTERFACE = 65537
const NCRYPT_KEY_TYPE_PROPERTY = "Key Type"
const NCRYPT_KEY_USAGE_PROPERTY = "Key Usage"
const NCRYPT_LAST_MODIFIED_PROPERTY = "Modified"
const NCRYPT_LENGTHS_PROPERTY = "Lengths"
const NCRYPT_LENGTH_PROPERTY = "Length"
const NCRYPT_MACHINE_KEY_FLAG = 32
const NCRYPT_MAX_ALG_ID_LENGTH = 512
const NCRYPT_MAX_KEY_NAME_LENGTH = 512
const NCRYPT_MAX_NAME_LENGTH_PROPERTY = "Max Name Length"
const NCRYPT_MAX_PROPERTY_DATA = 1048576
const NCRYPT_MAX_PROPERTY_NAME = 64
const NCRYPT_MD2_ALGORITHM = "BCRYPT_MD2_ALGORITHM"
const NCRYPT_MD4_ALGORITHM = "BCRYPT_MD4_ALGORITHM"
const NCRYPT_MD5_ALGORITHM = "BCRYPT_MD5_ALGORITHM"
const NCRYPT_NAME_PROPERTY = "Name"
const NCRYPT_NO_KEY_VALIDATION = 8
const NCRYPT_NO_PADDING_FLAG = 1
const NCRYPT_OPAQUETRANSPORT_BLOB = "OpaqueTransport"
const NCRYPT_OVERWRITE_KEY_FLAG = 128
const NCRYPT_PAD_CIPHER_FLAG = 16
const NCRYPT_PAD_OAEP_FLAG = 4
const NCRYPT_PAD_PKCS1_FLAG = 2
const NCRYPT_PAD_PSS_FLAG = 8
const NCRYPT_PBKDF2_ALGORITHM = "BCRYPT_PBKDF2_ALGORITHM"
const NCRYPT_PCP_ALTERNATE_KEY_STORAGE_LOCATION_PROPERTY = "PCP_ALTERNATE_KEY_STORAGE_LOCATION"
const NCRYPT_PCP_CHANGEPASSWORD_PROPERTY = "PCP_CHANGEPASSWORD"
const NCRYPT_PCP_EKCERT_PROPERTY = "PCP_EKCERT"
const NCRYPT_PCP_EKNVCERT_PROPERTY = "PCP_EKNVCERT"
const NCRYPT_PCP_EKPUB_PROPERTY = "PCP_EKPUB"
const NCRYPT_PCP_ENCRYPTION_KEY = 2
const NCRYPT_PCP_EXPORT_ALLOWED_PROPERTY = "PCP_EXPORT_ALLOWED"
const NCRYPT_PCP_GENERIC_KEY = 3
const NCRYPT_PCP_IDENTITY_KEY = 8
const NCRYPT_PCP_KEYATTESTATION_PROPERTY = "PCP_TPM12_KEYATTESTATION"
const NCRYPT_PCP_KEY_USAGE_POLICY_PROPERTY = "PCP_KEY_USAGE_POLICY"
const NCRYPT_PCP_MIGRATIONPASSWORD_PROPERTY = "PCP_MIGRATIONPASSWORD"
const NCRYPT_PCP_PASSWORD_REQUIRED_PROPERTY = "PCP_PASSWORD_REQUIRED"
const NCRYPT_PCP_PCRTABLE_PROPERTY = "PCP_PCRTABLE"
const NCRYPT_PCP_PLATFORMHANDLE_PROPERTY = "PCP_PLATFORMHANDLE"
const NCRYPT_PCP_PLATFORM_BINDING_PCRDIGESTLIST_PROPERTY = "PCP_PLATFORM_BINDING_PCRDIGESTLIST"
const NCRYPT_PCP_PLATFORM_BINDING_PCRDIGEST_PROPERTY = "PCP_PLATFORM_BINDING_PCRDIGEST"
const NCRYPT_PCP_PLATFORM_BINDING_PCRMASK_PROPERTY = "PCP_PLATFORM_BINDING_PCRMASK"
const NCRYPT_PCP_PLATFORM_TYPE_PROPERTY = "PCP_PLATFORM_TYPE"
const NCRYPT_PCP_PROVIDERHANDLE_PROPERTY = "PCP_PROVIDERMHANDLE"
const NCRYPT_PCP_PROVIDER_VERSION_PROPERTY = "PCP_PROVIDER_VERSION"
const NCRYPT_PCP_SIGNATURE_KEY = 1
const NCRYPT_PCP_SRKPUB_PROPERTY = "PCP_SRKPUB"
const NCRYPT_PCP_STORAGEPARENT_PROPERTY = "PCP_STORAGEPARENT"
const NCRYPT_PCP_STORAGE_KEY = 4
const NCRYPT_PCP_TPM12_IDACTIVATION_PROPERTY = "PCP_TPM12_IDACTIVATION"
const NCRYPT_PCP_TPM12_IDBINDING_PROPERTY = "PCP_TPM12_IDBINDING"
const NCRYPT_PCP_USAGEAUTH_PROPERTY = "PCP_USAGEAUTH"
const NCRYPT_PERSIST_FLAG = 2147483648
const NCRYPT_PERSIST_ONLY_FLAG = 1073741824
const NCRYPT_PIN_PROMPT_PROPERTY = "SmartCardPinPrompt"
const NCRYPT_PIN_PROPERTY = "SmartCardPin"
const NCRYPT_PKCS7_ENVELOPE_BLOB = "PKCS7_ENVELOPE"
const NCRYPT_PKCS8_PRIVATE_KEY_BLOB = "PKCS8_PRIVATEKEY"
const NCRYPT_PROTECTED_KEY_BLOB = "ProtectedKeyBlob"
const NCRYPT_PROTECTED_KEY_BLOB_MAGIC = 1263817296
const NCRYPT_PROVIDER_HANDLE_PROPERTY = "Provider Handle"
const NCRYPT_RC2_ALGORITHM = "BCRYPT_RC2_ALGORITHM"
const NCRYPT_RC2_ALGORITHM_GROUP = "NCRYPT_RC2_ALGORITHM"
const NCRYPT_READER_ICON_PROPERTY = "SmartCardReaderIcon"
const NCRYPT_READER_PROPERTY = "SmartCardReader"
const NCRYPT_REGISTER_NOTIFY_FLAG = 1
const NCRYPT_RNG_OPERATION = 32
const NCRYPT_ROOT_CERTSTORE_PROPERTY = "SmartcardRootCertStore"
const NCRYPT_RSA_ALGORITHM = "BCRYPT_RSA_ALGORITHM"
const NCRYPT_RSA_ALGORITHM_GROUP = "NCRYPT_RSA_ALGORITHM"
const NCRYPT_RSA_SIGN_ALGORITHM = "BCRYPT_RSA_SIGN_ALGORITHM"
const NCRYPT_SCARD_PIN_ID = "SmartCardPinId"
const NCRYPT_SCARD_PIN_INFO = "SmartCardPinInfo"
const NCRYPT_SCHANNEL_INTERFACE = 65538
const NCRYPT_SCHANNEL_SIGNATURE_INTERFACE = 65539
const NCRYPT_SECRET_AGREEMENT_INTERFACE = 4
const NCRYPT_SECRET_AGREEMENT_OPERATION = 8
const NCRYPT_SECURE_PIN_PROPERTY = "SmartCardSecurePin"
const NCRYPT_SECURITY_DESCR_PROPERTY = "Security Descr"
const NCRYPT_SECURITY_DESCR_SUPPORT_PROPERTY = "Security Descr Support"
const NCRYPT_SHA1_ALGORITHM = "BCRYPT_SHA1_ALGORITHM"
const NCRYPT_SHA256_ALGORITHM = "BCRYPT_SHA256_ALGORITHM"
const NCRYPT_SHA384_ALGORITHM = "BCRYPT_SHA384_ALGORITHM"
const NCRYPT_SHA512_ALGORITHM = "BCRYPT_SHA512_ALGORITHM"
const NCRYPT_SIGNATURE_INTERFACE = 5
const NCRYPT_SIGNATURE_OPERATION = 16
const NCRYPT_SILENT_FLAG = 64
const NCRYPT_SMARTCARD_GUID_PROPERTY = "SmartCardGuid"
const NCRYPT_SP800108_CTR_HMAC_ALGORITHM = "BCRYPT_SP800108_CTR_HMAC_ALGORITHM"
const NCRYPT_SP80056A_CONCAT_ALGORITHM = "BCRYPT_SP80056A_CONCAT_ALGORITHM"
const NCRYPT_TPM12_PROVIDER = 65536
const NCRYPT_UI_FORCE_HIGH_PROTECTION_FLAG = 2
const NCRYPT_UI_POLICY_PROPERTY = "UI Policy"
const NCRYPT_UI_PROTECT_KEY_FLAG = 1
const NCRYPT_UNIQUE_NAME_PROPERTY = "Unique Name"
const NCRYPT_UNREGISTER_NOTIFY_FLAG = 2
const NCRYPT_USER_CERTSTORE_PROPERTY = "SmartCardUserCertStore"
const NCRYPT_USE_CONTEXT_PROPERTY = "Use Context"
const NCRYPT_USE_COUNT_ENABLED_PROPERTY = "Enabled Use Count"
const NCRYPT_USE_COUNT_PROPERTY = "Use Count"
const NCRYPT_VERSION_PROPERTY = "Version"
const NCRYPT_WINDOW_HANDLE_PROPERTY = "HWND Handle"
const NCRYPT_WRITE_KEY_TO_LEGACY_STORE_FLAG = 512
const NC_AllowAgg = 1
const NC_AllowWin = 16384
const NC_Complex = 8192
const NC_FromDDL = 262144
const NC_GenCol = 8
const NC_HasAgg = 16
const NC_HasWin = 32768
const NC_IdxExpr = 32
const NC_InAggFunc = 131072
const NC_IsCheck = 4
const NC_IsDDL = 65536
const NC_MinMaxAgg = 4096
const NC_NoSelect = 524288
const NC_OrderAgg = 134217728
const NC_PartIdx = 2
const NC_SelfRef = 46
const NC_Subquery = 64
const NC_UAggInfo = 256
const NC_UBaseReg = 1024
const NC_UEList = 128
const NC_UUpsert = 512
const NC_Where = 1048576
const NDEBUG = 1
const NDR_ASCII_CHAR = 0
const NDR_BIG_ENDIAN = 0
const NDR_CHAR_REP_MASK = 15
const NDR_EBCDIC_CHAR = 1
const NDR_FLOAT_REP_MASK = 65280
const NDR_IBM_FLOAT = 768
const NDR_IEEE_FLOAT = 0
const NDR_INT_REP_MASK = 240
const NDR_LITTLE_ENDIAN = 16
const NDR_LOCAL_DATA_REPRESENTATION = 16
const NDR_LOCAL_ENDIAN = 16
const NDR_SHAREABLE = 0
const NDR_VAX_FLOAT = 256
const NETINFO_DISKRED = 4
const NETINFO_DLL16 = 1
const NETINFO_PRINTERRED = 8
const NETPROPERTY_PERSISTENT = 1
const NETSCAPE_SIGN_CA_CERT_TYPE = 1
const NETSCAPE_SIGN_CERT_TYPE = 16
const NETSCAPE_SMIME_CA_CERT_TYPE = 2
const NETSCAPE_SMIME_CERT_TYPE = 32
const NETSCAPE_SSL_CA_CERT_TYPE = 4
const NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE = 128
const NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE = 64
const NEWFILEOPENORD = 1547
const NEWFILEOPENV2ORD = 1552
const NEWFRAME = 1
const NEWTRANSPARENT = 3
const NEXTBAND = 3
const NFR_ANSI = 1
const NFR_UNICODE = 2
const NF_QUERY = 3
const NF_REQUERY = 4
const NID_EXTERNAL_PEN = 8
const NID_EXTERNAL_TOUCH = 2
const NID_INTEGRATED_PEN = 4
const NID_INTEGRATED_TOUCH = 1
const NID_MULTI_INPUT = 64
const NID_READY = 128
const NIF_GUID = 32
const NIF_ICON = 2
const NIF_INFO = 16
const NIF_MESSAGE = 1
const NIF_REALTIME = 64
const NIF_SHOWTIP = 128
const NIF_STATE = 8
const NIF_TIP = 4
const NIIF_ERROR = 3
const NIIF_ICON_MASK = 15
const NIIF_INFO = 1
const NIIF_LARGE_ICON = 32
const NIIF_NONE = 0
const NIIF_NOSOUND = 16
const NIIF_RESPECT_QUIET_TIME = 128
const NIIF_USER = 4
const NIIF_WARNING = 2
const NIM_ADD = 0
const NIM_DELETE = 2
const NIM_MODIFY = 1
const NIM_SETFOCUS = 3
const NIM_SETVERSION = 4
const NINF_KEY = 1
const NIN_BALLOONHIDE = 1027
const NIN_BALLOONSHOW = 1026
const NIN_BALLOONTIMEOUT = 1028
const NIN_BALLOONUSERCLICK = 1029
const NIN_KEYSELECT = 1025
const NIN_POPUPCLOSE = 1031
const NIN_POPUPOPEN = 1030
const NIN_SELECT = 1024
const NIS_HIDDEN = 1
const NIS_SHAREDICON = 2
const NI_CHANGECANDIDATELIST = 19
const NI_CLOSECANDIDATE = 17
const NI_COMPOSITIONSTR = 21
const NI_FINALIZECONVERSIONRESULT = 20
const NI_IMEMENUSELECTED = 24
const NI_OPENCANDIDATE = 16
const NI_SELECTCANDIDATESTR = 18
const NI_SETCANDIDATE_PAGESIZE = 23
const NI_SETCANDIDATE_PAGESTART = 22
const NLS_ALPHANUMERIC = 0
const NLS_DBCSCHAR = 65536
const NLS_HIRAGANA = 262144
const NLS_IME_CONVERSION = 8388608
const NLS_IME_DISABLE = 536870912
const NLS_KATAKANA = 131072
const NLS_ROMAN = 4194304
const NLS_VALID_LOCALE_MASK = 1048575
const NMPWAIT_NOWAIT = 1
const NMPWAIT_USE_DEFAULT_WAIT = 0
const NMPWAIT_WAIT_FOREVER = 4294967295
const NN = 1
const NOERROR = 0
const NONANTIALIASED_QUALITY = 3
const NONZEROLHND = 2
const NONZEROLPTR = 0
const NON_PAGED_DEBUG_SIGNATURE = 18766
const NOPARITY = 0
const NORMAL_PRINT = 0
const NORMAL_PRIORITY_CLASS = 32
const NORM_IGNORECASE = 1
const NORM_IGNOREKANATYPE = 65536
const NORM_IGNORENONSPACE = 2
const NORM_IGNORESYMBOLS = 4
const NORM_IGNOREWIDTH = 131072
const NORM_LINGUISTIC_CASING = 134217728
const NOTIFYICON_VERSION = 3
const NOTIFYICON_VERSION_4 = 4
const NOT_WITHIN = 0
const NO_ADDRESS = 11004
const NO_DATA = 11004
const NO_ERROR = 0
const NO_LOCK = 0
const NO_PRIORITY = 0
const NO_PROPAGATE_INHERIT_ACE = 4
const NO_RECOVERY = 11003
const NO_SRBTYPE_ADAPTER_DESCRIPTOR_SIZE = 0
const NRC_ACTSES = 15
const NRC_BADDR = 7
const NRC_BRIDGE = 35
const NRC_BUFLEN = 1
const NRC_CANCEL = 38
const NRC_CANOCCR = 36
const NRC_CMDCAN = 11
const NRC_CMDTMO = 5
const NRC_DUPENV = 48
const NRC_DUPNAME = 13
const NRC_ENVNOTDEF = 52
const NRC_GOODRET = 0
const NRC_IFBUSY = 33
const NRC_ILLCMD = 3
const NRC_ILLNN = 19
const NRC_INCOMP = 6
const NRC_INUSE = 22
const NRC_INVADDRESS = 57
const NRC_INVDDID = 59
const NRC_LOCKFAIL = 60
const NRC_LOCTFUL = 17
const NRC_MAXAPPS = 54
const NRC_NAMCONF = 25
const NRC_NAMERR = 23
const NRC_NAMTFUL = 14
const NRC_NOCALL = 20
const NRC_NORES = 9
const NRC_NORESOURCES = 56
const NRC_NOSAPS = 55
const NRC_NOWILD = 21
const NRC_OPENERR = 63
const NRC_OSRESNOTAV = 53
const NRC_PENDING = 255
const NRC_REMTFUL = 18
const NRC_SABORT = 24
const NRC_SCLOSED = 10
const NRC_SNUMOUT = 8
const NRC_SYSTEM = 64
const NRC_TOOMANY = 34
const NT351_INTERFACE_SIZE = 64
const NTAPI = "__stdcall"
const NTAPI_INLINE = "NTAPI"
const NTDDI_LONGHORN = 100663296
const NTDDI_VERSION = 167772160
const NTDDI_VISTA = 100663296
const NTDDI_VISTASP1 = 100663552
const NTDDI_VISTASP2 = 100663808
const NTDDI_VISTASP3 = 100664064
const NTDDI_VISTASP4 = 100664320
const NTDDI_WIN10 = 167772160
const NTDDI_WIN10_19H1 = 167772167
const NTDDI_WIN10_CO = 167772171
const NTDDI_WIN10_FE = 167772170
const NTDDI_WIN10_MN = 167772169
const NTDDI_WIN10_RS1 = 167772162
const NTDDI_WIN10_RS2 = 167772163
const NTDDI_WIN10_RS3 = 167772164
const NTDDI_WIN10_RS4 = 167772165
const NTDDI_WIN10_RS5 = 167772166
const NTDDI_WIN10_TH2 = 167772161
const NTDDI_WIN10_VB = 167772168
const NTDDI_WIN2K = 83886080
const NTDDI_WIN2KSP1 = 83886336
const NTDDI_WIN2KSP2 = 83886592
const NTDDI_WIN2KSP3 = 83886848
const NTDDI_WIN2KSP4 = 83887104
const NTDDI_WIN6 = 100663296
const NTDDI_WIN6SP1 = 100663552
const NTDDI_WIN6SP2 = 100663808
const NTDDI_WIN6SP3 = 100664064
const NTDDI_WIN6SP4 = 100664320
const NTDDI_WIN7 = 100728832
const NTDDI_WIN8 = 100794368
const NTDDI_WINBLUE = 100859904
const NTDDI_WINTHRESHOLD = 167772160
const NTDDI_WINXP = 83951616
const NTDDI_WINXPSP1 = 83951872
const NTDDI_WINXPSP2 = 83952128
const NTDDI_WINXPSP3 = 83952384
const NTDDI_WINXPSP4 = 83952640
const NTDDI_WS03 = 84017152
const NTDDI_WS03SP1 = 84017408
const NTDDI_WS03SP2 = 84017664
const NTDDI_WS03SP3 = 84017920
const NTDDI_WS03SP4 = 84018176
const NTDDI_WS08 = 100663552
const NTDDI_WS08SP2 = 100663808
const NTDDI_WS08SP3 = 100664064
const NTDDI_WS08SP4 = 100664320
const NTE_OP_OK = 0
const NTM_BOLD = 32
const NTM_DSIG = 2097152
const NTM_ITALIC = 1
const NTM_MULTIPLEMASTER = 524288
const NTM_NONNEGATIVE_AC = 65536
const NTM_PS_OPENTYPE = 131072
const NTM_REGULAR = 64
const NTM_TT_OPENTYPE = 262144
const NTM_TYPE1 = 1048576
const NTSYSAPI = "DECLSPEC_IMPORT"
const NTSYSCALLAPI = "DECLSPEC_IMPORT"
const NULLREGION = 1
const NULL_BRUSH = 5
const NULL_PEN = 8
const NUMA_NO_PREFERRED_NODE = -1
const NUMBRUSHES = 16
const NUMCOLORS = 24
const NUMFONTS = 22
const NUMLOCK_ON = 32
const NUMMARKERS = 20
const NUMPENS = 18
const NUMPRS_CURRENCY = 1024
const NUMPRS_DECIMAL = 256
const NUMPRS_EXPONENT = 2048
const NUMPRS_HEX_OCT = 64
const NUMPRS_INEXACT = 131072
const NUMPRS_LEADING_MINUS = 16
const NUMPRS_LEADING_PLUS = 4
const NUMPRS_LEADING_WHITE = 1
const NUMPRS_NEG = 65536
const NUMPRS_PARENS = 128
const NUMPRS_STD = 8191
const NUMPRS_THOUSANDS = 512
const NUMPRS_TRAILING_MINUS = 32
const NUMPRS_TRAILING_PLUS = 8
const NUMPRS_TRAILING_WHITE = 2
const NUMPRS_USE_ALL = 4096
const NUMRESERVED = 106
const NUM_DISCHARGE_POLICIES = 4
const N_BTMASK = 15
const N_BTSHFT = 4
const N_OR_COST = 3
const N_SORT_BUCKET = 32
const N_STATEMENT = 8
const N_TMASK = 48
const N_TMASK1 = 192
const N_TMASK2 = 240
const N_TSHIFT = 2
const NeedCurrentDirectoryForExePath = 0
const NotifyServiceStatusChange = 0
const OBJECT_INHERIT_ACE = 1
const OBJ_BITMAP = 7
const OBJ_BRUSH = 2
const OBJ_COLORSPACE = 14
const OBJ_DC = 3
const OBJ_ENHMETADC = 12
const OBJ_ENHMETAFILE = 13
const OBJ_EXTPEN = 11
const OBJ_FONT = 6
const OBJ_MEMDC = 10
const OBJ_METADC = 4
const OBJ_METAFILE = 9
const OBJ_PAL = 5
const OBJ_PEN = 1
const OBJ_REGION = 8
const OBSOLETE_DISK_GET_WRITE_CACHE_STATE = 475356
const OBSOLETE_IOCTL_STORAGE_RESET_BUS = 3002368
const OBSOLETE_IOCTL_STORAGE_RESET_DEVICE = 3002372
const OCSP_BASIC_BY_KEY_RESPONDER_ID = 2
const OCSP_BASIC_BY_NAME_RESPONDER_ID = 1
const OCSP_BASIC_GOOD_CERT_STATUS = 0
const OCSP_BASIC_RESPONSE_V1 = 0
const OCSP_BASIC_REVOKED_CERT_STATUS = 1
const OCSP_BASIC_UNKNOWN_CERT_STATUS = 2
const OCSP_INTERNAL_ERROR_RESPONSE = 2
const OCSP_MALFORMED_REQUEST_RESPONSE = 1
const OCSP_REQUEST_V1 = 0
const OCSP_SIG_REQUIRED_RESPONSE = 5
const OCSP_SUCCESSFUL_RESPONSE = 0
const OCSP_TRY_LATER_RESPONSE = 3
const OCSP_UNAUTHORIZED_RESPONSE = 6
const ODA_DRAWENTIRE = 1
const ODA_FOCUS = 4
const ODA_SELECT = 2
const ODDPARITY = 1
const ODS_CHECKED = 8
const ODS_COMBOBOXEDIT = 4096
const ODS_DEFAULT = 32
const ODS_DISABLED = 4
const ODS_FOCUS = 16
const ODS_GRAYED = 2
const ODS_HOTLIGHT = 64
const ODS_INACTIVE = 128
const ODS_NOACCEL = 256
const ODS_NOFOCUSRECT = 512
const ODS_SELECTED = 1
const ODT_BUTTON = 4
const ODT_COMBOBOX = 3
const ODT_LISTBOX = 2
const ODT_MENU = 1
const ODT_STATIC = 5
const OEM_CHARSET = 255
const OEM_FIXED_FONT = 10
const OE_Abort = 2
const OE_Cascade = 10
const OE_Default = 11
const OE_Fail = 3
const OE_Ignore = 4
const OE_None = 0
const OE_Replace = 5
const OE_Restrict = 7
const OE_Rollback = 1
const OE_SetDflt = 9
const OE_SetNull = 8
const OE_Update = 6
const OFFLINE_STATUS_INCOMPLETE = 4
const OFFLINE_STATUS_LOCAL = 1
const OFFLINE_STATUS_REMOTE = 2
const OFN_ALLOWMULTISELECT = 512
const OFN_CREATEPROMPT = 8192
const OFN_DONTADDTORECENT = 33554432
const OFN_ENABLEHOOK = 32
const OFN_ENABLEINCLUDENOTIFY = 4194304
const OFN_ENABLESIZING = 8388608
const OFN_ENABLETEMPLATE = 64
const OFN_ENABLETEMPLATEHANDLE = 128
const OFN_EXPLORER = 524288
const OFN_EXTENSIONDIFFERENT = 1024
const OFN_EX_NOPLACESBAR = 1
const OFN_FILEMUSTEXIST = 4096
const OFN_FORCESHOWHIDDEN = 268435456
const OFN_HIDEREADONLY = 4
const OFN_LONGNAMES = 2097152
const OFN_NOCHANGEDIR = 8
const OFN_NODEREFERENCELINKS = 1048576
const OFN_NOLONGNAMES = 262144
const OFN_NONETWORKBUTTON = 131072
const OFN_NOREADONLYRETURN = 32768
const OFN_NOTESTFILECREATE = 65536
const OFN_NOVALIDATE = 256
const OFN_OVERWRITEPROMPT = 2
const OFN_PATHMUSTEXIST = 2048
const OFN_READONLY = 1
const OFN_SHAREAWARE = 16384
const OFN_SHAREFALLTHROUGH = 2
const OFN_SHARENOWARN = 1
const OFN_SHAREWARN = 0
const OFN_SHOWHELP = 16
const OFS_MAXPATHNAME = 128
const OF_CANCEL = 2048
const OF_CREATE = 4096
const OF_DELETE = 512
const OF_EXIST = 16384
const OF_PARSE = 256
const OF_PROMPT = 8192
const OF_READ = 0
const OF_READWRITE = 2
const OF_REOPEN = 32768
const OF_SHARE_COMPAT = 0
const OF_SHARE_DENY_NONE = 64
const OF_SHARE_DENY_READ = 48
const OF_SHARE_DENY_WRITE = 32
const OF_SHARE_EXCLUSIVE = 16
const OF_VERIFY = 1024
const OF_WRITE = 1
const OInetCombineIUri = 0
const OInetCombineUrl = 0
const OInetCombineUrlEx = 0
const OInetCompareUrl = 0
const OInetGetSession = 0
const OInetParseUrl = 0
const OInetQueryInfo = 0
const OLDFONTENUMPROC = 0
const OLD_P_OVERLAY = 2
const OLECREATE_LEAVERUNNING = 1
const OLEIVERB_DISCARDUNDOSTATE = -6
const OLEIVERB_HIDE = -3
const OLEIVERB_INPLACEACTIVATE = -5
const OLEIVERB_OPEN = -2
const OLEIVERB_PRIMARY = 0
const OLEIVERB_SHOW = -1
const OLEIVERB_UIACTIVATE = -4
const OLEOBJ_E_FIRST = 2147746176
const OLEOBJ_E_LAST = 2147746191
const OLEOBJ_S_FIRST = 262528
const OLEOBJ_S_LAST = 262543
const OMIT_TEMPDB = 0
const ONE5STOPBITS = 1
const ONEPASS_MULTI = 2
const ONEPASS_OFF = 0
const ONEPASS_SINGLE = 1
const ONESTOPBIT = 0
const OPAQUE = 2
const OPAQUEKEYBLOB = 9
const OPENCARDNAMEA_EX = 0
const OPENCARDNAMEW_EX = 0
const OPENCARDNAME_A = 0
const OPENCARDNAME_W = 0
const OPENCHANNEL = 4110
const OPEN_ALWAYS = 4
const OPEN_EXISTING = 3
const OPERATION_API_VERSION = 1
const OPERATION_END_DISCARD = 1
const OPERATION_START_TRACE_CURRENT_THREAD = 1
const OPFLAG_APPEND = 8
const OPFLAG_AUXDELETE = 4
const OPFLAG_BULKCSR = 1
const OPFLAG_BYTELENARG = 192
const OPFLAG_EPHEM = 1
const OPFLAG_FORDELETE = 8
const OPFLAG_ISNOOP = 64
const OPFLAG_ISUPDATE = 4
const OPFLAG_LASTROWID = 32
const OPFLAG_LENGTHARG = 64
const OPFLAG_NCHANGE = 1
const OPFLAG_NOCHNG = 1
const OPFLAG_NOCHNG_MAGIC = 109
const OPFLAG_P2ISREG = 16
const OPFLAG_PERMUTE = 1
const OPFLAG_PREFORMAT = 128
const OPFLAG_SAVEPOSITION = 2
const OPFLAG_SEEKEQ = 2
const OPFLAG_TYPEOFARG = 128
const OPFLAG_USESEEKRESULT = 16
const OPFLG_IN1 = 2
const OPFLG_IN2 = 4
const OPFLG_IN3 = 8
const OPFLG_JUMP = 1
const OPFLG_JUMP0 = 128
const OPFLG_NCYCLE = 64
const OPFLG_OUT2 = 16
const OPFLG_OUT3 = 32
const OPLOCK_LEVEL_CACHE_HANDLE = 2
const OPLOCK_LEVEL_CACHE_READ = 1
const OPLOCK_LEVEL_CACHE_WRITE = 4
const OP_Abortable = 189
const OP_Add = 106
const OP_AddImm = 86
const OP_Affinity = 96
const OP_AggFinal = 165
const OP_AggInverse = 161
const OP_AggStep = 162
const OP_AggStep1 = 163
const OP_AggValue = 164
const OP_And = 44
const OP_AutoCommit = 1
const OP_BeginSubrtn = 74
const OP_BitAnd = 102
const OP_BitNot = 114
const OP_BitOr = 103
const OP_Blob = 77
const OP_Cast = 88
const OP_Checkpoint = 3
const OP_Clear = 145
const OP_Close = 122
const OP_ClrSubtype = 180
const OP_CollSeq = 85
const OP_Column = 94
const OP_ColumnsUsed = 123
const OP_Compare = 90
const OP_Concat = 111
const OP_Copy = 80
const OP_Count = 98
const OP_CreateBtree = 147
const OP_CursorHint = 185
const OP_CursorLock = 167
const OP_CursorUnlock = 168
const OP_DecrJumpZero = 61
const OP_DeferredSeek = 141
const OP_Delete = 130
const OP_Destroy = 144
const OP_Divide = 109
const OP_DropIndex = 152
const OP_DropTable = 151
const OP_DropTrigger = 154
const OP_ElseEq = 58
const OP_EndCoroutine = 68
const OP_Eq = 53
const OP_Expire = 166
const OP_Explain = 188
const OP_Filter = 64
const OP_FilterAdd = 183
const OP_FinishSeek = 143
const OP_FkCheck = 83
const OP_FkCounter = 158
const OP_FkIfZero = 49
const OP_Found = 29
const OP_Function = 66
const OP_Ge = 57
const OP_GetSubtype = 181
const OP_Gosub = 10
const OP_Goto = 9
const OP_Gt = 54
const OP_Halt = 70
const OP_HaltIfNull = 69
const OP_IdxDelete = 140
const OP_IdxGE = 45
const OP_IdxGT = 41
const OP_IdxInsert = 138
const OP_IdxLE = 40
const OP_IdxLT = 42
const OP_IdxRowid = 142
const OP_If = 16
const OP_IfNoHope = 26
const OP_IfNot = 17
const OP_IfNotOpen = 25
const OP_IfNotZero = 60
const OP_IfNullRow = 20
const OP_IfPos = 59
const OP_IfSizeBetween = 33
const OP_IncrVacuum = 62
const OP_Init = 8
const OP_InitCoroutine = 11
const OP_Insert = 128
const OP_Int64 = 72
const OP_IntCopy = 82
const OP_Integer = 71
const OP_IntegrityCk = 155
const OP_IsNull = 50
const OP_IsTrue = 91
const OP_IsType = 18
const OP_JournalMode = 4
const OP_Jump = 14
const OP_Last = 32
const OP_Le = 55
const OP_LoadAnalysis = 150
const OP_Lt = 56
const OP_MakeRecord = 97
const OP_MaxPgcnt = 179
const OP_MemMax = 159
const OP_Move = 79
const OP_Multiply = 108
const OP_MustBeInt = 13
const OP_Ne = 52
const OP_NewRowid = 127
const OP_Next = 39
const OP_NoConflict = 27
const OP_Noop = 187
const OP_Not = 19
const OP_NotExists = 31
const OP_NotFound = 28
const OP_NotNull = 51
const OP_Null = 75
const OP_NullRow = 136
const OP_Offset = 93
const OP_OffsetLimit = 160
const OP_Once = 15
const OP_OpenAutoindex = 116
const OP_OpenDup = 115
const OP_OpenEphemeral = 118
const OP_OpenPseudo = 121
const OP_OpenRead = 112
const OP_OpenWrite = 113
const OP_Or = 43
const OP_Pagecount = 178
const OP_Param = 157
const OP_ParseSchema = 149
const OP_Permutation = 89
const OP_Prev = 38
const OP_Program = 48
const OP_PureFunc = 65
const OP_ReadCookie = 99
const OP_Real = 153
const OP_RealAffinity = 87
const OP_ReleaseReg = 186
const OP_Remainder = 110
const OP_ReopenIdx = 101
const OP_ResetCount = 131
const OP_ResetSorter = 146
const OP_ResultRow = 84
const OP_Return = 67
const OP_Rewind = 36
const OP_RowCell = 129
const OP_RowData = 134
const OP_RowSetAdd = 156
const OP_RowSetRead = 46
const OP_RowSetTest = 47
const OP_Rowid = 135
const OP_SCopy = 81
const OP_Savepoint = 0
const OP_SeekEnd = 137
const OP_SeekGE = 23
const OP_SeekGT = 24
const OP_SeekHit = 125
const OP_SeekLE = 22
const OP_SeekLT = 21
const OP_SeekRowid = 30
const OP_SeekScan = 124
const OP_Sequence = 126
const OP_SequenceTest = 120
const OP_SetCookie = 100
const OP_SetSubtype = 182
const OP_ShiftLeft = 104
const OP_ShiftRight = 105
const OP_SoftNull = 76
const OP_Sort = 35
const OP_SorterCompare = 132
const OP_SorterData = 133
const OP_SorterInsert = 139
const OP_SorterNext = 37
const OP_SorterOpen = 119
const OP_SorterSort = 34
const OP_SqlExec = 148
const OP_String = 73
const OP_String8 = 117
const OP_Subtract = 107
const OP_TableLock = 169
const OP_Trace = 184
const OP_Transaction = 2
const OP_TypeCheck = 95
const OP_VBegin = 170
const OP_VCheck = 174
const OP_VColumn = 176
const OP_VCreate = 171
const OP_VDestroy = 172
const OP_VFilter = 6
const OP_VInitIn = 175
const OP_VNext = 63
const OP_VOpen = 173
const OP_VRename = 177
const OP_VUpdate = 7
const OP_Vacuum = 5
const OP_Variable = 78
const OP_Yield = 12
const OP_ZeroOrNull = 92
const ORD_LANGDRIVER = 1
const OR_INVALID_OID = 1911
const OR_INVALID_OXID = 1910
const OR_INVALID_SET = 1912
const OSVERSION_MASK = 4294901760
const OS_VXWORKS = 0
const OUTPUT_DEBUG_STRING_EVENT = 8
const OUT_CHARACTER_PRECIS = 2
const OUT_DEFAULT_PRECIS = 0
const OUT_DEVICE_PRECIS = 5
const OUT_OUTLINE_PRECIS = 8
const OUT_PS_ONLY_PRECIS = 10
const OUT_RASTER_PRECIS = 6
const OUT_SCREEN_OUTLINE_PRECIS = 9
const OUT_STRING_PRECIS = 1
const OUT_STROKE_PRECIS = 3
const OUT_TT_ONLY_PRECIS = 7
const OUT_TT_PRECIS = 4
const OVERFLOW = 3
const OVERWRITE_HIDDEN = 4
const OWNER_SECURITY_INFORMATION = 1
const ObjectCloseAuditAlarm = 0
const ObjectDeleteAuditAlarm = 0
const ObjectOpenAuditAlarm = 0
const ObjectPrivilegeAuditAlarm = 0
const OemToAnsi = 0
const OemToAnsiBuff = 0
const OemToChar = 0
const OemToCharBuff = 0
const OpenBackupEventLog = 0
const OpenDesktop = 0
const OpenEncryptedFileRaw = 0
const OpenEvent = 0
const OpenEventLog = 0
const OpenFileMapping = 0
const OpenJobObject = 0
const OpenMutex = 0
const OpenPrinter = 0
const OpenPrinter2 = 0
const OpenPrivateNamespace = 0
const OpenSCManager = 0
const OpenSemaphore = 0
const OpenService = 0
const OpenWaitableTimer = 0
const OpenWindowStation = 0
const OutputDebugStr = 0
const OutputDebugString = 0
const P4_COLLSEQ = -2
const P4_DYNAMIC = -6
const P4_EXPR = -9
const P4_FREE_IF_LE = -6
const P4_FUNCCTX = -15
const P4_FUNCDEF = -7
const P4_INT32 = -3
const P4_INT64 = -13
const P4_INTARRAY = -14
const P4_KEYINFO = -8
const P4_MEM = -10
const P4_NOTUSED = 0
const P4_REAL = -12
const P4_STATIC = -1
const P4_SUBPROGRAM = -4
const P4_TABLE = -5
const P4_TABLEREF = -16
const P4_TRANSIENT = 0
const P4_VTAB = -11
const P5_ConstraintCheck = 3
const P5_ConstraintFK = 4
const P5_ConstraintNotNull = 1
const P5_ConstraintUnique = 2
const PAGER_CACHESPILL = 32
const PAGER_CKPT_FULLFSYNC = 16
const PAGER_ERROR = 6
const PAGER_FLAGS_MASK = 56
const PAGER_FULLFSYNC = 8
const PAGER_GET_NOCONTENT = 1
const PAGER_GET_READONLY = 2
const PAGER_JOURNALMODE_DELETE = 0
const PAGER_JOURNALMODE_MEMORY = 4
const PAGER_JOURNALMODE_OFF = 2
const PAGER_JOURNALMODE_PERSIST = 1
const PAGER_JOURNALMODE_QUERY = -1
const PAGER_JOURNALMODE_TRUNCATE = 3
const PAGER_JOURNALMODE_WAL = 5
const PAGER_LOCKINGMODE_EXCLUSIVE = 1
const PAGER_LOCKINGMODE_NORMAL = 0
const PAGER_LOCKINGMODE_QUERY = -1
const PAGER_MEMORY = 2
const PAGER_OMIT_JOURNAL = 1
const PAGER_OPEN = 0
const PAGER_READER = 1
const PAGER_STAT_HIT = 0
const PAGER_STAT_MISS = 1
const PAGER_STAT_SPILL = 3
const PAGER_STAT_WRITE = 2
const PAGER_SYNCHRONOUS_EXTRA = 4
const PAGER_SYNCHRONOUS_FULL = 3
const PAGER_SYNCHRONOUS_MASK = 7
const PAGER_SYNCHRONOUS_NORMAL = 2
const PAGER_SYNCHRONOUS_OFF = 1
const PAGER_WRITER_CACHEMOD = 3
const PAGER_WRITER_DBMOD = 4
const PAGER_WRITER_FINISHED = 5
const PAGER_WRITER_LOCKED = 2
const PAGESETUPDLGORD = 1546
const PAGESETUPDLGORDMOTIF = 1550
const PAGE_ENCLAVE_DECOMMIT = 268435456
const PAGE_ENCLAVE_THREAD_CONTROL = 2147483648
const PAGE_ENCLAVE_UNVALIDATED = 536870912
const PAGE_EXECUTE = 16
const PAGE_EXECUTE_READ = 32
const PAGE_EXECUTE_READWRITE = 64
const PAGE_EXECUTE_WRITECOPY = 128
const PAGE_GRAPHICS_COHERENT = 131072
const PAGE_GRAPHICS_EXECUTE = 16384
const PAGE_GRAPHICS_EXECUTE_READ = 32768
const PAGE_GRAPHICS_EXECUTE_READWRITE = 65536
const PAGE_GRAPHICS_NOACCESS = 2048
const PAGE_GRAPHICS_READONLY = 4096
const PAGE_GRAPHICS_READWRITE = 8192
const PAGE_GUARD = 256
const PAGE_NOACCESS = 1
const PAGE_NOCACHE = 512
const PAGE_READONLY = 2
const PAGE_READWRITE = 4
const PAGE_REVERT_TO_FILE_MAP = 2147483648
const PAGE_TARGETS_INVALID = 1073741824
const PAGE_TARGETS_NO_UPDATE = 1073741824
const PAGE_WRITECOMBINE = 1024
const PAGE_WRITECOPY = 8
const PANOSE_COUNT = 10
const PAN_ANY = 0
const PAN_ARMSTYLE_INDEX = 6
const PAN_BENT_ARMS_DOUBLE_SERIF = 11
const PAN_BENT_ARMS_HORZ = 7
const PAN_BENT_ARMS_SINGLE_SERIF = 10
const PAN_BENT_ARMS_VERT = 9
const PAN_BENT_ARMS_WEDGE = 8
const PAN_CONTRAST_HIGH = 8
const PAN_CONTRAST_INDEX = 4
const PAN_CONTRAST_LOW = 4
const PAN_CONTRAST_MEDIUM = 6
const PAN_CONTRAST_MEDIUM_HIGH = 7
const PAN_CONTRAST_MEDIUM_LOW = 5
const PAN_CONTRAST_NONE = 2
const PAN_CONTRAST_VERY_HIGH = 9
const PAN_CONTRAST_VERY_LOW = 3
const PAN_CULTURE_LATIN = 0
const PAN_FAMILYTYPE_INDEX = 0
const PAN_FAMILY_DECORATIVE = 4
const PAN_FAMILY_PICTORIAL = 5
const PAN_FAMILY_SCRIPT = 3
const PAN_FAMILY_TEXT_DISPLAY = 2
const PAN_LETTERFORM_INDEX = 7
const PAN_LETT_NORMAL_BOXED = 4
const PAN_LETT_NORMAL_CONTACT = 2
const PAN_LETT_NORMAL_FLATTENED = 5
const PAN_LETT_NORMAL_OFF_CENTER = 7
const PAN_LETT_NORMAL_ROUNDED = 6
const PAN_LETT_NORMAL_SQUARE = 8
const PAN_LETT_NORMAL_WEIGHTED = 3
const PAN_LETT_OBLIQUE_BOXED = 11
const PAN_LETT_OBLIQUE_CONTACT = 9
const PAN_LETT_OBLIQUE_FLATTENED = 12
const PAN_LETT_OBLIQUE_OFF_CENTER = 14
const PAN_LETT_OBLIQUE_ROUNDED = 13
const PAN_LETT_OBLIQUE_SQUARE = 15
const PAN_LETT_OBLIQUE_WEIGHTED = 10
const PAN_MIDLINE_CONSTANT_POINTED = 9
const PAN_MIDLINE_CONSTANT_SERIFED = 10
const PAN_MIDLINE_CONSTANT_TRIMMED = 8
const PAN_MIDLINE_HIGH_POINTED = 6
const PAN_MIDLINE_HIGH_SERIFED = 7
const PAN_MIDLINE_HIGH_TRIMMED = 5
const PAN_MIDLINE_INDEX = 8
const PAN_MIDLINE_LOW_POINTED = 12
const PAN_MIDLINE_LOW_SERIFED = 13
const PAN_MIDLINE_LOW_TRIMMED = 11
const PAN_MIDLINE_STANDARD_POINTED = 3
const PAN_MIDLINE_STANDARD_SERIFED = 4
const PAN_MIDLINE_STANDARD_TRIMMED = 2
const PAN_NO_FIT = 1
const PAN_PROPORTION_INDEX = 3
const PAN_PROP_CONDENSED = 6
const PAN_PROP_EVEN_WIDTH = 4
const PAN_PROP_EXPANDED = 5
const PAN_PROP_MODERN = 3
const PAN_PROP_MONOSPACED = 9
const PAN_PROP_OLD_STYLE = 2
const PAN_PROP_VERY_CONDENSED = 8
const PAN_PROP_VERY_EXPANDED = 7
const PAN_SERIFSTYLE_INDEX = 1
const PAN_SERIF_BONE = 8
const PAN_SERIF_COVE = 2
const PAN_SERIF_EXAGGERATED = 9
const PAN_SERIF_FLARED = 14
const PAN_SERIF_NORMAL_SANS = 11
const PAN_SERIF_OBTUSE_COVE = 3
const PAN_SERIF_OBTUSE_SANS = 12
const PAN_SERIF_OBTUSE_SQUARE_COVE = 5
const PAN_SERIF_PERP_SANS = 13
const PAN_SERIF_ROUNDED = 15
const PAN_SERIF_SQUARE = 6
const PAN_SERIF_SQUARE_COVE = 4
const PAN_SERIF_THIN = 7
const PAN_SERIF_TRIANGLE = 10
const PAN_STRAIGHT_ARMS_DOUBLE_SERIF = 6
const PAN_STRAIGHT_ARMS_HORZ = 2
const PAN_STRAIGHT_ARMS_SINGLE_SERIF = 5
const PAN_STRAIGHT_ARMS_VERT = 4
const PAN_STRAIGHT_ARMS_WEDGE = 3
const PAN_STROKEVARIATION_INDEX = 5
const PAN_STROKE_GRADUAL_DIAG = 2
const PAN_STROKE_GRADUAL_HORZ = 5
const PAN_STROKE_GRADUAL_TRAN = 3
const PAN_STROKE_GRADUAL_VERT = 4
const PAN_STROKE_INSTANT_VERT = 8
const PAN_STROKE_RAPID_HORZ = 7
const PAN_STROKE_RAPID_VERT = 6
const PAN_WEIGHT_BLACK = 10
const PAN_WEIGHT_BOLD = 8
const PAN_WEIGHT_BOOK = 5
const PAN_WEIGHT_DEMI = 7
const PAN_WEIGHT_HEAVY = 9
const PAN_WEIGHT_INDEX = 2
const PAN_WEIGHT_LIGHT = 3
const PAN_WEIGHT_MEDIUM = 6
const PAN_WEIGHT_NORD = 11
const PAN_WEIGHT_THIN = 4
const PAN_WEIGHT_VERY_LIGHT = 2
const PAN_XHEIGHT_CONSTANT_LARGE = 4
const PAN_XHEIGHT_CONSTANT_SMALL = 2
const PAN_XHEIGHT_CONSTANT_STD = 3
const PAN_XHEIGHT_DUCKING_LARGE = 7
const PAN_XHEIGHT_DUCKING_SMALL = 5
const PAN_XHEIGHT_DUCKING_STD = 6
const PAN_XHEIGHT_INDEX = 9
const PARAMFLAG_FHASCUSTDATA = 64
const PARAMFLAG_FHASDEFAULT = 32
const PARAMFLAG_FIN = 1
const PARAMFLAG_FLCID = 4
const PARAMFLAG_FOPT = 16
const PARAMFLAG_FOUT = 2
const PARAMFLAG_FRETVAL = 8
const PARAMFLAG_NONE = 0
const PARSE_DECODE = 0
const PARSE_ENCODE = 0
const PARSE_MODE_DECLARE_VTAB = 1
const PARSE_MODE_NORMAL = 0
const PARSE_MODE_RENAME = 2
const PARSE_MODE_UNMAP = 3
const PARTITION_ENTRY_UNUSED = 0
const PARTITION_EXTENDED = 5
const PARTITION_FAT32 = 11
const PARTITION_FAT32_XINT13 = 12
const PARTITION_FAT_12 = 1
const PARTITION_FAT_16 = 4
const PARTITION_HUGE = 6
const PARTITION_IFS = 7
const PARTITION_LDM = 66
const PARTITION_NTFT = 128
const PARTITION_OS2BOOTMGR = 10
const PARTITION_PREP = 65
const PARTITION_UNIX = 99
const PARTITION_XENIX_1 = 2
const PARTITION_XENIX_2 = 3
const PARTITION_XINT13 = 14
const PARTITION_XINT13_EXTENDED = 15
const PARTLY_WITHIN = 1
const PASCAL = "__stdcall"
const PASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = 0
const PASSTHROUGH = 19
const PATH_MAX = 260
const PA_ACTIVATE = 1
const PA_NOACTIVATE = 3
const PBTF_APMRESUMEFROMFAILURE = 1
const PBT_APMBATTERYLOW = 9
const PBT_APMOEMEVENT = 11
const PBT_APMPOWERSTATUSCHANGE = 10
const PBT_APMQUERYSTANDBY = 1
const PBT_APMQUERYSTANDBYFAILED = 3
const PBT_APMQUERYSUSPEND = 0
const PBT_APMQUERYSUSPENDFAILED = 2
const PBT_APMRESUMEAUTOMATIC = 18
const PBT_APMRESUMECRITICAL = 6
const PBT_APMRESUMESTANDBY = 8
const PBT_APMRESUMESUSPEND = 7
const PBT_APMSTANDBY = 5
const PBT_APMSUSPEND = 4
const PBT_POWERSETTINGCHANGE = 32787
const PCACHE1_MIGHT_USE_GROUP_MUTEX = 1
const PCACHE_DIRTYLIST_ADD = 2
const PCACHE_DIRTYLIST_FRONT = 3
const PCACHE_DIRTYLIST_REMOVE = 1
const PCASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = 0
const PCLEANUI = 2214592512
const PC_EXPLICIT = 2
const PC_INTERIORS = 128
const PC_NOCOLLAPSE = 4
const PC_NONE = 0
const PC_PATHS = 512
const PC_POLYGON = 1
const PC_POLYPOLYGON = 256
const PC_RECTANGLE = 2
const PC_RESERVED = 1
const PC_SCANLINE = 8
const PC_STYLED = 32
const PC_TRAPEZOID = 4
const PC_WIDE = 16
const PC_WIDESTYLED = 64
const PC_WINDPOLYGON = 4
const PDCAP_D0_SUPPORTED = 1
const PDCAP_D1_SUPPORTED = 2
const PDCAP_D2_SUPPORTED = 4
const PDCAP_D3_SUPPORTED = 8
const PDCAP_WAKE_FROM_D0_SUPPORTED = 16
const PDCAP_WAKE_FROM_D1_SUPPORTED = 32
const PDCAP_WAKE_FROM_D2_SUPPORTED = 64
const PDCAP_WAKE_FROM_D3_SUPPORTED = 128
const PDCAP_WARM_EJECT_SUPPORTED = 256
const PDC_ARRIVAL = 1
const PDC_MAPPING_CHANGE = 256
const PDC_MODE_ASPECTRATIOPRESERVED = 2048
const PDC_MODE_CENTERED = 128
const PDC_MODE_DEFAULT = 64
const PDC_ORIENTATION_0 = 4
const PDC_ORIENTATION_180 = 16
const PDC_ORIENTATION_270 = 32
const PDC_ORIENTATION_90 = 8
const PDC_ORIGIN = 1024
const PDC_REMOVAL = 2
const PDC_RESOLUTION = 512
const PDERR_CREATEICFAILURE = 4106
const PDERR_DEFAULTDIFFERENT = 4108
const PDERR_DNDMMISMATCH = 4105
const PDERR_GETDEVMODEFAIL = 4101
const PDERR_INITFAILURE = 4102
const PDERR_LOADDRVFAILURE = 4100
const PDERR_NODEFAULTPRN = 4104
const PDERR_NODEVICES = 4103
const PDERR_PARSEFAILURE = 4098
const PDERR_PRINTERCODES = 4096
const PDERR_PRINTERNOTFOUND = 4107
const PDERR_RETDEFFAILURE = 4099
const PDERR_SETUPFAILURE = 4097
const PDEVICESIZE = 26
const PDIRTYUI = 2281701376
const PD_ALLPAGES = 0
const PD_COLLATE = 16
const PD_CURRENTPAGE = 4194304
const PD_DISABLEPRINTTOFILE = 524288
const PD_ENABLEPRINTHOOK = 4096
const PD_ENABLEPRINTTEMPLATE = 16384
const PD_ENABLEPRINTTEMPLATEHANDLE = 65536
const PD_ENABLESETUPHOOK = 8192
const PD_ENABLESETUPTEMPLATE = 32768
const PD_ENABLESETUPTEMPLATEHANDLE = 131072
const PD_EXCLUSIONFLAGS = 16777216
const PD_EXCL_COPIESANDCOLLATE = 33024
const PD_HIDEPRINTTOFILE = 1048576
const PD_NOCURRENTPAGE = 8388608
const PD_NONETWORKBUTTON = 2097152
const PD_NOPAGENUMS = 8
const PD_NOSELECTION = 4
const PD_NOWARNING = 128
const PD_PAGENUMS = 2
const PD_PRINTSETUP = 64
const PD_PRINTTOFILE = 32
const PD_RESULT_APPLY = 2
const PD_RESULT_CANCEL = 0
const PD_RESULT_PRINT = 1
const PD_RETURNDC = 256
const PD_RETURNDEFAULT = 1024
const PD_RETURNIC = 512
const PD_SELECTION = 1
const PD_SHOWHELP = 2048
const PD_USEDEVMODECOPIES = 262144
const PD_USEDEVMODECOPIESANDCOLLATE = 262144
const PD_USELARGETEMPLATE = 268435456
const PENARBITRATIONTYPE_FIS = 2
const PENARBITRATIONTYPE_MAX = 4
const PENARBITRATIONTYPE_NONE = 0
const PENARBITRATIONTYPE_SPT = 3
const PENARBITRATIONTYPE_WIN8 = 1
const PENDING_BYTE = 0
const PENDING_LOCK = 3
const PENVISUALIZATION_CURSOR = 32
const PENVISUALIZATION_DOUBLETAP = 2
const PENVISUALIZATION_OFF = 0
const PENVISUALIZATION_ON = 35
const PENVISUALIZATION_TAP = 1
const PEN_FLAG_BARREL = 1
const PEN_FLAG_ERASER = 4
const PEN_FLAG_INVERTED = 2
const PEN_FLAG_NONE = 0
const PEN_MASK_NONE = 0
const PEN_MASK_PRESSURE = 1
const PEN_MASK_ROTATION = 2
const PEN_MASK_TILT_X = 4
const PEN_MASK_TILT_Y = 8
const PERFORMANCE_DATA_VERSION = 1
const PERFSTATE_POLICY_CHANGE_IDEAL = 0
const PERFSTATE_POLICY_CHANGE_MAX = 2
const PERFSTATE_POLICY_CHANGE_ROCKET = 2
const PERFSTATE_POLICY_CHANGE_SINGLE = 1
const PERF_100NSEC_MULTI_TIMER = 575735040
const PERF_100NSEC_MULTI_TIMER_INV = 592512256
const PERF_100NSEC_TIMER = 542180608
const PERF_100NSEC_TIMER_INV = 558957824
const PERF_AVERAGE_BASE = 1073939458
const PERF_AVERAGE_BULK = 1073874176
const PERF_AVERAGE_TIMER = 805438464
const PERF_COUNTER_100NS_QUEUELEN_TYPE = 5571840
const PERF_COUNTER_BASE = 196608
const PERF_COUNTER_BULK_COUNT = 272696576
const PERF_COUNTER_COUNTER = 272696320
const PERF_COUNTER_DELTA = 4195328
const PERF_COUNTER_ELAPSED = 262144
const PERF_COUNTER_FRACTION = 131072
const PERF_COUNTER_HISTOGRAM = 393216
const PERF_COUNTER_HISTOGRAM_TYPE = 2147483648
const PERF_COUNTER_LARGE_DELTA = 4195584
const PERF_COUNTER_LARGE_QUEUELEN_TYPE = 4523264
const PERF_COUNTER_LARGE_RAWCOUNT = 65792
const PERF_COUNTER_LARGE_RAWCOUNT_HEX = 256
const PERF_COUNTER_MULTI_BASE = 1107494144
const PERF_COUNTER_MULTI_TIMER = 574686464
const PERF_COUNTER_MULTI_TIMER_INV = 591463680
const PERF_COUNTER_NODATA = 1073742336
const PERF_COUNTER_OBJ_TIME_QUEUELEN_TYPE = 6620416
const PERF_COUNTER_PRECISION = 458752
const PERF_COUNTER_QUEUELEN = 327680
const PERF_COUNTER_QUEUELEN_TYPE = 4523008
const PERF_COUNTER_RATE = 65536
const PERF_COUNTER_RAWCOUNT = 65536
const PERF_COUNTER_RAWCOUNT_HEX = 0
const PERF_COUNTER_TEXT = 2816
const PERF_COUNTER_TIMER = 541132032
const PERF_COUNTER_TIMER_INV = 557909248
const PERF_COUNTER_VALUE = 0
const PERF_DATA_REVISION = 1
const PERF_DATA_VERSION = 1
const PERF_DELTA_BASE = 8388608
const PERF_DELTA_COUNTER = 4194304
const PERF_DETAIL_ADVANCED = 200
const PERF_DETAIL_EXPERT = 300
const PERF_DETAIL_NOVICE = 100
const PERF_DETAIL_WIZARD = 400
const PERF_DISPLAY_NOSHOW = 1073741824
const PERF_DISPLAY_NO_SUFFIX = 0
const PERF_DISPLAY_PERCENT = 536870912
const PERF_DISPLAY_PER_SEC = 268435456
const PERF_DISPLAY_SECONDS = 805306368
const PERF_ELAPSED_TIME = 807666944
const PERF_INVERSE_COUNTER = 16777216
const PERF_LARGE_RAW_BASE = 1073939712
const PERF_LARGE_RAW_FRACTION = 537003264
const PERF_MULTI_COUNTER = 33554432
const PERF_NO_INSTANCES = -1
const PERF_NO_UNIQUE_ID = -1
const PERF_NUMBER_DECIMAL = 65536
const PERF_NUMBER_DEC_1000 = 131072
const PERF_NUMBER_HEX = 0
const PERF_OBJECT_TIMER = 2097152
const PERF_OBJ_TIME_TIMER = 543229184
const PERF_PRECISION_100NS_TIMER = 542573824
const PERF_PRECISION_OBJECT_TIMER = 543622400
const PERF_PRECISION_SYSTEM_TIMER = 541525248
const PERF_PRECISION_TIMESTAMP = 1073939712
const PERF_RAW_BASE = 1073939459
const PERF_RAW_FRACTION = 537003008
const PERF_SAMPLE_BASE = 1073939457
const PERF_SAMPLE_COUNTER = 4260864
const PERF_SAMPLE_FRACTION = 549585920
const PERF_SIZE_DWORD = 0
const PERF_SIZE_LARGE = 256
const PERF_SIZE_VARIABLE_LEN = 768
const PERF_SIZE_ZERO = 512
const PERF_TEXT_ASCII = 65536
const PERF_TEXT_UNICODE = 0
const PERF_TIMER_100NS = 1048576
const PERF_TIMER_TICK = 0
const PERF_TYPE_COUNTER = 1024
const PERF_TYPE_NUMBER = 0
const PERF_TYPE_TEXT = 2048
const PERF_TYPE_ZERO = 3072
const PERSISTENT_VOLUME_STATE_SHORT_NAME_CREATION_DISABLED = 1
const PFD_DEPTH_DONTCARE = 536870912
const PFD_DIRECT3D_ACCELERATED = 16384
const PFD_DOUBLEBUFFER = 1
const PFD_DOUBLEBUFFER_DONTCARE = 1073741824
const PFD_DRAW_TO_BITMAP = 8
const PFD_DRAW_TO_WINDOW = 4
const PFD_GENERIC_ACCELERATED = 4096
const PFD_GENERIC_FORMAT = 64
const PFD_MAIN_PLANE = 0
const PFD_NEED_PALETTE = 128
const PFD_NEED_SYSTEM_PALETTE = 256
const PFD_OVERLAY_PLANE = 1
const PFD_STEREO = 2
const PFD_STEREO_DONTCARE = 2147483648
const PFD_SUPPORT_COMPOSITION = 32768
const PFD_SUPPORT_DIRECTDRAW = 8192
const PFD_SUPPORT_GDI = 16
const PFD_SUPPORT_OPENGL = 32
const PFD_SWAP_COPY = 1024
const PFD_SWAP_EXCHANGE = 512
const PFD_SWAP_LAYER_BUFFERS = 2048
const PFD_TYPE_COLORINDEX = 1
const PFD_TYPE_RGBA = 0
const PFD_UNDERLAY_PLANE = -1
const PFNGETPROFILEPATH = 0
const PFNPROCESSPOLICIES = 0
const PFNRECONCILEPROFILE = 0
const PF_3DNOW_INSTRUCTIONS_AVAILABLE = 7
const PF_ALPHA_BYTE_INSTRUCTIONS = 5
const PF_APPLETALK = 16
const PF_ARM_64BIT_LOADSTORE_ATOMIC = 25
const PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE = 24
const PF_ARM_EXTERNAL_CACHE_AVAILABLE = 26
const PF_ARM_FMAC_INSTRUCTIONS_AVAILABLE = 27
const PF_ARM_NEON_INSTRUCTIONS_AVAILABLE = 19
const PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE = 34
const PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE = 43
const PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE = 44
const PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE = 31
const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE = 30
const PF_ARM_V8_INSTRUCTIONS_AVAILABLE = 29
const PF_ARM_VFP_32_REGISTERS_AVAILABLE = 18
const PF_AVX2_INSTRUCTIONS_AVAILABLE = 40
const PF_AVX512F_INSTRUCTIONS_AVAILABLE = 41
const PF_AVX_INSTRUCTIONS_AVAILABLE = 39
const PF_BAN = 21
const PF_CCITT = 10
const PF_CHANNELS_ENABLED = 16
const PF_CHAOS = 5
const PF_COMPARE64_EXCHANGE128 = 15
const PF_COMPARE_EXCHANGE128 = 14
const PF_COMPARE_EXCHANGE_DOUBLE = 2
const PF_DATAKIT = 9
const PF_DECnet = 12
const PF_DLI = 13
const PF_ECMA = 8
const PF_ERMS_AVAILABLE = 42
const PF_FASTFAIL_AVAILABLE = 23
const PF_FIREFOX = 19
const PF_FLOATING_POINT_EMULATED = 1
const PF_FLOATING_POINT_PRECISION_ERRATA = 0
const PF_HYLINK = 15
const PF_IMPLINK = 3
const PF_INET = 2
const PF_IPX = 6
const PF_ISO = 7
const PF_LAT = 14
const PF_MAX = 22
const PF_MMX_INSTRUCTIONS_AVAILABLE = 3
const PF_MONITORX_INSTRUCTION_AVAILABLE = 35
const PF_NS = 6
const PF_NX_ENABLED = 12
const PF_OSI = 7
const PF_PAE_ENABLED = 9
const PF_PPC_MOVEMEM_64BIT_OK = 4
const PF_PUP = 4
const PF_RDPID_INSTRUCTION_AVAILABLE = 33
const PF_RDRAND_INSTRUCTION_AVAILABLE = 28
const PF_RDTSCP_INSTRUCTION_AVAILABLE = 32
const PF_RDTSC_INSTRUCTION_AVAILABLE = 8
const PF_RDWRFSGSBASE_AVAILABLE = 22
const PF_SECOND_LEVEL_ADDRESS_TRANSLATION = 20
const PF_SNA = 11
const PF_SSE3_INSTRUCTIONS_AVAILABLE = 13
const PF_SSE4_1_INSTRUCTIONS_AVAILABLE = 37
const PF_SSE4_2_INSTRUCTIONS_AVAILABLE = 38
const PF_SSE_DAZ_MODE_AVAILABLE = 11
const PF_SSSE3_INSTRUCTIONS_AVAILABLE = 36
const PF_UNIX = 1
const PF_UNKNOWN1 = 20
const PF_UNSPEC = 0
const PF_VIRT_FIRMWARE_ENABLED = 21
const PF_VOICEVIEW = 18
const PF_XMMI64_INSTRUCTIONS_AVAILABLE = 10
const PF_XMMI_INSTRUCTIONS_AVAILABLE = 6
const PF_XSAVE_ENABLED = 17
const PGET_MODULE_HANDLE_EX = 0
const PGHDR_CLEAN = 1
const PGHDR_DIRTY = 2
const PGHDR_DONT_WRITE = 16
const PGHDR_MMAP = 32
const PGHDR_NEED_SYNC = 8
const PGHDR_WAL_APPEND = 64
const PGHDR_WRITEABLE = 4
const PHYSICALHEIGHT = 111
const PHYSICALOFFSETX = 112
const PHYSICALOFFSETY = 113
const PHYSICALWIDTH = 110
const PIDDI_THUMBNAIL = 2
const PIDDSI_BYTECOUNT = 4
const PIDDSI_CATEGORY = 2
const PIDDSI_COMPANY = 15
const PIDDSI_DOCPARTS = 13
const PIDDSI_HEADINGPAIR = 12
const PIDDSI_HIDDENCOUNT = 9
const PIDDSI_LINECOUNT = 5
const PIDDSI_LINKSDIRTY = 16
const PIDDSI_MANAGER = 14
const PIDDSI_MMCLIPCOUNT = 10
const PIDDSI_NOTECOUNT = 8
const PIDDSI_PARCOUNT = 6
const PIDDSI_PRESFORMAT = 3
const PIDDSI_SCALE = 11
const PIDDSI_SLIDECOUNT = 7
const PIDMSI_COPYRIGHT = 11
const PIDMSI_EDITOR = 2
const PIDMSI_OWNER = 8
const PIDMSI_PRODUCTION = 10
const PIDMSI_PROJECT = 6
const PIDMSI_RATING = 9
const PIDMSI_SEQUENCE_NO = 5
const PIDMSI_SOURCE = 4
const PIDMSI_STATUS = 7
const PIDMSI_SUPPLIER = 3
const PIDSI_APPNAME = 18
const PIDSI_AUTHOR = 4
const PIDSI_CHARCOUNT = 16
const PIDSI_COMMENTS = 6
const PIDSI_CREATE_DTM = 12
const PIDSI_DOC_SECURITY = 19
const PIDSI_EDITTIME = 10
const PIDSI_KEYWORDS = 5
const PIDSI_LASTAUTHOR = 8
const PIDSI_LASTPRINTED = 11
const PIDSI_LASTSAVE_DTM = 13
const PIDSI_PAGECOUNT = 14
const PIDSI_REVNUMBER = 9
const PIDSI_SUBJECT = 3
const PIDSI_TEMPLATE = 7
const PIDSI_THUMBNAIL = 17
const PIDSI_TITLE = 2
const PIDSI_WORDCOUNT = 15
const PID_BEHAVIOR = 2147483651
const PID_CODEPAGE = 1
const PID_DICTIONARY = 0
const PID_FIRST_NAME_DEFAULT = 4095
const PID_FIRST_USABLE = 2
const PID_ILLEGAL = 4294967295
const PID_LOCALE = 2147483648
const PID_MAX_READONLY = 3221225471
const PID_MIN_READONLY = 2147483648
const PID_MODIFY_TIME = 2147483649
const PID_SECURITY = 2147483650
const PIPE_ACCEPT_REMOTE_CLIENTS = 0
const PIPE_ACCESS_DUPLEX = 3
const PIPE_ACCESS_INBOUND = 1
const PIPE_ACCESS_OUTBOUND = 2
const PIPE_CLIENT_END = 0
const PIPE_NOWAIT = 1
const PIPE_READMODE_BYTE = 0
const PIPE_READMODE_MESSAGE = 2
const PIPE_REJECT_REMOTE_CLIENTS = 8
const PIPE_SERVER_END = 1
const PIPE_TYPE_BYTE = 0
const PIPE_TYPE_MESSAGE = 4
const PIPE_UNLIMITED_INSTANCES = 255
const PIPE_WAIT = 0
const PI_DOCFILECLSIDLOOKUP = 0
const PKCS12_ALLOW_OVERWRITE_KEY = 16384
const PKCS12_ALWAYS_CNG_KSP = 512
const PKCS12_CONFIG_REGPATH = "Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\PFX"
const PKCS12_DISABLE_ENCRYPT_CERTIFICATES = 256
const PKCS12_ENCRYPT_CERTIFICATES = 512
const PKCS12_ENCRYPT_CERTIFICATES_VALUE_NAME = "EncryptCertificates"
const PKCS12_EXPORT_ECC_CURVE_OID = 8192
const PKCS12_EXPORT_ECC_CURVE_PARAMETERS = 4096
const PKCS12_EXPORT_PBES2_PARAMS = 128
const PKCS12_EXPORT_RESERVED_MASK = 4294901760
const PKCS12_EXPORT_SILENT = 64
const PKCS12_IMPORT_RESERVED_MASK = 4294901760
const PKCS12_IMPORT_SILENT = 64
const PKCS12_INCLUDE_EXTENDED_PROPERTIES = 16
const PKCS12_NO_PERSIST_KEY = 32768
const PKCS12_OBJECT_LOCATOR_ALL_IMPORT_FLAGS = 33360
const PKCS12_ONLY_CERTIFICATES = 1024
const PKCS12_ONLY_CERTIFICATES_CONTAINER_NAME = "PfxContainer"
const PKCS12_ONLY_CERTIFICATES_PROVIDER_NAME = "PfxProvider"
const PKCS12_ONLY_CERTIFICATES_PROVIDER_TYPE = 0
const PKCS12_ONLY_NOT_ENCRYPTED_CERTIFICATES = 2048
const PKCS12_PBES2_ALG_AES256_SHA256 = "AES256-SHA256"
const PKCS12_PBKDF2_ID_HMAC_SHA1 = "1.2.840.113549.2.7"
const PKCS12_PBKDF2_ID_HMAC_SHA256 = "1.2.840.113549.2.9"
const PKCS12_PBKDF2_ID_HMAC_SHA384 = "1.2.840.113549.2.10"
const PKCS12_PBKDF2_ID_HMAC_SHA512 = "1.2.840.113549.2.11"
const PKCS12_PREFER_CNG_KSP = 256
const PKCS12_PROTECT_TO_DOMAIN_SIDS = 32
const PKCS12_VIRTUAL_ISOLATION_KEY = 65536
const PKCS5_PADDING = 1
const PKCS_7_ASN_ENCODING = 65536
const PKCS_7_NDR_ENCODING = 131072
const PKCS_RSA_SSA_PSS_TRAILER_FIELD_BC = 1
const PLAINTEXTKEYBLOB = 8
const PLANES = 14
const PLOSS = 6
const PMB_ACTIVE = 1
const PME_CURRENT_VERSION = 1
const PME_FAILFAST_ON_COMMIT_FAIL_DISABLE = 0
const PME_FAILFAST_ON_COMMIT_FAIL_ENABLE = 1
const PM_NOREMOVE = 0
const PM_NOYIELD = 2
const PM_QS_INPUT = 470220800
const PM_QS_PAINT = 2097152
const PM_QS_POSTMESSAGE = 9961472
const PM_QS_SENDMESSAGE = 4194304
const PM_REMOVE = 1
const POINTER_DEVICE_PRODUCT_STRING_MAX = 520
const POINTER_FLAG_CANCELED = 32768
const POINTER_FLAG_CAPTURECHANGED = 2097152
const POINTER_FLAG_CONFIDENCE = 16384
const POINTER_FLAG_DOWN = 65536
const POINTER_FLAG_FIFTHBUTTON = 256
const POINTER_FLAG_FIRSTBUTTON = 16
const POINTER_FLAG_FOURTHBUTTON = 128
const POINTER_FLAG_HASTRANSFORM = 4194304
const POINTER_FLAG_HWHEEL = 1048576
const POINTER_FLAG_INCONTACT = 4
const POINTER_FLAG_INRANGE = 2
const POINTER_FLAG_NEW = 1
const POINTER_FLAG_NONE = 0
const POINTER_FLAG_PRIMARY = 8192
const POINTER_FLAG_SECONDBUTTON = 32
const POINTER_FLAG_THIRDBUTTON = 64
const POINTER_FLAG_UP = 262144
const POINTER_FLAG_UPDATE = 131072
const POINTER_FLAG_WHEEL = 524288
const POINTER_MESSAGE_FLAG_CANCELED = 32768
const POINTER_MESSAGE_FLAG_CONFIDENCE = 16384
const POINTER_MESSAGE_FLAG_FIFTHBUTTON = 256
const POINTER_MESSAGE_FLAG_FIRSTBUTTON = 16
const POINTER_MESSAGE_FLAG_FOURTHBUTTON = 128
const POINTER_MESSAGE_FLAG_INCONTACT = 4
const POINTER_MESSAGE_FLAG_INRANGE = 2
const POINTER_MESSAGE_FLAG_NEW = 1
const POINTER_MESSAGE_FLAG_PRIMARY = 8192
const POINTER_MESSAGE_FLAG_SECONDBUTTON = 32
const POINTER_MESSAGE_FLAG_THIRDBUTTON = 64
const POINTER_MOD_CTRL = 8
const POINTER_MOD_SHIFT = 4
const POLICY_AUDIT_SUBCATEGORY_COUNT = 56
const POLICY_SHOWREASONUI_ALWAYS = 1
const POLICY_SHOWREASONUI_NEVER = 0
const POLICY_SHOWREASONUI_SERVERONLY = 3
const POLICY_SHOWREASONUI_WORKSTATIONONLY = 2
const POLYFILL_LAST = 2
const POLYGONALCAPS = 32
const POPENCARDNAMEA_EX = 0
const POPENCARDNAMEW_EX = 0
const POPENCARDNAME_A = 0
const POPENCARDNAME_W = 0
const PORT_STATUS_DOOR_OPEN = 7
const PORT_STATUS_NO_TONER = 6
const PORT_STATUS_OFFLINE = 1
const PORT_STATUS_OUTPUT_BIN_FULL = 4
const PORT_STATUS_OUT_OF_MEMORY = 9
const PORT_STATUS_PAPER_JAM = 2
const PORT_STATUS_PAPER_OUT = 3
const PORT_STATUS_PAPER_PROBLEM = 5
const PORT_STATUS_POWER_SAVE = 12
const PORT_STATUS_TONER_LOW = 10
const PORT_STATUS_TYPE_ERROR = 1
const PORT_STATUS_TYPE_INFO = 3
const PORT_STATUS_TYPE_WARNING = 2
const PORT_STATUS_USER_INTERVENTION = 8
const PORT_STATUS_WARMING_UP = 11
const PORT_TYPE_NET_ATTACHED = 8
const PORT_TYPE_READ = 2
const PORT_TYPE_REDIRECTED = 4
const PORT_TYPE_WRITE = 1
const POSTSCRIPT_DATA = 37
const POSTSCRIPT_IDENTIFY = 4117
const POSTSCRIPT_IGNORE = 38
const POSTSCRIPT_INJECTION = 4118
const POSTSCRIPT_PASSTHROUGH = 4115
const POWERBUTTON_ACTION_INDEX_HIBERNATE = 2
const POWERBUTTON_ACTION_INDEX_NOTHING = 0
const POWERBUTTON_ACTION_INDEX_SHUTDOWN = 3
const POWERBUTTON_ACTION_INDEX_SLEEP = 1
const POWERBUTTON_ACTION_VALUE_HIBERNATE = 3
const POWERBUTTON_ACTION_VALUE_NOTHING = 0
const POWERBUTTON_ACTION_VALUE_SHUTDOWN = 6
const POWERBUTTON_ACTION_VALUE_SLEEP = 2
const POWER_ACTION_CRITICAL = 2147483648
const POWER_ACTION_DISABLE_WAKES = 1073741824
const POWER_ACTION_HIBERBOOT = 8
const POWER_ACTION_LIGHTEST_FIRST = 268435456
const POWER_ACTION_LOCK_CONSOLE = 536870912
const POWER_ACTION_OVERRIDE_APPS = 4
const POWER_ACTION_PSEUDO_TRANSITION = 134217728
const POWER_ACTION_QUERY_ALLOWED = 1
const POWER_ACTION_UI_ALLOWED = 2
const POWER_DEVICE_IDLE_POLICY_CONSERVATIVE = 1
const POWER_DEVICE_IDLE_POLICY_PERFORMANCE = 0
const POWER_FORCE_TRIGGER_RESET = 2147483648
const POWER_LEVEL_USER_NOTIFY_EXEC = 4
const POWER_LEVEL_USER_NOTIFY_SOUND = 2
const POWER_LEVEL_USER_NOTIFY_TEXT = 1
const POWER_PLATFORM_ROLE_V1 = 1
const POWER_PLATFORM_ROLE_V1_MAX = 1
const POWER_PLATFORM_ROLE_V2 = 2
const POWER_PLATFORM_ROLE_V2_MAX = 1
const POWER_PLATFORM_ROLE_VERSION = 2
const POWER_PLATFORM_ROLE_VERSION_MAX = 1
const POWER_REQUEST_CONTEXT_DETAILED_STRING = 2
const POWER_REQUEST_CONTEXT_SIMPLE_STRING = 1
const POWER_REQUEST_CONTEXT_VERSION = 0
const POWER_SETTING_VALUE_VERSION = 1
const POWER_SYSTEM_MAXIMUM = 7
const POWER_USER_NOTIFY_BUTTON = 8
const POWER_USER_NOTIFY_FORCED_SHUTDOWN = 32
const POWER_USER_NOTIFY_SHUTDOWN = 16
const PO_DELETE = 19
const PO_PORTCHANGE = 32
const PO_RENAME = 20
const PO_REN_PORT = 52
const PO_THROTTLE_ADAPTIVE = 3
const PO_THROTTLE_CONSTANT = 1
const PO_THROTTLE_DEGRADE = 2
const PO_THROTTLE_MAXIMUM = 4
const PO_THROTTLE_NONE = 0
const PPM_FIRMWARE_ACPI1C2 = 1
const PPM_FIRMWARE_ACPI1C3 = 2
const PPM_FIRMWARE_ACPI1TSTATES = 4
const PPM_FIRMWARE_CPC = 262144
const PPM_FIRMWARE_CSD = 16
const PPM_FIRMWARE_CST = 8
const PPM_FIRMWARE_OSC = 65536
const PPM_FIRMWARE_PCCH = 16384
const PPM_FIRMWARE_PCCP = 32768
const PPM_FIRMWARE_PCT = 32
const PPM_FIRMWARE_PDC = 131072
const PPM_FIRMWARE_PPC = 256
const PPM_FIRMWARE_PSD = 512
const PPM_FIRMWARE_PSS = 64
const PPM_FIRMWARE_PTC = 1024
const PPM_FIRMWARE_TPC = 4096
const PPM_FIRMWARE_TSD = 8192
const PPM_FIRMWARE_TSS = 2048
const PPM_FIRMWARE_XPSS = 128
const PPM_IDLE_IMPLEMENTATION_CSTATES = 1
const PPM_IDLE_IMPLEMENTATION_NONE = 0
const PPM_IDLE_IMPLEMENTATION_PEP = 2
const PPM_PERFORMANCE_IMPLEMENTATION_CPPC = 3
const PPM_PERFORMANCE_IMPLEMENTATION_NONE = 0
const PPM_PERFORMANCE_IMPLEMENTATION_PCCV1 = 2
const PPM_PERFORMANCE_IMPLEMENTATION_PEP = 4
const PPM_PERFORMANCE_IMPLEMENTATION_PSTATES = 1
const PP_ADMIN_PIN = 31
const PP_APPLI_CERT = 18
const PP_CERTCHAIN = 9
const PP_CHANGE_PASSWORD = 7
const PP_CLIENT_HWND = 1
const PP_CONTAINER = 6
const PP_CONTEXT_INFO = 11
const PP_CRYPT_COUNT_KEY_USE = 41
const PP_DELETEKEY = 24
const PP_DISPLAYERRORS = 1
const PP_ENUMALGS = 1
const PP_ENUMALGS_EX = 22
const PP_ENUMCONTAINERS = 2
const PP_ENUMELECTROOTS = 26
const PP_ENUMEX_SIGNING_PROT = 40
const PP_ENUMMANDROOTS = 25
const PP_IMPTYPE = 3
const PP_KEYEXCHANGE_ALG = 14
const PP_KEYEXCHANGE_KEYSIZE = 12
const PP_KEYEXCHANGE_PIN = 32
const PP_KEYSET_SEC_DESCR = 8
const PP_KEYSET_TYPE = 27
const PP_KEYSPEC = 39
const PP_KEYSTORAGE = 17
const PP_KEYX_KEYSIZE_INC = 35
const PP_KEY_TYPE_SUBTYPE = 10
const PP_NAME = 4
const PP_PIN_PROMPT_STRING = 44
const PP_PROVTYPE = 16
const PP_ROOT_CERTSTORE = 46
const PP_SECURE_KEYEXCHANGE_PIN = 47
const PP_SECURE_SIGNATURE_PIN = 48
const PP_SESSION_KEYSIZE = 20
const PP_SGC_INFO = 37
const PP_SIGNATURE_ALG = 15
const PP_SIGNATURE_KEYSIZE = 13
const PP_SIGNATURE_PIN = 33
const PP_SIG_KEYSIZE_INC = 34
const PP_SMARTCARD_GUID = 45
const PP_SMARTCARD_READER = 43
const PP_SMARTCARD_READER_ICON = 47
const PP_SYM_KEYSIZE = 19
const PP_UI_PROMPT = 21
const PP_UNIQUE_CONTAINER = 36
const PP_USER_CERTSTORE = 42
const PP_USE_HARDWARE_RNG = 38
const PP_VERSION = 5
const PRAGMA_DEPRECATED_DDK = 0
const PREFERRED_SCHEMA_TABLE = "sqlite_schema"
const PREFERRED_TEMP_SCHEMA_TABLE = "sqlite_temp_schema"
const PRF_CHECKVISIBLE = 1
const PRF_CHILDREN = 16
const PRF_CLIENT = 4
const PRF_ERASEBKGND = 8
const PRF_NONCLIENT = 2
const PRF_OWNED = 32
const PRINTACTION_DOCUMENTDEFAULTS = 6
const PRINTACTION_NETINSTALL = 2
const PRINTACTION_NETINSTALLLINK = 3
const PRINTACTION_OPEN = 0
const PRINTACTION_OPENNETPRN = 5
const PRINTACTION_PROPERTIES = 1
const PRINTACTION_SERVERPROPERTIES = 7
const PRINTACTION_TESTPAGE = 4
const PRINTDLGEXORD = 1549
const PRINTDLGORD = 1538
const PRINTER_ACCESS_ADMINISTER = 4
const PRINTER_ACCESS_USE = 8
const PRINTER_ALL_ACCESS = 983052
const PRINTER_ATTRIBUTE_DEFAULT = 4
const PRINTER_ATTRIBUTE_DIRECT = 2
const PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST = 512
const PRINTER_ATTRIBUTE_ENABLE_BIDI = 2048
const PRINTER_ATTRIBUTE_ENABLE_DEVQ = 128
const PRINTER_ATTRIBUTE_FAX = 16384
const PRINTER_ATTRIBUTE_HIDDEN = 32
const PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS = 256
const PRINTER_ATTRIBUTE_LOCAL = 64
const PRINTER_ATTRIBUTE_NETWORK = 16
const PRINTER_ATTRIBUTE_PUBLISHED = 8192
const PRINTER_ATTRIBUTE_QUEUED = 1
const PRINTER_ATTRIBUTE_RAW_ONLY = 4096
const PRINTER_ATTRIBUTE_SHARED = 8
const PRINTER_ATTRIBUTE_TS = 32768
const PRINTER_ATTRIBUTE_WORK_OFFLINE = 1024
const PRINTER_CHANGE_ADD_FORM = 65536
const PRINTER_CHANGE_ADD_JOB = 256
const PRINTER_CHANGE_ADD_PORT = 1048576
const PRINTER_CHANGE_ADD_PRINTER = 1
const PRINTER_CHANGE_ADD_PRINTER_DRIVER = 268435456
const PRINTER_CHANGE_ADD_PRINT_PROCESSOR = 16777216
const PRINTER_CHANGE_ALL = 2004353023
const PRINTER_CHANGE_CONFIGURE_PORT = 2097152
const PRINTER_CHANGE_DELETE_FORM = 262144
const PRINTER_CHANGE_DELETE_JOB = 1024
const PRINTER_CHANGE_DELETE_PORT = 4194304
const PRINTER_CHANGE_DELETE_PRINTER = 4
const PRINTER_CHANGE_DELETE_PRINTER_DRIVER = 1073741824
const PRINTER_CHANGE_DELETE_PRINT_PROCESSOR = 67108864
const PRINTER_CHANGE_FAILED_CONNECTION_PRINTER = 8
const PRINTER_CHANGE_FORM = 458752
const PRINTER_CHANGE_JOB = 65280
const PRINTER_CHANGE_PORT = 7340032
const PRINTER_CHANGE_PRINTER = 255
const PRINTER_CHANGE_PRINTER_DRIVER = 1879048192
const PRINTER_CHANGE_PRINT_PROCESSOR = 117440512
const PRINTER_CHANGE_SET_FORM = 131072
const PRINTER_CHANGE_SET_JOB = 512
const PRINTER_CHANGE_SET_PRINTER = 2
const PRINTER_CHANGE_SET_PRINTER_DRIVER = 536870912
const PRINTER_CHANGE_TIMEOUT = 2147483648
const PRINTER_CHANGE_WRITE_JOB = 2048
const PRINTER_CONNECTION_MISMATCH = 32
const PRINTER_CONNECTION_NO_UI = 64
const PRINTER_CONTROL_PAUSE = 1
const PRINTER_CONTROL_PURGE = 3
const PRINTER_CONTROL_RESUME = 2
const PRINTER_CONTROL_SET_STATUS = 4
const PRINTER_ENUM_CONNECTIONS = 4
const PRINTER_ENUM_CONTAINER = 32768
const PRINTER_ENUM_DEFAULT = 1
const PRINTER_ENUM_EXPAND = 16384
const PRINTER_ENUM_FAVORITE = 4
const PRINTER_ENUM_HIDE = 16777216
const PRINTER_ENUM_ICON1 = 65536
const PRINTER_ENUM_ICON2 = 131072
const PRINTER_ENUM_ICON3 = 262144
const PRINTER_ENUM_ICON4 = 524288
const PRINTER_ENUM_ICON5 = 1048576
const PRINTER_ENUM_ICON6 = 2097152
const PRINTER_ENUM_ICON7 = 4194304
const PRINTER_ENUM_ICON8 = 8388608
const PRINTER_ENUM_ICONMASK = 16711680
const PRINTER_ENUM_LOCAL = 2
const PRINTER_ENUM_NAME = 8
const PRINTER_ENUM_NETWORK = 64
const PRINTER_ENUM_REMOTE = 16
const PRINTER_ENUM_SHARED = 32
const PRINTER_ERROR_INFORMATION = 2147483648
const PRINTER_ERROR_JAM = 2
const PRINTER_ERROR_OUTOFPAPER = 1
const PRINTER_ERROR_OUTOFTONER = 4
const PRINTER_ERROR_SEVERE = 536870912
const PRINTER_ERROR_WARNING = 1073741824
const PRINTER_EXECUTE = 131080
const PRINTER_FONTTYPE = 16384
const PRINTER_NOTIFY_FIELD_ATTRIBUTES = 13
const PRINTER_NOTIFY_FIELD_AVERAGE_PPM = 21
const PRINTER_NOTIFY_FIELD_BYTES_PRINTED = 25
const PRINTER_NOTIFY_FIELD_CJOBS = 20
const PRINTER_NOTIFY_FIELD_COMMENT = 5
const PRINTER_NOTIFY_FIELD_DATATYPE = 11
const PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY = 15
const PRINTER_NOTIFY_FIELD_DEVMODE = 7
const PRINTER_NOTIFY_FIELD_DRIVER_NAME = 4
const PRINTER_NOTIFY_FIELD_LOCATION = 6
const PRINTER_NOTIFY_FIELD_OBJECT_GUID = 26
const PRINTER_NOTIFY_FIELD_PAGES_PRINTED = 23
const PRINTER_NOTIFY_FIELD_PARAMETERS = 10
const PRINTER_NOTIFY_FIELD_PORT_NAME = 3
const PRINTER_NOTIFY_FIELD_PRINTER_NAME = 1
const PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR = 9
const PRINTER_NOTIFY_FIELD_PRIORITY = 14
const PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR = 12
const PRINTER_NOTIFY_FIELD_SEPFILE = 8
const PRINTER_NOTIFY_FIELD_SERVER_NAME = 0
const PRINTER_NOTIFY_FIELD_SHARE_NAME = 2
const PRINTER_NOTIFY_FIELD_START_TIME = 16
const PRINTER_NOTIFY_FIELD_STATUS = 18
const PRINTER_NOTIFY_FIELD_STATUS_STRING = 19
const PRINTER_NOTIFY_FIELD_TOTAL_BYTES = 24
const PRINTER_NOTIFY_FIELD_TOTAL_PAGES = 22
const PRINTER_NOTIFY_FIELD_UNTIL_TIME = 17
const PRINTER_NOTIFY_INFO_DISCARDED = 1
const PRINTER_NOTIFY_OPTIONS_REFRESH = 1
const PRINTER_NOTIFY_TYPE = 0
const PRINTER_READ = 131080
const PRINTER_STATUS_BUSY = 512
const PRINTER_STATUS_DOOR_OPEN = 4194304
const PRINTER_STATUS_ERROR = 2
const PRINTER_STATUS_INITIALIZING = 32768
const PRINTER_STATUS_IO_ACTIVE = 256
const PRINTER_STATUS_MANUAL_FEED = 32
const PRINTER_STATUS_NOT_AVAILABLE = 4096
const PRINTER_STATUS_NO_TONER = 262144
const PRINTER_STATUS_OFFLINE = 128
const PRINTER_STATUS_OUTPUT_BIN_FULL = 2048
const PRINTER_STATUS_OUT_OF_MEMORY = 2097152
const PRINTER_STATUS_PAGE_PUNT = 524288
const PRINTER_STATUS_PAPER_JAM = 8
const PRINTER_STATUS_PAPER_OUT = 16
const PRINTER_STATUS_PAPER_PROBLEM = 64
const PRINTER_STATUS_PAUSED = 1
const PRINTER_STATUS_PENDING_DELETION = 4
const PRINTER_STATUS_POWER_SAVE = 16777216
const PRINTER_STATUS_PRINTING = 1024
const PRINTER_STATUS_PROCESSING = 16384
const PRINTER_STATUS_SERVER_UNKNOWN = 8388608
const PRINTER_STATUS_TONER_LOW = 131072
const PRINTER_STATUS_USER_INTERVENTION = 1048576
const PRINTER_STATUS_WAITING = 8192
const PRINTER_STATUS_WARMING_UP = 65536
const PRINTER_WRITE = 131080
const PRINTRATEUNIT_CPS = 2
const PRINTRATEUNIT_IPM = 4
const PRINTRATEUNIT_LPM = 3
const PRINTRATEUNIT_PPM = 1
const PRINT_PROP_FORCE_NAME = 1
const PRIVATEKEYBLOB = 7
const PRIVATE_NAMESPACE_FLAG_DESTROY = 1
const PRIVILEGE_SET_ALL_NECESSARY = 1
const PRNSETUPDLGORD = 1539
const PROCESSOR_ALPHA_21064 = 21064
const PROCESSOR_AMD_X8664 = 8664
const PROCESSOR_ARCHITECTURE_ALPHA = 2
const PROCESSOR_ARCHITECTURE_ALPHA64 = 7
const PROCESSOR_ARCHITECTURE_AMD64 = 9
const PROCESSOR_ARCHITECTURE_ARM = 5
const PROCESSOR_ARCHITECTURE_ARM32_ON_WIN64 = 13
const PROCESSOR_ARCHITECTURE_ARM64 = 12
const PROCESSOR_ARCHITECTURE_IA32_ON_ARM64 = 14
const PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10
const PROCESSOR_ARCHITECTURE_IA64 = 6
const PROCESSOR_ARCHITECTURE_INTEL = 0
const PROCESSOR_ARCHITECTURE_MIPS = 1
const PROCESSOR_ARCHITECTURE_MSIL = 8
const PROCESSOR_ARCHITECTURE_NEUTRAL = 11
const PROCESSOR_ARCHITECTURE_PPC = 3
const PROCESSOR_ARCHITECTURE_SHX = 4
const PROCESSOR_ARCHITECTURE_UNKNOWN = 65535
const PROCESSOR_ARM720 = 1824
const PROCESSOR_ARM820 = 2080
const PROCESSOR_ARM920 = 2336
const PROCESSOR_ARM_7TDMI = 70001
const PROCESSOR_HITACHI_SH3 = 10003
const PROCESSOR_HITACHI_SH3E = 10004
const PROCESSOR_HITACHI_SH4 = 10005
const PROCESSOR_IDLESTATE_POLICY_COUNT = 3
const PROCESSOR_INTEL_386 = 386
const PROCESSOR_INTEL_486 = 486
const PROCESSOR_INTEL_IA64 = 2200
const PROCESSOR_INTEL_PENTIUM = 586
const PROCESSOR_MIPS_R4000 = 4000
const PROCESSOR_MOTOROLA_821 = 821
const PROCESSOR_OPTIL = 18767
const PROCESSOR_PERF_BOOST_MODE_AGGRESSIVE = 2
const PROCESSOR_PERF_BOOST_MODE_DISABLED = 0
const PROCESSOR_PERF_BOOST_MODE_EFFICIENT_AGGRESSIVE = 4
const PROCESSOR_PERF_BOOST_MODE_EFFICIENT_ENABLED = 3
const PROCESSOR_PERF_BOOST_MODE_ENABLED = 1
const PROCESSOR_PERF_BOOST_MODE_MAX = 4
const PROCESSOR_PERF_BOOST_POLICY_DISABLED = 0
const PROCESSOR_PERF_BOOST_POLICY_MAX = 100
const PROCESSOR_PPC_601 = 601
const PROCESSOR_PPC_603 = 603
const PROCESSOR_PPC_604 = 604
const PROCESSOR_PPC_620 = 620
const PROCESSOR_SHx_SH3 = 103
const PROCESSOR_SHx_SH4 = 104
const PROCESSOR_STRONGARM = 2577
const PROCESS_AFFINITY_ENABLE_AUTO_UPDATE = 1
const PROCESS_ALL_ACCESS = 2097151
const PROCESS_CREATE_PROCESS = 128
const PROCESS_CREATE_THREAD = 2
const PROCESS_CREATION_ALL_APPLICATION_PACKAGES_OPT_OUT = 1
const PROCESS_CREATION_CHILD_PROCESS_OVERRIDE = 2
const PROCESS_CREATION_CHILD_PROCESS_RESTRICTED = 1
const PROCESS_CREATION_CHILD_PROCESS_RESTRICTED_UNLESS_SECURE = 4
const PROCESS_CREATION_MITIGATION_POLICY2_ALLOW_DOWNGRADE_DYNAMIC_CODE_POLICY_ALWAYS_OFF = 2097152
const PROCESS_CREATION_MITIGATION_POLICY2_ALLOW_DOWNGRADE_DYNAMIC_CODE_POLICY_ALWAYS_ON = 1048576
const PROCESS_CREATION_MITIGATION_POLICY2_ALLOW_DOWNGRADE_DYNAMIC_CODE_POLICY_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_ALLOW_DOWNGRADE_DYNAMIC_CODE_POLICY_MASK = 3145728
const PROCESS_CREATION_MITIGATION_POLICY2_ALLOW_DOWNGRADE_DYNAMIC_CODE_POLICY_RESERVED = 3145728
const PROCESS_CREATION_MITIGATION_POLICY2_BLOCK_NON_CET_BINARIES_ALWAYS_OFF = 137438953472
const PROCESS_CREATION_MITIGATION_POLICY2_BLOCK_NON_CET_BINARIES_ALWAYS_ON = 68719476736
const PROCESS_CREATION_MITIGATION_POLICY2_BLOCK_NON_CET_BINARIES_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_BLOCK_NON_CET_BINARIES_MASK = 206158430208
const PROCESS_CREATION_MITIGATION_POLICY2_BLOCK_NON_CET_BINARIES_NON_EHCONT = 206158430208
const PROCESS_CREATION_MITIGATION_POLICY2_CET_DYNAMIC_APIS_OUT_OF_PROC_ONLY_ALWAYS_OFF = 562949953421312
const PROCESS_CREATION_MITIGATION_POLICY2_CET_DYNAMIC_APIS_OUT_OF_PROC_ONLY_ALWAYS_ON = 281474976710656
const PROCESS_CREATION_MITIGATION_POLICY2_CET_DYNAMIC_APIS_OUT_OF_PROC_ONLY_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_CET_DYNAMIC_APIS_OUT_OF_PROC_ONLY_MASK = 844424930131968
const PROCESS_CREATION_MITIGATION_POLICY2_CET_DYNAMIC_APIS_OUT_OF_PROC_ONLY_RESERVED = 844424930131968
const PROCESS_CREATION_MITIGATION_POLICY2_CET_USER_SHADOW_STACKS_ALWAYS_OFF = 536870912
const PROCESS_CREATION_MITIGATION_POLICY2_CET_USER_SHADOW_STACKS_ALWAYS_ON = 268435456
const PROCESS_CREATION_MITIGATION_POLICY2_CET_USER_SHADOW_STACKS_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_CET_USER_SHADOW_STACKS_MASK = 805306368
const PROCESS_CREATION_MITIGATION_POLICY2_CET_USER_SHADOW_STACKS_STRICT_MODE = 805306368
const PROCESS_CREATION_MITIGATION_POLICY2_LOADER_INTEGRITY_CONTINUITY_ALWAYS_OFF = 32
const PROCESS_CREATION_MITIGATION_POLICY2_LOADER_INTEGRITY_CONTINUITY_ALWAYS_ON = 16
const PROCESS_CREATION_MITIGATION_POLICY2_LOADER_INTEGRITY_CONTINUITY_AUDIT = 48
const PROCESS_CREATION_MITIGATION_POLICY2_LOADER_INTEGRITY_CONTINUITY_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_LOADER_INTEGRITY_CONTINUITY_MASK = 48
const PROCESS_CREATION_MITIGATION_POLICY2_MODULE_TAMPERING_PROTECTION_ALWAYS_OFF = 8192
const PROCESS_CREATION_MITIGATION_POLICY2_MODULE_TAMPERING_PROTECTION_ALWAYS_ON = 4096
const PROCESS_CREATION_MITIGATION_POLICY2_MODULE_TAMPERING_PROTECTION_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_MODULE_TAMPERING_PROTECTION_MASK = 12288
const PROCESS_CREATION_MITIGATION_POLICY2_MODULE_TAMPERING_PROTECTION_NOINHERIT = 12288
const PROCESS_CREATION_MITIGATION_POLICY2_RESTRICT_INDIRECT_BRANCH_PREDICTION_ALWAYS_OFF = 131072
const PROCESS_CREATION_MITIGATION_POLICY2_RESTRICT_INDIRECT_BRANCH_PREDICTION_ALWAYS_ON = 65536
const PROCESS_CREATION_MITIGATION_POLICY2_RESTRICT_INDIRECT_BRANCH_PREDICTION_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_RESTRICT_INDIRECT_BRANCH_PREDICTION_MASK = 196608
const PROCESS_CREATION_MITIGATION_POLICY2_RESTRICT_INDIRECT_BRANCH_PREDICTION_RESERVED = 196608
const PROCESS_CREATION_MITIGATION_POLICY2_SPECULATIVE_STORE_BYPASS_DISABLE_ALWAYS_OFF = 33554432
const PROCESS_CREATION_MITIGATION_POLICY2_SPECULATIVE_STORE_BYPASS_DISABLE_ALWAYS_ON = 16777216
const PROCESS_CREATION_MITIGATION_POLICY2_SPECULATIVE_STORE_BYPASS_DISABLE_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_SPECULATIVE_STORE_BYPASS_DISABLE_MASK = 50331648
const PROCESS_CREATION_MITIGATION_POLICY2_SPECULATIVE_STORE_BYPASS_DISABLE_RESERVED = 50331648
const PROCESS_CREATION_MITIGATION_POLICY2_STRICT_CONTROL_FLOW_GUARD_ALWAYS_OFF = 512
const PROCESS_CREATION_MITIGATION_POLICY2_STRICT_CONTROL_FLOW_GUARD_ALWAYS_ON = 256
const PROCESS_CREATION_MITIGATION_POLICY2_STRICT_CONTROL_FLOW_GUARD_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_STRICT_CONTROL_FLOW_GUARD_MASK = 768
const PROCESS_CREATION_MITIGATION_POLICY2_STRICT_CONTROL_FLOW_GUARD_RESERVED = 768
const PROCESS_CREATION_MITIGATION_POLICY2_USER_CET_SET_CONTEXT_IP_VALIDATION_ALWAYS_OFF = 8589934592
const PROCESS_CREATION_MITIGATION_POLICY2_USER_CET_SET_CONTEXT_IP_VALIDATION_ALWAYS_ON = 4294967296
const PROCESS_CREATION_MITIGATION_POLICY2_USER_CET_SET_CONTEXT_IP_VALIDATION_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY2_USER_CET_SET_CONTEXT_IP_VALIDATION_MASK = 12884901888
const PROCESS_CREATION_MITIGATION_POLICY2_USER_CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODE = 12884901888
const PROCESS_CREATION_MITIGATION_POLICY_AUDIT_NONSYSTEM_FONTS = 844424930131968
const PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALLOW_STORE = 52776558133248
const PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_OFF = 35184372088832
const PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON = 17592186044416
const PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_MASK = 52776558133248
const PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF = 131072
const PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_ON = 65536
const PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_MASK = 196608
const PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_RESERVED = 196608
const PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_OFF = 2199023255552
const PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON = 1099511627776
const PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_EXPORT_SUPPRESSION = 3298534883328
const PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_MASK = 3298534883328
const PROCESS_CREATION_MITIGATION_POLICY_DEP_ATL_THUNK_ENABLE = 2
const PROCESS_CREATION_MITIGATION_POLICY_DEP_ENABLE = 1
const PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_ALWAYS_OFF = 8589934592
const PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_ALWAYS_ON = 4294967296
const PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_MASK = 12884901888
const PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_RESERVED = 12884901888
const PROCESS_CREATION_MITIGATION_POLICY_FONT_DISABLE_ALWAYS_OFF = 562949953421312
const PROCESS_CREATION_MITIGATION_POLICY_FONT_DISABLE_ALWAYS_ON = 281474976710656
const PROCESS_CREATION_MITIGATION_POLICY_FONT_DISABLE_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_FONT_DISABLE_MASK = 844424930131968
const PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_ALWAYS_OFF = 512
const PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_ALWAYS_ON = 256
const PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_ALWAYS_ON_REQ_RELOCS = 768
const PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_MASK = 768
const PROCESS_CREATION_MITIGATION_POLICY_HEAP_TERMINATE_ALWAYS_OFF = 8192
const PROCESS_CREATION_MITIGATION_POLICY_HEAP_TERMINATE_ALWAYS_ON = 4096
const PROCESS_CREATION_MITIGATION_POLICY_HEAP_TERMINATE_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_HEAP_TERMINATE_MASK = 12288
const PROCESS_CREATION_MITIGATION_POLICY_HEAP_TERMINATE_RESERVED = 12288
const PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_ALWAYS_OFF = 2097152
const PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_ALWAYS_ON = 1048576
const PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_MASK = 3145728
const PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_RESERVED = 3145728
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_LOW_LABEL_ALWAYS_OFF = 144115188075855872
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_LOW_LABEL_ALWAYS_ON = 72057594037927936
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_LOW_LABEL_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_LOW_LABEL_MASK = 216172782113783808
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_LOW_LABEL_RESERVED = 216172782113783808
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_REMOTE_ALWAYS_OFF = 9007199254740992
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_REMOTE_ALWAYS_ON = 4503599627370496
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_REMOTE_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_REMOTE_MASK = 13510798882111488
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_NO_REMOTE_RESERVED = 13510798882111488
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_PREFER_SYSTEM32_ALWAYS_OFF = 2305843009213693952
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_PREFER_SYSTEM32_ALWAYS_ON = 1152921504606846976
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_PREFER_SYSTEM32_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_PREFER_SYSTEM32_MASK = 3458764513820540928
const PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_PREFER_SYSTEM32_RESERVED = 3458764513820540928
const PROCESS_CREATION_MITIGATION_POLICY_PROHIBIT_DYNAMIC_CODE_ALWAYS_OFF = 137438953472
const PROCESS_CREATION_MITIGATION_POLICY_PROHIBIT_DYNAMIC_CODE_ALWAYS_ON = 68719476736
const PROCESS_CREATION_MITIGATION_POLICY_PROHIBIT_DYNAMIC_CODE_ALWAYS_ON_ALLOW_OPT_OUT = 206158430208
const PROCESS_CREATION_MITIGATION_POLICY_PROHIBIT_DYNAMIC_CODE_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_PROHIBIT_DYNAMIC_CODE_MASK = 206158430208
const PROCESS_CREATION_MITIGATION_POLICY_SEHOP_ENABLE = 4
const PROCESS_CREATION_MITIGATION_POLICY_STRICT_HANDLE_CHECKS_ALWAYS_OFF = 33554432
const PROCESS_CREATION_MITIGATION_POLICY_STRICT_HANDLE_CHECKS_ALWAYS_ON = 16777216
const PROCESS_CREATION_MITIGATION_POLICY_STRICT_HANDLE_CHECKS_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_STRICT_HANDLE_CHECKS_MASK = 50331648
const PROCESS_CREATION_MITIGATION_POLICY_STRICT_HANDLE_CHECKS_RESERVED = 50331648
const PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_OFF = 536870912
const PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON = 268435456
const PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_DEFER = 0
const PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_MASK = 805306368
const PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_RESERVED = 805306368
const PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION = 2
const PROCESS_DEP_ENABLE = 1
const PROCESS_DUP_HANDLE = 64
const PROCESS_HEAP_ENTRY_BUSY = 4
const PROCESS_HEAP_ENTRY_DDESHARE = 32
const PROCESS_HEAP_ENTRY_MOVEABLE = 16
const PROCESS_HEAP_REGION = 1
const PROCESS_HEAP_SEG_ALLOC = 8
const PROCESS_HEAP_UNCOMMITTED_RANGE = 2
const PROCESS_LEAP_SECOND_INFO_FLAG_ENABLE_SIXTY_SECOND = 1
const PROCESS_LEAP_SECOND_INFO_VALID_FLAGS = 1
const PROCESS_MODE_BACKGROUND_BEGIN = 1048576
const PROCESS_MODE_BACKGROUND_END = 2097152
const PROCESS_NAME_NATIVE = 1
const PROCESS_POWER_THROTTLING_CURRENT_VERSION = 1
const PROCESS_POWER_THROTTLING_EXECUTION_SPEED = 1
const PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION = 4
const PROCESS_POWER_THROTTLING_VALID_FLAGS = 5
const PROCESS_QUERY_INFORMATION = 1024
const PROCESS_QUERY_LIMITED_INFORMATION = 4096
const PROCESS_SET_INFORMATION = 512
const PROCESS_SET_QUOTA = 256
const PROCESS_SET_SESSIONID = 4
const PROCESS_SUSPEND_RESUME = 2048
const PROCESS_TERMINATE = 1
const PROCESS_VM_OPERATION = 8
const PROCESS_VM_READ = 16
const PROCESS_VM_WRITE = 32
const PROC_IDLE_BUCKET_COUNT = 6
const PROC_IDLE_BUCKET_COUNT_EX = 16
const PROC_THREAD_ATTRIBUTE_ADDITIVE = 262144
const PROC_THREAD_ATTRIBUTE_ALL_APPLICATION_PACKAGES_POLICY = 131072
const PROC_THREAD_ATTRIBUTE_CHILD_PROCESS_POLICY = 131072
const PROC_THREAD_ATTRIBUTE_GROUP_AFFINITY = 196608
const PROC_THREAD_ATTRIBUTE_HANDLE_LIST = 131072
const PROC_THREAD_ATTRIBUTE_IDEAL_PROCESSOR = 196608
const PROC_THREAD_ATTRIBUTE_INPUT = 131072
const PROC_THREAD_ATTRIBUTE_JOB_LIST = 131072
const PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY = 131072
const PROC_THREAD_ATTRIBUTE_NUMBER = 65535
const PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 131072
const PROC_THREAD_ATTRIBUTE_PREFERRED_NODE = 131072
const PROC_THREAD_ATTRIBUTE_PROTECTION_LEVEL = 131072
const PROC_THREAD_ATTRIBUTE_REPLACE_VALUE = 1
const PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES = 131072
const PROC_THREAD_ATTRIBUTE_THREAD = 65536
const PROC_THREAD_ATTRIBUTE_UMS_THREAD = 196608
const PROC_THREAD_ATTRIBUTE_WIN32K_FILTER = 131072
const PRODUCT_ARM64_SERVER = 120
const PRODUCT_BUSINESS = 6
const PRODUCT_BUSINESS_N = 16
const PRODUCT_CLOUD_HOST_INFRASTRUCTURE_SERVER = 124
const PRODUCT_CLOUD_STORAGE_SERVER = 110
const PRODUCT_CLUSTER_SERVER = 18
const PRODUCT_CLUSTER_SERVER_V = 64
const PRODUCT_CONNECTED_CAR = 117
const PRODUCT_CORE = 101
const PRODUCT_CORE_ARM = 97
const PRODUCT_CORE_CONNECTED = 111
const PRODUCT_CORE_CONNECTED_COUNTRYSPECIFIC = 116
const PRODUCT_CORE_CONNECTED_N = 113
const PRODUCT_CORE_CONNECTED_SINGLELANGUAGE = 115
const PRODUCT_CORE_COUNTRYSPECIFIC = 99
const PRODUCT_CORE_LANGUAGESPECIFIC = 100
const PRODUCT_CORE_N = 98
const PRODUCT_CORE_SINGLELANGUAGE = 100
const PRODUCT_DATACENTER_EVALUATION_SERVER = 80
const PRODUCT_DATACENTER_SERVER = 8
const PRODUCT_DATACENTER_SERVER_CORE = 12
const PRODUCT_DATACENTER_SERVER_CORE_V = 39
const PRODUCT_DATACENTER_SERVER_V = 37
const PRODUCT_EDUCATION = 121
const PRODUCT_EDUCATION_N = 122
const PRODUCT_EMBEDDED = 65
const PRODUCT_EMBEDDED_A = 88
const PRODUCT_EMBEDDED_AUTOMOTIVE = 85
const PRODUCT_EMBEDDED_E = 90
const PRODUCT_EMBEDDED_EVAL = 107
const PRODUCT_EMBEDDED_E_EVAL = 108
const PRODUCT_EMBEDDED_INDUSTRY = 89
const PRODUCT_EMBEDDED_INDUSTRY_A = 86
const PRODUCT_EMBEDDED_INDUSTRY_A_E = 92
const PRODUCT_EMBEDDED_INDUSTRY_E = 91
const PRODUCT_EMBEDDED_INDUSTRY_EVAL = 105
const PRODUCT_EMBEDDED_INDUSTRY_E_EVAL = 106
const PRODUCT_ENTERPRISE = 4
const PRODUCT_ENTERPRISE_E = 70
const PRODUCT_ENTERPRISE_EVALUATION = 72
const PRODUCT_ENTERPRISE_N = 27
const PRODUCT_ENTERPRISE_N_EVALUATION = 84
const PRODUCT_ENTERPRISE_S = 125
const PRODUCT_ENTERPRISE_SERVER = 10
const PRODUCT_ENTERPRISE_SERVER_CORE = 14
const PRODUCT_ENTERPRISE_SERVER_CORE_V = 41
const PRODUCT_ENTERPRISE_SERVER_IA64 = 15
const PRODUCT_ENTERPRISE_SERVER_V = 38
const PRODUCT_ENTERPRISE_S_EVALUATION = 129
const PRODUCT_ENTERPRISE_S_N = 126
const PRODUCT_ENTERPRISE_S_N_EVALUATION = 130
const PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL = 60
const PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC = 62
const PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT = 59
const PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC = 61
const PRODUCT_HOME_BASIC = 2
const PRODUCT_HOME_BASIC_E = 67
const PRODUCT_HOME_BASIC_N = 5
const PRODUCT_HOME_PREMIUM = 3
const PRODUCT_HOME_PREMIUM_E = 68
const PRODUCT_HOME_PREMIUM_N = 26
const PRODUCT_HOME_PREMIUM_SERVER = 34
const PRODUCT_HOME_SERVER = 19
const PRODUCT_HYPERV = 42
const PRODUCT_ID_LENGTH = 16
const PRODUCT_INDUSTRY_HANDHELD = 118
const PRODUCT_IOTUAP = 123
const PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 30
const PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 32
const PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 31
const PRODUCT_MOBILE_CORE = 104
const PRODUCT_MOBILE_ENTERPRISE = 133
const PRODUCT_MULTIPOINT_PREMIUM_SERVER = 77
const PRODUCT_MULTIPOINT_STANDARD_SERVER = 76
const PRODUCT_NANO_SERVER = 109
const PRODUCT_PPI_PRO = 119
const PRODUCT_PROFESSIONAL = 48
const PRODUCT_PROFESSIONAL_E = 69
const PRODUCT_PROFESSIONAL_EMBEDDED = 58
const PRODUCT_PROFESSIONAL_N = 49
const PRODUCT_PROFESSIONAL_S = 127
const PRODUCT_PROFESSIONAL_STUDENT = 112
const PRODUCT_PROFESSIONAL_STUDENT_N = 114
const PRODUCT_PROFESSIONAL_S_N = 128
const PRODUCT_PROFESSIONAL_WMC = 103
const PRODUCT_SB_SOLUTION_SERVER = 50
const PRODUCT_SB_SOLUTION_SERVER_EM = 54
const PRODUCT_SERVER_FOR_SB_SOLUTIONS = 51
const PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM = 55
const PRODUCT_SERVER_FOR_SMALLBUSINESS = 24
const PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 35
const PRODUCT_SERVER_FOUNDATION = 33
const PRODUCT_SERVER_V = 37
const PRODUCT_SMALLBUSINESS_SERVER = 9
const PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = 25
const PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE = 63
const PRODUCT_SOLUTION_EMBEDDEDSERVER = 56
const PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE = 57
const PRODUCT_STANDARD_EVALUATION_SERVER = 79
const PRODUCT_STANDARD_SERVER = 7
const PRODUCT_STANDARD_SERVER_CORE = 13
const PRODUCT_STANDARD_SERVER_CORE_V = 40
const PRODUCT_STANDARD_SERVER_SOLUTIONS = 52
const PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE = 53
const PRODUCT_STANDARD_SERVER_V = 36
const PRODUCT_STARTER = 11
const PRODUCT_STARTER_E = 66
const PRODUCT_STARTER_N = 47
const PRODUCT_STORAGE_ENTERPRISE_SERVER = 23
const PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE = 46
const PRODUCT_STORAGE_EXPRESS_SERVER = 20
const PRODUCT_STORAGE_EXPRESS_SERVER_CORE = 43
const PRODUCT_STORAGE_STANDARD_EVALUATION_SERVER = 96
const PRODUCT_STORAGE_STANDARD_SERVER = 21
const PRODUCT_STORAGE_STANDARD_SERVER_CORE = 44
const PRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER = 95
const PRODUCT_STORAGE_WORKGROUP_SERVER = 22
const PRODUCT_STORAGE_WORKGROUP_SERVER_CORE = 45
const PRODUCT_THINPC = 87
const PRODUCT_ULTIMATE = 1
const PRODUCT_ULTIMATE_E = 71
const PRODUCT_ULTIMATE_N = 28
const PRODUCT_UNDEFINED = 0
const PRODUCT_UNLICENSED = 2882382797
const PRODUCT_WEB_SERVER = 17
const PRODUCT_WEB_SERVER_CORE = 29
const PROFILE_EMBEDDED = 77
const PROFILE_KERNEL = 536870912
const PROFILE_LINKED = 76
const PROFILE_SERVER = 1073741824
const PROFILE_USER = 268435456
const PROGRESS_CANCEL = 1
const PROGRESS_CONTINUE = 0
const PROGRESS_QUIET = 3
const PROGRESS_STOP = 2
const PROOF_QUALITY = 2
const PROPSETFLAG_ANSI = 2
const PROPSETFLAG_CASE_SENSITIVE = 8
const PROPSETFLAG_DEFAULT = 0
const PROPSETFLAG_NONSIMPLE = 1
const PROPSETFLAG_UNBUFFERED = 4
const PROPSETHDR_OSVERSION_UNKNOWN = 4294967295
const PROPSET_BEHAVIOR_CASE_SENSITIVE = 1
const PROPSHEETHEADER = 0
const PROPSHEETPAGE = 0
const PROPSHEETPAGE_LATEST = 0
const PROPSHEETPAGE_V1 = 0
const PROPSHEETPAGE_V2 = 0
const PROPSHEETPAGE_V3 = 0
const PROP_LG_CXDLG = 252
const PROP_LG_CYDLG = 218
const PROP_MED_CXDLG = 227
const PROP_MED_CYDLG = 215
const PROP_SM_CXDLG = 212
const PROP_SM_CYDLG = 188
const PROTECTED_DACL_SECURITY_INFORMATION = 2147483648
const PROTECTED_SACL_SECURITY_INFORMATION = 1073741824
const PROTECTION_LEVEL_ANTIMALWARE_LIGHT = 3
const PROTECTION_LEVEL_AUTHENTICODE = 7
const PROTECTION_LEVEL_CODEGEN_LIGHT = 6
const PROTECTION_LEVEL_LSA_LIGHT = 4
const PROTECTION_LEVEL_NONE = 4294967294
const PROTECTION_LEVEL_PPL_APP = 8
const PROTECTION_LEVEL_SAME = 4294967295
const PROTECTION_LEVEL_WINDOWS = 1
const PROTECTION_LEVEL_WINDOWS_LIGHT = 2
const PROTECTION_LEVEL_WINTCB = 5
const PROTECTION_LEVEL_WINTCB_LIGHT = 0
const PROTOCOLFLAG_NO_PICS_CHECK = 1
const PROVIDER_KEEPS_VALUE_LENGTH = 1
const PROV_DH_SCHANNEL = 18
const PROV_DSS = 3
const PROV_DSS_DH = 13
const PROV_EC_ECDSA_FULL = 16
const PROV_EC_ECDSA_SIG = 14
const PROV_EC_ECNRA_FULL = 17
const PROV_EC_ECNRA_SIG = 15
const PROV_FORTEZZA = 4
const PROV_INTEL_SEC = 22
const PROV_MS_EXCHANGE = 5
const PROV_REPLACE_OWF = 23
const PROV_RNG = 21
const PROV_RSA_AES = 24
const PROV_RSA_FULL = 1
const PROV_RSA_SCHANNEL = 12
const PROV_RSA_SIG = 2
const PROV_SPYRUS_LYNKS = 20
const PROV_SSL = 6
const PROV_STT_ACQ = 8
const PROV_STT_BRND = 9
const PROV_STT_ISS = 11
const PROV_STT_MER = 7
const PROV_STT_ROOT = 10
const PRPC_HTTP_TRANSPORT_CREDENTIALS = 0
const PRPC_SECURITY_QOS_V2 = 0
const PRPC_SECURITY_QOS_V3 = 0
const PRSPEC_INVALID = 4294967295
const PRSPEC_LPWSTR = 0
const PRSPEC_PROPID = 1
const PR_JOBSTATUS = 0
const PSBTN_APPLYNOW = 4
const PSBTN_BACK = 0
const PSBTN_CANCEL = 5
const PSBTN_FINISH = 2
const PSBTN_HELP = 6
const PSBTN_MAX = 6
const PSBTN_NEXT = 1
const PSBTN_OK = 3
const PSCARD_READERSTATE_A = 0
const PSCARD_READERSTATE_W = 0
const PSCB_BUTTONPRESSED = 3
const PSCB_INITIALIZED = 1
const PSCB_PRECREATE = 2
const PSD_DEFAULTMINMARGINS = 0
const PSD_DISABLEMARGINS = 16
const PSD_DISABLEORIENTATION = 256
const PSD_DISABLEPAGEPAINTING = 524288
const PSD_DISABLEPAPER = 512
const PSD_DISABLEPRINTER = 32
const PSD_ENABLEPAGEPAINTHOOK = 262144
const PSD_ENABLEPAGESETUPHOOK = 8192
const PSD_ENABLEPAGESETUPTEMPLATE = 32768
const PSD_ENABLEPAGESETUPTEMPLATEHANDLE = 131072
const PSD_INHUNDREDTHSOFMILLIMETERS = 8
const PSD_INTHOUSANDTHSOFINCHES = 4
const PSD_INWININIINTLMEASURE = 0
const PSD_MARGINS = 2
const PSD_MINMARGINS = 1
const PSD_NONETWORKBUTTON = 2097152
const PSD_NOWARNING = 128
const PSD_RETURNDEFAULT = 1024
const PSD_SHOWHELP = 2048
const PSEC_WINNT_AUTH_IDENTITY = 0
const PSH_DEFAULT = 0
const PSH_HASHELP = 512
const PSH_HEADER = 524288
const PSH_MODELESS = 1024
const PSH_NOAPPLYNOW = 128
const PSH_NOCONTEXTHELP = 33554432
const PSH_PROPSHEETPAGE = 8
const PSH_PROPTITLE = 1
const PSH_RTLREADING = 2048
const PSH_STRETCHWATERMARK = 262144
const PSH_USECALLBACK = 256
const PSH_USEHBMHEADER = 1048576
const PSH_USEHBMWATERMARK = 65536
const PSH_USEHICON = 2
const PSH_USEHPLWATERMARK = 131072
const PSH_USEICONID = 4
const PSH_USEPAGELANG = 2097152
const PSH_USEPSTARTPAGE = 64
const PSH_WATERMARK = 32768
const PSH_WIZARD = 32
const PSH_WIZARD97 = 16777216
const PSH_WIZARDCONTEXTHELP = 4096
const PSH_WIZARDHASFINISH = 16
const PSH_WIZARD_LITE = 4194304
const PSIDENT_GDICENTRIC = 0
const PSIDENT_PSCENTRIC = 1
const PSINJECT_BEGINDEFAULTS = 12
const PSINJECT_BEGINPAGESETUP = 101
const PSINJECT_BEGINPROLOG = 14
const PSINJECT_BEGINSETUP = 16
const PSINJECT_BEGINSTREAM = 1
const PSINJECT_BOUNDINGBOX = 9
const PSINJECT_COMMENTS = 11
const PSINJECT_DLFONT = 3722304989
const PSINJECT_DOCNEEDEDRES = 5
const PSINJECT_DOCSUPPLIEDRES = 6
const PSINJECT_DOCUMENTPROCESSCOLORS = 10
const PSINJECT_DOCUMENTPROCESSCOLORSATEND = 21
const PSINJECT_ENDDEFAULTS = 13
const PSINJECT_ENDPAGECOMMENTS = 107
const PSINJECT_ENDPAGESETUP = 102
const PSINJECT_ENDPROLOG = 15
const PSINJECT_ENDSETUP = 17
const PSINJECT_ENDSTREAM = 20
const PSINJECT_EOF = 19
const PSINJECT_ORIENTATION = 8
const PSINJECT_PAGEBBOX = 106
const PSINJECT_PAGENUMBER = 100
const PSINJECT_PAGEORDER = 7
const PSINJECT_PAGES = 4
const PSINJECT_PAGESATEND = 3
const PSINJECT_PAGETRAILER = 103
const PSINJECT_PLATECOLOR = 104
const PSINJECT_PSADOBE = 2
const PSINJECT_SHOWPAGE = 105
const PSINJECT_TRAILER = 18
const PSINJECT_VMRESTORE = 201
const PSINJECT_VMSAVE = 200
const PSM_ADDPAGE = 1127
const PSM_APPLY = 1134
const PSM_CANCELTOCLOSE = 1131
const PSM_CHANGED = 1128
const PSM_GETCURRENTPAGEHWND = 1142
const PSM_GETRESULT = 1159
const PSM_GETTABCONTROL = 1140
const PSM_HWNDTOINDEX = 1153
const PSM_IDTOINDEX = 1157
const PSM_INDEXTOHWND = 1154
const PSM_INDEXTOID = 1158
const PSM_INDEXTOPAGE = 1156
const PSM_INSERTPAGE = 1143
const PSM_ISDIALOGMESSAGE = 1141
const PSM_PAGETOINDEX = 1155
const PSM_PRESSBUTTON = 1137
const PSM_QUERYSIBLINGS = 1132
const PSM_REBOOTSYSTEM = 1130
const PSM_RECALCPAGESIZES = 1160
const PSM_REMOVEPAGE = 1126
const PSM_RESTARTWINDOWS = 1129
const PSM_SETCURSEL = 1125
const PSM_SETCURSELID = 1138
const PSM_SETFINISHTEXT = 1139
const PSM_SETFINISHTEXTA = 1139
const PSM_SETFINISHTEXTW = 1145
const PSM_SETHEADERSUBTITLE = 1151
const PSM_SETHEADERSUBTITLEA = 1151
const PSM_SETHEADERSUBTITLEW = 1152
const PSM_SETHEADERTITLE = 1149
const PSM_SETHEADERTITLEA = 1149
const PSM_SETHEADERTITLEW = 1150
const PSM_SETTITLE = 1135
const PSM_SETTITLEA = 1135
const PSM_SETTITLEW = 1144
const PSM_SETWIZBUTTONS = 1136
const PSM_UNCHANGED = 1133
const PSNRET_INVALID = 1
const PSNRET_INVALID_NOCHANGEPAGE = 2
const PSNRET_MESSAGEHANDLED = 3
const PSNRET_NOERROR = 0
const PSN_APPLY = 18446744073709551414
const PSN_FIRST = 18446744073709551416
const PSN_GETOBJECT = 18446744073709551406
const PSN_HELP = 18446744073709551411
const PSN_KILLACTIVE = 18446744073709551415
const PSN_LAST = 18446744073709551317
const PSN_QUERYCANCEL = 18446744073709551407
const PSN_QUERYINITIALFOCUS = 18446744073709551403
const PSN_RESET = 18446744073709551413
const PSN_SETACTIVE = 18446744073709551416
const PSN_TRANSLATEACCELERATOR = 18446744073709551404
const PSN_WIZBACK = 18446744073709551410
const PSN_WIZFINISH = 18446744073709551408
const PSN_WIZNEXT = 18446744073709551409
const PSPCB_ADDREF = 0
const PSPCB_CREATE = 2
const PSPCB_RELEASE = 1
const PSPROTOCOL_ASCII = 0
const PSPROTOCOL_BCP = 1
const PSPROTOCOL_BINARY = 3
const PSPROTOCOL_TBCP = 2
const PSP_DEFAULT = 0
const PSP_DLGINDIRECT = 1
const PSP_HASHELP = 32
const PSP_HIDEHEADER = 2048
const PSP_PREMATURE = 1024
const PSP_RTLREADING = 16
const PSP_USECALLBACK = 128
const PSP_USEFUSIONCONTEXT = 16384
const PSP_USEHEADERSUBTITLE = 8192
const PSP_USEHEADERTITLE = 4096
const PSP_USEHICON = 2
const PSP_USEICONID = 4
const PSP_USEREFPARENT = 64
const PSP_USETITLE = 8
const PSWIZB_BACK = 1
const PSWIZB_DISABLEDFINISH = 8
const PSWIZB_FINISH = 4
const PSWIZB_NEXT = 2
const PS_ALTERNATE = 8
const PS_COSMETIC = 0
const PS_DASH = 1
const PS_DASHDOT = 3
const PS_DASHDOTDOT = 4
const PS_DOT = 2
const PS_ENDCAP_FLAT = 512
const PS_ENDCAP_MASK = 3840
const PS_ENDCAP_ROUND = 0
const PS_ENDCAP_SQUARE = 256
const PS_GEOMETRIC = 65536
const PS_INSIDEFRAME = 6
const PS_JOIN_BEVEL = 4096
const PS_JOIN_MASK = 61440
const PS_JOIN_MITER = 8192
const PS_JOIN_ROUND = 0
const PS_NULL = 5
const PS_OPENTYPE_FONTTYPE = 65536
const PS_SOLID = 0
const PS_STYLE_MASK = 15
const PS_TYPE_MASK = 983040
const PS_USERSTYLE = 7
const PTF_INTKEY = 1
const PTF_LEAF = 8
const PTF_LEAFDATA = 4
const PTF_ZERODATA = 2
const PTRMAP_BTREE = 5
const PTRMAP_FREEPAGE = 2
const PTRMAP_OVERFLOW1 = 3
const PTRMAP_OVERFLOW2 = 4
const PTRMAP_ROOTPAGE = 1
const PT_BEZIERTO = 4
const PT_CLOSEFIGURE = 1
const PT_LINETO = 2
const PT_MOVETO = 6
const PUBLICKEYBLOB = 6
const PUBLICKEYBLOBEX = 10
const PURGE_RXABORT = 2
const PURGE_RXCLEAR = 8
const PURGE_TXABORT = 1
const PURGE_TXCLEAR = 4
const PWR_CRITICALRESUME = 3
const PWR_FAIL = -1
const PWR_OK = 1
const PWR_SUSPENDREQUEST = 1
const PWR_SUSPENDRESUME = 2
const PW_CLIENTONLY = 1
const PW_RENDERFULLCONTENT = 2
const P_DETACH = 4
const P_NOWAIT = 1
const P_NOWAITO = 3
const P_OVERLAY = 2
const P_WAIT = 0
const P_tmpdir = "_P_tmpdir"
const PageSetupDlg = 0
const PartitionClassGuid = 0
const PcTeb = 24
const PeekConsoleInput = 0
const PeekMessage = 0
const PlaySound = 0
const PolyTextOut = 0
const PostAppMessage = 0
const PostMessage = 0
const PostThreadMessage = 0
const PragFlg_NeedSchema = 1
const PragFlg_NoColumns = 2
const PragFlg_NoColumns1 = 4
const PragFlg_ReadOnly = 8
const PragFlg_Result0 = 16
const PragFlg_Result1 = 32
const PragFlg_SchemaOpt = 64
const PragFlg_SchemaReq = 128
const PragTyp_ACTIVATE_EXTENSIONS = 0
const PragTyp_ANALYSIS_LIMIT = 1
const PragTyp_AUTO_VACUUM = 3
const PragTyp_BUSY_TIMEOUT = 5
const PragTyp_CACHE_SIZE = 6
const PragTyp_CACHE_SPILL = 7
const PragTyp_CASE_SENSITIVE_LIKE = 8
const PragTyp_COLLATION_LIST = 9
const PragTyp_COMPILE_OPTIONS = 10
const PragTyp_DATABASE_LIST = 12
const PragTyp_DATA_STORE_DIRECTORY = 11
const PragTyp_DEFAULT_CACHE_SIZE = 13
const PragTyp_ENCODING = 14
const PragTyp_FLAG = 4
const PragTyp_FOREIGN_KEY_CHECK = 15
const PragTyp_FOREIGN_KEY_LIST = 16
const PragTyp_FUNCTION_LIST = 17
const PragTyp_HARD_HEAP_LIMIT = 18
const PragTyp_HEADER_VALUE = 2
const PragTyp_INCREMENTAL_VACUUM = 19
const PragTyp_INDEX_INFO = 20
const PragTyp_INDEX_LIST = 21
const PragTyp_INTEGRITY_CHECK = 22
const PragTyp_JOURNAL_MODE = 23
const PragTyp_JOURNAL_SIZE_LIMIT = 24
const PragTyp_LOCKING_MODE = 26
const PragTyp_LOCK_PROXY_FILE = 25
const PragTyp_LOCK_STATUS = 44
const PragTyp_MMAP_SIZE = 28
const PragTyp_MODULE_LIST = 29
const PragTyp_OPTIMIZE = 30
const PragTyp_PAGE_COUNT = 27
const PragTyp_PAGE_SIZE = 31
const PragTyp_PRAGMA_LIST = 32
const PragTyp_SECURE_DELETE = 33
const PragTyp_SHRINK_MEMORY = 34
const PragTyp_SOFT_HEAP_LIMIT = 35
const PragTyp_STATS = 45
const PragTyp_SYNCHRONOUS = 36
const PragTyp_TABLE_INFO = 37
const PragTyp_TABLE_LIST = 38
const PragTyp_TEMP_STORE = 39
const PragTyp_TEMP_STORE_DIRECTORY = 40
const PragTyp_THREADS = 41
const PragTyp_WAL_AUTOCHECKPOINT = 42
const PragTyp_WAL_CHECKPOINT = 43
const PrintDlg = 0
const PrintDlgEx = 0
const PrinterMessageBox = 0
const PrivateExtractIcons = 0
const PrivilegedServiceAuditAlarm = 0
const PropertySheet = 0
const QDC_ALL_PATHS = 1
const QDC_DATABASE_CURRENT = 4
const QDC_INCLUDE_HMD = 32
const QDC_ONLY_ACTIVE_PATHS = 2
const QDC_VIRTUAL_MODE_AWARE = 16
const QDI_DIBTOSCREEN = 4
const QDI_GETDIBITS = 2
const QDI_SETDIBITS = 1
const QDI_STRETCHDIB = 8
const QID_SYNC = 4294967295
const QS_ALLEVENTS = 7359
const QS_ALLINPUT = 7423
const QS_ALLPOSTMESSAGE = 256
const QS_HOTKEY = 128
const QS_INPUT = 7175
const QS_KEY = 1
const QS_MOUSE = 6
const QS_MOUSEBUTTON = 4
const QS_MOUSEMOVE = 2
const QS_PAINT = 32
const QS_POINTER = 4096
const QS_POSTMESSAGE = 8
const QS_RAWINPUT = 1024
const QS_SENDMESSAGE = 64
const QS_TIMER = 16
const QS_TOUCH = 2048
const QUERYDIBSUPPORT = 3073
const QUERYESCSUPPORT = 8
const QUERYROPSUPPORT = 40
const QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS = 16
const QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE = 8
const QUERY_ACTCTX_FLAG_NO_ADDREF = 2147483648
const QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX = 4
const QUOTA_LIMITS_HARDWS_MAX_DISABLE = 8
const QUOTA_LIMITS_HARDWS_MAX_ENABLE = 4
const QUOTA_LIMITS_HARDWS_MIN_DISABLE = 2
const QUOTA_LIMITS_HARDWS_MIN_ENABLE = 1
const QUOTA_LIMITS_USE_DEFAULT_LIMITS = 16
const QueryDosDevice = 0
const QueryFullProcessImageName = 0
const QueryServiceConfig = 0
const QueryServiceConfig2 = 0
const QueryServiceLockStatus = 0
const R2_BLACK = 1
const R2_COPYPEN = 13
const R2_LAST = 16
const R2_MASKNOTPEN = 3
const R2_MASKPEN = 9
const R2_MASKPENNOT = 5
const R2_MERGENOTPEN = 12
const R2_MERGEPEN = 15
const R2_MERGEPENNOT = 14
const R2_NOP = 11
const R2_NOT = 6
const R2_NOTCOPYPEN = 4
const R2_NOTMASKPEN = 8
const R2_NOTMERGEPEN = 2
const R2_NOTXORPEN = 10
const R2_WHITE = 16
const R2_XORPEN = 7
const RANDOM_PADDING = 2
const RAND_MAX = 32767
const RASTERCAPS = 38
const RASTER_FONTTYPE = 1
const RBU_CREATE_STATE = "CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)"
const RBU_DELETE = 2
const RBU_ENABLE_DELTA_CKSUM = 0
const RBU_EXCLUSIVE_CHECKPOINT = "rbu_exclusive_checkpoint"
const RBU_IDX_DELETE = 4
const RBU_IDX_INSERT = 5
const RBU_INSERT = 1
const RBU_PK_EXTERNAL = 3
const RBU_PK_IPK = 2
const RBU_PK_NONE = 1
const RBU_PK_NOTABLE = 0
const RBU_PK_VTAB = 5
const RBU_PK_WITHOUT_ROWID = 4
const RBU_REPLACE = 3
const RBU_STAGE_CAPTURE = 3
const RBU_STAGE_CKPT = 4
const RBU_STAGE_DONE = 5
const RBU_STAGE_MOVE = 2
const RBU_STAGE_OAL = 1
const RBU_STATE_CKPT = 6
const RBU_STATE_COOKIE = 7
const RBU_STATE_DATATBL = 10
const RBU_STATE_IDX = 3
const RBU_STATE_OALSZ = 8
const RBU_STATE_PHASEONESTEP = 9
const RBU_STATE_PROGRESS = 5
const RBU_STATE_ROW = 4
const RBU_STATE_STAGE = 1
const RBU_STATE_TBL = 2
const RBU_UPDATE = 6
const RBU_ZIPVFS_CTRL_FILE_POINTER = 230439
const RC_BANDING = 2
const RC_BIGFONT = 1024
const RC_BITBLT = 1
const RC_BITMAP64 = 8
const RC_DEVBITS = 32768
const RC_DIBTODEV = 512
const RC_DI_BITMAP = 128
const RC_FLOODFILL = 4096
const RC_GDI20_OUTPUT = 16
const RC_GDI20_STATE = 32
const RC_OP_DX_OUTPUT = 16384
const RC_PALETTE = 256
const RC_SAVEBITMAP = 64
const RC_SCALING = 4
const RC_STRETCHBLT = 2048
const RC_STRETCHDIB = 8192
const RDH_RECTANGLES = 1
const RDW_ALLCHILDREN = 128
const RDW_ERASE = 4
const RDW_ERASENOW = 512
const RDW_FRAME = 1024
const RDW_INTERNALPAINT = 2
const RDW_INVALIDATE = 1
const RDW_NOCHILDREN = 64
const RDW_NOERASE = 32
const RDW_NOFRAME = 2048
const RDW_NOINTERNALPAINT = 16
const RDW_UPDATENOW = 256
const RDW_VALIDATE = 8
const READMARK_NOT_USED = 4294967295
const READ_ATTRIBUTES = 208
const READ_ATTRIBUTE_BUFFER_SIZE = 512
const READ_COMPRESSION_INFO_VALID = 32
const READ_CONTROL = 131072
const READ_LOCK = 1
const READ_THREAD_PROFILING_FLAG_DISPATCHING = 1
const READ_THREAD_PROFILING_FLAG_HARDWARE_COUNTERS = 2
const READ_THRESHOLDS = 209
const READ_THRESHOLD_BUFFER_SIZE = 512
const REALTIME_PRIORITY_CLASS = 256
const REASON_HWINSTALL = 65538
const REASON_LEGACY_API = 2147942400
const REASON_OTHER = 0
const REASON_PLANNED_FLAG = 2147483648
const REASON_SERVICEHANG = 196613
const REASON_SWHWRECONF = 196612
const REASON_SWINSTALL = 196610
const REASON_UNKNOWN = 255
const REASON_UNSTABLE = 327686
const RECOVERED_READS_VALID = 4
const RECOVERED_WRITES_VALID = 1
const RECOVERY_DEFAULT_PING_INTERVAL = 5000
const RECOVERY_MAX_PING_INTERVAL = 300000
const REGDB_E_FIRST = 2147746128
const REGDB_E_LAST = 2147746143
const REGDB_S_FIRST = 262480
const REGDB_S_LAST = 262495
const REGISTERED = 4
const REGISTERING = 0
const REGISTERWORDENUMPROC = 0
const REGULAR_FONTTYPE = 1024
const REG_APP_HIVE = 16
const REG_BINARY = 3
const REG_BOOT_HIVE = 1024
const REG_CREATED_NEW_KEY = 1
const REG_DWORD = 4
const REG_DWORD_BIG_ENDIAN = 5
const REG_DWORD_LITTLE_ENDIAN = 4
const REG_EXPAND_SZ = 2
const REG_FORCE_RESTORE = 8
const REG_FORCE_UNLOAD = 1
const REG_FULL_RESOURCE_DESCRIPTOR = 9
const REG_HIVE_EXACT_FILE_GROWTH = 128
const REG_HIVE_NO_RM = 256
const REG_HIVE_SINGLE_LOG = 512
const REG_LATEST_FORMAT = 2
const REG_LEGAL_CHANGE_FILTER = 268435471
const REG_LEGAL_OPTION = 15
const REG_LINK = 6
const REG_MUI_STRING_TRUNCATE = 1
const REG_MULTI_SZ = 7
const REG_NONE = 0
const REG_NOTIFY_CHANGE_ATTRIBUTES = 2
const REG_NOTIFY_CHANGE_LAST_SET = 4
const REG_NOTIFY_CHANGE_NAME = 1
const REG_NOTIFY_CHANGE_SECURITY = 8
const REG_NOTIFY_THREAD_AGNOSTIC = 268435456
const REG_NO_COMPRESSION = 4
const REG_NO_LAZY_FLUSH = 4
const REG_OPENED_EXISTING_KEY = 2
const REG_OPTION_BACKUP_RESTORE = 4
const REG_OPTION_CREATE_LINK = 2
const REG_OPTION_NON_VOLATILE = 0
const REG_OPTION_OPEN_LINK = 8
const REG_OPTION_RESERVED = 0
const REG_OPTION_VOLATILE = 1
const REG_PROCESS_APPKEY = 1
const REG_PROCESS_PRIVATE = 32
const REG_QWORD = 11
const REG_QWORD_LITTLE_ENDIAN = 11
const REG_REFRESH_HIVE = 2
const REG_RESOURCE_LIST = 8
const REG_RESOURCE_REQUIREMENTS_LIST = 10
const REG_SECURE_CONNECTION = 1
const REG_STANDARD_FORMAT = 1
const REG_START_JOURNAL = 64
const REG_SZ = 1
const REG_WHOLE_HIVE_VOLATILE = 1
const RELATIVE = 2
const REMOTE_NAME_INFO_LEVEL = 2
const REMOTE_PROTOCOL_INFO_FLAG_LOOPBACK = 1
const REMOTE_PROTOCOL_INFO_FLAG_OFFLINE = 2
const REMOTE_PROTOCOL_INFO_FLAG_PERSISTENT_HANDLE = 4
const REPLACEDLGORD = 1541
const REPLACEFILE_IGNORE_ACL_ERRORS = 4
const REPLACEFILE_IGNORE_MERGE_ERRORS = 2
const REPLACEFILE_WRITE_THROUGH = 1
const REPLACE_ALTERNATE = 11
const REPLACE_PRIMARY = 10
const REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY = 2
const REPORT_NO_PRIVATE_KEY = 1
const REQUEST_OPLOCK_CURRENT_VERSION = 1
const REQUEST_OPLOCK_INPUT_FLAG_ACK = 2
const REQUEST_OPLOCK_INPUT_FLAG_COMPLETE_ACK_ON_CLOSE = 4
const REQUEST_OPLOCK_INPUT_FLAG_REQUEST = 1
const REQUEST_OPLOCK_OUTPUT_FLAG_ACK_REQUIRED = 1
const REQUEST_OPLOCK_OUTPUT_FLAG_MODES_PROVIDED = 2
const RESERVED_BYTE = 1
const RESERVED_LOCK = 2
const RESETDEV = 7
const RESOURCEDISPLAYTYPE_DIRECTORY = 9
const RESOURCEDISPLAYTYPE_DOMAIN = 1
const RESOURCEDISPLAYTYPE_FILE = 4
const RESOURCEDISPLAYTYPE_GENERIC = 0
const RESOURCEDISPLAYTYPE_GROUP = 5
const RESOURCEDISPLAYTYPE_NDSCONTAINER = 11
const RESOURCEDISPLAYTYPE_NETWORK = 6
const RESOURCEDISPLAYTYPE_ROOT = 7
const RESOURCEDISPLAYTYPE_SERVER = 2
const RESOURCEDISPLAYTYPE_SHARE = 3
const RESOURCEDISPLAYTYPE_SHAREADMIN = 8
const RESOURCEDISPLAYTYPE_TREE = 10
const RESOURCEMANAGER_ALL_ACCESS = 2031743
const RESOURCEMANAGER_COMPLETE_PROPAGATION = 64
const RESOURCEMANAGER_ENLIST = 8
const RESOURCEMANAGER_GENERIC_EXECUTE = 1179740
const RESOURCEMANAGER_GENERIC_READ = 1179649
const RESOURCEMANAGER_GENERIC_WRITE = 1179774
const RESOURCEMANAGER_GET_NOTIFICATION = 16
const RESOURCEMANAGER_QUERY_INFORMATION = 1
const RESOURCEMANAGER_RECOVER = 4
const RESOURCEMANAGER_REGISTER_PROTOCOL = 32
const RESOURCEMANAGER_SET_INFORMATION = 2
const RESOURCETYPE_ANY = 0
const RESOURCETYPE_DISK = 1
const RESOURCETYPE_PRINT = 2
const RESOURCETYPE_RESERVED = 8
const RESOURCETYPE_UNKNOWN = 4294967295
const RESOURCEUSAGE_ALL = 19
const RESOURCEUSAGE_ATTACHED = 16
const RESOURCEUSAGE_CONNECTABLE = 1
const RESOURCEUSAGE_CONTAINER = 2
const RESOURCEUSAGE_NOLOCALDEVICE = 4
const RESOURCEUSAGE_RESERVED = 2147483648
const RESOURCEUSAGE_SIBLING = 8
const RESOURCE_CONNECTED = 1
const RESOURCE_CONTEXT = 5
const RESOURCE_ENUM_LN = 1
const RESOURCE_ENUM_MODULE_EXACT = 16
const RESOURCE_ENUM_MUI = 2
const RESOURCE_ENUM_MUI_SYSTEM = 4
const RESOURCE_ENUM_VALIDATE = 8
const RESOURCE_GLOBALNET = 2
const RESOURCE_MANAGER_COMMUNICATION = 2
const RESOURCE_MANAGER_MAXIMUM_OPTION = 3
const RESOURCE_MANAGER_OBJECT_NAME_LENGTH_IN_BYTES = 0
const RESOURCE_MANAGER_OBJECT_PATH = "\\\\ResourceManager\\\\"
const RESOURCE_MANAGER_VOLATILE = 1
const RESOURCE_RECENT = 4
const RESOURCE_REMEMBERED = 3
const RESTART_MAX_CMD_LINE = 1024
const RESTART_NO_CRASH = 1
const RESTART_NO_HANG = 2
const RESTART_NO_PATCH = 4
const RESTART_NO_REBOOT = 8
const RESTORE_CTM = 4100
const RES_CURSOR = 2
const RES_ICON = 1
const RETRACT_IEPORT = 3
const RETURN_SMART_STATUS = 218
const REVERSE_PRINT = 1
const REVISION_LENGTH = 4
const RGN_AND = 1
const RGN_COPY = 5
const RGN_DIFF = 4
const RGN_ERROR = 0
const RGN_MAX = 5
const RGN_MIN = 1
const RGN_OR = 2
const RGN_XOR = 3
const RIDEV_APPKEYS = 1024
const RIDEV_CAPTUREMOUSE = 512
const RIDEV_DEVNOTIFY = 8192
const RIDEV_EXCLUDE = 16
const RIDEV_EXINPUTSINK = 4096
const RIDEV_EXMODEMASK = 240
const RIDEV_INPUTSINK = 256
const RIDEV_NOHOTKEYS = 512
const RIDEV_NOLEGACY = 48
const RIDEV_PAGEONLY = 32
const RIDEV_REMOVE = 1
const RIDI_DEVICEINFO = 536870923
const RIDI_DEVICENAME = 536870919
const RIDI_PREPARSEDDATA = 536870917
const RID_HEADER = 268435461
const RID_INPUT = 268435459
const RIGHTMOST_BUTTON_PRESSED = 2
const RIGHT_ALT_PRESSED = 1
const RIGHT_CTRL_PRESSED = 4
const RIM_INPUT = 0
const RIM_INPUTSINK = 1
const RIM_TYPEHID = 2
const RIM_TYPEKEYBOARD = 1
const RIM_TYPEMAX = 2
const RIM_TYPEMOUSE = 0
const RIP_EVENT = 9
const RI_KEY_BREAK = 1
const RI_KEY_E0 = 2
const RI_KEY_E1 = 4
const RI_KEY_MAKE = 0
const RI_KEY_TERMSRV_SET_LED = 8
const RI_KEY_TERMSRV_SHADOW = 16
const RI_MOUSE_BUTTON_1_DOWN = 1
const RI_MOUSE_BUTTON_1_UP = 2
const RI_MOUSE_BUTTON_2_DOWN = 4
const RI_MOUSE_BUTTON_2_UP = 8
const RI_MOUSE_BUTTON_3_DOWN = 16
const RI_MOUSE_BUTTON_3_UP = 32
const RI_MOUSE_BUTTON_4_DOWN = 64
const RI_MOUSE_BUTTON_4_UP = 128
const RI_MOUSE_BUTTON_5_DOWN = 256
const RI_MOUSE_BUTTON_5_UP = 512
const RI_MOUSE_HWHEEL = 2048
const RI_MOUSE_LEFT_BUTTON_DOWN = 1
const RI_MOUSE_LEFT_BUTTON_UP = 2
const RI_MOUSE_MIDDLE_BUTTON_DOWN = 16
const RI_MOUSE_MIDDLE_BUTTON_UP = 32
const RI_MOUSE_RIGHT_BUTTON_DOWN = 4
const RI_MOUSE_RIGHT_BUTTON_UP = 8
const RI_MOUSE_WHEEL = 1024
const RNDAWAY = 0
const RNDTOWARDS = 0
const ROTFLAGS_ALLOWANYCLIENT = 2
const ROTFLAGS_REGISTRATIONKEEPSALIVE = 1
const ROTREGFLAGS_ALLOWANYCLIENT = 1
const ROT_COMPARE_MAX = 2048
const ROWSET_ALLOCATION_SIZE = 1024
const ROWSET_ENTRY_PER_CHUNK = 1016
const ROWSET_NEXT = 2
const ROWSET_SORTED = 1
const RPCFLG_ASYNCHRONOUS = 1073741824
const RPCFLG_AUTO_COMPLETE = 134217728
const RPCFLG_HAS_CALLBACK = 67108864
const RPCFLG_HAS_MULTI_SYNTAXES = 33554432
const RPCFLG_INPUT_SYNCHRONOUS = 536870912
const RPCFLG_LOCAL_CALL = 268435456
const RPCFLG_MESSAGE = 16777216
const RPCFLG_NON_NDR = 2147483648
const RPCNSAPI = "DECLSPEC_IMPORT"
const RPCRTAPI = "DECLSPEC_IMPORT"
const RPC_ASYNC_VERSION_1_0 = 0
const RPC_BUFFER_ASYNC = 32768
const RPC_BUFFER_COMPLETE = 4096
const RPC_BUFFER_EXTRA = 16384
const RPC_BUFFER_NONOTIFY = 65536
const RPC_BUFFER_PARTIAL = 8192
const RPC_CALL_ATTRIBUTES_V1 = 0
const RPC_CALL_ATTRIBUTES_V2 = 0
const RPC_CALL_ATTRIBUTES_VERSION = 1
const RPC_CALL_LOCAL_ADDRESS = 0
const RPC_CALL_LOCAL_ADDRESS_V1 = 0
const RPC_CALL_STATUS_CANCELLED = 2
const RPC_CALL_STATUS_DISCONNECTED = 3
const RPC_CALL_STATUS_IN_PROGRESS = 1
const RPC_CONTEXT_HANDLE_DEFAULT_FLAGS = 0
const RPC_CONTEXT_HANDLE_DEFAULT_GUARD = -4083
const RPC_CONTEXT_HANDLE_DONT_SERIALIZE = 536870912
const RPC_CONTEXT_HANDLE_FLAGS = 805306368
const RPC_CONTEXT_HANDLE_SERIALIZE = 268435456
const RPC_C_AUTHN_DCE_PRIVATE = 1
const RPC_C_AUTHN_DCE_PUBLIC = 2
const RPC_C_AUTHN_DEC_PUBLIC = 4
const RPC_C_AUTHN_DEFAULT = 4294967295
const RPC_C_AUTHN_DIGEST = 21
const RPC_C_AUTHN_DPA = 17
const RPC_C_AUTHN_GSS_KERBEROS = 16
const RPC_C_AUTHN_GSS_NEGOTIATE = 9
const RPC_C_AUTHN_GSS_SCHANNEL = 14
const RPC_C_AUTHN_INFO_TYPE_HTTP = 1
const RPC_C_AUTHN_LEVEL_CALL = 3
const RPC_C_AUTHN_LEVEL_CONNECT = 2
const RPC_C_AUTHN_LEVEL_DEFAULT = 0
const RPC_C_AUTHN_LEVEL_NONE = 1
const RPC_C_AUTHN_LEVEL_PKT = 4
const RPC_C_AUTHN_LEVEL_PKT_INTEGRITY = 5
const RPC_C_AUTHN_LEVEL_PKT_PRIVACY = 6
const RPC_C_AUTHN_MQ = 100
const RPC_C_AUTHN_MSN = 18
const RPC_C_AUTHN_NONE = 0
const RPC_C_AUTHN_WINNT = 10
const RPC_C_AUTHZ_DCE = 2
const RPC_C_AUTHZ_DEFAULT = 4294967295
const RPC_C_AUTHZ_NAME = 1
const RPC_C_AUTHZ_NONE = 0
const RPC_C_BINDING_DEFAULT_TIMEOUT = 5
const RPC_C_BINDING_INFINITE_TIMEOUT = 10
const RPC_C_BINDING_MAX_TIMEOUT = 9
const RPC_C_BINDING_MIN_TIMEOUT = 0
const RPC_C_BIND_TO_ALL_NICS = 1
const RPC_C_CANCEL_INFINITE_TIMEOUT = -1
const RPC_C_DONT_FAIL = 4
const RPC_C_EP_ALL_ELTS = 0
const RPC_C_EP_MATCH_BY_BOTH = 3
const RPC_C_EP_MATCH_BY_IF = 1
const RPC_C_EP_MATCH_BY_OBJ = 2
const RPC_C_FULL_CERT_CHAIN = 1
const RPC_C_HTTP_AUTHN_SCHEME_BASIC = 1
const RPC_C_HTTP_AUTHN_SCHEME_CERT = 65536
const RPC_C_HTTP_AUTHN_SCHEME_DIGEST = 8
const RPC_C_HTTP_AUTHN_SCHEME_NEGOTIATE = 16
const RPC_C_HTTP_AUTHN_SCHEME_NTLM = 2
const RPC_C_HTTP_AUTHN_SCHEME_PASSPORT = 4
const RPC_C_HTTP_AUTHN_TARGET_PROXY = 2
const RPC_C_HTTP_AUTHN_TARGET_SERVER = 1
const RPC_C_HTTP_FLAG_IGNORE_CERT_CN_INVALID = 8
const RPC_C_HTTP_FLAG_USE_FIRST_AUTH_SCHEME = 2
const RPC_C_HTTP_FLAG_USE_SSL = 1
const RPC_C_IMP_LEVEL_ANONYMOUS = 1
const RPC_C_IMP_LEVEL_DEFAULT = 0
const RPC_C_IMP_LEVEL_DELEGATE = 4
const RPC_C_IMP_LEVEL_IDENTIFY = 2
const RPC_C_IMP_LEVEL_IMPERSONATE = 3
const RPC_C_INFINITE_TIMEOUT = 4294967295
const RPC_C_LISTEN_MAX_CALLS_DEFAULT = 1234
const RPC_C_MGMT_INQ_IF_IDS = 0
const RPC_C_MGMT_INQ_PRINC_NAME = 1
const RPC_C_MGMT_INQ_STATS = 2
const RPC_C_MGMT_IS_SERVER_LISTEN = 3
const RPC_C_MGMT_STOP_SERVER_LISTEN = 4
const RPC_C_MQ_AUTHN_LEVEL_NONE = 0
const RPC_C_MQ_AUTHN_LEVEL_PKT_INTEGRITY = 8
const RPC_C_MQ_AUTHN_LEVEL_PKT_PRIVACY = 16
const RPC_C_MQ_CLEAR_ON_OPEN = 2
const RPC_C_MQ_EXPRESS = 0
const RPC_C_MQ_JOURNAL_ALWAYS = 2
const RPC_C_MQ_JOURNAL_DEADLETTER = 1
const RPC_C_MQ_JOURNAL_NONE = 0
const RPC_C_MQ_PERMANENT = 1
const RPC_C_MQ_RECOVERABLE = 1
const RPC_C_MQ_TEMPORARY = 0
const RPC_C_MQ_USE_EXISTING_SECURITY = 4
const RPC_C_NOTIFY_ON_SEND_COMPLETE = 1
const RPC_C_NS_DEFAULT_EXP_AGE = -1
const RPC_C_NS_SYNTAX_DCE = 3
const RPC_C_NS_SYNTAX_DEFAULT = 0
const RPC_C_OPT_BINDING_NONCAUSAL = 9
const RPC_C_OPT_CALL_TIMEOUT = 12
const RPC_C_OPT_DONT_LINGER = 13
const RPC_C_OPT_MAX_OPTIONS = 14
const RPC_C_OPT_MQ_ACKNOWLEDGE = 4
const RPC_C_OPT_MQ_AUTHN_LEVEL = 6
const RPC_C_OPT_MQ_AUTHN_SERVICE = 5
const RPC_C_OPT_MQ_DELIVERY = 1
const RPC_C_OPT_MQ_JOURNAL = 3
const RPC_C_OPT_MQ_PRIORITY = 2
const RPC_C_OPT_MQ_TIME_TO_BE_RECEIVED = 8
const RPC_C_OPT_MQ_TIME_TO_REACH_QUEUE = 7
const RPC_C_OPT_SECURITY_CALLBACK = 10
const RPC_C_OPT_UNIQUE_BINDING = 11
const RPC_C_PARM_BUFFER_LENGTH = 2
const RPC_C_PARM_MAX_PACKET_LENGTH = 1
const RPC_C_PROFILE_ALL_ELT = 1
const RPC_C_PROFILE_ALL_ELTS = 1
const RPC_C_PROFILE_DEFAULT_ELT = 0
const RPC_C_PROFILE_MATCH_BY_BOTH = 4
const RPC_C_PROFILE_MATCH_BY_IF = 2
const RPC_C_PROFILE_MATCH_BY_MBR = 3
const RPC_C_PROTECT_LEVEL_CALL = 3
const RPC_C_PROTECT_LEVEL_CONNECT = 2
const RPC_C_PROTECT_LEVEL_DEFAULT = 0
const RPC_C_PROTECT_LEVEL_NONE = 1
const RPC_C_PROTECT_LEVEL_PKT = 4
const RPC_C_PROTECT_LEVEL_PKT_INTEGRITY = 5
const RPC_C_PROTECT_LEVEL_PKT_PRIVACY = 6
const RPC_C_PROTSEQ_MAX_REQS_DEFAULT = 10
const RPC_C_QOS_CAPABILITIES_ANY_AUTHORITY = 4
const RPC_C_QOS_CAPABILITIES_DEFAULT = 0
const RPC_C_QOS_CAPABILITIES_IGNORE_DELEGATE_FAILURE = 8
const RPC_C_QOS_CAPABILITIES_LOCAL_MA_HINT = 16
const RPC_C_QOS_CAPABILITIES_MAKE_FULLSIC = 2
const RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH = 1
const RPC_C_QOS_IDENTITY_DYNAMIC = 1
const RPC_C_QOS_IDENTITY_STATIC = 0
const RPC_C_SECURITY_QOS_VERSION = 1
const RPC_C_SECURITY_QOS_VERSION_1 = 1
const RPC_C_SECURITY_QOS_VERSION_2 = 2
const RPC_C_SECURITY_QOS_VERSION_3 = 3
const RPC_C_STATS_CALLS_IN = 0
const RPC_C_STATS_CALLS_OUT = 1
const RPC_C_STATS_PKTS_IN = 2
const RPC_C_STATS_PKTS_OUT = 3
const RPC_C_USE_INTERNET_PORT = 1
const RPC_C_USE_INTRANET_PORT = 2
const RPC_C_VERS_ALL = 1
const RPC_C_VERS_COMPATIBLE = 2
const RPC_C_VERS_EXACT = 3
const RPC_C_VERS_MAJOR_ONLY = 4
const RPC_C_VERS_UPTO = 5
const RPC_EEINFO_VERSION = 1
const RPC_ENTRY = "__RPC_API"
const RPC_FLAGS_VALID_BIT = 32768
const RPC_HTTP_TRANSPORT_CREDENTIALS = 0
const RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH = 16
const RPC_IF_ALLOW_LOCAL_ONLY = 32
const RPC_IF_ALLOW_SECURE_ONLY = 8
const RPC_IF_ALLOW_UNKNOWN_AUTHORITY = 4
const RPC_IF_AUTOLISTEN = 1
const RPC_IF_OLE = 2
const RPC_IF_SEC_NO_CACHE = 64
const RPC_INTERFACE_HAS_PIPES = 1
const RPC_MGR_EPV = 0
const RPC_NCA_FLAGS_BROADCAST = 2
const RPC_NCA_FLAGS_DEFAULT = 0
const RPC_NCA_FLAGS_IDEMPOTENT = 1
const RPC_NCA_FLAGS_MAYBE = 4
const RPC_PROTSEQ_VECTOR = 0
const RPC_PROXY_CONNECTION_TYPE_IN_PROXY = 0
const RPC_PROXY_CONNECTION_TYPE_OUT_PROXY = 1
const RPC_P_ADDR_FORMAT_TCP_IPV4 = 1
const RPC_P_ADDR_FORMAT_TCP_IPV6 = 2
const RPC_QUERY_CLIENT_PRINCIPAL_NAME = 4
const RPC_QUERY_SERVER_PRINCIPAL_NAME = 2
const RPC_SECURITY_QOS_V2 = 0
const RPC_SECURITY_QOS_V3 = 0
const RPC_S_ACCESS_DENIED = 5
const RPC_S_ADDRESS_ERROR = 1768
const RPC_S_ALREADY_LISTENING = 1713
const RPC_S_ALREADY_REGISTERED = 1711
const RPC_S_ASYNC_CALL_PENDING = 997
const RPC_S_BINDING_HAS_NO_AUTH = 1746
const RPC_S_BINDING_INCOMPLETE = 1819
const RPC_S_BUFFER_TOO_SMALL = 122
const RPC_S_CALL_CANCELLED = 1818
const RPC_S_CALL_FAILED = 1726
const RPC_S_CALL_FAILED_DNE = 1727
const RPC_S_CALL_IN_PROGRESS = 1791
const RPC_S_CANNOT_SUPPORT = 1764
const RPC_S_CANT_CREATE_ENDPOINT = 1720
const RPC_S_COMM_FAILURE = 1820
const RPC_S_COOKIE_AUTH_FAILED = 1833
const RPC_S_DO_NOT_DISTURB = 1834
const RPC_S_DUPLICATE_ENDPOINT = 1740
const RPC_S_ENTRY_ALREADY_EXISTS = 1760
const RPC_S_ENTRY_NOT_FOUND = 1761
const RPC_S_ENTRY_TYPE_MISMATCH = 1922
const RPC_S_FP_DIV_ZERO = 1769
const RPC_S_FP_OVERFLOW = 1771
const RPC_S_FP_UNDERFLOW = 1770
const RPC_S_GROUP_MEMBER_NOT_FOUND = 1898
const RPC_S_GRP_ELT_NOT_ADDED = 1928
const RPC_S_GRP_ELT_NOT_REMOVED = 1929
const RPC_S_INCOMPLETE_NAME = 1755
const RPC_S_INTERFACE_NOT_EXPORTED = 1924
const RPC_S_INTERFACE_NOT_FOUND = 1759
const RPC_S_INTERNAL_ERROR = 1766
const RPC_S_INVALID_ARG = 87
const RPC_S_INVALID_ASYNC_CALL = 1915
const RPC_S_INVALID_ASYNC_HANDLE = 1914
const RPC_S_INVALID_AUTH_IDENTITY = 1749
const RPC_S_INVALID_BINDING = 1702
const RPC_S_INVALID_BOUND = 1734
const RPC_S_INVALID_ENDPOINT_FORMAT = 1706
const RPC_S_INVALID_LEVEL = 87
const RPC_S_INVALID_NAF_ID = 1763
const RPC_S_INVALID_NAME_SYNTAX = 1736
const RPC_S_INVALID_NETWORK_OPTIONS = 1724
const RPC_S_INVALID_NET_ADDR = 1707
const RPC_S_INVALID_OBJECT = 1900
const RPC_S_INVALID_RPC_PROTSEQ = 1704
const RPC_S_INVALID_SECURITY_DESC = 1338
const RPC_S_INVALID_STRING_BINDING = 1700
const RPC_S_INVALID_STRING_UUID = 1705
const RPC_S_INVALID_TAG = 1733
const RPC_S_INVALID_TIMEOUT = 1709
const RPC_S_INVALID_VERS_OPTION = 1756
const RPC_S_MAX_CALLS_TOO_SMALL = 1742
const RPC_S_NAME_SERVICE_UNAVAILABLE = 1762
const RPC_S_NOTHING_TO_EXPORT = 1754
const RPC_S_NOT_ALL_OBJS_EXPORTED = 1923
const RPC_S_NOT_ALL_OBJS_UNEXPORTED = 1758
const RPC_S_NOT_CANCELLED = 1826
const RPC_S_NOT_LISTENING = 1715
const RPC_S_NOT_RPC_ERROR = 1823
const RPC_S_NO_BINDINGS = 1718
const RPC_S_NO_CALL_ACTIVE = 1725
const RPC_S_NO_CONTEXT_AVAILABLE = 1765
const RPC_S_NO_ENDPOINT_FOUND = 1708
const RPC_S_NO_ENTRY_NAME = 1735
const RPC_S_NO_INTERFACES = 1817
const RPC_S_NO_MORE_BINDINGS = 1806
const RPC_S_NO_MORE_MEMBERS = 1757
const RPC_S_NO_PRINC_NAME = 1822
const RPC_S_NO_PROTSEQS = 1719
const RPC_S_NO_PROTSEQS_REGISTERED = 1714
const RPC_S_OBJECT_NOT_FOUND = 1710
const RPC_S_OK = 0
const RPC_S_OUT_OF_MEMORY = 14
const RPC_S_OUT_OF_RESOURCES = 1721
const RPC_S_OUT_OF_THREADS = 164
const RPC_S_PRF_ELT_NOT_ADDED = 1926
const RPC_S_PRF_ELT_NOT_REMOVED = 1927
const RPC_S_PROCNUM_OUT_OF_RANGE = 1745
const RPC_S_PROFILE_NOT_ADDED = 1925
const RPC_S_PROTOCOL_ERROR = 1728
const RPC_S_PROTSEQ_NOT_FOUND = 1744
const RPC_S_PROTSEQ_NOT_SUPPORTED = 1703
const RPC_S_PROXY_ACCESS_DENIED = 1729
const RPC_S_SEC_PKG_ERROR = 1825
const RPC_S_SEND_INCOMPLETE = 1913
const RPC_S_SERVER_OUT_OF_MEMORY = 1130
const RPC_S_SERVER_TOO_BUSY = 1723
const RPC_S_SERVER_UNAVAILABLE = 1722
const RPC_S_STRING_TOO_LONG = 1743
const RPC_S_SYSTEM_HANDLE_COUNT_EXCEEDED = 1835
const RPC_S_SYSTEM_HANDLE_TYPE_MISMATCH = 1836
const RPC_S_TIMEOUT = 1460
const RPC_S_TYPE_ALREADY_REGISTERED = 1712
const RPC_S_UNKNOWN_AUTHN_LEVEL = 1748
const RPC_S_UNKNOWN_AUTHN_SERVICE = 1747
const RPC_S_UNKNOWN_AUTHN_TYPE = 1741
const RPC_S_UNKNOWN_AUTHZ_SERVICE = 1750
const RPC_S_UNKNOWN_IF = 1717
const RPC_S_UNKNOWN_MGR_TYPE = 1716
const RPC_S_UNKNOWN_PRINCIPAL = 1332
const RPC_S_UNSUPPORTED_AUTHN_LEVEL = 1821
const RPC_S_UNSUPPORTED_NAME_SYNTAX = 1737
const RPC_S_UNSUPPORTED_TRANS_SYN = 1730
const RPC_S_UNSUPPORTED_TYPE = 1732
const RPC_S_UUID_LOCAL_ONLY = 1824
const RPC_S_UUID_NO_ADDRESS = 1739
const RPC_S_WRONG_KIND_OF_BINDING = 1701
const RPC_S_ZERO_DIVIDE = 1767
const RPC_VAR_ENTRY = "__cdecl"
const RPC_X_BAD_STUB_DATA = 1783
const RPC_X_BYTE_COUNT_TOO_SMALL = 1782
const RPC_X_ENUM_VALUE_OUT_OF_RANGE = 1781
const RPC_X_ENUM_VALUE_TOO_LARGE = 1781
const RPC_X_INVALID_BOUND = 1734
const RPC_X_INVALID_BUFFER = 1784
const RPC_X_INVALID_ES_ACTION = 1827
const RPC_X_INVALID_PIPE_OBJECT = 1830
const RPC_X_INVALID_PIPE_OPERATION = 1831
const RPC_X_INVALID_TAG = 1733
const RPC_X_NO_MEMORY = 14
const RPC_X_NO_MORE_ENTRIES = 1772
const RPC_X_NULL_REF_POINTER = 1780
const RPC_X_PIPE_APP_MEMORY = 14
const RPC_X_PIPE_CLOSED = 1916
const RPC_X_PIPE_DISCIPLINE_ERROR = 1917
const RPC_X_PIPE_EMPTY = 1918
const RPC_X_SS_CANNOT_GET_CALL_HANDLE = 1779
const RPC_X_SS_CHAR_TRANS_OPEN_FAIL = 1773
const RPC_X_SS_CHAR_TRANS_SHORT_FILE = 1774
const RPC_X_SS_CONTEXT_DAMAGED = 1777
const RPC_X_SS_CONTEXT_MISMATCH = 6
const RPC_X_SS_HANDLES_MISMATCH = 1778
const RPC_X_SS_IN_NULL_CONTEXT = 1775
const RPC_X_WRONG_ES_VERSION = 1828
const RPC_X_WRONG_PIPE_ORDER = 1831
const RPC_X_WRONG_PIPE_VERSION = 1832
const RPC_X_WRONG_STUB_VERSION = 1829
const RPI_FLAG_SMB2_SHARECAP_CLUSTER = 64
const RPI_FLAG_SMB2_SHARECAP_CONTINUOUS_AVAILABILITY = 16
const RPI_FLAG_SMB2_SHARECAP_DFS = 8
const RPI_FLAG_SMB2_SHARECAP_SCALEOUT = 32
const RPI_FLAG_SMB2_SHARECAP_TIMEWARP = 2
const RPI_SMB2_FLAG_SERVERCAP_DFS = 1
const RPI_SMB2_FLAG_SERVERCAP_DIRECTORY_LEASING = 32
const RPI_SMB2_FLAG_SERVERCAP_LARGEMTU = 4
const RPI_SMB2_FLAG_SERVERCAP_LEASING = 2
const RPI_SMB2_FLAG_SERVERCAP_MULTICHANNEL = 8
const RPI_SMB2_FLAG_SERVERCAP_PERSISTENT_HANDLES = 16
const RP_INIFILE = 2
const RP_LOGON = 1
const RRF_NOEXPAND = 268435456
const RRF_RT_ANY = 65535
const RRF_RT_DWORD = 24
const RRF_RT_QWORD = 72
const RRF_RT_REG_BINARY = 8
const RRF_RT_REG_DWORD = 16
const RRF_RT_REG_EXPAND_SZ = 4
const RRF_RT_REG_MULTI_SZ = 32
const RRF_RT_REG_NONE = 1
const RRF_RT_REG_QWORD = 64
const RRF_RT_REG_SZ = 2
const RRF_SUBKEY_WOW6432KEY = 131072
const RRF_SUBKEY_WOW6464KEY = 65536
const RRF_WOW64_MASK = 196608
const RRF_ZEROONFAILURE = 536870912
const RSA1024BIT_KEY = 67108864
const RTL_CONDITION_VARIABLE_LOCKMODE_SHARED = 1
const RTL_CRITICAL_SECTION_ALL_FLAG_BITS = 4278190080
const RTL_CRITICAL_SECTION_DEBUG_FLAG_STATIC_INIT = 1
const RTL_CRITICAL_SECTION_FLAG_DYNAMIC_SPIN = 33554432
const RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO = 268435456
const RTL_CRITICAL_SECTION_FLAG_NO_DEBUG_INFO = 16777216
const RTL_CRITICAL_SECTION_FLAG_RESERVED = 3758096384
const RTL_CRITICAL_SECTION_FLAG_RESOURCE_TYPE = 134217728
const RTL_CRITICAL_SECTION_FLAG_STATIC_INIT = 67108864
const RTL_CRITSECT_TYPE = 0
const RTL_RESOURCE_TYPE = 1
const RTL_RUN_ONCE_ASYNC = 2
const RTL_RUN_ONCE_CHECK_ONLY = 1
const RTL_RUN_ONCE_CTX_RESERVED_BITS = 2
const RTL_RUN_ONCE_INIT_FAILED = 4
const RTL_UMS_VERSION = 256
const RTL_VRF_FLG_APPCOMPAT_CHECKS = 16
const RTL_VRF_FLG_COM_CHECKS = 256
const RTL_VRF_FLG_DANGEROUS_APIS = 512
const RTL_VRF_FLG_DEADLOCK_CHECKS = 2048
const RTL_VRF_FLG_DIRTY_STACKS = 64
const RTL_VRF_FLG_ENABLED_SYSTEM_WIDE = 131072
const RTL_VRF_FLG_ENABLE_LOGGING = 16384
const RTL_VRF_FLG_FAST_FILL_HEAP = 32768
const RTL_VRF_FLG_FIRST_CHANCE_EXCEPTION_CHECKS = 4096
const RTL_VRF_FLG_FULL_PAGE_HEAP = 1
const RTL_VRF_FLG_HANDLE_CHECKS = 4
const RTL_VRF_FLG_LOCK_CHECKS = 262144
const RTL_VRF_FLG_MISCELLANEOUS_CHECKS = 131072
const RTL_VRF_FLG_RACE_CHECKS = 1024
const RTL_VRF_FLG_RESERVED_DONOTUSE = 2
const RTL_VRF_FLG_RPC_CHECKS = 128
const RTL_VRF_FLG_STACK_CHECKS = 8
const RTL_VRF_FLG_TLS_CHECKS = 32
const RTL_VRF_FLG_VIRTUAL_MEM_CHECKS = 8192
const RTL_VRF_FLG_VIRTUAL_SPACE_TRACKING = 65536
const RTREE_CACHE_SZ = 5
const RTREE_CHECK_MAX_ERROR = 100
const RTREE_COORD_INT32 = 1
const RTREE_COORD_REAL32 = 0
const RTREE_DEFAULT_ROWEST = 1048576
const RTREE_EQ = 65
const RTREE_FALSE = 64
const RTREE_GE = 68
const RTREE_GT = 69
const RTREE_LE = 66
const RTREE_LT = 67
const RTREE_MATCH = 70
const RTREE_MAXCELLS = 51
const RTREE_MAX_AUX_COLUMN = 100
const RTREE_MAX_DEPTH = 40
const RTREE_MAX_DIMENSIONS = 5
const RTREE_MIN_ROWEST = 100
const RTREE_QUERY = 71
const RTREE_TRUE = 63
const RTREE_ZERO = 0
const RTS_CONTROL_DISABLE = 0
const RTS_CONTROL_ENABLE = 1
const RTS_CONTROL_HANDSHAKE = 2
const RTS_CONTROL_TOGGLE = 3
const RUNDLGORD = 1545
const RUSSIAN_CHARSET = 204
const ReadConsole = 0
const ReadConsoleInput = 0
const ReadConsoleOutput = 0
const ReadConsoleOutputCharacter = 0
const ReadEventLog = 0
const RealGetWindowClass = 0
const RegConnectRegistry = 0
const RegConnectRegistryEx = 0
const RegCopyTree = 0
const RegCreateKey = 0
const RegCreateKeyEx = 0
const RegCreateKeyTransacted = 0
const RegDeleteKey = 0
const RegDeleteKeyEx = 0
const RegDeleteKeyTransacted = 0
const RegDeleteKeyValue = 0
const RegDeleteTree = 0
const RegDeleteValue = 0
const RegEnumKey = 0
const RegEnumKeyEx = 0
const RegEnumValue = 0
const RegGetValue = 0
const RegLoadAppKey = 0
const RegLoadKey = 0
const RegLoadMUIString = 0
const RegOpenKey = 0
const RegOpenKeyEx = 0
const RegOpenKeyTransacted = 0
const RegQueryInfoKey = 0
const RegQueryMultipleValues = 0
const RegQueryValue = 0
const RegQueryValueEx = 0
const RegReplaceKey = 0
const RegRestoreKey = 0
const RegSaveKey = 0
const RegSaveKeyEx = 0
const RegSetKeyValue = 0
const RegSetValue = 0
const RegSetValueEx = 0
const RegUnLoadKey = 0
const RegisterClass = 0
const RegisterClassEx = 0
const RegisterClipboardFormat = 0
const RegisterDeviceNotification = 0
const RegisterEventSource = 0
const RegisterServiceCtrlHandler = 0
const RegisterServiceCtrlHandlerEx = 0
const RegisterWindowMessage = 0
const RemoveDirectory = 0
const RemoveDirectoryTransacted = 0
const RemoveFontResource = 0
const RemoveFontResourceEx = 0
const RemoveProp = 0
const ReplaceFile = 0
const ReplaceText = 0
const ReportEvent = 0
const ResetDC = 0
const ResetPrinter = 0
const RotateLeft32 = 0
const RotateLeft64 = 0
const RotateRight32 = 0
const RotateRight64 = 0
const RpcBindingCreate = 0
const RpcBindingFromStringBinding = 0
const RpcBindingInqAuthClient = 0
const RpcBindingInqAuthClientEx = 0
const RpcBindingInqAuthInfo = 0
const RpcBindingInqAuthInfoEx = 0
const RpcBindingSetAuthInfo = 0
const RpcBindingSetAuthInfoEx = 0
const RpcBindingToStringBinding = 0
const RpcEndExcept = "}"
const RpcEndFinally = "}"
const RpcEpRegister = 0
const RpcEpRegisterNoReplace = 0
const RpcMgmtEpEltInqNext = 0
const RpcMgmtInqServerPrincName = 0
const RpcNetworkInqProtseqs = 0
const RpcNetworkIsProtseqValid = 0
const RpcNsBindingExport = 0
const RpcNsBindingExportPnP = 0
const RpcNsBindingImportBegin = 0
const RpcNsBindingInqEntryName = 0
const RpcNsBindingLookupBegin = 0
const RpcNsBindingUnexport = 0
const RpcNsBindingUnexportPnP = 0
const RpcNsEntryExpandName = 0
const RpcNsEntryObjectInqBegin = 0
const RpcNsGroupDelete = 0
const RpcNsGroupMbrAdd = 0
const RpcNsGroupMbrInqBegin = 0
const RpcNsGroupMbrInqNext = 0
const RpcNsGroupMbrRemove = 0
const RpcNsMgmtBindingUnexport = 0
const RpcNsMgmtEntryCreate = 0
const RpcNsMgmtEntryDelete = 0
const RpcNsMgmtEntryInqIfIds = 0
const RpcNsProfileDelete = 0
const RpcNsProfileEltAdd = 0
const RpcNsProfileEltInqBegin = 0
const RpcNsProfileEltInqNext = 0
const RpcNsProfileEltRemove = 0
const RpcProtseqVectorFree = 0
const RpcServerInqCallAttributes = 0
const RpcServerInqDefaultPrincName = 0
const RpcServerRegisterAuthInfo = 0
const RpcServerUseProtseq = 0
const RpcServerUseProtseqEp = 0
const RpcServerUseProtseqEpEx = 0
const RpcServerUseProtseqEx = 0
const RpcServerUseProtseqIf = 0
const RpcServerUseProtseqIfEx = 0
const RpcStringBindingCompose = 0
const RpcStringBindingParse = 0
const RpcStringFree = 0
const SACL_SECURITY_INFORMATION = 8
const SANDBOX_INERT = 2
const SAVEPOINT_BEGIN = 0
const SAVEPOINT_RELEASE = 1
const SAVEPOINT_ROLLBACK = 2
const SAVE_ATTRIBUTE_VALUES = 211
const SAVE_CTM = 4101
const SBM_ENABLE_ARROWS = 228
const SBM_GETPOS = 225
const SBM_GETRANGE = 227
const SBM_GETSCROLLBARINFO = 235
const SBM_GETSCROLLINFO = 234
const SBM_SETPOS = 224
const SBM_SETRANGE = 226
const SBM_SETRANGEREDRAW = 230
const SBM_SETSCROLLINFO = 233
const SBS_BOTTOMALIGN = 4
const SBS_HORZ = 0
const SBS_LEFTALIGN = 2
const SBS_RIGHTALIGN = 4
const SBS_SIZEBOX = 8
const SBS_SIZEBOXBOTTOMRIGHTALIGN = 4
const SBS_SIZEBOXTOPLEFTALIGN = 2
const SBS_SIZEGRIP = 16
const SBS_TOPALIGN = 2
const SBS_VERT = 1
const SB_BOTH = 3
const SB_BOTTOM = 7
const SB_CONST_ALPHA = 1
const SB_CTL = 2
const SB_ENDSCROLL = 8
const SB_GRAD_RECT = 16
const SB_GRAD_TRI = 32
const SB_HORZ = 0
const SB_LEFT = 6
const SB_LINEDOWN = 1
const SB_LINELEFT = 0
const SB_LINERIGHT = 1
const SB_LINEUP = 0
const SB_NONE = 0
const SB_PAGEDOWN = 3
const SB_PAGELEFT = 2
const SB_PAGERIGHT = 3
const SB_PAGEUP = 2
const SB_PIXEL_ALPHA = 2
const SB_PREMULT_ALPHA = 4
const SB_RIGHT = 7
const SB_THUMBPOSITION = 4
const SB_THUMBTRACK = 5
const SB_TOP = 6
const SB_VERT = 1
const SCALINGFACTORX = 114
const SCALINGFACTORY = 115
const SCARD_ABSENT = 1
const SCARD_ATR_LENGTH = 33
const SCARD_CLASS_COMMUNICATIONS = 2
const SCARD_CLASS_ICC_STATE = 9
const SCARD_CLASS_IFD_PROTOCOL = 8
const SCARD_CLASS_MECHANICAL = 6
const SCARD_CLASS_PERF = 32766
const SCARD_CLASS_POWER_MGMT = 4
const SCARD_CLASS_PROTOCOL = 3
const SCARD_CLASS_SECURITY = 5
const SCARD_CLASS_SYSTEM = 32767
const SCARD_CLASS_VENDOR_DEFINED = 7
const SCARD_CLASS_VENDOR_INFO = 1
const SCARD_COLD_RESET = 1
const SCARD_EJECT_CARD = 3
const SCARD_LEAVE_CARD = 0
const SCARD_NEGOTIABLE = 5
const SCARD_PCI_RAW = 0
const SCARD_PCI_T0 = 0
const SCARD_PCI_T1 = 0
const SCARD_POWERED = 4
const SCARD_POWER_DOWN = 0
const SCARD_PRESENT = 2
const SCARD_PROTOCOL_DEFAULT = 2147483648
const SCARD_PROTOCOL_OPTIMAL = 0
const SCARD_PROTOCOL_RAW = 65536
const SCARD_PROTOCOL_T0 = 1
const SCARD_PROTOCOL_T1 = 2
const SCARD_PROTOCOL_Tx = 3
const SCARD_PROTOCOL_UNDEFINED = 0
const SCARD_PROVIDER_CSP = 2
const SCARD_PROVIDER_PRIMARY = 1
const SCARD_READERSTATE_A = 0
const SCARD_READERSTATE_W = 0
const SCARD_READER_CONFISCATES = 4
const SCARD_READER_EJECTS = 2
const SCARD_READER_SWALLOWS = 1
const SCARD_READER_TYPE_IDE = 16
const SCARD_READER_TYPE_KEYBOARD = 4
const SCARD_READER_TYPE_PARALELL = 2
const SCARD_READER_TYPE_PCMCIA = 64
const SCARD_READER_TYPE_SCSI = 8
const SCARD_READER_TYPE_SERIAL = 1
const SCARD_READER_TYPE_USB = 32
const SCARD_READER_TYPE_VENDOR = 240
const SCARD_RESET_CARD = 1
const SCARD_SCOPE_SYSTEM = 2
const SCARD_SCOPE_TERMINAL = 1
const SCARD_SCOPE_USER = 0
const SCARD_SHARE_DIRECT = 3
const SCARD_SHARE_EXCLUSIVE = 1
const SCARD_SHARE_SHARED = 2
const SCARD_SPECIFIC = 6
const SCARD_STATE_ATRMATCH = 64
const SCARD_STATE_CHANGED = 2
const SCARD_STATE_EMPTY = 16
const SCARD_STATE_EXCLUSIVE = 128
const SCARD_STATE_IGNORE = 1
const SCARD_STATE_INUSE = 256
const SCARD_STATE_MUTE = 512
const SCARD_STATE_PRESENT = 32
const SCARD_STATE_UNAVAILABLE = 8
const SCARD_STATE_UNAWARE = 0
const SCARD_STATE_UNKNOWN = 4
const SCARD_STATE_UNPOWERED = 1024
const SCARD_SWALLOWED = 3
const SCARD_S_SUCCESS = 0
const SCARD_T0_CMD_LENGTH = 5
const SCARD_T0_HEADER_LENGTH = 7
const SCARD_T1_EPILOGUE_LENGTH = 2
const SCARD_T1_MAX_IFS = 254
const SCARD_T1_PROLOGUE_LENGTH = 3
const SCARD_UNKNOWN = 0
const SCARD_UNPOWER_CARD = 2
const SCARD_WARM_RESET = 2
const SCERR_NOCARDNAME = 16384
const SCERR_NOGUIDS = 32768
const SCF_ISSECURE = 1
const SCHANNEL_ENC_KEY = 1
const SCHANNEL_MAC_KEY = 0
const SCHED_E_SERVICE_NOT_LOCALSYSTEM = 6200
const SCHEMA_ROOT = 1
const SCHEME_OID_RETRIEVE_ENCODED_OBJECTW_FUNC = "SchemeDllRetrieveEncodedObjectW"
const SCHEME_OID_RETRIEVE_ENCODED_OBJECT_FUNC = "SchemeDllRetrieveEncodedObject"
const SCOPE_SECURITY_INFORMATION = 64
const SCREEN_FONTTYPE = 8192
const SCROLLLOCK_ON = 64
const SCRUB_DATA_INPUT_FLAG_RESUME = 1
const SCRUB_DATA_INPUT_FLAG_SKIP_IN_SYNC = 2
const SCRUB_DATA_INPUT_FLAG_SKIP_NON_INTEGRITY_DATA = 4
const SCRUB_DATA_OUTPUT_FLAG_INCOMPLETE = 1
const SCRUB_DATA_OUTPUT_FLAG_NON_USER_DATA_RANGE = 65536
const SCS_32BIT_BINARY = 0
const SCS_64BIT_BINARY = 6
const SCS_CAP_COMPSTR = 1
const SCS_CAP_MAKEREAD = 2
const SCS_CAP_SETRECONVERTSTRING = 4
const SCS_CHANGEATTR = 18
const SCS_CHANGECLAUSE = 36
const SCS_DOS_BINARY = 1
const SCS_OS216_BINARY = 5
const SCS_PIF_BINARY = 3
const SCS_POSIX_BINARY = 4
const SCS_QUERYRECONVERTSTRING = 131072
const SCS_SETRECONVERTSTRING = 65536
const SCS_SETSTR = 9
const SCS_THIS_PLATFORM_BINARY = 0
const SCS_WOW_BINARY = 2
const SC_ARRANGE = 61712
const SC_CLOSE = 61536
const SC_CONTEXTHELP = 61824
const SC_DEFAULT = 61792
const SC_DLG_FORCE_UI = 4
const SC_DLG_MINIMAL_UI = 1
const SC_DLG_NO_UI = 2
const SC_GROUP_IDENTIFIER = 43
const SC_GROUP_IDENTIFIERA = 43
const SC_GROUP_IDENTIFIERW = 43
const SC_HOTKEY = 61776
const SC_HSCROLL = 61568
const SC_ICON = 61472
const SC_KEYMENU = 61696
const SC_MANAGER_ALL_ACCESS = 983103
const SC_MANAGER_CONNECT = 1
const SC_MANAGER_CREATE_SERVICE = 2
const SC_MANAGER_ENUMERATE_SERVICE = 4
const SC_MANAGER_LOCK = 8
const SC_MANAGER_MODIFY_BOOT_CONFIG = 32
const SC_MANAGER_QUERY_LOCK_STATUS = 16
const SC_MAXIMIZE = 61488
const SC_MINIMIZE = 61472
const SC_MONITORPOWER = 61808
const SC_MOUSEMENU = 61584
const SC_MOVE = 61456
const SC_NEXTWINDOW = 61504
const SC_PREVWINDOW = 61520
const SC_RESTORE = 61728
const SC_SCREENSAVE = 61760
const SC_SEPARATOR = 61455
const SC_SIZE = 61440
const SC_TASKLIST = 61744
const SC_VSCROLL = 61552
const SC_ZOOM = 61488
const SCardAddReaderToGroup = 0
const SCardConnect = 0
const SCardForgetCardType = 0
const SCardForgetReader = 0
const SCardForgetReaderGroup = 0
const SCardGetCardTypeProviderName = 0
const SCardGetProviderId = 0
const SCardGetReaderCapabilities = 0
const SCardGetStatusChange = 0
const SCardIntroduceCardType = 0
const SCardIntroduceReader = 0
const SCardIntroduceReaderGroup = 0
const SCardListCardTypes = 0
const SCardListCards = 0
const SCardListInterfaces = 0
const SCardListReaderGroups = 0
const SCardListReaders = 0
const SCardLocateCards = 0
const SCardLocateCardsByATR = 0
const SCardReadCache = 0
const SCardRemoveReaderFromGroup = 0
const SCardSetCardTypeProviderName = 0
const SCardSetReaderCapabilities = 0
const SCardStatus = 0
const SCardUIDlgSelectCard = 0
const SCardWriteCache = 0
const SDC_ALLOW_CHANGES = 1024
const SDC_ALLOW_PATH_ORDER_CHANGES = 8192
const SDC_APPLY = 128
const SDC_FORCE_MODE_ENUMERATION = 4096
const SDC_NO_OPTIMIZATION = 256
const SDC_PATH_PERSIST_IF_REQUIRED = 2048
const SDC_SAVE_TO_DATABASE = 512
const SDC_TOPOLOGY_CLONE = 2
const SDC_TOPOLOGY_EXTEND = 4
const SDC_TOPOLOGY_EXTERNAL = 8
const SDC_TOPOLOGY_INTERNAL = 1
const SDC_TOPOLOGY_SUPPLIED = 16
const SDC_USE_DATABASE_CURRENT = 15
const SDC_USE_SUPPLIED_DISPLAY_CONFIG = 32
const SDC_VALIDATE = 64
const SDC_VIRTUAL_MODE_AWARE = 32768
const SD_GLOBAL_CHANGE_TYPE_MACHINE_SID = 1
const SEARCH_ALL = 0
const SEARCH_ALL_NO_SEQ = 4
const SEARCH_ALTERNATE = 2
const SEARCH_ALT_NO_SEQ = 6
const SEARCH_PRIMARY = 1
const SEARCH_PRI_NO_SEQ = 5
const SECTION_ALL_ACCESS = 983071
const SECTION_EXTEND_SIZE = 16
const SECTION_MAP_EXECUTE = 8
const SECTION_MAP_EXECUTE_EXPLICIT = 32
const SECTION_MAP_READ = 4
const SECTION_MAP_WRITE = 2
const SECTION_QUERY = 1
const SECURITY_ANONYMOUS = 0
const SECURITY_ANONYMOUS_LOGON_RID = 7
const SECURITY_APPPOOL_ID_BASE_RID = 82
const SECURITY_APPPOOL_ID_RID_COUNT = 6
const SECURITY_APP_PACKAGE_BASE_RID = 2
const SECURITY_APP_PACKAGE_RID_COUNT = 8
const SECURITY_AUTHENTICATED_USER_RID = 11
const SECURITY_AUTHENTICATION_AUTHORITY_ASSERTED_RID = 1
const SECURITY_AUTHENTICATION_AUTHORITY_RID_COUNT = 1
const SECURITY_AUTHENTICATION_SERVICE_ASSERTED_RID = 2
const SECURITY_BATCH_RID = 3
const SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT = 2
const SECURITY_BUILTIN_CAPABILITY_RID_COUNT = 2
const SECURITY_BUILTIN_DOMAIN_RID = 32
const SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE = 1
const SECURITY_BUILTIN_PACKAGE_ANY_RESTRICTED_PACKAGE = 2
const SECURITY_CAPABILITY_APPOINTMENTS = 11
const SECURITY_CAPABILITY_BASE_RID = 3
const SECURITY_CAPABILITY_CONTACTS = 12
const SECURITY_CAPABILITY_DOCUMENTS_LIBRARY = 7
const SECURITY_CAPABILITY_ENTERPRISE_AUTHENTICATION = 8
const SECURITY_CAPABILITY_INTERNET_CLIENT = 1
const SECURITY_CAPABILITY_INTERNET_CLIENT_SERVER = 2
const SECURITY_CAPABILITY_INTERNET_EXPLORER = 4096
const SECURITY_CAPABILITY_MUSIC_LIBRARY = 6
const SECURITY_CAPABILITY_PICTURES_LIBRARY = 4
const SECURITY_CAPABILITY_PRIVATE_NETWORK_CLIENT_SERVER = 3
const SECURITY_CAPABILITY_REMOVABLE_STORAGE = 10
const SECURITY_CAPABILITY_RID_COUNT = 5
const SECURITY_CAPABILITY_SHARED_USER_CERTIFICATES = 9
const SECURITY_CAPABILITY_VIDEOS_LIBRARY = 5
const SECURITY_CLOUD_INFRASTRUCTURE_SERVICES_ID_BASE_RID = 85
const SECURITY_CLOUD_INFRASTRUCTURE_SERVICES_ID_RID_COUNT = 6
const SECURITY_COM_ID_BASE_RID = 89
const SECURITY_CONTEXT_TRACKING = 262144
const SECURITY_CREATOR_GROUP_RID = 1
const SECURITY_CREATOR_GROUP_SERVER_RID = 3
const SECURITY_CREATOR_OWNER_RID = 0
const SECURITY_CREATOR_OWNER_RIGHTS_RID = 4
const SECURITY_CREATOR_OWNER_SERVER_RID = 2
const SECURITY_CRED_TYPE_BASE_RID = 65
const SECURITY_CRED_TYPE_RID_COUNT = 2
const SECURITY_CRED_TYPE_THIS_ORG_CERT_RID = 1
const SECURITY_DASHOST_ID_BASE_RID = 92
const SECURITY_DASHOST_ID_RID_COUNT = 6
const SECURITY_DELEGATION = 0
const SECURITY_DESCRIPTOR_MIN_LENGTH = 0
const SECURITY_DESCRIPTOR_REVISION = 1
const SECURITY_DESCRIPTOR_REVISION1 = 1
const SECURITY_DIALUP_RID = 1
const SECURITY_DYNAMIC_TRACKING = 1
const SECURITY_EFFECTIVE_ONLY = 524288
const SECURITY_ENTERPRISE_CONTROLLERS_RID = 9
const SECURITY_ENTERPRISE_READONLY_CONTROLLERS_RID = 22
const SECURITY_IDENTIFICATION = 0
const SECURITY_IE_STATE_GREEN = 0
const SECURITY_IE_STATE_RED = 1
const SECURITY_IMPERSONATION = 0
const SECURITY_INTERACTIVE_RID = 4
const SECURITY_IUSER_RID = 17
const SECURITY_LOCAL_LOGON_RID = 1
const SECURITY_LOCAL_RID = 0
const SECURITY_LOCAL_SERVICE_RID = 19
const SECURITY_LOCAL_SYSTEM_RID = 18
const SECURITY_LOGON_IDS_RID = 5
const SECURITY_LOGON_IDS_RID_COUNT = 3
const SECURITY_MANDATORY_HIGH_RID = 12288
const SECURITY_MANDATORY_LOW_RID = 4096
const SECURITY_MANDATORY_MAXIMUM_USER_RID = 16384
const SECURITY_MANDATORY_MEDIUM_RID = 8192
const SECURITY_MANDATORY_PROTECTED_PROCESS_RID = 20480
const SECURITY_MANDATORY_SYSTEM_RID = 16384
const SECURITY_MANDATORY_UNTRUSTED_RID = 0
const SECURITY_MAX_ALWAYS_FILTERED = 999
const SECURITY_MAX_BASE_RID = 111
const SECURITY_MAX_IMPERSONATION_LEVEL = 0
const SECURITY_MAX_SID_SIZE = 0
const SECURITY_MIN_BASE_RID = 80
const SECURITY_MIN_IMPERSONATION_LEVEL = 0
const SECURITY_MIN_NEVER_FILTERED = 1000
const SECURITY_NETWORK_RID = 2
const SECURITY_NETWORK_SERVICE_RID = 20
const SECURITY_NFS_ID_BASE_RID = 88
const SECURITY_NT_NON_UNIQUE = 21
const SECURITY_NT_NON_UNIQUE_SUB_AUTH_COUNT = 3
const SECURITY_NULL_RID = 0
const SECURITY_OTHER_ORGANIZATION_RID = 1000
const SECURITY_PACKAGE_BASE_RID = 64
const SECURITY_PACKAGE_DIGEST_RID = 21
const SECURITY_PACKAGE_NTLM_RID = 10
const SECURITY_PACKAGE_RID_COUNT = 2
const SECURITY_PACKAGE_SCHANNEL_RID = 14
const SECURITY_PRINCIPAL_SELF_RID = 10
const SECURITY_PROXY_RID = 8
const SECURITY_RDV_GFX_BASE_RID = 91
const SECURITY_REMOTE_LOGON_RID = 14
const SECURITY_RESERVED_ID_BASE_RID = 81
const SECURITY_RESTRICTED_CODE_RID = 12
const SECURITY_SERVER_LOGON_RID = 9
const SECURITY_SERVICE_ID_BASE_RID = 80
const SECURITY_SERVICE_ID_RID_COUNT = 6
const SECURITY_SERVICE_RID = 6
const SECURITY_SQOS_PRESENT = 1048576
const SECURITY_STATIC_TRACKING = 0
const SECURITY_TASK_ID_BASE_RID = 87
const SECURITY_TERMINAL_SERVER_RID = 13
const SECURITY_THIS_ORGANIZATION_RID = 15
const SECURITY_TRUSTED_INSTALLER_RID1 = 956008885
const SECURITY_TRUSTED_INSTALLER_RID2 = 3418522649
const SECURITY_TRUSTED_INSTALLER_RID3 = 1831038044
const SECURITY_TRUSTED_INSTALLER_RID4 = 1853292631
const SECURITY_TRUSTED_INSTALLER_RID5 = 2271478464
const SECURITY_USERMODEDRIVERHOST_ID_BASE_RID = 84
const SECURITY_USERMODEDRIVERHOST_ID_RID_COUNT = 6
const SECURITY_VALID_SQOS_FLAGS = 2031616
const SECURITY_VIRTUALACCOUNT_ID_RID_COUNT = 6
const SECURITY_VIRTUALSERVER_ID_BASE_RID = 83
const SECURITY_VIRTUALSERVER_ID_RID_COUNT = 6
const SECURITY_WINDOWSMOBILE_ID_BASE_RID = 112
const SECURITY_WINDOW_MANAGER_BASE_RID = 90
const SECURITY_WMIHOST_ID_BASE_RID = 86
const SECURITY_WMIHOST_ID_RID_COUNT = 6
const SECURITY_WORLD_RID = 0
const SECURITY_WRITE_RESTRICTED_CODE_RID = 33
const SEC_64K_PAGES = 524288
const SEC_COMMIT = 134217728
const SEC_E_NOT_SUPPORTED = "SEC_E_UNSUPPORTED_FUNCTION"
const SEC_E_NO_SPM = "SEC_E_INTERNAL_ERROR"
const SEC_FILE = 8388608
const SEC_IMAGE = 16777216
const SEC_IMAGE_NO_EXECUTE = 285212672
const SEC_LARGE_PAGES = 2147483648
const SEC_NOCACHE = 268435456
const SEC_PARTITION_OWNER_HANDLE = 262144
const SEC_PROTECTED_IMAGE = 33554432
const SEC_RESERVE = 67108864
const SEC_WINNT_AUTH_IDENTITY = 0
const SEC_WINNT_AUTH_IDENTITY_ANSI = 1
const SEC_WINNT_AUTH_IDENTITY_UNICODE = 2
const SEC_WRITECOMBINE = 1073741824
const SEEK_CUR = 1
const SEEK_END = 2
const SEEK_SET = 0
const SEE_MASK_ASYNCOK = 1048576
const SEE_MASK_CLASSKEY = 3
const SEE_MASK_CLASSNAME = 1
const SEE_MASK_CONNECTNETDRV = 128
const SEE_MASK_DEFAULT = 0
const SEE_MASK_DOENVSUBST = 512
const SEE_MASK_FLAG_DDEWAIT = 256
const SEE_MASK_FLAG_HINST_IS_SITE = 134217728
const SEE_MASK_FLAG_LOG_USAGE = 67108864
const SEE_MASK_FLAG_NO_UI = 1024
const SEE_MASK_HMONITOR = 2097152
const SEE_MASK_HOTKEY = 32
const SEE_MASK_IDLIST = 4
const SEE_MASK_INVOKEIDLIST = 12
const SEE_MASK_NOASYNC = 256
const SEE_MASK_NOCLOSEPROCESS = 64
const SEE_MASK_NOQUERYCLASSSTORE = 16777216
const SEE_MASK_NOZONECHECKS = 8388608
const SEE_MASK_NO_CONSOLE = 32768
const SEE_MASK_UNICODE = 16384
const SEE_MASK_WAITFORINPUTIDLE = 33554432
const SEF_AVOID_OWNER_CHECK = 16
const SEF_AVOID_OWNER_RESTRICTION = 4096
const SEF_AVOID_PRIVILEGE_CHECK = 8
const SEF_DACL_AUTO_INHERIT = 1
const SEF_DEFAULT_DESCRIPTOR_FOR_OBJECT = 4
const SEF_DEFAULT_GROUP_FROM_PARENT = 64
const SEF_DEFAULT_OWNER_FROM_PARENT = 32
const SEF_MACL_NO_EXECUTE_UP = 1024
const SEF_MACL_NO_READ_UP = 512
const SEF_MACL_NO_WRITE_UP = 256
const SEF_MACL_VALID_FLAGS = 1792
const SEF_SACL_AUTO_INHERIT = 2
const SELECTDIB = 41
const SELECTPAPERSOURCE = 18
const SELECT_CAP_CONVERSION = 1
const SELECT_CAP_SENTENCE = 2
const SEMAPHORE_ALL_ACCESS = 2031619
const SEMAPHORE_MODIFY_STATE = 2
const SEM_FAILCRITICALERRORS = 1
const SEM_NOALIGNMENTFAULTEXCEPT = 4
const SEM_NOGPFAULTERRORBOX = 2
const SEM_NOOPENFILEERRORBOX = 32768
const SERIAL_NUMBER_LENGTH = 32
const SERKF_AVAILABLE = 2
const SERKF_INDICATOR = 4
const SERKF_SERIALKEYSON = 1
const SERVER_ACCESS_ADMINISTER = 1
const SERVER_ACCESS_ENUMERATE = 2
const SERVER_ALL_ACCESS = 983043
const SERVER_EXECUTE = 131074
const SERVER_READ = 131074
const SERVER_WRITE = 131075
const SERVICES_ACTIVE_DATABASEA = "ServicesActive"
const SERVICES_ACTIVE_DATABASEW = "ServicesActive"
const SERVICES_FAILED_DATABASEA = "ServicesFailed"
const SERVICES_FAILED_DATABASEW = "ServicesFailed"
const SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 32
const SERVICE_ACCEPT_LOWRESOURCES = 8192
const SERVICE_ACCEPT_NETBINDCHANGE = 16
const SERVICE_ACCEPT_PARAMCHANGE = 8
const SERVICE_ACCEPT_PAUSE_CONTINUE = 2
const SERVICE_ACCEPT_POWEREVENT = 64
const SERVICE_ACCEPT_PRESHUTDOWN = 256
const SERVICE_ACCEPT_SESSIONCHANGE = 128
const SERVICE_ACCEPT_SHUTDOWN = 4
const SERVICE_ACCEPT_STOP = 1
const SERVICE_ACCEPT_SYSTEMLOWRESOURCES = 16384
const SERVICE_ACCEPT_TIMECHANGE = 512
const SERVICE_ACCEPT_TRIGGEREVENT = 1024
const SERVICE_ACCEPT_USER_LOGOFF = 2048
const SERVICE_ACTIVE = 1
const SERVICE_ADAPTER = 4
const SERVICE_ALL_ACCESS = 983551
const SERVICE_AUTO_START = 2
const SERVICE_BOOT_START = 0
const SERVICE_CHANGE_CONFIG = 2
const SERVICE_CONFIG_DELAYED_AUTO_START_INFO = 3
const SERVICE_CONFIG_DESCRIPTION = 1
const SERVICE_CONFIG_FAILURE_ACTIONS = 2
const SERVICE_CONFIG_FAILURE_ACTIONS_FLAG = 4
const SERVICE_CONFIG_LAUNCH_PROTECTED = 12
const SERVICE_CONFIG_PREFERRED_NODE = 9
const SERVICE_CONFIG_PRESHUTDOWN_INFO = 7
const SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO = 6
const SERVICE_CONFIG_SERVICE_SID_INFO = 5
const SERVICE_CONFIG_TRIGGER_INFO = 8
const SERVICE_CONTINUE_PENDING = 5
const SERVICE_CONTROL_CONTINUE = 3
const SERVICE_CONTROL_DEVICEEVENT = 11
const SERVICE_CONTROL_HARDWAREPROFILECHANGE = 12
const SERVICE_CONTROL_INTERROGATE = 4
const SERVICE_CONTROL_LOWRESOURCES = 96
const SERVICE_CONTROL_NETBINDADD = 7
const SERVICE_CONTROL_NETBINDDISABLE = 10
const SERVICE_CONTROL_NETBINDENABLE = 9
const SERVICE_CONTROL_NETBINDREMOVE = 8
const SERVICE_CONTROL_PARAMCHANGE = 6
const SERVICE_CONTROL_PAUSE = 2
const SERVICE_CONTROL_POWEREVENT = 13
const SERVICE_CONTROL_PRESHUTDOWN = 15
const SERVICE_CONTROL_SESSIONCHANGE = 14
const SERVICE_CONTROL_SHUTDOWN = 5
const SERVICE_CONTROL_STATUS_REASON_INFO = 1
const SERVICE_CONTROL_STOP = 1
const SERVICE_CONTROL_SYSTEMLOWRESOURCES = 97
const SERVICE_CONTROL_TIMECHANGE = 16
const SERVICE_CONTROL_TRIGGEREVENT = 32
const SERVICE_CONTROL_USER_LOGOFF = 17
const SERVICE_DEMAND_START = 3
const SERVICE_DISABLED = 4
const SERVICE_DRIVER = 11
const SERVICE_DYNAMIC_INFORMATION_LEVEL_START_REASON = 1
const SERVICE_ENUMERATE_DEPENDENTS = 8
const SERVICE_ERROR_CRITICAL = 3
const SERVICE_ERROR_IGNORE = 0
const SERVICE_ERROR_NORMAL = 1
const SERVICE_ERROR_SEVERE = 2
const SERVICE_FILE_SYSTEM_DRIVER = 2
const SERVICE_INACTIVE = 2
const SERVICE_INTERACTIVE_PROCESS = 256
const SERVICE_INTERROGATE = 128
const SERVICE_KERNEL_DRIVER = 1
const SERVICE_LAUNCH_PROTECTED_ANTIMALWARE_LIGHT = 3
const SERVICE_LAUNCH_PROTECTED_NONE = 0
const SERVICE_LAUNCH_PROTECTED_WINDOWS = 1
const SERVICE_LAUNCH_PROTECTED_WINDOWS_LIGHT = 2
const SERVICE_NOTIFY_CONTINUE_PENDING = 16
const SERVICE_NOTIFY_CREATED = 128
const SERVICE_NOTIFY_DELETED = 256
const SERVICE_NOTIFY_DELETE_PENDING = 512
const SERVICE_NOTIFY_PAUSED = 64
const SERVICE_NOTIFY_PAUSE_PENDING = 32
const SERVICE_NOTIFY_RUNNING = 8
const SERVICE_NOTIFY_START_PENDING = 2
const SERVICE_NOTIFY_STATUS_CHANGE = 2
const SERVICE_NOTIFY_STATUS_CHANGE_1 = 1
const SERVICE_NOTIFY_STATUS_CHANGE_2 = 2
const SERVICE_NOTIFY_STOPPED = 1
const SERVICE_NOTIFY_STOP_PENDING = 4
const SERVICE_NO_CHANGE = 4294967295
const SERVICE_PAUSED = 7
const SERVICE_PAUSE_CONTINUE = 64
const SERVICE_PAUSE_PENDING = 6
const SERVICE_QUERY_CONFIG = 1
const SERVICE_QUERY_STATUS = 4
const SERVICE_RECOGNIZER_DRIVER = 8
const SERVICE_RUNNING = 4
const SERVICE_RUNS_IN_SYSTEM_PROCESS = 1
const SERVICE_SID_TYPE_NONE = 0
const SERVICE_SID_TYPE_RESTRICTED = 3
const SERVICE_SID_TYPE_UNRESTRICTED = 1
const SERVICE_START = 16
const SERVICE_START_PENDING = 2
const SERVICE_START_REASON_AUTO = 2
const SERVICE_START_REASON_DELAYEDAUTO = 16
const SERVICE_START_REASON_DEMAND = 1
const SERVICE_START_REASON_RESTART_ON_FAILURE = 8
const SERVICE_START_REASON_TRIGGER = 4
const SERVICE_STATE_ALL = 3
const SERVICE_STOP = 32
const SERVICE_STOPPED = 1
const SERVICE_STOP_PENDING = 3
const SERVICE_STOP_REASON_FLAG_CUSTOM = 536870912
const SERVICE_STOP_REASON_FLAG_MAX = 2147483648
const SERVICE_STOP_REASON_FLAG_MIN = 0
const SERVICE_STOP_REASON_FLAG_PLANNED = 1073741824
const SERVICE_STOP_REASON_FLAG_UNPLANNED = 268435456
const SERVICE_STOP_REASON_MAJOR_APPLICATION = 327680
const SERVICE_STOP_REASON_MAJOR_HARDWARE = 131072
const SERVICE_STOP_REASON_MAJOR_MAX = 458752
const SERVICE_STOP_REASON_MAJOR_MAX_CUSTOM = 16711680
const SERVICE_STOP_REASON_MAJOR_MIN = 0
const SERVICE_STOP_REASON_MAJOR_MIN_CUSTOM = 4194304
const SERVICE_STOP_REASON_MAJOR_NONE = 393216
const SERVICE_STOP_REASON_MAJOR_OPERATINGSYSTEM = 196608
const SERVICE_STOP_REASON_MAJOR_OTHER = 65536
const SERVICE_STOP_REASON_MAJOR_SOFTWARE = 262144
const SERVICE_STOP_REASON_MINOR_DISK = 8
const SERVICE_STOP_REASON_MINOR_ENVIRONMENT = 10
const SERVICE_STOP_REASON_MINOR_HARDWARE_DRIVER = 11
const SERVICE_STOP_REASON_MINOR_HUNG = 6
const SERVICE_STOP_REASON_MINOR_INSTALLATION = 3
const SERVICE_STOP_REASON_MINOR_MAINTENANCE = 2
const SERVICE_STOP_REASON_MINOR_MAX = 25
const SERVICE_STOP_REASON_MINOR_MAX_CUSTOM = 65535
const SERVICE_STOP_REASON_MINOR_MEMOTYLIMIT = 24
const SERVICE_STOP_REASON_MINOR_MIN = 0
const SERVICE_STOP_REASON_MINOR_MIN_CUSTOM = 256
const SERVICE_STOP_REASON_MINOR_MMC = 22
const SERVICE_STOP_REASON_MINOR_NETWORKCARD = 9
const SERVICE_STOP_REASON_MINOR_NETWORK_CONNECTIVITY = 17
const SERVICE_STOP_REASON_MINOR_NONE = 23
const SERVICE_STOP_REASON_MINOR_OTHER = 1
const SERVICE_STOP_REASON_MINOR_OTHERDRIVER = 12
const SERVICE_STOP_REASON_MINOR_RECONFIG = 5
const SERVICE_STOP_REASON_MINOR_SECURITY = 16
const SERVICE_STOP_REASON_MINOR_SECURITYFIX = 15
const SERVICE_STOP_REASON_MINOR_SECURITYFIX_UNINSTALL = 21
const SERVICE_STOP_REASON_MINOR_SERVICEPACK = 13
const SERVICE_STOP_REASON_MINOR_SERVICEPACK_UNINSTALL = 19
const SERVICE_STOP_REASON_MINOR_SOFTWARE_UPDATE = 14
const SERVICE_STOP_REASON_MINOR_SOFTWARE_UPDATE_UNINSTALL = 20
const SERVICE_STOP_REASON_MINOR_UNSTABLE = 7
const SERVICE_STOP_REASON_MINOR_UPGRADE = 4
const SERVICE_STOP_REASON_MINOR_WMI = 18
const SERVICE_SYSTEM_START = 1
const SERVICE_TRIGGER_DATA_TYPE_BINARY = 1
const SERVICE_TRIGGER_DATA_TYPE_KEYWORD_ALL = 5
const SERVICE_TRIGGER_DATA_TYPE_KEYWORD_ANY = 4
const SERVICE_TRIGGER_DATA_TYPE_LEVEL = 3
const SERVICE_TRIGGER_DATA_TYPE_STRING = 2
const SERVICE_TRIGGER_TYPE_AGGREGATE = 30
const SERVICE_TRIGGER_TYPE_CUSTOM = 20
const SERVICE_TRIGGER_TYPE_CUSTOM_SYSTEM_STATE_CHANGE = 7
const SERVICE_TRIGGER_TYPE_DEVICE_INTERFACE_ARRIVAL = 1
const SERVICE_TRIGGER_TYPE_DOMAIN_JOIN = 3
const SERVICE_TRIGGER_TYPE_FIREWALL_PORT_EVENT = 4
const SERVICE_TRIGGER_TYPE_GROUP_POLICY = 5
const SERVICE_TRIGGER_TYPE_IP_ADDRESS_AVAILABILITY = 2
const SERVICE_TRIGGER_TYPE_NETWORK_ENDPOINT = 6
const SERVICE_TYPE_ALL = 319
const SERVICE_USER_DEFINED_CONTROL = 256
const SERVICE_WIN32 = 48
const SERVICE_WIN32_OWN_PROCESS = 16
const SERVICE_WIN32_SHARE_PROCESS = 32
const SESSIONS_ROWID = "_rowid_"
const SESSIONS_STRM_CHUNK_SIZE = 1024
const SESSION_ABORTED = 6
const SESSION_ALL_ACCESS = 983043
const SESSION_ESTABLISHED = 3
const SESSION_MAX_BUFFER_SZ = 2147483391
const SESSION_MODIFY_ACCESS = 2
const SESSION_QUERY_ACCESS = 1
const SESSION_UPDATE_CACHE_SZ = 12
const SETABORTPROC = 9
const SETALLJUSTVALUES = 771
const SETBREAK = 8
const SETCHARSET = 772
const SETCOLORTABLE = 4
const SETCOPYCOUNT = 17
const SETDIBSCALING = 32
const SETDTR = 5
const SETICMPROFILE_EMBEDED = 1
const SETKERNTRACK = 770
const SETLINECAP = 21
const SETLINEJOIN = 22
const SETMITERLIMIT = 23
const SETRGBSTRINGA = "commdlg_SetRGBColor"
const SETRGBSTRINGW = "commdlg_SetRGBColor"
const SETRTS = 3
const SETWALLPAPER_DEFAULT = -1
const SETXOFF = 1
const SETXON = 2
const SET_ARC_DIRECTION = 4102
const SET_BACKGROUND_COLOR = 4103
const SET_BOUNDS = 4109
const SET_CLIP_BOX = 4108
const SET_FEATURE_IN_REGISTRY = 4
const SET_FEATURE_ON_PROCESS = 2
const SET_FEATURE_ON_THREAD = 1
const SET_FEATURE_ON_THREAD_INTERNET = 64
const SET_FEATURE_ON_THREAD_INTRANET = 16
const SET_FEATURE_ON_THREAD_LOCALMACHINE = 8
const SET_FEATURE_ON_THREAD_RESTRICTED = 128
const SET_FEATURE_ON_THREAD_TRUSTED = 32
const SET_MIRROR_MODE = 4110
const SET_POLY_MODE = 4104
const SET_REPAIR_DELETE_CROSSLINK = 4
const SET_REPAIR_DISABLED_AND_BUGCHECK_ON_CORRUPT = 16
const SET_REPAIR_ENABLED = 1
const SET_REPAIR_VALID_MASK = 31
const SET_REPAIR_VOLUME_BITMAP_SCAN = 2
const SET_REPAIR_WARN_ABOUT_DATA_LOSS = 8
const SET_SCREEN_ANGLE = 4105
const SET_SPREAD = 4106
const SET_TAPE_DRIVE_INFORMATION = 1
const SET_TAPE_MEDIA_INFORMATION = 0
const SEVERITY_ERROR = 1
const SEVERITY_SUCCESS = 0
const SE_DACL_AUTO_INHERITED = 1024
const SE_DACL_AUTO_INHERIT_REQ = 256
const SE_DACL_DEFAULTED = 8
const SE_DACL_PRESENT = 4
const SE_DACL_PROTECTED = 4096
const SE_ERR_ACCESSDENIED = 5
const SE_ERR_ASSOCINCOMPLETE = 27
const SE_ERR_DDEBUSY = 30
const SE_ERR_DDEFAIL = 29
const SE_ERR_DDETIMEOUT = 28
const SE_ERR_DLLNOTFOUND = 32
const SE_ERR_FNF = 2
const SE_ERR_NOASSOC = 31
const SE_ERR_OOM = 8
const SE_ERR_PNF = 3
const SE_ERR_SHARE = 26
const SE_GROUP_DEFAULTED = 2
const SE_GROUP_ENABLED = 4
const SE_GROUP_ENABLED_BY_DEFAULT = 2
const SE_GROUP_INTEGRITY = 32
const SE_GROUP_INTEGRITY_ENABLED = 64
const SE_GROUP_LOGON_ID = 3221225472
const SE_GROUP_MANDATORY = 1
const SE_GROUP_OWNER = 8
const SE_GROUP_RESOURCE = 536870912
const SE_GROUP_USE_FOR_DENY_ONLY = 16
const SE_GROUP_VALID_ATTRIBUTES = 3758096511
const SE_LEARNING_MODE_FLAG_PERMISSIVE = 1
const SE_OWNER_DEFAULTED = 1
const SE_PRIVILEGE_ENABLED = 2
const SE_PRIVILEGE_ENABLED_BY_DEFAULT = 1
const SE_PRIVILEGE_REMOVED = 4
const SE_PRIVILEGE_USED_FOR_ACCESS = 2147483648
const SE_PRIVILEGE_VALID_ATTRIBUTES = 2147483655
const SE_RM_CONTROL_VALID = 16384
const SE_SACL_AUTO_INHERITED = 2048
const SE_SACL_AUTO_INHERIT_REQ = 512
const SE_SACL_DEFAULTED = 32
const SE_SACL_PRESENT = 16
const SE_SACL_PROTECTED = 8192
const SE_SECURITY_DESCRIPTOR_FLAG_NO_LABEL_ACE = 2
const SE_SECURITY_DESCRIPTOR_FLAG_NO_OWNER_ACE = 1
const SE_SECURITY_DESCRIPTOR_VALID_FLAGS = 3
const SE_SELF_RELATIVE = 32768
const SF_Aggregate = 8
const SF_All = 2
const SF_ComplexResult = 262144
const SF_Compound = 256
const SF_Converted = 65536
const SF_CopyCte = 67108864
const SF_Correlated = 536870912
const SF_Distinct = 1
const SF_Expanded = 64
const SF_FixedLimit = 16384
const SF_HasAgg = 16
const SF_HasTypeInfo = 128
const SF_IncludeHidden = 131072
const SF_MaybeConvert = 32768
const SF_MinMaxAgg = 4096
const SF_MultiPart = 33554432
const SF_MultiValue = 1024
const SF_NestedFrom = 2048
const SF_NoopOrderBy = 4194304
const SF_OrderByReqd = 134217728
const SF_PushDown = 16777216
const SF_Recursive = 8192
const SF_Resolved = 4
const SF_UFSrcCheck = 8388608
const SF_UpdateFrom = 268435456
const SF_UsesEphemeral = 32
const SF_Values = 512
const SF_View = 2097152
const SF_WhereBegin = 524288
const SF_WinRewrite = 1048576
const SHADEBLENDCAPS = 120
const SHARED_FIRST = 2
const SHARED_LOCK = 1
const SHARED_SIZE = 510
const SHAREVISTRINGA = "commdlg_ShareViolation"
const SHAREVISTRINGW = "commdlg_ShareViolation"
const SHERB_NOCONFIRMATION = 1
const SHERB_NOPROGRESSUI = 2
const SHERB_NOSOUND = 4
const SHEmptyRecycleBin = 0
const SHEnumerateUnreadMailAccounts = 0
const SHFileOperation = 0
const SHGFI_ADDOVERLAYS = 32
const SHGFI_ATTRIBUTES = 2048
const SHGFI_ATTR_SPECIFIED = 131072
const SHGFI_DISPLAYNAME = 512
const SHGFI_EXETYPE = 8192
const SHGFI_ICON = 256
const SHGFI_ICONLOCATION = 4096
const SHGFI_LARGEICON = 0
const SHGFI_LINKOVERLAY = 32768
const SHGFI_OPENICON = 2
const SHGFI_OVERLAYINDEX = 64
const SHGFI_PIDL = 8
const SHGFI_SELECTED = 65536
const SHGFI_SHELLICONSIZE = 4
const SHGFI_SMALLICON = 1
const SHGFI_SYSICONINDEX = 16384
const SHGFI_TYPENAME = 1024
const SHGFI_USEFILEATTRIBUTES = 16
const SHGNLI_NOLNK = 8
const SHGNLI_NOLOCNAME = 16
const SHGNLI_NOUNIQUE = 4
const SHGNLI_PIDL = 1
const SHGNLI_PREFIXNAME = 2
const SHGNLI_USEURLEXT = 32
const SHGSI_ICON = 256
const SHGSI_ICONLOCATION = 0
const SHGSI_LARGEICON = 0
const SHGSI_LINKOVERLAY = 32768
const SHGSI_SELECTED = 65536
const SHGSI_SHELLICONSIZE = 4
const SHGSI_SMALLICON = 1
const SHGSI_SYSICONINDEX = 16384
const SHGetDiskFreeSpace = 0
const SHGetDiskFreeSpaceEx = 0
const SHGetFileInfo = 0
const SHGetNewLinkInfo = 0
const SHGetUnreadMailCount = 0
const SHIFTJIS_CHARSET = 128
const SHIFT_PRESSED = 16
const SHIL_EXTRALARGE = 2
const SHIL_JUMBO = 4
const SHIL_LARGE = 0
const SHIL_LAST = 4
const SHIL_SMALL = 1
const SHIL_SYSSMALL = 3
const SHInvokePrinterCommand = 0
const SHOW_FULLSCREEN = 3
const SHOW_ICONWINDOW = 2
const SHOW_OPENNOACTIVATE = 4
const SHOW_OPENWINDOW = 1
const SHQueryRecycleBin = 0
const SHSetUnreadMailCount = 0
const SHTDN_REASON_FLAG_CLEAN_UI = 67108864
const SHTDN_REASON_FLAG_COMMENT_REQUIRED = 16777216
const SHTDN_REASON_FLAG_DIRTY_PROBLEM_ID_REQUIRED = 33554432
const SHTDN_REASON_FLAG_DIRTY_UI = 134217728
const SHTDN_REASON_FLAG_PLANNED = 2147483648
const SHTDN_REASON_FLAG_USER_DEFINED = 1073741824
const SHTDN_REASON_LEGACY_API = 2147942400
const SHTDN_REASON_MAJOR_APPLICATION = 262144
const SHTDN_REASON_MAJOR_HARDWARE = 65536
const SHTDN_REASON_MAJOR_LEGACY_API = 458752
const SHTDN_REASON_MAJOR_NONE = 0
const SHTDN_REASON_MAJOR_OPERATINGSYSTEM = 131072
const SHTDN_REASON_MAJOR_OTHER = 0
const SHTDN_REASON_MAJOR_POWER = 393216
const SHTDN_REASON_MAJOR_SOFTWARE = 196608
const SHTDN_REASON_MAJOR_SYSTEM = 327680
const SHTDN_REASON_MINOR_BLUESCREEN = 15
const SHTDN_REASON_MINOR_CORDUNPLUGGED = 11
const SHTDN_REASON_MINOR_DC_DEMOTION = 34
const SHTDN_REASON_MINOR_DC_PROMOTION = 33
const SHTDN_REASON_MINOR_DISK = 7
const SHTDN_REASON_MINOR_ENVIRONMENT = 12
const SHTDN_REASON_MINOR_HARDWARE_DRIVER = 13
const SHTDN_REASON_MINOR_HOTFIX = 17
const SHTDN_REASON_MINOR_HOTFIX_UNINSTALL = 23
const SHTDN_REASON_MINOR_HUNG = 5
const SHTDN_REASON_MINOR_INSTALLATION = 2
const SHTDN_REASON_MINOR_MAINTENANCE = 1
const SHTDN_REASON_MINOR_MMC = 25
const SHTDN_REASON_MINOR_NETWORKCARD = 9
const SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY = 20
const SHTDN_REASON_MINOR_NONE = 255
const SHTDN_REASON_MINOR_OTHER = 0
const SHTDN_REASON_MINOR_OTHERDRIVER = 14
const SHTDN_REASON_MINOR_POWER_SUPPLY = 10
const SHTDN_REASON_MINOR_PROCESSOR = 8
const SHTDN_REASON_MINOR_RECONFIG = 4
const SHTDN_REASON_MINOR_SECURITY = 19
const SHTDN_REASON_MINOR_SECURITYFIX = 18
const SHTDN_REASON_MINOR_SECURITYFIX_UNINSTALL = 24
const SHTDN_REASON_MINOR_SERVICEPACK = 16
const SHTDN_REASON_MINOR_SERVICEPACK_UNINSTALL = 22
const SHTDN_REASON_MINOR_SYSTEMRESTORE = 26
const SHTDN_REASON_MINOR_TERMSRV = 32
const SHTDN_REASON_MINOR_UNSTABLE = 6
const SHTDN_REASON_MINOR_UPGRADE = 3
const SHTDN_REASON_MINOR_WMI = 21
const SHTDN_REASON_UNKNOWN = 255
const SHTDN_REASON_VALID_BIT_MASK = 3238002687
const SHUTDOWN_ARSO = 8192
const SHUTDOWN_FORCE_OTHERS = 1
const SHUTDOWN_FORCE_SELF = 2
const SHUTDOWN_GRACE_OVERRIDE = 32
const SHUTDOWN_HYBRID = 512
const SHUTDOWN_INSTALL_UPDATES = 64
const SHUTDOWN_MOBILE_UI = 4096
const SHUTDOWN_NOREBOOT = 16
const SHUTDOWN_NORETRY = 1
const SHUTDOWN_POWEROFF = 8
const SHUTDOWN_RESTART = 4
const SHUTDOWN_RESTARTAPPS = 128
const SHUTDOWN_RESTART_BOOTOPTIONS = 1024
const SHUTDOWN_SKIP_SVC_PRESHUTDOWN = 256
const SHUTDOWN_SOFT_REBOOT = 2048
const SHUTDOWN_TYPE_LEN = 32
const SID_HASH_SIZE = 32
const SID_IBindHost = 0
const SID_MAX_SUB_AUTHORITIES = 15
const SID_RECOMMENDED_SUB_AUTHORITIES = 1
const SID_REVISION = 1
const SID_SBindHost = 0
const SID_SInternetHostSecurityManager = 0
const SID_SInternetSecurityManager = 0
const SID_SInternetSecurityManagerEx = 0
const SID_SInternetSecurityManagerEx2 = 0
const SIF_ALL = 23
const SIF_DISABLENOSCROLL = 8
const SIF_PAGE = 2
const SIF_POS = 4
const SIF_RANGE = 1
const SIF_TRACKPOS = 16
const SIID_INVALID = -1
const SIMPLEBLOB = 1
const SIMPLEREGION = 2
const SIMULATED_FONTTYPE = 32768
const SING = 2
const SITE_PIN_RULES_ALL_SUBDOMAINS_FLAG = 1
const SIZEFULLSCREEN = 2
const SIZEICONIC = 1
const SIZENORMAL = 0
const SIZEOF_RFPO_DATA = 16
const SIZEPALETTE = 104
const SIZEZOOMHIDE = 4
const SIZEZOOMSHOW = 3
const SIZE_MAX = 4294967295
const SIZE_MAXHIDE = 4
const SIZE_MAXIMIZED = 2
const SIZE_MAXSHOW = 3
const SIZE_MINIMIZED = 1
const SIZE_OF_80387_REGISTERS = 80
const SIZE_RESTORED = 0
const SKF_AUDIBLEFEEDBACK = 64
const SKF_AVAILABLE = 2
const SKF_CONFIRMHOTKEY = 8
const SKF_HOTKEYACTIVE = 4
const SKF_HOTKEYSOUND = 16
const SKF_INDICATOR = 32
const SKF_LALTLATCHED = 268435456
const SKF_LALTLOCKED = 1048576
const SKF_LCTLLATCHED = 67108864
const SKF_LCTLLOCKED = 262144
const SKF_LSHIFTLATCHED = 16777216
const SKF_LSHIFTLOCKED = 65536
const SKF_LWINLATCHED = 1073741824
const SKF_LWINLOCKED = 4194304
const SKF_RALTLATCHED = 536870912
const SKF_RALTLOCKED = 2097152
const SKF_RCTLLATCHED = 134217728
const SKF_RCTLLOCKED = 524288
const SKF_RSHIFTLATCHED = 33554432
const SKF_RSHIFTLOCKED = 131072
const SKF_RWINLATCHED = 2147483648
const SKF_RWINLOCKED = 8388608
const SKF_STICKYKEYSON = 1
const SKF_TRISTATE = 128
const SKF_TWOKEYSOFF = 256
const SLE_ERROR = 1
const SLE_MINORERROR = 2
const SLE_WARNING = 3
const SLOT_2_0 = 2080895
const SLOT_4_2_0 = 4028612735
const SMART_ABORT_OFFLINE_SELFTEST = 127
const SMART_CMD = 176
const SMART_CYL_HI = 194
const SMART_CYL_LOW = 79
const SMART_ERROR_NO_MEM = 7
const SMART_EXTENDED_SELFTEST_CAPTIVE = 130
const SMART_EXTENDED_SELFTEST_OFFLINE = 2
const SMART_GET_VERSION = 475264
const SMART_IDE_ERROR = 1
const SMART_INVALID_BUFFER = 4
const SMART_INVALID_COMMAND = 3
const SMART_INVALID_DRIVE = 5
const SMART_INVALID_FLAG = 2
const SMART_INVALID_IOCTL = 6
const SMART_INVALID_REGISTER = 8
const SMART_LOG_SECTOR_SIZE = 512
const SMART_NOT_SUPPORTED = 9
const SMART_NO_ERROR = 0
const SMART_NO_IDE_DEVICE = 10
const SMART_OFFLINE_ROUTINE_OFFLINE = 0
const SMART_RCV_DRIVE_DATA = 508040
const SMART_READ_LOG = 213
const SMART_SEND_DRIVE_COMMAND = 508036
const SMART_SHORT_SELFTEST_CAPTIVE = 129
const SMART_SHORT_SELFTEST_OFFLINE = 1
const SMART_WRITE_LOG = 214
const SMTO_ABORTIFHUNG = 2
const SMTO_BLOCK = 1
const SMTO_ERRORONEXIT = 32
const SMTO_NORMAL = 0
const SMTO_NOTIMEOUTIFNOTHUNG = 8
const SM_ARRANGE = 56
const SM_CARETBLINKINGENABLED = 8194
const SM_CLEANBOOT = 67
const SM_CMETRICS = 97
const SM_CMONITORS = 80
const SM_CMOUSEBUTTONS = 43
const SM_CONVERTIBLESLATEMODE = 8195
const SM_CXBORDER = 5
const SM_CXCURSOR = 13
const SM_CXDLGFRAME = 7
const SM_CXDOUBLECLK = 36
const SM_CXDRAG = 68
const SM_CXEDGE = 45
const SM_CXFIXEDFRAME = 7
const SM_CXFOCUSBORDER = 83
const SM_CXFRAME = 32
const SM_CXFULLSCREEN = 16
const SM_CXHSCROLL = 21
const SM_CXHTHUMB = 10
const SM_CXICON = 11
const SM_CXICONSPACING = 38
const SM_CXMAXIMIZED = 61
const SM_CXMAXTRACK = 59
const SM_CXMENUCHECK = 71
const SM_CXMENUSIZE = 54
const SM_CXMIN = 28
const SM_CXMINIMIZED = 57
const SM_CXMINSPACING = 47
const SM_CXMINTRACK = 34
const SM_CXPADDEDBORDER = 92
const SM_CXSCREEN = 0
const SM_CXSIZE = 30
const SM_CXSIZEFRAME = 32
const SM_CXSMICON = 49
const SM_CXSMSIZE = 52
const SM_CXVIRTUALSCREEN = 78
const SM_CXVSCROLL = 2
const SM_CYBORDER = 6
const SM_CYCAPTION = 4
const SM_CYCURSOR = 14
const SM_CYDLGFRAME = 8
const SM_CYDOUBLECLK = 37
const SM_CYDRAG = 69
const SM_CYEDGE = 46
const SM_CYFIXEDFRAME = 8
const SM_CYFOCUSBORDER = 84
const SM_CYFRAME = 33
const SM_CYFULLSCREEN = 17
const SM_CYHSCROLL = 3
const SM_CYICON = 12
const SM_CYICONSPACING = 39
const SM_CYKANJIWINDOW = 18
const SM_CYMAXIMIZED = 62
const SM_CYMAXTRACK = 60
const SM_CYMENU = 15
const SM_CYMENUCHECK = 72
const SM_CYMENUSIZE = 55
const SM_CYMIN = 29
const SM_CYMINIMIZED = 58
const SM_CYMINSPACING = 48
const SM_CYMINTRACK = 35
const SM_CYSCREEN = 1
const SM_CYSIZE = 31
const SM_CYSIZEFRAME = 33
const SM_CYSMCAPTION = 51
const SM_CYSMICON = 50
const SM_CYSMSIZE = 53
const SM_CYVIRTUALSCREEN = 79
const SM_CYVSCROLL = 20
const SM_CYVTHUMB = 9
const SM_DBCSENABLED = 42
const SM_DEBUG = 22
const SM_DIGITIZER = 94
const SM_IMMENABLED = 82
const SM_MAXIMUMTOUCHES = 95
const SM_MEDIACENTER = 87
const SM_MENUDROPALIGNMENT = 40
const SM_MIDEASTENABLED = 74
const SM_MOUSEHORIZONTALWHEELPRESENT = 91
const SM_MOUSEPRESENT = 19
const SM_MOUSEWHEELPRESENT = 75
const SM_NETWORK = 63
const SM_PENWINDOWS = 41
const SM_REMOTECONTROL = 8193
const SM_REMOTESESSION = 4096
const SM_RESERVED1 = 24
const SM_RESERVED2 = 25
const SM_RESERVED3 = 26
const SM_RESERVED4 = 27
const SM_SAMEDISPLAYFORMAT = 81
const SM_SECURE = 44
const SM_SERVERR2 = 89
const SM_SHOWSOUNDS = 70
const SM_SHUTTINGDOWN = 8192
const SM_SLOWMACHINE = 73
const SM_STARTER = 88
const SM_SWAPBUTTON = 23
const SM_SYSTEMDOCKED = 8196
const SM_TABLETPC = 86
const SM_XVIRTUALSCREEN = 76
const SM_YVIRTUALSCREEN = 77
const SNAPSHOT_POLICY_ALWAYS = 1
const SNAPSHOT_POLICY_NEVER = 0
const SNAPSHOT_POLICY_UNPLANNED = 2
const SNDMSG = 0
const SND_ALIAS = 65536
const SND_ALIAS_ID = 1114112
const SND_ALIAS_START = 0
const SND_APPLICATION = 128
const SND_ASYNC = 1
const SND_FILENAME = 131072
const SND_LOOP = 8
const SND_MEMORY = 4
const SND_NODEFAULT = 2
const SND_NOSTOP = 16
const SND_NOWAIT = 8192
const SND_PURGE = 64
const SND_RESOURCE = 262148
const SND_SYNC = 0
const SOCKET_ERROR = -1
const SOCK_DGRAM = 2
const SOCK_RAW = 3
const SOCK_RDM = 4
const SOCK_SEQPACKET = 5
const SOCK_STREAM = 1
const SOFTDIST_ADSTATE_AVAILABLE = 1
const SOFTDIST_ADSTATE_DOWNLOADED = 2
const SOFTDIST_ADSTATE_INSTALLED = 3
const SOFTDIST_ADSTATE_NONE = 0
const SOFTDIST_FLAG_DELETE_SUBSCRIPTION = 8
const SOFTDIST_FLAG_USAGE_AUTOINSTALL = 4
const SOFTDIST_FLAG_USAGE_EMAIL = 1
const SOFTDIST_FLAG_USAGE_PRECACHE = 2
const SOFTKEYBOARD_TYPE_C1 = 2
const SOFTKEYBOARD_TYPE_T1 = 1
const SOL_SOCKET = 65535
const SOMAXCONN = 5
const SORTED_CTL_EXT_COUNT_OFFSET = 4
const SORTED_CTL_EXT_FLAGS_OFFSET = 0
const SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG = 1
const SORTED_CTL_EXT_HASH_BUCKET_OFFSET = 12
const SORTED_CTL_EXT_MAX_COLLISION_OFFSET = 8
const SORTER_MAX_MERGE_COUNT = 16
const SORTER_TYPE_INTEGER = 1
const SORTER_TYPE_TEXT = 2
const SORTFLAG_UseSorter = 1
const SORT_CHINESE_BIG5 = 0
const SORT_CHINESE_BOPOMOFO = 3
const SORT_CHINESE_PRC = 2
const SORT_CHINESE_PRCP = 0
const SORT_CHINESE_RADICALSTROKE = 4
const SORT_CHINESE_UNICODE = 1
const SORT_DEFAULT = 0
const SORT_DIGITSASNUMBERS = 8
const SORT_GEORGIAN_MODERN = 1
const SORT_GEORGIAN_TRADITIONAL = 0
const SORT_GERMAN_PHONE_BOOK = 1
const SORT_HUNGARIAN_DEFAULT = 0
const SORT_HUNGARIAN_TECHNICAL = 1
const SORT_INVARIANT_MATH = 1
const SORT_JAPANESE_RADICALSTROKE = 4
const SORT_JAPANESE_UNICODE = 1
const SORT_JAPANESE_XJIS = 0
const SORT_KOREAN_KSC = 0
const SORT_KOREAN_UNICODE = 1
const SORT_STRINGSORT = 4096
const SOUND_SYSTEM_APPEND = 14
const SOUND_SYSTEM_APPSTART = 12
const SOUND_SYSTEM_BEEP = 3
const SOUND_SYSTEM_ERROR = 4
const SOUND_SYSTEM_FAULT = 13
const SOUND_SYSTEM_INFORMATION = 7
const SOUND_SYSTEM_MAXIMIZE = 8
const SOUND_SYSTEM_MENUCOMMAND = 15
const SOUND_SYSTEM_MENUPOPUP = 16
const SOUND_SYSTEM_MINIMIZE = 9
const SOUND_SYSTEM_QUESTION = 5
const SOUND_SYSTEM_RESTOREDOWN = 11
const SOUND_SYSTEM_RESTOREUP = 10
const SOUND_SYSTEM_SHUTDOWN = 2
const SOUND_SYSTEM_STARTUP = 1
const SOUND_SYSTEM_WARNING = 6
const SO_ACCEPTCONN = 2
const SO_BROADCAST = 32
const SO_CONNDATA = 28672
const SO_CONNDATALEN = 28676
const SO_CONNECT_TIME = 28684
const SO_CONNOPT = 28673
const SO_CONNOPTLEN = 28677
const SO_DEBUG = 1
const SO_DISCDATA = 28674
const SO_DISCDATALEN = 28678
const SO_DISCOPT = 28675
const SO_DISCOPTLEN = 28679
const SO_DONTROUTE = 16
const SO_ERROR = 4103
const SO_KEEPALIVE = 8
const SO_LINGER = 128
const SO_MAXDG = 28681
const SO_MAXPATHDG = 28682
const SO_OOBINLINE = 256
const SO_OPENTYPE = 28680
const SO_RCVBUF = 4098
const SO_RCVLOWAT = 4100
const SO_RCVTIMEO = 4102
const SO_REUSEADDR = 4
const SO_SNDBUF = 4097
const SO_SNDLOWAT = 4099
const SO_SNDTIMEO = 4101
const SO_SYNCHRONOUS_ALERT = 16
const SO_SYNCHRONOUS_NONALERT = 32
const SO_TYPE = 4104
const SO_UPDATE_ACCEPT_CONTEXT = 28683
const SO_USELOOPBACK = 64
const SPACEPARITY = 4
const SPCLPASSTHROUGH2 = 4568
const SPECIFIC_RIGHTS_ALL = 65535
const SPIF_SENDCHANGE = 2
const SPIF_SENDWININICHANGE = 2
const SPIF_UPDATEINIFILE = 1
const SPILLFLAG_NOSYNC = 4
const SPILLFLAG_OFF = 1
const SPILLFLAG_ROLLBACK = 2
const SPI_GETACCESSTIMEOUT = 60
const SPI_GETACTIVEWINDOWTRACKING = 4096
const SPI_GETACTIVEWNDTRKTIMEOUT = 8194
const SPI_GETACTIVEWNDTRKZORDER = 4108
const SPI_GETANIMATION = 72
const SPI_GETAUDIODESCRIPTION = 116
const SPI_GETBEEP = 1
const SPI_GETBLOCKSENDINPUTRESETS = 4134
const SPI_GETBORDER = 5
const SPI_GETCARETBROWSING = 4172
const SPI_GETCARETWIDTH = 8198
const SPI_GETCLEARTYPE = 4168
const SPI_GETCLIENTAREAANIMATION = 4162
const SPI_GETCOMBOBOXANIMATION = 4100
const SPI_GETCONTACTVISUALIZATION = 8216
const SPI_GETCURSORSHADOW = 4122
const SPI_GETDEFAULTINPUTLANG = 89
const SPI_GETDESKWALLPAPER = 115
const SPI_GETDISABLEOVERLAPPEDCONTENT = 4160
const SPI_GETDOCKMOVING = 144
const SPI_GETDRAGFROMMAXIMIZE = 140
const SPI_GETDRAGFULLWINDOWS = 38
const SPI_GETDROPSHADOW = 4132
const SPI_GETFASTTASKSWITCH = 35
const SPI_GETFILTERKEYS = 50
const SPI_GETFLATMENU = 4130
const SPI_GETFOCUSBORDERHEIGHT = 8208
const SPI_GETFOCUSBORDERWIDTH = 8206
const SPI_GETFONTSMOOTHING = 74
const SPI_GETFONTSMOOTHINGCONTRAST = 8204
const SPI_GETFONTSMOOTHINGORIENTATION = 8210
const SPI_GETFONTSMOOTHINGTYPE = 8202
const SPI_GETFOREGROUNDFLASHCOUNT = 8196
const SPI_GETFOREGROUNDLOCKTIMEOUT = 8192
const SPI_GETGESTUREVISUALIZATION = 8218
const SPI_GETGRADIENTCAPTIONS = 4104
const SPI_GETGRIDGRANULARITY = 18
const SPI_GETHIGHCONTRAST = 66
const SPI_GETHOTTRACKING = 4110
const SPI_GETHUNGAPPTIMEOUT = 120
const SPI_GETICONMETRICS = 45
const SPI_GETICONTITLELOGFONT = 31
const SPI_GETICONTITLEWRAP = 25
const SPI_GETKEYBOARDCUES = 4106
const SPI_GETKEYBOARDDELAY = 22
const SPI_GETKEYBOARDPREF = 68
const SPI_GETKEYBOARDSPEED = 10
const SPI_GETLISTBOXSMOOTHSCROLLING = 4102
const SPI_GETLOGICALDPIOVERRIDE = 158
const SPI_GETLOWPOWERACTIVE = 83
const SPI_GETLOWPOWERTIMEOUT = 79
const SPI_GETMENUANIMATION = 4098
const SPI_GETMENUDROPALIGNMENT = 27
const SPI_GETMENUFADE = 4114
const SPI_GETMENURECT = 162
const SPI_GETMENUSHOWDELAY = 106
const SPI_GETMENUUNDERLINES = 4106
const SPI_GETMESSAGEDURATION = 8214
const SPI_GETMINIMIZEDMETRICS = 43
const SPI_GETMINIMUMHITRADIUS = 8212
const SPI_GETMOUSE = 3
const SPI_GETMOUSECLICKLOCK = 4126
const SPI_GETMOUSECLICKLOCKTIME = 8200
const SPI_GETMOUSECORNERCLIPLENGTH = 160
const SPI_GETMOUSEDOCKTHRESHOLD = 126
const SPI_GETMOUSEDRAGOUTTHRESHOLD = 132
const SPI_GETMOUSEHOVERHEIGHT = 100
const SPI_GETMOUSEHOVERTIME = 102
const SPI_GETMOUSEHOVERWIDTH = 98
const SPI_GETMOUSEKEYS = 54
const SPI_GETMOUSESIDEMOVETHRESHOLD = 136
const SPI_GETMOUSESONAR = 4124
const SPI_GETMOUSESPEED = 112
const SPI_GETMOUSETRAILS = 94
const SPI_GETMOUSEVANISH = 4128
const SPI_GETMOUSEWHEELROUTING = 8220
const SPI_GETNONCLIENTMETRICS = 41
const SPI_GETPENARBITRATIONTYPE = 8224
const SPI_GETPENDOCKTHRESHOLD = 128
const SPI_GETPENDRAGOUTTHRESHOLD = 134
const SPI_GETPENSIDEMOVETHRESHOLD = 138
const SPI_GETPENVISUALIZATION = 8222
const SPI_GETPOWEROFFACTIVE = 84
const SPI_GETPOWEROFFTIMEOUT = 80
const SPI_GETSCREENREADER = 70
const SPI_GETSCREENSAVEACTIVE = 16
const SPI_GETSCREENSAVERRUNNING = 114
const SPI_GETSCREENSAVESECURE = 118
const SPI_GETSCREENSAVETIMEOUT = 14
const SPI_GETSELECTIONFADE = 4116
const SPI_GETSERIALKEYS = 62
const SPI_GETSHOWIMEUI = 110
const SPI_GETSHOWSOUNDS = 56
const SPI_GETSNAPSIZING = 142
const SPI_GETSNAPTODEFBUTTON = 95
const SPI_GETSOUNDSENTRY = 64
const SPI_GETSPEECHRECOGNITION = 4170
const SPI_GETSTICKYKEYS = 58
const SPI_GETSYSTEMLANGUAGEBAR = 4176
const SPI_GETTHREADLOCALINPUTSETTINGS = 4174
const SPI_GETTOGGLEKEYS = 52
const SPI_GETTOOLTIPANIMATION = 4118
const SPI_GETTOOLTIPFADE = 4120
const SPI_GETTOUCHPREDICTIONPARAMETERS = 156
const SPI_GETUIEFFECTS = 4158
const SPI_GETWAITTOKILLSERVICETIMEOUT = 124
const SPI_GETWAITTOKILLTIMEOUT = 122
const SPI_GETWHEELSCROLLCHARS = 108
const SPI_GETWHEELSCROLLLINES = 104
const SPI_GETWINARRANGING = 130
const SPI_GETWINDOWSEXTENSION = 92
const SPI_GETWORKAREA = 48
const SPI_ICONHORIZONTALSPACING = 13
const SPI_ICONVERTICALSPACING = 24
const SPI_LANGDRIVER = 12
const SPI_SCREENSAVERRUNNING = 97
const SPI_SETACCESSTIMEOUT = 61
const SPI_SETACTIVEWINDOWTRACKING = 4097
const SPI_SETACTIVEWNDTRKTIMEOUT = 8195
const SPI_SETACTIVEWNDTRKZORDER = 4109
const SPI_SETANIMATION = 73
const SPI_SETAUDIODESCRIPTION = 117
const SPI_SETBEEP = 2
const SPI_SETBLOCKSENDINPUTRESETS = 4135
const SPI_SETBORDER = 6
const SPI_SETCARETBROWSING = 4173
const SPI_SETCARETWIDTH = 8199
const SPI_SETCLEARTYPE = 4169
const SPI_SETCLIENTAREAANIMATION = 4163
const SPI_SETCOMBOBOXANIMATION = 4101
const SPI_SETCONTACTVISUALIZATION = 8217
const SPI_SETCURSORS = 87
const SPI_SETCURSORSHADOW = 4123
const SPI_SETDEFAULTINPUTLANG = 90
const SPI_SETDESKPATTERN = 21
const SPI_SETDESKWALLPAPER = 20
const SPI_SETDISABLEOVERLAPPEDCONTENT = 4161
const SPI_SETDOCKMOVING = 145
const SPI_SETDOUBLECLICKTIME = 32
const SPI_SETDOUBLECLKHEIGHT = 30
const SPI_SETDOUBLECLKWIDTH = 29
const SPI_SETDRAGFROMMAXIMIZE = 141
const SPI_SETDRAGFULLWINDOWS = 37
const SPI_SETDRAGHEIGHT = 77
const SPI_SETDRAGWIDTH = 76
const SPI_SETDROPSHADOW = 4133
const SPI_SETFASTTASKSWITCH = 36
const SPI_SETFILTERKEYS = 51
const SPI_SETFLATMENU = 4131
const SPI_SETFOCUSBORDERHEIGHT = 8209
const SPI_SETFOCUSBORDERWIDTH = 8207
const SPI_SETFONTSMOOTHING = 75
const SPI_SETFONTSMOOTHINGCONTRAST = 8205
const SPI_SETFONTSMOOTHINGORIENTATION = 8211
const SPI_SETFONTSMOOTHINGTYPE = 8203
const SPI_SETFOREGROUNDFLASHCOUNT = 8197
const SPI_SETFOREGROUNDLOCKTIMEOUT = 8193
const SPI_SETGESTUREVISUALIZATION = 8219
const SPI_SETGRADIENTCAPTIONS = 4105
const SPI_SETGRIDGRANULARITY = 19
const SPI_SETHANDHELD = 78
const SPI_SETHIGHCONTRAST = 67
const SPI_SETHOTTRACKING = 4111
const SPI_SETHUNGAPPTIMEOUT = 121
const SPI_SETICONMETRICS = 46
const SPI_SETICONS = 88
const SPI_SETICONTITLELOGFONT = 34
const SPI_SETICONTITLEWRAP = 26
const SPI_SETKEYBOARDCUES = 4107
const SPI_SETKEYBOARDDELAY = 23
const SPI_SETKEYBOARDPREF = 69
const SPI_SETKEYBOARDSPEED = 11
const SPI_SETLANGTOGGLE = 91
const SPI_SETLISTBOXSMOOTHSCROLLING = 4103
const SPI_SETLOGICALDPIOVERRIDE = 159
const SPI_SETLOWPOWERACTIVE = 85
const SPI_SETLOWPOWERTIMEOUT = 81
const SPI_SETMENUANIMATION = 4099
const SPI_SETMENUDROPALIGNMENT = 28
const SPI_SETMENUFADE = 4115
const SPI_SETMENURECT = 163
const SPI_SETMENUSHOWDELAY = 107
const SPI_SETMENUUNDERLINES = 4107
const SPI_SETMESSAGEDURATION = 8215
const SPI_SETMINIMIZEDMETRICS = 44
const SPI_SETMINIMUMHITRADIUS = 8213
const SPI_SETMOUSE = 4
const SPI_SETMOUSEBUTTONSWAP = 33
const SPI_SETMOUSECLICKLOCK = 4127
const SPI_SETMOUSECLICKLOCKTIME = 8201
const SPI_SETMOUSECORNERCLIPLENGTH = 161
const SPI_SETMOUSEDOCKTHRESHOLD = 127
const SPI_SETMOUSEDRAGOUTTHRESHOLD = 133
const SPI_SETMOUSEHOVERHEIGHT = 101
const SPI_SETMOUSEHOVERTIME = 103
const SPI_SETMOUSEHOVERWIDTH = 99
const SPI_SETMOUSEKEYS = 55
const SPI_SETMOUSESIDEMOVETHRESHOLD = 137
const SPI_SETMOUSESONAR = 4125
const SPI_SETMOUSESPEED = 113
const SPI_SETMOUSETRAILS = 93
const SPI_SETMOUSEVANISH = 4129
const SPI_SETMOUSEWHEELROUTING = 8221
const SPI_SETNONCLIENTMETRICS = 42
const SPI_SETPENARBITRATIONTYPE = 8225
const SPI_SETPENDOCKTHRESHOLD = 129
const SPI_SETPENDRAGOUTTHRESHOLD = 135
const SPI_SETPENSIDEMOVETHRESHOLD = 139
const SPI_SETPENVISUALIZATION = 8223
const SPI_SETPENWINDOWS = 49
const SPI_SETPOWEROFFACTIVE = 86
const SPI_SETPOWEROFFTIMEOUT = 82
const SPI_SETSCREENREADER = 71
const SPI_SETSCREENSAVEACTIVE = 17
const SPI_SETSCREENSAVERRUNNING = 97
const SPI_SETSCREENSAVESECURE = 119
const SPI_SETSCREENSAVETIMEOUT = 15
const SPI_SETSELECTIONFADE = 4117
const SPI_SETSERIALKEYS = 63
const SPI_SETSHOWIMEUI = 111
const SPI_SETSHOWSOUNDS = 57
const SPI_SETSNAPSIZING = 143
const SPI_SETSNAPTODEFBUTTON = 96
const SPI_SETSOUNDSENTRY = 65
const SPI_SETSPEECHRECOGNITION = 4171
const SPI_SETSTICKYKEYS = 59
const SPI_SETSYSTEMLANGUAGEBAR = 4177
const SPI_SETTHREADLOCALINPUTSETTINGS = 4175
const SPI_SETTOGGLEKEYS = 53
const SPI_SETTOOLTIPANIMATION = 4119
const SPI_SETTOOLTIPFADE = 4121
const SPI_SETTOUCHPREDICTIONPARAMETERS = 157
const SPI_SETUIEFFECTS = 4159
const SPI_SETWAITTOKILLSERVICETIMEOUT = 125
const SPI_SETWAITTOKILLTIMEOUT = 123
const SPI_SETWHEELSCROLLCHARS = 109
const SPI_SETWHEELSCROLLLINES = 105
const SPI_SETWINARRANGING = 131
const SPI_SETWORKAREA = 47
const SPOINTER_32 = 0
const SPOOL_FILE_PERSISTENT = 1
const SPOOL_FILE_TEMPORARY = 2
const SPVERSION_MASK = 65280
const SP_APPABORT = -2
const SP_ERROR = -1
const SP_NOTREPORTED = 16384
const SP_OUTOFDISK = -4
const SP_OUTOFMEMORY = -5
const SP_USERABORT = -3
const SQLITE3_TEXT = 3
const SQLITE_ABORT = 4
const SQLITE_ABORT_ROLLBACK = 516
const SQLITE_ACCESS_EXISTS = 0
const SQLITE_ACCESS_READ = 2
const SQLITE_ACCESS_READWRITE = 1
const SQLITE_AFF_BLOB = 65
const SQLITE_AFF_FLEXNUM = 70
const SQLITE_AFF_INTEGER = 68
const SQLITE_AFF_MASK = 71
const SQLITE_AFF_NONE = 64
const SQLITE_AFF_NUMERIC = 67
const SQLITE_AFF_REAL = 69
const SQLITE_AFF_TEXT = 66
const SQLITE_ALLOW_COVERING_INDEX_SCAN = 1
const SQLITE_ALTER_TABLE = 26
const SQLITE_AMALGAMATION = 1
const SQLITE_ANALYZE = 28
const SQLITE_ANY = 5
const SQLITE_ASCII = 1
const SQLITE_ATOMIC_INTRINSICS = 1
const SQLITE_ATTACH = 24
const SQLITE_AUTH = 23
const SQLITE_AUTH_USER = 279
const SQLITE_AllOpts = 4294967295
const SQLITE_AutoIndex = 32768
const SQLITE_BIGENDIAN = 0
const SQLITE_BIG_DBL = 1e+99
const SQLITE_BLDF1_INDEXED = 1
const SQLITE_BLDF1_UNIQUE = 2
const SQLITE_BLDF2_2NDPASS = 4
const SQLITE_BLOB = 4
const SQLITE_BUSY = 5
const SQLITE_BUSY_RECOVERY = 261
const SQLITE_BUSY_SNAPSHOT = 517
const SQLITE_BUSY_TIMEOUT = 773
const SQLITE_BYTEORDER = 1234
const SQLITE_BalancedMerge = 2097152
const SQLITE_BloomFilter = 524288
const SQLITE_BloomPulldown = 1048576
const SQLITE_CANTOPEN = 14
const SQLITE_CANTOPEN_BKPT = 0
const SQLITE_CANTOPEN_CONVPATH = 1038
const SQLITE_CANTOPEN_DIRTYWAL = 1294
const SQLITE_CANTOPEN_FULLPATH = 782
const SQLITE_CANTOPEN_ISDIR = 526
const SQLITE_CANTOPEN_NOTEMPDIR = 270
const SQLITE_CANTOPEN_SYMLINK = 1550
const SQLITE_CHANGESETAPPLY_FKNOACTION = 8
const SQLITE_CHANGESETAPPLY_IGNORENOOP = 4
const SQLITE_CHANGESETAPPLY_INVERT = 2
const SQLITE_CHANGESETAPPLY_NOSAVEPOINT = 1
const SQLITE_CHANGESETSTART_INVERT = 2
const SQLITE_CHANGESET_ABORT = 2
const SQLITE_CHANGESET_CONFLICT = 3
const SQLITE_CHANGESET_CONSTRAINT = 4
const SQLITE_CHANGESET_DATA = 1
const SQLITE_CHANGESET_FOREIGN_KEY = 5
const SQLITE_CHANGESET_NOTFOUND = 2
const SQLITE_CHANGESET_OMIT = 0
const SQLITE_CHANGESET_REPLACE = 1
const SQLITE_CHECKPOINT_FULL = 1
const SQLITE_CHECKPOINT_PASSIVE = 0
const SQLITE_CHECKPOINT_RESTART = 2
const SQLITE_CHECKPOINT_TRUNCATE = 3
const SQLITE_CONFIG_COVERING_INDEX_SCAN = 20
const SQLITE_CONFIG_GETMALLOC = 5
const SQLITE_CONFIG_GETMUTEX = 11
const SQLITE_CONFIG_GETPCACHE = 15
const SQLITE_CONFIG_GETPCACHE2 = 19
const SQLITE_CONFIG_HEAP = 8
const SQLITE_CONFIG_LOG = 16
const SQLITE_CONFIG_LOOKASIDE = 13
const SQLITE_CONFIG_MALLOC = 4
const SQLITE_CONFIG_MEMDB_MAXSIZE = 29
const SQLITE_CONFIG_MEMSTATUS = 9
const SQLITE_CONFIG_MMAP_SIZE = 22
const SQLITE_CONFIG_MULTITHREAD = 2
const SQLITE_CONFIG_MUTEX = 10
const SQLITE_CONFIG_PAGECACHE = 7
const SQLITE_CONFIG_PCACHE = 14
const SQLITE_CONFIG_PCACHE2 = 18
const SQLITE_CONFIG_PCACHE_HDRSZ = 24
const SQLITE_CONFIG_PMASZ = 25
const SQLITE_CONFIG_ROWID_IN_VIEW = 30
const SQLITE_CONFIG_SCRATCH = 6
const SQLITE_CONFIG_SERIALIZED = 3
const SQLITE_CONFIG_SINGLETHREAD = 1
const SQLITE_CONFIG_SMALL_MALLOC = 27
const SQLITE_CONFIG_SORTERREF_SIZE = 28
const SQLITE_CONFIG_SQLLOG = 21
const SQLITE_CONFIG_STMTJRNL_SPILL = 26
const SQLITE_CONFIG_URI = 17
const SQLITE_CONFIG_WIN32_HEAPSIZE = 23
const SQLITE_CONSTRAINT = 19
const SQLITE_CONSTRAINT_CHECK = 275
const SQLITE_CONSTRAINT_COMMITHOOK = 531
const SQLITE_CONSTRAINT_DATATYPE = 3091
const SQLITE_CONSTRAINT_FOREIGNKEY = 787
const SQLITE_CONSTRAINT_FUNCTION = 1043
const SQLITE_CONSTRAINT_NOTNULL = 1299
const SQLITE_CONSTRAINT_PINNED = 2835
const SQLITE_CONSTRAINT_PRIMARYKEY = 1555
const SQLITE_CONSTRAINT_ROWID = 2579
const SQLITE_CONSTRAINT_TRIGGER = 1811
const SQLITE_CONSTRAINT_UNIQUE = 2067
const SQLITE_CONSTRAINT_VTAB = 2323
const SQLITE_COPY = 0
const SQLITE_CORE = 1
const SQLITE_CORRUPT = 11
const SQLITE_CORRUPT_BKPT = 0
const SQLITE_CORRUPT_INDEX = 779
const SQLITE_CORRUPT_SEQUENCE = 523
const SQLITE_CORRUPT_VTAB = 267
const SQLITE_CREATE_INDEX = 1
const SQLITE_CREATE_TABLE = 2
const SQLITE_CREATE_TEMP_INDEX = 3
const SQLITE_CREATE_TEMP_TABLE = 4
const SQLITE_CREATE_TEMP_TRIGGER = 5
const SQLITE_CREATE_TEMP_VIEW = 6
const SQLITE_CREATE_TRIGGER = 7
const SQLITE_CREATE_VIEW = 8
const SQLITE_CREATE_VTABLE = 29
const SQLITE_CacheSpill = 32
const SQLITE_CellSizeCk = 2097152
const SQLITE_CkptFullFSync = 16
const SQLITE_Coroutines = 33554432
const SQLITE_CountOfView = 512
const SQLITE_CoverIdxScan = 32
const SQLITE_CursorHints = 1024
const SQLITE_DBCONFIG_DEFENSIVE = 1010
const SQLITE_DBCONFIG_DQS_DDL = 1014
const SQLITE_DBCONFIG_DQS_DML = 1013
const SQLITE_DBCONFIG_ENABLE_FKEY = 1002
const SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004
const SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005
const SQLITE_DBCONFIG_ENABLE_QPSG = 1007
const SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003
const SQLITE_DBCONFIG_ENABLE_VIEW = 1015
const SQLITE_DBCONFIG_LEGACY_ALTER_TABLE = 1012
const SQLITE_DBCONFIG_LEGACY_FILE_FORMAT = 1016
const SQLITE_DBCONFIG_LOOKASIDE = 1001
const SQLITE_DBCONFIG_MAINDBNAME = 1000
const SQLITE_DBCONFIG_MAX = 1019
const SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE = 1006
const SQLITE_DBCONFIG_RESET_DATABASE = 1009
const SQLITE_DBCONFIG_REVERSE_SCANORDER = 1019
const SQLITE_DBCONFIG_STMT_SCANSTATUS = 1018
const SQLITE_DBCONFIG_TRIGGER_EQP = 1008
const SQLITE_DBCONFIG_TRUSTED_SCHEMA = 1017
const SQLITE_DBCONFIG_WRITABLE_SCHEMA = 1011
const SQLITE_DBSTATUS_CACHE_HIT = 7
const SQLITE_DBSTATUS_CACHE_MISS = 8
const SQLITE_DBSTATUS_CACHE_SPILL = 12
const SQLITE_DBSTATUS_CACHE_USED = 1
const SQLITE_DBSTATUS_CACHE_USED_SHARED = 11
const SQLITE_DBSTATUS_CACHE_WRITE = 9
const SQLITE_DBSTATUS_DEFERRED_FKS = 10
const SQLITE_DBSTATUS_LOOKASIDE_HIT = 4
const SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL = 6
const SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE = 5
const SQLITE_DBSTATUS_LOOKASIDE_USED = 0
const SQLITE_DBSTATUS_MAX = 12
const SQLITE_DBSTATUS_SCHEMA_USED = 2
const SQLITE_DBSTATUS_STMT_USED = 3
const SQLITE_DEFAULT_AUTOVACUUM = 0
const SQLITE_DEFAULT_CACHE_SIZE = -2000
const SQLITE_DEFAULT_FILE_FORMAT = 4
const SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT = -1
const SQLITE_DEFAULT_LOOKASIDE = 40
const SQLITE_DEFAULT_MEMSTATUS = 0
const SQLITE_DEFAULT_MMAP_SIZE = 0
const SQLITE_DEFAULT_OPTIMIZE_LIMIT = 2000
const SQLITE_DEFAULT_PAGE_SIZE = 4096
const SQLITE_DEFAULT_PCACHE_INITSZ = 20
const SQLITE_DEFAULT_RECURSIVE_TRIGGERS = 0
const SQLITE_DEFAULT_SECTOR_SIZE = 4096
const SQLITE_DEFAULT_SORTERREF_SIZE = 2147483647
const SQLITE_DEFAULT_SYNCHRONOUS = 2
const SQLITE_DEFAULT_WAL_AUTOCHECKPOINT = 1000
const SQLITE_DEFAULT_WAL_SYNCHRONOUS = 2
const SQLITE_DEFAULT_WORKER_THREADS = 0
const SQLITE_DELETE = 9
const SQLITE_DENY = 1
const SQLITE_DESERIALIZE_FREEONCLOSE = 1
const SQLITE_DESERIALIZE_READONLY = 4
const SQLITE_DESERIALIZE_RESIZEABLE = 2
const SQLITE_DETACH = 25
const SQLITE_DETERMINISTIC = 2048
const SQLITE_DIGIT_SEPARATOR = 95
const SQLITE_DIRECTONLY = 524288
const SQLITE_DIRECT_OVERFLOW_READ = 1
const SQLITE_DONE = 101
const SQLITE_DQS = 3
const SQLITE_DROP_INDEX = 10
const SQLITE_DROP_TABLE = 11
const SQLITE_DROP_TEMP_INDEX = 12
const SQLITE_DROP_TEMP_TABLE = 13
const SQLITE_DROP_TEMP_TRIGGER = 14
const SQLITE_DROP_TEMP_VIEW = 15
const SQLITE_DROP_TRIGGER = 16
const SQLITE_DROP_VIEW = 17
const SQLITE_DROP_VTABLE = 30
const SQLITE_Defensive = 268435456
const SQLITE_DeferFKs = 524288
const SQLITE_DistinctOpt = 16
const SQLITE_DqsDDL = 536870912
const SQLITE_DqsDML = 1073741824
const SQLITE_ECEL_DUP = 1
const SQLITE_ECEL_FACTOR = 2
const SQLITE_ECEL_OMITREF = 8
const SQLITE_ECEL_REF = 4
const SQLITE_EMPTY = 16
const SQLITE_ENABLE_COLUMN_METADATA = 1
const SQLITE_ENABLE_DBSTAT_VTAB = 1
const SQLITE_ENABLE_FTS5 = 1
const SQLITE_ENABLE_GEOPOLY = 1
const SQLITE_ENABLE_JSON1 = 1
const SQLITE_ENABLE_LOCKING_STYLE = 0
const SQLITE_ENABLE_MATH_FUNCTIONS = 1
const SQLITE_ENABLE_MEMORY_MANAGEMENT = 1
const SQLITE_ENABLE_OFFSET_SQL_FUNC = 1
const SQLITE_ENABLE_PREUPDATE_HOOK = 1
const SQLITE_ENABLE_RBU = 1
const SQLITE_ENABLE_RTREE = 1
const SQLITE_ENABLE_SESSION = 1
const SQLITE_ENABLE_SNAPSHOT = 1
const SQLITE_ENABLE_STAT4 = 1
const SQLITE_ENABLE_UNLOCK_NOTIFY = 1
const SQLITE_ERROR = 1
const SQLITE_ERROR_MISSING_COLLSEQ = 257
const SQLITE_ERROR_RETRY = 513
const SQLITE_ERROR_SNAPSHOT = 769
const SQLITE_EXTERN = 0
const SQLITE_EnableQPSG = 8388608
const SQLITE_EnableTrigger = 262144
const SQLITE_EnableView = 2147483648
const SQLITE_FAIL = 3
const SQLITE_FAULTINJECTOR_COUNT = 1
const SQLITE_FAULTINJECTOR_MALLOC = 0
const SQLITE_FCNTL_BEGIN_ATOMIC_WRITE = 31
const SQLITE_FCNTL_BUSYHANDLER = 15
const SQLITE_FCNTL_CHUNK_SIZE = 6
const SQLITE_FCNTL_CKPT_DONE = 37
const SQLITE_FCNTL_CKPT_START = 39
const SQLITE_FCNTL_CKSM_FILE = 41
const SQLITE_FCNTL_COMMIT_ATOMIC_WRITE = 32
const SQLITE_FCNTL_COMMIT_PHASETWO = 22
const SQLITE_FCNTL_DATA_VERSION = 35
const SQLITE_FCNTL_DB_UNCHANGED = 3389603744
const SQLITE_FCNTL_EXTERNAL_READER = 40
const SQLITE_FCNTL_FILE_POINTER = 7
const SQLITE_FCNTL_GET_LOCKPROXYFILE = 2
const SQLITE_FCNTL_HAS_MOVED = 20
const SQLITE_FCNTL_JOURNAL_POINTER = 28
const SQLITE_FCNTL_LAST_ERRNO = 4
const SQLITE_FCNTL_LOCKSTATE = 1
const SQLITE_FCNTL_LOCK_TIMEOUT = 34
const SQLITE_FCNTL_MMAP_SIZE = 18
const SQLITE_FCNTL_OVERWRITE = 11
const SQLITE_FCNTL_PDB = 30
const SQLITE_FCNTL_PERSIST_WAL = 10
const SQLITE_FCNTL_POWERSAFE_OVERWRITE = 13
const SQLITE_FCNTL_PRAGMA = 14
const SQLITE_FCNTL_RBU = 26
const SQLITE_FCNTL_RBUCNT = 5149216
const SQLITE_FCNTL_RESERVE_BYTES = 38
const SQLITE_FCNTL_RESET_CACHE = 42
const SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE = 33
const SQLITE_FCNTL_SET_LOCKPROXYFILE = 3
const SQLITE_FCNTL_SIZE_HINT = 5
const SQLITE_FCNTL_SIZE_LIMIT = 36
const SQLITE_FCNTL_SYNC = 21
const SQLITE_FCNTL_SYNC_OMITTED = 8
const SQLITE_FCNTL_TEMPFILENAME = 16
const SQLITE_FCNTL_TRACE = 19
const SQLITE_FCNTL_VFSNAME = 12
const SQLITE_FCNTL_VFS_POINTER = 27
const SQLITE_FCNTL_WAL_BLOCK = 24
const SQLITE_FCNTL_WIN32_AV_RETRY = 9
const SQLITE_FCNTL_WIN32_GET_HANDLE = 29
const SQLITE_FCNTL_WIN32_SET_HANDLE = 23
const SQLITE_FCNTL_ZIPVFS = 25
const SQLITE_FILE_HEADER = "SQLite format 3"
const SQLITE_FLOAT = 2
const SQLITE_FORMAT = 24
const SQLITE_FP_PRECISION_LIMIT = 100000000
const SQLITE_FRAME_MAGIC = 2275391262
const SQLITE_FTS5_MAX_EXPR_DEPTH = 256
const SQLITE_FULL = 13
const SQLITE_FUNCTION = 31
const SQLITE_FUNC_ANYORDER = 134217728
const SQLITE_FUNC_BUILTIN = 8388608
const SQLITE_FUNC_BYTELEN = 192
const SQLITE_FUNC_CASE = 8
const SQLITE_FUNC_CONSTANT = 2048
const SQLITE_FUNC_COUNT = 256
const SQLITE_FUNC_DIRECT = 524288
const SQLITE_FUNC_ENCMASK = 3
const SQLITE_FUNC_EPHEM = 16
const SQLITE_FUNC_HASH_SZ = 23
const SQLITE_FUNC_INLINE = 4194304
const SQLITE_FUNC_INTERNAL = 262144
const SQLITE_FUNC_LENGTH = 64
const SQLITE_FUNC_LIKE = 4
const SQLITE_FUNC_MINMAX = 4096
const SQLITE_FUNC_NEEDCOLL = 32
const SQLITE_FUNC_RUNONLY = 32768
const SQLITE_FUNC_SLOCHNG = 8192
const SQLITE_FUNC_TEST = 16384
const SQLITE_FUNC_TYPEOF = 128
const SQLITE_FUNC_UNLIKELY = 1024
const SQLITE_FUNC_UNSAFE = 2097152
const SQLITE_FUNC_WINDOW = 65536
const SQLITE_FactorOutConst = 8
const SQLITE_FlttnUnionAll = 8388608
const SQLITE_ForeignKeys = 16384
const SQLITE_Fts3Tokenizer = 4194304
const SQLITE_FullColNames = 4
const SQLITE_FullFSync = 8
const SQLITE_GET_LOCKPROXYFILE = 2
const SQLITE_GroupByOrder = 4
const SQLITE_HAVE_C99_MATH_FUNCS = 1
const SQLITE_HAVE_ZLIB = 1
const SQLITE_IDXTYPE_APPDEF = 0
const SQLITE_IDXTYPE_IPK = 3
const SQLITE_IDXTYPE_PRIMARYKEY = 2
const SQLITE_IDXTYPE_UNIQUE = 1
const SQLITE_IGNORE = 2
const SQLITE_INDEX_CONSTRAINT_EQ = 2
const SQLITE_INDEX_CONSTRAINT_FUNCTION = 150
const SQLITE_INDEX_CONSTRAINT_GE = 32
const SQLITE_INDEX_CONSTRAINT_GLOB = 66
const SQLITE_INDEX_CONSTRAINT_GT = 4
const SQLITE_INDEX_CONSTRAINT_IS = 72
const SQLITE_INDEX_CONSTRAINT_ISNOT = 69
const SQLITE_INDEX_CONSTRAINT_ISNOTNULL = 70
const SQLITE_INDEX_CONSTRAINT_ISNULL = 71
const SQLITE_INDEX_CONSTRAINT_LE = 8
const SQLITE_INDEX_CONSTRAINT_LIKE = 65
const SQLITE_INDEX_CONSTRAINT_LIMIT = 73
const SQLITE_INDEX_CONSTRAINT_LT = 16
const SQLITE_INDEX_CONSTRAINT_MATCH = 64
const SQLITE_INDEX_CONSTRAINT_NE = 68
const SQLITE_INDEX_CONSTRAINT_OFFSET = 74
const SQLITE_INDEX_CONSTRAINT_REGEXP = 67
const SQLITE_INDEX_SCAN_UNIQUE = 1
const SQLITE_INNOCUOUS = 2097152
const SQLITE_INSERT = 18
const SQLITE_INTEGER = 1
const SQLITE_INTEGRITY_CHECK_ERROR_MAX = 100
const SQLITE_INTERNAL = 2
const SQLITE_INTERRUPT = 9
const SQLITE_IOCAP_ATOMIC = 1
const SQLITE_IOCAP_ATOMIC16K = 64
const SQLITE_IOCAP_ATOMIC1K = 4
const SQLITE_IOCAP_ATOMIC2K = 8
const SQLITE_IOCAP_ATOMIC32K = 128
const SQLITE_IOCAP_ATOMIC4K = 16
const SQLITE_IOCAP_ATOMIC512 = 2
const SQLITE_IOCAP_ATOMIC64K = 256
const SQLITE_IOCAP_ATOMIC8K = 32
const SQLITE_IOCAP_BATCH_ATOMIC = 16384
const SQLITE_IOCAP_IMMUTABLE = 8192
const SQLITE_IOCAP_POWERSAFE_OVERWRITE = 4096
const SQLITE_IOCAP_SAFE_APPEND = 512
const SQLITE_IOCAP_SEQUENTIAL = 1024
const SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN = 2048
const SQLITE_IOERR = 10
const SQLITE_IOERR_ACCESS = 3338
const SQLITE_IOERR_AUTH = 7178
const SQLITE_IOERR_BEGIN_ATOMIC = 7434
const SQLITE_IOERR_BLOCKED = 2826
const SQLITE_IOERR_CHECKRESERVEDLOCK = 3594
const SQLITE_IOERR_CLOSE = 4106
const SQLITE_IOERR_COMMIT_ATOMIC = 7690
const SQLITE_IOERR_CONVPATH = 6666
const SQLITE_IOERR_CORRUPTFS = 8458
const SQLITE_IOERR_DATA = 8202
const SQLITE_IOERR_DELETE = 2570
const SQLITE_IOERR_DELETE_NOENT = 5898
const SQLITE_IOERR_DIR_CLOSE = 4362
const SQLITE_IOERR_DIR_FSYNC = 1290
const SQLITE_IOERR_FSTAT = 1802
const SQLITE_IOERR_FSYNC = 1034
const SQLITE_IOERR_GETTEMPPATH = 6410
const SQLITE_IOERR_IN_PAGE = 8714
const SQLITE_IOERR_LOCK = 3850
const SQLITE_IOERR_MMAP = 6154
const SQLITE_IOERR_NOMEM = 3082
const SQLITE_IOERR_NOMEM_BKPT = 3082
const SQLITE_IOERR_RDLOCK = 2314
const SQLITE_IOERR_READ = 266
const SQLITE_IOERR_ROLLBACK_ATOMIC = 7946
const SQLITE_IOERR_SEEK = 5642
const SQLITE_IOERR_SHMLOCK = 5130
const SQLITE_IOERR_SHMMAP = 5386
const SQLITE_IOERR_SHMOPEN = 4618
const SQLITE_IOERR_SHMSIZE = 4874
const SQLITE_IOERR_SHORT_READ = 522
const SQLITE_IOERR_TRUNCATE = 1546
const SQLITE_IOERR_UNLOCK = 2058
const SQLITE_IOERR_VNODE = 6922
const SQLITE_IOERR_WRITE = 778
const SQLITE_IgnoreChecks = 512
const SQLITE_IndexedExpr = 16777216
const SQLITE_JUMPIFNULL = 16
const SQLITE_LAST_ERRNO = 4
const SQLITE_LIKE_DOESNT_MATCH_BLOBS = 1
const SQLITE_LIMIT_ATTACHED = 7
const SQLITE_LIMIT_COLUMN = 2
const SQLITE_LIMIT_COMPOUND_SELECT = 4
const SQLITE_LIMIT_EXPR_DEPTH = 3
const SQLITE_LIMIT_FUNCTION_ARG = 6
const SQLITE_LIMIT_LENGTH = 0
const SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8
const SQLITE_LIMIT_SQL_LENGTH = 1
const SQLITE_LIMIT_TRIGGER_DEPTH = 10
const SQLITE_LIMIT_VARIABLE_NUMBER = 9
const SQLITE_LIMIT_VDBE_OP = 5
const SQLITE_LIMIT_WORKER_THREADS = 11
const SQLITE_LITTLEENDIAN = 1
const SQLITE_LOCKED = 6
const SQLITE_LOCKED_SHAREDCACHE = 262
const SQLITE_LOCKED_VTAB = 518
const SQLITE_LOCKFILEEX_FLAGS = 1
const SQLITE_LOCKFILE_FLAGS = 3
const SQLITE_LOCK_EXCLUSIVE = 4
const SQLITE_LOCK_NONE = 0
const SQLITE_LOCK_PENDING = 3
const SQLITE_LOCK_RESERVED = 2
const SQLITE_LOCK_SHARED = 1
const SQLITE_LegacyAlter = 67108864
const SQLITE_LegacyFileFmt = 2
const SQLITE_LoadExtFunc = 131072
const SQLITE_LoadExtension = 65536
const SQLITE_MALLOC_SOFT_LIMIT = 1024
const SQLITE_MATCH = 0
const SQLITE_MAX_ALLOCATION_SIZE = 2147483391
const SQLITE_MAX_ATTACHED = 10
const SQLITE_MAX_COLUMN = 2000
const SQLITE_MAX_COMPOUND_SELECT = 500
const SQLITE_MAX_DB = 12
const SQLITE_MAX_DEFAULT_PAGE_SIZE = 8192
const SQLITE_MAX_EXPR_DEPTH = 1000
const SQLITE_MAX_FILE_FORMAT = 4
const SQLITE_MAX_FUNCTION_ARG = 127
const SQLITE_MAX_LENGTH = 1000000000
const SQLITE_MAX_LIKE_PATTERN_LENGTH = 50000
const SQLITE_MAX_MEMORY = 0
const SQLITE_MAX_MMAP_SIZE = 2147418112
const SQLITE_MAX_PAGE_COUNT = 4294967294
const SQLITE_MAX_PAGE_SIZE = 65536
const SQLITE_MAX_PATHLEN = 260
const SQLITE_MAX_PMASZ = 536870912
const SQLITE_MAX_PREPARE_RETRY = 25
const SQLITE_MAX_SCHEMA_RETRY = 50
const SQLITE_MAX_SQL_LENGTH = 1000000000
const SQLITE_MAX_SRCLIST = 200
const SQLITE_MAX_SYMLINK = 200
const SQLITE_MAX_TRIGGER_DEPTH = 1000
const SQLITE_MAX_VARIABLE_NUMBER = 32766
const SQLITE_MAX_VDBE_OP = 250000000
const SQLITE_MAX_WORKER_THREADS = 8
const SQLITE_MEMDB_DEFAULT_MAXSIZE = 1073741824
const SQLITE_MISMATCH = 20
const SQLITE_MISUSE = 21
const SQLITE_MISUSE_BKPT = 0
const SQLITE_MUTEX_FAST = 0
const SQLITE_MUTEX_RECURSIVE = 1
const SQLITE_MUTEX_STATIC_APP1 = 8
const SQLITE_MUTEX_STATIC_APP2 = 9
const SQLITE_MUTEX_STATIC_APP3 = 10
const SQLITE_MUTEX_STATIC_LRU = 6
const SQLITE_MUTEX_STATIC_LRU2 = 7
const SQLITE_MUTEX_STATIC_MAIN = 2
const SQLITE_MUTEX_STATIC_MASTER = 2
const SQLITE_MUTEX_STATIC_MEM = 3
const SQLITE_MUTEX_STATIC_MEM2 = 4
const SQLITE_MUTEX_STATIC_OPEN = 4
const SQLITE_MUTEX_STATIC_PMEM = 7
const SQLITE_MUTEX_STATIC_PRNG = 5
const SQLITE_MUTEX_STATIC_TEMPDIR = 11
const SQLITE_MUTEX_STATIC_VFS1 = 11
const SQLITE_MUTEX_STATIC_VFS2 = 12
const SQLITE_MUTEX_STATIC_VFS3 = 13
const SQLITE_MX_JUMP_OPCODE = 64
const SQLITE_MinMaxOpt = 65536
const SQLITE_NOLFS = 22
const SQLITE_NOMATCH = 1
const SQLITE_NOMEM = 7
const SQLITE_NOMEM_BKPT = 7
const SQLITE_NOTADB = 26
const SQLITE_NOTFOUND = 12
const SQLITE_NOTICE = 27
const SQLITE_NOTICE_RBU = 795
const SQLITE_NOTICE_RECOVER_ROLLBACK = 539
const SQLITE_NOTICE_RECOVER_WAL = 283
const SQLITE_NOTNULL = 144
const SQLITE_NOWILDCARDMATCH = 2
const SQLITE_NTUNE = 6
const SQLITE_NULL = 5
const SQLITE_NULLEQ = 128
const SQLITE_N_BTREE_META = 16
const SQLITE_N_KEYWORD = 147
const SQLITE_N_LIMIT = 12
const SQLITE_N_STDTYPE = 6
const SQLITE_NoCkptOnClose = 2048
const SQLITE_NoSchemaError = 134217728
const SQLITE_NullCallback = 256
const SQLITE_NullUnusedCols = 67108864
const SQLITE_OK = 0
const SQLITE_OK_LOAD_PERMANENTLY = 256
const SQLITE_OK_SYMLINK = 512
const SQLITE_OMIT_SEH = 1
const SQLITE_OPEN_AUTOPROXY = 32
const SQLITE_OPEN_CREATE = 4
const SQLITE_OPEN_DELETEONCLOSE = 8
const SQLITE_OPEN_EXCLUSIVE = 16
const SQLITE_OPEN_EXRESCODE = 33554432
const SQLITE_OPEN_FULLMUTEX = 65536
const SQLITE_OPEN_MAIN_DB = 256
const SQLITE_OPEN_MAIN_JOURNAL = 2048
const SQLITE_OPEN_MASTER_JOURNAL = 16384
const SQLITE_OPEN_MEMORY = 128
const SQLITE_OPEN_NOFOLLOW = 16777216
const SQLITE_OPEN_NOMUTEX = 32768
const SQLITE_OPEN_PRIVATECACHE = 262144
const SQLITE_OPEN_READONLY = 1
const SQLITE_OPEN_READWRITE = 2
const SQLITE_OPEN_SHAREDCACHE = 131072
const SQLITE_OPEN_SUBJOURNAL = 8192
const SQLITE_OPEN_SUPER_JOURNAL = 16384
const SQLITE_OPEN_TEMP_DB = 512
const SQLITE_OPEN_TEMP_JOURNAL = 4096
const SQLITE_OPEN_TRANSIENT_DB = 1024
const SQLITE_OPEN_URI = 64
const SQLITE_OPEN_WAL = 524288
const SQLITE_OS_WIN = 1
const SQLITE_OS_WINCE = 0
const SQLITE_OS_WINNT = 1
const SQLITE_OS_WINRT = 0
const SQLITE_OS_WIN_THREADS = 1
const SQLITE_OmitNoopJoin = 256
const SQLITE_OmitOrderBy = 262144
const SQLITE_OnePass = 134217728
const SQLITE_OrderByIdxJoin = 64
const SQLITE_PERM = 3
const SQLITE_POWERSAFE_OVERWRITE = 1
const SQLITE_PRAGMA = 19
const SQLITE_PREPARE_MASK = 15
const SQLITE_PREPARE_NORMALIZE = 2
const SQLITE_PREPARE_NO_VTAB = 4
const SQLITE_PREPARE_PERSISTENT = 1
const SQLITE_PREPARE_SAVESQL = 128
const SQLITE_PRINTF_INTERNAL = 1
const SQLITE_PRINTF_MALLOCED = 4
const SQLITE_PRINTF_SQLFUNC = 2
const SQLITE_PRINT_BUF_SIZE = 70
const SQLITE_PRIVATE = 0
const SQLITE_PROTOCOL = 15
const SQLITE_PTRSIZE = 4
const SQLITE_PropagateConst = 32768
const SQLITE_PushDown = 4096
const SQLITE_QUERY_PLANNER_LIMIT = 20000
const SQLITE_QUERY_PLANNER_LIMIT_INCR = 1000
const SQLITE_QueryFlattener = 1
const SQLITE_QueryOnly = 1048576
const SQLITE_RANGE = 25
const SQLITE_RBU_STATE_CHECKPOINT = 3
const SQLITE_RBU_STATE_DONE = 4
const SQLITE_RBU_STATE_ERROR = 5
const SQLITE_RBU_STATE_MOVE = 2
const SQLITE_RBU_STATE_OAL = 1
const SQLITE_RBU_UPDATE_CACHESIZE = 16
const SQLITE_READ = 20
const SQLITE_READONLY = 8
const SQLITE_READONLY_CANTINIT = 1288
const SQLITE_READONLY_CANTLOCK = 520
const SQLITE_READONLY_DBMOVED = 1032
const SQLITE_READONLY_DIRECTORY = 1544
const SQLITE_READONLY_RECOVERY = 264
const SQLITE_READONLY_ROLLBACK = 776
const SQLITE_RECURSIVE = 33
const SQLITE_REINDEX = 27
const SQLITE_REPLACE = 5
const SQLITE_RESULT_SUBTYPE = 16777216
const SQLITE_ROLLBACK = 1
const SQLITE_ROW = 100
const SQLITE_RecTriggers = 8192
const SQLITE_ReleaseReg = 4194304
const SQLITE_ResetDatabase = 33554432
const SQLITE_ReverseOrder = 4096
const SQLITE_SAVEPOINT = 32
const SQLITE_SCANSTAT_COMPLEX = 1
const SQLITE_SCANSTAT_EST = 2
const SQLITE_SCANSTAT_EXPLAIN = 4
const SQLITE_SCANSTAT_NAME = 3
const SQLITE_SCANSTAT_NCYCLE = 7
const SQLITE_SCANSTAT_NLOOP = 0
const SQLITE_SCANSTAT_NVISIT = 1
const SQLITE_SCANSTAT_PARENTID = 6
const SQLITE_SCANSTAT_SELECTID = 5
const SQLITE_SCHEMA = 17
const SQLITE_SELECT = 21
const SQLITE_SERIALIZE_NOCOPY = 1
const SQLITE_SESSION_CONFIG_STRMSIZE = 1
const SQLITE_SESSION_OBJCONFIG_ROWID = 2
const SQLITE_SESSION_OBJCONFIG_SIZE = 1
const SQLITE_SET_LOCKPROXYFILE = 3
const SQLITE_SHM_EXCLUSIVE = 8
const SQLITE_SHM_LOCK = 2
const SQLITE_SHM_NLOCK = 8
const SQLITE_SHM_SHARED = 4
const SQLITE_SHM_UNLOCK = 1
const SQLITE_SORTER_PMASZ = 250
const SQLITE_SOUNDEX = 1
const SQLITE_SOURCE_ID = "2024-05-23 13:25:27 96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e"
const SQLITE_SO_ASC = 0
const SQLITE_SO_DESC = 1
const SQLITE_SO_UNDEFINED = -1
const SQLITE_STAT4_SAMPLES = 24
const SQLITE_STATE_BUSY = 109
const SQLITE_STATE_CLOSED = 206
const SQLITE_STATE_ERROR = 213
const SQLITE_STATE_OPEN = 118
const SQLITE_STATE_SICK = 186
const SQLITE_STATE_ZOMBIE = 167
const SQLITE_STATUS_MALLOC_COUNT = 9
const SQLITE_STATUS_MALLOC_SIZE = 5
const SQLITE_STATUS_MEMORY_USED = 0
const SQLITE_STATUS_PAGECACHE_OVERFLOW = 2
const SQLITE_STATUS_PAGECACHE_SIZE = 7
const SQLITE_STATUS_PAGECACHE_USED = 1
const SQLITE_STATUS_PARSER_STACK = 6
const SQLITE_STATUS_SCRATCH_OVERFLOW = 4
const SQLITE_STATUS_SCRATCH_SIZE = 8
const SQLITE_STATUS_SCRATCH_USED = 3
const SQLITE_STDCALL = 0
const SQLITE_STMTJRNL_SPILL = 65536
const SQLITE_STMTSTATUS_AUTOINDEX = 3
const SQLITE_STMTSTATUS_FILTER_HIT = 8
const SQLITE_STMTSTATUS_FILTER_MISS = 7
const SQLITE_STMTSTATUS_FULLSCAN_STEP = 1
const SQLITE_STMTSTATUS_MEMUSED = 99
const SQLITE_STMTSTATUS_REPREPARE = 5
const SQLITE_STMTSTATUS_RUN = 6
const SQLITE_STMTSTATUS_SORT = 2
const SQLITE_STMTSTATUS_VM_STEP = 4
const SQLITE_SUBTYPE = 1048576
const SQLITE_SYNC_DATAONLY = 16
const SQLITE_SYNC_FULL = 3
const SQLITE_SYNC_NORMAL = 2
const SQLITE_SYSTEM_MALLOC = 1
const SQLITE_SeekScan = 131072
const SQLITE_ShortColNames = 64
const SQLITE_SimplifyJoin = 8192
const SQLITE_SkipScan = 16384
const SQLITE_Stat4 = 2048
const SQLITE_StmtScanStatus = 1024
const SQLITE_TEMP_FILE_PREFIX = "etilqs_"
const SQLITE_TEMP_STORE = 1
const SQLITE_TESTCTRL_ALWAYS = 13
const SQLITE_TESTCTRL_ASSERT = 12
const SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS = 10
const SQLITE_TESTCTRL_BITVEC_TEST = 8
const SQLITE_TESTCTRL_BYTEORDER = 22
const SQLITE_TESTCTRL_EXPLAIN_STMT = 19
const SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS = 29
const SQLITE_TESTCTRL_FAULT_INSTALL = 9
const SQLITE_TESTCTRL_FIRST = 5
const SQLITE_TESTCTRL_FK_NO_ACTION = 7
const SQLITE_TESTCTRL_IMPOSTER = 25
const SQLITE_TESTCTRL_INTERNAL_FUNCTIONS = 17
const SQLITE_TESTCTRL_ISINIT = 23
const SQLITE_TESTCTRL_ISKEYWORD = 16
const SQLITE_TESTCTRL_JSON_SELFCHECK = 14
const SQLITE_TESTCTRL_LAST = 34
const SQLITE_TESTCTRL_LOCALTIME_FAULT = 18
const SQLITE_TESTCTRL_LOGEST = 33
const SQLITE_TESTCTRL_NEVER_CORRUPT = 20
const SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD = 19
const SQLITE_TESTCTRL_OPTIMIZATIONS = 15
const SQLITE_TESTCTRL_PARSER_COVERAGE = 26
const SQLITE_TESTCTRL_PENDING_BYTE = 11
const SQLITE_TESTCTRL_PRNG_RESET = 7
const SQLITE_TESTCTRL_PRNG_RESTORE = 6
const SQLITE_TESTCTRL_PRNG_SAVE = 5
const SQLITE_TESTCTRL_PRNG_SEED = 28
const SQLITE_TESTCTRL_RESERVE = 14
const SQLITE_TESTCTRL_RESULT_INTREAL = 27
const SQLITE_TESTCTRL_SCRATCHMALLOC = 17
const SQLITE_TESTCTRL_SEEK_COUNT = 30
const SQLITE_TESTCTRL_SORTER_MMAP = 24
const SQLITE_TESTCTRL_TRACEFLAGS = 31
const SQLITE_TESTCTRL_TUNE = 32
const SQLITE_TESTCTRL_USELONGDOUBLE = 34
const SQLITE_TESTCTRL_VDBE_COVERAGE = 21
const SQLITE_TEXT = 3
const SQLITE_THREADSAFE = 1
const SQLITE_THREADS_IMPLEMENTED = 1
const SQLITE_TOKEN_KEYWORD = 2
const SQLITE_TOKEN_QUOTED = 1
const SQLITE_TOOBIG = 18
const SQLITE_TRACE_CLOSE = 8
const SQLITE_TRACE_LEGACY = 64
const SQLITE_TRACE_NONLEGACY_MASK = 15
const SQLITE_TRACE_PROFILE = 2
const SQLITE_TRACE_ROW = 4
const SQLITE_TRACE_STMT = 1
const SQLITE_TRACE_XPROFILE = 128
const SQLITE_TRANSACTION = 22
const SQLITE_TXN_NONE = 0
const SQLITE_TXN_READ = 1
const SQLITE_TXN_WRITE = 2
const SQLITE_Transitive = 128
const SQLITE_TriggerEQP = 16777216
const SQLITE_TrustedSchema = 128
const SQLITE_UPDATE = 23
const SQLITE_USE_URI = 0
const SQLITE_UTF16 = 4
const SQLITE_UTF16BE = 3
const SQLITE_UTF16LE = 2
const SQLITE_UTF16NATIVE = 2
const SQLITE_UTF16_ALIGNED = 8
const SQLITE_UTF8 = 1
const SQLITE_VERSION = "3.46.0"
const SQLITE_VERSION_NUMBER = 3046000
const SQLITE_VTABRISK_High = 2
const SQLITE_VTABRISK_Low = 0
const SQLITE_VTABRISK_Normal = 1
const SQLITE_VTAB_CONSTRAINT_SUPPORT = 1
const SQLITE_VTAB_DIRECTONLY = 3
const SQLITE_VTAB_INNOCUOUS = 2
const SQLITE_VTAB_USES_ALL_SCHEMAS = 4
const SQLITE_WARNING = 28
const SQLITE_WARNING_AUTOINDEX = 284
const SQLITE_WIN32_CREATEFILEMAPPINGA = 0
const SQLITE_WIN32_DATA_DIRECTORY_TYPE = 1
const SQLITE_WIN32_GETVERSIONEX = 0
const SQLITE_WIN32_IOERR_RETRY = 10
const SQLITE_WIN32_IOERR_RETRY_DELAY = 25
const SQLITE_WIN32_MAX_ERRMSG_CHARS = 1024
const SQLITE_WIN32_MAX_PATH_BYTES = 1040
const SQLITE_WIN32_MAX_PATH_CHARS = 260
const SQLITE_WIN32_TEMP_DIRECTORY_TYPE = 2
const SQLITE_WIN32_VOLATILE = 0
const SQLITE_WINNT_MAX_PATH_BYTES = 0
const SQLITE_WINNT_MAX_PATH_CHARS = 32767
const SQLITE_WITHOUT_ZONEMALLOC = 1
const SQLITE_WindowFunc = 2
const SQLITE_WriteSchema = 1
const SRB_TYPE_SCSI_REQUEST_BLOCK = 0
const SRB_TYPE_STORAGE_REQUEST_BLOCK = 1
const SRT_Coroutine = 13
const SRT_Discard = 4
const SRT_DistFifo = 5
const SRT_DistQueue = 6
const SRT_EphemTab = 12
const SRT_Except = 2
const SRT_Exists = 3
const SRT_Fifo = 8
const SRT_Mem = 10
const SRT_Output = 9
const SRT_Queue = 7
const SRT_Set = 11
const SRT_Table = 14
const SRT_Union = 1
const SRT_Upfrom = 15
const SRWLOCK_INIT = "RTL_SRWLOCK_INIT"
const SSF_AVAILABLE = 2
const SSF_INDICATOR = 4
const SSF_SOUNDSENTRYON = 1
const SSGF_DISPLAY = 3
const SSGF_NONE = 0
const SSIZE_MAX = 2147483647
const SSL_ECCPUBLIC_BLOB = "SSLECCPUBLICBLOB"
const SSL_F12_ERROR_TEXT_LENGTH = 256
const SSL_HPKP_HEADER_COUNT = 2
const SSL_HPKP_PKP_HEADER_INDEX = 0
const SSL_HPKP_PKP_RO_HEADER_INDEX = 1
const SSL_KEY_PIN_ERROR_TEXT_LENGTH = 512
const SSL_OBJECT_LOCATOR_CERT_VALIDATION_CONFIG_FUNC = "SslObjectLocatorInitializeCertValidationConfig"
const SSL_OBJECT_LOCATOR_ISSUER_LIST_FUNC = "SslObjectLocatorInitializeIssuerList"
const SSL_OBJECT_LOCATOR_PFX_FUNC = "SslObjectLocatorInitializePfx"
const SSTF_BORDER = 2
const SSTF_CHARS = 1
const SSTF_DISPLAY = 3
const SSTF_NONE = 0
const SSWF_CUSTOM = 4
const SSWF_DISPLAY = 3
const SSWF_NONE = 0
const SSWF_TITLE = 1
const SSWF_WINDOW = 2
const SS_BITMAP = 14
const SS_BLACKFRAME = 7
const SS_BLACKRECT = 4
const SS_CENTER = 1
const SS_CENTERIMAGE = 512
const SS_EDITCONTROL = 8192
const SS_ELLIPSISMASK = 49152
const SS_ENDELLIPSIS = 16384
const SS_ENHMETAFILE = 15
const SS_ETCHEDFRAME = 18
const SS_ETCHEDHORZ = 16
const SS_ETCHEDVERT = 17
const SS_GRAYFRAME = 8
const SS_GRAYRECT = 5
const SS_ICON = 3
const SS_LEFT = 0
const SS_LEFTNOWORDWRAP = 12
const SS_NOPREFIX = 128
const SS_NOTIFY = 256
const SS_OWNERDRAW = 13
const SS_PATHELLIPSIS = 32768
const SS_REALSIZECONTROL = 64
const SS_REALSIZEIMAGE = 2048
const SS_RIGHT = 2
const SS_RIGHTJUST = 1024
const SS_SIMPLE = 11
const SS_SUNKEN = 4096
const SS_TYPEMASK = 31
const SS_USERITEM = 10
const SS_WHITEFRAME = 9
const SS_WHITERECT = 6
const SS_WORDELLIPSIS = 49152
const STACK_SIZE_PARAM_IS_A_RESERVATION = 65536
const STAMP_AXESLIST = 134245473
const STAMP_CFF2 = 134248035
const STAMP_DESIGNVECTOR = 134248036
const STAMP_TRUETYPE_VARIATION = 134248052
const STANDARD_RIGHTS_ALL = 2031616
const STANDARD_RIGHTS_EXECUTE = 131072
const STANDARD_RIGHTS_READ = 131072
const STANDARD_RIGHTS_REQUIRED = 983040
const STANDARD_RIGHTS_WRITE = 131072
const STARTDOC = 10
const STARTF_FORCEOFFFEEDBACK = 128
const STARTF_FORCEONFEEDBACK = 64
const STARTF_PREVENTPINNING = 8192
const STARTF_RUNFULLSCREEN = 32
const STARTF_TITLEISAPPID = 4096
const STARTF_TITLEISLINKNAME = 2048
const STARTF_UNTRUSTEDSOURCE = 32768
const STARTF_USECOUNTCHARS = 8
const STARTF_USEFILLATTRIBUTE = 16
const STARTF_USEHOTKEY = 512
const STARTF_USEPOSITION = 4
const STARTF_USESHOWWINDOW = 1
const STARTF_USESIZE = 2
const STARTF_USESTDHANDLES = 256
const START_PAGE_GENERAL = 4294967295
const STATE_SYSTEM_ALERT_HIGH = 268435456
const STATE_SYSTEM_ALERT_LOW = 67108864
const STATE_SYSTEM_ALERT_MEDIUM = 134217728
const STATE_SYSTEM_ANIMATED = 16384
const STATE_SYSTEM_BUSY = 2048
const STATE_SYSTEM_CHECKED = 16
const STATE_SYSTEM_COLLAPSED = 1024
const STATE_SYSTEM_DEFAULT = 256
const STATE_SYSTEM_EXPANDED = 512
const STATE_SYSTEM_EXTSELECTABLE = 33554432
const STATE_SYSTEM_FLOATING = 4096
const STATE_SYSTEM_FOCUSABLE = 1048576
const STATE_SYSTEM_FOCUSED = 4
const STATE_SYSTEM_HOTTRACKED = 128
const STATE_SYSTEM_INDETERMINATE = 32
const STATE_SYSTEM_INVISIBLE = 32768
const STATE_SYSTEM_LINKED = 4194304
const STATE_SYSTEM_MARQUEED = 8192
const STATE_SYSTEM_MIXED = 32
const STATE_SYSTEM_MOVEABLE = 262144
const STATE_SYSTEM_MULTISELECTABLE = 16777216
const STATE_SYSTEM_OFFSCREEN = 65536
const STATE_SYSTEM_PRESSED = 8
const STATE_SYSTEM_PROTECTED = 536870912
const STATE_SYSTEM_READONLY = 64
const STATE_SYSTEM_SELECTABLE = 2097152
const STATE_SYSTEM_SELECTED = 2
const STATE_SYSTEM_SELFVOICING = 524288
const STATE_SYSTEM_SIZEABLE = 131072
const STATE_SYSTEM_TRAVERSED = 8388608
const STATE_SYSTEM_UNAVAILABLE = 1
const STATE_SYSTEM_VALID = 1073741823
const STAT_GET_NDLT = 4
const STAT_GET_NEQ = 2
const STAT_GET_NLT = 3
const STAT_GET_ROWID = 1
const STAT_GET_STAT1 = 0
const STDAPICALLTYPE = "WINAPI"
const STDAPIVCALLTYPE = "__cdecl"
const STDERR_FILENO = 2
const STDIN_FILENO = 0
const STDMETHODCALLTYPE = "WINAPI"
const STDMETHODVCALLTYPE = "__cdecl"
const STDOLE2_LCID = 0
const STDOLE2_MAJORVERNUM = 2
const STDOLE2_MINORVERNUM = 0
const STDOLE_LCID = 0
const STDOLE_MAJORVERNUM = 1
const STDOLE_MINORVERNUM = 0
const STDOUT_FILENO = 1
const STD_ERROR_HANDLE = -12
const STD_INPUT_HANDLE = -10
const STD_OUTPUT_HANDLE = -11
const STGFMT_ANY = 4
const STGFMT_DOCFILE = 5
const STGFMT_DOCUMENT = 0
const STGFMT_FILE = 3
const STGFMT_NATIVE = 1
const STGFMT_STORAGE = 0
const STGM_CONVERT = 131072
const STGM_CREATE = 4096
const STGM_DELETEONRELEASE = 67108864
const STGM_DIRECT = 0
const STGM_DIRECT_SWMR = 4194304
const STGM_FAILIFTHERE = 0
const STGM_NOSCRATCH = 1048576
const STGM_NOSNAPSHOT = 2097152
const STGM_PRIORITY = 262144
const STGM_READ = 0
const STGM_READWRITE = 2
const STGM_SHARE_DENY_NONE = 64
const STGM_SHARE_DENY_READ = 48
const STGM_SHARE_DENY_WRITE = 32
const STGM_SHARE_EXCLUSIVE = 16
const STGM_SIMPLE = 134217728
const STGM_TRANSACTED = 65536
const STGM_WRITE = 1
const STGOPTIONS_VERSION = 2
const STGTY_REPEAT = 256
const STG_LAYOUT_INTERLEAVED = 1
const STG_LAYOUT_SEQUENTIAL = 0
const STG_TOEND = 4294967295
const STILL_ACTIVE = "STATUS_PENDING"
const STM_GETICON = 369
const STM_GETIMAGE = 371
const STM_MSGMAX = 372
const STM_SETICON = 368
const STM_SETIMAGE = 370
const STN_CLICKED = 0
const STN_DBLCLK = 1
const STN_DISABLE = 3
const STN_ENABLE = 2
const STOCK_LAST = 19
const STORAGE_ADDRESS_TYPE_BTL8 = 0
const STORAGE_CRYPTO_CAPABILITY_VERSION_1 = 1
const STORAGE_CRYPTO_DESCRIPTOR_VERSION_1 = 1
const STORAGE_DEVICE_FLAGS_PAGE_83_DEVICEGUID = 4
const STORAGE_DEVICE_FLAGS_RANDOM_DEVICEGUID_REASON_CONFLICT = 1
const STORAGE_DEVICE_FLAGS_RANDOM_DEVICEGUID_REASON_NOHWID = 2
const STORAGE_FAILURE_PREDICTION_CONFIG_V1 = 1
const STORAGE_INFO_FLAGS_ALIGNED_DEVICE = 1
const STORAGE_INFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE = 2
const STORAGE_INFO_OFFSET_UNKNOWN = 4294967295
const STORAGE_PRIORITY_HINT_SUPPORTED = 1
const STORAGE_RPMB_DESCRIPTOR_VERSION_1 = 1
const STORAGE_RPMB_MINIMUM_RELIABLE_WRITE_SIZE = 512
const STORAGE_TIER_DESCRIPTION_LENGTH = 512
const STORAGE_TIER_FLAG_NO_SEEK_PENALTY = 131072
const STORAGE_TIER_FLAG_PARITY = 8388608
const STORAGE_TIER_FLAG_READ_CACHE = 4194304
const STORAGE_TIER_FLAG_SMR = 16777216
const STORAGE_TIER_FLAG_WRITE_BACK_CACHE = 2097152
const STORAGE_TIER_NAME_LENGTH = 256
const STREAM_CLEAR_ENCRYPTION = 4
const STREAM_CONTAINS_GHOSTED_FILE_EXTENTS = 16
const STREAM_CONTAINS_PROPERTIES = 4
const STREAM_CONTAINS_SECURITY = 2
const STREAM_MODIFIED_WHEN_READ = 1
const STREAM_NORMAL_ATTRIBUTE = 0
const STREAM_SET_ENCRYPTION = 3
const STREAM_SPARSE_ATTRIBUTE = 8
const STRETCHBLT = 2048
const STRETCH_ANDSCANS = 1
const STRETCH_DELETESCANS = 3
const STRETCH_HALFTONE = 4
const STRETCH_ORSCANS = 2
const STRICT = 1
const STRUNCATE = 80
const STYLE_DESCRIPTION_SIZE = 32
const ST_ADVISE = 2
const ST_BLOCKED = 8
const ST_BLOCKNEXT = 128
const ST_CLIENT = 16
const ST_CONNECTED = 1
const ST_INLIST = 64
const ST_ISLOCAL = 4
const ST_ISSELF = 256
const ST_TERMINATED = 32
const SUBLANG_AFRIKAANS_SOUTH_AFRICA = 1
const SUBLANG_ALBANIAN_ALBANIA = 1
const SUBLANG_ALSATIAN_FRANCE = 1
const SUBLANG_AMHARIC_ETHIOPIA = 1
const SUBLANG_ARABIC_ALGERIA = 5
const SUBLANG_ARABIC_BAHRAIN = 15
const SUBLANG_ARABIC_EGYPT = 3
const SUBLANG_ARABIC_IRAQ = 2
const SUBLANG_ARABIC_JORDAN = 11
const SUBLANG_ARABIC_KUWAIT = 13
const SUBLANG_ARABIC_LEBANON = 12
const SUBLANG_ARABIC_LIBYA = 4
const SUBLANG_ARABIC_MOROCCO = 6
const SUBLANG_ARABIC_OMAN = 8
const SUBLANG_ARABIC_QATAR = 16
const SUBLANG_ARABIC_SAUDI_ARABIA = 1
const SUBLANG_ARABIC_SYRIA = 10
const SUBLANG_ARABIC_TUNISIA = 7
const SUBLANG_ARABIC_UAE = 14
const SUBLANG_ARABIC_YEMEN = 9
const SUBLANG_ARMENIAN_ARMENIA = 1
const SUBLANG_ASSAMESE_INDIA = 1
const SUBLANG_AZERBAIJANI_AZERBAIJAN_CYRILLIC = 2
const SUBLANG_AZERBAIJANI_AZERBAIJAN_LATIN = 1
const SUBLANG_AZERI_CYRILLIC = 2
const SUBLANG_AZERI_LATIN = 1
const SUBLANG_BANGLA_BANGLADESH = 2
const SUBLANG_BANGLA_INDIA = 1
const SUBLANG_BASHKIR_RUSSIA = 1
const SUBLANG_BASQUE_BASQUE = 1
const SUBLANG_BELARUSIAN_BELARUS = 1
const SUBLANG_BENGALI_BANGLADESH = 2
const SUBLANG_BENGALI_INDIA = 1
const SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 8
const SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN = 5
const SUBLANG_BRETON_FRANCE = 1
const SUBLANG_BULGARIAN_BULGARIA = 1
const SUBLANG_CATALAN_CATALAN = 1
const SUBLANG_CENTRAL_KURDISH_IRAQ = 1
const SUBLANG_CHEROKEE_CHEROKEE = 1
const SUBLANG_CHINESE_HONGKONG = 3
const SUBLANG_CHINESE_MACAU = 5
const SUBLANG_CHINESE_SIMPLIFIED = 2
const SUBLANG_CHINESE_SINGAPORE = 4
const SUBLANG_CHINESE_TRADITIONAL = 1
const SUBLANG_CORSICAN_FRANCE = 1
const SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN = 4
const SUBLANG_CROATIAN_CROATIA = 1
const SUBLANG_CUSTOM_DEFAULT = 3
const SUBLANG_CUSTOM_UNSPECIFIED = 4
const SUBLANG_CZECH_CZECH_REPUBLIC = 1
const SUBLANG_DANISH_DENMARK = 1
const SUBLANG_DARI_AFGHANISTAN = 1
const SUBLANG_DEFAULT = 1
const SUBLANG_DIVEHI_MALDIVES = 1
const SUBLANG_DUTCH = 1
const SUBLANG_DUTCH_BELGIAN = 2
const SUBLANG_ENGLISH_AUS = 3
const SUBLANG_ENGLISH_BELIZE = 10
const SUBLANG_ENGLISH_CAN = 4
const SUBLANG_ENGLISH_CARIBBEAN = 9
const SUBLANG_ENGLISH_EIRE = 6
const SUBLANG_ENGLISH_INDIA = 16
const SUBLANG_ENGLISH_IRELAND = 6
const SUBLANG_ENGLISH_JAMAICA = 8
const SUBLANG_ENGLISH_MALAYSIA = 17
const SUBLANG_ENGLISH_NZ = 5
const SUBLANG_ENGLISH_PHILIPPINES = 13
const SUBLANG_ENGLISH_SINGAPORE = 18
const SUBLANG_ENGLISH_SOUTH_AFRICA = 7
const SUBLANG_ENGLISH_TRINIDAD = 11
const SUBLANG_ENGLISH_UK = 2
const SUBLANG_ENGLISH_US = 1
const SUBLANG_ENGLISH_ZIMBABWE = 12
const SUBLANG_ESTONIAN_ESTONIA = 1
const SUBLANG_FAEROESE_FAROE_ISLANDS = 1
const SUBLANG_FILIPINO_PHILIPPINES = 1
const SUBLANG_FINNISH_FINLAND = 1
const SUBLANG_FRENCH = 1
const SUBLANG_FRENCH_BELGIAN = 2
const SUBLANG_FRENCH_CANADIAN = 3
const SUBLANG_FRENCH_LUXEMBOURG = 5
const SUBLANG_FRENCH_MONACO = 6
const SUBLANG_FRENCH_SWISS = 4
const SUBLANG_FRISIAN_NETHERLANDS = 1
const SUBLANG_FULAH_SENEGAL = 2
const SUBLANG_GALICIAN_GALICIAN = 1
const SUBLANG_GEORGIAN_GEORGIA = 1
const SUBLANG_GERMAN = 1
const SUBLANG_GERMAN_AUSTRIAN = 3
const SUBLANG_GERMAN_LIECHTENSTEIN = 5
const SUBLANG_GERMAN_LUXEMBOURG = 4
const SUBLANG_GERMAN_SWISS = 2
const SUBLANG_GREEK_GREECE = 1
const SUBLANG_GREENLANDIC_GREENLAND = 1
const SUBLANG_GUJARATI_INDIA = 1
const SUBLANG_HAUSA_NIGERIA = 1
const SUBLANG_HAUSA_NIGERIA_LATIN = 1
const SUBLANG_HAWAIIAN_US = 1
const SUBLANG_HEBREW_ISRAEL = 1
const SUBLANG_HINDI_INDIA = 1
const SUBLANG_HUNGARIAN_HUNGARY = 1
const SUBLANG_ICELANDIC_ICELAND = 1
const SUBLANG_IGBO_NIGERIA = 1
const SUBLANG_INDONESIAN_INDONESIA = 1
const SUBLANG_INUKTITUT_CANADA = 1
const SUBLANG_INUKTITUT_CANADA_LATIN = 2
const SUBLANG_IRISH_IRELAND = 2
const SUBLANG_ITALIAN = 1
const SUBLANG_ITALIAN_SWISS = 2
const SUBLANG_JAPANESE_JAPAN = 1
const SUBLANG_KANNADA_INDIA = 1
const SUBLANG_KASHMIRI_INDIA = 2
const SUBLANG_KASHMIRI_SASIA = 2
const SUBLANG_KAZAK_KAZAKHSTAN = 1
const SUBLANG_KHMER_CAMBODIA = 1
const SUBLANG_KICHE_GUATEMALA = 1
const SUBLANG_KINYARWANDA_RWANDA = 1
const SUBLANG_KONKANI_INDIA = 1
const SUBLANG_KOREAN = 1
const SUBLANG_KYRGYZ_KYRGYZSTAN = 1
const SUBLANG_LAO_LAO = 1
const SUBLANG_LAO_LAO_PDR = 1
const SUBLANG_LATVIAN_LATVIA = 1
const SUBLANG_LITHUANIAN = 1
const SUBLANG_LITHUANIAN_LITHUANIA = 1
const SUBLANG_LOWER_SORBIAN_GERMANY = 2
const SUBLANG_LUXEMBOURGISH_LUXEMBOURG = 1
const SUBLANG_MACEDONIAN_MACEDONIA = 1
const SUBLANG_MALAYALAM_INDIA = 1
const SUBLANG_MALAY_BRUNEI_DARUSSALAM = 2
const SUBLANG_MALAY_MALAYSIA = 1
const SUBLANG_MALTESE_MALTA = 1
const SUBLANG_MAORI_NEW_ZEALAND = 1
const SUBLANG_MAPUDUNGUN_CHILE = 1
const SUBLANG_MARATHI_INDIA = 1
const SUBLANG_MOHAWK_MOHAWK = 1
const SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA = 1
const SUBLANG_MONGOLIAN_PRC = 2
const SUBLANG_NEPALI_INDIA = 2
const SUBLANG_NEPALI_NEPAL = 1
const SUBLANG_NEUTRAL = 0
const SUBLANG_NORWEGIAN_BOKMAL = 1
const SUBLANG_NORWEGIAN_NYNORSK = 2
const SUBLANG_OCCITAN_FRANCE = 1
const SUBLANG_ORIYA_INDIA = 1
const SUBLANG_PASHTO_AFGHANISTAN = 1
const SUBLANG_PERSIAN_IRAN = 1
const SUBLANG_POLISH_POLAND = 1
const SUBLANG_PORTUGUESE = 2
const SUBLANG_PORTUGUESE_BRAZILIAN = 1
const SUBLANG_PORTUGUESE_PORTUGAL = 2
const SUBLANG_PULAR_SENEGAL = 2
const SUBLANG_PUNJABI_INDIA = 1
const SUBLANG_PUNJABI_PAKISTAN = 2
const SUBLANG_QUECHUA_BOLIVIA = 1
const SUBLANG_QUECHUA_ECUADOR = 2
const SUBLANG_QUECHUA_PERU = 3
const SUBLANG_ROMANIAN_ROMANIA = 1
const SUBLANG_ROMANSH_SWITZERLAND = 1
const SUBLANG_RUSSIAN_RUSSIA = 1
const SUBLANG_SAKHA_RUSSIA = 1
const SUBLANG_SAMI_INARI_FINLAND = 9
const SUBLANG_SAMI_LULE_NORWAY = 4
const SUBLANG_SAMI_LULE_SWEDEN = 5
const SUBLANG_SAMI_NORTHERN_FINLAND = 3
const SUBLANG_SAMI_NORTHERN_NORWAY = 1
const SUBLANG_SAMI_NORTHERN_SWEDEN = 2
const SUBLANG_SAMI_SKOLT_FINLAND = 8
const SUBLANG_SAMI_SOUTHERN_NORWAY = 6
const SUBLANG_SAMI_SOUTHERN_SWEDEN = 7
const SUBLANG_SANSKRIT_INDIA = 1
const SUBLANG_SCOTTISH_GAELIC = 1
const SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 7
const SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN = 6
const SUBLANG_SERBIAN_CYRILLIC = 3
const SUBLANG_SERBIAN_LATIN = 2
const SUBLANG_SERBIAN_MONTENEGRO_CYRILLIC = 12
const SUBLANG_SERBIAN_MONTENEGRO_LATIN = 11
const SUBLANG_SERBIAN_SERBIA_CYRILLIC = 10
const SUBLANG_SERBIAN_SERBIA_LATIN = 9
const SUBLANG_SINDHI_AFGHANISTAN = 2
const SUBLANG_SINDHI_INDIA = 1
const SUBLANG_SINDHI_PAKISTAN = 2
const SUBLANG_SINHALESE_SRI_LANKA = 1
const SUBLANG_SLOVAK_SLOVAKIA = 1
const SUBLANG_SLOVENIAN_SLOVENIA = 1
const SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA = 1
const SUBLANG_SPANISH = 1
const SUBLANG_SPANISH_ARGENTINA = 11
const SUBLANG_SPANISH_BOLIVIA = 16
const SUBLANG_SPANISH_CHILE = 13
const SUBLANG_SPANISH_COLOMBIA = 9
const SUBLANG_SPANISH_COSTA_RICA = 5
const SUBLANG_SPANISH_DOMINICAN_REPUBLIC = 7
const SUBLANG_SPANISH_ECUADOR = 12
const SUBLANG_SPANISH_EL_SALVADOR = 17
const SUBLANG_SPANISH_GUATEMALA = 4
const SUBLANG_SPANISH_HONDURAS = 18
const SUBLANG_SPANISH_MEXICAN = 2
const SUBLANG_SPANISH_MODERN = 3
const SUBLANG_SPANISH_NICARAGUA = 19
const SUBLANG_SPANISH_PANAMA = 6
const SUBLANG_SPANISH_PARAGUAY = 15
const SUBLANG_SPANISH_PERU = 10
const SUBLANG_SPANISH_PUERTO_RICO = 20
const SUBLANG_SPANISH_URUGUAY = 14
const SUBLANG_SPANISH_US = 21
const SUBLANG_SPANISH_VENEZUELA = 8
const SUBLANG_SWAHILI_KENYA = 1
const SUBLANG_SWEDISH = 1
const SUBLANG_SWEDISH_FINLAND = 2
const SUBLANG_SWEDISH_SWEDEN = 1
const SUBLANG_SYRIAC = 1
const SUBLANG_SYRIAC_SYRIA = 1
const SUBLANG_SYS_DEFAULT = 2
const SUBLANG_TAJIK_TAJIKISTAN = 1
const SUBLANG_TAMAZIGHT_ALGERIA_LATIN = 2
const SUBLANG_TAMAZIGHT_MOROCCO_TIFINAGH = 4
const SUBLANG_TAMIL_INDIA = 1
const SUBLANG_TAMIL_SRI_LANKA = 2
const SUBLANG_TATAR_RUSSIA = 1
const SUBLANG_TELUGU_INDIA = 1
const SUBLANG_THAI_THAILAND = 1
const SUBLANG_TIBETAN_BHUTAN = 2
const SUBLANG_TIBETAN_PRC = 1
const SUBLANG_TIGRIGNA_ERITREA = 2
const SUBLANG_TIGRINYA_ERITREA = 2
const SUBLANG_TIGRINYA_ETHIOPIA = 1
const SUBLANG_TSWANA_BOTSWANA = 2
const SUBLANG_TSWANA_SOUTH_AFRICA = 1
const SUBLANG_TURKISH_TURKEY = 1
const SUBLANG_TURKMEN_TURKMENISTAN = 1
const SUBLANG_UIGHUR_PRC = 1
const SUBLANG_UI_CUSTOM_DEFAULT = 5
const SUBLANG_UKRAINIAN_UKRAINE = 1
const SUBLANG_UPPER_SORBIAN_GERMANY = 1
const SUBLANG_URDU_INDIA = 2
const SUBLANG_URDU_PAKISTAN = 1
const SUBLANG_UZBEK_CYRILLIC = 2
const SUBLANG_UZBEK_LATIN = 1
const SUBLANG_VALENCIAN_VALENCIA = 2
const SUBLANG_VIETNAMESE_VIETNAM = 1
const SUBLANG_WELSH_UNITED_KINGDOM = 1
const SUBLANG_WOLOF_SENEGAL = 1
const SUBLANG_XHOSA_SOUTH_AFRICA = 1
const SUBLANG_YAKUT_RUSSIA = 1
const SUBLANG_YI_PRC = 1
const SUBLANG_YORUBA_NIGERIA = 1
const SUBLANG_ZULU_SOUTH_AFRICA = 1
const SUBVERSION_MASK = 255
const SUCCESSFUL_ACCESS_ACE_FLAG = 64
const SUPPORT_LANG_NUMBER = 32
const SWP_ASYNCWINDOWPOS = 16384
const SWP_DEFERERASE = 8192
const SWP_DRAWFRAME = 32
const SWP_FRAMECHANGED = 32
const SWP_HIDEWINDOW = 128
const SWP_NOACTIVATE = 16
const SWP_NOCOPYBITS = 256
const SWP_NOMOVE = 2
const SWP_NOOWNERZORDER = 512
const SWP_NOREDRAW = 8
const SWP_NOREPOSITION = 512
const SWP_NOSENDCHANGING = 1024
const SWP_NOSIZE = 1
const SWP_NOZORDER = 4
const SWP_SHOWWINDOW = 64
const SW_ERASE = 4
const SW_FORCEMINIMIZE = 11
const SW_HIDE = 0
const SW_INVALIDATE = 2
const SW_MAX = 11
const SW_MAXIMIZE = 3
const SW_MINIMIZE = 6
const SW_NORMAL = 1
const SW_OTHERUNZOOM = 4
const SW_OTHERZOOM = 2
const SW_PARENTCLOSING = 1
const SW_PARENTOPENING = 3
const SW_RESTORE = 9
const SW_SCROLLCHILDREN = 1
const SW_SHOW = 5
const SW_SHOWDEFAULT = 10
const SW_SHOWMAXIMIZED = 3
const SW_SHOWMINIMIZED = 2
const SW_SHOWMINNOACTIVE = 7
const SW_SHOWNA = 8
const SW_SHOWNOACTIVATE = 4
const SW_SHOWNORMAL = 1
const SW_SMOOTHSCROLL = 16
const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE = 2
const SYMBOLIC_LINK_FLAG_DIRECTORY = 1
const SYMBOL_CHARSET = 2
const SYMBOL_FONTTYPE = 524288
const SYMLINK_FLAG_RELATIVE = 1
const SYMMETRICWRAPKEYBLOB = 11
const SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY = 2
const SYNCHRONIZATION_BARRIER_FLAGS_NO_DELETE = 4
const SYNCHRONIZATION_BARRIER_FLAGS_SPIN_ONLY = 1
const SYNCHRONIZE = 1048576
const SYSCALL = 0
const SYSPAL_ERROR = 0
const SYSPAL_NOSTATIC = 2
const SYSPAL_NOSTATIC256 = 3
const SYSPAL_STATIC = 1
const SYSRGN = 4
const SYSTEM_ALARM_ACE_TYPE = 3
const SYSTEM_ALARM_CALLBACK_ACE_TYPE = 14
const SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = 16
const SYSTEM_ALARM_OBJECT_ACE_TYPE = 8
const SYSTEM_AUDIT_ACE_TYPE = 2
const SYSTEM_AUDIT_CALLBACK_ACE_TYPE = 13
const SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = 15
const SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7
const SYSTEM_CACHE_ALIGNMENT_SIZE = 64
const SYSTEM_FIXED_FONT = 16
const SYSTEM_FONT = 13
const SYSTEM_MANDATORY_LABEL_ACE_TYPE = 17
const SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP = 4
const SYSTEM_MANDATORY_LABEL_NO_READ_UP = 2
const SYSTEM_MANDATORY_LABEL_NO_WRITE_UP = 1
const SYSTEM_MANDATORY_LABEL_VALID_MASK = 7
const SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE = 18
const SYSTEM_SCOPED_POLICY_ID_ACE_TYPE = 19
const SYSTEM_STATUS_FLAG_POWER_SAVING_ON = 1
const SYS_OPEN = 20
const S_ALLTHRESHOLD = 2
const S_ASYNCHRONOUS = "MK_S_ASYNCHRONOUS"
const S_LEGATO = 1
const S_NORMAL = 0
const S_PERIOD1024 = 1
const S_PERIOD2048 = 2
const S_PERIOD512 = 0
const S_PERIODVOICE = 3
const S_QUEUEEMPTY = 0
const S_SERBDNT = -5
const S_SERDCC = -7
const S_SERDDR = -14
const S_SERDFQ = -13
const S_SERDLN = -6
const S_SERDMD = -10
const S_SERDPT = -12
const S_SERDSH = -11
const S_SERDSR = -15
const S_SERDST = -16
const S_SERDTP = -8
const S_SERDVL = -9
const S_SERDVNA = -1
const S_SERMACT = -3
const S_SEROFM = -2
const S_SERQFUL = -4
const S_STACCATO = 2
const S_THRESHOLD = 1
const S_WHITE1024 = 5
const S_WHITE2048 = 6
const S_WHITE512 = 4
const S_WHITEVOICE = 7
const ScrollConsoleScreenBuffer = 0
const SearchPath = 0
const SecureZeroMemory = 0
const SendDlgItemMessage = 0
const SendMessage = 0
const SendMessageCallback = 0
const SendMessageTimeout = 0
const SendNotifyMessage = 0
const SetCalendarInfo = 0
const SetClassLong = 0
const SetClassLongPtr = 0
const SetClassLongPtrA = 0
const SetClassLongPtrW = 0
const SetComputerName = 0
const SetComputerNameEx = 0
const SetConsoleNumberOfCommands = 0
const SetConsoleTitle = 0
const SetCurrentDirectory = 0
const SetDefaultCommConfig = 0
const SetDefaultPrinter = 0
const SetDlgItemText = 0
const SetDllDirectory = 0
const SetEnvironmentStrings = 0
const SetEnvironmentVariable = 0
const SetFileAttributes = 0
const SetFileAttributesTransacted = 0
const SetFileSecurity = 0
const SetFileShortName = 0
const SetFirmwareEnvironmentVariable = 0
const SetFirmwareEnvironmentVariableEx = 0
const SetForm = 0
const SetICMProfile = 0
const SetJob = 0
const SetLocaleInfo = 0
const SetMenuItemInfo = 0
const SetPort = 0
const SetPrinter = 0
const SetPrinterData = 0
const SetPrinterDataEx = 0
const SetProp = 0
const SetUserObjectInformation = 0
const SetVolumeLabel = 0
const SetVolumeMountPoint = 0
const SetWindowLong = 0
const SetWindowLongPtr = 0
const SetWindowLongPtrA = 0
const SetWindowLongPtrW = 0
const SetWindowText = 0
const SetWindowsHook = 0
const SetWindowsHookEx = 0
const ShellAbout = 0
const ShellExecute = 0
const ShellExecuteEx = 0
const ShellMessageBox = 0
const Shell_NotifyIcon = 0
const StartDoc = 0
const StartDocPrinter = 0
const StartService = 0
const StartServiceCtrlDispatcher = 0
const StorageIdTypeNAA = 0
const StoragePortClassGuid = 0
const SystemParametersInfo = 0
const TABTYP_NORM = 0
const TABTYP_VIEW = 2
const TABTYP_VTAB = 1
const TAPE_ABSOLUTE_BLOCK = 1
const TAPE_ABSOLUTE_POSITION = 0
const TAPE_CHECK_FOR_DRIVE_PROBLEM = 2
const TAPE_DRIVE_ABSOLUTE_BLK = 2147487744
const TAPE_DRIVE_ABS_BLK_IMMED = 2147491840
const TAPE_DRIVE_CLEAN_REQUESTS = 33554432
const TAPE_DRIVE_COMPRESSION = 131072
const TAPE_DRIVE_ECC = 65536
const TAPE_DRIVE_EJECT_MEDIA = 16777216
const TAPE_DRIVE_END_OF_DATA = 2147549184
const TAPE_DRIVE_EOT_WZ_SIZE = 8192
const TAPE_DRIVE_ERASE_BOP_ONLY = 64
const TAPE_DRIVE_ERASE_IMMEDIATE = 128
const TAPE_DRIVE_ERASE_LONG = 32
const TAPE_DRIVE_ERASE_SHORT = 16
const TAPE_DRIVE_FILEMARKS = 2147745792
const TAPE_DRIVE_FIXED = 1
const TAPE_DRIVE_FIXED_BLOCK = 1024
const TAPE_DRIVE_FORMAT = 2684354560
const TAPE_DRIVE_FORMAT_IMMEDIATE = 3221225472
const TAPE_DRIVE_GET_ABSOLUTE_BLK = 1048576
const TAPE_DRIVE_GET_LOGICAL_BLK = 2097152
const TAPE_DRIVE_HIGH_FEATURES = 2147483648
const TAPE_DRIVE_INITIATOR = 4
const TAPE_DRIVE_LOAD_UNLD_IMMED = 2147483680
const TAPE_DRIVE_LOAD_UNLOAD = 2147483649
const TAPE_DRIVE_LOCK_UNLK_IMMED = 2147483776
const TAPE_DRIVE_LOCK_UNLOCK = 2147483652
const TAPE_DRIVE_LOGICAL_BLK = 2147500032
const TAPE_DRIVE_LOG_BLK_IMMED = 2147516416
const TAPE_DRIVE_PADDING = 262144
const TAPE_DRIVE_RELATIVE_BLKS = 2147614720
const TAPE_DRIVE_REPORT_SMKS = 524288
const TAPE_DRIVE_RESERVED_BIT = 2147483648
const TAPE_DRIVE_REVERSE_POSITION = 2151677952
const TAPE_DRIVE_REWIND_IMMEDIATE = 2147483656
const TAPE_DRIVE_SELECT = 2
const TAPE_DRIVE_SEQUENTIAL_FMKS = 2148007936
const TAPE_DRIVE_SEQUENTIAL_SMKS = 2149580800
const TAPE_DRIVE_SETMARKS = 2148532224
const TAPE_DRIVE_SET_BLOCK_SIZE = 2147483664
const TAPE_DRIVE_SET_CMP_BOP_ONLY = 67108864
const TAPE_DRIVE_SET_COMPRESSION = 2147484160
const TAPE_DRIVE_SET_ECC = 2147483904
const TAPE_DRIVE_SET_EOT_WZ_SIZE = 4194304
const TAPE_DRIVE_SET_PADDING = 2147484672
const TAPE_DRIVE_SET_REPORT_SMKS = 2147485696
const TAPE_DRIVE_SPACE_IMMEDIATE = 2155872256
const TAPE_DRIVE_TAPE_CAPACITY = 256
const TAPE_DRIVE_TAPE_REMAINING = 512
const TAPE_DRIVE_TENSION = 2147483650
const TAPE_DRIVE_TENSION_IMMED = 2147483712
const TAPE_DRIVE_VARIABLE_BLOCK = 2048
const TAPE_DRIVE_WRITE_FILEMARKS = 2181038080
const TAPE_DRIVE_WRITE_LONG_FMKS = 2281701376
const TAPE_DRIVE_WRITE_MARK_IMMED = 2415919104
const TAPE_DRIVE_WRITE_PROTECT = 4096
const TAPE_DRIVE_WRITE_SETMARKS = 2164260864
const TAPE_DRIVE_WRITE_SHORT_FMKS = 2214592512
const TAPE_ERASE_LONG = 1
const TAPE_ERASE_SHORT = 0
const TAPE_FILEMARKS = 1
const TAPE_FIXED_PARTITIONS = 0
const TAPE_FORMAT = 5
const TAPE_INITIATOR_PARTITIONS = 2
const TAPE_LOAD = 0
const TAPE_LOCK = 3
const TAPE_LOGICAL_BLOCK = 2
const TAPE_LOGICAL_POSITION = 1
const TAPE_LONG_FILEMARKS = 3
const TAPE_PSEUDO_LOGICAL_BLOCK = 3
const TAPE_PSEUDO_LOGICAL_POSITION = 2
const TAPE_QUERY_DEVICE_ERROR_DATA = 4
const TAPE_QUERY_DRIVE_PARAMETERS = 0
const TAPE_QUERY_IO_ERROR_DATA = 3
const TAPE_QUERY_MEDIA_CAPACITY = 1
const TAPE_RESET_STATISTICS = 2
const TAPE_RETURN_ENV_INFO = 1
const TAPE_RETURN_STATISTICS = 0
const TAPE_REWIND = 0
const TAPE_SELECT_PARTITIONS = 1
const TAPE_SETMARKS = 0
const TAPE_SHORT_FILEMARKS = 2
const TAPE_SPACE_END_OF_DATA = 4
const TAPE_SPACE_FILEMARKS = 6
const TAPE_SPACE_RELATIVE_BLOCKS = 5
const TAPE_SPACE_SEQUENTIAL_FMKS = 7
const TAPE_SPACE_SEQUENTIAL_SMKS = 9
const TAPE_SPACE_SETMARKS = 8
const TAPE_TENSION = 2
const TAPE_UNLOAD = 1
const TAPE_UNLOCK = 4
const TARGET_IS_NT351_OR_WIN95_OR_LATER = 1
const TARGET_IS_NT40_OR_LATER = 1
const TARGET_IS_NT50_OR_LATER = 1
const TARGET_IS_NT51_OR_LATER = 1
const TARGET_IS_NT60_OR_LATER = 1
const TARGET_IS_NT61_OR_LATER = 1
const TA_BASELINE = 24
const TA_BOTTOM = 8
const TA_CENTER = 6
const TA_LEFT = 0
const TA_MASK = 287
const TA_NOUPDATECP = 0
const TA_RIGHT = 2
const TA_RTLREADING = 256
const TA_TOP = 0
const TA_UPDATECP = 1
const TBS_SUCCESS = 0
const TCI_SRCCHARSET = 1
const TCI_SRCCODEPAGE = 2
const TCI_SRCFONTSIG = 3
const TCI_SRCLOCALE = 4096
const TCP_BSDURGENT = 28672
const TCP_NODELAY = 1
const TC_CP_STROKE = 4
const TC_CR_90 = 8
const TC_CR_ANY = 16
const TC_EA_DOUBLE = 512
const TC_GP_TRAP = 2
const TC_HARDERR = 1
const TC_IA_ABLE = 1024
const TC_NORMAL = 0
const TC_OP_CHARACTER = 1
const TC_OP_STROKE = 2
const TC_RA_ABLE = 8192
const TC_RESERVED = 32768
const TC_SA_CONTIN = 256
const TC_SA_DOUBLE = 64
const TC_SA_INTEGER = 128
const TC_SCROLLBLT = 65536
const TC_SF_X_YINDEP = 32
const TC_SIGNAL = 3
const TC_SO_ABLE = 4096
const TC_UA_ABLE = 2048
const TC_VA_ABLE = 16384
const TECHNOLOGY = 2
const TERM_ANDINFO = 32
const TERM_CODED = 4
const TERM_COPIED = 8
const TERM_DYNAMIC = 1
const TERM_HEURTRUTH = 8192
const TERM_HIGHTRUTH = 16384
const TERM_IS = 2048
const TERM_LIKE = 1024
const TERM_LIKECOND = 512
const TERM_LIKEOPT = 256
const TERM_OK = 64
const TERM_ORINFO = 16
const TERM_SLICE = 32768
const TERM_VARSELECT = 4096
const TERM_VIRTUAL = 2
const TERM_VNULL = 128
const TEXTCAPS = 34
const TF_Autoincrement = 8
const TF_DISCONNECT = 1
const TF_Ephemeral = 16384
const TF_Eponymous = 32768
const TF_HasGenerated = 96
const TF_HasHidden = 2
const TF_HasNotNull = 2048
const TF_HasPrimaryKey = 4
const TF_HasStat1 = 16
const TF_HasStat4 = 8192
const TF_HasStored = 64
const TF_HasVirtual = 32
const TF_MaybeReanalyze = 256
const TF_NoVisibleRowid = 512
const TF_OOOHidden = 1024
const TF_REUSE_SOCKET = 2
const TF_Readonly = 1
const TF_Shadow = 4096
const TF_Strict = 65536
const TF_WRITE_BEHIND = 4
const TF_WithoutRowid = 128
const THAI_CHARSET = 222
const THIS = 0
const THIS_ = 0
const THREAD_ALL_ACCESS = 2097151
const THREAD_BASE_PRIORITY_IDLE = -15
const THREAD_BASE_PRIORITY_LOWRT = 15
const THREAD_BASE_PRIORITY_MAX = 2
const THREAD_BASE_PRIORITY_MIN = -2
const THREAD_DIRECT_IMPERSONATION = 512
const THREAD_GET_CONTEXT = 8
const THREAD_IMPERSONATE = 256
const THREAD_MODE_BACKGROUND_BEGIN = 65536
const THREAD_MODE_BACKGROUND_END = 131072
const THREAD_PRIORITY_ABOVE_NORMAL = 1
const THREAD_PRIORITY_BELOW_NORMAL = -1
const THREAD_PRIORITY_ERROR_RETURN = 2147483647
const THREAD_PRIORITY_HIGHEST = 2
const THREAD_PRIORITY_IDLE = -15
const THREAD_PRIORITY_LOWEST = -2
const THREAD_PRIORITY_NORMAL = 0
const THREAD_PRIORITY_TIME_CRITICAL = 15
const THREAD_PROFILING_FLAG_DISPATCH = 1
const THREAD_QUERY_INFORMATION = 64
const THREAD_QUERY_LIMITED_INFORMATION = 2048
const THREAD_SET_CONTEXT = 16
const THREAD_SET_INFORMATION = 32
const THREAD_SET_LIMITED_INFORMATION = 1024
const THREAD_SET_THREAD_TOKEN = 128
const THREAD_SUSPEND_RESUME = 2
const THREAD_TERMINATE = 1
const TIMEFMT_ENUMPROC = 0
const TIMEOUT_ASYNC = 4294967295
const TIMERR_BASE = 96
const TIMERR_NOCANDO = 97
const TIMERR_NOERROR = 0
const TIMERR_STRUCT = 129
const TIMERV_COALESCING_MAX = 2147483637
const TIMERV_COALESCING_MIN = 1
const TIMERV_DEFAULT_COALESCING = 0
const TIMERV_NO_COALESCING = 4294967295
const TIMER_ABSTIME = 1
const TIMER_ALL_ACCESS = 2031619
const TIMER_MODIFY_STATE = 2
const TIMER_QUERY_STATE = 1
const TIMESTAMP_DONT_HASH_DATA = 1
const TIMESTAMP_FAILURE_BAD_ALG = 0
const TIMESTAMP_FAILURE_BAD_FORMAT = 5
const TIMESTAMP_FAILURE_BAD_REQUEST = 2
const TIMESTAMP_FAILURE_EXTENSION_NOT_SUPPORTED = 16
const TIMESTAMP_FAILURE_INFO_NOT_AVAILABLE = 17
const TIMESTAMP_FAILURE_POLICY_NOT_SUPPORTED = 15
const TIMESTAMP_FAILURE_SYSTEM_FAILURE = 25
const TIMESTAMP_FAILURE_TIME_NOT_AVAILABLE = 14
const TIMESTAMP_NO_AUTH_RETRIEVAL = 131072
const TIMESTAMP_STATUS_GRANTED = 0
const TIMESTAMP_STATUS_GRANTED_WITH_MODS = 1
const TIMESTAMP_STATUS_REJECTED = 2
const TIMESTAMP_STATUS_REVOCATION_WARNING = 4
const TIMESTAMP_STATUS_REVOKED = 5
const TIMESTAMP_STATUS_WAITING = 3
const TIMESTAMP_VERIFY_CONTEXT_SIGNATURE = 32
const TIMESTAMP_VERSION = 1
const TIME_BYTES = 4
const TIME_CALLBACK_EVENT_PULSE = 32
const TIME_CALLBACK_EVENT_SET = 16
const TIME_CALLBACK_FUNCTION = 0
const TIME_FORCE24HOURFORMAT = 8
const TIME_KILL_SYNCHRONOUS = 256
const TIME_MIDI = 16
const TIME_MS = 1
const TIME_NOMINUTESORSECONDS = 1
const TIME_NOSECONDS = 2
const TIME_NOTIMEMARKER = 4
const TIME_ONESHOT = 0
const TIME_PERIODIC = 1
const TIME_SAMPLES = 2
const TIME_SMPTE = 8
const TIME_TICKS = 32
const TIME_VALID_OID_FLUSH_OBJECT_FUNC = "TimeValidDllFlushObject"
const TIME_VALID_OID_GET_OBJECT_FUNC = "TimeValidDllGetObject"
const TIME_ZONE_ID_DAYLIGHT = 2
const TIME_ZONE_ID_STANDARD = 1
const TIME_ZONE_ID_UNKNOWN = 0
const TKF_AVAILABLE = 2
const TKF_CONFIRMHOTKEY = 8
const TKF_HOTKEYACTIVE = 4
const TKF_HOTKEYSOUND = 16
const TKF_INDICATOR = 32
const TKF_TOGGLEKEYSON = 1
const TK_ABORT = 27
const TK_ACTION = 28
const TK_ADD = 163
const TK_AFTER = 29
const TK_AGG_COLUMN = 169
const TK_AGG_FUNCTION = 168
const TK_ALL = 135
const TK_ALTER = 162
const TK_ALWAYS = 96
const TK_ANALYZE = 30
const TK_AND = 44
const TK_ANY = 101
const TK_AS = 24
const TK_ASC = 31
const TK_ASTERISK = 180
const TK_ATTACH = 32
const TK_AUTOINCR = 126
const TK_BEFORE = 33
const TK_BEGIN = 5
const TK_BETWEEN = 48
const TK_BITAND = 102
const TK_BITNOT = 114
const TK_BITOR = 103
const TK_BLOB = 154
const TK_BY = 34
const TK_CASCADE = 35
const TK_CASE = 157
const TK_CAST = 36
const TK_CHECK = 124
const TK_COLLATE = 113
const TK_COLUMN = 167
const TK_COLUMNKW = 60
const TK_COMMA = 25
const TK_COMMIT = 10
const TK_CONCAT = 111
const TK_CONFLICT = 37
const TK_CONSTRAINT = 119
const TK_CREATE = 17
const TK_CTIME_KW = 100
const TK_CURRENT = 85
const TK_DATABASE = 38
const TK_DEFAULT = 120
const TK_DEFERRABLE = 131
const TK_DEFERRED = 7
const TK_DELETE = 128
const TK_DESC = 39
const TK_DETACH = 40
const TK_DISTINCT = 140
const TK_DO = 61
const TK_DOT = 141
const TK_DROP = 133
const TK_EACH = 41
const TK_ELSE = 160
const TK_END = 11
const TK_EQ = 53
const TK_ERROR = 182
const TK_ESCAPE = 58
const TK_EXCEPT = 136
const TK_EXCLUDE = 91
const TK_EXCLUSIVE = 9
const TK_EXISTS = 20
const TK_EXPLAIN = 2
const TK_FAIL = 42
const TK_FILTER = 166
const TK_FIRST = 83
const TK_FLOAT = 153
const TK_FOLLOWING = 86
const TK_FOR = 62
const TK_FOREIGN = 132
const TK_FROM = 142
const TK_FUNCTION = 172
const TK_GE = 57
const TK_GENERATED = 95
const TK_GROUP = 146
const TK_GROUPS = 92
const TK_GT = 54
const TK_HAVING = 147
const TK_ID = 59
const TK_IF = 18
const TK_IF_NULL_ROW = 179
const TK_IGNORE = 63
const TK_ILLEGAL = 185
const TK_IMMEDIATE = 8
const TK_IN = 49
const TK_INDEX = 161
const TK_INDEXED = 116
const TK_INITIALLY = 64
const TK_INSERT = 127
const TK_INSTEAD = 65
const TK_INTEGER = 155
const TK_INTERSECT = 137
const TK_INTO = 151
const TK_IS = 45
const TK_ISNOT = 171
const TK_ISNULL = 50
const TK_JOIN = 143
const TK_JOIN_KW = 118
const TK_KEY = 67
const TK_LAST = 84
const TK_LE = 55
const TK_LIKE_KW = 47
const TK_LIMIT = 148
const TK_LP = 22
const TK_LSHIFT = 104
const TK_LT = 56
const TK_MATCH = 46
const TK_MATERIALIZED = 97
const TK_MINUS = 107
const TK_NE = 52
const TK_NO = 66
const TK_NOT = 19
const TK_NOTHING = 152
const TK_NOTNULL = 51
const TK_NULL = 121
const TK_NULLS = 82
const TK_OF = 68
const TK_OFFSET = 69
const TK_ON = 115
const TK_OR = 43
const TK_ORDER = 145
const TK_OTHERS = 93
const TK_OVER = 165
const TK_PARTITION = 87
const TK_PLAN = 4
const TK_PLUS = 106
const TK_PRAGMA = 70
const TK_PRECEDING = 88
const TK_PRIMARY = 122
const TK_PTR = 112
const TK_QNUMBER = 183
const TK_QUERY = 3
const TK_RAISE = 71
const TK_RANGE = 89
const TK_RECURSIVE = 72
const TK_REFERENCES = 125
const TK_REGISTER = 176
const TK_REINDEX = 98
const TK_RELEASE = 14
const TK_REM = 110
const TK_RENAME = 99
const TK_REPLACE = 73
const TK_RESTRICT = 74
const TK_RETURNING = 150
const TK_ROLLBACK = 12
const TK_ROW = 75
const TK_ROWS = 76
const TK_RP = 23
const TK_RSHIFT = 105
const TK_SAVEPOINT = 13
const TK_SELECT = 138
const TK_SELECT_COLUMN = 178
const TK_SEMI = 1
const TK_SET = 130
const TK_SLASH = 109
const TK_SPACE = 184
const TK_SPAN = 181
const TK_STAR = 108
const TK_STRING = 117
const TK_TABLE = 16
const TK_TEMP = 21
const TK_THEN = 159
const TK_TIES = 94
const TK_TO = 15
const TK_TRANSACTION = 6
const TK_TRIGGER = 77
const TK_TRUEFALSE = 170
const TK_TRUTH = 175
const TK_UMINUS = 174
const TK_UNBOUNDED = 90
const TK_UNION = 134
const TK_UNIQUE = 123
const TK_UPDATE = 129
const TK_UPLUS = 173
const TK_USING = 144
const TK_VACUUM = 78
const TK_VALUES = 139
const TK_VARIABLE = 156
const TK_VECTOR = 177
const TK_VIEW = 79
const TK_VIRTUAL = 80
const TK_WHEN = 158
const TK_WHERE = 149
const TK_WINDOW = 164
const TK_WITH = 81
const TK_WITHOUT = 26
const TLOSS = 5
const TLS_MINIMUM_AVAILABLE = 64
const TME_CANCEL = 2147483648
const TME_HOVER = 1
const TME_LEAVE = 2
const TME_NONCLIENT = 16
const TME_QUERY = 1073741824
const TMPF_DEVICE = 8
const TMPF_FIXED_PITCH = 1
const TMPF_TRUETYPE = 4
const TMPF_VECTOR = 2
const TMP_MAX = 32767
const TMP_MAX_S = 32767
const TOKEN = 0
const TOKEN_ADJUST_DEFAULT = 128
const TOKEN_ADJUST_GROUPS = 64
const TOKEN_ADJUST_PRIVILEGES = 32
const TOKEN_ADJUST_SESSIONID = 256
const TOKEN_ALL_ACCESS = 983551
const TOKEN_ALL_ACCESS_P = 983295
const TOKEN_ASSIGN_PRIMARY = 1
const TOKEN_DUPLICATE = 2
const TOKEN_EXECUTE = 131072
const TOKEN_IMPERSONATE = 4
const TOKEN_MANDATORY_POLICY_NEW_PROCESS_MIN = 2
const TOKEN_MANDATORY_POLICY_NO_WRITE_UP = 1
const TOKEN_MANDATORY_POLICY_OFF = 0
const TOKEN_MANDATORY_POLICY_VALID_MASK = 3
const TOKEN_QUERY = 8
const TOKEN_QUERY_SOURCE = 16
const TOKEN_READ = 131080
const TOKEN_SOURCE_LENGTH = 8
const TOKEN_WRITE = 131296
const TOUCHEVENTF_DOWN = 2
const TOUCHEVENTF_INRANGE = 8
const TOUCHEVENTF_MOVE = 1
const TOUCHEVENTF_NOCOALESCE = 32
const TOUCHEVENTF_PALM = 128
const TOUCHEVENTF_PEN = 64
const TOUCHEVENTF_PRIMARY = 16
const TOUCHEVENTF_UP = 4
const TOUCHINPUTMASKF_CONTACTAREA = 4
const TOUCHINPUTMASKF_EXTRAINFO = 2
const TOUCHINPUTMASKF_TIMEFROMSYSTEM = 1
const TOUCHPREDICTIONPARAMETERS_DEFAULT_LATENCY = 8
const TOUCHPREDICTIONPARAMETERS_DEFAULT_RLS_DELTA = 0
const TOUCHPREDICTIONPARAMETERS_DEFAULT_RLS_EXPO_SMOOTH_ALPHA = 0
const TOUCHPREDICTIONPARAMETERS_DEFAULT_RLS_LAMBDA_LEARNING_RATE = 0
const TOUCHPREDICTIONPARAMETERS_DEFAULT_RLS_LAMBDA_MAX = 0
const TOUCHPREDICTIONPARAMETERS_DEFAULT_RLS_LAMBDA_MIN = 0
const TOUCHPREDICTIONPARAMETERS_DEFAULT_SAMPLETIME = 8
const TOUCHPREDICTIONPARAMETERS_DEFAULT_USE_HW_TIMESTAMP = 1
const TOUCH_FEEDBACK_DEFAULT = 1
const TOUCH_FEEDBACK_INDIRECT = 2
const TOUCH_FEEDBACK_NONE = 3
const TOUCH_FLAG_NONE = 0
const TOUCH_HIT_TESTING_CLIENT = 1
const TOUCH_HIT_TESTING_DEFAULT = 0
const TOUCH_HIT_TESTING_NONE = 2
const TOUCH_HIT_TESTING_PROXIMITY_CLOSEST = 0
const TOUCH_HIT_TESTING_PROXIMITY_FARTHEST = 4095
const TOUCH_MASK_CONTACTAREA = 1
const TOUCH_MASK_NONE = 0
const TOUCH_MASK_ORIENTATION = 2
const TOUCH_MASK_PRESSURE = 4
const TPM_BOTTOMALIGN = 32
const TPM_CENTERALIGN = 4
const TPM_HORIZONTAL = 0
const TPM_HORNEGANIMATION = 2048
const TPM_HORPOSANIMATION = 1024
const TPM_LAYOUTRTL = 32768
const TPM_LEFTALIGN = 0
const TPM_LEFTBUTTON = 0
const TPM_NOANIMATION = 16384
const TPM_NONOTIFY = 128
const TPM_RECURSE = 1
const TPM_RETURNCMD = 256
const TPM_RIGHTALIGN = 8
const TPM_RIGHTBUTTON = 2
const TPM_TOPALIGN = 0
const TPM_VCENTERALIGN = 16
const TPM_VERNEGANIMATION = 8192
const TPM_VERPOSANIMATION = 4096
const TPM_VERTICAL = 64
const TPM_WORKAREA = 65536
const TRANSACTIONMANAGER_ALL_ACCESS = 983103
const TRANSACTIONMANAGER_BIND_TRANSACTION = 32
const TRANSACTIONMANAGER_CREATE_RM = 16
const TRANSACTIONMANAGER_GENERIC_EXECUTE = 131072
const TRANSACTIONMANAGER_GENERIC_READ = 131073
const TRANSACTIONMANAGER_GENERIC_WRITE = 131102
const TRANSACTIONMANAGER_OBJECT_NAME_LENGTH_IN_BYTES = 0
const TRANSACTIONMANAGER_OBJECT_PATH = "\\\\TransactionManager\\\\"
const TRANSACTIONMANAGER_QUERY_INFORMATION = 1
const TRANSACTIONMANAGER_RECOVER = 4
const TRANSACTIONMANAGER_RENAME = 8
const TRANSACTIONMANAGER_SET_INFORMATION = 2
const TRANSACTION_ALL_ACCESS = 2031679
const TRANSACTION_COMMIT = 8
const TRANSACTION_DO_NOT_PROMOTE = 1
const TRANSACTION_ENLIST = 4
const TRANSACTION_GENERIC_EXECUTE = 1179672
const TRANSACTION_GENERIC_READ = 1179649
const TRANSACTION_GENERIC_WRITE = 1179710
const TRANSACTION_MANAGER_COMMIT_DEFAULT = 0
const TRANSACTION_MANAGER_COMMIT_LOWEST = 8
const TRANSACTION_MANAGER_COMMIT_SYSTEM_HIVES = 4
const TRANSACTION_MANAGER_COMMIT_SYSTEM_VOLUME = 2
const TRANSACTION_MANAGER_CORRUPT_FOR_PROGRESS = 32
const TRANSACTION_MANAGER_CORRUPT_FOR_RECOVERY = 16
const TRANSACTION_MANAGER_MAXIMUM_OPTION = 63
const TRANSACTION_MANAGER_VOLATILE = 1
const TRANSACTION_MAXIMUM_OPTION = 1
const TRANSACTION_NOTIFICATION_TM_ONLINE_FLAG_IS_CLUSTERED = 1
const TRANSACTION_NOTIFY_COMMIT = 4
const TRANSACTION_NOTIFY_COMMIT_COMPLETE = 64
const TRANSACTION_NOTIFY_COMMIT_FINALIZE = 1073741824
const TRANSACTION_NOTIFY_COMMIT_REQUEST = 67108864
const TRANSACTION_NOTIFY_DELEGATE_COMMIT = 1024
const TRANSACTION_NOTIFY_ENLIST_MASK = 262144
const TRANSACTION_NOTIFY_ENLIST_PREPREPARE = 4096
const TRANSACTION_NOTIFY_INDOUBT = 16384
const TRANSACTION_NOTIFY_LAST_RECOVER = 8192
const TRANSACTION_NOTIFY_MARSHAL = 131072
const TRANSACTION_NOTIFY_MASK = 1073741823
const TRANSACTION_NOTIFY_PREPARE = 2
const TRANSACTION_NOTIFY_PREPARE_COMPLETE = 32
const TRANSACTION_NOTIFY_PREPREPARE = 1
const TRANSACTION_NOTIFY_PREPREPARE_COMPLETE = 16
const TRANSACTION_NOTIFY_PROMOTE = 134217728
const TRANSACTION_NOTIFY_PROMOTE_NEW = 268435456
const TRANSACTION_NOTIFY_PROPAGATE_PULL = 32768
const TRANSACTION_NOTIFY_PROPAGATE_PUSH = 65536
const TRANSACTION_NOTIFY_RECOVER = 256
const TRANSACTION_NOTIFY_RECOVER_QUERY = 2048
const TRANSACTION_NOTIFY_REQUEST_OUTCOME = 536870912
const TRANSACTION_NOTIFY_RM_DISCONNECTED = 16777216
const TRANSACTION_NOTIFY_ROLLBACK = 8
const TRANSACTION_NOTIFY_ROLLBACK_COMPLETE = 128
const TRANSACTION_NOTIFY_SINGLE_PHASE_COMMIT = 512
const TRANSACTION_NOTIFY_TM_ONLINE = 33554432
const TRANSACTION_OBJECT_NAME_LENGTH_IN_BYTES = 0
const TRANSACTION_OBJECT_PATH = "\\\\Transaction\\\\"
const TRANSACTION_PROPAGATE = 32
const TRANSACTION_QUERY_INFORMATION = 1
const TRANSACTION_RESOURCE_MANAGER_RIGHTS = 1179703
const TRANSACTION_RIGHT_RESERVED1 = 64
const TRANSACTION_ROLLBACK = 16
const TRANSACTION_SET_INFORMATION = 2
const TRANSFORM_CTM = 4107
const TRANSPARENT = 1
const TRANSPORT_TYPE_CN = 1
const TRANSPORT_TYPE_DG = 2
const TRANSPORT_TYPE_LPC = 4
const TRANSPORT_TYPE_WMSG = 8
const TRANS_NONE = 0
const TRANS_READ = 1
const TRANS_WRITE = 2
const TREETRACE_ENABLED = 0
const TRIGGER_AFTER = 2
const TRIGGER_BEFORE = 1
const TRUE = 1
const TRUETYPE_FONTTYPE = 4
const TRUNCATE_EXISTING = 5
const TRY_AGAIN = 11002
const TT_AVAILABLE = 1
const TT_ENABLED = 2
const TT_OPENTYPE_FONTTYPE = 131072
const TT_POLYGON_TYPE = 24
const TT_PRIM_CSPLINE = 3
const TT_PRIM_LINE = 1
const TT_PRIM_QSPLINE = 2
const TURKISH_CHARSET = 162
const TWF_FINETOUCH = 1
const TWF_WANTPALM = 2
const TWOSTOPBITS = 2
const TXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY_FLAG_CREATED = 1
const TXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY_FLAG_DELETED = 2
const TXFS_LOGGING_MODE_FULL = 2
const TXFS_LOGGING_MODE_SIMPLE = 1
const TXFS_MODIFY_RM_VALID_FLAGS = 261631
const TXFS_QUERY_RM_INFORMATION_VALID_FLAGS = 246192
const TXFS_RM_FLAG_DO_NOT_RESET_RM_AT_NEXT_START = 32768
const TXFS_RM_FLAG_ENFORCE_MINIMUM_SIZE = 4096
const TXFS_RM_FLAG_GROW_LOG = 1024
const TXFS_RM_FLAG_LOGGING_MODE = 1
const TXFS_RM_FLAG_LOG_AUTO_SHRINK_PERCENTAGE = 64
const TXFS_RM_FLAG_LOG_CONTAINER_COUNT_MAX = 4
const TXFS_RM_FLAG_LOG_CONTAINER_COUNT_MIN = 8
const TXFS_RM_FLAG_LOG_GROWTH_INCREMENT_NUM_CONTAINERS = 16
const TXFS_RM_FLAG_LOG_GROWTH_INCREMENT_PERCENT = 32
const TXFS_RM_FLAG_LOG_NO_CONTAINER_COUNT_MAX = 128
const TXFS_RM_FLAG_LOG_NO_CONTAINER_COUNT_MIN = 256
const TXFS_RM_FLAG_PREFER_AVAILABILITY = 131072
const TXFS_RM_FLAG_PREFER_CONSISTENCY = 65536
const TXFS_RM_FLAG_PRESERVE_CHANGES = 8192
const TXFS_RM_FLAG_RENAME_RM = 2
const TXFS_RM_FLAG_RESET_RM_AT_NEXT_START = 16384
const TXFS_RM_FLAG_SHRINK_LOG = 2048
const TXFS_RM_STATE_ACTIVE = 2
const TXFS_RM_STATE_NOT_STARTED = 0
const TXFS_RM_STATE_SHUTTING_DOWN = 3
const TXFS_RM_STATE_STARTING = 1
const TXFS_ROLLFORWARD_REDO_FLAG_USE_LAST_REDO_LSN = 1
const TXFS_ROLLFORWARD_REDO_FLAG_USE_LAST_VIRTUAL_CLOCK = 2
const TXFS_ROLLFORWARD_REDO_VALID_FLAGS = 3
const TXFS_SAVEPOINT_CLEAR = 4
const TXFS_SAVEPOINT_CLEAR_ALL = 16
const TXFS_SAVEPOINT_ROLLBACK = 2
const TXFS_SAVEPOINT_SET = 1
const TXFS_START_RM_FLAG_LOGGING_MODE = 1024
const TXFS_START_RM_FLAG_LOG_AUTO_SHRINK_PERCENTAGE = 32
const TXFS_START_RM_FLAG_LOG_CONTAINER_COUNT_MAX = 1
const TXFS_START_RM_FLAG_LOG_CONTAINER_COUNT_MIN = 2
const TXFS_START_RM_FLAG_LOG_CONTAINER_SIZE = 4
const TXFS_START_RM_FLAG_LOG_GROWTH_INCREMENT_NUM_CONTAINERS = 8
const TXFS_START_RM_FLAG_LOG_GROWTH_INCREMENT_PERCENT = 16
const TXFS_START_RM_FLAG_LOG_NO_CONTAINER_COUNT_MAX = 64
const TXFS_START_RM_FLAG_LOG_NO_CONTAINER_COUNT_MIN = 128
const TXFS_START_RM_FLAG_PREFER_AVAILABILITY = 8192
const TXFS_START_RM_FLAG_PREFER_CONSISTENCY = 4096
const TXFS_START_RM_FLAG_PRESERVE_CHANGES = 2048
const TXFS_START_RM_FLAG_RECOVER_BEST_EFFORT = 512
const TXFS_START_RM_VALID_FLAGS = 15999
const TXFS_TRANSACTED_VERSION_NONTRANSACTED = 4294967294
const TXFS_TRANSACTED_VERSION_UNCOMMITTED = 4294967295
const TXFS_TRANSACTION_STATE_ACTIVE = 1
const TXFS_TRANSACTION_STATE_NONE = 0
const TXFS_TRANSACTION_STATE_NOTACTIVE = 3
const TXFS_TRANSACTION_STATE_PREPARED = 2
const TYPE1_FONTTYPE = 262144
const TabbedTextOut = 0
const TapeClassGuid = 0
const TextOut = 0
const TranslateAccelerator = 0
const UAS_EXACTLEGACY = 4096
const UCLEANUI = 67108864
const UCSCHAR_INVALID_CHARACTER = 4294967295
const UDIRTYUI = 134217728
const UILANGUAGE_ENUMPROC = 0
const UISF_ACTIVE = 4
const UISF_HIDEACCEL = 2
const UISF_HIDEFOCUS = 1
const UIS_CLEAR = 2
const UIS_INITIALIZE = 3
const UIS_SET = 1
const UI_CAP_2700 = 1
const UI_CAP_ROT90 = 2
const UI_CAP_ROTANY = 4
const ULW_ALPHA = 2
const ULW_COLORKEY = 1
const ULW_EX_NORESIZE = 8
const ULW_OPAQUE = 4
const UNDEFINE_ALTERNATE = 13
const UNDEFINE_PRIMARY = 12
const UNDERFLOW = 4
const UNICODE_NOCHAR = 65535
const UNICODE_STRING_MAX_CHARS = 32767
const UNIQUE_NAME = 0
const UNIVERSAL_NAME_INFO_LEVEL = 1
const UNKNOWN_LOCK = 5
const UNLOAD_DLL_DEBUG_EVENT = 7
const UNLOCK_ELEMENT = 1
const UNPROTECTED_DACL_SECURITY_INFORMATION = 536870912
const UNPROTECTED_SACL_SECURITY_INFORMATION = 268435456
const UNRECOVERED_READS_VALID = 8
const UNRECOVERED_WRITES_VALID = 2
const UOI_FLAGS = 1
const UOI_HEAPSIZE = 5
const UOI_IO = 6
const UOI_NAME = 2
const UOI_TIMERPROC_EXCEPTION_SUPPRESSION = 7
const UOI_TYPE = 3
const UOI_USER_SID = 4
const UPDFCACHE_IFBLANK = 16
const UPDFCACHE_IFBLANKORONSAVECACHE = 18
const UPDFCACHE_NODATACACHE = 1
const UPDFCACHE_NORMALCACHE = 8
const UPDFCACHE_ONLYIFBLANK = 2147483648
const UPDFCACHE_ONSAVECACHE = 2
const UPDFCACHE_ONSTOPCACHE = 4
const UPOINTER_32 = 0
const URLACTION_ACTIVEX_CONFIRM_NOOBJECTSAFETY = 4612
const URLACTION_ACTIVEX_CURR_MAX = 4619
const URLACTION_ACTIVEX_DYNSRC_VIDEO_AND_ANIMATION = 4618
const URLACTION_ACTIVEX_MAX = 5119
const URLACTION_ACTIVEX_MIN = 4608
const URLACTION_ACTIVEX_NO_WEBOC_SCRIPT = 4614
const URLACTION_ACTIVEX_OVERRIDE_DATA_SAFETY = 4610
const URLACTION_ACTIVEX_OVERRIDE_DOMAINLIST = 4619
const URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY = 4609
const URLACTION_ACTIVEX_OVERRIDE_OPTIN = 4616
const URLACTION_ACTIVEX_OVERRIDE_REPURPOSEDETECTION = 4615
const URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY = 4611
const URLACTION_ACTIVEX_RUN = 4608
const URLACTION_ACTIVEX_SCRIPTLET_RUN = 4617
const URLACTION_ACTIVEX_TREATASUNTRUSTED = 4613
const URLACTION_ALLOW_ACTIVEX_FILTERING = 9986
const URLACTION_ALLOW_APEVALUATION = 8961
const URLACTION_ALLOW_AUDIO_VIDEO = 9985
const URLACTION_ALLOW_AUDIO_VIDEO_PLUGINS = 9988
const URLACTION_ALLOW_CROSSDOMAIN_APPCACHE_MANIFEST = 9994
const URLACTION_ALLOW_CROSSDOMAIN_DROP_ACROSS_WINDOWS = 9993
const URLACTION_ALLOW_CROSSDOMAIN_DROP_WITHIN_WINDOW = 9992
const URLACTION_ALLOW_RENDER_LEGACY_DXTFILTERS = 9995
const URLACTION_ALLOW_RESTRICTEDPROTOCOLS = 8960
const URLACTION_ALLOW_STRUCTURED_STORAGE_SNIFFING = 9987
const URLACTION_ALLOW_XDOMAIN_SUBFRAME_RESIZE = 5128
const URLACTION_ALLOW_XHR_EVALUATION = 8962
const URLACTION_ALLOW_ZONE_ELEVATION_OPT_OUT_ADDITION = 9990
const URLACTION_ALLOW_ZONE_ELEVATION_VIA_OPT_OUT = 9989
const URLACTION_AUTHENTICATE_CLIENT = 6657
const URLACTION_AUTOMATIC_ACTIVEX_UI = 8705
const URLACTION_AUTOMATIC_DOWNLOAD_UI = 8704
const URLACTION_AUTOMATIC_DOWNLOAD_UI_MIN = 8704
const URLACTION_BEHAVIOR_MIN = 8192
const URLACTION_BEHAVIOR_RUN = 8192
const URLACTION_CHANNEL_SOFTDIST_MAX = 7935
const URLACTION_CHANNEL_SOFTDIST_MIN = 7680
const URLACTION_CHANNEL_SOFTDIST_PERMISSIONS = 7685
const URLACTION_CLIENT_CERT_PROMPT = 6660
const URLACTION_COOKIES = 6658
const URLACTION_COOKIES_ENABLED = 6672
const URLACTION_COOKIES_SESSION = 6659
const URLACTION_COOKIES_SESSION_THIRD_PARTY = 6662
const URLACTION_COOKIES_THIRD_PARTY = 6661
const URLACTION_CREDENTIALS_USE = 6656
const URLACTION_CROSS_DOMAIN_DATA = 5126
const URLACTION_DOTNET_USERCONTROLS = 8197
const URLACTION_DOWNLOAD_CURR_MAX = 4100
const URLACTION_DOWNLOAD_MAX = 4607
const URLACTION_DOWNLOAD_MIN = 4096
const URLACTION_DOWNLOAD_SIGNED_ACTIVEX = 4097
const URLACTION_DOWNLOAD_UNSIGNED_ACTIVEX = 4100
const URLACTION_FEATURE_BLOCK_INPUT_PROMPTS = 8453
const URLACTION_FEATURE_CROSSDOMAIN_FOCUS_CHANGE = 8455
const URLACTION_FEATURE_DATA_BINDING = 8454
const URLACTION_FEATURE_FORCE_ADDR_AND_STATUS = 8452
const URLACTION_FEATURE_MIME_SNIFFING = 8448
const URLACTION_FEATURE_MIN = 8448
const URLACTION_FEATURE_SCRIPT_STATUS_BAR = 8451
const URLACTION_FEATURE_WINDOW_RESTRICTIONS = 8450
const URLACTION_FEATURE_ZONE_ELEVATION = 8449
const URLACTION_HTML_ALLOW_CROSS_DOMAIN_CANVAS = 5645
const URLACTION_HTML_ALLOW_CROSS_DOMAIN_TEXTTRACK = 5648
const URLACTION_HTML_ALLOW_CROSS_DOMAIN_WEBWORKER = 5647
const URLACTION_HTML_ALLOW_INDEXEDDB = 5649
const URLACTION_HTML_ALLOW_INJECTED_DYNAMIC_HTML = 5643
const URLACTION_HTML_ALLOW_WINDOW_CLOSE = 5646
const URLACTION_HTML_FONT_DOWNLOAD = 5636
const URLACTION_HTML_INCLUDE_FILE_PATH = 5642
const URLACTION_HTML_JAVA_RUN = 5637
const URLACTION_HTML_MAX = 6143
const URLACTION_HTML_META_REFRESH = 5640
const URLACTION_HTML_MIN = 5632
const URLACTION_HTML_MIXED_CONTENT = 5641
const URLACTION_HTML_REQUIRE_UTF8_DOCUMENT_CODEPAGE = 5644
const URLACTION_HTML_SUBFRAME_NAVIGATE = 5639
const URLACTION_HTML_SUBMIT_FORMS = 5633
const URLACTION_HTML_SUBMIT_FORMS_FROM = 5634
const URLACTION_HTML_SUBMIT_FORMS_TO = 5635
const URLACTION_HTML_USERDATA_SAVE = 5638
const URLACTION_INFODELIVERY_CURR_MAX = 7430
const URLACTION_INFODELIVERY_MAX = 7679
const URLACTION_INFODELIVERY_MIN = 7424
const URLACTION_INFODELIVERY_NO_ADDING_CHANNELS = 7424
const URLACTION_INFODELIVERY_NO_ADDING_SUBSCRIPTIONS = 7427
const URLACTION_INFODELIVERY_NO_CHANNEL_LOGGING = 7430
const URLACTION_INFODELIVERY_NO_EDITING_CHANNELS = 7425
const URLACTION_INFODELIVERY_NO_EDITING_SUBSCRIPTIONS = 7428
const URLACTION_INFODELIVERY_NO_REMOVING_CHANNELS = 7426
const URLACTION_INFODELIVERY_NO_REMOVING_SUBSCRIPTIONS = 7429
const URLACTION_INPRIVATE_BLOCKING = 9984
const URLACTION_JAVA_CURR_MAX = 7168
const URLACTION_JAVA_MAX = 7423
const URLACTION_JAVA_MIN = 7168
const URLACTION_JAVA_PERMISSIONS = 7168
const URLACTION_LOOSE_XAML = 9218
const URLACTION_LOWRIGHTS = 9472
const URLACTION_MIN = 4096
const URLACTION_NETWORK_CURR_MAX = 6672
const URLACTION_NETWORK_MAX = 7167
const URLACTION_NETWORK_MIN = 6656
const URLACTION_PLUGGABLE_PROTOCOL_XHR = 5131
const URLACTION_SCRIPT_CURR_MAX = 5131
const URLACTION_SCRIPT_JAVA_USE = 5122
const URLACTION_SCRIPT_MAX = 5631
const URLACTION_SCRIPT_MIN = 5120
const URLACTION_SCRIPT_NAVIGATE = 5130
const URLACTION_SCRIPT_OVERRIDE_SAFETY = 5121
const URLACTION_SCRIPT_PASTE = 5127
const URLACTION_SCRIPT_RUN = 5120
const URLACTION_SCRIPT_SAFE_ACTIVEX = 5125
const URLACTION_SCRIPT_XSSFILTER = 5129
const URLACTION_SHELL_ALLOW_CROSS_SITE_SHARE = 6161
const URLACTION_SHELL_CURR_MAX = 6161
const URLACTION_SHELL_ENHANCED_DRAGDROP_SECURITY = 6155
const URLACTION_SHELL_EXECUTE_HIGHRISK = 6150
const URLACTION_SHELL_EXECUTE_LOWRISK = 6152
const URLACTION_SHELL_EXECUTE_MODRISK = 6151
const URLACTION_SHELL_EXTENSIONSECURITY = 6156
const URLACTION_SHELL_FILE_DOWNLOAD = 6147
const URLACTION_SHELL_INSTALL_DTITEMS = 6144
const URLACTION_SHELL_MAX = 6655
const URLACTION_SHELL_MIN = 6144
const URLACTION_SHELL_MOVE_OR_COPY = 6146
const URLACTION_SHELL_POPUPMGR = 6153
const URLACTION_SHELL_PREVIEW = 6159
const URLACTION_SHELL_REMOTEQUERY = 6158
const URLACTION_SHELL_RTF_OBJECTS_LOAD = 6154
const URLACTION_SHELL_SECURE_DRAGSOURCE = 6157
const URLACTION_SHELL_SHARE = 6160
const URLACTION_SHELL_SHELLEXECUTE = 6150
const URLACTION_SHELL_VERB = 6148
const URLACTION_SHELL_WEBVIEW_VERB = 6149
const URLACTION_WINDOWS_BROWSER_APPLICATIONS = 9216
const URLACTION_WINFX_SETUP = 9728
const URLACTION_XPS_DOCUMENTS = 9217
const URLDownloadToCacheFile = 0
const URLDownloadToFile = 0
const URLMON_OPTION_URL_ENCODING = 268435460
const URLMON_OPTION_USERAGENT = 268435457
const URLMON_OPTION_USERAGENT_REFRESH = 268435458
const URLMON_OPTION_USE_BINDSTRINGCREDS = 268435464
const URLMON_OPTION_USE_BROWSERAPPSDOCUMENTS = 268435472
const URLOSTRM_GETNEWESTVERSION = 3
const URLOSTRM_USECACHEDCOPY = 2
const URLOSTRM_USECACHEDCOPY_ONLY = 1
const URLOpenBlockingStream = 0
const URLOpenPullStream = 0
const URLOpenStream = 0
const URLPOLICY_ACTIVEX_CHECK_LIST = 65536
const URLPOLICY_ALLOW = 0
const URLPOLICY_AUTHENTICATE_CHALLENGE_RESPONSE = 65536
const URLPOLICY_AUTHENTICATE_CLEARTEXT_OK = 0
const URLPOLICY_AUTHENTICATE_MUTUAL_ONLY = 196608
const URLPOLICY_BEHAVIOR_CHECK_LIST = 65536
const URLPOLICY_CHANNEL_SOFTDIST_AUTOINSTALL = 196608
const URLPOLICY_CHANNEL_SOFTDIST_PRECACHE = 131072
const URLPOLICY_CHANNEL_SOFTDIST_PROHIBIT = 65536
const URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY = 196608
const URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT = 131072
const URLPOLICY_CREDENTIALS_MUST_PROMPT_USER = 65536
const URLPOLICY_CREDENTIALS_SILENT_LOGON_OK = 0
const URLPOLICY_DISALLOW = 3
const URLPOLICY_DONTCHECKDLGBOX = 256
const URLPOLICY_JAVA_CUSTOM = 8388608
const URLPOLICY_JAVA_HIGH = 65536
const URLPOLICY_JAVA_LOW = 196608
const URLPOLICY_JAVA_MEDIUM = 131072
const URLPOLICY_JAVA_PROHIBIT = 0
const URLPOLICY_LOG_ON_ALLOW = 64
const URLPOLICY_LOG_ON_DISALLOW = 128
const URLPOLICY_MASK_PERMISSIONS = 15
const URLPOLICY_NOTIFY_ON_ALLOW = 16
const URLPOLICY_NOTIFY_ON_DISALLOW = 32
const URLPOLICY_QUERY = 1
const URLZONE_ESC_FLAG = 256
const URL_MK_LEGACY = 0
const URL_MK_NO_CANONICALIZE = 2
const URL_MK_UNIFORM = 1
const URL_OID_GET_OBJECT_URL_FUNC = "UrlDllGetObjectUrl"
const USAGE_MATCH_TYPE_AND = 0
const USAGE_MATCH_TYPE_OR = 1
const USER_CALL_IS_ASYNC = 256
const USER_CALL_NEW_CORRELATION_DESC = 512
const USER_DEFAULT_SCREEN_DPI = 96
const USER_MARSHAL_CB_SIGNATURE = 85
const USER_MARSHAL_FC_BYTE = 1
const USER_MARSHAL_FC_CHAR = 2
const USER_MARSHAL_FC_DOUBLE = 12
const USER_MARSHAL_FC_FLOAT = 10
const USER_MARSHAL_FC_HYPER = 11
const USER_MARSHAL_FC_LONG = 8
const USER_MARSHAL_FC_SHORT = 6
const USER_MARSHAL_FC_SMALL = 3
const USER_MARSHAL_FC_ULONG = 9
const USER_MARSHAL_FC_USHORT = 7
const USER_MARSHAL_FC_USMALL = 4
const USER_MARSHAL_FC_WCHAR = 5
const USER_TIMER_MAXIMUM = 2147483647
const USER_TIMER_MINIMUM = 10
const USE___UUIDOF = 0
const USN_DELETE_FLAG_DELETE = 1
const USN_DELETE_FLAG_NOTIFY = 2
const USN_DELETE_VALID_FLAGS = 3
const USN_PAGE_SIZE = 4096
const USN_REASON_BASIC_INFO_CHANGE = 32768
const USN_REASON_CLOSE = 2147483648
const USN_REASON_COMPRESSION_CHANGE = 131072
const USN_REASON_DATA_EXTEND = 2
const USN_REASON_DATA_OVERWRITE = 1
const USN_REASON_DATA_TRUNCATION = 4
const USN_REASON_EA_CHANGE = 1024
const USN_REASON_ENCRYPTION_CHANGE = 262144
const USN_REASON_FILE_CREATE = 256
const USN_REASON_FILE_DELETE = 512
const USN_REASON_HARD_LINK_CHANGE = 65536
const USN_REASON_INDEXABLE_CHANGE = 16384
const USN_REASON_NAMED_DATA_EXTEND = 32
const USN_REASON_NAMED_DATA_OVERWRITE = 16
const USN_REASON_NAMED_DATA_TRUNCATION = 64
const USN_REASON_OBJECT_ID_CHANGE = 524288
const USN_REASON_RENAME_NEW_NAME = 8192
const USN_REASON_RENAME_OLD_NAME = 4096
const USN_REASON_REPARSE_POINT_CHANGE = 1048576
const USN_REASON_SECURITY_CHANGE = 2048
const USN_REASON_STREAM_CHANGE = 2097152
const USN_REASON_TRANSACTED_CHANGE = 4194304
const USN_SOURCE_AUXILIARY_DATA = 2
const USN_SOURCE_DATA_MANAGEMENT = 1
const USN_SOURCE_REPLICATION_MANAGEMENT = 4
const UnregisterClass = 0
const UpdateICMRegKey = 0
const UpdateResource = 0
const UploadPrinterDriverPackage = 0
const UpperToLower = 0
const UriBuilder_USE_ORIGINAL_FLAGS = 1
const Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME = 4
const Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME = 2
const Uri_CREATE_ALLOW_RELATIVE = 1
const Uri_CREATE_CANONICALIZE = 256
const Uri_CREATE_CANONICALIZE_ABSOLUTE = 131072
const Uri_CREATE_CRACK_UNKNOWN_SCHEMES = 512
const Uri_CREATE_DECODE_EXTRA_INFO = 64
const Uri_CREATE_FILE_USE_DOS_PATH = 32
const Uri_CREATE_IE_SETTINGS = 8192
const Uri_CREATE_NOFRAG = 8
const Uri_CREATE_NORMALIZE_INTL_CHARACTERS = 65536
const Uri_CREATE_NO_CANONICALIZE = 16
const Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES = 1024
const Uri_CREATE_NO_DECODE_EXTRA_INFO = 128
const Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS = 32768
const Uri_CREATE_NO_IE_SETTINGS = 16384
const Uri_CREATE_NO_PRE_PROCESS_HTML_URI = 4096
const Uri_CREATE_PRE_PROCESS_HTML_URI = 2048
const Uri_DISPLAY_IDN_HOST = 4
const Uri_DISPLAY_NO_FRAGMENT = 1
const Uri_DISPLAY_NO_PUNYCODE = 8
const Uri_ENCODING_HOST_IS_IDN = 4
const Uri_ENCODING_HOST_IS_PERCENT_ENCODED_CP = 16
const Uri_ENCODING_HOST_IS_PERCENT_ENCODED_UTF8 = 8
const Uri_ENCODING_QUERY_AND_FRAGMENT_IS_CP = 64
const Uri_ENCODING_QUERY_AND_FRAGMENT_IS_PERCENT_ENCODED_UTF8 = 32
const Uri_ENCODING_RFC = 41
const Uri_ENCODING_USER_INFO_AND_PATH_IS_CP = 2
const Uri_ENCODING_USER_INFO_AND_PATH_IS_PERCENT_ENCODED_UTF8 = 1
const Uri_HAS_ABSOLUTE_URI = 1
const Uri_HAS_AUTHORITY = 1
const Uri_HAS_DISPLAY_URI = 1
const Uri_HAS_DOMAIN = 1
const Uri_HAS_EXTENSION = 1
const Uri_HAS_FRAGMENT = 1
const Uri_HAS_HOST = 1
const Uri_HAS_HOST_TYPE = 1
const Uri_HAS_PASSWORD = 1
const Uri_HAS_PATH = 1
const Uri_HAS_PATH_AND_QUERY = 1
const Uri_HAS_PORT = 1
const Uri_HAS_QUERY = 1
const Uri_HAS_RAW_URI = 1
const Uri_HAS_SCHEME = 1
const Uri_HAS_SCHEME_NAME = 1
const Uri_HAS_USER_INFO = 1
const Uri_HAS_USER_NAME = 1
const Uri_HAS_ZONE = 1
const Uri_PUNYCODE_IDN_HOST = 2
const UuidFromString = 0
const UuidToString = 0
const VALID_INHERIT_FLAGS = 31
const VALID_NTFT = 192
const VALID_SYMBOLIC_LINK_FLAGS = 1
const VARCMP_EQ = 1
const VARCMP_GT = 2
const VARCMP_LT = 0
const VARCMP_NULL = 3
const VARIABLE_PITCH = 2
const VARIANT_ALPHABOOL = 2
const VARIANT_CALENDAR_GREGORIAN = 64
const VARIANT_CALENDAR_HIJRI = 8
const VARIANT_CALENDAR_THAI = 32
const VARIANT_LOCALBOOL = 16
const VARIANT_NOUSEROVERRIDE = 4
const VARIANT_NOVALUEPROP = 1
const VARIANT_TRUE = -1
const VARIANT_USE_NLS = 128
const VDBE_DISPLAY_P4 = 1
const VDBE_HALT_STATE = 3
const VDBE_INIT_STATE = 0
const VDBE_READY_STATE = 1
const VDBE_RUN_STATE = 2
const VENDOR_ID_LENGTH = 8
const VERTRES = 10
const VERTSIZE = 6
const VER_AND = 6
const VER_BUILDNUMBER = 4
const VER_CONDITION_MASK = 7
const VER_EQUAL = 1
const VER_GREATER = 2
const VER_GREATER_EQUAL = 3
const VER_LESS = 4
const VER_LESS_EQUAL = 5
const VER_MAJORVERSION = 2
const VER_MINORVERSION = 1
const VER_NT_DOMAIN_CONTROLLER = 2
const VER_NT_SERVER = 3
const VER_NT_WORKSTATION = 1
const VER_NUM_BITS_PER_CONDITION_MASK = 3
const VER_OR = 7
const VER_PLATFORMID = 8
const VER_PLATFORM_WIN32_NT = 2
const VER_PLATFORM_WIN32_WINDOWS = 1
const VER_PLATFORM_WIN32s = 0
const VER_PRODUCT_TYPE = 128
const VER_SERVER_NT = 2147483648
const VER_SERVICEPACKMAJOR = 32
const VER_SERVICEPACKMINOR = 16
const VER_SUITENAME = 64
const VER_SUITE_BACKOFFICE = 4
const VER_SUITE_BLADE = 1024
const VER_SUITE_COMMUNICATIONS = 8
const VER_SUITE_COMPUTE_SERVER = 16384
const VER_SUITE_DATACENTER = 128
const VER_SUITE_EMBEDDEDNT = 64
const VER_SUITE_EMBEDDED_RESTRICTED = 2048
const VER_SUITE_ENTERPRISE = 2
const VER_SUITE_PERSONAL = 512
const VER_SUITE_SECURITY_APPLIANCE = 4096
const VER_SUITE_SINGLEUSERTS = 256
const VER_SUITE_SMALLBUSINESS = 1
const VER_SUITE_SMALLBUSINESS_RESTRICTED = 32
const VER_SUITE_STORAGE_SERVER = 8192
const VER_SUITE_TERMINAL = 16
const VER_SUITE_WH_SERVER = 32768
const VER_WORKSTATION_NT = 1073741824
const VFFF_ISSHAREDFILE = 1
const VFF_BUFFTOOSMALL = 4
const VFF_CURNEDEST = 1
const VFF_FILEINUSE = 2
const VFT2_DRV_COMM = 10
const VFT2_DRV_DISPLAY = 4
const VFT2_DRV_INPUTMETHOD = 11
const VFT2_DRV_INSTALLABLE = 8
const VFT2_DRV_KEYBOARD = 2
const VFT2_DRV_LANGUAGE = 3
const VFT2_DRV_MOUSE = 5
const VFT2_DRV_NETWORK = 6
const VFT2_DRV_PRINTER = 1
const VFT2_DRV_SOUND = 9
const VFT2_DRV_SYSTEM = 7
const VFT2_DRV_VERSIONED_PRINTER = 12
const VFT2_FONT_RASTER = 1
const VFT2_FONT_TRUETYPE = 3
const VFT2_FONT_VECTOR = 2
const VFT2_UNKNOWN = 0
const VFT_APP = 1
const VFT_DLL = 2
const VFT_DRV = 3
const VFT_FONT = 4
const VFT_STATIC_LIB = 7
const VFT_UNKNOWN = 0
const VFT_VXD = 5
const VIETNAMESE_CHARSET = 163
const VIEW_E_FIRST = 2147746112
const VIEW_E_LAST = 2147746127
const VIEW_S_FIRST = 262464
const VIEW_S_LAST = 262479
const VIFF_DONTDELETEOLD = 2
const VIFF_FORCEINSTALL = 1
const VIF_ACCESSVIOLATION = 512
const VIF_BUFFTOOSMALL = 262144
const VIF_CANNOTCREATE = 2048
const VIF_CANNOTDELETE = 4096
const VIF_CANNOTDELETECUR = 16384
const VIF_CANNOTLOADCABINET = 1048576
const VIF_CANNOTLOADLZ32 = 524288
const VIF_CANNOTREADDST = 131072
const VIF_CANNOTREADSRC = 65536
const VIF_CANNOTRENAME = 8192
const VIF_DIFFCODEPG = 16
const VIF_DIFFLANG = 8
const VIF_DIFFTYPE = 32
const VIF_FILEINUSE = 128
const VIF_MISMATCH = 2
const VIF_OUTOFMEMORY = 32768
const VIF_OUTOFSPACE = 256
const VIF_SHARINGVIOLATION = 1024
const VIF_SRCOLD = 4
const VIF_TEMPFILE = 1
const VIF_WRITEPROT = 64
const VIRTDISKAPI = "DECLSPEC_IMPORT"
const VIRTUAL_STORAGE_TYPE_DEVICE_ISO = 1
const VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN = 0
const VIRTUAL_STORAGE_TYPE_DEVICE_VHD = 2
const VIRTUAL_STORAGE_TYPE_DEVICE_VHDX = 3
const VK_ACCEPT = 30
const VK_ADD = 107
const VK_APPS = 93
const VK_ATTN = 246
const VK_BACK = 8
const VK_BROWSER_BACK = 166
const VK_BROWSER_FAVORITES = 171
const VK_BROWSER_FORWARD = 167
const VK_BROWSER_HOME = 172
const VK_BROWSER_REFRESH = 168
const VK_BROWSER_SEARCH = 170
const VK_BROWSER_STOP = 169
const VK_CANCEL = 3
const VK_CAPITAL = 20
const VK_CLEAR = 12
const VK_CONTROL = 17
const VK_CONVERT = 28
const VK_CRSEL = 247
const VK_DECIMAL = 110
const VK_DELETE = 46
const VK_DIVIDE = 111
const VK_DOWN = 40
const VK_END = 35
const VK_EREOF = 249
const VK_ESCAPE = 27
const VK_EXECUTE = 43
const VK_EXSEL = 248
const VK_F1 = 112
const VK_F10 = 121
const VK_F11 = 122
const VK_F12 = 123
const VK_F13 = 124
const VK_F14 = 125
const VK_F15 = 126
const VK_F16 = 127
const VK_F17 = 128
const VK_F18 = 129
const VK_F19 = 130
const VK_F2 = 113
const VK_F20 = 131
const VK_F21 = 132
const VK_F22 = 133
const VK_F23 = 134
const VK_F24 = 135
const VK_F3 = 114
const VK_F4 = 115
const VK_F5 = 116
const VK_F6 = 117
const VK_F7 = 118
const VK_F8 = 119
const VK_F9 = 120
const VK_FINAL = 24
const VK_GAMEPAD_A = 195
const VK_GAMEPAD_B = 196
const VK_GAMEPAD_DPAD_DOWN = 204
const VK_GAMEPAD_DPAD_LEFT = 205
const VK_GAMEPAD_DPAD_RIGHT = 206
const VK_GAMEPAD_DPAD_UP = 203
const VK_GAMEPAD_LEFT_SHOULDER = 200
const VK_GAMEPAD_LEFT_THUMBSTICK_BUTTON = 209
const VK_GAMEPAD_LEFT_THUMBSTICK_DOWN = 212
const VK_GAMEPAD_LEFT_THUMBSTICK_LEFT = 214
const VK_GAMEPAD_LEFT_THUMBSTICK_RIGHT = 213
const VK_GAMEPAD_LEFT_THUMBSTICK_UP = 211
const VK_GAMEPAD_LEFT_TRIGGER = 201
const VK_GAMEPAD_MENU = 207
const VK_GAMEPAD_RIGHT_SHOULDER = 199
const VK_GAMEPAD_RIGHT_THUMBSTICK_BUTTON = 210
const VK_GAMEPAD_RIGHT_THUMBSTICK_DOWN = 216
const VK_GAMEPAD_RIGHT_THUMBSTICK_LEFT = 218
const VK_GAMEPAD_RIGHT_THUMBSTICK_RIGHT = 217
const VK_GAMEPAD_RIGHT_THUMBSTICK_UP = 215
const VK_GAMEPAD_RIGHT_TRIGGER = 202
const VK_GAMEPAD_VIEW = 208
const VK_GAMEPAD_X = 197
const VK_GAMEPAD_Y = 198
const VK_HANGEUL = 21
const VK_HANGUL = 21
const VK_HANJA = 25
const VK_HELP = 47
const VK_HOME = 36
const VK_ICO_00 = 228
const VK_ICO_CLEAR = 230
const VK_ICO_HELP = 227
const VK_IME_OFF = 26
const VK_IME_ON = 22
const VK_INSERT = 45
const VK_JUNJA = 23
const VK_KANA = 21
const VK_KANJI = 25
const VK_LAUNCH_APP1 = 182
const VK_LAUNCH_APP2 = 183
const VK_LAUNCH_MAIL = 180
const VK_LAUNCH_MEDIA_SELECT = 181
const VK_LBUTTON = 1
const VK_LCONTROL = 162
const VK_LEFT = 37
const VK_LMENU = 164
const VK_LSHIFT = 160
const VK_LWIN = 91
const VK_MBUTTON = 4
const VK_MEDIA_NEXT_TRACK = 176
const VK_MEDIA_PLAY_PAUSE = 179
const VK_MEDIA_PREV_TRACK = 177
const VK_MEDIA_STOP = 178
const VK_MENU = 18
const VK_MODECHANGE = 31
const VK_MULTIPLY = 106
const VK_NAVIGATION_ACCEPT = 142
const VK_NAVIGATION_CANCEL = 143
const VK_NAVIGATION_DOWN = 139
const VK_NAVIGATION_LEFT = 140
const VK_NAVIGATION_MENU = 137
const VK_NAVIGATION_RIGHT = 141
const VK_NAVIGATION_UP = 138
const VK_NAVIGATION_VIEW = 136
const VK_NEXT = 34
const VK_NONAME = 252
const VK_NONCONVERT = 29
const VK_NUMLOCK = 144
const VK_NUMPAD0 = 96
const VK_NUMPAD1 = 97
const VK_NUMPAD2 = 98
const VK_NUMPAD3 = 99
const VK_NUMPAD4 = 100
const VK_NUMPAD5 = 101
const VK_NUMPAD6 = 102
const VK_NUMPAD7 = 103
const VK_NUMPAD8 = 104
const VK_NUMPAD9 = 105
const VK_OEM_1 = 186
const VK_OEM_102 = 226
const VK_OEM_2 = 191
const VK_OEM_3 = 192
const VK_OEM_4 = 219
const VK_OEM_5 = 220
const VK_OEM_6 = 221
const VK_OEM_7 = 222
const VK_OEM_8 = 223
const VK_OEM_ATTN = 240
const VK_OEM_AUTO = 243
const VK_OEM_AX = 225
const VK_OEM_BACKTAB = 245
const VK_OEM_CLEAR = 254
const VK_OEM_COMMA = 188
const VK_OEM_COPY = 242
const VK_OEM_CUSEL = 239
const VK_OEM_ENLW = 244
const VK_OEM_FINISH = 241
const VK_OEM_FJ_JISHO = 146
const VK_OEM_FJ_LOYA = 149
const VK_OEM_FJ_MASSHOU = 147
const VK_OEM_FJ_ROYA = 150
const VK_OEM_FJ_TOUROKU = 148
const VK_OEM_JUMP = 234
const VK_OEM_MINUS = 189
const VK_OEM_NEC_EQUAL = 146
const VK_OEM_PA1 = 235
const VK_OEM_PA2 = 236
const VK_OEM_PA3 = 237
const VK_OEM_PERIOD = 190
const VK_OEM_PLUS = 187
const VK_OEM_RESET = 233
const VK_OEM_WSCTRL = 238
const VK_PA1 = 253
const VK_PACKET = 231
const VK_PAUSE = 19
const VK_PLAY = 250
const VK_PRINT = 42
const VK_PRIOR = 33
const VK_PROCESSKEY = 229
const VK_RBUTTON = 2
const VK_RCONTROL = 163
const VK_RETURN = 13
const VK_RIGHT = 39
const VK_RMENU = 165
const VK_RSHIFT = 161
const VK_RWIN = 92
const VK_SCROLL = 145
const VK_SELECT = 41
const VK_SEPARATOR = 108
const VK_SHIFT = 16
const VK_SLEEP = 95
const VK_SNAPSHOT = 44
const VK_SPACE = 32
const VK_SUBTRACT = 109
const VK_TAB = 9
const VK_UP = 38
const VK_VOLUME_DOWN = 174
const VK_VOLUME_MUTE = 173
const VK_VOLUME_UP = 175
const VK_XBUTTON1 = 5
const VK_XBUTTON2 = 6
const VK_ZOOM = 251
const VOID = 0
const VOLUME_IS_DIRTY = 1
const VOLUME_NAME_DOS = 0
const VOLUME_NAME_GUID = 1
const VOLUME_NAME_NONE = 4
const VOLUME_NAME_NT = 2
const VOLUME_SESSION_OPEN = 4
const VOLUME_UPGRADE_SCHEDULED = 2
const VOS_DOS = 65536
const VOS_DOS_WINDOWS16 = 65537
const VOS_DOS_WINDOWS32 = 65540
const VOS_NT = 262144
const VOS_NT_WINDOWS32 = 262148
const VOS_OS216 = 131072
const VOS_OS216_PM16 = 131074
const VOS_OS232 = 196608
const VOS_OS232_PM32 = 196611
const VOS_UNKNOWN = 0
const VOS_WINCE = 327680
const VOS__BASE = 0
const VOS__PM16 = 2
const VOS__PM32 = 3
const VOS__WINDOWS16 = 1
const VOS__WINDOWS32 = 4
const VP_COMMAND_GET = 1
const VP_COMMAND_SET = 2
const VP_CP_CMD_ACTIVATE = 1
const VP_CP_CMD_CHANGE = 4
const VP_CP_CMD_DEACTIVATE = 2
const VP_CP_TYPE_APS_TRIGGER = 1
const VP_CP_TYPE_MACROVISION = 2
const VP_FLAGS_BRIGHTNESS = 64
const VP_FLAGS_CONTRAST = 128
const VP_FLAGS_COPYPROTECT = 256
const VP_FLAGS_FLICKER = 4
const VP_FLAGS_MAX_UNSCALED = 16
const VP_FLAGS_OVERSCAN = 8
const VP_FLAGS_POSITION = 32
const VP_FLAGS_TV_MODE = 1
const VP_FLAGS_TV_STANDARD = 2
const VP_MODE_TV_PLAYBACK = 2
const VP_MODE_WIN_GRAPHICS = 1
const VP_TV_STANDARD_NTSC_433 = 65536
const VP_TV_STANDARD_NTSC_M = 1
const VP_TV_STANDARD_NTSC_M_J = 2
const VP_TV_STANDARD_PAL_60 = 262144
const VP_TV_STANDARD_PAL_B = 4
const VP_TV_STANDARD_PAL_D = 8
const VP_TV_STANDARD_PAL_G = 131072
const VP_TV_STANDARD_PAL_H = 16
const VP_TV_STANDARD_PAL_I = 32
const VP_TV_STANDARD_PAL_M = 64
const VP_TV_STANDARD_PAL_N = 128
const VP_TV_STANDARD_SECAM_B = 256
const VP_TV_STANDARD_SECAM_D = 512
const VP_TV_STANDARD_SECAM_G = 1024
const VP_TV_STANDARD_SECAM_H = 2048
const VP_TV_STANDARD_SECAM_K = 4096
const VP_TV_STANDARD_SECAM_K1 = 8192
const VP_TV_STANDARD_SECAM_L = 16384
const VP_TV_STANDARD_SECAM_L1 = 524288
const VP_TV_STANDARD_WIN_VGA = 32768
const VREFRESH = 116
const VRL_CLASS_CONSISTENCY = 1
const VRL_CUSTOM_CLASS_BEGIN = 256
const VRL_ENABLE_KERNEL_BREAKS = 2147483648
const VRL_PREDEFINED_CLASS_BEGIN = 1
const VS_ALLOW_LATIN = 1
const VS_FFI_FILEFLAGSMASK = 63
const VS_FFI_SIGNATURE = 4277077181
const VS_FFI_STRUCVERSION = 65536
const VS_FF_DEBUG = 1
const VS_FF_INFOINFERRED = 16
const VS_FF_PATCHED = 4
const VS_FF_PRERELEASE = 2
const VS_FF_PRIVATEBUILD = 8
const VS_FF_SPECIALBUILD = 32
const VS_FILE_INFO = "RT_VERSION"
const VS_USER_DEFINED = 100
const VS_VERSION_INFO = 1
const VTA_BASELINE = 24
const VTA_BOTTOM = 2
const VTA_CENTER = 6
const VTA_LEFT = 8
const VTA_RIGHT = 0
const VTA_TOP = 0
const VTBIT_CY = 1
const VTBIT_DECIMAL = 1
const VTBIT_I1 = 1
const VTBIT_I2 = 1
const VTBIT_I4 = 1
const VTBIT_I8 = 1
const VTBIT_R4 = 1
const VTBIT_R8 = 1
const VTBIT_UI1 = 1
const VTBIT_UI2 = 1
const VTBIT_UI4 = 1
const VTBIT_UI8 = 1
const VTDATEGRE_MAX = 2958465
const VTDATEGRE_MIN = -657434
const VT_HARDTYPE = 0
const VarBoolFromInt = 0
const VarBoolFromUint = 0
const VarBstrFromInt = 0
const VarBstrFromUint = 0
const VarCyFromInt = 0
const VarCyFromUint = 0
const VarDateFromInt = 0
const VarDateFromUint = 0
const VarDecFromInt = 0
const VarDecFromUint = 0
const VarI1FromInt = 0
const VarI1FromUint = 0
const VarI2FromInt = 0
const VarI2FromUint = 0
const VarI4FromInt = 0
const VarI4FromUint = 0
const VarI8FromInt = 0
const VarI8FromUint = 0
const VarIntFromBool = 0
const VarIntFromCy = 0
const VarIntFromDate = 0
const VarIntFromDec = 0
const VarIntFromDisp = 0
const VarIntFromI1 = 0
const VarIntFromI2 = 0
const VarIntFromI4 = 0
const VarIntFromI8 = 0
const VarIntFromR4 = 0
const VarIntFromR8 = 0
const VarIntFromStr = 0
const VarIntFromUI1 = 0
const VarIntFromUI2 = 0
const VarIntFromUI4 = 0
const VarIntFromUI8 = 0
const VarIntFromUint = 0
const VarR4FromInt = 0
const VarR4FromUint = 0
const VarR8FromInt = 0
const VarR8FromUint = 0
const VarUI1FromInt = 0
const VarUI1FromUint = 0
const VarUI2FromInt = 0
const VarUI2FromUint = 0
const VarUI4FromInt = 0
const VarUI4FromUint = 0
const VarUintFromBool = 0
const VarUintFromCy = 0
const VarUintFromDate = 0
const VarUintFromDec = 0
const VarUintFromDisp = 0
const VarUintFromI1 = 0
const VarUintFromI2 = 0
const VarUintFromI4 = 0
const VarUintFromI8 = 0
const VarUintFromInt = 0
const VarUintFromR4 = 0
const VarUintFromR8 = 0
const VarUintFromStr = 0
const VarUintFromUI1 = 0
const VarUintFromUI2 = 0
const VarUintFromUI4 = 0
const VarUintFromUI8 = 0
const VerFindFile = 0
const VerInstallFile = 0
const VerLanguageName = 0
const VerQueryValue = 0
const VerifyVersionInfo = 0
const ViewCanHaveRowid = 0
const VkKeyScan = 0
const VkKeyScanEx = 0
const VolumeClassGuid = 0
const WAIT_CHILD = 0
const WAIT_GRANDCHILD = 1
const WAIT_IO_COMPLETION = "STATUS_USER_APC"
const WAIT_TIMEOUT = 258
const WALINDEX_HDR_SIZE = 0
const WALINDEX_MAX_VERSION = 3007000
const WALINDEX_PGSZ = 0
const WAL_ALL_BUT_WRITE = 1
const WAL_CKPT_LOCK = 1
const WAL_EXCLUSIVE_MODE = 1
const WAL_FRAME_HDRSIZE = 24
const WAL_HDRSIZE = 32
const WAL_HEAPMEMORY_MODE = 2
const WAL_LOCK_CKPT = 1
const WAL_LOCK_READ0 = 3
const WAL_LOCK_WRITE = 0
const WAL_MAGIC = 931071618
const WAL_MAX_VERSION = 3007000
const WAL_NORMAL_MODE = 0
const WAL_NREADER = 5
const WAL_RDONLY = 1
const WAL_RDWR = 0
const WAL_RECOVER_LOCK = 2
const WAL_RETRY = -1
const WAL_RETRY_BLOCKED_MASK = 0
const WAL_RETRY_PROTOCOL_LIMIT = 100
const WAL_SAVEPOINT_NDATA = 4
const WAL_SHM_RDONLY = 2
const WAL_WRITE_LOCK = 0
const WARNING_IPSEC_MM_POLICY_PRUNED = 13024
const WARNING_IPSEC_QM_POLICY_PRUNED = 13025
const WAVECAPS_LRVOLUME = 8
const WAVECAPS_PITCH = 1
const WAVECAPS_PLAYBACKRATE = 2
const WAVECAPS_SAMPLEACCURATE = 32
const WAVECAPS_SYNC = 16
const WAVECAPS_VOLUME = 4
const WAVERR_BADFORMAT = 32
const WAVERR_BASE = 32
const WAVERR_LASTERROR = 35
const WAVERR_STILLPLAYING = 33
const WAVERR_SYNC = 35
const WAVERR_UNPREPARED = 34
const WAVE_ALLOWSYNC = 2
const WAVE_FORMAT_1M08 = 1
const WAVE_FORMAT_1M16 = 4
const WAVE_FORMAT_1S08 = 2
const WAVE_FORMAT_1S16 = 8
const WAVE_FORMAT_2M08 = 16
const WAVE_FORMAT_2M16 = 64
const WAVE_FORMAT_2S08 = 32
const WAVE_FORMAT_2S16 = 128
const WAVE_FORMAT_44M08 = 256
const WAVE_FORMAT_44M16 = 1024
const WAVE_FORMAT_44S08 = 512
const WAVE_FORMAT_44S16 = 2048
const WAVE_FORMAT_48M08 = 4096
const WAVE_FORMAT_48M16 = 16384
const WAVE_FORMAT_48S08 = 8192
const WAVE_FORMAT_48S16 = 32768
const WAVE_FORMAT_4M08 = 256
const WAVE_FORMAT_4M16 = 1024
const WAVE_FORMAT_4S08 = 512
const WAVE_FORMAT_4S16 = 2048
const WAVE_FORMAT_96M08 = 65536
const WAVE_FORMAT_96M16 = 262144
const WAVE_FORMAT_96S08 = 131072
const WAVE_FORMAT_96S16 = 524288
const WAVE_FORMAT_DIRECT = 8
const WAVE_FORMAT_DIRECT_QUERY = 9
const WAVE_FORMAT_PCM = 1
const WAVE_FORMAT_QUERY = 1
const WAVE_INVALIDFORMAT = 0
const WAVE_MAPPED = 4
const WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE = 16
const WAVE_MAPPER = -1
const WA_ACTIVE = 1
const WA_CLICKACTIVE = 2
const WA_INACTIVE = 0
const WB_ISDELIMITER = 2
const WB_LEFT = 0
const WB_RIGHT = 1
const WC_COMPOSITECHECK = 512
const WC_DEFAULTCHAR = 64
const WC_DISCARDNS = 16
const WC_ERR_INVALID_CHARS = 128
const WC_NETADDRESS = "msctls_netaddress"
const WC_NO_BEST_FIT_CHARS = 1024
const WC_SEPCHARS = 32
const WDA_EXCLUDEFROMCAPTURE = 17
const WDA_MONITOR = 1
const WDA_NONE = 0
const WDK_NTDDI_VERSION = 167772171
const WDT_INPROC64_CALL = 1349805143
const WDT_INPROC_CALL = 1215587415
const WDT_REMOTE_CALL = 1383359575
const WGL_FONT_LINES = 0
const WGL_FONT_POLYGONS = 1
const WGL_SWAPMULTIPLE_MAX = 16
const WGL_SWAP_MAIN_PLANE = 1
const WGL_SWAP_OVERLAY1 = 2
const WGL_SWAP_OVERLAY10 = 1024
const WGL_SWAP_OVERLAY11 = 2048
const WGL_SWAP_OVERLAY12 = 4096
const WGL_SWAP_OVERLAY13 = 8192
const WGL_SWAP_OVERLAY14 = 16384
const WGL_SWAP_OVERLAY15 = 32768
const WGL_SWAP_OVERLAY2 = 4
const WGL_SWAP_OVERLAY3 = 8
const WGL_SWAP_OVERLAY4 = 16
const WGL_SWAP_OVERLAY5 = 32
const WGL_SWAP_OVERLAY6 = 64
const WGL_SWAP_OVERLAY7 = 128
const WGL_SWAP_OVERLAY8 = 256
const WGL_SWAP_OVERLAY9 = 512
const WGL_SWAP_UNDERLAY1 = 65536
const WGL_SWAP_UNDERLAY10 = 33554432
const WGL_SWAP_UNDERLAY11 = 67108864
const WGL_SWAP_UNDERLAY12 = 134217728
const WGL_SWAP_UNDERLAY13 = 268435456
const WGL_SWAP_UNDERLAY14 = 536870912
const WGL_SWAP_UNDERLAY15 = 1073741824
const WGL_SWAP_UNDERLAY2 = 131072
const WGL_SWAP_UNDERLAY3 = 262144
const WGL_SWAP_UNDERLAY4 = 524288
const WGL_SWAP_UNDERLAY5 = 1048576
const WGL_SWAP_UNDERLAY6 = 2097152
const WGL_SWAP_UNDERLAY7 = 4194304
const WGL_SWAP_UNDERLAY8 = 8388608
const WGL_SWAP_UNDERLAY9 = 16777216
const WHDR_BEGINLOOP = 4
const WHDR_DONE = 1
const WHDR_ENDLOOP = 8
const WHDR_INQUEUE = 16
const WHDR_PREPARED = 2
const WHEEL_DELTA = 120
const WHEEL_PAGESCROLL = 4294967295
const WHERE_AGG_DISTINCT = 1024
const WHERE_AUTO_INDEX = 16384
const WHERE_BIGNULL_SORT = 524288
const WHERE_BLOOMFILTER = 4194304
const WHERE_BOTH_LIMIT = 48
const WHERE_BTM_LIMIT = 32
const WHERE_COLUMN_EQ = 1
const WHERE_COLUMN_IN = 4
const WHERE_COLUMN_NULL = 8
const WHERE_COLUMN_RANGE = 2
const WHERE_CONSTRAINT = 15
const WHERE_DISTINCTBY = 128
const WHERE_DISTINCT_NOOP = 0
const WHERE_DISTINCT_ORDERED = 2
const WHERE_DISTINCT_UNIQUE = 1
const WHERE_DISTINCT_UNORDERED = 3
const WHERE_DUPLICATES_OK = 16
const WHERE_EXPRIDX = 67108864
const WHERE_GROUPBY = 64
const WHERE_IDX_ONLY = 64
const WHERE_INDEXED = 512
const WHERE_IN_ABLE = 2048
const WHERE_IN_EARLYOUT = 262144
const WHERE_IN_SEEKSCAN = 1048576
const WHERE_IPK = 256
const WHERE_MULTI_OR = 8192
const WHERE_OMIT_OFFSET = 16777216
const WHERE_ONEPASS_DESIRED = 4
const WHERE_ONEPASS_MULTIROW = 8
const WHERE_ONEROW = 4096
const WHERE_ORDERBY_LIMIT = 2048
const WHERE_ORDERBY_MAX = 2
const WHERE_ORDERBY_MIN = 1
const WHERE_ORDERBY_NORMAL = 0
const WHERE_OR_SUBCLAUSE = 32
const WHERE_PARTIALIDX = 131072
const WHERE_RIGHT_JOIN = 4096
const WHERE_SELFCULL = 8388608
const WHERE_SKIPSCAN = 32768
const WHERE_SORTBYGROUP = 512
const WHERE_TOP_LIMIT = 16
const WHERE_TRANSCONS = 2097152
const WHERE_UNQ_WANTED = 65536
const WHERE_USE_LIMIT = 16384
const WHERE_VIRTUALTABLE = 1024
const WHERE_WANT_DISTINCT = 256
const WHITEONBLACK = 2
const WHITE_BRUSH = 0
const WHITE_PEN = 6
const WH_CALLWNDPROC = 4
const WH_CALLWNDPROCRET = 12
const WH_CBT = 5
const WH_DEBUG = 9
const WH_FOREGROUNDIDLE = 11
const WH_GETMESSAGE = 3
const WH_HARDWARE = 8
const WH_JOURNALPLAYBACK = 1
const WH_JOURNALRECORD = 0
const WH_KEYBOARD = 2
const WH_KEYBOARD_LL = 13
const WH_MAX = 14
const WH_MAXHOOK = 14
const WH_MIN = -1
const WH_MINHOOK = -1
const WH_MOUSE = 7
const WH_MOUSE_LL = 14
const WH_MSGFILTER = -1
const WH_SHELL = 10
const WH_SYSMSGFILTER = 6
const WIM_CLOSE = 959
const WIM_DATA = 960
const WIM_OPEN = 958
const WIN31_CLASS = "NULL"
const WIN32 = 1
const WINABLEAPI = "DECLSPEC_IMPORT"
const WINADVAPI = "DECLSPEC_IMPORT"
const WINAPI = "__stdcall"
const WINAPIV = "__cdecl"
const WINAPI_FAMILY = 3
const WINAPI_FAMILY_APP = 2
const WINAPI_FAMILY_DESKTOP_APP = 3
const WINAPI_INLINE = "WINAPI"
const WINAPI_PARTITION_APP = 2
const WINAPI_PARTITION_DESKTOP = 1
const WINBASEAPI = "DECLSPEC_IMPORT"
const WINCFGMGR32API = "DECLSPEC_IMPORT"
const WINCOMMCTRLAPI = "DECLSPEC_IMPORT"
const WINCOMMDLGAPI = "DECLSPEC_IMPORT"
const WINCRYPT32API = "WINIMPM"
const WINCRYPT32STRINGAPI = "WINIMPM"
const WINDEVQUERYAPI = "DECLSPEC_IMPORT"
const WINDING = 2
const WINDOW_AGGINVERSE = 2
const WINDOW_AGGSTEP = 3
const WINDOW_BUFFER_SIZE_EVENT = 4
const WINDOW_ENDING_INT = 1
const WINDOW_ENDING_NUM = 4
const WINDOW_NTH_VALUE_INT = 2
const WINDOW_RETURN_ROW = 1
const WINDOW_STARTING_INT = 0
const WINDOW_STARTING_NUM = 3
const WINEVENT_INCONTEXT = 4
const WINEVENT_OUTOFCONTEXT = 0
const WINEVENT_SKIPOWNPROCESS = 2
const WINEVENT_SKIPOWNTHREAD = 1
const WINFILE_PERSIST_WAL = 4
const WINFILE_PSOW = 16
const WINFILE_RDONLY = 2
const WINGDIAPI = "DECLSPEC_IMPORT"
const WINIMPM = "DECLSPEC_IMPORT"
const WININETINFO_OPTION_LOCK_HANDLE = 65534
const WINMMAPI = "DECLSPEC_IMPORT"
const WINNORMALIZEAPI = "DECLSPEC_IMPORT"
const WINNT = 1
const WINPATHCCHAPI = "WINBASEAPI"
const WINPERF_LOG_DEBUG = 2
const WINPERF_LOG_NONE = 0
const WINPERF_LOG_USER = 1
const WINPERF_LOG_VERBOSE = 3
const WINSHELLAPI = "DECLSPEC_IMPORT"
const WINSHM_RDLCK = 2
const WINSHM_UNLCK = 1
const WINSHM_WRLCK = 3
const WINSPOOLAPI = "DECLSPEC_IMPORT"
const WINSTA_ACCESSCLIPBOARD = 4
const WINSTA_ACCESSGLOBALATOMS = 32
const WINSTA_ALL_ACCESS = 895
const WINSTA_CREATEDESKTOP = 8
const WINSTA_ENUMDESKTOPS = 1
const WINSTA_ENUMERATE = 256
const WINSTA_EXITWINDOWS = 64
const WINSTA_READATTRIBUTES = 2
const WINSTA_READSCREEN = 512
const WINSTA_WRITEATTRIBUTES = 16
const WINSTORAGEAPI = "DECLSPEC_IMPORT"
const WINSWDEVICEAPI = "DECLSPEC_IMPORT"
const WINUSERAPI = "DECLSPEC_IMPORT"
const WINVER = 2560
const WIN_SHM_BASE = 120
const WIN_SHM_DMS = 128
const WIZ_BODYCX = 184
const WIZ_BODYX = 92
const WIZ_CXBMP = 80
const WIZ_CXDLG = 276
const WIZ_CYDLG = 140
const WMSZ_BOTTOM = 6
const WMSZ_BOTTOMLEFT = 7
const WMSZ_BOTTOMRIGHT = 8
const WMSZ_LEFT = 1
const WMSZ_RIGHT = 2
const WMSZ_TOP = 3
const WMSZ_TOPLEFT = 4
const WMSZ_TOPRIGHT = 5
const WM_ACTIVATE = 6
const WM_ACTIVATEAPP = 28
const WM_AFXFIRST = 864
const WM_AFXLAST = 895
const WM_APP = 32768
const WM_APPCOMMAND = 793
const WM_ASKCBFORMATNAME = 780
const WM_CANCELJOURNAL = 75
const WM_CANCELMODE = 31
const WM_CAPTURECHANGED = 533
const WM_CHANGECBCHAIN = 781
const WM_CHANGEUISTATE = 295
const WM_CHAR = 258
const WM_CHARTOITEM = 47
const WM_CHILDACTIVATE = 34
const WM_CHOOSEFONT_GETLOGFONT = 1025
const WM_CHOOSEFONT_SETFLAGS = 1126
const WM_CHOOSEFONT_SETLOGFONT = 1125
const WM_CLEAR = 771
const WM_CLIPBOARDUPDATE = 797
const WM_CLOSE = 16
const WM_COMMAND = 273
const WM_COMMNOTIFY = 68
const WM_COMPACTING = 65
const WM_COMPAREITEM = 57
const WM_CONTEXTMENU = 123
const WM_COPY = 769
const WM_COPYDATA = 74
const WM_CREATE = 1
const WM_CTLCOLORBTN = 309
const WM_CTLCOLORDLG = 310
const WM_CTLCOLOREDIT = 307
const WM_CTLCOLORLISTBOX = 308
const WM_CTLCOLORMSGBOX = 306
const WM_CTLCOLORSCROLLBAR = 311
const WM_CTLCOLORSTATIC = 312
const WM_CUT = 768
const WM_DDE_ACK = 996
const WM_DDE_ADVISE = 994
const WM_DDE_DATA = 997
const WM_DDE_EXECUTE = 1000
const WM_DDE_FIRST = 992
const WM_DDE_INITIATE = 992
const WM_DDE_LAST = 1000
const WM_DDE_POKE = 999
const WM_DDE_REQUEST = 998
const WM_DDE_TERMINATE = 993
const WM_DDE_UNADVISE = 995
const WM_DEADCHAR = 259
const WM_DELETEITEM = 45
const WM_DESTROY = 2
const WM_DESTROYCLIPBOARD = 775
const WM_DEVICECHANGE = 537
const WM_DEVMODECHANGE = 27
const WM_DISPLAYCHANGE = 126
const WM_DPICHANGED = 736
const WM_DPICHANGED_AFTERPARENT = 739
const WM_DPICHANGED_BEFOREPARENT = 738
const WM_DRAWCLIPBOARD = 776
const WM_DRAWITEM = 43
const WM_DROPFILES = 563
const WM_DWMCOLORIZATIONCOLORCHANGED = 800
const WM_DWMCOMPOSITIONCHANGED = 798
const WM_DWMNCRENDERINGCHANGED = 799
const WM_DWMSENDICONICLIVEPREVIEWBITMAP = 806
const WM_DWMSENDICONICTHUMBNAIL = 803
const WM_DWMWINDOWMAXIMIZEDCHANGE = 801
const WM_ENABLE = 10
const WM_ENDSESSION = 22
const WM_ENTERIDLE = 289
const WM_ENTERMENULOOP = 529
const WM_ENTERSIZEMOVE = 561
const WM_ERASEBKGND = 20
const WM_EXITMENULOOP = 530
const WM_EXITSIZEMOVE = 562
const WM_FONTCHANGE = 29
const WM_GESTURE = 281
const WM_GESTURENOTIFY = 282
const WM_GETDLGCODE = 135
const WM_GETDPISCALEDSIZE = 740
const WM_GETFONT = 49
const WM_GETHOTKEY = 51
const WM_GETICON = 127
const WM_GETMINMAXINFO = 36
const WM_GETOBJECT = 61
const WM_GETTEXT = 13
const WM_GETTEXTLENGTH = 14
const WM_GETTITLEBARINFOEX = 831
const WM_HANDHELDFIRST = 856
const WM_HANDHELDLAST = 863
const WM_HELP = 83
const WM_HOTKEY = 786
const WM_HSCROLL = 276
const WM_HSCROLLCLIPBOARD = 782
const WM_ICONERASEBKGND = 39
const WM_IME_CHAR = 646
const WM_IME_COMPOSITION = 271
const WM_IME_COMPOSITIONFULL = 644
const WM_IME_CONTROL = 643
const WM_IME_ENDCOMPOSITION = 270
const WM_IME_KEYDOWN = 656
const WM_IME_KEYLAST = 271
const WM_IME_KEYUP = 657
const WM_IME_NOTIFY = 642
const WM_IME_REQUEST = 648
const WM_IME_SELECT = 645
const WM_IME_SETCONTEXT = 641
const WM_IME_STARTCOMPOSITION = 269
const WM_INITDIALOG = 272
const WM_INITMENU = 278
const WM_INITMENUPOPUP = 279
const WM_INPUT = 255
const WM_INPUTLANGCHANGE = 81
const WM_INPUTLANGCHANGEREQUEST = 80
const WM_INPUT_DEVICE_CHANGE = 254
const WM_KEYDOWN = 256
const WM_KEYFIRST = 256
const WM_KEYLAST = 265
const WM_KEYUP = 257
const WM_KILLFOCUS = 8
const WM_LBUTTONDBLCLK = 515
const WM_LBUTTONDOWN = 513
const WM_LBUTTONUP = 514
const WM_MBUTTONDBLCLK = 521
const WM_MBUTTONDOWN = 519
const WM_MBUTTONUP = 520
const WM_MDIACTIVATE = 546
const WM_MDICASCADE = 551
const WM_MDICREATE = 544
const WM_MDIDESTROY = 545
const WM_MDIGETACTIVE = 553
const WM_MDIICONARRANGE = 552
const WM_MDIMAXIMIZE = 549
const WM_MDINEXT = 548
const WM_MDIREFRESHMENU = 564
const WM_MDIRESTORE = 547
const WM_MDISETMENU = 560
const WM_MDITILE = 550
const WM_MEASUREITEM = 44
const WM_MENUCHAR = 288
const WM_MENUCOMMAND = 294
const WM_MENUDRAG = 291
const WM_MENUGETOBJECT = 292
const WM_MENURBUTTONUP = 290
const WM_MENUSELECT = 287
const WM_MOUSEACTIVATE = 33
const WM_MOUSEFIRST = 512
const WM_MOUSEHOVER = 673
const WM_MOUSEHWHEEL = 526
const WM_MOUSELAST = 526
const WM_MOUSELEAVE = 675
const WM_MOUSEMOVE = 512
const WM_MOUSEWHEEL = 522
const WM_MOVE = 3
const WM_MOVING = 534
const WM_NCACTIVATE = 134
const WM_NCCALCSIZE = 131
const WM_NCCREATE = 129
const WM_NCDESTROY = 130
const WM_NCHITTEST = 132
const WM_NCLBUTTONDBLCLK = 163
const WM_NCLBUTTONDOWN = 161
const WM_NCLBUTTONUP = 162
const WM_NCMBUTTONDBLCLK = 169
const WM_NCMBUTTONDOWN = 167
const WM_NCMBUTTONUP = 168
const WM_NCMOUSEHOVER = 672
const WM_NCMOUSELEAVE = 674
const WM_NCMOUSEMOVE = 160
const WM_NCPAINT = 133
const WM_NCPOINTERDOWN = 578
const WM_NCPOINTERUP = 579
const WM_NCPOINTERUPDATE = 577
const WM_NCRBUTTONDBLCLK = 166
const WM_NCRBUTTONDOWN = 164
const WM_NCRBUTTONUP = 165
const WM_NCXBUTTONDBLCLK = 173
const WM_NCXBUTTONDOWN = 171
const WM_NCXBUTTONUP = 172
const WM_NEXTDLGCTL = 40
const WM_NEXTMENU = 531
const WM_NOTIFY = 78
const WM_NOTIFYFORMAT = 85
const WM_NULL = 0
const WM_PAINT = 15
const WM_PAINTCLIPBOARD = 777
const WM_PAINTICON = 38
const WM_PALETTECHANGED = 785
const WM_PALETTEISCHANGING = 784
const WM_PARENTNOTIFY = 528
const WM_PASTE = 770
const WM_PENWINFIRST = 896
const WM_PENWINLAST = 911
const WM_POINTERACTIVATE = 587
const WM_POINTERCAPTURECHANGED = 588
const WM_POINTERDEVICECHANGE = 568
const WM_POINTERDEVICEINRANGE = 569
const WM_POINTERDEVICEOUTOFRANGE = 570
const WM_POINTERDOWN = 582
const WM_POINTERENTER = 585
const WM_POINTERHWHEEL = 591
const WM_POINTERLEAVE = 586
const WM_POINTERROUTEDAWAY = 594
const WM_POINTERROUTEDRELEASED = 595
const WM_POINTERROUTEDTO = 593
const WM_POINTERUP = 583
const WM_POINTERUPDATE = 581
const WM_POINTERWHEEL = 590
const WM_POWER = 72
const WM_POWERBROADCAST = 536
const WM_PRINT = 791
const WM_PRINTCLIENT = 792
const WM_PSD_ENVSTAMPRECT = 1029
const WM_PSD_FULLPAGERECT = 1025
const WM_PSD_GREEKTEXTRECT = 1028
const WM_PSD_MARGINRECT = 1027
const WM_PSD_MINMARGINRECT = 1026
const WM_PSD_PAGESETUPDLG = 1024
const WM_PSD_YAFULLPAGERECT = 1030
const WM_QUERYDRAGICON = 55
const WM_QUERYENDSESSION = 17
const WM_QUERYNEWPALETTE = 783
const WM_QUERYOPEN = 19
const WM_QUERYUISTATE = 297
const WM_QUEUESYNC = 35
const WM_QUIT = 18
const WM_RBUTTONDBLCLK = 518
const WM_RBUTTONDOWN = 516
const WM_RBUTTONUP = 517
const WM_RENDERALLFORMATS = 774
const WM_RENDERFORMAT = 773
const WM_SETCURSOR = 32
const WM_SETFOCUS = 7
const WM_SETFONT = 48
const WM_SETHOTKEY = 50
const WM_SETICON = 128
const WM_SETREDRAW = 11
const WM_SETTEXT = 12
const WM_SETTINGCHANGE = 26
const WM_SHOWWINDOW = 24
const WM_SIZE = 5
const WM_SIZECLIPBOARD = 779
const WM_SIZING = 532
const WM_SPOOLERSTATUS = 42
const WM_STYLECHANGED = 125
const WM_STYLECHANGING = 124
const WM_SYNCPAINT = 136
const WM_SYSCHAR = 262
const WM_SYSCOLORCHANGE = 21
const WM_SYSCOMMAND = 274
const WM_SYSDEADCHAR = 263
const WM_SYSKEYDOWN = 260
const WM_SYSKEYUP = 261
const WM_TABLET_FIRST = 704
const WM_TABLET_LAST = 735
const WM_TCARD = 82
const WM_THEMECHANGED = 794
const WM_TIMECHANGE = 30
const WM_TIMER = 275
const WM_TOUCH = 576
const WM_TOUCHHITTESTING = 589
const WM_UNDO = 772
const WM_UNICHAR = 265
const WM_UNINITMENUPOPUP = 293
const WM_UPDATEUISTATE = 296
const WM_USER = 1024
const WM_USERCHANGED = 84
const WM_VKEYTOITEM = 46
const WM_VSCROLL = 277
const WM_VSCROLLCLIPBOARD = 778
const WM_WINDOWPOSCHANGED = 71
const WM_WINDOWPOSCHANGING = 70
const WM_WININICHANGE = 26
const WM_WTSSESSION_CHANGE = 689
const WM_XBUTTONDBLCLK = 525
const WM_XBUTTONDOWN = 523
const WM_XBUTTONUP = 524
const WNCON_DYNAMIC = 8
const WNCON_FORNETCARD = 1
const WNCON_NOTROUTED = 2
const WNCON_SLOWLINK = 4
const WNFMT_ABBREVIATED = 2
const WNFMT_CONNECTION = 32
const WNFMT_INENUM = 16
const WNFMT_MULTILINE = 1
const WNNC_CRED_MANAGER = 4294901760
const WNNC_NET_10NET = 327680
const WNNC_NET_3IN1 = 2555904
const WNNC_NET_9TILES = 589824
const WNNC_NET_APPLETALK = 1245184
const WNNC_NET_AS400 = 720896
const WNNC_NET_AVID = 1703936
const WNNC_NET_AVID1 = 3801088
const WNNC_NET_BMC = 1572864
const WNNC_NET_BWNFS = 1048576
const WNNC_NET_CLEARCASE = 1441792
const WNNC_NET_COGENT = 1114112
const WNNC_NET_CSC = 2490368
const WNNC_NET_DAV = 3014656
const WNNC_NET_DCE = 1638400
const WNNC_NET_DECORB = 2097152
const WNNC_NET_DFS = 3866624
const WNNC_NET_DISTINCT = 2293760
const WNNC_NET_DOCUSPACE = 1769472
const WNNC_NET_DRIVEONWEB = 4063232
const WNNC_NET_EXIFS = 2949120
const WNNC_NET_EXTENDNET = 2686976
const WNNC_NET_FARALLON = 1179648
const WNNC_NET_FJ_REDIR = 2228224
const WNNC_NET_FOXBAT = 2818048
const WNNC_NET_FRONTIER = 1507328
const WNNC_NET_FTP_NFS = 786432
const WNNC_NET_GOOGLE = 4390912
const WNNC_NET_HOB_NFS = 3276800
const WNNC_NET_IBMAL = 3407872
const WNNC_NET_INTERGRAPH = 1310720
const WNNC_NET_KNOWARE = 3080192
const WNNC_NET_KWNP = 3932160
const WNNC_NET_LANMAN = 131072
const WNNC_NET_LANSTEP = 524288
const WNNC_NET_LANTASTIC = 655360
const WNNC_NET_LIFENET = 917504
const WNNC_NET_LOCK = 3473408
const WNNC_NET_LOCUS = 393216
const WNNC_NET_MANGOSOFT = 1835008
const WNNC_NET_MASFAX = 3211264
const WNNC_NET_MFILES = 4259840
const WNNC_NET_MSNET = 65536
const WNNC_NET_MS_NFS = 4325376
const WNNC_NET_NDFS = 4456448
const WNNC_NET_NETWARE = 196608
const WNNC_NET_OBJECT_DIRE = 3145728
const WNNC_NET_OPENAFS = 3735552
const WNNC_NET_PATHWORKS = 851968
const WNNC_NET_POWERLAN = 983040
const WNNC_NET_PROTSTOR = 2162688
const WNNC_NET_QUINCY = 3670016
const WNNC_NET_RDR2SAMPLE = 2424832
const WNNC_NET_RIVERFRONT1 = 1966080
const WNNC_NET_RIVERFRONT2 = 2031616
const WNNC_NET_RSFX = 4194304
const WNNC_NET_SERNET = 1900544
const WNNC_NET_SHIVA = 3342336
const WNNC_NET_SMB = 131072
const WNNC_NET_SRT = 3604480
const WNNC_NET_STAC = 2752512
const WNNC_NET_SUN_PC_NFS = 458752
const WNNC_NET_SYMFONET = 1376256
const WNNC_NET_TERMSRV = 3538944
const WNNC_NET_TWINS = 2359296
const WNNC_NET_VINES = 262144
const WNNC_NET_VMWARE = 4128768
const WNNC_NET_YAHOO = 2883584
const WNNC_NET_ZENWORKS = 3997696
const WN_ACCESS_DENIED = 5
const WN_ALREADY_CONNECTED = 85
const WN_BAD_DEV_TYPE = 66
const WN_BAD_HANDLE = 6
const WN_BAD_LEVEL = 124
const WN_BAD_LOCALNAME = 1200
const WN_BAD_NETNAME = 67
const WN_BAD_PASSWORD = 86
const WN_BAD_POINTER = 487
const WN_BAD_PROFILE = 1206
const WN_BAD_PROVIDER = 1204
const WN_BAD_USER = 2202
const WN_BAD_VALUE = 87
const WN_CANCEL = 1223
const WN_CANNOT_OPEN_PROFILE = 1205
const WN_CONNECTED_OTHER_PASSWORD = 2108
const WN_CONNECTED_OTHER_PASSWORD_DEFAULT = 2109
const WN_CONNECTION_CLOSED = 1201
const WN_DEVICE_ALREADY_REMEMBERED = 1202
const WN_DEVICE_ERROR = 31
const WN_DEVICE_IN_USE = 2404
const WN_EXTENDED_ERROR = 1208
const WN_FUNCTION_BUSY = 170
const WN_MORE_DATA = 234
const WN_NET_ERROR = 59
const WN_NOT_AUTHENTICATED = 1244
const WN_NOT_CONNECTED = 2250
const WN_NOT_CONTAINER = 1207
const WN_NOT_INITIALIZING = 1247
const WN_NOT_LOGGED_ON = 1245
const WN_NOT_SUPPORTED = 50
const WN_NOT_VALIDATED = 1311
const WN_NO_ERROR = 0
const WN_NO_MORE_DEVICES = 1248
const WN_NO_MORE_ENTRIES = 259
const WN_NO_NETWORK = 1222
const WN_NO_NET_OR_BAD_PATH = 1203
const WN_OPEN_FILES = 2401
const WN_OUT_OF_MEMORY = 8
const WN_RETRY = 1237
const WN_SUCCESS = 0
const WN_WINDOWS_ERROR = 59
const WNetAddConnection = 0
const WNetAddConnection2 = 0
const WNetAddConnection3 = 0
const WNetCancelConnection = 0
const WNetCancelConnection2 = 0
const WNetConnectionDialog1 = 0
const WNetDisconnectDialog1 = 0
const WNetEnumResource = 0
const WNetGetConnection = 0
const WNetGetLastError = 0
const WNetGetNetworkInformation = 0
const WNetGetProviderName = 0
const WNetGetResourceInformation = 0
const WNetGetResourceParent = 0
const WNetGetUniversalName = 0
const WNetGetUser = 0
const WNetOpenEnum = 0
const WNetRestoreConnection = 0
const WNetUseConnection = 0
const WOF_CURRENT_VERSION = 1
const WOF_PROVIDER_FILE = 2
const WOM_CLOSE = 956
const WOM_DONE = 957
const WOM_OPEN = 955
const WOW64_CONTEXT_ALL = 65599
const WOW64_CONTEXT_CONTROL = 65537
const WOW64_CONTEXT_DEBUG_REGISTERS = 65552
const WOW64_CONTEXT_EXCEPTION_ACTIVE = 134217728
const WOW64_CONTEXT_EXCEPTION_REPORTING = 2147483648
const WOW64_CONTEXT_EXCEPTION_REQUEST = 1073741824
const WOW64_CONTEXT_EXTENDED_REGISTERS = 65568
const WOW64_CONTEXT_FLOATING_POINT = 65544
const WOW64_CONTEXT_FULL = 65543
const WOW64_CONTEXT_INTEGER = 65538
const WOW64_CONTEXT_SEGMENTS = 65540
const WOW64_CONTEXT_SERVICE_ACTIVE = 268435456
const WOW64_CONTEXT_XSTATE = 65600
const WOW64_CONTEXT_i386 = 65536
const WOW64_CONTEXT_i486 = 65536
const WOW64_MAXIMUM_SUPPORTED_EXTENSION = 512
const WOW64_SIZE_OF_80387_REGISTERS = 80
const WO_ALL = 16383
const WO_AND = 1024
const WO_AUX = 64
const WO_EQ = 2
const WO_EQUIV = 2048
const WO_GE = 32
const WO_GT = 4
const WO_IN = 1
const WO_IS = 128
const WO_ISNULL = 256
const WO_LE = 8
const WO_LT = 16
const WO_NOOP = 4096
const WO_OR = 512
const WO_ROWVAL = 8192
const WO_SINGLE = 511
const WPF_ASYNCWINDOWPLACEMENT = 4
const WPF_RESTORETOMAXIMIZED = 2
const WPF_SETMINPOSITION = 1
const WRC_Abort = 2
const WRC_Continue = 0
const WRC_Prune = 1
const WRITE_COMPRESSION_INFO_VALID = 16
const WRITE_DAC = 262144
const WRITE_LOCK = 2
const WRITE_OWNER = 524288
const WRITE_RESTRICTED = 8
const WRITE_WATCH_FLAG_RESET = 1
const WSABASEERR = 10000
const WSADESCRIPTION_LEN = 256
const WSAEACCES = 10013
const WSAEADDRINUSE = 10048
const WSAEADDRNOTAVAIL = 10049
const WSAEAFNOSUPPORT = 10047
const WSAEALREADY = 10037
const WSAEBADF = 10009
const WSAECANCELLED = 10103
const WSAECONNABORTED = 10053
const WSAECONNREFUSED = 10061
const WSAECONNRESET = 10054
const WSAEDESTADDRREQ = 10039
const WSAEDISCON = 10101
const WSAEDQUOT = 10069
const WSAEFAULT = 10014
const WSAEHOSTDOWN = 10064
const WSAEHOSTUNREACH = 10065
const WSAEINPROGRESS = 10036
const WSAEINTR = 10004
const WSAEINVAL = 10022
const WSAEINVALIDPROCTABLE = 10104
const WSAEINVALIDPROVIDER = 10105
const WSAEISCONN = 10056
const WSAELOOP = 10062
const WSAEMFILE = 10024
const WSAEMSGSIZE = 10040
const WSAENAMETOOLONG = 10063
const WSAENETDOWN = 10050
const WSAENETRESET = 10052
const WSAENETUNREACH = 10051
const WSAENOBUFS = 10055
const WSAENOMORE = 10102
const WSAENOPROTOOPT = 10042
const WSAENOTCONN = 10057
const WSAENOTEMPTY = 10066
const WSAENOTSOCK = 10038
const WSAEOPNOTSUPP = 10045
const WSAEPFNOSUPPORT = 10046
const WSAEPROCLIM = 10067
const WSAEPROTONOSUPPORT = 10043
const WSAEPROTOTYPE = 10041
const WSAEPROVIDERFAILEDINIT = 10106
const WSAEREFUSED = 10112
const WSAEREMOTE = 10071
const WSAESHUTDOWN = 10058
const WSAESOCKTNOSUPPORT = 10044
const WSAESTALE = 10070
const WSAETIMEDOUT = 10060
const WSAETOOMANYREFS = 10059
const WSAEUSERS = 10068
const WSAEWOULDBLOCK = 10035
const WSAHOST_NOT_FOUND = 11001
const WSANOTINITIALISED = 10093
const WSANO_ADDRESS = 11004
const WSANO_DATA = 11004
const WSANO_RECOVERY = 11003
const WSASERVICE_NOT_FOUND = 10108
const WSASYSCALLFAILURE = 10107
const WSASYSNOTREADY = 10091
const WSASYS_STATUS_LEN = 128
const WSATRY_AGAIN = 11002
const WSATYPE_NOT_FOUND = 10109
const WSAVERNOTSUPPORTED = 10092
const WSA_E_CANCELLED = 10111
const WSA_E_NO_MORE = 10110
const WSA_QOS_ADMISSION_FAILURE = 11010
const WSA_QOS_BAD_OBJECT = 11013
const WSA_QOS_BAD_STYLE = 11012
const WSA_QOS_EFILTERCOUNT = 11021
const WSA_QOS_EFILTERSTYLE = 11019
const WSA_QOS_EFILTERTYPE = 11020
const WSA_QOS_EFLOWCOUNT = 11023
const WSA_QOS_EFLOWDESC = 11026
const WSA_QOS_EFLOWSPEC = 11017
const WSA_QOS_EOBJLENGTH = 11022
const WSA_QOS_EPOLICYOBJ = 11025
const WSA_QOS_EPROVSPECBUF = 11018
const WSA_QOS_EPSFILTERSPEC = 11028
const WSA_QOS_EPSFLOWSPEC = 11027
const WSA_QOS_ESDMODEOBJ = 11029
const WSA_QOS_ESERVICETYPE = 11016
const WSA_QOS_ESHAPERATEOBJ = 11030
const WSA_QOS_EUNKNOWNPSOBJ = 11024
const WSA_QOS_EUNKOWNPSOBJ = 11024
const WSA_QOS_GENERIC_ERROR = 11015
const WSA_QOS_NO_RECEIVERS = 11008
const WSA_QOS_NO_SENDERS = 11007
const WSA_QOS_POLICY_FAILURE = 11011
const WSA_QOS_RECEIVERS = 11005
const WSA_QOS_REQUEST_CONFIRMED = 11009
const WSA_QOS_RESERVED_PETYPE = 11031
const WSA_QOS_SENDERS = 11006
const WSA_QOS_TRAFFIC_CTRL_ERROR = 11014
const WSF_VISIBLE = 1
const WS_ACTIVECAPTION = 1
const WS_BORDER = 8388608
const WS_CAPTION = 12582912
const WS_CHILD = 1073741824
const WS_CHILDWINDOW = 1073741824
const WS_CLIPCHILDREN = 33554432
const WS_CLIPSIBLINGS = 67108864
const WS_DISABLED = 134217728
const WS_DLGFRAME = 4194304
const WS_EX_ACCEPTFILES = 16
const WS_EX_APPWINDOW = 262144
const WS_EX_CLIENTEDGE = 512
const WS_EX_COMPOSITED = 33554432
const WS_EX_CONTEXTHELP = 1024
const WS_EX_CONTROLPARENT = 65536
const WS_EX_DLGMODALFRAME = 1
const WS_EX_LAYERED = 524288
const WS_EX_LAYOUTRTL = 4194304
const WS_EX_LEFT = 0
const WS_EX_LEFTSCROLLBAR = 16384
const WS_EX_LTRREADING = 0
const WS_EX_MDICHILD = 64
const WS_EX_NOACTIVATE = 134217728
const WS_EX_NOINHERITLAYOUT = 1048576
const WS_EX_NOPARENTNOTIFY = 4
const WS_EX_NOREDIRECTIONBITMAP = 2097152
const WS_EX_OVERLAPPEDWINDOW = 768
const WS_EX_PALETTEWINDOW = 392
const WS_EX_RIGHT = 4096
const WS_EX_RIGHTSCROLLBAR = 0
const WS_EX_RTLREADING = 8192
const WS_EX_STATICEDGE = 131072
const WS_EX_TOOLWINDOW = 128
const WS_EX_TOPMOST = 8
const WS_EX_TRANSPARENT = 32
const WS_EX_WINDOWEDGE = 256
const WS_GROUP = 131072
const WS_HSCROLL = 1048576
const WS_ICONIC = 536870912
const WS_MAXIMIZE = 16777216
const WS_MAXIMIZEBOX = 65536
const WS_MINIMIZE = 536870912
const WS_MINIMIZEBOX = 131072
const WS_OVERLAPPED = 0
const WS_OVERLAPPEDWINDOW = 13565952
const WS_POPUP = 2147483648
const WS_POPUPWINDOW = 2156396544
const WS_SIZEBOX = 262144
const WS_SYSMENU = 524288
const WS_TABSTOP = 65536
const WS_THICKFRAME = 262144
const WS_TILED = 0
const WS_TILEDWINDOW = 13565952
const WS_VISIBLE = 268435456
const WS_VSCROLL = 2097152
const WTS_CONSOLE_CONNECT = 1
const WTS_CONSOLE_DISCONNECT = 2
const WTS_REMOTE_CONNECT = 3
const WTS_REMOTE_DISCONNECT = 4
const WTS_SESSION_CREATE = 10
const WTS_SESSION_LOCK = 7
const WTS_SESSION_LOGOFF = 6
const WTS_SESSION_LOGON = 5
const WTS_SESSION_REMOTE_CONTROL = 9
const WTS_SESSION_TERMINATE = 11
const WTS_SESSION_UNLOCK = 8
const WT_EXECUTEDEFAULT = 0
const WT_EXECUTEDELETEWAIT = 8
const WT_EXECUTEINIOTHREAD = 1
const WT_EXECUTEINLONGTHREAD = 16
const WT_EXECUTEINPERSISTENTIOTHREAD = 64
const WT_EXECUTEINPERSISTENTTHREAD = 128
const WT_EXECUTEINTIMERTHREAD = 32
const WT_EXECUTEINUITHREAD = 2
const WT_EXECUTEINWAITTHREAD = 4
const WT_EXECUTELONGFUNCTION = 16
const WT_EXECUTEONLYONCE = 8
const WT_TRANSFER_IMPERSONATION = 256
const WVR_ALIGNBOTTOM = 64
const WVR_ALIGNLEFT = 32
const WVR_ALIGNRIGHT = 128
const WVR_ALIGNTOP = 16
const WVR_HREDRAW = 256
const WVR_REDRAW = 768
const WVR_VALIDRECTS = 1024
const WVR_VREDRAW = 512
const WaitNamedPipe = 0
const WinHelp = 0
const WriteConsole = 0
const WriteConsoleInput = 0
const WriteConsoleOutput = 0
const WriteConsoleOutputCharacter = 0
const WriteOnceDiskClassGuid = 0
const WritePrivateProfileSection = 0
const WritePrivateProfileString = 0
const WritePrivateProfileStruct = 0
const WriteProfileSection = 0
const WriteProfileString = 0
const X3_BTYPE_QP_INST_VAL_POS_X = 0
const X3_BTYPE_QP_INST_WORD_POS_X = 23
const X3_BTYPE_QP_INST_WORD_X = 2
const X3_BTYPE_QP_SIZE_X = 9
const X3_D_WH_INST_WORD_POS_X = 24
const X3_D_WH_INST_WORD_X = 3
const X3_D_WH_SIGN_VAL_POS_X = 0
const X3_D_WH_SIZE_X = 3
const X3_EMPTY_INST_VAL_POS_X = 0
const X3_EMPTY_INST_WORD_POS_X = 14
const X3_EMPTY_INST_WORD_X = 1
const X3_EMPTY_SIZE_X = 2
const X3_IMM20_INST_WORD_POS_X = 4
const X3_IMM20_INST_WORD_X = 3
const X3_IMM20_SIGN_VAL_POS_X = 0
const X3_IMM20_SIZE_X = 20
const X3_IMM39_1_INST_WORD_POS_X = 0
const X3_IMM39_1_INST_WORD_X = 2
const X3_IMM39_1_SIGN_VAL_POS_X = 36
const X3_IMM39_1_SIZE_X = 23
const X3_IMM39_2_INST_WORD_POS_X = 16
const X3_IMM39_2_INST_WORD_X = 1
const X3_IMM39_2_SIGN_VAL_POS_X = 20
const X3_IMM39_2_SIZE_X = 16
const X3_I_INST_WORD_POS_X = 27
const X3_I_INST_WORD_X = 3
const X3_I_SIGN_VAL_POS_X = 59
const X3_I_SIZE_X = 1
const X3_OPCODE_INST_WORD_POS_X = 28
const X3_OPCODE_INST_WORD_X = 3
const X3_OPCODE_SIGN_VAL_POS_X = 0
const X3_OPCODE_SIZE_X = 4
const X3_P_INST_WORD_POS_X = 0
const X3_P_INST_WORD_X = 3
const X3_P_SIGN_VAL_POS_X = 0
const X3_P_SIZE_X = 4
const X3_TMPLT_INST_WORD_POS_X = 0
const X3_TMPLT_INST_WORD_X = 0
const X3_TMPLT_SIGN_VAL_POS_X = 0
const X3_TMPLT_SIZE_X = 4
const X509_ANY_STRING = "X509_NAME_VALUE"
const X509_ASN_ENCODING = 1
const X509_CRL_REASON_CODE = "X509_ENUMERATED"
const X509_DH_PUBLICKEY = "X509_MULTI_BYTE_UINT"
const X509_DSS_PUBLICKEY = "X509_MULTI_BYTE_UINT"
const X509_NDR_ENCODING = 2
const X509_SUBJECT_INFO_ACCESS = "X509_AUTHORITY_INFO_ACCESS"
const X509_UNICODE_ANY_STRING = "X509_UNICODE_NAME_VALUE"
const XACT_E_FIRST = 2147799040
const XACT_E_LAST = 2147799081
const XACT_S_FIRST = 315392
const XACT_S_LAST = 315408
const XBUTTON1 = 1
const XBUTTON2 = 2
const XCLASS_BOOL = 4096
const XCLASS_DATA = 8192
const XCLASS_FLAGS = 16384
const XCLASS_MASK = 64512
const XCLASS_NOTIFICATION = 32768
const XN_EXPR = -2
const XN_ROWID = -1
const XSTATE_AMX_TILE_CONFIG = 17
const XSTATE_AMX_TILE_DATA = 18
const XSTATE_AVX = 2
const XSTATE_AVX512_KMASK = 5
const XSTATE_AVX512_ZMM = 7
const XSTATE_AVX512_ZMM_H = 6
const XSTATE_CET_S = 12
const XSTATE_CET_U = 11
const XSTATE_GSSE = 2
const XSTATE_IPT = 8
const XSTATE_LEGACY_FLOATING_POINT = 0
const XSTATE_LEGACY_SSE = 1
const XSTATE_LWP = 62
const XSTATE_MASK_ALLOWED = 4611686018427390463
const XSTATE_MASK_AMX_TILE_CONFIG = 131072
const XSTATE_MASK_AMX_TILE_DATA = 262144
const XSTATE_MASK_AVX = 4
const XSTATE_MASK_AVX512 = 224
const XSTATE_MASK_CET_S = 4096
const XSTATE_MASK_CET_U = 2048
const XSTATE_MASK_GSSE = 4
const XSTATE_MASK_IPT = 256
const XSTATE_MASK_LARGE_FEATURES = 262144
const XSTATE_MASK_LEGACY = 3
const XSTATE_MASK_LEGACY_FLOATING_POINT = 1
const XSTATE_MASK_LEGACY_SSE = 2
const XSTATE_MASK_LWP = 4611686018427387904
const XSTATE_MASK_MPX = 24
const XSTATE_MASK_PASID = 1024
const XSTATE_MASK_PERSISTENT = 4611686018427387920
const XSTATE_MASK_USER_VISIBLE_SUPERVISOR = 2048
const XSTATE_MPX_BNDCSR = 4
const XSTATE_MPX_BNDREGS = 3
const XSTATE_PASID = 10
const XST_ADVACKRCVD = 13
const XST_ADVDATAACKRCVD = 16
const XST_ADVDATASENT = 15
const XST_ADVSENT = 11
const XST_CONNECTED = 2
const XST_DATARCVD = 6
const XST_EXECACKRCVD = 10
const XST_EXECSENT = 9
const XST_INCOMPLETE = 1
const XST_INIT1 = 3
const XST_INIT2 = 4
const XST_NULL = 0
const XST_POKEACKRCVD = 8
const XST_POKESENT = 7
const XST_REQSENT = 5
const XST_UNADVACKRCVD = 14
const XST_UNADVSENT = 12
const XTYPF_ACKREQ = 8
const XTYPF_NOBLOCK = 2
const XTYPF_NODATA = 4
const XTYP_ADVDATA = 16400
const XTYP_ADVREQ = 8226
const XTYP_ADVSTART = 4144
const XTYP_ADVSTOP = 32832
const XTYP_CONNECT = 4194
const XTYP_CONNECT_CONFIRM = 32882
const XTYP_DISCONNECT = 32962
const XTYP_ERROR = 32770
const XTYP_EXECUTE = 16464
const XTYP_MASK = 240
const XTYP_MONITOR = 33010
const XTYP_POKE = 16528
const XTYP_REGISTER = 32930
const XTYP_REQUEST = 8368
const XTYP_SHIFT = 4
const XTYP_UNREGISTER = 32978
const XTYP_WILDCONNECT = 8418
const XTYP_XACT_COMPLETE = 32896
const XcvData = 0
const YYDYNSTACK = 1
const YYFALLBACK = 1
const YYFREE = 0
const YYGROWABLESTACK = 1
const YYMALLOCARGTYPE = 0
const YYNOCODE = 322
const YYNOERRORRECOVERY = 1
const YYNRULE = 409
const YYNRULE_WITH_ACTION = 344
const YYNSTATE = 583
const YYNTOKEN = 186
const YYPARSEFREENEVERNULL = 1
const YYREALLOC = 0
const YYSTACKDEPTH = 100
const YYWILDCARD = 101
const YY_ACCEPT_ACTION = 1255
const YY_ACTTAB_COUNT = 2142
const YY_ERROR_ACTION = 1254
const YY_MAX_DSTRCTR = 319
const YY_MAX_REDUCE = 1665
const YY_MAX_SHIFT = 582
const YY_MAX_SHIFTREDUCE = 1253
const YY_MIN_DSTRCTR = 205
const YY_MIN_REDUCE = 1257
const YY_MIN_SHIFTREDUCE = 845
const YY_NO_ACTION = 1256
const YY_REDUCE_COUNT = 411
const YY_REDUCE_MAX = 1798
const YY_REDUCE_MIN = -275
const YY_SHIFT_COUNT = 582
const YY_SHIFT_MAX = 2128
const YY_SHIFT_MIN = 0
const YieldProcessor = 0
const ZAWPROXYAPI = "DECLSPEC_IMPORT"
const ZERO_PADDING = 3
const ZeroMemory = 0
const _ALLOCA_S_HEAP_MARKER = 56797
const _ALLOCA_S_MARKER_SIZE = 8
const _ALLOCA_S_STACK_MARKER = 52428
const _ALLOCA_S_THRESHOLD = 1024
const _ALPHA = 259
const _ANONYMOUS_STRUCT = 0
const _ANONYMOUS_UNION = 0
const _ARGMAX = 100
const _ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = 0
const _BLANK = 64
const _CALL_REPORTFAULT = 2
const _CONTROL = 32
const _CRTIMP2 = "_CRTIMP"
const _CRTIMP_ALTERNATIVE = "_CRTIMP"
const _CRTIMP_NOIA64 = "_CRTIMP"
const _CRTIMP_PURE = "_CRTIMP"
const _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS = 4
const _CRT_INTERNAL_LOCAL_SCANF_OPTIONS = 2
const _CRT_INTERNAL_PRINTF_LEGACY_MSVCRT_COMPATIBILITY = 8
const _CRT_INTERNAL_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS = 16
const _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION = 1
const _CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS = 4
const _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR = 2
const _CRT_INTERNAL_SCANF_LEGACY_MSVCRT_COMPATIBILITY = 4
const _CRT_INTERNAL_SCANF_LEGACY_WIDE_SPECIFIERS = 2
const _CRT_INTERNAL_SCANF_SECURECRT = 1
const _CRT_SECURE_CPP_NOTHROW = 0
const _CVTBUFSIZE = 349
const _Check_return_ = "__checkReturn"
const _DIGIT = 4
const _DOMAIN = 1
const _FILE_OFFSET_BITS = 64
const _FORCENAMELESSUNION = 1
const _FPCLASS_ND = 16
const _FPCLASS_NINF = 4
const _FPCLASS_NN = 8
const _FPCLASS_NZ = 32
const _FPCLASS_PD = 128
const _FPCLASS_PINF = 512
const _FPCLASS_PN = 256
const _FPCLASS_PZ = 64
const _FPCLASS_QNAN = 2
const _FPCLASS_SNAN = 1
const _FREEENTRY = 0
const _HEAPBADBEGIN = -3
const _HEAPBADNODE = -4
const _HEAPBADPTR = -6
const _HEAPEMPTY = -1
const _HEAPEND = -5
const _HEAPOK = -2
const _HEAP_MAXREQ = 4294967264
const _HEX = 128
const _HUGE = 0
const _I16_MAX = 32767
const _I16_MIN = -32768
const _I32_MAX = 2147483647
const _I32_MIN = -2147483648
const _I64_MAX = 9223372036854775807
const _I64_MIN = -9223372036854775808
const _I8_MAX = 127
const _I8_MIN = -128
const _ILP32 = 1
const _INC_CRT_UNICODE_MACROS = 2
const _INTEGRAL_MAX_BITS = 64
const _IOB_ENTRIES = 20
const _IOEOF = 16
const _IOERR = 32
const _IOFBF = 0
const _IOLBF = 64
const _IOMYBUF = 8
const _IONBF = 4
const _IOREAD = 1
const _IORW = 128
const _IOSTRG = 64
const _IOWRT = 2
const _LARGEFILE_SOURCE = 1
const _LARGE_FILE = 1
const _LEADBYTE = 32768
const _LOWER = 2
const _MAX_DIR = 256
const _MAX_DRIVE = 3
const _MAX_ENV = 32767
const _MAX_EXT = 256
const _MAX_FNAME = 256
const _MAX_PATH = 260
const _MAX_WAIT_MALLOC_CRT = 60000
const _MCRTIMP = "_CRTIMP"
const _MRTIMP2 = "_CRTIMP"
const _M_IX86 = 600
const _NFILE = 512
const _NLSCMPERROR = 2147483647
const _NSTREAM_ = 512
const _OLD_P_OVERLAY = 2
const _OUT_TO_DEFAULT = 0
const _OUT_TO_MSGBOX = 2
const _OUT_TO_STDERR = 1
const _OVERFLOW = 3
const _PLOSS = 6
const _POSIX_CPUTIME = 200809
const _POSIX_MONOTONIC_CLOCK = 200809
const _POSIX_THREAD_CPUTIME = 200809
const _POSIX_TIMERS = 200809
const _PROPSHEETPAGEA_V3 = 0
const _PROPSHEETPAGEW_V3 = 0
const _PUNCT = 16
const _P_DETACH = 4
const _P_NOWAIT = 1
const _P_NOWAITO = 3
const _P_OVERLAY = 2
const _P_WAIT = 0
const _P_tmpdir = "\\\\"
const _REPORT_ERRMODE = 3
const _RPC_HTTP_TRANSPORT_CREDENTIALS = 0
const _RPC_SECURITY_QOS_V2 = 0
const _RPC_SECURITY_QOS_V3 = 0
const _RTL_RUN_ONCE_DEF = 1
const _ReadBarrier = 0
const _SECURECRT_FILL_BUFFER_PATTERN = 253
const _SEC_WINNT_AUTH_IDENTITY = 0
const _SING = 2
const _SPACE = 8
const _STRALIGN_USE_SECURE_CRT = 0
const _SYS_OPEN = 20
const _TLOSS = 5
const _TRUNCATE = -1
const _TWO_DIGIT_EXPONENT = 1
const _UI16_MAX = 65535
const _UI32_MAX = 4294967295
const _UI64_MAX = 18446744073709551615
const _UI8_MAX = 255
const _UNDERFLOW = 4
const _UPPER = 1
const _USEDENTRY = 1
const _WAIT_CHILD = 0
const _WAIT_GRANDCHILD = 1
const _WConst_return = 0
const _WIN32 = 1
const _WIN32_IE = 2560
const _WIN32_IE_IE100 = 2560
const _WIN32_IE_IE110 = 2560
const _WIN32_IE_IE20 = 512
const _WIN32_IE_IE30 = 768
const _WIN32_IE_IE302 = 770
const _WIN32_IE_IE40 = 1024
const _WIN32_IE_IE401 = 1025
const _WIN32_IE_IE50 = 1280
const _WIN32_IE_IE501 = 1281
const _WIN32_IE_IE55 = 1360
const _WIN32_IE_IE60 = 1536
const _WIN32_IE_IE60SP1 = 1537
const _WIN32_IE_IE60SP2 = 1539
const _WIN32_IE_IE70 = 1792
const _WIN32_IE_IE80 = 2048
const _WIN32_IE_IE90 = 2304
const _WIN32_IE_LONGHORN = 1792
const _WIN32_IE_NT4 = 512
const _WIN32_IE_NT4SP1 = 512
const _WIN32_IE_NT4SP2 = 512
const _WIN32_IE_NT4SP3 = 770
const _WIN32_IE_NT4SP4 = 1025
const _WIN32_IE_NT4SP5 = 1025
const _WIN32_IE_NT4SP6 = 1280
const _WIN32_IE_WIN10 = 2560
const _WIN32_IE_WIN2K = 1281
const _WIN32_IE_WIN2KSP1 = 1281
const _WIN32_IE_WIN2KSP2 = 1281
const _WIN32_IE_WIN2KSP3 = 1281
const _WIN32_IE_WIN2KSP4 = 1281
const _WIN32_IE_WIN6 = 1792
const _WIN32_IE_WIN7 = 2048
const _WIN32_IE_WIN8 = 2560
const _WIN32_IE_WIN98 = 1025
const _WIN32_IE_WIN98SE = 1280
const _WIN32_IE_WINBLUE = 2560
const _WIN32_IE_WINME = 1360
const _WIN32_IE_WINTHRESHOLD = 2560
const _WIN32_IE_WS03 = 1538
const _WIN32_IE_WS03SP1 = 1539
const _WIN32_IE_XP = 1536
const _WIN32_IE_XPSP1 = 1537
const _WIN32_IE_XPSP2 = 1539
const _WIN32_WINNT = 2560
const _WIN32_WINNT_LONGHORN = 1536
const _WIN32_WINNT_NT4 = 1024
const _WIN32_WINNT_VISTA = 1536
const _WIN32_WINNT_WIN10 = 2560
const _WIN32_WINNT_WIN2K = 1280
const _WIN32_WINNT_WIN6 = 1536
const _WIN32_WINNT_WIN7 = 1537
const _WIN32_WINNT_WIN8 = 1538
const _WIN32_WINNT_WINBLUE = 1539
const _WIN32_WINNT_WINTHRESHOLD = 2560
const _WIN32_WINNT_WINXP = 1281
const _WIN32_WINNT_WS03 = 1282
const _WIN32_WINNT_WS08 = 1536
const _WRITE_ABORT_MSG = 1
const _WriteBarrier = 0
const _X86_ = 1
const _XOPEN_SOURCE = 600
const __ATOMIC_ACQUIRE = 2
const __ATOMIC_ACQ_REL = 4
const __ATOMIC_CONSUME = 1
const __ATOMIC_HLE_ACQUIRE = 65536
const __ATOMIC_HLE_RELEASE = 131072
const __ATOMIC_RELAXED = 0
const __ATOMIC_RELEASE = 3
const __ATOMIC_SEQ_CST = 5
const __BIGGEST_ALIGNMENT__ = 16
const __BYTE_ORDER__ = 1234
const __C89_NAMELESS = 0
const __CCGO__ = 1
const __CHAR_BIT__ = 8
const __CLRCALL_OR_CDECL = "__cdecl"
const __CRTDECL = "__cdecl"
const __DBL_DECIMAL_DIG__ = 17
const __DBL_DIG__ = 15
const __DBL_HAS_DENORM__ = 1
const __DBL_HAS_INFINITY__ = 1
const __DBL_HAS_QUIET_NAN__ = 1
const __DBL_IS_IEC_60559__ = 2
const __DBL_MANT_DIG__ = 53
const __DBL_MAX_10_EXP__ = 308
const __DBL_MAX_EXP__ = 1024
const __DBL_MIN_10_EXP__ = -307
const __DBL_MIN_EXP__ = -1021
const __DEC128_EPSILON__ = 0
const __DEC128_MANT_DIG__ = 34
const __DEC128_MAX_EXP__ = 6145
const __DEC128_MAX__ = 0
const __DEC128_MIN_EXP__ = -6142
const __DEC128_MIN__ = 0
const __DEC128_SUBNORMAL_MIN__ = 0
const __DEC32_EPSILON__ = 0
const __DEC32_MANT_DIG__ = 7
const __DEC32_MAX_EXP__ = 97
const __DEC32_MAX__ = 0
const __DEC32_MIN_EXP__ = -94
const __DEC32_MIN__ = 0
const __DEC32_SUBNORMAL_MIN__ = 0
const __DEC64_EPSILON__ = 0
const __DEC64_MANT_DIG__ = 16
const __DEC64_MAX_EXP__ = 385
const __DEC64_MAX__ = 0
const __DEC64_MIN_EXP__ = -382
const __DEC64_MIN__ = 0
const __DEC64_SUBNORMAL_MIN__ = 0
const __DECIMAL_BID_FORMAT__ = 1
const __DECIMAL_DIG__ = 17
const __DEC_EVAL_METHOD__ = 2
const __FINITE_MATH_ONLY__ = 0
const __FLOAT_WORD_ORDER__ = 1234
const __FLT128_DECIMAL_DIG__ = 36
const __FLT128_DENORM_MIN__ = 0
const __FLT128_DIG__ = 33
const __FLT128_EPSILON__ = 0
const __FLT128_HAS_DENORM__ = 1
const __FLT128_HAS_INFINITY__ = 1
const __FLT128_HAS_QUIET_NAN__ = 1
const __FLT128_IS_IEC_60559__ = 2
const __FLT128_MANT_DIG__ = 113
const __FLT128_MAX_10_EXP__ = 4932
const __FLT128_MAX_EXP__ = 16384
const __FLT128_MAX__ = 0
const __FLT128_MIN_10_EXP__ = -4931
const __FLT128_MIN_EXP__ = -16381
const __FLT128_MIN__ = 0
const __FLT128_NORM_MAX__ = 0
const __FLT32X_DECIMAL_DIG__ = 17
const __FLT32X_DENORM_MIN__ = 0
const __FLT32X_DIG__ = 15
const __FLT32X_EPSILON__ = 0
const __FLT32X_HAS_DENORM__ = 1
const __FLT32X_HAS_INFINITY__ = 1
const __FLT32X_HAS_QUIET_NAN__ = 1
const __FLT32X_IS_IEC_60559__ = 2
const __FLT32X_MANT_DIG__ = 53
const __FLT32X_MAX_10_EXP__ = 308
const __FLT32X_MAX_EXP__ = 1024
const __FLT32X_MAX__ = 0
const __FLT32X_MIN_10_EXP__ = -307
const __FLT32X_MIN_EXP__ = -1021
const __FLT32X_MIN__ = 0
const __FLT32X_NORM_MAX__ = 0
const __FLT32_DECIMAL_DIG__ = 9
const __FLT32_DENORM_MIN__ = 0
const __FLT32_DIG__ = 6
const __FLT32_EPSILON__ = 0
const __FLT32_HAS_DENORM__ = 1
const __FLT32_HAS_INFINITY__ = 1
const __FLT32_HAS_QUIET_NAN__ = 1
const __FLT32_IS_IEC_60559__ = 2
const __FLT32_MANT_DIG__ = 24
const __FLT32_MAX_10_EXP__ = 38
const __FLT32_MAX_EXP__ = 128
const __FLT32_MAX__ = 0
const __FLT32_MIN_10_EXP__ = -37
const __FLT32_MIN_EXP__ = -125
const __FLT32_MIN__ = 0
const __FLT32_NORM_MAX__ = 0
const __FLT64X_DECIMAL_DIG__ = 36
const __FLT64X_DENORM_MIN__ = 0
const __FLT64X_DIG__ = 33
const __FLT64X_EPSILON__ = 0
const __FLT64X_HAS_DENORM__ = 1
const __FLT64X_HAS_INFINITY__ = 1
const __FLT64X_HAS_QUIET_NAN__ = 1
const __FLT64X_IS_IEC_60559__ = 2
const __FLT64X_MANT_DIG__ = 113
const __FLT64X_MAX_10_EXP__ = 4932
const __FLT64X_MAX_EXP__ = 16384
const __FLT64X_MAX__ = 0
const __FLT64X_MIN_10_EXP__ = -4931
const __FLT64X_MIN_EXP__ = -16381
const __FLT64X_MIN__ = 0
const __FLT64X_NORM_MAX__ = 0
const __FLT64_DECIMAL_DIG__ = 17
const __FLT64_DENORM_MIN__ = 0
const __FLT64_DIG__ = 15
const __FLT64_EPSILON__ = 0
const __FLT64_HAS_DENORM__ = 1
const __FLT64_HAS_INFINITY__ = 1
const __FLT64_HAS_QUIET_NAN__ = 1
const __FLT64_IS_IEC_60559__ = 2
const __FLT64_MANT_DIG__ = 53
const __FLT64_MAX_10_EXP__ = 308
const __FLT64_MAX_EXP__ = 1024
const __FLT64_MAX__ = 0
const __FLT64_MIN_10_EXP__ = -307
const __FLT64_MIN_EXP__ = -1021
const __FLT64_MIN__ = 0
const __FLT64_NORM_MAX__ = 0
const __FLT_DECIMAL_DIG__ = 9
const __FLT_DENORM_MIN__ = 0
const __FLT_DIG__ = 6
const __FLT_EPSILON__ = 0
const __FLT_EVAL_METHOD_TS_18661_3__ = 2
const __FLT_EVAL_METHOD__ = 2
const __FLT_HAS_DENORM__ = 1
const __FLT_HAS_INFINITY__ = 1
const __FLT_HAS_QUIET_NAN__ = 1
const __FLT_IS_IEC_60559__ = 2
const __FLT_MANT_DIG__ = 24
const __FLT_MAX_10_EXP__ = 38
const __FLT_MAX_EXP__ = 128
const __FLT_MAX__ = 0
const __FLT_MIN_10_EXP__ = -37
const __FLT_MIN_EXP__ = -125
const __FLT_MIN__ = 0
const __FLT_NORM_MAX__ = 0
const __FLT_RADIX__ = 2
const __FUNCTION__ = 0
const __GCC_ASM_FLAG_OUTPUTS__ = 1
const __GCC_ATOMIC_BOOL_LOCK_FREE = 2
const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2
const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2
const __GCC_ATOMIC_CHAR_LOCK_FREE = 2
const __GCC_ATOMIC_INT_LOCK_FREE = 2
const __GCC_ATOMIC_LLONG_LOCK_FREE = 2
const __GCC_ATOMIC_LONG_LOCK_FREE = 2
const __GCC_ATOMIC_POINTER_LOCK_FREE = 2
const __GCC_ATOMIC_SHORT_LOCK_FREE = 2
const __GCC_ATOMIC_TEST_AND_SET_TRUEVAL = 1
const __GCC_ATOMIC_WCHAR_T_LOCK_FREE = 2
const __GCC_CONSTRUCTIVE_SIZE = 64
const __GCC_DESTRUCTIVE_SIZE = 64
const __GCC_HAVE_DWARF2_CFI_ASM = 1
const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1
const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1
const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1
const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1
const __GCC_IEC_559 = 2
const __GCC_IEC_559_COMPLEX = 2
const __GNUC_EXECUTION_CHARSET_NAME = "UTF-8"
const __GNUC_MINOR__ = 0
const __GNUC_PATCHLEVEL__ = 0
const __GNUC_STDC_INLINE__ = 1
const __GNUC_WIDE_EXECUTION_CHARSET_NAME = "UTF-16LE"
const __GNUC__ = 12
const __GNU_EXTENSION = 0
const __GOT_SECURE_LIB__ = 200411
const __GXX_ABI_VERSION = 1017
const __GXX_MERGED_TYPEINFO_NAMES = 0
const __GXX_TYPEINFO_EQUALITY_INLINE = 0
const __HAVE_SPECULATION_SAFE_VALUE = 1
const __ILP32__ = 1
const __INT16_MAX__ = 32767
const __INT32_MAX__ = 2147483647
const __INT32_TYPE__ = 0
const __INT64_MAX__ = 9223372036854775807
const __INT8_MAX__ = 127
const __INTMAX_MAX__ = 9223372036854775807
const __INTMAX_WIDTH__ = 64
const __INTPTR_MAX__ = 2147483647
const __INTPTR_TYPE__ = 0
const __INTPTR_WIDTH__ = 32
const __INT_FAST16_MAX__ = 32767
const __INT_FAST16_WIDTH__ = 16
const __INT_FAST32_MAX__ = 2147483647
const __INT_FAST32_TYPE__ = 0
const __INT_FAST32_WIDTH__ = 32
const __INT_FAST64_MAX__ = 9223372036854775807
const __INT_FAST64_WIDTH__ = 64
const __INT_FAST8_MAX__ = 127
const __INT_FAST8_WIDTH__ = 8
const __INT_LEAST16_MAX__ = 32767
const __INT_LEAST16_WIDTH__ = 16
const __INT_LEAST32_MAX__ = 2147483647
const __INT_LEAST32_TYPE__ = 0
const __INT_LEAST32_WIDTH__ = 32
const __INT_LEAST64_MAX__ = 9223372036854775807
const __INT_LEAST64_WIDTH__ = 64
const __INT_LEAST8_MAX__ = 127
const __INT_LEAST8_WIDTH__ = 8
const __INT_MAX__ = 2147483647
const __INT_WIDTH__ = 32
const __LAHF_SAHF__ = 1
const __LDBL_DECIMAL_DIG__ = 17
const __LDBL_DENORM_MIN__ = 0
const __LDBL_DIG__ = 15
const __LDBL_EPSILON__ = 0
const __LDBL_HAS_DENORM__ = 1
const __LDBL_HAS_INFINITY__ = 1
const __LDBL_HAS_QUIET_NAN__ = 1
const __LDBL_IS_IEC_60559__ = 2
const __LDBL_MANT_DIG__ = 53
const __LDBL_MAX_10_EXP__ = 308
const __LDBL_MAX_EXP__ = 1024
const __LDBL_MAX__ = 0
const __LDBL_MIN_10_EXP__ = -307
const __LDBL_MIN_EXP__ = -1021
const __LDBL_MIN__ = 0
const __LDBL_NORM_MAX__ = 0
const __LONG32 = 0
const __LONG_DOUBLE_64__ = 1
const __LONG_LONG_MAX__ = 9223372036854775807
const __LONG_LONG_WIDTH__ = 64
const __LONG_MAX__ = 2147483647
const __LONG_WIDTH__ = 32
const __MIDL_CONST = 0
const __MINGW32_MAJOR_VERSION = 3
const __MINGW32_MINOR_VERSION = 11
const __MINGW32__ = 1
const __MINGW64_VERSION_BUGFIX = 0
const __MINGW64_VERSION_MAJOR = 10
const __MINGW64_VERSION_MINOR = 0
const __MINGW64_VERSION_RC = 0
const __MINGW64_VERSION_STATE = "alpha"
const __MINGW_ATTRIB_DEPRECATED_MSVC2005 = 0
const __MINGW_ATTRIB_DEPRECATED_SEC_WARN = 0
const __MINGW_DEBUGBREAK_IMPL = 1
const __MINGW_FORTIFY_LEVEL = 0
const __MINGW_FORTIFY_VA_ARG = 0
const __MINGW_FPCLASS_DEFINED = 1
const __MINGW_GCC_VERSION = 120000
const __MINGW_HAVE_ANSI_C99_PRINTF = 1
const __MINGW_HAVE_ANSI_C99_SCANF = 1
const __MINGW_HAVE_WIDE_C99_PRINTF = 1
const __MINGW_HAVE_WIDE_C99_SCANF = 1
const __MINGW_MSVC2005_DEPREC_STR = "This POSIX function is deprecated beginning in Visual C++ 2005, use _CRT_NONSTDC_NO_DEPRECATE to disable deprecation"
const __MINGW_PROCNAMEEXT_AW = "A"
const __MINGW_SEC_WARN_STR = "This function or variable may be unsafe, use _CRT_SECURE_NO_WARNINGS to disable deprecation"
const __MSVCRT_VERSION__ = 1792
const __MSVCRT__ = 1
const __NO_INLINE__ = 1
const __ORDER_BIG_ENDIAN__ = 4321
const __ORDER_LITTLE_ENDIAN__ = 1234
const __ORDER_PDP_ENDIAN__ = 3412
const __PCTYPE_FUNC = 0
const __PRAGMA_REDEFINE_EXTNAME = 1
const __PRETTY_FUNCTION__ = 0
const __PTRDIFF_MAX__ = 2147483647
const __PTRDIFF_TYPE__ = 0
const __PTRDIFF_WIDTH__ = 32
const __REQUIRED_RPCNDR_H_VERSION__ = 475
const __RPCNDR_H_VERSION__ = 475
const __RPCSAL_H_VERSION__ = 100
const __RPC_API = "__stdcall"
const __RPC_CALLEE = "__stdcall"
const __RPC_STUB = "__RPC_API"
const __RPC_USER = "__RPC_API"
const __SCHAR_MAX__ = 127
const __SCHAR_WIDTH__ = 8
const __SEG_FS = 1
const __SEG_GS = 1
const __SHRT_MAX__ = 32767
const __SHRT_WIDTH__ = 16
const __SIG_ATOMIC_MAX__ = 2147483647
const __SIG_ATOMIC_MIN__ = -2147483648
const __SIG_ATOMIC_TYPE__ = 0
const __SIG_ATOMIC_WIDTH__ = 32
const __SIZEOF_DOUBLE__ = 8
const __SIZEOF_FLOAT128__ = 16
const __SIZEOF_FLOAT80__ = 12
const __SIZEOF_FLOAT__ = 4
const __SIZEOF_INT__ = 4
const __SIZEOF_LONG_DOUBLE__ = 8
const __SIZEOF_LONG_LONG__ = 8
const __SIZEOF_LONG__ = 4
const __SIZEOF_POINTER__ = 4
const __SIZEOF_PTRDIFF_T__ = 4
const __SIZEOF_SHORT__ = 2
const __SIZEOF_SIZE_T__ = 4
const __SIZEOF_WCHAR_T__ = 2
const __SIZEOF_WINT_T__ = 2
const __SIZE_MAX__ = 4294967295
const __SIZE_WIDTH__ = 32
const __SQLITESESSION_H_ = 1
const __STDC_HOSTED__ = 1
const __STDC_SECURE_LIB__ = 200411
const __STDC_UTF_16__ = 1
const __STDC_UTF_32__ = 1
const __STDC_VERSION__ = 201710
const __STDC_WANT_SECURE_LIB__ = 0
const __STDC__ = 1
const __UA_WCSLEN = 0
const __UINT16_MAX__ = 65535
const __UINT32_MAX__ = 4294967295
const __UINT64_MAX__ = 18446744073709551615
const __UINT8_MAX__ = 255
const __UINTMAX_MAX__ = 18446744073709551615
const __UINTPTR_MAX__ = 4294967295
const __UINT_FAST16_MAX__ = 65535
const __UINT_FAST32_MAX__ = 4294967295
const __UINT_FAST64_MAX__ = 18446744073709551615
const __UINT_FAST8_MAX__ = 255
const __UINT_LEAST16_MAX__ = 65535
const __UINT_LEAST32_MAX__ = 4294967295
const __UINT_LEAST64_MAX__ = 18446744073709551615
const __UINT_LEAST8_MAX__ = 255
const __USER_LABEL_PREFIX__ = 0
const __USE_MINGW_ANSI_STDIO = 1
const __USE_MINGW_STRTOX = 1
const __VERSION__ = "12-win32"
const __WCHAR_MAX__ = 65535
const __WCHAR_MIN__ = 0
const __WCHAR_WIDTH__ = 16
const __WIN32 = 1
const __WIN32__ = 1
const __WINNT = 1
const __WINNT__ = 1
const __WINT_MAX__ = 65535
const __WINT_MIN__ = 0
const __WINT_WIDTH__ = 16
const __argc = 0
const __argv = 0
const __builtin_vsnprintf = 0
const __builtin_vsprintf = 0
const __checkReturn = "__inner_checkReturn"
const __clockid_t_defined = 1
const __code_model_32__ = 1
const __i386 = 1
const __i386__ = 1
const __i686 = 1
const __i686__ = 1
const __int16 = 0
const __int32 = 0
const __int3264 = 0
const __int8 = 0
const __mb_cur_max = 0
const __mingw_bos_ovr = "__mingw_ovr"
const __mingw_choose_expr = 0
const __pentiumpro = 1
const __pentiumpro__ = 1
const __setusermatherr = 0
const __wargv = 0
const _acmdln = 0
const _copysignl = 0
const _doserrno = 0
const _environ = 0
const _fmode = 0
const _ftime = 0
const _ftime_s = 0
const _hypotl = 0
const _inline = 0
const _iob = 0
const _osplatform = 0
const _osver = 0
const _pctype = 0
const _pgmptr = 0
const _pwctype = 0
const _threadid = 0
const _timeb = 0
const _wP_tmpdir = "\\\\"
const _wcmdln = 0
const _wctype = 0
const _wenviron = 0
const _winmajor = 0
const _winminor = 0
const _winver = 0
const _wpgmptr = 0
const abnormal_termination = 0
const auxGetDevCaps = 0
const bBatch = 0
const cPRIV_KEY_CACHE_MAX_ITEMS_DEFAULT = 20
const cPRIV_KEY_CACHE_PURGE_INTERVAL_SECONDS_DEFAULT = 86400
const cbNDRContext = 20
const chx1 = 1040
const chx10 = 1049
const chx11 = 1050
const chx12 = 1051
const chx13 = 1052
const chx14 = 1053
const chx15 = 1054
const chx16 = 1055
const chx2 = 1041
const chx3 = 1042
const chx4 = 1043
const chx5 = 1044
const chx6 = 1045
const chx7 = 1046
const chx8 = 1047
const chx9 = 1048
const cmb1 = 1136
const cmb10 = 1145
const cmb11 = 1146
const cmb12 = 1147
const cmb13 = 1148
const cmb14 = 1149
const cmb15 = 1150
const cmb16 = 1151
const cmb2 = 1137
const cmb3 = 1138
const cmb4 = 1139
const cmb5 = 1140
const cmb6 = 1141
const cmb7 = 1142
const cmb8 = 1143
const cmb9 = 1144
const ctl1 = 1184
const ctlFirst = 1024
const ctlLast = 1279
const cume_distFinalizeFunc = 0
const dwFORCE_KEY_PROTECTION_DISABLED = 0
const dwFORCE_KEY_PROTECTION_HIGH = 2
const dwFORCE_KEY_PROTECTION_USER_SELECT = 1
const edt1 = 1152
const edt10 = 1161
const edt11 = 1162
const edt12 = 1163
const edt13 = 1164
const edt14 = 1165
const edt15 = 1166
const edt16 = 1167
const edt2 = 1153
const edt3 = 1154
const edt4 = 1155
const edt5 = 1156
const edt6 = 1157
const edt7 = 1158
const edt8 = 1159
const edt9 = 1160
const environ = 0
const errno = 0
const etBUFSIZE = 70
const etCHARX = 8
const etDECIMAL = 16
const etDYNSTRING = 6
const etEXP = 2
const etFLOAT = 1
const etGENERIC = 3
const etINVALID = 17
const etORDINAL = 15
const etPERCENT = 7
const etPOINTER = 13
const etRADIX = 0
const etSIZE = 4
const etSQLESCAPE = 9
const etSQLESCAPE2 = 10
const etSQLESCAPE3 = 14
const etSRCITEM = 12
const etSTRING = 5
const etTOKEN = 11
const exception_code = 0
const first_valueInvFunc = 0
const first_valueValueFunc = 0
const frm1 = 1076
const frm2 = 1077
const frm3 = 1078
const frm4 = 1079
const fseeko = 0
const ftello = 0
const fts5GetVarint = 0
const fts5YYDYNSTACK = 0
const fts5YYFREE = 0
const fts5YYGROWABLESTACK = 0
const fts5YYMALLOCARGTYPE = 0
const fts5YYNFTS5TOKEN = 16
const fts5YYNOCODE = 27
const fts5YYNOERRORRECOVERY = 1
const fts5YYNRULE = 28
const fts5YYNRULE_WITH_ACTION = 28
const fts5YYNSTATE = 35
const fts5YYPARSEFREENOTNULL = 1
const fts5YYREALLOC = 0
const fts5YYSTACKDEPTH = 100
const fts5YY_ACCEPT_ACTION = 81
const fts5YY_ACTTAB_COUNT = 105
const fts5YY_ERROR_ACTION = 80
const fts5YY_MAX_DSTRCTR = 24
const fts5YY_MAX_REDUCE = 110
const fts5YY_MAX_SHIFT = 34
const fts5YY_MAX_SHIFTREDUCE = 79
const fts5YY_MIN_DSTRCTR = 16
const fts5YY_MIN_REDUCE = 83
const fts5YY_MIN_SHIFTREDUCE = 52
const fts5YY_NO_ACTION = 82
const fts5YY_REDUCE_COUNT = 17
const fts5YY_REDUCE_MAX = 67
const fts5YY_REDUCE_MIN = -17
const fts5YY_SHIFT_COUNT = 34
const fts5YY_SHIFT_MAX = 93
const fts5YY_SHIFT_MIN = 0
const get4byte = 0
const getVarint = 0
const grp1 = 1072
const grp2 = 1073
const grp3 = 1074
const grp4 = 1075
const h_errno = 0
const hyper = "__int64"
const i386 = 1
const ico1 = 1084
const ico2 = 1085
const ico3 = 1086
const ico4 = 1087
const isascii = 0
const iscsym = 0
const iscsymf = 0
const joyGetDevCaps = 0
const lst1 = 1120
const lst10 = 1129
const lst11 = 1130
const lst12 = 1131
const lst13 = 1132
const lst14 = 1133
const lst15 = 1134
const lst16 = 1135
const lst2 = 1121
const lst3 = 1122
const lst4 = 1123
const lst5 = 1124
const lst6 = 1125
const lst7 = 1126
const lst8 = 1127
const lst9 = 1128
const lstrcat = 0
const lstrcmp = 0
const lstrcmpi = 0
const lstrcpy = 0
const lstrcpyn = 0
const lstrlen = 0
const matherr = 0
const mciGetDeviceID = 0
const mciGetDeviceIDFromElementID = 0
const mciGetErrorString = 0
const mciSendCommand = 0
const mciSendString = 0
const mem0 = 0
const midiInGetDevCaps = 0
const midiInGetErrorText = 0
const midiOutGetDevCaps = 0
const midiOutGetErrorText = 0
const midl_user_allocate = 0
const midl_user_free = 0
const mixerGetControlDetails = 0
const mixerGetDevCaps = 0
const mixerGetLineControls = 0
const mixerGetLineInfo = 0
const mmioInstallIOProc = 0
const mmioOpen = 0
const mmioRename = 0
const mmioStringToFOURCC = 0
const noopFunc = 0
const nth_valueInvFunc = 0
const nth_valueValueFunc = 0
const ntileFinalizeFunc = 0
const onexit_t = 0
const osInterlockedCompareExchange = 0
const pcache1 = 0
const pclose = 0
const percent_rankFinalizeFunc = 0
const popen = 0
const pread64 = 0
const psh1 = 1024
const psh10 = 1033
const psh11 = 1034
const psh12 = 1035
const psh13 = 1036
const psh14 = 1037
const psh15 = 1038
const psh16 = 1039
const psh2 = 1025
const psh3 = 1026
const psh4 = 1027
const psh5 = 1028
const psh6 = 1029
const psh7 = 1030
const psh8 = 1031
const psh9 = 1032
const pshHelp = 1038
const put4byte = 0
const putVarint = 0
const pwrite64 = 0
const rad1 = 1056
const rad10 = 1065
const rad11 = 1066
const rad12 = 1067
const rad13 = 1068
const rad14 = 1069
const rad15 = 1070
const rad16 = 1071
const rad2 = 1057
const rad3 = 1058
const rad4 = 1059
const rad5 = 1060
const rad6 = 1061
const rad7 = 1062
const rad8 = 1063
const rad9 = 1064
const rct1 = 1080
const rct2 = 1081
const rct3 = 1082
const rct4 = 1083
const rpc_binding_handle_t = 0
const rpc_binding_vector_t = 0
const scr1 = 1168
const scr2 = 1169
const scr3 = 1170
const scr4 = 1171
const scr5 = 1172
const scr6 = 1173
const scr7 = 1174
const scr8 = 1175
const sndPlaySound = 0
const sqlite3Fts5ParserARG_PARAM = 0
const sqlite3Fts5ParserARG_PDECL = 0
const sqlite3Fts5ParserFTS5TOKENTYPE = 0
const sqlite3GlobalConfig = 0
const sqlite3ParserCTX_PARAM = 0
const sqlite3ParserCTX_PDECL = 0
const sqlite3ParserTOKENTYPE = 0
const sqlite3Parser_ENGINEALWAYSONSTACK = 1
const sqlite3StrNICmp = 0
const stc1 = 1088
const stc10 = 1097
const stc11 = 1098
const stc12 = 1099
const stc13 = 1100
const stc14 = 1101
const stc15 = 1102
const stc16 = 1103
const stc17 = 1104
const stc18 = 1105
const stc19 = 1106
const stc2 = 1089
const stc20 = 1107
const stc21 = 1108
const stc22 = 1109
const stc23 = 1110
const stc24 = 1111
const stc25 = 1112
const stc26 = 1113
const stc27 = 1114
const stc28 = 1115
const stc29 = 1116
const stc3 = 1090
const stc30 = 1117
const stc31 = 1118
const stc32 = 1119
const stc4 = 1091
const stc5 = 1092
const stc6 = 1093
const stc7 = 1094
const stc8 = 1095
const stc9 = 1096
const stderr = 0
const stdin = 0
const stdout = 0
const strcasecmp = 0
const strncasecmp = 0
const sys_errlist = 0
const sys_nerr = 0
const szFORCE_KEY_PROTECTION = "ForceKeyProtection"
const szKEY_CACHE_ENABLED = "CachePrivateKeys"
const szKEY_CACHE_SECONDS = "PrivateKeyLifetimeSeconds"
const szKEY_CRYPTOAPI_PRIVATE_KEY_OPTIONS = "Software\\\\Policies\\\\Microsoft\\\\Cryptography"
const szOIDVerisign_FailInfo = "2.16.840.1.113733.1.9.4"
const szOIDVerisign_MessageType = "2.16.840.1.113733.1.9.2"
const szOIDVerisign_PkiStatus = "2.16.840.1.113733.1.9.3"
const szOIDVerisign_RecipientNonce = "2.16.840.1.113733.1.9.6"
const szOIDVerisign_SenderNonce = "2.16.840.1.113733.1.9.5"
const szOIDVerisign_TransactionID = "2.16.840.1.113733.1.9.7"
const szOID_ANSI_X942 = "1.2.840.10046"
const szOID_ANSI_X942_DH = "1.2.840.10046.2.1"
const szOID_ANY_APPLICATION_POLICY = "1.3.6.1.4.1.311.10.12.1"
const szOID_ANY_CERT_POLICY = "2.5.29.32.0"
const szOID_ANY_ENHANCED_KEY_USAGE = "2.5.29.37.0"
const szOID_APPLICATION_CERT_POLICIES = "1.3.6.1.4.1.311.21.10"
const szOID_APPLICATION_POLICY_CONSTRAINTS = "1.3.6.1.4.1.311.21.12"
const szOID_APPLICATION_POLICY_MAPPINGS = "1.3.6.1.4.1.311.21.11"
const szOID_ARCHIVED_KEY_ATTR = "1.3.6.1.4.1.311.21.13"
const szOID_ARCHIVED_KEY_CERT_HASH = "1.3.6.1.4.1.311.21.16"
const szOID_ATTEST_WHQL_CRYPTO = "1.3.6.1.4.1.311.10.3.5.1"
const szOID_ATTR_PLATFORM_SPECIFICATION = "2.23.133.2.17"
const szOID_ATTR_SUPPORTED_ALGORITHMS = "2.5.4.52"
const szOID_ATTR_TPM_SECURITY_ASSERTIONS = "2.23.133.2.18"
const szOID_ATTR_TPM_SPECIFICATION = "2.23.133.2.16"
const szOID_AUTHORITY_INFO_ACCESS = "1.3.6.1.5.5.7.1.1"
const szOID_AUTHORITY_KEY_IDENTIFIER = "2.5.29.1"
const szOID_AUTHORITY_KEY_IDENTIFIER2 = "2.5.29.35"
const szOID_AUTHORITY_REVOCATION_LIST = "2.5.4.38"
const szOID_AUTO_ENROLL_CTL_USAGE = "1.3.6.1.4.1.311.20.1"
const szOID_BACKGROUND_OTHER_LOGOTYPE = "1.3.6.1.5.5.7.20.2"
const szOID_BASIC_CONSTRAINTS = "2.5.29.10"
const szOID_BASIC_CONSTRAINTS2 = "2.5.29.19"
const szOID_BIOMETRIC_EXT = "1.3.6.1.5.5.7.1.2"
const szOID_BIOMETRIC_SIGNING = "1.3.6.1.4.1.311.10.3.41"
const szOID_BUSINESS_CATEGORY = "2.5.4.15"
const szOID_CA_CERTIFICATE = "2.5.4.37"
const szOID_CERTIFICATE_REVOCATION_LIST = "2.5.4.39"
const szOID_CERTIFICATE_TEMPLATE = "1.3.6.1.4.1.311.21.7"
const szOID_CERTSRV_CA_VERSION = "1.3.6.1.4.1.311.21.1"
const szOID_CERTSRV_CROSSCA_VERSION = "1.3.6.1.4.1.311.21.22"
const szOID_CERTSRV_PREVIOUS_CERT_HASH = "1.3.6.1.4.1.311.21.2"
const szOID_CERT_DISALLOWED_FILETIME_PROP_ID = "1.3.6.1.4.1.311.10.11.104"
const szOID_CERT_EXTENSIONS = "1.3.6.1.4.1.311.2.1.14"
const szOID_CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID = "1.3.6.1.4.1.311.10.11.28"
const szOID_CERT_KEY_IDENTIFIER_PROP_ID = "1.3.6.1.4.1.311.10.11.20"
const szOID_CERT_MANIFOLD = "1.3.6.1.4.1.311.20.3"
const szOID_CERT_MD5_HASH_PROP_ID = "1.3.6.1.4.1.311.10.11.4"
const szOID_CERT_POLICIES = "2.5.29.32"
const szOID_CERT_POLICIES_95 = "2.5.29.3"
const szOID_CERT_POLICIES_95_QUALIFIER1 = "2.16.840.1.113733.1.7.1.1"
const szOID_CERT_PROP_ID_PREFIX = "1.3.6.1.4.1.311.10.11."
const szOID_CERT_SIGNATURE_HASH_PROP_ID = "1.3.6.1.4.1.311.10.11.15"
const szOID_CERT_STRONG_KEY_OS_1 = "1.3.6.1.4.1.311.72.2.1"
const szOID_CERT_STRONG_KEY_OS_CURRENT = "szOID_CERT_STRONG_KEY_OS_1"
const szOID_CERT_STRONG_KEY_OS_PREFIX = "1.3.6.1.4.1.311.72.2."
const szOID_CERT_STRONG_SIGN_OS_1 = "1.3.6.1.4.1.311.72.1.1"
const szOID_CERT_STRONG_SIGN_OS_CURRENT = "szOID_CERT_STRONG_SIGN_OS_1"
const szOID_CERT_STRONG_SIGN_OS_PREFIX = "1.3.6.1.4.1.311.72.1."
const szOID_CERT_SUBJECT_NAME_MD5_HASH_PROP_ID = "1.3.6.1.4.1.311.10.11.29"
const szOID_CMC = "1.3.6.1.5.5.7.7"
const szOID_CMC_ADD_ATTRIBUTES = "1.3.6.1.4.1.311.10.10.1"
const szOID_CMC_ADD_EXTENSIONS = "1.3.6.1.5.5.7.7.8"
const szOID_CMC_DATA_RETURN = "1.3.6.1.5.5.7.7.4"
const szOID_CMC_DECRYPTED_POP = "1.3.6.1.5.5.7.7.10"
const szOID_CMC_ENCRYPTED_POP = "1.3.6.1.5.5.7.7.9"
const szOID_CMC_GET_CERT = "1.3.6.1.5.5.7.7.15"
const szOID_CMC_GET_CRL = "1.3.6.1.5.5.7.7.16"
const szOID_CMC_IDENTIFICATION = "1.3.6.1.5.5.7.7.2"
const szOID_CMC_IDENTITY_PROOF = "1.3.6.1.5.5.7.7.3"
const szOID_CMC_ID_CONFIRM_CERT_ACCEPTANCE = "1.3.6.1.5.5.7.7.24"
const szOID_CMC_ID_POP_LINK_RANDOM = "1.3.6.1.5.5.7.7.22"
const szOID_CMC_ID_POP_LINK_WITNESS = "1.3.6.1.5.5.7.7.23"
const szOID_CMC_LRA_POP_WITNESS = "1.3.6.1.5.5.7.7.11"
const szOID_CMC_QUERY_PENDING = "1.3.6.1.5.5.7.7.21"
const szOID_CMC_RECIPIENT_NONCE = "1.3.6.1.5.5.7.7.7"
const szOID_CMC_REG_INFO = "1.3.6.1.5.5.7.7.18"
const szOID_CMC_RESPONSE_INFO = "1.3.6.1.5.5.7.7.19"
const szOID_CMC_REVOKE_REQUEST = "1.3.6.1.5.5.7.7.17"
const szOID_CMC_SENDER_NONCE = "1.3.6.1.5.5.7.7.6"
const szOID_CMC_STATUS_INFO = "1.3.6.1.5.5.7.7.1"
const szOID_CMC_TRANSACTION_ID = "1.3.6.1.5.5.7.7.5"
const szOID_CN_ECDSA_SHA256 = "1.2.156.11235.1.1.1"
const szOID_COMMON_NAME = "2.5.4.3"
const szOID_COUNTRY_NAME = "2.5.4.6"
const szOID_CRL_DIST_POINTS = "2.5.29.31"
const szOID_CRL_NEXT_PUBLISH = "1.3.6.1.4.1.311.21.4"
const szOID_CRL_NUMBER = "2.5.29.20"
const szOID_CRL_REASON_CODE = "2.5.29.21"
const szOID_CRL_SELF_CDP = "1.3.6.1.4.1.311.21.14"
const szOID_CRL_VIRTUAL_BASE = "1.3.6.1.4.1.311.21.3"
const szOID_CROSS_CERTIFICATE_PAIR = "2.5.4.40"
const szOID_CROSS_CERT_DIST_POINTS = "1.3.6.1.4.1.311.10.9.1"
const szOID_CTL = "1.3.6.1.4.1.311.10.1"
const szOID_CT_CERT_SCTLIST = "1.3.6.1.4.1.11129.2.4.2"
const szOID_CT_PKI_DATA = "1.3.6.1.5.5.7.12.2"
const szOID_CT_PKI_RESPONSE = "1.3.6.1.5.5.7.12.3"
const szOID_DELTA_CRL_INDICATOR = "2.5.29.27"
const szOID_DESCRIPTION = "2.5.4.13"
const szOID_DESTINATION_INDICATOR = "2.5.4.27"
const szOID_DEVICE_SERIAL_NUMBER = "2.5.4.5"
const szOID_DH_SINGLE_PASS_STDDH_SHA1_KDF = "1.3.133.16.840.63.0.2"
const szOID_DH_SINGLE_PASS_STDDH_SHA256_KDF = "1.3.132.1.11.1"
const szOID_DH_SINGLE_PASS_STDDH_SHA384_KDF = "1.3.132.1.11.2"
const szOID_DISALLOWED_HASH = "szOID_CERT_SIGNATURE_HASH_PROP_ID"
const szOID_DISALLOWED_LIST = "1.3.6.1.4.1.311.10.3.30"
const szOID_DN_QUALIFIER = "2.5.4.46"
const szOID_DOMAIN_COMPONENT = "0.9.2342.19200300.100.1.25"
const szOID_DRM = "1.3.6.1.4.1.311.10.5.1"
const szOID_DRM_INDIVIDUALIZATION = "1.3.6.1.4.1.311.10.5.2"
const szOID_DS = "2.5"
const szOID_DSALG = "2.5.8"
const szOID_DSALG_CRPT = "2.5.8.1"
const szOID_DSALG_HASH = "2.5.8.2"
const szOID_DSALG_RSA = "2.5.8.1.1"
const szOID_DSALG_SIGN = "2.5.8.3"
const szOID_DS_EMAIL_REPLICATION = "1.3.6.1.4.1.311.21.19"
const szOID_DYNAMIC_CODE_GEN_SIGNER = "1.3.6.1.4.1.311.76.5.1"
const szOID_ECC_CURVE_BRAINPOOLP160R1 = "1.3.36.3.3.2.8.1.1.1"
const szOID_ECC_CURVE_BRAINPOOLP160T1 = "1.3.36.3.3.2.8.1.1.2"
const szOID_ECC_CURVE_BRAINPOOLP192R1 = "1.3.36.3.3.2.8.1.1.3"
const szOID_ECC_CURVE_BRAINPOOLP192T1 = "1.3.36.3.3.2.8.1.1.4"
const szOID_ECC_CURVE_BRAINPOOLP224R1 = "1.3.36.3.3.2.8.1.1.5"
const szOID_ECC_CURVE_BRAINPOOLP224T1 = "1.3.36.3.3.2.8.1.1.6"
const szOID_ECC_CURVE_BRAINPOOLP256R1 = "1.3.36.3.3.2.8.1.1.7"
const szOID_ECC_CURVE_BRAINPOOLP256T1 = "1.3.36.3.3.2.8.1.1.8"
const szOID_ECC_CURVE_BRAINPOOLP320R1 = "1.3.36.3.3.2.8.1.1.9"
const szOID_ECC_CURVE_BRAINPOOLP320T1 = "1.3.36.3.3.2.8.1.1.10"
const szOID_ECC_CURVE_BRAINPOOLP384R1 = "1.3.36.3.3.2.8.1.1.11"
const szOID_ECC_CURVE_BRAINPOOLP384T1 = "1.3.36.3.3.2.8.1.1.12"
const szOID_ECC_CURVE_BRAINPOOLP512R1 = "1.3.36.3.3.2.8.1.1.13"
const szOID_ECC_CURVE_BRAINPOOLP512T1 = "1.3.36.3.3.2.8.1.1.14"
const szOID_ECC_CURVE_EC192WAPI = "1.2.156.11235.1.1.2.1"
const szOID_ECC_CURVE_NISTP192 = "1.2.840.10045.3.1.1"
const szOID_ECC_CURVE_NISTP224 = "1.3.132.0.33"
const szOID_ECC_CURVE_NISTP256 = "szOID_ECC_CURVE_P256"
const szOID_ECC_CURVE_NISTP384 = "szOID_ECC_CURVE_P384"
const szOID_ECC_CURVE_NISTP521 = "szOID_ECC_CURVE_P521"
const szOID_ECC_CURVE_P256 = "1.2.840.10045.3.1.7"
const szOID_ECC_CURVE_P384 = "1.3.132.0.34"
const szOID_ECC_CURVE_P521 = "1.3.132.0.35"
const szOID_ECC_CURVE_SECP160K1 = "1.3.132.0.9"
const szOID_ECC_CURVE_SECP160R1 = "1.3.132.0.8"
const szOID_ECC_CURVE_SECP160R2 = "1.3.132.0.30"
const szOID_ECC_CURVE_SECP192K1 = "1.3.132.0.31"
const szOID_ECC_CURVE_SECP192R1 = "szOID_ECC_CURVE_NISTP192"
const szOID_ECC_CURVE_SECP224K1 = "1.3.132.0.32"
const szOID_ECC_CURVE_SECP224R1 = "szOID_ECC_CURVE_NISTP224"
const szOID_ECC_CURVE_SECP256K1 = "1.3.132.0.10"
const szOID_ECC_CURVE_SECP256R1 = "szOID_ECC_CURVE_P256"
const szOID_ECC_CURVE_SECP384R1 = "szOID_ECC_CURVE_P384"
const szOID_ECC_CURVE_SECP521R1 = "szOID_ECC_CURVE_P521"
const szOID_ECC_CURVE_WTLS12 = "szOID_ECC_CURVE_NISTP224"
const szOID_ECC_CURVE_WTLS7 = "szOID_ECC_CURVE_SECP160R2"
const szOID_ECC_CURVE_WTLS9 = "2.23.43.1.4.9"
const szOID_ECC_CURVE_X962P192V1 = "1.2.840.10045.3.1.1"
const szOID_ECC_CURVE_X962P192V2 = "1.2.840.10045.3.1.2"
const szOID_ECC_CURVE_X962P192V3 = "1.2.840.10045.3.1.3"
const szOID_ECC_CURVE_X962P239V1 = "1.2.840.10045.3.1.4"
const szOID_ECC_CURVE_X962P239V2 = "1.2.840.10045.3.1.5"
const szOID_ECC_CURVE_X962P239V3 = "1.2.840.10045.3.1.6"
const szOID_ECC_CURVE_X962P256V1 = "szOID_ECC_CURVE_P256"
const szOID_ECC_PUBLIC_KEY = "1.2.840.10045.2.1"
const szOID_ECDSA_SHA1 = "1.2.840.10045.4.1"
const szOID_ECDSA_SHA256 = "1.2.840.10045.4.3.2"
const szOID_ECDSA_SHA384 = "1.2.840.10045.4.3.3"
const szOID_ECDSA_SHA512 = "1.2.840.10045.4.3.4"
const szOID_ECDSA_SPECIFIED = "1.2.840.10045.4.3"
const szOID_EFS_RECOVERY = "1.3.6.1.4.1.311.10.3.4.1"
const szOID_EMBEDDED_NT_CRYPTO = "1.3.6.1.4.1.311.10.3.8"
const szOID_ENCLAVE_SIGNING = "1.3.6.1.4.1.311.10.3.42"
const szOID_ENCRYPTED_KEY_HASH = "1.3.6.1.4.1.311.21.21"
const szOID_ENHANCED_KEY_USAGE = "2.5.29.37"
const szOID_ENROLLMENT_AGENT = "1.3.6.1.4.1.311.20.2.1"
const szOID_ENROLLMENT_CSP_PROVIDER = "1.3.6.1.4.1.311.13.2.2"
const szOID_ENROLLMENT_NAME_VALUE_PAIR = "1.3.6.1.4.1.311.13.2.1"
const szOID_ENROLL_AIK_INFO = "1.3.6.1.4.1.311.21.39"
const szOID_ENROLL_ATTESTATION_CHALLENGE = "1.3.6.1.4.1.311.21.28"
const szOID_ENROLL_ATTESTATION_STATEMENT = "1.3.6.1.4.1.311.21.24"
const szOID_ENROLL_CAXCHGCERT_HASH = "1.3.6.1.4.1.311.21.27"
const szOID_ENROLL_CERTTYPE_EXTENSION = "1.3.6.1.4.1.311.20.2"
const szOID_ENROLL_EKPUB_CHALLENGE = "1.3.6.1.4.1.311.21.26"
const szOID_ENROLL_EKVERIFYCERT = "1.3.6.1.4.1.311.21.31"
const szOID_ENROLL_EKVERIFYCREDS = "1.3.6.1.4.1.311.21.32"
const szOID_ENROLL_EKVERIFYKEY = "1.3.6.1.4.1.311.21.30"
const szOID_ENROLL_EK_CA_KEYID = "1.3.6.1.4.1.311.21.43"
const szOID_ENROLL_EK_INFO = "1.3.6.1.4.1.311.21.23"
const szOID_ENROLL_ENCRYPTION_ALGORITHM = "1.3.6.1.4.1.311.21.29"
const szOID_ENROLL_KEY_AFFINITY = "1.3.6.1.4.1.311.21.41"
const szOID_ENROLL_KSP_NAME = "1.3.6.1.4.1.311.21.25"
const szOID_ENROLL_SCEP_CHALLENGE_ANSWER = "1.3.6.1.4.1.311.21.35"
const szOID_ENROLL_SCEP_CLIENT_REQUEST = "1.3.6.1.4.1.311.21.37"
const szOID_ENROLL_SCEP_ERROR = "1.3.6.1.4.1.311.21.33"
const szOID_ENROLL_SCEP_SERVER_MESSAGE = "1.3.6.1.4.1.311.21.38"
const szOID_ENROLL_SCEP_SERVER_SECRET = "1.3.6.1.4.1.311.21.40"
const szOID_ENROLL_SCEP_SERVER_STATE = "1.3.6.1.4.1.311.21.34"
const szOID_ENROLL_SCEP_SIGNER_HASH = "1.3.6.1.4.1.311.21.42"
const szOID_ENTERPRISE_OID_ROOT = "1.3.6.1.4.1.311.21.8"
const szOID_EV_RDN_COUNTRY = "1.3.6.1.4.1.311.60.2.1.3"
const szOID_EV_RDN_LOCALE = "1.3.6.1.4.1.311.60.2.1.1"
const szOID_EV_RDN_STATE_OR_PROVINCE = "1.3.6.1.4.1.311.60.2.1.2"
const szOID_EV_WHQL_CRYPTO = "1.3.6.1.4.1.311.10.3.39"
const szOID_FACSIMILE_TELEPHONE_NUMBER = "2.5.4.23"
const szOID_FRESHEST_CRL = "2.5.29.46"
const szOID_GIVEN_NAME = "2.5.4.42"
const szOID_HPKP_DOMAIN_NAME_CTL = "1.3.6.1.4.1.311.10.3.60"
const szOID_HPKP_HEADER_VALUE_CTL = "1.3.6.1.4.1.311.10.3.61"
const szOID_INFOSEC = "2.16.840.1.101.2.1"
const szOID_INFOSEC_SuiteAConfidentiality = "2.16.840.1.101.2.1.1.14"
const szOID_INFOSEC_SuiteAIntegrity = "2.16.840.1.101.2.1.1.15"
const szOID_INFOSEC_SuiteAKMandSig = "2.16.840.1.101.2.1.1.18"
const szOID_INFOSEC_SuiteAKeyManagement = "2.16.840.1.101.2.1.1.17"
const szOID_INFOSEC_SuiteASignature = "2.16.840.1.101.2.1.1.13"
const szOID_INFOSEC_SuiteATokenProtection = "2.16.840.1.101.2.1.1.16"
const szOID_INFOSEC_mosaicConfidentiality = "2.16.840.1.101.2.1.1.4"
const szOID_INFOSEC_mosaicIntegrity = "2.16.840.1.101.2.1.1.6"
const szOID_INFOSEC_mosaicKMandSig = "2.16.840.1.101.2.1.1.12"
const szOID_INFOSEC_mosaicKMandUpdSig = "2.16.840.1.101.2.1.1.20"
const szOID_INFOSEC_mosaicKeyManagement = "2.16.840.1.101.2.1.1.10"
const szOID_INFOSEC_mosaicSignature = "2.16.840.1.101.2.1.1.2"
const szOID_INFOSEC_mosaicTokenProtection = "2.16.840.1.101.2.1.1.8"
const szOID_INFOSEC_mosaicUpdatedInteg = "2.16.840.1.101.2.1.1.21"
const szOID_INFOSEC_mosaicUpdatedSig = "2.16.840.1.101.2.1.1.19"
const szOID_INFOSEC_sdnsConfidentiality = "2.16.840.1.101.2.1.1.3"
const szOID_INFOSEC_sdnsIntegrity = "2.16.840.1.101.2.1.1.5"
const szOID_INFOSEC_sdnsKMandSig = "2.16.840.1.101.2.1.1.11"
const szOID_INFOSEC_sdnsKeyManagement = "2.16.840.1.101.2.1.1.9"
const szOID_INFOSEC_sdnsSignature = "2.16.840.1.101.2.1.1.1"
const szOID_INFOSEC_sdnsTokenProtection = "2.16.840.1.101.2.1.1.7"
const szOID_INHIBIT_ANY_POLICY = "2.5.29.54"
const szOID_INITIALS = "2.5.4.43"
const szOID_INTERNATIONALIZED_EMAIL_ADDRESS = "1.3.6.1.4.1.311.20.2.4"
const szOID_INTERNATIONAL_ISDN_NUMBER = "2.5.4.25"
const szOID_IPSEC_KP_IKE_INTERMEDIATE = "1.3.6.1.5.5.8.2.2"
const szOID_ISSUED_CERT_HASH = "1.3.6.1.4.1.311.21.17"
const szOID_ISSUER_ALT_NAME = "2.5.29.8"
const szOID_ISSUER_ALT_NAME2 = "2.5.29.18"
const szOID_ISSUING_DIST_POINT = "2.5.29.28"
const szOID_IUM_SIGNING = "1.3.6.1.4.1.311.10.3.37"
const szOID_KEYID_RDN = "1.3.6.1.4.1.311.10.7.1"
const szOID_KEY_ATTRIBUTES = "2.5.29.2"
const szOID_KEY_USAGE = "2.5.29.15"
const szOID_KEY_USAGE_RESTRICTION = "2.5.29.4"
const szOID_KP_CA_EXCHANGE = "1.3.6.1.4.1.311.21.5"
const szOID_KP_CSP_SIGNATURE = "1.3.6.1.4.1.311.10.3.16"
const szOID_KP_CTL_USAGE_SIGNING = "1.3.6.1.4.1.311.10.3.1"
const szOID_KP_DOCUMENT_SIGNING = "1.3.6.1.4.1.311.10.3.12"
const szOID_KP_EFS = "1.3.6.1.4.1.311.10.3.4"
const szOID_KP_FLIGHT_SIGNING = "1.3.6.1.4.1.311.10.3.27"
const szOID_KP_KERNEL_MODE_CODE_SIGNING = "1.3.6.1.4.1.311.61.1.1"
const szOID_KP_KERNEL_MODE_HAL_EXTENSION_SIGNING = "1.3.6.1.4.1.311.61.5.1"
const szOID_KP_KERNEL_MODE_TRUSTED_BOOT_SIGNING = "1.3.6.1.4.1.311.61.4.1"
const szOID_KP_KEY_RECOVERY = "1.3.6.1.4.1.311.10.3.11"
const szOID_KP_KEY_RECOVERY_AGENT = "1.3.6.1.4.1.311.21.6"
const szOID_KP_LIFETIME_SIGNING = "1.3.6.1.4.1.311.10.3.13"
const szOID_KP_MOBILE_DEVICE_SOFTWARE = "1.3.6.1.4.1.311.10.3.14"
const szOID_KP_QUALIFIED_SUBORDINATION = "1.3.6.1.4.1.311.10.3.10"
const szOID_KP_SMARTCARD_LOGON = "1.3.6.1.4.1.311.20.2.2"
const szOID_KP_SMART_DISPLAY = "1.3.6.1.4.1.311.10.3.15"
const szOID_KP_TIME_STAMP_SIGNING = "1.3.6.1.4.1.311.10.3.2"
const szOID_KP_TPM_AIK_CERTIFICATE = "2.23.133.8.3"
const szOID_KP_TPM_EK_CERTIFICATE = "2.23.133.8.1"
const szOID_KP_TPM_PLATFORM_CERTIFICATE = "2.23.133.8.2"
const szOID_LEGACY_POLICY_MAPPINGS = "2.5.29.5"
const szOID_LICENSES = "1.3.6.1.4.1.311.10.6.1"
const szOID_LICENSE_SERVER = "1.3.6.1.4.1.311.10.6.2"
const szOID_LOCALITY_NAME = "2.5.4.7"
const szOID_LOCAL_MACHINE_KEYSET = "1.3.6.1.4.1.311.17.2"
const szOID_LOGOTYPE_EXT = "1.3.6.1.5.5.7.1.12"
const szOID_LOYALTY_OTHER_LOGOTYPE = "1.3.6.1.5.5.7.20.1"
const szOID_MEMBER = "2.5.4.31"
const szOID_MICROSOFT_PUBLISHER_SIGNER = "1.3.6.1.4.1.311.76.8.1"
const szOID_NAME_CONSTRAINTS = "2.5.29.30"
const szOID_NETSCAPE = "2.16.840.1.113730"
const szOID_NETSCAPE_BASE_URL = "2.16.840.1.113730.1.2"
const szOID_NETSCAPE_CA_POLICY_URL = "2.16.840.1.113730.1.8"
const szOID_NETSCAPE_CA_REVOCATION_URL = "2.16.840.1.113730.1.4"
const szOID_NETSCAPE_CERT_EXTENSION = "2.16.840.1.113730.1"
const szOID_NETSCAPE_CERT_RENEWAL_URL = "2.16.840.1.113730.1.7"
const szOID_NETSCAPE_CERT_SEQUENCE = "2.16.840.1.113730.2.5"
const szOID_NETSCAPE_CERT_TYPE = "2.16.840.1.113730.1.1"
const szOID_NETSCAPE_COMMENT = "2.16.840.1.113730.1.13"
const szOID_NETSCAPE_DATA_TYPE = "2.16.840.1.113730.2"
const szOID_NETSCAPE_REVOCATION_URL = "2.16.840.1.113730.1.3"
const szOID_NETSCAPE_SSL_SERVER_NAME = "2.16.840.1.113730.1.12"
const szOID_NEXT_UPDATE_LOCATION = "1.3.6.1.4.1.311.10.2"
const szOID_NIST_AES128_CBC = "2.16.840.1.101.3.4.1.2"
const szOID_NIST_AES128_WRAP = "2.16.840.1.101.3.4.1.5"
const szOID_NIST_AES192_CBC = "2.16.840.1.101.3.4.1.22"
const szOID_NIST_AES192_WRAP = "2.16.840.1.101.3.4.1.25"
const szOID_NIST_AES256_CBC = "2.16.840.1.101.3.4.1.42"
const szOID_NIST_AES256_WRAP = "2.16.840.1.101.3.4.1.45"
const szOID_NIST_sha256 = "2.16.840.1.101.3.4.2.1"
const szOID_NIST_sha384 = "2.16.840.1.101.3.4.2.2"
const szOID_NIST_sha512 = "2.16.840.1.101.3.4.2.3"
const szOID_NT5_CRYPTO = "1.3.6.1.4.1.311.10.3.6"
const szOID_NTDS_REPLICATION = "1.3.6.1.4.1.311.25.1"
const szOID_NT_PRINCIPAL_NAME = "1.3.6.1.4.1.311.20.2.3"
const szOID_OEM_WHQL_CRYPTO = "1.3.6.1.4.1.311.10.3.7"
const szOID_OIW = "1.3.14"
const szOID_OIWDIR = "1.3.14.7.2"
const szOID_OIWDIR_CRPT = "1.3.14.7.2.1"
const szOID_OIWDIR_HASH = "1.3.14.7.2.2"
const szOID_OIWDIR_SIGN = "1.3.14.7.2.3"
const szOID_OIWDIR_md2 = "1.3.14.7.2.2.1"
const szOID_OIWDIR_md2RSA = "1.3.14.7.2.3.1"
const szOID_OIWSEC = "1.3.14.3.2"
const szOID_OIWSEC_desCBC = "1.3.14.3.2.7"
const szOID_OIWSEC_desCFB = "1.3.14.3.2.9"
const szOID_OIWSEC_desECB = "1.3.14.3.2.6"
const szOID_OIWSEC_desEDE = "1.3.14.3.2.17"
const szOID_OIWSEC_desMAC = "1.3.14.3.2.10"
const szOID_OIWSEC_desOFB = "1.3.14.3.2.8"
const szOID_OIWSEC_dhCommMod = "1.3.14.3.2.16"
const szOID_OIWSEC_dsa = "1.3.14.3.2.12"
const szOID_OIWSEC_dsaComm = "1.3.14.3.2.20"
const szOID_OIWSEC_dsaCommSHA = "1.3.14.3.2.21"
const szOID_OIWSEC_dsaCommSHA1 = "1.3.14.3.2.28"
const szOID_OIWSEC_dsaSHA1 = "1.3.14.3.2.27"
const szOID_OIWSEC_keyHashSeal = "1.3.14.3.2.23"
const szOID_OIWSEC_md2RSASign = "1.3.14.3.2.24"
const szOID_OIWSEC_md4RSA = "1.3.14.3.2.2"
const szOID_OIWSEC_md4RSA2 = "1.3.14.3.2.4"
const szOID_OIWSEC_md5RSA = "1.3.14.3.2.3"
const szOID_OIWSEC_md5RSASign = "1.3.14.3.2.25"
const szOID_OIWSEC_mdc2 = "1.3.14.3.2.19"
const szOID_OIWSEC_mdc2RSA = "1.3.14.3.2.14"
const szOID_OIWSEC_rsaSign = "1.3.14.3.2.11"
const szOID_OIWSEC_rsaXchg = "1.3.14.3.2.22"
const szOID_OIWSEC_sha = "1.3.14.3.2.18"
const szOID_OIWSEC_sha1 = "1.3.14.3.2.26"
const szOID_OIWSEC_sha1RSASign = "1.3.14.3.2.29"
const szOID_OIWSEC_shaDSA = "1.3.14.3.2.13"
const szOID_OIWSEC_shaRSA = "1.3.14.3.2.15"
const szOID_ORGANIZATIONAL_UNIT_NAME = "2.5.4.11"
const szOID_ORGANIZATION_NAME = "2.5.4.10"
const szOID_OS_VERSION = "1.3.6.1.4.1.311.13.2.3"
const szOID_OWNER = "2.5.4.32"
const szOID_PHYSICAL_DELIVERY_OFFICE_NAME = "2.5.4.19"
const szOID_PIN_RULES_CTL = "1.3.6.1.4.1.311.10.3.32"
const szOID_PIN_RULES_DOMAIN_NAME = "1.3.6.1.4.1.311.10.3.34"
const szOID_PIN_RULES_EXT = "1.3.6.1.4.1.311.10.3.33"
const szOID_PIN_RULES_LOG_END_DATE_EXT = "1.3.6.1.4.1.311.10.3.35"
const szOID_PIN_RULES_SIGNER = "1.3.6.1.4.1.311.10.3.31"
const szOID_PKCS = "1.2.840.113549.1"
const szOID_PKCS_1 = "1.2.840.113549.1.1"
const szOID_PKCS_10 = "1.2.840.113549.1.10"
const szOID_PKCS_12 = "1.2.840.113549.1.12"
const szOID_PKCS_12_EXTENDED_ATTRIBUTES = "1.3.6.1.4.1.311.17.3"
const szOID_PKCS_12_FRIENDLY_NAME_ATTR = "1.2.840.113549.1.9.20"
const szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR = "1.3.6.1.4.1.311.17.1"
const szOID_PKCS_12_LOCAL_KEY_ID = "1.2.840.113549.1.9.21"
const szOID_PKCS_12_PROTECTED_PASSWORD_SECRET_BAG_TYPE_ID = "1.3.6.1.4.1.311.17.4"
const szOID_PKCS_12_PbeIds = "1.2.840.113549.1.12.1"
const szOID_PKCS_12_pbeWithSHA1And128BitRC2 = "1.2.840.113549.1.12.1.5"
const szOID_PKCS_12_pbeWithSHA1And128BitRC4 = "1.2.840.113549.1.12.1.1"
const szOID_PKCS_12_pbeWithSHA1And2KeyTripleDES = "1.2.840.113549.1.12.1.4"
const szOID_PKCS_12_pbeWithSHA1And3KeyTripleDES = "1.2.840.113549.1.12.1.3"
const szOID_PKCS_12_pbeWithSHA1And40BitRC2 = "1.2.840.113549.1.12.1.6"
const szOID_PKCS_12_pbeWithSHA1And40BitRC4 = "1.2.840.113549.1.12.1.2"
const szOID_PKCS_2 = "1.2.840.113549.1.2"
const szOID_PKCS_3 = "1.2.840.113549.1.3"
const szOID_PKCS_4 = "1.2.840.113549.1.4"
const szOID_PKCS_5 = "1.2.840.113549.1.5"
const szOID_PKCS_5_PBES2 = "1.2.840.113549.1.5.13"
const szOID_PKCS_5_PBKDF2 = "1.2.840.113549.1.5.12"
const szOID_PKCS_6 = "1.2.840.113549.1.6"
const szOID_PKCS_7 = "1.2.840.113549.1.7"
const szOID_PKCS_7_DATA = "1.2.840.113549.1.7.1"
const szOID_PKCS_7_DIGESTED = "1.2.840.113549.1.7.5"
const szOID_PKCS_7_ENCRYPTED = "1.2.840.113549.1.7.6"
const szOID_PKCS_7_ENVELOPED = "1.2.840.113549.1.7.3"
const szOID_PKCS_7_SIGNED = "1.2.840.113549.1.7.2"
const szOID_PKCS_7_SIGNEDANDENVELOPED = "1.2.840.113549.1.7.4"
const szOID_PKCS_8 = "1.2.840.113549.1.8"
const szOID_PKCS_9 = "1.2.840.113549.1.9"
const szOID_PKCS_9_CONTENT_TYPE = "1.2.840.113549.1.9.3"
const szOID_PKCS_9_MESSAGE_DIGEST = "1.2.840.113549.1.9.4"
const szOID_PKINIT_KP_KDC = "1.3.6.1.5.2.3.5"
const szOID_PKIX = "1.3.6.1.5.5.7"
const szOID_PKIX_ACC_DESCR = "1.3.6.1.5.5.7.48"
const szOID_PKIX_CA_ISSUERS = "1.3.6.1.5.5.7.48.2"
const szOID_PKIX_CA_REPOSITORY = "1.3.6.1.5.5.7.48.5"
const szOID_PKIX_KP = "1.3.6.1.5.5.7.3"
const szOID_PKIX_KP_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2"
const szOID_PKIX_KP_CODE_SIGNING = "1.3.6.1.5.5.7.3.3"
const szOID_PKIX_KP_EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4"
const szOID_PKIX_KP_IPSEC_END_SYSTEM = "1.3.6.1.5.5.7.3.5"
const szOID_PKIX_KP_IPSEC_TUNNEL = "1.3.6.1.5.5.7.3.6"
const szOID_PKIX_KP_IPSEC_USER = "1.3.6.1.5.5.7.3.7"
const szOID_PKIX_KP_OCSP_SIGNING = "1.3.6.1.5.5.7.3.9"
const szOID_PKIX_KP_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"
const szOID_PKIX_KP_TIMESTAMP_SIGNING = "1.3.6.1.5.5.7.3.8"
const szOID_PKIX_NO_SIGNATURE = "1.3.6.1.5.5.7.6.2"
const szOID_PKIX_OCSP = "1.3.6.1.5.5.7.48.1"
const szOID_PKIX_OCSP_BASIC_SIGNED_RESPONSE = "1.3.6.1.5.5.7.48.1.1"
const szOID_PKIX_OCSP_NOCHECK = "1.3.6.1.5.5.7.48.1.5"
const szOID_PKIX_OCSP_NONCE = "1.3.6.1.5.5.7.48.1.2"
const szOID_PKIX_PE = "1.3.6.1.5.5.7.1"
const szOID_PKIX_POLICY_QUALIFIER_CPS = "1.3.6.1.5.5.7.2.1"
const szOID_PKIX_POLICY_QUALIFIER_USERNOTICE = "1.3.6.1.5.5.7.2.2"
const szOID_PKIX_TIME_STAMPING = "1.3.6.1.5.5.7.48.3"
const szOID_PLATFORM_MANIFEST_BINARY_ID = "1.3.6.1.4.1.311.10.3.28"
const szOID_POLICY_CONSTRAINTS = "2.5.29.36"
const szOID_POLICY_MAPPINGS = "2.5.29.33"
const szOID_POSTAL_ADDRESS = "2.5.4.16"
const szOID_POSTAL_CODE = "2.5.4.17"
const szOID_POST_OFFICE_BOX = "2.5.4.18"
const szOID_PREFERRED_DELIVERY_METHOD = "2.5.4.28"
const szOID_PRESENTATION_ADDRESS = "2.5.4.29"
const szOID_PRIVATEKEY_USAGE_PERIOD = "2.5.29.16"
const szOID_PRODUCT_UPDATE = "1.3.6.1.4.1.311.31.1"
const szOID_PROTECTED_PROCESS_LIGHT_SIGNER = "1.3.6.1.4.1.311.10.3.22"
const szOID_PROTECTED_PROCESS_SIGNER = "1.3.6.1.4.1.311.10.3.24"
const szOID_QC_EU_COMPLIANCE = "0.4.0.1862.1.1"
const szOID_QC_SSCD = "0.4.0.1862.1.4"
const szOID_QC_STATEMENTS_EXT = "1.3.6.1.5.5.7.1.3"
const szOID_RDN_DUMMY_SIGNER = "1.3.6.1.4.1.311.21.9"
const szOID_RDN_TCG_PLATFORM_MANUFACTURER = "2.23.133.2.4"
const szOID_RDN_TCG_PLATFORM_MODEL = "2.23.133.2.5"
const szOID_RDN_TCG_PLATFORM_VERSION = "2.23.133.2.6"
const szOID_RDN_TPM_MANUFACTURER = "2.23.133.2.1"
const szOID_RDN_TPM_MODEL = "2.23.133.2.2"
const szOID_RDN_TPM_VERSION = "2.23.133.2.3"
const szOID_REASON_CODE_HOLD = "2.5.29.23"
const szOID_REGISTERED_ADDRESS = "2.5.4.26"
const szOID_REMOVE_CERTIFICATE = "1.3.6.1.4.1.311.10.8.1"
const szOID_RENEWAL_CERTIFICATE = "1.3.6.1.4.1.311.13.1"
const szOID_REQUEST_CLIENT_INFO = "1.3.6.1.4.1.311.21.20"
const szOID_REQUIRE_CERT_CHAIN_POLICY = "1.3.6.1.4.1.311.21.15"
const szOID_REVOKED_LIST_SIGNER = "1.3.6.1.4.1.311.10.3.19"
const szOID_RFC3161_counterSign = "1.3.6.1.4.1.311.3.3.1"
const szOID_ROLE_OCCUPANT = "2.5.4.33"
const szOID_ROOT_LIST_SIGNER = "1.3.6.1.4.1.311.10.3.9"
const szOID_ROOT_PROGRAM_AUTO_UPDATE_CA_REVOCATION = "1.3.6.1.4.1.311.60.3.1"
const szOID_ROOT_PROGRAM_AUTO_UPDATE_END_REVOCATION = "1.3.6.1.4.1.311.60.3.2"
const szOID_ROOT_PROGRAM_FLAGS = "1.3.6.1.4.1.311.60.1.1"
const szOID_ROOT_PROGRAM_NO_OCSP_FAILOVER_TO_CRL = "1.3.6.1.4.1.311.60.3.3"
const szOID_RSA = "1.2.840.113549"
const szOID_RSAES_OAEP = "1.2.840.113549.1.1.7"
const szOID_RSA_DES_EDE3_CBC = "1.2.840.113549.3.7"
const szOID_RSA_DH = "1.2.840.113549.1.3.1"
const szOID_RSA_ENCRYPT = "1.2.840.113549.3"
const szOID_RSA_HASH = "1.2.840.113549.2"
const szOID_RSA_MD2 = "1.2.840.113549.2.2"
const szOID_RSA_MD2RSA = "1.2.840.113549.1.1.2"
const szOID_RSA_MD4 = "1.2.840.113549.2.4"
const szOID_RSA_MD4RSA = "1.2.840.113549.1.1.3"
const szOID_RSA_MD5 = "1.2.840.113549.2.5"
const szOID_RSA_MD5RSA = "1.2.840.113549.1.1.4"
const szOID_RSA_MGF1 = "1.2.840.113549.1.1.8"
const szOID_RSA_PSPECIFIED = "1.2.840.113549.1.1.9"
const szOID_RSA_RC2CBC = "1.2.840.113549.3.2"
const szOID_RSA_RC4 = "1.2.840.113549.3.4"
const szOID_RSA_RC5_CBCPad = "1.2.840.113549.3.9"
const szOID_RSA_RSA = "1.2.840.113549.1.1.1"
const szOID_RSA_SETOAEP_RSA = "1.2.840.113549.1.1.6"
const szOID_RSA_SHA1RSA = "1.2.840.113549.1.1.5"
const szOID_RSA_SHA256RSA = "1.2.840.113549.1.1.11"
const szOID_RSA_SHA384RSA = "1.2.840.113549.1.1.12"
const szOID_RSA_SHA512RSA = "1.2.840.113549.1.1.13"
const szOID_RSA_SMIMECapabilities = "1.2.840.113549.1.9.15"
const szOID_RSA_SMIMEalg = "1.2.840.113549.1.9.16.3"
const szOID_RSA_SMIMEalgCMS3DESwrap = "1.2.840.113549.1.9.16.3.6"
const szOID_RSA_SMIMEalgCMSRC2wrap = "1.2.840.113549.1.9.16.3.7"
const szOID_RSA_SMIMEalgESDH = "1.2.840.113549.1.9.16.3.5"
const szOID_RSA_SSA_PSS = "1.2.840.113549.1.1.10"
const szOID_RSA_certExtensions = "1.2.840.113549.1.9.14"
const szOID_RSA_challengePwd = "1.2.840.113549.1.9.7"
const szOID_RSA_contentType = "1.2.840.113549.1.9.3"
const szOID_RSA_counterSign = "1.2.840.113549.1.9.6"
const szOID_RSA_data = "1.2.840.113549.1.7.1"
const szOID_RSA_digestedData = "1.2.840.113549.1.7.5"
const szOID_RSA_emailAddr = "1.2.840.113549.1.9.1"
const szOID_RSA_encryptedData = "1.2.840.113549.1.7.6"
const szOID_RSA_envelopedData = "1.2.840.113549.1.7.3"
const szOID_RSA_extCertAttrs = "1.2.840.113549.1.9.9"
const szOID_RSA_hashedData = "1.2.840.113549.1.7.5"
const szOID_RSA_messageDigest = "1.2.840.113549.1.9.4"
const szOID_RSA_preferSignedData = "1.2.840.113549.1.9.15.1"
const szOID_RSA_signEnvData = "1.2.840.113549.1.7.4"
const szOID_RSA_signedData = "1.2.840.113549.1.7.2"
const szOID_RSA_signingTime = "1.2.840.113549.1.9.5"
const szOID_RSA_unstructAddr = "1.2.840.113549.1.9.8"
const szOID_RSA_unstructName = "1.2.840.113549.1.9.2"
const szOID_SEARCH_GUIDE = "2.5.4.14"
const szOID_SEE_ALSO = "2.5.4.34"
const szOID_SERIALIZED = "1.3.6.1.4.1.311.10.3.3.1"
const szOID_SERVER_GATED_CRYPTO = "1.3.6.1.4.1.311.10.3.3"
const szOID_SGC_NETSCAPE = "2.16.840.1.113730.4.1"
const szOID_SITE_PIN_RULES_FLAGS_ATTR = "1.3.6.1.4.1.311.10.4.3"
const szOID_SITE_PIN_RULES_INDEX_ATTR = "1.3.6.1.4.1.311.10.4.2"
const szOID_SORTED_CTL = "1.3.6.1.4.1.311.10.1.1"
const szOID_STATE_OR_PROVINCE_NAME = "2.5.4.8"
const szOID_STREET_ADDRESS = "2.5.4.9"
const szOID_SUBJECT_ALT_NAME = "2.5.29.7"
const szOID_SUBJECT_ALT_NAME2 = "2.5.29.17"
const szOID_SUBJECT_DIR_ATTRS = "2.5.29.9"
const szOID_SUBJECT_INFO_ACCESS = "1.3.6.1.5.5.7.1.11"
const szOID_SUBJECT_KEY_IDENTIFIER = "2.5.29.14"
const szOID_SUPPORTED_APPLICATION_CONTEXT = "2.5.4.30"
const szOID_SUR_NAME = "2.5.4.4"
const szOID_SYNC_ROOT_CTL_EXT = "1.3.6.1.4.1.311.10.3.50"
const szOID_TELEPHONE_NUMBER = "2.5.4.20"
const szOID_TELETEXT_TERMINAL_IDENTIFIER = "2.5.4.22"
const szOID_TELEX_NUMBER = "2.5.4.21"
const szOID_TIMESTAMP_TOKEN = "1.2.840.113549.1.9.16.1.4"
const szOID_TITLE = "2.5.4.12"
const szOID_TLS_FEATURES_EXT = "1.3.6.1.5.5.7.1.24"
const szOID_USER_CERTIFICATE = "2.5.4.36"
const szOID_USER_PASSWORD = "2.5.4.35"
const szOID_VERISIGN_BITSTRING_6_13 = "2.16.840.1.113733.1.6.13"
const szOID_VERISIGN_ISS_STRONG_CRYPTO = "2.16.840.1.113733.1.8.1"
const szOID_VERISIGN_ONSITE_JURISDICTION_HASH = "2.16.840.1.113733.1.6.11"
const szOID_VERISIGN_PRIVATE_6_9 = "2.16.840.1.113733.1.6.9"
const szOID_WHQL_CRYPTO = "1.3.6.1.4.1.311.10.3.5"
const szOID_WINDOWS_KITS_SIGNER = "1.3.6.1.4.1.311.10.3.20"
const szOID_WINDOWS_RT_SIGNER = "1.3.6.1.4.1.311.10.3.21"
const szOID_WINDOWS_SOFTWARE_EXTENSION_SIGNER = "1.3.6.1.4.1.311.10.3.26"
const szOID_WINDOWS_STORE_SIGNER = "1.3.6.1.4.1.311.76.3.1"
const szOID_WINDOWS_TCB_SIGNER = "1.3.6.1.4.1.311.10.3.23"
const szOID_WINDOWS_THIRD_PARTY_COMPONENT_SIGNER = "1.3.6.1.4.1.311.10.3.25"
const szOID_X21_ADDRESS = "2.5.4.24"
const szOID_X957 = "1.2.840.10040"
const szOID_X957_DSA = "1.2.840.10040.4.1"
const szOID_X957_SHA1DSA = "1.2.840.10040.4.3"
const szOID_YESNO_TRUST_ATTR = "1.3.6.1.4.1.311.10.4.1"
const szPRIV_KEY_CACHE_MAX_ITEMS = "PrivKeyCacheMaxItems"
const szPRIV_KEY_CACHE_PURGE_INTERVAL_SECONDS = "PrivKeyCachePurgeIntervalSeconds"
const sz_CERT_STORE_PROV_COLLECTION = "Collection"
const sz_CERT_STORE_PROV_FILENAME = "sz_CERT_STORE_PROV_FILENAME_W"
const sz_CERT_STORE_PROV_FILENAME_W = "File"
const sz_CERT_STORE_PROV_LDAP = "sz_CERT_STORE_PROV_LDAP_W"
const sz_CERT_STORE_PROV_LDAP_W = "Ldap"
const sz_CERT_STORE_PROV_MEMORY = "Memory"
const sz_CERT_STORE_PROV_PHYSICAL = "sz_CERT_STORE_PROV_PHYSICAL_W"
const sz_CERT_STORE_PROV_PHYSICAL_W = "Physical"
const sz_CERT_STORE_PROV_PKCS12 = "PKCS12"
const sz_CERT_STORE_PROV_PKCS7 = "PKCS7"
const sz_CERT_STORE_PROV_SERIALIZED = "Serialized"
const sz_CERT_STORE_PROV_SMART_CARD = "sz_CERT_STORE_PROV_SMART_CARD_W"
const sz_CERT_STORE_PROV_SMART_CARD_W = "SmartCard"
const sz_CERT_STORE_PROV_SYSTEM = "sz_CERT_STORE_PROV_SYSTEM_W"
const sz_CERT_STORE_PROV_SYSTEM_REGISTRY = "sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W"
const sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W = "SystemRegistry"
const sz_CERT_STORE_PROV_SYSTEM_W = "System"
const tkCREATE = 4
const tkEND = 7
const tkEXPLAIN = 3
const tkOTHER = 2
const tkSEMI = 0
const tkTEMP = 5
const tkTRIGGER = 6
const tkWS = 1
const toascii = 0
const ua_CharUpper = 0
const ua_CharUpperW = 0
const ua_lstrcmp = 0
const ua_lstrcmpW = 0
const ua_lstrcmpi = 0
const ua_lstrcmpiW = 0
const ua_lstrlen = 0
const ua_lstrlenW = 0
const ua_tcscpy = 0
const ua_wcschr = 0
const ua_wcscpy = 0
const ua_wcsicmp = 0
const ua_wcslen = 0
const ua_wcsrchr = 0
const uuid_t = 0
const uuid_vector_t = 0
const vfsList = 0
const waveInGetDevCaps = 0
const waveInGetErrorText = 0
const waveOutGetDevCaps = 0
const waveOutGetErrorText = 0
const wcswcs = 0
const wglUseFontBitmaps = 0
const wglUseFontOutlines = 0
const wpopen = 0
const wsdAutoext = 0
const wsdHooks = 0
const wsdPrng = 0
const wsdStat = 0
const wsprintf = 0
const wvsprintf = 0

type t__builtin_va_list = uintptr

type t__predefined_size_t = uint32

type t__predefined_wchar_t = uint16

type t__predefined_ptrdiff_t = int32

type t__gnuc_va_list = uintptr

type Tva_list = uintptr

type va_list = Tva_list

// C documentation
//
//	/*
//	** CAPI3REF: Database Connection Handle
//	** KEYWORDS: {database connection} {database connections}
//	**
//	** Each open SQLite database is represented by a pointer to an instance of
//	** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
//	** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
//	** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
//	** and [sqlite3_close_v2()] are its destructors.  There are many other
//	** interfaces (such as
//	** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
//	** [sqlite3_busy_timeout()] to name but three) that are methods on an
//	** sqlite3 object.
//	*/
type Tsqlite3 = struct {
	F__ccgo_align           [0]uint32
	FpVfs                   uintptr
	FpVdbe                  uintptr
	FpDfltColl              uintptr
	Fmutex                  uintptr
	FaDb                    uintptr
	FnDb                    int32
	FmDbFlags               Tu32
	F__ccgo_align7          [4]byte
	Fflags                  Tu64
	FlastRowid              Ti64
	FszMmap                 Ti64
	FnSchemaLock            Tu32
	FopenFlags              uint32
	FerrCode                int32
	FerrByteOffset          int32
	FerrMask                int32
	FiSysErrno              int32
	FdbOptFlags             Tu32
	Fenc                    Tu8
	FautoCommit             Tu8
	Ftemp_store             Tu8
	FmallocFailed           Tu8
	FbBenignMalloc          Tu8
	FdfltLockMode           Tu8
	FnextAutovac            int8
	FsuppressErr            Tu8
	FvtabOnConflict         Tu8
	FisTransactionSavepoint Tu8
	FmTrace                 Tu8
	FnoSharedCache          Tu8
	FnSqlExec               Tu8
	FeOpenState             Tu8
	FnextPagesize           int32
	FnChange                Ti64
	FnTotalChange           Ti64
	FaLimit                 [12]int32
	FnMaxSorterMmap         int32
	Finit1                  Tsqlite3InitInfo
	FnVdbeActive            int32
	FnVdbeRead              int32
	FnVdbeWrite             int32
	FnVdbeExec              int32
	FnVDestroy              int32
	FnExtension             int32
	FaExtension             uintptr
	Ftrace                  struct {
		FxV2     [0]uintptr
		FxLegacy uintptr
	}
	FpTraceArg          uintptr
	FxProfile           uintptr
	FpProfileArg        uintptr
	FpCommitArg         uintptr
	FxCommitCallback    uintptr
	FpRollbackArg       uintptr
	FxRollbackCallback  uintptr
	FpUpdateArg         uintptr
	FxUpdateCallback    uintptr
	FpAutovacPagesArg   uintptr
	FxAutovacDestr      uintptr
	FxAutovacPages      uintptr
	FpParse             uintptr
	FpPreUpdateArg      uintptr
	FxPreUpdateCallback uintptr
	FpPreUpdate         uintptr
	FxWalCallback       uintptr
	FpWalArg            uintptr
	FxCollNeeded        uintptr
	FxCollNeeded16      uintptr
	FpCollNeededArg     uintptr
	FpErr               uintptr
	F__ccgo_align67     [4]byte
	Fu1                 struct {
		F__ccgo_align  [0]uint32
		FnotUsed1      [0]float64
		FisInterrupted int32
		F__ccgo_pad2   [4]byte
	}
	Flookaside           TLookaside
	FxAuth               Tsqlite3_xauth
	FpAuthArg            uintptr
	FxProgress           uintptr
	FpProgressArg        uintptr
	FnProgressOps        uint32
	FnVTrans             int32
	FaModule             THash
	FpVtabCtx            uintptr
	FaVTrans             uintptr
	FpDisconnect         uintptr
	FaFunc               THash
	FaCollSeq            THash
	FbusyHandler         TBusyHandler
	FaDbStatic           [2]TDb
	FpSavepoint          uintptr
	FnAnalysisLimit      int32
	FbusyTimeout         int32
	FnSavepoint          int32
	FnStatement          int32
	FnDeferredCons       Ti64
	FnDeferredImmCons    Ti64
	FpnBytesFreed        uintptr
	FpDbData             uintptr
	FpBlockingConnection uintptr
	FpUnlockConnection   uintptr
	FpUnlockArg          uintptr
	FxUnlockNotify       uintptr
	FpNextBlocked        uintptr
	F__ccgo_pad97        [4]byte
}

type sqlite3 = Tsqlite3

// C documentation
//
//	/*
//	** CAPI3REF: 64-Bit Integer Types
//	** KEYWORDS: sqlite_int64 sqlite_uint64
//	**
//	** Because there is no cross-platform way to specify 64-bit integer types
//	** SQLite includes typedefs for 64-bit signed and unsigned integers.
//	**
//	** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
//	** The sqlite_int64 and sqlite_uint64 types are supported for backwards
//	** compatibility only.
//	**
//	** ^The sqlite3_int64 and sqlite_int64 types can store integer values
//	** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
//	** sqlite3_uint64 and sqlite_uint64 types can store integer values
//	** between 0 and +18446744073709551615 inclusive.
//	*/
type Tsqlite_int64 = int64

type sqlite_int64 = Tsqlite_int64

type Tsqlite_uint64 = uint64

type sqlite_uint64 = Tsqlite_uint64

type Tsqlite3_int64 = int64

type sqlite3_int64 = Tsqlite3_int64

type Tsqlite3_uint64 = uint64

type sqlite3_uint64 = Tsqlite3_uint64

// C documentation
//
//	/*
//	** The type for a callback function.
//	** This is legacy and deprecated.  It is included for historical
//	** compatibility and is not documented.
//	*/
type Tsqlite3_callback = uintptr

type sqlite3_callback = Tsqlite3_callback

/*
** CAPI3REF: Result Codes
** KEYWORDS: {result code definitions}
**
** Many SQLite functions return an integer result code from the set shown
** here in order to indicate success or failure.
**
** New error codes may be added in future versions of SQLite.
**
** See also: [extended result code definitions]
 */
/* beginning-of-error-codes */
/* end-of-error-codes */

/*
** CAPI3REF: Extended Result Codes
** KEYWORDS: {extended result code definitions}
**
** In its default configuration, SQLite API routines return one of 30 integer
** [result codes].  However, experience has shown that many of
** these result codes are too coarse-grained.  They do not provide as
** much information about problems as programmers might like.  In an effort to
** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
** and later) include
** support for additional result codes that provide more detailed information
** about errors. These [extended result codes] are enabled or disabled
** on a per database connection basis using the
** [sqlite3_extended_result_codes()] API.  Or, the extended code for
** the most recent error can be obtained using
** [sqlite3_extended_errcode()].
 */

/*
** CAPI3REF: Flags For File Open Operations
**
** These bit values are intended for use in the
** 3rd parameter to the [sqlite3_open_v2()] interface and
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
**
** Only those flags marked as "Ok for sqlite3_open_v2()" may be
** used as the third argument to the [sqlite3_open_v2()] interface.
** The other flags have historically been ignored by sqlite3_open_v2(),
** though future versions of SQLite might change so that an error is
** raised if any of the disallowed bits are passed into sqlite3_open_v2().
** Applications should not depend on the historical behavior.
**
** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
** [sqlite3_open_v2()] does *not* cause the underlying database file
** to be opened using O_EXCL.  Passing SQLITE_OPEN_EXCLUSIVE into
** [sqlite3_open_v2()] has historically be a no-op and might become an
** error in future versions of SQLite.
 */

/* Reserved:                         0x00F00000 */
/* Legacy compatibility: */

/*
** CAPI3REF: Device Characteristics
**
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
** object returns an integer which is a vector of these
** bit values expressing I/O characteristics of the mass storage
** device that holds the file that the [sqlite3_io_methods]
** refers to.
**
** The SQLITE_IOCAP_ATOMIC property means that all writes of
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
** mean that writes of blocks that are nnn bytes in size and
** are aligned to an address which is an integer multiple of
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
** that when data is appended to a file, the data is appended
** first then the size of the file is extended, never the other
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
** information is written to disk in the same order as calls
** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
** after reboot following a crash or power loss, the only bytes in a
** file that were written at the application level might have changed
** and that adjacent bytes, even bytes within the same sector are
** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
** flag indicates that a file cannot be deleted when open.  The
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
** read-only media and cannot be changed even by processes with
** elevated privileges.
**
** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
** filesystem supports doing multiple write operations atomically when those
** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
 */

/*
** CAPI3REF: File Locking Levels
**
** SQLite uses one of these integer values as the second
** argument to calls it makes to the xLock() and xUnlock() methods
** of an [sqlite3_io_methods] object.  These values are ordered from
** lest restrictive to most restrictive.
**
** The argument to xLock() is always SHARED or higher.  The argument to
** xUnlock is either SHARED or NONE.
 */

/*
** CAPI3REF: Synchronization Type Flags
**
** When SQLite invokes the xSync() method of an
** [sqlite3_io_methods] object it uses a combination of
** these integer values as the second argument.
**
** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
** sync operation only needs to flush data to mass storage.  Inode
** information need not be flushed. If the lower four bits of the flag
** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
** If the lower four bits equal SQLITE_SYNC_FULL, that means
** to use Mac OS X style fullsync instead of fsync().
**
** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
** settings.  The [synchronous pragma] determines when calls to the
** xSync VFS method occur and applies uniformly across all platforms.
** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
** energetic or rigorous or forceful the sync operations are and
** only make a difference on Mac OSX for the default SQLite code.
** (Third-party VFS implementations might also make the distinction
** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
** operating systems natively supported by SQLite, only Mac OSX
** cares about the difference.)
 */

// C documentation
//
//	/*
//	** CAPI3REF: OS Interface Open File Handle
//	**
//	** An [sqlite3_file] object represents an open file in the
//	** [sqlite3_vfs | OS interface layer].  Individual OS interface
//	** implementations will
//	** want to subclass this object by appending additional fields
//	** for their own use.  The pMethods entry is a pointer to an
//	** [sqlite3_io_methods] object that defines methods for performing
//	** I/O operations on the open file.
//	*/
type Tsqlite3_file = struct {
	FpMethods uintptr
}

type sqlite3_file = Tsqlite3_file

type Tsqlite3_file1 = struct {
	FpMethods uintptr
}

type sqlite3_file1 = Tsqlite3_file1

// C documentation
//
//	/*
//	** CAPI3REF: OS Interface File Virtual Methods Object
//	**
//	** Every file opened by the [sqlite3_vfs.xOpen] method populates an
//	** [sqlite3_file] object (or, more commonly, a subclass of the
//	** [sqlite3_file] object) with a pointer to an instance of this object.
//	** This object defines the methods used to perform various operations
//	** against the open file represented by the [sqlite3_file] object.
//	**
//	** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
//	** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
//	** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed.  The
//	** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
//	** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
//	** to NULL.
//	**
//	** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
//	** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
//	** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
//	** flag may be ORed in to indicate that only the data of the file
//	** and not its inode needs to be synced.
//	**
//	** The integer values to xLock() and xUnlock() are one of
//	** <ul>
//	** <li> [SQLITE_LOCK_NONE],
//	** <li> [SQLITE_LOCK_SHARED],
//	** <li> [SQLITE_LOCK_RESERVED],
//	** <li> [SQLITE_LOCK_PENDING], or
//	** <li> [SQLITE_LOCK_EXCLUSIVE].
//	** </ul>
//	** xLock() upgrades the database file lock.  In other words, xLock() moves the
//	** database file lock in the direction NONE toward EXCLUSIVE. The argument to
//	** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never
//	** SQLITE_LOCK_NONE.  If the database file lock is already at or above the
//	** requested lock, then the call to xLock() is a no-op.
//	** xUnlock() downgrades the database file lock to either SHARED or NONE.
//	** If the lock is already at or below the requested lock state, then the call
//	** to xUnlock() is a no-op.
//	** The xCheckReservedLock() method checks whether any database connection,
//	** either in this process or in some other process, is holding a RESERVED,
//	** PENDING, or EXCLUSIVE lock on the file.  It returns true
//	** if such a lock exists and false otherwise.
//	**
//	** The xFileControl() method is a generic interface that allows custom
//	** VFS implementations to directly control an open file using the
//	** [sqlite3_file_control()] interface.  The second "op" argument is an
//	** integer opcode.  The third argument is a generic pointer intended to
//	** point to a structure that may contain arguments or space in which to
//	** write return values.  Potential uses for xFileControl() might be
//	** functions to enable blocking locks with timeouts, to change the
//	** locking strategy (for example to use dot-file locks), to inquire
//	** about the status of a lock, or to break stale locks.  The SQLite
//	** core reserves all opcodes less than 100 for its own use.
//	** A [file control opcodes | list of opcodes] less than 100 is available.
//	** Applications that define a custom xFileControl method should use opcodes
//	** greater than 100 to avoid conflicts.  VFS implementations should
//	** return [SQLITE_NOTFOUND] for file control opcodes that they do not
//	** recognize.
//	**
//	** The xSectorSize() method returns the sector size of the
//	** device that underlies the file.  The sector size is the
//	** minimum write that can be performed without disturbing
//	** other bytes in the file.  The xDeviceCharacteristics()
//	** method returns a bit vector describing behaviors of the
//	** underlying device:
//	**
//	** <ul>
//	** <li> [SQLITE_IOCAP_ATOMIC]
//	** <li> [SQLITE_IOCAP_ATOMIC512]
//	** <li> [SQLITE_IOCAP_ATOMIC1K]
//	** <li> [SQLITE_IOCAP_ATOMIC2K]
//	** <li> [SQLITE_IOCAP_ATOMIC4K]
//	** <li> [SQLITE_IOCAP_ATOMIC8K]
//	** <li> [SQLITE_IOCAP_ATOMIC16K]
//	** <li> [SQLITE_IOCAP_ATOMIC32K]
//	** <li> [SQLITE_IOCAP_ATOMIC64K]
//	** <li> [SQLITE_IOCAP_SAFE_APPEND]
//	** <li> [SQLITE_IOCAP_SEQUENTIAL]
//	** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
//	** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
//	** <li> [SQLITE_IOCAP_IMMUTABLE]
//	** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
//	** </ul>
//	**
//	** The SQLITE_IOCAP_ATOMIC property means that all writes of
//	** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
//	** mean that writes of blocks that are nnn bytes in size and
//	** are aligned to an address which is an integer multiple of
//	** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
//	** that when data is appended to a file, the data is appended
//	** first then the size of the file is extended, never the other
//	** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
//	** information is written to disk in the same order as calls
//	** to xWrite().
//	**
//	** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
//	** in the unread portions of the buffer with zeros.  A VFS that
//	** fails to zero-fill short reads might seem to work.  However,
//	** failure to zero-fill short reads will eventually lead to
//	** database corruption.
//	*/
type Tsqlite3_io_methods = struct {
	FiVersion               int32
	FxClose                 uintptr
	FxRead                  uintptr
	FxWrite                 uintptr
	FxTruncate              uintptr
	FxSync                  uintptr
	FxFileSize              uintptr
	FxLock                  uintptr
	FxUnlock                uintptr
	FxCheckReservedLock     uintptr
	FxFileControl           uintptr
	FxSectorSize            uintptr
	FxDeviceCharacteristics uintptr
	FxShmMap                uintptr
	FxShmLock               uintptr
	FxShmBarrier            uintptr
	FxShmUnmap              uintptr
	FxFetch                 uintptr
	FxUnfetch               uintptr
}

type sqlite3_io_methods = Tsqlite3_io_methods

type Tsqlite3_io_methods1 = struct {
	FiVersion               int32
	FxClose                 uintptr
	FxRead                  uintptr
	FxWrite                 uintptr
	FxTruncate              uintptr
	FxSync                  uintptr
	FxFileSize              uintptr
	FxLock                  uintptr
	FxUnlock                uintptr
	FxCheckReservedLock     uintptr
	FxFileControl           uintptr
	FxSectorSize            uintptr
	FxDeviceCharacteristics uintptr
	FxShmMap                uintptr
	FxShmLock               uintptr
	FxShmBarrier            uintptr
	FxShmUnmap              uintptr
	FxFetch                 uintptr
	FxUnfetch               uintptr
}

type sqlite3_io_methods1 = Tsqlite3_io_methods1

/*
** CAPI3REF: Standard File Control Opcodes
** KEYWORDS: {file control opcodes} {file control opcode}
**
** These integer constants are opcodes for the xFileControl method
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
** interface.
**
** <ul>
** <li>[[SQLITE_FCNTL_LOCKSTATE]]
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
** opcode causes the xFileControl method to write the current state of
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
** into an integer that the pArg argument points to.
** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].
**
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
** layer a hint of how large the database file will grow to be during the
** current transaction.  This hint is not guaranteed to be accurate but it
** is often close.  The underlying VFS might choose to preallocate database
** file space based on this hint in order to help writes to the database
** file run faster.
**
** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
** implements [sqlite3_deserialize()] to set an upper bound on the size
** of the in-memory database.  The argument is a pointer to a [sqlite3_int64].
** If the integer pointed to is negative, then it is filled in with the
** current limit.  Otherwise the limit is set to the larger of the value
** of the integer pointed to and the current database size.  The integer
** pointed to is set to the new limit.
**
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
** extends and truncates the database file in chunks of a size specified
** by the user. The fourth argument to [sqlite3_file_control()] should
** point to an integer (type int) containing the new chunk-size to use
** for the nominated database. Allocating database file space in large
** chunks (say 1MB at a time), may reduce file-system fragmentation and
** improve performance on some systems.
**
** <li>[[SQLITE_FCNTL_FILE_POINTER]]
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
** to the [sqlite3_file] object associated with a particular database
** connection.  See also [SQLITE_FCNTL_JOURNAL_POINTER].
**
** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
** to the [sqlite3_file] object associated with the journal file (either
** the [rollback journal] or the [write-ahead log]) for a particular database
** connection.  See also [SQLITE_FCNTL_FILE_POINTER].
**
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
** No longer in use.
**
** <li>[[SQLITE_FCNTL_SYNC]]
** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
** sent to the VFS immediately before the xSync method is invoked on a
** database file descriptor. Or, if the xSync method is not invoked
** because the user has configured SQLite with
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
** of the xSync method. In most cases, the pointer argument passed with
** this file-control is NULL. However, if the database file is being synced
** as part of a multi-database commit, the argument points to a nul-terminated
** string containing the transactions super-journal file name. VFSes that
** do not need this signal should silently ignore this opcode. Applications
** should not call [sqlite3_file_control()] with this opcode as doing so may
** disrupt the operation of the specialized VFSes that do require it.
**
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
** and sent to the VFS after a transaction has been committed immediately
** but before the database is unlocked. VFSes that do not need this signal
** should silently ignore this opcode. Applications should not call
** [sqlite3_file_control()] with this opcode as doing so may disrupt the
** operation of the specialized VFSes that do require it.
**
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
** retry counts and intervals for certain disk I/O operations for the
** windows [VFS] in order to provide robustness in the presence of
** anti-virus programs.  By default, the windows VFS will retry file read,
** file write, and file delete operations up to 10 times, with a delay
** of 25 milliseconds before the first retry and with the delay increasing
** by an additional 25 milliseconds with each subsequent retry.  This
** opcode allows these two values (10 retries and 25 milliseconds of delay)
** to be adjusted.  The values are changed for all database connections
** within the same process.  The argument is a pointer to an array of two
** integers where the first integer is the new retry count and the second
** integer is the delay.  If either integer is negative, then the setting
** is not changed but instead the prior value of that setting is written
** into the array entry, allowing the current retry settings to be
** interrogated.  The zDbName parameter is ignored.
**
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
** write ahead log ([WAL file]) and shared memory
** files used for transaction control
** are automatically deleted when the latest connection to the database
** closes.  Setting persistent WAL mode causes those files to persist after
** close.  Persisting the files is useful when other processes that do not
** have write permission on the directory containing the database file want
** to read the database file, as the WAL and shared memory files must exist
** in order for the database to be readable.  The fourth parameter to
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
** WAL mode.  If the integer is -1, then it is overwritten with the current
** WAL persistence setting.
**
** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
** xDeviceCharacteristics methods. The fourth parameter to
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
** mode.  If the integer is -1, then it is overwritten with the current
** zero-damage mode setting.
**
** <li>[[SQLITE_FCNTL_OVERWRITE]]
** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
** a write transaction to indicate that, unless it is rolled back for some
** reason, the entire database file will be overwritten by the current
** transaction. This is used by VACUUM operations.
**
** <li>[[SQLITE_FCNTL_VFSNAME]]
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
** final bottom-level VFS are written into memory obtained from
** [sqlite3_malloc()] and the result is stored in the char* variable
** that the fourth parameter of [sqlite3_file_control()] points to.
** The caller is responsible for freeing the memory when done.  As with
** all file-control actions, there is no guarantee that this will actually
** do anything.  Callers should initialize the char* variable to a NULL
** pointer in case this file-control is not implemented.  This file-control
** is intended for diagnostic use only.
**
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
** [VFSes] currently in use.  ^(The argument X in
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
** of type "[sqlite3_vfs] **".  This opcodes will set *X
** to a pointer to the top-level VFS.)^
** ^When there are multiple VFS shims in the stack, this opcode finds the
** upper-most shim only.
**
** <li>[[SQLITE_FCNTL_PRAGMA]]
** ^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. ^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.  ^The handler for an
** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
** of the char** argument point to a string obtained from [sqlite3_mprintf()]
** or the equivalent and that string will become the result of the pragma or
** the error message if the pragma fails. ^If the
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
** file control returns [SQLITE_OK], then the parser assumes that the
** VFS has handled the PRAGMA itself and the parser generates a no-op
** prepared statement if result string is NULL, or that returns a copy
** of the result string if the string is non-NULL.
** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
** that the VFS encountered an error while handling the [PRAGMA] and the
** compilation of the PRAGMA fails with an error.  ^The [SQLITE_FCNTL_PRAGMA]
** file control occurs at the beginning of pragma statement analysis and so
** it is able to override built-in [PRAGMA] statements.
**
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
** ^The [SQLITE_FCNTL_BUSYHANDLER]
** file-control may be invoked by SQLite on the database file handle
** shortly after it is opened in order to provide a custom VFS with access
** to the connection's busy-handler callback. The argument is of type (void**)
** - an array of two (void *) values. The first (void *) actually points
** to a function of type (int (*)(void *)). In order to invoke the connection's
** busy-handler, this function should be invoked with the second (void *) in
** the array as the only argument. If it returns non-zero, then the operation
** should be retried. If it returns zero, the custom VFS should abandon the
** current operation.
**
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
** to have SQLite generate a
** temporary filename using the same algorithm that is followed to generate
** temporary filenames for TEMP tables and other internal uses.  The
** argument should be a char** which will be filled with the filename
** written into memory obtained from [sqlite3_malloc()].  The caller should
** invoke [sqlite3_free()] on the result to avoid a memory leak.
**
** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
** maximum number of bytes that will be used for memory-mapped I/O.
** The argument is a pointer to a value of type sqlite3_int64 that
** is an advisory maximum number of bytes in the file to memory map.  The
** pointer is overwritten with the old value.  The limit is not changed if
** the value originally pointed to is negative, and so the current limit
** can be queried by passing in a pointer to a negative number.  This
** file-control is used internally to implement [PRAGMA mmap_size].
**
** <li>[[SQLITE_FCNTL_TRACE]]
** The [SQLITE_FCNTL_TRACE] file control provides advisory information
** to the VFS about what the higher layers of the SQLite stack are doing.
** This file control is used by some VFS activity tracing [shims].
** The argument is a zero-terminated string.  Higher layers in the
** SQLite stack may generate instances of this file control if
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
**
** <li>[[SQLITE_FCNTL_HAS_MOVED]]
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
** pointer to an integer and it writes a boolean into that integer depending
** on whether or not the file has been renamed, moved, or deleted since it
** was first opened.
**
** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
** underlying native file handle associated with a file handle.  This file
** control interprets its argument as a pointer to a native file handle and
** writes the resulting value there.
**
** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
** opcode causes the xFileControl method to swap the file handle with the one
** pointed to by the pArg argument.  This capability is used during testing
** and only needs to be supported when SQLITE_TEST is defined.
**
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
** be advantageous to block on the next WAL lock if the lock is not immediately
** available.  The WAL subsystem issues this signal during rare
** circumstances in order to fix a problem with priority inversion.
** Applications should <em>not</em> use this file-control.
**
** <li>[[SQLITE_FCNTL_ZIPVFS]]
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
** VFS should return SQLITE_NOTFOUND for this opcode.
**
** <li>[[SQLITE_FCNTL_RBU]]
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
** this opcode.
**
** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
** the file descriptor is placed in "batch write mode", which
** means all subsequent write operations will be deferred and done
** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].  Systems
** that do not support batch atomic writes will return SQLITE_NOTFOUND.
** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
** no VFS interface calls on the same [sqlite3_file] file descriptor
** except for calls to the xWrite method and the xFileControl method
** with [SQLITE_FCNTL_SIZE_HINT].
**
** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
** operations since the previous successful call to
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
** This file control returns [SQLITE_OK] if and only if the writes were
** all performed successfully and have been committed to persistent storage.
** ^Regardless of whether or not it is successful, this file control takes
** the file descriptor out of batch write mode so that all subsequent
** write operations are independent.
** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
**
** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
** operations since the previous successful call to
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
** ^This file control takes the file descriptor out of batch write mode
** so that all subsequent write operations are independent.
** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
**
** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
** to block for up to M milliseconds before failing when attempting to
** obtain a file lock using the xLock or xShmLock methods of the VFS.
** The parameter is a pointer to a 32-bit signed integer that contains
** the value that M is to be set to. Before returning, the 32-bit signed
** integer is overwritten with the previous value of M.
**
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
** a database file.  The argument is a pointer to a 32-bit unsigned integer.
** The "data version" for the pager is written into the pointer.  The
** "data version" changes whenever any change occurs to the corresponding
** database file, either through SQL statements on the same database
** connection or through transactions committed by separate database
** connections possibly in other processes. The [sqlite3_total_changes()]
** interface can be used to find if any database on the connection has changed,
** but that interface responds to changes on TEMP as well as MAIN and does
** not provide a mechanism to detect changes to MAIN only.  Also, the
** [sqlite3_total_changes()] interface responds to internal changes only and
** omits changes made by other database connections.  The
** [PRAGMA data_version] command provides a mechanism to detect changes to
** a single attached database that occur due to other database connections,
** but omits changes implemented by the database connection on which it is
** called.  This file control is the only mechanism to detect changes that
** happen either internally or externally and that are associated with
** a particular attached database.
**
** <li>[[SQLITE_FCNTL_CKPT_START]]
** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint
** in wal mode before the client starts to copy pages from the wal
** file to the database file.
**
** <li>[[SQLITE_FCNTL_CKPT_DONE]]
** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
** in wal mode after the client has finished copying pages from the wal
** file to the database file, but before the *-shm file is updated to
** record the fact that the pages have been checkpointed.
**
** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
** whether or not there is a database client in another process with a wal-mode
** transaction open on the database or not. It is only available on unix.The
** (void*) argument passed with this file-control should be a pointer to a
** value of type (int). The integer value is set to 1 if the database is a wal
** mode database and there exists at least one client in another process that
** currently has an SQL transaction open on the database. It is set to 0 if
** the database is not a wal-mode db, or if there is no such connection in any
** other process. This opcode cannot be used to detect transactions opened
** by clients within the current process, only within other processes.
**
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
** [checksum VFS shim] only.
**
** <li>[[SQLITE_FCNTL_RESET_CACHE]]
** If there is currently no transaction open on the database, and the
** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
** purges the contents of the in-memory page cache. If there is an open
** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
** </ul>
 */

/* deprecated names */

// C documentation
//
//	/*
//	** CAPI3REF: Mutex Handle
//	**
//	** The mutex module within SQLite defines [sqlite3_mutex] to be an
//	** abstract type for a mutex object.  The SQLite core never looks
//	** at the internal representation of an [sqlite3_mutex].  It only
//	** deals with pointers to the [sqlite3_mutex] object.
//	**
//	** Mutexes are created using [sqlite3_mutex_alloc()].
//	*/
type Tsqlite3_mutex = struct {
	Fmutex TCRITICAL_SECTION
	Fid    int32
}

type sqlite3_mutex = Tsqlite3_mutex

// C documentation
//
//	/*
//	** CAPI3REF: Loadable Extension Thunk
//	**
//	** A pointer to the opaque sqlite3_api_routines structure is passed as
//	** the third parameter to entry points of [loadable extensions].  This
//	** structure must be typedefed in order to work around compiler warnings
//	** on some platforms.
//	*/
type Tsqlite3_api_routines = struct {
	Faggregate_context      uintptr
	Faggregate_count        uintptr
	Fbind_blob              uintptr
	Fbind_double            uintptr
	Fbind_int               uintptr
	Fbind_int64             uintptr
	Fbind_null              uintptr
	Fbind_parameter_count   uintptr
	Fbind_parameter_index   uintptr
	Fbind_parameter_name    uintptr
	Fbind_text              uintptr
	Fbind_text16            uintptr
	Fbind_value             uintptr
	Fbusy_handler           uintptr
	Fbusy_timeout           uintptr
	Fchanges                uintptr
	Fclose1                 uintptr
	Fcollation_needed       uintptr
	Fcollation_needed16     uintptr
	Fcolumn_blob            uintptr
	Fcolumn_bytes           uintptr
	Fcolumn_bytes16         uintptr
	Fcolumn_count           uintptr
	Fcolumn_database_name   uintptr
	Fcolumn_database_name16 uintptr
	Fcolumn_decltype        uintptr
	Fcolumn_decltype16      uintptr
	Fcolumn_double          uintptr
	Fcolumn_int             uintptr
	Fcolumn_int64           uintptr
	Fcolumn_name            uintptr
	Fcolumn_name16          uintptr
	Fcolumn_origin_name     uintptr
	Fcolumn_origin_name16   uintptr
	Fcolumn_table_name      uintptr
	Fcolumn_table_name16    uintptr
	Fcolumn_text            uintptr
	Fcolumn_text16          uintptr
	Fcolumn_type            uintptr
	Fcolumn_value           uintptr
	Fcommit_hook            uintptr
	Fcomplete               uintptr
	Fcomplete16             uintptr
	Fcreate_collation       uintptr
	Fcreate_collation16     uintptr
	Fcreate_function        uintptr
	Fcreate_function16      uintptr
	Fcreate_module          uintptr
	Fdata_count             uintptr
	Fdb_handle              uintptr
	Fdeclare_vtab           uintptr
	Fenable_shared_cache    uintptr
	Ferrcode                uintptr
	Ferrmsg                 uintptr
	Ferrmsg16               uintptr
	Fexec                   uintptr
	Fexpired                uintptr
	Ffinalize               uintptr
	Ffree                   uintptr
	Ffree_table             uintptr
	Fget_autocommit         uintptr
	Fget_auxdata            uintptr
	Fget_table              uintptr
	Fglobal_recover         uintptr
	Finterruptx             uintptr
	Flast_insert_rowid      uintptr
	Flibversion             uintptr
	Flibversion_number      uintptr
	Fmalloc                 uintptr
	Fmprintf                uintptr
	Fopen                   uintptr
	Fopen16                 uintptr
	Fprepare                uintptr
	Fprepare16              uintptr
	Fprofile                uintptr
	Fprogress_handler       uintptr
	Frealloc                uintptr
	Freset                  uintptr
	Fresult_blob            uintptr
	Fresult_double          uintptr
	Fresult_error           uintptr
	Fresult_error16         uintptr
	Fresult_int             uintptr
	Fresult_int64           uintptr
	Fresult_null            uintptr
	Fresult_text            uintptr
	Fresult_text16          uintptr
	Fresult_text16be        uintptr
	Fresult_text16le        uintptr
	Fresult_value           uintptr
	Frollback_hook          uintptr
	Fset_authorizer         uintptr
	Fset_auxdata            uintptr
	Fxsnprintf              uintptr
	Fstep                   uintptr
	Ftable_column_metadata  uintptr
	Fthread_cleanup         uintptr
	Ftotal_changes          uintptr
	Ftrace                  uintptr
	Ftransfer_bindings      uintptr
	Fupdate_hook            uintptr
	Fuser_data              uintptr
	Fvalue_blob             uintptr
	Fvalue_bytes            uintptr
	Fvalue_bytes16          uintptr
	Fvalue_double           uintptr
	Fvalue_int              uintptr
	Fvalue_int64            uintptr
	Fvalue_numeric_type     uintptr
	Fvalue_text             uintptr
	Fvalue_text16           uintptr
	Fvalue_text16be         uintptr
	Fvalue_text16le         uintptr
	Fvalue_type             uintptr
	Fvmprintf               uintptr
	Foverload_function      uintptr
	Fprepare_v2             uintptr
	Fprepare16_v2           uintptr
	Fclear_bindings         uintptr
	Fcreate_module_v2       uintptr
	Fbind_zeroblob          uintptr
	Fblob_bytes             uintptr
	Fblob_close             uintptr
	Fblob_open              uintptr
	Fblob_read              uintptr
	Fblob_write             uintptr
	Fcreate_collation_v2    uintptr
	Ffile_control           uintptr
	Fmemory_highwater       uintptr
	Fmemory_used            uintptr
	Fmutex_alloc            uintptr
	Fmutex_enter            uintptr
	Fmutex_free             uintptr
	Fmutex_leave            uintptr
	Fmutex_try              uintptr
	Fopen_v2                uintptr
	Frelease_memory         uintptr
	Fresult_error_nomem     uintptr
	Fresult_error_toobig    uintptr
	Fsleep                  uintptr
	Fsoft_heap_limit        uintptr
	Fvfs_find               uintptr
	Fvfs_register           uintptr
	Fvfs_unregister         uintptr
	Fxthreadsafe            uintptr
	Fresult_zeroblob        uintptr
	Fresult_error_code      uintptr
	Ftest_control           uintptr
	Frandomness             uintptr
	Fcontext_db_handle      uintptr
	Fextended_result_codes  uintptr
	Flimit                  uintptr
	Fnext_stmt              uintptr
	Fsql                    uintptr
	Fstatus                 uintptr
	Fbackup_finish          uintptr
	Fbackup_init            uintptr
	Fbackup_pagecount       uintptr
	Fbackup_remaining       uintptr
	Fbackup_step            uintptr
	Fcompileoption_get      uintptr
	Fcompileoption_used     uintptr
	Fcreate_function_v2     uintptr
	Fdb_config              uintptr
	Fdb_mutex               uintptr
	Fdb_status              uintptr
	Fextended_errcode       uintptr
	Flog                    uintptr
	Fsoft_heap_limit64      uintptr
	Fsourceid               uintptr
	Fstmt_status            uintptr
	Fstrnicmp               uintptr
	Funlock_notify          uintptr
	Fwal_autocheckpoint     uintptr
	Fwal_checkpoint         uintptr
	Fwal_hook               uintptr
	Fblob_reopen            uintptr
	Fvtab_config            uintptr
	Fvtab_on_conflict       uintptr
	Fclose_v2               uintptr
	Fdb_filename            uintptr
	Fdb_readonly            uintptr
	Fdb_release_memory      uintptr
	Ferrstr                 uintptr
	Fstmt_busy              uintptr
	Fstmt_readonly          uintptr
	Fstricmp                uintptr
	Furi_boolean            uintptr
	Furi_int64              uintptr
	Furi_parameter          uintptr
	Fxvsnprintf             uintptr
	Fwal_checkpoint_v2      uintptr
	Fauto_extension         uintptr
	Fbind_blob64            uintptr
	Fbind_text64            uintptr
	Fcancel_auto_extension  uintptr
	Fload_extension         uintptr
	Fmalloc64               uintptr
	Fmsize                  uintptr
	Frealloc64              uintptr
	Freset_auto_extension   uintptr
	Fresult_blob64          uintptr
	Fresult_text64          uintptr
	Fstrglob                uintptr
	Fvalue_dup              uintptr
	Fvalue_free             uintptr
	Fresult_zeroblob64      uintptr
	Fbind_zeroblob64        uintptr
	Fvalue_subtype          uintptr
	Fresult_subtype         uintptr
	Fstatus64               uintptr
	Fstrlike                uintptr
	Fdb_cacheflush          uintptr
	Fsystem_errno           uintptr
	Ftrace_v2               uintptr
	Fexpanded_sql           uintptr
	Fset_last_insert_rowid  uintptr
	Fprepare_v3             uintptr
	Fprepare16_v3           uintptr
	Fbind_pointer           uintptr
	Fresult_pointer         uintptr
	Fvalue_pointer          uintptr
	Fvtab_nochange          uintptr
	Fvalue_nochange         uintptr
	Fvtab_collation         uintptr
	Fkeyword_count          uintptr
	Fkeyword_name           uintptr
	Fkeyword_check          uintptr
	Fstr_new                uintptr
	Fstr_finish             uintptr
	Fstr_appendf            uintptr
	Fstr_vappendf           uintptr
	Fstr_append             uintptr
	Fstr_appendall          uintptr
	Fstr_appendchar         uintptr
	Fstr_reset              uintptr
	Fstr_errcode            uintptr
	Fstr_length             uintptr
	Fstr_value              uintptr
	Fcreate_window_function uintptr
	Fnormalized_sql         uintptr
	Fstmt_isexplain         uintptr
	Fvalue_frombind         uintptr
	Fdrop_modules           uintptr
	Fhard_heap_limit64      uintptr
	Furi_key                uintptr
	Ffilename_database      uintptr
	Ffilename_journal       uintptr
	Ffilename_wal           uintptr
	Fcreate_filename        uintptr
	Ffree_filename          uintptr
	Fdatabase_file_object   uintptr
	Ftxn_state              uintptr
	Fchanges64              uintptr
	Ftotal_changes64        uintptr
	Fautovacuum_pages       uintptr
	Ferror_offset           uintptr
	Fvtab_rhs_value         uintptr
	Fvtab_distinct          uintptr
	Fvtab_in                uintptr
	Fvtab_in_first          uintptr
	Fvtab_in_next           uintptr
	Fdeserialize            uintptr
	Fserialize              uintptr
	Fdb_name                uintptr
	Fvalue_encoding         uintptr
	Fis_interrupted         uintptr
	Fstmt_explain           uintptr
	Fget_clientdata         uintptr
	Fset_clientdata         uintptr
}

type sqlite3_api_routines = Tsqlite3_api_routines

// C documentation
//
//	/*
//	** CAPI3REF: File Name
//	**
//	** Type [sqlite3_filename] is used by SQLite to pass filenames to the
//	** xOpen method of a [VFS]. It may be cast to (const char*) and treated
//	** as a normal, nul-terminated, UTF-8 buffer containing the filename, but
//	** may also be passed to special APIs such as:
//	**
//	** <ul>
//	** <li>  sqlite3_filename_database()
//	** <li>  sqlite3_filename_journal()
//	** <li>  sqlite3_filename_wal()
//	** <li>  sqlite3_uri_parameter()
//	** <li>  sqlite3_uri_boolean()
//	** <li>  sqlite3_uri_int64()
//	** <li>  sqlite3_uri_key()
//	** </ul>
//	*/
type Tsqlite3_filename = uintptr

type sqlite3_filename = Tsqlite3_filename

// C documentation
//
//	/*
//	** CAPI3REF: OS Interface Object
//	**
//	** An instance of the sqlite3_vfs object defines the interface between
//	** the SQLite core and the underlying operating system.  The "vfs"
//	** in the name of the object stands for "virtual file system".  See
//	** the [VFS | VFS documentation] for further information.
//	**
//	** The VFS interface is sometimes extended by adding new methods onto
//	** the end.  Each time such an extension occurs, the iVersion field
//	** is incremented.  The iVersion value started out as 1 in
//	** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
//	** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
//	** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
//	** may be appended to the sqlite3_vfs object and the iVersion value
//	** may increase again in future versions of SQLite.
//	** Note that due to an oversight, the structure
//	** of the sqlite3_vfs object changed in the transition from
//	** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
//	** and yet the iVersion field was not increased.
//	**
//	** The szOsFile field is the size of the subclassed [sqlite3_file]
//	** structure used by this VFS.  mxPathname is the maximum length of
//	** a pathname in this VFS.
//	**
//	** Registered sqlite3_vfs objects are kept on a linked list formed by
//	** the pNext pointer.  The [sqlite3_vfs_register()]
//	** and [sqlite3_vfs_unregister()] interfaces manage this list
//	** in a thread-safe way.  The [sqlite3_vfs_find()] interface
//	** searches the list.  Neither the application code nor the VFS
//	** implementation should use the pNext pointer.
//	**
//	** The pNext field is the only field in the sqlite3_vfs
//	** structure that SQLite will ever modify.  SQLite will only access
//	** or modify this field while holding a particular static mutex.
//	** The application should never modify anything within the sqlite3_vfs
//	** object once the object has been registered.
//	**
//	** The zName field holds the name of the VFS module.  The name must
//	** be unique across all VFS modules.
//	**
//	** [[sqlite3_vfs.xOpen]]
//	** ^SQLite guarantees that the zFilename parameter to xOpen
//	** is either a NULL pointer or string obtained
//	** from xFullPathname() with an optional suffix added.
//	** ^If a suffix is added to the zFilename parameter, it will
//	** consist of a single "-" character followed by no more than
//	** 11 alphanumeric and/or "-" characters.
//	** ^SQLite further guarantees that
//	** the string will be valid and unchanged until xClose() is
//	** called. Because of the previous sentence,
//	** the [sqlite3_file] can safely store a pointer to the
//	** filename if it needs to remember the filename for some reason.
//	** If the zFilename parameter to xOpen is a NULL pointer then xOpen
//	** must invent its own temporary name for the file.  ^Whenever the
//	** xFilename parameter is NULL it will also be the case that the
//	** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
//	**
//	** The flags argument to xOpen() includes all bits set in
//	** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
//	** or [sqlite3_open16()] is used, then flags includes at least
//	** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
//	** If xOpen() opens a file read-only then it sets *pOutFlags to
//	** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
//	**
//	** ^(SQLite will also add one of the following flags to the xOpen()
//	** call, depending on the object being opened:
//	**
//	** <ul>
//	** <li>  [SQLITE_OPEN_MAIN_DB]
//	** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
//	** <li>  [SQLITE_OPEN_TEMP_DB]
//	** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
//	** <li>  [SQLITE_OPEN_TRANSIENT_DB]
//	** <li>  [SQLITE_OPEN_SUBJOURNAL]
//	** <li>  [SQLITE_OPEN_SUPER_JOURNAL]
//	** <li>  [SQLITE_OPEN_WAL]
//	** </ul>)^
//	**
//	** The file I/O implementation can use the object type flags to
//	** change the way it deals with files.  For example, an application
//	** that does not care about crash recovery or rollback might make
//	** the open of a journal file a no-op.  Writes to this journal would
//	** also be no-ops, and any attempt to read the journal would return
//	** SQLITE_IOERR.  Or the implementation might recognize that a database
//	** file will be doing page-aligned sector reads and writes in a random
//	** order and set up its I/O subsystem accordingly.
//	**
//	** SQLite might also add one of the following flags to the xOpen method:
//	**
//	** <ul>
//	** <li> [SQLITE_OPEN_DELETEONCLOSE]
//	** <li> [SQLITE_OPEN_EXCLUSIVE]
//	** </ul>
//	**
//	** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
//	** deleted when it is closed.  ^The [SQLITE_OPEN_DELETEONCLOSE]
//	** will be set for TEMP databases and their journals, transient
//	** databases, and subjournals.
//	**
//	** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
//	** with the [SQLITE_OPEN_CREATE] flag, which are both directly
//	** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
//	** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
//	** SQLITE_OPEN_CREATE, is used to indicate that file should always
//	** be created, and that it is an error if it already exists.
//	** It is <i>not</i> used to indicate the file should be opened
//	** for exclusive access.
//	**
//	** ^At least szOsFile bytes of memory are allocated by SQLite
//	** to hold the [sqlite3_file] structure passed as the third
//	** argument to xOpen.  The xOpen method does not have to
//	** allocate the structure; it should just fill it in.  Note that
//	** the xOpen method must set the sqlite3_file.pMethods to either
//	** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
//	** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
//	** element will be valid after xOpen returns regardless of the success
//	** or failure of the xOpen call.
//	**
//	** [[sqlite3_vfs.xAccess]]
//	** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
//	** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
//	** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
//	** to test whether a file is at least readable.  The SQLITE_ACCESS_READ
//	** flag is never actually used and is not implemented in the built-in
//	** VFSes of SQLite.  The file is named by the second argument and can be a
//	** directory. The xAccess method returns [SQLITE_OK] on success or some
//	** non-zero error code if there is an I/O error or if the name of
//	** the file given in the second argument is illegal.  If SQLITE_OK
//	** is returned, then non-zero or zero is written into *pResOut to indicate
//	** whether or not the file is accessible.
//	**
//	** ^SQLite will always allocate at least mxPathname+1 bytes for the
//	** output buffer xFullPathname.  The exact size of the output buffer
//	** is also passed as a parameter to both  methods. If the output buffer
//	** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
//	** handled as a fatal error by SQLite, vfs implementations should endeavor
//	** to prevent this by setting mxPathname to a sufficiently large value.
//	**
//	** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
//	** interfaces are not strictly a part of the filesystem, but they are
//	** included in the VFS structure for completeness.
//	** The xRandomness() function attempts to return nBytes bytes
//	** of good-quality randomness into zOut.  The return value is
//	** the actual number of bytes of randomness obtained.
//	** The xSleep() method causes the calling thread to sleep for at
//	** least the number of microseconds given.  ^The xCurrentTime()
//	** method returns a Julian Day Number for the current date and time as
//	** a floating point value.
//	** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
//	** Day Number multiplied by 86400000 (the number of milliseconds in
//	** a 24-hour day).
//	** ^SQLite will use the xCurrentTimeInt64() method to get the current
//	** date and time if that method is available (if iVersion is 2 or
//	** greater and the function pointer is not NULL) and will fall back
//	** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
//	**
//	** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
//	** are not used by the SQLite core.  These optional interfaces are provided
//	** by some VFSes to facilitate testing of the VFS code. By overriding
//	** system calls with functions under its control, a test program can
//	** simulate faults and error conditions that would otherwise be difficult
//	** or impossible to induce.  The set of system calls that can be overridden
//	** varies from one VFS to another, and from one version of the same VFS to the
//	** next.  Applications that use these interfaces must be prepared for any
//	** or all of these interfaces to be NULL or for their behavior to change
//	** from one release to the next.  Applications must not attempt to access
//	** any of these methods if the iVersion of the VFS is less than 3.
//	*/
type Tsqlite3_vfs = struct {
	FiVersion          int32
	FszOsFile          int32
	FmxPathname        int32
	FpNext             uintptr
	FzName             uintptr
	FpAppData          uintptr
	FxOpen             uintptr
	FxDelete           uintptr
	FxAccess           uintptr
	FxFullPathname     uintptr
	FxDlOpen           uintptr
	FxDlError          uintptr
	FxDlSym            uintptr
	FxDlClose          uintptr
	FxRandomness       uintptr
	FxSleep            uintptr
	FxCurrentTime      uintptr
	FxGetLastError     uintptr
	FxCurrentTimeInt64 uintptr
	FxSetSystemCall    uintptr
	FxGetSystemCall    uintptr
	FxNextSystemCall   uintptr
}

type sqlite3_vfs = Tsqlite3_vfs

type Tsqlite3_syscall_ptr = uintptr

type sqlite3_syscall_ptr = Tsqlite3_syscall_ptr

type Tsqlite3_vfs1 = struct {
	FiVersion          int32
	FszOsFile          int32
	FmxPathname        int32
	FpNext             uintptr
	FzName             uintptr
	FpAppData          uintptr
	FxOpen             uintptr
	FxDelete           uintptr
	FxAccess           uintptr
	FxFullPathname     uintptr
	FxDlOpen           uintptr
	FxDlError          uintptr
	FxDlSym            uintptr
	FxDlClose          uintptr
	FxRandomness       uintptr
	FxSleep            uintptr
	FxCurrentTime      uintptr
	FxGetLastError     uintptr
	FxCurrentTimeInt64 uintptr
	FxSetSystemCall    uintptr
	FxGetSystemCall    uintptr
	FxNextSystemCall   uintptr
}

type sqlite3_vfs1 = Tsqlite3_vfs1

// C documentation
//
//	/*
//	** CAPI3REF: Memory Allocation Routines
//	**
//	** An instance of this object defines the interface between SQLite
//	** and low-level memory allocation routines.
//	**
//	** This object is used in only one place in the SQLite interface.
//	** A pointer to an instance of this object is the argument to
//	** [sqlite3_config()] when the configuration option is
//	** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
//	** By creating an instance of this object
//	** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
//	** during configuration, an application can specify an alternative
//	** memory allocation subsystem for SQLite to use for all of its
//	** dynamic memory needs.
//	**
//	** Note that SQLite comes with several [built-in memory allocators]
//	** that are perfectly adequate for the overwhelming majority of applications
//	** and that this object is only useful to a tiny minority of applications
//	** with specialized memory allocation requirements.  This object is
//	** also used during testing of SQLite in order to specify an alternative
//	** memory allocator that simulates memory out-of-memory conditions in
//	** order to verify that SQLite recovers gracefully from such
//	** conditions.
//	**
//	** The xMalloc, xRealloc, and xFree methods must work like the
//	** malloc(), realloc() and free() functions from the standard C library.
//	** ^SQLite guarantees that the second argument to
//	** xRealloc is always a value returned by a prior call to xRoundup.
//	**
//	** xSize should return the allocated size of a memory allocation
//	** previously obtained from xMalloc or xRealloc.  The allocated size
//	** is always at least as big as the requested size but may be larger.
//	**
//	** The xRoundup method returns what would be the allocated size of
//	** a memory allocation given a particular requested size.  Most memory
//	** allocators round up memory allocations at least to the next multiple
//	** of 8.  Some allocators round up to a larger multiple or to a power of 2.
//	** Every memory allocation request coming in through [sqlite3_malloc()]
//	** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0,
//	** that causes the corresponding memory allocation to fail.
//	**
//	** The xInit method initializes the memory allocator.  For example,
//	** it might allocate any required mutexes or initialize internal data
//	** structures.  The xShutdown method is invoked (indirectly) by
//	** [sqlite3_shutdown()] and should deallocate any resources acquired
//	** by xInit.  The pAppData pointer is used as the only parameter to
//	** xInit and xShutdown.
//	**
//	** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
//	** the xInit method, so the xInit method need not be threadsafe.  The
//	** xShutdown method is only called from [sqlite3_shutdown()] so it does
//	** not need to be threadsafe either.  For all other methods, SQLite
//	** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
//	** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
//	** it is by default) and so the methods are automatically serialized.
//	** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
//	** methods must be threadsafe or else make their own arrangements for
//	** serialization.
//	**
//	** SQLite will never invoke xInit() more than once without an intervening
//	** call to xShutdown().
//	*/
type Tsqlite3_mem_methods = struct {
	FxMalloc   uintptr
	FxFree     uintptr
	FxRealloc  uintptr
	FxSize     uintptr
	FxRoundup  uintptr
	FxInit     uintptr
	FxShutdown uintptr
	FpAppData  uintptr
}

type sqlite3_mem_methods = Tsqlite3_mem_methods

type Tsqlite3_mem_methods1 = struct {
	FxMalloc   uintptr
	FxFree     uintptr
	FxRealloc  uintptr
	FxSize     uintptr
	FxRoundup  uintptr
	FxInit     uintptr
	FxShutdown uintptr
	FpAppData  uintptr
}

type sqlite3_mem_methods1 = Tsqlite3_mem_methods1

// C documentation
//
//	/*
//	** CAPI3REF: Dynamically Typed Value Object
//	** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
//	**
//	** SQLite uses the sqlite3_value object to represent all values
//	** that can be stored in a database table. SQLite uses dynamic typing
//	** for the values it stores.  ^Values stored in sqlite3_value objects
//	** can be integers, floating point values, strings, BLOBs, or NULL.
//	**
//	** An sqlite3_value object may be either "protected" or "unprotected".
//	** Some interfaces require a protected sqlite3_value.  Other interfaces
//	** will accept either a protected or an unprotected sqlite3_value.
//	** Every interface that accepts sqlite3_value arguments specifies
//	** whether or not it requires a protected sqlite3_value.  The
//	** [sqlite3_value_dup()] interface can be used to construct a new
//	** protected sqlite3_value from an unprotected sqlite3_value.
//	**
//	** The terms "protected" and "unprotected" refer to whether or not
//	** a mutex is held.  An internal mutex is held for a protected
//	** sqlite3_value object but no mutex is held for an unprotected
//	** sqlite3_value object.  If SQLite is compiled to be single-threaded
//	** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
//	** or if SQLite is run in one of reduced mutex modes
//	** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
//	** then there is no distinction between protected and unprotected
//	** sqlite3_value objects and they can be used interchangeably.  However,
//	** for maximum code portability it is recommended that applications
//	** still make the distinction between protected and unprotected
//	** sqlite3_value objects even when not strictly required.
//	**
//	** ^The sqlite3_value objects that are passed as parameters into the
//	** implementation of [application-defined SQL functions] are protected.
//	** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
//	** are protected.
//	** ^The sqlite3_value object returned by
//	** [sqlite3_column_value()] is unprotected.
//	** Unprotected sqlite3_value objects may only be used as arguments
//	** to [sqlite3_result_value()], [sqlite3_bind_value()], and
//	** [sqlite3_value_dup()].
//	** The [sqlite3_value_blob | sqlite3_value_type()] family of
//	** interfaces require protected sqlite3_value objects.
//	*/
type Tsqlite3_value = struct {
	F__ccgo_align [0]uint32
	Fu            TMemValue
	Fz            uintptr
	Fn            int32
	Fflags        Tu16
	Fenc          Tu8
	FeSubtype     Tu8
	Fdb           uintptr
	FszMalloc     int32
	FuTemp        Tu32
	FzMalloc      uintptr
	FxDel         uintptr
}

type sqlite3_value = Tsqlite3_value

// C documentation
//
//	/*
//	** CAPI3REF: SQL Function Context Object
//	**
//	** The context in which an SQL function executes is stored in an
//	** sqlite3_context object.  ^A pointer to an sqlite3_context object
//	** is always first parameter to [application-defined SQL functions].
//	** The application-defined SQL function implementation will pass this
//	** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
//	** [sqlite3_aggregate_context()], [sqlite3_user_data()],
//	** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
//	** and/or [sqlite3_set_auxdata()].
//	*/
type Tsqlite3_context = struct {
	FpOut     uintptr
	FpFunc    uintptr
	FpMem     uintptr
	FpVdbe    uintptr
	FiOp      int32
	FisError  int32
	Fenc      Tu8
	FskipFlag Tu8
	Fargc     Tu8
	Fargv     [1]uintptr
}

type sqlite3_context = Tsqlite3_context

// C documentation
//
//	/*
//	** CAPI3REF: Constants Defining Special Destructor Behavior
//	**
//	** These are special values for the destructor that is passed in as the
//	** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
//	** argument is SQLITE_STATIC, it means that the content pointer is constant
//	** and will never change.  It does not need to be destroyed.  ^The
//	** SQLITE_TRANSIENT value means that the content will likely change in
//	** the near future and that SQLite should make its own private copy of
//	** the content before returning.
//	**
//	** The typedef is necessary to work around problems in certain
//	** C++ compilers.
//	*/
type Tsqlite3_destructor_type = uintptr

type sqlite3_destructor_type = Tsqlite3_destructor_type

// C documentation
//
//	/*
//	** Structures used by the virtual table interface
//	*/
type Tsqlite3_vtab = struct {
	FpModule uintptr
	FnRef    int32
	FzErrMsg uintptr
}

type sqlite3_vtab = Tsqlite3_vtab

type Tsqlite3_index_info = struct {
	F__ccgo_align     [0]uint32
	FnConstraint      int32
	FaConstraint      uintptr
	FnOrderBy         int32
	FaOrderBy         uintptr
	FaConstraintUsage uintptr
	FidxNum           int32
	FidxStr           uintptr
	FneedToFreeIdxStr int32
	ForderByConsumed  int32
	F__ccgo_align9    [4]byte
	FestimatedCost    float64
	FestimatedRows    Tsqlite3_int64
	FidxFlags         int32
	F__ccgo_align12   [4]byte
	FcolUsed          Tsqlite3_uint64
}

type sqlite3_index_info = Tsqlite3_index_info

type Tsqlite3_vtab_cursor = struct {
	FpVtab uintptr
}

type sqlite3_vtab_cursor = Tsqlite3_vtab_cursor

type Tsqlite3_module = struct {
	FiVersion      int32
	FxCreate       uintptr
	FxConnect      uintptr
	FxBestIndex    uintptr
	FxDisconnect   uintptr
	FxDestroy      uintptr
	FxOpen         uintptr
	FxClose        uintptr
	FxFilter       uintptr
	FxNext         uintptr
	FxEof          uintptr
	FxColumn       uintptr
	FxRowid        uintptr
	FxUpdate       uintptr
	FxBegin        uintptr
	FxSync         uintptr
	FxCommit       uintptr
	FxRollback     uintptr
	FxFindFunction uintptr
	FxRename       uintptr
	FxSavepoint    uintptr
	FxRelease      uintptr
	FxRollbackTo   uintptr
	FxShadowName   uintptr
	FxIntegrity    uintptr
}

type sqlite3_module = Tsqlite3_module

/*
** CAPI3REF: Virtual Table Object
** KEYWORDS: sqlite3_module {virtual table module}
**
** This structure, sometimes called a "virtual table module",
** defines the implementation of a [virtual table].
** This structure consists mostly of methods for the module.
**
** ^A virtual table module is created by filling in a persistent
** instance of this structure and passing a pointer to that instance
** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
** ^The registration remains valid until it is replaced by a different
** module or until the [database connection] closes.  The content
** of this structure must not change while it is registered with
** any database connection.
 */
type Tsqlite3_module1 = struct {
	FiVersion      int32
	FxCreate       uintptr
	FxConnect      uintptr
	FxBestIndex    uintptr
	FxDisconnect   uintptr
	FxDestroy      uintptr
	FxOpen         uintptr
	FxClose        uintptr
	FxFilter       uintptr
	FxNext         uintptr
	FxEof          uintptr
	FxColumn       uintptr
	FxRowid        uintptr
	FxUpdate       uintptr
	FxBegin        uintptr
	FxSync         uintptr
	FxCommit       uintptr
	FxRollback     uintptr
	FxFindFunction uintptr
	FxRename       uintptr
	FxSavepoint    uintptr
	FxRelease      uintptr
	FxRollbackTo   uintptr
	FxShadowName   uintptr
	FxIntegrity    uintptr
}

type sqlite3_module1 = Tsqlite3_module1

/*
** CAPI3REF: Virtual Table Indexing Information
** KEYWORDS: sqlite3_index_info
**
** The sqlite3_index_info structure and its substructures is used as part
** of the [virtual table] interface to
** pass information into and receive the reply from the [xBestIndex]
** method of a [virtual table module].  The fields under **Inputs** are the
** inputs to xBestIndex and are read-only.  xBestIndex inserts its
** results into the **Outputs** fields.
**
** ^(The aConstraint[] array records WHERE clause constraints of the form:
**
** <blockquote>column OP expr</blockquote>
**
** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
** stored in aConstraint[].op using one of the
** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
** ^(The index of the column is stored in
** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
** expr on the right-hand side can be evaluated (and thus the constraint
** is usable) and false if it cannot.)^
**
** ^The optimizer automatically inverts terms of the form "expr OP column"
** and makes other simplifications to the WHERE clause in an attempt to
** get as many WHERE clause terms into the form shown above as possible.
** ^The aConstraint[] array only reports WHERE clause terms that are
** relevant to the particular virtual table being queried.
**
** ^Information about the ORDER BY clause is stored in aOrderBy[].
** ^Each term of aOrderBy records a column of the ORDER BY clause.
**
** The colUsed field indicates which columns of the virtual table may be
** required by the current scan. Virtual table columns are numbered from
** zero in the order in which they appear within the CREATE TABLE statement
** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
** the corresponding bit is set within the colUsed mask if the column may be
** required by SQLite. If the table has at least 64 columns and any column
** to the right of the first 63 is required, then bit 63 of colUsed is also
** set. In other words, column iCol may be required if the expression
** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to
** non-zero.
**
** The [xBestIndex] method must fill aConstraintUsage[] with information
** about what parameters to pass to xFilter.  ^If argvIndex>0 then
** the right-hand side of the corresponding aConstraint[] is evaluated
** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
** is true, then the constraint is assumed to be fully handled by the
** virtual table and might not be checked again by the byte code.)^ ^(The
** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
** is left in its default setting of false, the constraint will always be
** checked separately in byte code.  If the omit flag is change to true, then
** the constraint may or may not be checked in byte code.  In other words,
** when the omit flag is true there is no guarantee that the constraint will
** not be checked again using byte code.)^
**
** ^The idxNum and idxStr values are recorded and passed into the
** [xFilter] method.
** ^[sqlite3_free()] is used to free idxStr if and only if
** needToFreeIdxStr is true.
**
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
** the correct order to satisfy the ORDER BY clause so that no separate
** sorting step is required.
**
** ^The estimatedCost value is an estimate of the cost of a particular
** strategy. A cost of N indicates that the cost of the strategy is similar
** to a linear scan of an SQLite table with N rows. A cost of log(N)
** indicates that the expense of the operation is similar to that of a
** binary search on a unique indexed field of an SQLite table with N rows.
**
** ^The estimatedRows value is an estimate of the number of rows that
** will be returned by the strategy.
**
** The xBestIndex method may optionally populate the idxFlags field with a
** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
** assumes that the strategy may visit at most one row.
**
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
** SQLite also assumes that if a call to the xUpdate() method is made as
** part of the same statement to delete or update a virtual table row and the
** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback
** any database changes. In other words, if the xUpdate() returns
** SQLITE_CONSTRAINT, the database contents must be exactly as they were
** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not
** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by
** the xUpdate method are automatically rolled back by SQLite.
**
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
** If a virtual table extension is
** used with an SQLite version earlier than 3.8.2, the results of attempting
** to read or write the estimatedRows field are undefined (but are likely
** to include crashing the application). The estimatedRows field should
** therefore only be used if [sqlite3_libversion_number()] returns a
** value greater than or equal to 3008002. Similarly, the idxFlags field
** was added for [version 3.9.0] ([dateof:3.9.0]).
** It may therefore only be used if
** sqlite3_libversion_number() returns a value greater than or equal to
** 3009000.
 */
type Tsqlite3_index_info1 = struct {
	F__ccgo_align     [0]uint32
	FnConstraint      int32
	FaConstraint      uintptr
	FnOrderBy         int32
	FaOrderBy         uintptr
	FaConstraintUsage uintptr
	FidxNum           int32
	FidxStr           uintptr
	FneedToFreeIdxStr int32
	ForderByConsumed  int32
	F__ccgo_align9    [4]byte
	FestimatedCost    float64
	FestimatedRows    Tsqlite3_int64
	FidxFlags         int32
	F__ccgo_align12   [4]byte
	FcolUsed          Tsqlite3_uint64
}

type sqlite3_index_info1 = Tsqlite3_index_info1

/*
** CAPI3REF: Virtual Table Instance Object
** KEYWORDS: sqlite3_vtab
**
** Every [virtual table module] implementation uses a subclass
** of this object to describe a particular instance
** of the [virtual table].  Each subclass will
** be tailored to the specific needs of the module implementation.
** The purpose of this superclass is to define certain fields that are
** common to all module implementations.
**
** ^Virtual tables methods can set an error message by assigning a
** string obtained from [sqlite3_mprintf()] to zErrMsg.  The method should
** take care that any prior string is freed by a call to [sqlite3_free()]
** prior to assigning a new string to zErrMsg.  ^After the error message
** is delivered up to the client application, the string will be automatically
** freed by sqlite3_free() and the zErrMsg field will be zeroed.
 */
type Tsqlite3_vtab1 = struct {
	FpModule uintptr
	FnRef    int32
	FzErrMsg uintptr
}

type sqlite3_vtab1 = Tsqlite3_vtab1

/*
** CAPI3REF: Virtual Table Cursor Object
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
**
** Every [virtual table module] implementation uses a subclass of the
** following structure to describe cursors that point into the
** [virtual table] and are used
** to loop through the virtual table.  Cursors are created using the
** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
** by the [sqlite3_module.xClose | xClose] method.  Cursors are used
** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
** of the module.  Each module implementation will define
** the content of a cursor structure to suit its own needs.
**
** This superclass exists in order to define fields of the cursor that
** are common to all implementations.
 */
type Tsqlite3_vtab_cursor1 = struct {
	FpVtab uintptr
}

type sqlite3_vtab_cursor1 = Tsqlite3_vtab_cursor1

// C documentation
//
//	/*
//	** CAPI3REF: Mutex Methods Object
//	**
//	** An instance of this structure defines the low-level routines
//	** used to allocate and use mutexes.
//	**
//	** Usually, the default mutex implementations provided by SQLite are
//	** sufficient, however the application has the option of substituting a custom
//	** implementation for specialized deployments or systems for which SQLite
//	** does not provide a suitable implementation. In this case, the application
//	** creates and populates an instance of this structure to pass
//	** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
//	** Additionally, an instance of this structure can be used as an
//	** output variable when querying the system for the current mutex
//	** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
//	**
//	** ^The xMutexInit method defined by this structure is invoked as
//	** part of system initialization by the sqlite3_initialize() function.
//	** ^The xMutexInit routine is called by SQLite exactly once for each
//	** effective call to [sqlite3_initialize()].
//	**
//	** ^The xMutexEnd method defined by this structure is invoked as
//	** part of system shutdown by the sqlite3_shutdown() function. The
//	** implementation of this method is expected to release all outstanding
//	** resources obtained by the mutex methods implementation, especially
//	** those obtained by the xMutexInit method.  ^The xMutexEnd()
//	** interface is invoked exactly once for each call to [sqlite3_shutdown()].
//	**
//	** ^(The remaining seven methods defined by this structure (xMutexAlloc,
//	** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
//	** xMutexNotheld) implement the following interfaces (respectively):
//	**
//	** <ul>
//	**   <li>  [sqlite3_mutex_alloc()] </li>
//	**   <li>  [sqlite3_mutex_free()] </li>
//	**   <li>  [sqlite3_mutex_enter()] </li>
//	**   <li>  [sqlite3_mutex_try()] </li>
//	**   <li>  [sqlite3_mutex_leave()] </li>
//	**   <li>  [sqlite3_mutex_held()] </li>
//	**   <li>  [sqlite3_mutex_notheld()] </li>
//	** </ul>)^
//	**
//	** The only difference is that the public sqlite3_XXX functions enumerated
//	** above silently ignore any invocations that pass a NULL pointer instead
//	** of a valid mutex handle. The implementations of the methods defined
//	** by this structure are not required to handle this case. The results
//	** of passing a NULL pointer instead of a valid mutex handle are undefined
//	** (i.e. it is acceptable to provide an implementation that segfaults if
//	** it is passed a NULL pointer).
//	**
//	** The xMutexInit() method must be threadsafe.  It must be harmless to
//	** invoke xMutexInit() multiple times within the same process and without
//	** intervening calls to xMutexEnd().  Second and subsequent calls to
//	** xMutexInit() must be no-ops.
//	**
//	** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
//	** and its associates).  Similarly, xMutexAlloc() must not use SQLite memory
//	** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
//	** memory allocation for a fast or recursive mutex.
//	**
//	** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
//	** called, but only if the prior call to xMutexInit returned SQLITE_OK.
//	** If xMutexInit fails in any way, it is expected to clean up after itself
//	** prior to returning.
//	*/
type Tsqlite3_mutex_methods = struct {
	FxMutexInit    uintptr
	FxMutexEnd     uintptr
	FxMutexAlloc   uintptr
	FxMutexFree    uintptr
	FxMutexEnter   uintptr
	FxMutexTry     uintptr
	FxMutexLeave   uintptr
	FxMutexHeld    uintptr
	FxMutexNotheld uintptr
}

type sqlite3_mutex_methods = Tsqlite3_mutex_methods

type Tsqlite3_mutex_methods1 = struct {
	FxMutexInit    uintptr
	FxMutexEnd     uintptr
	FxMutexAlloc   uintptr
	FxMutexFree    uintptr
	FxMutexEnter   uintptr
	FxMutexTry     uintptr
	FxMutexLeave   uintptr
	FxMutexHeld    uintptr
	FxMutexNotheld uintptr
}

type sqlite3_mutex_methods1 = Tsqlite3_mutex_methods1

// C documentation
//
//	/*
//	** CAPI3REF: Dynamic String Object
//	** KEYWORDS: {dynamic string}
//	**
//	** An instance of the sqlite3_str object contains a dynamically-sized
//	** string under construction.
//	**
//	** The lifecycle of an sqlite3_str object is as follows:
//	** <ol>
//	** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
//	** <li> ^Text is appended to the sqlite3_str object using various
//	** methods, such as [sqlite3_str_appendf()].
//	** <li> ^The sqlite3_str object is destroyed and the string it created
//	** is returned using the [sqlite3_str_finish()] interface.
//	** </ol>
//	*/
type Tsqlite3_str = struct {
	Fdb          uintptr
	FzText       uintptr
	FnAlloc      Tu32
	FmxAlloc     Tu32
	FnChar       Tu32
	FaccError    Tu8
	FprintfFlags Tu8
}

type sqlite3_str = Tsqlite3_str

// C documentation
//
//	/*
//	** CAPI3REF: Custom Page Cache Object
//	**
//	** The sqlite3_pcache_page object represents a single page in the
//	** page cache.  The page cache will allocate instances of this
//	** object.  Various methods of the page cache use pointers to instances
//	** of this object as parameters or as their return value.
//	**
//	** See [sqlite3_pcache_methods2] for additional information.
//	*/
type Tsqlite3_pcache_page = struct {
	FpBuf   uintptr
	FpExtra uintptr
}

type sqlite3_pcache_page = Tsqlite3_pcache_page

type Tsqlite3_pcache_page1 = struct {
	FpBuf   uintptr
	FpExtra uintptr
}

type sqlite3_pcache_page1 = Tsqlite3_pcache_page1

// C documentation
//
//	/*
//	** CAPI3REF: Application Defined Page Cache.
//	** KEYWORDS: {page cache}
//	**
//	** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
//	** register an alternative page cache implementation by passing in an
//	** instance of the sqlite3_pcache_methods2 structure.)^
//	** In many applications, most of the heap memory allocated by
//	** SQLite is used for the page cache.
//	** By implementing a
//	** custom page cache using this API, an application can better control
//	** the amount of memory consumed by SQLite, the way in which
//	** that memory is allocated and released, and the policies used to
//	** determine exactly which parts of a database file are cached and for
//	** how long.
//	**
//	** The alternative page cache mechanism is an
//	** extreme measure that is only needed by the most demanding applications.
//	** The built-in page cache is recommended for most uses.
//	**
//	** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
//	** internal buffer by SQLite within the call to [sqlite3_config].  Hence
//	** the application may discard the parameter after the call to
//	** [sqlite3_config()] returns.)^
//	**
//	** [[the xInit() page cache method]]
//	** ^(The xInit() method is called once for each effective
//	** call to [sqlite3_initialize()])^
//	** (usually only once during the lifetime of the process). ^(The xInit()
//	** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
//	** The intent of the xInit() method is to set up global data structures
//	** required by the custom page cache implementation.
//	** ^(If the xInit() method is NULL, then the
//	** built-in default page cache is used instead of the application defined
//	** page cache.)^
//	**
//	** [[the xShutdown() page cache method]]
//	** ^The xShutdown() method is called by [sqlite3_shutdown()].
//	** It can be used to clean up
//	** any outstanding resources before process shutdown, if required.
//	** ^The xShutdown() method may be NULL.
//	**
//	** ^SQLite automatically serializes calls to the xInit method,
//	** so the xInit method need not be threadsafe.  ^The
//	** xShutdown method is only called from [sqlite3_shutdown()] so it does
//	** not need to be threadsafe either.  All other methods must be threadsafe
//	** in multithreaded applications.
//	**
//	** ^SQLite will never invoke xInit() more than once without an intervening
//	** call to xShutdown().
//	**
//	** [[the xCreate() page cache methods]]
//	** ^SQLite invokes the xCreate() method to construct a new cache instance.
//	** SQLite will typically create one cache instance for each open database file,
//	** though this is not guaranteed. ^The
//	** first parameter, szPage, is the size in bytes of the pages that must
//	** be allocated by the cache.  ^szPage will always a power of two.  ^The
//	** second parameter szExtra is a number of bytes of extra storage
//	** associated with each page cache entry.  ^The szExtra parameter will
//	** a number less than 250.  SQLite will use the
//	** extra szExtra bytes on each page to store metadata about the underlying
//	** database page on disk.  The value passed into szExtra depends
//	** on the SQLite version, the target platform, and how SQLite was compiled.
//	** ^The third argument to xCreate(), bPurgeable, is true if the cache being
//	** created will be used to cache database pages of a file stored on disk, or
//	** false if it is used for an in-memory database. The cache implementation
//	** does not have to do anything special based with the value of bPurgeable;
//	** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
//	** never invoke xUnpin() except to deliberately delete a page.
//	** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
//	** false will always have the "discard" flag set to true.
//	** ^Hence, a cache created with bPurgeable false will
//	** never contain any unpinned pages.
//	**
//	** [[the xCachesize() page cache method]]
//	** ^(The xCachesize() method may be called at any time by SQLite to set the
//	** suggested maximum cache-size (number of pages stored by) the cache
//	** instance passed as the first argument. This is the value configured using
//	** the SQLite "[PRAGMA cache_size]" command.)^  As with the bPurgeable
//	** parameter, the implementation is not required to do anything with this
//	** value; it is advisory only.
//	**
//	** [[the xPagecount() page cache methods]]
//	** The xPagecount() method must return the number of pages currently
//	** stored in the cache, both pinned and unpinned.
//	**
//	** [[the xFetch() page cache methods]]
//	** The xFetch() method locates a page in the cache and returns a pointer to
//	** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
//	** The pBuf element of the returned sqlite3_pcache_page object will be a
//	** pointer to a buffer of szPage bytes used to store the content of a
//	** single database page.  The pExtra element of sqlite3_pcache_page will be
//	** a pointer to the szExtra bytes of extra storage that SQLite has requested
//	** for each entry in the page cache.
//	**
//	** The page to be fetched is determined by the key. ^The minimum key value
//	** is 1.  After it has been retrieved using xFetch, the page is considered
//	** to be "pinned".
//	**
//	** If the requested page is already in the page cache, then the page cache
//	** implementation must return a pointer to the page buffer with its content
//	** intact.  If the requested page is not already in the cache, then the
//	** cache implementation should use the value of the createFlag
//	** parameter to help it determined what action to take:
//	**
//	** <table border=1 width=85% align=center>
//	** <tr><th> createFlag <th> Behavior when page is not already in cache
//	** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
//	** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
//	**                 Otherwise return NULL.
//	** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
//	**                 NULL if allocating a new page is effectively impossible.
//	** </table>
//	**
//	** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  SQLite
//	** will only use a createFlag of 2 after a prior call with a createFlag of 1
//	** failed.)^  In between the xFetch() calls, SQLite may
//	** attempt to unpin one or more cache pages by spilling the content of
//	** pinned pages to disk and synching the operating system disk cache.
//	**
//	** [[the xUnpin() page cache method]]
//	** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
//	** as its second argument.  If the third parameter, discard, is non-zero,
//	** then the page must be evicted from the cache.
//	** ^If the discard parameter is
//	** zero, then the page may be discarded or retained at the discretion of
//	** page cache implementation. ^The page cache implementation
//	** may choose to evict unpinned pages at any time.
//	**
//	** The cache must not perform any reference counting. A single
//	** call to xUnpin() unpins the page regardless of the number of prior calls
//	** to xFetch().
//	**
//	** [[the xRekey() page cache methods]]
//	** The xRekey() method is used to change the key value associated with the
//	** page passed as the second argument. If the cache
//	** previously contains an entry associated with newKey, it must be
//	** discarded. ^Any prior cache entry associated with newKey is guaranteed not
//	** to be pinned.
//	**
//	** When SQLite calls the xTruncate() method, the cache must discard all
//	** existing cache entries with page numbers (keys) greater than or equal
//	** to the value of the iLimit parameter passed to xTruncate(). If any
//	** of these pages are pinned, they are implicitly unpinned, meaning that
//	** they can be safely discarded.
//	**
//	** [[the xDestroy() page cache method]]
//	** ^The xDestroy() method is used to delete a cache allocated by xCreate().
//	** All resources associated with the specified cache should be freed. ^After
//	** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
//	** handle invalid, and will not use it with any other sqlite3_pcache_methods2
//	** functions.
//	**
//	** [[the xShrink() page cache method]]
//	** ^SQLite invokes the xShrink() method when it wants the page cache to
//	** free up as much of heap memory as possible.  The page cache implementation
//	** is not obligated to free any memory, but well-behaved implementations should
//	** do their best.
//	*/
type Tsqlite3_pcache_methods2 = struct {
	FiVersion   int32
	FpArg       uintptr
	FxInit      uintptr
	FxShutdown  uintptr
	FxCreate    uintptr
	FxCachesize uintptr
	FxPagecount uintptr
	FxFetch     uintptr
	FxUnpin     uintptr
	FxRekey     uintptr
	FxTruncate  uintptr
	FxDestroy   uintptr
	FxShrink    uintptr
}

type sqlite3_pcache_methods2 = Tsqlite3_pcache_methods2

type Tsqlite3_pcache_methods21 = struct {
	FiVersion   int32
	FpArg       uintptr
	FxInit      uintptr
	FxShutdown  uintptr
	FxCreate    uintptr
	FxCachesize uintptr
	FxPagecount uintptr
	FxFetch     uintptr
	FxUnpin     uintptr
	FxRekey     uintptr
	FxTruncate  uintptr
	FxDestroy   uintptr
	FxShrink    uintptr
}

type sqlite3_pcache_methods21 = Tsqlite3_pcache_methods21

// C documentation
//
//	/*
//	** This is the obsolete pcache_methods object that has now been replaced
//	** by sqlite3_pcache_methods2.  This object is not used by SQLite.  It is
//	** retained in the header file for backwards compatibility only.
//	*/
type Tsqlite3_pcache_methods = struct {
	FpArg       uintptr
	FxInit      uintptr
	FxShutdown  uintptr
	FxCreate    uintptr
	FxCachesize uintptr
	FxPagecount uintptr
	FxFetch     uintptr
	FxUnpin     uintptr
	FxRekey     uintptr
	FxTruncate  uintptr
	FxDestroy   uintptr
}

type sqlite3_pcache_methods = Tsqlite3_pcache_methods

type Tsqlite3_pcache_methods1 = struct {
	FpArg       uintptr
	FxInit      uintptr
	FxShutdown  uintptr
	FxCreate    uintptr
	FxCachesize uintptr
	FxPagecount uintptr
	FxFetch     uintptr
	FxUnpin     uintptr
	FxRekey     uintptr
	FxTruncate  uintptr
	FxDestroy   uintptr
}

type sqlite3_pcache_methods1 = Tsqlite3_pcache_methods1

// C documentation
//
//	/*
//	** CAPI3REF: Online Backup Object
//	**
//	** The sqlite3_backup object records state information about an ongoing
//	** online backup operation.  ^The sqlite3_backup object is created by
//	** a call to [sqlite3_backup_init()] and is destroyed by a call to
//	** [sqlite3_backup_finish()].
//	**
//	** See Also: [Using the SQLite Online Backup API]
//	*/
type Tsqlite3_backup = struct {
	FpDestDb     uintptr
	FpDest       uintptr
	FiDestSchema Tu32
	FbDestLocked int32
	FiNext       TPgno
	FpSrcDb      uintptr
	FpSrc        uintptr
	Frc          int32
	FnRemaining  TPgno
	FnPagecount  TPgno
	FisAttached  int32
	FpNext       uintptr
}

type sqlite3_backup = Tsqlite3_backup

// C documentation
//
//	/*
//	** CAPI3REF: Database Snapshot
//	** KEYWORDS: {snapshot} {sqlite3_snapshot}
//	**
//	** An instance of the snapshot object records the state of a [WAL mode]
//	** database for some specific point in history.
//	**
//	** In [WAL mode], multiple [database connections] that are open on the
//	** same database file can each be reading a different historical version
//	** of the database file.  When a [database connection] begins a read
//	** transaction, that connection sees an unchanging copy of the database
//	** as it existed for the point in time when the transaction first started.
//	** Subsequent changes to the database from other connections are not seen
//	** by the reader until a new read transaction is started.
//	**
//	** The sqlite3_snapshot object records state information about an historical
//	** version of the database file so that it is possible to later open a new read
//	** transaction that sees that historical version of the database rather than
//	** the most recent version.
//	*/
type Tsqlite3_snapshot = struct {
	Fhidden [48]uint8
}

type sqlite3_snapshot = Tsqlite3_snapshot

/*
** CAPI3REF: Flags for sqlite3_deserialize()
**
** The following are allowed values for 6th argument (the F argument) to
** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
**
** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
** in the P argument is held in memory obtained from [sqlite3_malloc64()]
** and that SQLite should take ownership of this memory and automatically
** free it when it has finished using it.  Without this flag, the caller
** is responsible for freeing any dynamically allocated memory.
**
** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to
** grow the size of the database using calls to [sqlite3_realloc64()].  This
** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.
** Without this flag, the deserialized database cannot increase in size beyond
** the number of bytes specified by the M parameter.
**
** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database
** should be treated as read-only.
 */

/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
 */

/******** Begin file sqlite3rtree.h *********/
/*
** 2010 August 30
**
** 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.
**
*************************************************************************
 */

type Tsqlite3_rtree_geometry = struct {
	FpContext uintptr
	FnParam   int32
	FaParam   uintptr
	FpUser    uintptr
	FxDelUser uintptr
}

type sqlite3_rtree_geometry = Tsqlite3_rtree_geometry

type Tsqlite3_rtree_query_info = struct {
	F__ccgo_align  [0]uint32
	FpContext      uintptr
	FnParam        int32
	FaParam        uintptr
	FpUser         uintptr
	FxDelUser      uintptr
	FaCoord        uintptr
	FanQueue       uintptr
	FnCoord        int32
	FiLevel        int32
	FmxLevel       int32
	FiRowid        Tsqlite3_int64
	FrParentScore  Tsqlite3_rtree_dbl
	FeParentWithin int32
	FeWithin       int32
	FrScore        Tsqlite3_rtree_dbl
	FapSqlParam    uintptr
	F__ccgo_pad16  [4]byte
}

type sqlite3_rtree_query_info = Tsqlite3_rtree_query_info

// C documentation
//
//	/* The double-precision datatype used by RTree depends on the
//	** SQLITE_RTREE_INT_ONLY compile-time option.
//	*/
type Tsqlite3_rtree_dbl = float64

type sqlite3_rtree_dbl = Tsqlite3_rtree_dbl

/*
** A pointer to a structure of the following type is passed as the first
** argument to callbacks registered using rtree_geometry_callback().
 */
type Tsqlite3_rtree_geometry1 = struct {
	FpContext uintptr
	FnParam   int32
	FaParam   uintptr
	FpUser    uintptr
	FxDelUser uintptr
}

type sqlite3_rtree_geometry1 = Tsqlite3_rtree_geometry1

/*
** A pointer to a structure of the following type is passed as the
** argument to scored geometry callback registered using
** sqlite3_rtree_query_callback().
**
** Note that the first 5 fields of this structure are identical to
** sqlite3_rtree_geometry.  This structure is a subclass of
** sqlite3_rtree_geometry.
 */
type Tsqlite3_rtree_query_info1 = struct {
	F__ccgo_align  [0]uint32
	FpContext      uintptr
	FnParam        int32
	FaParam        uintptr
	FpUser         uintptr
	FxDelUser      uintptr
	FaCoord        uintptr
	FanQueue       uintptr
	FnCoord        int32
	FiLevel        int32
	FmxLevel       int32
	FiRowid        Tsqlite3_int64
	FrParentScore  Tsqlite3_rtree_dbl
	FeParentWithin int32
	FeWithin       int32
	FrScore        Tsqlite3_rtree_dbl
	FapSqlParam    uintptr
	F__ccgo_pad16  [4]byte
}

type sqlite3_rtree_query_info1 = Tsqlite3_rtree_query_info1

/*
** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
 */

/******** End of sqlite3rtree.h *********/
/******** Begin file sqlite3session.h *********/

/*
** Make sure we can call this stuff from C++.
 */

// C documentation
//
//	/*
//	** CAPI3REF: Session Object Handle
//	**
//	** An instance of this object is a [session] that can be used to
//	** record changes to a database.
//	*/
type Tsqlite3_session = struct {
	F__ccgo_align      [0]uint32
	Fdb                uintptr
	FzDb               uintptr
	FbEnableSize       int32
	FbEnable           int32
	FbIndirect         int32
	FbAutoAttach       int32
	FbImplicitPK       int32
	Frc                int32
	FpFilterCtx        uintptr
	FxTableFilter      uintptr
	FnMalloc           Ti64
	FnMaxChangesetSize Ti64
	FpZeroBlob         uintptr
	FpNext             uintptr
	FpTable            uintptr
	Fhook              TSessionHook
}

type sqlite3_session = Tsqlite3_session

// C documentation
//
//	/*
//	** CAPI3REF: Changeset Iterator Handle
//	**
//	** An instance of this object acts as a cursor for iterating
//	** over the elements of a [changeset] or [patchset].
//	*/
type Tsqlite3_changeset_iter = struct {
	Fin         TSessionInput
	Ftblhdr     TSessionBuffer
	FbPatchset  int32
	FbInvert    int32
	FbSkipEmpty int32
	Frc         int32
	FpConflict  uintptr
	FzTab       uintptr
	FnCol       int32
	Fop         int32
	FbIndirect  int32
	FabPK       uintptr
	FapValue    uintptr
}

type sqlite3_changeset_iter = Tsqlite3_changeset_iter

// C documentation
//
//	/*
//	** CAPI3REF: Changegroup Handle
//	**
//	** A changegroup is an object used to combine two or more
//	** [changesets] or [patchsets]
//	*/
type Tsqlite3_changegroup = struct {
	Frc     int32
	FbPatch int32
	FpList  uintptr
	Frec    TSessionBuffer
	Fdb     uintptr
	FzDb    uintptr
}

type sqlite3_changegroup = Tsqlite3_changegroup

/*
** CAPI3REF: Flags for sqlite3changeset_apply_v2
**
** The following flags may passed via the 9th parameter to
** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
**
** <dl>
** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
**   Usually, the sessions module encloses all operations performed by
**   a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
**   SAVEPOINT is committed if the changeset or patchset is successfully
**   applied, or rolled back if an error occurs. Specifying this flag
**   causes the sessions module to omit this savepoint. In this case, if the
**   caller has an open transaction or savepoint when apply_v2() is called,
**   it may revert the partially applied changeset by rolling it back.
**
** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
**   Invert the changeset before applying it. This is equivalent to inverting
**   a changeset using sqlite3changeset_invert() before applying it. It is
**   an error to specify this flag with a patchset.
**
** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd>
**   Do not invoke the conflict handler callback for any changes that
**   would not actually modify the database even if they were applied.
**   Specifically, this means that the conflict handler is not invoked
**   for:
**    <ul>
**    <li>a delete change if the row being deleted cannot be found,
**    <li>an update change if the modified fields are already set to
**        their new values in the conflicting row, or
**    <li>an insert change if all fields of the conflicting row match
**        the row being inserted.
**    </ul>
**
** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd>
**   If this flag it set, then all foreign key constraints in the target
**   database behave as if they were declared with "ON UPDATE NO ACTION ON
**   DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL
**   or SET DEFAULT.
 */

/*
** CAPI3REF: Constants Passed To The Conflict Handler
**
** Values that may be passed as the second argument to a conflict-handler.
**
** <dl>
** <dt>SQLITE_CHANGESET_DATA<dd>
**   The conflict handler is invoked with CHANGESET_DATA as the second argument
**   when processing a DELETE or UPDATE change if a row with the required
**   PRIMARY KEY fields is present in the database, but one or more other
**   (non primary-key) fields modified by the update do not contain the
**   expected "before" values.
**
**   The conflicting row, in this case, is the database row with the matching
**   primary key.
**
** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
**   The conflict handler is invoked with CHANGESET_NOTFOUND as the second
**   argument when processing a DELETE or UPDATE change if a row with the
**   required PRIMARY KEY fields is not present in the database.
**
**   There is no conflicting row in this case. The results of invoking the
**   sqlite3changeset_conflict() API are undefined.
**
** <dt>SQLITE_CHANGESET_CONFLICT<dd>
**   CHANGESET_CONFLICT is passed as the second argument to the conflict
**   handler while processing an INSERT change if the operation would result
**   in duplicate primary key values.
**
**   The conflicting row in this case is the database row with the matching
**   primary key.
**
** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
**   If foreign key handling is enabled, and applying a changeset leaves the
**   database in a state containing foreign key violations, the conflict
**   handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
**   exactly once before the changeset is committed. If the conflict handler
**   returns CHANGESET_OMIT, the changes, including those that caused the
**   foreign key constraint violation, are committed. Or, if it returns
**   CHANGESET_ABORT, the changeset is rolled back.
**
**   No current or conflicting row information is provided. The only function
**   it is possible to call on the supplied sqlite3_changeset_iter handle
**   is sqlite3changeset_fk_conflicts().
**
** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
**   If any other constraint violation occurs while applying a change (i.e.
**   a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
**   invoked with CHANGESET_CONSTRAINT as the second argument.
**
**   There is no conflicting row in this case. The results of invoking the
**   sqlite3changeset_conflict() API are undefined.
**
** </dl>
 */

/*
** CAPI3REF: Constants Returned By The Conflict Handler
**
** A conflict handler callback must return one of the following three values.
**
** <dl>
** <dt>SQLITE_CHANGESET_OMIT<dd>
**   If a conflict handler returns this value no special action is taken. The
**   change that caused the conflict is not applied. The session module
**   continues to the next change in the changeset.
**
** <dt>SQLITE_CHANGESET_REPLACE<dd>
**   This value may only be returned if the second argument to the conflict
**   handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
**   is not the case, any changes applied so far are rolled back and the
**   call to sqlite3changeset_apply() returns SQLITE_MISUSE.
**
**   If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
**   handler, then the conflicting row is either updated or deleted, depending
**   on the type of change.
**
**   If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
**   handler, then the conflicting row is removed from the database and a
**   second attempt to apply the change is made. If this second attempt fails,
**   the original row is restored to the database before continuing.
**
** <dt>SQLITE_CHANGESET_ABORT<dd>
**   If this value is returned, any changes applied so far are rolled back
**   and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
** </dl>
 */

// C documentation
//
//	/*
//	** CAPI3REF: Rebasing changesets
//	** EXPERIMENTAL
//	**
//	** Suppose there is a site hosting a database in state S0. And that
//	** modifications are made that move that database to state S1 and a
//	** changeset recorded (the "local" changeset). Then, a changeset based
//	** on S0 is received from another site (the "remote" changeset) and
//	** applied to the database. The database is then in state
//	** (S1+"remote"), where the exact state depends on any conflict
//	** resolution decisions (OMIT or REPLACE) made while applying "remote".
//	** Rebasing a changeset is to update it to take those conflict
//	** resolution decisions into account, so that the same conflicts
//	** do not have to be resolved elsewhere in the network.
//	**
//	** For example, if both the local and remote changesets contain an
//	** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
//	**
//	**   local:  INSERT INTO t1 VALUES(1, 'v1');
//	**   remote: INSERT INTO t1 VALUES(1, 'v2');
//	**
//	** and the conflict resolution is REPLACE, then the INSERT change is
//	** removed from the local changeset (it was overridden). Or, if the
//	** conflict resolution was "OMIT", then the local changeset is modified
//	** to instead contain:
//	**
//	**           UPDATE t1 SET b = 'v2' WHERE a=1;
//	**
//	** Changes within the local changeset are rebased as follows:
//	**
//	** <dl>
//	** <dt>Local INSERT<dd>
//	**   This may only conflict with a remote INSERT. If the conflict
//	**   resolution was OMIT, then add an UPDATE change to the rebased
//	**   changeset. Or, if the conflict resolution was REPLACE, add
//	**   nothing to the rebased changeset.
//	**
//	** <dt>Local DELETE<dd>
//	**   This may conflict with a remote UPDATE or DELETE. In both cases the
//	**   only possible resolution is OMIT. If the remote operation was a
//	**   DELETE, then add no change to the rebased changeset. If the remote
//	**   operation was an UPDATE, then the old.* fields of change are updated
//	**   to reflect the new.* values in the UPDATE.
//	**
//	** <dt>Local UPDATE<dd>
//	**   This may conflict with a remote UPDATE or DELETE. If it conflicts
//	**   with a DELETE, and the conflict resolution was OMIT, then the update
//	**   is changed into an INSERT. Any undefined values in the new.* record
//	**   from the update change are filled in using the old.* values from
//	**   the conflicting DELETE. Or, if the conflict resolution was REPLACE,
//	**   the UPDATE change is simply omitted from the rebased changeset.
//	**
//	**   If conflict is with a remote UPDATE and the resolution is OMIT, then
//	**   the old.* values are rebased using the new.* values in the remote
//	**   change. Or, if the resolution is REPLACE, then the change is copied
//	**   into the rebased changeset with updates to columns also updated by
//	**   the conflicting remote UPDATE removed. If this means no columns would
//	**   be updated, the change is omitted.
//	** </dl>
//	**
//	** A local change may be rebased against multiple remote changes
//	** simultaneously. If a single key is modified by multiple remote
//	** changesets, they are combined as follows before the local changeset
//	** is rebased:
//	**
//	** <ul>
//	**    <li> If there has been one or more REPLACE resolutions on a
//	**         key, it is rebased according to a REPLACE.
//	**
//	**    <li> If there have been no REPLACE resolutions on a key, then
//	**         the local changeset is rebased according to the most recent
//	**         of the OMIT resolutions.
//	** </ul>
//	**
//	** Note that conflict resolutions from multiple remote changesets are
//	** combined on a per-field basis, not per-row. This means that in the
//	** case of multiple remote UPDATE operations, some fields of a single
//	** local change may be rebased for REPLACE while others are rebased for
//	** OMIT.
//	**
//	** In order to rebase a local changeset, the remote changeset must first
//	** be applied to the local database using sqlite3changeset_apply_v2() and
//	** the buffer of rebase information captured. Then:
//	**
//	** <ol>
//	**   <li> An sqlite3_rebaser object is created by calling
//	**        sqlite3rebaser_create().
//	**   <li> The new object is configured with the rebase buffer obtained from
//	**        sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
//	**        If the local changeset is to be rebased against multiple remote
//	**        changesets, then sqlite3rebaser_configure() should be called
//	**        multiple times, in the same order that the multiple
//	**        sqlite3changeset_apply_v2() calls were made.
//	**   <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().
//	**   <li> The sqlite3_rebaser object is deleted by calling
//	**        sqlite3rebaser_delete().
//	** </ol>
//	*/
type Tsqlite3_rebaser = struct {
	Fgrp Tsqlite3_changegroup
}

type sqlite3_rebaser = Tsqlite3_rebaser

/*
** CAPI3REF: Values for sqlite3session_config().
 */

/*
** Make sure we can call this stuff from C++.
 */

/******** End of sqlite3session.h *********/
/******** Begin file fts5.h *********/
/*
** 2014 May 31
**
** 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.
**
******************************************************************************
**
** Interfaces to extend FTS5. Using the interfaces defined in this file,
** FTS5 may be extended with:
**
**     * custom tokenizers, and
**     * custom auxiliary functions.
 */

/*************************************************************************
** CUSTOM AUXILIARY FUNCTIONS
**
** Virtual table implementations may overload SQL functions by implementing
** the sqlite3_module.xFindFunction() method.
 */

type TFts5ExtensionApi = struct {
	FiVersion           int32
	FxUserData          uintptr
	FxColumnCount       uintptr
	FxRowCount          uintptr
	FxColumnTotalSize   uintptr
	FxTokenize          uintptr
	FxPhraseCount       uintptr
	FxPhraseSize        uintptr
	FxInstCount         uintptr
	FxInst              uintptr
	FxRowid             uintptr
	FxColumnText        uintptr
	FxColumnSize        uintptr
	FxQueryPhrase       uintptr
	FxSetAuxdata        uintptr
	FxGetAuxdata        uintptr
	FxPhraseFirst       uintptr
	FxPhraseNext        uintptr
	FxPhraseFirstColumn uintptr
	FxPhraseNextColumn  uintptr
	FxQueryToken        uintptr
	FxInstToken         uintptr
}

type Fts5ExtensionApi = TFts5ExtensionApi

type TFts5PhraseIter = struct {
	Fa uintptr
	Fb uintptr
}

type Fts5PhraseIter = TFts5PhraseIter

type Tfts5_extension_function = uintptr

type fts5_extension_function = Tfts5_extension_function

type TFts5PhraseIter1 = struct {
	Fa uintptr
	Fb uintptr
}

type Fts5PhraseIter1 = TFts5PhraseIter1

/*
** EXTENSION API FUNCTIONS
**
** xUserData(pFts):
**   Return a copy of the pUserData pointer passed to the xCreateFunction()
**   API when the extension function was registered.
**
** xColumnTotalSize(pFts, iCol, pnToken):
**   If parameter iCol is less than zero, set output variable *pnToken
**   to the total number of tokens in the FTS5 table. Or, if iCol is
**   non-negative but less than the number of columns in the table, return
**   the total number of tokens in column iCol, considering all rows in
**   the FTS5 table.
**
**   If parameter iCol is greater than or equal to the number of columns
**   in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
**   an OOM condition or IO error), an appropriate SQLite error code is
**   returned.
**
** xColumnCount(pFts):
**   Return the number of columns in the table.
**
** xColumnSize(pFts, iCol, pnToken):
**   If parameter iCol is less than zero, set output variable *pnToken
**   to the total number of tokens in the current row. Or, if iCol is
**   non-negative but less than the number of columns in the table, set
**   *pnToken to the number of tokens in column iCol of the current row.
**
**   If parameter iCol is greater than or equal to the number of columns
**   in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
**   an OOM condition or IO error), an appropriate SQLite error code is
**   returned.
**
**   This function may be quite inefficient if used with an FTS5 table
**   created with the "columnsize=0" option.
**
** xColumnText:
**   If parameter iCol is less than zero, or greater than or equal to the
**   number of columns in the table, SQLITE_RANGE is returned.
**
**   Otherwise, this function attempts to retrieve the text of column iCol of
**   the current document. If successful, (*pz) is set to point to a buffer
**   containing the text in utf-8 encoding, (*pn) is set to the size in bytes
**   (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
**   if an error occurs, an SQLite error code is returned and the final values
**   of (*pz) and (*pn) are undefined.
**
** xPhraseCount:
**   Returns the number of phrases in the current query expression.
**
** xPhraseSize:
**   If parameter iCol is less than zero, or greater than or equal to the
**   number of phrases in the current query, as returned by xPhraseCount,
**   0 is returned. Otherwise, this function returns the number of tokens in
**   phrase iPhrase of the query. Phrases are numbered starting from zero.
**
** xInstCount:
**   Set *pnInst to the total number of occurrences of all phrases within
**   the query within the current row. Return SQLITE_OK if successful, or
**   an error code (i.e. SQLITE_NOMEM) if an error occurs.
**
**   This API can be quite slow if used with an FTS5 table created with the
**   "detail=none" or "detail=column" option. If the FTS5 table is created
**   with either "detail=none" or "detail=column" and "content=" option
**   (i.e. if it is a contentless table), then this API always returns 0.
**
** xInst:
**   Query for the details of phrase match iIdx within the current row.
**   Phrase matches are numbered starting from zero, so the iIdx argument
**   should be greater than or equal to zero and smaller than the value
**   output by xInstCount(). If iIdx is less than zero or greater than
**   or equal to the value returned by xInstCount(), SQLITE_RANGE is returned.
**
**   Otherwise, output parameter *piPhrase is set to the phrase number, *piCol
**   to the column in which it occurs and *piOff the token offset of the
**   first token of the phrase. SQLITE_OK is returned if successful, or an
**   error code (i.e. SQLITE_NOMEM) if an error occurs.
**
**   This API can be quite slow if used with an FTS5 table created with the
**   "detail=none" or "detail=column" option.
**
** xRowid:
**   Returns the rowid of the current row.
**
** xTokenize:
**   Tokenize text using the tokenizer belonging to the FTS5 table.
**
** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
**   This API function is used to query the FTS table for phrase iPhrase
**   of the current query. Specifically, a query equivalent to:
**
**       ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
**
**   with $p set to a phrase equivalent to the phrase iPhrase of the
**   current query is executed. Any column filter that applies to
**   phrase iPhrase of the current query is included in $p. For each
**   row visited, the callback function passed as the fourth argument
**   is invoked. The context and API objects passed to the callback
**   function may be used to access the properties of each matched row.
**   Invoking Api.xUserData() returns a copy of the pointer passed as
**   the third argument to pUserData.
**
**   If parameter iPhrase is less than zero, or greater than or equal to
**   the number of phrases in the query, as returned by xPhraseCount(),
**   this function returns SQLITE_RANGE.
**
**   If the callback function returns any value other than SQLITE_OK, the
**   query is abandoned and the xQueryPhrase function returns immediately.
**   If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
**   Otherwise, the error code is propagated upwards.
**
**   If the query runs to completion without incident, SQLITE_OK is returned.
**   Or, if some error occurs before the query completes or is aborted by
**   the callback, an SQLite error code is returned.
**
**
** xSetAuxdata(pFts5, pAux, xDelete)
**
**   Save the pointer passed as the second argument as the extension function's
**   "auxiliary data". The pointer may then be retrieved by the current or any
**   future invocation of the same fts5 extension function made as part of
**   the same MATCH query using the xGetAuxdata() API.
**
**   Each extension function is allocated a single auxiliary data slot for
**   each FTS query (MATCH expression). If the extension function is invoked
**   more than once for a single FTS query, then all invocations share a
**   single auxiliary data context.
**
**   If there is already an auxiliary data pointer when this function is
**   invoked, then it is replaced by the new pointer. If an xDelete callback
**   was specified along with the original pointer, it is invoked at this
**   point.
**
**   The xDelete callback, if one is specified, is also invoked on the
**   auxiliary data pointer after the FTS5 query has finished.
**
**   If an error (e.g. an OOM condition) occurs within this function,
**   the auxiliary data is set to NULL and an error code returned. If the
**   xDelete parameter was not NULL, it is invoked on the auxiliary data
**   pointer before returning.
**
**
** xGetAuxdata(pFts5, bClear)
**
**   Returns the current auxiliary data pointer for the fts5 extension
**   function. See the xSetAuxdata() method for details.
**
**   If the bClear argument is non-zero, then the auxiliary data is cleared
**   (set to NULL) before this function returns. In this case the xDelete,
**   if any, is not invoked.
**
**
** xRowCount(pFts5, pnRow)
**
**   This function is used to retrieve the total number of rows in the table.
**   In other words, the same value that would be returned by:
**
**        SELECT count(*) FROM ftstable;
**
** xPhraseFirst()
**   This function is used, along with type Fts5PhraseIter and the xPhraseNext
**   method, to iterate through all instances of a single query phrase within
**   the current row. This is the same information as is accessible via the
**   xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
**   to use, this API may be faster under some circumstances. To iterate
**   through instances of phrase iPhrase, use the following code:
**
**       Fts5PhraseIter iter;
**       int iCol, iOff;
**       for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
**           iCol>=0;
**           pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
**       ){
**         // An instance of phrase iPhrase at offset iOff of column iCol
**       }
**
**   The Fts5PhraseIter structure is defined above. Applications should not
**   modify this structure directly - it should only be used as shown above
**   with the xPhraseFirst() and xPhraseNext() API methods (and by
**   xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
**
**   This API can be quite slow if used with an FTS5 table created with the
**   "detail=none" or "detail=column" option. If the FTS5 table is created
**   with either "detail=none" or "detail=column" and "content=" option
**   (i.e. if it is a contentless table), then this API always iterates
**   through an empty set (all calls to xPhraseFirst() set iCol to -1).
**
** xPhraseNext()
**   See xPhraseFirst above.
**
** xPhraseFirstColumn()
**   This function and xPhraseNextColumn() are similar to the xPhraseFirst()
**   and xPhraseNext() APIs described above. The difference is that instead
**   of iterating through all instances of a phrase in the current row, these
**   APIs are used to iterate through the set of columns in the current row
**   that contain one or more instances of a specified phrase. For example:
**
**       Fts5PhraseIter iter;
**       int iCol;
**       for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
**           iCol>=0;
**           pApi->xPhraseNextColumn(pFts, &iter, &iCol)
**       ){
**         // Column iCol contains at least one instance of phrase iPhrase
**       }
**
**   This API can be quite slow if used with an FTS5 table created with the
**   "detail=none" option. If the FTS5 table is created with either
**   "detail=none" "content=" option (i.e. if it is a contentless table),
**   then this API always iterates through an empty set (all calls to
**   xPhraseFirstColumn() set iCol to -1).
**
**   The information accessed using this API and its companion
**   xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
**   (or xInst/xInstCount). The chief advantage of this API is that it is
**   significantly more efficient than those alternatives when used with
**   "detail=column" tables.
**
** xPhraseNextColumn()
**   See xPhraseFirstColumn above.
**
** xQueryToken(pFts5, iPhrase, iToken, ppToken, pnToken)
**   This is used to access token iToken of phrase iPhrase of the current
**   query. Before returning, output parameter *ppToken is set to point
**   to a buffer containing the requested token, and *pnToken to the
**   size of this buffer in bytes.
**
**   If iPhrase or iToken are less than zero, or if iPhrase is greater than
**   or equal to the number of phrases in the query as reported by
**   xPhraseCount(), or if iToken is equal to or greater than the number of
**   tokens in the phrase, SQLITE_RANGE is returned and *ppToken and *pnToken

	are both zeroed.

**
**   The output text is not a copy of the query text that specified the
**   token. It is the output of the tokenizer module. For tokendata=1
**   tables, this includes any embedded 0x00 and trailing data.
**
** xInstToken(pFts5, iIdx, iToken, ppToken, pnToken)
**   This is used to access token iToken of phrase hit iIdx within the
**   current row. If iIdx is less than zero or greater than or equal to the
**   value returned by xInstCount(), SQLITE_RANGE is returned.  Otherwise,
**   output variable (*ppToken) is set to point to a buffer containing the
**   matching document token, and (*pnToken) to the size of that buffer in
**   bytes. This API is not available if the specified token matches a
**   prefix query term. In that case both output variables are always set
**   to 0.
**
**   The output text is not a copy of the document text that was tokenized.
**   It is the output of the tokenizer module. For tokendata=1 tables, this
**   includes any embedded 0x00 and trailing data.
**
**   This API can be quite slow if used with an FTS5 table created with the
**   "detail=none" or "detail=column" option.
*/
type TFts5ExtensionApi1 = struct {
	FiVersion           int32
	FxUserData          uintptr
	FxColumnCount       uintptr
	FxRowCount          uintptr
	FxColumnTotalSize   uintptr
	FxTokenize          uintptr
	FxPhraseCount       uintptr
	FxPhraseSize        uintptr
	FxInstCount         uintptr
	FxInst              uintptr
	FxRowid             uintptr
	FxColumnText        uintptr
	FxColumnSize        uintptr
	FxQueryPhrase       uintptr
	FxSetAuxdata        uintptr
	FxGetAuxdata        uintptr
	FxPhraseFirst       uintptr
	FxPhraseNext        uintptr
	FxPhraseFirstColumn uintptr
	FxPhraseNextColumn  uintptr
	FxQueryToken        uintptr
	FxInstToken         uintptr
}

type Fts5ExtensionApi1 = TFts5ExtensionApi1

type Tfts5_tokenizer = struct {
	FxCreate   uintptr
	FxDelete   uintptr
	FxTokenize uintptr
}

type fts5_tokenizer = Tfts5_tokenizer

type Tfts5_tokenizer1 = struct {
	FxCreate   uintptr
	FxDelete   uintptr
	FxTokenize uintptr
}

type fts5_tokenizer1 = Tfts5_tokenizer1

/* Flags that may be passed as the third argument to xTokenize() */

/* Flags that may be passed by the tokenizer implementation back to FTS5
** as the third argument to the supplied xToken callback. */

/*
** END OF CUSTOM TOKENIZERS
*************************************************************************/

// C documentation
//
//	/*************************************************************************
//	** FTS5 EXTENSION REGISTRATION API
//	*/
type Tfts5_api = struct {
	FiVersion         int32
	FxCreateTokenizer uintptr
	FxFindTokenizer   uintptr
	FxCreateFunction  uintptr
}

type fts5_api = Tfts5_api

type Tfts5_api1 = struct {
	FiVersion         int32
	FxCreateTokenizer uintptr
	FxFindTokenizer   uintptr
	FxCreateFunction  uintptr
}

type fts5_api1 = Tfts5_api1

/*
** END OF REGISTRATION API
*************************************************************************/

/******** End of fts5.h *********/

/************** End of sqlite3.h *********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/

/*
** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory.
 */

/*
** Include the configuration header output by 'configure' if we're using the
** autoconf-based build
 */

/************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
/************** Begin file sqliteLimit.h *************************************/
/*
** 2007 May 7
**
** 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 defines various limits of what SQLite can process.
 */

/*
** The maximum length of a TEXT or BLOB in bytes.   This also
** limits the size of a row in a table or index.
**
** The hard limit is the ability of a 32-bit signed integer
** to count the size: 2^31-1 or 2147483647.
 */

/*
** This is the maximum number of
**
**    * Columns in a table
**    * Columns in an index
**    * Columns in a view
**    * Terms in the SET clause of an UPDATE statement
**    * Terms in the result set of a SELECT statement
**    * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
**    * Terms in the VALUES clause of an INSERT statement
**
** The hard upper limit here is 32676.  Most database people will
** tell you that in a well-normalized database, you usually should
** not have more than a dozen or so columns in any table.  And if
** that is the case, there is no point in having more than a few
** dozen values in any of the other situations described above.
 */

/*
** The maximum length of a single SQL statement in bytes.
**
** It used to be the case that setting this value to zero would
** turn the limit off.  That is no longer true.  It is not possible
** to turn this limit off.
 */

/*
** The maximum depth of an expression tree. This is limited to
** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
** want to place more severe limits on the complexity of an
** expression. A value of 0 means that there is no limit.
 */

/*
** The maximum number of terms in a compound SELECT statement.
** The code generator for compound SELECT statements does one
** level of recursion for each term.  A stack overflow can result
** if the number of terms is too large.  In practice, most SQL
** never has more than 3 or 4 terms.  Use a value of 0 to disable
** any limit on the number of terms in a compound SELECT.
 */

/*
** The maximum number of opcodes in a VDBE program.
** Not currently enforced.
 */

/*
** The maximum number of arguments to an SQL function.
 */

/*
** The suggested maximum number of in-memory pages to use for
** the main database table and for temporary tables.
**
** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000,
** which means the cache size is limited to 2048000 bytes of memory.
** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
 */

/*
** The default number of frames to accumulate in the log file before
** checkpointing the database in WAL mode.
 */

/*
** The maximum number of attached databases.  This must be between 0
** and 125.  The upper bound of 125 is because the attached databases are
** counted using a signed 8-bit integer which has a maximum value of 127
** and we have to allow 2 extra counts for the "main" and "temp" databases.
 */

/*
** The maximum value of a ?nnn wildcard that the parser will accept.
** If the value exceeds 32767 then extra space is required for the Expr
** structure.  But otherwise, we believe that the number can be as large
** as a signed 32-bit integer can hold.
 */

/* Maximum page size.  The upper bound on this value is 65536.  This a limit
** imposed by the use of 16-bit offsets within each page.
**
** Earlier versions of SQLite allowed the user to change this value at
** compile time. This is no longer permitted, on the grounds that it creates
** a library that is technically incompatible with an SQLite library
** compiled with a different limit. If a process operating on a database
** with a page-size of 65536 bytes crashes, then an instance of SQLite
** compiled with the default page-size limit will not be able to rollback
** the aborted transaction. This could lead to database corruption.
 */

/*
** The default size of a database page.
 */

/*
** Ordinarily, if no value is explicitly provided, SQLite creates databases
** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
** device characteristics (sector-size and atomic write() support),
** SQLite may choose a larger value. This constant is the maximum value
** SQLite will choose on its own.
 */

/*
** Maximum number of pages in one database file.
**
** This is really just the default value for the max_page_count pragma.
** This value can be lowered (or raised) at run-time using that the
** max_page_count macro.
 */

/*
** Maximum length (in bytes) of the pattern in a LIKE or GLOB
** operator.
 */

/*
** Maximum depth of recursion for triggers.
**
** A value of 1 means that a trigger program will not be able to itself
** fire any triggers. A value of 0 means that no trigger programs at all
** may be executed.
 */

/************** End of sqliteLimit.h *****************************************/
/************** Continuing where we left off in sqliteInt.h ******************/

/* Disable nuisance warnings on Borland compilers */

/*
** A few places in the code require atomic load/store of aligned
** integer values.
 */

/*
** Include standard header files as necessary
 */

/*
** The following macros are used to cast pointers to integers and
** integers to pointers.  The way you do this varies from one compiler
** to the next, so we have developed the following set of #if statements
** to generate appropriate macros for a wide range of compilers.
**
** The correct "ANSI" way to do this is to use the intptr_t type.
** Unfortunately, that typedef is not available on all compilers, or
** if it is available, it requires an #include of specific headers
** that vary from one machine to the next.
**
** Ticket #3860:  The llvm-gcc-4.2 compiler from Apple chokes on
** the ((void*)&((char*)0)[X]) construct.  But MSVC chokes on ((void*)(X)).
** So we have to define the macros in different ways depending on the
** compiler.
 */

/*
** Macros to hint to the compiler that a function should or should not be
** inlined.
 */

/*
** Make sure that the compiler intrinsics we desire are enabled when
** compiling with an appropriate version of MSVC unless prevented by
** the SQLITE_DISABLE_INTRINSIC define.
 */

/*
** Enable SQLITE_USE_SEH by default on MSVC builds.  Only omit
** SEH support if the -DSQLITE_OMIT_SEH option is given.
 */

/*
** Enable SQLITE_DIRECT_OVERFLOW_READ, unless the build explicitly
** disables it using -DSQLITE_DIRECT_OVERFLOW_READ=0
 */
/* In all other cases, enable */

/*
** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
** 0 means mutexes are permanently disable and the library is never
** threadsafe.  1 means the library is serialized which is the highest
** level of threadsafety.  2 means the library is multithreaded - multiple
** threads can use SQLite as long as no two threads try to use the same
** database connection at the same time.
**
** Older versions of SQLite used an optional THREADSAFE macro.
** We support that for legacy.
**
** To ensure that the correct value of "THREADSAFE" is reported when querying
** for compile-time options at runtime (e.g. "PRAGMA compile_options"), this
** logic is partially replicated in ctime.c. If it is updated here, it should
** also be updated there.
 */

/*
** Powersafe overwrite is on by default.  But can be turned off using
** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option.
 */

/*
** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
** which case memory allocation statistics are disabled by default.
 */

/*
** Exactly one of the following macros must be defined in order to
** specify which memory allocation subsystem to use.
**
**     SQLITE_SYSTEM_MALLOC          // Use normal system malloc()
**     SQLITE_WIN32_MALLOC           // Use Win32 native heap API
**     SQLITE_ZERO_MALLOC            // Use a stub allocator that always fails
**     SQLITE_MEMDEBUG               // Debugging version of system malloc()
**
** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the
** assert() macro is enabled, each call into the Win32 native heap subsystem
** will cause HeapValidate to be called.  If heap validation should fail, an
** assertion will be triggered.
**
** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
** the default.
 */

/*
** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
** sizes of memory allocations below this value where possible.
 */

/*
** We need to define _XOPEN_SOURCE as follows in order to enable
** recursive mutexes on most Unix systems and fchmod() on OpenBSD.
** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit
** it.
 */

/*
** NDEBUG and SQLITE_DEBUG are opposites.  It should always be true that
** defined(NDEBUG)==!defined(SQLITE_DEBUG).  If this is not currently true,
** make it true by defining or undefining NDEBUG.
**
** Setting NDEBUG makes the code smaller and faster by disabling the
** assert() statements in the code.  So we want the default action
** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG
** is set.  Thus NDEBUG becomes an opt-in rather than an opt-out
** feature.
 */

/*
** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on.
 */

/*
** The testcase() macro is used to aid in coverage testing.  When
** doing coverage testing, the condition inside the argument to
** testcase() must be evaluated both true and false in order to
** get full branch coverage.  The testcase() macro is inserted
** to help ensure adequate test coverage in places where simple
** condition/decision coverage is inadequate.  For example, testcase()
** can be used to make sure boundary values are tested.  For
** bitmask tests, testcase() can be used to make sure each bit
** is significant and used at least once.  On switch statements
** where multiple cases go to the same block of code, testcase()
** can insure that all cases are evaluated.
 */

/*
** The TESTONLY macro is used to enclose variable declarations or
** other bits of code that are needed to support the arguments
** within testcase() and assert() macros.
 */

/*
** Sometimes we need a small amount of code such as a variable initialization
** to setup for a later assert() statement.  We do not want this code to
** appear when assert() is disabled.  The following macro is therefore
** used to contain that setup code.  The "VVA" acronym stands for
** "Verification, Validation, and Accreditation".  In other words, the
** code within VVA_ONLY() will only run during verification processes.
 */

/*
** Disable ALWAYS() and NEVER() (make them pass-throughs) for coverage
** and mutation testing
 */

/*
** The ALWAYS and NEVER macros surround boolean expressions which
** are intended to always be true or false, respectively.  Such
** expressions could be omitted from the code completely.  But they
** are included in a few cases in order to enhance the resilience
** of SQLite to unexpected behavior - to make the code "self-healing"
** or "ductile" rather than being "brittle" and crashing at the first
** hint of unplanned behavior.
**
** In other words, ALWAYS and NEVER are added for defensive code.
**
** When doing coverage testing ALWAYS and NEVER are hard-coded to
** be true and false so that the unreachable code they specify will
** not be counted as untested code.
 */

/*
** Some conditionals are optimizations only.  In other words, if the
** conditionals are replaced with a constant 1 (true) or 0 (false) then
** the correct answer is still obtained, though perhaps not as quickly.
**
** The following macros mark these optimizations conditionals.
 */

/*
** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
** defined.  We need to defend against those failures when testing with
** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
** during a normal build.  The following macro can be used to disable tests
** that are always false except when SQLITE_TEST_REALLOC_STRESS is set.
 */

/*
** Declarations used for tracing the operating system interfaces.
 */

/*
** Is the sqlite3ErrName() function needed in the build?  Currently,
** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
** OSTRACE is enabled), and by several "test*.c" files (which are
** compiled using SQLITE_TEST).
 */

/*
** SQLITE_ENABLE_EXPLAIN_COMMENTS is incompatible with SQLITE_OMIT_EXPLAIN
 */

/*
** SQLITE_OMIT_VIRTUALTABLE implies SQLITE_OMIT_ALTERTABLE
 */

/*
** Return true (non-zero) if the input is an integer that is too large
** to fit in 32-bits.  This macro is used inside of various testcase()
** macros to verify that we have tested SQLite for large-file support.
 */

/*
** The macro unlikely() is a hint that surrounds a boolean
** expression that is usually false.  Macro likely() surrounds
** a boolean expression that is usually true.  These hints could,
** in theory, be used by the compiler to generate better code, but
** currently they are just comments for human readers.
 */

/************** Include hash.h in the middle of sqliteInt.h ******************/
/************** Begin file hash.h ********************************************/
/*
** 2001 September 22
**
** 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 is the header file for the generic hash-table implementation
** used in SQLite.
 */

// C documentation
//
//	/* Forward declarations of structures. */
type THash = struct {
	Fhtsize uint32
	Fcount  uint32
	Ffirst  uintptr
	Fht     uintptr
}

type Hash = THash

type THashElem = struct {
	Fnext uintptr
	Fprev uintptr
	Fdata uintptr
	FpKey uintptr
}

type HashElem = THashElem

/* A complete hash table is an instance of the following structure.
** The internals of this structure are intended to be opaque -- client
** code should not attempt to access or modify the fields of this structure
** directly.  Change this structure only by using the routines below.
** However, some of the "procedures" and "functions" for modifying and
** accessing this structure are really macros, so we can't really make
** this structure opaque.
**
** All elements of the hash table are on a single doubly-linked list.
** Hash.first points to the head of this list.
**
** There are Hash.htsize buckets.  Each bucket points to a spot in
** the global doubly-linked list.  The contents of the bucket are the
** element pointed to plus the next _ht.count-1 elements in the list.
**
** Hash.htsize and Hash.ht may be zero.  In that case lookup is done
** by a linear search of the global list.  For small tables, the
** Hash.ht table is never allocated because if there are few elements
** in the table, it is faster to do a linear search than to manage
** the hash table.
 */
type THash1 = struct {
	Fhtsize uint32
	Fcount  uint32
	Ffirst  uintptr
	Fht     uintptr
}

type Hash1 = THash1

/* Each element in the hash table is an instance of the following
** structure.  All elements are stored on a single doubly-linked list.
**
** Again, this structure is intended to be opaque, but it can't really
** be opaque because it is used by macros.
 */
type THashElem1 = struct {
	Fnext uintptr
	Fprev uintptr
	Fdata uintptr
	FpKey uintptr
}

type HashElem1 = THashElem1

type Tsize_t = uint32

type size_t = Tsize_t

type Tssize_t = int32

type ssize_t = Tssize_t

type Trsize_t = uint32

type rsize_t = Trsize_t

type Tintptr_t = int32

type intptr_t = Tintptr_t

type Tuintptr_t = uint32

type uintptr_t = Tuintptr_t

type Tptrdiff_t = int32

type ptrdiff_t = Tptrdiff_t

type Twchar_t = uint16

type wchar_t = Twchar_t

type Twint_t = uint16

type wint_t = Twint_t

type Twctype_t = uint16

type wctype_t = Twctype_t

type Terrno_t = int32

type errno_t = Terrno_t

type t__time32_t = int32

type t__time64_t = int64

type Ttime_t = int32

type time_t = Ttime_t

type Tthreadlocaleinfostruct = struct {
	Frefcount      int32
	Flc_codepage   uint32
	Flc_collate_cp uint32
	Flc_handle     [6]uint32
	Flc_id         [6]TLC_ID
	Flc_category   [6]struct {
		Flocale    uintptr
		Fwlocale   uintptr
		Frefcount  uintptr
		Fwrefcount uintptr
	}
	Flc_clike            int32
	Fmb_cur_max          int32
	Flconv_intl_refcount uintptr
	Flconv_num_refcount  uintptr
	Flconv_mon_refcount  uintptr
	Flconv               uintptr
	Fctype1_refcount     uintptr
	Fctype1              uintptr
	Fpctype              uintptr
	Fpclmap              uintptr
	Fpcumap              uintptr
	Flc_time_curr        uintptr
}

type threadlocaleinfostruct = Tthreadlocaleinfostruct

type Tpthreadlocinfo = uintptr

type pthreadlocinfo = Tpthreadlocinfo

type Tpthreadmbcinfo = uintptr

type pthreadmbcinfo = Tpthreadmbcinfo

type T_locale_tstruct = struct {
	Flocinfo Tpthreadlocinfo
	Fmbcinfo Tpthreadmbcinfo
}

type _locale_tstruct = T_locale_tstruct

type Tlocaleinfo_struct = T_locale_tstruct

type localeinfo_struct = Tlocaleinfo_struct

type T_locale_t = uintptr

type _locale_t = T_locale_t

type TLC_ID = struct {
	FwLanguage uint16
	FwCountry  uint16
	FwCodePage uint16
}

type LC_ID = TLC_ID

type TtagLC_ID = TLC_ID

type tagLC_ID = TtagLC_ID

type TLPLC_ID = uintptr

type LPLC_ID = TLPLC_ID

type Tthreadlocinfo = struct {
	Frefcount      int32
	Flc_codepage   uint32
	Flc_collate_cp uint32
	Flc_handle     [6]uint32
	Flc_id         [6]TLC_ID
	Flc_category   [6]struct {
		Flocale    uintptr
		Fwlocale   uintptr
		Frefcount  uintptr
		Fwrefcount uintptr
	}
	Flc_clike            int32
	Fmb_cur_max          int32
	Flconv_intl_refcount uintptr
	Flconv_num_refcount  uintptr
	Flconv_mon_refcount  uintptr
	Flconv               uintptr
	Fctype1_refcount     uintptr
	Fctype1              uintptr
	Fpctype              uintptr
	Fpclmap              uintptr
	Fpcumap              uintptr
	Flc_time_curr        uintptr
}

type threadlocinfo = Tthreadlocinfo

type T_iobuf = struct {
	F_ptr      uintptr
	F_cnt      int32
	F_base     uintptr
	F_flag     int32
	F_file     int32
	F_charbuf  int32
	F_bufsiz   int32
	F_tmpfname uintptr
}

type _iobuf = T_iobuf

type TFILE = struct {
	F_ptr      uintptr
	F_cnt      int32
	F_base     uintptr
	F_flag     int32
	F_file     int32
	F_charbuf  int32
	F_bufsiz   int32
	F_tmpfname uintptr
}

type FILE = TFILE

type T_off_t = int32

type _off_t = T_off_t

type Toff32_t = int32

type off32_t = Toff32_t

type T_off64_t = int64

type _off64_t = T_off64_t

type Toff64_t = int64

type off64_t = Toff64_t

type Toff_t = int64

type off_t = Toff_t

type Tfpos_t = int64

type fpos_t = Tfpos_t

type T_onexit_t = uintptr

type _onexit_t = T_onexit_t

type Tdiv_t = struct {
	Fquot int32
	Frem  int32
}

type div_t = Tdiv_t

type T_div_t = Tdiv_t

type _div_t = T_div_t

type Tldiv_t = struct {
	Fquot int32
	Frem  int32
}

type ldiv_t = Tldiv_t

type T_ldiv_t = Tldiv_t

type _ldiv_t = T_ldiv_t

type T_LDOUBLE = struct {
	Fld [10]uint8
}

type _LDOUBLE = T_LDOUBLE

type T_CRT_DOUBLE = struct {
	F__ccgo_align [0]uint32
	Fx            float64
}

type _CRT_DOUBLE = T_CRT_DOUBLE

type T_CRT_FLOAT = struct {
	Ff float32
}

type _CRT_FLOAT = T_CRT_FLOAT

type T_LONGDOUBLE = struct {
	F__ccgo_align [0]uint32
	Fx            float64
}

type _LONGDOUBLE = T_LONGDOUBLE

type T_LDBL12 = struct {
	Fld12 [12]uint8
}

type _LDBL12 = T_LDBL12

type T_purecall_handler = uintptr

type _purecall_handler = T_purecall_handler

type T_invalid_parameter_handler = uintptr

type _invalid_parameter_handler = T_invalid_parameter_handler

type Tlldiv_t = struct {
	F__ccgo_align [0]uint32
	Fquot         int64
	Frem          int64
}

type lldiv_t = Tlldiv_t

type T_HEAPINFO = struct {
	F_pentry  uintptr
	F_size    Tsize_t
	F_useflag int32
}

type _HEAPINFO = T_HEAPINFO

type T_heapinfo = T_HEAPINFO

type _heapinfo = T_heapinfo

type Tmax_align_t = struct {
	F__ccgo_align   [0]uint32
	F__max_align_ll int64
	F__max_align_ld float64
}

type max_align_t = Tmax_align_t

/* Copyright (C) 1989-2022 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */

/*
 * ISO C Standard:  7.17  Common definitions  <stddef.h>
 */

/*
** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
** This allows better measurements of where memcpy() is used when running
** cachegrind.  But this macro version of memcpy() is very slow so it
** should not be used in production.  This is a performance measurement
** hack only.
 */

/*
** If compiling for a processor that lacks floating point support,
** substitute integer for floating-point
 */

/*
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
** afterward. Having this macro allows us to cause the C compiler
** to omit code used by TEMP tables without messy #ifndef statements.
 */

/*
** The "file format" number is an integer that is incremented whenever
** the VDBE-level file format changes.  The following macros define the
** the default file format for new databases and the maximum file format
** that the library can read.
 */

/*
** Determine whether triggers are recursive by default.  This can be
** changed at run-time using a pragma.
 */

/*
** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
** on the command-line
 */

/*
** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if
** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it
** to zero.
 */

/*
** The default initial allocation for the pagecache when using separate
** pagecaches for each database connection.  A positive number is the
** number of pages.  A negative number N translations means that a buffer
** of -1024*N bytes is allocated and used for as many pages as it will hold.
**
** The default value of "20" was chosen to minimize the run-time of the
** speedtest1 test program with options: --shrink-memory --reprepare
 */

/*
** Default value for the SQLITE_CONFIG_SORTERREF_SIZE option.
 */

/*
** The compile-time options SQLITE_MMAP_READWRITE and
** SQLITE_ENABLE_BATCH_ATOMIC_WRITE are not compatible with one another.
** You must choose one or the other (or neither) but not both.
 */

/*
** GCC does not define the offsetof() macro so we'll have to do it
** ourselves.
 */

/*
** Macros to compute minimum and maximum of two numbers.
 */

/*
** Swap two objects of type TYPE.
 */

/*
** Check to see if this machine uses EBCDIC.  (Yes, believe it or
** not, there are still machines out there that use EBCDIC.)
 */

// C documentation
//
//	/*
//	** Integers of known sizes.  These typedefs might change for architectures
//	** where the sizes very.  Preprocessor macros are available so that the
//	** types can be conveniently redefined at compile-type.  Like this:
//	**
//	**         cc '-DUINTPTR_TYPE=long long int' ...
//	*/
type Ti64 = int64

type i64 = Ti64

/* 8-byte signed integer */
type Tu64 = uint64

type u64 = Tu64

/* 8-byte unsigned integer */
type Tu32 = uint32

type u32 = Tu32

/* 4-byte unsigned integer */
type Tu16 = uint16

type u16 = Tu16

/* 2-byte unsigned integer */
type Ti16 = int16

type i16 = Ti16

/* 2-byte signed integer */
type Tu8 = uint8

type u8 = Tu8

/* 1-byte unsigned integer */
type Ti8 = int8

type i8 = Ti8

/* 1-byte signed integer */

/*
** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
** that can be stored in a u32 without loss of data.  The value
** is 0x00000000ffffffff.  But because of quirks of some compilers, we
** have to specify the value in the less intuitive manner shown:
 */

// C documentation
//
//	/*
//	** The datatype used to store estimates of the number of rows in a
//	** table or index.
//	*/
type TtRowcnt = uint64

type tRowcnt = TtRowcnt

// C documentation
//
//	/*
//	** Estimated quantities used for query planning are stored as 16-bit
//	** logarithms.  For quantity X, the value stored is 10*log2(X).  This
//	** gives a possible range of values of approximately 1.0e986 to 1e-986.
//	** But the allowed values are "grainy".  Not every value is representable.
//	** For example, quantities 16 and 17 are both represented by a LogEst
//	** of 40.  However, since LogEst quantities are suppose to be estimates,
//	** not exact values, this imprecision is not a problem.
//	**
//	** "LogEst" is short for "Logarithmic Estimate".
//	**
//	** Examples:
//	**      1 -> 0              20 -> 43          10000 -> 132
//	**      2 -> 10             25 -> 46          25000 -> 146
//	**      3 -> 16            100 -> 66        1000000 -> 199
//	**      4 -> 20           1000 -> 99        1048576 -> 200
//	**     10 -> 33           1024 -> 100    4294967296 -> 320
//	**
//	** The LogEst can be negative to indicate fractional values.
//	** Examples:
//	**
//	**    0.5 -> -10           0.1 -> -33        0.0625 -> -40
//	*/
type TLogEst = int16

type LogEst = TLogEst

/*
** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
 */

// C documentation
//
//	/* The uptr type is an unsigned integer large enough to hold a pointer
//	*/
type Tuptr = uint32

type uptr = Tuptr

/*
** Bits for the sqlite3WhereTrace mask:
**
** (---any--)   Top-level block structure
** 0x-------F   High-level debug messages
** 0x----FFF-   More detail
** 0xFFFF----   Low-level debug messages
**
** 0x00000001   Code generation
** 0x00000002   Solver
** 0x00000004   Solver costs
** 0x00000008   WhereLoop inserts
**
** 0x00000010   Display sqlite3_index_info xBestIndex calls
** 0x00000020   Range an equality scan metrics
** 0x00000040   IN operator decisions
** 0x00000080   WhereLoop cost adjustments
** 0x00000100
** 0x00000200   Covering index decisions
** 0x00000400   OR optimization
** 0x00000800   Index scanner
** 0x00001000   More details associated with code generation
** 0x00002000
** 0x00004000   Show all WHERE terms at key points
** 0x00008000   Show the full SELECT statement at key places
**
** 0x00010000   Show more detail when printing WHERE terms
** 0x00020000   Show WHERE terms returned from whereScanNext()
 */

// C documentation
//
//	/*
//	** An instance of the following structure is used to store the busy-handler
//	** callback for a given sqlite handle.
//	**
//	** The sqlite.busyHandler member of the sqlite struct contains the busy
//	** callback for the database handle. Each pager opened via the sqlite
//	** handle is passed a pointer to sqlite.busyHandler. The busy-handler
//	** callback is currently invoked only from within pager.c.
//	*/
type TBusyHandler = struct {
	FxBusyHandler uintptr
	FpBusyArg     uintptr
	FnBusy        int32
}

type BusyHandler = TBusyHandler

type TBusyHandler1 = struct {
	FxBusyHandler uintptr
	FpBusyArg     uintptr
	FnBusy        int32
}

type BusyHandler1 = TBusyHandler1

/*
** Name of table that holds the database schema.
**
** The PREFERRED names are used wherever possible.  But LEGACY is also
** used for backwards compatibility.
**
**  1.  Queries can use either the PREFERRED or the LEGACY names
**  2.  The sqlite3_set_authorizer() callback uses the LEGACY name
**  3.  The PRAGMA table_list statement uses the PREFERRED name
**
** The LEGACY names are stored in the internal symbol hash table
** in support of (2).  Names are translated using sqlite3PreferredTableName()
** for (3).  The sqlite3FindTable() function takes care of translating
** names for (1).
**
** Note that "sqlite_temp_schema" can also be called "temp.sqlite_schema".
 */

/*
** The root-page of the schema table.
 */

/*
** The name of the schema table.  The name is different for TEMP.
 */

/*
** A convenience macro that returns the number of elements in
** an array.
 */

/*
** Determine if the argument is a power of two
 */

/*
** The following value as a destructor means to use sqlite3DbFree().
** The sqlite3DbFree() routine requires two parameters instead of the
** one parameter that destructors normally want.  So we have to introduce
** this magic value that the code knows to handle differently.  Any
** pointer will work here as long as it is distinct from SQLITE_STATIC
** and SQLITE_TRANSIENT.
 */

/*
** When SQLITE_OMIT_WSD is defined, it means that the target platform does
** not support Writable Static Data (WSD) such as global and static variables.
** All variables must either be on the stack or dynamically allocated from
** the heap.  When WSD is unsupported, the variable declarations scattered
** throughout the SQLite code must become constants instead.  The SQLITE_WSD
** macro is used for this purpose.  And instead of referencing the variable
** directly, we use its constant as a key to lookup the run-time allocated
** buffer that holds real variable.  The constant is also the initializer
** for the run-time allocated buffer.
**
** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
** macros become no-ops and have zero performance impact.
 */

/*
** The following macros are used to suppress compiler warnings and to
** make it clear to human readers when a function parameter is deliberately
** left unused within the body of a function. This usually happens when
** a function is called via a function pointer. For example the
** implementation of an SQL aggregate step callback may not use the
** parameter indicating the number of arguments passed to the aggregate,
** if it knows that this is enforced elsewhere.
**
** When a function parameter is not used at all within the body of a function,
** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
** However, these macros may also be used to suppress warnings related to
** parameters that may or may not be used depending on compilation options.
** For example those parameters only used in assert() statements. In these
** cases the parameters are named as per the usual conventions.
 */

// C documentation
//
//	/*
//	** Forward references to structures
//	*/
type TAggInfo = struct {
	FdirectMode     Tu8
	FuseSortingIdx  Tu8
	FnSortingColumn Tu16
	FsortingIdx     int32
	FsortingIdxPTab int32
	FiFirstReg      int32
	FpGroupBy       uintptr
	FaCol           uintptr
	FnColumn        int32
	FnAccumulator   int32
	FaFunc          uintptr
	FnFunc          int32
	FselId          Tu32
}

type AggInfo = TAggInfo

type TAuthContext = struct {
	FzAuthContext uintptr
	FpParse       uintptr
}

type AuthContext = TAuthContext

type TAutoincInfo = struct {
	FpNext  uintptr
	FpTab   uintptr
	FiDb    int32
	FregCtr int32
}

type AutoincInfo = TAutoincInfo

type TBitvec = struct {
	FiSize    Tu32
	FnSet     Tu32
	FiDivisor Tu32
	Fu        struct {
		FaHash   [0][125]Tu32
		FapSub   [0][125]uintptr
		FaBitmap [500]Tu8
	}
}

type Bitvec = TBitvec

type TCollSeq = struct {
	FzName uintptr
	Fenc   Tu8
	FpUser uintptr
	FxCmp  uintptr
	FxDel  uintptr
}

type CollSeq = TCollSeq

type TColumn = struct {
	FzCnName  uintptr
	F__ccgo4  uint8
	Faffinity int8
	FszEst    Tu8
	FhName    Tu8
	FiDflt    Tu16
	FcolFlags Tu16
}

type Column = TColumn

type TCte = struct {
	FzName   uintptr
	FpCols   uintptr
	FpSelect uintptr
	FzCteErr uintptr
	FpUse    uintptr
	FeM10d   Tu8
}

type Cte = TCte

type TCteUse = struct {
	FnUse    int32
	FaddrM9e int32
	FregRtn  int32
	FiCur    int32
	FnRowEst TLogEst
	FeM10d   Tu8
}

type CteUse = TCteUse

type TDb = struct {
	FzDbSName     uintptr
	FpBt          uintptr
	Fsafety_level Tu8
	FbSyncSet     Tu8
	FpSchema      uintptr
}

type Db = TDb

type TDbClientData = struct {
	FpNext       uintptr
	FpData       uintptr
	FxDestructor uintptr
	FzName       [1]int8
}

type DbClientData = TDbClientData

type TDbFixer = struct {
	FpParse  uintptr
	Fw       TWalker
	FpSchema uintptr
	FbTemp   Tu8
	FzDb     uintptr
	FzType   uintptr
	FpName   uintptr
}

type DbFixer = TDbFixer

type TSchema = struct {
	Fschema_cookie int32
	FiGeneration   int32
	FtblHash       THash
	FidxHash       THash
	FtrigHash      THash
	FfkeyHash      THash
	FpSeqTab       uintptr
	Ffile_format   Tu8
	Fenc           Tu8
	FschemaFlags   Tu16
	Fcache_size    int32
}

type Schema = TSchema

type TExpr = struct {
	Fop      Tu8
	FaffExpr int8
	Fop2     Tu8
	Fflags   Tu32
	Fu       struct {
		FiValue [0]int32
		FzToken uintptr
	}
	FpLeft  uintptr
	FpRight uintptr
	Fx      struct {
		FpSelect [0]uintptr
		FpList   uintptr
	}
	FnHeight int32
	FiTable  int32
	FiColumn TynVar
	FiAgg    Ti16
	Fw       struct {
		FiOfst [0]int32
		FiJoin int32
	}
	FpAggInfo uintptr
	Fy        struct {
		FpWin [0]uintptr
		Fsub  [0]struct {
			FiAddr     int32
			FregReturn int32
		}
		FpTab        uintptr
		F__ccgo_pad3 [4]byte
	}
}

type Expr = TExpr

type TExprList = struct {
	FnExpr  int32
	FnAlloc int32
	Fa      [1]TExprList_item
}

type ExprList = TExprList

type TFKey = struct {
	FpFrom      uintptr
	FpNextFrom  uintptr
	FzTo        uintptr
	FpNextTo    uintptr
	FpPrevTo    uintptr
	FnCol       int32
	FisDeferred Tu8
	FaAction    [2]Tu8
	FapTrigger  [2]uintptr
	FaCol       [1]TsColMap
}

type FKey = TFKey

type TFpDecode = struct {
	Fsign      int8
	FisSpecial int8
	Fn         int32
	FiDP       int32
	Fz         uintptr
	FzBuf      [24]int8
}

type FpDecode = TFpDecode

type TFuncDestructor = struct {
	FnRef      int32
	FxDestroy  uintptr
	FpUserData uintptr
}

type FuncDestructor = TFuncDestructor

type TFuncDef = struct {
	FnArg      Ti8
	FfuncFlags Tu32
	FpUserData uintptr
	FpNext     uintptr
	FxSFunc    uintptr
	FxFinalize uintptr
	FxValue    uintptr
	FxInverse  uintptr
	FzName     uintptr
	Fu         struct {
		FpDestructor [0]uintptr
		FpHash       uintptr
	}
}

type FuncDef = TFuncDef

type TFuncDefHash = struct {
	Fa [23]uintptr
}

type FuncDefHash = TFuncDefHash

type TIdList = struct {
	FnId int32
	FeU4 Tu8
	Fa   [1]TIdList_item
}

type IdList = TIdList

type TIndex = struct {
	F__ccgo_align   [0]uint32
	FzName          uintptr
	FaiColumn       uintptr
	FaiRowLogEst    uintptr
	FpTable         uintptr
	FzColAff        uintptr
	FpNext          uintptr
	FpSchema        uintptr
	FaSortOrder     uintptr
	FazColl         uintptr
	FpPartIdxWhere  uintptr
	FaColExpr       uintptr
	Ftnum           TPgno
	FszIdxRow       TLogEst
	FnKeyCol        Tu16
	FnColumn        Tu16
	FonError        Tu8
	F__ccgo56       uint16
	FnSample        int32
	FmxSample       int32
	FnSampleCol     int32
	FaAvgEq         uintptr
	FaSample        uintptr
	FaiRowEst       uintptr
	F__ccgo_align34 [4]byte
	FnRowEst0       TtRowcnt
	FcolNotIdxed    TBitmask
}

type Index = TIndex

type TIndexedExpr = struct {
	FpExpr         uintptr
	FiDataCur      int32
	FiIdxCur       int32
	FiIdxCol       int32
	FbMaybeNullRow Tu8
	Faff           Tu8
	FpIENext       uintptr
}

type IndexedExpr = TIndexedExpr

type TIndexSample = struct {
	Fp     uintptr
	Fn     int32
	FanEq  uintptr
	FanLt  uintptr
	FanDLt uintptr
}

type IndexSample = TIndexSample

type TKeyInfo = struct {
	FnRef       Tu32
	Fenc        Tu8
	FnKeyField  Tu16
	FnAllField  Tu16
	Fdb         uintptr
	FaSortFlags uintptr
	FaColl      [1]uintptr
}

type KeyInfo = TKeyInfo

type TLookaside = struct {
	FbDisable   Tu32
	Fsz         Tu16
	FszTrue     Tu16
	FbMalloced  Tu8
	FnSlot      Tu32
	FanStat     [3]Tu32
	FpInit      uintptr
	FpFree      uintptr
	FpSmallInit uintptr
	FpSmallFree uintptr
	FpMiddle    uintptr
	FpStart     uintptr
	FpEnd       uintptr
	FpTrueEnd   uintptr
}

type Lookaside = TLookaside

type TLookasideSlot = struct {
	FpNext uintptr
}

type LookasideSlot = TLookasideSlot

type TModule = struct {
	FpModule    uintptr
	FzName      uintptr
	FnRefModule int32
	FpAux       uintptr
	FxDestroy   uintptr
	FpEpoTab    uintptr
}

type Module = TModule

type TNameContext = struct {
	FpParse   uintptr
	FpSrcList uintptr
	FuNC      struct {
		FpAggInfo [0]uintptr
		FpUpsert  [0]uintptr
		FiBaseReg [0]int32
		FpEList   uintptr
	}
	FpNext         uintptr
	FnRef          int32
	FnNcErr        int32
	FncFlags       int32
	FnNestedSelect Tu32
	FpWinSelect    uintptr
}

type NameContext = TNameContext

type TOnOrUsing = struct {
	FpOn    uintptr
	FpUsing uintptr
}

type OnOrUsing = TOnOrUsing

type TParse = struct {
	Fdb               uintptr
	FzErrMsg          uintptr
	FpVdbe            uintptr
	Frc               int32
	FcolNamesSet      Tu8
	FcheckSchema      Tu8
	Fnested           Tu8
	FnTempReg         Tu8
	FisMultiWrite     Tu8
	FmayAbort         Tu8
	FhasCompound      Tu8
	FokConstFactor    Tu8
	FdisableLookaside Tu8
	FprepFlags        Tu8
	FwithinRJSubrtn   Tu8
	FbHasWith         Tu8
	FnRangeReg        int32
	FiRangeReg        int32
	FnErr             int32
	FnTab             int32
	FnMem             int32
	FszOpAlloc        int32
	FiSelfTab         int32
	FnLabel           int32
	FnLabelAlloc      int32
	FaLabel           uintptr
	FpConstExpr       uintptr
	FpIdxEpr          uintptr
	FpIdxPartExpr     uintptr
	FconstraintName   TToken
	FwriteMask        TyDbMask
	FcookieMask       TyDbMask
	FregRowid         int32
	FregRoot          int32
	FnMaxArg          int32
	FnSelect          int32
	FnProgressSteps   Tu32
	FnTableLock       int32
	FaTableLock       uintptr
	FpAinc            uintptr
	FpToplevel        uintptr
	FpTriggerTab      uintptr
	FpTriggerPrg      uintptr
	FpCleanup         uintptr
	Fu1               struct {
		FpReturning [0]uintptr
		FaddrCrTab  int32
	}
	Foldmask         Tu32
	Fnewmask         Tu32
	FnQueryLoop      TLogEst
	FeTriggerOp      Tu8
	FbReturning      Tu8
	FeOrconf         Tu8
	FdisableTriggers Tu8
	FaTempReg        [8]int32
	FpOuterParse     uintptr
	FsNameToken      TToken
	FsLastToken      TToken
	FnVar            TynVar
	FiPkSortOrder    Tu8
	Fexplain         Tu8
	FeParseMode      Tu8
	FnVtabLock       int32
	FnHeight         int32
	FaddrExplain     int32
	FpVList          uintptr
	FpReprepare      uintptr
	FzTail           uintptr
	FpNewTable       uintptr
	FpNewIndex       uintptr
	FpNewTrigger     uintptr
	FzAuthContext    uintptr
	FsArg            TToken
	FapVtabLock      uintptr
	FpWith           uintptr
	FpRename         uintptr
}

type Parse = TParse

type TParseCleanup = struct {
	FpNext    uintptr
	FpPtr     uintptr
	FxCleanup uintptr
}

type ParseCleanup = TParseCleanup

type TPreUpdate = struct {
	F__ccgo_align [0]uint32
	Fv            uintptr
	FpCsr         uintptr
	Fop           int32
	FaRecord      uintptr
	Fkeyinfo      TKeyInfo
	FpUnpacked    uintptr
	FpNewUnpacked uintptr
	FiNewReg      int32
	FiBlobWrite   int32
	FiKey1        Ti64
	FiKey2        Ti64
	FaNew         uintptr
	FpTab         uintptr
	FpPk          uintptr
	F__ccgo_pad14 [4]byte
}

type PreUpdate = TPreUpdate

type TPrintfArguments = struct {
	FnArg  int32
	FnUsed int32
	FapArg uintptr
}

type PrintfArguments = TPrintfArguments

type TRCStr = struct {
	F__ccgo_align [0]uint32
	FnRCRef       Tu64
}

type RCStr = TRCStr

type TRenameToken = struct {
	Fp     uintptr
	Ft     TToken
	FpNext uintptr
}

type RenameToken = TRenameToken

type TReturning = struct {
	FpParse    uintptr
	FpReturnEL uintptr
	FretTrig   TTrigger
	FretTStep  TTriggerStep
	FiRetCur   int32
	FnRetCol   int32
	FiRetReg   int32
	FzName     [40]int8
}

type Returning = TReturning

type TRowSet = struct {
	FpChunk  uintptr
	Fdb      uintptr
	FpEntry  uintptr
	FpLast   uintptr
	FpFresh  uintptr
	FpForest uintptr
	FnFresh  Tu16
	FrsFlags Tu16
	FiBatch  int32
}

type RowSet = TRowSet

type TSavepoint = struct {
	F__ccgo_align     [0]uint32
	FzName            uintptr
	F__ccgo_align1    [4]byte
	FnDeferredCons    Ti64
	FnDeferredImmCons Ti64
	FpNext            uintptr
	F__ccgo_pad4      [4]byte
}

type Savepoint = TSavepoint

type TSelect = struct {
	Fop           Tu8
	FnSelectRow   TLogEst
	FselFlags     Tu32
	FiLimit       int32
	FiOffset      int32
	FselId        Tu32
	FaddrOpenEphm [2]int32
	FpEList       uintptr
	FpSrc         uintptr
	FpWhere       uintptr
	FpGroupBy     uintptr
	FpHaving      uintptr
	FpOrderBy     uintptr
	FpPrior       uintptr
	FpNext        uintptr
	FpLimit       uintptr
	FpWith        uintptr
	FpWin         uintptr
	FpWinDefn     uintptr
}

type Select = TSelect

type TSQLiteThread = struct {
	Ftid     uintptr
	Fid      uint32
	FxTask   uintptr
	FpIn     uintptr
	FpResult uintptr
}

type SQLiteThread = TSQLiteThread

type TSelectDest = struct {
	FeDest    Tu8
	FiSDParm  int32
	FiSDParm2 int32
	FiSdst    int32
	FnSdst    int32
	FzAffSdst uintptr
	FpOrderBy uintptr
}

type SelectDest = TSelectDest

type TSrcItem = struct {
	F__ccgo_align [0]uint32
	FpSchema      uintptr
	FzDatabase    uintptr
	FzName        uintptr
	FzAlias       uintptr
	FpTab         uintptr
	FpSelect      uintptr
	FaddrFillSub  int32
	FregReturn    int32
	FregResult    int32
	Ffg           struct {
		F__ccgo_align  [0]uint32
		Fjointype      Tu8
		F__ccgo_align1 [2]byte
		F__ccgo4       uint16
	}
	FiCursor int32
	Fu3      struct {
		FpUsing [0]uintptr
		FpOn    uintptr
	}
	F__ccgo_align12 [4]byte
	FcolUsed        TBitmask
	Fu1             struct {
		FpFuncArg   [0]uintptr
		FnRow       [0]Tu32
		FzIndexedBy uintptr
	}
	Fu2 struct {
		FpCteUse  [0]uintptr
		FpIBIndex uintptr
	}
}

type SrcItem = TSrcItem

type TSrcList = struct {
	F__ccgo_align [0]uint32
	FnSrc         int32
	FnAlloc       Tu32
	Fa            [1]TSrcItem
}

type SrcList = TSrcList

type TStrAccum = struct {
	Fdb          uintptr
	FzText       uintptr
	FnAlloc      Tu32
	FmxAlloc     Tu32
	FnChar       Tu32
	FaccError    Tu8
	FprintfFlags Tu8
}

type StrAccum = TStrAccum

type Tsqlite3_str1 = TStrAccum

type sqlite3_str1 = Tsqlite3_str1

/* Internal alias for sqlite3_str */
type TTable = struct {
	FzName      uintptr
	FaCol       uintptr
	FpIndex     uintptr
	FzColAff    uintptr
	FpCheck     uintptr
	Ftnum       TPgno
	FnTabRef    Tu32
	FtabFlags   Tu32
	FiPKey      Ti16
	FnCol       Ti16
	FnNVCol     Ti16
	FnRowLogEst TLogEst
	FszTabRow   TLogEst
	FkeyConf    Tu8
	FeTabType   Tu8
	Fu          struct {
		Fview [0]struct {
			FpSelect uintptr
		}
		Fvtab [0]struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		}
		Ftab struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		}
	}
	FpTrigger uintptr
	FpSchema  uintptr
}

type Table = TTable

type TTableLock = struct {
	FiDb         int32
	FiTab        TPgno
	FisWriteLock Tu8
	FzLockName   uintptr
}

type TableLock = TTableLock

type TToken = struct {
	Fz uintptr
	Fn uint32
}

type Token = TToken

type TTrigger = struct {
	FzName      uintptr
	Ftable      uintptr
	Fop         Tu8
	Ftr_tm      Tu8
	FbReturning Tu8
	FpWhen      uintptr
	FpColumns   uintptr
	FpSchema    uintptr
	FpTabSchema uintptr
	Fstep_list  uintptr
	FpNext      uintptr
}

type Trigger = TTrigger

type TTriggerPrg = struct {
	FpTrigger uintptr
	FpNext    uintptr
	FpProgram uintptr
	Forconf   int32
	FaColmask [2]Tu32
}

type TriggerPrg = TTriggerPrg

type TTriggerStep = struct {
	Fop        Tu8
	Forconf    Tu8
	FpTrig     uintptr
	FpSelect   uintptr
	FzTarget   uintptr
	FpFrom     uintptr
	FpWhere    uintptr
	FpExprList uintptr
	FpIdList   uintptr
	FpUpsert   uintptr
	FzSpan     uintptr
	FpNext     uintptr
	FpLast     uintptr
}

type TriggerStep = TTriggerStep

type TUnpackedRecord = struct {
	F__ccgo_align [0]uint32
	FpKeyInfo     uintptr
	FaMem         uintptr
	Fu            struct {
		F__ccgo_align [0]uint32
		Fi            [0]Ti64
		Fz            uintptr
		F__ccgo_pad2  [4]byte
	}
	Fn            int32
	FnField       Tu16
	Fdefault_rc   Ti8
	FerrCode      Tu8
	Fr1           Ti8
	Fr2           Ti8
	FeqSeen       Tu8
	F__ccgo_pad10 [5]byte
}

type UnpackedRecord = TUnpackedRecord

type TUpsert = struct {
	FpUpsertTarget      uintptr
	FpUpsertTargetWhere uintptr
	FpUpsertSet         uintptr
	FpUpsertWhere       uintptr
	FpNextUpsert        uintptr
	FisDoUpdate         Tu8
	FisDup              Tu8
	FpToFree            uintptr
	FpUpsertIdx         uintptr
	FpUpsertSrc         uintptr
	FregData            int32
	FiDataCur           int32
	FiIdxCur            int32
}

type Upsert = TUpsert

type TVTable = struct {
	Fdb          uintptr
	FpMod        uintptr
	FpVtab       uintptr
	FnRef        int32
	FbConstraint Tu8
	FbAllSchemas Tu8
	FeVtabRisk   Tu8
	FiSavepoint  int32
	FpNext       uintptr
}

type VTable = TVTable

type TVtabCtx = struct {
	FpVTable   uintptr
	FpTab      uintptr
	FpPrior    uintptr
	FbDeclared int32
}

type VtabCtx = TVtabCtx

type TWalker = struct {
	FpParse           uintptr
	FxExprCallback    uintptr
	FxSelectCallback  uintptr
	FxSelectCallback2 uintptr
	FwalkerDepth      int32
	FeCode            Tu16
	FmWFlags          Tu16
	Fu                struct {
		Fn           [0]int32
		FiCur        [0]int32
		FpSrcList    [0]uintptr
		FpCCurHint   [0]uintptr
		FpRefSrcList [0]uintptr
		FaiCol       [0]uintptr
		FpIdxCover   [0]uintptr
		FpGroupBy    [0]uintptr
		FpSelect     [0]uintptr
		FpRewrite    [0]uintptr
		FpConst      [0]uintptr
		FpRename     [0]uintptr
		FpTab        [0]uintptr
		FpCovIdxCk   [0]uintptr
		FpSrcItem    [0]uintptr
		FpFix        [0]uintptr
		FaMem        [0]uintptr
		FpNC         uintptr
	}
}

type Walker = TWalker

type TWhereInfo = struct {
	F__ccgo_align    [0]uint32
	FpParse          uintptr
	FpTabList        uintptr
	FpOrderBy        uintptr
	FpResultSet      uintptr
	FpSelect         uintptr
	FaiCurOnePass    [2]int32
	FiContinue       int32
	FiBreak          int32
	FsavedNQueryLoop int32
	FwctrlFlags      Tu16
	FiLimit          TLogEst
	FnLevel          Tu8
	FnOBSat          Ti8
	FeOnePass        Tu8
	FeDistinct       Tu8
	F__ccgo48        uint8
	FnRowOut         TLogEst
	FiTop            int32
	FiEndWhere       int32
	FpLoops          uintptr
	FpMemToFree      uintptr
	F__ccgo_align24  [4]byte
	FrevMask         TBitmask
	FsWC             TWhereClause
	FsMaskSet        TWhereMaskSet
	Fa               [1]TWhereLevel
}

type WhereInfo = TWhereInfo

type TWindow = struct {
	FzName          uintptr
	FzBase          uintptr
	FpPartition     uintptr
	FpOrderBy       uintptr
	FeFrmType       Tu8
	FeStart         Tu8
	FeEnd           Tu8
	FbImplicitFrame Tu8
	FeExclude       Tu8
	FpStart         uintptr
	FpEnd           uintptr
	FppThis         uintptr
	FpNextWin       uintptr
	FpFilter        uintptr
	FpWFunc         uintptr
	FiEphCsr        int32
	FregAccum       int32
	FregResult      int32
	FcsrApp         int32
	FregApp         int32
	FregPart        int32
	FpOwner         uintptr
	FnBufferCol     int32
	FiArgCol        int32
	FregOne         int32
	FregStartRowid  int32
	FregEndRowid    int32
	FbExprArgs      Tu8
}

type Window = TWindow

type TWith = struct {
	FnCte   int32
	FbView  int32
	FpOuter uintptr
	Fa      [1]TCte
}

type With = TWith

// C documentation
//
//	/*
//	** The bitmask datatype defined below is used for various optimizations.
//	**
//	** Changing this from a 64-bit to a 32-bit type limits the number of
//	** tables in a join to 32 instead of 64.  But it also reduces the size
//	** of the library by 738 bytes on ix86.
//	*/
type TBitmask = uint64

type Bitmask = TBitmask

/*
** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
 */

/*
** A bit in a Bitmask
 */

// C documentation
//
//	/* A VList object records a mapping between parameters/variables/wildcards
//	** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
//	** variable number associated with that parameter.  See the format description
//	** on the sqlite3VListAdd() routine for more information.  A VList is really
//	** just an array of integers.
//	*/
type TVList = int32

type VList = TVList

/************** End of os.h **************************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
/************** Include pager.h in the middle of sqliteInt.h *****************/
/************** Begin file pager.h *******************************************/
/*
** 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 header file defines the interface that the sqlite page cache
** subsystem.  The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
 */

/*
** Default maximum size for persistent journal files. A negative
** value means no limit. This value may be overridden using the
** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
 */

// C documentation
//
//	/*
//	** The type used to represent a page number.  The first page in a file
//	** is called page 1.  0 is used to represent "not a page".
//	*/
type TPgno = uint32

type Pgno = TPgno

// C documentation
//
//	/*
//	** Each open file is managed by a separate instance of the "Pager" structure.
//	*/
type TPager = struct {
	F__ccgo_align      [0]uint32
	FpVfs              uintptr
	FexclusiveMode     Tu8
	FjournalMode       Tu8
	FuseJournal        Tu8
	FnoSync            Tu8
	FfullSync          Tu8
	FextraSync         Tu8
	FsyncFlags         Tu8
	FwalSyncFlags      Tu8
	FtempFile          Tu8
	FnoLock            Tu8
	FreadOnly          Tu8
	FmemDb             Tu8
	FmemVfs            Tu8
	FeState            Tu8
	FeLock             Tu8
	FchangeCountDone   Tu8
	FsetSuper          Tu8
	FdoNotSpill        Tu8
	FsubjInMemory      Tu8
	FbUseFetch         Tu8
	FhasHeldSharedLock Tu8
	FdbSize            TPgno
	FdbOrigSize        TPgno
	FdbFileSize        TPgno
	FdbHintSize        TPgno
	FerrCode           int32
	FnRec              int32
	FcksumInit         Tu32
	FnSubRec           Tu32
	FpInJournal        uintptr
	Ffd                uintptr
	Fjfd               uintptr
	Fsjfd              uintptr
	F__ccgo_align34    [4]byte
	FjournalOff        Ti64
	FjournalHdr        Ti64
	FpBackup           uintptr
	FaSavepoint        uintptr
	FnSavepoint        int32
	FiDataVersion      Tu32
	FdbFileVers        [16]int8
	FnMmapOut          int32
	F__ccgo_align42    [4]byte
	FszMmap            Tsqlite3_int64
	FpMmapFreelist     uintptr
	FnExtra            Tu16
	FnReserve          Ti16
	FvfsFlags          Tu32
	FsectorSize        Tu32
	FmxPgno            TPgno
	FlckPgno           TPgno
	FpageSize          Ti64
	FjournalSizeLimit  Ti64
	FzFilename         uintptr
	FzJournal          uintptr
	FxBusyHandler      uintptr
	FpBusyHandlerArg   uintptr
	FaStat             [4]Tu32
	FxReiniter         uintptr
	FxGet              uintptr
	FpTmpSpace         uintptr
	FpPCache           uintptr
	FpWal              uintptr
	FzWal              uintptr
}

type Pager = TPager

// C documentation
//
//	/*
//	** Handle type for pages.
//	*/
type TDbPage = struct {
	F__ccgo_align  [0]uint32
	FpPage         uintptr
	FpData         uintptr
	FpExtra        uintptr
	FpCache        uintptr
	FpDirty        uintptr
	FpPager        uintptr
	Fpgno          TPgno
	Fflags         Tu16
	F__ccgo_align8 [2]byte
	FnRef          Ti64
	FpDirtyNext    uintptr
	FpDirtyPrev    uintptr
}

type DbPage = TDbPage

// C documentation
//
//	/*
//	** Handle type for pages.
//	*/
type TPgHdr2 = TDbPage

type PgHdr2 = TPgHdr2

/* Functions to support testing and debugging. */

/************** End of pager.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
/************** Include btree.h in the middle of sqliteInt.h *****************/
/************** Begin file btree.h *******************************************/
/*
** 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 header file defines the interface that the sqlite B-Tree file
** subsystem.  See comments in the source code for a detailed description
** of what each interface routine does.
 */

/* TODO: This definition is just included so other modules compile. It
** needs to be revisited.
 */

/*
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
 */

// C documentation
//
//	/*
//	** Forward declarations of structure
//	*/
type TBtree = struct {
	Fdb             uintptr
	FpBt            uintptr
	FinTrans        Tu8
	Fsharable       Tu8
	Flocked         Tu8
	FhasIncrblobCur Tu8
	FwantToLock     int32
	FnBackup        int32
	FiBDataVersion  Tu32
	FpNext          uintptr
	FpPrev          uintptr
	Flock           TBtLock
}

type Btree = TBtree

type TBtCursor = struct {
	F__ccgo_align   [0]uint32
	FeState         Tu8
	FcurFlags       Tu8
	FcurPagerFlags  Tu8
	Fhints          Tu8
	FskipNext       int32
	FpBtree         uintptr
	FaOverflow      uintptr
	FpKey           uintptr
	FpBt            uintptr
	FpNext          uintptr
	F__ccgo_align10 [4]byte
	Finfo           TCellInfo
	FnKey           Ti64
	FpgnoRoot       TPgno
	FiPage          Ti8
	FcurIntKey      Tu8
	Fix             Tu16
	FaiIdx          [19]Tu16
	FpKeyInfo       uintptr
	FpPage          uintptr
	FapPage         [19]uintptr
	F__ccgo_pad20   [4]byte
}

type BtCursor = TBtCursor

type TBtShared = struct {
	FpPager          uintptr
	Fdb              uintptr
	FpCursor         uintptr
	FpPage1          uintptr
	FopenFlags       Tu8
	FautoVacuum      Tu8
	FincrVacuum      Tu8
	FbDoTruncate     Tu8
	FinTransaction   Tu8
	Fmax1bytePayload Tu8
	FnReserveWanted  Tu8
	FbtsFlags        Tu16
	FmaxLocal        Tu16
	FminLocal        Tu16
	FmaxLeaf         Tu16
	FminLeaf         Tu16
	FpageSize        Tu32
	FusableSize      Tu32
	FnTransaction    int32
	FnPage           Tu32
	FpSchema         uintptr
	FxFreeSchema     uintptr
	Fmutex           uintptr
	FpHasContent     uintptr
	FnRef            int32
	FpNext           uintptr
	FpLock           uintptr
	FpWriter         uintptr
	FpTmpSpace       uintptr
	FnPreformatSize  int32
}

type BtShared = TBtShared

type TBtreePayload = struct {
	F__ccgo_align  [0]uint32
	FpKey          uintptr
	F__ccgo_align1 [4]byte
	FnKey          Tsqlite3_int64
	FpData         uintptr
	FaMem          uintptr
	FnMem          Tu16
	FnData         int32
	FnZero         int32
	F__ccgo_pad7   [4]byte
}

type BtreePayload = TBtreePayload

/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */

/* An instance of the BtreePayload object describes the content of a single
** entry in either an index or table btree.
**
** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
** an arbitrary key and no data.  These btrees have pKey,nKey set to the
** key and the pData,nData,nZero fields are uninitialized.  The aMem,nMem
** fields give an array of Mem objects that are a decomposition of the key.
** The nMem field might be zero, indicating that no decomposition is available.
**
** Table btrees (used for rowid tables) contain an integer rowid used as
** the key and passed in the nKey field.  The pKey field is zero.
** pData,nData hold the content of the new entry.  nZero extra zero bytes
** are appended to the end of the content when constructing the entry.
** The aMem,nMem fields are uninitialized for table btrees.
**
** Field usage summary:
**
**               Table BTrees                   Index Btrees
**
**   pKey        always NULL                    encoded key
**   nKey        the ROWID                      length of pKey
**   pData       data                           not used
**   aMem        not used                       decomposed key value
**   nMem        not used                       entries in aMem
**   nData       length of pData                not used
**   nZero       extra zeros after pData        not used
**
** This object is used to pass information into sqlite3BtreeInsert().  The
** same information used to be passed as five separate parameters.  But placing
** the information into this object helps to keep the interface more
** organized and understandable, and it also helps the resulting code to
** run a little faster by using fewer registers for parameter passing.
 */
type TBtreePayload1 = struct {
	F__ccgo_align  [0]uint32
	FpKey          uintptr
	F__ccgo_align1 [4]byte
	FnKey          Tsqlite3_int64
	FpData         uintptr
	FaMem          uintptr
	FnMem          Tu16
	FnData         int32
	FnZero         int32
	F__ccgo_pad7   [4]byte
}

type BtreePayload1 = TBtreePayload1

/************** End of btree.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
/************** Include vdbe.h in the middle of sqliteInt.h ******************/
/************** Begin file vdbe.h ********************************************/
/*
** 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.
**
*************************************************************************
** Header file for the Virtual DataBase Engine (VDBE)
**
** This header defines the interface to the virtual database engine
** or VDBE.  The VDBE implements an abstract machine that runs a
** simple program to access and modify the underlying database.
 */
/* #include <stdio.h> */

// C documentation
//
//	/*
//	** A single VDBE is an opaque structure named "Vdbe".  Only routines
//	** in the source file sqliteVdbe.c are allowed to see the insides
//	** of this structure.
//	*/
type TVdbe = struct {
	F__ccgo_align       [0]uint32
	Fdb                 uintptr
	FppVPrev            uintptr
	FpVNext             uintptr
	FpParse             uintptr
	FnVar               TynVar
	FnMem               int32
	FnCursor            int32
	FcacheCtr           Tu32
	Fpc                 int32
	Frc                 int32
	FnChange            Ti64
	FiStatement         int32
	F__ccgo_align12     [4]byte
	FiCurrentTime       Ti64
	FnFkConstraint      Ti64
	FnStmtDefCons       Ti64
	FnStmtDefImmCons    Ti64
	FaMem               uintptr
	FapArg              uintptr
	FapCsr              uintptr
	FaVar               uintptr
	FaOp                uintptr
	FnOp                int32
	FnOpAlloc           int32
	FaColName           uintptr
	FpResultRow         uintptr
	FzErrMsg            uintptr
	FpVList             uintptr
	F__ccgo_align27     [4]byte
	FstartTime          Ti64
	FnResColumn         Tu16
	FnResAlloc          Tu16
	FerrorAction        Tu8
	FminWriteFileFormat Tu8
	FprepFlags          Tu8
	FeVdbeState         Tu8
	F__ccgo152          uint16
	FbtreeMask          TyDbMask
	FlockMask           TyDbMask
	FaCounter           [9]Tu32
	FzSql               uintptr
	FpFree              uintptr
	FpFrame             uintptr
	FpDelFrame          uintptr
	FnFrame             int32
	Fexpmask            Tu32
	FpProgram           uintptr
	FpAuxData           uintptr
}

type Vdbe = TVdbe

// C documentation
//
//	/*
//	** The names of the following types declared in vdbeInt.h are required
//	** for the VdbeOp definition.
//	*/
type TMem = struct {
	F__ccgo_align [0]uint32
	Fu            TMemValue
	Fz            uintptr
	Fn            int32
	Fflags        Tu16
	Fenc          Tu8
	FeSubtype     Tu8
	Fdb           uintptr
	FszMalloc     int32
	FuTemp        Tu32
	FzMalloc      uintptr
	FxDel         uintptr
}

type Mem = TMem

// C documentation
//
//	/*
//	** The names of the following types declared in vdbeInt.h are required
//	** for the VdbeOp definition.
//	*/
type Tsqlite3_value1 = TMem

type sqlite3_value1 = Tsqlite3_value1

type TSubProgram = struct {
	FaOp   uintptr
	FnOp   int32
	FnMem  int32
	FnCsr  int32
	FaOnce uintptr
	Ftoken uintptr
	FpNext uintptr
}

type SubProgram = TSubProgram

/*
** A single instruction of the virtual machine has an opcode
** and as many as three operands.  The instruction is recorded
** as an instance of the following structure:
 */
type TVdbeOp1 = struct {
	Fopcode Tu8
	Fp4type int8
	Fp5     Tu16
	Fp1     int32
	Fp2     int32
	Fp3     int32
	Fp4     Tp4union
}

type VdbeOp1 = TVdbeOp1

type TVdbeOp = struct {
	Fopcode Tu8
	Fp4type int8
	Fp5     Tu16
	Fp1     int32
	Fp2     int32
	Fp3     int32
	Fp4     Tp4union
}

type VdbeOp = TVdbeOp

/*
** A sub-routine used to implement a trigger program.
 */
type TSubProgram1 = struct {
	FaOp   uintptr
	FnOp   int32
	FnMem  int32
	FnCsr  int32
	FaOnce uintptr
	Ftoken uintptr
	FpNext uintptr
}

type SubProgram1 = TSubProgram1

/*
** A smaller version of VdbeOp used for the VdbeAddOpList() function because
** it takes up less space.
 */
type TVdbeOpList1 = struct {
	Fopcode Tu8
	Fp1     int8
	Fp2     int8
	Fp3     int8
}

type VdbeOpList1 = TVdbeOpList1

type TVdbeOpList = struct {
	Fopcode Tu8
	Fp1     int8
	Fp2     int8
	Fp3     int8
}

type VdbeOpList = TVdbeOpList

type TRecordCompare = uintptr

type RecordCompare = TRecordCompare

/* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
** each VDBE opcode.
**
** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
** comments in VDBE programs that show key decision points in the code
** generator.
 */

/*
** The VdbeCoverage macros are used to set a coverage testing point
** for VDBE branch instructions.  The coverage testing points are line
** numbers in the sqlite3.c source file.  VDBE branch coverage testing
** only works with an amalgamation build.  That's ok since a VDBE branch
** coverage build designed for testing the test suite only.  No application
** should ever ship with VDBE branch coverage measuring turned on.
**
**    VdbeCoverage(v)                  // Mark the previously coded instruction
**                                     // as a branch
**
**    VdbeCoverageIf(v, conditional)   // Mark previous if conditional true
**
**    VdbeCoverageAlwaysTaken(v)       // Previous branch is always taken
**
**    VdbeCoverageNeverTaken(v)        // Previous branch is never taken
**
**    VdbeCoverageNeverNull(v)         // Previous three-way branch is only
**                                     // taken on the first two ways.  The
**                                     // NULL option is not possible
**
**    VdbeCoverageEqNe(v)              // Previous OP_Jump is only interested
**                                     // in distinguishing equal and not-equal.
**
** Every VDBE branch operation must be tagged with one of the macros above.
** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
** routine in vdbe.c, alerting the developer to the missed tag.
**
** During testing, the test application will invoke
** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
** routine that is invoked as each bytecode branch is taken.  The callback
** contains the sqlite3.c source line number of the VdbeCoverage macro and
** flags to indicate whether or not the branch was taken.  The test application
** is responsible for keeping track of this and reporting byte-code branches
** that are never taken.
**
** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
** vdbe.c source file for additional information.
 */

/************** End of vdbe.h ************************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
/************** Include pcache.h in the middle of sqliteInt.h ****************/
/************** Begin file pcache.h ******************************************/
/*
** 2008 August 05
**
** 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 header file defines the interface that the sqlite page cache
** subsystem.
 */

type TPgHdr = struct {
	F__ccgo_align  [0]uint32
	FpPage         uintptr
	FpData         uintptr
	FpExtra        uintptr
	FpCache        uintptr
	FpDirty        uintptr
	FpPager        uintptr
	Fpgno          TPgno
	Fflags         Tu16
	F__ccgo_align8 [2]byte
	FnRef          Ti64
	FpDirtyNext    uintptr
	FpDirtyPrev    uintptr
}

type PgHdr = TPgHdr

type TPCache = struct {
	F__ccgo_align  [0]uint32
	FpDirty        uintptr
	FpDirtyTail    uintptr
	FpSynced       uintptr
	F__ccgo_align3 [4]byte
	FnRefSum       Ti64
	FszCache       int32
	FszSpill       int32
	FszPage        int32
	FszExtra       int32
	FbPurgeable    Tu8
	FeCreate       Tu8
	FxStress       uintptr
	FpStress       uintptr
	FpCache        uintptr
}

type PCache = TPCache

/************** End of mutex.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/

/* The SQLITE_EXTRA_DURABLE compile-time option used to set the default
** synchronous setting to EXTRA.  It is no longer supported.
 */

/*
** Default synchronous levels.
**
** Note that (for historical reasons) the PAGER_SYNCHRONOUS_* macros differ
** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1.
**
**           PAGER_SYNCHRONOUS       DEFAULT_SYNCHRONOUS
**   OFF           1                         0
**   NORMAL        2                         1
**   FULL          3                         2
**   EXTRA         4                         3
**
** The "PRAGMA synchronous" statement also uses the zero-based numbers.
** In other words, the zero-based numbers are used for all external interfaces
** and the one-based values are used internally.
 */

/*
** Each database file to be accessed by the system is an instance
** of the following structure.  There are normally two of these structures
** in the sqlite.aDb[] array.  aDb[0] is the main database file and
** aDb[1] is the database file used to hold temporary tables.  Additional
** databases may be attached.
 */
type TDb1 = struct {
	FzDbSName     uintptr
	FpBt          uintptr
	Fsafety_level Tu8
	FbSyncSet     Tu8
	FpSchema      uintptr
}

type Db1 = TDb1

/*
** An instance of the following structure stores a database schema.
**
** Most Schema objects are associated with a Btree.  The exception is
** the Schema for the TEMP database (sqlite3.aDb[1]) which is free-standing.
** In shared cache mode, a single Schema object can be shared by multiple
** Btrees that refer to the same underlying BtShared object.
**
** Schema objects are automatically deallocated when the last Btree that
** references them is destroyed.   The TEMP Schema is manually freed by
** sqlite3_close().
*
** A thread must be holding a mutex on the corresponding Btree in order
** to access Schema content.  This implies that the thread must also be
** holding a mutex on the sqlite3 connection pointer that owns the Btree.
** For a TEMP Schema, only the connection mutex is required.
 */
type TSchema1 = struct {
	Fschema_cookie int32
	FiGeneration   int32
	FtblHash       THash
	FidxHash       THash
	FtrigHash      THash
	FfkeyHash      THash
	FpSeqTab       uintptr
	Ffile_format   Tu8
	Fenc           Tu8
	FschemaFlags   Tu16
	Fcache_size    int32
}

type Schema1 = TSchema1

/*
** These macros can be used to test, set, or clear bits in the
** Db.pSchema->flags field.
 */

/*
** Allowed values for the DB.pSchema->flags field.
**
** The DB_SchemaLoaded flag is set after the database schema has been
** read into internal hash tables.
**
** DB_UnresetViews means that one or more views have column names that
** have been filled out.  If the schema changes, these column names might
** changes and so the view will need to be reset.
 */

/*
** The number of different kinds of things that can be limited
** using the sqlite3_limit() interface.
 */

/*
** Lookaside malloc is a set of fixed-size buffers that can be used
** to satisfy small transient memory allocation requests for objects
** associated with a particular database connection.  The use of
** lookaside malloc provides a significant performance enhancement
** (approx 10%) by avoiding numerous malloc/free requests while parsing
** SQL statements.
**
** The Lookaside structure holds configuration information about the
** lookaside malloc subsystem.  Each available memory allocation in
** the lookaside subsystem is stored on a linked list of LookasideSlot
** objects.
**
** Lookaside allocations are only allowed for objects that are associated
** with a particular database connection.  Hence, schema information cannot
** be stored in lookaside because in shared cache mode the schema information
** is shared by multiple database connections.  Therefore, while parsing
** schema information, the Lookaside.bEnabled flag is cleared so that
** lookaside allocations are not used to construct the schema objects.
**
** New lookaside allocations are only allowed if bDisable==0.  When
** bDisable is greater than zero, sz is set to zero which effectively
** disables lookaside without adding a new test for the bDisable flag
** in a performance-critical path.  sz should be set by to szTrue whenever
** bDisable changes back to zero.
**
** Lookaside buffers are initially held on the pInit list.  As they are
** used and freed, they are added back to the pFree list.  New allocations
** come off of pFree first, then pInit as a fallback.  This dual-list
** allows use to compute a high-water mark - the maximum number of allocations
** outstanding at any point in the past - by subtracting the number of
** allocations on the pInit list from the total number of allocations.
**
** Enhancement on 2019-12-12:  Two-size-lookaside
** The default lookaside configuration is 100 slots of 1200 bytes each.
** The larger slot sizes are important for performance, but they waste
** a lot of space, as most lookaside allocations are less than 128 bytes.
** The two-size-lookaside enhancement breaks up the lookaside allocation
** into two pools:  One of 128-byte slots and the other of the default size
** (1200-byte) slots.   Allocations are filled from the small-pool first,
** failing over to the full-size pool if that does not work.  Thus more
** lookaside slots are available while also using less memory.
** This enhancement can be omitted by compiling with
** SQLITE_OMIT_TWOSIZE_LOOKASIDE.
 */
type TLookaside1 = struct {
	FbDisable   Tu32
	Fsz         Tu16
	FszTrue     Tu16
	FbMalloced  Tu8
	FnSlot      Tu32
	FanStat     [3]Tu32
	FpInit      uintptr
	FpFree      uintptr
	FpSmallInit uintptr
	FpSmallFree uintptr
	FpMiddle    uintptr
	FpStart     uintptr
	FpEnd       uintptr
	FpTrueEnd   uintptr
}

type Lookaside1 = TLookaside1

type TLookasideSlot1 = struct {
	FpNext uintptr
}

type LookasideSlot1 = TLookasideSlot1

/* Size of the smaller allocations in two-size lookaside */

/*
** A hash table for built-in function definitions.  (Application-defined
** functions use a regular table table from hash.h.)
**
** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
** Collisions are on the FuncDef.u.pHash chain.  Use the SQLITE_FUNC_HASH()
** macro to compute a hash on the function name.
 */
type TFuncDefHash1 = struct {
	Fa [23]uintptr
}

type FuncDefHash1 = TFuncDefHash1

// C documentation
//
//	/*
//	** typedef for the authorization callback function.
//	*/
type Tsqlite3_xauth = uintptr

type sqlite3_xauth = Tsqlite3_xauth

/* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
** in the style of sqlite3_trace()
 */

/*
** Maximum number of sqlite3.aDb[] entries.  This is the number of attached
** databases plus 2 for "main" and "temp".
 */

/*
** Each database connection is an instance of the following structure.
 */
type Tsqlite31 = struct {
	F__ccgo_align           [0]uint32
	FpVfs                   uintptr
	FpVdbe                  uintptr
	FpDfltColl              uintptr
	Fmutex                  uintptr
	FaDb                    uintptr
	FnDb                    int32
	FmDbFlags               Tu32
	F__ccgo_align7          [4]byte
	Fflags                  Tu64
	FlastRowid              Ti64
	FszMmap                 Ti64
	FnSchemaLock            Tu32
	FopenFlags              uint32
	FerrCode                int32
	FerrByteOffset          int32
	FerrMask                int32
	FiSysErrno              int32
	FdbOptFlags             Tu32
	Fenc                    Tu8
	FautoCommit             Tu8
	Ftemp_store             Tu8
	FmallocFailed           Tu8
	FbBenignMalloc          Tu8
	FdfltLockMode           Tu8
	FnextAutovac            int8
	FsuppressErr            Tu8
	FvtabOnConflict         Tu8
	FisTransactionSavepoint Tu8
	FmTrace                 Tu8
	FnoSharedCache          Tu8
	FnSqlExec               Tu8
	FeOpenState             Tu8
	FnextPagesize           int32
	FnChange                Ti64
	FnTotalChange           Ti64
	FaLimit                 [12]int32
	FnMaxSorterMmap         int32
	Finit1                  Tsqlite3InitInfo
	FnVdbeActive            int32
	FnVdbeRead              int32
	FnVdbeWrite             int32
	FnVdbeExec              int32
	FnVDestroy              int32
	FnExtension             int32
	FaExtension             uintptr
	Ftrace                  struct {
		FxV2     [0]uintptr
		FxLegacy uintptr
	}
	FpTraceArg          uintptr
	FxProfile           uintptr
	FpProfileArg        uintptr
	FpCommitArg         uintptr
	FxCommitCallback    uintptr
	FpRollbackArg       uintptr
	FxRollbackCallback  uintptr
	FpUpdateArg         uintptr
	FxUpdateCallback    uintptr
	FpAutovacPagesArg   uintptr
	FxAutovacDestr      uintptr
	FxAutovacPages      uintptr
	FpParse             uintptr
	FpPreUpdateArg      uintptr
	FxPreUpdateCallback uintptr
	FpPreUpdate         uintptr
	FxWalCallback       uintptr
	FpWalArg            uintptr
	FxCollNeeded        uintptr
	FxCollNeeded16      uintptr
	FpCollNeededArg     uintptr
	FpErr               uintptr
	F__ccgo_align67     [4]byte
	Fu1                 struct {
		F__ccgo_align  [0]uint32
		FnotUsed1      [0]float64
		FisInterrupted int32
		F__ccgo_pad2   [4]byte
	}
	Flookaside           TLookaside
	FxAuth               Tsqlite3_xauth
	FpAuthArg            uintptr
	FxProgress           uintptr
	FpProgressArg        uintptr
	FnProgressOps        uint32
	FnVTrans             int32
	FaModule             THash
	FpVtabCtx            uintptr
	FaVTrans             uintptr
	FpDisconnect         uintptr
	FaFunc               THash
	FaCollSeq            THash
	FbusyHandler         TBusyHandler
	FaDbStatic           [2]TDb
	FpSavepoint          uintptr
	FnAnalysisLimit      int32
	FbusyTimeout         int32
	FnSavepoint          int32
	FnStatement          int32
	FnDeferredCons       Ti64
	FnDeferredImmCons    Ti64
	FpnBytesFreed        uintptr
	FpDbData             uintptr
	FpBlockingConnection uintptr
	FpUnlockConnection   uintptr
	FpUnlockArg          uintptr
	FxUnlockNotify       uintptr
	FpNextBlocked        uintptr
	F__ccgo_pad97        [4]byte
}

type sqlite31 = Tsqlite31

/*
** A macro to discover the encoding of a database.
 */

/*
** A u64 constant where the lower 32 bits are all zeros.  Only the
** upper 32 bits are included in the argument.  Necessary because some
** C-compilers still do not accept LL integer literals.
 */

/*
** Possible values for the sqlite3.flags.
**
** Value constraints (enforced via assert()):
**      SQLITE_FullFSync     == PAGER_FULLFSYNC
**      SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
**      SQLITE_CacheSpill    == PAGER_CACHE_SPILL
 */
/*   result set is empty */
/*   DELETE, or UPDATE and return */
/*   the count using a callback. */

/* Flags used only if debugging */

/*
** Allowed values for sqlite3.mDbFlags
 */

/*
** Bits of the sqlite3.dbOptFlags field that are used by the
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
** selectively disable various optimizations.
 */
/* TH3 expects this value  ^^^^^^^^^^ to be 0x0000800. Don't change it */
/* TH3 expects this value  ^^^^^^^^^^ to be 0x40000. Coordinate any change */
/* TH3 expects this value  ^^^^^^^^^^ See flatten04.test */

/*
** Macros for testing whether or not optimizations are enabled or disabled.
 */

/*
** Return true if it OK to factor constant expressions into the initialization
** code. The argument is a Parse object for the code generator.
 */

/* Possible values for the sqlite3.eOpenState field.
** The numbers are randomly selected such that a minimum of three bits must
** change to convert any number to another or to zero
 */

/*
** Each SQL function is defined by an instance of the following
** structure.  For global built-in functions (ex: substr(), max(), count())
** a pointer to this structure is held in the sqlite3BuiltinFunctions object.
** For per-connection application-defined functions, a pointer to this
** structure is held in the db->aHash hash table.
**
** The u.pHash field is used by the global built-ins.  The u.pDestructor
** field is used by per-connection app-def functions.
 */
type TFuncDef1 = struct {
	FnArg      Ti8
	FfuncFlags Tu32
	FpUserData uintptr
	FpNext     uintptr
	FxSFunc    uintptr
	FxFinalize uintptr
	FxValue    uintptr
	FxInverse  uintptr
	FzName     uintptr
	Fu         struct {
		FpDestructor [0]uintptr
		FpHash       uintptr
	}
}

type FuncDef1 = TFuncDef1

/*
** This structure encapsulates a user-function destructor callback (as
** configured using create_function_v2()) and a reference counter. When
** create_function_v2() is called to create a function with a destructor,
** a single object of this type is allocated. FuncDestructor.nRef is set to
** the number of FuncDef objects created (either 1 or 3, depending on whether
** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
** member of each of the new FuncDef objects is set to point to the allocated
** FuncDestructor.
**
** Thereafter, when one of the FuncDef objects is deleted, the reference
** count on this object is decremented. When it reaches 0, the destructor
** is invoked and the FuncDestructor structure freed.
 */
type TFuncDestructor1 = struct {
	FnRef      int32
	FxDestroy  uintptr
	FpUserData uintptr
}

type FuncDestructor1 = TFuncDestructor1

/*
** Possible values for FuncDef.flags.  Note that the _LENGTH and _TYPEOF
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG.  And
** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC.  There
** are assert() statements in the code to verify this.
**
** Value constraints (enforced via assert()):
**     SQLITE_FUNC_MINMAX      ==  NC_MinMaxAgg      == SF_MinMaxAgg
**     SQLITE_FUNC_ANYORDER    ==  NC_OrderAgg       == SF_OrderByReqd
**     SQLITE_FUNC_LENGTH      ==  OPFLAG_LENGTHARG
**     SQLITE_FUNC_TYPEOF      ==  OPFLAG_TYPEOFARG
**     SQLITE_FUNC_BYTELEN     ==  OPFLAG_BYTELENARG
**     SQLITE_FUNC_CONSTANT    ==  SQLITE_DETERMINISTIC from the API
**     SQLITE_FUNC_DIRECT      ==  SQLITE_DIRECTONLY from the API
**     SQLITE_FUNC_UNSAFE      ==  SQLITE_INNOCUOUS  -- opposite meanings!!!
**     SQLITE_FUNC_ENCMASK   depends on SQLITE_UTF* macros in the API
**
** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the
** same bit value, their meanings are inverted.  SQLITE_FUNC_UNSAFE is
** used internally and if set means that the function has side effects.
** SQLITE_INNOCUOUS is used by application code and means "not unsafe".
** See multiple instances of tag-20230109-1.
 */
/*                           0x0200 -- available for reuse */
/* SQLITE_SUBTYPE            0x00100000 // Consumer of subtypes */
/*  SQLITE_RESULT_SUBTYPE    0x01000000 // Generator of subtypes */

/* Identifier numbers for each in-line function */

/*
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
** used to create the initializers for the FuncDef structures.
**
**   FUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Used to create a scalar function definition of a function zName
**     implemented by C function xFunc that accepts nArg arguments. The
**     value passed as iArg is cast to a (void*) and made available
**     as the user-data (sqlite3_user_data()) for the function. If
**     argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
**
**   VFUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
**
**   SFUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
**     adds the SQLITE_DIRECTONLY flag.
**
**   INLINE_FUNC(zName, nArg, iFuncId, mFlags)
**     zName is the name of a function that is implemented by in-line
**     byte code rather than by the usual callbacks. The iFuncId
**     parameter determines the function id.  The mFlags parameter is
**     optional SQLITE_FUNC_ flags for this function.
**
**   TEST_FUNC(zName, nArg, iFuncId, mFlags)
**     zName is the name of a test-only function implemented by in-line
**     byte code rather than by the usual callbacks. The iFuncId
**     parameter determines the function id.  The mFlags parameter is
**     optional SQLITE_FUNC_ flags for this function.
**
**   DFUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
**     adds the SQLITE_FUNC_SLOCHNG flag.  Used for date & time functions
**     and functions like sqlite_version() that can change, but not during
**     a single query.  The iArg is ignored.  The user-data is always set
**     to a NULL pointer.  The bNC parameter is not used.
**
**   MFUNCTION(zName, nArg, xPtr, xFunc)
**     For math-library functions.  xPtr is an arbitrary pointer.
**
**   PURE_DATE(zName, nArg, iArg, bNC, xFunc)
**     Used for "pure" date/time functions, this macro is like DFUNCTION
**     except that it does set the SQLITE_FUNC_CONSTANT flags.  iArg is
**     ignored and the user-data for these functions is set to an
**     arbitrary non-NULL pointer.  The bNC parameter is not used.
**
**   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
**     Used to create an aggregate function definition implemented by
**     the C functions xStep and xFinal. The first four parameters
**     are interpreted in the same way as the first 4 parameters to
**     FUNCTION().
**
**   WAGGREGATE(zName, nArg, iArg, xStep, xFinal, xValue, xInverse)
**     Used to create an aggregate function definition implemented by
**     the C functions xStep and xFinal. The first four parameters
**     are interpreted in the same way as the first 4 parameters to
**     FUNCTION().
**
**   LIKEFUNC(zName, nArg, pArg, flags)
**     Used to create a scalar function definition of a function zName
**     that accepts nArg arguments and is implemented by a call to C
**     function likeFunc. Argument pArg is cast to a (void *) and made
**     available as the function user-data (sqlite3_user_data()). The
**     FuncDef.flags variable is set to the value passed as the flags
**     parameter.
 */

/*
** All current savepoints are stored in a linked list starting at
** sqlite3.pSavepoint. The first element in the list is the most recently
** opened savepoint. Savepoints are added to the list by the vdbe
** OP_Savepoint instruction.
 */
type TSavepoint1 = struct {
	F__ccgo_align     [0]uint32
	FzName            uintptr
	F__ccgo_align1    [4]byte
	FnDeferredCons    Ti64
	FnDeferredImmCons Ti64
	FpNext            uintptr
	F__ccgo_pad4      [4]byte
}

type Savepoint1 = TSavepoint1

/*
** The following are used as the second parameter to sqlite3Savepoint(),
** and as the P1 argument to the OP_Savepoint instruction.
 */

/*
** Each SQLite module (virtual table definition) is defined by an
** instance of the following structure, stored in the sqlite3.aModule
** hash table.
 */
type TModule1 = struct {
	FpModule    uintptr
	FzName      uintptr
	FnRefModule int32
	FpAux       uintptr
	FxDestroy   uintptr
	FpEpoTab    uintptr
}

type Module1 = TModule1

/*
** Information about each column of an SQL table is held in an instance
** of the Column structure, in the Table.aCol[] array.
**
** Definitions:
**
**   "table column index"     This is the index of the column in the
**                            Table.aCol[] array, and also the index of
**                            the column in the original CREATE TABLE stmt.
**
**   "storage column index"   This is the index of the column in the
**                            record BLOB generated by the OP_MakeRecord
**                            opcode.  The storage column index is less than
**                            or equal to the table column index.  It is
**                            equal if and only if there are no VIRTUAL
**                            columns to the left.
**
** Notes on zCnName:
** The zCnName field stores the name of the column, the datatype of the
** column, and the collating sequence for the column, in that order, all in
** a single allocation.  Each string is 0x00 terminated.  The datatype
** is only included if the COLFLAG_HASTYPE bit of colFlags is set and the
** collating sequence name is only included if the COLFLAG_HASCOLL bit is
** set.
 */
type TColumn1 = struct {
	FzCnName  uintptr
	F__ccgo4  uint8
	Faffinity int8
	FszEst    Tu8
	FhName    Tu8
	FiDflt    Tu16
	FcolFlags Tu16
}

type Column1 = TColumn1

/* Allowed values for Column.eCType.
**
** Values must match entries in the global constant arrays
** sqlite3StdTypeLen[] and sqlite3StdType[].  Each value is one more
** than the offset into these arrays for the corresponding name.
** Adjust the SQLITE_N_STDTYPE value if adding or removing entries.
 */

/* Allowed values for Column.colFlags.
**
** Constraints:
**         TF_HasVirtual == COLFLAG_VIRTUAL
**         TF_HasStored  == COLFLAG_STORED
**         TF_HasHidden  == COLFLAG_HIDDEN
 */

/*
** A "Collating Sequence" is defined by an instance of the following
** structure. Conceptually, a collating sequence consists of a name and
** a comparison routine that defines the order of that sequence.
**
** If CollSeq.xCmp is NULL, it means that the
** collating sequence is undefined.  Indices built on an undefined
** collating sequence may not be read or written.
 */
type TCollSeq1 = struct {
	FzName uintptr
	Fenc   Tu8
	FpUser uintptr
	FxCmp  uintptr
	FxDel  uintptr
}

type CollSeq1 = TCollSeq1

/*
** A sort order can be either ASC or DESC.
 */

/*
** Column affinity types.
**
** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
** 't' for SQLITE_AFF_TEXT.  But we can save a little space and improve
** the speed a little by numbering the values consecutively.
**
** But rather than start with 0 or 1, we begin with 'A'.  That way,
** when multiple affinity types are concatenated into a string and
** used as the P4 operand, they will be more readable.
**
** Note also that the numeric types are grouped together so that testing
** for a numeric type is a single comparison.  And the BLOB type is first.
 */

/*
** The SQLITE_AFF_MASK values masks off the significant bits of an
** affinity value.
 */

/*
** Additional bit values that can be ORed with an affinity without
** changing the affinity.
**
** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
** It causes an assert() to fire if either operand to a comparison
** operator is NULL.  It is added to certain comparison operators to
** prove that the operands are always NOT NULL.
 */

/*
** An object of this type is created for each virtual table present in
** the database schema.
**
** If the database schema is shared, then there is one instance of this
** structure for each database connection (sqlite3*) that uses the shared
** schema. This is because each database connection requires its own unique
** instance of the sqlite3_vtab* handle used to access the virtual table
** implementation. sqlite3_vtab* handles can not be shared between
** database connections, even when the rest of the in-memory database
** schema is shared, as the implementation often stores the database
** connection handle passed to it via the xConnect() or xCreate() method
** during initialization internally. This database connection handle may
** then be used by the virtual table implementation to access real tables
** within the database. So that they appear as part of the callers
** transaction, these accesses need to be made via the same database
** connection as that used to execute SQL operations on the virtual table.
**
** All VTable objects that correspond to a single table in a shared
** database schema are initially stored in a linked-list pointed to by
** the Table.pVTable member variable of the corresponding Table object.
** When an sqlite3_prepare() operation is required to access the virtual
** table, it searches the list for the VTable that corresponds to the
** database connection doing the preparing so as to use the correct
** sqlite3_vtab* handle in the compiled query.
**
** When an in-memory Table object is deleted (for example when the
** schema is being reloaded for some reason), the VTable objects are not
** deleted and the sqlite3_vtab* handles are not xDisconnect()ed
** immediately. Instead, they are moved from the Table.pVTable list to
** another linked list headed by the sqlite3.pDisconnect member of the
** corresponding sqlite3 structure. They are then deleted/xDisconnected
** next time a statement is prepared using said sqlite3*. This is done
** to avoid deadlock issues involving multiple sqlite3.mutex mutexes.
** Refer to comments above function sqlite3VtabUnlockList() for an
** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect
** list without holding the corresponding sqlite3.mutex mutex.
**
** The memory for objects of this type is always allocated by
** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
** the first argument.
 */
type TVTable1 = struct {
	Fdb          uintptr
	FpMod        uintptr
	FpVtab       uintptr
	FnRef        int32
	FbConstraint Tu8
	FbAllSchemas Tu8
	FeVtabRisk   Tu8
	FiSavepoint  int32
	FpNext       uintptr
}

type VTable1 = TVTable1

/* Allowed values for VTable.eVtabRisk
 */

/*
** The schema for each SQL table, virtual table, and view is represented
** in memory by an instance of the following structure.
 */
type TTable1 = struct {
	FzName      uintptr
	FaCol       uintptr
	FpIndex     uintptr
	FzColAff    uintptr
	FpCheck     uintptr
	Ftnum       TPgno
	FnTabRef    Tu32
	FtabFlags   Tu32
	FiPKey      Ti16
	FnCol       Ti16
	FnNVCol     Ti16
	FnRowLogEst TLogEst
	FszTabRow   TLogEst
	FkeyConf    Tu8
	FeTabType   Tu8
	Fu          struct {
		Fview [0]struct {
			FpSelect uintptr
		}
		Fvtab [0]struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		}
		Ftab struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		}
	}
	FpTrigger uintptr
	FpSchema  uintptr
}

type Table1 = TTable1

/*
** Allowed values for Table.tabFlags.
**
** TF_OOOHidden applies to tables or view that have hidden columns that are
** followed by non-hidden columns.  Example:  "CREATE VIRTUAL TABLE x USING
** vtab1(a HIDDEN, b);".  Since "b" is a non-hidden column but "a" is hidden,
** the TF_OOOHidden attribute would apply in this case.  Such tables require
** special handling during INSERT processing. The "OOO" means "Out Of Order".
**
** Constraints:
**
**         TF_HasVirtual == COLFLAG_VIRTUAL
**         TF_HasStored  == COLFLAG_STORED
**         TF_HasHidden  == COLFLAG_HIDDEN
 */

/*
** Allowed values for Table.eTabType
 */

/*
** Test to see whether or not a table is a virtual table.  This is
** done as a macro so that it will be optimized out when virtual
** table support is omitted from the build.
 */

/*
** Macros to determine if a column is hidden.  IsOrdinaryHiddenColumn()
** only works for non-virtual tables (ordinary tables and views) and is
** always false unless SQLITE_ENABLE_HIDDEN_COLUMNS is defined.  The
** IsHiddenColumn() macro is general purpose.
 */

/* Does the table have a rowid */

/* Macro is true if the SQLITE_ALLOW_ROWID_IN_VIEW (mis-)feature is
** available.  By default, this macro is false
 */

/*
** Each foreign key constraint is an instance of the following structure.
**
** A foreign key is associated with two tables.  The "from" table is
** the table that contains the REFERENCES clause that creates the foreign
** key.  The "to" table is the table that is named in the REFERENCES clause.
** Consider this example:
**
**     CREATE TABLE ex1(
**       a INTEGER PRIMARY KEY,
**       b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
**     );
**
** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
** Equivalent names:
**
**     from-table == child-table
**       to-table == parent-table
**
** Each REFERENCES clause generates an instance of the following structure
** which is attached to the from-table.  The to-table need not exist when
** the from-table is created.  The existence of the to-table is not checked.
**
** The list of all parents for child Table X is held at X.pFKey.
**
** A list of all children for a table named Z (which might not even exist)
** is held in Schema.fkeyHash with a hash key of Z.
 */
type TFKey1 = struct {
	FpFrom      uintptr
	FpNextFrom  uintptr
	FzTo        uintptr
	FpNextTo    uintptr
	FpPrevTo    uintptr
	FnCol       int32
	FisDeferred Tu8
	FaAction    [2]Tu8
	FapTrigger  [2]uintptr
	FaCol       [1]TsColMap
}

type FKey1 = TFKey1

/*
** SQLite supports many different ways to resolve a constraint
** error.  ROLLBACK processing means that a constraint violation
** causes the operation in process to fail and for the current transaction
** to be rolled back.  ABORT processing means the operation in process
** fails and any prior changes from that one operation are backed out,
** but the transaction is not rolled back.  FAIL processing means that
** the operation in progress stops and returns an error code.  But prior
** changes due to the same operation are not backed out and no rollback
** occurs.  IGNORE means that the particular row that caused the constraint
** error is not inserted or updated.  Processing continues and no error
** is returned.  REPLACE means that preexisting database rows that caused
** a UNIQUE constraint violation are removed so that the new insert or
** update can proceed.  Processing continues and no error is reported.
** UPDATE applies to insert operations only and means that the insert
** is omitted and the DO UPDATE clause of an upsert is run instead.
**
** RESTRICT, SETNULL, SETDFLT, and CASCADE actions apply only to foreign keys.
** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
** same as ROLLBACK for DEFERRED keys.  SETNULL means that the foreign
** key is set to NULL.  SETDFLT means that the foreign key is set
** to its default value.  CASCADE means that a DELETE or UPDATE of the
** referenced table row is propagated into the row that holds the
** foreign key.
**
** The OE_Default value is a place holder that means to use whatever
** conflict resolution algorithm is required from context.
**
** The following symbolic values are used to record which type
** of conflict resolution action to take.
 */

/*
** An instance of the following structure is passed as the first
** argument to sqlite3VdbeKeyCompare and is used to control the
** comparison of the two index keys.
**
** Note that aSortOrder[] and aColl[] have nField+1 slots.  There
** are nField slots for the columns of an index then one extra slot
** for the rowid at the end.
 */
type TKeyInfo1 = struct {
	FnRef       Tu32
	Fenc        Tu8
	FnKeyField  Tu16
	FnAllField  Tu16
	Fdb         uintptr
	FaSortFlags uintptr
	FaColl      [1]uintptr
}

type KeyInfo1 = TKeyInfo1

/*
** Allowed bit values for entries in the KeyInfo.aSortFlags[] array.
 */

/*
** This object holds a record which has been parsed out into individual
** fields, for the purposes of doing a comparison.
**
** A record is an object that contains one or more fields of data.
** Records are used to store the content of a table row and to store
** the key of an index.  A blob encoding of a record is created by
** the OP_MakeRecord opcode of the VDBE and is disassembled by the
** OP_Column opcode.
**
** An instance of this object serves as a "key" for doing a search on
** an index b+tree. The goal of the search is to find the entry that
** is closed to the key described by this object.  This object might hold
** just a prefix of the key.  The number of fields is given by
** pKeyInfo->nField.
**
** The r1 and r2 fields are the values to return if this key is less than
** or greater than a key in the btree, respectively.  These are normally
** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
** is in DESC order.
**
** The key comparison functions actually return default_rc when they find
** an equals comparison.  default_rc can be -1, 0, or +1.  If there are
** multiple entries in the b-tree with the same key (when only looking
** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to
** cause the search to find the last match, or +1 to cause the search to
** find the first match.
**
** The key comparison functions will set eqSeen to true if they ever
** get and equal results when comparing this structure to a b-tree record.
** When default_rc!=0, the search might end up on the record immediately
** before the first match or immediately after the last match.  The
** eqSeen field will indicate whether or not an exact match exists in the
** b-tree.
 */
type TUnpackedRecord1 = struct {
	F__ccgo_align [0]uint32
	FpKeyInfo     uintptr
	FaMem         uintptr
	Fu            struct {
		F__ccgo_align [0]uint32
		Fi            [0]Ti64
		Fz            uintptr
		F__ccgo_pad2  [4]byte
	}
	Fn            int32
	FnField       Tu16
	Fdefault_rc   Ti8
	FerrCode      Tu8
	Fr1           Ti8
	Fr2           Ti8
	FeqSeen       Tu8
	F__ccgo_pad10 [5]byte
}

type UnpackedRecord1 = TUnpackedRecord1

/*
** Each SQL index is represented in memory by an
** instance of the following structure.
**
** The columns of the table that are to be indexed are described
** by the aiColumn[] field of this structure.  For example, suppose
** we have the following table and index:
**
**     CREATE TABLE Ex1(c1 int, c2 int, c3 text);
**     CREATE INDEX Ex2 ON Ex1(c3,c1);
**
** In the Table structure describing Ex1, nCol==3 because there are
** three columns in the table.  In the Index structure describing
** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
** The value of aiColumn is {2, 0}.  aiColumn[0]==2 because the
** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
** The second column to be indexed (c1) has an index of 0 in
** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
**
** The Index.onError field determines whether or not the indexed columns
** must be unique and what to do if they are not.  When Index.onError=OE_None,
** it means this is not a unique index.  Otherwise it is a unique index
** and the value of Index.onError indicates which conflict resolution
** algorithm to employ when an attempt is made to insert a non-unique
** element.
**
** The colNotIdxed bitmask is used in combination with SrcItem.colUsed
** for a fast test to see if an index can serve as a covering index.
** colNotIdxed has a 1 bit for every column of the original table that
** is *not* available in the index.  Thus the expression
** "colUsed & colNotIdxed" will be non-zero if the index is not a
** covering index.  The most significant bit of of colNotIdxed will always
** be true (note-20221022-a).  If a column beyond the 63rd column of the
** table is used, the "colUsed & colNotIdxed" test will always be non-zero
** and we have to assume either that the index is not covering, or use
** an alternative (slower) algorithm to determine whether or not
** the index is covering.
**
** While parsing a CREATE TABLE or CREATE INDEX statement in order to
** generate VDBE code (as opposed to parsing one read from an sqlite_schema
** table as part of parsing an existing database schema), transient instances
** of this structure may be created. In this case the Index.tnum variable is
** used to store the address of a VDBE instruction, not a database page
** number (it cannot - the database page is not allocated until the VDBE
** program is executed). See convertToWithoutRowidTable() for details.
 */
type TIndex1 = struct {
	F__ccgo_align   [0]uint32
	FzName          uintptr
	FaiColumn       uintptr
	FaiRowLogEst    uintptr
	FpTable         uintptr
	FzColAff        uintptr
	FpNext          uintptr
	FpSchema        uintptr
	FaSortOrder     uintptr
	FazColl         uintptr
	FpPartIdxWhere  uintptr
	FaColExpr       uintptr
	Ftnum           TPgno
	FszIdxRow       TLogEst
	FnKeyCol        Tu16
	FnColumn        Tu16
	FonError        Tu8
	F__ccgo56       uint16
	FnSample        int32
	FmxSample       int32
	FnSampleCol     int32
	FaAvgEq         uintptr
	FaSample        uintptr
	FaiRowEst       uintptr
	F__ccgo_align34 [4]byte
	FnRowEst0       TtRowcnt
	FcolNotIdxed    TBitmask
}

type Index1 = TIndex1

/*
** Allowed values for Index.idxType
 */

/* Return true if index X is a PRIMARY KEY index */

/* Return true if index X is a UNIQUE index */

/* The Index.aiColumn[] values are normally positive integer.  But
** there are some negative values that have special meaning:
 */

/*
** Each sample stored in the sqlite_stat4 table is represented in memory
** using a structure of this type.  See documentation at the top of the
** analyze.c source file for additional information.
 */
type TIndexSample1 = struct {
	Fp     uintptr
	Fn     int32
	FanEq  uintptr
	FanLt  uintptr
	FanDLt uintptr
}

type IndexSample1 = TIndexSample1

/*
** Possible values to use within the flags argument to sqlite3GetToken().
 */

/*
** Each token coming out of the lexer is an instance of
** this structure.  Tokens are also used as part of an expression.
**
** The memory that "z" points to is owned by other objects.  Take care
** that the owner of the "z" string does not deallocate the string before
** the Token goes out of scope!  Very often, the "z" points to some place
** in the middle of the Parse.zSql text.  But it might also point to a
** static string.
 */
type TToken1 = struct {
	Fz uintptr
	Fn uint32
}

type Token1 = TToken1

/*
** An instance of this structure contains information needed to generate
** code for a SELECT that contains aggregate functions.
**
** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
** pointer to this structure.  The Expr.iAgg field is the index in
** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
** code for that node.
**
** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
** original Select structure that describes the SELECT statement.  These
** fields do not need to be freed when deallocating the AggInfo structure.
 */
type TAggInfo1 = struct {
	FdirectMode     Tu8
	FuseSortingIdx  Tu8
	FnSortingColumn Tu16
	FsortingIdx     int32
	FsortingIdxPTab int32
	FiFirstReg      int32
	FpGroupBy       uintptr
	FaCol           uintptr
	FnColumn        int32
	FnAccumulator   int32
	FaFunc          uintptr
	FnFunc          int32
	FselId          Tu32
}

type AggInfo1 = TAggInfo1

/*
** Macros to compute aCol[] and aFunc[] register numbers.
**
** These macros should not be used prior to the call to
** assignAggregateRegisters() that computes the value of pAggInfo->iFirstReg.
** The assert()s that are part of this macro verify that constraint.
 */

// C documentation
//
//	/*
//	** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
//	** Usually it is 16-bits.  But if SQLITE_MAX_VARIABLE_NUMBER is greater
//	** than 32767 we have to make it 32-bit.  16-bit is preferred because
//	** it uses less memory in the Expr object, which is a big memory user
//	** in systems with lots of prepared statements.  And few applications
//	** need more than about 10 or 20 variables.  But some extreme users want
//	** to have prepared statements with over 32766 variables, and for them
//	** the option is available (at compile-time).
//	*/
type TynVar = int16

type ynVar = TynVar

/*
** Each node of an expression in the parse tree is an instance
** of this structure.
**
** Expr.op is the opcode. The integer parser token codes are reused
** as opcodes here. For example, the parser defines TK_GE to be an integer
** code representing the ">=" operator. This same integer code is reused
** to represent the greater-than-or-equal-to operator in the expression
** tree.
**
** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If
** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the
** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
** then Expr.u.zToken contains the name of the function.
**
** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
** binary operator. Either or both may be NULL.
**
** Expr.x.pList is a list of arguments if the expression is an SQL function,
** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
** Expr.x.pSelect is used if the expression is a sub-select or an expression of
** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is
** valid.
**
** An expression of the form ID or ID.ID refers to a column in a table.
** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
** the integer cursor number of a VDBE cursor pointing to that table and
** Expr.iColumn is the column number for the specific column.  If the
** expression is used as a result in an aggregate SELECT, then the
** value is also stored in the Expr.iAgg column in the aggregate so that
** it can be accessed after all aggregates are computed.
**
** If the expression is an unbound variable marker (a question mark
** character '?' in the original SQL) then the Expr.iTable holds the index
** number for that variable.
**
** If the expression is a subquery then Expr.iColumn holds an integer
** register number containing the result of the subquery.  If the
** subquery gives a constant result, then iTable is -1.  If the subquery
** gives a different answer at different times during statement processing
** then iTable is the address of a subroutine that computes the subquery.
**
** If the Expr is of type OP_Column, and the table it is selecting from
** is a disk table or the "old.*" pseudo-table, then pTab points to the
** corresponding table definition.
**
** ALLOCATION NOTES:
**
** Expr objects can use a lot of memory space in database schema.  To
** help reduce memory requirements, sometimes an Expr object will be
** truncated.  And to reduce the number of memory allocations, sometimes
** two or more Expr objects will be stored in a single memory allocation,
** together with Expr.u.zToken strings.
**
** If the EP_Reduced and EP_TokenOnly flags are set when
** an Expr object is truncated.  When EP_Reduced is set, then all
** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
** are contained within the same memory allocation.  Note, however, that
** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately
** allocated, regardless of whether or not EP_Reduced is set.
 */
type TExpr1 = struct {
	Fop      Tu8
	FaffExpr int8
	Fop2     Tu8
	Fflags   Tu32
	Fu       struct {
		FiValue [0]int32
		FzToken uintptr
	}
	FpLeft  uintptr
	FpRight uintptr
	Fx      struct {
		FpSelect [0]uintptr
		FpList   uintptr
	}
	FnHeight int32
	FiTable  int32
	FiColumn TynVar
	FiAgg    Ti16
	Fw       struct {
		FiOfst [0]int32
		FiJoin int32
	}
	FpAggInfo uintptr
	Fy        struct {
		FpWin [0]uintptr
		Fsub  [0]struct {
			FiAddr     int32
			FregReturn int32
		}
		FpTab        uintptr
		F__ccgo_pad3 [4]byte
	}
}

type Expr1 = TExpr1

/* The following are the meanings of bits in the Expr.flags field.
** Value restrictions:
**
**          EP_Agg == NC_HasAgg == SF_HasAgg
**          EP_Win == NC_HasWin
 */
/*   0x80000000 // Available */

/* The EP_Propagate mask is a set of properties that automatically propagate
** upwards into parent nodes.
 */

/* Macros can be used to test, set, or clear bits in the
** Expr.flags field.
 */

/* Macros used to ensure that the correct members of unions are accessed
** in Expr.
 */

/* Flags for use with Expr.vvaFlags
 */

/* The ExprSetVVAProperty() macro is used for Verification, Validation,
** and Accreditation only.  It works like ExprSetProperty() during VVA
** processes but is a no-op for delivery.
 */

/*
** Macros to determine the number of bytes required by a normal Expr
** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
** and an Expr struct with the EP_TokenOnly flag set.
 */

/*
** Flags passed to the sqlite3ExprDup() function. See the header comment
** above sqlite3ExprDup() for details.
 */

/*
** True if the expression passed as an argument was a function with
** an OVER() clause (a window function).
 */

/*
** A list of expressions.  Each expression may optionally have a
** name.  An expr/name combination can be used in several ways, such
** as the list of "expr AS ID" fields following a "SELECT" or in the
** list of "ID = expr" items in an UPDATE.  A list of expressions can
** also be used as the argument to a function, in which case the a.zName
** field is not used.
**
** In order to try to keep memory usage down, the Expr.a.zEName field
** is used for multiple purposes:
**
**     eEName          Usage
**    ----------       -------------------------
**    ENAME_NAME       (1) the AS of result set column
**                     (2) COLUMN= of an UPDATE
**
**    ENAME_TAB        DB.TABLE.NAME used to resolve names
**                     of subqueries
**
**    ENAME_SPAN       Text of the original result set
**                     expression.
 */
type TExprList1 = struct {
	FnExpr  int32
	FnAlloc int32
	Fa      [1]TExprList_item
}

type ExprList1 = TExprList1

/*
** Allowed values for Expr.a.eEName
 */

/*
** An instance of this structure can hold a simple list of identifiers,
** such as the list "a,b,c" in the following statements:
**
**      INSERT INTO t(a,b,c) VALUES ...;
**      CREATE INDEX idx ON t(a,b,c);
**      CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
**
** The IdList.a.idx field is used when the IdList represents the list of
** column names after a table name in an INSERT statement.  In the statement
**
**     INSERT INTO t(a,b,c) ...
**
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
 */
type TIdList1 = struct {
	FnId int32
	FeU4 Tu8
	Fa   [1]TIdList_item
}

type IdList1 = TIdList1

/*
** Allowed values for IdList.eType, which determines which value of the a.u4
** is valid.
 */

/*
** The SrcItem object represents a single term in the FROM clause of a query.
** The SrcList object is mostly an array of SrcItems.
**
** The jointype starts out showing the join type between the current table
** and the next table on the list.  The parser builds the list this way.
** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
** jointype expresses the join between the table and the previous table.
**
** In the colUsed field, the high-order bit (bit 63) is set if the table
** contains more than 63 columns and the 64-th or later column is used.
**
** Union member validity:
**
**    u1.zIndexedBy      fg.isIndexedBy && !fg.isTabFunc
**    u1.pFuncArg        fg.isTabFunc   && !fg.isIndexedBy
**    u1.nRow            !fg.isTabFunc  && !fg.isIndexedBy
**
**    u2.pIBIndex        fg.isIndexedBy && !fg.isCte
**    u2.pCteUse         fg.isCte       && !fg.isIndexedBy
 */
type TSrcItem1 = struct {
	F__ccgo_align [0]uint32
	FpSchema      uintptr
	FzDatabase    uintptr
	FzName        uintptr
	FzAlias       uintptr
	FpTab         uintptr
	FpSelect      uintptr
	FaddrFillSub  int32
	FregReturn    int32
	FregResult    int32
	Ffg           struct {
		F__ccgo_align  [0]uint32
		Fjointype      Tu8
		F__ccgo_align1 [2]byte
		F__ccgo4       uint16
	}
	FiCursor int32
	Fu3      struct {
		FpUsing [0]uintptr
		FpOn    uintptr
	}
	F__ccgo_align12 [4]byte
	FcolUsed        TBitmask
	Fu1             struct {
		FpFuncArg   [0]uintptr
		FnRow       [0]Tu32
		FzIndexedBy uintptr
	}
	Fu2 struct {
		FpCteUse  [0]uintptr
		FpIBIndex uintptr
	}
}

type SrcItem1 = TSrcItem1

/*
** The OnOrUsing object represents either an ON clause or a USING clause.
** It can never be both at the same time, but it can be neither.
 */
type TOnOrUsing1 = struct {
	FpOn    uintptr
	FpUsing uintptr
}

type OnOrUsing1 = TOnOrUsing1

/*
** This object represents one or more tables that are the source of
** content for an SQL statement.  For example, a single SrcList object
** is used to hold the FROM clause of a SELECT statement.  SrcList also
** represents the target tables for DELETE, INSERT, and UPDATE statements.
**
 */
type TSrcList1 = struct {
	F__ccgo_align [0]uint32
	FnSrc         int32
	FnAlloc       Tu32
	Fa            [1]TSrcItem
}

type SrcList1 = TSrcList1

/*
** Permitted values of the SrcList.a.jointype field
 */

/*
** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
** and the WhereInfo.wctrlFlags member.
**
** Value constraints (enforced via assert()):
**     WHERE_USE_LIMIT  == SF_FixedLimit
 */
/*     0x2000    not currently used */
/*     0x8000    not currently used */

/* Allowed return values from sqlite3WhereIsDistinct()
 */

/*
** A NameContext defines a context in which to resolve table and column
** names.  The context consists of a list of tables (the pSrcList) field and
** a list of named expression (pEList).  The named expression list may
** be NULL.  The pSrc corresponds to the FROM clause of a SELECT or
** to the table being operated on by INSERT, UPDATE, or DELETE.  The
** pEList corresponds to the result set of a SELECT and is NULL for
** other statements.
**
** NameContexts can be nested.  When resolving names, the inner-most
** context is searched first.  If no match is found, the next outer
** context is checked.  If there is still no match, the next context
** is checked.  This process continues until either a match is found
** or all contexts are check.  When a match is found, the nRef member of
** the context containing the match is incremented.
**
** Each subquery gets a new NameContext.  The pNext field points to the
** NameContext in the parent query.  Thus the process of scanning the
** NameContext list corresponds to searching through successively outer
** subqueries looking for a match.
 */
type TNameContext1 = struct {
	FpParse   uintptr
	FpSrcList uintptr
	FuNC      struct {
		FpAggInfo [0]uintptr
		FpUpsert  [0]uintptr
		FiBaseReg [0]int32
		FpEList   uintptr
	}
	FpNext         uintptr
	FnRef          int32
	FnNcErr        int32
	FncFlags       int32
	FnNestedSelect Tu32
	FpWinSelect    uintptr
}

type NameContext1 = TNameContext1

/*
** Allowed values for the NameContext, ncFlags field.
**
** Value constraints (all checked via assert()):
**    NC_HasAgg    == SF_HasAgg       == EP_Agg
**    NC_MinMaxAgg == SF_MinMaxAgg    == SQLITE_FUNC_MINMAX
**    NC_OrderAgg  == SF_OrderByReqd  == SQLITE_FUNC_ANYORDER
**    NC_HasWin    == EP_Win
**
 */

/*
** An instance of the following object describes a single ON CONFLICT
** clause in an upsert.
**
** The pUpsertTarget field is only set if the ON CONFLICT clause includes
** conflict-target clause.  (In "ON CONFLICT(a,b)" the "(a,b)" is the
** conflict-target clause.)  The pUpsertTargetWhere is the optional
** WHERE clause used to identify partial unique indexes.
**
** pUpsertSet is the list of column=expr terms of the UPDATE statement.
** The pUpsertSet field is NULL for a ON CONFLICT DO NOTHING.  The
** pUpsertWhere is the WHERE clause for the UPDATE and is NULL if the
** WHERE clause is omitted.
 */
type TUpsert1 = struct {
	FpUpsertTarget      uintptr
	FpUpsertTargetWhere uintptr
	FpUpsertSet         uintptr
	FpUpsertWhere       uintptr
	FpNextUpsert        uintptr
	FisDoUpdate         Tu8
	FisDup              Tu8
	FpToFree            uintptr
	FpUpsertIdx         uintptr
	FpUpsertSrc         uintptr
	FregData            int32
	FiDataCur           int32
	FiIdxCur            int32
}

type Upsert1 = TUpsert1

/*
** An instance of the following structure contains all information
** needed to generate code for a single SELECT statement.
**
** See the header comment on the computeLimitRegisters() routine for a
** detailed description of the meaning of the iLimit and iOffset fields.
**
** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
** These addresses must be stored so that we can go back and fill in
** the P4_KEYINFO and P2 parameters later.  Neither the KeyInfo nor
** the number of columns in P2 can be computed at the same time
** as the OP_OpenEphm instruction is coded because not
** enough information about the compound query is known at that point.
** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
** for the result set.  The KeyInfo for addrOpenEphm[2] contains collating
** sequences for the ORDER BY clause.
 */
type TSelect1 = struct {
	Fop           Tu8
	FnSelectRow   TLogEst
	FselFlags     Tu32
	FiLimit       int32
	FiOffset      int32
	FselId        Tu32
	FaddrOpenEphm [2]int32
	FpEList       uintptr
	FpSrc         uintptr
	FpWhere       uintptr
	FpGroupBy     uintptr
	FpHaving      uintptr
	FpOrderBy     uintptr
	FpPrior       uintptr
	FpNext        uintptr
	FpLimit       uintptr
	FpWith        uintptr
	FpWin         uintptr
	FpWinDefn     uintptr
}

type Select1 = TSelect1

/*
** Allowed values for Select.selFlags.  The "SF" prefix stands for
** "Select Flag".
**
** Value constraints (all checked via assert())
**     SF_HasAgg      == NC_HasAgg
**     SF_MinMaxAgg   == NC_MinMaxAgg     == SQLITE_FUNC_MINMAX
**     SF_OrderByReqd == NC_OrderAgg      == SQLITE_FUNC_ANYORDER
**     SF_FixedLimit  == WHERE_USE_LIMIT
 */

/* True if S exists and has SF_NestedFrom */

/*
** The results of a SELECT can be distributed in several ways, as defined
** by one of the following macros.  The "SRT" prefix means "SELECT Result
** Type".
**
**     SRT_Union       Store results as a key in a temporary index
**                     identified by pDest->iSDParm.
**
**     SRT_Except      Remove results from the temporary index pDest->iSDParm.
**
**     SRT_Exists      Store a 1 in memory cell pDest->iSDParm if the result
**                     set is not empty.
**
**     SRT_Discard     Throw the results away.  This is used by SELECT
**                     statements within triggers whose only purpose is
**                     the side-effects of functions.
**
**     SRT_Output      Generate a row of output (using the OP_ResultRow
**                     opcode) for each row in the result set.
**
**     SRT_Mem         Only valid if the result is a single column.
**                     Store the first column of the first result row
**                     in register pDest->iSDParm then abandon the rest
**                     of the query.  This destination implies "LIMIT 1".
**
**     SRT_Set         The result must be a single column.  Store each
**                     row of result as the key in table pDest->iSDParm.
**                     Apply the affinity pDest->affSdst before storing
**                     results.  Used to implement "IN (SELECT ...)".
**
**     SRT_EphemTab    Create an temporary table pDest->iSDParm and store
**                     the result there. The cursor is left open after
**                     returning.  This is like SRT_Table except that
**                     this destination uses OP_OpenEphemeral to create
**                     the table first.
**
**     SRT_Coroutine   Generate a co-routine that returns a new row of
**                     results each time it is invoked.  The entry point
**                     of the co-routine is stored in register pDest->iSDParm
**                     and the result row is stored in pDest->nDest registers
**                     starting with pDest->iSdst.
**
**     SRT_Table       Store results in temporary table pDest->iSDParm.
**     SRT_Fifo        This is like SRT_EphemTab except that the table
**                     is assumed to already be open.  SRT_Fifo has
**                     the additional property of being able to ignore
**                     the ORDER BY clause.
**
**     SRT_DistFifo    Store results in a temporary table pDest->iSDParm.
**                     But also use temporary table pDest->iSDParm+1 as
**                     a record of all prior results and ignore any duplicate
**                     rows.  Name means:  "Distinct Fifo".
**
**     SRT_Queue       Store results in priority queue pDest->iSDParm (really
**                     an index).  Append a sequence number so that all entries
**                     are distinct.
**
**     SRT_DistQueue   Store results in priority queue pDest->iSDParm only if
**                     the same record has never been stored before.  The
**                     index at pDest->iSDParm+1 hold all prior stores.
**
**     SRT_Upfrom      Store results in the temporary table already opened by
**                     pDest->iSDParm. If (pDest->iSDParm<0), then the temp
**                     table is an intkey table - in this case the first
**                     column returned by the SELECT is used as the integer
**                     key. If (pDest->iSDParm>0), then the table is an index
**                     table. (pDest->iSDParm) is the number of key columns in
**                     each index record in this case.
 */

/* The DISTINCT clause is ignored for all of the above.  Not that
** IgnorableDistinct() implies IgnorableOrderby() */

/* The ORDER BY clause is ignored for all of the above */

/*
** An instance of this object describes where to put of the results of
** a SELECT statement.
 */
type TSelectDest1 = struct {
	FeDest    Tu8
	FiSDParm  int32
	FiSDParm2 int32
	FiSdst    int32
	FnSdst    int32
	FzAffSdst uintptr
	FpOrderBy uintptr
}

type SelectDest1 = TSelectDest1

/*
** During code generation of statements that do inserts into AUTOINCREMENT
** tables, the following information is attached to the Table.u.autoInc.p
** pointer of each autoincrement table to record some side information that
** the code generator needs.  We have to keep per-table autoincrement
** information in case inserts are done within triggers.  Triggers do not
** normally coordinate their activities, but we do need to coordinate the
** loading and saving of autoincrement information.
 */
type TAutoincInfo1 = struct {
	FpNext  uintptr
	FpTab   uintptr
	FiDb    int32
	FregCtr int32
}

type AutoincInfo1 = TAutoincInfo1

/*
** At least one instance of the following structure is created for each
** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
** statement. All such objects are stored in the linked list headed at
** Parse.pTriggerPrg and deleted once statement compilation has been
** completed.
**
** A Vdbe sub-program that implements the body and WHEN clause of trigger
** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of
** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
** The Parse.pTriggerPrg list never contains two entries with the same
** values for both pTrigger and orconf.
**
** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
** accessed (or set to 0 for triggers fired as a result of INSERT
** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to
** a mask of new.* columns used by the program.
 */
type TTriggerPrg1 = struct {
	FpTrigger uintptr
	FpNext    uintptr
	FpProgram uintptr
	Forconf   int32
	FaColmask [2]Tu32
}

type TriggerPrg1 = TTriggerPrg1

// C documentation
//
//	/*
//	** The yDbMask datatype for the bitmask of all attached databases.
//	*/
type TyDbMask = uint32

type yDbMask = TyDbMask

/*
** For each index X that has as one of its arguments either an expression
** or the name of a virtual generated column, and if X is in scope such that
** the value of the expression can simply be read from the index, then
** there is an instance of this object on the Parse.pIdxExpr list.
**
** During code generation, while generating code to evaluate expressions,
** this list is consulted and if a matching expression is found, the value
** is read from the index rather than being recomputed.
 */
type TIndexedExpr1 = struct {
	FpExpr         uintptr
	FiDataCur      int32
	FiIdxCur       int32
	FiIdxCol       int32
	FbMaybeNullRow Tu8
	Faff           Tu8
	FpIENext       uintptr
}

type IndexedExpr1 = TIndexedExpr1

/*
** An instance of the ParseCleanup object specifies an operation that
** should be performed after parsing to deallocation resources obtained
** during the parse and which are no longer needed.
 */
type TParseCleanup1 = struct {
	FpNext    uintptr
	FpPtr     uintptr
	FxCleanup uintptr
}

type ParseCleanup1 = TParseCleanup1

/*
** An SQL parser context.  A copy of this structure is passed through
** the parser and down into all the parser action routine in order to
** carry around information that is global to the entire parse.
**
** The structure is divided into two parts.  When the parser and code
** generate call themselves recursively, the first part of the structure
** is constant but the second part is reset at the beginning and end of
** each recursion.
**
** The nTableLock and aTableLock variables are only used if the shared-cache
** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
** used to store the set of table-locks required by the statement being
** compiled. Function sqlite3TableLock() is used to add entries to the
** list.
 */
type TParse1 = struct {
	Fdb               uintptr
	FzErrMsg          uintptr
	FpVdbe            uintptr
	Frc               int32
	FcolNamesSet      Tu8
	FcheckSchema      Tu8
	Fnested           Tu8
	FnTempReg         Tu8
	FisMultiWrite     Tu8
	FmayAbort         Tu8
	FhasCompound      Tu8
	FokConstFactor    Tu8
	FdisableLookaside Tu8
	FprepFlags        Tu8
	FwithinRJSubrtn   Tu8
	FbHasWith         Tu8
	FnRangeReg        int32
	FiRangeReg        int32
	FnErr             int32
	FnTab             int32
	FnMem             int32
	FszOpAlloc        int32
	FiSelfTab         int32
	FnLabel           int32
	FnLabelAlloc      int32
	FaLabel           uintptr
	FpConstExpr       uintptr
	FpIdxEpr          uintptr
	FpIdxPartExpr     uintptr
	FconstraintName   TToken
	FwriteMask        TyDbMask
	FcookieMask       TyDbMask
	FregRowid         int32
	FregRoot          int32
	FnMaxArg          int32
	FnSelect          int32
	FnProgressSteps   Tu32
	FnTableLock       int32
	FaTableLock       uintptr
	FpAinc            uintptr
	FpToplevel        uintptr
	FpTriggerTab      uintptr
	FpTriggerPrg      uintptr
	FpCleanup         uintptr
	Fu1               struct {
		FpReturning [0]uintptr
		FaddrCrTab  int32
	}
	Foldmask         Tu32
	Fnewmask         Tu32
	FnQueryLoop      TLogEst
	FeTriggerOp      Tu8
	FbReturning      Tu8
	FeOrconf         Tu8
	FdisableTriggers Tu8
	FaTempReg        [8]int32
	FpOuterParse     uintptr
	FsNameToken      TToken
	FsLastToken      TToken
	FnVar            TynVar
	FiPkSortOrder    Tu8
	Fexplain         Tu8
	FeParseMode      Tu8
	FnVtabLock       int32
	FnHeight         int32
	FaddrExplain     int32
	FpVList          uintptr
	FpReprepare      uintptr
	FzTail           uintptr
	FpNewTable       uintptr
	FpNewIndex       uintptr
	FpNewTrigger     uintptr
	FzAuthContext    uintptr
	FsArg            TToken
	FapVtabLock      uintptr
	FpWith           uintptr
	FpRename         uintptr
}

type Parse1 = TParse1

/* Allowed values for Parse.eParseMode
 */

/*
** Sizes and pointers of various parts of the Parse object.
 */

/*
** Return true if currently inside an sqlite3_declare_vtab() call.
 */

/*
** An instance of the following structure can be declared on a stack and used
** to save the Parse.zAuthContext value so that it can be restored later.
 */
type TAuthContext1 = struct {
	FzAuthContext uintptr
	FpParse       uintptr
}

type AuthContext1 = TAuthContext1

/*
** Bitfield flags for P5 value in various opcodes.
**
** Value constraints (enforced via assert()):
**    OPFLAG_LENGTHARG    == SQLITE_FUNC_LENGTH
**    OPFLAG_TYPEOFARG    == SQLITE_FUNC_TYPEOF
**    OPFLAG_BULKCSR      == BTREE_BULKLOAD
**    OPFLAG_SEEKEQ       == BTREE_SEEK_EQ
**    OPFLAG_FORDELETE    == BTREE_FORDELETE
**    OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
**    OPFLAG_AUXDELETE    == BTREE_AUXDELETE
 */
/* Also used in P2 (not P5) of OP_Delete */

/*
** Each trigger present in the database schema is stored as an instance of
** struct Trigger.
**
** Pointers to instances of struct Trigger are stored in two ways.
** 1. In the "trigHash" hash table (part of the sqlite3* that represents the
**    database). This allows Trigger structures to be retrieved by name.
** 2. All triggers associated with a single table form a linked list, using the
**    pNext member of struct Trigger. A pointer to the first element of the
**    linked list is stored as the "pTrigger" member of the associated
**    struct Table.
**
** The "step_list" member points to the first element of a linked list
** containing the SQL statements specified as the trigger program.
 */
type TTrigger1 = struct {
	FzName      uintptr
	Ftable      uintptr
	Fop         Tu8
	Ftr_tm      Tu8
	FbReturning Tu8
	FpWhen      uintptr
	FpColumns   uintptr
	FpSchema    uintptr
	FpTabSchema uintptr
	Fstep_list  uintptr
	FpNext      uintptr
}

type Trigger1 = TTrigger1

/*
** A trigger is either a BEFORE or an AFTER trigger.  The following constants
** determine which.
**
** If there are multiple triggers, you might of some BEFORE and some AFTER.
** In that cases, the constants below can be ORed together.
 */

/*
** An instance of struct TriggerStep is used to store a single SQL statement
** that is a part of a trigger-program.
**
** Instances of struct TriggerStep are stored in a singly linked list (linked
** using the "pNext" member) referenced by the "step_list" member of the
** associated struct Trigger instance. The first element of the linked list is
** the first step of the trigger-program.
**
** The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
** "SELECT" statement. The meanings of the other members is determined by the
** value of "op" as follows:
**
** (op == TK_INSERT)
** orconf    -> stores the ON CONFLICT algorithm
** pSelect   -> The content to be inserted - either a SELECT statement or
**              a VALUES clause.
** zTarget   -> Dequoted name of the table to insert into.
** pIdList   -> If this is an INSERT INTO ... (<column-names>) VALUES ...
**              statement, then this stores the column-names to be
**              inserted into.
** pUpsert   -> The ON CONFLICT clauses for an Upsert
**
** (op == TK_DELETE)
** zTarget   -> Dequoted name of the table to delete from.
** pWhere    -> The WHERE clause of the DELETE statement if one is specified.
**              Otherwise NULL.
**
** (op == TK_UPDATE)
** zTarget   -> Dequoted name of the table to update.
** pWhere    -> The WHERE clause of the UPDATE statement if one is specified.
**              Otherwise NULL.
** pExprList -> A list of the columns to update and the expressions to update
**              them to. See sqlite3Update() documentation of "pChanges"
**              argument.
**
** (op == TK_SELECT)
** pSelect   -> The SELECT statement
**
** (op == TK_RETURNING)
** pExprList -> The list of expressions that follow the RETURNING keyword.
**
 */
type TTriggerStep1 = struct {
	Fop        Tu8
	Forconf    Tu8
	FpTrig     uintptr
	FpSelect   uintptr
	FzTarget   uintptr
	FpFrom     uintptr
	FpWhere    uintptr
	FpExprList uintptr
	FpIdList   uintptr
	FpUpsert   uintptr
	FzSpan     uintptr
	FpNext     uintptr
	FpLast     uintptr
}

type TriggerStep1 = TTriggerStep1

/*
** Information about a RETURNING clause
 */
type TReturning1 = struct {
	FpParse    uintptr
	FpReturnEL uintptr
	FretTrig   TTrigger
	FretTStep  TTriggerStep
	FiRetCur   int32
	FnRetCol   int32
	FiRetReg   int32
	FzName     [40]int8
}

type Returning1 = TReturning1

/*
** The following object is the header for an "RCStr" or "reference-counted
** string".  An RCStr is passed around and used like any other char*
** that has been dynamically allocated.  The important interface
** differences:
**
**   1.  RCStr strings are reference counted.  They are deallocated
**       when the reference count reaches zero.
**
**   2.  Use sqlite3RCStrUnref() to free an RCStr string rather than
**       sqlite3_free()
**
**   3.  Make a (read-only) copy of a read-only RCStr string using
**       sqlite3RCStrRef().
**
** "String" is in the name, but an RCStr object can also be used to hold
** binary data.
 */
type TRCStr1 = struct {
	F__ccgo_align [0]uint32
	FnRCRef       Tu64
}

type RCStr1 = TRCStr1

// C documentation
//
//	/*
//	** A pointer to this structure is used to communicate information
//	** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
//	*/
type TInitData = struct {
	Fdb         uintptr
	FpzErrMsg   uintptr
	FiDb        int32
	Frc         int32
	FmInitFlags Tu32
	FnInitRow   Tu32
	FmxPage     TPgno
}

type InitData = TInitData

/*
** Allowed values for mInitFlags
 */

/* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
** on debug-builds of the CLI using ".testctrl tune ID VALUE".  Tuning
** parameters are for temporary use during development, to help find
** optimal values for parameters in the query planner.  The should not
** be used on trunk check-ins.  They are a temporary mechanism available
** for transient development builds only.
**
** Tuning parameters are numbered starting with 1.
 */

/*
** Structure containing global configuration data for the SQLite library.
**
** This structure also contains some state information.
 */
type TSqlite3Config = struct {
	F__ccgo_align        [0]uint32
	FbMemstat            int32
	FbCoreMutex          Tu8
	FbFullMutex          Tu8
	FbOpenUri            Tu8
	FbUseCis             Tu8
	FbSmallMalloc        Tu8
	FbExtraSchemaChecks  Tu8
	FbUseLongDouble      Tu8
	FmxStrlen            int32
	FneverCorrupt        int32
	FszLookaside         int32
	FnLookaside          int32
	FnStmtSpill          int32
	Fm                   Tsqlite3_mem_methods
	Fmutex               Tsqlite3_mutex_methods
	Fpcache2             Tsqlite3_pcache_methods2
	FpHeap               uintptr
	FnHeap               int32
	FmnReq               int32
	FmxReq               int32
	FszMmap              Tsqlite3_int64
	FmxMmap              Tsqlite3_int64
	FpPage               uintptr
	FszPage              int32
	FnPage               int32
	FmxParserStack       int32
	FsharedCacheEnabled  int32
	FszPma               Tu32
	FisInit              int32
	FinProgress          int32
	FisMutexInit         int32
	FisMallocInit        int32
	FisPCacheInit        int32
	FnRefInitMutex       int32
	FpInitMutex          uintptr
	FxLog                uintptr
	FpLogArg             uintptr
	F__ccgo_align37      [4]byte
	FmxMemdbSize         Tsqlite3_int64
	FxTestCallback       uintptr
	FbLocaltimeFault     int32
	FxAltLocaltime       uintptr
	FiOnceResetThreshold int32
	FszSorterRef         Tu32
	FiPrngSeed           uint32
}

type Sqlite3Config = TSqlite3Config

/*
** This macro is used inside of assert() statements to indicate that
** the assert is only valid on a well-formed database.  Instead of:
**
**     assert( X );
**
** One writes:
**
**     assert( X || CORRUPT_DB );
**
** CORRUPT_DB is true during normal operation.  CORRUPT_DB does not indicate
** that the database is definitely corrupt, only that it might be corrupt.
** For most test cases, CORRUPT_DB is set to false using a special
** sqlite3_test_control().  This enables assert() statements to prove
** things that are always true for well-formed databases.
 */

/*
** Context pointer passed down through the tree-walk.
 */
type TWalker1 = struct {
	FpParse           uintptr
	FxExprCallback    uintptr
	FxSelectCallback  uintptr
	FxSelectCallback2 uintptr
	FwalkerDepth      int32
	FeCode            Tu16
	FmWFlags          Tu16
	Fu                struct {
		Fn           [0]int32
		FiCur        [0]int32
		FpSrcList    [0]uintptr
		FpCCurHint   [0]uintptr
		FpRefSrcList [0]uintptr
		FaiCol       [0]uintptr
		FpIdxCover   [0]uintptr
		FpGroupBy    [0]uintptr
		FpSelect     [0]uintptr
		FpRewrite    [0]uintptr
		FpConst      [0]uintptr
		FpRename     [0]uintptr
		FpTab        [0]uintptr
		FpCovIdxCk   [0]uintptr
		FpSrcItem    [0]uintptr
		FpFix        [0]uintptr
		FaMem        [0]uintptr
		FpNC         uintptr
	}
}

type Walker1 = TWalker1

/*
** The following structure contains information used by the sqliteFix...
** routines as they walk the parse tree to make database references
** explicit.
 */
type TDbFixer1 = struct {
	FpParse  uintptr
	Fw       TWalker
	FpSchema uintptr
	FbTemp   Tu8
	FzDb     uintptr
	FzType   uintptr
	FpName   uintptr
}

type DbFixer1 = TDbFixer1

/*
** Return code from the parse-tree walking primitives and their
** callbacks.
 */

/*
** A single common table expression
 */
type TCte1 = struct {
	FzName   uintptr
	FpCols   uintptr
	FpSelect uintptr
	FzCteErr uintptr
	FpUse    uintptr
	FeM10d   Tu8
}

type Cte1 = TCte1

/*
** Allowed values for the materialized flag (eM10d):
 */

/*
** An instance of the With object represents a WITH clause containing
** one or more CTEs (common table expressions).
 */
type TWith1 = struct {
	FnCte   int32
	FbView  int32
	FpOuter uintptr
	Fa      [1]TCte
}

type With1 = TWith1

/*
** The Cte object is not guaranteed to persist for the entire duration
** of code generation.  (The query flattener or other parser tree
** edits might delete it.)  The following object records information
** about each Common Table Expression that must be preserved for the
** duration of the parse.
**
** The CteUse objects are freed using sqlite3ParserAddCleanup() rather
** than sqlite3SelectDelete(), which is what enables them to persist
** until the end of code generation.
 */
type TCteUse1 = struct {
	FnUse    int32
	FaddrM9e int32
	FregRtn  int32
	FiCur    int32
	FnRowEst TLogEst
	FeM10d   Tu8
}

type CteUse1 = TCteUse1

/* Client data associated with sqlite3_set_clientdata() and
** sqlite3_get_clientdata().
 */
type TDbClientData1 = struct {
	FpNext       uintptr
	FpData       uintptr
	FxDestructor uintptr
	FzName       [1]int8
}

type DbClientData1 = TDbClientData1

/*
** This object is used in various ways, most (but not all) related to window
** functions.
**
**   (1) A single instance of this structure is attached to the
**       the Expr.y.pWin field for each window function in an expression tree.
**       This object holds the information contained in the OVER clause,
**       plus additional fields used during code generation.
**
**   (2) All window functions in a single SELECT form a linked-list
**       attached to Select.pWin.  The Window.pFunc and Window.pExpr
**       fields point back to the expression that is the window function.
**
**   (3) The terms of the WINDOW clause of a SELECT are instances of this
**       object on a linked list attached to Select.pWinDefn.
**
**   (4) For an aggregate function with a FILTER clause, an instance
**       of this object is stored in Expr.y.pWin with eFrmType set to
**       TK_FILTER. In this case the only field used is Window.pFilter.
**
** The uses (1) and (2) are really the same Window object that just happens
** to be accessible in two different ways.  Use case (3) are separate objects.
 */
type TWindow1 = struct {
	FzName          uintptr
	FzBase          uintptr
	FpPartition     uintptr
	FpOrderBy       uintptr
	FeFrmType       Tu8
	FeStart         Tu8
	FeEnd           Tu8
	FbImplicitFrame Tu8
	FeExclude       Tu8
	FpStart         uintptr
	FpEnd           uintptr
	FppThis         uintptr
	FpNextWin       uintptr
	FpFilter        uintptr
	FpWFunc         uintptr
	FiEphCsr        int32
	FregAccum       int32
	FregResult      int32
	FcsrApp         int32
	FregApp         int32
	FregPart        int32
	FpOwner         uintptr
	FnBufferCol     int32
	FiArgCol        int32
	FregOne         int32
	FregStartRowid  int32
	FregEndRowid    int32
	FbExprArgs      Tu8
}

type Window1 = TWindow1

/*
** An instance of the following structure holds information about SQL
** functions arguments that are the parameters to the printf() function.
 */
type TPrintfArguments1 = struct {
	FnArg  int32
	FnUsed int32
	FapArg uintptr
}

type PrintfArguments1 = TPrintfArguments1

/*
** An instance of this object receives the decoding of a floating point
** value into an approximate decimal representation.
 */
type TFpDecode1 = struct {
	Fsign      int8
	FisSpecial int8
	Fn         int32
	FiDP       int32
	Fz         uintptr
	FzBuf      [24]int8
}

type FpDecode1 = TFpDecode1

/************** End of sqliteInt.h *******************************************/
/************** Begin file os_common.h ***************************************/
/*
** 2004 May 22
**
** 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 macros and a little bit of code that is common to
** all of the platform-specific files (os_*.c) and is #included into those
** files.
**
** This file should be #included by the os_*.c files only.  It is not a
** general purpose header file.
 */

/*
** At least two bugs have slipped in because we changed the MEMORY_DEBUG
** macro to SQLITE_DEBUG and some older makefiles have not yet made the
** switch.  The following code should catch this problem at compile-time.
 */

/*
** Macros for performance tracing.  Normally turned off.  Only works
** on i486 hardware.
 */

/*
** If we compile with the SQLITE_TEST macro set, then the following block
** of code will give us the ability to simulate a disk I/O error.  This
** is used for testing the I/O recovery logic.
 */

/*
** When testing, keep a count of the number of open files.
 */

/************** End of os_common.h *******************************************/
/************** Begin file ctime.c *******************************************/
/* DO NOT EDIT!
** This file is automatically generated by the script in the canonical
** SQLite source tree at tool/mkctimec.tcl.
**
** To modify this header, edit any of the various lists in that script
** which specify categories of generated conditionals in this file.
 */

/*
** 2010 February 23
**
** 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 implements routines used to report what compile-time options
** SQLite was built with.
 */

/*
** Include the configuration header output by 'configure' if we're using the
** autoconf-based build
 */

/* These macros are provided to "stringify" the value of the define
** for those options in which the value is meaningful. */

/* Like CTIMEOPT_VAL, but especially for SQLITE_DEFAULT_LOOKASIDE. This
** option requires a separate macro because legal values contain a single
** comma. e.g. (-DSQLITE_DEFAULT_LOOKASIDE="100,100") */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** An array of names of all compile-time options.  This array should
//	** be sorted A-Z.
//	**
//	** This array looks large, but in a typical installation actually uses
//	** only a handful of compile-time options, so most times this array is usually
//	** rather short and uses little memory space.
//	*/
var _sqlite3azCompileOpt = [55]uintptr{
	0:  __ccgo_ts,
	1:  __ccgo_ts + 20,
	2:  __ccgo_ts + 42,
	3:  __ccgo_ts + 61,
	4:  __ccgo_ts + 86,
	5:  __ccgo_ts + 108,
	6:  __ccgo_ts + 138,
	7:  __ccgo_ts + 158,
	8:  __ccgo_ts + 178,
	9:  __ccgo_ts + 201,
	10: __ccgo_ts + 226,
	11: __ccgo_ts + 253,
	12: __ccgo_ts + 278,
	13: __ccgo_ts + 300,
	14: __ccgo_ts + 332,
	15: __ccgo_ts + 358,
	16: __ccgo_ts + 383,
	17: __ccgo_ts + 404,
	18: __ccgo_ts + 427,
	19: __ccgo_ts + 446,
	20: __ccgo_ts + 458,
	21: __ccgo_ts + 473,
	22: __ccgo_ts + 495,
	23: __ccgo_ts + 520,
	24: __ccgo_ts + 543,
	25: __ccgo_ts + 565,
	26: __ccgo_ts + 576,
	27: __ccgo_ts + 589,
	28: __ccgo_ts + 604,
	29: __ccgo_ts + 620,
	30: __ccgo_ts + 633,
	31: __ccgo_ts + 654,
	32: __ccgo_ts + 678,
	33: __ccgo_ts + 701,
	34: __ccgo_ts + 717,
	35: __ccgo_ts + 733,
	36: __ccgo_ts + 757,
	37: __ccgo_ts + 784,
	38: __ccgo_ts + 804,
	39: __ccgo_ts + 825,
	40: __ccgo_ts + 847,
	41: __ccgo_ts + 877,
	42: __ccgo_ts + 902,
	43: __ccgo_ts + 928,
	44: __ccgo_ts + 948,
	45: __ccgo_ts + 974,
	46: __ccgo_ts + 997,
	47: __ccgo_ts + 1023,
	48: __ccgo_ts + 1045,
	49: __ccgo_ts + 1066,
	50: __ccgo_ts + 1076,
	51: __ccgo_ts + 1085,
	52: __ccgo_ts + 1093,
	53: __ccgo_ts + 1107,
	54: __ccgo_ts + 1120,
}

func _sqlite3CompileOptions(tls *libc.TLS, pnOpt uintptr) (r uintptr) {
	*(*int32)(unsafe.Pointer(pnOpt)) = int32(libc.Uint32FromInt64(220) / libc.Uint32FromInt64(4))
	return uintptr(unsafe.Pointer(&_sqlite3azCompileOpt))
}

/************** End of ctime.c ***********************************************/
/************** Begin file global.c ******************************************/
/*
** 2008 June 13
**
** 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 definitions of global variables and constants.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/* An array to map all upper-case characters into their corresponding
//	** lower-case character.
//	**
//	** SQLite only considers US-ASCII (or EBCDIC) characters.  We do not
//	** handle case conversions for the UTF character set since the tables
//	** involved are nearly as big or bigger than SQLite itself.
//	*/
var _sqlite3UpperToLower = [274]uint8{
	1:   uint8(1),
	2:   uint8(2),
	3:   uint8(3),
	4:   uint8(4),
	5:   uint8(5),
	6:   uint8(6),
	7:   uint8(7),
	8:   uint8(8),
	9:   uint8(9),
	10:  uint8(10),
	11:  uint8(11),
	12:  uint8(12),
	13:  uint8(13),
	14:  uint8(14),
	15:  uint8(15),
	16:  uint8(16),
	17:  uint8(17),
	18:  uint8(18),
	19:  uint8(19),
	20:  uint8(20),
	21:  uint8(21),
	22:  uint8(22),
	23:  uint8(23),
	24:  uint8(24),
	25:  uint8(25),
	26:  uint8(26),
	27:  uint8(27),
	28:  uint8(28),
	29:  uint8(29),
	30:  uint8(30),
	31:  uint8(31),
	32:  uint8(32),
	33:  uint8(33),
	34:  uint8(34),
	35:  uint8(35),
	36:  uint8(36),
	37:  uint8(37),
	38:  uint8(38),
	39:  uint8(39),
	40:  uint8(40),
	41:  uint8(41),
	42:  uint8(42),
	43:  uint8(43),
	44:  uint8(44),
	45:  uint8(45),
	46:  uint8(46),
	47:  uint8(47),
	48:  uint8(48),
	49:  uint8(49),
	50:  uint8(50),
	51:  uint8(51),
	52:  uint8(52),
	53:  uint8(53),
	54:  uint8(54),
	55:  uint8(55),
	56:  uint8(56),
	57:  uint8(57),
	58:  uint8(58),
	59:  uint8(59),
	60:  uint8(60),
	61:  uint8(61),
	62:  uint8(62),
	63:  uint8(63),
	64:  uint8(64),
	65:  uint8(97),
	66:  uint8(98),
	67:  uint8(99),
	68:  uint8(100),
	69:  uint8(101),
	70:  uint8(102),
	71:  uint8(103),
	72:  uint8(104),
	73:  uint8(105),
	74:  uint8(106),
	75:  uint8(107),
	76:  uint8(108),
	77:  uint8(109),
	78:  uint8(110),
	79:  uint8(111),
	80:  uint8(112),
	81:  uint8(113),
	82:  uint8(114),
	83:  uint8(115),
	84:  uint8(116),
	85:  uint8(117),
	86:  uint8(118),
	87:  uint8(119),
	88:  uint8(120),
	89:  uint8(121),
	90:  uint8(122),
	91:  uint8(91),
	92:  uint8(92),
	93:  uint8(93),
	94:  uint8(94),
	95:  uint8(95),
	96:  uint8(96),
	97:  uint8(97),
	98:  uint8(98),
	99:  uint8(99),
	100: uint8(100),
	101: uint8(101),
	102: uint8(102),
	103: uint8(103),
	104: uint8(104),
	105: uint8(105),
	106: uint8(106),
	107: uint8(107),
	108: uint8(108),
	109: uint8(109),
	110: uint8(110),
	111: uint8(111),
	112: uint8(112),
	113: uint8(113),
	114: uint8(114),
	115: uint8(115),
	116: uint8(116),
	117: uint8(117),
	118: uint8(118),
	119: uint8(119),
	120: uint8(120),
	121: uint8(121),
	122: uint8(122),
	123: uint8(123),
	124: uint8(124),
	125: uint8(125),
	126: uint8(126),
	127: uint8(127),
	128: uint8(128),
	129: uint8(129),
	130: uint8(130),
	131: uint8(131),
	132: uint8(132),
	133: uint8(133),
	134: uint8(134),
	135: uint8(135),
	136: uint8(136),
	137: uint8(137),
	138: uint8(138),
	139: uint8(139),
	140: uint8(140),
	141: uint8(141),
	142: uint8(142),
	143: uint8(143),
	144: uint8(144),
	145: uint8(145),
	146: uint8(146),
	147: uint8(147),
	148: uint8(148),
	149: uint8(149),
	150: uint8(150),
	151: uint8(151),
	152: uint8(152),
	153: uint8(153),
	154: uint8(154),
	155: uint8(155),
	156: uint8(156),
	157: uint8(157),
	158: uint8(158),
	159: uint8(159),
	160: uint8(160),
	161: uint8(161),
	162: uint8(162),
	163: uint8(163),
	164: uint8(164),
	165: uint8(165),
	166: uint8(166),
	167: uint8(167),
	168: uint8(168),
	169: uint8(169),
	170: uint8(170),
	171: uint8(171),
	172: uint8(172),
	173: uint8(173),
	174: uint8(174),
	175: uint8(175),
	176: uint8(176),
	177: uint8(177),
	178: uint8(178),
	179: uint8(179),
	180: uint8(180),
	181: uint8(181),
	182: uint8(182),
	183: uint8(183),
	184: uint8(184),
	185: uint8(185),
	186: uint8(186),
	187: uint8(187),
	188: uint8(188),
	189: uint8(189),
	190: uint8(190),
	191: uint8(191),
	192: uint8(192),
	193: uint8(193),
	194: uint8(194),
	195: uint8(195),
	196: uint8(196),
	197: uint8(197),
	198: uint8(198),
	199: uint8(199),
	200: uint8(200),
	201: uint8(201),
	202: uint8(202),
	203: uint8(203),
	204: uint8(204),
	205: uint8(205),
	206: uint8(206),
	207: uint8(207),
	208: uint8(208),
	209: uint8(209),
	210: uint8(210),
	211: uint8(211),
	212: uint8(212),
	213: uint8(213),
	214: uint8(214),
	215: uint8(215),
	216: uint8(216),
	217: uint8(217),
	218: uint8(218),
	219: uint8(219),
	220: uint8(220),
	221: uint8(221),
	222: uint8(222),
	223: uint8(223),
	224: uint8(224),
	225: uint8(225),
	226: uint8(226),
	227: uint8(227),
	228: uint8(228),
	229: uint8(229),
	230: uint8(230),
	231: uint8(231),
	232: uint8(232),
	233: uint8(233),
	234: uint8(234),
	235: uint8(235),
	236: uint8(236),
	237: uint8(237),
	238: uint8(238),
	239: uint8(239),
	240: uint8(240),
	241: uint8(241),
	242: uint8(242),
	243: uint8(243),
	244: uint8(244),
	245: uint8(245),
	246: uint8(246),
	247: uint8(247),
	248: uint8(248),
	249: uint8(249),
	250: uint8(250),
	251: uint8(251),
	252: uint8(252),
	253: uint8(253),
	254: uint8(254),
	255: uint8(255),
	256: uint8(1),
	259: uint8(1),
	260: uint8(1),
	263: uint8(1),
	265: uint8(1),
	267: uint8(1),
	268: uint8(1),
	270: uint8(1),
	273: uint8(1),
}

var _sqlite3aLTb = uintptr(unsafe.Pointer(&_sqlite3UpperToLower)) + uintptr(libc.Int32FromInt32(256)-libc.Int32FromInt32(OP_Ne))

var _sqlite3aEQb = uintptr(unsafe.Pointer(&_sqlite3UpperToLower)) + uintptr(libc.Int32FromInt32(256)+libc.Int32FromInt32(6)-libc.Int32FromInt32(OP_Ne))

var _sqlite3aGTb = uintptr(unsafe.Pointer(&_sqlite3UpperToLower)) + uintptr(libc.Int32FromInt32(256)+libc.Int32FromInt32(12)-libc.Int32FromInt32(OP_Ne))

// C documentation
//
//	/*
//	** The following 256 byte lookup table is used to support SQLites built-in
//	** equivalents to the following standard library functions:
//	**
//	**   isspace()                        0x01
//	**   isalpha()                        0x02
//	**   isdigit()                        0x04
//	**   isalnum()                        0x06
//	**   isxdigit()                       0x08
//	**   toupper()                        0x20
//	**   SQLite identifier character      0x40   $, _, or non-ascii
//	**   Quote character                  0x80
//	**
//	** Bit 0x20 is set if the mapped character requires translation to upper
//	** case. i.e. if the character is a lower-case ASCII character.
//	** If x is a lower-case ASCII character, then its upper-case equivalent
//	** is (x - 0x20). Therefore toupper() can be implemented as:
//	**
//	**   (x & ~(map[x]&0x20))
//	**
//	** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
//	** array. tolower() is used more often than toupper() by SQLite.
//	**
//	** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
//	** SQLite identifier.  Identifiers are alphanumerics, "_", "$", and any
//	** non-ASCII UTF character. Hence the test for whether or not a character is
//	** part of an identifier is 0x46.
//	*/
var _sqlite3CtypeMap = [256]uint8{
	9:   uint8(0x01),
	10:  uint8(0x01),
	11:  uint8(0x01),
	12:  uint8(0x01),
	13:  uint8(0x01),
	32:  uint8(0x01),
	34:  uint8(0x80),
	36:  uint8(0x40),
	39:  uint8(0x80),
	48:  uint8(0x0c),
	49:  uint8(0x0c),
	50:  uint8(0x0c),
	51:  uint8(0x0c),
	52:  uint8(0x0c),
	53:  uint8(0x0c),
	54:  uint8(0x0c),
	55:  uint8(0x0c),
	56:  uint8(0x0c),
	57:  uint8(0x0c),
	65:  uint8(0x0a),
	66:  uint8(0x0a),
	67:  uint8(0x0a),
	68:  uint8(0x0a),
	69:  uint8(0x0a),
	70:  uint8(0x0a),
	71:  uint8(0x02),
	72:  uint8(0x02),
	73:  uint8(0x02),
	74:  uint8(0x02),
	75:  uint8(0x02),
	76:  uint8(0x02),
	77:  uint8(0x02),
	78:  uint8(0x02),
	79:  uint8(0x02),
	80:  uint8(0x02),
	81:  uint8(0x02),
	82:  uint8(0x02),
	83:  uint8(0x02),
	84:  uint8(0x02),
	85:  uint8(0x02),
	86:  uint8(0x02),
	87:  uint8(0x02),
	88:  uint8(0x02),
	89:  uint8(0x02),
	90:  uint8(0x02),
	91:  uint8(0x80),
	95:  uint8(0x40),
	96:  uint8(0x80),
	97:  uint8(0x2a),
	98:  uint8(0x2a),
	99:  uint8(0x2a),
	100: uint8(0x2a),
	101: uint8(0x2a),
	102: uint8(0x2a),
	103: uint8(0x22),
	104: uint8(0x22),
	105: uint8(0x22),
	106: uint8(0x22),
	107: uint8(0x22),
	108: uint8(0x22),
	109: uint8(0x22),
	110: uint8(0x22),
	111: uint8(0x22),
	112: uint8(0x22),
	113: uint8(0x22),
	114: uint8(0x22),
	115: uint8(0x22),
	116: uint8(0x22),
	117: uint8(0x22),
	118: uint8(0x22),
	119: uint8(0x22),
	120: uint8(0x22),
	121: uint8(0x22),
	122: uint8(0x22),
	128: uint8(0x40),
	129: uint8(0x40),
	130: uint8(0x40),
	131: uint8(0x40),
	132: uint8(0x40),
	133: uint8(0x40),
	134: uint8(0x40),
	135: uint8(0x40),
	136: uint8(0x40),
	137: uint8(0x40),
	138: uint8(0x40),
	139: uint8(0x40),
	140: uint8(0x40),
	141: uint8(0x40),
	142: uint8(0x40),
	143: uint8(0x40),
	144: uint8(0x40),
	145: uint8(0x40),
	146: uint8(0x40),
	147: uint8(0x40),
	148: uint8(0x40),
	149: uint8(0x40),
	150: uint8(0x40),
	151: uint8(0x40),
	152: uint8(0x40),
	153: uint8(0x40),
	154: uint8(0x40),
	155: uint8(0x40),
	156: uint8(0x40),
	157: uint8(0x40),
	158: uint8(0x40),
	159: uint8(0x40),
	160: uint8(0x40),
	161: uint8(0x40),
	162: uint8(0x40),
	163: uint8(0x40),
	164: uint8(0x40),
	165: uint8(0x40),
	166: uint8(0x40),
	167: uint8(0x40),
	168: uint8(0x40),
	169: uint8(0x40),
	170: uint8(0x40),
	171: uint8(0x40),
	172: uint8(0x40),
	173: uint8(0x40),
	174: uint8(0x40),
	175: uint8(0x40),
	176: uint8(0x40),
	177: uint8(0x40),
	178: uint8(0x40),
	179: uint8(0x40),
	180: uint8(0x40),
	181: uint8(0x40),
	182: uint8(0x40),
	183: uint8(0x40),
	184: uint8(0x40),
	185: uint8(0x40),
	186: uint8(0x40),
	187: uint8(0x40),
	188: uint8(0x40),
	189: uint8(0x40),
	190: uint8(0x40),
	191: uint8(0x40),
	192: uint8(0x40),
	193: uint8(0x40),
	194: uint8(0x40),
	195: uint8(0x40),
	196: uint8(0x40),
	197: uint8(0x40),
	198: uint8(0x40),
	199: uint8(0x40),
	200: uint8(0x40),
	201: uint8(0x40),
	202: uint8(0x40),
	203: uint8(0x40),
	204: uint8(0x40),
	205: uint8(0x40),
	206: uint8(0x40),
	207: uint8(0x40),
	208: uint8(0x40),
	209: uint8(0x40),
	210: uint8(0x40),
	211: uint8(0x40),
	212: uint8(0x40),
	213: uint8(0x40),
	214: uint8(0x40),
	215: uint8(0x40),
	216: uint8(0x40),
	217: uint8(0x40),
	218: uint8(0x40),
	219: uint8(0x40),
	220: uint8(0x40),
	221: uint8(0x40),
	222: uint8(0x40),
	223: uint8(0x40),
	224: uint8(0x40),
	225: uint8(0x40),
	226: uint8(0x40),
	227: uint8(0x40),
	228: uint8(0x40),
	229: uint8(0x40),
	230: uint8(0x40),
	231: uint8(0x40),
	232: uint8(0x40),
	233: uint8(0x40),
	234: uint8(0x40),
	235: uint8(0x40),
	236: uint8(0x40),
	237: uint8(0x40),
	238: uint8(0x40),
	239: uint8(0x40),
	240: uint8(0x40),
	241: uint8(0x40),
	242: uint8(0x40),
	243: uint8(0x40),
	244: uint8(0x40),
	245: uint8(0x40),
	246: uint8(0x40),
	247: uint8(0x40),
	248: uint8(0x40),
	249: uint8(0x40),
	250: uint8(0x40),
	251: uint8(0x40),
	252: uint8(0x40),
	253: uint8(0x40),
	254: uint8(0x40),
	255: uint8(0x40),
}

/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
** compatibility for legacy applications, the URI filename capability is
** disabled by default.
**
** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
**
** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
** disabled. The default value may be changed by compiling with the
** SQLITE_USE_URI symbol defined.
 */

/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
** that compile-time option is omitted.
 */

/* The minimum PMA size is set to this value multiplied by the database
** page size in bytes.
 */

/* Statement journals spill to disk when their size exceeds the following
** threshold (in bytes). 0 means that statement journals are created and
** written to disk immediately (the default behavior for SQLite versions
** before 3.12.0).  -1 means always keep the entire statement journal in
** memory.  (The statement journal is also always held entirely in memory
** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this
** setting.)
 */

/*
** The default lookaside-configuration, the format "SZ,N".  SZ is the
** number of bytes in each lookaside slot (should be a multiple of 8)
** and N is the number of slots.  The lookaside-configuration can be
** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
** or at run-time for an individual database connection using
** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
**
** With the two-size-lookaside enhancement, less lookaside is required.
** The default configuration of 1200,40 actually provides 30 1200-byte slots
** and 93 128-byte slots, which is more lookaside than is available
** using the older 1200,100 configuration without two-size-lookaside.
 */

/* The default maximum size of an in-memory database created using
** sqlite3_deserialize()
 */

// C documentation
//
//	/*
//	** The following singleton contains the global configuration for
//	** the SQLite library.
//	*/
var _sqlite3Config = TSqlite3Config{
	FbCoreMutex:          uint8(1),
	FbFullMutex:          libc.BoolUint8(true),
	FbUseCis:             uint8(SQLITE_ALLOW_COVERING_INDEX_SCAN),
	FbExtraSchemaChecks:  uint8(1),
	FmxStrlen:            int32(0x7ffffffe),
	FszLookaside:         int32(1200),
	FnLookaside:          int32(40),
	FnStmtSpill:          libc.Int32FromInt32(64) * libc.Int32FromInt32(1024),
	FmxMmap:              int64(SQLITE_MAX_MMAP_SIZE),
	FnPage:               int32(SQLITE_DEFAULT_PCACHE_INITSZ),
	FszPma:               uint32(SQLITE_SORTER_PMASZ),
	FmxMemdbSize:         int64(SQLITE_MEMDB_DEFAULT_MAXSIZE),
	FiOnceResetThreshold: int32(0x7ffffffe),
	FszSorterRef:         uint32(SQLITE_DEFAULT_SORTERREF_SIZE),
}

// C documentation
//
//	/*
//	** Hash table for global functions - functions common to all
//	** database connections.  After initialization, this table is
//	** read-only.
//	*/
var _sqlite3BuiltinFunctions TFuncDefHash

// C documentation
//
//	/*
//	** The value of the "pending" byte must be 0x40000000 (1 byte past the
//	** 1-gibabyte boundary) in a compatible database.  SQLite never uses
//	** the database page that contains the pending byte.  It never attempts
//	** to read or write that page.  The pending byte page is set aside
//	** for use by the VFS layers as space for managing file locks.
//	**
//	** During testing, it is often desirable to move the pending byte to
//	** a different position in the file.  This allows code that has to
//	** deal with the pending byte to run on files that are much smaller
//	** than 1 GiB.  The sqlite3_test_control() interface can be used to
//	** move the pending byte.
//	**
//	** IMPORTANT:  Changing the pending byte to any value other than
//	** 0x40000000 results in an incompatible database file format!
//	** Changing the pending byte during operation will result in undefined
//	** and incorrect behavior.
//	*/
var _sqlite3PendingByte = int32(0x40000000)

// C documentation
//
//	/*
//	** Tracing flags set by SQLITE_TESTCTRL_TRACEFLAGS.
//	*/
var _sqlite3TreeTrace = uint32(0)

var _sqlite3WhereTrace = uint32(0)

// C documentation
//
//	/* #include "opcodes.h" */
//	/*
//	** Properties of opcodes.  The OPFLG_INITIALIZER macro is
//	** created by mkopcodeh.awk during compilation.  Data is obtained
//	** from the comments following the "case OP_xxxx:" statements in
//	** the vdbe.c file.
//	*/
var _sqlite3OpcodeProperty = [190]uint8{
	4:   uint8(0x10),
	6:   uint8(0x41),
	8:   uint8(0x81),
	9:   uint8(0x01),
	10:  uint8(0x01),
	11:  uint8(0x81),
	12:  uint8(0x83),
	13:  uint8(0x83),
	14:  uint8(0x01),
	15:  uint8(0x01),
	16:  uint8(0x03),
	17:  uint8(0x03),
	18:  uint8(0x01),
	19:  uint8(0x12),
	20:  uint8(0x01),
	21:  uint8(0xc9),
	22:  uint8(0xc9),
	23:  uint8(0xc9),
	24:  uint8(0xc9),
	25:  uint8(0x01),
	26:  uint8(0x49),
	27:  uint8(0x49),
	28:  uint8(0x49),
	29:  uint8(0x49),
	30:  uint8(0xc9),
	31:  uint8(0x49),
	32:  uint8(0xc1),
	33:  uint8(0x01),
	34:  uint8(0x41),
	35:  uint8(0x41),
	36:  uint8(0xc1),
	37:  uint8(0x01),
	38:  uint8(0x41),
	39:  uint8(0x41),
	40:  uint8(0x41),
	41:  uint8(0x41),
	42:  uint8(0x41),
	43:  uint8(0x26),
	44:  uint8(0x26),
	45:  uint8(0x41),
	46:  uint8(0x23),
	47:  uint8(0x0b),
	48:  uint8(0x81),
	49:  uint8(0x01),
	50:  uint8(0x03),
	51:  uint8(0x03),
	52:  uint8(0x0b),
	53:  uint8(0x0b),
	54:  uint8(0x0b),
	55:  uint8(0x0b),
	56:  uint8(0x0b),
	57:  uint8(0x0b),
	58:  uint8(0x01),
	59:  uint8(0x03),
	60:  uint8(0x03),
	61:  uint8(0x03),
	62:  uint8(0x01),
	63:  uint8(0x41),
	64:  uint8(0x01),
	67:  uint8(0x02),
	68:  uint8(0x02),
	69:  uint8(0x08),
	71:  uint8(0x10),
	72:  uint8(0x10),
	73:  uint8(0x10),
	75:  uint8(0x10),
	77:  uint8(0x10),
	78:  uint8(0x10),
	81:  uint8(0x10),
	82:  uint8(0x10),
	86:  uint8(0x02),
	87:  uint8(0x02),
	88:  uint8(0x02),
	91:  uint8(0x12),
	92:  uint8(0x1e),
	93:  uint8(0x20),
	94:  uint8(0x40),
	98:  uint8(0x10),
	99:  uint8(0x10),
	101: uint8(0x40),
	102: uint8(0x26),
	103: uint8(0x26),
	104: uint8(0x26),
	105: uint8(0x26),
	106: uint8(0x26),
	107: uint8(0x26),
	108: uint8(0x26),
	109: uint8(0x26),
	110: uint8(0x26),
	111: uint8(0x26),
	112: uint8(0x40),
	114: uint8(0x12),
	115: uint8(0x40),
	116: uint8(0x40),
	117: uint8(0x10),
	118: uint8(0x40),
	122: uint8(0x40),
	124: uint8(0x40),
	125: uint8(0x40),
	126: uint8(0x10),
	127: uint8(0x10),
	133: uint8(0x40),
	135: uint8(0x50),
	137: uint8(0x40),
	138: uint8(0x04),
	139: uint8(0x04),
	141: uint8(0x40),
	142: uint8(0x50),
	143: uint8(0x40),
	144: uint8(0x10),
	147: uint8(0x10),
	153: uint8(0x10),
	156: uint8(0x06),
	157: uint8(0x10),
	159: uint8(0x04),
	160: uint8(0x1a),
	173: uint8(0x40),
	174: uint8(0x10),
	175: uint8(0x50),
	176: uint8(0x40),
	178: uint8(0x10),
	179: uint8(0x10),
	180: uint8(0x02),
	181: uint8(0x12),
	182: uint8(0x12),
}

// C documentation
//
//	/*
//	** Name of the default collating sequence
//	*/
var _sqlite3StrBINARY = [7]int8{'B', 'I', 'N', 'A', 'R', 'Y'}

// C documentation
//
//	/*
//	** Standard typenames.  These names must match the COLTYPE_* definitions.
//	** Adjust the SQLITE_N_STDTYPE value if adding or removing entries.
//	**
//	**    sqlite3StdType[]            The actual names of the datatypes.
//	**
//	**    sqlite3StdTypeLen[]         The length (in bytes) of each entry
//	**                                in sqlite3StdType[].
//	**
//	**    sqlite3StdTypeAffinity[]    The affinity associated with each entry
//	**                                in sqlite3StdType[].
//	*/
var _sqlite3StdTypeLen = [6]uint8{
	0: uint8(3),
	1: uint8(4),
	2: uint8(3),
	3: uint8(7),
	4: uint8(4),
	5: uint8(4),
}

var _sqlite3StdTypeAffinity = [6]int8{
	0: int8(SQLITE_AFF_NUMERIC),
	1: int8(SQLITE_AFF_BLOB),
	2: int8(SQLITE_AFF_INTEGER),
	3: int8(SQLITE_AFF_INTEGER),
	4: int8(SQLITE_AFF_REAL),
	5: int8(SQLITE_AFF_TEXT),
}

var _sqlite3StdType = [6]uintptr{
	0: __ccgo_ts + 1133,
	1: __ccgo_ts + 1137,
	2: __ccgo_ts + 1142,
	3: __ccgo_ts + 1146,
	4: __ccgo_ts + 1154,
	5: __ccgo_ts + 1159,
}

/************** End of global.c **********************************************/
/************** Begin file status.c ******************************************/
/*
** 2008 June 18
**
** 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 implements the sqlite3_status() interface and related
** functionality.
 */
/* #include "sqliteInt.h" */
/************** Include vdbeInt.h in the middle of status.c ******************/
/************** Begin file vdbeInt.h *****************************************/
/*
** 2003 September 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 is the header file for information that is private to the
** VDBE.  This information used to all be at the top of the single
** source code file "vdbe.c".  When that file became too big (over
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
 */

/*
** The maximum number of times that a statement will try to reparse
** itself before giving up and returning SQLITE_SCHEMA.
 */

/*
** VDBE_DISPLAY_P4 is true or false depending on whether or not the
** "explain" P4 display logic is enabled.
 */

// C documentation
//
//	/*
//	** SQL is translated into a sequence of instructions to be
//	** executed by a virtual machine.  Each instruction is an instance
//	** of the following structure.
//	*/
type TOp = struct {
	Fopcode Tu8
	Fp4type int8
	Fp5     Tu16
	Fp1     int32
	Fp2     int32
	Fp3     int32
	Fp4     Tp4union
}

type Op = TOp

// C documentation
//
//	/*
//	** Boolean values
//	*/
type TBool = uint32

type Bool = TBool

// C documentation
//
//	/* Opaque type used by code in vdbesort.c */
type TVdbeSorter = struct {
	F__ccgo_align   [0]uint32
	FmnPmaSize      int32
	FmxPmaSize      int32
	FmxKeysize      int32
	Fpgsz           int32
	FpReader        uintptr
	FpMerger        uintptr
	Fdb             uintptr
	FpKeyInfo       uintptr
	FpUnpacked      uintptr
	F__ccgo_align9  [4]byte
	Flist           TSorterList
	FiMemory        int32
	FnMemory        int32
	FbUsePMA        Tu8
	FbUseThreads    Tu8
	FiPrev          Tu8
	FnTask          Tu8
	FtypeMask       Tu8
	F__ccgo_align17 [3]byte
	FaTask          [1]TSortSubtask
}

type VdbeSorter = TVdbeSorter

// C documentation
//
//	/* Elements of the linked list at Vdbe.pAuxData */
type TAuxData = struct {
	FiAuxOp     int32
	FiAuxArg    int32
	FpAux       uintptr
	FxDeleteAux uintptr
	FpNextAux   uintptr
}

type AuxData = TAuxData

// C documentation
//
//	/* A cache of large TEXT or BLOB values in a VdbeCursor */
type TVdbeTxtBlbCache = struct {
	F__ccgo_align  [0]uint32
	FpCValue       uintptr
	F__ccgo_align1 [4]byte
	FiOffset       Ti64
	FiCol          int32
	FcacheStatus   Tu32
	FcolCacheCtr   Tu32
	F__ccgo_pad5   [4]byte
}

type VdbeTxtBlbCache = TVdbeTxtBlbCache

/* Types of VDBE cursors */

// C documentation
//
//	/*
//	** A VdbeCursor is an superclass (a wrapper) for various cursor objects:
//	**
//	**      * A b-tree cursor
//	**          -  In the main database or in an ephemeral database
//	**          -  On either an index or a table
//	**      * A sorter
//	**      * A virtual table
//	**      * A one-row "pseudotable" stored in a single register
//	*/
type TVdbeCursor = struct {
	F__ccgo_align   [0]uint32
	FeCurType       Tu8
	FiDb            Ti8
	FnullRow        Tu8
	FdeferredMoveto Tu8
	FisTable        Tu8
	F__ccgo_align5  [3]byte
	F__ccgo8        uint8
	FseekHit        Tu16
	Fub             struct {
		FaAltMap [0]uintptr
		FpBtx    uintptr
	}
	FseqCount    Ti64
	FcacheStatus Tu32
	FseekResult  int32
	FpAltCursor  uintptr
	Fuc          struct {
		FpVCur   [0]uintptr
		FpSorter [0]uintptr
		FpCursor uintptr
	}
	FpKeyInfo     uintptr
	FiHdrOffset   Tu32
	FpgnoRoot     TPgno
	FnField       Ti16
	FnHdrParsed   Tu16
	FmovetoTarget Ti64
	FaOffset      uintptr
	FaRow         uintptr
	FpayloadSize  Tu32
	FszRow        Tu32
	FpCache       uintptr
	FaType        [1]Tu32
}

type VdbeCursor = TVdbeCursor

type TVdbeCursor1 = struct {
	F__ccgo_align   [0]uint32
	FeCurType       Tu8
	FiDb            Ti8
	FnullRow        Tu8
	FdeferredMoveto Tu8
	FisTable        Tu8
	F__ccgo_align5  [3]byte
	F__ccgo8        uint8
	FseekHit        Tu16
	Fub             struct {
		FaAltMap [0]uintptr
		FpBtx    uintptr
	}
	FseqCount    Ti64
	FcacheStatus Tu32
	FseekResult  int32
	FpAltCursor  uintptr
	Fuc          struct {
		FpVCur   [0]uintptr
		FpSorter [0]uintptr
		FpCursor uintptr
	}
	FpKeyInfo     uintptr
	FiHdrOffset   Tu32
	FpgnoRoot     TPgno
	FnField       Ti16
	FnHdrParsed   Tu16
	FmovetoTarget Ti64
	FaOffset      uintptr
	FaRow         uintptr
	FpayloadSize  Tu32
	FszRow        Tu32
	FpCache       uintptr
	FaType        [1]Tu32
}

type VdbeCursor1 = TVdbeCursor1

/* Return true if P is a null-only cursor
 */

/*
** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
 */

/*
** Large TEXT or BLOB values can be slow to load, so we want to avoid
** loading them more than once.  For that reason, large TEXT and BLOB values
** can be stored in a cache defined by this object, and attached to the
** VdbeCursor using the pCache field.
 */
type TVdbeTxtBlbCache1 = struct {
	F__ccgo_align  [0]uint32
	FpCValue       uintptr
	F__ccgo_align1 [4]byte
	FiOffset       Ti64
	FiCol          int32
	FcacheStatus   Tu32
	FcolCacheCtr   Tu32
	F__ccgo_pad5   [4]byte
}

type VdbeTxtBlbCache1 = TVdbeTxtBlbCache1

// C documentation
//
//	/*
//	** When a sub-program is executed (OP_Program), a structure of this type
//	** is allocated to store the current value of the program counter, as
//	** well as the current memory cell array and various other frame specific
//	** values stored in the Vdbe struct. When the sub-program is finished,
//	** these values are copied back to the Vdbe from the VdbeFrame structure,
//	** restoring the state of the VM to as it was before the sub-program
//	** began executing.
//	**
//	** The memory for a VdbeFrame object is allocated and managed by a memory
//	** cell in the parent (calling) frame. When the memory cell is deleted or
//	** overwritten, the VdbeFrame object is not freed immediately. Instead, it
//	** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame
//	** list is deleted when the VM is reset in VdbeHalt(). The reason for doing
//	** this instead of deleting the VdbeFrame immediately is to avoid recursive
//	** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the
//	** child frame are released.
//	**
//	** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
//	** set to NULL if the currently executing frame is the main program.
//	*/
type TVdbeFrame = struct {
	F__ccgo_align   [0]uint32
	Fv              uintptr
	FpParent        uintptr
	FaOp            uintptr
	FaMem           uintptr
	FapCsr          uintptr
	FaOnce          uintptr
	Ftoken          uintptr
	F__ccgo_align7  [4]byte
	FlastRowid      Ti64
	FpAuxData       uintptr
	FnCursor        int32
	Fpc             int32
	FnOp            int32
	FnMem           int32
	FnChildMem      int32
	FnChildCsr      int32
	F__ccgo_align15 [4]byte
	FnChange        Ti64
	FnDbChange      Ti64
}

type VdbeFrame = TVdbeFrame

type TVdbeFrame1 = struct {
	F__ccgo_align   [0]uint32
	Fv              uintptr
	FpParent        uintptr
	FaOp            uintptr
	FaMem           uintptr
	FapCsr          uintptr
	FaOnce          uintptr
	Ftoken          uintptr
	F__ccgo_align7  [4]byte
	FlastRowid      Ti64
	FpAuxData       uintptr
	FnCursor        int32
	Fpc             int32
	FnOp            int32
	FnMem           int32
	FnChildMem      int32
	FnChildCsr      int32
	F__ccgo_align15 [4]byte
	FnChange        Ti64
	FnDbChange      Ti64
}

type VdbeFrame1 = TVdbeFrame1

/*
** Size of struct Mem not including the Mem.zMalloc member or anything that
** follows.
 */

/* One or more of the following flags are set to indicate the
** representations of the value stored in the Mem struct.
**
**  *  MEM_Null                An SQL NULL value
**
**  *  MEM_Null|MEM_Zero       An SQL NULL with the virtual table
**                             UPDATE no-change flag set
**
**  *  MEM_Null|MEM_Term|      An SQL NULL, but also contains a
**        MEM_Subtype          pointer accessible using
**                             sqlite3_value_pointer().
**
**  *  MEM_Null|MEM_Cleared    Special SQL NULL that compares non-equal
**                             to other NULLs even using the IS operator.
**
**  *  MEM_Str                 A string, stored in Mem.z with
**                             length Mem.n.  Zero-terminated if
**                             MEM_Term is set.  This flag is
**                             incompatible with MEM_Blob and
**                             MEM_Null, but can appear with MEM_Int,
**                             MEM_Real, and MEM_IntReal.
**
**  *  MEM_Blob                A blob, stored in Mem.z length Mem.n.
**                             Incompatible with MEM_Str, MEM_Null,
**                             MEM_Int, MEM_Real, and MEM_IntReal.
**
**  *  MEM_Blob|MEM_Zero       A blob in Mem.z of length Mem.n plus
**                             MEM.u.i extra 0x00 bytes at the end.
**
**  *  MEM_Int                 Integer stored in Mem.u.i.
**
**  *  MEM_Real                Real stored in Mem.u.r.
**
**  *  MEM_IntReal             Real stored as an integer in Mem.u.i.
**
** If the MEM_Null flag is set, then the value is an SQL NULL value.
** For a pointer type created using sqlite3_bind_pointer() or
** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
**
** If the MEM_Str flag is set then Mem.z points at a string representation.
** Usually this is encoded in the same unicode encoding as the main
** database (see below for exceptions). If the MEM_Term flag is also
** set, then the string is nul terminated. The MEM_Int and MEM_Real
** flags may coexist with the MEM_Str flag.
 */

/* Extra bits that modify the meanings of the core datatypes above
 */
/*                   0x0080   // Available */

/* Bits that determine the storage for Mem.z for a string or blob or
** aggregate accumulator.
 */

/* Return TRUE if Mem X contains dynamically allocated content - anything
** that needs to be deallocated to avoid a leak.
 */

/*
** Clear any existing type flags from a Mem and replace them with f
 */

/*
** True if Mem X is a NULL-nochng type.
 */

/*
** Return true if a memory cell has been initialized and is valid.
** is for use inside assert() statements only.
**
** A Memory cell is initialized if at least one of the
** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits
** is set.  It is "undefined" if all those bits are zero.
 */

/*
** Each auxiliary data pointer stored by a user defined function
** implementation calling sqlite3_set_auxdata() is stored in an instance
** of this structure. All such structures associated with a single VM
** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
** when the VM is halted (if not before).
 */
type TAuxData1 = struct {
	FiAuxOp     int32
	FiAuxArg    int32
	FpAux       uintptr
	FxDeleteAux uintptr
	FpNextAux   uintptr
}

type AuxData1 = TAuxData1

/*
** The "context" argument for an installable function.  A pointer to an
** instance of this structure is the first argument to the routines used
** implement the SQL functions.
**
** There is a typedef for this structure in sqlite.h.  So all routines,
** even the public interface to SQLite, can use a pointer to this structure.
** But this file is the only place where the internal details of this
** structure are known.
**
** This structure is defined inside of vdbeInt.h because it uses substructures
** (Mem) which are only defined there.
 */
type Tsqlite3_context1 = struct {
	FpOut     uintptr
	FpFunc    uintptr
	FpMem     uintptr
	FpVdbe    uintptr
	FiOp      int32
	FisError  int32
	Fenc      Tu8
	FskipFlag Tu8
	Fargc     Tu8
	Fargv     [1]uintptr
}

type sqlite3_context1 = Tsqlite3_context1

// C documentation
//
//	/* A bitfield type for use inside of structures.  Always follow with :N where
//	** N is the number of bits.
//	*/
type Tbft = uint32

type bft = Tbft

/* Bit Field Type */

// C documentation
//
//	/* The ScanStatus object holds a single value for the
//	** sqlite3_stmt_scanstatus() interface.
//	**
//	** aAddrRange[]:
//	**   This array is used by ScanStatus elements associated with EQP
//	**   notes that make an SQLITE_SCANSTAT_NCYCLE value available. It is
//	**   an array of up to 3 ranges of VM addresses for which the Vdbe.anCycle[]
//	**   values should be summed to calculate the NCYCLE value. Each pair of
//	**   integer addresses is a start and end address (both inclusive) for a range
//	**   instructions. A start value of 0 indicates an empty range.
//	*/
type TScanStatus = struct {
	FaddrExplain int32
	FaAddrRange  [6]int32
	FaddrLoop    int32
	FaddrVisit   int32
	FiSelectID   int32
	FnEst        TLogEst
	FzName       uintptr
}

type ScanStatus = TScanStatus

type TScanStatus1 = struct {
	FaddrExplain int32
	FaAddrRange  [6]int32
	FaddrLoop    int32
	FaddrVisit   int32
	FiSelectID   int32
	FnEst        TLogEst
	FzName       uintptr
}

type ScanStatus1 = TScanStatus1

// C documentation
//
//	/* The DblquoteStr object holds the text of a double-quoted
//	** string for a prepared statement.  A linked list of these objects
//	** is constructed during statement parsing and is held on Vdbe.pDblStr.
//	** When computing a normalized SQL statement for an SQL statement, that
//	** list is consulted for each double-quoted identifier to see if the
//	** identifier should really be a string literal.
//	*/
type TDblquoteStr = struct {
	FpNextStr uintptr
	Fz        [8]int8
}

type DblquoteStr = TDblquoteStr

type TDblquoteStr1 = struct {
	FpNextStr uintptr
	Fz        [8]int8
}

type DblquoteStr1 = TDblquoteStr1

/*
** An instance of the virtual machine.  This structure contains the complete
** state of the virtual machine.
**
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
** is really a pointer to an instance of this structure.
 */
type TVdbe1 = struct {
	F__ccgo_align       [0]uint32
	Fdb                 uintptr
	FppVPrev            uintptr
	FpVNext             uintptr
	FpParse             uintptr
	FnVar               TynVar
	FnMem               int32
	FnCursor            int32
	FcacheCtr           Tu32
	Fpc                 int32
	Frc                 int32
	FnChange            Ti64
	FiStatement         int32
	F__ccgo_align12     [4]byte
	FiCurrentTime       Ti64
	FnFkConstraint      Ti64
	FnStmtDefCons       Ti64
	FnStmtDefImmCons    Ti64
	FaMem               uintptr
	FapArg              uintptr
	FapCsr              uintptr
	FaVar               uintptr
	FaOp                uintptr
	FnOp                int32
	FnOpAlloc           int32
	FaColName           uintptr
	FpResultRow         uintptr
	FzErrMsg            uintptr
	FpVList             uintptr
	F__ccgo_align27     [4]byte
	FstartTime          Ti64
	FnResColumn         Tu16
	FnResAlloc          Tu16
	FerrorAction        Tu8
	FminWriteFileFormat Tu8
	FprepFlags          Tu8
	FeVdbeState         Tu8
	F__ccgo152          uint16
	FbtreeMask          TyDbMask
	FlockMask           TyDbMask
	FaCounter           [9]Tu32
	FzSql               uintptr
	FpFree              uintptr
	FpFrame             uintptr
	FpDelFrame          uintptr
	FnFrame             int32
	Fexpmask            Tu32
	FpProgram           uintptr
	FpAuxData           uintptr
}

type Vdbe1 = TVdbe1

/*
** The following are allowed values for Vdbe.eVdbeState
 */

/*
** Structure used to store the context required by the
** sqlite3_preupdate_*() API functions.
 */
type TPreUpdate1 = struct {
	F__ccgo_align [0]uint32
	Fv            uintptr
	FpCsr         uintptr
	Fop           int32
	FaRecord      uintptr
	Fkeyinfo      TKeyInfo
	FpUnpacked    uintptr
	FpNewUnpacked uintptr
	FiNewReg      int32
	FiBlobWrite   int32
	FiKey1        Ti64
	FiKey2        Ti64
	FaNew         uintptr
	FpTab         uintptr
	FpPk          uintptr
	F__ccgo_pad14 [4]byte
}

type PreUpdate1 = TPreUpdate1

// C documentation
//
//	/*
//	** An instance of this object is used to pass an vector of values into
//	** OP_VFilter, the xFilter method of a virtual table.  The vector is the
//	** set of values on the right-hand side of an IN constraint.
//	**
//	** The value as passed into xFilter is an sqlite3_value with a "pointer"
//	** type, such as is generated by sqlite3_result_pointer() and read by
//	** sqlite3_value_pointer.  Such values have MEM_Term|MEM_Subtype|MEM_Null
//	** and a subtype of 'p'.  The sqlite3_vtab_in_first() and _next() interfaces
//	** know how to use this object to step through all the values in the
//	** right operand of the IN constraint.
//	*/
type TValueList = struct {
	FpCsr uintptr
	FpOut uintptr
}

type ValueList = TValueList

type TValueList1 = struct {
	FpCsr uintptr
	FpOut uintptr
}

type ValueList1 = TValueList1

/************** End of vdbeInt.h *********************************************/
/************** Continuing where we left off in status.c *********************/

// C documentation
//
//	/*
//	** Variables in which to record status information.
//	*/
type Tsqlite3StatValueType = uint32

type sqlite3StatValueType = Tsqlite3StatValueType

type Tsqlite3StatType = struct {
	FnowValue [10]Tsqlite3StatValueType
	FmxValue  [10]Tsqlite3StatValueType
}

type sqlite3StatType = Tsqlite3StatType

type Tsqlite3StatType1 = struct {
	FnowValue [10]Tsqlite3StatValueType
	FmxValue  [10]Tsqlite3StatValueType
}

type sqlite3StatType1 = Tsqlite3StatType1

var _sqlite3Stat = Tsqlite3StatType1{}

// C documentation
//
//	/*
//	** Elements of sqlite3Stat[] are protected by either the memory allocator
//	** mutex, or by the pcache1 mutex.  The following array determines which.
//	*/
var _statMutex = [10]int8{
	1: int8(1),
	2: int8(1),
	7: int8(1),
}

/* The "wsdStat" macro will resolve to the status information
** state vector.  If writable static data is unsupported on the target,
** we have to locate the state vector at run-time.  In the more common
** case where writable static data is supported, wsdStat can refer directly
** to the "sqlite3Stat" state vector declared above.
 */

// C documentation
//
//	/*
//	** Return the current value of a status parameter.  The caller must
//	** be holding the appropriate mutex.
//	*/
func _sqlite3StatusValue(tls *libc.TLS, op int32) (r Tsqlite3_int64) {
	return int64(*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + uintptr(op)*4)))
}

// C documentation
//
//	/*
//	** Add N to the value of a status record.  The caller must hold the
//	** appropriate mutex.  (Locking is checked by assert()).
//	**
//	** The StatusUp() routine can accept positive or negative values for N.
//	** The value of N is added to the current status value and the high-water
//	** mark is adjusted if necessary.
//	**
//	** The StatusDown() routine lowers the current value by N.  The highwater
//	** mark is unchanged.  N must be non-negative for StatusDown().
//	*/
func _sqlite3StatusUp(tls *libc.TLS, op int32, N int32) {
	*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + uintptr(op)*4)) += uint32(uint32(N))
	if *(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + uintptr(op)*4)) > *(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + 40 + uintptr(op)*4)) {
		*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + 40 + uintptr(op)*4)) = *(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + uintptr(op)*4))
	}
}

func _sqlite3StatusDown(tls *libc.TLS, op int32, N int32) {
	*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + uintptr(op)*4)) -= uint32(uint32(N))
}

// C documentation
//
//	/*
//	** Adjust the highwater mark if necessary.
//	** The caller must hold the appropriate mutex.
//	*/
func _sqlite3StatusHighwater(tls *libc.TLS, op int32, X int32) {
	var newValue Tsqlite3StatValueType
	_ = newValue
	newValue = uint32(uint32(X))
	if newValue > *(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + 40 + uintptr(op)*4)) {
		*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + 40 + uintptr(op)*4)) = newValue
	}
}

// C documentation
//
//	/*
//	** Query status information.
//	*/
func Xsqlite3_status64(tls *libc.TLS, op int32, pCurrent uintptr, pHighwater uintptr, resetFlag int32) (r int32) {
	var pMutex, v1 uintptr
	_, _ = pMutex, v1
	if op < 0 || op >= int32(libc.Uint32FromInt64(40)/libc.Uint32FromInt64(4)) {
		return _sqlite3MisuseError(tls, int32(23961))
	}
	if _statMutex[op] != 0 {
		v1 = _sqlite3Pcache1Mutex(tls)
	} else {
		v1 = _sqlite3MallocMutex(tls)
	}
	pMutex = v1
	Xsqlite3_mutex_enter(tls, pMutex)
	*(*Tsqlite3_int64)(unsafe.Pointer(pCurrent)) = int64(*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + uintptr(op)*4)))
	*(*Tsqlite3_int64)(unsafe.Pointer(pHighwater)) = int64(*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + 40 + uintptr(op)*4)))
	if resetFlag != 0 {
		*(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + 40 + uintptr(op)*4)) = *(*Tsqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Stat)) + uintptr(op)*4))
	}
	Xsqlite3_mutex_leave(tls, pMutex)
	_ = pMutex /* Prevent warning when SQLITE_THREADSAFE=0 */
	return SQLITE_OK
}

func Xsqlite3_status(tls *libc.TLS, op int32, pCurrent uintptr, pHighwater uintptr, resetFlag int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* iCur at bp+0 */ Tsqlite3_int64
	var _ /* iHwtr at bp+8 */ Tsqlite3_int64
	_ = rc
	*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = 0
	*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)) = 0
	rc = Xsqlite3_status64(tls, op, bp, bp+8, resetFlag)
	if rc == 0 {
		*(*int32)(unsafe.Pointer(pCurrent)) = int32(*(*Tsqlite3_int64)(unsafe.Pointer(bp)))
		*(*int32)(unsafe.Pointer(pHighwater)) = int32(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the number of LookasideSlot elements on the linked list
//	*/
func _countLookasideSlots(tls *libc.TLS, p uintptr) (r Tu32) {
	var cnt Tu32
	_ = cnt
	cnt = uint32(0)
	for p != 0 {
		p = (*TLookasideSlot)(unsafe.Pointer(p)).FpNext
		cnt++
	}
	return cnt
}

// C documentation
//
//	/*
//	** Count the number of slots of lookaside memory that are outstanding
//	*/
func _sqlite3LookasideUsed(tls *libc.TLS, db uintptr, pHighwater uintptr) (r int32) {
	var nFree, nInit Tu32
	_, _ = nFree, nInit
	nInit = _countLookasideSlots(tls, (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit)
	nFree = _countLookasideSlots(tls, (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree)
	nInit += _countLookasideSlots(tls, (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit)
	nFree += _countLookasideSlots(tls, (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree)
	if pHighwater != 0 {
		*(*int32)(unsafe.Pointer(pHighwater)) = int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot - nInit)
	}
	return int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot - (nInit + nFree))
}

// C documentation
//
//	/*
//	** Query status information for a single database connection
//	*/
func Xsqlite3_db_status(tls *libc.TLS, db uintptr, op int32, pCurrent uintptr, pHighwater uintptr, resetFlag int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, i1, i2, nByte, rc, totalUsed int32
	var p, p1, pBt, pPager, pPager1, pSchema, pVdbe uintptr
	var _ /* nByte at bp+0 */ int32
	var _ /* nByte at bp+4 */ int32
	var _ /* nRet at bp+8 */ Tu64
	_, _, _, _, _, _, _, _, _, _, _, _, _ = i, i1, i2, nByte, p, p1, pBt, pPager, pPager1, pSchema, pVdbe, rc, totalUsed
	rc = SQLITE_OK /* Return code */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	switch op {
	case SQLITE_DBSTATUS_LOOKASIDE_USED:
		*(*int32)(unsafe.Pointer(pCurrent)) = _sqlite3LookasideUsed(tls, db, pHighwater)
		if resetFlag != 0 {
			p = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
			if p != 0 {
				for (*TLookasideSlot)(unsafe.Pointer(p)).FpNext != 0 {
					p = (*TLookasideSlot)(unsafe.Pointer(p)).FpNext
				}
				(*TLookasideSlot)(unsafe.Pointer(p)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = uintptr(0)
			}
			p = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
			if p != 0 {
				for (*TLookasideSlot)(unsafe.Pointer(p)).FpNext != 0 {
					p = (*TLookasideSlot)(unsafe.Pointer(p)).FpNext
				}
				(*TLookasideSlot)(unsafe.Pointer(p)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = uintptr(0)
			}
		}
	case int32(SQLITE_DBSTATUS_LOOKASIDE_HIT):
		fallthrough
	case int32(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE):
		fallthrough
	case int32(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL):
		*(*int32)(unsafe.Pointer(pCurrent)) = 0
		*(*int32)(unsafe.Pointer(pHighwater)) = int32(*(*Tu32)(unsafe.Pointer(db + 320 + 16 + uintptr(op-int32(SQLITE_DBSTATUS_LOOKASIDE_HIT))*4)))
		if resetFlag != 0 {
			*(*Tu32)(unsafe.Pointer(db + 320 + 16 + uintptr(op-int32(SQLITE_DBSTATUS_LOOKASIDE_HIT))*4)) = uint32(0)
		}
		break
		/*
		 ** Return an approximation for the amount of memory currently used
		 ** by all pagers associated with the given database connection.  The
		 ** highwater mark is meaningless and is returned as zero.
		 */
		fallthrough
	case int32(SQLITE_DBSTATUS_CACHE_USED_SHARED):
		fallthrough
	case int32(SQLITE_DBSTATUS_CACHE_USED):
		totalUsed = 0
		_sqlite3BtreeEnterAll(tls, db)
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if pBt != 0 {
				pPager = _sqlite3BtreePager(tls, pBt)
				nByte = _sqlite3PagerMemUsed(tls, pPager)
				if op == int32(SQLITE_DBSTATUS_CACHE_USED_SHARED) {
					nByte = nByte / _sqlite3BtreeConnectionCount(tls, pBt)
				}
				totalUsed += nByte
			}
			goto _1
		_1:
			;
			i++
		}
		_sqlite3BtreeLeaveAll(tls, db)
		*(*int32)(unsafe.Pointer(pCurrent)) = totalUsed
		*(*int32)(unsafe.Pointer(pHighwater)) = 0
		break
		/*
		 ** *pCurrent gets an accurate estimate of the amount of memory used
		 ** to store the schema for all databases (main, temp, and any ATTACHed
		 ** databases.  *pHighwater is set to zero.
		 */
		fallthrough
	case int32(SQLITE_DBSTATUS_SCHEMA_USED): /* Used to iterate through schemas */
		*(*int32)(unsafe.Pointer(bp)) = 0 /* Used to accumulate return value */
		_sqlite3BtreeEnterAll(tls, db)
		(*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed = bp
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart
		i1 = 0
		for {
			if !(i1 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i1)*16))).FpSchema
			if pSchema != uintptr(0) {
				*(*int32)(unsafe.Pointer(bp)) = int32(uint32(*(*int32)(unsafe.Pointer(bp))) + uint32((*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxRoundup})))(tls, int32(16)))*((*TSchema)(unsafe.Pointer(pSchema)).FtblHash.Fcount+(*TSchema)(unsafe.Pointer(pSchema)).FtrigHash.Fcount+(*TSchema)(unsafe.Pointer(pSchema)).FidxHash.Fcount+(*TSchema)(unsafe.Pointer(pSchema)).FfkeyHash.Fcount))
				*(*int32)(unsafe.Pointer(bp)) = int32(uint64(*(*int32)(unsafe.Pointer(bp))) + Xsqlite3_msize(tls, (*TSchema)(unsafe.Pointer(pSchema)).FtblHash.Fht))
				*(*int32)(unsafe.Pointer(bp)) = int32(uint64(*(*int32)(unsafe.Pointer(bp))) + Xsqlite3_msize(tls, (*TSchema)(unsafe.Pointer(pSchema)).FtrigHash.Fht))
				*(*int32)(unsafe.Pointer(bp)) = int32(uint64(*(*int32)(unsafe.Pointer(bp))) + Xsqlite3_msize(tls, (*TSchema)(unsafe.Pointer(pSchema)).FidxHash.Fht))
				*(*int32)(unsafe.Pointer(bp)) = int32(uint64(*(*int32)(unsafe.Pointer(bp))) + Xsqlite3_msize(tls, (*TSchema)(unsafe.Pointer(pSchema)).FfkeyHash.Fht))
				p1 = (*THash)(unsafe.Pointer(pSchema + 40)).Ffirst
				for {
					if !(p1 != 0) {
						break
					}
					_sqlite3DeleteTrigger(tls, db, (*THashElem)(unsafe.Pointer(p1)).Fdata)
					goto _3
				_3:
					;
					p1 = (*THashElem)(unsafe.Pointer(p1)).Fnext
				}
				p1 = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
				for {
					if !(p1 != 0) {
						break
					}
					_sqlite3DeleteTable(tls, db, (*THashElem)(unsafe.Pointer(p1)).Fdata)
					goto _4
				_4:
					;
					p1 = (*THashElem)(unsafe.Pointer(p1)).Fnext
				}
			}
			goto _2
		_2:
			;
			i1++
		}
		(*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd
		_sqlite3BtreeLeaveAll(tls, db)
		*(*int32)(unsafe.Pointer(pHighwater)) = 0
		*(*int32)(unsafe.Pointer(pCurrent)) = *(*int32)(unsafe.Pointer(bp))
		break
		/*
		 ** *pCurrent gets an accurate estimate of the amount of memory used
		 ** to store all prepared statements.
		 ** *pHighwater is set to zero.
		 */
		fallthrough
	case int32(SQLITE_DBSTATUS_STMT_USED): /* Used to iterate through VMs */
		*(*int32)(unsafe.Pointer(bp + 4)) = 0 /* Used to accumulate return value */
		(*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed = bp + 4
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart
		pVdbe = (*Tsqlite3)(unsafe.Pointer(db)).FpVdbe
		for {
			if !(pVdbe != 0) {
				break
			}
			_sqlite3VdbeDelete(tls, pVdbe)
			goto _5
		_5:
			;
			pVdbe = (*TVdbe1)(unsafe.Pointer(pVdbe)).FpVNext
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd
		(*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed = uintptr(0)
		*(*int32)(unsafe.Pointer(pHighwater)) = 0 /* IMP: R-64479-57858 */
		*(*int32)(unsafe.Pointer(pCurrent)) = *(*int32)(unsafe.Pointer(bp + 4))
		break
		/*
		 ** Set *pCurrent to the total cache hits or misses encountered by all
		 ** pagers the database handle is connected to. *pHighwater is always set
		 ** to zero.
		 */
		fallthrough
	case int32(SQLITE_DBSTATUS_CACHE_SPILL):
		op = libc.Int32FromInt32(SQLITE_DBSTATUS_CACHE_WRITE) + libc.Int32FromInt32(1)
		fallthrough
	case int32(SQLITE_DBSTATUS_CACHE_HIT):
		fallthrough
	case int32(SQLITE_DBSTATUS_CACHE_MISS):
		fallthrough
	case int32(SQLITE_DBSTATUS_CACHE_WRITE):
		*(*Tu64)(unsafe.Pointer(bp + 8)) = uint64(0)
		i2 = 0
		for {
			if !(i2 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i2)*16))).FpBt != 0 {
				pPager1 = _sqlite3BtreePager(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i2)*16))).FpBt)
				_sqlite3PagerCacheStat(tls, pPager1, op, resetFlag, bp+8)
			}
			goto _6
		_6:
			;
			i2++
		}
		*(*int32)(unsafe.Pointer(pHighwater)) = 0 /* IMP: R-42420-56072 */
		/* IMP: R-54100-20147 */
		/* IMP: R-29431-39229 */
		*(*int32)(unsafe.Pointer(pCurrent)) = int32(*(*Tu64)(unsafe.Pointer(bp + 8))) & int32(0x7fffffff)
		break
		/* Set *pCurrent to non-zero if there are unresolved deferred foreign
		 ** key constraints.  Set *pCurrent to zero if all foreign key constraints
		 ** have been satisfied.  The *pHighwater is always set to zero.
		 */
		fallthrough
	case int32(SQLITE_DBSTATUS_DEFERRED_FKS):
		*(*int32)(unsafe.Pointer(pHighwater)) = 0 /* IMP: R-11967-56545 */
		*(*int32)(unsafe.Pointer(pCurrent)) = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons > 0 || (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons > 0)
	default:
		rc = int32(SQLITE_ERROR)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

type t__timeb32 = struct {
	Ftime     t__time32_t
	Fmillitm  uint16
	Ftimezone int16
	Fdstflag  int16
}

type Ttimeb = struct {
	Ftime     Ttime_t
	Fmillitm  uint16
	Ftimezone int16
	Fdstflag  int16
}

type timeb = Ttimeb

type t__timeb64 = struct {
	F__ccgo_align [0]uint32
	Ftime         t__time64_t
	Fmillitm      uint16
	Ftimezone     int16
	Fdstflag      int16
	F__ccgo_pad4  [2]byte
}

type T_timespec32 = struct {
	Ftv_sec  t__time32_t
	Ftv_nsec int32
}

type _timespec32 = T_timespec32

type T_timespec64 = struct {
	F__ccgo_align [0]uint32
	Ftv_sec       t__time64_t
	Ftv_nsec      int32
	F__ccgo_pad2  [4]byte
}

type _timespec64 = T_timespec64

type Ttimespec = struct {
	Ftv_sec  Ttime_t
	Ftv_nsec int32
}

type timespec = Ttimespec

type Titimerspec = struct {
	Fit_interval Ttimespec
	Fit_value    Ttimespec
}

type itimerspec = Titimerspec

type Tclock_t = int32

type clock_t = Tclock_t

type Ttm = struct {
	Ftm_sec   int32
	Ftm_min   int32
	Ftm_hour  int32
	Ftm_mday  int32
	Ftm_mon   int32
	Ftm_year  int32
	Ftm_wday  int32
	Ftm_yday  int32
	Ftm_isdst int32
}

type tm = Ttm

type Ttimeval = struct {
	Ftv_sec  int32
	Ftv_usec int32
}

type timeval = Ttimeval

type Ttimezone = struct {
	Ftz_minuteswest int32
	Ftz_dsttime     int32
}

type timezone = Ttimezone

type Tclockid_t = int32

type clockid_t = Tclockid_t

/*
** The MSVC CRT on Windows CE may not have a localtime() function.
** So declare a substitute.  The substitute function itself is
** defined in "os_win.c".
 */

// C documentation
//
//	/*
//	** A structure for holding a single date and time.
//	*/
type TDateTime = struct {
	F__ccgo_align [0]uint32
	FiJD          Tsqlite3_int64
	FY            int32
	FM            int32
	FD            int32
	Fh            int32
	Fm            int32
	Ftz           int32
	Fs            float64
	FvalidJD      int8
	FvalidYMD     int8
	FvalidHMS     int8
	FnFloor       int8
	F__ccgo44     uint8
	F__ccgo_pad17 [3]byte
}

type DateTime = TDateTime

type TDateTime1 = struct {
	F__ccgo_align [0]uint32
	FiJD          Tsqlite3_int64
	FY            int32
	FM            int32
	FD            int32
	Fh            int32
	Fm            int32
	Ftz           int32
	Fs            float64
	FvalidJD      int8
	FvalidYMD     int8
	FvalidHMS     int8
	FnFloor       int8
	F__ccgo44     uint8
	F__ccgo_pad17 [3]byte
}

type DateTime1 = TDateTime1

// C documentation
//
//	/*
//	** Convert zDate into one or more integers according to the conversion
//	** specifier zFormat.
//	**
//	** zFormat[] contains 4 characters for each integer converted, except for
//	** the last integer which is specified by three characters.  The meaning
//	** of a four-character format specifiers ABCD is:
//	**
//	**    A:   number of digits to convert.  Always "2" or "4".
//	**    B:   minimum value.  Always "0" or "1".
//	**    C:   maximum value, decoded as:
//	**           a:  12
//	**           b:  14
//	**           c:  24
//	**           d:  31
//	**           e:  59
//	**           f:  9999
//	**    D:   the separator character, or \000 to indicate this is the
//	**         last number to convert.
//	**
//	** Example:  To translate an ISO-8601 date YYYY-MM-DD, the format would
//	** be "40f-21a-20c".  The "40f-" indicates the 4-digit year followed by "-".
//	** The "21a-" indicates the 2-digit month followed by "-".  The "20c" indicates
//	** the 2-digit day which is the last integer in the set.
//	**
//	** The function returns the number of successful conversions.
//	*/
func _getDigits(tls *libc.TLS, zDate uintptr, zFormat uintptr, va uintptr) (r int32) {
	var N, min, nextC, v1 int8
	var ap Tva_list
	var cnt, val int32
	var max Tu16
	_, _, _, _, _, _, _, _ = N, ap, cnt, max, min, nextC, val, v1
	cnt = 0
	ap = va
	for cond := true; cond; cond = nextC != 0 {
		N = int8(int32(*(*int8)(unsafe.Pointer(zFormat))) - int32('0'))
		min = int8(int32(*(*int8)(unsafe.Pointer(zFormat + 1))) - int32('0'))
		val = 0
		max = _aMx[int32(*(*int8)(unsafe.Pointer(zFormat + 2)))-int32('a')]
		nextC = *(*int8)(unsafe.Pointer(zFormat + 3))
		val = 0
		for {
			v1 = N
			N--
			if !(v1 != 0) {
				break
			}
			if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zDate)))])&libc.Int32FromInt32(0x04) != 0) {
				goto end_getDigits
			}
			val = val*int32(10) + int32(*(*int8)(unsafe.Pointer(zDate))) - int32('0')
			zDate++
		}
		if val < int32(int32(min)) || val > int32(int32(max)) || int32(int32(nextC)) != 0 && int32(int32(nextC)) != int32(*(*int8)(unsafe.Pointer(zDate))) {
			goto end_getDigits
		}
		*(*int32)(unsafe.Pointer(libc.VaUintptr(&ap))) = val
		zDate++
		cnt++
		zFormat += uintptr(4)
	}
	goto end_getDigits
end_getDigits:
	;
	_ = ap
	return cnt
}

/* The aMx[] array translates the 3rd character of each format
 ** spec into a max size:    a   b   c   d   e      f */
var _aMx = [6]Tu16{
	0: uint16(12),
	1: uint16(14),
	2: uint16(24),
	3: uint16(31),
	4: uint16(59),
	5: uint16(14712),
}

// 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 int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zDate)))])&int32(0x01) != 0 {
		zDate++
	}
	(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
	c = int32(*(*int8)(unsafe.Pointer(zDate)))
	if c == int32('-') {
		sgn = -int32(1)
	} else {
		if c == int32('+') {
			sgn = +libc.Int32FromInt32(1)
		} else {
			if c == int32('Z') || c == int32('z') {
				zDate++
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 4, 0x10)
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 3, 0x8)
				goto zulu_time
			} else {
				return libc.BoolInt32(c != 0)
			}
		}
	}
	zDate++
	if _getDigits(tls, zDate, __ccgo_ts+1164, libc.VaList(bp+16, bp, bp+4)) != int32(2) {
		return int32(1)
	}
	zDate += uintptr(5)
	(*TDateTime)(unsafe.Pointer(p)).Ftz = sgn * (*(*int32)(unsafe.Pointer(bp + 4)) + *(*int32)(unsafe.Pointer(bp))*int32(60))
	goto zulu_time
zulu_time:
	;
	for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zDate)))])&int32(0x01) != 0 {
		zDate++
	}
	return libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zDate))) != 0)
}

// 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+1172, libc.VaList(bp+24, bp, bp+4)) != int32(2) {
		return int32(1)
	}
	zDate += uintptr(5)
	if int32(*(*int8)(unsafe.Pointer(zDate))) == int32(':') {
		zDate++
		if _getDigits(tls, zDate, __ccgo_ts+1180, libc.VaList(bp+24, bp+8)) != int32(1) {
			return int32(1)
		}
		zDate += uintptr(2)
		if int32(*(*int8)(unsafe.Pointer(zDate))) == int32('.') && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zDate + 1)))])&int32(0x04) != 0 {
			rScale = float64(1)
			zDate++
			for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zDate)))])&int32(0x04) != 0 {
				ms = ms*float64(10) + float64(*(*int8)(unsafe.Pointer(zDate))) - libc.Float64FromUint8('0')
				rScale *= float64(10)
				zDate++
			}
			ms /= rScale
		}
	} else {
		*(*int32)(unsafe.Pointer(bp + 8)) = 0
	}
	(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
	(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = int8(1)
	(*TDateTime)(unsafe.Pointer(p)).Fh = *(*int32)(unsafe.Pointer(bp))
	(*TDateTime)(unsafe.Pointer(p)).Fm = *(*int32)(unsafe.Pointer(bp + 4))
	(*TDateTime)(unsafe.Pointer(p)).Fs = float64(*(*int32)(unsafe.Pointer(bp + 8))) + ms
	if _parseTimezone(tls, zDate, p) != 0 {
		return int32(1)
	}
	return 0
}

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

// 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))&0x1>>0)) != 0 {
		_datetimeError(tls, p)
		return
	}
	if M <= int32(2) {
		Y--
		M += int32(12)
	}
	A = Y / int32(100)
	B = int32(2) - 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(X1+X2+D+B) - libc.Float64FromFloat64(1524.5)) * libc.Float64FromInt32(86400000))
	(*TDateTime)(unsafe.Pointer(p)).FvalidJD = int8(1)
	if (*TDateTime)(unsafe.Pointer(p)).FvalidHMS != 0 {
		*(*Tsqlite3_int64)(unsafe.Pointer(p)) += int64((*TDateTime)(unsafe.Pointer(p)).Fh*int32(3600000)+(*TDateTime)(unsafe.Pointer(p)).Fm*int32(60000)) + int64((*TDateTime)(unsafe.Pointer(p)).Fs*libc.Float64FromInt32(1000)+libc.Float64FromFloat64(0.5))
		if (*TDateTime)(unsafe.Pointer(p)).Ftz != 0 {
			*(*Tsqlite3_int64)(unsafe.Pointer(p)) -= int64((*TDateTime)(unsafe.Pointer(p)).Ftz * int32(60000))
			(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = 0
			(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = 0
			(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 3, 0x8)
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 4, 0x10)
		}
	}
}

// C documentation
//
//	/*
//	** Given the YYYY-MM-DD information current in p, determine if there
//	** is day-of-month overflow and set nFloor to the number of days that
//	** would need to be subtracted from the date in order to bring the
//	** date back to the end of the month.
//	*/
func _computeFloor(tls *libc.TLS, p uintptr) {
	if (*TDateTime)(unsafe.Pointer(p)).FD <= int32(28) {
		(*TDateTime)(unsafe.Pointer(p)).FnFloor = 0
	} else {
		if int32(1)<<(*TDateTime)(unsafe.Pointer(p)).FM&int32(0x15aa) != 0 {
			(*TDateTime)(unsafe.Pointer(p)).FnFloor = 0
		} else {
			if (*TDateTime)(unsafe.Pointer(p)).FM != int32(2) {
				(*TDateTime)(unsafe.Pointer(p)).FnFloor = libc.BoolInt8((*TDateTime)(unsafe.Pointer(p)).FD == libc.Int32FromInt32(31))
			} else {
				if (*TDateTime)(unsafe.Pointer(p)).FY%int32(4) != 0 || (*TDateTime)(unsafe.Pointer(p)).FY%int32(100) == 0 && (*TDateTime)(unsafe.Pointer(p)).FY%int32(400) != 0 {
					(*TDateTime)(unsafe.Pointer(p)).FnFloor = int8((*TDateTime)(unsafe.Pointer(p)).FD - int32(28))
				} else {
					(*TDateTime)(unsafe.Pointer(p)).FnFloor = int8((*TDateTime)(unsafe.Pointer(p)).FD - int32(29))
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Parse dates of the form
//	**
//	**     YYYY-MM-DD HH:MM:SS.FFF
//	**     YYYY-MM-DD HH:MM:SS
//	**     YYYY-MM-DD HH:MM
//	**     YYYY-MM-DD
//	**
//	** Write the result into the DateTime structure and return 0
//	** on success and 1 if the input string is not a well-formed
//	** date.
//	*/
func _parseYyyyMmDd(tls *libc.TLS, zDate uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var neg, v1 int32
	var _ /* D at bp+8 */ int32
	var _ /* M at bp+4 */ int32
	var _ /* Y at bp+0 */ int32
	_, _ = neg, v1
	if int32(*(*int8)(unsafe.Pointer(zDate))) == int32('-') {
		zDate++
		neg = int32(1)
	} else {
		neg = 0
	}
	if _getDigits(tls, zDate, __ccgo_ts+1184, libc.VaList(bp+24, bp, bp+4, bp+8)) != int32(3) {
		return int32(1)
	}
	zDate += uintptr(10)
	for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zDate)))])&int32(0x01) != 0 || int32('T') == int32(*(*Tu8)(unsafe.Pointer(zDate))) {
		zDate++
	}
	if _parseHhMmSs(tls, zDate, p) == 0 {
		/* We got the time */
	} else {
		if int32(*(*int8)(unsafe.Pointer(zDate))) == 0 {
			(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = 0
		} else {
			return int32(1)
		}
	}
	(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
	(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = int8(1)
	if neg != 0 {
		v1 = -*(*int32)(unsafe.Pointer(bp))
	} else {
		v1 = *(*int32)(unsafe.Pointer(bp))
	}
	(*TDateTime)(unsafe.Pointer(p)).FY = v1
	(*TDateTime)(unsafe.Pointer(p)).FM = *(*int32)(unsafe.Pointer(bp + 4))
	(*TDateTime)(unsafe.Pointer(p)).FD = *(*int32)(unsafe.Pointer(bp + 8))
	_computeFloor(tls, p)
	if (*TDateTime)(unsafe.Pointer(p)).Ftz != 0 {
		_computeJD(tls, p)
	}
	return 0
}

/* Forward declaration */

// 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 = int8(1)
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 3, 0x8)
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 4, 0x10)
		_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), 0, 0x1)
	if r >= float64(0) && r < float64(5.3734845e+06) {
		(*TDateTime)(unsafe.Pointer(p)).FiJD = int64(r*libc.Float64FromFloat64(8.64e+07) + libc.Float64FromFloat64(0.5))
		(*TDateTime)(unsafe.Pointer(p)).FvalidJD = int8(1)
	}
}

// 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+1196) == 0 && _sqlite3NotPureFunc(tls, context) != 0 {
				return _setDateTimeToCurrent(tls, context, p)
			} else {
				if _sqlite3AtoF(tls, zDate, bp, _sqlite3Strlen30(tls, zDate), uint8(SQLITE_UTF8)) > 0 {
					_setRawDateNumber(tls, p, *(*float64)(unsafe.Pointer(bp)))
					return 0
				} else {
					if (_sqlite3StrICmp(tls, zDate, __ccgo_ts+1200) == 0 || _sqlite3StrICmp(tls, zDate, __ccgo_ts+1207) == 0) && _sqlite3NotPureFunc(tls, context) != 0 {
						libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 2, 0x4)
						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
//
//	/*
//	** Return TRUE if the given julian day number is within range.
//	**
//	** The input is the JulianDay times 86400000.
//	*/
func _validJulianDay(tls *libc.TLS, iJD Tsqlite3_int64) (r int32) {
	return libc.BoolInt32(iJD >= 0 && iJD <= libc.Int64FromInt32(0x1a640)<<libc.Int32FromInt32(32)|libc.Int64FromInt32(0x1072fdff))
}

// C documentation
//
//	/*
//	** Compute the Year, Month, and Day from the julian day number.
//	*/
func _computeYMD(tls *libc.TLS, p uintptr) {
	var A, B, C, D, E, X1, Z, v1, v2 int32
	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, X1, Z, v1, v2
	if (*TDateTime)(unsafe.Pointer(p)).FvalidYMD != 0 {
		return
	}
	if !((*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0) {
		(*TDateTime)(unsafe.Pointer(p)).FY = int32(2000)
		(*TDateTime)(unsafe.Pointer(p)).FM = int32(1)
		(*TDateTime)(unsafe.Pointer(p)).FD = int32(1)
	} else {
		if !(_validJulianDay(tls, (*TDateTime)(unsafe.Pointer(p)).FiJD) != 0) {
			_datetimeError(tls, p)
			return
		} else {
			Z = int32(((*TDateTime)(unsafe.Pointer(p)).FiJD + libc.Int64FromInt32(43200000)) / libc.Int64FromInt32(86400000))
			A = int32((float64(float64(Z)) - libc.Float64FromFloat64(1.86721625e+06)) / libc.Float64FromFloat64(36524.25))
			A = Z + int32(1) + A - A/int32(4)
			B = A + int32(1524)
			C = int32((float64(float64(B)) - libc.Float64FromFloat64(122.1)) / libc.Float64FromFloat64(365.25))
			D = int32(36525) * (C & int32(32767)) / int32(100)
			E = int32(float64(B-D) / libc.Float64FromFloat64(30.6001))
			X1 = int32(libc.Float64FromFloat64(30.6001) * float64(float64(E)))
			(*TDateTime)(unsafe.Pointer(p)).FD = B - D - X1
			if E < int32(14) {
				v1 = E - int32(1)
			} else {
				v1 = E - int32(13)
			}
			(*TDateTime)(unsafe.Pointer(p)).FM = v1
			if (*TDateTime)(unsafe.Pointer(p)).FM > int32(2) {
				v2 = C - int32(4716)
			} else {
				v2 = C - int32(4715)
			}
			(*TDateTime)(unsafe.Pointer(p)).FY = v2
		}
	}
	(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = int8(1)
}

// 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), 0, 0x1)
	(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = int8(1)
}

// C documentation
//
//	/*
//	** Compute both YMD and HMS
//	*/
func _computeYMD_HMS(tls *libc.TLS, p uintptr) {
	_computeYMD(tls, p)
	_computeHMS(tls, p)
}

// C documentation
//
//	/*
//	** Clear the YMD and HMS and the TZ
//	*/
func _clearYMD_HMS_TZ(tls *libc.TLS, p uintptr) {
	(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = 0
	(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = 0
	(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
}

/*
** On recent Windows platforms, the localtime_s() function is available
** as part of the "Secure CRT". It is essentially equivalent to
** localtime_r() available under most POSIX platforms, except that the
** order of the parameters is reversed.
**
** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
**
** If the user has not indicated to use localtime_r() or localtime_s()
** already, check for an MSVC build environment that provides
** localtime_s().
 */

// C documentation
//
//	/*
//	** The following routine implements the rough equivalent of localtime_r()
//	** using whatever operating-system specific localtime facility that
//	** is available.  This routine returns 0 on success and
//	** non-zero on any kind of error.
//	**
//	** If the sqlite3GlobalConfig.bLocaltimeFault variable is non-zero then this
//	** routine will always fail.  If bLocaltimeFault is nonzero and
//	** sqlite3GlobalConfig.xAltLocaltime is not NULL, then xAltLocaltime() is
//	** invoked in place of the OS-defined localtime() function.
//	**
//	** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
//	** library function localtime_r() is used to assist in the calculation of
//	** local time.
//	*/
func _osLocaltime(tls *libc.TLS, t uintptr, pTm uintptr) (r int32) {
	var mutex, pX, v1 uintptr
	var rc int32
	_, _, _, _ = mutex, pX, rc, v1
	mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
	Xsqlite3_mutex_enter(tls, mutex)
	v1 = libc.X_localtime32(tls, t)
	goto _2
_2:
	pX = v1
	if _sqlite3Config.FbLocaltimeFault != 0 {
		if _sqlite3Config.FxAltLocaltime != uintptr(0) && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.FxAltLocaltime})))(tls, t, pTm) {
			pX = pTm
		} else {
			pX = uintptr(0)
		}
	}
	if pX != 0 {
		*(*Ttm)(unsafe.Pointer(pTm)) = *(*Ttm)(unsafe.Pointer(pX))
	}
	Xsqlite3_mutex_leave(tls, mutex)
	rc = libc.BoolInt32(pX == uintptr(0))
	return rc
}

// 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(96)
	defer tls.Free(96)
	var iYearDiff int32
	var _ /* sLocal at bp+4 */ Ttm
	var _ /* t at bp+0 */ Ttime_t
	var _ /* x at bp+40 */ TDateTime
	_ = iYearDiff
	/* Initialize the contents of sLocal to avoid a compiler warning. */
	libc.Xmemset(tls, bp+4, 0, uint32(36))
	_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)(unsafe.Pointer(bp + 40)) = *(*TDateTime)(unsafe.Pointer(p))
		_computeYMD_HMS(tls, bp+40)
		iYearDiff = int32(2000) + (*(*TDateTime)(unsafe.Pointer(bp + 40))).FY%int32(4) - (*(*TDateTime)(unsafe.Pointer(bp + 40))).FY
		(*(*TDateTime)(unsafe.Pointer(bp + 40))).FY += iYearDiff
		(*(*TDateTime)(unsafe.Pointer(bp + 40))).FvalidJD = 0
		_computeJD(tls, bp+40)
		*(*Ttime_t)(unsafe.Pointer(bp)) = int32((*(*TDateTime)(unsafe.Pointer(bp + 40))).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
	} else {
		iYearDiff = 0
		*(*Ttime_t)(unsafe.Pointer(bp)) = int32((*TDateTime)(unsafe.Pointer(p)).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
	}
	if _osLocaltime(tls, bp, bp+4) != 0 {
		Xsqlite3_result_error(tls, pCtx, __ccgo_ts+1217, -int32(1))
		return int32(SQLITE_ERROR)
	}
	(*TDateTime)(unsafe.Pointer(p)).FY = (*(*Ttm)(unsafe.Pointer(bp + 4))).Ftm_year + int32(1900) - iYearDiff
	(*TDateTime)(unsafe.Pointer(p)).FM = (*(*Ttm)(unsafe.Pointer(bp + 4))).Ftm_mon + int32(1)
	(*TDateTime)(unsafe.Pointer(p)).FD = (*(*Ttm)(unsafe.Pointer(bp + 4))).Ftm_mday
	(*TDateTime)(unsafe.Pointer(p)).Fh = (*(*Ttm)(unsafe.Pointer(bp + 4))).Ftm_hour
	(*TDateTime)(unsafe.Pointer(p)).Fm = (*(*Ttm)(unsafe.Pointer(bp + 4))).Ftm_min
	(*TDateTime)(unsafe.Pointer(p)).Fs = float64((*(*Ttm)(unsafe.Pointer(bp + 4))).Ftm_sec) + float64((*TDateTime)(unsafe.Pointer(p)).FiJD%libc.Int64FromInt32(1000))*float64(0.001)
	(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = int8(1)
	(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = int8(1)
	(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
	(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 1, 0x2)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The following table defines various date transformations of the form
//	**
//	**            'NNN days'
//	**
//	** Where NNN is an arbitrary floating-point number and "days" can be one
//	** of several units of time.
//	*/
var _aXformType = [6]struct {
	FnName  Tu8
	FzName  [7]int8
	FrLimit float32
	FrXform float32
}{
	0: {
		FnName:  uint8(6),
		FzName:  [7]int8{'s', 'e', 'c', 'o', 'n', 'd'},
		FrLimit: float32(4.6427e+14),
		FrXform: float32(1),
	},
	1: {
		FnName:  uint8(6),
		FzName:  [7]int8{'m', 'i', 'n', 'u', 't', 'e'},
		FrLimit: float32(7.7379e+12),
		FrXform: float32(60),
	},
	2: {
		FnName:  uint8(4),
		FzName:  [7]int8{'h', 'o', 'u', 'r'},
		FrLimit: float32(1.2897e+11),
		FrXform: float32(3600),
	},
	3: {
		FnName:  uint8(3),
		FzName:  [7]int8{'d', 'a', 'y'},
		FrLimit: float32(5.373485e+06),
		FrXform: float32(86400),
	},
	4: {
		FnName:  uint8(5),
		FzName:  [7]int8{'m', 'o', 'n', 't', 'h'},
		FrLimit: float32(176546),
		FrXform: float32(libc.Float64FromFloat64(30) * libc.Float64FromFloat64(86400)),
	},
	5: {
		FnName:  uint8(4),
		FzName:  [7]int8{'y', 'e', 'a', 'r'},
		FrLimit: float32(14713),
		FrXform: float32(libc.Float64FromFloat64(365) * libc.Float64FromFloat64(86400)),
	},
}

// 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))&0x1>>0)) != 0) || (*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0 {
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
	} 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 = (*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 = int8(1)
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
		}
	}
}

// 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, x, y, v1, v10, v13, v3, v6, v8 int32
	var iErr, iGuess, iOrigJD, v2 Ti64
	var rRounder, v11 float64
	var z0 int8
	var z2 uintptr
	var v4, v7 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, i, iErr, iGuess, iOrigJD, rRounder, rc, x, y, z0, z2, v1, v10, v11, v13, v2, v3, v4, v6, v7, v8
	rc = int32(1)
	switch int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(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+1240) == 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+1245) == 0 {
			_computeJD(tls, p)
			_clearYMD_HMS_TZ(tls, p)
			rc = 0
			(*TDateTime)(unsafe.Pointer(p)).FnFloor = 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+1253) == 0 {
			_computeJD(tls, p)
			*(*Tsqlite3_int64)(unsafe.Pointer(p)) -= int64(int32((*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+1259) == 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))&0x1>>0)) != 0 {
				rc = 0
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
			}
		}
	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+1269) == 0 && _sqlite3NotPureFunc(tls, pCtx) != 0 {
			if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x10>>4)) != 0 {
				v1 = SQLITE_OK
			} else {
				v1 = _toLocaltime(tls, p, pCtx)
			}
			rc = v1
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 3, 0x8)
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 4, 0x10)
		}
	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+1279) == 0 && int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x1>>0)) != 0 {
			if idx > int32(1) {
				return int32(1)
			} /* IMP: R-49255-55373 */
			*(*float64)(unsafe.Pointer(bp)) = (*TDateTime)(unsafe.Pointer(p)).Fs*float64(1000) + float64(2.1086676e+14)
			if *(*float64)(unsafe.Pointer(bp)) >= float64(0) && *(*float64)(unsafe.Pointer(bp)) < float64(4.642690608e+14) {
				_clearYMD_HMS_TZ(tls, p)
				(*TDateTime)(unsafe.Pointer(p)).FiJD = int64(*(*float64)(unsafe.Pointer(bp)) + libc.Float64FromFloat64(0.5))
				(*TDateTime)(unsafe.Pointer(p)).FvalidJD = int8(1)
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
				rc = 0
			}
		} else {
			if Xsqlite3_stricmp(tls, z, __ccgo_ts+1289) == 0 && _sqlite3NotPureFunc(tls, pCtx) != 0 {
				if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x8>>3)) == 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, uint32(48))
						iGuess -= iErr
						(*(*TDateTime)(unsafe.Pointer(bp + 8))).FiJD = iGuess
						(*(*TDateTime)(unsafe.Pointer(bp + 8))).FvalidJD = int8(1)
						rc = _toLocaltime(tls, bp+8, pCtx)
						if rc != 0 {
							return rc
						}
						_computeJD(tls, bp+8)
						iErr = (*(*TDateTime)(unsafe.Pointer(bp + 8))).FiJD - iOrigJD
						goto _5
					_5:
						;
						if v4 = iErr != 0; v4 {
							v3 = cnt
							cnt++
						}
						if !(v4 && v3 < int32(3)) {
							break
						}
					}
					libc.Xmemset(tls, p, 0, uint32(48))
					(*TDateTime)(unsafe.Pointer(p)).FiJD = iGuess
					(*TDateTime)(unsafe.Pointer(p)).FvalidJD = int8(1)
					libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 3, 0x8)
					libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 4, 0x10)
				}
				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 v7 = Xsqlite3_strnicmp(tls, z, __ccgo_ts+1293, int32(8)) == 0 && _sqlite3AtoF(tls, z+8, bp, _sqlite3Strlen30(tls, z+8), uint8(SQLITE_UTF8)) > 0 && *(*float64)(unsafe.Pointer(bp)) >= float64(0) && *(*float64)(unsafe.Pointer(bp)) < float64(7); v7 {
			v6 = int32(*(*float64)(unsafe.Pointer(bp)))
			n = v6
		}
		if v7 && float64(v6) == *(*float64)(unsafe.Pointer(bp)) {
			_computeYMD_HMS(tls, p)
			(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
			(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
			_computeJD(tls, p)
			Z = ((*TDateTime)(unsafe.Pointer(p)).FiJD + int64(129600000)) / int64(86400000) % int64(7)
			if Z > int64(int64(n)) {
				Z -= int64(7)
			}
			*(*Tsqlite3_int64)(unsafe.Pointer(p)) += (int64(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+1302, int32(9)) != 0 {
			if Xsqlite3_stricmp(tls, z, __ccgo_ts+1200) == 0 || Xsqlite3_stricmp(tls, z, __ccgo_ts+1207) == 0 {
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 2, 0x4)
				rc = 0
			}
			break
		}
		if !((*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0) && !((*TDateTime)(unsafe.Pointer(p)).FvalidYMD != 0) && !((*TDateTime)(unsafe.Pointer(p)).FvalidHMS != 0) {
			break
		}
		z += uintptr(9)
		_computeYMD(tls, p)
		(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = int8(1)
		v8 = libc.Int32FromInt32(0)
		(*TDateTime)(unsafe.Pointer(p)).Fm = v8
		(*TDateTime)(unsafe.Pointer(p)).Fh = v8
		(*TDateTime)(unsafe.Pointer(p)).Fs = float64(0)
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
		(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
		(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1312) == 0 {
			(*TDateTime)(unsafe.Pointer(p)).FD = int32(1)
			rc = 0
		} else {
			if Xsqlite3_stricmp(tls, z, __ccgo_ts+1318) == 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+1323) == 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
		z0 = *(*int8)(unsafe.Pointer(z))
		n = int32(1)
		for {
			if !(*(*int8)(unsafe.Pointer(z + uintptr(n))) != 0) {
				break
			}
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(n)))) == int32(':') {
				break
			}
			if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(n))))])&int32(0x01) != 0 {
				break
			}
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(n)))) == int32('-') {
				if n == int32(5) && _getDigits(tls, z+1, __ccgo_ts+1327, libc.VaList(bp+136, bp+56)) == int32(1) {
					break
				}
				if n == int32(6) && _getDigits(tls, z+1, __ccgo_ts+1331, libc.VaList(bp+136, bp+56)) == int32(1) {
					break
				}
			}
			goto _9
		_9:
			;
			n++
		}
		if _sqlite3AtoF(tls, z, bp, n, uint8(SQLITE_UTF8)) <= 0 {
			break
		}
		if int32(*(*int8)(unsafe.Pointer(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 int32(int32(z0)) != int32('+') && int32(int32(z0)) != int32('-') {
				break
			} /* Must start with +/- */
			if n == int32(5) {
				if _getDigits(tls, z+1, __ccgo_ts+1335, libc.VaList(bp+136, bp+56, bp+60, bp+64)) != int32(3) {
					break
				}
			} else {
				if _getDigits(tls, z+1, __ccgo_ts+1347, libc.VaList(bp+136, bp+56, bp+60, bp+64)) != int32(3) {
					break
				}
				z++
			}
			if *(*int32)(unsafe.Pointer(bp + 60)) >= int32(12) {
				break
			} /* M range 0..11 */
			if *(*int32)(unsafe.Pointer(bp + 64)) >= int32(31) {
				break
			} /* D range 0..30 */
			_computeYMD_HMS(tls, p)
			(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
			if int32(int32(z0)) == int32('-') {
				*(*int32)(unsafe.Pointer(p + 8)) -= *(*int32)(unsafe.Pointer(bp + 56))
				*(*int32)(unsafe.Pointer(p + 12)) -= *(*int32)(unsafe.Pointer(bp + 60))
				*(*int32)(unsafe.Pointer(bp + 64)) = -*(*int32)(unsafe.Pointer(bp + 64))
			} else {
				*(*int32)(unsafe.Pointer(p + 8)) += *(*int32)(unsafe.Pointer(bp + 56))
				*(*int32)(unsafe.Pointer(p + 12)) += *(*int32)(unsafe.Pointer(bp + 60))
			}
			if (*TDateTime)(unsafe.Pointer(p)).FM > 0 {
				v10 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(1)) / int32(12)
			} else {
				v10 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(12)) / int32(12)
			}
			x = v10
			*(*int32)(unsafe.Pointer(p + 8)) += x
			*(*int32)(unsafe.Pointer(p + 12)) -= x * int32(12)
			_computeFloor(tls, p)
			_computeJD(tls, p)
			(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = 0
			(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = 0
			*(*Tsqlite3_int64)(unsafe.Pointer(p)) += int64(*(*int32)(unsafe.Pointer(bp + 64))) * int64(86400000)
			if int32(*(*int8)(unsafe.Pointer(z + 11))) == 0 {
				rc = 0
				break
			}
			if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + 11)))])&int32(0x01) != 0 && _getDigits(tls, z+12, __ccgo_ts+1172, libc.VaList(bp+136, bp+68, bp+72)) == int32(2) {
				z2 = z + 12
				n = int32(2)
			} else {
				break
			}
		}
		if int32(*(*int8)(unsafe.Pointer(z2 + uintptr(n)))) == int32(':') {
			if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z2)))])&libc.Int32FromInt32(0x04) != 0) {
				z2++
			}
			libc.Xmemset(tls, bp+80, 0, uint32(48))
			if _parseHhMmSs(tls, z2, bp+80) != 0 {
				break
			}
			_computeJD(tls, bp+80)
			(*(*TDateTime)(unsafe.Pointer(bp + 80))).FiJD -= int64(43200000)
			day = (*(*TDateTime)(unsafe.Pointer(bp + 80))).FiJD / int64(86400000)
			(*(*TDateTime)(unsafe.Pointer(bp + 80))).FiJD -= day * int64(86400000)
			if int32(int32(z0)) == int32('-') {
				(*(*TDateTime)(unsafe.Pointer(bp + 80))).FiJD = -(*(*TDateTime)(unsafe.Pointer(bp + 80))).FiJD
			}
			_computeJD(tls, p)
			_clearYMD_HMS_TZ(tls, p)
			*(*Tsqlite3_int64)(unsafe.Pointer(p)) += (*(*TDateTime)(unsafe.Pointer(bp + 80))).FiJD
			rc = 0
			break
		}
		/* If control reaches this point, it means the transformation is
		 ** one of the forms like "+NNN days".  */
		z += uintptr(n)
		for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x01) != 0 {
			z++
		}
		n = _sqlite3Strlen30(tls, z)
		if n < int32(3) || n > int32(10) {
			break
		}
		if int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(z + uintptr(n-int32(1)))))]) == int32('s') {
			n--
		}
		_computeJD(tls, p)
		if *(*float64)(unsafe.Pointer(bp)) < libc.Float64FromInt32(0) {
			v11 = -libc.Float64FromFloat64(0.5)
		} else {
			v11 = +libc.Float64FromFloat64(0.5)
		}
		rRounder = v11
		(*TDateTime)(unsafe.Pointer(p)).FnFloor = 0
		i = 0
		for {
			if !(i < int32(libc.Uint32FromInt64(96)/libc.Uint32FromInt64(16))) {
				break
			}
			if int32(_aXformType[i].FnName) == n && Xsqlite3_strnicmp(tls, uintptr(unsafe.Pointer(&_aXformType))+uintptr(i)*16+1, z, n) == 0 && *(*float64)(unsafe.Pointer(bp)) > float64(-_aXformType[i].FrLimit) && *(*float64)(unsafe.Pointer(bp)) < float64(_aXformType[i].FrLimit) {
				switch i {
				case int32(4): /* Special processing to add months */
					_computeYMD_HMS(tls, p)
					*(*int32)(unsafe.Pointer(p + 12)) += int32(*(*float64)(unsafe.Pointer(bp)))
					if (*TDateTime)(unsafe.Pointer(p)).FM > 0 {
						v13 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(1)) / int32(12)
					} else {
						v13 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(12)) / int32(12)
					}
					x = v13
					*(*int32)(unsafe.Pointer(p + 8)) += x
					*(*int32)(unsafe.Pointer(p + 12)) -= x * int32(12)
					_computeFloor(tls, p)
					(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
					*(*float64)(unsafe.Pointer(bp)) -= float64(int32(*(*float64)(unsafe.Pointer(bp))))
				case int32(5): /* Special processing to add years */
					y = int32(*(*float64)(unsafe.Pointer(bp)))
					_computeYMD_HMS(tls, p)
					*(*int32)(unsafe.Pointer(p + 8)) += y
					_computeFloor(tls, p)
					(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
					*(*float64)(unsafe.Pointer(bp)) -= float64(int32(*(*float64)(unsafe.Pointer(bp))))
					break
				}
				_computeJD(tls, p)
				*(*Tsqlite3_int64)(unsafe.Pointer(p)) += int64(*(*float64)(unsafe.Pointer(bp))*libc.Float64FromFloat64(1000)*float64(_aXformType[i].FrXform) + rRounder)
				rc = 0
				break
			}
			goto _12
		_12:
			;
			i++
		}
		_clearYMD_HMS_TZ(tls, p)
	default:
		break
	}
	return rc
}

// 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, uint32(48))
	if argc == 0 {
		if !(_sqlite3NotPureFunc(tls, context) != 0) {
			return int32(1)
		}
		return _setDateTimeToCurrent(tls, context, p)
	}
	v1 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	eType = v1
	if v1 == int32(SQLITE_FLOAT) || eType == int32(SQLITE_INTEGER) {
		_setRawDateNumber(tls, p, Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv))))
	} else {
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(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)(unsafe.Pointer(argv + uintptr(i)*4)))
		n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		if z == uintptr(0) || _parseModifier(tls, context, z, n, p, i) != 0 {
			return int32(1)
		}
		goto _2
	_2:
		;
		i++
	}
	_computeJD(tls, p)
	if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x2>>1)) != 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 = 0
	}
	return 0
}

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

// C documentation
//
//	/*
//	**    julianday( TIMESTRING, MOD, MOD, ...)
//	**
//	** Return the julian day number of the date specified in the arguments
//	*/
func _juliandayFunc(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)
		Xsqlite3_result_double(tls, context, float64((*(*TDateTime)(unsafe.Pointer(bp))).FiJD)/float64(8.64e+07))
	}
}

// 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))&0x4>>2)) != 0 {
			Xsqlite3_result_double(tls, context, float64((*(*TDateTime)(unsafe.Pointer(bp))).FiJD-libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000000))/float64(1000))
		} else {
			Xsqlite3_result_int64(tls, context, (*(*TDateTime)(unsafe.Pointer(bp))).FiJD/int64(1000)-libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
		}
	}
}

// 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]int8
	_, _, _ = Y, n, s
	if _isDate(tls, context, argc, argv, bp) == 0 {
		_computeYMD_HMS(tls, bp)
		Y = (*(*TDateTime)(unsafe.Pointer(bp))).FY
		if Y < 0 {
			Y = -Y
		}
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(1)] = int8(int32('0') + Y/int32(1000)%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(2)] = int8(int32('0') + Y/int32(100)%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(3)] = int8(int32('0') + Y/int32(10)%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(4)] = int8(int32('0') + Y%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(5)] = int8('-')
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(6)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FM/int32(10)%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(7)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FM%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(8)] = int8('-')
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(9)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FD/int32(10)%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(10)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FD%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(11)] = int8(' ')
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(12)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fh/int32(10)%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(13)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fh%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(14)] = int8(':')
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(15)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fm/int32(10)%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(16)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fm%int32(10))
		(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(17)] = int8(':')
		if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x4>>2)) != 0 {
			s = int32(libc.Float64FromFloat64(1000)*(*(*TDateTime)(unsafe.Pointer(bp))).Fs + libc.Float64FromFloat64(0.5))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(18)] = int8(int32('0') + s/int32(10000)%int32(10))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(19)] = int8(int32('0') + s/int32(1000)%int32(10))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(20)] = int8('.')
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(21)] = int8(int32('0') + s/int32(100)%int32(10))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(22)] = int8(int32('0') + s/int32(10)%int32(10))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(23)] = int8(int32('0') + s%int32(10))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(24)] = 0
			n = int32(24)
		} else {
			s = int32((*(*TDateTime)(unsafe.Pointer(bp))).Fs)
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(18)] = int8(int32('0') + s/int32(10)%int32(10))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(19)] = int8(int32('0') + s%int32(10))
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[int32(20)] = 0
			n = int32(20)
		}
		if (*(*TDateTime)(unsafe.Pointer(bp))).FY < 0 {
			(*(*[32]int8)(unsafe.Pointer(bp + 48)))[0] = int8('-')
			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
//
//	/*
//	**    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]int8
	_, _ = n, s
	if _isDate(tls, context, argc, argv, bp) == 0 {
		_computeHMS(tls, bp)
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[0] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fh/int32(10)%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(1)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fh%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(2)] = int8(':')
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(3)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fm/int32(10)%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(4)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).Fm%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(5)] = int8(':')
		if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x4>>2)) != 0 {
			s = int32(libc.Float64FromFloat64(1000)*(*(*TDateTime)(unsafe.Pointer(bp))).Fs + libc.Float64FromFloat64(0.5))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(6)] = int8(int32('0') + s/int32(10000)%int32(10))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(7)] = int8(int32('0') + s/int32(1000)%int32(10))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(8)] = int8('.')
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(9)] = int8(int32('0') + s/int32(100)%int32(10))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(10)] = int8(int32('0') + s/int32(10)%int32(10))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(11)] = int8(int32('0') + s%int32(10))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(12)] = 0
			n = int32(12)
		} else {
			s = int32((*(*TDateTime)(unsafe.Pointer(bp))).Fs)
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(6)] = int8(int32('0') + s/int32(10)%int32(10))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(7)] = int8(int32('0') + s%int32(10))
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(8)] = 0
			n = int32(8)
		}
		Xsqlite3_result_text(tls, context, bp+48, n, uintptr(-libc.Int32FromInt32(1)))
	}
}

// C documentation
//
//	/*
//	**    date( TIMESTRING, MOD, MOD, ...)
//	**
//	** Return YYYY-MM-DD
//	*/
func _dateFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var Y int32
	var _ /* x at bp+0 */ TDateTime
	var _ /* zBuf at bp+48 */ [16]int8
	_ = Y
	if _isDate(tls, context, argc, argv, bp) == 0 {
		_computeYMD(tls, bp)
		Y = (*(*TDateTime)(unsafe.Pointer(bp))).FY
		if Y < 0 {
			Y = -Y
		}
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(1)] = int8(int32('0') + Y/int32(1000)%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(2)] = int8(int32('0') + Y/int32(100)%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(3)] = int8(int32('0') + Y/int32(10)%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(4)] = int8(int32('0') + Y%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(5)] = int8('-')
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(6)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FM/int32(10)%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(7)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FM%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(8)] = int8('-')
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(9)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FD/int32(10)%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(10)] = int8(int32('0') + (*(*TDateTime)(unsafe.Pointer(bp))).FD%int32(10))
		(*(*[16]int8)(unsafe.Pointer(bp + 48)))[int32(11)] = 0
		if (*(*TDateTime)(unsafe.Pointer(bp))).FY < 0 {
			(*(*[16]int8)(unsafe.Pointer(bp + 48)))[0] = int8('-')
			Xsqlite3_result_text(tls, context, bp+48, int32(11), uintptr(-libc.Int32FromInt32(1)))
		} else {
			Xsqlite3_result_text(tls, context, bp+48+1, int32(10), uintptr(-libc.Int32FromInt32(1)))
		}
	}
}

// C documentation
//
//	/*
//	** Compute the number of days after the most recent January 1.
//	**
//	** In other words, compute the zero-based day number for the
//	** current year:
//	**
//	**   Jan01 = 0,  Jan02 = 1, ..., Jan31 = 30, Feb01 = 31, ...
//	**   Dec31 = 364 or 365.
//	*/
func _daysAfterJan01(tls *libc.TLS, pDate uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* jan01 at bp+0 */ TDateTime
	*(*TDateTime)(unsafe.Pointer(bp)) = *(*TDateTime)(unsafe.Pointer(pDate))
	(*(*TDateTime)(unsafe.Pointer(bp))).FvalidJD = 0
	(*(*TDateTime)(unsafe.Pointer(bp))).FM = int32(1)
	(*(*TDateTime)(unsafe.Pointer(bp))).FD = int32(1)
	_computeJD(tls, bp)
	return int32(((*TDateTime)(unsafe.Pointer(pDate)).FiJD - (*(*TDateTime)(unsafe.Pointer(bp))).FiJD + libc.Int64FromInt32(43200000)) / libc.Int64FromInt32(86400000))
}

// C documentation
//
//	/*
//	** Return the number of days after the most recent Monday.
//	**
//	** In other words, return the day of the week according
//	** to this code:
//	**
//	**   0=Monday, 1=Tuesday, 2=Wednesday, ..., 6=Sunday.
//	*/
func _daysAfterMonday(tls *libc.TLS, pDate uintptr) (r int32) {
	return int32(((*TDateTime)(unsafe.Pointer(pDate)).FiJD+libc.Int64FromInt32(43200000))/libc.Int64FromInt32(86400000)) % int32(7)
}

// C documentation
//
//	/*
//	** Return the number of days after the most recent Sunday.
//	**
//	** In other words, return the day of the week according
//	** to this code:
//	**
//	**   0=Sunday, 1=Monday, 2=Tues, ..., 6=Saturday
//	*/
func _daysAfterSunday(tls *libc.TLS, pDate uintptr) (r int32) {
	return int32(((*TDateTime)(unsafe.Pointer(pDate)).FiJD+libc.Int64FromInt32(129600000))/libc.Int64FromInt32(86400000)) % int32(7)
}

// 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 int8
	var db, zFmt, v3, v4, v5, v6, v7 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+120 */ TDateTime
	var _ /* y at bp+72 */ TDateTime
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, cf, db, h, i, iS, j, s, zFmt, v2, v3, v4, v5, v6, v7
	if argc == 0 {
		return
	}
	zFmt = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zFmt == uintptr(0) || _isDate(tls, context, argc-int32(1), argv+uintptr(1)*4, bp) != 0 {
		return
	}
	db = Xsqlite3_context_db_handle(tls, context)
	_sqlite3StrAccumInit(tls, bp+48, uintptr(0), uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 120)))
	_computeJD(tls, bp)
	_computeYMD_HMS(tls, bp)
	v2 = libc.Uint32FromInt32(0)
	j = v2
	i = v2
	for {
		if !(*(*int8)(unsafe.Pointer(zFmt + uintptr(i))) != 0) {
			break
		}
		if int32(*(*int8)(unsafe.Pointer(zFmt + uintptr(i)))) != int32('%') {
			goto _1
		}
		if j < i {
			Xsqlite3_str_append(tls, bp+48, zFmt+uintptr(j), int32(i-j))
		}
		i++
		j = i + uint32(1)
		cf = *(*int8)(unsafe.Pointer(zFmt + uintptr(i)))
		switch int32(int32(cf)) {
		case int32('d'): /* Fall thru */
			fallthrough
		case int32('e'):
			if int32(int32(cf)) == int32('d') {
				v3 = __ccgo_ts + 1359
			} else {
				v3 = __ccgo_ts + 1364
			}
			Xsqlite3_str_appendf(tls, bp+48, v3, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).FD))
		case int32('f'): /* Fractional seconds.  (Non-standard) */
			s = (*(*TDateTime)(unsafe.Pointer(bp))).Fs
			if s > float64(59.999) {
				s = float64(59.999)
			}
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1368, libc.VaList(bp+176, s))
		case int32('F'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1375, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).FY, (*(*TDateTime)(unsafe.Pointer(bp))).FM, (*(*TDateTime)(unsafe.Pointer(bp))).FD))
		case int32('G'): /* Fall thru */
			fallthrough
		case int32('g'):
			*(*TDateTime)(unsafe.Pointer(bp + 72)) = *(*TDateTime)(unsafe.Pointer(bp))
			/* Move y so that it is the Thursday in the same week as x */
			(*(*TDateTime)(unsafe.Pointer(bp + 72))).FiJD += int64((int32(3) - _daysAfterMonday(tls, bp)) * int32(86400000))
			(*(*TDateTime)(unsafe.Pointer(bp + 72))).FvalidYMD = 0
			_computeYMD(tls, bp+72)
			if int32(int32(cf)) == int32('g') {
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1359, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp + 72))).FY%int32(100)))
			} else {
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1390, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp + 72))).FY))
			}
		case int32('H'):
			fallthrough
		case int32('k'):
			if int32(int32(cf)) == int32('H') {
				v4 = __ccgo_ts + 1359
			} else {
				v4 = __ccgo_ts + 1364
			}
			Xsqlite3_str_appendf(tls, bp+48, v4, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).Fh))
		case int32('I'): /* Fall thru */
			fallthrough
		case int32('l'):
			h = (*(*TDateTime)(unsafe.Pointer(bp))).Fh
			if h > int32(12) {
				h -= int32(12)
			}
			if h == 0 {
				h = int32(12)
			}
			if int32(int32(cf)) == int32('I') {
				v5 = __ccgo_ts + 1359
			} else {
				v5 = __ccgo_ts + 1364
			}
			Xsqlite3_str_appendf(tls, bp+48, v5, libc.VaList(bp+176, h))
		case int32('j'): /* Day of year.  Jan01==1, Jan02==2, and so forth */
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1395, libc.VaList(bp+176, _daysAfterJan01(tls, bp)+int32(1)))
		case int32('J'): /* Julian day number.  (Non-standard) */
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1400, libc.VaList(bp+176, float64((*(*TDateTime)(unsafe.Pointer(bp))).FiJD)/float64(8.64e+07)))
		case int32('m'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1359, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).FM))
		case int32('M'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1359, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).Fm))
		case int32('p'): /* Fall thru */
			fallthrough
		case int32('P'):
			if (*(*TDateTime)(unsafe.Pointer(bp))).Fh >= int32(12) {
				if int32(int32(cf)) == int32('p') {
					v6 = __ccgo_ts + 1406
				} else {
					v6 = __ccgo_ts + 1409
				}
				Xsqlite3_str_append(tls, bp+48, v6, int32(2))
			} else {
				if int32(int32(cf)) == int32('p') {
					v7 = __ccgo_ts + 1412
				} else {
					v7 = __ccgo_ts + 1415
				}
				Xsqlite3_str_append(tls, bp+48, v7, int32(2))
			}
		case int32('R'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1418, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).Fh, (*(*TDateTime)(unsafe.Pointer(bp))).Fm))
		case int32('s'):
			if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x4>>2)) != 0 {
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1428, libc.VaList(bp+176, float64((*(*TDateTime)(unsafe.Pointer(bp))).FiJD-libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000000))/float64(1000)))
			} else {
				iS = (*(*TDateTime)(unsafe.Pointer(bp))).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000)
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1433, libc.VaList(bp+176, iS))
			}
		case int32('S'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1359, libc.VaList(bp+176, int32((*(*TDateTime)(unsafe.Pointer(bp))).Fs)))
		case int32('T'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1438, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).Fh, (*(*TDateTime)(unsafe.Pointer(bp))).Fm, int32((*(*TDateTime)(unsafe.Pointer(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 = int8(int32(int8(_daysAfterSunday(tls, bp))) + int32('0'))
			if int32(int32(c)) == int32('0') && int32(int32(cf)) == int32('u') {
				c = int8('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+1359, libc.VaList(bp+176, (_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)(unsafe.Pointer(bp + 120)) = *(*TDateTime)(unsafe.Pointer(bp))
			/* Adjust y so that is the Thursday in the same week as x */
			(*(*TDateTime)(unsafe.Pointer(bp + 120))).FiJD += int64((int32(3) - _daysAfterMonday(tls, bp)) * int32(86400000))
			(*(*TDateTime)(unsafe.Pointer(bp + 120))).FvalidYMD = 0
			_computeYMD(tls, bp+120)
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1359, libc.VaList(bp+176, _daysAfterJan01(tls, bp+120)/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+1359, libc.VaList(bp+176, (_daysAfterJan01(tls, bp)-_daysAfterMonday(tls, bp)+int32(7))/int32(7)))
		case int32('Y'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1390, libc.VaList(bp+176, (*(*TDateTime)(unsafe.Pointer(bp))).FY))
		case int32('%'):
			Xsqlite3_str_appendchar(tls, bp+48, int32(1), int8('%'))
		default:
			Xsqlite3_str_reset(tls, bp+48)
			return
		}
		goto _1
	_1:
		;
		i++
	}
	if j < i {
		Xsqlite3_str_append(tls, bp+48, zFmt+uintptr(j), int32(i-j))
	}
	_sqlite3ResultStrAccum(tls, context, bp+48)
}

// C documentation
//
//	/*
//	** current_time()
//	**
//	** This function returns the same value as time('now').
//	*/
func _ctimeFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	_timeFunc(tls, context, 0, uintptr(0))
}

// C documentation
//
//	/*
//	** current_date()
//	**
//	** This function returns the same value as date('now').
//	*/
func _cdateFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	_dateFunc(tls, context, 0, uintptr(0))
}

// C documentation
//
//	/*
//	** timediff(DATE1, DATE2)
//	**
//	** Return the amount of time that must be added to DATE2 in order to
//	** convert it into DATE2.  The time difference format is:
//	**
//	**     +YYYY-MM-DD HH:MM:SS.SSS
//	**
//	** The initial "+" becomes "-" if DATE1 occurs before DATE2.  For
//	** date/time values A and B, the following invariant should hold:
//	**
//	**     datetime(A) == (datetime(B, timediff(A,B))
//	**
//	** Both DATE arguments must be either a julian day number, or an
//	** ISO-8601 string.  The unix timestamps are not supported by this
//	** routine.
//	*/
func _timediffFunc(tls *libc.TLS, context uintptr, NotUsed1 int32, argv uintptr) {
	bp := tls.Alloc(192)
	defer tls.Free(192)
	var M, Y int32
	var sign int8
	var p1, p2 uintptr
	var _ /* d1 at bp+0 */ TDateTime
	var _ /* d2 at bp+48 */ TDateTime
	var _ /* sRes at bp+96 */ Tsqlite3_str
	_, _, _, _, _ = M, Y, sign, p1, p2
	_ = NotUsed1
	if _isDate(tls, context, int32(1), argv, bp) != 0 {
		return
	}
	if _isDate(tls, context, int32(1), argv+1*4, bp+48) != 0 {
		return
	}
	_computeYMD_HMS(tls, bp)
	_computeYMD_HMS(tls, bp+48)
	if (*(*TDateTime)(unsafe.Pointer(bp))).FiJD >= (*(*TDateTime)(unsafe.Pointer(bp + 48))).FiJD {
		sign = int8('+')
		Y = (*(*TDateTime)(unsafe.Pointer(bp))).FY - (*(*TDateTime)(unsafe.Pointer(bp + 48))).FY
		if Y != 0 {
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FY = (*(*TDateTime)(unsafe.Pointer(bp))).FY
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FvalidJD = 0
			_computeJD(tls, bp+48)
		}
		M = (*(*TDateTime)(unsafe.Pointer(bp))).FM - (*(*TDateTime)(unsafe.Pointer(bp + 48))).FM
		if M < 0 {
			Y--
			M += int32(12)
		}
		if M != 0 {
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FM = (*(*TDateTime)(unsafe.Pointer(bp))).FM
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FvalidJD = 0
			_computeJD(tls, bp+48)
		}
		for (*(*TDateTime)(unsafe.Pointer(bp))).FiJD < (*(*TDateTime)(unsafe.Pointer(bp + 48))).FiJD {
			M--
			if M < 0 {
				M = int32(11)
				Y--
			}
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FM--
			if (*(*TDateTime)(unsafe.Pointer(bp + 48))).FM < int32(1) {
				(*(*TDateTime)(unsafe.Pointer(bp + 48))).FM = int32(12)
				(*(*TDateTime)(unsafe.Pointer(bp + 48))).FY--
			}
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FvalidJD = 0
			_computeJD(tls, bp+48)
		}
		(*(*TDateTime)(unsafe.Pointer(bp))).FiJD -= (*(*TDateTime)(unsafe.Pointer(bp + 48))).FiJD
		p1 = bp
		*(*Tsqlite3_int64)(unsafe.Pointer(p1)) = Tsqlite3_int64(uint64(*(*Tsqlite3_int64)(unsafe.Pointer(p1))) + libc.Uint64FromInt32(1486995408)*libc.Uint64FromInt32(100000))
	} else { /* d1<d2 */
		sign = int8('-')
		Y = (*(*TDateTime)(unsafe.Pointer(bp + 48))).FY - (*(*TDateTime)(unsafe.Pointer(bp))).FY
		if Y != 0 {
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FY = (*(*TDateTime)(unsafe.Pointer(bp))).FY
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FvalidJD = 0
			_computeJD(tls, bp+48)
		}
		M = (*(*TDateTime)(unsafe.Pointer(bp + 48))).FM - (*(*TDateTime)(unsafe.Pointer(bp))).FM
		if M < 0 {
			Y--
			M += int32(12)
		}
		if M != 0 {
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FM = (*(*TDateTime)(unsafe.Pointer(bp))).FM
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FvalidJD = 0
			_computeJD(tls, bp+48)
		}
		for (*(*TDateTime)(unsafe.Pointer(bp))).FiJD > (*(*TDateTime)(unsafe.Pointer(bp + 48))).FiJD {
			M--
			if M < 0 {
				M = int32(11)
				Y--
			}
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FM++
			if (*(*TDateTime)(unsafe.Pointer(bp + 48))).FM > int32(12) {
				(*(*TDateTime)(unsafe.Pointer(bp + 48))).FM = int32(1)
				(*(*TDateTime)(unsafe.Pointer(bp + 48))).FY++
			}
			(*(*TDateTime)(unsafe.Pointer(bp + 48))).FvalidJD = 0
			_computeJD(tls, bp+48)
		}
		(*(*TDateTime)(unsafe.Pointer(bp))).FiJD = (*(*TDateTime)(unsafe.Pointer(bp + 48))).FiJD - (*(*TDateTime)(unsafe.Pointer(bp))).FiJD
		p2 = bp
		*(*Tsqlite3_int64)(unsafe.Pointer(p2)) = Tsqlite3_int64(uint64(*(*Tsqlite3_int64)(unsafe.Pointer(p2))) + libc.Uint64FromInt32(1486995408)*libc.Uint64FromInt32(100000))
	}
	_clearYMD_HMS_TZ(tls, bp)
	_computeYMD_HMS(tls, bp)
	_sqlite3StrAccumInit(tls, bp+96, uintptr(0), uintptr(0), 0, int32(100))
	Xsqlite3_str_appendf(tls, bp+96, __ccgo_ts+1453, libc.VaList(bp+128, int32(int32(sign)), Y, M, (*(*TDateTime)(unsafe.Pointer(bp))).FD-int32(1), (*(*TDateTime)(unsafe.Pointer(bp))).Fh, (*(*TDateTime)(unsafe.Pointer(bp))).Fm, (*(*TDateTime)(unsafe.Pointer(bp))).Fs))
	_sqlite3ResultStrAccum(tls, context, bp+96)
}

// C documentation
//
//	/*
//	** current_timestamp()
//	**
//	** This function returns the same value as datetime('now').
//	*/
func _ctimestampFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	_datetimeFunc(tls, context, 0, uintptr(0))
}

// C documentation
//
//	/*
//	** This function registered all of the above C functions as SQL
//	** functions.  This should be the only routine in this file with
//	** external linkage.
//	*/
func _sqlite3RegisterDateTimeFunctions(tls *libc.TLS) {
	_sqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&_aDateTimeFuncs)), int32(libc.Uint32FromInt64(400)/libc.Uint32FromInt64(40)))
}

var _aDateTimeFuncs = [10]TFuncDef{
	0: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1259,
	},
	1: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1279,
	},
	2: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1487,
	},
	3: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1492,
	},
	4: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1497,
	},
	5: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1506,
	},
	6: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1515,
	},
	7: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1524,
	},
	8: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1537,
	},
	9: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1555,
	},
}

func init() {
	p := unsafe.Pointer(&_aDateTimeFuncs)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_juliandayFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_unixepochFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_dateFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_timeFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_datetimeFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_strftimeFunc)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_timediffFunc)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_ctimeFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_ctimestampFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_cdateFunc)
}

/************** End of date.c ************************************************/
/************** Begin file os.c **********************************************/
/*
** 2005 November 29
**
** 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 OS interface code that is common to all
** architectures.
 */
/* #include "sqliteInt.h" */

/*
** If we compile with the SQLITE_TEST macro set, then the following block
** of code will give us the ability to simulate a disk I/O error.  This
** is used for testing the I/O recovery logic.
 */

/*
** When testing, also keep a count of the number of open files.
 */

/*
** The default SQLite sqlite3_vfs implementations do not allocate
** memory (actually, os_unix.c allocates a small amount of memory
** from within OsOpen()), but some third-party implementations may.
** So we test the effects of a malloc() failing and the sqlite3OsXXX()
** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro.
**
** The following functions are instrumented for malloc() failure
** testing:
**
**     sqlite3OsRead()
**     sqlite3OsWrite()
**     sqlite3OsSync()
**     sqlite3OsFileSize()
**     sqlite3OsLock()
**     sqlite3OsCheckReservedLock()
**     sqlite3OsFileControl()
**     sqlite3OsShmMap()
**     sqlite3OsOpen()
**     sqlite3OsDelete()
**     sqlite3OsAccess()
**     sqlite3OsFullPathname()
**
 */

// C documentation
//
//	/*
//	** The following routines are convenience wrappers around methods
//	** of the sqlite3_file object.  This is mostly just syntactic sugar. All
//	** of this would be completely automatic if SQLite were coded using
//	** C++ instead of plain old C.
//	*/
func _sqlite3OsClose(tls *libc.TLS, pId uintptr) {
	if (*Tsqlite3_file)(unsafe.Pointer(pId)).FpMethods != 0 {
		(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pId)).FpMethods)).FxClose})))(tls, pId)
		(*Tsqlite3_file)(unsafe.Pointer(pId)).FpMethods = uintptr(0)
	}
}

func _sqlite3OsRead(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset Ti64) (r int32) {
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxRead})))(tls, id, pBuf, amt, offset)
}

func _sqlite3OsWrite(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset Ti64) (r int32) {
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxWrite})))(tls, id, pBuf, amt, offset)
}

func _sqlite3OsTruncate(tls *libc.TLS, id uintptr, size Ti64) (r int32) {
	return (*(*func(*libc.TLS, uintptr, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxTruncate})))(tls, id, size)
}

func _sqlite3OsSync(tls *libc.TLS, id uintptr, flags int32) (r int32) {
	var v1 int32
	_ = v1
	if flags != 0 {
		v1 = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxSync})))(tls, id, flags)
	} else {
		v1 = SQLITE_OK
	}
	return v1
}

func _sqlite3OsFileSize(tls *libc.TLS, id uintptr, pSize uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFileSize})))(tls, id, pSize)
}

func _sqlite3OsLock(tls *libc.TLS, id uintptr, lockType int32) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxLock})))(tls, id, lockType)
}

func _sqlite3OsUnlock(tls *libc.TLS, id uintptr, lockType int32) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxUnlock})))(tls, id, lockType)
}

func _sqlite3OsCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxCheckReservedLock})))(tls, id, pResOut)
}

// C documentation
//
//	/*
//	** Use sqlite3OsFileControl() when we are doing something that might fail
//	** and we need to know about the failures.  Use sqlite3OsFileControlHint()
//	** when simply tossing information over the wall to the VFS and we do not
//	** really care if the VFS receives and understands the information since it
//	** is only a hint and can be safely ignored.  The sqlite3OsFileControlHint()
//	** routine has no return value since the return value would be meaningless.
//	*/
func _sqlite3OsFileControl(tls *libc.TLS, id uintptr, op int32, pArg uintptr) (r int32) {
	if (*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods == uintptr(0) {
		return int32(SQLITE_NOTFOUND)
	}
	return (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFileControl})))(tls, id, op, pArg)
}

func _sqlite3OsFileControlHint(tls *libc.TLS, id uintptr, op int32, pArg uintptr) {
	if (*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods != 0 {
		(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFileControl})))(tls, id, op, pArg)
	}
}

func _sqlite3OsSectorSize(tls *libc.TLS, id uintptr) (r int32) {
	var xSectorSize uintptr
	var v1 int32
	_, _ = xSectorSize, v1
	xSectorSize = (*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxSectorSize
	if xSectorSize != 0 {
		v1 = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xSectorSize})))(tls, id)
	} else {
		v1 = int32(SQLITE_DEFAULT_SECTOR_SIZE)
	}
	return v1
}

func _sqlite3OsDeviceCharacteristics(tls *libc.TLS, id uintptr) (r int32) {
	if (*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods == uintptr(0) {
		return 0
	}
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxDeviceCharacteristics})))(tls, id)
}

func _sqlite3OsShmLock(tls *libc.TLS, id uintptr, offset int32, n int32, flags int32) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmLock})))(tls, id, offset, n, flags)
}

func _sqlite3OsShmBarrier(tls *libc.TLS, id uintptr) {
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmBarrier})))(tls, id)
}

func _sqlite3OsShmUnmap(tls *libc.TLS, id uintptr, deleteFlag int32) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmUnmap})))(tls, id, deleteFlag)
}

func _sqlite3OsShmMap(tls *libc.TLS, id uintptr, iPage int32, pgsz int32, bExtend int32, pp uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmMap})))(tls, id, iPage, pgsz, bExtend, pp)
}

// C documentation
//
//	/* The real implementation of xFetch and xUnfetch */
func _sqlite3OsFetch(tls *libc.TLS, id uintptr, iOff Ti64, iAmt int32, pp uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, Tsqlite3_int64, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFetch})))(tls, id, iOff, iAmt, pp)
}

func _sqlite3OsUnfetch(tls *libc.TLS, id uintptr, iOff Ti64, p uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, Tsqlite3_int64, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxUnfetch})))(tls, id, iOff, p)
}

// C documentation
//
//	/*
//	** The next group of routines are convenience wrappers around the
//	** VFS methods.
//	*/
func _sqlite3OsOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr, pFile uintptr, flags int32, pFlagsOut uintptr) (r int32) {
	var rc int32
	_ = rc
	/* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
	 ** down into the VFS layer.  Some SQLITE_OPEN_ flags (for example,
	 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
	 ** reaching the VFS. */
	rc = (*(*func(*libc.TLS, uintptr, Tsqlite3_filename, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxOpen})))(tls, pVfs, zPath, pFile, flags&int32(0x1087f7f), pFlagsOut)
	return rc
}

func _sqlite3OsDelete(tls *libc.TLS, pVfs uintptr, zPath uintptr, dirSync int32) (r int32) {
	var v1 int32
	_ = v1
	if (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxDelete != uintptr(0) {
		v1 = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxDelete})))(tls, pVfs, zPath, dirSync)
	} else {
		v1 = SQLITE_OK
	}
	return v1
}

func _sqlite3OsAccess(tls *libc.TLS, pVfs uintptr, zPath uintptr, flags int32, pResOut uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxAccess})))(tls, pVfs, zPath, flags, pResOut)
}

func _sqlite3OsFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nPathOut int32, zPathOut uintptr) (r int32) {
	*(*int8)(unsafe.Pointer(zPathOut)) = 0
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxFullPathname})))(tls, pVfs, zPath, nPathOut, zPathOut)
}

func _sqlite3OsDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) (r uintptr) {
	/* tag-20210611-1 */
	return (*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxDlOpen})))(tls, pVfs, zPath)
}

func _sqlite3OsDlError(tls *libc.TLS, pVfs uintptr, nByte int32, zBufOut uintptr) {
	(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxDlError})))(tls, pVfs, nByte, zBufOut)
}

func _sqlite3OsDlSym(tls *libc.TLS, pVfs uintptr, pHdle uintptr, zSym uintptr) (r uintptr) {
	return (*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxDlSym})))(tls, pVfs, pHdle, zSym)
}

func _sqlite3OsDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxDlClose})))(tls, pVfs, pHandle)
}

func _sqlite3OsRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zBufOut uintptr) (r int32) {
	if _sqlite3Config.FiPrngSeed != 0 {
		libc.Xmemset(tls, zBufOut, 0, uint32(uint32(nByte)))
		if nByte > libc.Int32FromInt64(4) {
			nByte = int32(4)
		}
		libc.Xmemcpy(tls, zBufOut, uintptr(unsafe.Pointer(&_sqlite3Config))+276, uint32(uint32(nByte)))
		return SQLITE_OK
	} else {
		return (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxRandomness})))(tls, pVfs, nByte, zBufOut)
	}
	return r
}

func _sqlite3OsSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxSleep})))(tls, pVfs, nMicro)
}

func _sqlite3OsGetLastError(tls *libc.TLS, pVfs uintptr) (r int32) {
	var v1 int32
	_ = v1
	if (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxGetLastError != 0 {
		v1 = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxGetLastError})))(tls, pVfs, 0, uintptr(0))
	} else {
		v1 = 0
	}
	return v1
}

func _sqlite3OsCurrentTimeInt64(tls *libc.TLS, pVfs uintptr, pTimeOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* r at bp+0 */ float64
	_ = rc
	/* IMPLEMENTATION-OF: R-49045-42493 SQLite will use the xCurrentTimeInt64()
	 ** method to get the current date and time if that method is available
	 ** (if iVersion is 2 or greater and the function pointer is not NULL) and
	 ** will fall back to xCurrentTime() if xCurrentTimeInt64() is
	 ** unavailable.
	 */
	if (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FiVersion >= int32(2) && (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxCurrentTimeInt64 != 0 {
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxCurrentTimeInt64})))(tls, pVfs, pTimeOut)
	} else {
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxCurrentTime})))(tls, pVfs, bp)
		*(*Tsqlite3_int64)(unsafe.Pointer(pTimeOut)) = int64(*(*float64)(unsafe.Pointer(bp)) * libc.Float64FromFloat64(8.64e+07))
	}
	return rc
}

func _sqlite3OsOpenMalloc(tls *libc.TLS, pVfs uintptr, zFile uintptr, ppFile uintptr, flags int32, pOutFlags uintptr) (r int32) {
	var pFile uintptr
	var rc int32
	_, _ = pFile, rc
	pFile = _sqlite3MallocZero(tls, uint64((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile))
	if pFile != 0 {
		rc = _sqlite3OsOpen(tls, pVfs, zFile, pFile, flags, pOutFlags)
		if rc != SQLITE_OK {
			Xsqlite3_free(tls, pFile)
			*(*uintptr)(unsafe.Pointer(ppFile)) = uintptr(0)
		} else {
			*(*uintptr)(unsafe.Pointer(ppFile)) = pFile
		}
	} else {
		*(*uintptr)(unsafe.Pointer(ppFile)) = uintptr(0)
		rc = int32(SQLITE_NOMEM)
	}
	return rc
}

func _sqlite3OsCloseFree(tls *libc.TLS, pFile uintptr) {
	_sqlite3OsClose(tls, pFile)
	Xsqlite3_free(tls, pFile)
}

// C documentation
//
//	/*
//	** This function is a wrapper around the OS specific implementation of
//	** sqlite3_os_init(). The purpose of the wrapper is to provide the
//	** ability to simulate a malloc failure, so that the handling of an
//	** error in sqlite3_os_init() by the upper layers can be tested.
//	*/
func _sqlite3OsInit(tls *libc.TLS) (r int32) {
	var p uintptr
	_ = p
	p = Xsqlite3_malloc(tls, int32(10))
	if p == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	Xsqlite3_free(tls, p)
	return Xsqlite3_os_init(tls)
}

// C documentation
//
//	/*
//	** The list of all registered VFS implementations.
//	*/
var _vfsList = uintptr(0)

// C documentation
//
//	/*
//	** Locate a VFS by name.  If no name is given, simply return the
//	** first VFS on the list.
//	*/
func Xsqlite3_vfs_find(tls *libc.TLS, zVfs uintptr) (r uintptr) {
	var mutex, pVfs uintptr
	var rc int32
	_, _, _ = mutex, pVfs, rc
	pVfs = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return uintptr(0)
	}
	mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
	Xsqlite3_mutex_enter(tls, mutex)
	pVfs = _vfsList
	for {
		if !(pVfs != 0) {
			break
		}
		if zVfs == uintptr(0) {
			break
		}
		if libc.Xstrcmp(tls, zVfs, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FzName) == 0 {
			break
		}
		goto _1
	_1:
		;
		pVfs = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return pVfs
}

// C documentation
//
//	/*
//	** Unlink a VFS from the linked list
//	*/
func _vfsUnlink(tls *libc.TLS, pVfs uintptr) {
	var p uintptr
	_ = p
	if pVfs == uintptr(0) {
		/* No-op */
	} else {
		if _vfsList == pVfs {
			_vfsList = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext
		} else {
			if _vfsList != 0 {
				p = _vfsList
				for (*Tsqlite3_vfs)(unsafe.Pointer(p)).FpNext != 0 && (*Tsqlite3_vfs)(unsafe.Pointer(p)).FpNext != pVfs {
					p = (*Tsqlite3_vfs)(unsafe.Pointer(p)).FpNext
				}
				if (*Tsqlite3_vfs)(unsafe.Pointer(p)).FpNext == pVfs {
					(*Tsqlite3_vfs)(unsafe.Pointer(p)).FpNext = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Register a VFS with the system.  It is harmless to register the same
//	** VFS multiple times.  The new VFS becomes the default if makeDflt is
//	** true.
//	*/
func Xsqlite3_vfs_register(tls *libc.TLS, pVfs uintptr, makeDflt int32) (r int32) {
	var mutex uintptr
	var rc int32
	_, _ = mutex, rc
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
	Xsqlite3_mutex_enter(tls, mutex)
	_vfsUnlink(tls, pVfs)
	if makeDflt != 0 || _vfsList == uintptr(0) {
		(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext = _vfsList
		_vfsList = pVfs
	} else {
		(*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext = (*Tsqlite3_vfs)(unsafe.Pointer(_vfsList)).FpNext
		(*Tsqlite3_vfs)(unsafe.Pointer(_vfsList)).FpNext = pVfs
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Unregister a VFS so that it is no longer accessible.
//	*/
func Xsqlite3_vfs_unregister(tls *libc.TLS, pVfs uintptr) (r int32) {
	var mutex uintptr
	var rc int32
	_, _ = mutex, rc
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
	Xsqlite3_mutex_enter(tls, mutex)
	_vfsUnlink(tls, pVfs)
	Xsqlite3_mutex_leave(tls, mutex)
	return SQLITE_OK
}

/************** End of os.c **************************************************/
/************** Begin file fault.c *******************************************/
/*
** 2008 Jan 22
**
** 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 to support the concept of "benign"
** malloc failures (when the xMalloc() or xRealloc() method of the
** sqlite3_mem_methods structure fails to allocate a block of memory
** and returns 0).
**
** Most malloc failures are non-benign. After they occur, SQLite
** abandons the current operation and returns an error code (usually
** SQLITE_NOMEM) to the user. However, sometimes a fault is not necessarily
** fatal. For example, if a malloc fails while resizing a hash table, this
** is completely recoverable simply by not carrying out the resize. The
** hash table will continue to function normally.  So a malloc failure
** during a hash table resize is a benign fault.
 */

/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Global variables.
//	*/
type TBenignMallocHooks = struct {
	FxBenignBegin uintptr
	FxBenignEnd   uintptr
}

type BenignMallocHooks = TBenignMallocHooks

type TBenignMallocHooks1 = struct {
	FxBenignBegin uintptr
	FxBenignEnd   uintptr
}

type BenignMallocHooks1 = TBenignMallocHooks1

var _sqlite3Hooks = TBenignMallocHooks1{}

/* The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks
** structure.  If writable static data is unsupported on the target,
** we have to locate the state vector at run-time.  In the more common
** case where writable static data is supported, wsdHooks can refer directly
** to the "sqlite3Hooks" state vector declared above.
 */

// C documentation
//
//	/*
//	** Register hooks to call when sqlite3BeginBenignMalloc() and
//	** sqlite3EndBenignMalloc() are called, respectively.
//	*/
func _sqlite3BenignMallocHooks(tls *libc.TLS, xBenignBegin uintptr, xBenignEnd uintptr) {
	_sqlite3Hooks.FxBenignBegin = xBenignBegin
	_sqlite3Hooks.FxBenignEnd = xBenignEnd
}

// C documentation
//
//	/*
//	** This (sqlite3EndBenignMalloc()) is called by SQLite code to indicate that
//	** subsequent malloc failures are benign. A call to sqlite3EndBenignMalloc()
//	** indicates that subsequent malloc failures are non-benign.
//	*/
func _sqlite3BeginBenignMalloc(tls *libc.TLS) {
	if _sqlite3Hooks.FxBenignBegin != 0 {
		(*(*func(*libc.TLS))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Hooks.FxBenignBegin})))(tls)
	}
}

func _sqlite3EndBenignMalloc(tls *libc.TLS) {
	if _sqlite3Hooks.FxBenignEnd != 0 {
		(*(*func(*libc.TLS))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Hooks.FxBenignEnd})))(tls)
	}
}

/************** End of fault.c ***********************************************/
/************** Begin file mem0.c ********************************************/
/*
** 2008 October 28
**
** 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 a no-op memory allocation drivers for use when
** SQLITE_ZERO_MALLOC is defined.  The allocation drivers implemented
** here always fail.  SQLite will not operate with these drivers.  These
** are merely placeholders.  Real drivers must be substituted using
** sqlite3_config() before SQLite will operate.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is the default.  It is
** used when no other memory allocator is specified using compile-time
** macros.
 */

/************** End of mem0.c ************************************************/
/************** Begin file mem1.c ********************************************/
/*
** 2007 August 14
**
** 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 low-level memory allocation drivers for when
** SQLite will use the standard C-library malloc/realloc/free interface
** to obtain the memory it needs.
**
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.  The content of
** this file is only used if SQLITE_SYSTEM_MALLOC is defined.  The
** SQLITE_SYSTEM_MALLOC macro is defined automatically if neither the
** SQLITE_MEMDEBUG nor the SQLITE_WIN32_MALLOC macros are defined.  The
** default configuration is to use memory allocation routines in this
** file.
**
** C-preprocessor macro summary:
**
**    HAVE_MALLOC_USABLE_SIZE     The configure script sets this symbol if
**                                the malloc_usable_size() interface exists
**                                on the target platform.  Or, this symbol
**                                can be set manually, if desired.
**                                If an equivalent interface exists by
**                                a different name, using a separate -D
**                                option to rename it.
**
**    SQLITE_WITHOUT_ZONEMALLOC   Some older macs lack support for the zone
**                                memory allocator.  Set this symbol to enable
**                                building on older macs.
**
**    SQLITE_WITHOUT_MSIZE        Set this symbol to disable the use of
**                                _msize() on windows systems.  This might
**                                be necessary when compiling for Delphi,
**                                for example.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is the default.  It is
** used when no other memory allocator is specified using compile-time
** macros.
 */

/*
** Use standard C library malloc and free on non-Apple systems.
** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
 */

/*
** The malloc.h header file is needed for malloc_usable_size() function
** on some systems (e.g. Linux).
 */

/*
** Include the malloc.h header file, if necessary.  Also set define macro
** SQLITE_MALLOCSIZE to the appropriate function name, which is _msize()
** for MSVC and malloc_usable_size() for most other systems (e.g. Linux).
** The memory size function can always be overridden manually by defining
** the macro SQLITE_MALLOCSIZE to the desired function name.
 */

// C documentation
//
//	/*
//	** Like malloc(), but remember the size of the allocation
//	** so that we can find it later using sqlite3MemSize().
//	**
//	** For this low-level routine, we are guaranteed that nByte>0 because
//	** cases of nByte<=0 will be intercepted and dealt with by higher level
//	** routines.
//	*/
func _sqlite3MemMalloc(tls *libc.TLS, nByte int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	_ = p
	p = libc.Xmalloc(tls, uint32(nByte+int32(8)))
	if p != 0 {
		*(*Tsqlite3_int64)(unsafe.Pointer(p)) = int64(int64(nByte))
		p += 8
	} else {
		Xsqlite3_log(tls, int32(SQLITE_NOMEM), __ccgo_ts+1568, libc.VaList(bp+8, nByte))
	}
	return p
}

// C documentation
//
//	/*
//	** Like free() but works for allocations obtained from sqlite3MemMalloc()
//	** or sqlite3MemRealloc().
//	**
//	** For this low-level routine, we already know that pPrior!=0 since
//	** cases where pPrior==0 will have been intercepted and dealt with
//	** by higher-level routines.
//	*/
func _sqlite3MemFree(tls *libc.TLS, pPrior uintptr) {
	var p uintptr
	_ = p
	p = pPrior
	p -= 8
	libc.Xfree(tls, p)
}

// C documentation
//
//	/*
//	** Report the allocated size of a prior return from xMalloc()
//	** or xRealloc().
//	*/
func _sqlite3MemSize(tls *libc.TLS, pPrior uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pPrior
	p -= 8
	return int32(*(*Tsqlite3_int64)(unsafe.Pointer(p)))
}

// C documentation
//
//	/*
//	** Like realloc().  Resize an allocation previously obtained from
//	** sqlite3MemMalloc().
//	**
//	** For this low-level interface, we know that pPrior!=0.  Cases where
//	** pPrior==0 while have been intercepted by higher-level routine and
//	** redirected to xMalloc.  Similarly, we know that nByte>0 because
//	** cases where nByte<=0 will have been intercepted by higher-level
//	** routines and redirected to xFree.
//	*/
func _sqlite3MemRealloc(tls *libc.TLS, pPrior uintptr, nByte int32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p uintptr
	_ = p
	p = pPrior
	/* EV: R-46199-30249 */
	p -= 8
	p = libc.Xrealloc(tls, p, uint32(nByte+libc.Int32FromInt32(8)))
	if p != 0 {
		*(*Tsqlite3_int64)(unsafe.Pointer(p)) = int64(int64(nByte))
		p += 8
	} else {
		Xsqlite3_log(tls, int32(SQLITE_NOMEM), __ccgo_ts+1606, libc.VaList(bp+8, _sqlite3MemSize(tls, pPrior), nByte))
	}
	return p
}

// C documentation
//
//	/*
//	** Round up a request size to the next valid allocation size.
//	*/
func _sqlite3MemRoundup(tls *libc.TLS, n int32) (r int32) {
	return (n + int32(7)) & ^libc.Int32FromInt32(7)
}

// C documentation
//
//	/*
//	** Initialize this module.
//	*/
func _sqlite3MemInit(tls *libc.TLS, NotUsed uintptr) (r int32) {
	_ = NotUsed
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Deinitialize this module.
//	*/
func _sqlite3MemShutdown(tls *libc.TLS, NotUsed uintptr) {
	_ = NotUsed
	return
}

// C documentation
//
//	/*
//	** This routine is the only routine in this file with external linkage.
//	**
//	** Populate the low-level memory allocation function pointers in
//	** sqlite3GlobalConfig.m with pointers to the routines in this file.
//	*/
func _sqlite3MemSetDefault(tls *libc.TLS) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	Xsqlite3_config(tls, int32(SQLITE_CONFIG_MALLOC), libc.VaList(bp+8, uintptr(unsafe.Pointer(&_defaultMethods))))
}

var _defaultMethods = Tsqlite3_mem_methods{}

func init() {
	p := unsafe.Pointer(&_defaultMethods)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_sqlite3MemMalloc)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_sqlite3MemFree)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_sqlite3MemRealloc)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_sqlite3MemSize)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_sqlite3MemRoundup)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_sqlite3MemInit)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_sqlite3MemShutdown)
}

/************** End of mem1.c ************************************************/
/************** Begin file mem2.c ********************************************/
/*
** 2007 August 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 low-level memory allocation drivers for when
** SQLite will use the standard C-library malloc/realloc/free interface
** to obtain the memory it needs while adding lots of additional debugging
** information to each allocation in order to help detect and fix memory
** leaks and memory usage errors.
**
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is used only if the
** SQLITE_MEMDEBUG macro is defined
 */

/************** End of mem2.c ************************************************/
/************** Begin file mem3.c ********************************************/
/*
** 2007 October 14
**
** 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 C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** This version of the memory allocation subsystem omits all
** use of malloc(). The SQLite user supplies a block of memory
** before calling sqlite3_initialize() from which allocations
** are made and returned by the xMalloc() and xRealloc()
** implementations. Once sqlite3_initialize() has been called,
** the amount of memory available to SQLite is fixed and cannot
** be changed.
**
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is only built into the library
** SQLITE_ENABLE_MEMSYS3 is defined. Defining this symbol does not
** mean that the library will use a memory-pool by default, just that
** it is available. The mempool allocator is activated by calling
** sqlite3_config().
 */

/************** End of mem3.c ************************************************/
/************** Begin file mem5.c ********************************************/
/*
** 2007 October 14
**
** 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 C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** This version of the memory allocation subsystem omits all
** use of malloc(). The application gives SQLite a block of memory
** before calling sqlite3_initialize() from which allocations
** are made and returned by the xMalloc() and xRealloc()
** implementations. Once sqlite3_initialize() has been called,
** the amount of memory available to SQLite is fixed and cannot
** be changed.
**
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
**
** This memory allocator uses the following algorithm:
**
**   1.  All memory allocation sizes are rounded up to a power of 2.
**
**   2.  If two adjacent free blocks are the halves of a larger block,
**       then the two blocks are coalesced into the single larger block.
**
**   3.  New memory is allocated from the first available free block.
**
** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
** Concerning Dynamic Storage Allocation". Journal of the Association for
** Computing Machinery, Volume 21, Number 8, July 1974, pages 491-499.
**
** Let n be the size of the largest allocation divided by the minimum
** allocation size (after rounding all sizes up to a power of 2.)  Let M
** be the maximum amount of memory ever outstanding at one time.  Let
** N be the total amount of memory available for allocation.  Robson
** proved that this memory allocator will never breakdown due to
** fragmentation as long as the following constraint holds:
**
**      N >=  M*(1 + log2(n)/2) - n + 1
**
** The sqlite3_status() logic tracks the maximum values of n and M so
** that an application can, at any time, verify this constraint.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is used only when
** SQLITE_ENABLE_MEMSYS5 is defined.
 */

/************** End of mem5.c ************************************************/
/************** Begin file mutex.c *******************************************/
/*
** 2007 August 14
**
** 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 C functions that implement mutexes.
**
** This file contains code that is common across all mutex implementations.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Initialize the mutex system.
//	*/
func _sqlite3MutexInit(tls *libc.TLS) (r int32) {
	var pFrom, pTo uintptr
	var rc int32
	_, _, _ = pFrom, pTo, rc
	rc = SQLITE_OK
	if !(_sqlite3Config.Fmutex.FxMutexAlloc != 0) {
		pTo = uintptr(unsafe.Pointer(&_sqlite3Config)) + 64
		if _sqlite3Config.FbCoreMutex != 0 {
			pFrom = _sqlite3DefaultMutex(tls)
		} else {
			pFrom = _sqlite3NoopMutex(tls)
		}
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexInit = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexInit
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexEnd = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexEnd
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexFree = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexFree
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexEnter = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexEnter
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexTry = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexTry
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexLeave = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexLeave
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexHeld = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexHeld
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexNotheld = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexNotheld
		_sqlite3MemoryBarrier(tls)
		(*Tsqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexAlloc = (*Tsqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexAlloc
	}
	rc = (*(*func(*libc.TLS) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexInit})))(tls)
	_sqlite3MemoryBarrier(tls)
	return rc
}

// C documentation
//
//	/*
//	** Shutdown the mutex system. This call frees resources allocated by
//	** sqlite3MutexInit().
//	*/
func _sqlite3MutexEnd(tls *libc.TLS) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if _sqlite3Config.Fmutex.FxMutexEnd != 0 {
		rc = (*(*func(*libc.TLS) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexEnd})))(tls)
	}
	return rc
}

// C documentation
//
//	/*
//	** Retrieve a pointer to a static mutex or allocate a new dynamic one.
//	*/
func Xsqlite3_mutex_alloc(tls *libc.TLS, id int32) (r uintptr) {
	if id <= int32(SQLITE_MUTEX_RECURSIVE) && Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	if id > int32(SQLITE_MUTEX_RECURSIVE) && _sqlite3MutexInit(tls) != 0 {
		return uintptr(0)
	}
	return (*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexAlloc})))(tls, id)
}

func _sqlite3MutexAlloc(tls *libc.TLS, id int32) (r uintptr) {
	if !(_sqlite3Config.FbCoreMutex != 0) {
		return uintptr(0)
	}
	return (*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexAlloc})))(tls, id)
}

// C documentation
//
//	/*
//	** Free a dynamic mutex.
//	*/
func Xsqlite3_mutex_free(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexFree})))(tls, p)
	}
}

// C documentation
//
//	/*
//	** Obtain the mutex p. If some other thread already has the mutex, block
//	** until it can be obtained.
//	*/
func Xsqlite3_mutex_enter(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexEnter})))(tls, p)
	}
}

// C documentation
//
//	/*
//	** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another
//	** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
//	*/
func Xsqlite3_mutex_try(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if p != 0 {
		return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexTry})))(tls, p)
	}
	return rc
}

// C documentation
//
//	/*
//	** The sqlite3_mutex_leave() routine exits a mutex that was previously
//	** entered by the same thread.  The behavior is undefined if the mutex
//	** is not currently entered. If a NULL pointer is passed as an argument
//	** this function is a no-op.
//	*/
func Xsqlite3_mutex_leave(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fmutex.FxMutexLeave})))(tls, p)
	}
}

/************** End of mutex.c ***********************************************/
/************** Begin file mutex_noop.c **************************************/
/*
** 2008 October 07
**
** 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 C functions that implement mutexes.
**
** This implementation in this file does not provide any mutual
** exclusion and is thus suitable for use only in applications
** that use SQLite in a single thread.  The routines defined
** here are place-holders.  Applications can substitute working
** mutex routines at start-time using the
**
**     sqlite3_config(SQLITE_CONFIG_MUTEX,...)
**
** interface.
**
** If compiled with SQLITE_DEBUG, then additional logic is inserted
** that does error checking on mutexes to make sure they are being
** called correctly.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Stub routines for all mutex methods.
//	**
//	** This routines provide no mutual exclusion or error checking.
//	*/
func _noopMutexInit(tls *libc.TLS) (r int32) {
	return SQLITE_OK
}

func _noopMutexEnd(tls *libc.TLS) (r int32) {
	return SQLITE_OK
}

func _noopMutexAlloc(tls *libc.TLS, id int32) (r uintptr) {
	_ = id
	return libc.UintptrFromInt32(8)
}

func _noopMutexFree(tls *libc.TLS, p uintptr) {
	_ = p
	return
}

func _noopMutexEnter(tls *libc.TLS, p uintptr) {
	_ = p
	return
}

func _noopMutexTry(tls *libc.TLS, p uintptr) (r int32) {
	_ = p
	return SQLITE_OK
}

func _noopMutexLeave(tls *libc.TLS, p uintptr) {
	_ = p
	return
}

func _sqlite3NoopMutex(tls *libc.TLS) (r uintptr) {
	return uintptr(unsafe.Pointer(&_sMutex))
}

var _sMutex = Tsqlite3_mutex_methods{}

func init() {
	p := unsafe.Pointer(&_sMutex)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_noopMutexInit)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_noopMutexEnd)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_noopMutexAlloc)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_noopMutexFree)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_noopMutexEnter)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_noopMutexTry)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_noopMutexLeave)
}

type T_EXCEPTION_POINTERS = struct {
	FExceptionRecord TPEXCEPTION_RECORD
	FContextRecord   TPCONTEXT
}

type _EXCEPTION_POINTERS = T_EXCEPTION_POINTERS

type T_EXCEPTION_RECORD = struct {
	FExceptionCode        TDWORD
	FExceptionFlags       TDWORD
	FExceptionRecord      uintptr
	FExceptionAddress     TPVOID
	FNumberParameters     TDWORD
	FExceptionInformation [15]TULONG_PTR
}

type _EXCEPTION_RECORD = T_EXCEPTION_RECORD

type T_CONTEXT = struct {
	FContextFlags      TDWORD
	FDr0               TDWORD
	FDr1               TDWORD
	FDr2               TDWORD
	FDr3               TDWORD
	FDr6               TDWORD
	FDr7               TDWORD
	FFloatSave         TFLOATING_SAVE_AREA
	FSegGs             TDWORD
	FSegFs             TDWORD
	FSegEs             TDWORD
	FSegDs             TDWORD
	FEdi               TDWORD
	FEsi               TDWORD
	FEbx               TDWORD
	FEdx               TDWORD
	FEcx               TDWORD
	FEax               TDWORD
	FEbp               TDWORD
	FEip               TDWORD
	FSegCs             TDWORD
	FEFlags            TDWORD
	FEsp               TDWORD
	FSegSs             TDWORD
	FExtendedRegisters [512]TBYTE
}

type _CONTEXT = T_CONTEXT

type T_PHNDLR = uintptr

type _PHNDLR = T_PHNDLR

type T_XCPT_ACTION = struct {
	FXcptNum    uint32
	FSigNum     int32
	FXcptAction T_PHNDLR
}

type _XCPT_ACTION = T_XCPT_ACTION

type TPEXCEPTION_HANDLER = uintptr

type PEXCEPTION_HANDLER = TPEXCEPTION_HANDLER

type TULONG = uint32

type ULONG = TULONG

type TPULONG = uintptr

type PULONG = TPULONG

type TUSHORT = uint16

type USHORT = TUSHORT

type TPUSHORT = uintptr

type PUSHORT = TPUSHORT

type TUCHAR = uint8

type UCHAR = TUCHAR

type TPUCHAR = uintptr

type PUCHAR = TPUCHAR

type TPSZ = uintptr

type PSZ = TPSZ

type TWINBOOL = int32

type WINBOOL = TWINBOOL

type TBOOL = int32

type BOOL = TBOOL

type TPBOOL = uintptr

type PBOOL = TPBOOL

type TLPBOOL = uintptr

type LPBOOL = TLPBOOL

type TBYTE = uint8

type BYTE = TBYTE

type TWORD = uint16

type WORD = TWORD

type TDWORD = uint32

type DWORD = TDWORD

type TFLOAT = float32

type FLOAT = TFLOAT

type TPFLOAT = uintptr

type PFLOAT = TPFLOAT

type TPBYTE = uintptr

type PBYTE = TPBYTE

type TLPBYTE = uintptr

type LPBYTE = TLPBYTE

type TPINT = uintptr

type PINT = TPINT

type TLPINT = uintptr

type LPINT = TLPINT

type TPWORD = uintptr

type PWORD = TPWORD

type TLPWORD = uintptr

type LPWORD = TLPWORD

type TLPLONG = uintptr

type LPLONG = TLPLONG

type TPDWORD = uintptr

type PDWORD = TPDWORD

type TLPDWORD = uintptr

type LPDWORD = TLPDWORD

type TLPVOID = uintptr

type LPVOID = TLPVOID

type TLPCVOID = uintptr

type LPCVOID = TLPCVOID

type TINT = int32

type INT = TINT

type TUINT = uint32

type UINT = TUINT

type TPUINT = uintptr

type PUINT = TPUINT

type TPOINTER_64_INT = uint32

type POINTER_64_INT = TPOINTER_64_INT

type TINT8 = int8

type INT8 = TINT8

type TPINT8 = uintptr

type PINT8 = TPINT8

type TINT16 = int16

type INT16 = TINT16

type TPINT16 = uintptr

type PINT16 = TPINT16

type TINT32 = int32

type INT32 = TINT32

type TPINT32 = uintptr

type PINT32 = TPINT32

type TINT64 = int64

type INT64 = TINT64

type TPINT64 = uintptr

type PINT64 = TPINT64

type TUINT8 = uint8

type UINT8 = TUINT8

type TPUINT8 = uintptr

type PUINT8 = TPUINT8

type TUINT16 = uint16

type UINT16 = TUINT16

type TPUINT16 = uintptr

type PUINT16 = TPUINT16

type TUINT32 = uint32

type UINT32 = TUINT32

type TPUINT32 = uintptr

type PUINT32 = TPUINT32

type TUINT64 = uint64

type UINT64 = TUINT64

type TPUINT64 = uintptr

type PUINT64 = TPUINT64

type TLONG32 = int32

type LONG32 = TLONG32

type TPLONG32 = uintptr

type PLONG32 = TPLONG32

type TULONG32 = uint32

type ULONG32 = TULONG32

type TPULONG32 = uintptr

type PULONG32 = TPULONG32

type TDWORD32 = uint32

type DWORD32 = TDWORD32

type TPDWORD32 = uintptr

type PDWORD32 = TPDWORD32

type TINT_PTR = int32

type INT_PTR = TINT_PTR

type TPINT_PTR = uintptr

type PINT_PTR = TPINT_PTR

type TUINT_PTR = uint32

type UINT_PTR = TUINT_PTR

type TPUINT_PTR = uintptr

type PUINT_PTR = TPUINT_PTR

type TLONG_PTR = int32

type LONG_PTR = TLONG_PTR

type TPLONG_PTR = uintptr

type PLONG_PTR = TPLONG_PTR

type TULONG_PTR = uint32

type ULONG_PTR = TULONG_PTR

type TPULONG_PTR = uintptr

type PULONG_PTR = TPULONG_PTR

type TUHALF_PTR = uint16

type UHALF_PTR = TUHALF_PTR

type TPUHALF_PTR = uintptr

type PUHALF_PTR = TPUHALF_PTR

type THALF_PTR = int16

type HALF_PTR = THALF_PTR

type TPHALF_PTR = uintptr

type PHALF_PTR = TPHALF_PTR

type TSHANDLE_PTR = int32

type SHANDLE_PTR = TSHANDLE_PTR

type THANDLE_PTR = uint32

type HANDLE_PTR = THANDLE_PTR

type TSIZE_T = uint32

type SIZE_T = TSIZE_T

type TPSIZE_T = uintptr

type PSIZE_T = TPSIZE_T

type TSSIZE_T = int32

type SSIZE_T = TSSIZE_T

type TPSSIZE_T = uintptr

type PSSIZE_T = TPSSIZE_T

type TDWORD_PTR = uint32

type DWORD_PTR = TDWORD_PTR

type TPDWORD_PTR = uintptr

type PDWORD_PTR = TPDWORD_PTR

type TLONG64 = int64

type LONG64 = TLONG64

type TPLONG64 = uintptr

type PLONG64 = TPLONG64

type TULONG64 = uint64

type ULONG64 = TULONG64

type TPULONG64 = uintptr

type PULONG64 = TPULONG64

type TDWORD64 = uint64

type DWORD64 = TDWORD64

type TPDWORD64 = uintptr

type PDWORD64 = TPDWORD64

type TKAFFINITY = uint32

type KAFFINITY = TKAFFINITY

type TPKAFFINITY = uintptr

type PKAFFINITY = TPKAFFINITY

type TPVOID = uintptr

type PVOID = TPVOID

type TPVOID64 = uintptr

type PVOID64 = TPVOID64

type TCHAR = int8

type CHAR = TCHAR

type TSHORT = int16

type SHORT = TSHORT

type TLONG = int32

type LONG = TLONG

type TWCHAR = uint16

type WCHAR = TWCHAR

type TPWCHAR = uintptr

type PWCHAR = TPWCHAR

type TLPWCH = uintptr

type LPWCH = TLPWCH

type TPWCH = uintptr

type PWCH = TPWCH

type TLPCWCH = uintptr

type LPCWCH = TLPCWCH

type TPCWCH = uintptr

type PCWCH = TPCWCH

type TNWPSTR = uintptr

type NWPSTR = TNWPSTR

type TLPWSTR = uintptr

type LPWSTR = TLPWSTR

type TPWSTR = uintptr

type PWSTR = TPWSTR

type TPZPWSTR = uintptr

type PZPWSTR = TPZPWSTR

type TPCZPWSTR = uintptr

type PCZPWSTR = TPCZPWSTR

type TLPUWSTR = uintptr

type LPUWSTR = TLPUWSTR

type TPUWSTR = uintptr

type PUWSTR = TPUWSTR

type TLPCWSTR = uintptr

type LPCWSTR = TLPCWSTR

type TPCWSTR = uintptr

type PCWSTR = TPCWSTR

type TPZPCWSTR = uintptr

type PZPCWSTR = TPZPCWSTR

type TLPCUWSTR = uintptr

type LPCUWSTR = TLPCUWSTR

type TPCUWSTR = uintptr

type PCUWSTR = TPCUWSTR

type TPZZWSTR = uintptr

type PZZWSTR = TPZZWSTR

type TPCZZWSTR = uintptr

type PCZZWSTR = TPCZZWSTR

type TPUZZWSTR = uintptr

type PUZZWSTR = TPUZZWSTR

type TPCUZZWSTR = uintptr

type PCUZZWSTR = TPCUZZWSTR

type TPNZWCH = uintptr

type PNZWCH = TPNZWCH

type TPCNZWCH = uintptr

type PCNZWCH = TPCNZWCH

type TPUNZWCH = uintptr

type PUNZWCH = TPUNZWCH

type TPCUNZWCH = uintptr

type PCUNZWCH = TPCUNZWCH

type TLPCWCHAR = uintptr

type LPCWCHAR = TLPCWCHAR

type TPCWCHAR = uintptr

type PCWCHAR = TPCWCHAR

type TLPCUWCHAR = uintptr

type LPCUWCHAR = TLPCUWCHAR

type TPCUWCHAR = uintptr

type PCUWCHAR = TPCUWCHAR

type TUCSCHAR = uint32

type UCSCHAR = TUCSCHAR

type TPUCSCHAR = uintptr

type PUCSCHAR = TPUCSCHAR

type TPCUCSCHAR = uintptr

type PCUCSCHAR = TPCUCSCHAR

type TPUCSSTR = uintptr

type PUCSSTR = TPUCSSTR

type TPUUCSSTR = uintptr

type PUUCSSTR = TPUUCSSTR

type TPCUCSSTR = uintptr

type PCUCSSTR = TPCUCSSTR

type TPCUUCSSTR = uintptr

type PCUUCSSTR = TPCUUCSSTR

type TPUUCSCHAR = uintptr

type PUUCSCHAR = TPUUCSCHAR

type TPCUUCSCHAR = uintptr

type PCUUCSCHAR = TPCUUCSCHAR

type TPCHAR = uintptr

type PCHAR = TPCHAR

type TLPCH = uintptr

type LPCH = TLPCH

type TPCH = uintptr

type PCH = TPCH

type TLPCCH = uintptr

type LPCCH = TLPCCH

type TPCCH = uintptr

type PCCH = TPCCH

type TNPSTR = uintptr

type NPSTR = TNPSTR

type TLPSTR = uintptr

type LPSTR = TLPSTR

type TPSTR = uintptr

type PSTR = TPSTR

type TPZPSTR = uintptr

type PZPSTR = TPZPSTR

type TPCZPSTR = uintptr

type PCZPSTR = TPCZPSTR

type TLPCSTR = uintptr

type LPCSTR = TLPCSTR

type TPCSTR = uintptr

type PCSTR = TPCSTR

type TPZPCSTR = uintptr

type PZPCSTR = TPZPCSTR

type TPZZSTR = uintptr

type PZZSTR = TPZZSTR

type TPCZZSTR = uintptr

type PCZZSTR = TPCZZSTR

type TPNZCH = uintptr

type PNZCH = TPNZCH

type TPCNZCH = uintptr

type PCNZCH = TPCNZCH

type TTCHAR = int8

type TPTCHAR = uintptr

type PTCHAR = TPTCHAR

type TTBYTE = uint8

type TPTBYTE = uintptr

type PTBYTE = TPTBYTE

type TLPTCH = uintptr

type LPTCH = TLPTCH

type TPTCH = uintptr

type PTCH = TPTCH

type TLPCTCH = uintptr

type LPCTCH = TLPCTCH

type TPCTCH = uintptr

type PCTCH = TPCTCH

type TPTSTR = uintptr

type PTSTR = TPTSTR

type TLPTSTR = uintptr

type LPTSTR = TLPTSTR

type TPUTSTR = uintptr

type PUTSTR = TPUTSTR

type TLPUTSTR = uintptr

type LPUTSTR = TLPUTSTR

type TPCTSTR = uintptr

type PCTSTR = TPCTSTR

type TLPCTSTR = uintptr

type LPCTSTR = TLPCTSTR

type TPCUTSTR = uintptr

type PCUTSTR = TPCUTSTR

type TLPCUTSTR = uintptr

type LPCUTSTR = TLPCUTSTR

type TPZZTSTR = uintptr

type PZZTSTR = TPZZTSTR

type TPUZZTSTR = uintptr

type PUZZTSTR = TPUZZTSTR

type TPCZZTSTR = uintptr

type PCZZTSTR = TPCZZTSTR

type TPCUZZTSTR = uintptr

type PCUZZTSTR = TPCUZZTSTR

type TPZPTSTR = uintptr

type PZPTSTR = TPZPTSTR

type TPNZTCH = uintptr

type PNZTCH = TPNZTCH

type TPUNZTCH = uintptr

type PUNZTCH = TPUNZTCH

type TPCNZTCH = uintptr

type PCNZTCH = TPCNZTCH

type TPCUNZTCH = uintptr

type PCUNZTCH = TPCUNZTCH

type TPSHORT = uintptr

type PSHORT = TPSHORT

type TPLONG = uintptr

type PLONG = TPLONG

type TGROUP_AFFINITY = struct {
	FMask     TKAFFINITY
	FGroup    TWORD
	FReserved [3]TWORD
}

type GROUP_AFFINITY = TGROUP_AFFINITY

type T_GROUP_AFFINITY = TGROUP_AFFINITY

type _GROUP_AFFINITY = T_GROUP_AFFINITY

type TPGROUP_AFFINITY = uintptr

type PGROUP_AFFINITY = TPGROUP_AFFINITY

type THANDLE = uintptr

type HANDLE = THANDLE

type TPHANDLE = uintptr

type PHANDLE = TPHANDLE

type TFCHAR = uint8

type FCHAR = TFCHAR

type TFSHORT = uint16

type FSHORT = TFSHORT

type TFLONG = uint32

type FLONG = TFLONG

type THRESULT = int32

type HRESULT = THRESULT

type TCCHAR = int8

type CCHAR = TCCHAR

type TLCID = uint32

type LCID = TLCID

type TPLCID = uintptr

type PLCID = TPLCID

type TLANGID = uint16

type LANGID = TLANGID

type TCOMPARTMENT_ID = int32

type COMPARTMENT_ID = TCOMPARTMENT_ID

const _UNSPECIFIED_COMPARTMENT_ID = 0
const _DEFAULT_COMPARTMENT_ID = 1

type TPCOMPARTMENT_ID = uintptr

type PCOMPARTMENT_ID = TPCOMPARTMENT_ID

type TFLOAT128 = struct {
	F__ccgo_align [0]uint32
	FLowPart      int64
	FHighPart     int64
}

type FLOAT128 = TFLOAT128

type T_FLOAT128 = TFLOAT128

type _FLOAT128 = T_FLOAT128

type TPFLOAT128 = uintptr

type PFLOAT128 = TPFLOAT128

type TLONGLONG = int64

type LONGLONG = TLONGLONG

type TULONGLONG = uint64

type ULONGLONG = TULONGLONG

type TPLONGLONG = uintptr

type PLONGLONG = TPLONGLONG

type TPULONGLONG = uintptr

type PULONGLONG = TPULONGLONG

type TUSN = int64

type USN = TUSN

type TLARGE_INTEGER = struct {
	F__ccgo_align [0]uint32
	Fu            [0]struct {
		FLowPart  TDWORD
		FHighPart TLONG
	}
	FQuadPart  [0]TLONGLONG
	F__ccgo0_0 struct {
		FLowPart  TDWORD
		FHighPart TLONG
	}
}

type LARGE_INTEGER = TLARGE_INTEGER

type T_LARGE_INTEGER = TLARGE_INTEGER

type _LARGE_INTEGER = T_LARGE_INTEGER

type TPLARGE_INTEGER = uintptr

type PLARGE_INTEGER = TPLARGE_INTEGER

type TULARGE_INTEGER = struct {
	F__ccgo_align [0]uint32
	Fu            [0]struct {
		FLowPart  TDWORD
		FHighPart TDWORD
	}
	FQuadPart  [0]TULONGLONG
	F__ccgo0_0 struct {
		FLowPart  TDWORD
		FHighPart TDWORD
	}
}

type ULARGE_INTEGER = TULARGE_INTEGER

type T_ULARGE_INTEGER = TULARGE_INTEGER

type _ULARGE_INTEGER = T_ULARGE_INTEGER

type TPULARGE_INTEGER = uintptr

type PULARGE_INTEGER = TPULARGE_INTEGER

type TLUID = struct {
	FLowPart  TDWORD
	FHighPart TLONG
}

type LUID = TLUID

type T_LUID = TLUID

type _LUID = T_LUID

type TPLUID = uintptr

type PLUID = TPLUID

type TDWORDLONG = uint64

type DWORDLONG = TDWORDLONG

type TPDWORDLONG = uintptr

type PDWORDLONG = TPDWORDLONG

type TBOOLEAN = uint8

type BOOLEAN = TBOOLEAN

type TPBOOLEAN = uintptr

type PBOOLEAN = TPBOOLEAN

type TLIST_ENTRY = struct {
	FFlink uintptr
	FBlink uintptr
}

type LIST_ENTRY = TLIST_ENTRY

type T_LIST_ENTRY = TLIST_ENTRY

type _LIST_ENTRY = T_LIST_ENTRY

type TPLIST_ENTRY = uintptr

type PLIST_ENTRY = TPLIST_ENTRY

type TPRLIST_ENTRY = uintptr

type PRLIST_ENTRY = TPRLIST_ENTRY

type TSINGLE_LIST_ENTRY = struct {
	FNext uintptr
}

type SINGLE_LIST_ENTRY = TSINGLE_LIST_ENTRY

type T_SINGLE_LIST_ENTRY = TSINGLE_LIST_ENTRY

type _SINGLE_LIST_ENTRY = T_SINGLE_LIST_ENTRY

type TPSINGLE_LIST_ENTRY = uintptr

type PSINGLE_LIST_ENTRY = TPSINGLE_LIST_ENTRY

type TLIST_ENTRY32 = struct {
	FFlink TDWORD
	FBlink TDWORD
}

type LIST_ENTRY32 = TLIST_ENTRY32

type TPLIST_ENTRY32 = uintptr

type PLIST_ENTRY32 = TPLIST_ENTRY32

type TLIST_ENTRY64 = struct {
	F__ccgo_align [0]uint32
	FFlink        TULONGLONG
	FBlink        TULONGLONG
}

type LIST_ENTRY64 = TLIST_ENTRY64

type TPLIST_ENTRY64 = uintptr

type PLIST_ENTRY64 = TPLIST_ENTRY64

type TGUID = struct {
	FData1 uint32
	FData2 uint16
	FData3 uint16
	FData4 [8]uint8
}

type GUID = TGUID

type T_GUID = TGUID

type _GUID = T_GUID

type TLPGUID = uintptr

type LPGUID = TLPGUID

type TLPCGUID = uintptr

type LPCGUID = TLPCGUID

type TIID = struct {
	FData1 uint32
	FData2 uint16
	FData3 uint16
	FData4 [8]uint8
}

type IID = TIID

type TLPIID = uintptr

type LPIID = TLPIID

type TCLSID = struct {
	FData1 uint32
	FData2 uint16
	FData3 uint16
	FData4 [8]uint8
}

type CLSID = TCLSID

type TLPCLSID = uintptr

type LPCLSID = TLPCLSID

type TFMTID = struct {
	FData1 uint32
	FData2 uint16
	FData3 uint16
	FData4 [8]uint8
}

type FMTID = TFMTID

type TLPFMTID = uintptr

type LPFMTID = TLPFMTID

type TOBJECTID = struct {
	FLineage    TGUID
	FUniquifier TDWORD
}

type OBJECTID = TOBJECTID

type T_OBJECTID = TOBJECTID

type _OBJECTID = T_OBJECTID

type TPEXCEPTION_ROUTINE = uintptr

type PEXCEPTION_ROUTINE = TPEXCEPTION_ROUTINE

type TKSPIN_LOCK = uint32

type KSPIN_LOCK = TKSPIN_LOCK

type TPKSPIN_LOCK = uintptr

type PKSPIN_LOCK = TPKSPIN_LOCK

type TM128A = struct {
	F__ccgo_align [0]uint32
	FLow          TULONGLONG
	FHigh         TLONGLONG
}

type M128A = TM128A

type T_M128A = TM128A

type _M128A = T_M128A

type TPM128A = uintptr

type PM128A = TPM128A

type TXSAVE_FORMAT = struct {
	F__ccgo_align   [0]uint32
	FControlWord    TWORD
	FStatusWord     TWORD
	FTagWord        TBYTE
	FReserved1      TBYTE
	FErrorOpcode    TWORD
	FErrorOffset    TDWORD
	FErrorSelector  TWORD
	FReserved2      TWORD
	FDataOffset     TDWORD
	FDataSelector   TWORD
	FReserved3      TWORD
	FMxCsr          TDWORD
	FMxCsr_Mask     TDWORD
	FFloatRegisters [8]TM128A
	FXmmRegisters   [8]TM128A
	FReserved4      [220]TBYTE
	FCr0NpxState    TDWORD
}

type XSAVE_FORMAT = TXSAVE_FORMAT

type T_XSAVE_FORMAT = TXSAVE_FORMAT

type _XSAVE_FORMAT = T_XSAVE_FORMAT

type TPXSAVE_FORMAT = uintptr

type PXSAVE_FORMAT = TPXSAVE_FORMAT

type TXSAVE_AREA_HEADER = struct {
	F__ccgo_align [0]uint32
	FMask         TDWORD64
	FReserved     [7]TDWORD64
}

type XSAVE_AREA_HEADER = TXSAVE_AREA_HEADER

type T_XSAVE_AREA_HEADER = TXSAVE_AREA_HEADER

type _XSAVE_AREA_HEADER = T_XSAVE_AREA_HEADER

type TPXSAVE_AREA_HEADER = uintptr

type PXSAVE_AREA_HEADER = TPXSAVE_AREA_HEADER

type TXSAVE_AREA = struct {
	F__ccgo_align [0]uint32
	FLegacyState  TXSAVE_FORMAT
	FHeader       TXSAVE_AREA_HEADER
}

type XSAVE_AREA = TXSAVE_AREA

type T_XSAVE_AREA = TXSAVE_AREA

type _XSAVE_AREA = T_XSAVE_AREA

type TPXSAVE_AREA = uintptr

type PXSAVE_AREA = TPXSAVE_AREA

type TXSTATE_CONTEXT = struct {
	F__ccgo_align [0]uint32
	FMask         TDWORD64
	FLength       TDWORD
	FReserved1    TDWORD
	FArea         TPXSAVE_AREA
	FReserved2    TDWORD
	FBuffer       TPVOID
	FReserved3    TDWORD
}

type XSTATE_CONTEXT = TXSTATE_CONTEXT

type T_XSTATE_CONTEXT = TXSTATE_CONTEXT

type _XSTATE_CONTEXT = T_XSTATE_CONTEXT

type TPXSTATE_CONTEXT = uintptr

type PXSTATE_CONTEXT = TPXSTATE_CONTEXT

type TSCOPE_TABLE_AMD64 = struct {
	FCount       TDWORD
	FScopeRecord [1]struct {
		FBeginAddress   TDWORD
		FEndAddress     TDWORD
		FHandlerAddress TDWORD
		FJumpTarget     TDWORD
	}
}

type SCOPE_TABLE_AMD64 = TSCOPE_TABLE_AMD64

type T_SCOPE_TABLE_AMD64 = TSCOPE_TABLE_AMD64

type _SCOPE_TABLE_AMD64 = T_SCOPE_TABLE_AMD64

type TPSCOPE_TABLE_AMD64 = uintptr

type PSCOPE_TABLE_AMD64 = TPSCOPE_TABLE_AMD64

type TFLOATING_SAVE_AREA = struct {
	FControlWord   TDWORD
	FStatusWord    TDWORD
	FTagWord       TDWORD
	FErrorOffset   TDWORD
	FErrorSelector TDWORD
	FDataOffset    TDWORD
	FDataSelector  TDWORD
	FRegisterArea  [80]TBYTE
	FCr0NpxState   TDWORD
}

type FLOATING_SAVE_AREA = TFLOATING_SAVE_AREA

type T_FLOATING_SAVE_AREA = TFLOATING_SAVE_AREA

type _FLOATING_SAVE_AREA = T_FLOATING_SAVE_AREA

type TPFLOATING_SAVE_AREA = uintptr

type PFLOATING_SAVE_AREA = TPFLOATING_SAVE_AREA

type TCONTEXT = struct {
	FContextFlags      TDWORD
	FDr0               TDWORD
	FDr1               TDWORD
	FDr2               TDWORD
	FDr3               TDWORD
	FDr6               TDWORD
	FDr7               TDWORD
	FFloatSave         TFLOATING_SAVE_AREA
	FSegGs             TDWORD
	FSegFs             TDWORD
	FSegEs             TDWORD
	FSegDs             TDWORD
	FEdi               TDWORD
	FEsi               TDWORD
	FEbx               TDWORD
	FEdx               TDWORD
	FEcx               TDWORD
	FEax               TDWORD
	FEbp               TDWORD
	FEip               TDWORD
	FSegCs             TDWORD
	FEFlags            TDWORD
	FEsp               TDWORD
	FSegSs             TDWORD
	FExtendedRegisters [512]TBYTE
}

type CONTEXT = TCONTEXT

type TPCONTEXT = uintptr

type PCONTEXT = TPCONTEXT

type TLDT_ENTRY = struct {
	FLimitLow TWORD
	FBaseLow  TWORD
	FHighWord struct {
		FBits [0]struct {
			F__ccgo0 uint32
		}
		FBytes struct {
			FBaseMid TBYTE
			FFlags1  TBYTE
			FFlags2  TBYTE
			FBaseHi  TBYTE
		}
	}
}

type LDT_ENTRY = TLDT_ENTRY

type T_LDT_ENTRY = TLDT_ENTRY

type _LDT_ENTRY = T_LDT_ENTRY

type TPLDT_ENTRY = uintptr

type PLDT_ENTRY = TPLDT_ENTRY

type TEXCEPTION_RECORD = struct {
	FExceptionCode        TDWORD
	FExceptionFlags       TDWORD
	FExceptionRecord      uintptr
	FExceptionAddress     TPVOID
	FNumberParameters     TDWORD
	FExceptionInformation [15]TULONG_PTR
}

type EXCEPTION_RECORD = TEXCEPTION_RECORD

type TPEXCEPTION_RECORD = uintptr

type PEXCEPTION_RECORD = TPEXCEPTION_RECORD

type TEXCEPTION_RECORD32 = struct {
	FExceptionCode        TDWORD
	FExceptionFlags       TDWORD
	FExceptionRecord      TDWORD
	FExceptionAddress     TDWORD
	FNumberParameters     TDWORD
	FExceptionInformation [15]TDWORD
}

type EXCEPTION_RECORD32 = TEXCEPTION_RECORD32

type T_EXCEPTION_RECORD32 = TEXCEPTION_RECORD32

type _EXCEPTION_RECORD32 = T_EXCEPTION_RECORD32

type TPEXCEPTION_RECORD32 = uintptr

type PEXCEPTION_RECORD32 = TPEXCEPTION_RECORD32

type TEXCEPTION_RECORD64 = struct {
	F__ccgo_align         [0]uint32
	FExceptionCode        TDWORD
	FExceptionFlags       TDWORD
	FExceptionRecord      TDWORD64
	FExceptionAddress     TDWORD64
	FNumberParameters     TDWORD
	F__unusedAlignment    TDWORD
	FExceptionInformation [15]TDWORD64
}

type EXCEPTION_RECORD64 = TEXCEPTION_RECORD64

type T_EXCEPTION_RECORD64 = TEXCEPTION_RECORD64

type _EXCEPTION_RECORD64 = T_EXCEPTION_RECORD64

type TPEXCEPTION_RECORD64 = uintptr

type PEXCEPTION_RECORD64 = TPEXCEPTION_RECORD64

type TEXCEPTION_POINTERS = struct {
	FExceptionRecord TPEXCEPTION_RECORD
	FContextRecord   TPCONTEXT
}

type EXCEPTION_POINTERS = TEXCEPTION_POINTERS

type TPEXCEPTION_POINTERS = uintptr

type PEXCEPTION_POINTERS = TPEXCEPTION_POINTERS

type TPACCESS_TOKEN = uintptr

type PACCESS_TOKEN = TPACCESS_TOKEN

type TPSECURITY_DESCRIPTOR = uintptr

type PSECURITY_DESCRIPTOR = TPSECURITY_DESCRIPTOR

type TPSID = uintptr

type PSID = TPSID

type TPCLAIMS_BLOB = uintptr

type PCLAIMS_BLOB = TPCLAIMS_BLOB

type TACCESS_MASK = uint32

type ACCESS_MASK = TACCESS_MASK

type TPACCESS_MASK = uintptr

type PACCESS_MASK = TPACCESS_MASK

type TGENERIC_MAPPING = struct {
	FGenericRead    TACCESS_MASK
	FGenericWrite   TACCESS_MASK
	FGenericExecute TACCESS_MASK
	FGenericAll     TACCESS_MASK
}

type GENERIC_MAPPING = TGENERIC_MAPPING

type T_GENERIC_MAPPING = TGENERIC_MAPPING

type _GENERIC_MAPPING = T_GENERIC_MAPPING

type TPGENERIC_MAPPING = uintptr

type PGENERIC_MAPPING = TPGENERIC_MAPPING

type TLUID_AND_ATTRIBUTES = struct {
	FLuid       TLUID
	FAttributes TDWORD
}

type LUID_AND_ATTRIBUTES = TLUID_AND_ATTRIBUTES

type T_LUID_AND_ATTRIBUTES = TLUID_AND_ATTRIBUTES

type _LUID_AND_ATTRIBUTES = T_LUID_AND_ATTRIBUTES

type TPLUID_AND_ATTRIBUTES = uintptr

type PLUID_AND_ATTRIBUTES = TPLUID_AND_ATTRIBUTES

type TLUID_AND_ATTRIBUTES_ARRAY = [1]TLUID_AND_ATTRIBUTES

type LUID_AND_ATTRIBUTES_ARRAY = TLUID_AND_ATTRIBUTES_ARRAY

type TPLUID_AND_ATTRIBUTES_ARRAY = uintptr

type PLUID_AND_ATTRIBUTES_ARRAY = TPLUID_AND_ATTRIBUTES_ARRAY

type TSID_IDENTIFIER_AUTHORITY = struct {
	FValue [6]TBYTE
}

type SID_IDENTIFIER_AUTHORITY = TSID_IDENTIFIER_AUTHORITY

type T_SID_IDENTIFIER_AUTHORITY = TSID_IDENTIFIER_AUTHORITY

type _SID_IDENTIFIER_AUTHORITY = T_SID_IDENTIFIER_AUTHORITY

type TPSID_IDENTIFIER_AUTHORITY = uintptr

type PSID_IDENTIFIER_AUTHORITY = TPSID_IDENTIFIER_AUTHORITY

type TSID = struct {
	FRevision            TBYTE
	FSubAuthorityCount   TBYTE
	FIdentifierAuthority TSID_IDENTIFIER_AUTHORITY
	FSubAuthority        [1]TDWORD
}

type SID = TSID

type T_SID = TSID

type _SID = T_SID

type TPISID = uintptr

type PISID = TPISID

type TSID_NAME_USE = int32

type SID_NAME_USE = TSID_NAME_USE

type __SID_NAME_USE = int32

const _SidTypeUser = 1
const _SidTypeGroup = 2
const _SidTypeDomain = 3
const _SidTypeAlias = 4
const _SidTypeWellKnownGroup = 5
const _SidTypeDeletedAccount = 6
const _SidTypeInvalid = 7
const _SidTypeUnknown = 8
const _SidTypeComputer = 9
const _SidTypeLabel = 10
const _SidTypeLogonSession = 11

type TPSID_NAME_USE = uintptr

type PSID_NAME_USE = TPSID_NAME_USE

type TSID_AND_ATTRIBUTES = struct {
	FSid        TPSID
	FAttributes TDWORD
}

type SID_AND_ATTRIBUTES = TSID_AND_ATTRIBUTES

type T_SID_AND_ATTRIBUTES = TSID_AND_ATTRIBUTES

type _SID_AND_ATTRIBUTES = T_SID_AND_ATTRIBUTES

type TPSID_AND_ATTRIBUTES = uintptr

type PSID_AND_ATTRIBUTES = TPSID_AND_ATTRIBUTES

type TSID_AND_ATTRIBUTES_ARRAY = [1]TSID_AND_ATTRIBUTES

type SID_AND_ATTRIBUTES_ARRAY = TSID_AND_ATTRIBUTES_ARRAY

type TPSID_AND_ATTRIBUTES_ARRAY = uintptr

type PSID_AND_ATTRIBUTES_ARRAY = TPSID_AND_ATTRIBUTES_ARRAY

type TSID_HASH_ENTRY = uint32

type SID_HASH_ENTRY = TSID_HASH_ENTRY

type TPSID_HASH_ENTRY = uintptr

type PSID_HASH_ENTRY = TPSID_HASH_ENTRY

type TSID_AND_ATTRIBUTES_HASH = struct {
	FSidCount TDWORD
	FSidAttr  TPSID_AND_ATTRIBUTES
	FHash     [32]TSID_HASH_ENTRY
}

type SID_AND_ATTRIBUTES_HASH = TSID_AND_ATTRIBUTES_HASH

type T_SID_AND_ATTRIBUTES_HASH = TSID_AND_ATTRIBUTES_HASH

type _SID_AND_ATTRIBUTES_HASH = T_SID_AND_ATTRIBUTES_HASH

type TPSID_AND_ATTRIBUTES_HASH = uintptr

type PSID_AND_ATTRIBUTES_HASH = TPSID_AND_ATTRIBUTES_HASH

type TWELL_KNOWN_SID_TYPE = int32

type WELL_KNOWN_SID_TYPE = TWELL_KNOWN_SID_TYPE

const _WinNullSid = 0
const _WinWorldSid = 1
const _WinLocalSid = 2
const _WinCreatorOwnerSid = 3
const _WinCreatorGroupSid = 4
const _WinCreatorOwnerServerSid = 5
const _WinCreatorGroupServerSid = 6
const _WinNtAuthoritySid = 7
const _WinDialupSid = 8
const _WinNetworkSid = 9
const _WinBatchSid = 10
const _WinInteractiveSid = 11
const _WinServiceSid = 12
const _WinAnonymousSid = 13
const _WinProxySid = 14
const _WinEnterpriseControllersSid = 15
const _WinSelfSid = 16
const _WinAuthenticatedUserSid = 17
const _WinRestrictedCodeSid = 18
const _WinTerminalServerSid = 19
const _WinRemoteLogonIdSid = 20
const _WinLogonIdsSid = 21
const _WinLocalSystemSid = 22
const _WinLocalServiceSid = 23
const _WinNetworkServiceSid = 24
const _WinBuiltinDomainSid = 25
const _WinBuiltinAdministratorsSid = 26
const _WinBuiltinUsersSid = 27
const _WinBuiltinGuestsSid = 28
const _WinBuiltinPowerUsersSid = 29
const _WinBuiltinAccountOperatorsSid = 30
const _WinBuiltinSystemOperatorsSid = 31
const _WinBuiltinPrintOperatorsSid = 32
const _WinBuiltinBackupOperatorsSid = 33
const _WinBuiltinReplicatorSid = 34
const _WinBuiltinPreWindows2000CompatibleAccessSid = 35
const _WinBuiltinRemoteDesktopUsersSid = 36
const _WinBuiltinNetworkConfigurationOperatorsSid = 37
const _WinAccountAdministratorSid = 38
const _WinAccountGuestSid = 39
const _WinAccountKrbtgtSid = 40
const _WinAccountDomainAdminsSid = 41
const _WinAccountDomainUsersSid = 42
const _WinAccountDomainGuestsSid = 43
const _WinAccountComputersSid = 44
const _WinAccountControllersSid = 45
const _WinAccountCertAdminsSid = 46
const _WinAccountSchemaAdminsSid = 47
const _WinAccountEnterpriseAdminsSid = 48
const _WinAccountPolicyAdminsSid = 49
const _WinAccountRasAndIasServersSid = 50
const _WinNTLMAuthenticationSid = 51
const _WinDigestAuthenticationSid = 52
const _WinSChannelAuthenticationSid = 53
const _WinThisOrganizationSid = 54
const _WinOtherOrganizationSid = 55
const _WinBuiltinIncomingForestTrustBuildersSid = 56
const _WinBuiltinPerfMonitoringUsersSid = 57
const _WinBuiltinPerfLoggingUsersSid = 58
const _WinBuiltinAuthorizationAccessSid = 59
const _WinBuiltinTerminalServerLicenseServersSid = 60
const _WinBuiltinDCOMUsersSid = 61
const _WinBuiltinIUsersSid = 62
const _WinIUserSid = 63
const _WinBuiltinCryptoOperatorsSid = 64
const _WinUntrustedLabelSid = 65
const _WinLowLabelSid = 66
const _WinMediumLabelSid = 67
const _WinHighLabelSid = 68
const _WinSystemLabelSid = 69
const _WinWriteRestrictedCodeSid = 70
const _WinCreatorOwnerRightsSid = 71
const _WinCacheablePrincipalsGroupSid = 72
const _WinNonCacheablePrincipalsGroupSid = 73
const _WinEnterpriseReadonlyControllersSid = 74
const _WinAccountReadonlyControllersSid = 75
const _WinBuiltinEventLogReadersGroup = 76
const _WinNewEnterpriseReadonlyControllersSid = 77
const _WinBuiltinCertSvcDComAccessGroup = 78
const _WinMediumPlusLabelSid = 79
const _WinLocalLogonSid = 80
const _WinConsoleLogonSid = 81
const _WinThisOrganizationCertificateSid = 82
const _WinApplicationPackageAuthoritySid = 83
const _WinBuiltinAnyPackageSid = 84
const _WinCapabilityInternetClientSid = 85
const _WinCapabilityInternetClientServerSid = 86
const _WinCapabilityPrivateNetworkClientServerSid = 87
const _WinCapabilityPicturesLibrarySid = 88
const _WinCapabilityVideosLibrarySid = 89
const _WinCapabilityMusicLibrarySid = 90
const _WinCapabilityDocumentsLibrarySid = 91
const _WinCapabilitySharedUserCertificatesSid = 92
const _WinCapabilityEnterpriseAuthenticationSid = 93
const _WinCapabilityRemovableStorageSid = 94
const _WinBuiltinRDSRemoteAccessServersSid = 95
const _WinBuiltinRDSEndpointServersSid = 96
const _WinBuiltinRDSManagementServersSid = 97
const _WinUserModeDriversSid = 98
const _WinBuiltinHyperVAdminsSid = 99
const _WinAccountCloneableControllersSid = 100
const _WinBuiltinAccessControlAssistanceOperatorsSid = 101
const _WinBuiltinRemoteManagementUsersSid = 102
const _WinAuthenticationAuthorityAssertedSid = 103
const _WinAuthenticationServiceAssertedSid = 104
const _WinLocalAccountSid = 105
const _WinLocalAccountAndAdministratorSid = 106
const _WinAccountProtectedUsersSid = 107
const _WinCapabilityAppointmentsSid = 108
const _WinCapabilityContactsSid = 109
const _WinAccountDefaultSystemManagedSid = 110
const _WinBuiltinDefaultSystemManagedGroupSid = 111
const _WinBuiltinStorageReplicaAdminsSid = 112
const _WinAccountKeyAdminsSid = 113
const _WinAccountEnterpriseKeyAdminsSid = 114
const _WinAuthenticationKeyTrustSid = 115
const _WinAuthenticationKeyPropertyMFASid = 116
const _WinAuthenticationKeyPropertyAttestationSid = 117

type TACL = struct {
	FAclRevision TBYTE
	FSbz1        TBYTE
	FAclSize     TWORD
	FAceCount    TWORD
	FSbz2        TWORD
}

type ACL = TACL

type T_ACL = TACL

type _ACL = T_ACL

type TPACL = uintptr

type PACL = TPACL

type TACE_HEADER = struct {
	FAceType  TBYTE
	FAceFlags TBYTE
	FAceSize  TWORD
}

type ACE_HEADER = TACE_HEADER

type T_ACE_HEADER = TACE_HEADER

type _ACE_HEADER = T_ACE_HEADER

type TPACE_HEADER = uintptr

type PACE_HEADER = TPACE_HEADER

type TACCESS_ALLOWED_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type ACCESS_ALLOWED_ACE = TACCESS_ALLOWED_ACE

type T_ACCESS_ALLOWED_ACE = TACCESS_ALLOWED_ACE

type _ACCESS_ALLOWED_ACE = T_ACCESS_ALLOWED_ACE

type TPACCESS_ALLOWED_ACE = uintptr

type PACCESS_ALLOWED_ACE = TPACCESS_ALLOWED_ACE

type TACCESS_DENIED_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type ACCESS_DENIED_ACE = TACCESS_DENIED_ACE

type T_ACCESS_DENIED_ACE = TACCESS_DENIED_ACE

type _ACCESS_DENIED_ACE = T_ACCESS_DENIED_ACE

type TPACCESS_DENIED_ACE = uintptr

type PACCESS_DENIED_ACE = TPACCESS_DENIED_ACE

type TSYSTEM_AUDIT_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type SYSTEM_AUDIT_ACE = TSYSTEM_AUDIT_ACE

type T_SYSTEM_AUDIT_ACE = TSYSTEM_AUDIT_ACE

type _SYSTEM_AUDIT_ACE = T_SYSTEM_AUDIT_ACE

type TPSYSTEM_AUDIT_ACE = uintptr

type PSYSTEM_AUDIT_ACE = TPSYSTEM_AUDIT_ACE

type TSYSTEM_ALARM_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type SYSTEM_ALARM_ACE = TSYSTEM_ALARM_ACE

type T_SYSTEM_ALARM_ACE = TSYSTEM_ALARM_ACE

type _SYSTEM_ALARM_ACE = T_SYSTEM_ALARM_ACE

type TPSYSTEM_ALARM_ACE = uintptr

type PSYSTEM_ALARM_ACE = TPSYSTEM_ALARM_ACE

type TSYSTEM_RESOURCE_ATTRIBUTE_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type SYSTEM_RESOURCE_ATTRIBUTE_ACE = TSYSTEM_RESOURCE_ATTRIBUTE_ACE

type T_SYSTEM_RESOURCE_ATTRIBUTE_ACE = TSYSTEM_RESOURCE_ATTRIBUTE_ACE

type _SYSTEM_RESOURCE_ATTRIBUTE_ACE = T_SYSTEM_RESOURCE_ATTRIBUTE_ACE

type TPSYSTEM_RESOURCE_ATTRIBUTE_ACE = uintptr

type PSYSTEM_RESOURCE_ATTRIBUTE_ACE = TPSYSTEM_RESOURCE_ATTRIBUTE_ACE

type TSYSTEM_SCOPED_POLICY_ID_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type SYSTEM_SCOPED_POLICY_ID_ACE = TSYSTEM_SCOPED_POLICY_ID_ACE

type T_SYSTEM_SCOPED_POLICY_ID_ACE = TSYSTEM_SCOPED_POLICY_ID_ACE

type _SYSTEM_SCOPED_POLICY_ID_ACE = T_SYSTEM_SCOPED_POLICY_ID_ACE

type TPSYSTEM_SCOPED_POLICY_ID_ACE = uintptr

type PSYSTEM_SCOPED_POLICY_ID_ACE = TPSYSTEM_SCOPED_POLICY_ID_ACE

type TSYSTEM_MANDATORY_LABEL_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type SYSTEM_MANDATORY_LABEL_ACE = TSYSTEM_MANDATORY_LABEL_ACE

type T_SYSTEM_MANDATORY_LABEL_ACE = TSYSTEM_MANDATORY_LABEL_ACE

type _SYSTEM_MANDATORY_LABEL_ACE = T_SYSTEM_MANDATORY_LABEL_ACE

type TPSYSTEM_MANDATORY_LABEL_ACE = uintptr

type PSYSTEM_MANDATORY_LABEL_ACE = TPSYSTEM_MANDATORY_LABEL_ACE

type TACCESS_ALLOWED_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type ACCESS_ALLOWED_OBJECT_ACE = TACCESS_ALLOWED_OBJECT_ACE

type T_ACCESS_ALLOWED_OBJECT_ACE = TACCESS_ALLOWED_OBJECT_ACE

type _ACCESS_ALLOWED_OBJECT_ACE = T_ACCESS_ALLOWED_OBJECT_ACE

type TPACCESS_ALLOWED_OBJECT_ACE = uintptr

type PACCESS_ALLOWED_OBJECT_ACE = TPACCESS_ALLOWED_OBJECT_ACE

type TACCESS_DENIED_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type ACCESS_DENIED_OBJECT_ACE = TACCESS_DENIED_OBJECT_ACE

type T_ACCESS_DENIED_OBJECT_ACE = TACCESS_DENIED_OBJECT_ACE

type _ACCESS_DENIED_OBJECT_ACE = T_ACCESS_DENIED_OBJECT_ACE

type TPACCESS_DENIED_OBJECT_ACE = uintptr

type PACCESS_DENIED_OBJECT_ACE = TPACCESS_DENIED_OBJECT_ACE

type TSYSTEM_AUDIT_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type SYSTEM_AUDIT_OBJECT_ACE = TSYSTEM_AUDIT_OBJECT_ACE

type T_SYSTEM_AUDIT_OBJECT_ACE = TSYSTEM_AUDIT_OBJECT_ACE

type _SYSTEM_AUDIT_OBJECT_ACE = T_SYSTEM_AUDIT_OBJECT_ACE

type TPSYSTEM_AUDIT_OBJECT_ACE = uintptr

type PSYSTEM_AUDIT_OBJECT_ACE = TPSYSTEM_AUDIT_OBJECT_ACE

type TSYSTEM_ALARM_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type SYSTEM_ALARM_OBJECT_ACE = TSYSTEM_ALARM_OBJECT_ACE

type T_SYSTEM_ALARM_OBJECT_ACE = TSYSTEM_ALARM_OBJECT_ACE

type _SYSTEM_ALARM_OBJECT_ACE = T_SYSTEM_ALARM_OBJECT_ACE

type TPSYSTEM_ALARM_OBJECT_ACE = uintptr

type PSYSTEM_ALARM_OBJECT_ACE = TPSYSTEM_ALARM_OBJECT_ACE

type TACCESS_ALLOWED_CALLBACK_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type ACCESS_ALLOWED_CALLBACK_ACE = TACCESS_ALLOWED_CALLBACK_ACE

type T_ACCESS_ALLOWED_CALLBACK_ACE = TACCESS_ALLOWED_CALLBACK_ACE

type _ACCESS_ALLOWED_CALLBACK_ACE = T_ACCESS_ALLOWED_CALLBACK_ACE

type TPACCESS_ALLOWED_CALLBACK_ACE = uintptr

type PACCESS_ALLOWED_CALLBACK_ACE = TPACCESS_ALLOWED_CALLBACK_ACE

type TACCESS_DENIED_CALLBACK_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type ACCESS_DENIED_CALLBACK_ACE = TACCESS_DENIED_CALLBACK_ACE

type T_ACCESS_DENIED_CALLBACK_ACE = TACCESS_DENIED_CALLBACK_ACE

type _ACCESS_DENIED_CALLBACK_ACE = T_ACCESS_DENIED_CALLBACK_ACE

type TPACCESS_DENIED_CALLBACK_ACE = uintptr

type PACCESS_DENIED_CALLBACK_ACE = TPACCESS_DENIED_CALLBACK_ACE

type TSYSTEM_AUDIT_CALLBACK_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type SYSTEM_AUDIT_CALLBACK_ACE = TSYSTEM_AUDIT_CALLBACK_ACE

type T_SYSTEM_AUDIT_CALLBACK_ACE = TSYSTEM_AUDIT_CALLBACK_ACE

type _SYSTEM_AUDIT_CALLBACK_ACE = T_SYSTEM_AUDIT_CALLBACK_ACE

type TPSYSTEM_AUDIT_CALLBACK_ACE = uintptr

type PSYSTEM_AUDIT_CALLBACK_ACE = TPSYSTEM_AUDIT_CALLBACK_ACE

type TSYSTEM_ALARM_CALLBACK_ACE = struct {
	FHeader   TACE_HEADER
	FMask     TACCESS_MASK
	FSidStart TDWORD
}

type SYSTEM_ALARM_CALLBACK_ACE = TSYSTEM_ALARM_CALLBACK_ACE

type T_SYSTEM_ALARM_CALLBACK_ACE = TSYSTEM_ALARM_CALLBACK_ACE

type _SYSTEM_ALARM_CALLBACK_ACE = T_SYSTEM_ALARM_CALLBACK_ACE

type TPSYSTEM_ALARM_CALLBACK_ACE = uintptr

type PSYSTEM_ALARM_CALLBACK_ACE = TPSYSTEM_ALARM_CALLBACK_ACE

type TACCESS_ALLOWED_CALLBACK_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type ACCESS_ALLOWED_CALLBACK_OBJECT_ACE = TACCESS_ALLOWED_CALLBACK_OBJECT_ACE

type T_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE = TACCESS_ALLOWED_CALLBACK_OBJECT_ACE

type _ACCESS_ALLOWED_CALLBACK_OBJECT_ACE = T_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE

type TPACCESS_ALLOWED_CALLBACK_OBJECT_ACE = uintptr

type PACCESS_ALLOWED_CALLBACK_OBJECT_ACE = TPACCESS_ALLOWED_CALLBACK_OBJECT_ACE

type TACCESS_DENIED_CALLBACK_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type ACCESS_DENIED_CALLBACK_OBJECT_ACE = TACCESS_DENIED_CALLBACK_OBJECT_ACE

type T_ACCESS_DENIED_CALLBACK_OBJECT_ACE = TACCESS_DENIED_CALLBACK_OBJECT_ACE

type _ACCESS_DENIED_CALLBACK_OBJECT_ACE = T_ACCESS_DENIED_CALLBACK_OBJECT_ACE

type TPACCESS_DENIED_CALLBACK_OBJECT_ACE = uintptr

type PACCESS_DENIED_CALLBACK_OBJECT_ACE = TPACCESS_DENIED_CALLBACK_OBJECT_ACE

type TSYSTEM_AUDIT_CALLBACK_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type SYSTEM_AUDIT_CALLBACK_OBJECT_ACE = TSYSTEM_AUDIT_CALLBACK_OBJECT_ACE

type T_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE = TSYSTEM_AUDIT_CALLBACK_OBJECT_ACE

type _SYSTEM_AUDIT_CALLBACK_OBJECT_ACE = T_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE

type TPSYSTEM_AUDIT_CALLBACK_OBJECT_ACE = uintptr

type PSYSTEM_AUDIT_CALLBACK_OBJECT_ACE = TPSYSTEM_AUDIT_CALLBACK_OBJECT_ACE

type TSYSTEM_ALARM_CALLBACK_OBJECT_ACE = struct {
	FHeader              TACE_HEADER
	FMask                TACCESS_MASK
	FFlags               TDWORD
	FObjectType          TGUID
	FInheritedObjectType TGUID
	FSidStart            TDWORD
}

type SYSTEM_ALARM_CALLBACK_OBJECT_ACE = TSYSTEM_ALARM_CALLBACK_OBJECT_ACE

type T_SYSTEM_ALARM_CALLBACK_OBJECT_ACE = TSYSTEM_ALARM_CALLBACK_OBJECT_ACE

type _SYSTEM_ALARM_CALLBACK_OBJECT_ACE = T_SYSTEM_ALARM_CALLBACK_OBJECT_ACE

type TPSYSTEM_ALARM_CALLBACK_OBJECT_ACE = uintptr

type PSYSTEM_ALARM_CALLBACK_OBJECT_ACE = TPSYSTEM_ALARM_CALLBACK_OBJECT_ACE

type TACL_INFORMATION_CLASS = int32

type ACL_INFORMATION_CLASS = TACL_INFORMATION_CLASS

type __ACL_INFORMATION_CLASS = int32

const _AclRevisionInformation = 1
const _AclSizeInformation = 2

type TACL_REVISION_INFORMATION = struct {
	FAclRevision TDWORD
}

type ACL_REVISION_INFORMATION = TACL_REVISION_INFORMATION

type T_ACL_REVISION_INFORMATION = TACL_REVISION_INFORMATION

type _ACL_REVISION_INFORMATION = T_ACL_REVISION_INFORMATION

type TPACL_REVISION_INFORMATION = uintptr

type PACL_REVISION_INFORMATION = TPACL_REVISION_INFORMATION

type TACL_SIZE_INFORMATION = struct {
	FAceCount      TDWORD
	FAclBytesInUse TDWORD
	FAclBytesFree  TDWORD
}

type ACL_SIZE_INFORMATION = TACL_SIZE_INFORMATION

type T_ACL_SIZE_INFORMATION = TACL_SIZE_INFORMATION

type _ACL_SIZE_INFORMATION = T_ACL_SIZE_INFORMATION

type TPACL_SIZE_INFORMATION = uintptr

type PACL_SIZE_INFORMATION = TPACL_SIZE_INFORMATION

type TSECURITY_DESCRIPTOR_CONTROL = uint16

type SECURITY_DESCRIPTOR_CONTROL = TSECURITY_DESCRIPTOR_CONTROL

type TPSECURITY_DESCRIPTOR_CONTROL = uintptr

type PSECURITY_DESCRIPTOR_CONTROL = TPSECURITY_DESCRIPTOR_CONTROL

type TSECURITY_DESCRIPTOR_RELATIVE = struct {
	FRevision TBYTE
	FSbz1     TBYTE
	FControl  TSECURITY_DESCRIPTOR_CONTROL
	FOwner    TDWORD
	FGroup    TDWORD
	FSacl     TDWORD
	FDacl     TDWORD
}

type SECURITY_DESCRIPTOR_RELATIVE = TSECURITY_DESCRIPTOR_RELATIVE

type T_SECURITY_DESCRIPTOR_RELATIVE = TSECURITY_DESCRIPTOR_RELATIVE

type _SECURITY_DESCRIPTOR_RELATIVE = T_SECURITY_DESCRIPTOR_RELATIVE

type TPISECURITY_DESCRIPTOR_RELATIVE = uintptr

type PISECURITY_DESCRIPTOR_RELATIVE = TPISECURITY_DESCRIPTOR_RELATIVE

type TSECURITY_DESCRIPTOR = struct {
	FRevision TBYTE
	FSbz1     TBYTE
	FControl  TSECURITY_DESCRIPTOR_CONTROL
	FOwner    TPSID
	FGroup    TPSID
	FSacl     TPACL
	FDacl     TPACL
}

type SECURITY_DESCRIPTOR = TSECURITY_DESCRIPTOR

type T_SECURITY_DESCRIPTOR = TSECURITY_DESCRIPTOR

type _SECURITY_DESCRIPTOR = T_SECURITY_DESCRIPTOR

type TPISECURITY_DESCRIPTOR = uintptr

type PISECURITY_DESCRIPTOR = TPISECURITY_DESCRIPTOR

type TOBJECT_TYPE_LIST = struct {
	FLevel      TWORD
	FSbz        TWORD
	FObjectType uintptr
}

type OBJECT_TYPE_LIST = TOBJECT_TYPE_LIST

type T_OBJECT_TYPE_LIST = TOBJECT_TYPE_LIST

type _OBJECT_TYPE_LIST = T_OBJECT_TYPE_LIST

type TPOBJECT_TYPE_LIST = uintptr

type POBJECT_TYPE_LIST = TPOBJECT_TYPE_LIST

type TAUDIT_EVENT_TYPE = int32

type AUDIT_EVENT_TYPE = TAUDIT_EVENT_TYPE

type __AUDIT_EVENT_TYPE = int32

const _AuditEventObjectAccess = 0
const _AuditEventDirectoryServiceAccess = 1

type TPAUDIT_EVENT_TYPE = uintptr

type PAUDIT_EVENT_TYPE = TPAUDIT_EVENT_TYPE

type TPRIVILEGE_SET = struct {
	FPrivilegeCount TDWORD
	FControl        TDWORD
	FPrivilege      [1]TLUID_AND_ATTRIBUTES
}

type PRIVILEGE_SET = TPRIVILEGE_SET

type T_PRIVILEGE_SET = TPRIVILEGE_SET

type _PRIVILEGE_SET = T_PRIVILEGE_SET

type TPPRIVILEGE_SET = uintptr

type PPRIVILEGE_SET = TPPRIVILEGE_SET

type TACCESS_REASON_TYPE = int32

type ACCESS_REASON_TYPE = TACCESS_REASON_TYPE

type __ACCESS_REASON_TYPE = int32

const _AccessReasonNone = 0
const _AccessReasonAllowedAce = 65536
const _AccessReasonDeniedAce = 131072
const _AccessReasonAllowedParentAce = 196608
const _AccessReasonDeniedParentAce = 262144
const _AccessReasonNotGrantedByCape = 327680
const _AccessReasonNotGrantedByParentCape = 393216
const _AccessReasonNotGrantedToAppContainer = 458752
const _AccessReasonMissingPrivilege = 1048576
const _AccessReasonFromPrivilege = 2097152
const _AccessReasonIntegrityLevel = 3145728
const _AccessReasonOwnership = 4194304
const _AccessReasonNullDacl = 5242880
const _AccessReasonEmptyDacl = 6291456
const _AccessReasonNoSD = 7340032
const _AccessReasonNoGrant = 8388608

type TACCESS_REASON = uint32

type ACCESS_REASON = TACCESS_REASON

type TACCESS_REASONS = struct {
	FData [32]TACCESS_REASON
}

type ACCESS_REASONS = TACCESS_REASONS

type T_ACCESS_REASONS = TACCESS_REASONS

type _ACCESS_REASONS = T_ACCESS_REASONS

type TPACCESS_REASONS = uintptr

type PACCESS_REASONS = TPACCESS_REASONS

type TSE_SECURITY_DESCRIPTOR = struct {
	FSize               TDWORD
	FFlags              TDWORD
	FSecurityDescriptor TPSECURITY_DESCRIPTOR
}

type SE_SECURITY_DESCRIPTOR = TSE_SECURITY_DESCRIPTOR

type T_SE_SECURITY_DESCRIPTOR = TSE_SECURITY_DESCRIPTOR

type _SE_SECURITY_DESCRIPTOR = T_SE_SECURITY_DESCRIPTOR

type TPSE_SECURITY_DESCRIPTOR = uintptr

type PSE_SECURITY_DESCRIPTOR = TPSE_SECURITY_DESCRIPTOR

type TSE_ACCESS_REQUEST = struct {
	FSize                    TDWORD
	FSeSecurityDescriptor    TPSE_SECURITY_DESCRIPTOR
	FDesiredAccess           TACCESS_MASK
	FPreviouslyGrantedAccess TACCESS_MASK
	FPrincipalSelfSid        TPSID
	FGenericMapping          TPGENERIC_MAPPING
	FObjectTypeListCount     TDWORD
	FObjectTypeList          TPOBJECT_TYPE_LIST
}

type SE_ACCESS_REQUEST = TSE_ACCESS_REQUEST

type T_SE_ACCESS_REQUEST = TSE_ACCESS_REQUEST

type _SE_ACCESS_REQUEST = T_SE_ACCESS_REQUEST

type TPSE_ACCESS_REQUEST = uintptr

type PSE_ACCESS_REQUEST = TPSE_ACCESS_REQUEST

type TSE_ACCESS_REPLY = struct {
	FSize            TDWORD
	FResultListCount TDWORD
	FGrantedAccess   TPACCESS_MASK
	FAccessStatus    TPDWORD
	FAccessReason    TPACCESS_REASONS
	FPrivileges      uintptr
}

type SE_ACCESS_REPLY = TSE_ACCESS_REPLY

type T_SE_ACCESS_REPLY = TSE_ACCESS_REPLY

type _SE_ACCESS_REPLY = T_SE_ACCESS_REPLY

type TPSE_ACCESS_REPLY = uintptr

type PSE_ACCESS_REPLY = TPSE_ACCESS_REPLY

type TSECURITY_IMPERSONATION_LEVEL = int32

type SECURITY_IMPERSONATION_LEVEL = TSECURITY_IMPERSONATION_LEVEL

type __SECURITY_IMPERSONATION_LEVEL = int32

const _SecurityAnonymous = 0
const _SecurityIdentification = 1
const _SecurityImpersonation = 2
const _SecurityDelegation = 3

type TPSECURITY_IMPERSONATION_LEVEL = uintptr

type PSECURITY_IMPERSONATION_LEVEL = TPSECURITY_IMPERSONATION_LEVEL

type TTOKEN_TYPE = int32

type TOKEN_TYPE = TTOKEN_TYPE

type __TOKEN_TYPE = int32

const _TokenPrimary = 1
const _TokenImpersonation = 2

type TPTOKEN_TYPE = uintptr

type PTOKEN_TYPE = TPTOKEN_TYPE

type TTOKEN_ELEVATION_TYPE = int32

type TOKEN_ELEVATION_TYPE = TTOKEN_ELEVATION_TYPE

type __TOKEN_ELEVATION_TYPE = int32

const _TokenElevationTypeDefault = 1
const _TokenElevationTypeFull = 2
const _TokenElevationTypeLimited = 3

type TPTOKEN_ELEVATION_TYPE = uintptr

type PTOKEN_ELEVATION_TYPE = TPTOKEN_ELEVATION_TYPE

type TTOKEN_INFORMATION_CLASS = int32

type TOKEN_INFORMATION_CLASS = TTOKEN_INFORMATION_CLASS

type __TOKEN_INFORMATION_CLASS = int32

const _TokenUser = 1
const _TokenGroups = 2
const _TokenPrivileges = 3
const _TokenOwner = 4
const _TokenPrimaryGroup = 5
const _TokenDefaultDacl = 6
const _TokenSource = 7
const _TokenType = 8
const _TokenImpersonationLevel = 9
const _TokenStatistics = 10
const _TokenRestrictedSids = 11
const _TokenSessionId = 12
const _TokenGroupsAndPrivileges = 13
const _TokenSessionReference = 14
const _TokenSandBoxInert = 15
const _TokenAuditPolicy = 16
const _TokenOrigin = 17
const _TokenElevationType = 18
const _TokenLinkedToken = 19
const _TokenElevation = 20
const _TokenHasRestrictions = 21
const _TokenAccessInformation = 22
const _TokenVirtualizationAllowed = 23
const _TokenVirtualizationEnabled = 24
const _TokenIntegrityLevel = 25
const _TokenUIAccess = 26
const _TokenMandatoryPolicy = 27
const _TokenLogonSid = 28
const _TokenIsAppContainer = 29
const _TokenCapabilities = 30
const _TokenAppContainerSid = 31
const _TokenAppContainerNumber = 32
const _TokenUserClaimAttributes = 33
const _TokenDeviceClaimAttributes = 34
const _TokenRestrictedUserClaimAttributes = 35
const _TokenRestrictedDeviceClaimAttributes = 36
const _TokenDeviceGroups = 37
const _TokenRestrictedDeviceGroups = 38
const _TokenSecurityAttributes = 39
const _TokenIsRestricted = 40
const _MaxTokenInfoClass = 41

type TPTOKEN_INFORMATION_CLASS = uintptr

type PTOKEN_INFORMATION_CLASS = TPTOKEN_INFORMATION_CLASS

type TTOKEN_USER = struct {
	FUser TSID_AND_ATTRIBUTES
}

type TOKEN_USER = TTOKEN_USER

type T_TOKEN_USER = TTOKEN_USER

type _TOKEN_USER = T_TOKEN_USER

type TPTOKEN_USER = uintptr

type PTOKEN_USER = TPTOKEN_USER

type TTOKEN_GROUPS = struct {
	FGroupCount TDWORD
	FGroups     [1]TSID_AND_ATTRIBUTES
}

type TOKEN_GROUPS = TTOKEN_GROUPS

type T_TOKEN_GROUPS = TTOKEN_GROUPS

type _TOKEN_GROUPS = T_TOKEN_GROUPS

type TPTOKEN_GROUPS = uintptr

type PTOKEN_GROUPS = TPTOKEN_GROUPS

type TTOKEN_PRIVILEGES = struct {
	FPrivilegeCount TDWORD
	FPrivileges     [1]TLUID_AND_ATTRIBUTES
}

type TOKEN_PRIVILEGES = TTOKEN_PRIVILEGES

type T_TOKEN_PRIVILEGES = TTOKEN_PRIVILEGES

type _TOKEN_PRIVILEGES = T_TOKEN_PRIVILEGES

type TPTOKEN_PRIVILEGES = uintptr

type PTOKEN_PRIVILEGES = TPTOKEN_PRIVILEGES

type TTOKEN_OWNER = struct {
	FOwner TPSID
}

type TOKEN_OWNER = TTOKEN_OWNER

type T_TOKEN_OWNER = TTOKEN_OWNER

type _TOKEN_OWNER = T_TOKEN_OWNER

type TPTOKEN_OWNER = uintptr

type PTOKEN_OWNER = TPTOKEN_OWNER

type TTOKEN_PRIMARY_GROUP = struct {
	FPrimaryGroup TPSID
}

type TOKEN_PRIMARY_GROUP = TTOKEN_PRIMARY_GROUP

type T_TOKEN_PRIMARY_GROUP = TTOKEN_PRIMARY_GROUP

type _TOKEN_PRIMARY_GROUP = T_TOKEN_PRIMARY_GROUP

type TPTOKEN_PRIMARY_GROUP = uintptr

type PTOKEN_PRIMARY_GROUP = TPTOKEN_PRIMARY_GROUP

type TTOKEN_DEFAULT_DACL = struct {
	FDefaultDacl TPACL
}

type TOKEN_DEFAULT_DACL = TTOKEN_DEFAULT_DACL

type T_TOKEN_DEFAULT_DACL = TTOKEN_DEFAULT_DACL

type _TOKEN_DEFAULT_DACL = T_TOKEN_DEFAULT_DACL

type TPTOKEN_DEFAULT_DACL = uintptr

type PTOKEN_DEFAULT_DACL = TPTOKEN_DEFAULT_DACL

type TTOKEN_USER_CLAIMS = struct {
	FUserClaims TPCLAIMS_BLOB
}

type TOKEN_USER_CLAIMS = TTOKEN_USER_CLAIMS

type T_TOKEN_USER_CLAIMS = TTOKEN_USER_CLAIMS

type _TOKEN_USER_CLAIMS = T_TOKEN_USER_CLAIMS

type TPTOKEN_USER_CLAIMS = uintptr

type PTOKEN_USER_CLAIMS = TPTOKEN_USER_CLAIMS

type TTOKEN_DEVICE_CLAIMS = struct {
	FDeviceClaims TPCLAIMS_BLOB
}

type TOKEN_DEVICE_CLAIMS = TTOKEN_DEVICE_CLAIMS

type T_TOKEN_DEVICE_CLAIMS = TTOKEN_DEVICE_CLAIMS

type _TOKEN_DEVICE_CLAIMS = T_TOKEN_DEVICE_CLAIMS

type TPTOKEN_DEVICE_CLAIMS = uintptr

type PTOKEN_DEVICE_CLAIMS = TPTOKEN_DEVICE_CLAIMS

type TTOKEN_GROUPS_AND_PRIVILEGES = struct {
	FSidCount            TDWORD
	FSidLength           TDWORD
	FSids                TPSID_AND_ATTRIBUTES
	FRestrictedSidCount  TDWORD
	FRestrictedSidLength TDWORD
	FRestrictedSids      TPSID_AND_ATTRIBUTES
	FPrivilegeCount      TDWORD
	FPrivilegeLength     TDWORD
	FPrivileges          TPLUID_AND_ATTRIBUTES
	FAuthenticationId    TLUID
}

type TOKEN_GROUPS_AND_PRIVILEGES = TTOKEN_GROUPS_AND_PRIVILEGES

type T_TOKEN_GROUPS_AND_PRIVILEGES = TTOKEN_GROUPS_AND_PRIVILEGES

type _TOKEN_GROUPS_AND_PRIVILEGES = T_TOKEN_GROUPS_AND_PRIVILEGES

type TPTOKEN_GROUPS_AND_PRIVILEGES = uintptr

type PTOKEN_GROUPS_AND_PRIVILEGES = TPTOKEN_GROUPS_AND_PRIVILEGES

type TTOKEN_LINKED_TOKEN = struct {
	FLinkedToken THANDLE
}

type TOKEN_LINKED_TOKEN = TTOKEN_LINKED_TOKEN

type T_TOKEN_LINKED_TOKEN = TTOKEN_LINKED_TOKEN

type _TOKEN_LINKED_TOKEN = T_TOKEN_LINKED_TOKEN

type TPTOKEN_LINKED_TOKEN = uintptr

type PTOKEN_LINKED_TOKEN = TPTOKEN_LINKED_TOKEN

type TTOKEN_ELEVATION = struct {
	FTokenIsElevated TDWORD
}

type TOKEN_ELEVATION = TTOKEN_ELEVATION

type T_TOKEN_ELEVATION = TTOKEN_ELEVATION

type _TOKEN_ELEVATION = T_TOKEN_ELEVATION

type TPTOKEN_ELEVATION = uintptr

type PTOKEN_ELEVATION = TPTOKEN_ELEVATION

type TTOKEN_MANDATORY_LABEL = struct {
	FLabel TSID_AND_ATTRIBUTES
}

type TOKEN_MANDATORY_LABEL = TTOKEN_MANDATORY_LABEL

type T_TOKEN_MANDATORY_LABEL = TTOKEN_MANDATORY_LABEL

type _TOKEN_MANDATORY_LABEL = T_TOKEN_MANDATORY_LABEL

type TPTOKEN_MANDATORY_LABEL = uintptr

type PTOKEN_MANDATORY_LABEL = TPTOKEN_MANDATORY_LABEL

type TTOKEN_MANDATORY_POLICY = struct {
	FPolicy TDWORD
}

type TOKEN_MANDATORY_POLICY = TTOKEN_MANDATORY_POLICY

type T_TOKEN_MANDATORY_POLICY = TTOKEN_MANDATORY_POLICY

type _TOKEN_MANDATORY_POLICY = T_TOKEN_MANDATORY_POLICY

type TPTOKEN_MANDATORY_POLICY = uintptr

type PTOKEN_MANDATORY_POLICY = TPTOKEN_MANDATORY_POLICY

type TTOKEN_ACCESS_INFORMATION = struct {
	FSidHash            TPSID_AND_ATTRIBUTES_HASH
	FRestrictedSidHash  TPSID_AND_ATTRIBUTES_HASH
	FPrivileges         TPTOKEN_PRIVILEGES
	FAuthenticationId   TLUID
	FTokenType          TTOKEN_TYPE
	FImpersonationLevel TSECURITY_IMPERSONATION_LEVEL
	FMandatoryPolicy    TTOKEN_MANDATORY_POLICY
	FFlags              TDWORD
	FAppContainerNumber TDWORD
	FPackageSid         TPSID
	FCapabilitiesHash   TPSID_AND_ATTRIBUTES_HASH
}

type TOKEN_ACCESS_INFORMATION = TTOKEN_ACCESS_INFORMATION

type T_TOKEN_ACCESS_INFORMATION = TTOKEN_ACCESS_INFORMATION

type _TOKEN_ACCESS_INFORMATION = T_TOKEN_ACCESS_INFORMATION

type TPTOKEN_ACCESS_INFORMATION = uintptr

type PTOKEN_ACCESS_INFORMATION = TPTOKEN_ACCESS_INFORMATION

type TTOKEN_AUDIT_POLICY = struct {
	FPerUserPolicy [29]TUCHAR
}

type TOKEN_AUDIT_POLICY = TTOKEN_AUDIT_POLICY

type T_TOKEN_AUDIT_POLICY = TTOKEN_AUDIT_POLICY

type _TOKEN_AUDIT_POLICY = T_TOKEN_AUDIT_POLICY

type TPTOKEN_AUDIT_POLICY = uintptr

type PTOKEN_AUDIT_POLICY = TPTOKEN_AUDIT_POLICY

type TTOKEN_SOURCE = struct {
	FSourceName       [8]TCHAR
	FSourceIdentifier TLUID
}

type TOKEN_SOURCE = TTOKEN_SOURCE

type T_TOKEN_SOURCE = TTOKEN_SOURCE

type _TOKEN_SOURCE = T_TOKEN_SOURCE

type TPTOKEN_SOURCE = uintptr

type PTOKEN_SOURCE = TPTOKEN_SOURCE

type TTOKEN_STATISTICS = struct {
	F__ccgo_align       [0]uint32
	FTokenId            TLUID
	FAuthenticationId   TLUID
	FExpirationTime     TLARGE_INTEGER
	FTokenType          TTOKEN_TYPE
	FImpersonationLevel TSECURITY_IMPERSONATION_LEVEL
	FDynamicCharged     TDWORD
	FDynamicAvailable   TDWORD
	FGroupCount         TDWORD
	FPrivilegeCount     TDWORD
	FModifiedId         TLUID
}

type TOKEN_STATISTICS = TTOKEN_STATISTICS

type T_TOKEN_STATISTICS = TTOKEN_STATISTICS

type _TOKEN_STATISTICS = T_TOKEN_STATISTICS

type TPTOKEN_STATISTICS = uintptr

type PTOKEN_STATISTICS = TPTOKEN_STATISTICS

type TTOKEN_CONTROL = struct {
	FTokenId          TLUID
	FAuthenticationId TLUID
	FModifiedId       TLUID
	FTokenSource      TTOKEN_SOURCE
}

type TOKEN_CONTROL = TTOKEN_CONTROL

type T_TOKEN_CONTROL = TTOKEN_CONTROL

type _TOKEN_CONTROL = T_TOKEN_CONTROL

type TPTOKEN_CONTROL = uintptr

type PTOKEN_CONTROL = TPTOKEN_CONTROL

type TTOKEN_ORIGIN = struct {
	FOriginatingLogonSession TLUID
}

type TOKEN_ORIGIN = TTOKEN_ORIGIN

type T_TOKEN_ORIGIN = TTOKEN_ORIGIN

type _TOKEN_ORIGIN = T_TOKEN_ORIGIN

type TPTOKEN_ORIGIN = uintptr

type PTOKEN_ORIGIN = TPTOKEN_ORIGIN

type TMANDATORY_LEVEL = int32

type MANDATORY_LEVEL = TMANDATORY_LEVEL

type __MANDATORY_LEVEL = int32

const _MandatoryLevelUntrusted = 0
const _MandatoryLevelLow = 1
const _MandatoryLevelMedium = 2
const _MandatoryLevelHigh = 3
const _MandatoryLevelSystem = 4
const _MandatoryLevelSecureProcess = 5
const _MandatoryLevelCount = 6

type TPMANDATORY_LEVEL = uintptr

type PMANDATORY_LEVEL = TPMANDATORY_LEVEL

type TTOKEN_APPCONTAINER_INFORMATION = struct {
	FTokenAppContainer TPSID
}

type TOKEN_APPCONTAINER_INFORMATION = TTOKEN_APPCONTAINER_INFORMATION

type T_TOKEN_APPCONTAINER_INFORMATION = TTOKEN_APPCONTAINER_INFORMATION

type _TOKEN_APPCONTAINER_INFORMATION = T_TOKEN_APPCONTAINER_INFORMATION

type TPTOKEN_APPCONTAINER_INFORMATION = uintptr

type PTOKEN_APPCONTAINER_INFORMATION = TPTOKEN_APPCONTAINER_INFORMATION

type TCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE = struct {
	F__ccgo_align [0]uint32
	FVersion      TDWORD64
	FName         TPWSTR
	F__ccgo_pad2  [4]byte
}

type CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE = TCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE

type T_CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE = TCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE

type _CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE = T_CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE

type TPCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE = uintptr

type PCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE = TPCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE

type TCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE = struct {
	FpValue      TPVOID
	FValueLength TDWORD
}

type CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE = TCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE

type T_CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE = TCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE

type _CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE = T_CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE

type TPCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE = uintptr

type PCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE = TPCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE

type TCLAIM_SECURITY_ATTRIBUTE_V1 = struct {
	FName       TPWSTR
	FValueType  TWORD
	FReserved   TWORD
	FFlags      TDWORD
	FValueCount TDWORD
	FValues     struct {
		FpUint64      [0]TPDWORD64
		FppString     [0]uintptr
		FpFqbn        [0]TPCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE
		FpOctetString [0]TPCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE
		FpInt64       TPLONG64
	}
}

type CLAIM_SECURITY_ATTRIBUTE_V1 = TCLAIM_SECURITY_ATTRIBUTE_V1

type T_CLAIM_SECURITY_ATTRIBUTE_V1 = TCLAIM_SECURITY_ATTRIBUTE_V1

type _CLAIM_SECURITY_ATTRIBUTE_V1 = T_CLAIM_SECURITY_ATTRIBUTE_V1

type TPCLAIM_SECURITY_ATTRIBUTE_V1 = uintptr

type PCLAIM_SECURITY_ATTRIBUTE_V1 = TPCLAIM_SECURITY_ATTRIBUTE_V1

type TCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 = struct {
	FName       TDWORD
	FValueType  TWORD
	FReserved   TWORD
	FFlags      TDWORD
	FValueCount TDWORD
	FValues     struct {
		FpUint64      [0][1]TDWORD
		FppString     [0][1]TDWORD
		FpFqbn        [0][1]TDWORD
		FpOctetString [0][1]TDWORD
		FpInt64       [1]TDWORD
	}
}

type CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 = TCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1

type T_CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 = TCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1

type _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 = T_CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1

type TPCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 = uintptr

type PCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 = TPCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1

type TCLAIM_SECURITY_ATTRIBUTES_INFORMATION = struct {
	FVersion        TWORD
	FReserved       TWORD
	FAttributeCount TDWORD
	FAttribute      struct {
		FpAttributeV1 TPCLAIM_SECURITY_ATTRIBUTE_V1
	}
}

type CLAIM_SECURITY_ATTRIBUTES_INFORMATION = TCLAIM_SECURITY_ATTRIBUTES_INFORMATION

type T_CLAIM_SECURITY_ATTRIBUTES_INFORMATION = TCLAIM_SECURITY_ATTRIBUTES_INFORMATION

type _CLAIM_SECURITY_ATTRIBUTES_INFORMATION = T_CLAIM_SECURITY_ATTRIBUTES_INFORMATION

type TPCLAIM_SECURITY_ATTRIBUTES_INFORMATION = uintptr

type PCLAIM_SECURITY_ATTRIBUTES_INFORMATION = TPCLAIM_SECURITY_ATTRIBUTES_INFORMATION

type TSECURITY_CONTEXT_TRACKING_MODE = uint8

type SECURITY_CONTEXT_TRACKING_MODE = TSECURITY_CONTEXT_TRACKING_MODE

type TPSECURITY_CONTEXT_TRACKING_MODE = uintptr

type PSECURITY_CONTEXT_TRACKING_MODE = TPSECURITY_CONTEXT_TRACKING_MODE

type TSECURITY_QUALITY_OF_SERVICE = struct {
	FLength              TDWORD
	FImpersonationLevel  TSECURITY_IMPERSONATION_LEVEL
	FContextTrackingMode TSECURITY_CONTEXT_TRACKING_MODE
	FEffectiveOnly       TBOOLEAN
}

type SECURITY_QUALITY_OF_SERVICE = TSECURITY_QUALITY_OF_SERVICE

type T_SECURITY_QUALITY_OF_SERVICE = TSECURITY_QUALITY_OF_SERVICE

type _SECURITY_QUALITY_OF_SERVICE = T_SECURITY_QUALITY_OF_SERVICE

type TPSECURITY_QUALITY_OF_SERVICE = uintptr

type PSECURITY_QUALITY_OF_SERVICE = TPSECURITY_QUALITY_OF_SERVICE

type TSE_IMPERSONATION_STATE = struct {
	FToken         TPACCESS_TOKEN
	FCopyOnOpen    TBOOLEAN
	FEffectiveOnly TBOOLEAN
	FLevel         TSECURITY_IMPERSONATION_LEVEL
}

type SE_IMPERSONATION_STATE = TSE_IMPERSONATION_STATE

type T_SE_IMPERSONATION_STATE = TSE_IMPERSONATION_STATE

type _SE_IMPERSONATION_STATE = T_SE_IMPERSONATION_STATE

type TPSE_IMPERSONATION_STATE = uintptr

type PSE_IMPERSONATION_STATE = TPSE_IMPERSONATION_STATE

type TSECURITY_INFORMATION = uint32

type SECURITY_INFORMATION = TSECURITY_INFORMATION

type TPSECURITY_INFORMATION = uintptr

type PSECURITY_INFORMATION = TPSECURITY_INFORMATION

type TSE_LEARNING_MODE_DATA_TYPE = int32

type SE_LEARNING_MODE_DATA_TYPE = TSE_LEARNING_MODE_DATA_TYPE

type __SE_LEARNING_MODE_DATA_TYPE = int32

const _SeLearningModeInvalidType = 0
const _SeLearningModeSettings = 1
const _SeLearningModeMax = 2

type TSECURITY_CAPABILITIES = struct {
	FAppContainerSid TPSID
	FCapabilities    TPSID_AND_ATTRIBUTES
	FCapabilityCount TDWORD
	FReserved        TDWORD
}

type SECURITY_CAPABILITIES = TSECURITY_CAPABILITIES

type T_SECURITY_CAPABILITIES = TSECURITY_CAPABILITIES

type _SECURITY_CAPABILITIES = T_SECURITY_CAPABILITIES

type TPSECURITY_CAPABILITIES = uintptr

type PSECURITY_CAPABILITIES = TPSECURITY_CAPABILITIES

type TLPSECURITY_CAPABILITIES = uintptr

type LPSECURITY_CAPABILITIES = TLPSECURITY_CAPABILITIES

type TJOB_SET_ARRAY = struct {
	FJobHandle   THANDLE
	FMemberLevel TDWORD
	FFlags       TDWORD
}

type JOB_SET_ARRAY = TJOB_SET_ARRAY

type T_JOB_SET_ARRAY = TJOB_SET_ARRAY

type _JOB_SET_ARRAY = T_JOB_SET_ARRAY

type TPJOB_SET_ARRAY = uintptr

type PJOB_SET_ARRAY = TPJOB_SET_ARRAY

type TEXCEPTION_REGISTRATION_RECORD = struct {
	F__ccgo0_0 struct {
		Fprev [0]uintptr
		FNext uintptr
	}
	F__ccgo1_4 struct {
		Fhandler [0]TPEXCEPTION_ROUTINE
		FHandler TPEXCEPTION_ROUTINE
	}
}

type EXCEPTION_REGISTRATION_RECORD = TEXCEPTION_REGISTRATION_RECORD

type T_EXCEPTION_REGISTRATION_RECORD = TEXCEPTION_REGISTRATION_RECORD

type _EXCEPTION_REGISTRATION_RECORD = T_EXCEPTION_REGISTRATION_RECORD

type TPEXCEPTION_REGISTRATION_RECORD = uintptr

type PEXCEPTION_REGISTRATION_RECORD = TPEXCEPTION_REGISTRATION_RECORD

type TEXCEPTION_REGISTRATION = struct {
	F__ccgo0_0 struct {
		Fprev [0]uintptr
		FNext uintptr
	}
	F__ccgo1_4 struct {
		Fhandler [0]TPEXCEPTION_ROUTINE
		FHandler TPEXCEPTION_ROUTINE
	}
}

type EXCEPTION_REGISTRATION = TEXCEPTION_REGISTRATION

type TPEXCEPTION_REGISTRATION = uintptr

type PEXCEPTION_REGISTRATION = TPEXCEPTION_REGISTRATION

type TNT_TIB = struct {
	FExceptionList uintptr
	FStackBase     TPVOID
	FStackLimit    TPVOID
	FSubSystemTib  TPVOID
	F__ccgo4_16    struct {
		FVersion   [0]TDWORD
		FFiberData TPVOID
	}
	FArbitraryUserPointer TPVOID
	FSelf                 uintptr
}

type NT_TIB = TNT_TIB

type T_NT_TIB = TNT_TIB

type _NT_TIB = T_NT_TIB

type TPNT_TIB = uintptr

type PNT_TIB = TPNT_TIB

type TNT_TIB32 = struct {
	FExceptionList TDWORD
	FStackBase     TDWORD
	FStackLimit    TDWORD
	FSubSystemTib  TDWORD
	F__ccgo4_16    struct {
		FVersion   [0]TDWORD
		FFiberData TDWORD
	}
	FArbitraryUserPointer TDWORD
	FSelf                 TDWORD
}

type NT_TIB32 = TNT_TIB32

type T_NT_TIB32 = TNT_TIB32

type _NT_TIB32 = T_NT_TIB32

type TPNT_TIB32 = uintptr

type PNT_TIB32 = TPNT_TIB32

type TNT_TIB64 = struct {
	F__ccgo_align  [0]uint32
	FExceptionList TDWORD64
	FStackBase     TDWORD64
	FStackLimit    TDWORD64
	FSubSystemTib  TDWORD64
	F__ccgo4_32    struct {
		F__ccgo_align [0]uint32
		FVersion      [0]TDWORD
		FFiberData    TDWORD64
	}
	FArbitraryUserPointer TDWORD64
	FSelf                 TDWORD64
}

type NT_TIB64 = TNT_TIB64

type T_NT_TIB64 = TNT_TIB64

type _NT_TIB64 = T_NT_TIB64

type TPNT_TIB64 = uintptr

type PNT_TIB64 = TPNT_TIB64

type TUMS_CREATE_THREAD_ATTRIBUTES = struct {
	FUmsVersion        TDWORD
	FUmsContext        TPVOID
	FUmsCompletionList TPVOID
}

type UMS_CREATE_THREAD_ATTRIBUTES = TUMS_CREATE_THREAD_ATTRIBUTES

type T_UMS_CREATE_THREAD_ATTRIBUTES = TUMS_CREATE_THREAD_ATTRIBUTES

type _UMS_CREATE_THREAD_ATTRIBUTES = T_UMS_CREATE_THREAD_ATTRIBUTES

type TPUMS_CREATE_THREAD_ATTRIBUTES = uintptr

type PUMS_CREATE_THREAD_ATTRIBUTES = TPUMS_CREATE_THREAD_ATTRIBUTES

type TCOMPONENT_FILTER = struct {
	FComponentFlags TDWORD
}

type COMPONENT_FILTER = TCOMPONENT_FILTER

type T_COMPONENT_FILTER = TCOMPONENT_FILTER

type _COMPONENT_FILTER = T_COMPONENT_FILTER

type TPCOMPONENT_FILTER = uintptr

type PCOMPONENT_FILTER = TPCOMPONENT_FILTER

type TPROCESS_DYNAMIC_EH_CONTINUATION_TARGET = struct {
	FTargetAddress TULONG_PTR
	FFlags         TULONG_PTR
}

type PROCESS_DYNAMIC_EH_CONTINUATION_TARGET = TPROCESS_DYNAMIC_EH_CONTINUATION_TARGET

type T_PROCESS_DYNAMIC_EH_CONTINUATION_TARGET = TPROCESS_DYNAMIC_EH_CONTINUATION_TARGET

type _PROCESS_DYNAMIC_EH_CONTINUATION_TARGET = T_PROCESS_DYNAMIC_EH_CONTINUATION_TARGET

type TPPROCESS_DYNAMIC_EH_CONTINUATION_TARGET = uintptr

type PPROCESS_DYNAMIC_EH_CONTINUATION_TARGET = TPPROCESS_DYNAMIC_EH_CONTINUATION_TARGET

type TPROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION = struct {
	FNumberOfTargets TWORD
	FReserved        TWORD
	FReserved2       TDWORD
	FTargets         TPPROCESS_DYNAMIC_EH_CONTINUATION_TARGET
}

type PROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION = TPROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION

type T_PROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION = TPROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION

type _PROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION = T_PROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION

type TPPROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION = uintptr

type PPROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION = TPPROCESS_DYNAMIC_EH_CONTINUATION_TARGETS_INFORMATION

type TPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE = struct {
	FBaseAddress TULONG_PTR
	FSize        TSIZE_T
	FFlags       TDWORD
}

type PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE = TPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE

type T_PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE = TPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE

type _PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE = T_PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE

type TPPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE = uintptr

type PPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE = TPPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE

type TPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION = struct {
	FNumberOfRanges TWORD
	FReserved       TWORD
	FReserved2      TDWORD
	FRanges         TPPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGE
}

type PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION = TPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION

type T_PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION = TPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION

type _PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION = T_PROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION

type TPPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION = uintptr

type PPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION = TPPROCESS_DYNAMIC_ENFORCED_ADDRESS_RANGES_INFORMATION

type TQUOTA_LIMITS = struct {
	F__ccgo_align          [0]uint32
	FPagedPoolLimit        TSIZE_T
	FNonPagedPoolLimit     TSIZE_T
	FMinimumWorkingSetSize TSIZE_T
	FMaximumWorkingSetSize TSIZE_T
	FPagefileLimit         TSIZE_T
	F__ccgo_align5         [4]byte
	FTimeLimit             TLARGE_INTEGER
}

type QUOTA_LIMITS = TQUOTA_LIMITS

type T_QUOTA_LIMITS = TQUOTA_LIMITS

type _QUOTA_LIMITS = T_QUOTA_LIMITS

type TPQUOTA_LIMITS = uintptr

type PQUOTA_LIMITS = TPQUOTA_LIMITS

type TRATE_QUOTA_LIMIT = struct {
	F__ccgo1_0 [0]struct {
		F__ccgo0 uint32
	}
	FRateData TDWORD
}

type RATE_QUOTA_LIMIT = TRATE_QUOTA_LIMIT

type T_RATE_QUOTA_LIMIT = TRATE_QUOTA_LIMIT

type _RATE_QUOTA_LIMIT = T_RATE_QUOTA_LIMIT

type TPRATE_QUOTA_LIMIT = uintptr

type PRATE_QUOTA_LIMIT = TPRATE_QUOTA_LIMIT

type TQUOTA_LIMITS_EX = struct {
	F__ccgo_align          [0]uint32
	FPagedPoolLimit        TSIZE_T
	FNonPagedPoolLimit     TSIZE_T
	FMinimumWorkingSetSize TSIZE_T
	FMaximumWorkingSetSize TSIZE_T
	FPagefileLimit         TSIZE_T
	F__ccgo_align5         [4]byte
	FTimeLimit             TLARGE_INTEGER
	FWorkingSetLimit       TSIZE_T
	FReserved2             TSIZE_T
	FReserved3             TSIZE_T
	FReserved4             TSIZE_T
	FFlags                 TDWORD
	FCpuRateLimit          TRATE_QUOTA_LIMIT
}

type QUOTA_LIMITS_EX = TQUOTA_LIMITS_EX

type T_QUOTA_LIMITS_EX = TQUOTA_LIMITS_EX

type _QUOTA_LIMITS_EX = T_QUOTA_LIMITS_EX

type TPQUOTA_LIMITS_EX = uintptr

type PQUOTA_LIMITS_EX = TPQUOTA_LIMITS_EX

type TIO_COUNTERS = struct {
	F__ccgo_align        [0]uint32
	FReadOperationCount  TULONGLONG
	FWriteOperationCount TULONGLONG
	FOtherOperationCount TULONGLONG
	FReadTransferCount   TULONGLONG
	FWriteTransferCount  TULONGLONG
	FOtherTransferCount  TULONGLONG
}

type IO_COUNTERS = TIO_COUNTERS

type T_IO_COUNTERS = TIO_COUNTERS

type _IO_COUNTERS = T_IO_COUNTERS

type TPIO_COUNTERS = uintptr

type PIO_COUNTERS = TPIO_COUNTERS

type THARDWARE_COUNTER_TYPE = int32

type HARDWARE_COUNTER_TYPE = THARDWARE_COUNTER_TYPE

type __HARDWARE_COUNTER_TYPE = int32

const _PMCCounter = 0
const _MaxHardwareCounterType = 1

type TPHARDWARE_COUNTER_TYPE = uintptr

type PHARDWARE_COUNTER_TYPE = TPHARDWARE_COUNTER_TYPE

type TPROCESS_MITIGATION_POLICY = int32

type PROCESS_MITIGATION_POLICY = TPROCESS_MITIGATION_POLICY

type __PROCESS_MITIGATION_POLICY = int32

const _ProcessDEPPolicy = 0
const _ProcessASLRPolicy = 1
const _ProcessDynamicCodePolicy = 2
const _ProcessStrictHandleCheckPolicy = 3
const _ProcessSystemCallDisablePolicy = 4
const _ProcessMitigationOptionsMask = 5
const _ProcessExtensionPointDisablePolicy = 6
const _ProcessControlFlowGuardPolicy = 7
const _ProcessSignaturePolicy = 8
const _ProcessFontDisablePolicy = 9
const _ProcessImageLoadPolicy = 10
const _ProcessSystemCallFilterPolicy = 11
const _ProcessPayloadRestrictionPolicy = 12
const _ProcessChildProcessPolicy = 13
const _ProcessSideChannelIsolationPolicy = 14
const _ProcessUserShadowStackPolicy = 15
const _ProcessRedirectionTrustPolicy = 16
const _MaxProcessMitigationPolicy = 17

type TPPROCESS_MITIGATION_POLICY = uintptr

type PPROCESS_MITIGATION_POLICY = TPPROCESS_MITIGATION_POLICY

type TPROCESS_MITIGATION_ASLR_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_ASLR_POLICY = TPROCESS_MITIGATION_ASLR_POLICY

type T_PROCESS_MITIGATION_ASLR_POLICY = TPROCESS_MITIGATION_ASLR_POLICY

type _PROCESS_MITIGATION_ASLR_POLICY = T_PROCESS_MITIGATION_ASLR_POLICY

type TPPROCESS_MITIGATION_ASLR_POLICY = uintptr

type PPROCESS_MITIGATION_ASLR_POLICY = TPPROCESS_MITIGATION_ASLR_POLICY

type TPROCESS_MITIGATION_DEP_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
	FPermanent TBOOLEAN
}

type PROCESS_MITIGATION_DEP_POLICY = TPROCESS_MITIGATION_DEP_POLICY

type T_PROCESS_MITIGATION_DEP_POLICY = TPROCESS_MITIGATION_DEP_POLICY

type _PROCESS_MITIGATION_DEP_POLICY = T_PROCESS_MITIGATION_DEP_POLICY

type TPPROCESS_MITIGATION_DEP_POLICY = uintptr

type PPROCESS_MITIGATION_DEP_POLICY = TPPROCESS_MITIGATION_DEP_POLICY

type TPROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY = TPROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY

type T_PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY = TPROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY

type _PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY = T_PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY

type TPPROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY = uintptr

type PPROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY = TPPROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY

type TPROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY = TPROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY

type T_PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY = TPROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY

type _PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY = T_PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY

type TPPROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY = uintptr

type PPROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY = TPPROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY

type TPROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY = TPROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY

type T_PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY = TPROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY

type _PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY = T_PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY

type TPPROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY = uintptr

type PPROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY = TPPROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY

type TPROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY = TPROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY

type T_PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY = TPROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY

type _PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY = T_PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY

type TPPROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY = uintptr

type PPROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY = TPPROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY

type TPROCESS_MITIGATION_BINARY_SIGNATURE_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY = TPROCESS_MITIGATION_BINARY_SIGNATURE_POLICY

type T_PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY = TPROCESS_MITIGATION_BINARY_SIGNATURE_POLICY

type _PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY = T_PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY

type TPPROCESS_MITIGATION_BINARY_SIGNATURE_POLICY = uintptr

type PPROCESS_MITIGATION_BINARY_SIGNATURE_POLICY = TPPROCESS_MITIGATION_BINARY_SIGNATURE_POLICY

type TPROCESS_MITIGATION_DYNAMIC_CODE_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint8
			F__ccgo4 uint32
		}
		FFlags       TDWORD
		F__ccgo_pad2 [4]byte
	}
}

type PROCESS_MITIGATION_DYNAMIC_CODE_POLICY = TPROCESS_MITIGATION_DYNAMIC_CODE_POLICY

type T_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY = TPROCESS_MITIGATION_DYNAMIC_CODE_POLICY

type _PROCESS_MITIGATION_DYNAMIC_CODE_POLICY = T_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY

type TPPROCESS_MITIGATION_DYNAMIC_CODE_POLICY = uintptr

type PPROCESS_MITIGATION_DYNAMIC_CODE_POLICY = TPPROCESS_MITIGATION_DYNAMIC_CODE_POLICY

type TPROCESS_MITIGATION_FONT_DISABLE_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_FONT_DISABLE_POLICY = TPROCESS_MITIGATION_FONT_DISABLE_POLICY

type T_PROCESS_MITIGATION_FONT_DISABLE_POLICY = TPROCESS_MITIGATION_FONT_DISABLE_POLICY

type _PROCESS_MITIGATION_FONT_DISABLE_POLICY = T_PROCESS_MITIGATION_FONT_DISABLE_POLICY

type TPPROCESS_MITIGATION_FONT_DISABLE_POLICY = uintptr

type PPROCESS_MITIGATION_FONT_DISABLE_POLICY = TPPROCESS_MITIGATION_FONT_DISABLE_POLICY

type TPROCESS_MITIGATION_IMAGE_LOAD_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_IMAGE_LOAD_POLICY = TPROCESS_MITIGATION_IMAGE_LOAD_POLICY

type T_PROCESS_MITIGATION_IMAGE_LOAD_POLICY = TPROCESS_MITIGATION_IMAGE_LOAD_POLICY

type _PROCESS_MITIGATION_IMAGE_LOAD_POLICY = T_PROCESS_MITIGATION_IMAGE_LOAD_POLICY

type TPPROCESS_MITIGATION_IMAGE_LOAD_POLICY = uintptr

type PPROCESS_MITIGATION_IMAGE_LOAD_POLICY = TPPROCESS_MITIGATION_IMAGE_LOAD_POLICY

type TPROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY = TPROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY

type T_PROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY = TPROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY

type _PROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY = T_PROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY

type TPPROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY = uintptr

type PPROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY = TPPROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY

type TPROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY = TPROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY

type T_PROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY = TPROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY

type _PROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY = T_PROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY

type TPPROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY = uintptr

type PPROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY = TPPROCESS_MITIGATION_PAYLOAD_RESTRICTION_POLICY

type TPROCESS_MITIGATION_CHILD_PROCESS_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_CHILD_PROCESS_POLICY = TPROCESS_MITIGATION_CHILD_PROCESS_POLICY

type T_PROCESS_MITIGATION_CHILD_PROCESS_POLICY = TPROCESS_MITIGATION_CHILD_PROCESS_POLICY

type _PROCESS_MITIGATION_CHILD_PROCESS_POLICY = T_PROCESS_MITIGATION_CHILD_PROCESS_POLICY

type TPPROCESS_MITIGATION_CHILD_PROCESS_POLICY = uintptr

type PPROCESS_MITIGATION_CHILD_PROCESS_POLICY = TPPROCESS_MITIGATION_CHILD_PROCESS_POLICY

type TPROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY = TPROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY

type T_PROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY = TPROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY

type _PROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY = T_PROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY

type TPPROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY = uintptr

type PPROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY = TPPROCESS_MITIGATION_SIDE_CHANNEL_ISOLATION_POLICY

type TPROCESS_MITIGATION_USER_SHADOW_STACK_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY = TPROCESS_MITIGATION_USER_SHADOW_STACK_POLICY

type T_PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY = TPROCESS_MITIGATION_USER_SHADOW_STACK_POLICY

type _PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY = T_PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY

type TPPROCESS_MITIGATION_USER_SHADOW_STACK_POLICY = uintptr

type PPROCESS_MITIGATION_USER_SHADOW_STACK_POLICY = TPPROCESS_MITIGATION_USER_SHADOW_STACK_POLICY

type TPROCESS_MITIGATION_REDIRECTION_TRUST_POLICY = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
}

type PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY = TPROCESS_MITIGATION_REDIRECTION_TRUST_POLICY

type T_PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY = TPROCESS_MITIGATION_REDIRECTION_TRUST_POLICY

type _PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY = T_PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY

type TPPROCESS_MITIGATION_REDIRECTION_TRUST_POLICY = uintptr

type PPROCESS_MITIGATION_REDIRECTION_TRUST_POLICY = TPPROCESS_MITIGATION_REDIRECTION_TRUST_POLICY

type TJOBOBJECT_BASIC_ACCOUNTING_INFORMATION = struct {
	F__ccgo_align              [0]uint32
	FTotalUserTime             TLARGE_INTEGER
	FTotalKernelTime           TLARGE_INTEGER
	FThisPeriodTotalUserTime   TLARGE_INTEGER
	FThisPeriodTotalKernelTime TLARGE_INTEGER
	FTotalPageFaultCount       TDWORD
	FTotalProcesses            TDWORD
	FActiveProcesses           TDWORD
	FTotalTerminatedProcesses  TDWORD
}

type JOBOBJECT_BASIC_ACCOUNTING_INFORMATION = TJOBOBJECT_BASIC_ACCOUNTING_INFORMATION

type T_JOBOBJECT_BASIC_ACCOUNTING_INFORMATION = TJOBOBJECT_BASIC_ACCOUNTING_INFORMATION

type _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION = T_JOBOBJECT_BASIC_ACCOUNTING_INFORMATION

type TPJOBOBJECT_BASIC_ACCOUNTING_INFORMATION = uintptr

type PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION = TPJOBOBJECT_BASIC_ACCOUNTING_INFORMATION

type TJOBOBJECT_BASIC_LIMIT_INFORMATION = struct {
	F__ccgo_align            [0]uint32
	FPerProcessUserTimeLimit TLARGE_INTEGER
	FPerJobUserTimeLimit     TLARGE_INTEGER
	FLimitFlags              TDWORD
	FMinimumWorkingSetSize   TSIZE_T
	FMaximumWorkingSetSize   TSIZE_T
	FActiveProcessLimit      TDWORD
	FAffinity                TULONG_PTR
	FPriorityClass           TDWORD
	FSchedulingClass         TDWORD
	F__ccgo_pad9             [4]byte
}

type JOBOBJECT_BASIC_LIMIT_INFORMATION = TJOBOBJECT_BASIC_LIMIT_INFORMATION

type T_JOBOBJECT_BASIC_LIMIT_INFORMATION = TJOBOBJECT_BASIC_LIMIT_INFORMATION

type _JOBOBJECT_BASIC_LIMIT_INFORMATION = T_JOBOBJECT_BASIC_LIMIT_INFORMATION

type TPJOBOBJECT_BASIC_LIMIT_INFORMATION = uintptr

type PJOBOBJECT_BASIC_LIMIT_INFORMATION = TPJOBOBJECT_BASIC_LIMIT_INFORMATION

type TJOBOBJECT_EXTENDED_LIMIT_INFORMATION = struct {
	F__ccgo_align          [0]uint32
	FBasicLimitInformation TJOBOBJECT_BASIC_LIMIT_INFORMATION
	FIoInfo                TIO_COUNTERS
	FProcessMemoryLimit    TSIZE_T
	FJobMemoryLimit        TSIZE_T
	FPeakProcessMemoryUsed TSIZE_T
	FPeakJobMemoryUsed     TSIZE_T
}

type JOBOBJECT_EXTENDED_LIMIT_INFORMATION = TJOBOBJECT_EXTENDED_LIMIT_INFORMATION

type T_JOBOBJECT_EXTENDED_LIMIT_INFORMATION = TJOBOBJECT_EXTENDED_LIMIT_INFORMATION

type _JOBOBJECT_EXTENDED_LIMIT_INFORMATION = T_JOBOBJECT_EXTENDED_LIMIT_INFORMATION

type TPJOBOBJECT_EXTENDED_LIMIT_INFORMATION = uintptr

type PJOBOBJECT_EXTENDED_LIMIT_INFORMATION = TPJOBOBJECT_EXTENDED_LIMIT_INFORMATION

type TJOBOBJECT_BASIC_PROCESS_ID_LIST = struct {
	FNumberOfAssignedProcesses TDWORD
	FNumberOfProcessIdsInList  TDWORD
	FProcessIdList             [1]TULONG_PTR
}

type JOBOBJECT_BASIC_PROCESS_ID_LIST = TJOBOBJECT_BASIC_PROCESS_ID_LIST

type T_JOBOBJECT_BASIC_PROCESS_ID_LIST = TJOBOBJECT_BASIC_PROCESS_ID_LIST

type _JOBOBJECT_BASIC_PROCESS_ID_LIST = T_JOBOBJECT_BASIC_PROCESS_ID_LIST

type TPJOBOBJECT_BASIC_PROCESS_ID_LIST = uintptr

type PJOBOBJECT_BASIC_PROCESS_ID_LIST = TPJOBOBJECT_BASIC_PROCESS_ID_LIST

type TJOBOBJECT_BASIC_UI_RESTRICTIONS = struct {
	FUIRestrictionsClass TDWORD
}

type JOBOBJECT_BASIC_UI_RESTRICTIONS = TJOBOBJECT_BASIC_UI_RESTRICTIONS

type T_JOBOBJECT_BASIC_UI_RESTRICTIONS = TJOBOBJECT_BASIC_UI_RESTRICTIONS

type _JOBOBJECT_BASIC_UI_RESTRICTIONS = T_JOBOBJECT_BASIC_UI_RESTRICTIONS

type TPJOBOBJECT_BASIC_UI_RESTRICTIONS = uintptr

type PJOBOBJECT_BASIC_UI_RESTRICTIONS = TPJOBOBJECT_BASIC_UI_RESTRICTIONS

type TJOBOBJECT_SECURITY_LIMIT_INFORMATION = struct {
	FSecurityLimitFlags TDWORD
	FJobToken           THANDLE
	FSidsToDisable      TPTOKEN_GROUPS
	FPrivilegesToDelete TPTOKEN_PRIVILEGES
	FRestrictedSids     TPTOKEN_GROUPS
}

type JOBOBJECT_SECURITY_LIMIT_INFORMATION = TJOBOBJECT_SECURITY_LIMIT_INFORMATION

type T_JOBOBJECT_SECURITY_LIMIT_INFORMATION = TJOBOBJECT_SECURITY_LIMIT_INFORMATION

type _JOBOBJECT_SECURITY_LIMIT_INFORMATION = T_JOBOBJECT_SECURITY_LIMIT_INFORMATION

type TPJOBOBJECT_SECURITY_LIMIT_INFORMATION = uintptr

type PJOBOBJECT_SECURITY_LIMIT_INFORMATION = TPJOBOBJECT_SECURITY_LIMIT_INFORMATION

type TJOBOBJECT_END_OF_JOB_TIME_INFORMATION = struct {
	FEndOfJobTimeAction TDWORD
}

type JOBOBJECT_END_OF_JOB_TIME_INFORMATION = TJOBOBJECT_END_OF_JOB_TIME_INFORMATION

type T_JOBOBJECT_END_OF_JOB_TIME_INFORMATION = TJOBOBJECT_END_OF_JOB_TIME_INFORMATION

type _JOBOBJECT_END_OF_JOB_TIME_INFORMATION = T_JOBOBJECT_END_OF_JOB_TIME_INFORMATION

type TPJOBOBJECT_END_OF_JOB_TIME_INFORMATION = uintptr

type PJOBOBJECT_END_OF_JOB_TIME_INFORMATION = TPJOBOBJECT_END_OF_JOB_TIME_INFORMATION

type TJOBOBJECT_ASSOCIATE_COMPLETION_PORT = struct {
	FCompletionKey  TPVOID
	FCompletionPort THANDLE
}

type JOBOBJECT_ASSOCIATE_COMPLETION_PORT = TJOBOBJECT_ASSOCIATE_COMPLETION_PORT

type T_JOBOBJECT_ASSOCIATE_COMPLETION_PORT = TJOBOBJECT_ASSOCIATE_COMPLETION_PORT

type _JOBOBJECT_ASSOCIATE_COMPLETION_PORT = T_JOBOBJECT_ASSOCIATE_COMPLETION_PORT

type TPJOBOBJECT_ASSOCIATE_COMPLETION_PORT = uintptr

type PJOBOBJECT_ASSOCIATE_COMPLETION_PORT = TPJOBOBJECT_ASSOCIATE_COMPLETION_PORT

type TJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = struct {
	F__ccgo_align [0]uint32
	FBasicInfo    TJOBOBJECT_BASIC_ACCOUNTING_INFORMATION
	FIoInfo       TIO_COUNTERS
}

type JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = TJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION

type T_JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = TJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION

type _JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = T_JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION

type TPJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = uintptr

type PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = TPJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION

type TJOBOBJECT_JOBSET_INFORMATION = struct {
	FMemberLevel TDWORD
}

type JOBOBJECT_JOBSET_INFORMATION = TJOBOBJECT_JOBSET_INFORMATION

type T_JOBOBJECT_JOBSET_INFORMATION = TJOBOBJECT_JOBSET_INFORMATION

type _JOBOBJECT_JOBSET_INFORMATION = T_JOBOBJECT_JOBSET_INFORMATION

type TPJOBOBJECT_JOBSET_INFORMATION = uintptr

type PJOBOBJECT_JOBSET_INFORMATION = TPJOBOBJECT_JOBSET_INFORMATION

type TJOBOBJECT_RATE_CONTROL_TOLERANCE = int32

type JOBOBJECT_RATE_CONTROL_TOLERANCE = TJOBOBJECT_RATE_CONTROL_TOLERANCE

type __JOBOBJECT_RATE_CONTROL_TOLERANCE = int32

const _ToleranceLow = 1
const _ToleranceMedium = 2
const _ToleranceHigh = 3

type TJOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL = int32

type JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL = TJOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL

type __JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL = int32

const _ToleranceIntervalShort = 1
const _ToleranceIntervalMedium = 2
const _ToleranceIntervalLong = 3

type TJOBOBJECT_NOTIFICATION_LIMIT_INFORMATION = struct {
	F__ccgo_align                 [0]uint32
	FIoReadBytesLimit             TDWORD64
	FIoWriteBytesLimit            TDWORD64
	FPerJobUserTimeLimit          TLARGE_INTEGER
	FJobMemoryLimit               TDWORD64
	FRateControlTolerance         TJOBOBJECT_RATE_CONTROL_TOLERANCE
	FRateControlToleranceInterval TJOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL
	FLimitFlags                   TDWORD
	F__ccgo_pad7                  [4]byte
}

type JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION = TJOBOBJECT_NOTIFICATION_LIMIT_INFORMATION

type T_JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION = TJOBOBJECT_NOTIFICATION_LIMIT_INFORMATION

type _JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION = T_JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION

type TPJOBOBJECT_NOTIFICATION_LIMIT_INFORMATION = uintptr

type PJOBOBJECT_NOTIFICATION_LIMIT_INFORMATION = TPJOBOBJECT_NOTIFICATION_LIMIT_INFORMATION

type TJOBOBJECT_LIMIT_VIOLATION_INFORMATION = struct {
	F__ccgo_align              [0]uint32
	FLimitFlags                TDWORD
	FViolationLimitFlags       TDWORD
	FIoReadBytes               TDWORD64
	FIoReadBytesLimit          TDWORD64
	FIoWriteBytes              TDWORD64
	FIoWriteBytesLimit         TDWORD64
	FPerJobUserTime            TLARGE_INTEGER
	FPerJobUserTimeLimit       TLARGE_INTEGER
	FJobMemory                 TDWORD64
	FJobMemoryLimit            TDWORD64
	FRateControlTolerance      TJOBOBJECT_RATE_CONTROL_TOLERANCE
	FRateControlToleranceLimit TJOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL
}

type JOBOBJECT_LIMIT_VIOLATION_INFORMATION = TJOBOBJECT_LIMIT_VIOLATION_INFORMATION

type T_JOBOBJECT_LIMIT_VIOLATION_INFORMATION = TJOBOBJECT_LIMIT_VIOLATION_INFORMATION

type _JOBOBJECT_LIMIT_VIOLATION_INFORMATION = T_JOBOBJECT_LIMIT_VIOLATION_INFORMATION

type TPJOBOBJECT_LIMIT_VIOLATION_INFORMATION = uintptr

type PJOBOBJECT_LIMIT_VIOLATION_INFORMATION = TPJOBOBJECT_LIMIT_VIOLATION_INFORMATION

type TJOBOBJECT_CPU_RATE_CONTROL_INFORMATION = struct {
	FControlFlags TDWORD
	F__ccgo1_4    struct {
		FWeight  [0]TDWORD
		FCpuRate TDWORD
	}
}

type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION = TJOBOBJECT_CPU_RATE_CONTROL_INFORMATION

type T_JOBOBJECT_CPU_RATE_CONTROL_INFORMATION = TJOBOBJECT_CPU_RATE_CONTROL_INFORMATION

type _JOBOBJECT_CPU_RATE_CONTROL_INFORMATION = T_JOBOBJECT_CPU_RATE_CONTROL_INFORMATION

type TPJOBOBJECT_CPU_RATE_CONTROL_INFORMATION = uintptr

type PJOBOBJECT_CPU_RATE_CONTROL_INFORMATION = TPJOBOBJECT_CPU_RATE_CONTROL_INFORMATION

type TJOBOBJECTINFOCLASS = int32

type JOBOBJECTINFOCLASS = TJOBOBJECTINFOCLASS

type __JOBOBJECTINFOCLASS = int32

const _JobObjectBasicAccountingInformation = 1
const _JobObjectBasicLimitInformation = 2
const _JobObjectBasicProcessIdList = 3
const _JobObjectBasicUIRestrictions = 4
const _JobObjectSecurityLimitInformation = 5
const _JobObjectEndOfJobTimeInformation = 6
const _JobObjectAssociateCompletionPortInformation = 7
const _JobObjectBasicAndIoAccountingInformation = 8
const _JobObjectExtendedLimitInformation = 9
const _JobObjectJobSetInformation = 10
const _JobObjectGroupInformation = 11
const _JobObjectNotificationLimitInformation = 12
const _JobObjectLimitViolationInformation = 13
const _JobObjectGroupInformationEx = 14
const _JobObjectCpuRateControlInformation = 15
const _JobObjectCompletionFilter = 16
const _JobObjectCompletionCounter = 17
const _JobObjectReserved1Information = 18
const _JobObjectReserved2Information = 19
const _JobObjectReserved3Information = 20
const _JobObjectReserved4Information = 21
const _JobObjectReserved5Information = 22
const _JobObjectReserved6Information = 23
const _JobObjectReserved7Information = 24
const _JobObjectReserved8Information = 25
const _MaxJobObjectInfoClass = 26

type TFIRMWARE_TYPE = int32

type FIRMWARE_TYPE = TFIRMWARE_TYPE

type __FIRMWARE_TYPE = int32

const _FirmwareTypeUnknown = 0
const _FirmwareTypeBios = 1
const _FirmwareTypeUefi = 2
const _FirmwareTypeMax = 3

type TPFIRMWARE_TYPE = uintptr

type PFIRMWARE_TYPE = TPFIRMWARE_TYPE

type TLOGICAL_PROCESSOR_RELATIONSHIP = int32

type LOGICAL_PROCESSOR_RELATIONSHIP = TLOGICAL_PROCESSOR_RELATIONSHIP

type __LOGICAL_PROCESSOR_RELATIONSHIP = int32

const _RelationProcessorCore = 0
const _RelationNumaNode = 1
const _RelationCache = 2
const _RelationProcessorPackage = 3
const _RelationGroup = 4
const _RelationAll = 65535

type TPROCESSOR_CACHE_TYPE = int32

type PROCESSOR_CACHE_TYPE = TPROCESSOR_CACHE_TYPE

type __PROCESSOR_CACHE_TYPE = int32

const _CacheUnified = 0
const _CacheInstruction = 1
const _CacheData = 2
const _CacheTrace = 3

type TCACHE_DESCRIPTOR = struct {
	FLevel         TBYTE
	FAssociativity TBYTE
	FLineSize      TWORD
	FSize          TDWORD
	FType          TPROCESSOR_CACHE_TYPE
}

type CACHE_DESCRIPTOR = TCACHE_DESCRIPTOR

type T_CACHE_DESCRIPTOR = TCACHE_DESCRIPTOR

type _CACHE_DESCRIPTOR = T_CACHE_DESCRIPTOR

type TPCACHE_DESCRIPTOR = uintptr

type PCACHE_DESCRIPTOR = TPCACHE_DESCRIPTOR

type TSYSTEM_LOGICAL_PROCESSOR_INFORMATION = struct {
	F__ccgo_align  [0]uint32
	FProcessorMask TULONG_PTR
	FRelationship  TLOGICAL_PROCESSOR_RELATIONSHIP
	F__ccgo2_8     struct {
		F__ccgo_align [0]uint32
		FNumaNode     [0]struct {
			FNodeNumber TDWORD
		}
		FCache         [0]TCACHE_DESCRIPTOR
		FReserved      [0][2]TULONGLONG
		FProcessorCore struct {
			FFlags TBYTE
		}
		F__ccgo_pad4 [15]byte
	}
}

type SYSTEM_LOGICAL_PROCESSOR_INFORMATION = TSYSTEM_LOGICAL_PROCESSOR_INFORMATION

type T_SYSTEM_LOGICAL_PROCESSOR_INFORMATION = TSYSTEM_LOGICAL_PROCESSOR_INFORMATION

type _SYSTEM_LOGICAL_PROCESSOR_INFORMATION = T_SYSTEM_LOGICAL_PROCESSOR_INFORMATION

type TPSYSTEM_LOGICAL_PROCESSOR_INFORMATION = uintptr

type PSYSTEM_LOGICAL_PROCESSOR_INFORMATION = TPSYSTEM_LOGICAL_PROCESSOR_INFORMATION

type TPROCESSOR_RELATIONSHIP = struct {
	FFlags      TBYTE
	FReserved   [21]TBYTE
	FGroupCount TWORD
	FGroupMask  [1]TGROUP_AFFINITY
}

type PROCESSOR_RELATIONSHIP = TPROCESSOR_RELATIONSHIP

type T_PROCESSOR_RELATIONSHIP = TPROCESSOR_RELATIONSHIP

type _PROCESSOR_RELATIONSHIP = T_PROCESSOR_RELATIONSHIP

type TPPROCESSOR_RELATIONSHIP = uintptr

type PPROCESSOR_RELATIONSHIP = TPPROCESSOR_RELATIONSHIP

type TNUMA_NODE_RELATIONSHIP = struct {
	FNodeNumber TDWORD
	FReserved   [20]TBYTE
	FGroupMask  TGROUP_AFFINITY
}

type NUMA_NODE_RELATIONSHIP = TNUMA_NODE_RELATIONSHIP

type T_NUMA_NODE_RELATIONSHIP = TNUMA_NODE_RELATIONSHIP

type _NUMA_NODE_RELATIONSHIP = T_NUMA_NODE_RELATIONSHIP

type TPNUMA_NODE_RELATIONSHIP = uintptr

type PNUMA_NODE_RELATIONSHIP = TPNUMA_NODE_RELATIONSHIP

type TCACHE_RELATIONSHIP = struct {
	FLevel         TBYTE
	FAssociativity TBYTE
	FLineSize      TWORD
	FCacheSize     TDWORD
	FType          TPROCESSOR_CACHE_TYPE
	FReserved      [20]TBYTE
	FGroupMask     TGROUP_AFFINITY
}

type CACHE_RELATIONSHIP = TCACHE_RELATIONSHIP

type T_CACHE_RELATIONSHIP = TCACHE_RELATIONSHIP

type _CACHE_RELATIONSHIP = T_CACHE_RELATIONSHIP

type TPCACHE_RELATIONSHIP = uintptr

type PCACHE_RELATIONSHIP = TPCACHE_RELATIONSHIP

type TPROCESSOR_GROUP_INFO = struct {
	FMaximumProcessorCount TBYTE
	FActiveProcessorCount  TBYTE
	FReserved              [38]TBYTE
	FActiveProcessorMask   TKAFFINITY
}

type PROCESSOR_GROUP_INFO = TPROCESSOR_GROUP_INFO

type T_PROCESSOR_GROUP_INFO = TPROCESSOR_GROUP_INFO

type _PROCESSOR_GROUP_INFO = T_PROCESSOR_GROUP_INFO

type TPPROCESSOR_GROUP_INFO = uintptr

type PPROCESSOR_GROUP_INFO = TPPROCESSOR_GROUP_INFO

type TGROUP_RELATIONSHIP = struct {
	FMaximumGroupCount TWORD
	FActiveGroupCount  TWORD
	FReserved          [20]TBYTE
	FGroupInfo         [1]TPROCESSOR_GROUP_INFO
}

type GROUP_RELATIONSHIP = TGROUP_RELATIONSHIP

type T_GROUP_RELATIONSHIP = TGROUP_RELATIONSHIP

type _GROUP_RELATIONSHIP = T_GROUP_RELATIONSHIP

type TPGROUP_RELATIONSHIP = uintptr

type PGROUP_RELATIONSHIP = TPGROUP_RELATIONSHIP

type T_SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX = struct {
	FRelationship TLOGICAL_PROCESSOR_RELATIONSHIP
	FSize         TDWORD
	F__ccgo2_8    struct {
		FNumaNode    [0]TNUMA_NODE_RELATIONSHIP
		FCache       [0]TCACHE_RELATIONSHIP
		FGroup       [0]TGROUP_RELATIONSHIP
		FProcessor   TPROCESSOR_RELATIONSHIP
		F__ccgo_pad4 [32]byte
	}
}

type _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX = T_SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX

type TSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX = struct {
	FRelationship TLOGICAL_PROCESSOR_RELATIONSHIP
	FSize         TDWORD
	F__ccgo2_8    struct {
		FNumaNode    [0]TNUMA_NODE_RELATIONSHIP
		FCache       [0]TCACHE_RELATIONSHIP
		FGroup       [0]TGROUP_RELATIONSHIP
		FProcessor   TPROCESSOR_RELATIONSHIP
		F__ccgo_pad4 [32]byte
	}
}

type SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX = TSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX

type TPSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX = uintptr

type PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX = TPSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX

type TSYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION = struct {
	F__ccgo_align [0]uint32
	FCycleTime    TDWORD64
}

type SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION = TSYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION

type T_SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION = TSYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION

type _SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION = T_SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION

type TPSYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION = uintptr

type PSYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION = TPSYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION

type TSYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION = struct {
	F__ccgo0 uint32
}

type SYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION = TSYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION

type T_SYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION = TSYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION

type _SYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION = T_SYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION

type TPSYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION = uintptr

type PSYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION = TPSYSTEM_SUPPORTED_PROCESSOR_ARCHITECTURES_INFORMATION

type TXSTATE_FEATURE = struct {
	FOffset TDWORD
	FSize   TDWORD
}

type XSTATE_FEATURE = TXSTATE_FEATURE

type T_XSTATE_FEATURE = TXSTATE_FEATURE

type _XSTATE_FEATURE = T_XSTATE_FEATURE

type TPXSTATE_FEATURE = uintptr

type PXSTATE_FEATURE = TPXSTATE_FEATURE

type TXSTATE_CONFIGURATION = struct {
	F__ccgo_align            [0]uint32
	FEnabledFeatures         TDWORD64
	FEnabledVolatileFeatures TDWORD64
	FSize                    TDWORD
	F__ccgo20                uint8
	FFeatures                [64]TXSTATE_FEATURE
}

type XSTATE_CONFIGURATION = TXSTATE_CONFIGURATION

type T_XSTATE_CONFIGURATION = TXSTATE_CONFIGURATION

type _XSTATE_CONFIGURATION = T_XSTATE_CONFIGURATION

type TPXSTATE_CONFIGURATION = uintptr

type PXSTATE_CONFIGURATION = TPXSTATE_CONFIGURATION

type TMEMORY_BASIC_INFORMATION = struct {
	FBaseAddress       TPVOID
	FAllocationBase    TPVOID
	FAllocationProtect TDWORD
	FRegionSize        TSIZE_T
	FState             TDWORD
	FProtect           TDWORD
	FType              TDWORD
}

type MEMORY_BASIC_INFORMATION = TMEMORY_BASIC_INFORMATION

type T_MEMORY_BASIC_INFORMATION = TMEMORY_BASIC_INFORMATION

type _MEMORY_BASIC_INFORMATION = T_MEMORY_BASIC_INFORMATION

type TPMEMORY_BASIC_INFORMATION = uintptr

type PMEMORY_BASIC_INFORMATION = TPMEMORY_BASIC_INFORMATION

type TMEMORY_BASIC_INFORMATION32 = struct {
	FBaseAddress       TDWORD
	FAllocationBase    TDWORD
	FAllocationProtect TDWORD
	FRegionSize        TDWORD
	FState             TDWORD
	FProtect           TDWORD
	FType              TDWORD
}

type MEMORY_BASIC_INFORMATION32 = TMEMORY_BASIC_INFORMATION32

type T_MEMORY_BASIC_INFORMATION32 = TMEMORY_BASIC_INFORMATION32

type _MEMORY_BASIC_INFORMATION32 = T_MEMORY_BASIC_INFORMATION32

type TPMEMORY_BASIC_INFORMATION32 = uintptr

type PMEMORY_BASIC_INFORMATION32 = TPMEMORY_BASIC_INFORMATION32

type TMEMORY_BASIC_INFORMATION64 = struct {
	F__ccgo_align      [0]uint32
	FBaseAddress       TULONGLONG
	FAllocationBase    TULONGLONG
	FAllocationProtect TDWORD
	F__alignment1      TDWORD
	FRegionSize        TULONGLONG
	FState             TDWORD
	FProtect           TDWORD
	FType              TDWORD
	F__alignment2      TDWORD
}

type MEMORY_BASIC_INFORMATION64 = TMEMORY_BASIC_INFORMATION64

type T_MEMORY_BASIC_INFORMATION64 = TMEMORY_BASIC_INFORMATION64

type _MEMORY_BASIC_INFORMATION64 = T_MEMORY_BASIC_INFORMATION64

type TPMEMORY_BASIC_INFORMATION64 = uintptr

type PMEMORY_BASIC_INFORMATION64 = TPMEMORY_BASIC_INFORMATION64

type TCFG_CALL_TARGET_INFO = struct {
	FOffset TULONG_PTR
	FFlags  TULONG_PTR
}

type CFG_CALL_TARGET_INFO = TCFG_CALL_TARGET_INFO

type T_CFG_CALL_TARGET_INFO = TCFG_CALL_TARGET_INFO

type _CFG_CALL_TARGET_INFO = T_CFG_CALL_TARGET_INFO

type TPCFG_CALL_TARGET_INFO = uintptr

type PCFG_CALL_TARGET_INFO = TPCFG_CALL_TARGET_INFO

type TMEM_ADDRESS_REQUIREMENTS = struct {
	FLowestStartingAddress TPVOID
	FHighestEndingAddress  TPVOID
	FAlignment             TSIZE_T
}

type MEM_ADDRESS_REQUIREMENTS = TMEM_ADDRESS_REQUIREMENTS

type T_MEM_ADDRESS_REQUIREMENTS = TMEM_ADDRESS_REQUIREMENTS

type _MEM_ADDRESS_REQUIREMENTS = T_MEM_ADDRESS_REQUIREMENTS

type TPMEM_ADDRESS_REQUIREMENTS = uintptr

type PMEM_ADDRESS_REQUIREMENTS = TPMEM_ADDRESS_REQUIREMENTS

type TMEM_EXTENDED_PARAMETER_TYPE = int32

type MEM_EXTENDED_PARAMETER_TYPE = TMEM_EXTENDED_PARAMETER_TYPE

type _MEM_EXTENDED_PARAMETER_TYPE = int32

const _MemExtendedParameterInvalidType = 0
const _MemExtendedParameterAddressRequirements = 1
const _MemExtendedParameterNumaNode = 2
const _MemExtendedParameterPartitionHandle = 3
const _MemExtendedParameterUserPhysicalHandle = 4
const _MemExtendedParameterAttributeFlags = 5
const _MemExtendedParameterMax = 6

type TPMEM_EXTENDED_PARAMETER_TYPE = uintptr

type PMEM_EXTENDED_PARAMETER_TYPE = TPMEM_EXTENDED_PARAMETER_TYPE

type TMEM_EXTENDED_PARAMETER = struct {
	F__ccgo_align [0]uint32
	F__ccgo0_0    struct {
		F__ccgo_align [0]uint32
		F__ccgo0      uint64
	}
	F__ccgo1_8 struct {
		F__ccgo_align [0]uint32
		FPointer      [0]TPVOID
		FSize         [0]TSIZE_T
		FHandle       [0]THANDLE
		FULong        [0]TDWORD
		FULong64      TDWORD64
	}
}

type MEM_EXTENDED_PARAMETER = TMEM_EXTENDED_PARAMETER

type TPMEM_EXTENDED_PARAMETER = uintptr

type PMEM_EXTENDED_PARAMETER = TPMEM_EXTENDED_PARAMETER

type TMEM_EXTENDED_PARAMETER1 = struct {
	F__ccgo_align [0]uint32
	F__ccgo0_0    struct {
		F__ccgo_align [0]uint32
		F__ccgo0      uint64
	}
	F__ccgo1_8 struct {
		F__ccgo_align [0]uint32
		FPointer      [0]TPVOID
		FSize         [0]TSIZE_T
		FHandle       [0]THANDLE
		FULong        [0]TDWORD
		FULong64      TDWORD64
	}
}

type MEM_EXTENDED_PARAMETER1 = TMEM_EXTENDED_PARAMETER1

type TMEM_SECTION_EXTENDED_PARAMETER_TYPE = int32

type MEM_SECTION_EXTENDED_PARAMETER_TYPE = TMEM_SECTION_EXTENDED_PARAMETER_TYPE

type _MEM_SECTION_EXTENDED_PARAMETER_TYPE = int32

const _MemSectionExtendedParameterInvalidType = 0
const _MemSectionExtendedParameterUserPhysicalFlags = 1
const _MemSectionExtendedParameterNumaNode = 2
const _MemSectionExtendedParameterMax = 3

type TPMEM_SECTION_EXTENDED_PARAMETER_TYPE = uintptr

type PMEM_SECTION_EXTENDED_PARAMETER_TYPE = TPMEM_SECTION_EXTENDED_PARAMETER_TYPE

type TFILE_ID_128 = struct {
	FIdentifier [16]TBYTE
}

type FILE_ID_128 = TFILE_ID_128

type TPFILE_ID_128 = uintptr

type PFILE_ID_128 = TPFILE_ID_128

type TFILE_ID_1281 = struct {
	FIdentifier [16]TBYTE
}

type FILE_ID_1281 = TFILE_ID_1281

type TFILE_NOTIFY_INFORMATION = struct {
	FNextEntryOffset TDWORD
	FAction          TDWORD
	FFileNameLength  TDWORD
	FFileName        [1]TWCHAR
}

type FILE_NOTIFY_INFORMATION = TFILE_NOTIFY_INFORMATION

type T_FILE_NOTIFY_INFORMATION = TFILE_NOTIFY_INFORMATION

type _FILE_NOTIFY_INFORMATION = T_FILE_NOTIFY_INFORMATION

type TPFILE_NOTIFY_INFORMATION = uintptr

type PFILE_NOTIFY_INFORMATION = TPFILE_NOTIFY_INFORMATION

type TFILE_SEGMENT_ELEMENT = struct {
	F__ccgo_align [0]uint32
	FAlignment    [0]TULONGLONG
	FBuffer       TPVOID64
	F__ccgo_pad2  [4]byte
}

type FILE_SEGMENT_ELEMENT = TFILE_SEGMENT_ELEMENT

type T_FILE_SEGMENT_ELEMENT = TFILE_SEGMENT_ELEMENT

type _FILE_SEGMENT_ELEMENT = T_FILE_SEGMENT_ELEMENT

type TPFILE_SEGMENT_ELEMENT = uintptr

type PFILE_SEGMENT_ELEMENT = TPFILE_SEGMENT_ELEMENT

type TREPARSE_GUID_DATA_BUFFER = struct {
	FReparseTag           TDWORD
	FReparseDataLength    TWORD
	FReserved             TWORD
	FReparseGuid          TGUID
	FGenericReparseBuffer struct {
		FDataBuffer [1]TBYTE
	}
}

type REPARSE_GUID_DATA_BUFFER = TREPARSE_GUID_DATA_BUFFER

type T_REPARSE_GUID_DATA_BUFFER = TREPARSE_GUID_DATA_BUFFER

type _REPARSE_GUID_DATA_BUFFER = T_REPARSE_GUID_DATA_BUFFER

type TPREPARSE_GUID_DATA_BUFFER = uintptr

type PREPARSE_GUID_DATA_BUFFER = TPREPARSE_GUID_DATA_BUFFER

type TSCRUB_DATA_INPUT = struct {
	FSize          TDWORD
	FFlags         TDWORD
	FMaximumIos    TDWORD
	FReserved      [17]TDWORD
	FResumeContext [816]TBYTE
}

type SCRUB_DATA_INPUT = TSCRUB_DATA_INPUT

type T_SCRUB_DATA_INPUT = TSCRUB_DATA_INPUT

type _SCRUB_DATA_INPUT = T_SCRUB_DATA_INPUT

type TPSCRUB_DATA_INPUT = uintptr

type PSCRUB_DATA_INPUT = TPSCRUB_DATA_INPUT

type TSCRUB_DATA_OUTPUT = struct {
	F__ccgo_align          [0]uint32
	FSize                  TDWORD
	FFlags                 TDWORD
	FStatus                TDWORD
	F__ccgo_align3         [4]byte
	FErrorFileOffset       TULONGLONG
	FErrorLength           TULONGLONG
	FNumberOfBytesRepaired TULONGLONG
	FNumberOfBytesFailed   TULONGLONG
	FInternalFileReference TULONGLONG
	FReserved              [6]TDWORD
	FResumeContext         [816]TBYTE
}

type SCRUB_DATA_OUTPUT = TSCRUB_DATA_OUTPUT

type T_SCRUB_DATA_OUTPUT = TSCRUB_DATA_OUTPUT

type _SCRUB_DATA_OUTPUT = T_SCRUB_DATA_OUTPUT

type TPSCRUB_DATA_OUTPUT = uintptr

type PSCRUB_DATA_OUTPUT = TPSCRUB_DATA_OUTPUT

type TSYSTEM_POWER_STATE = int32

type SYSTEM_POWER_STATE = TSYSTEM_POWER_STATE

type __SYSTEM_POWER_STATE = int32

const _PowerSystemUnspecified = 0
const _PowerSystemWorking = 1
const _PowerSystemSleeping1 = 2
const _PowerSystemSleeping2 = 3
const _PowerSystemSleeping3 = 4
const _PowerSystemHibernate = 5
const _PowerSystemShutdown = 6
const _PowerSystemMaximum = 7

type TPSYSTEM_POWER_STATE = uintptr

type PSYSTEM_POWER_STATE = TPSYSTEM_POWER_STATE

type TPOWER_ACTION = int32

type POWER_ACTION = TPOWER_ACTION

const _PowerActionNone = 0
const _PowerActionReserved = 1
const _PowerActionSleep = 2
const _PowerActionHibernate = 3
const _PowerActionShutdown = 4
const _PowerActionShutdownReset = 5
const _PowerActionShutdownOff = 6
const _PowerActionWarmEject = 7

type TPPOWER_ACTION = uintptr

type PPOWER_ACTION = TPPOWER_ACTION

type TDEVICE_POWER_STATE = int32

type DEVICE_POWER_STATE = TDEVICE_POWER_STATE

type __DEVICE_POWER_STATE = int32

const _PowerDeviceUnspecified = 0
const _PowerDeviceD0 = 1
const _PowerDeviceD1 = 2
const _PowerDeviceD2 = 3
const _PowerDeviceD3 = 4
const _PowerDeviceMaximum = 5

type TPDEVICE_POWER_STATE = uintptr

type PDEVICE_POWER_STATE = TPDEVICE_POWER_STATE

type TMONITOR_DISPLAY_STATE = int32

type MONITOR_DISPLAY_STATE = TMONITOR_DISPLAY_STATE

type __MONITOR_DISPLAY_STATE = int32

const _PowerMonitorOff = 0
const _PowerMonitorOn = 1
const _PowerMonitorDim = 2

type TPMONITOR_DISPLAY_STATE = uintptr

type PMONITOR_DISPLAY_STATE = TPMONITOR_DISPLAY_STATE

type TUSER_ACTIVITY_PRESENCE = int32

type USER_ACTIVITY_PRESENCE = TUSER_ACTIVITY_PRESENCE

type __USER_ACTIVITY_PRESENCE = int32

const _PowerUserPresent = 0
const _PowerUserNotPresent = 1
const _PowerUserInactive = 2
const _PowerUserMaximum = 3
const _PowerUserInvalid = 3

type TPUSER_ACTIVITY_PRESENCE = uintptr

type PUSER_ACTIVITY_PRESENCE = TPUSER_ACTIVITY_PRESENCE

type TEXECUTION_STATE = uint32

type EXECUTION_STATE = TEXECUTION_STATE

type TPEXECUTION_STATE = uintptr

type PEXECUTION_STATE = TPEXECUTION_STATE

type TLATENCY_TIME = int32

type LATENCY_TIME = TLATENCY_TIME

const _LT_DONT_CARE = 0
const _LT_LOWEST_LATENCY = 1

type TPOWER_REQUEST_TYPE = int32

type POWER_REQUEST_TYPE = TPOWER_REQUEST_TYPE

type __POWER_REQUEST_TYPE = int32

const _PowerRequestDisplayRequired = 0
const _PowerRequestSystemRequired = 1
const _PowerRequestAwayModeRequired = 2
const _PowerRequestExecutionRequired = 3

type TPPOWER_REQUEST_TYPE = uintptr

type PPOWER_REQUEST_TYPE = TPPOWER_REQUEST_TYPE

type TCM_POWER_DATA = struct {
	FPD_Size                 TDWORD
	FPD_MostRecentPowerState TDEVICE_POWER_STATE
	FPD_Capabilities         TDWORD
	FPD_D1Latency            TDWORD
	FPD_D2Latency            TDWORD
	FPD_D3Latency            TDWORD
	FPD_PowerStateMapping    [7]TDEVICE_POWER_STATE
	FPD_DeepestSystemWake    TSYSTEM_POWER_STATE
}

type CM_POWER_DATA = TCM_POWER_DATA

type TCM_Power_Data_s = TCM_POWER_DATA

type CM_Power_Data_s = TCM_Power_Data_s

type TPCM_POWER_DATA = uintptr

type PCM_POWER_DATA = TPCM_POWER_DATA

type TPOWER_INFORMATION_LEVEL = int32

type POWER_INFORMATION_LEVEL = TPOWER_INFORMATION_LEVEL

const _SystemPowerPolicyAc = 0
const _SystemPowerPolicyDc = 1
const _VerifySystemPolicyAc = 2
const _VerifySystemPolicyDc = 3
const _SystemPowerCapabilities = 4
const _SystemBatteryState = 5
const _SystemPowerStateHandler = 6
const _ProcessorStateHandler = 7
const _SystemPowerPolicyCurrent = 8
const _AdministratorPowerPolicy = 9
const _SystemReserveHiberFile = 10
const _ProcessorInformation = 11
const _SystemPowerInformation = 12
const _ProcessorStateHandler2 = 13
const _LastWakeTime = 14
const _LastSleepTime = 15
const _SystemExecutionState = 16
const _SystemPowerStateNotifyHandler = 17
const _ProcessorPowerPolicyAc = 18
const _ProcessorPowerPolicyDc = 19
const _VerifyProcessorPowerPolicyAc = 20
const _VerifyProcessorPowerPolicyDc = 21
const _ProcessorPowerPolicyCurrent = 22
const _SystemPowerStateLogging = 23
const _SystemPowerLoggingEntry = 24
const _SetPowerSettingValue = 25
const _NotifyUserPowerSetting = 26
const _PowerInformationLevelUnused0 = 27
const _SystemMonitorHiberBootPowerOff = 28
const _SystemVideoState = 29
const _TraceApplicationPowerMessage = 30
const _TraceApplicationPowerMessageEnd = 31
const _ProcessorPerfStates = 32
const _ProcessorIdleStates = 33
const _ProcessorCap = 34
const _SystemWakeSource = 35
const _SystemHiberFileInformation = 36
const _TraceServicePowerMessage = 37
const _ProcessorLoad = 38
const _PowerShutdownNotification = 39
const _MonitorCapabilities = 40
const _SessionPowerInit = 41
const _SessionDisplayState = 42
const _PowerRequestCreate = 43
const _PowerRequestAction = 44
const _GetPowerRequestList = 45
const _ProcessorInformationEx = 46
const _NotifyUserModeLegacyPowerEvent = 47
const _GroupPark = 48
const _ProcessorIdleDomains = 49
const _WakeTimerList = 50
const _SystemHiberFileSize = 51
const _ProcessorIdleStatesHv = 52
const _ProcessorPerfStatesHv = 53
const _ProcessorPerfCapHv = 54
const _ProcessorSetIdle = 55
const _LogicalProcessorIdling = 56
const _UserPresence = 57
const _PowerSettingNotificationName = 58
const _GetPowerSettingValue = 59
const _IdleResiliency = 60
const _SessionRITState = 61
const _SessionConnectNotification = 62
const _SessionPowerCleanup = 63
const _SessionLockState = 64
const _SystemHiberbootState = 65
const _PlatformInformation = 66
const _PdcInvocation = 67
const _MonitorInvocation = 68
const _FirmwareTableInformationRegistered = 69
const _SetShutdownSelectedTime = 70
const _SuspendResumeInvocation = 71
const _PlmPowerRequestCreate = 72
const _ScreenOff = 73
const _CsDeviceNotification = 74
const _PlatformRole = 75
const _LastResumePerformance = 76
const _DisplayBurst = 77
const _ExitLatencySamplingPercentage = 78
const _ApplyLowPowerScenarioSettings = 79
const _PowerInformationLevelMaximum = 80

type TPOWER_USER_PRESENCE_TYPE = int32

type POWER_USER_PRESENCE_TYPE = TPOWER_USER_PRESENCE_TYPE

const _UserNotPresent = 0
const _UserPresent = 1
const _UserUnknown = 255

type TPPOWER_USER_PRESENCE_TYPE = uintptr

type PPOWER_USER_PRESENCE_TYPE = TPPOWER_USER_PRESENCE_TYPE

type TPOWER_USER_PRESENCE = struct {
	FUserPresence TPOWER_USER_PRESENCE_TYPE
}

type POWER_USER_PRESENCE = TPOWER_USER_PRESENCE

type T_POWER_USER_PRESENCE = TPOWER_USER_PRESENCE

type _POWER_USER_PRESENCE = T_POWER_USER_PRESENCE

type TPPOWER_USER_PRESENCE = uintptr

type PPOWER_USER_PRESENCE = TPPOWER_USER_PRESENCE

type TPOWER_SESSION_CONNECT = struct {
	FConnected TBOOLEAN
	FConsole   TBOOLEAN
}

type POWER_SESSION_CONNECT = TPOWER_SESSION_CONNECT

type T_POWER_SESSION_CONNECT = TPOWER_SESSION_CONNECT

type _POWER_SESSION_CONNECT = T_POWER_SESSION_CONNECT

type TPPOWER_SESSION_CONNECT = uintptr

type PPOWER_SESSION_CONNECT = TPPOWER_SESSION_CONNECT

type TPOWER_SESSION_TIMEOUTS = struct {
	FInputTimeout   TDWORD
	FDisplayTimeout TDWORD
}

type POWER_SESSION_TIMEOUTS = TPOWER_SESSION_TIMEOUTS

type T_POWER_SESSION_TIMEOUTS = TPOWER_SESSION_TIMEOUTS

type _POWER_SESSION_TIMEOUTS = T_POWER_SESSION_TIMEOUTS

type TPPOWER_SESSION_TIMEOUTS = uintptr

type PPOWER_SESSION_TIMEOUTS = TPPOWER_SESSION_TIMEOUTS

type TPOWER_SESSION_RIT_STATE = struct {
	FActive        TBOOLEAN
	FLastInputTime TDWORD
}

type POWER_SESSION_RIT_STATE = TPOWER_SESSION_RIT_STATE

type T_POWER_SESSION_RIT_STATE = TPOWER_SESSION_RIT_STATE

type _POWER_SESSION_RIT_STATE = T_POWER_SESSION_RIT_STATE

type TPPOWER_SESSION_RIT_STATE = uintptr

type PPOWER_SESSION_RIT_STATE = TPPOWER_SESSION_RIT_STATE

type TPOWER_SESSION_WINLOGON = struct {
	FSessionId TDWORD
	FConsole   TBOOLEAN
	FLocked    TBOOLEAN
}

type POWER_SESSION_WINLOGON = TPOWER_SESSION_WINLOGON

type T_POWER_SESSION_WINLOGON = TPOWER_SESSION_WINLOGON

type _POWER_SESSION_WINLOGON = T_POWER_SESSION_WINLOGON

type TPPOWER_SESSION_WINLOGON = uintptr

type PPOWER_SESSION_WINLOGON = TPPOWER_SESSION_WINLOGON

type TPOWER_IDLE_RESILIENCY = struct {
	FCoalescingTimeout    TDWORD
	FIdleResiliencyPeriod TDWORD
}

type POWER_IDLE_RESILIENCY = TPOWER_IDLE_RESILIENCY

type T_POWER_IDLE_RESILIENCY = TPOWER_IDLE_RESILIENCY

type _POWER_IDLE_RESILIENCY = T_POWER_IDLE_RESILIENCY

type TPPOWER_IDLE_RESILIENCY = uintptr

type PPOWER_IDLE_RESILIENCY = TPPOWER_IDLE_RESILIENCY

type TPOWER_MONITOR_REQUEST_REASON = int32

type POWER_MONITOR_REQUEST_REASON = TPOWER_MONITOR_REQUEST_REASON

const _MonitorRequestReasonUnknown = 0
const _MonitorRequestReasonPowerButton = 1
const _MonitorRequestReasonRemoteConnection = 2
const _MonitorRequestReasonScMonitorpower = 3
const _MonitorRequestReasonUserInput = 4
const _MonitorRequestReasonAcDcDisplayBurst = 5
const _MonitorRequestReasonUserDisplayBurst = 6
const _MonitorRequestReasonPoSetSystemState = 7
const _MonitorRequestReasonSetThreadExecutionState = 8
const _MonitorRequestReasonFullWake = 9
const _MonitorRequestReasonSessionUnlock = 10
const _MonitorRequestReasonScreenOffRequest = 11
const _MonitorRequestReasonIdleTimeout = 12
const _MonitorRequestReasonPolicyChange = 13
const _MonitorRequestReasonMax = 14

type TPOWER_MONITOR_INVOCATION = struct {
	FOn            TBOOLEAN
	FConsole       TBOOLEAN
	FRequestReason TPOWER_MONITOR_REQUEST_REASON
}

type POWER_MONITOR_INVOCATION = TPOWER_MONITOR_INVOCATION

type T_POWER_MONITOR_INVOCATION = TPOWER_MONITOR_INVOCATION

type _POWER_MONITOR_INVOCATION = T_POWER_MONITOR_INVOCATION

type TPPOWER_MONITOR_INVOCATION = uintptr

type PPOWER_MONITOR_INVOCATION = TPPOWER_MONITOR_INVOCATION

type TRESUME_PERFORMANCE = struct {
	F__ccgo_align            [0]uint32
	FPostTimeMs              TDWORD
	F__ccgo_align1           [4]byte
	FTotalResumeTimeMs       TULONGLONG
	FResumeCompleteTimestamp TULONGLONG
}

type RESUME_PERFORMANCE = TRESUME_PERFORMANCE

type T_RESUME_PERFORMANCE = TRESUME_PERFORMANCE

type _RESUME_PERFORMANCE = T_RESUME_PERFORMANCE

type TPRESUME_PERFORMANCE = uintptr

type PRESUME_PERFORMANCE = TPRESUME_PERFORMANCE

type TSYSTEM_POWER_CONDITION = int32

type SYSTEM_POWER_CONDITION = TSYSTEM_POWER_CONDITION

const _PoAc = 0
const _PoDc = 1
const _PoHot = 2
const _PoConditionMaximum = 3

type TSET_POWER_SETTING_VALUE = struct {
	FVersion        TDWORD
	FGuid           TGUID
	FPowerCondition TSYSTEM_POWER_CONDITION
	FDataLength     TDWORD
	FData           [1]TBYTE
}

type SET_POWER_SETTING_VALUE = TSET_POWER_SETTING_VALUE

type TPSET_POWER_SETTING_VALUE = uintptr

type PSET_POWER_SETTING_VALUE = TPSET_POWER_SETTING_VALUE

type TNOTIFY_USER_POWER_SETTING = struct {
	FGuid TGUID
}

type NOTIFY_USER_POWER_SETTING = TNOTIFY_USER_POWER_SETTING

type TPNOTIFY_USER_POWER_SETTING = uintptr

type PNOTIFY_USER_POWER_SETTING = TPNOTIFY_USER_POWER_SETTING

type TAPPLICATIONLAUNCH_SETTING_VALUE = struct {
	F__ccgo_align     [0]uint32
	FActivationTime   TLARGE_INTEGER
	FFlags            TDWORD
	FButtonInstanceID TDWORD
}

type APPLICATIONLAUNCH_SETTING_VALUE = TAPPLICATIONLAUNCH_SETTING_VALUE

type T_APPLICATIONLAUNCH_SETTING_VALUE = TAPPLICATIONLAUNCH_SETTING_VALUE

type _APPLICATIONLAUNCH_SETTING_VALUE = T_APPLICATIONLAUNCH_SETTING_VALUE

type TPAPPLICATIONLAUNCH_SETTING_VALUE = uintptr

type PAPPLICATIONLAUNCH_SETTING_VALUE = TPAPPLICATIONLAUNCH_SETTING_VALUE

type TPOWER_PLATFORM_ROLE = int32

type POWER_PLATFORM_ROLE = TPOWER_PLATFORM_ROLE

type __POWER_PLATFORM_ROLE = int32

const _PlatformRoleUnspecified = 0
const _PlatformRoleDesktop = 1
const _PlatformRoleMobile = 2
const _PlatformRoleWorkstation = 3
const _PlatformRoleEnterpriseServer = 4
const _PlatformRoleSOHOServer = 5
const _PlatformRoleAppliancePC = 6
const _PlatformRolePerformanceServer = 7
const _PlatformRoleSlate = 8
const _PlatformRoleMaximum = 9

type TPPOWER_PLATFORM_ROLE = uintptr

type PPOWER_PLATFORM_ROLE = TPPOWER_PLATFORM_ROLE

type TPOWER_PLATFORM_INFORMATION = struct {
	FAoAc TBOOLEAN
}

type POWER_PLATFORM_INFORMATION = TPOWER_PLATFORM_INFORMATION

type T_POWER_PLATFORM_INFORMATION = TPOWER_PLATFORM_INFORMATION

type _POWER_PLATFORM_INFORMATION = T_POWER_PLATFORM_INFORMATION

type TPPOWER_PLATFORM_INFORMATION = uintptr

type PPOWER_PLATFORM_INFORMATION = TPPOWER_PLATFORM_INFORMATION

type TBATTERY_REPORTING_SCALE = struct {
	FGranularity TDWORD
	FCapacity    TDWORD
}

type BATTERY_REPORTING_SCALE = TBATTERY_REPORTING_SCALE

type TPBATTERY_REPORTING_SCALE = uintptr

type PBATTERY_REPORTING_SCALE = TPBATTERY_REPORTING_SCALE

type TPPM_WMI_LEGACY_PERFSTATE = struct {
	FFrequency        TDWORD
	FFlags            TDWORD
	FPercentFrequency TDWORD
}

type PPM_WMI_LEGACY_PERFSTATE = TPPM_WMI_LEGACY_PERFSTATE

type TPPPM_WMI_LEGACY_PERFSTATE = uintptr

type PPPM_WMI_LEGACY_PERFSTATE = TPPPM_WMI_LEGACY_PERFSTATE

type TPPM_WMI_IDLE_STATE = struct {
	FLatency        TDWORD
	FPower          TDWORD
	FTimeCheck      TDWORD
	FPromotePercent TBYTE
	FDemotePercent  TBYTE
	FStateType      TBYTE
	FReserved       TBYTE
	FStateFlags     TDWORD
	FContext        TDWORD
	FIdleHandler    TDWORD
	FReserved1      TDWORD
}

type PPM_WMI_IDLE_STATE = TPPM_WMI_IDLE_STATE

type TPPPM_WMI_IDLE_STATE = uintptr

type PPPM_WMI_IDLE_STATE = TPPPM_WMI_IDLE_STATE

type TPPM_WMI_IDLE_STATES = struct {
	F__ccgo_align     [0]uint32
	FType             TDWORD
	FCount            TDWORD
	FTargetState      TDWORD
	FOldState         TDWORD
	FTargetProcessors TDWORD64
	FState            [1]TPPM_WMI_IDLE_STATE
}

type PPM_WMI_IDLE_STATES = TPPM_WMI_IDLE_STATES

type TPPPM_WMI_IDLE_STATES = uintptr

type PPPM_WMI_IDLE_STATES = TPPPM_WMI_IDLE_STATES

type TPPM_WMI_IDLE_STATES_EX = struct {
	FType             TDWORD
	FCount            TDWORD
	FTargetState      TDWORD
	FOldState         TDWORD
	FTargetProcessors TPVOID
	FState            [1]TPPM_WMI_IDLE_STATE
}

type PPM_WMI_IDLE_STATES_EX = TPPM_WMI_IDLE_STATES_EX

type TPPPM_WMI_IDLE_STATES_EX = uintptr

type PPPM_WMI_IDLE_STATES_EX = TPPPM_WMI_IDLE_STATES_EX

type TPPM_WMI_PERF_STATE = struct {
	F__ccgo_align     [0]uint32
	FFrequency        TDWORD
	FPower            TDWORD
	FPercentFrequency TBYTE
	FIncreaseLevel    TBYTE
	FDecreaseLevel    TBYTE
	FType             TBYTE
	FIncreaseTime     TDWORD
	FDecreaseTime     TDWORD
	F__ccgo_align8    [4]byte
	FControl          TDWORD64
	FStatus           TDWORD64
	FHitCount         TDWORD
	FReserved1        TDWORD
	FReserved2        TDWORD64
	FReserved3        TDWORD64
}

type PPM_WMI_PERF_STATE = TPPM_WMI_PERF_STATE

type TPPPM_WMI_PERF_STATE = uintptr

type PPPM_WMI_PERF_STATE = TPPPM_WMI_PERF_STATE

type TPPM_WMI_PERF_STATES = struct {
	F__ccgo_align      [0]uint32
	FCount             TDWORD
	FMaxFrequency      TDWORD
	FCurrentState      TDWORD
	FMaxPerfState      TDWORD
	FMinPerfState      TDWORD
	FLowestPerfState   TDWORD
	FThermalConstraint TDWORD
	FBusyAdjThreshold  TBYTE
	FPolicyType        TBYTE
	FType              TBYTE
	FReserved          TBYTE
	FTimerInterval     TDWORD
	F__ccgo_align12    [4]byte
	FTargetProcessors  TDWORD64
	FPStateHandler     TDWORD
	FPStateContext     TDWORD
	FTStateHandler     TDWORD
	FTStateContext     TDWORD
	FFeedbackHandler   TDWORD
	FReserved1         TDWORD
	FReserved2         TDWORD64
	FState             [1]TPPM_WMI_PERF_STATE
}

type PPM_WMI_PERF_STATES = TPPM_WMI_PERF_STATES

type TPPPM_WMI_PERF_STATES = uintptr

type PPPM_WMI_PERF_STATES = TPPPM_WMI_PERF_STATES

type TPPM_WMI_PERF_STATES_EX = struct {
	F__ccgo_align      [0]uint32
	FCount             TDWORD
	FMaxFrequency      TDWORD
	FCurrentState      TDWORD
	FMaxPerfState      TDWORD
	FMinPerfState      TDWORD
	FLowestPerfState   TDWORD
	FThermalConstraint TDWORD
	FBusyAdjThreshold  TBYTE
	FPolicyType        TBYTE
	FType              TBYTE
	FReserved          TBYTE
	FTimerInterval     TDWORD
	FTargetProcessors  TPVOID
	FPStateHandler     TDWORD
	FPStateContext     TDWORD
	FTStateHandler     TDWORD
	FTStateContext     TDWORD
	FFeedbackHandler   TDWORD
	FReserved1         TDWORD
	FReserved2         TDWORD64
	FState             [1]TPPM_WMI_PERF_STATE
}

type PPM_WMI_PERF_STATES_EX = TPPM_WMI_PERF_STATES_EX

type TPPPM_WMI_PERF_STATES_EX = uintptr

type PPPM_WMI_PERF_STATES_EX = TPPPM_WMI_PERF_STATES_EX

type TPPM_IDLE_STATE_ACCOUNTING = struct {
	F__ccgo_align       [0]uint32
	FIdleTransitions    TDWORD
	FFailedTransitions  TDWORD
	FInvalidBucketIndex TDWORD
	F__ccgo_align3      [4]byte
	FTotalTime          TDWORD64
	FIdleTimeBuckets    [6]TDWORD
}

type PPM_IDLE_STATE_ACCOUNTING = TPPM_IDLE_STATE_ACCOUNTING

type TPPPM_IDLE_STATE_ACCOUNTING = uintptr

type PPPM_IDLE_STATE_ACCOUNTING = TPPPM_IDLE_STATE_ACCOUNTING

type TPPM_IDLE_ACCOUNTING = struct {
	F__ccgo_align     [0]uint32
	FStateCount       TDWORD
	FTotalTransitions TDWORD
	FResetCount       TDWORD
	F__ccgo_align3    [4]byte
	FStartTime        TDWORD64
	FState            [1]TPPM_IDLE_STATE_ACCOUNTING
}

type PPM_IDLE_ACCOUNTING = TPPM_IDLE_ACCOUNTING

type TPPPM_IDLE_ACCOUNTING = uintptr

type PPPM_IDLE_ACCOUNTING = TPPPM_IDLE_ACCOUNTING

type TPPM_IDLE_STATE_BUCKET_EX = struct {
	F__ccgo_align [0]uint32
	FTotalTimeUs  TDWORD64
	FMinTimeUs    TDWORD
	FMaxTimeUs    TDWORD
	FCount        TDWORD
	F__ccgo_pad4  [4]byte
}

type PPM_IDLE_STATE_BUCKET_EX = TPPM_IDLE_STATE_BUCKET_EX

type TPPPM_IDLE_STATE_BUCKET_EX = uintptr

type PPPM_IDLE_STATE_BUCKET_EX = TPPPM_IDLE_STATE_BUCKET_EX

type TPPM_IDLE_STATE_ACCOUNTING_EX = struct {
	F__ccgo_align         [0]uint32
	FTotalTime            TDWORD64
	FIdleTransitions      TDWORD
	FFailedTransitions    TDWORD
	FInvalidBucketIndex   TDWORD
	FMinTimeUs            TDWORD
	FMaxTimeUs            TDWORD
	FCancelledTransitions TDWORD
	FIdleTimeBuckets      [16]TPPM_IDLE_STATE_BUCKET_EX
}

type PPM_IDLE_STATE_ACCOUNTING_EX = TPPM_IDLE_STATE_ACCOUNTING_EX

type TPPPM_IDLE_STATE_ACCOUNTING_EX = uintptr

type PPPM_IDLE_STATE_ACCOUNTING_EX = TPPPM_IDLE_STATE_ACCOUNTING_EX

type TPPM_IDLE_ACCOUNTING_EX = struct {
	F__ccgo_align     [0]uint32
	FStateCount       TDWORD
	FTotalTransitions TDWORD
	FResetCount       TDWORD
	FAbortCount       TDWORD
	FStartTime        TDWORD64
	FState            [1]TPPM_IDLE_STATE_ACCOUNTING_EX
}

type PPM_IDLE_ACCOUNTING_EX = TPPM_IDLE_ACCOUNTING_EX

type TPPPM_IDLE_ACCOUNTING_EX = uintptr

type PPPM_IDLE_ACCOUNTING_EX = TPPPM_IDLE_ACCOUNTING_EX

type TPPM_PERFSTATE_EVENT = struct {
	FState     TDWORD
	FStatus    TDWORD
	FLatency   TDWORD
	FSpeed     TDWORD
	FProcessor TDWORD
}

type PPM_PERFSTATE_EVENT = TPPM_PERFSTATE_EVENT

type TPPPM_PERFSTATE_EVENT = uintptr

type PPPM_PERFSTATE_EVENT = TPPPM_PERFSTATE_EVENT

type TPPM_PERFSTATE_DOMAIN_EVENT = struct {
	F__ccgo_align  [0]uint32
	FState         TDWORD
	FLatency       TDWORD
	FSpeed         TDWORD
	F__ccgo_align3 [4]byte
	FProcessors    TDWORD64
}

type PPM_PERFSTATE_DOMAIN_EVENT = TPPM_PERFSTATE_DOMAIN_EVENT

type TPPPM_PERFSTATE_DOMAIN_EVENT = uintptr

type PPPM_PERFSTATE_DOMAIN_EVENT = TPPPM_PERFSTATE_DOMAIN_EVENT

type TPPM_IDLESTATE_EVENT = struct {
	F__ccgo_align [0]uint32
	FNewState     TDWORD
	FOldState     TDWORD
	FProcessors   TDWORD64
}

type PPM_IDLESTATE_EVENT = TPPM_IDLESTATE_EVENT

type TPPPM_IDLESTATE_EVENT = uintptr

type PPPM_IDLESTATE_EVENT = TPPPM_IDLESTATE_EVENT

type TPPM_THERMALCHANGE_EVENT = struct {
	F__ccgo_align      [0]uint32
	FThermalConstraint TDWORD
	F__ccgo_align1     [4]byte
	FProcessors        TDWORD64
}

type PPM_THERMALCHANGE_EVENT = TPPM_THERMALCHANGE_EVENT

type TPPPM_THERMALCHANGE_EVENT = uintptr

type PPPM_THERMALCHANGE_EVENT = TPPPM_THERMALCHANGE_EVENT

type TPPM_THERMAL_POLICY_EVENT = struct {
	F__ccgo_align  [0]uint32
	FMode          TBYTE
	F__ccgo_align1 [7]byte
	FProcessors    TDWORD64
}

type PPM_THERMAL_POLICY_EVENT = TPPM_THERMAL_POLICY_EVENT

type TPPPM_THERMAL_POLICY_EVENT = uintptr

type PPPM_THERMAL_POLICY_EVENT = TPPPM_THERMAL_POLICY_EVENT

type TPOWER_ACTION_POLICY = struct {
	FAction    TPOWER_ACTION
	FFlags     TDWORD
	FEventCode TDWORD
}

type POWER_ACTION_POLICY = TPOWER_ACTION_POLICY

type TPPOWER_ACTION_POLICY = uintptr

type PPOWER_ACTION_POLICY = TPPOWER_ACTION_POLICY

type TPROCESSOR_IDLESTATE_INFO = struct {
	FTimeCheck      TDWORD
	FDemotePercent  TBYTE
	FPromotePercent TBYTE
	FSpare          [2]TBYTE
}

type PROCESSOR_IDLESTATE_INFO = TPROCESSOR_IDLESTATE_INFO

type TPPROCESSOR_IDLESTATE_INFO = uintptr

type PPROCESSOR_IDLESTATE_INFO = TPPROCESSOR_IDLESTATE_INFO

type TSYSTEM_POWER_LEVEL = struct {
	FEnable         TBOOLEAN
	FSpare          [3]TBYTE
	FBatteryLevel   TDWORD
	FPowerPolicy    TPOWER_ACTION_POLICY
	FMinSystemState TSYSTEM_POWER_STATE
}

type SYSTEM_POWER_LEVEL = TSYSTEM_POWER_LEVEL

type TPSYSTEM_POWER_LEVEL = uintptr

type PSYSTEM_POWER_LEVEL = TPSYSTEM_POWER_LEVEL

type TSYSTEM_POWER_POLICY = struct {
	FRevision                    TDWORD
	FPowerButton                 TPOWER_ACTION_POLICY
	FSleepButton                 TPOWER_ACTION_POLICY
	FLidClose                    TPOWER_ACTION_POLICY
	FLidOpenWake                 TSYSTEM_POWER_STATE
	FReserved                    TDWORD
	FIdle                        TPOWER_ACTION_POLICY
	FIdleTimeout                 TDWORD
	FIdleSensitivity             TBYTE
	FDynamicThrottle             TBYTE
	FSpare2                      [2]TBYTE
	FMinSleep                    TSYSTEM_POWER_STATE
	FMaxSleep                    TSYSTEM_POWER_STATE
	FReducedLatencySleep         TSYSTEM_POWER_STATE
	FWinLogonFlags               TDWORD
	FSpare3                      TDWORD
	FDozeS4Timeout               TDWORD
	FBroadcastCapacityResolution TDWORD
	FDischargePolicy             [4]TSYSTEM_POWER_LEVEL
	FVideoTimeout                TDWORD
	FVideoDimDisplay             TBOOLEAN
	FVideoReserved               [3]TDWORD
	FSpindownTimeout             TDWORD
	FOptimizeForPower            TBOOLEAN
	FFanThrottleTolerance        TBYTE
	FForcedThrottle              TBYTE
	FMinThrottle                 TBYTE
	FOverThrottled               TPOWER_ACTION_POLICY
}

type SYSTEM_POWER_POLICY = TSYSTEM_POWER_POLICY

type T_SYSTEM_POWER_POLICY = TSYSTEM_POWER_POLICY

type _SYSTEM_POWER_POLICY = T_SYSTEM_POWER_POLICY

type TPSYSTEM_POWER_POLICY = uintptr

type PSYSTEM_POWER_POLICY = TPSYSTEM_POWER_POLICY

type TPROCESSOR_IDLESTATE_POLICY = struct {
	FRevision TWORD
	FFlags    struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint16
		}
		FAsWORD TWORD
	}
	FPolicyCount TDWORD
	FPolicy      [3]TPROCESSOR_IDLESTATE_INFO
}

type PROCESSOR_IDLESTATE_POLICY = TPROCESSOR_IDLESTATE_POLICY

type TPPROCESSOR_IDLESTATE_POLICY = uintptr

type PPROCESSOR_IDLESTATE_POLICY = TPPROCESSOR_IDLESTATE_POLICY

type TPROCESSOR_POWER_POLICY_INFO = struct {
	FTimeCheck      TDWORD
	FDemoteLimit    TDWORD
	FPromoteLimit   TDWORD
	FDemotePercent  TBYTE
	FPromotePercent TBYTE
	FSpare          [2]TBYTE
	F__ccgo16       uint32
}

type PROCESSOR_POWER_POLICY_INFO = TPROCESSOR_POWER_POLICY_INFO

type T_PROCESSOR_POWER_POLICY_INFO = TPROCESSOR_POWER_POLICY_INFO

type _PROCESSOR_POWER_POLICY_INFO = T_PROCESSOR_POWER_POLICY_INFO

type TPPROCESSOR_POWER_POLICY_INFO = uintptr

type PPROCESSOR_POWER_POLICY_INFO = TPPROCESSOR_POWER_POLICY_INFO

type TPROCESSOR_POWER_POLICY = struct {
	FRevision        TDWORD
	FDynamicThrottle TBYTE
	FSpare           [3]TBYTE
	F__ccgo8         uint32
	FPolicyCount     TDWORD
	FPolicy          [3]TPROCESSOR_POWER_POLICY_INFO
}

type PROCESSOR_POWER_POLICY = TPROCESSOR_POWER_POLICY

type T_PROCESSOR_POWER_POLICY = TPROCESSOR_POWER_POLICY

type _PROCESSOR_POWER_POLICY = T_PROCESSOR_POWER_POLICY

type TPPROCESSOR_POWER_POLICY = uintptr

type PPROCESSOR_POWER_POLICY = TPPROCESSOR_POWER_POLICY

type TPROCESSOR_PERFSTATE_POLICY = struct {
	FRevision         TDWORD
	FMaxThrottle      TBYTE
	FMinThrottle      TBYTE
	FBusyAdjThreshold TBYTE
	F__ccgo4_7        struct {
		FFlags [0]struct {
			F__ccgo1_0 [0]struct {
				F__ccgo0 uint8
			}
			FAsBYTE TBYTE
		}
		FSpare TBYTE
	}
	FTimeCheck       TDWORD
	FIncreaseTime    TDWORD
	FDecreaseTime    TDWORD
	FIncreasePercent TDWORD
	FDecreasePercent TDWORD
}

type PROCESSOR_PERFSTATE_POLICY = TPROCESSOR_PERFSTATE_POLICY

type TPPROCESSOR_PERFSTATE_POLICY = uintptr

type PPROCESSOR_PERFSTATE_POLICY = TPPROCESSOR_PERFSTATE_POLICY

type TADMINISTRATOR_POWER_POLICY = struct {
	FMinSleep           TSYSTEM_POWER_STATE
	FMaxSleep           TSYSTEM_POWER_STATE
	FMinVideoTimeout    TDWORD
	FMaxVideoTimeout    TDWORD
	FMinSpindownTimeout TDWORD
	FMaxSpindownTimeout TDWORD
}

type ADMINISTRATOR_POWER_POLICY = TADMINISTRATOR_POWER_POLICY

type T_ADMINISTRATOR_POWER_POLICY = TADMINISTRATOR_POWER_POLICY

type _ADMINISTRATOR_POWER_POLICY = T_ADMINISTRATOR_POWER_POLICY

type TPADMINISTRATOR_POWER_POLICY = uintptr

type PADMINISTRATOR_POWER_POLICY = TPADMINISTRATOR_POWER_POLICY

type TSYSTEM_POWER_CAPABILITIES = struct {
	FPowerButtonPresent     TBOOLEAN
	FSleepButtonPresent     TBOOLEAN
	FLidPresent             TBOOLEAN
	FSystemS1               TBOOLEAN
	FSystemS2               TBOOLEAN
	FSystemS3               TBOOLEAN
	FSystemS4               TBOOLEAN
	FSystemS5               TBOOLEAN
	FHiberFilePresent       TBOOLEAN
	FFullWake               TBOOLEAN
	FVideoDimPresent        TBOOLEAN
	FApmPresent             TBOOLEAN
	FUpsPresent             TBOOLEAN
	FThermalControl         TBOOLEAN
	FProcessorThrottle      TBOOLEAN
	FProcessorMinThrottle   TBYTE
	FProcessorMaxThrottle   TBYTE
	FFastSystemS4           TBOOLEAN
	Fspare2                 [3]TBYTE
	FDiskSpinDown           TBOOLEAN
	Fspare3                 [8]TBYTE
	FSystemBatteriesPresent TBOOLEAN
	FBatteriesAreShortTerm  TBOOLEAN
	FBatteryScale           [3]TBATTERY_REPORTING_SCALE
	FAcOnLineWake           TSYSTEM_POWER_STATE
	FSoftLidWake            TSYSTEM_POWER_STATE
	FRtcWake                TSYSTEM_POWER_STATE
	FMinDeviceWakeState     TSYSTEM_POWER_STATE
	FDefaultLowLatencyWake  TSYSTEM_POWER_STATE
}

type SYSTEM_POWER_CAPABILITIES = TSYSTEM_POWER_CAPABILITIES

type TPSYSTEM_POWER_CAPABILITIES = uintptr

type PSYSTEM_POWER_CAPABILITIES = TPSYSTEM_POWER_CAPABILITIES

type TSYSTEM_BATTERY_STATE = struct {
	FAcOnLine          TBOOLEAN
	FBatteryPresent    TBOOLEAN
	FCharging          TBOOLEAN
	FDischarging       TBOOLEAN
	FSpare1            [4]TBOOLEAN
	FMaxCapacity       TDWORD
	FRemainingCapacity TDWORD
	FRate              TDWORD
	FEstimatedTime     TDWORD
	FDefaultAlert1     TDWORD
	FDefaultAlert2     TDWORD
}

type SYSTEM_BATTERY_STATE = TSYSTEM_BATTERY_STATE

type TPSYSTEM_BATTERY_STATE = uintptr

type PSYSTEM_BATTERY_STATE = TPSYSTEM_BATTERY_STATE

type TIMAGE_DOS_HEADER = struct {
	Fe_magic    TWORD
	Fe_cblp     TWORD
	Fe_cp       TWORD
	Fe_crlc     TWORD
	Fe_cparhdr  TWORD
	Fe_minalloc TWORD
	Fe_maxalloc TWORD
	Fe_ss       TWORD
	Fe_sp       TWORD
	Fe_csum     TWORD
	Fe_ip       TWORD
	Fe_cs       TWORD
	Fe_lfarlc   TWORD
	Fe_ovno     TWORD
	Fe_res      [4]TWORD
	Fe_oemid    TWORD
	Fe_oeminfo  TWORD
	Fe_res2     [10]TWORD
	Fe_lfanew   TLONG
}

type IMAGE_DOS_HEADER = TIMAGE_DOS_HEADER

type T_IMAGE_DOS_HEADER = TIMAGE_DOS_HEADER

type _IMAGE_DOS_HEADER = T_IMAGE_DOS_HEADER

type TPIMAGE_DOS_HEADER = uintptr

type PIMAGE_DOS_HEADER = TPIMAGE_DOS_HEADER

type TIMAGE_OS2_HEADER = struct {
	Fne_magic        TWORD
	Fne_ver          TCHAR
	Fne_rev          TCHAR
	Fne_enttab       TWORD
	Fne_cbenttab     TWORD
	Fne_crc          TLONG
	Fne_flags        TWORD
	Fne_autodata     TWORD
	Fne_heap         TWORD
	Fne_stack        TWORD
	Fne_csip         TLONG
	Fne_sssp         TLONG
	Fne_cseg         TWORD
	Fne_cmod         TWORD
	Fne_cbnrestab    TWORD
	Fne_segtab       TWORD
	Fne_rsrctab      TWORD
	Fne_restab       TWORD
	Fne_modtab       TWORD
	Fne_imptab       TWORD
	Fne_nrestab      TLONG
	Fne_cmovent      TWORD
	Fne_align        TWORD
	Fne_cres         TWORD
	Fne_exetyp       TBYTE
	Fne_flagsothers  TBYTE
	Fne_pretthunks   TWORD
	Fne_psegrefbytes TWORD
	Fne_swaparea     TWORD
	Fne_expver       TWORD
}

type IMAGE_OS2_HEADER = TIMAGE_OS2_HEADER

type T_IMAGE_OS2_HEADER = TIMAGE_OS2_HEADER

type _IMAGE_OS2_HEADER = T_IMAGE_OS2_HEADER

type TPIMAGE_OS2_HEADER = uintptr

type PIMAGE_OS2_HEADER = TPIMAGE_OS2_HEADER

type TIMAGE_VXD_HEADER = struct {
	Fe32_magic        TWORD
	Fe32_border       TBYTE
	Fe32_worder       TBYTE
	Fe32_level        TDWORD
	Fe32_cpu          TWORD
	Fe32_os           TWORD
	Fe32_ver          TDWORD
	Fe32_mflags       TDWORD
	Fe32_mpages       TDWORD
	Fe32_startobj     TDWORD
	Fe32_eip          TDWORD
	Fe32_stackobj     TDWORD
	Fe32_esp          TDWORD
	Fe32_pagesize     TDWORD
	Fe32_lastpagesize TDWORD
	Fe32_fixupsize    TDWORD
	Fe32_fixupsum     TDWORD
	Fe32_ldrsize      TDWORD
	Fe32_ldrsum       TDWORD
	Fe32_objtab       TDWORD
	Fe32_objcnt       TDWORD
	Fe32_objmap       TDWORD
	Fe32_itermap      TDWORD
	Fe32_rsrctab      TDWORD
	Fe32_rsrccnt      TDWORD
	Fe32_restab       TDWORD
	Fe32_enttab       TDWORD
	Fe32_dirtab       TDWORD
	Fe32_dircnt       TDWORD
	Fe32_fpagetab     TDWORD
	Fe32_frectab      TDWORD
	Fe32_impmod       TDWORD
	Fe32_impmodcnt    TDWORD
	Fe32_impproc      TDWORD
	Fe32_pagesum      TDWORD
	Fe32_datapage     TDWORD
	Fe32_preload      TDWORD
	Fe32_nrestab      TDWORD
	Fe32_cbnrestab    TDWORD
	Fe32_nressum      TDWORD
	Fe32_autodata     TDWORD
	Fe32_debuginfo    TDWORD
	Fe32_debuglen     TDWORD
	Fe32_instpreload  TDWORD
	Fe32_instdemand   TDWORD
	Fe32_heapsize     TDWORD
	Fe32_res3         [12]TBYTE
	Fe32_winresoff    TDWORD
	Fe32_winreslen    TDWORD
	Fe32_devid        TWORD
	Fe32_ddkver       TWORD
}

type IMAGE_VXD_HEADER = TIMAGE_VXD_HEADER

type T_IMAGE_VXD_HEADER = TIMAGE_VXD_HEADER

type _IMAGE_VXD_HEADER = T_IMAGE_VXD_HEADER

type TPIMAGE_VXD_HEADER = uintptr

type PIMAGE_VXD_HEADER = TPIMAGE_VXD_HEADER

type TIMAGE_FILE_HEADER = struct {
	FMachine              TWORD
	FNumberOfSections     TWORD
	FTimeDateStamp        TDWORD
	FPointerToSymbolTable TDWORD
	FNumberOfSymbols      TDWORD
	FSizeOfOptionalHeader TWORD
	FCharacteristics      TWORD
}

type IMAGE_FILE_HEADER = TIMAGE_FILE_HEADER

type T_IMAGE_FILE_HEADER = TIMAGE_FILE_HEADER

type _IMAGE_FILE_HEADER = T_IMAGE_FILE_HEADER

type TPIMAGE_FILE_HEADER = uintptr

type PIMAGE_FILE_HEADER = TPIMAGE_FILE_HEADER

type TIMAGE_DATA_DIRECTORY = struct {
	FVirtualAddress TDWORD
	FSize           TDWORD
}

type IMAGE_DATA_DIRECTORY = TIMAGE_DATA_DIRECTORY

type T_IMAGE_DATA_DIRECTORY = TIMAGE_DATA_DIRECTORY

type _IMAGE_DATA_DIRECTORY = T_IMAGE_DATA_DIRECTORY

type TPIMAGE_DATA_DIRECTORY = uintptr

type PIMAGE_DATA_DIRECTORY = TPIMAGE_DATA_DIRECTORY

type TIMAGE_OPTIONAL_HEADER32 = struct {
	FMagic                       TWORD
	FMajorLinkerVersion          TBYTE
	FMinorLinkerVersion          TBYTE
	FSizeOfCode                  TDWORD
	FSizeOfInitializedData       TDWORD
	FSizeOfUninitializedData     TDWORD
	FAddressOfEntryPoint         TDWORD
	FBaseOfCode                  TDWORD
	FBaseOfData                  TDWORD
	FImageBase                   TDWORD
	FSectionAlignment            TDWORD
	FFileAlignment               TDWORD
	FMajorOperatingSystemVersion TWORD
	FMinorOperatingSystemVersion TWORD
	FMajorImageVersion           TWORD
	FMinorImageVersion           TWORD
	FMajorSubsystemVersion       TWORD
	FMinorSubsystemVersion       TWORD
	FWin32VersionValue           TDWORD
	FSizeOfImage                 TDWORD
	FSizeOfHeaders               TDWORD
	FCheckSum                    TDWORD
	FSubsystem                   TWORD
	FDllCharacteristics          TWORD
	FSizeOfStackReserve          TDWORD
	FSizeOfStackCommit           TDWORD
	FSizeOfHeapReserve           TDWORD
	FSizeOfHeapCommit            TDWORD
	FLoaderFlags                 TDWORD
	FNumberOfRvaAndSizes         TDWORD
	FDataDirectory               [16]TIMAGE_DATA_DIRECTORY
}

type IMAGE_OPTIONAL_HEADER32 = TIMAGE_OPTIONAL_HEADER32

type T_IMAGE_OPTIONAL_HEADER = TIMAGE_OPTIONAL_HEADER32

type _IMAGE_OPTIONAL_HEADER = T_IMAGE_OPTIONAL_HEADER

type TPIMAGE_OPTIONAL_HEADER32 = uintptr

type PIMAGE_OPTIONAL_HEADER32 = TPIMAGE_OPTIONAL_HEADER32

type TIMAGE_ROM_OPTIONAL_HEADER = struct {
	FMagic                   TWORD
	FMajorLinkerVersion      TBYTE
	FMinorLinkerVersion      TBYTE
	FSizeOfCode              TDWORD
	FSizeOfInitializedData   TDWORD
	FSizeOfUninitializedData TDWORD
	FAddressOfEntryPoint     TDWORD
	FBaseOfCode              TDWORD
	FBaseOfData              TDWORD
	FBaseOfBss               TDWORD
	FGprMask                 TDWORD
	FCprMask                 [4]TDWORD
	FGpValue                 TDWORD
}

type IMAGE_ROM_OPTIONAL_HEADER = TIMAGE_ROM_OPTIONAL_HEADER

type T_IMAGE_ROM_OPTIONAL_HEADER = TIMAGE_ROM_OPTIONAL_HEADER

type _IMAGE_ROM_OPTIONAL_HEADER = T_IMAGE_ROM_OPTIONAL_HEADER

type TPIMAGE_ROM_OPTIONAL_HEADER = uintptr

type PIMAGE_ROM_OPTIONAL_HEADER = TPIMAGE_ROM_OPTIONAL_HEADER

type TIMAGE_OPTIONAL_HEADER64 = struct {
	F__ccgo_align                [0]uint32
	FMagic                       TWORD
	FMajorLinkerVersion          TBYTE
	FMinorLinkerVersion          TBYTE
	FSizeOfCode                  TDWORD
	FSizeOfInitializedData       TDWORD
	FSizeOfUninitializedData     TDWORD
	FAddressOfEntryPoint         TDWORD
	FBaseOfCode                  TDWORD
	FImageBase                   TULONGLONG
	FSectionAlignment            TDWORD
	FFileAlignment               TDWORD
	FMajorOperatingSystemVersion TWORD
	FMinorOperatingSystemVersion TWORD
	FMajorImageVersion           TWORD
	FMinorImageVersion           TWORD
	FMajorSubsystemVersion       TWORD
	FMinorSubsystemVersion       TWORD
	FWin32VersionValue           TDWORD
	FSizeOfImage                 TDWORD
	FSizeOfHeaders               TDWORD
	FCheckSum                    TDWORD
	FSubsystem                   TWORD
	FDllCharacteristics          TWORD
	FSizeOfStackReserve          TULONGLONG
	FSizeOfStackCommit           TULONGLONG
	FSizeOfHeapReserve           TULONGLONG
	FSizeOfHeapCommit            TULONGLONG
	FLoaderFlags                 TDWORD
	FNumberOfRvaAndSizes         TDWORD
	FDataDirectory               [16]TIMAGE_DATA_DIRECTORY
}

type IMAGE_OPTIONAL_HEADER64 = TIMAGE_OPTIONAL_HEADER64

type T_IMAGE_OPTIONAL_HEADER64 = TIMAGE_OPTIONAL_HEADER64

type _IMAGE_OPTIONAL_HEADER64 = T_IMAGE_OPTIONAL_HEADER64

type TPIMAGE_OPTIONAL_HEADER64 = uintptr

type PIMAGE_OPTIONAL_HEADER64 = TPIMAGE_OPTIONAL_HEADER64

type TIMAGE_OPTIONAL_HEADER = struct {
	FMagic                       TWORD
	FMajorLinkerVersion          TBYTE
	FMinorLinkerVersion          TBYTE
	FSizeOfCode                  TDWORD
	FSizeOfInitializedData       TDWORD
	FSizeOfUninitializedData     TDWORD
	FAddressOfEntryPoint         TDWORD
	FBaseOfCode                  TDWORD
	FBaseOfData                  TDWORD
	FImageBase                   TDWORD
	FSectionAlignment            TDWORD
	FFileAlignment               TDWORD
	FMajorOperatingSystemVersion TWORD
	FMinorOperatingSystemVersion TWORD
	FMajorImageVersion           TWORD
	FMinorImageVersion           TWORD
	FMajorSubsystemVersion       TWORD
	FMinorSubsystemVersion       TWORD
	FWin32VersionValue           TDWORD
	FSizeOfImage                 TDWORD
	FSizeOfHeaders               TDWORD
	FCheckSum                    TDWORD
	FSubsystem                   TWORD
	FDllCharacteristics          TWORD
	FSizeOfStackReserve          TDWORD
	FSizeOfStackCommit           TDWORD
	FSizeOfHeapReserve           TDWORD
	FSizeOfHeapCommit            TDWORD
	FLoaderFlags                 TDWORD
	FNumberOfRvaAndSizes         TDWORD
	FDataDirectory               [16]TIMAGE_DATA_DIRECTORY
}

type IMAGE_OPTIONAL_HEADER = TIMAGE_OPTIONAL_HEADER

type TPIMAGE_OPTIONAL_HEADER = uintptr

type PIMAGE_OPTIONAL_HEADER = TPIMAGE_OPTIONAL_HEADER

type TIMAGE_NT_HEADERS64 = struct {
	F__ccgo_align   [0]uint32
	FSignature      TDWORD
	FFileHeader     TIMAGE_FILE_HEADER
	FOptionalHeader TIMAGE_OPTIONAL_HEADER64
}

type IMAGE_NT_HEADERS64 = TIMAGE_NT_HEADERS64

type T_IMAGE_NT_HEADERS64 = TIMAGE_NT_HEADERS64

type _IMAGE_NT_HEADERS64 = T_IMAGE_NT_HEADERS64

type TPIMAGE_NT_HEADERS64 = uintptr

type PIMAGE_NT_HEADERS64 = TPIMAGE_NT_HEADERS64

type TIMAGE_NT_HEADERS32 = struct {
	FSignature      TDWORD
	FFileHeader     TIMAGE_FILE_HEADER
	FOptionalHeader TIMAGE_OPTIONAL_HEADER32
}

type IMAGE_NT_HEADERS32 = TIMAGE_NT_HEADERS32

type T_IMAGE_NT_HEADERS = TIMAGE_NT_HEADERS32

type _IMAGE_NT_HEADERS = T_IMAGE_NT_HEADERS

type TPIMAGE_NT_HEADERS32 = uintptr

type PIMAGE_NT_HEADERS32 = TPIMAGE_NT_HEADERS32

type TIMAGE_ROM_HEADERS = struct {
	FFileHeader     TIMAGE_FILE_HEADER
	FOptionalHeader TIMAGE_ROM_OPTIONAL_HEADER
}

type IMAGE_ROM_HEADERS = TIMAGE_ROM_HEADERS

type T_IMAGE_ROM_HEADERS = TIMAGE_ROM_HEADERS

type _IMAGE_ROM_HEADERS = T_IMAGE_ROM_HEADERS

type TPIMAGE_ROM_HEADERS = uintptr

type PIMAGE_ROM_HEADERS = TPIMAGE_ROM_HEADERS

type TIMAGE_NT_HEADERS = struct {
	FSignature      TDWORD
	FFileHeader     TIMAGE_FILE_HEADER
	FOptionalHeader TIMAGE_OPTIONAL_HEADER32
}

type IMAGE_NT_HEADERS = TIMAGE_NT_HEADERS

type TPIMAGE_NT_HEADERS = uintptr

type PIMAGE_NT_HEADERS = TPIMAGE_NT_HEADERS

type TANON_OBJECT_HEADER = struct {
	FSig1          TWORD
	FSig2          TWORD
	FVersion       TWORD
	FMachine       TWORD
	FTimeDateStamp TDWORD
	FClassID       TCLSID
	FSizeOfData    TDWORD
}

type ANON_OBJECT_HEADER = TANON_OBJECT_HEADER

type TANON_OBJECT_HEADER_V2 = struct {
	FSig1           TWORD
	FSig2           TWORD
	FVersion        TWORD
	FMachine        TWORD
	FTimeDateStamp  TDWORD
	FClassID        TCLSID
	FSizeOfData     TDWORD
	FFlags          TDWORD
	FMetaDataSize   TDWORD
	FMetaDataOffset TDWORD
}

type ANON_OBJECT_HEADER_V2 = TANON_OBJECT_HEADER_V2

type TANON_OBJECT_HEADER_BIGOBJ = struct {
	FSig1                 TWORD
	FSig2                 TWORD
	FVersion              TWORD
	FMachine              TWORD
	FTimeDateStamp        TDWORD
	FClassID              TCLSID
	FSizeOfData           TDWORD
	FFlags                TDWORD
	FMetaDataSize         TDWORD
	FMetaDataOffset       TDWORD
	FNumberOfSections     TDWORD
	FPointerToSymbolTable TDWORD
	FNumberOfSymbols      TDWORD
}

type ANON_OBJECT_HEADER_BIGOBJ = TANON_OBJECT_HEADER_BIGOBJ

type TIMAGE_SECTION_HEADER = struct {
	FName [8]TBYTE
	FMisc struct {
		FVirtualSize     [0]TDWORD
		FPhysicalAddress TDWORD
	}
	FVirtualAddress       TDWORD
	FSizeOfRawData        TDWORD
	FPointerToRawData     TDWORD
	FPointerToRelocations TDWORD
	FPointerToLinenumbers TDWORD
	FNumberOfRelocations  TWORD
	FNumberOfLinenumbers  TWORD
	FCharacteristics      TDWORD
}

type IMAGE_SECTION_HEADER = TIMAGE_SECTION_HEADER

type T_IMAGE_SECTION_HEADER = TIMAGE_SECTION_HEADER

type _IMAGE_SECTION_HEADER = T_IMAGE_SECTION_HEADER

type TPIMAGE_SECTION_HEADER = uintptr

type PIMAGE_SECTION_HEADER = TPIMAGE_SECTION_HEADER

type TIMAGE_SYMBOL = struct {
	FN struct {
		FName [0]struct {
			FShort TDWORD
			FLong  TDWORD
		}
		FLongName  [0][2]TDWORD
		FShortName [8]TBYTE
	}
	FValue              TDWORD
	FSectionNumber      TSHORT
	FType               TWORD
	FStorageClass       TBYTE
	FNumberOfAuxSymbols TBYTE
}

type IMAGE_SYMBOL = TIMAGE_SYMBOL

type T_IMAGE_SYMBOL = TIMAGE_SYMBOL

type _IMAGE_SYMBOL = T_IMAGE_SYMBOL

type TPIMAGE_SYMBOL = uintptr

type PIMAGE_SYMBOL = TPIMAGE_SYMBOL

type TIMAGE_SYMBOL_EX = struct {
	FN struct {
		FName [0]struct {
			FShort TDWORD
			FLong  TDWORD
		}
		FLongName  [0][2]TDWORD
		FShortName [8]TBYTE
	}
	FValue              TDWORD
	FSectionNumber      TLONG
	FType               TWORD
	FStorageClass       TBYTE
	FNumberOfAuxSymbols TBYTE
}

type IMAGE_SYMBOL_EX = TIMAGE_SYMBOL_EX

type T_IMAGE_SYMBOL_EX = TIMAGE_SYMBOL_EX

type _IMAGE_SYMBOL_EX = T_IMAGE_SYMBOL_EX

type TPIMAGE_SYMBOL_EX = uintptr

type PIMAGE_SYMBOL_EX = TPIMAGE_SYMBOL_EX

type TIMAGE_AUX_SYMBOL_TOKEN_DEF = struct {
	FbAuxType         TBYTE
	FbReserved        TBYTE
	FSymbolTableIndex TDWORD
	FrgbReserved      [12]TBYTE
}

type IMAGE_AUX_SYMBOL_TOKEN_DEF = TIMAGE_AUX_SYMBOL_TOKEN_DEF

type TPIMAGE_AUX_SYMBOL_TOKEN_DEF = uintptr

type PIMAGE_AUX_SYMBOL_TOKEN_DEF = TPIMAGE_AUX_SYMBOL_TOKEN_DEF

type TIMAGE_AUX_SYMBOL_TOKEN_DEF1 = struct {
	FbAuxType         TBYTE
	FbReserved        TBYTE
	FSymbolTableIndex TDWORD
	FrgbReserved      [12]TBYTE
}

type IMAGE_AUX_SYMBOL_TOKEN_DEF1 = TIMAGE_AUX_SYMBOL_TOKEN_DEF1

type TIMAGE_AUX_SYMBOL = struct {
	FFile [0]struct {
		FName [18]TBYTE
	}
	FSection [0]struct {
		FLength              TDWORD
		FNumberOfRelocations TWORD
		FNumberOfLinenumbers TWORD
		FCheckSum            TDWORD
		FNumber              TSHORT
		FSelection           TBYTE
	}
	FTokenDef [0]TIMAGE_AUX_SYMBOL_TOKEN_DEF
	FCRC      [0]struct {
		Fcrc         TDWORD
		FrgbReserved [14]TBYTE
	}
	FSym struct {
		FTagIndex TDWORD
		FMisc     struct {
			FTotalSize [0]TDWORD
			FLnSz      struct {
				FLinenumber TWORD
				FSize       TWORD
			}
		}
		FFcnAry struct {
			FArray [0]struct {
				FDimension [4]TWORD
			}
			FFunction struct {
				FPointerToLinenumber   TDWORD
				FPointerToNextFunction TDWORD
			}
		}
		FTvIndex TWORD
	}
}

type IMAGE_AUX_SYMBOL = TIMAGE_AUX_SYMBOL

type T_IMAGE_AUX_SYMBOL = TIMAGE_AUX_SYMBOL

type _IMAGE_AUX_SYMBOL = T_IMAGE_AUX_SYMBOL

type TPIMAGE_AUX_SYMBOL = uintptr

type PIMAGE_AUX_SYMBOL = TPIMAGE_AUX_SYMBOL

type TIMAGE_AUX_SYMBOL_EX = struct {
	FFile [0]struct {
		FName [20]TBYTE
	}
	FSection [0]struct {
		FLength              TDWORD
		FNumberOfRelocations TWORD
		FNumberOfLinenumbers TWORD
		FCheckSum            TDWORD
		FNumber              TSHORT
		FSelection           TBYTE
		FbReserved           TBYTE
		FHighNumber          TSHORT
		FrgbReserved         [2]TBYTE
	}
	F__ccgo3_0 [0]struct {
		FTokenDef    TIMAGE_AUX_SYMBOL_TOKEN_DEF
		FrgbReserved [2]TBYTE
	}
	FCRC [0]struct {
		Fcrc         TDWORD
		FrgbReserved [16]TBYTE
	}
	FSym struct {
		FWeakDefaultSymIndex TDWORD
		FWeakSearchType      TDWORD
		FrgbReserved         [12]TBYTE
	}
	F__ccgo_pad5 [4]byte
}

type IMAGE_AUX_SYMBOL_EX = TIMAGE_AUX_SYMBOL_EX

type T_IMAGE_AUX_SYMBOL_EX = TIMAGE_AUX_SYMBOL_EX

type _IMAGE_AUX_SYMBOL_EX = T_IMAGE_AUX_SYMBOL_EX

type TPIMAGE_AUX_SYMBOL_EX = uintptr

type PIMAGE_AUX_SYMBOL_EX = TPIMAGE_AUX_SYMBOL_EX

type TIMAGE_AUX_SYMBOL_TYPE = int32

type IMAGE_AUX_SYMBOL_TYPE = TIMAGE_AUX_SYMBOL_TYPE

type _IMAGE_AUX_SYMBOL_TYPE = int32

const _IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1

type TIMAGE_RELOCATION = struct {
	F__ccgo0_0 struct {
		FRelocCount     [0]TDWORD
		FVirtualAddress TDWORD
	}
	FSymbolTableIndex TDWORD
	FType             TWORD
}

type IMAGE_RELOCATION = TIMAGE_RELOCATION

type T_IMAGE_RELOCATION = TIMAGE_RELOCATION

type _IMAGE_RELOCATION = T_IMAGE_RELOCATION

type TPIMAGE_RELOCATION = uintptr

type PIMAGE_RELOCATION = TPIMAGE_RELOCATION

type TIMAGE_LINENUMBER = struct {
	FType struct {
		FVirtualAddress   [0]TDWORD
		FSymbolTableIndex TDWORD
	}
	FLinenumber TWORD
}

type IMAGE_LINENUMBER = TIMAGE_LINENUMBER

type T_IMAGE_LINENUMBER = TIMAGE_LINENUMBER

type _IMAGE_LINENUMBER = T_IMAGE_LINENUMBER

type TPIMAGE_LINENUMBER = uintptr

type PIMAGE_LINENUMBER = TPIMAGE_LINENUMBER

type TIMAGE_BASE_RELOCATION = struct {
	FVirtualAddress TDWORD
	FSizeOfBlock    TDWORD
}

type IMAGE_BASE_RELOCATION = TIMAGE_BASE_RELOCATION

type T_IMAGE_BASE_RELOCATION = TIMAGE_BASE_RELOCATION

type _IMAGE_BASE_RELOCATION = T_IMAGE_BASE_RELOCATION

type TPIMAGE_BASE_RELOCATION = uintptr

type PIMAGE_BASE_RELOCATION = TPIMAGE_BASE_RELOCATION

type TIMAGE_ARCHIVE_MEMBER_HEADER = struct {
	FName      [16]TBYTE
	FDate      [12]TBYTE
	FUserID    [6]TBYTE
	FGroupID   [6]TBYTE
	FMode      [8]TBYTE
	FSize      [10]TBYTE
	FEndHeader [2]TBYTE
}

type IMAGE_ARCHIVE_MEMBER_HEADER = TIMAGE_ARCHIVE_MEMBER_HEADER

type T_IMAGE_ARCHIVE_MEMBER_HEADER = TIMAGE_ARCHIVE_MEMBER_HEADER

type _IMAGE_ARCHIVE_MEMBER_HEADER = T_IMAGE_ARCHIVE_MEMBER_HEADER

type TPIMAGE_ARCHIVE_MEMBER_HEADER = uintptr

type PIMAGE_ARCHIVE_MEMBER_HEADER = TPIMAGE_ARCHIVE_MEMBER_HEADER

type TIMAGE_EXPORT_DIRECTORY = struct {
	FCharacteristics       TDWORD
	FTimeDateStamp         TDWORD
	FMajorVersion          TWORD
	FMinorVersion          TWORD
	FName                  TDWORD
	FBase                  TDWORD
	FNumberOfFunctions     TDWORD
	FNumberOfNames         TDWORD
	FAddressOfFunctions    TDWORD
	FAddressOfNames        TDWORD
	FAddressOfNameOrdinals TDWORD
}

type IMAGE_EXPORT_DIRECTORY = TIMAGE_EXPORT_DIRECTORY

type T_IMAGE_EXPORT_DIRECTORY = TIMAGE_EXPORT_DIRECTORY

type _IMAGE_EXPORT_DIRECTORY = T_IMAGE_EXPORT_DIRECTORY

type TPIMAGE_EXPORT_DIRECTORY = uintptr

type PIMAGE_EXPORT_DIRECTORY = TPIMAGE_EXPORT_DIRECTORY

type TIMAGE_IMPORT_BY_NAME = struct {
	FHint TWORD
	FName [1]TCHAR
}

type IMAGE_IMPORT_BY_NAME = TIMAGE_IMPORT_BY_NAME

type T_IMAGE_IMPORT_BY_NAME = TIMAGE_IMPORT_BY_NAME

type _IMAGE_IMPORT_BY_NAME = T_IMAGE_IMPORT_BY_NAME

type TPIMAGE_IMPORT_BY_NAME = uintptr

type PIMAGE_IMPORT_BY_NAME = TPIMAGE_IMPORT_BY_NAME

type TIMAGE_THUNK_DATA64 = struct {
	F__ccgo_align [0]uint32
	Fu1           struct {
		F__ccgo_align    [0]uint32
		FFunction        [0]TULONGLONG
		FOrdinal         [0]TULONGLONG
		FAddressOfData   [0]TULONGLONG
		FForwarderString TULONGLONG
	}
}

type IMAGE_THUNK_DATA64 = TIMAGE_THUNK_DATA64

type T_IMAGE_THUNK_DATA64 = TIMAGE_THUNK_DATA64

type _IMAGE_THUNK_DATA64 = T_IMAGE_THUNK_DATA64

type TPIMAGE_THUNK_DATA64 = uintptr

type PIMAGE_THUNK_DATA64 = TPIMAGE_THUNK_DATA64

type TIMAGE_THUNK_DATA32 = struct {
	Fu1 struct {
		FFunction        [0]TDWORD
		FOrdinal         [0]TDWORD
		FAddressOfData   [0]TDWORD
		FForwarderString TDWORD
	}
}

type IMAGE_THUNK_DATA32 = TIMAGE_THUNK_DATA32

type T_IMAGE_THUNK_DATA32 = TIMAGE_THUNK_DATA32

type _IMAGE_THUNK_DATA32 = T_IMAGE_THUNK_DATA32

type TPIMAGE_THUNK_DATA32 = uintptr

type PIMAGE_THUNK_DATA32 = TPIMAGE_THUNK_DATA32

type TPIMAGE_TLS_CALLBACK = uintptr

type PIMAGE_TLS_CALLBACK = TPIMAGE_TLS_CALLBACK

type TIMAGE_TLS_DIRECTORY64 = struct {
	F__ccgo_align          [0]uint32
	FStartAddressOfRawData TULONGLONG
	FEndAddressOfRawData   TULONGLONG
	FAddressOfIndex        TULONGLONG
	FAddressOfCallBacks    TULONGLONG
	FSizeOfZeroFill        TDWORD
	FCharacteristics       TDWORD
}

type IMAGE_TLS_DIRECTORY64 = TIMAGE_TLS_DIRECTORY64

type T_IMAGE_TLS_DIRECTORY64 = TIMAGE_TLS_DIRECTORY64

type _IMAGE_TLS_DIRECTORY64 = T_IMAGE_TLS_DIRECTORY64

type TPIMAGE_TLS_DIRECTORY64 = uintptr

type PIMAGE_TLS_DIRECTORY64 = TPIMAGE_TLS_DIRECTORY64

type TIMAGE_TLS_DIRECTORY32 = struct {
	FStartAddressOfRawData TDWORD
	FEndAddressOfRawData   TDWORD
	FAddressOfIndex        TDWORD
	FAddressOfCallBacks    TDWORD
	FSizeOfZeroFill        TDWORD
	FCharacteristics       TDWORD
}

type IMAGE_TLS_DIRECTORY32 = TIMAGE_TLS_DIRECTORY32

type T_IMAGE_TLS_DIRECTORY32 = TIMAGE_TLS_DIRECTORY32

type _IMAGE_TLS_DIRECTORY32 = T_IMAGE_TLS_DIRECTORY32

type TPIMAGE_TLS_DIRECTORY32 = uintptr

type PIMAGE_TLS_DIRECTORY32 = TPIMAGE_TLS_DIRECTORY32

type TIMAGE_THUNK_DATA = struct {
	Fu1 struct {
		FFunction        [0]TDWORD
		FOrdinal         [0]TDWORD
		FAddressOfData   [0]TDWORD
		FForwarderString TDWORD
	}
}

type IMAGE_THUNK_DATA = TIMAGE_THUNK_DATA

type TPIMAGE_THUNK_DATA = uintptr

type PIMAGE_THUNK_DATA = TPIMAGE_THUNK_DATA

type TIMAGE_TLS_DIRECTORY = struct {
	FStartAddressOfRawData TDWORD
	FEndAddressOfRawData   TDWORD
	FAddressOfIndex        TDWORD
	FAddressOfCallBacks    TDWORD
	FSizeOfZeroFill        TDWORD
	FCharacteristics       TDWORD
}

type IMAGE_TLS_DIRECTORY = TIMAGE_TLS_DIRECTORY

type TPIMAGE_TLS_DIRECTORY = uintptr

type PIMAGE_TLS_DIRECTORY = TPIMAGE_TLS_DIRECTORY

type TIMAGE_IMPORT_DESCRIPTOR = struct {
	F__ccgo0_0 struct {
		FOriginalFirstThunk [0]TDWORD
		FCharacteristics    TDWORD
	}
	FTimeDateStamp  TDWORD
	FForwarderChain TDWORD
	FName           TDWORD
	FFirstThunk     TDWORD
}

type IMAGE_IMPORT_DESCRIPTOR = TIMAGE_IMPORT_DESCRIPTOR

type T_IMAGE_IMPORT_DESCRIPTOR = TIMAGE_IMPORT_DESCRIPTOR

type _IMAGE_IMPORT_DESCRIPTOR = T_IMAGE_IMPORT_DESCRIPTOR

type TPIMAGE_IMPORT_DESCRIPTOR = uintptr

type PIMAGE_IMPORT_DESCRIPTOR = TPIMAGE_IMPORT_DESCRIPTOR

type TIMAGE_BOUND_IMPORT_DESCRIPTOR = struct {
	FTimeDateStamp               TDWORD
	FOffsetModuleName            TWORD
	FNumberOfModuleForwarderRefs TWORD
}

type IMAGE_BOUND_IMPORT_DESCRIPTOR = TIMAGE_BOUND_IMPORT_DESCRIPTOR

type T_IMAGE_BOUND_IMPORT_DESCRIPTOR = TIMAGE_BOUND_IMPORT_DESCRIPTOR

type _IMAGE_BOUND_IMPORT_DESCRIPTOR = T_IMAGE_BOUND_IMPORT_DESCRIPTOR

type TPIMAGE_BOUND_IMPORT_DESCRIPTOR = uintptr

type PIMAGE_BOUND_IMPORT_DESCRIPTOR = TPIMAGE_BOUND_IMPORT_DESCRIPTOR

type TIMAGE_BOUND_FORWARDER_REF = struct {
	FTimeDateStamp    TDWORD
	FOffsetModuleName TWORD
	FReserved         TWORD
}

type IMAGE_BOUND_FORWARDER_REF = TIMAGE_BOUND_FORWARDER_REF

type T_IMAGE_BOUND_FORWARDER_REF = TIMAGE_BOUND_FORWARDER_REF

type _IMAGE_BOUND_FORWARDER_REF = T_IMAGE_BOUND_FORWARDER_REF

type TPIMAGE_BOUND_FORWARDER_REF = uintptr

type PIMAGE_BOUND_FORWARDER_REF = TPIMAGE_BOUND_FORWARDER_REF

type TIMAGE_DELAYLOAD_DESCRIPTOR = struct {
	FAttributes struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FAllAttributes TDWORD
	}
	FDllNameRVA                 TDWORD
	FModuleHandleRVA            TDWORD
	FImportAddressTableRVA      TDWORD
	FImportNameTableRVA         TDWORD
	FBoundImportAddressTableRVA TDWORD
	FUnloadInformationTableRVA  TDWORD
	FTimeDateStamp              TDWORD
}

type IMAGE_DELAYLOAD_DESCRIPTOR = TIMAGE_DELAYLOAD_DESCRIPTOR

type T_IMAGE_DELAYLOAD_DESCRIPTOR = TIMAGE_DELAYLOAD_DESCRIPTOR

type _IMAGE_DELAYLOAD_DESCRIPTOR = T_IMAGE_DELAYLOAD_DESCRIPTOR

type TPIMAGE_DELAYLOAD_DESCRIPTOR = uintptr

type PIMAGE_DELAYLOAD_DESCRIPTOR = TPIMAGE_DELAYLOAD_DESCRIPTOR

type TPCIMAGE_DELAYLOAD_DESCRIPTOR = uintptr

type PCIMAGE_DELAYLOAD_DESCRIPTOR = TPCIMAGE_DELAYLOAD_DESCRIPTOR

type TIMAGE_RESOURCE_DIRECTORY = struct {
	FCharacteristics      TDWORD
	FTimeDateStamp        TDWORD
	FMajorVersion         TWORD
	FMinorVersion         TWORD
	FNumberOfNamedEntries TWORD
	FNumberOfIdEntries    TWORD
}

type IMAGE_RESOURCE_DIRECTORY = TIMAGE_RESOURCE_DIRECTORY

type T_IMAGE_RESOURCE_DIRECTORY = TIMAGE_RESOURCE_DIRECTORY

type _IMAGE_RESOURCE_DIRECTORY = T_IMAGE_RESOURCE_DIRECTORY

type TPIMAGE_RESOURCE_DIRECTORY = uintptr

type PIMAGE_RESOURCE_DIRECTORY = TPIMAGE_RESOURCE_DIRECTORY

type TIMAGE_RESOURCE_DIRECTORY_ENTRY = struct {
	F__ccgo0_0 struct {
		FName      [0]TDWORD
		FId        [0]TWORD
		F__ccgo0_0 struct {
			F__ccgo0 uint32
		}
	}
	F__ccgo1_4 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FOffsetToData TDWORD
	}
}

type IMAGE_RESOURCE_DIRECTORY_ENTRY = TIMAGE_RESOURCE_DIRECTORY_ENTRY

type T_IMAGE_RESOURCE_DIRECTORY_ENTRY = TIMAGE_RESOURCE_DIRECTORY_ENTRY

type _IMAGE_RESOURCE_DIRECTORY_ENTRY = T_IMAGE_RESOURCE_DIRECTORY_ENTRY

type TPIMAGE_RESOURCE_DIRECTORY_ENTRY = uintptr

type PIMAGE_RESOURCE_DIRECTORY_ENTRY = TPIMAGE_RESOURCE_DIRECTORY_ENTRY

type TIMAGE_RESOURCE_DIRECTORY_STRING = struct {
	FLength     TWORD
	FNameString [1]TCHAR
}

type IMAGE_RESOURCE_DIRECTORY_STRING = TIMAGE_RESOURCE_DIRECTORY_STRING

type T_IMAGE_RESOURCE_DIRECTORY_STRING = TIMAGE_RESOURCE_DIRECTORY_STRING

type _IMAGE_RESOURCE_DIRECTORY_STRING = T_IMAGE_RESOURCE_DIRECTORY_STRING

type TPIMAGE_RESOURCE_DIRECTORY_STRING = uintptr

type PIMAGE_RESOURCE_DIRECTORY_STRING = TPIMAGE_RESOURCE_DIRECTORY_STRING

type TIMAGE_RESOURCE_DIR_STRING_U = struct {
	FLength     TWORD
	FNameString [1]TWCHAR
}

type IMAGE_RESOURCE_DIR_STRING_U = TIMAGE_RESOURCE_DIR_STRING_U

type T_IMAGE_RESOURCE_DIR_STRING_U = TIMAGE_RESOURCE_DIR_STRING_U

type _IMAGE_RESOURCE_DIR_STRING_U = T_IMAGE_RESOURCE_DIR_STRING_U

type TPIMAGE_RESOURCE_DIR_STRING_U = uintptr

type PIMAGE_RESOURCE_DIR_STRING_U = TPIMAGE_RESOURCE_DIR_STRING_U

type TIMAGE_RESOURCE_DATA_ENTRY = struct {
	FOffsetToData TDWORD
	FSize         TDWORD
	FCodePage     TDWORD
	FReserved     TDWORD
}

type IMAGE_RESOURCE_DATA_ENTRY = TIMAGE_RESOURCE_DATA_ENTRY

type T_IMAGE_RESOURCE_DATA_ENTRY = TIMAGE_RESOURCE_DATA_ENTRY

type _IMAGE_RESOURCE_DATA_ENTRY = T_IMAGE_RESOURCE_DATA_ENTRY

type TPIMAGE_RESOURCE_DATA_ENTRY = uintptr

type PIMAGE_RESOURCE_DATA_ENTRY = TPIMAGE_RESOURCE_DATA_ENTRY

type TIMAGE_LOAD_CONFIG_DIRECTORY32 = struct {
	FSize                          TDWORD
	FTimeDateStamp                 TDWORD
	FMajorVersion                  TWORD
	FMinorVersion                  TWORD
	FGlobalFlagsClear              TDWORD
	FGlobalFlagsSet                TDWORD
	FCriticalSectionDefaultTimeout TDWORD
	FDeCommitFreeBlockThreshold    TDWORD
	FDeCommitTotalFreeThreshold    TDWORD
	FLockPrefixTable               TDWORD
	FMaximumAllocationSize         TDWORD
	FVirtualMemoryThreshold        TDWORD
	FProcessHeapFlags              TDWORD
	FProcessAffinityMask           TDWORD
	FCSDVersion                    TWORD
	FReserved1                     TWORD
	FEditList                      TDWORD
	FSecurityCookie                TDWORD
	FSEHandlerTable                TDWORD
	FSEHandlerCount                TDWORD
}

type IMAGE_LOAD_CONFIG_DIRECTORY32 = TIMAGE_LOAD_CONFIG_DIRECTORY32

type TPIMAGE_LOAD_CONFIG_DIRECTORY32 = uintptr

type PIMAGE_LOAD_CONFIG_DIRECTORY32 = TPIMAGE_LOAD_CONFIG_DIRECTORY32

type TIMAGE_LOAD_CONFIG_DIRECTORY64 = struct {
	F__ccgo_align                  [0]uint32
	FSize                          TDWORD
	FTimeDateStamp                 TDWORD
	FMajorVersion                  TWORD
	FMinorVersion                  TWORD
	FGlobalFlagsClear              TDWORD
	FGlobalFlagsSet                TDWORD
	FCriticalSectionDefaultTimeout TDWORD
	FDeCommitFreeBlockThreshold    TULONGLONG
	FDeCommitTotalFreeThreshold    TULONGLONG
	FLockPrefixTable               TULONGLONG
	FMaximumAllocationSize         TULONGLONG
	FVirtualMemoryThreshold        TULONGLONG
	FProcessAffinityMask           TULONGLONG
	FProcessHeapFlags              TDWORD
	FCSDVersion                    TWORD
	FReserved1                     TWORD
	FEditList                      TULONGLONG
	FSecurityCookie                TULONGLONG
	FSEHandlerTable                TULONGLONG
	FSEHandlerCount                TULONGLONG
}

type IMAGE_LOAD_CONFIG_DIRECTORY64 = TIMAGE_LOAD_CONFIG_DIRECTORY64

type TPIMAGE_LOAD_CONFIG_DIRECTORY64 = uintptr

type PIMAGE_LOAD_CONFIG_DIRECTORY64 = TPIMAGE_LOAD_CONFIG_DIRECTORY64

type TIMAGE_LOAD_CONFIG_DIRECTORY = struct {
	FSize                          TDWORD
	FTimeDateStamp                 TDWORD
	FMajorVersion                  TWORD
	FMinorVersion                  TWORD
	FGlobalFlagsClear              TDWORD
	FGlobalFlagsSet                TDWORD
	FCriticalSectionDefaultTimeout TDWORD
	FDeCommitFreeBlockThreshold    TDWORD
	FDeCommitTotalFreeThreshold    TDWORD
	FLockPrefixTable               TDWORD
	FMaximumAllocationSize         TDWORD
	FVirtualMemoryThreshold        TDWORD
	FProcessHeapFlags              TDWORD
	FProcessAffinityMask           TDWORD
	FCSDVersion                    TWORD
	FReserved1                     TWORD
	FEditList                      TDWORD
	FSecurityCookie                TDWORD
	FSEHandlerTable                TDWORD
	FSEHandlerCount                TDWORD
}

type IMAGE_LOAD_CONFIG_DIRECTORY = TIMAGE_LOAD_CONFIG_DIRECTORY

type TPIMAGE_LOAD_CONFIG_DIRECTORY = uintptr

type PIMAGE_LOAD_CONFIG_DIRECTORY = TPIMAGE_LOAD_CONFIG_DIRECTORY

type TIMAGE_CE_RUNTIME_FUNCTION_ENTRY = struct {
	FFuncStart TDWORD
	F__ccgo4   uint32
}

type IMAGE_CE_RUNTIME_FUNCTION_ENTRY = TIMAGE_CE_RUNTIME_FUNCTION_ENTRY

type T_IMAGE_CE_RUNTIME_FUNCTION_ENTRY = TIMAGE_CE_RUNTIME_FUNCTION_ENTRY

type _IMAGE_CE_RUNTIME_FUNCTION_ENTRY = T_IMAGE_CE_RUNTIME_FUNCTION_ENTRY

type TPIMAGE_CE_RUNTIME_FUNCTION_ENTRY = uintptr

type PIMAGE_CE_RUNTIME_FUNCTION_ENTRY = TPIMAGE_CE_RUNTIME_FUNCTION_ENTRY

type TIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY = struct {
	F__ccgo_align     [0]uint32
	FBeginAddress     TULONGLONG
	FEndAddress       TULONGLONG
	FExceptionHandler TULONGLONG
	FHandlerData      TULONGLONG
	FPrologEndAddress TULONGLONG
}

type IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY = TIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY

type T_IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY = TIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY

type _IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY = T_IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY

type TPIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY = uintptr

type PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY = TPIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY

type TIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY = struct {
	FBeginAddress     TDWORD
	FEndAddress       TDWORD
	FExceptionHandler TDWORD
	FHandlerData      TDWORD
	FPrologEndAddress TDWORD
}

type IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY = TIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY

type T_IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY = TIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY

type _IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY = T_IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY

type TPIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY = uintptr

type PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY = TPIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY

type TIMAGE_ARM_RUNTIME_FUNCTION_ENTRY = struct {
	FBeginAddress TDWORD
	F__ccgo1_4    struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FUnwindData TDWORD
	}
}

type IMAGE_ARM_RUNTIME_FUNCTION_ENTRY = TIMAGE_ARM_RUNTIME_FUNCTION_ENTRY

type T_IMAGE_ARM_RUNTIME_FUNCTION_ENTRY = TIMAGE_ARM_RUNTIME_FUNCTION_ENTRY

type _IMAGE_ARM_RUNTIME_FUNCTION_ENTRY = T_IMAGE_ARM_RUNTIME_FUNCTION_ENTRY

type TPIMAGE_ARM_RUNTIME_FUNCTION_ENTRY = uintptr

type PIMAGE_ARM_RUNTIME_FUNCTION_ENTRY = TPIMAGE_ARM_RUNTIME_FUNCTION_ENTRY

type TIMAGE_ARM64_RUNTIME_FUNCTION_ENTRY = struct {
	FBeginAddress TDWORD
	F__ccgo1_4    struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FUnwindData TDWORD
	}
}

type IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY = TIMAGE_ARM64_RUNTIME_FUNCTION_ENTRY

type T_IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY = TIMAGE_ARM64_RUNTIME_FUNCTION_ENTRY

type _IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY = T_IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY

type TPIMAGE_ARM64_RUNTIME_FUNCTION_ENTRY = uintptr

type PIMAGE_ARM64_RUNTIME_FUNCTION_ENTRY = TPIMAGE_ARM64_RUNTIME_FUNCTION_ENTRY

type T_IMAGE_RUNTIME_FUNCTION_ENTRY = struct {
	FBeginAddress TDWORD
	FEndAddress   TDWORD
	F__ccgo2_8    struct {
		FUnwindData        [0]TDWORD
		FUnwindInfoAddress TDWORD
	}
}

type _IMAGE_RUNTIME_FUNCTION_ENTRY = T_IMAGE_RUNTIME_FUNCTION_ENTRY

type T_PIMAGE_RUNTIME_FUNCTION_ENTRY = uintptr

type _PIMAGE_RUNTIME_FUNCTION_ENTRY = T_PIMAGE_RUNTIME_FUNCTION_ENTRY

type T_IMAGE_RUNTIME_FUNCTION_ENTRY1 = struct {
	FBeginAddress TDWORD
	FEndAddress   TDWORD
	F__ccgo2_8    struct {
		FUnwindData        [0]TDWORD
		FUnwindInfoAddress TDWORD
	}
}

type _IMAGE_RUNTIME_FUNCTION_ENTRY1 = T_IMAGE_RUNTIME_FUNCTION_ENTRY1

type TIMAGE_IA64_RUNTIME_FUNCTION_ENTRY = struct {
	FBeginAddress TDWORD
	FEndAddress   TDWORD
	F__ccgo2_8    struct {
		FUnwindData        [0]TDWORD
		FUnwindInfoAddress TDWORD
	}
}

type IMAGE_IA64_RUNTIME_FUNCTION_ENTRY = TIMAGE_IA64_RUNTIME_FUNCTION_ENTRY

type TPIMAGE_IA64_RUNTIME_FUNCTION_ENTRY = uintptr

type PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY = TPIMAGE_IA64_RUNTIME_FUNCTION_ENTRY

type TIMAGE_RUNTIME_FUNCTION_ENTRY = struct {
	FBeginAddress TDWORD
	FEndAddress   TDWORD
	F__ccgo2_8    struct {
		FUnwindData        [0]TDWORD
		FUnwindInfoAddress TDWORD
	}
}

type IMAGE_RUNTIME_FUNCTION_ENTRY = TIMAGE_RUNTIME_FUNCTION_ENTRY

type TPIMAGE_RUNTIME_FUNCTION_ENTRY = uintptr

type PIMAGE_RUNTIME_FUNCTION_ENTRY = TPIMAGE_RUNTIME_FUNCTION_ENTRY

type TIMAGE_DEBUG_DIRECTORY = struct {
	FCharacteristics  TDWORD
	FTimeDateStamp    TDWORD
	FMajorVersion     TWORD
	FMinorVersion     TWORD
	FType             TDWORD
	FSizeOfData       TDWORD
	FAddressOfRawData TDWORD
	FPointerToRawData TDWORD
}

type IMAGE_DEBUG_DIRECTORY = TIMAGE_DEBUG_DIRECTORY

type T_IMAGE_DEBUG_DIRECTORY = TIMAGE_DEBUG_DIRECTORY

type _IMAGE_DEBUG_DIRECTORY = T_IMAGE_DEBUG_DIRECTORY

type TPIMAGE_DEBUG_DIRECTORY = uintptr

type PIMAGE_DEBUG_DIRECTORY = TPIMAGE_DEBUG_DIRECTORY

type TIMAGE_COFF_SYMBOLS_HEADER = struct {
	FNumberOfSymbols      TDWORD
	FLvaToFirstSymbol     TDWORD
	FNumberOfLinenumbers  TDWORD
	FLvaToFirstLinenumber TDWORD
	FRvaToFirstByteOfCode TDWORD
	FRvaToLastByteOfCode  TDWORD
	FRvaToFirstByteOfData TDWORD
	FRvaToLastByteOfData  TDWORD
}

type IMAGE_COFF_SYMBOLS_HEADER = TIMAGE_COFF_SYMBOLS_HEADER

type T_IMAGE_COFF_SYMBOLS_HEADER = TIMAGE_COFF_SYMBOLS_HEADER

type _IMAGE_COFF_SYMBOLS_HEADER = T_IMAGE_COFF_SYMBOLS_HEADER

type TPIMAGE_COFF_SYMBOLS_HEADER = uintptr

type PIMAGE_COFF_SYMBOLS_HEADER = TPIMAGE_COFF_SYMBOLS_HEADER

type TFPO_DATA = struct {
	FulOffStart TDWORD
	FcbProcSize TDWORD
	FcdwLocals  TDWORD
	FcdwParams  TWORD
	F__ccgo14   uint16
}

type FPO_DATA = TFPO_DATA

type T_FPO_DATA = TFPO_DATA

type _FPO_DATA = T_FPO_DATA

type TPFPO_DATA = uintptr

type PFPO_DATA = TPFPO_DATA

type TIMAGE_DEBUG_MISC = struct {
	FDataType TDWORD
	FLength   TDWORD
	FUnicode  TBOOLEAN
	FReserved [3]TBYTE
	FData     [1]TBYTE
}

type IMAGE_DEBUG_MISC = TIMAGE_DEBUG_MISC

type T_IMAGE_DEBUG_MISC = TIMAGE_DEBUG_MISC

type _IMAGE_DEBUG_MISC = T_IMAGE_DEBUG_MISC

type TPIMAGE_DEBUG_MISC = uintptr

type PIMAGE_DEBUG_MISC = TPIMAGE_DEBUG_MISC

type TIMAGE_FUNCTION_ENTRY = struct {
	FStartingAddress TDWORD
	FEndingAddress   TDWORD
	FEndOfPrologue   TDWORD
}

type IMAGE_FUNCTION_ENTRY = TIMAGE_FUNCTION_ENTRY

type T_IMAGE_FUNCTION_ENTRY = TIMAGE_FUNCTION_ENTRY

type _IMAGE_FUNCTION_ENTRY = T_IMAGE_FUNCTION_ENTRY

type TPIMAGE_FUNCTION_ENTRY = uintptr

type PIMAGE_FUNCTION_ENTRY = TPIMAGE_FUNCTION_ENTRY

type TIMAGE_FUNCTION_ENTRY64 = struct {
	F__ccgo_align    [0]uint32
	FStartingAddress TULONGLONG
	FEndingAddress   TULONGLONG
	F__ccgo2_16      struct {
		F__ccgo_align      [0]uint32
		FUnwindInfoAddress [0]TULONGLONG
		FEndOfPrologue     TULONGLONG
	}
}

type IMAGE_FUNCTION_ENTRY64 = TIMAGE_FUNCTION_ENTRY64

type T_IMAGE_FUNCTION_ENTRY64 = TIMAGE_FUNCTION_ENTRY64

type _IMAGE_FUNCTION_ENTRY64 = T_IMAGE_FUNCTION_ENTRY64

type TPIMAGE_FUNCTION_ENTRY64 = uintptr

type PIMAGE_FUNCTION_ENTRY64 = TPIMAGE_FUNCTION_ENTRY64

type TIMAGE_SEPARATE_DEBUG_HEADER = struct {
	FSignature          TWORD
	FFlags              TWORD
	FMachine            TWORD
	FCharacteristics    TWORD
	FTimeDateStamp      TDWORD
	FCheckSum           TDWORD
	FImageBase          TDWORD
	FSizeOfImage        TDWORD
	FNumberOfSections   TDWORD
	FExportedNamesSize  TDWORD
	FDebugDirectorySize TDWORD
	FSectionAlignment   TDWORD
	FReserved           [2]TDWORD
}

type IMAGE_SEPARATE_DEBUG_HEADER = TIMAGE_SEPARATE_DEBUG_HEADER

type T_IMAGE_SEPARATE_DEBUG_HEADER = TIMAGE_SEPARATE_DEBUG_HEADER

type _IMAGE_SEPARATE_DEBUG_HEADER = T_IMAGE_SEPARATE_DEBUG_HEADER

type TPIMAGE_SEPARATE_DEBUG_HEADER = uintptr

type PIMAGE_SEPARATE_DEBUG_HEADER = TPIMAGE_SEPARATE_DEBUG_HEADER

type TNON_PAGED_DEBUG_INFO = struct {
	F__ccgo_align    [0]uint32
	FSignature       TWORD
	FFlags           TWORD
	FSize            TDWORD
	FMachine         TWORD
	FCharacteristics TWORD
	FTimeDateStamp   TDWORD
	FCheckSum        TDWORD
	FSizeOfImage     TDWORD
	FImageBase       TULONGLONG
}

type NON_PAGED_DEBUG_INFO = TNON_PAGED_DEBUG_INFO

type T_NON_PAGED_DEBUG_INFO = TNON_PAGED_DEBUG_INFO

type _NON_PAGED_DEBUG_INFO = T_NON_PAGED_DEBUG_INFO

type TPNON_PAGED_DEBUG_INFO = uintptr

type PNON_PAGED_DEBUG_INFO = TPNON_PAGED_DEBUG_INFO

type TIMAGE_ARCHITECTURE_HEADER = struct {
	F__ccgo0       uint32
	FFirstEntryRVA TDWORD
}

type IMAGE_ARCHITECTURE_HEADER = TIMAGE_ARCHITECTURE_HEADER

type T_ImageArchitectureHeader = TIMAGE_ARCHITECTURE_HEADER

type _ImageArchitectureHeader = T_ImageArchitectureHeader

type TPIMAGE_ARCHITECTURE_HEADER = uintptr

type PIMAGE_ARCHITECTURE_HEADER = TPIMAGE_ARCHITECTURE_HEADER

type TIMAGE_ARCHITECTURE_ENTRY = struct {
	FFixupInstRVA TDWORD
	FNewInst      TDWORD
}

type IMAGE_ARCHITECTURE_ENTRY = TIMAGE_ARCHITECTURE_ENTRY

type T_ImageArchitectureEntry = TIMAGE_ARCHITECTURE_ENTRY

type _ImageArchitectureEntry = T_ImageArchitectureEntry

type TPIMAGE_ARCHITECTURE_ENTRY = uintptr

type PIMAGE_ARCHITECTURE_ENTRY = TPIMAGE_ARCHITECTURE_ENTRY

type TIMPORT_OBJECT_HEADER = struct {
	FSig1          TWORD
	FSig2          TWORD
	FVersion       TWORD
	FMachine       TWORD
	FTimeDateStamp TDWORD
	FSizeOfData    TDWORD
	F__ccgo6_16    struct {
		FHint    [0]TWORD
		FOrdinal TWORD
	}
	F__ccgo18 uint16
}

type IMPORT_OBJECT_HEADER = TIMPORT_OBJECT_HEADER

type TIMPORT_OBJECT_TYPE = int32

type IMPORT_OBJECT_TYPE = TIMPORT_OBJECT_TYPE

type _IMPORT_OBJECT_TYPE = int32

const _IMPORT_OBJECT_CODE = 0
const _IMPORT_OBJECT_DATA = 1
const _IMPORT_OBJECT_CONST = 2

type TIMPORT_OBJECT_NAME_TYPE = int32

type IMPORT_OBJECT_NAME_TYPE = TIMPORT_OBJECT_NAME_TYPE

type _IMPORT_OBJECT_NAME_TYPE = int32

const _IMPORT_OBJECT_ORDINAL = 0
const _IMPORT_OBJECT_NAME = 1
const _IMPORT_OBJECT_NAME_NO_PREFIX = 2
const _IMPORT_OBJECT_NAME_UNDECORATE = 3

type TReplacesCorHdrNumericDefines = int32

type ReplacesCorHdrNumericDefines = TReplacesCorHdrNumericDefines

type _ReplacesCorHdrNumericDefines = int32

const _COMIMAGE_FLAGS_ILONLY = 1
const _COMIMAGE_FLAGS_32BITREQUIRED = 2
const _COMIMAGE_FLAGS_IL_LIBRARY = 4
const _COMIMAGE_FLAGS_STRONGNAMESIGNED = 8
const _COMIMAGE_FLAGS_TRACKDEBUGDATA = 65536
const _COR_VERSION_MAJOR_V2 = 2
const _COR_VERSION_MAJOR = 2
const _COR_VERSION_MINOR = 0
const _COR_DELETED_NAME_LENGTH = 8
const _COR_VTABLEGAP_NAME_LENGTH = 8
const _NATIVE_TYPE_MAX_CB = 1
const _COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE = 255
const _IMAGE_COR_MIH_METHODRVA = 1
const _IMAGE_COR_MIH_EHRVA = 2
const _IMAGE_COR_MIH_BASICBLOCK = 8
const _COR_VTABLE_32BIT = 1
const _COR_VTABLE_64BIT = 2
const _COR_VTABLE_FROM_UNMANAGED = 4
const _COR_VTABLE_CALL_MOST_DERIVED = 16
const _IMAGE_COR_EATJ_THUNK_SIZE = 32
const _MAX_CLASS_NAME = 1024
const _MAX_PACKAGE_NAME = 1024

type TIMAGE_COR20_HEADER = struct {
	Fcb                  TDWORD
	FMajorRuntimeVersion TWORD
	FMinorRuntimeVersion TWORD
	FMetaData            TIMAGE_DATA_DIRECTORY
	FFlags               TDWORD
	F__ccgo5_20          struct {
		FEntryPointRVA   [0]TDWORD
		FEntryPointToken TDWORD
	}
	FResources               TIMAGE_DATA_DIRECTORY
	FStrongNameSignature     TIMAGE_DATA_DIRECTORY
	FCodeManagerTable        TIMAGE_DATA_DIRECTORY
	FVTableFixups            TIMAGE_DATA_DIRECTORY
	FExportAddressTableJumps TIMAGE_DATA_DIRECTORY
	FManagedNativeHeader     TIMAGE_DATA_DIRECTORY
}

type IMAGE_COR20_HEADER = TIMAGE_COR20_HEADER

type TPIMAGE_COR20_HEADER = uintptr

type PIMAGE_COR20_HEADER = TPIMAGE_COR20_HEADER

type TIMAGE_COR20_HEADER1 = struct {
	Fcb                  TDWORD
	FMajorRuntimeVersion TWORD
	FMinorRuntimeVersion TWORD
	FMetaData            TIMAGE_DATA_DIRECTORY
	FFlags               TDWORD
	F__ccgo5_20          struct {
		FEntryPointRVA   [0]TDWORD
		FEntryPointToken TDWORD
	}
	FResources               TIMAGE_DATA_DIRECTORY
	FStrongNameSignature     TIMAGE_DATA_DIRECTORY
	FCodeManagerTable        TIMAGE_DATA_DIRECTORY
	FVTableFixups            TIMAGE_DATA_DIRECTORY
	FExportAddressTableJumps TIMAGE_DATA_DIRECTORY
	FManagedNativeHeader     TIMAGE_DATA_DIRECTORY
}

type IMAGE_COR20_HEADER1 = TIMAGE_COR20_HEADER1

type TSLIST_ENTRY = struct {
	FNext uintptr
}

type SLIST_ENTRY = TSLIST_ENTRY

type TPSLIST_ENTRY = uintptr

type PSLIST_ENTRY = TPSLIST_ENTRY

type TSLIST_HEADER = struct {
	F__ccgo_align [0]uint32
	F__ccgo1_0    [0]struct {
		FNext     TSLIST_ENTRY
		FDepth    TWORD
		FSequence TWORD
	}
	FAlignment TULONGLONG
}

type SLIST_HEADER = TSLIST_HEADER

type T_SLIST_HEADER = TSLIST_HEADER

type _SLIST_HEADER = T_SLIST_HEADER

type TPSLIST_HEADER = uintptr

type PSLIST_HEADER = TPSLIST_HEADER

type TRTL_RUN_ONCE = struct {
	FPtr TPVOID
}

type RTL_RUN_ONCE = TRTL_RUN_ONCE

type T_RTL_RUN_ONCE = TRTL_RUN_ONCE

type _RTL_RUN_ONCE = T_RTL_RUN_ONCE

type TPRTL_RUN_ONCE = uintptr

type PRTL_RUN_ONCE = TPRTL_RUN_ONCE

type TPRTL_RUN_ONCE_INIT_FN = uintptr

type PRTL_RUN_ONCE_INIT_FN = TPRTL_RUN_ONCE_INIT_FN

type TRTL_BARRIER = struct {
	FReserved1 TDWORD
	FReserved2 TDWORD
	FReserved3 [2]TULONG_PTR
	FReserved4 TDWORD
	FReserved5 TDWORD
}

type RTL_BARRIER = TRTL_BARRIER

type T_RTL_BARRIER = TRTL_BARRIER

type _RTL_BARRIER = T_RTL_BARRIER

type TPRTL_BARRIER = uintptr

type PRTL_BARRIER = TPRTL_BARRIER

type TMESSAGE_RESOURCE_ENTRY = struct {
	FLength TWORD
	FFlags  TWORD
	FText   [1]TBYTE
}

type MESSAGE_RESOURCE_ENTRY = TMESSAGE_RESOURCE_ENTRY

type T_MESSAGE_RESOURCE_ENTRY = TMESSAGE_RESOURCE_ENTRY

type _MESSAGE_RESOURCE_ENTRY = T_MESSAGE_RESOURCE_ENTRY

type TPMESSAGE_RESOURCE_ENTRY = uintptr

type PMESSAGE_RESOURCE_ENTRY = TPMESSAGE_RESOURCE_ENTRY

type TMESSAGE_RESOURCE_BLOCK = struct {
	FLowId           TDWORD
	FHighId          TDWORD
	FOffsetToEntries TDWORD
}

type MESSAGE_RESOURCE_BLOCK = TMESSAGE_RESOURCE_BLOCK

type T_MESSAGE_RESOURCE_BLOCK = TMESSAGE_RESOURCE_BLOCK

type _MESSAGE_RESOURCE_BLOCK = T_MESSAGE_RESOURCE_BLOCK

type TPMESSAGE_RESOURCE_BLOCK = uintptr

type PMESSAGE_RESOURCE_BLOCK = TPMESSAGE_RESOURCE_BLOCK

type TMESSAGE_RESOURCE_DATA = struct {
	FNumberOfBlocks TDWORD
	FBlocks         [1]TMESSAGE_RESOURCE_BLOCK
}

type MESSAGE_RESOURCE_DATA = TMESSAGE_RESOURCE_DATA

type T_MESSAGE_RESOURCE_DATA = TMESSAGE_RESOURCE_DATA

type _MESSAGE_RESOURCE_DATA = T_MESSAGE_RESOURCE_DATA

type TPMESSAGE_RESOURCE_DATA = uintptr

type PMESSAGE_RESOURCE_DATA = TPMESSAGE_RESOURCE_DATA

type TOSVERSIONINFOA = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TCHAR
}

type OSVERSIONINFOA = TOSVERSIONINFOA

type T_OSVERSIONINFOA = TOSVERSIONINFOA

type _OSVERSIONINFOA = T_OSVERSIONINFOA

type TPOSVERSIONINFOA = uintptr

type POSVERSIONINFOA = TPOSVERSIONINFOA

type TLPOSVERSIONINFOA = uintptr

type LPOSVERSIONINFOA = TLPOSVERSIONINFOA

type TOSVERSIONINFOW = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TWCHAR
}

type OSVERSIONINFOW = TOSVERSIONINFOW

type T_OSVERSIONINFOW = TOSVERSIONINFOW

type _OSVERSIONINFOW = T_OSVERSIONINFOW

type TPOSVERSIONINFOW = uintptr

type POSVERSIONINFOW = TPOSVERSIONINFOW

type TLPOSVERSIONINFOW = uintptr

type LPOSVERSIONINFOW = TLPOSVERSIONINFOW

type TRTL_OSVERSIONINFOW = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TWCHAR
}

type RTL_OSVERSIONINFOW = TRTL_OSVERSIONINFOW

type TPRTL_OSVERSIONINFOW = uintptr

type PRTL_OSVERSIONINFOW = TPRTL_OSVERSIONINFOW

type TOSVERSIONINFO = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TCHAR
}

type OSVERSIONINFO = TOSVERSIONINFO

type TPOSVERSIONINFO = uintptr

type POSVERSIONINFO = TPOSVERSIONINFO

type TLPOSVERSIONINFO = uintptr

type LPOSVERSIONINFO = TLPOSVERSIONINFO

type TOSVERSIONINFOEXA = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TCHAR
	FwServicePackMajor   TWORD
	FwServicePackMinor   TWORD
	FwSuiteMask          TWORD
	FwProductType        TBYTE
	FwReserved           TBYTE
}

type OSVERSIONINFOEXA = TOSVERSIONINFOEXA

type T_OSVERSIONINFOEXA = TOSVERSIONINFOEXA

type _OSVERSIONINFOEXA = T_OSVERSIONINFOEXA

type TPOSVERSIONINFOEXA = uintptr

type POSVERSIONINFOEXA = TPOSVERSIONINFOEXA

type TLPOSVERSIONINFOEXA = uintptr

type LPOSVERSIONINFOEXA = TLPOSVERSIONINFOEXA

type TOSVERSIONINFOEXW = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TWCHAR
	FwServicePackMajor   TWORD
	FwServicePackMinor   TWORD
	FwSuiteMask          TWORD
	FwProductType        TBYTE
	FwReserved           TBYTE
}

type OSVERSIONINFOEXW = TOSVERSIONINFOEXW

type T_OSVERSIONINFOEXW = TOSVERSIONINFOEXW

type _OSVERSIONINFOEXW = T_OSVERSIONINFOEXW

type TPOSVERSIONINFOEXW = uintptr

type POSVERSIONINFOEXW = TPOSVERSIONINFOEXW

type TLPOSVERSIONINFOEXW = uintptr

type LPOSVERSIONINFOEXW = TLPOSVERSIONINFOEXW

type TRTL_OSVERSIONINFOEXW = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TWCHAR
	FwServicePackMajor   TWORD
	FwServicePackMinor   TWORD
	FwSuiteMask          TWORD
	FwProductType        TBYTE
	FwReserved           TBYTE
}

type RTL_OSVERSIONINFOEXW = TRTL_OSVERSIONINFOEXW

type TPRTL_OSVERSIONINFOEXW = uintptr

type PRTL_OSVERSIONINFOEXW = TPRTL_OSVERSIONINFOEXW

type TOSVERSIONINFOEX = struct {
	FdwOSVersionInfoSize TDWORD
	FdwMajorVersion      TDWORD
	FdwMinorVersion      TDWORD
	FdwBuildNumber       TDWORD
	FdwPlatformId        TDWORD
	FszCSDVersion        [128]TCHAR
	FwServicePackMajor   TWORD
	FwServicePackMinor   TWORD
	FwSuiteMask          TWORD
	FwProductType        TBYTE
	FwReserved           TBYTE
}

type OSVERSIONINFOEX = TOSVERSIONINFOEX

type TPOSVERSIONINFOEX = uintptr

type POSVERSIONINFOEX = TPOSVERSIONINFOEX

type TLPOSVERSIONINFOEX = uintptr

type LPOSVERSIONINFOEX = TLPOSVERSIONINFOEX

type TRTL_UMS_THREAD_INFO_CLASS = int32

type RTL_UMS_THREAD_INFO_CLASS = TRTL_UMS_THREAD_INFO_CLASS

type __RTL_UMS_THREAD_INFO_CLASS = int32

const _UmsThreadInvalidInfoClass = 0
const _UmsThreadUserContext = 1
const _UmsThreadPriority = 2
const _UmsThreadAffinity = 3
const _UmsThreadTeb = 4
const _UmsThreadIsSuspended = 5
const _UmsThreadIsTerminated = 6
const _UmsThreadMaxInfoClass = 7

type TPRTL_UMS_THREAD_INFO_CLASS = uintptr

type PRTL_UMS_THREAD_INFO_CLASS = TPRTL_UMS_THREAD_INFO_CLASS

type TRTL_UMS_SCHEDULER_REASON = int32

type RTL_UMS_SCHEDULER_REASON = TRTL_UMS_SCHEDULER_REASON

type __RTL_UMS_SCHEDULER_REASON = int32

const _UmsSchedulerStartup = 0
const _UmsSchedulerThreadBlocked = 1
const _UmsSchedulerThreadYield = 2

type TPRTL_UMS_SCHEDULER_REASON = uintptr

type PRTL_UMS_SCHEDULER_REASON = TPRTL_UMS_SCHEDULER_REASON

type TPRTL_UMS_SCHEDULER_ENTRY_POINT = uintptr

type PRTL_UMS_SCHEDULER_ENTRY_POINT = TPRTL_UMS_SCHEDULER_ENTRY_POINT

type TRTL_CRITICAL_SECTION_DEBUG = struct {
	FType                      TWORD
	FCreatorBackTraceIndex     TWORD
	FCriticalSection           uintptr
	FProcessLocksList          TLIST_ENTRY
	FEntryCount                TDWORD
	FContentionCount           TDWORD
	FFlags                     TDWORD
	FCreatorBackTraceIndexHigh TWORD
	FSpareWORD                 TWORD
}

type RTL_CRITICAL_SECTION_DEBUG = TRTL_CRITICAL_SECTION_DEBUG

type T_RTL_CRITICAL_SECTION_DEBUG = TRTL_CRITICAL_SECTION_DEBUG

type _RTL_CRITICAL_SECTION_DEBUG = T_RTL_CRITICAL_SECTION_DEBUG

type TPRTL_CRITICAL_SECTION_DEBUG = uintptr

type PRTL_CRITICAL_SECTION_DEBUG = TPRTL_CRITICAL_SECTION_DEBUG

type TRTL_RESOURCE_DEBUG = struct {
	FType                      TWORD
	FCreatorBackTraceIndex     TWORD
	FCriticalSection           uintptr
	FProcessLocksList          TLIST_ENTRY
	FEntryCount                TDWORD
	FContentionCount           TDWORD
	FFlags                     TDWORD
	FCreatorBackTraceIndexHigh TWORD
	FSpareWORD                 TWORD
}

type RTL_RESOURCE_DEBUG = TRTL_RESOURCE_DEBUG

type TPRTL_RESOURCE_DEBUG = uintptr

type PRTL_RESOURCE_DEBUG = TPRTL_RESOURCE_DEBUG

type TRTL_CRITICAL_SECTION = struct {
	FDebugInfo      TPRTL_CRITICAL_SECTION_DEBUG
	FLockCount      TLONG
	FRecursionCount TLONG
	FOwningThread   THANDLE
	FLockSemaphore  THANDLE
	FSpinCount      TULONG_PTR
}

type RTL_CRITICAL_SECTION = TRTL_CRITICAL_SECTION

type T_RTL_CRITICAL_SECTION = TRTL_CRITICAL_SECTION

type _RTL_CRITICAL_SECTION = T_RTL_CRITICAL_SECTION

type TPRTL_CRITICAL_SECTION = uintptr

type PRTL_CRITICAL_SECTION = TPRTL_CRITICAL_SECTION

type TRTL_SRWLOCK = struct {
	FPtr TPVOID
}

type RTL_SRWLOCK = TRTL_SRWLOCK

type T_RTL_SRWLOCK = TRTL_SRWLOCK

type _RTL_SRWLOCK = T_RTL_SRWLOCK

type TPRTL_SRWLOCK = uintptr

type PRTL_SRWLOCK = TPRTL_SRWLOCK

type TRTL_CONDITION_VARIABLE = struct {
	FPtr TPVOID
}

type RTL_CONDITION_VARIABLE = TRTL_CONDITION_VARIABLE

type T_RTL_CONDITION_VARIABLE = TRTL_CONDITION_VARIABLE

type _RTL_CONDITION_VARIABLE = T_RTL_CONDITION_VARIABLE

type TPRTL_CONDITION_VARIABLE = uintptr

type PRTL_CONDITION_VARIABLE = TPRTL_CONDITION_VARIABLE

type TPAPCFUNC = uintptr

type PAPCFUNC = TPAPCFUNC

type TPVECTORED_EXCEPTION_HANDLER = uintptr

type PVECTORED_EXCEPTION_HANDLER = TPVECTORED_EXCEPTION_HANDLER

type THEAP_INFORMATION_CLASS = int32

type HEAP_INFORMATION_CLASS = THEAP_INFORMATION_CLASS

type __HEAP_INFORMATION_CLASS = int32

const _HeapCompatibilityInformation = 0
const _HeapEnableTerminationOnCorruption = 1

type TWORKERCALLBACKFUNC = uintptr

type WORKERCALLBACKFUNC = TWORKERCALLBACKFUNC

type TAPC_CALLBACK_FUNCTION = uintptr

type APC_CALLBACK_FUNCTION = TAPC_CALLBACK_FUNCTION

type TWAITORTIMERCALLBACKFUNC = uintptr

type WAITORTIMERCALLBACKFUNC = TWAITORTIMERCALLBACKFUNC

type TWAITORTIMERCALLBACK = uintptr

type WAITORTIMERCALLBACK = TWAITORTIMERCALLBACK

type TPFLS_CALLBACK_FUNCTION = uintptr

type PFLS_CALLBACK_FUNCTION = TPFLS_CALLBACK_FUNCTION

type TPSECURE_MEMORY_CACHE_CALLBACK = uintptr

type PSECURE_MEMORY_CACHE_CALLBACK = TPSECURE_MEMORY_CACHE_CALLBACK

type TACTIVATION_CONTEXT_INFO_CLASS = int32

type ACTIVATION_CONTEXT_INFO_CLASS = TACTIVATION_CONTEXT_INFO_CLASS

type __ACTIVATION_CONTEXT_INFO_CLASS = int32

const _ActivationContextBasicInformation = 1
const _ActivationContextDetailedInformation = 2
const _AssemblyDetailedInformationInActivationContext = 3
const _FileInformationInAssemblyOfAssemblyInActivationContext = 4
const _RunlevelInformationInActivationContext = 5
const _CompatibilityInformationInActivationContext = 6
const _ActivationContextManifestResourceName = 7
const _MaxActivationContextInfoClass = 8
const _AssemblyDetailedInformationInActivationContxt = 3
const _FileInformationInAssemblyOfAssemblyInActivationContxt = 4

type TACTCTX_REQUESTED_RUN_LEVEL = int32

type ACTCTX_REQUESTED_RUN_LEVEL = TACTCTX_REQUESTED_RUN_LEVEL

const _ACTCTX_RUN_LEVEL_UNSPECIFIED = 0
const _ACTCTX_RUN_LEVEL_AS_INVOKER = 1
const _ACTCTX_RUN_LEVEL_HIGHEST_AVAILABLE = 2
const _ACTCTX_RUN_LEVEL_REQUIRE_ADMIN = 3
const _ACTCTX_RUN_LEVEL_NUMBERS = 4

type TACTCTX_COMPATIBILITY_ELEMENT_TYPE = int32

type ACTCTX_COMPATIBILITY_ELEMENT_TYPE = TACTCTX_COMPATIBILITY_ELEMENT_TYPE

const _ACTCTX_COMPATIBILITY_ELEMENT_TYPE_UNKNOWN = 0
const _ACTCTX_COMPATIBILITY_ELEMENT_TYPE_OS = 1
const _ACTCTX_COMPATIBILITY_ELEMENT_TYPE_MITIGATION = 2

type TACTIVATION_CONTEXT_QUERY_INDEX = struct {
	FulAssemblyIndex       TDWORD
	FulFileIndexInAssembly TDWORD
}

type ACTIVATION_CONTEXT_QUERY_INDEX = TACTIVATION_CONTEXT_QUERY_INDEX

type T_ACTIVATION_CONTEXT_QUERY_INDEX = TACTIVATION_CONTEXT_QUERY_INDEX

type _ACTIVATION_CONTEXT_QUERY_INDEX = T_ACTIVATION_CONTEXT_QUERY_INDEX

type TPACTIVATION_CONTEXT_QUERY_INDEX = uintptr

type PACTIVATION_CONTEXT_QUERY_INDEX = TPACTIVATION_CONTEXT_QUERY_INDEX

type TASSEMBLY_FILE_DETAILED_INFORMATION = struct {
	FulFlags          TDWORD
	FulFilenameLength TDWORD
	FulPathLength     TDWORD
	FlpFileName       TPCWSTR
	FlpFilePath       TPCWSTR
}

type ASSEMBLY_FILE_DETAILED_INFORMATION = TASSEMBLY_FILE_DETAILED_INFORMATION

type T_ASSEMBLY_FILE_DETAILED_INFORMATION = TASSEMBLY_FILE_DETAILED_INFORMATION

type _ASSEMBLY_FILE_DETAILED_INFORMATION = T_ASSEMBLY_FILE_DETAILED_INFORMATION

type TPASSEMBLY_FILE_DETAILED_INFORMATION = uintptr

type PASSEMBLY_FILE_DETAILED_INFORMATION = TPASSEMBLY_FILE_DETAILED_INFORMATION

type TACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = struct {
	F__ccgo_align                      [0]uint32
	FulFlags                           TDWORD
	FulEncodedAssemblyIdentityLength   TDWORD
	FulManifestPathType                TDWORD
	FulManifestPathLength              TDWORD
	FliManifestLastWriteTime           TLARGE_INTEGER
	FulPolicyPathType                  TDWORD
	FulPolicyPathLength                TDWORD
	FliPolicyLastWriteTime             TLARGE_INTEGER
	FulMetadataSatelliteRosterIndex    TDWORD
	FulManifestVersionMajor            TDWORD
	FulManifestVersionMinor            TDWORD
	FulPolicyVersionMajor              TDWORD
	FulPolicyVersionMinor              TDWORD
	FulAssemblyDirectoryNameLength     TDWORD
	FlpAssemblyEncodedAssemblyIdentity TPCWSTR
	FlpAssemblyManifestPath            TPCWSTR
	FlpAssemblyPolicyPath              TPCWSTR
	FlpAssemblyDirectoryName           TPCWSTR
	FulFileCount                       TDWORD
	F__ccgo_pad19                      [4]byte
}

type ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = TACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION

type T_ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = TACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION

type _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = T_ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION

type TPACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = uintptr

type PACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = TPACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION

type TACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = struct {
	FulFlags  TDWORD
	FRunLevel TACTCTX_REQUESTED_RUN_LEVEL
	FUiAccess TDWORD
}

type ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = TACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION

type T_ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = TACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION

type _ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = T_ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION

type TPACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = uintptr

type PACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = TPACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION

type TCOMPATIBILITY_CONTEXT_ELEMENT = struct {
	FId   TGUID
	FType TACTCTX_COMPATIBILITY_ELEMENT_TYPE
}

type COMPATIBILITY_CONTEXT_ELEMENT = TCOMPATIBILITY_CONTEXT_ELEMENT

type T_COMPATIBILITY_CONTEXT_ELEMENT = TCOMPATIBILITY_CONTEXT_ELEMENT

type _COMPATIBILITY_CONTEXT_ELEMENT = T_COMPATIBILITY_CONTEXT_ELEMENT

type TPCOMPATIBILITY_CONTEXT_ELEMENT = uintptr

type PCOMPATIBILITY_CONTEXT_ELEMENT = TPCOMPATIBILITY_CONTEXT_ELEMENT

type TACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = struct {
	FElementCount TDWORD
}

type ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = TACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION

type T_ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = TACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION

type _ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = T_ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION

type TPACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = uintptr

type PACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = TPACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION

type TSUPPORTED_OS_INFO = struct {
	FOsCount         TWORD
	FMitigationExist TWORD
	FOsList          [4]TWORD
}

type SUPPORTED_OS_INFO = TSUPPORTED_OS_INFO

type T_SUPPORTED_OS_INFO = TSUPPORTED_OS_INFO

type _SUPPORTED_OS_INFO = T_SUPPORTED_OS_INFO

type TPSUPPORTED_OS_INFO = uintptr

type PSUPPORTED_OS_INFO = TPSUPPORTED_OS_INFO

type TACTIVATION_CONTEXT_DETAILED_INFORMATION = struct {
	FdwFlags                      TDWORD
	FulFormatVersion              TDWORD
	FulAssemblyCount              TDWORD
	FulRootManifestPathType       TDWORD
	FulRootManifestPathChars      TDWORD
	FulRootConfigurationPathType  TDWORD
	FulRootConfigurationPathChars TDWORD
	FulAppDirPathType             TDWORD
	FulAppDirPathChars            TDWORD
	FlpRootManifestPath           TPCWSTR
	FlpRootConfigurationPath      TPCWSTR
	FlpAppDirPath                 TPCWSTR
}

type ACTIVATION_CONTEXT_DETAILED_INFORMATION = TACTIVATION_CONTEXT_DETAILED_INFORMATION

type T_ACTIVATION_CONTEXT_DETAILED_INFORMATION = TACTIVATION_CONTEXT_DETAILED_INFORMATION

type _ACTIVATION_CONTEXT_DETAILED_INFORMATION = T_ACTIVATION_CONTEXT_DETAILED_INFORMATION

type TPACTIVATION_CONTEXT_DETAILED_INFORMATION = uintptr

type PACTIVATION_CONTEXT_DETAILED_INFORMATION = TPACTIVATION_CONTEXT_DETAILED_INFORMATION

type TPCACTIVATION_CONTEXT_QUERY_INDEX = uintptr

type PCACTIVATION_CONTEXT_QUERY_INDEX = TPCACTIVATION_CONTEXT_QUERY_INDEX

type TPCASSEMBLY_FILE_DETAILED_INFORMATION = uintptr

type PCASSEMBLY_FILE_DETAILED_INFORMATION = TPCASSEMBLY_FILE_DETAILED_INFORMATION

type TPCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = uintptr

type PCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = TPCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION

type TPCACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = uintptr

type PCACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = TPCACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION

type TPCCOMPATIBILITY_CONTEXT_ELEMENT = uintptr

type PCCOMPATIBILITY_CONTEXT_ELEMENT = TPCCOMPATIBILITY_CONTEXT_ELEMENT

type TPCACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = uintptr

type PCACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION = TPCACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION

type TPCACTIVATION_CONTEXT_DETAILED_INFORMATION = uintptr

type PCACTIVATION_CONTEXT_DETAILED_INFORMATION = TPCACTIVATION_CONTEXT_DETAILED_INFORMATION

type TRTL_VERIFIER_DLL_LOAD_CALLBACK = uintptr

type RTL_VERIFIER_DLL_LOAD_CALLBACK = TRTL_VERIFIER_DLL_LOAD_CALLBACK

type TRTL_VERIFIER_DLL_UNLOAD_CALLBACK = uintptr

type RTL_VERIFIER_DLL_UNLOAD_CALLBACK = TRTL_VERIFIER_DLL_UNLOAD_CALLBACK

type TRTL_VERIFIER_NTDLLHEAPFREE_CALLBACK = uintptr

type RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK = TRTL_VERIFIER_NTDLLHEAPFREE_CALLBACK

type TRTL_VERIFIER_THUNK_DESCRIPTOR = struct {
	FThunkName       TPCHAR
	FThunkOldAddress TPVOID
	FThunkNewAddress TPVOID
}

type RTL_VERIFIER_THUNK_DESCRIPTOR = TRTL_VERIFIER_THUNK_DESCRIPTOR

type T_RTL_VERIFIER_THUNK_DESCRIPTOR = TRTL_VERIFIER_THUNK_DESCRIPTOR

type _RTL_VERIFIER_THUNK_DESCRIPTOR = T_RTL_VERIFIER_THUNK_DESCRIPTOR

type TPRTL_VERIFIER_THUNK_DESCRIPTOR = uintptr

type PRTL_VERIFIER_THUNK_DESCRIPTOR = TPRTL_VERIFIER_THUNK_DESCRIPTOR

type TRTL_VERIFIER_DLL_DESCRIPTOR = struct {
	FDllName    TPWCHAR
	FDllFlags   TDWORD
	FDllAddress TPVOID
	FDllThunks  TPRTL_VERIFIER_THUNK_DESCRIPTOR
}

type RTL_VERIFIER_DLL_DESCRIPTOR = TRTL_VERIFIER_DLL_DESCRIPTOR

type T_RTL_VERIFIER_DLL_DESCRIPTOR = TRTL_VERIFIER_DLL_DESCRIPTOR

type _RTL_VERIFIER_DLL_DESCRIPTOR = T_RTL_VERIFIER_DLL_DESCRIPTOR

type TPRTL_VERIFIER_DLL_DESCRIPTOR = uintptr

type PRTL_VERIFIER_DLL_DESCRIPTOR = TPRTL_VERIFIER_DLL_DESCRIPTOR

type TRTL_VERIFIER_PROVIDER_DESCRIPTOR = struct {
	FLength                        TDWORD
	FProviderDlls                  TPRTL_VERIFIER_DLL_DESCRIPTOR
	FProviderDllLoadCallback       TRTL_VERIFIER_DLL_LOAD_CALLBACK
	FProviderDllUnloadCallback     TRTL_VERIFIER_DLL_UNLOAD_CALLBACK
	FVerifierImage                 TPWSTR
	FVerifierFlags                 TDWORD
	FVerifierDebug                 TDWORD
	FRtlpGetStackTraceAddress      TPVOID
	FRtlpDebugPageHeapCreate       TPVOID
	FRtlpDebugPageHeapDestroy      TPVOID
	FProviderNtdllHeapFreeCallback TRTL_VERIFIER_NTDLLHEAPFREE_CALLBACK
}

type RTL_VERIFIER_PROVIDER_DESCRIPTOR = TRTL_VERIFIER_PROVIDER_DESCRIPTOR

type T_RTL_VERIFIER_PROVIDER_DESCRIPTOR = TRTL_VERIFIER_PROVIDER_DESCRIPTOR

type _RTL_VERIFIER_PROVIDER_DESCRIPTOR = T_RTL_VERIFIER_PROVIDER_DESCRIPTOR

type TPRTL_VERIFIER_PROVIDER_DESCRIPTOR = uintptr

type PRTL_VERIFIER_PROVIDER_DESCRIPTOR = TPRTL_VERIFIER_PROVIDER_DESCRIPTOR

type THARDWARE_COUNTER_DATA = struct {
	F__ccgo_align [0]uint32
	FType         THARDWARE_COUNTER_TYPE
	FReserved     TDWORD
	FValue        TDWORD64
}

type HARDWARE_COUNTER_DATA = THARDWARE_COUNTER_DATA

type T_HARDWARE_COUNTER_DATA = THARDWARE_COUNTER_DATA

type _HARDWARE_COUNTER_DATA = T_HARDWARE_COUNTER_DATA

type TPHARDWARE_COUNTER_DATA = uintptr

type PHARDWARE_COUNTER_DATA = TPHARDWARE_COUNTER_DATA

type TPERFORMANCE_DATA = struct {
	F__ccgo_align       [0]uint32
	FSize               TWORD
	FVersion            TBYTE
	FHwCountersCount    TBYTE
	FContextSwitchCount TDWORD
	FWaitReasonBitMap   TDWORD64
	FCycleTime          TDWORD64
	FRetryCount         TDWORD
	FReserved           TDWORD
	FHwCounters         [16]THARDWARE_COUNTER_DATA
}

type PERFORMANCE_DATA = TPERFORMANCE_DATA

type T_PERFORMANCE_DATA = TPERFORMANCE_DATA

type _PERFORMANCE_DATA = T_PERFORMANCE_DATA

type TPPERFORMANCE_DATA = uintptr

type PPERFORMANCE_DATA = TPPERFORMANCE_DATA

type TEVENTLOGRECORD = struct {
	FLength              TDWORD
	FReserved            TDWORD
	FRecordNumber        TDWORD
	FTimeGenerated       TDWORD
	FTimeWritten         TDWORD
	FEventID             TDWORD
	FEventType           TWORD
	FNumStrings          TWORD
	FEventCategory       TWORD
	FReservedFlags       TWORD
	FClosingRecordNumber TDWORD
	FStringOffset        TDWORD
	FUserSidLength       TDWORD
	FUserSidOffset       TDWORD
	FDataLength          TDWORD
	FDataOffset          TDWORD
}

type EVENTLOGRECORD = TEVENTLOGRECORD

type T_EVENTLOGRECORD = TEVENTLOGRECORD

type _EVENTLOGRECORD = T_EVENTLOGRECORD

type TPEVENTLOGRECORD = uintptr

type PEVENTLOGRECORD = TPEVENTLOGRECORD

type TEVENTSFORLOGFILE = struct {
	FulSize           TDWORD
	FszLogicalLogFile [256]TWCHAR
	FulNumRecords     TDWORD
}

type EVENTSFORLOGFILE = TEVENTSFORLOGFILE

type T_EVENTSFORLOGFILE = TEVENTSFORLOGFILE

type _EVENTSFORLOGFILE = T_EVENTSFORLOGFILE

type TPEVENTSFORLOGFILE = uintptr

type PEVENTSFORLOGFILE = TPEVENTSFORLOGFILE

type TPACKEDEVENTINFO = struct {
	FulSize                TDWORD
	FulNumEventsForLogFile TDWORD
}

type PACKEDEVENTINFO = TPACKEDEVENTINFO

type T_PACKEDEVENTINFO = TPACKEDEVENTINFO

type _PACKEDEVENTINFO = T_PACKEDEVENTINFO

type TPPACKEDEVENTINFO = uintptr

type PPACKEDEVENTINFO = TPPACKEDEVENTINFO

type TSERVICE_NODE_TYPE = int32

type SERVICE_NODE_TYPE = TSERVICE_NODE_TYPE

type __CM_SERVICE_NODE_TYPE = int32

const _DriverType = 1
const _FileSystemType = 2
const _Win32ServiceOwnProcess = 16
const _Win32ServiceShareProcess = 32
const _AdapterType = 4
const _RecognizerType = 8

type TSERVICE_LOAD_TYPE = int32

type SERVICE_LOAD_TYPE = TSERVICE_LOAD_TYPE

type __CM_SERVICE_LOAD_TYPE = int32

const _BootLoad = 0
const _SystemLoad = 1
const _AutoLoad = 2
const _DemandLoad = 3
const _DisableLoad = 4

type TSERVICE_ERROR_TYPE = int32

type SERVICE_ERROR_TYPE = TSERVICE_ERROR_TYPE

type __CM_ERROR_CONTROL_TYPE = int32

const _IgnoreError = 0
const _NormalError = 1
const _SevereError = 2
const _CriticalError = 3

type TTAPE_ERASE = struct {
	FType      TDWORD
	FImmediate TBOOLEAN
}

type TAPE_ERASE = TTAPE_ERASE

type T_TAPE_ERASE = TTAPE_ERASE

type _TAPE_ERASE = T_TAPE_ERASE

type TPTAPE_ERASE = uintptr

type PTAPE_ERASE = TPTAPE_ERASE

type TTAPE_PREPARE = struct {
	FOperation TDWORD
	FImmediate TBOOLEAN
}

type TAPE_PREPARE = TTAPE_PREPARE

type T_TAPE_PREPARE = TTAPE_PREPARE

type _TAPE_PREPARE = T_TAPE_PREPARE

type TPTAPE_PREPARE = uintptr

type PTAPE_PREPARE = TPTAPE_PREPARE

type TTAPE_WRITE_MARKS = struct {
	FType      TDWORD
	FCount     TDWORD
	FImmediate TBOOLEAN
}

type TAPE_WRITE_MARKS = TTAPE_WRITE_MARKS

type T_TAPE_WRITE_MARKS = TTAPE_WRITE_MARKS

type _TAPE_WRITE_MARKS = T_TAPE_WRITE_MARKS

type TPTAPE_WRITE_MARKS = uintptr

type PTAPE_WRITE_MARKS = TPTAPE_WRITE_MARKS

type TTAPE_GET_POSITION = struct {
	F__ccgo_align [0]uint32
	FType         TDWORD
	FPartition    TDWORD
	FOffset       TLARGE_INTEGER
}

type TAPE_GET_POSITION = TTAPE_GET_POSITION

type T_TAPE_GET_POSITION = TTAPE_GET_POSITION

type _TAPE_GET_POSITION = T_TAPE_GET_POSITION

type TPTAPE_GET_POSITION = uintptr

type PTAPE_GET_POSITION = TPTAPE_GET_POSITION

type TTAPE_SET_POSITION = struct {
	F__ccgo_align [0]uint32
	FMethod       TDWORD
	FPartition    TDWORD
	FOffset       TLARGE_INTEGER
	FImmediate    TBOOLEAN
	F__ccgo_pad4  [7]byte
}

type TAPE_SET_POSITION = TTAPE_SET_POSITION

type T_TAPE_SET_POSITION = TTAPE_SET_POSITION

type _TAPE_SET_POSITION = T_TAPE_SET_POSITION

type TPTAPE_SET_POSITION = uintptr

type PTAPE_SET_POSITION = TPTAPE_SET_POSITION

type TTAPE_GET_DRIVE_PARAMETERS = struct {
	FECC                   TBOOLEAN
	FCompression           TBOOLEAN
	FDataPadding           TBOOLEAN
	FReportSetmarks        TBOOLEAN
	FDefaultBlockSize      TDWORD
	FMaximumBlockSize      TDWORD
	FMinimumBlockSize      TDWORD
	FMaximumPartitionCount TDWORD
	FFeaturesLow           TDWORD
	FFeaturesHigh          TDWORD
	FEOTWarningZoneSize    TDWORD
}

type TAPE_GET_DRIVE_PARAMETERS = TTAPE_GET_DRIVE_PARAMETERS

type T_TAPE_GET_DRIVE_PARAMETERS = TTAPE_GET_DRIVE_PARAMETERS

type _TAPE_GET_DRIVE_PARAMETERS = T_TAPE_GET_DRIVE_PARAMETERS

type TPTAPE_GET_DRIVE_PARAMETERS = uintptr

type PTAPE_GET_DRIVE_PARAMETERS = TPTAPE_GET_DRIVE_PARAMETERS

type TTAPE_SET_DRIVE_PARAMETERS = struct {
	FECC                TBOOLEAN
	FCompression        TBOOLEAN
	FDataPadding        TBOOLEAN
	FReportSetmarks     TBOOLEAN
	FEOTWarningZoneSize TDWORD
}

type TAPE_SET_DRIVE_PARAMETERS = TTAPE_SET_DRIVE_PARAMETERS

type T_TAPE_SET_DRIVE_PARAMETERS = TTAPE_SET_DRIVE_PARAMETERS

type _TAPE_SET_DRIVE_PARAMETERS = T_TAPE_SET_DRIVE_PARAMETERS

type TPTAPE_SET_DRIVE_PARAMETERS = uintptr

type PTAPE_SET_DRIVE_PARAMETERS = TPTAPE_SET_DRIVE_PARAMETERS

type TTAPE_GET_MEDIA_PARAMETERS = struct {
	F__ccgo_align   [0]uint32
	FCapacity       TLARGE_INTEGER
	FRemaining      TLARGE_INTEGER
	FBlockSize      TDWORD
	FPartitionCount TDWORD
	FWriteProtected TBOOLEAN
	F__ccgo_pad5    [7]byte
}

type TAPE_GET_MEDIA_PARAMETERS = TTAPE_GET_MEDIA_PARAMETERS

type T_TAPE_GET_MEDIA_PARAMETERS = TTAPE_GET_MEDIA_PARAMETERS

type _TAPE_GET_MEDIA_PARAMETERS = T_TAPE_GET_MEDIA_PARAMETERS

type TPTAPE_GET_MEDIA_PARAMETERS = uintptr

type PTAPE_GET_MEDIA_PARAMETERS = TPTAPE_GET_MEDIA_PARAMETERS

type TTAPE_SET_MEDIA_PARAMETERS = struct {
	FBlockSize TDWORD
}

type TAPE_SET_MEDIA_PARAMETERS = TTAPE_SET_MEDIA_PARAMETERS

type T_TAPE_SET_MEDIA_PARAMETERS = TTAPE_SET_MEDIA_PARAMETERS

type _TAPE_SET_MEDIA_PARAMETERS = T_TAPE_SET_MEDIA_PARAMETERS

type TPTAPE_SET_MEDIA_PARAMETERS = uintptr

type PTAPE_SET_MEDIA_PARAMETERS = TPTAPE_SET_MEDIA_PARAMETERS

type TTAPE_CREATE_PARTITION = struct {
	FMethod TDWORD
	FCount  TDWORD
	FSize   TDWORD
}

type TAPE_CREATE_PARTITION = TTAPE_CREATE_PARTITION

type T_TAPE_CREATE_PARTITION = TTAPE_CREATE_PARTITION

type _TAPE_CREATE_PARTITION = T_TAPE_CREATE_PARTITION

type TPTAPE_CREATE_PARTITION = uintptr

type PTAPE_CREATE_PARTITION = TPTAPE_CREATE_PARTITION

type TTAPE_WMI_OPERATIONS = struct {
	FMethod         TDWORD
	FDataBufferSize TDWORD
	FDataBuffer     TPVOID
}

type TAPE_WMI_OPERATIONS = TTAPE_WMI_OPERATIONS

type T_TAPE_WMI_OPERATIONS = TTAPE_WMI_OPERATIONS

type _TAPE_WMI_OPERATIONS = T_TAPE_WMI_OPERATIONS

type TPTAPE_WMI_OPERATIONS = uintptr

type PTAPE_WMI_OPERATIONS = TPTAPE_WMI_OPERATIONS

type TTAPE_DRIVE_PROBLEM_TYPE = int32

type TAPE_DRIVE_PROBLEM_TYPE = TTAPE_DRIVE_PROBLEM_TYPE

type __TAPE_DRIVE_PROBLEM_TYPE = int32

const _TapeDriveProblemNone = 0
const _TapeDriveReadWriteWarning = 1
const _TapeDriveReadWriteError = 2
const _TapeDriveReadWarning = 3
const _TapeDriveWriteWarning = 4
const _TapeDriveReadError = 5
const _TapeDriveWriteError = 6
const _TapeDriveHardwareError = 7
const _TapeDriveUnsupportedMedia = 8
const _TapeDriveScsiConnectionError = 9
const _TapeDriveTimetoClean = 10
const _TapeDriveCleanDriveNow = 11
const _TapeDriveMediaLifeExpired = 12
const _TapeDriveSnappedTape = 13

type TTP_VERSION = uint32

type TP_VERSION = TTP_VERSION

type TPTP_VERSION = uintptr

type PTP_VERSION = TPTP_VERSION

type TPTP_CALLBACK_INSTANCE = uintptr

type PTP_CALLBACK_INSTANCE = TPTP_CALLBACK_INSTANCE

type TPTP_SIMPLE_CALLBACK = uintptr

type PTP_SIMPLE_CALLBACK = TPTP_SIMPLE_CALLBACK

type TPTP_POOL = uintptr

type PTP_POOL = TPTP_POOL

type TTP_CALLBACK_PRIORITY = int32

type TP_CALLBACK_PRIORITY = TTP_CALLBACK_PRIORITY

type __TP_CALLBACK_PRIORITY = int32

const _TP_CALLBACK_PRIORITY_HIGH = 0
const _TP_CALLBACK_PRIORITY_NORMAL = 1
const _TP_CALLBACK_PRIORITY_LOW = 2
const _TP_CALLBACK_PRIORITY_INVALID = 3
const _TP_CALLBACK_PRIORITY_COUNT = 3

type TTP_POOL_STACK_INFORMATION = struct {
	FStackReserve TSIZE_T
	FStackCommit  TSIZE_T
}

type TP_POOL_STACK_INFORMATION = TTP_POOL_STACK_INFORMATION

type T_TP_POOL_STACK_INFORMATION = TTP_POOL_STACK_INFORMATION

type _TP_POOL_STACK_INFORMATION = T_TP_POOL_STACK_INFORMATION

type TPTP_POOL_STACK_INFORMATION = uintptr

type PTP_POOL_STACK_INFORMATION = TPTP_POOL_STACK_INFORMATION

type TPTP_CLEANUP_GROUP = uintptr

type PTP_CLEANUP_GROUP = TPTP_CLEANUP_GROUP

type TPTP_CLEANUP_GROUP_CANCEL_CALLBACK = uintptr

type PTP_CLEANUP_GROUP_CANCEL_CALLBACK = TPTP_CLEANUP_GROUP_CANCEL_CALLBACK

type TTP_CALLBACK_ENVIRON_V3 = struct {
	FVersion                    TTP_VERSION
	FPool                       TPTP_POOL
	FCleanupGroup               TPTP_CLEANUP_GROUP
	FCleanupGroupCancelCallback TPTP_CLEANUP_GROUP_CANCEL_CALLBACK
	FRaceDll                    TPVOID
	FActivationContext          uintptr
	FFinalizationCallback       TPTP_SIMPLE_CALLBACK
	Fu                          struct {
		Fs [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
	FCallbackPriority TTP_CALLBACK_PRIORITY
	FSize             TDWORD
}

type TP_CALLBACK_ENVIRON_V3 = TTP_CALLBACK_ENVIRON_V3

type T_TP_CALLBACK_ENVIRON_V3 = TTP_CALLBACK_ENVIRON_V3

type _TP_CALLBACK_ENVIRON_V3 = T_TP_CALLBACK_ENVIRON_V3

type TTP_CALLBACK_ENVIRON = struct {
	FVersion                    TTP_VERSION
	FPool                       TPTP_POOL
	FCleanupGroup               TPTP_CLEANUP_GROUP
	FCleanupGroupCancelCallback TPTP_CLEANUP_GROUP_CANCEL_CALLBACK
	FRaceDll                    TPVOID
	FActivationContext          uintptr
	FFinalizationCallback       TPTP_SIMPLE_CALLBACK
	Fu                          struct {
		Fs [0]struct {
			F__ccgo0 uint32
		}
		FFlags TDWORD
	}
	FCallbackPriority TTP_CALLBACK_PRIORITY
	FSize             TDWORD
}

type TP_CALLBACK_ENVIRON = TTP_CALLBACK_ENVIRON

type TPTP_CALLBACK_ENVIRON = uintptr

type PTP_CALLBACK_ENVIRON = TPTP_CALLBACK_ENVIRON

type TPTP_WORK = uintptr

type PTP_WORK = TPTP_WORK

type TPTP_WORK_CALLBACK = uintptr

type PTP_WORK_CALLBACK = TPTP_WORK_CALLBACK

type TPTP_TIMER = uintptr

type PTP_TIMER = TPTP_TIMER

type TPTP_TIMER_CALLBACK = uintptr

type PTP_TIMER_CALLBACK = TPTP_TIMER_CALLBACK

type TTP_WAIT_RESULT = uint32

type TP_WAIT_RESULT = TTP_WAIT_RESULT

type TPTP_WAIT = uintptr

type PTP_WAIT = TPTP_WAIT

type TPTP_WAIT_CALLBACK = uintptr

type PTP_WAIT_CALLBACK = TPTP_WAIT_CALLBACK

type TPTP_IO = uintptr

type PTP_IO = TPTP_IO

type TCRM_PROTOCOL_ID = struct {
	FData1 uint32
	FData2 uint16
	FData3 uint16
	FData4 [8]uint8
}

type CRM_PROTOCOL_ID = TCRM_PROTOCOL_ID

type TPCRM_PROTOCOL_ID = uintptr

type PCRM_PROTOCOL_ID = TPCRM_PROTOCOL_ID

type TNOTIFICATION_MASK = uint32

type NOTIFICATION_MASK = TNOTIFICATION_MASK

type TTRANSACTION_NOTIFICATION = struct {
	F__ccgo_align            [0]uint32
	FTransactionKey          TPVOID
	FTransactionNotification TULONG
	FTmVirtualClock          TLARGE_INTEGER
	FArgumentLength          TULONG
	F__ccgo_pad4             [4]byte
}

type TRANSACTION_NOTIFICATION = TTRANSACTION_NOTIFICATION

type T_TRANSACTION_NOTIFICATION = TTRANSACTION_NOTIFICATION

type _TRANSACTION_NOTIFICATION = T_TRANSACTION_NOTIFICATION

type TPTRANSACTION_NOTIFICATION = uintptr

type PTRANSACTION_NOTIFICATION = TPTRANSACTION_NOTIFICATION

type TTRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT = struct {
	FEnlistmentId TGUID
	FUOW          TGUID
}

type TRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT = TTRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT

type T_TRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT = TTRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT

type _TRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT = T_TRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT

type TPTRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT = uintptr

type PTRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT = TPTRANSACTION_NOTIFICATION_RECOVERY_ARGUMENT

type TTRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT = struct {
	FTmIdentity TGUID
	FFlags      TULONG
}

type TRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT = TTRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT

type T_TRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT = TTRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT

type _TRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT = T_TRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT

type TPTRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT = uintptr

type PTRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT = TPTRANSACTION_NOTIFICATION_TM_ONLINE_ARGUMENT

type TSAVEPOINT_ID = uint32

type SAVEPOINT_ID = TSAVEPOINT_ID

type TPSAVEPOINT_ID = uintptr

type PSAVEPOINT_ID = TPSAVEPOINT_ID

type TTRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT = struct {
	FSavepointId TSAVEPOINT_ID
}

type TRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT = TTRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT

type T_TRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT = TTRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT

type _TRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT = T_TRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT

type TPTRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT = uintptr

type PTRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT = TPTRANSACTION_NOTIFICATION_SAVEPOINT_ARGUMENT

type TTRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT = struct {
	FPropagationCookie TULONG
	FUOW               TGUID
	FTmIdentity        TGUID
	FBufferLength      TULONG
}

type TRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT = TTRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT

type T_TRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT = TTRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT

type _TRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT = T_TRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT

type TPTRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT = uintptr

type PTRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT = TPTRANSACTION_NOTIFICATION_PROPAGATE_ARGUMENT

type TTRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT = struct {
	FMarshalCookie TULONG
	FUOW           TGUID
}

type TRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT = TTRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT

type T_TRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT = TTRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT

type _TRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT = T_TRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT

type TPTRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT = uintptr

type PTRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT = TPTRANSACTION_NOTIFICATION_MARSHAL_ARGUMENT

type TTRANSACTION_NOTIFICATION_PROMOTE_ARGUMENT = struct {
	FPropagationCookie TULONG
	FUOW               TGUID
	FTmIdentity        TGUID
	FBufferLength      TULONG
}

type TRANSACTION_NOTIFICATION_PROMOTE_ARGUMENT = TTRANSACTION_NOTIFICATION_PROMOTE_ARGUMENT

type TPTRANSACTION_NOTIFICATION_PROMOTE_ARGUMENT = uintptr

type PTRANSACTION_NOTIFICATION_PROMOTE_ARGUMENT = TPTRANSACTION_NOTIFICATION_PROMOTE_ARGUMENT

type TKCRM_MARSHAL_HEADER = struct {
	FVersionMajor TULONG
	FVersionMinor TULONG
	FNumProtocols TULONG
	FUnused       TULONG
}

type KCRM_MARSHAL_HEADER = TKCRM_MARSHAL_HEADER

type T_KCRM_MARSHAL_HEADER = TKCRM_MARSHAL_HEADER

type _KCRM_MARSHAL_HEADER = T_KCRM_MARSHAL_HEADER

type TPKCRM_MARSHAL_HEADER = uintptr

type PKCRM_MARSHAL_HEADER = TPKCRM_MARSHAL_HEADER

type TPRKCRM_MARSHAL_HEADER = uintptr

type PRKCRM_MARSHAL_HEADER = TPRKCRM_MARSHAL_HEADER

type TKCRM_TRANSACTION_BLOB = struct {
	FUOW            TGUID
	FTmIdentity     TGUID
	FIsolationLevel TULONG
	FIsolationFlags TULONG
	FTimeout        TULONG
	FDescription    [64]TWCHAR
}

type KCRM_TRANSACTION_BLOB = TKCRM_TRANSACTION_BLOB

type T_KCRM_TRANSACTION_BLOB = TKCRM_TRANSACTION_BLOB

type _KCRM_TRANSACTION_BLOB = T_KCRM_TRANSACTION_BLOB

type TPKCRM_TRANSACTION_BLOB = uintptr

type PKCRM_TRANSACTION_BLOB = TPKCRM_TRANSACTION_BLOB

type TPRKCRM_TRANSACTION_BLOB = uintptr

type PRKCRM_TRANSACTION_BLOB = TPRKCRM_TRANSACTION_BLOB

type TKCRM_PROTOCOL_BLOB = struct {
	FProtocolId              TCRM_PROTOCOL_ID
	FStaticInfoLength        TULONG
	FTransactionIdInfoLength TULONG
	FUnused1                 TULONG
	FUnused2                 TULONG
}

type KCRM_PROTOCOL_BLOB = TKCRM_PROTOCOL_BLOB

type T_KCRM_PROTOCOL_BLOB = TKCRM_PROTOCOL_BLOB

type _KCRM_PROTOCOL_BLOB = T_KCRM_PROTOCOL_BLOB

type TPKCRM_PROTOCOL_BLOB = uintptr

type PKCRM_PROTOCOL_BLOB = TPKCRM_PROTOCOL_BLOB

type TPRKCRM_PROTOCOL_BLOB = uintptr

type PRKCRM_PROTOCOL_BLOB = TPRKCRM_PROTOCOL_BLOB

type TTRANSACTION_OUTCOME = int32

type TRANSACTION_OUTCOME = TTRANSACTION_OUTCOME

type __TRANSACTION_OUTCOME = int32

const _TransactionOutcomeUndetermined = 1
const _TransactionOutcomeCommitted = 2
const _TransactionOutcomeAborted = 3

type TTRANSACTION_STATE = int32

type TRANSACTION_STATE = TTRANSACTION_STATE

type __TRANSACTION_STATE = int32

const _TransactionStateNormal = 1
const _TransactionStateIndoubt = 2
const _TransactionStateCommittedNotify = 3

type TTRANSACTION_BASIC_INFORMATION = struct {
	FTransactionId TGUID
	FState         TDWORD
	FOutcome       TDWORD
}

type TRANSACTION_BASIC_INFORMATION = TTRANSACTION_BASIC_INFORMATION

type T_TRANSACTION_BASIC_INFORMATION = TTRANSACTION_BASIC_INFORMATION

type _TRANSACTION_BASIC_INFORMATION = T_TRANSACTION_BASIC_INFORMATION

type TPTRANSACTION_BASIC_INFORMATION = uintptr

type PTRANSACTION_BASIC_INFORMATION = TPTRANSACTION_BASIC_INFORMATION

type TTRANSACTIONMANAGER_BASIC_INFORMATION = struct {
	F__ccgo_align [0]uint32
	FTmIdentity   TGUID
	FVirtualClock TLARGE_INTEGER
}

type TRANSACTIONMANAGER_BASIC_INFORMATION = TTRANSACTIONMANAGER_BASIC_INFORMATION

type T_TRANSACTIONMANAGER_BASIC_INFORMATION = TTRANSACTIONMANAGER_BASIC_INFORMATION

type _TRANSACTIONMANAGER_BASIC_INFORMATION = T_TRANSACTIONMANAGER_BASIC_INFORMATION

type TPTRANSACTIONMANAGER_BASIC_INFORMATION = uintptr

type PTRANSACTIONMANAGER_BASIC_INFORMATION = TPTRANSACTIONMANAGER_BASIC_INFORMATION

type TTRANSACTIONMANAGER_LOG_INFORMATION = struct {
	FLogIdentity TGUID
}

type TRANSACTIONMANAGER_LOG_INFORMATION = TTRANSACTIONMANAGER_LOG_INFORMATION

type T_TRANSACTIONMANAGER_LOG_INFORMATION = TTRANSACTIONMANAGER_LOG_INFORMATION

type _TRANSACTIONMANAGER_LOG_INFORMATION = T_TRANSACTIONMANAGER_LOG_INFORMATION

type TPTRANSACTIONMANAGER_LOG_INFORMATION = uintptr

type PTRANSACTIONMANAGER_LOG_INFORMATION = TPTRANSACTIONMANAGER_LOG_INFORMATION

type TTRANSACTIONMANAGER_LOGPATH_INFORMATION = struct {
	FLogPathLength TDWORD
	FLogPath       [1]TWCHAR
}

type TRANSACTIONMANAGER_LOGPATH_INFORMATION = TTRANSACTIONMANAGER_LOGPATH_INFORMATION

type T_TRANSACTIONMANAGER_LOGPATH_INFORMATION = TTRANSACTIONMANAGER_LOGPATH_INFORMATION

type _TRANSACTIONMANAGER_LOGPATH_INFORMATION = T_TRANSACTIONMANAGER_LOGPATH_INFORMATION

type TPTRANSACTIONMANAGER_LOGPATH_INFORMATION = uintptr

type PTRANSACTIONMANAGER_LOGPATH_INFORMATION = TPTRANSACTIONMANAGER_LOGPATH_INFORMATION

type TTRANSACTIONMANAGER_RECOVERY_INFORMATION = struct {
	F__ccgo_align     [0]uint32
	FLastRecoveredLsn TULONGLONG
}

type TRANSACTIONMANAGER_RECOVERY_INFORMATION = TTRANSACTIONMANAGER_RECOVERY_INFORMATION

type T_TRANSACTIONMANAGER_RECOVERY_INFORMATION = TTRANSACTIONMANAGER_RECOVERY_INFORMATION

type _TRANSACTIONMANAGER_RECOVERY_INFORMATION = T_TRANSACTIONMANAGER_RECOVERY_INFORMATION

type TPTRANSACTIONMANAGER_RECOVERY_INFORMATION = uintptr

type PTRANSACTIONMANAGER_RECOVERY_INFORMATION = TPTRANSACTIONMANAGER_RECOVERY_INFORMATION

type TTRANSACTIONMANAGER_OLDEST_INFORMATION = struct {
	FOldestTransactionGuid TGUID
}

type TRANSACTIONMANAGER_OLDEST_INFORMATION = TTRANSACTIONMANAGER_OLDEST_INFORMATION

type T_TRANSACTIONMANAGER_OLDEST_INFORMATION = TTRANSACTIONMANAGER_OLDEST_INFORMATION

type _TRANSACTIONMANAGER_OLDEST_INFORMATION = T_TRANSACTIONMANAGER_OLDEST_INFORMATION

type TPTRANSACTIONMANAGER_OLDEST_INFORMATION = uintptr

type PTRANSACTIONMANAGER_OLDEST_INFORMATION = TPTRANSACTIONMANAGER_OLDEST_INFORMATION

type TTRANSACTION_PROPERTIES_INFORMATION = struct {
	F__ccgo_align      [0]uint32
	FIsolationLevel    TDWORD
	FIsolationFlags    TDWORD
	FTimeout           TLARGE_INTEGER
	FOutcome           TDWORD
	FDescriptionLength TDWORD
	FDescription       [1]TWCHAR
	F__ccgo_pad6       [6]byte
}

type TRANSACTION_PROPERTIES_INFORMATION = TTRANSACTION_PROPERTIES_INFORMATION

type T_TRANSACTION_PROPERTIES_INFORMATION = TTRANSACTION_PROPERTIES_INFORMATION

type _TRANSACTION_PROPERTIES_INFORMATION = T_TRANSACTION_PROPERTIES_INFORMATION

type TPTRANSACTION_PROPERTIES_INFORMATION = uintptr

type PTRANSACTION_PROPERTIES_INFORMATION = TPTRANSACTION_PROPERTIES_INFORMATION

type TTRANSACTION_BIND_INFORMATION = struct {
	FTmHandle THANDLE
}

type TRANSACTION_BIND_INFORMATION = TTRANSACTION_BIND_INFORMATION

type T_TRANSACTION_BIND_INFORMATION = TTRANSACTION_BIND_INFORMATION

type _TRANSACTION_BIND_INFORMATION = T_TRANSACTION_BIND_INFORMATION

type TPTRANSACTION_BIND_INFORMATION = uintptr

type PTRANSACTION_BIND_INFORMATION = TPTRANSACTION_BIND_INFORMATION

type TTRANSACTION_ENLISTMENT_PAIR = struct {
	FEnlistmentId      TGUID
	FResourceManagerId TGUID
}

type TRANSACTION_ENLISTMENT_PAIR = TTRANSACTION_ENLISTMENT_PAIR

type T_TRANSACTION_ENLISTMENT_PAIR = TTRANSACTION_ENLISTMENT_PAIR

type _TRANSACTION_ENLISTMENT_PAIR = T_TRANSACTION_ENLISTMENT_PAIR

type TPTRANSACTION_ENLISTMENT_PAIR = uintptr

type PTRANSACTION_ENLISTMENT_PAIR = TPTRANSACTION_ENLISTMENT_PAIR

type TTRANSACTION_ENLISTMENTS_INFORMATION = struct {
	FNumberOfEnlistments TDWORD
	FEnlistmentPair      [1]TTRANSACTION_ENLISTMENT_PAIR
}

type TRANSACTION_ENLISTMENTS_INFORMATION = TTRANSACTION_ENLISTMENTS_INFORMATION

type T_TRANSACTION_ENLISTMENTS_INFORMATION = TTRANSACTION_ENLISTMENTS_INFORMATION

type _TRANSACTION_ENLISTMENTS_INFORMATION = T_TRANSACTION_ENLISTMENTS_INFORMATION

type TPTRANSACTION_ENLISTMENTS_INFORMATION = uintptr

type PTRANSACTION_ENLISTMENTS_INFORMATION = TPTRANSACTION_ENLISTMENTS_INFORMATION

type TTRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION = struct {
	FSuperiorEnlistmentPair TTRANSACTION_ENLISTMENT_PAIR
}

type TRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION = TTRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION

type T_TRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION = TTRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION

type _TRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION = T_TRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION

type TPTRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION = uintptr

type PTRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION = TPTRANSACTION_SUPERIOR_ENLISTMENT_INFORMATION

type TRESOURCEMANAGER_BASIC_INFORMATION = struct {
	FResourceManagerId TGUID
	FDescriptionLength TDWORD
	FDescription       [1]TWCHAR
}

type RESOURCEMANAGER_BASIC_INFORMATION = TRESOURCEMANAGER_BASIC_INFORMATION

type T_RESOURCEMANAGER_BASIC_INFORMATION = TRESOURCEMANAGER_BASIC_INFORMATION

type _RESOURCEMANAGER_BASIC_INFORMATION = T_RESOURCEMANAGER_BASIC_INFORMATION

type TPRESOURCEMANAGER_BASIC_INFORMATION = uintptr

type PRESOURCEMANAGER_BASIC_INFORMATION = TPRESOURCEMANAGER_BASIC_INFORMATION

type TRESOURCEMANAGER_COMPLETION_INFORMATION = struct {
	FIoCompletionPortHandle THANDLE
	FCompletionKey          TULONG_PTR
}

type RESOURCEMANAGER_COMPLETION_INFORMATION = TRESOURCEMANAGER_COMPLETION_INFORMATION

type T_RESOURCEMANAGER_COMPLETION_INFORMATION = TRESOURCEMANAGER_COMPLETION_INFORMATION

type _RESOURCEMANAGER_COMPLETION_INFORMATION = T_RESOURCEMANAGER_COMPLETION_INFORMATION

type TPRESOURCEMANAGER_COMPLETION_INFORMATION = uintptr

type PRESOURCEMANAGER_COMPLETION_INFORMATION = TPRESOURCEMANAGER_COMPLETION_INFORMATION

type TTRANSACTION_INFORMATION_CLASS = int32

type TRANSACTION_INFORMATION_CLASS = TTRANSACTION_INFORMATION_CLASS

type __TRANSACTION_INFORMATION_CLASS = int32

const _TransactionBasicInformation = 0
const _TransactionPropertiesInformation = 1
const _TransactionEnlistmentInformation = 2
const _TransactionSuperiorEnlistmentInformation = 3
const _TransactionBindInformation = 4
const _TransactionDTCPrivateInformation = 5

type TTRANSACTIONMANAGER_INFORMATION_CLASS = int32

type TRANSACTIONMANAGER_INFORMATION_CLASS = TTRANSACTIONMANAGER_INFORMATION_CLASS

type __TRANSACTIONMANAGER_INFORMATION_CLASS = int32

const _TransactionManagerBasicInformation = 0
const _TransactionManagerLogInformation = 1
const _TransactionManagerLogPathInformation = 2
const _TransactionManagerOnlineProbeInformation = 3
const _TransactionManagerRecoveryInformation = 4
const _TransactionManagerOldestTransactionInformation = 5

type TRESOURCEMANAGER_INFORMATION_CLASS = int32

type RESOURCEMANAGER_INFORMATION_CLASS = TRESOURCEMANAGER_INFORMATION_CLASS

type __RESOURCEMANAGER_INFORMATION_CLASS = int32

const _ResourceManagerBasicInformation = 0
const _ResourceManagerCompletionInformation = 1

type TENLISTMENT_BASIC_INFORMATION = struct {
	FEnlistmentId      TGUID
	FTransactionId     TGUID
	FResourceManagerId TGUID
}

type ENLISTMENT_BASIC_INFORMATION = TENLISTMENT_BASIC_INFORMATION

type T_ENLISTMENT_BASIC_INFORMATION = TENLISTMENT_BASIC_INFORMATION

type _ENLISTMENT_BASIC_INFORMATION = T_ENLISTMENT_BASIC_INFORMATION

type TPENLISTMENT_BASIC_INFORMATION = uintptr

type PENLISTMENT_BASIC_INFORMATION = TPENLISTMENT_BASIC_INFORMATION

type TENLISTMENT_CRM_INFORMATION = struct {
	FCrmTransactionManagerId TGUID
	FCrmResourceManagerId    TGUID
	FCrmEnlistmentId         TGUID
}

type ENLISTMENT_CRM_INFORMATION = TENLISTMENT_CRM_INFORMATION

type T_ENLISTMENT_CRM_INFORMATION = TENLISTMENT_CRM_INFORMATION

type _ENLISTMENT_CRM_INFORMATION = T_ENLISTMENT_CRM_INFORMATION

type TPENLISTMENT_CRM_INFORMATION = uintptr

type PENLISTMENT_CRM_INFORMATION = TPENLISTMENT_CRM_INFORMATION

type TENLISTMENT_INFORMATION_CLASS = int32

type ENLISTMENT_INFORMATION_CLASS = TENLISTMENT_INFORMATION_CLASS

type __ENLISTMENT_INFORMATION_CLASS = int32

const _EnlistmentBasicInformation = 0
const _EnlistmentRecoveryInformation = 1
const _EnlistmentCrmInformation = 2

type TTRANSACTION_LIST_ENTRY = struct {
	FUOW TGUID
}

type TRANSACTION_LIST_ENTRY = TTRANSACTION_LIST_ENTRY

type T_TRANSACTION_LIST_ENTRY = TTRANSACTION_LIST_ENTRY

type _TRANSACTION_LIST_ENTRY = T_TRANSACTION_LIST_ENTRY

type TPTRANSACTION_LIST_ENTRY = uintptr

type PTRANSACTION_LIST_ENTRY = TPTRANSACTION_LIST_ENTRY

type TTRANSACTION_LIST_INFORMATION = struct {
	FNumberOfTransactions   TDWORD
	FTransactionInformation [1]TTRANSACTION_LIST_ENTRY
}

type TRANSACTION_LIST_INFORMATION = TTRANSACTION_LIST_INFORMATION

type T_TRANSACTION_LIST_INFORMATION = TTRANSACTION_LIST_INFORMATION

type _TRANSACTION_LIST_INFORMATION = T_TRANSACTION_LIST_INFORMATION

type TPTRANSACTION_LIST_INFORMATION = uintptr

type PTRANSACTION_LIST_INFORMATION = TPTRANSACTION_LIST_INFORMATION

type TKTMOBJECT_TYPE = int32

type KTMOBJECT_TYPE = TKTMOBJECT_TYPE

type __KTMOBJECT_TYPE = int32

const _KTMOBJECT_TRANSACTION = 0
const _KTMOBJECT_TRANSACTION_MANAGER = 1
const _KTMOBJECT_RESOURCE_MANAGER = 2
const _KTMOBJECT_ENLISTMENT = 3
const _KTMOBJECT_INVALID = 4

type TPKTMOBJECT_TYPE = uintptr

type PKTMOBJECT_TYPE = TPKTMOBJECT_TYPE

type TKTMOBJECT_CURSOR = struct {
	FLastQuery     TGUID
	FObjectIdCount TDWORD
	FObjectIds     [1]TGUID
}

type KTMOBJECT_CURSOR = TKTMOBJECT_CURSOR

type T_KTMOBJECT_CURSOR = TKTMOBJECT_CURSOR

type _KTMOBJECT_CURSOR = T_KTMOBJECT_CURSOR

type TPKTMOBJECT_CURSOR = uintptr

type PKTMOBJECT_CURSOR = TPKTMOBJECT_CURSOR

type TWOW64_FLOATING_SAVE_AREA = struct {
	FControlWord   TDWORD
	FStatusWord    TDWORD
	FTagWord       TDWORD
	FErrorOffset   TDWORD
	FErrorSelector TDWORD
	FDataOffset    TDWORD
	FDataSelector  TDWORD
	FRegisterArea  [80]TBYTE
	FCr0NpxState   TDWORD
}

type WOW64_FLOATING_SAVE_AREA = TWOW64_FLOATING_SAVE_AREA

type T_WOW64_FLOATING_SAVE_AREA = TWOW64_FLOATING_SAVE_AREA

type _WOW64_FLOATING_SAVE_AREA = T_WOW64_FLOATING_SAVE_AREA

type TPWOW64_FLOATING_SAVE_AREA = uintptr

type PWOW64_FLOATING_SAVE_AREA = TPWOW64_FLOATING_SAVE_AREA

type TWOW64_CONTEXT = struct {
	FContextFlags      TDWORD
	FDr0               TDWORD
	FDr1               TDWORD
	FDr2               TDWORD
	FDr3               TDWORD
	FDr6               TDWORD
	FDr7               TDWORD
	FFloatSave         TWOW64_FLOATING_SAVE_AREA
	FSegGs             TDWORD
	FSegFs             TDWORD
	FSegEs             TDWORD
	FSegDs             TDWORD
	FEdi               TDWORD
	FEsi               TDWORD
	FEbx               TDWORD
	FEdx               TDWORD
	FEcx               TDWORD
	FEax               TDWORD
	FEbp               TDWORD
	FEip               TDWORD
	FSegCs             TDWORD
	FEFlags            TDWORD
	FEsp               TDWORD
	FSegSs             TDWORD
	FExtendedRegisters [512]TBYTE
}

type WOW64_CONTEXT = TWOW64_CONTEXT

type T_WOW64_CONTEXT = TWOW64_CONTEXT

type _WOW64_CONTEXT = T_WOW64_CONTEXT

type TPWOW64_CONTEXT = uintptr

type PWOW64_CONTEXT = TPWOW64_CONTEXT

type TWOW64_LDT_ENTRY = struct {
	FLimitLow TWORD
	FBaseLow  TWORD
	FHighWord struct {
		FBits [0]struct {
			F__ccgo0 uint32
		}
		FBytes struct {
			FBaseMid TBYTE
			FFlags1  TBYTE
			FFlags2  TBYTE
			FBaseHi  TBYTE
		}
	}
}

type WOW64_LDT_ENTRY = TWOW64_LDT_ENTRY

type T_WOW64_LDT_ENTRY = TWOW64_LDT_ENTRY

type _WOW64_LDT_ENTRY = T_WOW64_LDT_ENTRY

type TPWOW64_LDT_ENTRY = uintptr

type PWOW64_LDT_ENTRY = TPWOW64_LDT_ENTRY

type TWOW64_DESCRIPTOR_TABLE_ENTRY = struct {
	FSelector   TDWORD
	FDescriptor TWOW64_LDT_ENTRY
}

type WOW64_DESCRIPTOR_TABLE_ENTRY = TWOW64_DESCRIPTOR_TABLE_ENTRY

type T_WOW64_DESCRIPTOR_TABLE_ENTRY = TWOW64_DESCRIPTOR_TABLE_ENTRY

type _WOW64_DESCRIPTOR_TABLE_ENTRY = T_WOW64_DESCRIPTOR_TABLE_ENTRY

type TPWOW64_DESCRIPTOR_TABLE_ENTRY = uintptr

type PWOW64_DESCRIPTOR_TABLE_ENTRY = TPWOW64_DESCRIPTOR_TABLE_ENTRY

type TPROCESSOR_NUMBER = struct {
	FGroup    TWORD
	FNumber   TBYTE
	FReserved TBYTE
}

type PROCESSOR_NUMBER = TPROCESSOR_NUMBER

type T_PROCESSOR_NUMBER = TPROCESSOR_NUMBER

type _PROCESSOR_NUMBER = T_PROCESSOR_NUMBER

type TPPROCESSOR_NUMBER = uintptr

type PPROCESSOR_NUMBER = TPPROCESSOR_NUMBER

type TWPARAM = uint32

type WPARAM = TWPARAM

type TLPARAM = int32

type LPARAM = TLPARAM

type TLRESULT = int32

type LRESULT = TLRESULT

type TSPHANDLE = uintptr

type SPHANDLE = TSPHANDLE

type TLPHANDLE = uintptr

type LPHANDLE = TLPHANDLE

type THGLOBAL = uintptr

type HGLOBAL = THGLOBAL

type THLOCAL = uintptr

type HLOCAL = THLOCAL

type TGLOBALHANDLE = uintptr

type GLOBALHANDLE = TGLOBALHANDLE

type TLOCALHANDLE = uintptr

type LOCALHANDLE = TLOCALHANDLE

type TFARPROC = uintptr

type FARPROC = TFARPROC

type TNEARPROC = uintptr

type NEARPROC = TNEARPROC

type TPROC = uintptr

type PROC = TPROC

type TATOM = uint16

type ATOM = TATOM

type THFILE = int32

type HFILE = THFILE

type THINSTANCE__ = struct {
	Funused int32
}

type HINSTANCE__ = THINSTANCE__

type THINSTANCE = uintptr

type HINSTANCE = THINSTANCE

type THKEY__ = struct {
	Funused int32
}

type HKEY__ = THKEY__

type THKEY = uintptr

type HKEY = THKEY

type TPHKEY = uintptr

type PHKEY = TPHKEY

type THKL__ = struct {
	Funused int32
}

type HKL__ = THKL__

type THKL = uintptr

type HKL = THKL

type THLSURF__ = struct {
	Funused int32
}

type HLSURF__ = THLSURF__

type THLSURF = uintptr

type HLSURF = THLSURF

type THMETAFILE__ = struct {
	Funused int32
}

type HMETAFILE__ = THMETAFILE__

type THMETAFILE = uintptr

type HMETAFILE = THMETAFILE

type THMODULE = uintptr

type HMODULE = THMODULE

type THRGN__ = struct {
	Funused int32
}

type HRGN__ = THRGN__

type THRGN = uintptr

type HRGN = THRGN

type THRSRC__ = struct {
	Funused int32
}

type HRSRC__ = THRSRC__

type THRSRC = uintptr

type HRSRC = THRSRC

type THSPRITE__ = struct {
	Funused int32
}

type HSPRITE__ = THSPRITE__

type THSPRITE = uintptr

type HSPRITE = THSPRITE

type THSTR__ = struct {
	Funused int32
}

type HSTR__ = THSTR__

type THSTR = uintptr

type HSTR = THSTR

type THTASK__ = struct {
	Funused int32
}

type HTASK__ = THTASK__

type THTASK = uintptr

type HTASK = THTASK

type THWINSTA__ = struct {
	Funused int32
}

type HWINSTA__ = THWINSTA__

type THWINSTA = uintptr

type HWINSTA = THWINSTA

type TFILETIME = struct {
	FdwLowDateTime  TDWORD
	FdwHighDateTime TDWORD
}

type FILETIME = TFILETIME

type T_FILETIME = TFILETIME

type _FILETIME = T_FILETIME

type TPFILETIME = uintptr

type PFILETIME = TPFILETIME

type TLPFILETIME = uintptr

type LPFILETIME = TLPFILETIME

type THWND__ = struct {
	Funused int32
}

type HWND__ = THWND__

type THWND = uintptr

type HWND = THWND

type THHOOK__ = struct {
	Funused int32
}

type HHOOK__ = THHOOK__

type THHOOK = uintptr

type HHOOK = THHOOK

type THGDIOBJ = uintptr

type HGDIOBJ = THGDIOBJ

type THACCEL__ = struct {
	Funused int32
}

type HACCEL__ = THACCEL__

type THACCEL = uintptr

type HACCEL = THACCEL

type THBITMAP__ = struct {
	Funused int32
}

type HBITMAP__ = THBITMAP__

type THBITMAP = uintptr

type HBITMAP = THBITMAP

type THBRUSH__ = struct {
	Funused int32
}

type HBRUSH__ = THBRUSH__

type THBRUSH = uintptr

type HBRUSH = THBRUSH

type THCOLORSPACE__ = struct {
	Funused int32
}

type HCOLORSPACE__ = THCOLORSPACE__

type THCOLORSPACE = uintptr

type HCOLORSPACE = THCOLORSPACE

type THDC__ = struct {
	Funused int32
}

type HDC__ = THDC__

type THDC = uintptr

type HDC = THDC

type THGLRC__ = struct {
	Funused int32
}

type HGLRC__ = THGLRC__

type THGLRC = uintptr

type HGLRC = THGLRC

type THDESK__ = struct {
	Funused int32
}

type HDESK__ = THDESK__

type THDESK = uintptr

type HDESK = THDESK

type THENHMETAFILE__ = struct {
	Funused int32
}

type HENHMETAFILE__ = THENHMETAFILE__

type THENHMETAFILE = uintptr

type HENHMETAFILE = THENHMETAFILE

type THFONT__ = struct {
	Funused int32
}

type HFONT__ = THFONT__

type THFONT = uintptr

type HFONT = THFONT

type THICON__ = struct {
	Funused int32
}

type HICON__ = THICON__

type THICON = uintptr

type HICON = THICON

type THMENU__ = struct {
	Funused int32
}

type HMENU__ = THMENU__

type THMENU = uintptr

type HMENU = THMENU

type THPALETTE__ = struct {
	Funused int32
}

type HPALETTE__ = THPALETTE__

type THPALETTE = uintptr

type HPALETTE = THPALETTE

type THPEN__ = struct {
	Funused int32
}

type HPEN__ = THPEN__

type THPEN = uintptr

type HPEN = THPEN

type THMONITOR__ = struct {
	Funused int32
}

type HMONITOR__ = THMONITOR__

type THMONITOR = uintptr

type HMONITOR = THMONITOR

type THWINEVENTHOOK__ = struct {
	Funused int32
}

type HWINEVENTHOOK__ = THWINEVENTHOOK__

type THWINEVENTHOOK = uintptr

type HWINEVENTHOOK = THWINEVENTHOOK

type THCURSOR = uintptr

type HCURSOR = THCURSOR

type TCOLORREF = uint32

type COLORREF = TCOLORREF

type THUMPD__ = struct {
	Funused int32
}

type HUMPD__ = THUMPD__

type THUMPD = uintptr

type HUMPD = THUMPD

type TLPCOLORREF = uintptr

type LPCOLORREF = TLPCOLORREF

type TRECT = struct {
	Fleft   TLONG
	Ftop    TLONG
	Fright  TLONG
	Fbottom TLONG
}

type RECT = TRECT

type TtagRECT = TRECT

type tagRECT = TtagRECT

type TPRECT = uintptr

type PRECT = TPRECT

type TNPRECT = uintptr

type NPRECT = TNPRECT

type TLPRECT = uintptr

type LPRECT = TLPRECT

type TLPCRECT = uintptr

type LPCRECT = TLPCRECT

type TRECTL = struct {
	Fleft   TLONG
	Ftop    TLONG
	Fright  TLONG
	Fbottom TLONG
}

type RECTL = TRECTL

type T_RECTL = TRECTL

type _RECTL = T_RECTL

type TPRECTL = uintptr

type PRECTL = TPRECTL

type TLPRECTL = uintptr

type LPRECTL = TLPRECTL

type TLPCRECTL = uintptr

type LPCRECTL = TLPCRECTL

type TPOINT = struct {
	Fx TLONG
	Fy TLONG
}

type POINT = TPOINT

type TtagPOINT = TPOINT

type tagPOINT = TtagPOINT

type TPPOINT = uintptr

type PPOINT = TPPOINT

type TNPPOINT = uintptr

type NPPOINT = TNPPOINT

type TLPPOINT = uintptr

type LPPOINT = TLPPOINT

type TPOINTL = struct {
	Fx TLONG
	Fy TLONG
}

type POINTL = TPOINTL

type T_POINTL = TPOINTL

type _POINTL = T_POINTL

type TPPOINTL = uintptr

type PPOINTL = TPPOINTL

type TSIZE = struct {
	Fcx TLONG
	Fcy TLONG
}

type SIZE = TSIZE

type TtagSIZE = TSIZE

type tagSIZE = TtagSIZE

type TPSIZE = uintptr

type PSIZE = TPSIZE

type TLPSIZE = uintptr

type LPSIZE = TLPSIZE

type TSIZEL = struct {
	Fcx TLONG
	Fcy TLONG
}

type SIZEL = TSIZEL

type TPSIZEL = uintptr

type PSIZEL = TPSIZEL

type TLPSIZEL = uintptr

type LPSIZEL = TLPSIZEL

type TPOINTS = struct {
	Fx TSHORT
	Fy TSHORT
}

type POINTS = TPOINTS

type TtagPOINTS = TPOINTS

type tagPOINTS = TtagPOINTS

type TPPOINTS = uintptr

type PPOINTS = TPPOINTS

type TLPPOINTS = uintptr

type LPPOINTS = TLPPOINTS

type TAPP_LOCAL_DEVICE_ID = struct {
	Fvalue [32]TBYTE
}

type APP_LOCAL_DEVICE_ID = TAPP_LOCAL_DEVICE_ID

type TDPI_AWARENESS_CONTEXT__ = struct {
	Funused int32
}

type DPI_AWARENESS_CONTEXT__ = TDPI_AWARENESS_CONTEXT__

type TDPI_AWARENESS_CONTEXT = uintptr

type DPI_AWARENESS_CONTEXT = TDPI_AWARENESS_CONTEXT

type TDPI_AWARENESS = int32

type DPI_AWARENESS = TDPI_AWARENESS

type _DPI_AWARENESS = int32

const _DPI_AWARENESS_INVALID = -1
const _DPI_AWARENESS_UNAWARE = 0
const _DPI_AWARENESS_SYSTEM_AWARE = 1
const _DPI_AWARENESS_PER_MONITOR_AWARE = 2

type TDPI_HOSTING_BEHAVIOR = int32

type DPI_HOSTING_BEHAVIOR = TDPI_HOSTING_BEHAVIOR

type _DPI_HOSTING_BEHAVIOR = int32

const _DPI_HOSTING_BEHAVIOR_INVALID = -1
const _DPI_HOSTING_BEHAVIOR_DEFAULT = 0
const _DPI_HOSTING_BEHAVIOR_MIXED = 1

type TSECURITY_ATTRIBUTES = struct {
	FnLength              TDWORD
	FlpSecurityDescriptor TLPVOID
	FbInheritHandle       TWINBOOL
}

type SECURITY_ATTRIBUTES = TSECURITY_ATTRIBUTES

type T_SECURITY_ATTRIBUTES = TSECURITY_ATTRIBUTES

type _SECURITY_ATTRIBUTES = T_SECURITY_ATTRIBUTES

type TPSECURITY_ATTRIBUTES = uintptr

type PSECURITY_ATTRIBUTES = TPSECURITY_ATTRIBUTES

type TLPSECURITY_ATTRIBUTES = uintptr

type LPSECURITY_ATTRIBUTES = TLPSECURITY_ATTRIBUTES

type TOVERLAPPED = struct {
	FInternal     TULONG_PTR
	FInternalHigh TULONG_PTR
	F__ccgo2_8    struct {
		FPointer   [0]TPVOID
		F__ccgo0_0 struct {
			FOffset     TDWORD
			FOffsetHigh TDWORD
		}
	}
	FhEvent THANDLE
}

type OVERLAPPED = TOVERLAPPED

type T_OVERLAPPED = TOVERLAPPED

type _OVERLAPPED = T_OVERLAPPED

type TLPOVERLAPPED = uintptr

type LPOVERLAPPED = TLPOVERLAPPED

type TOVERLAPPED_ENTRY = struct {
	FlpCompletionKey            TULONG_PTR
	FlpOverlapped               TLPOVERLAPPED
	FInternal                   TULONG_PTR
	FdwNumberOfBytesTransferred TDWORD
}

type OVERLAPPED_ENTRY = TOVERLAPPED_ENTRY

type T_OVERLAPPED_ENTRY = TOVERLAPPED_ENTRY

type _OVERLAPPED_ENTRY = T_OVERLAPPED_ENTRY

type TLPOVERLAPPED_ENTRY = uintptr

type LPOVERLAPPED_ENTRY = TLPOVERLAPPED_ENTRY

type TSYSTEMTIME = struct {
	FwYear         TWORD
	FwMonth        TWORD
	FwDayOfWeek    TWORD
	FwDay          TWORD
	FwHour         TWORD
	FwMinute       TWORD
	FwSecond       TWORD
	FwMilliseconds TWORD
}

type SYSTEMTIME = TSYSTEMTIME

type T_SYSTEMTIME = TSYSTEMTIME

type _SYSTEMTIME = T_SYSTEMTIME

type TPSYSTEMTIME = uintptr

type PSYSTEMTIME = TPSYSTEMTIME

type TLPSYSTEMTIME = uintptr

type LPSYSTEMTIME = TLPSYSTEMTIME

type TWIN32_FIND_DATAA = struct {
	FdwFileAttributes   TDWORD
	FftCreationTime     TFILETIME
	FftLastAccessTime   TFILETIME
	FftLastWriteTime    TFILETIME
	FnFileSizeHigh      TDWORD
	FnFileSizeLow       TDWORD
	FdwReserved0        TDWORD
	FdwReserved1        TDWORD
	FcFileName          [260]TCHAR
	FcAlternateFileName [14]TCHAR
}

type WIN32_FIND_DATAA = TWIN32_FIND_DATAA

type T_WIN32_FIND_DATAA = TWIN32_FIND_DATAA

type _WIN32_FIND_DATAA = T_WIN32_FIND_DATAA

type TPWIN32_FIND_DATAA = uintptr

type PWIN32_FIND_DATAA = TPWIN32_FIND_DATAA

type TLPWIN32_FIND_DATAA = uintptr

type LPWIN32_FIND_DATAA = TLPWIN32_FIND_DATAA

type TWIN32_FIND_DATAW = struct {
	FdwFileAttributes   TDWORD
	FftCreationTime     TFILETIME
	FftLastAccessTime   TFILETIME
	FftLastWriteTime    TFILETIME
	FnFileSizeHigh      TDWORD
	FnFileSizeLow       TDWORD
	FdwReserved0        TDWORD
	FdwReserved1        TDWORD
	FcFileName          [260]TWCHAR
	FcAlternateFileName [14]TWCHAR
}

type WIN32_FIND_DATAW = TWIN32_FIND_DATAW

type T_WIN32_FIND_DATAW = TWIN32_FIND_DATAW

type _WIN32_FIND_DATAW = T_WIN32_FIND_DATAW

type TPWIN32_FIND_DATAW = uintptr

type PWIN32_FIND_DATAW = TPWIN32_FIND_DATAW

type TLPWIN32_FIND_DATAW = uintptr

type LPWIN32_FIND_DATAW = TLPWIN32_FIND_DATAW

type TWIN32_FIND_DATA = struct {
	FdwFileAttributes   TDWORD
	FftCreationTime     TFILETIME
	FftLastAccessTime   TFILETIME
	FftLastWriteTime    TFILETIME
	FnFileSizeHigh      TDWORD
	FnFileSizeLow       TDWORD
	FdwReserved0        TDWORD
	FdwReserved1        TDWORD
	FcFileName          [260]TCHAR
	FcAlternateFileName [14]TCHAR
}

type WIN32_FIND_DATA = TWIN32_FIND_DATA

type TPWIN32_FIND_DATA = uintptr

type PWIN32_FIND_DATA = TPWIN32_FIND_DATA

type TLPWIN32_FIND_DATA = uintptr

type LPWIN32_FIND_DATA = TLPWIN32_FIND_DATA

type TFINDEX_INFO_LEVELS = int32

type FINDEX_INFO_LEVELS = TFINDEX_INFO_LEVELS

type __FINDEX_INFO_LEVELS = int32

const _FindExInfoStandard = 0
const _FindExInfoBasic = 1
const _FindExInfoMaxInfoLevel = 2

type TFINDEX_SEARCH_OPS = int32

type FINDEX_SEARCH_OPS = TFINDEX_SEARCH_OPS

type __FINDEX_SEARCH_OPS = int32

const _FindExSearchNameMatch = 0
const _FindExSearchLimitToDirectories = 1
const _FindExSearchLimitToDevices = 2
const _FindExSearchMaxSearchOp = 3

type TGET_FILEEX_INFO_LEVELS = int32

type GET_FILEEX_INFO_LEVELS = TGET_FILEEX_INFO_LEVELS

type __GET_FILEEX_INFO_LEVELS = int32

const _GetFileExInfoStandard = 0
const _GetFileExMaxInfoLevel = 1

type TFILE_INFO_BY_HANDLE_CLASS = int32

type FILE_INFO_BY_HANDLE_CLASS = TFILE_INFO_BY_HANDLE_CLASS

type __FILE_INFO_BY_HANDLE_CLASS = int32

const _FileBasicInfo = 0
const _FileStandardInfo = 1
const _FileNameInfo = 2
const _FileRenameInfo = 3
const _FileDispositionInfo = 4
const _FileAllocationInfo = 5
const _FileEndOfFileInfo = 6
const _FileStreamInfo = 7
const _FileCompressionInfo = 8
const _FileAttributeTagInfo = 9
const _FileIdBothDirectoryInfo = 10
const _FileIdBothDirectoryRestartInfo = 11
const _FileIoPriorityHintInfo = 12
const _FileRemoteProtocolInfo = 13
const _FileFullDirectoryInfo = 14
const _FileFullDirectoryRestartInfo = 15
const _FileStorageInfo = 16
const _FileAlignmentInfo = 17
const _FileIdInfo = 18
const _FileIdExtdDirectoryInfo = 19
const _FileIdExtdDirectoryRestartInfo = 20
const _FileCaseSensitiveInfo = 21
const _FileNormalizedNameInfo = 22
const _MaximumFileInfoByHandleClass = 23

type TPFILE_INFO_BY_HANDLE_CLASS = uintptr

type PFILE_INFO_BY_HANDLE_CLASS = TPFILE_INFO_BY_HANDLE_CLASS

type TCRITICAL_SECTION = struct {
	FDebugInfo      TPRTL_CRITICAL_SECTION_DEBUG
	FLockCount      TLONG
	FRecursionCount TLONG
	FOwningThread   THANDLE
	FLockSemaphore  THANDLE
	FSpinCount      TULONG_PTR
}

type CRITICAL_SECTION = TCRITICAL_SECTION

type TPCRITICAL_SECTION = uintptr

type PCRITICAL_SECTION = TPCRITICAL_SECTION

type TLPCRITICAL_SECTION = uintptr

type LPCRITICAL_SECTION = TLPCRITICAL_SECTION

type TCRITICAL_SECTION_DEBUG = struct {
	FType                      TWORD
	FCreatorBackTraceIndex     TWORD
	FCriticalSection           uintptr
	FProcessLocksList          TLIST_ENTRY
	FEntryCount                TDWORD
	FContentionCount           TDWORD
	FFlags                     TDWORD
	FCreatorBackTraceIndexHigh TWORD
	FSpareWORD                 TWORD
}

type CRITICAL_SECTION_DEBUG = TCRITICAL_SECTION_DEBUG

type TPCRITICAL_SECTION_DEBUG = uintptr

type PCRITICAL_SECTION_DEBUG = TPCRITICAL_SECTION_DEBUG

type TLPCRITICAL_SECTION_DEBUG = uintptr

type LPCRITICAL_SECTION_DEBUG = TLPCRITICAL_SECTION_DEBUG

type TLPOVERLAPPED_COMPLETION_ROUTINE = uintptr

type LPOVERLAPPED_COMPLETION_ROUTINE = TLPOVERLAPPED_COMPLETION_ROUTINE

type TPROCESS_HEAP_ENTRY = struct {
	FlpData       TPVOID
	FcbData       TDWORD
	FcbOverhead   TBYTE
	FiRegionIndex TBYTE
	FwFlags       TWORD
	F__ccgo5_12   struct {
		FRegion [0]struct {
			FdwCommittedSize   TDWORD
			FdwUnCommittedSize TDWORD
			FlpFirstBlock      TLPVOID
			FlpLastBlock       TLPVOID
		}
		FBlock struct {
			FhMem       THANDLE
			FdwReserved [3]TDWORD
		}
	}
}

type PROCESS_HEAP_ENTRY = TPROCESS_HEAP_ENTRY

type T_PROCESS_HEAP_ENTRY = TPROCESS_HEAP_ENTRY

type _PROCESS_HEAP_ENTRY = T_PROCESS_HEAP_ENTRY

type TLPPROCESS_HEAP_ENTRY = uintptr

type LPPROCESS_HEAP_ENTRY = TLPPROCESS_HEAP_ENTRY

type TPPROCESS_HEAP_ENTRY = uintptr

type PPROCESS_HEAP_ENTRY = TPPROCESS_HEAP_ENTRY

type TREASON_CONTEXT = struct {
	FVersion TULONG
	FFlags   TDWORD
	FReason  struct {
		FSimpleReasonString [0]TLPWSTR
		FDetailed           struct {
			FLocalizedReasonModule THMODULE
			FLocalizedReasonId     TULONG
			FReasonStringCount     TULONG
			FReasonStrings         uintptr
		}
	}
}

type REASON_CONTEXT = TREASON_CONTEXT

type T_REASON_CONTEXT = TREASON_CONTEXT

type _REASON_CONTEXT = T_REASON_CONTEXT

type TPREASON_CONTEXT = uintptr

type PREASON_CONTEXT = TPREASON_CONTEXT

type TPTHREAD_START_ROUTINE = uintptr

type PTHREAD_START_ROUTINE = TPTHREAD_START_ROUTINE

type TLPTHREAD_START_ROUTINE = uintptr

type LPTHREAD_START_ROUTINE = TLPTHREAD_START_ROUTINE

type TPENCLAVE_ROUTINE = uintptr

type PENCLAVE_ROUTINE = TPENCLAVE_ROUTINE

type TLPENCLAVE_ROUTINE = uintptr

type LPENCLAVE_ROUTINE = TLPENCLAVE_ROUTINE

type TEXCEPTION_DEBUG_INFO = struct {
	FExceptionRecord TEXCEPTION_RECORD
	FdwFirstChance   TDWORD
}

type EXCEPTION_DEBUG_INFO = TEXCEPTION_DEBUG_INFO

type T_EXCEPTION_DEBUG_INFO = TEXCEPTION_DEBUG_INFO

type _EXCEPTION_DEBUG_INFO = T_EXCEPTION_DEBUG_INFO

type TLPEXCEPTION_DEBUG_INFO = uintptr

type LPEXCEPTION_DEBUG_INFO = TLPEXCEPTION_DEBUG_INFO

type TCREATE_THREAD_DEBUG_INFO = struct {
	FhThread           THANDLE
	FlpThreadLocalBase TLPVOID
	FlpStartAddress    TLPTHREAD_START_ROUTINE
}

type CREATE_THREAD_DEBUG_INFO = TCREATE_THREAD_DEBUG_INFO

type T_CREATE_THREAD_DEBUG_INFO = TCREATE_THREAD_DEBUG_INFO

type _CREATE_THREAD_DEBUG_INFO = T_CREATE_THREAD_DEBUG_INFO

type TLPCREATE_THREAD_DEBUG_INFO = uintptr

type LPCREATE_THREAD_DEBUG_INFO = TLPCREATE_THREAD_DEBUG_INFO

type TCREATE_PROCESS_DEBUG_INFO = struct {
	FhFile                 THANDLE
	FhProcess              THANDLE
	FhThread               THANDLE
	FlpBaseOfImage         TLPVOID
	FdwDebugInfoFileOffset TDWORD
	FnDebugInfoSize        TDWORD
	FlpThreadLocalBase     TLPVOID
	FlpStartAddress        TLPTHREAD_START_ROUTINE
	FlpImageName           TLPVOID
	FfUnicode              TWORD
}

type CREATE_PROCESS_DEBUG_INFO = TCREATE_PROCESS_DEBUG_INFO

type T_CREATE_PROCESS_DEBUG_INFO = TCREATE_PROCESS_DEBUG_INFO

type _CREATE_PROCESS_DEBUG_INFO = T_CREATE_PROCESS_DEBUG_INFO

type TLPCREATE_PROCESS_DEBUG_INFO = uintptr

type LPCREATE_PROCESS_DEBUG_INFO = TLPCREATE_PROCESS_DEBUG_INFO

type TEXIT_THREAD_DEBUG_INFO = struct {
	FdwExitCode TDWORD
}

type EXIT_THREAD_DEBUG_INFO = TEXIT_THREAD_DEBUG_INFO

type T_EXIT_THREAD_DEBUG_INFO = TEXIT_THREAD_DEBUG_INFO

type _EXIT_THREAD_DEBUG_INFO = T_EXIT_THREAD_DEBUG_INFO

type TLPEXIT_THREAD_DEBUG_INFO = uintptr

type LPEXIT_THREAD_DEBUG_INFO = TLPEXIT_THREAD_DEBUG_INFO

type TEXIT_PROCESS_DEBUG_INFO = struct {
	FdwExitCode TDWORD
}

type EXIT_PROCESS_DEBUG_INFO = TEXIT_PROCESS_DEBUG_INFO

type T_EXIT_PROCESS_DEBUG_INFO = TEXIT_PROCESS_DEBUG_INFO

type _EXIT_PROCESS_DEBUG_INFO = T_EXIT_PROCESS_DEBUG_INFO

type TLPEXIT_PROCESS_DEBUG_INFO = uintptr

type LPEXIT_PROCESS_DEBUG_INFO = TLPEXIT_PROCESS_DEBUG_INFO

type TLOAD_DLL_DEBUG_INFO = struct {
	FhFile                 THANDLE
	FlpBaseOfDll           TLPVOID
	FdwDebugInfoFileOffset TDWORD
	FnDebugInfoSize        TDWORD
	FlpImageName           TLPVOID
	FfUnicode              TWORD
}

type LOAD_DLL_DEBUG_INFO = TLOAD_DLL_DEBUG_INFO

type T_LOAD_DLL_DEBUG_INFO = TLOAD_DLL_DEBUG_INFO

type _LOAD_DLL_DEBUG_INFO = T_LOAD_DLL_DEBUG_INFO

type TLPLOAD_DLL_DEBUG_INFO = uintptr

type LPLOAD_DLL_DEBUG_INFO = TLPLOAD_DLL_DEBUG_INFO

type TUNLOAD_DLL_DEBUG_INFO = struct {
	FlpBaseOfDll TLPVOID
}

type UNLOAD_DLL_DEBUG_INFO = TUNLOAD_DLL_DEBUG_INFO

type T_UNLOAD_DLL_DEBUG_INFO = TUNLOAD_DLL_DEBUG_INFO

type _UNLOAD_DLL_DEBUG_INFO = T_UNLOAD_DLL_DEBUG_INFO

type TLPUNLOAD_DLL_DEBUG_INFO = uintptr

type LPUNLOAD_DLL_DEBUG_INFO = TLPUNLOAD_DLL_DEBUG_INFO

type TOUTPUT_DEBUG_STRING_INFO = struct {
	FlpDebugStringData  TLPSTR
	FfUnicode           TWORD
	FnDebugStringLength TWORD
}

type OUTPUT_DEBUG_STRING_INFO = TOUTPUT_DEBUG_STRING_INFO

type T_OUTPUT_DEBUG_STRING_INFO = TOUTPUT_DEBUG_STRING_INFO

type _OUTPUT_DEBUG_STRING_INFO = T_OUTPUT_DEBUG_STRING_INFO

type TLPOUTPUT_DEBUG_STRING_INFO = uintptr

type LPOUTPUT_DEBUG_STRING_INFO = TLPOUTPUT_DEBUG_STRING_INFO

type TRIP_INFO = struct {
	FdwError TDWORD
	FdwType  TDWORD
}

type RIP_INFO = TRIP_INFO

type T_RIP_INFO = TRIP_INFO

type _RIP_INFO = T_RIP_INFO

type TLPRIP_INFO = uintptr

type LPRIP_INFO = TLPRIP_INFO

type TDEBUG_EVENT = struct {
	FdwDebugEventCode TDWORD
	FdwProcessId      TDWORD
	FdwThreadId       TDWORD
	Fu                struct {
		FCreateThread      [0]TCREATE_THREAD_DEBUG_INFO
		FCreateProcessInfo [0]TCREATE_PROCESS_DEBUG_INFO
		FExitThread        [0]TEXIT_THREAD_DEBUG_INFO
		FExitProcess       [0]TEXIT_PROCESS_DEBUG_INFO
		FLoadDll           [0]TLOAD_DLL_DEBUG_INFO
		FUnloadDll         [0]TUNLOAD_DLL_DEBUG_INFO
		FDebugString       [0]TOUTPUT_DEBUG_STRING_INFO
		FRipInfo           [0]TRIP_INFO
		FException         TEXCEPTION_DEBUG_INFO
	}
}

type DEBUG_EVENT = TDEBUG_EVENT

type T_DEBUG_EVENT = TDEBUG_EVENT

type _DEBUG_EVENT = T_DEBUG_EVENT

type TLPDEBUG_EVENT = uintptr

type LPDEBUG_EVENT = TLPDEBUG_EVENT

type TLPCONTEXT = uintptr

type LPCONTEXT = TLPCONTEXT

type TBEM_FREE_INTERFACE_CALLBACK = uintptr

type BEM_FREE_INTERFACE_CALLBACK = TBEM_FREE_INTERFACE_CALLBACK

type TPTOP_LEVEL_EXCEPTION_FILTER = uintptr

type PTOP_LEVEL_EXCEPTION_FILTER = TPTOP_LEVEL_EXCEPTION_FILTER

type TLPTOP_LEVEL_EXCEPTION_FILTER = uintptr

type LPTOP_LEVEL_EXCEPTION_FILTER = TLPTOP_LEVEL_EXCEPTION_FILTER

type TBY_HANDLE_FILE_INFORMATION = struct {
	FdwFileAttributes     TDWORD
	FftCreationTime       TFILETIME
	FftLastAccessTime     TFILETIME
	FftLastWriteTime      TFILETIME
	FdwVolumeSerialNumber TDWORD
	FnFileSizeHigh        TDWORD
	FnFileSizeLow         TDWORD
	FnNumberOfLinks       TDWORD
	FnFileIndexHigh       TDWORD
	FnFileIndexLow        TDWORD
}

type BY_HANDLE_FILE_INFORMATION = TBY_HANDLE_FILE_INFORMATION

type T_BY_HANDLE_FILE_INFORMATION = TBY_HANDLE_FILE_INFORMATION

type _BY_HANDLE_FILE_INFORMATION = T_BY_HANDLE_FILE_INFORMATION

type TPBY_HANDLE_FILE_INFORMATION = uintptr

type PBY_HANDLE_FILE_INFORMATION = TPBY_HANDLE_FILE_INFORMATION

type TLPBY_HANDLE_FILE_INFORMATION = uintptr

type LPBY_HANDLE_FILE_INFORMATION = TLPBY_HANDLE_FILE_INFORMATION

type TWIN32_FILE_ATTRIBUTE_DATA = struct {
	FdwFileAttributes TDWORD
	FftCreationTime   TFILETIME
	FftLastAccessTime TFILETIME
	FftLastWriteTime  TFILETIME
	FnFileSizeHigh    TDWORD
	FnFileSizeLow     TDWORD
}

type WIN32_FILE_ATTRIBUTE_DATA = TWIN32_FILE_ATTRIBUTE_DATA

type T_WIN32_FILE_ATTRIBUTE_DATA = TWIN32_FILE_ATTRIBUTE_DATA

type _WIN32_FILE_ATTRIBUTE_DATA = T_WIN32_FILE_ATTRIBUTE_DATA

type TLPWIN32_FILE_ATTRIBUTE_DATA = uintptr

type LPWIN32_FILE_ATTRIBUTE_DATA = TLPWIN32_FILE_ATTRIBUTE_DATA

type TCREATEFILE2_EXTENDED_PARAMETERS = struct {
	FdwSize               TDWORD
	FdwFileAttributes     TDWORD
	FdwFileFlags          TDWORD
	FdwSecurityQosFlags   TDWORD
	FlpSecurityAttributes TLPSECURITY_ATTRIBUTES
	FhTemplateFile        THANDLE
}

type CREATEFILE2_EXTENDED_PARAMETERS = TCREATEFILE2_EXTENDED_PARAMETERS

type T_CREATEFILE2_EXTENDED_PARAMETERS = TCREATEFILE2_EXTENDED_PARAMETERS

type _CREATEFILE2_EXTENDED_PARAMETERS = T_CREATEFILE2_EXTENDED_PARAMETERS

type TPCREATEFILE2_EXTENDED_PARAMETERS = uintptr

type PCREATEFILE2_EXTENDED_PARAMETERS = TPCREATEFILE2_EXTENDED_PARAMETERS

type TLPCREATEFILE2_EXTENDED_PARAMETERS = uintptr

type LPCREATEFILE2_EXTENDED_PARAMETERS = TLPCREATEFILE2_EXTENDED_PARAMETERS

type THEAP_SUMMARY = struct {
	Fcb           TDWORD
	FcbAllocated  TSIZE_T
	FcbCommitted  TSIZE_T
	FcbReserved   TSIZE_T
	FcbMaxReserve TSIZE_T
}

type HEAP_SUMMARY = THEAP_SUMMARY

type T_HEAP_SUMMARY = THEAP_SUMMARY

type _HEAP_SUMMARY = T_HEAP_SUMMARY

type TPHEAP_SUMMARY = uintptr

type PHEAP_SUMMARY = TPHEAP_SUMMARY

type TLPHEAP_SUMMARY = uintptr

type LPHEAP_SUMMARY = TLPHEAP_SUMMARY

type TENUMUILANG = struct {
	FNumOfEnumUILang    TULONG
	FSizeOfEnumUIBuffer TULONG
	FpEnumUIBuffer      uintptr
}

type ENUMUILANG = TENUMUILANG

type TtagENUMUILANG = TENUMUILANG

type tagENUMUILANG = TtagENUMUILANG

type TPENUMUILANG = uintptr

type PENUMUILANG = TPENUMUILANG

type TENUMRESLANGPROCA = uintptr

type ENUMRESLANGPROCA = TENUMRESLANGPROCA

type TENUMRESLANGPROCW = uintptr

type ENUMRESLANGPROCW = TENUMRESLANGPROCW

type TENUMRESNAMEPROCA = uintptr

type ENUMRESNAMEPROCA = TENUMRESNAMEPROCA

type TENUMRESNAMEPROCW = uintptr

type ENUMRESNAMEPROCW = TENUMRESNAMEPROCW

type TENUMRESTYPEPROCA = uintptr

type ENUMRESTYPEPROCA = TENUMRESTYPEPROCA

type TENUMRESTYPEPROCW = uintptr

type ENUMRESTYPEPROCW = TENUMRESTYPEPROCW

type TPGET_MODULE_HANDLE_EXA = uintptr

type PGET_MODULE_HANDLE_EXA = TPGET_MODULE_HANDLE_EXA

type TPGET_MODULE_HANDLE_EXW = uintptr

type PGET_MODULE_HANDLE_EXW = TPGET_MODULE_HANDLE_EXW

type TDLL_DIRECTORY_COOKIE = uintptr

type DLL_DIRECTORY_COOKIE = TDLL_DIRECTORY_COOKIE

type TPDLL_DIRECTORY_COOKIE = uintptr

type PDLL_DIRECTORY_COOKIE = TPDLL_DIRECTORY_COOKIE

type TREDIRECTION_FUNCTION_DESCRIPTOR = struct {
	FDllName           TPCSTR
	FFunctionName      TPCSTR
	FRedirectionTarget TPVOID
}

type REDIRECTION_FUNCTION_DESCRIPTOR = TREDIRECTION_FUNCTION_DESCRIPTOR

type T_REDIRECTION_FUNCTION_DESCRIPTOR = TREDIRECTION_FUNCTION_DESCRIPTOR

type _REDIRECTION_FUNCTION_DESCRIPTOR = T_REDIRECTION_FUNCTION_DESCRIPTOR

type TPREDIRECTION_FUNCTION_DESCRIPTOR = uintptr

type PREDIRECTION_FUNCTION_DESCRIPTOR = TPREDIRECTION_FUNCTION_DESCRIPTOR

type TPCREDIRECTION_FUNCTION_DESCRIPTOR = uintptr

type PCREDIRECTION_FUNCTION_DESCRIPTOR = TPCREDIRECTION_FUNCTION_DESCRIPTOR

type TREDIRECTION_DESCRIPTOR = struct {
	FVersion       TULONG
	FFunctionCount TULONG
	FRedirections  TPCREDIRECTION_FUNCTION_DESCRIPTOR
}

type REDIRECTION_DESCRIPTOR = TREDIRECTION_DESCRIPTOR

type T_REDIRECTION_DESCRIPTOR = TREDIRECTION_DESCRIPTOR

type _REDIRECTION_DESCRIPTOR = T_REDIRECTION_DESCRIPTOR

type TPREDIRECTION_DESCRIPTOR = uintptr

type PREDIRECTION_DESCRIPTOR = TPREDIRECTION_DESCRIPTOR

type TPCREDIRECTION_DESCRIPTOR = uintptr

type PCREDIRECTION_DESCRIPTOR = TPCREDIRECTION_DESCRIPTOR

type TMEMORY_RESOURCE_NOTIFICATION_TYPE = int32

type MEMORY_RESOURCE_NOTIFICATION_TYPE = TMEMORY_RESOURCE_NOTIFICATION_TYPE

type __MEMORY_RESOURCE_NOTIFICATION_TYPE = int32

const _LowMemoryResourceNotification = 0
const _HighMemoryResourceNotification = 1

type TWIN32_MEMORY_RANGE_ENTRY = struct {
	FVirtualAddress TPVOID
	FNumberOfBytes  TSIZE_T
}

type WIN32_MEMORY_RANGE_ENTRY = TWIN32_MEMORY_RANGE_ENTRY

type T_WIN32_MEMORY_RANGE_ENTRY = TWIN32_MEMORY_RANGE_ENTRY

type _WIN32_MEMORY_RANGE_ENTRY = T_WIN32_MEMORY_RANGE_ENTRY

type TPWIN32_MEMORY_RANGE_ENTRY = uintptr

type PWIN32_MEMORY_RANGE_ENTRY = TPWIN32_MEMORY_RANGE_ENTRY

type TPBAD_MEMORY_CALLBACK_ROUTINE = uintptr

type PBAD_MEMORY_CALLBACK_ROUTINE = TPBAD_MEMORY_CALLBACK_ROUTINE

type TOFFER_PRIORITY = int32

type OFFER_PRIORITY = TOFFER_PRIORITY

type __OFFER_PRIORITY = int32

const _VmOfferPriorityVeryLow = 1
const _VmOfferPriorityLow = 2
const _VmOfferPriorityBelowNormal = 3
const _VmOfferPriorityNormal = 4

type TSTARTUPINFOA = struct {
	Fcb              TDWORD
	FlpReserved      TLPSTR
	FlpDesktop       TLPSTR
	FlpTitle         TLPSTR
	FdwX             TDWORD
	FdwY             TDWORD
	FdwXSize         TDWORD
	FdwYSize         TDWORD
	FdwXCountChars   TDWORD
	FdwYCountChars   TDWORD
	FdwFillAttribute TDWORD
	FdwFlags         TDWORD
	FwShowWindow     TWORD
	FcbReserved2     TWORD
	FlpReserved2     TLPBYTE
	FhStdInput       THANDLE
	FhStdOutput      THANDLE
	FhStdError       THANDLE
}

type STARTUPINFOA = TSTARTUPINFOA

type T_STARTUPINFOA = TSTARTUPINFOA

type _STARTUPINFOA = T_STARTUPINFOA

type TLPSTARTUPINFOA = uintptr

type LPSTARTUPINFOA = TLPSTARTUPINFOA

type TSTARTUPINFOW = struct {
	Fcb              TDWORD
	FlpReserved      TLPWSTR
	FlpDesktop       TLPWSTR
	FlpTitle         TLPWSTR
	FdwX             TDWORD
	FdwY             TDWORD
	FdwXSize         TDWORD
	FdwYSize         TDWORD
	FdwXCountChars   TDWORD
	FdwYCountChars   TDWORD
	FdwFillAttribute TDWORD
	FdwFlags         TDWORD
	FwShowWindow     TWORD
	FcbReserved2     TWORD
	FlpReserved2     TLPBYTE
	FhStdInput       THANDLE
	FhStdOutput      THANDLE
	FhStdError       THANDLE
}

type STARTUPINFOW = TSTARTUPINFOW

type T_STARTUPINFOW = TSTARTUPINFOW

type _STARTUPINFOW = T_STARTUPINFOW

type TLPSTARTUPINFOW = uintptr

type LPSTARTUPINFOW = TLPSTARTUPINFOW

type TSTARTUPINFO = struct {
	Fcb              TDWORD
	FlpReserved      TLPSTR
	FlpDesktop       TLPSTR
	FlpTitle         TLPSTR
	FdwX             TDWORD
	FdwY             TDWORD
	FdwXSize         TDWORD
	FdwYSize         TDWORD
	FdwXCountChars   TDWORD
	FdwYCountChars   TDWORD
	FdwFillAttribute TDWORD
	FdwFlags         TDWORD
	FwShowWindow     TWORD
	FcbReserved2     TWORD
	FlpReserved2     TLPBYTE
	FhStdInput       THANDLE
	FhStdOutput      THANDLE
	FhStdError       THANDLE
}

type STARTUPINFO = TSTARTUPINFO

type TLPSTARTUPINFO = uintptr

type LPSTARTUPINFO = TLPSTARTUPINFO

type TPROCESS_INFORMATION = struct {
	FhProcess    THANDLE
	FhThread     THANDLE
	FdwProcessId TDWORD
	FdwThreadId  TDWORD
}

type PROCESS_INFORMATION = TPROCESS_INFORMATION

type T_PROCESS_INFORMATION = TPROCESS_INFORMATION

type _PROCESS_INFORMATION = T_PROCESS_INFORMATION

type TPPROCESS_INFORMATION = uintptr

type PPROCESS_INFORMATION = TPPROCESS_INFORMATION

type TLPPROCESS_INFORMATION = uintptr

type LPPROCESS_INFORMATION = TLPPROCESS_INFORMATION

type TPROCESS_INFORMATION_CLASS = int32

type PROCESS_INFORMATION_CLASS = TPROCESS_INFORMATION_CLASS

type __PROCESS_INFORMATION_CLASS = int32

const _ProcessMemoryPriority = 0
const _ProcessMemoryExhaustionInfo = 1
const _ProcessAppMemoryInfo = 2
const _ProcessInPrivateInfo = 3
const _ProcessPowerThrottling = 4
const _ProcessReservedValue1 = 5
const _ProcessTelemetryCoverageInfo = 6
const _ProcessProtectionLevelInfo = 7
const _ProcessLeapSecondInfo = 8
const _ProcessMachineTypeInfo = 9
const _ProcessInformationClassMax = 10

type TAPP_MEMORY_INFORMATION = struct {
	F__ccgo_align           [0]uint32
	FAvailableCommit        TULONG64
	FPrivateCommitUsage     TULONG64
	FPeakPrivateCommitUsage TULONG64
	FTotalCommitUsage       TULONG64
}

type APP_MEMORY_INFORMATION = TAPP_MEMORY_INFORMATION

type T_APP_MEMORY_INFORMATION = TAPP_MEMORY_INFORMATION

type _APP_MEMORY_INFORMATION = T_APP_MEMORY_INFORMATION

type TPAPP_MEMORY_INFORMATION = uintptr

type PAPP_MEMORY_INFORMATION = TPAPP_MEMORY_INFORMATION

type TMACHINE_ATTRIBUTES = int32

type MACHINE_ATTRIBUTES = TMACHINE_ATTRIBUTES

type __MACHINE_ATTRIBUTES = int32

const _UserEnabled = 1
const _KernelEnabled = 2
const _Wow64Container = 4

type TPROCESS_MACHINE_INFORMATION = struct {
	FProcessMachine    TUSHORT
	FRes0              TUSHORT
	FMachineAttributes TMACHINE_ATTRIBUTES
}

type PROCESS_MACHINE_INFORMATION = TPROCESS_MACHINE_INFORMATION

type T_PROCESS_MACHINE_INFORMATION = TPROCESS_MACHINE_INFORMATION

type _PROCESS_MACHINE_INFORMATION = T_PROCESS_MACHINE_INFORMATION

type TPROCESS_MEMORY_EXHAUSTION_TYPE = int32

type PROCESS_MEMORY_EXHAUSTION_TYPE = TPROCESS_MEMORY_EXHAUSTION_TYPE

type __PROCESS_MEMORY_EXHAUSTION_TYPE = int32

const _PMETypeFailFastOnCommitFailure = 0
const _PMETypeMax = 1

type TPPROCESS_MEMORY_EXHAUSTION_TYPE = uintptr

type PPROCESS_MEMORY_EXHAUSTION_TYPE = TPPROCESS_MEMORY_EXHAUSTION_TYPE

type TPROCESS_MEMORY_EXHAUSTION_INFO = struct {
	FVersion  TUSHORT
	FReserved TUSHORT
	FType     TPROCESS_MEMORY_EXHAUSTION_TYPE
	FValue    TULONG_PTR
}

type PROCESS_MEMORY_EXHAUSTION_INFO = TPROCESS_MEMORY_EXHAUSTION_INFO

type T_PROCESS_MEMORY_EXHAUSTION_INFO = TPROCESS_MEMORY_EXHAUSTION_INFO

type _PROCESS_MEMORY_EXHAUSTION_INFO = T_PROCESS_MEMORY_EXHAUSTION_INFO

type TPPROCESS_MEMORY_EXHAUSTION_INFO = uintptr

type PPROCESS_MEMORY_EXHAUSTION_INFO = TPPROCESS_MEMORY_EXHAUSTION_INFO

type TPROCESS_POWER_THROTTLING_STATE = struct {
	FVersion     TULONG
	FControlMask TULONG
	FStateMask   TULONG
}

type PROCESS_POWER_THROTTLING_STATE = TPROCESS_POWER_THROTTLING_STATE

type T_PROCESS_POWER_THROTTLING_STATE = TPROCESS_POWER_THROTTLING_STATE

type _PROCESS_POWER_THROTTLING_STATE = T_PROCESS_POWER_THROTTLING_STATE

type TPPROCESS_POWER_THROTTLING_STATE = uintptr

type PPROCESS_POWER_THROTTLING_STATE = TPPROCESS_POWER_THROTTLING_STATE

type TPROCESS_PROTECTION_LEVEL_INFORMATION = struct {
	FProtectionLevel TDWORD
}

type PROCESS_PROTECTION_LEVEL_INFORMATION = TPROCESS_PROTECTION_LEVEL_INFORMATION

type TPROCESS_LEAP_SECOND_INFO = struct {
	FFlags    TULONG
	FReserved TULONG
}

type PROCESS_LEAP_SECOND_INFO = TPROCESS_LEAP_SECOND_INFO

type T_PROCESS_LEAP_SECOND_INFO = TPROCESS_LEAP_SECOND_INFO

type _PROCESS_LEAP_SECOND_INFO = T_PROCESS_LEAP_SECOND_INFO

type TPPROCESS_LEAP_SECOND_INFO = uintptr

type PPROCESS_LEAP_SECOND_INFO = TPPROCESS_LEAP_SECOND_INFO

type TPPROC_THREAD_ATTRIBUTE_LIST = uintptr

type PPROC_THREAD_ATTRIBUTE_LIST = TPPROC_THREAD_ATTRIBUTE_LIST

type TLPPROC_THREAD_ATTRIBUTE_LIST = uintptr

type LPPROC_THREAD_ATTRIBUTE_LIST = TLPPROC_THREAD_ATTRIBUTE_LIST

type TMEMORY_PRIORITY_INFORMATION = struct {
	FMemoryPriority TULONG
}

type MEMORY_PRIORITY_INFORMATION = TMEMORY_PRIORITY_INFORMATION

type T_MEMORY_PRIORITY_INFORMATION = TMEMORY_PRIORITY_INFORMATION

type _MEMORY_PRIORITY_INFORMATION = T_MEMORY_PRIORITY_INFORMATION

type TPMEMORY_PRIORITY_INFORMATION = uintptr

type PMEMORY_PRIORITY_INFORMATION = TPMEMORY_PRIORITY_INFORMATION

type TSRWLOCK = struct {
	FPtr TPVOID
}

type SRWLOCK = TSRWLOCK

type TPSRWLOCK = uintptr

type PSRWLOCK = TPSRWLOCK

type TINIT_ONCE = struct {
	FPtr TPVOID
}

type INIT_ONCE = TINIT_ONCE

type TPINIT_ONCE = uintptr

type PINIT_ONCE = TPINIT_ONCE

type TLPINIT_ONCE = uintptr

type LPINIT_ONCE = TLPINIT_ONCE

type TPINIT_ONCE_FN = uintptr

type PINIT_ONCE_FN = TPINIT_ONCE_FN

type TCONDITION_VARIABLE = struct {
	FPtr TPVOID
}

type CONDITION_VARIABLE = TCONDITION_VARIABLE

type TPCONDITION_VARIABLE = uintptr

type PCONDITION_VARIABLE = TPCONDITION_VARIABLE

type TPTIMERAPCROUTINE = uintptr

type PTIMERAPCROUTINE = TPTIMERAPCROUTINE

type TSYNCHRONIZATION_BARRIER = struct {
	FReserved1 TDWORD
	FReserved2 TDWORD
	FReserved3 [2]TULONG_PTR
	FReserved4 TDWORD
	FReserved5 TDWORD
}

type SYNCHRONIZATION_BARRIER = TSYNCHRONIZATION_BARRIER

type TPSYNCHRONIZATION_BARRIER = uintptr

type PSYNCHRONIZATION_BARRIER = TPSYNCHRONIZATION_BARRIER

type TLPSYNCHRONIZATION_BARRIER = uintptr

type LPSYNCHRONIZATION_BARRIER = TLPSYNCHRONIZATION_BARRIER

type TSYSTEM_INFO = struct {
	F__ccgo0_0 struct {
		F__ccgo1_0 [0]struct {
			FwProcessorArchitecture TWORD
			FwReserved              TWORD
		}
		FdwOemId TDWORD
	}
	FdwPageSize                  TDWORD
	FlpMinimumApplicationAddress TLPVOID
	FlpMaximumApplicationAddress TLPVOID
	FdwActiveProcessorMask       TDWORD_PTR
	FdwNumberOfProcessors        TDWORD
	FdwProcessorType             TDWORD
	FdwAllocationGranularity     TDWORD
	FwProcessorLevel             TWORD
	FwProcessorRevision          TWORD
}

type SYSTEM_INFO = TSYSTEM_INFO

type T_SYSTEM_INFO = TSYSTEM_INFO

type _SYSTEM_INFO = T_SYSTEM_INFO

type TLPSYSTEM_INFO = uintptr

type LPSYSTEM_INFO = TLPSYSTEM_INFO

type TMEMORYSTATUSEX = struct {
	F__ccgo_align            [0]uint32
	FdwLength                TDWORD
	FdwMemoryLoad            TDWORD
	FullTotalPhys            TDWORDLONG
	FullAvailPhys            TDWORDLONG
	FullTotalPageFile        TDWORDLONG
	FullAvailPageFile        TDWORDLONG
	FullTotalVirtual         TDWORDLONG
	FullAvailVirtual         TDWORDLONG
	FullAvailExtendedVirtual TDWORDLONG
}

type MEMORYSTATUSEX = TMEMORYSTATUSEX

type T_MEMORYSTATUSEX = TMEMORYSTATUSEX

type _MEMORYSTATUSEX = T_MEMORYSTATUSEX

type TLPMEMORYSTATUSEX = uintptr

type LPMEMORYSTATUSEX = TLPMEMORYSTATUSEX

type TCOMPUTER_NAME_FORMAT = int32

type COMPUTER_NAME_FORMAT = TCOMPUTER_NAME_FORMAT

type __COMPUTER_NAME_FORMAT = int32

const _ComputerNameNetBIOS = 0
const _ComputerNameDnsHostname = 1
const _ComputerNameDnsDomain = 2
const _ComputerNameDnsFullyQualified = 3
const _ComputerNamePhysicalNetBIOS = 4
const _ComputerNamePhysicalDnsHostname = 5
const _ComputerNamePhysicalDnsDomain = 6
const _ComputerNamePhysicalDnsFullyQualified = 7
const _ComputerNameMax = 8

type TPTP_WIN32_IO_CALLBACK = uintptr

type PTP_WIN32_IO_CALLBACK = TPTP_WIN32_IO_CALLBACK

type TPFIBER_START_ROUTINE = uintptr

type PFIBER_START_ROUTINE = TPFIBER_START_ROUTINE

type TLPFIBER_START_ROUTINE = uintptr

type LPFIBER_START_ROUTINE = TLPFIBER_START_ROUTINE

type TPFIBER_CALLOUT_ROUTINE = uintptr

type PFIBER_CALLOUT_ROUTINE = TPFIBER_CALLOUT_ROUTINE

type TLPLDT_ENTRY = uintptr

type LPLDT_ENTRY = TLPLDT_ENTRY

type TCOMMPROP = struct {
	FwPacketLength       TWORD
	FwPacketVersion      TWORD
	FdwServiceMask       TDWORD
	FdwReserved1         TDWORD
	FdwMaxTxQueue        TDWORD
	FdwMaxRxQueue        TDWORD
	FdwMaxBaud           TDWORD
	FdwProvSubType       TDWORD
	FdwProvCapabilities  TDWORD
	FdwSettableParams    TDWORD
	FdwSettableBaud      TDWORD
	FwSettableData       TWORD
	FwSettableStopParity TWORD
	FdwCurrentTxQueue    TDWORD
	FdwCurrentRxQueue    TDWORD
	FdwProvSpec1         TDWORD
	FdwProvSpec2         TDWORD
	FwcProvChar          [1]TWCHAR
}

type COMMPROP = TCOMMPROP

type T_COMMPROP = TCOMMPROP

type _COMMPROP = T_COMMPROP

type TLPCOMMPROP = uintptr

type LPCOMMPROP = TLPCOMMPROP

type TCOMSTAT = struct {
	F__ccgo0  uint32
	FcbInQue  TDWORD
	FcbOutQue TDWORD
}

type COMSTAT = TCOMSTAT

type T_COMSTAT = TCOMSTAT

type _COMSTAT = T_COMSTAT

type TLPCOMSTAT = uintptr

type LPCOMSTAT = TLPCOMSTAT

type TDCB = struct {
	FDCBlength  TDWORD
	FBaudRate   TDWORD
	F__ccgo8    uint32
	FwReserved  TWORD
	FXonLim     TWORD
	FXoffLim    TWORD
	FByteSize   TBYTE
	FParity     TBYTE
	FStopBits   TBYTE
	FXonChar    int8
	FXoffChar   int8
	FErrorChar  int8
	FEofChar    int8
	FEvtChar    int8
	FwReserved1 TWORD
}

type DCB = TDCB

type T_DCB = TDCB

type _DCB = T_DCB

type TLPDCB = uintptr

type LPDCB = TLPDCB

type TCOMMTIMEOUTS = struct {
	FReadIntervalTimeout         TDWORD
	FReadTotalTimeoutMultiplier  TDWORD
	FReadTotalTimeoutConstant    TDWORD
	FWriteTotalTimeoutMultiplier TDWORD
	FWriteTotalTimeoutConstant   TDWORD
}

type COMMTIMEOUTS = TCOMMTIMEOUTS

type T_COMMTIMEOUTS = TCOMMTIMEOUTS

type _COMMTIMEOUTS = T_COMMTIMEOUTS

type TLPCOMMTIMEOUTS = uintptr

type LPCOMMTIMEOUTS = TLPCOMMTIMEOUTS

type TCOMMCONFIG = struct {
	FdwSize            TDWORD
	FwVersion          TWORD
	FwReserved         TWORD
	Fdcb               TDCB
	FdwProviderSubType TDWORD
	FdwProviderOffset  TDWORD
	FdwProviderSize    TDWORD
	FwcProviderData    [1]TWCHAR
}

type COMMCONFIG = TCOMMCONFIG

type T_COMMCONFIG = TCOMMCONFIG

type _COMMCONFIG = T_COMMCONFIG

type TLPCOMMCONFIG = uintptr

type LPCOMMCONFIG = TLPCOMMCONFIG

type TMEMORYSTATUS = struct {
	FdwLength        TDWORD
	FdwMemoryLoad    TDWORD
	FdwTotalPhys     TSIZE_T
	FdwAvailPhys     TSIZE_T
	FdwTotalPageFile TSIZE_T
	FdwAvailPageFile TSIZE_T
	FdwTotalVirtual  TSIZE_T
	FdwAvailVirtual  TSIZE_T
}

type MEMORYSTATUS = TMEMORYSTATUS

type T_MEMORYSTATUS = TMEMORYSTATUS

type _MEMORYSTATUS = T_MEMORYSTATUS

type TLPMEMORYSTATUS = uintptr

type LPMEMORYSTATUS = TLPMEMORYSTATUS

type TJIT_DEBUG_INFO = struct {
	F__ccgo_align            [0]uint32
	FdwSize                  TDWORD
	FdwProcessorArchitecture TDWORD
	FdwThreadID              TDWORD
	FdwReserved0             TDWORD
	FlpExceptionAddress      TULONG64
	FlpExceptionRecord       TULONG64
	FlpContextRecord         TULONG64
}

type JIT_DEBUG_INFO = TJIT_DEBUG_INFO

type T_JIT_DEBUG_INFO = TJIT_DEBUG_INFO

type _JIT_DEBUG_INFO = T_JIT_DEBUG_INFO

type TLPJIT_DEBUG_INFO = uintptr

type LPJIT_DEBUG_INFO = TLPJIT_DEBUG_INFO

type TJIT_DEBUG_INFO32 = struct {
	F__ccgo_align            [0]uint32
	FdwSize                  TDWORD
	FdwProcessorArchitecture TDWORD
	FdwThreadID              TDWORD
	FdwReserved0             TDWORD
	FlpExceptionAddress      TULONG64
	FlpExceptionRecord       TULONG64
	FlpContextRecord         TULONG64
}

type JIT_DEBUG_INFO32 = TJIT_DEBUG_INFO32

type TLPJIT_DEBUG_INFO32 = uintptr

type LPJIT_DEBUG_INFO32 = TLPJIT_DEBUG_INFO32

type TJIT_DEBUG_INFO64 = struct {
	F__ccgo_align            [0]uint32
	FdwSize                  TDWORD
	FdwProcessorArchitecture TDWORD
	FdwThreadID              TDWORD
	FdwReserved0             TDWORD
	FlpExceptionAddress      TULONG64
	FlpExceptionRecord       TULONG64
	FlpContextRecord         TULONG64
}

type JIT_DEBUG_INFO64 = TJIT_DEBUG_INFO64

type TLPJIT_DEBUG_INFO64 = uintptr

type LPJIT_DEBUG_INFO64 = TLPJIT_DEBUG_INFO64

type TLPEXCEPTION_RECORD = uintptr

type LPEXCEPTION_RECORD = TLPEXCEPTION_RECORD

type TLPEXCEPTION_POINTERS = uintptr

type LPEXCEPTION_POINTERS = TLPEXCEPTION_POINTERS

type TOFSTRUCT = struct {
	FcBytes     TBYTE
	FfFixedDisk TBYTE
	FnErrCode   TWORD
	FReserved1  TWORD
	FReserved2  TWORD
	FszPathName [128]TCHAR
}

type OFSTRUCT = TOFSTRUCT

type T_OFSTRUCT = TOFSTRUCT

type _OFSTRUCT = T_OFSTRUCT

type TLPOFSTRUCT = uintptr

type LPOFSTRUCT = TLPOFSTRUCT

type TPOFSTRUCT = uintptr

type POFSTRUCT = TPOFSTRUCT

type TTHREAD_INFORMATION_CLASS = int32

type THREAD_INFORMATION_CLASS = TTHREAD_INFORMATION_CLASS

type __THREAD_INFORMATION_CLASS = int32

const _ThreadMemoryPriority = 0
const _ThreadAbsoluteCpuPriority = 1
const _ThreadDynamicCodePolicy = 2
const _ThreadPowerThrottling = 3
const _ThreadInformationClassMax = 4

type TPOWER_REQUEST_CONTEXT = struct {
	FVersion TULONG
	FFlags   TDWORD
	FReason  struct {
		FSimpleReasonString [0]TLPWSTR
		FDetailed           struct {
			FLocalizedReasonModule THMODULE
			FLocalizedReasonId     TULONG
			FReasonStringCount     TULONG
			FReasonStrings         uintptr
		}
	}
}

type POWER_REQUEST_CONTEXT = TPOWER_REQUEST_CONTEXT

type TPPOWER_REQUEST_CONTEXT = uintptr

type PPOWER_REQUEST_CONTEXT = TPPOWER_REQUEST_CONTEXT

type TLPPOWER_REQUEST_CONTEXT = uintptr

type LPPOWER_REQUEST_CONTEXT = TLPPOWER_REQUEST_CONTEXT

type TDEP_SYSTEM_POLICY_TYPE = int32

type DEP_SYSTEM_POLICY_TYPE = TDEP_SYSTEM_POLICY_TYPE

type __DEP_SYSTEM_POLICY_TYPE = int32

const _DEPPolicyAlwaysOff = 0
const _DEPPolicyAlwaysOn = 1
const _DEPPolicyOptIn = 2
const _DEPPolicyOptOut = 3
const _DEPTotalPolicyCount = 4

type TPFE_EXPORT_FUNC = uintptr

type PFE_EXPORT_FUNC = TPFE_EXPORT_FUNC

type TPFE_IMPORT_FUNC = uintptr

type PFE_IMPORT_FUNC = TPFE_IMPORT_FUNC

type TWIN32_STREAM_ID = struct {
	F__ccgo_align       [0]uint32
	FdwStreamId         TDWORD
	FdwStreamAttributes TDWORD
	FSize               TLARGE_INTEGER
	FdwStreamNameSize   TDWORD
	FcStreamName        [1]TWCHAR
	F__ccgo_pad5        [2]byte
}

type WIN32_STREAM_ID = TWIN32_STREAM_ID

type T_WIN32_STREAM_ID = TWIN32_STREAM_ID

type _WIN32_STREAM_ID = T_WIN32_STREAM_ID

type TLPWIN32_STREAM_ID = uintptr

type LPWIN32_STREAM_ID = TLPWIN32_STREAM_ID

type TSTARTUPINFOEXA = struct {
	FStartupInfo     TSTARTUPINFOA
	FlpAttributeList TLPPROC_THREAD_ATTRIBUTE_LIST
}

type STARTUPINFOEXA = TSTARTUPINFOEXA

type T_STARTUPINFOEXA = TSTARTUPINFOEXA

type _STARTUPINFOEXA = T_STARTUPINFOEXA

type TLPSTARTUPINFOEXA = uintptr

type LPSTARTUPINFOEXA = TLPSTARTUPINFOEXA

type TSTARTUPINFOEXW = struct {
	FStartupInfo     TSTARTUPINFOW
	FlpAttributeList TLPPROC_THREAD_ATTRIBUTE_LIST
}

type STARTUPINFOEXW = TSTARTUPINFOEXW

type T_STARTUPINFOEXW = TSTARTUPINFOEXW

type _STARTUPINFOEXW = T_STARTUPINFOEXW

type TLPSTARTUPINFOEXW = uintptr

type LPSTARTUPINFOEXW = TLPSTARTUPINFOEXW

type TSTARTUPINFOEX = struct {
	FStartupInfo     TSTARTUPINFOA
	FlpAttributeList TLPPROC_THREAD_ATTRIBUTE_LIST
}

type STARTUPINFOEX = TSTARTUPINFOEX

type TLPSTARTUPINFOEX = uintptr

type LPSTARTUPINFOEX = TLPSTARTUPINFOEX

type TPROC_THREAD_ATTRIBUTE_NUM = int32

type PROC_THREAD_ATTRIBUTE_NUM = TPROC_THREAD_ATTRIBUTE_NUM

type __PROC_THREAD_ATTRIBUTE_NUM = int32

const _ProcThreadAttributeParentProcess = 0
const _ProcThreadAttributeHandleList = 2
const _ProcThreadAttributeGroupAffinity = 3
const _ProcThreadAttributePreferredNode = 4
const _ProcThreadAttributeIdealProcessor = 5
const _ProcThreadAttributeUmsThread = 6
const _ProcThreadAttributeMitigationPolicy = 7
const _ProcThreadAttributeSecurityCapabilities = 9
const _ProcThreadAttributeProtectionLevel = 11
const _ProcThreadAttributeJobList = 13
const _ProcThreadAttributeChildProcessPolicy = 14
const _ProcThreadAttributeAllApplicationPackagesPolicy = 15
const _ProcThreadAttributeWin32kFilter = 16

type TPGET_SYSTEM_WOW64_DIRECTORY_A = uintptr

type PGET_SYSTEM_WOW64_DIRECTORY_A = TPGET_SYSTEM_WOW64_DIRECTORY_A

type TPGET_SYSTEM_WOW64_DIRECTORY_W = uintptr

type PGET_SYSTEM_WOW64_DIRECTORY_W = TPGET_SYSTEM_WOW64_DIRECTORY_W

type TLPPROGRESS_ROUTINE = uintptr

type LPPROGRESS_ROUTINE = TLPPROGRESS_ROUTINE

type TCOPYFILE2_MESSAGE_TYPE = int32

type COPYFILE2_MESSAGE_TYPE = TCOPYFILE2_MESSAGE_TYPE

type __COPYFILE2_MESSAGE_TYPE = int32

const _COPYFILE2_CALLBACK_NONE = 0
const _COPYFILE2_CALLBACK_CHUNK_STARTED = 1
const _COPYFILE2_CALLBACK_CHUNK_FINISHED = 2
const _COPYFILE2_CALLBACK_STREAM_STARTED = 3
const _COPYFILE2_CALLBACK_STREAM_FINISHED = 4
const _COPYFILE2_CALLBACK_POLL_CONTINUE = 5
const _COPYFILE2_CALLBACK_ERROR = 6
const _COPYFILE2_CALLBACK_MAX = 7

type TCOPYFILE2_MESSAGE_ACTION = int32

type COPYFILE2_MESSAGE_ACTION = TCOPYFILE2_MESSAGE_ACTION

type __COPYFILE2_MESSAGE_ACTION = int32

const _COPYFILE2_PROGRESS_CONTINUE = 0
const _COPYFILE2_PROGRESS_CANCEL = 1
const _COPYFILE2_PROGRESS_STOP = 2
const _COPYFILE2_PROGRESS_QUIET = 3
const _COPYFILE2_PROGRESS_PAUSE = 4

type TCOPYFILE2_COPY_PHASE = int32

type COPYFILE2_COPY_PHASE = TCOPYFILE2_COPY_PHASE

type __COPYFILE2_COPY_PHASE = int32

const _COPYFILE2_PHASE_NONE = 0
const _COPYFILE2_PHASE_PREPARE_SOURCE = 1
const _COPYFILE2_PHASE_PREPARE_DEST = 2
const _COPYFILE2_PHASE_READ_SOURCE = 3
const _COPYFILE2_PHASE_WRITE_DESTINATION = 4
const _COPYFILE2_PHASE_SERVER_COPY = 5
const _COPYFILE2_PHASE_NAMEGRAFT_COPY = 6
const _COPYFILE2_PHASE_MAX = 7

type TCOPYFILE2_MESSAGE = struct {
	F__ccgo_align [0]uint32
	FType         TCOPYFILE2_MESSAGE_TYPE
	FdwPadding    TDWORD
	FInfo         struct {
		F__ccgo_align  [0]uint32
		FChunkFinished [0]struct {
			F__ccgo_align              [0]uint32
			FdwStreamNumber            TDWORD
			FdwFlags                   TDWORD
			FhSourceFile               THANDLE
			FhDestinationFile          THANDLE
			FuliChunkNumber            TULARGE_INTEGER
			FuliChunkSize              TULARGE_INTEGER
			FuliStreamSize             TULARGE_INTEGER
			FuliStreamBytesTransferred TULARGE_INTEGER
			FuliTotalFileSize          TULARGE_INTEGER
			FuliTotalBytesTransferred  TULARGE_INTEGER
		}
		FStreamStarted [0]struct {
			F__ccgo_align     [0]uint32
			FdwStreamNumber   TDWORD
			FdwReserved       TDWORD
			FhSourceFile      THANDLE
			FhDestinationFile THANDLE
			FuliStreamSize    TULARGE_INTEGER
			FuliTotalFileSize TULARGE_INTEGER
		}
		FStreamFinished [0]struct {
			F__ccgo_align              [0]uint32
			FdwStreamNumber            TDWORD
			FdwReserved                TDWORD
			FhSourceFile               THANDLE
			FhDestinationFile          THANDLE
			FuliStreamSize             TULARGE_INTEGER
			FuliStreamBytesTransferred TULARGE_INTEGER
			FuliTotalFileSize          TULARGE_INTEGER
			FuliTotalBytesTransferred  TULARGE_INTEGER
		}
		FPollContinue [0]struct {
			FdwReserved TDWORD
		}
		FError [0]struct {
			F__ccgo_align              [0]uint32
			FCopyPhase                 TCOPYFILE2_COPY_PHASE
			FdwStreamNumber            TDWORD
			FhrFailure                 THRESULT
			FdwReserved                TDWORD
			FuliChunkNumber            TULARGE_INTEGER
			FuliStreamSize             TULARGE_INTEGER
			FuliStreamBytesTransferred TULARGE_INTEGER
			FuliTotalFileSize          TULARGE_INTEGER
			FuliTotalBytesTransferred  TULARGE_INTEGER
		}
		FChunkStarted struct {
			F__ccgo_align     [0]uint32
			FdwStreamNumber   TDWORD
			FdwReserved       TDWORD
			FhSourceFile      THANDLE
			FhDestinationFile THANDLE
			FuliChunkNumber   TULARGE_INTEGER
			FuliChunkSize     TULARGE_INTEGER
			FuliStreamSize    TULARGE_INTEGER
			FuliTotalFileSize TULARGE_INTEGER
		}
		F__ccgo_pad6 [16]byte
	}
}

type COPYFILE2_MESSAGE = TCOPYFILE2_MESSAGE

type TPCOPYFILE2_PROGRESS_ROUTINE = uintptr

type PCOPYFILE2_PROGRESS_ROUTINE = TPCOPYFILE2_PROGRESS_ROUTINE

type TCOPYFILE2_EXTENDED_PARAMETERS = struct {
	FdwSize            TDWORD
	FdwCopyFlags       TDWORD
	FpfCancel          uintptr
	FpProgressRoutine  TPCOPYFILE2_PROGRESS_ROUTINE
	FpvCallbackContext TPVOID
}

type COPYFILE2_EXTENDED_PARAMETERS = TCOPYFILE2_EXTENDED_PARAMETERS

type TSTREAM_INFO_LEVELS = int32

type STREAM_INFO_LEVELS = TSTREAM_INFO_LEVELS

type __STREAM_INFO_LEVELS = int32

const _FindStreamInfoStandard = 0
const _FindStreamInfoMaxInfoLevel = 1

type TWIN32_FIND_STREAM_DATA = struct {
	F__ccgo_align [0]uint32
	FStreamSize   TLARGE_INTEGER
	FcStreamName  [296]TWCHAR
}

type WIN32_FIND_STREAM_DATA = TWIN32_FIND_STREAM_DATA

type T_WIN32_FIND_STREAM_DATA = TWIN32_FIND_STREAM_DATA

type _WIN32_FIND_STREAM_DATA = T_WIN32_FIND_STREAM_DATA

type TPWIN32_FIND_STREAM_DATA = uintptr

type PWIN32_FIND_STREAM_DATA = TPWIN32_FIND_STREAM_DATA

type TEVENTLOG_FULL_INFORMATION = struct {
	FdwFull TDWORD
}

type EVENTLOG_FULL_INFORMATION = TEVENTLOG_FULL_INFORMATION

type T_EVENTLOG_FULL_INFORMATION = TEVENTLOG_FULL_INFORMATION

type _EVENTLOG_FULL_INFORMATION = T_EVENTLOG_FULL_INFORMATION

type TLPEVENTLOG_FULL_INFORMATION = uintptr

type LPEVENTLOG_FULL_INFORMATION = TLPEVENTLOG_FULL_INFORMATION

type TOPERATION_ID = uint32

type OPERATION_ID = TOPERATION_ID

type TOPERATION_START_PARAMETERS = struct {
	FVersion     TULONG
	FOperationId TOPERATION_ID
	FFlags       TULONG
}

type OPERATION_START_PARAMETERS = TOPERATION_START_PARAMETERS

type T_OPERATION_START_PARAMETERS = TOPERATION_START_PARAMETERS

type _OPERATION_START_PARAMETERS = T_OPERATION_START_PARAMETERS

type TPOPERATION_START_PARAMETERS = uintptr

type POPERATION_START_PARAMETERS = TPOPERATION_START_PARAMETERS

type TOPERATION_END_PARAMETERS = struct {
	FVersion     TULONG
	FOperationId TOPERATION_ID
	FFlags       TULONG
}

type OPERATION_END_PARAMETERS = TOPERATION_END_PARAMETERS

type T_OPERATION_END_PARAMETERS = TOPERATION_END_PARAMETERS

type _OPERATION_END_PARAMETERS = T_OPERATION_END_PARAMETERS

type TPOPERATION_END_PARAMETERS = uintptr

type POPERATION_END_PARAMETERS = TPOPERATION_END_PARAMETERS

type THW_PROFILE_INFOA = struct {
	FdwDockInfo      TDWORD
	FszHwProfileGuid [39]TCHAR
	FszHwProfileName [80]TCHAR
}

type HW_PROFILE_INFOA = THW_PROFILE_INFOA

type TtagHW_PROFILE_INFOA = THW_PROFILE_INFOA

type tagHW_PROFILE_INFOA = TtagHW_PROFILE_INFOA

type TLPHW_PROFILE_INFOA = uintptr

type LPHW_PROFILE_INFOA = TLPHW_PROFILE_INFOA

type THW_PROFILE_INFOW = struct {
	FdwDockInfo      TDWORD
	FszHwProfileGuid [39]TWCHAR
	FszHwProfileName [80]TWCHAR
}

type HW_PROFILE_INFOW = THW_PROFILE_INFOW

type TtagHW_PROFILE_INFOW = THW_PROFILE_INFOW

type tagHW_PROFILE_INFOW = TtagHW_PROFILE_INFOW

type TLPHW_PROFILE_INFOW = uintptr

type LPHW_PROFILE_INFOW = TLPHW_PROFILE_INFOW

type THW_PROFILE_INFO = struct {
	FdwDockInfo      TDWORD
	FszHwProfileGuid [39]TCHAR
	FszHwProfileName [80]TCHAR
}

type HW_PROFILE_INFO = THW_PROFILE_INFO

type TLPHW_PROFILE_INFO = uintptr

type LPHW_PROFILE_INFO = TLPHW_PROFILE_INFO

type TTIME_ZONE_INFORMATION = struct {
	FBias         TLONG
	FStandardName [32]TWCHAR
	FStandardDate TSYSTEMTIME
	FStandardBias TLONG
	FDaylightName [32]TWCHAR
	FDaylightDate TSYSTEMTIME
	FDaylightBias TLONG
}

type TIME_ZONE_INFORMATION = TTIME_ZONE_INFORMATION

type T_TIME_ZONE_INFORMATION = TTIME_ZONE_INFORMATION

type _TIME_ZONE_INFORMATION = T_TIME_ZONE_INFORMATION

type TPTIME_ZONE_INFORMATION = uintptr

type PTIME_ZONE_INFORMATION = TPTIME_ZONE_INFORMATION

type TLPTIME_ZONE_INFORMATION = uintptr

type LPTIME_ZONE_INFORMATION = TLPTIME_ZONE_INFORMATION

type TDYNAMIC_TIME_ZONE_INFORMATION = struct {
	FBias                        TLONG
	FStandardName                [32]TWCHAR
	FStandardDate                TSYSTEMTIME
	FStandardBias                TLONG
	FDaylightName                [32]TWCHAR
	FDaylightDate                TSYSTEMTIME
	FDaylightBias                TLONG
	FTimeZoneKeyName             [128]TWCHAR
	FDynamicDaylightTimeDisabled TBOOLEAN
}

type DYNAMIC_TIME_ZONE_INFORMATION = TDYNAMIC_TIME_ZONE_INFORMATION

type T_TIME_DYNAMIC_ZONE_INFORMATION = TDYNAMIC_TIME_ZONE_INFORMATION

type _TIME_DYNAMIC_ZONE_INFORMATION = T_TIME_DYNAMIC_ZONE_INFORMATION

type TPDYNAMIC_TIME_ZONE_INFORMATION = uintptr

type PDYNAMIC_TIME_ZONE_INFORMATION = TPDYNAMIC_TIME_ZONE_INFORMATION

type TSYSTEM_POWER_STATUS = struct {
	FACLineStatus        TBYTE
	FBatteryFlag         TBYTE
	FBatteryLifePercent  TBYTE
	FReserved1           TBYTE
	FBatteryLifeTime     TDWORD
	FBatteryFullLifeTime TDWORD
}

type SYSTEM_POWER_STATUS = TSYSTEM_POWER_STATUS

type T_SYSTEM_POWER_STATUS = TSYSTEM_POWER_STATUS

type _SYSTEM_POWER_STATUS = T_SYSTEM_POWER_STATUS

type TLPSYSTEM_POWER_STATUS = uintptr

type LPSYSTEM_POWER_STATUS = TLPSYSTEM_POWER_STATUS

type TACTCTXA = struct {
	FcbSize                 TULONG
	FdwFlags                TDWORD
	FlpSource               TLPCSTR
	FwProcessorArchitecture TUSHORT
	FwLangId                TLANGID
	FlpAssemblyDirectory    TLPCSTR
	FlpResourceName         TLPCSTR
	FlpApplicationName      TLPCSTR
	FhModule                THMODULE
}

type ACTCTXA = TACTCTXA

type TtagACTCTXA = TACTCTXA

type tagACTCTXA = TtagACTCTXA

type TPACTCTXA = uintptr

type PACTCTXA = TPACTCTXA

type TACTCTXW = struct {
	FcbSize                 TULONG
	FdwFlags                TDWORD
	FlpSource               TLPCWSTR
	FwProcessorArchitecture TUSHORT
	FwLangId                TLANGID
	FlpAssemblyDirectory    TLPCWSTR
	FlpResourceName         TLPCWSTR
	FlpApplicationName      TLPCWSTR
	FhModule                THMODULE
}

type ACTCTXW = TACTCTXW

type TtagACTCTXW = TACTCTXW

type tagACTCTXW = TtagACTCTXW

type TPACTCTXW = uintptr

type PACTCTXW = TPACTCTXW

type TACTCTX = struct {
	FcbSize                 TULONG
	FdwFlags                TDWORD
	FlpSource               TLPCSTR
	FwProcessorArchitecture TUSHORT
	FwLangId                TLANGID
	FlpAssemblyDirectory    TLPCSTR
	FlpResourceName         TLPCSTR
	FlpApplicationName      TLPCSTR
	FhModule                THMODULE
}

type ACTCTX = TACTCTX

type TPACTCTX = uintptr

type PACTCTX = TPACTCTX

type TPCACTCTXA = uintptr

type PCACTCTXA = TPCACTCTXA

type TPCACTCTXW = uintptr

type PCACTCTXW = TPCACTCTXW

type TPCACTCTX = uintptr

type PCACTCTX = TPCACTCTX

type TACTCTX_SECTION_KEYED_DATA_2600 = struct {
	FcbSize                    TULONG
	FulDataFormatVersion       TULONG
	FlpData                    TPVOID
	FulLength                  TULONG
	FlpSectionGlobalData       TPVOID
	FulSectionGlobalDataLength TULONG
	FlpSectionBase             TPVOID
	FulSectionTotalLength      TULONG
	FhActCtx                   THANDLE
	FulAssemblyRosterIndex     TULONG
}

type ACTCTX_SECTION_KEYED_DATA_2600 = TACTCTX_SECTION_KEYED_DATA_2600

type TtagACTCTX_SECTION_KEYED_DATA_2600 = TACTCTX_SECTION_KEYED_DATA_2600

type tagACTCTX_SECTION_KEYED_DATA_2600 = TtagACTCTX_SECTION_KEYED_DATA_2600

type TPACTCTX_SECTION_KEYED_DATA_2600 = uintptr

type PACTCTX_SECTION_KEYED_DATA_2600 = TPACTCTX_SECTION_KEYED_DATA_2600

type TPCACTCTX_SECTION_KEYED_DATA_2600 = uintptr

type PCACTCTX_SECTION_KEYED_DATA_2600 = TPCACTCTX_SECTION_KEYED_DATA_2600

type TACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = struct {
	FlpInformation             TPVOID
	FlpSectionBase             TPVOID
	FulSectionLength           TULONG
	FlpSectionGlobalDataBase   TPVOID
	FulSectionGlobalDataLength TULONG
}

type ACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = TACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA

type TtagACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = TACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA

type tagACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = TtagACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA

type TPACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = uintptr

type PACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = TPACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA

type TPCACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = uintptr

type PCACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA = TPCACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA

type TACTCTX_SECTION_KEYED_DATA = struct {
	FcbSize                    TULONG
	FulDataFormatVersion       TULONG
	FlpData                    TPVOID
	FulLength                  TULONG
	FlpSectionGlobalData       TPVOID
	FulSectionGlobalDataLength TULONG
	FlpSectionBase             TPVOID
	FulSectionTotalLength      TULONG
	FhActCtx                   THANDLE
	FulAssemblyRosterIndex     TULONG
	FulFlags                   TULONG
	FAssemblyMetadata          TACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA
}

type ACTCTX_SECTION_KEYED_DATA = TACTCTX_SECTION_KEYED_DATA

type TtagACTCTX_SECTION_KEYED_DATA = TACTCTX_SECTION_KEYED_DATA

type tagACTCTX_SECTION_KEYED_DATA = TtagACTCTX_SECTION_KEYED_DATA

type TPACTCTX_SECTION_KEYED_DATA = uintptr

type PACTCTX_SECTION_KEYED_DATA = TPACTCTX_SECTION_KEYED_DATA

type TPCACTCTX_SECTION_KEYED_DATA = uintptr

type PCACTCTX_SECTION_KEYED_DATA = TPCACTCTX_SECTION_KEYED_DATA

type TACTIVATION_CONTEXT_BASIC_INFORMATION = struct {
	FhActCtx THANDLE
	FdwFlags TDWORD
}

type ACTIVATION_CONTEXT_BASIC_INFORMATION = TACTIVATION_CONTEXT_BASIC_INFORMATION

type T_ACTIVATION_CONTEXT_BASIC_INFORMATION = TACTIVATION_CONTEXT_BASIC_INFORMATION

type _ACTIVATION_CONTEXT_BASIC_INFORMATION = T_ACTIVATION_CONTEXT_BASIC_INFORMATION

type TPACTIVATION_CONTEXT_BASIC_INFORMATION = uintptr

type PACTIVATION_CONTEXT_BASIC_INFORMATION = TPACTIVATION_CONTEXT_BASIC_INFORMATION

type TPCACTIVATION_CONTEXT_BASIC_INFORMATION = uintptr

type PCACTIVATION_CONTEXT_BASIC_INFORMATION = TPCACTIVATION_CONTEXT_BASIC_INFORMATION

type TPQUERYACTCTXW_FUNC = uintptr

type PQUERYACTCTXW_FUNC = TPQUERYACTCTXW_FUNC

type TAPPLICATION_RECOVERY_CALLBACK = uintptr

type APPLICATION_RECOVERY_CALLBACK = TAPPLICATION_RECOVERY_CALLBACK

type TFILE_BASIC_INFO = struct {
	F__ccgo_align   [0]uint32
	FCreationTime   TLARGE_INTEGER
	FLastAccessTime TLARGE_INTEGER
	FLastWriteTime  TLARGE_INTEGER
	FChangeTime     TLARGE_INTEGER
	FFileAttributes TDWORD
	F__ccgo_pad5    [4]byte
}

type FILE_BASIC_INFO = TFILE_BASIC_INFO

type T_FILE_BASIC_INFO = TFILE_BASIC_INFO

type _FILE_BASIC_INFO = T_FILE_BASIC_INFO

type TPFILE_BASIC_INFO = uintptr

type PFILE_BASIC_INFO = TPFILE_BASIC_INFO

type TFILE_STANDARD_INFO = struct {
	F__ccgo_align   [0]uint32
	FAllocationSize TLARGE_INTEGER
	FEndOfFile      TLARGE_INTEGER
	FNumberOfLinks  TDWORD
	FDeletePending  TBOOLEAN
	FDirectory      TBOOLEAN
	F__ccgo_pad5    [2]byte
}

type FILE_STANDARD_INFO = TFILE_STANDARD_INFO

type T_FILE_STANDARD_INFO = TFILE_STANDARD_INFO

type _FILE_STANDARD_INFO = T_FILE_STANDARD_INFO

type TPFILE_STANDARD_INFO = uintptr

type PFILE_STANDARD_INFO = TPFILE_STANDARD_INFO

type TFILE_NAME_INFO = struct {
	FFileNameLength TDWORD
	FFileName       [1]TWCHAR
}

type FILE_NAME_INFO = TFILE_NAME_INFO

type T_FILE_NAME_INFO = TFILE_NAME_INFO

type _FILE_NAME_INFO = T_FILE_NAME_INFO

type TPFILE_NAME_INFO = uintptr

type PFILE_NAME_INFO = TPFILE_NAME_INFO

type TFILE_CASE_SENSITIVE_INFO = struct {
	FFlags TULONG
}

type FILE_CASE_SENSITIVE_INFO = TFILE_CASE_SENSITIVE_INFO

type T_FILE_CASE_SENSITIVE_INFO = TFILE_CASE_SENSITIVE_INFO

type _FILE_CASE_SENSITIVE_INFO = T_FILE_CASE_SENSITIVE_INFO

type TPFILE_CASE_SENSITIVE_INFO = uintptr

type PFILE_CASE_SENSITIVE_INFO = TPFILE_CASE_SENSITIVE_INFO

type TFILE_RENAME_INFO = struct {
	F__ccgo0_0 struct {
		FFlags           [0]TDWORD
		FReplaceIfExists TBOOLEAN
		F__ccgo_pad2     [3]byte
	}
	FRootDirectory  THANDLE
	FFileNameLength TDWORD
	FFileName       [1]TWCHAR
}

type FILE_RENAME_INFO = TFILE_RENAME_INFO

type T_FILE_RENAME_INFO = TFILE_RENAME_INFO

type _FILE_RENAME_INFO = T_FILE_RENAME_INFO

type TPFILE_RENAME_INFO = uintptr

type PFILE_RENAME_INFO = TPFILE_RENAME_INFO

type TFILE_ALLOCATION_INFO = struct {
	F__ccgo_align   [0]uint32
	FAllocationSize TLARGE_INTEGER
}

type FILE_ALLOCATION_INFO = TFILE_ALLOCATION_INFO

type T_FILE_ALLOCATION_INFO = TFILE_ALLOCATION_INFO

type _FILE_ALLOCATION_INFO = T_FILE_ALLOCATION_INFO

type TPFILE_ALLOCATION_INFO = uintptr

type PFILE_ALLOCATION_INFO = TPFILE_ALLOCATION_INFO

type TFILE_END_OF_FILE_INFO = struct {
	F__ccgo_align [0]uint32
	FEndOfFile    TLARGE_INTEGER
}

type FILE_END_OF_FILE_INFO = TFILE_END_OF_FILE_INFO

type T_FILE_END_OF_FILE_INFO = TFILE_END_OF_FILE_INFO

type _FILE_END_OF_FILE_INFO = T_FILE_END_OF_FILE_INFO

type TPFILE_END_OF_FILE_INFO = uintptr

type PFILE_END_OF_FILE_INFO = TPFILE_END_OF_FILE_INFO

type TFILE_STREAM_INFO = struct {
	F__ccgo_align         [0]uint32
	FNextEntryOffset      TDWORD
	FStreamNameLength     TDWORD
	FStreamSize           TLARGE_INTEGER
	FStreamAllocationSize TLARGE_INTEGER
	FStreamName           [1]TWCHAR
	F__ccgo_pad5          [6]byte
}

type FILE_STREAM_INFO = TFILE_STREAM_INFO

type T_FILE_STREAM_INFO = TFILE_STREAM_INFO

type _FILE_STREAM_INFO = T_FILE_STREAM_INFO

type TPFILE_STREAM_INFO = uintptr

type PFILE_STREAM_INFO = TPFILE_STREAM_INFO

type TFILE_COMPRESSION_INFO = struct {
	F__ccgo_align         [0]uint32
	FCompressedFileSize   TLARGE_INTEGER
	FCompressionFormat    TWORD
	FCompressionUnitShift TUCHAR
	FChunkShift           TUCHAR
	FClusterShift         TUCHAR
	FReserved             [3]TUCHAR
}

type FILE_COMPRESSION_INFO = TFILE_COMPRESSION_INFO

type T_FILE_COMPRESSION_INFO = TFILE_COMPRESSION_INFO

type _FILE_COMPRESSION_INFO = T_FILE_COMPRESSION_INFO

type TPFILE_COMPRESSION_INFO = uintptr

type PFILE_COMPRESSION_INFO = TPFILE_COMPRESSION_INFO

type TFILE_ATTRIBUTE_TAG_INFO = struct {
	FFileAttributes TDWORD
	FReparseTag     TDWORD
}

type FILE_ATTRIBUTE_TAG_INFO = TFILE_ATTRIBUTE_TAG_INFO

type T_FILE_ATTRIBUTE_TAG_INFO = TFILE_ATTRIBUTE_TAG_INFO

type _FILE_ATTRIBUTE_TAG_INFO = T_FILE_ATTRIBUTE_TAG_INFO

type TPFILE_ATTRIBUTE_TAG_INFO = uintptr

type PFILE_ATTRIBUTE_TAG_INFO = TPFILE_ATTRIBUTE_TAG_INFO

type TFILE_DISPOSITION_INFO = struct {
	FDeleteFileA TBOOLEAN
}

type FILE_DISPOSITION_INFO = TFILE_DISPOSITION_INFO

type T_FILE_DISPOSITION_INFO = TFILE_DISPOSITION_INFO

type _FILE_DISPOSITION_INFO = T_FILE_DISPOSITION_INFO

type TPFILE_DISPOSITION_INFO = uintptr

type PFILE_DISPOSITION_INFO = TPFILE_DISPOSITION_INFO

type TFILE_DISPOSITION_INFO_EX = struct {
	FFlags TDWORD
}

type FILE_DISPOSITION_INFO_EX = TFILE_DISPOSITION_INFO_EX

type T_FILE_DISPOSITION_INFO_EX = TFILE_DISPOSITION_INFO_EX

type _FILE_DISPOSITION_INFO_EX = T_FILE_DISPOSITION_INFO_EX

type TPFILE_DISPOSITION_INFO_EX = uintptr

type PFILE_DISPOSITION_INFO_EX = TPFILE_DISPOSITION_INFO_EX

type TFILE_ID_BOTH_DIR_INFO = struct {
	F__ccgo_align    [0]uint32
	FNextEntryOffset TDWORD
	FFileIndex       TDWORD
	FCreationTime    TLARGE_INTEGER
	FLastAccessTime  TLARGE_INTEGER
	FLastWriteTime   TLARGE_INTEGER
	FChangeTime      TLARGE_INTEGER
	FEndOfFile       TLARGE_INTEGER
	FAllocationSize  TLARGE_INTEGER
	FFileAttributes  TDWORD
	FFileNameLength  TDWORD
	FEaSize          TDWORD
	FShortNameLength TCCHAR
	FShortName       [12]TWCHAR
	F__ccgo_align13  [2]byte
	FFileId          TLARGE_INTEGER
	FFileName        [1]TWCHAR
	F__ccgo_pad15    [6]byte
}

type FILE_ID_BOTH_DIR_INFO = TFILE_ID_BOTH_DIR_INFO

type T_FILE_ID_BOTH_DIR_INFO = TFILE_ID_BOTH_DIR_INFO

type _FILE_ID_BOTH_DIR_INFO = T_FILE_ID_BOTH_DIR_INFO

type TPFILE_ID_BOTH_DIR_INFO = uintptr

type PFILE_ID_BOTH_DIR_INFO = TPFILE_ID_BOTH_DIR_INFO

type TFILE_FULL_DIR_INFO = struct {
	F__ccgo_align    [0]uint32
	FNextEntryOffset TULONG
	FFileIndex       TULONG
	FCreationTime    TLARGE_INTEGER
	FLastAccessTime  TLARGE_INTEGER
	FLastWriteTime   TLARGE_INTEGER
	FChangeTime      TLARGE_INTEGER
	FEndOfFile       TLARGE_INTEGER
	FAllocationSize  TLARGE_INTEGER
	FFileAttributes  TULONG
	FFileNameLength  TULONG
	FEaSize          TULONG
	FFileName        [1]TWCHAR
	F__ccgo_pad12    [2]byte
}

type FILE_FULL_DIR_INFO = TFILE_FULL_DIR_INFO

type T_FILE_FULL_DIR_INFO = TFILE_FULL_DIR_INFO

type _FILE_FULL_DIR_INFO = T_FILE_FULL_DIR_INFO

type TPFILE_FULL_DIR_INFO = uintptr

type PFILE_FULL_DIR_INFO = TPFILE_FULL_DIR_INFO

type TPRIORITY_HINT = int32

type PRIORITY_HINT = TPRIORITY_HINT

type __PRIORITY_HINT = int32

const _IoPriorityHintVeryLow = 0
const _IoPriorityHintLow = 1
const _IoPriorityHintNormal = 2
const _MaximumIoPriorityHintType = 3

type TFILE_IO_PRIORITY_HINT_INFO = struct {
	FPriorityHint TPRIORITY_HINT
}

type FILE_IO_PRIORITY_HINT_INFO = TFILE_IO_PRIORITY_HINT_INFO

type T_FILE_IO_PRIORITY_HINT_INFO = TFILE_IO_PRIORITY_HINT_INFO

type _FILE_IO_PRIORITY_HINT_INFO = T_FILE_IO_PRIORITY_HINT_INFO

type TPFILE_IO_PRIORITY_HINT_INFO = uintptr

type PFILE_IO_PRIORITY_HINT_INFO = TPFILE_IO_PRIORITY_HINT_INFO

type TFILE_ALIGNMENT_INFO = struct {
	FAlignmentRequirement TULONG
}

type FILE_ALIGNMENT_INFO = TFILE_ALIGNMENT_INFO

type T_FILE_ALIGNMENT_INFO = TFILE_ALIGNMENT_INFO

type _FILE_ALIGNMENT_INFO = T_FILE_ALIGNMENT_INFO

type TPFILE_ALIGNMENT_INFO = uintptr

type PFILE_ALIGNMENT_INFO = TPFILE_ALIGNMENT_INFO

type TFILE_STORAGE_INFO = struct {
	FLogicalBytesPerSector                                 TULONG
	FPhysicalBytesPerSectorForAtomicity                    TULONG
	FPhysicalBytesPerSectorForPerformance                  TULONG
	FFileSystemEffectivePhysicalBytesPerSectorForAtomicity TULONG
	FFlags                                                 TULONG
	FByteOffsetForSectorAlignment                          TULONG
	FByteOffsetForPartitionAlignment                       TULONG
}

type FILE_STORAGE_INFO = TFILE_STORAGE_INFO

type T_FILE_STORAGE_INFO = TFILE_STORAGE_INFO

type _FILE_STORAGE_INFO = T_FILE_STORAGE_INFO

type TPFILE_STORAGE_INFO = uintptr

type PFILE_STORAGE_INFO = TPFILE_STORAGE_INFO

type TFILE_ID_INFO = struct {
	F__ccgo_align       [0]uint32
	FVolumeSerialNumber TULONGLONG
	FFileId             TFILE_ID_128
}

type FILE_ID_INFO = TFILE_ID_INFO

type T_FILE_ID_INFO = TFILE_ID_INFO

type _FILE_ID_INFO = T_FILE_ID_INFO

type TPFILE_ID_INFO = uintptr

type PFILE_ID_INFO = TPFILE_ID_INFO

type TFILE_ID_EXTD_DIR_INFO = struct {
	F__ccgo_align    [0]uint32
	FNextEntryOffset TULONG
	FFileIndex       TULONG
	FCreationTime    TLARGE_INTEGER
	FLastAccessTime  TLARGE_INTEGER
	FLastWriteTime   TLARGE_INTEGER
	FChangeTime      TLARGE_INTEGER
	FEndOfFile       TLARGE_INTEGER
	FAllocationSize  TLARGE_INTEGER
	FFileAttributes  TULONG
	FFileNameLength  TULONG
	FEaSize          TULONG
	FReparsePointTag TULONG
	FFileId          TFILE_ID_128
	FFileName        [1]TWCHAR
	F__ccgo_pad14    [6]byte
}

type FILE_ID_EXTD_DIR_INFO = TFILE_ID_EXTD_DIR_INFO

type T_FILE_ID_EXTD_DIR_INFO = TFILE_ID_EXTD_DIR_INFO

type _FILE_ID_EXTD_DIR_INFO = T_FILE_ID_EXTD_DIR_INFO

type TPFILE_ID_EXTD_DIR_INFO = uintptr

type PFILE_ID_EXTD_DIR_INFO = TPFILE_ID_EXTD_DIR_INFO

type TFILE_REMOTE_PROTOCOL_INFO = struct {
	FStructureVersion     TUSHORT
	FStructureSize        TUSHORT
	FProtocol             TULONG
	FProtocolMajorVersion TUSHORT
	FProtocolMinorVersion TUSHORT
	FProtocolRevision     TUSHORT
	FReserved             TUSHORT
	FFlags                TULONG
	FGenericReserved      struct {
		FReserved [8]TULONG
	}
	FProtocolSpecific struct {
		FReserved [0][16]TULONG
		FSmb2     struct {
			FServer struct {
				FCapabilities TULONG
			}
			FShare struct {
				FCapabilities TULONG
				FCachingFlags TULONG
			}
		}
		F__ccgo_pad2 [52]byte
	}
}

type FILE_REMOTE_PROTOCOL_INFO = TFILE_REMOTE_PROTOCOL_INFO

type T_FILE_REMOTE_PROTOCOL_INFO = TFILE_REMOTE_PROTOCOL_INFO

type _FILE_REMOTE_PROTOCOL_INFO = T_FILE_REMOTE_PROTOCOL_INFO

type TPFILE_REMOTE_PROTOCOL_INFO = uintptr

type PFILE_REMOTE_PROTOCOL_INFO = TPFILE_REMOTE_PROTOCOL_INFO

type TFILE_ID_TYPE = int32

type FILE_ID_TYPE = TFILE_ID_TYPE

type __FILE_ID_TYPE = int32

const _FileIdType = 0
const _ObjectIdType = 1
const _ExtendedFileIdType = 2
const _MaximumFileIdType = 3

type TPFILE_ID_TYPE = uintptr

type PFILE_ID_TYPE = TPFILE_ID_TYPE

type TFILE_ID_DESCRIPTOR = struct {
	F__ccgo_align [0]uint32
	FdwSize       TDWORD
	FType         TFILE_ID_TYPE
	F__ccgo2_8    struct {
		F__ccgo_align   [0]uint32
		FObjectId       [0]TGUID
		FExtendedFileId [0]TFILE_ID_128
		FFileId         TLARGE_INTEGER
		F__ccgo_pad3    [8]byte
	}
}

type FILE_ID_DESCRIPTOR = TFILE_ID_DESCRIPTOR

type TLPFILE_ID_DESCRIPTOR = uintptr

type LPFILE_ID_DESCRIPTOR = TLPFILE_ID_DESCRIPTOR

type TFILE_ID_DESCRIPTOR1 = struct {
	F__ccgo_align [0]uint32
	FdwSize       TDWORD
	FType         TFILE_ID_TYPE
	F__ccgo2_8    struct {
		F__ccgo_align   [0]uint32
		FObjectId       [0]TGUID
		FExtendedFileId [0]TFILE_ID_128
		FFileId         TLARGE_INTEGER
		F__ccgo_pad3    [8]byte
	}
}

type FILE_ID_DESCRIPTOR1 = TFILE_ID_DESCRIPTOR1

type TDRAWPATRECT = struct {
	FptPosition TPOINT
	FptSize     TPOINT
	FwStyle     TWORD
	FwPattern   TWORD
}

type DRAWPATRECT = TDRAWPATRECT

type T_DRAWPATRECT = TDRAWPATRECT

type _DRAWPATRECT = T_DRAWPATRECT

type TPDRAWPATRECT = uintptr

type PDRAWPATRECT = TPDRAWPATRECT

type TPSINJECTDATA = struct {
	FDataBytes      TDWORD
	FInjectionPoint TWORD
	FPageNumber     TWORD
}

type PSINJECTDATA = TPSINJECTDATA

type T_PSINJECTDATA = TPSINJECTDATA

type _PSINJECTDATA = T_PSINJECTDATA

type TPPSINJECTDATA = uintptr

type PPSINJECTDATA = TPPSINJECTDATA

type TPSFEATURE_OUTPUT = struct {
	FbPageIndependent TWINBOOL
	FbSetPageDevice   TWINBOOL
}

type PSFEATURE_OUTPUT = TPSFEATURE_OUTPUT

type T_PSFEATURE_OUTPUT = TPSFEATURE_OUTPUT

type _PSFEATURE_OUTPUT = T_PSFEATURE_OUTPUT

type TPPSFEATURE_OUTPUT = uintptr

type PPSFEATURE_OUTPUT = TPPSFEATURE_OUTPUT

type TPSFEATURE_CUSTPAPER = struct {
	FlOrientation  TLONG
	FlWidth        TLONG
	FlHeight       TLONG
	FlWidthOffset  TLONG
	FlHeightOffset TLONG
}

type PSFEATURE_CUSTPAPER = TPSFEATURE_CUSTPAPER

type T_PSFEATURE_CUSTPAPER = TPSFEATURE_CUSTPAPER

type _PSFEATURE_CUSTPAPER = T_PSFEATURE_CUSTPAPER

type TPPSFEATURE_CUSTPAPER = uintptr

type PPSFEATURE_CUSTPAPER = TPPSFEATURE_CUSTPAPER

type TXFORM = struct {
	FeM11 TFLOAT
	FeM12 TFLOAT
	FeM21 TFLOAT
	FeM22 TFLOAT
	FeDx  TFLOAT
	FeDy  TFLOAT
}

type XFORM = TXFORM

type TtagXFORM = TXFORM

type tagXFORM = TtagXFORM

type TPXFORM = uintptr

type PXFORM = TPXFORM

type TLPXFORM = uintptr

type LPXFORM = TLPXFORM

type TBITMAP = struct {
	FbmType       TLONG
	FbmWidth      TLONG
	FbmHeight     TLONG
	FbmWidthBytes TLONG
	FbmPlanes     TWORD
	FbmBitsPixel  TWORD
	FbmBits       TLPVOID
}

type BITMAP = TBITMAP

type TtagBITMAP = TBITMAP

type tagBITMAP = TtagBITMAP

type TPBITMAP = uintptr

type PBITMAP = TPBITMAP

type TNPBITMAP = uintptr

type NPBITMAP = TNPBITMAP

type TLPBITMAP = uintptr

type LPBITMAP = TLPBITMAP

type TRGBTRIPLE = struct {
	FrgbtBlue  TBYTE
	FrgbtGreen TBYTE
	FrgbtRed   TBYTE
}

type RGBTRIPLE = TRGBTRIPLE

type TtagRGBTRIPLE = TRGBTRIPLE

type tagRGBTRIPLE = TtagRGBTRIPLE

type TPRGBTRIPLE = uintptr

type PRGBTRIPLE = TPRGBTRIPLE

type TNPRGBTRIPLE = uintptr

type NPRGBTRIPLE = TNPRGBTRIPLE

type TLPRGBTRIPLE = uintptr

type LPRGBTRIPLE = TLPRGBTRIPLE

type TRGBQUAD = struct {
	FrgbBlue     TBYTE
	FrgbGreen    TBYTE
	FrgbRed      TBYTE
	FrgbReserved TBYTE
}

type RGBQUAD = TRGBQUAD

type TtagRGBQUAD = TRGBQUAD

type tagRGBQUAD = TtagRGBQUAD

type TLPRGBQUAD = uintptr

type LPRGBQUAD = TLPRGBQUAD

type TLCSCSTYPE = int32

type LCSCSTYPE = TLCSCSTYPE

type TLCSGAMUTMATCH = int32

type LCSGAMUTMATCH = TLCSGAMUTMATCH

type TFXPT16DOT16 = int32

type FXPT16DOT16 = TFXPT16DOT16

type TLPFXPT16DOT16 = uintptr

type LPFXPT16DOT16 = TLPFXPT16DOT16

type TFXPT2DOT30 = int32

type FXPT2DOT30 = TFXPT2DOT30

type TLPFXPT2DOT30 = uintptr

type LPFXPT2DOT30 = TLPFXPT2DOT30

type TCIEXYZ = struct {
	FciexyzX TFXPT2DOT30
	FciexyzY TFXPT2DOT30
	FciexyzZ TFXPT2DOT30
}

type CIEXYZ = TCIEXYZ

type TtagCIEXYZ = TCIEXYZ

type tagCIEXYZ = TtagCIEXYZ

type TLPCIEXYZ = uintptr

type LPCIEXYZ = TLPCIEXYZ

type TCIEXYZTRIPLE = struct {
	FciexyzRed   TCIEXYZ
	FciexyzGreen TCIEXYZ
	FciexyzBlue  TCIEXYZ
}

type CIEXYZTRIPLE = TCIEXYZTRIPLE

type TtagICEXYZTRIPLE = TCIEXYZTRIPLE

type tagICEXYZTRIPLE = TtagICEXYZTRIPLE

type TLPCIEXYZTRIPLE = uintptr

type LPCIEXYZTRIPLE = TLPCIEXYZTRIPLE

type TLOGCOLORSPACEA = struct {
	FlcsSignature  TDWORD
	FlcsVersion    TDWORD
	FlcsSize       TDWORD
	FlcsCSType     TLCSCSTYPE
	FlcsIntent     TLCSGAMUTMATCH
	FlcsEndpoints  TCIEXYZTRIPLE
	FlcsGammaRed   TDWORD
	FlcsGammaGreen TDWORD
	FlcsGammaBlue  TDWORD
	FlcsFilename   [260]TCHAR
}

type LOGCOLORSPACEA = TLOGCOLORSPACEA

type TtagLOGCOLORSPACEA = TLOGCOLORSPACEA

type tagLOGCOLORSPACEA = TtagLOGCOLORSPACEA

type TLPLOGCOLORSPACEA = uintptr

type LPLOGCOLORSPACEA = TLPLOGCOLORSPACEA

type TLOGCOLORSPACEW = struct {
	FlcsSignature  TDWORD
	FlcsVersion    TDWORD
	FlcsSize       TDWORD
	FlcsCSType     TLCSCSTYPE
	FlcsIntent     TLCSGAMUTMATCH
	FlcsEndpoints  TCIEXYZTRIPLE
	FlcsGammaRed   TDWORD
	FlcsGammaGreen TDWORD
	FlcsGammaBlue  TDWORD
	FlcsFilename   [260]TWCHAR
}

type LOGCOLORSPACEW = TLOGCOLORSPACEW

type TtagLOGCOLORSPACEW = TLOGCOLORSPACEW

type tagLOGCOLORSPACEW = TtagLOGCOLORSPACEW

type TLPLOGCOLORSPACEW = uintptr

type LPLOGCOLORSPACEW = TLPLOGCOLORSPACEW

type TLOGCOLORSPACE = struct {
	FlcsSignature  TDWORD
	FlcsVersion    TDWORD
	FlcsSize       TDWORD
	FlcsCSType     TLCSCSTYPE
	FlcsIntent     TLCSGAMUTMATCH
	FlcsEndpoints  TCIEXYZTRIPLE
	FlcsGammaRed   TDWORD
	FlcsGammaGreen TDWORD
	FlcsGammaBlue  TDWORD
	FlcsFilename   [260]TCHAR
}

type LOGCOLORSPACE = TLOGCOLORSPACE

type TLPLOGCOLORSPACE = uintptr

type LPLOGCOLORSPACE = TLPLOGCOLORSPACE

type TBITMAPCOREHEADER = struct {
	FbcSize     TDWORD
	FbcWidth    TWORD
	FbcHeight   TWORD
	FbcPlanes   TWORD
	FbcBitCount TWORD
}

type BITMAPCOREHEADER = TBITMAPCOREHEADER

type TtagBITMAPCOREHEADER = TBITMAPCOREHEADER

type tagBITMAPCOREHEADER = TtagBITMAPCOREHEADER

type TLPBITMAPCOREHEADER = uintptr

type LPBITMAPCOREHEADER = TLPBITMAPCOREHEADER

type TPBITMAPCOREHEADER = uintptr

type PBITMAPCOREHEADER = TPBITMAPCOREHEADER

type TBITMAPINFOHEADER = struct {
	FbiSize          TDWORD
	FbiWidth         TLONG
	FbiHeight        TLONG
	FbiPlanes        TWORD
	FbiBitCount      TWORD
	FbiCompression   TDWORD
	FbiSizeImage     TDWORD
	FbiXPelsPerMeter TLONG
	FbiYPelsPerMeter TLONG
	FbiClrUsed       TDWORD
	FbiClrImportant  TDWORD
}

type BITMAPINFOHEADER = TBITMAPINFOHEADER

type TtagBITMAPINFOHEADER = TBITMAPINFOHEADER

type tagBITMAPINFOHEADER = TtagBITMAPINFOHEADER

type TLPBITMAPINFOHEADER = uintptr

type LPBITMAPINFOHEADER = TLPBITMAPINFOHEADER

type TPBITMAPINFOHEADER = uintptr

type PBITMAPINFOHEADER = TPBITMAPINFOHEADER

type TBITMAPV4HEADER = struct {
	FbV4Size          TDWORD
	FbV4Width         TLONG
	FbV4Height        TLONG
	FbV4Planes        TWORD
	FbV4BitCount      TWORD
	FbV4V4Compression TDWORD
	FbV4SizeImage     TDWORD
	FbV4XPelsPerMeter TLONG
	FbV4YPelsPerMeter TLONG
	FbV4ClrUsed       TDWORD
	FbV4ClrImportant  TDWORD
	FbV4RedMask       TDWORD
	FbV4GreenMask     TDWORD
	FbV4BlueMask      TDWORD
	FbV4AlphaMask     TDWORD
	FbV4CSType        TDWORD
	FbV4Endpoints     TCIEXYZTRIPLE
	FbV4GammaRed      TDWORD
	FbV4GammaGreen    TDWORD
	FbV4GammaBlue     TDWORD
}

type BITMAPV4HEADER = TBITMAPV4HEADER

type TLPBITMAPV4HEADER = uintptr

type LPBITMAPV4HEADER = TLPBITMAPV4HEADER

type TPBITMAPV4HEADER = uintptr

type PBITMAPV4HEADER = TPBITMAPV4HEADER

type TBITMAPV5HEADER = struct {
	FbV5Size          TDWORD
	FbV5Width         TLONG
	FbV5Height        TLONG
	FbV5Planes        TWORD
	FbV5BitCount      TWORD
	FbV5Compression   TDWORD
	FbV5SizeImage     TDWORD
	FbV5XPelsPerMeter TLONG
	FbV5YPelsPerMeter TLONG
	FbV5ClrUsed       TDWORD
	FbV5ClrImportant  TDWORD
	FbV5RedMask       TDWORD
	FbV5GreenMask     TDWORD
	FbV5BlueMask      TDWORD
	FbV5AlphaMask     TDWORD
	FbV5CSType        TDWORD
	FbV5Endpoints     TCIEXYZTRIPLE
	FbV5GammaRed      TDWORD
	FbV5GammaGreen    TDWORD
	FbV5GammaBlue     TDWORD
	FbV5Intent        TDWORD
	FbV5ProfileData   TDWORD
	FbV5ProfileSize   TDWORD
	FbV5Reserved      TDWORD
}

type BITMAPV5HEADER = TBITMAPV5HEADER

type TLPBITMAPV5HEADER = uintptr

type LPBITMAPV5HEADER = TLPBITMAPV5HEADER

type TPBITMAPV5HEADER = uintptr

type PBITMAPV5HEADER = TPBITMAPV5HEADER

type TBITMAPINFO = struct {
	FbmiHeader TBITMAPINFOHEADER
	FbmiColors [1]TRGBQUAD
}

type BITMAPINFO = TBITMAPINFO

type TtagBITMAPINFO = TBITMAPINFO

type tagBITMAPINFO = TtagBITMAPINFO

type TLPBITMAPINFO = uintptr

type LPBITMAPINFO = TLPBITMAPINFO

type TPBITMAPINFO = uintptr

type PBITMAPINFO = TPBITMAPINFO

type TBITMAPCOREINFO = struct {
	FbmciHeader TBITMAPCOREHEADER
	FbmciColors [1]TRGBTRIPLE
}

type BITMAPCOREINFO = TBITMAPCOREINFO

type TtagBITMAPCOREINFO = TBITMAPCOREINFO

type tagBITMAPCOREINFO = TtagBITMAPCOREINFO

type TLPBITMAPCOREINFO = uintptr

type LPBITMAPCOREINFO = TLPBITMAPCOREINFO

type TPBITMAPCOREINFO = uintptr

type PBITMAPCOREINFO = TPBITMAPCOREINFO

type TBITMAPFILEHEADER = struct {
	FbfType      TWORD
	FbfSize      TDWORD
	FbfReserved1 TWORD
	FbfReserved2 TWORD
	FbfOffBits   TDWORD
}

type BITMAPFILEHEADER = TBITMAPFILEHEADER

type TtagBITMAPFILEHEADER = TBITMAPFILEHEADER

type tagBITMAPFILEHEADER = TtagBITMAPFILEHEADER

type TLPBITMAPFILEHEADER = uintptr

type LPBITMAPFILEHEADER = TLPBITMAPFILEHEADER

type TPBITMAPFILEHEADER = uintptr

type PBITMAPFILEHEADER = TPBITMAPFILEHEADER

type TFONTSIGNATURE = struct {
	FfsUsb [4]TDWORD
	FfsCsb [2]TDWORD
}

type FONTSIGNATURE = TFONTSIGNATURE

type TtagFONTSIGNATURE = TFONTSIGNATURE

type tagFONTSIGNATURE = TtagFONTSIGNATURE

type TPFONTSIGNATURE = uintptr

type PFONTSIGNATURE = TPFONTSIGNATURE

type TLPFONTSIGNATURE = uintptr

type LPFONTSIGNATURE = TLPFONTSIGNATURE

type TCHARSETINFO = struct {
	FciCharset TUINT
	FciACP     TUINT
	Ffs        TFONTSIGNATURE
}

type CHARSETINFO = TCHARSETINFO

type TtagCHARSETINFO = TCHARSETINFO

type tagCHARSETINFO = TtagCHARSETINFO

type TPCHARSETINFO = uintptr

type PCHARSETINFO = TPCHARSETINFO

type TNPCHARSETINFO = uintptr

type NPCHARSETINFO = TNPCHARSETINFO

type TLPCHARSETINFO = uintptr

type LPCHARSETINFO = TLPCHARSETINFO

type TLOCALESIGNATURE = struct {
	FlsUsb          [4]TDWORD
	FlsCsbDefault   [2]TDWORD
	FlsCsbSupported [2]TDWORD
}

type LOCALESIGNATURE = TLOCALESIGNATURE

type TtagLOCALESIGNATURE = TLOCALESIGNATURE

type tagLOCALESIGNATURE = TtagLOCALESIGNATURE

type TPLOCALESIGNATURE = uintptr

type PLOCALESIGNATURE = TPLOCALESIGNATURE

type TLPLOCALESIGNATURE = uintptr

type LPLOCALESIGNATURE = TLPLOCALESIGNATURE

type THANDLETABLE = struct {
	FobjectHandle [1]THGDIOBJ
}

type HANDLETABLE = THANDLETABLE

type TtagHANDLETABLE = THANDLETABLE

type tagHANDLETABLE = TtagHANDLETABLE

type TPHANDLETABLE = uintptr

type PHANDLETABLE = TPHANDLETABLE

type TLPHANDLETABLE = uintptr

type LPHANDLETABLE = TLPHANDLETABLE

type TMETARECORD = struct {
	FrdSize     TDWORD
	FrdFunction TWORD
	FrdParm     [1]TWORD
}

type METARECORD = TMETARECORD

type TtagMETARECORD = TMETARECORD

type tagMETARECORD = TtagMETARECORD

type TPMETARECORD = uintptr

type PMETARECORD = TPMETARECORD

type TLPMETARECORD = uintptr

type LPMETARECORD = TLPMETARECORD

type TMETAFILEPICT = struct {
	Fmm   TLONG
	FxExt TLONG
	FyExt TLONG
	FhMF  THMETAFILE
}

type METAFILEPICT = TMETAFILEPICT

type TtagMETAFILEPICT = TMETAFILEPICT

type tagMETAFILEPICT = TtagMETAFILEPICT

type TLPMETAFILEPICT = uintptr

type LPMETAFILEPICT = TLPMETAFILEPICT

type TMETAHEADER = struct {
	FmtType         TWORD
	FmtHeaderSize   TWORD
	FmtVersion      TWORD
	FmtSize         TDWORD
	FmtNoObjects    TWORD
	FmtMaxRecord    TDWORD
	FmtNoParameters TWORD
}

type METAHEADER = TMETAHEADER

type TtagMETAHEADER = TMETAHEADER

type tagMETAHEADER = TtagMETAHEADER

type TPMETAHEADER = uintptr

type PMETAHEADER = TPMETAHEADER

type TLPMETAHEADER = uintptr

type LPMETAHEADER = TLPMETAHEADER

type TENHMETARECORD = struct {
	FiType TDWORD
	FnSize TDWORD
	FdParm [1]TDWORD
}

type ENHMETARECORD = TENHMETARECORD

type TtagENHMETARECORD = TENHMETARECORD

type tagENHMETARECORD = TtagENHMETARECORD

type TPENHMETARECORD = uintptr

type PENHMETARECORD = TPENHMETARECORD

type TLPENHMETARECORD = uintptr

type LPENHMETARECORD = TLPENHMETARECORD

type TENHMETAHEADER = struct {
	FiType          TDWORD
	FnSize          TDWORD
	FrclBounds      TRECTL
	FrclFrame       TRECTL
	FdSignature     TDWORD
	FnVersion       TDWORD
	FnBytes         TDWORD
	FnRecords       TDWORD
	FnHandles       TWORD
	FsReserved      TWORD
	FnDescription   TDWORD
	FoffDescription TDWORD
	FnPalEntries    TDWORD
	FszlDevice      TSIZEL
	FszlMillimeters TSIZEL
	FcbPixelFormat  TDWORD
	FoffPixelFormat TDWORD
	FbOpenGL        TDWORD
	FszlMicrometers TSIZEL
}

type ENHMETAHEADER = TENHMETAHEADER

type TtagENHMETAHEADER = TENHMETAHEADER

type tagENHMETAHEADER = TtagENHMETAHEADER

type TPENHMETAHEADER = uintptr

type PENHMETAHEADER = TPENHMETAHEADER

type TLPENHMETAHEADER = uintptr

type LPENHMETAHEADER = TLPENHMETAHEADER

type TBCHAR = uint8

type BCHAR = TBCHAR

type TTEXTMETRICA = struct {
	FtmHeight           TLONG
	FtmAscent           TLONG
	FtmDescent          TLONG
	FtmInternalLeading  TLONG
	FtmExternalLeading  TLONG
	FtmAveCharWidth     TLONG
	FtmMaxCharWidth     TLONG
	FtmWeight           TLONG
	FtmOverhang         TLONG
	FtmDigitizedAspectX TLONG
	FtmDigitizedAspectY TLONG
	FtmFirstChar        TBYTE
	FtmLastChar         TBYTE
	FtmDefaultChar      TBYTE
	FtmBreakChar        TBYTE
	FtmItalic           TBYTE
	FtmUnderlined       TBYTE
	FtmStruckOut        TBYTE
	FtmPitchAndFamily   TBYTE
	FtmCharSet          TBYTE
}

type TEXTMETRICA = TTEXTMETRICA

type TtagTEXTMETRICA = TTEXTMETRICA

type tagTEXTMETRICA = TtagTEXTMETRICA

type TPTEXTMETRICA = uintptr

type PTEXTMETRICA = TPTEXTMETRICA

type TNPTEXTMETRICA = uintptr

type NPTEXTMETRICA = TNPTEXTMETRICA

type TLPTEXTMETRICA = uintptr

type LPTEXTMETRICA = TLPTEXTMETRICA

type TTEXTMETRICW = struct {
	FtmHeight           TLONG
	FtmAscent           TLONG
	FtmDescent          TLONG
	FtmInternalLeading  TLONG
	FtmExternalLeading  TLONG
	FtmAveCharWidth     TLONG
	FtmMaxCharWidth     TLONG
	FtmWeight           TLONG
	FtmOverhang         TLONG
	FtmDigitizedAspectX TLONG
	FtmDigitizedAspectY TLONG
	FtmFirstChar        TWCHAR
	FtmLastChar         TWCHAR
	FtmDefaultChar      TWCHAR
	FtmBreakChar        TWCHAR
	FtmItalic           TBYTE
	FtmUnderlined       TBYTE
	FtmStruckOut        TBYTE
	FtmPitchAndFamily   TBYTE
	FtmCharSet          TBYTE
}

type TEXTMETRICW = TTEXTMETRICW

type TtagTEXTMETRICW = TTEXTMETRICW

type tagTEXTMETRICW = TtagTEXTMETRICW

type TPTEXTMETRICW = uintptr

type PTEXTMETRICW = TPTEXTMETRICW

type TNPTEXTMETRICW = uintptr

type NPTEXTMETRICW = TNPTEXTMETRICW

type TLPTEXTMETRICW = uintptr

type LPTEXTMETRICW = TLPTEXTMETRICW

type TTEXTMETRIC = struct {
	FtmHeight           TLONG
	FtmAscent           TLONG
	FtmDescent          TLONG
	FtmInternalLeading  TLONG
	FtmExternalLeading  TLONG
	FtmAveCharWidth     TLONG
	FtmMaxCharWidth     TLONG
	FtmWeight           TLONG
	FtmOverhang         TLONG
	FtmDigitizedAspectX TLONG
	FtmDigitizedAspectY TLONG
	FtmFirstChar        TBYTE
	FtmLastChar         TBYTE
	FtmDefaultChar      TBYTE
	FtmBreakChar        TBYTE
	FtmItalic           TBYTE
	FtmUnderlined       TBYTE
	FtmStruckOut        TBYTE
	FtmPitchAndFamily   TBYTE
	FtmCharSet          TBYTE
}

type TEXTMETRIC = TTEXTMETRIC

type TPTEXTMETRIC = uintptr

type PTEXTMETRIC = TPTEXTMETRIC

type TNPTEXTMETRIC = uintptr

type NPTEXTMETRIC = TNPTEXTMETRIC

type TLPTEXTMETRIC = uintptr

type LPTEXTMETRIC = TLPTEXTMETRIC

type TNEWTEXTMETRICA = struct {
	FtmHeight           TLONG
	FtmAscent           TLONG
	FtmDescent          TLONG
	FtmInternalLeading  TLONG
	FtmExternalLeading  TLONG
	FtmAveCharWidth     TLONG
	FtmMaxCharWidth     TLONG
	FtmWeight           TLONG
	FtmOverhang         TLONG
	FtmDigitizedAspectX TLONG
	FtmDigitizedAspectY TLONG
	FtmFirstChar        TBYTE
	FtmLastChar         TBYTE
	FtmDefaultChar      TBYTE
	FtmBreakChar        TBYTE
	FtmItalic           TBYTE
	FtmUnderlined       TBYTE
	FtmStruckOut        TBYTE
	FtmPitchAndFamily   TBYTE
	FtmCharSet          TBYTE
	FntmFlags           TDWORD
	FntmSizeEM          TUINT
	FntmCellHeight      TUINT
	FntmAvgWidth        TUINT
}

type NEWTEXTMETRICA = TNEWTEXTMETRICA

type TtagNEWTEXTMETRICA = TNEWTEXTMETRICA

type tagNEWTEXTMETRICA = TtagNEWTEXTMETRICA

type TPNEWTEXTMETRICA = uintptr

type PNEWTEXTMETRICA = TPNEWTEXTMETRICA

type TNPNEWTEXTMETRICA = uintptr

type NPNEWTEXTMETRICA = TNPNEWTEXTMETRICA

type TLPNEWTEXTMETRICA = uintptr

type LPNEWTEXTMETRICA = TLPNEWTEXTMETRICA

type TNEWTEXTMETRICW = struct {
	FtmHeight           TLONG
	FtmAscent           TLONG
	FtmDescent          TLONG
	FtmInternalLeading  TLONG
	FtmExternalLeading  TLONG
	FtmAveCharWidth     TLONG
	FtmMaxCharWidth     TLONG
	FtmWeight           TLONG
	FtmOverhang         TLONG
	FtmDigitizedAspectX TLONG
	FtmDigitizedAspectY TLONG
	FtmFirstChar        TWCHAR
	FtmLastChar         TWCHAR
	FtmDefaultChar      TWCHAR
	FtmBreakChar        TWCHAR
	FtmItalic           TBYTE
	FtmUnderlined       TBYTE
	FtmStruckOut        TBYTE
	FtmPitchAndFamily   TBYTE
	FtmCharSet          TBYTE
	FntmFlags           TDWORD
	FntmSizeEM          TUINT
	FntmCellHeight      TUINT
	FntmAvgWidth        TUINT
}

type NEWTEXTMETRICW = TNEWTEXTMETRICW

type TtagNEWTEXTMETRICW = TNEWTEXTMETRICW

type tagNEWTEXTMETRICW = TtagNEWTEXTMETRICW

type TPNEWTEXTMETRICW = uintptr

type PNEWTEXTMETRICW = TPNEWTEXTMETRICW

type TNPNEWTEXTMETRICW = uintptr

type NPNEWTEXTMETRICW = TNPNEWTEXTMETRICW

type TLPNEWTEXTMETRICW = uintptr

type LPNEWTEXTMETRICW = TLPNEWTEXTMETRICW

type TNEWTEXTMETRIC = struct {
	FtmHeight           TLONG
	FtmAscent           TLONG
	FtmDescent          TLONG
	FtmInternalLeading  TLONG
	FtmExternalLeading  TLONG
	FtmAveCharWidth     TLONG
	FtmMaxCharWidth     TLONG
	FtmWeight           TLONG
	FtmOverhang         TLONG
	FtmDigitizedAspectX TLONG
	FtmDigitizedAspectY TLONG
	FtmFirstChar        TBYTE
	FtmLastChar         TBYTE
	FtmDefaultChar      TBYTE
	FtmBreakChar        TBYTE
	FtmItalic           TBYTE
	FtmUnderlined       TBYTE
	FtmStruckOut        TBYTE
	FtmPitchAndFamily   TBYTE
	FtmCharSet          TBYTE
	FntmFlags           TDWORD
	FntmSizeEM          TUINT
	FntmCellHeight      TUINT
	FntmAvgWidth        TUINT
}

type NEWTEXTMETRIC = TNEWTEXTMETRIC

type TPNEWTEXTMETRIC = uintptr

type PNEWTEXTMETRIC = TPNEWTEXTMETRIC

type TNPNEWTEXTMETRIC = uintptr

type NPNEWTEXTMETRIC = TNPNEWTEXTMETRIC

type TLPNEWTEXTMETRIC = uintptr

type LPNEWTEXTMETRIC = TLPNEWTEXTMETRIC

type TNEWTEXTMETRICEXA = struct {
	FntmTm      TNEWTEXTMETRICA
	FntmFontSig TFONTSIGNATURE
}

type NEWTEXTMETRICEXA = TNEWTEXTMETRICEXA

type TtagNEWTEXTMETRICEXA = TNEWTEXTMETRICEXA

type tagNEWTEXTMETRICEXA = TtagNEWTEXTMETRICEXA

type TNEWTEXTMETRICEXW = struct {
	FntmTm      TNEWTEXTMETRICW
	FntmFontSig TFONTSIGNATURE
}

type NEWTEXTMETRICEXW = TNEWTEXTMETRICEXW

type TtagNEWTEXTMETRICEXW = TNEWTEXTMETRICEXW

type tagNEWTEXTMETRICEXW = TtagNEWTEXTMETRICEXW

type TNEWTEXTMETRICEX = struct {
	FntmTm      TNEWTEXTMETRICA
	FntmFontSig TFONTSIGNATURE
}

type NEWTEXTMETRICEX = TNEWTEXTMETRICEX

type TPELARRAY = struct {
	FpaXCount TLONG
	FpaYCount TLONG
	FpaXExt   TLONG
	FpaYExt   TLONG
	FpaRGBs   TBYTE
}

type PELARRAY = TPELARRAY

type TtagPELARRAY = TPELARRAY

type tagPELARRAY = TtagPELARRAY

type TPPELARRAY = uintptr

type PPELARRAY = TPPELARRAY

type TNPPELARRAY = uintptr

type NPPELARRAY = TNPPELARRAY

type TLPPELARRAY = uintptr

type LPPELARRAY = TLPPELARRAY

type TLOGBRUSH = struct {
	FlbStyle TUINT
	FlbColor TCOLORREF
	FlbHatch TULONG_PTR
}

type LOGBRUSH = TLOGBRUSH

type TtagLOGBRUSH = TLOGBRUSH

type tagLOGBRUSH = TtagLOGBRUSH

type TPLOGBRUSH = uintptr

type PLOGBRUSH = TPLOGBRUSH

type TNPLOGBRUSH = uintptr

type NPLOGBRUSH = TNPLOGBRUSH

type TLPLOGBRUSH = uintptr

type LPLOGBRUSH = TLPLOGBRUSH

type TLOGBRUSH32 = struct {
	FlbStyle TUINT
	FlbColor TCOLORREF
	FlbHatch TULONG
}

type LOGBRUSH32 = TLOGBRUSH32

type TtagLOGBRUSH32 = TLOGBRUSH32

type tagLOGBRUSH32 = TtagLOGBRUSH32

type TPLOGBRUSH32 = uintptr

type PLOGBRUSH32 = TPLOGBRUSH32

type TNPLOGBRUSH32 = uintptr

type NPLOGBRUSH32 = TNPLOGBRUSH32

type TLPLOGBRUSH32 = uintptr

type LPLOGBRUSH32 = TLPLOGBRUSH32

type TPATTERN = struct {
	FlbStyle TUINT
	FlbColor TCOLORREF
	FlbHatch TULONG_PTR
}

type PATTERN = TPATTERN

type TPPATTERN = uintptr

type PPATTERN = TPPATTERN

type TNPPATTERN = uintptr

type NPPATTERN = TNPPATTERN

type TLPPATTERN = uintptr

type LPPATTERN = TLPPATTERN

type TLOGPEN = struct {
	FlopnStyle TUINT
	FlopnWidth TPOINT
	FlopnColor TCOLORREF
}

type LOGPEN = TLOGPEN

type TtagLOGPEN = TLOGPEN

type tagLOGPEN = TtagLOGPEN

type TPLOGPEN = uintptr

type PLOGPEN = TPLOGPEN

type TNPLOGPEN = uintptr

type NPLOGPEN = TNPLOGPEN

type TLPLOGPEN = uintptr

type LPLOGPEN = TLPLOGPEN

type TEXTLOGPEN = struct {
	FelpPenStyle   TDWORD
	FelpWidth      TDWORD
	FelpBrushStyle TUINT
	FelpColor      TCOLORREF
	FelpHatch      TULONG_PTR
	FelpNumEntries TDWORD
	FelpStyleEntry [1]TDWORD
}

type EXTLOGPEN = TEXTLOGPEN

type TtagEXTLOGPEN = TEXTLOGPEN

type tagEXTLOGPEN = TtagEXTLOGPEN

type TPEXTLOGPEN = uintptr

type PEXTLOGPEN = TPEXTLOGPEN

type TNPEXTLOGPEN = uintptr

type NPEXTLOGPEN = TNPEXTLOGPEN

type TLPEXTLOGPEN = uintptr

type LPEXTLOGPEN = TLPEXTLOGPEN

type TEXTLOGPEN32 = struct {
	FelpPenStyle   TDWORD
	FelpWidth      TDWORD
	FelpBrushStyle TUINT
	FelpColor      TCOLORREF
	FelpHatch      TULONG
	FelpNumEntries TDWORD
	FelpStyleEntry [1]TDWORD
}

type EXTLOGPEN32 = TEXTLOGPEN32

type TtagEXTLOGPEN32 = TEXTLOGPEN32

type tagEXTLOGPEN32 = TtagEXTLOGPEN32

type TPEXTLOGPEN32 = uintptr

type PEXTLOGPEN32 = TPEXTLOGPEN32

type TNPEXTLOGPEN32 = uintptr

type NPEXTLOGPEN32 = TNPEXTLOGPEN32

type TLPEXTLOGPEN32 = uintptr

type LPEXTLOGPEN32 = TLPEXTLOGPEN32

type TPALETTEENTRY = struct {
	FpeRed   TBYTE
	FpeGreen TBYTE
	FpeBlue  TBYTE
	FpeFlags TBYTE
}

type PALETTEENTRY = TPALETTEENTRY

type TtagPALETTEENTRY = TPALETTEENTRY

type tagPALETTEENTRY = TtagPALETTEENTRY

type TPPALETTEENTRY = uintptr

type PPALETTEENTRY = TPPALETTEENTRY

type TLPPALETTEENTRY = uintptr

type LPPALETTEENTRY = TLPPALETTEENTRY

type TLOGPALETTE = struct {
	FpalVersion    TWORD
	FpalNumEntries TWORD
	FpalPalEntry   [1]TPALETTEENTRY
}

type LOGPALETTE = TLOGPALETTE

type TtagLOGPALETTE = TLOGPALETTE

type tagLOGPALETTE = TtagLOGPALETTE

type TPLOGPALETTE = uintptr

type PLOGPALETTE = TPLOGPALETTE

type TNPLOGPALETTE = uintptr

type NPLOGPALETTE = TNPLOGPALETTE

type TLPLOGPALETTE = uintptr

type LPLOGPALETTE = TLPLOGPALETTE

type TLOGFONTA = struct {
	FlfHeight         TLONG
	FlfWidth          TLONG
	FlfEscapement     TLONG
	FlfOrientation    TLONG
	FlfWeight         TLONG
	FlfItalic         TBYTE
	FlfUnderline      TBYTE
	FlfStrikeOut      TBYTE
	FlfCharSet        TBYTE
	FlfOutPrecision   TBYTE
	FlfClipPrecision  TBYTE
	FlfQuality        TBYTE
	FlfPitchAndFamily TBYTE
	FlfFaceName       [32]TCHAR
}

type LOGFONTA = TLOGFONTA

type TtagLOGFONTA = TLOGFONTA

type tagLOGFONTA = TtagLOGFONTA

type TPLOGFONTA = uintptr

type PLOGFONTA = TPLOGFONTA

type TNPLOGFONTA = uintptr

type NPLOGFONTA = TNPLOGFONTA

type TLPLOGFONTA = uintptr

type LPLOGFONTA = TLPLOGFONTA

type TLOGFONTW = struct {
	FlfHeight         TLONG
	FlfWidth          TLONG
	FlfEscapement     TLONG
	FlfOrientation    TLONG
	FlfWeight         TLONG
	FlfItalic         TBYTE
	FlfUnderline      TBYTE
	FlfStrikeOut      TBYTE
	FlfCharSet        TBYTE
	FlfOutPrecision   TBYTE
	FlfClipPrecision  TBYTE
	FlfQuality        TBYTE
	FlfPitchAndFamily TBYTE
	FlfFaceName       [32]TWCHAR
}

type LOGFONTW = TLOGFONTW

type TtagLOGFONTW = TLOGFONTW

type tagLOGFONTW = TtagLOGFONTW

type TPLOGFONTW = uintptr

type PLOGFONTW = TPLOGFONTW

type TNPLOGFONTW = uintptr

type NPLOGFONTW = TNPLOGFONTW

type TLPLOGFONTW = uintptr

type LPLOGFONTW = TLPLOGFONTW

type TLOGFONT = struct {
	FlfHeight         TLONG
	FlfWidth          TLONG
	FlfEscapement     TLONG
	FlfOrientation    TLONG
	FlfWeight         TLONG
	FlfItalic         TBYTE
	FlfUnderline      TBYTE
	FlfStrikeOut      TBYTE
	FlfCharSet        TBYTE
	FlfOutPrecision   TBYTE
	FlfClipPrecision  TBYTE
	FlfQuality        TBYTE
	FlfPitchAndFamily TBYTE
	FlfFaceName       [32]TCHAR
}

type LOGFONT = TLOGFONT

type TPLOGFONT = uintptr

type PLOGFONT = TPLOGFONT

type TNPLOGFONT = uintptr

type NPLOGFONT = TNPLOGFONT

type TLPLOGFONT = uintptr

type LPLOGFONT = TLPLOGFONT

type TENUMLOGFONTA = struct {
	FelfLogFont  TLOGFONTA
	FelfFullName [64]TBYTE
	FelfStyle    [32]TBYTE
}

type ENUMLOGFONTA = TENUMLOGFONTA

type TtagENUMLOGFONTA = TENUMLOGFONTA

type tagENUMLOGFONTA = TtagENUMLOGFONTA

type TLPENUMLOGFONTA = uintptr

type LPENUMLOGFONTA = TLPENUMLOGFONTA

type TENUMLOGFONTW = struct {
	FelfLogFont  TLOGFONTW
	FelfFullName [64]TWCHAR
	FelfStyle    [32]TWCHAR
}

type ENUMLOGFONTW = TENUMLOGFONTW

type TtagENUMLOGFONTW = TENUMLOGFONTW

type tagENUMLOGFONTW = TtagENUMLOGFONTW

type TLPENUMLOGFONTW = uintptr

type LPENUMLOGFONTW = TLPENUMLOGFONTW

type TENUMLOGFONT = struct {
	FelfLogFont  TLOGFONTA
	FelfFullName [64]TBYTE
	FelfStyle    [32]TBYTE
}

type ENUMLOGFONT = TENUMLOGFONT

type TLPENUMLOGFONT = uintptr

type LPENUMLOGFONT = TLPENUMLOGFONT

type TENUMLOGFONTEXA = struct {
	FelfLogFont  TLOGFONTA
	FelfFullName [64]TBYTE
	FelfStyle    [32]TBYTE
	FelfScript   [32]TBYTE
}

type ENUMLOGFONTEXA = TENUMLOGFONTEXA

type TtagENUMLOGFONTEXA = TENUMLOGFONTEXA

type tagENUMLOGFONTEXA = TtagENUMLOGFONTEXA

type TLPENUMLOGFONTEXA = uintptr

type LPENUMLOGFONTEXA = TLPENUMLOGFONTEXA

type TENUMLOGFONTEXW = struct {
	FelfLogFont  TLOGFONTW
	FelfFullName [64]TWCHAR
	FelfStyle    [32]TWCHAR
	FelfScript   [32]TWCHAR
}

type ENUMLOGFONTEXW = TENUMLOGFONTEXW

type TtagENUMLOGFONTEXW = TENUMLOGFONTEXW

type tagENUMLOGFONTEXW = TtagENUMLOGFONTEXW

type TLPENUMLOGFONTEXW = uintptr

type LPENUMLOGFONTEXW = TLPENUMLOGFONTEXW

type TENUMLOGFONTEX = struct {
	FelfLogFont  TLOGFONTA
	FelfFullName [64]TBYTE
	FelfStyle    [32]TBYTE
	FelfScript   [32]TBYTE
}

type ENUMLOGFONTEX = TENUMLOGFONTEX

type TLPENUMLOGFONTEX = uintptr

type LPENUMLOGFONTEX = TLPENUMLOGFONTEX

type TPANOSE = struct {
	FbFamilyType      TBYTE
	FbSerifStyle      TBYTE
	FbWeight          TBYTE
	FbProportion      TBYTE
	FbContrast        TBYTE
	FbStrokeVariation TBYTE
	FbArmStyle        TBYTE
	FbLetterform      TBYTE
	FbMidline         TBYTE
	FbXHeight         TBYTE
}

type PANOSE = TPANOSE

type TtagPANOSE = TPANOSE

type tagPANOSE = TtagPANOSE

type TLPPANOSE = uintptr

type LPPANOSE = TLPPANOSE

type TEXTLOGFONTA = struct {
	FelfLogFont   TLOGFONTA
	FelfFullName  [64]TBYTE
	FelfStyle     [32]TBYTE
	FelfVersion   TDWORD
	FelfStyleSize TDWORD
	FelfMatch     TDWORD
	FelfReserved  TDWORD
	FelfVendorId  [4]TBYTE
	FelfCulture   TDWORD
	FelfPanose    TPANOSE
}

type EXTLOGFONTA = TEXTLOGFONTA

type TtagEXTLOGFONTA = TEXTLOGFONTA

type tagEXTLOGFONTA = TtagEXTLOGFONTA

type TPEXTLOGFONTA = uintptr

type PEXTLOGFONTA = TPEXTLOGFONTA

type TNPEXTLOGFONTA = uintptr

type NPEXTLOGFONTA = TNPEXTLOGFONTA

type TLPEXTLOGFONTA = uintptr

type LPEXTLOGFONTA = TLPEXTLOGFONTA

type TEXTLOGFONTW = struct {
	FelfLogFont   TLOGFONTW
	FelfFullName  [64]TWCHAR
	FelfStyle     [32]TWCHAR
	FelfVersion   TDWORD
	FelfStyleSize TDWORD
	FelfMatch     TDWORD
	FelfReserved  TDWORD
	FelfVendorId  [4]TBYTE
	FelfCulture   TDWORD
	FelfPanose    TPANOSE
}

type EXTLOGFONTW = TEXTLOGFONTW

type TtagEXTLOGFONTW = TEXTLOGFONTW

type tagEXTLOGFONTW = TtagEXTLOGFONTW

type TPEXTLOGFONTW = uintptr

type PEXTLOGFONTW = TPEXTLOGFONTW

type TNPEXTLOGFONTW = uintptr

type NPEXTLOGFONTW = TNPEXTLOGFONTW

type TLPEXTLOGFONTW = uintptr

type LPEXTLOGFONTW = TLPEXTLOGFONTW

type TEXTLOGFONT = struct {
	FelfLogFont   TLOGFONTA
	FelfFullName  [64]TBYTE
	FelfStyle     [32]TBYTE
	FelfVersion   TDWORD
	FelfStyleSize TDWORD
	FelfMatch     TDWORD
	FelfReserved  TDWORD
	FelfVendorId  [4]TBYTE
	FelfCulture   TDWORD
	FelfPanose    TPANOSE
}

type EXTLOGFONT = TEXTLOGFONT

type TPEXTLOGFONT = uintptr

type PEXTLOGFONT = TPEXTLOGFONT

type TNPEXTLOGFONT = uintptr

type NPEXTLOGFONT = TNPEXTLOGFONT

type TLPEXTLOGFONT = uintptr

type LPEXTLOGFONT = TLPEXTLOGFONT

type TDEVMODEA = struct {
	FdmDeviceName    [32]TBYTE
	FdmSpecVersion   TWORD
	FdmDriverVersion TWORD
	FdmSize          TWORD
	FdmDriverExtra   TWORD
	FdmFields        TDWORD
	F__ccgo6_44      struct {
		F__ccgo1_0 [0]struct {
			FdmPosition           TPOINTL
			FdmDisplayOrientation TDWORD
			FdmDisplayFixedOutput TDWORD
		}
		F__ccgo0_0 struct {
			FdmOrientation   int16
			FdmPaperSize     int16
			FdmPaperLength   int16
			FdmPaperWidth    int16
			FdmScale         int16
			FdmCopies        int16
			FdmDefaultSource int16
			FdmPrintQuality  int16
		}
	}
	FdmColor       int16
	FdmDuplex      int16
	FdmYResolution int16
	FdmTTOption    int16
	FdmCollate     int16
	FdmFormName    [32]TBYTE
	FdmLogPixels   TWORD
	FdmBitsPerPel  TDWORD
	FdmPelsWidth   TDWORD
	FdmPelsHeight  TDWORD
	F__ccgo17_116  struct {
		FdmNup          [0]TDWORD
		FdmDisplayFlags TDWORD
	}
	FdmDisplayFrequency TDWORD
	FdmICMMethod        TDWORD
	FdmICMIntent        TDWORD
	FdmMediaType        TDWORD
	FdmDitherType       TDWORD
	FdmReserved1        TDWORD
	FdmReserved2        TDWORD
	FdmPanningWidth     TDWORD
	FdmPanningHeight    TDWORD
}

type DEVMODEA = TDEVMODEA

type T_devicemodeA = TDEVMODEA

type _devicemodeA = T_devicemodeA

type TPDEVMODEA = uintptr

type PDEVMODEA = TPDEVMODEA

type TNPDEVMODEA = uintptr

type NPDEVMODEA = TNPDEVMODEA

type TLPDEVMODEA = uintptr

type LPDEVMODEA = TLPDEVMODEA

type TDEVMODEW = struct {
	FdmDeviceName    [32]TWCHAR
	FdmSpecVersion   TWORD
	FdmDriverVersion TWORD
	FdmSize          TWORD
	FdmDriverExtra   TWORD
	FdmFields        TDWORD
	F__ccgo6_76      struct {
		F__ccgo1_0 [0]struct {
			FdmPosition           TPOINTL
			FdmDisplayOrientation TDWORD
			FdmDisplayFixedOutput TDWORD
		}
		F__ccgo0_0 struct {
			FdmOrientation   int16
			FdmPaperSize     int16
			FdmPaperLength   int16
			FdmPaperWidth    int16
			FdmScale         int16
			FdmCopies        int16
			FdmDefaultSource int16
			FdmPrintQuality  int16
		}
	}
	FdmColor       int16
	FdmDuplex      int16
	FdmYResolution int16
	FdmTTOption    int16
	FdmCollate     int16
	FdmFormName    [32]TWCHAR
	FdmLogPixels   TWORD
	FdmBitsPerPel  TDWORD
	FdmPelsWidth   TDWORD
	FdmPelsHeight  TDWORD
	F__ccgo17_180  struct {
		FdmNup          [0]TDWORD
		FdmDisplayFlags TDWORD
	}
	FdmDisplayFrequency TDWORD
	FdmICMMethod        TDWORD
	FdmICMIntent        TDWORD
	FdmMediaType        TDWORD
	FdmDitherType       TDWORD
	FdmReserved1        TDWORD
	FdmReserved2        TDWORD
	FdmPanningWidth     TDWORD
	FdmPanningHeight    TDWORD
}

type DEVMODEW = TDEVMODEW

type T_devicemodeW = TDEVMODEW

type _devicemodeW = T_devicemodeW

type TPDEVMODEW = uintptr

type PDEVMODEW = TPDEVMODEW

type TNPDEVMODEW = uintptr

type NPDEVMODEW = TNPDEVMODEW

type TLPDEVMODEW = uintptr

type LPDEVMODEW = TLPDEVMODEW

type TDEVMODE = struct {
	FdmDeviceName    [32]TBYTE
	FdmSpecVersion   TWORD
	FdmDriverVersion TWORD
	FdmSize          TWORD
	FdmDriverExtra   TWORD
	FdmFields        TDWORD
	F__ccgo6_44      struct {
		F__ccgo1_0 [0]struct {
			FdmPosition           TPOINTL
			FdmDisplayOrientation TDWORD
			FdmDisplayFixedOutput TDWORD
		}
		F__ccgo0_0 struct {
			FdmOrientation   int16
			FdmPaperSize     int16
			FdmPaperLength   int16
			FdmPaperWidth    int16
			FdmScale         int16
			FdmCopies        int16
			FdmDefaultSource int16
			FdmPrintQuality  int16
		}
	}
	FdmColor       int16
	FdmDuplex      int16
	FdmYResolution int16
	FdmTTOption    int16
	FdmCollate     int16
	FdmFormName    [32]TBYTE
	FdmLogPixels   TWORD
	FdmBitsPerPel  TDWORD
	FdmPelsWidth   TDWORD
	FdmPelsHeight  TDWORD
	F__ccgo17_116  struct {
		FdmNup          [0]TDWORD
		FdmDisplayFlags TDWORD
	}
	FdmDisplayFrequency TDWORD
	FdmICMMethod        TDWORD
	FdmICMIntent        TDWORD
	FdmMediaType        TDWORD
	FdmDitherType       TDWORD
	FdmReserved1        TDWORD
	FdmReserved2        TDWORD
	FdmPanningWidth     TDWORD
	FdmPanningHeight    TDWORD
}

type DEVMODE = TDEVMODE

type TPDEVMODE = uintptr

type PDEVMODE = TPDEVMODE

type TNPDEVMODE = uintptr

type NPDEVMODE = TNPDEVMODE

type TLPDEVMODE = uintptr

type LPDEVMODE = TLPDEVMODE

type TDISPLAY_DEVICEA = struct {
	Fcb           TDWORD
	FDeviceName   [32]TCHAR
	FDeviceString [128]TCHAR
	FStateFlags   TDWORD
	FDeviceID     [128]TCHAR
	FDeviceKey    [128]TCHAR
}

type DISPLAY_DEVICEA = TDISPLAY_DEVICEA

type T_DISPLAY_DEVICEA = TDISPLAY_DEVICEA

type _DISPLAY_DEVICEA = T_DISPLAY_DEVICEA

type TPDISPLAY_DEVICEA = uintptr

type PDISPLAY_DEVICEA = TPDISPLAY_DEVICEA

type TLPDISPLAY_DEVICEA = uintptr

type LPDISPLAY_DEVICEA = TLPDISPLAY_DEVICEA

type TDISPLAY_DEVICEW = struct {
	Fcb           TDWORD
	FDeviceName   [32]TWCHAR
	FDeviceString [128]TWCHAR
	FStateFlags   TDWORD
	FDeviceID     [128]TWCHAR
	FDeviceKey    [128]TWCHAR
}

type DISPLAY_DEVICEW = TDISPLAY_DEVICEW

type T_DISPLAY_DEVICEW = TDISPLAY_DEVICEW

type _DISPLAY_DEVICEW = T_DISPLAY_DEVICEW

type TPDISPLAY_DEVICEW = uintptr

type PDISPLAY_DEVICEW = TPDISPLAY_DEVICEW

type TLPDISPLAY_DEVICEW = uintptr

type LPDISPLAY_DEVICEW = TLPDISPLAY_DEVICEW

type TDISPLAY_DEVICE = struct {
	Fcb           TDWORD
	FDeviceName   [32]TCHAR
	FDeviceString [128]TCHAR
	FStateFlags   TDWORD
	FDeviceID     [128]TCHAR
	FDeviceKey    [128]TCHAR
}

type DISPLAY_DEVICE = TDISPLAY_DEVICE

type TPDISPLAY_DEVICE = uintptr

type PDISPLAY_DEVICE = TPDISPLAY_DEVICE

type TLPDISPLAY_DEVICE = uintptr

type LPDISPLAY_DEVICE = TLPDISPLAY_DEVICE

type TDISPLAYCONFIG_RATIONAL = struct {
	FNumerator   TUINT32
	FDenominator TUINT32
}

type DISPLAYCONFIG_RATIONAL = TDISPLAYCONFIG_RATIONAL

type TDISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY = int32

type DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY = TDISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY

const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER = -1
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15 = 0
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO = 1
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO = 2
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO = 3
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI = 4
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI = 5
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS = 6
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN = 8
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI = 9
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL = 10
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED = 11
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL = 12
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED = 13
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE = 14
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST = 15
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_WIRED = 16
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_VIRTUAL = 17
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = -2147483648
const _DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32 = -1

type TDISPLAYCONFIG_SCANLINE_ORDERING = uint32

type DISPLAYCONFIG_SCANLINE_ORDERING = TDISPLAYCONFIG_SCANLINE_ORDERING

const _DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0
const _DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = 1
const _DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = 2
const _DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST = 2
const _DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3
const _DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_2DREGION = struct {
	Fcx TUINT32
	Fcy TUINT32
}

type DISPLAYCONFIG_2DREGION = TDISPLAYCONFIG_2DREGION

type TDISPLAYCONFIG_VIDEO_SIGNAL_INFO = struct {
	F__ccgo_align [0]uint32
	FpixelRate    TUINT64
	FhSyncFreq    TDISPLAYCONFIG_RATIONAL
	FvSyncFreq    TDISPLAYCONFIG_RATIONAL
	FactiveSize   TDISPLAYCONFIG_2DREGION
	FtotalSize    TDISPLAYCONFIG_2DREGION
	F__ccgo5_40   struct {
		FvideoStandard        [0]TUINT32
		FAdditionalSignalInfo struct {
			F__ccgo0 uint32
		}
	}
	FscanLineOrdering TDISPLAYCONFIG_SCANLINE_ORDERING
}

type DISPLAYCONFIG_VIDEO_SIGNAL_INFO = TDISPLAYCONFIG_VIDEO_SIGNAL_INFO

type TDISPLAYCONFIG_SCALING = uint32

type DISPLAYCONFIG_SCALING = TDISPLAYCONFIG_SCALING

const _DISPLAYCONFIG_SCALING_IDENTITY = 1
const _DISPLAYCONFIG_SCALING_CENTERED = 2
const _DISPLAYCONFIG_SCALING_STRETCHED = 3
const _DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX = 4
const _DISPLAYCONFIG_SCALING_CUSTOM = 5
const _DISPLAYCONFIG_SCALING_PREFERRED = 128
const _DISPLAYCONFIG_SCALING_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_ROTATION = uint32

type DISPLAYCONFIG_ROTATION = TDISPLAYCONFIG_ROTATION

const _DISPLAYCONFIG_ROTATION_IDENTITY = 1
const _DISPLAYCONFIG_ROTATION_ROTATE90 = 2
const _DISPLAYCONFIG_ROTATION_ROTATE180 = 3
const _DISPLAYCONFIG_ROTATION_ROTATE270 = 4
const _DISPLAYCONFIG_ROTATION_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_MODE_INFO_TYPE = uint32

type DISPLAYCONFIG_MODE_INFO_TYPE = TDISPLAYCONFIG_MODE_INFO_TYPE

const _DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = 1
const _DISPLAYCONFIG_MODE_INFO_TYPE_TARGET = 2
const _DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE = 3
const _DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_PIXELFORMAT = uint32

type DISPLAYCONFIG_PIXELFORMAT = TDISPLAYCONFIG_PIXELFORMAT

const _DISPLAYCONFIG_PIXELFORMAT_8BPP = 1
const _DISPLAYCONFIG_PIXELFORMAT_16BPP = 2
const _DISPLAYCONFIG_PIXELFORMAT_24BPP = 3
const _DISPLAYCONFIG_PIXELFORMAT_32BPP = 4
const _DISPLAYCONFIG_PIXELFORMAT_NONGDI = 5
const _DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_SOURCE_MODE = struct {
	Fwidth       TUINT32
	Fheight      TUINT32
	FpixelFormat TDISPLAYCONFIG_PIXELFORMAT
	Fposition    TPOINTL
}

type DISPLAYCONFIG_SOURCE_MODE = TDISPLAYCONFIG_SOURCE_MODE

type TDISPLAYCONFIG_TARGET_MODE = struct {
	F__ccgo_align          [0]uint32
	FtargetVideoSignalInfo TDISPLAYCONFIG_VIDEO_SIGNAL_INFO
}

type DISPLAYCONFIG_TARGET_MODE = TDISPLAYCONFIG_TARGET_MODE

type TDISPLAYCONFIG_DESKTOP_IMAGE_INFO = struct {
	FPathSourceSize     TPOINTL
	FDesktopImageRegion TRECTL
	FDesktopImageClip   TRECTL
}

type DISPLAYCONFIG_DESKTOP_IMAGE_INFO = TDISPLAYCONFIG_DESKTOP_IMAGE_INFO

type TDISPLAYCONFIG_MODE_INFO = struct {
	F__ccgo_align [0]uint32
	FinfoType     TDISPLAYCONFIG_MODE_INFO_TYPE
	Fid           TUINT32
	FadapterId    TLUID
	F__ccgo3_16   struct {
		F__ccgo_align [0]uint32
		FsourceMode   [0]TDISPLAYCONFIG_SOURCE_MODE
		FtargetMode   TDISPLAYCONFIG_TARGET_MODE
	}
}

type DISPLAYCONFIG_MODE_INFO = TDISPLAYCONFIG_MODE_INFO

type TDISPLAYCONFIG_PATH_SOURCE_INFO = struct {
	FadapterId  TLUID
	Fid         TUINT32
	F__ccgo2_12 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FmodeInfoIdx TUINT32
	}
	FstatusFlags TUINT32
}

type DISPLAYCONFIG_PATH_SOURCE_INFO = TDISPLAYCONFIG_PATH_SOURCE_INFO

type TDISPLAYCONFIG_PATH_TARGET_INFO = struct {
	FadapterId  TLUID
	Fid         TUINT32
	F__ccgo2_12 struct {
		F__ccgo1_0 [0]struct {
			F__ccgo0 uint32
		}
		FmodeInfoIdx TUINT32
	}
	FoutputTechnology TDISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY
	Frotation         TDISPLAYCONFIG_ROTATION
	Fscaling          TDISPLAYCONFIG_SCALING
	FrefreshRate      TDISPLAYCONFIG_RATIONAL
	FscanLineOrdering TDISPLAYCONFIG_SCANLINE_ORDERING
	FtargetAvailable  TWINBOOL
	FstatusFlags      TUINT32
}

type DISPLAYCONFIG_PATH_TARGET_INFO = TDISPLAYCONFIG_PATH_TARGET_INFO

type TDISPLAYCONFIG_PATH_INFO = struct {
	FsourceInfo TDISPLAYCONFIG_PATH_SOURCE_INFO
	FtargetInfo TDISPLAYCONFIG_PATH_TARGET_INFO
	Fflags      TUINT32
}

type DISPLAYCONFIG_PATH_INFO = TDISPLAYCONFIG_PATH_INFO

type TDISPLAYCONFIG_TOPOLOGY_ID = uint32

type DISPLAYCONFIG_TOPOLOGY_ID = TDISPLAYCONFIG_TOPOLOGY_ID

const _DISPLAYCONFIG_TOPOLOGY_INTERNAL = 1
const _DISPLAYCONFIG_TOPOLOGY_CLONE = 2
const _DISPLAYCONFIG_TOPOLOGY_EXTEND = 4
const _DISPLAYCONFIG_TOPOLOGY_EXTERNAL = 8
const _DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_DEVICE_INFO_TYPE = uint32

type DISPLAYCONFIG_DEVICE_INFO_TYPE = TDISPLAYCONFIG_DEVICE_INFO_TYPE

const _DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1
const _DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2
const _DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE = 3
const _DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME = 4
const _DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE = 5
const _DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE = 6
const _DISPLAYCONFIG_DEVICE_INFO_GET_SUPPORT_VIRTUAL_RESOLUTION = 7
const _DISPLAYCONFIG_DEVICE_INFO_SET_SUPPORT_VIRTUAL_RESOLUTION = 8
const _DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO = 9
const _DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE = 10
const _DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL = 11
const _DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_DEVICE_INFO_HEADER = struct {
	Ftype1     TDISPLAYCONFIG_DEVICE_INFO_TYPE
	Fsize      TUINT32
	FadapterId TLUID
	Fid        TUINT32
}

type DISPLAYCONFIG_DEVICE_INFO_HEADER = TDISPLAYCONFIG_DEVICE_INFO_HEADER

type TDISPLAYCONFIG_SOURCE_DEVICE_NAME = struct {
	Fheader            TDISPLAYCONFIG_DEVICE_INFO_HEADER
	FviewGdiDeviceName [32]TWCHAR
}

type DISPLAYCONFIG_SOURCE_DEVICE_NAME = TDISPLAYCONFIG_SOURCE_DEVICE_NAME

type TDISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS = struct {
	F__ccgo0_0 struct {
		Fvalue     [0]TUINT32
		F__ccgo0_0 struct {
			F__ccgo0 uint32
		}
	}
}

type DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS = TDISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS

type TDISPLAYCONFIG_TARGET_DEVICE_NAME = struct {
	Fheader                    TDISPLAYCONFIG_DEVICE_INFO_HEADER
	Fflags                     TDISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS
	FoutputTechnology          TDISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY
	FedidManufactureId         TUINT16
	FedidProductCodeId         TUINT16
	FconnectorInstance         TUINT32
	FmonitorFriendlyDeviceName [64]TWCHAR
	FmonitorDevicePath         [128]TWCHAR
}

type DISPLAYCONFIG_TARGET_DEVICE_NAME = TDISPLAYCONFIG_TARGET_DEVICE_NAME

type TDISPLAYCONFIG_TARGET_PREFERRED_MODE = struct {
	F__ccgo_align  [0]uint32
	Fheader        TDISPLAYCONFIG_DEVICE_INFO_HEADER
	Fwidth         TUINT32
	Fheight        TUINT32
	F__ccgo_align3 [4]byte
	FtargetMode    TDISPLAYCONFIG_TARGET_MODE
}

type DISPLAYCONFIG_TARGET_PREFERRED_MODE = TDISPLAYCONFIG_TARGET_PREFERRED_MODE

type TDISPLAYCONFIG_ADAPTER_NAME = struct {
	Fheader            TDISPLAYCONFIG_DEVICE_INFO_HEADER
	FadapterDevicePath [128]TWCHAR
}

type DISPLAYCONFIG_ADAPTER_NAME = TDISPLAYCONFIG_ADAPTER_NAME

type TDISPLAYCONFIG_TARGET_BASE_TYPE = struct {
	Fheader               TDISPLAYCONFIG_DEVICE_INFO_HEADER
	FbaseOutputTechnology TDISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY
}

type DISPLAYCONFIG_TARGET_BASE_TYPE = TDISPLAYCONFIG_TARGET_BASE_TYPE

type TDISPLAYCONFIG_SET_TARGET_PERSISTENCE = struct {
	Fheader     TDISPLAYCONFIG_DEVICE_INFO_HEADER
	F__ccgo1_20 struct {
		Fvalue     [0]TUINT32
		F__ccgo0_0 struct {
			F__ccgo0 uint32
		}
	}
}

type DISPLAYCONFIG_SET_TARGET_PERSISTENCE = TDISPLAYCONFIG_SET_TARGET_PERSISTENCE

type TDISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION = struct {
	Fheader     TDISPLAYCONFIG_DEVICE_INFO_HEADER
	F__ccgo1_20 struct {
		Fvalue     [0]TUINT32
		F__ccgo0_0 struct {
			F__ccgo0 uint32
		}
	}
}

type DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION = TDISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION

type TDISPLAYCONFIG_COLOR_ENCODING = uint32

type DISPLAYCONFIG_COLOR_ENCODING = TDISPLAYCONFIG_COLOR_ENCODING

type __DISPLAYCONFIG_COLOR_ENCODING = uint32

const _DISPLAYCONFIG_COLOR_ENCODING_RGB = 0
const _DISPLAYCONFIG_COLOR_ENCODING_YCBCR444 = 1
const _DISPLAYCONFIG_COLOR_ENCODING_YCBCR422 = 2
const _DISPLAYCONFIG_COLOR_ENCODING_YCBCR420 = 3
const _DISPLAYCONFIG_COLOR_ENCODING_INTENSITY = 4
const _DISPLAYCONFIG_COLOR_ENCODING_FORCE_UINT32 = 4294967295

type TDISPLAYCONFIG_GET_ADVANCED_COLOR_INFO = struct {
	Fheader     TDISPLAYCONFIG_DEVICE_INFO_HEADER
	F__ccgo1_20 struct {
		Fvalue     [0]TUINT32
		F__ccgo0_0 struct {
			F__ccgo0 uint32
		}
	}
	FcolorEncoding       TDISPLAYCONFIG_COLOR_ENCODING
	FbitsPerColorChannel TUINT32
}

type DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO = TDISPLAYCONFIG_GET_ADVANCED_COLOR_INFO

type T_DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO = TDISPLAYCONFIG_GET_ADVANCED_COLOR_INFO

type _DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO = T_DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO

type TDISPLAYCONFIG_SET_ADVANCED_COLOR_STATE = struct {
	Fheader     TDISPLAYCONFIG_DEVICE_INFO_HEADER
	F__ccgo1_20 struct {
		Fvalue     [0]TUINT32
		F__ccgo0_0 struct {
			F__ccgo0 uint32
		}
	}
}

type DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE = TDISPLAYCONFIG_SET_ADVANCED_COLOR_STATE

type T_DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE = TDISPLAYCONFIG_SET_ADVANCED_COLOR_STATE

type _DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE = T_DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE

type TDISPLAYCONFIG_SDR_WHITE_LEVEL = struct {
	Fheader        TDISPLAYCONFIG_DEVICE_INFO_HEADER
	FSDRWhiteLevel TULONG
}

type DISPLAYCONFIG_SDR_WHITE_LEVEL = TDISPLAYCONFIG_SDR_WHITE_LEVEL

type T_DISPLAYCONFIG_SDR_WHITE_LEVEL = TDISPLAYCONFIG_SDR_WHITE_LEVEL

type _DISPLAYCONFIG_SDR_WHITE_LEVEL = T_DISPLAYCONFIG_SDR_WHITE_LEVEL

type TRGNDATAHEADER = struct {
	FdwSize   TDWORD
	FiType    TDWORD
	FnCount   TDWORD
	FnRgnSize TDWORD
	FrcBound  TRECT
}

type RGNDATAHEADER = TRGNDATAHEADER

type T_RGNDATAHEADER = TRGNDATAHEADER

type _RGNDATAHEADER = T_RGNDATAHEADER

type TPRGNDATAHEADER = uintptr

type PRGNDATAHEADER = TPRGNDATAHEADER

type TRGNDATA = struct {
	Frdh    TRGNDATAHEADER
	FBuffer [1]int8
}

type RGNDATA = TRGNDATA

type T_RGNDATA = TRGNDATA

type _RGNDATA = T_RGNDATA

type TPRGNDATA = uintptr

type PRGNDATA = TPRGNDATA

type TNPRGNDATA = uintptr

type NPRGNDATA = TNPRGNDATA

type TLPRGNDATA = uintptr

type LPRGNDATA = TLPRGNDATA

type TABC = struct {
	FabcA int32
	FabcB TUINT
	FabcC int32
}

type ABC = TABC

type T_ABC = TABC

type _ABC = T_ABC

type TPABC = uintptr

type PABC = TPABC

type TNPABC = uintptr

type NPABC = TNPABC

type TLPABC = uintptr

type LPABC = TLPABC

type TABCFLOAT = struct {
	FabcfA TFLOAT
	FabcfB TFLOAT
	FabcfC TFLOAT
}

type ABCFLOAT = TABCFLOAT

type T_ABCFLOAT = TABCFLOAT

type _ABCFLOAT = T_ABCFLOAT

type TPABCFLOAT = uintptr

type PABCFLOAT = TPABCFLOAT

type TNPABCFLOAT = uintptr

type NPABCFLOAT = TNPABCFLOAT

type TLPABCFLOAT = uintptr

type LPABCFLOAT = TLPABCFLOAT

type TOUTLINETEXTMETRICA = struct {
	FotmSize                TUINT
	FotmTextMetrics         TTEXTMETRICA
	FotmFiller              TBYTE
	FotmPanoseNumber        TPANOSE
	FotmfsSelection         TUINT
	FotmfsType              TUINT
	FotmsCharSlopeRise      int32
	FotmsCharSlopeRun       int32
	FotmItalicAngle         int32
	FotmEMSquare            TUINT
	FotmAscent              int32
	FotmDescent             int32
	FotmLineGap             TUINT
	FotmsCapEmHeight        TUINT
	FotmsXHeight            TUINT
	FotmrcFontBox           TRECT
	FotmMacAscent           int32
	FotmMacDescent          int32
	FotmMacLineGap          TUINT
	FotmusMinimumPPEM       TUINT
	FotmptSubscriptSize     TPOINT
	FotmptSubscriptOffset   TPOINT
	FotmptSuperscriptSize   TPOINT
	FotmptSuperscriptOffset TPOINT
	FotmsStrikeoutSize      TUINT
	FotmsStrikeoutPosition  int32
	FotmsUnderscoreSize     int32
	FotmsUnderscorePosition int32
	FotmpFamilyName         TPSTR
	FotmpFaceName           TPSTR
	FotmpStyleName          TPSTR
	FotmpFullName           TPSTR
}

type OUTLINETEXTMETRICA = TOUTLINETEXTMETRICA

type T_OUTLINETEXTMETRICA = TOUTLINETEXTMETRICA

type _OUTLINETEXTMETRICA = T_OUTLINETEXTMETRICA

type TPOUTLINETEXTMETRICA = uintptr

type POUTLINETEXTMETRICA = TPOUTLINETEXTMETRICA

type TNPOUTLINETEXTMETRICA = uintptr

type NPOUTLINETEXTMETRICA = TNPOUTLINETEXTMETRICA

type TLPOUTLINETEXTMETRICA = uintptr

type LPOUTLINETEXTMETRICA = TLPOUTLINETEXTMETRICA

type TOUTLINETEXTMETRICW = struct {
	FotmSize                TUINT
	FotmTextMetrics         TTEXTMETRICW
	FotmFiller              TBYTE
	FotmPanoseNumber        TPANOSE
	FotmfsSelection         TUINT
	FotmfsType              TUINT
	FotmsCharSlopeRise      int32
	FotmsCharSlopeRun       int32
	FotmItalicAngle         int32
	FotmEMSquare            TUINT
	FotmAscent              int32
	FotmDescent             int32
	FotmLineGap             TUINT
	FotmsCapEmHeight        TUINT
	FotmsXHeight            TUINT
	FotmrcFontBox           TRECT
	FotmMacAscent           int32
	FotmMacDescent          int32
	FotmMacLineGap          TUINT
	FotmusMinimumPPEM       TUINT
	FotmptSubscriptSize     TPOINT
	FotmptSubscriptOffset   TPOINT
	FotmptSuperscriptSize   TPOINT
	FotmptSuperscriptOffset TPOINT
	FotmsStrikeoutSize      TUINT
	FotmsStrikeoutPosition  int32
	FotmsUnderscoreSize     int32
	FotmsUnderscorePosition int32
	FotmpFamilyName         TPSTR
	FotmpFaceName           TPSTR
	FotmpStyleName          TPSTR
	FotmpFullName           TPSTR
}

type OUTLINETEXTMETRICW = TOUTLINETEXTMETRICW

type T_OUTLINETEXTMETRICW = TOUTLINETEXTMETRICW

type _OUTLINETEXTMETRICW = T_OUTLINETEXTMETRICW

type TPOUTLINETEXTMETRICW = uintptr

type POUTLINETEXTMETRICW = TPOUTLINETEXTMETRICW

type TNPOUTLINETEXTMETRICW = uintptr

type NPOUTLINETEXTMETRICW = TNPOUTLINETEXTMETRICW

type TLPOUTLINETEXTMETRICW = uintptr

type LPOUTLINETEXTMETRICW = TLPOUTLINETEXTMETRICW

type TOUTLINETEXTMETRIC = struct {
	FotmSize                TUINT
	FotmTextMetrics         TTEXTMETRICA
	FotmFiller              TBYTE
	FotmPanoseNumber        TPANOSE
	FotmfsSelection         TUINT
	FotmfsType              TUINT
	FotmsCharSlopeRise      int32
	FotmsCharSlopeRun       int32
	FotmItalicAngle         int32
	FotmEMSquare            TUINT
	FotmAscent              int32
	FotmDescent             int32
	FotmLineGap             TUINT
	FotmsCapEmHeight        TUINT
	FotmsXHeight            TUINT
	FotmrcFontBox           TRECT
	FotmMacAscent           int32
	FotmMacDescent          int32
	FotmMacLineGap          TUINT
	FotmusMinimumPPEM       TUINT
	FotmptSubscriptSize     TPOINT
	FotmptSubscriptOffset   TPOINT
	FotmptSuperscriptSize   TPOINT
	FotmptSuperscriptOffset TPOINT
	FotmsStrikeoutSize      TUINT
	FotmsStrikeoutPosition  int32
	FotmsUnderscoreSize     int32
	FotmsUnderscorePosition int32
	FotmpFamilyName         TPSTR
	FotmpFaceName           TPSTR
	FotmpStyleName          TPSTR
	FotmpFullName           TPSTR
}

type OUTLINETEXTMETRIC = TOUTLINETEXTMETRIC

type TPOUTLINETEXTMETRIC = uintptr

type POUTLINETEXTMETRIC = TPOUTLINETEXTMETRIC

type TNPOUTLINETEXTMETRIC = uintptr

type NPOUTLINETEXTMETRIC = TNPOUTLINETEXTMETRIC

type TLPOUTLINETEXTMETRIC = uintptr

type LPOUTLINETEXTMETRIC = TLPOUTLINETEXTMETRIC

type TPOLYTEXTA = struct {
	Fx       int32
	Fy       int32
	Fn       TUINT
	Flpstr   TLPCSTR
	FuiFlags TUINT
	Frcl     TRECT
	Fpdx     uintptr
}

type POLYTEXTA = TPOLYTEXTA

type TtagPOLYTEXTA = TPOLYTEXTA

type tagPOLYTEXTA = TtagPOLYTEXTA

type TPPOLYTEXTA = uintptr

type PPOLYTEXTA = TPPOLYTEXTA

type TNPPOLYTEXTA = uintptr

type NPPOLYTEXTA = TNPPOLYTEXTA

type TLPPOLYTEXTA = uintptr

type LPPOLYTEXTA = TLPPOLYTEXTA

type TPOLYTEXTW = struct {
	Fx       int32
	Fy       int32
	Fn       TUINT
	Flpstr   TLPCWSTR
	FuiFlags TUINT
	Frcl     TRECT
	Fpdx     uintptr
}

type POLYTEXTW = TPOLYTEXTW

type TtagPOLYTEXTW = TPOLYTEXTW

type tagPOLYTEXTW = TtagPOLYTEXTW

type TPPOLYTEXTW = uintptr

type PPOLYTEXTW = TPPOLYTEXTW

type TNPPOLYTEXTW = uintptr

type NPPOLYTEXTW = TNPPOLYTEXTW

type TLPPOLYTEXTW = uintptr

type LPPOLYTEXTW = TLPPOLYTEXTW

type TPOLYTEXT = struct {
	Fx       int32
	Fy       int32
	Fn       TUINT
	Flpstr   TLPCSTR
	FuiFlags TUINT
	Frcl     TRECT
	Fpdx     uintptr
}

type POLYTEXT = TPOLYTEXT

type TPPOLYTEXT = uintptr

type PPOLYTEXT = TPPOLYTEXT

type TNPPOLYTEXT = uintptr

type NPPOLYTEXT = TNPPOLYTEXT

type TLPPOLYTEXT = uintptr

type LPPOLYTEXT = TLPPOLYTEXT

type TFIXED = struct {
	Ffract TWORD
	Fvalue int16
}

type FIXED = TFIXED

type T_FIXED = TFIXED

type _FIXED = T_FIXED

type TMAT2 = struct {
	FeM11 TFIXED
	FeM12 TFIXED
	FeM21 TFIXED
	FeM22 TFIXED
}

type MAT2 = TMAT2

type T_MAT2 = TMAT2

type _MAT2 = T_MAT2

type TLPMAT2 = uintptr

type LPMAT2 = TLPMAT2

type TGLYPHMETRICS = struct {
	FgmBlackBoxX     TUINT
	FgmBlackBoxY     TUINT
	FgmptGlyphOrigin TPOINT
	FgmCellIncX      int16
	FgmCellIncY      int16
}

type GLYPHMETRICS = TGLYPHMETRICS

type T_GLYPHMETRICS = TGLYPHMETRICS

type _GLYPHMETRICS = T_GLYPHMETRICS

type TLPGLYPHMETRICS = uintptr

type LPGLYPHMETRICS = TLPGLYPHMETRICS

type TPOINTFX = struct {
	Fx TFIXED
	Fy TFIXED
}

type POINTFX = TPOINTFX

type TtagPOINTFX = TPOINTFX

type tagPOINTFX = TtagPOINTFX

type TLPPOINTFX = uintptr

type LPPOINTFX = TLPPOINTFX

type TTTPOLYCURVE = struct {
	FwType TWORD
	Fcpfx  TWORD
	Fapfx  [1]TPOINTFX
}

type TTPOLYCURVE = TTTPOLYCURVE

type TtagTTPOLYCURVE = TTTPOLYCURVE

type tagTTPOLYCURVE = TtagTTPOLYCURVE

type TLPTTPOLYCURVE = uintptr

type LPTTPOLYCURVE = TLPTTPOLYCURVE

type TTTPOLYGONHEADER = struct {
	Fcb       TDWORD
	FdwType   TDWORD
	FpfxStart TPOINTFX
}

type TTPOLYGONHEADER = TTTPOLYGONHEADER

type TtagTTPOLYGONHEADER = TTTPOLYGONHEADER

type tagTTPOLYGONHEADER = TtagTTPOLYGONHEADER

type TLPTTPOLYGONHEADER = uintptr

type LPTTPOLYGONHEADER = TLPTTPOLYGONHEADER

type TGCP_RESULTSA = struct {
	FlStructSize TDWORD
	FlpOutString TLPSTR
	FlpOrder     uintptr
	FlpDx        uintptr
	FlpCaretPos  uintptr
	FlpClass     TLPSTR
	FlpGlyphs    TLPWSTR
	FnGlyphs     TUINT
	FnMaxFit     int32
}

type GCP_RESULTSA = TGCP_RESULTSA

type TtagGCP_RESULTSA = TGCP_RESULTSA

type tagGCP_RESULTSA = TtagGCP_RESULTSA

type TLPGCP_RESULTSA = uintptr

type LPGCP_RESULTSA = TLPGCP_RESULTSA

type TGCP_RESULTSW = struct {
	FlStructSize TDWORD
	FlpOutString TLPWSTR
	FlpOrder     uintptr
	FlpDx        uintptr
	FlpCaretPos  uintptr
	FlpClass     TLPSTR
	FlpGlyphs    TLPWSTR
	FnGlyphs     TUINT
	FnMaxFit     int32
}

type GCP_RESULTSW = TGCP_RESULTSW

type TtagGCP_RESULTSW = TGCP_RESULTSW

type tagGCP_RESULTSW = TtagGCP_RESULTSW

type TLPGCP_RESULTSW = uintptr

type LPGCP_RESULTSW = TLPGCP_RESULTSW

type TGCP_RESULTS = struct {
	FlStructSize TDWORD
	FlpOutString TLPSTR
	FlpOrder     uintptr
	FlpDx        uintptr
	FlpCaretPos  uintptr
	FlpClass     TLPSTR
	FlpGlyphs    TLPWSTR
	FnGlyphs     TUINT
	FnMaxFit     int32
}

type GCP_RESULTS = TGCP_RESULTS

type TLPGCP_RESULTS = uintptr

type LPGCP_RESULTS = TLPGCP_RESULTS

type TRASTERIZER_STATUS = struct {
	FnSize       int16
	FwFlags      int16
	FnLanguageID int16
}

type RASTERIZER_STATUS = TRASTERIZER_STATUS

type T_RASTERIZER_STATUS = TRASTERIZER_STATUS

type _RASTERIZER_STATUS = T_RASTERIZER_STATUS

type TLPRASTERIZER_STATUS = uintptr

type LPRASTERIZER_STATUS = TLPRASTERIZER_STATUS

type TPIXELFORMATDESCRIPTOR = struct {
	FnSize           TWORD
	FnVersion        TWORD
	FdwFlags         TDWORD
	FiPixelType      TBYTE
	FcColorBits      TBYTE
	FcRedBits        TBYTE
	FcRedShift       TBYTE
	FcGreenBits      TBYTE
	FcGreenShift     TBYTE
	FcBlueBits       TBYTE
	FcBlueShift      TBYTE
	FcAlphaBits      TBYTE
	FcAlphaShift     TBYTE
	FcAccumBits      TBYTE
	FcAccumRedBits   TBYTE
	FcAccumGreenBits TBYTE
	FcAccumBlueBits  TBYTE
	FcAccumAlphaBits TBYTE
	FcDepthBits      TBYTE
	FcStencilBits    TBYTE
	FcAuxBuffers     TBYTE
	FiLayerType      TBYTE
	FbReserved       TBYTE
	FdwLayerMask     TDWORD
	FdwVisibleMask   TDWORD
	FdwDamageMask    TDWORD
}

type PIXELFORMATDESCRIPTOR = TPIXELFORMATDESCRIPTOR

type TtagPIXELFORMATDESCRIPTOR = TPIXELFORMATDESCRIPTOR

type tagPIXELFORMATDESCRIPTOR = TtagPIXELFORMATDESCRIPTOR

type TPPIXELFORMATDESCRIPTOR = uintptr

type PPIXELFORMATDESCRIPTOR = TPPIXELFORMATDESCRIPTOR

type TLPPIXELFORMATDESCRIPTOR = uintptr

type LPPIXELFORMATDESCRIPTOR = TLPPIXELFORMATDESCRIPTOR

type TOLDFONTENUMPROCA = uintptr

type OLDFONTENUMPROCA = TOLDFONTENUMPROCA

type TOLDFONTENUMPROCW = uintptr

type OLDFONTENUMPROCW = TOLDFONTENUMPROCW

type TFONTENUMPROCA = uintptr

type FONTENUMPROCA = TFONTENUMPROCA

type TFONTENUMPROCW = uintptr

type FONTENUMPROCW = TFONTENUMPROCW

type TFONTENUMPROC = uintptr

type FONTENUMPROC = TFONTENUMPROC

type TGOBJENUMPROC = uintptr

type GOBJENUMPROC = TGOBJENUMPROC

type TLINEDDAPROC = uintptr

type LINEDDAPROC = TLINEDDAPROC

type TLPFNDEVMODE = uintptr

type LPFNDEVMODE = TLPFNDEVMODE

type TLPFNDEVCAPS = uintptr

type LPFNDEVCAPS = TLPFNDEVCAPS

type TWCRANGE = struct {
	FwcLow   TWCHAR
	FcGlyphs TUSHORT
}

type WCRANGE = TWCRANGE

type TtagWCRANGE = TWCRANGE

type tagWCRANGE = TtagWCRANGE

type TPWCRANGE = uintptr

type PWCRANGE = TPWCRANGE

type TLPWCRANGE = uintptr

type LPWCRANGE = TLPWCRANGE

type TGLYPHSET = struct {
	FcbThis           TDWORD
	FflAccel          TDWORD
	FcGlyphsSupported TDWORD
	FcRanges          TDWORD
	Franges           [1]TWCRANGE
}

type GLYPHSET = TGLYPHSET

type TtagGLYPHSET = TGLYPHSET

type tagGLYPHSET = TtagGLYPHSET

type TPGLYPHSET = uintptr

type PGLYPHSET = TPGLYPHSET

type TLPGLYPHSET = uintptr

type LPGLYPHSET = TLPGLYPHSET

type TDESIGNVECTOR = struct {
	FdvReserved TDWORD
	FdvNumAxes  TDWORD
	FdvValues   [16]TLONG
}

type DESIGNVECTOR = TDESIGNVECTOR

type TtagDESIGNVECTOR = TDESIGNVECTOR

type tagDESIGNVECTOR = TtagDESIGNVECTOR

type TPDESIGNVECTOR = uintptr

type PDESIGNVECTOR = TPDESIGNVECTOR

type TLPDESIGNVECTOR = uintptr

type LPDESIGNVECTOR = TLPDESIGNVECTOR

type TAXISINFOA = struct {
	FaxMinValue TLONG
	FaxMaxValue TLONG
	FaxAxisName [16]TBYTE
}

type AXISINFOA = TAXISINFOA

type TtagAXISINFOA = TAXISINFOA

type tagAXISINFOA = TtagAXISINFOA

type TPAXISINFOA = uintptr

type PAXISINFOA = TPAXISINFOA

type TLPAXISINFOA = uintptr

type LPAXISINFOA = TLPAXISINFOA

type TAXISINFOW = struct {
	FaxMinValue TLONG
	FaxMaxValue TLONG
	FaxAxisName [16]TWCHAR
}

type AXISINFOW = TAXISINFOW

type TtagAXISINFOW = TAXISINFOW

type tagAXISINFOW = TtagAXISINFOW

type TPAXISINFOW = uintptr

type PAXISINFOW = TPAXISINFOW

type TLPAXISINFOW = uintptr

type LPAXISINFOW = TLPAXISINFOW

type TAXISINFO = struct {
	FaxMinValue TLONG
	FaxMaxValue TLONG
	FaxAxisName [16]TBYTE
}

type AXISINFO = TAXISINFO

type TPAXISINFO = uintptr

type PAXISINFO = TPAXISINFO

type TLPAXISINFO = uintptr

type LPAXISINFO = TLPAXISINFO

type TAXESLISTA = struct {
	FaxlReserved TDWORD
	FaxlNumAxes  TDWORD
	FaxlAxisInfo [16]TAXISINFOA
}

type AXESLISTA = TAXESLISTA

type TtagAXESLISTA = TAXESLISTA

type tagAXESLISTA = TtagAXESLISTA

type TPAXESLISTA = uintptr

type PAXESLISTA = TPAXESLISTA

type TLPAXESLISTA = uintptr

type LPAXESLISTA = TLPAXESLISTA

type TAXESLISTW = struct {
	FaxlReserved TDWORD
	FaxlNumAxes  TDWORD
	FaxlAxisInfo [16]TAXISINFOW
}

type AXESLISTW = TAXESLISTW

type TtagAXESLISTW = TAXESLISTW

type tagAXESLISTW = TtagAXESLISTW

type TPAXESLISTW = uintptr

type PAXESLISTW = TPAXESLISTW

type TLPAXESLISTW = uintptr

type LPAXESLISTW = TLPAXESLISTW

type TAXESLIST = struct {
	FaxlReserved TDWORD
	FaxlNumAxes  TDWORD
	FaxlAxisInfo [16]TAXISINFOA
}

type AXESLIST = TAXESLIST

type TPAXESLIST = uintptr

type PAXESLIST = TPAXESLIST

type TLPAXESLIST = uintptr

type LPAXESLIST = TLPAXESLIST

type TENUMLOGFONTEXDVA = struct {
	FelfEnumLogfontEx TENUMLOGFONTEXA
	FelfDesignVector  TDESIGNVECTOR
}

type ENUMLOGFONTEXDVA = TENUMLOGFONTEXDVA

type TtagENUMLOGFONTEXDVA = TENUMLOGFONTEXDVA

type tagENUMLOGFONTEXDVA = TtagENUMLOGFONTEXDVA

type TPENUMLOGFONTEXDVA = uintptr

type PENUMLOGFONTEXDVA = TPENUMLOGFONTEXDVA

type TLPENUMLOGFONTEXDVA = uintptr

type LPENUMLOGFONTEXDVA = TLPENUMLOGFONTEXDVA

type TENUMLOGFONTEXDVW = struct {
	FelfEnumLogfontEx TENUMLOGFONTEXW
	FelfDesignVector  TDESIGNVECTOR
}

type ENUMLOGFONTEXDVW = TENUMLOGFONTEXDVW

type TtagENUMLOGFONTEXDVW = TENUMLOGFONTEXDVW

type tagENUMLOGFONTEXDVW = TtagENUMLOGFONTEXDVW

type TPENUMLOGFONTEXDVW = uintptr

type PENUMLOGFONTEXDVW = TPENUMLOGFONTEXDVW

type TLPENUMLOGFONTEXDVW = uintptr

type LPENUMLOGFONTEXDVW = TLPENUMLOGFONTEXDVW

type TENUMLOGFONTEXDV = struct {
	FelfEnumLogfontEx TENUMLOGFONTEXA
	FelfDesignVector  TDESIGNVECTOR
}

type ENUMLOGFONTEXDV = TENUMLOGFONTEXDV

type TPENUMLOGFONTEXDV = uintptr

type PENUMLOGFONTEXDV = TPENUMLOGFONTEXDV

type TLPENUMLOGFONTEXDV = uintptr

type LPENUMLOGFONTEXDV = TLPENUMLOGFONTEXDV

type TENUMTEXTMETRICA = struct {
	FetmNewTextMetricEx TNEWTEXTMETRICEXA
	FetmAxesList        TAXESLISTA
}

type ENUMTEXTMETRICA = TENUMTEXTMETRICA

type TtagENUMTEXTMETRICA = TENUMTEXTMETRICA

type tagENUMTEXTMETRICA = TtagENUMTEXTMETRICA

type TPENUMTEXTMETRICA = uintptr

type PENUMTEXTMETRICA = TPENUMTEXTMETRICA

type TLPENUMTEXTMETRICA = uintptr

type LPENUMTEXTMETRICA = TLPENUMTEXTMETRICA

type TENUMTEXTMETRICW = struct {
	FetmNewTextMetricEx TNEWTEXTMETRICEXW
	FetmAxesList        TAXESLISTW
}

type ENUMTEXTMETRICW = TENUMTEXTMETRICW

type TtagENUMTEXTMETRICW = TENUMTEXTMETRICW

type tagENUMTEXTMETRICW = TtagENUMTEXTMETRICW

type TPENUMTEXTMETRICW = uintptr

type PENUMTEXTMETRICW = TPENUMTEXTMETRICW

type TLPENUMTEXTMETRICW = uintptr

type LPENUMTEXTMETRICW = TLPENUMTEXTMETRICW

type TENUMTEXTMETRIC = struct {
	FetmNewTextMetricEx TNEWTEXTMETRICEXA
	FetmAxesList        TAXESLISTA
}

type ENUMTEXTMETRIC = TENUMTEXTMETRIC

type TPENUMTEXTMETRIC = uintptr

type PENUMTEXTMETRIC = TPENUMTEXTMETRIC

type TLPENUMTEXTMETRIC = uintptr

type LPENUMTEXTMETRIC = TLPENUMTEXTMETRIC

type TCOLOR16 = uint16

type COLOR16 = TCOLOR16

type TTRIVERTEX = struct {
	Fx     TLONG
	Fy     TLONG
	FRed   TCOLOR16
	FGreen TCOLOR16
	FBlue  TCOLOR16
	FAlpha TCOLOR16
}

type TRIVERTEX = TTRIVERTEX

type T_TRIVERTEX = TTRIVERTEX

type _TRIVERTEX = T_TRIVERTEX

type TPTRIVERTEX = uintptr

type PTRIVERTEX = TPTRIVERTEX

type TLPTRIVERTEX = uintptr

type LPTRIVERTEX = TLPTRIVERTEX

type TGRADIENT_TRIANGLE = struct {
	FVertex1 TULONG
	FVertex2 TULONG
	FVertex3 TULONG
}

type GRADIENT_TRIANGLE = TGRADIENT_TRIANGLE

type T_GRADIENT_TRIANGLE = TGRADIENT_TRIANGLE

type _GRADIENT_TRIANGLE = T_GRADIENT_TRIANGLE

type TPGRADIENT_TRIANGLE = uintptr

type PGRADIENT_TRIANGLE = TPGRADIENT_TRIANGLE

type TLPGRADIENT_TRIANGLE = uintptr

type LPGRADIENT_TRIANGLE = TLPGRADIENT_TRIANGLE

type TGRADIENT_RECT = struct {
	FUpperLeft  TULONG
	FLowerRight TULONG
}

type GRADIENT_RECT = TGRADIENT_RECT

type T_GRADIENT_RECT = TGRADIENT_RECT

type _GRADIENT_RECT = T_GRADIENT_RECT

type TPGRADIENT_RECT = uintptr

type PGRADIENT_RECT = TPGRADIENT_RECT

type TLPGRADIENT_RECT = uintptr

type LPGRADIENT_RECT = TLPGRADIENT_RECT

type TBLENDFUNCTION = struct {
	FBlendOp             TBYTE
	FBlendFlags          TBYTE
	FSourceConstantAlpha TBYTE
	FAlphaFormat         TBYTE
}

type BLENDFUNCTION = TBLENDFUNCTION

type T_BLENDFUNCTION = TBLENDFUNCTION

type _BLENDFUNCTION = T_BLENDFUNCTION

type TPBLENDFUNCTION = uintptr

type PBLENDFUNCTION = TPBLENDFUNCTION

type TMFENUMPROC = uintptr

type MFENUMPROC = TMFENUMPROC

type TENHMFENUMPROC = uintptr

type ENHMFENUMPROC = TENHMFENUMPROC

type TDIBSECTION = struct {
	FdsBm        TBITMAP
	FdsBmih      TBITMAPINFOHEADER
	FdsBitfields [3]TDWORD
	FdshSection  THANDLE
	FdsOffset    TDWORD
}

type DIBSECTION = TDIBSECTION

type TtagDIBSECTION = TDIBSECTION

type tagDIBSECTION = TtagDIBSECTION

type TLPDIBSECTION = uintptr

type LPDIBSECTION = TLPDIBSECTION

type TPDIBSECTION = uintptr

type PDIBSECTION = TPDIBSECTION

type TCOLORADJUSTMENT = struct {
	FcaSize            TWORD
	FcaFlags           TWORD
	FcaIlluminantIndex TWORD
	FcaRedGamma        TWORD
	FcaGreenGamma      TWORD
	FcaBlueGamma       TWORD
	FcaReferenceBlack  TWORD
	FcaReferenceWhite  TWORD
	FcaContrast        TSHORT
	FcaBrightness      TSHORT
	FcaColorfulness    TSHORT
	FcaRedGreenTint    TSHORT
}

type COLORADJUSTMENT = TCOLORADJUSTMENT

type TtagCOLORADJUSTMENT = TCOLORADJUSTMENT

type tagCOLORADJUSTMENT = TtagCOLORADJUSTMENT

type TPCOLORADJUSTMENT = uintptr

type PCOLORADJUSTMENT = TPCOLORADJUSTMENT

type TLPCOLORADJUSTMENT = uintptr

type LPCOLORADJUSTMENT = TLPCOLORADJUSTMENT

type TABORTPROC = uintptr

type ABORTPROC = TABORTPROC

type TDOCINFOA = struct {
	FcbSize       int32
	FlpszDocName  TLPCSTR
	FlpszOutput   TLPCSTR
	FlpszDatatype TLPCSTR
	FfwType       TDWORD
}

type DOCINFOA = TDOCINFOA

type T_DOCINFOA = TDOCINFOA

type _DOCINFOA = T_DOCINFOA

type TLPDOCINFOA = uintptr

type LPDOCINFOA = TLPDOCINFOA

type TDOCINFOW = struct {
	FcbSize       int32
	FlpszDocName  TLPCWSTR
	FlpszOutput   TLPCWSTR
	FlpszDatatype TLPCWSTR
	FfwType       TDWORD
}

type DOCINFOW = TDOCINFOW

type T_DOCINFOW = TDOCINFOW

type _DOCINFOW = T_DOCINFOW

type TLPDOCINFOW = uintptr

type LPDOCINFOW = TLPDOCINFOW

type TDOCINFO = struct {
	FcbSize       int32
	FlpszDocName  TLPCSTR
	FlpszOutput   TLPCSTR
	FlpszDatatype TLPCSTR
	FfwType       TDWORD
}

type DOCINFO = TDOCINFO

type TLPDOCINFO = uintptr

type LPDOCINFO = TLPDOCINFO

type TKERNINGPAIR = struct {
	FwFirst      TWORD
	FwSecond     TWORD
	FiKernAmount int32
}

type KERNINGPAIR = TKERNINGPAIR

type TtagKERNINGPAIR = TKERNINGPAIR

type tagKERNINGPAIR = TtagKERNINGPAIR

type TLPKERNINGPAIR = uintptr

type LPKERNINGPAIR = TLPKERNINGPAIR

type TICMENUMPROCA = uintptr

type ICMENUMPROCA = TICMENUMPROCA

type TICMENUMPROCW = uintptr

type ICMENUMPROCW = TICMENUMPROCW

type TEMR = struct {
	FiType TDWORD
	FnSize TDWORD
}

type EMR = TEMR

type TtagEMR = TEMR

type tagEMR = TtagEMR

type TPEMR = uintptr

type PEMR = TPEMR

type TEMRTEXT = struct {
	FptlReference TPOINTL
	FnChars       TDWORD
	FoffString    TDWORD
	FfOptions     TDWORD
	Frcl          TRECTL
	FoffDx        TDWORD
}

type EMRTEXT = TEMRTEXT

type TtagEMRTEXT = TEMRTEXT

type tagEMRTEXT = TtagEMRTEXT

type TPEMRTEXT = uintptr

type PEMRTEXT = TPEMRTEXT

type TEMRABORTPATH = struct {
	Femr TEMR
}

type EMRABORTPATH = TEMRABORTPATH

type TtagABORTPATH = TEMRABORTPATH

type tagABORTPATH = TtagABORTPATH

type TPEMRABORTPATH = uintptr

type PEMRABORTPATH = TPEMRABORTPATH

type TEMRBEGINPATH = struct {
	Femr TEMR
}

type EMRBEGINPATH = TEMRBEGINPATH

type TPEMRBEGINPATH = uintptr

type PEMRBEGINPATH = TPEMRBEGINPATH

type TEMRENDPATH = struct {
	Femr TEMR
}

type EMRENDPATH = TEMRENDPATH

type TPEMRENDPATH = uintptr

type PEMRENDPATH = TPEMRENDPATH

type TEMRCLOSEFIGURE = struct {
	Femr TEMR
}

type EMRCLOSEFIGURE = TEMRCLOSEFIGURE

type TPEMRCLOSEFIGURE = uintptr

type PEMRCLOSEFIGURE = TPEMRCLOSEFIGURE

type TEMRFLATTENPATH = struct {
	Femr TEMR
}

type EMRFLATTENPATH = TEMRFLATTENPATH

type TPEMRFLATTENPATH = uintptr

type PEMRFLATTENPATH = TPEMRFLATTENPATH

type TEMRWIDENPATH = struct {
	Femr TEMR
}

type EMRWIDENPATH = TEMRWIDENPATH

type TPEMRWIDENPATH = uintptr

type PEMRWIDENPATH = TPEMRWIDENPATH

type TEMRSETMETARGN = struct {
	Femr TEMR
}

type EMRSETMETARGN = TEMRSETMETARGN

type TPEMRSETMETARGN = uintptr

type PEMRSETMETARGN = TPEMRSETMETARGN

type TEMRSAVEDC = struct {
	Femr TEMR
}

type EMRSAVEDC = TEMRSAVEDC

type TPEMRSAVEDC = uintptr

type PEMRSAVEDC = TPEMRSAVEDC

type TEMRREALIZEPALETTE = struct {
	Femr TEMR
}

type EMRREALIZEPALETTE = TEMRREALIZEPALETTE

type TPEMRREALIZEPALETTE = uintptr

type PEMRREALIZEPALETTE = TPEMRREALIZEPALETTE

type TEMRSELECTCLIPPATH = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSELECTCLIPPATH = TEMRSELECTCLIPPATH

type TtagEMRSELECTCLIPPATH = TEMRSELECTCLIPPATH

type tagEMRSELECTCLIPPATH = TtagEMRSELECTCLIPPATH

type TPEMRSELECTCLIPPATH = uintptr

type PEMRSELECTCLIPPATH = TPEMRSELECTCLIPPATH

type TEMRSETBKMODE = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETBKMODE = TEMRSETBKMODE

type TPEMRSETBKMODE = uintptr

type PEMRSETBKMODE = TPEMRSETBKMODE

type TEMRSETMAPMODE = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETMAPMODE = TEMRSETMAPMODE

type TPEMRSETMAPMODE = uintptr

type PEMRSETMAPMODE = TPEMRSETMAPMODE

type TEMRSETLAYOUT = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETLAYOUT = TEMRSETLAYOUT

type TPEMRSETLAYOUT = uintptr

type PEMRSETLAYOUT = TPEMRSETLAYOUT

type TEMRSETPOLYFILLMODE = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETPOLYFILLMODE = TEMRSETPOLYFILLMODE

type TPEMRSETPOLYFILLMODE = uintptr

type PEMRSETPOLYFILLMODE = TPEMRSETPOLYFILLMODE

type TEMRSETROP2 = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETROP2 = TEMRSETROP2

type TPEMRSETROP2 = uintptr

type PEMRSETROP2 = TPEMRSETROP2

type TEMRSETSTRETCHBLTMODE = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETSTRETCHBLTMODE = TEMRSETSTRETCHBLTMODE

type TPEMRSETSTRETCHBLTMODE = uintptr

type PEMRSETSTRETCHBLTMODE = TPEMRSETSTRETCHBLTMODE

type TEMRSETICMMODE = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETICMMODE = TEMRSETICMMODE

type TPEMRSETICMMODE = uintptr

type PEMRSETICMMODE = TPEMRSETICMMODE

type TEMRSETTEXTALIGN = struct {
	Femr   TEMR
	FiMode TDWORD
}

type EMRSETTEXTALIGN = TEMRSETTEXTALIGN

type TPEMRSETTEXTALIGN = uintptr

type PEMRSETTEXTALIGN = TPEMRSETTEXTALIGN

type TEMRSETMITERLIMIT = struct {
	Femr         TEMR
	FeMiterLimit TFLOAT
}

type EMRSETMITERLIMIT = TEMRSETMITERLIMIT

type TtagEMRSETMITERLIMIT = TEMRSETMITERLIMIT

type tagEMRSETMITERLIMIT = TtagEMRSETMITERLIMIT

type TPEMRSETMITERLIMIT = uintptr

type PEMRSETMITERLIMIT = TPEMRSETMITERLIMIT

type TEMRRESTOREDC = struct {
	Femr       TEMR
	FiRelative TLONG
}

type EMRRESTOREDC = TEMRRESTOREDC

type TtagEMRRESTOREDC = TEMRRESTOREDC

type tagEMRRESTOREDC = TtagEMRRESTOREDC

type TPEMRRESTOREDC = uintptr

type PEMRRESTOREDC = TPEMRRESTOREDC

type TEMRSETARCDIRECTION = struct {
	Femr           TEMR
	FiArcDirection TDWORD
}

type EMRSETARCDIRECTION = TEMRSETARCDIRECTION

type TtagEMRSETARCDIRECTION = TEMRSETARCDIRECTION

type tagEMRSETARCDIRECTION = TtagEMRSETARCDIRECTION

type TPEMRSETARCDIRECTION = uintptr

type PEMRSETARCDIRECTION = TPEMRSETARCDIRECTION

type TEMRSETMAPPERFLAGS = struct {
	Femr     TEMR
	FdwFlags TDWORD
}

type EMRSETMAPPERFLAGS = TEMRSETMAPPERFLAGS

type TtagEMRSETMAPPERFLAGS = TEMRSETMAPPERFLAGS

type tagEMRSETMAPPERFLAGS = TtagEMRSETMAPPERFLAGS

type TPEMRSETMAPPERFLAGS = uintptr

type PEMRSETMAPPERFLAGS = TPEMRSETMAPPERFLAGS

type TEMRSETBKCOLOR = struct {
	Femr     TEMR
	FcrColor TCOLORREF
}

type EMRSETBKCOLOR = TEMRSETBKCOLOR

type TtagEMRSETTEXTCOLOR = TEMRSETBKCOLOR

type tagEMRSETTEXTCOLOR = TtagEMRSETTEXTCOLOR

type TPEMRSETBKCOLOR = uintptr

type PEMRSETBKCOLOR = TPEMRSETBKCOLOR

type TEMRSETTEXTCOLOR = struct {
	Femr     TEMR
	FcrColor TCOLORREF
}

type EMRSETTEXTCOLOR = TEMRSETTEXTCOLOR

type TPEMRSETTEXTCOLOR = uintptr

type PEMRSETTEXTCOLOR = TPEMRSETTEXTCOLOR

type TEMRSELECTOBJECT = struct {
	Femr      TEMR
	FihObject TDWORD
}

type EMRSELECTOBJECT = TEMRSELECTOBJECT

type TtagEMRSELECTOBJECT = TEMRSELECTOBJECT

type tagEMRSELECTOBJECT = TtagEMRSELECTOBJECT

type TPEMRSELECTOBJECT = uintptr

type PEMRSELECTOBJECT = TPEMRSELECTOBJECT

type TEMRDELETEOBJECT = struct {
	Femr      TEMR
	FihObject TDWORD
}

type EMRDELETEOBJECT = TEMRDELETEOBJECT

type TPEMRDELETEOBJECT = uintptr

type PEMRDELETEOBJECT = TPEMRDELETEOBJECT

type TEMRSELECTPALETTE = struct {
	Femr   TEMR
	FihPal TDWORD
}

type EMRSELECTPALETTE = TEMRSELECTPALETTE

type TtagEMRSELECTPALETTE = TEMRSELECTPALETTE

type tagEMRSELECTPALETTE = TtagEMRSELECTPALETTE

type TPEMRSELECTPALETTE = uintptr

type PEMRSELECTPALETTE = TPEMRSELECTPALETTE

type TEMRRESIZEPALETTE = struct {
	Femr      TEMR
	FihPal    TDWORD
	FcEntries TDWORD
}

type EMRRESIZEPALETTE = TEMRRESIZEPALETTE

type TtagEMRRESIZEPALETTE = TEMRRESIZEPALETTE

type tagEMRRESIZEPALETTE = TtagEMRRESIZEPALETTE

type TPEMRRESIZEPALETTE = uintptr

type PEMRRESIZEPALETTE = TPEMRRESIZEPALETTE

type TEMRSETPALETTEENTRIES = struct {
	Femr         TEMR
	FihPal       TDWORD
	FiStart      TDWORD
	FcEntries    TDWORD
	FaPalEntries [1]TPALETTEENTRY
}

type EMRSETPALETTEENTRIES = TEMRSETPALETTEENTRIES

type TtagEMRSETPALETTEENTRIES = TEMRSETPALETTEENTRIES

type tagEMRSETPALETTEENTRIES = TtagEMRSETPALETTEENTRIES

type TPEMRSETPALETTEENTRIES = uintptr

type PEMRSETPALETTEENTRIES = TPEMRSETPALETTEENTRIES

type TEMRSETCOLORADJUSTMENT = struct {
	Femr             TEMR
	FColorAdjustment TCOLORADJUSTMENT
}

type EMRSETCOLORADJUSTMENT = TEMRSETCOLORADJUSTMENT

type TtagEMRSETCOLORADJUSTMENT = TEMRSETCOLORADJUSTMENT

type tagEMRSETCOLORADJUSTMENT = TtagEMRSETCOLORADJUSTMENT

type TPEMRSETCOLORADJUSTMENT = uintptr

type PEMRSETCOLORADJUSTMENT = TPEMRSETCOLORADJUSTMENT

type TEMRGDICOMMENT = struct {
	Femr    TEMR
	FcbData TDWORD
	FData   [1]TBYTE
}

type EMRGDICOMMENT = TEMRGDICOMMENT

type TtagEMRGDICOMMENT = TEMRGDICOMMENT

type tagEMRGDICOMMENT = TtagEMRGDICOMMENT

type TPEMRGDICOMMENT = uintptr

type PEMRGDICOMMENT = TPEMRGDICOMMENT

type TEMREOF = struct {
	Femr           TEMR
	FnPalEntries   TDWORD
	FoffPalEntries TDWORD
	FnSizeLast     TDWORD
}

type EMREOF = TEMREOF

type TtagEMREOF = TEMREOF

type tagEMREOF = TtagEMREOF

type TPEMREOF = uintptr

type PEMREOF = TPEMREOF

type TEMRLINETO = struct {
	Femr TEMR
	Fptl TPOINTL
}

type EMRLINETO = TEMRLINETO

type TtagEMRLINETO = TEMRLINETO

type tagEMRLINETO = TtagEMRLINETO

type TPEMRLINETO = uintptr

type PEMRLINETO = TPEMRLINETO

type TEMRMOVETOEX = struct {
	Femr TEMR
	Fptl TPOINTL
}

type EMRMOVETOEX = TEMRMOVETOEX

type TPEMRMOVETOEX = uintptr

type PEMRMOVETOEX = TPEMRMOVETOEX

type TEMROFFSETCLIPRGN = struct {
	Femr       TEMR
	FptlOffset TPOINTL
}

type EMROFFSETCLIPRGN = TEMROFFSETCLIPRGN

type TtagEMROFFSETCLIPRGN = TEMROFFSETCLIPRGN

type tagEMROFFSETCLIPRGN = TtagEMROFFSETCLIPRGN

type TPEMROFFSETCLIPRGN = uintptr

type PEMROFFSETCLIPRGN = TPEMROFFSETCLIPRGN

type TEMRFILLPATH = struct {
	Femr       TEMR
	FrclBounds TRECTL
}

type EMRFILLPATH = TEMRFILLPATH

type TtagEMRFILLPATH = TEMRFILLPATH

type tagEMRFILLPATH = TtagEMRFILLPATH

type TPEMRFILLPATH = uintptr

type PEMRFILLPATH = TPEMRFILLPATH

type TEMRSTROKEANDFILLPATH = struct {
	Femr       TEMR
	FrclBounds TRECTL
}

type EMRSTROKEANDFILLPATH = TEMRSTROKEANDFILLPATH

type TPEMRSTROKEANDFILLPATH = uintptr

type PEMRSTROKEANDFILLPATH = TPEMRSTROKEANDFILLPATH

type TEMRSTROKEPATH = struct {
	Femr       TEMR
	FrclBounds TRECTL
}

type EMRSTROKEPATH = TEMRSTROKEPATH

type TPEMRSTROKEPATH = uintptr

type PEMRSTROKEPATH = TPEMRSTROKEPATH

type TEMREXCLUDECLIPRECT = struct {
	Femr     TEMR
	FrclClip TRECTL
}

type EMREXCLUDECLIPRECT = TEMREXCLUDECLIPRECT

type TtagEMREXCLUDECLIPRECT = TEMREXCLUDECLIPRECT

type tagEMREXCLUDECLIPRECT = TtagEMREXCLUDECLIPRECT

type TPEMREXCLUDECLIPRECT = uintptr

type PEMREXCLUDECLIPRECT = TPEMREXCLUDECLIPRECT

type TEMRINTERSECTCLIPRECT = struct {
	Femr     TEMR
	FrclClip TRECTL
}

type EMRINTERSECTCLIPRECT = TEMRINTERSECTCLIPRECT

type TPEMRINTERSECTCLIPRECT = uintptr

type PEMRINTERSECTCLIPRECT = TPEMRINTERSECTCLIPRECT

type TEMRSETVIEWPORTORGEX = struct {
	Femr       TEMR
	FptlOrigin TPOINTL
}

type EMRSETVIEWPORTORGEX = TEMRSETVIEWPORTORGEX

type TtagEMRSETVIEWPORTORGEX = TEMRSETVIEWPORTORGEX

type tagEMRSETVIEWPORTORGEX = TtagEMRSETVIEWPORTORGEX

type TPEMRSETVIEWPORTORGEX = uintptr

type PEMRSETVIEWPORTORGEX = TPEMRSETVIEWPORTORGEX

type TEMRSETWINDOWORGEX = struct {
	Femr       TEMR
	FptlOrigin TPOINTL
}

type EMRSETWINDOWORGEX = TEMRSETWINDOWORGEX

type TPEMRSETWINDOWORGEX = uintptr

type PEMRSETWINDOWORGEX = TPEMRSETWINDOWORGEX

type TEMRSETBRUSHORGEX = struct {
	Femr       TEMR
	FptlOrigin TPOINTL
}

type EMRSETBRUSHORGEX = TEMRSETBRUSHORGEX

type TPEMRSETBRUSHORGEX = uintptr

type PEMRSETBRUSHORGEX = TPEMRSETBRUSHORGEX

type TEMRSETVIEWPORTEXTEX = struct {
	Femr       TEMR
	FszlExtent TSIZEL
}

type EMRSETVIEWPORTEXTEX = TEMRSETVIEWPORTEXTEX

type TtagEMRSETVIEWPORTEXTEX = TEMRSETVIEWPORTEXTEX

type tagEMRSETVIEWPORTEXTEX = TtagEMRSETVIEWPORTEXTEX

type TPEMRSETVIEWPORTEXTEX = uintptr

type PEMRSETVIEWPORTEXTEX = TPEMRSETVIEWPORTEXTEX

type TEMRSETWINDOWEXTEX = struct {
	Femr       TEMR
	FszlExtent TSIZEL
}

type EMRSETWINDOWEXTEX = TEMRSETWINDOWEXTEX

type TPEMRSETWINDOWEXTEX = uintptr

type PEMRSETWINDOWEXTEX = TPEMRSETWINDOWEXTEX

type TEMRSCALEVIEWPORTEXTEX = struct {
	Femr    TEMR
	FxNum   TLONG
	FxDenom TLONG
	FyNum   TLONG
	FyDenom TLONG
}

type EMRSCALEVIEWPORTEXTEX = TEMRSCALEVIEWPORTEXTEX

type TtagEMRSCALEVIEWPORTEXTEX = TEMRSCALEVIEWPORTEXTEX

type tagEMRSCALEVIEWPORTEXTEX = TtagEMRSCALEVIEWPORTEXTEX

type TPEMRSCALEVIEWPORTEXTEX = uintptr

type PEMRSCALEVIEWPORTEXTEX = TPEMRSCALEVIEWPORTEXTEX

type TEMRSCALEWINDOWEXTEX = struct {
	Femr    TEMR
	FxNum   TLONG
	FxDenom TLONG
	FyNum   TLONG
	FyDenom TLONG
}

type EMRSCALEWINDOWEXTEX = TEMRSCALEWINDOWEXTEX

type TPEMRSCALEWINDOWEXTEX = uintptr

type PEMRSCALEWINDOWEXTEX = TPEMRSCALEWINDOWEXTEX

type TEMRSETWORLDTRANSFORM = struct {
	Femr   TEMR
	Fxform TXFORM
}

type EMRSETWORLDTRANSFORM = TEMRSETWORLDTRANSFORM

type TtagEMRSETWORLDTRANSFORM = TEMRSETWORLDTRANSFORM

type tagEMRSETWORLDTRANSFORM = TtagEMRSETWORLDTRANSFORM

type TPEMRSETWORLDTRANSFORM = uintptr

type PEMRSETWORLDTRANSFORM = TPEMRSETWORLDTRANSFORM

type TEMRMODIFYWORLDTRANSFORM = struct {
	Femr   TEMR
	Fxform TXFORM
	FiMode TDWORD
}

type EMRMODIFYWORLDTRANSFORM = TEMRMODIFYWORLDTRANSFORM

type TtagEMRMODIFYWORLDTRANSFORM = TEMRMODIFYWORLDTRANSFORM

type tagEMRMODIFYWORLDTRANSFORM = TtagEMRMODIFYWORLDTRANSFORM

type TPEMRMODIFYWORLDTRANSFORM = uintptr

type PEMRMODIFYWORLDTRANSFORM = TPEMRMODIFYWORLDTRANSFORM

type TEMRSETPIXELV = struct {
	Femr      TEMR
	FptlPixel TPOINTL
	FcrColor  TCOLORREF
}

type EMRSETPIXELV = TEMRSETPIXELV

type TtagEMRSETPIXELV = TEMRSETPIXELV

type tagEMRSETPIXELV = TtagEMRSETPIXELV

type TPEMRSETPIXELV = uintptr

type PEMRSETPIXELV = TPEMRSETPIXELV

type TEMREXTFLOODFILL = struct {
	Femr      TEMR
	FptlStart TPOINTL
	FcrColor  TCOLORREF
	FiMode    TDWORD
}

type EMREXTFLOODFILL = TEMREXTFLOODFILL

type TtagEMREXTFLOODFILL = TEMREXTFLOODFILL

type tagEMREXTFLOODFILL = TtagEMREXTFLOODFILL

type TPEMREXTFLOODFILL = uintptr

type PEMREXTFLOODFILL = TPEMREXTFLOODFILL

type TEMRELLIPSE = struct {
	Femr    TEMR
	FrclBox TRECTL
}

type EMRELLIPSE = TEMRELLIPSE

type TtagEMRELLIPSE = TEMRELLIPSE

type tagEMRELLIPSE = TtagEMRELLIPSE

type TPEMRELLIPSE = uintptr

type PEMRELLIPSE = TPEMRELLIPSE

type TEMRRECTANGLE = struct {
	Femr    TEMR
	FrclBox TRECTL
}

type EMRRECTANGLE = TEMRRECTANGLE

type TPEMRRECTANGLE = uintptr

type PEMRRECTANGLE = TPEMRRECTANGLE

type TEMRROUNDRECT = struct {
	Femr       TEMR
	FrclBox    TRECTL
	FszlCorner TSIZEL
}

type EMRROUNDRECT = TEMRROUNDRECT

type TtagEMRROUNDRECT = TEMRROUNDRECT

type tagEMRROUNDRECT = TtagEMRROUNDRECT

type TPEMRROUNDRECT = uintptr

type PEMRROUNDRECT = TPEMRROUNDRECT

type TEMRARC = struct {
	Femr      TEMR
	FrclBox   TRECTL
	FptlStart TPOINTL
	FptlEnd   TPOINTL
}

type EMRARC = TEMRARC

type TtagEMRARC = TEMRARC

type tagEMRARC = TtagEMRARC

type TPEMRARC = uintptr

type PEMRARC = TPEMRARC

type TEMRARCTO = struct {
	Femr      TEMR
	FrclBox   TRECTL
	FptlStart TPOINTL
	FptlEnd   TPOINTL
}

type EMRARCTO = TEMRARCTO

type TPEMRARCTO = uintptr

type PEMRARCTO = TPEMRARCTO

type TEMRCHORD = struct {
	Femr      TEMR
	FrclBox   TRECTL
	FptlStart TPOINTL
	FptlEnd   TPOINTL
}

type EMRCHORD = TEMRCHORD

type TPEMRCHORD = uintptr

type PEMRCHORD = TPEMRCHORD

type TEMRPIE = struct {
	Femr      TEMR
	FrclBox   TRECTL
	FptlStart TPOINTL
	FptlEnd   TPOINTL
}

type EMRPIE = TEMRPIE

type TPEMRPIE = uintptr

type PEMRPIE = TPEMRPIE

type TEMRANGLEARC = struct {
	Femr         TEMR
	FptlCenter   TPOINTL
	FnRadius     TDWORD
	FeStartAngle TFLOAT
	FeSweepAngle TFLOAT
}

type EMRANGLEARC = TEMRANGLEARC

type TtagEMRANGLEARC = TEMRANGLEARC

type tagEMRANGLEARC = TtagEMRANGLEARC

type TPEMRANGLEARC = uintptr

type PEMRANGLEARC = TPEMRANGLEARC

type TEMRPOLYLINE = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcptl      TDWORD
	Faptl      [1]TPOINTL
}

type EMRPOLYLINE = TEMRPOLYLINE

type TtagEMRPOLYLINE = TEMRPOLYLINE

type tagEMRPOLYLINE = TtagEMRPOLYLINE

type TPEMRPOLYLINE = uintptr

type PEMRPOLYLINE = TPEMRPOLYLINE

type TEMRPOLYBEZIER = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcptl      TDWORD
	Faptl      [1]TPOINTL
}

type EMRPOLYBEZIER = TEMRPOLYBEZIER

type TPEMRPOLYBEZIER = uintptr

type PEMRPOLYBEZIER = TPEMRPOLYBEZIER

type TEMRPOLYGON = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcptl      TDWORD
	Faptl      [1]TPOINTL
}

type EMRPOLYGON = TEMRPOLYGON

type TPEMRPOLYGON = uintptr

type PEMRPOLYGON = TPEMRPOLYGON

type TEMRPOLYBEZIERTO = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcptl      TDWORD
	Faptl      [1]TPOINTL
}

type EMRPOLYBEZIERTO = TEMRPOLYBEZIERTO

type TPEMRPOLYBEZIERTO = uintptr

type PEMRPOLYBEZIERTO = TPEMRPOLYBEZIERTO

type TEMRPOLYLINETO = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcptl      TDWORD
	Faptl      [1]TPOINTL
}

type EMRPOLYLINETO = TEMRPOLYLINETO

type TPEMRPOLYLINETO = uintptr

type PEMRPOLYLINETO = TPEMRPOLYLINETO

type TEMRPOLYLINE16 = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcpts      TDWORD
	Fapts      [1]TPOINTS
}

type EMRPOLYLINE16 = TEMRPOLYLINE16

type TtagEMRPOLYLINE16 = TEMRPOLYLINE16

type tagEMRPOLYLINE16 = TtagEMRPOLYLINE16

type TPEMRPOLYLINE16 = uintptr

type PEMRPOLYLINE16 = TPEMRPOLYLINE16

type TEMRPOLYBEZIER16 = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcpts      TDWORD
	Fapts      [1]TPOINTS
}

type EMRPOLYBEZIER16 = TEMRPOLYBEZIER16

type TPEMRPOLYBEZIER16 = uintptr

type PEMRPOLYBEZIER16 = TPEMRPOLYBEZIER16

type TEMRPOLYGON16 = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcpts      TDWORD
	Fapts      [1]TPOINTS
}

type EMRPOLYGON16 = TEMRPOLYGON16

type TPEMRPOLYGON16 = uintptr

type PEMRPOLYGON16 = TPEMRPOLYGON16

type TEMRPOLYBEZIERTO16 = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcpts      TDWORD
	Fapts      [1]TPOINTS
}

type EMRPOLYBEZIERTO16 = TEMRPOLYBEZIERTO16

type TPEMRPOLYBEZIERTO16 = uintptr

type PEMRPOLYBEZIERTO16 = TPEMRPOLYBEZIERTO16

type TEMRPOLYLINETO16 = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcpts      TDWORD
	Fapts      [1]TPOINTS
}

type EMRPOLYLINETO16 = TEMRPOLYLINETO16

type TPEMRPOLYLINETO16 = uintptr

type PEMRPOLYLINETO16 = TPEMRPOLYLINETO16

type TEMRPOLYDRAW = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcptl      TDWORD
	Faptl      [1]TPOINTL
	FabTypes   [1]TBYTE
}

type EMRPOLYDRAW = TEMRPOLYDRAW

type TtagEMRPOLYDRAW = TEMRPOLYDRAW

type tagEMRPOLYDRAW = TtagEMRPOLYDRAW

type TPEMRPOLYDRAW = uintptr

type PEMRPOLYDRAW = TPEMRPOLYDRAW

type TEMRPOLYDRAW16 = struct {
	Femr       TEMR
	FrclBounds TRECTL
	Fcpts      TDWORD
	Fapts      [1]TPOINTS
	FabTypes   [1]TBYTE
}

type EMRPOLYDRAW16 = TEMRPOLYDRAW16

type TtagEMRPOLYDRAW16 = TEMRPOLYDRAW16

type tagEMRPOLYDRAW16 = TtagEMRPOLYDRAW16

type TPEMRPOLYDRAW16 = uintptr

type PEMRPOLYDRAW16 = TPEMRPOLYDRAW16

type TEMRPOLYPOLYLINE = struct {
	Femr         TEMR
	FrclBounds   TRECTL
	FnPolys      TDWORD
	Fcptl        TDWORD
	FaPolyCounts [1]TDWORD
	Faptl        [1]TPOINTL
}

type EMRPOLYPOLYLINE = TEMRPOLYPOLYLINE

type TtagEMRPOLYPOLYLINE = TEMRPOLYPOLYLINE

type tagEMRPOLYPOLYLINE = TtagEMRPOLYPOLYLINE

type TPEMRPOLYPOLYLINE = uintptr

type PEMRPOLYPOLYLINE = TPEMRPOLYPOLYLINE

type TEMRPOLYPOLYGON = struct {
	Femr         TEMR
	FrclBounds   TRECTL
	FnPolys      TDWORD
	Fcptl        TDWORD
	FaPolyCounts [1]TDWORD
	Faptl        [1]TPOINTL
}

type EMRPOLYPOLYGON = TEMRPOLYPOLYGON

type TPEMRPOLYPOLYGON = uintptr

type PEMRPOLYPOLYGON = TPEMRPOLYPOLYGON

type TEMRPOLYPOLYLINE16 = struct {
	Femr         TEMR
	FrclBounds   TRECTL
	FnPolys      TDWORD
	Fcpts        TDWORD
	FaPolyCounts [1]TDWORD
	Fapts        [1]TPOINTS
}

type EMRPOLYPOLYLINE16 = TEMRPOLYPOLYLINE16

type TtagEMRPOLYPOLYLINE16 = TEMRPOLYPOLYLINE16

type tagEMRPOLYPOLYLINE16 = TtagEMRPOLYPOLYLINE16

type TPEMRPOLYPOLYLINE16 = uintptr

type PEMRPOLYPOLYLINE16 = TPEMRPOLYPOLYLINE16

type TEMRPOLYPOLYGON16 = struct {
	Femr         TEMR
	FrclBounds   TRECTL
	FnPolys      TDWORD
	Fcpts        TDWORD
	FaPolyCounts [1]TDWORD
	Fapts        [1]TPOINTS
}

type EMRPOLYPOLYGON16 = TEMRPOLYPOLYGON16

type TPEMRPOLYPOLYGON16 = uintptr

type PEMRPOLYPOLYGON16 = TPEMRPOLYPOLYGON16

type TEMRINVERTRGN = struct {
	Femr       TEMR
	FrclBounds TRECTL
	FcbRgnData TDWORD
	FRgnData   [1]TBYTE
}

type EMRINVERTRGN = TEMRINVERTRGN

type TtagEMRINVERTRGN = TEMRINVERTRGN

type tagEMRINVERTRGN = TtagEMRINVERTRGN

type TPEMRINVERTRGN = uintptr

type PEMRINVERTRGN = TPEMRINVERTRGN

type TEMRPAINTRGN = struct {
	Femr       TEMR
	FrclBounds TRECTL
	FcbRgnData TDWORD
	FRgnData   [1]TBYTE
}

type EMRPAINTRGN = TEMRPAINTRGN

type TPEMRPAINTRGN = uintptr

type PEMRPAINTRGN = TPEMRPAINTRGN

type TEMRFILLRGN = struct {
	Femr       TEMR
	FrclBounds TRECTL
	FcbRgnData TDWORD
	FihBrush   TDWORD
	FRgnData   [1]TBYTE
}

type EMRFILLRGN = TEMRFILLRGN

type TtagEMRFILLRGN = TEMRFILLRGN

type tagEMRFILLRGN = TtagEMRFILLRGN

type TPEMRFILLRGN = uintptr

type PEMRFILLRGN = TPEMRFILLRGN

type TEMRFRAMERGN = struct {
	Femr       TEMR
	FrclBounds TRECTL
	FcbRgnData TDWORD
	FihBrush   TDWORD
	FszlStroke TSIZEL
	FRgnData   [1]TBYTE
}

type EMRFRAMERGN = TEMRFRAMERGN

type TtagEMRFRAMERGN = TEMRFRAMERGN

type tagEMRFRAMERGN = TtagEMRFRAMERGN

type TPEMRFRAMERGN = uintptr

type PEMRFRAMERGN = TPEMRFRAMERGN

type TEMREXTSELECTCLIPRGN = struct {
	Femr       TEMR
	FcbRgnData TDWORD
	FiMode     TDWORD
	FRgnData   [1]TBYTE
}

type EMREXTSELECTCLIPRGN = TEMREXTSELECTCLIPRGN

type TtagEMREXTSELECTCLIPRGN = TEMREXTSELECTCLIPRGN

type tagEMREXTSELECTCLIPRGN = TtagEMREXTSELECTCLIPRGN

type TPEMREXTSELECTCLIPRGN = uintptr

type PEMREXTSELECTCLIPRGN = TPEMREXTSELECTCLIPRGN

type TEMREXTTEXTOUTA = struct {
	Femr           TEMR
	FrclBounds     TRECTL
	FiGraphicsMode TDWORD
	FexScale       TFLOAT
	FeyScale       TFLOAT
	Femrtext       TEMRTEXT
}

type EMREXTTEXTOUTA = TEMREXTTEXTOUTA

type TtagEMREXTTEXTOUTA = TEMREXTTEXTOUTA

type tagEMREXTTEXTOUTA = TtagEMREXTTEXTOUTA

type TPEMREXTTEXTOUTA = uintptr

type PEMREXTTEXTOUTA = TPEMREXTTEXTOUTA

type TEMREXTTEXTOUTW = struct {
	Femr           TEMR
	FrclBounds     TRECTL
	FiGraphicsMode TDWORD
	FexScale       TFLOAT
	FeyScale       TFLOAT
	Femrtext       TEMRTEXT
}

type EMREXTTEXTOUTW = TEMREXTTEXTOUTW

type TPEMREXTTEXTOUTW = uintptr

type PEMREXTTEXTOUTW = TPEMREXTTEXTOUTW

type TEMRPOLYTEXTOUTA = struct {
	Femr           TEMR
	FrclBounds     TRECTL
	FiGraphicsMode TDWORD
	FexScale       TFLOAT
	FeyScale       TFLOAT
	FcStrings      TLONG
	Faemrtext      [1]TEMRTEXT
}

type EMRPOLYTEXTOUTA = TEMRPOLYTEXTOUTA

type TtagEMRPOLYTEXTOUTA = TEMRPOLYTEXTOUTA

type tagEMRPOLYTEXTOUTA = TtagEMRPOLYTEXTOUTA

type TPEMRPOLYTEXTOUTA = uintptr

type PEMRPOLYTEXTOUTA = TPEMRPOLYTEXTOUTA

type TEMRPOLYTEXTOUTW = struct {
	Femr           TEMR
	FrclBounds     TRECTL
	FiGraphicsMode TDWORD
	FexScale       TFLOAT
	FeyScale       TFLOAT
	FcStrings      TLONG
	Faemrtext      [1]TEMRTEXT
}

type EMRPOLYTEXTOUTW = TEMRPOLYTEXTOUTW

type TPEMRPOLYTEXTOUTW = uintptr

type PEMRPOLYTEXTOUTW = TPEMRPOLYTEXTOUTW

type TEMRBITBLT = struct {
	Femr          TEMR
	FrclBounds    TRECTL
	FxDest        TLONG
	FyDest        TLONG
	FcxDest       TLONG
	FcyDest       TLONG
	FdwRop        TDWORD
	FxSrc         TLONG
	FySrc         TLONG
	FxformSrc     TXFORM
	FcrBkColorSrc TCOLORREF
	FiUsageSrc    TDWORD
	FoffBmiSrc    TDWORD
	FcbBmiSrc     TDWORD
	FoffBitsSrc   TDWORD
	FcbBitsSrc    TDWORD
}

type EMRBITBLT = TEMRBITBLT

type TtagEMRBITBLT = TEMRBITBLT

type tagEMRBITBLT = TtagEMRBITBLT

type TPEMRBITBLT = uintptr

type PEMRBITBLT = TPEMRBITBLT

type TEMRSTRETCHBLT = struct {
	Femr          TEMR
	FrclBounds    TRECTL
	FxDest        TLONG
	FyDest        TLONG
	FcxDest       TLONG
	FcyDest       TLONG
	FdwRop        TDWORD
	FxSrc         TLONG
	FySrc         TLONG
	FxformSrc     TXFORM
	FcrBkColorSrc TCOLORREF
	FiUsageSrc    TDWORD
	FoffBmiSrc    TDWORD
	FcbBmiSrc     TDWORD
	FoffBitsSrc   TDWORD
	FcbBitsSrc    TDWORD
	FcxSrc        TLONG
	FcySrc        TLONG
}

type EMRSTRETCHBLT = TEMRSTRETCHBLT

type TtagEMRSTRETCHBLT = TEMRSTRETCHBLT

type tagEMRSTRETCHBLT = TtagEMRSTRETCHBLT

type TPEMRSTRETCHBLT = uintptr

type PEMRSTRETCHBLT = TPEMRSTRETCHBLT

type TEMRMASKBLT = struct {
	Femr          TEMR
	FrclBounds    TRECTL
	FxDest        TLONG
	FyDest        TLONG
	FcxDest       TLONG
	FcyDest       TLONG
	FdwRop        TDWORD
	FxSrc         TLONG
	FySrc         TLONG
	FxformSrc     TXFORM
	FcrBkColorSrc TCOLORREF
	FiUsageSrc    TDWORD
	FoffBmiSrc    TDWORD
	FcbBmiSrc     TDWORD
	FoffBitsSrc   TDWORD
	FcbBitsSrc    TDWORD
	FxMask        TLONG
	FyMask        TLONG
	FiUsageMask   TDWORD
	FoffBmiMask   TDWORD
	FcbBmiMask    TDWORD
	FoffBitsMask  TDWORD
	FcbBitsMask   TDWORD
}

type EMRMASKBLT = TEMRMASKBLT

type TtagEMRMASKBLT = TEMRMASKBLT

type tagEMRMASKBLT = TtagEMRMASKBLT

type TPEMRMASKBLT = uintptr

type PEMRMASKBLT = TPEMRMASKBLT

type TEMRPLGBLT = struct {
	Femr          TEMR
	FrclBounds    TRECTL
	FaptlDest     [3]TPOINTL
	FxSrc         TLONG
	FySrc         TLONG
	FcxSrc        TLONG
	FcySrc        TLONG
	FxformSrc     TXFORM
	FcrBkColorSrc TCOLORREF
	FiUsageSrc    TDWORD
	FoffBmiSrc    TDWORD
	FcbBmiSrc     TDWORD
	FoffBitsSrc   TDWORD
	FcbBitsSrc    TDWORD
	FxMask        TLONG
	FyMask        TLONG
	FiUsageMask   TDWORD
	FoffBmiMask   TDWORD
	FcbBmiMask    TDWORD
	FoffBitsMask  TDWORD
	FcbBitsMask   TDWORD
}

type EMRPLGBLT = TEMRPLGBLT

type TtagEMRPLGBLT = TEMRPLGBLT

type tagEMRPLGBLT = TtagEMRPLGBLT

type TPEMRPLGBLT = uintptr

type PEMRPLGBLT = TPEMRPLGBLT

type TEMRSETDIBITSTODEVICE = struct {
	Femr        TEMR
	FrclBounds  TRECTL
	FxDest      TLONG
	FyDest      TLONG
	FxSrc       TLONG
	FySrc       TLONG
	FcxSrc      TLONG
	FcySrc      TLONG
	FoffBmiSrc  TDWORD
	FcbBmiSrc   TDWORD
	FoffBitsSrc TDWORD
	FcbBitsSrc  TDWORD
	FiUsageSrc  TDWORD
	FiStartScan TDWORD
	FcScans     TDWORD
}

type EMRSETDIBITSTODEVICE = TEMRSETDIBITSTODEVICE

type TtagEMRSETDIBITSTODEVICE = TEMRSETDIBITSTODEVICE

type tagEMRSETDIBITSTODEVICE = TtagEMRSETDIBITSTODEVICE

type TPEMRSETDIBITSTODEVICE = uintptr

type PEMRSETDIBITSTODEVICE = TPEMRSETDIBITSTODEVICE

type TEMRSTRETCHDIBITS = struct {
	Femr        TEMR
	FrclBounds  TRECTL
	FxDest      TLONG
	FyDest      TLONG
	FxSrc       TLONG
	FySrc       TLONG
	FcxSrc      TLONG
	FcySrc      TLONG
	FoffBmiSrc  TDWORD
	FcbBmiSrc   TDWORD
	FoffBitsSrc TDWORD
	FcbBitsSrc  TDWORD
	FiUsageSrc  TDWORD
	FdwRop      TDWORD
	FcxDest     TLONG
	FcyDest     TLONG
}

type EMRSTRETCHDIBITS = TEMRSTRETCHDIBITS

type TtagEMRSTRETCHDIBITS = TEMRSTRETCHDIBITS

type tagEMRSTRETCHDIBITS = TtagEMRSTRETCHDIBITS

type TPEMRSTRETCHDIBITS = uintptr

type PEMRSTRETCHDIBITS = TPEMRSTRETCHDIBITS

type TEMREXTCREATEFONTINDIRECTW = struct {
	Femr    TEMR
	FihFont TDWORD
	Felfw   TEXTLOGFONTW
}

type EMREXTCREATEFONTINDIRECTW = TEMREXTCREATEFONTINDIRECTW

type TtagEMREXTCREATEFONTINDIRECTW = TEMREXTCREATEFONTINDIRECTW

type tagEMREXTCREATEFONTINDIRECTW = TtagEMREXTCREATEFONTINDIRECTW

type TPEMREXTCREATEFONTINDIRECTW = uintptr

type PEMREXTCREATEFONTINDIRECTW = TPEMREXTCREATEFONTINDIRECTW

type TEMRCREATEPALETTE = struct {
	Femr   TEMR
	FihPal TDWORD
	Flgpl  TLOGPALETTE
}

type EMRCREATEPALETTE = TEMRCREATEPALETTE

type TtagEMRCREATEPALETTE = TEMRCREATEPALETTE

type tagEMRCREATEPALETTE = TtagEMRCREATEPALETTE

type TPEMRCREATEPALETTE = uintptr

type PEMRCREATEPALETTE = TPEMRCREATEPALETTE

type TEMRCREATEPEN = struct {
	Femr   TEMR
	FihPen TDWORD
	Flopn  TLOGPEN
}

type EMRCREATEPEN = TEMRCREATEPEN

type TtagEMRCREATEPEN = TEMRCREATEPEN

type tagEMRCREATEPEN = TtagEMRCREATEPEN

type TPEMRCREATEPEN = uintptr

type PEMRCREATEPEN = TPEMRCREATEPEN

type TEMREXTCREATEPEN = struct {
	Femr     TEMR
	FihPen   TDWORD
	FoffBmi  TDWORD
	FcbBmi   TDWORD
	FoffBits TDWORD
	FcbBits  TDWORD
	Felp     TEXTLOGPEN
}

type EMREXTCREATEPEN = TEMREXTCREATEPEN

type TtagEMREXTCREATEPEN = TEMREXTCREATEPEN

type tagEMREXTCREATEPEN = TtagEMREXTCREATEPEN

type TPEMREXTCREATEPEN = uintptr

type PEMREXTCREATEPEN = TPEMREXTCREATEPEN

type TEMRCREATEBRUSHINDIRECT = struct {
	Femr     TEMR
	FihBrush TDWORD
	Flb      TLOGBRUSH32
}

type EMRCREATEBRUSHINDIRECT = TEMRCREATEBRUSHINDIRECT

type TtagEMRCREATEBRUSHINDIRECT = TEMRCREATEBRUSHINDIRECT

type tagEMRCREATEBRUSHINDIRECT = TtagEMRCREATEBRUSHINDIRECT

type TPEMRCREATEBRUSHINDIRECT = uintptr

type PEMRCREATEBRUSHINDIRECT = TPEMRCREATEBRUSHINDIRECT

type TEMRCREATEMONOBRUSH = struct {
	Femr     TEMR
	FihBrush TDWORD
	FiUsage  TDWORD
	FoffBmi  TDWORD
	FcbBmi   TDWORD
	FoffBits TDWORD
	FcbBits  TDWORD
}

type EMRCREATEMONOBRUSH = TEMRCREATEMONOBRUSH

type TtagEMRCREATEMONOBRUSH = TEMRCREATEMONOBRUSH

type tagEMRCREATEMONOBRUSH = TtagEMRCREATEMONOBRUSH

type TPEMRCREATEMONOBRUSH = uintptr

type PEMRCREATEMONOBRUSH = TPEMRCREATEMONOBRUSH

type TEMRCREATEDIBPATTERNBRUSHPT = struct {
	Femr     TEMR
	FihBrush TDWORD
	FiUsage  TDWORD
	FoffBmi  TDWORD
	FcbBmi   TDWORD
	FoffBits TDWORD
	FcbBits  TDWORD
}

type EMRCREATEDIBPATTERNBRUSHPT = TEMRCREATEDIBPATTERNBRUSHPT

type TtagEMRCREATEDIBPATTERNBRUSHPT = TEMRCREATEDIBPATTERNBRUSHPT

type tagEMRCREATEDIBPATTERNBRUSHPT = TtagEMRCREATEDIBPATTERNBRUSHPT

type TPEMRCREATEDIBPATTERNBRUSHPT = uintptr

type PEMRCREATEDIBPATTERNBRUSHPT = TPEMRCREATEDIBPATTERNBRUSHPT

type TEMRFORMAT = struct {
	FdSignature TDWORD
	FnVersion   TDWORD
	FcbData     TDWORD
	FoffData    TDWORD
}

type EMRFORMAT = TEMRFORMAT

type TtagEMRFORMAT = TEMRFORMAT

type tagEMRFORMAT = TtagEMRFORMAT

type TPEMRFORMAT = uintptr

type PEMRFORMAT = TPEMRFORMAT

type TEMRGLSRECORD = struct {
	Femr    TEMR
	FcbData TDWORD
	FData   [1]TBYTE
}

type EMRGLSRECORD = TEMRGLSRECORD

type TtagEMRGLSRECORD = TEMRGLSRECORD

type tagEMRGLSRECORD = TtagEMRGLSRECORD

type TPEMRGLSRECORD = uintptr

type PEMRGLSRECORD = TPEMRGLSRECORD

type TEMRGLSBOUNDEDRECORD = struct {
	Femr       TEMR
	FrclBounds TRECTL
	FcbData    TDWORD
	FData      [1]TBYTE
}

type EMRGLSBOUNDEDRECORD = TEMRGLSBOUNDEDRECORD

type TtagEMRGLSBOUNDEDRECORD = TEMRGLSBOUNDEDRECORD

type tagEMRGLSBOUNDEDRECORD = TtagEMRGLSBOUNDEDRECORD

type TPEMRGLSBOUNDEDRECORD = uintptr

type PEMRGLSBOUNDEDRECORD = TPEMRGLSBOUNDEDRECORD

type TEMRPIXELFORMAT = struct {
	Femr TEMR
	Fpfd TPIXELFORMATDESCRIPTOR
}

type EMRPIXELFORMAT = TEMRPIXELFORMAT

type TtagEMRPIXELFORMAT = TEMRPIXELFORMAT

type tagEMRPIXELFORMAT = TtagEMRPIXELFORMAT

type TPEMRPIXELFORMAT = uintptr

type PEMRPIXELFORMAT = TPEMRPIXELFORMAT

type TEMRCREATECOLORSPACE = struct {
	Femr  TEMR
	FihCS TDWORD
	Flcs  TLOGCOLORSPACEA
}

type EMRCREATECOLORSPACE = TEMRCREATECOLORSPACE

type TtagEMRCREATECOLORSPACE = TEMRCREATECOLORSPACE

type tagEMRCREATECOLORSPACE = TtagEMRCREATECOLORSPACE

type TPEMRCREATECOLORSPACE = uintptr

type PEMRCREATECOLORSPACE = TPEMRCREATECOLORSPACE

type TEMRSETCOLORSPACE = struct {
	Femr  TEMR
	FihCS TDWORD
}

type EMRSETCOLORSPACE = TEMRSETCOLORSPACE

type TtagEMRSETCOLORSPACE = TEMRSETCOLORSPACE

type tagEMRSETCOLORSPACE = TtagEMRSETCOLORSPACE

type TPEMRSETCOLORSPACE = uintptr

type PEMRSETCOLORSPACE = TPEMRSETCOLORSPACE

type TEMRSELECTCOLORSPACE = struct {
	Femr  TEMR
	FihCS TDWORD
}

type EMRSELECTCOLORSPACE = TEMRSELECTCOLORSPACE

type TPEMRSELECTCOLORSPACE = uintptr

type PEMRSELECTCOLORSPACE = TPEMRSELECTCOLORSPACE

type TEMRDELETECOLORSPACE = struct {
	Femr  TEMR
	FihCS TDWORD
}

type EMRDELETECOLORSPACE = TEMRDELETECOLORSPACE

type TPEMRDELETECOLORSPACE = uintptr

type PEMRDELETECOLORSPACE = TPEMRDELETECOLORSPACE

type TEMREXTESCAPE = struct {
	Femr       TEMR
	FiEscape   TINT
	FcbEscData TINT
	FEscData   [1]TBYTE
}

type EMREXTESCAPE = TEMREXTESCAPE

type TtagEMREXTESCAPE = TEMREXTESCAPE

type tagEMREXTESCAPE = TtagEMREXTESCAPE

type TPEMREXTESCAPE = uintptr

type PEMREXTESCAPE = TPEMREXTESCAPE

type TEMRDRAWESCAPE = struct {
	Femr       TEMR
	FiEscape   TINT
	FcbEscData TINT
	FEscData   [1]TBYTE
}

type EMRDRAWESCAPE = TEMRDRAWESCAPE

type TPEMRDRAWESCAPE = uintptr

type PEMRDRAWESCAPE = TPEMRDRAWESCAPE

type TEMRNAMEDESCAPE = struct {
	Femr       TEMR
	FiEscape   TINT
	FcbDriver  TINT
	FcbEscData TINT
	FEscData   [1]TBYTE
}

type EMRNAMEDESCAPE = TEMRNAMEDESCAPE

type TtagEMRNAMEDESCAPE = TEMRNAMEDESCAPE

type tagEMRNAMEDESCAPE = TtagEMRNAMEDESCAPE

type TPEMRNAMEDESCAPE = uintptr

type PEMRNAMEDESCAPE = TPEMRNAMEDESCAPE

type TEMRSETICMPROFILE = struct {
	Femr     TEMR
	FdwFlags TDWORD
	FcbName  TDWORD
	FcbData  TDWORD
	FData    [1]TBYTE
}

type EMRSETICMPROFILE = TEMRSETICMPROFILE

type TtagEMRSETICMPROFILE = TEMRSETICMPROFILE

type tagEMRSETICMPROFILE = TtagEMRSETICMPROFILE

type TPEMRSETICMPROFILE = uintptr

type PEMRSETICMPROFILE = TPEMRSETICMPROFILE

type TEMRSETICMPROFILEA = struct {
	Femr     TEMR
	FdwFlags TDWORD
	FcbName  TDWORD
	FcbData  TDWORD
	FData    [1]TBYTE
}

type EMRSETICMPROFILEA = TEMRSETICMPROFILEA

type TPEMRSETICMPROFILEA = uintptr

type PEMRSETICMPROFILEA = TPEMRSETICMPROFILEA

type TEMRSETICMPROFILEW = struct {
	Femr     TEMR
	FdwFlags TDWORD
	FcbName  TDWORD
	FcbData  TDWORD
	FData    [1]TBYTE
}

type EMRSETICMPROFILEW = TEMRSETICMPROFILEW

type TPEMRSETICMPROFILEW = uintptr

type PEMRSETICMPROFILEW = TPEMRSETICMPROFILEW

type TEMRCREATECOLORSPACEW = struct {
	Femr     TEMR
	FihCS    TDWORD
	Flcs     TLOGCOLORSPACEW
	FdwFlags TDWORD
	FcbData  TDWORD
	FData    [1]TBYTE
}

type EMRCREATECOLORSPACEW = TEMRCREATECOLORSPACEW

type TtagEMRCREATECOLORSPACEW = TEMRCREATECOLORSPACEW

type tagEMRCREATECOLORSPACEW = TtagEMRCREATECOLORSPACEW

type TPEMRCREATECOLORSPACEW = uintptr

type PEMRCREATECOLORSPACEW = TPEMRCREATECOLORSPACEW

type TEMRCOLORMATCHTOTARGET = struct {
	Femr      TEMR
	FdwAction TDWORD
	FdwFlags  TDWORD
	FcbName   TDWORD
	FcbData   TDWORD
	FData     [1]TBYTE
}

type EMRCOLORMATCHTOTARGET = TEMRCOLORMATCHTOTARGET

type TtagCOLORMATCHTOTARGET = TEMRCOLORMATCHTOTARGET

type tagCOLORMATCHTOTARGET = TtagCOLORMATCHTOTARGET

type TPEMRCOLORMATCHTOTARGET = uintptr

type PEMRCOLORMATCHTOTARGET = TPEMRCOLORMATCHTOTARGET

type TEMRCOLORCORRECTPALETTE = struct {
	Femr         TEMR
	FihPalette   TDWORD
	FnFirstEntry TDWORD
	FnPalEntries TDWORD
	FnReserved   TDWORD
}

type EMRCOLORCORRECTPALETTE = TEMRCOLORCORRECTPALETTE

type TtagCOLORCORRECTPALETTE = TEMRCOLORCORRECTPALETTE

type tagCOLORCORRECTPALETTE = TtagCOLORCORRECTPALETTE

type TPEMRCOLORCORRECTPALETTE = uintptr

type PEMRCOLORCORRECTPALETTE = TPEMRCOLORCORRECTPALETTE

type TEMRALPHABLEND = struct {
	Femr          TEMR
	FrclBounds    TRECTL
	FxDest        TLONG
	FyDest        TLONG
	FcxDest       TLONG
	FcyDest       TLONG
	FdwRop        TDWORD
	FxSrc         TLONG
	FySrc         TLONG
	FxformSrc     TXFORM
	FcrBkColorSrc TCOLORREF
	FiUsageSrc    TDWORD
	FoffBmiSrc    TDWORD
	FcbBmiSrc     TDWORD
	FoffBitsSrc   TDWORD
	FcbBitsSrc    TDWORD
	FcxSrc        TLONG
	FcySrc        TLONG
}

type EMRALPHABLEND = TEMRALPHABLEND

type TtagEMRALPHABLEND = TEMRALPHABLEND

type tagEMRALPHABLEND = TtagEMRALPHABLEND

type TPEMRALPHABLEND = uintptr

type PEMRALPHABLEND = TPEMRALPHABLEND

type TEMRGRADIENTFILL = struct {
	Femr       TEMR
	FrclBounds TRECTL
	FnVer      TDWORD
	FnTri      TDWORD
	FulMode    TULONG
	FVer       [1]TTRIVERTEX
}

type EMRGRADIENTFILL = TEMRGRADIENTFILL

type TtagEMRGRADIENTFILL = TEMRGRADIENTFILL

type tagEMRGRADIENTFILL = TtagEMRGRADIENTFILL

type TPEMRGRADIENTFILL = uintptr

type PEMRGRADIENTFILL = TPEMRGRADIENTFILL

type TEMRTRANSPARENTBLT = struct {
	Femr          TEMR
	FrclBounds    TRECTL
	FxDest        TLONG
	FyDest        TLONG
	FcxDest       TLONG
	FcyDest       TLONG
	FdwRop        TDWORD
	FxSrc         TLONG
	FySrc         TLONG
	FxformSrc     TXFORM
	FcrBkColorSrc TCOLORREF
	FiUsageSrc    TDWORD
	FoffBmiSrc    TDWORD
	FcbBmiSrc     TDWORD
	FoffBitsSrc   TDWORD
	FcbBitsSrc    TDWORD
	FcxSrc        TLONG
	FcySrc        TLONG
}

type EMRTRANSPARENTBLT = TEMRTRANSPARENTBLT

type TtagEMRTRANSPARENTBLT = TEMRTRANSPARENTBLT

type tagEMRTRANSPARENTBLT = TtagEMRTRANSPARENTBLT

type TPEMRTRANSPARENTBLT = uintptr

type PEMRTRANSPARENTBLT = TPEMRTRANSPARENTBLT

type TPOINTFLOAT = struct {
	Fx TFLOAT
	Fy TFLOAT
}

type POINTFLOAT = TPOINTFLOAT

type T_POINTFLOAT = TPOINTFLOAT

type _POINTFLOAT = T_POINTFLOAT

type TPPOINTFLOAT = uintptr

type PPOINTFLOAT = TPPOINTFLOAT

type TGLYPHMETRICSFLOAT = struct {
	FgmfBlackBoxX     TFLOAT
	FgmfBlackBoxY     TFLOAT
	FgmfptGlyphOrigin TPOINTFLOAT
	FgmfCellIncX      TFLOAT
	FgmfCellIncY      TFLOAT
}

type GLYPHMETRICSFLOAT = TGLYPHMETRICSFLOAT

type T_GLYPHMETRICSFLOAT = TGLYPHMETRICSFLOAT

type _GLYPHMETRICSFLOAT = T_GLYPHMETRICSFLOAT

type TPGLYPHMETRICSFLOAT = uintptr

type PGLYPHMETRICSFLOAT = TPGLYPHMETRICSFLOAT

type TLPGLYPHMETRICSFLOAT = uintptr

type LPGLYPHMETRICSFLOAT = TLPGLYPHMETRICSFLOAT

type TLAYERPLANEDESCRIPTOR = struct {
	FnSize           TWORD
	FnVersion        TWORD
	FdwFlags         TDWORD
	FiPixelType      TBYTE
	FcColorBits      TBYTE
	FcRedBits        TBYTE
	FcRedShift       TBYTE
	FcGreenBits      TBYTE
	FcGreenShift     TBYTE
	FcBlueBits       TBYTE
	FcBlueShift      TBYTE
	FcAlphaBits      TBYTE
	FcAlphaShift     TBYTE
	FcAccumBits      TBYTE
	FcAccumRedBits   TBYTE
	FcAccumGreenBits TBYTE
	FcAccumBlueBits  TBYTE
	FcAccumAlphaBits TBYTE
	FcDepthBits      TBYTE
	FcStencilBits    TBYTE
	FcAuxBuffers     TBYTE
	FiLayerPlane     TBYTE
	FbReserved       TBYTE
	FcrTransparent   TCOLORREF
}

type LAYERPLANEDESCRIPTOR = TLAYERPLANEDESCRIPTOR

type TtagLAYERPLANEDESCRIPTOR = TLAYERPLANEDESCRIPTOR

type tagLAYERPLANEDESCRIPTOR = TtagLAYERPLANEDESCRIPTOR

type TPLAYERPLANEDESCRIPTOR = uintptr

type PLAYERPLANEDESCRIPTOR = TPLAYERPLANEDESCRIPTOR

type TLPLAYERPLANEDESCRIPTOR = uintptr

type LPLAYERPLANEDESCRIPTOR = TLPLAYERPLANEDESCRIPTOR

type TWGLSWAP = struct {
	Fhdc     THDC
	FuiFlags TUINT
}

type WGLSWAP = TWGLSWAP

type T_WGLSWAP = TWGLSWAP

type _WGLSWAP = T_WGLSWAP

type TPWGLSWAP = uintptr

type PWGLSWAP = TPWGLSWAP

type TLPWGLSWAP = uintptr

type LPWGLSWAP = TLPWGLSWAP

type THDWP = uintptr

type HDWP = THDWP

type TMENUTEMPLATEA = struct{}

type MENUTEMPLATEA = TMENUTEMPLATEA

type TMENUTEMPLATEW = struct{}

type MENUTEMPLATEW = TMENUTEMPLATEW

type TLPMENUTEMPLATEA = uintptr

type LPMENUTEMPLATEA = TLPMENUTEMPLATEA

type TLPMENUTEMPLATEW = uintptr

type LPMENUTEMPLATEW = TLPMENUTEMPLATEW

type TMENUTEMPLATE = struct{}

type MENUTEMPLATE = TMENUTEMPLATE

type TLPMENUTEMPLATE = uintptr

type LPMENUTEMPLATE = TLPMENUTEMPLATE

type TWNDPROC = uintptr

type WNDPROC = TWNDPROC

type TDLGPROC = uintptr

type DLGPROC = TDLGPROC

type TTIMERPROC = uintptr

type TIMERPROC = TTIMERPROC

type TGRAYSTRINGPROC = uintptr

type GRAYSTRINGPROC = TGRAYSTRINGPROC

type TWNDENUMPROC = uintptr

type WNDENUMPROC = TWNDENUMPROC

type THOOKPROC = uintptr

type HOOKPROC = THOOKPROC

type TSENDASYNCPROC = uintptr

type SENDASYNCPROC = TSENDASYNCPROC

type TPROPENUMPROCA = uintptr

type PROPENUMPROCA = TPROPENUMPROCA

type TPROPENUMPROCW = uintptr

type PROPENUMPROCW = TPROPENUMPROCW

type TPROPENUMPROCEXA = uintptr

type PROPENUMPROCEXA = TPROPENUMPROCEXA

type TPROPENUMPROCEXW = uintptr

type PROPENUMPROCEXW = TPROPENUMPROCEXW

type TEDITWORDBREAKPROCA = uintptr

type EDITWORDBREAKPROCA = TEDITWORDBREAKPROCA

type TEDITWORDBREAKPROCW = uintptr

type EDITWORDBREAKPROCW = TEDITWORDBREAKPROCW

type TDRAWSTATEPROC = uintptr

type DRAWSTATEPROC = TDRAWSTATEPROC

type TPROPENUMPROC = uintptr

type PROPENUMPROC = TPROPENUMPROC

type TPROPENUMPROCEX = uintptr

type PROPENUMPROCEX = TPROPENUMPROCEX

type TEDITWORDBREAKPROC = uintptr

type EDITWORDBREAKPROC = TEDITWORDBREAKPROC

type TNAMEENUMPROCA = uintptr

type NAMEENUMPROCA = TNAMEENUMPROCA

type TNAMEENUMPROCW = uintptr

type NAMEENUMPROCW = TNAMEENUMPROCW

type TWINSTAENUMPROCA = uintptr

type WINSTAENUMPROCA = TWINSTAENUMPROCA

type TWINSTAENUMPROCW = uintptr

type WINSTAENUMPROCW = TWINSTAENUMPROCW

type TDESKTOPENUMPROCA = uintptr

type DESKTOPENUMPROCA = TDESKTOPENUMPROCA

type TDESKTOPENUMPROCW = uintptr

type DESKTOPENUMPROCW = TDESKTOPENUMPROCW

type TWINSTAENUMPROC = uintptr

type WINSTAENUMPROC = TWINSTAENUMPROC

type TDESKTOPENUMPROC = uintptr

type DESKTOPENUMPROC = TDESKTOPENUMPROC

type TCBT_CREATEWNDA = struct {
	Flpcs            uintptr
	FhwndInsertAfter THWND
}

type CBT_CREATEWNDA = TCBT_CREATEWNDA

type TtagCBT_CREATEWNDA = TCBT_CREATEWNDA

type tagCBT_CREATEWNDA = TtagCBT_CREATEWNDA

type TLPCBT_CREATEWNDA = uintptr

type LPCBT_CREATEWNDA = TLPCBT_CREATEWNDA

type TCBT_CREATEWNDW = struct {
	Flpcs            uintptr
	FhwndInsertAfter THWND
}

type CBT_CREATEWNDW = TCBT_CREATEWNDW

type TtagCBT_CREATEWNDW = TCBT_CREATEWNDW

type tagCBT_CREATEWNDW = TtagCBT_CREATEWNDW

type TLPCBT_CREATEWNDW = uintptr

type LPCBT_CREATEWNDW = TLPCBT_CREATEWNDW

type TCBT_CREATEWND = struct {
	Flpcs            uintptr
	FhwndInsertAfter THWND
}

type CBT_CREATEWND = TCBT_CREATEWND

type TLPCBT_CREATEWND = uintptr

type LPCBT_CREATEWND = TLPCBT_CREATEWND

type TCBTACTIVATESTRUCT = struct {
	FfMouse     TWINBOOL
	FhWndActive THWND
}

type CBTACTIVATESTRUCT = TCBTACTIVATESTRUCT

type TtagCBTACTIVATESTRUCT = TCBTACTIVATESTRUCT

type tagCBTACTIVATESTRUCT = TtagCBTACTIVATESTRUCT

type TLPCBTACTIVATESTRUCT = uintptr

type LPCBTACTIVATESTRUCT = TLPCBTACTIVATESTRUCT

type TWTSSESSION_NOTIFICATION = struct {
	FcbSize      TDWORD
	FdwSessionId TDWORD
}

type WTSSESSION_NOTIFICATION = TWTSSESSION_NOTIFICATION

type TtagWTSSESSION_NOTIFICATION = TWTSSESSION_NOTIFICATION

type tagWTSSESSION_NOTIFICATION = TtagWTSSESSION_NOTIFICATION

type TPWTSSESSION_NOTIFICATION = uintptr

type PWTSSESSION_NOTIFICATION = TPWTSSESSION_NOTIFICATION

type TSHELLHOOKINFO = struct {
	Fhwnd THWND
	Frc   TRECT
}

type SHELLHOOKINFO = TSHELLHOOKINFO

type TLPSHELLHOOKINFO = uintptr

type LPSHELLHOOKINFO = TLPSHELLHOOKINFO

type TEVENTMSG = struct {
	Fmessage TUINT
	FparamL  TUINT
	FparamH  TUINT
	Ftime    TDWORD
	Fhwnd    THWND
}

type EVENTMSG = TEVENTMSG

type TtagEVENTMSG = TEVENTMSG

type tagEVENTMSG = TtagEVENTMSG

type TPEVENTMSGMSG = uintptr

type PEVENTMSGMSG = TPEVENTMSGMSG

type TNPEVENTMSGMSG = uintptr

type NPEVENTMSGMSG = TNPEVENTMSGMSG

type TLPEVENTMSGMSG = uintptr

type LPEVENTMSGMSG = TLPEVENTMSGMSG

type TPEVENTMSG = uintptr

type PEVENTMSG = TPEVENTMSG

type TNPEVENTMSG = uintptr

type NPEVENTMSG = TNPEVENTMSG

type TLPEVENTMSG = uintptr

type LPEVENTMSG = TLPEVENTMSG

type TCWPSTRUCT = struct {
	FlParam  TLPARAM
	FwParam  TWPARAM
	Fmessage TUINT
	Fhwnd    THWND
}

type CWPSTRUCT = TCWPSTRUCT

type TtagCWPSTRUCT = TCWPSTRUCT

type tagCWPSTRUCT = TtagCWPSTRUCT

type TPCWPSTRUCT = uintptr

type PCWPSTRUCT = TPCWPSTRUCT

type TNPCWPSTRUCT = uintptr

type NPCWPSTRUCT = TNPCWPSTRUCT

type TLPCWPSTRUCT = uintptr

type LPCWPSTRUCT = TLPCWPSTRUCT

type TCWPRETSTRUCT = struct {
	FlResult TLRESULT
	FlParam  TLPARAM
	FwParam  TWPARAM
	Fmessage TUINT
	Fhwnd    THWND
}

type CWPRETSTRUCT = TCWPRETSTRUCT

type TtagCWPRETSTRUCT = TCWPRETSTRUCT

type tagCWPRETSTRUCT = TtagCWPRETSTRUCT

type TPCWPRETSTRUCT = uintptr

type PCWPRETSTRUCT = TPCWPRETSTRUCT

type TNPCWPRETSTRUCT = uintptr

type NPCWPRETSTRUCT = TNPCWPRETSTRUCT

type TLPCWPRETSTRUCT = uintptr

type LPCWPRETSTRUCT = TLPCWPRETSTRUCT

type TKBDLLHOOKSTRUCT = struct {
	FvkCode      TDWORD
	FscanCode    TDWORD
	Fflags       TDWORD
	Ftime        TDWORD
	FdwExtraInfo TULONG_PTR
}

type KBDLLHOOKSTRUCT = TKBDLLHOOKSTRUCT

type TtagKBDLLHOOKSTRUCT = TKBDLLHOOKSTRUCT

type tagKBDLLHOOKSTRUCT = TtagKBDLLHOOKSTRUCT

type TLPKBDLLHOOKSTRUCT = uintptr

type LPKBDLLHOOKSTRUCT = TLPKBDLLHOOKSTRUCT

type TPKBDLLHOOKSTRUCT = uintptr

type PKBDLLHOOKSTRUCT = TPKBDLLHOOKSTRUCT

type TMSLLHOOKSTRUCT = struct {
	Fpt          TPOINT
	FmouseData   TDWORD
	Fflags       TDWORD
	Ftime        TDWORD
	FdwExtraInfo TULONG_PTR
}

type MSLLHOOKSTRUCT = TMSLLHOOKSTRUCT

type TtagMSLLHOOKSTRUCT = TMSLLHOOKSTRUCT

type tagMSLLHOOKSTRUCT = TtagMSLLHOOKSTRUCT

type TLPMSLLHOOKSTRUCT = uintptr

type LPMSLLHOOKSTRUCT = TLPMSLLHOOKSTRUCT

type TPMSLLHOOKSTRUCT = uintptr

type PMSLLHOOKSTRUCT = TPMSLLHOOKSTRUCT

type TDEBUGHOOKINFO = struct {
	FidThread          TDWORD
	FidThreadInstaller TDWORD
	FlParam            TLPARAM
	FwParam            TWPARAM
	Fcode              int32
}

type DEBUGHOOKINFO = TDEBUGHOOKINFO

type TtagDEBUGHOOKINFO = TDEBUGHOOKINFO

type tagDEBUGHOOKINFO = TtagDEBUGHOOKINFO

type TPDEBUGHOOKINFO = uintptr

type PDEBUGHOOKINFO = TPDEBUGHOOKINFO

type TNPDEBUGHOOKINFO = uintptr

type NPDEBUGHOOKINFO = TNPDEBUGHOOKINFO

type TLPDEBUGHOOKINFO = uintptr

type LPDEBUGHOOKINFO = TLPDEBUGHOOKINFO

type TMOUSEHOOKSTRUCT = struct {
	Fpt           TPOINT
	Fhwnd         THWND
	FwHitTestCode TUINT
	FdwExtraInfo  TULONG_PTR
}

type MOUSEHOOKSTRUCT = TMOUSEHOOKSTRUCT

type TtagMOUSEHOOKSTRUCT = TMOUSEHOOKSTRUCT

type tagMOUSEHOOKSTRUCT = TtagMOUSEHOOKSTRUCT

type TLPMOUSEHOOKSTRUCT = uintptr

type LPMOUSEHOOKSTRUCT = TLPMOUSEHOOKSTRUCT

type TPMOUSEHOOKSTRUCT = uintptr

type PMOUSEHOOKSTRUCT = TPMOUSEHOOKSTRUCT

type TMOUSEHOOKSTRUCTEX = struct {
	F__unnamed TMOUSEHOOKSTRUCT
	FmouseData TDWORD
}

type MOUSEHOOKSTRUCTEX = TMOUSEHOOKSTRUCTEX

type TtagMOUSEHOOKSTRUCTEX = TMOUSEHOOKSTRUCTEX

type tagMOUSEHOOKSTRUCTEX = TtagMOUSEHOOKSTRUCTEX

type TLPMOUSEHOOKSTRUCTEX = uintptr

type LPMOUSEHOOKSTRUCTEX = TLPMOUSEHOOKSTRUCTEX

type TPMOUSEHOOKSTRUCTEX = uintptr

type PMOUSEHOOKSTRUCTEX = TPMOUSEHOOKSTRUCTEX

type THARDWAREHOOKSTRUCT = struct {
	Fhwnd    THWND
	Fmessage TUINT
	FwParam  TWPARAM
	FlParam  TLPARAM
}

type HARDWAREHOOKSTRUCT = THARDWAREHOOKSTRUCT

type TtagHARDWAREHOOKSTRUCT = THARDWAREHOOKSTRUCT

type tagHARDWAREHOOKSTRUCT = TtagHARDWAREHOOKSTRUCT

type TLPHARDWAREHOOKSTRUCT = uintptr

type LPHARDWAREHOOKSTRUCT = TLPHARDWAREHOOKSTRUCT

type TPHARDWAREHOOKSTRUCT = uintptr

type PHARDWAREHOOKSTRUCT = TPHARDWAREHOOKSTRUCT

type TMOUSEMOVEPOINT = struct {
	Fx           int32
	Fy           int32
	Ftime        TDWORD
	FdwExtraInfo TULONG_PTR
}

type MOUSEMOVEPOINT = TMOUSEMOVEPOINT

type TtagMOUSEMOVEPOINT = TMOUSEMOVEPOINT

type tagMOUSEMOVEPOINT = TtagMOUSEMOVEPOINT

type TPMOUSEMOVEPOINT = uintptr

type PMOUSEMOVEPOINT = TPMOUSEMOVEPOINT

type TLPMOUSEMOVEPOINT = uintptr

type LPMOUSEMOVEPOINT = TLPMOUSEMOVEPOINT

type TUSEROBJECTFLAGS = struct {
	FfInherit  TWINBOOL
	FfReserved TWINBOOL
	FdwFlags   TDWORD
}

type USEROBJECTFLAGS = TUSEROBJECTFLAGS

type TtagUSEROBJECTFLAGS = TUSEROBJECTFLAGS

type tagUSEROBJECTFLAGS = TtagUSEROBJECTFLAGS

type TPUSEROBJECTFLAGS = uintptr

type PUSEROBJECTFLAGS = TPUSEROBJECTFLAGS

type TWNDCLASSEXA = struct {
	FcbSize        TUINT
	Fstyle         TUINT
	FlpfnWndProc   TWNDPROC
	FcbClsExtra    int32
	FcbWndExtra    int32
	FhInstance     THINSTANCE
	FhIcon         THICON
	FhCursor       THCURSOR
	FhbrBackground THBRUSH
	FlpszMenuName  TLPCSTR
	FlpszClassName TLPCSTR
	FhIconSm       THICON
}

type WNDCLASSEXA = TWNDCLASSEXA

type TtagWNDCLASSEXA = TWNDCLASSEXA

type tagWNDCLASSEXA = TtagWNDCLASSEXA

type TPWNDCLASSEXA = uintptr

type PWNDCLASSEXA = TPWNDCLASSEXA

type TNPWNDCLASSEXA = uintptr

type NPWNDCLASSEXA = TNPWNDCLASSEXA

type TLPWNDCLASSEXA = uintptr

type LPWNDCLASSEXA = TLPWNDCLASSEXA

type TWNDCLASSEXW = struct {
	FcbSize        TUINT
	Fstyle         TUINT
	FlpfnWndProc   TWNDPROC
	FcbClsExtra    int32
	FcbWndExtra    int32
	FhInstance     THINSTANCE
	FhIcon         THICON
	FhCursor       THCURSOR
	FhbrBackground THBRUSH
	FlpszMenuName  TLPCWSTR
	FlpszClassName TLPCWSTR
	FhIconSm       THICON
}

type WNDCLASSEXW = TWNDCLASSEXW

type TtagWNDCLASSEXW = TWNDCLASSEXW

type tagWNDCLASSEXW = TtagWNDCLASSEXW

type TPWNDCLASSEXW = uintptr

type PWNDCLASSEXW = TPWNDCLASSEXW

type TNPWNDCLASSEXW = uintptr

type NPWNDCLASSEXW = TNPWNDCLASSEXW

type TLPWNDCLASSEXW = uintptr

type LPWNDCLASSEXW = TLPWNDCLASSEXW

type TWNDCLASSEX = struct {
	FcbSize        TUINT
	Fstyle         TUINT
	FlpfnWndProc   TWNDPROC
	FcbClsExtra    int32
	FcbWndExtra    int32
	FhInstance     THINSTANCE
	FhIcon         THICON
	FhCursor       THCURSOR
	FhbrBackground THBRUSH
	FlpszMenuName  TLPCSTR
	FlpszClassName TLPCSTR
	FhIconSm       THICON
}

type WNDCLASSEX = TWNDCLASSEX

type TPWNDCLASSEX = uintptr

type PWNDCLASSEX = TPWNDCLASSEX

type TNPWNDCLASSEX = uintptr

type NPWNDCLASSEX = TNPWNDCLASSEX

type TLPWNDCLASSEX = uintptr

type LPWNDCLASSEX = TLPWNDCLASSEX

type TWNDCLASSA = struct {
	Fstyle         TUINT
	FlpfnWndProc   TWNDPROC
	FcbClsExtra    int32
	FcbWndExtra    int32
	FhInstance     THINSTANCE
	FhIcon         THICON
	FhCursor       THCURSOR
	FhbrBackground THBRUSH
	FlpszMenuName  TLPCSTR
	FlpszClassName TLPCSTR
}

type WNDCLASSA = TWNDCLASSA

type TtagWNDCLASSA = TWNDCLASSA

type tagWNDCLASSA = TtagWNDCLASSA

type TPWNDCLASSA = uintptr

type PWNDCLASSA = TPWNDCLASSA

type TNPWNDCLASSA = uintptr

type NPWNDCLASSA = TNPWNDCLASSA

type TLPWNDCLASSA = uintptr

type LPWNDCLASSA = TLPWNDCLASSA

type TWNDCLASSW = struct {
	Fstyle         TUINT
	FlpfnWndProc   TWNDPROC
	FcbClsExtra    int32
	FcbWndExtra    int32
	FhInstance     THINSTANCE
	FhIcon         THICON
	FhCursor       THCURSOR
	FhbrBackground THBRUSH
	FlpszMenuName  TLPCWSTR
	FlpszClassName TLPCWSTR
}

type WNDCLASSW = TWNDCLASSW

type TtagWNDCLASSW = TWNDCLASSW

type tagWNDCLASSW = TtagWNDCLASSW

type TPWNDCLASSW = uintptr

type PWNDCLASSW = TPWNDCLASSW

type TNPWNDCLASSW = uintptr

type NPWNDCLASSW = TNPWNDCLASSW

type TLPWNDCLASSW = uintptr

type LPWNDCLASSW = TLPWNDCLASSW

type TWNDCLASS = struct {
	Fstyle         TUINT
	FlpfnWndProc   TWNDPROC
	FcbClsExtra    int32
	FcbWndExtra    int32
	FhInstance     THINSTANCE
	FhIcon         THICON
	FhCursor       THCURSOR
	FhbrBackground THBRUSH
	FlpszMenuName  TLPCSTR
	FlpszClassName TLPCSTR
}

type WNDCLASS = TWNDCLASS

type TPWNDCLASS = uintptr

type PWNDCLASS = TPWNDCLASS

type TNPWNDCLASS = uintptr

type NPWNDCLASS = TNPWNDCLASS

type TLPWNDCLASS = uintptr

type LPWNDCLASS = TLPWNDCLASS

type TMSG = struct {
	Fhwnd    THWND
	Fmessage TUINT
	FwParam  TWPARAM
	FlParam  TLPARAM
	Ftime    TDWORD
	Fpt      TPOINT
}

type MSG = TMSG

type TtagMSG = TMSG

type tagMSG = TtagMSG

type TPMSG = uintptr

type PMSG = TPMSG

type TNPMSG = uintptr

type NPMSG = TNPMSG

type TLPMSG = uintptr

type LPMSG = TLPMSG

type TMINMAXINFO = struct {
	FptReserved     TPOINT
	FptMaxSize      TPOINT
	FptMaxPosition  TPOINT
	FptMinTrackSize TPOINT
	FptMaxTrackSize TPOINT
}

type MINMAXINFO = TMINMAXINFO

type TtagMINMAXINFO = TMINMAXINFO

type tagMINMAXINFO = TtagMINMAXINFO

type TPMINMAXINFO = uintptr

type PMINMAXINFO = TPMINMAXINFO

type TLPMINMAXINFO = uintptr

type LPMINMAXINFO = TLPMINMAXINFO

type TCOPYDATASTRUCT = struct {
	FdwData TULONG_PTR
	FcbData TDWORD
	FlpData TPVOID
}

type COPYDATASTRUCT = TCOPYDATASTRUCT

type TtagCOPYDATASTRUCT = TCOPYDATASTRUCT

type tagCOPYDATASTRUCT = TtagCOPYDATASTRUCT

type TPCOPYDATASTRUCT = uintptr

type PCOPYDATASTRUCT = TPCOPYDATASTRUCT

type TMDINEXTMENU = struct {
	FhmenuIn   THMENU
	FhmenuNext THMENU
	FhwndNext  THWND
}

type MDINEXTMENU = TMDINEXTMENU

type TtagMDINEXTMENU = TMDINEXTMENU

type tagMDINEXTMENU = TtagMDINEXTMENU

type TPMDINEXTMENU = uintptr

type PMDINEXTMENU = TPMDINEXTMENU

type TLPMDINEXTMENU = uintptr

type LPMDINEXTMENU = TLPMDINEXTMENU

type TPOWERBROADCAST_SETTING = struct {
	FPowerSetting TGUID
	FDataLength   TDWORD
	FData         [1]TUCHAR
}

type POWERBROADCAST_SETTING = TPOWERBROADCAST_SETTING

type TPPOWERBROADCAST_SETTING = uintptr

type PPOWERBROADCAST_SETTING = TPPOWERBROADCAST_SETTING

type TWINDOWPOS = struct {
	Fhwnd            THWND
	FhwndInsertAfter THWND
	Fx               int32
	Fy               int32
	Fcx              int32
	Fcy              int32
	Fflags           TUINT
}

type WINDOWPOS = TWINDOWPOS

type TtagWINDOWPOS = TWINDOWPOS

type tagWINDOWPOS = TtagWINDOWPOS

type TLPWINDOWPOS = uintptr

type LPWINDOWPOS = TLPWINDOWPOS

type TPWINDOWPOS = uintptr

type PWINDOWPOS = TPWINDOWPOS

type TNCCALCSIZE_PARAMS = struct {
	Frgrc  [3]TRECT
	Flppos TPWINDOWPOS
}

type NCCALCSIZE_PARAMS = TNCCALCSIZE_PARAMS

type TtagNCCALCSIZE_PARAMS = TNCCALCSIZE_PARAMS

type tagNCCALCSIZE_PARAMS = TtagNCCALCSIZE_PARAMS

type TLPNCCALCSIZE_PARAMS = uintptr

type LPNCCALCSIZE_PARAMS = TLPNCCALCSIZE_PARAMS

type TTRACKMOUSEEVENT = struct {
	FcbSize      TDWORD
	FdwFlags     TDWORD
	FhwndTrack   THWND
	FdwHoverTime TDWORD
}

type TRACKMOUSEEVENT = TTRACKMOUSEEVENT

type TtagTRACKMOUSEEVENT = TTRACKMOUSEEVENT

type tagTRACKMOUSEEVENT = TtagTRACKMOUSEEVENT

type TLPTRACKMOUSEEVENT = uintptr

type LPTRACKMOUSEEVENT = TLPTRACKMOUSEEVENT

type TACCEL = struct {
	FfVirt TBYTE
	Fkey   TWORD
	Fcmd   TWORD
}

type ACCEL = TACCEL

type TtagACCEL = TACCEL

type tagACCEL = TtagACCEL

type TLPACCEL = uintptr

type LPACCEL = TLPACCEL

type TPAINTSTRUCT = struct {
	Fhdc         THDC
	FfErase      TWINBOOL
	FrcPaint     TRECT
	FfRestore    TWINBOOL
	FfIncUpdate  TWINBOOL
	FrgbReserved [32]TBYTE
}

type PAINTSTRUCT = TPAINTSTRUCT

type TtagPAINTSTRUCT = TPAINTSTRUCT

type tagPAINTSTRUCT = TtagPAINTSTRUCT

type TPPAINTSTRUCT = uintptr

type PPAINTSTRUCT = TPPAINTSTRUCT

type TNPPAINTSTRUCT = uintptr

type NPPAINTSTRUCT = TNPPAINTSTRUCT

type TLPPAINTSTRUCT = uintptr

type LPPAINTSTRUCT = TLPPAINTSTRUCT

type TCREATESTRUCTA = struct {
	FlpCreateParams TLPVOID
	FhInstance      THINSTANCE
	FhMenu          THMENU
	FhwndParent     THWND
	Fcy             int32
	Fcx             int32
	Fy              int32
	Fx              int32
	Fstyle          TLONG
	FlpszName       TLPCSTR
	FlpszClass      TLPCSTR
	FdwExStyle      TDWORD
}

type CREATESTRUCTA = TCREATESTRUCTA

type TtagCREATESTRUCTA = TCREATESTRUCTA

type tagCREATESTRUCTA = TtagCREATESTRUCTA

type TLPCREATESTRUCTA = uintptr

type LPCREATESTRUCTA = TLPCREATESTRUCTA

type TCREATESTRUCTW = struct {
	FlpCreateParams TLPVOID
	FhInstance      THINSTANCE
	FhMenu          THMENU
	FhwndParent     THWND
	Fcy             int32
	Fcx             int32
	Fy              int32
	Fx              int32
	Fstyle          TLONG
	FlpszName       TLPCWSTR
	FlpszClass      TLPCWSTR
	FdwExStyle      TDWORD
}

type CREATESTRUCTW = TCREATESTRUCTW

type TtagCREATESTRUCTW = TCREATESTRUCTW

type tagCREATESTRUCTW = TtagCREATESTRUCTW

type TLPCREATESTRUCTW = uintptr

type LPCREATESTRUCTW = TLPCREATESTRUCTW

type TCREATESTRUCT = struct {
	FlpCreateParams TLPVOID
	FhInstance      THINSTANCE
	FhMenu          THMENU
	FhwndParent     THWND
	Fcy             int32
	Fcx             int32
	Fy              int32
	Fx              int32
	Fstyle          TLONG
	FlpszName       TLPCSTR
	FlpszClass      TLPCSTR
	FdwExStyle      TDWORD
}

type CREATESTRUCT = TCREATESTRUCT

type TLPCREATESTRUCT = uintptr

type LPCREATESTRUCT = TLPCREATESTRUCT

type TWINDOWPLACEMENT = struct {
	Flength           TUINT
	Fflags            TUINT
	FshowCmd          TUINT
	FptMinPosition    TPOINT
	FptMaxPosition    TPOINT
	FrcNormalPosition TRECT
}

type WINDOWPLACEMENT = TWINDOWPLACEMENT

type TtagWINDOWPLACEMENT = TWINDOWPLACEMENT

type tagWINDOWPLACEMENT = TtagWINDOWPLACEMENT

type TPWINDOWPLACEMENT = uintptr

type PWINDOWPLACEMENT = TPWINDOWPLACEMENT

type TLPWINDOWPLACEMENT = uintptr

type LPWINDOWPLACEMENT = TLPWINDOWPLACEMENT

type TNMHDR = struct {
	FhwndFrom THWND
	FidFrom   TUINT_PTR
	Fcode     TUINT
}

type NMHDR = TNMHDR

type TtagNMHDR = TNMHDR

type tagNMHDR = TtagNMHDR

type TLPNMHDR = uintptr

type LPNMHDR = TLPNMHDR

type TSTYLESTRUCT = struct {
	FstyleOld TDWORD
	FstyleNew TDWORD
}

type STYLESTRUCT = TSTYLESTRUCT

type TtagSTYLESTRUCT = TSTYLESTRUCT

type tagSTYLESTRUCT = TtagSTYLESTRUCT

type TLPSTYLESTRUCT = uintptr

type LPSTYLESTRUCT = TLPSTYLESTRUCT

type TMEASUREITEMSTRUCT = struct {
	FCtlType    TUINT
	FCtlID      TUINT
	FitemID     TUINT
	FitemWidth  TUINT
	FitemHeight TUINT
	FitemData   TULONG_PTR
}

type MEASUREITEMSTRUCT = TMEASUREITEMSTRUCT

type TtagMEASUREITEMSTRUCT = TMEASUREITEMSTRUCT

type tagMEASUREITEMSTRUCT = TtagMEASUREITEMSTRUCT

type TPMEASUREITEMSTRUCT = uintptr

type PMEASUREITEMSTRUCT = TPMEASUREITEMSTRUCT

type TLPMEASUREITEMSTRUCT = uintptr

type LPMEASUREITEMSTRUCT = TLPMEASUREITEMSTRUCT

type TDRAWITEMSTRUCT = struct {
	FCtlType    TUINT
	FCtlID      TUINT
	FitemID     TUINT
	FitemAction TUINT
	FitemState  TUINT
	FhwndItem   THWND
	FhDC        THDC
	FrcItem     TRECT
	FitemData   TULONG_PTR
}

type DRAWITEMSTRUCT = TDRAWITEMSTRUCT

type TtagDRAWITEMSTRUCT = TDRAWITEMSTRUCT

type tagDRAWITEMSTRUCT = TtagDRAWITEMSTRUCT

type TPDRAWITEMSTRUCT = uintptr

type PDRAWITEMSTRUCT = TPDRAWITEMSTRUCT

type TLPDRAWITEMSTRUCT = uintptr

type LPDRAWITEMSTRUCT = TLPDRAWITEMSTRUCT

type TDELETEITEMSTRUCT = struct {
	FCtlType  TUINT
	FCtlID    TUINT
	FitemID   TUINT
	FhwndItem THWND
	FitemData TULONG_PTR
}

type DELETEITEMSTRUCT = TDELETEITEMSTRUCT

type TtagDELETEITEMSTRUCT = TDELETEITEMSTRUCT

type tagDELETEITEMSTRUCT = TtagDELETEITEMSTRUCT

type TPDELETEITEMSTRUCT = uintptr

type PDELETEITEMSTRUCT = TPDELETEITEMSTRUCT

type TLPDELETEITEMSTRUCT = uintptr

type LPDELETEITEMSTRUCT = TLPDELETEITEMSTRUCT

type TCOMPAREITEMSTRUCT = struct {
	FCtlType    TUINT
	FCtlID      TUINT
	FhwndItem   THWND
	FitemID1    TUINT
	FitemData1  TULONG_PTR
	FitemID2    TUINT
	FitemData2  TULONG_PTR
	FdwLocaleId TDWORD
}

type COMPAREITEMSTRUCT = TCOMPAREITEMSTRUCT

type TtagCOMPAREITEMSTRUCT = TCOMPAREITEMSTRUCT

type tagCOMPAREITEMSTRUCT = TtagCOMPAREITEMSTRUCT

type TPCOMPAREITEMSTRUCT = uintptr

type PCOMPAREITEMSTRUCT = TPCOMPAREITEMSTRUCT

type TLPCOMPAREITEMSTRUCT = uintptr

type LPCOMPAREITEMSTRUCT = TLPCOMPAREITEMSTRUCT

type TBSMINFO = struct {
	FcbSize TUINT
	Fhdesk  THDESK
	Fhwnd   THWND
	Fluid   TLUID
}

type BSMINFO = TBSMINFO

type TPBSMINFO = uintptr

type PBSMINFO = TPBSMINFO

type THDEVNOTIFY = uintptr

type HDEVNOTIFY = THDEVNOTIFY

type TPHDEVNOTIFY = uintptr

type PHDEVNOTIFY = TPHDEVNOTIFY

type THPOWERNOTIFY = uintptr

type HPOWERNOTIFY = THPOWERNOTIFY

type TPHPOWERNOTIFY = uintptr

type PHPOWERNOTIFY = TPHPOWERNOTIFY

type TPREGISTERCLASSNAMEW = uintptr

type PREGISTERCLASSNAMEW = TPREGISTERCLASSNAMEW

type TUPDATELAYEREDWINDOWINFO = struct {
	FcbSize   TDWORD
	FhdcDst   THDC
	FpptDst   uintptr
	Fpsize    uintptr
	FhdcSrc   THDC
	FpptSrc   uintptr
	FcrKey    TCOLORREF
	Fpblend   uintptr
	FdwFlags  TDWORD
	FprcDirty uintptr
}

type UPDATELAYEREDWINDOWINFO = TUPDATELAYEREDWINDOWINFO

type TtagUPDATELAYEREDWINDOWINFO = TUPDATELAYEREDWINDOWINFO

type tagUPDATELAYEREDWINDOWINFO = TtagUPDATELAYEREDWINDOWINFO

type TPUPDATELAYEREDWINDOWINFO = uintptr

type PUPDATELAYEREDWINDOWINFO = TPUPDATELAYEREDWINDOWINFO

type TFLASHWINFO = struct {
	FcbSize    TUINT
	Fhwnd      THWND
	FdwFlags   TDWORD
	FuCount    TUINT
	FdwTimeout TDWORD
}

type FLASHWINFO = TFLASHWINFO

type TPFLASHWINFO = uintptr

type PFLASHWINFO = TPFLASHWINFO

type TDLGTEMPLATE = struct {
	Fstyle           TDWORD
	FdwExtendedStyle TDWORD
	Fcdit            TWORD
	Fx               int16
	Fy               int16
	Fcx              int16
	Fcy              int16
}

type DLGTEMPLATE = TDLGTEMPLATE

type TLPDLGTEMPLATEA = uintptr

type LPDLGTEMPLATEA = TLPDLGTEMPLATEA

type TLPDLGTEMPLATEW = uintptr

type LPDLGTEMPLATEW = TLPDLGTEMPLATEW

type TLPDLGTEMPLATE = uintptr

type LPDLGTEMPLATE = TLPDLGTEMPLATE

type TLPCDLGTEMPLATEA = uintptr

type LPCDLGTEMPLATEA = TLPCDLGTEMPLATEA

type TLPCDLGTEMPLATEW = uintptr

type LPCDLGTEMPLATEW = TLPCDLGTEMPLATEW

type TLPCDLGTEMPLATE = uintptr

type LPCDLGTEMPLATE = TLPCDLGTEMPLATE

type TDLGITEMTEMPLATE = struct {
	Fstyle           TDWORD
	FdwExtendedStyle TDWORD
	Fx               int16
	Fy               int16
	Fcx              int16
	Fcy              int16
	Fid              TWORD
}

type DLGITEMTEMPLATE = TDLGITEMTEMPLATE

type TPDLGITEMTEMPLATEA = uintptr

type PDLGITEMTEMPLATEA = TPDLGITEMTEMPLATEA

type TPDLGITEMTEMPLATEW = uintptr

type PDLGITEMTEMPLATEW = TPDLGITEMTEMPLATEW

type TPDLGITEMTEMPLATE = uintptr

type PDLGITEMTEMPLATE = TPDLGITEMTEMPLATE

type TLPDLGITEMTEMPLATEA = uintptr

type LPDLGITEMTEMPLATEA = TLPDLGITEMTEMPLATEA

type TLPDLGITEMTEMPLATEW = uintptr

type LPDLGITEMTEMPLATEW = TLPDLGITEMTEMPLATEW

type TLPDLGITEMTEMPLATE = uintptr

type LPDLGITEMTEMPLATE = TLPDLGITEMTEMPLATE

type TDIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = int32

type DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = TDIALOG_CONTROL_DPI_CHANGE_BEHAVIORS

type _DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = int32

const _DCDC_DEFAULT = 0
const _DCDC_DISABLE_FONT_UPDATE = 1
const _DCDC_DISABLE_RELAYOUT = 2

type TDIALOG_DPI_CHANGE_BEHAVIORS = int32

type DIALOG_DPI_CHANGE_BEHAVIORS = TDIALOG_DPI_CHANGE_BEHAVIORS

type _DIALOG_DPI_CHANGE_BEHAVIORS = int32

const _DDC_DEFAULT = 0
const _DDC_DISABLE_ALL = 1
const _DDC_DISABLE_RESIZE = 2
const _DDC_DISABLE_CONTROL_RELAYOUT = 4

type TMOUSEINPUT = struct {
	Fdx          TLONG
	Fdy          TLONG
	FmouseData   TDWORD
	FdwFlags     TDWORD
	Ftime        TDWORD
	FdwExtraInfo TULONG_PTR
}

type MOUSEINPUT = TMOUSEINPUT

type TtagMOUSEINPUT = TMOUSEINPUT

type tagMOUSEINPUT = TtagMOUSEINPUT

type TPMOUSEINPUT = uintptr

type PMOUSEINPUT = TPMOUSEINPUT

type TLPMOUSEINPUT = uintptr

type LPMOUSEINPUT = TLPMOUSEINPUT

type TKEYBDINPUT = struct {
	FwVk         TWORD
	FwScan       TWORD
	FdwFlags     TDWORD
	Ftime        TDWORD
	FdwExtraInfo TULONG_PTR
}

type KEYBDINPUT = TKEYBDINPUT

type TtagKEYBDINPUT = TKEYBDINPUT

type tagKEYBDINPUT = TtagKEYBDINPUT

type TPKEYBDINPUT = uintptr

type PKEYBDINPUT = TPKEYBDINPUT

type TLPKEYBDINPUT = uintptr

type LPKEYBDINPUT = TLPKEYBDINPUT

type THARDWAREINPUT = struct {
	FuMsg    TDWORD
	FwParamL TWORD
	FwParamH TWORD
}

type HARDWAREINPUT = THARDWAREINPUT

type TtagHARDWAREINPUT = THARDWAREINPUT

type tagHARDWAREINPUT = TtagHARDWAREINPUT

type TPHARDWAREINPUT = uintptr

type PHARDWAREINPUT = TPHARDWAREINPUT

type TLPHARDWAREINPUT = uintptr

type LPHARDWAREINPUT = TLPHARDWAREINPUT

type TINPUT = struct {
	Ftype1     TDWORD
	F__ccgo1_4 struct {
		Fki [0]TKEYBDINPUT
		Fhi [0]THARDWAREINPUT
		Fmi TMOUSEINPUT
	}
}

type INPUT = TINPUT

type TtagINPUT = TINPUT

type tagINPUT = TtagINPUT

type TPINPUT = uintptr

type PINPUT = TPINPUT

type TLPINPUT = uintptr

type LPINPUT = TLPINPUT

type THTOUCHINPUT__ = struct {
	Funused int32
}

type HTOUCHINPUT__ = THTOUCHINPUT__

type THTOUCHINPUT = uintptr

type HTOUCHINPUT = THTOUCHINPUT

type TTOUCHINPUT = struct {
	Fx           TLONG
	Fy           TLONG
	FhSource     THANDLE
	FdwID        TDWORD
	FdwFlags     TDWORD
	FdwMask      TDWORD
	FdwTime      TDWORD
	FdwExtraInfo TULONG_PTR
	FcxContact   TDWORD
	FcyContact   TDWORD
}

type TOUCHINPUT = TTOUCHINPUT

type TtagTOUCHINPUT = TTOUCHINPUT

type tagTOUCHINPUT = TtagTOUCHINPUT

type TPTOUCHINPUT = uintptr

type PTOUCHINPUT = TPTOUCHINPUT

type TPCTOUCHINPUT = uintptr

type PCTOUCHINPUT = TPCTOUCHINPUT

type TPOINTER_INPUT_TYPE = uint32

type POINTER_INPUT_TYPE = TPOINTER_INPUT_TYPE

type TPOINTER_FLAGS = uint32

type POINTER_FLAGS = TPOINTER_FLAGS

type TTOUCH_FLAGS = uint32

type TOUCH_FLAGS = TTOUCH_FLAGS

type TTOUCH_MASK = uint32

type TOUCH_MASK = TTOUCH_MASK

type TPEN_FLAGS = uint32

type PEN_FLAGS = TPEN_FLAGS

type TPEN_MASK = uint32

type PEN_MASK = TPEN_MASK

type _tagPOINTER_INPUT_TYPE = int32

const _PT_POINTER = 1
const _PT_TOUCH = 2
const _PT_PEN = 3
const _PT_MOUSE = 4
const _PT_TOUCHPAD = 5

type TFEEDBACK_TYPE = uint32

type FEEDBACK_TYPE = TFEEDBACK_TYPE

type _tagFEEDBACK_TYPE = uint32

const _FEEDBACK_TOUCH_CONTACTVISUALIZATION = 1
const _FEEDBACK_PEN_BARRELVISUALIZATION = 2
const _FEEDBACK_PEN_TAP = 3
const _FEEDBACK_PEN_DOUBLETAP = 4
const _FEEDBACK_PEN_PRESSANDHOLD = 5
const _FEEDBACK_PEN_RIGHTTAP = 6
const _FEEDBACK_TOUCH_TAP = 7
const _FEEDBACK_TOUCH_DOUBLETAP = 8
const _FEEDBACK_TOUCH_PRESSANDHOLD = 9
const _FEEDBACK_TOUCH_RIGHTTAP = 10
const _FEEDBACK_GESTURE_PRESSANDTAP = 11
const _FEEDBACK_MAX = 4294967295

type TPOINTER_BUTTON_CHANGE_TYPE = int32

type POINTER_BUTTON_CHANGE_TYPE = TPOINTER_BUTTON_CHANGE_TYPE

type _tagPOINTER_BUTTON_CHANGE_TYPE = int32

const _POINTER_CHANGE_NONE = 0
const _POINTER_CHANGE_FIRSTBUTTON_DOWN = 1
const _POINTER_CHANGE_FIRSTBUTTON_UP = 2
const _POINTER_CHANGE_SECONDBUTTON_DOWN = 3
const _POINTER_CHANGE_SECONDBUTTON_UP = 4
const _POINTER_CHANGE_THIRDBUTTON_DOWN = 5
const _POINTER_CHANGE_THIRDBUTTON_UP = 6
const _POINTER_CHANGE_FOURTHBUTTON_DOWN = 7
const _POINTER_CHANGE_FOURTHBUTTON_UP = 8
const _POINTER_CHANGE_FIFTHBUTTON_DOWN = 9
const _POINTER_CHANGE_FIFTHBUTTON_UP = 10

type TPOINTER_INFO = struct {
	F__ccgo_align          [0]uint32
	FpointerType           TPOINTER_INPUT_TYPE
	FpointerId             TUINT32
	FframeId               TUINT32
	FpointerFlags          TPOINTER_FLAGS
	FsourceDevice          THANDLE
	FhwndTarget            THWND
	FptPixelLocation       TPOINT
	FptHimetricLocation    TPOINT
	FptPixelLocationRaw    TPOINT
	FptHimetricLocationRaw TPOINT
	FdwTime                TDWORD
	FhistoryCount          TUINT32
	FInputData             TINT32
	FdwKeyStates           TDWORD
	FPerformanceCount      TUINT64
	FButtonChangeType      TPOINTER_BUTTON_CHANGE_TYPE
	F__ccgo_pad16          [4]byte
}

type POINTER_INFO = TPOINTER_INFO

type TtagPOINTER_INFO = TPOINTER_INFO

type tagPOINTER_INFO = TtagPOINTER_INFO

type TPOINTER_TOUCH_INFO = struct {
	F__ccgo_align [0]uint32
	FpointerInfo  TPOINTER_INFO
	FtouchFlags   TTOUCH_FLAGS
	FtouchMask    TTOUCH_MASK
	FrcContact    TRECT
	FrcContactRaw TRECT
	Forientation  TUINT32
	Fpressure     TUINT32
}

type POINTER_TOUCH_INFO = TPOINTER_TOUCH_INFO

type TtagPOINTER_TOUCH_INFO = TPOINTER_TOUCH_INFO

type tagPOINTER_TOUCH_INFO = TtagPOINTER_TOUCH_INFO

type TPOINTER_PEN_INFO = struct {
	F__ccgo_align [0]uint32
	FpointerInfo  TPOINTER_INFO
	FpenFlags     TPEN_FLAGS
	FpenMask      TPEN_MASK
	Fpressure     TUINT32
	Frotation     TUINT32
	FtiltX        TINT32
	FtiltY        TINT32
}

type POINTER_PEN_INFO = TPOINTER_PEN_INFO

type TtagPOINTER_PEN_INFO = TPOINTER_PEN_INFO

type tagPOINTER_PEN_INFO = TtagPOINTER_PEN_INFO

type TPOINTER_FEEDBACK_MODE = int32

type POINTER_FEEDBACK_MODE = TPOINTER_FEEDBACK_MODE

const _POINTER_FEEDBACK_DEFAULT = 1
const _POINTER_FEEDBACK_INDIRECT = 2
const _POINTER_FEEDBACK_NONE = 3

type TUSAGE_PROPERTIES = struct {
	Flevel           TUSHORT
	Fpage            TUSHORT
	Fusage           TUSHORT
	FlogicalMinimum  TINT32
	FlogicalMaximum  TINT32
	Funit            TUSHORT
	Fexponent        TUSHORT
	Fcount           TBYTE
	FphysicalMinimum TINT32
	FphysicalMaximum TINT32
}

type USAGE_PROPERTIES = TUSAGE_PROPERTIES

type TtagUSAGE_PROPERTIES = TUSAGE_PROPERTIES

type tagUSAGE_PROPERTIES = TtagUSAGE_PROPERTIES

type TPUSAGE_PROPERTIES = uintptr

type PUSAGE_PROPERTIES = TPUSAGE_PROPERTIES

type TPOINTER_TYPE_INFO = struct {
	F__ccgo_align  [0]uint32
	Ftype1         TPOINTER_INPUT_TYPE
	F__ccgo_align1 [4]byte
	F__ccgo1_8     struct {
		F__ccgo_align [0]uint32
		FpenInfo      [0]TPOINTER_PEN_INFO
		FtouchInfo    TPOINTER_TOUCH_INFO
	}
}

type POINTER_TYPE_INFO = TPOINTER_TYPE_INFO

type TtagPOINTER_TYPE_INFO = TPOINTER_TYPE_INFO

type tagPOINTER_TYPE_INFO = TtagPOINTER_TYPE_INFO

type TPPOINTER_TYPE_INFO = uintptr

type PPOINTER_TYPE_INFO = TPPOINTER_TYPE_INFO

type TINPUT_INJECTION_VALUE = struct {
	Fpage  TUSHORT
	Fusage TUSHORT
	Fvalue TINT32
	Findex TUSHORT
}

type INPUT_INJECTION_VALUE = TINPUT_INJECTION_VALUE

type TtagINPUT_INJECTION_VALUE = TINPUT_INJECTION_VALUE

type tagINPUT_INJECTION_VALUE = TtagINPUT_INJECTION_VALUE

type TPINPUT_INJECTION_VALUE = uintptr

type PINPUT_INJECTION_VALUE = TPINPUT_INJECTION_VALUE

type TTOUCH_HIT_TESTING_PROXIMITY_EVALUATION = struct {
	Fscore         TUINT16
	FadjustedPoint TPOINT
}

type TOUCH_HIT_TESTING_PROXIMITY_EVALUATION = TTOUCH_HIT_TESTING_PROXIMITY_EVALUATION

type TtagTOUCH_HIT_TESTING_PROXIMITY_EVALUATION = TTOUCH_HIT_TESTING_PROXIMITY_EVALUATION

type tagTOUCH_HIT_TESTING_PROXIMITY_EVALUATION = TtagTOUCH_HIT_TESTING_PROXIMITY_EVALUATION

type TPTOUCH_HIT_TESTING_PROXIMITY_EVALUATION = uintptr

type PTOUCH_HIT_TESTING_PROXIMITY_EVALUATION = TPTOUCH_HIT_TESTING_PROXIMITY_EVALUATION

type TTOUCH_HIT_TESTING_INPUT = struct {
	FpointerId              TUINT32
	Fpoint                  TPOINT
	FboundingBox            TRECT
	FnonOccludedBoundingBox TRECT
	Forientation            TUINT32
}

type TOUCH_HIT_TESTING_INPUT = TTOUCH_HIT_TESTING_INPUT

type TtagTOUCH_HIT_TESTING_INPUT = TTOUCH_HIT_TESTING_INPUT

type tagTOUCH_HIT_TESTING_INPUT = TtagTOUCH_HIT_TESTING_INPUT

type TPTOUCH_HIT_TESTING_INPUT = uintptr

type PTOUCH_HIT_TESTING_INPUT = TPTOUCH_HIT_TESTING_INPUT

type TLASTINPUTINFO = struct {
	FcbSize TUINT
	FdwTime TDWORD
}

type LASTINPUTINFO = TLASTINPUTINFO

type TtagLASTINPUTINFO = TLASTINPUTINFO

type tagLASTINPUTINFO = TtagLASTINPUTINFO

type TPLASTINPUTINFO = uintptr

type PLASTINPUTINFO = TPLASTINPUTINFO

type TTPMPARAMS = struct {
	FcbSize    TUINT
	FrcExclude TRECT
}

type TPMPARAMS = TTPMPARAMS

type TtagTPMPARAMS = TTPMPARAMS

type tagTPMPARAMS = TtagTPMPARAMS

type TMENUINFO = struct {
	FcbSize          TDWORD
	FfMask           TDWORD
	FdwStyle         TDWORD
	FcyMax           TUINT
	FhbrBack         THBRUSH
	FdwContextHelpID TDWORD
	FdwMenuData      TULONG_PTR
}

type MENUINFO = TMENUINFO

type TtagMENUINFO = TMENUINFO

type tagMENUINFO = TtagMENUINFO

type TLPMENUINFO = uintptr

type LPMENUINFO = TLPMENUINFO

type TLPTPMPARAMS = uintptr

type LPTPMPARAMS = TLPTPMPARAMS

type TLPCMENUINFO = uintptr

type LPCMENUINFO = TLPCMENUINFO

type TMENUGETOBJECTINFO = struct {
	FdwFlags TDWORD
	FuPos    TUINT
	Fhmenu   THMENU
	Friid    TPVOID
	FpvObj   TPVOID
}

type MENUGETOBJECTINFO = TMENUGETOBJECTINFO

type TtagMENUGETOBJECTINFO = TMENUGETOBJECTINFO

type tagMENUGETOBJECTINFO = TtagMENUGETOBJECTINFO

type TPMENUGETOBJECTINFO = uintptr

type PMENUGETOBJECTINFO = TPMENUGETOBJECTINFO

type TMENUITEMINFOA = struct {
	FcbSize        TUINT
	FfMask         TUINT
	FfType         TUINT
	FfState        TUINT
	FwID           TUINT
	FhSubMenu      THMENU
	FhbmpChecked   THBITMAP
	FhbmpUnchecked THBITMAP
	FdwItemData    TULONG_PTR
	FdwTypeData    TLPSTR
	Fcch           TUINT
	FhbmpItem      THBITMAP
}

type MENUITEMINFOA = TMENUITEMINFOA

type TtagMENUITEMINFOA = TMENUITEMINFOA

type tagMENUITEMINFOA = TtagMENUITEMINFOA

type TLPMENUITEMINFOA = uintptr

type LPMENUITEMINFOA = TLPMENUITEMINFOA

type TMENUITEMINFOW = struct {
	FcbSize        TUINT
	FfMask         TUINT
	FfType         TUINT
	FfState        TUINT
	FwID           TUINT
	FhSubMenu      THMENU
	FhbmpChecked   THBITMAP
	FhbmpUnchecked THBITMAP
	FdwItemData    TULONG_PTR
	FdwTypeData    TLPWSTR
	Fcch           TUINT
	FhbmpItem      THBITMAP
}

type MENUITEMINFOW = TMENUITEMINFOW

type TtagMENUITEMINFOW = TMENUITEMINFOW

type tagMENUITEMINFOW = TtagMENUITEMINFOW

type TLPMENUITEMINFOW = uintptr

type LPMENUITEMINFOW = TLPMENUITEMINFOW

type TMENUITEMINFO = struct {
	FcbSize        TUINT
	FfMask         TUINT
	FfType         TUINT
	FfState        TUINT
	FwID           TUINT
	FhSubMenu      THMENU
	FhbmpChecked   THBITMAP
	FhbmpUnchecked THBITMAP
	FdwItemData    TULONG_PTR
	FdwTypeData    TLPSTR
	Fcch           TUINT
	FhbmpItem      THBITMAP
}

type MENUITEMINFO = TMENUITEMINFO

type TLPMENUITEMINFO = uintptr

type LPMENUITEMINFO = TLPMENUITEMINFO

type TLPCMENUITEMINFOA = uintptr

type LPCMENUITEMINFOA = TLPCMENUITEMINFOA

type TLPCMENUITEMINFOW = uintptr

type LPCMENUITEMINFOW = TLPCMENUITEMINFOW

type TLPCMENUITEMINFO = uintptr

type LPCMENUITEMINFO = TLPCMENUITEMINFO

type TDROPSTRUCT = struct {
	FhwndSource    THWND
	FhwndSink      THWND
	FwFmt          TDWORD
	FdwData        TULONG_PTR
	FptDrop        TPOINT
	FdwControlData TDWORD
}

type DROPSTRUCT = TDROPSTRUCT

type TtagDROPSTRUCT = TDROPSTRUCT

type tagDROPSTRUCT = TtagDROPSTRUCT

type TPDROPSTRUCT = uintptr

type PDROPSTRUCT = TPDROPSTRUCT

type TLPDROPSTRUCT = uintptr

type LPDROPSTRUCT = TLPDROPSTRUCT

type TDRAWTEXTPARAMS = struct {
	FcbSize        TUINT
	FiTabLength    int32
	FiLeftMargin   int32
	FiRightMargin  int32
	FuiLengthDrawn TUINT
}

type DRAWTEXTPARAMS = TDRAWTEXTPARAMS

type TtagDRAWTEXTPARAMS = TDRAWTEXTPARAMS

type tagDRAWTEXTPARAMS = TtagDRAWTEXTPARAMS

type TLPDRAWTEXTPARAMS = uintptr

type LPDRAWTEXTPARAMS = TLPDRAWTEXTPARAMS

type THELPINFO = struct {
	FcbSize       TUINT
	FiContextType int32
	FiCtrlId      int32
	FhItemHandle  THANDLE
	FdwContextId  TDWORD_PTR
	FMousePos     TPOINT
}

type HELPINFO = THELPINFO

type TtagHELPINFO = THELPINFO

type tagHELPINFO = TtagHELPINFO

type TLPHELPINFO = uintptr

type LPHELPINFO = TLPHELPINFO

type TMSGBOXCALLBACK = uintptr

type MSGBOXCALLBACK = TMSGBOXCALLBACK

type TMSGBOXPARAMSA = struct {
	FcbSize             TUINT
	FhwndOwner          THWND
	FhInstance          THINSTANCE
	FlpszText           TLPCSTR
	FlpszCaption        TLPCSTR
	FdwStyle            TDWORD
	FlpszIcon           TLPCSTR
	FdwContextHelpId    TDWORD_PTR
	FlpfnMsgBoxCallback TMSGBOXCALLBACK
	FdwLanguageId       TDWORD
}

type MSGBOXPARAMSA = TMSGBOXPARAMSA

type TtagMSGBOXPARAMSA = TMSGBOXPARAMSA

type tagMSGBOXPARAMSA = TtagMSGBOXPARAMSA

type TPMSGBOXPARAMSA = uintptr

type PMSGBOXPARAMSA = TPMSGBOXPARAMSA

type TLPMSGBOXPARAMSA = uintptr

type LPMSGBOXPARAMSA = TLPMSGBOXPARAMSA

type TMSGBOXPARAMSW = struct {
	FcbSize             TUINT
	FhwndOwner          THWND
	FhInstance          THINSTANCE
	FlpszText           TLPCWSTR
	FlpszCaption        TLPCWSTR
	FdwStyle            TDWORD
	FlpszIcon           TLPCWSTR
	FdwContextHelpId    TDWORD_PTR
	FlpfnMsgBoxCallback TMSGBOXCALLBACK
	FdwLanguageId       TDWORD
}

type MSGBOXPARAMSW = TMSGBOXPARAMSW

type TtagMSGBOXPARAMSW = TMSGBOXPARAMSW

type tagMSGBOXPARAMSW = TtagMSGBOXPARAMSW

type TPMSGBOXPARAMSW = uintptr

type PMSGBOXPARAMSW = TPMSGBOXPARAMSW

type TLPMSGBOXPARAMSW = uintptr

type LPMSGBOXPARAMSW = TLPMSGBOXPARAMSW

type TMSGBOXPARAMS = struct {
	FcbSize             TUINT
	FhwndOwner          THWND
	FhInstance          THINSTANCE
	FlpszText           TLPCSTR
	FlpszCaption        TLPCSTR
	FdwStyle            TDWORD
	FlpszIcon           TLPCSTR
	FdwContextHelpId    TDWORD_PTR
	FlpfnMsgBoxCallback TMSGBOXCALLBACK
	FdwLanguageId       TDWORD
}

type MSGBOXPARAMS = TMSGBOXPARAMS

type TPMSGBOXPARAMS = uintptr

type PMSGBOXPARAMS = TPMSGBOXPARAMS

type TLPMSGBOXPARAMS = uintptr

type LPMSGBOXPARAMS = TLPMSGBOXPARAMS

type TMENUITEMTEMPLATEHEADER = struct {
	FversionNumber TWORD
	Foffset        TWORD
}

type MENUITEMTEMPLATEHEADER = TMENUITEMTEMPLATEHEADER

type TPMENUITEMTEMPLATEHEADER = uintptr

type PMENUITEMTEMPLATEHEADER = TPMENUITEMTEMPLATEHEADER

type TMENUITEMTEMPLATE = struct {
	FmtOption TWORD
	FmtID     TWORD
	FmtString [1]TWCHAR
}

type MENUITEMTEMPLATE = TMENUITEMTEMPLATE

type TPMENUITEMTEMPLATE = uintptr

type PMENUITEMTEMPLATE = TPMENUITEMTEMPLATE

type TICONINFO = struct {
	FfIcon    TWINBOOL
	FxHotspot TDWORD
	FyHotspot TDWORD
	FhbmMask  THBITMAP
	FhbmColor THBITMAP
}

type ICONINFO = TICONINFO

type T_ICONINFO = TICONINFO

type _ICONINFO = T_ICONINFO

type TPICONINFO = uintptr

type PICONINFO = TPICONINFO

type TCURSORSHAPE = struct {
	FxHotSpot  int32
	FyHotSpot  int32
	Fcx        int32
	Fcy        int32
	FcbWidth   int32
	FPlanes    TBYTE
	FBitsPixel TBYTE
}

type CURSORSHAPE = TCURSORSHAPE

type TtagCURSORSHAPE = TCURSORSHAPE

type tagCURSORSHAPE = TtagCURSORSHAPE

type TLPCURSORSHAPE = uintptr

type LPCURSORSHAPE = TLPCURSORSHAPE

type TICONINFOEXA = struct {
	FcbSize    TDWORD
	FfIcon     TWINBOOL
	FxHotspot  TDWORD
	FyHotspot  TDWORD
	FhbmMask   THBITMAP
	FhbmColor  THBITMAP
	FwResID    TWORD
	FszModName [260]TCHAR
	FszResName [260]TCHAR
}

type ICONINFOEXA = TICONINFOEXA

type T_ICONINFOEXA = TICONINFOEXA

type _ICONINFOEXA = T_ICONINFOEXA

type TPICONINFOEXA = uintptr

type PICONINFOEXA = TPICONINFOEXA

type TICONINFOEXW = struct {
	FcbSize    TDWORD
	FfIcon     TWINBOOL
	FxHotspot  TDWORD
	FyHotspot  TDWORD
	FhbmMask   THBITMAP
	FhbmColor  THBITMAP
	FwResID    TWORD
	FszModName [260]TWCHAR
	FszResName [260]TWCHAR
}

type ICONINFOEXW = TICONINFOEXW

type T_ICONINFOEXW = TICONINFOEXW

type _ICONINFOEXW = T_ICONINFOEXW

type TPICONINFOEXW = uintptr

type PICONINFOEXW = TPICONINFOEXW

type TICONINFOEX = struct {
	FcbSize    TDWORD
	FfIcon     TWINBOOL
	FxHotspot  TDWORD
	FyHotspot  TDWORD
	FhbmMask   THBITMAP
	FhbmColor  THBITMAP
	FwResID    TWORD
	FszModName [260]TCHAR
	FszResName [260]TCHAR
}

type ICONINFOEX = TICONINFOEX

type TPICONINFOEX = uintptr

type PICONINFOEX = TPICONINFOEX

type TSCROLLINFO = struct {
	FcbSize    TUINT
	FfMask     TUINT
	FnMin      int32
	FnMax      int32
	FnPage     TUINT
	FnPos      int32
	FnTrackPos int32
}

type SCROLLINFO = TSCROLLINFO

type TtagSCROLLINFO = TSCROLLINFO

type tagSCROLLINFO = TtagSCROLLINFO

type TLPSCROLLINFO = uintptr

type LPSCROLLINFO = TLPSCROLLINFO

type TLPCSCROLLINFO = uintptr

type LPCSCROLLINFO = TLPCSCROLLINFO

type TMDICREATESTRUCTA = struct {
	FszClass TLPCSTR
	FszTitle TLPCSTR
	FhOwner  THANDLE
	Fx       int32
	Fy       int32
	Fcx      int32
	Fcy      int32
	Fstyle   TDWORD
	FlParam  TLPARAM
}

type MDICREATESTRUCTA = TMDICREATESTRUCTA

type TtagMDICREATESTRUCTA = TMDICREATESTRUCTA

type tagMDICREATESTRUCTA = TtagMDICREATESTRUCTA

type TLPMDICREATESTRUCTA = uintptr

type LPMDICREATESTRUCTA = TLPMDICREATESTRUCTA

type TMDICREATESTRUCTW = struct {
	FszClass TLPCWSTR
	FszTitle TLPCWSTR
	FhOwner  THANDLE
	Fx       int32
	Fy       int32
	Fcx      int32
	Fcy      int32
	Fstyle   TDWORD
	FlParam  TLPARAM
}

type MDICREATESTRUCTW = TMDICREATESTRUCTW

type TtagMDICREATESTRUCTW = TMDICREATESTRUCTW

type tagMDICREATESTRUCTW = TtagMDICREATESTRUCTW

type TLPMDICREATESTRUCTW = uintptr

type LPMDICREATESTRUCTW = TLPMDICREATESTRUCTW

type TMDICREATESTRUCT = struct {
	FszClass TLPCSTR
	FszTitle TLPCSTR
	FhOwner  THANDLE
	Fx       int32
	Fy       int32
	Fcx      int32
	Fcy      int32
	Fstyle   TDWORD
	FlParam  TLPARAM
}

type MDICREATESTRUCT = TMDICREATESTRUCT

type TLPMDICREATESTRUCT = uintptr

type LPMDICREATESTRUCT = TLPMDICREATESTRUCT

type TCLIENTCREATESTRUCT = struct {
	FhWindowMenu  THANDLE
	FidFirstChild TUINT
}

type CLIENTCREATESTRUCT = TCLIENTCREATESTRUCT

type TtagCLIENTCREATESTRUCT = TCLIENTCREATESTRUCT

type tagCLIENTCREATESTRUCT = TtagCLIENTCREATESTRUCT

type TLPCLIENTCREATESTRUCT = uintptr

type LPCLIENTCREATESTRUCT = TLPCLIENTCREATESTRUCT

type THELPPOLY = uint32

type HELPPOLY = THELPPOLY

type TMULTIKEYHELPA = struct {
	FmkSize      TDWORD
	FmkKeylist   TCHAR
	FszKeyphrase [1]TCHAR
}

type MULTIKEYHELPA = TMULTIKEYHELPA

type TtagMULTIKEYHELPA = TMULTIKEYHELPA

type tagMULTIKEYHELPA = TtagMULTIKEYHELPA

type TPMULTIKEYHELPA = uintptr

type PMULTIKEYHELPA = TPMULTIKEYHELPA

type TLPMULTIKEYHELPA = uintptr

type LPMULTIKEYHELPA = TLPMULTIKEYHELPA

type TMULTIKEYHELPW = struct {
	FmkSize      TDWORD
	FmkKeylist   TWCHAR
	FszKeyphrase [1]TWCHAR
}

type MULTIKEYHELPW = TMULTIKEYHELPW

type TtagMULTIKEYHELPW = TMULTIKEYHELPW

type tagMULTIKEYHELPW = TtagMULTIKEYHELPW

type TPMULTIKEYHELPW = uintptr

type PMULTIKEYHELPW = TPMULTIKEYHELPW

type TLPMULTIKEYHELPW = uintptr

type LPMULTIKEYHELPW = TLPMULTIKEYHELPW

type TMULTIKEYHELP = struct {
	FmkSize      TDWORD
	FmkKeylist   TCHAR
	FszKeyphrase [1]TCHAR
}

type MULTIKEYHELP = TMULTIKEYHELP

type TPMULTIKEYHELP = uintptr

type PMULTIKEYHELP = TPMULTIKEYHELP

type TLPMULTIKEYHELP = uintptr

type LPMULTIKEYHELP = TLPMULTIKEYHELP

type THELPWININFOA = struct {
	FwStructSize int32
	Fx           int32
	Fy           int32
	Fdx          int32
	Fdy          int32
	FwMax        int32
	FrgchMember  [2]TCHAR
}

type HELPWININFOA = THELPWININFOA

type TtagHELPWININFOA = THELPWININFOA

type tagHELPWININFOA = TtagHELPWININFOA

type TPHELPWININFOA = uintptr

type PHELPWININFOA = TPHELPWININFOA

type TLPHELPWININFOA = uintptr

type LPHELPWININFOA = TLPHELPWININFOA

type THELPWININFOW = struct {
	FwStructSize int32
	Fx           int32
	Fy           int32
	Fdx          int32
	Fdy          int32
	FwMax        int32
	FrgchMember  [2]TWCHAR
}

type HELPWININFOW = THELPWININFOW

type TtagHELPWININFOW = THELPWININFOW

type tagHELPWININFOW = TtagHELPWININFOW

type TPHELPWININFOW = uintptr

type PHELPWININFOW = TPHELPWININFOW

type TLPHELPWININFOW = uintptr

type LPHELPWININFOW = TLPHELPWININFOW

type THELPWININFO = struct {
	FwStructSize int32
	Fx           int32
	Fy           int32
	Fdx          int32
	Fdy          int32
	FwMax        int32
	FrgchMember  [2]TCHAR
}

type HELPWININFO = THELPWININFO

type TPHELPWININFO = uintptr

type PHELPWININFO = TPHELPWININFO

type TLPHELPWININFO = uintptr

type LPHELPWININFO = TLPHELPWININFO

type TTOUCHPREDICTIONPARAMETERS = struct {
	FcbSize          TUINT
	FdwLatency       TUINT
	FdwSampleTime    TUINT
	FbUseHWTimeStamp TUINT
}

type TOUCHPREDICTIONPARAMETERS = TTOUCHPREDICTIONPARAMETERS

type TtagTouchPredictionParameters = TTOUCHPREDICTIONPARAMETERS

type tagTouchPredictionParameters = TtagTouchPredictionParameters

type TPTOUCHPREDICTIONPARAMETERS = uintptr

type PTOUCHPREDICTIONPARAMETERS = TPTOUCHPREDICTIONPARAMETERS

type TNONCLIENTMETRICSA = struct {
	FcbSize             TUINT
	FiBorderWidth       int32
	FiScrollWidth       int32
	FiScrollHeight      int32
	FiCaptionWidth      int32
	FiCaptionHeight     int32
	FlfCaptionFont      TLOGFONTA
	FiSmCaptionWidth    int32
	FiSmCaptionHeight   int32
	FlfSmCaptionFont    TLOGFONTA
	FiMenuWidth         int32
	FiMenuHeight        int32
	FlfMenuFont         TLOGFONTA
	FlfStatusFont       TLOGFONTA
	FlfMessageFont      TLOGFONTA
	FiPaddedBorderWidth int32
}

type NONCLIENTMETRICSA = TNONCLIENTMETRICSA

type TtagNONCLIENTMETRICSA = TNONCLIENTMETRICSA

type tagNONCLIENTMETRICSA = TtagNONCLIENTMETRICSA

type TPNONCLIENTMETRICSA = uintptr

type PNONCLIENTMETRICSA = TPNONCLIENTMETRICSA

type TLPNONCLIENTMETRICSA = uintptr

type LPNONCLIENTMETRICSA = TLPNONCLIENTMETRICSA

type TNONCLIENTMETRICSW = struct {
	FcbSize             TUINT
	FiBorderWidth       int32
	FiScrollWidth       int32
	FiScrollHeight      int32
	FiCaptionWidth      int32
	FiCaptionHeight     int32
	FlfCaptionFont      TLOGFONTW
	FiSmCaptionWidth    int32
	FiSmCaptionHeight   int32
	FlfSmCaptionFont    TLOGFONTW
	FiMenuWidth         int32
	FiMenuHeight        int32
	FlfMenuFont         TLOGFONTW
	FlfStatusFont       TLOGFONTW
	FlfMessageFont      TLOGFONTW
	FiPaddedBorderWidth int32
}

type NONCLIENTMETRICSW = TNONCLIENTMETRICSW

type TtagNONCLIENTMETRICSW = TNONCLIENTMETRICSW

type tagNONCLIENTMETRICSW = TtagNONCLIENTMETRICSW

type TPNONCLIENTMETRICSW = uintptr

type PNONCLIENTMETRICSW = TPNONCLIENTMETRICSW

type TLPNONCLIENTMETRICSW = uintptr

type LPNONCLIENTMETRICSW = TLPNONCLIENTMETRICSW

type TNONCLIENTMETRICS = struct {
	FcbSize             TUINT
	FiBorderWidth       int32
	FiScrollWidth       int32
	FiScrollHeight      int32
	FiCaptionWidth      int32
	FiCaptionHeight     int32
	FlfCaptionFont      TLOGFONTA
	FiSmCaptionWidth    int32
	FiSmCaptionHeight   int32
	FlfSmCaptionFont    TLOGFONTA
	FiMenuWidth         int32
	FiMenuHeight        int32
	FlfMenuFont         TLOGFONTA
	FlfStatusFont       TLOGFONTA
	FlfMessageFont      TLOGFONTA
	FiPaddedBorderWidth int32
}

type NONCLIENTMETRICS = TNONCLIENTMETRICS

type TPNONCLIENTMETRICS = uintptr

type PNONCLIENTMETRICS = TPNONCLIENTMETRICS

type TLPNONCLIENTMETRICS = uintptr

type LPNONCLIENTMETRICS = TLPNONCLIENTMETRICS

type TMINIMIZEDMETRICS = struct {
	FcbSize   TUINT
	FiWidth   int32
	FiHorzGap int32
	FiVertGap int32
	FiArrange int32
}

type MINIMIZEDMETRICS = TMINIMIZEDMETRICS

type TtagMINIMIZEDMETRICS = TMINIMIZEDMETRICS

type tagMINIMIZEDMETRICS = TtagMINIMIZEDMETRICS

type TPMINIMIZEDMETRICS = uintptr

type PMINIMIZEDMETRICS = TPMINIMIZEDMETRICS

type TLPMINIMIZEDMETRICS = uintptr

type LPMINIMIZEDMETRICS = TLPMINIMIZEDMETRICS

type TICONMETRICSA = struct {
	FcbSize       TUINT
	FiHorzSpacing int32
	FiVertSpacing int32
	FiTitleWrap   int32
	FlfFont       TLOGFONTA
}

type ICONMETRICSA = TICONMETRICSA

type TtagICONMETRICSA = TICONMETRICSA

type tagICONMETRICSA = TtagICONMETRICSA

type TPICONMETRICSA = uintptr

type PICONMETRICSA = TPICONMETRICSA

type TLPICONMETRICSA = uintptr

type LPICONMETRICSA = TLPICONMETRICSA

type TICONMETRICSW = struct {
	FcbSize       TUINT
	FiHorzSpacing int32
	FiVertSpacing int32
	FiTitleWrap   int32
	FlfFont       TLOGFONTW
}

type ICONMETRICSW = TICONMETRICSW

type TtagICONMETRICSW = TICONMETRICSW

type tagICONMETRICSW = TtagICONMETRICSW

type TPICONMETRICSW = uintptr

type PICONMETRICSW = TPICONMETRICSW

type TLPICONMETRICSW = uintptr

type LPICONMETRICSW = TLPICONMETRICSW

type TICONMETRICS = struct {
	FcbSize       TUINT
	FiHorzSpacing int32
	FiVertSpacing int32
	FiTitleWrap   int32
	FlfFont       TLOGFONTA
}

type ICONMETRICS = TICONMETRICS

type TPICONMETRICS = uintptr

type PICONMETRICS = TPICONMETRICS

type TLPICONMETRICS = uintptr

type LPICONMETRICS = TLPICONMETRICS

type TANIMATIONINFO = struct {
	FcbSize      TUINT
	FiMinAnimate int32
}

type ANIMATIONINFO = TANIMATIONINFO

type TtagANIMATIONINFO = TANIMATIONINFO

type tagANIMATIONINFO = TtagANIMATIONINFO

type TLPANIMATIONINFO = uintptr

type LPANIMATIONINFO = TLPANIMATIONINFO

type TSERIALKEYSA = struct {
	FcbSize         TUINT
	FdwFlags        TDWORD
	FlpszActivePort TLPSTR
	FlpszPort       TLPSTR
	FiBaudRate      TUINT
	FiPortState     TUINT
	FiActive        TUINT
}

type SERIALKEYSA = TSERIALKEYSA

type TtagSERIALKEYSA = TSERIALKEYSA

type tagSERIALKEYSA = TtagSERIALKEYSA

type TLPSERIALKEYSA = uintptr

type LPSERIALKEYSA = TLPSERIALKEYSA

type TSERIALKEYSW = struct {
	FcbSize         TUINT
	FdwFlags        TDWORD
	FlpszActivePort TLPWSTR
	FlpszPort       TLPWSTR
	FiBaudRate      TUINT
	FiPortState     TUINT
	FiActive        TUINT
}

type SERIALKEYSW = TSERIALKEYSW

type TtagSERIALKEYSW = TSERIALKEYSW

type tagSERIALKEYSW = TtagSERIALKEYSW

type TLPSERIALKEYSW = uintptr

type LPSERIALKEYSW = TLPSERIALKEYSW

type TSERIALKEYS = struct {
	FcbSize         TUINT
	FdwFlags        TDWORD
	FlpszActivePort TLPSTR
	FlpszPort       TLPSTR
	FiBaudRate      TUINT
	FiPortState     TUINT
	FiActive        TUINT
}

type SERIALKEYS = TSERIALKEYS

type TLPSERIALKEYS = uintptr

type LPSERIALKEYS = TLPSERIALKEYS

type THIGHCONTRASTA = struct {
	FcbSize            TUINT
	FdwFlags           TDWORD
	FlpszDefaultScheme TLPSTR
}

type HIGHCONTRASTA = THIGHCONTRASTA

type TtagHIGHCONTRASTA = THIGHCONTRASTA

type tagHIGHCONTRASTA = TtagHIGHCONTRASTA

type TLPHIGHCONTRASTA = uintptr

type LPHIGHCONTRASTA = TLPHIGHCONTRASTA

type THIGHCONTRASTW = struct {
	FcbSize            TUINT
	FdwFlags           TDWORD
	FlpszDefaultScheme TLPWSTR
}

type HIGHCONTRASTW = THIGHCONTRASTW

type TtagHIGHCONTRASTW = THIGHCONTRASTW

type tagHIGHCONTRASTW = TtagHIGHCONTRASTW

type TLPHIGHCONTRASTW = uintptr

type LPHIGHCONTRASTW = TLPHIGHCONTRASTW

type THIGHCONTRAST = struct {
	FcbSize            TUINT
	FdwFlags           TDWORD
	FlpszDefaultScheme TLPSTR
}

type HIGHCONTRAST = THIGHCONTRAST

type TLPHIGHCONTRAST = uintptr

type LPHIGHCONTRAST = TLPHIGHCONTRAST

type TVIDEOPARAMETERS = struct {
	FGuid                  TGUID
	FdwOffset              TULONG
	FdwCommand             TULONG
	FdwFlags               TULONG
	FdwMode                TULONG
	FdwTVStandard          TULONG
	FdwAvailableModes      TULONG
	FdwAvailableTVStandard TULONG
	FdwFlickerFilter       TULONG
	FdwOverScanX           TULONG
	FdwOverScanY           TULONG
	FdwMaxUnscaledX        TULONG
	FdwMaxUnscaledY        TULONG
	FdwPositionX           TULONG
	FdwPositionY           TULONG
	FdwBrightness          TULONG
	FdwContrast            TULONG
	FdwCPType              TULONG
	FdwCPCommand           TULONG
	FdwCPStandard          TULONG
	FdwCPKey               TULONG
	FbCP_APSTriggerBits    TULONG
	FbOEMCopyProtection    [256]TUCHAR
}

type VIDEOPARAMETERS = TVIDEOPARAMETERS

type T_VIDEOPARAMETERS = TVIDEOPARAMETERS

type _VIDEOPARAMETERS = T_VIDEOPARAMETERS

type TPVIDEOPARAMETERS = uintptr

type PVIDEOPARAMETERS = TPVIDEOPARAMETERS

type TLPVIDEOPARAMETERS = uintptr

type LPVIDEOPARAMETERS = TLPVIDEOPARAMETERS

type TFILTERKEYS = struct {
	FcbSize      TUINT
	FdwFlags     TDWORD
	FiWaitMSec   TDWORD
	FiDelayMSec  TDWORD
	FiRepeatMSec TDWORD
	FiBounceMSec TDWORD
}

type FILTERKEYS = TFILTERKEYS

type TtagFILTERKEYS = TFILTERKEYS

type tagFILTERKEYS = TtagFILTERKEYS

type TLPFILTERKEYS = uintptr

type LPFILTERKEYS = TLPFILTERKEYS

type TSTICKYKEYS = struct {
	FcbSize  TUINT
	FdwFlags TDWORD
}

type STICKYKEYS = TSTICKYKEYS

type TtagSTICKYKEYS = TSTICKYKEYS

type tagSTICKYKEYS = TtagSTICKYKEYS

type TLPSTICKYKEYS = uintptr

type LPSTICKYKEYS = TLPSTICKYKEYS

type TMOUSEKEYS = struct {
	FcbSize          TUINT
	FdwFlags         TDWORD
	FiMaxSpeed       TDWORD
	FiTimeToMaxSpeed TDWORD
	FiCtrlSpeed      TDWORD
	FdwReserved1     TDWORD
	FdwReserved2     TDWORD
}

type MOUSEKEYS = TMOUSEKEYS

type TtagMOUSEKEYS = TMOUSEKEYS

type tagMOUSEKEYS = TtagMOUSEKEYS

type TLPMOUSEKEYS = uintptr

type LPMOUSEKEYS = TLPMOUSEKEYS

type TACCESSTIMEOUT = struct {
	FcbSize       TUINT
	FdwFlags      TDWORD
	FiTimeOutMSec TDWORD
}

type ACCESSTIMEOUT = TACCESSTIMEOUT

type TtagACCESSTIMEOUT = TACCESSTIMEOUT

type tagACCESSTIMEOUT = TtagACCESSTIMEOUT

type TLPACCESSTIMEOUT = uintptr

type LPACCESSTIMEOUT = TLPACCESSTIMEOUT

type TSOUNDSENTRYA = struct {
	FcbSize                 TUINT
	FdwFlags                TDWORD
	FiFSTextEffect          TDWORD
	FiFSTextEffectMSec      TDWORD
	FiFSTextEffectColorBits TDWORD
	FiFSGrafEffect          TDWORD
	FiFSGrafEffectMSec      TDWORD
	FiFSGrafEffectColor     TDWORD
	FiWindowsEffect         TDWORD
	FiWindowsEffectMSec     TDWORD
	FlpszWindowsEffectDLL   TLPSTR
	FiWindowsEffectOrdinal  TDWORD
}

type SOUNDSENTRYA = TSOUNDSENTRYA

type TtagSOUNDSENTRYA = TSOUNDSENTRYA

type tagSOUNDSENTRYA = TtagSOUNDSENTRYA

type TLPSOUNDSENTRYA = uintptr

type LPSOUNDSENTRYA = TLPSOUNDSENTRYA

type TSOUNDSENTRYW = struct {
	FcbSize                 TUINT
	FdwFlags                TDWORD
	FiFSTextEffect          TDWORD
	FiFSTextEffectMSec      TDWORD
	FiFSTextEffectColorBits TDWORD
	FiFSGrafEffect          TDWORD
	FiFSGrafEffectMSec      TDWORD
	FiFSGrafEffectColor     TDWORD
	FiWindowsEffect         TDWORD
	FiWindowsEffectMSec     TDWORD
	FlpszWindowsEffectDLL   TLPWSTR
	FiWindowsEffectOrdinal  TDWORD
}

type SOUNDSENTRYW = TSOUNDSENTRYW

type TtagSOUNDSENTRYW = TSOUNDSENTRYW

type tagSOUNDSENTRYW = TtagSOUNDSENTRYW

type TLPSOUNDSENTRYW = uintptr

type LPSOUNDSENTRYW = TLPSOUNDSENTRYW

type TSOUNDSENTRY = struct {
	FcbSize                 TUINT
	FdwFlags                TDWORD
	FiFSTextEffect          TDWORD
	FiFSTextEffectMSec      TDWORD
	FiFSTextEffectColorBits TDWORD
	FiFSGrafEffect          TDWORD
	FiFSGrafEffectMSec      TDWORD
	FiFSGrafEffectColor     TDWORD
	FiWindowsEffect         TDWORD
	FiWindowsEffectMSec     TDWORD
	FlpszWindowsEffectDLL   TLPSTR
	FiWindowsEffectOrdinal  TDWORD
}

type SOUNDSENTRY = TSOUNDSENTRY

type TLPSOUNDSENTRY = uintptr

type LPSOUNDSENTRY = TLPSOUNDSENTRY

type TTOGGLEKEYS = struct {
	FcbSize  TUINT
	FdwFlags TDWORD
}

type TOGGLEKEYS = TTOGGLEKEYS

type TtagTOGGLEKEYS = TTOGGLEKEYS

type tagTOGGLEKEYS = TtagTOGGLEKEYS

type TLPTOGGLEKEYS = uintptr

type LPTOGGLEKEYS = TLPTOGGLEKEYS

type TMONITORINFO = struct {
	FcbSize    TDWORD
	FrcMonitor TRECT
	FrcWork    TRECT
	FdwFlags   TDWORD
}

type MONITORINFO = TMONITORINFO

type TtagMONITORINFO = TMONITORINFO

type tagMONITORINFO = TtagMONITORINFO

type TLPMONITORINFO = uintptr

type LPMONITORINFO = TLPMONITORINFO

type TAUDIODESCRIPTION = struct {
	FcbSize  TUINT
	FEnabled TWINBOOL
	FLocale  TLCID
}

type AUDIODESCRIPTION = TAUDIODESCRIPTION

type TtagAUDIODESCRIPTION = TAUDIODESCRIPTION

type tagAUDIODESCRIPTION = TtagAUDIODESCRIPTION

type TLPAUDIODESCRIPTION = uintptr

type LPAUDIODESCRIPTION = TLPAUDIODESCRIPTION

type TMONITORINFOEXA = struct {
	F__ccgo0_0 struct {
		FcbSize    TDWORD
		FrcMonitor TRECT
		FrcWork    TRECT
		FdwFlags   TDWORD
	}
	FszDevice [32]TCHAR
}

type MONITORINFOEXA = TMONITORINFOEXA

type TtagMONITORINFOEXA = TMONITORINFOEXA

type tagMONITORINFOEXA = TtagMONITORINFOEXA

type TLPMONITORINFOEXA = uintptr

type LPMONITORINFOEXA = TLPMONITORINFOEXA

type TMONITORINFOEXW = struct {
	F__ccgo0_0 struct {
		FcbSize    TDWORD
		FrcMonitor TRECT
		FrcWork    TRECT
		FdwFlags   TDWORD
	}
	FszDevice [32]TWCHAR
}

type MONITORINFOEXW = TMONITORINFOEXW

type TtagMONITORINFOEXW = TMONITORINFOEXW

type tagMONITORINFOEXW = TtagMONITORINFOEXW

type TLPMONITORINFOEXW = uintptr

type LPMONITORINFOEXW = TLPMONITORINFOEXW

type TMONITORINFOEX = struct {
	F__ccgo0_0 struct {
		FcbSize    TDWORD
		FrcMonitor TRECT
		FrcWork    TRECT
		FdwFlags   TDWORD
	}
	FszDevice [32]TCHAR
}

type MONITORINFOEX = TMONITORINFOEX

type TLPMONITORINFOEX = uintptr

type LPMONITORINFOEX = TLPMONITORINFOEX

type TMONITORENUMPROC = uintptr

type MONITORENUMPROC = TMONITORENUMPROC

type TWINEVENTPROC = uintptr

type WINEVENTPROC = TWINEVENTPROC

type TGUITHREADINFO = struct {
	FcbSize        TDWORD
	Fflags         TDWORD
	FhwndActive    THWND
	FhwndFocus     THWND
	FhwndCapture   THWND
	FhwndMenuOwner THWND
	FhwndMoveSize  THWND
	FhwndCaret     THWND
	FrcCaret       TRECT
}

type GUITHREADINFO = TGUITHREADINFO

type TtagGUITHREADINFO = TGUITHREADINFO

type tagGUITHREADINFO = TtagGUITHREADINFO

type TPGUITHREADINFO = uintptr

type PGUITHREADINFO = TPGUITHREADINFO

type TLPGUITHREADINFO = uintptr

type LPGUITHREADINFO = TLPGUITHREADINFO

type TCURSORINFO = struct {
	FcbSize      TDWORD
	Fflags       TDWORD
	FhCursor     THCURSOR
	FptScreenPos TPOINT
}

type CURSORINFO = TCURSORINFO

type TtagCURSORINFO = TCURSORINFO

type tagCURSORINFO = TtagCURSORINFO

type TPCURSORINFO = uintptr

type PCURSORINFO = TPCURSORINFO

type TLPCURSORINFO = uintptr

type LPCURSORINFO = TLPCURSORINFO

type TWINDOWINFO = struct {
	FcbSize          TDWORD
	FrcWindow        TRECT
	FrcClient        TRECT
	FdwStyle         TDWORD
	FdwExStyle       TDWORD
	FdwWindowStatus  TDWORD
	FcxWindowBorders TUINT
	FcyWindowBorders TUINT
	FatomWindowType  TATOM
	FwCreatorVersion TWORD
}

type WINDOWINFO = TWINDOWINFO

type TtagWINDOWINFO = TWINDOWINFO

type tagWINDOWINFO = TtagWINDOWINFO

type TPWINDOWINFO = uintptr

type PWINDOWINFO = TPWINDOWINFO

type TLPWINDOWINFO = uintptr

type LPWINDOWINFO = TLPWINDOWINFO

type TTITLEBARINFO = struct {
	FcbSize     TDWORD
	FrcTitleBar TRECT
	Frgstate    [6]TDWORD
}

type TITLEBARINFO = TTITLEBARINFO

type TtagTITLEBARINFO = TTITLEBARINFO

type tagTITLEBARINFO = TtagTITLEBARINFO

type TPTITLEBARINFO = uintptr

type PTITLEBARINFO = TPTITLEBARINFO

type TLPTITLEBARINFO = uintptr

type LPTITLEBARINFO = TLPTITLEBARINFO

type TTITLEBARINFOEX = struct {
	FcbSize     TDWORD
	FrcTitleBar TRECT
	Frgstate    [6]TDWORD
	Frgrect     [6]TRECT
}

type TITLEBARINFOEX = TTITLEBARINFOEX

type TtagTITLEBARINFOEX = TTITLEBARINFOEX

type tagTITLEBARINFOEX = TtagTITLEBARINFOEX

type TPTITLEBARINFOEX = uintptr

type PTITLEBARINFOEX = TPTITLEBARINFOEX

type TLPTITLEBARINFOEX = uintptr

type LPTITLEBARINFOEX = TLPTITLEBARINFOEX

type TMENUBARINFO = struct {
	FcbSize   TDWORD
	FrcBar    TRECT
	FhMenu    THMENU
	FhwndMenu THWND
	F__ccgo28 uint8
}

type MENUBARINFO = TMENUBARINFO

type TtagMENUBARINFO = TMENUBARINFO

type tagMENUBARINFO = TtagMENUBARINFO

type TPMENUBARINFO = uintptr

type PMENUBARINFO = TPMENUBARINFO

type TLPMENUBARINFO = uintptr

type LPMENUBARINFO = TLPMENUBARINFO

type TSCROLLBARINFO = struct {
	FcbSize        TDWORD
	FrcScrollBar   TRECT
	FdxyLineButton int32
	FxyThumbTop    int32
	FxyThumbBottom int32
	Freserved      int32
	Frgstate       [6]TDWORD
}

type SCROLLBARINFO = TSCROLLBARINFO

type TtagSCROLLBARINFO = TSCROLLBARINFO

type tagSCROLLBARINFO = TtagSCROLLBARINFO

type TPSCROLLBARINFO = uintptr

type PSCROLLBARINFO = TPSCROLLBARINFO

type TLPSCROLLBARINFO = uintptr

type LPSCROLLBARINFO = TLPSCROLLBARINFO

type TCOMBOBOXINFO = struct {
	FcbSize      TDWORD
	FrcItem      TRECT
	FrcButton    TRECT
	FstateButton TDWORD
	FhwndCombo   THWND
	FhwndItem    THWND
	FhwndList    THWND
}

type COMBOBOXINFO = TCOMBOBOXINFO

type TtagCOMBOBOXINFO = TCOMBOBOXINFO

type tagCOMBOBOXINFO = TtagCOMBOBOXINFO

type TPCOMBOBOXINFO = uintptr

type PCOMBOBOXINFO = TPCOMBOBOXINFO

type TLPCOMBOBOXINFO = uintptr

type LPCOMBOBOXINFO = TLPCOMBOBOXINFO

type TALTTABINFO = struct {
	FcbSize    TDWORD
	FcItems    int32
	FcColumns  int32
	FcRows     int32
	FiColFocus int32
	FiRowFocus int32
	FcxItem    int32
	FcyItem    int32
	FptStart   TPOINT
}

type ALTTABINFO = TALTTABINFO

type TtagALTTABINFO = TALTTABINFO

type tagALTTABINFO = TtagALTTABINFO

type TPALTTABINFO = uintptr

type PALTTABINFO = TPALTTABINFO

type TLPALTTABINFO = uintptr

type LPALTTABINFO = TLPALTTABINFO

type THRAWINPUT__ = struct {
	Funused int32
}

type HRAWINPUT__ = THRAWINPUT__

type THRAWINPUT = uintptr

type HRAWINPUT = THRAWINPUT

type TRAWINPUTHEADER = struct {
	FdwType  TDWORD
	FdwSize  TDWORD
	FhDevice THANDLE
	FwParam  TWPARAM
}

type RAWINPUTHEADER = TRAWINPUTHEADER

type TtagRAWINPUTHEADER = TRAWINPUTHEADER

type tagRAWINPUTHEADER = TtagRAWINPUTHEADER

type TPRAWINPUTHEADER = uintptr

type PRAWINPUTHEADER = TPRAWINPUTHEADER

type TLPRAWINPUTHEADER = uintptr

type LPRAWINPUTHEADER = TLPRAWINPUTHEADER

type TRAWMOUSE = struct {
	FusFlags   TUSHORT
	F__ccgo1_4 struct {
		F__ccgo1_0 [0]struct {
			FusButtonFlags TUSHORT
			FusButtonData  TUSHORT
		}
		FulButtons TULONG
	}
	FulRawButtons       TULONG
	FlLastX             TLONG
	FlLastY             TLONG
	FulExtraInformation TULONG
}

type RAWMOUSE = TRAWMOUSE

type TtagRAWMOUSE = TRAWMOUSE

type tagRAWMOUSE = TtagRAWMOUSE

type TPRAWMOUSE = uintptr

type PRAWMOUSE = TPRAWMOUSE

type TLPRAWMOUSE = uintptr

type LPRAWMOUSE = TLPRAWMOUSE

type TRAWKEYBOARD = struct {
	FMakeCode         TUSHORT
	FFlags            TUSHORT
	FReserved         TUSHORT
	FVKey             TUSHORT
	FMessage          TUINT
	FExtraInformation TULONG
}

type RAWKEYBOARD = TRAWKEYBOARD

type TtagRAWKEYBOARD = TRAWKEYBOARD

type tagRAWKEYBOARD = TtagRAWKEYBOARD

type TPRAWKEYBOARD = uintptr

type PRAWKEYBOARD = TPRAWKEYBOARD

type TLPRAWKEYBOARD = uintptr

type LPRAWKEYBOARD = TLPRAWKEYBOARD

type TRAWHID = struct {
	FdwSizeHid TDWORD
	FdwCount   TDWORD
	FbRawData  [1]TBYTE
}

type RAWHID = TRAWHID

type TtagRAWHID = TRAWHID

type tagRAWHID = TtagRAWHID

type TPRAWHID = uintptr

type PRAWHID = TPRAWHID

type TLPRAWHID = uintptr

type LPRAWHID = TLPRAWHID

type TRAWINPUT = struct {
	Fheader TRAWINPUTHEADER
	Fdata   struct {
		Fkeyboard [0]TRAWKEYBOARD
		Fhid      [0]TRAWHID
		Fmouse    TRAWMOUSE
	}
}

type RAWINPUT = TRAWINPUT

type TtagRAWINPUT = TRAWINPUT

type tagRAWINPUT = TtagRAWINPUT

type TPRAWINPUT = uintptr

type PRAWINPUT = TPRAWINPUT

type TLPRAWINPUT = uintptr

type LPRAWINPUT = TLPRAWINPUT

type TRID_DEVICE_INFO_MOUSE = struct {
	FdwId                TDWORD
	FdwNumberOfButtons   TDWORD
	FdwSampleRate        TDWORD
	FfHasHorizontalWheel TWINBOOL
}

type RID_DEVICE_INFO_MOUSE = TRID_DEVICE_INFO_MOUSE

type TtagRID_DEVICE_INFO_MOUSE = TRID_DEVICE_INFO_MOUSE

type tagRID_DEVICE_INFO_MOUSE = TtagRID_DEVICE_INFO_MOUSE

type TPRID_DEVICE_INFO_MOUSE = uintptr

type PRID_DEVICE_INFO_MOUSE = TPRID_DEVICE_INFO_MOUSE

type TRID_DEVICE_INFO_KEYBOARD = struct {
	FdwType                 TDWORD
	FdwSubType              TDWORD
	FdwKeyboardMode         TDWORD
	FdwNumberOfFunctionKeys TDWORD
	FdwNumberOfIndicators   TDWORD
	FdwNumberOfKeysTotal    TDWORD
}

type RID_DEVICE_INFO_KEYBOARD = TRID_DEVICE_INFO_KEYBOARD

type TtagRID_DEVICE_INFO_KEYBOARD = TRID_DEVICE_INFO_KEYBOARD

type tagRID_DEVICE_INFO_KEYBOARD = TtagRID_DEVICE_INFO_KEYBOARD

type TPRID_DEVICE_INFO_KEYBOARD = uintptr

type PRID_DEVICE_INFO_KEYBOARD = TPRID_DEVICE_INFO_KEYBOARD

type TRID_DEVICE_INFO_HID = struct {
	FdwVendorId      TDWORD
	FdwProductId     TDWORD
	FdwVersionNumber TDWORD
	FusUsagePage     TUSHORT
	FusUsage         TUSHORT
}

type RID_DEVICE_INFO_HID = TRID_DEVICE_INFO_HID

type TtagRID_DEVICE_INFO_HID = TRID_DEVICE_INFO_HID

type tagRID_DEVICE_INFO_HID = TtagRID_DEVICE_INFO_HID

type TPRID_DEVICE_INFO_HID = uintptr

type PRID_DEVICE_INFO_HID = TPRID_DEVICE_INFO_HID

type TRID_DEVICE_INFO = struct {
	FcbSize    TDWORD
	FdwType    TDWORD
	F__ccgo2_8 struct {
		Fkeyboard    [0]TRID_DEVICE_INFO_KEYBOARD
		Fhid         [0]TRID_DEVICE_INFO_HID
		Fmouse       TRID_DEVICE_INFO_MOUSE
		F__ccgo_pad3 [8]byte
	}
}

type RID_DEVICE_INFO = TRID_DEVICE_INFO

type TtagRID_DEVICE_INFO = TRID_DEVICE_INFO

type tagRID_DEVICE_INFO = TtagRID_DEVICE_INFO

type TPRID_DEVICE_INFO = uintptr

type PRID_DEVICE_INFO = TPRID_DEVICE_INFO

type TLPRID_DEVICE_INFO = uintptr

type LPRID_DEVICE_INFO = TLPRID_DEVICE_INFO

type TRAWINPUTDEVICE = struct {
	FusUsagePage TUSHORT
	FusUsage     TUSHORT
	FdwFlags     TDWORD
	FhwndTarget  THWND
}

type RAWINPUTDEVICE = TRAWINPUTDEVICE

type TtagRAWINPUTDEVICE = TRAWINPUTDEVICE

type tagRAWINPUTDEVICE = TtagRAWINPUTDEVICE

type TPRAWINPUTDEVICE = uintptr

type PRAWINPUTDEVICE = TPRAWINPUTDEVICE

type TLPRAWINPUTDEVICE = uintptr

type LPRAWINPUTDEVICE = TLPRAWINPUTDEVICE

type TPCRAWINPUTDEVICE = uintptr

type PCRAWINPUTDEVICE = TPCRAWINPUTDEVICE

type TRAWINPUTDEVICELIST = struct {
	FhDevice THANDLE
	FdwType  TDWORD
}

type RAWINPUTDEVICELIST = TRAWINPUTDEVICELIST

type TtagRAWINPUTDEVICELIST = TRAWINPUTDEVICELIST

type tagRAWINPUTDEVICELIST = TtagRAWINPUTDEVICELIST

type TPRAWINPUTDEVICELIST = uintptr

type PRAWINPUTDEVICELIST = TPRAWINPUTDEVICELIST

type TPOINTER_DEVICE_TYPE = uint32

type POINTER_DEVICE_TYPE = TPOINTER_DEVICE_TYPE

type _tagPOINTER_DEVICE_TYPE = uint32

const _POINTER_DEVICE_TYPE_INTEGRATED_PEN = 1
const _POINTER_DEVICE_TYPE_EXTERNAL_PEN = 2
const _POINTER_DEVICE_TYPE_TOUCH = 3
const _POINTER_DEVICE_TYPE_TOUCH_PAD = 4
const _POINTER_DEVICE_TYPE_MAX = 4294967295

type TPOINTER_DEVICE_INFO = struct {
	FdisplayOrientation TDWORD
	Fdevice             THANDLE
	FpointerDeviceType  TPOINTER_DEVICE_TYPE
	Fmonitor            THMONITOR
	FstartingCursorId   TULONG
	FmaxActiveContacts  TUSHORT
	FproductString      [520]TWCHAR
}

type POINTER_DEVICE_INFO = TPOINTER_DEVICE_INFO

type TtagPOINTER_DEVICE_INFO = TPOINTER_DEVICE_INFO

type tagPOINTER_DEVICE_INFO = TtagPOINTER_DEVICE_INFO

type TPOINTER_DEVICE_PROPERTY = struct {
	FlogicalMin   TINT32
	FlogicalMax   TINT32
	FphysicalMin  TINT32
	FphysicalMax  TINT32
	Funit         TUINT32
	FunitExponent TUINT32
	FusagePageId  TUSHORT
	FusageId      TUSHORT
}

type POINTER_DEVICE_PROPERTY = TPOINTER_DEVICE_PROPERTY

type TtagPOINTER_DEVICE_PROPERTY = TPOINTER_DEVICE_PROPERTY

type tagPOINTER_DEVICE_PROPERTY = TtagPOINTER_DEVICE_PROPERTY

type TPOINTER_DEVICE_CURSOR_TYPE = uint32

type POINTER_DEVICE_CURSOR_TYPE = TPOINTER_DEVICE_CURSOR_TYPE

type _tagPOINTER_DEVICE_CURSOR_TYPE = uint32

const _POINTER_DEVICE_CURSOR_TYPE_UNKNOWN = 0
const _POINTER_DEVICE_CURSOR_TYPE_TIP = 1
const _POINTER_DEVICE_CURSOR_TYPE_ERASER = 2
const _POINTER_DEVICE_CURSOR_TYPE_MAX = 4294967295

type TPOINTER_DEVICE_CURSOR_INFO = struct {
	FcursorId TUINT32
	Fcursor   TPOINTER_DEVICE_CURSOR_TYPE
}

type POINTER_DEVICE_CURSOR_INFO = TPOINTER_DEVICE_CURSOR_INFO

type TtagPOINTER_DEVICE_CURSOR_INFO = TPOINTER_DEVICE_CURSOR_INFO

type tagPOINTER_DEVICE_CURSOR_INFO = TtagPOINTER_DEVICE_CURSOR_INFO

type TCHANGEFILTERSTRUCT = struct {
	FcbSize    TDWORD
	FExtStatus TDWORD
}

type CHANGEFILTERSTRUCT = TCHANGEFILTERSTRUCT

type TtagCHANGEFILTERSTRUCT = TCHANGEFILTERSTRUCT

type tagCHANGEFILTERSTRUCT = TtagCHANGEFILTERSTRUCT

type TPCHANGEFILTERSTRUCT = uintptr

type PCHANGEFILTERSTRUCT = TPCHANGEFILTERSTRUCT

type THGESTUREINFO__ = struct {
	Funused int32
}

type HGESTUREINFO__ = THGESTUREINFO__

type THGESTUREINFO = uintptr

type HGESTUREINFO = THGESTUREINFO

type TGESTUREINFO = struct {
	F__ccgo_align  [0]uint32
	FcbSize        TUINT
	FdwFlags       TDWORD
	FdwID          TDWORD
	FhwndTarget    THWND
	FptsLocation   TPOINTS
	FdwInstanceID  TDWORD
	FdwSequenceID  TDWORD
	F__ccgo_align7 [4]byte
	FullArguments  TULONGLONG
	FcbExtraArgs   TUINT
	F__ccgo_pad9   [4]byte
}

type GESTUREINFO = TGESTUREINFO

type TtagGESTUREINFO = TGESTUREINFO

type tagGESTUREINFO = TtagGESTUREINFO

type TPGESTUREINFO = uintptr

type PGESTUREINFO = TPGESTUREINFO

type TPCGESTUREINFO = uintptr

type PCGESTUREINFO = TPCGESTUREINFO

type TGESTURENOTIFYSTRUCT = struct {
	FcbSize       TUINT
	FdwFlags      TDWORD
	FhwndTarget   THWND
	FptsLocation  TPOINTS
	FdwInstanceID TDWORD
}

type GESTURENOTIFYSTRUCT = TGESTURENOTIFYSTRUCT

type TtagGESTURENOTIFYSTRUCT = TGESTURENOTIFYSTRUCT

type tagGESTURENOTIFYSTRUCT = TtagGESTURENOTIFYSTRUCT

type TPGESTURENOTIFYSTRUCT = uintptr

type PGESTURENOTIFYSTRUCT = TPGESTURENOTIFYSTRUCT

type TGESTURECONFIG = struct {
	FdwID    TDWORD
	FdwWant  TDWORD
	FdwBlock TDWORD
}

type GESTURECONFIG = TGESTURECONFIG

type TtagGESTURECONFIG = TGESTURECONFIG

type tagGESTURECONFIG = TtagGESTURECONFIG

type TPGESTURECONFIG = uintptr

type PGESTURECONFIG = TPGESTURECONFIG

type TINPUT_MESSAGE_DEVICE_TYPE = int32

type INPUT_MESSAGE_DEVICE_TYPE = TINPUT_MESSAGE_DEVICE_TYPE

type _tagINPUT_MESSAGE_DEVICE_TYPE = int32

const _IMDT_UNAVAILABLE = 0
const _IMDT_KEYBOARD = 1
const _IMDT_MOUSE = 2
const _IMDT_TOUCH = 4
const _IMDT_PEN = 8
const _IMDT_TOUCHPAD = 16

type TINPUT_MESSAGE_ORIGIN_ID = int32

type INPUT_MESSAGE_ORIGIN_ID = TINPUT_MESSAGE_ORIGIN_ID

type _tagINPUT_MESSAGE_ORIGIN_ID = int32

const _IMO_UNAVAILABLE = 0
const _IMO_HARDWARE = 1
const _IMO_INJECTED = 2
const _IMO_SYSTEM = 4

type TINPUT_MESSAGE_SOURCE = struct {
	FdeviceType TINPUT_MESSAGE_DEVICE_TYPE
	ForiginId   TINPUT_MESSAGE_ORIGIN_ID
}

type INPUT_MESSAGE_SOURCE = TINPUT_MESSAGE_SOURCE

type TtagINPUT_MESSAGE_SOURCE = TINPUT_MESSAGE_SOURCE

type tagINPUT_MESSAGE_SOURCE = TtagINPUT_MESSAGE_SOURCE

type TAR_STATE = int32

type AR_STATE = TAR_STATE

type _tagAR_STATE = int32

const _AR_ENABLED = 0
const _AR_DISABLED = 1
const _AR_SUPPRESSED = 2
const _AR_REMOTESESSION = 4
const _AR_MULTIMON = 8
const _AR_NOSENSOR = 16
const _AR_NOT_SUPPORTED = 32
const _AR_DOCKED = 64
const _AR_LAPTOP = 128

type TPAR_STATE = uintptr

type PAR_STATE = TPAR_STATE

type TORIENTATION_PREFERENCE = int32

type ORIENTATION_PREFERENCE = TORIENTATION_PREFERENCE

type _ORIENTATION_PREFERENCE = int32

const _ORIENTATION_PREFERENCE_NONE = 0
const _ORIENTATION_PREFERENCE_LANDSCAPE = 1
const _ORIENTATION_PREFERENCE_PORTRAIT = 2
const _ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 4
const _ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 8

type TINPUT_TRANSFORM = struct {
	F__ccgo0_0 struct {
		Fm         [0][4][4]float32
		F__ccgo0_0 struct {
			F_11 float32
			F_12 float32
			F_13 float32
			F_14 float32
			F_21 float32
			F_22 float32
			F_23 float32
			F_24 float32
			F_31 float32
			F_32 float32
			F_33 float32
			F_34 float32
			F_41 float32
			F_42 float32
			F_43 float32
			F_44 float32
		}
	}
}

type INPUT_TRANSFORM = TINPUT_TRANSFORM

type TtagINPUT_TRANSFORM = TINPUT_TRANSFORM

type tagINPUT_TRANSFORM = TtagINPUT_TRANSFORM

type TLGRPID = uint32

type LGRPID = TLGRPID

type TLCTYPE = uint32

type LCTYPE = TLCTYPE

type TCALTYPE = uint32

type CALTYPE = TCALTYPE

type TCALID = uint32

type CALID = TCALID

type TCPINFO = struct {
	FMaxCharSize TUINT
	FDefaultChar [2]TBYTE
	FLeadByte    [12]TBYTE
}

type CPINFO = TCPINFO

type T_cpinfo = TCPINFO

type _cpinfo = T_cpinfo

type TLPCPINFO = uintptr

type LPCPINFO = TLPCPINFO

type TCPINFOEXA = struct {
	FMaxCharSize        TUINT
	FDefaultChar        [2]TBYTE
	FLeadByte           [12]TBYTE
	FUnicodeDefaultChar TWCHAR
	FCodePage           TUINT
	FCodePageName       [260]TCHAR
}

type CPINFOEXA = TCPINFOEXA

type T_cpinfoexA = TCPINFOEXA

type _cpinfoexA = T_cpinfoexA

type TLPCPINFOEXA = uintptr

type LPCPINFOEXA = TLPCPINFOEXA

type TCPINFOEXW = struct {
	FMaxCharSize        TUINT
	FDefaultChar        [2]TBYTE
	FLeadByte           [12]TBYTE
	FUnicodeDefaultChar TWCHAR
	FCodePage           TUINT
	FCodePageName       [260]TWCHAR
}

type CPINFOEXW = TCPINFOEXW

type T_cpinfoexW = TCPINFOEXW

type _cpinfoexW = T_cpinfoexW

type TLPCPINFOEXW = uintptr

type LPCPINFOEXW = TLPCPINFOEXW

type TCPINFOEX = struct {
	FMaxCharSize        TUINT
	FDefaultChar        [2]TBYTE
	FLeadByte           [12]TBYTE
	FUnicodeDefaultChar TWCHAR
	FCodePage           TUINT
	FCodePageName       [260]TCHAR
}

type CPINFOEX = TCPINFOEX

type TLPCPINFOEX = uintptr

type LPCPINFOEX = TLPCPINFOEX

type TNUMBERFMTA = struct {
	FNumDigits     TUINT
	FLeadingZero   TUINT
	FGrouping      TUINT
	FlpDecimalSep  TLPSTR
	FlpThousandSep TLPSTR
	FNegativeOrder TUINT
}

type NUMBERFMTA = TNUMBERFMTA

type T_numberfmtA = TNUMBERFMTA

type _numberfmtA = T_numberfmtA

type TLPNUMBERFMTA = uintptr

type LPNUMBERFMTA = TLPNUMBERFMTA

type TNUMBERFMTW = struct {
	FNumDigits     TUINT
	FLeadingZero   TUINT
	FGrouping      TUINT
	FlpDecimalSep  TLPWSTR
	FlpThousandSep TLPWSTR
	FNegativeOrder TUINT
}

type NUMBERFMTW = TNUMBERFMTW

type T_numberfmtW = TNUMBERFMTW

type _numberfmtW = T_numberfmtW

type TLPNUMBERFMTW = uintptr

type LPNUMBERFMTW = TLPNUMBERFMTW

type TNUMBERFMT = struct {
	FNumDigits     TUINT
	FLeadingZero   TUINT
	FGrouping      TUINT
	FlpDecimalSep  TLPSTR
	FlpThousandSep TLPSTR
	FNegativeOrder TUINT
}

type NUMBERFMT = TNUMBERFMT

type TLPNUMBERFMT = uintptr

type LPNUMBERFMT = TLPNUMBERFMT

type TCURRENCYFMTA = struct {
	FNumDigits        TUINT
	FLeadingZero      TUINT
	FGrouping         TUINT
	FlpDecimalSep     TLPSTR
	FlpThousandSep    TLPSTR
	FNegativeOrder    TUINT
	FPositiveOrder    TUINT
	FlpCurrencySymbol TLPSTR
}

type CURRENCYFMTA = TCURRENCYFMTA

type T_currencyfmtA = TCURRENCYFMTA

type _currencyfmtA = T_currencyfmtA

type TLPCURRENCYFMTA = uintptr

type LPCURRENCYFMTA = TLPCURRENCYFMTA

type TCURRENCYFMTW = struct {
	FNumDigits        TUINT
	FLeadingZero      TUINT
	FGrouping         TUINT
	FlpDecimalSep     TLPWSTR
	FlpThousandSep    TLPWSTR
	FNegativeOrder    TUINT
	FPositiveOrder    TUINT
	FlpCurrencySymbol TLPWSTR
}

type CURRENCYFMTW = TCURRENCYFMTW

type T_currencyfmtW = TCURRENCYFMTW

type _currencyfmtW = T_currencyfmtW

type TLPCURRENCYFMTW = uintptr

type LPCURRENCYFMTW = TLPCURRENCYFMTW

type TCURRENCYFMT = struct {
	FNumDigits        TUINT
	FLeadingZero      TUINT
	FGrouping         TUINT
	FlpDecimalSep     TLPSTR
	FlpThousandSep    TLPSTR
	FNegativeOrder    TUINT
	FPositiveOrder    TUINT
	FlpCurrencySymbol TLPSTR
}

type CURRENCYFMT = TCURRENCYFMT

type TLPCURRENCYFMT = uintptr

type LPCURRENCYFMT = TLPCURRENCYFMT

type _SYSNLS_FUNCTION = int32

const _COMPARE_STRING = 1

type TNLS_FUNCTION = uint32

type NLS_FUNCTION = TNLS_FUNCTION

type TNLSVERSIONINFO = struct {
	FdwNLSVersionInfoSize TDWORD
	FdwNLSVersion         TDWORD
	FdwDefinedVersion     TDWORD
	FdwEffectiveId        TDWORD
	FguidCustomVersion    TGUID
}

type NLSVERSIONINFO = TNLSVERSIONINFO

type T_nlsversioninfo = TNLSVERSIONINFO

type _nlsversioninfo = T_nlsversioninfo

type TLPNLSVERSIONINFO = uintptr

type LPNLSVERSIONINFO = TLPNLSVERSIONINFO

type TNLSVERSIONINFOEX = struct {
	FdwNLSVersionInfoSize TDWORD
	FdwNLSVersion         TDWORD
	FdwDefinedVersion     TDWORD
	FdwEffectiveId        TDWORD
	FguidCustomVersion    TGUID
}

type NLSVERSIONINFOEX = TNLSVERSIONINFOEX

type T_nlsversioninfoex = TNLSVERSIONINFOEX

type _nlsversioninfoex = T_nlsversioninfoex

type TLPNLSVERSIONINFOEX = uintptr

type LPNLSVERSIONINFOEX = TLPNLSVERSIONINFOEX

type TGEOID = int32

type GEOID = TGEOID

type TGEOTYPE = uint32

type GEOTYPE = TGEOTYPE

type TGEOCLASS = uint32

type GEOCLASS = TGEOCLASS

type _SYSGEOTYPE = int32

const _GEO_NATION = 1
const _GEO_LATITUDE = 2
const _GEO_LONGITUDE = 3
const _GEO_ISO2 = 4
const _GEO_ISO3 = 5
const _GEO_RFC1766 = 6
const _GEO_LCID = 7
const _GEO_FRIENDLYNAME = 8
const _GEO_OFFICIALNAME = 9
const _GEO_TIMEZONES = 10
const _GEO_OFFICIALLANGUAGES = 11
const _GEO_ISO_UN_NUMBER = 12
const _GEO_PARENT = 13
const _GEO_DIALINGCODE = 14
const _GEO_CURRENCYCODE = 15
const _GEO_CURRENCYSYMBOL = 16

type _SYSGEOCLASS = int32

const _GEOCLASS_NATION = 16
const _GEOCLASS_REGION = 14
const _GEOCLASS_ALL = 0

type TNORM_FORM = int32

type NORM_FORM = TNORM_FORM

type __NORM_FORM = int32

const _NormalizationOther = 0
const _NormalizationC = 1
const _NormalizationD = 2
const _NormalizationKC = 5
const _NormalizationKD = 6

type TLANGUAGEGROUP_ENUMPROCA = uintptr

type LANGUAGEGROUP_ENUMPROCA = TLANGUAGEGROUP_ENUMPROCA

type TLANGGROUPLOCALE_ENUMPROCA = uintptr

type LANGGROUPLOCALE_ENUMPROCA = TLANGGROUPLOCALE_ENUMPROCA

type TUILANGUAGE_ENUMPROCA = uintptr

type UILANGUAGE_ENUMPROCA = TUILANGUAGE_ENUMPROCA

type TCODEPAGE_ENUMPROCA = uintptr

type CODEPAGE_ENUMPROCA = TCODEPAGE_ENUMPROCA

type TDATEFMT_ENUMPROCA = uintptr

type DATEFMT_ENUMPROCA = TDATEFMT_ENUMPROCA

type TDATEFMT_ENUMPROCEXA = uintptr

type DATEFMT_ENUMPROCEXA = TDATEFMT_ENUMPROCEXA

type TTIMEFMT_ENUMPROCA = uintptr

type TIMEFMT_ENUMPROCA = TTIMEFMT_ENUMPROCA

type TCALINFO_ENUMPROCA = uintptr

type CALINFO_ENUMPROCA = TCALINFO_ENUMPROCA

type TCALINFO_ENUMPROCEXA = uintptr

type CALINFO_ENUMPROCEXA = TCALINFO_ENUMPROCEXA

type TLOCALE_ENUMPROCA = uintptr

type LOCALE_ENUMPROCA = TLOCALE_ENUMPROCA

type TLOCALE_ENUMPROCW = uintptr

type LOCALE_ENUMPROCW = TLOCALE_ENUMPROCW

type TLANGUAGEGROUP_ENUMPROCW = uintptr

type LANGUAGEGROUP_ENUMPROCW = TLANGUAGEGROUP_ENUMPROCW

type TLANGGROUPLOCALE_ENUMPROCW = uintptr

type LANGGROUPLOCALE_ENUMPROCW = TLANGGROUPLOCALE_ENUMPROCW

type TUILANGUAGE_ENUMPROCW = uintptr

type UILANGUAGE_ENUMPROCW = TUILANGUAGE_ENUMPROCW

type TCODEPAGE_ENUMPROCW = uintptr

type CODEPAGE_ENUMPROCW = TCODEPAGE_ENUMPROCW

type TDATEFMT_ENUMPROCW = uintptr

type DATEFMT_ENUMPROCW = TDATEFMT_ENUMPROCW

type TDATEFMT_ENUMPROCEXW = uintptr

type DATEFMT_ENUMPROCEXW = TDATEFMT_ENUMPROCEXW

type TTIMEFMT_ENUMPROCW = uintptr

type TIMEFMT_ENUMPROCW = TTIMEFMT_ENUMPROCW

type TCALINFO_ENUMPROCW = uintptr

type CALINFO_ENUMPROCW = TCALINFO_ENUMPROCW

type TCALINFO_ENUMPROCEXW = uintptr

type CALINFO_ENUMPROCEXW = TCALINFO_ENUMPROCEXW

type TGEO_ENUMPROC = uintptr

type GEO_ENUMPROC = TGEO_ENUMPROC

type TFILEMUIINFO = struct {
	FdwSize               TDWORD
	FdwVersion            TDWORD
	FdwFileType           TDWORD
	FpChecksum            [16]TBYTE
	FpServiceChecksum     [16]TBYTE
	FdwLanguageNameOffset TDWORD
	FdwTypeIDMainSize     TDWORD
	FdwTypeIDMainOffset   TDWORD
	FdwTypeNameMainOffset TDWORD
	FdwTypeIDMUISize      TDWORD
	FdwTypeIDMUIOffset    TDWORD
	FdwTypeNameMUIOffset  TDWORD
	FabBuffer             [8]TBYTE
}

type FILEMUIINFO = TFILEMUIINFO

type T_FILEMUIINFO = TFILEMUIINFO

type _FILEMUIINFO = T_FILEMUIINFO

type TPFILEMUIINFO = uintptr

type PFILEMUIINFO = TPFILEMUIINFO

type TCALINFO_ENUMPROCEXEX = uintptr

type CALINFO_ENUMPROCEXEX = TCALINFO_ENUMPROCEXEX

type TDATEFMT_ENUMPROCEXEX = uintptr

type DATEFMT_ENUMPROCEXEX = TDATEFMT_ENUMPROCEXEX

type TTIMEFMT_ENUMPROCEX = uintptr

type TIMEFMT_ENUMPROCEX = TTIMEFMT_ENUMPROCEX

type TLOCALE_ENUMPROCEX = uintptr

type LOCALE_ENUMPROCEX = TLOCALE_ENUMPROCEX

type TCOORD = struct {
	FX TSHORT
	FY TSHORT
}

type COORD = TCOORD

type T_COORD = TCOORD

type _COORD = T_COORD

type TPCOORD = uintptr

type PCOORD = TPCOORD

type TSMALL_RECT = struct {
	FLeft   TSHORT
	FTop    TSHORT
	FRight  TSHORT
	FBottom TSHORT
}

type SMALL_RECT = TSMALL_RECT

type T_SMALL_RECT = TSMALL_RECT

type _SMALL_RECT = T_SMALL_RECT

type TPSMALL_RECT = uintptr

type PSMALL_RECT = TPSMALL_RECT

type TKEY_EVENT_RECORD = struct {
	FbKeyDown         TWINBOOL
	FwRepeatCount     TWORD
	FwVirtualKeyCode  TWORD
	FwVirtualScanCode TWORD
	FuChar            struct {
		FAsciiChar   [0]TCHAR
		FUnicodeChar TWCHAR
	}
	FdwControlKeyState TDWORD
}

type KEY_EVENT_RECORD = TKEY_EVENT_RECORD

type T_KEY_EVENT_RECORD = TKEY_EVENT_RECORD

type _KEY_EVENT_RECORD = T_KEY_EVENT_RECORD

type TPKEY_EVENT_RECORD = uintptr

type PKEY_EVENT_RECORD = TPKEY_EVENT_RECORD

type TMOUSE_EVENT_RECORD = struct {
	FdwMousePosition   TCOORD
	FdwButtonState     TDWORD
	FdwControlKeyState TDWORD
	FdwEventFlags      TDWORD
}

type MOUSE_EVENT_RECORD = TMOUSE_EVENT_RECORD

type T_MOUSE_EVENT_RECORD = TMOUSE_EVENT_RECORD

type _MOUSE_EVENT_RECORD = T_MOUSE_EVENT_RECORD

type TPMOUSE_EVENT_RECORD = uintptr

type PMOUSE_EVENT_RECORD = TPMOUSE_EVENT_RECORD

type TWINDOW_BUFFER_SIZE_RECORD = struct {
	FdwSize TCOORD
}

type WINDOW_BUFFER_SIZE_RECORD = TWINDOW_BUFFER_SIZE_RECORD

type T_WINDOW_BUFFER_SIZE_RECORD = TWINDOW_BUFFER_SIZE_RECORD

type _WINDOW_BUFFER_SIZE_RECORD = T_WINDOW_BUFFER_SIZE_RECORD

type TPWINDOW_BUFFER_SIZE_RECORD = uintptr

type PWINDOW_BUFFER_SIZE_RECORD = TPWINDOW_BUFFER_SIZE_RECORD

type TMENU_EVENT_RECORD = struct {
	FdwCommandId TUINT
}

type MENU_EVENT_RECORD = TMENU_EVENT_RECORD

type T_MENU_EVENT_RECORD = TMENU_EVENT_RECORD

type _MENU_EVENT_RECORD = T_MENU_EVENT_RECORD

type TPMENU_EVENT_RECORD = uintptr

type PMENU_EVENT_RECORD = TPMENU_EVENT_RECORD

type TFOCUS_EVENT_RECORD = struct {
	FbSetFocus TWINBOOL
}

type FOCUS_EVENT_RECORD = TFOCUS_EVENT_RECORD

type T_FOCUS_EVENT_RECORD = TFOCUS_EVENT_RECORD

type _FOCUS_EVENT_RECORD = T_FOCUS_EVENT_RECORD

type TPFOCUS_EVENT_RECORD = uintptr

type PFOCUS_EVENT_RECORD = TPFOCUS_EVENT_RECORD

type TINPUT_RECORD = struct {
	FEventType TWORD
	FEvent     struct {
		FMouseEvent            [0]TMOUSE_EVENT_RECORD
		FWindowBufferSizeEvent [0]TWINDOW_BUFFER_SIZE_RECORD
		FMenuEvent             [0]TMENU_EVENT_RECORD
		FFocusEvent            [0]TFOCUS_EVENT_RECORD
		FKeyEvent              TKEY_EVENT_RECORD
	}
}

type INPUT_RECORD = TINPUT_RECORD

type T_INPUT_RECORD = TINPUT_RECORD

type _INPUT_RECORD = T_INPUT_RECORD

type TPINPUT_RECORD = uintptr

type PINPUT_RECORD = TPINPUT_RECORD

type TCHAR_INFO = struct {
	FChar struct {
		FAsciiChar   [0]TCHAR
		FUnicodeChar TWCHAR
	}
	FAttributes TWORD
}

type CHAR_INFO = TCHAR_INFO

type T_CHAR_INFO = TCHAR_INFO

type _CHAR_INFO = T_CHAR_INFO

type TPCHAR_INFO = uintptr

type PCHAR_INFO = TPCHAR_INFO

type TCONSOLE_SCREEN_BUFFER_INFO = struct {
	FdwSize              TCOORD
	FdwCursorPosition    TCOORD
	FwAttributes         TWORD
	FsrWindow            TSMALL_RECT
	FdwMaximumWindowSize TCOORD
}

type CONSOLE_SCREEN_BUFFER_INFO = TCONSOLE_SCREEN_BUFFER_INFO

type T_CONSOLE_SCREEN_BUFFER_INFO = TCONSOLE_SCREEN_BUFFER_INFO

type _CONSOLE_SCREEN_BUFFER_INFO = T_CONSOLE_SCREEN_BUFFER_INFO

type TPCONSOLE_SCREEN_BUFFER_INFO = uintptr

type PCONSOLE_SCREEN_BUFFER_INFO = TPCONSOLE_SCREEN_BUFFER_INFO

type TCONSOLE_CURSOR_INFO = struct {
	FdwSize   TDWORD
	FbVisible TWINBOOL
}

type CONSOLE_CURSOR_INFO = TCONSOLE_CURSOR_INFO

type T_CONSOLE_CURSOR_INFO = TCONSOLE_CURSOR_INFO

type _CONSOLE_CURSOR_INFO = T_CONSOLE_CURSOR_INFO

type TPCONSOLE_CURSOR_INFO = uintptr

type PCONSOLE_CURSOR_INFO = TPCONSOLE_CURSOR_INFO

type TCONSOLE_FONT_INFO = struct {
	FnFont      TDWORD
	FdwFontSize TCOORD
}

type CONSOLE_FONT_INFO = TCONSOLE_FONT_INFO

type T_CONSOLE_FONT_INFO = TCONSOLE_FONT_INFO

type _CONSOLE_FONT_INFO = T_CONSOLE_FONT_INFO

type TPCONSOLE_FONT_INFO = uintptr

type PCONSOLE_FONT_INFO = TPCONSOLE_FONT_INFO

type TCONSOLE_SELECTION_INFO = struct {
	FdwFlags           TDWORD
	FdwSelectionAnchor TCOORD
	FsrSelection       TSMALL_RECT
}

type CONSOLE_SELECTION_INFO = TCONSOLE_SELECTION_INFO

type T_CONSOLE_SELECTION_INFO = TCONSOLE_SELECTION_INFO

type _CONSOLE_SELECTION_INFO = T_CONSOLE_SELECTION_INFO

type TPCONSOLE_SELECTION_INFO = uintptr

type PCONSOLE_SELECTION_INFO = TPCONSOLE_SELECTION_INFO

type TPHANDLER_ROUTINE = uintptr

type PHANDLER_ROUTINE = TPHANDLER_ROUTINE

type TCONSOLE_FONT_INFOEX = struct {
	FcbSize     TULONG
	FnFont      TDWORD
	FdwFontSize TCOORD
	FFontFamily TUINT
	FFontWeight TUINT
	FFaceName   [32]TWCHAR
}

type CONSOLE_FONT_INFOEX = TCONSOLE_FONT_INFOEX

type T_CONSOLE_FONT_INFOEX = TCONSOLE_FONT_INFOEX

type _CONSOLE_FONT_INFOEX = T_CONSOLE_FONT_INFOEX

type TPCONSOLE_FONT_INFOEX = uintptr

type PCONSOLE_FONT_INFOEX = TPCONSOLE_FONT_INFOEX

type TCONSOLE_HISTORY_INFO = struct {
	FcbSize                 TUINT
	FHistoryBufferSize      TUINT
	FNumberOfHistoryBuffers TUINT
	FdwFlags                TDWORD
}

type CONSOLE_HISTORY_INFO = TCONSOLE_HISTORY_INFO

type T_CONSOLE_HISTORY_INFO = TCONSOLE_HISTORY_INFO

type _CONSOLE_HISTORY_INFO = T_CONSOLE_HISTORY_INFO

type TPCONSOLE_HISTORY_INFO = uintptr

type PCONSOLE_HISTORY_INFO = TPCONSOLE_HISTORY_INFO

type TCONSOLE_READCONSOLE_CONTROL = struct {
	FnLength           TULONG
	FnInitialChars     TULONG
	FdwCtrlWakeupMask  TULONG
	FdwControlKeyState TULONG
}

type CONSOLE_READCONSOLE_CONTROL = TCONSOLE_READCONSOLE_CONTROL

type T_CONSOLE_READCONSOLE_CONTROL = TCONSOLE_READCONSOLE_CONTROL

type _CONSOLE_READCONSOLE_CONTROL = T_CONSOLE_READCONSOLE_CONTROL

type TPCONSOLE_READCONSOLE_CONTROL = uintptr

type PCONSOLE_READCONSOLE_CONTROL = TPCONSOLE_READCONSOLE_CONTROL

type TCONSOLE_SCREEN_BUFFER_INFOEX = struct {
	FcbSize               TULONG
	FdwSize               TCOORD
	FdwCursorPosition     TCOORD
	FwAttributes          TWORD
	FsrWindow             TSMALL_RECT
	FdwMaximumWindowSize  TCOORD
	FwPopupAttributes     TWORD
	FbFullscreenSupported TWINBOOL
	FColorTable           [16]TCOLORREF
}

type CONSOLE_SCREEN_BUFFER_INFOEX = TCONSOLE_SCREEN_BUFFER_INFOEX

type T_CONSOLE_SCREEN_BUFFER_INFOEX = TCONSOLE_SCREEN_BUFFER_INFOEX

type _CONSOLE_SCREEN_BUFFER_INFOEX = T_CONSOLE_SCREEN_BUFFER_INFOEX

type TPCONSOLE_SCREEN_BUFFER_INFOEX = uintptr

type PCONSOLE_SCREEN_BUFFER_INFOEX = TPCONSOLE_SCREEN_BUFFER_INFOEX

type TVS_FIXEDFILEINFO = struct {
	FdwSignature        TDWORD
	FdwStrucVersion     TDWORD
	FdwFileVersionMS    TDWORD
	FdwFileVersionLS    TDWORD
	FdwProductVersionMS TDWORD
	FdwProductVersionLS TDWORD
	FdwFileFlagsMask    TDWORD
	FdwFileFlags        TDWORD
	FdwFileOS           TDWORD
	FdwFileType         TDWORD
	FdwFileSubtype      TDWORD
	FdwFileDateMS       TDWORD
	FdwFileDateLS       TDWORD
}

type VS_FIXEDFILEINFO = TVS_FIXEDFILEINFO

type TtagVS_FIXEDFILEINFO = TVS_FIXEDFILEINFO

type tagVS_FIXEDFILEINFO = TtagVS_FIXEDFILEINFO

type TREGSAM = uint32

type REGSAM = TREGSAM

type TLSTATUS = int32

type LSTATUS = TLSTATUS

type Tval_context = struct {
	Fvaluelen      int32
	Fvalue_context TLPVOID
	Fval_buff_ptr  TLPVOID
}

type val_context = Tval_context

type TPVALCONTEXT = uintptr

type PVALCONTEXT = TPVALCONTEXT

type TPVALUEA = struct {
	Fpv_valuename     TLPSTR
	Fpv_valuelen      int32
	Fpv_value_context TLPVOID
	Fpv_type          TDWORD
}

type PVALUEA = TPVALUEA

type TpvalueA = TPVALUEA

type pvalueA = TpvalueA

type TPPVALUEA = uintptr

type PPVALUEA = TPPVALUEA

type TPVALUEW = struct {
	Fpv_valuename     TLPWSTR
	Fpv_valuelen      int32
	Fpv_value_context TLPVOID
	Fpv_type          TDWORD
}

type PVALUEW = TPVALUEW

type TpvalueW = TPVALUEW

type pvalueW = TpvalueW

type TPPVALUEW = uintptr

type PPVALUEW = TPPVALUEW

type TPVALUE = struct {
	Fpv_valuename     TLPSTR
	Fpv_valuelen      int32
	Fpv_value_context TLPVOID
	Fpv_type          TDWORD
}

type PVALUE = TPVALUE

type TPPVALUE = uintptr

type PPVALUE = TPPVALUE

type TPQUERYHANDLER = uintptr

type PQUERYHANDLER = TPQUERYHANDLER

type TREG_PROVIDER = struct {
	Fpi_R0_1val     TPQUERYHANDLER
	Fpi_R0_allvals  TPQUERYHANDLER
	Fpi_R3_1val     TPQUERYHANDLER
	Fpi_R3_allvals  TPQUERYHANDLER
	Fpi_flags       TDWORD
	Fpi_key_context TLPVOID
}

type REG_PROVIDER = TREG_PROVIDER

type Tprovider_info = TREG_PROVIDER

type provider_info = Tprovider_info

type TPPROVIDER = uintptr

type PPROVIDER = TPPROVIDER

type TVALENTA = struct {
	Fve_valuename TLPSTR
	Fve_valuelen  TDWORD
	Fve_valueptr  TDWORD_PTR
	Fve_type      TDWORD
}

type VALENTA = TVALENTA

type Tvalue_entA = TVALENTA

type value_entA = Tvalue_entA

type TPVALENTA = uintptr

type PVALENTA = TPVALENTA

type TVALENTW = struct {
	Fve_valuename TLPWSTR
	Fve_valuelen  TDWORD
	Fve_valueptr  TDWORD_PTR
	Fve_type      TDWORD
}

type VALENTW = TVALENTW

type Tvalue_entW = TVALENTW

type value_entW = Tvalue_entW

type TPVALENTW = uintptr

type PVALENTW = TPVALENTW

type TVALENT = struct {
	Fve_valuename TLPSTR
	Fve_valuelen  TDWORD
	Fve_valueptr  TDWORD_PTR
	Fve_type      TDWORD
}

type VALENT = TVALENT

type TPVALENT = uintptr

type PVALENT = TPVALENT

type TNETRESOURCEA = struct {
	FdwScope       TDWORD
	FdwType        TDWORD
	FdwDisplayType TDWORD
	FdwUsage       TDWORD
	FlpLocalName   TLPSTR
	FlpRemoteName  TLPSTR
	FlpComment     TLPSTR
	FlpProvider    TLPSTR
}

type NETRESOURCEA = TNETRESOURCEA

type T_NETRESOURCEA = TNETRESOURCEA

type _NETRESOURCEA = T_NETRESOURCEA

type TLPNETRESOURCEA = uintptr

type LPNETRESOURCEA = TLPNETRESOURCEA

type TNETRESOURCEW = struct {
	FdwScope       TDWORD
	FdwType        TDWORD
	FdwDisplayType TDWORD
	FdwUsage       TDWORD
	FlpLocalName   TLPWSTR
	FlpRemoteName  TLPWSTR
	FlpComment     TLPWSTR
	FlpProvider    TLPWSTR
}

type NETRESOURCEW = TNETRESOURCEW

type T_NETRESOURCEW = TNETRESOURCEW

type _NETRESOURCEW = T_NETRESOURCEW

type TLPNETRESOURCEW = uintptr

type LPNETRESOURCEW = TLPNETRESOURCEW

type TNETRESOURCE = struct {
	FdwScope       TDWORD
	FdwType        TDWORD
	FdwDisplayType TDWORD
	FdwUsage       TDWORD
	FlpLocalName   TLPSTR
	FlpRemoteName  TLPSTR
	FlpComment     TLPSTR
	FlpProvider    TLPSTR
}

type NETRESOURCE = TNETRESOURCE

type TLPNETRESOURCE = uintptr

type LPNETRESOURCE = TLPNETRESOURCE

type TCONNECTDLGSTRUCTA = struct {
	FcbStructure TDWORD
	FhwndOwner   THWND
	FlpConnRes   TLPNETRESOURCEA
	FdwFlags     TDWORD
	FdwDevNum    TDWORD
}

type CONNECTDLGSTRUCTA = TCONNECTDLGSTRUCTA

type T_CONNECTDLGSTRUCTA = TCONNECTDLGSTRUCTA

type _CONNECTDLGSTRUCTA = T_CONNECTDLGSTRUCTA

type TLPCONNECTDLGSTRUCTA = uintptr

type LPCONNECTDLGSTRUCTA = TLPCONNECTDLGSTRUCTA

type TCONNECTDLGSTRUCTW = struct {
	FcbStructure TDWORD
	FhwndOwner   THWND
	FlpConnRes   TLPNETRESOURCEW
	FdwFlags     TDWORD
	FdwDevNum    TDWORD
}

type CONNECTDLGSTRUCTW = TCONNECTDLGSTRUCTW

type T_CONNECTDLGSTRUCTW = TCONNECTDLGSTRUCTW

type _CONNECTDLGSTRUCTW = T_CONNECTDLGSTRUCTW

type TLPCONNECTDLGSTRUCTW = uintptr

type LPCONNECTDLGSTRUCTW = TLPCONNECTDLGSTRUCTW

type TCONNECTDLGSTRUCT = struct {
	FcbStructure TDWORD
	FhwndOwner   THWND
	FlpConnRes   TLPNETRESOURCEA
	FdwFlags     TDWORD
	FdwDevNum    TDWORD
}

type CONNECTDLGSTRUCT = TCONNECTDLGSTRUCT

type TLPCONNECTDLGSTRUCT = uintptr

type LPCONNECTDLGSTRUCT = TLPCONNECTDLGSTRUCT

type TDISCDLGSTRUCTA = struct {
	FcbStructure  TDWORD
	FhwndOwner    THWND
	FlpLocalName  TLPSTR
	FlpRemoteName TLPSTR
	FdwFlags      TDWORD
}

type DISCDLGSTRUCTA = TDISCDLGSTRUCTA

type T_DISCDLGSTRUCTA = TDISCDLGSTRUCTA

type _DISCDLGSTRUCTA = T_DISCDLGSTRUCTA

type TLPDISCDLGSTRUCTA = uintptr

type LPDISCDLGSTRUCTA = TLPDISCDLGSTRUCTA

type TDISCDLGSTRUCTW = struct {
	FcbStructure  TDWORD
	FhwndOwner    THWND
	FlpLocalName  TLPWSTR
	FlpRemoteName TLPWSTR
	FdwFlags      TDWORD
}

type DISCDLGSTRUCTW = TDISCDLGSTRUCTW

type T_DISCDLGSTRUCTW = TDISCDLGSTRUCTW

type _DISCDLGSTRUCTW = T_DISCDLGSTRUCTW

type TLPDISCDLGSTRUCTW = uintptr

type LPDISCDLGSTRUCTW = TLPDISCDLGSTRUCTW

type TDISCDLGSTRUCT = struct {
	FcbStructure  TDWORD
	FhwndOwner    THWND
	FlpLocalName  TLPSTR
	FlpRemoteName TLPSTR
	FdwFlags      TDWORD
}

type DISCDLGSTRUCT = TDISCDLGSTRUCT

type TLPDISCDLGSTRUCT = uintptr

type LPDISCDLGSTRUCT = TLPDISCDLGSTRUCT

type TUNIVERSAL_NAME_INFOA = struct {
	FlpUniversalName TLPSTR
}

type UNIVERSAL_NAME_INFOA = TUNIVERSAL_NAME_INFOA

type T_UNIVERSAL_NAME_INFOA = TUNIVERSAL_NAME_INFOA

type _UNIVERSAL_NAME_INFOA = T_UNIVERSAL_NAME_INFOA

type TLPUNIVERSAL_NAME_INFOA = uintptr

type LPUNIVERSAL_NAME_INFOA = TLPUNIVERSAL_NAME_INFOA

type TUNIVERSAL_NAME_INFOW = struct {
	FlpUniversalName TLPWSTR
}

type UNIVERSAL_NAME_INFOW = TUNIVERSAL_NAME_INFOW

type T_UNIVERSAL_NAME_INFOW = TUNIVERSAL_NAME_INFOW

type _UNIVERSAL_NAME_INFOW = T_UNIVERSAL_NAME_INFOW

type TLPUNIVERSAL_NAME_INFOW = uintptr

type LPUNIVERSAL_NAME_INFOW = TLPUNIVERSAL_NAME_INFOW

type TUNIVERSAL_NAME_INFO = struct {
	FlpUniversalName TLPSTR
}

type UNIVERSAL_NAME_INFO = TUNIVERSAL_NAME_INFO

type TLPUNIVERSAL_NAME_INFO = uintptr

type LPUNIVERSAL_NAME_INFO = TLPUNIVERSAL_NAME_INFO

type TREMOTE_NAME_INFOA = struct {
	FlpUniversalName  TLPSTR
	FlpConnectionName TLPSTR
	FlpRemainingPath  TLPSTR
}

type REMOTE_NAME_INFOA = TREMOTE_NAME_INFOA

type T_REMOTE_NAME_INFOA = TREMOTE_NAME_INFOA

type _REMOTE_NAME_INFOA = T_REMOTE_NAME_INFOA

type TLPREMOTE_NAME_INFOA = uintptr

type LPREMOTE_NAME_INFOA = TLPREMOTE_NAME_INFOA

type TREMOTE_NAME_INFOW = struct {
	FlpUniversalName  TLPWSTR
	FlpConnectionName TLPWSTR
	FlpRemainingPath  TLPWSTR
}

type REMOTE_NAME_INFOW = TREMOTE_NAME_INFOW

type T_REMOTE_NAME_INFOW = TREMOTE_NAME_INFOW

type _REMOTE_NAME_INFOW = T_REMOTE_NAME_INFOW

type TLPREMOTE_NAME_INFOW = uintptr

type LPREMOTE_NAME_INFOW = TLPREMOTE_NAME_INFOW

type TREMOTE_NAME_INFO = struct {
	FlpUniversalName  TLPSTR
	FlpConnectionName TLPSTR
	FlpRemainingPath  TLPSTR
}

type REMOTE_NAME_INFO = TREMOTE_NAME_INFO

type TLPREMOTE_NAME_INFO = uintptr

type LPREMOTE_NAME_INFO = TLPREMOTE_NAME_INFO

type TNETINFOSTRUCT = struct {
	FcbStructure       TDWORD
	FdwProviderVersion TDWORD
	FdwStatus          TDWORD
	FdwCharacteristics TDWORD
	FdwHandle          TULONG_PTR
	FwNetType          TWORD
	FdwPrinters        TDWORD
	FdwDrives          TDWORD
}

type NETINFOSTRUCT = TNETINFOSTRUCT

type T_NETINFOSTRUCT = TNETINFOSTRUCT

type _NETINFOSTRUCT = T_NETINFOSTRUCT

type TLPNETINFOSTRUCT = uintptr

type LPNETINFOSTRUCT = TLPNETINFOSTRUCT

type TPFNGETPROFILEPATHA = uintptr

type PFNGETPROFILEPATHA = TPFNGETPROFILEPATHA

type TPFNGETPROFILEPATHW = uintptr

type PFNGETPROFILEPATHW = TPFNGETPROFILEPATHW

type TPFNRECONCILEPROFILEA = uintptr

type PFNRECONCILEPROFILEA = TPFNRECONCILEPROFILEA

type TPFNRECONCILEPROFILEW = uintptr

type PFNRECONCILEPROFILEW = TPFNRECONCILEPROFILEW

type TPFNPROCESSPOLICIESA = uintptr

type PFNPROCESSPOLICIESA = TPFNPROCESSPOLICIESA

type TPFNPROCESSPOLICIESW = uintptr

type PFNPROCESSPOLICIESW = TPFNPROCESSPOLICIESW

type TNETCONNECTINFOSTRUCT = struct {
	FcbStructure   TDWORD
	FdwFlags       TDWORD
	FdwSpeed       TDWORD
	FdwDelay       TDWORD
	FdwOptDataSize TDWORD
}

type NETCONNECTINFOSTRUCT = TNETCONNECTINFOSTRUCT

type T_NETCONNECTINFOSTRUCT = TNETCONNECTINFOSTRUCT

type _NETCONNECTINFOSTRUCT = T_NETCONNECTINFOSTRUCT

type TLPNETCONNECTINFOSTRUCT = uintptr

type LPNETCONNECTINFOSTRUCT = TLPNETCONNECTINFOSTRUCT

type TATTACH_VIRTUAL_DISK_FLAG = int32

type ATTACH_VIRTUAL_DISK_FLAG = TATTACH_VIRTUAL_DISK_FLAG

type __ATTACH_VIRTUAL_DISK_FLAG = int32

const _ATTACH_VIRTUAL_DISK_FLAG_NONE = 0
const _ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY = 1
const _ATTACH_VIRTUAL_DISK_FLAG_NO_DRIVE_LETTER = 2
const _ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME = 4
const _ATTACH_VIRTUAL_DISK_FLAG_NO_LOCAL_HOST = 8

type TATTACH_VIRTUAL_DISK_VERSION = int32

type ATTACH_VIRTUAL_DISK_VERSION = TATTACH_VIRTUAL_DISK_VERSION

type __ATTACH_VIRTUAL_DISK_VERSION = int32

const _ATTACH_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _ATTACH_VIRTUAL_DISK_VERSION_1 = 1

type TCOMPACT_VIRTUAL_DISK_FLAG = int32

type COMPACT_VIRTUAL_DISK_FLAG = TCOMPACT_VIRTUAL_DISK_FLAG

type __COMPACT_VIRTUAL_DISK_FLAG = int32

const _COMPACT_VIRTUAL_DISK_FLAG_NONE = 0

type TCOMPACT_VIRTUAL_DISK_VERSION = int32

type COMPACT_VIRTUAL_DISK_VERSION = TCOMPACT_VIRTUAL_DISK_VERSION

type __COMPACT_VIRTUAL_DISK_VERSION = int32

const _COMPACT_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _COMPACT_VIRTUAL_DISK_VERSION_1 = 1

type TCREATE_VIRTUAL_DISK_FLAG = int32

type CREATE_VIRTUAL_DISK_FLAG = TCREATE_VIRTUAL_DISK_FLAG

type __CREATE_VIRTUAL_DISK_FLAG = int32

const _CREATE_VIRTUAL_DISK_FLAG_NONE = 0
const _CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION = 1
const _CREATE_VIRTUAL_DISK_FLAG_PREVENT_WRITES_TO_SOURCE_DISK = 2
const _CREATE_VIRTUAL_DISK_FLAG_DO_NOT_COPY_METADATA_FROM_PARENT = 4

type TCREATE_VIRTUAL_DISK_VERSION = int32

type CREATE_VIRTUAL_DISK_VERSION = TCREATE_VIRTUAL_DISK_VERSION

type __CREATE_VIRTUAL_DISK_VERSION = int32

const _CREATE_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _CREATE_VIRTUAL_DISK_VERSION_1 = 1
const _CREATE_VIRTUAL_DISK_VERSION_2 = 2

type TDEPENDENT_DISK_FLAG = int32

type DEPENDENT_DISK_FLAG = TDEPENDENT_DISK_FLAG

type __DEPENDENT_DISK_FLAG = int32

const _DEPENDENT_DISK_FLAG_NONE = 0
const _DEPENDENT_DISK_FLAG_MULT_BACKING_FILES = 1
const _DEPENDENT_DISK_FLAG_FULLY_ALLOCATED = 2
const _DEPENDENT_DISK_FLAG_READ_ONLY = 4
const _DEPENDENT_DISK_FLAG_REMOTE = 8
const _DEPENDENT_DISK_FLAG_SYSTEM_VOLUME = 16
const _DEPENDENT_DISK_FLAG_SYSTEM_VOLUME_PARENT = 32
const _DEPENDENT_DISK_FLAG_REMOVABLE = 64
const _DEPENDENT_DISK_FLAG_NO_DRIVE_LETTER = 128
const _DEPENDENT_DISK_FLAG_PARENT = 256
const _DEPENDENT_DISK_FLAG_NO_HOST_DISK = 512
const _DEPENDENT_DISK_FLAG_PERMANENT_LIFETIME = 1024

type TEXPAND_VIRTUAL_DISK_VERSION = int32

type EXPAND_VIRTUAL_DISK_VERSION = TEXPAND_VIRTUAL_DISK_VERSION

type __EXPAND_VIRTUAL_DISK_VERSION = int32

const _EXPAND_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _EXPAND_VIRTUAL_DISK_VERSION_1 = 1

type TDETACH_VIRTUAL_DISK_FLAG = int32

type DETACH_VIRTUAL_DISK_FLAG = TDETACH_VIRTUAL_DISK_FLAG

type __DETACH_VIRTUAL_DISK_FLAG = int32

const _DETACH_VIRTUAL_DISK_FLAG_NONE = 0

type TEXPAND_VIRTUAL_DISK_FLAG = int32

type EXPAND_VIRTUAL_DISK_FLAG = TEXPAND_VIRTUAL_DISK_FLAG

type __EXPAND_VIRTUAL_DISK_FLAG = int32

const _EXPAND_VIRTUAL_DISK_FLAG_NONE = 0

type TGET_STORAGE_DEPENDENCY_FLAG = int32

type GET_STORAGE_DEPENDENCY_FLAG = TGET_STORAGE_DEPENDENCY_FLAG

type __GET_STORAGE_DEPENDENCY_FLAG = int32

const _GET_STORAGE_DEPENDENCY_FLAG_NONE = 0
const _GET_STORAGE_DEPENDENCY_FLAG_HOST_VOLUMES = 1
const _GET_STORAGE_DEPENDENCY_FLAG_DISK_HANDLE = 2

type TGET_VIRTUAL_DISK_INFO_VERSION = int32

type GET_VIRTUAL_DISK_INFO_VERSION = TGET_VIRTUAL_DISK_INFO_VERSION

type __GET_VIRTUAL_DISK_INFO_VERSION = int32

const _GET_VIRTUAL_DISK_INFO_UNSPECIFIED = 0
const _GET_VIRTUAL_DISK_INFO_SIZE = 1
const _GET_VIRTUAL_DISK_INFO_IDENTIFIER = 2
const _GET_VIRTUAL_DISK_INFO_PARENT_LOCATION = 3
const _GET_VIRTUAL_DISK_INFO_PARENT_IDENTIFIER = 4
const _GET_VIRTUAL_DISK_INFO_PARENT_TIMESTAMP = 5
const _GET_VIRTUAL_DISK_INFO_VIRTUAL_STORAGE_TYPE = 6
const _GET_VIRTUAL_DISK_INFO_PROVIDER_SUBTYPE = 7
const _GET_VIRTUAL_DISK_INFO_IS_4K_ALIGNED = 8
const _GET_VIRTUAL_DISK_INFO_PHYSICAL_DISK = 9
const _GET_VIRTUAL_DISK_INFO_VHD_PHYSICAL_SECTOR_SIZE = 10
const _GET_VIRTUAL_DISK_INFO_SMALLEST_SAFE_VIRTUAL_SIZE = 11
const _GET_VIRTUAL_DISK_INFO_FRAGMENTATION = 12
const _GET_VIRTUAL_DISK_INFO_IS_LOADED = 13
const _GET_VIRTUAL_DISK_INFO_VIRTUAL_DISK_ID = 14
const _GET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE = 15

type TMIRROR_VIRTUAL_DISK_FLAG = int32

type MIRROR_VIRTUAL_DISK_FLAG = TMIRROR_VIRTUAL_DISK_FLAG

type __MIRROR_VIRTUAL_DISK_FLAG = int32

const _MIRROR_VIRTUAL_DISK_FLAG_NONE = 0
const _MIRROR_VIRTUAL_DISK_FLAG_EXISTING_FILE = 1

type TMIRROR_VIRTUAL_DISK_VERSION = int32

type MIRROR_VIRTUAL_DISK_VERSION = TMIRROR_VIRTUAL_DISK_VERSION

type __MIRROR_VIRTUAL_DISK_VERSION = int32

const _MIRROR_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _MIRROR_VIRTUAL_DISK_VERSION_1 = 1

type TMERGE_VIRTUAL_DISK_FLAG = int32

type MERGE_VIRTUAL_DISK_FLAG = TMERGE_VIRTUAL_DISK_FLAG

type __MERGE_VIRTUAL_DISK_FLAG = int32

const _MERGE_VIRTUAL_DISK_FLAG_NONE = 0

type TMERGE_VIRTUAL_DISK_VERSION = int32

type MERGE_VIRTUAL_DISK_VERSION = TMERGE_VIRTUAL_DISK_VERSION

type __MERGE_VIRTUAL_DISK_VERSION = int32

const _MERGE_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _MERGE_VIRTUAL_DISK_VERSION_1 = 1
const _MERGE_VIRTUAL_DISK_VERSION_2 = 2

type TOPEN_VIRTUAL_DISK_FLAG = int32

type OPEN_VIRTUAL_DISK_FLAG = TOPEN_VIRTUAL_DISK_FLAG

type __OPEN_VIRTUAL_DISK_FLAG = int32

const _OPEN_VIRTUAL_DISK_FLAG_NONE = 0
const _OPEN_VIRTUAL_DISK_FLAG_NO_PARENTS = 1
const _OPEN_VIRTUAL_DISK_FLAG_BLANK_FILE = 2
const _OPEN_VIRTUAL_DISK_FLAG_BOOT_DRIVE = 4
const _OPEN_VIRTUAL_DISK_FLAG_CACHED_IO = 8
const _OPEN_VIRTUAL_DISK_FLAG_CUSTOM_DIFF_CHAIN = 16

type TOPEN_VIRTUAL_DISK_VERSION = int32

type OPEN_VIRTUAL_DISK_VERSION = TOPEN_VIRTUAL_DISK_VERSION

type __OPEN_VIRTUAL_DISK_VERSION = int32

const _OPEN_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _OPEN_VIRTUAL_DISK_VERSION_1 = 1
const _OPEN_VIRTUAL_DISK_VERSION_2 = 2

type TSET_VIRTUAL_DISK_INFO_VERSION = int32

type SET_VIRTUAL_DISK_INFO_VERSION = TSET_VIRTUAL_DISK_INFO_VERSION

type __SET_VIRTUAL_DISK_INFO_VERSION = int32

const _SET_VIRTUAL_DISK_INFO_UNSPECIFIED = 0
const _SET_VIRTUAL_DISK_INFO_PARENT_PATH = 1
const _SET_VIRTUAL_DISK_INFO_IDENTIFIER = 2
const _SET_VIRTUAL_DISK_INFO_PARENT_PATH_WITH_DEPTH = 3
const _SET_VIRTUAL_DISK_INFO_PHYSICAL_SECTOR_SIZE = 4
const _SET_VIRTUAL_DISK_INFO_VIRTUAL_DISK_ID = 5
const _SET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE = 6
const _SET_VIRTUAL_DISK_INFO_PARENT_LOCATOR = 7

type TSTORAGE_DEPENDENCY_INFO_VERSION = int32

type STORAGE_DEPENDENCY_INFO_VERSION = TSTORAGE_DEPENDENCY_INFO_VERSION

type __STORAGE_DEPENDENCY_INFO_VERSION = int32

const _STORAGE_DEPENDENCY_INFO_VERSION_UNSPECIFIED = 0
const _STORAGE_DEPENDENCY_INFO_VERSION_1 = 1
const _STORAGE_DEPENDENCY_INFO_VERSION_2 = 2

type TVIRTUAL_DISK_ACCESS_MASK = int32

type VIRTUAL_DISK_ACCESS_MASK = TVIRTUAL_DISK_ACCESS_MASK

type __VIRTUAL_DISK_ACCESS_MASK = int32

const _VIRTUAL_DISK_ACCESS_NONE = 0
const _VIRTUAL_DISK_ACCESS_ATTACH_RO = 65536
const _VIRTUAL_DISK_ACCESS_ATTACH_RW = 131072
const _VIRTUAL_DISK_ACCESS_DETACH = 262144
const _VIRTUAL_DISK_ACCESS_GET_INFO = 524288
const _VIRTUAL_DISK_ACCESS_CREATE = 1048576
const _VIRTUAL_DISK_ACCESS_METAOPS = 2097152
const _VIRTUAL_DISK_ACCESS_READ = 851968
const _VIRTUAL_DISK_ACCESS_ALL = 4128768
const _VIRTUAL_DISK_ACCESS_WRITABLE = 3276800

type TRESIZE_VIRTUAL_DISK_FLAG = int32

type RESIZE_VIRTUAL_DISK_FLAG = TRESIZE_VIRTUAL_DISK_FLAG

type __RESIZE_VIRTUAL_DISK_FLAG = int32

const _RESIZE_VIRTUAL_DISK_FLAG_NONE = 0
const _RESIZE_VIRTUAL_DISK_FLAG_ALLOW_UNSAFE_VIRTUAL_SIZE = 1
const _RESIZE_VIRTUAL_DISK_FLAG_RESIZE_TO_SMALLEST_SAFE_VIRTUAL_SIZE = 2

type TRESIZE_VIRTUAL_DISK_VERSION = int32

type RESIZE_VIRTUAL_DISK_VERSION = TRESIZE_VIRTUAL_DISK_VERSION

type __RESIZE_VIRTUAL_DISK_VERSION = int32

const _RESIZE_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0
const _RESIZE_VIRTUAL_DISK_VERSION_1 = 1

type TAPPLY_SNAPSHOT_VHDSET_FLAG = int32

type APPLY_SNAPSHOT_VHDSET_FLAG = TAPPLY_SNAPSHOT_VHDSET_FLAG

type __APPLY_SNAPSHOT_VHDSET_FLAG = int32

const _APPLY_SNAPSHOT_VHDSET_FLAG_NONE = 0
const _APPLY_SNAPSHOT_VHDSET_FLAG_WRITEABLE = 1

type TPAPPLY_SNAPSHOT_VHDSET_FLAG = uintptr

type PAPPLY_SNAPSHOT_VHDSET_FLAG = TPAPPLY_SNAPSHOT_VHDSET_FLAG

type TAPPLY_SNAPSHOT_VHDSET_VERSION = int32

type APPLY_SNAPSHOT_VHDSET_VERSION = TAPPLY_SNAPSHOT_VHDSET_VERSION

type __APPLY_SNAPSHOT_VHDSET_VERSION = int32

const _APPLY_SNAPSHOT_VHDSET_VERSION_UNSPECIFIED = 0
const _APPLY_SNAPSHOT_VHDSET_VERSION_1 = 1

type TDELETE_SNAPSHOT_VHDSET_FLAG = int32

type DELETE_SNAPSHOT_VHDSET_FLAG = TDELETE_SNAPSHOT_VHDSET_FLAG

type __DELETE_SNAPSHOT_VHDSET_FLAG = int32

const _DELETE_SNAPSHOT_VHDSET_FLAG_NONE = 0
const _DELETE_SNAPSHOT_VHDSET_FLAG_PERSIST_RCT = 1

type TPDELETE_SNAPSHOT_VHDSET_FLAG = uintptr

type PDELETE_SNAPSHOT_VHDSET_FLAG = TPDELETE_SNAPSHOT_VHDSET_FLAG

type TDELETE_SNAPSHOT_VHDSET_VERSION = int32

type DELETE_SNAPSHOT_VHDSET_VERSION = TDELETE_SNAPSHOT_VHDSET_VERSION

type __DELETE_SNAPSHOT_VHDSET_VERSION = int32

const _DELETE_SNAPSHOT_VHDSET_VERSION_UNSPECIFIED = 0
const _DELETE_SNAPSHOT_VHDSET_VERSION_1 = 1

type TPDELETE_SNAPSHOT_VHDSET_VERSION = uintptr

type PDELETE_SNAPSHOT_VHDSET_VERSION = TPDELETE_SNAPSHOT_VHDSET_VERSION

type TMODIFY_VHDSET_FLAG = int32

type MODIFY_VHDSET_FLAG = TMODIFY_VHDSET_FLAG

type __MODIFY_VHDSET_FLAG = int32

const _MODIFY_VHDSET_FLAG_NONE = 0

type TPMODIFY_VHDSET_FLAG = uintptr

type PMODIFY_VHDSET_FLAG = TPMODIFY_VHDSET_FLAG

type TMODIFY_VHDSET_VERSION = int32

type MODIFY_VHDSET_VERSION = TMODIFY_VHDSET_VERSION

type __MODIFY_VHDSET_VERSION = int32

const _MODIFY_VHDSET_UNSPECIFIED = 0
const _MODIFY_VHDSET_SNAPSHOT_PATH = 1
const _MODIFY_VHDSET_REMOVE_SNAPSHOT = 2
const _MODIFY_VHDSET_DEFAULT_SNAPSHOT_PATH = 3

type TPMODIFY_VHDSET_VERSION = uintptr

type PMODIFY_VHDSET_VERSION = TPMODIFY_VHDSET_VERSION

type TQUERY_CHANGES_VIRTUAL_DISK_FLAG = int32

type QUERY_CHANGES_VIRTUAL_DISK_FLAG = TQUERY_CHANGES_VIRTUAL_DISK_FLAG

type __QUERY_CHANGES_VIRTUAL_DISK_FLAG = int32

const _QUERY_CHANGES_VIRTUAL_DISK_FLAG_NONE = 0

type TTAKE_SNAPSHOT_VHDSET_FLAG = int32

type TAKE_SNAPSHOT_VHDSET_FLAG = TTAKE_SNAPSHOT_VHDSET_FLAG

type __TAKE_SNAPSHOT_VHDSET_FLAG = int32

const _TAKE_SNAPSHOT_VHDSET_FLAG_NONE = 0

type TPTAKE_SNAPSHOT_VHDSET_FLAG = uintptr

type PTAKE_SNAPSHOT_VHDSET_FLAG = TPTAKE_SNAPSHOT_VHDSET_FLAG

type TTAKE_SNAPSHOT_VHDSET_VERSION = int32

type TAKE_SNAPSHOT_VHDSET_VERSION = TTAKE_SNAPSHOT_VHDSET_VERSION

type __TAKE_SNAPSHOT_VHDSET_VERSION = int32

const _TAKE_SNAPSHOT_VHDSET_VERSION_UNSPECIFIED = 0
const _TAKE_SNAPSHOT_VHDSET_VERSION_1 = 1

type TVIRTUAL_STORAGE_TYPE = struct {
	FDeviceId TULONG
	FVendorId TGUID
}

type VIRTUAL_STORAGE_TYPE = TVIRTUAL_STORAGE_TYPE

type T_VIRTUAL_STORAGE_TYPE = TVIRTUAL_STORAGE_TYPE

type _VIRTUAL_STORAGE_TYPE = T_VIRTUAL_STORAGE_TYPE

type TPVIRTUAL_STORAGE_TYPE = uintptr

type PVIRTUAL_STORAGE_TYPE = TPVIRTUAL_STORAGE_TYPE

type TATTACH_VIRTUAL_DISK_PARAMETERS = struct {
	FVersion   TATTACH_VIRTUAL_DISK_VERSION
	F__ccgo1_4 struct {
		FVersion1 struct {
			FReserved TULONG
		}
	}
}

type ATTACH_VIRTUAL_DISK_PARAMETERS = TATTACH_VIRTUAL_DISK_PARAMETERS

type T_ATTACH_VIRTUAL_DISK_PARAMETERS = TATTACH_VIRTUAL_DISK_PARAMETERS

type _ATTACH_VIRTUAL_DISK_PARAMETERS = T_ATTACH_VIRTUAL_DISK_PARAMETERS

type TPATTACH_VIRTUAL_DISK_PARAMETERS = uintptr

type PATTACH_VIRTUAL_DISK_PARAMETERS = TPATTACH_VIRTUAL_DISK_PARAMETERS

type TCOMPACT_VIRTUAL_DISK_PARAMETERS = struct {
	FVersion   TCOMPACT_VIRTUAL_DISK_VERSION
	F__ccgo1_4 struct {
		FVersion1 struct {
			FReserved TULONG
		}
	}
}

type COMPACT_VIRTUAL_DISK_PARAMETERS = TCOMPACT_VIRTUAL_DISK_PARAMETERS

type T_COMPACT_VIRTUAL_DISK_PARAMETERS = TCOMPACT_VIRTUAL_DISK_PARAMETERS

type _COMPACT_VIRTUAL_DISK_PARAMETERS = T_COMPACT_VIRTUAL_DISK_PARAMETERS

type TPCOMPACT_VIRTUAL_DISK_PARAMETERS = uintptr

type PCOMPACT_VIRTUAL_DISK_PARAMETERS = TPCOMPACT_VIRTUAL_DISK_PARAMETERS

type TCREATE_VIRTUAL_DISK_PARAMETERS = struct {
	F__ccgo_align  [0]uint32
	FVersion       TCREATE_VIRTUAL_DISK_VERSION
	F__ccgo_align1 [4]byte
	F__ccgo1_8     struct {
		F__ccgo_align [0]uint32
		FVersion2     [0]struct {
			F__ccgo_align             [0]uint32
			FUniqueId                 TGUID
			FMaximumSize              TULONGLONG
			FBlockSizeInBytes         TULONG
			FSectorSizeInBytes        TULONG
			FParentPath               TPCWSTR
			FSourcePath               TPCWSTR
			FOpenFlags                TOPEN_VIRTUAL_DISK_FLAG
			FParentVirtualStorageType TVIRTUAL_STORAGE_TYPE
			FSourceVirtualStorageType TVIRTUAL_STORAGE_TYPE
			FResiliencyGuid           TGUID
			F__ccgo_pad10             [4]byte
		}
		FVersion1 struct {
			F__ccgo_align      [0]uint32
			FUniqueId          TGUID
			FMaximumSize       TULONGLONG
			FBlockSizeInBytes  TULONG
			FSectorSizeInBytes TULONG
			FParentPath        TPCWSTR
			FSourcePath        TPCWSTR
		}
		F__ccgo_pad2 [64]byte
	}
}

type CREATE_VIRTUAL_DISK_PARAMETERS = TCREATE_VIRTUAL_DISK_PARAMETERS

type T_CREATE_VIRTUAL_DISK_PARAMETERS = TCREATE_VIRTUAL_DISK_PARAMETERS

type _CREATE_VIRTUAL_DISK_PARAMETERS = T_CREATE_VIRTUAL_DISK_PARAMETERS

type TPCREATE_VIRTUAL_DISK_PARAMETERS = uintptr

type PCREATE_VIRTUAL_DISK_PARAMETERS = TPCREATE_VIRTUAL_DISK_PARAMETERS

type TEXPAND_VIRTUAL_DISK_PARAMETERS = struct {
	F__ccgo_align  [0]uint32
	FVersion       TEXPAND_VIRTUAL_DISK_VERSION
	F__ccgo_align1 [4]byte
	F__ccgo1_8     struct {
		F__ccgo_align [0]uint32
		FVersion1     struct {
			F__ccgo_align [0]uint32
			FNewSize      TULONGLONG
		}
	}
}

type EXPAND_VIRTUAL_DISK_PARAMETERS = TEXPAND_VIRTUAL_DISK_PARAMETERS

type T_EXPAND_VIRTUAL_DISK_PARAMETERS = TEXPAND_VIRTUAL_DISK_PARAMETERS

type _EXPAND_VIRTUAL_DISK_PARAMETERS = T_EXPAND_VIRTUAL_DISK_PARAMETERS

type TPEXPAND_VIRTUAL_DISK_PARAMETERS = uintptr

type PEXPAND_VIRTUAL_DISK_PARAMETERS = TPEXPAND_VIRTUAL_DISK_PARAMETERS

type TGET_VIRTUAL_DISK_INFO = struct {
	F__ccgo_align  [0]uint32
	FVersion       TGET_VIRTUAL_DISK_INFO_VERSION
	F__ccgo_align1 [4]byte
	F__ccgo1_8     struct {
		F__ccgo_align   [0]uint32
		FIdentifier     [0]TGUID
		FParentLocation [0]struct {
			FParentResolved       TWINBOOL
			FParentLocationBuffer [1]TWCHAR
		}
		FParentIdentifier   [0]TGUID
		FParentTimestamp    [0]TULONG
		FVirtualStorageType [0]TVIRTUAL_STORAGE_TYPE
		FProviderSubtype    [0]TULONG
		FIs4kAligned        [0]TWINBOOL
		FIsLoaded           [0]TWINBOOL
		FPhysicalDisk       [0]struct {
			FLogicalSectorSize  TULONG
			FPhysicalSectorSize TULONG
			FIsRemote           TWINBOOL
		}
		FVhdPhysicalSectorSize   [0]TULONG
		FSmallestSafeVirtualSize [0]TULONGLONG
		FFragmentationPercentage [0]TULONG
		FVirtualDiskId           [0]TGUID
		FChangeTrackingState     [0]struct {
			FEnabled      TWINBOOL
			FNewerChanges TWINBOOL
			FMostRecentId [1]TWCHAR
		}
		FSize struct {
			F__ccgo_align [0]uint32
			FVirtualSize  TULONGLONG
			FPhysicalSize TULONGLONG
			FBlockSize    TULONG
			FSectorSize   TULONG
		}
	}
}

type GET_VIRTUAL_DISK_INFO = TGET_VIRTUAL_DISK_INFO

type T_GET_VIRTUAL_DISK_INFO = TGET_VIRTUAL_DISK_INFO

type _GET_VIRTUAL_DISK_INFO = T_GET_VIRTUAL_DISK_INFO

type TPGET_VIRTUAL_DISK_INFO = uintptr

type PGET_VIRTUAL_DISK_INFO = TPGET_VIRTUAL_DISK_INFO

type TMERGE_VIRTUAL_DISK_PARAMETERS = struct {
	FVersion   TMERGE_VIRTUAL_DISK_VERSION
	F__ccgo1_4 struct {
		FVersion2 [0]struct {
			FMergeSourceDepth TULONG
			FMergeTargetDepth TULONG
		}
		FVersion1 struct {
			FMergeDepth TULONG
		}
		F__ccgo_pad2 [4]byte
	}
}

type MERGE_VIRTUAL_DISK_PARAMETERS = TMERGE_VIRTUAL_DISK_PARAMETERS

type T_MERGE_VIRTUAL_DISK_PARAMETERS = TMERGE_VIRTUAL_DISK_PARAMETERS

type _MERGE_VIRTUAL_DISK_PARAMETERS = T_MERGE_VIRTUAL_DISK_PARAMETERS

type TPMERGE_VIRTUAL_DISK_PARAMETERS = uintptr

type PMERGE_VIRTUAL_DISK_PARAMETERS = TPMERGE_VIRTUAL_DISK_PARAMETERS

type TOPEN_VIRTUAL_DISK_PARAMETERS = struct {
	FVersion   TOPEN_VIRTUAL_DISK_VERSION
	F__ccgo1_4 struct {
		FVersion2 [0]struct {
			FGetInfoOnly    TWINBOOL
			FReadOnly       TWINBOOL
			FResiliencyGuid TGUID
		}
		FVersion1 struct {
			FRWDepth TULONG
		}
		F__ccgo_pad2 [20]byte
	}
}

type OPEN_VIRTUAL_DISK_PARAMETERS = TOPEN_VIRTUAL_DISK_PARAMETERS

type T_OPEN_VIRTUAL_DISK_PARAMETERS = TOPEN_VIRTUAL_DISK_PARAMETERS

type _OPEN_VIRTUAL_DISK_PARAMETERS = T_OPEN_VIRTUAL_DISK_PARAMETERS

type TPOPEN_VIRTUAL_DISK_PARAMETERS = uintptr

type POPEN_VIRTUAL_DISK_PARAMETERS = TPOPEN_VIRTUAL_DISK_PARAMETERS

type TSET_VIRTUAL_DISK_INFO = struct {
	FVersion   TSET_VIRTUAL_DISK_INFO_VERSION
	F__ccgo1_4 struct {
		FUniqueIdentifier        [0]TGUID
		FParentPathWithDepthInfo [0]struct {
			FChildDepth     TULONG
			FParentFilePath TPCWSTR
		}
		FVhdPhysicalSectorSize [0]TULONG
		FVirtualDiskId         [0]TGUID
		FChangeTrackingEnabled [0]TWINBOOL
		FParentLocator         [0]struct {
			FLinkageId      TGUID
			FParentFilePath TPCWSTR
		}
		FParentFilePath TPCWSTR
		F__ccgo_pad7    [16]byte
	}
}

type SET_VIRTUAL_DISK_INFO = TSET_VIRTUAL_DISK_INFO

type T_SET_VIRTUAL_DISK_INFO = TSET_VIRTUAL_DISK_INFO

type _SET_VIRTUAL_DISK_INFO = T_SET_VIRTUAL_DISK_INFO

type TPSET_VIRTUAL_DISK_INFO = uintptr

type PSET_VIRTUAL_DISK_INFO = TPSET_VIRTUAL_DISK_INFO

type TSTORAGE_DEPENDENCY_INFO_TYPE_1 = struct {
	FDependencyTypeFlags   TDEPENDENT_DISK_FLAG
	FProviderSpecificFlags TULONG
	FVirtualStorageType    TVIRTUAL_STORAGE_TYPE
}

type STORAGE_DEPENDENCY_INFO_TYPE_1 = TSTORAGE_DEPENDENCY_INFO_TYPE_1

type T_STORAGE_DEPENDENCY_INFO_TYPE_1 = TSTORAGE_DEPENDENCY_INFO_TYPE_1

type _STORAGE_DEPENDENCY_INFO_TYPE_1 = T_STORAGE_DEPENDENCY_INFO_TYPE_1

type TPSTORAGE_DEPENDENCY_INFO_TYPE_1 = uintptr

type PSTORAGE_DEPENDENCY_INFO_TYPE_1 = TPSTORAGE_DEPENDENCY_INFO_TYPE_1

type TSTORAGE_DEPENDENCY_INFO_TYPE_2 = struct {
	FDependencyTypeFlags         TDEPENDENT_DISK_FLAG
	FProviderSpecificFlags       TULONG
	FVirtualStorageType          TVIRTUAL_STORAGE_TYPE
	FAncestorLevel               TULONG
	FDependencyDeviceName        TPWSTR
	FHostVolumeName              TPWSTR
	FDependentVolumeName         TPWSTR
	FDependentVolumeRelativePath TPWSTR
}

type STORAGE_DEPENDENCY_INFO_TYPE_2 = TSTORAGE_DEPENDENCY_INFO_TYPE_2

type T_STORAGE_DEPENDENCY_INFO_TYPE_2 = TSTORAGE_DEPENDENCY_INFO_TYPE_2

type _STORAGE_DEPENDENCY_INFO_TYPE_2 = T_STORAGE_DEPENDENCY_INFO_TYPE_2

type TPSTORAGE_DEPENDENCY_INFO_TYPE_2 = uintptr

type PSTORAGE_DEPENDENCY_INFO_TYPE_2 = TPSTORAGE_DEPENDENCY_INFO_TYPE_2

type TSTORAGE_DEPENDENCY_INFO = struct {
	FVersion       TSTORAGE_DEPENDENCY_INFO_VERSION
	FNumberEntries TULONG
	F__ccgo2_8     struct {
		FVersion2Entries [0][1]TSTORAGE_DEPENDENCY_INFO_TYPE_2
		FVersion1Entries [1]TSTORAGE_DEPENDENCY_INFO_TYPE_1
		F__ccgo_pad2     [20]byte
	}
}

type STORAGE_DEPENDENCY_INFO = TSTORAGE_DEPENDENCY_INFO

type T_STORAGE_DEPENDENCY_INFO = TSTORAGE_DEPENDENCY_INFO

type _STORAGE_DEPENDENCY_INFO = T_STORAGE_DEPENDENCY_INFO

type TPSTORAGE_DEPENDENCY_INFO = uintptr

type PSTORAGE_DEPENDENCY_INFO = TPSTORAGE_DEPENDENCY_INFO

type TVIRTUAL_DISK_PROGRESS = struct {
	F__ccgo_align    [0]uint32
	FOperationStatus TDWORD
	F__ccgo_align1   [4]byte
	FCurrentValue    TULONGLONG
	FCompletionValue TULONGLONG
}

type VIRTUAL_DISK_PROGRESS = TVIRTUAL_DISK_PROGRESS

type T_VIRTUAL_DISK_PROGRESS = TVIRTUAL_DISK_PROGRESS

type _VIRTUAL_DISK_PROGRESS = T_VIRTUAL_DISK_PROGRESS

type TPVIRTUAL_DISK_PROGRESS = uintptr

type PVIRTUAL_DISK_PROGRESS = TPVIRTUAL_DISK_PROGRESS

type TMIRROR_VIRTUAL_DISK_PARAMETERS = struct {
	FVersion   TMIRROR_VIRTUAL_DISK_VERSION
	F__ccgo1_4 struct {
		FVersion1 struct {
			FMirrorVirtualDiskPath TPCWSTR
		}
	}
}

type MIRROR_VIRTUAL_DISK_PARAMETERS = TMIRROR_VIRTUAL_DISK_PARAMETERS

type T_MIRROR_VIRTUAL_DISK_PARAMETERS = TMIRROR_VIRTUAL_DISK_PARAMETERS

type _MIRROR_VIRTUAL_DISK_PARAMETERS = T_MIRROR_VIRTUAL_DISK_PARAMETERS

type TPMIRROR_VIRTUAL_DISK_PARAMETERS = uintptr

type PMIRROR_VIRTUAL_DISK_PARAMETERS = TPMIRROR_VIRTUAL_DISK_PARAMETERS

type TRESIZE_VIRTUAL_DISK_PARAMETERS = struct {
	F__ccgo_align  [0]uint32
	FVersion       TRESIZE_VIRTUAL_DISK_VERSION
	F__ccgo_align1 [4]byte
	F__ccgo1_8     struct {
		F__ccgo_align [0]uint32
		FVersion1     struct {
			F__ccgo_align [0]uint32
			FNewSize      TULONGLONG
		}
	}
}

type RESIZE_VIRTUAL_DISK_PARAMETERS = TRESIZE_VIRTUAL_DISK_PARAMETERS

type T_RESIZE_VIRTUAL_DISK_PARAMETERS = TRESIZE_VIRTUAL_DISK_PARAMETERS

type _RESIZE_VIRTUAL_DISK_PARAMETERS = T_RESIZE_VIRTUAL_DISK_PARAMETERS

type TPRESIZE_VIRTUAL_DISK_PARAMETERS = uintptr

type PRESIZE_VIRTUAL_DISK_PARAMETERS = TPRESIZE_VIRTUAL_DISK_PARAMETERS

type TAPPLY_SNAPSHOT_VHDSET_PARAMETERS = struct {
	FVersion   TAPPLY_SNAPSHOT_VHDSET_VERSION
	F__ccgo1_4 struct {
		FVersion1 struct {
			FSnapshotId     TGUID
			FLeafSnapshotId TGUID
		}
	}
}

type APPLY_SNAPSHOT_VHDSET_PARAMETERS = TAPPLY_SNAPSHOT_VHDSET_PARAMETERS

type T_APPLY_SNAPSHOT_VHDSET_PARAMETERS = TAPPLY_SNAPSHOT_VHDSET_PARAMETERS

type _APPLY_SNAPSHOT_VHDSET_PARAMETERS = T_APPLY_SNAPSHOT_VHDSET_PARAMETERS

type TPAPPLY_SNAPSHOT_VHDSET_PARAMETERS = uintptr

type PAPPLY_SNAPSHOT_VHDSET_PARAMETERS = TPAPPLY_SNAPSHOT_VHDSET_PARAMETERS

type TDELETE_SNAPSHOT_VHDSET_PARAMETERS = struct {
	FVersion   TDELETE_SNAPSHOT_VHDSET_VERSION
	F__ccgo1_4 struct {
		FVersion1 struct {
			FSnapshotId TGUID
		}
	}
}

type DELETE_SNAPSHOT_VHDSET_PARAMETERS = TDELETE_SNAPSHOT_VHDSET_PARAMETERS

type T_DELETE_SNAPSHOT_VHDSET_PARAMETERS = TDELETE_SNAPSHOT_VHDSET_PARAMETERS

type _DELETE_SNAPSHOT_VHDSET_PARAMETERS = T_DELETE_SNAPSHOT_VHDSET_PARAMETERS

type TPDELETE_SNAPSHOT_VHDSET_PARAMETERS = uintptr

type PDELETE_SNAPSHOT_VHDSET_PARAMETERS = TPDELETE_SNAPSHOT_VHDSET_PARAMETERS

type TMODIFY_VHDSET_PARAMETERS = struct {
	FVersion   TMODIFY_VHDSET_VERSION
	F__ccgo1_4 struct {
		FSnapshotId      [0]TGUID
		FDefaultFilePath [0]TPCWSTR
		FSnapshotPath    struct {
			FSnapshotId       TGUID
			FSnapshotFilePath TPCWSTR
		}
	}
}

type MODIFY_VHDSET_PARAMETERS = TMODIFY_VHDSET_PARAMETERS

type T_MODIFY_VHDSET_PARAMETERS = TMODIFY_VHDSET_PARAMETERS

type _MODIFY_VHDSET_PARAMETERS = T_MODIFY_VHDSET_PARAMETERS

type TPMODIFY_VHDSET_PARAMETERS = uintptr

type PMODIFY_VHDSET_PARAMETERS = TPMODIFY_VHDSET_PARAMETERS

type TQUERY_CHANGES_VIRTUAL_DISK_RANGE = struct {
	F__ccgo_align [0]uint32
	FByteOffset   TULONG64
	FByteLength   TULONG64
	FReserved     TULONG64
}

type QUERY_CHANGES_VIRTUAL_DISK_RANGE = TQUERY_CHANGES_VIRTUAL_DISK_RANGE

type T_QUERY_CHANGES_VIRTUAL_DISK_RANGE = TQUERY_CHANGES_VIRTUAL_DISK_RANGE

type _QUERY_CHANGES_VIRTUAL_DISK_RANGE = T_QUERY_CHANGES_VIRTUAL_DISK_RANGE

type TPQUERY_CHANGES_VIRTUAL_DISK_RANGE = uintptr

type PQUERY_CHANGES_VIRTUAL_DISK_RANGE = TPQUERY_CHANGES_VIRTUAL_DISK_RANGE

type TTAKE_SNAPSHOT_VHDSET_PARAMETERS = struct {
	FVersion   TTAKE_SNAPSHOT_VHDSET_VERSION
	F__ccgo1_4 struct {
		FVersion1 struct {
			FSnapshotId TGUID
		}
	}
}

type TAKE_SNAPSHOT_VHDSET_PARAMETERS = TTAKE_SNAPSHOT_VHDSET_PARAMETERS

type T_TAKE_SNAPSHOT_VHDSET_PARAMETERS = TTAKE_SNAPSHOT_VHDSET_PARAMETERS

type _TAKE_SNAPSHOT_VHDSET_PARAMETERS = T_TAKE_SNAPSHOT_VHDSET_PARAMETERS

type TPTAKE_SNAPSHOT_VHDSET_PARAMETERS = uintptr

type PTAKE_SNAPSHOT_VHDSET_PARAMETERS = TPTAKE_SNAPSHOT_VHDSET_PARAMETERS

type TDDEACK = struct {
	F__ccgo0 uint16
}

type DDEACK = TDDEACK

type TDDEADVISE = struct {
	F__ccgo0  uint16
	FcfFormat int16
}

type DDEADVISE = TDDEADVISE

type TDDEDATA = struct {
	F__ccgo0  uint16
	FcfFormat int16
	FValue    [1]TBYTE
}

type DDEDATA = TDDEDATA

type TDDEPOKE = struct {
	F__ccgo0  uint16
	FcfFormat int16
	FValue    [1]TBYTE
}

type DDEPOKE = TDDEPOKE

type TDDELN = struct {
	F__ccgo0  uint16
	FcfFormat int16
}

type DDELN = TDDELN

type TDDEUP = struct {
	F__ccgo0  uint16
	FcfFormat int16
	Frgb      [1]TBYTE
}

type DDEUP = TDDEUP

type THCONVLIST__ = struct {
	Funused int32
}

type HCONVLIST__ = THCONVLIST__

type THCONVLIST = uintptr

type HCONVLIST = THCONVLIST

type THCONV__ = struct {
	Funused int32
}

type HCONV__ = THCONV__

type THCONV = uintptr

type HCONV = THCONV

type THSZ__ = struct {
	Funused int32
}

type HSZ__ = THSZ__

type THSZ = uintptr

type HSZ = THSZ

type THDDEDATA__ = struct {
	Funused int32
}

type HDDEDATA__ = THDDEDATA__

type THDDEDATA = uintptr

type HDDEDATA = THDDEDATA

type THSZPAIR = struct {
	FhszSvc   THSZ
	FhszTopic THSZ
}

type HSZPAIR = THSZPAIR

type TtagHSZPAIR = THSZPAIR

type tagHSZPAIR = TtagHSZPAIR

type TPHSZPAIR = uintptr

type PHSZPAIR = TPHSZPAIR

type TCONVCONTEXT = struct {
	Fcb         TUINT
	FwFlags     TUINT
	FwCountryID TUINT
	FiCodePage  int32
	FdwLangID   TDWORD
	FdwSecurity TDWORD
	Fqos        TSECURITY_QUALITY_OF_SERVICE
}

type CONVCONTEXT = TCONVCONTEXT

type TtagCONVCONTEXT = TCONVCONTEXT

type tagCONVCONTEXT = TtagCONVCONTEXT

type TPCONVCONTEXT = uintptr

type PCONVCONTEXT = TPCONVCONTEXT

type TCONVINFO = struct {
	Fcb            TDWORD
	FhUser         TDWORD_PTR
	FhConvPartner  THCONV
	FhszSvcPartner THSZ
	FhszServiceReq THSZ
	FhszTopic      THSZ
	FhszItem       THSZ
	FwFmt          TUINT
	FwType         TUINT
	FwStatus       TUINT
	FwConvst       TUINT
	FwLastError    TUINT
	FhConvList     THCONVLIST
	FConvCtxt      TCONVCONTEXT
	Fhwnd          THWND
	FhwndPartner   THWND
}

type CONVINFO = TCONVINFO

type TtagCONVINFO = TCONVINFO

type tagCONVINFO = TtagCONVINFO

type TPCONVINFO = uintptr

type PCONVINFO = TPCONVINFO

type TPFNCALLBACK = uintptr

type PFNCALLBACK = TPFNCALLBACK

type TDDEML_MSG_HOOK_DATA = struct {
	FuiLo   TUINT_PTR
	FuiHi   TUINT_PTR
	FcbData TDWORD
	FData   [8]TDWORD
}

type DDEML_MSG_HOOK_DATA = TDDEML_MSG_HOOK_DATA

type TtagDDEML_MSG_HOOK_DATA = TDDEML_MSG_HOOK_DATA

type tagDDEML_MSG_HOOK_DATA = TtagDDEML_MSG_HOOK_DATA

type TPDDEML_MSG_HOOK_DATA = uintptr

type PDDEML_MSG_HOOK_DATA = TPDDEML_MSG_HOOK_DATA

type TMONMSGSTRUCT = struct {
	Fcb     TUINT
	FhwndTo THWND
	FdwTime TDWORD
	FhTask  THANDLE
	FwMsg   TUINT
	FwParam TWPARAM
	FlParam TLPARAM
	Fdmhd   TDDEML_MSG_HOOK_DATA
}

type MONMSGSTRUCT = TMONMSGSTRUCT

type TtagMONMSGSTRUCT = TMONMSGSTRUCT

type tagMONMSGSTRUCT = TtagMONMSGSTRUCT

type TPMONMSGSTRUCT = uintptr

type PMONMSGSTRUCT = TPMONMSGSTRUCT

type TMONCBSTRUCT = struct {
	Fcb      TUINT
	FdwTime  TDWORD
	FhTask   THANDLE
	FdwRet   TDWORD
	FwType   TUINT
	FwFmt    TUINT
	FhConv   THCONV
	Fhsz1    THSZ
	Fhsz2    THSZ
	FhData   THDDEDATA
	FdwData1 TULONG_PTR
	FdwData2 TULONG_PTR
	Fcc      TCONVCONTEXT
	FcbData  TDWORD
	FData    [8]TDWORD
}

type MONCBSTRUCT = TMONCBSTRUCT

type TtagMONCBSTRUCT = TMONCBSTRUCT

type tagMONCBSTRUCT = TtagMONCBSTRUCT

type TPMONCBSTRUCT = uintptr

type PMONCBSTRUCT = TPMONCBSTRUCT

type TMONHSZSTRUCTA = struct {
	Fcb       TUINT
	FfsAction TWINBOOL
	FdwTime   TDWORD
	Fhsz      THSZ
	FhTask    THANDLE
	Fstr      [1]TCHAR
}

type MONHSZSTRUCTA = TMONHSZSTRUCTA

type TtagMONHSZSTRUCTA = TMONHSZSTRUCTA

type tagMONHSZSTRUCTA = TtagMONHSZSTRUCTA

type TPMONHSZSTRUCTA = uintptr

type PMONHSZSTRUCTA = TPMONHSZSTRUCTA

type TMONHSZSTRUCTW = struct {
	Fcb       TUINT
	FfsAction TWINBOOL
	FdwTime   TDWORD
	Fhsz      THSZ
	FhTask    THANDLE
	Fstr      [1]TWCHAR
}

type MONHSZSTRUCTW = TMONHSZSTRUCTW

type TtagMONHSZSTRUCTW = TMONHSZSTRUCTW

type tagMONHSZSTRUCTW = TtagMONHSZSTRUCTW

type TPMONHSZSTRUCTW = uintptr

type PMONHSZSTRUCTW = TPMONHSZSTRUCTW

type TMONHSZSTRUCT = struct {
	Fcb       TUINT
	FfsAction TWINBOOL
	FdwTime   TDWORD
	Fhsz      THSZ
	FhTask    THANDLE
	Fstr      [1]TCHAR
}

type MONHSZSTRUCT = TMONHSZSTRUCT

type TPMONHSZSTRUCT = uintptr

type PMONHSZSTRUCT = TPMONHSZSTRUCT

type TMONERRSTRUCT = struct {
	Fcb         TUINT
	FwLastError TUINT
	FdwTime     TDWORD
	FhTask      THANDLE
}

type MONERRSTRUCT = TMONERRSTRUCT

type TtagMONERRSTRUCT = TMONERRSTRUCT

type tagMONERRSTRUCT = TtagMONERRSTRUCT

type TPMONERRSTRUCT = uintptr

type PMONERRSTRUCT = TPMONERRSTRUCT

type TMONLINKSTRUCT = struct {
	Fcb           TUINT
	FdwTime       TDWORD
	FhTask        THANDLE
	FfEstablished TWINBOOL
	FfNoData      TWINBOOL
	FhszSvc       THSZ
	FhszTopic     THSZ
	FhszItem      THSZ
	FwFmt         TUINT
	FfServer      TWINBOOL
	FhConvServer  THCONV
	FhConvClient  THCONV
}

type MONLINKSTRUCT = TMONLINKSTRUCT

type TtagMONLINKSTRUCT = TMONLINKSTRUCT

type tagMONLINKSTRUCT = TtagMONLINKSTRUCT

type TPMONLINKSTRUCT = uintptr

type PMONLINKSTRUCT = TPMONLINKSTRUCT

type TMONCONVSTRUCT = struct {
	Fcb          TUINT
	FfConnect    TWINBOOL
	FdwTime      TDWORD
	FhTask       THANDLE
	FhszSvc      THSZ
	FhszTopic    THSZ
	FhConvClient THCONV
	FhConvServer THCONV
}

type MONCONVSTRUCT = TMONCONVSTRUCT

type TtagMONCONVSTRUCT = TMONCONVSTRUCT

type tagMONCONVSTRUCT = TtagMONCONVSTRUCT

type TPMONCONVSTRUCT = uintptr

type PMONCONVSTRUCT = TPMONCONVSTRUCT

type TCRGB = struct {
	FbRed   TBYTE
	FbGreen TBYTE
	FbBlue  TBYTE
	FbExtra TBYTE
}

type CRGB = TCRGB

type TtagCRGB = TCRGB

type tagCRGB = TtagCRGB

type TMMVERSION = uint32

type MMVERSION = TMMVERSION

type TMMRESULT = uint32

type MMRESULT = TMMRESULT

type TLPUINT = uintptr

type LPUINT = TLPUINT

type TMMTIME = struct {
	FwType TUINT
	Fu     struct {
		Fsample [0]TDWORD
		Fcb     [0]TDWORD
		Fticks  [0]TDWORD
		Fsmpte  [0]struct {
			Fhour  TBYTE
			Fmin   TBYTE
			Fsec   TBYTE
			Fframe TBYTE
			Ffps   TBYTE
			Fdummy TBYTE
			Fpad   [2]TBYTE
		}
		Fmidi [0]struct {
			Fsongptrpos TDWORD
		}
		Fms          TDWORD
		F__ccgo_pad6 [4]byte
	}
}

type MMTIME = TMMTIME

type Tmmtime_tag = TMMTIME

type mmtime_tag = Tmmtime_tag

type TPMMTIME = uintptr

type PMMTIME = TPMMTIME

type TNPMMTIME = uintptr

type NPMMTIME = TNPMMTIME

type TLPMMTIME = uintptr

type LPMMTIME = TLPMMTIME

type THDRVR__ = struct {
	Funused int32
}

type HDRVR__ = THDRVR__

type THDRVR = uintptr

type HDRVR = THDRVR

type TDRVCONFIGINFOEX = struct {
	FdwDCISize          TDWORD
	FlpszDCISectionName TLPCWSTR
	FlpszDCIAliasName   TLPCWSTR
	FdnDevNode          TDWORD
}

type DRVCONFIGINFOEX = TDRVCONFIGINFOEX

type TPDRVCONFIGINFOEX = uintptr

type PDRVCONFIGINFOEX = TPDRVCONFIGINFOEX

type TDRVCONFIGINFOEX1 = struct {
	FdwDCISize          TDWORD
	FlpszDCISectionName TLPCWSTR
	FlpszDCIAliasName   TLPCWSTR
	FdnDevNode          TDWORD
}

type DRVCONFIGINFOEX1 = TDRVCONFIGINFOEX1

type TNPDRVCONFIGINFOEX = uintptr

type NPDRVCONFIGINFOEX = TNPDRVCONFIGINFOEX

type TLPDRVCONFIGINFOEX = uintptr

type LPDRVCONFIGINFOEX = TLPDRVCONFIGINFOEX

type TDRVCONFIGINFO = struct {
	FdwDCISize          TDWORD
	FlpszDCISectionName TLPCWSTR
	FlpszDCIAliasName   TLPCWSTR
}

type DRVCONFIGINFO = TDRVCONFIGINFO

type TtagDRVCONFIGINFO = TDRVCONFIGINFO

type tagDRVCONFIGINFO = TtagDRVCONFIGINFO

type TPDRVCONFIGINFO = uintptr

type PDRVCONFIGINFO = TPDRVCONFIGINFO

type TNPDRVCONFIGINFO = uintptr

type NPDRVCONFIGINFO = TNPDRVCONFIGINFO

type TLPDRVCONFIGINFO = uintptr

type LPDRVCONFIGINFO = TLPDRVCONFIGINFO

type TDRIVERPROC = uintptr

type DRIVERPROC = TDRIVERPROC

type TLPDRVCALLBACK = uintptr

type LPDRVCALLBACK = TLPDRVCALLBACK

type TPDRVCALLBACK = uintptr

type PDRVCALLBACK = TPDRVCALLBACK

type THWAVE__ = struct {
	Funused int32
}

type HWAVE__ = THWAVE__

type THWAVE = uintptr

type HWAVE = THWAVE

type THWAVEIN__ = struct {
	Funused int32
}

type HWAVEIN__ = THWAVEIN__

type THWAVEIN = uintptr

type HWAVEIN = THWAVEIN

type THWAVEOUT__ = struct {
	Funused int32
}

type HWAVEOUT__ = THWAVEOUT__

type THWAVEOUT = uintptr

type HWAVEOUT = THWAVEOUT

type TLPHWAVEIN = uintptr

type LPHWAVEIN = TLPHWAVEIN

type TLPHWAVEOUT = uintptr

type LPHWAVEOUT = TLPHWAVEOUT

type TLPWAVECALLBACK = uintptr

type LPWAVECALLBACK = TLPWAVECALLBACK

type TWAVEHDR = struct {
	FlpData          TLPSTR
	FdwBufferLength  TDWORD
	FdwBytesRecorded TDWORD
	FdwUser          TDWORD_PTR
	FdwFlags         TDWORD
	FdwLoops         TDWORD
	FlpNext          uintptr
	Freserved        TDWORD_PTR
}

type WAVEHDR = TWAVEHDR

type Twavehdr_tag = TWAVEHDR

type wavehdr_tag = Twavehdr_tag

type TPWAVEHDR = uintptr

type PWAVEHDR = TPWAVEHDR

type TNPWAVEHDR = uintptr

type NPWAVEHDR = TNPWAVEHDR

type TLPWAVEHDR = uintptr

type LPWAVEHDR = TLPWAVEHDR

type TWAVEOUTCAPSA = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FdwFormats      TDWORD
	FwChannels      TWORD
	FwReserved1     TWORD
	FdwSupport      TDWORD
}

type WAVEOUTCAPSA = TWAVEOUTCAPSA

type TtagWAVEOUTCAPSA = TWAVEOUTCAPSA

type tagWAVEOUTCAPSA = TtagWAVEOUTCAPSA

type TPWAVEOUTCAPSA = uintptr

type PWAVEOUTCAPSA = TPWAVEOUTCAPSA

type TNPWAVEOUTCAPSA = uintptr

type NPWAVEOUTCAPSA = TNPWAVEOUTCAPSA

type TLPWAVEOUTCAPSA = uintptr

type LPWAVEOUTCAPSA = TLPWAVEOUTCAPSA

type TWAVEOUTCAPSW = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TWCHAR
	FdwFormats      TDWORD
	FwChannels      TWORD
	FwReserved1     TWORD
	FdwSupport      TDWORD
}

type WAVEOUTCAPSW = TWAVEOUTCAPSW

type TtagWAVEOUTCAPSW = TWAVEOUTCAPSW

type tagWAVEOUTCAPSW = TtagWAVEOUTCAPSW

type TPWAVEOUTCAPSW = uintptr

type PWAVEOUTCAPSW = TPWAVEOUTCAPSW

type TNPWAVEOUTCAPSW = uintptr

type NPWAVEOUTCAPSW = TNPWAVEOUTCAPSW

type TLPWAVEOUTCAPSW = uintptr

type LPWAVEOUTCAPSW = TLPWAVEOUTCAPSW

type TWAVEOUTCAPS = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FdwFormats      TDWORD
	FwChannels      TWORD
	FwReserved1     TWORD
	FdwSupport      TDWORD
}

type WAVEOUTCAPS = TWAVEOUTCAPS

type TPWAVEOUTCAPS = uintptr

type PWAVEOUTCAPS = TPWAVEOUTCAPS

type TNPWAVEOUTCAPS = uintptr

type NPWAVEOUTCAPS = TNPWAVEOUTCAPS

type TLPWAVEOUTCAPS = uintptr

type LPWAVEOUTCAPS = TLPWAVEOUTCAPS

type TWAVEOUTCAPS2A = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FdwFormats        TDWORD
	FwChannels        TWORD
	FwReserved1       TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type WAVEOUTCAPS2A = TWAVEOUTCAPS2A

type TtagWAVEOUTCAPS2A = TWAVEOUTCAPS2A

type tagWAVEOUTCAPS2A = TtagWAVEOUTCAPS2A

type TPWAVEOUTCAPS2A = uintptr

type PWAVEOUTCAPS2A = TPWAVEOUTCAPS2A

type TNPWAVEOUTCAPS2A = uintptr

type NPWAVEOUTCAPS2A = TNPWAVEOUTCAPS2A

type TLPWAVEOUTCAPS2A = uintptr

type LPWAVEOUTCAPS2A = TLPWAVEOUTCAPS2A

type TWAVEOUTCAPS2W = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TWCHAR
	FdwFormats        TDWORD
	FwChannels        TWORD
	FwReserved1       TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type WAVEOUTCAPS2W = TWAVEOUTCAPS2W

type TtagWAVEOUTCAPS2W = TWAVEOUTCAPS2W

type tagWAVEOUTCAPS2W = TtagWAVEOUTCAPS2W

type TPWAVEOUTCAPS2W = uintptr

type PWAVEOUTCAPS2W = TPWAVEOUTCAPS2W

type TNPWAVEOUTCAPS2W = uintptr

type NPWAVEOUTCAPS2W = TNPWAVEOUTCAPS2W

type TLPWAVEOUTCAPS2W = uintptr

type LPWAVEOUTCAPS2W = TLPWAVEOUTCAPS2W

type TWAVEOUTCAPS2 = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FdwFormats        TDWORD
	FwChannels        TWORD
	FwReserved1       TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type WAVEOUTCAPS2 = TWAVEOUTCAPS2

type TPWAVEOUTCAPS2 = uintptr

type PWAVEOUTCAPS2 = TPWAVEOUTCAPS2

type TNPWAVEOUTCAPS2 = uintptr

type NPWAVEOUTCAPS2 = TNPWAVEOUTCAPS2

type TLPWAVEOUTCAPS2 = uintptr

type LPWAVEOUTCAPS2 = TLPWAVEOUTCAPS2

type TWAVEINCAPSA = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FdwFormats      TDWORD
	FwChannels      TWORD
	FwReserved1     TWORD
}

type WAVEINCAPSA = TWAVEINCAPSA

type TtagWAVEINCAPSA = TWAVEINCAPSA

type tagWAVEINCAPSA = TtagWAVEINCAPSA

type TPWAVEINCAPSA = uintptr

type PWAVEINCAPSA = TPWAVEINCAPSA

type TNPWAVEINCAPSA = uintptr

type NPWAVEINCAPSA = TNPWAVEINCAPSA

type TLPWAVEINCAPSA = uintptr

type LPWAVEINCAPSA = TLPWAVEINCAPSA

type TWAVEINCAPSW = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TWCHAR
	FdwFormats      TDWORD
	FwChannels      TWORD
	FwReserved1     TWORD
}

type WAVEINCAPSW = TWAVEINCAPSW

type TtagWAVEINCAPSW = TWAVEINCAPSW

type tagWAVEINCAPSW = TtagWAVEINCAPSW

type TPWAVEINCAPSW = uintptr

type PWAVEINCAPSW = TPWAVEINCAPSW

type TNPWAVEINCAPSW = uintptr

type NPWAVEINCAPSW = TNPWAVEINCAPSW

type TLPWAVEINCAPSW = uintptr

type LPWAVEINCAPSW = TLPWAVEINCAPSW

type TWAVEINCAPS = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FdwFormats      TDWORD
	FwChannels      TWORD
	FwReserved1     TWORD
}

type WAVEINCAPS = TWAVEINCAPS

type TPWAVEINCAPS = uintptr

type PWAVEINCAPS = TPWAVEINCAPS

type TNPWAVEINCAPS = uintptr

type NPWAVEINCAPS = TNPWAVEINCAPS

type TLPWAVEINCAPS = uintptr

type LPWAVEINCAPS = TLPWAVEINCAPS

type TWAVEINCAPS2A = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FdwFormats        TDWORD
	FwChannels        TWORD
	FwReserved1       TWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type WAVEINCAPS2A = TWAVEINCAPS2A

type TtagWAVEINCAPS2A = TWAVEINCAPS2A

type tagWAVEINCAPS2A = TtagWAVEINCAPS2A

type TPWAVEINCAPS2A = uintptr

type PWAVEINCAPS2A = TPWAVEINCAPS2A

type TNPWAVEINCAPS2A = uintptr

type NPWAVEINCAPS2A = TNPWAVEINCAPS2A

type TLPWAVEINCAPS2A = uintptr

type LPWAVEINCAPS2A = TLPWAVEINCAPS2A

type TWAVEINCAPS2W = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TWCHAR
	FdwFormats        TDWORD
	FwChannels        TWORD
	FwReserved1       TWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type WAVEINCAPS2W = TWAVEINCAPS2W

type TtagWAVEINCAPS2W = TWAVEINCAPS2W

type tagWAVEINCAPS2W = TtagWAVEINCAPS2W

type TPWAVEINCAPS2W = uintptr

type PWAVEINCAPS2W = TPWAVEINCAPS2W

type TNPWAVEINCAPS2W = uintptr

type NPWAVEINCAPS2W = TNPWAVEINCAPS2W

type TLPWAVEINCAPS2W = uintptr

type LPWAVEINCAPS2W = TLPWAVEINCAPS2W

type TWAVEINCAPS2 = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FdwFormats        TDWORD
	FwChannels        TWORD
	FwReserved1       TWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type WAVEINCAPS2 = TWAVEINCAPS2

type TPWAVEINCAPS2 = uintptr

type PWAVEINCAPS2 = TPWAVEINCAPS2

type TNPWAVEINCAPS2 = uintptr

type NPWAVEINCAPS2 = TNPWAVEINCAPS2

type TLPWAVEINCAPS2 = uintptr

type LPWAVEINCAPS2 = TLPWAVEINCAPS2

type TWAVEFORMAT = struct {
	FwFormatTag      TWORD
	FnChannels       TWORD
	FnSamplesPerSec  TDWORD
	FnAvgBytesPerSec TDWORD
	FnBlockAlign     TWORD
}

type WAVEFORMAT = TWAVEFORMAT

type Twaveformat_tag = TWAVEFORMAT

type waveformat_tag = Twaveformat_tag

type TPWAVEFORMAT = uintptr

type PWAVEFORMAT = TPWAVEFORMAT

type TNPWAVEFORMAT = uintptr

type NPWAVEFORMAT = TNPWAVEFORMAT

type TLPWAVEFORMAT = uintptr

type LPWAVEFORMAT = TLPWAVEFORMAT

type TPCMWAVEFORMAT = struct {
	Fwf             TWAVEFORMAT
	FwBitsPerSample TWORD
}

type PCMWAVEFORMAT = TPCMWAVEFORMAT

type Tpcmwaveformat_tag = TPCMWAVEFORMAT

type pcmwaveformat_tag = Tpcmwaveformat_tag

type TPPCMWAVEFORMAT = uintptr

type PPCMWAVEFORMAT = TPPCMWAVEFORMAT

type TNPPCMWAVEFORMAT = uintptr

type NPPCMWAVEFORMAT = TNPPCMWAVEFORMAT

type TLPPCMWAVEFORMAT = uintptr

type LPPCMWAVEFORMAT = TLPPCMWAVEFORMAT

type TWAVEFORMATEX = struct {
	FwFormatTag      TWORD
	FnChannels       TWORD
	FnSamplesPerSec  TDWORD
	FnAvgBytesPerSec TDWORD
	FnBlockAlign     TWORD
	FwBitsPerSample  TWORD
	FcbSize          TWORD
}

type WAVEFORMATEX = TWAVEFORMATEX

type TtWAVEFORMATEX = TWAVEFORMATEX

type tWAVEFORMATEX = TtWAVEFORMATEX

type TPWAVEFORMATEX = uintptr

type PWAVEFORMATEX = TPWAVEFORMATEX

type TNPWAVEFORMATEX = uintptr

type NPWAVEFORMATEX = TNPWAVEFORMATEX

type TLPWAVEFORMATEX = uintptr

type LPWAVEFORMATEX = TLPWAVEFORMATEX

type TLPCWAVEFORMATEX = uintptr

type LPCWAVEFORMATEX = TLPCWAVEFORMATEX

type THMIDI__ = struct {
	Funused int32
}

type HMIDI__ = THMIDI__

type THMIDI = uintptr

type HMIDI = THMIDI

type THMIDIIN__ = struct {
	Funused int32
}

type HMIDIIN__ = THMIDIIN__

type THMIDIIN = uintptr

type HMIDIIN = THMIDIIN

type THMIDIOUT__ = struct {
	Funused int32
}

type HMIDIOUT__ = THMIDIOUT__

type THMIDIOUT = uintptr

type HMIDIOUT = THMIDIOUT

type THMIDISTRM__ = struct {
	Funused int32
}

type HMIDISTRM__ = THMIDISTRM__

type THMIDISTRM = uintptr

type HMIDISTRM = THMIDISTRM

type TLPHMIDI = uintptr

type LPHMIDI = TLPHMIDI

type TLPHMIDIIN = uintptr

type LPHMIDIIN = TLPHMIDIIN

type TLPHMIDIOUT = uintptr

type LPHMIDIOUT = TLPHMIDIOUT

type TLPHMIDISTRM = uintptr

type LPHMIDISTRM = TLPHMIDISTRM

type TLPMIDICALLBACK = uintptr

type LPMIDICALLBACK = TLPMIDICALLBACK

type TPATCHARRAY = [128]TWORD

type PATCHARRAY = TPATCHARRAY

type TLPPATCHARRAY = uintptr

type LPPATCHARRAY = TLPPATCHARRAY

type TKEYARRAY = [128]TWORD

type KEYARRAY = TKEYARRAY

type TLPKEYARRAY = uintptr

type LPKEYARRAY = TLPKEYARRAY

type TMIDIOUTCAPSA = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FwTechnology    TWORD
	FwVoices        TWORD
	FwNotes         TWORD
	FwChannelMask   TWORD
	FdwSupport      TDWORD
}

type MIDIOUTCAPSA = TMIDIOUTCAPSA

type TtagMIDIOUTCAPSA = TMIDIOUTCAPSA

type tagMIDIOUTCAPSA = TtagMIDIOUTCAPSA

type TPMIDIOUTCAPSA = uintptr

type PMIDIOUTCAPSA = TPMIDIOUTCAPSA

type TNPMIDIOUTCAPSA = uintptr

type NPMIDIOUTCAPSA = TNPMIDIOUTCAPSA

type TLPMIDIOUTCAPSA = uintptr

type LPMIDIOUTCAPSA = TLPMIDIOUTCAPSA

type TMIDIOUTCAPSW = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TWCHAR
	FwTechnology    TWORD
	FwVoices        TWORD
	FwNotes         TWORD
	FwChannelMask   TWORD
	FdwSupport      TDWORD
}

type MIDIOUTCAPSW = TMIDIOUTCAPSW

type TtagMIDIOUTCAPSW = TMIDIOUTCAPSW

type tagMIDIOUTCAPSW = TtagMIDIOUTCAPSW

type TPMIDIOUTCAPSW = uintptr

type PMIDIOUTCAPSW = TPMIDIOUTCAPSW

type TNPMIDIOUTCAPSW = uintptr

type NPMIDIOUTCAPSW = TNPMIDIOUTCAPSW

type TLPMIDIOUTCAPSW = uintptr

type LPMIDIOUTCAPSW = TLPMIDIOUTCAPSW

type TMIDIOUTCAPS = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FwTechnology    TWORD
	FwVoices        TWORD
	FwNotes         TWORD
	FwChannelMask   TWORD
	FdwSupport      TDWORD
}

type MIDIOUTCAPS = TMIDIOUTCAPS

type TPMIDIOUTCAPS = uintptr

type PMIDIOUTCAPS = TPMIDIOUTCAPS

type TNPMIDIOUTCAPS = uintptr

type NPMIDIOUTCAPS = TNPMIDIOUTCAPS

type TLPMIDIOUTCAPS = uintptr

type LPMIDIOUTCAPS = TLPMIDIOUTCAPS

type TMIDIOUTCAPS2A = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FwTechnology      TWORD
	FwVoices          TWORD
	FwNotes           TWORD
	FwChannelMask     TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIDIOUTCAPS2A = TMIDIOUTCAPS2A

type TtagMIDIOUTCAPS2A = TMIDIOUTCAPS2A

type tagMIDIOUTCAPS2A = TtagMIDIOUTCAPS2A

type TPMIDIOUTCAPS2A = uintptr

type PMIDIOUTCAPS2A = TPMIDIOUTCAPS2A

type TNPMIDIOUTCAPS2A = uintptr

type NPMIDIOUTCAPS2A = TNPMIDIOUTCAPS2A

type TLPMIDIOUTCAPS2A = uintptr

type LPMIDIOUTCAPS2A = TLPMIDIOUTCAPS2A

type TMIDIOUTCAPS2W = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TWCHAR
	FwTechnology      TWORD
	FwVoices          TWORD
	FwNotes           TWORD
	FwChannelMask     TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIDIOUTCAPS2W = TMIDIOUTCAPS2W

type TtagMIDIOUTCAPS2W = TMIDIOUTCAPS2W

type tagMIDIOUTCAPS2W = TtagMIDIOUTCAPS2W

type TPMIDIOUTCAPS2W = uintptr

type PMIDIOUTCAPS2W = TPMIDIOUTCAPS2W

type TNPMIDIOUTCAPS2W = uintptr

type NPMIDIOUTCAPS2W = TNPMIDIOUTCAPS2W

type TLPMIDIOUTCAPS2W = uintptr

type LPMIDIOUTCAPS2W = TLPMIDIOUTCAPS2W

type TMIDIOUTCAPS2 = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FwTechnology      TWORD
	FwVoices          TWORD
	FwNotes           TWORD
	FwChannelMask     TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIDIOUTCAPS2 = TMIDIOUTCAPS2

type TPMIDIOUTCAPS2 = uintptr

type PMIDIOUTCAPS2 = TPMIDIOUTCAPS2

type TNPMIDIOUTCAPS2 = uintptr

type NPMIDIOUTCAPS2 = TNPMIDIOUTCAPS2

type TLPMIDIOUTCAPS2 = uintptr

type LPMIDIOUTCAPS2 = TLPMIDIOUTCAPS2

type TMIDIINCAPSA = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FdwSupport      TDWORD
}

type MIDIINCAPSA = TMIDIINCAPSA

type TtagMIDIINCAPSA = TMIDIINCAPSA

type tagMIDIINCAPSA = TtagMIDIINCAPSA

type TPMIDIINCAPSA = uintptr

type PMIDIINCAPSA = TPMIDIINCAPSA

type TNPMIDIINCAPSA = uintptr

type NPMIDIINCAPSA = TNPMIDIINCAPSA

type TLPMIDIINCAPSA = uintptr

type LPMIDIINCAPSA = TLPMIDIINCAPSA

type TMIDIINCAPSW = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TWCHAR
	FdwSupport      TDWORD
}

type MIDIINCAPSW = TMIDIINCAPSW

type TtagMIDIINCAPSW = TMIDIINCAPSW

type tagMIDIINCAPSW = TtagMIDIINCAPSW

type TPMIDIINCAPSW = uintptr

type PMIDIINCAPSW = TPMIDIINCAPSW

type TNPMIDIINCAPSW = uintptr

type NPMIDIINCAPSW = TNPMIDIINCAPSW

type TLPMIDIINCAPSW = uintptr

type LPMIDIINCAPSW = TLPMIDIINCAPSW

type TMIDIINCAPS = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FdwSupport      TDWORD
}

type MIDIINCAPS = TMIDIINCAPS

type TPMIDIINCAPS = uintptr

type PMIDIINCAPS = TPMIDIINCAPS

type TNPMIDIINCAPS = uintptr

type NPMIDIINCAPS = TNPMIDIINCAPS

type TLPMIDIINCAPS = uintptr

type LPMIDIINCAPS = TLPMIDIINCAPS

type TMIDIINCAPS2A = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIDIINCAPS2A = TMIDIINCAPS2A

type TtagMIDIINCAPS2A = TMIDIINCAPS2A

type tagMIDIINCAPS2A = TtagMIDIINCAPS2A

type TPMIDIINCAPS2A = uintptr

type PMIDIINCAPS2A = TPMIDIINCAPS2A

type TNPMIDIINCAPS2A = uintptr

type NPMIDIINCAPS2A = TNPMIDIINCAPS2A

type TLPMIDIINCAPS2A = uintptr

type LPMIDIINCAPS2A = TLPMIDIINCAPS2A

type TMIDIINCAPS2W = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TWCHAR
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIDIINCAPS2W = TMIDIINCAPS2W

type TtagMIDIINCAPS2W = TMIDIINCAPS2W

type tagMIDIINCAPS2W = TtagMIDIINCAPS2W

type TPMIDIINCAPS2W = uintptr

type PMIDIINCAPS2W = TPMIDIINCAPS2W

type TNPMIDIINCAPS2W = uintptr

type NPMIDIINCAPS2W = TNPMIDIINCAPS2W

type TLPMIDIINCAPS2W = uintptr

type LPMIDIINCAPS2W = TLPMIDIINCAPS2W

type TMIDIINCAPS2 = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIDIINCAPS2 = TMIDIINCAPS2

type TPMIDIINCAPS2 = uintptr

type PMIDIINCAPS2 = TPMIDIINCAPS2

type TNPMIDIINCAPS2 = uintptr

type NPMIDIINCAPS2 = TNPMIDIINCAPS2

type TLPMIDIINCAPS2 = uintptr

type LPMIDIINCAPS2 = TLPMIDIINCAPS2

type TMIDIHDR = struct {
	FlpData          TLPSTR
	FdwBufferLength  TDWORD
	FdwBytesRecorded TDWORD
	FdwUser          TDWORD_PTR
	FdwFlags         TDWORD
	FlpNext          uintptr
	Freserved        TDWORD_PTR
	FdwOffset        TDWORD
	FdwReserved      [8]TDWORD_PTR
}

type MIDIHDR = TMIDIHDR

type Tmidihdr_tag = TMIDIHDR

type midihdr_tag = Tmidihdr_tag

type TPMIDIHDR = uintptr

type PMIDIHDR = TPMIDIHDR

type TNPMIDIHDR = uintptr

type NPMIDIHDR = TNPMIDIHDR

type TLPMIDIHDR = uintptr

type LPMIDIHDR = TLPMIDIHDR

type TMIDIEVENT = struct {
	FdwDeltaTime TDWORD
	FdwStreamID  TDWORD
	FdwEvent     TDWORD
	FdwParms     [1]TDWORD
}

type MIDIEVENT = TMIDIEVENT

type Tmidievent_tag = TMIDIEVENT

type midievent_tag = Tmidievent_tag

type TMIDISTRMBUFFVER = struct {
	FdwVersion    TDWORD
	FdwMid        TDWORD
	FdwOEMVersion TDWORD
}

type MIDISTRMBUFFVER = TMIDISTRMBUFFVER

type Tmidistrmbuffver_tag = TMIDISTRMBUFFVER

type midistrmbuffver_tag = Tmidistrmbuffver_tag

type TMIDIPROPTIMEDIV = struct {
	FcbStruct  TDWORD
	FdwTimeDiv TDWORD
}

type MIDIPROPTIMEDIV = TMIDIPROPTIMEDIV

type Tmidiproptimediv_tag = TMIDIPROPTIMEDIV

type midiproptimediv_tag = Tmidiproptimediv_tag

type TLPMIDIPROPTIMEDIV = uintptr

type LPMIDIPROPTIMEDIV = TLPMIDIPROPTIMEDIV

type TMIDIPROPTEMPO = struct {
	FcbStruct TDWORD
	FdwTempo  TDWORD
}

type MIDIPROPTEMPO = TMIDIPROPTEMPO

type Tmidiproptempo_tag = TMIDIPROPTEMPO

type midiproptempo_tag = Tmidiproptempo_tag

type TLPMIDIPROPTEMPO = uintptr

type LPMIDIPROPTEMPO = TLPMIDIPROPTEMPO

type TAUXCAPSA = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FwTechnology    TWORD
	FwReserved1     TWORD
	FdwSupport      TDWORD
}

type AUXCAPSA = TAUXCAPSA

type TtagAUXCAPSA = TAUXCAPSA

type tagAUXCAPSA = TtagAUXCAPSA

type TPAUXCAPSA = uintptr

type PAUXCAPSA = TPAUXCAPSA

type TNPAUXCAPSA = uintptr

type NPAUXCAPSA = TNPAUXCAPSA

type TLPAUXCAPSA = uintptr

type LPAUXCAPSA = TLPAUXCAPSA

type TAUXCAPSW = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TWCHAR
	FwTechnology    TWORD
	FwReserved1     TWORD
	FdwSupport      TDWORD
}

type AUXCAPSW = TAUXCAPSW

type TtagAUXCAPSW = TAUXCAPSW

type tagAUXCAPSW = TtagAUXCAPSW

type TPAUXCAPSW = uintptr

type PAUXCAPSW = TPAUXCAPSW

type TNPAUXCAPSW = uintptr

type NPAUXCAPSW = TNPAUXCAPSW

type TLPAUXCAPSW = uintptr

type LPAUXCAPSW = TLPAUXCAPSW

type TAUXCAPS = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FwTechnology    TWORD
	FwReserved1     TWORD
	FdwSupport      TDWORD
}

type AUXCAPS = TAUXCAPS

type TPAUXCAPS = uintptr

type PAUXCAPS = TPAUXCAPS

type TNPAUXCAPS = uintptr

type NPAUXCAPS = TNPAUXCAPS

type TLPAUXCAPS = uintptr

type LPAUXCAPS = TLPAUXCAPS

type TAUXCAPS2A = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FwTechnology      TWORD
	FwReserved1       TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type AUXCAPS2A = TAUXCAPS2A

type TtagAUXCAPS2A = TAUXCAPS2A

type tagAUXCAPS2A = TtagAUXCAPS2A

type TPAUXCAPS2A = uintptr

type PAUXCAPS2A = TPAUXCAPS2A

type TNPAUXCAPS2A = uintptr

type NPAUXCAPS2A = TNPAUXCAPS2A

type TLPAUXCAPS2A = uintptr

type LPAUXCAPS2A = TLPAUXCAPS2A

type TAUXCAPS2W = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TWCHAR
	FwTechnology      TWORD
	FwReserved1       TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type AUXCAPS2W = TAUXCAPS2W

type TtagAUXCAPS2W = TAUXCAPS2W

type tagAUXCAPS2W = TtagAUXCAPS2W

type TPAUXCAPS2W = uintptr

type PAUXCAPS2W = TPAUXCAPS2W

type TNPAUXCAPS2W = uintptr

type NPAUXCAPS2W = TNPAUXCAPS2W

type TLPAUXCAPS2W = uintptr

type LPAUXCAPS2W = TLPAUXCAPS2W

type TAUXCAPS2 = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FwTechnology      TWORD
	FwReserved1       TWORD
	FdwSupport        TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type AUXCAPS2 = TAUXCAPS2

type TPAUXCAPS2 = uintptr

type PAUXCAPS2 = TPAUXCAPS2

type TNPAUXCAPS2 = uintptr

type NPAUXCAPS2 = TNPAUXCAPS2

type TLPAUXCAPS2 = uintptr

type LPAUXCAPS2 = TLPAUXCAPS2

type THMIXEROBJ__ = struct {
	Funused int32
}

type HMIXEROBJ__ = THMIXEROBJ__

type THMIXEROBJ = uintptr

type HMIXEROBJ = THMIXEROBJ

type TLPHMIXEROBJ = uintptr

type LPHMIXEROBJ = TLPHMIXEROBJ

type THMIXER__ = struct {
	Funused int32
}

type HMIXER__ = THMIXER__

type THMIXER = uintptr

type HMIXER = THMIXER

type TLPHMIXER = uintptr

type LPHMIXER = TLPHMIXER

type TMIXERCAPSA = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FfdwSupport     TDWORD
	FcDestinations  TDWORD
}

type MIXERCAPSA = TMIXERCAPSA

type TtagMIXERCAPSA = TMIXERCAPSA

type tagMIXERCAPSA = TtagMIXERCAPSA

type TPMIXERCAPSA = uintptr

type PMIXERCAPSA = TPMIXERCAPSA

type TLPMIXERCAPSA = uintptr

type LPMIXERCAPSA = TLPMIXERCAPSA

type TMIXERCAPSW = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TWCHAR
	FfdwSupport     TDWORD
	FcDestinations  TDWORD
}

type MIXERCAPSW = TMIXERCAPSW

type TtagMIXERCAPSW = TMIXERCAPSW

type tagMIXERCAPSW = TtagMIXERCAPSW

type TPMIXERCAPSW = uintptr

type PMIXERCAPSW = TPMIXERCAPSW

type TLPMIXERCAPSW = uintptr

type LPMIXERCAPSW = TLPMIXERCAPSW

type TMIXERCAPS = struct {
	FwMid           TWORD
	FwPid           TWORD
	FvDriverVersion TMMVERSION
	FszPname        [32]TCHAR
	FfdwSupport     TDWORD
	FcDestinations  TDWORD
}

type MIXERCAPS = TMIXERCAPS

type TPMIXERCAPS = uintptr

type PMIXERCAPS = TPMIXERCAPS

type TLPMIXERCAPS = uintptr

type LPMIXERCAPS = TLPMIXERCAPS

type TMIXERCAPS2A = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FfdwSupport       TDWORD
	FcDestinations    TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIXERCAPS2A = TMIXERCAPS2A

type TtagMIXERCAPS2A = TMIXERCAPS2A

type tagMIXERCAPS2A = TtagMIXERCAPS2A

type TPMIXERCAPS2A = uintptr

type PMIXERCAPS2A = TPMIXERCAPS2A

type TLPMIXERCAPS2A = uintptr

type LPMIXERCAPS2A = TLPMIXERCAPS2A

type TMIXERCAPS2W = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TWCHAR
	FfdwSupport       TDWORD
	FcDestinations    TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIXERCAPS2W = TMIXERCAPS2W

type TtagMIXERCAPS2W = TMIXERCAPS2W

type tagMIXERCAPS2W = TtagMIXERCAPS2W

type TPMIXERCAPS2W = uintptr

type PMIXERCAPS2W = TPMIXERCAPS2W

type TLPMIXERCAPS2W = uintptr

type LPMIXERCAPS2W = TLPMIXERCAPS2W

type TMIXERCAPS2 = struct {
	FwMid             TWORD
	FwPid             TWORD
	FvDriverVersion   TMMVERSION
	FszPname          [32]TCHAR
	FfdwSupport       TDWORD
	FcDestinations    TDWORD
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type MIXERCAPS2 = TMIXERCAPS2

type TPMIXERCAPS2 = uintptr

type PMIXERCAPS2 = TPMIXERCAPS2

type TLPMIXERCAPS2 = uintptr

type LPMIXERCAPS2 = TLPMIXERCAPS2

type TMIXERLINEA = struct {
	FcbStruct        TDWORD
	FdwDestination   TDWORD
	FdwSource        TDWORD
	FdwLineID        TDWORD
	FfdwLine         TDWORD
	FdwUser          TDWORD_PTR
	FdwComponentType TDWORD
	FcChannels       TDWORD
	FcConnections    TDWORD
	FcControls       TDWORD
	FszShortName     [16]TCHAR
	FszName          [64]TCHAR
	FTarget          struct {
		FdwType         TDWORD
		FdwDeviceID     TDWORD
		FwMid           TWORD
		FwPid           TWORD
		FvDriverVersion TMMVERSION
		FszPname        [32]TCHAR
	}
}

type MIXERLINEA = TMIXERLINEA

type TtagMIXERLINEA = TMIXERLINEA

type tagMIXERLINEA = TtagMIXERLINEA

type TPMIXERLINEA = uintptr

type PMIXERLINEA = TPMIXERLINEA

type TLPMIXERLINEA = uintptr

type LPMIXERLINEA = TLPMIXERLINEA

type TMIXERLINEW = struct {
	FcbStruct        TDWORD
	FdwDestination   TDWORD
	FdwSource        TDWORD
	FdwLineID        TDWORD
	FfdwLine         TDWORD
	FdwUser          TDWORD_PTR
	FdwComponentType TDWORD
	FcChannels       TDWORD
	FcConnections    TDWORD
	FcControls       TDWORD
	FszShortName     [16]TWCHAR
	FszName          [64]TWCHAR
	FTarget          struct {
		FdwType         TDWORD
		FdwDeviceID     TDWORD
		FwMid           TWORD
		FwPid           TWORD
		FvDriverVersion TMMVERSION
		FszPname        [32]TWCHAR
	}
}

type MIXERLINEW = TMIXERLINEW

type TtagMIXERLINEW = TMIXERLINEW

type tagMIXERLINEW = TtagMIXERLINEW

type TPMIXERLINEW = uintptr

type PMIXERLINEW = TPMIXERLINEW

type TLPMIXERLINEW = uintptr

type LPMIXERLINEW = TLPMIXERLINEW

type TMIXERLINE = struct {
	FcbStruct        TDWORD
	FdwDestination   TDWORD
	FdwSource        TDWORD
	FdwLineID        TDWORD
	FfdwLine         TDWORD
	FdwUser          TDWORD_PTR
	FdwComponentType TDWORD
	FcChannels       TDWORD
	FcConnections    TDWORD
	FcControls       TDWORD
	FszShortName     [16]TCHAR
	FszName          [64]TCHAR
	FTarget          struct {
		FdwType         TDWORD
		FdwDeviceID     TDWORD
		FwMid           TWORD
		FwPid           TWORD
		FvDriverVersion TMMVERSION
		FszPname        [32]TCHAR
	}
}

type MIXERLINE = TMIXERLINE

type TPMIXERLINE = uintptr

type PMIXERLINE = TPMIXERLINE

type TLPMIXERLINE = uintptr

type LPMIXERLINE = TLPMIXERLINE

type TMIXERCONTROLA = struct {
	FcbStruct       TDWORD
	FdwControlID    TDWORD
	FdwControlType  TDWORD
	FfdwControl     TDWORD
	FcMultipleItems TDWORD
	FszShortName    [16]TCHAR
	FszName         [64]TCHAR
	FBounds         struct {
		F__ccgo1_0 [0]struct {
			FdwMinimum TDWORD
			FdwMaximum TDWORD
		}
		FdwReserved [0][6]TDWORD
		F__ccgo0_0  struct {
			FlMinimum TLONG
			FlMaximum TLONG
		}
		F__ccgo_pad3 [16]byte
	}
	FMetrics struct {
		FcbCustomData [0]TDWORD
		FdwReserved   [0][6]TDWORD
		FcSteps       TDWORD
		F__ccgo_pad3  [20]byte
	}
}

type MIXERCONTROLA = TMIXERCONTROLA

type TtagMIXERCONTROLA = TMIXERCONTROLA

type tagMIXERCONTROLA = TtagMIXERCONTROLA

type TPMIXERCONTROLA = uintptr

type PMIXERCONTROLA = TPMIXERCONTROLA

type TLPMIXERCONTROLA = uintptr

type LPMIXERCONTROLA = TLPMIXERCONTROLA

type TMIXERCONTROLW = struct {
	FcbStruct       TDWORD
	FdwControlID    TDWORD
	FdwControlType  TDWORD
	FfdwControl     TDWORD
	FcMultipleItems TDWORD
	FszShortName    [16]TWCHAR
	FszName         [64]TWCHAR
	FBounds         struct {
		F__ccgo1_0 [0]struct {
			FdwMinimum TDWORD
			FdwMaximum TDWORD
		}
		FdwReserved [0][6]TDWORD
		F__ccgo0_0  struct {
			FlMinimum TLONG
			FlMaximum TLONG
		}
		F__ccgo_pad3 [16]byte
	}
	FMetrics struct {
		FcbCustomData [0]TDWORD
		FdwReserved   [0][6]TDWORD
		FcSteps       TDWORD
		F__ccgo_pad3  [20]byte
	}
}

type MIXERCONTROLW = TMIXERCONTROLW

type TtagMIXERCONTROLW = TMIXERCONTROLW

type tagMIXERCONTROLW = TtagMIXERCONTROLW

type TPMIXERCONTROLW = uintptr

type PMIXERCONTROLW = TPMIXERCONTROLW

type TLPMIXERCONTROLW = uintptr

type LPMIXERCONTROLW = TLPMIXERCONTROLW

type TMIXERCONTROL = struct {
	FcbStruct       TDWORD
	FdwControlID    TDWORD
	FdwControlType  TDWORD
	FfdwControl     TDWORD
	FcMultipleItems TDWORD
	FszShortName    [16]TCHAR
	FszName         [64]TCHAR
	FBounds         struct {
		F__ccgo1_0 [0]struct {
			FdwMinimum TDWORD
			FdwMaximum TDWORD
		}
		FdwReserved [0][6]TDWORD
		F__ccgo0_0  struct {
			FlMinimum TLONG
			FlMaximum TLONG
		}
		F__ccgo_pad3 [16]byte
	}
	FMetrics struct {
		FcbCustomData [0]TDWORD
		FdwReserved   [0][6]TDWORD
		FcSteps       TDWORD
		F__ccgo_pad3  [20]byte
	}
}

type MIXERCONTROL = TMIXERCONTROL

type TPMIXERCONTROL = uintptr

type PMIXERCONTROL = TPMIXERCONTROL

type TLPMIXERCONTROL = uintptr

type LPMIXERCONTROL = TLPMIXERCONTROL

type TMIXERLINECONTROLSA = struct {
	FcbStruct  TDWORD
	FdwLineID  TDWORD
	F__ccgo2_8 struct {
		FdwControlType [0]TDWORD
		FdwControlID   TDWORD
	}
	FcControls TDWORD
	Fcbmxctrl  TDWORD
	Fpamxctrl  TLPMIXERCONTROLA
}

type MIXERLINECONTROLSA = TMIXERLINECONTROLSA

type TtagMIXERLINECONTROLSA = TMIXERLINECONTROLSA

type tagMIXERLINECONTROLSA = TtagMIXERLINECONTROLSA

type TPMIXERLINECONTROLSA = uintptr

type PMIXERLINECONTROLSA = TPMIXERLINECONTROLSA

type TLPMIXERLINECONTROLSA = uintptr

type LPMIXERLINECONTROLSA = TLPMIXERLINECONTROLSA

type TMIXERLINECONTROLSW = struct {
	FcbStruct  TDWORD
	FdwLineID  TDWORD
	F__ccgo2_8 struct {
		FdwControlType [0]TDWORD
		FdwControlID   TDWORD
	}
	FcControls TDWORD
	Fcbmxctrl  TDWORD
	Fpamxctrl  TLPMIXERCONTROLW
}

type MIXERLINECONTROLSW = TMIXERLINECONTROLSW

type TtagMIXERLINECONTROLSW = TMIXERLINECONTROLSW

type tagMIXERLINECONTROLSW = TtagMIXERLINECONTROLSW

type TPMIXERLINECONTROLSW = uintptr

type PMIXERLINECONTROLSW = TPMIXERLINECONTROLSW

type TLPMIXERLINECONTROLSW = uintptr

type LPMIXERLINECONTROLSW = TLPMIXERLINECONTROLSW

type TMIXERLINECONTROLS = struct {
	FcbStruct  TDWORD
	FdwLineID  TDWORD
	F__ccgo2_8 struct {
		FdwControlType [0]TDWORD
		FdwControlID   TDWORD
	}
	FcControls TDWORD
	Fcbmxctrl  TDWORD
	Fpamxctrl  TLPMIXERCONTROLA
}

type MIXERLINECONTROLS = TMIXERLINECONTROLS

type TPMIXERLINECONTROLS = uintptr

type PMIXERLINECONTROLS = TPMIXERLINECONTROLS

type TLPMIXERLINECONTROLS = uintptr

type LPMIXERLINECONTROLS = TLPMIXERLINECONTROLS

type TMIXERCONTROLDETAILS = struct {
	FcbStruct    TDWORD
	FdwControlID TDWORD
	FcChannels   TDWORD
	F__ccgo3_12  struct {
		FcMultipleItems [0]TDWORD
		FhwndOwner      THWND
	}
	FcbDetails TDWORD
	FpaDetails TLPVOID
}

type MIXERCONTROLDETAILS = TMIXERCONTROLDETAILS

type TtMIXERCONTROLDETAILS = TMIXERCONTROLDETAILS

type tMIXERCONTROLDETAILS = TtMIXERCONTROLDETAILS

type TPMIXERCONTROLDETAILS = uintptr

type PMIXERCONTROLDETAILS = TPMIXERCONTROLDETAILS

type TLPMIXERCONTROLDETAILS = uintptr

type LPMIXERCONTROLDETAILS = TLPMIXERCONTROLDETAILS

type TMIXERCONTROLDETAILS_LISTTEXTA = struct {
	FdwParam1 TDWORD
	FdwParam2 TDWORD
	FszName   [64]TCHAR
}

type MIXERCONTROLDETAILS_LISTTEXTA = TMIXERCONTROLDETAILS_LISTTEXTA

type TtagMIXERCONTROLDETAILS_LISTTEXTA = TMIXERCONTROLDETAILS_LISTTEXTA

type tagMIXERCONTROLDETAILS_LISTTEXTA = TtagMIXERCONTROLDETAILS_LISTTEXTA

type TPMIXERCONTROLDETAILS_LISTTEXTA = uintptr

type PMIXERCONTROLDETAILS_LISTTEXTA = TPMIXERCONTROLDETAILS_LISTTEXTA

type TLPMIXERCONTROLDETAILS_LISTTEXTA = uintptr

type LPMIXERCONTROLDETAILS_LISTTEXTA = TLPMIXERCONTROLDETAILS_LISTTEXTA

type TMIXERCONTROLDETAILS_LISTTEXTW = struct {
	FdwParam1 TDWORD
	FdwParam2 TDWORD
	FszName   [64]TWCHAR
}

type MIXERCONTROLDETAILS_LISTTEXTW = TMIXERCONTROLDETAILS_LISTTEXTW

type TtagMIXERCONTROLDETAILS_LISTTEXTW = TMIXERCONTROLDETAILS_LISTTEXTW

type tagMIXERCONTROLDETAILS_LISTTEXTW = TtagMIXERCONTROLDETAILS_LISTTEXTW

type TPMIXERCONTROLDETAILS_LISTTEXTW = uintptr

type PMIXERCONTROLDETAILS_LISTTEXTW = TPMIXERCONTROLDETAILS_LISTTEXTW

type TLPMIXERCONTROLDETAILS_LISTTEXTW = uintptr

type LPMIXERCONTROLDETAILS_LISTTEXTW = TLPMIXERCONTROLDETAILS_LISTTEXTW

type TMIXERCONTROLDETAILS_LISTTEXT = struct {
	FdwParam1 TDWORD
	FdwParam2 TDWORD
	FszName   [64]TCHAR
}

type MIXERCONTROLDETAILS_LISTTEXT = TMIXERCONTROLDETAILS_LISTTEXT

type TPMIXERCONTROLDETAILS_LISTTEXT = uintptr

type PMIXERCONTROLDETAILS_LISTTEXT = TPMIXERCONTROLDETAILS_LISTTEXT

type TLPMIXERCONTROLDETAILS_LISTTEXT = uintptr

type LPMIXERCONTROLDETAILS_LISTTEXT = TLPMIXERCONTROLDETAILS_LISTTEXT

type TMIXERCONTROLDETAILS_BOOLEAN = struct {
	FfValue TLONG
}

type MIXERCONTROLDETAILS_BOOLEAN = TMIXERCONTROLDETAILS_BOOLEAN

type TtMIXERCONTROLDETAILS_BOOLEAN = TMIXERCONTROLDETAILS_BOOLEAN

type tMIXERCONTROLDETAILS_BOOLEAN = TtMIXERCONTROLDETAILS_BOOLEAN

type TPMIXERCONTROLDETAILS_BOOLEAN = uintptr

type PMIXERCONTROLDETAILS_BOOLEAN = TPMIXERCONTROLDETAILS_BOOLEAN

type TLPMIXERCONTROLDETAILS_BOOLEAN = uintptr

type LPMIXERCONTROLDETAILS_BOOLEAN = TLPMIXERCONTROLDETAILS_BOOLEAN

type TMIXERCONTROLDETAILS_SIGNED = struct {
	FlValue TLONG
}

type MIXERCONTROLDETAILS_SIGNED = TMIXERCONTROLDETAILS_SIGNED

type TtMIXERCONTROLDETAILS_SIGNED = TMIXERCONTROLDETAILS_SIGNED

type tMIXERCONTROLDETAILS_SIGNED = TtMIXERCONTROLDETAILS_SIGNED

type TPMIXERCONTROLDETAILS_SIGNED = uintptr

type PMIXERCONTROLDETAILS_SIGNED = TPMIXERCONTROLDETAILS_SIGNED

type TLPMIXERCONTROLDETAILS_SIGNED = uintptr

type LPMIXERCONTROLDETAILS_SIGNED = TLPMIXERCONTROLDETAILS_SIGNED

type TMIXERCONTROLDETAILS_UNSIGNED = struct {
	FdwValue TDWORD
}

type MIXERCONTROLDETAILS_UNSIGNED = TMIXERCONTROLDETAILS_UNSIGNED

type TtMIXERCONTROLDETAILS_UNSIGNED = TMIXERCONTROLDETAILS_UNSIGNED

type tMIXERCONTROLDETAILS_UNSIGNED = TtMIXERCONTROLDETAILS_UNSIGNED

type TPMIXERCONTROLDETAILS_UNSIGNED = uintptr

type PMIXERCONTROLDETAILS_UNSIGNED = TPMIXERCONTROLDETAILS_UNSIGNED

type TLPMIXERCONTROLDETAILS_UNSIGNED = uintptr

type LPMIXERCONTROLDETAILS_UNSIGNED = TLPMIXERCONTROLDETAILS_UNSIGNED

type TLPTIMECALLBACK = uintptr

type LPTIMECALLBACK = TLPTIMECALLBACK

type TTIMECAPS = struct {
	FwPeriodMin TUINT
	FwPeriodMax TUINT
}

type TIMECAPS = TTIMECAPS

type Ttimecaps_tag = TTIMECAPS

type timecaps_tag = Ttimecaps_tag

type TPTIMECAPS = uintptr

type PTIMECAPS = TPTIMECAPS

type TNPTIMECAPS = uintptr

type NPTIMECAPS = TNPTIMECAPS

type TLPTIMECAPS = uintptr

type LPTIMECAPS = TLPTIMECAPS

type TJOYCAPSA = struct {
	FwMid        TWORD
	FwPid        TWORD
	FszPname     [32]TCHAR
	FwXmin       TUINT
	FwXmax       TUINT
	FwYmin       TUINT
	FwYmax       TUINT
	FwZmin       TUINT
	FwZmax       TUINT
	FwNumButtons TUINT
	FwPeriodMin  TUINT
	FwPeriodMax  TUINT
	FwRmin       TUINT
	FwRmax       TUINT
	FwUmin       TUINT
	FwUmax       TUINT
	FwVmin       TUINT
	FwVmax       TUINT
	FwCaps       TUINT
	FwMaxAxes    TUINT
	FwNumAxes    TUINT
	FwMaxButtons TUINT
	FszRegKey    [32]TCHAR
	FszOEMVxD    [260]TCHAR
}

type JOYCAPSA = TJOYCAPSA

type TtagJOYCAPSA = TJOYCAPSA

type tagJOYCAPSA = TtagJOYCAPSA

type TPJOYCAPSA = uintptr

type PJOYCAPSA = TPJOYCAPSA

type TNPJOYCAPSA = uintptr

type NPJOYCAPSA = TNPJOYCAPSA

type TLPJOYCAPSA = uintptr

type LPJOYCAPSA = TLPJOYCAPSA

type TJOYCAPSW = struct {
	FwMid        TWORD
	FwPid        TWORD
	FszPname     [32]TWCHAR
	FwXmin       TUINT
	FwXmax       TUINT
	FwYmin       TUINT
	FwYmax       TUINT
	FwZmin       TUINT
	FwZmax       TUINT
	FwNumButtons TUINT
	FwPeriodMin  TUINT
	FwPeriodMax  TUINT
	FwRmin       TUINT
	FwRmax       TUINT
	FwUmin       TUINT
	FwUmax       TUINT
	FwVmin       TUINT
	FwVmax       TUINT
	FwCaps       TUINT
	FwMaxAxes    TUINT
	FwNumAxes    TUINT
	FwMaxButtons TUINT
	FszRegKey    [32]TWCHAR
	FszOEMVxD    [260]TWCHAR
}

type JOYCAPSW = TJOYCAPSW

type TtagJOYCAPSW = TJOYCAPSW

type tagJOYCAPSW = TtagJOYCAPSW

type TPJOYCAPSW = uintptr

type PJOYCAPSW = TPJOYCAPSW

type TNPJOYCAPSW = uintptr

type NPJOYCAPSW = TNPJOYCAPSW

type TLPJOYCAPSW = uintptr

type LPJOYCAPSW = TLPJOYCAPSW

type TJOYCAPS = struct {
	FwMid        TWORD
	FwPid        TWORD
	FszPname     [32]TCHAR
	FwXmin       TUINT
	FwXmax       TUINT
	FwYmin       TUINT
	FwYmax       TUINT
	FwZmin       TUINT
	FwZmax       TUINT
	FwNumButtons TUINT
	FwPeriodMin  TUINT
	FwPeriodMax  TUINT
	FwRmin       TUINT
	FwRmax       TUINT
	FwUmin       TUINT
	FwUmax       TUINT
	FwVmin       TUINT
	FwVmax       TUINT
	FwCaps       TUINT
	FwMaxAxes    TUINT
	FwNumAxes    TUINT
	FwMaxButtons TUINT
	FszRegKey    [32]TCHAR
	FszOEMVxD    [260]TCHAR
}

type JOYCAPS = TJOYCAPS

type TPJOYCAPS = uintptr

type PJOYCAPS = TPJOYCAPS

type TNPJOYCAPS = uintptr

type NPJOYCAPS = TNPJOYCAPS

type TLPJOYCAPS = uintptr

type LPJOYCAPS = TLPJOYCAPS

type TJOYCAPS2A = struct {
	FwMid             TWORD
	FwPid             TWORD
	FszPname          [32]TCHAR
	FwXmin            TUINT
	FwXmax            TUINT
	FwYmin            TUINT
	FwYmax            TUINT
	FwZmin            TUINT
	FwZmax            TUINT
	FwNumButtons      TUINT
	FwPeriodMin       TUINT
	FwPeriodMax       TUINT
	FwRmin            TUINT
	FwRmax            TUINT
	FwUmin            TUINT
	FwUmax            TUINT
	FwVmin            TUINT
	FwVmax            TUINT
	FwCaps            TUINT
	FwMaxAxes         TUINT
	FwNumAxes         TUINT
	FwMaxButtons      TUINT
	FszRegKey         [32]TCHAR
	FszOEMVxD         [260]TCHAR
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type JOYCAPS2A = TJOYCAPS2A

type TtagJOYCAPS2A = TJOYCAPS2A

type tagJOYCAPS2A = TtagJOYCAPS2A

type TPJOYCAPS2A = uintptr

type PJOYCAPS2A = TPJOYCAPS2A

type TNPJOYCAPS2A = uintptr

type NPJOYCAPS2A = TNPJOYCAPS2A

type TLPJOYCAPS2A = uintptr

type LPJOYCAPS2A = TLPJOYCAPS2A

type TJOYCAPS2W = struct {
	FwMid             TWORD
	FwPid             TWORD
	FszPname          [32]TWCHAR
	FwXmin            TUINT
	FwXmax            TUINT
	FwYmin            TUINT
	FwYmax            TUINT
	FwZmin            TUINT
	FwZmax            TUINT
	FwNumButtons      TUINT
	FwPeriodMin       TUINT
	FwPeriodMax       TUINT
	FwRmin            TUINT
	FwRmax            TUINT
	FwUmin            TUINT
	FwUmax            TUINT
	FwVmin            TUINT
	FwVmax            TUINT
	FwCaps            TUINT
	FwMaxAxes         TUINT
	FwNumAxes         TUINT
	FwMaxButtons      TUINT
	FszRegKey         [32]TWCHAR
	FszOEMVxD         [260]TWCHAR
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type JOYCAPS2W = TJOYCAPS2W

type TtagJOYCAPS2W = TJOYCAPS2W

type tagJOYCAPS2W = TtagJOYCAPS2W

type TPJOYCAPS2W = uintptr

type PJOYCAPS2W = TPJOYCAPS2W

type TNPJOYCAPS2W = uintptr

type NPJOYCAPS2W = TNPJOYCAPS2W

type TLPJOYCAPS2W = uintptr

type LPJOYCAPS2W = TLPJOYCAPS2W

type TJOYCAPS2 = struct {
	FwMid             TWORD
	FwPid             TWORD
	FszPname          [32]TCHAR
	FwXmin            TUINT
	FwXmax            TUINT
	FwYmin            TUINT
	FwYmax            TUINT
	FwZmin            TUINT
	FwZmax            TUINT
	FwNumButtons      TUINT
	FwPeriodMin       TUINT
	FwPeriodMax       TUINT
	FwRmin            TUINT
	FwRmax            TUINT
	FwUmin            TUINT
	FwUmax            TUINT
	FwVmin            TUINT
	FwVmax            TUINT
	FwCaps            TUINT
	FwMaxAxes         TUINT
	FwNumAxes         TUINT
	FwMaxButtons      TUINT
	FszRegKey         [32]TCHAR
	FszOEMVxD         [260]TCHAR
	FManufacturerGuid TGUID
	FProductGuid      TGUID
	FNameGuid         TGUID
}

type JOYCAPS2 = TJOYCAPS2

type TPJOYCAPS2 = uintptr

type PJOYCAPS2 = TPJOYCAPS2

type TNPJOYCAPS2 = uintptr

type NPJOYCAPS2 = TNPJOYCAPS2

type TLPJOYCAPS2 = uintptr

type LPJOYCAPS2 = TLPJOYCAPS2

type TJOYINFO = struct {
	FwXpos    TUINT
	FwYpos    TUINT
	FwZpos    TUINT
	FwButtons TUINT
}

type JOYINFO = TJOYINFO

type Tjoyinfo_tag = TJOYINFO

type joyinfo_tag = Tjoyinfo_tag

type TPJOYINFO = uintptr

type PJOYINFO = TPJOYINFO

type TNPJOYINFO = uintptr

type NPJOYINFO = TNPJOYINFO

type TLPJOYINFO = uintptr

type LPJOYINFO = TLPJOYINFO

type TJOYINFOEX = struct {
	FdwSize         TDWORD
	FdwFlags        TDWORD
	FdwXpos         TDWORD
	FdwYpos         TDWORD
	FdwZpos         TDWORD
	FdwRpos         TDWORD
	FdwUpos         TDWORD
	FdwVpos         TDWORD
	FdwButtons      TDWORD
	FdwButtonNumber TDWORD
	FdwPOV          TDWORD
	FdwReserved1    TDWORD
	FdwReserved2    TDWORD
}

type JOYINFOEX = TJOYINFOEX

type Tjoyinfoex_tag = TJOYINFOEX

type joyinfoex_tag = Tjoyinfoex_tag

type TPJOYINFOEX = uintptr

type PJOYINFOEX = TPJOYINFOEX

type TNPJOYINFOEX = uintptr

type NPJOYINFOEX = TNPJOYINFOEX

type TLPJOYINFOEX = uintptr

type LPJOYINFOEX = TLPJOYINFOEX

type TFOURCC = uint32

type FOURCC = TFOURCC

type THPSTR = uintptr

type HPSTR = THPSTR

type THMMIO__ = struct {
	Funused int32
}

type HMMIO__ = THMMIO__

type THMMIO = uintptr

type HMMIO = THMMIO

type TLPMMIOPROC = uintptr

type LPMMIOPROC = TLPMMIOPROC

type TMMIOINFO = struct {
	FdwFlags     TDWORD
	FfccIOProc   TFOURCC
	FpIOProc     TLPMMIOPROC
	FwErrorRet   TUINT
	Fhtask       THTASK
	FcchBuffer   TLONG
	FpchBuffer   THPSTR
	FpchNext     THPSTR
	FpchEndRead  THPSTR
	FpchEndWrite THPSTR
	FlBufOffset  TLONG
	FlDiskOffset TLONG
	FadwInfo     [3]TDWORD
	FdwReserved1 TDWORD
	FdwReserved2 TDWORD
	Fhmmio       THMMIO
}

type MMIOINFO = TMMIOINFO

type T_MMIOINFO = TMMIOINFO

type _MMIOINFO = T_MMIOINFO

type TPMMIOINFO = uintptr

type PMMIOINFO = TPMMIOINFO

type TNPMMIOINFO = uintptr

type NPMMIOINFO = TNPMMIOINFO

type TLPMMIOINFO = uintptr

type LPMMIOINFO = TLPMMIOINFO

type TLPCMMIOINFO = uintptr

type LPCMMIOINFO = TLPCMMIOINFO

type TMMCKINFO = struct {
	Fckid         TFOURCC
	Fcksize       TDWORD
	FfccType      TFOURCC
	FdwDataOffset TDWORD
	FdwFlags      TDWORD
}

type MMCKINFO = TMMCKINFO

type T_MMCKINFO = TMMCKINFO

type _MMCKINFO = T_MMCKINFO

type TPMMCKINFO = uintptr

type PMMCKINFO = TPMMCKINFO

type TNPMMCKINFO = uintptr

type NPMMCKINFO = TNPMMCKINFO

type TLPMMCKINFO = uintptr

type LPMMCKINFO = TLPMMCKINFO

type TLPCMMCKINFO = uintptr

type LPCMMCKINFO = TLPCMMCKINFO

type TMCIERROR = uint32

type MCIERROR = TMCIERROR

type TMCIDEVICEID = uint32

type MCIDEVICEID = TMCIDEVICEID

type TYIELDPROC = uintptr

type YIELDPROC = TYIELDPROC

type TMCI_GENERIC_PARMS = struct {
	FdwCallback TDWORD_PTR
}

type MCI_GENERIC_PARMS = TMCI_GENERIC_PARMS

type TtagMCI_GENERIC_PARMS = TMCI_GENERIC_PARMS

type tagMCI_GENERIC_PARMS = TtagMCI_GENERIC_PARMS

type TPMCI_GENERIC_PARMS = uintptr

type PMCI_GENERIC_PARMS = TPMCI_GENERIC_PARMS

type TLPMCI_GENERIC_PARMS = uintptr

type LPMCI_GENERIC_PARMS = TLPMCI_GENERIC_PARMS

type TMCI_OPEN_PARMSA = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
}

type MCI_OPEN_PARMSA = TMCI_OPEN_PARMSA

type TtagMCI_OPEN_PARMSA = TMCI_OPEN_PARMSA

type tagMCI_OPEN_PARMSA = TtagMCI_OPEN_PARMSA

type TPMCI_OPEN_PARMSA = uintptr

type PMCI_OPEN_PARMSA = TPMCI_OPEN_PARMSA

type TLPMCI_OPEN_PARMSA = uintptr

type LPMCI_OPEN_PARMSA = TLPMCI_OPEN_PARMSA

type TMCI_OPEN_PARMSW = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCWSTR
	FlpstrElementName TLPCWSTR
	FlpstrAlias       TLPCWSTR
}

type MCI_OPEN_PARMSW = TMCI_OPEN_PARMSW

type TtagMCI_OPEN_PARMSW = TMCI_OPEN_PARMSW

type tagMCI_OPEN_PARMSW = TtagMCI_OPEN_PARMSW

type TPMCI_OPEN_PARMSW = uintptr

type PMCI_OPEN_PARMSW = TPMCI_OPEN_PARMSW

type TLPMCI_OPEN_PARMSW = uintptr

type LPMCI_OPEN_PARMSW = TLPMCI_OPEN_PARMSW

type TMCI_OPEN_PARMS = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
}

type MCI_OPEN_PARMS = TMCI_OPEN_PARMS

type TPMCI_OPEN_PARMS = uintptr

type PMCI_OPEN_PARMS = TPMCI_OPEN_PARMS

type TLPMCI_OPEN_PARMS = uintptr

type LPMCI_OPEN_PARMS = TLPMCI_OPEN_PARMS

type TMCI_PLAY_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwFrom     TDWORD
	FdwTo       TDWORD
}

type MCI_PLAY_PARMS = TMCI_PLAY_PARMS

type TtagMCI_PLAY_PARMS = TMCI_PLAY_PARMS

type tagMCI_PLAY_PARMS = TtagMCI_PLAY_PARMS

type TPMCI_PLAY_PARMS = uintptr

type PMCI_PLAY_PARMS = TPMCI_PLAY_PARMS

type TLPMCI_PLAY_PARMS = uintptr

type LPMCI_PLAY_PARMS = TLPMCI_PLAY_PARMS

type TMCI_SEEK_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwTo       TDWORD
}

type MCI_SEEK_PARMS = TMCI_SEEK_PARMS

type TtagMCI_SEEK_PARMS = TMCI_SEEK_PARMS

type tagMCI_SEEK_PARMS = TtagMCI_SEEK_PARMS

type TPMCI_SEEK_PARMS = uintptr

type PMCI_SEEK_PARMS = TPMCI_SEEK_PARMS

type TLPMCI_SEEK_PARMS = uintptr

type LPMCI_SEEK_PARMS = TLPMCI_SEEK_PARMS

type TMCI_STATUS_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwReturn   TDWORD_PTR
	FdwItem     TDWORD
	FdwTrack    TDWORD
}

type MCI_STATUS_PARMS = TMCI_STATUS_PARMS

type TtagMCI_STATUS_PARMS = TMCI_STATUS_PARMS

type tagMCI_STATUS_PARMS = TtagMCI_STATUS_PARMS

type TPMCI_STATUS_PARMS = uintptr

type PMCI_STATUS_PARMS = TPMCI_STATUS_PARMS

type TLPMCI_STATUS_PARMS = uintptr

type LPMCI_STATUS_PARMS = TLPMCI_STATUS_PARMS

type TMCI_INFO_PARMSA = struct {
	FdwCallback  TDWORD_PTR
	FlpstrReturn TLPSTR
	FdwRetSize   TDWORD
}

type MCI_INFO_PARMSA = TMCI_INFO_PARMSA

type TtagMCI_INFO_PARMSA = TMCI_INFO_PARMSA

type tagMCI_INFO_PARMSA = TtagMCI_INFO_PARMSA

type TLPMCI_INFO_PARMSA = uintptr

type LPMCI_INFO_PARMSA = TLPMCI_INFO_PARMSA

type TMCI_INFO_PARMSW = struct {
	FdwCallback  TDWORD_PTR
	FlpstrReturn TLPWSTR
	FdwRetSize   TDWORD
}

type MCI_INFO_PARMSW = TMCI_INFO_PARMSW

type TtagMCI_INFO_PARMSW = TMCI_INFO_PARMSW

type tagMCI_INFO_PARMSW = TtagMCI_INFO_PARMSW

type TLPMCI_INFO_PARMSW = uintptr

type LPMCI_INFO_PARMSW = TLPMCI_INFO_PARMSW

type TMCI_INFO_PARMS = struct {
	FdwCallback  TDWORD_PTR
	FlpstrReturn TLPSTR
	FdwRetSize   TDWORD
}

type MCI_INFO_PARMS = TMCI_INFO_PARMS

type TLPMCI_INFO_PARMS = uintptr

type LPMCI_INFO_PARMS = TLPMCI_INFO_PARMS

type TMCI_GETDEVCAPS_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwReturn   TDWORD
	FdwItem     TDWORD
}

type MCI_GETDEVCAPS_PARMS = TMCI_GETDEVCAPS_PARMS

type TtagMCI_GETDEVCAPS_PARMS = TMCI_GETDEVCAPS_PARMS

type tagMCI_GETDEVCAPS_PARMS = TtagMCI_GETDEVCAPS_PARMS

type TPMCI_GETDEVCAPS_PARMS = uintptr

type PMCI_GETDEVCAPS_PARMS = TPMCI_GETDEVCAPS_PARMS

type TLPMCI_GETDEVCAPS_PARMS = uintptr

type LPMCI_GETDEVCAPS_PARMS = TLPMCI_GETDEVCAPS_PARMS

type TMCI_SYSINFO_PARMSA = struct {
	FdwCallback  TDWORD_PTR
	FlpstrReturn TLPSTR
	FdwRetSize   TDWORD
	FdwNumber    TDWORD
	FwDeviceType TUINT
}

type MCI_SYSINFO_PARMSA = TMCI_SYSINFO_PARMSA

type TtagMCI_SYSINFO_PARMSA = TMCI_SYSINFO_PARMSA

type tagMCI_SYSINFO_PARMSA = TtagMCI_SYSINFO_PARMSA

type TPMCI_SYSINFO_PARMSA = uintptr

type PMCI_SYSINFO_PARMSA = TPMCI_SYSINFO_PARMSA

type TLPMCI_SYSINFO_PARMSA = uintptr

type LPMCI_SYSINFO_PARMSA = TLPMCI_SYSINFO_PARMSA

type TMCI_SYSINFO_PARMSW = struct {
	FdwCallback  TDWORD_PTR
	FlpstrReturn TLPWSTR
	FdwRetSize   TDWORD
	FdwNumber    TDWORD
	FwDeviceType TUINT
}

type MCI_SYSINFO_PARMSW = TMCI_SYSINFO_PARMSW

type TtagMCI_SYSINFO_PARMSW = TMCI_SYSINFO_PARMSW

type tagMCI_SYSINFO_PARMSW = TtagMCI_SYSINFO_PARMSW

type TPMCI_SYSINFO_PARMSW = uintptr

type PMCI_SYSINFO_PARMSW = TPMCI_SYSINFO_PARMSW

type TLPMCI_SYSINFO_PARMSW = uintptr

type LPMCI_SYSINFO_PARMSW = TLPMCI_SYSINFO_PARMSW

type TMCI_SYSINFO_PARMS = struct {
	FdwCallback  TDWORD_PTR
	FlpstrReturn TLPSTR
	FdwRetSize   TDWORD
	FdwNumber    TDWORD
	FwDeviceType TUINT
}

type MCI_SYSINFO_PARMS = TMCI_SYSINFO_PARMS

type TPMCI_SYSINFO_PARMS = uintptr

type PMCI_SYSINFO_PARMS = TPMCI_SYSINFO_PARMS

type TLPMCI_SYSINFO_PARMS = uintptr

type LPMCI_SYSINFO_PARMS = TLPMCI_SYSINFO_PARMS

type TMCI_SET_PARMS = struct {
	FdwCallback   TDWORD_PTR
	FdwTimeFormat TDWORD
	FdwAudio      TDWORD
}

type MCI_SET_PARMS = TMCI_SET_PARMS

type TtagMCI_SET_PARMS = TMCI_SET_PARMS

type tagMCI_SET_PARMS = TtagMCI_SET_PARMS

type TPMCI_SET_PARMS = uintptr

type PMCI_SET_PARMS = TPMCI_SET_PARMS

type TLPMCI_SET_PARMS = uintptr

type LPMCI_SET_PARMS = TLPMCI_SET_PARMS

type TMCI_BREAK_PARMS = struct {
	FdwCallback TDWORD_PTR
	FnVirtKey   int32
	FhwndBreak  THWND
}

type MCI_BREAK_PARMS = TMCI_BREAK_PARMS

type TtagMCI_BREAK_PARMS = TMCI_BREAK_PARMS

type tagMCI_BREAK_PARMS = TtagMCI_BREAK_PARMS

type TPMCI_BREAK_PARMS = uintptr

type PMCI_BREAK_PARMS = TPMCI_BREAK_PARMS

type TLPMCI_BREAK_PARMS = uintptr

type LPMCI_BREAK_PARMS = TLPMCI_BREAK_PARMS

type TMCI_SAVE_PARMSA = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
}

type MCI_SAVE_PARMSA = TMCI_SAVE_PARMSA

type TtagMCI_SAVE_PARMSA = TMCI_SAVE_PARMSA

type tagMCI_SAVE_PARMSA = TtagMCI_SAVE_PARMSA

type TPMCI_SAVE_PARMSA = uintptr

type PMCI_SAVE_PARMSA = TPMCI_SAVE_PARMSA

type TLPMCI_SAVE_PARMSA = uintptr

type LPMCI_SAVE_PARMSA = TLPMCI_SAVE_PARMSA

type TMCI_SAVE_PARMSW = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCWSTR
}

type MCI_SAVE_PARMSW = TMCI_SAVE_PARMSW

type TtagMCI_SAVE_PARMSW = TMCI_SAVE_PARMSW

type tagMCI_SAVE_PARMSW = TtagMCI_SAVE_PARMSW

type TPMCI_SAVE_PARMSW = uintptr

type PMCI_SAVE_PARMSW = TPMCI_SAVE_PARMSW

type TLPMCI_SAVE_PARMSW = uintptr

type LPMCI_SAVE_PARMSW = TLPMCI_SAVE_PARMSW

type TMCI_SAVE_PARMS = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
}

type MCI_SAVE_PARMS = TMCI_SAVE_PARMS

type TPMCI_SAVE_PARMS = uintptr

type PMCI_SAVE_PARMS = TPMCI_SAVE_PARMS

type TLPMCI_SAVE_PARMS = uintptr

type LPMCI_SAVE_PARMS = TLPMCI_SAVE_PARMS

type TMCI_LOAD_PARMSA = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
}

type MCI_LOAD_PARMSA = TMCI_LOAD_PARMSA

type TtagMCI_LOAD_PARMSA = TMCI_LOAD_PARMSA

type tagMCI_LOAD_PARMSA = TtagMCI_LOAD_PARMSA

type TPMCI_LOAD_PARMSA = uintptr

type PMCI_LOAD_PARMSA = TPMCI_LOAD_PARMSA

type TLPMCI_LOAD_PARMSA = uintptr

type LPMCI_LOAD_PARMSA = TLPMCI_LOAD_PARMSA

type TMCI_LOAD_PARMSW = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCWSTR
}

type MCI_LOAD_PARMSW = TMCI_LOAD_PARMSW

type TtagMCI_LOAD_PARMSW = TMCI_LOAD_PARMSW

type tagMCI_LOAD_PARMSW = TtagMCI_LOAD_PARMSW

type TPMCI_LOAD_PARMSW = uintptr

type PMCI_LOAD_PARMSW = TPMCI_LOAD_PARMSW

type TLPMCI_LOAD_PARMSW = uintptr

type LPMCI_LOAD_PARMSW = TLPMCI_LOAD_PARMSW

type TMCI_LOAD_PARMS = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
}

type MCI_LOAD_PARMS = TMCI_LOAD_PARMS

type TPMCI_LOAD_PARMS = uintptr

type PMCI_LOAD_PARMS = TPMCI_LOAD_PARMS

type TLPMCI_LOAD_PARMS = uintptr

type LPMCI_LOAD_PARMS = TLPMCI_LOAD_PARMS

type TMCI_RECORD_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwFrom     TDWORD
	FdwTo       TDWORD
}

type MCI_RECORD_PARMS = TMCI_RECORD_PARMS

type TtagMCI_RECORD_PARMS = TMCI_RECORD_PARMS

type tagMCI_RECORD_PARMS = TtagMCI_RECORD_PARMS

type TLPMCI_RECORD_PARMS = uintptr

type LPMCI_RECORD_PARMS = TLPMCI_RECORD_PARMS

type TMCI_VD_PLAY_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwFrom     TDWORD
	FdwTo       TDWORD
	FdwSpeed    TDWORD
}

type MCI_VD_PLAY_PARMS = TMCI_VD_PLAY_PARMS

type TtagMCI_VD_PLAY_PARMS = TMCI_VD_PLAY_PARMS

type tagMCI_VD_PLAY_PARMS = TtagMCI_VD_PLAY_PARMS

type TPMCI_VD_PLAY_PARMS = uintptr

type PMCI_VD_PLAY_PARMS = TPMCI_VD_PLAY_PARMS

type TLPMCI_VD_PLAY_PARMS = uintptr

type LPMCI_VD_PLAY_PARMS = TLPMCI_VD_PLAY_PARMS

type TMCI_VD_STEP_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwFrames   TDWORD
}

type MCI_VD_STEP_PARMS = TMCI_VD_STEP_PARMS

type TtagMCI_VD_STEP_PARMS = TMCI_VD_STEP_PARMS

type tagMCI_VD_STEP_PARMS = TtagMCI_VD_STEP_PARMS

type TPMCI_VD_STEP_PARMS = uintptr

type PMCI_VD_STEP_PARMS = TPMCI_VD_STEP_PARMS

type TLPMCI_VD_STEP_PARMS = uintptr

type LPMCI_VD_STEP_PARMS = TLPMCI_VD_STEP_PARMS

type TMCI_VD_ESCAPE_PARMSA = struct {
	FdwCallback   TDWORD_PTR
	FlpstrCommand TLPCSTR
}

type MCI_VD_ESCAPE_PARMSA = TMCI_VD_ESCAPE_PARMSA

type TtagMCI_VD_ESCAPE_PARMSA = TMCI_VD_ESCAPE_PARMSA

type tagMCI_VD_ESCAPE_PARMSA = TtagMCI_VD_ESCAPE_PARMSA

type TPMCI_VD_ESCAPE_PARMSA = uintptr

type PMCI_VD_ESCAPE_PARMSA = TPMCI_VD_ESCAPE_PARMSA

type TLPMCI_VD_ESCAPE_PARMSA = uintptr

type LPMCI_VD_ESCAPE_PARMSA = TLPMCI_VD_ESCAPE_PARMSA

type TMCI_VD_ESCAPE_PARMSW = struct {
	FdwCallback   TDWORD_PTR
	FlpstrCommand TLPCWSTR
}

type MCI_VD_ESCAPE_PARMSW = TMCI_VD_ESCAPE_PARMSW

type TtagMCI_VD_ESCAPE_PARMSW = TMCI_VD_ESCAPE_PARMSW

type tagMCI_VD_ESCAPE_PARMSW = TtagMCI_VD_ESCAPE_PARMSW

type TPMCI_VD_ESCAPE_PARMSW = uintptr

type PMCI_VD_ESCAPE_PARMSW = TPMCI_VD_ESCAPE_PARMSW

type TLPMCI_VD_ESCAPE_PARMSW = uintptr

type LPMCI_VD_ESCAPE_PARMSW = TLPMCI_VD_ESCAPE_PARMSW

type TMCI_VD_ESCAPE_PARMS = struct {
	FdwCallback   TDWORD_PTR
	FlpstrCommand TLPCSTR
}

type MCI_VD_ESCAPE_PARMS = TMCI_VD_ESCAPE_PARMS

type TPMCI_VD_ESCAPE_PARMS = uintptr

type PMCI_VD_ESCAPE_PARMS = TPMCI_VD_ESCAPE_PARMS

type TLPMCI_VD_ESCAPE_PARMS = uintptr

type LPMCI_VD_ESCAPE_PARMS = TLPMCI_VD_ESCAPE_PARMS

type TMCI_WAVE_OPEN_PARMSA = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
	FdwBufferSeconds  TDWORD
}

type MCI_WAVE_OPEN_PARMSA = TMCI_WAVE_OPEN_PARMSA

type TtagMCI_WAVE_OPEN_PARMSA = TMCI_WAVE_OPEN_PARMSA

type tagMCI_WAVE_OPEN_PARMSA = TtagMCI_WAVE_OPEN_PARMSA

type TPMCI_WAVE_OPEN_PARMSA = uintptr

type PMCI_WAVE_OPEN_PARMSA = TPMCI_WAVE_OPEN_PARMSA

type TLPMCI_WAVE_OPEN_PARMSA = uintptr

type LPMCI_WAVE_OPEN_PARMSA = TLPMCI_WAVE_OPEN_PARMSA

type TMCI_WAVE_OPEN_PARMSW = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCWSTR
	FlpstrElementName TLPCWSTR
	FlpstrAlias       TLPCWSTR
	FdwBufferSeconds  TDWORD
}

type MCI_WAVE_OPEN_PARMSW = TMCI_WAVE_OPEN_PARMSW

type TtagMCI_WAVE_OPEN_PARMSW = TMCI_WAVE_OPEN_PARMSW

type tagMCI_WAVE_OPEN_PARMSW = TtagMCI_WAVE_OPEN_PARMSW

type TPMCI_WAVE_OPEN_PARMSW = uintptr

type PMCI_WAVE_OPEN_PARMSW = TPMCI_WAVE_OPEN_PARMSW

type TLPMCI_WAVE_OPEN_PARMSW = uintptr

type LPMCI_WAVE_OPEN_PARMSW = TLPMCI_WAVE_OPEN_PARMSW

type TMCI_WAVE_OPEN_PARMS = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
	FdwBufferSeconds  TDWORD
}

type MCI_WAVE_OPEN_PARMS = TMCI_WAVE_OPEN_PARMS

type TPMCI_WAVE_OPEN_PARMS = uintptr

type PMCI_WAVE_OPEN_PARMS = TPMCI_WAVE_OPEN_PARMS

type TLPMCI_WAVE_OPEN_PARMS = uintptr

type LPMCI_WAVE_OPEN_PARMS = TLPMCI_WAVE_OPEN_PARMS

type TMCI_WAVE_DELETE_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwFrom     TDWORD
	FdwTo       TDWORD
}

type MCI_WAVE_DELETE_PARMS = TMCI_WAVE_DELETE_PARMS

type TtagMCI_WAVE_DELETE_PARMS = TMCI_WAVE_DELETE_PARMS

type tagMCI_WAVE_DELETE_PARMS = TtagMCI_WAVE_DELETE_PARMS

type TPMCI_WAVE_DELETE_PARMS = uintptr

type PMCI_WAVE_DELETE_PARMS = TPMCI_WAVE_DELETE_PARMS

type TLPMCI_WAVE_DELETE_PARMS = uintptr

type LPMCI_WAVE_DELETE_PARMS = TLPMCI_WAVE_DELETE_PARMS

type TMCI_WAVE_SET_PARMS = struct {
	FdwCallback      TDWORD_PTR
	FdwTimeFormat    TDWORD
	FdwAudio         TDWORD
	FwInput          TUINT
	FwOutput         TUINT
	FwFormatTag      TWORD
	FwReserved2      TWORD
	FnChannels       TWORD
	FwReserved3      TWORD
	FnSamplesPerSec  TDWORD
	FnAvgBytesPerSec TDWORD
	FnBlockAlign     TWORD
	FwReserved4      TWORD
	FwBitsPerSample  TWORD
	FwReserved5      TWORD
}

type MCI_WAVE_SET_PARMS = TMCI_WAVE_SET_PARMS

type TtagMCI_WAVE_SET_PARMS = TMCI_WAVE_SET_PARMS

type tagMCI_WAVE_SET_PARMS = TtagMCI_WAVE_SET_PARMS

type TPMCI_WAVE_SET_PARMS = uintptr

type PMCI_WAVE_SET_PARMS = TPMCI_WAVE_SET_PARMS

type TLPMCI_WAVE_SET_PARMS = uintptr

type LPMCI_WAVE_SET_PARMS = TLPMCI_WAVE_SET_PARMS

type TMCI_SEQ_SET_PARMS = struct {
	FdwCallback   TDWORD_PTR
	FdwTimeFormat TDWORD
	FdwAudio      TDWORD
	FdwTempo      TDWORD
	FdwPort       TDWORD
	FdwSlave      TDWORD
	FdwMaster     TDWORD
	FdwOffset     TDWORD
}

type MCI_SEQ_SET_PARMS = TMCI_SEQ_SET_PARMS

type TtagMCI_SEQ_SET_PARMS = TMCI_SEQ_SET_PARMS

type tagMCI_SEQ_SET_PARMS = TtagMCI_SEQ_SET_PARMS

type TPMCI_SEQ_SET_PARMS = uintptr

type PMCI_SEQ_SET_PARMS = TPMCI_SEQ_SET_PARMS

type TLPMCI_SEQ_SET_PARMS = uintptr

type LPMCI_SEQ_SET_PARMS = TLPMCI_SEQ_SET_PARMS

type TMCI_ANIM_OPEN_PARMSA = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
	FdwStyle          TDWORD
	FhWndParent       THWND
}

type MCI_ANIM_OPEN_PARMSA = TMCI_ANIM_OPEN_PARMSA

type TtagMCI_ANIM_OPEN_PARMSA = TMCI_ANIM_OPEN_PARMSA

type tagMCI_ANIM_OPEN_PARMSA = TtagMCI_ANIM_OPEN_PARMSA

type TPMCI_ANIM_OPEN_PARMSA = uintptr

type PMCI_ANIM_OPEN_PARMSA = TPMCI_ANIM_OPEN_PARMSA

type TLPMCI_ANIM_OPEN_PARMSA = uintptr

type LPMCI_ANIM_OPEN_PARMSA = TLPMCI_ANIM_OPEN_PARMSA

type TMCI_ANIM_OPEN_PARMSW = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCWSTR
	FlpstrElementName TLPCWSTR
	FlpstrAlias       TLPCWSTR
	FdwStyle          TDWORD
	FhWndParent       THWND
}

type MCI_ANIM_OPEN_PARMSW = TMCI_ANIM_OPEN_PARMSW

type TtagMCI_ANIM_OPEN_PARMSW = TMCI_ANIM_OPEN_PARMSW

type tagMCI_ANIM_OPEN_PARMSW = TtagMCI_ANIM_OPEN_PARMSW

type TPMCI_ANIM_OPEN_PARMSW = uintptr

type PMCI_ANIM_OPEN_PARMSW = TPMCI_ANIM_OPEN_PARMSW

type TLPMCI_ANIM_OPEN_PARMSW = uintptr

type LPMCI_ANIM_OPEN_PARMSW = TLPMCI_ANIM_OPEN_PARMSW

type TMCI_ANIM_OPEN_PARMS = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
	FdwStyle          TDWORD
	FhWndParent       THWND
}

type MCI_ANIM_OPEN_PARMS = TMCI_ANIM_OPEN_PARMS

type TPMCI_ANIM_OPEN_PARMS = uintptr

type PMCI_ANIM_OPEN_PARMS = TPMCI_ANIM_OPEN_PARMS

type TLPMCI_ANIM_OPEN_PARMS = uintptr

type LPMCI_ANIM_OPEN_PARMS = TLPMCI_ANIM_OPEN_PARMS

type TMCI_ANIM_PLAY_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwFrom     TDWORD
	FdwTo       TDWORD
	FdwSpeed    TDWORD
}

type MCI_ANIM_PLAY_PARMS = TMCI_ANIM_PLAY_PARMS

type TtagMCI_ANIM_PLAY_PARMS = TMCI_ANIM_PLAY_PARMS

type tagMCI_ANIM_PLAY_PARMS = TtagMCI_ANIM_PLAY_PARMS

type TPMCI_ANIM_PLAY_PARMS = uintptr

type PMCI_ANIM_PLAY_PARMS = TPMCI_ANIM_PLAY_PARMS

type TLPMCI_ANIM_PLAY_PARMS = uintptr

type LPMCI_ANIM_PLAY_PARMS = TLPMCI_ANIM_PLAY_PARMS

type TMCI_ANIM_STEP_PARMS = struct {
	FdwCallback TDWORD_PTR
	FdwFrames   TDWORD
}

type MCI_ANIM_STEP_PARMS = TMCI_ANIM_STEP_PARMS

type TtagMCI_ANIM_STEP_PARMS = TMCI_ANIM_STEP_PARMS

type tagMCI_ANIM_STEP_PARMS = TtagMCI_ANIM_STEP_PARMS

type TPMCI_ANIM_STEP_PARMS = uintptr

type PMCI_ANIM_STEP_PARMS = TPMCI_ANIM_STEP_PARMS

type TLPMCI_ANIM_STEP_PARMS = uintptr

type LPMCI_ANIM_STEP_PARMS = TLPMCI_ANIM_STEP_PARMS

type TMCI_ANIM_WINDOW_PARMSA = struct {
	FdwCallback TDWORD_PTR
	FhWnd       THWND
	FnCmdShow   TUINT
	FlpstrText  TLPCSTR
}

type MCI_ANIM_WINDOW_PARMSA = TMCI_ANIM_WINDOW_PARMSA

type TtagMCI_ANIM_WINDOW_PARMSA = TMCI_ANIM_WINDOW_PARMSA

type tagMCI_ANIM_WINDOW_PARMSA = TtagMCI_ANIM_WINDOW_PARMSA

type TPMCI_ANIM_WINDOW_PARMSA = uintptr

type PMCI_ANIM_WINDOW_PARMSA = TPMCI_ANIM_WINDOW_PARMSA

type TLPMCI_ANIM_WINDOW_PARMSA = uintptr

type LPMCI_ANIM_WINDOW_PARMSA = TLPMCI_ANIM_WINDOW_PARMSA

type TMCI_ANIM_WINDOW_PARMSW = struct {
	FdwCallback TDWORD_PTR
	FhWnd       THWND
	FnCmdShow   TUINT
	FlpstrText  TLPCWSTR
}

type MCI_ANIM_WINDOW_PARMSW = TMCI_ANIM_WINDOW_PARMSW

type TtagMCI_ANIM_WINDOW_PARMSW = TMCI_ANIM_WINDOW_PARMSW

type tagMCI_ANIM_WINDOW_PARMSW = TtagMCI_ANIM_WINDOW_PARMSW

type TPMCI_ANIM_WINDOW_PARMSW = uintptr

type PMCI_ANIM_WINDOW_PARMSW = TPMCI_ANIM_WINDOW_PARMSW

type TLPMCI_ANIM_WINDOW_PARMSW = uintptr

type LPMCI_ANIM_WINDOW_PARMSW = TLPMCI_ANIM_WINDOW_PARMSW

type TMCI_ANIM_WINDOW_PARMS = struct {
	FdwCallback TDWORD_PTR
	FhWnd       THWND
	FnCmdShow   TUINT
	FlpstrText  TLPCSTR
}

type MCI_ANIM_WINDOW_PARMS = TMCI_ANIM_WINDOW_PARMS

type TPMCI_ANIM_WINDOW_PARMS = uintptr

type PMCI_ANIM_WINDOW_PARMS = TPMCI_ANIM_WINDOW_PARMS

type TLPMCI_ANIM_WINDOW_PARMS = uintptr

type LPMCI_ANIM_WINDOW_PARMS = TLPMCI_ANIM_WINDOW_PARMS

type TMCI_ANIM_RECT_PARMS = struct {
	FdwCallback TDWORD_PTR
	Frc         TRECT
}

type MCI_ANIM_RECT_PARMS = TMCI_ANIM_RECT_PARMS

type TtagMCI_ANIM_RECT_PARMS = TMCI_ANIM_RECT_PARMS

type tagMCI_ANIM_RECT_PARMS = TtagMCI_ANIM_RECT_PARMS

type TPMCI_ANIM_RECT_PARMS = uintptr

type PMCI_ANIM_RECT_PARMS = TPMCI_ANIM_RECT_PARMS

type TLPMCI_ANIM_RECT_PARMS = uintptr

type LPMCI_ANIM_RECT_PARMS = TLPMCI_ANIM_RECT_PARMS

type TMCI_ANIM_UPDATE_PARMS = struct {
	FdwCallback TDWORD_PTR
	Frc         TRECT
	FhDC        THDC
}

type MCI_ANIM_UPDATE_PARMS = TMCI_ANIM_UPDATE_PARMS

type TtagMCI_ANIM_UPDATE_PARMS = TMCI_ANIM_UPDATE_PARMS

type tagMCI_ANIM_UPDATE_PARMS = TtagMCI_ANIM_UPDATE_PARMS

type TPMCI_ANIM_UPDATE_PARMS = uintptr

type PMCI_ANIM_UPDATE_PARMS = TPMCI_ANIM_UPDATE_PARMS

type TLPMCI_ANIM_UPDATE_PARMS = uintptr

type LPMCI_ANIM_UPDATE_PARMS = TLPMCI_ANIM_UPDATE_PARMS

type TMCI_OVLY_OPEN_PARMSA = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
	FdwStyle          TDWORD
	FhWndParent       THWND
}

type MCI_OVLY_OPEN_PARMSA = TMCI_OVLY_OPEN_PARMSA

type TtagMCI_OVLY_OPEN_PARMSA = TMCI_OVLY_OPEN_PARMSA

type tagMCI_OVLY_OPEN_PARMSA = TtagMCI_OVLY_OPEN_PARMSA

type TPMCI_OVLY_OPEN_PARMSA = uintptr

type PMCI_OVLY_OPEN_PARMSA = TPMCI_OVLY_OPEN_PARMSA

type TLPMCI_OVLY_OPEN_PARMSA = uintptr

type LPMCI_OVLY_OPEN_PARMSA = TLPMCI_OVLY_OPEN_PARMSA

type TMCI_OVLY_OPEN_PARMSW = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCWSTR
	FlpstrElementName TLPCWSTR
	FlpstrAlias       TLPCWSTR
	FdwStyle          TDWORD
	FhWndParent       THWND
}

type MCI_OVLY_OPEN_PARMSW = TMCI_OVLY_OPEN_PARMSW

type TtagMCI_OVLY_OPEN_PARMSW = TMCI_OVLY_OPEN_PARMSW

type tagMCI_OVLY_OPEN_PARMSW = TtagMCI_OVLY_OPEN_PARMSW

type TPMCI_OVLY_OPEN_PARMSW = uintptr

type PMCI_OVLY_OPEN_PARMSW = TPMCI_OVLY_OPEN_PARMSW

type TLPMCI_OVLY_OPEN_PARMSW = uintptr

type LPMCI_OVLY_OPEN_PARMSW = TLPMCI_OVLY_OPEN_PARMSW

type TMCI_OVLY_OPEN_PARMS = struct {
	FdwCallback       TDWORD_PTR
	FwDeviceID        TMCIDEVICEID
	FlpstrDeviceType  TLPCSTR
	FlpstrElementName TLPCSTR
	FlpstrAlias       TLPCSTR
	FdwStyle          TDWORD
	FhWndParent       THWND
}

type MCI_OVLY_OPEN_PARMS = TMCI_OVLY_OPEN_PARMS

type TPMCI_OVLY_OPEN_PARMS = uintptr

type PMCI_OVLY_OPEN_PARMS = TPMCI_OVLY_OPEN_PARMS

type TLPMCI_OVLY_OPEN_PARMS = uintptr

type LPMCI_OVLY_OPEN_PARMS = TLPMCI_OVLY_OPEN_PARMS

type TMCI_OVLY_WINDOW_PARMSA = struct {
	FdwCallback TDWORD_PTR
	FhWnd       THWND
	FnCmdShow   TUINT
	FlpstrText  TLPCSTR
}

type MCI_OVLY_WINDOW_PARMSA = TMCI_OVLY_WINDOW_PARMSA

type TtagMCI_OVLY_WINDOW_PARMSA = TMCI_OVLY_WINDOW_PARMSA

type tagMCI_OVLY_WINDOW_PARMSA = TtagMCI_OVLY_WINDOW_PARMSA

type TPMCI_OVLY_WINDOW_PARMSA = uintptr

type PMCI_OVLY_WINDOW_PARMSA = TPMCI_OVLY_WINDOW_PARMSA

type TLPMCI_OVLY_WINDOW_PARMSA = uintptr

type LPMCI_OVLY_WINDOW_PARMSA = TLPMCI_OVLY_WINDOW_PARMSA

type TMCI_OVLY_WINDOW_PARMSW = struct {
	FdwCallback TDWORD_PTR
	FhWnd       THWND
	FnCmdShow   TUINT
	FlpstrText  TLPCWSTR
}

type MCI_OVLY_WINDOW_PARMSW = TMCI_OVLY_WINDOW_PARMSW

type TtagMCI_OVLY_WINDOW_PARMSW = TMCI_OVLY_WINDOW_PARMSW

type tagMCI_OVLY_WINDOW_PARMSW = TtagMCI_OVLY_WINDOW_PARMSW

type TPMCI_OVLY_WINDOW_PARMSW = uintptr

type PMCI_OVLY_WINDOW_PARMSW = TPMCI_OVLY_WINDOW_PARMSW

type TLPMCI_OVLY_WINDOW_PARMSW = uintptr

type LPMCI_OVLY_WINDOW_PARMSW = TLPMCI_OVLY_WINDOW_PARMSW

type TMCI_OVLY_WINDOW_PARMS = struct {
	FdwCallback TDWORD_PTR
	FhWnd       THWND
	FnCmdShow   TUINT
	FlpstrText  TLPCSTR
}

type MCI_OVLY_WINDOW_PARMS = TMCI_OVLY_WINDOW_PARMS

type TPMCI_OVLY_WINDOW_PARMS = uintptr

type PMCI_OVLY_WINDOW_PARMS = TPMCI_OVLY_WINDOW_PARMS

type TLPMCI_OVLY_WINDOW_PARMS = uintptr

type LPMCI_OVLY_WINDOW_PARMS = TLPMCI_OVLY_WINDOW_PARMS

type TMCI_OVLY_RECT_PARMS = struct {
	FdwCallback TDWORD_PTR
	Frc         TRECT
}

type MCI_OVLY_RECT_PARMS = TMCI_OVLY_RECT_PARMS

type TtagMCI_OVLY_RECT_PARMS = TMCI_OVLY_RECT_PARMS

type tagMCI_OVLY_RECT_PARMS = TtagMCI_OVLY_RECT_PARMS

type TPMCI_OVLY_RECT_PARMS = uintptr

type PMCI_OVLY_RECT_PARMS = TPMCI_OVLY_RECT_PARMS

type TLPMCI_OVLY_RECT_PARMS = uintptr

type LPMCI_OVLY_RECT_PARMS = TLPMCI_OVLY_RECT_PARMS

type TMCI_OVLY_SAVE_PARMSA = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
	Frc         TRECT
}

type MCI_OVLY_SAVE_PARMSA = TMCI_OVLY_SAVE_PARMSA

type TtagMCI_OVLY_SAVE_PARMSA = TMCI_OVLY_SAVE_PARMSA

type tagMCI_OVLY_SAVE_PARMSA = TtagMCI_OVLY_SAVE_PARMSA

type TPMCI_OVLY_SAVE_PARMSA = uintptr

type PMCI_OVLY_SAVE_PARMSA = TPMCI_OVLY_SAVE_PARMSA

type TLPMCI_OVLY_SAVE_PARMSA = uintptr

type LPMCI_OVLY_SAVE_PARMSA = TLPMCI_OVLY_SAVE_PARMSA

type TMCI_OVLY_SAVE_PARMSW = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCWSTR
	Frc         TRECT
}

type MCI_OVLY_SAVE_PARMSW = TMCI_OVLY_SAVE_PARMSW

type TtagMCI_OVLY_SAVE_PARMSW = TMCI_OVLY_SAVE_PARMSW

type tagMCI_OVLY_SAVE_PARMSW = TtagMCI_OVLY_SAVE_PARMSW

type TPMCI_OVLY_SAVE_PARMSW = uintptr

type PMCI_OVLY_SAVE_PARMSW = TPMCI_OVLY_SAVE_PARMSW

type TLPMCI_OVLY_SAVE_PARMSW = uintptr

type LPMCI_OVLY_SAVE_PARMSW = TLPMCI_OVLY_SAVE_PARMSW

type TMCI_OVLY_SAVE_PARMS = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
	Frc         TRECT
}

type MCI_OVLY_SAVE_PARMS = TMCI_OVLY_SAVE_PARMS

type TPMCI_OVLY_SAVE_PARMS = uintptr

type PMCI_OVLY_SAVE_PARMS = TPMCI_OVLY_SAVE_PARMS

type TLPMCI_OVLY_SAVE_PARMS = uintptr

type LPMCI_OVLY_SAVE_PARMS = TLPMCI_OVLY_SAVE_PARMS

type TMCI_OVLY_LOAD_PARMSA = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
	Frc         TRECT
}

type MCI_OVLY_LOAD_PARMSA = TMCI_OVLY_LOAD_PARMSA

type TtagMCI_OVLY_LOAD_PARMSA = TMCI_OVLY_LOAD_PARMSA

type tagMCI_OVLY_LOAD_PARMSA = TtagMCI_OVLY_LOAD_PARMSA

type TPMCI_OVLY_LOAD_PARMSA = uintptr

type PMCI_OVLY_LOAD_PARMSA = TPMCI_OVLY_LOAD_PARMSA

type TLPMCI_OVLY_LOAD_PARMSA = uintptr

type LPMCI_OVLY_LOAD_PARMSA = TLPMCI_OVLY_LOAD_PARMSA

type TMCI_OVLY_LOAD_PARMSW = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCWSTR
	Frc         TRECT
}

type MCI_OVLY_LOAD_PARMSW = TMCI_OVLY_LOAD_PARMSW

type TtagMCI_OVLY_LOAD_PARMSW = TMCI_OVLY_LOAD_PARMSW

type tagMCI_OVLY_LOAD_PARMSW = TtagMCI_OVLY_LOAD_PARMSW

type TPMCI_OVLY_LOAD_PARMSW = uintptr

type PMCI_OVLY_LOAD_PARMSW = TPMCI_OVLY_LOAD_PARMSW

type TLPMCI_OVLY_LOAD_PARMSW = uintptr

type LPMCI_OVLY_LOAD_PARMSW = TLPMCI_OVLY_LOAD_PARMSW

type TMCI_OVLY_LOAD_PARMS = struct {
	FdwCallback TDWORD_PTR
	Flpfilename TLPCSTR
	Frc         TRECT
}

type MCI_OVLY_LOAD_PARMS = TMCI_OVLY_LOAD_PARMS

type TPMCI_OVLY_LOAD_PARMS = uintptr

type PMCI_OVLY_LOAD_PARMS = TPMCI_OVLY_LOAD_PARMS

type TLPMCI_OVLY_LOAD_PARMS = uintptr

type LPMCI_OVLY_LOAD_PARMS = TLPMCI_OVLY_LOAD_PARMS

type TNCB = struct {
	Fncb_command  TUCHAR
	Fncb_retcode  TUCHAR
	Fncb_lsn      TUCHAR
	Fncb_num      TUCHAR
	Fncb_buffer   TPUCHAR
	Fncb_length   TWORD
	Fncb_callname [16]TUCHAR
	Fncb_name     [16]TUCHAR
	Fncb_rto      TUCHAR
	Fncb_sto      TUCHAR
	Fncb_post     uintptr
	Fncb_lana_num TUCHAR
	Fncb_cmd_cplt TUCHAR
	Fncb_reserve  [10]TUCHAR
	Fncb_event    THANDLE
}

type NCB = TNCB

type T_NCB = TNCB

type _NCB = T_NCB

type TPNCB = uintptr

type PNCB = TPNCB

type TADAPTER_STATUS = struct {
	Fadapter_address   [6]TUCHAR
	Frev_major         TUCHAR
	Freserved0         TUCHAR
	Fadapter_type      TUCHAR
	Frev_minor         TUCHAR
	Fduration          TWORD
	Ffrmr_recv         TWORD
	Ffrmr_xmit         TWORD
	Fiframe_recv_err   TWORD
	Fxmit_aborts       TWORD
	Fxmit_success      TDWORD
	Frecv_success      TDWORD
	Fiframe_xmit_err   TWORD
	Frecv_buff_unavail TWORD
	Ft1_timeouts       TWORD
	Fti_timeouts       TWORD
	Freserved1         TDWORD
	Ffree_ncbs         TWORD
	Fmax_cfg_ncbs      TWORD
	Fmax_ncbs          TWORD
	Fxmit_buf_unavail  TWORD
	Fmax_dgram_size    TWORD
	Fpending_sess      TWORD
	Fmax_cfg_sess      TWORD
	Fmax_sess          TWORD
	Fmax_sess_pkt_size TWORD
	Fname_count        TWORD
}

type ADAPTER_STATUS = TADAPTER_STATUS

type T_ADAPTER_STATUS = TADAPTER_STATUS

type _ADAPTER_STATUS = T_ADAPTER_STATUS

type TPADAPTER_STATUS = uintptr

type PADAPTER_STATUS = TPADAPTER_STATUS

type TNAME_BUFFER = struct {
	Fname       [16]TUCHAR
	Fname_num   TUCHAR
	Fname_flags TUCHAR
}

type NAME_BUFFER = TNAME_BUFFER

type T_NAME_BUFFER = TNAME_BUFFER

type _NAME_BUFFER = T_NAME_BUFFER

type TPNAME_BUFFER = uintptr

type PNAME_BUFFER = TPNAME_BUFFER

type TSESSION_HEADER = struct {
	Fsess_name           TUCHAR
	Fnum_sess            TUCHAR
	Frcv_dg_outstanding  TUCHAR
	Frcv_any_outstanding TUCHAR
}

type SESSION_HEADER = TSESSION_HEADER

type T_SESSION_HEADER = TSESSION_HEADER

type _SESSION_HEADER = T_SESSION_HEADER

type TPSESSION_HEADER = uintptr

type PSESSION_HEADER = TPSESSION_HEADER

type TSESSION_BUFFER = struct {
	Flsn               TUCHAR
	Fstate             TUCHAR
	Flocal_name        [16]TUCHAR
	Fremote_name       [16]TUCHAR
	Frcvs_outstanding  TUCHAR
	Fsends_outstanding TUCHAR
}

type SESSION_BUFFER = TSESSION_BUFFER

type T_SESSION_BUFFER = TSESSION_BUFFER

type _SESSION_BUFFER = T_SESSION_BUFFER

type TPSESSION_BUFFER = uintptr

type PSESSION_BUFFER = TPSESSION_BUFFER

type TLANA_ENUM = struct {
	Flength TUCHAR
	Flana   [255]TUCHAR
}

type LANA_ENUM = TLANA_ENUM

type T_LANA_ENUM = TLANA_ENUM

type _LANA_ENUM = T_LANA_ENUM

type TPLANA_ENUM = uintptr

type PLANA_ENUM = TPLANA_ENUM

type TFIND_NAME_HEADER = struct {
	Fnode_count   TWORD
	Freserved     TUCHAR
	Funique_group TUCHAR
}

type FIND_NAME_HEADER = TFIND_NAME_HEADER

type T_FIND_NAME_HEADER = TFIND_NAME_HEADER

type _FIND_NAME_HEADER = T_FIND_NAME_HEADER

type TPFIND_NAME_HEADER = uintptr

type PFIND_NAME_HEADER = TPFIND_NAME_HEADER

type TFIND_NAME_BUFFER = struct {
	Flength           TUCHAR
	Faccess_control   TUCHAR
	Fframe_control    TUCHAR
	Fdestination_addr [6]TUCHAR
	Fsource_addr      [6]TUCHAR
	Frouting_info     [18]TUCHAR
}

type FIND_NAME_BUFFER = TFIND_NAME_BUFFER

type T_FIND_NAME_BUFFER = TFIND_NAME_BUFFER

type _FIND_NAME_BUFFER = T_FIND_NAME_BUFFER

type TPFIND_NAME_BUFFER = uintptr

type PFIND_NAME_BUFFER = TPFIND_NAME_BUFFER

type TACTION_HEADER = struct {
	Ftransport_id TULONG
	Faction_code  TUSHORT
	Freserved     TUSHORT
}

type ACTION_HEADER = TACTION_HEADER

type T_ACTION_HEADER = TACTION_HEADER

type _ACTION_HEADER = T_ACTION_HEADER

type TPACTION_HEADER = uintptr

type PACTION_HEADER = TPACTION_HEADER

type TI_RPC_HANDLE = uintptr

type I_RPC_HANDLE = TI_RPC_HANDLE

type TRPC_STATUS = int32

type RPC_STATUS = TRPC_STATUS

type TRPC_CSTR = uintptr

type RPC_CSTR = TRPC_CSTR

type TRPC_WSTR = uintptr

type RPC_WSTR = TRPC_WSTR

type TRPC_BINDING_HANDLE = uintptr

type RPC_BINDING_HANDLE = TRPC_BINDING_HANDLE

type Thandle_t = uintptr

type handle_t = Thandle_t

type TUUID = struct {
	FData1 uint32
	FData2 uint16
	FData3 uint16
	FData4 [8]uint8
}

type UUID = TUUID

type TRPC_BINDING_VECTOR = struct {
	FCount    uint32
	FBindingH [1]TRPC_BINDING_HANDLE
}

type RPC_BINDING_VECTOR = TRPC_BINDING_VECTOR

type T_RPC_BINDING_VECTOR = TRPC_BINDING_VECTOR

type _RPC_BINDING_VECTOR = T_RPC_BINDING_VECTOR

type TUUID_VECTOR = struct {
	FCount uint32
	FUuid  [1]uintptr
}

type UUID_VECTOR = TUUID_VECTOR

type T_UUID_VECTOR = TUUID_VECTOR

type _UUID_VECTOR = T_UUID_VECTOR

type TRPC_IF_HANDLE = uintptr

type RPC_IF_HANDLE = TRPC_IF_HANDLE

type TRPC_IF_ID = struct {
	FUuid      TUUID
	FVersMajor uint16
	FVersMinor uint16
}

type RPC_IF_ID = TRPC_IF_ID

type T_RPC_IF_ID = TRPC_IF_ID

type _RPC_IF_ID = T_RPC_IF_ID

type TRPC_PROTSEQ_VECTORA = struct {
	FCount   uint32
	FProtseq [1]uintptr
}

type RPC_PROTSEQ_VECTORA = TRPC_PROTSEQ_VECTORA

type T_RPC_PROTSEQ_VECTORA = TRPC_PROTSEQ_VECTORA

type _RPC_PROTSEQ_VECTORA = T_RPC_PROTSEQ_VECTORA

type TRPC_PROTSEQ_VECTORW = struct {
	FCount   uint32
	FProtseq [1]uintptr
}

type RPC_PROTSEQ_VECTORW = TRPC_PROTSEQ_VECTORW

type T_RPC_PROTSEQ_VECTORW = TRPC_PROTSEQ_VECTORW

type _RPC_PROTSEQ_VECTORW = T_RPC_PROTSEQ_VECTORW

type TRPC_POLICY = struct {
	FLength        uint32
	FEndpointFlags uint32
	FNICFlags      uint32
}

type RPC_POLICY = TRPC_POLICY

type T_RPC_POLICY = TRPC_POLICY

type _RPC_POLICY = T_RPC_POLICY

type TPRPC_POLICY = uintptr

type PRPC_POLICY = TPRPC_POLICY

type TRPC_STATS_VECTOR = struct {
	FCount uint32
	FStats [1]uint32
}

type RPC_STATS_VECTOR = TRPC_STATS_VECTOR

type TRPC_IF_ID_VECTOR = struct {
	FCount uint32
	FIfId  [1]uintptr
}

type RPC_IF_ID_VECTOR = TRPC_IF_ID_VECTOR

type TRPC_AUTH_IDENTITY_HANDLE = uintptr

type RPC_AUTH_IDENTITY_HANDLE = TRPC_AUTH_IDENTITY_HANDLE

type TRPC_AUTHZ_HANDLE = uintptr

type RPC_AUTHZ_HANDLE = TRPC_AUTHZ_HANDLE

type TRPC_SECURITY_QOS = struct {
	FVersion           uint32
	FCapabilities      uint32
	FIdentityTracking  uint32
	FImpersonationType uint32
}

type RPC_SECURITY_QOS = TRPC_SECURITY_QOS

type T_RPC_SECURITY_QOS = TRPC_SECURITY_QOS

type _RPC_SECURITY_QOS = T_RPC_SECURITY_QOS

type TPRPC_SECURITY_QOS = uintptr

type PRPC_SECURITY_QOS = TPRPC_SECURITY_QOS

type TSEC_WINNT_AUTH_IDENTITY_W = struct {
	FUser           uintptr
	FUserLength     uint32
	FDomain         uintptr
	FDomainLength   uint32
	FPassword       uintptr
	FPasswordLength uint32
	FFlags          uint32
}

type SEC_WINNT_AUTH_IDENTITY_W = TSEC_WINNT_AUTH_IDENTITY_W

type T_SEC_WINNT_AUTH_IDENTITY_W = TSEC_WINNT_AUTH_IDENTITY_W

type _SEC_WINNT_AUTH_IDENTITY_W = T_SEC_WINNT_AUTH_IDENTITY_W

type TPSEC_WINNT_AUTH_IDENTITY_W = uintptr

type PSEC_WINNT_AUTH_IDENTITY_W = TPSEC_WINNT_AUTH_IDENTITY_W

type TSEC_WINNT_AUTH_IDENTITY_A = struct {
	FUser           uintptr
	FUserLength     uint32
	FDomain         uintptr
	FDomainLength   uint32
	FPassword       uintptr
	FPasswordLength uint32
	FFlags          uint32
}

type SEC_WINNT_AUTH_IDENTITY_A = TSEC_WINNT_AUTH_IDENTITY_A

type T_SEC_WINNT_AUTH_IDENTITY_A = TSEC_WINNT_AUTH_IDENTITY_A

type _SEC_WINNT_AUTH_IDENTITY_A = T_SEC_WINNT_AUTH_IDENTITY_A

type TPSEC_WINNT_AUTH_IDENTITY_A = uintptr

type PSEC_WINNT_AUTH_IDENTITY_A = TPSEC_WINNT_AUTH_IDENTITY_A

type TRPC_HTTP_TRANSPORT_CREDENTIALS_W = struct {
	FTransportCredentials     uintptr
	FFlags                    uint32
	FAuthenticationTarget     uint32
	FNumberOfAuthnSchemes     uint32
	FAuthnSchemes             uintptr
	FServerCertificateSubject uintptr
}

type RPC_HTTP_TRANSPORT_CREDENTIALS_W = TRPC_HTTP_TRANSPORT_CREDENTIALS_W

type T_RPC_HTTP_TRANSPORT_CREDENTIALS_W = TRPC_HTTP_TRANSPORT_CREDENTIALS_W

type _RPC_HTTP_TRANSPORT_CREDENTIALS_W = T_RPC_HTTP_TRANSPORT_CREDENTIALS_W

type TPRPC_HTTP_TRANSPORT_CREDENTIALS_W = uintptr

type PRPC_HTTP_TRANSPORT_CREDENTIALS_W = TPRPC_HTTP_TRANSPORT_CREDENTIALS_W

type TRPC_HTTP_TRANSPORT_CREDENTIALS_A = struct {
	FTransportCredentials     uintptr
	FFlags                    uint32
	FAuthenticationTarget     uint32
	FNumberOfAuthnSchemes     uint32
	FAuthnSchemes             uintptr
	FServerCertificateSubject uintptr
}

type RPC_HTTP_TRANSPORT_CREDENTIALS_A = TRPC_HTTP_TRANSPORT_CREDENTIALS_A

type T_RPC_HTTP_TRANSPORT_CREDENTIALS_A = TRPC_HTTP_TRANSPORT_CREDENTIALS_A

type _RPC_HTTP_TRANSPORT_CREDENTIALS_A = T_RPC_HTTP_TRANSPORT_CREDENTIALS_A

type TPRPC_HTTP_TRANSPORT_CREDENTIALS_A = uintptr

type PRPC_HTTP_TRANSPORT_CREDENTIALS_A = TPRPC_HTTP_TRANSPORT_CREDENTIALS_A

type TRPC_SECURITY_QOS_V2_W = struct {
	FVersion                    uint32
	FCapabilities               uint32
	FIdentityTracking           uint32
	FImpersonationType          uint32
	FAdditionalSecurityInfoType uint32
	Fu                          struct {
		FHttpCredentials uintptr
	}
}

type RPC_SECURITY_QOS_V2_W = TRPC_SECURITY_QOS_V2_W

type T_RPC_SECURITY_QOS_V2_W = TRPC_SECURITY_QOS_V2_W

type _RPC_SECURITY_QOS_V2_W = T_RPC_SECURITY_QOS_V2_W

type TPRPC_SECURITY_QOS_V2_W = uintptr

type PRPC_SECURITY_QOS_V2_W = TPRPC_SECURITY_QOS_V2_W

type TRPC_SECURITY_QOS_V2_A = struct {
	FVersion                    uint32
	FCapabilities               uint32
	FIdentityTracking           uint32
	FImpersonationType          uint32
	FAdditionalSecurityInfoType uint32
	Fu                          struct {
		FHttpCredentials uintptr
	}
}

type RPC_SECURITY_QOS_V2_A = TRPC_SECURITY_QOS_V2_A

type T_RPC_SECURITY_QOS_V2_A = TRPC_SECURITY_QOS_V2_A

type _RPC_SECURITY_QOS_V2_A = T_RPC_SECURITY_QOS_V2_A

type TPRPC_SECURITY_QOS_V2_A = uintptr

type PRPC_SECURITY_QOS_V2_A = TPRPC_SECURITY_QOS_V2_A

type TRPC_SECURITY_QOS_V3_W = struct {
	FVersion                    uint32
	FCapabilities               uint32
	FIdentityTracking           uint32
	FImpersonationType          uint32
	FAdditionalSecurityInfoType uint32
	Fu                          struct {
		FHttpCredentials uintptr
	}
	FSid uintptr
}

type RPC_SECURITY_QOS_V3_W = TRPC_SECURITY_QOS_V3_W

type T_RPC_SECURITY_QOS_V3_W = TRPC_SECURITY_QOS_V3_W

type _RPC_SECURITY_QOS_V3_W = T_RPC_SECURITY_QOS_V3_W

type TPRPC_SECURITY_QOS_V3_W = uintptr

type PRPC_SECURITY_QOS_V3_W = TPRPC_SECURITY_QOS_V3_W

type TRPC_SECURITY_QOS_V3_A = struct {
	FVersion                    uint32
	FCapabilities               uint32
	FIdentityTracking           uint32
	FImpersonationType          uint32
	FAdditionalSecurityInfoType uint32
	Fu                          struct {
		FHttpCredentials uintptr
	}
	FSid uintptr
}

type RPC_SECURITY_QOS_V3_A = TRPC_SECURITY_QOS_V3_A

type T_RPC_SECURITY_QOS_V3_A = TRPC_SECURITY_QOS_V3_A

type _RPC_SECURITY_QOS_V3_A = T_RPC_SECURITY_QOS_V3_A

type TPRPC_SECURITY_QOS_V3_A = uintptr

type PRPC_SECURITY_QOS_V3_A = TPRPC_SECURITY_QOS_V3_A

type TRPC_HTTP_REDIRECTOR_STAGE = int32

type RPC_HTTP_REDIRECTOR_STAGE = TRPC_HTTP_REDIRECTOR_STAGE

type __RPC_HTTP_REDIRECTOR_STAGE = int32

const _RPCHTTP_RS_REDIRECT = 1
const _RPCHTTP_RS_ACCESS_1 = 2
const _RPCHTTP_RS_SESSION = 3
const _RPCHTTP_RS_ACCESS_2 = 4
const _RPCHTTP_RS_INTERFACE = 5

type TRPC_NEW_HTTP_PROXY_CHANNEL = uintptr

type RPC_NEW_HTTP_PROXY_CHANNEL = TRPC_NEW_HTTP_PROXY_CHANNEL

type TRPC_HTTP_PROXY_FREE_STRING = uintptr

type RPC_HTTP_PROXY_FREE_STRING = TRPC_HTTP_PROXY_FREE_STRING

type TRPC_AUTH_KEY_RETRIEVAL_FN = uintptr

type RPC_AUTH_KEY_RETRIEVAL_FN = TRPC_AUTH_KEY_RETRIEVAL_FN

type TRPC_CLIENT_INFORMATION1 = struct {
	FUserName     uintptr
	FComputerName uintptr
	FPrivilege    uint16
	FAuthFlags    uint32
}

type RPC_CLIENT_INFORMATION1 = TRPC_CLIENT_INFORMATION1

type TPRPC_CLIENT_INFORMATION1 = uintptr

type PRPC_CLIENT_INFORMATION1 = TPRPC_CLIENT_INFORMATION1

type TRPC_EP_INQ_HANDLE = uintptr

type RPC_EP_INQ_HANDLE = TRPC_EP_INQ_HANDLE

type TRPC_MGMT_AUTHORIZATION_FN = uintptr

type RPC_MGMT_AUTHORIZATION_FN = TRPC_MGMT_AUTHORIZATION_FN

type TRPC_BINDING_HANDLE_OPTIONS_V1 = struct {
	FVersion     uint32
	FFlags       uint32
	FComTimeout  uint32
	FCallTimeout uint32
}

type RPC_BINDING_HANDLE_OPTIONS_V1 = TRPC_BINDING_HANDLE_OPTIONS_V1

type T_RPC_BINDING_HANDLE_OPTIONS_V1 = TRPC_BINDING_HANDLE_OPTIONS_V1

type _RPC_BINDING_HANDLE_OPTIONS_V1 = T_RPC_BINDING_HANDLE_OPTIONS_V1

type TRPC_BINDING_HANDLE_OPTIONS = struct {
	FVersion     uint32
	FFlags       uint32
	FComTimeout  uint32
	FCallTimeout uint32
}

type RPC_BINDING_HANDLE_OPTIONS = TRPC_BINDING_HANDLE_OPTIONS

type TRPC_BINDING_HANDLE_SECURITY_V1 = struct {
	FVersion         uint32
	FServerPrincName uintptr
	FAuthnLevel      uint32
	FAuthnSvc        uint32
	FAuthIdentity    uintptr
	FSecurityQos     uintptr
}

type RPC_BINDING_HANDLE_SECURITY_V1 = TRPC_BINDING_HANDLE_SECURITY_V1

type TRPC_BINDING_HANDLE_SECURITY = struct {
	FVersion         uint32
	FServerPrincName uintptr
	FAuthnLevel      uint32
	FAuthnSvc        uint32
	FAuthIdentity    uintptr
	FSecurityQos     uintptr
}

type RPC_BINDING_HANDLE_SECURITY = TRPC_BINDING_HANDLE_SECURITY

type TRPC_BINDING_HANDLE_TEMPLATE_V1 = struct {
	FVersion          uint32
	FFlags            uint32
	FProtocolSequence uint32
	FNetworkAddress   uintptr
	FStringEndpoint   uintptr
	Fu1               struct {
		FReserved uintptr
	}
	FObjectUuid TUUID
}

type RPC_BINDING_HANDLE_TEMPLATE_V1 = TRPC_BINDING_HANDLE_TEMPLATE_V1

type T_RPC_BINDING_HANDLE_TEMPLATE = TRPC_BINDING_HANDLE_TEMPLATE_V1

type _RPC_BINDING_HANDLE_TEMPLATE = T_RPC_BINDING_HANDLE_TEMPLATE

type TRPC_BINDING_HANDLE_TEMPLATE = struct {
	FVersion          uint32
	FFlags            uint32
	FProtocolSequence uint32
	FNetworkAddress   uintptr
	FStringEndpoint   uintptr
	Fu1               struct {
		FReserved uintptr
	}
	FObjectUuid TUUID
}

type RPC_BINDING_HANDLE_TEMPLATE = TRPC_BINDING_HANDLE_TEMPLATE

type TRPC_VERSION = struct {
	FMajorVersion uint16
	FMinorVersion uint16
}

type RPC_VERSION = TRPC_VERSION

type T_RPC_VERSION = TRPC_VERSION

type _RPC_VERSION = T_RPC_VERSION

type TRPC_SYNTAX_IDENTIFIER = struct {
	FSyntaxGUID    TGUID
	FSyntaxVersion TRPC_VERSION
}

type RPC_SYNTAX_IDENTIFIER = TRPC_SYNTAX_IDENTIFIER

type T_RPC_SYNTAX_IDENTIFIER = TRPC_SYNTAX_IDENTIFIER

type _RPC_SYNTAX_IDENTIFIER = T_RPC_SYNTAX_IDENTIFIER

type TPRPC_SYNTAX_IDENTIFIER = uintptr

type PRPC_SYNTAX_IDENTIFIER = TPRPC_SYNTAX_IDENTIFIER

type TRPC_MESSAGE = struct {
	FHandle                  TRPC_BINDING_HANDLE
	FDataRepresentation      uint32
	FBuffer                  uintptr
	FBufferLength            uint32
	FProcNum                 uint32
	FTransferSyntax          TPRPC_SYNTAX_IDENTIFIER
	FRpcInterfaceInformation uintptr
	FReservedForRuntime      uintptr
	FManagerEpv              uintptr
	FImportContext           uintptr
	FRpcFlags                uint32
}

type RPC_MESSAGE = TRPC_MESSAGE

type T_RPC_MESSAGE = TRPC_MESSAGE

type _RPC_MESSAGE = T_RPC_MESSAGE

type TPRPC_MESSAGE = uintptr

type PRPC_MESSAGE = TPRPC_MESSAGE

type _RPC_ADDRESS_CHANGE_TYPE = int32

const _PROTOCOL_NOT_LOADED = 1
const _PROTOCOL_LOADED = 2
const _PROTOCOL_ADDRESS_CHANGE = 3

type TRPC_DISPATCH_FUNCTION = uintptr

type RPC_DISPATCH_FUNCTION = TRPC_DISPATCH_FUNCTION

type TRPC_DISPATCH_TABLE = struct {
	FDispatchTableCount uint32
	FDispatchTable      uintptr
	FReserved           TLONG_PTR
}

type RPC_DISPATCH_TABLE = TRPC_DISPATCH_TABLE

type TPRPC_DISPATCH_TABLE = uintptr

type PRPC_DISPATCH_TABLE = TPRPC_DISPATCH_TABLE

type TRPC_PROTSEQ_ENDPOINT = struct {
	FRpcProtocolSequence uintptr
	FEndpoint            uintptr
}

type RPC_PROTSEQ_ENDPOINT = TRPC_PROTSEQ_ENDPOINT

type T_RPC_PROTSEQ_ENDPOINT = TRPC_PROTSEQ_ENDPOINT

type _RPC_PROTSEQ_ENDPOINT = T_RPC_PROTSEQ_ENDPOINT

type TPRPC_PROTSEQ_ENDPOINT = uintptr

type PRPC_PROTSEQ_ENDPOINT = TPRPC_PROTSEQ_ENDPOINT

type TRPC_SERVER_INTERFACE = struct {
	FLength                  uint32
	FInterfaceId             TRPC_SYNTAX_IDENTIFIER
	FTransferSyntax          TRPC_SYNTAX_IDENTIFIER
	FDispatchTable           TPRPC_DISPATCH_TABLE
	FRpcProtseqEndpointCount uint32
	FRpcProtseqEndpoint      TPRPC_PROTSEQ_ENDPOINT
	FDefaultManagerEpv       uintptr
	FInterpreterInfo         uintptr
	FFlags                   uint32
}

type RPC_SERVER_INTERFACE = TRPC_SERVER_INTERFACE

type T_RPC_SERVER_INTERFACE = TRPC_SERVER_INTERFACE

type _RPC_SERVER_INTERFACE = T_RPC_SERVER_INTERFACE

type TPRPC_SERVER_INTERFACE = uintptr

type PRPC_SERVER_INTERFACE = TPRPC_SERVER_INTERFACE

type TRPC_CLIENT_INTERFACE = struct {
	FLength                  uint32
	FInterfaceId             TRPC_SYNTAX_IDENTIFIER
	FTransferSyntax          TRPC_SYNTAX_IDENTIFIER
	FDispatchTable           TPRPC_DISPATCH_TABLE
	FRpcProtseqEndpointCount uint32
	FRpcProtseqEndpoint      TPRPC_PROTSEQ_ENDPOINT
	FReserved                TULONG_PTR
	FInterpreterInfo         uintptr
	FFlags                   uint32
}

type RPC_CLIENT_INTERFACE = TRPC_CLIENT_INTERFACE

type T_RPC_CLIENT_INTERFACE = TRPC_CLIENT_INTERFACE

type _RPC_CLIENT_INTERFACE = T_RPC_CLIENT_INTERFACE

type TPRPC_CLIENT_INTERFACE = uintptr

type PRPC_CLIENT_INTERFACE = TPRPC_CLIENT_INTERFACE

type TI_RPC_MUTEX = uintptr

type I_RPC_MUTEX = TI_RPC_MUTEX

type TPRPC_RUNDOWN = uintptr

type PRPC_RUNDOWN = TPRPC_RUNDOWN

type TRPC_TRANSFER_SYNTAX = struct {
	FUuid      TUUID
	FVersMajor uint16
	FVersMinor uint16
}

type RPC_TRANSFER_SYNTAX = TRPC_TRANSFER_SYNTAX

type T_RPC_TRANSFER_SYNTAX = TRPC_TRANSFER_SYNTAX

type _RPC_TRANSFER_SYNTAX = T_RPC_TRANSFER_SYNTAX

type TRPCLT_PDU_FILTER_FUNC = uintptr

type RPCLT_PDU_FILTER_FUNC = TRPCLT_PDU_FILTER_FUNC

type TRPC_SETFILTER_FUNC = uintptr

type RPC_SETFILTER_FUNC = TRPC_SETFILTER_FUNC

type TRPC_C_OPT_METADATA_DESCRIPTOR = struct {
	FBufferSize uint32
	FBuffer     uintptr
}

type RPC_C_OPT_METADATA_DESCRIPTOR = TRPC_C_OPT_METADATA_DESCRIPTOR

type T_RPC_C_OPT_METADATA_DESCRIPTOR = TRPC_C_OPT_METADATA_DESCRIPTOR

type _RPC_C_OPT_METADATA_DESCRIPTOR = T_RPC_C_OPT_METADATA_DESCRIPTOR

type TRDR_CALLOUT_STATE = struct {
	FLastError           TRPC_STATUS
	FLastEEInfo          uintptr
	FLastCalledStage     TRPC_HTTP_REDIRECTOR_STAGE
	FServerName          uintptr
	FServerPort          uintptr
	FRemoteUser          uintptr
	FAuthType            uintptr
	FResourceTypePresent uint8
	FMetadataPresent     uint8
	FSessionIdPresent    uint8
	FInterfacePresent    uint8
	FResourceType        TUUID
	FMetadata            TRPC_C_OPT_METADATA_DESCRIPTOR
	FSessionId           TUUID
	FInterface           TRPC_SYNTAX_IDENTIFIER
	FCertContext         uintptr
}

type RDR_CALLOUT_STATE = TRDR_CALLOUT_STATE

type T_RDR_CALLOUT_STATE = TRDR_CALLOUT_STATE

type _RDR_CALLOUT_STATE = T_RDR_CALLOUT_STATE

type TI_RpcProxyIsValidMachineFn = uintptr

type I_RpcProxyIsValidMachineFn = TI_RpcProxyIsValidMachineFn

type TI_RpcProxyGetClientAddressFn = uintptr

type I_RpcProxyGetClientAddressFn = TI_RpcProxyGetClientAddressFn

type TI_RpcProxyGetConnectionTimeoutFn = uintptr

type I_RpcProxyGetConnectionTimeoutFn = TI_RpcProxyGetConnectionTimeoutFn

type TI_RpcPerformCalloutFn = uintptr

type I_RpcPerformCalloutFn = TI_RpcPerformCalloutFn

type TI_RpcFreeCalloutStateFn = uintptr

type I_RpcFreeCalloutStateFn = TI_RpcFreeCalloutStateFn

type TI_RpcProxyCallbackInterface = struct {
	FIsValidMachineFn       TI_RpcProxyIsValidMachineFn
	FGetClientAddressFn     TI_RpcProxyGetClientAddressFn
	FGetConnectionTimeoutFn TI_RpcProxyGetConnectionTimeoutFn
	FPerformCalloutFn       TI_RpcPerformCalloutFn
	FFreeCalloutStateFn     TI_RpcFreeCalloutStateFn
}

type I_RpcProxyCallbackInterface = TI_RpcProxyCallbackInterface

type TtagI_RpcProxyCallbackInterface = TI_RpcProxyCallbackInterface

type tagI_RpcProxyCallbackInterface = TtagI_RpcProxyCallbackInterface

type TRPC_NS_HANDLE = uintptr

type RPC_NS_HANDLE = TRPC_NS_HANDLE

type TRPC_NOTIFICATION_TYPES = int32

type RPC_NOTIFICATION_TYPES = TRPC_NOTIFICATION_TYPES

type __RPC_NOTIFICATION_TYPES = int32

const _RpcNotificationTypeNone = 0
const _RpcNotificationTypeEvent = 1
const _RpcNotificationTypeApc = 2
const _RpcNotificationTypeIoc = 3
const _RpcNotificationTypeHwnd = 4
const _RpcNotificationTypeCallback = 5

type TRPC_ASYNC_EVENT = int32

type RPC_ASYNC_EVENT = TRPC_ASYNC_EVENT

type __RPC_ASYNC_EVENT = int32

const _RpcCallComplete = 0
const _RpcSendComplete = 1
const _RpcReceiveComplete = 2

type T_RPC_ASYNC_STATE = struct {
	FSize             uint32
	FSignature        uint32
	FLock             int32
	FFlags            uint32
	FStubInfo         uintptr
	FUserInfo         uintptr
	FRuntimeInfo      uintptr
	FEvent            TRPC_ASYNC_EVENT
	FNotificationType TRPC_NOTIFICATION_TYPES
	Fu                struct {
		FIOC [0]struct {
			FhIOPort                    THANDLE
			FdwNumberOfBytesTransferred TDWORD
			FdwCompletionKey            TDWORD_PTR
			FlpOverlapped               TLPOVERLAPPED
		}
		FHWND [0]struct {
			FhWnd THWND
			FMsg  TUINT
		}
		FhEvent              [0]THANDLE
		FNotificationRoutine [0]TPFN_RPCNOTIFICATION_ROUTINE
		FAPC                 struct {
			FNotificationRoutine TPFN_RPCNOTIFICATION_ROUTINE
			FhThread             THANDLE
		}
		F__ccgo_pad5 [8]byte
	}
	FReserved [4]TLONG_PTR
}

type _RPC_ASYNC_STATE = T_RPC_ASYNC_STATE

type TPFN_RPCNOTIFICATION_ROUTINE = uintptr

type PFN_RPCNOTIFICATION_ROUTINE = TPFN_RPCNOTIFICATION_ROUTINE

type TRPC_ASYNC_STATE = struct {
	FSize             uint32
	FSignature        uint32
	FLock             int32
	FFlags            uint32
	FStubInfo         uintptr
	FUserInfo         uintptr
	FRuntimeInfo      uintptr
	FEvent            TRPC_ASYNC_EVENT
	FNotificationType TRPC_NOTIFICATION_TYPES
	Fu                struct {
		FIOC [0]struct {
			FhIOPort                    THANDLE
			FdwNumberOfBytesTransferred TDWORD
			FdwCompletionKey            TDWORD_PTR
			FlpOverlapped               TLPOVERLAPPED
		}
		FHWND [0]struct {
			FhWnd THWND
			FMsg  TUINT
		}
		FhEvent              [0]THANDLE
		FNotificationRoutine [0]TPFN_RPCNOTIFICATION_ROUTINE
		FAPC                 struct {
			FNotificationRoutine TPFN_RPCNOTIFICATION_ROUTINE
			FhThread             THANDLE
		}
		F__ccgo_pad5 [8]byte
	}
	FReserved [4]TLONG_PTR
}

type RPC_ASYNC_STATE = TRPC_ASYNC_STATE

type TPRPC_ASYNC_STATE = uintptr

type PRPC_ASYNC_STATE = TPRPC_ASYNC_STATE

type TExtendedErrorParamTypes = int32

type ExtendedErrorParamTypes = TExtendedErrorParamTypes

type _tagExtendedErrorParamTypes = int32

const _eeptAnsiString = 1
const _eeptUnicodeString = 2
const _eeptLongVal = 3
const _eeptShortVal = 4
const _eeptPointerVal = 5
const _eeptNone = 6
const _eeptBinary = 7

type TBinaryParam = struct {
	FBuffer uintptr
	FSize   int16
}

type BinaryParam = TBinaryParam

type TtagBinaryParam = TBinaryParam

type tagBinaryParam = TtagBinaryParam

type TRPC_EE_INFO_PARAM = struct {
	F__ccgo_align  [0]uint32
	FParameterType TExtendedErrorParamTypes
	F__ccgo_align1 [4]byte
	Fu             struct {
		F__ccgo_align  [0]uint32
		FUnicodeString [0]TLPWSTR
		FLVal          [0]int32
		FSVal          [0]int16
		FPVal          [0]TULONGLONG
		FBVal          [0]TBinaryParam
		FAnsiString    TLPSTR
		F__ccgo_pad6   [4]byte
	}
}

type RPC_EE_INFO_PARAM = TRPC_EE_INFO_PARAM

type TtagRPC_EE_INFO_PARAM = TRPC_EE_INFO_PARAM

type tagRPC_EE_INFO_PARAM = TtagRPC_EE_INFO_PARAM

type TRPC_EXTENDED_ERROR_INFO = struct {
	F__ccgo_align [0]uint32
	FVersion      TULONG
	FComputerName TLPWSTR
	FProcessID    TULONG
	Fu            struct {
		FFileTime   [0]TFILETIME
		FSystemTime TSYSTEMTIME
	}
	FGeneratingComponent TULONG
	FStatus              TULONG
	FDetectionLocation   TUSHORT
	FFlags               TUSHORT
	FNumberOfParameters  int32
	F__ccgo_align9       [4]byte
	FParameters          [4]TRPC_EE_INFO_PARAM
}

type RPC_EXTENDED_ERROR_INFO = TRPC_EXTENDED_ERROR_INFO

type TtagRPC_EXTENDED_ERROR_INFO = TRPC_EXTENDED_ERROR_INFO

type tagRPC_EXTENDED_ERROR_INFO = TtagRPC_EXTENDED_ERROR_INFO

type TRPC_ERROR_ENUM_HANDLE = struct {
	FSignature  TULONG
	FCurrentPos uintptr
	FHead       uintptr
}

type RPC_ERROR_ENUM_HANDLE = TRPC_ERROR_ENUM_HANDLE

type TtagRPC_ERROR_ENUM_HANDLE = TRPC_ERROR_ENUM_HANDLE

type tagRPC_ERROR_ENUM_HANDLE = TtagRPC_ERROR_ENUM_HANDLE

type TRPC_CALL_ATTRIBUTES_V1_W = struct {
	FVersion                         uint32
	FFlags                           uint32
	FServerPrincipalNameBufferLength uint32
	FServerPrincipalName             uintptr
	FClientPrincipalNameBufferLength uint32
	FClientPrincipalName             uintptr
	FAuthenticationLevel             uint32
	FAuthenticationService           uint32
	FNullSession                     TWINBOOL
}

type RPC_CALL_ATTRIBUTES_V1_W = TRPC_CALL_ATTRIBUTES_V1_W

type TtagRPC_CALL_ATTRIBUTES_V1_W = TRPC_CALL_ATTRIBUTES_V1_W

type tagRPC_CALL_ATTRIBUTES_V1_W = TtagRPC_CALL_ATTRIBUTES_V1_W

type TRPC_CALL_ATTRIBUTES_V1_A = struct {
	FVersion                         uint32
	FFlags                           uint32
	FServerPrincipalNameBufferLength uint32
	FServerPrincipalName             uintptr
	FClientPrincipalNameBufferLength uint32
	FClientPrincipalName             uintptr
	FAuthenticationLevel             uint32
	FAuthenticationService           uint32
	FNullSession                     TWINBOOL
}

type RPC_CALL_ATTRIBUTES_V1_A = TRPC_CALL_ATTRIBUTES_V1_A

type TtagRPC_CALL_ATTRIBUTES_V1_A = TRPC_CALL_ATTRIBUTES_V1_A

type tagRPC_CALL_ATTRIBUTES_V1_A = TtagRPC_CALL_ATTRIBUTES_V1_A

type TRPC_CALL_ATTRIBUTES = struct {
	FVersion                         uint32
	FFlags                           uint32
	FServerPrincipalNameBufferLength uint32
	FServerPrincipalName             uintptr
	FClientPrincipalNameBufferLength uint32
	FClientPrincipalName             uintptr
	FAuthenticationLevel             uint32
	FAuthenticationService           uint32
	FNullSession                     TWINBOOL
}

type RPC_CALL_ATTRIBUTES = TRPC_CALL_ATTRIBUTES

type TRPC_ASYNC_NOTIFICATION_INFO = struct {
	FIOC [0]struct {
		FhIOPort                    THANDLE
		FdwNumberOfBytesTransferred TDWORD
		FdwCompletionKey            TDWORD_PTR
		FlpOverlapped               TLPOVERLAPPED
	}
	FHWND [0]struct {
		FhWnd THWND
		FMsg  TUINT
	}
	FhEvent              [0]THANDLE
	FNotificationRoutine [0]TPFN_RPCNOTIFICATION_ROUTINE
	FAPC                 struct {
		FNotificationRoutine TPFN_RPCNOTIFICATION_ROUTINE
		FhThread             THANDLE
	}
	F__ccgo_pad5 [8]byte
}

type RPC_ASYNC_NOTIFICATION_INFO = TRPC_ASYNC_NOTIFICATION_INFO

type T_RPC_ASYNC_NOTIFICATION_INFO = TRPC_ASYNC_NOTIFICATION_INFO

type _RPC_ASYNC_NOTIFICATION_INFO = T_RPC_ASYNC_NOTIFICATION_INFO

type TPRPC_ASYNC_NOTIFICATION_INFO = uintptr

type PRPC_ASYNC_NOTIFICATION_INFO = TPRPC_ASYNC_NOTIFICATION_INFO

type TRpcCallType = int32

type RpcCallType = TRpcCallType

type __RpcCallType = int32

const _rctInvalid = 0
const _rctNormal = 1
const _rctTraining = 2
const _rctGuaranteed = 3

type TRpcLocalAddressFormat = int32

type RpcLocalAddressFormat = TRpcLocalAddressFormat

type __RpcLocalAddressFormat = int32

const _rlafInvalid = 0
const _rlafIPv4 = 1
const _rlafIPv6 = 2

type TRPC_NOTIFICATIONS = int32

type RPC_NOTIFICATIONS = TRPC_NOTIFICATIONS

type __RPC_NOTIFICATIONS = int32

const _RpcNotificationCallNone = 0
const _RpcNotificationClientDisconnect = 1
const _RpcNotificationCallCancel = 2

type TRpcCallClientLocality = int32

type RpcCallClientLocality = TRpcCallClientLocality

type __RpcCallClientLocality = int32

const _rcclInvalid = 0
const _rcclLocal = 1
const _rcclRemote = 2
const _rcclClientUnknownLocality = 3

type TRPC_CALL_LOCAL_ADDRESS_V1_A = struct {
	FVersion       uint32
	FBuffer        uintptr
	FBufferSize    uint32
	FAddressFormat TRpcLocalAddressFormat
}

type RPC_CALL_LOCAL_ADDRESS_V1_A = TRPC_CALL_LOCAL_ADDRESS_V1_A

type TtagRPC_CALL_LOCAL_ADDRESS_V1_A = TRPC_CALL_LOCAL_ADDRESS_V1_A

type tagRPC_CALL_LOCAL_ADDRESS_V1_A = TtagRPC_CALL_LOCAL_ADDRESS_V1_A

type TRPC_CALL_LOCAL_ADDRESS_A = struct {
	FVersion       uint32
	FBuffer        uintptr
	FBufferSize    uint32
	FAddressFormat TRpcLocalAddressFormat
}

type RPC_CALL_LOCAL_ADDRESS_A = TRPC_CALL_LOCAL_ADDRESS_A

type TRPC_CALL_LOCAL_ADDRESS_V1_W = struct {
	FVersion       uint32
	FBuffer        uintptr
	FBufferSize    uint32
	FAddressFormat TRpcLocalAddressFormat
}

type RPC_CALL_LOCAL_ADDRESS_V1_W = TRPC_CALL_LOCAL_ADDRESS_V1_W

type TtagRPC_CALL_LOCAL_ADDRESS_V1_W = TRPC_CALL_LOCAL_ADDRESS_V1_W

type tagRPC_CALL_LOCAL_ADDRESS_V1_W = TtagRPC_CALL_LOCAL_ADDRESS_V1_W

type TRPC_CALL_LOCAL_ADDRESS_W = struct {
	FVersion       uint32
	FBuffer        uintptr
	FBufferSize    uint32
	FAddressFormat TRpcLocalAddressFormat
}

type RPC_CALL_LOCAL_ADDRESS_W = TRPC_CALL_LOCAL_ADDRESS_W

type TRPC_CALL_ATTRIBUTES_V2_A = struct {
	FVersion                         uint32
	FFlags                           uint32
	FServerPrincipalNameBufferLength uint32
	FServerPrincipalName             uintptr
	FClientPrincipalNameBufferLength uint32
	FClientPrincipalName             uintptr
	FAuthenticationLevel             uint32
	FAuthenticationService           uint32
	FNullSession                     TWINBOOL
	FKernelMode                      TWINBOOL
	FProtocolSequence                uint32
	FIsClientLocal                   TRpcCallClientLocality
	FClientPID                       THANDLE
	FCallStatus                      uint32
	FCallType                        TRpcCallType
	FCallLocalAddress                uintptr
	FOpNum                           uint16
	FInterfaceUuid                   TUUID
}

type RPC_CALL_ATTRIBUTES_V2_A = TRPC_CALL_ATTRIBUTES_V2_A

type TtagRPC_CALL_ATTRIBUTES_V2A = TRPC_CALL_ATTRIBUTES_V2_A

type tagRPC_CALL_ATTRIBUTES_V2A = TtagRPC_CALL_ATTRIBUTES_V2A

type TRPC_CALL_ATTRIBUTES_A = struct {
	FVersion                         uint32
	FFlags                           uint32
	FServerPrincipalNameBufferLength uint32
	FServerPrincipalName             uintptr
	FClientPrincipalNameBufferLength uint32
	FClientPrincipalName             uintptr
	FAuthenticationLevel             uint32
	FAuthenticationService           uint32
	FNullSession                     TWINBOOL
	FKernelMode                      TWINBOOL
	FProtocolSequence                uint32
	FIsClientLocal                   TRpcCallClientLocality
	FClientPID                       THANDLE
	FCallStatus                      uint32
	FCallType                        TRpcCallType
	FCallLocalAddress                uintptr
	FOpNum                           uint16
	FInterfaceUuid                   TUUID
}

type RPC_CALL_ATTRIBUTES_A = TRPC_CALL_ATTRIBUTES_A

type TRPC_CALL_ATTRIBUTES_V2_W = struct {
	FVersion                         uint32
	FFlags                           uint32
	FServerPrincipalNameBufferLength uint32
	FServerPrincipalName             uintptr
	FClientPrincipalNameBufferLength uint32
	FClientPrincipalName             uintptr
	FAuthenticationLevel             uint32
	FAuthenticationService           uint32
	FNullSession                     TWINBOOL
	FKernelMode                      TWINBOOL
	FProtocolSequence                uint32
	FIsClientLocal                   TRpcCallClientLocality
	FClientPID                       THANDLE
	FCallStatus                      uint32
	FCallType                        TRpcCallType
	FCallLocalAddress                uintptr
	FOpNum                           uint16
	FInterfaceUuid                   TUUID
}

type RPC_CALL_ATTRIBUTES_V2_W = TRPC_CALL_ATTRIBUTES_V2_W

type TtagRPC_CALL_ATTRIBUTES_V2W = TRPC_CALL_ATTRIBUTES_V2_W

type tagRPC_CALL_ATTRIBUTES_V2W = TtagRPC_CALL_ATTRIBUTES_V2W

type TRPC_CALL_ATTRIBUTES_W = struct {
	FVersion                         uint32
	FFlags                           uint32
	FServerPrincipalNameBufferLength uint32
	FServerPrincipalName             uintptr
	FClientPrincipalNameBufferLength uint32
	FClientPrincipalName             uintptr
	FAuthenticationLevel             uint32
	FAuthenticationService           uint32
	FNullSession                     TWINBOOL
	FKernelMode                      TWINBOOL
	FProtocolSequence                uint32
	FIsClientLocal                   TRpcCallClientLocality
	FClientPID                       THANDLE
	FCallStatus                      uint32
	FCallType                        TRpcCallType
	FCallLocalAddress                uintptr
	FOpNum                           uint16
	FInterfaceUuid                   TUUID
}

type RPC_CALL_ATTRIBUTES_W = TRPC_CALL_ATTRIBUTES_W

type THDROP__ = struct {
	Funused int32
}

type HDROP__ = THDROP__

type THDROP = uintptr

type HDROP = THDROP

type TDRAGINFOA = struct {
	FuSize       TUINT
	Fpt          TPOINT
	FfNC         TWINBOOL
	FlpFileList  TLPSTR
	FgrfKeyState TDWORD
}

type DRAGINFOA = TDRAGINFOA

type T_DRAGINFOA = TDRAGINFOA

type _DRAGINFOA = T_DRAGINFOA

type TLPDRAGINFOA = uintptr

type LPDRAGINFOA = TLPDRAGINFOA

type TDRAGINFOW = struct {
	FuSize       TUINT
	Fpt          TPOINT
	FfNC         TWINBOOL
	FlpFileList  TLPWSTR
	FgrfKeyState TDWORD
}

type DRAGINFOW = TDRAGINFOW

type T_DRAGINFOW = TDRAGINFOW

type _DRAGINFOW = T_DRAGINFOW

type TLPDRAGINFOW = uintptr

type LPDRAGINFOW = TLPDRAGINFOW

type TDRAGINFO = struct {
	FuSize       TUINT
	Fpt          TPOINT
	FfNC         TWINBOOL
	FlpFileList  TLPSTR
	FgrfKeyState TDWORD
}

type DRAGINFO = TDRAGINFO

type TLPDRAGINFO = uintptr

type LPDRAGINFO = TLPDRAGINFO

type TAPPBARDATA = struct {
	FcbSize           TDWORD
	FhWnd             THWND
	FuCallbackMessage TUINT
	FuEdge            TUINT
	Frc               TRECT
	FlParam           TLPARAM
}

type APPBARDATA = TAPPBARDATA

type T_AppBarData = TAPPBARDATA

type _AppBarData = T_AppBarData

type TPAPPBARDATA = uintptr

type PAPPBARDATA = TPAPPBARDATA

type TFILEOP_FLAGS = uint16

type FILEOP_FLAGS = TFILEOP_FLAGS

type TPRINTEROP_FLAGS = uint16

type PRINTEROP_FLAGS = TPRINTEROP_FLAGS

type TSHFILEOPSTRUCTA = struct {
	Fhwnd                  THWND
	FwFunc                 TUINT
	FpFrom                 TLPCSTR
	FpTo                   TLPCSTR
	FfFlags                TFILEOP_FLAGS
	FfAnyOperationsAborted TWINBOOL
	FhNameMappings         TLPVOID
	FlpszProgressTitle     TPCSTR
}

type SHFILEOPSTRUCTA = TSHFILEOPSTRUCTA

type T_SHFILEOPSTRUCTA = TSHFILEOPSTRUCTA

type _SHFILEOPSTRUCTA = T_SHFILEOPSTRUCTA

type TLPSHFILEOPSTRUCTA = uintptr

type LPSHFILEOPSTRUCTA = TLPSHFILEOPSTRUCTA

type TSHFILEOPSTRUCTW = struct {
	Fhwnd                  THWND
	FwFunc                 TUINT
	FpFrom                 TLPCWSTR
	FpTo                   TLPCWSTR
	FfFlags                TFILEOP_FLAGS
	FfAnyOperationsAborted TWINBOOL
	FhNameMappings         TLPVOID
	FlpszProgressTitle     TPCWSTR
}

type SHFILEOPSTRUCTW = TSHFILEOPSTRUCTW

type T_SHFILEOPSTRUCTW = TSHFILEOPSTRUCTW

type _SHFILEOPSTRUCTW = T_SHFILEOPSTRUCTW

type TLPSHFILEOPSTRUCTW = uintptr

type LPSHFILEOPSTRUCTW = TLPSHFILEOPSTRUCTW

type TSHFILEOPSTRUCT = struct {
	Fhwnd                  THWND
	FwFunc                 TUINT
	FpFrom                 TLPCSTR
	FpTo                   TLPCSTR
	FfFlags                TFILEOP_FLAGS
	FfAnyOperationsAborted TWINBOOL
	FhNameMappings         TLPVOID
	FlpszProgressTitle     TPCSTR
}

type SHFILEOPSTRUCT = TSHFILEOPSTRUCT

type TLPSHFILEOPSTRUCT = uintptr

type LPSHFILEOPSTRUCT = TLPSHFILEOPSTRUCT

type TSHNAMEMAPPINGA = struct {
	FpszOldPath TLPSTR
	FpszNewPath TLPSTR
	FcchOldPath int32
	FcchNewPath int32
}

type SHNAMEMAPPINGA = TSHNAMEMAPPINGA

type T_SHNAMEMAPPINGA = TSHNAMEMAPPINGA

type _SHNAMEMAPPINGA = T_SHNAMEMAPPINGA

type TLPSHNAMEMAPPINGA = uintptr

type LPSHNAMEMAPPINGA = TLPSHNAMEMAPPINGA

type TSHNAMEMAPPINGW = struct {
	FpszOldPath TLPWSTR
	FpszNewPath TLPWSTR
	FcchOldPath int32
	FcchNewPath int32
}

type SHNAMEMAPPINGW = TSHNAMEMAPPINGW

type T_SHNAMEMAPPINGW = TSHNAMEMAPPINGW

type _SHNAMEMAPPINGW = T_SHNAMEMAPPINGW

type TLPSHNAMEMAPPINGW = uintptr

type LPSHNAMEMAPPINGW = TLPSHNAMEMAPPINGW

type TSHNAMEMAPPING = struct {
	FpszOldPath TLPSTR
	FpszNewPath TLPSTR
	FcchOldPath int32
	FcchNewPath int32
}

type SHNAMEMAPPING = TSHNAMEMAPPING

type TLPSHNAMEMAPPING = uintptr

type LPSHNAMEMAPPING = TLPSHNAMEMAPPING

type TSHELLEXECUTEINFOA = struct {
	FcbSize       TDWORD
	FfMask        TULONG
	Fhwnd         THWND
	FlpVerb       TLPCSTR
	FlpFile       TLPCSTR
	FlpParameters TLPCSTR
	FlpDirectory  TLPCSTR
	FnShow        int32
	FhInstApp     THINSTANCE
	FlpIDList     uintptr
	FlpClass      TLPCSTR
	FhkeyClass    THKEY
	FdwHotKey     TDWORD
	F__ccgo13_52  struct {
		FhMonitor [0]THANDLE
		FhIcon    THANDLE
	}
	FhProcess THANDLE
}

type SHELLEXECUTEINFOA = TSHELLEXECUTEINFOA

type T_SHELLEXECUTEINFOA = TSHELLEXECUTEINFOA

type _SHELLEXECUTEINFOA = T_SHELLEXECUTEINFOA

type TLPSHELLEXECUTEINFOA = uintptr

type LPSHELLEXECUTEINFOA = TLPSHELLEXECUTEINFOA

type TSHELLEXECUTEINFOW = struct {
	FcbSize       TDWORD
	FfMask        TULONG
	Fhwnd         THWND
	FlpVerb       TLPCWSTR
	FlpFile       TLPCWSTR
	FlpParameters TLPCWSTR
	FlpDirectory  TLPCWSTR
	FnShow        int32
	FhInstApp     THINSTANCE
	FlpIDList     uintptr
	FlpClass      TLPCWSTR
	FhkeyClass    THKEY
	FdwHotKey     TDWORD
	F__ccgo13_52  struct {
		FhMonitor [0]THANDLE
		FhIcon    THANDLE
	}
	FhProcess THANDLE
}

type SHELLEXECUTEINFOW = TSHELLEXECUTEINFOW

type T_SHELLEXECUTEINFOW = TSHELLEXECUTEINFOW

type _SHELLEXECUTEINFOW = T_SHELLEXECUTEINFOW

type TLPSHELLEXECUTEINFOW = uintptr

type LPSHELLEXECUTEINFOW = TLPSHELLEXECUTEINFOW

type TSHELLEXECUTEINFO = struct {
	FcbSize       TDWORD
	FfMask        TULONG
	Fhwnd         THWND
	FlpVerb       TLPCSTR
	FlpFile       TLPCSTR
	FlpParameters TLPCSTR
	FlpDirectory  TLPCSTR
	FnShow        int32
	FhInstApp     THINSTANCE
	FlpIDList     uintptr
	FlpClass      TLPCSTR
	FhkeyClass    THKEY
	FdwHotKey     TDWORD
	F__ccgo13_52  struct {
		FhMonitor [0]THANDLE
		FhIcon    THANDLE
	}
	FhProcess THANDLE
}

type SHELLEXECUTEINFO = TSHELLEXECUTEINFO

type TLPSHELLEXECUTEINFO = uintptr

type LPSHELLEXECUTEINFO = TLPSHELLEXECUTEINFO

type TSHCREATEPROCESSINFOW = struct {
	FcbSize               TDWORD
	FfMask                TULONG
	Fhwnd                 THWND
	FpszFile              TLPCWSTR
	FpszParameters        TLPCWSTR
	FpszCurrentDirectory  TLPCWSTR
	FhUserToken           THANDLE
	FlpProcessAttributes  TLPSECURITY_ATTRIBUTES
	FlpThreadAttributes   TLPSECURITY_ATTRIBUTES
	FbInheritHandles      TWINBOOL
	FdwCreationFlags      TDWORD
	FlpStartupInfo        TLPSTARTUPINFOW
	FlpProcessInformation TLPPROCESS_INFORMATION
}

type SHCREATEPROCESSINFOW = TSHCREATEPROCESSINFOW

type T_SHCREATEPROCESSINFOW = TSHCREATEPROCESSINFOW

type _SHCREATEPROCESSINFOW = T_SHCREATEPROCESSINFOW

type TPSHCREATEPROCESSINFOW = uintptr

type PSHCREATEPROCESSINFOW = TPSHCREATEPROCESSINFOW

type TASSOCCLASS = int32

type ASSOCCLASS = TASSOCCLASS

type _ASSOCCLASS = int32

const _ASSOCCLASS_SHELL_KEY = 0
const _ASSOCCLASS_PROGID_KEY = 1
const _ASSOCCLASS_PROGID_STR = 2
const _ASSOCCLASS_CLSID_KEY = 3
const _ASSOCCLASS_CLSID_STR = 4
const _ASSOCCLASS_APP_KEY = 5
const _ASSOCCLASS_APP_STR = 6
const _ASSOCCLASS_SYSTEM_STR = 7
const _ASSOCCLASS_FOLDER = 8
const _ASSOCCLASS_STAR = 9
const _ASSOCCLASS_FIXED_PROGID_STR = 10
const _ASSOCCLASS_PROTOCOL_STR = 11

type TASSOCIATIONELEMENT = struct {
	Fac       TASSOCCLASS
	FhkClass  THKEY
	FpszClass TPCWSTR
}

type ASSOCIATIONELEMENT = TASSOCIATIONELEMENT

type TSHQUERYRBINFO = struct {
	F__ccgo_align  [0]uint32
	FcbSize        TDWORD
	F__ccgo_align1 [4]byte
	Fi64Size       int64
	Fi64NumItems   int64
}

type SHQUERYRBINFO = TSHQUERYRBINFO

type T_SHQUERYRBINFO = TSHQUERYRBINFO

type _SHQUERYRBINFO = T_SHQUERYRBINFO

type TLPSHQUERYRBINFO = uintptr

type LPSHQUERYRBINFO = TLPSHQUERYRBINFO

type TQUERY_USER_NOTIFICATION_STATE = int32

type QUERY_USER_NOTIFICATION_STATE = TQUERY_USER_NOTIFICATION_STATE

const _QUNS_NOT_PRESENT = 1
const _QUNS_BUSY = 2
const _QUNS_RUNNING_D3D_FULL_SCREEN = 3
const _QUNS_PRESENTATION_MODE = 4
const _QUNS_ACCEPTS_NOTIFICATIONS = 5
const _QUNS_QUIET_TIME = 6
const _QUNS_APP = 7

type TNOTIFYICONDATAA = struct {
	FcbSize           TDWORD
	FhWnd             THWND
	FuID              TUINT
	FuFlags           TUINT
	FuCallbackMessage TUINT
	FhIcon            THICON
	FszTip            [128]TCHAR
	FdwState          TDWORD
	FdwStateMask      TDWORD
	FszInfo           [256]TCHAR
	F__ccgo10_416     struct {
		FuVersion [0]TUINT
		FuTimeout TUINT
	}
	FszInfoTitle  [64]TCHAR
	FdwInfoFlags  TDWORD
	FguidItem     TGUID
	FhBalloonIcon THICON
}

type NOTIFYICONDATAA = TNOTIFYICONDATAA

type T_NOTIFYICONDATAA = TNOTIFYICONDATAA

type _NOTIFYICONDATAA = T_NOTIFYICONDATAA

type TPNOTIFYICONDATAA = uintptr

type PNOTIFYICONDATAA = TPNOTIFYICONDATAA

type TNOTIFYICONDATAW = struct {
	FcbSize           TDWORD
	FhWnd             THWND
	FuID              TUINT
	FuFlags           TUINT
	FuCallbackMessage TUINT
	FhIcon            THICON
	FszTip            [128]TWCHAR
	FdwState          TDWORD
	FdwStateMask      TDWORD
	FszInfo           [256]TWCHAR
	F__ccgo10_800     struct {
		FuVersion [0]TUINT
		FuTimeout TUINT
	}
	FszInfoTitle  [64]TWCHAR
	FdwInfoFlags  TDWORD
	FguidItem     TGUID
	FhBalloonIcon THICON
}

type NOTIFYICONDATAW = TNOTIFYICONDATAW

type T_NOTIFYICONDATAW = TNOTIFYICONDATAW

type _NOTIFYICONDATAW = T_NOTIFYICONDATAW

type TPNOTIFYICONDATAW = uintptr

type PNOTIFYICONDATAW = TPNOTIFYICONDATAW

type TNOTIFYICONDATA = struct {
	FcbSize           TDWORD
	FhWnd             THWND
	FuID              TUINT
	FuFlags           TUINT
	FuCallbackMessage TUINT
	FhIcon            THICON
	FszTip            [128]TCHAR
	FdwState          TDWORD
	FdwStateMask      TDWORD
	FszInfo           [256]TCHAR
	F__ccgo10_416     struct {
		FuVersion [0]TUINT
		FuTimeout TUINT
	}
	FszInfoTitle  [64]TCHAR
	FdwInfoFlags  TDWORD
	FguidItem     TGUID
	FhBalloonIcon THICON
}

type NOTIFYICONDATA = TNOTIFYICONDATA

type TPNOTIFYICONDATA = uintptr

type PNOTIFYICONDATA = TPNOTIFYICONDATA

type TNOTIFYICONIDENTIFIER = struct {
	FcbSize   TDWORD
	FhWnd     THWND
	FuID      TUINT
	FguidItem TGUID
}

type NOTIFYICONIDENTIFIER = TNOTIFYICONIDENTIFIER

type T_NOTIFYICONIDENTIFIER = TNOTIFYICONIDENTIFIER

type _NOTIFYICONIDENTIFIER = T_NOTIFYICONIDENTIFIER

type TPNOTIFYICONIDENTIFIER = uintptr

type PNOTIFYICONIDENTIFIER = TPNOTIFYICONIDENTIFIER

type TSHFILEINFOA = struct {
	FhIcon         THICON
	FiIcon         int32
	FdwAttributes  TDWORD
	FszDisplayName [260]TCHAR
	FszTypeName    [80]TCHAR
}

type SHFILEINFOA = TSHFILEINFOA

type T_SHFILEINFOA = TSHFILEINFOA

type _SHFILEINFOA = T_SHFILEINFOA

type TSHFILEINFOW = struct {
	FhIcon         THICON
	FiIcon         int32
	FdwAttributes  TDWORD
	FszDisplayName [260]TWCHAR
	FszTypeName    [80]TWCHAR
}

type SHFILEINFOW = TSHFILEINFOW

type T_SHFILEINFOW = TSHFILEINFOW

type _SHFILEINFOW = T_SHFILEINFOW

type TSHFILEINFO = struct {
	FhIcon         THICON
	FiIcon         int32
	FdwAttributes  TDWORD
	FszDisplayName [260]TCHAR
	FszTypeName    [80]TCHAR
}

type SHFILEINFO = TSHFILEINFO

type TSHSTOCKICONINFO = struct {
	FcbSize         TDWORD
	FhIcon          THICON
	FiSysImageIndex int32
	FiIcon          int32
	FszPath         [260]TWCHAR
}

type SHSTOCKICONINFO = TSHSTOCKICONINFO

type T_SHSTOCKICONINFO = TSHSTOCKICONINFO

type _SHSTOCKICONINFO = T_SHSTOCKICONINFO

type TSHSTOCKICONID = int32

type SHSTOCKICONID = TSHSTOCKICONID

type _SHSTOCKICONID = int32

const _SIID_DOCNOASSOC = 0
const _SIID_DOCASSOC = 1
const _SIID_APPLICATION = 2
const _SIID_FOLDER = 3
const _SIID_FOLDEROPEN = 4
const _SIID_DRIVE525 = 5
const _SIID_DRIVE35 = 6
const _SIID_DRIVEREMOVE = 7
const _SIID_DRIVEFIXED = 8
const _SIID_DRIVENET = 9
const _SIID_DRIVENETDISABLED = 10
const _SIID_DRIVECD = 11
const _SIID_DRIVERAM = 12
const _SIID_WORLD = 13
const _SIID_SERVER = 15
const _SIID_PRINTER = 16
const _SIID_MYNETWORK = 17
const _SIID_FIND = 22
const _SIID_HELP = 23
const _SIID_SHARE = 28
const _SIID_LINK = 29
const _SIID_SLOWFILE = 30
const _SIID_RECYCLER = 31
const _SIID_RECYCLERFULL = 32
const _SIID_MEDIACDAUDIO = 40
const _SIID_LOCK = 47
const _SIID_AUTOLIST = 49
const _SIID_PRINTERNET = 50
const _SIID_SERVERSHARE = 51
const _SIID_PRINTERFAX = 52
const _SIID_PRINTERFAXNET = 53
const _SIID_PRINTERFILE = 54
const _SIID_STACK = 55
const _SIID_MEDIASVCD = 56
const _SIID_STUFFEDFOLDER = 57
const _SIID_DRIVEUNKNOWN = 58
const _SIID_DRIVEDVD = 59
const _SIID_MEDIADVD = 60
const _SIID_MEDIADVDRAM = 61
const _SIID_MEDIADVDRW = 62
const _SIID_MEDIADVDR = 63
const _SIID_MEDIADVDROM = 64
const _SIID_MEDIACDAUDIOPLUS = 65
const _SIID_MEDIACDRW = 66
const _SIID_MEDIACDR = 67
const _SIID_MEDIACDBURN = 68
const _SIID_MEDIABLANKCD = 69
const _SIID_MEDIACDROM = 70
const _SIID_AUDIOFILES = 71
const _SIID_IMAGEFILES = 72
const _SIID_VIDEOFILES = 73
const _SIID_MIXEDFILES = 74
const _SIID_FOLDERBACK = 75
const _SIID_FOLDERFRONT = 76
const _SIID_SHIELD = 77
const _SIID_WARNING = 78
const _SIID_INFO = 79
const _SIID_ERROR = 80
const _SIID_KEY = 81
const _SIID_SOFTWARE = 82
const _SIID_RENAME = 83
const _SIID_DELETE = 84
const _SIID_MEDIAAUDIODVD = 85
const _SIID_MEDIAMOVIEDVD = 86
const _SIID_MEDIAENHANCEDCD = 87
const _SIID_MEDIAENHANCEDDVD = 88
const _SIID_MEDIAHDDVD = 89
const _SIID_MEDIABLURAY = 90
const _SIID_MEDIAVCD = 91
const _SIID_MEDIADVDPLUSR = 92
const _SIID_MEDIADVDPLUSRW = 93
const _SIID_DESKTOPPC = 94
const _SIID_MOBILEPC = 95
const _SIID_USERS = 96
const _SIID_MEDIASMARTMEDIA = 97
const _SIID_MEDIACOMPACTFLASH = 98
const _SIID_DEVICECELLPHONE = 99
const _SIID_DEVICECAMERA = 100
const _SIID_DEVICEVIDEOCAMERA = 101
const _SIID_DEVICEAUDIOPLAYER = 102
const _SIID_NETWORKCONNECT = 103
const _SIID_INTERNET = 104
const _SIID_ZIPFILE = 105
const _SIID_SETTINGS = 106
const _SIID_DRIVEHDDVD = 132
const _SIID_DRIVEBD = 133
const _SIID_MEDIAHDDVDROM = 134
const _SIID_MEDIAHDDVDR = 135
const _SIID_MEDIAHDDVDRAM = 136
const _SIID_MEDIABDROM = 137
const _SIID_MEDIABDR = 138
const _SIID_MEDIABDRE = 139
const _SIID_CLUSTEREDDRIVE = 140
const _SIID_MAX_ICONS = 175

type TOPEN_PRINTER_PROPS_INFOA = struct {
	FdwSize       TDWORD
	FpszSheetName TLPSTR
	FuSheetIndex  TUINT
	FdwFlags      TDWORD
	FbModal       TWINBOOL
}

type OPEN_PRINTER_PROPS_INFOA = TOPEN_PRINTER_PROPS_INFOA

type T_OPEN_PRINTER_PROPS_INFOA = TOPEN_PRINTER_PROPS_INFOA

type _OPEN_PRINTER_PROPS_INFOA = T_OPEN_PRINTER_PROPS_INFOA

type TPOPEN_PRINTER_PROPS_INFOA = uintptr

type POPEN_PRINTER_PROPS_INFOA = TPOPEN_PRINTER_PROPS_INFOA

type TOPEN_PRINTER_PROPS_INFOW = struct {
	FdwSize       TDWORD
	FpszSheetName TLPWSTR
	FuSheetIndex  TUINT
	FdwFlags      TDWORD
	FbModal       TWINBOOL
}

type OPEN_PRINTER_PROPS_INFOW = TOPEN_PRINTER_PROPS_INFOW

type T_OPEN_PRINTER_PROPS_INFOW = TOPEN_PRINTER_PROPS_INFOW

type _OPEN_PRINTER_PROPS_INFOW = T_OPEN_PRINTER_PROPS_INFOW

type TPOPEN_PRINTER_PROPS_INFOW = uintptr

type POPEN_PRINTER_PROPS_INFOW = TPOPEN_PRINTER_PROPS_INFOW

type TOPEN_PRINTER_PROPS_INFO = struct {
	FdwSize       TDWORD
	FpszSheetName TLPSTR
	FuSheetIndex  TUINT
	FdwFlags      TDWORD
	FbModal       TWINBOOL
}

type OPEN_PRINTER_PROPS_INFO = TOPEN_PRINTER_PROPS_INFO

type TPOPEN_PRINTER_PROPS_INFO = uintptr

type POPEN_PRINTER_PROPS_INFO = TPOPEN_PRINTER_PROPS_INFO

type TPFNCANSHAREFOLDERW = uintptr

type PFNCANSHAREFOLDERW = TPFNCANSHAREFOLDERW

type TPFNSHOWSHAREFOLDERUIW = uintptr

type PFNSHOWSHAREFOLDERUIW = TPFNSHOWSHAREFOLDERUIW

type TNC_ADDRESS = struct {
	FpAddrInfo    uintptr
	FPortNumber   TUSHORT
	FPrefixLength TBYTE
}

type NC_ADDRESS = TNC_ADDRESS

type TtagNC_ADDRESS = TNC_ADDRESS

type tagNC_ADDRESS = TtagNC_ADDRESS

type TPNC_ADDRESS = uintptr

type PNC_ADDRESS = TPNC_ADDRESS

type TPERF_DATA_BLOCK = struct {
	F__ccgo_align     [0]uint32
	FSignature        [4]TWCHAR
	FLittleEndian     TDWORD
	FVersion          TDWORD
	FRevision         TDWORD
	FTotalByteLength  TDWORD
	FHeaderLength     TDWORD
	FNumObjectTypes   TDWORD
	FDefaultObject    TLONG
	FSystemTime       TSYSTEMTIME
	F__ccgo_align9    [4]byte
	FPerfTime         TLARGE_INTEGER
	FPerfFreq         TLARGE_INTEGER
	FPerfTime100nSec  TLARGE_INTEGER
	FSystemNameLength TDWORD
	FSystemNameOffset TDWORD
}

type PERF_DATA_BLOCK = TPERF_DATA_BLOCK

type T_PERF_DATA_BLOCK = TPERF_DATA_BLOCK

type _PERF_DATA_BLOCK = T_PERF_DATA_BLOCK

type TPPERF_DATA_BLOCK = uintptr

type PPERF_DATA_BLOCK = TPPERF_DATA_BLOCK

type TPERF_OBJECT_TYPE = struct {
	F__ccgo_align         [0]uint32
	FTotalByteLength      TDWORD
	FDefinitionLength     TDWORD
	FHeaderLength         TDWORD
	FObjectNameTitleIndex TDWORD
	FObjectNameTitle      TLPWSTR
	FObjectHelpTitleIndex TDWORD
	FObjectHelpTitle      TLPWSTR
	FDetailLevel          TDWORD
	FNumCounters          TDWORD
	FDefaultCounter       TLONG
	FNumInstances         TLONG
	FCodePage             TDWORD
	FPerfTime             TLARGE_INTEGER
	FPerfFreq             TLARGE_INTEGER
}

type PERF_OBJECT_TYPE = TPERF_OBJECT_TYPE

type T_PERF_OBJECT_TYPE = TPERF_OBJECT_TYPE

type _PERF_OBJECT_TYPE = T_PERF_OBJECT_TYPE

type TPPERF_OBJECT_TYPE = uintptr

type PPERF_OBJECT_TYPE = TPPERF_OBJECT_TYPE

type TPERF_COUNTER_DEFINITION = struct {
	FByteLength            TDWORD
	FCounterNameTitleIndex TDWORD
	FCounterNameTitle      TLPWSTR
	FCounterHelpTitleIndex TDWORD
	FCounterHelpTitle      TLPWSTR
	FDefaultScale          TLONG
	FDetailLevel           TDWORD
	FCounterType           TDWORD
	FCounterSize           TDWORD
	FCounterOffset         TDWORD
}

type PERF_COUNTER_DEFINITION = TPERF_COUNTER_DEFINITION

type T_PERF_COUNTER_DEFINITION = TPERF_COUNTER_DEFINITION

type _PERF_COUNTER_DEFINITION = T_PERF_COUNTER_DEFINITION

type TPPERF_COUNTER_DEFINITION = uintptr

type PPERF_COUNTER_DEFINITION = TPPERF_COUNTER_DEFINITION

type TPERF_INSTANCE_DEFINITION = struct {
	FByteLength             TDWORD
	FParentObjectTitleIndex TDWORD
	FParentObjectInstance   TDWORD
	FUniqueID               TLONG
	FNameOffset             TDWORD
	FNameLength             TDWORD
}

type PERF_INSTANCE_DEFINITION = TPERF_INSTANCE_DEFINITION

type T_PERF_INSTANCE_DEFINITION = TPERF_INSTANCE_DEFINITION

type _PERF_INSTANCE_DEFINITION = T_PERF_INSTANCE_DEFINITION

type TPPERF_INSTANCE_DEFINITION = uintptr

type PPERF_INSTANCE_DEFINITION = TPPERF_INSTANCE_DEFINITION

type TPERF_COUNTER_BLOCK = struct {
	FByteLength TDWORD
}

type PERF_COUNTER_BLOCK = TPERF_COUNTER_BLOCK

type T_PERF_COUNTER_BLOCK = TPERF_COUNTER_BLOCK

type _PERF_COUNTER_BLOCK = T_PERF_COUNTER_BLOCK

type TPPERF_COUNTER_BLOCK = uintptr

type PPERF_COUNTER_BLOCK = TPPERF_COUNTER_BLOCK

type Tu_char = uint8

type u_char = Tu_char

type Tu_short = uint16

type u_short = Tu_short

type Tu_int = uint32

type u_int = Tu_int

type Tu_long = uint32

type u_long = Tu_long

type Tu_int64 = uint64

type u_int64 = Tu_int64

type TIN_ADDR = struct {
	FS_un struct {
		FS_un_w [0]struct {
			Fs_w1 Tu_short
			Fs_w2 Tu_short
		}
		FS_addr [0]Tu_long
		FS_un_b struct {
			Fs_b1 Tu_char
			Fs_b2 Tu_char
			Fs_b3 Tu_char
			Fs_b4 Tu_char
		}
	}
}

type IN_ADDR = TIN_ADDR

type Tin_addr = TIN_ADDR

type in_addr = Tin_addr

type TPIN_ADDR = uintptr

type PIN_ADDR = TPIN_ADDR

type TLPIN_ADDR = uintptr

type LPIN_ADDR = TLPIN_ADDR

type TSOCKET = uint32

type SOCKET = TSOCKET

type Tfd_set = struct {
	Ffd_count Tu_int
	Ffd_array [64]TSOCKET
}

type fd_set = Tfd_set

type TFD_SET = struct {
	Ffd_count Tu_int
	Ffd_array [64]TSOCKET
}

type FD_SET = TFD_SET

type Tfd_set1 = TFD_SET

type fd_set1 = Tfd_set1

type TPFD_SET = uintptr

type PFD_SET = TPFD_SET

type TLPFD_SET = uintptr

type LPFD_SET = TLPFD_SET

type Thostent = struct {
	Fh_name      uintptr
	Fh_aliases   uintptr
	Fh_addrtype  int16
	Fh_length    int16
	Fh_addr_list uintptr
}

type hostent = Thostent

type Tnetent = struct {
	Fn_name     uintptr
	Fn_aliases  uintptr
	Fn_addrtype int16
	Fn_net      Tu_long
}

type netent = Tnetent

type Tservent = struct {
	Fs_name    uintptr
	Fs_aliases uintptr
	Fs_port    int16
	Fs_proto   uintptr
}

type servent = Tservent

type Tprotoent = struct {
	Fp_name    uintptr
	Fp_aliases uintptr
	Fp_proto   int16
}

type protoent = Tprotoent

type Tsockproto = struct {
	Fsp_family   Tu_short
	Fsp_protocol Tu_short
}

type sockproto = Tsockproto

type Tlinger = struct {
	Fl_onoff  Tu_short
	Fl_linger Tu_short
}

type linger = Tlinger

type Tsockaddr = struct {
	Fsa_family Tu_short
	Fsa_data   [14]int8
}

type sockaddr = Tsockaddr

type Tsockaddr_in = struct {
	Fsin_family int16
	Fsin_port   Tu_short
	Fsin_addr   Tin_addr
	Fsin_zero   [8]int8
}

type sockaddr_in = Tsockaddr_in

type THOSTENT = struct {
	Fh_name      uintptr
	Fh_aliases   uintptr
	Fh_addrtype  int16
	Fh_length    int16
	Fh_addr_list uintptr
}

type HOSTENT = THOSTENT

type TPHOSTENT = uintptr

type PHOSTENT = TPHOSTENT

type TLPHOSTENT = uintptr

type LPHOSTENT = TLPHOSTENT

type TSERVENT = struct {
	Fs_name    uintptr
	Fs_aliases uintptr
	Fs_port    int16
	Fs_proto   uintptr
}

type SERVENT = TSERVENT

type TPSERVENT = uintptr

type PSERVENT = TPSERVENT

type TLPSERVENT = uintptr

type LPSERVENT = TLPSERVENT

type TPROTOENT = struct {
	Fp_name    uintptr
	Fp_aliases uintptr
	Fp_proto   int16
}

type PROTOENT = TPROTOENT

type TPPROTOENT = uintptr

type PPROTOENT = TPPROTOENT

type TLPPROTOENT = uintptr

type LPPROTOENT = TLPPROTOENT

type TSOCKADDR = struct {
	Fsa_family Tu_short
	Fsa_data   [14]int8
}

type SOCKADDR = TSOCKADDR

type TPSOCKADDR = uintptr

type PSOCKADDR = TPSOCKADDR

type TLPSOCKADDR = uintptr

type LPSOCKADDR = TLPSOCKADDR

type TSOCKADDR_IN = struct {
	Fsin_family int16
	Fsin_port   Tu_short
	Fsin_addr   Tin_addr
	Fsin_zero   [8]int8
}

type SOCKADDR_IN = TSOCKADDR_IN

type TPSOCKADDR_IN = uintptr

type PSOCKADDR_IN = TPSOCKADDR_IN

type TLPSOCKADDR_IN = uintptr

type LPSOCKADDR_IN = TLPSOCKADDR_IN

type TLINGER = struct {
	Fl_onoff  Tu_short
	Fl_linger Tu_short
}

type LINGER = TLINGER

type TPLINGER = uintptr

type PLINGER = TPLINGER

type TLPLINGER = uintptr

type LPLINGER = TLPLINGER

type TTIMEVAL = struct {
	Ftv_sec  int32
	Ftv_usec int32
}

type TIMEVAL = TTIMEVAL

type TPTIMEVAL = uintptr

type PTIMEVAL = TPTIMEVAL

type TLPTIMEVAL = uintptr

type LPTIMEVAL = TLPTIMEVAL

type TIP_MREQ = struct {
	Fimr_multiaddr Tin_addr
	Fimr_interface Tin_addr
}

type IP_MREQ = TIP_MREQ

type Tip_mreq = TIP_MREQ

type ip_mreq = Tip_mreq

type TPIP_MREQ = uintptr

type PIP_MREQ = TPIP_MREQ

type TWSADATA = struct {
	FwVersion       TWORD
	FwHighVersion   TWORD
	FszDescription  [257]int8
	FszSystemStatus [129]int8
	FiMaxSockets    uint16
	FiMaxUdpDg      uint16
	FlpVendorInfo   uintptr
}

type WSADATA = TWSADATA

type TWSAData = TWSADATA

type WSAData = TWSAData

type TLPWSADATA = uintptr

type LPWSADATA = TLPWSADATA

type TTRANSMIT_FILE_BUFFERS = struct {
	FHead       TLPVOID
	FHeadLength TDWORD
	FTail       TLPVOID
	FTailLength TDWORD
}

type TRANSMIT_FILE_BUFFERS = TTRANSMIT_FILE_BUFFERS

type T_TRANSMIT_FILE_BUFFERS = TTRANSMIT_FILE_BUFFERS

type _TRANSMIT_FILE_BUFFERS = T_TRANSMIT_FILE_BUFFERS

type TPTRANSMIT_FILE_BUFFERS = uintptr

type PTRANSMIT_FILE_BUFFERS = TPTRANSMIT_FILE_BUFFERS

type TLPTRANSMIT_FILE_BUFFERS = uintptr

type LPTRANSMIT_FILE_BUFFERS = TLPTRANSMIT_FILE_BUFFERS

type TALG_ID = uint32

type ALG_ID = TALG_ID

type THCRYPTHASH = uint32

type HCRYPTHASH = THCRYPTHASH

type THCRYPTKEY = uint32

type HCRYPTKEY = THCRYPTKEY

type THCRYPTPROV = uint32

type HCRYPTPROV = THCRYPTPROV

type TCMS_KEY_INFO = struct {
	FdwVersion TDWORD
	FAlgid     TALG_ID
	FpbOID     uintptr
	FcbOID     TDWORD
}

type CMS_KEY_INFO = TCMS_KEY_INFO

type T_CMS_KEY_INFO = TCMS_KEY_INFO

type _CMS_KEY_INFO = T_CMS_KEY_INFO

type TPCMS_KEY_INFO = uintptr

type PCMS_KEY_INFO = TPCMS_KEY_INFO

type THMAC_INFO = struct {
	FHashAlgid     TALG_ID
	FpbInnerString uintptr
	FcbInnerString TDWORD
	FpbOuterString uintptr
	FcbOuterString TDWORD
}

type HMAC_INFO = THMAC_INFO

type T_HMAC_Info = THMAC_INFO

type _HMAC_Info = T_HMAC_Info

type TPHMAC_INFO = uintptr

type PHMAC_INFO = TPHMAC_INFO

type TSCHANNEL_ALG = struct {
	FdwUse      TDWORD
	FAlgid      TALG_ID
	FcBits      TDWORD
	FdwFlags    TDWORD
	FdwReserved TDWORD
}

type SCHANNEL_ALG = TSCHANNEL_ALG

type T_SCHANNEL_ALG = TSCHANNEL_ALG

type _SCHANNEL_ALG = T_SCHANNEL_ALG

type TPSCHANNEL_ALG = uintptr

type PSCHANNEL_ALG = TPSCHANNEL_ALG

type TPROV_ENUMALGS = struct {
	FaiAlgid   TALG_ID
	FdwBitLen  TDWORD
	FdwNameLen TDWORD
	FszName    [20]TCHAR
}

type PROV_ENUMALGS = TPROV_ENUMALGS

type T_PROV_ENUMALGS = TPROV_ENUMALGS

type _PROV_ENUMALGS = T_PROV_ENUMALGS

type TPROV_ENUMALGS_EX = struct {
	FaiAlgid       TALG_ID
	FdwDefaultLen  TDWORD
	FdwMinLen      TDWORD
	FdwMaxLen      TDWORD
	FdwProtocols   TDWORD
	FdwNameLen     TDWORD
	FszName        [20]TCHAR
	FdwLongNameLen TDWORD
	FszLongName    [40]TCHAR
}

type PROV_ENUMALGS_EX = TPROV_ENUMALGS_EX

type T_PROV_ENUMALGS_EX = TPROV_ENUMALGS_EX

type _PROV_ENUMALGS_EX = T_PROV_ENUMALGS_EX

type TBLOBHEADER = struct {
	FbType    TBYTE
	FbVersion TBYTE
	Freserved TWORD
	FaiKeyAlg TALG_ID
}

type BLOBHEADER = TBLOBHEADER

type T_PUBLICKEYSTRUC = TBLOBHEADER

type _PUBLICKEYSTRUC = T_PUBLICKEYSTRUC

type TPUBLICKEYSTRUC = struct {
	FbType    TBYTE
	FbVersion TBYTE
	Freserved TWORD
	FaiKeyAlg TALG_ID
}

type PUBLICKEYSTRUC = TPUBLICKEYSTRUC

type TRSAPUBKEY = struct {
	Fmagic  TDWORD
	Fbitlen TDWORD
	Fpubexp TDWORD
}

type RSAPUBKEY = TRSAPUBKEY

type T_RSAPUBKEY = TRSAPUBKEY

type _RSAPUBKEY = T_RSAPUBKEY

type TDHPUBKEY = struct {
	Fmagic  TDWORD
	Fbitlen TDWORD
}

type DHPUBKEY = TDHPUBKEY

type T_PUBKEY = TDHPUBKEY

type _PUBKEY = T_PUBKEY

type TDSSPUBKEY = struct {
	Fmagic  TDWORD
	Fbitlen TDWORD
}

type DSSPUBKEY = TDSSPUBKEY

type TKEAPUBKEY = struct {
	Fmagic  TDWORD
	Fbitlen TDWORD
}

type KEAPUBKEY = TKEAPUBKEY

type TTEKPUBKEY = struct {
	Fmagic  TDWORD
	Fbitlen TDWORD
}

type TEKPUBKEY = TTEKPUBKEY

type TDSSSEED = struct {
	Fcounter TDWORD
	Fseed    [20]TBYTE
}

type DSSSEED = TDSSSEED

type T_DSSSEED = TDSSSEED

type _DSSSEED = T_DSSSEED

type TDHPUBKEY_VER3 = struct {
	Fmagic   TDWORD
	FbitlenP TDWORD
	FbitlenQ TDWORD
	FbitlenJ TDWORD
	FDSSSeed TDSSSEED
}

type DHPUBKEY_VER3 = TDHPUBKEY_VER3

type T_PUBKEYVER3 = TDHPUBKEY_VER3

type _PUBKEYVER3 = T_PUBKEYVER3

type TDSSPUBKEY_VER3 = struct {
	Fmagic   TDWORD
	FbitlenP TDWORD
	FbitlenQ TDWORD
	FbitlenJ TDWORD
	FDSSSeed TDSSSEED
}

type DSSPUBKEY_VER3 = TDSSPUBKEY_VER3

type TDHPRIVKEY_VER3 = struct {
	Fmagic   TDWORD
	FbitlenP TDWORD
	FbitlenQ TDWORD
	FbitlenJ TDWORD
	FbitlenX TDWORD
	FDSSSeed TDSSSEED
}

type DHPRIVKEY_VER3 = TDHPRIVKEY_VER3

type T_PRIVKEYVER3 = TDHPRIVKEY_VER3

type _PRIVKEYVER3 = T_PRIVKEYVER3

type TDSSPRIVKEY_VER3 = struct {
	Fmagic   TDWORD
	FbitlenP TDWORD
	FbitlenQ TDWORD
	FbitlenJ TDWORD
	FbitlenX TDWORD
	FDSSSeed TDSSSEED
}

type DSSPRIVKEY_VER3 = TDSSPRIVKEY_VER3

type TKEY_TYPE_SUBTYPE = struct {
	FdwKeySpec TDWORD
	FType      TGUID
	FSubtype   TGUID
}

type KEY_TYPE_SUBTYPE = TKEY_TYPE_SUBTYPE

type T_KEY_TYPE_SUBTYPE = TKEY_TYPE_SUBTYPE

type _KEY_TYPE_SUBTYPE = T_KEY_TYPE_SUBTYPE

type TPKEY_TYPE_SUBTYPE = uintptr

type PKEY_TYPE_SUBTYPE = TPKEY_TYPE_SUBTYPE

type TCERT_FORTEZZA_DATA_PROP = struct {
	FSerialNumber [8]uint8
	FCertIndex    int32
	FCertLabel    [36]uint8
}

type CERT_FORTEZZA_DATA_PROP = TCERT_FORTEZZA_DATA_PROP

type T_CERT_FORTEZZA_DATA_PROP = TCERT_FORTEZZA_DATA_PROP

type _CERT_FORTEZZA_DATA_PROP = T_CERT_FORTEZZA_DATA_PROP

type TCRYPT_RC4_KEY_STATE = struct {
	FKey  [16]uint8
	FSBox [256]uint8
	Fi    uint8
	Fj    uint8
}

type CRYPT_RC4_KEY_STATE = TCRYPT_RC4_KEY_STATE

type T_CRYPT_RC4_KEY_STATE = TCRYPT_RC4_KEY_STATE

type _CRYPT_RC4_KEY_STATE = T_CRYPT_RC4_KEY_STATE

type TPCRYPT_RC4_KEY_STATE = uintptr

type PCRYPT_RC4_KEY_STATE = TPCRYPT_RC4_KEY_STATE

type TCRYPT_DES_KEY_STATE = struct {
	FKey      [8]uint8
	FIV       [8]uint8
	FFeedback [8]uint8
}

type CRYPT_DES_KEY_STATE = TCRYPT_DES_KEY_STATE

type T_CRYPT_DES_KEY_STATE = TCRYPT_DES_KEY_STATE

type _CRYPT_DES_KEY_STATE = T_CRYPT_DES_KEY_STATE

type TPCRYPT_DES_KEY_STATE = uintptr

type PCRYPT_DES_KEY_STATE = TPCRYPT_DES_KEY_STATE

type TCRYPT_3DES_KEY_STATE = struct {
	FKey      [24]uint8
	FIV       [8]uint8
	FFeedback [8]uint8
}

type CRYPT_3DES_KEY_STATE = TCRYPT_3DES_KEY_STATE

type T_CRYPT_3DES_KEY_STATE = TCRYPT_3DES_KEY_STATE

type _CRYPT_3DES_KEY_STATE = T_CRYPT_3DES_KEY_STATE

type TPCRYPT_3DES_KEY_STATE = uintptr

type PCRYPT_3DES_KEY_STATE = TPCRYPT_3DES_KEY_STATE

type TCRYPT_AES_128_KEY_STATE = struct {
	FKey             [16]uint8
	FIV              [16]uint8
	FEncryptionState [11][16]uint8
	FDecryptionState [11][16]uint8
	FFeedback        [16]uint8
}

type CRYPT_AES_128_KEY_STATE = TCRYPT_AES_128_KEY_STATE

type T_CRYPT_AES_128_KEY_STATE = TCRYPT_AES_128_KEY_STATE

type _CRYPT_AES_128_KEY_STATE = T_CRYPT_AES_128_KEY_STATE

type TPCRYPT_AES_128_KEY_STATE = uintptr

type PCRYPT_AES_128_KEY_STATE = TPCRYPT_AES_128_KEY_STATE

type TCRYPT_AES_256_KEY_STATE = struct {
	FKey             [32]uint8
	FIV              [16]uint8
	FEncryptionState [15][16]uint8
	FDecryptionState [15][16]uint8
	FFeedback        [16]uint8
}

type CRYPT_AES_256_KEY_STATE = TCRYPT_AES_256_KEY_STATE

type T_CRYPT_AES_256_KEY_STATE = TCRYPT_AES_256_KEY_STATE

type _CRYPT_AES_256_KEY_STATE = T_CRYPT_AES_256_KEY_STATE

type TPCRYPT_AES_256_KEY_STATE = uintptr

type PCRYPT_AES_256_KEY_STATE = TPCRYPT_AES_256_KEY_STATE

type TCRYPT_INTEGER_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_INTEGER_BLOB = TCRYPT_INTEGER_BLOB

type T_CRYPTOAPI_BLOB = TCRYPT_INTEGER_BLOB

type _CRYPTOAPI_BLOB = T_CRYPTOAPI_BLOB

type TPCRYPT_INTEGER_BLOB = uintptr

type PCRYPT_INTEGER_BLOB = TPCRYPT_INTEGER_BLOB

type TCRYPT_UINT_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_UINT_BLOB = TCRYPT_UINT_BLOB

type TPCRYPT_UINT_BLOB = uintptr

type PCRYPT_UINT_BLOB = TPCRYPT_UINT_BLOB

type TCRYPT_OBJID_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_OBJID_BLOB = TCRYPT_OBJID_BLOB

type TPCRYPT_OBJID_BLOB = uintptr

type PCRYPT_OBJID_BLOB = TPCRYPT_OBJID_BLOB

type TCERT_NAME_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CERT_NAME_BLOB = TCERT_NAME_BLOB

type TPCERT_NAME_BLOB = uintptr

type PCERT_NAME_BLOB = TPCERT_NAME_BLOB

type TCERT_RDN_VALUE_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CERT_RDN_VALUE_BLOB = TCERT_RDN_VALUE_BLOB

type TPCERT_RDN_VALUE_BLOB = uintptr

type PCERT_RDN_VALUE_BLOB = TPCERT_RDN_VALUE_BLOB

type TCERT_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CERT_BLOB = TCERT_BLOB

type TPCERT_BLOB = uintptr

type PCERT_BLOB = TPCERT_BLOB

type TCRL_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRL_BLOB = TCRL_BLOB

type TPCRL_BLOB = uintptr

type PCRL_BLOB = TPCRL_BLOB

type TDATA_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type DATA_BLOB = TDATA_BLOB

type TPDATA_BLOB = uintptr

type PDATA_BLOB = TPDATA_BLOB

type TCRYPT_DATA_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_DATA_BLOB = TCRYPT_DATA_BLOB

type TPCRYPT_DATA_BLOB = uintptr

type PCRYPT_DATA_BLOB = TPCRYPT_DATA_BLOB

type TCRYPT_HASH_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_HASH_BLOB = TCRYPT_HASH_BLOB

type TPCRYPT_HASH_BLOB = uintptr

type PCRYPT_HASH_BLOB = TPCRYPT_HASH_BLOB

type TCRYPT_DIGEST_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_DIGEST_BLOB = TCRYPT_DIGEST_BLOB

type TPCRYPT_DIGEST_BLOB = uintptr

type PCRYPT_DIGEST_BLOB = TPCRYPT_DIGEST_BLOB

type TCRYPT_DER_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_DER_BLOB = TCRYPT_DER_BLOB

type TPCRYPT_DER_BLOB = uintptr

type PCRYPT_DER_BLOB = TPCRYPT_DER_BLOB

type TCRYPT_ATTR_BLOB = struct {
	FcbData TDWORD
	FpbData uintptr
}

type CRYPT_ATTR_BLOB = TCRYPT_ATTR_BLOB

type TPCRYPT_ATTR_BLOB = uintptr

type PCRYPT_ATTR_BLOB = TPCRYPT_ATTR_BLOB

type TCMS_DH_KEY_INFO = struct {
	FdwVersion          TDWORD
	FAlgid              TALG_ID
	FpszContentEncObjId TLPSTR
	FPubInfo            TCRYPT_DATA_BLOB
	FpReserved          uintptr
}

type CMS_DH_KEY_INFO = TCMS_DH_KEY_INFO

type T_CMS_DH_KEY_INFO = TCMS_DH_KEY_INFO

type _CMS_DH_KEY_INFO = T_CMS_DH_KEY_INFO

type TPCMS_DH_KEY_INFO = uintptr

type PCMS_DH_KEY_INFO = TPCMS_DH_KEY_INFO

type THCRYPTPROV_OR_NCRYPT_KEY_HANDLE = uint32

type HCRYPTPROV_OR_NCRYPT_KEY_HANDLE = THCRYPTPROV_OR_NCRYPT_KEY_HANDLE

type THCRYPTPROV_LEGACY = uint32

type HCRYPTPROV_LEGACY = THCRYPTPROV_LEGACY

type TNTSTATUS = int32

type NTSTATUS = TNTSTATUS

type TPNTSTATUS = uintptr

type PNTSTATUS = TPNTSTATUS

type TBCRYPT_KEY_LENGTHS_STRUCT = struct {
	FdwMinLength TULONG
	FdwMaxLength TULONG
	FdwIncrement TULONG
}

type BCRYPT_KEY_LENGTHS_STRUCT = TBCRYPT_KEY_LENGTHS_STRUCT

type t__BCRYPT_KEY_LENGTHS_STRUCT = TBCRYPT_KEY_LENGTHS_STRUCT

type TBCRYPT_AUTH_TAG_LENGTHS_STRUCT = struct {
	FdwMinLength TULONG
	FdwMaxLength TULONG
	FdwIncrement TULONG
}

type BCRYPT_AUTH_TAG_LENGTHS_STRUCT = TBCRYPT_AUTH_TAG_LENGTHS_STRUCT

type TBCRYPT_OID = struct {
	FcbOID TULONG
	FpbOID TPUCHAR
}

type BCRYPT_OID = TBCRYPT_OID

type T_BCRYPT_OID = TBCRYPT_OID

type _BCRYPT_OID = T_BCRYPT_OID

type TBCRYPT_OID_LIST = struct {
	FdwOIDCount TULONG
	FpOIDs      uintptr
}

type BCRYPT_OID_LIST = TBCRYPT_OID_LIST

type T_BCRYPT_OID_LIST = TBCRYPT_OID_LIST

type _BCRYPT_OID_LIST = T_BCRYPT_OID_LIST

type TBCRYPT_PKCS1_PADDING_INFO = struct {
	FpszAlgId TLPCWSTR
}

type BCRYPT_PKCS1_PADDING_INFO = TBCRYPT_PKCS1_PADDING_INFO

type T_BCRYPT_PKCS1_PADDING_INFO = TBCRYPT_PKCS1_PADDING_INFO

type _BCRYPT_PKCS1_PADDING_INFO = T_BCRYPT_PKCS1_PADDING_INFO

type TBCRYPT_PSS_PADDING_INFO = struct {
	FpszAlgId TLPCWSTR
	FcbSalt   TULONG
}

type BCRYPT_PSS_PADDING_INFO = TBCRYPT_PSS_PADDING_INFO

type T_BCRYPT_PSS_PADDING_INFO = TBCRYPT_PSS_PADDING_INFO

type _BCRYPT_PSS_PADDING_INFO = T_BCRYPT_PSS_PADDING_INFO

type TBCRYPT_OAEP_PADDING_INFO = struct {
	FpszAlgId TLPCWSTR
	FpbLabel  TPUCHAR
	FcbLabel  TULONG
}

type BCRYPT_OAEP_PADDING_INFO = TBCRYPT_OAEP_PADDING_INFO

type T_BCRYPT_OAEP_PADDING_INFO = TBCRYPT_OAEP_PADDING_INFO

type _BCRYPT_OAEP_PADDING_INFO = T_BCRYPT_OAEP_PADDING_INFO

type TBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = struct {
	F__ccgo_align   [0]uint32
	FcbSize         TULONG
	FdwInfoVersion  TULONG
	FpbNonce        TPUCHAR
	FcbNonce        TULONG
	FpbAuthData     TPUCHAR
	FcbAuthData     TULONG
	FpbTag          TPUCHAR
	FcbTag          TULONG
	FpbMacContext   TPUCHAR
	FcbMacContext   TULONG
	FcbAAD          TULONG
	F__ccgo_align11 [4]byte
	FcbData         TULONGLONG
	FdwFlags        TULONG
	F__ccgo_pad13   [4]byte
}

type BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = TBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO

type T_BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = TBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO

type _BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = T_BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO

type TPBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = uintptr

type PBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = TPBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO

type TBCryptBuffer = struct {
	FcbBuffer   TULONG
	FBufferType TULONG
	FpvBuffer   TPVOID
}

type BCryptBuffer = TBCryptBuffer

type T_BCryptBuffer = TBCryptBuffer

type _BCryptBuffer = T_BCryptBuffer

type TPBCryptBuffer = uintptr

type PBCryptBuffer = TPBCryptBuffer

type TBCryptBufferDesc = struct {
	FulVersion TULONG
	FcBuffers  TULONG
	FpBuffers  TPBCryptBuffer
}

type BCryptBufferDesc = TBCryptBufferDesc

type T_BCryptBufferDesc = TBCryptBufferDesc

type _BCryptBufferDesc = T_BCryptBufferDesc

type TPBCryptBufferDesc = uintptr

type PBCryptBufferDesc = TPBCryptBufferDesc

type TBCRYPT_HANDLE = uintptr

type BCRYPT_HANDLE = TBCRYPT_HANDLE

type TBCRYPT_ALG_HANDLE = uintptr

type BCRYPT_ALG_HANDLE = TBCRYPT_ALG_HANDLE

type TBCRYPT_KEY_HANDLE = uintptr

type BCRYPT_KEY_HANDLE = TBCRYPT_KEY_HANDLE

type TBCRYPT_HASH_HANDLE = uintptr

type BCRYPT_HASH_HANDLE = TBCRYPT_HASH_HANDLE

type TBCRYPT_SECRET_HANDLE = uintptr

type BCRYPT_SECRET_HANDLE = TBCRYPT_SECRET_HANDLE

type TBCRYPT_KEY_BLOB = struct {
	FMagic TULONG
}

type BCRYPT_KEY_BLOB = TBCRYPT_KEY_BLOB

type T_BCRYPT_KEY_BLOB = TBCRYPT_KEY_BLOB

type _BCRYPT_KEY_BLOB = T_BCRYPT_KEY_BLOB

type TBCRYPT_RSAKEY_BLOB = struct {
	FMagic       TULONG
	FBitLength   TULONG
	FcbPublicExp TULONG
	FcbModulus   TULONG
	FcbPrime1    TULONG
	FcbPrime2    TULONG
}

type BCRYPT_RSAKEY_BLOB = TBCRYPT_RSAKEY_BLOB

type T_BCRYPT_RSAKEY_BLOB = TBCRYPT_RSAKEY_BLOB

type _BCRYPT_RSAKEY_BLOB = T_BCRYPT_RSAKEY_BLOB

type TBCRYPT_ECCKEY_BLOB = struct {
	FdwMagic TULONG
	FcbKey   TULONG
}

type BCRYPT_ECCKEY_BLOB = TBCRYPT_ECCKEY_BLOB

type T_BCRYPT_ECCKEY_BLOB = TBCRYPT_ECCKEY_BLOB

type _BCRYPT_ECCKEY_BLOB = T_BCRYPT_ECCKEY_BLOB

type TPBCRYPT_ECCKEY_BLOB = uintptr

type PBCRYPT_ECCKEY_BLOB = TPBCRYPT_ECCKEY_BLOB

type TBCRYPT_DH_KEY_BLOB = struct {
	FdwMagic TULONG
	FcbKey   TULONG
}

type BCRYPT_DH_KEY_BLOB = TBCRYPT_DH_KEY_BLOB

type T_BCRYPT_DH_KEY_BLOB = TBCRYPT_DH_KEY_BLOB

type _BCRYPT_DH_KEY_BLOB = T_BCRYPT_DH_KEY_BLOB

type TPBCRYPT_DH_KEY_BLOB = uintptr

type PBCRYPT_DH_KEY_BLOB = TPBCRYPT_DH_KEY_BLOB

type TBCRYPT_DH_PARAMETER_HEADER = struct {
	FcbLength    TULONG
	FdwMagic     TULONG
	FcbKeyLength TULONG
}

type BCRYPT_DH_PARAMETER_HEADER = TBCRYPT_DH_PARAMETER_HEADER

type T_BCRYPT_DH_PARAMETER_HEADER = TBCRYPT_DH_PARAMETER_HEADER

type _BCRYPT_DH_PARAMETER_HEADER = T_BCRYPT_DH_PARAMETER_HEADER

type TBCRYPT_DSA_KEY_BLOB = struct {
	FdwMagic TULONG
	FcbKey   TULONG
	FCount   [4]TUCHAR
	FSeed    [20]TUCHAR
	Fq       [20]TUCHAR
}

type BCRYPT_DSA_KEY_BLOB = TBCRYPT_DSA_KEY_BLOB

type T_BCRYPT_DSA_KEY_BLOB = TBCRYPT_DSA_KEY_BLOB

type _BCRYPT_DSA_KEY_BLOB = T_BCRYPT_DSA_KEY_BLOB

type TPBCRYPT_DSA_KEY_BLOB = uintptr

type PBCRYPT_DSA_KEY_BLOB = TPBCRYPT_DSA_KEY_BLOB

type THASHALGORITHM_ENUM = int32

type HASHALGORITHM_ENUM = THASHALGORITHM_ENUM

const _DSA_HASH_ALGORITHM_SHA1 = 0
const _DSA_HASH_ALGORITHM_SHA256 = 1
const _DSA_HASH_ALGORITHM_SHA512 = 2

type TDSAFIPSVERSION_ENUM = int32

type DSAFIPSVERSION_ENUM = TDSAFIPSVERSION_ENUM

const _DSA_FIPS186_2 = 0
const _DSA_FIPS186_3 = 1

type TBCRYPT_DSA_KEY_BLOB_V2 = struct {
	FdwMagic         TULONG
	FcbKey           TULONG
	FhashAlgorithm   THASHALGORITHM_ENUM
	FstandardVersion TDSAFIPSVERSION_ENUM
	FcbSeedLength    TULONG
	FcbGroupSize     TULONG
	FCount           [4]TUCHAR
}

type BCRYPT_DSA_KEY_BLOB_V2 = TBCRYPT_DSA_KEY_BLOB_V2

type T_BCRYPT_DSA_KEY_BLOB_V2 = TBCRYPT_DSA_KEY_BLOB_V2

type _BCRYPT_DSA_KEY_BLOB_V2 = T_BCRYPT_DSA_KEY_BLOB_V2

type TPBCRYPT_DSA_KEY_BLOB_V2 = uintptr

type PBCRYPT_DSA_KEY_BLOB_V2 = TPBCRYPT_DSA_KEY_BLOB_V2

type TBCRYPT_KEY_DATA_BLOB_HEADER = struct {
	FdwMagic   TULONG
	FdwVersion TULONG
	FcbKeyData TULONG
}

type BCRYPT_KEY_DATA_BLOB_HEADER = TBCRYPT_KEY_DATA_BLOB_HEADER

type T_BCRYPT_KEY_DATA_BLOB_HEADER = TBCRYPT_KEY_DATA_BLOB_HEADER

type _BCRYPT_KEY_DATA_BLOB_HEADER = T_BCRYPT_KEY_DATA_BLOB_HEADER

type TPBCRYPT_KEY_DATA_BLOB_HEADER = uintptr

type PBCRYPT_KEY_DATA_BLOB_HEADER = TPBCRYPT_KEY_DATA_BLOB_HEADER

type TBCRYPT_DSA_PARAMETER_HEADER = struct {
	FcbLength    TULONG
	FdwMagic     TULONG
	FcbKeyLength TULONG
	FCount       [4]TUCHAR
	FSeed        [20]TUCHAR
	Fq           [20]TUCHAR
}

type BCRYPT_DSA_PARAMETER_HEADER = TBCRYPT_DSA_PARAMETER_HEADER

type T_BCRYPT_DSA_PARAMETER_HEADER = TBCRYPT_DSA_PARAMETER_HEADER

type _BCRYPT_DSA_PARAMETER_HEADER = T_BCRYPT_DSA_PARAMETER_HEADER

type TBCRYPT_DSA_PARAMETER_HEADER_V2 = struct {
	FcbLength        TULONG
	FdwMagic         TULONG
	FcbKeyLength     TULONG
	FhashAlgorithm   THASHALGORITHM_ENUM
	FstandardVersion TDSAFIPSVERSION_ENUM
	FcbSeedLength    TULONG
	FcbGroupSize     TULONG
	FCount           [4]TUCHAR
}

type BCRYPT_DSA_PARAMETER_HEADER_V2 = TBCRYPT_DSA_PARAMETER_HEADER_V2

type T_BCRYPT_DSA_PARAMETER_HEADER_V2 = TBCRYPT_DSA_PARAMETER_HEADER_V2

type _BCRYPT_DSA_PARAMETER_HEADER_V2 = T_BCRYPT_DSA_PARAMETER_HEADER_V2

type TBCRYPT_ECC_CURVE_NAMES = struct {
	FdwEccCurveNames TULONG
	FpEccCurveNames  uintptr
}

type BCRYPT_ECC_CURVE_NAMES = TBCRYPT_ECC_CURVE_NAMES

type T_BCRYPT_ECC_CURVE_NAMES = TBCRYPT_ECC_CURVE_NAMES

type _BCRYPT_ECC_CURVE_NAMES = T_BCRYPT_ECC_CURVE_NAMES

type TBCRYPT_HASH_OPERATION_TYPE = int32

type BCRYPT_HASH_OPERATION_TYPE = TBCRYPT_HASH_OPERATION_TYPE

const _BCRYPT_HASH_OPERATION_HASH_DATA = 1
const _BCRYPT_HASH_OPERATION_FINISH_HASH = 2

type TBCRYPT_MULTI_HASH_OPERATION = struct {
	FiHash         TULONG
	FhashOperation TBCRYPT_HASH_OPERATION_TYPE
	FpbBuffer      TPUCHAR
	FcbBuffer      TULONG
}

type BCRYPT_MULTI_HASH_OPERATION = TBCRYPT_MULTI_HASH_OPERATION

type T_BCRYPT_MULTI_HASH_OPERATION = TBCRYPT_MULTI_HASH_OPERATION

type _BCRYPT_MULTI_HASH_OPERATION = T_BCRYPT_MULTI_HASH_OPERATION

type TBCRYPT_MULTI_OPERATION_TYPE = int32

type BCRYPT_MULTI_OPERATION_TYPE = TBCRYPT_MULTI_OPERATION_TYPE

const _BCRYPT_OPERATION_TYPE_HASH = 1

type TBCRYPT_MULTI_OBJECT_LENGTH_STRUCT = struct {
	FcbPerObject  TULONG
	FcbPerElement TULONG
}

type BCRYPT_MULTI_OBJECT_LENGTH_STRUCT = TBCRYPT_MULTI_OBJECT_LENGTH_STRUCT

type T_BCRYPT_MULTI_OBJECT_LENGTH_STRUCT = TBCRYPT_MULTI_OBJECT_LENGTH_STRUCT

type _BCRYPT_MULTI_OBJECT_LENGTH_STRUCT = T_BCRYPT_MULTI_OBJECT_LENGTH_STRUCT

type TBCRYPT_ALGORITHM_IDENTIFIER = struct {
	FpszName TLPWSTR
	FdwClass TULONG
	FdwFlags TULONG
}

type BCRYPT_ALGORITHM_IDENTIFIER = TBCRYPT_ALGORITHM_IDENTIFIER

type T_BCRYPT_ALGORITHM_IDENTIFIER = TBCRYPT_ALGORITHM_IDENTIFIER

type _BCRYPT_ALGORITHM_IDENTIFIER = T_BCRYPT_ALGORITHM_IDENTIFIER

type TBCRYPT_PROVIDER_NAME = struct {
	FpszProviderName TLPWSTR
}

type BCRYPT_PROVIDER_NAME = TBCRYPT_PROVIDER_NAME

type T_BCRYPT_PROVIDER_NAME = TBCRYPT_PROVIDER_NAME

type _BCRYPT_PROVIDER_NAME = T_BCRYPT_PROVIDER_NAME

type TBCRYPT_INTERFACE_VERSION = struct {
	FMajorVersion TUSHORT
	FMinorVersion TUSHORT
}

type BCRYPT_INTERFACE_VERSION = TBCRYPT_INTERFACE_VERSION

type T_BCRYPT_INTERFACE_VERSION = TBCRYPT_INTERFACE_VERSION

type _BCRYPT_INTERFACE_VERSION = T_BCRYPT_INTERFACE_VERSION

type TPBCRYPT_INTERFACE_VERSION = uintptr

type PBCRYPT_INTERFACE_VERSION = TPBCRYPT_INTERFACE_VERSION

type TCRYPT_INTERFACE_REG = struct {
	FdwInterface    TULONG
	FdwFlags        TULONG
	FcFunctions     TULONG
	FrgpszFunctions uintptr
}

type CRYPT_INTERFACE_REG = TCRYPT_INTERFACE_REG

type T_CRYPT_INTERFACE_REG = TCRYPT_INTERFACE_REG

type _CRYPT_INTERFACE_REG = T_CRYPT_INTERFACE_REG

type TPCRYPT_INTERFACE_REG = uintptr

type PCRYPT_INTERFACE_REG = TPCRYPT_INTERFACE_REG

type TCRYPT_IMAGE_REG = struct {
	FpszImage      TPWSTR
	FcInterfaces   TULONG
	FrgpInterfaces uintptr
}

type CRYPT_IMAGE_REG = TCRYPT_IMAGE_REG

type T_CRYPT_IMAGE_REG = TCRYPT_IMAGE_REG

type _CRYPT_IMAGE_REG = T_CRYPT_IMAGE_REG

type TPCRYPT_IMAGE_REG = uintptr

type PCRYPT_IMAGE_REG = TPCRYPT_IMAGE_REG

type TCRYPT_PROVIDER_REG = struct {
	FcAliases     TULONG
	FrgpszAliases uintptr
	FpUM          TPCRYPT_IMAGE_REG
	FpKM          TPCRYPT_IMAGE_REG
}

type CRYPT_PROVIDER_REG = TCRYPT_PROVIDER_REG

type T_CRYPT_PROVIDER_REG = TCRYPT_PROVIDER_REG

type _CRYPT_PROVIDER_REG = T_CRYPT_PROVIDER_REG

type TPCRYPT_PROVIDER_REG = uintptr

type PCRYPT_PROVIDER_REG = TPCRYPT_PROVIDER_REG

type TCRYPT_PROVIDERS = struct {
	FcProviders     TULONG
	FrgpszProviders uintptr
}

type CRYPT_PROVIDERS = TCRYPT_PROVIDERS

type T_CRYPT_PROVIDERS = TCRYPT_PROVIDERS

type _CRYPT_PROVIDERS = T_CRYPT_PROVIDERS

type TPCRYPT_PROVIDERS = uintptr

type PCRYPT_PROVIDERS = TPCRYPT_PROVIDERS

type TCRYPT_CONTEXT_CONFIG = struct {
	FdwFlags    TULONG
	FdwReserved TULONG
}

type CRYPT_CONTEXT_CONFIG = TCRYPT_CONTEXT_CONFIG

type T_CRYPT_CONTEXT_CONFIG = TCRYPT_CONTEXT_CONFIG

type _CRYPT_CONTEXT_CONFIG = T_CRYPT_CONTEXT_CONFIG

type TPCRYPT_CONTEXT_CONFIG = uintptr

type PCRYPT_CONTEXT_CONFIG = TPCRYPT_CONTEXT_CONFIG

type TCRYPT_CONTEXT_FUNCTION_CONFIG = struct {
	FdwFlags    TULONG
	FdwReserved TULONG
}

type CRYPT_CONTEXT_FUNCTION_CONFIG = TCRYPT_CONTEXT_FUNCTION_CONFIG

type T_CRYPT_CONTEXT_FUNCTION_CONFIG = TCRYPT_CONTEXT_FUNCTION_CONFIG

type _CRYPT_CONTEXT_FUNCTION_CONFIG = T_CRYPT_CONTEXT_FUNCTION_CONFIG

type TPCRYPT_CONTEXT_FUNCTION_CONFIG = uintptr

type PCRYPT_CONTEXT_FUNCTION_CONFIG = TPCRYPT_CONTEXT_FUNCTION_CONFIG

type TCRYPT_CONTEXTS = struct {
	FcContexts     TULONG
	FrgpszContexts uintptr
}

type CRYPT_CONTEXTS = TCRYPT_CONTEXTS

type T_CRYPT_CONTEXTS = TCRYPT_CONTEXTS

type _CRYPT_CONTEXTS = T_CRYPT_CONTEXTS

type TPCRYPT_CONTEXTS = uintptr

type PCRYPT_CONTEXTS = TPCRYPT_CONTEXTS

type TCRYPT_CONTEXT_FUNCTIONS = struct {
	FcFunctions     TULONG
	FrgpszFunctions uintptr
}

type CRYPT_CONTEXT_FUNCTIONS = TCRYPT_CONTEXT_FUNCTIONS

type T_CRYPT_CONTEXT_FUNCTIONS = TCRYPT_CONTEXT_FUNCTIONS

type _CRYPT_CONTEXT_FUNCTIONS = T_CRYPT_CONTEXT_FUNCTIONS

type TPCRYPT_CONTEXT_FUNCTIONS = uintptr

type PCRYPT_CONTEXT_FUNCTIONS = TPCRYPT_CONTEXT_FUNCTIONS

type TCRYPT_CONTEXT_FUNCTION_PROVIDERS = struct {
	FcProviders     TULONG
	FrgpszProviders uintptr
}

type CRYPT_CONTEXT_FUNCTION_PROVIDERS = TCRYPT_CONTEXT_FUNCTION_PROVIDERS

type T_CRYPT_CONTEXT_FUNCTION_PROVIDERS = TCRYPT_CONTEXT_FUNCTION_PROVIDERS

type _CRYPT_CONTEXT_FUNCTION_PROVIDERS = T_CRYPT_CONTEXT_FUNCTION_PROVIDERS

type TPCRYPT_CONTEXT_FUNCTION_PROVIDERS = uintptr

type PCRYPT_CONTEXT_FUNCTION_PROVIDERS = TPCRYPT_CONTEXT_FUNCTION_PROVIDERS

type TCRYPT_PROPERTY_REF = struct {
	FpszProperty TPWSTR
	FcbValue     TULONG
	FpbValue     TPUCHAR
}

type CRYPT_PROPERTY_REF = TCRYPT_PROPERTY_REF

type T_CRYPT_PROPERTY_REF = TCRYPT_PROPERTY_REF

type _CRYPT_PROPERTY_REF = T_CRYPT_PROPERTY_REF

type TPCRYPT_PROPERTY_REF = uintptr

type PCRYPT_PROPERTY_REF = TPCRYPT_PROPERTY_REF

type TCRYPT_IMAGE_REF = struct {
	FpszImage TPWSTR
	FdwFlags  TULONG
}

type CRYPT_IMAGE_REF = TCRYPT_IMAGE_REF

type T_CRYPT_IMAGE_REF = TCRYPT_IMAGE_REF

type _CRYPT_IMAGE_REF = T_CRYPT_IMAGE_REF

type TPCRYPT_IMAGE_REF = uintptr

type PCRYPT_IMAGE_REF = TPCRYPT_IMAGE_REF

type TCRYPT_PROVIDER_REF = struct {
	FdwInterface   TULONG
	FpszFunction   TPWSTR
	FpszProvider   TPWSTR
	FcProperties   TULONG
	FrgpProperties uintptr
	FpUM           TPCRYPT_IMAGE_REF
	FpKM           TPCRYPT_IMAGE_REF
}

type CRYPT_PROVIDER_REF = TCRYPT_PROVIDER_REF

type T_CRYPT_PROVIDER_REF = TCRYPT_PROVIDER_REF

type _CRYPT_PROVIDER_REF = T_CRYPT_PROVIDER_REF

type TPCRYPT_PROVIDER_REF = uintptr

type PCRYPT_PROVIDER_REF = TPCRYPT_PROVIDER_REF

type TCRYPT_PROVIDER_REFS = struct {
	FcProviders   TULONG
	FrgpProviders uintptr
}

type CRYPT_PROVIDER_REFS = TCRYPT_PROVIDER_REFS

type T_CRYPT_PROVIDER_REFS = TCRYPT_PROVIDER_REFS

type _CRYPT_PROVIDER_REFS = T_CRYPT_PROVIDER_REFS

type TPCRYPT_PROVIDER_REFS = uintptr

type PCRYPT_PROVIDER_REFS = TPCRYPT_PROVIDER_REFS

type TSECURITY_STATUS = int32

type SECURITY_STATUS = TSECURITY_STATUS

type TPFN_NCRYPT_ALLOC = uintptr

type PFN_NCRYPT_ALLOC = TPFN_NCRYPT_ALLOC

type TPFN_NCRYPT_FREE = uintptr

type PFN_NCRYPT_FREE = TPFN_NCRYPT_FREE

type TNCRYPT_ALLOC_PARA = struct {
	FcbSize   TDWORD
	FpfnAlloc TPFN_NCRYPT_ALLOC
	FpfnFree  TPFN_NCRYPT_FREE
}

type NCRYPT_ALLOC_PARA = TNCRYPT_ALLOC_PARA

type TNCryptBuffer = struct {
	FcbBuffer   TULONG
	FBufferType TULONG
	FpvBuffer   TPVOID
}

type NCryptBuffer = TNCryptBuffer

type TPNCryptBuffer = uintptr

type PNCryptBuffer = TPNCryptBuffer

type TNCryptBufferDesc = struct {
	FulVersion TULONG
	FcBuffers  TULONG
	FpBuffers  TPBCryptBuffer
}

type NCryptBufferDesc = TNCryptBufferDesc

type TPNCryptBufferDesc = uintptr

type PNCryptBufferDesc = TPNCryptBufferDesc

type TNCRYPT_HANDLE = uint32

type NCRYPT_HANDLE = TNCRYPT_HANDLE

type TNCRYPT_PROV_HANDLE = uint32

type NCRYPT_PROV_HANDLE = TNCRYPT_PROV_HANDLE

type TNCRYPT_KEY_HANDLE = uint32

type NCRYPT_KEY_HANDLE = TNCRYPT_KEY_HANDLE

type TNCRYPT_HASH_HANDLE = uint32

type NCRYPT_HASH_HANDLE = TNCRYPT_HASH_HANDLE

type TNCRYPT_SECRET_HANDLE = uint32

type NCRYPT_SECRET_HANDLE = TNCRYPT_SECRET_HANDLE

type TNCRYPT_CIPHER_PADDING_INFO = struct {
	FcbSize      TULONG
	FdwFlags     TDWORD
	FpbIV        TPUCHAR
	FcbIV        TULONG
	FpbOtherInfo TPUCHAR
	FcbOtherInfo TULONG
}

type NCRYPT_CIPHER_PADDING_INFO = TNCRYPT_CIPHER_PADDING_INFO

type T_NCRYPT_CIPHER_PADDING_INFO = TNCRYPT_CIPHER_PADDING_INFO

type _NCRYPT_CIPHER_PADDING_INFO = T_NCRYPT_CIPHER_PADDING_INFO

type TPNCRYPT_CIPHER_PADDING_INFO = uintptr

type PNCRYPT_CIPHER_PADDING_INFO = TPNCRYPT_CIPHER_PADDING_INFO

type TNCryptAlgorithmName = struct {
	FpszName         TLPWSTR
	FdwClass         TDWORD
	FdwAlgOperations TDWORD
	FdwFlags         TDWORD
}

type NCryptAlgorithmName = TNCryptAlgorithmName

type T_NCryptAlgorithmName = TNCryptAlgorithmName

type _NCryptAlgorithmName = T_NCryptAlgorithmName

type TNCryptKeyName = struct {
	FpszName         TLPWSTR
	FpszAlgid        TLPWSTR
	FdwLegacyKeySpec TDWORD
	FdwFlags         TDWORD
}

type NCryptKeyName = TNCryptKeyName

type TNCryptProviderName = struct {
	FpszName    TLPWSTR
	FpszComment TLPWSTR
}

type NCryptProviderName = TNCryptProviderName

type TNCRYPT_UI_POLICY = struct {
	FdwVersion        TDWORD
	FdwFlags          TDWORD
	FpszCreationTitle TLPCWSTR
	FpszFriendlyName  TLPCWSTR
	FpszDescription   TLPCWSTR
}

type NCRYPT_UI_POLICY = TNCRYPT_UI_POLICY

type t__NCRYPT_UI_POLICY = TNCRYPT_UI_POLICY

type TNCRYPT_SUPPORTED_LENGTHS = struct {
	FdwMinLength     TDWORD
	FdwMaxLength     TDWORD
	FdwIncrement     TDWORD
	FdwDefaultLength TDWORD
}

type NCRYPT_SUPPORTED_LENGTHS = TNCRYPT_SUPPORTED_LENGTHS

type t__NCRYPT_SUPPORTED_LENGTHS = TNCRYPT_SUPPORTED_LENGTHS

type TNCRYPT_KEY_BLOB_HEADER = struct {
	FcbSize    TULONG
	FdwMagic   TULONG
	FcbAlgName TULONG
	FcbKeyData TULONG
}

type NCRYPT_KEY_BLOB_HEADER = TNCRYPT_KEY_BLOB_HEADER

type T_NCRYPT_KEY_BLOB_HEADER = TNCRYPT_KEY_BLOB_HEADER

type _NCRYPT_KEY_BLOB_HEADER = T_NCRYPT_KEY_BLOB_HEADER

type TPNCRYPT_KEY_BLOB_HEADER = uintptr

type PNCRYPT_KEY_BLOB_HEADER = TPNCRYPT_KEY_BLOB_HEADER

type TCRYPT_BIT_BLOB = struct {
	FcbData      TDWORD
	FpbData      uintptr
	FcUnusedBits TDWORD
}

type CRYPT_BIT_BLOB = TCRYPT_BIT_BLOB

type T_CRYPT_BIT_BLOB = TCRYPT_BIT_BLOB

type _CRYPT_BIT_BLOB = T_CRYPT_BIT_BLOB

type TPCRYPT_BIT_BLOB = uintptr

type PCRYPT_BIT_BLOB = TPCRYPT_BIT_BLOB

type TCRYPT_ALGORITHM_IDENTIFIER = struct {
	FpszObjId   TLPSTR
	FParameters TCRYPT_OBJID_BLOB
}

type CRYPT_ALGORITHM_IDENTIFIER = TCRYPT_ALGORITHM_IDENTIFIER

type T_CRYPT_ALGORITHM_IDENTIFIER = TCRYPT_ALGORITHM_IDENTIFIER

type _CRYPT_ALGORITHM_IDENTIFIER = T_CRYPT_ALGORITHM_IDENTIFIER

type TPCRYPT_ALGORITHM_IDENTIFIER = uintptr

type PCRYPT_ALGORITHM_IDENTIFIER = TPCRYPT_ALGORITHM_IDENTIFIER

type TCRYPT_OBJID_TABLE = struct {
	FdwAlgId  TDWORD
	FpszObjId TLPCSTR
}

type CRYPT_OBJID_TABLE = TCRYPT_OBJID_TABLE

type T_CRYPT_OBJID_TABLE = TCRYPT_OBJID_TABLE

type _CRYPT_OBJID_TABLE = T_CRYPT_OBJID_TABLE

type TPCRYPT_OBJID_TABLE = uintptr

type PCRYPT_OBJID_TABLE = TPCRYPT_OBJID_TABLE

type TCRYPT_HASH_INFO = struct {
	FHashAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FHash          TCRYPT_HASH_BLOB
}

type CRYPT_HASH_INFO = TCRYPT_HASH_INFO

type T_CRYPT_HASH_INFO = TCRYPT_HASH_INFO

type _CRYPT_HASH_INFO = T_CRYPT_HASH_INFO

type TPCRYPT_HASH_INFO = uintptr

type PCRYPT_HASH_INFO = TPCRYPT_HASH_INFO

type TCERT_EXTENSION = struct {
	FpszObjId  TLPSTR
	FfCritical TWINBOOL
	FValue     TCRYPT_OBJID_BLOB
}

type CERT_EXTENSION = TCERT_EXTENSION

type T_CERT_EXTENSION = TCERT_EXTENSION

type _CERT_EXTENSION = T_CERT_EXTENSION

type TPCERT_EXTENSION = uintptr

type PCERT_EXTENSION = TPCERT_EXTENSION

type TPCCERT_EXTENSION = uintptr

type PCCERT_EXTENSION = TPCCERT_EXTENSION

type TCRYPT_ATTRIBUTE_TYPE_VALUE = struct {
	FpszObjId TLPSTR
	FValue    TCRYPT_OBJID_BLOB
}

type CRYPT_ATTRIBUTE_TYPE_VALUE = TCRYPT_ATTRIBUTE_TYPE_VALUE

type T_CRYPT_ATTRIBUTE_TYPE_VALUE = TCRYPT_ATTRIBUTE_TYPE_VALUE

type _CRYPT_ATTRIBUTE_TYPE_VALUE = T_CRYPT_ATTRIBUTE_TYPE_VALUE

type TPCRYPT_ATTRIBUTE_TYPE_VALUE = uintptr

type PCRYPT_ATTRIBUTE_TYPE_VALUE = TPCRYPT_ATTRIBUTE_TYPE_VALUE

type TCRYPT_ATTRIBUTE = struct {
	FpszObjId TLPSTR
	FcValue   TDWORD
	FrgValue  TPCRYPT_ATTR_BLOB
}

type CRYPT_ATTRIBUTE = TCRYPT_ATTRIBUTE

type T_CRYPT_ATTRIBUTE = TCRYPT_ATTRIBUTE

type _CRYPT_ATTRIBUTE = T_CRYPT_ATTRIBUTE

type TPCRYPT_ATTRIBUTE = uintptr

type PCRYPT_ATTRIBUTE = TPCRYPT_ATTRIBUTE

type TCRYPT_ATTRIBUTES = struct {
	FcAttr  TDWORD
	FrgAttr TPCRYPT_ATTRIBUTE
}

type CRYPT_ATTRIBUTES = TCRYPT_ATTRIBUTES

type T_CRYPT_ATTRIBUTES = TCRYPT_ATTRIBUTES

type _CRYPT_ATTRIBUTES = T_CRYPT_ATTRIBUTES

type TPCRYPT_ATTRIBUTES = uintptr

type PCRYPT_ATTRIBUTES = TPCRYPT_ATTRIBUTES

type TCERT_RDN_ATTR = struct {
	FpszObjId    TLPSTR
	FdwValueType TDWORD
	FValue       TCERT_RDN_VALUE_BLOB
}

type CERT_RDN_ATTR = TCERT_RDN_ATTR

type T_CERT_RDN_ATTR = TCERT_RDN_ATTR

type _CERT_RDN_ATTR = T_CERT_RDN_ATTR

type TPCERT_RDN_ATTR = uintptr

type PCERT_RDN_ATTR = TPCERT_RDN_ATTR

type TCERT_RDN = struct {
	FcRDNAttr  TDWORD
	FrgRDNAttr TPCERT_RDN_ATTR
}

type CERT_RDN = TCERT_RDN

type T_CERT_RDN = TCERT_RDN

type _CERT_RDN = T_CERT_RDN

type TPCERT_RDN = uintptr

type PCERT_RDN = TPCERT_RDN

type TCERT_NAME_INFO = struct {
	FcRDN  TDWORD
	FrgRDN TPCERT_RDN
}

type CERT_NAME_INFO = TCERT_NAME_INFO

type T_CERT_NAME_INFO = TCERT_NAME_INFO

type _CERT_NAME_INFO = T_CERT_NAME_INFO

type TPCERT_NAME_INFO = uintptr

type PCERT_NAME_INFO = TPCERT_NAME_INFO

type TCERT_NAME_VALUE = struct {
	FdwValueType TDWORD
	FValue       TCERT_RDN_VALUE_BLOB
}

type CERT_NAME_VALUE = TCERT_NAME_VALUE

type T_CERT_NAME_VALUE = TCERT_NAME_VALUE

type _CERT_NAME_VALUE = T_CERT_NAME_VALUE

type TPCERT_NAME_VALUE = uintptr

type PCERT_NAME_VALUE = TPCERT_NAME_VALUE

type TCERT_PUBLIC_KEY_INFO = struct {
	FAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FPublicKey TCRYPT_BIT_BLOB
}

type CERT_PUBLIC_KEY_INFO = TCERT_PUBLIC_KEY_INFO

type T_CERT_PUBLIC_KEY_INFO = TCERT_PUBLIC_KEY_INFO

type _CERT_PUBLIC_KEY_INFO = T_CERT_PUBLIC_KEY_INFO

type TPCERT_PUBLIC_KEY_INFO = uintptr

type PCERT_PUBLIC_KEY_INFO = TPCERT_PUBLIC_KEY_INFO

type TCRYPT_ECC_PRIVATE_KEY_INFO = struct {
	FdwVersion  TDWORD
	FPrivateKey TCRYPT_DER_BLOB
	FszCurveOid TLPSTR
	FPublicKey  TCRYPT_BIT_BLOB
}

type CRYPT_ECC_PRIVATE_KEY_INFO = TCRYPT_ECC_PRIVATE_KEY_INFO

type T_CRYPT_ECC_PRIVATE_KEY_INFO = TCRYPT_ECC_PRIVATE_KEY_INFO

type _CRYPT_ECC_PRIVATE_KEY_INFO = T_CRYPT_ECC_PRIVATE_KEY_INFO

type TPCRYPT_ECC_PRIVATE_KEY_INFO = uintptr

type PCRYPT_ECC_PRIVATE_KEY_INFO = TPCRYPT_ECC_PRIVATE_KEY_INFO

type TCRYPT_PRIVATE_KEY_INFO = struct {
	FVersion     TDWORD
	FAlgorithm   TCRYPT_ALGORITHM_IDENTIFIER
	FPrivateKey  TCRYPT_DER_BLOB
	FpAttributes TPCRYPT_ATTRIBUTES
}

type CRYPT_PRIVATE_KEY_INFO = TCRYPT_PRIVATE_KEY_INFO

type T_CRYPT_PRIVATE_KEY_INFO = TCRYPT_PRIVATE_KEY_INFO

type _CRYPT_PRIVATE_KEY_INFO = T_CRYPT_PRIVATE_KEY_INFO

type TPCRYPT_PRIVATE_KEY_INFO = uintptr

type PCRYPT_PRIVATE_KEY_INFO = TPCRYPT_PRIVATE_KEY_INFO

type TCRYPT_ENCRYPTED_PRIVATE_KEY_INFO = struct {
	FEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FEncryptedPrivateKey TCRYPT_DATA_BLOB
}

type CRYPT_ENCRYPTED_PRIVATE_KEY_INFO = TCRYPT_ENCRYPTED_PRIVATE_KEY_INFO

type T_CRYPT_ENCRYPTED_PRIVATE_KEY_INFO = TCRYPT_ENCRYPTED_PRIVATE_KEY_INFO

type _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO = T_CRYPT_ENCRYPTED_PRIVATE_KEY_INFO

type TPCRYPT_ENCRYPTED_PRIVATE_KEY_INFO = uintptr

type PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO = TPCRYPT_ENCRYPTED_PRIVATE_KEY_INFO

type TPCRYPT_DECRYPT_PRIVATE_KEY_FUNC = uintptr

type PCRYPT_DECRYPT_PRIVATE_KEY_FUNC = TPCRYPT_DECRYPT_PRIVATE_KEY_FUNC

type TPCRYPT_ENCRYPT_PRIVATE_KEY_FUNC = uintptr

type PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC = TPCRYPT_ENCRYPT_PRIVATE_KEY_FUNC

type TPCRYPT_RESOLVE_HCRYPTPROV_FUNC = uintptr

type PCRYPT_RESOLVE_HCRYPTPROV_FUNC = TPCRYPT_RESOLVE_HCRYPTPROV_FUNC

type TCRYPT_PKCS8_IMPORT_PARAMS = struct {
	FPrivateKey             TCRYPT_DIGEST_BLOB
	FpResolvehCryptProvFunc TPCRYPT_RESOLVE_HCRYPTPROV_FUNC
	FpVoidResolveFunc       TLPVOID
	FpDecryptPrivateKeyFunc TPCRYPT_DECRYPT_PRIVATE_KEY_FUNC
	FpVoidDecryptFunc       TLPVOID
}

type CRYPT_PKCS8_IMPORT_PARAMS = TCRYPT_PKCS8_IMPORT_PARAMS

type T_CRYPT_PKCS8_IMPORT_PARAMS = TCRYPT_PKCS8_IMPORT_PARAMS

type _CRYPT_PKCS8_IMPORT_PARAMS = T_CRYPT_PKCS8_IMPORT_PARAMS

type TPCRYPT_PKCS8_IMPORT_PARAMS = uintptr

type PCRYPT_PKCS8_IMPORT_PARAMS = TPCRYPT_PKCS8_IMPORT_PARAMS

type TCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS = struct {
	FPrivateKey             TCRYPT_DIGEST_BLOB
	FpResolvehCryptProvFunc TPCRYPT_RESOLVE_HCRYPTPROV_FUNC
	FpVoidResolveFunc       TLPVOID
	FpDecryptPrivateKeyFunc TPCRYPT_DECRYPT_PRIVATE_KEY_FUNC
	FpVoidDecryptFunc       TLPVOID
}

type CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS = TCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS

type TPCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS = uintptr

type PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS = TPCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS

type TCRYPT_PKCS8_EXPORT_PARAMS = struct {
	FhCryptProv             THCRYPTPROV
	FdwKeySpec              TDWORD
	FpszPrivateKeyObjId     TLPSTR
	FpEncryptPrivateKeyFunc TPCRYPT_ENCRYPT_PRIVATE_KEY_FUNC
	FpVoidEncryptFunc       TLPVOID
}

type CRYPT_PKCS8_EXPORT_PARAMS = TCRYPT_PKCS8_EXPORT_PARAMS

type T_CRYPT_PKCS8_EXPORT_PARAMS = TCRYPT_PKCS8_EXPORT_PARAMS

type _CRYPT_PKCS8_EXPORT_PARAMS = T_CRYPT_PKCS8_EXPORT_PARAMS

type TPCRYPT_PKCS8_EXPORT_PARAMS = uintptr

type PCRYPT_PKCS8_EXPORT_PARAMS = TPCRYPT_PKCS8_EXPORT_PARAMS

type TCERT_INFO = struct {
	FdwVersion            TDWORD
	FSerialNumber         TCRYPT_INTEGER_BLOB
	FSignatureAlgorithm   TCRYPT_ALGORITHM_IDENTIFIER
	FIssuer               TCERT_NAME_BLOB
	FNotBefore            TFILETIME
	FNotAfter             TFILETIME
	FSubject              TCERT_NAME_BLOB
	FSubjectPublicKeyInfo TCERT_PUBLIC_KEY_INFO
	FIssuerUniqueId       TCRYPT_BIT_BLOB
	FSubjectUniqueId      TCRYPT_BIT_BLOB
	FcExtension           TDWORD
	FrgExtension          TPCERT_EXTENSION
}

type CERT_INFO = TCERT_INFO

type T_CERT_INFO = TCERT_INFO

type _CERT_INFO = T_CERT_INFO

type TPCERT_INFO = uintptr

type PCERT_INFO = TPCERT_INFO

type TCRL_ENTRY = struct {
	FSerialNumber   TCRYPT_INTEGER_BLOB
	FRevocationDate TFILETIME
	FcExtension     TDWORD
	FrgExtension    TPCERT_EXTENSION
}

type CRL_ENTRY = TCRL_ENTRY

type T_CRL_ENTRY = TCRL_ENTRY

type _CRL_ENTRY = T_CRL_ENTRY

type TPCRL_ENTRY = uintptr

type PCRL_ENTRY = TPCRL_ENTRY

type TCRL_INFO = struct {
	FdwVersion          TDWORD
	FSignatureAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FIssuer             TCERT_NAME_BLOB
	FThisUpdate         TFILETIME
	FNextUpdate         TFILETIME
	FcCRLEntry          TDWORD
	FrgCRLEntry         TPCRL_ENTRY
	FcExtension         TDWORD
	FrgExtension        TPCERT_EXTENSION
}

type CRL_INFO = TCRL_INFO

type T_CRL_INFO = TCRL_INFO

type _CRL_INFO = T_CRL_INFO

type TPCRL_INFO = uintptr

type PCRL_INFO = TPCRL_INFO

type TCERT_OR_CRL_BLOB = struct {
	FdwChoice  TDWORD
	FcbEncoded TDWORD
	FpbEncoded uintptr
}

type CERT_OR_CRL_BLOB = TCERT_OR_CRL_BLOB

type T_CERT_OR_CRL_BLOB = TCERT_OR_CRL_BLOB

type _CERT_OR_CRL_BLOB = T_CERT_OR_CRL_BLOB

type TPCERT_OR_CRL_BLOB = uintptr

type PCERT_OR_CRL_BLOB = TPCERT_OR_CRL_BLOB

type TCERT_OR_CRL_BUNDLE = struct {
	FcItem  TDWORD
	FrgItem TPCERT_OR_CRL_BLOB
}

type CERT_OR_CRL_BUNDLE = TCERT_OR_CRL_BUNDLE

type T_CERT_OR_CRL_BUNDLE = TCERT_OR_CRL_BUNDLE

type _CERT_OR_CRL_BUNDLE = T_CERT_OR_CRL_BUNDLE

type TPCERT_OR_CRL_BUNDLE = uintptr

type PCERT_OR_CRL_BUNDLE = TPCERT_OR_CRL_BUNDLE

type TCERT_REQUEST_INFO = struct {
	FdwVersion            TDWORD
	FSubject              TCERT_NAME_BLOB
	FSubjectPublicKeyInfo TCERT_PUBLIC_KEY_INFO
	FcAttribute           TDWORD
	FrgAttribute          TPCRYPT_ATTRIBUTE
}

type CERT_REQUEST_INFO = TCERT_REQUEST_INFO

type T_CERT_REQUEST_INFO = TCERT_REQUEST_INFO

type _CERT_REQUEST_INFO = T_CERT_REQUEST_INFO

type TPCERT_REQUEST_INFO = uintptr

type PCERT_REQUEST_INFO = TPCERT_REQUEST_INFO

type TCERT_KEYGEN_REQUEST_INFO = struct {
	FdwVersion            TDWORD
	FSubjectPublicKeyInfo TCERT_PUBLIC_KEY_INFO
	FpwszChallengeString  TLPWSTR
}

type CERT_KEYGEN_REQUEST_INFO = TCERT_KEYGEN_REQUEST_INFO

type T_CERT_KEYGEN_REQUEST_INFO = TCERT_KEYGEN_REQUEST_INFO

type _CERT_KEYGEN_REQUEST_INFO = T_CERT_KEYGEN_REQUEST_INFO

type TPCERT_KEYGEN_REQUEST_INFO = uintptr

type PCERT_KEYGEN_REQUEST_INFO = TPCERT_KEYGEN_REQUEST_INFO

type TCERT_SIGNED_CONTENT_INFO = struct {
	FToBeSigned         TCRYPT_DER_BLOB
	FSignatureAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FSignature          TCRYPT_BIT_BLOB
}

type CERT_SIGNED_CONTENT_INFO = TCERT_SIGNED_CONTENT_INFO

type T_CERT_SIGNED_CONTENT_INFO = TCERT_SIGNED_CONTENT_INFO

type _CERT_SIGNED_CONTENT_INFO = T_CERT_SIGNED_CONTENT_INFO

type TPCERT_SIGNED_CONTENT_INFO = uintptr

type PCERT_SIGNED_CONTENT_INFO = TPCERT_SIGNED_CONTENT_INFO

type TCTL_USAGE = struct {
	FcUsageIdentifier     TDWORD
	FrgpszUsageIdentifier uintptr
}

type CTL_USAGE = TCTL_USAGE

type T_CTL_USAGE = TCTL_USAGE

type _CTL_USAGE = T_CTL_USAGE

type TPCTL_USAGE = uintptr

type PCTL_USAGE = TPCTL_USAGE

type TCERT_ENHKEY_USAGE = struct {
	FcUsageIdentifier     TDWORD
	FrgpszUsageIdentifier uintptr
}

type CERT_ENHKEY_USAGE = TCERT_ENHKEY_USAGE

type TPCERT_ENHKEY_USAGE = uintptr

type PCERT_ENHKEY_USAGE = TPCERT_ENHKEY_USAGE

type TPCCTL_USAGE = uintptr

type PCCTL_USAGE = TPCCTL_USAGE

type TPCCERT_ENHKEY_USAGE = uintptr

type PCCERT_ENHKEY_USAGE = TPCCERT_ENHKEY_USAGE

type TCTL_ENTRY = struct {
	FSubjectIdentifier TCRYPT_DATA_BLOB
	FcAttribute        TDWORD
	FrgAttribute       TPCRYPT_ATTRIBUTE
}

type CTL_ENTRY = TCTL_ENTRY

type T_CTL_ENTRY = TCTL_ENTRY

type _CTL_ENTRY = T_CTL_ENTRY

type TPCTL_ENTRY = uintptr

type PCTL_ENTRY = TPCTL_ENTRY

type TCTL_INFO = struct {
	FdwVersion        TDWORD
	FSubjectUsage     TCTL_USAGE
	FListIdentifier   TCRYPT_DATA_BLOB
	FSequenceNumber   TCRYPT_INTEGER_BLOB
	FThisUpdate       TFILETIME
	FNextUpdate       TFILETIME
	FSubjectAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FcCTLEntry        TDWORD
	FrgCTLEntry       TPCTL_ENTRY
	FcExtension       TDWORD
	FrgExtension      TPCERT_EXTENSION
}

type CTL_INFO = TCTL_INFO

type T_CTL_INFO = TCTL_INFO

type _CTL_INFO = T_CTL_INFO

type TPCTL_INFO = uintptr

type PCTL_INFO = TPCTL_INFO

type TCRYPT_TIME_STAMP_REQUEST_INFO = struct {
	FpszTimeStampAlgorithm TLPSTR
	FpszContentType        TLPSTR
	FContent               TCRYPT_OBJID_BLOB
	FcAttribute            TDWORD
	FrgAttribute           TPCRYPT_ATTRIBUTE
}

type CRYPT_TIME_STAMP_REQUEST_INFO = TCRYPT_TIME_STAMP_REQUEST_INFO

type T_CRYPT_TIME_STAMP_REQUEST_INFO = TCRYPT_TIME_STAMP_REQUEST_INFO

type _CRYPT_TIME_STAMP_REQUEST_INFO = T_CRYPT_TIME_STAMP_REQUEST_INFO

type TPCRYPT_TIME_STAMP_REQUEST_INFO = uintptr

type PCRYPT_TIME_STAMP_REQUEST_INFO = TPCRYPT_TIME_STAMP_REQUEST_INFO

type TCRYPT_ENROLLMENT_NAME_VALUE_PAIR = struct {
	FpwszName  TLPWSTR
	FpwszValue TLPWSTR
}

type CRYPT_ENROLLMENT_NAME_VALUE_PAIR = TCRYPT_ENROLLMENT_NAME_VALUE_PAIR

type T_CRYPT_ENROLLMENT_NAME_VALUE_PAIR = TCRYPT_ENROLLMENT_NAME_VALUE_PAIR

type _CRYPT_ENROLLMENT_NAME_VALUE_PAIR = T_CRYPT_ENROLLMENT_NAME_VALUE_PAIR

type TPCRYPT_ENROLLMENT_NAME_VALUE_PAIR = uintptr

type PCRYPT_ENROLLMENT_NAME_VALUE_PAIR = TPCRYPT_ENROLLMENT_NAME_VALUE_PAIR

type TCRYPT_CSP_PROVIDER = struct {
	FdwKeySpec        TDWORD
	FpwszProviderName TLPWSTR
	FSignature        TCRYPT_BIT_BLOB
}

type CRYPT_CSP_PROVIDER = TCRYPT_CSP_PROVIDER

type T_CRYPT_CSP_PROVIDER = TCRYPT_CSP_PROVIDER

type _CRYPT_CSP_PROVIDER = T_CRYPT_CSP_PROVIDER

type TPCRYPT_CSP_PROVIDER = uintptr

type PCRYPT_CSP_PROVIDER = TPCRYPT_CSP_PROVIDER

type TPFN_CRYPT_ALLOC = uintptr

type PFN_CRYPT_ALLOC = TPFN_CRYPT_ALLOC

type TPFN_CRYPT_FREE = uintptr

type PFN_CRYPT_FREE = TPFN_CRYPT_FREE

type TCRYPT_ENCODE_PARA = struct {
	FcbSize   TDWORD
	FpfnAlloc TPFN_CRYPT_ALLOC
	FpfnFree  TPFN_CRYPT_FREE
}

type CRYPT_ENCODE_PARA = TCRYPT_ENCODE_PARA

type T_CRYPT_ENCODE_PARA = TCRYPT_ENCODE_PARA

type _CRYPT_ENCODE_PARA = T_CRYPT_ENCODE_PARA

type TPCRYPT_ENCODE_PARA = uintptr

type PCRYPT_ENCODE_PARA = TPCRYPT_ENCODE_PARA

type TCRYPT_DECODE_PARA = struct {
	FcbSize   TDWORD
	FpfnAlloc TPFN_CRYPT_ALLOC
	FpfnFree  TPFN_CRYPT_FREE
}

type CRYPT_DECODE_PARA = TCRYPT_DECODE_PARA

type T_CRYPT_DECODE_PARA = TCRYPT_DECODE_PARA

type _CRYPT_DECODE_PARA = T_CRYPT_DECODE_PARA

type TPCRYPT_DECODE_PARA = uintptr

type PCRYPT_DECODE_PARA = TPCRYPT_DECODE_PARA

type TCERT_EXTENSIONS = struct {
	FcExtension  TDWORD
	FrgExtension TPCERT_EXTENSION
}

type CERT_EXTENSIONS = TCERT_EXTENSIONS

type T_CERT_EXTENSIONS = TCERT_EXTENSIONS

type _CERT_EXTENSIONS = T_CERT_EXTENSIONS

type TPCERT_EXTENSIONS = uintptr

type PCERT_EXTENSIONS = TPCERT_EXTENSIONS

type TCERT_AUTHORITY_KEY_ID_INFO = struct {
	FKeyId            TCRYPT_DATA_BLOB
	FCertIssuer       TCERT_NAME_BLOB
	FCertSerialNumber TCRYPT_INTEGER_BLOB
}

type CERT_AUTHORITY_KEY_ID_INFO = TCERT_AUTHORITY_KEY_ID_INFO

type T_CERT_AUTHORITY_KEY_ID_INFO = TCERT_AUTHORITY_KEY_ID_INFO

type _CERT_AUTHORITY_KEY_ID_INFO = T_CERT_AUTHORITY_KEY_ID_INFO

type TPCERT_AUTHORITY_KEY_ID_INFO = uintptr

type PCERT_AUTHORITY_KEY_ID_INFO = TPCERT_AUTHORITY_KEY_ID_INFO

type TCERT_PRIVATE_KEY_VALIDITY = struct {
	FNotBefore TFILETIME
	FNotAfter  TFILETIME
}

type CERT_PRIVATE_KEY_VALIDITY = TCERT_PRIVATE_KEY_VALIDITY

type T_CERT_PRIVATE_KEY_VALIDITY = TCERT_PRIVATE_KEY_VALIDITY

type _CERT_PRIVATE_KEY_VALIDITY = T_CERT_PRIVATE_KEY_VALIDITY

type TPCERT_PRIVATE_KEY_VALIDITY = uintptr

type PCERT_PRIVATE_KEY_VALIDITY = TPCERT_PRIVATE_KEY_VALIDITY

type TCERT_KEY_ATTRIBUTES_INFO = struct {
	FKeyId                  TCRYPT_DATA_BLOB
	FIntendedKeyUsage       TCRYPT_BIT_BLOB
	FpPrivateKeyUsagePeriod TPCERT_PRIVATE_KEY_VALIDITY
}

type CERT_KEY_ATTRIBUTES_INFO = TCERT_KEY_ATTRIBUTES_INFO

type T_CERT_KEY_ATTRIBUTES_INFO = TCERT_KEY_ATTRIBUTES_INFO

type _CERT_KEY_ATTRIBUTES_INFO = T_CERT_KEY_ATTRIBUTES_INFO

type TPCERT_KEY_ATTRIBUTES_INFO = uintptr

type PCERT_KEY_ATTRIBUTES_INFO = TPCERT_KEY_ATTRIBUTES_INFO

type TCERT_POLICY_ID = struct {
	FcCertPolicyElementId     TDWORD
	FrgpszCertPolicyElementId uintptr
}

type CERT_POLICY_ID = TCERT_POLICY_ID

type T_CERT_POLICY_ID = TCERT_POLICY_ID

type _CERT_POLICY_ID = T_CERT_POLICY_ID

type TPCERT_POLICY_ID = uintptr

type PCERT_POLICY_ID = TPCERT_POLICY_ID

type TCERT_KEY_USAGE_RESTRICTION_INFO = struct {
	FcCertPolicyId      TDWORD
	FrgCertPolicyId     TPCERT_POLICY_ID
	FRestrictedKeyUsage TCRYPT_BIT_BLOB
}

type CERT_KEY_USAGE_RESTRICTION_INFO = TCERT_KEY_USAGE_RESTRICTION_INFO

type T_CERT_KEY_USAGE_RESTRICTION_INFO = TCERT_KEY_USAGE_RESTRICTION_INFO

type _CERT_KEY_USAGE_RESTRICTION_INFO = T_CERT_KEY_USAGE_RESTRICTION_INFO

type TPCERT_KEY_USAGE_RESTRICTION_INFO = uintptr

type PCERT_KEY_USAGE_RESTRICTION_INFO = TPCERT_KEY_USAGE_RESTRICTION_INFO

type TCERT_OTHER_NAME = struct {
	FpszObjId TLPSTR
	FValue    TCRYPT_OBJID_BLOB
}

type CERT_OTHER_NAME = TCERT_OTHER_NAME

type T_CERT_OTHER_NAME = TCERT_OTHER_NAME

type _CERT_OTHER_NAME = T_CERT_OTHER_NAME

type TPCERT_OTHER_NAME = uintptr

type PCERT_OTHER_NAME = TPCERT_OTHER_NAME

type TCERT_ALT_NAME_ENTRY = struct {
	FdwAltNameChoice TDWORD
	F__ccgo1_4       struct {
		FpwszRfc822Name  [0]TLPWSTR
		FpwszDNSName     [0]TLPWSTR
		FDirectoryName   [0]TCERT_NAME_BLOB
		FpwszURL         [0]TLPWSTR
		FIPAddress       [0]TCRYPT_DATA_BLOB
		FpszRegisteredID [0]TLPSTR
		FpOtherName      TPCERT_OTHER_NAME
		F__ccgo_pad7     [4]byte
	}
}

type CERT_ALT_NAME_ENTRY = TCERT_ALT_NAME_ENTRY

type T_CERT_ALT_NAME_ENTRY = TCERT_ALT_NAME_ENTRY

type _CERT_ALT_NAME_ENTRY = T_CERT_ALT_NAME_ENTRY

type TPCERT_ALT_NAME_ENTRY = uintptr

type PCERT_ALT_NAME_ENTRY = TPCERT_ALT_NAME_ENTRY

type TCERT_ALT_NAME_INFO = struct {
	FcAltEntry  TDWORD
	FrgAltEntry TPCERT_ALT_NAME_ENTRY
}

type CERT_ALT_NAME_INFO = TCERT_ALT_NAME_INFO

type T_CERT_ALT_NAME_INFO = TCERT_ALT_NAME_INFO

type _CERT_ALT_NAME_INFO = T_CERT_ALT_NAME_INFO

type TPCERT_ALT_NAME_INFO = uintptr

type PCERT_ALT_NAME_INFO = TPCERT_ALT_NAME_INFO

type TCERT_BASIC_CONSTRAINTS_INFO = struct {
	FSubjectType          TCRYPT_BIT_BLOB
	FfPathLenConstraint   TWINBOOL
	FdwPathLenConstraint  TDWORD
	FcSubtreesConstraint  TDWORD
	FrgSubtreesConstraint uintptr
}

type CERT_BASIC_CONSTRAINTS_INFO = TCERT_BASIC_CONSTRAINTS_INFO

type T_CERT_BASIC_CONSTRAINTS_INFO = TCERT_BASIC_CONSTRAINTS_INFO

type _CERT_BASIC_CONSTRAINTS_INFO = T_CERT_BASIC_CONSTRAINTS_INFO

type TPCERT_BASIC_CONSTRAINTS_INFO = uintptr

type PCERT_BASIC_CONSTRAINTS_INFO = TPCERT_BASIC_CONSTRAINTS_INFO

type TCERT_BASIC_CONSTRAINTS2_INFO = struct {
	FfCA                 TWINBOOL
	FfPathLenConstraint  TWINBOOL
	FdwPathLenConstraint TDWORD
}

type CERT_BASIC_CONSTRAINTS2_INFO = TCERT_BASIC_CONSTRAINTS2_INFO

type T_CERT_BASIC_CONSTRAINTS2_INFO = TCERT_BASIC_CONSTRAINTS2_INFO

type _CERT_BASIC_CONSTRAINTS2_INFO = T_CERT_BASIC_CONSTRAINTS2_INFO

type TPCERT_BASIC_CONSTRAINTS2_INFO = uintptr

type PCERT_BASIC_CONSTRAINTS2_INFO = TPCERT_BASIC_CONSTRAINTS2_INFO

type TCERT_POLICY_QUALIFIER_INFO = struct {
	FpszPolicyQualifierId TLPSTR
	FQualifier            TCRYPT_OBJID_BLOB
}

type CERT_POLICY_QUALIFIER_INFO = TCERT_POLICY_QUALIFIER_INFO

type T_CERT_POLICY_QUALIFIER_INFO = TCERT_POLICY_QUALIFIER_INFO

type _CERT_POLICY_QUALIFIER_INFO = T_CERT_POLICY_QUALIFIER_INFO

type TPCERT_POLICY_QUALIFIER_INFO = uintptr

type PCERT_POLICY_QUALIFIER_INFO = TPCERT_POLICY_QUALIFIER_INFO

type TCERT_POLICY_INFO = struct {
	FpszPolicyIdentifier TLPSTR
	FcPolicyQualifier    TDWORD
	FrgPolicyQualifier   uintptr
}

type CERT_POLICY_INFO = TCERT_POLICY_INFO

type T_CERT_POLICY_INFO = TCERT_POLICY_INFO

type _CERT_POLICY_INFO = T_CERT_POLICY_INFO

type TPCERT_POLICY_INFO = uintptr

type PCERT_POLICY_INFO = TPCERT_POLICY_INFO

type TCERT_POLICIES_INFO = struct {
	FcPolicyInfo  TDWORD
	FrgPolicyInfo uintptr
}

type CERT_POLICIES_INFO = TCERT_POLICIES_INFO

type T_CERT_POLICIES_INFO = TCERT_POLICIES_INFO

type _CERT_POLICIES_INFO = T_CERT_POLICIES_INFO

type TPCERT_POLICIES_INFO = uintptr

type PCERT_POLICIES_INFO = TPCERT_POLICIES_INFO

type TCERT_POLICY_QUALIFIER_NOTICE_REFERENCE = struct {
	FpszOrganization TLPSTR
	FcNoticeNumbers  TDWORD
	FrgNoticeNumbers uintptr
}

type CERT_POLICY_QUALIFIER_NOTICE_REFERENCE = TCERT_POLICY_QUALIFIER_NOTICE_REFERENCE

type T_CERT_POLICY_QUALIFIER_NOTICE_REFERENCE = TCERT_POLICY_QUALIFIER_NOTICE_REFERENCE

type _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE = T_CERT_POLICY_QUALIFIER_NOTICE_REFERENCE

type TPCERT_POLICY_QUALIFIER_NOTICE_REFERENCE = uintptr

type PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE = TPCERT_POLICY_QUALIFIER_NOTICE_REFERENCE

type TCERT_POLICY_QUALIFIER_USER_NOTICE = struct {
	FpNoticeReference uintptr
	FpszDisplayText   TLPWSTR
}

type CERT_POLICY_QUALIFIER_USER_NOTICE = TCERT_POLICY_QUALIFIER_USER_NOTICE

type T_CERT_POLICY_QUALIFIER_USER_NOTICE = TCERT_POLICY_QUALIFIER_USER_NOTICE

type _CERT_POLICY_QUALIFIER_USER_NOTICE = T_CERT_POLICY_QUALIFIER_USER_NOTICE

type TPCERT_POLICY_QUALIFIER_USER_NOTICE = uintptr

type PCERT_POLICY_QUALIFIER_USER_NOTICE = TPCERT_POLICY_QUALIFIER_USER_NOTICE

type TCPS_URLS = struct {
	FpszURL     TLPWSTR
	FpAlgorithm uintptr
	FpDigest    uintptr
}

type CPS_URLS = TCPS_URLS

type T_CPS_URLS = TCPS_URLS

type _CPS_URLS = T_CPS_URLS

type TPCPS_URLS = uintptr

type PCPS_URLS = TPCPS_URLS

type TCERT_POLICY95_QUALIFIER1 = struct {
	FpszPracticesReference  TLPWSTR
	FpszNoticeIdentifier    TLPSTR
	FpszNSINoticeIdentifier TLPSTR
	FcCPSURLs               TDWORD
	FrgCPSURLs              uintptr
}

type CERT_POLICY95_QUALIFIER1 = TCERT_POLICY95_QUALIFIER1

type T_CERT_POLICY95_QUALIFIER1 = TCERT_POLICY95_QUALIFIER1

type _CERT_POLICY95_QUALIFIER1 = T_CERT_POLICY95_QUALIFIER1

type TPCERT_POLICY95_QUALIFIER1 = uintptr

type PCERT_POLICY95_QUALIFIER1 = TPCERT_POLICY95_QUALIFIER1

type TCERT_POLICY_MAPPING = struct {
	FpszIssuerDomainPolicy  TLPSTR
	FpszSubjectDomainPolicy TLPSTR
}

type CERT_POLICY_MAPPING = TCERT_POLICY_MAPPING

type T_CERT_POLICY_MAPPING = TCERT_POLICY_MAPPING

type _CERT_POLICY_MAPPING = T_CERT_POLICY_MAPPING

type TPCERT_POLICY_MAPPING = uintptr

type PCERT_POLICY_MAPPING = TPCERT_POLICY_MAPPING

type TCERT_POLICY_MAPPINGS_INFO = struct {
	FcPolicyMapping  TDWORD
	FrgPolicyMapping TPCERT_POLICY_MAPPING
}

type CERT_POLICY_MAPPINGS_INFO = TCERT_POLICY_MAPPINGS_INFO

type T_CERT_POLICY_MAPPINGS_INFO = TCERT_POLICY_MAPPINGS_INFO

type _CERT_POLICY_MAPPINGS_INFO = T_CERT_POLICY_MAPPINGS_INFO

type TPCERT_POLICY_MAPPINGS_INFO = uintptr

type PCERT_POLICY_MAPPINGS_INFO = TPCERT_POLICY_MAPPINGS_INFO

type TCERT_POLICY_CONSTRAINTS_INFO = struct {
	FfRequireExplicitPolicy           TWINBOOL
	FdwRequireExplicitPolicySkipCerts TDWORD
	FfInhibitPolicyMapping            TWINBOOL
	FdwInhibitPolicyMappingSkipCerts  TDWORD
}

type CERT_POLICY_CONSTRAINTS_INFO = TCERT_POLICY_CONSTRAINTS_INFO

type T_CERT_POLICY_CONSTRAINTS_INFO = TCERT_POLICY_CONSTRAINTS_INFO

type _CERT_POLICY_CONSTRAINTS_INFO = T_CERT_POLICY_CONSTRAINTS_INFO

type TPCERT_POLICY_CONSTRAINTS_INFO = uintptr

type PCERT_POLICY_CONSTRAINTS_INFO = TPCERT_POLICY_CONSTRAINTS_INFO

type TCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = struct {
	FpszObjId TLPSTR
	FcValue   TDWORD
	FrgValue  TPCRYPT_DER_BLOB
}

type CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = TCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY

type T_CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = TCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY

type _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = T_CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY

type TPCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = uintptr

type PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = TPCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY

type TCRYPT_CONTENT_INFO = struct {
	FpszObjId TLPSTR
	FContent  TCRYPT_DER_BLOB
}

type CRYPT_CONTENT_INFO = TCRYPT_CONTENT_INFO

type T_CRYPT_CONTENT_INFO = TCRYPT_CONTENT_INFO

type _CRYPT_CONTENT_INFO = T_CRYPT_CONTENT_INFO

type TPCRYPT_CONTENT_INFO = uintptr

type PCRYPT_CONTENT_INFO = TPCRYPT_CONTENT_INFO

type TCRYPT_SEQUENCE_OF_ANY = struct {
	FcValue  TDWORD
	FrgValue TPCRYPT_DER_BLOB
}

type CRYPT_SEQUENCE_OF_ANY = TCRYPT_SEQUENCE_OF_ANY

type T_CRYPT_SEQUENCE_OF_ANY = TCRYPT_SEQUENCE_OF_ANY

type _CRYPT_SEQUENCE_OF_ANY = T_CRYPT_SEQUENCE_OF_ANY

type TPCRYPT_SEQUENCE_OF_ANY = uintptr

type PCRYPT_SEQUENCE_OF_ANY = TPCRYPT_SEQUENCE_OF_ANY

type TCERT_AUTHORITY_KEY_ID2_INFO = struct {
	FKeyId                     TCRYPT_DATA_BLOB
	FAuthorityCertIssuer       TCERT_ALT_NAME_INFO
	FAuthorityCertSerialNumber TCRYPT_INTEGER_BLOB
}

type CERT_AUTHORITY_KEY_ID2_INFO = TCERT_AUTHORITY_KEY_ID2_INFO

type T_CERT_AUTHORITY_KEY_ID2_INFO = TCERT_AUTHORITY_KEY_ID2_INFO

type _CERT_AUTHORITY_KEY_ID2_INFO = T_CERT_AUTHORITY_KEY_ID2_INFO

type TPCERT_AUTHORITY_KEY_ID2_INFO = uintptr

type PCERT_AUTHORITY_KEY_ID2_INFO = TPCERT_AUTHORITY_KEY_ID2_INFO

type TCERT_ACCESS_DESCRIPTION = struct {
	FpszAccessMethod TLPSTR
	FAccessLocation  TCERT_ALT_NAME_ENTRY
}

type CERT_ACCESS_DESCRIPTION = TCERT_ACCESS_DESCRIPTION

type T_CERT_ACCESS_DESCRIPTION = TCERT_ACCESS_DESCRIPTION

type _CERT_ACCESS_DESCRIPTION = T_CERT_ACCESS_DESCRIPTION

type TPCERT_ACCESS_DESCRIPTION = uintptr

type PCERT_ACCESS_DESCRIPTION = TPCERT_ACCESS_DESCRIPTION

type TCERT_AUTHORITY_INFO_ACCESS = struct {
	FcAccDescr  TDWORD
	FrgAccDescr TPCERT_ACCESS_DESCRIPTION
}

type CERT_AUTHORITY_INFO_ACCESS = TCERT_AUTHORITY_INFO_ACCESS

type T_CERT_AUTHORITY_INFO_ACCESS = TCERT_AUTHORITY_INFO_ACCESS

type _CERT_AUTHORITY_INFO_ACCESS = T_CERT_AUTHORITY_INFO_ACCESS

type TPCERT_AUTHORITY_INFO_ACCESS = uintptr

type PCERT_AUTHORITY_INFO_ACCESS = TPCERT_AUTHORITY_INFO_ACCESS

type TCERT_SUBJECT_INFO_ACCESS = struct {
	FcAccDescr  TDWORD
	FrgAccDescr TPCERT_ACCESS_DESCRIPTION
}

type CERT_SUBJECT_INFO_ACCESS = TCERT_SUBJECT_INFO_ACCESS

type TPCERT_SUBJECT_INFO_ACCESS = uintptr

type PCERT_SUBJECT_INFO_ACCESS = TPCERT_SUBJECT_INFO_ACCESS

type TCRL_DIST_POINT_NAME = struct {
	FdwDistPointNameChoice TDWORD
	F__ccgo1_4             struct {
		FFullName TCERT_ALT_NAME_INFO
	}
}

type CRL_DIST_POINT_NAME = TCRL_DIST_POINT_NAME

type T_CRL_DIST_POINT_NAME = TCRL_DIST_POINT_NAME

type _CRL_DIST_POINT_NAME = T_CRL_DIST_POINT_NAME

type TPCRL_DIST_POINT_NAME = uintptr

type PCRL_DIST_POINT_NAME = TPCRL_DIST_POINT_NAME

type TCRL_DIST_POINT = struct {
	FDistPointName TCRL_DIST_POINT_NAME
	FReasonFlags   TCRYPT_BIT_BLOB
	FCRLIssuer     TCERT_ALT_NAME_INFO
}

type CRL_DIST_POINT = TCRL_DIST_POINT

type T_CRL_DIST_POINT = TCRL_DIST_POINT

type _CRL_DIST_POINT = T_CRL_DIST_POINT

type TPCRL_DIST_POINT = uintptr

type PCRL_DIST_POINT = TPCRL_DIST_POINT

type TCRL_DIST_POINTS_INFO = struct {
	FcDistPoint  TDWORD
	FrgDistPoint TPCRL_DIST_POINT
}

type CRL_DIST_POINTS_INFO = TCRL_DIST_POINTS_INFO

type T_CRL_DIST_POINTS_INFO = TCRL_DIST_POINTS_INFO

type _CRL_DIST_POINTS_INFO = T_CRL_DIST_POINTS_INFO

type TPCRL_DIST_POINTS_INFO = uintptr

type PCRL_DIST_POINTS_INFO = TPCRL_DIST_POINTS_INFO

type TCROSS_CERT_DIST_POINTS_INFO = struct {
	FdwSyncDeltaTime TDWORD
	FcDistPoint      TDWORD
	FrgDistPoint     TPCERT_ALT_NAME_INFO
}

type CROSS_CERT_DIST_POINTS_INFO = TCROSS_CERT_DIST_POINTS_INFO

type T_CROSS_CERT_DIST_POINTS_INFO = TCROSS_CERT_DIST_POINTS_INFO

type _CROSS_CERT_DIST_POINTS_INFO = T_CROSS_CERT_DIST_POINTS_INFO

type TPCROSS_CERT_DIST_POINTS_INFO = uintptr

type PCROSS_CERT_DIST_POINTS_INFO = TPCROSS_CERT_DIST_POINTS_INFO

type TCERT_PAIR = struct {
	FForward TCERT_BLOB
	FReverse TCERT_BLOB
}

type CERT_PAIR = TCERT_PAIR

type T_CERT_PAIR = TCERT_PAIR

type _CERT_PAIR = T_CERT_PAIR

type TPCERT_PAIR = uintptr

type PCERT_PAIR = TPCERT_PAIR

type TCRL_ISSUING_DIST_POINT = struct {
	FDistPointName          TCRL_DIST_POINT_NAME
	FfOnlyContainsUserCerts TWINBOOL
	FfOnlyContainsCACerts   TWINBOOL
	FOnlySomeReasonFlags    TCRYPT_BIT_BLOB
	FfIndirectCRL           TWINBOOL
}

type CRL_ISSUING_DIST_POINT = TCRL_ISSUING_DIST_POINT

type T_CRL_ISSUING_DIST_POINT = TCRL_ISSUING_DIST_POINT

type _CRL_ISSUING_DIST_POINT = T_CRL_ISSUING_DIST_POINT

type TPCRL_ISSUING_DIST_POINT = uintptr

type PCRL_ISSUING_DIST_POINT = TPCRL_ISSUING_DIST_POINT

type TCERT_GENERAL_SUBTREE = struct {
	FBase      TCERT_ALT_NAME_ENTRY
	FdwMinimum TDWORD
	FfMaximum  TWINBOOL
	FdwMaximum TDWORD
}

type CERT_GENERAL_SUBTREE = TCERT_GENERAL_SUBTREE

type T_CERT_GENERAL_SUBTREE = TCERT_GENERAL_SUBTREE

type _CERT_GENERAL_SUBTREE = T_CERT_GENERAL_SUBTREE

type TPCERT_GENERAL_SUBTREE = uintptr

type PCERT_GENERAL_SUBTREE = TPCERT_GENERAL_SUBTREE

type TCERT_NAME_CONSTRAINTS_INFO = struct {
	FcPermittedSubtree  TDWORD
	FrgPermittedSubtree TPCERT_GENERAL_SUBTREE
	FcExcludedSubtree   TDWORD
	FrgExcludedSubtree  TPCERT_GENERAL_SUBTREE
}

type CERT_NAME_CONSTRAINTS_INFO = TCERT_NAME_CONSTRAINTS_INFO

type T_CERT_NAME_CONSTRAINTS_INFO = TCERT_NAME_CONSTRAINTS_INFO

type _CERT_NAME_CONSTRAINTS_INFO = T_CERT_NAME_CONSTRAINTS_INFO

type TPCERT_NAME_CONSTRAINTS_INFO = uintptr

type PCERT_NAME_CONSTRAINTS_INFO = TPCERT_NAME_CONSTRAINTS_INFO

type TCERT_DSS_PARAMETERS = struct {
	Fp TCRYPT_UINT_BLOB
	Fq TCRYPT_UINT_BLOB
	Fg TCRYPT_UINT_BLOB
}

type CERT_DSS_PARAMETERS = TCERT_DSS_PARAMETERS

type T_CERT_DSS_PARAMETERS = TCERT_DSS_PARAMETERS

type _CERT_DSS_PARAMETERS = T_CERT_DSS_PARAMETERS

type TPCERT_DSS_PARAMETERS = uintptr

type PCERT_DSS_PARAMETERS = TPCERT_DSS_PARAMETERS

type TCERT_DH_PARAMETERS = struct {
	Fp TCRYPT_UINT_BLOB
	Fg TCRYPT_UINT_BLOB
}

type CERT_DH_PARAMETERS = TCERT_DH_PARAMETERS

type T_CERT_DH_PARAMETERS = TCERT_DH_PARAMETERS

type _CERT_DH_PARAMETERS = T_CERT_DH_PARAMETERS

type TPCERT_DH_PARAMETERS = uintptr

type PCERT_DH_PARAMETERS = TPCERT_DH_PARAMETERS

type TCERT_ECC_SIGNATURE = struct {
	Fr TCRYPT_UINT_BLOB
	Fs TCRYPT_UINT_BLOB
}

type CERT_ECC_SIGNATURE = TCERT_ECC_SIGNATURE

type T_CERT_ECC_SIGNATURE = TCERT_ECC_SIGNATURE

type _CERT_ECC_SIGNATURE = T_CERT_ECC_SIGNATURE

type TPCERT_ECC_SIGNATURE = uintptr

type PCERT_ECC_SIGNATURE = TPCERT_ECC_SIGNATURE

type TCERT_X942_DH_VALIDATION_PARAMS = struct {
	Fseed        TCRYPT_BIT_BLOB
	FpgenCounter TDWORD
}

type CERT_X942_DH_VALIDATION_PARAMS = TCERT_X942_DH_VALIDATION_PARAMS

type T_CERT_X942_DH_VALIDATION_PARAMS = TCERT_X942_DH_VALIDATION_PARAMS

type _CERT_X942_DH_VALIDATION_PARAMS = T_CERT_X942_DH_VALIDATION_PARAMS

type TPCERT_X942_DH_VALIDATION_PARAMS = uintptr

type PCERT_X942_DH_VALIDATION_PARAMS = TPCERT_X942_DH_VALIDATION_PARAMS

type TCERT_X942_DH_PARAMETERS = struct {
	Fp                 TCRYPT_UINT_BLOB
	Fg                 TCRYPT_UINT_BLOB
	Fq                 TCRYPT_UINT_BLOB
	Fj                 TCRYPT_UINT_BLOB
	FpValidationParams TPCERT_X942_DH_VALIDATION_PARAMS
}

type CERT_X942_DH_PARAMETERS = TCERT_X942_DH_PARAMETERS

type T_CERT_X942_DH_PARAMETERS = TCERT_X942_DH_PARAMETERS

type _CERT_X942_DH_PARAMETERS = T_CERT_X942_DH_PARAMETERS

type TPCERT_X942_DH_PARAMETERS = uintptr

type PCERT_X942_DH_PARAMETERS = TPCERT_X942_DH_PARAMETERS

type TCRYPT_X942_OTHER_INFO = struct {
	FpszContentEncryptionObjId TLPSTR
	FrgbCounter                [4]TBYTE
	FrgbKeyLength              [4]TBYTE
	FPubInfo                   TCRYPT_DATA_BLOB
}

type CRYPT_X942_OTHER_INFO = TCRYPT_X942_OTHER_INFO

type T_CRYPT_X942_OTHER_INFO = TCRYPT_X942_OTHER_INFO

type _CRYPT_X942_OTHER_INFO = T_CRYPT_X942_OTHER_INFO

type TPCRYPT_X942_OTHER_INFO = uintptr

type PCRYPT_X942_OTHER_INFO = TPCRYPT_X942_OTHER_INFO

type TCRYPT_ECC_CMS_SHARED_INFO = struct {
	FAlgorithm      TCRYPT_ALGORITHM_IDENTIFIER
	FEntityUInfo    TCRYPT_DATA_BLOB
	FrgbSuppPubInfo [4]TBYTE
}

type CRYPT_ECC_CMS_SHARED_INFO = TCRYPT_ECC_CMS_SHARED_INFO

type T_CRYPT_ECC_CMS_SHARED_INFO = TCRYPT_ECC_CMS_SHARED_INFO

type _CRYPT_ECC_CMS_SHARED_INFO = T_CRYPT_ECC_CMS_SHARED_INFO

type TPCRYPT_ECC_CMS_SHARED_INFO = uintptr

type PCRYPT_ECC_CMS_SHARED_INFO = TPCRYPT_ECC_CMS_SHARED_INFO

type TCRYPT_RC2_CBC_PARAMETERS = struct {
	FdwVersion TDWORD
	FfIV       TWINBOOL
	FrgbIV     [8]TBYTE
}

type CRYPT_RC2_CBC_PARAMETERS = TCRYPT_RC2_CBC_PARAMETERS

type T_CRYPT_RC2_CBC_PARAMETERS = TCRYPT_RC2_CBC_PARAMETERS

type _CRYPT_RC2_CBC_PARAMETERS = T_CRYPT_RC2_CBC_PARAMETERS

type TPCRYPT_RC2_CBC_PARAMETERS = uintptr

type PCRYPT_RC2_CBC_PARAMETERS = TPCRYPT_RC2_CBC_PARAMETERS

type TCRYPT_SMIME_CAPABILITY = struct {
	FpszObjId   TLPSTR
	FParameters TCRYPT_OBJID_BLOB
}

type CRYPT_SMIME_CAPABILITY = TCRYPT_SMIME_CAPABILITY

type T_CRYPT_SMIME_CAPABILITY = TCRYPT_SMIME_CAPABILITY

type _CRYPT_SMIME_CAPABILITY = T_CRYPT_SMIME_CAPABILITY

type TPCRYPT_SMIME_CAPABILITY = uintptr

type PCRYPT_SMIME_CAPABILITY = TPCRYPT_SMIME_CAPABILITY

type TCRYPT_SMIME_CAPABILITIES = struct {
	FcCapability  TDWORD
	FrgCapability TPCRYPT_SMIME_CAPABILITY
}

type CRYPT_SMIME_CAPABILITIES = TCRYPT_SMIME_CAPABILITIES

type T_CRYPT_SMIME_CAPABILITIES = TCRYPT_SMIME_CAPABILITIES

type _CRYPT_SMIME_CAPABILITIES = T_CRYPT_SMIME_CAPABILITIES

type TPCRYPT_SMIME_CAPABILITIES = uintptr

type PCRYPT_SMIME_CAPABILITIES = TPCRYPT_SMIME_CAPABILITIES

type TCERT_QC_STATEMENT = struct {
	FpszStatementId TLPSTR
	FStatementInfo  TCRYPT_OBJID_BLOB
}

type CERT_QC_STATEMENT = TCERT_QC_STATEMENT

type T_CERT_QC_STATEMENT = TCERT_QC_STATEMENT

type _CERT_QC_STATEMENT = T_CERT_QC_STATEMENT

type TPCERT_QC_STATEMENT = uintptr

type PCERT_QC_STATEMENT = TPCERT_QC_STATEMENT

type TCERT_QC_STATEMENTS_EXT_INFO = struct {
	FcStatement  TDWORD
	FrgStatement TPCERT_QC_STATEMENT
}

type CERT_QC_STATEMENTS_EXT_INFO = TCERT_QC_STATEMENTS_EXT_INFO

type T_CERT_QC_STATEMENTS_EXT_INFO = TCERT_QC_STATEMENTS_EXT_INFO

type _CERT_QC_STATEMENTS_EXT_INFO = T_CERT_QC_STATEMENTS_EXT_INFO

type TPCERT_QC_STATEMENTS_EXT_INFO = uintptr

type PCERT_QC_STATEMENTS_EXT_INFO = TPCERT_QC_STATEMENTS_EXT_INFO

type TCRYPT_MASK_GEN_ALGORITHM = struct {
	FpszObjId      TLPSTR
	FHashAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
}

type CRYPT_MASK_GEN_ALGORITHM = TCRYPT_MASK_GEN_ALGORITHM

type T_CRYPT_MASK_GEN_ALGORITHM = TCRYPT_MASK_GEN_ALGORITHM

type _CRYPT_MASK_GEN_ALGORITHM = T_CRYPT_MASK_GEN_ALGORITHM

type TPCRYPT_MASK_GEN_ALGORITHM = uintptr

type PCRYPT_MASK_GEN_ALGORITHM = TPCRYPT_MASK_GEN_ALGORITHM

type TCRYPT_RSA_SSA_PSS_PARAMETERS = struct {
	FHashAlgorithm    TCRYPT_ALGORITHM_IDENTIFIER
	FMaskGenAlgorithm TCRYPT_MASK_GEN_ALGORITHM
	FdwSaltLength     TDWORD
	FdwTrailerField   TDWORD
}

type CRYPT_RSA_SSA_PSS_PARAMETERS = TCRYPT_RSA_SSA_PSS_PARAMETERS

type T_CRYPT_RSA_SSA_PSS_PARAMETERS = TCRYPT_RSA_SSA_PSS_PARAMETERS

type _CRYPT_RSA_SSA_PSS_PARAMETERS = T_CRYPT_RSA_SSA_PSS_PARAMETERS

type TPCRYPT_RSA_SSA_PSS_PARAMETERS = uintptr

type PCRYPT_RSA_SSA_PSS_PARAMETERS = TPCRYPT_RSA_SSA_PSS_PARAMETERS

type TCRYPT_PSOURCE_ALGORITHM = struct {
	FpszObjId           TLPSTR
	FEncodingParameters TCRYPT_DATA_BLOB
}

type CRYPT_PSOURCE_ALGORITHM = TCRYPT_PSOURCE_ALGORITHM

type T_CRYPT_PSOURCE_ALGORITHM = TCRYPT_PSOURCE_ALGORITHM

type _CRYPT_PSOURCE_ALGORITHM = T_CRYPT_PSOURCE_ALGORITHM

type TPCRYPT_PSOURCE_ALGORITHM = uintptr

type PCRYPT_PSOURCE_ALGORITHM = TPCRYPT_PSOURCE_ALGORITHM

type TCRYPT_RSAES_OAEP_PARAMETERS = struct {
	FHashAlgorithm    TCRYPT_ALGORITHM_IDENTIFIER
	FMaskGenAlgorithm TCRYPT_MASK_GEN_ALGORITHM
	FPSourceAlgorithm TCRYPT_PSOURCE_ALGORITHM
}

type CRYPT_RSAES_OAEP_PARAMETERS = TCRYPT_RSAES_OAEP_PARAMETERS

type T_CRYPT_RSAES_OAEP_PARAMETERS = TCRYPT_RSAES_OAEP_PARAMETERS

type _CRYPT_RSAES_OAEP_PARAMETERS = T_CRYPT_RSAES_OAEP_PARAMETERS

type TPCRYPT_RSAES_OAEP_PARAMETERS = uintptr

type PCRYPT_RSAES_OAEP_PARAMETERS = TPCRYPT_RSAES_OAEP_PARAMETERS

type TCMC_TAGGED_ATTRIBUTE = struct {
	FdwBodyPartID TDWORD
	FAttribute    TCRYPT_ATTRIBUTE
}

type CMC_TAGGED_ATTRIBUTE = TCMC_TAGGED_ATTRIBUTE

type T_CMC_TAGGED_ATTRIBUTE = TCMC_TAGGED_ATTRIBUTE

type _CMC_TAGGED_ATTRIBUTE = T_CMC_TAGGED_ATTRIBUTE

type TPCMC_TAGGED_ATTRIBUTE = uintptr

type PCMC_TAGGED_ATTRIBUTE = TPCMC_TAGGED_ATTRIBUTE

type TCMC_TAGGED_CERT_REQUEST = struct {
	FdwBodyPartID      TDWORD
	FSignedCertRequest TCRYPT_DER_BLOB
}

type CMC_TAGGED_CERT_REQUEST = TCMC_TAGGED_CERT_REQUEST

type T_CMC_TAGGED_CERT_REQUEST = TCMC_TAGGED_CERT_REQUEST

type _CMC_TAGGED_CERT_REQUEST = T_CMC_TAGGED_CERT_REQUEST

type TPCMC_TAGGED_CERT_REQUEST = uintptr

type PCMC_TAGGED_CERT_REQUEST = TPCMC_TAGGED_CERT_REQUEST

type TCMC_TAGGED_REQUEST = struct {
	FdwTaggedRequestChoice TDWORD
	F__ccgo1_4             struct {
		FpTaggedCertRequest TPCMC_TAGGED_CERT_REQUEST
	}
}

type CMC_TAGGED_REQUEST = TCMC_TAGGED_REQUEST

type T_CMC_TAGGED_REQUEST = TCMC_TAGGED_REQUEST

type _CMC_TAGGED_REQUEST = T_CMC_TAGGED_REQUEST

type TPCMC_TAGGED_REQUEST = uintptr

type PCMC_TAGGED_REQUEST = TPCMC_TAGGED_REQUEST

type TCMC_TAGGED_CONTENT_INFO = struct {
	FdwBodyPartID       TDWORD
	FEncodedContentInfo TCRYPT_DER_BLOB
}

type CMC_TAGGED_CONTENT_INFO = TCMC_TAGGED_CONTENT_INFO

type T_CMC_TAGGED_CONTENT_INFO = TCMC_TAGGED_CONTENT_INFO

type _CMC_TAGGED_CONTENT_INFO = T_CMC_TAGGED_CONTENT_INFO

type TPCMC_TAGGED_CONTENT_INFO = uintptr

type PCMC_TAGGED_CONTENT_INFO = TPCMC_TAGGED_CONTENT_INFO

type TCMC_TAGGED_OTHER_MSG = struct {
	FdwBodyPartID TDWORD
	FpszObjId     TLPSTR
	FValue        TCRYPT_OBJID_BLOB
}

type CMC_TAGGED_OTHER_MSG = TCMC_TAGGED_OTHER_MSG

type T_CMC_TAGGED_OTHER_MSG = TCMC_TAGGED_OTHER_MSG

type _CMC_TAGGED_OTHER_MSG = T_CMC_TAGGED_OTHER_MSG

type TPCMC_TAGGED_OTHER_MSG = uintptr

type PCMC_TAGGED_OTHER_MSG = TPCMC_TAGGED_OTHER_MSG

type TCMC_DATA_INFO = struct {
	FcTaggedAttribute    TDWORD
	FrgTaggedAttribute   TPCMC_TAGGED_ATTRIBUTE
	FcTaggedRequest      TDWORD
	FrgTaggedRequest     TPCMC_TAGGED_REQUEST
	FcTaggedContentInfo  TDWORD
	FrgTaggedContentInfo TPCMC_TAGGED_CONTENT_INFO
	FcTaggedOtherMsg     TDWORD
	FrgTaggedOtherMsg    TPCMC_TAGGED_OTHER_MSG
}

type CMC_DATA_INFO = TCMC_DATA_INFO

type T_CMC_DATA_INFO = TCMC_DATA_INFO

type _CMC_DATA_INFO = T_CMC_DATA_INFO

type TPCMC_DATA_INFO = uintptr

type PCMC_DATA_INFO = TPCMC_DATA_INFO

type TCMC_RESPONSE_INFO = struct {
	FcTaggedAttribute    TDWORD
	FrgTaggedAttribute   TPCMC_TAGGED_ATTRIBUTE
	FcTaggedContentInfo  TDWORD
	FrgTaggedContentInfo TPCMC_TAGGED_CONTENT_INFO
	FcTaggedOtherMsg     TDWORD
	FrgTaggedOtherMsg    TPCMC_TAGGED_OTHER_MSG
}

type CMC_RESPONSE_INFO = TCMC_RESPONSE_INFO

type T_CMC_RESPONSE_INFO = TCMC_RESPONSE_INFO

type _CMC_RESPONSE_INFO = T_CMC_RESPONSE_INFO

type TPCMC_RESPONSE_INFO = uintptr

type PCMC_RESPONSE_INFO = TPCMC_RESPONSE_INFO

type TCMC_PEND_INFO = struct {
	FPendToken TCRYPT_DATA_BLOB
	FPendTime  TFILETIME
}

type CMC_PEND_INFO = TCMC_PEND_INFO

type T_CMC_PEND_INFO = TCMC_PEND_INFO

type _CMC_PEND_INFO = T_CMC_PEND_INFO

type TPCMC_PEND_INFO = uintptr

type PCMC_PEND_INFO = TPCMC_PEND_INFO

type TCMC_STATUS_INFO = struct {
	FdwStatus          TDWORD
	FcBodyList         TDWORD
	FrgdwBodyList      uintptr
	FpwszStatusString  TLPWSTR
	FdwOtherInfoChoice TDWORD
	F__ccgo5_20        struct {
		FpPendInfo  [0]TPCMC_PEND_INFO
		FdwFailInfo TDWORD
	}
}

type CMC_STATUS_INFO = TCMC_STATUS_INFO

type T_CMC_STATUS_INFO = TCMC_STATUS_INFO

type _CMC_STATUS_INFO = T_CMC_STATUS_INFO

type TPCMC_STATUS_INFO = uintptr

type PCMC_STATUS_INFO = TPCMC_STATUS_INFO

type TCMC_ADD_EXTENSIONS_INFO = struct {
	FdwCmcDataReference TDWORD
	FcCertReference     TDWORD
	FrgdwCertReference  uintptr
	FcExtension         TDWORD
	FrgExtension        TPCERT_EXTENSION
}

type CMC_ADD_EXTENSIONS_INFO = TCMC_ADD_EXTENSIONS_INFO

type T_CMC_ADD_EXTENSIONS_INFO = TCMC_ADD_EXTENSIONS_INFO

type _CMC_ADD_EXTENSIONS_INFO = T_CMC_ADD_EXTENSIONS_INFO

type TPCMC_ADD_EXTENSIONS_INFO = uintptr

type PCMC_ADD_EXTENSIONS_INFO = TPCMC_ADD_EXTENSIONS_INFO

type TCMC_ADD_ATTRIBUTES_INFO = struct {
	FdwCmcDataReference TDWORD
	FcCertReference     TDWORD
	FrgdwCertReference  uintptr
	FcAttribute         TDWORD
	FrgAttribute        TPCRYPT_ATTRIBUTE
}

type CMC_ADD_ATTRIBUTES_INFO = TCMC_ADD_ATTRIBUTES_INFO

type T_CMC_ADD_ATTRIBUTES_INFO = TCMC_ADD_ATTRIBUTES_INFO

type _CMC_ADD_ATTRIBUTES_INFO = T_CMC_ADD_ATTRIBUTES_INFO

type TPCMC_ADD_ATTRIBUTES_INFO = uintptr

type PCMC_ADD_ATTRIBUTES_INFO = TPCMC_ADD_ATTRIBUTES_INFO

type TCERT_TEMPLATE_EXT = struct {
	FpszObjId       TLPSTR
	FdwMajorVersion TDWORD
	FfMinorVersion  TWINBOOL
	FdwMinorVersion TDWORD
}

type CERT_TEMPLATE_EXT = TCERT_TEMPLATE_EXT

type T_CERT_TEMPLATE_EXT = TCERT_TEMPLATE_EXT

type _CERT_TEMPLATE_EXT = T_CERT_TEMPLATE_EXT

type TPCERT_TEMPLATE_EXT = uintptr

type PCERT_TEMPLATE_EXT = TPCERT_TEMPLATE_EXT

type TCERT_HASHED_URL = struct {
	FHashAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FHash          TCRYPT_HASH_BLOB
	FpwszUrl       TLPWSTR
}

type CERT_HASHED_URL = TCERT_HASHED_URL

type T_CERT_HASHED_URL = TCERT_HASHED_URL

type _CERT_HASHED_URL = T_CERT_HASHED_URL

type TPCERT_HASHED_URL = uintptr

type PCERT_HASHED_URL = TPCERT_HASHED_URL

type TCERT_LOGOTYPE_DETAILS = struct {
	FpwszMimeType TLPWSTR
	FcHashedUrl   TDWORD
	FrgHashedUrl  TPCERT_HASHED_URL
}

type CERT_LOGOTYPE_DETAILS = TCERT_LOGOTYPE_DETAILS

type T_CERT_LOGOTYPE_DETAILS = TCERT_LOGOTYPE_DETAILS

type _CERT_LOGOTYPE_DETAILS = T_CERT_LOGOTYPE_DETAILS

type TPCERT_LOGOTYPE_DETAILS = uintptr

type PCERT_LOGOTYPE_DETAILS = TPCERT_LOGOTYPE_DETAILS

type TCERT_LOGOTYPE_REFERENCE = struct {
	FcHashedUrl  TDWORD
	FrgHashedUrl TPCERT_HASHED_URL
}

type CERT_LOGOTYPE_REFERENCE = TCERT_LOGOTYPE_REFERENCE

type T_CERT_LOGOTYPE_REFERENCE = TCERT_LOGOTYPE_REFERENCE

type _CERT_LOGOTYPE_REFERENCE = T_CERT_LOGOTYPE_REFERENCE

type TPCERT_LOGOTYPE_REFERENCE = uintptr

type PCERT_LOGOTYPE_REFERENCE = TPCERT_LOGOTYPE_REFERENCE

type TCERT_LOGOTYPE_IMAGE_INFO = struct {
	FdwLogotypeImageInfoChoice       TDWORD
	FdwFileSize                      TDWORD
	FdwXSize                         TDWORD
	FdwYSize                         TDWORD
	FdwLogotypeImageResolutionChoice TDWORD
	F__ccgo5_20                      struct {
		FdwTableSize [0]TDWORD
		FdwNumBits   TDWORD
	}
	FpwszLanguage TLPWSTR
}

type CERT_LOGOTYPE_IMAGE_INFO = TCERT_LOGOTYPE_IMAGE_INFO

type T_CERT_LOGOTYPE_IMAGE_INFO = TCERT_LOGOTYPE_IMAGE_INFO

type _CERT_LOGOTYPE_IMAGE_INFO = T_CERT_LOGOTYPE_IMAGE_INFO

type TPCERT_LOGOTYPE_IMAGE_INFO = uintptr

type PCERT_LOGOTYPE_IMAGE_INFO = TPCERT_LOGOTYPE_IMAGE_INFO

type TCERT_LOGOTYPE_IMAGE = struct {
	FLogotypeDetails    TCERT_LOGOTYPE_DETAILS
	FpLogotypeImageInfo TPCERT_LOGOTYPE_IMAGE_INFO
}

type CERT_LOGOTYPE_IMAGE = TCERT_LOGOTYPE_IMAGE

type T_CERT_LOGOTYPE_IMAGE = TCERT_LOGOTYPE_IMAGE

type _CERT_LOGOTYPE_IMAGE = T_CERT_LOGOTYPE_IMAGE

type TPCERT_LOGOTYPE_IMAGE = uintptr

type PCERT_LOGOTYPE_IMAGE = TPCERT_LOGOTYPE_IMAGE

type TCERT_LOGOTYPE_AUDIO_INFO = struct {
	FdwFileSize   TDWORD
	FdwPlayTime   TDWORD
	FdwChannels   TDWORD
	FdwSampleRate TDWORD
	FpwszLanguage TLPWSTR
}

type CERT_LOGOTYPE_AUDIO_INFO = TCERT_LOGOTYPE_AUDIO_INFO

type T_CERT_LOGOTYPE_AUDIO_INFO = TCERT_LOGOTYPE_AUDIO_INFO

type _CERT_LOGOTYPE_AUDIO_INFO = T_CERT_LOGOTYPE_AUDIO_INFO

type TPCERT_LOGOTYPE_AUDIO_INFO = uintptr

type PCERT_LOGOTYPE_AUDIO_INFO = TPCERT_LOGOTYPE_AUDIO_INFO

type TCERT_LOGOTYPE_AUDIO = struct {
	FLogotypeDetails    TCERT_LOGOTYPE_DETAILS
	FpLogotypeAudioInfo TPCERT_LOGOTYPE_AUDIO_INFO
}

type CERT_LOGOTYPE_AUDIO = TCERT_LOGOTYPE_AUDIO

type T_CERT_LOGOTYPE_AUDIO = TCERT_LOGOTYPE_AUDIO

type _CERT_LOGOTYPE_AUDIO = T_CERT_LOGOTYPE_AUDIO

type TPCERT_LOGOTYPE_AUDIO = uintptr

type PCERT_LOGOTYPE_AUDIO = TPCERT_LOGOTYPE_AUDIO

type TCERT_LOGOTYPE_DATA = struct {
	FcLogotypeImage  TDWORD
	FrgLogotypeImage TPCERT_LOGOTYPE_IMAGE
	FcLogotypeAudio  TDWORD
	FrgLogotypeAudio TPCERT_LOGOTYPE_AUDIO
}

type CERT_LOGOTYPE_DATA = TCERT_LOGOTYPE_DATA

type T_CERT_LOGOTYPE_DATA = TCERT_LOGOTYPE_DATA

type _CERT_LOGOTYPE_DATA = T_CERT_LOGOTYPE_DATA

type TPCERT_LOGOTYPE_DATA = uintptr

type PCERT_LOGOTYPE_DATA = TPCERT_LOGOTYPE_DATA

type TCERT_LOGOTYPE_INFO = struct {
	FdwLogotypeInfoChoice TDWORD
	F__ccgo1_4            struct {
		FpLogotypeIndirectInfo [0]TPCERT_LOGOTYPE_REFERENCE
		FpLogotypeDirectInfo   TPCERT_LOGOTYPE_DATA
	}
}

type CERT_LOGOTYPE_INFO = TCERT_LOGOTYPE_INFO

type T_CERT_LOGOTYPE_INFO = TCERT_LOGOTYPE_INFO

type _CERT_LOGOTYPE_INFO = T_CERT_LOGOTYPE_INFO

type TPCERT_LOGOTYPE_INFO = uintptr

type PCERT_LOGOTYPE_INFO = TPCERT_LOGOTYPE_INFO

type TCERT_OTHER_LOGOTYPE_INFO = struct {
	FpszObjId     TLPSTR
	FLogotypeInfo TCERT_LOGOTYPE_INFO
}

type CERT_OTHER_LOGOTYPE_INFO = TCERT_OTHER_LOGOTYPE_INFO

type T_CERT_OTHER_LOGOTYPE_INFO = TCERT_OTHER_LOGOTYPE_INFO

type _CERT_OTHER_LOGOTYPE_INFO = T_CERT_OTHER_LOGOTYPE_INFO

type TPCERT_OTHER_LOGOTYPE_INFO = uintptr

type PCERT_OTHER_LOGOTYPE_INFO = TPCERT_OTHER_LOGOTYPE_INFO

type TCERT_LOGOTYPE_EXT_INFO = struct {
	FcCommunityLogo  TDWORD
	FrgCommunityLogo TPCERT_LOGOTYPE_INFO
	FpIssuerLogo     TPCERT_LOGOTYPE_INFO
	FpSubjectLogo    TPCERT_LOGOTYPE_INFO
	FcOtherLogo      TDWORD
	FrgOtherLogo     TPCERT_OTHER_LOGOTYPE_INFO
}

type CERT_LOGOTYPE_EXT_INFO = TCERT_LOGOTYPE_EXT_INFO

type T_CERT_LOGOTYPE_EXT_INFO = TCERT_LOGOTYPE_EXT_INFO

type _CERT_LOGOTYPE_EXT_INFO = T_CERT_LOGOTYPE_EXT_INFO

type TPCERT_LOGOTYPE_EXT_INFO = uintptr

type PCERT_LOGOTYPE_EXT_INFO = TPCERT_LOGOTYPE_EXT_INFO

type TCERT_BIOMETRIC_DATA = struct {
	FdwTypeOfBiometricDataChoice TDWORD
	F__ccgo1_4                   struct {
		FpszObjId     [0]TLPSTR
		FdwPredefined TDWORD
	}
	FHashedUrl TCERT_HASHED_URL
}

type CERT_BIOMETRIC_DATA = TCERT_BIOMETRIC_DATA

type T_CERT_BIOMETRIC_DATA = TCERT_BIOMETRIC_DATA

type _CERT_BIOMETRIC_DATA = T_CERT_BIOMETRIC_DATA

type TPCERT_BIOMETRIC_DATA = uintptr

type PCERT_BIOMETRIC_DATA = TPCERT_BIOMETRIC_DATA

type TCERT_BIOMETRIC_EXT_INFO = struct {
	FcBiometricData  TDWORD
	FrgBiometricData TPCERT_BIOMETRIC_DATA
}

type CERT_BIOMETRIC_EXT_INFO = TCERT_BIOMETRIC_EXT_INFO

type T_CERT_BIOMETRIC_EXT_INFO = TCERT_BIOMETRIC_EXT_INFO

type _CERT_BIOMETRIC_EXT_INFO = T_CERT_BIOMETRIC_EXT_INFO

type TPCERT_BIOMETRIC_EXT_INFO = uintptr

type PCERT_BIOMETRIC_EXT_INFO = TPCERT_BIOMETRIC_EXT_INFO

type TOCSP_SIGNATURE_INFO = struct {
	FSignatureAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FSignature          TCRYPT_BIT_BLOB
	FcCertEncoded       TDWORD
	FrgCertEncoded      TPCERT_BLOB
}

type OCSP_SIGNATURE_INFO = TOCSP_SIGNATURE_INFO

type T_OCSP_SIGNATURE_INFO = TOCSP_SIGNATURE_INFO

type _OCSP_SIGNATURE_INFO = T_OCSP_SIGNATURE_INFO

type TPOCSP_SIGNATURE_INFO = uintptr

type POCSP_SIGNATURE_INFO = TPOCSP_SIGNATURE_INFO

type TOCSP_SIGNED_REQUEST_INFO = struct {
	FToBeSigned             TCRYPT_DER_BLOB
	FpOptionalSignatureInfo TPOCSP_SIGNATURE_INFO
}

type OCSP_SIGNED_REQUEST_INFO = TOCSP_SIGNED_REQUEST_INFO

type T_OCSP_SIGNED_REQUEST_INFO = TOCSP_SIGNED_REQUEST_INFO

type _OCSP_SIGNED_REQUEST_INFO = T_OCSP_SIGNED_REQUEST_INFO

type TPOCSP_SIGNED_REQUEST_INFO = uintptr

type POCSP_SIGNED_REQUEST_INFO = TPOCSP_SIGNED_REQUEST_INFO

type TOCSP_CERT_ID = struct {
	FHashAlgorithm  TCRYPT_ALGORITHM_IDENTIFIER
	FIssuerNameHash TCRYPT_HASH_BLOB
	FIssuerKeyHash  TCRYPT_HASH_BLOB
	FSerialNumber   TCRYPT_INTEGER_BLOB
}

type OCSP_CERT_ID = TOCSP_CERT_ID

type T_OCSP_CERT_ID = TOCSP_CERT_ID

type _OCSP_CERT_ID = T_OCSP_CERT_ID

type TPOCSP_CERT_ID = uintptr

type POCSP_CERT_ID = TPOCSP_CERT_ID

type TOCSP_REQUEST_ENTRY = struct {
	FCertId      TOCSP_CERT_ID
	FcExtension  TDWORD
	FrgExtension TPCERT_EXTENSION
}

type OCSP_REQUEST_ENTRY = TOCSP_REQUEST_ENTRY

type T_OCSP_REQUEST_ENTRY = TOCSP_REQUEST_ENTRY

type _OCSP_REQUEST_ENTRY = T_OCSP_REQUEST_ENTRY

type TPOCSP_REQUEST_ENTRY = uintptr

type POCSP_REQUEST_ENTRY = TPOCSP_REQUEST_ENTRY

type TOCSP_REQUEST_INFO = struct {
	FdwVersion      TDWORD
	FpRequestorName TPCERT_ALT_NAME_ENTRY
	FcRequestEntry  TDWORD
	FrgRequestEntry TPOCSP_REQUEST_ENTRY
	FcExtension     TDWORD
	FrgExtension    TPCERT_EXTENSION
}

type OCSP_REQUEST_INFO = TOCSP_REQUEST_INFO

type T_OCSP_REQUEST_INFO = TOCSP_REQUEST_INFO

type _OCSP_REQUEST_INFO = T_OCSP_REQUEST_INFO

type TPOCSP_REQUEST_INFO = uintptr

type POCSP_REQUEST_INFO = TPOCSP_REQUEST_INFO

type TOCSP_RESPONSE_INFO = struct {
	FdwStatus TDWORD
	FpszObjId TLPSTR
	FValue    TCRYPT_OBJID_BLOB
}

type OCSP_RESPONSE_INFO = TOCSP_RESPONSE_INFO

type T_OCSP_RESPONSE_INFO = TOCSP_RESPONSE_INFO

type _OCSP_RESPONSE_INFO = T_OCSP_RESPONSE_INFO

type TPOCSP_RESPONSE_INFO = uintptr

type POCSP_RESPONSE_INFO = TPOCSP_RESPONSE_INFO

type TOCSP_BASIC_SIGNED_RESPONSE_INFO = struct {
	FToBeSigned    TCRYPT_DER_BLOB
	FSignatureInfo TOCSP_SIGNATURE_INFO
}

type OCSP_BASIC_SIGNED_RESPONSE_INFO = TOCSP_BASIC_SIGNED_RESPONSE_INFO

type T_OCSP_BASIC_SIGNED_RESPONSE_INFO = TOCSP_BASIC_SIGNED_RESPONSE_INFO

type _OCSP_BASIC_SIGNED_RESPONSE_INFO = T_OCSP_BASIC_SIGNED_RESPONSE_INFO

type TPOCSP_BASIC_SIGNED_RESPONSE_INFO = uintptr

type POCSP_BASIC_SIGNED_RESPONSE_INFO = TPOCSP_BASIC_SIGNED_RESPONSE_INFO

type TOCSP_BASIC_REVOKED_INFO = struct {
	FRevocationDate  TFILETIME
	FdwCrlReasonCode TDWORD
}

type OCSP_BASIC_REVOKED_INFO = TOCSP_BASIC_REVOKED_INFO

type T_OCSP_BASIC_REVOKED_INFO = TOCSP_BASIC_REVOKED_INFO

type _OCSP_BASIC_REVOKED_INFO = T_OCSP_BASIC_REVOKED_INFO

type TPOCSP_BASIC_REVOKED_INFO = uintptr

type POCSP_BASIC_REVOKED_INFO = TPOCSP_BASIC_REVOKED_INFO

type TOCSP_BASIC_RESPONSE_ENTRY = struct {
	FCertId       TOCSP_CERT_ID
	FdwCertStatus TDWORD
	F__ccgo2_40   struct {
		FpRevokedInfo TPOCSP_BASIC_REVOKED_INFO
	}
	FThisUpdate  TFILETIME
	FNextUpdate  TFILETIME
	FcExtension  TDWORD
	FrgExtension TPCERT_EXTENSION
}

type OCSP_BASIC_RESPONSE_ENTRY = TOCSP_BASIC_RESPONSE_ENTRY

type T_OCSP_BASIC_RESPONSE_ENTRY = TOCSP_BASIC_RESPONSE_ENTRY

type _OCSP_BASIC_RESPONSE_ENTRY = T_OCSP_BASIC_RESPONSE_ENTRY

type TPOCSP_BASIC_RESPONSE_ENTRY = uintptr

type POCSP_BASIC_RESPONSE_ENTRY = TPOCSP_BASIC_RESPONSE_ENTRY

type TOCSP_BASIC_RESPONSE_INFO = struct {
	FdwVersion           TDWORD
	FdwResponderIdChoice TDWORD
	F__ccgo2_8           struct {
		FByKeyResponderId  [0]TCRYPT_HASH_BLOB
		FByNameResponderId TCERT_NAME_BLOB
	}
	FProducedAt      TFILETIME
	FcResponseEntry  TDWORD
	FrgResponseEntry TPOCSP_BASIC_RESPONSE_ENTRY
	FcExtension      TDWORD
	FrgExtension     TPCERT_EXTENSION
}

type OCSP_BASIC_RESPONSE_INFO = TOCSP_BASIC_RESPONSE_INFO

type T_OCSP_BASIC_RESPONSE_INFO = TOCSP_BASIC_RESPONSE_INFO

type _OCSP_BASIC_RESPONSE_INFO = T_OCSP_BASIC_RESPONSE_INFO

type TPOCSP_BASIC_RESPONSE_INFO = uintptr

type POCSP_BASIC_RESPONSE_INFO = TPOCSP_BASIC_RESPONSE_INFO

type TCERT_SUPPORTED_ALGORITHM_INFO = struct {
	FAlgorithm            TCRYPT_ALGORITHM_IDENTIFIER
	FIntendedKeyUsage     TCRYPT_BIT_BLOB
	FIntendedCertPolicies TCERT_POLICIES_INFO
}

type CERT_SUPPORTED_ALGORITHM_INFO = TCERT_SUPPORTED_ALGORITHM_INFO

type T_CERT_SUPPORTED_ALGORITHM_INFO = TCERT_SUPPORTED_ALGORITHM_INFO

type _CERT_SUPPORTED_ALGORITHM_INFO = T_CERT_SUPPORTED_ALGORITHM_INFO

type TPCERT_SUPPORTED_ALGORITHM_INFO = uintptr

type PCERT_SUPPORTED_ALGORITHM_INFO = TPCERT_SUPPORTED_ALGORITHM_INFO

type TCERT_TPM_SPECIFICATION_INFO = struct {
	FpwszFamily TLPWSTR
	FdwLevel    TDWORD
	FdwRevision TDWORD
}

type CERT_TPM_SPECIFICATION_INFO = TCERT_TPM_SPECIFICATION_INFO

type T_CERT_TPM_SPECIFICATION_INFO = TCERT_TPM_SPECIFICATION_INFO

type _CERT_TPM_SPECIFICATION_INFO = T_CERT_TPM_SPECIFICATION_INFO

type TPCERT_TPM_SPECIFICATION_INFO = uintptr

type PCERT_TPM_SPECIFICATION_INFO = TPCERT_TPM_SPECIFICATION_INFO

type THCRYPTOIDFUNCSET = uintptr

type HCRYPTOIDFUNCSET = THCRYPTOIDFUNCSET

type THCRYPTOIDFUNCADDR = uintptr

type HCRYPTOIDFUNCADDR = THCRYPTOIDFUNCADDR

type TCRYPT_OID_FUNC_ENTRY = struct {
	FpszOID     TLPCSTR
	FpvFuncAddr uintptr
}

type CRYPT_OID_FUNC_ENTRY = TCRYPT_OID_FUNC_ENTRY

type T_CRYPT_OID_FUNC_ENTRY = TCRYPT_OID_FUNC_ENTRY

type _CRYPT_OID_FUNC_ENTRY = T_CRYPT_OID_FUNC_ENTRY

type TPCRYPT_OID_FUNC_ENTRY = uintptr

type PCRYPT_OID_FUNC_ENTRY = TPCRYPT_OID_FUNC_ENTRY

type TPFN_CRYPT_ENUM_OID_FUNC = uintptr

type PFN_CRYPT_ENUM_OID_FUNC = TPFN_CRYPT_ENUM_OID_FUNC

type TCRYPT_OID_INFO = struct {
	FcbSize     TDWORD
	FpszOID     TLPCSTR
	FpwszName   TLPCWSTR
	FdwGroupId  TDWORD
	F__ccgo4_16 struct {
		FAlgid    [0]TALG_ID
		FdwLength [0]TDWORD
		FdwValue  TDWORD
	}
	FExtraInfo TCRYPT_DATA_BLOB
}

type CRYPT_OID_INFO = TCRYPT_OID_INFO

type T_CRYPT_OID_INFO = TCRYPT_OID_INFO

type _CRYPT_OID_INFO = T_CRYPT_OID_INFO

type TPCRYPT_OID_INFO = uintptr

type PCRYPT_OID_INFO = TPCRYPT_OID_INFO

type TCCRYPT_OID_INFO = struct {
	FcbSize     TDWORD
	FpszOID     TLPCSTR
	FpwszName   TLPCWSTR
	FdwGroupId  TDWORD
	F__ccgo4_16 struct {
		FAlgid    [0]TALG_ID
		FdwLength [0]TDWORD
		FdwValue  TDWORD
	}
	FExtraInfo TCRYPT_DATA_BLOB
}

type CCRYPT_OID_INFO = TCCRYPT_OID_INFO

type TPCCRYPT_OID_INFO = uintptr

type PCCRYPT_OID_INFO = TPCCRYPT_OID_INFO

type TPFN_CRYPT_ENUM_OID_INFO = uintptr

type PFN_CRYPT_ENUM_OID_INFO = TPFN_CRYPT_ENUM_OID_INFO

type TCERT_STRONG_SIGN_SERIALIZED_INFO = struct {
	FdwFlags                    TDWORD
	FpwszCNGSignHashAlgids      TLPWSTR
	FpwszCNGPubKeyMinBitLengths TLPWSTR
}

type CERT_STRONG_SIGN_SERIALIZED_INFO = TCERT_STRONG_SIGN_SERIALIZED_INFO

type T_CERT_STRONG_SIGN_SERIALIZED_INFO = TCERT_STRONG_SIGN_SERIALIZED_INFO

type _CERT_STRONG_SIGN_SERIALIZED_INFO = T_CERT_STRONG_SIGN_SERIALIZED_INFO

type TPCERT_STRONG_SIGN_SERIALIZED_INFO = uintptr

type PCERT_STRONG_SIGN_SERIALIZED_INFO = TPCERT_STRONG_SIGN_SERIALIZED_INFO

type TCERT_STRONG_SIGN_PARA = struct {
	FcbSize       TDWORD
	FdwInfoChoice TDWORD
	F__ccgo2_8    struct {
		FpSerializedInfo [0]TPCERT_STRONG_SIGN_SERIALIZED_INFO
		FpszOID          [0]TLPSTR
		FpvInfo          uintptr
	}
}

type CERT_STRONG_SIGN_PARA = TCERT_STRONG_SIGN_PARA

type T_CERT_STRONG_SIGN_PARA = TCERT_STRONG_SIGN_PARA

type _CERT_STRONG_SIGN_PARA = T_CERT_STRONG_SIGN_PARA

type TPCERT_STRONG_SIGN_PARA = uintptr

type PCERT_STRONG_SIGN_PARA = TPCERT_STRONG_SIGN_PARA

type TPCCERT_STRONG_SIGN_PARA = uintptr

type PCCERT_STRONG_SIGN_PARA = TPCCERT_STRONG_SIGN_PARA

type THCRYPTMSG = uintptr

type HCRYPTMSG = THCRYPTMSG

type TCERT_ISSUER_SERIAL_NUMBER = struct {
	FIssuer       TCERT_NAME_BLOB
	FSerialNumber TCRYPT_INTEGER_BLOB
}

type CERT_ISSUER_SERIAL_NUMBER = TCERT_ISSUER_SERIAL_NUMBER

type T_CERT_ISSUER_SERIAL_NUMBER = TCERT_ISSUER_SERIAL_NUMBER

type _CERT_ISSUER_SERIAL_NUMBER = T_CERT_ISSUER_SERIAL_NUMBER

type TPCERT_ISSUER_SERIAL_NUMBER = uintptr

type PCERT_ISSUER_SERIAL_NUMBER = TPCERT_ISSUER_SERIAL_NUMBER

type TCERT_ID = struct {
	FdwIdChoice TDWORD
	F__ccgo1_4  struct {
		FKeyId              [0]TCRYPT_HASH_BLOB
		FHashId             [0]TCRYPT_HASH_BLOB
		FIssuerSerialNumber TCERT_ISSUER_SERIAL_NUMBER
	}
}

type CERT_ID = TCERT_ID

type T_CERT_ID = TCERT_ID

type _CERT_ID = T_CERT_ID

type TPCERT_ID = uintptr

type PCERT_ID = TPCERT_ID

type TCMSG_SIGNER_ENCODE_INFO = struct {
	FcbSize    TDWORD
	FpCertInfo TPCERT_INFO
	F__ccgo2_8 struct {
		FhNCryptKey [0]TNCRYPT_KEY_HANDLE
		FhCryptProv THCRYPTPROV
	}
	FdwKeySpec     TDWORD
	FHashAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvHashAuxInfo uintptr
	FcAuthAttr     TDWORD
	FrgAuthAttr    TPCRYPT_ATTRIBUTE
	FcUnauthAttr   TDWORD
	FrgUnauthAttr  TPCRYPT_ATTRIBUTE
}

type CMSG_SIGNER_ENCODE_INFO = TCMSG_SIGNER_ENCODE_INFO

type T_CMSG_SIGNER_ENCODE_INFO = TCMSG_SIGNER_ENCODE_INFO

type _CMSG_SIGNER_ENCODE_INFO = T_CMSG_SIGNER_ENCODE_INFO

type TPCMSG_SIGNER_ENCODE_INFO = uintptr

type PCMSG_SIGNER_ENCODE_INFO = TPCMSG_SIGNER_ENCODE_INFO

type TCMSG_SIGNED_ENCODE_INFO = struct {
	FcbSize        TDWORD
	FcSigners      TDWORD
	FrgSigners     TPCMSG_SIGNER_ENCODE_INFO
	FcCertEncoded  TDWORD
	FrgCertEncoded TPCERT_BLOB
	FcCrlEncoded   TDWORD
	FrgCrlEncoded  TPCRL_BLOB
}

type CMSG_SIGNED_ENCODE_INFO = TCMSG_SIGNED_ENCODE_INFO

type T_CMSG_SIGNED_ENCODE_INFO = TCMSG_SIGNED_ENCODE_INFO

type _CMSG_SIGNED_ENCODE_INFO = T_CMSG_SIGNED_ENCODE_INFO

type TPCMSG_SIGNED_ENCODE_INFO = uintptr

type PCMSG_SIGNED_ENCODE_INFO = TPCMSG_SIGNED_ENCODE_INFO

type TCMSG_RECIPIENT_ENCODE_INFO = struct {
	FdwRecipientChoice TDWORD
	F__ccgo1_4         struct {
		FpKeyAgree [0]TPCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO
		FpMailList [0]TPCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO
		FpKeyTrans TPCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO
	}
}

type CMSG_RECIPIENT_ENCODE_INFO = TCMSG_RECIPIENT_ENCODE_INFO

type T_CMSG_RECIPIENT_ENCODE_INFO = TCMSG_RECIPIENT_ENCODE_INFO

type _CMSG_RECIPIENT_ENCODE_INFO = T_CMSG_RECIPIENT_ENCODE_INFO

type TPCMSG_RECIPIENT_ENCODE_INFO = uintptr

type PCMSG_RECIPIENT_ENCODE_INFO = TPCMSG_RECIPIENT_ENCODE_INFO

type TCMSG_ENVELOPED_ENCODE_INFO = struct {
	FcbSize                     TDWORD
	FhCryptProv                 THCRYPTPROV_LEGACY
	FContentEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvEncryptionAuxInfo        uintptr
	FcRecipients                TDWORD
	FrgpRecipients              uintptr
}

type CMSG_ENVELOPED_ENCODE_INFO = TCMSG_ENVELOPED_ENCODE_INFO

type T_CMSG_ENVELOPED_ENCODE_INFO = TCMSG_ENVELOPED_ENCODE_INFO

type _CMSG_ENVELOPED_ENCODE_INFO = T_CMSG_ENVELOPED_ENCODE_INFO

type TPCMSG_ENVELOPED_ENCODE_INFO = uintptr

type PCMSG_ENVELOPED_ENCODE_INFO = TPCMSG_ENVELOPED_ENCODE_INFO

type TCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = struct {
	FcbSize                 TDWORD
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvKeyEncryptionAuxInfo uintptr
	FhCryptProv             THCRYPTPROV_LEGACY
	FRecipientPublicKey     TCRYPT_BIT_BLOB
	FRecipientId            TCERT_ID
}

type CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = TCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO

type T_CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = TCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO

type _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = T_CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO

type TPCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = uintptr

type PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = TPCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO

type TCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = struct {
	FcbSize             TDWORD
	FRecipientPublicKey TCRYPT_BIT_BLOB
	FRecipientId        TCERT_ID
	FDate               TFILETIME
	FpOtherAttr         TPCRYPT_ATTRIBUTE_TYPE_VALUE
}

type CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = TCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO

type T_CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = TCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO

type _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = T_CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO

type TPCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = uintptr

type PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = TPCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO

type TCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = struct {
	FcbSize                 TDWORD
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvKeyEncryptionAuxInfo uintptr
	FKeyWrapAlgorithm       TCRYPT_ALGORITHM_IDENTIFIER
	FpvKeyWrapAuxInfo       uintptr
	FhCryptProv             THCRYPTPROV_LEGACY
	FdwKeySpec              TDWORD
	FdwKeyChoice            TDWORD
	F__ccgo8_48             struct {
		FpSenderId           [0]TPCERT_ID
		FpEphemeralAlgorithm TPCRYPT_ALGORITHM_IDENTIFIER
	}
	FUserKeyingMaterial        TCRYPT_DATA_BLOB
	FcRecipientEncryptedKeys   TDWORD
	FrgpRecipientEncryptedKeys uintptr
}

type CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = TCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO

type T_CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = TCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO

type _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = T_CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO

type TPCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = uintptr

type PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = TPCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO

type TCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = struct {
	FcbSize                 TDWORD
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvKeyEncryptionAuxInfo uintptr
	FhCryptProv             THCRYPTPROV
	FdwKeyChoice            TDWORD
	F__ccgo5_28             struct {
		FpvKeyEncryptionKey [0]uintptr
		FhKeyEncryptionKey  THCRYPTKEY
	}
	FKeyId      TCRYPT_DATA_BLOB
	FDate       TFILETIME
	FpOtherAttr TPCRYPT_ATTRIBUTE_TYPE_VALUE
}

type CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = TCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO

type T_CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = TCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO

type _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = T_CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO

type TPCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = uintptr

type PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = TPCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO

type TCMSG_RC2_AUX_INFO = struct {
	FcbSize   TDWORD
	FdwBitLen TDWORD
}

type CMSG_RC2_AUX_INFO = TCMSG_RC2_AUX_INFO

type T_CMSG_RC2_AUX_INFO = TCMSG_RC2_AUX_INFO

type _CMSG_RC2_AUX_INFO = T_CMSG_RC2_AUX_INFO

type TPCMSG_RC2_AUX_INFO = uintptr

type PCMSG_RC2_AUX_INFO = TPCMSG_RC2_AUX_INFO

type TCMSG_SP3_COMPATIBLE_AUX_INFO = struct {
	FcbSize  TDWORD
	FdwFlags TDWORD
}

type CMSG_SP3_COMPATIBLE_AUX_INFO = TCMSG_SP3_COMPATIBLE_AUX_INFO

type T_CMSG_SP3_COMPATIBLE_AUX_INFO = TCMSG_SP3_COMPATIBLE_AUX_INFO

type _CMSG_SP3_COMPATIBLE_AUX_INFO = T_CMSG_SP3_COMPATIBLE_AUX_INFO

type TPCMSG_SP3_COMPATIBLE_AUX_INFO = uintptr

type PCMSG_SP3_COMPATIBLE_AUX_INFO = TPCMSG_SP3_COMPATIBLE_AUX_INFO

type TCMSG_RC4_AUX_INFO = struct {
	FcbSize   TDWORD
	FdwBitLen TDWORD
}

type CMSG_RC4_AUX_INFO = TCMSG_RC4_AUX_INFO

type T_CMSG_RC4_AUX_INFO = TCMSG_RC4_AUX_INFO

type _CMSG_RC4_AUX_INFO = T_CMSG_RC4_AUX_INFO

type TPCMSG_RC4_AUX_INFO = uintptr

type PCMSG_RC4_AUX_INFO = TPCMSG_RC4_AUX_INFO

type TCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = struct {
	FcbSize        TDWORD
	FSignedInfo    TCMSG_SIGNED_ENCODE_INFO
	FEnvelopedInfo TCMSG_ENVELOPED_ENCODE_INFO
}

type CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = TCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO

type T_CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = TCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO

type _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = T_CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO

type TPCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = uintptr

type PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = TPCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO

type TCMSG_HASHED_ENCODE_INFO = struct {
	FcbSize        TDWORD
	FhCryptProv    THCRYPTPROV_LEGACY
	FHashAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvHashAuxInfo uintptr
}

type CMSG_HASHED_ENCODE_INFO = TCMSG_HASHED_ENCODE_INFO

type T_CMSG_HASHED_ENCODE_INFO = TCMSG_HASHED_ENCODE_INFO

type _CMSG_HASHED_ENCODE_INFO = T_CMSG_HASHED_ENCODE_INFO

type TPCMSG_HASHED_ENCODE_INFO = uintptr

type PCMSG_HASHED_ENCODE_INFO = TPCMSG_HASHED_ENCODE_INFO

type TCMSG_ENCRYPTED_ENCODE_INFO = struct {
	FcbSize                     TDWORD
	FContentEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvEncryptionAuxInfo        uintptr
}

type CMSG_ENCRYPTED_ENCODE_INFO = TCMSG_ENCRYPTED_ENCODE_INFO

type T_CMSG_ENCRYPTED_ENCODE_INFO = TCMSG_ENCRYPTED_ENCODE_INFO

type _CMSG_ENCRYPTED_ENCODE_INFO = T_CMSG_ENCRYPTED_ENCODE_INFO

type TPCMSG_ENCRYPTED_ENCODE_INFO = uintptr

type PCMSG_ENCRYPTED_ENCODE_INFO = TPCMSG_ENCRYPTED_ENCODE_INFO

type TPFN_CMSG_STREAM_OUTPUT = uintptr

type PFN_CMSG_STREAM_OUTPUT = TPFN_CMSG_STREAM_OUTPUT

type TCMSG_STREAM_INFO = struct {
	FcbContent       TDWORD
	FpfnStreamOutput TPFN_CMSG_STREAM_OUTPUT
	FpvArg           uintptr
}

type CMSG_STREAM_INFO = TCMSG_STREAM_INFO

type T_CMSG_STREAM_INFO = TCMSG_STREAM_INFO

type _CMSG_STREAM_INFO = T_CMSG_STREAM_INFO

type TPCMSG_STREAM_INFO = uintptr

type PCMSG_STREAM_INFO = TPCMSG_STREAM_INFO

type TCMSG_SIGNER_INFO = struct {
	FdwVersion               TDWORD
	FIssuer                  TCERT_NAME_BLOB
	FSerialNumber            TCRYPT_INTEGER_BLOB
	FHashAlgorithm           TCRYPT_ALGORITHM_IDENTIFIER
	FHashEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FEncryptedHash           TCRYPT_DATA_BLOB
	FAuthAttrs               TCRYPT_ATTRIBUTES
	FUnauthAttrs             TCRYPT_ATTRIBUTES
}

type CMSG_SIGNER_INFO = TCMSG_SIGNER_INFO

type T_CMSG_SIGNER_INFO = TCMSG_SIGNER_INFO

type _CMSG_SIGNER_INFO = T_CMSG_SIGNER_INFO

type TPCMSG_SIGNER_INFO = uintptr

type PCMSG_SIGNER_INFO = TPCMSG_SIGNER_INFO

type TCMSG_CMS_SIGNER_INFO = struct {
	FdwVersion               TDWORD
	FSignerId                TCERT_ID
	FHashAlgorithm           TCRYPT_ALGORITHM_IDENTIFIER
	FHashEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FEncryptedHash           TCRYPT_DATA_BLOB
	FAuthAttrs               TCRYPT_ATTRIBUTES
	FUnauthAttrs             TCRYPT_ATTRIBUTES
}

type CMSG_CMS_SIGNER_INFO = TCMSG_CMS_SIGNER_INFO

type T_CMSG_CMS_SIGNER_INFO = TCMSG_CMS_SIGNER_INFO

type _CMSG_CMS_SIGNER_INFO = T_CMSG_CMS_SIGNER_INFO

type TPCMSG_CMS_SIGNER_INFO = uintptr

type PCMSG_CMS_SIGNER_INFO = TPCMSG_CMS_SIGNER_INFO

type TCMSG_ATTR = struct {
	FcAttr  TDWORD
	FrgAttr TPCRYPT_ATTRIBUTE
}

type CMSG_ATTR = TCMSG_ATTR

type TPCMSG_ATTR = uintptr

type PCMSG_ATTR = TPCMSG_ATTR

type TCMSG_KEY_TRANS_RECIPIENT_INFO = struct {
	FdwVersion              TDWORD
	FRecipientId            TCERT_ID
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FEncryptedKey           TCRYPT_DATA_BLOB
}

type CMSG_KEY_TRANS_RECIPIENT_INFO = TCMSG_KEY_TRANS_RECIPIENT_INFO

type T_CMSG_KEY_TRANS_RECIPIENT_INFO = TCMSG_KEY_TRANS_RECIPIENT_INFO

type _CMSG_KEY_TRANS_RECIPIENT_INFO = T_CMSG_KEY_TRANS_RECIPIENT_INFO

type TPCMSG_KEY_TRANS_RECIPIENT_INFO = uintptr

type PCMSG_KEY_TRANS_RECIPIENT_INFO = TPCMSG_KEY_TRANS_RECIPIENT_INFO

type TCMSG_RECIPIENT_ENCRYPTED_KEY_INFO = struct {
	FRecipientId  TCERT_ID
	FEncryptedKey TCRYPT_DATA_BLOB
	FDate         TFILETIME
	FpOtherAttr   TPCRYPT_ATTRIBUTE_TYPE_VALUE
}

type CMSG_RECIPIENT_ENCRYPTED_KEY_INFO = TCMSG_RECIPIENT_ENCRYPTED_KEY_INFO

type T_CMSG_RECIPIENT_ENCRYPTED_KEY_INFO = TCMSG_RECIPIENT_ENCRYPTED_KEY_INFO

type _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO = T_CMSG_RECIPIENT_ENCRYPTED_KEY_INFO

type TPCMSG_RECIPIENT_ENCRYPTED_KEY_INFO = uintptr

type PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO = TPCMSG_RECIPIENT_ENCRYPTED_KEY_INFO

type TCMSG_KEY_AGREE_RECIPIENT_INFO = struct {
	FdwVersion          TDWORD
	FdwOriginatorChoice TDWORD
	F__ccgo2_8          struct {
		FOriginatorPublicKeyInfo [0]TCERT_PUBLIC_KEY_INFO
		FOriginatorCertId        TCERT_ID
		F__ccgo_pad2             [4]byte
	}
	FUserKeyingMaterial        TCRYPT_DATA_BLOB
	FKeyEncryptionAlgorithm    TCRYPT_ALGORITHM_IDENTIFIER
	FcRecipientEncryptedKeys   TDWORD
	FrgpRecipientEncryptedKeys uintptr
}

type CMSG_KEY_AGREE_RECIPIENT_INFO = TCMSG_KEY_AGREE_RECIPIENT_INFO

type T_CMSG_KEY_AGREE_RECIPIENT_INFO = TCMSG_KEY_AGREE_RECIPIENT_INFO

type _CMSG_KEY_AGREE_RECIPIENT_INFO = T_CMSG_KEY_AGREE_RECIPIENT_INFO

type TPCMSG_KEY_AGREE_RECIPIENT_INFO = uintptr

type PCMSG_KEY_AGREE_RECIPIENT_INFO = TPCMSG_KEY_AGREE_RECIPIENT_INFO

type TCMSG_MAIL_LIST_RECIPIENT_INFO = struct {
	FdwVersion              TDWORD
	FKeyId                  TCRYPT_DATA_BLOB
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FEncryptedKey           TCRYPT_DATA_BLOB
	FDate                   TFILETIME
	FpOtherAttr             TPCRYPT_ATTRIBUTE_TYPE_VALUE
}

type CMSG_MAIL_LIST_RECIPIENT_INFO = TCMSG_MAIL_LIST_RECIPIENT_INFO

type T_CMSG_MAIL_LIST_RECIPIENT_INFO = TCMSG_MAIL_LIST_RECIPIENT_INFO

type _CMSG_MAIL_LIST_RECIPIENT_INFO = T_CMSG_MAIL_LIST_RECIPIENT_INFO

type TPCMSG_MAIL_LIST_RECIPIENT_INFO = uintptr

type PCMSG_MAIL_LIST_RECIPIENT_INFO = TPCMSG_MAIL_LIST_RECIPIENT_INFO

type TCMSG_CMS_RECIPIENT_INFO = struct {
	FdwRecipientChoice TDWORD
	F__ccgo1_4         struct {
		FpKeyAgree [0]TPCMSG_KEY_AGREE_RECIPIENT_INFO
		FpMailList [0]TPCMSG_MAIL_LIST_RECIPIENT_INFO
		FpKeyTrans TPCMSG_KEY_TRANS_RECIPIENT_INFO
	}
}

type CMSG_CMS_RECIPIENT_INFO = TCMSG_CMS_RECIPIENT_INFO

type T_CMSG_CMS_RECIPIENT_INFO = TCMSG_CMS_RECIPIENT_INFO

type _CMSG_CMS_RECIPIENT_INFO = T_CMSG_CMS_RECIPIENT_INFO

type TPCMSG_CMS_RECIPIENT_INFO = uintptr

type PCMSG_CMS_RECIPIENT_INFO = TPCMSG_CMS_RECIPIENT_INFO

type TCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = struct {
	FcbSize        TDWORD
	FhCryptProv    THCRYPTPROV_LEGACY
	FdwSignerIndex TDWORD
	FdwSignerType  TDWORD
	FpvSigner      uintptr
}

type CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = TCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA

type T_CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = TCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA

type _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = T_CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA

type TPCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = uintptr

type PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = TPCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA

type TCMSG_CTRL_DECRYPT_PARA = struct {
	FcbSize    TDWORD
	F__ccgo1_4 struct {
		FhNCryptKey [0]TNCRYPT_KEY_HANDLE
		FhCryptProv THCRYPTPROV
	}
	FdwKeySpec        TDWORD
	FdwRecipientIndex TDWORD
}

type CMSG_CTRL_DECRYPT_PARA = TCMSG_CTRL_DECRYPT_PARA

type T_CMSG_CTRL_DECRYPT_PARA = TCMSG_CTRL_DECRYPT_PARA

type _CMSG_CTRL_DECRYPT_PARA = T_CMSG_CTRL_DECRYPT_PARA

type TPCMSG_CTRL_DECRYPT_PARA = uintptr

type PCMSG_CTRL_DECRYPT_PARA = TPCMSG_CTRL_DECRYPT_PARA

type TCMSG_CTRL_KEY_TRANS_DECRYPT_PARA = struct {
	FcbSize    TDWORD
	F__ccgo1_4 struct {
		FhNCryptKey [0]TNCRYPT_KEY_HANDLE
		FhCryptProv THCRYPTPROV
	}
	FdwKeySpec        TDWORD
	FpKeyTrans        TPCMSG_KEY_TRANS_RECIPIENT_INFO
	FdwRecipientIndex TDWORD
}

type CMSG_CTRL_KEY_TRANS_DECRYPT_PARA = TCMSG_CTRL_KEY_TRANS_DECRYPT_PARA

type T_CMSG_CTRL_KEY_TRANS_DECRYPT_PARA = TCMSG_CTRL_KEY_TRANS_DECRYPT_PARA

type _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA = T_CMSG_CTRL_KEY_TRANS_DECRYPT_PARA

type TPCMSG_CTRL_KEY_TRANS_DECRYPT_PARA = uintptr

type PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA = TPCMSG_CTRL_KEY_TRANS_DECRYPT_PARA

type TCMSG_CTRL_KEY_AGREE_DECRYPT_PARA = struct {
	FcbSize    TDWORD
	F__ccgo1_4 struct {
		FhNCryptKey [0]TNCRYPT_KEY_HANDLE
		FhCryptProv THCRYPTPROV
	}
	FdwKeySpec                    TDWORD
	FpKeyAgree                    TPCMSG_KEY_AGREE_RECIPIENT_INFO
	FdwRecipientIndex             TDWORD
	FdwRecipientEncryptedKeyIndex TDWORD
	FOriginatorPublicKey          TCRYPT_BIT_BLOB
}

type CMSG_CTRL_KEY_AGREE_DECRYPT_PARA = TCMSG_CTRL_KEY_AGREE_DECRYPT_PARA

type T_CMSG_CTRL_KEY_AGREE_DECRYPT_PARA = TCMSG_CTRL_KEY_AGREE_DECRYPT_PARA

type _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA = T_CMSG_CTRL_KEY_AGREE_DECRYPT_PARA

type TPCMSG_CTRL_KEY_AGREE_DECRYPT_PARA = uintptr

type PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA = TPCMSG_CTRL_KEY_AGREE_DECRYPT_PARA

type TCMSG_CTRL_MAIL_LIST_DECRYPT_PARA = struct {
	FcbSize           TDWORD
	FhCryptProv       THCRYPTPROV
	FpMailList        TPCMSG_MAIL_LIST_RECIPIENT_INFO
	FdwRecipientIndex TDWORD
	FdwKeyChoice      TDWORD
	F__ccgo5_20       struct {
		FpvKeyEncryptionKey [0]uintptr
		FhKeyEncryptionKey  THCRYPTKEY
	}
}

type CMSG_CTRL_MAIL_LIST_DECRYPT_PARA = TCMSG_CTRL_MAIL_LIST_DECRYPT_PARA

type T_CMSG_CTRL_MAIL_LIST_DECRYPT_PARA = TCMSG_CTRL_MAIL_LIST_DECRYPT_PARA

type _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA = T_CMSG_CTRL_MAIL_LIST_DECRYPT_PARA

type TPCMSG_CTRL_MAIL_LIST_DECRYPT_PARA = uintptr

type PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA = TPCMSG_CTRL_MAIL_LIST_DECRYPT_PARA

type TCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = struct {
	FcbSize        TDWORD
	FdwSignerIndex TDWORD
	Fblob          TCRYPT_DATA_BLOB
}

type CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = TCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA

type T_CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = TCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA

type _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = T_CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA

type TPCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = uintptr

type PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = TPCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA

type TCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = struct {
	FcbSize            TDWORD
	FdwSignerIndex     TDWORD
	FdwUnauthAttrIndex TDWORD
}

type CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = TCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA

type T_CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = TCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA

type _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = T_CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA

type TPCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = uintptr

type PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = TPCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA

type TPFN_CMSG_ALLOC = uintptr

type PFN_CMSG_ALLOC = TPFN_CMSG_ALLOC

type TPFN_CMSG_FREE = uintptr

type PFN_CMSG_FREE = TPFN_CMSG_FREE

type TPFN_CMSG_GEN_ENCRYPT_KEY = uintptr

type PFN_CMSG_GEN_ENCRYPT_KEY = TPFN_CMSG_GEN_ENCRYPT_KEY

type TPFN_CMSG_EXPORT_ENCRYPT_KEY = uintptr

type PFN_CMSG_EXPORT_ENCRYPT_KEY = TPFN_CMSG_EXPORT_ENCRYPT_KEY

type TPFN_CMSG_IMPORT_ENCRYPT_KEY = uintptr

type PFN_CMSG_IMPORT_ENCRYPT_KEY = TPFN_CMSG_IMPORT_ENCRYPT_KEY

type TCMSG_CONTENT_ENCRYPT_INFO = struct {
	FcbSize                     TDWORD
	FhCryptProv                 THCRYPTPROV_LEGACY
	FContentEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvEncryptionAuxInfo        uintptr
	FcRecipients                TDWORD
	FrgCmsRecipients            TPCMSG_RECIPIENT_ENCODE_INFO
	FpfnAlloc                   TPFN_CMSG_ALLOC
	FpfnFree                    TPFN_CMSG_FREE
	FdwEncryptFlags             TDWORD
	F__ccgo9_44                 struct {
		FhCNGContentEncryptKey [0]TBCRYPT_KEY_HANDLE
		FhContentEncryptKey    THCRYPTKEY
	}
	FdwFlags                      TDWORD
	FfCNG                         TWINBOOL
	FpbCNGContentEncryptKeyObject uintptr
	FpbContentEncryptKey          uintptr
	FcbContentEncryptKey          TDWORD
}

type CMSG_CONTENT_ENCRYPT_INFO = TCMSG_CONTENT_ENCRYPT_INFO

type T_CMSG_CONTENT_ENCRYPT_INFO = TCMSG_CONTENT_ENCRYPT_INFO

type _CMSG_CONTENT_ENCRYPT_INFO = T_CMSG_CONTENT_ENCRYPT_INFO

type TPCMSG_CONTENT_ENCRYPT_INFO = uintptr

type PCMSG_CONTENT_ENCRYPT_INFO = TPCMSG_CONTENT_ENCRYPT_INFO

type TPFN_CMSG_GEN_CONTENT_ENCRYPT_KEY = uintptr

type PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY = TPFN_CMSG_GEN_CONTENT_ENCRYPT_KEY

type TCMSG_KEY_TRANS_ENCRYPT_INFO = struct {
	FcbSize                 TDWORD
	FdwRecipientIndex       TDWORD
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FEncryptedKey           TCRYPT_DATA_BLOB
	FdwFlags                TDWORD
}

type CMSG_KEY_TRANS_ENCRYPT_INFO = TCMSG_KEY_TRANS_ENCRYPT_INFO

type T_CMSG_KEY_TRANS_ENCRYPT_INFO = TCMSG_KEY_TRANS_ENCRYPT_INFO

type _CMSG_KEY_TRANS_ENCRYPT_INFO = T_CMSG_KEY_TRANS_ENCRYPT_INFO

type TPCMSG_KEY_TRANS_ENCRYPT_INFO = uintptr

type PCMSG_KEY_TRANS_ENCRYPT_INFO = TPCMSG_KEY_TRANS_ENCRYPT_INFO

type TPFN_CMSG_EXPORT_KEY_TRANS = uintptr

type PFN_CMSG_EXPORT_KEY_TRANS = TPFN_CMSG_EXPORT_KEY_TRANS

type TCMSG_KEY_AGREE_KEY_ENCRYPT_INFO = struct {
	FcbSize       TDWORD
	FEncryptedKey TCRYPT_DATA_BLOB
}

type CMSG_KEY_AGREE_KEY_ENCRYPT_INFO = TCMSG_KEY_AGREE_KEY_ENCRYPT_INFO

type T_CMSG_KEY_AGREE_KEY_ENCRYPT_INFO = TCMSG_KEY_AGREE_KEY_ENCRYPT_INFO

type _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO = T_CMSG_KEY_AGREE_KEY_ENCRYPT_INFO

type TPCMSG_KEY_AGREE_KEY_ENCRYPT_INFO = uintptr

type PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO = TPCMSG_KEY_AGREE_KEY_ENCRYPT_INFO

type TCMSG_KEY_AGREE_ENCRYPT_INFO = struct {
	FcbSize                 TDWORD
	FdwRecipientIndex       TDWORD
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FUserKeyingMaterial     TCRYPT_DATA_BLOB
	FdwOriginatorChoice     TDWORD
	F__ccgo5_32             struct {
		FOriginatorPublicKeyInfo [0]TCERT_PUBLIC_KEY_INFO
		FOriginatorCertId        TCERT_ID
		F__ccgo_pad2             [4]byte
	}
	FcKeyAgreeKeyEncryptInfo   TDWORD
	FrgpKeyAgreeKeyEncryptInfo uintptr
	FdwFlags                   TDWORD
}

type CMSG_KEY_AGREE_ENCRYPT_INFO = TCMSG_KEY_AGREE_ENCRYPT_INFO

type T_CMSG_KEY_AGREE_ENCRYPT_INFO = TCMSG_KEY_AGREE_ENCRYPT_INFO

type _CMSG_KEY_AGREE_ENCRYPT_INFO = T_CMSG_KEY_AGREE_ENCRYPT_INFO

type TPCMSG_KEY_AGREE_ENCRYPT_INFO = uintptr

type PCMSG_KEY_AGREE_ENCRYPT_INFO = TPCMSG_KEY_AGREE_ENCRYPT_INFO

type TPFN_CMSG_EXPORT_KEY_AGREE = uintptr

type PFN_CMSG_EXPORT_KEY_AGREE = TPFN_CMSG_EXPORT_KEY_AGREE

type TCMSG_MAIL_LIST_ENCRYPT_INFO = struct {
	FcbSize                 TDWORD
	FdwRecipientIndex       TDWORD
	FKeyEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FEncryptedKey           TCRYPT_DATA_BLOB
	FdwFlags                TDWORD
}

type CMSG_MAIL_LIST_ENCRYPT_INFO = TCMSG_MAIL_LIST_ENCRYPT_INFO

type T_CMSG_MAIL_LIST_ENCRYPT_INFO = TCMSG_MAIL_LIST_ENCRYPT_INFO

type _CMSG_MAIL_LIST_ENCRYPT_INFO = T_CMSG_MAIL_LIST_ENCRYPT_INFO

type TPCMSG_MAIL_LIST_ENCRYPT_INFO = uintptr

type PCMSG_MAIL_LIST_ENCRYPT_INFO = TPCMSG_MAIL_LIST_ENCRYPT_INFO

type TPFN_CMSG_EXPORT_MAIL_LIST = uintptr

type PFN_CMSG_EXPORT_MAIL_LIST = TPFN_CMSG_EXPORT_MAIL_LIST

type TPFN_CMSG_IMPORT_KEY_TRANS = uintptr

type PFN_CMSG_IMPORT_KEY_TRANS = TPFN_CMSG_IMPORT_KEY_TRANS

type TPFN_CMSG_IMPORT_KEY_AGREE = uintptr

type PFN_CMSG_IMPORT_KEY_AGREE = TPFN_CMSG_IMPORT_KEY_AGREE

type TPFN_CMSG_IMPORT_MAIL_LIST = uintptr

type PFN_CMSG_IMPORT_MAIL_LIST = TPFN_CMSG_IMPORT_MAIL_LIST

type TCMSG_CNG_CONTENT_DECRYPT_INFO = struct {
	FcbSize                       TDWORD
	FContentEncryptionAlgorithm   TCRYPT_ALGORITHM_IDENTIFIER
	FpfnAlloc                     TPFN_CMSG_ALLOC
	FpfnFree                      TPFN_CMSG_FREE
	FhNCryptKey                   TNCRYPT_KEY_HANDLE
	FpbContentEncryptKey          uintptr
	FcbContentEncryptKey          TDWORD
	FhCNGContentEncryptKey        TBCRYPT_KEY_HANDLE
	FpbCNGContentEncryptKeyObject uintptr
}

type CMSG_CNG_CONTENT_DECRYPT_INFO = TCMSG_CNG_CONTENT_DECRYPT_INFO

type T_CMSG_CNG_CONTENT_DECRYPT_INFO = TCMSG_CNG_CONTENT_DECRYPT_INFO

type _CMSG_CNG_CONTENT_DECRYPT_INFO = T_CMSG_CNG_CONTENT_DECRYPT_INFO

type TPCMSG_CNG_CONTENT_DECRYPT_INFO = uintptr

type PCMSG_CNG_CONTENT_DECRYPT_INFO = TPCMSG_CNG_CONTENT_DECRYPT_INFO

type TPFN_CMSG_CNG_IMPORT_KEY_TRANS = uintptr

type PFN_CMSG_CNG_IMPORT_KEY_TRANS = TPFN_CMSG_CNG_IMPORT_KEY_TRANS

type TPFN_CMSG_CNG_IMPORT_KEY_AGREE = uintptr

type PFN_CMSG_CNG_IMPORT_KEY_AGREE = TPFN_CMSG_CNG_IMPORT_KEY_AGREE

type TPFN_CMSG_CNG_IMPORT_CONTENT_ENCRYPT_KEY = uintptr

type PFN_CMSG_CNG_IMPORT_CONTENT_ENCRYPT_KEY = TPFN_CMSG_CNG_IMPORT_CONTENT_ENCRYPT_KEY

type THCERTSTORE = uintptr

type HCERTSTORE = THCERTSTORE

type TCERT_CONTEXT = struct {
	FdwCertEncodingType TDWORD
	FpbCertEncoded      uintptr
	FcbCertEncoded      TDWORD
	FpCertInfo          TPCERT_INFO
	FhCertStore         THCERTSTORE
}

type CERT_CONTEXT = TCERT_CONTEXT

type T_CERT_CONTEXT = TCERT_CONTEXT

type _CERT_CONTEXT = T_CERT_CONTEXT

type TPCERT_CONTEXT = uintptr

type PCERT_CONTEXT = TPCERT_CONTEXT

type TPCCERT_CONTEXT = uintptr

type PCCERT_CONTEXT = TPCCERT_CONTEXT

type TCRL_CONTEXT = struct {
	FdwCertEncodingType TDWORD
	FpbCrlEncoded       uintptr
	FcbCrlEncoded       TDWORD
	FpCrlInfo           TPCRL_INFO
	FhCertStore         THCERTSTORE
}

type CRL_CONTEXT = TCRL_CONTEXT

type T_CRL_CONTEXT = TCRL_CONTEXT

type _CRL_CONTEXT = T_CRL_CONTEXT

type TPCRL_CONTEXT = uintptr

type PCRL_CONTEXT = TPCRL_CONTEXT

type TPCCRL_CONTEXT = uintptr

type PCCRL_CONTEXT = TPCCRL_CONTEXT

type TCTL_CONTEXT = struct {
	FdwMsgAndCertEncodingType TDWORD
	FpbCtlEncoded             uintptr
	FcbCtlEncoded             TDWORD
	FpCtlInfo                 TPCTL_INFO
	FhCertStore               THCERTSTORE
	FhCryptMsg                THCRYPTMSG
	FpbCtlContent             uintptr
	FcbCtlContent             TDWORD
}

type CTL_CONTEXT = TCTL_CONTEXT

type T_CTL_CONTEXT = TCTL_CONTEXT

type _CTL_CONTEXT = T_CTL_CONTEXT

type TPCTL_CONTEXT = uintptr

type PCTL_CONTEXT = TPCTL_CONTEXT

type TPCCTL_CONTEXT = uintptr

type PCCTL_CONTEXT = TPCCTL_CONTEXT

type TCertKeyType = int32

type CertKeyType = TCertKeyType

type _CertKeyType = int32

const _KeyTypeOther = 0
const _KeyTypeVirtualSmartCard = 1
const _KeyTypePhysicalSmartCard = 2
const _KeyTypePassport = 3
const _KeyTypePassportRemote = 4
const _KeyTypePassportSmartCard = 5
const _KeyTypeHardware = 6
const _KeyTypeSoftware = 7
const _KeyTypeSelfSigned = 8

type TCRYPT_KEY_PROV_PARAM = struct {
	FdwParam TDWORD
	FpbData  uintptr
	FcbData  TDWORD
	FdwFlags TDWORD
}

type CRYPT_KEY_PROV_PARAM = TCRYPT_KEY_PROV_PARAM

type T_CRYPT_KEY_PROV_PARAM = TCRYPT_KEY_PROV_PARAM

type _CRYPT_KEY_PROV_PARAM = T_CRYPT_KEY_PROV_PARAM

type TPCRYPT_KEY_PROV_PARAM = uintptr

type PCRYPT_KEY_PROV_PARAM = TPCRYPT_KEY_PROV_PARAM

type TCRYPT_KEY_PROV_INFO = struct {
	FpwszContainerName TLPWSTR
	FpwszProvName      TLPWSTR
	FdwProvType        TDWORD
	FdwFlags           TDWORD
	FcProvParam        TDWORD
	FrgProvParam       TPCRYPT_KEY_PROV_PARAM
	FdwKeySpec         TDWORD
}

type CRYPT_KEY_PROV_INFO = TCRYPT_KEY_PROV_INFO

type T_CRYPT_KEY_PROV_INFO = TCRYPT_KEY_PROV_INFO

type _CRYPT_KEY_PROV_INFO = T_CRYPT_KEY_PROV_INFO

type TPCRYPT_KEY_PROV_INFO = uintptr

type PCRYPT_KEY_PROV_INFO = TPCRYPT_KEY_PROV_INFO

type TCERT_KEY_CONTEXT = struct {
	FcbSize    TDWORD
	F__ccgo1_4 struct {
		FhNCryptKey [0]TNCRYPT_KEY_HANDLE
		FhCryptProv THCRYPTPROV
	}
	FdwKeySpec TDWORD
}

type CERT_KEY_CONTEXT = TCERT_KEY_CONTEXT

type T_CERT_KEY_CONTEXT = TCERT_KEY_CONTEXT

type _CERT_KEY_CONTEXT = T_CERT_KEY_CONTEXT

type TPCERT_KEY_CONTEXT = uintptr

type PCERT_KEY_CONTEXT = TPCERT_KEY_CONTEXT

type TROOT_INFO_LUID = struct {
	FLowPart  TDWORD
	FHighPart TLONG
}

type ROOT_INFO_LUID = TROOT_INFO_LUID

type T_ROOT_INFO_LUID = TROOT_INFO_LUID

type _ROOT_INFO_LUID = T_ROOT_INFO_LUID

type TPROOT_INFO_LUID = uintptr

type PROOT_INFO_LUID = TPROOT_INFO_LUID

type TCRYPT_SMART_CARD_ROOT_INFO = struct {
	FrgbCardID [16]TBYTE
	Fluid      TROOT_INFO_LUID
}

type CRYPT_SMART_CARD_ROOT_INFO = TCRYPT_SMART_CARD_ROOT_INFO

type T_CRYPT_SMART_CARD_ROOT_INFO = TCRYPT_SMART_CARD_ROOT_INFO

type _CRYPT_SMART_CARD_ROOT_INFO = T_CRYPT_SMART_CARD_ROOT_INFO

type TPCRYPT_SMART_CARD_ROOT_INFO = uintptr

type PCRYPT_SMART_CARD_ROOT_INFO = TPCRYPT_SMART_CARD_ROOT_INFO

type TCERT_SYSTEM_STORE_RELOCATE_PARA = struct {
	F__ccgo0_0 struct {
		FpvBase   [0]uintptr
		FhKeyBase THKEY
	}
	F__ccgo1_4 struct {
		FpszSystemStore  [0]TLPCSTR
		FpwszSystemStore [0]TLPCWSTR
		FpvSystemStore   uintptr
	}
}

type CERT_SYSTEM_STORE_RELOCATE_PARA = TCERT_SYSTEM_STORE_RELOCATE_PARA

type T_CERT_SYSTEM_STORE_RELOCATE_PARA = TCERT_SYSTEM_STORE_RELOCATE_PARA

type _CERT_SYSTEM_STORE_RELOCATE_PARA = T_CERT_SYSTEM_STORE_RELOCATE_PARA

type TPCERT_SYSTEM_STORE_RELOCATE_PARA = uintptr

type PCERT_SYSTEM_STORE_RELOCATE_PARA = TPCERT_SYSTEM_STORE_RELOCATE_PARA

type TCERT_REGISTRY_STORE_CLIENT_GPT_PARA = struct {
	FhKeyBase    THKEY
	FpwszRegPath TLPWSTR
}

type CERT_REGISTRY_STORE_CLIENT_GPT_PARA = TCERT_REGISTRY_STORE_CLIENT_GPT_PARA

type T_CERT_REGISTRY_STORE_CLIENT_GPT_PARA = TCERT_REGISTRY_STORE_CLIENT_GPT_PARA

type _CERT_REGISTRY_STORE_CLIENT_GPT_PARA = T_CERT_REGISTRY_STORE_CLIENT_GPT_PARA

type TPCERT_REGISTRY_STORE_CLIENT_GPT_PARA = uintptr

type PCERT_REGISTRY_STORE_CLIENT_GPT_PARA = TPCERT_REGISTRY_STORE_CLIENT_GPT_PARA

type TCERT_REGISTRY_STORE_ROAMING_PARA = struct {
	FhKey               THKEY
	FpwszStoreDirectory TLPWSTR
}

type CERT_REGISTRY_STORE_ROAMING_PARA = TCERT_REGISTRY_STORE_ROAMING_PARA

type T_CERT_REGISTRY_STORE_ROAMING_PARA = TCERT_REGISTRY_STORE_ROAMING_PARA

type _CERT_REGISTRY_STORE_ROAMING_PARA = T_CERT_REGISTRY_STORE_ROAMING_PARA

type TPCERT_REGISTRY_STORE_ROAMING_PARA = uintptr

type PCERT_REGISTRY_STORE_ROAMING_PARA = TPCERT_REGISTRY_STORE_ROAMING_PARA

type TCERT_LDAP_STORE_OPENED_PARA = struct {
	FpvLdapSessionHandle uintptr
	FpwszLdapUrl         TLPCWSTR
}

type CERT_LDAP_STORE_OPENED_PARA = TCERT_LDAP_STORE_OPENED_PARA

type T_CERT_LDAP_STORE_OPENED_PARA = TCERT_LDAP_STORE_OPENED_PARA

type _CERT_LDAP_STORE_OPENED_PARA = T_CERT_LDAP_STORE_OPENED_PARA

type TPCERT_LDAP_STORE_OPENED_PARA = uintptr

type PCERT_LDAP_STORE_OPENED_PARA = TPCERT_LDAP_STORE_OPENED_PARA

type THCERTSTOREPROV = uintptr

type HCERTSTOREPROV = THCERTSTOREPROV

type TCERT_STORE_PROV_INFO = struct {
	FcbSize              TDWORD
	FcStoreProvFunc      TDWORD
	FrgpvStoreProvFunc   uintptr
	FhStoreProv          THCERTSTOREPROV
	FdwStoreProvFlags    TDWORD
	FhStoreProvFuncAddr2 THCRYPTOIDFUNCADDR
}

type CERT_STORE_PROV_INFO = TCERT_STORE_PROV_INFO

type T_CERT_STORE_PROV_INFO = TCERT_STORE_PROV_INFO

type _CERT_STORE_PROV_INFO = T_CERT_STORE_PROV_INFO

type TPCERT_STORE_PROV_INFO = uintptr

type PCERT_STORE_PROV_INFO = TPCERT_STORE_PROV_INFO

type TPFN_CERT_DLL_OPEN_STORE_PROV_FUNC = uintptr

type PFN_CERT_DLL_OPEN_STORE_PROV_FUNC = TPFN_CERT_DLL_OPEN_STORE_PROV_FUNC

type TPFN_CERT_STORE_PROV_CLOSE = uintptr

type PFN_CERT_STORE_PROV_CLOSE = TPFN_CERT_STORE_PROV_CLOSE

type TPFN_CERT_STORE_PROV_READ_CERT = uintptr

type PFN_CERT_STORE_PROV_READ_CERT = TPFN_CERT_STORE_PROV_READ_CERT

type TPFN_CERT_STORE_PROV_WRITE_CERT = uintptr

type PFN_CERT_STORE_PROV_WRITE_CERT = TPFN_CERT_STORE_PROV_WRITE_CERT

type TPFN_CERT_STORE_PROV_DELETE_CERT = uintptr

type PFN_CERT_STORE_PROV_DELETE_CERT = TPFN_CERT_STORE_PROV_DELETE_CERT

type TPFN_CERT_STORE_PROV_SET_CERT_PROPERTY = uintptr

type PFN_CERT_STORE_PROV_SET_CERT_PROPERTY = TPFN_CERT_STORE_PROV_SET_CERT_PROPERTY

type TPFN_CERT_STORE_PROV_READ_CRL = uintptr

type PFN_CERT_STORE_PROV_READ_CRL = TPFN_CERT_STORE_PROV_READ_CRL

type TPFN_CERT_STORE_PROV_WRITE_CRL = uintptr

type PFN_CERT_STORE_PROV_WRITE_CRL = TPFN_CERT_STORE_PROV_WRITE_CRL

type TPFN_CERT_STORE_PROV_DELETE_CRL = uintptr

type PFN_CERT_STORE_PROV_DELETE_CRL = TPFN_CERT_STORE_PROV_DELETE_CRL

type TPFN_CERT_STORE_PROV_SET_CRL_PROPERTY = uintptr

type PFN_CERT_STORE_PROV_SET_CRL_PROPERTY = TPFN_CERT_STORE_PROV_SET_CRL_PROPERTY

type TPFN_CERT_STORE_PROV_READ_CTL = uintptr

type PFN_CERT_STORE_PROV_READ_CTL = TPFN_CERT_STORE_PROV_READ_CTL

type TPFN_CERT_STORE_PROV_WRITE_CTL = uintptr

type PFN_CERT_STORE_PROV_WRITE_CTL = TPFN_CERT_STORE_PROV_WRITE_CTL

type TPFN_CERT_STORE_PROV_DELETE_CTL = uintptr

type PFN_CERT_STORE_PROV_DELETE_CTL = TPFN_CERT_STORE_PROV_DELETE_CTL

type TPFN_CERT_STORE_PROV_SET_CTL_PROPERTY = uintptr

type PFN_CERT_STORE_PROV_SET_CTL_PROPERTY = TPFN_CERT_STORE_PROV_SET_CTL_PROPERTY

type TPFN_CERT_STORE_PROV_CONTROL = uintptr

type PFN_CERT_STORE_PROV_CONTROL = TPFN_CERT_STORE_PROV_CONTROL

type TCERT_STORE_PROV_FIND_INFO = struct {
	FcbSize                   TDWORD
	FdwMsgAndCertEncodingType TDWORD
	FdwFindFlags              TDWORD
	FdwFindType               TDWORD
	FpvFindPara               uintptr
}

type CERT_STORE_PROV_FIND_INFO = TCERT_STORE_PROV_FIND_INFO

type T_CERT_STORE_PROV_FIND_INFO = TCERT_STORE_PROV_FIND_INFO

type _CERT_STORE_PROV_FIND_INFO = T_CERT_STORE_PROV_FIND_INFO

type TPCERT_STORE_PROV_FIND_INFO = uintptr

type PCERT_STORE_PROV_FIND_INFO = TPCERT_STORE_PROV_FIND_INFO

type TCCERT_STORE_PROV_FIND_INFO = struct {
	FcbSize                   TDWORD
	FdwMsgAndCertEncodingType TDWORD
	FdwFindFlags              TDWORD
	FdwFindType               TDWORD
	FpvFindPara               uintptr
}

type CCERT_STORE_PROV_FIND_INFO = TCCERT_STORE_PROV_FIND_INFO

type TPCCERT_STORE_PROV_FIND_INFO = uintptr

type PCCERT_STORE_PROV_FIND_INFO = TPCCERT_STORE_PROV_FIND_INFO

type TPFN_CERT_STORE_PROV_FIND_CERT = uintptr

type PFN_CERT_STORE_PROV_FIND_CERT = TPFN_CERT_STORE_PROV_FIND_CERT

type TPFN_CERT_STORE_PROV_FREE_FIND_CERT = uintptr

type PFN_CERT_STORE_PROV_FREE_FIND_CERT = TPFN_CERT_STORE_PROV_FREE_FIND_CERT

type TPFN_CERT_STORE_PROV_GET_CERT_PROPERTY = uintptr

type PFN_CERT_STORE_PROV_GET_CERT_PROPERTY = TPFN_CERT_STORE_PROV_GET_CERT_PROPERTY

type TPFN_CERT_STORE_PROV_FIND_CRL = uintptr

type PFN_CERT_STORE_PROV_FIND_CRL = TPFN_CERT_STORE_PROV_FIND_CRL

type TPFN_CERT_STORE_PROV_FREE_FIND_CRL = uintptr

type PFN_CERT_STORE_PROV_FREE_FIND_CRL = TPFN_CERT_STORE_PROV_FREE_FIND_CRL

type TPFN_CERT_STORE_PROV_GET_CRL_PROPERTY = uintptr

type PFN_CERT_STORE_PROV_GET_CRL_PROPERTY = TPFN_CERT_STORE_PROV_GET_CRL_PROPERTY

type TPFN_CERT_STORE_PROV_FIND_CTL = uintptr

type PFN_CERT_STORE_PROV_FIND_CTL = TPFN_CERT_STORE_PROV_FIND_CTL

type TPFN_CERT_STORE_PROV_FREE_FIND_CTL = uintptr

type PFN_CERT_STORE_PROV_FREE_FIND_CTL = TPFN_CERT_STORE_PROV_FREE_FIND_CTL

type TPFN_CERT_STORE_PROV_GET_CTL_PROPERTY = uintptr

type PFN_CERT_STORE_PROV_GET_CTL_PROPERTY = TPFN_CERT_STORE_PROV_GET_CTL_PROPERTY

type TCRL_FIND_ISSUED_FOR_PARA = struct {
	FpSubjectCert TPCCERT_CONTEXT
	FpIssuerCert  TPCCERT_CONTEXT
}

type CRL_FIND_ISSUED_FOR_PARA = TCRL_FIND_ISSUED_FOR_PARA

type T_CRL_FIND_ISSUED_FOR_PARA = TCRL_FIND_ISSUED_FOR_PARA

type _CRL_FIND_ISSUED_FOR_PARA = T_CRL_FIND_ISSUED_FOR_PARA

type TPCRL_FIND_ISSUED_FOR_PARA = uintptr

type PCRL_FIND_ISSUED_FOR_PARA = TPCRL_FIND_ISSUED_FOR_PARA

type TCTL_ANY_SUBJECT_INFO = struct {
	FSubjectAlgorithm  TCRYPT_ALGORITHM_IDENTIFIER
	FSubjectIdentifier TCRYPT_DATA_BLOB
}

type CTL_ANY_SUBJECT_INFO = TCTL_ANY_SUBJECT_INFO

type T_CTL_ANY_SUBJECT_INFO = TCTL_ANY_SUBJECT_INFO

type _CTL_ANY_SUBJECT_INFO = T_CTL_ANY_SUBJECT_INFO

type TPCTL_ANY_SUBJECT_INFO = uintptr

type PCTL_ANY_SUBJECT_INFO = TPCTL_ANY_SUBJECT_INFO

type TCTL_FIND_USAGE_PARA = struct {
	FcbSize         TDWORD
	FSubjectUsage   TCTL_USAGE
	FListIdentifier TCRYPT_DATA_BLOB
	FpSigner        TPCERT_INFO
}

type CTL_FIND_USAGE_PARA = TCTL_FIND_USAGE_PARA

type T_CTL_FIND_USAGE_PARA = TCTL_FIND_USAGE_PARA

type _CTL_FIND_USAGE_PARA = T_CTL_FIND_USAGE_PARA

type TPCTL_FIND_USAGE_PARA = uintptr

type PCTL_FIND_USAGE_PARA = TPCTL_FIND_USAGE_PARA

type TCTL_FIND_SUBJECT_PARA = struct {
	FcbSize        TDWORD
	FpUsagePara    TPCTL_FIND_USAGE_PARA
	FdwSubjectType TDWORD
	FpvSubject     uintptr
}

type CTL_FIND_SUBJECT_PARA = TCTL_FIND_SUBJECT_PARA

type T_CTL_FIND_SUBJECT_PARA = TCTL_FIND_SUBJECT_PARA

type _CTL_FIND_SUBJECT_PARA = T_CTL_FIND_SUBJECT_PARA

type TPCTL_FIND_SUBJECT_PARA = uintptr

type PCTL_FIND_SUBJECT_PARA = TPCTL_FIND_SUBJECT_PARA

type TPFN_CERT_CREATE_CONTEXT_SORT_FUNC = uintptr

type PFN_CERT_CREATE_CONTEXT_SORT_FUNC = TPFN_CERT_CREATE_CONTEXT_SORT_FUNC

type TCERT_CREATE_CONTEXT_PARA = struct {
	FcbSize  TDWORD
	FpfnFree TPFN_CRYPT_FREE
	FpvFree  uintptr
	FpfnSort TPFN_CERT_CREATE_CONTEXT_SORT_FUNC
	FpvSort  uintptr
}

type CERT_CREATE_CONTEXT_PARA = TCERT_CREATE_CONTEXT_PARA

type T_CERT_CREATE_CONTEXT_PARA = TCERT_CREATE_CONTEXT_PARA

type _CERT_CREATE_CONTEXT_PARA = T_CERT_CREATE_CONTEXT_PARA

type TPCERT_CREATE_CONTEXT_PARA = uintptr

type PCERT_CREATE_CONTEXT_PARA = TPCERT_CREATE_CONTEXT_PARA

type TCERT_SYSTEM_STORE_INFO = struct {
	FcbSize TDWORD
}

type CERT_SYSTEM_STORE_INFO = TCERT_SYSTEM_STORE_INFO

type T_CERT_SYSTEM_STORE_INFO = TCERT_SYSTEM_STORE_INFO

type _CERT_SYSTEM_STORE_INFO = T_CERT_SYSTEM_STORE_INFO

type TPCERT_SYSTEM_STORE_INFO = uintptr

type PCERT_SYSTEM_STORE_INFO = TPCERT_SYSTEM_STORE_INFO

type TCERT_PHYSICAL_STORE_INFO = struct {
	FcbSize               TDWORD
	FpszOpenStoreProvider TLPSTR
	FdwOpenEncodingType   TDWORD
	FdwOpenFlags          TDWORD
	FOpenParameters       TCRYPT_DATA_BLOB
	FdwFlags              TDWORD
	FdwPriority           TDWORD
}

type CERT_PHYSICAL_STORE_INFO = TCERT_PHYSICAL_STORE_INFO

type T_CERT_PHYSICAL_STORE_INFO = TCERT_PHYSICAL_STORE_INFO

type _CERT_PHYSICAL_STORE_INFO = T_CERT_PHYSICAL_STORE_INFO

type TPCERT_PHYSICAL_STORE_INFO = uintptr

type PCERT_PHYSICAL_STORE_INFO = TPCERT_PHYSICAL_STORE_INFO

type TPFN_CERT_ENUM_SYSTEM_STORE_LOCATION = uintptr

type PFN_CERT_ENUM_SYSTEM_STORE_LOCATION = TPFN_CERT_ENUM_SYSTEM_STORE_LOCATION

type TPFN_CERT_ENUM_SYSTEM_STORE = uintptr

type PFN_CERT_ENUM_SYSTEM_STORE = TPFN_CERT_ENUM_SYSTEM_STORE

type TPFN_CERT_ENUM_PHYSICAL_STORE = uintptr

type PFN_CERT_ENUM_PHYSICAL_STORE = TPFN_CERT_ENUM_PHYSICAL_STORE

type TCTL_VERIFY_USAGE_PARA = struct {
	FcbSize         TDWORD
	FListIdentifier TCRYPT_DATA_BLOB
	FcCtlStore      TDWORD
	FrghCtlStore    uintptr
	FcSignerStore   TDWORD
	FrghSignerStore uintptr
}

type CTL_VERIFY_USAGE_PARA = TCTL_VERIFY_USAGE_PARA

type T_CTL_VERIFY_USAGE_PARA = TCTL_VERIFY_USAGE_PARA

type _CTL_VERIFY_USAGE_PARA = T_CTL_VERIFY_USAGE_PARA

type TPCTL_VERIFY_USAGE_PARA = uintptr

type PCTL_VERIFY_USAGE_PARA = TPCTL_VERIFY_USAGE_PARA

type TCTL_VERIFY_USAGE_STATUS = struct {
	FcbSize          TDWORD
	FdwError         TDWORD
	FdwFlags         TDWORD
	FppCtl           uintptr
	FdwCtlEntryIndex TDWORD
	FppSigner        uintptr
	FdwSignerIndex   TDWORD
}

type CTL_VERIFY_USAGE_STATUS = TCTL_VERIFY_USAGE_STATUS

type T_CTL_VERIFY_USAGE_STATUS = TCTL_VERIFY_USAGE_STATUS

type _CTL_VERIFY_USAGE_STATUS = T_CTL_VERIFY_USAGE_STATUS

type TPCTL_VERIFY_USAGE_STATUS = uintptr

type PCTL_VERIFY_USAGE_STATUS = TPCTL_VERIFY_USAGE_STATUS

type TCERT_REVOCATION_CRL_INFO = struct {
	FcbSize           TDWORD
	FpBaseCrlContext  TPCCRL_CONTEXT
	FpDeltaCrlContext TPCCRL_CONTEXT
	FpCrlEntry        TPCRL_ENTRY
	FfDeltaCrlEntry   TWINBOOL
}

type CERT_REVOCATION_CRL_INFO = TCERT_REVOCATION_CRL_INFO

type T_CERT_REVOCATION_CRL_INFO = TCERT_REVOCATION_CRL_INFO

type _CERT_REVOCATION_CRL_INFO = T_CERT_REVOCATION_CRL_INFO

type TPCERT_REVOCATION_CRL_INFO = uintptr

type PCERT_REVOCATION_CRL_INFO = TPCERT_REVOCATION_CRL_INFO

type TCERT_REVOCATION_CHAIN_PARA = struct {
	FcbSize                     TDWORD
	FhChainEngine               THCERTCHAINENGINE
	FhAdditionalStore           THCERTSTORE
	FdwChainFlags               TDWORD
	FdwUrlRetrievalTimeout      TDWORD
	FpftCurrentTime             TLPFILETIME
	FpftCacheResync             TLPFILETIME
	FcbMaxUrlRetrievalByteCount TDWORD
}

type CERT_REVOCATION_CHAIN_PARA = TCERT_REVOCATION_CHAIN_PARA

type T_CERT_REVOCATION_CHAIN_PARA = TCERT_REVOCATION_CHAIN_PARA

type _CERT_REVOCATION_CHAIN_PARA = T_CERT_REVOCATION_CHAIN_PARA

type TPCERT_REVOCATION_CHAIN_PARA = uintptr

type PCERT_REVOCATION_CHAIN_PARA = TPCERT_REVOCATION_CHAIN_PARA

type TCERT_REVOCATION_PARA = struct {
	FcbSize       TDWORD
	FpIssuerCert  TPCCERT_CONTEXT
	FcCertStore   TDWORD
	FrgCertStore  uintptr
	FhCrlStore    THCERTSTORE
	FpftTimeToUse TLPFILETIME
}

type CERT_REVOCATION_PARA = TCERT_REVOCATION_PARA

type T_CERT_REVOCATION_PARA = TCERT_REVOCATION_PARA

type _CERT_REVOCATION_PARA = T_CERT_REVOCATION_PARA

type TPCERT_REVOCATION_PARA = uintptr

type PCERT_REVOCATION_PARA = TPCERT_REVOCATION_PARA

type TCERT_REVOCATION_STATUS = struct {
	FcbSize            TDWORD
	FdwIndex           TDWORD
	FdwError           TDWORD
	FdwReason          TDWORD
	FfHasFreshnessTime TWINBOOL
	FdwFreshnessTime   TDWORD
}

type CERT_REVOCATION_STATUS = TCERT_REVOCATION_STATUS

type T_CERT_REVOCATION_STATUS = TCERT_REVOCATION_STATUS

type _CERT_REVOCATION_STATUS = T_CERT_REVOCATION_STATUS

type TPCERT_REVOCATION_STATUS = uintptr

type PCERT_REVOCATION_STATUS = TPCERT_REVOCATION_STATUS

type TCRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO = struct {
	FCertSignHashCNGAlgPropData        TCRYPT_DATA_BLOB
	FCertIssuerPubKeyBitLengthPropData TCRYPT_DATA_BLOB
}

type CRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO = TCRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO

type T_CRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO = TCRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO

type _CRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO = T_CRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO

type TPCRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO = uintptr

type PCRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO = TPCRYPT_VERIFY_CERT_SIGN_STRONG_PROPERTIES_INFO

type TPFN_CRYPT_EXTRACT_ENCODED_SIGNATURE_PARAMETERS_FUNC = uintptr

type PFN_CRYPT_EXTRACT_ENCODED_SIGNATURE_PARAMETERS_FUNC = TPFN_CRYPT_EXTRACT_ENCODED_SIGNATURE_PARAMETERS_FUNC

type TPFN_CRYPT_SIGN_AND_ENCODE_HASH_FUNC = uintptr

type PFN_CRYPT_SIGN_AND_ENCODE_HASH_FUNC = TPFN_CRYPT_SIGN_AND_ENCODE_HASH_FUNC

type TPFN_CRYPT_VERIFY_ENCODED_SIGNATURE_FUNC = uintptr

type PFN_CRYPT_VERIFY_ENCODED_SIGNATURE_FUNC = TPFN_CRYPT_VERIFY_ENCODED_SIGNATURE_FUNC

type THCRYPTDEFAULTCONTEXT = uintptr

type HCRYPTDEFAULTCONTEXT = THCRYPTDEFAULTCONTEXT

type TCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA = struct {
	FcOID     TDWORD
	FrgpszOID uintptr
}

type CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA = TCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA

type T_CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA = TCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA

type _CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA = T_CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA

type TPCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA = uintptr

type PCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA = TPCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA

type TPFN_CRYPT_EXPORT_PUBLIC_KEY_INFO_EX2_FUNC = uintptr

type PFN_CRYPT_EXPORT_PUBLIC_KEY_INFO_EX2_FUNC = TPFN_CRYPT_EXPORT_PUBLIC_KEY_INFO_EX2_FUNC

type TPFN_CRYPT_EXPORT_PUBLIC_KEY_INFO_FROM_BCRYPT_HANDLE_FUNC = uintptr

type PFN_CRYPT_EXPORT_PUBLIC_KEY_INFO_FROM_BCRYPT_HANDLE_FUNC = TPFN_CRYPT_EXPORT_PUBLIC_KEY_INFO_FROM_BCRYPT_HANDLE_FUNC

type TPFN_IMPORT_PRIV_KEY_FUNC = uintptr

type PFN_IMPORT_PRIV_KEY_FUNC = TPFN_IMPORT_PRIV_KEY_FUNC

type TPFN_EXPORT_PRIV_KEY_FUNC = uintptr

type PFN_EXPORT_PRIV_KEY_FUNC = TPFN_EXPORT_PRIV_KEY_FUNC

type TPFN_IMPORT_PUBLIC_KEY_INFO_EX2_FUNC = uintptr

type PFN_IMPORT_PUBLIC_KEY_INFO_EX2_FUNC = TPFN_IMPORT_PUBLIC_KEY_INFO_EX2_FUNC

type TPFN_CRYPT_GET_SIGNER_CERTIFICATE = uintptr

type PFN_CRYPT_GET_SIGNER_CERTIFICATE = TPFN_CRYPT_GET_SIGNER_CERTIFICATE

type TCRYPT_SIGN_MESSAGE_PARA = struct {
	FcbSize             TDWORD
	FdwMsgEncodingType  TDWORD
	FpSigningCert       TPCCERT_CONTEXT
	FHashAlgorithm      TCRYPT_ALGORITHM_IDENTIFIER
	FpvHashAuxInfo      uintptr
	FcMsgCert           TDWORD
	FrgpMsgCert         uintptr
	FcMsgCrl            TDWORD
	FrgpMsgCrl          uintptr
	FcAuthAttr          TDWORD
	FrgAuthAttr         TPCRYPT_ATTRIBUTE
	FcUnauthAttr        TDWORD
	FrgUnauthAttr       TPCRYPT_ATTRIBUTE
	FdwFlags            TDWORD
	FdwInnerContentType TDWORD
}

type CRYPT_SIGN_MESSAGE_PARA = TCRYPT_SIGN_MESSAGE_PARA

type T_CRYPT_SIGN_MESSAGE_PARA = TCRYPT_SIGN_MESSAGE_PARA

type _CRYPT_SIGN_MESSAGE_PARA = T_CRYPT_SIGN_MESSAGE_PARA

type TPCRYPT_SIGN_MESSAGE_PARA = uintptr

type PCRYPT_SIGN_MESSAGE_PARA = TPCRYPT_SIGN_MESSAGE_PARA

type TCRYPT_VERIFY_MESSAGE_PARA = struct {
	FcbSize                   TDWORD
	FdwMsgAndCertEncodingType TDWORD
	FhCryptProv               THCRYPTPROV_LEGACY
	FpfnGetSignerCertificate  TPFN_CRYPT_GET_SIGNER_CERTIFICATE
	FpvGetArg                 uintptr
}

type CRYPT_VERIFY_MESSAGE_PARA = TCRYPT_VERIFY_MESSAGE_PARA

type T_CRYPT_VERIFY_MESSAGE_PARA = TCRYPT_VERIFY_MESSAGE_PARA

type _CRYPT_VERIFY_MESSAGE_PARA = T_CRYPT_VERIFY_MESSAGE_PARA

type TPCRYPT_VERIFY_MESSAGE_PARA = uintptr

type PCRYPT_VERIFY_MESSAGE_PARA = TPCRYPT_VERIFY_MESSAGE_PARA

type TCRYPT_ENCRYPT_MESSAGE_PARA = struct {
	FcbSize                     TDWORD
	FdwMsgEncodingType          TDWORD
	FhCryptProv                 THCRYPTPROV_LEGACY
	FContentEncryptionAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
	FpvEncryptionAuxInfo        uintptr
	FdwFlags                    TDWORD
	FdwInnerContentType         TDWORD
}

type CRYPT_ENCRYPT_MESSAGE_PARA = TCRYPT_ENCRYPT_MESSAGE_PARA

type T_CRYPT_ENCRYPT_MESSAGE_PARA = TCRYPT_ENCRYPT_MESSAGE_PARA

type _CRYPT_ENCRYPT_MESSAGE_PARA = T_CRYPT_ENCRYPT_MESSAGE_PARA

type TPCRYPT_ENCRYPT_MESSAGE_PARA = uintptr

type PCRYPT_ENCRYPT_MESSAGE_PARA = TPCRYPT_ENCRYPT_MESSAGE_PARA

type TCRYPT_DECRYPT_MESSAGE_PARA = struct {
	FcbSize                   TDWORD
	FdwMsgAndCertEncodingType TDWORD
	FcCertStore               TDWORD
	FrghCertStore             uintptr
}

type CRYPT_DECRYPT_MESSAGE_PARA = TCRYPT_DECRYPT_MESSAGE_PARA

type T_CRYPT_DECRYPT_MESSAGE_PARA = TCRYPT_DECRYPT_MESSAGE_PARA

type _CRYPT_DECRYPT_MESSAGE_PARA = T_CRYPT_DECRYPT_MESSAGE_PARA

type TPCRYPT_DECRYPT_MESSAGE_PARA = uintptr

type PCRYPT_DECRYPT_MESSAGE_PARA = TPCRYPT_DECRYPT_MESSAGE_PARA

type TCRYPT_HASH_MESSAGE_PARA = struct {
	FcbSize            TDWORD
	FdwMsgEncodingType TDWORD
	FhCryptProv        THCRYPTPROV_LEGACY
	FHashAlgorithm     TCRYPT_ALGORITHM_IDENTIFIER
	FpvHashAuxInfo     uintptr
}

type CRYPT_HASH_MESSAGE_PARA = TCRYPT_HASH_MESSAGE_PARA

type T_CRYPT_HASH_MESSAGE_PARA = TCRYPT_HASH_MESSAGE_PARA

type _CRYPT_HASH_MESSAGE_PARA = T_CRYPT_HASH_MESSAGE_PARA

type TPCRYPT_HASH_MESSAGE_PARA = uintptr

type PCRYPT_HASH_MESSAGE_PARA = TPCRYPT_HASH_MESSAGE_PARA

type TCRYPT_KEY_SIGN_MESSAGE_PARA = struct {
	FcbSize                   TDWORD
	FdwMsgAndCertEncodingType TDWORD
	F__ccgo2_8                struct {
		FhNCryptKey [0]TNCRYPT_KEY_HANDLE
		FhCryptProv THCRYPTPROV
	}
	FdwKeySpec       TDWORD
	FHashAlgorithm   TCRYPT_ALGORITHM_IDENTIFIER
	FpvHashAuxInfo   uintptr
	FPubKeyAlgorithm TCRYPT_ALGORITHM_IDENTIFIER
}

type CRYPT_KEY_SIGN_MESSAGE_PARA = TCRYPT_KEY_SIGN_MESSAGE_PARA

type T_CRYPT_KEY_SIGN_MESSAGE_PARA = TCRYPT_KEY_SIGN_MESSAGE_PARA

type _CRYPT_KEY_SIGN_MESSAGE_PARA = T_CRYPT_KEY_SIGN_MESSAGE_PARA

type TPCRYPT_KEY_SIGN_MESSAGE_PARA = uintptr

type PCRYPT_KEY_SIGN_MESSAGE_PARA = TPCRYPT_KEY_SIGN_MESSAGE_PARA

type TCRYPT_KEY_VERIFY_MESSAGE_PARA = struct {
	FcbSize            TDWORD
	FdwMsgEncodingType TDWORD
	FhCryptProv        THCRYPTPROV_LEGACY
}

type CRYPT_KEY_VERIFY_MESSAGE_PARA = TCRYPT_KEY_VERIFY_MESSAGE_PARA

type T_CRYPT_KEY_VERIFY_MESSAGE_PARA = TCRYPT_KEY_VERIFY_MESSAGE_PARA

type _CRYPT_KEY_VERIFY_MESSAGE_PARA = T_CRYPT_KEY_VERIFY_MESSAGE_PARA

type TPCRYPT_KEY_VERIFY_MESSAGE_PARA = uintptr

type PCRYPT_KEY_VERIFY_MESSAGE_PARA = TPCRYPT_KEY_VERIFY_MESSAGE_PARA

type TCERT_CHAIN = struct {
	FcCerts         TDWORD
	Fcerts          TPCERT_BLOB
	FkeyLocatorInfo TCRYPT_KEY_PROV_INFO
}

type CERT_CHAIN = TCERT_CHAIN

type T_CERT_CHAIN = TCERT_CHAIN

type _CERT_CHAIN = T_CERT_CHAIN

type TPCERT_CHAIN = uintptr

type PCERT_CHAIN = TPCERT_CHAIN

type THCRYPTASYNC = uintptr

type HCRYPTASYNC = THCRYPTASYNC

type TPHCRYPTASYNC = uintptr

type PHCRYPTASYNC = TPHCRYPTASYNC

type TPFN_CRYPT_ASYNC_PARAM_FREE_FUNC = uintptr

type PFN_CRYPT_ASYNC_PARAM_FREE_FUNC = TPFN_CRYPT_ASYNC_PARAM_FREE_FUNC

type TCRYPT_BLOB_ARRAY = struct {
	FcBlob  TDWORD
	FrgBlob TPCRYPT_DATA_BLOB
}

type CRYPT_BLOB_ARRAY = TCRYPT_BLOB_ARRAY

type T_CRYPT_BLOB_ARRAY = TCRYPT_BLOB_ARRAY

type _CRYPT_BLOB_ARRAY = T_CRYPT_BLOB_ARRAY

type TPCRYPT_BLOB_ARRAY = uintptr

type PCRYPT_BLOB_ARRAY = TPCRYPT_BLOB_ARRAY

type TCRYPT_CREDENTIALS = struct {
	FcbSize            TDWORD
	FpszCredentialsOid TLPCSTR
	FpvCredentials     TLPVOID
}

type CRYPT_CREDENTIALS = TCRYPT_CREDENTIALS

type T_CRYPT_CREDENTIALS = TCRYPT_CREDENTIALS

type _CRYPT_CREDENTIALS = T_CRYPT_CREDENTIALS

type TPCRYPT_CREDENTIALS = uintptr

type PCRYPT_CREDENTIALS = TPCRYPT_CREDENTIALS

type TCRYPT_PASSWORD_CREDENTIALSA = struct {
	FcbSize      TDWORD
	FpszUsername TLPSTR
	FpszPassword TLPSTR
}

type CRYPT_PASSWORD_CREDENTIALSA = TCRYPT_PASSWORD_CREDENTIALSA

type T_CRYPT_PASSWORD_CREDENTIALSA = TCRYPT_PASSWORD_CREDENTIALSA

type _CRYPT_PASSWORD_CREDENTIALSA = T_CRYPT_PASSWORD_CREDENTIALSA

type TPCRYPT_PASSWORD_CREDENTIALSA = uintptr

type PCRYPT_PASSWORD_CREDENTIALSA = TPCRYPT_PASSWORD_CREDENTIALSA

type TCRYPT_PASSWORD_CREDENTIALSW = struct {
	FcbSize      TDWORD
	FpszUsername TLPWSTR
	FpszPassword TLPWSTR
}

type CRYPT_PASSWORD_CREDENTIALSW = TCRYPT_PASSWORD_CREDENTIALSW

type T_CRYPT_PASSWORD_CREDENTIALSW = TCRYPT_PASSWORD_CREDENTIALSW

type _CRYPT_PASSWORD_CREDENTIALSW = T_CRYPT_PASSWORD_CREDENTIALSW

type TPCRYPT_PASSWORD_CREDENTIALSW = uintptr

type PCRYPT_PASSWORD_CREDENTIALSW = TPCRYPT_PASSWORD_CREDENTIALSW

type TCRYPT_PASSWORD_CREDENTIALS = struct {
	FcbSize      TDWORD
	FpszUsername TLPSTR
	FpszPassword TLPSTR
}

type CRYPT_PASSWORD_CREDENTIALS = TCRYPT_PASSWORD_CREDENTIALS

type TPCRYPT_PASSWORD_CREDENTIALS = uintptr

type PCRYPT_PASSWORD_CREDENTIALS = TPCRYPT_PASSWORD_CREDENTIALS

type TPFN_FREE_ENCODED_OBJECT_FUNC = uintptr

type PFN_FREE_ENCODED_OBJECT_FUNC = TPFN_FREE_ENCODED_OBJECT_FUNC

type TCRYPTNET_URL_CACHE_PRE_FETCH_INFO = struct {
	FcbSize         TDWORD
	FdwObjectType   TDWORD
	FdwError        TDWORD
	FdwReserved     TDWORD
	FThisUpdateTime TFILETIME
	FNextUpdateTime TFILETIME
	FPublishTime    TFILETIME
}

type CRYPTNET_URL_CACHE_PRE_FETCH_INFO = TCRYPTNET_URL_CACHE_PRE_FETCH_INFO

type T_CRYPTNET_URL_CACHE_PRE_FETCH_INFO = TCRYPTNET_URL_CACHE_PRE_FETCH_INFO

type _CRYPTNET_URL_CACHE_PRE_FETCH_INFO = T_CRYPTNET_URL_CACHE_PRE_FETCH_INFO

type TPCRYPTNET_URL_CACHE_PRE_FETCH_INFO = uintptr

type PCRYPTNET_URL_CACHE_PRE_FETCH_INFO = TPCRYPTNET_URL_CACHE_PRE_FETCH_INFO

type TCRYPTNET_URL_CACHE_FLUSH_INFO = struct {
	FcbSize          TDWORD
	FdwExemptSeconds TDWORD
	FExpireTime      TFILETIME
}

type CRYPTNET_URL_CACHE_FLUSH_INFO = TCRYPTNET_URL_CACHE_FLUSH_INFO

type T_CRYPTNET_URL_CACHE_FLUSH_INFO = TCRYPTNET_URL_CACHE_FLUSH_INFO

type _CRYPTNET_URL_CACHE_FLUSH_INFO = T_CRYPTNET_URL_CACHE_FLUSH_INFO

type TPCRYPTNET_URL_CACHE_FLUSH_INFO = uintptr

type PCRYPTNET_URL_CACHE_FLUSH_INFO = TPCRYPTNET_URL_CACHE_FLUSH_INFO

type TCRYPTNET_URL_CACHE_RESPONSE_INFO = struct {
	FcbSize           TDWORD
	FwResponseType    TWORD
	FwResponseFlags   TWORD
	FLastModifiedTime TFILETIME
	FdwMaxAge         TDWORD
	FpwszETag         TLPCWSTR
	FdwProxyId        TDWORD
}

type CRYPTNET_URL_CACHE_RESPONSE_INFO = TCRYPTNET_URL_CACHE_RESPONSE_INFO

type T_CRYPTNET_URL_CACHE_RESPONSE_INFO = TCRYPTNET_URL_CACHE_RESPONSE_INFO

type _CRYPTNET_URL_CACHE_RESPONSE_INFO = T_CRYPTNET_URL_CACHE_RESPONSE_INFO

type TPCRYPTNET_URL_CACHE_RESPONSE_INFO = uintptr

type PCRYPTNET_URL_CACHE_RESPONSE_INFO = TPCRYPTNET_URL_CACHE_RESPONSE_INFO

type TCRYPT_RETRIEVE_AUX_INFO = struct {
	FcbSize                     TDWORD
	FpLastSyncTime              uintptr
	FdwMaxUrlRetrievalByteCount TDWORD
	FpPreFetchInfo              TPCRYPTNET_URL_CACHE_PRE_FETCH_INFO
	FpFlushInfo                 TPCRYPTNET_URL_CACHE_FLUSH_INFO
	FppResponseInfo             uintptr
	FpwszCacheFileNamePrefix    TLPWSTR
	FpftCacheResync             TLPFILETIME
	FfProxyCacheRetrieval       TWINBOOL
	FdwHttpStatusCode           TDWORD
}

type CRYPT_RETRIEVE_AUX_INFO = TCRYPT_RETRIEVE_AUX_INFO

type T_CRYPT_RETRIEVE_AUX_INFO = TCRYPT_RETRIEVE_AUX_INFO

type _CRYPT_RETRIEVE_AUX_INFO = T_CRYPT_RETRIEVE_AUX_INFO

type TPCRYPT_RETRIEVE_AUX_INFO = uintptr

type PCRYPT_RETRIEVE_AUX_INFO = TPCRYPT_RETRIEVE_AUX_INFO

type TPFN_CRYPT_CANCEL_RETRIEVAL = uintptr

type PFN_CRYPT_CANCEL_RETRIEVAL = TPFN_CRYPT_CANCEL_RETRIEVAL

type TPFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC = uintptr

type PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC = TPFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC

type TCRYPT_ASYNC_RETRIEVAL_COMPLETION = struct {
	FpfnCompletion TPFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC
	FpvCompletion  TLPVOID
}

type CRYPT_ASYNC_RETRIEVAL_COMPLETION = TCRYPT_ASYNC_RETRIEVAL_COMPLETION

type T_CRYPT_ASYNC_RETRIEVAL_COMPLETION = TCRYPT_ASYNC_RETRIEVAL_COMPLETION

type _CRYPT_ASYNC_RETRIEVAL_COMPLETION = T_CRYPT_ASYNC_RETRIEVAL_COMPLETION

type TPCRYPT_ASYNC_RETRIEVAL_COMPLETION = uintptr

type PCRYPT_ASYNC_RETRIEVAL_COMPLETION = TPCRYPT_ASYNC_RETRIEVAL_COMPLETION

type TPFN_CANCEL_ASYNC_RETRIEVAL_FUNC = uintptr

type PFN_CANCEL_ASYNC_RETRIEVAL_FUNC = TPFN_CANCEL_ASYNC_RETRIEVAL_FUNC

type TCRYPT_URL_ARRAY = struct {
	FcUrl     TDWORD
	FrgwszUrl uintptr
}

type CRYPT_URL_ARRAY = TCRYPT_URL_ARRAY

type T_CRYPT_URL_ARRAY = TCRYPT_URL_ARRAY

type _CRYPT_URL_ARRAY = T_CRYPT_URL_ARRAY

type TPCRYPT_URL_ARRAY = uintptr

type PCRYPT_URL_ARRAY = TPCRYPT_URL_ARRAY

type TCRYPT_URL_INFO = struct {
	FcbSize          TDWORD
	FdwSyncDeltaTime TDWORD
	FcGroup          TDWORD
	FrgcGroupEntry   uintptr
}

type CRYPT_URL_INFO = TCRYPT_URL_INFO

type T_CRYPT_URL_INFO = TCRYPT_URL_INFO

type _CRYPT_URL_INFO = T_CRYPT_URL_INFO

type TPCRYPT_URL_INFO = uintptr

type PCRYPT_URL_INFO = TPCRYPT_URL_INFO

type TCERT_CRL_CONTEXT_PAIR = struct {
	FpCertContext TPCCERT_CONTEXT
	FpCrlContext  TPCCRL_CONTEXT
}

type CERT_CRL_CONTEXT_PAIR = TCERT_CRL_CONTEXT_PAIR

type T_CERT_CRL_CONTEXT_PAIR = TCERT_CRL_CONTEXT_PAIR

type _CERT_CRL_CONTEXT_PAIR = T_CERT_CRL_CONTEXT_PAIR

type TPCERT_CRL_CONTEXT_PAIR = uintptr

type PCERT_CRL_CONTEXT_PAIR = TPCERT_CRL_CONTEXT_PAIR

type TPCCERT_CRL_CONTEXT_PAIR = uintptr

type PCCERT_CRL_CONTEXT_PAIR = TPCCERT_CRL_CONTEXT_PAIR

type TCRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO = struct {
	FcbSize             TDWORD
	FiDeltaCrlIndicator int32
	FpftCacheResync     TLPFILETIME
	FpLastSyncTime      TLPFILETIME
	FpMaxAgeTime        TLPFILETIME
	FpChainPara         TPCERT_REVOCATION_CHAIN_PARA
	FpDeltaCrlIndicator TPCRYPT_INTEGER_BLOB
}

type CRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO = TCRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO

type T_CRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO = TCRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO

type _CRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO = T_CRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO

type TPCRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO = uintptr

type PCRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO = TPCRYPT_GET_TIME_VALID_OBJECT_EXTRA_INFO

type TPFN_CRYPT_ENUM_KEYID_PROP = uintptr

type PFN_CRYPT_ENUM_KEYID_PROP = TPFN_CRYPT_ENUM_KEYID_PROP

type THCERTCHAINENGINE = uintptr

type HCERTCHAINENGINE = THCERTCHAINENGINE

type TCERT_CHAIN_ENGINE_CONFIG = struct {
	FcbSize                    TDWORD
	FhRestrictedRoot           THCERTSTORE
	FhRestrictedTrust          THCERTSTORE
	FhRestrictedOther          THCERTSTORE
	FcAdditionalStore          TDWORD
	FrghAdditionalStore        uintptr
	FdwFlags                   TDWORD
	FdwUrlRetrievalTimeout     TDWORD
	FMaximumCachedCertificates TDWORD
	FCycleDetectionModulus     TDWORD
	FhExclusiveRoot            THCERTSTORE
	FhExclusiveTrustedPeople   THCERTSTORE
	FdwExclusiveFlags          TDWORD
}

type CERT_CHAIN_ENGINE_CONFIG = TCERT_CHAIN_ENGINE_CONFIG

type T_CERT_CHAIN_ENGINE_CONFIG = TCERT_CHAIN_ENGINE_CONFIG

type _CERT_CHAIN_ENGINE_CONFIG = T_CERT_CHAIN_ENGINE_CONFIG

type TPCERT_CHAIN_ENGINE_CONFIG = uintptr

type PCERT_CHAIN_ENGINE_CONFIG = TPCERT_CHAIN_ENGINE_CONFIG

type TCERT_TRUST_STATUS = struct {
	FdwErrorStatus TDWORD
	FdwInfoStatus  TDWORD
}

type CERT_TRUST_STATUS = TCERT_TRUST_STATUS

type T_CERT_TRUST_STATUS = TCERT_TRUST_STATUS

type _CERT_TRUST_STATUS = T_CERT_TRUST_STATUS

type TPCERT_TRUST_STATUS = uintptr

type PCERT_TRUST_STATUS = TPCERT_TRUST_STATUS

type TCERT_REVOCATION_INFO = struct {
	FcbSize             TDWORD
	FdwRevocationResult TDWORD
	FpszRevocationOid   TLPCSTR
	FpvOidSpecificInfo  TLPVOID
	FfHasFreshnessTime  TWINBOOL
	FdwFreshnessTime    TDWORD
	FpCrlInfo           TPCERT_REVOCATION_CRL_INFO
}

type CERT_REVOCATION_INFO = TCERT_REVOCATION_INFO

type T_CERT_REVOCATION_INFO = TCERT_REVOCATION_INFO

type _CERT_REVOCATION_INFO = T_CERT_REVOCATION_INFO

type TPCERT_REVOCATION_INFO = uintptr

type PCERT_REVOCATION_INFO = TPCERT_REVOCATION_INFO

type TCERT_TRUST_LIST_INFO = struct {
	FcbSize      TDWORD
	FpCtlEntry   TPCTL_ENTRY
	FpCtlContext TPCCTL_CONTEXT
}

type CERT_TRUST_LIST_INFO = TCERT_TRUST_LIST_INFO

type T_CERT_TRUST_LIST_INFO = TCERT_TRUST_LIST_INFO

type _CERT_TRUST_LIST_INFO = T_CERT_TRUST_LIST_INFO

type TPCERT_TRUST_LIST_INFO = uintptr

type PCERT_TRUST_LIST_INFO = TPCERT_TRUST_LIST_INFO

type TCERT_CHAIN_ELEMENT = struct {
	FcbSize                TDWORD
	FpCertContext          TPCCERT_CONTEXT
	FTrustStatus           TCERT_TRUST_STATUS
	FpRevocationInfo       TPCERT_REVOCATION_INFO
	FpIssuanceUsage        TPCERT_ENHKEY_USAGE
	FpApplicationUsage     TPCERT_ENHKEY_USAGE
	FpwszExtendedErrorInfo TLPCWSTR
}

type CERT_CHAIN_ELEMENT = TCERT_CHAIN_ELEMENT

type T_CERT_CHAIN_ELEMENT = TCERT_CHAIN_ELEMENT

type _CERT_CHAIN_ELEMENT = T_CERT_CHAIN_ELEMENT

type TPCERT_CHAIN_ELEMENT = uintptr

type PCERT_CHAIN_ELEMENT = TPCERT_CHAIN_ELEMENT

type TPCCERT_CHAIN_ELEMENT = uintptr

type PCCERT_CHAIN_ELEMENT = TPCCERT_CHAIN_ELEMENT

type TCERT_SIMPLE_CHAIN = struct {
	FcbSize                      TDWORD
	FTrustStatus                 TCERT_TRUST_STATUS
	FcElement                    TDWORD
	FrgpElement                  uintptr
	FpTrustListInfo              TPCERT_TRUST_LIST_INFO
	FfHasRevocationFreshnessTime TWINBOOL
	FdwRevocationFreshnessTime   TDWORD
}

type CERT_SIMPLE_CHAIN = TCERT_SIMPLE_CHAIN

type T_CERT_SIMPLE_CHAIN = TCERT_SIMPLE_CHAIN

type _CERT_SIMPLE_CHAIN = T_CERT_SIMPLE_CHAIN

type TPCERT_SIMPLE_CHAIN = uintptr

type PCERT_SIMPLE_CHAIN = TPCERT_SIMPLE_CHAIN

type TPCCERT_SIMPLE_CHAIN = uintptr

type PCCERT_SIMPLE_CHAIN = TPCCERT_SIMPLE_CHAIN

type TCERT_CHAIN_CONTEXT = struct {
	FcbSize                      TDWORD
	FTrustStatus                 TCERT_TRUST_STATUS
	FcChain                      TDWORD
	FrgpChain                    uintptr
	FcLowerQualityChainContext   TDWORD
	FrgpLowerQualityChainContext uintptr
	FfHasRevocationFreshnessTime TWINBOOL
	FdwRevocationFreshnessTime   TDWORD
	FdwCreateFlags               TDWORD
	FChainId                     TGUID
}

type CERT_CHAIN_CONTEXT = TCERT_CHAIN_CONTEXT

type T_CERT_CHAIN_CONTEXT = TCERT_CHAIN_CONTEXT

type _CERT_CHAIN_CONTEXT = T_CERT_CHAIN_CONTEXT

type TPCERT_CHAIN_CONTEXT = uintptr

type PCERT_CHAIN_CONTEXT = TPCERT_CHAIN_CONTEXT

type TPCCERT_CHAIN_CONTEXT = uintptr

type PCCERT_CHAIN_CONTEXT = TPCCERT_CHAIN_CONTEXT

type TCERT_USAGE_MATCH = struct {
	FdwType TDWORD
	FUsage  TCERT_ENHKEY_USAGE
}

type CERT_USAGE_MATCH = TCERT_USAGE_MATCH

type T_CERT_USAGE_MATCH = TCERT_USAGE_MATCH

type _CERT_USAGE_MATCH = T_CERT_USAGE_MATCH

type TPCERT_USAGE_MATCH = uintptr

type PCERT_USAGE_MATCH = TPCERT_USAGE_MATCH

type TCTL_USAGE_MATCH = struct {
	FdwType TDWORD
	FUsage  TCTL_USAGE
}

type CTL_USAGE_MATCH = TCTL_USAGE_MATCH

type T_CTL_USAGE_MATCH = TCTL_USAGE_MATCH

type _CTL_USAGE_MATCH = T_CTL_USAGE_MATCH

type TPCTL_USAGE_MATCH = uintptr

type PCTL_USAGE_MATCH = TPCTL_USAGE_MATCH

type TCERT_CHAIN_PARA = struct {
	FcbSize         TDWORD
	FRequestedUsage TCERT_USAGE_MATCH
}

type CERT_CHAIN_PARA = TCERT_CHAIN_PARA

type T_CERT_CHAIN_PARA = TCERT_CHAIN_PARA

type _CERT_CHAIN_PARA = T_CERT_CHAIN_PARA

type TPCERT_CHAIN_PARA = uintptr

type PCERT_CHAIN_PARA = TPCERT_CHAIN_PARA

type TCRL_REVOCATION_INFO = struct {
	FpCrlEntry       TPCRL_ENTRY
	FpCrlContext     TPCCRL_CONTEXT
	FpCrlIssuerChain TPCCERT_CHAIN_CONTEXT
}

type CRL_REVOCATION_INFO = TCRL_REVOCATION_INFO

type T_CRL_REVOCATION_INFO = TCRL_REVOCATION_INFO

type _CRL_REVOCATION_INFO = T_CRL_REVOCATION_INFO

type TPCRL_REVOCATION_INFO = uintptr

type PCRL_REVOCATION_INFO = TPCRL_REVOCATION_INFO

type TPFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK = uintptr

type PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK = TPFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK

type TCERT_CHAIN_FIND_ISSUER_PARA = struct {
	FcbSize                   TDWORD
	FpszUsageIdentifier       TLPCSTR
	FdwKeySpec                TDWORD
	FdwAcquirePrivateKeyFlags TDWORD
	FcIssuer                  TDWORD
	FrgIssuer                 uintptr
	FpfnFindCallback          TPFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK
	FpvFindArg                uintptr
}

type CERT_CHAIN_FIND_ISSUER_PARA = TCERT_CHAIN_FIND_ISSUER_PARA

type T_CERT_CHAIN_FIND_BY_ISSUER_PARA = TCERT_CHAIN_FIND_ISSUER_PARA

type _CERT_CHAIN_FIND_BY_ISSUER_PARA = T_CERT_CHAIN_FIND_BY_ISSUER_PARA

type TPCERT_CHAIN_FIND_ISSUER_PARA = uintptr

type PCERT_CHAIN_FIND_ISSUER_PARA = TPCERT_CHAIN_FIND_ISSUER_PARA

type TCERT_CHAIN_FIND_BY_ISSUER_PARA = struct {
	FcbSize                   TDWORD
	FpszUsageIdentifier       TLPCSTR
	FdwKeySpec                TDWORD
	FdwAcquirePrivateKeyFlags TDWORD
	FcIssuer                  TDWORD
	FrgIssuer                 uintptr
	FpfnFindCallback          TPFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK
	FpvFindArg                uintptr
}

type CERT_CHAIN_FIND_BY_ISSUER_PARA = TCERT_CHAIN_FIND_BY_ISSUER_PARA

type TPCERT_CHAIN_FIND_BY_ISSUER_PARA = uintptr

type PCERT_CHAIN_FIND_BY_ISSUER_PARA = TPCERT_CHAIN_FIND_BY_ISSUER_PARA

type TCERT_CHAIN_POLICY_PARA = struct {
	FcbSize            TDWORD
	FdwFlags           TDWORD
	FpvExtraPolicyPara uintptr
}

type CERT_CHAIN_POLICY_PARA = TCERT_CHAIN_POLICY_PARA

type T_CERT_CHAIN_POLICY_PARA = TCERT_CHAIN_POLICY_PARA

type _CERT_CHAIN_POLICY_PARA = T_CERT_CHAIN_POLICY_PARA

type TPCERT_CHAIN_POLICY_PARA = uintptr

type PCERT_CHAIN_POLICY_PARA = TPCERT_CHAIN_POLICY_PARA

type TCERT_CHAIN_POLICY_STATUS = struct {
	FcbSize              TDWORD
	FdwError             TDWORD
	FlChainIndex         TLONG
	FlElementIndex       TLONG
	FpvExtraPolicyStatus uintptr
}

type CERT_CHAIN_POLICY_STATUS = TCERT_CHAIN_POLICY_STATUS

type T_CERT_CHAIN_POLICY_STATUS = TCERT_CHAIN_POLICY_STATUS

type _CERT_CHAIN_POLICY_STATUS = T_CERT_CHAIN_POLICY_STATUS

type TPCERT_CHAIN_POLICY_STATUS = uintptr

type PCERT_CHAIN_POLICY_STATUS = TPCERT_CHAIN_POLICY_STATUS

type TAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA = struct {
	FcbSize              TDWORD
	FdwRegPolicySettings TDWORD
	FpSignerInfo         TPCMSG_SIGNER_INFO
}

type AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA = TAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA

type T_AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA = TAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA

type _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA = T_AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA

type TPAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA = uintptr

type PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA = TPAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA

type TAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS = struct {
	FcbSize      TDWORD
	FfCommercial TWINBOOL
}

type AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS = TAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS

type T_AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS = TAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS

type _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS = T_AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS

type TPAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS = uintptr

type PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS = TPAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS

type TAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA = struct {
	FcbSize              TDWORD
	FdwRegPolicySettings TDWORD
	FfCommercial         TWINBOOL
}

type AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA = TAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA

type T_AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA = TAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA

type _AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA = T_AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA

type TPAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA = uintptr

type PAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA = TPAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA

type THTTPSPolicyCallbackData = struct {
	F__ccgo0_0 struct {
		FcbSize   [0]TDWORD
		FcbStruct TDWORD
	}
	FdwAuthType     TDWORD
	FfdwChecks      TDWORD
	FpwszServerName uintptr
}

type HTTPSPolicyCallbackData = THTTPSPolicyCallbackData

type T_HTTPSPolicyCallbackData = THTTPSPolicyCallbackData

type _HTTPSPolicyCallbackData = T_HTTPSPolicyCallbackData

type TPHTTPSPolicyCallbackData = uintptr

type PHTTPSPolicyCallbackData = TPHTTPSPolicyCallbackData

type TSSL_EXTRA_CERT_CHAIN_POLICY_PARA = struct {
	F__ccgo0_0 struct {
		FcbSize   [0]TDWORD
		FcbStruct TDWORD
	}
	FdwAuthType     TDWORD
	FfdwChecks      TDWORD
	FpwszServerName uintptr
}

type SSL_EXTRA_CERT_CHAIN_POLICY_PARA = TSSL_EXTRA_CERT_CHAIN_POLICY_PARA

type TPSSL_EXTRA_CERT_CHAIN_POLICY_PARA = uintptr

type PSSL_EXTRA_CERT_CHAIN_POLICY_PARA = TPSSL_EXTRA_CERT_CHAIN_POLICY_PARA

type TEV_EXTRA_CERT_CHAIN_POLICY_PARA = struct {
	FcbSize                      TDWORD
	FdwRootProgramQualifierFlags TDWORD
}

type EV_EXTRA_CERT_CHAIN_POLICY_PARA = TEV_EXTRA_CERT_CHAIN_POLICY_PARA

type T_EV_EXTRA_CERT_CHAIN_POLICY_PARA = TEV_EXTRA_CERT_CHAIN_POLICY_PARA

type _EV_EXTRA_CERT_CHAIN_POLICY_PARA = T_EV_EXTRA_CERT_CHAIN_POLICY_PARA

type TPEV_EXTRA_CERT_CHAIN_POLICY_PARA = uintptr

type PEV_EXTRA_CERT_CHAIN_POLICY_PARA = TPEV_EXTRA_CERT_CHAIN_POLICY_PARA

type TEV_EXTRA_CERT_CHAIN_POLICY_STATUS = struct {
	FcbSize               TDWORD
	FdwQualifiers         TDWORD
	FdwIssuanceUsageIndex TDWORD
}

type EV_EXTRA_CERT_CHAIN_POLICY_STATUS = TEV_EXTRA_CERT_CHAIN_POLICY_STATUS

type T_EV_EXTRA_CERT_CHAIN_POLICY_STATUS = TEV_EXTRA_CERT_CHAIN_POLICY_STATUS

type _EV_EXTRA_CERT_CHAIN_POLICY_STATUS = T_EV_EXTRA_CERT_CHAIN_POLICY_STATUS

type TPEV_EXTRA_CERT_CHAIN_POLICY_STATUS = uintptr

type PEV_EXTRA_CERT_CHAIN_POLICY_STATUS = TPEV_EXTRA_CERT_CHAIN_POLICY_STATUS

type TSSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS = struct {
	FcbSize          TDWORD
	FdwErrorLevel    TDWORD
	FdwErrorCategory TDWORD
	FdwReserved      TDWORD
	FwszErrorText    [256]TWCHAR
}

type SSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS = TSSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS

type T_SSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS = TSSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS

type _SSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS = T_SSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS

type TPSSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS = uintptr

type PSSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS = TPSSL_F12_EXTRA_CERT_CHAIN_POLICY_STATUS

type TSSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA = struct {
	FcbSize         TDWORD
	FdwReserved     TDWORD
	FpwszServerName TLPWSTR
	FrgpszHpkpValue [2]TLPSTR
}

type SSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA = TSSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA

type T_SSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA = TSSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA

type _SSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA = T_SSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA

type TPSSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA = uintptr

type PSSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA = TPSSL_HPKP_HEADER_EXTRA_CERT_CHAIN_POLICY_PARA

type TSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA = struct {
	FcbSize         TDWORD
	FdwReserved     TDWORD
	FpwszServerName TPCWSTR
}

type SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA = TSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA

type T_SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA = TSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA

type _SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA = T_SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA

type TPSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA = uintptr

type PSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA = TPSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_PARA

type TSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS = struct {
	FcbSize       TDWORD
	FlError       TLONG
	FwszErrorText [512]TWCHAR
}

type SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS = TSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS

type T_SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS = TSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS

type _SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS = T_SSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS

type TPSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS = uintptr

type PSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS = TPSSL_KEY_PIN_EXTRA_CERT_CHAIN_POLICY_STATUS

type TCRYPT_PKCS12_PBE_PARAMS = struct {
	FiIterations int32
	FcbSalt      TULONG
}

type CRYPT_PKCS12_PBE_PARAMS = TCRYPT_PKCS12_PBE_PARAMS

type T_CRYPT_PKCS12_PBE_PARAMS = TCRYPT_PKCS12_PBE_PARAMS

type _CRYPT_PKCS12_PBE_PARAMS = T_CRYPT_PKCS12_PBE_PARAMS

type TPKCS12_PBES2_EXPORT_PARAMS = struct {
	FdwSize            TDWORD
	FhNcryptDescriptor TPVOID
	FpwszPbes2Alg      TLPWSTR
}

type PKCS12_PBES2_EXPORT_PARAMS = TPKCS12_PBES2_EXPORT_PARAMS

type T_PKCS12_PBES2_EXPORT_PARAMS = TPKCS12_PBES2_EXPORT_PARAMS

type _PKCS12_PBES2_EXPORT_PARAMS = T_PKCS12_PBES2_EXPORT_PARAMS

type TPPKCS12_PBES2_EXPORT_PARAMS = uintptr

type PPKCS12_PBES2_EXPORT_PARAMS = TPPKCS12_PBES2_EXPORT_PARAMS

type THCERT_SERVER_OCSP_RESPONSE = uintptr

type HCERT_SERVER_OCSP_RESPONSE = THCERT_SERVER_OCSP_RESPONSE

type TCERT_SERVER_OCSP_RESPONSE_CONTEXT = struct {
	FcbSize                TDWORD
	FpbEncodedOcspResponse uintptr
	FcbEncodedOcspResponse TDWORD
}

type CERT_SERVER_OCSP_RESPONSE_CONTEXT = TCERT_SERVER_OCSP_RESPONSE_CONTEXT

type T_CERT_SERVER_OCSP_RESPONSE_CONTEXT = TCERT_SERVER_OCSP_RESPONSE_CONTEXT

type _CERT_SERVER_OCSP_RESPONSE_CONTEXT = T_CERT_SERVER_OCSP_RESPONSE_CONTEXT

type TPCERT_SERVER_OCSP_RESPONSE_CONTEXT = uintptr

type PCERT_SERVER_OCSP_RESPONSE_CONTEXT = TPCERT_SERVER_OCSP_RESPONSE_CONTEXT

type TPCCERT_SERVER_OCSP_RESPONSE_CONTEXT = uintptr

type PCCERT_SERVER_OCSP_RESPONSE_CONTEXT = TPCCERT_SERVER_OCSP_RESPONSE_CONTEXT

type TPFN_CERT_SERVER_OCSP_RESPONSE_UPDATE_CALLBACK = uintptr

type PFN_CERT_SERVER_OCSP_RESPONSE_UPDATE_CALLBACK = TPFN_CERT_SERVER_OCSP_RESPONSE_UPDATE_CALLBACK

type TCERT_SERVER_OCSP_RESPONSE_OPEN_PARA = struct {
	FcbSize              TDWORD
	FdwFlags             TDWORD
	FpcbUsedSize         uintptr
	FpwszOcspDirectory   TPWSTR
	FpfnUpdateCallback   TPFN_CERT_SERVER_OCSP_RESPONSE_UPDATE_CALLBACK
	FpvUpdateCallbackArg TPVOID
}

type CERT_SERVER_OCSP_RESPONSE_OPEN_PARA = TCERT_SERVER_OCSP_RESPONSE_OPEN_PARA

type T_CERT_SERVER_OCSP_RESPONSE_OPEN_PARA = TCERT_SERVER_OCSP_RESPONSE_OPEN_PARA

type _CERT_SERVER_OCSP_RESPONSE_OPEN_PARA = T_CERT_SERVER_OCSP_RESPONSE_OPEN_PARA

type TPCERT_SERVER_OCSP_RESPONSE_OPEN_PARA = uintptr

type PCERT_SERVER_OCSP_RESPONSE_OPEN_PARA = TPCERT_SERVER_OCSP_RESPONSE_OPEN_PARA

type TCERT_SELECT_CHAIN_PARA = struct {
	FhChainEngine     THCERTCHAINENGINE
	FpTime            TPFILETIME
	FhAdditionalStore THCERTSTORE
	FpChainPara       TPCERT_CHAIN_PARA
	FdwFlags          TDWORD
}

type CERT_SELECT_CHAIN_PARA = TCERT_SELECT_CHAIN_PARA

type T_CERT_SELECT_CHAIN_PARA = TCERT_SELECT_CHAIN_PARA

type _CERT_SELECT_CHAIN_PARA = T_CERT_SELECT_CHAIN_PARA

type TPCERT_SELECT_CHAIN_PARA = uintptr

type PCERT_SELECT_CHAIN_PARA = TPCERT_SELECT_CHAIN_PARA

type TPCCERT_SELECT_CHAIN_PARA = uintptr

type PCCERT_SELECT_CHAIN_PARA = TPCCERT_SELECT_CHAIN_PARA

type TCERT_SELECT_CRITERIA = struct {
	FdwType TDWORD
	FcPara  TDWORD
	FppPara uintptr
}

type CERT_SELECT_CRITERIA = TCERT_SELECT_CRITERIA

type T_CERT_SELECT_CRITERIA = TCERT_SELECT_CRITERIA

type _CERT_SELECT_CRITERIA = T_CERT_SELECT_CRITERIA

type TPCERT_SELECT_CRITERIA = uintptr

type PCERT_SELECT_CRITERIA = TPCERT_SELECT_CRITERIA

type TPCCERT_SELECT_CRITERIA = uintptr

type PCCERT_SELECT_CRITERIA = TPCCERT_SELECT_CRITERIA

type TCRYPT_TIMESTAMP_REQUEST = struct {
	FdwVersion      TDWORD
	FHashAlgorithm  TCRYPT_ALGORITHM_IDENTIFIER
	FHashedMessage  TCRYPT_DER_BLOB
	FpszTSAPolicyId TLPSTR
	FNonce          TCRYPT_INTEGER_BLOB
	FfCertReq       TWINBOOL
	FcExtension     TDWORD
	FrgExtension    TPCERT_EXTENSION
}

type CRYPT_TIMESTAMP_REQUEST = TCRYPT_TIMESTAMP_REQUEST

type T_CRYPT_TIMESTAMP_REQUEST = TCRYPT_TIMESTAMP_REQUEST

type _CRYPT_TIMESTAMP_REQUEST = T_CRYPT_TIMESTAMP_REQUEST

type TPCRYPT_TIMESTAMP_REQUEST = uintptr

type PCRYPT_TIMESTAMP_REQUEST = TPCRYPT_TIMESTAMP_REQUEST

type TCRYPT_TIMESTAMP_RESPONSE = struct {
	FdwStatus    TDWORD
	FcFreeText   TDWORD
	FrgFreeText  uintptr
	FFailureInfo TCRYPT_BIT_BLOB
	FContentInfo TCRYPT_DER_BLOB
}

type CRYPT_TIMESTAMP_RESPONSE = TCRYPT_TIMESTAMP_RESPONSE

type T_CRYPT_TIMESTAMP_RESPONSE = TCRYPT_TIMESTAMP_RESPONSE

type _CRYPT_TIMESTAMP_RESPONSE = T_CRYPT_TIMESTAMP_RESPONSE

type TPCRYPT_TIMESTAMP_RESPONSE = uintptr

type PCRYPT_TIMESTAMP_RESPONSE = TPCRYPT_TIMESTAMP_RESPONSE

type TCRYPT_TIMESTAMP_ACCURACY = struct {
	FdwSeconds TDWORD
	FdwMillis  TDWORD
	FdwMicros  TDWORD
}

type CRYPT_TIMESTAMP_ACCURACY = TCRYPT_TIMESTAMP_ACCURACY

type T_CRYPT_TIMESTAMP_ACCURACY = TCRYPT_TIMESTAMP_ACCURACY

type _CRYPT_TIMESTAMP_ACCURACY = T_CRYPT_TIMESTAMP_ACCURACY

type TPCRYPT_TIMESTAMP_ACCURACY = uintptr

type PCRYPT_TIMESTAMP_ACCURACY = TPCRYPT_TIMESTAMP_ACCURACY

type TCRYPT_TIMESTAMP_INFO = struct {
	FdwVersion      TDWORD
	FpszTSAPolicyId TLPSTR
	FHashAlgorithm  TCRYPT_ALGORITHM_IDENTIFIER
	FHashedMessage  TCRYPT_DER_BLOB
	FSerialNumber   TCRYPT_INTEGER_BLOB
	FftTime         TFILETIME
	FpvAccuracy     TPCRYPT_TIMESTAMP_ACCURACY
	FfOrdering      TWINBOOL
	FNonce          TCRYPT_DER_BLOB
	FTsa            TCRYPT_DER_BLOB
	FcExtension     TDWORD
	FrgExtension    TPCERT_EXTENSION
}

type CRYPT_TIMESTAMP_INFO = TCRYPT_TIMESTAMP_INFO

type T_CRYPT_TIMESTAMP_INFO = TCRYPT_TIMESTAMP_INFO

type _CRYPT_TIMESTAMP_INFO = T_CRYPT_TIMESTAMP_INFO

type TPCRYPT_TIMESTAMP_INFO = uintptr

type PCRYPT_TIMESTAMP_INFO = TPCRYPT_TIMESTAMP_INFO

type TCRYPT_TIMESTAMP_CONTEXT = struct {
	FcbEncoded  TDWORD
	FpbEncoded  uintptr
	FpTimeStamp TPCRYPT_TIMESTAMP_INFO
}

type CRYPT_TIMESTAMP_CONTEXT = TCRYPT_TIMESTAMP_CONTEXT

type T_CRYPT_TIMESTAMP_CONTEXT = TCRYPT_TIMESTAMP_CONTEXT

type _CRYPT_TIMESTAMP_CONTEXT = T_CRYPT_TIMESTAMP_CONTEXT

type TPCRYPT_TIMESTAMP_CONTEXT = uintptr

type PCRYPT_TIMESTAMP_CONTEXT = TPCRYPT_TIMESTAMP_CONTEXT

type TCRYPT_TIMESTAMP_PARA = struct {
	FpszTSAPolicyId TLPCSTR
	FfRequestCerts  TWINBOOL
	FNonce          TCRYPT_INTEGER_BLOB
	FcExtension     TDWORD
	FrgExtension    TPCERT_EXTENSION
}

type CRYPT_TIMESTAMP_PARA = TCRYPT_TIMESTAMP_PARA

type T_CRYPT_TIMESTAMP_PARA = TCRYPT_TIMESTAMP_PARA

type _CRYPT_TIMESTAMP_PARA = T_CRYPT_TIMESTAMP_PARA

type TPCRYPT_TIMESTAMP_PARA = uintptr

type PCRYPT_TIMESTAMP_PARA = TPCRYPT_TIMESTAMP_PARA

type TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FLUSH = uintptr

type PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FLUSH = TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FLUSH

type TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET = uintptr

type PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET = TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET

type TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_RELEASE = uintptr

type PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_RELEASE = TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_RELEASE

type TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_PASSWORD = uintptr

type PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_PASSWORD = TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_PASSWORD

type TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE = uintptr

type PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE = TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE

type TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_IDENTIFIER = uintptr

type PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_IDENTIFIER = TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_IDENTIFIER

type TCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE = struct {
	FcbSize            TDWORD
	FpfnGet            TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET
	FpfnRelease        TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_RELEASE
	FpfnFreePassword   TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_PASSWORD
	FpfnFree           TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE
	FpfnFreeIdentifier TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_IDENTIFIER
}

type CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE = TCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE

type T_CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE = TCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE

type _CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE = T_CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE

type TPCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE = uintptr

type PCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE = TPCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE

type TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_INITIALIZE = uintptr

type PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_INITIALIZE = TPFN_CRYPT_OBJECT_LOCATOR_PROVIDER_INITIALIZE

type TPFN_CERT_IS_WEAK_HASH = uintptr

type PFN_CERT_IS_WEAK_HASH = TPFN_CERT_IS_WEAK_HASH

type TCRYPTPROTECT_PROMPTSTRUCT = struct {
	FcbSize        TDWORD
	FdwPromptFlags TDWORD
	FhwndApp       THWND
	FszPrompt      TLPCWSTR
}

type CRYPTPROTECT_PROMPTSTRUCT = TCRYPTPROTECT_PROMPTSTRUCT

type T_CRYPTPROTECT_PROMPTSTRUCT = TCRYPTPROTECT_PROMPTSTRUCT

type _CRYPTPROTECT_PROMPTSTRUCT = T_CRYPTPROTECT_PROMPTSTRUCT

type TPCRYPTPROTECT_PROMPTSTRUCT = uintptr

type PCRYPTPROTECT_PROMPTSTRUCT = TPCRYPTPROTECT_PROMPTSTRUCT

type TEFS_CERTIFICATE_BLOB = struct {
	FdwCertEncodingType TDWORD
	FcbData             TDWORD
	FpbData             TPBYTE
}

type EFS_CERTIFICATE_BLOB = TEFS_CERTIFICATE_BLOB

type T_CERTIFICATE_BLOB = TEFS_CERTIFICATE_BLOB

type _CERTIFICATE_BLOB = T_CERTIFICATE_BLOB

type TPEFS_CERTIFICATE_BLOB = uintptr

type PEFS_CERTIFICATE_BLOB = TPEFS_CERTIFICATE_BLOB

type TEFS_HASH_BLOB = struct {
	FcbData TDWORD
	FpbData TPBYTE
}

type EFS_HASH_BLOB = TEFS_HASH_BLOB

type T_EFS_HASH_BLOB = TEFS_HASH_BLOB

type _EFS_HASH_BLOB = T_EFS_HASH_BLOB

type TPEFS_HASH_BLOB = uintptr

type PEFS_HASH_BLOB = TPEFS_HASH_BLOB

type TEFS_RPC_BLOB = struct {
	FcbData TDWORD
	FpbData TPBYTE
}

type EFS_RPC_BLOB = TEFS_RPC_BLOB

type T_EFS_RPC_BLOB = TEFS_RPC_BLOB

type _EFS_RPC_BLOB = T_EFS_RPC_BLOB

type TPEFS_RPC_BLOB = uintptr

type PEFS_RPC_BLOB = TPEFS_RPC_BLOB

type TEFS_KEY_INFO = struct {
	FdwVersion TDWORD
	FEntropy   TULONG
	FAlgorithm TALG_ID
	FKeyLength TULONG
}

type EFS_KEY_INFO = TEFS_KEY_INFO

type T_EFS_KEY_INFO = TEFS_KEY_INFO

type _EFS_KEY_INFO = T_EFS_KEY_INFO

type TPEFS_KEY_INFO = uintptr

type PEFS_KEY_INFO = TPEFS_KEY_INFO

type TENCRYPTION_CERTIFICATE = struct {
	FcbTotalLength TDWORD
	FpUserSid      uintptr
	FpCertBlob     TPEFS_CERTIFICATE_BLOB
}

type ENCRYPTION_CERTIFICATE = TENCRYPTION_CERTIFICATE

type T_ENCRYPTION_CERTIFICATE = TENCRYPTION_CERTIFICATE

type _ENCRYPTION_CERTIFICATE = T_ENCRYPTION_CERTIFICATE

type TPENCRYPTION_CERTIFICATE = uintptr

type PENCRYPTION_CERTIFICATE = TPENCRYPTION_CERTIFICATE

type TENCRYPTION_CERTIFICATE_HASH = struct {
	FcbTotalLength        TDWORD
	FpUserSid             uintptr
	FpHash                TPEFS_HASH_BLOB
	FlpDisplayInformation TLPWSTR
}

type ENCRYPTION_CERTIFICATE_HASH = TENCRYPTION_CERTIFICATE_HASH

type T_ENCRYPTION_CERTIFICATE_HASH = TENCRYPTION_CERTIFICATE_HASH

type _ENCRYPTION_CERTIFICATE_HASH = T_ENCRYPTION_CERTIFICATE_HASH

type TPENCRYPTION_CERTIFICATE_HASH = uintptr

type PENCRYPTION_CERTIFICATE_HASH = TPENCRYPTION_CERTIFICATE_HASH

type TENCRYPTION_CERTIFICATE_HASH_LIST = struct {
	FnCert_Hash TDWORD
	FpUsers     uintptr
}

type ENCRYPTION_CERTIFICATE_HASH_LIST = TENCRYPTION_CERTIFICATE_HASH_LIST

type T_ENCRYPTION_CERTIFICATE_HASH_LIST = TENCRYPTION_CERTIFICATE_HASH_LIST

type _ENCRYPTION_CERTIFICATE_HASH_LIST = T_ENCRYPTION_CERTIFICATE_HASH_LIST

type TPENCRYPTION_CERTIFICATE_HASH_LIST = uintptr

type PENCRYPTION_CERTIFICATE_HASH_LIST = TPENCRYPTION_CERTIFICATE_HASH_LIST

type TENCRYPTION_CERTIFICATE_LIST = struct {
	FnUsers TDWORD
	FpUsers uintptr
}

type ENCRYPTION_CERTIFICATE_LIST = TENCRYPTION_CERTIFICATE_LIST

type T_ENCRYPTION_CERTIFICATE_LIST = TENCRYPTION_CERTIFICATE_LIST

type _ENCRYPTION_CERTIFICATE_LIST = T_ENCRYPTION_CERTIFICATE_LIST

type TPENCRYPTION_CERTIFICATE_LIST = uintptr

type PENCRYPTION_CERTIFICATE_LIST = TPENCRYPTION_CERTIFICATE_LIST

type TRPC_IMPORT_CONTEXT_P = struct {
	FLookupContext  TRPC_NS_HANDLE
	FProposedHandle TRPC_BINDING_HANDLE
	FBindings       uintptr
}

type RPC_IMPORT_CONTEXT_P = TRPC_IMPORT_CONTEXT_P

type TPRPC_IMPORT_CONTEXT_P = uintptr

type PRPC_IMPORT_CONTEXT_P = TPRPC_IMPORT_CONTEXT_P

type Tbyte = uint8

type byte = Tbyte

type Tcs_byte = uint8

type cs_byte = Tcs_byte

type Tboolean = uint8

type boolean = Tboolean

type TNDR_CCONTEXT = uintptr

type NDR_CCONTEXT = TNDR_CCONTEXT

type TNDR_SCONTEXT = uintptr

type NDR_SCONTEXT = TNDR_SCONTEXT

type T_NDR_SCONTEXT = struct {
	Fpad         [2]uintptr
	FuserContext uintptr
}

type _NDR_SCONTEXT = T_NDR_SCONTEXT

type TNDR_RUNDOWN = uintptr

type NDR_RUNDOWN = TNDR_RUNDOWN

type TNDR_NOTIFY_ROUTINE = uintptr

type NDR_NOTIFY_ROUTINE = TNDR_NOTIFY_ROUTINE

type TNDR_NOTIFY2_ROUTINE = uintptr

type NDR_NOTIFY2_ROUTINE = TNDR_NOTIFY2_ROUTINE

type TSCONTEXT_QUEUE = struct {
	FNumberOfObjects uint32
	FArrayOfObjects  uintptr
}

type SCONTEXT_QUEUE = TSCONTEXT_QUEUE

type T_SCONTEXT_QUEUE = TSCONTEXT_QUEUE

type _SCONTEXT_QUEUE = T_SCONTEXT_QUEUE

type TPSCONTEXT_QUEUE = uintptr

type PSCONTEXT_QUEUE = TPSCONTEXT_QUEUE

type Terror_status_t = uint32

type error_status_t = Terror_status_t

type T_MIDL_STUB_MESSAGE = struct {
	FRpcMsg                 TPRPC_MESSAGE
	FBuffer                 uintptr
	FBufferStart            uintptr
	FBufferEnd              uintptr
	FBufferMark             uintptr
	FBufferLength           uint32
	FMemorySize             uint32
	FMemory                 uintptr
	FIsClient               uint8
	FPad                    uint8
	FuFlags2                uint16
	FReuseBuffer            int32
	FpAllocAllNodesContext  uintptr
	FpPointerQueueState     uintptr
	FIgnoreEmbeddedPointers int32
	FPointerBufferMark      uintptr
	FfBufferValid           uint8
	FuFlags                 uint8
	FUniquePtrCount         uint16
	FMaxCount               TULONG_PTR
	FOffset                 uint32
	FActualCount            uint32
	FpfnAllocate            uintptr
	FpfnFree                uintptr
	FStackTop               uintptr
	FpPresentedType         uintptr
	FpTransmitType          uintptr
	FSavedHandle            Thandle_t
	FStubDesc               uintptr
	FFullPtrXlatTables      uintptr
	FFullPtrRefId           uint32
	FPointerLength          uint32
	F__ccgo112              uint32
	FdwDestContext          uint32
	FpvDestContext          uintptr
	FSavedContextHandles    uintptr
	FParamNumber            int32
	FpRpcChannelBuffer      uintptr
	FpArrayInfo             TPARRAY_INFO
	FSizePtrCountArray      uintptr
	FSizePtrOffsetArray     uintptr
	FSizePtrLengthArray     uintptr
	FpArgQueue              uintptr
	FdwStubPhase            uint32
	FLowStackMark           uintptr
	FpAsyncMsg              TPNDR_ASYNC_MESSAGE
	FpCorrInfo              TPNDR_CORRELATION_INFO
	FpCorrMemory            uintptr
	FpMemoryList            uintptr
	FpCSInfo                uintptr
	FConformanceMark        uintptr
	FVarianceMark           uintptr
	FUnused                 TINT_PTR
	FpContext               uintptr
	FpUserMarshalList       uintptr
	FReserved51_2           TINT_PTR
	FReserved51_3           TINT_PTR
	FReserved51_4           TINT_PTR
	FReserved51_5           TINT_PTR
}

type _MIDL_STUB_MESSAGE = T_MIDL_STUB_MESSAGE

type T_MIDL_STUB_DESC = struct {
	FRpcInterfaceInformation uintptr
	FpfnAllocate             uintptr
	FpfnFree                 uintptr
	FIMPLICIT_HANDLE_INFO    struct {
		FpPrimitiveHandle    [0]uintptr
		FpGenericBindingInfo [0]TPGENERIC_BINDING_INFO
		FpAutoHandle         uintptr
	}
	FapfnNdrRundownRoutines      uintptr
	FaGenericBindingRoutinePairs uintptr
	FapfnExprEval                uintptr
	FaXmitQuintuple              uintptr
	FpFormatTypes                uintptr
	FfCheckBounds                int32
	FVersion                     uint32
	FpMallocFreeStruct           uintptr
	FMIDLVersion                 int32
	FCommFaultOffsets            uintptr
	FaUserMarshalQuadruple       uintptr
	FNotifyRoutineTable          uintptr
	FmFlags                      TULONG_PTR
	FCsRoutineTables             uintptr
	FReserved4                   uintptr
	FReserved5                   TULONG_PTR
}

type _MIDL_STUB_DESC = T_MIDL_STUB_DESC

type T_FULL_PTR_XLAT_TABLES = struct {
	FRefIdToPointer struct {
		FXlatTable       uintptr
		FStateTable      uintptr
		FNumberOfEntries uint32
	}
	FPointerToRefId struct {
		FXlatTable       uintptr
		FNumberOfBuckets uint32
		FHashMask        uint32
	}
	FNextRefId uint32
	FXlatSide  TXLAT_SIDE
}

type _FULL_PTR_XLAT_TABLES = T_FULL_PTR_XLAT_TABLES

const _XLAT_SERVER = 1
const _XLAT_CLIENT = 2

type TRPC_BUFPTR = uintptr

type RPC_BUFPTR = TRPC_BUFPTR

type TRPC_LENGTH = uint32

type RPC_LENGTH = TRPC_LENGTH

type TEXPR_EVAL = uintptr

type EXPR_EVAL = TEXPR_EVAL

type TPFORMAT_STRING = uintptr

type PFORMAT_STRING = TPFORMAT_STRING

type TARRAY_INFO = struct {
	FDimension             int32
	FBufferConformanceMark uintptr
	FBufferVarianceMark    uintptr
	FMaxCountArray         uintptr
	FOffsetArray           uintptr
	FActualCountArray      uintptr
}

type ARRAY_INFO = TARRAY_INFO

type TPARRAY_INFO = uintptr

type PARRAY_INFO = TPARRAY_INFO

type TPNDR_ASYNC_MESSAGE = uintptr

type PNDR_ASYNC_MESSAGE = TPNDR_ASYNC_MESSAGE

type TPNDR_CORRELATION_INFO = uintptr

type PNDR_CORRELATION_INFO = TPNDR_CORRELATION_INFO

type TCS_STUB_INFO = struct {
	FWireCodeset             uint32
	FDesiredReceivingCodeset uint32
	FCSArrayInfo             uintptr
}

type CS_STUB_INFO = TCS_STUB_INFO

type T_MIDL_SYNTAX_INFO = struct {
	FTransferSyntax        TRPC_SYNTAX_IDENTIFIER
	FDispatchTable         uintptr
	FProcString            TPFORMAT_STRING
	FFmtStringOffset       uintptr
	FTypeString            TPFORMAT_STRING
	FaUserMarshalQuadruple uintptr
	FpReserved1            TULONG_PTR
	FpReserved2            TULONG_PTR
}

type _MIDL_SYNTAX_INFO = T_MIDL_SYNTAX_INFO

type TMIDL_SYNTAX_INFO = struct {
	FTransferSyntax        TRPC_SYNTAX_IDENTIFIER
	FDispatchTable         uintptr
	FProcString            TPFORMAT_STRING
	FFmtStringOffset       uintptr
	FTypeString            TPFORMAT_STRING
	FaUserMarshalQuadruple uintptr
	FpReserved1            TULONG_PTR
	FpReserved2            TULONG_PTR
}

type MIDL_SYNTAX_INFO = TMIDL_SYNTAX_INFO

type TPMIDL_SYNTAX_INFO = uintptr

type PMIDL_SYNTAX_INFO = TPMIDL_SYNTAX_INFO

type TMIDL_STUB_MESSAGE = struct {
	FRpcMsg                 TPRPC_MESSAGE
	FBuffer                 uintptr
	FBufferStart            uintptr
	FBufferEnd              uintptr
	FBufferMark             uintptr
	FBufferLength           uint32
	FMemorySize             uint32
	FMemory                 uintptr
	FIsClient               uint8
	FPad                    uint8
	FuFlags2                uint16
	FReuseBuffer            int32
	FpAllocAllNodesContext  uintptr
	FpPointerQueueState     uintptr
	FIgnoreEmbeddedPointers int32
	FPointerBufferMark      uintptr
	FfBufferValid           uint8
	FuFlags                 uint8
	FUniquePtrCount         uint16
	FMaxCount               TULONG_PTR
	FOffset                 uint32
	FActualCount            uint32
	FpfnAllocate            uintptr
	FpfnFree                uintptr
	FStackTop               uintptr
	FpPresentedType         uintptr
	FpTransmitType          uintptr
	FSavedHandle            Thandle_t
	FStubDesc               uintptr
	FFullPtrXlatTables      uintptr
	FFullPtrRefId           uint32
	FPointerLength          uint32
	F__ccgo112              uint32
	FdwDestContext          uint32
	FpvDestContext          uintptr
	FSavedContextHandles    uintptr
	FParamNumber            int32
	FpRpcChannelBuffer      uintptr
	FpArrayInfo             TPARRAY_INFO
	FSizePtrCountArray      uintptr
	FSizePtrOffsetArray     uintptr
	FSizePtrLengthArray     uintptr
	FpArgQueue              uintptr
	FdwStubPhase            uint32
	FLowStackMark           uintptr
	FpAsyncMsg              TPNDR_ASYNC_MESSAGE
	FpCorrInfo              TPNDR_CORRELATION_INFO
	FpCorrMemory            uintptr
	FpMemoryList            uintptr
	FpCSInfo                uintptr
	FConformanceMark        uintptr
	FVarianceMark           uintptr
	FUnused                 TINT_PTR
	FpContext               uintptr
	FpUserMarshalList       uintptr
	FReserved51_2           TINT_PTR
	FReserved51_3           TINT_PTR
	FReserved51_4           TINT_PTR
	FReserved51_5           TINT_PTR
}

type MIDL_STUB_MESSAGE = TMIDL_STUB_MESSAGE

type TPMIDL_STUB_MESSAGE = uintptr

type PMIDL_STUB_MESSAGE = TPMIDL_STUB_MESSAGE

type TGENERIC_BINDING_ROUTINE = uintptr

type GENERIC_BINDING_ROUTINE = TGENERIC_BINDING_ROUTINE

type TGENERIC_UNBIND_ROUTINE = uintptr

type GENERIC_UNBIND_ROUTINE = TGENERIC_UNBIND_ROUTINE

type TGENERIC_BINDING_ROUTINE_PAIR = struct {
	FpfnBind   TGENERIC_BINDING_ROUTINE
	FpfnUnbind TGENERIC_UNBIND_ROUTINE
}

type GENERIC_BINDING_ROUTINE_PAIR = TGENERIC_BINDING_ROUTINE_PAIR

type T_GENERIC_BINDING_ROUTINE_PAIR = TGENERIC_BINDING_ROUTINE_PAIR

type _GENERIC_BINDING_ROUTINE_PAIR = T_GENERIC_BINDING_ROUTINE_PAIR

type TPGENERIC_BINDING_ROUTINE_PAIR = uintptr

type PGENERIC_BINDING_ROUTINE_PAIR = TPGENERIC_BINDING_ROUTINE_PAIR

type TGENERIC_BINDING_INFO = struct {
	FpObj      uintptr
	FSize      uint32
	FpfnBind   TGENERIC_BINDING_ROUTINE
	FpfnUnbind TGENERIC_UNBIND_ROUTINE
}

type GENERIC_BINDING_INFO = TGENERIC_BINDING_INFO

type t__GENERIC_BINDING_INFO = TGENERIC_BINDING_INFO

type TPGENERIC_BINDING_INFO = uintptr

type PGENERIC_BINDING_INFO = TPGENERIC_BINDING_INFO

type TXMIT_HELPER_ROUTINE = uintptr

type XMIT_HELPER_ROUTINE = TXMIT_HELPER_ROUTINE

type TXMIT_ROUTINE_QUINTUPLE = struct {
	FpfnTranslateToXmit   TXMIT_HELPER_ROUTINE
	FpfnTranslateFromXmit TXMIT_HELPER_ROUTINE
	FpfnFreeXmit          TXMIT_HELPER_ROUTINE
	FpfnFreeInst          TXMIT_HELPER_ROUTINE
}

type XMIT_ROUTINE_QUINTUPLE = TXMIT_ROUTINE_QUINTUPLE

type T_XMIT_ROUTINE_QUINTUPLE = TXMIT_ROUTINE_QUINTUPLE

type _XMIT_ROUTINE_QUINTUPLE = T_XMIT_ROUTINE_QUINTUPLE

type TPXMIT_ROUTINE_QUINTUPLE = uintptr

type PXMIT_ROUTINE_QUINTUPLE = TPXMIT_ROUTINE_QUINTUPLE

type TUSER_MARSHAL_SIZING_ROUTINE = uintptr

type USER_MARSHAL_SIZING_ROUTINE = TUSER_MARSHAL_SIZING_ROUTINE

type TUSER_MARSHAL_MARSHALLING_ROUTINE = uintptr

type USER_MARSHAL_MARSHALLING_ROUTINE = TUSER_MARSHAL_MARSHALLING_ROUTINE

type TUSER_MARSHAL_UNMARSHALLING_ROUTINE = uintptr

type USER_MARSHAL_UNMARSHALLING_ROUTINE = TUSER_MARSHAL_UNMARSHALLING_ROUTINE

type TUSER_MARSHAL_FREEING_ROUTINE = uintptr

type USER_MARSHAL_FREEING_ROUTINE = TUSER_MARSHAL_FREEING_ROUTINE

type TUSER_MARSHAL_ROUTINE_QUADRUPLE = struct {
	FpfnBufferSize TUSER_MARSHAL_SIZING_ROUTINE
	FpfnMarshall   TUSER_MARSHAL_MARSHALLING_ROUTINE
	FpfnUnmarshall TUSER_MARSHAL_UNMARSHALLING_ROUTINE
	FpfnFree       TUSER_MARSHAL_FREEING_ROUTINE
}

type USER_MARSHAL_ROUTINE_QUADRUPLE = TUSER_MARSHAL_ROUTINE_QUADRUPLE

type T_USER_MARSHAL_ROUTINE_QUADRUPLE = TUSER_MARSHAL_ROUTINE_QUADRUPLE

type _USER_MARSHAL_ROUTINE_QUADRUPLE = T_USER_MARSHAL_ROUTINE_QUADRUPLE

type TUSER_MARSHAL_CB_TYPE = int32

type USER_MARSHAL_CB_TYPE = TUSER_MARSHAL_CB_TYPE

type __USER_MARSHAL_CB_TYPE = int32

const _USER_MARSHAL_CB_BUFFER_SIZE = 0
const _USER_MARSHAL_CB_MARSHALL = 1
const _USER_MARSHAL_CB_UNMARSHALL = 2
const _USER_MARSHAL_CB_FREE = 3

type TUSER_MARSHAL_CB = struct {
	FFlags       uint32
	FpStubMsg    TPMIDL_STUB_MESSAGE
	FpReserve    TPFORMAT_STRING
	FSignature   uint32
	FCBType      TUSER_MARSHAL_CB_TYPE
	FpFormat     TPFORMAT_STRING
	FpTypeFormat TPFORMAT_STRING
}

type USER_MARSHAL_CB = TUSER_MARSHAL_CB

type T_USER_MARSHAL_CB = TUSER_MARSHAL_CB

type _USER_MARSHAL_CB = T_USER_MARSHAL_CB

type TMALLOC_FREE_STRUCT = struct {
	FpfnAllocate uintptr
	FpfnFree     uintptr
}

type MALLOC_FREE_STRUCT = TMALLOC_FREE_STRUCT

type T_MALLOC_FREE_STRUCT = TMALLOC_FREE_STRUCT

type _MALLOC_FREE_STRUCT = T_MALLOC_FREE_STRUCT

type TCOMM_FAULT_OFFSETS = struct {
	FCommOffset  int16
	FFaultOffset int16
}

type COMM_FAULT_OFFSETS = TCOMM_FAULT_OFFSETS

type T_COMM_FAULT_OFFSETS = TCOMM_FAULT_OFFSETS

type _COMM_FAULT_OFFSETS = T_COMM_FAULT_OFFSETS

type TIDL_CS_CONVERT = int32

type IDL_CS_CONVERT = TIDL_CS_CONVERT

type __IDL_CS_CONVERT = int32

const _IDL_CS_NO_CONVERT = 0
const _IDL_CS_IN_PLACE_CONVERT = 1
const _IDL_CS_NEW_BUFFER_CONVERT = 2

type TCS_TYPE_NET_SIZE_ROUTINE = uintptr

type CS_TYPE_NET_SIZE_ROUTINE = TCS_TYPE_NET_SIZE_ROUTINE

type TCS_TYPE_LOCAL_SIZE_ROUTINE = uintptr

type CS_TYPE_LOCAL_SIZE_ROUTINE = TCS_TYPE_LOCAL_SIZE_ROUTINE

type TCS_TYPE_TO_NETCS_ROUTINE = uintptr

type CS_TYPE_TO_NETCS_ROUTINE = TCS_TYPE_TO_NETCS_ROUTINE

type TCS_TYPE_FROM_NETCS_ROUTINE = uintptr

type CS_TYPE_FROM_NETCS_ROUTINE = TCS_TYPE_FROM_NETCS_ROUTINE

type TCS_TAG_GETTING_ROUTINE = uintptr

type CS_TAG_GETTING_ROUTINE = TCS_TAG_GETTING_ROUTINE

type TNDR_CS_SIZE_CONVERT_ROUTINES = struct {
	FpfnNetSize   TCS_TYPE_NET_SIZE_ROUTINE
	FpfnToNetCs   TCS_TYPE_TO_NETCS_ROUTINE
	FpfnLocalSize TCS_TYPE_LOCAL_SIZE_ROUTINE
	FpfnFromNetCs TCS_TYPE_FROM_NETCS_ROUTINE
}

type NDR_CS_SIZE_CONVERT_ROUTINES = TNDR_CS_SIZE_CONVERT_ROUTINES

type T_NDR_CS_SIZE_CONVERT_ROUTINES = TNDR_CS_SIZE_CONVERT_ROUTINES

type _NDR_CS_SIZE_CONVERT_ROUTINES = T_NDR_CS_SIZE_CONVERT_ROUTINES

type TNDR_CS_ROUTINES = struct {
	FpSizeConvertRoutines uintptr
	FpTagGettingRoutines  uintptr
}

type NDR_CS_ROUTINES = TNDR_CS_ROUTINES

type T_NDR_CS_ROUTINES = TNDR_CS_ROUTINES

type _NDR_CS_ROUTINES = T_NDR_CS_ROUTINES

type TMIDL_STUB_DESC = struct {
	FRpcInterfaceInformation uintptr
	FpfnAllocate             uintptr
	FpfnFree                 uintptr
	FIMPLICIT_HANDLE_INFO    struct {
		FpPrimitiveHandle    [0]uintptr
		FpGenericBindingInfo [0]TPGENERIC_BINDING_INFO
		FpAutoHandle         uintptr
	}
	FapfnNdrRundownRoutines      uintptr
	FaGenericBindingRoutinePairs uintptr
	FapfnExprEval                uintptr
	FaXmitQuintuple              uintptr
	FpFormatTypes                uintptr
	FfCheckBounds                int32
	FVersion                     uint32
	FpMallocFreeStruct           uintptr
	FMIDLVersion                 int32
	FCommFaultOffsets            uintptr
	FaUserMarshalQuadruple       uintptr
	FNotifyRoutineTable          uintptr
	FmFlags                      TULONG_PTR
	FCsRoutineTables             uintptr
	FReserved4                   uintptr
	FReserved5                   TULONG_PTR
}

type MIDL_STUB_DESC = TMIDL_STUB_DESC

type TPMIDL_STUB_DESC = uintptr

type PMIDL_STUB_DESC = TPMIDL_STUB_DESC

type TPMIDL_XMIT_TYPE = uintptr

type PMIDL_XMIT_TYPE = TPMIDL_XMIT_TYPE

type TMIDL_FORMAT_STRING = struct {
	FPad int16
}

type MIDL_FORMAT_STRING = TMIDL_FORMAT_STRING

type T_MIDL_FORMAT_STRING = TMIDL_FORMAT_STRING

type _MIDL_FORMAT_STRING = T_MIDL_FORMAT_STRING

type TSTUB_THUNK = uintptr

type STUB_THUNK = TSTUB_THUNK

type TSERVER_ROUTINE = uintptr

type SERVER_ROUTINE = TSERVER_ROUTINE

type TMIDL_SERVER_INFO = struct {
	FpStubDesc       TPMIDL_STUB_DESC
	FDispatchTable   uintptr
	FProcString      TPFORMAT_STRING
	FFmtStringOffset uintptr
	FThunkTable      uintptr
	FpTransferSyntax TPRPC_SYNTAX_IDENTIFIER
	FnCount          TULONG_PTR
	FpSyntaxInfo     TPMIDL_SYNTAX_INFO
}

type MIDL_SERVER_INFO = TMIDL_SERVER_INFO

type T_MIDL_SERVER_INFO_ = TMIDL_SERVER_INFO

type _MIDL_SERVER_INFO_ = T_MIDL_SERVER_INFO_

type TPMIDL_SERVER_INFO = uintptr

type PMIDL_SERVER_INFO = TPMIDL_SERVER_INFO

type TMIDL_STUBLESS_PROXY_INFO = struct {
	FpStubDesc          TPMIDL_STUB_DESC
	FProcFormatString   TPFORMAT_STRING
	FFormatStringOffset uintptr
	FpTransferSyntax    TPRPC_SYNTAX_IDENTIFIER
	FnCount             TULONG_PTR
	FpSyntaxInfo        TPMIDL_SYNTAX_INFO
}

type MIDL_STUBLESS_PROXY_INFO = TMIDL_STUBLESS_PROXY_INFO

type T_MIDL_STUBLESS_PROXY_INFO = TMIDL_STUBLESS_PROXY_INFO

type _MIDL_STUBLESS_PROXY_INFO = T_MIDL_STUBLESS_PROXY_INFO

type TPMIDL_STUBLESS_PROXY_INFO = uintptr

type PMIDL_STUBLESS_PROXY_INFO = TPMIDL_STUBLESS_PROXY_INFO

type TPARAM_OFFSETTABLE = uintptr

type PARAM_OFFSETTABLE = TPARAM_OFFSETTABLE

type TPPARAM_OFFSETTABLE = uintptr

type PPARAM_OFFSETTABLE = TPPARAM_OFFSETTABLE

type TCLIENT_CALL_RETURN = struct {
	FSimple  [0]TLONG_PTR
	FPointer uintptr
}

type CLIENT_CALL_RETURN = TCLIENT_CALL_RETURN

type T_CLIENT_CALL_RETURN = TCLIENT_CALL_RETURN

type _CLIENT_CALL_RETURN = T_CLIENT_CALL_RETURN

type TXLAT_SIDE = int32

type XLAT_SIDE = TXLAT_SIDE

type TFULL_PTR_TO_REFID_ELEMENT = struct {
	FNext    uintptr
	FPointer uintptr
	FRefId   uint32
	FState   uint8
}

type FULL_PTR_TO_REFID_ELEMENT = TFULL_PTR_TO_REFID_ELEMENT

type T_FULL_PTR_TO_REFID_ELEMENT = TFULL_PTR_TO_REFID_ELEMENT

type _FULL_PTR_TO_REFID_ELEMENT = T_FULL_PTR_TO_REFID_ELEMENT

type TPFULL_PTR_TO_REFID_ELEMENT = uintptr

type PFULL_PTR_TO_REFID_ELEMENT = TPFULL_PTR_TO_REFID_ELEMENT

type TFULL_PTR_XLAT_TABLES = struct {
	FRefIdToPointer struct {
		FXlatTable       uintptr
		FStateTable      uintptr
		FNumberOfEntries uint32
	}
	FPointerToRefId struct {
		FXlatTable       uintptr
		FNumberOfBuckets uint32
		FHashMask        uint32
	}
	FNextRefId uint32
	FXlatSide  TXLAT_SIDE
}

type FULL_PTR_XLAT_TABLES = TFULL_PTR_XLAT_TABLES

type TPFULL_PTR_XLAT_TABLES = uintptr

type PFULL_PTR_XLAT_TABLES = TPFULL_PTR_XLAT_TABLES

type TSTUB_PHASE = int32

type STUB_PHASE = TSTUB_PHASE

const _STUB_UNMARSHAL = 0
const _STUB_CALL_SERVER = 1
const _STUB_MARSHAL = 2
const _STUB_CALL_SERVER_NO_HRESULT = 3

type TPROXY_PHASE = int32

type PROXY_PHASE = TPROXY_PHASE

const _PROXY_CALCSIZE = 0
const _PROXY_GETBUFFER = 1
const _PROXY_MARSHAL = 2
const _PROXY_SENDRECEIVE = 3
const _PROXY_UNMARSHAL = 4

type TIRpcStubBuffer1 = struct {
	FlpVtbl uintptr
}

type IRpcStubBuffer1 = TIRpcStubBuffer1

type TRPC_SS_THREAD_HANDLE = uintptr

type RPC_SS_THREAD_HANDLE = TRPC_SS_THREAD_HANDLE

type TNDR_USER_MARSHAL_INFO_LEVEL1 = struct {
	FBuffer            uintptr
	FBufferSize        uint32
	FpfnAllocate       uintptr
	FpfnFree           uintptr
	FpRpcChannelBuffer uintptr
	FReserved          [5]TULONG_PTR
}

type NDR_USER_MARSHAL_INFO_LEVEL1 = TNDR_USER_MARSHAL_INFO_LEVEL1

type T_NDR_USER_MARSHAL_INFO_LEVEL1 = TNDR_USER_MARSHAL_INFO_LEVEL1

type _NDR_USER_MARSHAL_INFO_LEVEL1 = T_NDR_USER_MARSHAL_INFO_LEVEL1

type TNDR_USER_MARSHAL_INFO = struct {
	FInformationLevel uint32
	F__ccgo1_4        struct {
		FLevel1 TNDR_USER_MARSHAL_INFO_LEVEL1
	}
}

type NDR_USER_MARSHAL_INFO = TNDR_USER_MARSHAL_INFO

type T_NDR_USER_MARSHAL_INFO = TNDR_USER_MARSHAL_INFO

type _NDR_USER_MARSHAL_INFO = T_NDR_USER_MARSHAL_INFO

type TREGCLS = int32

type REGCLS = TREGCLS

type _tagREGCLS = int32

const _REGCLS_SINGLEUSE = 0
const _REGCLS_MULTIPLEUSE = 1
const _REGCLS_MULTI_SEPARATE = 2
const _REGCLS_SUSPENDED = 4
const _REGCLS_SURROGATE = 8

type TIRpcStubBuffer = struct {
	FlpVtbl uintptr
}

type IRpcStubBuffer = TIRpcStubBuffer

type TIRpcChannelBuffer = struct {
	FlpVtbl uintptr
}

type IRpcChannelBuffer = TIRpcChannelBuffer

type TCOINITBASE = int32

type COINITBASE = TCOINITBASE

type _tagCOINITBASE = int32

const _COINITBASE_MULTITHREADED = 0

type TOLECHAR = uint16

type OLECHAR = TOLECHAR

type TLPOLESTR = uintptr

type LPOLESTR = TLPOLESTR

type TLPCOLESTR = uintptr

type LPCOLESTR = TLPCOLESTR

type TDOUBLE = float64

type DOUBLE = TDOUBLE

type TCOAUTHIDENTITY = struct {
	FUser           uintptr
	FUserLength     TULONG
	FDomain         uintptr
	FDomainLength   TULONG
	FPassword       uintptr
	FPasswordLength TULONG
	FFlags          TULONG
}

type COAUTHIDENTITY = TCOAUTHIDENTITY

type T_COAUTHIDENTITY = TCOAUTHIDENTITY

type _COAUTHIDENTITY = T_COAUTHIDENTITY

type TCOAUTHINFO = struct {
	FdwAuthnSvc           TDWORD
	FdwAuthzSvc           TDWORD
	FpwszServerPrincName  TLPWSTR
	FdwAuthnLevel         TDWORD
	FdwImpersonationLevel TDWORD
	FpAuthIdentityData    uintptr
	FdwCapabilities       TDWORD
}

type COAUTHINFO = TCOAUTHINFO

type T_COAUTHINFO = TCOAUTHINFO

type _COAUTHINFO = T_COAUTHINFO

type TSCODE = int32

type SCODE = TSCODE

type TPSCODE = uintptr

type PSCODE = TPSCODE

type TMEMCTX = int32

type MEMCTX = TMEMCTX

type _tagMEMCTX = int32

const _MEMCTX_TASK = 1
const _MEMCTX_SHARED = 2
const _MEMCTX_MACSYSTEM = 3
const _MEMCTX_UNKNOWN = -1
const _MEMCTX_SAME = -2

type TCLSCTX = int32

type CLSCTX = TCLSCTX

type _tagCLSCTX = int32

const _CLSCTX_INPROC_SERVER = 1
const _CLSCTX_INPROC_HANDLER = 2
const _CLSCTX_LOCAL_SERVER = 4
const _CLSCTX_INPROC_SERVER16 = 8
const _CLSCTX_REMOTE_SERVER = 16
const _CLSCTX_INPROC_HANDLER16 = 32
const _CLSCTX_RESERVED1 = 64
const _CLSCTX_RESERVED2 = 128
const _CLSCTX_RESERVED3 = 256
const _CLSCTX_RESERVED4 = 512
const _CLSCTX_NO_CODE_DOWNLOAD = 1024
const _CLSCTX_RESERVED5 = 2048
const _CLSCTX_NO_CUSTOM_MARSHAL = 4096
const _CLSCTX_ENABLE_CODE_DOWNLOAD = 8192
const _CLSCTX_NO_FAILURE_LOG = 16384
const _CLSCTX_DISABLE_AAA = 32768
const _CLSCTX_ENABLE_AAA = 65536
const _CLSCTX_FROM_DEFAULT_CONTEXT = 131072
const _CLSCTX_ACTIVATE_32_BIT_SERVER = 262144
const _CLSCTX_ACTIVATE_64_BIT_SERVER = 524288
const _CLSCTX_ENABLE_CLOAKING = 1048576
const _CLSCTX_APPCONTAINER = 4194304
const _CLSCTX_ACTIVATE_AAA_AS_IU = 8388608
const _CLSCTX_PS_DLL = -2147483648

type TMSHLFLAGS = int32

type MSHLFLAGS = TMSHLFLAGS

type _tagMSHLFLAGS = int32

const _MSHLFLAGS_NORMAL = 0
const _MSHLFLAGS_TABLESTRONG = 1
const _MSHLFLAGS_TABLEWEAK = 2
const _MSHLFLAGS_NOPING = 4
const _MSHLFLAGS_RESERVED1 = 8
const _MSHLFLAGS_RESERVED2 = 16
const _MSHLFLAGS_RESERVED3 = 32
const _MSHLFLAGS_RESERVED4 = 64

type TMSHCTX = int32

type MSHCTX = TMSHCTX

type _tagMSHCTX = int32

const _MSHCTX_LOCAL = 0
const _MSHCTX_NOSHAREDMEM = 1
const _MSHCTX_DIFFERENTMACHINE = 2
const _MSHCTX_INPROC = 3
const _MSHCTX_CROSSCTX = 4

type TBYTE_BLOB = struct {
	FclSize TULONG
	FabData [1]Tbyte
}

type BYTE_BLOB = TBYTE_BLOB

type T_BYTE_BLOB = TBYTE_BLOB

type _BYTE_BLOB = T_BYTE_BLOB

type TUP_BYTE_BLOB = uintptr

type UP_BYTE_BLOB = TUP_BYTE_BLOB

type TWORD_BLOB = struct {
	FclSize TULONG
	FasData [1]uint16
}

type WORD_BLOB = TWORD_BLOB

type T_WORD_BLOB = TWORD_BLOB

type _WORD_BLOB = T_WORD_BLOB

type TUP_WORD_BLOB = uintptr

type UP_WORD_BLOB = TUP_WORD_BLOB

type TDWORD_BLOB = struct {
	FclSize TULONG
	FalData [1]TULONG
}

type DWORD_BLOB = TDWORD_BLOB

type T_DWORD_BLOB = TDWORD_BLOB

type _DWORD_BLOB = T_DWORD_BLOB

type TUP_DWORD_BLOB = uintptr

type UP_DWORD_BLOB = TUP_DWORD_BLOB

type TFLAGGED_BYTE_BLOB = struct {
	FfFlags TULONG
	FclSize TULONG
	FabData [1]Tbyte
}

type FLAGGED_BYTE_BLOB = TFLAGGED_BYTE_BLOB

type T_FLAGGED_BYTE_BLOB = TFLAGGED_BYTE_BLOB

type _FLAGGED_BYTE_BLOB = T_FLAGGED_BYTE_BLOB

type TUP_FLAGGED_BYTE_BLOB = uintptr

type UP_FLAGGED_BYTE_BLOB = TUP_FLAGGED_BYTE_BLOB

type TFLAGGED_WORD_BLOB = struct {
	FfFlags TULONG
	FclSize TULONG
	FasData [1]uint16
}

type FLAGGED_WORD_BLOB = TFLAGGED_WORD_BLOB

type T_FLAGGED_WORD_BLOB = TFLAGGED_WORD_BLOB

type _FLAGGED_WORD_BLOB = T_FLAGGED_WORD_BLOB

type TUP_FLAGGED_WORD_BLOB = uintptr

type UP_FLAGGED_WORD_BLOB = TUP_FLAGGED_WORD_BLOB

type TBYTE_SIZEDARR = struct {
	FclSize TULONG
	FpData  uintptr
}

type BYTE_SIZEDARR = TBYTE_SIZEDARR

type T_BYTE_SIZEDARR = TBYTE_SIZEDARR

type _BYTE_SIZEDARR = T_BYTE_SIZEDARR

type TWORD_SIZEDARR = struct {
	FclSize TULONG
	FpData  uintptr
}

type WORD_SIZEDARR = TWORD_SIZEDARR

type T_SHORT_SIZEDARR = TWORD_SIZEDARR

type _SHORT_SIZEDARR = T_SHORT_SIZEDARR

type TDWORD_SIZEDARR = struct {
	FclSize TULONG
	FpData  uintptr
}

type DWORD_SIZEDARR = TDWORD_SIZEDARR

type T_LONG_SIZEDARR = TDWORD_SIZEDARR

type _LONG_SIZEDARR = T_LONG_SIZEDARR

type THYPER_SIZEDARR = struct {
	FclSize TULONG
	FpData  uintptr
}

type HYPER_SIZEDARR = THYPER_SIZEDARR

type T_HYPER_SIZEDARR = THYPER_SIZEDARR

type _HYPER_SIZEDARR = T_HYPER_SIZEDARR

type TBLOB = struct {
	FcbSize    TULONG
	FpBlobData uintptr
}

type BLOB = TBLOB

type TtagBLOB = TBLOB

type tagBLOB = TtagBLOB

type TLPBLOB = uintptr

type LPBLOB = TLPBLOB

type TIUnknown = struct {
	FlpVtbl uintptr
}

type IUnknown = TIUnknown

type TAsyncIUnknown = struct {
	FlpVtbl uintptr
}

type AsyncIUnknown = TAsyncIUnknown

type TIClassFactory = struct {
	FlpVtbl uintptr
}

type IClassFactory = TIClassFactory

type TLPUNKNOWN = uintptr

type LPUNKNOWN = TLPUNKNOWN

type TIUnknownVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
}

type IUnknownVtbl = TIUnknownVtbl

type TIUnknown1 = struct {
	FlpVtbl uintptr
}

type IUnknown1 = TIUnknown1

type TAsyncIUnknownVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FBegin_QueryInterface  uintptr
	FFinish_QueryInterface uintptr
	FBegin_AddRef          uintptr
	FFinish_AddRef         uintptr
	FBegin_Release         uintptr
	FFinish_Release        uintptr
}

type AsyncIUnknownVtbl = TAsyncIUnknownVtbl

type TAsyncIUnknown1 = struct {
	FlpVtbl uintptr
}

type AsyncIUnknown1 = TAsyncIUnknown1

type TLPCLASSFACTORY = uintptr

type LPCLASSFACTORY = TLPCLASSFACTORY

type TIClassFactoryVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCreateInstance uintptr
	FLockServer     uintptr
}

type IClassFactoryVtbl = TIClassFactoryVtbl

type TIClassFactory1 = struct {
	FlpVtbl uintptr
}

type IClassFactory1 = TIClassFactory1

type TIMarshal = struct {
	FlpVtbl uintptr
}

type IMarshal = TIMarshal

type TINoMarshal = struct {
	FlpVtbl uintptr
}

type INoMarshal = TINoMarshal

type TIAgileObject = struct {
	FlpVtbl uintptr
}

type IAgileObject = TIAgileObject

type TIAgileReference = struct {
	FlpVtbl uintptr
}

type IAgileReference = TIAgileReference

type TIMarshal2 = struct {
	FlpVtbl uintptr
}

type IMarshal2 = TIMarshal2

type TIMalloc = struct {
	FlpVtbl uintptr
}

type IMalloc = TIMalloc

type TIStdMarshalInfo = struct {
	FlpVtbl uintptr
}

type IStdMarshalInfo = TIStdMarshalInfo

type TIExternalConnection = struct {
	FlpVtbl uintptr
}

type IExternalConnection = TIExternalConnection

type TIMultiQI = struct {
	FlpVtbl uintptr
}

type IMultiQI = TIMultiQI

type TAsyncIMultiQI = struct {
	FlpVtbl uintptr
}

type AsyncIMultiQI = TAsyncIMultiQI

type TIInternalUnknown = struct {
	FlpVtbl uintptr
}

type IInternalUnknown = TIInternalUnknown

type TIEnumUnknown = struct {
	FlpVtbl uintptr
}

type IEnumUnknown = TIEnumUnknown

type TIEnumString = struct {
	FlpVtbl uintptr
}

type IEnumString = TIEnumString

type TISequentialStream = struct {
	FlpVtbl uintptr
}

type ISequentialStream = TISequentialStream

type TIStream = struct {
	FlpVtbl uintptr
}

type IStream = TIStream

type TIRpcChannelBuffer2 = struct {
	FlpVtbl uintptr
}

type IRpcChannelBuffer2 = TIRpcChannelBuffer2

type TIAsyncRpcChannelBuffer = struct {
	FlpVtbl uintptr
}

type IAsyncRpcChannelBuffer = TIAsyncRpcChannelBuffer

type TIRpcChannelBuffer3 = struct {
	FlpVtbl uintptr
}

type IRpcChannelBuffer3 = TIRpcChannelBuffer3

type TIRpcSyntaxNegotiate = struct {
	FlpVtbl uintptr
}

type IRpcSyntaxNegotiate = TIRpcSyntaxNegotiate

type TIRpcProxyBuffer = struct {
	FlpVtbl uintptr
}

type IRpcProxyBuffer = TIRpcProxyBuffer

type TIPSFactoryBuffer = struct {
	FlpVtbl uintptr
}

type IPSFactoryBuffer = TIPSFactoryBuffer

type TIChannelHook = struct {
	FlpVtbl uintptr
}

type IChannelHook = TIChannelHook

type TIClientSecurity = struct {
	FlpVtbl uintptr
}

type IClientSecurity = TIClientSecurity

type TIServerSecurity = struct {
	FlpVtbl uintptr
}

type IServerSecurity = TIServerSecurity

type TIRpcOptions = struct {
	FlpVtbl uintptr
}

type IRpcOptions = TIRpcOptions

type TIGlobalOptions = struct {
	FlpVtbl uintptr
}

type IGlobalOptions = TIGlobalOptions

type TISurrogate = struct {
	FlpVtbl uintptr
}

type ISurrogate = TISurrogate

type TIGlobalInterfaceTable = struct {
	FlpVtbl uintptr
}

type IGlobalInterfaceTable = TIGlobalInterfaceTable

type TISynchronize = struct {
	FlpVtbl uintptr
}

type ISynchronize = TISynchronize

type TISynchronizeHandle = struct {
	FlpVtbl uintptr
}

type ISynchronizeHandle = TISynchronizeHandle

type TISynchronizeEvent = struct {
	FlpVtbl uintptr
}

type ISynchronizeEvent = TISynchronizeEvent

type TISynchronizeContainer = struct {
	FlpVtbl uintptr
}

type ISynchronizeContainer = TISynchronizeContainer

type TISynchronizeMutex = struct {
	FlpVtbl uintptr
}

type ISynchronizeMutex = TISynchronizeMutex

type TICancelMethodCalls = struct {
	FlpVtbl uintptr
}

type ICancelMethodCalls = TICancelMethodCalls

type TIAsyncManager = struct {
	FlpVtbl uintptr
}

type IAsyncManager = TIAsyncManager

type TICallFactory = struct {
	FlpVtbl uintptr
}

type ICallFactory = TICallFactory

type TIRpcHelper = struct {
	FlpVtbl uintptr
}

type IRpcHelper = TIRpcHelper

type TIReleaseMarshalBuffers = struct {
	FlpVtbl uintptr
}

type IReleaseMarshalBuffers = TIReleaseMarshalBuffers

type TIWaitMultiple = struct {
	FlpVtbl uintptr
}

type IWaitMultiple = TIWaitMultiple

type TIAddrTrackingControl = struct {
	FlpVtbl uintptr
}

type IAddrTrackingControl = TIAddrTrackingControl

type TIAddrExclusionControl = struct {
	FlpVtbl uintptr
}

type IAddrExclusionControl = TIAddrExclusionControl

type TIPipeByte = struct {
	FlpVtbl uintptr
}

type IPipeByte = TIPipeByte

type TIPipeLong = struct {
	FlpVtbl uintptr
}

type IPipeLong = TIPipeLong

type TIPipeDouble = struct {
	FlpVtbl uintptr
}

type IPipeDouble = TIPipeDouble

type TIComThreadingInfo = struct {
	FlpVtbl uintptr
}

type IComThreadingInfo = TIComThreadingInfo

type TIProcessInitControl = struct {
	FlpVtbl uintptr
}

type IProcessInitControl = TIProcessInitControl

type TIFastRundown = struct {
	FlpVtbl uintptr
}

type IFastRundown = TIFastRundown

type TIMarshalingStream = struct {
	FlpVtbl uintptr
}

type IMarshalingStream = TIMarshalingStream

type TCOSERVERINFO = struct {
	FdwReserved1 TDWORD
	FpwszName    TLPWSTR
	FpAuthInfo   uintptr
	FdwReserved2 TDWORD
}

type COSERVERINFO = TCOSERVERINFO

type T_COSERVERINFO = TCOSERVERINFO

type _COSERVERINFO = T_COSERVERINFO

type TLPMARSHAL = uintptr

type LPMARSHAL = TLPMARSHAL

type TIMarshalVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetUnmarshalClass  uintptr
	FGetMarshalSizeMax  uintptr
	FMarshalInterface   uintptr
	FUnmarshalInterface uintptr
	FReleaseMarshalData uintptr
	FDisconnectObject   uintptr
}

type IMarshalVtbl = TIMarshalVtbl

type TIMarshal1 = struct {
	FlpVtbl uintptr
}

type IMarshal1 = TIMarshal1

type TINoMarshalVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
}

type INoMarshalVtbl = TINoMarshalVtbl

type TINoMarshal1 = struct {
	FlpVtbl uintptr
}

type INoMarshal1 = TINoMarshal1

type TIAgileObjectVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
}

type IAgileObjectVtbl = TIAgileObjectVtbl

type TIAgileObject1 = struct {
	FlpVtbl uintptr
}

type IAgileObject1 = TIAgileObject1

type TIAgileReferenceVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FResolve        uintptr
}

type IAgileReferenceVtbl = TIAgileReferenceVtbl

type TIAgileReference1 = struct {
	FlpVtbl uintptr
}

type IAgileReference1 = TIAgileReference1

type TLPMARSHAL2 = uintptr

type LPMARSHAL2 = TLPMARSHAL2

type TIMarshal2Vtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetUnmarshalClass  uintptr
	FGetMarshalSizeMax  uintptr
	FMarshalInterface   uintptr
	FUnmarshalInterface uintptr
	FReleaseMarshalData uintptr
	FDisconnectObject   uintptr
}

type IMarshal2Vtbl = TIMarshal2Vtbl

type TIMarshal21 = struct {
	FlpVtbl uintptr
}

type IMarshal21 = TIMarshal21

type TLPMALLOC = uintptr

type LPMALLOC = TLPMALLOC

type TIMallocVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FAlloc          uintptr
	FRealloc        uintptr
	FFree           uintptr
	FGetSize        uintptr
	FDidAlloc       uintptr
	FHeapMinimize   uintptr
}

type IMallocVtbl = TIMallocVtbl

type TIMalloc1 = struct {
	FlpVtbl uintptr
}

type IMalloc1 = TIMalloc1

type TLPSTDMARSHALINFO = uintptr

type LPSTDMARSHALINFO = TLPSTDMARSHALINFO

type TIStdMarshalInfoVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetClassForHandler uintptr
}

type IStdMarshalInfoVtbl = TIStdMarshalInfoVtbl

type TIStdMarshalInfo1 = struct {
	FlpVtbl uintptr
}

type IStdMarshalInfo1 = TIStdMarshalInfo1

type TLPEXTERNALCONNECTION = uintptr

type LPEXTERNALCONNECTION = TLPEXTERNALCONNECTION

type TEXTCONN = int32

type EXTCONN = TEXTCONN

type _tagEXTCONN = int32

const _EXTCONN_STRONG = 1
const _EXTCONN_WEAK = 2
const _EXTCONN_CALLABLE = 4

type TIExternalConnectionVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FAddConnection     uintptr
	FReleaseConnection uintptr
}

type IExternalConnectionVtbl = TIExternalConnectionVtbl

type TIExternalConnection1 = struct {
	FlpVtbl uintptr
}

type IExternalConnection1 = TIExternalConnection1

type TLPMULTIQI = uintptr

type LPMULTIQI = TLPMULTIQI

type TMULTI_QI = struct {
	FpIID uintptr
	FpItf uintptr
	Fhr   THRESULT
}

type MULTI_QI = TMULTI_QI

type TtagMULTI_QI = TMULTI_QI

type tagMULTI_QI = TtagMULTI_QI

type TIMultiQIVtbl = struct {
	FQueryInterface          uintptr
	FAddRef                  uintptr
	FRelease                 uintptr
	FQueryMultipleInterfaces uintptr
}

type IMultiQIVtbl = TIMultiQIVtbl

type TIMultiQI1 = struct {
	FlpVtbl uintptr
}

type IMultiQI1 = TIMultiQI1

type TAsyncIMultiQIVtbl = struct {
	FQueryInterface                 uintptr
	FAddRef                         uintptr
	FRelease                        uintptr
	FBegin_QueryMultipleInterfaces  uintptr
	FFinish_QueryMultipleInterfaces uintptr
}

type AsyncIMultiQIVtbl = TAsyncIMultiQIVtbl

type TAsyncIMultiQI1 = struct {
	FlpVtbl uintptr
}

type AsyncIMultiQI1 = TAsyncIMultiQI1

type TIInternalUnknownVtbl = struct {
	FQueryInterface         uintptr
	FAddRef                 uintptr
	FRelease                uintptr
	FQueryInternalInterface uintptr
}

type IInternalUnknownVtbl = TIInternalUnknownVtbl

type TIInternalUnknown1 = struct {
	FlpVtbl uintptr
}

type IInternalUnknown1 = TIInternalUnknown1

type TLPENUMUNKNOWN = uintptr

type LPENUMUNKNOWN = TLPENUMUNKNOWN

type TIEnumUnknownVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumUnknownVtbl = TIEnumUnknownVtbl

type TIEnumUnknown1 = struct {
	FlpVtbl uintptr
}

type IEnumUnknown1 = TIEnumUnknown1

type TLPENUMSTRING = uintptr

type LPENUMSTRING = TLPENUMSTRING

type TIEnumStringVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumStringVtbl = TIEnumStringVtbl

type TIEnumString1 = struct {
	FlpVtbl uintptr
}

type IEnumString1 = TIEnumString1

type TISequentialStreamVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FRead           uintptr
	FWrite          uintptr
}

type ISequentialStreamVtbl = TISequentialStreamVtbl

type TISequentialStream1 = struct {
	FlpVtbl uintptr
}

type ISequentialStream1 = TISequentialStream1

type TLPSTREAM = uintptr

type LPSTREAM = TLPSTREAM

type TSTATSTG = struct {
	F__ccgo_align      [0]uint32
	FpwcsName          TLPOLESTR
	Ftype1             TDWORD
	FcbSize            TULARGE_INTEGER
	Fmtime             TFILETIME
	Fctime             TFILETIME
	Fatime             TFILETIME
	FgrfMode           TDWORD
	FgrfLocksSupported TDWORD
	Fclsid             TCLSID
	FgrfStateBits      TDWORD
	Freserved          TDWORD
}

type STATSTG = TSTATSTG

type TtagSTATSTG = TSTATSTG

type tagSTATSTG = TtagSTATSTG

type TSTGTY = int32

type STGTY = TSTGTY

type _tagSTGTY = int32

const _STGTY_STORAGE = 1
const _STGTY_STREAM = 2
const _STGTY_LOCKBYTES = 3
const _STGTY_PROPERTY = 4

type TSTREAM_SEEK = int32

type STREAM_SEEK = TSTREAM_SEEK

type _tagSTREAM_SEEK = int32

const _STREAM_SEEK_SET = 0
const _STREAM_SEEK_CUR = 1
const _STREAM_SEEK_END = 2

type TLOCKTYPE = int32

type LOCKTYPE = TLOCKTYPE

type _tagLOCKTYPE = int32

const _LOCK_WRITE = 1
const _LOCK_EXCLUSIVE = 2
const _LOCK_ONLYONCE = 4

type TIStreamVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FRead           uintptr
	FWrite          uintptr
	FSeek           uintptr
	FSetSize        uintptr
	FCopyTo         uintptr
	FCommit         uintptr
	FRevert         uintptr
	FLockRegion     uintptr
	FUnlockRegion   uintptr
	FStat           uintptr
	FClone          uintptr
}

type IStreamVtbl = TIStreamVtbl

type TIStream1 = struct {
	FlpVtbl uintptr
}

type IStream1 = TIStream1

type TRPCOLEDATAREP = uint32

type RPCOLEDATAREP = TRPCOLEDATAREP

type TRPCOLEMESSAGE = struct {
	Freserved1          uintptr
	FdataRepresentation TRPCOLEDATAREP
	FBuffer             uintptr
	FcbBuffer           TULONG
	FiMethod            TULONG
	Freserved2          [5]uintptr
	FrpcFlags           TULONG
}

type RPCOLEMESSAGE = TRPCOLEMESSAGE

type TtagRPCOLEMESSAGE = TRPCOLEMESSAGE

type tagRPCOLEMESSAGE = TtagRPCOLEMESSAGE

type TPRPCOLEMESSAGE = uintptr

type PRPCOLEMESSAGE = TPRPCOLEMESSAGE

type TIRpcChannelBufferVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetBuffer      uintptr
	FSendReceive    uintptr
	FFreeBuffer     uintptr
	FGetDestCtx     uintptr
	FIsConnected    uintptr
}

type IRpcChannelBufferVtbl = TIRpcChannelBufferVtbl

type TIRpcChannelBuffer1 = struct {
	FlpVtbl uintptr
}

type IRpcChannelBuffer1 = TIRpcChannelBuffer1

type TIRpcChannelBuffer2Vtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetBuffer          uintptr
	FSendReceive        uintptr
	FFreeBuffer         uintptr
	FGetDestCtx         uintptr
	FIsConnected        uintptr
	FGetProtocolVersion uintptr
}

type IRpcChannelBuffer2Vtbl = TIRpcChannelBuffer2Vtbl

type TIRpcChannelBuffer21 = struct {
	FlpVtbl uintptr
}

type IRpcChannelBuffer21 = TIRpcChannelBuffer21

type TIAsyncRpcChannelBufferVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetBuffer          uintptr
	FSendReceive        uintptr
	FFreeBuffer         uintptr
	FGetDestCtx         uintptr
	FIsConnected        uintptr
	FGetProtocolVersion uintptr
	FSend               uintptr
	FReceive            uintptr
	FGetDestCtxEx       uintptr
}

type IAsyncRpcChannelBufferVtbl = TIAsyncRpcChannelBufferVtbl

type TIAsyncRpcChannelBuffer1 = struct {
	FlpVtbl uintptr
}

type IAsyncRpcChannelBuffer1 = TIAsyncRpcChannelBuffer1

type TIRpcChannelBuffer3Vtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetBuffer          uintptr
	FSendReceive        uintptr
	FFreeBuffer         uintptr
	FGetDestCtx         uintptr
	FIsConnected        uintptr
	FGetProtocolVersion uintptr
	FSend               uintptr
	FReceive            uintptr
	FCancel             uintptr
	FGetCallContext     uintptr
	FGetDestCtxEx       uintptr
	FGetState           uintptr
	FRegisterAsync      uintptr
}

type IRpcChannelBuffer3Vtbl = TIRpcChannelBuffer3Vtbl

type TIRpcChannelBuffer31 = struct {
	FlpVtbl uintptr
}

type IRpcChannelBuffer31 = TIRpcChannelBuffer31

type TIRpcSyntaxNegotiateVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FNegotiateSyntax uintptr
}

type IRpcSyntaxNegotiateVtbl = TIRpcSyntaxNegotiateVtbl

type TIRpcSyntaxNegotiate1 = struct {
	FlpVtbl uintptr
}

type IRpcSyntaxNegotiate1 = TIRpcSyntaxNegotiate1

type TIRpcProxyBufferVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FConnect        uintptr
	FDisconnect     uintptr
}

type IRpcProxyBufferVtbl = TIRpcProxyBufferVtbl

type TIRpcProxyBuffer1 = struct {
	FlpVtbl uintptr
}

type IRpcProxyBuffer1 = TIRpcProxyBuffer1

type TIRpcStubBufferVtbl = struct {
	FQueryInterface            uintptr
	FAddRef                    uintptr
	FRelease                   uintptr
	FConnect                   uintptr
	FDisconnect                uintptr
	FInvoke                    uintptr
	FIsIIDSupported            uintptr
	FCountRefs                 uintptr
	FDebugServerQueryInterface uintptr
	FDebugServerRelease        uintptr
}

type IRpcStubBufferVtbl = TIRpcStubBufferVtbl

type TIPSFactoryBufferVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCreateProxy    uintptr
	FCreateStub     uintptr
}

type IPSFactoryBufferVtbl = TIPSFactoryBufferVtbl

type TIPSFactoryBuffer1 = struct {
	FlpVtbl uintptr
}

type IPSFactoryBuffer1 = TIPSFactoryBuffer1

type TSChannelHookCallInfo = struct {
	Fiid         TIID
	FcbSize      TDWORD
	FuCausality  TGUID
	FdwServerPid TDWORD
	FiMethod     TDWORD
	FpObject     uintptr
}

type SChannelHookCallInfo = TSChannelHookCallInfo

type TIChannelHookVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FClientGetSize    uintptr
	FClientFillBuffer uintptr
	FClientNotify     uintptr
	FServerNotify     uintptr
	FServerGetSize    uintptr
	FServerFillBuffer uintptr
}

type IChannelHookVtbl = TIChannelHookVtbl

type TIChannelHook1 = struct {
	FlpVtbl uintptr
}

type IChannelHook1 = TIChannelHook1

type TSOLE_AUTHENTICATION_SERVICE = struct {
	FdwAuthnSvc     TDWORD
	FdwAuthzSvc     TDWORD
	FpPrincipalName uintptr
	Fhr             THRESULT
}

type SOLE_AUTHENTICATION_SERVICE = TSOLE_AUTHENTICATION_SERVICE

type TtagSOLE_AUTHENTICATION_SERVICE = TSOLE_AUTHENTICATION_SERVICE

type tagSOLE_AUTHENTICATION_SERVICE = TtagSOLE_AUTHENTICATION_SERVICE

type TPSOLE_AUTHENTICATION_SERVICE = uintptr

type PSOLE_AUTHENTICATION_SERVICE = TPSOLE_AUTHENTICATION_SERVICE

type TEOLE_AUTHENTICATION_CAPABILITIES = int32

type EOLE_AUTHENTICATION_CAPABILITIES = TEOLE_AUTHENTICATION_CAPABILITIES

type _tagEOLE_AUTHENTICATION_CAPABILITIES = int32

const _EOAC_NONE = 0
const _EOAC_MUTUAL_AUTH = 1
const _EOAC_STATIC_CLOAKING = 32
const _EOAC_DYNAMIC_CLOAKING = 64
const _EOAC_ANY_AUTHORITY = 128
const _EOAC_MAKE_FULLSIC = 256
const _EOAC_DEFAULT = 2048
const _EOAC_SECURE_REFS = 2
const _EOAC_ACCESS_CONTROL = 4
const _EOAC_APPID = 8
const _EOAC_DYNAMIC = 16
const _EOAC_REQUIRE_FULLSIC = 512
const _EOAC_AUTO_IMPERSONATE = 1024
const _EOAC_NO_CUSTOM_MARSHAL = 8192
const _EOAC_DISABLE_AAA = 4096

type TSOLE_AUTHENTICATION_INFO = struct {
	FdwAuthnSvc TDWORD
	FdwAuthzSvc TDWORD
	FpAuthInfo  uintptr
}

type SOLE_AUTHENTICATION_INFO = TSOLE_AUTHENTICATION_INFO

type TtagSOLE_AUTHENTICATION_INFO = TSOLE_AUTHENTICATION_INFO

type tagSOLE_AUTHENTICATION_INFO = TtagSOLE_AUTHENTICATION_INFO

type TPSOLE_AUTHENTICATION_INFO = uintptr

type PSOLE_AUTHENTICATION_INFO = TPSOLE_AUTHENTICATION_INFO

type TSOLE_AUTHENTICATION_LIST = struct {
	FcAuthInfo TDWORD
	FaAuthInfo uintptr
}

type SOLE_AUTHENTICATION_LIST = TSOLE_AUTHENTICATION_LIST

type TtagSOLE_AUTHENTICATION_LIST = TSOLE_AUTHENTICATION_LIST

type tagSOLE_AUTHENTICATION_LIST = TtagSOLE_AUTHENTICATION_LIST

type TPSOLE_AUTHENTICATION_LIST = uintptr

type PSOLE_AUTHENTICATION_LIST = TPSOLE_AUTHENTICATION_LIST

type TIClientSecurityVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FQueryBlanket   uintptr
	FSetBlanket     uintptr
	FCopyProxy      uintptr
}

type IClientSecurityVtbl = TIClientSecurityVtbl

type TIClientSecurity1 = struct {
	FlpVtbl uintptr
}

type IClientSecurity1 = TIClientSecurity1

type TIServerSecurityVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FQueryBlanket      uintptr
	FImpersonateClient uintptr
	FRevertToSelf      uintptr
	FIsImpersonating   uintptr
}

type IServerSecurityVtbl = TIServerSecurityVtbl

type TIServerSecurity1 = struct {
	FlpVtbl uintptr
}

type IServerSecurity1 = TIServerSecurity1

type TRPCOPT_PROPERTIES = int32

type RPCOPT_PROPERTIES = TRPCOPT_PROPERTIES

type _tagRPCOPT_PROPERTIES = int32

const _COMBND_RPCTIMEOUT = 1
const _COMBND_SERVER_LOCALITY = 2
const _COMBND_RESERVED1 = 4

type TRPCOPT_SERVER_LOCALITY_VALUES = int32

type RPCOPT_SERVER_LOCALITY_VALUES = TRPCOPT_SERVER_LOCALITY_VALUES

type _tagRPCOPT_SERVER_LOCALITY_VALUES = int32

const _SERVER_LOCALITY_PROCESS_LOCAL = 0
const _SERVER_LOCALITY_MACHINE_LOCAL = 1
const _SERVER_LOCALITY_REMOTE = 2

type TIRpcOptionsVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSet            uintptr
	FQuery          uintptr
}

type IRpcOptionsVtbl = TIRpcOptionsVtbl

type TIRpcOptions1 = struct {
	FlpVtbl uintptr
}

type IRpcOptions1 = TIRpcOptions1

type TGLOBALOPT_PROPERTIES = int32

type GLOBALOPT_PROPERTIES = TGLOBALOPT_PROPERTIES

type _tagGLOBALOPT_PROPERTIES = int32

const _COMGLB_EXCEPTION_HANDLING = 1
const _COMGLB_APPID = 2
const _COMGLB_RPC_THREADPOOL_SETTING = 3
const _COMGLB_RO_SETTINGS = 4
const _COMGLB_UNMARSHALING_POLICY = 5

type TGLOBALOPT_EH_VALUES = int32

type GLOBALOPT_EH_VALUES = TGLOBALOPT_EH_VALUES

type _tagGLOBALOPT_EH_VALUES = int32

const _COMGLB_EXCEPTION_HANDLE = 0
const _COMGLB_EXCEPTION_DONOT_HANDLE_FATAL = 1
const _COMGLB_EXCEPTION_DONOT_HANDLE = 1
const _COMGLB_EXCEPTION_DONOT_HANDLE_ANY = 2

type TGLOBALOPT_RPCTP_VALUES = int32

type GLOBALOPT_RPCTP_VALUES = TGLOBALOPT_RPCTP_VALUES

type _tagGLOBALOPT_RPCTP_VALUES = int32

const _COMGLB_RPC_THREADPOOL_SETTING_DEFAULT_POOL = 0
const _COMGLB_RPC_THREADPOOL_SETTING_PRIVATE_POOL = 1

type TGLOBALOPT_RO_FLAGS = int32

type GLOBALOPT_RO_FLAGS = TGLOBALOPT_RO_FLAGS

type _tagGLOBALOPT_RO_FLAGS = int32

const _COMGLB_STA_MODALLOOP_REMOVE_TOUCH_MESSAGES = 1
const _COMGLB_STA_MODALLOOP_SHARED_QUEUE_REMOVE_INPUT_MESSAGES = 2
const _COMGLB_STA_MODALLOOP_SHARED_QUEUE_DONOT_REMOVE_INPUT_MESSAGES = 4
const _COMGLB_FAST_RUNDOWN = 8
const _COMGLB_RESERVED1 = 16
const _COMGLB_RESERVED2 = 32
const _COMGLB_RESERVED3 = 64
const _COMGLB_STA_MODALLOOP_SHARED_QUEUE_REORDER_POINTER_MESSAGES = 128

type TGLOBALOPT_UNMARSHALING_POLICY_VALUES = int32

type GLOBALOPT_UNMARSHALING_POLICY_VALUES = TGLOBALOPT_UNMARSHALING_POLICY_VALUES

type _tagGLOBALOPT_UNMARSHALING_POLICY_VALUES = int32

const _COMGLB_UNMARSHALING_POLICY_NORMAL = 0
const _COMGLB_UNMARSHALING_POLICY_STRONG = 1
const _COMGLB_UNMARSHALING_POLICY_HYBRID = 2

type TIGlobalOptionsVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSet            uintptr
	FQuery          uintptr
}

type IGlobalOptionsVtbl = TIGlobalOptionsVtbl

type TIGlobalOptions1 = struct {
	FlpVtbl uintptr
}

type IGlobalOptions1 = TIGlobalOptions1

type TLPSURROGATE = uintptr

type LPSURROGATE = TLPSURROGATE

type TISurrogateVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FLoadDllServer  uintptr
	FFreeSurrogate  uintptr
}

type ISurrogateVtbl = TISurrogateVtbl

type TISurrogate1 = struct {
	FlpVtbl uintptr
}

type ISurrogate1 = TISurrogate1

type TLPGLOBALINTERFACETABLE = uintptr

type LPGLOBALINTERFACETABLE = TLPGLOBALINTERFACETABLE

type TIGlobalInterfaceTableVtbl = struct {
	FQueryInterface            uintptr
	FAddRef                    uintptr
	FRelease                   uintptr
	FRegisterInterfaceInGlobal uintptr
	FRevokeInterfaceFromGlobal uintptr
	FGetInterfaceFromGlobal    uintptr
}

type IGlobalInterfaceTableVtbl = TIGlobalInterfaceTableVtbl

type TIGlobalInterfaceTable1 = struct {
	FlpVtbl uintptr
}

type IGlobalInterfaceTable1 = TIGlobalInterfaceTable1

type TISynchronizeVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FWait           uintptr
	FSignal         uintptr
	FReset          uintptr
}

type ISynchronizeVtbl = TISynchronizeVtbl

type TISynchronize1 = struct {
	FlpVtbl uintptr
}

type ISynchronize1 = TISynchronize1

type TISynchronizeHandleVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetHandle      uintptr
}

type ISynchronizeHandleVtbl = TISynchronizeHandleVtbl

type TISynchronizeHandle1 = struct {
	FlpVtbl uintptr
}

type ISynchronizeHandle1 = TISynchronizeHandle1

type TISynchronizeEventVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetHandle      uintptr
	FSetEventHandle uintptr
}

type ISynchronizeEventVtbl = TISynchronizeEventVtbl

type TISynchronizeEvent1 = struct {
	FlpVtbl uintptr
}

type ISynchronizeEvent1 = TISynchronizeEvent1

type TISynchronizeContainerVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FAddSynchronize uintptr
	FWaitMultiple   uintptr
}

type ISynchronizeContainerVtbl = TISynchronizeContainerVtbl

type TISynchronizeContainer1 = struct {
	FlpVtbl uintptr
}

type ISynchronizeContainer1 = TISynchronizeContainer1

type TISynchronizeMutexVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FWait           uintptr
	FSignal         uintptr
	FReset          uintptr
	FReleaseMutex   uintptr
}

type ISynchronizeMutexVtbl = TISynchronizeMutexVtbl

type TISynchronizeMutex1 = struct {
	FlpVtbl uintptr
}

type ISynchronizeMutex1 = TISynchronizeMutex1

type TLPCANCELMETHODCALLS = uintptr

type LPCANCELMETHODCALLS = TLPCANCELMETHODCALLS

type TICancelMethodCallsVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCancel         uintptr
	FTestCancel     uintptr
}

type ICancelMethodCallsVtbl = TICancelMethodCallsVtbl

type TICancelMethodCalls1 = struct {
	FlpVtbl uintptr
}

type ICancelMethodCalls1 = TICancelMethodCalls1

type TDCOM_CALL_STATE = int32

type DCOM_CALL_STATE = TDCOM_CALL_STATE

type _tagDCOM_CALL_STATE = int32

const _DCOM_NONE = 0
const _DCOM_CALL_COMPLETE = 1
const _DCOM_CALL_CANCELED = 2

type TIAsyncManagerVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCompleteCall   uintptr
	FGetCallContext uintptr
	FGetState       uintptr
}

type IAsyncManagerVtbl = TIAsyncManagerVtbl

type TIAsyncManager1 = struct {
	FlpVtbl uintptr
}

type IAsyncManager1 = TIAsyncManager1

type TICallFactoryVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCreateCall     uintptr
}

type ICallFactoryVtbl = TICallFactoryVtbl

type TICallFactory1 = struct {
	FlpVtbl uintptr
}

type ICallFactory1 = TICallFactory1

type TIRpcHelperVtbl = struct {
	FQueryInterface         uintptr
	FAddRef                 uintptr
	FRelease                uintptr
	FGetDCOMProtocolVersion uintptr
	FGetIIDFromOBJREF       uintptr
}

type IRpcHelperVtbl = TIRpcHelperVtbl

type TIRpcHelper1 = struct {
	FlpVtbl uintptr
}

type IRpcHelper1 = TIRpcHelper1

type TIReleaseMarshalBuffersVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FReleaseMarshalBuffer uintptr
}

type IReleaseMarshalBuffersVtbl = TIReleaseMarshalBuffersVtbl

type TIReleaseMarshalBuffers1 = struct {
	FlpVtbl uintptr
}

type IReleaseMarshalBuffers1 = TIReleaseMarshalBuffers1

type TIWaitMultipleVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FWaitMultiple   uintptr
	FAddSynchronize uintptr
}

type IWaitMultipleVtbl = TIWaitMultipleVtbl

type TIWaitMultiple1 = struct {
	FlpVtbl uintptr
}

type IWaitMultiple1 = TIWaitMultiple1

type TLPADDRTRACKINGCONTROL = uintptr

type LPADDRTRACKINGCONTROL = TLPADDRTRACKINGCONTROL

type TIAddrTrackingControlVtbl = struct {
	FQueryInterface                uintptr
	FAddRef                        uintptr
	FRelease                       uintptr
	FEnableCOMDynamicAddrTracking  uintptr
	FDisableCOMDynamicAddrTracking uintptr
}

type IAddrTrackingControlVtbl = TIAddrTrackingControlVtbl

type TIAddrTrackingControl1 = struct {
	FlpVtbl uintptr
}

type IAddrTrackingControl1 = TIAddrTrackingControl1

type TLPADDREXCLUSIONCONTROL = uintptr

type LPADDREXCLUSIONCONTROL = TLPADDREXCLUSIONCONTROL

type TIAddrExclusionControlVtbl = struct {
	FQueryInterface              uintptr
	FAddRef                      uintptr
	FRelease                     uintptr
	FGetCurrentAddrExclusionList uintptr
	FUpdateAddrExclusionList     uintptr
}

type IAddrExclusionControlVtbl = TIAddrExclusionControlVtbl

type TIAddrExclusionControl1 = struct {
	FlpVtbl uintptr
}

type IAddrExclusionControl1 = TIAddrExclusionControl1

type TIPipeByteVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FPull           uintptr
	FPush           uintptr
}

type IPipeByteVtbl = TIPipeByteVtbl

type TIPipeByte1 = struct {
	FlpVtbl uintptr
}

type IPipeByte1 = TIPipeByte1

type TIPipeLongVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FPull           uintptr
	FPush           uintptr
}

type IPipeLongVtbl = TIPipeLongVtbl

type TIPipeLong1 = struct {
	FlpVtbl uintptr
}

type IPipeLong1 = TIPipeLong1

type TIPipeDoubleVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FPull           uintptr
	FPush           uintptr
}

type IPipeDoubleVtbl = TIPipeDoubleVtbl

type TIPipeDouble1 = struct {
	FlpVtbl uintptr
}

type IPipeDouble1 = TIPipeDouble1

type TAPTTYPEQUALIFIER = int32

type APTTYPEQUALIFIER = TAPTTYPEQUALIFIER

type __APTTYPEQUALIFIER = int32

const _APTTYPEQUALIFIER_NONE = 0
const _APTTYPEQUALIFIER_IMPLICIT_MTA = 1
const _APTTYPEQUALIFIER_NA_ON_MTA = 2
const _APTTYPEQUALIFIER_NA_ON_STA = 3
const _APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA = 4
const _APTTYPEQUALIFIER_NA_ON_MAINSTA = 5
const _APTTYPEQUALIFIER_APPLICATION_STA = 6

type TAPTTYPE = int32

type APTTYPE = TAPTTYPE

type __APTTYPE = int32

const _APTTYPE_CURRENT = -1
const _APTTYPE_STA = 0
const _APTTYPE_MTA = 1
const _APTTYPE_NA = 2
const _APTTYPE_MAINSTA = 3

type TTHDTYPE = int32

type THDTYPE = TTHDTYPE

type __THDTYPE = int32

const _THDTYPE_BLOCKMESSAGES = 0
const _THDTYPE_PROCESSMESSAGES = 1

type TAPARTMENTID = uint32

type APARTMENTID = TAPARTMENTID

type TIComThreadingInfoVtbl = struct {
	FQueryInterface            uintptr
	FAddRef                    uintptr
	FRelease                   uintptr
	FGetCurrentApartmentType   uintptr
	FGetCurrentThreadType      uintptr
	FGetCurrentLogicalThreadId uintptr
	FSetCurrentLogicalThreadId uintptr
}

type IComThreadingInfoVtbl = TIComThreadingInfoVtbl

type TIComThreadingInfo1 = struct {
	FlpVtbl uintptr
}

type IComThreadingInfo1 = TIComThreadingInfo1

type TIProcessInitControlVtbl = struct {
	FQueryInterface          uintptr
	FAddRef                  uintptr
	FRelease                 uintptr
	FResetInitializerTimeout uintptr
}

type IProcessInitControlVtbl = TIProcessInitControlVtbl

type TIProcessInitControl1 = struct {
	FlpVtbl uintptr
}

type IProcessInitControl1 = TIProcessInitControl1

type TIFastRundownVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
}

type IFastRundownVtbl = TIFastRundownVtbl

type TIFastRundown1 = struct {
	FlpVtbl uintptr
}

type IFastRundown1 = TIFastRundown1

type TCO_MARSHALING_CONTEXT_ATTRIBUTES = int32

type CO_MARSHALING_CONTEXT_ATTRIBUTES = TCO_MARSHALING_CONTEXT_ATTRIBUTES

type _CO_MARSHALING_CONTEXT_ATTRIBUTES = int32

const _CO_MARSHALING_SOURCE_IS_APP_CONTAINER = 0

type TIMarshalingStreamVtbl = struct {
	FQueryInterface                uintptr
	FAddRef                        uintptr
	FRelease                       uintptr
	FRead                          uintptr
	FWrite                         uintptr
	FSeek                          uintptr
	FSetSize                       uintptr
	FCopyTo                        uintptr
	FCommit                        uintptr
	FRevert                        uintptr
	FLockRegion                    uintptr
	FUnlockRegion                  uintptr
	FStat                          uintptr
	FClone                         uintptr
	FGetMarshalingContextAttribute uintptr
}

type IMarshalingStreamVtbl = TIMarshalingStreamVtbl

type TIMarshalingStream1 = struct {
	FlpVtbl uintptr
}

type IMarshalingStream1 = TIMarshalingStream1

type TServerInformation = struct {
	F__ccgo_align      [0]uint32
	FdwServerPid       TDWORD
	FdwServerTid       TDWORD
	Fui64ServerAddress TUINT64
}

type ServerInformation = TServerInformation

type TtagServerInformation = TServerInformation

type tagServerInformation = TtagServerInformation

type TPServerInformation = uintptr

type PServerInformation = TPServerInformation

type TCO_MTA_USAGE_COOKIE__ = struct {
	Funused int32
}

type CO_MTA_USAGE_COOKIE__ = TCO_MTA_USAGE_COOKIE__

type TCO_MTA_USAGE_COOKIE = uintptr

type CO_MTA_USAGE_COOKIE = TCO_MTA_USAGE_COOKIE

type TSTDMSHLFLAGS = int32

type STDMSHLFLAGS = TSTDMSHLFLAGS

type _tagSTDMSHLFLAGS = int32

const _SMEXF_SERVER = 1
const _SMEXF_HANDLER = 2

type TPROPVARIANT = struct {
	F__ccgo_align [0]uint32
	F__ccgo0_0    struct {
		F__ccgo_align [0]uint32
		FdecVal       [0]TDECIMAL
		F__ccgo0_0    struct {
			F__ccgo_align [0]uint32
			Fvt           TVARTYPE
			FwReserved1   TPROPVAR_PAD1
			FwReserved2   TPROPVAR_PAD2
			FwReserved3   TPROPVAR_PAD3
			F__ccgo4_8    struct {
				F__ccgo_align     [0]uint32
				FbVal             [0]TUCHAR
				FiVal             [0]TSHORT
				FuiVal            [0]TUSHORT
				FlVal             [0]TLONG
				FulVal            [0]TULONG
				FintVal           [0]TINT
				FuintVal          [0]TUINT
				FhVal             [0]TLARGE_INTEGER
				FuhVal            [0]TULARGE_INTEGER
				FfltVal           [0]TFLOAT
				FdblVal           [0]TDOUBLE
				FboolVal          [0]TVARIANT_BOOL
				Fscode            [0]TSCODE
				FcyVal            [0]TCY
				Fdate             [0]TDATE
				Ffiletime         [0]TFILETIME
				Fpuuid            [0]uintptr
				Fpclipdata        [0]uintptr
				FbstrVal          [0]TBSTR
				FbstrblobVal      [0]TBSTRBLOB
				Fblob             [0]TBLOB
				FpszVal           [0]TLPSTR
				FpwszVal          [0]TLPWSTR
				FpunkVal          [0]uintptr
				FpdispVal         [0]uintptr
				FpStream          [0]uintptr
				FpStorage         [0]uintptr
				FpVersionedStream [0]TLPVERSIONEDSTREAM
				Fparray           [0]TLPSAFEARRAY
				Fcac              [0]TCAC
				Fcaub             [0]TCAUB
				Fcai              [0]TCAI
				Fcaui             [0]TCAUI
				Fcal              [0]TCAL
				Fcaul             [0]TCAUL
				Fcah              [0]TCAH
				Fcauh             [0]TCAUH
				Fcaflt            [0]TCAFLT
				Fcadbl            [0]TCADBL
				Fcabool           [0]TCABOOL
				Fcascode          [0]TCASCODE
				Fcacy             [0]TCACY
				Fcadate           [0]TCADATE
				Fcafiletime       [0]TCAFILETIME
				Fcauuid           [0]TCACLSID
				Fcaclipdata       [0]TCACLIPDATA
				Fcabstr           [0]TCABSTR
				Fcabstrblob       [0]TCABSTRBLOB
				Fcalpstr          [0]TCALPSTR
				Fcalpwstr         [0]TCALPWSTR
				Fcapropvar        [0]TCAPROPVARIANT
				FpcVal            [0]uintptr
				FpbVal            [0]uintptr
				FpiVal            [0]uintptr
				FpuiVal           [0]uintptr
				FplVal            [0]uintptr
				FpulVal           [0]uintptr
				FpintVal          [0]uintptr
				FpuintVal         [0]uintptr
				FpfltVal          [0]uintptr
				FpdblVal          [0]uintptr
				FpboolVal         [0]uintptr
				FpdecVal          [0]uintptr
				Fpscode           [0]uintptr
				FpcyVal           [0]uintptr
				Fpdate            [0]uintptr
				FpbstrVal         [0]uintptr
				FppunkVal         [0]uintptr
				FppdispVal        [0]uintptr
				Fpparray          [0]uintptr
				FpvarVal          [0]uintptr
				FcVal             TCHAR
				F__ccgo_pad72     [7]byte
			}
		}
	}
}

type PROPVARIANT = TPROPVARIANT

type TtagPROPVARIANT = TPROPVARIANT

type tagPROPVARIANT = TtagPROPVARIANT

type TCOWAIT_FLAGS = int32

type COWAIT_FLAGS = TCOWAIT_FLAGS

type _tagCOWAIT_FLAGS = int32

const _COWAIT_DEFAULT = 0
const _COWAIT_WAITALL = 1
const _COWAIT_ALERTABLE = 2
const _COWAIT_INPUTAVAILABLE = 4
const _COWAIT_DISPATCH_CALLS = 8
const _COWAIT_DISPATCH_WINDOW_MESSAGES = 16

type TCWMO_FLAGS = int32

type CWMO_FLAGS = TCWMO_FLAGS

type _CWMO_FLAGS = int32

const _CWMO_DEFAULT = 0
const _CWMO_DISPATCH_CALLS = 1
const _CWMO_DISPATCH_WINDOW_MESSAGES = 2

type TLPFNGETCLASSOBJECT = uintptr

type LPFNGETCLASSOBJECT = TLPFNGETCLASSOBJECT

type TLPFNCANUNLOADNOW = uintptr

type LPFNCANUNLOADNOW = TLPFNCANUNLOADNOW

type TCOINIT = int32

type COINIT = TCOINIT

type _tagCOINIT = int32

const _COINIT_APARTMENTTHREADED = 2
const _COINIT_MULTITHREADED = 0
const _COINIT_DISABLE_OLE1DDE = 4
const _COINIT_SPEED_OVER_MEMORY = 8

type TSTGFMT = uint32

type STGFMT = TSTGFMT

type TIMallocSpy = struct {
	FlpVtbl uintptr
}

type IMallocSpy = TIMallocSpy

type TIBindCtx = struct {
	FlpVtbl uintptr
}

type IBindCtx = TIBindCtx

type TIEnumMoniker = struct {
	FlpVtbl uintptr
}

type IEnumMoniker = TIEnumMoniker

type TIRunnableObject = struct {
	FlpVtbl uintptr
}

type IRunnableObject = TIRunnableObject

type TIRunningObjectTable = struct {
	FlpVtbl uintptr
}

type IRunningObjectTable = TIRunningObjectTable

type TIPersist = struct {
	FlpVtbl uintptr
}

type IPersist = TIPersist

type TIPersistStream = struct {
	FlpVtbl uintptr
}

type IPersistStream = TIPersistStream

type TIMoniker = struct {
	FlpVtbl uintptr
}

type IMoniker = TIMoniker

type TIROTData = struct {
	FlpVtbl uintptr
}

type IROTData = TIROTData

type TIEnumSTATSTG = struct {
	FlpVtbl uintptr
}

type IEnumSTATSTG = TIEnumSTATSTG

type TIStorage = struct {
	FlpVtbl uintptr
}

type IStorage = TIStorage

type TIPersistFile = struct {
	FlpVtbl uintptr
}

type IPersistFile = TIPersistFile

type TIPersistStorage = struct {
	FlpVtbl uintptr
}

type IPersistStorage = TIPersistStorage

type TILockBytes = struct {
	FlpVtbl uintptr
}

type ILockBytes = TILockBytes

type TIEnumFORMATETC = struct {
	FlpVtbl uintptr
}

type IEnumFORMATETC = TIEnumFORMATETC

type TIEnumSTATDATA = struct {
	FlpVtbl uintptr
}

type IEnumSTATDATA = TIEnumSTATDATA

type TIRootStorage = struct {
	FlpVtbl uintptr
}

type IRootStorage = TIRootStorage

type TIAdviseSink = struct {
	FlpVtbl uintptr
}

type IAdviseSink = TIAdviseSink

type TAsyncIAdviseSink = struct {
	FlpVtbl uintptr
}

type AsyncIAdviseSink = TAsyncIAdviseSink

type TIAdviseSink2 = struct {
	FlpVtbl uintptr
}

type IAdviseSink2 = TIAdviseSink2

type TAsyncIAdviseSink2 = struct {
	FlpVtbl uintptr
}

type AsyncIAdviseSink2 = TAsyncIAdviseSink2

type TIDataObject = struct {
	FlpVtbl uintptr
}

type IDataObject = TIDataObject

type TIDataAdviseHolder = struct {
	FlpVtbl uintptr
}

type IDataAdviseHolder = TIDataAdviseHolder

type TIMessageFilter = struct {
	FlpVtbl uintptr
}

type IMessageFilter = TIMessageFilter

type TIClassActivator = struct {
	FlpVtbl uintptr
}

type IClassActivator = TIClassActivator

type TIFillLockBytes = struct {
	FlpVtbl uintptr
}

type IFillLockBytes = TIFillLockBytes

type TIProgressNotify = struct {
	FlpVtbl uintptr
}

type IProgressNotify = TIProgressNotify

type TILayoutStorage = struct {
	FlpVtbl uintptr
}

type ILayoutStorage = TILayoutStorage

type TIBlockingLock = struct {
	FlpVtbl uintptr
}

type IBlockingLock = TIBlockingLock

type TITimeAndNoticeControl = struct {
	FlpVtbl uintptr
}

type ITimeAndNoticeControl = TITimeAndNoticeControl

type TIOplockStorage = struct {
	FlpVtbl uintptr
}

type IOplockStorage = TIOplockStorage

type TIDirectWriterLock = struct {
	FlpVtbl uintptr
}

type IDirectWriterLock = TIDirectWriterLock

type TIUrlMon = struct {
	FlpVtbl uintptr
}

type IUrlMon = TIUrlMon

type TIForegroundTransfer = struct {
	FlpVtbl uintptr
}

type IForegroundTransfer = TIForegroundTransfer

type TIThumbnailExtractor = struct {
	FlpVtbl uintptr
}

type IThumbnailExtractor = TIThumbnailExtractor

type TIDummyHICONIncluder = struct {
	FlpVtbl uintptr
}

type IDummyHICONIncluder = TIDummyHICONIncluder

type TIProcessLock = struct {
	FlpVtbl uintptr
}

type IProcessLock = TIProcessLock

type TISurrogateService = struct {
	FlpVtbl uintptr
}

type ISurrogateService = TISurrogateService

type TIInitializeSpy = struct {
	FlpVtbl uintptr
}

type IInitializeSpy = TIInitializeSpy

type TIApartmentShutdown = struct {
	FlpVtbl uintptr
}

type IApartmentShutdown = TIApartmentShutdown

type TRemHGLOBAL = struct {
	FfNullHGlobal TLONG
	FcbData       TULONG
	Fdata         [1]Tbyte
}

type RemHGLOBAL = TRemHGLOBAL

type TtagRemHGLOBAL = TRemHGLOBAL

type tagRemHGLOBAL = TtagRemHGLOBAL

type TRemHMETAFILEPICT = struct {
	Fmm     TLONG
	FxExt   TLONG
	FyExt   TLONG
	FcbData TULONG
	Fdata   [1]Tbyte
}

type RemHMETAFILEPICT = TRemHMETAFILEPICT

type TtagRemHMETAFILEPICT = TRemHMETAFILEPICT

type tagRemHMETAFILEPICT = TtagRemHMETAFILEPICT

type TRemHENHMETAFILE = struct {
	FcbData TULONG
	Fdata   [1]Tbyte
}

type RemHENHMETAFILE = TRemHENHMETAFILE

type TtagRemHENHMETAFILE = TRemHENHMETAFILE

type tagRemHENHMETAFILE = TtagRemHENHMETAFILE

type TRemHBITMAP = struct {
	FcbData TULONG
	Fdata   [1]Tbyte
}

type RemHBITMAP = TRemHBITMAP

type TtagRemHBITMAP = TRemHBITMAP

type tagRemHBITMAP = TtagRemHBITMAP

type TRemHPALETTE = struct {
	FcbData TULONG
	Fdata   [1]Tbyte
}

type RemHPALETTE = TRemHPALETTE

type TtagRemHPALETTE = TRemHPALETTE

type tagRemHPALETTE = TtagRemHPALETTE

type TRemHBRUSH = struct {
	FcbData TULONG
	Fdata   [1]Tbyte
}

type RemHBRUSH = TRemHBRUSH

type TtagRemBRUSH = TRemHBRUSH

type tagRemBRUSH = TtagRemBRUSH

type TDVASPECT = int32

type DVASPECT = TDVASPECT

type _tagDVASPECT = int32

const _DVASPECT_CONTENT = 1
const _DVASPECT_THUMBNAIL = 2
const _DVASPECT_ICON = 4
const _DVASPECT_DOCPRINT = 8

type TSTGC = int32

type STGC = TSTGC

type _tagSTGC = int32

const _STGC_DEFAULT = 0
const _STGC_OVERWRITE = 1
const _STGC_ONLYIFCURRENT = 2
const _STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE = 4
const _STGC_CONSOLIDATE = 8

type TSTGMOVE = int32

type STGMOVE = TSTGMOVE

type _tagSTGMOVE = int32

const _STGMOVE_MOVE = 0
const _STGMOVE_COPY = 1
const _STGMOVE_SHALLOWCOPY = 2

type TSTATFLAG = int32

type STATFLAG = TSTATFLAG

type _tagSTATFLAG = int32

const _STATFLAG_DEFAULT = 0
const _STATFLAG_NONAME = 1
const _STATFLAG_NOOPEN = 2

type THCONTEXT = uintptr

type HCONTEXT = THCONTEXT

type TuserCLIPFORMAT = struct {
	FfContext TLONG
	Fu        t__WIDL_wtypes_generated_name_00000001
}

type userCLIPFORMAT = TuserCLIPFORMAT

type T_userCLIPFORMAT = TuserCLIPFORMAT

type _userCLIPFORMAT = T_userCLIPFORMAT

type TwireCLIPFORMAT = uintptr

type wireCLIPFORMAT = TwireCLIPFORMAT

type TCLIPFORMAT = uint16

type CLIPFORMAT = TCLIPFORMAT

type TGDI_NONREMOTE = struct {
	FfContext TLONG
	Fu        t__WIDL_wtypes_generated_name_00000002
}

type GDI_NONREMOTE = TGDI_NONREMOTE

type T_GDI_NONREMOTE = TGDI_NONREMOTE

type _GDI_NONREMOTE = T_GDI_NONREMOTE

type TuserHGLOBAL = struct {
	F__ccgo_align  [0]uint32
	FfContext      TLONG
	F__ccgo_align1 [4]byte
	Fu             t__WIDL_wtypes_generated_name_00000003
}

type userHGLOBAL = TuserHGLOBAL

type T_userHGLOBAL = TuserHGLOBAL

type _userHGLOBAL = T_userHGLOBAL

type TwireHGLOBAL = uintptr

type wireHGLOBAL = TwireHGLOBAL

type TuserHMETAFILE = struct {
	F__ccgo_align  [0]uint32
	FfContext      TLONG
	F__ccgo_align1 [4]byte
	Fu             t__WIDL_wtypes_generated_name_00000004
}

type userHMETAFILE = TuserHMETAFILE

type T_userHMETAFILE = TuserHMETAFILE

type _userHMETAFILE = T_userHMETAFILE

type TremoteMETAFILEPICT = struct {
	Fmm   TLONG
	FxExt TLONG
	FyExt TLONG
	FhMF  uintptr
}

type remoteMETAFILEPICT = TremoteMETAFILEPICT

type T_remoteMETAFILEPICT = TremoteMETAFILEPICT

type _remoteMETAFILEPICT = T_remoteMETAFILEPICT

type TuserHMETAFILEPICT = struct {
	F__ccgo_align  [0]uint32
	FfContext      TLONG
	F__ccgo_align1 [4]byte
	Fu             t__WIDL_wtypes_generated_name_00000005
}

type userHMETAFILEPICT = TuserHMETAFILEPICT

type T_userHMETAFILEPICT = TuserHMETAFILEPICT

type _userHMETAFILEPICT = T_userHMETAFILEPICT

type TuserHENHMETAFILE = struct {
	F__ccgo_align  [0]uint32
	FfContext      TLONG
	F__ccgo_align1 [4]byte
	Fu             t__WIDL_wtypes_generated_name_00000006
}

type userHENHMETAFILE = TuserHENHMETAFILE

type T_userHENHMETAFILE = TuserHENHMETAFILE

type _userHENHMETAFILE = T_userHENHMETAFILE

type TuserBITMAP = struct {
	FbmType       TLONG
	FbmWidth      TLONG
	FbmHeight     TLONG
	FbmWidthBytes TLONG
	FbmPlanes     TWORD
	FbmBitsPixel  TWORD
	FcbSize       TULONG
	FpBuffer      [1]Tbyte
}

type userBITMAP = TuserBITMAP

type T_userBITMAP = TuserBITMAP

type _userBITMAP = T_userBITMAP

type TuserHBITMAP = struct {
	F__ccgo_align  [0]uint32
	FfContext      TLONG
	F__ccgo_align1 [4]byte
	Fu             t__WIDL_wtypes_generated_name_00000007
}

type userHBITMAP = TuserHBITMAP

type T_userHBITMAP = TuserHBITMAP

type _userHBITMAP = T_userHBITMAP

type TuserHPALETTE = struct {
	F__ccgo_align  [0]uint32
	FfContext      TLONG
	F__ccgo_align1 [4]byte
	Fu             t__WIDL_wtypes_generated_name_00000008
}

type userHPALETTE = TuserHPALETTE

type T_userHPALETTE = TuserHPALETTE

type _userHPALETTE = T_userHPALETTE

type TRemotableHandle = struct {
	FfContext TLONG
	Fu        t__WIDL_wtypes_generated_name_00000009
}

type RemotableHandle = TRemotableHandle

type T_RemotableHandle = TRemotableHandle

type _RemotableHandle = T_RemotableHandle

type TwireHWND = uintptr

type wireHWND = TwireHWND

type TwireHMENU = uintptr

type wireHMENU = TwireHMENU

type TwireHACCEL = uintptr

type wireHACCEL = TwireHACCEL

type TwireHBRUSH = uintptr

type wireHBRUSH = TwireHBRUSH

type TwireHFONT = uintptr

type wireHFONT = TwireHFONT

type TwireHDC = uintptr

type wireHDC = TwireHDC

type TwireHICON = uintptr

type wireHICON = TwireHICON

type TwireHRGN = uintptr

type wireHRGN = TwireHRGN

type TwireHMONITOR = uintptr

type wireHMONITOR = TwireHMONITOR

type TwireHBITMAP = uintptr

type wireHBITMAP = TwireHBITMAP

type TwireHPALETTE = uintptr

type wireHPALETTE = TwireHPALETTE

type TwireHENHMETAFILE = uintptr

type wireHENHMETAFILE = TwireHENHMETAFILE

type TwireHMETAFILE = uintptr

type wireHMETAFILE = TwireHMETAFILE

type TwireHMETAFILEPICT = uintptr

type wireHMETAFILEPICT = TwireHMETAFILEPICT

type THMETAFILEPICT = uintptr

type HMETAFILEPICT = THMETAFILEPICT

type TDATE = float64

type DATE = TDATE

type TCY = struct {
	F__ccgo_align [0]uint32
	Fint641       [0]TLONGLONG
	F__ccgo0_0    struct {
		FLo uint32
		FHi int32
	}
}

type CY = TCY

type TtagCY = TCY

type tagCY = TtagCY

type TLPCY = uintptr

type LPCY = TLPCY

type TDECIMAL = struct {
	F__ccgo_align [0]uint32
	FwReserved    TUSHORT
	F__ccgo1_2    struct {
		Fsignscale [0]TUSHORT
		F__ccgo0_0 struct {
			Fscale TBYTE
			Fsign  TBYTE
		}
	}
	FHi32      TULONG
	F__ccgo3_8 struct {
		F__ccgo_align [0]uint32
		FLo64         [0]TULONGLONG
		F__ccgo0_0    struct {
			FLo32  TULONG
			FMid32 TULONG
		}
	}
}

type DECIMAL = TDECIMAL

type TtagDEC = TDECIMAL

type tagDEC = TtagDEC

type TLPDECIMAL = uintptr

type LPDECIMAL = TLPDECIMAL

type TwireBSTR = uintptr

type wireBSTR = TwireBSTR

type TBSTR = uintptr

type BSTR = TBSTR

type TLPBSTR = uintptr

type LPBSTR = TLPBSTR

type TVARIANT_BOOL = int16

type VARIANT_BOOL = TVARIANT_BOOL

type TBSTRBLOB = struct {
	FcbSize TULONG
	FpData  uintptr
}

type BSTRBLOB = TBSTRBLOB

type TtagBSTRBLOB = TBSTRBLOB

type tagBSTRBLOB = TtagBSTRBLOB

type TLPBSTRBLOB = uintptr

type LPBSTRBLOB = TLPBSTRBLOB

type TCLIPDATA = struct {
	FcbSize    TULONG
	FulClipFmt TLONG
	FpClipData uintptr
}

type CLIPDATA = TCLIPDATA

type TtagCLIPDATA = TCLIPDATA

type tagCLIPDATA = TtagCLIPDATA

type TVARTYPE = uint16

type VARTYPE = TVARTYPE

type _VARENUM = int32

const _VT_EMPTY = 0
const _VT_NULL = 1
const _VT_I2 = 2
const _VT_I4 = 3
const _VT_R4 = 4
const _VT_R8 = 5
const _VT_CY = 6
const _VT_DATE = 7
const _VT_BSTR = 8
const _VT_DISPATCH = 9
const _VT_ERROR = 10
const _VT_BOOL = 11
const _VT_VARIANT = 12
const _VT_UNKNOWN = 13
const _VT_DECIMAL = 14
const _VT_I1 = 16
const _VT_UI1 = 17
const _VT_UI2 = 18
const _VT_UI4 = 19
const _VT_I8 = 20
const _VT_UI8 = 21
const _VT_INT = 22
const _VT_UINT = 23
const _VT_VOID = 24
const _VT_HRESULT = 25
const _VT_PTR = 26
const _VT_SAFEARRAY = 27
const _VT_CARRAY = 28
const _VT_USERDEFINED = 29
const _VT_LPSTR = 30
const _VT_LPWSTR = 31
const _VT_RECORD = 36
const _VT_INT_PTR = 37
const _VT_UINT_PTR = 38
const _VT_FILETIME = 64
const _VT_BLOB = 65
const _VT_STREAM = 66
const _VT_STORAGE = 67
const _VT_STREAMED_OBJECT = 68
const _VT_STORED_OBJECT = 69
const _VT_BLOB_OBJECT = 70
const _VT_CF = 71
const _VT_CLSID = 72
const _VT_VERSIONED_STREAM = 73
const _VT_BSTR_BLOB = 4095
const _VT_VECTOR = 4096
const _VT_ARRAY = 8192
const _VT_BYREF = 16384
const _VT_RESERVED = 32768
const _VT_ILLEGAL = 65535
const _VT_ILLEGALMASKED = 4095
const _VT_TYPEMASK = 4095

type TPROPID = uint32

type PROPID = TPROPID

type TPROPERTYKEY = struct {
	Ffmtid TGUID
	Fpid   TDWORD
}

type PROPERTYKEY = TPROPERTYKEY

type T_tagpropertykey = TPROPERTYKEY

type _tagpropertykey = T_tagpropertykey

type TCSPLATFORM = struct {
	FdwPlatformId    TDWORD
	FdwVersionHi     TDWORD
	FdwVersionLo     TDWORD
	FdwProcessorArch TDWORD
}

type CSPLATFORM = TCSPLATFORM

type TtagCSPLATFORM = TCSPLATFORM

type tagCSPLATFORM = TtagCSPLATFORM

type TQUERYCONTEXT = struct {
	FdwContext   TDWORD
	FPlatform    TCSPLATFORM
	FLocale      TLCID
	FdwVersionHi TDWORD
	FdwVersionLo TDWORD
}

type QUERYCONTEXT = TQUERYCONTEXT

type TtagQUERYCONTEXT = TQUERYCONTEXT

type tagQUERYCONTEXT = TtagQUERYCONTEXT

type TTYSPEC = int32

type TYSPEC = TTYSPEC

type _tagTYSPEC = int32

const _TYSPEC_CLSID = 0
const _TYSPEC_FILEEXT = 1
const _TYSPEC_MIMETYPE = 2
const _TYSPEC_FILENAME = 3
const _TYSPEC_PROGID = 4
const _TYSPEC_PACKAGENAME = 5
const _TYSPEC_OBJECTID = 6

type TuCLSSPEC = struct {
	Ftyspec       TDWORD
	Ftagged_union t__WIDL_wtypes_generated_name_0000000A
}

type uCLSSPEC = TuCLSSPEC

type t__WIDL_wtypes_generated_name_0000000B = TuCLSSPEC

type TLPMALLOCSPY = uintptr

type LPMALLOCSPY = TLPMALLOCSPY

type TIMallocSpyVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FPreAlloc         uintptr
	FPostAlloc        uintptr
	FPreFree          uintptr
	FPostFree         uintptr
	FPreRealloc       uintptr
	FPostRealloc      uintptr
	FPreGetSize       uintptr
	FPostGetSize      uintptr
	FPreDidAlloc      uintptr
	FPostDidAlloc     uintptr
	FPreHeapMinimize  uintptr
	FPostHeapMinimize uintptr
}

type IMallocSpyVtbl = TIMallocSpyVtbl

type TIMallocSpy1 = struct {
	FlpVtbl uintptr
}

type IMallocSpy1 = TIMallocSpy1

type TLPBC = uintptr

type LPBC = TLPBC

type TLPBINDCTX = uintptr

type LPBINDCTX = TLPBINDCTX

type TBIND_OPTS = struct {
	FcbStruct            TDWORD
	FgrfFlags            TDWORD
	FgrfMode             TDWORD
	FdwTickCountDeadline TDWORD
}

type BIND_OPTS = TBIND_OPTS

type TtagBIND_OPTS = TBIND_OPTS

type tagBIND_OPTS = TtagBIND_OPTS

type TLPBIND_OPTS = uintptr

type LPBIND_OPTS = TLPBIND_OPTS

type TBIND_OPTS2 = struct {
	FcbStruct            TDWORD
	FgrfFlags            TDWORD
	FgrfMode             TDWORD
	FdwTickCountDeadline TDWORD
	FdwTrackFlags        TDWORD
	FdwClassContext      TDWORD
	Flocale              TLCID
	FpServerInfo         uintptr
}

type BIND_OPTS2 = TBIND_OPTS2

type TtagBIND_OPTS2 = TBIND_OPTS2

type tagBIND_OPTS2 = TtagBIND_OPTS2

type TLPBIND_OPTS2 = uintptr

type LPBIND_OPTS2 = TLPBIND_OPTS2

type TBIND_OPTS3 = struct {
	FcbStruct            TDWORD
	FgrfFlags            TDWORD
	FgrfMode             TDWORD
	FdwTickCountDeadline TDWORD
	FdwTrackFlags        TDWORD
	FdwClassContext      TDWORD
	Flocale              TLCID
	FpServerInfo         uintptr
	Fhwnd                THWND
}

type BIND_OPTS3 = TBIND_OPTS3

type TtagBIND_OPTS3 = TBIND_OPTS3

type tagBIND_OPTS3 = TtagBIND_OPTS3

type TLPBIND_OPTS3 = uintptr

type LPBIND_OPTS3 = TLPBIND_OPTS3

type TBIND_FLAGS = int32

type BIND_FLAGS = TBIND_FLAGS

type _tagBIND_FLAGS = int32

const _BIND_MAYBOTHERUSER = 1
const _BIND_JUSTTESTEXISTENCE = 2

type TIBindCtxVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FRegisterObjectBound   uintptr
	FRevokeObjectBound     uintptr
	FReleaseBoundObjects   uintptr
	FSetBindOptions        uintptr
	FGetBindOptions        uintptr
	FGetRunningObjectTable uintptr
	FRegisterObjectParam   uintptr
	FGetObjectParam        uintptr
	FEnumObjectParam       uintptr
	FRevokeObjectParam     uintptr
}

type IBindCtxVtbl = TIBindCtxVtbl

type TIBindCtx1 = struct {
	FlpVtbl uintptr
}

type IBindCtx1 = TIBindCtx1

type TLPENUMMONIKER = uintptr

type LPENUMMONIKER = TLPENUMMONIKER

type TIEnumMonikerVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumMonikerVtbl = TIEnumMonikerVtbl

type TIEnumMoniker1 = struct {
	FlpVtbl uintptr
}

type IEnumMoniker1 = TIEnumMoniker1

type TLPRUNNABLEOBJECT = uintptr

type LPRUNNABLEOBJECT = TLPRUNNABLEOBJECT

type TIRunnableObjectVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetRunningClass    uintptr
	FRun                uintptr
	FIsRunning          uintptr
	FLockRunning        uintptr
	FSetContainedObject uintptr
}

type IRunnableObjectVtbl = TIRunnableObjectVtbl

type TIRunnableObject1 = struct {
	FlpVtbl uintptr
}

type IRunnableObject1 = TIRunnableObject1

type TLPRUNNINGOBJECTTABLE = uintptr

type LPRUNNINGOBJECTTABLE = TLPRUNNINGOBJECTTABLE

type TIRunningObjectTableVtbl = struct {
	FQueryInterface      uintptr
	FAddRef              uintptr
	FRelease             uintptr
	FRegister            uintptr
	FRevoke              uintptr
	FIsRunning           uintptr
	FGetObjectA          uintptr
	FNoteChangeTime      uintptr
	FGetTimeOfLastChange uintptr
	FEnumRunning         uintptr
}

type IRunningObjectTableVtbl = TIRunningObjectTableVtbl

type TIRunningObjectTable1 = struct {
	FlpVtbl uintptr
}

type IRunningObjectTable1 = TIRunningObjectTable1

type TLPPERSIST = uintptr

type LPPERSIST = TLPPERSIST

type TIPersistVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetClassID     uintptr
}

type IPersistVtbl = TIPersistVtbl

type TIPersist1 = struct {
	FlpVtbl uintptr
}

type IPersist1 = TIPersist1

type TLPPERSISTSTREAM = uintptr

type LPPERSISTSTREAM = TLPPERSISTSTREAM

type TIPersistStreamVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetClassID     uintptr
	FIsDirty        uintptr
	FLoad           uintptr
	FSave           uintptr
	FGetSizeMax     uintptr
}

type IPersistStreamVtbl = TIPersistStreamVtbl

type TIPersistStream1 = struct {
	FlpVtbl uintptr
}

type IPersistStream1 = TIPersistStream1

type TLPMONIKER = uintptr

type LPMONIKER = TLPMONIKER

type TMKSYS = int32

type MKSYS = TMKSYS

type _tagMKSYS = int32

const _MKSYS_NONE = 0
const _MKSYS_GENERICCOMPOSITE = 1
const _MKSYS_FILEMONIKER = 2
const _MKSYS_ANTIMONIKER = 3
const _MKSYS_ITEMMONIKER = 4
const _MKSYS_POINTERMONIKER = 5
const _MKSYS_CLASSMONIKER = 7
const _MKSYS_OBJREFMONIKER = 8
const _MKSYS_SESSIONMONIKER = 9
const _MKSYS_LUAMONIKER = 10

type TMKRREDUCE = int32

type MKRREDUCE = TMKRREDUCE

type _tagMKREDUCE = int32

const _MKRREDUCE_ONE = 196608
const _MKRREDUCE_TOUSER = 131072
const _MKRREDUCE_THROUGHUSER = 65536
const _MKRREDUCE_ALL = 0

type TIMonikerVtbl = struct {
	FQueryInterface      uintptr
	FAddRef              uintptr
	FRelease             uintptr
	FGetClassID          uintptr
	FIsDirty             uintptr
	FLoad                uintptr
	FSave                uintptr
	FGetSizeMax          uintptr
	FBindToObject        uintptr
	FBindToStorage       uintptr
	FReduce              uintptr
	FComposeWith         uintptr
	FEnum                uintptr
	FIsEqual             uintptr
	FHash                uintptr
	FIsRunning           uintptr
	FGetTimeOfLastChange uintptr
	FInverse             uintptr
	FCommonPrefixWith    uintptr
	FRelativePathTo      uintptr
	FGetDisplayName      uintptr
	FParseDisplayName    uintptr
	FIsSystemMoniker     uintptr
}

type IMonikerVtbl = TIMonikerVtbl

type TIMoniker1 = struct {
	FlpVtbl uintptr
}

type IMoniker1 = TIMoniker1

type TIROTDataVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FGetComparisonData uintptr
}

type IROTDataVtbl = TIROTDataVtbl

type TIROTData1 = struct {
	FlpVtbl uintptr
}

type IROTData1 = TIROTData1

type TLPENUMSTATSTG = uintptr

type LPENUMSTATSTG = TLPENUMSTATSTG

type TIEnumSTATSTGVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumSTATSTGVtbl = TIEnumSTATSTGVtbl

type TIEnumSTATSTG1 = struct {
	FlpVtbl uintptr
}

type IEnumSTATSTG1 = TIEnumSTATSTG1

type TLPSTORAGE = uintptr

type LPSTORAGE = TLPSTORAGE

type TRemSNB = struct {
	FulCntStr  TULONG
	FulCntChar TULONG
	FrgString  [1]TOLECHAR
}

type RemSNB = TRemSNB

type TtagRemSNB = TRemSNB

type tagRemSNB = TtagRemSNB

type TwireSNB = uintptr

type wireSNB = TwireSNB

type TSNB = uintptr

type SNB = TSNB

type TIStorageVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FCreateStream    uintptr
	FOpenStream      uintptr
	FCreateStorage   uintptr
	FOpenStorage     uintptr
	FCopyTo          uintptr
	FMoveElementTo   uintptr
	FCommit          uintptr
	FRevert          uintptr
	FEnumElements    uintptr
	FDestroyElement  uintptr
	FRenameElement   uintptr
	FSetElementTimes uintptr
	FSetClass        uintptr
	FSetStateBits    uintptr
	FStat            uintptr
}

type IStorageVtbl = TIStorageVtbl

type TIStorage1 = struct {
	FlpVtbl uintptr
}

type IStorage1 = TIStorage1

type TLPPERSISTFILE = uintptr

type LPPERSISTFILE = TLPPERSISTFILE

type TIPersistFileVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetClassID     uintptr
	FIsDirty        uintptr
	FLoad           uintptr
	FSave           uintptr
	FSaveCompleted  uintptr
	FGetCurFile     uintptr
}

type IPersistFileVtbl = TIPersistFileVtbl

type TIPersistFile1 = struct {
	FlpVtbl uintptr
}

type IPersistFile1 = TIPersistFile1

type TLPPERSISTSTORAGE = uintptr

type LPPERSISTSTORAGE = TLPPERSISTSTORAGE

type TIPersistStorageVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FGetClassID      uintptr
	FIsDirty         uintptr
	FInitNew         uintptr
	FLoad            uintptr
	FSave            uintptr
	FSaveCompleted   uintptr
	FHandsOffStorage uintptr
}

type IPersistStorageVtbl = TIPersistStorageVtbl

type TIPersistStorage1 = struct {
	FlpVtbl uintptr
}

type IPersistStorage1 = TIPersistStorage1

type TLPLOCKBYTES = uintptr

type LPLOCKBYTES = TLPLOCKBYTES

type TILockBytesVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FReadAt         uintptr
	FWriteAt        uintptr
	FFlush          uintptr
	FSetSize        uintptr
	FLockRegion     uintptr
	FUnlockRegion   uintptr
	FStat           uintptr
}

type ILockBytesVtbl = TILockBytesVtbl

type TILockBytes1 = struct {
	FlpVtbl uintptr
}

type ILockBytes1 = TILockBytes1

type TLPENUMFORMATETC = uintptr

type LPENUMFORMATETC = TLPENUMFORMATETC

type TDVTARGETDEVICE = struct {
	FtdSize             TDWORD
	FtdDriverNameOffset TWORD
	FtdDeviceNameOffset TWORD
	FtdPortNameOffset   TWORD
	FtdExtDevmodeOffset TWORD
	FtdData             [1]TBYTE
}

type DVTARGETDEVICE = TDVTARGETDEVICE

type TtagDVTARGETDEVICE = TDVTARGETDEVICE

type tagDVTARGETDEVICE = TtagDVTARGETDEVICE

type TLPCLIPFORMAT = uintptr

type LPCLIPFORMAT = TLPCLIPFORMAT

type TFORMATETC = struct {
	FcfFormat TCLIPFORMAT
	Fptd      uintptr
	FdwAspect TDWORD
	Flindex   TLONG
	Ftymed    TDWORD
}

type FORMATETC = TFORMATETC

type TtagFORMATETC = TFORMATETC

type tagFORMATETC = TtagFORMATETC

type TLPFORMATETC = uintptr

type LPFORMATETC = TLPFORMATETC

type TIEnumFORMATETCVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumFORMATETCVtbl = TIEnumFORMATETCVtbl

type TIEnumFORMATETC1 = struct {
	FlpVtbl uintptr
}

type IEnumFORMATETC1 = TIEnumFORMATETC1

type TLPENUMSTATDATA = uintptr

type LPENUMSTATDATA = TLPENUMSTATDATA

type TADVF = int32

type ADVF = TADVF

type _tagADVF = int32

const _ADVF_NODATA = 1
const _ADVF_PRIMEFIRST = 2
const _ADVF_ONLYONCE = 4
const _ADVF_DATAONSTOP = 64
const _ADVFCACHE_NOHANDLER = 8
const _ADVFCACHE_FORCEBUILTIN = 16
const _ADVFCACHE_ONSAVE = 32

type TSTATDATA = struct {
	Fformatetc    TFORMATETC
	Fadvf         TDWORD
	FpAdvSink     uintptr
	FdwConnection TDWORD
}

type STATDATA = TSTATDATA

type TtagSTATDATA = TSTATDATA

type tagSTATDATA = TtagSTATDATA

type TLPSTATDATA = uintptr

type LPSTATDATA = TLPSTATDATA

type TIEnumSTATDATAVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumSTATDATAVtbl = TIEnumSTATDATAVtbl

type TIEnumSTATDATA1 = struct {
	FlpVtbl uintptr
}

type IEnumSTATDATA1 = TIEnumSTATDATA1

type TLPROOTSTORAGE = uintptr

type LPROOTSTORAGE = TLPROOTSTORAGE

type TIRootStorageVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSwitchToFile   uintptr
}

type IRootStorageVtbl = TIRootStorageVtbl

type TIRootStorage1 = struct {
	FlpVtbl uintptr
}

type IRootStorage1 = TIRootStorage1

type TLPADVISESINK = uintptr

type LPADVISESINK = TLPADVISESINK

type TTYMED = int32

type TYMED = TTYMED

type _tagTYMED = int32

const _TYMED_HGLOBAL = 1
const _TYMED_FILE = 2
const _TYMED_ISTREAM = 4
const _TYMED_ISTORAGE = 8
const _TYMED_GDI = 16
const _TYMED_MFPICT = 32
const _TYMED_ENHMF = 64
const _TYMED_NULL = 0

type TRemSTGMEDIUM = struct {
	Ftymed          TDWORD
	FdwHandleType   TDWORD
	FpData          TULONG
	FpUnkForRelease TULONG
	FcbData         TULONG
	Fdata           [1]Tbyte
}

type RemSTGMEDIUM = TRemSTGMEDIUM

type TtagRemSTGMEDIUM = TRemSTGMEDIUM

type tagRemSTGMEDIUM = TtagRemSTGMEDIUM

type TuSTGMEDIUM = struct {
	Ftymed     TDWORD
	F__ccgo1_4 struct {
		FhMetaFilePict [0]THMETAFILEPICT
		FhEnhMetaFile  [0]THENHMETAFILE
		FhGlobal       [0]THGLOBAL
		FlpszFileName  [0]TLPOLESTR
		Fpstm          [0]uintptr
		Fpstg          [0]uintptr
		FhBitmap       THBITMAP
	}
	FpUnkForRelease uintptr
}

type uSTGMEDIUM = TuSTGMEDIUM

type TtagSTGMEDIUM = TuSTGMEDIUM

type tagSTGMEDIUM = TtagSTGMEDIUM

type TGDI_OBJECT = struct {
	FObjectType TDWORD
	Fu          t__WIDL_objidl_generated_name_0000000C
}

type GDI_OBJECT = TGDI_OBJECT

type T_GDI_OBJECT = TGDI_OBJECT

type _GDI_OBJECT = T_GDI_OBJECT

type TuserSTGMEDIUM = struct {
	F__ccgo0_0      T_STGMEDIUM_UNION
	FpUnkForRelease uintptr
}

type userSTGMEDIUM = TuserSTGMEDIUM

type T_userSTGMEDIUM = TuserSTGMEDIUM

type _userSTGMEDIUM = T_userSTGMEDIUM

type TwireSTGMEDIUM = uintptr

type wireSTGMEDIUM = TwireSTGMEDIUM

type TSTGMEDIUM = struct {
	Ftymed     TDWORD
	F__ccgo1_4 struct {
		FhMetaFilePict [0]THMETAFILEPICT
		FhEnhMetaFile  [0]THENHMETAFILE
		FhGlobal       [0]THGLOBAL
		FlpszFileName  [0]TLPOLESTR
		Fpstm          [0]uintptr
		Fpstg          [0]uintptr
		FhBitmap       THBITMAP
	}
	FpUnkForRelease uintptr
}

type STGMEDIUM = TSTGMEDIUM

type TwireASYNC_STGMEDIUM = uintptr

type wireASYNC_STGMEDIUM = TwireASYNC_STGMEDIUM

type TASYNC_STGMEDIUM = struct {
	Ftymed     TDWORD
	F__ccgo1_4 struct {
		FhMetaFilePict [0]THMETAFILEPICT
		FhEnhMetaFile  [0]THENHMETAFILE
		FhGlobal       [0]THGLOBAL
		FlpszFileName  [0]TLPOLESTR
		Fpstm          [0]uintptr
		Fpstg          [0]uintptr
		FhBitmap       THBITMAP
	}
	FpUnkForRelease uintptr
}

type ASYNC_STGMEDIUM = TASYNC_STGMEDIUM

type TLPSTGMEDIUM = uintptr

type LPSTGMEDIUM = TLPSTGMEDIUM

type TuserFLAG_STGMEDIUM = struct {
	FContextFlags   TLONG
	FfPassOwnership TLONG
	FStgmed         TuserSTGMEDIUM
}

type userFLAG_STGMEDIUM = TuserFLAG_STGMEDIUM

type T_userFLAG_STGMEDIUM = TuserFLAG_STGMEDIUM

type _userFLAG_STGMEDIUM = T_userFLAG_STGMEDIUM

type TwireFLAG_STGMEDIUM = uintptr

type wireFLAG_STGMEDIUM = TwireFLAG_STGMEDIUM

type TFLAG_STGMEDIUM = struct {
	FContextFlags   TLONG
	FfPassOwnership TLONG
	FStgmed         TSTGMEDIUM
}

type FLAG_STGMEDIUM = TFLAG_STGMEDIUM

type T_FLAG_STGMEDIUM = TFLAG_STGMEDIUM

type _FLAG_STGMEDIUM = T_FLAG_STGMEDIUM

type TIAdviseSinkVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FOnDataChange   uintptr
	FOnViewChange   uintptr
	FOnRename       uintptr
	FOnSave         uintptr
	FOnClose        uintptr
}

type IAdviseSinkVtbl = TIAdviseSinkVtbl

type TIAdviseSink1 = struct {
	FlpVtbl uintptr
}

type IAdviseSink1 = TIAdviseSink1

type TAsyncIAdviseSinkVtbl = struct {
	FQueryInterface      uintptr
	FAddRef              uintptr
	FRelease             uintptr
	FBegin_OnDataChange  uintptr
	FFinish_OnDataChange uintptr
	FBegin_OnViewChange  uintptr
	FFinish_OnViewChange uintptr
	FBegin_OnRename      uintptr
	FFinish_OnRename     uintptr
	FBegin_OnSave        uintptr
	FFinish_OnSave       uintptr
	FBegin_OnClose       uintptr
	FFinish_OnClose      uintptr
}

type AsyncIAdviseSinkVtbl = TAsyncIAdviseSinkVtbl

type TAsyncIAdviseSink1 = struct {
	FlpVtbl uintptr
}

type AsyncIAdviseSink1 = TAsyncIAdviseSink1

type TLPADVISESINK2 = uintptr

type LPADVISESINK2 = TLPADVISESINK2

type TIAdviseSink2Vtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FOnDataChange    uintptr
	FOnViewChange    uintptr
	FOnRename        uintptr
	FOnSave          uintptr
	FOnClose         uintptr
	FOnLinkSrcChange uintptr
}

type IAdviseSink2Vtbl = TIAdviseSink2Vtbl

type TIAdviseSink21 = struct {
	FlpVtbl uintptr
}

type IAdviseSink21 = TIAdviseSink21

type TAsyncIAdviseSink2Vtbl = struct {
	FQueryInterface         uintptr
	FAddRef                 uintptr
	FRelease                uintptr
	FBegin_OnDataChange     uintptr
	FFinish_OnDataChange    uintptr
	FBegin_OnViewChange     uintptr
	FFinish_OnViewChange    uintptr
	FBegin_OnRename         uintptr
	FFinish_OnRename        uintptr
	FBegin_OnSave           uintptr
	FFinish_OnSave          uintptr
	FBegin_OnClose          uintptr
	FFinish_OnClose         uintptr
	FBegin_OnLinkSrcChange  uintptr
	FFinish_OnLinkSrcChange uintptr
}

type AsyncIAdviseSink2Vtbl = TAsyncIAdviseSink2Vtbl

type TAsyncIAdviseSink21 = struct {
	FlpVtbl uintptr
}

type AsyncIAdviseSink21 = TAsyncIAdviseSink21

type TLPDATAOBJECT = uintptr

type LPDATAOBJECT = TLPDATAOBJECT

type TDATADIR = int32

type DATADIR = TDATADIR

type _tagDATADIR = int32

const _DATADIR_GET = 1
const _DATADIR_SET = 2

type TIDataObjectVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetData               uintptr
	FGetDataHere           uintptr
	FQueryGetData          uintptr
	FGetCanonicalFormatEtc uintptr
	FSetData               uintptr
	FEnumFormatEtc         uintptr
	FDAdvise               uintptr
	FDUnadvise             uintptr
	FEnumDAdvise           uintptr
}

type IDataObjectVtbl = TIDataObjectVtbl

type TIDataObject1 = struct {
	FlpVtbl uintptr
}

type IDataObject1 = TIDataObject1

type TLPDATAADVISEHOLDER = uintptr

type LPDATAADVISEHOLDER = TLPDATAADVISEHOLDER

type TIDataAdviseHolderVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FAdvise           uintptr
	FUnadvise         uintptr
	FEnumAdvise       uintptr
	FSendOnDataChange uintptr
}

type IDataAdviseHolderVtbl = TIDataAdviseHolderVtbl

type TIDataAdviseHolder1 = struct {
	FlpVtbl uintptr
}

type IDataAdviseHolder1 = TIDataAdviseHolder1

type TLPMESSAGEFILTER = uintptr

type LPMESSAGEFILTER = TLPMESSAGEFILTER

type TCALLTYPE = int32

type CALLTYPE = TCALLTYPE

type _tagCALLTYPE = int32

const _CALLTYPE_TOPLEVEL = 1
const _CALLTYPE_NESTED = 2
const _CALLTYPE_ASYNC = 3
const _CALLTYPE_TOPLEVEL_CALLPENDING = 4
const _CALLTYPE_ASYNC_CALLPENDING = 5

type TSERVERCALL = int32

type SERVERCALL = TSERVERCALL

type _tagSERVERCALL = int32

const _SERVERCALL_ISHANDLED = 0
const _SERVERCALL_REJECTED = 1
const _SERVERCALL_RETRYLATER = 2

type TPENDINGTYPE = int32

type PENDINGTYPE = TPENDINGTYPE

type _tagPENDINGTYPE = int32

const _PENDINGTYPE_TOPLEVEL = 1
const _PENDINGTYPE_NESTED = 2

type TPENDINGMSG = int32

type PENDINGMSG = TPENDINGMSG

type _tagPENDINGMSG = int32

const _PENDINGMSG_CANCELCALL = 0
const _PENDINGMSG_WAITNOPROCESS = 1
const _PENDINGMSG_WAITDEFPROCESS = 2

type TINTERFACEINFO = struct {
	FpUnk    uintptr
	Fiid     TIID
	FwMethod TWORD
}

type INTERFACEINFO = TINTERFACEINFO

type TtagINTERFACEINFO = TINTERFACEINFO

type tagINTERFACEINFO = TtagINTERFACEINFO

type TLPINTERFACEINFO = uintptr

type LPINTERFACEINFO = TLPINTERFACEINFO

type TIMessageFilterVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FHandleInComingCall uintptr
	FRetryRejectedCall  uintptr
	FMessagePending     uintptr
}

type IMessageFilterVtbl = TIMessageFilterVtbl

type TIMessageFilter1 = struct {
	FlpVtbl uintptr
}

type IMessageFilter1 = TIMessageFilter1

type TIClassActivatorVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetClassObject uintptr
}

type IClassActivatorVtbl = TIClassActivatorVtbl

type TIClassActivator1 = struct {
	FlpVtbl uintptr
}

type IClassActivator1 = TIClassActivator1

type TIFillLockBytesVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FFillAppend     uintptr
	FFillAt         uintptr
	FSetFillSize    uintptr
	FTerminate      uintptr
}

type IFillLockBytesVtbl = TIFillLockBytesVtbl

type TIFillLockBytes1 = struct {
	FlpVtbl uintptr
}

type IFillLockBytes1 = TIFillLockBytes1

type TIProgressNotifyVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FOnProgress     uintptr
}

type IProgressNotifyVtbl = TIProgressNotifyVtbl

type TIProgressNotify1 = struct {
	FlpVtbl uintptr
}

type IProgressNotify1 = TIProgressNotify1

type TStorageLayout = struct {
	F__ccgo_align    [0]uint32
	FLayoutType      TDWORD
	FpwcsElementName uintptr
	FcOffset         TLARGE_INTEGER
	FcBytes          TLARGE_INTEGER
}

type StorageLayout = TStorageLayout

type TtagStorageLayout = TStorageLayout

type tagStorageLayout = TtagStorageLayout

type TILayoutStorageVtbl = struct {
	FQueryInterface              uintptr
	FAddRef                      uintptr
	FRelease                     uintptr
	FLayoutScript                uintptr
	FBeginMonitor                uintptr
	FEndMonitor                  uintptr
	FReLayoutDocfile             uintptr
	FReLayoutDocfileOnILockBytes uintptr
}

type ILayoutStorageVtbl = TILayoutStorageVtbl

type TILayoutStorage1 = struct {
	FlpVtbl uintptr
}

type ILayoutStorage1 = TILayoutStorage1

type TIBlockingLockVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FLock           uintptr
	FUnlock         uintptr
}

type IBlockingLockVtbl = TIBlockingLockVtbl

type TIBlockingLock1 = struct {
	FlpVtbl uintptr
}

type IBlockingLock1 = TIBlockingLock1

type TITimeAndNoticeControlVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FSuppressChanges uintptr
}

type ITimeAndNoticeControlVtbl = TITimeAndNoticeControlVtbl

type TITimeAndNoticeControl1 = struct {
	FlpVtbl uintptr
}

type ITimeAndNoticeControl1 = TITimeAndNoticeControl1

type TIOplockStorageVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FCreateStorageEx uintptr
	FOpenStorageEx   uintptr
}

type IOplockStorageVtbl = TIOplockStorageVtbl

type TIOplockStorage1 = struct {
	FlpVtbl uintptr
}

type IOplockStorage1 = TIOplockStorage1

type TIDirectWriterLockVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FWaitForWriteAccess uintptr
	FReleaseWriteAccess uintptr
	FHaveWriteAccess    uintptr
}

type IDirectWriterLockVtbl = TIDirectWriterLockVtbl

type TIDirectWriterLock1 = struct {
	FlpVtbl uintptr
}

type IDirectWriterLock1 = TIDirectWriterLock1

type TIUrlMonVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FAsyncGetClassBits uintptr
}

type IUrlMonVtbl = TIUrlMonVtbl

type TIUrlMon1 = struct {
	FlpVtbl uintptr
}

type IUrlMon1 = TIUrlMon1

type TIForegroundTransferVtbl = struct {
	FQueryInterface          uintptr
	FAddRef                  uintptr
	FRelease                 uintptr
	FAllowForegroundTransfer uintptr
}

type IForegroundTransferVtbl = TIForegroundTransferVtbl

type TIForegroundTransfer1 = struct {
	FlpVtbl uintptr
}

type IForegroundTransfer1 = TIForegroundTransfer1

type TIThumbnailExtractorVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FExtractThumbnail uintptr
	FOnFileUpdated    uintptr
}

type IThumbnailExtractorVtbl = TIThumbnailExtractorVtbl

type TIThumbnailExtractor1 = struct {
	FlpVtbl uintptr
}

type IThumbnailExtractor1 = TIThumbnailExtractor1

type TIDummyHICONIncluderVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FDummy          uintptr
}

type IDummyHICONIncluderVtbl = TIDummyHICONIncluderVtbl

type TIDummyHICONIncluder1 = struct {
	FlpVtbl uintptr
}

type IDummyHICONIncluder1 = TIDummyHICONIncluder1

type TApplicationType = int32

type ApplicationType = TApplicationType

type _tagApplicationType = int32

const _ServerApplication = 0
const _LibraryApplication = 1

type TShutdownType = int32

type ShutdownType = TShutdownType

type _tagShutdownType = int32

const _IdleShutdown = 0
const _ForcedShutdown = 1

type TIProcessLockVtbl = struct {
	FQueryInterface      uintptr
	FAddRef              uintptr
	FRelease             uintptr
	FAddRefOnProcess     uintptr
	FReleaseRefOnProcess uintptr
}

type IProcessLockVtbl = TIProcessLockVtbl

type TIProcessLock1 = struct {
	FlpVtbl uintptr
}

type IProcessLock1 = TIProcessLock1

type TISurrogateServiceVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FInit              uintptr
	FApplicationLaunch uintptr
	FApplicationFree   uintptr
	FCatalogRefresh    uintptr
	FProcessShutdown   uintptr
}

type ISurrogateServiceVtbl = TISurrogateServiceVtbl

type TISurrogateService1 = struct {
	FlpVtbl uintptr
}

type ISurrogateService1 = TISurrogateService1

type TLPINITIALIZESPY = uintptr

type LPINITIALIZESPY = TLPINITIALIZESPY

type TIInitializeSpyVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FPreInitialize    uintptr
	FPostInitialize   uintptr
	FPreUninitialize  uintptr
	FPostUninitialize uintptr
}

type IInitializeSpyVtbl = TIInitializeSpyVtbl

type TIInitializeSpy1 = struct {
	FlpVtbl uintptr
}

type IInitializeSpy1 = TIInitializeSpy1

type TIApartmentShutdownVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FOnUninitialize uintptr
}

type IApartmentShutdownVtbl = TIApartmentShutdownVtbl

type TIApartmentShutdown1 = struct {
	FlpVtbl uintptr
}

type IApartmentShutdown1 = TIApartmentShutdown1

type TCOMSD = int32

type COMSD = TCOMSD

type _tagCOMSD = int32

const _SD_LAUNCHPERMISSIONS = 0
const _SD_ACCESSPERMISSIONS = 1
const _SD_LAUNCHRESTRICTIONS = 2
const _SD_ACCESSRESTRICTIONS = 3

type TSTGOPTIONS = struct {
	FusVersion        TUSHORT
	Freserved         TUSHORT
	FulSectorSize     TULONG
	FpwcsTemplateFile uintptr
}

type STGOPTIONS = TSTGOPTIONS

type TtagSTGOPTIONS = TSTGOPTIONS

type tagSTGOPTIONS = TtagSTGOPTIONS

type TIPersistMoniker = struct {
	FlpVtbl uintptr
}

type IPersistMoniker = TIPersistMoniker

type TIMonikerProp = struct {
	FlpVtbl uintptr
}

type IMonikerProp = TIMonikerProp

type TIBindProtocol = struct {
	FlpVtbl uintptr
}

type IBindProtocol = TIBindProtocol

type TIBinding = struct {
	FlpVtbl uintptr
}

type IBinding = TIBinding

type TIBindStatusCallback = struct {
	FlpVtbl uintptr
}

type IBindStatusCallback = TIBindStatusCallback

type TIBindStatusCallbackEx = struct {
	FlpVtbl uintptr
}

type IBindStatusCallbackEx = TIBindStatusCallbackEx

type TIAuthenticate = struct {
	FlpVtbl uintptr
}

type IAuthenticate = TIAuthenticate

type TIAuthenticateEx = struct {
	FlpVtbl uintptr
}

type IAuthenticateEx = TIAuthenticateEx

type TIHttpNegotiate = struct {
	FlpVtbl uintptr
}

type IHttpNegotiate = TIHttpNegotiate

type TIHttpNegotiate2 = struct {
	FlpVtbl uintptr
}

type IHttpNegotiate2 = TIHttpNegotiate2

type TIHttpNegotiate3 = struct {
	FlpVtbl uintptr
}

type IHttpNegotiate3 = TIHttpNegotiate3

type TIWinInetFileStream = struct {
	FlpVtbl uintptr
}

type IWinInetFileStream = TIWinInetFileStream

type TIWindowForBindingUI = struct {
	FlpVtbl uintptr
}

type IWindowForBindingUI = TIWindowForBindingUI

type TICodeInstall = struct {
	FlpVtbl uintptr
}

type ICodeInstall = TICodeInstall

type TIUri = struct {
	FlpVtbl uintptr
}

type IUri = TIUri

type TIUriContainer = struct {
	FlpVtbl uintptr
}

type IUriContainer = TIUriContainer

type TIUriBuilder = struct {
	FlpVtbl uintptr
}

type IUriBuilder = TIUriBuilder

type TIUriBuilderFactory = struct {
	FlpVtbl uintptr
}

type IUriBuilderFactory = TIUriBuilderFactory

type TIWinInetInfo = struct {
	FlpVtbl uintptr
}

type IWinInetInfo = TIWinInetInfo

type TIHttpSecurity = struct {
	FlpVtbl uintptr
}

type IHttpSecurity = TIHttpSecurity

type TIWinInetHttpInfo = struct {
	FlpVtbl uintptr
}

type IWinInetHttpInfo = TIWinInetHttpInfo

type TIWinInetHttpTimeouts = struct {
	FlpVtbl uintptr
}

type IWinInetHttpTimeouts = TIWinInetHttpTimeouts

type TIWinInetCacheHints = struct {
	FlpVtbl uintptr
}

type IWinInetCacheHints = TIWinInetCacheHints

type TIWinInetCacheHints2 = struct {
	FlpVtbl uintptr
}

type IWinInetCacheHints2 = TIWinInetCacheHints2

type TIBindHost = struct {
	FlpVtbl uintptr
}

type IBindHost = TIBindHost

type TIInternet = struct {
	FlpVtbl uintptr
}

type IInternet = TIInternet

type TIInternetBindInfo = struct {
	FlpVtbl uintptr
}

type IInternetBindInfo = TIInternetBindInfo

type TIInternetBindInfoEx = struct {
	FlpVtbl uintptr
}

type IInternetBindInfoEx = TIInternetBindInfoEx

type TIInternetProtocolRoot = struct {
	FlpVtbl uintptr
}

type IInternetProtocolRoot = TIInternetProtocolRoot

type TIInternetProtocol = struct {
	FlpVtbl uintptr
}

type IInternetProtocol = TIInternetProtocol

type TIInternetProtocolEx = struct {
	FlpVtbl uintptr
}

type IInternetProtocolEx = TIInternetProtocolEx

type TIInternetProtocolSink = struct {
	FlpVtbl uintptr
}

type IInternetProtocolSink = TIInternetProtocolSink

type TIInternetProtocolSinkStackable = struct {
	FlpVtbl uintptr
}

type IInternetProtocolSinkStackable = TIInternetProtocolSinkStackable

type TIInternetSession = struct {
	FlpVtbl uintptr
}

type IInternetSession = TIInternetSession

type TIInternetThreadSwitch = struct {
	FlpVtbl uintptr
}

type IInternetThreadSwitch = TIInternetThreadSwitch

type TIInternetPriority = struct {
	FlpVtbl uintptr
}

type IInternetPriority = TIInternetPriority

type TIInternetProtocolInfo = struct {
	FlpVtbl uintptr
}

type IInternetProtocolInfo = TIInternetProtocolInfo

type TIInternetSecurityMgrSite = struct {
	FlpVtbl uintptr
}

type IInternetSecurityMgrSite = TIInternetSecurityMgrSite

type TIInternetSecurityManager = struct {
	FlpVtbl uintptr
}

type IInternetSecurityManager = TIInternetSecurityManager

type TIInternetSecurityManagerEx = struct {
	FlpVtbl uintptr
}

type IInternetSecurityManagerEx = TIInternetSecurityManagerEx

type TIInternetSecurityManagerEx2 = struct {
	FlpVtbl uintptr
}

type IInternetSecurityManagerEx2 = TIInternetSecurityManagerEx2

type TIZoneIdentifier = struct {
	FlpVtbl uintptr
}

type IZoneIdentifier = TIZoneIdentifier

type TIInternetHostSecurityManager = struct {
	FlpVtbl uintptr
}

type IInternetHostSecurityManager = TIInternetHostSecurityManager

type TIInternetZoneManager = struct {
	FlpVtbl uintptr
}

type IInternetZoneManager = TIInternetZoneManager

type TIInternetZoneManagerEx = struct {
	FlpVtbl uintptr
}

type IInternetZoneManagerEx = TIInternetZoneManagerEx

type TIInternetZoneManagerEx2 = struct {
	FlpVtbl uintptr
}

type IInternetZoneManagerEx2 = TIInternetZoneManagerEx2

type TISoftDistExt = struct {
	FlpVtbl uintptr
}

type ISoftDistExt = TISoftDistExt

type TICatalogFileInfo = struct {
	FlpVtbl uintptr
}

type ICatalogFileInfo = TICatalogFileInfo

type TIDataFilter = struct {
	FlpVtbl uintptr
}

type IDataFilter = TIDataFilter

type TIEncodingFilterFactory = struct {
	FlpVtbl uintptr
}

type IEncodingFilterFactory = TIEncodingFilterFactory

type TIWrappedProtocol = struct {
	FlpVtbl uintptr
}

type IWrappedProtocol = TIWrappedProtocol

type TIGetBindHandle = struct {
	FlpVtbl uintptr
}

type IGetBindHandle = TIGetBindHandle

type TIBindCallbackRedirect = struct {
	FlpVtbl uintptr
}

type IBindCallbackRedirect = TIBindCallbackRedirect

type TIOleAdviseHolder = struct {
	FlpVtbl uintptr
}

type IOleAdviseHolder = TIOleAdviseHolder

type TIOleCache = struct {
	FlpVtbl uintptr
}

type IOleCache = TIOleCache

type TIOleCache2 = struct {
	FlpVtbl uintptr
}

type IOleCache2 = TIOleCache2

type TIOleCacheControl = struct {
	FlpVtbl uintptr
}

type IOleCacheControl = TIOleCacheControl

type TIParseDisplayName = struct {
	FlpVtbl uintptr
}

type IParseDisplayName = TIParseDisplayName

type TIOleContainer = struct {
	FlpVtbl uintptr
}

type IOleContainer = TIOleContainer

type TIOleClientSite = struct {
	FlpVtbl uintptr
}

type IOleClientSite = TIOleClientSite

type TIOleObject = struct {
	FlpVtbl uintptr
}

type IOleObject = TIOleObject

type TIOleWindow = struct {
	FlpVtbl uintptr
}

type IOleWindow = TIOleWindow

type TIOleLink = struct {
	FlpVtbl uintptr
}

type IOleLink = TIOleLink

type TIOleItemContainer = struct {
	FlpVtbl uintptr
}

type IOleItemContainer = TIOleItemContainer

type TIOleInPlaceUIWindow = struct {
	FlpVtbl uintptr
}

type IOleInPlaceUIWindow = TIOleInPlaceUIWindow

type TIOleInPlaceActiveObject = struct {
	FlpVtbl uintptr
}

type IOleInPlaceActiveObject = TIOleInPlaceActiveObject

type TIOleInPlaceFrame = struct {
	FlpVtbl uintptr
}

type IOleInPlaceFrame = TIOleInPlaceFrame

type TIOleInPlaceObject = struct {
	FlpVtbl uintptr
}

type IOleInPlaceObject = TIOleInPlaceObject

type TIOleInPlaceSite = struct {
	FlpVtbl uintptr
}

type IOleInPlaceSite = TIOleInPlaceSite

type TIContinue = struct {
	FlpVtbl uintptr
}

type IContinue = TIContinue

type TIViewObject = struct {
	FlpVtbl uintptr
}

type IViewObject = TIViewObject

type TIViewObject2 = struct {
	FlpVtbl uintptr
}

type IViewObject2 = TIViewObject2

type TIDropSource = struct {
	FlpVtbl uintptr
}

type IDropSource = TIDropSource

type TIDropTarget = struct {
	FlpVtbl uintptr
}

type IDropTarget = TIDropTarget

type TIDropSourceNotify = struct {
	FlpVtbl uintptr
}

type IDropSourceNotify = TIDropSourceNotify

type TIEnumOLEVERB = struct {
	FlpVtbl uintptr
}

type IEnumOLEVERB = TIEnumOLEVERB

type TLPOLEADVISEHOLDER = uintptr

type LPOLEADVISEHOLDER = TLPOLEADVISEHOLDER

type TIOleAdviseHolderVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FAdvise         uintptr
	FUnadvise       uintptr
	FEnumAdvise     uintptr
	FSendOnRename   uintptr
	FSendOnSave     uintptr
	FSendOnClose    uintptr
}

type IOleAdviseHolderVtbl = TIOleAdviseHolderVtbl

type TIOleAdviseHolder1 = struct {
	FlpVtbl uintptr
}

type IOleAdviseHolder1 = TIOleAdviseHolder1

type TLPOLECACHE = uintptr

type LPOLECACHE = TLPOLECACHE

type TIOleCacheVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCache          uintptr
	FUncache        uintptr
	FEnumCache      uintptr
	FInitCache      uintptr
	FSetData        uintptr
}

type IOleCacheVtbl = TIOleCacheVtbl

type TIOleCache1 = struct {
	FlpVtbl uintptr
}

type IOleCache1 = TIOleCache1

type TLPOLECACHE2 = uintptr

type LPOLECACHE2 = TLPOLECACHE2

type TDISCARDCACHE = int32

type DISCARDCACHE = TDISCARDCACHE

type _tagDISCARDCACHE = int32

const _DISCARDCACHE_SAVEIFDIRTY = 0
const _DISCARDCACHE_NOSAVE = 1

type TIOleCache2Vtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCache          uintptr
	FUncache        uintptr
	FEnumCache      uintptr
	FInitCache      uintptr
	FSetData        uintptr
	FUpdateCache    uintptr
	FDiscardCache   uintptr
}

type IOleCache2Vtbl = TIOleCache2Vtbl

type TIOleCache21 = struct {
	FlpVtbl uintptr
}

type IOleCache21 = TIOleCache21

type TLPOLECACHECONTROL = uintptr

type LPOLECACHECONTROL = TLPOLECACHECONTROL

type TIOleCacheControlVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FOnRun          uintptr
	FOnStop         uintptr
}

type IOleCacheControlVtbl = TIOleCacheControlVtbl

type TIOleCacheControl1 = struct {
	FlpVtbl uintptr
}

type IOleCacheControl1 = TIOleCacheControl1

type TLPPARSEDISPLAYNAME = uintptr

type LPPARSEDISPLAYNAME = TLPPARSEDISPLAYNAME

type TIParseDisplayNameVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FParseDisplayName uintptr
}

type IParseDisplayNameVtbl = TIParseDisplayNameVtbl

type TIParseDisplayName1 = struct {
	FlpVtbl uintptr
}

type IParseDisplayName1 = TIParseDisplayName1

type TLPOLECONTAINER = uintptr

type LPOLECONTAINER = TLPOLECONTAINER

type TIOleContainerVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FParseDisplayName uintptr
	FEnumObjects      uintptr
	FLockContainer    uintptr
}

type IOleContainerVtbl = TIOleContainerVtbl

type TIOleContainer1 = struct {
	FlpVtbl uintptr
}

type IOleContainer1 = TIOleContainer1

type TLPOLECLIENTSITE = uintptr

type LPOLECLIENTSITE = TLPOLECLIENTSITE

type TIOleClientSiteVtbl = struct {
	FQueryInterface         uintptr
	FAddRef                 uintptr
	FRelease                uintptr
	FSaveObject             uintptr
	FGetMoniker             uintptr
	FGetContainer           uintptr
	FShowObject             uintptr
	FOnShowWindow           uintptr
	FRequestNewObjectLayout uintptr
}

type IOleClientSiteVtbl = TIOleClientSiteVtbl

type TIOleClientSite1 = struct {
	FlpVtbl uintptr
}

type IOleClientSite1 = TIOleClientSite1

type TLPOLEOBJECT = uintptr

type LPOLEOBJECT = TLPOLEOBJECT

type TOLEGETMONIKER = int32

type OLEGETMONIKER = TOLEGETMONIKER

type _tagOLEGETMONIKER = int32

const _OLEGETMONIKER_ONLYIFTHERE = 1
const _OLEGETMONIKER_FORCEASSIGN = 2
const _OLEGETMONIKER_UNASSIGN = 3
const _OLEGETMONIKER_TEMPFORUSER = 4

type TOLEWHICHMK = int32

type OLEWHICHMK = TOLEWHICHMK

type _tagOLEWHICHMK = int32

const _OLEWHICHMK_CONTAINER = 1
const _OLEWHICHMK_OBJREL = 2
const _OLEWHICHMK_OBJFULL = 3

type TUSERCLASSTYPE = int32

type USERCLASSTYPE = TUSERCLASSTYPE

type _tagUSERCLASSTYPE = int32

const _USERCLASSTYPE_FULL = 1
const _USERCLASSTYPE_SHORT = 2
const _USERCLASSTYPE_APPNAME = 3

type TOLEMISC = int32

type OLEMISC = TOLEMISC

type _tagOLEMISC = int32

const _OLEMISC_RECOMPOSEONRESIZE = 1
const _OLEMISC_ONLYICONIC = 2
const _OLEMISC_INSERTNOTREPLACE = 4
const _OLEMISC_STATIC = 8
const _OLEMISC_CANTLINKINSIDE = 16
const _OLEMISC_CANLINKBYOLE1 = 32
const _OLEMISC_ISLINKOBJECT = 64
const _OLEMISC_INSIDEOUT = 128
const _OLEMISC_ACTIVATEWHENVISIBLE = 256
const _OLEMISC_RENDERINGISDEVICEINDEPENDENT = 512
const _OLEMISC_INVISIBLEATRUNTIME = 1024
const _OLEMISC_ALWAYSRUN = 2048
const _OLEMISC_ACTSLIKEBUTTON = 4096
const _OLEMISC_ACTSLIKELABEL = 8192
const _OLEMISC_NOUIACTIVATE = 16384
const _OLEMISC_ALIGNABLE = 32768
const _OLEMISC_SIMPLEFRAME = 65536
const _OLEMISC_SETCLIENTSITEFIRST = 131072
const _OLEMISC_IMEMODE = 262144
const _OLEMISC_IGNOREACTIVATEWHENVISIBLE = 524288
const _OLEMISC_WANTSTOMENUMERGE = 1048576
const _OLEMISC_SUPPORTSMULTILEVELUNDO = 2097152

type TOLECLOSE = int32

type OLECLOSE = TOLECLOSE

type _tagOLECLOSE = int32

const _OLECLOSE_SAVEIFDIRTY = 0
const _OLECLOSE_NOSAVE = 1
const _OLECLOSE_PROMPTSAVE = 2

type TIOleObjectVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FSetClientSite    uintptr
	FGetClientSite    uintptr
	FSetHostNames     uintptr
	FClose            uintptr
	FSetMoniker       uintptr
	FGetMoniker       uintptr
	FInitFromData     uintptr
	FGetClipboardData uintptr
	FDoVerb           uintptr
	FEnumVerbs        uintptr
	FUpdate           uintptr
	FIsUpToDate       uintptr
	FGetUserClassID   uintptr
	FGetUserType      uintptr
	FSetExtent        uintptr
	FGetExtent        uintptr
	FAdvise           uintptr
	FUnadvise         uintptr
	FEnumAdvise       uintptr
	FGetMiscStatus    uintptr
	FSetColorScheme   uintptr
}

type IOleObjectVtbl = TIOleObjectVtbl

type TIOleObject1 = struct {
	FlpVtbl uintptr
}

type IOleObject1 = TIOleObject1

type TOLERENDER = int32

type OLERENDER = TOLERENDER

type _tagOLERENDER = int32

const _OLERENDER_NONE = 0
const _OLERENDER_DRAW = 1
const _OLERENDER_FORMAT = 2
const _OLERENDER_ASIS = 3

type TLPOLERENDER = uintptr

type LPOLERENDER = TLPOLERENDER

type TOBJECTDESCRIPTOR = struct {
	FcbSize             TULONG
	Fclsid              TCLSID
	FdwDrawAspect       TDWORD
	Fsizel              TSIZEL
	Fpointl             TPOINTL
	FdwStatus           TDWORD
	FdwFullUserTypeName TDWORD
	FdwSrcOfCopy        TDWORD
}

type OBJECTDESCRIPTOR = TOBJECTDESCRIPTOR

type TtagOBJECTDESCRIPTOR = TOBJECTDESCRIPTOR

type tagOBJECTDESCRIPTOR = TtagOBJECTDESCRIPTOR

type TPOBJECTDESCRIPTOR = uintptr

type POBJECTDESCRIPTOR = TPOBJECTDESCRIPTOR

type TLPOBJECTDESCRIPTOR = uintptr

type LPOBJECTDESCRIPTOR = TLPOBJECTDESCRIPTOR

type TLINKSRCDESCRIPTOR = struct {
	FcbSize             TULONG
	Fclsid              TCLSID
	FdwDrawAspect       TDWORD
	Fsizel              TSIZEL
	Fpointl             TPOINTL
	FdwStatus           TDWORD
	FdwFullUserTypeName TDWORD
	FdwSrcOfCopy        TDWORD
}

type LINKSRCDESCRIPTOR = TLINKSRCDESCRIPTOR

type TPLINKSRCDESCRIPTOR = uintptr

type PLINKSRCDESCRIPTOR = TPLINKSRCDESCRIPTOR

type TLPLINKSRCDESCRIPTOR = uintptr

type LPLINKSRCDESCRIPTOR = TLPLINKSRCDESCRIPTOR

type TLPOLEWINDOW = uintptr

type LPOLEWINDOW = TLPOLEWINDOW

type TIOleWindowVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetWindow            uintptr
	FContextSensitiveHelp uintptr
}

type IOleWindowVtbl = TIOleWindowVtbl

type TIOleWindow1 = struct {
	FlpVtbl uintptr
}

type IOleWindow1 = TIOleWindow1

type TLPOLELINK = uintptr

type LPOLELINK = TLPOLELINK

type TOLEUPDATE = int32

type OLEUPDATE = TOLEUPDATE

type _tagOLEUPDATE = int32

const _OLEUPDATE_ALWAYS = 1
const _OLEUPDATE_ONCALL = 3

type TLPOLEUPDATE = uintptr

type LPOLEUPDATE = TLPOLEUPDATE

type TPOLEUPDATE = uintptr

type POLEUPDATE = TPOLEUPDATE

type TOLELINKBIND = int32

type OLELINKBIND = TOLELINKBIND

type _tagOLELINKBIND = int32

const _OLELINKBIND_EVENIFCLASSDIFF = 1

type TIOleLinkVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FSetUpdateOptions     uintptr
	FGetUpdateOptions     uintptr
	FSetSourceMoniker     uintptr
	FGetSourceMoniker     uintptr
	FSetSourceDisplayName uintptr
	FGetSourceDisplayName uintptr
	FBindToSource         uintptr
	FBindIfRunning        uintptr
	FGetBoundSource       uintptr
	FUnbindSource         uintptr
	FUpdate               uintptr
}

type IOleLinkVtbl = TIOleLinkVtbl

type TIOleLink1 = struct {
	FlpVtbl uintptr
}

type IOleLink1 = TIOleLink1

type TLPOLEITEMCONTAINER = uintptr

type LPOLEITEMCONTAINER = TLPOLEITEMCONTAINER

type TBINDSPEED = int32

type BINDSPEED = TBINDSPEED

type _tagBINDSPEED = int32

const _BINDSPEED_INDEFINITE = 1
const _BINDSPEED_MODERATE = 2
const _BINDSPEED_IMMEDIATE = 3

type TOLECONTF = int32

type OLECONTF = TOLECONTF

type _tagOLECONTF = int32

const _OLECONTF_EMBEDDINGS = 1
const _OLECONTF_LINKS = 2
const _OLECONTF_OTHERS = 4
const _OLECONTF_ONLYUSER = 8
const _OLECONTF_ONLYIFRUNNING = 16

type TIOleItemContainerVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FParseDisplayName uintptr
	FEnumObjects      uintptr
	FLockContainer    uintptr
	FGetObjectA       uintptr
	FGetObjectStorage uintptr
	FIsRunning        uintptr
}

type IOleItemContainerVtbl = TIOleItemContainerVtbl

type TIOleItemContainer1 = struct {
	FlpVtbl uintptr
}

type IOleItemContainer1 = TIOleItemContainer1

type TLPOLEINPLACEUIWINDOW = uintptr

type LPOLEINPLACEUIWINDOW = TLPOLEINPLACEUIWINDOW

type TBORDERWIDTHS = struct {
	Fleft   TLONG
	Ftop    TLONG
	Fright  TLONG
	Fbottom TLONG
}

type BORDERWIDTHS = TBORDERWIDTHS

type TLPBORDERWIDTHS = uintptr

type LPBORDERWIDTHS = TLPBORDERWIDTHS

type TLPCBORDERWIDTHS = uintptr

type LPCBORDERWIDTHS = TLPCBORDERWIDTHS

type TIOleInPlaceUIWindowVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetWindow            uintptr
	FContextSensitiveHelp uintptr
	FGetBorder            uintptr
	FRequestBorderSpace   uintptr
	FSetBorderSpace       uintptr
	FSetActiveObject      uintptr
}

type IOleInPlaceUIWindowVtbl = TIOleInPlaceUIWindowVtbl

type TIOleInPlaceUIWindow1 = struct {
	FlpVtbl uintptr
}

type IOleInPlaceUIWindow1 = TIOleInPlaceUIWindow1

type TLPOLEINPLACEACTIVEOBJECT = uintptr

type LPOLEINPLACEACTIVEOBJECT = TLPOLEINPLACEACTIVEOBJECT

type TIOleInPlaceActiveObjectVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetWindow             uintptr
	FContextSensitiveHelp  uintptr
	FTranslateAcceleratorA uintptr
	FOnFrameWindowActivate uintptr
	FOnDocWindowActivate   uintptr
	FResizeBorder          uintptr
	FEnableModeless        uintptr
}

type IOleInPlaceActiveObjectVtbl = TIOleInPlaceActiveObjectVtbl

type TIOleInPlaceActiveObject1 = struct {
	FlpVtbl uintptr
}

type IOleInPlaceActiveObject1 = TIOleInPlaceActiveObject1

type TLPOLEINPLACEFRAME = uintptr

type LPOLEINPLACEFRAME = TLPOLEINPLACEFRAME

type TOLEINPLACEFRAMEINFO = struct {
	Fcb            TUINT
	FfMDIApp       TWINBOOL
	FhwndFrame     THWND
	Fhaccel        THACCEL
	FcAccelEntries TUINT
}

type OLEINPLACEFRAMEINFO = TOLEINPLACEFRAMEINFO

type TtagOIFI = TOLEINPLACEFRAMEINFO

type tagOIFI = TtagOIFI

type TLPOLEINPLACEFRAMEINFO = uintptr

type LPOLEINPLACEFRAMEINFO = TLPOLEINPLACEFRAMEINFO

type TOLEMENUGROUPWIDTHS = struct {
	Fwidth [6]TLONG
}

type OLEMENUGROUPWIDTHS = TOLEMENUGROUPWIDTHS

type TtagOleMenuGroupWidths = TOLEMENUGROUPWIDTHS

type tagOleMenuGroupWidths = TtagOleMenuGroupWidths

type TLPOLEMENUGROUPWIDTHS = uintptr

type LPOLEMENUGROUPWIDTHS = TLPOLEMENUGROUPWIDTHS

type THOLEMENU = uintptr

type HOLEMENU = THOLEMENU

type TIOleInPlaceFrameVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetWindow             uintptr
	FContextSensitiveHelp  uintptr
	FGetBorder             uintptr
	FRequestBorderSpace    uintptr
	FSetBorderSpace        uintptr
	FSetActiveObject       uintptr
	FInsertMenus           uintptr
	FSetMenu               uintptr
	FRemoveMenus           uintptr
	FSetStatusText         uintptr
	FEnableModeless        uintptr
	FTranslateAcceleratorA uintptr
}

type IOleInPlaceFrameVtbl = TIOleInPlaceFrameVtbl

type TIOleInPlaceFrame1 = struct {
	FlpVtbl uintptr
}

type IOleInPlaceFrame1 = TIOleInPlaceFrame1

type TLPOLEINPLACEOBJECT = uintptr

type LPOLEINPLACEOBJECT = TLPOLEINPLACEOBJECT

type TIOleInPlaceObjectVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetWindow            uintptr
	FContextSensitiveHelp uintptr
	FInPlaceDeactivate    uintptr
	FUIDeactivate         uintptr
	FSetObjectRects       uintptr
	FReactivateAndUndo    uintptr
}

type IOleInPlaceObjectVtbl = TIOleInPlaceObjectVtbl

type TIOleInPlaceObject1 = struct {
	FlpVtbl uintptr
}

type IOleInPlaceObject1 = TIOleInPlaceObject1

type TLPOLEINPLACESITE = uintptr

type LPOLEINPLACESITE = TLPOLEINPLACESITE

type TIOleInPlaceSiteVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetWindow            uintptr
	FContextSensitiveHelp uintptr
	FCanInPlaceActivate   uintptr
	FOnInPlaceActivate    uintptr
	FOnUIActivate         uintptr
	FGetWindowContext     uintptr
	FScroll               uintptr
	FOnUIDeactivate       uintptr
	FOnInPlaceDeactivate  uintptr
	FDiscardUndoState     uintptr
	FDeactivateAndUndo    uintptr
	FOnPosRectChange      uintptr
}

type IOleInPlaceSiteVtbl = TIOleInPlaceSiteVtbl

type TIOleInPlaceSite1 = struct {
	FlpVtbl uintptr
}

type IOleInPlaceSite1 = TIOleInPlaceSite1

type TIContinueVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FFContinue      uintptr
}

type IContinueVtbl = TIContinueVtbl

type TIContinue1 = struct {
	FlpVtbl uintptr
}

type IContinue1 = TIContinue1

type TLPVIEWOBJECT = uintptr

type LPVIEWOBJECT = TLPVIEWOBJECT

type TIViewObjectVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FDraw           uintptr
	FGetColorSet    uintptr
	FFreeze         uintptr
	FUnfreeze       uintptr
	FSetAdvise      uintptr
	FGetAdvise      uintptr
}

type IViewObjectVtbl = TIViewObjectVtbl

type TIViewObject1 = struct {
	FlpVtbl uintptr
}

type IViewObject1 = TIViewObject1

type TLPVIEWOBJECT2 = uintptr

type LPVIEWOBJECT2 = TLPVIEWOBJECT2

type TIViewObject2Vtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FDraw           uintptr
	FGetColorSet    uintptr
	FFreeze         uintptr
	FUnfreeze       uintptr
	FSetAdvise      uintptr
	FGetAdvise      uintptr
	FGetExtent      uintptr
}

type IViewObject2Vtbl = TIViewObject2Vtbl

type TIViewObject21 = struct {
	FlpVtbl uintptr
}

type IViewObject21 = TIViewObject21

type TLPDROPSOURCE = uintptr

type LPDROPSOURCE = TLPDROPSOURCE

type TIDropSourceVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FQueryContinueDrag uintptr
	FGiveFeedback      uintptr
}

type IDropSourceVtbl = TIDropSourceVtbl

type TIDropSource1 = struct {
	FlpVtbl uintptr
}

type IDropSource1 = TIDropSource1

type TLPDROPTARGET = uintptr

type LPDROPTARGET = TLPDROPTARGET

type TIDropTargetVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FDragEnter      uintptr
	FDragOver       uintptr
	FDragLeave      uintptr
	FDrop           uintptr
}

type IDropTargetVtbl = TIDropTargetVtbl

type TIDropTarget1 = struct {
	FlpVtbl uintptr
}

type IDropTarget1 = TIDropTarget1

type TIDropSourceNotifyVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FDragEnterTarget uintptr
	FDragLeaveTarget uintptr
}

type IDropSourceNotifyVtbl = TIDropSourceNotifyVtbl

type TIDropSourceNotify1 = struct {
	FlpVtbl uintptr
}

type IDropSourceNotify1 = TIDropSourceNotify1

type TLPENUMOLEVERB = uintptr

type LPENUMOLEVERB = TLPENUMOLEVERB

type TOLEVERB = struct {
	FlVerb        TLONG
	FlpszVerbName TLPOLESTR
	FfuFlags      TDWORD
	FgrfAttribs   TDWORD
}

type OLEVERB = TOLEVERB

type TtagOLEVERB = TOLEVERB

type tagOLEVERB = TtagOLEVERB

type TLPOLEVERB = uintptr

type LPOLEVERB = TLPOLEVERB

type TOLEVERBATTRIB = int32

type OLEVERBATTRIB = TOLEVERBATTRIB

type _tagOLEVERBATTRIB = int32

const _OLEVERBATTRIB_NEVERDIRTIES = 1
const _OLEVERBATTRIB_ONCONTAINERMENU = 2

type TIEnumOLEVERBVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumOLEVERBVtbl = TIEnumOLEVERBVtbl

type TIEnumOLEVERB1 = struct {
	FlpVtbl uintptr
}

type IEnumOLEVERB1 = TIEnumOLEVERB1

type TIServiceProvider = struct {
	FlpVtbl uintptr
}

type IServiceProvider = TIServiceProvider

type TLPSERVICEPROVIDER = uintptr

type LPSERVICEPROVIDER = TLPSERVICEPROVIDER

type TIServiceProviderVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FQueryService   uintptr
}

type IServiceProviderVtbl = TIServiceProviderVtbl

type TIServiceProvider1 = struct {
	FlpVtbl uintptr
}

type IServiceProvider1 = TIServiceProvider1

type TICreateTypeInfo = struct {
	FlpVtbl uintptr
}

type ICreateTypeInfo = TICreateTypeInfo

type TICreateTypeInfo2 = struct {
	FlpVtbl uintptr
}

type ICreateTypeInfo2 = TICreateTypeInfo2

type TICreateTypeLib = struct {
	FlpVtbl uintptr
}

type ICreateTypeLib = TICreateTypeLib

type TICreateTypeLib2 = struct {
	FlpVtbl uintptr
}

type ICreateTypeLib2 = TICreateTypeLib2

type TIDispatch = struct {
	FlpVtbl uintptr
}

type IDispatch = TIDispatch

type TIEnumVARIANT = struct {
	FlpVtbl uintptr
}

type IEnumVARIANT = TIEnumVARIANT

type TITypeComp = struct {
	FlpVtbl uintptr
}

type ITypeComp = TITypeComp

type TITypeInfo = struct {
	FlpVtbl uintptr
}

type ITypeInfo = TITypeInfo

type TITypeInfo2 = struct {
	FlpVtbl uintptr
}

type ITypeInfo2 = TITypeInfo2

type TITypeLib = struct {
	FlpVtbl uintptr
}

type ITypeLib = TITypeLib

type TITypeLib2 = struct {
	FlpVtbl uintptr
}

type ITypeLib2 = TITypeLib2

type TITypeChangeEvents = struct {
	FlpVtbl uintptr
}

type ITypeChangeEvents = TITypeChangeEvents

type TIErrorInfo = struct {
	FlpVtbl uintptr
}

type IErrorInfo = TIErrorInfo

type TICreateErrorInfo = struct {
	FlpVtbl uintptr
}

type ICreateErrorInfo = TICreateErrorInfo

type TISupportErrorInfo = struct {
	FlpVtbl uintptr
}

type ISupportErrorInfo = TISupportErrorInfo

type TITypeFactory = struct {
	FlpVtbl uintptr
}

type ITypeFactory = TITypeFactory

type TITypeMarshal = struct {
	FlpVtbl uintptr
}

type ITypeMarshal = TITypeMarshal

type TIRecordInfo = struct {
	FlpVtbl uintptr
}

type IRecordInfo = TIRecordInfo

type TIErrorLog = struct {
	FlpVtbl uintptr
}

type IErrorLog = TIErrorLog

type TIPropertyBag = struct {
	FlpVtbl uintptr
}

type IPropertyBag = TIPropertyBag

type TCURRENCY = struct {
	F__ccgo_align [0]uint32
	Fint641       [0]TLONGLONG
	F__ccgo0_0    struct {
		FLo uint32
		FHi int32
	}
}

type CURRENCY = TCURRENCY

type TSAFEARRAYBOUND = struct {
	FcElements TULONG
	FlLbound   TLONG
}

type SAFEARRAYBOUND = TSAFEARRAYBOUND

type TtagSAFEARRAYBOUND = TSAFEARRAYBOUND

type tagSAFEARRAYBOUND = TtagSAFEARRAYBOUND

type TLPSAFEARRAYBOUND = uintptr

type LPSAFEARRAYBOUND = TLPSAFEARRAYBOUND

type TwireVARIANT = uintptr

type wireVARIANT = TwireVARIANT

type T_wireVARIANT = struct {
	F__ccgo_align [0]uint32
	FclSize       TDWORD
	FrpcReserved  TDWORD
	Fvt           TUSHORT
	FwReserved1   TUSHORT
	FwReserved2   TUSHORT
	FwReserved3   TUSHORT
	F__ccgo6_16   struct {
		F__ccgo_align [0]uint32
		FlVal         [0]TLONG
		FbVal         [0]TBYTE
		FiVal         [0]TSHORT
		FfltVal       [0]TFLOAT
		FdblVal       [0]TDOUBLE
		FboolVal      [0]TVARIANT_BOOL
		Fscode        [0]TSCODE
		FcyVal        [0]TCY
		Fdate         [0]TDATE
		FbstrVal      [0]TwireBSTR
		FpunkVal      [0]uintptr
		FpdispVal     [0]uintptr
		Fparray       [0]TwirePSAFEARRAY
		FbrecVal      [0]TwireBRECORD
		FpbVal        [0]uintptr
		FpiVal        [0]uintptr
		FplVal        [0]uintptr
		FpllVal       [0]uintptr
		FpfltVal      [0]uintptr
		FpdblVal      [0]uintptr
		FpboolVal     [0]uintptr
		Fpscode       [0]uintptr
		FpcyVal       [0]uintptr
		Fpdate        [0]uintptr
		FpbstrVal     [0]uintptr
		FppunkVal     [0]uintptr
		FppdispVal    [0]uintptr
		Fpparray      [0]uintptr
		FpvarVal      [0]uintptr
		FcVal         [0]TCHAR
		FuiVal        [0]TUSHORT
		FulVal        [0]TULONG
		FullVal       [0]TULONGLONG
		FintVal       [0]TINT
		FuintVal      [0]TUINT
		FdecVal       [0]TDECIMAL
		FpdecVal      [0]uintptr
		FpcVal        [0]uintptr
		FpuiVal       [0]uintptr
		FpulVal       [0]uintptr
		FpullVal      [0]uintptr
		FpintVal      [0]uintptr
		FpuintVal     [0]uintptr
		FllVal        TLONGLONG
		F__ccgo_pad44 [8]byte
	}
}

type _wireVARIANT = T_wireVARIANT

type TwireBRECORD = uintptr

type wireBRECORD = TwireBRECORD

type T_wireBRECORD = struct {
	FfFlags   TULONG
	FclSize   TULONG
	FpRecInfo uintptr
	FpRecord  uintptr
}

type _wireBRECORD = T_wireBRECORD

type TSAFEARR_BSTR = struct {
	FSize  TULONG
	FaBstr uintptr
}

type SAFEARR_BSTR = TSAFEARR_BSTR

type T_wireSAFEARR_BSTR = TSAFEARR_BSTR

type _wireSAFEARR_BSTR = T_wireSAFEARR_BSTR

type TSAFEARR_UNKNOWN = struct {
	FSize      TULONG
	FapUnknown uintptr
}

type SAFEARR_UNKNOWN = TSAFEARR_UNKNOWN

type T_wireSAFEARR_UNKNOWN = TSAFEARR_UNKNOWN

type _wireSAFEARR_UNKNOWN = T_wireSAFEARR_UNKNOWN

type TSAFEARR_DISPATCH = struct {
	FSize       TULONG
	FapDispatch uintptr
}

type SAFEARR_DISPATCH = TSAFEARR_DISPATCH

type T_wireSAFEARR_DISPATCH = TSAFEARR_DISPATCH

type _wireSAFEARR_DISPATCH = T_wireSAFEARR_DISPATCH

type TSAFEARR_VARIANT = struct {
	FSize     TULONG
	FaVariant uintptr
}

type SAFEARR_VARIANT = TSAFEARR_VARIANT

type T_wireSAFEARR_VARIANT = TSAFEARR_VARIANT

type _wireSAFEARR_VARIANT = T_wireSAFEARR_VARIANT

type TSAFEARR_BRECORD = struct {
	FSize    TULONG
	FaRecord uintptr
}

type SAFEARR_BRECORD = TSAFEARR_BRECORD

type T_wireSAFEARR_BRECORD = TSAFEARR_BRECORD

type _wireSAFEARR_BRECORD = T_wireSAFEARR_BRECORD

type TSAFEARR_HAVEIID = struct {
	FSize      TULONG
	FapUnknown uintptr
	Fiid       TIID
}

type SAFEARR_HAVEIID = TSAFEARR_HAVEIID

type T_wireSAFEARR_HAVEIID = TSAFEARR_HAVEIID

type _wireSAFEARR_HAVEIID = T_wireSAFEARR_HAVEIID

type TSF_TYPE = int32

type SF_TYPE = TSF_TYPE

type _tagSF_TYPE = int32

const _SF_ERROR = 10
const _SF_I1 = 16
const _SF_I2 = 2
const _SF_I4 = 3
const _SF_I8 = 20
const _SF_BSTR = 8
const _SF_UNKNOWN = 13
const _SF_DISPATCH = 9
const _SF_VARIANT = 12
const _SF_RECORD = 36
const _SF_HAVEIID = 32781

type TSAFEARRAYUNION = struct {
	FsfType TULONG
	Fu      t__WIDL_oaidl_generated_name_0000000E
}

type SAFEARRAYUNION = TSAFEARRAYUNION

type T_wireSAFEARRAY_UNION = TSAFEARRAYUNION

type _wireSAFEARRAY_UNION = T_wireSAFEARRAY_UNION

type TwireSAFEARRAY = uintptr

type wireSAFEARRAY = TwireSAFEARRAY

type T_wireSAFEARRAY = struct {
	FcDims         TUSHORT
	FfFeatures     TUSHORT
	FcbElements    TULONG
	FcLocks        TULONG
	FuArrayStructs TSAFEARRAYUNION
	Frgsabound     [1]TSAFEARRAYBOUND
}

type _wireSAFEARRAY = T_wireSAFEARRAY

type TwirePSAFEARRAY = uintptr

type wirePSAFEARRAY = TwirePSAFEARRAY

type TSAFEARRAY = struct {
	FcDims      TUSHORT
	FfFeatures  TUSHORT
	FcbElements TULONG
	FcLocks     TULONG
	FpvData     TPVOID
	Frgsabound  [1]TSAFEARRAYBOUND
}

type SAFEARRAY = TSAFEARRAY

type TtagSAFEARRAY = TSAFEARRAY

type tagSAFEARRAY = TtagSAFEARRAY

type TLPSAFEARRAY = uintptr

type LPSAFEARRAY = TLPSAFEARRAY

type TVARIANT = struct {
	F__ccgo_align [0]uint32
	F__ccgo0_0    struct {
		F__ccgo_align [0]uint32
		FdecVal       [0]TDECIMAL
		F__ccgo0_0    struct {
			F__ccgo_align [0]uint32
			Fvt           TVARTYPE
			FwReserved1   TWORD
			FwReserved2   TWORD
			FwReserved3   TWORD
			F__ccgo4_8    struct {
				F__ccgo_align [0]uint32
				FlVal         [0]TLONG
				FbVal         [0]TBYTE
				FiVal         [0]TSHORT
				FfltVal       [0]TFLOAT
				FdblVal       [0]TDOUBLE
				FboolVal      [0]TVARIANT_BOOL
				Fscode        [0]TSCODE
				FcyVal        [0]TCY
				Fdate         [0]TDATE
				FbstrVal      [0]TBSTR
				FpunkVal      [0]uintptr
				FpdispVal     [0]uintptr
				Fparray       [0]uintptr
				FpbVal        [0]uintptr
				FpiVal        [0]uintptr
				FplVal        [0]uintptr
				FpllVal       [0]uintptr
				FpfltVal      [0]uintptr
				FpdblVal      [0]uintptr
				FpboolVal     [0]uintptr
				Fpscode       [0]uintptr
				FpcyVal       [0]uintptr
				Fpdate        [0]uintptr
				FpbstrVal     [0]uintptr
				FppunkVal     [0]uintptr
				FppdispVal    [0]uintptr
				Fpparray      [0]uintptr
				FpvarVal      [0]uintptr
				Fbyref        [0]TPVOID
				FcVal         [0]TCHAR
				FuiVal        [0]TUSHORT
				FulVal        [0]TULONG
				FullVal       [0]TULONGLONG
				FintVal       [0]TINT
				FuintVal      [0]TUINT
				FpdecVal      [0]uintptr
				FpcVal        [0]uintptr
				FpuiVal       [0]uintptr
				FpulVal       [0]uintptr
				FpullVal      [0]uintptr
				FpintVal      [0]uintptr
				FpuintVal     [0]uintptr
				F__ccgo43_0   [0]struct {
					FpvRecord TPVOID
					FpRecInfo uintptr
				}
				FllVal TLONGLONG
			}
		}
	}
}

type VARIANT = TVARIANT

type TtagVARIANT = TVARIANT

type tagVARIANT = TtagVARIANT

type TLPVARIANT = uintptr

type LPVARIANT = TLPVARIANT

type TVARIANTARG = struct {
	F__ccgo_align [0]uint32
	F__ccgo0_0    struct {
		F__ccgo_align [0]uint32
		FdecVal       [0]TDECIMAL
		F__ccgo0_0    struct {
			F__ccgo_align [0]uint32
			Fvt           TVARTYPE
			FwReserved1   TWORD
			FwReserved2   TWORD
			FwReserved3   TWORD
			F__ccgo4_8    struct {
				F__ccgo_align [0]uint32
				FlVal         [0]TLONG
				FbVal         [0]TBYTE
				FiVal         [0]TSHORT
				FfltVal       [0]TFLOAT
				FdblVal       [0]TDOUBLE
				FboolVal      [0]TVARIANT_BOOL
				Fscode        [0]TSCODE
				FcyVal        [0]TCY
				Fdate         [0]TDATE
				FbstrVal      [0]TBSTR
				FpunkVal      [0]uintptr
				FpdispVal     [0]uintptr
				Fparray       [0]uintptr
				FpbVal        [0]uintptr
				FpiVal        [0]uintptr
				FplVal        [0]uintptr
				FpllVal       [0]uintptr
				FpfltVal      [0]uintptr
				FpdblVal      [0]uintptr
				FpboolVal     [0]uintptr
				Fpscode       [0]uintptr
				FpcyVal       [0]uintptr
				Fpdate        [0]uintptr
				FpbstrVal     [0]uintptr
				FppunkVal     [0]uintptr
				FppdispVal    [0]uintptr
				Fpparray      [0]uintptr
				FpvarVal      [0]uintptr
				Fbyref        [0]TPVOID
				FcVal         [0]TCHAR
				FuiVal        [0]TUSHORT
				FulVal        [0]TULONG
				FullVal       [0]TULONGLONG
				FintVal       [0]TINT
				FuintVal      [0]TUINT
				FpdecVal      [0]uintptr
				FpcVal        [0]uintptr
				FpuiVal       [0]uintptr
				FpulVal       [0]uintptr
				FpullVal      [0]uintptr
				FpintVal      [0]uintptr
				FpuintVal     [0]uintptr
				F__ccgo43_0   [0]struct {
					FpvRecord TPVOID
					FpRecInfo uintptr
				}
				FllVal TLONGLONG
			}
		}
	}
}

type VARIANTARG = TVARIANTARG

type TLPVARIANTARG = uintptr

type LPVARIANTARG = TLPVARIANTARG

type TDISPID = int32

type DISPID = TDISPID

type TMEMBERID = int32

type MEMBERID = TMEMBERID

type THREFTYPE = uint32

type HREFTYPE = THREFTYPE

type TTYPEKIND = int32

type TYPEKIND = TTYPEKIND

type _tagTYPEKIND = int32

const _TKIND_ENUM = 0
const _TKIND_RECORD = 1
const _TKIND_MODULE = 2
const _TKIND_INTERFACE = 3
const _TKIND_DISPATCH = 4
const _TKIND_COCLASS = 5
const _TKIND_ALIAS = 6
const _TKIND_UNION = 7
const _TKIND_MAX = 8

type TTYPEDESC = struct {
	F__ccgo0_0 struct {
		Flpadesc  [0]uintptr
		Fhreftype [0]THREFTYPE
		Flptdesc  uintptr
	}
	Fvt TVARTYPE
}

type TYPEDESC = TTYPEDESC

type TtagTYPEDESC = TTYPEDESC

type tagTYPEDESC = TtagTYPEDESC

type TARRAYDESC = struct {
	FtdescElem TTYPEDESC
	FcDims     TUSHORT
	Frgbounds  [1]TSAFEARRAYBOUND
}

type ARRAYDESC = TARRAYDESC

type TtagARRAYDESC = TARRAYDESC

type tagARRAYDESC = TtagARRAYDESC

type TPARAMDESCEX = struct {
	F__ccgo_align    [0]uint32
	FcBytes          TULONG
	F__ccgo_align1   [4]byte
	FvarDefaultValue TVARIANTARG
}

type PARAMDESCEX = TPARAMDESCEX

type TtagPARAMDESCEX = TPARAMDESCEX

type tagPARAMDESCEX = TtagPARAMDESCEX

type TLPPARAMDESCEX = uintptr

type LPPARAMDESCEX = TLPPARAMDESCEX

type TPARAMDESC = struct {
	Fpparamdescex TLPPARAMDESCEX
	FwParamFlags  TUSHORT
}

type PARAMDESC = TPARAMDESC

type TtagPARAMDESC = TPARAMDESC

type tagPARAMDESC = TtagPARAMDESC

type TLPPARAMDESC = uintptr

type LPPARAMDESC = TLPPARAMDESC

type TIDLDESC = struct {
	FdwReserved TULONG_PTR
	FwIDLFlags  TUSHORT
}

type IDLDESC = TIDLDESC

type TtagIDLDESC = TIDLDESC

type tagIDLDESC = TtagIDLDESC

type TLPIDLDESC = uintptr

type LPIDLDESC = TLPIDLDESC

type TELEMDESC = struct {
	Ftdesc     TTYPEDESC
	F__ccgo1_8 struct {
		Fparamdesc [0]TPARAMDESC
		Fidldesc   TIDLDESC
	}
}

type ELEMDESC = TELEMDESC

type TtagELEMDESC = TELEMDESC

type tagELEMDESC = TtagELEMDESC

type TLPELEMDESC = uintptr

type LPELEMDESC = TLPELEMDESC

type TTYPEATTR = struct {
	Fguid             TGUID
	Flcid             TLCID
	FdwReserved       TDWORD
	FmemidConstructor TMEMBERID
	FmemidDestructor  TMEMBERID
	FlpstrSchema      TLPOLESTR
	FcbSizeInstance   TULONG
	Ftypekind         TTYPEKIND
	FcFuncs           TWORD
	FcVars            TWORD
	FcImplTypes       TWORD
	FcbSizeVft        TWORD
	FcbAlignment      TWORD
	FwTypeFlags       TWORD
	FwMajorVerNum     TWORD
	FwMinorVerNum     TWORD
	FtdescAlias       TTYPEDESC
	FidldescType      TIDLDESC
}

type TYPEATTR = TTYPEATTR

type TtagTYPEATTR = TTYPEATTR

type tagTYPEATTR = TtagTYPEATTR

type TLPTYPEATTR = uintptr

type LPTYPEATTR = TLPTYPEATTR

type TDISPPARAMS = struct {
	Frgvarg            uintptr
	FrgdispidNamedArgs uintptr
	FcArgs             TUINT
	FcNamedArgs        TUINT
}

type DISPPARAMS = TDISPPARAMS

type TtagDISPPARAMS = TDISPPARAMS

type tagDISPPARAMS = TtagDISPPARAMS

type TEXCEPINFO = struct {
	FwCode             TWORD
	FwReserved         TWORD
	FbstrSource        TBSTR
	FbstrDescription   TBSTR
	FbstrHelpFile      TBSTR
	FdwHelpContext     TDWORD
	FpvReserved        TPVOID
	FpfnDeferredFillIn uintptr
	Fscode             TSCODE
}

type EXCEPINFO = TEXCEPINFO

type TtagEXCEPINFO = TEXCEPINFO

type tagEXCEPINFO = TtagEXCEPINFO

type TLPEXCEPINFO = uintptr

type LPEXCEPINFO = TLPEXCEPINFO

type TCALLCONV = int32

type CALLCONV = TCALLCONV

type _tagCALLCONV = int32

const _CC_FASTCALL = 0
const _CC_CDECL = 1
const _CC_MSCPASCAL = 2
const _CC_PASCAL = 2
const _CC_MACPASCAL = 3
const _CC_STDCALL = 4
const _CC_FPFASTCALL = 5
const _CC_SYSCALL = 6
const _CC_MPWCDECL = 7
const _CC_MPWPASCAL = 8
const _CC_MAX = 9

type TFUNCKIND = int32

type FUNCKIND = TFUNCKIND

type _tagFUNCKIND = int32

const _FUNC_VIRTUAL = 0
const _FUNC_PUREVIRTUAL = 1
const _FUNC_NONVIRTUAL = 2
const _FUNC_STATIC = 3
const _FUNC_DISPATCH = 4

type TINVOKEKIND = int32

type INVOKEKIND = TINVOKEKIND

type _tagINVOKEKIND = int32

const _INVOKE_FUNC = 1
const _INVOKE_PROPERTYGET = 2
const _INVOKE_PROPERTYPUT = 4
const _INVOKE_PROPERTYPUTREF = 8

type TFUNCDESC = struct {
	Fmemid             TMEMBERID
	Flprgscode         uintptr
	FlprgelemdescParam uintptr
	Ffunckind          TFUNCKIND
	Finvkind           TINVOKEKIND
	Fcallconv          TCALLCONV
	FcParams           TSHORT
	FcParamsOpt        TSHORT
	FoVft              TSHORT
	FcScodes           TSHORT
	FelemdescFunc      TELEMDESC
	FwFuncFlags        TWORD
}

type FUNCDESC = TFUNCDESC

type TtagFUNCDESC = TFUNCDESC

type tagFUNCDESC = TtagFUNCDESC

type TLPFUNCDESC = uintptr

type LPFUNCDESC = TLPFUNCDESC

type TVARKIND = int32

type VARKIND = TVARKIND

type _tagVARKIND = int32

const _VAR_PERINSTANCE = 0
const _VAR_STATIC = 1
const _VAR_CONST = 2
const _VAR_DISPATCH = 3

type TVARDESC = struct {
	Fmemid       TMEMBERID
	FlpstrSchema TLPOLESTR
	F__ccgo2_8   struct {
		FlpvarValue [0]uintptr
		FoInst      TULONG
	}
	FelemdescVar TELEMDESC
	FwVarFlags   TWORD
	Fvarkind     TVARKIND
}

type VARDESC = TVARDESC

type TtagVARDESC = TVARDESC

type tagVARDESC = TtagVARDESC

type TLPVARDESC = uintptr

type LPVARDESC = TLPVARDESC

type TTYPEFLAGS = int32

type TYPEFLAGS = TTYPEFLAGS

type _tagTYPEFLAGS = int32

const _TYPEFLAG_FAPPOBJECT = 1
const _TYPEFLAG_FCANCREATE = 2
const _TYPEFLAG_FLICENSED = 4
const _TYPEFLAG_FPREDECLID = 8
const _TYPEFLAG_FHIDDEN = 16
const _TYPEFLAG_FCONTROL = 32
const _TYPEFLAG_FDUAL = 64
const _TYPEFLAG_FNONEXTENSIBLE = 128
const _TYPEFLAG_FOLEAUTOMATION = 256
const _TYPEFLAG_FRESTRICTED = 512
const _TYPEFLAG_FAGGREGATABLE = 1024
const _TYPEFLAG_FREPLACEABLE = 2048
const _TYPEFLAG_FDISPATCHABLE = 4096
const _TYPEFLAG_FREVERSEBIND = 8192
const _TYPEFLAG_FPROXY = 16384

type TFUNCFLAGS = int32

type FUNCFLAGS = TFUNCFLAGS

type _tagFUNCFLAGS = int32

const _FUNCFLAG_FRESTRICTED = 1
const _FUNCFLAG_FSOURCE = 2
const _FUNCFLAG_FBINDABLE = 4
const _FUNCFLAG_FREQUESTEDIT = 8
const _FUNCFLAG_FDISPLAYBIND = 16
const _FUNCFLAG_FDEFAULTBIND = 32
const _FUNCFLAG_FHIDDEN = 64
const _FUNCFLAG_FUSESGETLASTERROR = 128
const _FUNCFLAG_FDEFAULTCOLLELEM = 256
const _FUNCFLAG_FUIDEFAULT = 512
const _FUNCFLAG_FNONBROWSABLE = 1024
const _FUNCFLAG_FREPLACEABLE = 2048
const _FUNCFLAG_FIMMEDIATEBIND = 4096

type TVARFLAGS = int32

type VARFLAGS = TVARFLAGS

type _tagVARFLAGS = int32

const _VARFLAG_FREADONLY = 1
const _VARFLAG_FSOURCE = 2
const _VARFLAG_FBINDABLE = 4
const _VARFLAG_FREQUESTEDIT = 8
const _VARFLAG_FDISPLAYBIND = 16
const _VARFLAG_FDEFAULTBIND = 32
const _VARFLAG_FHIDDEN = 64
const _VARFLAG_FRESTRICTED = 128
const _VARFLAG_FDEFAULTCOLLELEM = 256
const _VARFLAG_FUIDEFAULT = 512
const _VARFLAG_FNONBROWSABLE = 1024
const _VARFLAG_FREPLACEABLE = 2048
const _VARFLAG_FIMMEDIATEBIND = 4096

type TCLEANLOCALSTORAGE = struct {
	FpInterface uintptr
	FpStorage   TPVOID
	Fflags      TDWORD
}

type CLEANLOCALSTORAGE = TCLEANLOCALSTORAGE

type TtagCLEANLOCALSTORAGE = TCLEANLOCALSTORAGE

type tagCLEANLOCALSTORAGE = TtagCLEANLOCALSTORAGE

type TCUSTDATAITEM = struct {
	F__ccgo_align [0]uint32
	Fguid         TGUID
	FvarValue     TVARIANTARG
}

type CUSTDATAITEM = TCUSTDATAITEM

type TtagCUSTDATAITEM = TCUSTDATAITEM

type tagCUSTDATAITEM = TtagCUSTDATAITEM

type TLPCUSTDATAITEM = uintptr

type LPCUSTDATAITEM = TLPCUSTDATAITEM

type TCUSTDATA = struct {
	FcCustData   TDWORD
	FprgCustData TLPCUSTDATAITEM
}

type CUSTDATA = TCUSTDATA

type TtagCUSTDATA = TCUSTDATA

type tagCUSTDATA = TtagCUSTDATA

type TLPCUSTDATA = uintptr

type LPCUSTDATA = TLPCUSTDATA

type TLPCREATETYPEINFO = uintptr

type LPCREATETYPEINFO = TLPCREATETYPEINFO

type TICreateTypeInfoVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FSetGuid              uintptr
	FSetTypeFlags         uintptr
	FSetDocString         uintptr
	FSetHelpContext       uintptr
	FSetVersion           uintptr
	FAddRefTypeInfo       uintptr
	FAddFuncDesc          uintptr
	FAddImplType          uintptr
	FSetImplTypeFlags     uintptr
	FSetAlignment         uintptr
	FSetSchema            uintptr
	FAddVarDesc           uintptr
	FSetFuncAndParamNames uintptr
	FSetVarName           uintptr
	FSetTypeDescAlias     uintptr
	FDefineFuncAsDllEntry uintptr
	FSetFuncDocString     uintptr
	FSetVarDocString      uintptr
	FSetFuncHelpContext   uintptr
	FSetVarHelpContext    uintptr
	FSetMops              uintptr
	FSetTypeIdldesc       uintptr
	FLayOut               uintptr
}

type ICreateTypeInfoVtbl = TICreateTypeInfoVtbl

type TICreateTypeInfo1 = struct {
	FlpVtbl uintptr
}

type ICreateTypeInfo1 = TICreateTypeInfo1

type TLPCREATETYPEINFO2 = uintptr

type LPCREATETYPEINFO2 = TLPCREATETYPEINFO2

type TICreateTypeInfo2Vtbl = struct {
	FQueryInterface           uintptr
	FAddRef                   uintptr
	FRelease                  uintptr
	FSetGuid                  uintptr
	FSetTypeFlags             uintptr
	FSetDocString             uintptr
	FSetHelpContext           uintptr
	FSetVersion               uintptr
	FAddRefTypeInfo           uintptr
	FAddFuncDesc              uintptr
	FAddImplType              uintptr
	FSetImplTypeFlags         uintptr
	FSetAlignment             uintptr
	FSetSchema                uintptr
	FAddVarDesc               uintptr
	FSetFuncAndParamNames     uintptr
	FSetVarName               uintptr
	FSetTypeDescAlias         uintptr
	FDefineFuncAsDllEntry     uintptr
	FSetFuncDocString         uintptr
	FSetVarDocString          uintptr
	FSetFuncHelpContext       uintptr
	FSetVarHelpContext        uintptr
	FSetMops                  uintptr
	FSetTypeIdldesc           uintptr
	FLayOut                   uintptr
	FDeleteFuncDesc           uintptr
	FDeleteFuncDescByMemId    uintptr
	FDeleteVarDesc            uintptr
	FDeleteVarDescByMemId     uintptr
	FDeleteImplType           uintptr
	FSetCustData              uintptr
	FSetFuncCustData          uintptr
	FSetParamCustData         uintptr
	FSetVarCustData           uintptr
	FSetImplTypeCustData      uintptr
	FSetHelpStringContext     uintptr
	FSetFuncHelpStringContext uintptr
	FSetVarHelpStringContext  uintptr
	FInvalidate               uintptr
	FSetName                  uintptr
}

type ICreateTypeInfo2Vtbl = TICreateTypeInfo2Vtbl

type TICreateTypeInfo21 = struct {
	FlpVtbl uintptr
}

type ICreateTypeInfo21 = TICreateTypeInfo21

type TLPCREATETYPELIB = uintptr

type LPCREATETYPELIB = TLPCREATETYPELIB

type TICreateTypeLibVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FCreateTypeInfo  uintptr
	FSetName         uintptr
	FSetVersion      uintptr
	FSetGuid         uintptr
	FSetDocString    uintptr
	FSetHelpFileName uintptr
	FSetHelpContext  uintptr
	FSetLcid         uintptr
	FSetLibFlags     uintptr
	FSaveAllChanges  uintptr
}

type ICreateTypeLibVtbl = TICreateTypeLibVtbl

type TICreateTypeLib1 = struct {
	FlpVtbl uintptr
}

type ICreateTypeLib1 = TICreateTypeLib1

type TLPCREATETYPELIB2 = uintptr

type LPCREATETYPELIB2 = TLPCREATETYPELIB2

type TICreateTypeLib2Vtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FCreateTypeInfo       uintptr
	FSetName              uintptr
	FSetVersion           uintptr
	FSetGuid              uintptr
	FSetDocString         uintptr
	FSetHelpFileName      uintptr
	FSetHelpContext       uintptr
	FSetLcid              uintptr
	FSetLibFlags          uintptr
	FSaveAllChanges       uintptr
	FDeleteTypeInfo       uintptr
	FSetCustData          uintptr
	FSetHelpStringContext uintptr
	FSetHelpStringDll     uintptr
}

type ICreateTypeLib2Vtbl = TICreateTypeLib2Vtbl

type TICreateTypeLib21 = struct {
	FlpVtbl uintptr
}

type ICreateTypeLib21 = TICreateTypeLib21

type TLPDISPATCH = uintptr

type LPDISPATCH = TLPDISPATCH

type TIDispatchVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
}

type IDispatchVtbl = TIDispatchVtbl

type TIDispatch1 = struct {
	FlpVtbl uintptr
}

type IDispatch1 = TIDispatch1

type TLPENUMVARIANT = uintptr

type LPENUMVARIANT = TLPENUMVARIANT

type TIEnumVARIANTVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumVARIANTVtbl = TIEnumVARIANTVtbl

type TIEnumVARIANT1 = struct {
	FlpVtbl uintptr
}

type IEnumVARIANT1 = TIEnumVARIANT1

type TLPTYPECOMP = uintptr

type LPTYPECOMP = TLPTYPECOMP

type TDESCKIND = int32

type DESCKIND = TDESCKIND

type _tagDESCKIND = int32

const _DESCKIND_NONE = 0
const _DESCKIND_FUNCDESC = 1
const _DESCKIND_VARDESC = 2
const _DESCKIND_TYPECOMP = 3
const _DESCKIND_IMPLICITAPPOBJ = 4
const _DESCKIND_MAX = 5

type TBINDPTR = struct {
	Flpvardesc  [0]uintptr
	Flptcomp    [0]uintptr
	Flpfuncdesc uintptr
}

type BINDPTR = TBINDPTR

type TtagBINDPTR = TBINDPTR

type tagBINDPTR = TtagBINDPTR

type TLPBINDPTR = uintptr

type LPBINDPTR = TLPBINDPTR

type TITypeCompVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FBind           uintptr
	FBindType       uintptr
}

type ITypeCompVtbl = TITypeCompVtbl

type TITypeComp1 = struct {
	FlpVtbl uintptr
}

type ITypeComp1 = TITypeComp1

type TLPTYPEINFO = uintptr

type LPTYPEINFO = TLPTYPEINFO

type TITypeInfoVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetTypeAttr          uintptr
	FGetTypeComp          uintptr
	FGetFuncDesc          uintptr
	FGetVarDesc           uintptr
	FGetNames             uintptr
	FGetRefTypeOfImplType uintptr
	FGetImplTypeFlags     uintptr
	FGetIDsOfNames        uintptr
	FInvoke               uintptr
	FGetDocumentation     uintptr
	FGetDllEntry          uintptr
	FGetRefTypeInfo       uintptr
	FAddressOfMember      uintptr
	FCreateInstance       uintptr
	FGetMops              uintptr
	FGetContainingTypeLib uintptr
	FReleaseTypeAttr      uintptr
	FReleaseFuncDesc      uintptr
	FReleaseVarDesc       uintptr
}

type ITypeInfoVtbl = TITypeInfoVtbl

type TITypeInfo1 = struct {
	FlpVtbl uintptr
}

type ITypeInfo1 = TITypeInfo1

type TLPTYPEINFO2 = uintptr

type LPTYPEINFO2 = TLPTYPEINFO2

type TITypeInfo2Vtbl = struct {
	FQueryInterface         uintptr
	FAddRef                 uintptr
	FRelease                uintptr
	FGetTypeAttr            uintptr
	FGetTypeComp            uintptr
	FGetFuncDesc            uintptr
	FGetVarDesc             uintptr
	FGetNames               uintptr
	FGetRefTypeOfImplType   uintptr
	FGetImplTypeFlags       uintptr
	FGetIDsOfNames          uintptr
	FInvoke                 uintptr
	FGetDocumentation       uintptr
	FGetDllEntry            uintptr
	FGetRefTypeInfo         uintptr
	FAddressOfMember        uintptr
	FCreateInstance         uintptr
	FGetMops                uintptr
	FGetContainingTypeLib   uintptr
	FReleaseTypeAttr        uintptr
	FReleaseFuncDesc        uintptr
	FReleaseVarDesc         uintptr
	FGetTypeKind            uintptr
	FGetTypeFlags           uintptr
	FGetFuncIndexOfMemId    uintptr
	FGetVarIndexOfMemId     uintptr
	FGetCustData            uintptr
	FGetFuncCustData        uintptr
	FGetParamCustData       uintptr
	FGetVarCustData         uintptr
	FGetImplTypeCustData    uintptr
	FGetDocumentation2      uintptr
	FGetAllCustData         uintptr
	FGetAllFuncCustData     uintptr
	FGetAllParamCustData    uintptr
	FGetAllVarCustData      uintptr
	FGetAllImplTypeCustData uintptr
}

type ITypeInfo2Vtbl = TITypeInfo2Vtbl

type TITypeInfo21 = struct {
	FlpVtbl uintptr
}

type ITypeInfo21 = TITypeInfo21

type TSYSKIND = int32

type SYSKIND = TSYSKIND

type _tagSYSKIND = int32

const _SYS_WIN16 = 0
const _SYS_WIN32 = 1
const _SYS_MAC = 2
const _SYS_WIN64 = 3

type TLIBFLAGS = int32

type LIBFLAGS = TLIBFLAGS

type _tagLIBFLAGS = int32

const _LIBFLAG_FRESTRICTED = 1
const _LIBFLAG_FCONTROL = 2
const _LIBFLAG_FHIDDEN = 4
const _LIBFLAG_FHASDISKIMAGE = 8

type TLPTYPELIB = uintptr

type LPTYPELIB = TLPTYPELIB

type TTLIBATTR = struct {
	Fguid         TGUID
	Flcid         TLCID
	Fsyskind      TSYSKIND
	FwMajorVerNum TWORD
	FwMinorVerNum TWORD
	FwLibFlags    TWORD
}

type TLIBATTR = TTLIBATTR

type TtagTLIBATTR = TTLIBATTR

type tagTLIBATTR = TtagTLIBATTR

type TLPTLIBATTR = uintptr

type LPTLIBATTR = TLPTLIBATTR

type TITypeLibVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FGetTypeInfoCount  uintptr
	FGetTypeInfo       uintptr
	FGetTypeInfoType   uintptr
	FGetTypeInfoOfGuid uintptr
	FGetLibAttr        uintptr
	FGetTypeComp       uintptr
	FGetDocumentation  uintptr
	FIsName            uintptr
	FFindName          uintptr
	FReleaseTLibAttr   uintptr
}

type ITypeLibVtbl = TITypeLibVtbl

type TITypeLib1 = struct {
	FlpVtbl uintptr
}

type ITypeLib1 = TITypeLib1

type TLPTYPELIB2 = uintptr

type LPTYPELIB2 = TLPTYPELIB2

type TITypeLib2Vtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FGetTypeInfoCount  uintptr
	FGetTypeInfo       uintptr
	FGetTypeInfoType   uintptr
	FGetTypeInfoOfGuid uintptr
	FGetLibAttr        uintptr
	FGetTypeComp       uintptr
	FGetDocumentation  uintptr
	FIsName            uintptr
	FFindName          uintptr
	FReleaseTLibAttr   uintptr
	FGetCustData       uintptr
	FGetLibStatistics  uintptr
	FGetDocumentation2 uintptr
	FGetAllCustData    uintptr
}

type ITypeLib2Vtbl = TITypeLib2Vtbl

type TITypeLib21 = struct {
	FlpVtbl uintptr
}

type ITypeLib21 = TITypeLib21

type TLPTYPECHANGEEVENTS = uintptr

type LPTYPECHANGEEVENTS = TLPTYPECHANGEEVENTS

type TCHANGEKIND = int32

type CHANGEKIND = TCHANGEKIND

type _tagCHANGEKIND = int32

const _CHANGEKIND_ADDMEMBER = 0
const _CHANGEKIND_DELETEMEMBER = 1
const _CHANGEKIND_SETNAMES = 2
const _CHANGEKIND_SETDOCUMENTATION = 3
const _CHANGEKIND_GENERAL = 4
const _CHANGEKIND_INVALIDATE = 5
const _CHANGEKIND_CHANGEFAILED = 6
const _CHANGEKIND_MAX = 7

type TITypeChangeEventsVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FRequestTypeChange uintptr
	FAfterTypeChange   uintptr
}

type ITypeChangeEventsVtbl = TITypeChangeEventsVtbl

type TITypeChangeEvents1 = struct {
	FlpVtbl uintptr
}

type ITypeChangeEvents1 = TITypeChangeEvents1

type TLPERRORINFO = uintptr

type LPERRORINFO = TLPERRORINFO

type TIErrorInfoVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetGUID        uintptr
	FGetSource      uintptr
	FGetDescription uintptr
	FGetHelpFile    uintptr
	FGetHelpContext uintptr
}

type IErrorInfoVtbl = TIErrorInfoVtbl

type TIErrorInfo1 = struct {
	FlpVtbl uintptr
}

type IErrorInfo1 = TIErrorInfo1

type TLPCREATEERRORINFO = uintptr

type LPCREATEERRORINFO = TLPCREATEERRORINFO

type TICreateErrorInfoVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSetGUID        uintptr
	FSetSource      uintptr
	FSetDescription uintptr
	FSetHelpFile    uintptr
	FSetHelpContext uintptr
}

type ICreateErrorInfoVtbl = TICreateErrorInfoVtbl

type TICreateErrorInfo1 = struct {
	FlpVtbl uintptr
}

type ICreateErrorInfo1 = TICreateErrorInfo1

type TLPSUPPORTERRORINFO = uintptr

type LPSUPPORTERRORINFO = TLPSUPPORTERRORINFO

type TISupportErrorInfoVtbl = struct {
	FQueryInterface             uintptr
	FAddRef                     uintptr
	FRelease                    uintptr
	FInterfaceSupportsErrorInfo uintptr
}

type ISupportErrorInfoVtbl = TISupportErrorInfoVtbl

type TISupportErrorInfo1 = struct {
	FlpVtbl uintptr
}

type ISupportErrorInfo1 = TISupportErrorInfo1

type TITypeFactoryVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FCreateFromTypeInfo uintptr
}

type ITypeFactoryVtbl = TITypeFactoryVtbl

type TITypeFactory1 = struct {
	FlpVtbl uintptr
}

type ITypeFactory1 = TITypeFactory1

type TITypeMarshalVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSize           uintptr
	FMarshal        uintptr
	FUnmarshal      uintptr
	FFree           uintptr
}

type ITypeMarshalVtbl = TITypeMarshalVtbl

type TITypeMarshal1 = struct {
	FlpVtbl uintptr
}

type ITypeMarshal1 = TITypeMarshal1

type TLPRECORDINFO = uintptr

type LPRECORDINFO = TLPRECORDINFO

type TIRecordInfoVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FRecordInit       uintptr
	FRecordClear      uintptr
	FRecordCopy       uintptr
	FGetGuid          uintptr
	FGetName          uintptr
	FGetSize          uintptr
	FGetTypeInfo      uintptr
	FGetField         uintptr
	FGetFieldNoCopy   uintptr
	FPutField         uintptr
	FPutFieldNoCopy   uintptr
	FGetFieldNames    uintptr
	FIsMatchingType   uintptr
	FRecordCreate     uintptr
	FRecordCreateCopy uintptr
	FRecordDestroy    uintptr
}

type IRecordInfoVtbl = TIRecordInfoVtbl

type TIRecordInfo1 = struct {
	FlpVtbl uintptr
}

type IRecordInfo1 = TIRecordInfo1

type TLPERRORLOG = uintptr

type LPERRORLOG = TLPERRORLOG

type TIErrorLogVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FAddError       uintptr
}

type IErrorLogVtbl = TIErrorLogVtbl

type TIErrorLog1 = struct {
	FlpVtbl uintptr
}

type IErrorLog1 = TIErrorLog1

type TLPPROPERTYBAG = uintptr

type LPPROPERTYBAG = TLPPROPERTYBAG

type TIPropertyBagVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FRead           uintptr
	FWrite          uintptr
}

type IPropertyBagVtbl = TIPropertyBagVtbl

type TIPropertyBag1 = struct {
	FlpVtbl uintptr
}

type IPropertyBag1 = TIPropertyBag1

type TIXMLDOMImplementation = struct {
	FlpVtbl uintptr
}

type IXMLDOMImplementation = TIXMLDOMImplementation

type TIXMLDOMNode = struct {
	FlpVtbl uintptr
}

type IXMLDOMNode = TIXMLDOMNode

type TIXMLDOMDocumentFragment = struct {
	FlpVtbl uintptr
}

type IXMLDOMDocumentFragment = TIXMLDOMDocumentFragment

type TIXMLDOMDocument = struct {
	FlpVtbl uintptr
}

type IXMLDOMDocument = TIXMLDOMDocument

type TIXMLDOMNodeList = struct {
	FlpVtbl uintptr
}

type IXMLDOMNodeList = TIXMLDOMNodeList

type TIXMLDOMNamedNodeMap = struct {
	FlpVtbl uintptr
}

type IXMLDOMNamedNodeMap = TIXMLDOMNamedNodeMap

type TIXMLDOMCharacterData = struct {
	FlpVtbl uintptr
}

type IXMLDOMCharacterData = TIXMLDOMCharacterData

type TIXMLDOMAttribute = struct {
	FlpVtbl uintptr
}

type IXMLDOMAttribute = TIXMLDOMAttribute

type TIXMLDOMElement = struct {
	FlpVtbl uintptr
}

type IXMLDOMElement = TIXMLDOMElement

type TIXMLDOMText = struct {
	FlpVtbl uintptr
}

type IXMLDOMText = TIXMLDOMText

type TIXMLDOMComment = struct {
	FlpVtbl uintptr
}

type IXMLDOMComment = TIXMLDOMComment

type TIXMLDOMProcessingInstruction = struct {
	FlpVtbl uintptr
}

type IXMLDOMProcessingInstruction = TIXMLDOMProcessingInstruction

type TIXMLDOMCDATASection = struct {
	FlpVtbl uintptr
}

type IXMLDOMCDATASection = TIXMLDOMCDATASection

type TIXMLDOMDocumentType = struct {
	FlpVtbl uintptr
}

type IXMLDOMDocumentType = TIXMLDOMDocumentType

type TIXMLDOMNotation = struct {
	FlpVtbl uintptr
}

type IXMLDOMNotation = TIXMLDOMNotation

type TIXMLDOMEntity = struct {
	FlpVtbl uintptr
}

type IXMLDOMEntity = TIXMLDOMEntity

type TIXMLDOMEntityReference = struct {
	FlpVtbl uintptr
}

type IXMLDOMEntityReference = TIXMLDOMEntityReference

type TIXMLDOMParseError = struct {
	FlpVtbl uintptr
}

type IXMLDOMParseError = TIXMLDOMParseError

type TIXTLRuntime = struct {
	FlpVtbl uintptr
}

type IXTLRuntime = TIXTLRuntime

type TXMLDOMDocumentEvents = struct {
	FlpVtbl uintptr
}

type XMLDOMDocumentEvents = TXMLDOMDocumentEvents

type TIXMLHttpRequest = struct {
	FlpVtbl uintptr
}

type IXMLHttpRequest = TIXMLHttpRequest

type TIXMLDSOControl = struct {
	FlpVtbl uintptr
}

type IXMLDSOControl = TIXMLDSOControl

type TIXMLElementCollection = struct {
	FlpVtbl uintptr
}

type IXMLElementCollection = TIXMLElementCollection

type TIXMLDocument = struct {
	FlpVtbl uintptr
}

type IXMLDocument = TIXMLDocument

type TIXMLDocument2 = struct {
	FlpVtbl uintptr
}

type IXMLDocument2 = TIXMLDocument2

type TIXMLElement = struct {
	FlpVtbl uintptr
}

type IXMLElement = TIXMLElement

type TIXMLElement2 = struct {
	FlpVtbl uintptr
}

type IXMLElement2 = TIXMLElement2

type TIXMLAttribute = struct {
	FlpVtbl uintptr
}

type IXMLAttribute = TIXMLAttribute

type TIXMLError = struct {
	FlpVtbl uintptr
}

type IXMLError = TIXMLError

type TXML_ERROR = struct {
	F_nLine       uint32
	F_pchBuf      TBSTR
	F_cchBuf      uint32
	F_ich         uint32
	F_pszFound    TBSTR
	F_pszExpected TBSTR
	F_reserved1   TDWORD
	F_reserved2   TDWORD
}

type XML_ERROR = TXML_ERROR

type T_xml_error = TXML_ERROR

type _xml_error = T_xml_error

type TDOMNodeType = int32

type DOMNodeType = TDOMNodeType

type _tagDOMNodeType = int32

const _NODE_INVALID = 0
const _NODE_ELEMENT = 1
const _NODE_ATTRIBUTE = 2
const _NODE_TEXT = 3
const _NODE_CDATA_SECTION = 4
const _NODE_ENTITY_REFERENCE = 5
const _NODE_ENTITY = 6
const _NODE_PROCESSING_INSTRUCTION = 7
const _NODE_COMMENT = 8
const _NODE_DOCUMENT = 9
const _NODE_DOCUMENT_TYPE = 10
const _NODE_DOCUMENT_FRAGMENT = 11
const _NODE_NOTATION = 12

type TXMLELEM_TYPE = int32

type XMLELEM_TYPE = TXMLELEM_TYPE

type _tagXMLEMEM_TYPE = int32

const _XMLELEMTYPE_ELEMENT = 0
const _XMLELEMTYPE_TEXT = 1
const _XMLELEMTYPE_COMMENT = 2
const _XMLELEMTYPE_DOCUMENT = 3
const _XMLELEMTYPE_DTD = 4
const _XMLELEMTYPE_PI = 5
const _XMLELEMTYPE_OTHER = 6

type TIXMLDOMImplementationVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
	FhasFeature       uintptr
}

type IXMLDOMImplementationVtbl = TIXMLDOMImplementationVtbl

type TIXMLDOMImplementation1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMImplementation1 = TIXMLDOMImplementation1

type TIXMLDOMNodeVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
}

type IXMLDOMNodeVtbl = TIXMLDOMNodeVtbl

type TIXMLDOMNode1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMNode1 = TIXMLDOMNode1

type TIXMLDOMDocumentFragmentVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
}

type IXMLDOMDocumentFragmentVtbl = TIXMLDOMDocumentFragmentVtbl

type TIXMLDOMDocumentFragment1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMDocumentFragment1 = TIXMLDOMDocumentFragment1

type TIXMLDOMDocumentVtbl = struct {
	FQueryInterface              uintptr
	FAddRef                      uintptr
	FRelease                     uintptr
	FGetTypeInfoCount            uintptr
	FGetTypeInfo                 uintptr
	FGetIDsOfNames               uintptr
	FInvoke                      uintptr
	Fget_nodeName                uintptr
	Fget_nodeValue               uintptr
	Fput_nodeValue               uintptr
	Fget_nodeType                uintptr
	Fget_parentNode              uintptr
	Fget_childNodes              uintptr
	Fget_firstChild              uintptr
	Fget_lastChild               uintptr
	Fget_previousSibling         uintptr
	Fget_nextSibling             uintptr
	Fget_attributes              uintptr
	FinsertBefore                uintptr
	FreplaceChild                uintptr
	FremoveChild                 uintptr
	FappendChild                 uintptr
	FhasChildNodes               uintptr
	Fget_ownerDocument           uintptr
	FcloneNode                   uintptr
	Fget_nodeTypeString          uintptr
	Fget_text                    uintptr
	Fput_text                    uintptr
	Fget_specified               uintptr
	Fget_definition              uintptr
	Fget_nodeTypedValue          uintptr
	Fput_nodeTypedValue          uintptr
	Fget_dataType                uintptr
	Fput_dataType                uintptr
	Fget_xml                     uintptr
	FtransformNode               uintptr
	FselectNodes                 uintptr
	FselectSingleNode            uintptr
	Fget_parsed                  uintptr
	Fget_namespaceURI            uintptr
	Fget_prefix                  uintptr
	Fget_baseName                uintptr
	FtransformNodeToObject       uintptr
	Fget_doctype                 uintptr
	Fget_implementation          uintptr
	Fget_documentElement         uintptr
	Fputref_documentElement      uintptr
	FcreateElement               uintptr
	FcreateDocumentFragment      uintptr
	FcreateTextNode              uintptr
	FcreateComment               uintptr
	FcreateCDATASection          uintptr
	FcreateProcessingInstruction uintptr
	FcreateAttribute             uintptr
	FcreateEntityReference       uintptr
	FgetElementsByTagName        uintptr
	FcreateNode                  uintptr
	FnodeFromID                  uintptr
	Fload                        uintptr
	Fget_readyState              uintptr
	Fget_parseError              uintptr
	Fget_url                     uintptr
	Fget_async                   uintptr
	Fput_async                   uintptr
	Fabort                       uintptr
	FloadXML                     uintptr
	Fsave                        uintptr
	Fget_validateOnParse         uintptr
	Fput_validateOnParse         uintptr
	Fget_resolveExternals        uintptr
	Fput_resolveExternals        uintptr
	Fget_preserveWhiteSpace      uintptr
	Fput_preserveWhiteSpace      uintptr
	Fput_onreadystatechange      uintptr
	Fput_ondataavailable         uintptr
	Fput_ontransformnode         uintptr
}

type IXMLDOMDocumentVtbl = TIXMLDOMDocumentVtbl

type TIXMLDOMDocument1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMDocument1 = TIXMLDOMDocument1

type TIXMLDOMNodeListVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
	Fget_item         uintptr
	Fget_length       uintptr
	FnextNode         uintptr
	Freset            uintptr
	Fget__newEnum     uintptr
}

type IXMLDOMNodeListVtbl = TIXMLDOMNodeListVtbl

type TIXMLDOMNodeList1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMNodeList1 = TIXMLDOMNodeList1

type TIXMLDOMNamedNodeMapVtbl = struct {
	FQueryInterface      uintptr
	FAddRef              uintptr
	FRelease             uintptr
	FGetTypeInfoCount    uintptr
	FGetTypeInfo         uintptr
	FGetIDsOfNames       uintptr
	FInvoke              uintptr
	FgetNamedItem        uintptr
	FsetNamedItem        uintptr
	FremoveNamedItem     uintptr
	Fget_item            uintptr
	Fget_length          uintptr
	FgetQualifiedItem    uintptr
	FremoveQualifiedItem uintptr
	FnextNode            uintptr
	Freset               uintptr
	Fget__newEnum        uintptr
}

type IXMLDOMNamedNodeMapVtbl = TIXMLDOMNamedNodeMapVtbl

type TIXMLDOMNamedNodeMap1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMNamedNodeMap1 = TIXMLDOMNamedNodeMap1

type TIXMLDOMCharacterDataVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_data              uintptr
	Fput_data              uintptr
	Fget_length            uintptr
	FsubstringData         uintptr
	FappendData            uintptr
	FinsertData            uintptr
	FdeleteData            uintptr
	FreplaceData           uintptr
}

type IXMLDOMCharacterDataVtbl = TIXMLDOMCharacterDataVtbl

type TIXMLDOMCharacterData1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMCharacterData1 = TIXMLDOMCharacterData1

type TIXMLDOMAttributeVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_name              uintptr
	Fget_value             uintptr
	Fput_value             uintptr
}

type IXMLDOMAttributeVtbl = TIXMLDOMAttributeVtbl

type TIXMLDOMAttribute1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMAttribute1 = TIXMLDOMAttribute1

type TIXMLDOMElementVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_tagName           uintptr
	FgetAttribute          uintptr
	FsetAttribute          uintptr
	FremoveAttribute       uintptr
	FgetAttributeNode      uintptr
	FsetAttributeNode      uintptr
	FremoveAttributeNode   uintptr
	FgetElementsByTagName  uintptr
	Fnormalize             uintptr
}

type IXMLDOMElementVtbl = TIXMLDOMElementVtbl

type TIXMLDOMElement1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMElement1 = TIXMLDOMElement1

type TIXMLDOMTextVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_data              uintptr
	Fput_data              uintptr
	Fget_length            uintptr
	FsubstringData         uintptr
	FappendData            uintptr
	FinsertData            uintptr
	FdeleteData            uintptr
	FreplaceData           uintptr
	FsplitText             uintptr
}

type IXMLDOMTextVtbl = TIXMLDOMTextVtbl

type TIXMLDOMText1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMText1 = TIXMLDOMText1

type TIXMLDOMCommentVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_data              uintptr
	Fput_data              uintptr
	Fget_length            uintptr
	FsubstringData         uintptr
	FappendData            uintptr
	FinsertData            uintptr
	FdeleteData            uintptr
	FreplaceData           uintptr
}

type IXMLDOMCommentVtbl = TIXMLDOMCommentVtbl

type TIXMLDOMComment1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMComment1 = TIXMLDOMComment1

type TIXMLDOMProcessingInstructionVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_target            uintptr
	Fget_data              uintptr
	Fput_data              uintptr
}

type IXMLDOMProcessingInstructionVtbl = TIXMLDOMProcessingInstructionVtbl

type TIXMLDOMProcessingInstruction1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMProcessingInstruction1 = TIXMLDOMProcessingInstruction1

type TIXMLDOMCDATASectionVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_data              uintptr
	Fput_data              uintptr
	Fget_length            uintptr
	FsubstringData         uintptr
	FappendData            uintptr
	FinsertData            uintptr
	FdeleteData            uintptr
	FreplaceData           uintptr
	FsplitText             uintptr
}

type IXMLDOMCDATASectionVtbl = TIXMLDOMCDATASectionVtbl

type TIXMLDOMCDATASection1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMCDATASection1 = TIXMLDOMCDATASection1

type TIXMLDOMDocumentTypeVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_name              uintptr
	Fget_entities          uintptr
	Fget_notations         uintptr
}

type IXMLDOMDocumentTypeVtbl = TIXMLDOMDocumentTypeVtbl

type TIXMLDOMDocumentType1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMDocumentType1 = TIXMLDOMDocumentType1

type TIXMLDOMNotationVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_publicId          uintptr
	Fget_systemId          uintptr
}

type IXMLDOMNotationVtbl = TIXMLDOMNotationVtbl

type TIXMLDOMNotation1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMNotation1 = TIXMLDOMNotation1

type TIXMLDOMEntityVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	Fget_publicId          uintptr
	Fget_systemId          uintptr
	Fget_notationName      uintptr
}

type IXMLDOMEntityVtbl = TIXMLDOMEntityVtbl

type TIXMLDOMEntity1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMEntity1 = TIXMLDOMEntity1

type TIXMLDOMEntityReferenceVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
}

type IXMLDOMEntityReferenceVtbl = TIXMLDOMEntityReferenceVtbl

type TIXMLDOMEntityReference1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMEntityReference1 = TIXMLDOMEntityReference1

type TIXMLDOMParseErrorVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
	Fget_errorCode    uintptr
	Fget_url          uintptr
	Fget_reason       uintptr
	Fget_srcText      uintptr
	Fget_line         uintptr
	Fget_linepos      uintptr
	Fget_filepos      uintptr
}

type IXMLDOMParseErrorVtbl = TIXMLDOMParseErrorVtbl

type TIXMLDOMParseError1 = struct {
	FlpVtbl uintptr
}

type IXMLDOMParseError1 = TIXMLDOMParseError1

type TIXTLRuntimeVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_nodeName          uintptr
	Fget_nodeValue         uintptr
	Fput_nodeValue         uintptr
	Fget_nodeType          uintptr
	Fget_parentNode        uintptr
	Fget_childNodes        uintptr
	Fget_firstChild        uintptr
	Fget_lastChild         uintptr
	Fget_previousSibling   uintptr
	Fget_nextSibling       uintptr
	Fget_attributes        uintptr
	FinsertBefore          uintptr
	FreplaceChild          uintptr
	FremoveChild           uintptr
	FappendChild           uintptr
	FhasChildNodes         uintptr
	Fget_ownerDocument     uintptr
	FcloneNode             uintptr
	Fget_nodeTypeString    uintptr
	Fget_text              uintptr
	Fput_text              uintptr
	Fget_specified         uintptr
	Fget_definition        uintptr
	Fget_nodeTypedValue    uintptr
	Fput_nodeTypedValue    uintptr
	Fget_dataType          uintptr
	Fput_dataType          uintptr
	Fget_xml               uintptr
	FtransformNode         uintptr
	FselectNodes           uintptr
	FselectSingleNode      uintptr
	Fget_parsed            uintptr
	Fget_namespaceURI      uintptr
	Fget_prefix            uintptr
	Fget_baseName          uintptr
	FtransformNodeToObject uintptr
	FuniqueID              uintptr
	Fdepth                 uintptr
	FchildNumber           uintptr
	FancestorChildNumber   uintptr
	FabsoluteChildNumber   uintptr
	FformatIndex           uintptr
	FformatNumber          uintptr
	FformatDate            uintptr
	FformatTime            uintptr
}

type IXTLRuntimeVtbl = TIXTLRuntimeVtbl

type TIXTLRuntime1 = struct {
	FlpVtbl uintptr
}

type IXTLRuntime1 = TIXTLRuntime1

type TXMLDOMDocumentEventsVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
}

type XMLDOMDocumentEventsVtbl = TXMLDOMDocumentEventsVtbl

type TXMLDOMDocumentEvents1 = struct {
	FlpVtbl uintptr
}

type XMLDOMDocumentEvents1 = TXMLDOMDocumentEvents1

type TIXMLHttpRequestVtbl = struct {
	FQueryInterface         uintptr
	FAddRef                 uintptr
	FRelease                uintptr
	FGetTypeInfoCount       uintptr
	FGetTypeInfo            uintptr
	FGetIDsOfNames          uintptr
	FInvoke                 uintptr
	Fopen                   uintptr
	FsetRequestHeader       uintptr
	FgetResponseHeader      uintptr
	FgetAllResponseHeaders  uintptr
	Fsend                   uintptr
	Fabort                  uintptr
	Fget_status             uintptr
	Fget_statusText         uintptr
	Fget_responseXML        uintptr
	Fget_responseText       uintptr
	Fget_responseBody       uintptr
	Fget_responseStream     uintptr
	Fget_readyState         uintptr
	Fput_onreadystatechange uintptr
}

type IXMLHttpRequestVtbl = TIXMLHttpRequestVtbl

type TIXMLHttpRequest1 = struct {
	FlpVtbl uintptr
}

type IXMLHttpRequest1 = TIXMLHttpRequest1

type TIXMLDSOControlVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetTypeInfoCount      uintptr
	FGetTypeInfo           uintptr
	FGetIDsOfNames         uintptr
	FInvoke                uintptr
	Fget_XMLDocument       uintptr
	Fput_XMLDocument       uintptr
	Fget_JavaDSOCompatible uintptr
	Fput_JavaDSOCompatible uintptr
	Fget_readyState        uintptr
}

type IXMLDSOControlVtbl = TIXMLDSOControlVtbl

type TIXMLDSOControl1 = struct {
	FlpVtbl uintptr
}

type IXMLDSOControl1 = TIXMLDSOControl1

type TIXMLElementCollectionVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
	Fput_length       uintptr
	Fget_length       uintptr
	Fget__newEnum     uintptr
	Fitem             uintptr
}

type IXMLElementCollectionVtbl = TIXMLElementCollectionVtbl

type TIXMLElementCollection1 = struct {
	FlpVtbl uintptr
}

type IXMLElementCollection1 = TIXMLElementCollection1

type TIXMLDocumentVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetTypeInfoCount     uintptr
	FGetTypeInfo          uintptr
	FGetIDsOfNames        uintptr
	FInvoke               uintptr
	Fget_root             uintptr
	Fget_fileSize         uintptr
	Fget_fileModifiedDate uintptr
	Fget_fileUpdatedDate  uintptr
	Fget_URL              uintptr
	Fput_URL              uintptr
	Fget_mimeType         uintptr
	Fget_readyState       uintptr
	Fget_charset          uintptr
	Fput_charset          uintptr
	Fget_version          uintptr
	Fget_doctype          uintptr
	Fget_dtdURL           uintptr
	FcreateElement        uintptr
}

type IXMLDocumentVtbl = TIXMLDocumentVtbl

type TIXMLDocument1 = struct {
	FlpVtbl uintptr
}

type IXMLDocument1 = TIXMLDocument1

type TIXMLDocument2Vtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetTypeInfoCount     uintptr
	FGetTypeInfo          uintptr
	FGetIDsOfNames        uintptr
	FInvoke               uintptr
	Fget_root             uintptr
	Fget_fileSize         uintptr
	Fget_fileModifiedDate uintptr
	Fget_fileUpdatedDate  uintptr
	Fget_URL              uintptr
	Fput_URL              uintptr
	Fget_mimeType         uintptr
	Fget_readyState       uintptr
	Fget_charset          uintptr
	Fput_charset          uintptr
	Fget_version          uintptr
	Fget_doctype          uintptr
	Fget_dtdURL           uintptr
	FcreateElement        uintptr
	Fget_async            uintptr
	Fput_async            uintptr
}

type IXMLDocument2Vtbl = TIXMLDocument2Vtbl

type TIXMLDocument21 = struct {
	FlpVtbl uintptr
}

type IXMLDocument21 = TIXMLDocument21

type TIXMLElementVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
	Fget_tagName      uintptr
	Fput_tagName      uintptr
	Fget_parent       uintptr
	FsetAttribute     uintptr
	FgetAttribute     uintptr
	FremoveAttribute  uintptr
	Fget_children     uintptr
	Fget_type         uintptr
	Fget_text         uintptr
	Fput_text         uintptr
	FaddChild         uintptr
	FremoveChild      uintptr
}

type IXMLElementVtbl = TIXMLElementVtbl

type TIXMLElement1 = struct {
	FlpVtbl uintptr
}

type IXMLElement1 = TIXMLElement1

type TIXMLElement2Vtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
	Fget_tagName      uintptr
	Fput_tagName      uintptr
	Fget_parent       uintptr
	FsetAttribute     uintptr
	FgetAttribute     uintptr
	FremoveAttribute  uintptr
	Fget_children     uintptr
	Fget_type         uintptr
	Fget_text         uintptr
	Fput_text         uintptr
	FaddChild         uintptr
	FremoveChild      uintptr
	Fget_attributes   uintptr
}

type IXMLElement2Vtbl = TIXMLElement2Vtbl

type TIXMLElement21 = struct {
	FlpVtbl uintptr
}

type IXMLElement21 = TIXMLElement21

type TIXMLAttributeVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FGetTypeInfoCount uintptr
	FGetTypeInfo      uintptr
	FGetIDsOfNames    uintptr
	FInvoke           uintptr
	Fget_name         uintptr
	Fget_value        uintptr
}

type IXMLAttributeVtbl = TIXMLAttributeVtbl

type TIXMLAttribute1 = struct {
	FlpVtbl uintptr
}

type IXMLAttribute1 = TIXMLAttribute1

type TIXMLErrorVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetErrorInfo   uintptr
}

type IXMLErrorVtbl = TIXMLErrorVtbl

type TIXMLError1 = struct {
	FlpVtbl uintptr
}

type IXMLError1 = TIXMLError1

type TLPPERSISTMONIKER = uintptr

type LPPERSISTMONIKER = TLPPERSISTMONIKER

type TIPersistMonikerVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetClassID     uintptr
	FIsDirty        uintptr
	FLoad           uintptr
	FSave           uintptr
	FSaveCompleted  uintptr
	FGetCurMoniker  uintptr
}

type IPersistMonikerVtbl = TIPersistMonikerVtbl

type TIPersistMoniker1 = struct {
	FlpVtbl uintptr
}

type IPersistMoniker1 = TIPersistMoniker1

type TLPMONIKERPROP = uintptr

type LPMONIKERPROP = TLPMONIKERPROP

type TMONIKERPROPERTY = int32

type MONIKERPROPERTY = TMONIKERPROPERTY

type ___WIDL_urlmon_generated_name_0000000F = int32

const _MIMETYPEPROP = 0
const _USE_SRC_URL = 1
const _CLASSIDPROP = 2
const _TRUSTEDDOWNLOADPROP = 3
const _POPUPLEVELPROP = 4

type TIMonikerPropVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FPutProperty    uintptr
}

type IMonikerPropVtbl = TIMonikerPropVtbl

type TIMonikerProp1 = struct {
	FlpVtbl uintptr
}

type IMonikerProp1 = TIMonikerProp1

type TLPBINDPROTOCOL = uintptr

type LPBINDPROTOCOL = TLPBINDPROTOCOL

type TIBindProtocolVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCreateBinding  uintptr
}

type IBindProtocolVtbl = TIBindProtocolVtbl

type TIBindProtocol1 = struct {
	FlpVtbl uintptr
}

type IBindProtocol1 = TIBindProtocol1

type TLPBINDING = uintptr

type LPBINDING = TLPBINDING

type TIBindingVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FAbort          uintptr
	FSuspend        uintptr
	FResume         uintptr
	FSetPriority    uintptr
	FGetPriority    uintptr
	FGetBindResult  uintptr
}

type IBindingVtbl = TIBindingVtbl

type TIBinding1 = struct {
	FlpVtbl uintptr
}

type IBinding1 = TIBinding1

type TLPBINDSTATUSCALLBACK = uintptr

type LPBINDSTATUSCALLBACK = TLPBINDSTATUSCALLBACK

type TBINDVERB = int32

type BINDVERB = TBINDVERB

type ___WIDL_urlmon_generated_name_00000010 = int32

const _BINDVERB_GET = 0
const _BINDVERB_POST = 1
const _BINDVERB_PUT = 2
const _BINDVERB_CUSTOM = 3
const _BINDVERB_RESERVED1 = 4

type TBINDINFOF = int32

type BINDINFOF = TBINDINFOF

type ___WIDL_urlmon_generated_name_00000011 = int32

const _BINDINFOF_URLENCODESTGMEDDATA = 1
const _BINDINFOF_URLENCODEDEXTRAINFO = 2

type TBINDF = uint32

type BINDF = TBINDF

type ___WIDL_urlmon_generated_name_00000012 = uint32

const _BINDF_ASYNCHRONOUS = 1
const _BINDF_ASYNCSTORAGE = 2
const _BINDF_NOPROGRESSIVERENDERING = 4
const _BINDF_OFFLINEOPERATION = 8
const _BINDF_GETNEWESTVERSION = 16
const _BINDF_NOWRITECACHE = 32
const _BINDF_NEEDFILE = 64
const _BINDF_PULLDATA = 128
const _BINDF_IGNORESECURITYPROBLEM = 256
const _BINDF_RESYNCHRONIZE = 512
const _BINDF_HYPERLINK = 1024
const _BINDF_NO_UI = 2048
const _BINDF_SILENTOPERATION = 4096
const _BINDF_PRAGMA_NO_CACHE = 8192
const _BINDF_GETCLASSOBJECT = 16384
const _BINDF_RESERVED_1 = 32768
const _BINDF_FREE_THREADED = 65536
const _BINDF_DIRECT_READ = 131072
const _BINDF_FORMS_SUBMIT = 262144
const _BINDF_GETFROMCACHE_IF_NET_FAIL = 524288
const _BINDF_FROMURLMON = 1048576
const _BINDF_FWD_BACK = 2097152
const _BINDF_PREFERDEFAULTHANDLER = 4194304
const _BINDF_ENFORCERESTRICTED = 8388608
const _BINDF_RESERVED_2 = 2147483648
const _BINDF_RESERVED_3 = 16777216
const _BINDF_RESERVED_4 = 33554432
const _BINDF_RESERVED_5 = 67108864
const _BINDF_RESERVED_6 = 134217728
const _BINDF_RESERVED_7 = 1073741824
const _BINDF_RESERVED_8 = 536870912

type TURL_ENCODING = int32

type URL_ENCODING = TURL_ENCODING

type ___WIDL_urlmon_generated_name_00000013 = int32

const _URL_ENCODING_NONE = 0
const _URL_ENCODING_ENABLE_UTF8 = 268435456
const _URL_ENCODING_DISABLE_UTF8 = 536870912

type TBINDINFO = struct {
	FcbSize             TULONG
	FszExtraInfo        TLPWSTR
	FstgmedData         TSTGMEDIUM
	FgrfBindInfoF       TDWORD
	FdwBindVerb         TDWORD
	FszCustomVerb       TLPWSTR
	FcbstgmedData       TDWORD
	FdwOptions          TDWORD
	FdwOptionsFlags     TDWORD
	FdwCodePage         TDWORD
	FsecurityAttributes TSECURITY_ATTRIBUTES
	Fiid                TIID
	FpUnk               uintptr
	FdwReserved         TDWORD
}

type BINDINFO = TBINDINFO

type T_tagBINDINFO = TBINDINFO

type _tagBINDINFO = T_tagBINDINFO

type TREMSECURITY_ATTRIBUTES = struct {
	FnLength              TDWORD
	FlpSecurityDescriptor TDWORD
	FbInheritHandle       TWINBOOL
}

type REMSECURITY_ATTRIBUTES = TREMSECURITY_ATTRIBUTES

type T_REMSECURITY_ATTRIBUTES = TREMSECURITY_ATTRIBUTES

type _REMSECURITY_ATTRIBUTES = T_REMSECURITY_ATTRIBUTES

type TPREMSECURITY_ATTRIBUTES = uintptr

type PREMSECURITY_ATTRIBUTES = TPREMSECURITY_ATTRIBUTES

type TLPREMSECURITY_ATTRIBUTES = uintptr

type LPREMSECURITY_ATTRIBUTES = TLPREMSECURITY_ATTRIBUTES

type TRemBINDINFO = struct {
	FcbSize             TULONG
	FszExtraInfo        TLPWSTR
	FgrfBindInfoF       TDWORD
	FdwBindVerb         TDWORD
	FszCustomVerb       TLPWSTR
	FcbstgmedData       TDWORD
	FdwOptions          TDWORD
	FdwOptionsFlags     TDWORD
	FdwCodePage         TDWORD
	FsecurityAttributes TREMSECURITY_ATTRIBUTES
	Fiid                TIID
	FpUnk               uintptr
	FdwReserved         TDWORD
}

type RemBINDINFO = TRemBINDINFO

type T_tagRemBINDINFO = TRemBINDINFO

type _tagRemBINDINFO = T_tagRemBINDINFO

type TRemFORMATETC = struct {
	FcfFormat TDWORD
	Fptd      TDWORD
	FdwAspect TDWORD
	Flindex   TLONG
	Ftymed    TDWORD
}

type RemFORMATETC = TRemFORMATETC

type TtagRemFORMATETC = TRemFORMATETC

type tagRemFORMATETC = TtagRemFORMATETC

type TLPREMFORMATETC = uintptr

type LPREMFORMATETC = TLPREMFORMATETC

type TBINDINFO_OPTIONS = int32

type BINDINFO_OPTIONS = TBINDINFO_OPTIONS

type ___WIDL_urlmon_generated_name_00000014 = int32

const _BINDINFO_OPTIONS_WININETFLAG = 65536
const _BINDINFO_OPTIONS_ENABLE_UTF8 = 131072
const _BINDINFO_OPTIONS_DISABLE_UTF8 = 262144
const _BINDINFO_OPTIONS_USE_IE_ENCODING = 524288
const _BINDINFO_OPTIONS_BINDTOOBJECT = 1048576
const _BINDINFO_OPTIONS_SECURITYOPTOUT = 2097152
const _BINDINFO_OPTIONS_IGNOREMIMETEXTPLAIN = 4194304
const _BINDINFO_OPTIONS_USEBINDSTRINGCREDS = 8388608
const _BINDINFO_OPTIONS_IGNOREHTTPHTTPSREDIRECTS = 16777216
const _BINDINFO_OPTIONS_IGNORE_SSLERRORS_ONCE = 33554432
const _BINDINFO_WPC_DOWNLOADBLOCKED = 134217728
const _BINDINFO_WPC_LOGGING_ENABLED = 268435456
const _BINDINFO_OPTIONS_ALLOWCONNECTDATA = 536870912
const _BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS = 1073741824
const _BINDINFO_OPTIONS_SHDOCVW_NAVIGATE = -2147483648

type TBSCF = int32

type BSCF = TBSCF

type ___WIDL_urlmon_generated_name_00000015 = int32

const _BSCF_FIRSTDATANOTIFICATION = 1
const _BSCF_INTERMEDIATEDATANOTIFICATION = 2
const _BSCF_LASTDATANOTIFICATION = 4
const _BSCF_DATAFULLYAVAILABLE = 8
const _BSCF_AVAILABLEDATASIZEUNKNOWN = 16
const _BSCF_SKIPDRAINDATAFORFILEURLS = 32
const _BSCF_64BITLENGTHDOWNLOAD = 64

type TBINDSTATUS = int32

type BINDSTATUS = TBINDSTATUS

type _tagBINDSTATUS = int32

const _BINDSTATUS_FINDINGRESOURCE = 1
const _BINDSTATUS_CONNECTING = 2
const _BINDSTATUS_REDIRECTING = 3
const _BINDSTATUS_BEGINDOWNLOADDATA = 4
const _BINDSTATUS_DOWNLOADINGDATA = 5
const _BINDSTATUS_ENDDOWNLOADDATA = 6
const _BINDSTATUS_BEGINDOWNLOADCOMPONENTS = 7
const _BINDSTATUS_INSTALLINGCOMPONENTS = 8
const _BINDSTATUS_ENDDOWNLOADCOMPONENTS = 9
const _BINDSTATUS_USINGCACHEDCOPY = 10
const _BINDSTATUS_SENDINGREQUEST = 11
const _BINDSTATUS_CLASSIDAVAILABLE = 12
const _BINDSTATUS_MIMETYPEAVAILABLE = 13
const _BINDSTATUS_CACHEFILENAMEAVAILABLE = 14
const _BINDSTATUS_BEGINSYNCOPERATION = 15
const _BINDSTATUS_ENDSYNCOPERATION = 16
const _BINDSTATUS_BEGINUPLOADDATA = 17
const _BINDSTATUS_UPLOADINGDATA = 18
const _BINDSTATUS_ENDUPLOADDATA = 19
const _BINDSTATUS_PROTOCOLCLASSID = 20
const _BINDSTATUS_ENCODING = 21
const _BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE = 22
const _BINDSTATUS_CLASSINSTALLLOCATION = 23
const _BINDSTATUS_DECODING = 24
const _BINDSTATUS_LOADINGMIMEHANDLER = 25
const _BINDSTATUS_CONTENTDISPOSITIONATTACH = 26
const _BINDSTATUS_FILTERREPORTMIMETYPE = 27
const _BINDSTATUS_CLSIDCANINSTANTIATE = 28
const _BINDSTATUS_IUNKNOWNAVAILABLE = 29
const _BINDSTATUS_DIRECTBIND = 30
const _BINDSTATUS_RAWMIMETYPE = 31
const _BINDSTATUS_PROXYDETECTING = 32
const _BINDSTATUS_ACCEPTRANGES = 33
const _BINDSTATUS_COOKIE_SENT = 34
const _BINDSTATUS_COMPACT_POLICY_RECEIVED = 35
const _BINDSTATUS_COOKIE_SUPPRESSED = 36
const _BINDSTATUS_COOKIE_STATE_UNKNOWN = 37
const _BINDSTATUS_COOKIE_STATE_ACCEPT = 38
const _BINDSTATUS_COOKIE_STATE_REJECT = 39
const _BINDSTATUS_COOKIE_STATE_PROMPT = 40
const _BINDSTATUS_COOKIE_STATE_LEASH = 41
const _BINDSTATUS_COOKIE_STATE_DOWNGRADE = 42
const _BINDSTATUS_POLICY_HREF = 43
const _BINDSTATUS_P3P_HEADER = 44
const _BINDSTATUS_SESSION_COOKIE_RECEIVED = 45
const _BINDSTATUS_PERSISTENT_COOKIE_RECEIVED = 46
const _BINDSTATUS_SESSION_COOKIES_ALLOWED = 47
const _BINDSTATUS_CACHECONTROL = 48
const _BINDSTATUS_CONTENTDISPOSITIONFILENAME = 49
const _BINDSTATUS_MIMETEXTPLAINMISMATCH = 50
const _BINDSTATUS_PUBLISHERAVAILABLE = 51
const _BINDSTATUS_DISPLAYNAMEAVAILABLE = 52
const _BINDSTATUS_SSLUX_NAVBLOCKED = 53
const _BINDSTATUS_SERVER_MIMETYPEAVAILABLE = 54
const _BINDSTATUS_SNIFFED_CLASSIDAVAILABLE = 55
const _BINDSTATUS_64BIT_PROGRESS = 56
const _BINDSTATUS_LAST = 56
const _BINDSTATUS_RESERVED_0 = 57
const _BINDSTATUS_RESERVED_1 = 58
const _BINDSTATUS_RESERVED_2 = 59
const _BINDSTATUS_RESERVED_3 = 60
const _BINDSTATUS_RESERVED_4 = 61
const _BINDSTATUS_RESERVED_5 = 62
const _BINDSTATUS_RESERVED_6 = 63
const _BINDSTATUS_RESERVED_7 = 64
const _BINDSTATUS_RESERVED_8 = 65
const _BINDSTATUS_RESERVED_9 = 66
const _BINDSTATUS_LAST_PRIVATE = 66

type TIBindStatusCallbackVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FOnStartBinding    uintptr
	FGetPriority       uintptr
	FOnLowResource     uintptr
	FOnProgress        uintptr
	FOnStopBinding     uintptr
	FGetBindInfo       uintptr
	FOnDataAvailable   uintptr
	FOnObjectAvailable uintptr
}

type IBindStatusCallbackVtbl = TIBindStatusCallbackVtbl

type TIBindStatusCallback1 = struct {
	FlpVtbl uintptr
}

type IBindStatusCallback1 = TIBindStatusCallback1

type TLPBINDSTATUSCALLBACKEX = uintptr

type LPBINDSTATUSCALLBACKEX = TLPBINDSTATUSCALLBACKEX

type TBINDF2 = uint32

type BINDF2 = TBINDF2

type ___WIDL_urlmon_generated_name_00000016 = uint32

const _BINDF2_DISABLEBASICOVERHTTP = 1
const _BINDF2_DISABLEAUTOCOOKIEHANDLING = 2
const _BINDF2_READ_DATA_GREATER_THAN_4GB = 4
const _BINDF2_DISABLE_HTTP_REDIRECT_XSECURITYID = 8
const _BINDF2_SETDOWNLOADMODE = 32
const _BINDF2_DISABLE_HTTP_REDIRECT_CACHING = 64
const _BINDF2_KEEP_CALLBACK_MODULE_LOADED = 128
const _BINDF2_ALLOW_PROXY_CRED_PROMPT = 256
const _BINDF2_RESERVED_F = 131072
const _BINDF2_RESERVED_E = 262144
const _BINDF2_RESERVED_D = 524288
const _BINDF2_RESERVED_C = 1048576
const _BINDF2_RESERVED_B = 2097152
const _BINDF2_RESERVED_A = 4194304
const _BINDF2_RESERVED_9 = 8388608
const _BINDF2_RESERVED_8 = 16777216
const _BINDF2_RESERVED_7 = 33554432
const _BINDF2_RESERVED_6 = 67108864
const _BINDF2_RESERVED_5 = 134217728
const _BINDF2_RESERVED_4 = 268435456
const _BINDF2_RESERVED_3 = 536870912
const _BINDF2_RESERVED_2 = 1073741824
const _BINDF2_RESERVED_1 = 2147483648

type TIBindStatusCallbackExVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FOnStartBinding    uintptr
	FGetPriority       uintptr
	FOnLowResource     uintptr
	FOnProgress        uintptr
	FOnStopBinding     uintptr
	FGetBindInfo       uintptr
	FOnDataAvailable   uintptr
	FOnObjectAvailable uintptr
	FGetBindInfoEx     uintptr
}

type IBindStatusCallbackExVtbl = TIBindStatusCallbackExVtbl

type TIBindStatusCallbackEx1 = struct {
	FlpVtbl uintptr
}

type IBindStatusCallbackEx1 = TIBindStatusCallbackEx1

type TLPAUTHENTICATION = uintptr

type LPAUTHENTICATION = TLPAUTHENTICATION

type TIAuthenticateVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FAuthenticate   uintptr
}

type IAuthenticateVtbl = TIAuthenticateVtbl

type TIAuthenticate1 = struct {
	FlpVtbl uintptr
}

type IAuthenticate1 = TIAuthenticate1

type TLPAUTHENTICATIONEX = uintptr

type LPAUTHENTICATIONEX = TLPAUTHENTICATIONEX

type TAUTHENTICATEF = int32

type AUTHENTICATEF = TAUTHENTICATEF

type ___WIDL_urlmon_generated_name_00000017 = int32

const _AUTHENTICATEF_PROXY = 1
const _AUTHENTICATEF_BASIC = 2
const _AUTHENTICATEF_HTTP = 4

type TAUTHENTICATEINFO = struct {
	FdwFlags    TDWORD
	FdwReserved TDWORD
}

type AUTHENTICATEINFO = TAUTHENTICATEINFO

type T_tagAUTHENTICATEINFO = TAUTHENTICATEINFO

type _tagAUTHENTICATEINFO = T_tagAUTHENTICATEINFO

type TIAuthenticateExVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FAuthenticate   uintptr
	FAuthenticateEx uintptr
}

type IAuthenticateExVtbl = TIAuthenticateExVtbl

type TIAuthenticateEx1 = struct {
	FlpVtbl uintptr
}

type IAuthenticateEx1 = TIAuthenticateEx1

type TLPHTTPNEGOTIATE = uintptr

type LPHTTPNEGOTIATE = TLPHTTPNEGOTIATE

type TIHttpNegotiateVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FBeginningTransaction uintptr
	FOnResponse           uintptr
}

type IHttpNegotiateVtbl = TIHttpNegotiateVtbl

type TIHttpNegotiate1 = struct {
	FlpVtbl uintptr
}

type IHttpNegotiate1 = TIHttpNegotiate1

type TLPHTTPNEGOTIATE2 = uintptr

type LPHTTPNEGOTIATE2 = TLPHTTPNEGOTIATE2

type TIHttpNegotiate2Vtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FBeginningTransaction uintptr
	FOnResponse           uintptr
	FGetRootSecurityId    uintptr
}

type IHttpNegotiate2Vtbl = TIHttpNegotiate2Vtbl

type TIHttpNegotiate21 = struct {
	FlpVtbl uintptr
}

type IHttpNegotiate21 = TIHttpNegotiate21

type TLPHTTPNEGOTIATE3 = uintptr

type LPHTTPNEGOTIATE3 = TLPHTTPNEGOTIATE3

type TIHttpNegotiate3Vtbl = struct {
	FQueryInterface                 uintptr
	FAddRef                         uintptr
	FRelease                        uintptr
	FBeginningTransaction           uintptr
	FOnResponse                     uintptr
	FGetRootSecurityId              uintptr
	FGetSerializedClientCertContext uintptr
}

type IHttpNegotiate3Vtbl = TIHttpNegotiate3Vtbl

type TIHttpNegotiate31 = struct {
	FlpVtbl uintptr
}

type IHttpNegotiate31 = TIHttpNegotiate31

type TLPWININETFILESTREAM = uintptr

type LPWININETFILESTREAM = TLPWININETFILESTREAM

type TIWinInetFileStreamVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FSetHandleForUnlock uintptr
	FSetDeleteFile      uintptr
}

type IWinInetFileStreamVtbl = TIWinInetFileStreamVtbl

type TIWinInetFileStream1 = struct {
	FlpVtbl uintptr
}

type IWinInetFileStream1 = TIWinInetFileStream1

type TLPWINDOWFORBINDINGUI = uintptr

type LPWINDOWFORBINDINGUI = TLPWINDOWFORBINDINGUI

type TIWindowForBindingUIVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetWindow      uintptr
}

type IWindowForBindingUIVtbl = TIWindowForBindingUIVtbl

type TIWindowForBindingUI1 = struct {
	FlpVtbl uintptr
}

type IWindowForBindingUI1 = TIWindowForBindingUI1

type TLPCODEINSTALL = uintptr

type LPCODEINSTALL = TLPCODEINSTALL

type TCIP_STATUS = int32

type CIP_STATUS = TCIP_STATUS

type ___WIDL_urlmon_generated_name_00000018 = int32

const _CIP_DISK_FULL = 0
const _CIP_ACCESS_DENIED = 1
const _CIP_NEWER_VERSION_EXISTS = 2
const _CIP_OLDER_VERSION_EXISTS = 3
const _CIP_NAME_CONFLICT = 4
const _CIP_TRUST_VERIFICATION_COMPONENT_MISSING = 5
const _CIP_EXE_SELF_REGISTERATION_TIMEOUT = 6
const _CIP_UNSAFE_TO_ABORT = 7
const _CIP_NEED_REBOOT = 8
const _CIP_NEED_REBOOT_UI_PERMISSION = 9

type TICodeInstallVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FGetWindow            uintptr
	FOnCodeInstallProblem uintptr
}

type ICodeInstallVtbl = TICodeInstallVtbl

type TICodeInstall1 = struct {
	FlpVtbl uintptr
}

type ICodeInstall1 = TICodeInstall1

type TUri_PROPERTY = int32

type Uri_PROPERTY = TUri_PROPERTY

type ___WIDL_urlmon_generated_name_00000019 = int32

const _Uri_PROPERTY_ABSOLUTE_URI = 0
const _Uri_PROPERTY_STRING_START = 0
const _Uri_PROPERTY_AUTHORITY = 1
const _Uri_PROPERTY_DISPLAY_URI = 2
const _Uri_PROPERTY_DOMAIN = 3
const _Uri_PROPERTY_EXTENSION = 4
const _Uri_PROPERTY_FRAGMENT = 5
const _Uri_PROPERTY_HOST = 6
const _Uri_PROPERTY_PASSWORD = 7
const _Uri_PROPERTY_PATH = 8
const _Uri_PROPERTY_PATH_AND_QUERY = 9
const _Uri_PROPERTY_QUERY = 10
const _Uri_PROPERTY_RAW_URI = 11
const _Uri_PROPERTY_SCHEME_NAME = 12
const _Uri_PROPERTY_USER_INFO = 13
const _Uri_PROPERTY_USER_NAME = 14
const _Uri_PROPERTY_STRING_LAST = 14
const _Uri_PROPERTY_HOST_TYPE = 15
const _Uri_PROPERTY_DWORD_START = 15
const _Uri_PROPERTY_PORT = 16
const _Uri_PROPERTY_SCHEME = 17
const _Uri_PROPERTY_ZONE = 18
const _Uri_PROPERTY_DWORD_LAST = 18

type TUri_HOST_TYPE = int32

type Uri_HOST_TYPE = TUri_HOST_TYPE

type ___WIDL_urlmon_generated_name_0000001A = int32

const _Uri_HOST_UNKNOWN = 0
const _Uri_HOST_DNS = 1
const _Uri_HOST_IPV4 = 2
const _Uri_HOST_IPV6 = 3
const _Uri_HOST_IDN = 4

type TIUriVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FGetPropertyBSTR   uintptr
	FGetPropertyLength uintptr
	FGetPropertyDWORD  uintptr
	FHasProperty       uintptr
	FGetAbsoluteUri    uintptr
	FGetAuthority      uintptr
	FGetDisplayUri     uintptr
	FGetDomain         uintptr
	FGetExtension      uintptr
	FGetFragment       uintptr
	FGetHost           uintptr
	FGetPassword       uintptr
	FGetPath           uintptr
	FGetPathAndQuery   uintptr
	FGetQuery          uintptr
	FGetRawUri         uintptr
	FGetSchemeName     uintptr
	FGetUserInfo       uintptr
	FGetUserNameA      uintptr
	FGetHostType       uintptr
	FGetPort           uintptr
	FGetScheme         uintptr
	FGetZone           uintptr
	FGetProperties     uintptr
	FIsEqual           uintptr
}

type IUriVtbl = TIUriVtbl

type TIUri1 = struct {
	FlpVtbl uintptr
}

type IUri1 = TIUri1

type TIUriContainerVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetIUri        uintptr
}

type IUriContainerVtbl = TIUriContainerVtbl

type TIUriContainer1 = struct {
	FlpVtbl uintptr
}

type IUriContainer1 = TIUriContainer1

type TIUriBuilderVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FCreateUriSimple    uintptr
	FCreateUri          uintptr
	FCreateUriWithFlags uintptr
	FGetIUri            uintptr
	FSetIUri            uintptr
	FGetFragment        uintptr
	FGetHost            uintptr
	FGetPassword        uintptr
	FGetPath            uintptr
	FGetPort            uintptr
	FGetQuery           uintptr
	FGetSchemeName      uintptr
	FGetUserNameA       uintptr
	FSetFragment        uintptr
	FSetHost            uintptr
	FSetPassword        uintptr
	FSetPath            uintptr
	FSetPort            uintptr
	FSetQuery           uintptr
	FSetSchemeName      uintptr
	FSetUserName        uintptr
	FRemoveProperties   uintptr
	FHasBeenModified    uintptr
}

type IUriBuilderVtbl = TIUriBuilderVtbl

type TIUriBuilder1 = struct {
	FlpVtbl uintptr
}

type IUriBuilder1 = TIUriBuilder1

type TIUriBuilderFactoryVtbl = struct {
	FQueryInterface               uintptr
	FAddRef                       uintptr
	FRelease                      uintptr
	FCreateIUriBuilder            uintptr
	FCreateInitializedIUriBuilder uintptr
}

type IUriBuilderFactoryVtbl = TIUriBuilderFactoryVtbl

type TIUriBuilderFactory1 = struct {
	FlpVtbl uintptr
}

type IUriBuilderFactory1 = TIUriBuilderFactory1

type TLPWININETINFO = uintptr

type LPWININETINFO = TLPWININETINFO

type TIWinInetInfoVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FQueryOption    uintptr
}

type IWinInetInfoVtbl = TIWinInetInfoVtbl

type TIWinInetInfo1 = struct {
	FlpVtbl uintptr
}

type IWinInetInfo1 = TIWinInetInfo1

type TLPHTTPSECURITY = uintptr

type LPHTTPSECURITY = TLPHTTPSECURITY

type TIHttpSecurityVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FGetWindow         uintptr
	FOnSecurityProblem uintptr
}

type IHttpSecurityVtbl = TIHttpSecurityVtbl

type TIHttpSecurity1 = struct {
	FlpVtbl uintptr
}

type IHttpSecurity1 = TIHttpSecurity1

type TLPWININETHTTPINFO = uintptr

type LPWININETHTTPINFO = TLPWININETHTTPINFO

type TIWinInetHttpInfoVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FQueryOption    uintptr
	FQueryInfo      uintptr
}

type IWinInetHttpInfoVtbl = TIWinInetHttpInfoVtbl

type TIWinInetHttpInfo1 = struct {
	FlpVtbl uintptr
}

type IWinInetHttpInfo1 = TIWinInetHttpInfo1

type TIWinInetHttpTimeoutsVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FGetRequestTimeouts uintptr
}

type IWinInetHttpTimeoutsVtbl = TIWinInetHttpTimeoutsVtbl

type TIWinInetHttpTimeouts1 = struct {
	FlpVtbl uintptr
}

type IWinInetHttpTimeouts1 = TIWinInetHttpTimeouts1

type TLPWININETCACHEHINTS = uintptr

type LPWININETCACHEHINTS = TLPWININETCACHEHINTS

type TIWinInetCacheHintsVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FSetCacheExtension uintptr
}

type IWinInetCacheHintsVtbl = TIWinInetCacheHintsVtbl

type TIWinInetCacheHints1 = struct {
	FlpVtbl uintptr
}

type IWinInetCacheHints1 = TIWinInetCacheHints1

type TLPWININETCACHEHINTS2 = uintptr

type LPWININETCACHEHINTS2 = TLPWININETCACHEHINTS2

type TIWinInetCacheHints2Vtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FSetCacheExtension  uintptr
	FSetCacheExtension2 uintptr
}

type IWinInetCacheHints2Vtbl = TIWinInetCacheHints2Vtbl

type TIWinInetCacheHints21 = struct {
	FlpVtbl uintptr
}

type IWinInetCacheHints21 = TIWinInetCacheHints21

type TLPBINDHOST = uintptr

type LPBINDHOST = TLPBINDHOST

type TIBindHostVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FCreateMoniker        uintptr
	FMonikerBindToStorage uintptr
	FMonikerBindToObject  uintptr
}

type IBindHostVtbl = TIBindHostVtbl

type TIBindHost1 = struct {
	FlpVtbl uintptr
}

type IBindHost1 = TIBindHost1

type TLPIINTERNET = uintptr

type LPIINTERNET = TLPIINTERNET

type TIInternetVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
}

type IInternetVtbl = TIInternetVtbl

type TIInternet1 = struct {
	FlpVtbl uintptr
}

type IInternet1 = TIInternet1

type TLPIINTERNETBINDINFO = uintptr

type LPIINTERNETBINDINFO = TLPIINTERNETBINDINFO

type TBINDSTRING = int32

type BINDSTRING = TBINDSTRING

type _tagBINDSTRING = int32

const _BINDSTRING_HEADERS = 1
const _BINDSTRING_ACCEPT_MIMES = 2
const _BINDSTRING_EXTRA_URL = 3
const _BINDSTRING_LANGUAGE = 4
const _BINDSTRING_USERNAME = 5
const _BINDSTRING_PASSWORD = 6
const _BINDSTRING_UA_PIXELS = 7
const _BINDSTRING_UA_COLOR = 8
const _BINDSTRING_OS = 9
const _BINDSTRING_USER_AGENT = 10
const _BINDSTRING_ACCEPT_ENCODINGS = 11
const _BINDSTRING_POST_COOKIE = 12
const _BINDSTRING_POST_DATA_MIME = 13
const _BINDSTRING_URL = 14
const _BINDSTRING_IID = 15
const _BINDSTRING_FLAG_BIND_TO_OBJECT = 16
const _BINDSTRING_PTR_BIND_CONTEXT = 17
const _BINDSTRING_XDR_ORIGIN = 18
const _BINDSTRING_DOWNLOADPATH = 19
const _BINDSTRING_ROOTDOC_URL = 20
const _BINDSTRING_INITIAL_FILENAME = 21
const _BINDSTRING_PROXY_USERNAME = 22
const _BINDSTRING_PROXY_PASSWORD = 23

type TIInternetBindInfoVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetBindInfo    uintptr
	FGetBindString  uintptr
}

type IInternetBindInfoVtbl = TIInternetBindInfoVtbl

type TIInternetBindInfo1 = struct {
	FlpVtbl uintptr
}

type IInternetBindInfo1 = TIInternetBindInfo1

type TLPIINTERNETBINDINFOEX = uintptr

type LPIINTERNETBINDINFOEX = TLPIINTERNETBINDINFOEX

type TIInternetBindInfoExVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetBindInfo    uintptr
	FGetBindString  uintptr
	FGetBindInfoEx  uintptr
}

type IInternetBindInfoExVtbl = TIInternetBindInfoExVtbl

type TIInternetBindInfoEx1 = struct {
	FlpVtbl uintptr
}

type IInternetBindInfoEx1 = TIInternetBindInfoEx1

type TLPIINTERNETPROTOCOLROOT = uintptr

type LPIINTERNETPROTOCOLROOT = TLPIINTERNETPROTOCOLROOT

type TPI_FLAGS = int32

type PI_FLAGS = TPI_FLAGS

type __tagPI_FLAGS = int32

const _PI_PARSE_URL = 1
const _PI_FILTER_MODE = 2
const _PI_FORCE_ASYNC = 4
const _PI_USE_WORKERTHREAD = 8
const _PI_MIMEVERIFICATION = 16
const _PI_CLSIDLOOKUP = 32
const _PI_DATAPROGRESS = 64
const _PI_SYNCHRONOUS = 128
const _PI_APARTMENTTHREADED = 256
const _PI_CLASSINSTALL = 512
const _PI_PASSONBINDCTX = 8192
const _PI_NOMIMEHANDLER = 32768
const _PI_LOADAPPDIRECT = 16384
const _PD_FORCE_SWITCH = 65536
const _PI_PREFERDEFAULTHANDLER = 131072

type TPROTOCOLDATA = struct {
	FgrfFlags TDWORD
	FdwState  TDWORD
	FpData    TLPVOID
	FcbData   TULONG
}

type PROTOCOLDATA = TPROTOCOLDATA

type T_tagPROTOCOLDATA = TPROTOCOLDATA

type _tagPROTOCOLDATA = T_tagPROTOCOLDATA

type TStartParam = struct {
	Fiid       TIID
	FpIBindCtx uintptr
	FpItf      uintptr
}

type StartParam = TStartParam

type T_tagStartParam = TStartParam

type _tagStartParam = T_tagStartParam

type TIInternetProtocolRootVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FStart          uintptr
	FContinue       uintptr
	FAbort          uintptr
	FTerminate      uintptr
	FSuspend        uintptr
	FResume         uintptr
}

type IInternetProtocolRootVtbl = TIInternetProtocolRootVtbl

type TIInternetProtocolRoot1 = struct {
	FlpVtbl uintptr
}

type IInternetProtocolRoot1 = TIInternetProtocolRoot1

type TLPIINTERNETPROTOCOL = uintptr

type LPIINTERNETPROTOCOL = TLPIINTERNETPROTOCOL

type TIInternetProtocolVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FStart          uintptr
	FContinue       uintptr
	FAbort          uintptr
	FTerminate      uintptr
	FSuspend        uintptr
	FResume         uintptr
	FRead           uintptr
	FSeek           uintptr
	FLockRequest    uintptr
	FUnlockRequest  uintptr
}

type IInternetProtocolVtbl = TIInternetProtocolVtbl

type TIInternetProtocol1 = struct {
	FlpVtbl uintptr
}

type IInternetProtocol1 = TIInternetProtocol1

type TIInternetProtocolExVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FStart          uintptr
	FContinue       uintptr
	FAbort          uintptr
	FTerminate      uintptr
	FSuspend        uintptr
	FResume         uintptr
	FRead           uintptr
	FSeek           uintptr
	FLockRequest    uintptr
	FUnlockRequest  uintptr
	FStartEx        uintptr
}

type IInternetProtocolExVtbl = TIInternetProtocolExVtbl

type TIInternetProtocolEx1 = struct {
	FlpVtbl uintptr
}

type IInternetProtocolEx1 = TIInternetProtocolEx1

type TLPIINTERNETPROTOCOLSINK = uintptr

type LPIINTERNETPROTOCOLSINK = TLPIINTERNETPROTOCOLSINK

type TIInternetProtocolSinkVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSwitch         uintptr
	FReportProgress uintptr
	FReportData     uintptr
	FReportResult   uintptr
}

type IInternetProtocolSinkVtbl = TIInternetProtocolSinkVtbl

type TIInternetProtocolSink1 = struct {
	FlpVtbl uintptr
}

type IInternetProtocolSink1 = TIInternetProtocolSink1

type TLPIINTERNETPROTOCOLSINKStackable = uintptr

type LPIINTERNETPROTOCOLSINKStackable = TLPIINTERNETPROTOCOLSINKStackable

type TIInternetProtocolSinkStackableVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSwitchSink     uintptr
	FCommitSwitch   uintptr
	FRollbackSwitch uintptr
}

type IInternetProtocolSinkStackableVtbl = TIInternetProtocolSinkStackableVtbl

type TIInternetProtocolSinkStackable1 = struct {
	FlpVtbl uintptr
}

type IInternetProtocolSinkStackable1 = TIInternetProtocolSinkStackable1

type TLPIINTERNETSESSION = uintptr

type LPIINTERNETSESSION = TLPIINTERNETSESSION

type TOIBDG_FLAGS = int32

type OIBDG_FLAGS = TOIBDG_FLAGS

type __tagOIBDG_FLAGS = int32

const _OIBDG_APARTMENTTHREADED = 256
const _OIBDG_DATAONLY = 4096

type TIInternetSessionVtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FRegisterNameSpace    uintptr
	FUnregisterNameSpace  uintptr
	FRegisterMimeFilter   uintptr
	FUnregisterMimeFilter uintptr
	FCreateBinding        uintptr
	FSetSessionOption     uintptr
	FGetSessionOption     uintptr
}

type IInternetSessionVtbl = TIInternetSessionVtbl

type TIInternetSession1 = struct {
	FlpVtbl uintptr
}

type IInternetSession1 = TIInternetSession1

type TLPIINTERNETTHREADSWITCH = uintptr

type LPIINTERNETTHREADSWITCH = TLPIINTERNETTHREADSWITCH

type TIInternetThreadSwitchVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FPrepare        uintptr
	FContinue       uintptr
}

type IInternetThreadSwitchVtbl = TIInternetThreadSwitchVtbl

type TIInternetThreadSwitch1 = struct {
	FlpVtbl uintptr
}

type IInternetThreadSwitch1 = TIInternetThreadSwitch1

type TLPIINTERNETPRIORITY = uintptr

type LPIINTERNETPRIORITY = TLPIINTERNETPRIORITY

type TIInternetPriorityVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FSetPriority    uintptr
	FGetPriority    uintptr
}

type IInternetPriorityVtbl = TIInternetPriorityVtbl

type TIInternetPriority1 = struct {
	FlpVtbl uintptr
}

type IInternetPriority1 = TIInternetPriority1

type TLPIINTERNETPROTOCOLINFO = uintptr

type LPIINTERNETPROTOCOLINFO = TLPIINTERNETPROTOCOLINFO

type TPARSEACTION = int32

type PARSEACTION = TPARSEACTION

type __tagPARSEACTION = int32

const _PARSE_CANONICALIZE = 1
const _PARSE_FRIENDLY = 2
const _PARSE_SECURITY_URL = 3
const _PARSE_ROOTDOCUMENT = 4
const _PARSE_DOCUMENT = 5
const _PARSE_ANCHOR = 6
const _PARSE_ENCODE_IS_UNESCAPE = 7
const _PARSE_DECODE_IS_ESCAPE = 8
const _PARSE_PATH_FROM_URL = 9
const _PARSE_URL_FROM_PATH = 10
const _PARSE_MIME = 11
const _PARSE_SERVER = 12
const _PARSE_SCHEMA = 13
const _PARSE_SITE = 14
const _PARSE_DOMAIN = 15
const _PARSE_LOCATION = 16
const _PARSE_SECURITY_DOMAIN = 17
const _PARSE_ESCAPE = 18
const _PARSE_UNESCAPE = 19

type TPSUACTION = int32

type PSUACTION = TPSUACTION

type __tagPSUACTION = int32

const _PSU_DEFAULT = 1
const _PSU_SECURITY_URL_ONLY = 2

type TQUERYOPTION = int32

type QUERYOPTION = TQUERYOPTION

type __tagQUERYOPTION = int32

const _QUERY_EXPIRATION_DATE = 1
const _QUERY_TIME_OF_LAST_CHANGE = 2
const _QUERY_CONTENT_ENCODING = 3
const _QUERY_CONTENT_TYPE = 4
const _QUERY_REFRESH = 5
const _QUERY_RECOMBINE = 6
const _QUERY_CAN_NAVIGATE = 7
const _QUERY_USES_NETWORK = 8
const _QUERY_IS_CACHED = 9
const _QUERY_IS_INSTALLEDENTRY = 10
const _QUERY_IS_CACHED_OR_MAPPED = 11
const _QUERY_USES_CACHE = 12
const _QUERY_IS_SECURE = 13
const _QUERY_IS_SAFE = 14
const _QUERY_USES_HISTORYFOLDER = 15
const _QUERY_IS_CACHED_AND_USABLE_OFFLINE = 16

type TIInternetProtocolInfoVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FParseUrl       uintptr
	FCombineUrl     uintptr
	FCompareUrl     uintptr
	FQueryInfo      uintptr
}

type IInternetProtocolInfoVtbl = TIInternetProtocolInfoVtbl

type TIInternetProtocolInfo1 = struct {
	FlpVtbl uintptr
}

type IInternetProtocolInfo1 = TIInternetProtocolInfo1

type TINTERNETFEATURELIST = int32

type INTERNETFEATURELIST = TINTERNETFEATURELIST

type __tagINTERNETFEATURELIST = int32

const _FEATURE_OBJECT_CACHING = 0
const _FEATURE_ZONE_ELEVATION = 1
const _FEATURE_MIME_HANDLING = 2
const _FEATURE_MIME_SNIFFING = 3
const _FEATURE_WINDOW_RESTRICTIONS = 4
const _FEATURE_WEBOC_POPUPMANAGEMENT = 5
const _FEATURE_BEHAVIORS = 6
const _FEATURE_DISABLE_MK_PROTOCOL = 7
const _FEATURE_LOCALMACHINE_LOCKDOWN = 8
const _FEATURE_SECURITYBAND = 9
const _FEATURE_RESTRICT_ACTIVEXINSTALL = 10
const _FEATURE_VALIDATE_NAVIGATE_URL = 11
const _FEATURE_RESTRICT_FILEDOWNLOAD = 12
const _FEATURE_ADDON_MANAGEMENT = 13
const _FEATURE_PROTOCOL_LOCKDOWN = 14
const _FEATURE_HTTP_USERNAME_PASSWORD_DISABLE = 15
const _FEATURE_SAFE_BINDTOOBJECT = 16
const _FEATURE_UNC_SAVEDFILECHECK = 17
const _FEATURE_GET_URL_DOM_FILEPATH_UNENCODED = 18
const _FEATURE_TABBED_BROWSING = 19
const _FEATURE_SSLUX = 20
const _FEATURE_DISABLE_NAVIGATION_SOUNDS = 21
const _FEATURE_DISABLE_LEGACY_COMPRESSION = 22
const _FEATURE_FORCE_ADDR_AND_STATUS = 23
const _FEATURE_XMLHTTP = 24
const _FEATURE_DISABLE_TELNET_PROTOCOL = 25
const _FEATURE_FEEDS = 26
const _FEATURE_BLOCK_INPUT_PROMPTS = 27
const _FEATURE_ENTRY_COUNT = 28

type TIInternetSecurityMgrSiteVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetWindow      uintptr
	FEnableModeless uintptr
}

type IInternetSecurityMgrSiteVtbl = TIInternetSecurityMgrSiteVtbl

type TIInternetSecurityMgrSite1 = struct {
	FlpVtbl uintptr
}

type IInternetSecurityMgrSite1 = TIInternetSecurityMgrSite1

type TPUAF = int32

type PUAF = TPUAF

type ___WIDL_urlmon_generated_name_0000001B = int32

const _PUAF_DEFAULT = 0
const _PUAF_NOUI = 1
const _PUAF_ISFILE = 2
const _PUAF_WARN_IF_DENIED = 4
const _PUAF_FORCEUI_FOREGROUND = 8
const _PUAF_CHECK_TIFS = 16
const _PUAF_DONTCHECKBOXINDIALOG = 32
const _PUAF_TRUSTED = 64
const _PUAF_ACCEPT_WILDCARD_SCHEME = 128
const _PUAF_ENFORCERESTRICTED = 256
const _PUAF_NOSAVEDFILECHECK = 512
const _PUAF_REQUIRESAVEDFILECHECK = 1024
const _PUAF_DONT_USE_CACHE = 4096
const _PUAF_RESERVED1 = 8192
const _PUAF_RESERVED2 = 16384
const _PUAF_LMZ_UNLOCKED = 65536
const _PUAF_LMZ_LOCKED = 131072
const _PUAF_DEFAULTZONEPOL = 262144
const _PUAF_NPL_USE_LOCKED_IF_RESTRICTED = 524288
const _PUAF_NOUIIFLOCKED = 1048576
const _PUAF_DRAGPROTOCOLCHECK = 2097152

type TPUAFOUT = int32

type PUAFOUT = TPUAFOUT

type ___WIDL_urlmon_generated_name_0000001C = int32

const _PUAFOUT_DEFAULT = 0
const _PUAFOUT_ISLOCKZONEPOLICY = 1

type TSZM_FLAGS = int32

type SZM_FLAGS = TSZM_FLAGS

type ___WIDL_urlmon_generated_name_0000001D = int32

const _SZM_CREATE = 0
const _SZM_DELETE = 1

type TIInternetSecurityManagerVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FSetSecuritySite   uintptr
	FGetSecuritySite   uintptr
	FMapUrlToZone      uintptr
	FGetSecurityId     uintptr
	FProcessUrlAction  uintptr
	FQueryCustomPolicy uintptr
	FSetZoneMapping    uintptr
	FGetZoneMappings   uintptr
}

type IInternetSecurityManagerVtbl = TIInternetSecurityManagerVtbl

type TIInternetSecurityManager1 = struct {
	FlpVtbl uintptr
}

type IInternetSecurityManager1 = TIInternetSecurityManager1

type TIInternetSecurityManagerExVtbl = struct {
	FQueryInterface     uintptr
	FAddRef             uintptr
	FRelease            uintptr
	FSetSecuritySite    uintptr
	FGetSecuritySite    uintptr
	FMapUrlToZone       uintptr
	FGetSecurityId      uintptr
	FProcessUrlAction   uintptr
	FQueryCustomPolicy  uintptr
	FSetZoneMapping     uintptr
	FGetZoneMappings    uintptr
	FProcessUrlActionEx uintptr
}

type IInternetSecurityManagerExVtbl = TIInternetSecurityManagerExVtbl

type TIInternetSecurityManagerEx1 = struct {
	FlpVtbl uintptr
}

type IInternetSecurityManagerEx1 = TIInternetSecurityManagerEx1

type TIInternetSecurityManagerEx2Vtbl = struct {
	FQueryInterface       uintptr
	FAddRef               uintptr
	FRelease              uintptr
	FSetSecuritySite      uintptr
	FGetSecuritySite      uintptr
	FMapUrlToZone         uintptr
	FGetSecurityId        uintptr
	FProcessUrlAction     uintptr
	FQueryCustomPolicy    uintptr
	FSetZoneMapping       uintptr
	FGetZoneMappings      uintptr
	FProcessUrlActionEx   uintptr
	FMapUrlToZoneEx2      uintptr
	FProcessUrlActionEx2  uintptr
	FGetSecurityIdEx2     uintptr
	FQueryCustomPolicyEx2 uintptr
}

type IInternetSecurityManagerEx2Vtbl = TIInternetSecurityManagerEx2Vtbl

type TIInternetSecurityManagerEx21 = struct {
	FlpVtbl uintptr
}

type IInternetSecurityManagerEx21 = TIInternetSecurityManagerEx21

type TIZoneIdentifierVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetId          uintptr
	FSetId          uintptr
	FRemove         uintptr
}

type IZoneIdentifierVtbl = TIZoneIdentifierVtbl

type TIZoneIdentifier1 = struct {
	FlpVtbl uintptr
}

type IZoneIdentifier1 = TIZoneIdentifier1

type TIInternetHostSecurityManagerVtbl = struct {
	FQueryInterface    uintptr
	FAddRef            uintptr
	FRelease           uintptr
	FGetSecurityId     uintptr
	FProcessUrlAction  uintptr
	FQueryCustomPolicy uintptr
}

type IInternetHostSecurityManagerVtbl = TIInternetHostSecurityManagerVtbl

type TIInternetHostSecurityManager1 = struct {
	FlpVtbl uintptr
}

type IInternetHostSecurityManager1 = TIInternetHostSecurityManager1

type TLPURLZONEMANAGER = uintptr

type LPURLZONEMANAGER = TLPURLZONEMANAGER

type TURLZONE = int32

type URLZONE = TURLZONE

type _tagURLZONE = int32

const _URLZONE_INVALID = -1
const _URLZONE_PREDEFINED_MIN = 0
const _URLZONE_LOCAL_MACHINE = 0
const _URLZONE_INTRANET = 1
const _URLZONE_TRUSTED = 2
const _URLZONE_INTERNET = 3
const _URLZONE_UNTRUSTED = 4
const _URLZONE_PREDEFINED_MAX = 999
const _URLZONE_USER_MIN = 1000
const _URLZONE_USER_MAX = 10000

type TURLTEMPLATE = int32

type URLTEMPLATE = TURLTEMPLATE

type _tagURLTEMPLATE = int32

const _URLTEMPLATE_CUSTOM = 0
const _URLTEMPLATE_PREDEFINED_MIN = 65536
const _URLTEMPLATE_LOW = 65536
const _URLTEMPLATE_MEDLOW = 66816
const _URLTEMPLATE_MEDIUM = 69632
const _URLTEMPLATE_MEDHIGH = 70912
const _URLTEMPLATE_HIGH = 73728
const _URLTEMPLATE_PREDEFINED_MAX = 131072
const _MAX_ZONE_PATH = 260
const _MAX_ZONE_DESCRIPTION = 200

type TZAFLAGS = int32

type ZAFLAGS = TZAFLAGS

type ___WIDL_urlmon_generated_name_0000001E = int32

const _ZAFLAGS_CUSTOM_EDIT = 1
const _ZAFLAGS_ADD_SITES = 2
const _ZAFLAGS_REQUIRE_VERIFICATION = 4
const _ZAFLAGS_INCLUDE_PROXY_OVERRIDE = 8
const _ZAFLAGS_INCLUDE_INTRANET_SITES = 16
const _ZAFLAGS_NO_UI = 32
const _ZAFLAGS_SUPPORTS_VERIFICATION = 64
const _ZAFLAGS_UNC_AS_INTRANET = 128
const _ZAFLAGS_DETECT_INTRANET = 256
const _ZAFLAGS_USE_LOCKED_ZONES = 65536
const _ZAFLAGS_VERIFY_TEMPLATE_SETTINGS = 131072
const _ZAFLAGS_NO_CACHE = 262144

type TZONEATTRIBUTES = struct {
	FcbSize                 TULONG
	FszDisplayName          [260]TWCHAR
	FszDescription          [200]TWCHAR
	FszIconPath             [260]TWCHAR
	FdwTemplateMinLevel     TDWORD
	FdwTemplateRecommended  TDWORD
	FdwTemplateCurrentLevel TDWORD
	FdwFlags                TDWORD
}

type ZONEATTRIBUTES = TZONEATTRIBUTES

type T_ZONEATTRIBUTES = TZONEATTRIBUTES

type _ZONEATTRIBUTES = T_ZONEATTRIBUTES

type TLPZONEATTRIBUTES = uintptr

type LPZONEATTRIBUTES = TLPZONEATTRIBUTES

type TURLZONEREG = int32

type URLZONEREG = TURLZONEREG

type __URLZONEREG = int32

const _URLZONEREG_DEFAULT = 0
const _URLZONEREG_HKLM = 1
const _URLZONEREG_HKCU = 2

type TIInternetZoneManagerVtbl = struct {
	FQueryInterface             uintptr
	FAddRef                     uintptr
	FRelease                    uintptr
	FGetZoneAttributes          uintptr
	FSetZoneAttributes          uintptr
	FGetZoneCustomPolicy        uintptr
	FSetZoneCustomPolicy        uintptr
	FGetZoneActionPolicy        uintptr
	FSetZoneActionPolicy        uintptr
	FPromptAction               uintptr
	FLogAction                  uintptr
	FCreateZoneEnumerator       uintptr
	FGetZoneAt                  uintptr
	FDestroyZoneEnumerator      uintptr
	FCopyTemplatePoliciesToZone uintptr
}

type IInternetZoneManagerVtbl = TIInternetZoneManagerVtbl

type TIInternetZoneManager1 = struct {
	FlpVtbl uintptr
}

type IInternetZoneManager1 = TIInternetZoneManager1

type TIInternetZoneManagerExVtbl = struct {
	FQueryInterface             uintptr
	FAddRef                     uintptr
	FRelease                    uintptr
	FGetZoneAttributes          uintptr
	FSetZoneAttributes          uintptr
	FGetZoneCustomPolicy        uintptr
	FSetZoneCustomPolicy        uintptr
	FGetZoneActionPolicy        uintptr
	FSetZoneActionPolicy        uintptr
	FPromptAction               uintptr
	FLogAction                  uintptr
	FCreateZoneEnumerator       uintptr
	FGetZoneAt                  uintptr
	FDestroyZoneEnumerator      uintptr
	FCopyTemplatePoliciesToZone uintptr
	FGetZoneActionPolicyEx      uintptr
	FSetZoneActionPolicyEx      uintptr
}

type IInternetZoneManagerExVtbl = TIInternetZoneManagerExVtbl

type TIInternetZoneManagerEx1 = struct {
	FlpVtbl uintptr
}

type IInternetZoneManagerEx1 = TIInternetZoneManagerEx1

type TIInternetZoneManagerEx2Vtbl = struct {
	FQueryInterface             uintptr
	FAddRef                     uintptr
	FRelease                    uintptr
	FGetZoneAttributes          uintptr
	FSetZoneAttributes          uintptr
	FGetZoneCustomPolicy        uintptr
	FSetZoneCustomPolicy        uintptr
	FGetZoneActionPolicy        uintptr
	FSetZoneActionPolicy        uintptr
	FPromptAction               uintptr
	FLogAction                  uintptr
	FCreateZoneEnumerator       uintptr
	FGetZoneAt                  uintptr
	FDestroyZoneEnumerator      uintptr
	FCopyTemplatePoliciesToZone uintptr
	FGetZoneActionPolicyEx      uintptr
	FSetZoneActionPolicyEx      uintptr
	FGetZoneAttributesEx        uintptr
	FGetZoneSecurityState       uintptr
	FGetIESecurityState         uintptr
	FFixUnsecureSettings        uintptr
}

type IInternetZoneManagerEx2Vtbl = TIInternetZoneManagerEx2Vtbl

type TIInternetZoneManagerEx21 = struct {
	FlpVtbl uintptr
}

type IInternetZoneManagerEx21 = TIInternetZoneManagerEx21

type TCODEBASEHOLD = struct {
	FcbSize      TULONG
	FszDistUnit  TLPWSTR
	FszCodeBase  TLPWSTR
	FdwVersionMS TDWORD
	FdwVersionLS TDWORD
	FdwStyle     TDWORD
}

type CODEBASEHOLD = TCODEBASEHOLD

type T_tagCODEBASEHOLD = TCODEBASEHOLD

type _tagCODEBASEHOLD = T_tagCODEBASEHOLD

type TLPCODEBASEHOLD = uintptr

type LPCODEBASEHOLD = TLPCODEBASEHOLD

type TSOFTDISTINFO = struct {
	FcbSize                TULONG
	FdwFlags               TDWORD
	FdwAdState             TDWORD
	FszTitle               TLPWSTR
	FszAbstract            TLPWSTR
	FszHREF                TLPWSTR
	FdwInstalledVersionMS  TDWORD
	FdwInstalledVersionLS  TDWORD
	FdwUpdateVersionMS     TDWORD
	FdwUpdateVersionLS     TDWORD
	FdwAdvertisedVersionMS TDWORD
	FdwAdvertisedVersionLS TDWORD
	FdwReserved            TDWORD
}

type SOFTDISTINFO = TSOFTDISTINFO

type T_tagSOFTDISTINFO = TSOFTDISTINFO

type _tagSOFTDISTINFO = T_tagSOFTDISTINFO

type TLPSOFTDISTINFO = uintptr

type LPSOFTDISTINFO = TLPSOFTDISTINFO

type TISoftDistExtVtbl = struct {
	FQueryInterface               uintptr
	FAddRef                       uintptr
	FRelease                      uintptr
	FProcessSoftDist              uintptr
	FGetFirstCodeBase             uintptr
	FGetNextCodeBase              uintptr
	FAsyncInstallDistributionUnit uintptr
}

type ISoftDistExtVtbl = TISoftDistExtVtbl

type TISoftDistExt1 = struct {
	FlpVtbl uintptr
}

type ISoftDistExt1 = TISoftDistExt1

type TLPCATALOGFILEINFO = uintptr

type LPCATALOGFILEINFO = TLPCATALOGFILEINFO

type TICatalogFileInfoVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetCatalogFile uintptr
	FGetJavaTrust   uintptr
}

type ICatalogFileInfoVtbl = TICatalogFileInfoVtbl

type TICatalogFileInfo1 = struct {
	FlpVtbl uintptr
}

type ICatalogFileInfo1 = TICatalogFileInfo1

type TLPDATAFILTER = uintptr

type LPDATAFILTER = TLPDATAFILTER

type TIDataFilterVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FDoEncode         uintptr
	FDoDecode         uintptr
	FSetEncodingLevel uintptr
}

type IDataFilterVtbl = TIDataFilterVtbl

type TIDataFilter1 = struct {
	FlpVtbl uintptr
}

type IDataFilter1 = TIDataFilter1

type TPROTOCOLFILTERDATA = struct {
	FcbSize        TDWORD
	FpProtocolSink uintptr
	FpProtocol     uintptr
	FpUnk          uintptr
	FdwFilterFlags TDWORD
}

type PROTOCOLFILTERDATA = TPROTOCOLFILTERDATA

type T_tagPROTOCOLFILTERDATA = TPROTOCOLFILTERDATA

type _tagPROTOCOLFILTERDATA = T_tagPROTOCOLFILTERDATA

type TLPENCODINGFILTERFACTORY = uintptr

type LPENCODINGFILTERFACTORY = TLPENCODINGFILTERFACTORY

type TDATAINFO = struct {
	FulTotalSize      TULONG
	FulavrPacketSize  TULONG
	FulConnectSpeed   TULONG
	FulProcessorSpeed TULONG
}

type DATAINFO = TDATAINFO

type T_tagDATAINFO = TDATAINFO

type _tagDATAINFO = T_tagDATAINFO

type TIEncodingFilterFactoryVtbl = struct {
	FQueryInterface   uintptr
	FAddRef           uintptr
	FRelease          uintptr
	FFindBestFilter   uintptr
	FGetDefaultFilter uintptr
}

type IEncodingFilterFactoryVtbl = TIEncodingFilterFactoryVtbl

type TIEncodingFilterFactory1 = struct {
	FlpVtbl uintptr
}

type IEncodingFilterFactory1 = TIEncodingFilterFactory1

type THIT_LOGGING_INFO = struct {
	FdwStructSize      TDWORD
	FlpszLoggedUrlName TLPSTR
	FStartTime         TSYSTEMTIME
	FEndTime           TSYSTEMTIME
	FlpszExtendedInfo  TLPSTR
}

type HIT_LOGGING_INFO = THIT_LOGGING_INFO

type T_tagHIT_LOGGING_INFO = THIT_LOGGING_INFO

type _tagHIT_LOGGING_INFO = T_tagHIT_LOGGING_INFO

type TLPHIT_LOGGING_INFO = uintptr

type LPHIT_LOGGING_INFO = TLPHIT_LOGGING_INFO

type TCONFIRMSAFETY = struct {
	Fclsid   TCLSID
	FpUnk    uintptr
	FdwFlags TDWORD
}

type CONFIRMSAFETY = TCONFIRMSAFETY

type TLPIWRAPPEDPROTOCOL = uintptr

type LPIWRAPPEDPROTOCOL = TLPIWRAPPEDPROTOCOL

type TIWrappedProtocolVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetWrapperCode uintptr
}

type IWrappedProtocolVtbl = TIWrappedProtocolVtbl

type TIWrappedProtocol1 = struct {
	FlpVtbl uintptr
}

type IWrappedProtocol1 = TIWrappedProtocol1

type TLPGETBINDHANDLE = uintptr

type LPGETBINDHANDLE = TLPGETBINDHANDLE

type TBINDHANDLETYPES = int32

type BINDHANDLETYPES = TBINDHANDLETYPES

type ___WIDL_urlmon_generated_name_0000001F = int32

const _BINDHANDLETYPES_APPCACHE = 0
const _BINDHANDLETYPES_DEPENDENCY = 1
const _BINDHANDLETYPES_COUNT = 2

type TIGetBindHandleVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FGetBindHandle  uintptr
}

type IGetBindHandleVtbl = TIGetBindHandleVtbl

type TIGetBindHandle1 = struct {
	FlpVtbl uintptr
}

type IGetBindHandle1 = TIGetBindHandle1

type TPROTOCOL_ARGUMENT = struct {
	FszMethod    TLPCWSTR
	FszTargetUrl TLPCWSTR
}

type PROTOCOL_ARGUMENT = TPROTOCOL_ARGUMENT

type T_tagPROTOCOL_ARGUMENT = TPROTOCOL_ARGUMENT

type _tagPROTOCOL_ARGUMENT = T_tagPROTOCOL_ARGUMENT

type TLPPROTOCOL_ARGUMENT = uintptr

type LPPROTOCOL_ARGUMENT = TLPPROTOCOL_ARGUMENT

type TLPBINDCALLBACKREDIRECT = uintptr

type LPBINDCALLBACKREDIRECT = TLPBINDCALLBACKREDIRECT

type TIBindCallbackRedirectVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FRedirect       uintptr
}

type IBindCallbackRedirectVtbl = TIBindCallbackRedirectVtbl

type TIBindCallbackRedirect1 = struct {
	FlpVtbl uintptr
}

type IBindCallbackRedirect1 = TIBindCallbackRedirect1

type TIPropertyStorage = struct {
	FlpVtbl uintptr
}

type IPropertyStorage = TIPropertyStorage

type TIPropertySetStorage = struct {
	FlpVtbl uintptr
}

type IPropertySetStorage = TIPropertySetStorage

type TIEnumSTATPROPSTG = struct {
	FlpVtbl uintptr
}

type IEnumSTATPROPSTG = TIEnumSTATPROPSTG

type TIEnumSTATPROPSETSTG = struct {
	FlpVtbl uintptr
}

type IEnumSTATPROPSETSTG = TIEnumSTATPROPSETSTG

type TVERSIONEDSTREAM = struct {
	FguidVersion TGUID
	FpStream     uintptr
}

type VERSIONEDSTREAM = TVERSIONEDSTREAM

type TtagVersionedStream = TVERSIONEDSTREAM

type tagVersionedStream = TtagVersionedStream

type TLPVERSIONEDSTREAM = uintptr

type LPVERSIONEDSTREAM = TLPVERSIONEDSTREAM

type TCAC = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAC = TCAC

type TtagCAC = TCAC

type tagCAC = TtagCAC

type TCAUB = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAUB = TCAUB

type TtagCAUB = TCAUB

type tagCAUB = TtagCAUB

type TCAI = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAI = TCAI

type TtagCAI = TCAI

type tagCAI = TtagCAI

type TCAUI = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAUI = TCAUI

type TtagCAUI = TCAUI

type tagCAUI = TtagCAUI

type TCAL = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAL = TCAL

type TtagCAL = TCAL

type tagCAL = TtagCAL

type TCAUL = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAUL = TCAUL

type TtagCAUL = TCAUL

type tagCAUL = TtagCAUL

type TCAFLT = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAFLT = TCAFLT

type TtagCAFLT = TCAFLT

type tagCAFLT = TtagCAFLT

type TCADBL = struct {
	FcElems TULONG
	FpElems uintptr
}

type CADBL = TCADBL

type TtagCADBL = TCADBL

type tagCADBL = TtagCADBL

type TCACY = struct {
	FcElems TULONG
	FpElems uintptr
}

type CACY = TCACY

type TtagCACY = TCACY

type tagCACY = TtagCACY

type TCADATE = struct {
	FcElems TULONG
	FpElems uintptr
}

type CADATE = TCADATE

type TtagCADATE = TCADATE

type tagCADATE = TtagCADATE

type TCABSTR = struct {
	FcElems TULONG
	FpElems uintptr
}

type CABSTR = TCABSTR

type TtagCABSTR = TCABSTR

type tagCABSTR = TtagCABSTR

type TCABSTRBLOB = struct {
	FcElems TULONG
	FpElems uintptr
}

type CABSTRBLOB = TCABSTRBLOB

type TtagCABSTRBLOB = TCABSTRBLOB

type tagCABSTRBLOB = TtagCABSTRBLOB

type TCABOOL = struct {
	FcElems TULONG
	FpElems uintptr
}

type CABOOL = TCABOOL

type TtagCABOOL = TCABOOL

type tagCABOOL = TtagCABOOL

type TCASCODE = struct {
	FcElems TULONG
	FpElems uintptr
}

type CASCODE = TCASCODE

type TtagCASCODE = TCASCODE

type tagCASCODE = TtagCASCODE

type TCAPROPVARIANT = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAPROPVARIANT = TCAPROPVARIANT

type TtagCAPROPVARIANT = TCAPROPVARIANT

type tagCAPROPVARIANT = TtagCAPROPVARIANT

type TCAH = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAH = TCAH

type TtagCAH = TCAH

type tagCAH = TtagCAH

type TCAUH = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAUH = TCAUH

type TtagCAUH = TCAUH

type tagCAUH = TtagCAUH

type TCALPSTR = struct {
	FcElems TULONG
	FpElems uintptr
}

type CALPSTR = TCALPSTR

type TtagCALPSTR = TCALPSTR

type tagCALPSTR = TtagCALPSTR

type TCALPWSTR = struct {
	FcElems TULONG
	FpElems uintptr
}

type CALPWSTR = TCALPWSTR

type TtagCALPWSTR = TCALPWSTR

type tagCALPWSTR = TtagCALPWSTR

type TCAFILETIME = struct {
	FcElems TULONG
	FpElems uintptr
}

type CAFILETIME = TCAFILETIME

type TtagCAFILETIME = TCAFILETIME

type tagCAFILETIME = TtagCAFILETIME

type TCACLIPDATA = struct {
	FcElems TULONG
	FpElems uintptr
}

type CACLIPDATA = TCACLIPDATA

type TtagCACLIPDATA = TCACLIPDATA

type tagCACLIPDATA = TtagCACLIPDATA

type TCACLSID = struct {
	FcElems TULONG
	FpElems uintptr
}

type CACLSID = TCACLSID

type TtagCACLSID = TCACLSID

type tagCACLSID = TtagCACLSID

type TPROPVAR_PAD1 = uint16

type PROPVAR_PAD1 = TPROPVAR_PAD1

type TPROPVAR_PAD2 = uint16

type PROPVAR_PAD2 = TPROPVAR_PAD2

type TPROPVAR_PAD3 = uint16

type PROPVAR_PAD3 = TPROPVAR_PAD3

type TLPPROPVARIANT = uintptr

type LPPROPVARIANT = TLPPROPVARIANT

type _PIDMSI_STATUS_VALUE = int32

const _PIDMSI_STATUS_NORMAL = 0
const _PIDMSI_STATUS_NEW = 1
const _PIDMSI_STATUS_PRELIM = 2
const _PIDMSI_STATUS_DRAFT = 3
const _PIDMSI_STATUS_INPROGRESS = 4
const _PIDMSI_STATUS_EDIT = 5
const _PIDMSI_STATUS_REVIEW = 6
const _PIDMSI_STATUS_PROOF = 7
const _PIDMSI_STATUS_FINAL = 8
const _PIDMSI_STATUS_OTHER = 32767

type TPROPSPEC = struct {
	FulKind    TULONG
	F__ccgo1_4 struct {
		Flpwstr [0]TLPOLESTR
		Fpropid TPROPID
	}
}

type PROPSPEC = TPROPSPEC

type TtagPROPSPEC = TPROPSPEC

type tagPROPSPEC = TtagPROPSPEC

type TSTATPROPSTG = struct {
	FlpwstrName TLPOLESTR
	Fpropid     TPROPID
	Fvt         TVARTYPE
}

type STATPROPSTG = TSTATPROPSTG

type TtagSTATPROPSTG = TSTATPROPSTG

type tagSTATPROPSTG = TtagSTATPROPSTG

type TSTATPROPSETSTG = struct {
	Ffmtid       TFMTID
	Fclsid       TCLSID
	FgrfFlags    TDWORD
	Fmtime       TFILETIME
	Fctime       TFILETIME
	Fatime       TFILETIME
	FdwOSVersion TDWORD
}

type STATPROPSETSTG = TSTATPROPSETSTG

type TtagSTATPROPSETSTG = TSTATPROPSETSTG

type tagSTATPROPSETSTG = TtagSTATPROPSETSTG

type TIPropertyStorageVtbl = struct {
	FQueryInterface      uintptr
	FAddRef              uintptr
	FRelease             uintptr
	FReadMultiple        uintptr
	FWriteMultiple       uintptr
	FDeleteMultiple      uintptr
	FReadPropertyNames   uintptr
	FWritePropertyNames  uintptr
	FDeletePropertyNames uintptr
	FCommit              uintptr
	FRevert              uintptr
	FEnum                uintptr
	FSetTimes            uintptr
	FSetClass            uintptr
	FStat                uintptr
}

type IPropertyStorageVtbl = TIPropertyStorageVtbl

type TIPropertyStorage1 = struct {
	FlpVtbl uintptr
}

type IPropertyStorage1 = TIPropertyStorage1

type TLPPROPERTYSETSTORAGE = uintptr

type LPPROPERTYSETSTORAGE = TLPPROPERTYSETSTORAGE

type TIPropertySetStorageVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FCreate         uintptr
	FOpen           uintptr
	FDelete         uintptr
	FEnum           uintptr
}

type IPropertySetStorageVtbl = TIPropertySetStorageVtbl

type TIPropertySetStorage1 = struct {
	FlpVtbl uintptr
}

type IPropertySetStorage1 = TIPropertySetStorage1

type TLPENUMSTATPROPSTG = uintptr

type LPENUMSTATPROPSTG = TLPENUMSTATPROPSTG

type TIEnumSTATPROPSTGVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumSTATPROPSTGVtbl = TIEnumSTATPROPSTGVtbl

type TIEnumSTATPROPSTG1 = struct {
	FlpVtbl uintptr
}

type IEnumSTATPROPSTG1 = TIEnumSTATPROPSTG1

type TLPENUMSTATPROPSETSTG = uintptr

type LPENUMSTATPROPSETSTG = TLPENUMSTATPROPSETSTG

type TIEnumSTATPROPSETSTGVtbl = struct {
	FQueryInterface uintptr
	FAddRef         uintptr
	FRelease        uintptr
	FNext           uintptr
	FSkip           uintptr
	FReset          uintptr
	FClone          uintptr
}

type IEnumSTATPROPSETSTGVtbl = TIEnumSTATPROPSETSTGVtbl

type TIEnumSTATPROPSETSTG1 = struct {
	FlpVtbl uintptr
}

type IEnumSTATPROPSETSTG1 = TIEnumSTATPROPSETSTG1

type TLPPROPERTYSTORAGE = uintptr

type LPPROPERTYSTORAGE = TLPPROPERTYSTORAGE

type TSERIALIZEDPROPERTYVALUE = struct {
	FdwType TDWORD
	Frgb    [1]TBYTE
}

type SERIALIZEDPROPERTYVALUE = TSERIALIZEDPROPERTYVALUE

type TtagSERIALIZEDPROPERTYVALUE = TSERIALIZEDPROPERTYVALUE

type tagSERIALIZEDPROPERTYVALUE = TtagSERIALIZEDPROPERTYVALUE

type TNUMPARSE = struct {
	FcDig       TINT
	FdwInFlags  TULONG
	FdwOutFlags TULONG
	FcchUsed    TINT
	FnBaseShift TINT
	FnPwr10     TINT
}

type NUMPARSE = TNUMPARSE

type TUDATE = struct {
	Fst         TSYSTEMTIME
	FwDayOfYear TUSHORT
}

type UDATE = TUDATE

type TREGKIND = int32

type REGKIND = TREGKIND

type _tagREGKIND = int32

const _REGKIND_DEFAULT = 0
const _REGKIND_REGISTER = 1
const _REGKIND_NONE = 2

type TPARAMDATA = struct {
	FszName uintptr
	Fvt     TVARTYPE
}

type PARAMDATA = TPARAMDATA

type TtagPARAMDATA = TPARAMDATA

type tagPARAMDATA = TtagPARAMDATA

type TLPPARAMDATA = uintptr

type LPPARAMDATA = TLPPARAMDATA

type TMETHODDATA = struct {
	FszName   uintptr
	Fppdata   uintptr
	Fdispid   TDISPID
	FiMeth    TUINT
	Fcc       TCALLCONV
	FcArgs    TUINT
	FwFlags   TWORD
	FvtReturn TVARTYPE
}

type METHODDATA = TMETHODDATA

type TtagMETHODDATA = TMETHODDATA

type tagMETHODDATA = TtagMETHODDATA

type TLPMETHODDATA = uintptr

type LPMETHODDATA = TLPMETHODDATA

type TINTERFACEDATA = struct {
	Fpmethdata uintptr
	FcMembers  TUINT
}

type INTERFACEDATA = TINTERFACEDATA

type TtagINTERFACEDATA = TINTERFACEDATA

type tagINTERFACEDATA = TtagINTERFACEDATA

type TLPINTERFACEDATA = uintptr

type LPINTERFACEDATA = TLPINTERFACEDATA

type TLPOLESTREAM = uintptr

type LPOLESTREAM = TLPOLESTREAM

type T_OLESTREAM = struct {
	Flpstbl TLPOLESTREAMVTBL
}

type _OLESTREAM = T_OLESTREAM

type TOLESTREAMVTBL = struct {
	FGet uintptr
	FPut uintptr
}

type OLESTREAMVTBL = TOLESTREAMVTBL

type T_OLESTREAMVTBL = TOLESTREAMVTBL

type _OLESTREAMVTBL = T_OLESTREAMVTBL

type TLPOLESTREAMVTBL = uintptr

type LPOLESTREAMVTBL = TLPOLESTREAMVTBL

type TOLESTREAM = struct {
	Flpstbl TLPOLESTREAMVTBL
}

type OLESTREAM = TOLESTREAM

type TSTORAGE_READ_CAPACITY = struct {
	F__ccgo_align   [0]uint32
	FVersion        TULONG
	FSize           TULONG
	FBlockLength    TULONG
	F__ccgo_align3  [4]byte
	FNumberOfBlocks TLARGE_INTEGER
	FDiskLength     TLARGE_INTEGER
}

type STORAGE_READ_CAPACITY = TSTORAGE_READ_CAPACITY

type T_STORAGE_READ_CAPACITY = TSTORAGE_READ_CAPACITY

type _STORAGE_READ_CAPACITY = T_STORAGE_READ_CAPACITY

type TPSTORAGE_READ_CAPACITY = uintptr

type PSTORAGE_READ_CAPACITY = TPSTORAGE_READ_CAPACITY

type TDEVICE_DATA_MANAGEMENT_SET_ACTION = uint32

type DEVICE_DATA_MANAGEMENT_SET_ACTION = TDEVICE_DATA_MANAGEMENT_SET_ACTION

type TDEVICE_MANAGE_DATA_SET_ATTRIBUTES = struct {
	FSize                 TDWORD
	FAction               TDEVICE_DATA_MANAGEMENT_SET_ACTION
	FFlags                TDWORD
	FParameterBlockOffset TDWORD
	FParameterBlockLength TDWORD
	FDataSetRangesOffset  TDWORD
	FDataSetRangesLength  TDWORD
}

type DEVICE_MANAGE_DATA_SET_ATTRIBUTES = TDEVICE_MANAGE_DATA_SET_ATTRIBUTES

type T_DEVICE_MANAGE_DATA_SET_ATTRIBUTES = TDEVICE_MANAGE_DATA_SET_ATTRIBUTES

type _DEVICE_MANAGE_DATA_SET_ATTRIBUTES = T_DEVICE_MANAGE_DATA_SET_ATTRIBUTES

type TPDEVICE_MANAGE_DATA_SET_ATTRIBUTES = uintptr

type PDEVICE_MANAGE_DATA_SET_ATTRIBUTES = TPDEVICE_MANAGE_DATA_SET_ATTRIBUTES

type TDEVICE_DATA_SET_RANGE = struct {
	F__ccgo_align   [0]uint32
	FStartingOffset TLONGLONG
	FLengthInBytes  TDWORDLONG
}

type DEVICE_DATA_SET_RANGE = TDEVICE_DATA_SET_RANGE

type T_DEVICE_DATA_SET_RANGE = TDEVICE_DATA_SET_RANGE

type _DEVICE_DATA_SET_RANGE = T_DEVICE_DATA_SET_RANGE

type TPDEVICE_DATA_SET_RANGE = uintptr

type PDEVICE_DATA_SET_RANGE = TPDEVICE_DATA_SET_RANGE

type TDEVICE_DSM_NOTIFICATION_PARAMETERS = struct {
	FSize           TULONG
	FFlags          TULONG
	FNumFileTypeIDs TULONG
	FFileTypeID     [1]TGUID
}

type DEVICE_DSM_NOTIFICATION_PARAMETERS = TDEVICE_DSM_NOTIFICATION_PARAMETERS

type T_DEVICE_DSM_NOTIFICATION_PARAMETERS = TDEVICE_DSM_NOTIFICATION_PARAMETERS

type _DEVICE_DSM_NOTIFICATION_PARAMETERS = T_DEVICE_DSM_NOTIFICATION_PARAMETERS

type TPDEVICE_DSM_NOTIFICATION_PARAMETERS = uintptr

type PDEVICE_DSM_NOTIFICATION_PARAMETERS = TPDEVICE_DSM_NOTIFICATION_PARAMETERS

type TSTORAGE_GET_BC_PROPERTIES_OUTPUT = struct {
	F__ccgo_align             [0]uint32
	FMaximumRequestsPerPeriod TULONG
	FMinimumPeriod            TULONG
	FMaximumRequestSize       TULONGLONG
	FEstimatedTimePerRequest  TULONG
	FNumOutStandingRequests   TULONG
	FRequestSize              TULONGLONG
}

type STORAGE_GET_BC_PROPERTIES_OUTPUT = TSTORAGE_GET_BC_PROPERTIES_OUTPUT

type T_STORAGE_GET_BC_PROPERTIES_OUTPUT = TSTORAGE_GET_BC_PROPERTIES_OUTPUT

type _STORAGE_GET_BC_PROPERTIES_OUTPUT = T_STORAGE_GET_BC_PROPERTIES_OUTPUT

type TPSTORAGE_GET_BC_PROPERTIES_OUTPUT = uintptr

type PSTORAGE_GET_BC_PROPERTIES_OUTPUT = TPSTORAGE_GET_BC_PROPERTIES_OUTPUT

type TSTORAGE_ALLOCATE_BC_STREAM_INPUT = struct {
	FVersion           TULONG
	FRequestsPerPeriod TULONG
	FPeriod            TULONG
	FRetryFailures     TBOOLEAN
	FDiscardable       TBOOLEAN
	FReserved1         [2]TBOOLEAN
	FAccessType        TULONG
	FAccessMode        TULONG
}

type STORAGE_ALLOCATE_BC_STREAM_INPUT = TSTORAGE_ALLOCATE_BC_STREAM_INPUT

type T_STORAGE_ALLOCATE_BC_STREAM_INPUT = TSTORAGE_ALLOCATE_BC_STREAM_INPUT

type _STORAGE_ALLOCATE_BC_STREAM_INPUT = T_STORAGE_ALLOCATE_BC_STREAM_INPUT

type TPSTORAGE_ALLOCATE_BC_STREAM_INPUT = uintptr

type PSTORAGE_ALLOCATE_BC_STREAM_INPUT = TPSTORAGE_ALLOCATE_BC_STREAM_INPUT

type TSTORAGE_ALLOCATE_BC_STREAM_OUTPUT = struct {
	F__ccgo_align           [0]uint32
	FRequestSize            TULONGLONG
	FNumOutStandingRequests TULONG
	F__ccgo_pad2            [4]byte
}

type STORAGE_ALLOCATE_BC_STREAM_OUTPUT = TSTORAGE_ALLOCATE_BC_STREAM_OUTPUT

type T_STORAGE_ALLOCATE_BC_STREAM_OUTPUT = TSTORAGE_ALLOCATE_BC_STREAM_OUTPUT

type _STORAGE_ALLOCATE_BC_STREAM_OUTPUT = T_STORAGE_ALLOCATE_BC_STREAM_OUTPUT

type TPSTORAGE_ALLOCATE_BC_STREAM_OUTPUT = uintptr

type PSTORAGE_ALLOCATE_BC_STREAM_OUTPUT = TPSTORAGE_ALLOCATE_BC_STREAM_OUTPUT

type TSTORAGE_PRIORITY_HINT_SUPPORT = struct {
	FSupportFlags TULONG
}

type STORAGE_PRIORITY_HINT_SUPPORT = TSTORAGE_PRIORITY_HINT_SUPPORT

type T_STORAGE_PRIORITY_HINT_SUPPORT = TSTORAGE_PRIORITY_HINT_SUPPORT

type _STORAGE_PRIORITY_HINT_SUPPORT = T_STORAGE_PRIORITY_HINT_SUPPORT

type TPSTORAGE_PRIORITY_HINT_SUPPORT = uintptr

type PSTORAGE_PRIORITY_HINT_SUPPORT = TPSTORAGE_PRIORITY_HINT_SUPPORT

type TSTORAGE_MEDIA_SERIAL_NUMBER_DATA = struct {
	FReserved           TUSHORT
	FSerialNumberLength TUSHORT
}

type STORAGE_MEDIA_SERIAL_NUMBER_DATA = TSTORAGE_MEDIA_SERIAL_NUMBER_DATA

type T_STORAGE_MEDIA_SERIAL_NUMBER_DATA = TSTORAGE_MEDIA_SERIAL_NUMBER_DATA

type _STORAGE_MEDIA_SERIAL_NUMBER_DATA = T_STORAGE_MEDIA_SERIAL_NUMBER_DATA

type TPSTORAGE_MEDIA_SERIAL_NUMBER_DATA = uintptr

type PSTORAGE_MEDIA_SERIAL_NUMBER_DATA = TPSTORAGE_MEDIA_SERIAL_NUMBER_DATA

type TPERSISTENT_RESERVE_COMMAND = struct {
	FVersion   TULONG
	FSize      TULONG
	F__ccgo2_8 struct {
		FPR_OUT [0]struct {
			F__ccgo0 uint8
			F__ccgo1 uint8
		}
		FPR_IN struct {
			F__ccgo0          uint8
			FAllocationLength TUSHORT
		}
	}
}

type PERSISTENT_RESERVE_COMMAND = TPERSISTENT_RESERVE_COMMAND

type T_PERSISTENT_RESERVE_COMMAND = TPERSISTENT_RESERVE_COMMAND

type _PERSISTENT_RESERVE_COMMAND = T_PERSISTENT_RESERVE_COMMAND

type TPPERSISTENT_RESERVE_COMMAND = uintptr

type PPERSISTENT_RESERVE_COMMAND = TPPERSISTENT_RESERVE_COMMAND

type TSTORAGE_HOTPLUG_INFO = struct {
	FSize                     TDWORD
	FMediaRemovable           TBOOLEAN
	FMediaHotplug             TBOOLEAN
	FDeviceHotplug            TBOOLEAN
	FWriteCacheEnableOverride TBOOLEAN
}

type STORAGE_HOTPLUG_INFO = TSTORAGE_HOTPLUG_INFO

type T_STORAGE_HOTPLUG_INFO = TSTORAGE_HOTPLUG_INFO

type _STORAGE_HOTPLUG_INFO = T_STORAGE_HOTPLUG_INFO

type TPSTORAGE_HOTPLUG_INFO = uintptr

type PSTORAGE_HOTPLUG_INFO = TPSTORAGE_HOTPLUG_INFO

type TSTORAGE_DEVICE_NUMBER = struct {
	FDeviceType      TDWORD
	FDeviceNumber    TDWORD
	FPartitionNumber TDWORD
}

type STORAGE_DEVICE_NUMBER = TSTORAGE_DEVICE_NUMBER

type T_STORAGE_DEVICE_NUMBER = TSTORAGE_DEVICE_NUMBER

type _STORAGE_DEVICE_NUMBER = T_STORAGE_DEVICE_NUMBER

type TPSTORAGE_DEVICE_NUMBER = uintptr

type PSTORAGE_DEVICE_NUMBER = TPSTORAGE_DEVICE_NUMBER

type TSTORAGE_DEVICE_NUMBERS = struct {
	FVersion         TDWORD
	FSize            TDWORD
	FNumberOfDevices TDWORD
	FDevices         [1]TSTORAGE_DEVICE_NUMBER
}

type STORAGE_DEVICE_NUMBERS = TSTORAGE_DEVICE_NUMBERS

type T_STORAGE_DEVICE_NUMBERS = TSTORAGE_DEVICE_NUMBERS

type _STORAGE_DEVICE_NUMBERS = T_STORAGE_DEVICE_NUMBERS

type TPSTORAGE_DEVICE_NUMBERS = uintptr

type PSTORAGE_DEVICE_NUMBERS = TPSTORAGE_DEVICE_NUMBERS

type TSTORAGE_DEVICE_NUMBER_EX = struct {
	FVersion         TDWORD
	FSize            TDWORD
	FFlags           TDWORD
	FDeviceType      TDWORD
	FDeviceNumber    TDWORD
	FDeviceGuid      TGUID
	FPartitionNumber TDWORD
}

type STORAGE_DEVICE_NUMBER_EX = TSTORAGE_DEVICE_NUMBER_EX

type T_STORAGE_DEVICE_NUMBER_EX = TSTORAGE_DEVICE_NUMBER_EX

type _STORAGE_DEVICE_NUMBER_EX = T_STORAGE_DEVICE_NUMBER_EX

type TPSTORAGE_DEVICE_NUMBER_EX = uintptr

type PSTORAGE_DEVICE_NUMBER_EX = TPSTORAGE_DEVICE_NUMBER_EX

type TSTORAGE_BUS_RESET_REQUEST = struct {
	FPathId TBYTE
}

type STORAGE_BUS_RESET_REQUEST = TSTORAGE_BUS_RESET_REQUEST

type T_STORAGE_BUS_RESET_REQUEST = TSTORAGE_BUS_RESET_REQUEST

type _STORAGE_BUS_RESET_REQUEST = T_STORAGE_BUS_RESET_REQUEST

type TPSTORAGE_BUS_RESET_REQUEST = uintptr

type PSTORAGE_BUS_RESET_REQUEST = TPSTORAGE_BUS_RESET_REQUEST

type TSTORAGE_BREAK_RESERVATION_REQUEST = struct {
	FLength   TDWORD
	F_unused  TBYTE
	FPathId   TBYTE
	FTargetId TBYTE
	FLun      TBYTE
}

type STORAGE_BREAK_RESERVATION_REQUEST = TSTORAGE_BREAK_RESERVATION_REQUEST

type TPSTORAGE_BREAK_RESERVATION_REQUEST = uintptr

type PSTORAGE_BREAK_RESERVATION_REQUEST = TPSTORAGE_BREAK_RESERVATION_REQUEST

type TSTORAGE_BREAK_RESERVATION_REQUEST1 = struct {
	FLength   TDWORD
	F_unused  TBYTE
	FPathId   TBYTE
	FTargetId TBYTE
	FLun      TBYTE
}

type STORAGE_BREAK_RESERVATION_REQUEST1 = TSTORAGE_BREAK_RESERVATION_REQUEST1

type TPREVENT_MEDIA_REMOVAL = struct {
	FPreventMediaRemoval TBOOLEAN
}

type PREVENT_MEDIA_REMOVAL = TPREVENT_MEDIA_REMOVAL

type T_PREVENT_MEDIA_REMOVAL = TPREVENT_MEDIA_REMOVAL

type _PREVENT_MEDIA_REMOVAL = T_PREVENT_MEDIA_REMOVAL

type TPPREVENT_MEDIA_REMOVAL = uintptr

type PPREVENT_MEDIA_REMOVAL = TPPREVENT_MEDIA_REMOVAL

type TCLASS_MEDIA_CHANGE_CONTEXT = struct {
	FMediaChangeCount TDWORD
	FNewState         TDWORD
}

type CLASS_MEDIA_CHANGE_CONTEXT = TCLASS_MEDIA_CHANGE_CONTEXT

type T_CLASS_MEDIA_CHANGE_CONTEXT = TCLASS_MEDIA_CHANGE_CONTEXT

type _CLASS_MEDIA_CHANGE_CONTEXT = T_CLASS_MEDIA_CHANGE_CONTEXT

type TPCLASS_MEDIA_CHANGE_CONTEXT = uintptr

type PCLASS_MEDIA_CHANGE_CONTEXT = TPCLASS_MEDIA_CHANGE_CONTEXT

type TTAPE_STATISTICS = struct {
	F__ccgo_align           [0]uint32
	FVersion                TDWORD
	FFlags                  TDWORD
	FRecoveredWrites        TLARGE_INTEGER
	FUnrecoveredWrites      TLARGE_INTEGER
	FRecoveredReads         TLARGE_INTEGER
	FUnrecoveredReads       TLARGE_INTEGER
	FCompressionRatioReads  TBYTE
	FCompressionRatioWrites TBYTE
	F__ccgo_pad8            [6]byte
}

type TAPE_STATISTICS = TTAPE_STATISTICS

type T_TAPE_STATISTICS = TTAPE_STATISTICS

type _TAPE_STATISTICS = T_TAPE_STATISTICS

type TPTAPE_STATISTICS = uintptr

type PTAPE_STATISTICS = TPTAPE_STATISTICS

type TTAPE_GET_STATISTICS = struct {
	FOperation TDWORD
}

type TAPE_GET_STATISTICS = TTAPE_GET_STATISTICS

type T_TAPE_GET_STATISTICS = TTAPE_GET_STATISTICS

type _TAPE_GET_STATISTICS = T_TAPE_GET_STATISTICS

type TPTAPE_GET_STATISTICS = uintptr

type PTAPE_GET_STATISTICS = TPTAPE_GET_STATISTICS

type TSTORAGE_MEDIA_TYPE = int32

type STORAGE_MEDIA_TYPE = TSTORAGE_MEDIA_TYPE

type __STORAGE_MEDIA_TYPE = int32

const _DDS_4mm = 32
const _MiniQic = 33
const _Travan = 34
const _QIC = 35
const _MP_8mm = 36
const _AME_8mm = 37
const _AIT1_8mm = 38
const _DLT = 39
const _NCTP = 40
const _IBM_3480 = 41
const _IBM_3490E = 42
const _IBM_Magstar_3590 = 43
const _IBM_Magstar_MP = 44
const _STK_DATA_D3 = 45
const _SONY_DTF = 46
const _DV_6mm = 47
const _DMI = 48
const _SONY_D2 = 49
const _CLEANER_CARTRIDGE = 50
const _CD_ROM = 51
const _CD_R = 52
const _CD_RW = 53
const _DVD_ROM = 54
const _DVD_R = 55
const _DVD_RW = 56
const _MO_3_RW = 57
const _MO_5_WO = 58
const _MO_5_RW = 59
const _MO_5_LIMDOW = 60
const _PC_5_WO = 61
const _PC_5_RW = 62
const _PD_5_RW = 63
const _ABL_5_WO = 64
const _PINNACLE_APEX_5_RW = 65
const _SONY_12_WO = 66
const _PHILIPS_12_WO = 67
const _HITACHI_12_WO = 68
const _CYGNET_12_WO = 69
const _KODAK_14_WO = 70
const _MO_NFR_525 = 71
const _NIKON_12_RW = 72
const _IOMEGA_ZIP = 73
const _IOMEGA_JAZ = 74
const _SYQUEST_EZ135 = 75
const _SYQUEST_EZFLYER = 76
const _SYQUEST_SYJET = 77
const _AVATAR_F2 = 78
const _MP2_8mm = 79
const _DST_S = 80
const _DST_M = 81
const _DST_L = 82
const _VXATape_1 = 83
const _VXATape_2 = 84
const _STK_9840 = 85
const _LTO_Ultrium = 86
const _LTO_Accelis = 87
const _DVD_RAM = 88
const _AIT_8mm = 89
const _ADR_1 = 90
const _ADR_2 = 91
const _STK_9940 = 92
const _SAIT = 93
const _VXATape = 94

type TPSTORAGE_MEDIA_TYPE = uintptr

type PSTORAGE_MEDIA_TYPE = TPSTORAGE_MEDIA_TYPE

type TSTORAGE_BUS_TYPE = int32

type STORAGE_BUS_TYPE = TSTORAGE_BUS_TYPE

type __STORAGE_BUS_TYPE = int32

const _BusTypeUnknown = 0
const _BusTypeScsi = 1
const _BusTypeAtapi = 2
const _BusTypeAta = 3
const _BusType1394 = 4
const _BusTypeSsa = 5
const _BusTypeFibre = 6
const _BusTypeUsb = 7
const _BusTypeRAID = 8
const _BusTypeiScsi = 9
const _BusTypeSas = 10
const _BusTypeSata = 11
const _BusTypeSd = 12
const _BusTypeMmc = 13
const _BusTypeVirtual = 14
const _BusTypeFileBackedVirtual = 15
const _BusTypeSpaces = 16
const _BusTypeNvme = 17
const _BusTypeSCM = 18
const _BusTypeUfs = 19
const _BusTypeMax = 20
const _BusTypeMaxReserved = 127

type TPSTORAGE_BUS_TYPE = uintptr

type PSTORAGE_BUS_TYPE = TPSTORAGE_BUS_TYPE

type TDEVICE_MEDIA_INFO = struct {
	F__ccgo_align   [0]uint32
	FDeviceSpecific struct {
		F__ccgo_align      [0]uint32
		FRemovableDiskInfo [0]struct {
			F__ccgo_align         [0]uint32
			FCylinders            TLARGE_INTEGER
			FMediaType            TSTORAGE_MEDIA_TYPE
			FTracksPerCylinder    TDWORD
			FSectorsPerTrack      TDWORD
			FBytesPerSector       TDWORD
			FNumberMediaSides     TDWORD
			FMediaCharacteristics TDWORD
		}
		FTapeInfo [0]struct {
			FMediaType            TSTORAGE_MEDIA_TYPE
			FMediaCharacteristics TDWORD
			FCurrentBlockSize     TDWORD
			FBusType              TSTORAGE_BUS_TYPE
			FBusSpecificData      struct {
				FScsiInformation struct {
					FMediumType  TBYTE
					FDensityCode TBYTE
				}
			}
		}
		FDiskInfo struct {
			F__ccgo_align         [0]uint32
			FCylinders            TLARGE_INTEGER
			FMediaType            TSTORAGE_MEDIA_TYPE
			FTracksPerCylinder    TDWORD
			FSectorsPerTrack      TDWORD
			FBytesPerSector       TDWORD
			FNumberMediaSides     TDWORD
			FMediaCharacteristics TDWORD
		}
	}
}

type DEVICE_MEDIA_INFO = TDEVICE_MEDIA_INFO

type T_DEVICE_MEDIA_INFO = TDEVICE_MEDIA_INFO

type _DEVICE_MEDIA_INFO = T_DEVICE_MEDIA_INFO

type TPDEVICE_MEDIA_INFO = uintptr

type PDEVICE_MEDIA_INFO = TPDEVICE_MEDIA_INFO

type TGET_MEDIA_TYPES = struct {
	F__ccgo_align   [0]uint32
	FDeviceType     TDWORD
	FMediaInfoCount TDWORD
	FMediaInfo      [1]TDEVICE_MEDIA_INFO
}

type GET_MEDIA_TYPES = TGET_MEDIA_TYPES

type T_GET_MEDIA_TYPES = TGET_MEDIA_TYPES

type _GET_MEDIA_TYPES = T_GET_MEDIA_TYPES

type TPGET_MEDIA_TYPES = uintptr

type PGET_MEDIA_TYPES = TPGET_MEDIA_TYPES

type TSTORAGE_PREDICT_FAILURE = struct {
	FPredictFailure TDWORD
	FVendorSpecific [512]TBYTE
}

type STORAGE_PREDICT_FAILURE = TSTORAGE_PREDICT_FAILURE

type T_STORAGE_PREDICT_FAILURE = TSTORAGE_PREDICT_FAILURE

type _STORAGE_PREDICT_FAILURE = T_STORAGE_PREDICT_FAILURE

type TPSTORAGE_PREDICT_FAILURE = uintptr

type PSTORAGE_PREDICT_FAILURE = TPSTORAGE_PREDICT_FAILURE

type TSTORAGE_FAILURE_PREDICTION_CONFIG = struct {
	FVersion  TDWORD
	FSize     TDWORD
	FSet      TBOOLEAN
	FEnabled  TBOOLEAN
	FReserved TWORD
}

type STORAGE_FAILURE_PREDICTION_CONFIG = TSTORAGE_FAILURE_PREDICTION_CONFIG

type T_STORAGE_FAILURE_PREDICTION_CONFIG = TSTORAGE_FAILURE_PREDICTION_CONFIG

type _STORAGE_FAILURE_PREDICTION_CONFIG = T_STORAGE_FAILURE_PREDICTION_CONFIG

type TPSTORAGE_FAILURE_PREDICTION_CONFIG = uintptr

type PSTORAGE_FAILURE_PREDICTION_CONFIG = TPSTORAGE_FAILURE_PREDICTION_CONFIG

type TMEDIA_TYPE = int32

type MEDIA_TYPE = TMEDIA_TYPE

type __MEDIA_TYPE = int32

const _Unknown = 0
const _F5_1Pt2_512 = 1
const _F3_1Pt44_512 = 2
const _F3_2Pt88_512 = 3
const _F3_20Pt8_512 = 4
const _F3_720_512 = 5
const _F5_360_512 = 6
const _F5_320_512 = 7
const _F5_320_1024 = 8
const _F5_180_512 = 9
const _F5_160_512 = 10
const _RemovableMedia = 11
const _FixedMedia = 12
const _F3_120M_512 = 13
const _F3_640_512 = 14
const _F5_640_512 = 15
const _F5_720_512 = 16
const _F3_1Pt2_512 = 17
const _F3_1Pt23_1024 = 18
const _F5_1Pt23_1024 = 19
const _F3_128Mb_512 = 20
const _F3_230Mb_512 = 21
const _F8_256_128 = 22
const _F3_200Mb_512 = 23
const _F3_240M_512 = 24
const _F3_32M_512 = 25

type TPMEDIA_TYPE = uintptr

type PMEDIA_TYPE = TPMEDIA_TYPE

type TFORMAT_PARAMETERS = struct {
	FMediaType           TMEDIA_TYPE
	FStartCylinderNumber TDWORD
	FEndCylinderNumber   TDWORD
	FStartHeadNumber     TDWORD
	FEndHeadNumber       TDWORD
}

type FORMAT_PARAMETERS = TFORMAT_PARAMETERS

type T_FORMAT_PARAMETERS = TFORMAT_PARAMETERS

type _FORMAT_PARAMETERS = T_FORMAT_PARAMETERS

type TPFORMAT_PARAMETERS = uintptr

type PFORMAT_PARAMETERS = TPFORMAT_PARAMETERS

type TBAD_TRACK_NUMBER = uint16

type BAD_TRACK_NUMBER = TBAD_TRACK_NUMBER

type TPBAD_TRACK_NUMBER = uintptr

type PBAD_TRACK_NUMBER = TPBAD_TRACK_NUMBER

type TFORMAT_EX_PARAMETERS = struct {
	FMediaType           TMEDIA_TYPE
	FStartCylinderNumber TDWORD
	FEndCylinderNumber   TDWORD
	FStartHeadNumber     TDWORD
	FEndHeadNumber       TDWORD
	FFormatGapLength     TWORD
	FSectorsPerTrack     TWORD
	FSectorNumber        [1]TWORD
}

type FORMAT_EX_PARAMETERS = TFORMAT_EX_PARAMETERS

type T_FORMAT_EX_PARAMETERS = TFORMAT_EX_PARAMETERS

type _FORMAT_EX_PARAMETERS = T_FORMAT_EX_PARAMETERS

type TPFORMAT_EX_PARAMETERS = uintptr

type PFORMAT_EX_PARAMETERS = TPFORMAT_EX_PARAMETERS

type TDISK_GEOMETRY = struct {
	F__ccgo_align      [0]uint32
	FCylinders         TLARGE_INTEGER
	FMediaType         TMEDIA_TYPE
	FTracksPerCylinder TDWORD
	FSectorsPerTrack   TDWORD
	FBytesPerSector    TDWORD
}

type DISK_GEOMETRY = TDISK_GEOMETRY

type T_DISK_GEOMETRY = TDISK_GEOMETRY

type _DISK_GEOMETRY = T_DISK_GEOMETRY

type TPDISK_GEOMETRY = uintptr

type PDISK_GEOMETRY = TPDISK_GEOMETRY

type TPARTITION_INFORMATION = struct {
	F__ccgo_align        [0]uint32
	FStartingOffset      TLARGE_INTEGER
	FPartitionLength     TLARGE_INTEGER
	FHiddenSectors       TDWORD
	FPartitionNumber     TDWORD
	FPartitionType       TBYTE
	FBootIndicator       TBOOLEAN
	FRecognizedPartition TBOOLEAN
	FRewritePartition    TBOOLEAN
	F__ccgo_pad8         [4]byte
}

type PARTITION_INFORMATION = TPARTITION_INFORMATION

type T_PARTITION_INFORMATION = TPARTITION_INFORMATION

type _PARTITION_INFORMATION = T_PARTITION_INFORMATION

type TPPARTITION_INFORMATION = uintptr

type PPARTITION_INFORMATION = TPPARTITION_INFORMATION

type TSET_PARTITION_INFORMATION = struct {
	FPartitionType TBYTE
}

type SET_PARTITION_INFORMATION = TSET_PARTITION_INFORMATION

type T_SET_PARTITION_INFORMATION = TSET_PARTITION_INFORMATION

type _SET_PARTITION_INFORMATION = T_SET_PARTITION_INFORMATION

type TPSET_PARTITION_INFORMATION = uintptr

type PSET_PARTITION_INFORMATION = TPSET_PARTITION_INFORMATION

type TDRIVE_LAYOUT_INFORMATION = struct {
	F__ccgo_align   [0]uint32
	FPartitionCount TDWORD
	FSignature      TDWORD
	FPartitionEntry [1]TPARTITION_INFORMATION
}

type DRIVE_LAYOUT_INFORMATION = TDRIVE_LAYOUT_INFORMATION

type T_DRIVE_LAYOUT_INFORMATION = TDRIVE_LAYOUT_INFORMATION

type _DRIVE_LAYOUT_INFORMATION = T_DRIVE_LAYOUT_INFORMATION

type TPDRIVE_LAYOUT_INFORMATION = uintptr

type PDRIVE_LAYOUT_INFORMATION = TPDRIVE_LAYOUT_INFORMATION

type TVERIFY_INFORMATION = struct {
	F__ccgo_align   [0]uint32
	FStartingOffset TLARGE_INTEGER
	FLength         TDWORD
	F__ccgo_pad2    [4]byte
}

type VERIFY_INFORMATION = TVERIFY_INFORMATION

type T_VERIFY_INFORMATION = TVERIFY_INFORMATION

type _VERIFY_INFORMATION = T_VERIFY_INFORMATION

type TPVERIFY_INFORMATION = uintptr

type PVERIFY_INFORMATION = TPVERIFY_INFORMATION

type TREASSIGN_BLOCKS = struct {
	FReserved    TWORD
	FCount       TWORD
	FBlockNumber [1]TDWORD
}

type REASSIGN_BLOCKS = TREASSIGN_BLOCKS

type T_REASSIGN_BLOCKS = TREASSIGN_BLOCKS

type _REASSIGN_BLOCKS = T_REASSIGN_BLOCKS

type TPREASSIGN_BLOCKS = uintptr

type PREASSIGN_BLOCKS = TPREASSIGN_BLOCKS

type TREASSIGN_BLOCKS_EX = struct {
	F__ccgo_align  [0]uint32
	FReserved      TWORD
	FCount         TWORD
	F__ccgo_align2 [4]byte
	FBlockNumber   [1]TLARGE_INTEGER
}

type REASSIGN_BLOCKS_EX = TREASSIGN_BLOCKS_EX

type T_REASSIGN_BLOCKS_EX = TREASSIGN_BLOCKS_EX

type _REASSIGN_BLOCKS_EX = T_REASSIGN_BLOCKS_EX

type TPREASSIGN_BLOCKS_EX = uintptr

type PREASSIGN_BLOCKS_EX = TPREASSIGN_BLOCKS_EX

type TPARTITION_STYLE = int32

type PARTITION_STYLE = TPARTITION_STYLE

type __PARTITION_STYLE = int32

const _PARTITION_STYLE_MBR = 0
const _PARTITION_STYLE_GPT = 1
const _PARTITION_STYLE_RAW = 2

type TPARTITION_INFORMATION_GPT = struct {
	F__ccgo_align  [0]uint32
	FPartitionType TGUID
	FPartitionId   TGUID
	FAttributes    TDWORD64
	FName          [36]TWCHAR
}

type PARTITION_INFORMATION_GPT = TPARTITION_INFORMATION_GPT

type T_PARTITION_INFORMATION_GPT = TPARTITION_INFORMATION_GPT

type _PARTITION_INFORMATION_GPT = T_PARTITION_INFORMATION_GPT

type TPPARTITION_INFORMATION_GPT = uintptr

type PPARTITION_INFORMATION_GPT = TPPARTITION_INFORMATION_GPT

type TPARTITION_INFORMATION_MBR = struct {
	FPartitionType       TBYTE
	FBootIndicator       TBOOLEAN
	FRecognizedPartition TBOOLEAN
	FHiddenSectors       TDWORD
	FPartitionId         TGUID
}

type PARTITION_INFORMATION_MBR = TPARTITION_INFORMATION_MBR

type T_PARTITION_INFORMATION_MBR = TPARTITION_INFORMATION_MBR

type _PARTITION_INFORMATION_MBR = T_PARTITION_INFORMATION_MBR

type TPPARTITION_INFORMATION_MBR = uintptr

type PPARTITION_INFORMATION_MBR = TPPARTITION_INFORMATION_MBR

type TSET_PARTITION_INFORMATION_MBR = struct {
	FPartitionType TBYTE
}

type SET_PARTITION_INFORMATION_MBR = TSET_PARTITION_INFORMATION_MBR

type TSET_PARTITION_INFORMATION_GPT = struct {
	F__ccgo_align  [0]uint32
	FPartitionType TGUID
	FPartitionId   TGUID
	FAttributes    TDWORD64
	FName          [36]TWCHAR
}

type SET_PARTITION_INFORMATION_GPT = TSET_PARTITION_INFORMATION_GPT

type TSET_PARTITION_INFORMATION_EX = struct {
	F__ccgo_align   [0]uint32
	FPartitionStyle TPARTITION_STYLE
	F__ccgo_align1  [4]byte
	F__ccgo1_8      struct {
		F__ccgo_align [0]uint32
		FGpt          [0]TSET_PARTITION_INFORMATION_GPT
		FMbr          TSET_PARTITION_INFORMATION_MBR
		F__ccgo_pad2  [111]byte
	}
}

type SET_PARTITION_INFORMATION_EX = TSET_PARTITION_INFORMATION_EX

type T_SET_PARTITION_INFORMATION_EX = TSET_PARTITION_INFORMATION_EX

type _SET_PARTITION_INFORMATION_EX = T_SET_PARTITION_INFORMATION_EX

type TPSET_PARTITION_INFORMATION_EX = uintptr

type PSET_PARTITION_INFORMATION_EX = TPSET_PARTITION_INFORMATION_EX

type TCREATE_DISK_GPT = struct {
	FDiskId            TGUID
	FMaxPartitionCount TDWORD
}

type CREATE_DISK_GPT = TCREATE_DISK_GPT

type T_CREATE_DISK_GPT = TCREATE_DISK_GPT

type _CREATE_DISK_GPT = T_CREATE_DISK_GPT

type TPCREATE_DISK_GPT = uintptr

type PCREATE_DISK_GPT = TPCREATE_DISK_GPT

type TCREATE_DISK_MBR = struct {
	FSignature TDWORD
}

type CREATE_DISK_MBR = TCREATE_DISK_MBR

type T_CREATE_DISK_MBR = TCREATE_DISK_MBR

type _CREATE_DISK_MBR = T_CREATE_DISK_MBR

type TPCREATE_DISK_MBR = uintptr

type PCREATE_DISK_MBR = TPCREATE_DISK_MBR

type TCREATE_DISK = struct {
	FPartitionStyle TPARTITION_STYLE
	F__ccgo1_4      struct {
		FGpt         [0]TCREATE_DISK_GPT
		FMbr         TCREATE_DISK_MBR
		F__ccgo_pad2 [16]byte
	}
}

type CREATE_DISK = TCREATE_DISK

type T_CREATE_DISK = TCREATE_DISK

type _CREATE_DISK = T_CREATE_DISK

type TPCREATE_DISK = uintptr

type PCREATE_DISK = TPCREATE_DISK

type TGET_LENGTH_INFORMATION = struct {
	F__ccgo_align [0]uint32
	FLength       TLARGE_INTEGER
}

type GET_LENGTH_INFORMATION = TGET_LENGTH_INFORMATION

type T_GET_LENGTH_INFORMATION = TGET_LENGTH_INFORMATION

type _GET_LENGTH_INFORMATION = T_GET_LENGTH_INFORMATION

type TPGET_LENGTH_INFORMATION = uintptr

type PGET_LENGTH_INFORMATION = TPGET_LENGTH_INFORMATION

type TPARTITION_INFORMATION_EX = struct {
	F__ccgo_align     [0]uint32
	FPartitionStyle   TPARTITION_STYLE
	F__ccgo_align1    [4]byte
	FStartingOffset   TLARGE_INTEGER
	FPartitionLength  TLARGE_INTEGER
	FPartitionNumber  TDWORD
	FRewritePartition TBOOLEAN
	F__ccgo_align5    [3]byte
	F__ccgo5_32       struct {
		F__ccgo_align [0]uint32
		FGpt          [0]TPARTITION_INFORMATION_GPT
		FMbr          TPARTITION_INFORMATION_MBR
		F__ccgo_pad2  [88]byte
	}
}

type PARTITION_INFORMATION_EX = TPARTITION_INFORMATION_EX

type T_PARTITION_INFORMATION_EX = TPARTITION_INFORMATION_EX

type _PARTITION_INFORMATION_EX = T_PARTITION_INFORMATION_EX

type TPPARTITION_INFORMATION_EX = uintptr

type PPARTITION_INFORMATION_EX = TPPARTITION_INFORMATION_EX

type TDRIVE_LAYOUT_INFORMATION_GPT = struct {
	F__ccgo_align         [0]uint32
	FDiskId               TGUID
	FStartingUsableOffset TLARGE_INTEGER
	FUsableLength         TLARGE_INTEGER
	FMaxPartitionCount    TDWORD
	F__ccgo_pad4          [4]byte
}

type DRIVE_LAYOUT_INFORMATION_GPT = TDRIVE_LAYOUT_INFORMATION_GPT

type T_DRIVE_LAYOUT_INFORMATION_GPT = TDRIVE_LAYOUT_INFORMATION_GPT

type _DRIVE_LAYOUT_INFORMATION_GPT = T_DRIVE_LAYOUT_INFORMATION_GPT

type TPDRIVE_LAYOUT_INFORMATION_GPT = uintptr

type PDRIVE_LAYOUT_INFORMATION_GPT = TPDRIVE_LAYOUT_INFORMATION_GPT

type TDRIVE_LAYOUT_INFORMATION_MBR = struct {
	FSignature TDWORD
}

type DRIVE_LAYOUT_INFORMATION_MBR = TDRIVE_LAYOUT_INFORMATION_MBR

type T_DRIVE_LAYOUT_INFORMATION_MBR = TDRIVE_LAYOUT_INFORMATION_MBR

type _DRIVE_LAYOUT_INFORMATION_MBR = T_DRIVE_LAYOUT_INFORMATION_MBR

type TPDRIVE_LAYOUT_INFORMATION_MBR = uintptr

type PDRIVE_LAYOUT_INFORMATION_MBR = TPDRIVE_LAYOUT_INFORMATION_MBR

type TDRIVE_LAYOUT_INFORMATION_EX = struct {
	F__ccgo_align   [0]uint32
	FPartitionStyle TDWORD
	FPartitionCount TDWORD
	F__ccgo2_8      struct {
		F__ccgo_align [0]uint32
		FGpt          [0]TDRIVE_LAYOUT_INFORMATION_GPT
		FMbr          TDRIVE_LAYOUT_INFORMATION_MBR
		F__ccgo_pad2  [36]byte
	}
	FPartitionEntry [1]TPARTITION_INFORMATION_EX
}

type DRIVE_LAYOUT_INFORMATION_EX = TDRIVE_LAYOUT_INFORMATION_EX

type T_DRIVE_LAYOUT_INFORMATION_EX = TDRIVE_LAYOUT_INFORMATION_EX

type _DRIVE_LAYOUT_INFORMATION_EX = T_DRIVE_LAYOUT_INFORMATION_EX

type TPDRIVE_LAYOUT_INFORMATION_EX = uintptr

type PDRIVE_LAYOUT_INFORMATION_EX = TPDRIVE_LAYOUT_INFORMATION_EX

type TDETECTION_TYPE = int32

type DETECTION_TYPE = TDETECTION_TYPE

type __DETECTION_TYPE = int32

const _DetectNone = 0
const _DetectInt13 = 1
const _DetectExInt13 = 2

type TDISK_INT13_INFO = struct {
	FDriveSelect     TWORD
	FMaxCylinders    TDWORD
	FSectorsPerTrack TWORD
	FMaxHeads        TWORD
	FNumberDrives    TWORD
}

type DISK_INT13_INFO = TDISK_INT13_INFO

type T_DISK_INT13_INFO = TDISK_INT13_INFO

type _DISK_INT13_INFO = T_DISK_INT13_INFO

type TPDISK_INT13_INFO = uintptr

type PDISK_INT13_INFO = TPDISK_INT13_INFO

type TDISK_EX_INT13_INFO = struct {
	F__ccgo_align      [0]uint32
	FExBufferSize      TWORD
	FExFlags           TWORD
	FExCylinders       TDWORD
	FExHeads           TDWORD
	FExSectorsPerTrack TDWORD
	FExSectorsPerDrive TDWORD64
	FExSectorSize      TWORD
	FExReserved        TWORD
	F__ccgo_pad8       [4]byte
}

type DISK_EX_INT13_INFO = TDISK_EX_INT13_INFO

type T_DISK_EX_INT13_INFO = TDISK_EX_INT13_INFO

type _DISK_EX_INT13_INFO = T_DISK_EX_INT13_INFO

type TPDISK_EX_INT13_INFO = uintptr

type PDISK_EX_INT13_INFO = TPDISK_EX_INT13_INFO

type TDISK_DETECTION_INFO = struct {
	F__ccgo_align     [0]uint32
	FSizeOfDetectInfo TDWORD
	FDetectionType    TDETECTION_TYPE
	F__ccgo2_8        struct {
		F__ccgo_align [0]uint32
		F__ccgo0_0    struct {
			F__ccgo_align [0]uint32
			FInt13        TDISK_INT13_INFO
			FExInt13      TDISK_EX_INT13_INFO
		}
	}
}

type DISK_DETECTION_INFO = TDISK_DETECTION_INFO

type T_DISK_DETECTION_INFO = TDISK_DETECTION_INFO

type _DISK_DETECTION_INFO = T_DISK_DETECTION_INFO

type TPDISK_DETECTION_INFO = uintptr

type PDISK_DETECTION_INFO = TPDISK_DETECTION_INFO

type TDISK_PARTITION_INFO = struct {
	FSizeOfPartitionInfo TDWORD
	FPartitionStyle      TPARTITION_STYLE
	F__ccgo2_8           struct {
		FGpt [0]struct {
			FDiskId TGUID
		}
		FMbr struct {
			FSignature TDWORD
			FCheckSum  TDWORD
		}
		F__ccgo_pad2 [8]byte
	}
}

type DISK_PARTITION_INFO = TDISK_PARTITION_INFO

type T_DISK_PARTITION_INFO = TDISK_PARTITION_INFO

type _DISK_PARTITION_INFO = T_DISK_PARTITION_INFO

type TPDISK_PARTITION_INFO = uintptr

type PDISK_PARTITION_INFO = TPDISK_PARTITION_INFO

type TDISK_GEOMETRY_EX = struct {
	F__ccgo_align [0]uint32
	FGeometry     TDISK_GEOMETRY
	FDiskSize     TLARGE_INTEGER
	FData         [1]TBYTE
	F__ccgo_pad3  [7]byte
}

type DISK_GEOMETRY_EX = TDISK_GEOMETRY_EX

type T_DISK_GEOMETRY_EX = TDISK_GEOMETRY_EX

type _DISK_GEOMETRY_EX = T_DISK_GEOMETRY_EX

type TPDISK_GEOMETRY_EX = uintptr

type PDISK_GEOMETRY_EX = TPDISK_GEOMETRY_EX

type TDISK_CONTROLLER_NUMBER = struct {
	FControllerNumber TDWORD
	FDiskNumber       TDWORD
}

type DISK_CONTROLLER_NUMBER = TDISK_CONTROLLER_NUMBER

type T_DISK_CONTROLLER_NUMBER = TDISK_CONTROLLER_NUMBER

type _DISK_CONTROLLER_NUMBER = T_DISK_CONTROLLER_NUMBER

type TPDISK_CONTROLLER_NUMBER = uintptr

type PDISK_CONTROLLER_NUMBER = TPDISK_CONTROLLER_NUMBER

type TDISK_CACHE_RETENTION_PRIORITY = int32

type DISK_CACHE_RETENTION_PRIORITY = TDISK_CACHE_RETENTION_PRIORITY

const _EqualPriority = 0
const _KeepPrefetchedData = 1
const _KeepReadData = 2

type TDISK_CACHE_INFORMATION = struct {
	FParametersSavable             TBOOLEAN
	FReadCacheEnabled              TBOOLEAN
	FWriteCacheEnabled             TBOOLEAN
	FReadRetentionPriority         TDISK_CACHE_RETENTION_PRIORITY
	FWriteRetentionPriority        TDISK_CACHE_RETENTION_PRIORITY
	FDisablePrefetchTransferLength TWORD
	FPrefetchScalar                TBOOLEAN
	F__ccgo7_16                    struct {
		FBlockPrefetch [0]struct {
			FMinimum TWORD
			FMaximum TWORD
		}
		FScalarPrefetch struct {
			FMinimum       TWORD
			FMaximum       TWORD
			FMaximumBlocks TWORD
		}
	}
}

type DISK_CACHE_INFORMATION = TDISK_CACHE_INFORMATION

type T_DISK_CACHE_INFORMATION = TDISK_CACHE_INFORMATION

type _DISK_CACHE_INFORMATION = T_DISK_CACHE_INFORMATION

type TPDISK_CACHE_INFORMATION = uintptr

type PDISK_CACHE_INFORMATION = TPDISK_CACHE_INFORMATION

type TDISK_GROW_PARTITION = struct {
	F__ccgo_align    [0]uint32
	FPartitionNumber TDWORD
	F__ccgo_align1   [4]byte
	FBytesToGrow     TLARGE_INTEGER
}

type DISK_GROW_PARTITION = TDISK_GROW_PARTITION

type T_DISK_GROW_PARTITION = TDISK_GROW_PARTITION

type _DISK_GROW_PARTITION = T_DISK_GROW_PARTITION

type TPDISK_GROW_PARTITION = uintptr

type PDISK_GROW_PARTITION = TPDISK_GROW_PARTITION

type THISTOGRAM_BUCKET = struct {
	FReads  TDWORD
	FWrites TDWORD
}

type HISTOGRAM_BUCKET = THISTOGRAM_BUCKET

type T_HISTOGRAM_BUCKET = THISTOGRAM_BUCKET

type _HISTOGRAM_BUCKET = T_HISTOGRAM_BUCKET

type TPHISTOGRAM_BUCKET = uintptr

type PHISTOGRAM_BUCKET = TPHISTOGRAM_BUCKET

type TDISK_HISTOGRAM = struct {
	F__ccgo_align [0]uint32
	FDiskSize     TLARGE_INTEGER
	FStart        TLARGE_INTEGER
	FEnd          TLARGE_INTEGER
	FAverage      TLARGE_INTEGER
	FAverageRead  TLARGE_INTEGER
	FAverageWrite TLARGE_INTEGER
	FGranularity  TDWORD
	FSize         TDWORD
	FReadCount    TDWORD
	FWriteCount   TDWORD
	FHistogram    TPHISTOGRAM_BUCKET
	F__ccgo_pad11 [4]byte
}

type DISK_HISTOGRAM = TDISK_HISTOGRAM

type T_DISK_HISTOGRAM = TDISK_HISTOGRAM

type _DISK_HISTOGRAM = T_DISK_HISTOGRAM

type TPDISK_HISTOGRAM = uintptr

type PDISK_HISTOGRAM = TPDISK_HISTOGRAM

type TDISK_PERFORMANCE = struct {
	F__ccgo_align        [0]uint32
	FBytesRead           TLARGE_INTEGER
	FBytesWritten        TLARGE_INTEGER
	FReadTime            TLARGE_INTEGER
	FWriteTime           TLARGE_INTEGER
	FIdleTime            TLARGE_INTEGER
	FReadCount           TDWORD
	FWriteCount          TDWORD
	FQueueDepth          TDWORD
	FSplitCount          TDWORD
	FQueryTime           TLARGE_INTEGER
	FStorageDeviceNumber TDWORD
	FStorageManagerName  [8]TWCHAR
	F__ccgo_pad12        [4]byte
}

type DISK_PERFORMANCE = TDISK_PERFORMANCE

type T_DISK_PERFORMANCE = TDISK_PERFORMANCE

type _DISK_PERFORMANCE = T_DISK_PERFORMANCE

type TPDISK_PERFORMANCE = uintptr

type PDISK_PERFORMANCE = TPDISK_PERFORMANCE

type TDISK_RECORD = struct {
	F__ccgo_align   [0]uint32
	FByteOffset     TLARGE_INTEGER
	FStartTime      TLARGE_INTEGER
	FEndTime        TLARGE_INTEGER
	FVirtualAddress TPVOID
	FNumberOfBytes  TDWORD
	FDeviceNumber   TBYTE
	FReadRequest    TBOOLEAN
	F__ccgo_pad7    [6]byte
}

type DISK_RECORD = TDISK_RECORD

type T_DISK_RECORD = TDISK_RECORD

type _DISK_RECORD = T_DISK_RECORD

type TPDISK_RECORD = uintptr

type PDISK_RECORD = TPDISK_RECORD

type TDISK_LOGGING = struct {
	FFunction      TBYTE
	FBufferAddress TPVOID
	FBufferSize    TDWORD
}

type DISK_LOGGING = TDISK_LOGGING

type T_DISK_LOGGING = TDISK_LOGGING

type _DISK_LOGGING = T_DISK_LOGGING

type TPDISK_LOGGING = uintptr

type PDISK_LOGGING = TPDISK_LOGGING

type TBIN_TYPES = int32

type BIN_TYPES = TBIN_TYPES

type __BIN_TYPES = int32

const _RequestSize = 0
const _RequestLocation = 1

type TBIN_RANGE = struct {
	F__ccgo_align [0]uint32
	FStartValue   TLARGE_INTEGER
	FLength       TLARGE_INTEGER
}

type BIN_RANGE = TBIN_RANGE

type T_BIN_RANGE = TBIN_RANGE

type _BIN_RANGE = T_BIN_RANGE

type TPBIN_RANGE = uintptr

type PBIN_RANGE = TPBIN_RANGE

type TPERF_BIN = struct {
	F__ccgo_align [0]uint32
	FNumberOfBins TDWORD
	FTypeOfBin    TDWORD
	FBinsRanges   [1]TBIN_RANGE
}

type PERF_BIN = TPERF_BIN

type T_PERF_BIN = TPERF_BIN

type _PERF_BIN = T_PERF_BIN

type TPPERF_BIN = uintptr

type PPERF_BIN = TPPERF_BIN

type TBIN_COUNT = struct {
	F__ccgo_align [0]uint32
	FBinRange     TBIN_RANGE
	FBinCount     TDWORD
	F__ccgo_pad2  [4]byte
}

type BIN_COUNT = TBIN_COUNT

type T_BIN_COUNT = TBIN_COUNT

type _BIN_COUNT = T_BIN_COUNT

type TPBIN_COUNT = uintptr

type PBIN_COUNT = TPBIN_COUNT

type TBIN_RESULTS = struct {
	F__ccgo_align  [0]uint32
	FNumberOfBins  TDWORD
	F__ccgo_align1 [4]byte
	FBinCounts     [1]TBIN_COUNT
}

type BIN_RESULTS = TBIN_RESULTS

type T_BIN_RESULTS = TBIN_RESULTS

type _BIN_RESULTS = T_BIN_RESULTS

type TPBIN_RESULTS = uintptr

type PBIN_RESULTS = TPBIN_RESULTS

type TGETVERSIONINPARAMS = struct {
	FbVersion      TBYTE
	FbRevision     TBYTE
	FbReserved     TBYTE
	FbIDEDeviceMap TBYTE
	FfCapabilities TDWORD
	FdwReserved    [4]TDWORD
}

type GETVERSIONINPARAMS = TGETVERSIONINPARAMS

type T_GETVERSIONINPARAMS = TGETVERSIONINPARAMS

type _GETVERSIONINPARAMS = T_GETVERSIONINPARAMS

type TPGETVERSIONINPARAMS = uintptr

type PGETVERSIONINPARAMS = TPGETVERSIONINPARAMS

type TLPGETVERSIONINPARAMS = uintptr

type LPGETVERSIONINPARAMS = TLPGETVERSIONINPARAMS

type TIDEREGS = struct {
	FbFeaturesReg     TBYTE
	FbSectorCountReg  TBYTE
	FbSectorNumberReg TBYTE
	FbCylLowReg       TBYTE
	FbCylHighReg      TBYTE
	FbDriveHeadReg    TBYTE
	FbCommandReg      TBYTE
	FbReserved        TBYTE
}

type IDEREGS = TIDEREGS

type T_IDEREGS = TIDEREGS

type _IDEREGS = T_IDEREGS

type TPIDEREGS = uintptr

type PIDEREGS = TPIDEREGS

type TLPIDEREGS = uintptr

type LPIDEREGS = TLPIDEREGS

type TSENDCMDINPARAMS = struct {
	FcBufferSize  TDWORD
	FirDriveRegs  TIDEREGS
	FbDriveNumber TBYTE
	FbReserved    [3]TBYTE
	FdwReserved   [4]TDWORD
	FbBuffer      [1]TBYTE
}

type SENDCMDINPARAMS = TSENDCMDINPARAMS

type T_SENDCMDINPARAMS = TSENDCMDINPARAMS

type _SENDCMDINPARAMS = T_SENDCMDINPARAMS

type TPSENDCMDINPARAMS = uintptr

type PSENDCMDINPARAMS = TPSENDCMDINPARAMS

type TLPSENDCMDINPARAMS = uintptr

type LPSENDCMDINPARAMS = TLPSENDCMDINPARAMS

type TDRIVERSTATUS = struct {
	FbDriverError TBYTE
	FbIDEError    TBYTE
	FbReserved    [2]TBYTE
	FdwReserved   [2]TDWORD
}

type DRIVERSTATUS = TDRIVERSTATUS

type T_DRIVERSTATUS = TDRIVERSTATUS

type _DRIVERSTATUS = T_DRIVERSTATUS

type TPDRIVERSTATUS = uintptr

type PDRIVERSTATUS = TPDRIVERSTATUS

type TLPDRIVERSTATUS = uintptr

type LPDRIVERSTATUS = TLPDRIVERSTATUS

type TSENDCMDOUTPARAMS = struct {
	FcBufferSize  TDWORD
	FDriverStatus TDRIVERSTATUS
	FbBuffer      [1]TBYTE
}

type SENDCMDOUTPARAMS = TSENDCMDOUTPARAMS

type T_SENDCMDOUTPARAMS = TSENDCMDOUTPARAMS

type _SENDCMDOUTPARAMS = T_SENDCMDOUTPARAMS

type TPSENDCMDOUTPARAMS = uintptr

type PSENDCMDOUTPARAMS = TPSENDCMDOUTPARAMS

type TLPSENDCMDOUTPARAMS = uintptr

type LPSENDCMDOUTPARAMS = TLPSENDCMDOUTPARAMS

type TELEMENT_TYPE = int32

type ELEMENT_TYPE = TELEMENT_TYPE

type __ELEMENT_TYPE = int32

const _AllElements = 0
const _ChangerTransport = 1
const _ChangerSlot = 2
const _ChangerIEPort = 3
const _ChangerDrive = 4
const _ChangerDoor = 5
const _ChangerKeypad = 6
const _ChangerMaxElement = 7

type TPELEMENT_TYPE = uintptr

type PELEMENT_TYPE = TPELEMENT_TYPE

type TCHANGER_ELEMENT = struct {
	FElementType    TELEMENT_TYPE
	FElementAddress TDWORD
}

type CHANGER_ELEMENT = TCHANGER_ELEMENT

type T_CHANGER_ELEMENT = TCHANGER_ELEMENT

type _CHANGER_ELEMENT = T_CHANGER_ELEMENT

type TPCHANGER_ELEMENT = uintptr

type PCHANGER_ELEMENT = TPCHANGER_ELEMENT

type TCHANGER_ELEMENT_LIST = struct {
	FElement          TCHANGER_ELEMENT
	FNumberOfElements TDWORD
}

type CHANGER_ELEMENT_LIST = TCHANGER_ELEMENT_LIST

type T_CHANGER_ELEMENT_LIST = TCHANGER_ELEMENT_LIST

type _CHANGER_ELEMENT_LIST = T_CHANGER_ELEMENT_LIST

type TPCHANGER_ELEMENT_LIST = uintptr

type PCHANGER_ELEMENT_LIST = TPCHANGER_ELEMENT_LIST

type TGET_CHANGER_PARAMETERS = struct {
	FSize                       TDWORD
	FNumberTransportElements    TWORD
	FNumberStorageElements      TWORD
	FNumberCleanerSlots         TWORD
	FNumberIEElements           TWORD
	FNumberDataTransferElements TWORD
	FNumberOfDoors              TWORD
	FFirstSlotNumber            TWORD
	FFirstDriveNumber           TWORD
	FFirstTransportNumber       TWORD
	FFirstIEPortNumber          TWORD
	FFirstCleanerSlotAddress    TWORD
	FMagazineSize               TWORD
	FDriveCleanTimeout          TDWORD
	FFeatures0                  TDWORD
	FFeatures1                  TDWORD
	FMoveFromTransport          TBYTE
	FMoveFromSlot               TBYTE
	FMoveFromIePort             TBYTE
	FMoveFromDrive              TBYTE
	FExchangeFromTransport      TBYTE
	FExchangeFromSlot           TBYTE
	FExchangeFromIePort         TBYTE
	FExchangeFromDrive          TBYTE
	FLockUnlockCapabilities     TBYTE
	FPositionCapabilities       TBYTE
	FReserved1                  [2]TBYTE
	FReserved2                  [2]TDWORD
}

type GET_CHANGER_PARAMETERS = TGET_CHANGER_PARAMETERS

type T_GET_CHANGER_PARAMETERS = TGET_CHANGER_PARAMETERS

type _GET_CHANGER_PARAMETERS = T_GET_CHANGER_PARAMETERS

type TPGET_CHANGER_PARAMETERS = uintptr

type PGET_CHANGER_PARAMETERS = TPGET_CHANGER_PARAMETERS

type TCHANGER_PRODUCT_DATA = struct {
	FVendorId     [8]TBYTE
	FProductId    [16]TBYTE
	FRevision     [4]TBYTE
	FSerialNumber [32]TBYTE
	FDeviceType   TBYTE
}

type CHANGER_PRODUCT_DATA = TCHANGER_PRODUCT_DATA

type T_CHANGER_PRODUCT_DATA = TCHANGER_PRODUCT_DATA

type _CHANGER_PRODUCT_DATA = T_CHANGER_PRODUCT_DATA

type TPCHANGER_PRODUCT_DATA = uintptr

type PCHANGER_PRODUCT_DATA = TPCHANGER_PRODUCT_DATA

type TCHANGER_SET_ACCESS = struct {
	FElement TCHANGER_ELEMENT
	FControl TDWORD
}

type CHANGER_SET_ACCESS = TCHANGER_SET_ACCESS

type T_CHANGER_SET_ACCESS = TCHANGER_SET_ACCESS

type _CHANGER_SET_ACCESS = T_CHANGER_SET_ACCESS

type TPCHANGER_SET_ACCESS = uintptr

type PCHANGER_SET_ACCESS = TPCHANGER_SET_ACCESS

type TCHANGER_READ_ELEMENT_STATUS = struct {
	FElementList   TCHANGER_ELEMENT_LIST
	FVolumeTagInfo TBOOLEAN
}

type CHANGER_READ_ELEMENT_STATUS = TCHANGER_READ_ELEMENT_STATUS

type T_CHANGER_READ_ELEMENT_STATUS = TCHANGER_READ_ELEMENT_STATUS

type _CHANGER_READ_ELEMENT_STATUS = T_CHANGER_READ_ELEMENT_STATUS

type TPCHANGER_READ_ELEMENT_STATUS = uintptr

type PCHANGER_READ_ELEMENT_STATUS = TPCHANGER_READ_ELEMENT_STATUS

type TCHANGER_ELEMENT_STATUS = struct {
	FElement           TCHANGER_ELEMENT
	FSrcElementAddress TCHANGER_ELEMENT
	FFlags             TDWORD
	FExceptionCode     TDWORD
	FTargetId          TBYTE
	FLun               TBYTE
	FReserved          TWORD
	FPrimaryVolumeID   [36]TBYTE
	FAlternateVolumeID [36]TBYTE
}

type CHANGER_ELEMENT_STATUS = TCHANGER_ELEMENT_STATUS

type T_CHANGER_ELEMENT_STATUS = TCHANGER_ELEMENT_STATUS

type _CHANGER_ELEMENT_STATUS = T_CHANGER_ELEMENT_STATUS

type TPCHANGER_ELEMENT_STATUS = uintptr

type PCHANGER_ELEMENT_STATUS = TPCHANGER_ELEMENT_STATUS

type TCHANGER_ELEMENT_STATUS_EX = struct {
	FElement               TCHANGER_ELEMENT
	FSrcElementAddress     TCHANGER_ELEMENT
	FFlags                 TDWORD
	FExceptionCode         TDWORD
	FTargetId              TBYTE
	FLun                   TBYTE
	FReserved              TWORD
	FPrimaryVolumeID       [36]TBYTE
	FAlternateVolumeID     [36]TBYTE
	FVendorIdentification  [8]TBYTE
	FProductIdentification [16]TBYTE
	FSerialNumber          [32]TBYTE
}

type CHANGER_ELEMENT_STATUS_EX = TCHANGER_ELEMENT_STATUS_EX

type T_CHANGER_ELEMENT_STATUS_EX = TCHANGER_ELEMENT_STATUS_EX

type _CHANGER_ELEMENT_STATUS_EX = T_CHANGER_ELEMENT_STATUS_EX

type TPCHANGER_ELEMENT_STATUS_EX = uintptr

type PCHANGER_ELEMENT_STATUS_EX = TPCHANGER_ELEMENT_STATUS_EX

type TCHANGER_INITIALIZE_ELEMENT_STATUS = struct {
	FElementList TCHANGER_ELEMENT_LIST
	FBarCodeScan TBOOLEAN
}

type CHANGER_INITIALIZE_ELEMENT_STATUS = TCHANGER_INITIALIZE_ELEMENT_STATUS

type T_CHANGER_INITIALIZE_ELEMENT_STATUS = TCHANGER_INITIALIZE_ELEMENT_STATUS

type _CHANGER_INITIALIZE_ELEMENT_STATUS = T_CHANGER_INITIALIZE_ELEMENT_STATUS

type TPCHANGER_INITIALIZE_ELEMENT_STATUS = uintptr

type PCHANGER_INITIALIZE_ELEMENT_STATUS = TPCHANGER_INITIALIZE_ELEMENT_STATUS

type TCHANGER_SET_POSITION = struct {
	FTransport   TCHANGER_ELEMENT
	FDestination TCHANGER_ELEMENT
	FFlip        TBOOLEAN
}

type CHANGER_SET_POSITION = TCHANGER_SET_POSITION

type T_CHANGER_SET_POSITION = TCHANGER_SET_POSITION

type _CHANGER_SET_POSITION = T_CHANGER_SET_POSITION

type TPCHANGER_SET_POSITION = uintptr

type PCHANGER_SET_POSITION = TPCHANGER_SET_POSITION

type TCHANGER_EXCHANGE_MEDIUM = struct {
	FTransport    TCHANGER_ELEMENT
	FSource       TCHANGER_ELEMENT
	FDestination1 TCHANGER_ELEMENT
	FDestination2 TCHANGER_ELEMENT
	FFlip1        TBOOLEAN
	FFlip2        TBOOLEAN
}

type CHANGER_EXCHANGE_MEDIUM = TCHANGER_EXCHANGE_MEDIUM

type T_CHANGER_EXCHANGE_MEDIUM = TCHANGER_EXCHANGE_MEDIUM

type _CHANGER_EXCHANGE_MEDIUM = T_CHANGER_EXCHANGE_MEDIUM

type TPCHANGER_EXCHANGE_MEDIUM = uintptr

type PCHANGER_EXCHANGE_MEDIUM = TPCHANGER_EXCHANGE_MEDIUM

type TCHANGER_MOVE_MEDIUM = struct {
	FTransport   TCHANGER_ELEMENT
	FSource      TCHANGER_ELEMENT
	FDestination TCHANGER_ELEMENT
	FFlip        TBOOLEAN
}

type CHANGER_MOVE_MEDIUM = TCHANGER_MOVE_MEDIUM

type T_CHANGER_MOVE_MEDIUM = TCHANGER_MOVE_MEDIUM

type _CHANGER_MOVE_MEDIUM = T_CHANGER_MOVE_MEDIUM

type TPCHANGER_MOVE_MEDIUM = uintptr

type PCHANGER_MOVE_MEDIUM = TPCHANGER_MOVE_MEDIUM

type TCHANGER_SEND_VOLUME_TAG_INFORMATION = struct {
	FStartingElement  TCHANGER_ELEMENT
	FActionCode       TDWORD
	FVolumeIDTemplate [40]TBYTE
}

type CHANGER_SEND_VOLUME_TAG_INFORMATION = TCHANGER_SEND_VOLUME_TAG_INFORMATION

type T_CHANGER_SEND_VOLUME_TAG_INFORMATION = TCHANGER_SEND_VOLUME_TAG_INFORMATION

type _CHANGER_SEND_VOLUME_TAG_INFORMATION = T_CHANGER_SEND_VOLUME_TAG_INFORMATION

type TPCHANGER_SEND_VOLUME_TAG_INFORMATION = uintptr

type PCHANGER_SEND_VOLUME_TAG_INFORMATION = TPCHANGER_SEND_VOLUME_TAG_INFORMATION

type TREAD_ELEMENT_ADDRESS_INFO = struct {
	FNumberOfElements TDWORD
	FElementStatus    [1]TCHANGER_ELEMENT_STATUS
}

type READ_ELEMENT_ADDRESS_INFO = TREAD_ELEMENT_ADDRESS_INFO

type T_READ_ELEMENT_ADDRESS_INFO = TREAD_ELEMENT_ADDRESS_INFO

type _READ_ELEMENT_ADDRESS_INFO = T_READ_ELEMENT_ADDRESS_INFO

type TPREAD_ELEMENT_ADDRESS_INFO = uintptr

type PREAD_ELEMENT_ADDRESS_INFO = TPREAD_ELEMENT_ADDRESS_INFO

type TCHANGER_DEVICE_PROBLEM_TYPE = int32

type CHANGER_DEVICE_PROBLEM_TYPE = TCHANGER_DEVICE_PROBLEM_TYPE

type __CHANGER_DEVICE_PROBLEM_TYPE = int32

const _DeviceProblemNone = 0
const _DeviceProblemHardware = 1
const _DeviceProblemCHMError = 2
const _DeviceProblemDoorOpen = 3
const _DeviceProblemCalibrationError = 4
const _DeviceProblemTargetFailure = 5
const _DeviceProblemCHMMoveError = 6
const _DeviceProblemCHMZeroError = 7
const _DeviceProblemCartridgeInsertError = 8
const _DeviceProblemPositionError = 9
const _DeviceProblemSensorError = 10
const _DeviceProblemCartridgeEjectError = 11
const _DeviceProblemGripperError = 12
const _DeviceProblemDriveError = 13

type TPCHANGER_DEVICE_PROBLEM_TYPE = uintptr

type PCHANGER_DEVICE_PROBLEM_TYPE = TPCHANGER_DEVICE_PROBLEM_TYPE

type TPATHNAME_BUFFER = struct {
	FPathNameLength TDWORD
	FName           [1]TWCHAR
}

type PATHNAME_BUFFER = TPATHNAME_BUFFER

type T_PATHNAME_BUFFER = TPATHNAME_BUFFER

type _PATHNAME_BUFFER = T_PATHNAME_BUFFER

type TPPATHNAME_BUFFER = uintptr

type PPATHNAME_BUFFER = TPPATHNAME_BUFFER

type TFSCTL_QUERY_FAT_BPB_BUFFER = struct {
	FFirst0x24BytesOfBootSector [36]TBYTE
}

type FSCTL_QUERY_FAT_BPB_BUFFER = TFSCTL_QUERY_FAT_BPB_BUFFER

type T_FSCTL_QUERY_FAT_BPB_BUFFER = TFSCTL_QUERY_FAT_BPB_BUFFER

type _FSCTL_QUERY_FAT_BPB_BUFFER = T_FSCTL_QUERY_FAT_BPB_BUFFER

type TPFSCTL_QUERY_FAT_BPB_BUFFER = uintptr

type PFSCTL_QUERY_FAT_BPB_BUFFER = TPFSCTL_QUERY_FAT_BPB_BUFFER

type TNTFS_VOLUME_DATA_BUFFER = struct {
	F__ccgo_align                 [0]uint32
	FVolumeSerialNumber           TLARGE_INTEGER
	FNumberSectors                TLARGE_INTEGER
	FTotalClusters                TLARGE_INTEGER
	FFreeClusters                 TLARGE_INTEGER
	FTotalReserved                TLARGE_INTEGER
	FBytesPerSector               TDWORD
	FBytesPerCluster              TDWORD
	FBytesPerFileRecordSegment    TDWORD
	FClustersPerFileRecordSegment TDWORD
	FMftValidDataLength           TLARGE_INTEGER
	FMftStartLcn                  TLARGE_INTEGER
	FMft2StartLcn                 TLARGE_INTEGER
	FMftZoneStart                 TLARGE_INTEGER
	FMftZoneEnd                   TLARGE_INTEGER
}

type NTFS_VOLUME_DATA_BUFFER = TNTFS_VOLUME_DATA_BUFFER

type TPNTFS_VOLUME_DATA_BUFFER = uintptr

type PNTFS_VOLUME_DATA_BUFFER = TPNTFS_VOLUME_DATA_BUFFER

type TNTFS_EXTENDED_VOLUME_DATA = struct {
	FByteCount    TDWORD
	FMajorVersion TWORD
	FMinorVersion TWORD
}

type NTFS_EXTENDED_VOLUME_DATA = TNTFS_EXTENDED_VOLUME_DATA

type TPNTFS_EXTENDED_VOLUME_DATA = uintptr

type PNTFS_EXTENDED_VOLUME_DATA = TPNTFS_EXTENDED_VOLUME_DATA

type TSTARTING_LCN_INPUT_BUFFER = struct {
	F__ccgo_align [0]uint32
	FStartingLcn  TLARGE_INTEGER
}

type STARTING_LCN_INPUT_BUFFER = TSTARTING_LCN_INPUT_BUFFER

type TPSTARTING_LCN_INPUT_BUFFER = uintptr

type PSTARTING_LCN_INPUT_BUFFER = TPSTARTING_LCN_INPUT_BUFFER

type TVOLUME_BITMAP_BUFFER = struct {
	F__ccgo_align [0]uint32
	FStartingLcn  TLARGE_INTEGER
	FBitmapSize   TLARGE_INTEGER
	FBuffer       [1]TBYTE
	F__ccgo_pad3  [7]byte
}

type VOLUME_BITMAP_BUFFER = TVOLUME_BITMAP_BUFFER

type TPVOLUME_BITMAP_BUFFER = uintptr

type PVOLUME_BITMAP_BUFFER = TPVOLUME_BITMAP_BUFFER

type TSTARTING_VCN_INPUT_BUFFER = struct {
	F__ccgo_align [0]uint32
	FStartingVcn  TLARGE_INTEGER
}

type STARTING_VCN_INPUT_BUFFER = TSTARTING_VCN_INPUT_BUFFER

type TPSTARTING_VCN_INPUT_BUFFER = uintptr

type PSTARTING_VCN_INPUT_BUFFER = TPSTARTING_VCN_INPUT_BUFFER

type TRETRIEVAL_POINTERS_BUFFER = struct {
	F__ccgo_align  [0]uint32
	FExtentCount   TDWORD
	F__ccgo_align1 [4]byte
	FStartingVcn   TLARGE_INTEGER
	FExtents       [1]struct {
		F__ccgo_align [0]uint32
		FNextVcn      TLARGE_INTEGER
		FLcn          TLARGE_INTEGER
	}
}

type RETRIEVAL_POINTERS_BUFFER = TRETRIEVAL_POINTERS_BUFFER

type TPRETRIEVAL_POINTERS_BUFFER = uintptr

type PRETRIEVAL_POINTERS_BUFFER = TPRETRIEVAL_POINTERS_BUFFER

type TRETRIEVAL_POINTERS_BUFFER1 = struct {
	F__ccgo_align  [0]uint32
	FExtentCount   TDWORD
	F__ccgo_align1 [4]byte
	FStartingVcn   TLARGE_INTEGER
	FExtents       [1]struct {
		F__ccgo_align [0]uint32
		FNextVcn      TLARGE_INTEGER
		FLcn          TLARGE_INTEGER
	}
}

type RETRIEVAL_POINTERS_BUFFER1 = TRETRIEVAL_POINTERS_BUFFER1

type TNTFS_FILE_RECORD_INPUT_BUFFER = struct {
	F__ccgo_align        [0]uint32
	FFileReferenceNumber TLARGE_INTEGER
}

type NTFS_FILE_RECORD_INPUT_BUFFER = TNTFS_FILE_RECORD_INPUT_BUFFER

type TPNTFS_FILE_RECORD_INPUT_BUFFER = uintptr

type PNTFS_FILE_RECORD_INPUT_BUFFER = TPNTFS_FILE_RECORD_INPUT_BUFFER

type TNTFS_FILE_RECORD_OUTPUT_BUFFER = struct {
	F__ccgo_align        [0]uint32
	FFileReferenceNumber TLARGE_INTEGER
	FFileRecordLength    TDWORD
	FFileRecordBuffer    [1]TBYTE
	F__ccgo_pad3         [3]byte
}

type NTFS_FILE_RECORD_OUTPUT_BUFFER = TNTFS_FILE_RECORD_OUTPUT_BUFFER

type TPNTFS_FILE_RECORD_OUTPUT_BUFFER = uintptr

type PNTFS_FILE_RECORD_OUTPUT_BUFFER = TPNTFS_FILE_RECORD_OUTPUT_BUFFER

type TMOVE_FILE_DATA = struct {
	F__ccgo_align  [0]uint32
	FFileHandle    THANDLE
	F__ccgo_align1 [4]byte
	FStartingVcn   TLARGE_INTEGER
	FStartingLcn   TLARGE_INTEGER
	FClusterCount  TDWORD
	F__ccgo_pad4   [4]byte
}

type MOVE_FILE_DATA = TMOVE_FILE_DATA

type TPMOVE_FILE_DATA = uintptr

type PMOVE_FILE_DATA = TPMOVE_FILE_DATA

type TMOVE_FILE_RECORD_DATA = struct {
	F__ccgo_align     [0]uint32
	FFileHandle       THANDLE
	F__ccgo_align1    [4]byte
	FSourceFileRecord TLARGE_INTEGER
	FTargetFileRecord TLARGE_INTEGER
}

type MOVE_FILE_RECORD_DATA = TMOVE_FILE_RECORD_DATA

type T_MOVE_FILE_RECORD_DATA = TMOVE_FILE_RECORD_DATA

type _MOVE_FILE_RECORD_DATA = T_MOVE_FILE_RECORD_DATA

type TPMOVE_FILE_RECORD_DATA = uintptr

type PMOVE_FILE_RECORD_DATA = TPMOVE_FILE_RECORD_DATA

type TFIND_BY_SID_DATA = struct {
	FRestart TDWORD
	FSid     TSID
}

type FIND_BY_SID_DATA = TFIND_BY_SID_DATA

type TPFIND_BY_SID_DATA = uintptr

type PFIND_BY_SID_DATA = TPFIND_BY_SID_DATA

type TFIND_BY_SID_OUTPUT = struct {
	FNextEntryOffset TDWORD
	FFileIndex       TDWORD
	FFileNameLength  TDWORD
	FFileName        [1]TWCHAR
}

type FIND_BY_SID_OUTPUT = TFIND_BY_SID_OUTPUT

type TPFIND_BY_SID_OUTPUT = uintptr

type PFIND_BY_SID_OUTPUT = TPFIND_BY_SID_OUTPUT

type TMFT_ENUM_DATA = struct {
	F__ccgo_align             [0]uint32
	FStartFileReferenceNumber TDWORDLONG
	FLowUsn                   TUSN
	FHighUsn                  TUSN
}

type MFT_ENUM_DATA = TMFT_ENUM_DATA

type TPMFT_ENUM_DATA = uintptr

type PMFT_ENUM_DATA = TPMFT_ENUM_DATA

type TCREATE_USN_JOURNAL_DATA = struct {
	F__ccgo_align    [0]uint32
	FMaximumSize     TDWORDLONG
	FAllocationDelta TDWORDLONG
}

type CREATE_USN_JOURNAL_DATA = TCREATE_USN_JOURNAL_DATA

type TPCREATE_USN_JOURNAL_DATA = uintptr

type PCREATE_USN_JOURNAL_DATA = TPCREATE_USN_JOURNAL_DATA

type TREAD_USN_JOURNAL_DATA = struct {
	F__ccgo_align      [0]uint32
	FStartUsn          TUSN
	FReasonMask        TDWORD
	FReturnOnlyOnClose TDWORD
	FTimeout           TDWORDLONG
	FBytesToWaitFor    TDWORDLONG
	FUsnJournalID      TDWORDLONG
}

type READ_USN_JOURNAL_DATA = TREAD_USN_JOURNAL_DATA

type TPREAD_USN_JOURNAL_DATA = uintptr

type PREAD_USN_JOURNAL_DATA = TPREAD_USN_JOURNAL_DATA

type TUSN_RECORD = struct {
	F__ccgo_align              [0]uint32
	FRecordLength              TDWORD
	FMajorVersion              TWORD
	FMinorVersion              TWORD
	FFileReferenceNumber       TDWORDLONG
	FParentFileReferenceNumber TDWORDLONG
	FUsn                       TUSN
	FTimeStamp                 TLARGE_INTEGER
	FReason                    TDWORD
	FSourceInfo                TDWORD
	FSecurityId                TDWORD
	FFileAttributes            TDWORD
	FFileNameLength            TWORD
	FFileNameOffset            TWORD
	FFileName                  [1]TWCHAR
	F__ccgo_pad14              [2]byte
}

type USN_RECORD = TUSN_RECORD

type TPUSN_RECORD = uintptr

type PUSN_RECORD = TPUSN_RECORD

type TUSN_JOURNAL_DATA = struct {
	F__ccgo_align    [0]uint32
	FUsnJournalID    TDWORDLONG
	FFirstUsn        TUSN
	FNextUsn         TUSN
	FLowestValidUsn  TUSN
	FMaxUsn          TUSN
	FMaximumSize     TDWORDLONG
	FAllocationDelta TDWORDLONG
}

type USN_JOURNAL_DATA = TUSN_JOURNAL_DATA

type TPUSN_JOURNAL_DATA = uintptr

type PUSN_JOURNAL_DATA = TPUSN_JOURNAL_DATA

type TDELETE_USN_JOURNAL_DATA = struct {
	F__ccgo_align [0]uint32
	FUsnJournalID TDWORDLONG
	FDeleteFlags  TDWORD
	F__ccgo_pad2  [4]byte
}

type DELETE_USN_JOURNAL_DATA = TDELETE_USN_JOURNAL_DATA

type TPDELETE_USN_JOURNAL_DATA = uintptr

type PDELETE_USN_JOURNAL_DATA = TPDELETE_USN_JOURNAL_DATA

type TMARK_HANDLE_INFO = struct {
	FUsnSourceInfo TDWORD
	FVolumeHandle  THANDLE
	FHandleInfo    TDWORD
}

type MARK_HANDLE_INFO = TMARK_HANDLE_INFO

type TPMARK_HANDLE_INFO = uintptr

type PMARK_HANDLE_INFO = TPMARK_HANDLE_INFO

type TBULK_SECURITY_TEST_DATA = struct {
	FDesiredAccess TACCESS_MASK
	FSecurityIds   [1]TDWORD
}

type BULK_SECURITY_TEST_DATA = TBULK_SECURITY_TEST_DATA

type TPBULK_SECURITY_TEST_DATA = uintptr

type PBULK_SECURITY_TEST_DATA = TPBULK_SECURITY_TEST_DATA

type TFILE_PREFETCH = struct {
	F__ccgo_align [0]uint32
	FType         TDWORD
	FCount        TDWORD
	FPrefetch     [1]TDWORDLONG
}

type FILE_PREFETCH = TFILE_PREFETCH

type T_FILE_PREFETCH = TFILE_PREFETCH

type _FILE_PREFETCH = T_FILE_PREFETCH

type TPFILE_PREFETCH = uintptr

type PFILE_PREFETCH = TPFILE_PREFETCH

type TFILE_PREFETCH_EX = struct {
	F__ccgo_align  [0]uint32
	FType          TULONG
	FCount         TULONG
	FContext       TPVOID
	F__ccgo_align3 [4]byte
	FPrefetch      [1]TULONGLONG
}

type FILE_PREFETCH_EX = TFILE_PREFETCH_EX

type T_FILE_PREFETCH_EX = TFILE_PREFETCH_EX

type _FILE_PREFETCH_EX = T_FILE_PREFETCH_EX

type TPFILE_PREFETCH_EX = uintptr

type PFILE_PREFETCH_EX = TPFILE_PREFETCH_EX

type TFILESYSTEM_STATISTICS = struct {
	FFileSystemType          TWORD
	FVersion                 TWORD
	FSizeOfCompleteStructure TDWORD
	FUserFileReads           TDWORD
	FUserFileReadBytes       TDWORD
	FUserDiskReads           TDWORD
	FUserFileWrites          TDWORD
	FUserFileWriteBytes      TDWORD
	FUserDiskWrites          TDWORD
	FMetaDataReads           TDWORD
	FMetaDataReadBytes       TDWORD
	FMetaDataDiskReads       TDWORD
	FMetaDataWrites          TDWORD
	FMetaDataWriteBytes      TDWORD
	FMetaDataDiskWrites      TDWORD
}

type FILESYSTEM_STATISTICS = TFILESYSTEM_STATISTICS

type T_FILESYSTEM_STATISTICS = TFILESYSTEM_STATISTICS

type _FILESYSTEM_STATISTICS = T_FILESYSTEM_STATISTICS

type TPFILESYSTEM_STATISTICS = uintptr

type PFILESYSTEM_STATISTICS = TPFILESYSTEM_STATISTICS

type TFAT_STATISTICS = struct {
	FCreateHits          TDWORD
	FSuccessfulCreates   TDWORD
	FFailedCreates       TDWORD
	FNonCachedReads      TDWORD
	FNonCachedReadBytes  TDWORD
	FNonCachedWrites     TDWORD
	FNonCachedWriteBytes TDWORD
	FNonCachedDiskReads  TDWORD
	FNonCachedDiskWrites TDWORD
}

type FAT_STATISTICS = TFAT_STATISTICS

type T_FAT_STATISTICS = TFAT_STATISTICS

type _FAT_STATISTICS = T_FAT_STATISTICS

type TPFAT_STATISTICS = uintptr

type PFAT_STATISTICS = TPFAT_STATISTICS

type TEXFAT_STATISTICS = struct {
	FCreateHits          TDWORD
	FSuccessfulCreates   TDWORD
	FFailedCreates       TDWORD
	FNonCachedReads      TDWORD
	FNonCachedReadBytes  TDWORD
	FNonCachedWrites     TDWORD
	FNonCachedWriteBytes TDWORD
	FNonCachedDiskReads  TDWORD
	FNonCachedDiskWrites TDWORD
}

type EXFAT_STATISTICS = TEXFAT_STATISTICS

type T_EXFAT_STATISTICS = TEXFAT_STATISTICS

type _EXFAT_STATISTICS = T_EXFAT_STATISTICS

type TPEXFAT_STATISTICS = uintptr

type PEXFAT_STATISTICS = TPEXFAT_STATISTICS

type TNTFS_STATISTICS = struct {
	FLogFileFullExceptions TDWORD
	FOtherExceptions       TDWORD
	FMftReads              TDWORD
	FMftReadBytes          TDWORD
	FMftWrites             TDWORD
	FMftWriteBytes         TDWORD
	FMftWritesUserLevel    struct {
		FWrite   TWORD
		FCreate  TWORD
		FSetInfo TWORD
		FFlush   TWORD
	}
	FMftWritesFlushForLogFileFull TWORD
	FMftWritesLazyWriter          TWORD
	FMftWritesUserRequest         TWORD
	FMft2Writes                   TDWORD
	FMft2WriteBytes               TDWORD
	FMft2WritesUserLevel          struct {
		FWrite   TWORD
		FCreate  TWORD
		FSetInfo TWORD
		FFlush   TWORD
	}
	FMft2WritesFlushForLogFileFull   TWORD
	FMft2WritesLazyWriter            TWORD
	FMft2WritesUserRequest           TWORD
	FRootIndexReads                  TDWORD
	FRootIndexReadBytes              TDWORD
	FRootIndexWrites                 TDWORD
	FRootIndexWriteBytes             TDWORD
	FBitmapReads                     TDWORD
	FBitmapReadBytes                 TDWORD
	FBitmapWrites                    TDWORD
	FBitmapWriteBytes                TDWORD
	FBitmapWritesFlushForLogFileFull TWORD
	FBitmapWritesLazyWriter          TWORD
	FBitmapWritesUserRequest         TWORD
	FBitmapWritesUserLevel           struct {
		FWrite   TWORD
		FCreate  TWORD
		FSetInfo TWORD
	}
	FMftBitmapReads                     TDWORD
	FMftBitmapReadBytes                 TDWORD
	FMftBitmapWrites                    TDWORD
	FMftBitmapWriteBytes                TDWORD
	FMftBitmapWritesFlushForLogFileFull TWORD
	FMftBitmapWritesLazyWriter          TWORD
	FMftBitmapWritesUserRequest         TWORD
	FMftBitmapWritesUserLevel           struct {
		FWrite   TWORD
		FCreate  TWORD
		FSetInfo TWORD
		FFlush   TWORD
	}
	FUserIndexReads      TDWORD
	FUserIndexReadBytes  TDWORD
	FUserIndexWrites     TDWORD
	FUserIndexWriteBytes TDWORD
	FLogFileReads        TDWORD
	FLogFileReadBytes    TDWORD
	FLogFileWrites       TDWORD
	FLogFileWriteBytes   TDWORD
	FAllocate            struct {
		FCalls             TDWORD
		FClusters          TDWORD
		FHints             TDWORD
		FRunsReturned      TDWORD
		FHintsHonored      TDWORD
		FHintsClusters     TDWORD
		FCache             TDWORD
		FCacheClusters     TDWORD
		FCacheMiss         TDWORD
		FCacheMissClusters TDWORD
	}
}

type NTFS_STATISTICS = TNTFS_STATISTICS

type T_NTFS_STATISTICS = TNTFS_STATISTICS

type _NTFS_STATISTICS = T_NTFS_STATISTICS

type TPNTFS_STATISTICS = uintptr

type PNTFS_STATISTICS = TPNTFS_STATISTICS

type TFILE_OBJECTID_BUFFER = struct {
	FObjectId   [16]TBYTE
	F__ccgo1_16 struct {
		FExtendedInfo [0][48]TBYTE
		F__ccgo0_0    struct {
			FBirthVolumeId [16]TBYTE
			FBirthObjectId [16]TBYTE
			FDomainId      [16]TBYTE
		}
	}
}

type FILE_OBJECTID_BUFFER = TFILE_OBJECTID_BUFFER

type T_FILE_OBJECTID_BUFFER = TFILE_OBJECTID_BUFFER

type _FILE_OBJECTID_BUFFER = T_FILE_OBJECTID_BUFFER

type TPFILE_OBJECTID_BUFFER = uintptr

type PFILE_OBJECTID_BUFFER = TPFILE_OBJECTID_BUFFER

type TFILE_SET_SPARSE_BUFFER = struct {
	FSetSparse TBOOLEAN
}

type FILE_SET_SPARSE_BUFFER = TFILE_SET_SPARSE_BUFFER

type T_FILE_SET_SPARSE_BUFFER = TFILE_SET_SPARSE_BUFFER

type _FILE_SET_SPARSE_BUFFER = T_FILE_SET_SPARSE_BUFFER

type TPFILE_SET_SPARSE_BUFFER = uintptr

type PFILE_SET_SPARSE_BUFFER = TPFILE_SET_SPARSE_BUFFER

type TFILE_ZERO_DATA_INFORMATION = struct {
	F__ccgo_align    [0]uint32
	FFileOffset      TLARGE_INTEGER
	FBeyondFinalZero TLARGE_INTEGER
}

type FILE_ZERO_DATA_INFORMATION = TFILE_ZERO_DATA_INFORMATION

type T_FILE_ZERO_DATA_INFORMATION = TFILE_ZERO_DATA_INFORMATION

type _FILE_ZERO_DATA_INFORMATION = T_FILE_ZERO_DATA_INFORMATION

type TPFILE_ZERO_DATA_INFORMATION = uintptr

type PFILE_ZERO_DATA_INFORMATION = TPFILE_ZERO_DATA_INFORMATION

type TFILE_ALLOCATED_RANGE_BUFFER = struct {
	F__ccgo_align [0]uint32
	FFileOffset   TLARGE_INTEGER
	FLength       TLARGE_INTEGER
}

type FILE_ALLOCATED_RANGE_BUFFER = TFILE_ALLOCATED_RANGE_BUFFER

type T_FILE_ALLOCATED_RANGE_BUFFER = TFILE_ALLOCATED_RANGE_BUFFER

type _FILE_ALLOCATED_RANGE_BUFFER = T_FILE_ALLOCATED_RANGE_BUFFER

type TPFILE_ALLOCATED_RANGE_BUFFER = uintptr

type PFILE_ALLOCATED_RANGE_BUFFER = TPFILE_ALLOCATED_RANGE_BUFFER

type TENCRYPTION_BUFFER = struct {
	FEncryptionOperation TDWORD
	FPrivate             [1]TBYTE
}

type ENCRYPTION_BUFFER = TENCRYPTION_BUFFER

type T_ENCRYPTION_BUFFER = TENCRYPTION_BUFFER

type _ENCRYPTION_BUFFER = T_ENCRYPTION_BUFFER

type TPENCRYPTION_BUFFER = uintptr

type PENCRYPTION_BUFFER = TPENCRYPTION_BUFFER

type TDECRYPTION_STATUS_BUFFER = struct {
	FNoEncryptedStreams TBOOLEAN
}

type DECRYPTION_STATUS_BUFFER = TDECRYPTION_STATUS_BUFFER

type T_DECRYPTION_STATUS_BUFFER = TDECRYPTION_STATUS_BUFFER

type _DECRYPTION_STATUS_BUFFER = T_DECRYPTION_STATUS_BUFFER

type TPDECRYPTION_STATUS_BUFFER = uintptr

type PDECRYPTION_STATUS_BUFFER = TPDECRYPTION_STATUS_BUFFER

type TREQUEST_RAW_ENCRYPTED_DATA = struct {
	F__ccgo_align [0]uint32
	FFileOffset   TLONGLONG
	FLength       TDWORD
	F__ccgo_pad2  [4]byte
}

type REQUEST_RAW_ENCRYPTED_DATA = TREQUEST_RAW_ENCRYPTED_DATA

type T_REQUEST_RAW_ENCRYPTED_DATA = TREQUEST_RAW_ENCRYPTED_DATA

type _REQUEST_RAW_ENCRYPTED_DATA = T_REQUEST_RAW_ENCRYPTED_DATA

type TPREQUEST_RAW_ENCRYPTED_DATA = uintptr

type PREQUEST_RAW_ENCRYPTED_DATA = TPREQUEST_RAW_ENCRYPTED_DATA

type TENCRYPTED_DATA_INFO = struct {
	F__ccgo_align               [0]uint32
	FStartingFileOffset         TDWORDLONG
	FOutputBufferOffset         TDWORD
	FBytesWithinFileSize        TDWORD
	FBytesWithinValidDataLength TDWORD
	FCompressionFormat          TWORD
	FDataUnitShift              TBYTE
	FChunkShift                 TBYTE
	FClusterShift               TBYTE
	FEncryptionFormat           TBYTE
	FNumberOfDataBlocks         TWORD
	FDataBlockSize              [1]TDWORD
}

type ENCRYPTED_DATA_INFO = TENCRYPTED_DATA_INFO

type T_ENCRYPTED_DATA_INFO = TENCRYPTED_DATA_INFO

type _ENCRYPTED_DATA_INFO = T_ENCRYPTED_DATA_INFO

type TPENCRYPTED_DATA_INFO = uintptr

type PENCRYPTED_DATA_INFO = TPENCRYPTED_DATA_INFO

type TPLEX_READ_DATA_REQUEST = struct {
	F__ccgo_align [0]uint32
	FByteOffset   TLARGE_INTEGER
	FByteLength   TDWORD
	FPlexNumber   TDWORD
}

type PLEX_READ_DATA_REQUEST = TPLEX_READ_DATA_REQUEST

type T_PLEX_READ_DATA_REQUEST = TPLEX_READ_DATA_REQUEST

type _PLEX_READ_DATA_REQUEST = T_PLEX_READ_DATA_REQUEST

type TPPLEX_READ_DATA_REQUEST = uintptr

type PPLEX_READ_DATA_REQUEST = TPPLEX_READ_DATA_REQUEST

type TSI_COPYFILE = struct {
	FSourceFileNameLength      TDWORD
	FDestinationFileNameLength TDWORD
	FFlags                     TDWORD
	FFileNameBuffer            [1]TWCHAR
}

type SI_COPYFILE = TSI_COPYFILE

type T_SI_COPYFILE = TSI_COPYFILE

type _SI_COPYFILE = T_SI_COPYFILE

type TPSI_COPYFILE = uintptr

type PSI_COPYFILE = TPSI_COPYFILE

type TSTORAGE_DESCRIPTOR_HEADER = struct {
	FVersion TDWORD
	FSize    TDWORD
}

type STORAGE_DESCRIPTOR_HEADER = TSTORAGE_DESCRIPTOR_HEADER

type T_STORAGE_DESCRIPTOR_HEADER = TSTORAGE_DESCRIPTOR_HEADER

type _STORAGE_DESCRIPTOR_HEADER = T_STORAGE_DESCRIPTOR_HEADER

type TPSTORAGE_DESCRIPTOR_HEADER = uintptr

type PSTORAGE_DESCRIPTOR_HEADER = TPSTORAGE_DESCRIPTOR_HEADER

type TSTORAGE_PROPERTY_ID = int32

type STORAGE_PROPERTY_ID = TSTORAGE_PROPERTY_ID

type __STORAGE_PROPERTY_ID = int32

const _StorageDeviceProperty = 0
const _StorageAdapterProperty = 1
const _StorageDeviceIdProperty = 2
const _StorageDeviceUniqueIdProperty = 3
const _StorageDeviceWriteCacheProperty = 4
const _StorageMiniportProperty = 5
const _StorageAccessAlignmentProperty = 6
const _StorageDeviceSeekPenaltyProperty = 7
const _StorageDeviceTrimProperty = 8
const _StorageDeviceWriteAggregationProperty = 9
const _StorageDeviceDeviceTelemetryProperty = 10
const _StorageDeviceLBProvisioningProperty = 11
const _StorageDevicePowerProperty = 12
const _StorageDeviceCopyOffloadProperty = 13
const _StorageDeviceResiliencyProperty = 14
const _StorageDeviceMediumProductType = 15
const _StorageAdapterRpmbProperty = 16
const _StorageAdapterCryptoProperty = 17
const _StorageDeviceIoCapabilityProperty = 48
const _StorageAdapterProtocolSpecificProperty = 49
const _StorageDeviceProtocolSpecificProperty = 50
const _StorageAdapterTemperatureProperty = 51
const _StorageDeviceTemperatureProperty = 52
const _StorageAdapterPhysicalTopologyProperty = 53
const _StorageDevicePhysicalTopologyProperty = 54
const _StorageDeviceAttributesProperty = 55
const _StorageDeviceManagementStatus = 56
const _StorageAdapterSerialNumberProperty = 57
const _StorageDeviceLocationProperty = 58
const _StorageDeviceNumaProperty = 59
const _StorageDeviceZonedDeviceProperty = 60
const _StorageDeviceUnsafeShutdownCount = 61
const _StorageDeviceEnduranceProperty = 62
const _StorageDeviceLedStateProperty = 63
const _StorageDeviceSelfEncryptionProperty = 64
const _StorageFruIdProperty = 65

type TPSTORAGE_PROPERTY_ID = uintptr

type PSTORAGE_PROPERTY_ID = TPSTORAGE_PROPERTY_ID

type TSTORAGE_QUERY_TYPE = int32

type STORAGE_QUERY_TYPE = TSTORAGE_QUERY_TYPE

type __STORAGE_QUERY_TYPE = int32

const _PropertyStandardQuery = 0
const _PropertyExistsQuery = 1
const _PropertyMaskQuery = 2
const _PropertyQueryMaxDefined = 3

type TPSTORAGE_QUERY_TYPE = uintptr

type PSTORAGE_QUERY_TYPE = TPSTORAGE_QUERY_TYPE

type TSTORAGE_SET_TYPE = int32

type STORAGE_SET_TYPE = TSTORAGE_SET_TYPE

type __STORAGE_SET_TYPE = int32

const _PropertyStandardSet = 0
const _PropertyExistsSet = 1
const _PropertySetMaxDefined = 2

type TPSTORAGE_SET_TYPE = uintptr

type PSTORAGE_SET_TYPE = TPSTORAGE_SET_TYPE

type TSTORAGE_PROPERTY_QUERY = struct {
	FPropertyId           TSTORAGE_PROPERTY_ID
	FQueryType            TSTORAGE_QUERY_TYPE
	FAdditionalParameters [1]TBYTE
}

type STORAGE_PROPERTY_QUERY = TSTORAGE_PROPERTY_QUERY

type T_STORAGE_PROPERTY_QUERY = TSTORAGE_PROPERTY_QUERY

type _STORAGE_PROPERTY_QUERY = T_STORAGE_PROPERTY_QUERY

type TPSTORAGE_PROPERTY_QUERY = uintptr

type PSTORAGE_PROPERTY_QUERY = TPSTORAGE_PROPERTY_QUERY

type TSTORAGE_PROPERTY_SET = struct {
	FPropertyId           TSTORAGE_PROPERTY_ID
	FSetType              TSTORAGE_SET_TYPE
	FAdditionalParameters [1]TBYTE
}

type STORAGE_PROPERTY_SET = TSTORAGE_PROPERTY_SET

type T_STORAGE_PROPERTY_SET = TSTORAGE_PROPERTY_SET

type _STORAGE_PROPERTY_SET = T_STORAGE_PROPERTY_SET

type TPSTORAGE_PROPERTY_SET = uintptr

type PSTORAGE_PROPERTY_SET = TPSTORAGE_PROPERTY_SET

type TSTORAGE_DEVICE_DESCRIPTOR = struct {
	FVersion               TDWORD
	FSize                  TDWORD
	FDeviceType            TBYTE
	FDeviceTypeModifier    TBYTE
	FRemovableMedia        TBOOLEAN
	FCommandQueueing       TBOOLEAN
	FVendorIdOffset        TDWORD
	FProductIdOffset       TDWORD
	FProductRevisionOffset TDWORD
	FSerialNumberOffset    TDWORD
	FBusType               TSTORAGE_BUS_TYPE
	FRawPropertiesLength   TDWORD
	FRawDeviceProperties   [1]TBYTE
}

type STORAGE_DEVICE_DESCRIPTOR = TSTORAGE_DEVICE_DESCRIPTOR

type T_STORAGE_DEVICE_DESCRIPTOR = TSTORAGE_DEVICE_DESCRIPTOR

type _STORAGE_DEVICE_DESCRIPTOR = T_STORAGE_DEVICE_DESCRIPTOR

type TPSTORAGE_DEVICE_DESCRIPTOR = uintptr

type PSTORAGE_DEVICE_DESCRIPTOR = TPSTORAGE_DEVICE_DESCRIPTOR

type TSTORAGE_ADAPTER_DESCRIPTOR = struct {
	FVersion               TDWORD
	FSize                  TDWORD
	FMaximumTransferLength TDWORD
	FMaximumPhysicalPages  TDWORD
	FAlignmentMask         TDWORD
	FAdapterUsesPio        TBOOLEAN
	FAdapterScansDown      TBOOLEAN
	FCommandQueueing       TBOOLEAN
	FAcceleratedTransfer   TBOOLEAN
	FBusType               TBYTE
	FBusMajorVersion       TWORD
	FBusMinorVersion       TWORD
	FSrbType               TBYTE
	FAddressType           TBYTE
}

type STORAGE_ADAPTER_DESCRIPTOR = TSTORAGE_ADAPTER_DESCRIPTOR

type T_STORAGE_ADAPTER_DESCRIPTOR = TSTORAGE_ADAPTER_DESCRIPTOR

type _STORAGE_ADAPTER_DESCRIPTOR = T_STORAGE_ADAPTER_DESCRIPTOR

type TPSTORAGE_ADAPTER_DESCRIPTOR = uintptr

type PSTORAGE_ADAPTER_DESCRIPTOR = TPSTORAGE_ADAPTER_DESCRIPTOR

type TSTORAGE_DEVICE_ID_DESCRIPTOR = struct {
	FVersion             TDWORD
	FSize                TDWORD
	FNumberOfIdentifiers TDWORD
	FIdentifiers         [1]TBYTE
}

type STORAGE_DEVICE_ID_DESCRIPTOR = TSTORAGE_DEVICE_ID_DESCRIPTOR

type T_STORAGE_DEVICE_ID_DESCRIPTOR = TSTORAGE_DEVICE_ID_DESCRIPTOR

type _STORAGE_DEVICE_ID_DESCRIPTOR = T_STORAGE_DEVICE_ID_DESCRIPTOR

type TPSTORAGE_DEVICE_ID_DESCRIPTOR = uintptr

type PSTORAGE_DEVICE_ID_DESCRIPTOR = TPSTORAGE_DEVICE_ID_DESCRIPTOR

type TVOLUME_GET_GPT_ATTRIBUTES_INFORMATION = struct {
	F__ccgo_align  [0]uint32
	FGptAttributes TULONGLONG
}

type VOLUME_GET_GPT_ATTRIBUTES_INFORMATION = TVOLUME_GET_GPT_ATTRIBUTES_INFORMATION

type T_VOLUME_GET_GPT_ATTRIBUTES_INFORMATION = TVOLUME_GET_GPT_ATTRIBUTES_INFORMATION

type _VOLUME_GET_GPT_ATTRIBUTES_INFORMATION = T_VOLUME_GET_GPT_ATTRIBUTES_INFORMATION

type TPVOLUME_GET_GPT_ATTRIBUTES_INFORMATION = uintptr

type PVOLUME_GET_GPT_ATTRIBUTES_INFORMATION = TPVOLUME_GET_GPT_ATTRIBUTES_INFORMATION

type TFILE_MAKE_COMPATIBLE_BUFFER = struct {
	FCloseDisc TBOOLEAN
}

type FILE_MAKE_COMPATIBLE_BUFFER = TFILE_MAKE_COMPATIBLE_BUFFER

type T_FILE_MAKE_COMPATIBLE_BUFFER = TFILE_MAKE_COMPATIBLE_BUFFER

type _FILE_MAKE_COMPATIBLE_BUFFER = T_FILE_MAKE_COMPATIBLE_BUFFER

type TPFILE_MAKE_COMPATIBLE_BUFFER = uintptr

type PFILE_MAKE_COMPATIBLE_BUFFER = TPFILE_MAKE_COMPATIBLE_BUFFER

type TFILE_SET_DEFECT_MGMT_BUFFER = struct {
	FDisable TBOOLEAN
}

type FILE_SET_DEFECT_MGMT_BUFFER = TFILE_SET_DEFECT_MGMT_BUFFER

type T_FILE_SET_DEFECT_MGMT_BUFFER = TFILE_SET_DEFECT_MGMT_BUFFER

type _FILE_SET_DEFECT_MGMT_BUFFER = T_FILE_SET_DEFECT_MGMT_BUFFER

type TPFILE_SET_DEFECT_MGMT_BUFFER = uintptr

type PFILE_SET_DEFECT_MGMT_BUFFER = TPFILE_SET_DEFECT_MGMT_BUFFER

type TFILE_QUERY_SPARING_BUFFER = struct {
	FSparingUnitBytes TULONG
	FSoftwareSparing  TBOOLEAN
	FTotalSpareBlocks TULONG
	FFreeSpareBlocks  TULONG
}

type FILE_QUERY_SPARING_BUFFER = TFILE_QUERY_SPARING_BUFFER

type T_FILE_QUERY_SPARING_BUFFER = TFILE_QUERY_SPARING_BUFFER

type _FILE_QUERY_SPARING_BUFFER = T_FILE_QUERY_SPARING_BUFFER

type TPFILE_QUERY_SPARING_BUFFER = uintptr

type PFILE_QUERY_SPARING_BUFFER = TPFILE_QUERY_SPARING_BUFFER

type TFILE_QUERY_ON_DISK_VOL_INFO_BUFFER = struct {
	F__ccgo_align                    [0]uint32
	FDirectoryCount                  TLARGE_INTEGER
	FFileCount                       TLARGE_INTEGER
	FFsFormatMajVersion              TWORD
	FFsFormatMinVersion              TWORD
	FFsFormatName                    [12]TWCHAR
	F__ccgo_align5                   [4]byte
	FFormatTime                      TLARGE_INTEGER
	FLastUpdateTime                  TLARGE_INTEGER
	FCopyrightInfo                   [34]TWCHAR
	FAbstractInfo                    [34]TWCHAR
	FFormattingImplementationInfo    [34]TWCHAR
	FLastModifyingImplementationInfo [34]TWCHAR
}

type FILE_QUERY_ON_DISK_VOL_INFO_BUFFER = TFILE_QUERY_ON_DISK_VOL_INFO_BUFFER

type T_FILE_QUERY_ON_DISK_VOL_INFO_BUFFER = TFILE_QUERY_ON_DISK_VOL_INFO_BUFFER

type _FILE_QUERY_ON_DISK_VOL_INFO_BUFFER = T_FILE_QUERY_ON_DISK_VOL_INFO_BUFFER

type TPFILE_QUERY_ON_DISK_VOL_INFO_BUFFER = uintptr

type PFILE_QUERY_ON_DISK_VOL_INFO_BUFFER = TPFILE_QUERY_ON_DISK_VOL_INFO_BUFFER

type TSHRINK_VOLUME_REQUEST_TYPES = int32

type SHRINK_VOLUME_REQUEST_TYPES = TSHRINK_VOLUME_REQUEST_TYPES

type __SHRINK_VOLUME_REQUEST_TYPES = int32

const _ShrinkPrepare = 1
const _ShrinkCommit = 2
const _ShrinkAbort = 3

type TSHRINK_VOLUME_INFORMATION = struct {
	F__ccgo_align       [0]uint32
	FShrinkRequestType  TSHRINK_VOLUME_REQUEST_TYPES
	F__ccgo_align1      [4]byte
	FFlags              TDWORDLONG
	FNewNumberOfSectors TLONGLONG
}

type SHRINK_VOLUME_INFORMATION = TSHRINK_VOLUME_INFORMATION

type T_SHRINK_VOLUME_INFORMATION = TSHRINK_VOLUME_INFORMATION

type _SHRINK_VOLUME_INFORMATION = T_SHRINK_VOLUME_INFORMATION

type TPSHRINK_VOLUME_INFORMATION = uintptr

type PSHRINK_VOLUME_INFORMATION = TPSHRINK_VOLUME_INFORMATION

type TTXFS_MODIFY_RM = struct {
	F__ccgo_align            [0]uint32
	FFlags                   TULONG
	FLogContainerCountMax    TULONG
	FLogContainerCountMin    TULONG
	FLogContainerCount       TULONG
	FLogGrowthIncrement      TULONG
	FLogAutoShrinkPercentage TULONG
	FReserved                TULONGLONG
	FLoggingMode             TUSHORT
	F__ccgo_pad8             [6]byte
}

type TXFS_MODIFY_RM = TTXFS_MODIFY_RM

type T_TXFS_MODIFY_RM = TTXFS_MODIFY_RM

type _TXFS_MODIFY_RM = T_TXFS_MODIFY_RM

type TPTXFS_MODIFY_RM = uintptr

type PTXFS_MODIFY_RM = TPTXFS_MODIFY_RM

type TTXFS_QUERY_RM_INFORMATION = struct {
	F__ccgo_align            [0]uint32
	FBytesRequired           TULONG
	F__ccgo_align1           [4]byte
	FTailLsn                 TULONGLONG
	FCurrentLsn              TULONGLONG
	FArchiveTailLsn          TULONGLONG
	FLogContainerSize        TULONGLONG
	FHighestVirtualClock     TLARGE_INTEGER
	FLogContainerCount       TULONG
	FLogContainerCountMax    TULONG
	FLogContainerCountMin    TULONG
	FLogGrowthIncrement      TULONG
	FLogAutoShrinkPercentage TULONG
	FFlags                   TULONG
	FLoggingMode             TUSHORT
	FReserved                TUSHORT
	FRmState                 TULONG
	FLogCapacity             TULONGLONG
	FLogFree                 TULONGLONG
	FTopsSize                TULONGLONG
	FTopsUsed                TULONGLONG
	FTransactionCount        TULONGLONG
	FOnePCCount              TULONGLONG
	FTwoPCCount              TULONGLONG
	FNumberLogFileFull       TULONGLONG
	FOldestTransactionAge    TULONGLONG
	FRMName                  TGUID
	FTmLogPathOffset         TULONG
	F__ccgo_pad26            [4]byte
}

type TXFS_QUERY_RM_INFORMATION = TTXFS_QUERY_RM_INFORMATION

type T_TXFS_QUERY_RM_INFORMATION = TTXFS_QUERY_RM_INFORMATION

type _TXFS_QUERY_RM_INFORMATION = T_TXFS_QUERY_RM_INFORMATION

type TPTXFS_QUERY_RM_INFORMATION = uintptr

type PTXFS_QUERY_RM_INFORMATION = TPTXFS_QUERY_RM_INFORMATION

type TTXFS_ROLLFORWARD_REDO_INFORMATION = struct {
	F__ccgo_align       [0]uint32
	FLastVirtualClock   TLARGE_INTEGER
	FLastRedoLsn        TULONGLONG
	FHighestRecoveryLsn TULONGLONG
	FFlags              TULONG
	F__ccgo_pad4        [4]byte
}

type TXFS_ROLLFORWARD_REDO_INFORMATION = TTXFS_ROLLFORWARD_REDO_INFORMATION

type T_TXFS_ROLLFORWARD_REDO_INFORMATION = TTXFS_ROLLFORWARD_REDO_INFORMATION

type _TXFS_ROLLFORWARD_REDO_INFORMATION = T_TXFS_ROLLFORWARD_REDO_INFORMATION

type TPTXFS_ROLLFORWARD_REDO_INFORMATION = uintptr

type PTXFS_ROLLFORWARD_REDO_INFORMATION = TPTXFS_ROLLFORWARD_REDO_INFORMATION

type TTXFS_START_RM_INFORMATION = struct {
	F__ccgo_align            [0]uint32
	FFlags                   TULONG
	F__ccgo_align1           [4]byte
	FLogContainerSize        TULONGLONG
	FLogContainerCountMin    TULONG
	FLogContainerCountMax    TULONG
	FLogGrowthIncrement      TULONG
	FLogAutoShrinkPercentage TULONG
	FTmLogPathOffset         TULONG
	FTmLogPathLength         TUSHORT
	FLoggingMode             TUSHORT
	FLogPathLength           TUSHORT
	FReserved                TUSHORT
	FLogPath                 [1]TWCHAR
	F__ccgo_pad12            [2]byte
}

type TXFS_START_RM_INFORMATION = TTXFS_START_RM_INFORMATION

type T_TXFS_START_RM_INFORMATION = TTXFS_START_RM_INFORMATION

type _TXFS_START_RM_INFORMATION = T_TXFS_START_RM_INFORMATION

type TPTXFS_START_RM_INFORMATION = uintptr

type PTXFS_START_RM_INFORMATION = TPTXFS_START_RM_INFORMATION

type TTXFS_GET_METADATA_INFO_OUT = struct {
	F__ccgo_align [0]uint32
	FTxfFileId    struct {
		F__ccgo_align [0]uint32
		FLowPart      TLONGLONG
		FHighPart     TLONGLONG
	}
	FLockingTransaction TGUID
	FLastLsn            TULONGLONG
	FTransactionState   TULONG
	F__ccgo_pad4        [4]byte
}

type TXFS_GET_METADATA_INFO_OUT = TTXFS_GET_METADATA_INFO_OUT

type T_TXFS_GET_METADATA_INFO_OUT = TTXFS_GET_METADATA_INFO_OUT

type _TXFS_GET_METADATA_INFO_OUT = T_TXFS_GET_METADATA_INFO_OUT

type TPTXFS_GET_METADATA_INFO_OUT = uintptr

type PTXFS_GET_METADATA_INFO_OUT = TPTXFS_GET_METADATA_INFO_OUT

type TTXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY = struct {
	F__ccgo_align  [0]uint32
	FOffset        TULONGLONG
	FNameFlags     TULONG
	F__ccgo_align2 [4]byte
	FFileId        TLONGLONG
	FReserved1     TULONG
	FReserved2     TULONG
	FReserved3     TLONGLONG
	FFileName      [1]TWCHAR
	F__ccgo_pad7   [6]byte
}

type TXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY = TTXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY

type T_TXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY = TTXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY

type _TXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY = T_TXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY

type TPTXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY = uintptr

type PTXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY = TPTXFS_LIST_TRANSACTION_LOCKED_FILES_ENTRY

type TTXFS_LIST_TRANSACTION_LOCKED_FILES = struct {
	F__ccgo_align       [0]uint32
	FKtmTransaction     TGUID
	FNumberOfFiles      TULONGLONG
	FBufferSizeRequired TULONGLONG
	FOffset             TULONGLONG
}

type TXFS_LIST_TRANSACTION_LOCKED_FILES = TTXFS_LIST_TRANSACTION_LOCKED_FILES

type T_TXFS_LIST_TRANSACTION_LOCKED_FILES = TTXFS_LIST_TRANSACTION_LOCKED_FILES

type _TXFS_LIST_TRANSACTION_LOCKED_FILES = T_TXFS_LIST_TRANSACTION_LOCKED_FILES

type TPTXFS_LIST_TRANSACTION_LOCKED_FILES = uintptr

type PTXFS_LIST_TRANSACTION_LOCKED_FILES = TPTXFS_LIST_TRANSACTION_LOCKED_FILES

type TTXFS_LIST_TRANSACTIONS_ENTRY = struct {
	F__ccgo_align     [0]uint32
	FTransactionId    TGUID
	FTransactionState TULONG
	FReserved1        TULONG
	FReserved2        TULONG
	F__ccgo_align4    [4]byte
	FReserved3        TLONGLONG
}

type TXFS_LIST_TRANSACTIONS_ENTRY = TTXFS_LIST_TRANSACTIONS_ENTRY

type T_TXFS_LIST_TRANSACTIONS_ENTRY = TTXFS_LIST_TRANSACTIONS_ENTRY

type _TXFS_LIST_TRANSACTIONS_ENTRY = T_TXFS_LIST_TRANSACTIONS_ENTRY

type TPTXFS_LIST_TRANSACTIONS_ENTRY = uintptr

type PTXFS_LIST_TRANSACTIONS_ENTRY = TPTXFS_LIST_TRANSACTIONS_ENTRY

type TTXFS_LIST_TRANSACTIONS = struct {
	F__ccgo_align         [0]uint32
	FNumberOfTransactions TULONGLONG
	FBufferSizeRequired   TULONGLONG
}

type TXFS_LIST_TRANSACTIONS = TTXFS_LIST_TRANSACTIONS

type T_TXFS_LIST_TRANSACTIONS = TTXFS_LIST_TRANSACTIONS

type _TXFS_LIST_TRANSACTIONS = T_TXFS_LIST_TRANSACTIONS

type TPTXFS_LIST_TRANSACTIONS = uintptr

type PTXFS_LIST_TRANSACTIONS = TPTXFS_LIST_TRANSACTIONS

type TTXFS_READ_BACKUP_INFORMATION_OUT = struct {
	F__ccgo0_0 struct {
		FBuffer       [0]TUCHAR
		FBufferLength TULONG
	}
}

type TXFS_READ_BACKUP_INFORMATION_OUT = TTXFS_READ_BACKUP_INFORMATION_OUT

type T_TXFS_READ_BACKUP_INFORMATION_OUT = TTXFS_READ_BACKUP_INFORMATION_OUT

type _TXFS_READ_BACKUP_INFORMATION_OUT = T_TXFS_READ_BACKUP_INFORMATION_OUT

type TPTXFS_READ_BACKUP_INFORMATION_OUT = uintptr

type PTXFS_READ_BACKUP_INFORMATION_OUT = TPTXFS_READ_BACKUP_INFORMATION_OUT

type TTXFS_WRITE_BACKUP_INFORMATION = struct {
	FBuffer TUCHAR
}

type TXFS_WRITE_BACKUP_INFORMATION = TTXFS_WRITE_BACKUP_INFORMATION

type T_TXFS_WRITE_BACKUP_INFORMATION = TTXFS_WRITE_BACKUP_INFORMATION

type _TXFS_WRITE_BACKUP_INFORMATION = T_TXFS_WRITE_BACKUP_INFORMATION

type TPTXFS_WRITE_BACKUP_INFORMATION = uintptr

type PTXFS_WRITE_BACKUP_INFORMATION = TPTXFS_WRITE_BACKUP_INFORMATION

type TTXFS_GET_TRANSACTED_VERSION = struct {
	FThisBaseVersion   TULONG
	FLatestVersion     TULONG
	FThisMiniVersion   TUSHORT
	FFirstMiniVersion  TUSHORT
	FLatestMiniVersion TUSHORT
}

type TXFS_GET_TRANSACTED_VERSION = TTXFS_GET_TRANSACTED_VERSION

type T_TXFS_GET_TRANSACTED_VERSION = TTXFS_GET_TRANSACTED_VERSION

type _TXFS_GET_TRANSACTED_VERSION = T_TXFS_GET_TRANSACTED_VERSION

type TPTXFS_GET_TRANSACTED_VERSION = uintptr

type PTXFS_GET_TRANSACTED_VERSION = TPTXFS_GET_TRANSACTED_VERSION

type TTXFS_SAVEPOINT_INFORMATION = struct {
	FKtmTransaction THANDLE
	FActionCode     TULONG
	FSavepointId    TULONG
}

type TXFS_SAVEPOINT_INFORMATION = TTXFS_SAVEPOINT_INFORMATION

type T_TXFS_SAVEPOINT_INFORMATION = TTXFS_SAVEPOINT_INFORMATION

type _TXFS_SAVEPOINT_INFORMATION = T_TXFS_SAVEPOINT_INFORMATION

type TPTXFS_SAVEPOINT_INFORMATION = uintptr

type PTXFS_SAVEPOINT_INFORMATION = TPTXFS_SAVEPOINT_INFORMATION

type TTXFS_CREATE_MINIVERSION_INFO = struct {
	FStructureVersion TUSHORT
	FStructureLength  TUSHORT
	FBaseVersion      TULONG
	FMiniVersion      TUSHORT
}

type TXFS_CREATE_MINIVERSION_INFO = TTXFS_CREATE_MINIVERSION_INFO

type T_TXFS_CREATE_MINIVERSION_INFO = TTXFS_CREATE_MINIVERSION_INFO

type _TXFS_CREATE_MINIVERSION_INFO = T_TXFS_CREATE_MINIVERSION_INFO

type TPTXFS_CREATE_MINIVERSION_INFO = uintptr

type PTXFS_CREATE_MINIVERSION_INFO = TPTXFS_CREATE_MINIVERSION_INFO

type TTXFS_TRANSACTION_ACTIVE_INFO = struct {
	FTransactionsActiveAtSnapshot TBOOLEAN
}

type TXFS_TRANSACTION_ACTIVE_INFO = TTXFS_TRANSACTION_ACTIVE_INFO

type T_TXFS_TRANSACTION_ACTIVE_INFO = TTXFS_TRANSACTION_ACTIVE_INFO

type _TXFS_TRANSACTION_ACTIVE_INFO = T_TXFS_TRANSACTION_ACTIVE_INFO

type TPTXFS_TRANSACTION_ACTIVE_INFO = uintptr

type PTXFS_TRANSACTION_ACTIVE_INFO = TPTXFS_TRANSACTION_ACTIVE_INFO

type TWRITE_CACHE_TYPE = int32

type WRITE_CACHE_TYPE = TWRITE_CACHE_TYPE

type __WRITE_CACHE_TYPE = int32

const _WriteCacheTypeUnknown = 0
const _WriteCacheTypeNone = 1
const _WriteCacheTypeWriteBack = 2
const _WriteCacheTypeWriteThrough = 3

type TWRITE_CACHE_ENABLE = int32

type WRITE_CACHE_ENABLE = TWRITE_CACHE_ENABLE

type __WRITE_CACHE_ENABLE = int32

const _WriteCacheEnableUnknown = 0
const _WriteCacheDisabled = 1
const _WriteCacheEnabled = 2

type TWRITE_CACHE_CHANGE = int32

type WRITE_CACHE_CHANGE = TWRITE_CACHE_CHANGE

type __WRITE_CACHE_CHANGE = int32

const _WriteCacheChangeUnknown = 0
const _WriteCacheNotChangeable = 1
const _WriteCacheChangeable = 2

type TWRITE_THROUGH = int32

type WRITE_THROUGH = TWRITE_THROUGH

type __WRITE_THROUGH = int32

const _WriteThroughUnknown = 0
const _WriteThroughNotSupported = 1
const _WriteThroughSupported = 2

type TSTORAGE_WRITE_CACHE_PROPERTY = struct {
	FVersion                    TDWORD
	FSize                       TDWORD
	FWriteCacheType             TWRITE_CACHE_TYPE
	FWriteCacheEnabled          TWRITE_CACHE_ENABLE
	FWriteCacheChangeable       TWRITE_CACHE_CHANGE
	FWriteThroughSupported      TWRITE_THROUGH
	FFlushCacheSupported        TBOOLEAN
	FUserDefinedPowerProtection TBOOLEAN
	FNVCacheEnabled             TBOOLEAN
}

type STORAGE_WRITE_CACHE_PROPERTY = TSTORAGE_WRITE_CACHE_PROPERTY

type T_STORAGE_WRITE_CACHE_PROPERTY = TSTORAGE_WRITE_CACHE_PROPERTY

type _STORAGE_WRITE_CACHE_PROPERTY = T_STORAGE_WRITE_CACHE_PROPERTY

type TPSTORAGE_WRITE_CACHE_PROPERTY = uintptr

type PSTORAGE_WRITE_CACHE_PROPERTY = TPSTORAGE_WRITE_CACHE_PROPERTY

type TSTORAGE_PORT_CODE_SET = int32

type STORAGE_PORT_CODE_SET = TSTORAGE_PORT_CODE_SET

type __STORAGE_PORT_CODE_SET = int32

const _StoragePortCodeSetReserved = 0
const _StoragePortCodeSetStorport = 1
const _StoragePortCodeSetSCSIport = 2
const _StoragePortCodeSetSpaceport = 3
const _StoragePortCodeSetATAport = 4
const _StoragePortCodeSetUSBport = 5
const _StoragePortCodeSetSBP2port = 6
const _StoragePortCodeSetSDport = 7

type TPSTORAGE_PORT_CODE_SET = uintptr

type PSTORAGE_PORT_CODE_SET = TPSTORAGE_PORT_CODE_SET

type TSTORAGE_MINIPORT_DESCRIPTOR = struct {
	FVersion              TDWORD
	FSize                 TDWORD
	FPortdriver           TSTORAGE_PORT_CODE_SET
	FLUNResetSupported    TBOOLEAN
	FTargetResetSupported TBOOLEAN
}

type STORAGE_MINIPORT_DESCRIPTOR = TSTORAGE_MINIPORT_DESCRIPTOR

type T_STORAGE_MINIPORT_DESCRIPTOR = TSTORAGE_MINIPORT_DESCRIPTOR

type _STORAGE_MINIPORT_DESCRIPTOR = T_STORAGE_MINIPORT_DESCRIPTOR

type TPSTORAGE_MINIPORT_DESCRIPTOR = uintptr

type PSTORAGE_MINIPORT_DESCRIPTOR = TPSTORAGE_MINIPORT_DESCRIPTOR

type TSTORAGE_IDENTIFIER_CODE_SET = int32

type STORAGE_IDENTIFIER_CODE_SET = TSTORAGE_IDENTIFIER_CODE_SET

type __STORAGE_IDENTIFIER_CODE_SET = int32

const _StorageIdCodeSetReserved = 0
const _StorageIdCodeSetBinary = 1
const _StorageIdCodeSetAscii = 2
const _StorageIdCodeSetUtf8 = 3

type TPSTORAGE_IDENTIFIER_CODE_SET = uintptr

type PSTORAGE_IDENTIFIER_CODE_SET = TPSTORAGE_IDENTIFIER_CODE_SET

type TSTORAGE_IDENTIFIER_TYPE = int32

type STORAGE_IDENTIFIER_TYPE = TSTORAGE_IDENTIFIER_TYPE

type __STORAGE_IDENTIFIER_TYPE = int32

const _StorageIdTypeVendorSpecific = 0
const _StorageIdTypeVendorId = 1
const _StorageIdTypeEUI64 = 2
const _StorageIdTypeFCPHName = 3
const _StorageIdTypePortRelative = 4
const _StorageIdTypeTargetPortGroup = 5
const _StorageIdTypeLogicalUnitGroup = 6
const _StorageIdTypeMD5LogicalUnitIdentifier = 7
const _StorageIdTypeScsiNameString = 8

type TPSTORAGE_IDENTIFIER_TYPE = uintptr

type PSTORAGE_IDENTIFIER_TYPE = TPSTORAGE_IDENTIFIER_TYPE

type TSTORAGE_ID_NAA_FORMAT = int32

type STORAGE_ID_NAA_FORMAT = TSTORAGE_ID_NAA_FORMAT

type __STORAGE_ID_NAA_FORMAT = int32

const _StorageIdNAAFormatIEEEExtended = 2
const _StorageIdNAAFormatIEEERegistered = 3
const _StorageIdNAAFormatIEEEERegisteredExtended = 5

type TPSTORAGE_ID_NAA_FORMAT = uintptr

type PSTORAGE_ID_NAA_FORMAT = TPSTORAGE_ID_NAA_FORMAT

type TSTORAGE_ASSOCIATION_TYPE = int32

type STORAGE_ASSOCIATION_TYPE = TSTORAGE_ASSOCIATION_TYPE

type __STORAGE_ASSOCIATION_TYPE = int32

const _StorageIdAssocDevice = 0
const _StorageIdAssocPort = 1
const _StorageIdAssocTarget = 2

type TPSTORAGE_ASSOCIATION_TYPE = uintptr

type PSTORAGE_ASSOCIATION_TYPE = TPSTORAGE_ASSOCIATION_TYPE

type TSTORAGE_IDENTIFIER = struct {
	FCodeSet        TSTORAGE_IDENTIFIER_CODE_SET
	FType           TSTORAGE_IDENTIFIER_TYPE
	FIdentifierSize TUSHORT
	FNextOffset     TUSHORT
	FAssociation    TSTORAGE_ASSOCIATION_TYPE
	FIdentifier     [1]TUCHAR
}

type STORAGE_IDENTIFIER = TSTORAGE_IDENTIFIER

type T_STORAGE_IDENTIFIER = TSTORAGE_IDENTIFIER

type _STORAGE_IDENTIFIER = T_STORAGE_IDENTIFIER

type TPSTORAGE_IDENTIFIER = uintptr

type PSTORAGE_IDENTIFIER = TPSTORAGE_IDENTIFIER

type TSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR = struct {
	FVersion                       TDWORD
	FSize                          TDWORD
	FBytesPerCacheLine             TDWORD
	FBytesOffsetForCacheAlignment  TDWORD
	FBytesPerLogicalSector         TDWORD
	FBytesPerPhysicalSector        TDWORD
	FBytesOffsetForSectorAlignment TDWORD
}

type STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR = TSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR

type T_STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR = TSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR

type _STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR = T_STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR

type TPSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR = uintptr

type PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR = TPSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR

type TSTORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR = struct {
	FVersion           TDWORD
	FSize              TDWORD
	FMediumProductType TDWORD
}

type STORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR = TSTORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR

type T_STORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR = TSTORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR

type _STORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR = T_STORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR

type TPSTORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR = uintptr

type PSTORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR = TPSTORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR

type TDEVICE_SEEK_PENALTY_DESCRIPTOR = struct {
	FVersion           TDWORD
	FSize              TDWORD
	FIncursSeekPenalty TBOOLEAN
}

type DEVICE_SEEK_PENALTY_DESCRIPTOR = TDEVICE_SEEK_PENALTY_DESCRIPTOR

type T_DEVICE_SEEK_PENALTY_DESCRIPTOR = TDEVICE_SEEK_PENALTY_DESCRIPTOR

type _DEVICE_SEEK_PENALTY_DESCRIPTOR = T_DEVICE_SEEK_PENALTY_DESCRIPTOR

type TPDEVICE_SEEK_PENALTY_DESCRIPTOR = uintptr

type PDEVICE_SEEK_PENALTY_DESCRIPTOR = TPDEVICE_SEEK_PENALTY_DESCRIPTOR

type TDEVICE_WRITE_AGGREGATION_DESCRIPTOR = struct {
	FVersion                      TULONG
	FSize                         TULONG
	FBenefitsFromWriteAggregation TBOOLEAN
}

type DEVICE_WRITE_AGGREGATION_DESCRIPTOR = TDEVICE_WRITE_AGGREGATION_DESCRIPTOR

type T_DEVICE_WRITE_AGGREGATION_DESCRIPTOR = TDEVICE_WRITE_AGGREGATION_DESCRIPTOR

type _DEVICE_WRITE_AGGREGATION_DESCRIPTOR = T_DEVICE_WRITE_AGGREGATION_DESCRIPTOR

type TPDEVICE_WRITE_AGGREGATION_DESCRIPTOR = uintptr

type PDEVICE_WRITE_AGGREGATION_DESCRIPTOR = TPDEVICE_WRITE_AGGREGATION_DESCRIPTOR

type TDEVICE_TRIM_DESCRIPTOR = struct {
	FVersion     TDWORD
	FSize        TDWORD
	FTrimEnabled TBOOLEAN
}

type DEVICE_TRIM_DESCRIPTOR = TDEVICE_TRIM_DESCRIPTOR

type T_DEVICE_TRIM_DESCRIPTOR = TDEVICE_TRIM_DESCRIPTOR

type _DEVICE_TRIM_DESCRIPTOR = T_DEVICE_TRIM_DESCRIPTOR

type TPDEVICE_TRIM_DESCRIPTOR = uintptr

type PDEVICE_TRIM_DESCRIPTOR = TPDEVICE_TRIM_DESCRIPTOR

type TDEVICE_LB_PROVISIONING_DESCRIPTOR = struct {
	F__ccgo_align                 [0]uint32
	FVersion                      TDWORD
	FSize                         TDWORD
	F__ccgo8                      uint8
	FReserved1                    [7]TBYTE
	FOptimalUnmapGranularity      TDWORDLONG
	FUnmapGranularityAlignment    TDWORDLONG
	FMaxUnmapLbaCount             TDWORD
	FMaxUnmapBlockDescriptorCount TDWORD
}

type DEVICE_LB_PROVISIONING_DESCRIPTOR = TDEVICE_LB_PROVISIONING_DESCRIPTOR

type T_DEVICE_LB_PROVISIONING_DESCRIPTOR = TDEVICE_LB_PROVISIONING_DESCRIPTOR

type _DEVICE_LB_PROVISIONING_DESCRIPTOR = T_DEVICE_LB_PROVISIONING_DESCRIPTOR

type TPDEVICE_LB_PROVISIONING_DESCRIPTOR = uintptr

type PDEVICE_LB_PROVISIONING_DESCRIPTOR = TPDEVICE_LB_PROVISIONING_DESCRIPTOR

type TSTORAGE_LB_PROVISIONING_MAP_RESOURCES = struct {
	F__ccgo_align              [0]uint32
	FSize                      TDWORD
	FVersion                   TDWORD
	F__ccgo8                   uint8
	FReserved1                 [3]TBYTE
	F__ccgo12                  uint8
	FReserved3                 [3]TBYTE
	FAvailableMappingResources TDWORDLONG
	FUsedMappingResources      TDWORDLONG
}

type STORAGE_LB_PROVISIONING_MAP_RESOURCES = TSTORAGE_LB_PROVISIONING_MAP_RESOURCES

type T_STORAGE_LB_PROVISIONING_MAP_RESOURCES = TSTORAGE_LB_PROVISIONING_MAP_RESOURCES

type _STORAGE_LB_PROVISIONING_MAP_RESOURCES = T_STORAGE_LB_PROVISIONING_MAP_RESOURCES

type TPSTORAGE_LB_PROVISIONING_MAP_RESOURCES = uintptr

type PSTORAGE_LB_PROVISIONING_MAP_RESOURCES = TPSTORAGE_LB_PROVISIONING_MAP_RESOURCES

type TDEVICE_POWER_DESCRIPTOR = struct {
	FVersion                           TDWORD
	FSize                              TDWORD
	FDeviceAttentionSupported          TBOOLEAN
	FAsynchronousNotificationSupported TBOOLEAN
	FIdlePowerManagementEnabled        TBOOLEAN
	FD3ColdEnabled                     TBOOLEAN
	FD3ColdSupported                   TBOOLEAN
	FNoVerifyDuringIdlePower           TBOOLEAN
	FReserved                          [2]TBYTE
	FIdleTimeoutInMS                   TDWORD
}

type DEVICE_POWER_DESCRIPTOR = TDEVICE_POWER_DESCRIPTOR

type T_DEVICE_POWER_DESCRIPTOR = TDEVICE_POWER_DESCRIPTOR

type _DEVICE_POWER_DESCRIPTOR = T_DEVICE_POWER_DESCRIPTOR

type TPDEVICE_POWER_DESCRIPTOR = uintptr

type PDEVICE_POWER_DESCRIPTOR = TPDEVICE_POWER_DESCRIPTOR

type TDEVICE_COPY_OFFLOAD_DESCRIPTOR = struct {
	F__ccgo_align                       [0]uint32
	FVersion                            TDWORD
	FSize                               TDWORD
	FMaximumTokenLifetime               TDWORD
	FDefaultTokenLifetime               TDWORD
	FMaximumTransferSize                TDWORDLONG
	FOptimalTransferCount               TDWORDLONG
	FMaximumDataDescriptors             TDWORD
	FMaximumTransferLengthPerDescriptor TDWORD
	FOptimalTransferLengthPerDescriptor TDWORD
	FOptimalTransferLengthGranularity   TWORD
	FReserved                           [2]TBYTE
}

type DEVICE_COPY_OFFLOAD_DESCRIPTOR = TDEVICE_COPY_OFFLOAD_DESCRIPTOR

type T_DEVICE_COPY_OFFLOAD_DESCRIPTOR = TDEVICE_COPY_OFFLOAD_DESCRIPTOR

type _DEVICE_COPY_OFFLOAD_DESCRIPTOR = T_DEVICE_COPY_OFFLOAD_DESCRIPTOR

type TPDEVICE_COPY_OFFLOAD_DESCRIPTOR = uintptr

type PDEVICE_COPY_OFFLOAD_DESCRIPTOR = TPDEVICE_COPY_OFFLOAD_DESCRIPTOR

type TSTORAGE_DEVICE_RESILIENCY_DESCRIPTOR = struct {
	FVersion                TDWORD
	FSize                   TDWORD
	FNameOffset             TDWORD
	FNumberOfLogicalCopies  TDWORD
	FNumberOfPhysicalCopies TDWORD
	FPhysicalDiskRedundancy TDWORD
	FNumberOfColumns        TDWORD
	FInterleave             TDWORD
}

type STORAGE_DEVICE_RESILIENCY_DESCRIPTOR = TSTORAGE_DEVICE_RESILIENCY_DESCRIPTOR

type T_STORAGE_DEVICE_RESILIENCY_DESCRIPTOR = TSTORAGE_DEVICE_RESILIENCY_DESCRIPTOR

type _STORAGE_DEVICE_RESILIENCY_DESCRIPTOR = T_STORAGE_DEVICE_RESILIENCY_DESCRIPTOR

type TPSTORAGE_DEVICE_RESILIENCY_DESCRIPTOR = uintptr

type PSTORAGE_DEVICE_RESILIENCY_DESCRIPTOR = TPSTORAGE_DEVICE_RESILIENCY_DESCRIPTOR

type TSTORAGE_RPMB_FRAME_TYPE = int32

type STORAGE_RPMB_FRAME_TYPE = TSTORAGE_RPMB_FRAME_TYPE

type __STORAGE_RPMB_FRAME_TYPE = int32

const _StorageRpmbFrameTypeUnknown = 0
const _StorageRpmbFrameTypeStandard = 1
const _StorageRpmbFrameTypeMax = 2

type TPSTORAGE_RPMB_FRAME_TYPE = uintptr

type PSTORAGE_RPMB_FRAME_TYPE = TPSTORAGE_RPMB_FRAME_TYPE

type TSTORAGE_RPMB_DESCRIPTOR = struct {
	FVersion                     TDWORD
	FSize                        TDWORD
	FSizeInBytes                 TDWORD
	FMaxReliableWriteSizeInBytes TDWORD
	FFrameFormat                 TSTORAGE_RPMB_FRAME_TYPE
}

type STORAGE_RPMB_DESCRIPTOR = TSTORAGE_RPMB_DESCRIPTOR

type T_STORAGE_RPMB_DESCRIPTOR = TSTORAGE_RPMB_DESCRIPTOR

type _STORAGE_RPMB_DESCRIPTOR = T_STORAGE_RPMB_DESCRIPTOR

type TPSTORAGE_RPMB_DESCRIPTOR = uintptr

type PSTORAGE_RPMB_DESCRIPTOR = TPSTORAGE_RPMB_DESCRIPTOR

type TSTORAGE_CRYPTO_ALGORITHM_ID = int32

type STORAGE_CRYPTO_ALGORITHM_ID = TSTORAGE_CRYPTO_ALGORITHM_ID

type __STORAGE_CRYPTO_ALGORITHM_ID = int32

const _StorageCryptoAlgorithmUnknown = 0
const _StorageCryptoAlgorithmXTSAES = 1
const _StorageCryptoAlgorithmBitlockerAESCBC = 2
const _StorageCryptoAlgorithmAESECB = 3
const _StorageCryptoAlgorithmESSIVAESCBC = 4
const _StorageCryptoAlgorithmMax = 5

type TPSTORAGE_CRYPTO_ALGORITHM_ID = uintptr

type PSTORAGE_CRYPTO_ALGORITHM_ID = TPSTORAGE_CRYPTO_ALGORITHM_ID

type TSTORAGE_CRYPTO_KEY_SIZE = int32

type STORAGE_CRYPTO_KEY_SIZE = TSTORAGE_CRYPTO_KEY_SIZE

type __STORAGE_CRYPTO_KEY_SIZE = int32

const _StorageCryptoKeySizeUnknown = 0
const _StorageCryptoKeySize128Bits = 1
const _StorageCryptoKeySize192Bits = 2
const _StorageCryptoKeySize256Bits = 3
const _StorageCryptoKeySize512Bits = 4

type TPSTORAGE_CRYPTO_KEY_SIZE = uintptr

type PSTORAGE_CRYPTO_KEY_SIZE = TPSTORAGE_CRYPTO_KEY_SIZE

type TSTORAGE_CRYPTO_CAPABILITY = struct {
	FVersion               TDWORD
	FSize                  TDWORD
	FCryptoCapabilityIndex TDWORD
	FAlgorithmId           TSTORAGE_CRYPTO_ALGORITHM_ID
	FKeySize               TSTORAGE_CRYPTO_KEY_SIZE
	FDataUnitSizeBitmask   TDWORD
}

type STORAGE_CRYPTO_CAPABILITY = TSTORAGE_CRYPTO_CAPABILITY

type T_STORAGE_CRYPTO_CAPABILITY = TSTORAGE_CRYPTO_CAPABILITY

type _STORAGE_CRYPTO_CAPABILITY = T_STORAGE_CRYPTO_CAPABILITY

type TPSTORAGE_CRYPTO_CAPABILITY = uintptr

type PSTORAGE_CRYPTO_CAPABILITY = TPSTORAGE_CRYPTO_CAPABILITY

type TSTORAGE_CRYPTO_DESCRIPTOR = struct {
	FVersion               TDWORD
	FSize                  TDWORD
	FNumKeysSupported      TDWORD
	FNumCryptoCapabilities TDWORD
	FCryptoCapabilities    [1]TSTORAGE_CRYPTO_CAPABILITY
}

type STORAGE_CRYPTO_DESCRIPTOR = TSTORAGE_CRYPTO_DESCRIPTOR

type T_STORAGE_CRYPTO_DESCRIPTOR = TSTORAGE_CRYPTO_DESCRIPTOR

type _STORAGE_CRYPTO_DESCRIPTOR = T_STORAGE_CRYPTO_DESCRIPTOR

type TPSTORAGE_CRYPTO_DESCRIPTOR = uintptr

type PSTORAGE_CRYPTO_DESCRIPTOR = TPSTORAGE_CRYPTO_DESCRIPTOR

type TSTORAGE_TIER_MEDIA_TYPE = int32

type STORAGE_TIER_MEDIA_TYPE = TSTORAGE_TIER_MEDIA_TYPE

type __STORAGE_TIER_MEDIA_TYPE = int32

const _StorageTierMediaTypeUnspecified = 0
const _StorageTierMediaTypeDisk = 1
const _StorageTierMediaTypeSsd = 2
const _StorageTierMediaTypeScm = 4
const _StorageTierMediaTypeMax = 5

type TPSTORAGE_TIER_MEDIA_TYPE = uintptr

type PSTORAGE_TIER_MEDIA_TYPE = TPSTORAGE_TIER_MEDIA_TYPE

type TSTORAGE_TIER_CLASS = int32

type STORAGE_TIER_CLASS = TSTORAGE_TIER_CLASS

type __STORAGE_TIER_CLASS = int32

const _StorageTierClassUnspecified = 0
const _StorageTierClassCapacity = 1
const _StorageTierClassPerformance = 2
const _StorageTierClassMax = 3

type TPSTORAGE_TIER_CLASS = uintptr

type PSTORAGE_TIER_CLASS = TPSTORAGE_TIER_CLASS

type TSTORAGE_TIER = struct {
	F__ccgo_align        [0]uint32
	FId                  TGUID
	FName                [256]TWCHAR
	FDescription         [256]TWCHAR
	FFlags               TDWORDLONG
	FProvisionedCapacity TDWORDLONG
	FMediaType           TSTORAGE_TIER_MEDIA_TYPE
	FClass               TSTORAGE_TIER_CLASS
}

type STORAGE_TIER = TSTORAGE_TIER

type T_STORAGE_TIER = TSTORAGE_TIER

type _STORAGE_TIER = T_STORAGE_TIER

type TPSTORAGE_TIER = uintptr

type PSTORAGE_TIER = TPSTORAGE_TIER

type TSTORAGE_DEVICE_TIERING_DESCRIPTOR = struct {
	F__ccgo_align          [0]uint32
	FVersion               TDWORD
	FSize                  TDWORD
	FFlags                 TDWORD
	FTotalNumberOfTiers    TDWORD
	FNumberOfTiersReturned TDWORD
	F__ccgo_align5         [4]byte
	FTiers                 [1]TSTORAGE_TIER
}

type STORAGE_DEVICE_TIERING_DESCRIPTOR = TSTORAGE_DEVICE_TIERING_DESCRIPTOR

type T_STORAGE_DEVICE_TIERING_DESCRIPTOR = TSTORAGE_DEVICE_TIERING_DESCRIPTOR

type _STORAGE_DEVICE_TIERING_DESCRIPTOR = T_STORAGE_DEVICE_TIERING_DESCRIPTOR

type TPSTORAGE_DEVICE_TIERING_DESCRIPTOR = uintptr

type PSTORAGE_DEVICE_TIERING_DESCRIPTOR = TPSTORAGE_DEVICE_TIERING_DESCRIPTOR

type TSTORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR = struct {
	FVersion              TDWORD
	FSize                 TDWORD
	FNumberOfFaultDomains TDWORD
	FFaultDomainIds       [1]TGUID
}

type STORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR = TSTORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR

type T_STORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR = TSTORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR

type _STORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR = T_STORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR

type TPSTORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR = uintptr

type PSTORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR = TPSTORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR

type TSTORAGE_PROTOCOL_TYPE = int32

type STORAGE_PROTOCOL_TYPE = TSTORAGE_PROTOCOL_TYPE

type __STORAGE_PROTOCOL_TYPE = int32

const _ProtocolTypeUnknown = 0
const _ProtocolTypeScsi = 1
const _ProtocolTypeAta = 2
const _ProtocolTypeNvme = 3
const _ProtocolTypeSd = 4
const _ProtocolTypeUfs = 5
const _ProtocolTypeProprietary = 126
const _ProtocolTypeMaxReserved = 127

type TPSTORAGE_PROTOCOL_TYPE = uintptr

type PSTORAGE_PROTOCOL_TYPE = TPSTORAGE_PROTOCOL_TYPE

type TSTORAGE_PROTOCOL_NVME_DATA_TYPE = int32

type STORAGE_PROTOCOL_NVME_DATA_TYPE = TSTORAGE_PROTOCOL_NVME_DATA_TYPE

type __STORAGE_PROTOCOL_NVME_DATA_TYPE = int32

const _NVMeDataTypeUnknown = 0
const _NVMeDataTypeIdentify = 1
const _NVMeDataTypeLogPage = 2
const _NVMeDataTypeFeature = 3

type TPSTORAGE_PROTOCOL_NVME_DATA_TYPE = uintptr

type PSTORAGE_PROTOCOL_NVME_DATA_TYPE = TPSTORAGE_PROTOCOL_NVME_DATA_TYPE

type TSTORAGE_PROTOCOL_ATA_DATA_TYPE = int32

type STORAGE_PROTOCOL_ATA_DATA_TYPE = TSTORAGE_PROTOCOL_ATA_DATA_TYPE

type __STORAGE_PROTOCOL_ATA_DATA_TYPE = int32

const _AtaDataTypeUnknown = 0
const _AtaDataTypeIdentify = 1
const _AtaDataTypeLogPage = 2

type TPSTORAGE_PROTOCOL_ATA_DATA_TYPE = uintptr

type PSTORAGE_PROTOCOL_ATA_DATA_TYPE = TPSTORAGE_PROTOCOL_ATA_DATA_TYPE

type TSTORAGE_PROTOCOL_UFS_DATA_TYPE = int32

type STORAGE_PROTOCOL_UFS_DATA_TYPE = TSTORAGE_PROTOCOL_UFS_DATA_TYPE

type __STORAGE_PROTOCOL_UFS_DATA_TYPE = int32

const _UfsDataTypeUnknown = 0
const _UfsDataTypeQueryDescriptor = 1
const _UfsDataTypeQueryAttribute = 2
const _UfsDataTypeQueryFlag = 3
const _UfsDataTypeQueryDmeAttribute = 4
const _UfsDataTypeQueryDmePeerAttribute = 5
const _UfsDataTypeMax = 6

type TPSTORAGE_PROTOCOL_UFS_DATA_TYPE = uintptr

type PSTORAGE_PROTOCOL_UFS_DATA_TYPE = TPSTORAGE_PROTOCOL_UFS_DATA_TYPE

type TSTORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE = struct {
	FAsUlong   [0]TDWORD
	F__ccgo0_0 struct {
		F__ccgo0 uint32
	}
}

type STORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE = TSTORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE

type T_STORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE = TSTORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE

type _STORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE = T_STORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE

type TPSTORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE = uintptr

type PSTORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE = TPSTORAGE_PROTOCOL_DATA_SUBVALUE_GET_LOG_PAGE

type TSTORAGE_PROTOCOL_SPECIFIC_DATA = struct {
	FProtocolType                 TSTORAGE_PROTOCOL_TYPE
	FDataType                     TDWORD
	FProtocolDataRequestValue     TDWORD
	FProtocolDataRequestSubValue  TDWORD
	FProtocolDataOffset           TDWORD
	FProtocolDataLength           TDWORD
	FFixedProtocolReturnData      TDWORD
	FProtocolDataRequestSubValue2 TDWORD
	FProtocolDataRequestSubValue3 TDWORD
	FProtocolDataRequestSubValue4 TDWORD
}

type STORAGE_PROTOCOL_SPECIFIC_DATA = TSTORAGE_PROTOCOL_SPECIFIC_DATA

type T_STORAGE_PROTOCOL_SPECIFIC_DATA = TSTORAGE_PROTOCOL_SPECIFIC_DATA

type _STORAGE_PROTOCOL_SPECIFIC_DATA = T_STORAGE_PROTOCOL_SPECIFIC_DATA

type TPSTORAGE_PROTOCOL_SPECIFIC_DATA = uintptr

type PSTORAGE_PROTOCOL_SPECIFIC_DATA = TPSTORAGE_PROTOCOL_SPECIFIC_DATA

type TSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT = struct {
	FProtocolType            TSTORAGE_PROTOCOL_TYPE
	FDataType                TDWORD
	FProtocolDataValue       TDWORD
	FProtocolDataSubValue    TDWORD
	FProtocolDataOffset      TDWORD
	FProtocolDataLength      TDWORD
	FFixedProtocolReturnData TDWORD
	FProtocolDataSubValue2   TDWORD
	FProtocolDataSubValue3   TDWORD
	FProtocolDataSubValue4   TDWORD
	FProtocolDataSubValue5   TDWORD
	FReserved                [5]TDWORD
}

type STORAGE_PROTOCOL_SPECIFIC_DATA_EXT = TSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT

type T_STORAGE_PROTOCOL_SPECIFIC_DATA_EXT = TSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT

type _STORAGE_PROTOCOL_SPECIFIC_DATA_EXT = T_STORAGE_PROTOCOL_SPECIFIC_DATA_EXT

type TPSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT = uintptr

type PSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT = TPSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT

type TSTORAGE_PROTOCOL_DATA_DESCRIPTOR = struct {
	FVersion              TDWORD
	FSize                 TDWORD
	FProtocolSpecificData TSTORAGE_PROTOCOL_SPECIFIC_DATA
}

type STORAGE_PROTOCOL_DATA_DESCRIPTOR = TSTORAGE_PROTOCOL_DATA_DESCRIPTOR

type T_STORAGE_PROTOCOL_DATA_DESCRIPTOR = TSTORAGE_PROTOCOL_DATA_DESCRIPTOR

type _STORAGE_PROTOCOL_DATA_DESCRIPTOR = T_STORAGE_PROTOCOL_DATA_DESCRIPTOR

type TPSTORAGE_PROTOCOL_DATA_DESCRIPTOR = uintptr

type PSTORAGE_PROTOCOL_DATA_DESCRIPTOR = TPSTORAGE_PROTOCOL_DATA_DESCRIPTOR

type TSTORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT = struct {
	FVersion              TDWORD
	FSize                 TDWORD
	FProtocolSpecificData TSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT
}

type STORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT = TSTORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT

type T_STORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT = TSTORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT

type _STORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT = T_STORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT

type TPSTORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT = uintptr

type PSTORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT = TPSTORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT

type TREQUEST_OPLOCK_INPUT_BUFFER = struct {
	FStructureVersion     TWORD
	FStructureLength      TWORD
	FRequestedOplockLevel TDWORD
	FFlags                TDWORD
}

type REQUEST_OPLOCK_INPUT_BUFFER = TREQUEST_OPLOCK_INPUT_BUFFER

type T_REQUEST_OPLOCK_INPUT_BUFFER = TREQUEST_OPLOCK_INPUT_BUFFER

type _REQUEST_OPLOCK_INPUT_BUFFER = T_REQUEST_OPLOCK_INPUT_BUFFER

type TPREQUEST_OPLOCK_INPUT_BUFFER = uintptr

type PREQUEST_OPLOCK_INPUT_BUFFER = TPREQUEST_OPLOCK_INPUT_BUFFER

type TREQUEST_OPLOCK_OUTPUT_BUFFER = struct {
	FStructureVersion    TWORD
	FStructureLength     TWORD
	FOriginalOplockLevel TDWORD
	FNewOplockLevel      TDWORD
	FFlags               TDWORD
	FAccessMode          TACCESS_MASK
	FShareMode           TWORD
}

type REQUEST_OPLOCK_OUTPUT_BUFFER = TREQUEST_OPLOCK_OUTPUT_BUFFER

type T_REQUEST_OPLOCK_OUTPUT_BUFFER = TREQUEST_OPLOCK_OUTPUT_BUFFER

type _REQUEST_OPLOCK_OUTPUT_BUFFER = T_REQUEST_OPLOCK_OUTPUT_BUFFER

type TPREQUEST_OPLOCK_OUTPUT_BUFFER = uintptr

type PREQUEST_OPLOCK_OUTPUT_BUFFER = TPREQUEST_OPLOCK_OUTPUT_BUFFER

type TBOOT_AREA_INFO = struct {
	F__ccgo_align    [0]uint32
	FBootSectorCount TULONG
	F__ccgo_align1   [4]byte
	FBootSectors     [2]struct {
		F__ccgo_align [0]uint32
		FOffset       TLARGE_INTEGER
	}
}

type BOOT_AREA_INFO = TBOOT_AREA_INFO

type T_BOOT_AREA_INFO = TBOOT_AREA_INFO

type _BOOT_AREA_INFO = T_BOOT_AREA_INFO

type TPBOOT_AREA_INFO = uintptr

type PBOOT_AREA_INFO = TPBOOT_AREA_INFO

type TRETRIEVAL_POINTER_BASE = struct {
	F__ccgo_align   [0]uint32
	FFileAreaOffset TLARGE_INTEGER
}

type RETRIEVAL_POINTER_BASE = TRETRIEVAL_POINTER_BASE

type T_RETRIEVAL_POINTER_BASE = TRETRIEVAL_POINTER_BASE

type _RETRIEVAL_POINTER_BASE = T_RETRIEVAL_POINTER_BASE

type TPRETRIEVAL_POINTER_BASE = uintptr

type PRETRIEVAL_POINTER_BASE = TPRETRIEVAL_POINTER_BASE

type TFILE_FS_PERSISTENT_VOLUME_INFORMATION = struct {
	FVolumeFlags TULONG
	FFlagMask    TULONG
	FVersion     TULONG
	FReserved    TULONG
}

type FILE_FS_PERSISTENT_VOLUME_INFORMATION = TFILE_FS_PERSISTENT_VOLUME_INFORMATION

type T_FILE_FS_PERSISTENT_VOLUME_INFORMATION = TFILE_FS_PERSISTENT_VOLUME_INFORMATION

type _FILE_FS_PERSISTENT_VOLUME_INFORMATION = T_FILE_FS_PERSISTENT_VOLUME_INFORMATION

type TPFILE_FS_PERSISTENT_VOLUME_INFORMATION = uintptr

type PFILE_FS_PERSISTENT_VOLUME_INFORMATION = TPFILE_FS_PERSISTENT_VOLUME_INFORMATION

type TFILE_SYSTEM_RECOGNITION_INFORMATION = struct {
	FFileSystem [9]TCHAR
}

type FILE_SYSTEM_RECOGNITION_INFORMATION = TFILE_SYSTEM_RECOGNITION_INFORMATION

type T_FILE_SYSTEM_RECOGNITION_INFORMATION = TFILE_SYSTEM_RECOGNITION_INFORMATION

type _FILE_SYSTEM_RECOGNITION_INFORMATION = T_FILE_SYSTEM_RECOGNITION_INFORMATION

type TPFILE_SYSTEM_RECOGNITION_INFORMATION = uintptr

type PFILE_SYSTEM_RECOGNITION_INFORMATION = TPFILE_SYSTEM_RECOGNITION_INFORMATION

type TFILE_SYSTEM_RECOGNITION_STRUCTURE = struct {
	FJmp        [3]TUCHAR
	FFsName     [8]TUCHAR
	FMustBeZero [5]TUCHAR
	FIdentifier TULONG
	FLength     TUSHORT
	FChecksum   TUSHORT
}

type FILE_SYSTEM_RECOGNITION_STRUCTURE = TFILE_SYSTEM_RECOGNITION_STRUCTURE

type T_FILE_SYSTEM_RECOGNITION_STRUCTURE = TFILE_SYSTEM_RECOGNITION_STRUCTURE

type _FILE_SYSTEM_RECOGNITION_STRUCTURE = T_FILE_SYSTEM_RECOGNITION_STRUCTURE

type TSD_CHANGE_MACHINE_SID_INPUT = struct {
	FCurrentMachineSIDOffset TUSHORT
	FCurrentMachineSIDLength TUSHORT
	FNewMachineSIDOffset     TUSHORT
	FNewMachineSIDLength     TUSHORT
}

type SD_CHANGE_MACHINE_SID_INPUT = TSD_CHANGE_MACHINE_SID_INPUT

type T_SD_CHANGE_MACHINE_SID_INPUT = TSD_CHANGE_MACHINE_SID_INPUT

type _SD_CHANGE_MACHINE_SID_INPUT = T_SD_CHANGE_MACHINE_SID_INPUT

type TPSD_CHANGE_MACHINE_SID_INPUT = uintptr

type PSD_CHANGE_MACHINE_SID_INPUT = TPSD_CHANGE_MACHINE_SID_INPUT

type TSD_CHANGE_MACHINE_SID_OUTPUT = struct {
	F__ccgo_align           [0]uint32
	FNumSDChangedSuccess    TULONGLONG
	FNumSDChangedFail       TULONGLONG
	FNumSDUnused            TULONGLONG
	FNumSDTotal             TULONGLONG
	FNumMftSDChangedSuccess TULONGLONG
	FNumMftSDChangedFail    TULONGLONG
	FNumMftSDTotal          TULONGLONG
}

type SD_CHANGE_MACHINE_SID_OUTPUT = TSD_CHANGE_MACHINE_SID_OUTPUT

type T_SD_CHANGE_MACHINE_SID_OUTPUT = TSD_CHANGE_MACHINE_SID_OUTPUT

type _SD_CHANGE_MACHINE_SID_OUTPUT = T_SD_CHANGE_MACHINE_SID_OUTPUT

type TPSD_CHANGE_MACHINE_SID_OUTPUT = uintptr

type PSD_CHANGE_MACHINE_SID_OUTPUT = TPSD_CHANGE_MACHINE_SID_OUTPUT

type TEXTENDED_ENCRYPTED_DATA_INFO = struct {
	FExtendedCode TULONG
	FLength       TULONG
	FFlags        TULONG
	FReserved     TULONG
}

type EXTENDED_ENCRYPTED_DATA_INFO = TEXTENDED_ENCRYPTED_DATA_INFO

type T_EXTENDED_ENCRYPTED_DATA_INFO = TEXTENDED_ENCRYPTED_DATA_INFO

type _EXTENDED_ENCRYPTED_DATA_INFO = T_EXTENDED_ENCRYPTED_DATA_INFO

type TPEXTENDED_ENCRYPTED_DATA_INFO = uintptr

type PEXTENDED_ENCRYPTED_DATA_INFO = TPEXTENDED_ENCRYPTED_DATA_INFO

type TLOOKUP_STREAM_FROM_CLUSTER_INPUT = struct {
	F__ccgo_align     [0]uint32
	FFlags            TDWORD
	FNumberOfClusters TDWORD
	FCluster          [1]TLARGE_INTEGER
}

type LOOKUP_STREAM_FROM_CLUSTER_INPUT = TLOOKUP_STREAM_FROM_CLUSTER_INPUT

type T_LOOKUP_STREAM_FROM_CLUSTER_INPUT = TLOOKUP_STREAM_FROM_CLUSTER_INPUT

type _LOOKUP_STREAM_FROM_CLUSTER_INPUT = T_LOOKUP_STREAM_FROM_CLUSTER_INPUT

type TPLOOKUP_STREAM_FROM_CLUSTER_INPUT = uintptr

type PLOOKUP_STREAM_FROM_CLUSTER_INPUT = TPLOOKUP_STREAM_FROM_CLUSTER_INPUT

type TLOOKUP_STREAM_FROM_CLUSTER_OUTPUT = struct {
	FOffset             TDWORD
	FNumberOfMatches    TDWORD
	FBufferSizeRequired TDWORD
}

type LOOKUP_STREAM_FROM_CLUSTER_OUTPUT = TLOOKUP_STREAM_FROM_CLUSTER_OUTPUT

type T_LOOKUP_STREAM_FROM_CLUSTER_OUTPUT = TLOOKUP_STREAM_FROM_CLUSTER_OUTPUT

type _LOOKUP_STREAM_FROM_CLUSTER_OUTPUT = T_LOOKUP_STREAM_FROM_CLUSTER_OUTPUT

type TPLOOKUP_STREAM_FROM_CLUSTER_OUTPUT = uintptr

type PLOOKUP_STREAM_FROM_CLUSTER_OUTPUT = TPLOOKUP_STREAM_FROM_CLUSTER_OUTPUT

type TLOOKUP_STREAM_FROM_CLUSTER_ENTRY = struct {
	F__ccgo_align [0]uint32
	FOffsetToNext TDWORD
	FFlags        TDWORD
	FReserved     TLARGE_INTEGER
	FCluster      TLARGE_INTEGER
	FFileName     [1]TWCHAR
	F__ccgo_pad5  [6]byte
}

type LOOKUP_STREAM_FROM_CLUSTER_ENTRY = TLOOKUP_STREAM_FROM_CLUSTER_ENTRY

type T_LOOKUP_STREAM_FROM_CLUSTER_ENTRY = TLOOKUP_STREAM_FROM_CLUSTER_ENTRY

type _LOOKUP_STREAM_FROM_CLUSTER_ENTRY = T_LOOKUP_STREAM_FROM_CLUSTER_ENTRY

type TPLOOKUP_STREAM_FROM_CLUSTER_ENTRY = uintptr

type PLOOKUP_STREAM_FROM_CLUSTER_ENTRY = TPLOOKUP_STREAM_FROM_CLUSTER_ENTRY

type TFILE_TYPE_NOTIFICATION_INPUT = struct {
	FFlags          TULONG
	FNumFileTypeIDs TULONG
	FFileTypeID     [1]TGUID
}

type FILE_TYPE_NOTIFICATION_INPUT = TFILE_TYPE_NOTIFICATION_INPUT

type T_FILE_TYPE_NOTIFICATION_INPUT = TFILE_TYPE_NOTIFICATION_INPUT

type _FILE_TYPE_NOTIFICATION_INPUT = T_FILE_TYPE_NOTIFICATION_INPUT

type TPFILE_TYPE_NOTIFICATION_INPUT = uintptr

type PFILE_TYPE_NOTIFICATION_INPUT = TPFILE_TYPE_NOTIFICATION_INPUT

type TCSV_NAMESPACE_INFO = struct {
	F__ccgo_align   [0]uint32
	FVersion        TULONG
	FDeviceNumber   TULONG
	FStartingOffset TLARGE_INTEGER
	FSectorSize     TULONG
	F__ccgo_pad4    [4]byte
}

type CSV_NAMESPACE_INFO = TCSV_NAMESPACE_INFO

type T_CSV_NAMESPACE_INFO = TCSV_NAMESPACE_INFO

type _CSV_NAMESPACE_INFO = T_CSV_NAMESPACE_INFO

type TPCSV_NAMESPACE_INFO = uintptr

type PCSV_NAMESPACE_INFO = TPCSV_NAMESPACE_INFO

type TDISK_EXTENT = struct {
	F__ccgo_align   [0]uint32
	FDiskNumber     TDWORD
	F__ccgo_align1  [4]byte
	FStartingOffset TLARGE_INTEGER
	FExtentLength   TLARGE_INTEGER
}

type DISK_EXTENT = TDISK_EXTENT

type T_DISK_EXTENT = TDISK_EXTENT

type _DISK_EXTENT = T_DISK_EXTENT

type TPDISK_EXTENT = uintptr

type PDISK_EXTENT = TPDISK_EXTENT

type TVOLUME_DISK_EXTENTS = struct {
	F__ccgo_align        [0]uint32
	FNumberOfDiskExtents TDWORD
	F__ccgo_align1       [4]byte
	FExtents             [1]TDISK_EXTENT
}

type VOLUME_DISK_EXTENTS = TVOLUME_DISK_EXTENTS

type T_VOLUME_DISK_EXTENTS = TVOLUME_DISK_EXTENTS

type _VOLUME_DISK_EXTENTS = T_VOLUME_DISK_EXTENTS

type TPVOLUME_DISK_EXTENTS = uintptr

type PVOLUME_DISK_EXTENTS = TPVOLUME_DISK_EXTENTS

type TWOF_EXTERNAL_INFO = struct {
	FVersion  TDWORD
	FProvider TDWORD
}

type WOF_EXTERNAL_INFO = TWOF_EXTERNAL_INFO

type T_WOF_EXTERNAL_INFO = TWOF_EXTERNAL_INFO

type _WOF_EXTERNAL_INFO = T_WOF_EXTERNAL_INFO

type TPWOF_EXTERNAL_INFO = uintptr

type PWOF_EXTERNAL_INFO = TPWOF_EXTERNAL_INFO

type TFILE_PROVIDER_EXTERNAL_INFO_V0 = struct {
	FVersion   TDWORD
	FAlgorithm TDWORD
}

type FILE_PROVIDER_EXTERNAL_INFO_V0 = TFILE_PROVIDER_EXTERNAL_INFO_V0

type T_FILE_PROVIDER_EXTERNAL_INFO_V0 = TFILE_PROVIDER_EXTERNAL_INFO_V0

type _FILE_PROVIDER_EXTERNAL_INFO_V0 = T_FILE_PROVIDER_EXTERNAL_INFO_V0

type TPFILE_PROVIDER_EXTERNAL_INFO_V0 = uintptr

type PFILE_PROVIDER_EXTERNAL_INFO_V0 = TPFILE_PROVIDER_EXTERNAL_INFO_V0

type TFILE_PROVIDER_EXTERNAL_INFO_V1 = struct {
	FVersion   TDWORD
	FAlgorithm TDWORD
	FFlags     TDWORD
}

type FILE_PROVIDER_EXTERNAL_INFO_V1 = TFILE_PROVIDER_EXTERNAL_INFO_V1

type T_FILE_PROVIDER_EXTERNAL_INFO_V1 = TFILE_PROVIDER_EXTERNAL_INFO_V1

type _FILE_PROVIDER_EXTERNAL_INFO_V1 = T_FILE_PROVIDER_EXTERNAL_INFO_V1

type TPFILE_PROVIDER_EXTERNAL_INFO_V1 = uintptr

type PFILE_PROVIDER_EXTERNAL_INFO_V1 = TPFILE_PROVIDER_EXTERNAL_INFO_V1

type TUWORD = uint16

type UWORD = TUWORD

type TSCARD_IO_REQUEST = struct {
	FdwProtocol  TDWORD
	FcbPciLength TDWORD
}

type SCARD_IO_REQUEST = TSCARD_IO_REQUEST

type T_SCARD_IO_REQUEST = TSCARD_IO_REQUEST

type _SCARD_IO_REQUEST = T_SCARD_IO_REQUEST

type TPSCARD_IO_REQUEST = uintptr

type PSCARD_IO_REQUEST = TPSCARD_IO_REQUEST

type TLPSCARD_IO_REQUEST = uintptr

type LPSCARD_IO_REQUEST = TLPSCARD_IO_REQUEST

type TLPCSCARD_IO_REQUEST = uintptr

type LPCSCARD_IO_REQUEST = TLPCSCARD_IO_REQUEST

type TSCARD_T0_COMMAND = struct {
	FbCla TBYTE
	FbIns TBYTE
	FbP1  TBYTE
	FbP2  TBYTE
	FbP3  TBYTE
}

type SCARD_T0_COMMAND = TSCARD_T0_COMMAND

type TLPSCARD_T0_COMMAND = uintptr

type LPSCARD_T0_COMMAND = TLPSCARD_T0_COMMAND

type TSCARD_T0_REQUEST = struct {
	FioRequest  TSCARD_IO_REQUEST
	FbSw1       TBYTE
	FbSw2       TBYTE
	F__ccgo3_10 struct {
		FrgbHeader [0][5]TBYTE
		FCmdBytes  TSCARD_T0_COMMAND
	}
}

type SCARD_T0_REQUEST = TSCARD_T0_REQUEST

type TPSCARD_T0_REQUEST = uintptr

type PSCARD_T0_REQUEST = TPSCARD_T0_REQUEST

type TLPSCARD_T0_REQUEST = uintptr

type LPSCARD_T0_REQUEST = TLPSCARD_T0_REQUEST

type TSCARD_T1_REQUEST = struct {
	FioRequest TSCARD_IO_REQUEST
}

type SCARD_T1_REQUEST = TSCARD_T1_REQUEST

type TPSCARD_T1_REQUEST = uintptr

type PSCARD_T1_REQUEST = TPSCARD_T1_REQUEST

type TLPSCARD_T1_REQUEST = uintptr

type LPSCARD_T1_REQUEST = TLPSCARD_T1_REQUEST

type TLPCBYTE = uintptr

type LPCBYTE = TLPCBYTE

type TSCARDCONTEXT = uint32

type SCARDCONTEXT = TSCARDCONTEXT

type TPSCARDCONTEXT = uintptr

type PSCARDCONTEXT = TPSCARDCONTEXT

type TLPSCARDCONTEXT = uintptr

type LPSCARDCONTEXT = TLPSCARDCONTEXT

type TSCARDHANDLE = uint32

type SCARDHANDLE = TSCARDHANDLE

type TPSCARDHANDLE = uintptr

type PSCARDHANDLE = TPSCARDHANDLE

type TLPSCARDHANDLE = uintptr

type LPSCARDHANDLE = TLPSCARDHANDLE

type TSCARD_READERSTATEA = struct {
	FszReader       TLPCSTR
	FpvUserData     TLPVOID
	FdwCurrentState TDWORD
	FdwEventState   TDWORD
	FcbAtr          TDWORD
	FrgbAtr         [36]TBYTE
}

type SCARD_READERSTATEA = TSCARD_READERSTATEA

type TPSCARD_READERSTATEA = uintptr

type PSCARD_READERSTATEA = TPSCARD_READERSTATEA

type TLPSCARD_READERSTATEA = uintptr

type LPSCARD_READERSTATEA = TLPSCARD_READERSTATEA

type TSCARD_READERSTATEW = struct {
	FszReader       TLPCWSTR
	FpvUserData     TLPVOID
	FdwCurrentState TDWORD
	FdwEventState   TDWORD
	FcbAtr          TDWORD
	FrgbAtr         [36]TBYTE
}

type SCARD_READERSTATEW = TSCARD_READERSTATEW

type TPSCARD_READERSTATEW = uintptr

type PSCARD_READERSTATEW = TPSCARD_READERSTATEW

type TLPSCARD_READERSTATEW = uintptr

type LPSCARD_READERSTATEW = TLPSCARD_READERSTATEW

type TSCARD_READERSTATE = struct {
	FszReader       TLPCSTR
	FpvUserData     TLPVOID
	FdwCurrentState TDWORD
	FdwEventState   TDWORD
	FcbAtr          TDWORD
	FrgbAtr         [36]TBYTE
}

type SCARD_READERSTATE = TSCARD_READERSTATE

type TPSCARD_READERSTATE = uintptr

type PSCARD_READERSTATE = TPSCARD_READERSTATE

type TLPSCARD_READERSTATE = uintptr

type LPSCARD_READERSTATE = TLPSCARD_READERSTATE

type TSCARD_ATRMASK = struct {
	FcbAtr   TDWORD
	FrgbAtr  [36]TBYTE
	FrgbMask [36]TBYTE
}

type SCARD_ATRMASK = TSCARD_ATRMASK

type T_SCARD_ATRMASK = TSCARD_ATRMASK

type _SCARD_ATRMASK = T_SCARD_ATRMASK

type TPSCARD_ATRMASK = uintptr

type PSCARD_ATRMASK = TPSCARD_ATRMASK

type TLPSCARD_ATRMASK = uintptr

type LPSCARD_ATRMASK = TLPSCARD_ATRMASK

type TLPOCNCONNPROCA = uintptr

type LPOCNCONNPROCA = TLPOCNCONNPROCA

type TLPOCNCONNPROCW = uintptr

type LPOCNCONNPROCW = TLPOCNCONNPROCW

type TLPOCNCHKPROC = uintptr

type LPOCNCHKPROC = TLPOCNCHKPROC

type TLPOCNDSCPROC = uintptr

type LPOCNDSCPROC = TLPOCNDSCPROC

type TOPENCARD_SEARCH_CRITERIAA = struct {
	FdwStructSize         TDWORD
	FlpstrGroupNames      TLPSTR
	FnMaxGroupNames       TDWORD
	FrgguidInterfaces     TLPCGUID
	FcguidInterfaces      TDWORD
	FlpstrCardNames       TLPSTR
	FnMaxCardNames        TDWORD
	FlpfnCheck            TLPOCNCHKPROC
	FlpfnConnect          TLPOCNCONNPROCA
	FlpfnDisconnect       TLPOCNDSCPROC
	FpvUserData           TLPVOID
	FdwShareMode          TDWORD
	FdwPreferredProtocols TDWORD
}

type OPENCARD_SEARCH_CRITERIAA = TOPENCARD_SEARCH_CRITERIAA

type TPOPENCARD_SEARCH_CRITERIAA = uintptr

type POPENCARD_SEARCH_CRITERIAA = TPOPENCARD_SEARCH_CRITERIAA

type TLPOPENCARD_SEARCH_CRITERIAA = uintptr

type LPOPENCARD_SEARCH_CRITERIAA = TLPOPENCARD_SEARCH_CRITERIAA

type TOPENCARD_SEARCH_CRITERIAW = struct {
	FdwStructSize         TDWORD
	FlpstrGroupNames      TLPWSTR
	FnMaxGroupNames       TDWORD
	FrgguidInterfaces     TLPCGUID
	FcguidInterfaces      TDWORD
	FlpstrCardNames       TLPWSTR
	FnMaxCardNames        TDWORD
	FlpfnCheck            TLPOCNCHKPROC
	FlpfnConnect          TLPOCNCONNPROCW
	FlpfnDisconnect       TLPOCNDSCPROC
	FpvUserData           TLPVOID
	FdwShareMode          TDWORD
	FdwPreferredProtocols TDWORD
}

type OPENCARD_SEARCH_CRITERIAW = TOPENCARD_SEARCH_CRITERIAW

type TPOPENCARD_SEARCH_CRITERIAW = uintptr

type POPENCARD_SEARCH_CRITERIAW = TPOPENCARD_SEARCH_CRITERIAW

type TLPOPENCARD_SEARCH_CRITERIAW = uintptr

type LPOPENCARD_SEARCH_CRITERIAW = TLPOPENCARD_SEARCH_CRITERIAW

type TOPENCARD_SEARCH_CRITERIA = struct {
	FdwStructSize         TDWORD
	FlpstrGroupNames      TLPSTR
	FnMaxGroupNames       TDWORD
	FrgguidInterfaces     TLPCGUID
	FcguidInterfaces      TDWORD
	FlpstrCardNames       TLPSTR
	FnMaxCardNames        TDWORD
	FlpfnCheck            TLPOCNCHKPROC
	FlpfnConnect          TLPOCNCONNPROCA
	FlpfnDisconnect       TLPOCNDSCPROC
	FpvUserData           TLPVOID
	FdwShareMode          TDWORD
	FdwPreferredProtocols TDWORD
}

type OPENCARD_SEARCH_CRITERIA = TOPENCARD_SEARCH_CRITERIA

type TPOPENCARD_SEARCH_CRITERIA = uintptr

type POPENCARD_SEARCH_CRITERIA = TPOPENCARD_SEARCH_CRITERIA

type TLPOPENCARD_SEARCH_CRITERIA = uintptr

type LPOPENCARD_SEARCH_CRITERIA = TLPOPENCARD_SEARCH_CRITERIA

type TOPENCARDNAME_EXA = struct {
	FdwStructSize            TDWORD
	FhSCardContext           TSCARDCONTEXT
	FhwndOwner               THWND
	FdwFlags                 TDWORD
	FlpstrTitle              TLPCSTR
	FlpstrSearchDesc         TLPCSTR
	FhIcon                   THICON
	FpOpenCardSearchCriteria TPOPENCARD_SEARCH_CRITERIAA
	FlpfnConnect             TLPOCNCONNPROCA
	FpvUserData              TLPVOID
	FdwShareMode             TDWORD
	FdwPreferredProtocols    TDWORD
	FlpstrRdr                TLPSTR
	FnMaxRdr                 TDWORD
	FlpstrCard               TLPSTR
	FnMaxCard                TDWORD
	FdwActiveProtocol        TDWORD
	FhCardHandle             TSCARDHANDLE
}

type OPENCARDNAME_EXA = TOPENCARDNAME_EXA

type TPOPENCARDNAME_EXA = uintptr

type POPENCARDNAME_EXA = TPOPENCARDNAME_EXA

type TLPOPENCARDNAME_EXA = uintptr

type LPOPENCARDNAME_EXA = TLPOPENCARDNAME_EXA

type TOPENCARDNAME_EXW = struct {
	FdwStructSize            TDWORD
	FhSCardContext           TSCARDCONTEXT
	FhwndOwner               THWND
	FdwFlags                 TDWORD
	FlpstrTitle              TLPCWSTR
	FlpstrSearchDesc         TLPCWSTR
	FhIcon                   THICON
	FpOpenCardSearchCriteria TPOPENCARD_SEARCH_CRITERIAW
	FlpfnConnect             TLPOCNCONNPROCW
	FpvUserData              TLPVOID
	FdwShareMode             TDWORD
	FdwPreferredProtocols    TDWORD
	FlpstrRdr                TLPWSTR
	FnMaxRdr                 TDWORD
	FlpstrCard               TLPWSTR
	FnMaxCard                TDWORD
	FdwActiveProtocol        TDWORD
	FhCardHandle             TSCARDHANDLE
}

type OPENCARDNAME_EXW = TOPENCARDNAME_EXW

type TPOPENCARDNAME_EXW = uintptr

type POPENCARDNAME_EXW = TPOPENCARDNAME_EXW

type TLPOPENCARDNAME_EXW = uintptr

type LPOPENCARDNAME_EXW = TLPOPENCARDNAME_EXW

type TOPENCARDNAME_EX = struct {
	FdwStructSize            TDWORD
	FhSCardContext           TSCARDCONTEXT
	FhwndOwner               THWND
	FdwFlags                 TDWORD
	FlpstrTitle              TLPCSTR
	FlpstrSearchDesc         TLPCSTR
	FhIcon                   THICON
	FpOpenCardSearchCriteria TPOPENCARD_SEARCH_CRITERIAA
	FlpfnConnect             TLPOCNCONNPROCA
	FpvUserData              TLPVOID
	FdwShareMode             TDWORD
	FdwPreferredProtocols    TDWORD
	FlpstrRdr                TLPSTR
	FnMaxRdr                 TDWORD
	FlpstrCard               TLPSTR
	FnMaxCard                TDWORD
	FdwActiveProtocol        TDWORD
	FhCardHandle             TSCARDHANDLE
}

type OPENCARDNAME_EX = TOPENCARDNAME_EX

type TPOPENCARDNAME_EX = uintptr

type POPENCARDNAME_EX = TPOPENCARDNAME_EX

type TLPOPENCARDNAME_EX = uintptr

type LPOPENCARDNAME_EX = TLPOPENCARDNAME_EX

type TOPENCARDNAMEA = struct {
	FdwStructSize         TDWORD
	FhwndOwner            THWND
	FhSCardContext        TSCARDCONTEXT
	FlpstrGroupNames      TLPSTR
	FnMaxGroupNames       TDWORD
	FlpstrCardNames       TLPSTR
	FnMaxCardNames        TDWORD
	FrgguidInterfaces     TLPCGUID
	FcguidInterfaces      TDWORD
	FlpstrRdr             TLPSTR
	FnMaxRdr              TDWORD
	FlpstrCard            TLPSTR
	FnMaxCard             TDWORD
	FlpstrTitle           TLPCSTR
	FdwFlags              TDWORD
	FpvUserData           TLPVOID
	FdwShareMode          TDWORD
	FdwPreferredProtocols TDWORD
	FdwActiveProtocol     TDWORD
	FlpfnConnect          TLPOCNCONNPROCA
	FlpfnCheck            TLPOCNCHKPROC
	FlpfnDisconnect       TLPOCNDSCPROC
	FhCardHandle          TSCARDHANDLE
}

type OPENCARDNAMEA = TOPENCARDNAMEA

type TPOPENCARDNAMEA = uintptr

type POPENCARDNAMEA = TPOPENCARDNAMEA

type TLPOPENCARDNAMEA = uintptr

type LPOPENCARDNAMEA = TLPOPENCARDNAMEA

type TOPENCARDNAMEW = struct {
	FdwStructSize         TDWORD
	FhwndOwner            THWND
	FhSCardContext        TSCARDCONTEXT
	FlpstrGroupNames      TLPWSTR
	FnMaxGroupNames       TDWORD
	FlpstrCardNames       TLPWSTR
	FnMaxCardNames        TDWORD
	FrgguidInterfaces     TLPCGUID
	FcguidInterfaces      TDWORD
	FlpstrRdr             TLPWSTR
	FnMaxRdr              TDWORD
	FlpstrCard            TLPWSTR
	FnMaxCard             TDWORD
	FlpstrTitle           TLPCWSTR
	FdwFlags              TDWORD
	FpvUserData           TLPVOID
	FdwShareMode          TDWORD
	FdwPreferredProtocols TDWORD
	FdwActiveProtocol     TDWORD
	FlpfnConnect          TLPOCNCONNPROCW
	FlpfnCheck            TLPOCNCHKPROC
	FlpfnDisconnect       TLPOCNDSCPROC
	FhCardHandle          TSCARDHANDLE
}

type OPENCARDNAMEW = TOPENCARDNAMEW

type TPOPENCARDNAMEW = uintptr

type POPENCARDNAMEW = TPOPENCARDNAMEW

type TLPOPENCARDNAMEW = uintptr

type LPOPENCARDNAMEW = TLPOPENCARDNAMEW

type TOPENCARDNAME = struct {
	FdwStructSize         TDWORD
	FhwndOwner            THWND
	FhSCardContext        TSCARDCONTEXT
	FlpstrGroupNames      TLPSTR
	FnMaxGroupNames       TDWORD
	FlpstrCardNames       TLPSTR
	FnMaxCardNames        TDWORD
	FrgguidInterfaces     TLPCGUID
	FcguidInterfaces      TDWORD
	FlpstrRdr             TLPSTR
	FnMaxRdr              TDWORD
	FlpstrCard            TLPSTR
	FnMaxCard             TDWORD
	FlpstrTitle           TLPCSTR
	FdwFlags              TDWORD
	FpvUserData           TLPVOID
	FdwShareMode          TDWORD
	FdwPreferredProtocols TDWORD
	FdwActiveProtocol     TDWORD
	FlpfnConnect          TLPOCNCONNPROCA
	FlpfnCheck            TLPOCNCHKPROC
	FlpfnDisconnect       TLPOCNDSCPROC
	FhCardHandle          TSCARDHANDLE
}

type OPENCARDNAME = TOPENCARDNAME

type TPOPENCARDNAME = uintptr

type POPENCARDNAME = TPOPENCARDNAME

type TLPOPENCARDNAME = uintptr

type LPOPENCARDNAME = TLPOPENCARDNAME

type T_PROPSHEETPAGEA = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKA
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCSTR
	FpszHeaderSubTitle TLPCSTR
	FhActCtx           THANDLE
}

type _PROPSHEETPAGEA = T_PROPSHEETPAGEA

type T_PROPSHEETPAGEW = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCWSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCWSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCWSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKW
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCWSTR
	FpszHeaderSubTitle TLPCWSTR
	FhActCtx           THANDLE
}

type _PROPSHEETPAGEW = T_PROPSHEETPAGEW

type THPROPSHEETPAGE = uintptr

type HPROPSHEETPAGE = THPROPSHEETPAGE

type TLPFNPSPCALLBACKA = uintptr

type LPFNPSPCALLBACKA = TLPFNPSPCALLBACKA

type TLPFNPSPCALLBACKW = uintptr

type LPFNPSPCALLBACKW = TLPFNPSPCALLBACKW

type TPROPSHEETPAGE_RESOURCE = uintptr

type PROPSHEETPAGE_RESOURCE = TPROPSHEETPAGE_RESOURCE

type TPROPSHEETPAGEA_V1 = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCSTR
		FhIcon   THICON
	}
	FpszTitle    TLPCSTR
	FpfnDlgProc  TDLGPROC
	FlParam      TLPARAM
	FpfnCallback TLPFNPSPCALLBACKA
	FpcRefParent uintptr
}

type PROPSHEETPAGEA_V1 = TPROPSHEETPAGEA_V1

type T_PROPSHEETPAGEA_V1 = TPROPSHEETPAGEA_V1

type _PROPSHEETPAGEA_V1 = T_PROPSHEETPAGEA_V1

type TLPPROPSHEETPAGEA_V1 = uintptr

type LPPROPSHEETPAGEA_V1 = TLPPROPSHEETPAGEA_V1

type TLPCPROPSHEETPAGEA_V1 = uintptr

type LPCPROPSHEETPAGEA_V1 = TLPCPROPSHEETPAGEA_V1

type TPROPSHEETPAGEA_V2 = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKA
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCSTR
	FpszHeaderSubTitle TLPCSTR
}

type PROPSHEETPAGEA_V2 = TPROPSHEETPAGEA_V2

type T_PROPSHEETPAGEA_V2 = TPROPSHEETPAGEA_V2

type _PROPSHEETPAGEA_V2 = T_PROPSHEETPAGEA_V2

type TLPPROPSHEETPAGEA_V2 = uintptr

type LPPROPSHEETPAGEA_V2 = TLPPROPSHEETPAGEA_V2

type TLPCPROPSHEETPAGEA_V2 = uintptr

type LPCPROPSHEETPAGEA_V2 = TLPCPROPSHEETPAGEA_V2

type TPROPSHEETPAGEA_V3 = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKA
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCSTR
	FpszHeaderSubTitle TLPCSTR
	FhActCtx           THANDLE
}

type PROPSHEETPAGEA_V3 = TPROPSHEETPAGEA_V3

type TLPPROPSHEETPAGEA_V3 = uintptr

type LPPROPSHEETPAGEA_V3 = TLPPROPSHEETPAGEA_V3

type TLPCPROPSHEETPAGEA_V3 = uintptr

type LPCPROPSHEETPAGEA_V3 = TLPCPROPSHEETPAGEA_V3

type TPROPSHEETPAGEW_V1 = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCWSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCWSTR
		FhIcon   THICON
	}
	FpszTitle    TLPCWSTR
	FpfnDlgProc  TDLGPROC
	FlParam      TLPARAM
	FpfnCallback TLPFNPSPCALLBACKW
	FpcRefParent uintptr
}

type PROPSHEETPAGEW_V1 = TPROPSHEETPAGEW_V1

type T_PROPSHEETPAGEW_V1 = TPROPSHEETPAGEW_V1

type _PROPSHEETPAGEW_V1 = T_PROPSHEETPAGEW_V1

type TLPPROPSHEETPAGEW_V1 = uintptr

type LPPROPSHEETPAGEW_V1 = TLPPROPSHEETPAGEW_V1

type TLPCPROPSHEETPAGEW_V1 = uintptr

type LPCPROPSHEETPAGEW_V1 = TLPCPROPSHEETPAGEW_V1

type TPROPSHEETPAGEW_V2 = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCWSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCWSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCWSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKW
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCWSTR
	FpszHeaderSubTitle TLPCWSTR
}

type PROPSHEETPAGEW_V2 = TPROPSHEETPAGEW_V2

type T_PROPSHEETPAGEW_V2 = TPROPSHEETPAGEW_V2

type _PROPSHEETPAGEW_V2 = T_PROPSHEETPAGEW_V2

type TLPPROPSHEETPAGEW_V2 = uintptr

type LPPROPSHEETPAGEW_V2 = TLPPROPSHEETPAGEW_V2

type TLPCPROPSHEETPAGEW_V2 = uintptr

type LPCPROPSHEETPAGEW_V2 = TLPCPROPSHEETPAGEW_V2

type TPROPSHEETPAGEW_V3 = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCWSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCWSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCWSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKW
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCWSTR
	FpszHeaderSubTitle TLPCWSTR
	FhActCtx           THANDLE
}

type PROPSHEETPAGEW_V3 = TPROPSHEETPAGEW_V3

type TLPPROPSHEETPAGEW_V3 = uintptr

type LPPROPSHEETPAGEW_V3 = TLPPROPSHEETPAGEW_V3

type TLPCPROPSHEETPAGEW_V3 = uintptr

type LPCPROPSHEETPAGEW_V3 = TLPCPROPSHEETPAGEW_V3

type TPROPSHEETPAGEA_LATEST = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKA
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCSTR
	FpszHeaderSubTitle TLPCSTR
	FhActCtx           THANDLE
}

type PROPSHEETPAGEA_LATEST = TPROPSHEETPAGEA_LATEST

type TPROPSHEETPAGEW_LATEST = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCWSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCWSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCWSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKW
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCWSTR
	FpszHeaderSubTitle TLPCWSTR
	FhActCtx           THANDLE
}

type PROPSHEETPAGEW_LATEST = TPROPSHEETPAGEW_LATEST

type TLPPROPSHEETPAGEA_LATEST = uintptr

type LPPROPSHEETPAGEA_LATEST = TLPPROPSHEETPAGEA_LATEST

type TLPPROPSHEETPAGEW_LATEST = uintptr

type LPPROPSHEETPAGEW_LATEST = TLPPROPSHEETPAGEW_LATEST

type TLPCPROPSHEETPAGEA_LATEST = uintptr

type LPCPROPSHEETPAGEA_LATEST = TLPCPROPSHEETPAGEA_LATEST

type TLPCPROPSHEETPAGEW_LATEST = uintptr

type LPCPROPSHEETPAGEW_LATEST = TLPCPROPSHEETPAGEW_LATEST

type TPROPSHEETPAGEA = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKA
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCSTR
	FpszHeaderSubTitle TLPCSTR
	FhActCtx           THANDLE
}

type PROPSHEETPAGEA = TPROPSHEETPAGEA

type TPROPSHEETPAGEW = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhInstance  THINSTANCE
	F__ccgo3_12 struct {
		FpResource   [0]TPROPSHEETPAGE_RESOURCE
		FpszTemplate TLPCWSTR
	}
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCWSTR
		FhIcon   THICON
	}
	FpszTitle          TLPCWSTR
	FpfnDlgProc        TDLGPROC
	FlParam            TLPARAM
	FpfnCallback       TLPFNPSPCALLBACKW
	FpcRefParent       uintptr
	FpszHeaderTitle    TLPCWSTR
	FpszHeaderSubTitle TLPCWSTR
	FhActCtx           THANDLE
}

type PROPSHEETPAGEW = TPROPSHEETPAGEW

type TLPPROPSHEETPAGEA = uintptr

type LPPROPSHEETPAGEA = TLPPROPSHEETPAGEA

type TLPPROPSHEETPAGEW = uintptr

type LPPROPSHEETPAGEW = TLPPROPSHEETPAGEW

type TLPCPROPSHEETPAGEA = uintptr

type LPCPROPSHEETPAGEA = TLPCPROPSHEETPAGEA

type TLPCPROPSHEETPAGEW = uintptr

type LPCPROPSHEETPAGEW = TLPCPROPSHEETPAGEW

type TPFNPROPSHEETCALLBACK = uintptr

type PFNPROPSHEETCALLBACK = TPFNPROPSHEETCALLBACK

type TPROPSHEETHEADERA = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhwndParent THWND
	FhInstance  THINSTANCE
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCSTR
		FhIcon   THICON
	}
	FpszCaption TLPCSTR
	FnPages     TUINT
	F__ccgo7_28 struct {
		FpStartPage [0]TLPCSTR
		FnStartPage TUINT
	}
	F__ccgo8_32 struct {
		Fphpage [0]uintptr
		Fppsp   TLPCPROPSHEETPAGEA
	}
	FpfnCallback TPFNPROPSHEETCALLBACK
	F__ccgo10_40 struct {
		FpszbmWatermark [0]TLPCSTR
		FhbmWatermark   THBITMAP
	}
	FhplWatermark THPALETTE
	F__ccgo12_48  struct {
		FpszbmHeader [0]TLPCSTR
		FhbmHeader   THBITMAP
	}
}

type PROPSHEETHEADERA = TPROPSHEETHEADERA

type T_PROPSHEETHEADERA = TPROPSHEETHEADERA

type _PROPSHEETHEADERA = T_PROPSHEETHEADERA

type TLPPROPSHEETHEADERA = uintptr

type LPPROPSHEETHEADERA = TLPPROPSHEETHEADERA

type TLPCPROPSHEETHEADERA = uintptr

type LPCPROPSHEETHEADERA = TLPCPROPSHEETHEADERA

type TPROPSHEETHEADERW = struct {
	FdwSize     TDWORD
	FdwFlags    TDWORD
	FhwndParent THWND
	FhInstance  THINSTANCE
	F__ccgo4_16 struct {
		FpszIcon [0]TLPCWSTR
		FhIcon   THICON
	}
	FpszCaption TLPCWSTR
	FnPages     TUINT
	F__ccgo7_28 struct {
		FpStartPage [0]TLPCWSTR
		FnStartPage TUINT
	}
	F__ccgo8_32 struct {
		Fphpage [0]uintptr
		Fppsp   TLPCPROPSHEETPAGEW
	}
	FpfnCallback TPFNPROPSHEETCALLBACK
	F__ccgo10_40 struct {
		FpszbmWatermark [0]TLPCWSTR
		FhbmWatermark   THBITMAP
	}
	FhplWatermark THPALETTE
	F__ccgo12_48  struct {
		FpszbmHeader [0]TLPCWSTR
		FhbmHeader   THBITMAP
	}
}

type PROPSHEETHEADERW = TPROPSHEETHEADERW

type T_PROPSHEETHEADERW = TPROPSHEETHEADERW

type _PROPSHEETHEADERW = T_PROPSHEETHEADERW

type TLPPROPSHEETHEADERW = uintptr

type LPPROPSHEETHEADERW = TLPPROPSHEETHEADERW

type TLPCPROPSHEETHEADERW = uintptr

type LPCPROPSHEETHEADERW = TLPCPROPSHEETHEADERW

type TLPFNADDPROPSHEETPAGE = uintptr

type LPFNADDPROPSHEETPAGE = TLPFNADDPROPSHEETPAGE

type TLPFNADDPROPSHEETPAGES = uintptr

type LPFNADDPROPSHEETPAGES = TLPFNADDPROPSHEETPAGES

type TPSHNOTIFY = struct {
	Fhdr    TNMHDR
	FlParam TLPARAM
}

type PSHNOTIFY = TPSHNOTIFY

type T_PSHNOTIFY = TPSHNOTIFY

type _PSHNOTIFY = T_PSHNOTIFY

type TLPPSHNOTIFY = uintptr

type LPPSHNOTIFY = TLPPSHNOTIFY

type TPRINTER_INFO_1A = struct {
	FFlags        TDWORD
	FpDescription TLPSTR
	FpName        TLPSTR
	FpComment     TLPSTR
}

type PRINTER_INFO_1A = TPRINTER_INFO_1A

type T_PRINTER_INFO_1A = TPRINTER_INFO_1A

type _PRINTER_INFO_1A = T_PRINTER_INFO_1A

type TPPRINTER_INFO_1A = uintptr

type PPRINTER_INFO_1A = TPPRINTER_INFO_1A

type TLPPRINTER_INFO_1A = uintptr

type LPPRINTER_INFO_1A = TLPPRINTER_INFO_1A

type TPRINTER_INFO_1W = struct {
	FFlags        TDWORD
	FpDescription TLPWSTR
	FpName        TLPWSTR
	FpComment     TLPWSTR
}

type PRINTER_INFO_1W = TPRINTER_INFO_1W

type T_PRINTER_INFO_1W = TPRINTER_INFO_1W

type _PRINTER_INFO_1W = T_PRINTER_INFO_1W

type TPPRINTER_INFO_1W = uintptr

type PPRINTER_INFO_1W = TPPRINTER_INFO_1W

type TLPPRINTER_INFO_1W = uintptr

type LPPRINTER_INFO_1W = TLPPRINTER_INFO_1W

type TPRINTER_INFO_1 = struct {
	FFlags        TDWORD
	FpDescription TLPSTR
	FpName        TLPSTR
	FpComment     TLPSTR
}

type PRINTER_INFO_1 = TPRINTER_INFO_1

type TPPRINTER_INFO_1 = uintptr

type PPRINTER_INFO_1 = TPPRINTER_INFO_1

type TLPPRINTER_INFO_1 = uintptr

type LPPRINTER_INFO_1 = TLPPRINTER_INFO_1

type TPRINTER_INFO_2A = struct {
	FpServerName         TLPSTR
	FpPrinterName        TLPSTR
	FpShareName          TLPSTR
	FpPortName           TLPSTR
	FpDriverName         TLPSTR
	FpComment            TLPSTR
	FpLocation           TLPSTR
	FpDevMode            TLPDEVMODEA
	FpSepFile            TLPSTR
	FpPrintProcessor     TLPSTR
	FpDatatype           TLPSTR
	FpParameters         TLPSTR
	FpSecurityDescriptor TPSECURITY_DESCRIPTOR
	FAttributes          TDWORD
	FPriority            TDWORD
	FDefaultPriority     TDWORD
	FStartTime           TDWORD
	FUntilTime           TDWORD
	FStatus              TDWORD
	FcJobs               TDWORD
	FAveragePPM          TDWORD
}

type PRINTER_INFO_2A = TPRINTER_INFO_2A

type T_PRINTER_INFO_2A = TPRINTER_INFO_2A

type _PRINTER_INFO_2A = T_PRINTER_INFO_2A

type TPPRINTER_INFO_2A = uintptr

type PPRINTER_INFO_2A = TPPRINTER_INFO_2A

type TLPPRINTER_INFO_2A = uintptr

type LPPRINTER_INFO_2A = TLPPRINTER_INFO_2A

type TPRINTER_INFO_2W = struct {
	FpServerName         TLPWSTR
	FpPrinterName        TLPWSTR
	FpShareName          TLPWSTR
	FpPortName           TLPWSTR
	FpDriverName         TLPWSTR
	FpComment            TLPWSTR
	FpLocation           TLPWSTR
	FpDevMode            TLPDEVMODEW
	FpSepFile            TLPWSTR
	FpPrintProcessor     TLPWSTR
	FpDatatype           TLPWSTR
	FpParameters         TLPWSTR
	FpSecurityDescriptor TPSECURITY_DESCRIPTOR
	FAttributes          TDWORD
	FPriority            TDWORD
	FDefaultPriority     TDWORD
	FStartTime           TDWORD
	FUntilTime           TDWORD
	FStatus              TDWORD
	FcJobs               TDWORD
	FAveragePPM          TDWORD
}

type PRINTER_INFO_2W = TPRINTER_INFO_2W

type T_PRINTER_INFO_2W = TPRINTER_INFO_2W

type _PRINTER_INFO_2W = T_PRINTER_INFO_2W

type TPPRINTER_INFO_2W = uintptr

type PPRINTER_INFO_2W = TPPRINTER_INFO_2W

type TLPPRINTER_INFO_2W = uintptr

type LPPRINTER_INFO_2W = TLPPRINTER_INFO_2W

type TPRINTER_INFO_2 = struct {
	FpServerName         TLPSTR
	FpPrinterName        TLPSTR
	FpShareName          TLPSTR
	FpPortName           TLPSTR
	FpDriverName         TLPSTR
	FpComment            TLPSTR
	FpLocation           TLPSTR
	FpDevMode            TLPDEVMODEA
	FpSepFile            TLPSTR
	FpPrintProcessor     TLPSTR
	FpDatatype           TLPSTR
	FpParameters         TLPSTR
	FpSecurityDescriptor TPSECURITY_DESCRIPTOR
	FAttributes          TDWORD
	FPriority            TDWORD
	FDefaultPriority     TDWORD
	FStartTime           TDWORD
	FUntilTime           TDWORD
	FStatus              TDWORD
	FcJobs               TDWORD
	FAveragePPM          TDWORD
}

type PRINTER_INFO_2 = TPRINTER_INFO_2

type TPPRINTER_INFO_2 = uintptr

type PPRINTER_INFO_2 = TPPRINTER_INFO_2

type TLPPRINTER_INFO_2 = uintptr

type LPPRINTER_INFO_2 = TLPPRINTER_INFO_2

type TPRINTER_INFO_3 = struct {
	FpSecurityDescriptor TPSECURITY_DESCRIPTOR
}

type PRINTER_INFO_3 = TPRINTER_INFO_3

type T_PRINTER_INFO_3 = TPRINTER_INFO_3

type _PRINTER_INFO_3 = T_PRINTER_INFO_3

type TPPRINTER_INFO_3 = uintptr

type PPRINTER_INFO_3 = TPPRINTER_INFO_3

type TLPPRINTER_INFO_3 = uintptr

type LPPRINTER_INFO_3 = TLPPRINTER_INFO_3

type TPRINTER_INFO_4A = struct {
	FpPrinterName TLPSTR
	FpServerName  TLPSTR
	FAttributes   TDWORD
}

type PRINTER_INFO_4A = TPRINTER_INFO_4A

type T_PRINTER_INFO_4A = TPRINTER_INFO_4A

type _PRINTER_INFO_4A = T_PRINTER_INFO_4A

type TPPRINTER_INFO_4A = uintptr

type PPRINTER_INFO_4A = TPPRINTER_INFO_4A

type TLPPRINTER_INFO_4A = uintptr

type LPPRINTER_INFO_4A = TLPPRINTER_INFO_4A

type TPRINTER_INFO_4W = struct {
	FpPrinterName TLPWSTR
	FpServerName  TLPWSTR
	FAttributes   TDWORD
}

type PRINTER_INFO_4W = TPRINTER_INFO_4W

type T_PRINTER_INFO_4W = TPRINTER_INFO_4W

type _PRINTER_INFO_4W = T_PRINTER_INFO_4W

type TPPRINTER_INFO_4W = uintptr

type PPRINTER_INFO_4W = TPPRINTER_INFO_4W

type TLPPRINTER_INFO_4W = uintptr

type LPPRINTER_INFO_4W = TLPPRINTER_INFO_4W

type TPRINTER_INFO_4 = struct {
	FpPrinterName TLPSTR
	FpServerName  TLPSTR
	FAttributes   TDWORD
}

type PRINTER_INFO_4 = TPRINTER_INFO_4

type TPPRINTER_INFO_4 = uintptr

type PPRINTER_INFO_4 = TPPRINTER_INFO_4

type TLPPRINTER_INFO_4 = uintptr

type LPPRINTER_INFO_4 = TLPPRINTER_INFO_4

type TPRINTER_INFO_5A = struct {
	FpPrinterName             TLPSTR
	FpPortName                TLPSTR
	FAttributes               TDWORD
	FDeviceNotSelectedTimeout TDWORD
	FTransmissionRetryTimeout TDWORD
}

type PRINTER_INFO_5A = TPRINTER_INFO_5A

type T_PRINTER_INFO_5A = TPRINTER_INFO_5A

type _PRINTER_INFO_5A = T_PRINTER_INFO_5A

type TPPRINTER_INFO_5A = uintptr

type PPRINTER_INFO_5A = TPPRINTER_INFO_5A

type TLPPRINTER_INFO_5A = uintptr

type LPPRINTER_INFO_5A = TLPPRINTER_INFO_5A

type TPRINTER_INFO_5W = struct {
	FpPrinterName             TLPWSTR
	FpPortName                TLPWSTR
	FAttributes               TDWORD
	FDeviceNotSelectedTimeout TDWORD
	FTransmissionRetryTimeout TDWORD
}

type PRINTER_INFO_5W = TPRINTER_INFO_5W

type T_PRINTER_INFO_5W = TPRINTER_INFO_5W

type _PRINTER_INFO_5W = T_PRINTER_INFO_5W

type TPPRINTER_INFO_5W = uintptr

type PPRINTER_INFO_5W = TPPRINTER_INFO_5W

type TLPPRINTER_INFO_5W = uintptr

type LPPRINTER_INFO_5W = TLPPRINTER_INFO_5W

type TPRINTER_INFO_5 = struct {
	FpPrinterName             TLPSTR
	FpPortName                TLPSTR
	FAttributes               TDWORD
	FDeviceNotSelectedTimeout TDWORD
	FTransmissionRetryTimeout TDWORD
}

type PRINTER_INFO_5 = TPRINTER_INFO_5

type TPPRINTER_INFO_5 = uintptr

type PPRINTER_INFO_5 = TPPRINTER_INFO_5

type TLPPRINTER_INFO_5 = uintptr

type LPPRINTER_INFO_5 = TLPPRINTER_INFO_5

type TPRINTER_INFO_6 = struct {
	FdwStatus TDWORD
}

type PRINTER_INFO_6 = TPRINTER_INFO_6

type T_PRINTER_INFO_6 = TPRINTER_INFO_6

type _PRINTER_INFO_6 = T_PRINTER_INFO_6

type TPPRINTER_INFO_6 = uintptr

type PPRINTER_INFO_6 = TPPRINTER_INFO_6

type TLPPRINTER_INFO_6 = uintptr

type LPPRINTER_INFO_6 = TLPPRINTER_INFO_6

type TPRINTER_INFO_7A = struct {
	FpszObjectGUID TLPSTR
	FdwAction      TDWORD
}

type PRINTER_INFO_7A = TPRINTER_INFO_7A

type T_PRINTER_INFO_7A = TPRINTER_INFO_7A

type _PRINTER_INFO_7A = T_PRINTER_INFO_7A

type TPPRINTER_INFO_7A = uintptr

type PPRINTER_INFO_7A = TPPRINTER_INFO_7A

type TLPPRINTER_INFO_7A = uintptr

type LPPRINTER_INFO_7A = TLPPRINTER_INFO_7A

type TPRINTER_INFO_7W = struct {
	FpszObjectGUID TLPWSTR
	FdwAction      TDWORD
}

type PRINTER_INFO_7W = TPRINTER_INFO_7W

type T_PRINTER_INFO_7W = TPRINTER_INFO_7W

type _PRINTER_INFO_7W = T_PRINTER_INFO_7W

type TPPRINTER_INFO_7W = uintptr

type PPRINTER_INFO_7W = TPPRINTER_INFO_7W

type TLPPRINTER_INFO_7W = uintptr

type LPPRINTER_INFO_7W = TLPPRINTER_INFO_7W

type TPRINTER_INFO_7 = struct {
	FpszObjectGUID TLPSTR
	FdwAction      TDWORD
}

type PRINTER_INFO_7 = TPRINTER_INFO_7

type TPPRINTER_INFO_7 = uintptr

type PPRINTER_INFO_7 = TPPRINTER_INFO_7

type TLPPRINTER_INFO_7 = uintptr

type LPPRINTER_INFO_7 = TLPPRINTER_INFO_7

type TPRINTER_INFO_8A = struct {
	FpDevMode TLPDEVMODEA
}

type PRINTER_INFO_8A = TPRINTER_INFO_8A

type T_PRINTER_INFO_8A = TPRINTER_INFO_8A

type _PRINTER_INFO_8A = T_PRINTER_INFO_8A

type TPPRINTER_INFO_8A = uintptr

type PPRINTER_INFO_8A = TPPRINTER_INFO_8A

type TLPPRINTER_INFO_8A = uintptr

type LPPRINTER_INFO_8A = TLPPRINTER_INFO_8A

type TPRINTER_INFO_8W = struct {
	FpDevMode TLPDEVMODEW
}

type PRINTER_INFO_8W = TPRINTER_INFO_8W

type T_PRINTER_INFO_8W = TPRINTER_INFO_8W

type _PRINTER_INFO_8W = T_PRINTER_INFO_8W

type TPPRINTER_INFO_8W = uintptr

type PPRINTER_INFO_8W = TPPRINTER_INFO_8W

type TLPPRINTER_INFO_8W = uintptr

type LPPRINTER_INFO_8W = TLPPRINTER_INFO_8W

type TPRINTER_INFO_8 = struct {
	FpDevMode TLPDEVMODEA
}

type PRINTER_INFO_8 = TPRINTER_INFO_8

type TPPRINTER_INFO_8 = uintptr

type PPRINTER_INFO_8 = TPPRINTER_INFO_8

type TLPPRINTER_INFO_8 = uintptr

type LPPRINTER_INFO_8 = TLPPRINTER_INFO_8

type TPRINTER_INFO_9A = struct {
	FpDevMode TLPDEVMODEA
}

type PRINTER_INFO_9A = TPRINTER_INFO_9A

type T_PRINTER_INFO_9A = TPRINTER_INFO_9A

type _PRINTER_INFO_9A = T_PRINTER_INFO_9A

type TPPRINTER_INFO_9A = uintptr

type PPRINTER_INFO_9A = TPPRINTER_INFO_9A

type TLPPRINTER_INFO_9A = uintptr

type LPPRINTER_INFO_9A = TLPPRINTER_INFO_9A

type TPRINTER_INFO_9W = struct {
	FpDevMode TLPDEVMODEW
}

type PRINTER_INFO_9W = TPRINTER_INFO_9W

type T_PRINTER_INFO_9W = TPRINTER_INFO_9W

type _PRINTER_INFO_9W = T_PRINTER_INFO_9W

type TPPRINTER_INFO_9W = uintptr

type PPRINTER_INFO_9W = TPPRINTER_INFO_9W

type TLPPRINTER_INFO_9W = uintptr

type LPPRINTER_INFO_9W = TLPPRINTER_INFO_9W

type TPRINTER_INFO_9 = struct {
	FpDevMode TLPDEVMODEA
}

type PRINTER_INFO_9 = TPRINTER_INFO_9

type TPPRINTER_INFO_9 = uintptr

type PPRINTER_INFO_9 = TPPRINTER_INFO_9

type TLPPRINTER_INFO_9 = uintptr

type LPPRINTER_INFO_9 = TLPPRINTER_INFO_9

type TJOB_INFO_1A = struct {
	FJobId        TDWORD
	FpPrinterName TLPSTR
	FpMachineName TLPSTR
	FpUserName    TLPSTR
	FpDocument    TLPSTR
	FpDatatype    TLPSTR
	FpStatus      TLPSTR
	FStatus       TDWORD
	FPriority     TDWORD
	FPosition     TDWORD
	FTotalPages   TDWORD
	FPagesPrinted TDWORD
	FSubmitted    TSYSTEMTIME
}

type JOB_INFO_1A = TJOB_INFO_1A

type T_JOB_INFO_1A = TJOB_INFO_1A

type _JOB_INFO_1A = T_JOB_INFO_1A

type TPJOB_INFO_1A = uintptr

type PJOB_INFO_1A = TPJOB_INFO_1A

type TLPJOB_INFO_1A = uintptr

type LPJOB_INFO_1A = TLPJOB_INFO_1A

type TJOB_INFO_1W = struct {
	FJobId        TDWORD
	FpPrinterName TLPWSTR
	FpMachineName TLPWSTR
	FpUserName    TLPWSTR
	FpDocument    TLPWSTR
	FpDatatype    TLPWSTR
	FpStatus      TLPWSTR
	FStatus       TDWORD
	FPriority     TDWORD
	FPosition     TDWORD
	FTotalPages   TDWORD
	FPagesPrinted TDWORD
	FSubmitted    TSYSTEMTIME
}

type JOB_INFO_1W = TJOB_INFO_1W

type T_JOB_INFO_1W = TJOB_INFO_1W

type _JOB_INFO_1W = T_JOB_INFO_1W

type TPJOB_INFO_1W = uintptr

type PJOB_INFO_1W = TPJOB_INFO_1W

type TLPJOB_INFO_1W = uintptr

type LPJOB_INFO_1W = TLPJOB_INFO_1W

type TJOB_INFO_1 = struct {
	FJobId        TDWORD
	FpPrinterName TLPSTR
	FpMachineName TLPSTR
	FpUserName    TLPSTR
	FpDocument    TLPSTR
	FpDatatype    TLPSTR
	FpStatus      TLPSTR
	FStatus       TDWORD
	FPriority     TDWORD
	FPosition     TDWORD
	FTotalPages   TDWORD
	FPagesPrinted TDWORD
	FSubmitted    TSYSTEMTIME
}

type JOB_INFO_1 = TJOB_INFO_1

type TPJOB_INFO_1 = uintptr

type PJOB_INFO_1 = TPJOB_INFO_1

type TLPJOB_INFO_1 = uintptr

type LPJOB_INFO_1 = TLPJOB_INFO_1

type TJOB_INFO_2A = struct {
	FJobId               TDWORD
	FpPrinterName        TLPSTR
	FpMachineName        TLPSTR
	FpUserName           TLPSTR
	FpDocument           TLPSTR
	FpNotifyName         TLPSTR
	FpDatatype           TLPSTR
	FpPrintProcessor     TLPSTR
	FpParameters         TLPSTR
	FpDriverName         TLPSTR
	FpDevMode            TLPDEVMODEA
	FpStatus             TLPSTR
	FpSecurityDescriptor TPSECURITY_DESCRIPTOR
	FStatus              TDWORD
	FPriority            TDWORD
	FPosition            TDWORD
	FStartTime           TDWORD
	FUntilTime           TDWORD
	FTotalPages          TDWORD
	FSize                TDWORD
	FSubmitted           TSYSTEMTIME
	FTime                TDWORD
	FPagesPrinted        TDWORD
}

type JOB_INFO_2A = TJOB_INFO_2A

type T_JOB_INFO_2A = TJOB_INFO_2A

type _JOB_INFO_2A = T_JOB_INFO_2A

type TPJOB_INFO_2A = uintptr

type PJOB_INFO_2A = TPJOB_INFO_2A

type TLPJOB_INFO_2A = uintptr

type LPJOB_INFO_2A = TLPJOB_INFO_2A

type TJOB_INFO_2W = struct {
	FJobId               TDWORD
	FpPrinterName        TLPWSTR
	FpMachineName        TLPWSTR
	FpUserName           TLPWSTR
	FpDocument           TLPWSTR
	FpNotifyName         TLPWSTR
	FpDatatype           TLPWSTR
	FpPrintProcessor     TLPWSTR
	FpParameters         TLPWSTR
	FpDriverName         TLPWSTR
	FpDevMode            TLPDEVMODEW
	FpStatus             TLPWSTR
	FpSecurityDescriptor TPSECURITY_DESCRIPTOR
	FStatus              TDWORD
	FPriority            TDWORD
	FPosition            TDWORD
	FStartTime           TDWORD
	FUntilTime           TDWORD
	FTotalPages          TDWORD
	FSize                TDWORD
	FSubmitted           TSYSTEMTIME
	FTime                TDWORD
	FPagesPrinted        TDWORD
}

type JOB_INFO_2W = TJOB_INFO_2W

type T_JOB_INFO_2W = TJOB_INFO_2W

type _JOB_INFO_2W = T_JOB_INFO_2W

type TPJOB_INFO_2W = uintptr

type PJOB_INFO_2W = TPJOB_INFO_2W

type TLPJOB_INFO_2W = uintptr

type LPJOB_INFO_2W = TLPJOB_INFO_2W

type TJOB_INFO_2 = struct {
	FJobId               TDWORD
	FpPrinterName        TLPSTR
	FpMachineName        TLPSTR
	FpUserName           TLPSTR
	FpDocument           TLPSTR
	FpNotifyName         TLPSTR
	FpDatatype           TLPSTR
	FpPrintProcessor     TLPSTR
	FpParameters         TLPSTR
	FpDriverName         TLPSTR
	FpDevMode            TLPDEVMODEA
	FpStatus             TLPSTR
	FpSecurityDescriptor TPSECURITY_DESCRIPTOR
	FStatus              TDWORD
	FPriority            TDWORD
	FPosition            TDWORD
	FStartTime           TDWORD
	FUntilTime           TDWORD
	FTotalPages          TDWORD
	FSize                TDWORD
	FSubmitted           TSYSTEMTIME
	FTime                TDWORD
	FPagesPrinted        TDWORD
}

type JOB_INFO_2 = TJOB_INFO_2

type TPJOB_INFO_2 = uintptr

type PJOB_INFO_2 = TPJOB_INFO_2

type TLPJOB_INFO_2 = uintptr

type LPJOB_INFO_2 = TLPJOB_INFO_2

type TJOB_INFO_3 = struct {
	FJobId     TDWORD
	FNextJobId TDWORD
	FReserved  TDWORD
}

type JOB_INFO_3 = TJOB_INFO_3

type T_JOB_INFO_3 = TJOB_INFO_3

type _JOB_INFO_3 = T_JOB_INFO_3

type TPJOB_INFO_3 = uintptr

type PJOB_INFO_3 = TPJOB_INFO_3

type TLPJOB_INFO_3 = uintptr

type LPJOB_INFO_3 = TLPJOB_INFO_3

type TADDJOB_INFO_1A = struct {
	FPath  TLPSTR
	FJobId TDWORD
}

type ADDJOB_INFO_1A = TADDJOB_INFO_1A

type T_ADDJOB_INFO_1A = TADDJOB_INFO_1A

type _ADDJOB_INFO_1A = T_ADDJOB_INFO_1A

type TPADDJOB_INFO_1A = uintptr

type PADDJOB_INFO_1A = TPADDJOB_INFO_1A

type TLPADDJOB_INFO_1A = uintptr

type LPADDJOB_INFO_1A = TLPADDJOB_INFO_1A

type TADDJOB_INFO_1W = struct {
	FPath  TLPWSTR
	FJobId TDWORD
}

type ADDJOB_INFO_1W = TADDJOB_INFO_1W

type T_ADDJOB_INFO_1W = TADDJOB_INFO_1W

type _ADDJOB_INFO_1W = T_ADDJOB_INFO_1W

type TPADDJOB_INFO_1W = uintptr

type PADDJOB_INFO_1W = TPADDJOB_INFO_1W

type TLPADDJOB_INFO_1W = uintptr

type LPADDJOB_INFO_1W = TLPADDJOB_INFO_1W

type TADDJOB_INFO_1 = struct {
	FPath  TLPSTR
	FJobId TDWORD
}

type ADDJOB_INFO_1 = TADDJOB_INFO_1

type TPADDJOB_INFO_1 = uintptr

type PADDJOB_INFO_1 = TPADDJOB_INFO_1

type TLPADDJOB_INFO_1 = uintptr

type LPADDJOB_INFO_1 = TLPADDJOB_INFO_1

type TDRIVER_INFO_1A = struct {
	FpName TLPSTR
}

type DRIVER_INFO_1A = TDRIVER_INFO_1A

type T_DRIVER_INFO_1A = TDRIVER_INFO_1A

type _DRIVER_INFO_1A = T_DRIVER_INFO_1A

type TPDRIVER_INFO_1A = uintptr

type PDRIVER_INFO_1A = TPDRIVER_INFO_1A

type TLPDRIVER_INFO_1A = uintptr

type LPDRIVER_INFO_1A = TLPDRIVER_INFO_1A

type TDRIVER_INFO_1W = struct {
	FpName TLPWSTR
}

type DRIVER_INFO_1W = TDRIVER_INFO_1W

type T_DRIVER_INFO_1W = TDRIVER_INFO_1W

type _DRIVER_INFO_1W = T_DRIVER_INFO_1W

type TPDRIVER_INFO_1W = uintptr

type PDRIVER_INFO_1W = TPDRIVER_INFO_1W

type TLPDRIVER_INFO_1W = uintptr

type LPDRIVER_INFO_1W = TLPDRIVER_INFO_1W

type TDRIVER_INFO_1 = struct {
	FpName TLPSTR
}

type DRIVER_INFO_1 = TDRIVER_INFO_1

type TPDRIVER_INFO_1 = uintptr

type PDRIVER_INFO_1 = TPDRIVER_INFO_1

type TLPDRIVER_INFO_1 = uintptr

type LPDRIVER_INFO_1 = TLPDRIVER_INFO_1

type TDRIVER_INFO_2A = struct {
	FcVersion     TDWORD
	FpName        TLPSTR
	FpEnvironment TLPSTR
	FpDriverPath  TLPSTR
	FpDataFile    TLPSTR
	FpConfigFile  TLPSTR
}

type DRIVER_INFO_2A = TDRIVER_INFO_2A

type T_DRIVER_INFO_2A = TDRIVER_INFO_2A

type _DRIVER_INFO_2A = T_DRIVER_INFO_2A

type TPDRIVER_INFO_2A = uintptr

type PDRIVER_INFO_2A = TPDRIVER_INFO_2A

type TLPDRIVER_INFO_2A = uintptr

type LPDRIVER_INFO_2A = TLPDRIVER_INFO_2A

type TDRIVER_INFO_2W = struct {
	FcVersion     TDWORD
	FpName        TLPWSTR
	FpEnvironment TLPWSTR
	FpDriverPath  TLPWSTR
	FpDataFile    TLPWSTR
	FpConfigFile  TLPWSTR
}

type DRIVER_INFO_2W = TDRIVER_INFO_2W

type T_DRIVER_INFO_2W = TDRIVER_INFO_2W

type _DRIVER_INFO_2W = T_DRIVER_INFO_2W

type TPDRIVER_INFO_2W = uintptr

type PDRIVER_INFO_2W = TPDRIVER_INFO_2W

type TLPDRIVER_INFO_2W = uintptr

type LPDRIVER_INFO_2W = TLPDRIVER_INFO_2W

type TDRIVER_INFO_2 = struct {
	FcVersion     TDWORD
	FpName        TLPSTR
	FpEnvironment TLPSTR
	FpDriverPath  TLPSTR
	FpDataFile    TLPSTR
	FpConfigFile  TLPSTR
}

type DRIVER_INFO_2 = TDRIVER_INFO_2

type TPDRIVER_INFO_2 = uintptr

type PDRIVER_INFO_2 = TPDRIVER_INFO_2

type TLPDRIVER_INFO_2 = uintptr

type LPDRIVER_INFO_2 = TLPDRIVER_INFO_2

type TDRIVER_INFO_3A = struct {
	FcVersion         TDWORD
	FpName            TLPSTR
	FpEnvironment     TLPSTR
	FpDriverPath      TLPSTR
	FpDataFile        TLPSTR
	FpConfigFile      TLPSTR
	FpHelpFile        TLPSTR
	FpDependentFiles  TLPSTR
	FpMonitorName     TLPSTR
	FpDefaultDataType TLPSTR
}

type DRIVER_INFO_3A = TDRIVER_INFO_3A

type T_DRIVER_INFO_3A = TDRIVER_INFO_3A

type _DRIVER_INFO_3A = T_DRIVER_INFO_3A

type TPDRIVER_INFO_3A = uintptr

type PDRIVER_INFO_3A = TPDRIVER_INFO_3A

type TLPDRIVER_INFO_3A = uintptr

type LPDRIVER_INFO_3A = TLPDRIVER_INFO_3A

type TDRIVER_INFO_3W = struct {
	FcVersion         TDWORD
	FpName            TLPWSTR
	FpEnvironment     TLPWSTR
	FpDriverPath      TLPWSTR
	FpDataFile        TLPWSTR
	FpConfigFile      TLPWSTR
	FpHelpFile        TLPWSTR
	FpDependentFiles  TLPWSTR
	FpMonitorName     TLPWSTR
	FpDefaultDataType TLPWSTR
}

type DRIVER_INFO_3W = TDRIVER_INFO_3W

type T_DRIVER_INFO_3W = TDRIVER_INFO_3W

type _DRIVER_INFO_3W = T_DRIVER_INFO_3W

type TPDRIVER_INFO_3W = uintptr

type PDRIVER_INFO_3W = TPDRIVER_INFO_3W

type TLPDRIVER_INFO_3W = uintptr

type LPDRIVER_INFO_3W = TLPDRIVER_INFO_3W

type TDRIVER_INFO_3 = struct {
	FcVersion         TDWORD
	FpName            TLPSTR
	FpEnvironment     TLPSTR
	FpDriverPath      TLPSTR
	FpDataFile        TLPSTR
	FpConfigFile      TLPSTR
	FpHelpFile        TLPSTR
	FpDependentFiles  TLPSTR
	FpMonitorName     TLPSTR
	FpDefaultDataType TLPSTR
}

type DRIVER_INFO_3 = TDRIVER_INFO_3

type TPDRIVER_INFO_3 = uintptr

type PDRIVER_INFO_3 = TPDRIVER_INFO_3

type TLPDRIVER_INFO_3 = uintptr

type LPDRIVER_INFO_3 = TLPDRIVER_INFO_3

type TDRIVER_INFO_4A = struct {
	FcVersion          TDWORD
	FpName             TLPSTR
	FpEnvironment      TLPSTR
	FpDriverPath       TLPSTR
	FpDataFile         TLPSTR
	FpConfigFile       TLPSTR
	FpHelpFile         TLPSTR
	FpDependentFiles   TLPSTR
	FpMonitorName      TLPSTR
	FpDefaultDataType  TLPSTR
	FpszzPreviousNames TLPSTR
}

type DRIVER_INFO_4A = TDRIVER_INFO_4A

type T_DRIVER_INFO_4A = TDRIVER_INFO_4A

type _DRIVER_INFO_4A = T_DRIVER_INFO_4A

type TPDRIVER_INFO_4A = uintptr

type PDRIVER_INFO_4A = TPDRIVER_INFO_4A

type TLPDRIVER_INFO_4A = uintptr

type LPDRIVER_INFO_4A = TLPDRIVER_INFO_4A

type TDRIVER_INFO_4W = struct {
	FcVersion          TDWORD
	FpName             TLPWSTR
	FpEnvironment      TLPWSTR
	FpDriverPath       TLPWSTR
	FpDataFile         TLPWSTR
	FpConfigFile       TLPWSTR
	FpHelpFile         TLPWSTR
	FpDependentFiles   TLPWSTR
	FpMonitorName      TLPWSTR
	FpDefaultDataType  TLPWSTR
	FpszzPreviousNames TLPWSTR
}

type DRIVER_INFO_4W = TDRIVER_INFO_4W

type T_DRIVER_INFO_4W = TDRIVER_INFO_4W

type _DRIVER_INFO_4W = T_DRIVER_INFO_4W

type TPDRIVER_INFO_4W = uintptr

type PDRIVER_INFO_4W = TPDRIVER_INFO_4W

type TLPDRIVER_INFO_4W = uintptr

type LPDRIVER_INFO_4W = TLPDRIVER_INFO_4W

type TDRIVER_INFO_4 = struct {
	FcVersion          TDWORD
	FpName             TLPSTR
	FpEnvironment      TLPSTR
	FpDriverPath       TLPSTR
	FpDataFile         TLPSTR
	FpConfigFile       TLPSTR
	FpHelpFile         TLPSTR
	FpDependentFiles   TLPSTR
	FpMonitorName      TLPSTR
	FpDefaultDataType  TLPSTR
	FpszzPreviousNames TLPSTR
}

type DRIVER_INFO_4 = TDRIVER_INFO_4

type TPDRIVER_INFO_4 = uintptr

type PDRIVER_INFO_4 = TPDRIVER_INFO_4

type TLPDRIVER_INFO_4 = uintptr

type LPDRIVER_INFO_4 = TLPDRIVER_INFO_4

type TDRIVER_INFO_5A = struct {
	FcVersion           TDWORD
	FpName              TLPSTR
	FpEnvironment       TLPSTR
	FpDriverPath        TLPSTR
	FpDataFile          TLPSTR
	FpConfigFile        TLPSTR
	FdwDriverAttributes TDWORD
	FdwConfigVersion    TDWORD
	FdwDriverVersion    TDWORD
}

type DRIVER_INFO_5A = TDRIVER_INFO_5A

type T_DRIVER_INFO_5A = TDRIVER_INFO_5A

type _DRIVER_INFO_5A = T_DRIVER_INFO_5A

type TPDRIVER_INFO_5A = uintptr

type PDRIVER_INFO_5A = TPDRIVER_INFO_5A

type TLPDRIVER_INFO_5A = uintptr

type LPDRIVER_INFO_5A = TLPDRIVER_INFO_5A

type TDRIVER_INFO_5W = struct {
	FcVersion           TDWORD
	FpName              TLPWSTR
	FpEnvironment       TLPWSTR
	FpDriverPath        TLPWSTR
	FpDataFile          TLPWSTR
	FpConfigFile        TLPWSTR
	FdwDriverAttributes TDWORD
	FdwConfigVersion    TDWORD
	FdwDriverVersion    TDWORD
}

type DRIVER_INFO_5W = TDRIVER_INFO_5W

type T_DRIVER_INFO_5W = TDRIVER_INFO_5W

type _DRIVER_INFO_5W = T_DRIVER_INFO_5W

type TPDRIVER_INFO_5W = uintptr

type PDRIVER_INFO_5W = TPDRIVER_INFO_5W

type TLPDRIVER_INFO_5W = uintptr

type LPDRIVER_INFO_5W = TLPDRIVER_INFO_5W

type TDRIVER_INFO_5 = struct {
	FcVersion           TDWORD
	FpName              TLPSTR
	FpEnvironment       TLPSTR
	FpDriverPath        TLPSTR
	FpDataFile          TLPSTR
	FpConfigFile        TLPSTR
	FdwDriverAttributes TDWORD
	FdwConfigVersion    TDWORD
	FdwDriverVersion    TDWORD
}

type DRIVER_INFO_5 = TDRIVER_INFO_5

type TPDRIVER_INFO_5 = uintptr

type PDRIVER_INFO_5 = TPDRIVER_INFO_5

type TLPDRIVER_INFO_5 = uintptr

type LPDRIVER_INFO_5 = TLPDRIVER_INFO_5

type TDRIVER_INFO_6A = struct {
	F__ccgo_align      [0]uint32
	FcVersion          TDWORD
	FpName             TLPSTR
	FpEnvironment      TLPSTR
	FpDriverPath       TLPSTR
	FpDataFile         TLPSTR
	FpConfigFile       TLPSTR
	FpHelpFile         TLPSTR
	FpDependentFiles   TLPSTR
	FpMonitorName      TLPSTR
	FpDefaultDataType  TLPSTR
	FpszzPreviousNames TLPSTR
	FftDriverDate      TFILETIME
	F__ccgo_align12    [4]byte
	FdwlDriverVersion  TDWORDLONG
	FpszMfgName        TLPSTR
	FpszOEMUrl         TLPSTR
	FpszHardwareID     TLPSTR
	FpszProvider       TLPSTR
}

type DRIVER_INFO_6A = TDRIVER_INFO_6A

type T_DRIVER_INFO_6A = TDRIVER_INFO_6A

type _DRIVER_INFO_6A = T_DRIVER_INFO_6A

type TPDRIVER_INFO_6A = uintptr

type PDRIVER_INFO_6A = TPDRIVER_INFO_6A

type TLPDRIVER_INFO_6A = uintptr

type LPDRIVER_INFO_6A = TLPDRIVER_INFO_6A

type TDRIVER_INFO_6W = struct {
	F__ccgo_align      [0]uint32
	FcVersion          TDWORD
	FpName             TLPWSTR
	FpEnvironment      TLPWSTR
	FpDriverPath       TLPWSTR
	FpDataFile         TLPWSTR
	FpConfigFile       TLPWSTR
	FpHelpFile         TLPWSTR
	FpDependentFiles   TLPWSTR
	FpMonitorName      TLPWSTR
	FpDefaultDataType  TLPWSTR
	FpszzPreviousNames TLPWSTR
	FftDriverDate      TFILETIME
	F__ccgo_align12    [4]byte
	FdwlDriverVersion  TDWORDLONG
	FpszMfgName        TLPWSTR
	FpszOEMUrl         TLPWSTR
	FpszHardwareID     TLPWSTR
	FpszProvider       TLPWSTR
}

type DRIVER_INFO_6W = TDRIVER_INFO_6W

type T_DRIVER_INFO_6W = TDRIVER_INFO_6W

type _DRIVER_INFO_6W = T_DRIVER_INFO_6W

type TPDRIVER_INFO_6W = uintptr

type PDRIVER_INFO_6W = TPDRIVER_INFO_6W

type TLPDRIVER_INFO_6W = uintptr

type LPDRIVER_INFO_6W = TLPDRIVER_INFO_6W

type TDRIVER_INFO_6 = struct {
	F__ccgo_align      [0]uint32
	FcVersion          TDWORD
	FpName             TLPSTR
	FpEnvironment      TLPSTR
	FpDriverPath       TLPSTR
	FpDataFile         TLPSTR
	FpConfigFile       TLPSTR
	FpHelpFile         TLPSTR
	FpDependentFiles   TLPSTR
	FpMonitorName      TLPSTR
	FpDefaultDataType  TLPSTR
	FpszzPreviousNames TLPSTR
	FftDriverDate      TFILETIME
	F__ccgo_align12    [4]byte
	FdwlDriverVersion  TDWORDLONG
	FpszMfgName        TLPSTR
	FpszOEMUrl         TLPSTR
	FpszHardwareID     TLPSTR
	FpszProvider       TLPSTR
}

type DRIVER_INFO_6 = TDRIVER_INFO_6

type TPDRIVER_INFO_6 = uintptr

type PDRIVER_INFO_6 = TPDRIVER_INFO_6

type TLPDRIVER_INFO_6 = uintptr

type LPDRIVER_INFO_6 = TLPDRIVER_INFO_6

type TDOC_INFO_1A = struct {
	FpDocName    TLPSTR
	FpOutputFile TLPSTR
	FpDatatype   TLPSTR
}

type DOC_INFO_1A = TDOC_INFO_1A

type T_DOC_INFO_1A = TDOC_INFO_1A

type _DOC_INFO_1A = T_DOC_INFO_1A

type TPDOC_INFO_1A = uintptr

type PDOC_INFO_1A = TPDOC_INFO_1A

type TLPDOC_INFO_1A = uintptr

type LPDOC_INFO_1A = TLPDOC_INFO_1A

type TDOC_INFO_1W = struct {
	FpDocName    TLPWSTR
	FpOutputFile TLPWSTR
	FpDatatype   TLPWSTR
}

type DOC_INFO_1W = TDOC_INFO_1W

type T_DOC_INFO_1W = TDOC_INFO_1W

type _DOC_INFO_1W = T_DOC_INFO_1W

type TPDOC_INFO_1W = uintptr

type PDOC_INFO_1W = TPDOC_INFO_1W

type TLPDOC_INFO_1W = uintptr

type LPDOC_INFO_1W = TLPDOC_INFO_1W

type TDOC_INFO_1 = struct {
	FpDocName    TLPSTR
	FpOutputFile TLPSTR
	FpDatatype   TLPSTR
}

type DOC_INFO_1 = TDOC_INFO_1

type TPDOC_INFO_1 = uintptr

type PDOC_INFO_1 = TPDOC_INFO_1

type TLPDOC_INFO_1 = uintptr

type LPDOC_INFO_1 = TLPDOC_INFO_1

type TFORM_INFO_1A = struct {
	FFlags         TDWORD
	FpName         TLPSTR
	FSize          TSIZEL
	FImageableArea TRECTL
}

type FORM_INFO_1A = TFORM_INFO_1A

type T_FORM_INFO_1A = TFORM_INFO_1A

type _FORM_INFO_1A = T_FORM_INFO_1A

type TPFORM_INFO_1A = uintptr

type PFORM_INFO_1A = TPFORM_INFO_1A

type TLPFORM_INFO_1A = uintptr

type LPFORM_INFO_1A = TLPFORM_INFO_1A

type TFORM_INFO_1W = struct {
	FFlags         TDWORD
	FpName         TLPWSTR
	FSize          TSIZEL
	FImageableArea TRECTL
}

type FORM_INFO_1W = TFORM_INFO_1W

type T_FORM_INFO_1W = TFORM_INFO_1W

type _FORM_INFO_1W = T_FORM_INFO_1W

type TPFORM_INFO_1W = uintptr

type PFORM_INFO_1W = TPFORM_INFO_1W

type TLPFORM_INFO_1W = uintptr

type LPFORM_INFO_1W = TLPFORM_INFO_1W

type TFORM_INFO_1 = struct {
	FFlags         TDWORD
	FpName         TLPSTR
	FSize          TSIZEL
	FImageableArea TRECTL
}

type FORM_INFO_1 = TFORM_INFO_1

type TPFORM_INFO_1 = uintptr

type PFORM_INFO_1 = TPFORM_INFO_1

type TLPFORM_INFO_1 = uintptr

type LPFORM_INFO_1 = TLPFORM_INFO_1

type TDOC_INFO_2A = struct {
	FpDocName    TLPSTR
	FpOutputFile TLPSTR
	FpDatatype   TLPSTR
	FdwMode      TDWORD
	FJobId       TDWORD
}

type DOC_INFO_2A = TDOC_INFO_2A

type T_DOC_INFO_2A = TDOC_INFO_2A

type _DOC_INFO_2A = T_DOC_INFO_2A

type TPDOC_INFO_2A = uintptr

type PDOC_INFO_2A = TPDOC_INFO_2A

type TLPDOC_INFO_2A = uintptr

type LPDOC_INFO_2A = TLPDOC_INFO_2A

type TDOC_INFO_2W = struct {
	FpDocName    TLPWSTR
	FpOutputFile TLPWSTR
	FpDatatype   TLPWSTR
	FdwMode      TDWORD
	FJobId       TDWORD
}

type DOC_INFO_2W = TDOC_INFO_2W

type T_DOC_INFO_2W = TDOC_INFO_2W

type _DOC_INFO_2W = T_DOC_INFO_2W

type TPDOC_INFO_2W = uintptr

type PDOC_INFO_2W = TPDOC_INFO_2W

type TLPDOC_INFO_2W = uintptr

type LPDOC_INFO_2W = TLPDOC_INFO_2W

type TDOC_INFO_2 = struct {
	FpDocName    TLPSTR
	FpOutputFile TLPSTR
	FpDatatype   TLPSTR
	FdwMode      TDWORD
	FJobId       TDWORD
}

type DOC_INFO_2 = TDOC_INFO_2

type TPDOC_INFO_2 = uintptr

type PDOC_INFO_2 = TPDOC_INFO_2

type TLPDOC_INFO_2 = uintptr

type LPDOC_INFO_2 = TLPDOC_INFO_2

type TDOC_INFO_3A = struct {
	FpDocName    TLPSTR
	FpOutputFile TLPSTR
	FpDatatype   TLPSTR
	FdwFlags     TDWORD
}

type DOC_INFO_3A = TDOC_INFO_3A

type T_DOC_INFO_3A = TDOC_INFO_3A

type _DOC_INFO_3A = T_DOC_INFO_3A

type TPDOC_INFO_3A = uintptr

type PDOC_INFO_3A = TPDOC_INFO_3A

type TLPDOC_INFO_3A = uintptr

type LPDOC_INFO_3A = TLPDOC_INFO_3A

type TDOC_INFO_3W = struct {
	FpDocName    TLPWSTR
	FpOutputFile TLPWSTR
	FpDatatype   TLPWSTR
	FdwFlags     TDWORD
}

type DOC_INFO_3W = TDOC_INFO_3W

type T_DOC_INFO_3W = TDOC_INFO_3W

type _DOC_INFO_3W = T_DOC_INFO_3W

type TPDOC_INFO_3W = uintptr

type PDOC_INFO_3W = TPDOC_INFO_3W

type TLPDOC_INFO_3W = uintptr

type LPDOC_INFO_3W = TLPDOC_INFO_3W

type TDOC_INFO_3 = struct {
	FpDocName    TLPSTR
	FpOutputFile TLPSTR
	FpDatatype   TLPSTR
	FdwFlags     TDWORD
}

type DOC_INFO_3 = TDOC_INFO_3

type TPDOC_INFO_3 = uintptr

type PDOC_INFO_3 = TPDOC_INFO_3

type TLPDOC_INFO_3 = uintptr

type LPDOC_INFO_3 = TLPDOC_INFO_3

type TPRINTPROCESSOR_INFO_1A = struct {
	FpName TLPSTR
}

type PRINTPROCESSOR_INFO_1A = TPRINTPROCESSOR_INFO_1A

type T_PRINTPROCESSOR_INFO_1A = TPRINTPROCESSOR_INFO_1A

type _PRINTPROCESSOR_INFO_1A = T_PRINTPROCESSOR_INFO_1A

type TPPRINTPROCESSOR_INFO_1A = uintptr

type PPRINTPROCESSOR_INFO_1A = TPPRINTPROCESSOR_INFO_1A

type TLPPRINTPROCESSOR_INFO_1A = uintptr

type LPPRINTPROCESSOR_INFO_1A = TLPPRINTPROCESSOR_INFO_1A

type TPRINTPROCESSOR_INFO_1W = struct {
	FpName TLPWSTR
}

type PRINTPROCESSOR_INFO_1W = TPRINTPROCESSOR_INFO_1W

type T_PRINTPROCESSOR_INFO_1W = TPRINTPROCESSOR_INFO_1W

type _PRINTPROCESSOR_INFO_1W = T_PRINTPROCESSOR_INFO_1W

type TPPRINTPROCESSOR_INFO_1W = uintptr

type PPRINTPROCESSOR_INFO_1W = TPPRINTPROCESSOR_INFO_1W

type TLPPRINTPROCESSOR_INFO_1W = uintptr

type LPPRINTPROCESSOR_INFO_1W = TLPPRINTPROCESSOR_INFO_1W

type TPRINTPROCESSOR_INFO_1 = struct {
	FpName TLPSTR
}

type PRINTPROCESSOR_INFO_1 = TPRINTPROCESSOR_INFO_1

type TPPRINTPROCESSOR_INFO_1 = uintptr

type PPRINTPROCESSOR_INFO_1 = TPPRINTPROCESSOR_INFO_1

type TLPPRINTPROCESSOR_INFO_1 = uintptr

type LPPRINTPROCESSOR_INFO_1 = TLPPRINTPROCESSOR_INFO_1

type TPRINTPROCESSOR_CAPS_1 = struct {
	FdwLevel          TDWORD
	FdwNupOptions     TDWORD
	FdwPageOrderFlags TDWORD
	FdwNumberOfCopies TDWORD
}

type PRINTPROCESSOR_CAPS_1 = TPRINTPROCESSOR_CAPS_1

type T_PRINTPROCESSOR_CAPS_1 = TPRINTPROCESSOR_CAPS_1

type _PRINTPROCESSOR_CAPS_1 = T_PRINTPROCESSOR_CAPS_1

type TPPRINTPROCESSOR_CAPS_1 = uintptr

type PPRINTPROCESSOR_CAPS_1 = TPPRINTPROCESSOR_CAPS_1

type TPORT_INFO_1A = struct {
	FpName TLPSTR
}

type PORT_INFO_1A = TPORT_INFO_1A

type T_PORT_INFO_1A = TPORT_INFO_1A

type _PORT_INFO_1A = T_PORT_INFO_1A

type TPPORT_INFO_1A = uintptr

type PPORT_INFO_1A = TPPORT_INFO_1A

type TLPPORT_INFO_1A = uintptr

type LPPORT_INFO_1A = TLPPORT_INFO_1A

type TPORT_INFO_1W = struct {
	FpName TLPWSTR
}

type PORT_INFO_1W = TPORT_INFO_1W

type T_PORT_INFO_1W = TPORT_INFO_1W

type _PORT_INFO_1W = T_PORT_INFO_1W

type TPPORT_INFO_1W = uintptr

type PPORT_INFO_1W = TPPORT_INFO_1W

type TLPPORT_INFO_1W = uintptr

type LPPORT_INFO_1W = TLPPORT_INFO_1W

type TPORT_INFO_1 = struct {
	FpName TLPSTR
}

type PORT_INFO_1 = TPORT_INFO_1

type TPPORT_INFO_1 = uintptr

type PPORT_INFO_1 = TPPORT_INFO_1

type TLPPORT_INFO_1 = uintptr

type LPPORT_INFO_1 = TLPPORT_INFO_1

type TPORT_INFO_2A = struct {
	FpPortName    TLPSTR
	FpMonitorName TLPSTR
	FpDescription TLPSTR
	FfPortType    TDWORD
	FReserved     TDWORD
}

type PORT_INFO_2A = TPORT_INFO_2A

type T_PORT_INFO_2A = TPORT_INFO_2A

type _PORT_INFO_2A = T_PORT_INFO_2A

type TPPORT_INFO_2A = uintptr

type PPORT_INFO_2A = TPPORT_INFO_2A

type TLPPORT_INFO_2A = uintptr

type LPPORT_INFO_2A = TLPPORT_INFO_2A

type TPORT_INFO_2W = struct {
	FpPortName    TLPWSTR
	FpMonitorName TLPWSTR
	FpDescription TLPWSTR
	FfPortType    TDWORD
	FReserved     TDWORD
}

type PORT_INFO_2W = TPORT_INFO_2W

type T_PORT_INFO_2W = TPORT_INFO_2W

type _PORT_INFO_2W = T_PORT_INFO_2W

type TPPORT_INFO_2W = uintptr

type PPORT_INFO_2W = TPPORT_INFO_2W

type TLPPORT_INFO_2W = uintptr

type LPPORT_INFO_2W = TLPPORT_INFO_2W

type TPORT_INFO_2 = struct {
	FpPortName    TLPSTR
	FpMonitorName TLPSTR
	FpDescription TLPSTR
	FfPortType    TDWORD
	FReserved     TDWORD
}

type PORT_INFO_2 = TPORT_INFO_2

type TPPORT_INFO_2 = uintptr

type PPORT_INFO_2 = TPPORT_INFO_2

type TLPPORT_INFO_2 = uintptr

type LPPORT_INFO_2 = TLPPORT_INFO_2

type TPORT_INFO_3A = struct {
	FdwStatus   TDWORD
	FpszStatus  TLPSTR
	FdwSeverity TDWORD
}

type PORT_INFO_3A = TPORT_INFO_3A

type T_PORT_INFO_3A = TPORT_INFO_3A

type _PORT_INFO_3A = T_PORT_INFO_3A

type TPPORT_INFO_3A = uintptr

type PPORT_INFO_3A = TPPORT_INFO_3A

type TLPPORT_INFO_3A = uintptr

type LPPORT_INFO_3A = TLPPORT_INFO_3A

type TPORT_INFO_3W = struct {
	FdwStatus   TDWORD
	FpszStatus  TLPWSTR
	FdwSeverity TDWORD
}

type PORT_INFO_3W = TPORT_INFO_3W

type T_PORT_INFO_3W = TPORT_INFO_3W

type _PORT_INFO_3W = T_PORT_INFO_3W

type TPPORT_INFO_3W = uintptr

type PPORT_INFO_3W = TPPORT_INFO_3W

type TLPPORT_INFO_3W = uintptr

type LPPORT_INFO_3W = TLPPORT_INFO_3W

type TPORT_INFO_3 = struct {
	FdwStatus   TDWORD
	FpszStatus  TLPSTR
	FdwSeverity TDWORD
}

type PORT_INFO_3 = TPORT_INFO_3

type TPPORT_INFO_3 = uintptr

type PPORT_INFO_3 = TPPORT_INFO_3

type TLPPORT_INFO_3 = uintptr

type LPPORT_INFO_3 = TLPPORT_INFO_3

type TMONITOR_INFO_1A = struct {
	FpName TLPSTR
}

type MONITOR_INFO_1A = TMONITOR_INFO_1A

type T_MONITOR_INFO_1A = TMONITOR_INFO_1A

type _MONITOR_INFO_1A = T_MONITOR_INFO_1A

type TPMONITOR_INFO_1A = uintptr

type PMONITOR_INFO_1A = TPMONITOR_INFO_1A

type TLPMONITOR_INFO_1A = uintptr

type LPMONITOR_INFO_1A = TLPMONITOR_INFO_1A

type TMONITOR_INFO_1W = struct {
	FpName TLPWSTR
}

type MONITOR_INFO_1W = TMONITOR_INFO_1W

type T_MONITOR_INFO_1W = TMONITOR_INFO_1W

type _MONITOR_INFO_1W = T_MONITOR_INFO_1W

type TPMONITOR_INFO_1W = uintptr

type PMONITOR_INFO_1W = TPMONITOR_INFO_1W

type TLPMONITOR_INFO_1W = uintptr

type LPMONITOR_INFO_1W = TLPMONITOR_INFO_1W

type TMONITOR_INFO_1 = struct {
	FpName TLPSTR
}

type MONITOR_INFO_1 = TMONITOR_INFO_1

type TPMONITOR_INFO_1 = uintptr

type PMONITOR_INFO_1 = TPMONITOR_INFO_1

type TLPMONITOR_INFO_1 = uintptr

type LPMONITOR_INFO_1 = TLPMONITOR_INFO_1

type TMONITOR_INFO_2A = struct {
	FpName        TLPSTR
	FpEnvironment TLPSTR
	FpDLLName     TLPSTR
}

type MONITOR_INFO_2A = TMONITOR_INFO_2A

type T_MONITOR_INFO_2A = TMONITOR_INFO_2A

type _MONITOR_INFO_2A = T_MONITOR_INFO_2A

type TPMONITOR_INFO_2A = uintptr

type PMONITOR_INFO_2A = TPMONITOR_INFO_2A

type TLPMONITOR_INFO_2A = uintptr

type LPMONITOR_INFO_2A = TLPMONITOR_INFO_2A

type TMONITOR_INFO_2W = struct {
	FpName        TLPWSTR
	FpEnvironment TLPWSTR
	FpDLLName     TLPWSTR
}

type MONITOR_INFO_2W = TMONITOR_INFO_2W

type T_MONITOR_INFO_2W = TMONITOR_INFO_2W

type _MONITOR_INFO_2W = T_MONITOR_INFO_2W

type TPMONITOR_INFO_2W = uintptr

type PMONITOR_INFO_2W = TPMONITOR_INFO_2W

type TLPMONITOR_INFO_2W = uintptr

type LPMONITOR_INFO_2W = TLPMONITOR_INFO_2W

type TMONITOR_INFO_2 = struct {
	FpName        TLPSTR
	FpEnvironment TLPSTR
	FpDLLName     TLPSTR
}

type MONITOR_INFO_2 = TMONITOR_INFO_2

type TPMONITOR_INFO_2 = uintptr

type PMONITOR_INFO_2 = TPMONITOR_INFO_2

type TLPMONITOR_INFO_2 = uintptr

type LPMONITOR_INFO_2 = TLPMONITOR_INFO_2

type TDATATYPES_INFO_1A = struct {
	FpName TLPSTR
}

type DATATYPES_INFO_1A = TDATATYPES_INFO_1A

type T_DATATYPES_INFO_1A = TDATATYPES_INFO_1A

type _DATATYPES_INFO_1A = T_DATATYPES_INFO_1A

type TPDATATYPES_INFO_1A = uintptr

type PDATATYPES_INFO_1A = TPDATATYPES_INFO_1A

type TLPDATATYPES_INFO_1A = uintptr

type LPDATATYPES_INFO_1A = TLPDATATYPES_INFO_1A

type TDATATYPES_INFO_1W = struct {
	FpName TLPWSTR
}

type DATATYPES_INFO_1W = TDATATYPES_INFO_1W

type T_DATATYPES_INFO_1W = TDATATYPES_INFO_1W

type _DATATYPES_INFO_1W = T_DATATYPES_INFO_1W

type TPDATATYPES_INFO_1W = uintptr

type PDATATYPES_INFO_1W = TPDATATYPES_INFO_1W

type TLPDATATYPES_INFO_1W = uintptr

type LPDATATYPES_INFO_1W = TLPDATATYPES_INFO_1W

type TDATATYPES_INFO_1 = struct {
	FpName TLPSTR
}

type DATATYPES_INFO_1 = TDATATYPES_INFO_1

type TPDATATYPES_INFO_1 = uintptr

type PDATATYPES_INFO_1 = TPDATATYPES_INFO_1

type TLPDATATYPES_INFO_1 = uintptr

type LPDATATYPES_INFO_1 = TLPDATATYPES_INFO_1

type TPRINTER_DEFAULTSA = struct {
	FpDatatype     TLPSTR
	FpDevMode      TLPDEVMODEA
	FDesiredAccess TACCESS_MASK
}

type PRINTER_DEFAULTSA = TPRINTER_DEFAULTSA

type T_PRINTER_DEFAULTSA = TPRINTER_DEFAULTSA

type _PRINTER_DEFAULTSA = T_PRINTER_DEFAULTSA

type TPPRINTER_DEFAULTSA = uintptr

type PPRINTER_DEFAULTSA = TPPRINTER_DEFAULTSA

type TLPPRINTER_DEFAULTSA = uintptr

type LPPRINTER_DEFAULTSA = TLPPRINTER_DEFAULTSA

type TPRINTER_DEFAULTSW = struct {
	FpDatatype     TLPWSTR
	FpDevMode      TLPDEVMODEW
	FDesiredAccess TACCESS_MASK
}

type PRINTER_DEFAULTSW = TPRINTER_DEFAULTSW

type T_PRINTER_DEFAULTSW = TPRINTER_DEFAULTSW

type _PRINTER_DEFAULTSW = T_PRINTER_DEFAULTSW

type TPPRINTER_DEFAULTSW = uintptr

type PPRINTER_DEFAULTSW = TPPRINTER_DEFAULTSW

type TLPPRINTER_DEFAULTSW = uintptr

type LPPRINTER_DEFAULTSW = TLPPRINTER_DEFAULTSW

type TPRINTER_DEFAULTS = struct {
	FpDatatype     TLPSTR
	FpDevMode      TLPDEVMODEA
	FDesiredAccess TACCESS_MASK
}

type PRINTER_DEFAULTS = TPRINTER_DEFAULTS

type TPPRINTER_DEFAULTS = uintptr

type PPRINTER_DEFAULTS = TPPRINTER_DEFAULTS

type TLPPRINTER_DEFAULTS = uintptr

type LPPRINTER_DEFAULTS = TLPPRINTER_DEFAULTS

type TPRINTER_ENUM_VALUESA = struct {
	FpValueName  TLPSTR
	FcbValueName TDWORD
	FdwType      TDWORD
	FpData       TLPBYTE
	FcbData      TDWORD
}

type PRINTER_ENUM_VALUESA = TPRINTER_ENUM_VALUESA

type T_PRINTER_ENUM_VALUESA = TPRINTER_ENUM_VALUESA

type _PRINTER_ENUM_VALUESA = T_PRINTER_ENUM_VALUESA

type TPPRINTER_ENUM_VALUESA = uintptr

type PPRINTER_ENUM_VALUESA = TPPRINTER_ENUM_VALUESA

type TLPPRINTER_ENUM_VALUESA = uintptr

type LPPRINTER_ENUM_VALUESA = TLPPRINTER_ENUM_VALUESA

type TPRINTER_ENUM_VALUESW = struct {
	FpValueName  TLPWSTR
	FcbValueName TDWORD
	FdwType      TDWORD
	FpData       TLPBYTE
	FcbData      TDWORD
}

type PRINTER_ENUM_VALUESW = TPRINTER_ENUM_VALUESW

type T_PRINTER_ENUM_VALUESW = TPRINTER_ENUM_VALUESW

type _PRINTER_ENUM_VALUESW = T_PRINTER_ENUM_VALUESW

type TPPRINTER_ENUM_VALUESW = uintptr

type PPRINTER_ENUM_VALUESW = TPPRINTER_ENUM_VALUESW

type TLPPRINTER_ENUM_VALUESW = uintptr

type LPPRINTER_ENUM_VALUESW = TLPPRINTER_ENUM_VALUESW

type TPRINTER_ENUM_VALUES = struct {
	FpValueName  TLPSTR
	FcbValueName TDWORD
	FdwType      TDWORD
	FpData       TLPBYTE
	FcbData      TDWORD
}

type PRINTER_ENUM_VALUES = TPRINTER_ENUM_VALUES

type TPPRINTER_ENUM_VALUES = uintptr

type PPRINTER_ENUM_VALUES = TPPRINTER_ENUM_VALUES

type TLPPRINTER_ENUM_VALUES = uintptr

type LPPRINTER_ENUM_VALUES = TLPPRINTER_ENUM_VALUES

type TPRINTER_NOTIFY_OPTIONS_TYPE = struct {
	FType      TWORD
	FReserved0 TWORD
	FReserved1 TDWORD
	FReserved2 TDWORD
	FCount     TDWORD
	FpFields   TPWORD
}

type PRINTER_NOTIFY_OPTIONS_TYPE = TPRINTER_NOTIFY_OPTIONS_TYPE

type T_PRINTER_NOTIFY_OPTIONS_TYPE = TPRINTER_NOTIFY_OPTIONS_TYPE

type _PRINTER_NOTIFY_OPTIONS_TYPE = T_PRINTER_NOTIFY_OPTIONS_TYPE

type TPPRINTER_NOTIFY_OPTIONS_TYPE = uintptr

type PPRINTER_NOTIFY_OPTIONS_TYPE = TPPRINTER_NOTIFY_OPTIONS_TYPE

type TLPPRINTER_NOTIFY_OPTIONS_TYPE = uintptr

type LPPRINTER_NOTIFY_OPTIONS_TYPE = TLPPRINTER_NOTIFY_OPTIONS_TYPE

type TPRINTER_NOTIFY_OPTIONS = struct {
	FVersion TDWORD
	FFlags   TDWORD
	FCount   TDWORD
	FpTypes  TPPRINTER_NOTIFY_OPTIONS_TYPE
}

type PRINTER_NOTIFY_OPTIONS = TPRINTER_NOTIFY_OPTIONS

type T_PRINTER_NOTIFY_OPTIONS = TPRINTER_NOTIFY_OPTIONS

type _PRINTER_NOTIFY_OPTIONS = T_PRINTER_NOTIFY_OPTIONS

type TPPRINTER_NOTIFY_OPTIONS = uintptr

type PPRINTER_NOTIFY_OPTIONS = TPPRINTER_NOTIFY_OPTIONS

type TLPPRINTER_NOTIFY_OPTIONS = uintptr

type LPPRINTER_NOTIFY_OPTIONS = TLPPRINTER_NOTIFY_OPTIONS

type TPRINTER_NOTIFY_INFO_DATA = struct {
	FType       TWORD
	FField      TWORD
	FReserved   TDWORD
	FId         TDWORD
	FNotifyData struct {
		FData [0]struct {
			FcbBuf TDWORD
			FpBuf  TLPVOID
		}
		FadwData [2]TDWORD
	}
}

type PRINTER_NOTIFY_INFO_DATA = TPRINTER_NOTIFY_INFO_DATA

type T_PRINTER_NOTIFY_INFO_DATA = TPRINTER_NOTIFY_INFO_DATA

type _PRINTER_NOTIFY_INFO_DATA = T_PRINTER_NOTIFY_INFO_DATA

type TPPRINTER_NOTIFY_INFO_DATA = uintptr

type PPRINTER_NOTIFY_INFO_DATA = TPPRINTER_NOTIFY_INFO_DATA

type TLPPRINTER_NOTIFY_INFO_DATA = uintptr

type LPPRINTER_NOTIFY_INFO_DATA = TLPPRINTER_NOTIFY_INFO_DATA

type TPRINTER_NOTIFY_INFO = struct {
	FVersion TDWORD
	FFlags   TDWORD
	FCount   TDWORD
	FaData   [1]TPRINTER_NOTIFY_INFO_DATA
}

type PRINTER_NOTIFY_INFO = TPRINTER_NOTIFY_INFO

type T_PRINTER_NOTIFY_INFO = TPRINTER_NOTIFY_INFO

type _PRINTER_NOTIFY_INFO = T_PRINTER_NOTIFY_INFO

type TPPRINTER_NOTIFY_INFO = uintptr

type PPRINTER_NOTIFY_INFO = TPPRINTER_NOTIFY_INFO

type TLPPRINTER_NOTIFY_INFO = uintptr

type LPPRINTER_NOTIFY_INFO = TLPPRINTER_NOTIFY_INFO

type TBINARY_CONTAINER = struct {
	FcbBuf TDWORD
	FpData TLPBYTE
}

type BINARY_CONTAINER = TBINARY_CONTAINER

type T_BINARY_CONTAINER = TBINARY_CONTAINER

type _BINARY_CONTAINER = T_BINARY_CONTAINER

type TPBINARY_CONTAINER = uintptr

type PBINARY_CONTAINER = TPBINARY_CONTAINER

type TBIDI_DATA = struct {
	FdwBidiType TDWORD
	Fu          struct {
		FiData       [0]TLONG
		FsData       [0]TLPWSTR
		FfData       [0]TFLOAT
		FbiData      [0]TBINARY_CONTAINER
		FbData       TWINBOOL
		F__ccgo_pad5 [4]byte
	}
}

type BIDI_DATA = TBIDI_DATA

type T_BIDI_DATA = TBIDI_DATA

type _BIDI_DATA = T_BIDI_DATA

type TPBIDI_DATA = uintptr

type PBIDI_DATA = TPBIDI_DATA

type TLPBIDI_DATA = uintptr

type LPBIDI_DATA = TLPBIDI_DATA

type TBIDI_REQUEST_DATA = struct {
	FdwReqNumber TDWORD
	FpSchema     TLPWSTR
	Fdata        TBIDI_DATA
}

type BIDI_REQUEST_DATA = TBIDI_REQUEST_DATA

type T_BIDI_REQUEST_DATA = TBIDI_REQUEST_DATA

type _BIDI_REQUEST_DATA = T_BIDI_REQUEST_DATA

type TPBIDI_REQUEST_DATA = uintptr

type PBIDI_REQUEST_DATA = TPBIDI_REQUEST_DATA

type TLPBIDI_REQUEST_DATA = uintptr

type LPBIDI_REQUEST_DATA = TLPBIDI_REQUEST_DATA

type TBIDI_REQUEST_CONTAINER = struct {
	FVersion TDWORD
	FFlags   TDWORD
	FCount   TDWORD
	FaData   [1]TBIDI_REQUEST_DATA
}

type BIDI_REQUEST_CONTAINER = TBIDI_REQUEST_CONTAINER

type T_BIDI_REQUEST_CONTAINER = TBIDI_REQUEST_CONTAINER

type _BIDI_REQUEST_CONTAINER = T_BIDI_REQUEST_CONTAINER

type TPBIDI_REQUEST_CONTAINER = uintptr

type PBIDI_REQUEST_CONTAINER = TPBIDI_REQUEST_CONTAINER

type TLPBIDI_REQUEST_CONTAINER = uintptr

type LPBIDI_REQUEST_CONTAINER = TLPBIDI_REQUEST_CONTAINER

type TBIDI_RESPONSE_DATA = struct {
	FdwResult    TDWORD
	FdwReqNumber TDWORD
	FpSchema     TLPWSTR
	Fdata        TBIDI_DATA
}

type BIDI_RESPONSE_DATA = TBIDI_RESPONSE_DATA

type T_BIDI_RESPONSE_DATA = TBIDI_RESPONSE_DATA

type _BIDI_RESPONSE_DATA = T_BIDI_RESPONSE_DATA

type TPBIDI_RESPONSE_DATA = uintptr

type PBIDI_RESPONSE_DATA = TPBIDI_RESPONSE_DATA

type TLPBIDI_RESPONSE_DATA = uintptr

type LPBIDI_RESPONSE_DATA = TLPBIDI_RESPONSE_DATA

type TBIDI_RESPONSE_CONTAINER = struct {
	FVersion TDWORD
	FFlags   TDWORD
	FCount   TDWORD
	FaData   [1]TBIDI_RESPONSE_DATA
}

type BIDI_RESPONSE_CONTAINER = TBIDI_RESPONSE_CONTAINER

type T_BIDI_RESPONSE_CONTAINER = TBIDI_RESPONSE_CONTAINER

type _BIDI_RESPONSE_CONTAINER = T_BIDI_RESPONSE_CONTAINER

type TPBIDI_RESPONSE_CONTAINER = uintptr

type PBIDI_RESPONSE_CONTAINER = TPBIDI_RESPONSE_CONTAINER

type TLPBIDI_RESPONSE_CONTAINER = uintptr

type LPBIDI_RESPONSE_CONTAINER = TLPBIDI_RESPONSE_CONTAINER

type TBIDI_TYPE = int32

type BIDI_TYPE = TBIDI_TYPE

const _BIDI_NULL = 0
const _BIDI_INT = 1
const _BIDI_FLOAT = 2
const _BIDI_BOOL = 3
const _BIDI_STRING = 4
const _BIDI_TEXT = 5
const _BIDI_ENUM = 6
const _BIDI_BLOB = 7

type TPROVIDOR_INFO_1A = struct {
	FpName        TLPSTR
	FpEnvironment TLPSTR
	FpDLLName     TLPSTR
}

type PROVIDOR_INFO_1A = TPROVIDOR_INFO_1A

type T_PROVIDOR_INFO_1A = TPROVIDOR_INFO_1A

type _PROVIDOR_INFO_1A = T_PROVIDOR_INFO_1A

type TPPROVIDOR_INFO_1A = uintptr

type PPROVIDOR_INFO_1A = TPPROVIDOR_INFO_1A

type TLPPROVIDOR_INFO_1A = uintptr

type LPPROVIDOR_INFO_1A = TLPPROVIDOR_INFO_1A

type TPROVIDOR_INFO_1W = struct {
	FpName        TLPWSTR
	FpEnvironment TLPWSTR
	FpDLLName     TLPWSTR
}

type PROVIDOR_INFO_1W = TPROVIDOR_INFO_1W

type T_PROVIDOR_INFO_1W = TPROVIDOR_INFO_1W

type _PROVIDOR_INFO_1W = T_PROVIDOR_INFO_1W

type TPPROVIDOR_INFO_1W = uintptr

type PPROVIDOR_INFO_1W = TPPROVIDOR_INFO_1W

type TLPPROVIDOR_INFO_1W = uintptr

type LPPROVIDOR_INFO_1W = TLPPROVIDOR_INFO_1W

type TPROVIDOR_INFO_1 = struct {
	FpName        TLPSTR
	FpEnvironment TLPSTR
	FpDLLName     TLPSTR
}

type PROVIDOR_INFO_1 = TPROVIDOR_INFO_1

type TPPROVIDOR_INFO_1 = uintptr

type PPROVIDOR_INFO_1 = TPPROVIDOR_INFO_1

type TLPPROVIDOR_INFO_1 = uintptr

type LPPROVIDOR_INFO_1 = TLPPROVIDOR_INFO_1

type TPROVIDOR_INFO_2A = struct {
	FpOrder TLPSTR
}

type PROVIDOR_INFO_2A = TPROVIDOR_INFO_2A

type T_PROVIDOR_INFO_2A = TPROVIDOR_INFO_2A

type _PROVIDOR_INFO_2A = T_PROVIDOR_INFO_2A

type TPPROVIDOR_INFO_2A = uintptr

type PPROVIDOR_INFO_2A = TPPROVIDOR_INFO_2A

type TLPPROVIDOR_INFO_2A = uintptr

type LPPROVIDOR_INFO_2A = TLPPROVIDOR_INFO_2A

type TPROVIDOR_INFO_2W = struct {
	FpOrder TLPWSTR
}

type PROVIDOR_INFO_2W = TPROVIDOR_INFO_2W

type T_PROVIDOR_INFO_2W = TPROVIDOR_INFO_2W

type _PROVIDOR_INFO_2W = T_PROVIDOR_INFO_2W

type TPPROVIDOR_INFO_2W = uintptr

type PPROVIDOR_INFO_2W = TPPROVIDOR_INFO_2W

type TLPPROVIDOR_INFO_2W = uintptr

type LPPROVIDOR_INFO_2W = TLPPROVIDOR_INFO_2W

type TPROVIDOR_INFO_2 = struct {
	FpOrder TLPSTR
}

type PROVIDOR_INFO_2 = TPROVIDOR_INFO_2

type TPPROVIDOR_INFO_2 = uintptr

type PPROVIDOR_INFO_2 = TPPROVIDOR_INFO_2

type TLPPROVIDOR_INFO_2 = uintptr

type LPPROVIDOR_INFO_2 = TLPPROVIDOR_INFO_2

type TPRINTER_OPTION_FLAGS = int32

type PRINTER_OPTION_FLAGS = TPRINTER_OPTION_FLAGS

type _tagPRINTER_OPTION_FLAGS = int32

const _PRINTER_OPTION_NO_CACHE = 0
const _PRINTER_OPTION_CACHE = 1
const _PRINTER_OPTION_CLIENT_CHANGE = 2

type TEPrintXPSJobOperation = int32

type EPrintXPSJobOperation = TEPrintXPSJobOperation

type _tagEPrintXPSJobOperation = int32

const _kJobProduction = 0
const _kJobConsumption = 1

type TEPrintXPSJobProgress = int32

type EPrintXPSJobProgress = TEPrintXPSJobProgress

type _tagEPrintXPSJobProgress = int32

const _kAddingDocumentSequence = 0
const _kDocumentSequenceAdded = 1
const _kAddingFixedDocument = 2
const _kFixedDocumentAdded = 3
const _kAddingFixedPage = 4
const _kFixedPageAdded = 5
const _kResourceAdded = 6
const _kFontAdded = 7
const _kImageAdded = 8
const _kXpsDocumentCommitted = 9

type TPRINTER_CONNECTION_INFO_1 = struct {
	FdwFlags       TDWORD
	FpszDriverName TLPTSTR
}

type PRINTER_CONNECTION_INFO_1 = TPRINTER_CONNECTION_INFO_1

type T_PRINTER_CONNECTION_INFO_1 = TPRINTER_CONNECTION_INFO_1

type _PRINTER_CONNECTION_INFO_1 = T_PRINTER_CONNECTION_INFO_1

type TPPRINTER_CONNECTION_INFO_1 = uintptr

type PPRINTER_CONNECTION_INFO_1 = TPPRINTER_CONNECTION_INFO_1

type TDRIVER_INFO_8W = struct {
	F__ccgo_align                [0]uint32
	FcVersion                    TDWORD
	FpName                       TLPWSTR
	FpEnvironment                TLPWSTR
	FpDriverPath                 TLPWSTR
	FpDataFile                   TLPWSTR
	FpConfigFile                 TLPWSTR
	FpHelpFile                   TLPWSTR
	FpDependentFiles             TLPWSTR
	FpMonitorName                TLPWSTR
	FpDefaultDataType            TLPWSTR
	FpszzPreviousNames           TLPWSTR
	FftDriverDate                TFILETIME
	F__ccgo_align12              [4]byte
	FdwlDriverVersion            TDWORDLONG
	FpszMfgName                  TLPWSTR
	FpszOEMUrl                   TLPWSTR
	FpszHardwareID               TLPWSTR
	FpszProvider                 TLPWSTR
	FpszPrintProcessor           TLPWSTR
	FpszVendorSetup              TLPWSTR
	FpszzColorProfiles           TLPWSTR
	FpszInfPath                  TLPWSTR
	FdwPrinterDriverAttributes   TDWORD
	FpszzCoreDriverDependencies  TLPWSTR
	FftMinInboxDriverVerDate     TFILETIME
	FdwlMinInboxDriverVerVersion TDWORDLONG
}

type DRIVER_INFO_8W = TDRIVER_INFO_8W

type T_DRIVER_INFO_8W = TDRIVER_INFO_8W

type _DRIVER_INFO_8W = T_DRIVER_INFO_8W

type TPDRIVER_INFO_8W = uintptr

type PDRIVER_INFO_8W = TPDRIVER_INFO_8W

type TLPDRIVER_INFO_8W = uintptr

type LPDRIVER_INFO_8W = TLPDRIVER_INFO_8W

type TDRIVER_INFO_8A = struct {
	F__ccgo_align                [0]uint32
	FcVersion                    TDWORD
	FpName                       TLPSTR
	FpEnvironment                TLPSTR
	FpDriverPath                 TLPSTR
	FpDataFile                   TLPSTR
	FpConfigFile                 TLPSTR
	FpHelpFile                   TLPSTR
	FpDependentFiles             TLPSTR
	FpMonitorName                TLPSTR
	FpDefaultDataType            TLPSTR
	FpszzPreviousNames           TLPSTR
	FftDriverDate                TFILETIME
	F__ccgo_align12              [4]byte
	FdwlDriverVersion            TDWORDLONG
	FpszMfgName                  TLPSTR
	FpszOEMUrl                   TLPSTR
	FpszHardwareID               TLPSTR
	FpszProvider                 TLPSTR
	FpszPrintProcessor           TLPSTR
	FpszVendorSetup              TLPSTR
	FpszzColorProfiles           TLPSTR
	FpszInfPath                  TLPSTR
	FdwPrinterDriverAttributes   TDWORD
	FpszzCoreDriverDependencies  TLPSTR
	FftMinInboxDriverVerDate     TFILETIME
	FdwlMinInboxDriverVerVersion TDWORDLONG
}

type DRIVER_INFO_8A = TDRIVER_INFO_8A

type T_DRIVER_INFO_8A = TDRIVER_INFO_8A

type _DRIVER_INFO_8A = T_DRIVER_INFO_8A

type TPDRIVER_INFO_8A = uintptr

type PDRIVER_INFO_8A = TPDRIVER_INFO_8A

type TLPDRIVER_INFO_8A = uintptr

type LPDRIVER_INFO_8A = TLPDRIVER_INFO_8A

type TFORM_INFO_2A = struct {
	FFlags         TDWORD
	FpName         TLPSTR
	FSize          TSIZEL
	FImageableArea TRECTL
	FpKeyword      TLPCSTR
	FStringType    TDWORD
	FpMuiDll       TLPCSTR
	FdwResourceId  TDWORD
	FpDisplayName  TLPCSTR
	FwLangId       TLANGID
}

type FORM_INFO_2A = TFORM_INFO_2A

type T_FORM_INFO_2A = TFORM_INFO_2A

type _FORM_INFO_2A = T_FORM_INFO_2A

type TPFORM_INFO_2A = uintptr

type PFORM_INFO_2A = TPFORM_INFO_2A

type TFORM_INFO_2W = struct {
	FFlags         TDWORD
	FpName         TLPWSTR
	FSize          TSIZEL
	FImageableArea TRECTL
	FpKeyword      TLPCSTR
	FStringType    TDWORD
	FpMuiDll       TLPCWSTR
	FdwResourceId  TDWORD
	FpDisplayName  TLPCWSTR
	FwLangId       TLANGID
}

type FORM_INFO_2W = TFORM_INFO_2W

type T_FORM_INFO_2W = TFORM_INFO_2W

type _FORM_INFO_2W = T_FORM_INFO_2W

type TPFORM_INFO_2W = uintptr

type PFORM_INFO_2W = TPFORM_INFO_2W

type TDRIVER_INFO_8 = struct {
	F__ccgo_align                [0]uint32
	FcVersion                    TDWORD
	FpName                       TLPSTR
	FpEnvironment                TLPSTR
	FpDriverPath                 TLPSTR
	FpDataFile                   TLPSTR
	FpConfigFile                 TLPSTR
	FpHelpFile                   TLPSTR
	FpDependentFiles             TLPSTR
	FpMonitorName                TLPSTR
	FpDefaultDataType            TLPSTR
	FpszzPreviousNames           TLPSTR
	FftDriverDate                TFILETIME
	F__ccgo_align12              [4]byte
	FdwlDriverVersion            TDWORDLONG
	FpszMfgName                  TLPSTR
	FpszOEMUrl                   TLPSTR
	FpszHardwareID               TLPSTR
	FpszProvider                 TLPSTR
	FpszPrintProcessor           TLPSTR
	FpszVendorSetup              TLPSTR
	FpszzColorProfiles           TLPSTR
	FpszInfPath                  TLPSTR
	FdwPrinterDriverAttributes   TDWORD
	FpszzCoreDriverDependencies  TLPSTR
	FftMinInboxDriverVerDate     TFILETIME
	FdwlMinInboxDriverVerVersion TDWORDLONG
}

type DRIVER_INFO_8 = TDRIVER_INFO_8

type TPDRIVER_INFO_8 = uintptr

type PDRIVER_INFO_8 = TPDRIVER_INFO_8

type TLPDRIVER_INFO_8 = uintptr

type LPDRIVER_INFO_8 = TLPDRIVER_INFO_8

type TFORM_INFO_2 = struct {
	FFlags         TDWORD
	FpName         TLPSTR
	FSize          TSIZEL
	FImageableArea TRECTL
	FpKeyword      TLPCSTR
	FStringType    TDWORD
	FpMuiDll       TLPCSTR
	FdwResourceId  TDWORD
	FpDisplayName  TLPCSTR
	FwLangId       TLANGID
}

type FORM_INFO_2 = TFORM_INFO_2

type TPFORM_INFO_2 = uintptr

type PFORM_INFO_2 = TPFORM_INFO_2

type TPRINTPROCESSOR_CAPS_2 = struct {
	FdwLevel               TDWORD
	FdwNupOptions          TDWORD
	FdwPageOrderFlags      TDWORD
	FdwNumberOfCopies      TDWORD
	FdwNupDirectionCaps    TDWORD
	FdwNupBorderCaps       TDWORD
	FdwBookletHandlingCaps TDWORD
	FdwDuplexHandlingCaps  TDWORD
	FdwScalingCaps         TDWORD
}

type PRINTPROCESSOR_CAPS_2 = TPRINTPROCESSOR_CAPS_2

type T_PRINTPROCESSOR_CAPS_2 = TPRINTPROCESSOR_CAPS_2

type _PRINTPROCESSOR_CAPS_2 = T_PRINTPROCESSOR_CAPS_2

type TPPRINTPROCESSOR_CAPS_2 = uintptr

type PPRINTPROCESSOR_CAPS_2 = TPPRINTPROCESSOR_CAPS_2

type TCORE_PRINTER_DRIVERA = struct {
	F__ccgo_align     [0]uint32
	FCoreDriverGUID   TGUID
	FftDriverDate     TFILETIME
	FdwlDriverVersion TDWORDLONG
	FszPackageID      [260]TCHAR
	F__ccgo_pad4      [4]byte
}

type CORE_PRINTER_DRIVERA = TCORE_PRINTER_DRIVERA

type T_CORE_PRINTER_DRIVERA = TCORE_PRINTER_DRIVERA

type _CORE_PRINTER_DRIVERA = T_CORE_PRINTER_DRIVERA

type TPCORE_PRINTER_DRIVERA = uintptr

type PCORE_PRINTER_DRIVERA = TPCORE_PRINTER_DRIVERA

type TCORE_PRINTER_DRIVERW = struct {
	F__ccgo_align     [0]uint32
	FCoreDriverGUID   TGUID
	FftDriverDate     TFILETIME
	FdwlDriverVersion TDWORDLONG
	FszPackageID      [260]TWCHAR
}

type CORE_PRINTER_DRIVERW = TCORE_PRINTER_DRIVERW

type T_CORE_PRINTER_DRIVERW = TCORE_PRINTER_DRIVERW

type _CORE_PRINTER_DRIVERW = T_CORE_PRINTER_DRIVERW

type TPCORE_PRINTER_DRIVERW = uintptr

type PCORE_PRINTER_DRIVERW = TPCORE_PRINTER_DRIVERW

type TPRINTER_OPTIONS = struct {
	FcbSize  TUINT
	FdwFlags TDWORD
}

type PRINTER_OPTIONS = TPRINTER_OPTIONS

type T_PRINTER_OPTIONS = TPRINTER_OPTIONS

type _PRINTER_OPTIONS = T_PRINTER_OPTIONS

type TPPRINTER_OPTIONS = uintptr

type PPRINTER_OPTIONS = TPPRINTER_OPTIONS

type TCORE_PRINTER_DRIVER = struct {
	F__ccgo_align     [0]uint32
	FCoreDriverGUID   TGUID
	FftDriverDate     TFILETIME
	FdwlDriverVersion TDWORDLONG
	FszPackageID      [260]TCHAR
	F__ccgo_pad4      [4]byte
}

type CORE_PRINTER_DRIVER = TCORE_PRINTER_DRIVER

type TPCORE_PRINTER_DRIVER = uintptr

type PCORE_PRINTER_DRIVER = TPCORE_PRINTER_DRIVER

type TLPOFNHOOKPROC = uintptr

type LPOFNHOOKPROC = TLPOFNHOOKPROC

type TOPENFILENAME_NT4A = struct {
	FlStructSize       TDWORD
	FhwndOwner         THWND
	FhInstance         THINSTANCE
	FlpstrFilter       TLPCSTR
	FlpstrCustomFilter TLPSTR
	FnMaxCustFilter    TDWORD
	FnFilterIndex      TDWORD
	FlpstrFile         TLPSTR
	FnMaxFile          TDWORD
	FlpstrFileTitle    TLPSTR
	FnMaxFileTitle     TDWORD
	FlpstrInitialDir   TLPCSTR
	FlpstrTitle        TLPCSTR
	FFlags             TDWORD
	FnFileOffset       TWORD
	FnFileExtension    TWORD
	FlpstrDefExt       TLPCSTR
	FlCustData         TLPARAM
	FlpfnHook          TLPOFNHOOKPROC
	FlpTemplateName    TLPCSTR
}

type OPENFILENAME_NT4A = TOPENFILENAME_NT4A

type TtagOFN_NT4A = TOPENFILENAME_NT4A

type tagOFN_NT4A = TtagOFN_NT4A

type TLPOPENFILENAME_NT4A = uintptr

type LPOPENFILENAME_NT4A = TLPOPENFILENAME_NT4A

type TOPENFILENAME_NT4W = struct {
	FlStructSize       TDWORD
	FhwndOwner         THWND
	FhInstance         THINSTANCE
	FlpstrFilter       TLPCWSTR
	FlpstrCustomFilter TLPWSTR
	FnMaxCustFilter    TDWORD
	FnFilterIndex      TDWORD
	FlpstrFile         TLPWSTR
	FnMaxFile          TDWORD
	FlpstrFileTitle    TLPWSTR
	FnMaxFileTitle     TDWORD
	FlpstrInitialDir   TLPCWSTR
	FlpstrTitle        TLPCWSTR
	FFlags             TDWORD
	FnFileOffset       TWORD
	FnFileExtension    TWORD
	FlpstrDefExt       TLPCWSTR
	FlCustData         TLPARAM
	FlpfnHook          TLPOFNHOOKPROC
	FlpTemplateName    TLPCWSTR
}

type OPENFILENAME_NT4W = TOPENFILENAME_NT4W

type TtagOFN_NT4W = TOPENFILENAME_NT4W

type tagOFN_NT4W = TtagOFN_NT4W

type TLPOPENFILENAME_NT4W = uintptr

type LPOPENFILENAME_NT4W = TLPOPENFILENAME_NT4W

type TOPENFILENAME_NT4 = struct {
	FlStructSize       TDWORD
	FhwndOwner         THWND
	FhInstance         THINSTANCE
	FlpstrFilter       TLPCSTR
	FlpstrCustomFilter TLPSTR
	FnMaxCustFilter    TDWORD
	FnFilterIndex      TDWORD
	FlpstrFile         TLPSTR
	FnMaxFile          TDWORD
	FlpstrFileTitle    TLPSTR
	FnMaxFileTitle     TDWORD
	FlpstrInitialDir   TLPCSTR
	FlpstrTitle        TLPCSTR
	FFlags             TDWORD
	FnFileOffset       TWORD
	FnFileExtension    TWORD
	FlpstrDefExt       TLPCSTR
	FlCustData         TLPARAM
	FlpfnHook          TLPOFNHOOKPROC
	FlpTemplateName    TLPCSTR
}

type OPENFILENAME_NT4 = TOPENFILENAME_NT4

type TLPOPENFILENAME_NT4 = uintptr

type LPOPENFILENAME_NT4 = TLPOPENFILENAME_NT4

type TOPENFILENAMEA = struct {
	FlStructSize       TDWORD
	FhwndOwner         THWND
	FhInstance         THINSTANCE
	FlpstrFilter       TLPCSTR
	FlpstrCustomFilter TLPSTR
	FnMaxCustFilter    TDWORD
	FnFilterIndex      TDWORD
	FlpstrFile         TLPSTR
	FnMaxFile          TDWORD
	FlpstrFileTitle    TLPSTR
	FnMaxFileTitle     TDWORD
	FlpstrInitialDir   TLPCSTR
	FlpstrTitle        TLPCSTR
	FFlags             TDWORD
	FnFileOffset       TWORD
	FnFileExtension    TWORD
	FlpstrDefExt       TLPCSTR
	FlCustData         TLPARAM
	FlpfnHook          TLPOFNHOOKPROC
	FlpTemplateName    TLPCSTR
	FpvReserved        uintptr
	FdwReserved        TDWORD
	FFlagsEx           TDWORD
}

type OPENFILENAMEA = TOPENFILENAMEA

type TtagOFNA = TOPENFILENAMEA

type tagOFNA = TtagOFNA

type TLPOPENFILENAMEA = uintptr

type LPOPENFILENAMEA = TLPOPENFILENAMEA

type TOPENFILENAMEW = struct {
	FlStructSize       TDWORD
	FhwndOwner         THWND
	FhInstance         THINSTANCE
	FlpstrFilter       TLPCWSTR
	FlpstrCustomFilter TLPWSTR
	FnMaxCustFilter    TDWORD
	FnFilterIndex      TDWORD
	FlpstrFile         TLPWSTR
	FnMaxFile          TDWORD
	FlpstrFileTitle    TLPWSTR
	FnMaxFileTitle     TDWORD
	FlpstrInitialDir   TLPCWSTR
	FlpstrTitle        TLPCWSTR
	FFlags             TDWORD
	FnFileOffset       TWORD
	FnFileExtension    TWORD
	FlpstrDefExt       TLPCWSTR
	FlCustData         TLPARAM
	FlpfnHook          TLPOFNHOOKPROC
	FlpTemplateName    TLPCWSTR
	FpvReserved        uintptr
	FdwReserved        TDWORD
	FFlagsEx           TDWORD
}

type OPENFILENAMEW = TOPENFILENAMEW

type TtagOFNW = TOPENFILENAMEW

type tagOFNW = TtagOFNW

type TLPOPENFILENAMEW = uintptr

type LPOPENFILENAMEW = TLPOPENFILENAMEW

type TOPENFILENAME = struct {
	FlStructSize       TDWORD
	FhwndOwner         THWND
	FhInstance         THINSTANCE
	FlpstrFilter       TLPCSTR
	FlpstrCustomFilter TLPSTR
	FnMaxCustFilter    TDWORD
	FnFilterIndex      TDWORD
	FlpstrFile         TLPSTR
	FnMaxFile          TDWORD
	FlpstrFileTitle    TLPSTR
	FnMaxFileTitle     TDWORD
	FlpstrInitialDir   TLPCSTR
	FlpstrTitle        TLPCSTR
	FFlags             TDWORD
	FnFileOffset       TWORD
	FnFileExtension    TWORD
	FlpstrDefExt       TLPCSTR
	FlCustData         TLPARAM
	FlpfnHook          TLPOFNHOOKPROC
	FlpTemplateName    TLPCSTR
	FpvReserved        uintptr
	FdwReserved        TDWORD
	FFlagsEx           TDWORD
}

type OPENFILENAME = TOPENFILENAME

type TLPOPENFILENAME = uintptr

type LPOPENFILENAME = TLPOPENFILENAME

type TLPCCHOOKPROC = uintptr

type LPCCHOOKPROC = TLPCCHOOKPROC

type TOFNOTIFYA = struct {
	Fhdr     TNMHDR
	FlpOFN   TLPOPENFILENAMEA
	FpszFile TLPSTR
}

type OFNOTIFYA = TOFNOTIFYA

type T_OFNOTIFYA = TOFNOTIFYA

type _OFNOTIFYA = T_OFNOTIFYA

type TLPOFNOTIFYA = uintptr

type LPOFNOTIFYA = TLPOFNOTIFYA

type TOFNOTIFYW = struct {
	Fhdr     TNMHDR
	FlpOFN   TLPOPENFILENAMEW
	FpszFile TLPWSTR
}

type OFNOTIFYW = TOFNOTIFYW

type T_OFNOTIFYW = TOFNOTIFYW

type _OFNOTIFYW = T_OFNOTIFYW

type TLPOFNOTIFYW = uintptr

type LPOFNOTIFYW = TLPOFNOTIFYW

type TOFNOTIFY = struct {
	Fhdr     TNMHDR
	FlpOFN   TLPOPENFILENAMEA
	FpszFile TLPSTR
}

type OFNOTIFY = TOFNOTIFY

type TLPOFNOTIFY = uintptr

type LPOFNOTIFY = TLPOFNOTIFY

type TOFNOTIFYEXA = struct {
	Fhdr   TNMHDR
	FlpOFN TLPOPENFILENAMEA
	Fpsf   TLPVOID
	Fpidl  TLPVOID
}

type OFNOTIFYEXA = TOFNOTIFYEXA

type T_OFNOTIFYEXA = TOFNOTIFYEXA

type _OFNOTIFYEXA = T_OFNOTIFYEXA

type TLPOFNOTIFYEXA = uintptr

type LPOFNOTIFYEXA = TLPOFNOTIFYEXA

type TOFNOTIFYEXW = struct {
	Fhdr   TNMHDR
	FlpOFN TLPOPENFILENAMEW
	Fpsf   TLPVOID
	Fpidl  TLPVOID
}

type OFNOTIFYEXW = TOFNOTIFYEXW

type T_OFNOTIFYEXW = TOFNOTIFYEXW

type _OFNOTIFYEXW = T_OFNOTIFYEXW

type TLPOFNOTIFYEXW = uintptr

type LPOFNOTIFYEXW = TLPOFNOTIFYEXW

type TOFNOTIFYEX = struct {
	Fhdr   TNMHDR
	FlpOFN TLPOPENFILENAMEA
	Fpsf   TLPVOID
	Fpidl  TLPVOID
}

type OFNOTIFYEX = TOFNOTIFYEX

type TLPOFNOTIFYEX = uintptr

type LPOFNOTIFYEX = TLPOFNOTIFYEX

type TCHOOSECOLORA = struct {
	FlStructSize    TDWORD
	FhwndOwner      THWND
	FhInstance      THWND
	FrgbResult      TCOLORREF
	FlpCustColors   uintptr
	FFlags          TDWORD
	FlCustData      TLPARAM
	FlpfnHook       TLPCCHOOKPROC
	FlpTemplateName TLPCSTR
}

type CHOOSECOLORA = TCHOOSECOLORA

type TtagCHOOSECOLORA = TCHOOSECOLORA

type tagCHOOSECOLORA = TtagCHOOSECOLORA

type TLPCHOOSECOLORA = uintptr

type LPCHOOSECOLORA = TLPCHOOSECOLORA

type TCHOOSECOLORW = struct {
	FlStructSize    TDWORD
	FhwndOwner      THWND
	FhInstance      THWND
	FrgbResult      TCOLORREF
	FlpCustColors   uintptr
	FFlags          TDWORD
	FlCustData      TLPARAM
	FlpfnHook       TLPCCHOOKPROC
	FlpTemplateName TLPCWSTR
}

type CHOOSECOLORW = TCHOOSECOLORW

type TtagCHOOSECOLORW = TCHOOSECOLORW

type tagCHOOSECOLORW = TtagCHOOSECOLORW

type TLPCHOOSECOLORW = uintptr

type LPCHOOSECOLORW = TLPCHOOSECOLORW

type TCHOOSECOLOR = struct {
	FlStructSize    TDWORD
	FhwndOwner      THWND
	FhInstance      THWND
	FrgbResult      TCOLORREF
	FlpCustColors   uintptr
	FFlags          TDWORD
	FlCustData      TLPARAM
	FlpfnHook       TLPCCHOOKPROC
	FlpTemplateName TLPCSTR
}

type CHOOSECOLOR = TCHOOSECOLOR

type TLPCHOOSECOLOR = uintptr

type LPCHOOSECOLOR = TLPCHOOSECOLOR

type TLPFRHOOKPROC = uintptr

type LPFRHOOKPROC = TLPFRHOOKPROC

type TFINDREPLACEA = struct {
	FlStructSize      TDWORD
	FhwndOwner        THWND
	FhInstance        THINSTANCE
	FFlags            TDWORD
	FlpstrFindWhat    TLPSTR
	FlpstrReplaceWith TLPSTR
	FwFindWhatLen     TWORD
	FwReplaceWithLen  TWORD
	FlCustData        TLPARAM
	FlpfnHook         TLPFRHOOKPROC
	FlpTemplateName   TLPCSTR
}

type FINDREPLACEA = TFINDREPLACEA

type TtagFINDREPLACEA = TFINDREPLACEA

type tagFINDREPLACEA = TtagFINDREPLACEA

type TLPFINDREPLACEA = uintptr

type LPFINDREPLACEA = TLPFINDREPLACEA

type TFINDREPLACEW = struct {
	FlStructSize      TDWORD
	FhwndOwner        THWND
	FhInstance        THINSTANCE
	FFlags            TDWORD
	FlpstrFindWhat    TLPWSTR
	FlpstrReplaceWith TLPWSTR
	FwFindWhatLen     TWORD
	FwReplaceWithLen  TWORD
	FlCustData        TLPARAM
	FlpfnHook         TLPFRHOOKPROC
	FlpTemplateName   TLPCWSTR
}

type FINDREPLACEW = TFINDREPLACEW

type TtagFINDREPLACEW = TFINDREPLACEW

type tagFINDREPLACEW = TtagFINDREPLACEW

type TLPFINDREPLACEW = uintptr

type LPFINDREPLACEW = TLPFINDREPLACEW

type TFINDREPLACE = struct {
	FlStructSize      TDWORD
	FhwndOwner        THWND
	FhInstance        THINSTANCE
	FFlags            TDWORD
	FlpstrFindWhat    TLPSTR
	FlpstrReplaceWith TLPSTR
	FwFindWhatLen     TWORD
	FwReplaceWithLen  TWORD
	FlCustData        TLPARAM
	FlpfnHook         TLPFRHOOKPROC
	FlpTemplateName   TLPCSTR
}

type FINDREPLACE = TFINDREPLACE

type TLPFINDREPLACE = uintptr

type LPFINDREPLACE = TLPFINDREPLACE

type TLPCFHOOKPROC = uintptr

type LPCFHOOKPROC = TLPCFHOOKPROC

type TCHOOSEFONTA = struct {
	FlStructSize            TDWORD
	FhwndOwner              THWND
	FhDC                    THDC
	FlpLogFont              TLPLOGFONTA
	FiPointSize             TINT
	FFlags                  TDWORD
	FrgbColors              TCOLORREF
	FlCustData              TLPARAM
	FlpfnHook               TLPCFHOOKPROC
	FlpTemplateName         TLPCSTR
	FhInstance              THINSTANCE
	FlpszStyle              TLPSTR
	FnFontType              TWORD
	F___MISSING_ALIGNMENT__ TWORD
	FnSizeMin               TINT
	FnSizeMax               TINT
}

type CHOOSEFONTA = TCHOOSEFONTA

type TtagCHOOSEFONTA = TCHOOSEFONTA

type tagCHOOSEFONTA = TtagCHOOSEFONTA

type TLPCHOOSEFONTA = uintptr

type LPCHOOSEFONTA = TLPCHOOSEFONTA

type TCHOOSEFONTW = struct {
	FlStructSize            TDWORD
	FhwndOwner              THWND
	FhDC                    THDC
	FlpLogFont              TLPLOGFONTW
	FiPointSize             TINT
	FFlags                  TDWORD
	FrgbColors              TCOLORREF
	FlCustData              TLPARAM
	FlpfnHook               TLPCFHOOKPROC
	FlpTemplateName         TLPCWSTR
	FhInstance              THINSTANCE
	FlpszStyle              TLPWSTR
	FnFontType              TWORD
	F___MISSING_ALIGNMENT__ TWORD
	FnSizeMin               TINT
	FnSizeMax               TINT
}

type CHOOSEFONTW = TCHOOSEFONTW

type TtagCHOOSEFONTW = TCHOOSEFONTW

type tagCHOOSEFONTW = TtagCHOOSEFONTW

type TLPCHOOSEFONTW = uintptr

type LPCHOOSEFONTW = TLPCHOOSEFONTW

type TCHOOSEFONT = struct {
	FlStructSize            TDWORD
	FhwndOwner              THWND
	FhDC                    THDC
	FlpLogFont              TLPLOGFONTA
	FiPointSize             TINT
	FFlags                  TDWORD
	FrgbColors              TCOLORREF
	FlCustData              TLPARAM
	FlpfnHook               TLPCFHOOKPROC
	FlpTemplateName         TLPCSTR
	FhInstance              THINSTANCE
	FlpszStyle              TLPSTR
	FnFontType              TWORD
	F___MISSING_ALIGNMENT__ TWORD
	FnSizeMin               TINT
	FnSizeMax               TINT
}

type CHOOSEFONT = TCHOOSEFONT

type TLPCHOOSEFONT = uintptr

type LPCHOOSEFONT = TLPCHOOSEFONT

type TLPPRINTHOOKPROC = uintptr

type LPPRINTHOOKPROC = TLPPRINTHOOKPROC

type TLPSETUPHOOKPROC = uintptr

type LPSETUPHOOKPROC = TLPSETUPHOOKPROC

type TPRINTDLGA = struct {
	FlStructSize         TDWORD
	FhwndOwner           THWND
	FhDevMode            THGLOBAL
	FhDevNames           THGLOBAL
	FhDC                 THDC
	FFlags               TDWORD
	FnFromPage           TWORD
	FnToPage             TWORD
	FnMinPage            TWORD
	FnMaxPage            TWORD
	FnCopies             TWORD
	FhInstance           THINSTANCE
	FlCustData           TLPARAM
	FlpfnPrintHook       TLPPRINTHOOKPROC
	FlpfnSetupHook       TLPSETUPHOOKPROC
	FlpPrintTemplateName TLPCSTR
	FlpSetupTemplateName TLPCSTR
	FhPrintTemplate      THGLOBAL
	FhSetupTemplate      THGLOBAL
}

type PRINTDLGA = TPRINTDLGA

type TtagPDA = TPRINTDLGA

type tagPDA = TtagPDA

type TLPPRINTDLGA = uintptr

type LPPRINTDLGA = TLPPRINTDLGA

type TPRINTDLGW = struct {
	FlStructSize         TDWORD
	FhwndOwner           THWND
	FhDevMode            THGLOBAL
	FhDevNames           THGLOBAL
	FhDC                 THDC
	FFlags               TDWORD
	FnFromPage           TWORD
	FnToPage             TWORD
	FnMinPage            TWORD
	FnMaxPage            TWORD
	FnCopies             TWORD
	FhInstance           THINSTANCE
	FlCustData           TLPARAM
	FlpfnPrintHook       TLPPRINTHOOKPROC
	FlpfnSetupHook       TLPSETUPHOOKPROC
	FlpPrintTemplateName TLPCWSTR
	FlpSetupTemplateName TLPCWSTR
	FhPrintTemplate      THGLOBAL
	FhSetupTemplate      THGLOBAL
}

type PRINTDLGW = TPRINTDLGW

type TtagPDW = TPRINTDLGW

type tagPDW = TtagPDW

type TLPPRINTDLGW = uintptr

type LPPRINTDLGW = TLPPRINTDLGW

type TPRINTDLG = struct {
	FlStructSize         TDWORD
	FhwndOwner           THWND
	FhDevMode            THGLOBAL
	FhDevNames           THGLOBAL
	FhDC                 THDC
	FFlags               TDWORD
	FnFromPage           TWORD
	FnToPage             TWORD
	FnMinPage            TWORD
	FnMaxPage            TWORD
	FnCopies             TWORD
	FhInstance           THINSTANCE
	FlCustData           TLPARAM
	FlpfnPrintHook       TLPPRINTHOOKPROC
	FlpfnSetupHook       TLPSETUPHOOKPROC
	FlpPrintTemplateName TLPCSTR
	FlpSetupTemplateName TLPCSTR
	FhPrintTemplate      THGLOBAL
	FhSetupTemplate      THGLOBAL
}

type PRINTDLG = TPRINTDLG

type TLPPRINTDLG = uintptr

type LPPRINTDLG = TLPPRINTDLG

type TIPrintDialogCallback = struct {
	FlpVtbl uintptr
}

type IPrintDialogCallback = TIPrintDialogCallback

type TIPrintDialogCallbackVtbl = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FInitDone        uintptr
	FSelectionChange uintptr
	FHandleMessage   uintptr
}

type IPrintDialogCallbackVtbl = TIPrintDialogCallbackVtbl

type TIPrintDialogCallbackVtbl1 = struct {
	FQueryInterface  uintptr
	FAddRef          uintptr
	FRelease         uintptr
	FInitDone        uintptr
	FSelectionChange uintptr
	FHandleMessage   uintptr
}

type IPrintDialogCallbackVtbl1 = TIPrintDialogCallbackVtbl1

type TIPrintDialogServices = struct {
	FlpVtbl uintptr
}

type IPrintDialogServices = TIPrintDialogServices

type TIPrintDialogServicesVtbl = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetCurrentDevMode     uintptr
	FGetCurrentPrinterName uintptr
	FGetCurrentPortName    uintptr
}

type IPrintDialogServicesVtbl = TIPrintDialogServicesVtbl

type TIPrintDialogServicesVtbl1 = struct {
	FQueryInterface        uintptr
	FAddRef                uintptr
	FRelease               uintptr
	FGetCurrentDevMode     uintptr
	FGetCurrentPrinterName uintptr
	FGetCurrentPortName    uintptr
}

type IPrintDialogServicesVtbl1 = TIPrintDialogServicesVtbl1

type TPRINTPAGERANGE = struct {
	FnFromPage TDWORD
	FnToPage   TDWORD
}

type PRINTPAGERANGE = TPRINTPAGERANGE

type TtagPRINTPAGERANGE = TPRINTPAGERANGE

type tagPRINTPAGERANGE = TtagPRINTPAGERANGE

type TLPPRINTPAGERANGE = uintptr

type LPPRINTPAGERANGE = TLPPRINTPAGERANGE

type TPRINTDLGEXA = struct {
	FlStructSize         TDWORD
	FhwndOwner           THWND
	FhDevMode            THGLOBAL
	FhDevNames           THGLOBAL
	FhDC                 THDC
	FFlags               TDWORD
	FFlags2              TDWORD
	FExclusionFlags      TDWORD
	FnPageRanges         TDWORD
	FnMaxPageRanges      TDWORD
	FlpPageRanges        TLPPRINTPAGERANGE
	FnMinPage            TDWORD
	FnMaxPage            TDWORD
	FnCopies             TDWORD
	FhInstance           THINSTANCE
	FlpPrintTemplateName TLPCSTR
	FlpCallback          TLPUNKNOWN
	FnPropertyPages      TDWORD
	FlphPropertyPages    uintptr
	FnStartPage          TDWORD
	FdwResultAction      TDWORD
}

type PRINTDLGEXA = TPRINTDLGEXA

type TtagPDEXA = TPRINTDLGEXA

type tagPDEXA = TtagPDEXA

type TLPPRINTDLGEXA = uintptr

type LPPRINTDLGEXA = TLPPRINTDLGEXA

type TPRINTDLGEXW = struct {
	FlStructSize         TDWORD
	FhwndOwner           THWND
	FhDevMode            THGLOBAL
	FhDevNames           THGLOBAL
	FhDC                 THDC
	FFlags               TDWORD
	FFlags2              TDWORD
	FExclusionFlags      TDWORD
	FnPageRanges         TDWORD
	FnMaxPageRanges      TDWORD
	FlpPageRanges        TLPPRINTPAGERANGE
	FnMinPage            TDWORD
	FnMaxPage            TDWORD
	FnCopies             TDWORD
	FhInstance           THINSTANCE
	FlpPrintTemplateName TLPCWSTR
	FlpCallback          TLPUNKNOWN
	FnPropertyPages      TDWORD
	FlphPropertyPages    uintptr
	FnStartPage          TDWORD
	FdwResultAction      TDWORD
}

type PRINTDLGEXW = TPRINTDLGEXW

type TtagPDEXW = TPRINTDLGEXW

type tagPDEXW = TtagPDEXW

type TLPPRINTDLGEXW = uintptr

type LPPRINTDLGEXW = TLPPRINTDLGEXW

type TPRINTDLGEX = struct {
	FlStructSize         TDWORD
	FhwndOwner           THWND
	FhDevMode            THGLOBAL
	FhDevNames           THGLOBAL
	FhDC                 THDC
	FFlags               TDWORD
	FFlags2              TDWORD
	FExclusionFlags      TDWORD
	FnPageRanges         TDWORD
	FnMaxPageRanges      TDWORD
	FlpPageRanges        TLPPRINTPAGERANGE
	FnMinPage            TDWORD
	FnMaxPage            TDWORD
	FnCopies             TDWORD
	FhInstance           THINSTANCE
	FlpPrintTemplateName TLPCSTR
	FlpCallback          TLPUNKNOWN
	FnPropertyPages      TDWORD
	FlphPropertyPages    uintptr
	FnStartPage          TDWORD
	FdwResultAction      TDWORD
}

type PRINTDLGEX = TPRINTDLGEX

type TLPPRINTDLGEX = uintptr

type LPPRINTDLGEX = TLPPRINTDLGEX

type TDEVNAMES = struct {
	FwDriverOffset TWORD
	FwDeviceOffset TWORD
	FwOutputOffset TWORD
	FwDefault      TWORD
}

type DEVNAMES = TDEVNAMES

type TtagDEVNAMES = TDEVNAMES

type tagDEVNAMES = TtagDEVNAMES

type TLPDEVNAMES = uintptr

type LPDEVNAMES = TLPDEVNAMES

type TLPPAGEPAINTHOOK = uintptr

type LPPAGEPAINTHOOK = TLPPAGEPAINTHOOK

type TLPPAGESETUPHOOK = uintptr

type LPPAGESETUPHOOK = TLPPAGESETUPHOOK

type TPAGESETUPDLGA = struct {
	FlStructSize             TDWORD
	FhwndOwner               THWND
	FhDevMode                THGLOBAL
	FhDevNames               THGLOBAL
	FFlags                   TDWORD
	FptPaperSize             TPOINT
	FrtMinMargin             TRECT
	FrtMargin                TRECT
	FhInstance               THINSTANCE
	FlCustData               TLPARAM
	FlpfnPageSetupHook       TLPPAGESETUPHOOK
	FlpfnPagePaintHook       TLPPAGEPAINTHOOK
	FlpPageSetupTemplateName TLPCSTR
	FhPageSetupTemplate      THGLOBAL
}

type PAGESETUPDLGA = TPAGESETUPDLGA

type TtagPSDA = TPAGESETUPDLGA

type tagPSDA = TtagPSDA

type TLPPAGESETUPDLGA = uintptr

type LPPAGESETUPDLGA = TLPPAGESETUPDLGA

type TPAGESETUPDLGW = struct {
	FlStructSize             TDWORD
	FhwndOwner               THWND
	FhDevMode                THGLOBAL
	FhDevNames               THGLOBAL
	FFlags                   TDWORD
	FptPaperSize             TPOINT
	FrtMinMargin             TRECT
	FrtMargin                TRECT
	FhInstance               THINSTANCE
	FlCustData               TLPARAM
	FlpfnPageSetupHook       TLPPAGESETUPHOOK
	FlpfnPagePaintHook       TLPPAGEPAINTHOOK
	FlpPageSetupTemplateName TLPCWSTR
	FhPageSetupTemplate      THGLOBAL
}

type PAGESETUPDLGW = TPAGESETUPDLGW

type TtagPSDW = TPAGESETUPDLGW

type tagPSDW = TtagPSDW

type TLPPAGESETUPDLGW = uintptr

type LPPAGESETUPDLGW = TLPPAGESETUPDLGW

type TPAGESETUPDLG = struct {
	FlStructSize             TDWORD
	FhwndOwner               THWND
	FhDevMode                THGLOBAL
	FhDevNames               THGLOBAL
	FFlags                   TDWORD
	FptPaperSize             TPOINT
	FrtMinMargin             TRECT
	FrtMargin                TRECT
	FhInstance               THINSTANCE
	FlCustData               TLPARAM
	FlpfnPageSetupHook       TLPPAGESETUPHOOK
	FlpfnPagePaintHook       TLPPAGEPAINTHOOK
	FlpPageSetupTemplateName TLPCSTR
	FhPageSetupTemplate      THGLOBAL
}

type PAGESETUPDLG = TPAGESETUPDLG

type TLPPAGESETUPDLG = uintptr

type LPPAGESETUPDLG = TLPPAGESETUPDLG

type TSERVICE_DESCRIPTIONA = struct {
	FlpDescription TLPSTR
}

type SERVICE_DESCRIPTIONA = TSERVICE_DESCRIPTIONA

type T_SERVICE_DESCRIPTIONA = TSERVICE_DESCRIPTIONA

type _SERVICE_DESCRIPTIONA = T_SERVICE_DESCRIPTIONA

type TLPSERVICE_DESCRIPTIONA = uintptr

type LPSERVICE_DESCRIPTIONA = TLPSERVICE_DESCRIPTIONA

type TSERVICE_DESCRIPTIONW = struct {
	FlpDescription TLPWSTR
}

type SERVICE_DESCRIPTIONW = TSERVICE_DESCRIPTIONW

type T_SERVICE_DESCRIPTIONW = TSERVICE_DESCRIPTIONW

type _SERVICE_DESCRIPTIONW = T_SERVICE_DESCRIPTIONW

type TLPSERVICE_DESCRIPTIONW = uintptr

type LPSERVICE_DESCRIPTIONW = TLPSERVICE_DESCRIPTIONW

type TSERVICE_DESCRIPTION = struct {
	FlpDescription TLPSTR
}

type SERVICE_DESCRIPTION = TSERVICE_DESCRIPTION

type TLPSERVICE_DESCRIPTION = uintptr

type LPSERVICE_DESCRIPTION = TLPSERVICE_DESCRIPTION

type TSC_ACTION_TYPE = int32

type SC_ACTION_TYPE = TSC_ACTION_TYPE

type __SC_ACTION_TYPE = int32

const _SC_ACTION_NONE = 0
const _SC_ACTION_RESTART = 1
const _SC_ACTION_REBOOT = 2
const _SC_ACTION_RUN_COMMAND = 3

type TSC_ACTION = struct {
	FType  TSC_ACTION_TYPE
	FDelay TDWORD
}

type SC_ACTION = TSC_ACTION

type T_SC_ACTION = TSC_ACTION

type _SC_ACTION = T_SC_ACTION

type TLPSC_ACTION = uintptr

type LPSC_ACTION = TLPSC_ACTION

type TSERVICE_FAILURE_ACTIONSA = struct {
	FdwResetPeriod TDWORD
	FlpRebootMsg   TLPSTR
	FlpCommand     TLPSTR
	FcActions      TDWORD
	FlpsaActions   uintptr
}

type SERVICE_FAILURE_ACTIONSA = TSERVICE_FAILURE_ACTIONSA

type T_SERVICE_FAILURE_ACTIONSA = TSERVICE_FAILURE_ACTIONSA

type _SERVICE_FAILURE_ACTIONSA = T_SERVICE_FAILURE_ACTIONSA

type TLPSERVICE_FAILURE_ACTIONSA = uintptr

type LPSERVICE_FAILURE_ACTIONSA = TLPSERVICE_FAILURE_ACTIONSA

type TSERVICE_FAILURE_ACTIONSW = struct {
	FdwResetPeriod TDWORD
	FlpRebootMsg   TLPWSTR
	FlpCommand     TLPWSTR
	FcActions      TDWORD
	FlpsaActions   uintptr
}

type SERVICE_FAILURE_ACTIONSW = TSERVICE_FAILURE_ACTIONSW

type T_SERVICE_FAILURE_ACTIONSW = TSERVICE_FAILURE_ACTIONSW

type _SERVICE_FAILURE_ACTIONSW = T_SERVICE_FAILURE_ACTIONSW

type TLPSERVICE_FAILURE_ACTIONSW = uintptr

type LPSERVICE_FAILURE_ACTIONSW = TLPSERVICE_FAILURE_ACTIONSW

type TSERVICE_FAILURE_ACTIONS = struct {
	FdwResetPeriod TDWORD
	FlpRebootMsg   TLPSTR
	FlpCommand     TLPSTR
	FcActions      TDWORD
	FlpsaActions   uintptr
}

type SERVICE_FAILURE_ACTIONS = TSERVICE_FAILURE_ACTIONS

type TLPSERVICE_FAILURE_ACTIONS = uintptr

type LPSERVICE_FAILURE_ACTIONS = TLPSERVICE_FAILURE_ACTIONS

type TSC_HANDLE__ = struct {
	Funused int32
}

type SC_HANDLE__ = TSC_HANDLE__

type TSC_HANDLE = uintptr

type SC_HANDLE = TSC_HANDLE

type TLPSC_HANDLE = uintptr

type LPSC_HANDLE = TLPSC_HANDLE

type TSERVICE_STATUS_HANDLE__ = struct {
	Funused int32
}

type SERVICE_STATUS_HANDLE__ = TSERVICE_STATUS_HANDLE__

type TSERVICE_STATUS_HANDLE = uintptr

type SERVICE_STATUS_HANDLE = TSERVICE_STATUS_HANDLE

type TSC_STATUS_TYPE = int32

type SC_STATUS_TYPE = TSC_STATUS_TYPE

type __SC_STATUS_TYPE = int32

const _SC_STATUS_PROCESS_INFO = 0

type TSC_ENUM_TYPE = int32

type SC_ENUM_TYPE = TSC_ENUM_TYPE

type __SC_ENUM_TYPE = int32

const _SC_ENUM_PROCESS_INFO = 0

type TSERVICE_STATUS = struct {
	FdwServiceType             TDWORD
	FdwCurrentState            TDWORD
	FdwControlsAccepted        TDWORD
	FdwWin32ExitCode           TDWORD
	FdwServiceSpecificExitCode TDWORD
	FdwCheckPoint              TDWORD
	FdwWaitHint                TDWORD
}

type SERVICE_STATUS = TSERVICE_STATUS

type T_SERVICE_STATUS = TSERVICE_STATUS

type _SERVICE_STATUS = T_SERVICE_STATUS

type TLPSERVICE_STATUS = uintptr

type LPSERVICE_STATUS = TLPSERVICE_STATUS

type TSERVICE_STATUS_PROCESS = struct {
	FdwServiceType             TDWORD
	FdwCurrentState            TDWORD
	FdwControlsAccepted        TDWORD
	FdwWin32ExitCode           TDWORD
	FdwServiceSpecificExitCode TDWORD
	FdwCheckPoint              TDWORD
	FdwWaitHint                TDWORD
	FdwProcessId               TDWORD
	FdwServiceFlags            TDWORD
}

type SERVICE_STATUS_PROCESS = TSERVICE_STATUS_PROCESS

type T_SERVICE_STATUS_PROCESS = TSERVICE_STATUS_PROCESS

type _SERVICE_STATUS_PROCESS = T_SERVICE_STATUS_PROCESS

type TLPSERVICE_STATUS_PROCESS = uintptr

type LPSERVICE_STATUS_PROCESS = TLPSERVICE_STATUS_PROCESS

type TENUM_SERVICE_STATUSA = struct {
	FlpServiceName TLPSTR
	FlpDisplayName TLPSTR
	FServiceStatus TSERVICE_STATUS
}

type ENUM_SERVICE_STATUSA = TENUM_SERVICE_STATUSA

type T_ENUM_SERVICE_STATUSA = TENUM_SERVICE_STATUSA

type _ENUM_SERVICE_STATUSA = T_ENUM_SERVICE_STATUSA

type TLPENUM_SERVICE_STATUSA = uintptr

type LPENUM_SERVICE_STATUSA = TLPENUM_SERVICE_STATUSA

type TENUM_SERVICE_STATUSW = struct {
	FlpServiceName TLPWSTR
	FlpDisplayName TLPWSTR
	FServiceStatus TSERVICE_STATUS
}

type ENUM_SERVICE_STATUSW = TENUM_SERVICE_STATUSW

type T_ENUM_SERVICE_STATUSW = TENUM_SERVICE_STATUSW

type _ENUM_SERVICE_STATUSW = T_ENUM_SERVICE_STATUSW

type TLPENUM_SERVICE_STATUSW = uintptr

type LPENUM_SERVICE_STATUSW = TLPENUM_SERVICE_STATUSW

type TENUM_SERVICE_STATUS = struct {
	FlpServiceName TLPSTR
	FlpDisplayName TLPSTR
	FServiceStatus TSERVICE_STATUS
}

type ENUM_SERVICE_STATUS = TENUM_SERVICE_STATUS

type TLPENUM_SERVICE_STATUS = uintptr

type LPENUM_SERVICE_STATUS = TLPENUM_SERVICE_STATUS

type TENUM_SERVICE_STATUS_PROCESSA = struct {
	FlpServiceName        TLPSTR
	FlpDisplayName        TLPSTR
	FServiceStatusProcess TSERVICE_STATUS_PROCESS
}

type ENUM_SERVICE_STATUS_PROCESSA = TENUM_SERVICE_STATUS_PROCESSA

type T_ENUM_SERVICE_STATUS_PROCESSA = TENUM_SERVICE_STATUS_PROCESSA

type _ENUM_SERVICE_STATUS_PROCESSA = T_ENUM_SERVICE_STATUS_PROCESSA

type TLPENUM_SERVICE_STATUS_PROCESSA = uintptr

type LPENUM_SERVICE_STATUS_PROCESSA = TLPENUM_SERVICE_STATUS_PROCESSA

type TENUM_SERVICE_STATUS_PROCESSW = struct {
	FlpServiceName        TLPWSTR
	FlpDisplayName        TLPWSTR
	FServiceStatusProcess TSERVICE_STATUS_PROCESS
}

type ENUM_SERVICE_STATUS_PROCESSW = TENUM_SERVICE_STATUS_PROCESSW

type T_ENUM_SERVICE_STATUS_PROCESSW = TENUM_SERVICE_STATUS_PROCESSW

type _ENUM_SERVICE_STATUS_PROCESSW = T_ENUM_SERVICE_STATUS_PROCESSW

type TLPENUM_SERVICE_STATUS_PROCESSW = uintptr

type LPENUM_SERVICE_STATUS_PROCESSW = TLPENUM_SERVICE_STATUS_PROCESSW

type TENUM_SERVICE_STATUS_PROCESS = struct {
	FlpServiceName        TLPSTR
	FlpDisplayName        TLPSTR
	FServiceStatusProcess TSERVICE_STATUS_PROCESS
}

type ENUM_SERVICE_STATUS_PROCESS = TENUM_SERVICE_STATUS_PROCESS

type TLPENUM_SERVICE_STATUS_PROCESS = uintptr

type LPENUM_SERVICE_STATUS_PROCESS = TLPENUM_SERVICE_STATUS_PROCESS

type TSC_LOCK = uintptr

type SC_LOCK = TSC_LOCK

type TQUERY_SERVICE_LOCK_STATUSA = struct {
	FfIsLocked      TDWORD
	FlpLockOwner    TLPSTR
	FdwLockDuration TDWORD
}

type QUERY_SERVICE_LOCK_STATUSA = TQUERY_SERVICE_LOCK_STATUSA

type T_QUERY_SERVICE_LOCK_STATUSA = TQUERY_SERVICE_LOCK_STATUSA

type _QUERY_SERVICE_LOCK_STATUSA = T_QUERY_SERVICE_LOCK_STATUSA

type TLPQUERY_SERVICE_LOCK_STATUSA = uintptr

type LPQUERY_SERVICE_LOCK_STATUSA = TLPQUERY_SERVICE_LOCK_STATUSA

type TQUERY_SERVICE_LOCK_STATUSW = struct {
	FfIsLocked      TDWORD
	FlpLockOwner    TLPWSTR
	FdwLockDuration TDWORD
}

type QUERY_SERVICE_LOCK_STATUSW = TQUERY_SERVICE_LOCK_STATUSW

type T_QUERY_SERVICE_LOCK_STATUSW = TQUERY_SERVICE_LOCK_STATUSW

type _QUERY_SERVICE_LOCK_STATUSW = T_QUERY_SERVICE_LOCK_STATUSW

type TLPQUERY_SERVICE_LOCK_STATUSW = uintptr

type LPQUERY_SERVICE_LOCK_STATUSW = TLPQUERY_SERVICE_LOCK_STATUSW

type TQUERY_SERVICE_LOCK_STATUS = struct {
	FfIsLocked      TDWORD
	FlpLockOwner    TLPSTR
	FdwLockDuration TDWORD
}

type QUERY_SERVICE_LOCK_STATUS = TQUERY_SERVICE_LOCK_STATUS

type TLPQUERY_SERVICE_LOCK_STATUS = uintptr

type LPQUERY_SERVICE_LOCK_STATUS = TLPQUERY_SERVICE_LOCK_STATUS

type TQUERY_SERVICE_CONFIGA = struct {
	FdwServiceType      TDWORD
	FdwStartType        TDWORD
	FdwErrorControl     TDWORD
	FlpBinaryPathName   TLPSTR
	FlpLoadOrderGroup   TLPSTR
	FdwTagId            TDWORD
	FlpDependencies     TLPSTR
	FlpServiceStartName TLPSTR
	FlpDisplayName      TLPSTR
}

type QUERY_SERVICE_CONFIGA = TQUERY_SERVICE_CONFIGA

type T_QUERY_SERVICE_CONFIGA = TQUERY_SERVICE_CONFIGA

type _QUERY_SERVICE_CONFIGA = T_QUERY_SERVICE_CONFIGA

type TLPQUERY_SERVICE_CONFIGA = uintptr

type LPQUERY_SERVICE_CONFIGA = TLPQUERY_SERVICE_CONFIGA

type TQUERY_SERVICE_CONFIGW = struct {
	FdwServiceType      TDWORD
	FdwStartType        TDWORD
	FdwErrorControl     TDWORD
	FlpBinaryPathName   TLPWSTR
	FlpLoadOrderGroup   TLPWSTR
	FdwTagId            TDWORD
	FlpDependencies     TLPWSTR
	FlpServiceStartName TLPWSTR
	FlpDisplayName      TLPWSTR
}

type QUERY_SERVICE_CONFIGW = TQUERY_SERVICE_CONFIGW

type T_QUERY_SERVICE_CONFIGW = TQUERY_SERVICE_CONFIGW

type _QUERY_SERVICE_CONFIGW = T_QUERY_SERVICE_CONFIGW

type TLPQUERY_SERVICE_CONFIGW = uintptr

type LPQUERY_SERVICE_CONFIGW = TLPQUERY_SERVICE_CONFIGW

type TQUERY_SERVICE_CONFIG = struct {
	FdwServiceType      TDWORD
	FdwStartType        TDWORD
	FdwErrorControl     TDWORD
	FlpBinaryPathName   TLPSTR
	FlpLoadOrderGroup   TLPSTR
	FdwTagId            TDWORD
	FlpDependencies     TLPSTR
	FlpServiceStartName TLPSTR
	FlpDisplayName      TLPSTR
}

type QUERY_SERVICE_CONFIG = TQUERY_SERVICE_CONFIG

type TLPQUERY_SERVICE_CONFIG = uintptr

type LPQUERY_SERVICE_CONFIG = TLPQUERY_SERVICE_CONFIG

type TLPSERVICE_MAIN_FUNCTIONW = uintptr

type LPSERVICE_MAIN_FUNCTIONW = TLPSERVICE_MAIN_FUNCTIONW

type TLPSERVICE_MAIN_FUNCTIONA = uintptr

type LPSERVICE_MAIN_FUNCTIONA = TLPSERVICE_MAIN_FUNCTIONA

type TSERVICE_TABLE_ENTRYA = struct {
	FlpServiceName TLPSTR
	FlpServiceProc TLPSERVICE_MAIN_FUNCTIONA
}

type SERVICE_TABLE_ENTRYA = TSERVICE_TABLE_ENTRYA

type T_SERVICE_TABLE_ENTRYA = TSERVICE_TABLE_ENTRYA

type _SERVICE_TABLE_ENTRYA = T_SERVICE_TABLE_ENTRYA

type TLPSERVICE_TABLE_ENTRYA = uintptr

type LPSERVICE_TABLE_ENTRYA = TLPSERVICE_TABLE_ENTRYA

type TSERVICE_TABLE_ENTRYW = struct {
	FlpServiceName TLPWSTR
	FlpServiceProc TLPSERVICE_MAIN_FUNCTIONW
}

type SERVICE_TABLE_ENTRYW = TSERVICE_TABLE_ENTRYW

type T_SERVICE_TABLE_ENTRYW = TSERVICE_TABLE_ENTRYW

type _SERVICE_TABLE_ENTRYW = T_SERVICE_TABLE_ENTRYW

type TLPSERVICE_TABLE_ENTRYW = uintptr

type LPSERVICE_TABLE_ENTRYW = TLPSERVICE_TABLE_ENTRYW

type TSERVICE_TABLE_ENTRY = struct {
	FlpServiceName TLPSTR
	FlpServiceProc TLPSERVICE_MAIN_FUNCTIONA
}

type SERVICE_TABLE_ENTRY = TSERVICE_TABLE_ENTRY

type TLPSERVICE_TABLE_ENTRY = uintptr

type LPSERVICE_TABLE_ENTRY = TLPSERVICE_TABLE_ENTRY

type TLPHANDLER_FUNCTION = uintptr

type LPHANDLER_FUNCTION = TLPHANDLER_FUNCTION

type TLPHANDLER_FUNCTION_EX = uintptr

type LPHANDLER_FUNCTION_EX = TLPHANDLER_FUNCTION_EX

type TPFN_SC_NOTIFY_CALLBACK = uintptr

type PFN_SC_NOTIFY_CALLBACK = TPFN_SC_NOTIFY_CALLBACK

type TSERVICE_CONTROL_STATUS_REASON_PARAMSA = struct {
	FdwReason      TDWORD
	FpszComment    TLPSTR
	FServiceStatus TSERVICE_STATUS_PROCESS
}

type SERVICE_CONTROL_STATUS_REASON_PARAMSA = TSERVICE_CONTROL_STATUS_REASON_PARAMSA

type T_SERVICE_CONTROL_STATUS_REASON_PARAMSA = TSERVICE_CONTROL_STATUS_REASON_PARAMSA

type _SERVICE_CONTROL_STATUS_REASON_PARAMSA = T_SERVICE_CONTROL_STATUS_REASON_PARAMSA

type TPSERVICE_CONTROL_STATUS_REASON_PARAMSA = uintptr

type PSERVICE_CONTROL_STATUS_REASON_PARAMSA = TPSERVICE_CONTROL_STATUS_REASON_PARAMSA

type TSERVICE_CONTROL_STATUS_REASON_PARAMSW = struct {
	FdwReason      TDWORD
	FpszComment    TLPWSTR
	FServiceStatus TSERVICE_STATUS_PROCESS
}

type SERVICE_CONTROL_STATUS_REASON_PARAMSW = TSERVICE_CONTROL_STATUS_REASON_PARAMSW

type T_SERVICE_CONTROL_STATUS_REASON_PARAMSW = TSERVICE_CONTROL_STATUS_REASON_PARAMSW

type _SERVICE_CONTROL_STATUS_REASON_PARAMSW = T_SERVICE_CONTROL_STATUS_REASON_PARAMSW

type TPSERVICE_CONTROL_STATUS_REASON_PARAMSW = uintptr

type PSERVICE_CONTROL_STATUS_REASON_PARAMSW = TPSERVICE_CONTROL_STATUS_REASON_PARAMSW

type TSERVICE_CONTROL_STATUS_REASON_PARAMS = struct {
	FdwReason      TDWORD
	FpszComment    TLPSTR
	FServiceStatus TSERVICE_STATUS_PROCESS
}

type SERVICE_CONTROL_STATUS_REASON_PARAMS = TSERVICE_CONTROL_STATUS_REASON_PARAMS

type TPSERVICE_CONTROL_STATUS_REASON_PARAMS = uintptr

type PSERVICE_CONTROL_STATUS_REASON_PARAMS = TPSERVICE_CONTROL_STATUS_REASON_PARAMS

type TSERVICE_NOTIFYA = struct {
	FdwVersion               TDWORD
	FpfnNotifyCallback       TPFN_SC_NOTIFY_CALLBACK
	FpContext                TPVOID
	FdwNotificationStatus    TDWORD
	FServiceStatus           TSERVICE_STATUS_PROCESS
	FdwNotificationTriggered TDWORD
	FpszServiceNames         TLPSTR
}

type SERVICE_NOTIFYA = TSERVICE_NOTIFYA

type T_SERVICE_NOTIFYA = TSERVICE_NOTIFYA

type _SERVICE_NOTIFYA = T_SERVICE_NOTIFYA

type TPSERVICE_NOTIFYA = uintptr

type PSERVICE_NOTIFYA = TPSERVICE_NOTIFYA

type TSERVICE_NOTIFYW = struct {
	FdwVersion               TDWORD
	FpfnNotifyCallback       TPFN_SC_NOTIFY_CALLBACK
	FpContext                TPVOID
	FdwNotificationStatus    TDWORD
	FServiceStatus           TSERVICE_STATUS_PROCESS
	FdwNotificationTriggered TDWORD
	FpszServiceNames         TLPWSTR
}

type SERVICE_NOTIFYW = TSERVICE_NOTIFYW

type T_SERVICE_NOTIFYW = TSERVICE_NOTIFYW

type _SERVICE_NOTIFYW = T_SERVICE_NOTIFYW

type TPSERVICE_NOTIFYW = uintptr

type PSERVICE_NOTIFYW = TPSERVICE_NOTIFYW

type TSERVICE_NOTIFY = struct {
	FdwVersion               TDWORD
	FpfnNotifyCallback       TPFN_SC_NOTIFY_CALLBACK
	FpContext                TPVOID
	FdwNotificationStatus    TDWORD
	FServiceStatus           TSERVICE_STATUS_PROCESS
	FdwNotificationTriggered TDWORD
	FpszServiceNames         TLPSTR
}

type SERVICE_NOTIFY = TSERVICE_NOTIFY

type TPSERVICE_NOTIFY = uintptr

type PSERVICE_NOTIFY = TPSERVICE_NOTIFY

type TSERVICE_DELAYED_AUTO_START_INFO = struct {
	FfDelayedAutostart TWINBOOL
}

type SERVICE_DELAYED_AUTO_START_INFO = TSERVICE_DELAYED_AUTO_START_INFO

type T_SERVICE_DELAYED_AUTO_START_INFO = TSERVICE_DELAYED_AUTO_START_INFO

type _SERVICE_DELAYED_AUTO_START_INFO = T_SERVICE_DELAYED_AUTO_START_INFO

type TLPSERVICE_DELAYED_AUTO_START_INFO = uintptr

type LPSERVICE_DELAYED_AUTO_START_INFO = TLPSERVICE_DELAYED_AUTO_START_INFO

type TSERVICE_FAILURE_ACTIONS_FLAG = struct {
	FfFailureActionsOnNonCrashFailures TWINBOOL
}

type SERVICE_FAILURE_ACTIONS_FLAG = TSERVICE_FAILURE_ACTIONS_FLAG

type T_SERVICE_FAILURE_ACTIONS_FLAG = TSERVICE_FAILURE_ACTIONS_FLAG

type _SERVICE_FAILURE_ACTIONS_FLAG = T_SERVICE_FAILURE_ACTIONS_FLAG

type TLPSERVICE_FAILURE_ACTIONS_FLAG = uintptr

type LPSERVICE_FAILURE_ACTIONS_FLAG = TLPSERVICE_FAILURE_ACTIONS_FLAG

type TSERVICE_PRESHUTDOWN_INFO = struct {
	FdwPreshutdownTimeout TDWORD
}

type SERVICE_PRESHUTDOWN_INFO = TSERVICE_PRESHUTDOWN_INFO

type T_SERVICE_PRESHUTDOWN_INFO = TSERVICE_PRESHUTDOWN_INFO

type _SERVICE_PRESHUTDOWN_INFO = T_SERVICE_PRESHUTDOWN_INFO

type TLPSERVICE_PRESHUTDOWN_INFO = uintptr

type LPSERVICE_PRESHUTDOWN_INFO = TLPSERVICE_PRESHUTDOWN_INFO

type TSERVICE_REQUIRED_PRIVILEGES_INFOA = struct {
	FpmszRequiredPrivileges TLPSTR
}

type SERVICE_REQUIRED_PRIVILEGES_INFOA = TSERVICE_REQUIRED_PRIVILEGES_INFOA

type T_SERVICE_REQUIRED_PRIVILEGES_INFOA = TSERVICE_REQUIRED_PRIVILEGES_INFOA

type _SERVICE_REQUIRED_PRIVILEGES_INFOA = T_SERVICE_REQUIRED_PRIVILEGES_INFOA

type TLPSERVICE_REQUIRED_PRIVILEGES_INFOA = uintptr

type LPSERVICE_REQUIRED_PRIVILEGES_INFOA = TLPSERVICE_REQUIRED_PRIVILEGES_INFOA

type TSERVICE_REQUIRED_PRIVILEGES_INFOW = struct {
	FpmszRequiredPrivileges TLPWSTR
}

type SERVICE_REQUIRED_PRIVILEGES_INFOW = TSERVICE_REQUIRED_PRIVILEGES_INFOW

type T_SERVICE_REQUIRED_PRIVILEGES_INFOW = TSERVICE_REQUIRED_PRIVILEGES_INFOW

type _SERVICE_REQUIRED_PRIVILEGES_INFOW = T_SERVICE_REQUIRED_PRIVILEGES_INFOW

type TLPSERVICE_REQUIRED_PRIVILEGES_INFOW = uintptr

type LPSERVICE_REQUIRED_PRIVILEGES_INFOW = TLPSERVICE_REQUIRED_PRIVILEGES_INFOW

type TSERVICE_REQUIRED_PRIVILEGES_INFO = struct {
	FpmszRequiredPrivileges TLPSTR
}

type SERVICE_REQUIRED_PRIVILEGES_INFO = TSERVICE_REQUIRED_PRIVILEGES_INFO

type TSERVICE_SID_INFO = struct {
	FdwServiceSidType TDWORD
}

type SERVICE_SID_INFO = TSERVICE_SID_INFO

type T_SERVICE_SID_INFO = TSERVICE_SID_INFO

type _SERVICE_SID_INFO = T_SERVICE_SID_INFO

type TLPSERVICE_SID_INFO = uintptr

type LPSERVICE_SID_INFO = TLPSERVICE_SID_INFO

type TMODEMDEVCAPS = struct {
	FdwActualSize              TDWORD
	FdwRequiredSize            TDWORD
	FdwDevSpecificOffset       TDWORD
	FdwDevSpecificSize         TDWORD
	FdwModemProviderVersion    TDWORD
	FdwModemManufacturerOffset TDWORD
	FdwModemManufacturerSize   TDWORD
	FdwModemModelOffset        TDWORD
	FdwModemModelSize          TDWORD
	FdwModemVersionOffset      TDWORD
	FdwModemVersionSize        TDWORD
	FdwDialOptions             TDWORD
	FdwCallSetupFailTimer      TDWORD
	FdwInactivityTimeout       TDWORD
	FdwSpeakerVolume           TDWORD
	FdwSpeakerMode             TDWORD
	FdwModemOptions            TDWORD
	FdwMaxDTERate              TDWORD
	FdwMaxDCERate              TDWORD
	FabVariablePortion         [1]TBYTE
}

type MODEMDEVCAPS = TMODEMDEVCAPS

type T_MODEMDEVCAPS = TMODEMDEVCAPS

type _MODEMDEVCAPS = T_MODEMDEVCAPS

type TPMODEMDEVCAPS = uintptr

type PMODEMDEVCAPS = TPMODEMDEVCAPS

type TLPMODEMDEVCAPS = uintptr

type LPMODEMDEVCAPS = TLPMODEMDEVCAPS

type TMODEMSETTINGS = struct {
	FdwActualSize             TDWORD
	FdwRequiredSize           TDWORD
	FdwDevSpecificOffset      TDWORD
	FdwDevSpecificSize        TDWORD
	FdwCallSetupFailTimer     TDWORD
	FdwInactivityTimeout      TDWORD
	FdwSpeakerVolume          TDWORD
	FdwSpeakerMode            TDWORD
	FdwPreferredModemOptions  TDWORD
	FdwNegotiatedModemOptions TDWORD
	FdwNegotiatedDCERate      TDWORD
	FabVariablePortion        [1]TBYTE
}

type MODEMSETTINGS = TMODEMSETTINGS

type T_MODEMSETTINGS = TMODEMSETTINGS

type _MODEMSETTINGS = T_MODEMSETTINGS

type TPMODEMSETTINGS = uintptr

type PMODEMSETTINGS = TPMODEMSETTINGS

type TLPMODEMSETTINGS = uintptr

type LPMODEMSETTINGS = TLPMODEMSETTINGS

type THIMC__ = struct {
	Funused int32
}

type HIMC__ = THIMC__

type THIMC = uintptr

type HIMC = THIMC

type THIMCC__ = struct {
	Funused int32
}

type HIMCC__ = THIMCC__

type THIMCC = uintptr

type HIMCC = THIMCC

type TLPHKL = uintptr

type LPHKL = TLPHKL

type TCOMPOSITIONFORM = struct {
	FdwStyle      TDWORD
	FptCurrentPos TPOINT
	FrcArea       TRECT
}

type COMPOSITIONFORM = TCOMPOSITIONFORM

type TtagCOMPOSITIONFORM = TCOMPOSITIONFORM

type tagCOMPOSITIONFORM = TtagCOMPOSITIONFORM

type TPCOMPOSITIONFORM = uintptr

type PCOMPOSITIONFORM = TPCOMPOSITIONFORM

type TNPCOMPOSITIONFORM = uintptr

type NPCOMPOSITIONFORM = TNPCOMPOSITIONFORM

type TLPCOMPOSITIONFORM = uintptr

type LPCOMPOSITIONFORM = TLPCOMPOSITIONFORM

type TCANDIDATEFORM = struct {
	FdwIndex      TDWORD
	FdwStyle      TDWORD
	FptCurrentPos TPOINT
	FrcArea       TRECT
}

type CANDIDATEFORM = TCANDIDATEFORM

type TtagCANDIDATEFORM = TCANDIDATEFORM

type tagCANDIDATEFORM = TtagCANDIDATEFORM

type TPCANDIDATEFORM = uintptr

type PCANDIDATEFORM = TPCANDIDATEFORM

type TNPCANDIDATEFORM = uintptr

type NPCANDIDATEFORM = TNPCANDIDATEFORM

type TLPCANDIDATEFORM = uintptr

type LPCANDIDATEFORM = TLPCANDIDATEFORM

type TCANDIDATELIST = struct {
	FdwSize      TDWORD
	FdwStyle     TDWORD
	FdwCount     TDWORD
	FdwSelection TDWORD
	FdwPageStart TDWORD
	FdwPageSize  TDWORD
	FdwOffset    [1]TDWORD
}

type CANDIDATELIST = TCANDIDATELIST

type TtagCANDIDATELIST = TCANDIDATELIST

type tagCANDIDATELIST = TtagCANDIDATELIST

type TPCANDIDATELIST = uintptr

type PCANDIDATELIST = TPCANDIDATELIST

type TNPCANDIDATELIST = uintptr

type NPCANDIDATELIST = TNPCANDIDATELIST

type TLPCANDIDATELIST = uintptr

type LPCANDIDATELIST = TLPCANDIDATELIST

type TREGISTERWORDA = struct {
	FlpReading TLPSTR
	FlpWord    TLPSTR
}

type REGISTERWORDA = TREGISTERWORDA

type TtagREGISTERWORDA = TREGISTERWORDA

type tagREGISTERWORDA = TtagREGISTERWORDA

type TPREGISTERWORDA = uintptr

type PREGISTERWORDA = TPREGISTERWORDA

type TNPREGISTERWORDA = uintptr

type NPREGISTERWORDA = TNPREGISTERWORDA

type TLPREGISTERWORDA = uintptr

type LPREGISTERWORDA = TLPREGISTERWORDA

type TREGISTERWORDW = struct {
	FlpReading TLPWSTR
	FlpWord    TLPWSTR
}

type REGISTERWORDW = TREGISTERWORDW

type TtagREGISTERWORDW = TREGISTERWORDW

type tagREGISTERWORDW = TtagREGISTERWORDW

type TPREGISTERWORDW = uintptr

type PREGISTERWORDW = TPREGISTERWORDW

type TNPREGISTERWORDW = uintptr

type NPREGISTERWORDW = TNPREGISTERWORDW

type TLPREGISTERWORDW = uintptr

type LPREGISTERWORDW = TLPREGISTERWORDW

type TREGISTERWORD = struct {
	FlpReading TLPSTR
	FlpWord    TLPSTR
}

type REGISTERWORD = TREGISTERWORD

type TPREGISTERWORD = uintptr

type PREGISTERWORD = TPREGISTERWORD

type TNPREGISTERWORD = uintptr

type NPREGISTERWORD = TNPREGISTERWORD

type TLPREGISTERWORD = uintptr

type LPREGISTERWORD = TLPREGISTERWORD

type TRECONVERTSTRING = struct {
	FdwSize            TDWORD
	FdwVersion         TDWORD
	FdwStrLen          TDWORD
	FdwStrOffset       TDWORD
	FdwCompStrLen      TDWORD
	FdwCompStrOffset   TDWORD
	FdwTargetStrLen    TDWORD
	FdwTargetStrOffset TDWORD
}

type RECONVERTSTRING = TRECONVERTSTRING

type TtagRECONVERTSTRING = TRECONVERTSTRING

type tagRECONVERTSTRING = TtagRECONVERTSTRING

type TPRECONVERTSTRING = uintptr

type PRECONVERTSTRING = TPRECONVERTSTRING

type TNPRECONVERTSTRING = uintptr

type NPRECONVERTSTRING = TNPRECONVERTSTRING

type TLPRECONVERTSTRING = uintptr

type LPRECONVERTSTRING = TLPRECONVERTSTRING

type TSTYLEBUFA = struct {
	FdwStyle       TDWORD
	FszDescription [32]TCHAR
}

type STYLEBUFA = TSTYLEBUFA

type TtagSTYLEBUFA = TSTYLEBUFA

type tagSTYLEBUFA = TtagSTYLEBUFA

type TPSTYLEBUFA = uintptr

type PSTYLEBUFA = TPSTYLEBUFA

type TNPSTYLEBUFA = uintptr

type NPSTYLEBUFA = TNPSTYLEBUFA

type TLPSTYLEBUFA = uintptr

type LPSTYLEBUFA = TLPSTYLEBUFA

type TSTYLEBUFW = struct {
	FdwStyle       TDWORD
	FszDescription [32]TWCHAR
}

type STYLEBUFW = TSTYLEBUFW

type TtagSTYLEBUFW = TSTYLEBUFW

type tagSTYLEBUFW = TtagSTYLEBUFW

type TPSTYLEBUFW = uintptr

type PSTYLEBUFW = TPSTYLEBUFW

type TNPSTYLEBUFW = uintptr

type NPSTYLEBUFW = TNPSTYLEBUFW

type TLPSTYLEBUFW = uintptr

type LPSTYLEBUFW = TLPSTYLEBUFW

type TSTYLEBUF = struct {
	FdwStyle       TDWORD
	FszDescription [32]TCHAR
}

type STYLEBUF = TSTYLEBUF

type TPSTYLEBUF = uintptr

type PSTYLEBUF = TPSTYLEBUF

type TNPSTYLEBUF = uintptr

type NPSTYLEBUF = TNPSTYLEBUF

type TLPSTYLEBUF = uintptr

type LPSTYLEBUF = TLPSTYLEBUF

type TIMEMENUITEMINFOA = struct {
	FcbSize        TUINT
	FfType         TUINT
	FfState        TUINT
	FwID           TUINT
	FhbmpChecked   THBITMAP
	FhbmpUnchecked THBITMAP
	FdwItemData    TDWORD
	FszString      [80]TCHAR
	FhbmpItem      THBITMAP
}

type IMEMENUITEMINFOA = TIMEMENUITEMINFOA

type TtagIMEMENUITEMINFOA = TIMEMENUITEMINFOA

type tagIMEMENUITEMINFOA = TtagIMEMENUITEMINFOA

type TPIMEMENUITEMINFOA = uintptr

type PIMEMENUITEMINFOA = TPIMEMENUITEMINFOA

type TNPIMEMENUITEMINFOA = uintptr

type NPIMEMENUITEMINFOA = TNPIMEMENUITEMINFOA

type TLPIMEMENUITEMINFOA = uintptr

type LPIMEMENUITEMINFOA = TLPIMEMENUITEMINFOA

type TIMEMENUITEMINFOW = struct {
	FcbSize        TUINT
	FfType         TUINT
	FfState        TUINT
	FwID           TUINT
	FhbmpChecked   THBITMAP
	FhbmpUnchecked THBITMAP
	FdwItemData    TDWORD
	FszString      [80]TWCHAR
	FhbmpItem      THBITMAP
}

type IMEMENUITEMINFOW = TIMEMENUITEMINFOW

type TtagIMEMENUITEMINFOW = TIMEMENUITEMINFOW

type tagIMEMENUITEMINFOW = TtagIMEMENUITEMINFOW

type TPIMEMENUITEMINFOW = uintptr

type PIMEMENUITEMINFOW = TPIMEMENUITEMINFOW

type TNPIMEMENUITEMINFOW = uintptr

type NPIMEMENUITEMINFOW = TNPIMEMENUITEMINFOW

type TLPIMEMENUITEMINFOW = uintptr

type LPIMEMENUITEMINFOW = TLPIMEMENUITEMINFOW

type TIMEMENUITEMINFO = struct {
	FcbSize        TUINT
	FfType         TUINT
	FfState        TUINT
	FwID           TUINT
	FhbmpChecked   THBITMAP
	FhbmpUnchecked THBITMAP
	FdwItemData    TDWORD
	FszString      [80]TCHAR
	FhbmpItem      THBITMAP
}

type IMEMENUITEMINFO = TIMEMENUITEMINFO

type TPIMEMENUITEMINFO = uintptr

type PIMEMENUITEMINFO = TPIMEMENUITEMINFO

type TNPIMEMENUITEMINFO = uintptr

type NPIMEMENUITEMINFO = TNPIMEMENUITEMINFO

type TLPIMEMENUITEMINFO = uintptr

type LPIMEMENUITEMINFO = TLPIMEMENUITEMINFO

type TIMECHARPOSITION = struct {
	FdwSize      TDWORD
	FdwCharPos   TDWORD
	Fpt          TPOINT
	FcLineHeight TUINT
	FrcDocument  TRECT
}

type IMECHARPOSITION = TIMECHARPOSITION

type TtagIMECHARPOSITION = TIMECHARPOSITION

type tagIMECHARPOSITION = TtagIMECHARPOSITION

type TPIMECHARPOSITION = uintptr

type PIMECHARPOSITION = TPIMECHARPOSITION

type TNPIMECHARPOSITION = uintptr

type NPIMECHARPOSITION = TNPIMECHARPOSITION

type TLPIMECHARPOSITION = uintptr

type LPIMECHARPOSITION = TLPIMECHARPOSITION

type TIMCENUMPROC = uintptr

type IMCENUMPROC = TIMCENUMPROC

type TREGISTERWORDENUMPROCA = uintptr

type REGISTERWORDENUMPROCA = TREGISTERWORDENUMPROCA

type TREGISTERWORDENUMPROCW = uintptr

type REGISTERWORDENUMPROCW = TREGISTERWORDENUMPROCW

/* Restore old value of interface for Obj-C.  See above.  */

/*
** Determine if we are dealing with Windows NT.
**
** We ought to be able to determine if we are compiling for Windows 9x or
** Windows NT using the _WIN32_WINNT macro as follows:
**
** #if defined(_WIN32_WINNT)
** # define SQLITE_OS_WINNT 1
** #else
** # define SQLITE_OS_WINNT 0
** #endif
**
** However, Visual Studio 2005 does not set _WIN32_WINNT by default, as
** it ought to, so the above test does not work.  We'll just assume that
** everything is Windows NT unless the programmer explicitly says otherwise
** by setting SQLITE_OS_WINNT to 0.
 */

/*
** Determine if we are dealing with Windows CE - which has a much reduced
** API.
 */

/*
** Determine if we are dealing with WinRT, which provides only a subset of
** the full Win32 API.
 */

/*
** For WinCE, some API function parameters do not appear to be declared as
** volatile.
 */

/*
** For some Windows sub-platforms, the _beginthreadex() / _endthreadex()
** functions are not available (e.g. those not using MSVC, Cygwin, etc).
 */

/************** End of os_win.h **********************************************/
/************** Continuing where we left off in mutex_w32.c ******************/

/*
** The code in this file is only used if we are compiling multithreaded
** on a Win32 system.
 */

/*
** Each recursive mutex is an instance of the following structure.
 */
type Tsqlite3_mutex1 = struct {
	Fmutex TCRITICAL_SECTION
	Fid    int32
}

type sqlite3_mutex1 = Tsqlite3_mutex1

/*
** These are the initializer values used when declaring a "static" mutex
** on Win32.  It should be noted that all mutexes require initialization
** on the Win32 platform.
 */

// C documentation
//
//	/*
//	** Try to provide a memory barrier operation, needed for initialization
//	** and also for the xShmBarrier method of the VFS in cases when SQLite is
//	** compiled without mutexes (SQLITE_THREADSAFE=0).
//	*/
func _sqlite3MemoryBarrier(tls *libc.TLS) {
	libc.X__sync_synchronize(tls)
}

// C documentation
//
//	/*
//	** Initialize and deinitialize the mutex subsystem.
//	*/
var _winMutex_staticMutexes = [12]Tsqlite3_mutex{
	0: {
		Fid: int32(2),
	},
	1: {
		Fid: int32(3),
	},
	2: {
		Fid: int32(4),
	},
	3: {
		Fid: int32(5),
	},
	4: {
		Fid: int32(6),
	},
	5: {
		Fid: int32(7),
	},
	6: {
		Fid: int32(8),
	},
	7: {
		Fid: int32(9),
	},
	8: {
		Fid: int32(10),
	},
	9: {
		Fid: int32(11),
	},
	10: {
		Fid: int32(12),
	},
	11: {
		Fid: int32(13),
	},
}

var _winMutex_isInit = int32(0)
var _winMutex_isNt = -int32(1)

// C documentation
//
//	/* As the winMutexInit() and winMutexEnd() functions are called as part
//	** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
//	** "interlocked" magic used here is probably not strictly necessary.
//	*/
var _winMutex_lock = int32(0)

func _winMutexInit(tls *libc.TLS) (r int32) {
	var i int32
	_ = i
	/* The first to increment to 1 does actual initialization */
	if libc.X_InterlockedCompareExchange(tls, uintptr(unsafe.Pointer(&_winMutex_lock)), int32(1), 0) == 0 {
		i = 0
		for {
			if !(i < int32(libc.Uint32FromInt64(336)/libc.Uint32FromInt64(28))) {
				break
			}
			libc.XInitializeCriticalSection(tls, uintptr(unsafe.Pointer(&_winMutex_staticMutexes))+uintptr(i)*28)
			goto _1
		_1:
			;
			i++
		}
		_winMutex_isInit = int32(1)
	} else {
		/* Another thread is (in the process of) initializing the static
		 ** mutexes */
		for !(_winMutex_isInit != 0) {
			Xsqlite3_win32_sleep(tls, uint32(1))
		}
	}
	return SQLITE_OK
}

func _winMutexEnd(tls *libc.TLS) (r int32) {
	var i int32
	_ = i
	/* The first to decrement to 0 does actual shutdown
	 ** (which should be the last to shutdown.) */
	if libc.X_InterlockedCompareExchange(tls, uintptr(unsafe.Pointer(&_winMutex_lock)), 0, int32(1)) == int32(1) {
		if _winMutex_isInit == int32(1) {
			i = 0
			for {
				if !(i < int32(libc.Uint32FromInt64(336)/libc.Uint32FromInt64(28))) {
					break
				}
				libc.XDeleteCriticalSection(tls, uintptr(unsafe.Pointer(&_winMutex_staticMutexes))+uintptr(i)*28)
				goto _1
			_1:
				;
				i++
			}
			_winMutex_isInit = 0
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The sqlite3_mutex_alloc() routine allocates a new
//	** mutex and returns a pointer to it.  If it returns NULL
//	** that means that a mutex could not be allocated.  SQLite
//	** will unwind its stack and return an error.  The argument
//	** to sqlite3_mutex_alloc() is one of these integer constants:
//	**
//	** <ul>
//	** <li>  SQLITE_MUTEX_FAST
//	** <li>  SQLITE_MUTEX_RECURSIVE
//	** <li>  SQLITE_MUTEX_STATIC_MAIN
//	** <li>  SQLITE_MUTEX_STATIC_MEM
//	** <li>  SQLITE_MUTEX_STATIC_OPEN
//	** <li>  SQLITE_MUTEX_STATIC_PRNG
//	** <li>  SQLITE_MUTEX_STATIC_LRU
//	** <li>  SQLITE_MUTEX_STATIC_PMEM
//	** <li>  SQLITE_MUTEX_STATIC_APP1
//	** <li>  SQLITE_MUTEX_STATIC_APP2
//	** <li>  SQLITE_MUTEX_STATIC_APP3
//	** <li>  SQLITE_MUTEX_STATIC_VFS1
//	** <li>  SQLITE_MUTEX_STATIC_VFS2
//	** <li>  SQLITE_MUTEX_STATIC_VFS3
//	** </ul>
//	**
//	** The first two constants cause sqlite3_mutex_alloc() to create
//	** a new mutex.  The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
//	** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
//	** The mutex implementation does not need to make a distinction
//	** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
//	** not want to.  But SQLite will only request a recursive mutex in
//	** cases where it really needs one.  If a faster non-recursive mutex
//	** implementation is available on the host platform, the mutex subsystem
//	** might return such a mutex in response to SQLITE_MUTEX_FAST.
//	**
//	** The other allowed parameters to sqlite3_mutex_alloc() each return
//	** a pointer to a static preexisting mutex.  Six static mutexes are
//	** used by the current version of SQLite.  Future versions of SQLite
//	** may add additional static mutexes.  Static mutexes are for internal
//	** use by SQLite only.  Applications that use SQLite mutexes should
//	** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
//	** SQLITE_MUTEX_RECURSIVE.
//	**
//	** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
//	** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
//	** returns a different mutex on every call.  But for the static
//	** mutex types, the same mutex is returned on every call that has
//	** the same type number.
//	*/
func _winMutexAlloc(tls *libc.TLS, iType int32) (r uintptr) {
	var p uintptr
	_ = p
	switch iType {
	case SQLITE_MUTEX_FAST:
		fallthrough
	case int32(SQLITE_MUTEX_RECURSIVE):
		p = _sqlite3MallocZero(tls, uint64(28))
		if p != 0 {
			(*Tsqlite3_mutex)(unsafe.Pointer(p)).Fid = iType
			libc.XInitializeCriticalSection(tls, p)
		}
	default:
		p = uintptr(unsafe.Pointer(&_winMutex_staticMutexes)) + uintptr(iType-int32(2))*28
		break
	}
	return p
}

// C documentation
//
//	/*
//	** This routine deallocates a previously
//	** allocated mutex.  SQLite is careful to deallocate every
//	** mutex that it allocates.
//	*/
func _winMutexFree(tls *libc.TLS, p uintptr) {
	if (*Tsqlite3_mutex)(unsafe.Pointer(p)).Fid == SQLITE_MUTEX_FAST || (*Tsqlite3_mutex)(unsafe.Pointer(p)).Fid == int32(SQLITE_MUTEX_RECURSIVE) {
		libc.XDeleteCriticalSection(tls, p)
		Xsqlite3_free(tls, p)
	} else {
	}
}

// C documentation
//
//	/*
//	** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
//	** to enter a mutex.  If another thread is already within the mutex,
//	** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
//	** SQLITE_BUSY.  The sqlite3_mutex_try() interface returns SQLITE_OK
//	** upon successful entry.  Mutexes created using SQLITE_MUTEX_RECURSIVE can
//	** be entered multiple times by the same thread.  In such cases the,
//	** mutex must be exited an equal number of times before another thread
//	** can enter.  If the same thread tries to enter any other kind of mutex
//	** more than once, the behavior is undefined.
//	*/
func _winMutexEnter(tls *libc.TLS, p uintptr) {
	libc.XEnterCriticalSection(tls, p)
}

func _winMutexTry(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = int32(SQLITE_BUSY)
	/*
	 ** The sqlite3_mutex_try() routine is very rarely used, and when it
	 ** is used it is merely an optimization.  So it is OK for it to always
	 ** fail.
	 **
	 ** The TryEnterCriticalSection() interface is only available on WinNT.
	 ** And some windows compilers complain if you try to use it without
	 ** first doing some #defines that prevent SQLite from building on Win98.
	 ** For that reason, we will omit this optimization for now.  See
	 ** ticket #2685.
	 */
	if _winMutex_isNt < 0 {
		_winMutex_isNt = Xsqlite3_win32_is_nt(tls)
	}
	if _winMutex_isNt != 0 && libc.XTryEnterCriticalSection(tls, p) != 0 {
		rc = SQLITE_OK
	}
	return rc
}

// C documentation
//
//	/*
//	** The sqlite3_mutex_leave() routine exits a mutex that was
//	** previously entered by the same thread.  The behavior
//	** is undefined if the mutex is not currently entered or
//	** is not currently allocated.  SQLite will never do either.
//	*/
func _winMutexLeave(tls *libc.TLS, p uintptr) {
	libc.XLeaveCriticalSection(tls, p)
}

func _sqlite3DefaultMutex(tls *libc.TLS) (r uintptr) {
	return uintptr(unsafe.Pointer(&_sMutex1))
}

var _sMutex1 = Tsqlite3_mutex_methods{}

func init() {
	p := unsafe.Pointer(&_sMutex1)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_winMutexInit)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_winMutexEnd)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_winMutexAlloc)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_winMutexFree)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_winMutexEnter)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_winMutexTry)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_winMutexLeave)
}

/************** End of mutex_w32.c *******************************************/
/************** Begin file malloc.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.
**
*************************************************************************
**
** Memory allocation functions used throughout sqlite.
 */
/* #include "sqliteInt.h" */
/* #include <stdarg.h> */

// C documentation
//
//	/*
//	** Attempt to release up to n bytes of non-essential memory currently
//	** held by SQLite. An example of non-essential memory is memory used to
//	** cache database pages that are not currently in use.
//	*/
func Xsqlite3_release_memory(tls *libc.TLS, n int32) (r int32) {
	return _sqlite3PcacheReleaseMemory(tls, n)
}

/*
** Default value of the hard heap limit.  0 means "no limit".
 */

// C documentation
//
//	/*
//	** State information local to the memory allocation subsystem.
//	*/
type TMem0Global = struct {
	F__ccgo_align   [0]uint32
	Fmutex          uintptr
	F__ccgo_align1  [4]byte
	FalarmThreshold Tsqlite3_int64
	FhardLimit      Tsqlite3_int64
	FnearlyFull     int32
	F__ccgo_pad4    [4]byte
}

type Mem0Global = TMem0Global

/*
** Default value of the hard heap limit.  0 means "no limit".
 */

// C documentation
//
//	/*
//	** State information local to the memory allocation subsystem.
//	*/
var _mem0 = TMem0Global{}

// C documentation
//
//	/*
//	** Return the memory allocator mutex. sqlite3_status() needs it.
//	*/
func _sqlite3MallocMutex(tls *libc.TLS) (r uintptr) {
	return _mem0.Fmutex
}

// C documentation
//
//	/*
//	** Deprecated external interface.  It used to set an alarm callback
//	** that was invoked when memory usage grew too large.  Now it is a
//	** no-op.
//	*/
func Xsqlite3_memory_alarm(tls *libc.TLS, xCallback uintptr, pArg uintptr, iThreshold Tsqlite3_int64) (r int32) {
	_ = xCallback
	_ = pArg
	_ = iThreshold
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Set the soft heap-size limit for the library.  An argument of
//	** zero disables the limit.  A negative argument is a no-op used to
//	** obtain the return value.
//	**
//	** The return value is the value of the heap limit just before this
//	** interface was called.
//	**
//	** If the hard heap limit is enabled, then the soft heap limit cannot
//	** be disabled nor raised above the hard heap limit.
//	*/
func Xsqlite3_soft_heap_limit64(tls *libc.TLS, n Tsqlite3_int64) (r Tsqlite3_int64) {
	var excess, nUsed, priorLimit Tsqlite3_int64
	var rc int32
	_, _, _, _ = excess, nUsed, priorLimit, rc
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return int64(-int32(1))
	}
	Xsqlite3_mutex_enter(tls, _mem0.Fmutex)
	priorLimit = _mem0.FalarmThreshold
	if n < 0 {
		Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
		return priorLimit
	}
	if _mem0.FhardLimit > 0 && (n > _mem0.FhardLimit || n == 0) {
		n = _mem0.FhardLimit
	}
	_mem0.FalarmThreshold = n
	nUsed = _sqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)
	libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&_mem0))+24, libc.BoolInt32(n > 0 && n <= nUsed), libc.Int32FromInt32(__ATOMIC_RELAXED))
	Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
	excess = Xsqlite3_memory_used(tls) - n
	if excess > 0 {
		Xsqlite3_release_memory(tls, int32(excess&libc.Int64FromInt32(0x7fffffff)))
	}
	return priorLimit
}

func Xsqlite3_soft_heap_limit(tls *libc.TLS, n int32) {
	if n < 0 {
		n = 0
	}
	Xsqlite3_soft_heap_limit64(tls, int64(int64(n)))
}

// C documentation
//
//	/*
//	** Set the hard heap-size limit for the library. An argument of zero
//	** disables the hard heap limit.  A negative argument is a no-op used
//	** to obtain the return value without affecting the hard heap limit.
//	**
//	** The return value is the value of the hard heap limit just prior to
//	** calling this interface.
//	**
//	** Setting the hard heap limit will also activate the soft heap limit
//	** and constrain the soft heap limit to be no more than the hard heap
//	** limit.
//	*/
func Xsqlite3_hard_heap_limit64(tls *libc.TLS, n Tsqlite3_int64) (r Tsqlite3_int64) {
	var priorLimit Tsqlite3_int64
	var rc int32
	_, _ = priorLimit, rc
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return int64(-int32(1))
	}
	Xsqlite3_mutex_enter(tls, _mem0.Fmutex)
	priorLimit = _mem0.FhardLimit
	if n >= 0 {
		_mem0.FhardLimit = n
		if n < _mem0.FalarmThreshold || _mem0.FalarmThreshold == 0 {
			_mem0.FalarmThreshold = n
		}
	}
	Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
	return priorLimit
}

// C documentation
//
//	/*
//	** Initialize the memory allocation subsystem.
//	*/
func _sqlite3MallocInit(tls *libc.TLS) (r int32) {
	var rc int32
	_ = rc
	if _sqlite3Config.Fm.FxMalloc == uintptr(0) {
		_sqlite3MemSetDefault(tls)
	}
	_mem0.Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MEM))
	if _sqlite3Config.FpPage == uintptr(0) || _sqlite3Config.FszPage < int32(512) || _sqlite3Config.FnPage <= 0 {
		_sqlite3Config.FpPage = uintptr(0)
		_sqlite3Config.FszPage = 0
	}
	rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxInit})))(tls, _sqlite3Config.Fm.FpAppData)
	if rc != SQLITE_OK {
		libc.Xmemset(tls, uintptr(unsafe.Pointer(&_mem0)), 0, uint32(32))
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if the heap is currently under memory pressure - in other
//	** words if the amount of heap used is close to the limit set by
//	** sqlite3_soft_heap_limit().
//	*/
func _sqlite3HeapNearlyFull(tls *libc.TLS) (r int32) {
	return libc.AtomicLoadNInt32(uintptr(unsafe.Pointer(&_mem0))+24, libc.Int32FromInt32(__ATOMIC_RELAXED))
}

// C documentation
//
//	/*
//	** Deinitialize the memory allocation subsystem.
//	*/
func _sqlite3MallocEnd(tls *libc.TLS) {
	if _sqlite3Config.Fm.FxShutdown != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxShutdown})))(tls, _sqlite3Config.Fm.FpAppData)
	}
	libc.Xmemset(tls, uintptr(unsafe.Pointer(&_mem0)), 0, uint32(32))
}

// C documentation
//
//	/*
//	** Return the amount of memory currently checked out.
//	*/
func Xsqlite3_memory_used(tls *libc.TLS) (r Tsqlite3_int64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* mx at bp+8 */ Tsqlite3_int64
	var _ /* res at bp+0 */ Tsqlite3_int64
	Xsqlite3_status64(tls, SQLITE_STATUS_MEMORY_USED, bp, bp+8, 0)
	return *(*Tsqlite3_int64)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Return the maximum amount of memory that has ever been
//	** checked out since either the beginning of this process
//	** or since the most recent reset.
//	*/
func Xsqlite3_memory_highwater(tls *libc.TLS, resetFlag int32) (r Tsqlite3_int64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* mx at bp+8 */ Tsqlite3_int64
	var _ /* res at bp+0 */ Tsqlite3_int64
	Xsqlite3_status64(tls, SQLITE_STATUS_MEMORY_USED, bp, bp+8, resetFlag)
	return *(*Tsqlite3_int64)(unsafe.Pointer(bp + 8))
}

// C documentation
//
//	/*
//	** Trigger the alarm
//	*/
func _sqlite3MallocAlarm(tls *libc.TLS, nByte int32) {
	if _mem0.FalarmThreshold <= 0 {
		return
	}
	Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
	Xsqlite3_release_memory(tls, nByte)
	Xsqlite3_mutex_enter(tls, _mem0.Fmutex)
}

// C documentation
//
//	/*
//	** Do a memory allocation with statistics and alarms.  Assume the
//	** lock is already held.
//	*/
func _mallocWithAlarm(tls *libc.TLS, n int32, pp uintptr) {
	var nFull int32
	var nUsed Tsqlite3_int64
	var p uintptr
	_, _, _ = nFull, nUsed, p
	/* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
	 ** implementation of malloc_good_size(), which must be called in debug
	 ** mode and specifically when the DMD "Dark Matter Detector" is enabled
	 ** or else a crash results.  Hence, do not attempt to optimize out the
	 ** following xRoundup() call. */
	nFull = (*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxRoundup})))(tls, n)
	_sqlite3StatusHighwater(tls, int32(SQLITE_STATUS_MALLOC_SIZE), n)
	if _mem0.FalarmThreshold > 0 {
		nUsed = _sqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)
		if nUsed >= _mem0.FalarmThreshold-int64(int64(nFull)) {
			libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&_mem0))+24, libc.Int32FromInt32(1), libc.Int32FromInt32(__ATOMIC_RELAXED))
			_sqlite3MallocAlarm(tls, nFull)
			if _mem0.FhardLimit != 0 {
				nUsed = _sqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)
				if nUsed >= _mem0.FhardLimit-int64(int64(nFull)) {
					*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
					return
				}
			}
		} else {
			libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&_mem0))+24, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
		}
	}
	p = (*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxMalloc})))(tls, nFull)
	if p == uintptr(0) && _mem0.FalarmThreshold > 0 {
		_sqlite3MallocAlarm(tls, nFull)
		p = (*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxMalloc})))(tls, nFull)
	}
	if p != 0 {
		nFull = _sqlite3MallocSize(tls, p)
		_sqlite3StatusUp(tls, SQLITE_STATUS_MEMORY_USED, nFull)
		_sqlite3StatusUp(tls, int32(SQLITE_STATUS_MALLOC_COUNT), int32(1))
	}
	*(*uintptr)(unsafe.Pointer(pp)) = p
}

/*
** Maximum size of any single memory allocation.
**
** This is not a limit on the total amount of memory used.  This is
** a limit on the size parameter to sqlite3_malloc() and sqlite3_realloc().
**
** The upper bound is slightly less than 2GiB:  0x7ffffeff == 2,147,483,391
** This provides a 256-byte safety margin for defense against 32-bit
** signed integer overflow bugs when computing memory allocation sizes.
** Paranoid applications might want to reduce the maximum allocation size
** further for an even larger safety margin.  0x3fffffff or 0x0fffffff
** or even smaller would be reasonable upper bounds on the size of a memory
** allocations for most applications.
 */

// C documentation
//
//	/*
//	** Allocate memory.  This routine is like sqlite3_malloc() except that it
//	** assumes the memory subsystem has already been initialized.
//	*/
func _sqlite3Malloc(tls *libc.TLS, n Tu64) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* p at bp+0 */ uintptr
	if n == uint64(0) || n > uint64(SQLITE_MAX_ALLOCATION_SIZE) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	} else {
		if _sqlite3Config.FbMemstat != 0 {
			Xsqlite3_mutex_enter(tls, _mem0.Fmutex)
			_mallocWithAlarm(tls, int32(int32(n)), bp)
			Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
		} else {
			*(*uintptr)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxMalloc})))(tls, int32(int32(n)))
		}
	}
	/* IMP: R-11148-40995 */
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** This version of the memory allocation is for use by the application.
//	** First make sure the memory subsystem is initialized, then do the
//	** allocation.
//	*/
func Xsqlite3_malloc(tls *libc.TLS, n int32) (r uintptr) {
	var v1 uintptr
	_ = v1
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	if n <= 0 {
		v1 = uintptr(0)
	} else {
		v1 = _sqlite3Malloc(tls, uint64(uint64(n)))
	}
	return v1
}

func Xsqlite3_malloc64(tls *libc.TLS, n Tsqlite3_uint64) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _sqlite3Malloc(tls, n)
}

// C documentation
//
//	/*
//	** TRUE if p is a lookaside memory allocation from db
//	*/
func _isLookaside(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	return libc.BoolInt32(uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) && uint32(p) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd))
}

// C documentation
//
//	/*
//	** Return the size of a memory allocation previously obtained from
//	** sqlite3Malloc() or sqlite3_malloc().
//	*/
func _sqlite3MallocSize(tls *libc.TLS, p uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxSize})))(tls, p)
}

func _lookasideMallocSize(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	var v1 int32
	_ = v1
	if p < (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle {
		v1 = int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
	} else {
		v1 = int32(LOOKASIDE_SMALL)
	}
	return v1
}

func _sqlite3DbMallocSize(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	if db != 0 {
		if uint32(uint32(p)) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd) {
			if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
				return int32(LOOKASIDE_SMALL)
			}
			if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
				return int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
			}
		}
	}
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxSize})))(tls, p)
}

func Xsqlite3_msize(tls *libc.TLS, p uintptr) (r Tsqlite3_uint64) {
	var v1 int32
	_ = v1
	if p != 0 {
		v1 = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxSize})))(tls, p)
	} else {
		v1 = 0
	}
	return uint64(v1)
}

// C documentation
//
//	/*
//	** Free memory previously obtained from sqlite3Malloc().
//	*/
func Xsqlite3_free(tls *libc.TLS, p uintptr) {
	if p == uintptr(0) {
		return
	} /* IMP: R-49053-54554 */
	if _sqlite3Config.FbMemstat != 0 {
		Xsqlite3_mutex_enter(tls, _mem0.Fmutex)
		_sqlite3StatusDown(tls, SQLITE_STATUS_MEMORY_USED, _sqlite3MallocSize(tls, p))
		_sqlite3StatusDown(tls, int32(SQLITE_STATUS_MALLOC_COUNT), int32(1))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxFree})))(tls, p)
		Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
	} else {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxFree})))(tls, p)
	}
}

// C documentation
//
//	/*
//	** Add the size of memory allocation "p" to the count in
//	** *db->pnBytesFreed.
//	*/
func _measureAllocationSize(tls *libc.TLS, db uintptr, p uintptr) {
	*(*int32)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed)) += _sqlite3DbMallocSize(tls, db, p)
}

// C documentation
//
//	/*
//	** Free memory that might be associated with a particular database
//	** connection.  Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
//	** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
//	*/
func _sqlite3DbFreeNN(tls *libc.TLS, db uintptr, p uintptr) {
	var pBuf, pBuf1 uintptr
	_, _ = pBuf, pBuf1
	if db != 0 {
		if uint32(uint32(p)) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
			if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
				pBuf = p
				(*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = pBuf
				return
			}
			if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
				pBuf1 = p
				(*TLookasideSlot)(unsafe.Pointer(pBuf1)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = pBuf1
				return
			}
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
			_measureAllocationSize(tls, db, p)
			return
		}
	}
	Xsqlite3_free(tls, p)
}

func _sqlite3DbNNFreeNN(tls *libc.TLS, db uintptr, p uintptr) {
	var pBuf, pBuf1 uintptr
	_, _ = pBuf, pBuf1
	if uint32(uint32(p)) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
		if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
			pBuf = p
			(*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = pBuf
			return
		}
		if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
			pBuf1 = p
			(*TLookasideSlot)(unsafe.Pointer(pBuf1)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = pBuf1
			return
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
		_measureAllocationSize(tls, db, p)
		return
	}
	Xsqlite3_free(tls, p)
}

func _sqlite3DbFree(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		_sqlite3DbFreeNN(tls, db, p)
	}
}

// C documentation
//
//	/*
//	** Change the size of an existing memory allocation
//	*/
func _sqlite3Realloc(tls *libc.TLS, pOld uintptr, nBytes Tu64) (r uintptr) {
	var nDiff, nNew, nOld int32
	var nUsed, v1 Tsqlite3_int64
	var pNew uintptr
	var v2 bool
	_, _, _, _, _, _, _ = nDiff, nNew, nOld, nUsed, pNew, v1, v2
	if pOld == uintptr(0) {
		return _sqlite3Malloc(tls, nBytes) /* IMP: R-04300-56712 */
	}
	if nBytes == uint64(0) {
		Xsqlite3_free(tls, pOld) /* IMP: R-26507-47431 */
		return uintptr(0)
	}
	if nBytes >= uint64(0x7fffff00) {
		/* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
		return uintptr(0)
	}
	nOld = _sqlite3MallocSize(tls, pOld)
	/* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
	 ** argument to xRealloc is always a value returned by a prior call to
	 ** xRoundup. */
	nNew = (*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxRoundup})))(tls, int32(int32(nBytes)))
	if nOld == nNew {
		pNew = pOld
	} else {
		if _sqlite3Config.FbMemstat != 0 {
			Xsqlite3_mutex_enter(tls, _mem0.Fmutex)
			_sqlite3StatusHighwater(tls, int32(SQLITE_STATUS_MALLOC_SIZE), int32(int32(nBytes)))
			nDiff = nNew - nOld
			if v2 = nDiff > 0; v2 {
				v1 = _sqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)
				nUsed = v1
			}
			if v2 && v1 >= _mem0.FalarmThreshold-int64(int64(nDiff)) {
				_sqlite3MallocAlarm(tls, nDiff)
				if _mem0.FhardLimit > 0 && nUsed >= _mem0.FhardLimit-int64(int64(nDiff)) {
					Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
					return uintptr(0)
				}
			}
			pNew = (*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxRealloc})))(tls, pOld, nNew)
			if pNew == uintptr(0) && _mem0.FalarmThreshold > 0 {
				_sqlite3MallocAlarm(tls, int32(int32(nBytes)))
				pNew = (*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxRealloc})))(tls, pOld, nNew)
			}
			if pNew != 0 {
				nNew = _sqlite3MallocSize(tls, pNew)
				_sqlite3StatusUp(tls, SQLITE_STATUS_MEMORY_USED, nNew-nOld)
			}
			Xsqlite3_mutex_leave(tls, _mem0.Fmutex)
		} else {
			pNew = (*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fm.FxRealloc})))(tls, pOld, nNew)
		}
	}
	/* IMP: R-11148-40995 */
	return pNew
}

// C documentation
//
//	/*
//	** The public interface to sqlite3Realloc.  Make sure that the memory
//	** subsystem is initialized prior to invoking sqliteRealloc.
//	*/
func Xsqlite3_realloc(tls *libc.TLS, pOld uintptr, n int32) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	if n < 0 {
		n = 0
	} /* IMP: R-26507-47431 */
	return _sqlite3Realloc(tls, pOld, uint64(uint64(n)))
}

func Xsqlite3_realloc64(tls *libc.TLS, pOld uintptr, n Tsqlite3_uint64) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _sqlite3Realloc(tls, pOld, n)
}

// C documentation
//
//	/*
//	** Allocate and zero memory.
//	*/
func _sqlite3MallocZero(tls *libc.TLS, n Tu64) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3Malloc(tls, n)
	if p != 0 {
		libc.Xmemset(tls, p, 0, uint32(uint32(n)))
	}
	return p
}

// C documentation
//
//	/*
//	** Allocate and zero memory.  If the allocation fails, make
//	** the mallocFailed flag in the connection pointer.
//	*/
func _sqlite3DbMallocZero(tls *libc.TLS, db uintptr, n Tu64) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3DbMallocRaw(tls, db, n)
	if p != 0 {
		libc.Xmemset(tls, p, 0, uint32(uint32(n)))
	}
	return p
}

// C documentation
//
//	/* Finish the work of sqlite3DbMallocRawNN for the unusual and
//	** slower case when the allocation cannot be fulfilled using lookaside.
//	*/
func _dbMallocRawFinish(tls *libc.TLS, db uintptr, n Tu64) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3Malloc(tls, n)
	if !(p != 0) {
		_sqlite3OomFault(tls, db)
	}
	return p
}

// C documentation
//
//	/*
//	** Allocate memory, either lookaside (if possible) or heap.
//	** If the allocation fails, set the mallocFailed flag in
//	** the connection pointer.
//	**
//	** If db!=0 and db->mallocFailed is true (indicating a prior malloc
//	** failure on the same database connection) then always return 0.
//	** Hence for a particular database connection, once malloc starts
//	** failing, it fails consistently until mallocFailed is reset.
//	** This is an important assumption.  There are many places in the
//	** code that do things like this:
//	**
//	**         int *a = (int*)sqlite3DbMallocRaw(db, 100);
//	**         int *b = (int*)sqlite3DbMallocRaw(db, 200);
//	**         if( b ) a[10] = 9;
//	**
//	** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
//	** that all prior mallocs (ex: "a") worked too.
//	**
//	** The sqlite3MallocRawNN() variant guarantees that the "db" parameter is
//	** not a NULL pointer.
//	*/
func _sqlite3DbMallocRaw(tls *libc.TLS, db uintptr, n Tu64) (r uintptr) {
	var p uintptr
	_ = p
	if db != 0 {
		return _sqlite3DbMallocRawNN(tls, db, n)
	}
	p = _sqlite3Malloc(tls, n)
	return p
}

func _sqlite3DbMallocRawNN(tls *libc.TLS, db uintptr, n Tu64) (r uintptr) {
	var pBuf, v1, v2, v3, v4 uintptr
	_, _, _, _, _ = pBuf, v1, v2, v3, v4
	if n > uint64((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz) {
		if !((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0) {
			*(*Tu32)(unsafe.Pointer(db + 320 + 16 + 1*4))++
		} else {
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return uintptr(0)
			}
		}
		return _dbMallocRawFinish(tls, db, n)
	}
	if n <= uint64(LOOKASIDE_SMALL) {
		v1 = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
		pBuf = v1
		if v1 != uintptr(0) {
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = (*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext
			*(*Tu32)(unsafe.Pointer(db + 320 + 16))++
			return pBuf
		} else {
			v2 = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit
			pBuf = v2
			if v2 != uintptr(0) {
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = (*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext
				*(*Tu32)(unsafe.Pointer(db + 320 + 16))++
				return pBuf
			}
		}
	}
	v3 = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
	pBuf = v3
	if v3 != uintptr(0) {
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = (*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext
		*(*Tu32)(unsafe.Pointer(db + 320 + 16))++
		return pBuf
	} else {
		v4 = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit
		pBuf = v4
		if v4 != uintptr(0) {
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = (*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext
			*(*Tu32)(unsafe.Pointer(db + 320 + 16))++
			return pBuf
		} else {
			*(*Tu32)(unsafe.Pointer(db + 320 + 16 + 2*4))++
		}
	}
	return _dbMallocRawFinish(tls, db, n)
}

// C documentation
//
//	/*
//	** Resize the block of memory pointed to by p to n bytes. If the
//	** resize fails, set the mallocFailed flag in the connection object.
//	*/
func _sqlite3DbRealloc(tls *libc.TLS, db uintptr, p uintptr, n Tu64) (r uintptr) {
	if p == uintptr(0) {
		return _sqlite3DbMallocRawNN(tls, db, n)
	}
	if uint32(uint32(p)) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
		if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
			if n <= uint64(LOOKASIDE_SMALL) {
				return p
			}
		} else {
			if uint32(uint32(p)) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
				if n <= uint64((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue) {
					return p
				}
			}
		}
	}
	return _dbReallocFinish(tls, db, p, n)
}

func _dbReallocFinish(tls *libc.TLS, db uintptr, p uintptr, n Tu64) (r uintptr) {
	var pNew uintptr
	_ = pNew
	pNew = uintptr(0)
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		if _isLookaside(tls, db, p) != 0 {
			pNew = _sqlite3DbMallocRawNN(tls, db, n)
			if pNew != 0 {
				libc.Xmemcpy(tls, pNew, p, uint32(_lookasideMallocSize(tls, db, p)))
				_sqlite3DbFree(tls, db, p)
			}
		} else {
			pNew = _sqlite3Realloc(tls, p, n)
			if !(pNew != 0) {
				_sqlite3OomFault(tls, db)
			}
		}
	}
	return pNew
}

// C documentation
//
//	/*
//	** Attempt to reallocate p.  If the reallocation fails, then free p
//	** and set the mallocFailed flag in the database connection.
//	*/
func _sqlite3DbReallocOrFree(tls *libc.TLS, db uintptr, p uintptr, n Tu64) (r uintptr) {
	var pNew uintptr
	_ = pNew
	pNew = _sqlite3DbRealloc(tls, db, p, n)
	if !(pNew != 0) {
		_sqlite3DbFree(tls, db, p)
	}
	return pNew
}

// C documentation
//
//	/*
//	** Make a copy of a string in memory obtained from sqliteMalloc(). These
//	** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This
//	** is because when memory debugging is turned on, these two functions are
//	** called via macros that record the current file and line number in the
//	** ThreadData structure.
//	*/
func _sqlite3DbStrDup(tls *libc.TLS, db uintptr, z uintptr) (r uintptr) {
	var n Tsize_t
	var zNew uintptr
	_, _ = n, zNew
	if z == uintptr(0) {
		return uintptr(0)
	}
	n = libc.Xstrlen(tls, z) + uint32(1)
	zNew = _sqlite3DbMallocRaw(tls, db, uint64(uint64(n)))
	if zNew != 0 {
		libc.Xmemcpy(tls, zNew, z, n)
	}
	return zNew
}

func _sqlite3DbStrNDup(tls *libc.TLS, db uintptr, z uintptr, n Tu64) (r uintptr) {
	var zNew, v1 uintptr
	_, _ = zNew, v1
	if z != 0 {
		v1 = _sqlite3DbMallocRawNN(tls, db, n+uint64(1))
	} else {
		v1 = uintptr(0)
	}
	zNew = v1
	if zNew != 0 {
		libc.Xmemcpy(tls, zNew, z, uint32(uint32(n)))
		*(*int8)(unsafe.Pointer(zNew + uintptr(n))) = 0
	}
	return zNew
}

// C documentation
//
//	/*
//	** The text between zStart and zEnd represents a phrase within a larger
//	** SQL statement.  Make a copy of this phrase in space obtained form
//	** sqlite3DbMalloc().  Omit leading and trailing whitespace.
//	*/
func _sqlite3DbSpanDup(tls *libc.TLS, db uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var n int32
	_ = n
	for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zStart)))])&int32(0x01) != 0 {
		zStart++
	}
	n = int32(int32(zEnd)) - int32(int32(zStart))
	for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zStart + uintptr(n-int32(1)))))])&int32(0x01) != 0 {
		n--
	}
	return _sqlite3DbStrNDup(tls, db, zStart, uint64(uint64(n)))
}

// C documentation
//
//	/*
//	** Free any prior content in *pz and replace it with a copy of zNew.
//	*/
func _sqlite3SetString(tls *libc.TLS, pz uintptr, db uintptr, zNew uintptr) {
	var z uintptr
	_ = z
	z = _sqlite3DbStrDup(tls, db, zNew)
	_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pz)))
	*(*uintptr)(unsafe.Pointer(pz)) = z
}

// C documentation
//
//	/*
//	** Call this routine to record the fact that an OOM (out-of-memory) error
//	** has happened.  This routine will set db->mallocFailed, and also
//	** temporarily disable the lookaside memory allocator and interrupt
//	** any running VDBEs.
//	**
//	** Always return a NULL pointer so that this routine can be invoked using
//	**
//	**      return sqlite3OomFault(db);
//	**
//	** and thereby avoid unnecessary stack frame allocations for the overwhelmingly
//	** common case where no OOM occurs.
//	*/
func _sqlite3OomFault(tls *libc.TLS, db uintptr) (r uintptr) {
	var pParse uintptr
	_ = pParse
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && int32((*Tsqlite3)(unsafe.Pointer(db)).FbBenignMalloc) == 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed = uint8(1)
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec > 0 {
			libc.AtomicStoreNInt32(db+312, libc.Int32FromInt32(1), libc.Int32FromInt32(__ATOMIC_RELAXED))
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FpParse != 0 {
			_sqlite3ErrorMsg(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpParse, __ccgo_ts+1642, 0)
			(*TParse)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpParse)).Frc = int32(SQLITE_NOMEM)
			pParse = (*TParse)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpParse)).FpOuterParse
			for {
				if !(pParse != 0) {
					break
				}
				(*TParse)(unsafe.Pointer(pParse)).FnErr++
				(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
				goto _1
			_1:
				;
				pParse = (*TParse)(unsafe.Pointer(pParse)).FpOuterParse
			}
		}
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** This routine reactivates the memory allocator and clears the
//	** db->mallocFailed flag as necessary.
//	**
//	** The memory allocator is not restarted if there are running
//	** VDBEs.
//	*/
func _sqlite3OomClear(tls *libc.TLS, db uintptr) {
	var v1 int32
	_ = v1
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec == 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed = uint8(0)
		libc.AtomicStoreNInt32(db+312, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable--
		if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			v1 = 0
		} else {
			v1 = int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(v1)
	}
}

// C documentation
//
//	/*
//	** Take actions at the end of an API call to deal with error codes.
//	*/
func _apiHandleError(tls *libc.TLS, db uintptr, rc int32) (r int32) {
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
		_sqlite3OomClear(tls, db)
		_sqlite3Error(tls, db, int32(SQLITE_NOMEM))
		return int32(SQLITE_NOMEM)
	}
	return rc & (*Tsqlite3)(unsafe.Pointer(db)).FerrMask
}

// C documentation
//
//	/*
//	** This function must be called before exiting any API function (i.e.
//	** returning control to the user) that has called sqlite3_malloc or
//	** sqlite3_realloc.
//	**
//	** The returned value is normally a copy of the second argument to this
//	** function. However, if a malloc() failure has occurred since the previous
//	** invocation SQLITE_NOMEM is returned instead.
//	**
//	** If an OOM as occurred, then the connection error-code (the value
//	** returned by sqlite3_errcode()) is set to SQLITE_NOMEM.
//	*/
func _sqlite3ApiExit(tls *libc.TLS, db uintptr, rc int32) (r int32) {
	/* If the db handle must hold the connection handle mutex here.
	 ** Otherwise the read (and possible write) of db->mallocFailed
	 ** is unsafe, as is the call to sqlite3Error().
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 || rc != 0 {
		return _apiHandleError(tls, db, rc)
	}
	return 0
}

/************** End of malloc.c **********************************************/
/************** Begin file printf.c ******************************************/
/*
** The "printf" code that follows dates from the 1980's.  It is in
** the public domain.
**
**************************************************************************
**
** This file contains code for a set of "printf"-like routines.  These
** routines format strings much like the printf() from the standard C
** library, though the implementation here has enhancements to support
** SQLite.
 */
/* #include "sqliteInt.h" */

/*
** Conversion types fall into various categories as defined by the
** following enumeration.
 */
/* The rest are extensions, not normally found in printf() */

// C documentation
//
//	/*
//	** An "etByte" is an 8-bit unsigned value.
//	*/
type TetByte = uint8

type etByte = TetByte

// C documentation
//
//	/*
//	** Each builtin conversion character (ex: the 'd' in "%d") is described
//	** by an instance of the following structure
//	*/
type Tet_info = struct {
	Ffmttype int8
	Fbase    TetByte
	Fflags   TetByte
	Ftype1   TetByte
	Fcharset TetByte
	Fprefix  TetByte
}

type et_info = Tet_info

/*
** Allowed values for et_info.flags
 */

// C documentation
//
//	/*
//	** The following table is searched linearly, so it is good to put the
//	** most frequently used conversion types first.
//	*/
var _aDigits = [33]int8{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
var _aPrefix = [7]int8{'-', 'x', '0', 0, 'X', '0'}
var _fmtinfo = [23]Tet_info{
	0: {
		Ffmttype: int8('d'),
		Fbase:    uint8(10),
		Fflags:   uint8(1),
		Ftype1:   uint8(etDECIMAL),
	},
	1: {
		Ffmttype: int8('s'),
		Fflags:   uint8(4),
		Ftype1:   uint8(etSTRING),
	},
	2: {
		Ffmttype: int8('g'),
		Fflags:   uint8(1),
		Ftype1:   uint8(etGENERIC),
		Fcharset: uint8(30),
	},
	3: {
		Ffmttype: int8('z'),
		Fflags:   uint8(4),
		Ftype1:   uint8(etDYNSTRING),
	},
	4: {
		Ffmttype: int8('q'),
		Fflags:   uint8(4),
		Ftype1:   uint8(etSQLESCAPE),
	},
	5: {
		Ffmttype: int8('Q'),
		Fflags:   uint8(4),
		Ftype1:   uint8(etSQLESCAPE2),
	},
	6: {
		Ffmttype: int8('w'),
		Fflags:   uint8(4),
		Ftype1:   uint8(etSQLESCAPE3),
	},
	7: {
		Ffmttype: int8('c'),
		Ftype1:   uint8(etCHARX),
	},
	8: {
		Ffmttype: int8('o'),
		Fbase:    uint8(8),
		Fprefix:  uint8(2),
	},
	9: {
		Ffmttype: int8('u'),
		Fbase:    uint8(10),
		Ftype1:   uint8(etDECIMAL),
	},
	10: {
		Ffmttype: int8('x'),
		Fbase:    uint8(16),
		Fcharset: uint8(16),
		Fprefix:  uint8(1),
	},
	11: {
		Ffmttype: int8('X'),
		Fbase:    uint8(16),
		Fprefix:  uint8(4),
	},
	12: {
		Ffmttype: int8('f'),
		Fflags:   uint8(1),
		Ftype1:   uint8(etFLOAT),
	},
	13: {
		Ffmttype: int8('e'),
		Fflags:   uint8(1),
		Ftype1:   uint8(etEXP),
		Fcharset: uint8(30),
	},
	14: {
		Ffmttype: int8('E'),
		Fflags:   uint8(1),
		Ftype1:   uint8(etEXP),
		Fcharset: uint8(14),
	},
	15: {
		Ffmttype: int8('G'),
		Fflags:   uint8(1),
		Ftype1:   uint8(etGENERIC),
		Fcharset: uint8(14),
	},
	16: {
		Ffmttype: int8('i'),
		Fbase:    uint8(10),
		Fflags:   uint8(1),
		Ftype1:   uint8(etDECIMAL),
	},
	17: {
		Ffmttype: int8('n'),
		Ftype1:   uint8(etSIZE),
	},
	18: {
		Ffmttype: int8('%'),
		Ftype1:   uint8(etPERCENT),
	},
	19: {
		Ffmttype: int8('p'),
		Fbase:    uint8(16),
		Ftype1:   uint8(etPOINTER),
		Fprefix:  uint8(1),
	},
	20: {
		Ffmttype: int8('T'),
		Ftype1:   uint8(etTOKEN),
	},
	21: {
		Ffmttype: int8('S'),
		Ftype1:   uint8(etSRCITEM),
	},
	22: {
		Ffmttype: int8('r'),
		Fbase:    uint8(10),
		Fflags:   uint8(1),
		Ftype1:   uint8(etORDINAL),
	},
}

/* Notes:
**
**    %S    Takes a pointer to SrcItem.  Shows name or database.name
**    %!S   Like %S but prefer the zName over the zAlias
 */

// C documentation
//
//	/*
//	** Set the StrAccum object to an error mode.
//	*/
func _sqlite3StrAccumSetError(tls *libc.TLS, p uintptr, eError Tu8) {
	(*TStrAccum)(unsafe.Pointer(p)).FaccError = eError
	if (*TStrAccum)(unsafe.Pointer(p)).FmxAlloc != 0 {
		Xsqlite3_str_reset(tls, p)
	}
	if int32(int32(eError)) == int32(SQLITE_TOOBIG) {
		_sqlite3ErrorToParser(tls, (*TStrAccum)(unsafe.Pointer(p)).Fdb, int32(int32(eError)))
	}
}

// C documentation
//
//	/*
//	** Extra argument values from a PrintfArguments object
//	*/
func _getIntArg(tls *libc.TLS, p uintptr) (r Tsqlite3_int64) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if (*TPrintfArguments)(unsafe.Pointer(p)).FnArg <= (*TPrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return 0
	}
	v2 = p + 4
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	return Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer((*TPrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(v1)*4)))
}

func _getDoubleArg(tls *libc.TLS, p uintptr) (r float64) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if (*TPrintfArguments)(unsafe.Pointer(p)).FnArg <= (*TPrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return float64(0)
	}
	v2 = p + 4
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	return Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer((*TPrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(v1)*4)))
}

func _getTextArg(tls *libc.TLS, p uintptr) (r uintptr) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if (*TPrintfArguments)(unsafe.Pointer(p)).FnArg <= (*TPrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return uintptr(0)
	}
	v2 = p + 4
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	return Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer((*TPrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(v1)*4)))
}

// C documentation
//
//	/*
//	** Allocate memory for a temporary buffer needed for printf rendering.
//	**
//	** If the requested size of the temp buffer is larger than the size
//	** of the output buffer in pAccum, then cause an SQLITE_TOOBIG error.
//	** Do the size check before the memory allocation to prevent rogue
//	** SQL from requesting large allocations using the precision or width
//	** field of the printf() function.
//	*/
func _printfTempBuf(tls *libc.TLS, pAccum uintptr, n Tsqlite3_int64) (r uintptr) {
	var z uintptr
	_ = z
	if (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FaccError != 0 {
		return uintptr(0)
	}
	if n > int64((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc) && n > int64((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc) {
		_sqlite3StrAccumSetError(tls, pAccum, uint8(SQLITE_TOOBIG))
		return uintptr(0)
	}
	z = _sqlite3DbMallocRaw(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, uint64(uint64(n)))
	if z == uintptr(0) {
		_sqlite3StrAccumSetError(tls, pAccum, uint8(SQLITE_NOMEM))
	}
	return z
}

/*
** On machines with a small stack size, you can redefine the
** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
 */

/*
** Hard limit on the precision of floating-point conversions.
 */

// 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 bArgList, base Tu8
	var bufpt, cset, escarg, infop, pArgList, pExpr, pItem, pSel, pToken, pre, z, zExtra, zOut, v103, v11, v14, v15, v17, v20, v21, v23, v24, v4, v45, v46, v47, v48, v49, v52, v55, v57, v59, v61, v62, v64, v67, v68, v70, v72, v75, v76, v77, v78, v79, v80, v81, v82, v83, v89, v91, v94, v98, p92 uintptr
	var c, e2, exp, i, iRound, idx, ii, isnull, ix, j, length, nOut, nPad, needQuote, nn, precision, width, x, v10, v110, v111, v16, v18, v19, v2, v22, v3, v51, v56, v58, v60, v65, v66, v71, v73, v74, v85, v86, v87, v88, v90, v93, v96, v97 int32
	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, v101, v107, v54 int8
	var i1, j1, k, n1, nCopyBytes, nPrior, szBufNeeded, v, v100, v104, v106, v108, v109 Ti64
	var longvalue Tsqlite_uint64
	var n Tu64
	var realvalue float64
	var v102, v12 bool
	var _ /* buf at bp+0 */ [70]int8
	var _ /* s at bp+72 */ TFpDecode
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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, i1, iRound, idx, ii, infop, isnull, ix, j, j1, k, length, longvalue, n, n1, nCopyBytes, nOut, nPad, nPrior, needQuote, nn, pArgList, pExpr, pItem, pSel, pToken, pre, precision, prefix, px, q, realvalue, szBufNeeded, v, width, wx, x, x1, xtype, z, zExtra, zOut, v10, v100, v101, v102, v103, v104, v106, v107, v108, v109, v11, v110, v111, v12, v14, v15, v16, v17, v18, v19, v2, v20, v21, v22, v23, v24, v3, v4, v45, v46, v47, v48, v49, v5, v51, v52, v54, v55, v56, v57, v58, v59, v6, v60, v61, v62, v64, v65, v66, v67, v68, v7, v70, v71, v72, v73, v74, v75, v76, v77, v78, v79, v8, v80, v81, v82, v83, v85, v86, v87, v88, v89, v9, v90, v91, v93, v94, v96, v97, v98, p92 /* 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 int32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&int32(SQLITE_PRINTF_SQLFUNC) != 0 {
		pArgList = libc.VaUintptr(&ap)
		bArgList = uint8(1)
	} else {
		bArgList = uint8(0)
	}
	for {
		v2 = int32(*(*int8)(unsafe.Pointer(fmt)))
		c = v2
		if !(v2 != 0) {
			break
		}
		if c != int32('%') {
			bufpt = fmt
			for cond := true; cond; cond = *(*int8)(unsafe.Pointer(fmt)) != 0 && int32(*(*int8)(unsafe.Pointer(fmt))) != int32('%') {
				fmt++
			}
			Xsqlite3_str_append(tls, pAccum, bufpt, int32(int32(fmt))-int32(int32(bufpt)))
			if int32(*(*int8)(unsafe.Pointer(fmt))) == 0 {
				break
			}
		}
		fmt++
		v4 = fmt
		v3 = int32(*(*int8)(unsafe.Pointer(v4)))
		c = v3
		if v3 == 0 {
			Xsqlite3_str_append(tls, pAccum, __ccgo_ts+1656, 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++
				v14 = fmt
				c = int32(*(*int8)(unsafe.Pointer(v14)))
				if c == int32('l') {
					fmt++
					v15 = fmt
					c = int32(*(*int8)(unsafe.Pointer(v15)))
					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 = uint32(c - int32('0'))
				for {
					fmt++
					v17 = fmt
					v16 = int32(*(*int8)(unsafe.Pointer(v17)))
					c = v16
					if !(v16 >= int32('0') && c <= int32('9')) {
						break
					}
					wx = wx*uint32(10) + uint32(uint32(c)) - uint32('0')
				}
				width = int32(wx & uint32(0x7fffffff))
				if c != int32('.') && c != int32('l') {
					done = uint8(1)
				} else {
					fmt--
				}
			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) {
						v18 = -width
					} else {
						v18 = 0
					}
					width = v18
				}
				v19 = int32(*(*int8)(unsafe.Pointer(fmt + 1)))
				c = v19
				if v19 != int32('.') && c != int32('l') {
					fmt++
					v20 = fmt
					c = int32(*(*int8)(unsafe.Pointer(v20)))
					done = uint8(1)
				}
			case int32('.'):
				fmt++
				v21 = fmt
				c = int32(*(*int8)(unsafe.Pointer(v21)))
				if c == int32('*') {
					if bArgList != 0 {
						precision = int32(_getIntArg(tls, pArgList))
					} else {
						precision = libc.VaInt32(&ap)
					}
					if precision < 0 {
						if precision >= -int32(2147483647) {
							v22 = -precision
						} else {
							v22 = -int32(1)
						}
						precision = v22
					}
					fmt++
					v23 = fmt
					c = int32(*(*int8)(unsafe.Pointer(v23)))
				} else {
					px = uint32(0)
					for c >= int32('0') && c <= int32('9') {
						px = px*uint32(10) + uint32(uint32(c)) - uint32('0')
						fmt++
						v24 = fmt
						c = int32(*(*int8)(unsafe.Pointer(v24)))
					}
					precision = int32(px & uint32(0x7fffffff))
				}
				if c == int32('l') {
					fmt--
				} else {
					done = uint8(1)
				}
				break
			}
			goto _13
		_13:
			;
			if v12 = !(done != 0); v12 {
				fmt++
				v11 = fmt
				v10 = int32(*(*int8)(unsafe.Pointer(v11)))
				c = v10
			}
			if !(v12 && v10 != 0) {
				break
			}
		}
		/* Fetch the info entry for the field */
		infop = uintptr(unsafe.Pointer(&_fmtinfo))
		xtype = uint8(etINVALID)
		idx = 0
		for {
			if !(idx < int32(libc.Uint32FromInt64(138)/libc.Uint32FromInt64(6))) {
				break
			}
			if c == int32(_fmtinfo[idx].Ffmttype) {
				infop = uintptr(unsafe.Pointer(&_fmtinfo)) + uintptr(idx)*6
				xtype = (*Tet_info)(unsafe.Pointer(infop)).Ftype1
				break
			}
			goto _25
		_25:
			;
			idx++
		}
		/*
		 ** 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 int32(int32(xtype)) {
		case int32(etPOINTER):
			goto _26
		case etRADIX:
			goto _27
		case int32(etORDINAL):
			goto _28
		case int32(etDECIMAL):
			goto _29
		case int32(etGENERIC):
			goto _30
		case int32(etEXP):
			goto _31
		case int32(etFLOAT):
			goto _32
		case int32(etSIZE):
			goto _33
		case int32(etPERCENT):
			goto _34
		case int32(etCHARX):
			goto _35
		case int32(etDYNSTRING):
			goto _36
		case int32(etSTRING):
			goto _37
		case int32(etSQLESCAPE3):
			goto _38
		case int32(etSQLESCAPE2):
			goto _39
		case int32(etSQLESCAPE):
			goto _40
		case int32(etTOKEN):
			goto _41
		case int32(etSRCITEM):
			goto _42
		default:
			goto _43
		}
		goto _44
	_26:
		;
		flag_long = uint8(1)
	_28:
		;
	_27:
		;
		cThousand = uint8(0)
	_29:
		;
		if int32((*Tet_info)(unsafe.Pointer(infop)).Fflags)&int32(FLAG_SIGNED) != 0 {
			if bArgList != 0 {
				v = _getIntArg(tls, pArgList)
			} else {
				if flag_long != 0 {
					if int32(int32(flag_long)) == int32(2) {
						v = libc.VaInt64(&ap)
					} else {
						v = int64(libc.VaInt32(&ap))
					}
				} else {
					v = int64(libc.VaInt32(&ap))
				}
			}
			if v < 0 {
				longvalue = uint64(^v)
				longvalue++
				prefix = int8('-')
			} else {
				longvalue = uint64(uint64(v))
				prefix = int8(int8(flag_prefix))
			}
		} else {
			if bArgList != 0 {
				longvalue = uint64(_getIntArg(tls, pArgList))
			} else {
				if flag_long != 0 {
					if int32(int32(flag_long)) == int32(2) {
						longvalue = libc.VaUint64(&ap)
					} else {
						longvalue = uint64(libc.VaUint32(&ap))
					}
				} else {
					longvalue = uint64(libc.VaUint32(&ap))
				}
			}
			prefix = 0
		}
		if longvalue == uint64(0) {
			flag_alternateform = uint8(0)
		}
		if flag_zeropad != 0 && precision < width-libc.BoolInt32(int32(int32(prefix)) != 0) {
			precision = width - libc.BoolInt32(int32(int32(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 = uint64(uint64(precision)) + uint64(10)
			if cThousand != 0 {
				n += uint64(precision / int32(3))
			}
			v45 = _printfTempBuf(tls, pAccum, int64(int64(n)))
			zExtra = v45
			zOut = v45
			if zOut == uintptr(0) {
				return
			}
			nOut = int32(int32(n))
		}
		bufpt = zOut + uintptr(nOut-int32(1))
		if int32(int32(xtype)) == int32(etORDINAL) {
			x = int32(longvalue % libc.Uint64FromInt32(10))
			if x >= int32(4) || longvalue/uint64(10)%uint64(10) == uint64(1) {
				x = 0
			}
			bufpt--
			v46 = bufpt
			*(*int8)(unsafe.Pointer(v46)) = _zOrd[x*int32(2)+int32(1)]
			bufpt--
			v47 = bufpt
			*(*int8)(unsafe.Pointer(v47)) = _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--
			v48 = bufpt
			*(*int8)(unsafe.Pointer(v48)) = *(*int8)(unsafe.Pointer(cset + uintptr(longvalue%uint64(uint64(base)))))
			longvalue = longvalue / uint64(uint64(base))
		}
		length = t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int32(int32(bufpt))
		for precision > length {
			bufpt--
			v49 = bufpt
			*(*int8)(unsafe.Pointer(v49)) = int8('0') /* Zero pad */
			length++
		}
		if cThousand != 0 {
			nn = (length - int32(1)) / int32(3) /* Number of "," to insert */
			ix = (length-int32(1))%int32(3) + int32(1)
			bufpt -= uintptr(nn)
			idx = 0
			for {
				if !(nn > 0) {
					break
				}
				*(*int8)(unsafe.Pointer(bufpt + uintptr(idx))) = *(*int8)(unsafe.Pointer(bufpt + uintptr(idx+nn)))
				ix--
				if ix == 0 {
					idx++
					v51 = idx
					*(*int8)(unsafe.Pointer(bufpt + uintptr(v51))) = int8(int8(cThousand))
					nn--
					ix = int32(3)
				}
				goto _50
			_50:
				;
				idx++
			}
		}
		if prefix != 0 {
			bufpt--
			v52 = bufpt
			*(*int8)(unsafe.Pointer(v52)) = 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 = *(*int8)(unsafe.Pointer(pre))
				x1 = v54
				if !(int32(v54) != 0) {
					break
				}
				bufpt--
				v55 = bufpt
				*(*int8)(unsafe.Pointer(v55)) = x1
				goto _53
			_53:
				;
				pre++
			}
		}
		length = t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int32(int32(bufpt))
		goto _44
	_32:
		;
	_31:
		;
	_30:
		;
		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 int32(int32(xtype)) == int32(etFLOAT) {
			iRound = -precision
		} else {
			if int32(int32(xtype)) == int32(etGENERIC) {
				if precision == 0 {
					precision = int32(1)
				}
				iRound = precision
			} else {
				iRound = precision + int32(1)
			}
		}
		if flag_altform2 != 0 {
			v56 = int32(26)
		} else {
			v56 = int32(16)
		}
		_sqlite3FpDecode(tls, bp+72, realvalue, iRound, v56)
		if (*(*TFpDecode)(unsafe.Pointer(bp + 72))).FisSpecial != 0 {
			if int32((*(*TFpDecode)(unsafe.Pointer(bp + 72))).FisSpecial) == int32(2) {
				if flag_zeropad != 0 {
					v57 = __ccgo_ts + 1658
				} else {
					v57 = __ccgo_ts + 1663
				}
				bufpt = v57
				length = _sqlite3Strlen30(tls, bufpt)
				goto _44
			} else {
				if flag_zeropad != 0 {
					*(*int8)(unsafe.Pointer((*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fz)) = int8('9')
					(*(*TFpDecode)(unsafe.Pointer(bp + 72))).FiDP = int32(1000)
					(*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fn = int32(1)
				} else {
					libc.Xmemcpy(tls, bp, __ccgo_ts+1667, uint32(5))
					bufpt = bp
					if int32((*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fsign) == int32('-') {
						/* no-op */
					} else {
						if flag_prefix != 0 {
							(*(*[70]int8)(unsafe.Pointer(bp)))[0] = int8(int8(flag_prefix))
						} else {
							bufpt++
						}
					}
					length = _sqlite3Strlen30(tls, bufpt)
					goto _44
				}
			}
		}
		if int32((*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fsign) == int32('-') {
			prefix = int8('-')
		} else {
			prefix = int8(int8(flag_prefix))
		}
		exp = (*(*TFpDecode)(unsafe.Pointer(bp + 72))).FiDP - int32(1)
		/*
		 ** If the field type is etGENERIC, then convert to either etEXP
		 ** or etFLOAT, as appropriate.
		 */
		if int32(int32(xtype)) == int32(etGENERIC) {
			precision--
			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 int32(int32(xtype)) == int32(etEXP) {
			e2 = 0
		} else {
			e2 = (*(*TFpDecode)(unsafe.Pointer(bp + 72))).FiDP - int32(1)
		}
		bufpt = bp
		/* Size of a temporary buffer needed */
		if e2 > 0 {
			v58 = e2
		} else {
			v58 = 0
		}
		szBufNeeded = int64(v58) + int64(int64(precision)) + int64(int64(width)) + int64(15)
		if cThousand != 0 && e2 > 0 {
			szBufNeeded += int64((e2 + int32(2)) / int32(3))
		}
		if szBufNeeded > int64(SQLITE_PRINT_BUF_SIZE) {
			v59 = _printfTempBuf(tls, pAccum, szBufNeeded)
			zExtra = v59
			bufpt = v59
			if bufpt == uintptr(0) {
				return
			}
		}
		zOut = bufpt
		if precision > 0 {
			v60 = int32(1)
		} else {
			v60 = 0
		}
		flag_dp = uint8(v60 | int32(int32(flag_alternateform)) | int32(int32(flag_altform2)))
		/* The sign in front of the number */
		if prefix != 0 {
			v61 = bufpt
			bufpt++
			*(*int8)(unsafe.Pointer(v61)) = prefix
		}
		/* Digits prior to the decimal point */
		j = 0
		if e2 < 0 {
			v62 = bufpt
			bufpt++
			*(*int8)(unsafe.Pointer(v62)) = int8('0')
		} else {
			for {
				if !(e2 >= 0) {
					break
				}
				v64 = bufpt
				bufpt++
				if j < (*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fn {
					v66 = j
					j++
					v65 = int32(*(*int8)(unsafe.Pointer((*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fz + uintptr(v66))))
				} else {
					v65 = int32('0')
				}
				*(*int8)(unsafe.Pointer(v64)) = int8(v65)
				if cThousand != 0 && e2%int32(3) == 0 && e2 > int32(1) {
					v67 = bufpt
					bufpt++
					*(*int8)(unsafe.Pointer(v67)) = int8(',')
				}
				goto _63
			_63:
				;
				e2--
			}
		}
		/* The decimal point */
		if flag_dp != 0 {
			v68 = bufpt
			bufpt++
			*(*int8)(unsafe.Pointer(v68)) = int8('.')
		}
		/* "0" digits after the decimal point but before the first
		 ** significant digit of the number */
		e2++
		for {
			if !(e2 < 0 && precision > 0) {
				break
			}
			v70 = bufpt
			bufpt++
			*(*int8)(unsafe.Pointer(v70)) = int8('0')
			goto _69
		_69:
			;
			precision--
			e2++
		}
		/* Significant digits after the decimal point */
		for {
			v71 = precision
			precision--
			if !(v71 > 0) {
				break
			}
			v72 = bufpt
			bufpt++
			if j < (*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fn {
				v74 = j
				j++
				v73 = int32(*(*int8)(unsafe.Pointer((*(*TFpDecode)(unsafe.Pointer(bp + 72))).Fz + uintptr(v74))))
			} else {
				v73 = int32('0')
			}
			*(*int8)(unsafe.Pointer(v72)) = int8(v73)
		}
		/* Remove trailing zeros and the "." if no digits follow the "." */
		if flag_rtz != 0 && flag_dp != 0 {
			for int32(*(*int8)(unsafe.Pointer(bufpt + uintptr(-libc.Int32FromInt32(1))))) == int32('0') {
				bufpt--
				v75 = bufpt
				*(*int8)(unsafe.Pointer(v75)) = 0
			}
			if int32(*(*int8)(unsafe.Pointer(bufpt + uintptr(-libc.Int32FromInt32(1))))) == int32('.') {
				if flag_altform2 != 0 {
					v76 = bufpt
					bufpt++
					*(*int8)(unsafe.Pointer(v76)) = int8('0')
				} else {
					bufpt--
					v77 = bufpt
					*(*int8)(unsafe.Pointer(v77)) = 0
				}
			}
		}
		/* Add the "eNNN" suffix */
		if int32(int32(xtype)) == int32(etEXP) {
			exp = (*(*TFpDecode)(unsafe.Pointer(bp + 72))).FiDP - int32(1)
			v78 = bufpt
			bufpt++
			*(*int8)(unsafe.Pointer(v78)) = _aDigits[(*Tet_info)(unsafe.Pointer(infop)).Fcharset]
			if exp < 0 {
				v79 = bufpt
				bufpt++
				*(*int8)(unsafe.Pointer(v79)) = int8('-')
				exp = -exp
			} else {
				v80 = bufpt
				bufpt++
				*(*int8)(unsafe.Pointer(v80)) = int8('+')
			}
			if exp >= int32(100) {
				v81 = bufpt
				bufpt++
				*(*int8)(unsafe.Pointer(v81)) = int8(exp/libc.Int32FromInt32(100) + libc.Int32FromUint8('0')) /* 100's digit */
				exp %= int32(100)
			}
			v82 = bufpt
			bufpt++
			*(*int8)(unsafe.Pointer(v82)) = int8(exp/libc.Int32FromInt32(10) + libc.Int32FromUint8('0')) /* 10's digit */
			v83 = bufpt
			bufpt++
			*(*int8)(unsafe.Pointer(v83)) = int8(exp%libc.Int32FromInt32(10) + libc.Int32FromUint8('0')) /* 1's digit */
		}
		*(*int8)(unsafe.Pointer(bufpt)) = 0
		/* The converted number is in buf[] and zero terminated. Output it.
		 ** Note that the number is in the usual order, not reversed as with
		 ** integer conversions. */
		length = int32(int32(bufpt)) - int32(int32(zOut))
		bufpt = zOut
		/* Special case:  Add leading zeros if the flag_zeropad flag is
		 ** set and we are not left justified */
		if flag_zeropad != 0 && !(flag_leftjustify != 0) && length < width {
			nPad = width - length
			i = width
			for {
				if !(i >= nPad) {
					break
				}
				*(*int8)(unsafe.Pointer(bufpt + uintptr(i))) = *(*int8)(unsafe.Pointer(bufpt + uintptr(i-nPad)))
				goto _84
			_84:
				;
				i--
			}
			i = libc.BoolInt32(int32(int32(prefix)) != 0)
			for {
				v85 = nPad
				nPad--
				if !(v85 != 0) {
					break
				}
				v86 = i
				i++
				*(*int8)(unsafe.Pointer(bufpt + uintptr(v86))) = int8('0')
			}
			length = width
		}
		goto _44
	_33:
		;
		if !(bArgList != 0) {
			*(*int32)(unsafe.Pointer(libc.VaUintptr(&ap))) = int32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
		}
		v87 = libc.Int32FromInt32(0)
		width = v87
		length = v87
		goto _44
	_34:
		;
		(*(*[70]int8)(unsafe.Pointer(bp)))[0] = int8('%')
		bufpt = bp
		length = int32(1)
		goto _44
	_35:
		;
		if bArgList != 0 {
			bufpt = _getTextArg(tls, pArgList)
			length = int32(1)
			if bufpt != 0 {
				v89 = bufpt
				bufpt++
				v88 = int32(*(*int8)(unsafe.Pointer(v89)))
				c = v88
				(*(*[70]int8)(unsafe.Pointer(bp)))[0] = int8(v88)
				if c&int32(0xc0) == int32(0xc0) {
					for length < int32(4) && int32(*(*int8)(unsafe.Pointer(bufpt)))&int32(0xc0) == int32(0x80) {
						v90 = length
						length++
						v91 = bufpt
						bufpt++
						(*(*[70]int8)(unsafe.Pointer(bp)))[v90] = *(*int8)(unsafe.Pointer(v91))
					}
				}
			} else {
				(*(*[70]int8)(unsafe.Pointer(bp)))[0] = 0
			}
		} else {
			ch = libc.VaUint32(&ap)
			if ch < uint32(0x00080) {
				(*(*[70]int8)(unsafe.Pointer(bp)))[0] = int8(ch & uint32(0xff))
				length = int32(1)
			} else {
				if ch < uint32(0x00800) {
					(*(*[70]int8)(unsafe.Pointer(bp)))[0] = int8(int32(0xc0) + int32(uint8(ch>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1f))))
					(*(*[70]int8)(unsafe.Pointer(bp)))[int32(1)] = int8(int32(0x80) + int32(uint8(ch&libc.Uint32FromInt32(0x3f))))
					length = int32(2)
				} else {
					if ch < uint32(0x10000) {
						(*(*[70]int8)(unsafe.Pointer(bp)))[0] = int8(int32(0xe0) + int32(uint8(ch>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0f))))
						(*(*[70]int8)(unsafe.Pointer(bp)))[int32(1)] = int8(int32(0x80) + int32(uint8(ch>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3f))))
						(*(*[70]int8)(unsafe.Pointer(bp)))[int32(2)] = int8(int32(0x80) + int32(uint8(ch&libc.Uint32FromInt32(0x3f))))
						length = int32(3)
					} else {
						(*(*[70]int8)(unsafe.Pointer(bp)))[0] = int8(int32(0xf0) + int32(uint8(ch>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
						(*(*[70]int8)(unsafe.Pointer(bp)))[int32(1)] = int8(int32(0x80) + int32(uint8(ch>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3f))))
						(*(*[70]int8)(unsafe.Pointer(bp)))[int32(2)] = int8(int32(0x80) + int32(uint8(ch>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3f))))
						(*(*[70]int8)(unsafe.Pointer(bp)))[int32(3)] = int8(int32(0x80) + int32(uint8(ch&libc.Uint32FromInt32(0x3f))))
						length = int32(4)
					}
				}
			}
		}
		if precision > int32(1) {
			nPrior = int64(1)
			width -= precision - int32(1)
			if width > int32(1) && !(flag_leftjustify != 0) {
				Xsqlite3_str_appendchar(tls, pAccum, width-int32(1), int8(' '))
				width = 0
			}
			Xsqlite3_str_append(tls, pAccum, bp, length)
			precision--
			for precision > int32(1) {
				if nPrior > int64(precision-int32(1)) {
					nPrior = int64(precision - int32(1))
				}
				nCopyBytes = int64(int64(length)) * nPrior
				if nCopyBytes+int64((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar) >= int64((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc) {
					_sqlite3StrAccumEnlarge(tls, pAccum, nCopyBytes)
				}
				if (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FaccError != 0 {
					break
				}
				Xsqlite3_str_append(tls, pAccum, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText+uintptr(int64((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)-nCopyBytes), int32(int32(nCopyBytes)))
				precision = int32(int64(precision) - nPrior)
				nPrior *= int64(2)
			}
		}
		bufpt = bp
		flag_altform2 = uint8(1)
		goto adjust_width_for_utf8
	_37:
		;
	_36:
		;
		if bArgList != 0 {
			bufpt = _getTextArg(tls, pArgList)
			xtype = uint8(etSTRING)
		} else {
			bufpt = libc.VaUintptr(&ap)
		}
		if bufpt == uintptr(0) {
			bufpt = __ccgo_ts + 1672
		} else {
			if int32(int32(xtype)) == int32(etDYNSTRING) {
				if (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar == uint32(0) && (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc != 0 && width == 0 && precision < 0 && int32((*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 = uint32(_sqlite3DbMallocSize(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, bufpt))
					(*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar = uint32(int32(0x7fffffff) & int32(libc.Xstrlen(tls, bufpt)))
					p92 = pAccum + 21
					*(*Tu8)(unsafe.Pointer(p92)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p92))) | libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED))
					length = 0
					goto _44
				}
				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 {
					v93 = precision
					precision--
					if !(v93 > 0 && *(*uint8)(unsafe.Pointer(z)) != 0) {
						break
					}
					v94 = z
					z++
					if int32(*(*uint8)(unsafe.Pointer(v94))) >= int32(0xc0) {
						for int32(*(*uint8)(unsafe.Pointer(z)))&int32(0xc0) == int32(0x80) {
							z++
						}
					}
				}
				length = int32(int32(z)) - int32(bufpt)
			} else {
				length = 0
				for {
					if !(length < precision && *(*int8)(unsafe.Pointer(bufpt + uintptr(length))) != 0) {
						break
					}
					goto _95
				_95:
					;
					length++
				}
			}
		} else {
			length = int32(0x7fffffff) & int32(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 {
				v96 = ii
				ii--
				if int32(*(*int8)(unsafe.Pointer(bufpt + uintptr(v96))))&int32(0xc0) == int32(0x80) {
					width++
				}
			}
		}
		goto _44
	_40:
		; /* %q: Escape ' characters */
	_39:
		; /* %Q: Escape ' and enclose in '...' */
	_38:
		;
		if int32(int32(xtype)) == int32(etSQLESCAPE3) {
			v97 = int32('"')
		} else {
			v97 = int32('\'')
		}
		q = int8(v97)
		if bArgList != 0 {
			escarg = _getTextArg(tls, pArgList)
		} else {
			escarg = libc.VaUintptr(&ap)
		}
		isnull = libc.BoolInt32(escarg == uintptr(0))
		if isnull != 0 {
			if int32(int32(xtype)) == int32(etSQLESCAPE2) {
				v98 = __ccgo_ts + 1673
			} else {
				v98 = __ccgo_ts + 1678
			}
			escarg = v98
		}
		/* 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(int64(precision))
		v100 = libc.Int64FromInt32(0)
		n1 = v100
		i1 = v100
		for {
			if v102 = k != 0; v102 {
				v101 = *(*int8)(unsafe.Pointer(escarg + uintptr(i1)))
				ch1 = v101
			}
			if !(v102 && int32(v101) != 0) {
				break
			}
			if int32(int32(ch1)) == int32(int32(q)) {
				n1++
			}
			if flag_altform2 != 0 && int32(int32(ch1))&int32(0xc0) == int32(0xc0) {
				for int32(*(*int8)(unsafe.Pointer(escarg + uintptr(i1+int64(1)))))&int32(0xc0) == int32(0x80) {
					i1++
				}
			}
			goto _99
		_99:
			;
			i1++
			k--
		}
		needQuote = libc.BoolInt32(!(isnull != 0) && int32(int32(xtype)) == int32(etSQLESCAPE2))
		n1 += i1 + int64(3)
		if n1 > int64(SQLITE_PRINT_BUF_SIZE) {
			v103 = _printfTempBuf(tls, pAccum, n1)
			zExtra = v103
			bufpt = v103
			if bufpt == uintptr(0) {
				return
			}
		} else {
			bufpt = bp
		}
		j1 = 0
		if needQuote != 0 {
			v104 = j1
			j1++
			*(*int8)(unsafe.Pointer(bufpt + uintptr(v104))) = q
		}
		k = i1
		i1 = 0
		for {
			if !(i1 < k) {
				break
			}
			v106 = j1
			j1++
			v107 = *(*int8)(unsafe.Pointer(escarg + uintptr(i1)))
			ch1 = v107
			*(*int8)(unsafe.Pointer(bufpt + uintptr(v106))) = v107
			if int32(int32(ch1)) == int32(int32(q)) {
				v108 = j1
				j1++
				*(*int8)(unsafe.Pointer(bufpt + uintptr(v108))) = ch1
			}
			goto _105
		_105:
			;
			i1++
		}
		if needQuote != 0 {
			v109 = j1
			j1++
			*(*int8)(unsafe.Pointer(bufpt + uintptr(v109))) = q
		}
		*(*int8)(unsafe.Pointer(bufpt + uintptr(j1))) = 0
		length = int32(int32(j1))
		goto adjust_width_for_utf8
	_41:
		;
		if int32((*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&uint32(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, int32((*TToken)(unsafe.Pointer(pToken)).Fn))
				_sqlite3RecordErrorByteOffset(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, (*TToken)(unsafe.Pointer(pToken)).Fz)
			}
		}
		v110 = libc.Int32FromInt32(0)
		width = v110
		length = v110
		goto _44
	_42:
		;
		if int32((*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 (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase != 0 {
					Xsqlite3_str_appendall(tls, pAccum, (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase)
					Xsqlite3_str_append(tls, pAccum, __ccgo_ts+1685, 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 {
					pSel = (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect
					/* Because of tag-20240424-1 */
					if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_NestedFrom) != 0 {
						Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1687, 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+1697, libc.VaList(bp+120, *(*Tu32)(unsafe.Pointer(pItem + 64))))
						} else {
							Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1718, libc.VaList(bp+120, (*TSelect)(unsafe.Pointer(pSel)).FselId))
						}
					}
				}
			}
		}
		v111 = libc.Int32FromInt32(0)
		width = v111
		length = v111
		goto _44
	_43:
		;
		return
	_44:
		; /* 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 -= length
		if width > 0 {
			if !(flag_leftjustify != 0) {
				Xsqlite3_str_appendchar(tls, pAccum, width, int8(' '))
			}
			Xsqlite3_str_append(tls, pAccum, bufpt, length)
			if flag_leftjustify != 0 {
				Xsqlite3_str_appendchar(tls, pAccum, width, int8(' '))
			}
		} 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++
	} /* End for loop over the format string */
}

var _zOrd = [9]int8{'t', 'h', 's', 't', 'n', 'd', 'r', 'd'}

/* End of function */

// C documentation
//
//	/*
//	** The z string points to the first character of a token that is
//	** associated with an error.  If db does not already have an error
//	** byte offset recorded, try to compute the error byte offset for
//	** z and set the error byte offset in db.
//	*/
func _sqlite3RecordErrorByteOffset(tls *libc.TLS, db uintptr, z uintptr) {
	var pParse, zEnd, zText uintptr
	_, _, _ = pParse, zEnd, zText
	if db == uintptr(0) {
		return
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset != -int32(2) {
		return
	}
	pParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
	if pParse == uintptr(0) {
		return
	}
	zText = (*TParse)(unsafe.Pointer(pParse)).FzTail
	if zText == uintptr(0) {
		return
	}
	zEnd = zText + uintptr(libc.Xstrlen(tls, zText))
	if uint32(z) >= uint32(zText) && uint32(z) < uint32(zEnd) {
		(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = int32(int32(z)) - int32(int32(zText))
	}
}

// C documentation
//
//	/*
//	** If pExpr has a byte offset for the start of a token, record that as
//	** as the error offset.
//	*/
func _sqlite3RecordErrorOffsetOfExpr(tls *libc.TLS, db uintptr, pExpr uintptr) {
	for pExpr != 0 && ((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) || *(*int32)(unsafe.Pointer(pExpr + 36)) <= 0) {
		pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	}
	if pExpr == uintptr(0) {
		return
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = *(*int32)(unsafe.Pointer(pExpr + 36))
}

// C documentation
//
//	/*
//	** Enlarge the memory allocation on a StrAccum object so that it is
//	** able to accept at least N more bytes of text.
//	**
//	** Return the number of bytes of text that StrAccum is able to accept
//	** after the attempted enlargement.  The value returned might be zero.
//	*/
func _sqlite3StrAccumEnlarge(tls *libc.TLS, p uintptr, N Ti64) (r int32) {
	var szNew Ti64
	var zNew, zOld, v1, p2 uintptr
	_, _, _, _, _ = szNew, zNew, zOld, v1, p2
	/* Only called if really needed */
	if (*TStrAccum)(unsafe.Pointer(p)).FaccError != 0 {
		return 0
	}
	if (*TStrAccum)(unsafe.Pointer(p)).FmxAlloc == uint32(0) {
		_sqlite3StrAccumSetError(tls, p, uint8(SQLITE_TOOBIG))
		return int32((*TStrAccum)(unsafe.Pointer(p)).FnAlloc - (*TStrAccum)(unsafe.Pointer(p)).FnChar - uint32(1))
	} else {
		if int32((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&int32(SQLITE_PRINTF_MALLOCED) != 0 {
			v1 = (*TStrAccum)(unsafe.Pointer(p)).FzText
		} else {
			v1 = uintptr(0)
		}
		zOld = v1
		szNew = int64((*TStrAccum)(unsafe.Pointer(p)).FnChar) + N + int64(1)
		if szNew+int64((*TStrAccum)(unsafe.Pointer(p)).FnChar) <= int64((*TStrAccum)(unsafe.Pointer(p)).FmxAlloc) {
			/* Force exponential buffer size growth as long as it does not overflow,
			 ** to avoid having to call this routine too often */
			szNew += int64((*TStrAccum)(unsafe.Pointer(p)).FnChar)
		}
		if szNew > int64((*TStrAccum)(unsafe.Pointer(p)).FmxAlloc) {
			Xsqlite3_str_reset(tls, p)
			_sqlite3StrAccumSetError(tls, p, uint8(SQLITE_TOOBIG))
			return 0
		} else {
			(*TStrAccum)(unsafe.Pointer(p)).FnAlloc = uint32(int32(int32(szNew)))
		}
		if (*TStrAccum)(unsafe.Pointer(p)).Fdb != 0 {
			zNew = _sqlite3DbRealloc(tls, (*TStrAccum)(unsafe.Pointer(p)).Fdb, zOld, uint64((*TStrAccum)(unsafe.Pointer(p)).FnAlloc))
		} else {
			zNew = _sqlite3Realloc(tls, zOld, uint64((*TStrAccum)(unsafe.Pointer(p)).FnAlloc))
		}
		if zNew != 0 {
			if !(int32((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED) != libc.Int32FromInt32(0)) && (*TStrAccum)(unsafe.Pointer(p)).FnChar > uint32(0) {
				libc.Xmemcpy(tls, zNew, (*TStrAccum)(unsafe.Pointer(p)).FzText, (*TStrAccum)(unsafe.Pointer(p)).FnChar)
			}
			(*TStrAccum)(unsafe.Pointer(p)).FzText = zNew
			(*TStrAccum)(unsafe.Pointer(p)).FnAlloc = uint32(_sqlite3DbMallocSize(tls, (*TStrAccum)(unsafe.Pointer(p)).Fdb, zNew))
			p2 = p + 21
			*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED))
		} else {
			Xsqlite3_str_reset(tls, p)
			_sqlite3StrAccumSetError(tls, p, uint8(SQLITE_NOMEM))
			return 0
		}
	}
	return int32(int32(N))
}

// C documentation
//
//	/*
//	** Append N copies of character c to the given string buffer.
//	*/
func Xsqlite3_str_appendchar(tls *libc.TLS, p uintptr, N int32, c int8) {
	var v1, v3 int32
	var v2 bool
	var v4 Tu32
	var v5 uintptr
	_, _, _, _, _ = v1, v2, v3, v4, v5
	if v2 = int64((*Tsqlite3_str)(unsafe.Pointer(p)).FnChar)+int64(int64(N)) >= int64((*Tsqlite3_str)(unsafe.Pointer(p)).FnAlloc); v2 {
		v1 = _sqlite3StrAccumEnlarge(tls, p, int64(int64(N)))
		N = v1
	}
	if v2 && v1 <= 0 {
		return
	}
	for {
		v3 = N
		N--
		if !(v3 > 0) {
			break
		}
		v5 = p + 16
		v4 = *(*Tu32)(unsafe.Pointer(v5))
		*(*Tu32)(unsafe.Pointer(v5))++
		*(*int8)(unsafe.Pointer((*Tsqlite3_str)(unsafe.Pointer(p)).FzText + uintptr(v4))) = c
	}
}

// C documentation
//
//	/*
//	** The StrAccum "p" is not large enough to accept N new bytes of z[].
//	** So enlarge if first, then do the append.
//	**
//	** This is a helper routine to sqlite3_str_append() that does special-case
//	** work (enlarging the buffer) using tail recursion, so that the
//	** sqlite3_str_append() routine can use fast calling semantics.
//	*/
func _enlargeAndAppend(tls *libc.TLS, p uintptr, z uintptr, N int32) {
	N = _sqlite3StrAccumEnlarge(tls, p, int64(int64(N)))
	if N > 0 {
		libc.Xmemcpy(tls, (*TStrAccum)(unsafe.Pointer(p)).FzText+uintptr((*TStrAccum)(unsafe.Pointer(p)).FnChar), z, uint32(uint32(N)))
		*(*Tu32)(unsafe.Pointer(p + 16)) += uint32(uint32(N))
	}
}

// C documentation
//
//	/*
//	** Append N bytes of text from z to the StrAccum object.  Increase the
//	** size of the memory allocation for StrAccum if necessary.
//	*/
func Xsqlite3_str_append(tls *libc.TLS, p uintptr, z uintptr, N int32) {
	if (*Tsqlite3_str)(unsafe.Pointer(p)).FnChar+uint32(uint32(N)) >= (*Tsqlite3_str)(unsafe.Pointer(p)).FnAlloc {
		_enlargeAndAppend(tls, p, z, N)
	} else {
		if N != 0 {
			*(*Tu32)(unsafe.Pointer(p + 16)) += uint32(uint32(N))
			libc.Xmemcpy(tls, (*Tsqlite3_str)(unsafe.Pointer(p)).FzText+uintptr((*Tsqlite3_str)(unsafe.Pointer(p)).FnChar-uint32(uint32(N))), z, uint32(uint32(N)))
		}
	}
}

// C documentation
//
//	/*
//	** Append the complete text of zero-terminated string z[] to the p string.
//	*/
func Xsqlite3_str_appendall(tls *libc.TLS, p uintptr, z uintptr) {
	Xsqlite3_str_append(tls, p, z, _sqlite3Strlen30(tls, z))
}

// C documentation
//
//	/*
//	** Finish off a string by making sure it is zero-terminated.
//	** Return a pointer to the resulting string.  Return a NULL
//	** pointer if any kind of error was encountered.
//	*/
func _strAccumFinishRealloc(tls *libc.TLS, p uintptr) (r uintptr) {
	var zText, p1 uintptr
	_, _ = zText, p1
	zText = _sqlite3DbMallocRaw(tls, (*TStrAccum)(unsafe.Pointer(p)).Fdb, uint64((*TStrAccum)(unsafe.Pointer(p)).FnChar+uint32(1)))
	if zText != 0 {
		libc.Xmemcpy(tls, zText, (*TStrAccum)(unsafe.Pointer(p)).FzText, (*TStrAccum)(unsafe.Pointer(p)).FnChar+uint32(1))
		p1 = p + 21
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED))
	} else {
		_sqlite3StrAccumSetError(tls, p, uint8(SQLITE_NOMEM))
	}
	(*TStrAccum)(unsafe.Pointer(p)).FzText = zText
	return zText
}

func _sqlite3StrAccumFinish(tls *libc.TLS, p uintptr) (r uintptr) {
	if (*TStrAccum)(unsafe.Pointer(p)).FzText != 0 {
		*(*int8)(unsafe.Pointer((*TStrAccum)(unsafe.Pointer(p)).FzText + uintptr((*TStrAccum)(unsafe.Pointer(p)).FnChar))) = 0
		if (*TStrAccum)(unsafe.Pointer(p)).FmxAlloc > uint32(0) && !(int32((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED) != libc.Int32FromInt32(0)) {
			return _strAccumFinishRealloc(tls, p)
		}
	}
	return (*TStrAccum)(unsafe.Pointer(p)).FzText
}

// C documentation
//
//	/*
//	** Use the content of the StrAccum passed as the second argument
//	** as the result of an SQL function.
//	*/
func _sqlite3ResultStrAccum(tls *libc.TLS, pCtx uintptr, p uintptr) {
	if (*TStrAccum)(unsafe.Pointer(p)).FaccError != 0 {
		Xsqlite3_result_error_code(tls, pCtx, int32((*TStrAccum)(unsafe.Pointer(p)).FaccError))
		Xsqlite3_str_reset(tls, p)
	} else {
		if int32((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&int32(SQLITE_PRINTF_MALLOCED) != 0 {
			Xsqlite3_result_text(tls, pCtx, (*TStrAccum)(unsafe.Pointer(p)).FzText, int32((*TStrAccum)(unsafe.Pointer(p)).FnChar), __ccgo_fp(_sqlite3OomClear))
		} else {
			Xsqlite3_result_text(tls, pCtx, __ccgo_ts+1672, 0, libc.UintptrFromInt32(0))
			Xsqlite3_str_reset(tls, p)
		}
	}
}

// C documentation
//
//	/*
//	** This singleton is an sqlite3_str object that is returned if
//	** sqlite3_malloc() fails to provide space for a real one.  This
//	** sqlite3_str object accepts no new text and always returns
//	** an SQLITE_NOMEM error.
//	*/
var _sqlite3OomStr = Tsqlite3_str{
	FaccError: uint8(SQLITE_NOMEM),
}

// C documentation
//
//	/* Finalize a string created using sqlite3_str_new().
//	*/
func Xsqlite3_str_finish(tls *libc.TLS, p uintptr) (r uintptr) {
	var z uintptr
	_ = z
	if p != uintptr(0) && p != uintptr(unsafe.Pointer(&_sqlite3OomStr)) {
		z = _sqlite3StrAccumFinish(tls, p)
		Xsqlite3_free(tls, p)
	} else {
		z = uintptr(0)
	}
	return z
}

// C documentation
//
//	/* Return any error code associated with p */
func Xsqlite3_str_errcode(tls *libc.TLS, p uintptr) (r int32) {
	var v1 int32
	_ = v1
	if p != 0 {
		v1 = int32((*Tsqlite3_str)(unsafe.Pointer(p)).FaccError)
	} else {
		v1 = int32(SQLITE_NOMEM)
	}
	return v1
}

// C documentation
//
//	/* Return the current length of p in bytes */
func Xsqlite3_str_length(tls *libc.TLS, p uintptr) (r int32) {
	var v1 uint32
	_ = v1
	if p != 0 {
		v1 = (*Tsqlite3_str)(unsafe.Pointer(p)).FnChar
	} else {
		v1 = uint32(0)
	}
	return int32(v1)
}

// C documentation
//
//	/* Return the current value for p */
func Xsqlite3_str_value(tls *libc.TLS, p uintptr) (r uintptr) {
	if p == uintptr(0) || (*Tsqlite3_str)(unsafe.Pointer(p)).FnChar == uint32(0) {
		return uintptr(0)
	}
	*(*int8)(unsafe.Pointer((*Tsqlite3_str)(unsafe.Pointer(p)).FzText + uintptr((*Tsqlite3_str)(unsafe.Pointer(p)).FnChar))) = 0
	return (*Tsqlite3_str)(unsafe.Pointer(p)).FzText
}

// C documentation
//
//	/*
//	** Reset an StrAccum string.  Reclaim all malloced memory.
//	*/
func Xsqlite3_str_reset(tls *libc.TLS, p uintptr) {
	var p1 uintptr
	_ = p1
	if int32((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&int32(SQLITE_PRINTF_MALLOCED) != 0 {
		_sqlite3DbFree(tls, (*TStrAccum)(unsafe.Pointer(p)).Fdb, (*TStrAccum)(unsafe.Pointer(p)).FzText)
		p1 = p + 21
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED))
	}
	(*TStrAccum)(unsafe.Pointer(p)).FnAlloc = uint32(0)
	(*TStrAccum)(unsafe.Pointer(p)).FnChar = uint32(0)
	(*TStrAccum)(unsafe.Pointer(p)).FzText = uintptr(0)
}

// C documentation
//
//	/*
//	** Initialize a string accumulator.
//	**
//	** p:     The accumulator to be initialized.
//	** db:    Pointer to a database connection.  May be NULL.  Lookaside
//	**        memory is used if not NULL. db->mallocFailed is set appropriately
//	**        when not NULL.
//	** zBase: An initial buffer.  May be NULL in which case the initial buffer
//	**        is malloced.
//	** n:     Size of zBase in bytes.  If total space requirements never exceed
//	**        n then no memory allocations ever occur.
//	** mx:    Maximum number of bytes to accumulate.  If mx==0 then no memory
//	**        allocations will ever occur.
//	*/
func _sqlite3StrAccumInit(tls *libc.TLS, p uintptr, db uintptr, zBase uintptr, n int32, mx int32) {
	(*TStrAccum)(unsafe.Pointer(p)).FzText = zBase
	(*TStrAccum)(unsafe.Pointer(p)).Fdb = db
	(*TStrAccum)(unsafe.Pointer(p)).FnAlloc = uint32(uint32(n))
	(*TStrAccum)(unsafe.Pointer(p)).FmxAlloc = uint32(uint32(mx))
	(*TStrAccum)(unsafe.Pointer(p)).FnChar = uint32(0)
	(*TStrAccum)(unsafe.Pointer(p)).FaccError = uint8(0)
	(*TStrAccum)(unsafe.Pointer(p)).FprintfFlags = uint8(0)
}

// C documentation
//
//	/* Allocate and initialize a new dynamic string object */
func Xsqlite3_str_new(tls *libc.TLS, db uintptr) (r uintptr) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = Xsqlite3_malloc64(tls, uint64(24))
	if p != 0 {
		if db != 0 {
			v1 = *(*int32)(unsafe.Pointer(db + 120))
		} else {
			v1 = int32(SQLITE_MAX_LENGTH)
		}
		_sqlite3StrAccumInit(tls, p, uintptr(0), uintptr(0), 0, v1)
	} else {
		p = uintptr(unsafe.Pointer(&_sqlite3OomStr))
	}
	return p
}

// C documentation
//
//	/*
//	** Print into memory obtained from sqliteMalloc().  Use the internal
//	** %-conversion extensions.
//	*/
func _sqlite3VMPrintf(tls *libc.TLS, db uintptr, zFormat uintptr, ap Tva_list) (r uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var z uintptr
	var _ /* acc at bp+72 */ TStrAccum
	var _ /* zBase at bp+0 */ [70]int8
	_ = z
	_sqlite3StrAccumInit(tls, bp+72, db, bp, int32(70), *(*int32)(unsafe.Pointer(db + 120)))
	(*(*TStrAccum)(unsafe.Pointer(bp + 72))).FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
	Xsqlite3_str_vappendf(tls, bp+72, zFormat, ap)
	z = _sqlite3StrAccumFinish(tls, bp+72)
	if int32((*(*TStrAccum)(unsafe.Pointer(bp + 72))).FaccError) == int32(SQLITE_NOMEM) {
		_sqlite3OomFault(tls, db)
	}
	return z
}

// C documentation
//
//	/*
//	** Print into memory obtained from sqliteMalloc().  Use the internal
//	** %-conversion extensions.
//	*/
func _sqlite3MPrintf(tls *libc.TLS, db uintptr, zFormat uintptr, va uintptr) (r uintptr) {
	var ap Tva_list
	var z uintptr
	_, _ = ap, z
	ap = va
	z = _sqlite3VMPrintf(tls, db, zFormat, ap)
	_ = ap
	return z
}

// C documentation
//
//	/*
//	** Print into memory obtained from sqlite3_malloc().  Omit the internal
//	** %-conversion extensions.
//	*/
func Xsqlite3_vmprintf(tls *libc.TLS, zFormat uintptr, ap Tva_list) (r uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var z uintptr
	var _ /* acc at bp+72 */ TStrAccum
	var _ /* zBase at bp+0 */ [70]int8
	_ = z
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	_sqlite3StrAccumInit(tls, bp+72, uintptr(0), bp, int32(70), int32(SQLITE_MAX_LENGTH))
	Xsqlite3_str_vappendf(tls, bp+72, zFormat, ap)
	z = _sqlite3StrAccumFinish(tls, bp+72)
	return z
}

// C documentation
//
//	/*
//	** Print into memory obtained from sqlite3_malloc()().  Omit the internal
//	** %-conversion extensions.
//	*/
func Xsqlite3_mprintf(tls *libc.TLS, zFormat uintptr, va uintptr) (r uintptr) {
	var ap Tva_list
	var z uintptr
	_, _ = ap, z
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	ap = va
	z = Xsqlite3_vmprintf(tls, zFormat, ap)
	_ = ap
	return z
}

// C documentation
//
//	/*
//	** sqlite3_snprintf() works like snprintf() except that it ignores the
//	** current locale settings.  This is important for SQLite because we
//	** are not able to use a "," as the decimal point in place of "." as
//	** specified by some locales.
//	**
//	** Oops:  The first two arguments of sqlite3_snprintf() are backwards
//	** from the snprintf() standard.  Unfortunately, it is too late to change
//	** this without breaking compatibility, so we just have to live with the
//	** mistake.
//	**
//	** sqlite3_vsnprintf() is the varargs version.
//	*/
func Xsqlite3_vsnprintf(tls *libc.TLS, n int32, zBuf uintptr, zFormat uintptr, ap Tva_list) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* acc at bp+0 */ TStrAccum
	if n <= 0 {
		return zBuf
	}
	_sqlite3StrAccumInit(tls, bp, uintptr(0), zBuf, n, 0)
	Xsqlite3_str_vappendf(tls, bp, zFormat, ap)
	*(*int8)(unsafe.Pointer(zBuf + uintptr((*(*TStrAccum)(unsafe.Pointer(bp))).FnChar))) = 0
	return zBuf
}

func Xsqlite3_snprintf(tls *libc.TLS, n int32, zBuf uintptr, zFormat uintptr, va uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap Tva_list
	var _ /* acc at bp+0 */ TStrAccum
	_ = ap
	if n <= 0 {
		return zBuf
	}
	_sqlite3StrAccumInit(tls, bp, uintptr(0), zBuf, n, 0)
	ap = va
	Xsqlite3_str_vappendf(tls, bp, zFormat, ap)
	_ = ap
	*(*int8)(unsafe.Pointer(zBuf + uintptr((*(*TStrAccum)(unsafe.Pointer(bp))).FnChar))) = 0
	return zBuf
}

// C documentation
//
//	/*
//	** This is the routine that actually formats the sqlite3_log() message.
//	** We house it in a separate routine from sqlite3_log() to avoid using
//	** stack space on small-stack systems when logging is disabled.
//	**
//	** sqlite3_log() must render into a static buffer.  It cannot dynamically
//	** allocate memory because it might be called while the memory allocator
//	** mutex is held.
//	**
//	** sqlite3_str_vappendf() might ask for *temporary* memory allocations for
//	** certain format characters (%q) or for very large precisions or widths.
//	** Care must be taken that any sqlite3_log() calls that occur while the
//	** memory mutex is held do not use these mechanisms.
//	*/
func _renderLogMsg(tls *libc.TLS, iErrCode int32, zFormat uintptr, ap Tva_list) {
	bp := tls.Alloc(240)
	defer tls.Free(240)
	var _ /* acc at bp+0 */ TStrAccum
	var _ /* zMsg at bp+24 */ [210]int8 /* Complete log message */
	_sqlite3StrAccumInit(tls, bp, uintptr(0), bp+24, int32(210), 0)
	Xsqlite3_str_vappendf(tls, bp, zFormat, ap)
	(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.FxLog})))(tls, _sqlite3Config.FpLogArg, iErrCode, _sqlite3StrAccumFinish(tls, bp))
}

// C documentation
//
//	/*
//	** Format and write a message to the log if logging is enabled.
//	*/
func Xsqlite3_log(tls *libc.TLS, iErrCode int32, zFormat uintptr, va uintptr) {
	var ap Tva_list
	_ = ap /* Vararg list */
	if _sqlite3Config.FxLog != 0 {
		ap = va
		_renderLogMsg(tls, iErrCode, zFormat, ap)
		_ = ap
	}
}

// C documentation
//
//	/*
//	** variable-argument wrapper around sqlite3_str_vappendf(). The bFlags argument
//	** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
//	*/
func Xsqlite3_str_appendf(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Tva_list
	_ = ap
	ap = va
	Xsqlite3_str_vappendf(tls, p, zFormat, ap)
	_ = ap
}

/*****************************************************************************
** Reference counted string/blob storage
*****************************************************************************/

// C documentation
//
//	/*
//	** Increase the reference count of the string by one.
//	**
//	** The input parameter is returned.
//	*/
func _sqlite3RCStrRef(tls *libc.TLS, z uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = z
	p -= 8
	(*TRCStr)(unsafe.Pointer(p)).FnRCRef++
	return z
}

// C documentation
//
//	/*
//	** Decrease the reference count by one.  Free the string when the
//	** reference count reaches zero.
//	*/
func _sqlite3RCStrUnref(tls *libc.TLS, z uintptr) {
	var p uintptr
	_ = p
	p = z
	p -= 8
	if (*TRCStr)(unsafe.Pointer(p)).FnRCRef >= uint64(2) {
		(*TRCStr)(unsafe.Pointer(p)).FnRCRef--
	} else {
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Create a new string that is capable of holding N bytes of text, not counting
//	** the zero byte at the end.  The string is uninitialized.
//	**
//	** The reference count is initially 1.  Call sqlite3RCStrUnref() to free the
//	** newly allocated string.
//	**
//	** This routine returns 0 on an OOM.
//	*/
func _sqlite3RCStrNew(tls *libc.TLS, N Tu64) (r uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_malloc64(tls, N+uint64(8)+uint64(1))
	if p == uintptr(0) {
		return uintptr(0)
	}
	(*TRCStr)(unsafe.Pointer(p)).FnRCRef = uint64(1)
	return p + 1*8
}

// C documentation
//
//	/*
//	** Change the size of the string so that it is able to hold N bytes.
//	** The string might be reallocated, so return the new allocation.
//	*/
func _sqlite3RCStrResize(tls *libc.TLS, z uintptr, N Tu64) (r uintptr) {
	var p, pNew uintptr
	_, _ = p, pNew
	p = z
	p -= 8
	pNew = Xsqlite3_realloc64(tls, p, N+uint64(8)+uint64(1))
	if pNew == uintptr(0) {
		Xsqlite3_free(tls, p)
		return uintptr(0)
	} else {
		return pNew + 1*8
	}
	return r
}

/************** End of printf.c **********************************************/
/************** Begin file treeview.c ****************************************/
/*
** 2015-06-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.
**
*************************************************************************
**
** This file contains C code to implement the TreeView debugging routines.
** These routines print a parse tree to standard output for debugging and
** analysis.
**
** The interfaces in this file is only available when compiling
** with SQLITE_DEBUG.
 */
/* #include "sqliteInt.h" */

/************** End of treeview.c ********************************************/
/************** Begin file random.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 code to implement a pseudo-random number
** generator (PRNG) for SQLite.
**
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/* All threads share a single random number generator.
//	** This structure is the current state of the generator.
//	*/
type Tsqlite3PrngType = struct {
	Fs   [16]Tu32
	Fout [64]Tu8
	Fn   Tu8
}

type sqlite3PrngType = Tsqlite3PrngType

/************** End of printf.c **********************************************/
/************** Begin file treeview.c ****************************************/
/*
** 2015-06-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.
**
*************************************************************************
**
** This file contains C code to implement the TreeView debugging routines.
** These routines print a parse tree to standard output for debugging and
** analysis.
**
** The interfaces in this file is only available when compiling
** with SQLITE_DEBUG.
 */
/* #include "sqliteInt.h" */

/************** End of treeview.c ********************************************/
/************** Begin file random.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 code to implement a pseudo-random number
** generator (PRNG) for SQLite.
**
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/* All threads share a single random number generator.
//	** This structure is the current state of the generator.
//	*/
var _sqlite3Prng Tsqlite3PrngType

// C documentation
//
//	/* The RFC-7539 ChaCha20 block function
//	*/
func _chacha_block(tls *libc.TLS, out uintptr, in uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var i int32
	var _ /* x at bp+0 */ [16]Tu32
	_ = i
	libc.Xmemcpy(tls, bp, in, uint32(64))
	i = 0
	for {
		if !(i < int32(10)) {
			break
		}
		*(*Tu32)(unsafe.Pointer(bp)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]
		*(*Tu32)(unsafe.Pointer(bp + 12*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[0]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 8*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]
		*(*Tu32)(unsafe.Pointer(bp + 4*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(8)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]
		*(*Tu32)(unsafe.Pointer(bp + 12*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[0]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 8*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]
		*(*Tu32)(unsafe.Pointer(bp + 4*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(8)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		*(*Tu32)(unsafe.Pointer(bp + 1*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]
		*(*Tu32)(unsafe.Pointer(bp + 13*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(1)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 9*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]
		*(*Tu32)(unsafe.Pointer(bp + 5*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(9)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp + 1*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]
		*(*Tu32)(unsafe.Pointer(bp + 13*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(1)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 9*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]
		*(*Tu32)(unsafe.Pointer(bp + 5*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(9)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		*(*Tu32)(unsafe.Pointer(bp + 2*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]
		*(*Tu32)(unsafe.Pointer(bp + 14*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(2)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 10*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]
		*(*Tu32)(unsafe.Pointer(bp + 6*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(10)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp + 2*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]
		*(*Tu32)(unsafe.Pointer(bp + 14*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(2)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 10*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]
		*(*Tu32)(unsafe.Pointer(bp + 6*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(10)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		*(*Tu32)(unsafe.Pointer(bp + 3*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]
		*(*Tu32)(unsafe.Pointer(bp + 15*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(3)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 11*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]
		*(*Tu32)(unsafe.Pointer(bp + 7*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(11)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp + 3*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]
		*(*Tu32)(unsafe.Pointer(bp + 15*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(3)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 11*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]
		*(*Tu32)(unsafe.Pointer(bp + 7*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(11)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		*(*Tu32)(unsafe.Pointer(bp)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]
		*(*Tu32)(unsafe.Pointer(bp + 15*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[0]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 10*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]
		*(*Tu32)(unsafe.Pointer(bp + 5*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(10)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]
		*(*Tu32)(unsafe.Pointer(bp + 15*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[0]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 10*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(15)]
		*(*Tu32)(unsafe.Pointer(bp + 5*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(10)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		*(*Tu32)(unsafe.Pointer(bp + 1*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]
		*(*Tu32)(unsafe.Pointer(bp + 12*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(1)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 11*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]
		*(*Tu32)(unsafe.Pointer(bp + 6*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(11)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp + 1*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]
		*(*Tu32)(unsafe.Pointer(bp + 12*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(1)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 11*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(12)]
		*(*Tu32)(unsafe.Pointer(bp + 6*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(11)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		*(*Tu32)(unsafe.Pointer(bp + 2*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]
		*(*Tu32)(unsafe.Pointer(bp + 13*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(2)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 8*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]
		*(*Tu32)(unsafe.Pointer(bp + 7*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(8)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp + 2*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]
		*(*Tu32)(unsafe.Pointer(bp + 13*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(2)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 8*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(13)]
		*(*Tu32)(unsafe.Pointer(bp + 7*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(8)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		*(*Tu32)(unsafe.Pointer(bp + 3*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]
		*(*Tu32)(unsafe.Pointer(bp + 14*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(3)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]<<libc.Int32FromInt32(16) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		*(*Tu32)(unsafe.Pointer(bp + 9*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]
		*(*Tu32)(unsafe.Pointer(bp + 4*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(9)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]<<libc.Int32FromInt32(12) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		*(*Tu32)(unsafe.Pointer(bp + 3*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]
		*(*Tu32)(unsafe.Pointer(bp + 14*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(3)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]<<libc.Int32FromInt32(8) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		*(*Tu32)(unsafe.Pointer(bp + 9*4)) += (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(14)]
		*(*Tu32)(unsafe.Pointer(bp + 4*4)) ^= (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(9)]
		(*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)] = (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]<<libc.Int32FromInt32(7) | (*(*[16]Tu32)(unsafe.Pointer(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		goto _1
	_1:
		;
		i++
	}
	i = 0
	for {
		if !(i < int32(16)) {
			break
		}
		*(*Tu32)(unsafe.Pointer(out + uintptr(i)*4)) = (*(*[16]Tu32)(unsafe.Pointer(bp)))[i] + *(*Tu32)(unsafe.Pointer(in + uintptr(i)*4))
		goto _2
	_2:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Return N random bytes.
//	*/
func Xsqlite3_randomness(tls *libc.TLS, N int32, pBuf uintptr) {
	var mutex, pVfs, zBuf, p1 uintptr
	_, _, _, _ = mutex, pVfs, zBuf, p1
	zBuf = pBuf
	if Xsqlite3_initialize(tls) != 0 {
		return
	}
	mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_PRNG))
	Xsqlite3_mutex_enter(tls, mutex)
	if N <= 0 || pBuf == uintptr(0) {
		*(*Tu32)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Prng)))) = uint32(0)
		Xsqlite3_mutex_leave(tls, mutex)
		return
	}
	/* Initialize the state of the random number generator once,
	 ** the first time this routine is called.
	 */
	if *(*Tu32)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Prng)))) == uint32(0) {
		pVfs = Xsqlite3_vfs_find(tls, uintptr(0))
		libc.Xmemcpy(tls, uintptr(unsafe.Pointer(&_sqlite3Prng)), uintptr(unsafe.Pointer(&_chacha20_init)), uint32(16))
		if pVfs == uintptr(0) {
			libc.Xmemset(tls, uintptr(unsafe.Pointer(&_sqlite3Prng))+4*4, 0, uint32(44))
		} else {
			_sqlite3OsRandomness(tls, pVfs, int32(44), uintptr(unsafe.Pointer(&_sqlite3Prng))+4*4)
		}
		*(*Tu32)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 15*4)) = *(*Tu32)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 12*4))
		*(*Tu32)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 12*4)) = uint32(0)
		_sqlite3Prng.Fn = uint8(0)
	}
	for int32(1) != 0 {
		if N <= int32(_sqlite3Prng.Fn) {
			libc.Xmemcpy(tls, zBuf, uintptr(unsafe.Pointer(&_sqlite3Prng))+64+uintptr(int32(_sqlite3Prng.Fn)-N), uint32(uint32(N)))
			p1 = uintptr(unsafe.Pointer(&_sqlite3Prng)) + 128
			*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) - N)
			break
		}
		if int32(_sqlite3Prng.Fn) > 0 {
			libc.Xmemcpy(tls, zBuf, uintptr(unsafe.Pointer(&_sqlite3Prng))+64, uint32(_sqlite3Prng.Fn))
			N -= int32(_sqlite3Prng.Fn)
			zBuf += uintptr(_sqlite3Prng.Fn)
		}
		*(*Tu32)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 12*4))++
		_chacha_block(tls, uintptr(unsafe.Pointer(&_sqlite3Prng))+64, uintptr(unsafe.Pointer(&_sqlite3Prng)))
		_sqlite3Prng.Fn = uint8(64)
	}
	Xsqlite3_mutex_leave(tls, mutex)
}

var _chacha20_init = [4]Tu32{
	0: uint32(0x61707865),
	1: uint32(0x3320646e),
	2: uint32(0x79622d32),
	3: uint32(0x6b206574),
}

// C documentation
//
//	/*
//	** For testing purposes, we sometimes want to preserve the state of
//	** PRNG and restore the PRNG to its saved state at a later time, or
//	** to reset the PRNG to its initial state.  These routines accomplish
//	** those tasks.
//	**
//	** The sqlite3_test_control() interface calls these routines to
//	** control the PRNG.
//	*/
var _sqlite3SavedPrng Tsqlite3PrngType

func _sqlite3PrngSaveState(tls *libc.TLS) {
	libc.Xmemcpy(tls, uintptr(unsafe.Pointer(&_sqlite3SavedPrng)), uintptr(unsafe.Pointer(&_sqlite3Prng)), uint32(132))
}

func _sqlite3PrngRestoreState(tls *libc.TLS) {
	libc.Xmemcpy(tls, uintptr(unsafe.Pointer(&_sqlite3Prng)), uintptr(unsafe.Pointer(&_sqlite3SavedPrng)), uint32(132))
}

type T_PVFV = uintptr

type _PVFV = T_PVFV

type T_PIFV = uintptr

type _PIFV = T_PIFV

type T_PVFI = uintptr

type _PVFI = T_PVFI

type T_onexit_table_t = struct {
	F_first uintptr
	F_last  uintptr
	F_end   uintptr
}

type _onexit_table_t = T_onexit_table_t

type T_ino_t = uint16

type _ino_t = T_ino_t

type Tino_t = uint16

type ino_t = Tino_t

type T_dev_t = uint32

type _dev_t = T_dev_t

type Tdev_t = uint32

type dev_t = Tdev_t

type T_pid_t = int32

type _pid_t = T_pid_t

type Tpid_t = int32

type pid_t = Tpid_t

type T_mode_t = uint16

type _mode_t = T_mode_t

type Tmode_t = uint16

type mode_t = Tmode_t

type Tuseconds_t = uint32

type useconds_t = Tuseconds_t

type T_sigset_t = uint32

type _sigset_t = T_sigset_t

type T_beginthread_proc_type = uintptr

type _beginthread_proc_type = T_beginthread_proc_type

type T_beginthreadex_proc_type = uintptr

type _beginthreadex_proc_type = T_beginthreadex_proc_type

type T_tls_callback_type = uintptr

type _tls_callback_type = T_tls_callback_type

/* A running thread */
type TSQLiteThread1 = struct {
	Ftid     uintptr
	Fid      uint32
	FxTask   uintptr
	FpIn     uintptr
	FpResult uintptr
}

type SQLiteThread1 = TSQLiteThread1

// C documentation
//
//	/* Thread procedure Win32 compatibility shim */
func _sqlite3ThreadProc(tls *libc.TLS, pArg uintptr) (r uint32) {
	var p uintptr
	_ = p
	p = pArg
	(*TSQLiteThread)(unsafe.Pointer(p)).FpResult = (*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*TSQLiteThread)(unsafe.Pointer(p)).FxTask})))(tls, (*TSQLiteThread)(unsafe.Pointer(p)).FpIn)
	libc.X_endthreadex(tls, uint32(0))
	return uint32(0) /* NOT REACHED */
}

// C documentation
//
//	/* Create a new thread */
func _sqlite3ThreadCreate(tls *libc.TLS, ppThread uintptr, xTask uintptr, pIn uintptr) (r int32) {
	var p uintptr
	_ = p
	*(*uintptr)(unsafe.Pointer(ppThread)) = uintptr(0)
	p = _sqlite3Malloc(tls, uint64(20))
	if p == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	/* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a
	 ** function that returns SQLITE_ERROR when passed the argument 200, that
	 ** forces worker threads to run sequentially and deterministically
	 ** (via the sqlite3FaultSim() term of the conditional) for testing
	 ** purposes. */
	if int32(_sqlite3Config.FbCoreMutex) == 0 || _sqlite3FaultSim(tls, int32(200)) != 0 {
		libc.Xmemset(tls, p, 0, uint32(20))
	} else {
		(*TSQLiteThread)(unsafe.Pointer(p)).FxTask = xTask
		(*TSQLiteThread)(unsafe.Pointer(p)).FpIn = pIn
		(*TSQLiteThread)(unsafe.Pointer(p)).Ftid = uintptr(libc.X_beginthreadex(tls, uintptr(0), uint32(0), __ccgo_fp(_sqlite3ThreadProc), p, uint32(0), p+4))
		if (*TSQLiteThread)(unsafe.Pointer(p)).Ftid == uintptr(0) {
			libc.Xmemset(tls, p, 0, uint32(20))
		}
	}
	if (*TSQLiteThread)(unsafe.Pointer(p)).FxTask == uintptr(0) {
		(*TSQLiteThread)(unsafe.Pointer(p)).Fid = uint32(libc.XGetCurrentThreadId(tls))
		(*TSQLiteThread)(unsafe.Pointer(p)).FpResult = (*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{xTask})))(tls, pIn)
	}
	*(*uintptr)(unsafe.Pointer(ppThread)) = p
	return SQLITE_OK
}

/* os_win.c */

// C documentation
//
//	/* Get the results of the thread */
func _sqlite3ThreadJoin(tls *libc.TLS, p uintptr, ppOut uintptr) (r int32) {
	var bRc TBOOL
	var rc TDWORD
	var v1 int32
	_, _, _ = bRc, rc, v1
	if p == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	if (*TSQLiteThread)(unsafe.Pointer(p)).FxTask == uintptr(0) {
		/* assert( p->id==GetCurrentThreadId() ); */
		rc = libc.Uint32FromInt32(0x00000000) + libc.Uint32FromInt32(0)
	} else {
		rc = _sqlite3Win32Wait(tls, (*TSQLiteThread)(unsafe.Pointer(p)).Ftid)
		bRc = libc.XCloseHandle(tls, (*TSQLiteThread)(unsafe.Pointer(p)).Ftid)
	}
	if rc == libc.Uint32FromInt32(0x00000000)+libc.Uint32FromInt32(0) {
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*TSQLiteThread)(unsafe.Pointer(p)).FpResult
	}
	Xsqlite3_free(tls, p)
	if rc == libc.Uint32FromInt32(0x00000000)+libc.Uint32FromInt32(0) {
		v1 = SQLITE_OK
	} else {
		v1 = int32(SQLITE_ERROR)
	}
	return v1
}

/******************************** End Win32 Threads *************************/

/********************************* Single-Threaded **************************/
/****************************** End Single-Threaded *************************/

/************** End of threads.c *********************************************/
/************** Begin file utf.c *********************************************/
/*
** 2004 April 13
**
** 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 routines used to translate between UTF-8,
** UTF-16, UTF-16BE, and UTF-16LE.
**
** Notes on UTF-8:
**
**   Byte-0    Byte-1    Byte-2    Byte-3    Value
**  0xxxxxxx                                 00000000 00000000 0xxxxxxx
**  110yyyyy  10xxxxxx                       00000000 00000yyy yyxxxxxx
**  1110zzzz  10yyyyyy  10xxxxxx             00000000 zzzzyyyy yyxxxxxx
**  11110uuu  10uuzzzz  10yyyyyy  10xxxxxx   000uuuuu zzzzyyyy yyxxxxxx
**
**
** Notes on UTF-16:  (with wwww+1==uuuuu)
**
**      Word-0               Word-1          Value
**  110110ww wwzzzzyy   110111yy yyxxxxxx    000uuuuu zzzzyyyy yyxxxxxx
**  zzzzyyyy yyxxxxxx                        00000000 zzzzyyyy yyxxxxxx
**
**
** BOM or Byte Order Mark:
**     0xff 0xfe   little-endian utf-16 follows
**     0xfe 0xff   big-endian utf-16 follows
**
 */
/* #include "sqliteInt.h" */
/* #include <assert.h> */
/* #include "vdbeInt.h" */

// C documentation
//
//	/*
//	** This lookup table is used to help decode the first byte of
//	** a multi-byte UTF8 character.
//	*/
var _sqlite3Utf8Trans1 = [64]uint8{
	1:  uint8(0x01),
	2:  uint8(0x02),
	3:  uint8(0x03),
	4:  uint8(0x04),
	5:  uint8(0x05),
	6:  uint8(0x06),
	7:  uint8(0x07),
	8:  uint8(0x08),
	9:  uint8(0x09),
	10: uint8(0x0a),
	11: uint8(0x0b),
	12: uint8(0x0c),
	13: uint8(0x0d),
	14: uint8(0x0e),
	15: uint8(0x0f),
	16: uint8(0x10),
	17: uint8(0x11),
	18: uint8(0x12),
	19: uint8(0x13),
	20: uint8(0x14),
	21: uint8(0x15),
	22: uint8(0x16),
	23: uint8(0x17),
	24: uint8(0x18),
	25: uint8(0x19),
	26: uint8(0x1a),
	27: uint8(0x1b),
	28: uint8(0x1c),
	29: uint8(0x1d),
	30: uint8(0x1e),
	31: uint8(0x1f),
	33: uint8(0x01),
	34: uint8(0x02),
	35: uint8(0x03),
	36: uint8(0x04),
	37: uint8(0x05),
	38: uint8(0x06),
	39: uint8(0x07),
	40: uint8(0x08),
	41: uint8(0x09),
	42: uint8(0x0a),
	43: uint8(0x0b),
	44: uint8(0x0c),
	45: uint8(0x0d),
	46: uint8(0x0e),
	47: uint8(0x0f),
	49: uint8(0x01),
	50: uint8(0x02),
	51: uint8(0x03),
	52: uint8(0x04),
	53: uint8(0x05),
	54: uint8(0x06),
	55: uint8(0x07),
	57: uint8(0x01),
	58: uint8(0x02),
	59: uint8(0x03),
	61: uint8(0x01),
}

// C documentation
//
//	/*
//	** Translate a single UTF-8 character.  Return the unicode value.
//	**
//	** During translation, assume that the byte that zTerm points
//	** is a 0x00.
//	**
//	** Write a pointer to the next unread byte back into *pzNext.
//	**
//	** Notes On Invalid UTF-8:
//	**
//	**  *  This routine never allows a 7-bit character (0x00 through 0x7f) to
//	**     be encoded as a multi-byte character.  Any multi-byte character that
//	**     attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
//	**
//	**  *  This routine never allows a UTF16 surrogate value to be encoded.
//	**     If a multi-byte character attempts to encode a value between
//	**     0xd800 and 0xe000 then it is rendered as 0xfffd.
//	**
//	**  *  Bytes in the range of 0x80 through 0xbf which occur as the first
//	**     byte of a character are interpreted as single-byte characters
//	**     and rendered as themselves even though they are technically
//	**     invalid characters.
//	**
//	**  *  This routine accepts over-length UTF8 encodings
//	**     for unicode values 0x80 and greater.  It does not change over-length
//	**     encodings to 0xfffd as some systems recommend.
//	*/
func _sqlite3Utf8Read(tls *libc.TLS, pz uintptr) (r Tu32) {
	var c uint32
	var v1, v2, v3, v4 uintptr
	_, _, _, _, _ = c, v1, v2, v3, v4
	/* Same as READ_UTF8() above but without the zTerm parameter.
	 ** For this routine, we assume the UTF8 string is always zero-terminated.
	 */
	v2 = pz
	v1 = *(*uintptr)(unsafe.Pointer(v2))
	*(*uintptr)(unsafe.Pointer(v2))++
	c = uint32(*(*uint8)(unsafe.Pointer(v1)))
	if c >= uint32(0xc0) {
		c = uint32(_sqlite3Utf8Trans1[c-uint32(0xc0)])
		for int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pz)))))&int32(0xc0) == int32(0x80) {
			v4 = pz
			v3 = *(*uintptr)(unsafe.Pointer(v4))
			*(*uintptr)(unsafe.Pointer(v4))++
			c = c<<int32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v3))))
		}
		if c < uint32(0x80) || c&uint32(0xFFFFF800) == uint32(0xD800) || c&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
			c = uint32(0xFFFD)
		}
	}
	return c
}

// C documentation
//
//	/*
//	** Read a single UTF8 character out of buffer z[], but reading no
//	** more than n characters from the buffer.  z[] is not zero-terminated.
//	**
//	** Return the number of bytes used to construct the character.
//	**
//	** Invalid UTF8 might generate a strange result.  No effort is made
//	** to detect invalid UTF8.
//	**
//	** At most 4 bytes will be read out of z[].  The return value will always
//	** be between 1 and 4.
//	*/
func _sqlite3Utf8ReadLimited(tls *libc.TLS, z uintptr, n int32, piOut uintptr) (r int32) {
	var c Tu32
	var i int32
	_, _ = c, i
	i = int32(1)
	c = uint32(*(*Tu8)(unsafe.Pointer(z)))
	if c >= uint32(0xc0) {
		c = uint32(_sqlite3Utf8Trans1[c-uint32(0xc0)])
		if n > int32(4) {
			n = int32(4)
		}
		for i < n && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(i))))&int32(0xc0) == int32(0x80) {
			c = c<<libc.Int32FromInt32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*Tu8)(unsafe.Pointer(z + uintptr(i)))))
			i++
		}
	}
	*(*Tu32)(unsafe.Pointer(piOut)) = c
	return i
}

/*
** If the TRANSLATE_TRACE macro is defined, the value of each Mem is
** printed on stderr on the way into and out of sqlite3VdbeMemTranslate().
 */
/* #define TRANSLATE_TRACE 1 */

// C documentation
//
//	/*
//	** This routine transforms the internal text encoding used by pMem to
//	** desiredEnc. It is an error if the string is already of the desired
//	** encoding, or if *pMem does not contain a string value.
//	*/
func _sqlite3VdbeMemTranslate(tls *libc.TLS, pMem uintptr, desiredEnc Tu8) (r int32) {
	var c uint32
	var c2, c21, rc int32
	var len1 Tsqlite3_int64
	var temp Tu8
	var z, zIn, zOut, zTerm, v1, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v2, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v3, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v4, v40, v41, v42, v43, v44, v45, v46, v5, v6, v7, v8, v9 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, c2, c21, len1, rc, temp, z, zIn, zOut, zTerm, v1, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v2, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v3, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v4, v40, v41, v42, v43, v44, v45, v46, v5, v6, v7, v8, v9
	/* If the translation is between UTF-16 little and big endian, then
	 ** all that is required is to swap the byte order. This case is handled
	 ** differently from the others.
	 */
	if int32((*TMem)(unsafe.Pointer(pMem)).Fenc) != int32(SQLITE_UTF8) && int32(int32(desiredEnc)) != int32(SQLITE_UTF8) {
		rc = _sqlite3VdbeMemMakeWriteable(tls, pMem)
		if rc != SQLITE_OK {
			return int32(SQLITE_NOMEM)
		}
		zIn = (*TMem)(unsafe.Pointer(pMem)).Fz
		zTerm = zIn + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn & ^libc.Int32FromInt32(1))
		for zIn < zTerm {
			temp = *(*uint8)(unsafe.Pointer(zIn))
			*(*uint8)(unsafe.Pointer(zIn)) = *(*uint8)(unsafe.Pointer(zIn + libc.UintptrFromInt32(1)))
			zIn++
			v1 = zIn
			zIn++
			*(*uint8)(unsafe.Pointer(v1)) = temp
		}
		(*TMem)(unsafe.Pointer(pMem)).Fenc = desiredEnc
		goto translate_out
	}
	/* Set len to the maximum number of bytes required in the output buffer. */
	if int32(int32(desiredEnc)) == int32(SQLITE_UTF8) {
		/* When converting from UTF-16, the maximum growth results from
		 ** translating a 2-byte character to a 4-byte UTF-8 character.
		 ** A single byte is required for the output string
		 ** nul-terminator.
		 */
		*(*int32)(unsafe.Pointer(pMem + 12)) &= ^libc.Int32FromInt32(1)
		len1 = int64(2)*int64((*TMem)(unsafe.Pointer(pMem)).Fn) + int64(1)
	} else {
		/* When converting from UTF-8 to UTF-16 the maximum growth is caused
		 ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
		 ** character. Two bytes are required in the output buffer for the
		 ** nul-terminator.
		 */
		len1 = int64(2)*int64((*TMem)(unsafe.Pointer(pMem)).Fn) + int64(2)
	}
	/* Set zIn to point at the start of the input buffer and zTerm to point 1
	 ** byte past the end.
	 **
	 ** Variable zOut is set to point at the output buffer, space obtained
	 ** from sqlite3_malloc().
	 */
	zIn = (*TMem)(unsafe.Pointer(pMem)).Fz
	zTerm = zIn + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn)
	zOut = _sqlite3DbMallocRaw(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, uint64(uint64(len1)))
	if !(zOut != 0) {
		return int32(SQLITE_NOMEM)
	}
	z = zOut
	if int32((*TMem)(unsafe.Pointer(pMem)).Fenc) == int32(SQLITE_UTF8) {
		if int32(int32(desiredEnc)) == int32(SQLITE_UTF16LE) {
			/* UTF-8 -> UTF-16 Little-endian */
			for zIn < zTerm {
				v2 = zIn
				zIn++
				c = uint32(*(*uint8)(unsafe.Pointer(v2)))
				if c >= uint32(0xc0) {
					c = uint32(_sqlite3Utf8Trans1[c-uint32(0xc0)])
					for zIn != zTerm && int32(*(*uint8)(unsafe.Pointer(zIn)))&int32(0xc0) == int32(0x80) {
						v3 = zIn
						zIn++
						c = c<<int32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v3))))
					}
					if c < uint32(0x80) || c&uint32(0xFFFFF800) == uint32(0xD800) || c&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
						c = uint32(0xFFFD)
					}
				}
				if c <= uint32(0xFFFF) {
					v4 = z
					z++
					*(*uint8)(unsafe.Pointer(v4)) = uint8(c & libc.Uint32FromInt32(0x00FF))
					v5 = z
					z++
					*(*uint8)(unsafe.Pointer(v5)) = uint8(c >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0x00FF))
				} else {
					v6 = z
					z++
					*(*uint8)(unsafe.Pointer(v6)) = uint8(c>>libc.Int32FromInt32(10)&libc.Uint32FromInt32(0x003F) + (c-libc.Uint32FromInt32(0x10000))>>libc.Int32FromInt32(10)&libc.Uint32FromInt32(0x00C0))
					v7 = z
					z++
					*(*uint8)(unsafe.Pointer(v7)) = uint8(libc.Uint32FromInt32(0x00D8) + (c-libc.Uint32FromInt32(0x10000))>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x03))
					v8 = z
					z++
					*(*uint8)(unsafe.Pointer(v8)) = uint8(c & libc.Uint32FromInt32(0x00FF))
					v9 = z
					z++
					*(*uint8)(unsafe.Pointer(v9)) = uint8(libc.Uint32FromInt32(0x00DC) + c>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0x03))
				}
			}
		} else {
			/* UTF-8 -> UTF-16 Big-endian */
			for zIn < zTerm {
				v10 = zIn
				zIn++
				c = uint32(*(*uint8)(unsafe.Pointer(v10)))
				if c >= uint32(0xc0) {
					c = uint32(_sqlite3Utf8Trans1[c-uint32(0xc0)])
					for zIn != zTerm && int32(*(*uint8)(unsafe.Pointer(zIn)))&int32(0xc0) == int32(0x80) {
						v11 = zIn
						zIn++
						c = c<<int32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v11))))
					}
					if c < uint32(0x80) || c&uint32(0xFFFFF800) == uint32(0xD800) || c&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
						c = uint32(0xFFFD)
					}
				}
				if c <= uint32(0xFFFF) {
					v12 = z
					z++
					*(*uint8)(unsafe.Pointer(v12)) = uint8(c >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0x00FF))
					v13 = z
					z++
					*(*uint8)(unsafe.Pointer(v13)) = uint8(c & libc.Uint32FromInt32(0x00FF))
				} else {
					v14 = z
					z++
					*(*uint8)(unsafe.Pointer(v14)) = uint8(libc.Uint32FromInt32(0x00D8) + (c-libc.Uint32FromInt32(0x10000))>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x03))
					v15 = z
					z++
					*(*uint8)(unsafe.Pointer(v15)) = uint8(c>>libc.Int32FromInt32(10)&libc.Uint32FromInt32(0x003F) + (c-libc.Uint32FromInt32(0x10000))>>libc.Int32FromInt32(10)&libc.Uint32FromInt32(0x00C0))
					v16 = z
					z++
					*(*uint8)(unsafe.Pointer(v16)) = uint8(libc.Uint32FromInt32(0x00DC) + c>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0x03))
					v17 = z
					z++
					*(*uint8)(unsafe.Pointer(v17)) = uint8(c & libc.Uint32FromInt32(0x00FF))
				}
			}
		}
		(*TMem)(unsafe.Pointer(pMem)).Fn = int32(int32(z)) - int32(int32(zOut))
		v18 = z
		z++
		*(*uint8)(unsafe.Pointer(v18)) = uint8(0)
	} else {
		if int32((*TMem)(unsafe.Pointer(pMem)).Fenc) == int32(SQLITE_UTF16LE) {
			/* UTF-16 Little-endian -> UTF-8 */
			for zIn < zTerm {
				v19 = zIn
				zIn++
				c = uint32(*(*uint8)(unsafe.Pointer(v19)))
				v20 = zIn
				zIn++
				c += uint32(int32(*(*uint8)(unsafe.Pointer(v20))) << int32(8))
				if c >= uint32(0xd800) && c < uint32(0xe000) {
					if zIn < zTerm {
						v21 = zIn
						zIn++
						c2 = int32(*(*uint8)(unsafe.Pointer(v21)))
						v22 = zIn
						zIn++
						c2 += int32(*(*uint8)(unsafe.Pointer(v22))) << int32(8)
						c = uint32(c2&libc.Int32FromInt32(0x03FF)) + c&uint32(0x003F)<<int32(10) + (c&uint32(0x03C0)+uint32(0x0040))<<int32(10)
					}
				}
				if c < uint32(0x00080) {
					v23 = z
					z++
					*(*uint8)(unsafe.Pointer(v23)) = uint8(c & libc.Uint32FromInt32(0xFF))
				} else {
					if c < uint32(0x00800) {
						v24 = z
						z++
						*(*uint8)(unsafe.Pointer(v24)) = uint8(int32(0xC0) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
						v25 = z
						z++
						*(*uint8)(unsafe.Pointer(v25)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
					} else {
						if c < uint32(0x10000) {
							v26 = z
							z++
							*(*uint8)(unsafe.Pointer(v26)) = uint8(int32(0xE0) + int32(uint8(c>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
							v27 = z
							z++
							*(*uint8)(unsafe.Pointer(v27)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
							v28 = z
							z++
							*(*uint8)(unsafe.Pointer(v28)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
						} else {
							v29 = z
							z++
							*(*uint8)(unsafe.Pointer(v29)) = uint8(int32(0xF0) + int32(uint8(c>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
							v30 = z
							z++
							*(*uint8)(unsafe.Pointer(v30)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
							v31 = z
							z++
							*(*uint8)(unsafe.Pointer(v31)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
							v32 = z
							z++
							*(*uint8)(unsafe.Pointer(v32)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
						}
					}
				}
			}
		} else {
			/* UTF-16 Big-endian -> UTF-8 */
			for zIn < zTerm {
				v33 = zIn
				zIn++
				c = uint32(int32(*(*uint8)(unsafe.Pointer(v33))) << int32(8))
				v34 = zIn
				zIn++
				c += uint32(*(*uint8)(unsafe.Pointer(v34)))
				if c >= uint32(0xd800) && c < uint32(0xe000) {
					if zIn < zTerm {
						v35 = zIn
						zIn++
						c21 = int32(*(*uint8)(unsafe.Pointer(v35))) << int32(8)
						v36 = zIn
						zIn++
						c21 += int32(*(*uint8)(unsafe.Pointer(v36)))
						c = uint32(c21&libc.Int32FromInt32(0x03FF)) + c&uint32(0x003F)<<int32(10) + (c&uint32(0x03C0)+uint32(0x0040))<<int32(10)
					}
				}
				if c < uint32(0x00080) {
					v37 = z
					z++
					*(*uint8)(unsafe.Pointer(v37)) = uint8(c & libc.Uint32FromInt32(0xFF))
				} else {
					if c < uint32(0x00800) {
						v38 = z
						z++
						*(*uint8)(unsafe.Pointer(v38)) = uint8(int32(0xC0) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
						v39 = z
						z++
						*(*uint8)(unsafe.Pointer(v39)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
					} else {
						if c < uint32(0x10000) {
							v40 = z
							z++
							*(*uint8)(unsafe.Pointer(v40)) = uint8(int32(0xE0) + int32(uint8(c>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
							v41 = z
							z++
							*(*uint8)(unsafe.Pointer(v41)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
							v42 = z
							z++
							*(*uint8)(unsafe.Pointer(v42)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
						} else {
							v43 = z
							z++
							*(*uint8)(unsafe.Pointer(v43)) = uint8(int32(0xF0) + int32(uint8(c>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
							v44 = z
							z++
							*(*uint8)(unsafe.Pointer(v44)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
							v45 = z
							z++
							*(*uint8)(unsafe.Pointer(v45)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
							v46 = z
							z++
							*(*uint8)(unsafe.Pointer(v46)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
						}
					}
				}
			}
		}
		(*TMem)(unsafe.Pointer(pMem)).Fn = int32(int32(z)) - int32(int32(zOut))
	}
	*(*uint8)(unsafe.Pointer(z)) = uint8(0)
	c = uint32(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Term) | int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_AffMask)|libc.Int32FromInt32(MEM_Subtype)))
	_sqlite3VdbeMemRelease(tls, pMem)
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(uint16(c))
	(*TMem)(unsafe.Pointer(pMem)).Fenc = desiredEnc
	(*TMem)(unsafe.Pointer(pMem)).Fz = zOut
	(*TMem)(unsafe.Pointer(pMem)).FzMalloc = (*TMem)(unsafe.Pointer(pMem)).Fz
	(*TMem)(unsafe.Pointer(pMem)).FszMalloc = _sqlite3DbMallocSize(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).Fz)
	goto translate_out
translate_out:
	;
	return SQLITE_OK
	return r
}

// C documentation
//
//	/*
//	** This routine checks for a byte-order mark at the beginning of the
//	** UTF-16 string stored in *pMem. If one is present, it is removed and
//	** the encoding of the Mem adjusted. This routine does not do any
//	** byte-swapping, it just sets Mem.enc appropriately.
//	**
//	** The allocation (static, dynamic etc.) and encoding of the Mem may be
//	** changed by this function.
//	*/
func _sqlite3VdbeMemHandleBom(tls *libc.TLS, pMem uintptr) (r int32) {
	var b1, b2, bom Tu8
	var rc int32
	var p1 uintptr
	_, _, _, _, _ = b1, b2, bom, rc, p1
	rc = SQLITE_OK
	bom = uint8(0)
	if (*TMem)(unsafe.Pointer(pMem)).Fn > int32(1) {
		b1 = *(*Tu8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz))
		b2 = *(*Tu8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + libc.UintptrFromInt32(1)))
		if int32(int32(b1)) == int32(0xFE) && int32(int32(b2)) == int32(0xFF) {
			bom = uint8(SQLITE_UTF16BE)
		}
		if int32(int32(b1)) == int32(0xFF) && int32(int32(b2)) == int32(0xFE) {
			bom = uint8(SQLITE_UTF16LE)
		}
	}
	if bom != 0 {
		rc = _sqlite3VdbeMemMakeWriteable(tls, pMem)
		if rc == SQLITE_OK {
			*(*int32)(unsafe.Pointer(pMem + 12)) -= int32(2)
			libc.Xmemmove(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, (*TMem)(unsafe.Pointer(pMem)).Fz+2, uint32((*TMem)(unsafe.Pointer(pMem)).Fn))
			*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn))) = int8('\000')
			*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn+int32(1)))) = int8('\000')
			p1 = pMem + 16
			*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(MEM_Term))
			(*TMem)(unsafe.Pointer(pMem)).Fenc = bom
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
//	** return the number of unicode characters in pZ up to (but not including)
//	** the first 0x00 byte. If nByte is not less than zero, return the
//	** number of unicode characters in the first nByte of pZ (or up to
//	** the first 0x00, whichever comes first).
//	*/
func _sqlite3Utf8CharLen(tls *libc.TLS, zIn uintptr, nByte int32) (r1 int32) {
	var r int32
	var z, zTerm, v1 uintptr
	_, _, _, _ = r, z, zTerm, v1
	r = 0
	z = zIn
	if nByte >= 0 {
		zTerm = z + uintptr(nByte)
	} else {
		zTerm = uintptr(-libc.Int32FromInt32(1))
	}
	for int32(*(*Tu8)(unsafe.Pointer(z))) != 0 && z < zTerm {
		v1 = z
		z++
		if int32(*(*Tu8)(unsafe.Pointer(v1))) >= int32(0xc0) {
			for int32(*(*Tu8)(unsafe.Pointer(z)))&int32(0xc0) == int32(0x80) {
				z++
			}
		}
		r++
	}
	return r
}

/* This test function is not currently used by the automated test-suite.
** Hence it is only available in debug builds.
 */

// C documentation
//
//	/*
//	** Convert a UTF-16 string in the native encoding into a UTF-8 string.
//	** Memory to hold the UTF-8 string is obtained from sqlite3_malloc and must
//	** be freed by the calling function.
//	**
//	** NULL is returned if there is an allocation error.
//	*/
func _sqlite3Utf16to8(tls *libc.TLS, db uintptr, z uintptr, nByte int32, enc Tu8) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* m at bp+0 */ TMem
	libc.Xmemset(tls, bp, 0, uint32(40))
	(*(*TMem)(unsafe.Pointer(bp))).Fdb = db
	_sqlite3VdbeMemSetStr(tls, bp, z, int64(int64(nByte)), enc, libc.UintptrFromInt32(0))
	_sqlite3VdbeChangeEncoding(tls, bp, int32(SQLITE_UTF8))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3VdbeMemRelease(tls, bp)
		(*(*TMem)(unsafe.Pointer(bp))).Fz = uintptr(0)
	}
	return (*(*TMem)(unsafe.Pointer(bp))).Fz
}

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

type T_exception = struct {
	F__ccgo_align [0]uint32
	Ftype1        int32
	Fname         uintptr
	Farg1         float64
	Farg2         float64
	Fretval       float64
}

type _exception = T_exception

type t__mingw_dbl_type_t = struct {
	F__ccgo_align [0]uint32
	Fval          [0]uint64
	Flh           [0]struct {
		Flow  uint32
		Fhigh uint32
	}
	Fx float64
}

type t__mingw_flt_type_t = struct {
	Fval [0]uint32
	Fx   float32
}

type t__mingw_ldbl_type_t = struct {
	F__ccgo_align [0]uint32
	Flh           [0]struct {
		Flow      uint32
		Fhigh     uint32
		F__ccgo8  uint32
		F__ccgo12 uint32
	}
	Fx           float64
	F__ccgo_pad2 [8]byte
}

type T_complex = struct {
	F__ccgo_align [0]uint32
	Fx            float64
	Fy            float64
}

type _complex = T_complex

type Tfloat_t = float64

type float_t = Tfloat_t

type Tdouble_t = float64

type double_t = Tdouble_t

/* Documentation on decimal float math
   http://h21007.www2.hp.com/portal/site/dspp/menuitem.863c3e4cbcdc3f3515b49c108973a801?ciid=8cf166fedd1aa110VgnVCM100000a360ea10RCRD
*/

// C documentation
//
//	/*
//	** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
//	** or to bypass normal error detection during testing in order to let
//	** execute proceed further downstream.
//	**
//	** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0).  The
//	** sqlite3FaultSim() function only returns non-zero during testing.
//	**
//	** During testing, if the test harness has set a fault-sim callback using
//	** a call to sqlite3_test_control(SQLITE_TESTCTRL_FAULT_INSTALL), then
//	** each call to sqlite3FaultSim() is relayed to that application-supplied
//	** callback and the integer return value form the application-supplied
//	** callback is returned by sqlite3FaultSim().
//	**
//	** The integer argument to sqlite3FaultSim() is a code to identify which
//	** sqlite3FaultSim() instance is being invoked. Each call to sqlite3FaultSim()
//	** should have a unique code.  To prevent legacy testing applications from
//	** breaking, the codes should not be changed or reused.
//	*/
func _sqlite3FaultSim(tls *libc.TLS, iTest int32) (r int32) {
	var xCallback uintptr
	var v1 int32
	_, _ = xCallback, v1
	xCallback = _sqlite3Config.FxTestCallback
	if xCallback != 0 {
		v1 = (*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xCallback})))(tls, iTest)
	} else {
		v1 = SQLITE_OK
	}
	return v1
}

// C documentation
//
//	/*
//	** Return true if the floating point value is Not a Number (NaN).
//	**
//	** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
//	** Otherwise, we have our own implementation that works on most systems.
//	*/
func _sqlite3IsNaN(tls *libc.TLS, _x float64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = _x
	var rc int32
	var _ /* y at bp+8 */ Tu64
	_ = rc
	libc.Xmemcpy(tls, bp+8, bp, uint32(8))
	rc = libc.BoolInt32(*(*Tu64)(unsafe.Pointer(bp + 8))&(libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52)) == libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52) && *(*Tu64)(unsafe.Pointer(bp + 8))&(libc.Uint64FromInt32(1)<<libc.Int32FromInt32(52)-libc.Uint64FromInt32(1)) != uint64(0))
	return rc
}

// C documentation
//
//	/*
//	** Return true if the floating point value is NaN or +Inf or -Inf.
//	*/
func _sqlite3IsOverflow(tls *libc.TLS, _x float64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = _x
	var rc int32
	var _ /* y at bp+8 */ Tu64
	_ = rc
	libc.Xmemcpy(tls, bp+8, bp, uint32(8))
	rc = libc.BoolInt32(*(*Tu64)(unsafe.Pointer(bp + 8))&(libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52)) == libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52))
	return rc
}

// C documentation
//
//	/*
//	** Compute a string length that is limited to what can be stored in
//	** lower 30 bits of a 32-bit signed integer.
//	**
//	** The value returned will never be negative.  Nor will it ever be greater
//	** than the actual length of the string.  For very long strings (greater
//	** than 1GiB) the value returned might be less than the true string length.
//	*/
func _sqlite3Strlen30(tls *libc.TLS, z uintptr) (r int32) {
	if z == uintptr(0) {
		return 0
	}
	return int32(0x3fffffff) & int32(libc.Xstrlen(tls, z))
}

// 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 int32((*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 + 4))&0xf0>>4)) != 0 {
			return _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf0>>4))-int32(1)]
		} else {
			return zDflt
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Helper function for sqlite3Error() - called rarely.  Broken out into
//	** a separate routine to avoid unnecessary register saves on entry to
//	** sqlite3Error().
//	*/
func _sqlite3ErrorFinish(tls *libc.TLS, db uintptr, err_code int32) {
	if (*Tsqlite3)(unsafe.Pointer(db)).FpErr != 0 {
		_sqlite3ValueSetNull(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
	}
	_sqlite3SystemError(tls, db, err_code)
}

// C documentation
//
//	/*
//	** Set the current error code to err_code and clear any prior error message.
//	** Also set iSysErrno (by calling sqlite3System) if the err_code indicates
//	** that would be appropriate.
//	*/
func _sqlite3Error(tls *libc.TLS, db uintptr, err_code int32) {
	(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = err_code
	if err_code != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FpErr != 0 {
		_sqlite3ErrorFinish(tls, db, err_code)
	} else {
		(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = -int32(1)
	}
}

// C documentation
//
//	/*
//	** The equivalent of sqlite3Error(db, SQLITE_OK).  Clear the error state
//	** and error message.
//	*/
func _sqlite3ErrorClear(tls *libc.TLS, db uintptr) {
	(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = SQLITE_OK
	(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = -int32(1)
	if (*Tsqlite3)(unsafe.Pointer(db)).FpErr != 0 {
		_sqlite3ValueSetNull(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
	}
}

// C documentation
//
//	/*
//	** Load the sqlite3.iSysErrno field if that is an appropriate thing
//	** to do based on the SQLite error code in rc.
//	*/
func _sqlite3SystemError(tls *libc.TLS, db uintptr, rc int32) {
	if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
		return
	}
	rc &= int32(0xff)
	if rc == int32(SQLITE_CANTOPEN) || rc == int32(SQLITE_IOERR) {
		(*Tsqlite3)(unsafe.Pointer(db)).FiSysErrno = _sqlite3OsGetLastError(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs)
	}
}

// C documentation
//
//	/*
//	** Set the most recent error code and error string for the sqlite
//	** handle "db". The error code is set to "err_code".
//	**
//	** If it is not NULL, string zFormat specifies the format of the
//	** error string.  zFormat and any string tokens that follow it are
//	** assumed to be encoded in UTF-8.
//	**
//	** To clear the most recent error for sqlite handle "db", sqlite3Error
//	** should be called with err_code set to SQLITE_OK and zFormat set
//	** to NULL.
//	*/
func _sqlite3ErrorWithMsg(tls *libc.TLS, db uintptr, err_code int32, zFormat uintptr, va uintptr) {
	var ap Tva_list
	var z, v1 uintptr
	var v2 bool
	_, _, _, _ = ap, z, v1, v2
	(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = err_code
	_sqlite3SystemError(tls, db, err_code)
	if zFormat == uintptr(0) {
		_sqlite3Error(tls, db, err_code)
	} else {
		if v2 = (*Tsqlite3)(unsafe.Pointer(db)).FpErr != 0; !v2 {
			v1 = _sqlite3ValueNew(tls, db)
			(*Tsqlite3)(unsafe.Pointer(db)).FpErr = v1
		}
		if v2 || v1 != uintptr(0) {
			ap = va
			z = _sqlite3VMPrintf(tls, db, zFormat, ap)
			_ = ap
			_sqlite3ValueSetStr(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr, -int32(1), z, uint8(SQLITE_UTF8), __ccgo_fp(_sqlite3OomClear))
		}
	}
}

// C documentation
//
//	/*
//	** Check for interrupts and invoke progress callback.
//	*/
func _sqlite3ProgressCheck(tls *libc.TLS, p uintptr) {
	var db, v2 uintptr
	var v1 Tu32
	_, _, _ = db, v1, v2
	db = (*TParse)(unsafe.Pointer(p)).Fdb
	if libc.AtomicLoadNInt32(db+312, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
		(*TParse)(unsafe.Pointer(p)).FnErr++
		(*TParse)(unsafe.Pointer(p)).Frc = int32(SQLITE_INTERRUPT)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != 0 {
		if (*TParse)(unsafe.Pointer(p)).Frc == int32(SQLITE_INTERRUPT) {
			(*TParse)(unsafe.Pointer(p)).FnProgressSteps = uint32(0)
		} else {
			v2 = p + 112
			*(*Tu32)(unsafe.Pointer(v2))++
			v1 = *(*Tu32)(unsafe.Pointer(v2))
			if v1 >= (*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 {
					(*TParse)(unsafe.Pointer(p)).FnErr++
					(*TParse)(unsafe.Pointer(p)).Frc = int32(SQLITE_INTERRUPT)
				}
				(*TParse)(unsafe.Pointer(p)).FnProgressSteps = uint32(0)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Add an error message to pParse->zErrMsg and increment pParse->nErr.
//	**
//	** This function should be used to report any error that occurs while
//	** compiling an SQL statement (i.e. within sqlite3_prepare()). The
//	** last thing the sqlite3_prepare() function does is copy the error
//	** stored by this function into the database handle using sqlite3Error().
//	** Functions sqlite3Error() or sqlite3ErrorWithMsg() should be used
//	** during statement execution (sqlite3_step() etc.).
//	*/
func _sqlite3ErrorMsg(tls *libc.TLS, pParse uintptr, zFormat uintptr, va uintptr) {
	var ap Tva_list
	var db, zMsg uintptr
	_, _, _ = ap, db, zMsg
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = -int32(2)
	ap = va
	zMsg = _sqlite3VMPrintf(tls, db, zFormat, ap)
	_ = ap
	if (*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset < -int32(1) {
		(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = -int32(1)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr != 0 {
		_sqlite3DbFree(tls, db, zMsg)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FnErr++
			(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
		}
	} else {
		(*TParse)(unsafe.Pointer(pParse)).FnErr++
		_sqlite3DbFree(tls, db, (*TParse)(unsafe.Pointer(pParse)).FzErrMsg)
		(*TParse)(unsafe.Pointer(pParse)).FzErrMsg = zMsg
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
		(*TParse)(unsafe.Pointer(pParse)).FpWith = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** If database connection db is currently parsing SQL, then transfer
//	** error code errCode to that parser if the parser has not already
//	** encountered some other kind of error.
//	*/
func _sqlite3ErrorToParser(tls *libc.TLS, db uintptr, errCode int32) (r int32) {
	var pParse, v1 uintptr
	var v2 bool
	_, _, _ = pParse, v1, v2
	if v2 = db == uintptr(0); !v2 {
		v1 = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
		pParse = v1
	}
	if v2 || v1 == uintptr(0) {
		return errCode
	}
	(*TParse)(unsafe.Pointer(pParse)).Frc = errCode
	(*TParse)(unsafe.Pointer(pParse)).FnErr++
	return errCode
}

// C documentation
//
//	/*
//	** Convert an SQL-style quoted string into a normal string by removing
//	** the quote characters.  The conversion is done in-place.  If the
//	** input does not begin with a quote character, then this routine
//	** is a no-op.
//	**
//	** The input string must be zero-terminated.  A new zero-terminator
//	** is added to the dequoted string.
//	**
//	** The return value is -1 if no dequoting occurs or the length of the
//	** dequoted string, exclusive of the zero terminator, if dequoting does
//	** occur.
//	**
//	** 2002-02-14: This routine is extended to remove MS-Access style
//	** brackets from around identifiers.  For example:  "[a-b-c]" becomes
//	** "a-b-c".
//	*/
func _sqlite3Dequote(tls *libc.TLS, z uintptr) {
	var i, j, v2, v3 int32
	var quote int8
	_, _, _, _, _ = i, j, quote, v2, v3
	if z == uintptr(0) {
		return
	}
	quote = *(*int8)(unsafe.Pointer(z))
	if !(int32(_sqlite3CtypeMap[uint8(quote)])&libc.Int32FromInt32(0x80) != 0) {
		return
	}
	if int32(int32(quote)) == int32('[') {
		quote = int8(']')
	}
	i = int32(1)
	j = libc.Int32FromInt32(0)
	for {
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) == int32(int32(quote)) {
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(i+int32(1))))) == int32(int32(quote)) {
				v2 = j
				j++
				*(*int8)(unsafe.Pointer(z + uintptr(v2))) = quote
				i++
			} else {
				break
			}
		} else {
			v3 = j
			j++
			*(*int8)(unsafe.Pointer(z + uintptr(v3))) = *(*int8)(unsafe.Pointer(z + uintptr(i)))
		}
		goto _1
	_1:
		;
		i++
	}
	*(*int8)(unsafe.Pointer(z + uintptr(j))) = 0
}

func _sqlite3DequoteExpr(tls *libc.TLS, p uintptr) {
	var v1 int32
	_ = v1
	if int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8))))) == int32('"') {
		v1 = libc.Int32FromInt32(EP_Quoted) | libc.Int32FromInt32(EP_DblQuoted)
	} else {
		v1 = int32(EP_Quoted)
	}
	*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(v1)
	_sqlite3Dequote(tls, *(*uintptr)(unsafe.Pointer(p + 8)))
}

// C documentation
//
//	/*
//	** Expression p is a QNUMBER (quoted number). Dequote the value in p->u.zToken
//	** and set the type to INTEGER or FLOAT. "Quoted" integers or floats are those
//	** that contain '_' characters that must be removed before further processing.
//	*/
func _sqlite3DequoteNumber(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bHex int32
	var pIn, pOut, v1, v3 uintptr
	var _ /* iValue at bp+0 */ int32
	_, _, _, _, _ = bHex, pIn, pOut, v1, v3
	if p != 0 {
		pIn = *(*uintptr)(unsafe.Pointer(p + 8))
		pOut = *(*uintptr)(unsafe.Pointer(p + 8))
		bHex = libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(pIn))) == int32('0') && (int32(*(*int8)(unsafe.Pointer(pIn + 1))) == int32('x') || int32(*(*int8)(unsafe.Pointer(pIn + 1))) == int32('X')))
		(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_INTEGER)
		for {
			if int32(*(*int8)(unsafe.Pointer(pIn))) != int32('_') {
				v3 = pOut
				pOut++
				*(*int8)(unsafe.Pointer(v3)) = *(*int8)(unsafe.Pointer(pIn))
				if int32(*(*int8)(unsafe.Pointer(pIn))) == int32('e') || int32(*(*int8)(unsafe.Pointer(pIn))) == int32('E') || int32(*(*int8)(unsafe.Pointer(pIn))) == int32('.') {
					(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_FLOAT)
				}
			} else {
				if bHex == 0 && (!(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(pIn + uintptr(-libc.Int32FromInt32(1)))))])&libc.Int32FromInt32(0x04) != 0) || !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(pIn + 1)))])&libc.Int32FromInt32(0x04) != 0)) || bHex == int32(1) && (!(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(pIn + uintptr(-libc.Int32FromInt32(1)))))])&libc.Int32FromInt32(0x08) != 0) || !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(pIn + 1)))])&libc.Int32FromInt32(0x08) != 0)) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1732, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(p + 8))))
				}
			}
			goto _2
		_2:
			;
			v1 = pIn
			pIn++
			if !(*(*int8)(unsafe.Pointer(v1)) != 0) {
				break
			}
		}
		if bHex != 0 {
			(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_INTEGER)
		}
		/* tag-20240227-a: If after dequoting, the number is an integer that
		 ** fits in 32 bits, then it must be converted into EP_IntValue.  Other
		 ** parts of the code expect this.  See also tag-20240227-b. */
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_INTEGER) && _sqlite3GetInt32(tls, *(*uintptr)(unsafe.Pointer(p + 8)), bp) != 0 {
			*(*int32)(unsafe.Pointer(p + 8)) = *(*int32)(unsafe.Pointer(bp))
			*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(EP_IntValue)
		}
	}
}

// C documentation
//
//	/*
//	** If the input token p is quoted, try to adjust the token to remove
//	** the quotes.  This is not always possible:
//	**
//	**     "abc"     ->   abc
//	**     "ab""cd"  ->   (not possible because of the interior "")
//	**
//	** Remove the quotes if possible.  This is a optimization.  The overall
//	** system should still return the correct answer even if this routine
//	** is always a no-op.
//	*/
func _sqlite3DequoteToken(tls *libc.TLS, p uintptr) {
	var i uint32
	_ = i
	if (*TToken)(unsafe.Pointer(p)).Fn < uint32(2) {
		return
	}
	if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer((*TToken)(unsafe.Pointer(p)).Fz)))])&libc.Int32FromInt32(0x80) != 0) {
		return
	}
	i = uint32(1)
	for {
		if !(i < (*TToken)(unsafe.Pointer(p)).Fn-uint32(1)) {
			break
		}
		if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer((*TToken)(unsafe.Pointer(p)).Fz + uintptr(i))))])&int32(0x80) != 0 {
			return
		}
		goto _1
	_1:
		;
		i++
	}
	*(*uint32)(unsafe.Pointer(p + 4)) -= uint32(2)
	(*TToken)(unsafe.Pointer(p)).Fz++
}

// C documentation
//
//	/*
//	** Generate a Token object from a string
//	*/
func _sqlite3TokenInit(tls *libc.TLS, p uintptr, z uintptr) {
	(*TToken)(unsafe.Pointer(p)).Fz = z
	(*TToken)(unsafe.Pointer(p)).Fn = uint32(_sqlite3Strlen30(tls, z))
}

/* Convenient short-hand */

// C documentation
//
//	/*
//	** Some systems have stricmp().  Others have strcasecmp().  Because
//	** there is no consistency, we will define our own.
//	**
//	** IMPLEMENTATION-OF: R-30243-02494 The sqlite3_stricmp() and
//	** sqlite3_strnicmp() APIs allow applications and extensions to compare
//	** the contents of two buffers containing UTF-8 strings in a
//	** case-independent fashion, using the same definition of "case
//	** independence" that SQLite uses internally when comparing identifiers.
//	*/
func Xsqlite3_stricmp(tls *libc.TLS, zLeft uintptr, zRight uintptr) (r int32) {
	var v1 int32
	_ = v1
	if zLeft == uintptr(0) {
		if zRight != 0 {
			v1 = -int32(1)
		} else {
			v1 = 0
		}
		return v1
	} else {
		if zRight == uintptr(0) {
			return int32(1)
		}
	}
	return _sqlite3StrICmp(tls, zLeft, zRight)
}

func _sqlite3StrICmp(tls *libc.TLS, zLeft uintptr, zRight uintptr) (r int32) {
	var a, b uintptr
	var c, x int32
	_, _, _, _ = a, b, c, x
	a = zLeft
	b = zRight
	for {
		c = int32(*(*uint8)(unsafe.Pointer(a)))
		x = int32(*(*uint8)(unsafe.Pointer(b)))
		if c == x {
			if c == 0 {
				break
			}
		} else {
			c = int32(_sqlite3UpperToLower[c]) - int32(_sqlite3UpperToLower[x])
			if c != 0 {
				break
			}
		}
		a++
		b++
		goto _1
	_1:
	}
	return c
}

func Xsqlite3_strnicmp(tls *libc.TLS, zLeft uintptr, zRight uintptr, N int32) (r int32) {
	var a, b uintptr
	var v1, v2, v3 int32
	_, _, _, _, _ = a, b, v1, v2, v3
	if zLeft == uintptr(0) {
		if zRight != 0 {
			v1 = -int32(1)
		} else {
			v1 = 0
		}
		return v1
	} else {
		if zRight == uintptr(0) {
			return int32(1)
		}
	}
	a = zLeft
	b = zRight
	for {
		v2 = N
		N--
		if !(v2 > 0 && int32(*(*uint8)(unsafe.Pointer(a))) != 0 && int32(_sqlite3UpperToLower[*(*uint8)(unsafe.Pointer(a))]) == int32(_sqlite3UpperToLower[*(*uint8)(unsafe.Pointer(b))])) {
			break
		}
		a++
		b++
	}
	if N < 0 {
		v3 = 0
	} else {
		v3 = int32(_sqlite3UpperToLower[*(*uint8)(unsafe.Pointer(a))]) - int32(_sqlite3UpperToLower[*(*uint8)(unsafe.Pointer(b))])
	}
	return v3
}

// C documentation
//
//	/*
//	** Compute an 8-bit hash on a string that is insensitive to case differences
//	*/
func _sqlite3StrIHash(tls *libc.TLS, z uintptr) (r Tu8) {
	var h Tu8
	_ = h
	h = uint8(0)
	if z == uintptr(0) {
		return uint8(0)
	}
	for *(*int8)(unsafe.Pointer(z)) != 0 {
		h = Tu8(int32(h) + int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(z)))]))
		z++
	}
	return h
}

// C documentation
//
//	/* Double-Double multiplication.  (x[0],x[1]) *= (y,yy)
//	**
//	** Reference:
//	**   T. J. Dekker, "A Floating-Point Technique for Extending the
//	**   Available Precision".  1971-07-26.
//	*/
func _dekkerMul2(tls *libc.TLS, x uintptr, _y float64, yy float64) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	*(*float64)(unsafe.Pointer(bp)) = _y
	var c, cc, p, q, tx, ty float64
	var _ /* hx at bp+8 */ float64
	var _ /* hy at bp+16 */ float64
	var _ /* m at bp+24 */ Tu64
	_, _, _, _, _, _ = c, cc, p, q, tx, ty
	libc.Xmemcpy(tls, bp+24, x, uint32(8))
	*(*Tu64)(unsafe.Pointer(bp + 24)) &= uint64(0xfffffffffc000000)
	libc.Xmemcpy(tls, bp+8, bp+24, uint32(8))
	tx = libc.AtomicLoadPFloat64(x) - *(*float64)(unsafe.Pointer(bp + 8))
	libc.Xmemcpy(tls, bp+24, bp, uint32(8))
	*(*Tu64)(unsafe.Pointer(bp + 24)) &= uint64(0xfffffffffc000000)
	libc.Xmemcpy(tls, bp+16, bp+24, uint32(8))
	ty = *(*float64)(unsafe.Pointer(bp)) - *(*float64)(unsafe.Pointer(bp + 16))
	p = *(*float64)(unsafe.Pointer(bp + 8)) * *(*float64)(unsafe.Pointer(bp + 16))
	q = *(*float64)(unsafe.Pointer(bp + 8))*ty + tx**(*float64)(unsafe.Pointer(bp + 16))
	c = p + q
	cc = p - c + q + tx*ty
	cc = libc.AtomicLoadPFloat64(x)*yy + libc.AtomicLoadPFloat64(x+1*8)**(*float64)(unsafe.Pointer(bp)) + cc
	libc.AtomicStorePFloat64(x, c+cc)
	libc.AtomicStorePFloat64(x+1*8, c-libc.AtomicLoadPFloat64(x))
	*(*float64)(unsafe.Pointer(x + 1*8)) += cc
}

// C documentation
//
//	/*
//	** The string z[] is an text representation of a real number.
//	** Convert this string to a double and write it into *pResult.
//	**
//	** The string z[] is length bytes in length (bytes, not characters) and
//	** uses the encoding enc.  The string is not necessarily zero-terminated.
//	**
//	** Return TRUE if the result is a valid real number (or integer) and FALSE
//	** if the string is empty or contains extraneous text.  More specifically
//	** return
//	**      1          =>  The input string is a pure integer
//	**      2 or more  =>  The input has a decimal point or eNNN clause
//	**      0 or less  =>  The input string is not a valid number
//	**     -1          =>  Not a valid number, but has a valid prefix which
//	**                     includes a decimal point and/or an eNNN clause
//	**
//	** Valid numbers are in one of these formats:
//	**
//	**    [+-]digits[E[+-]digits]
//	**    [+-]digits.[digits][E[+-]digits]
//	**    [+-].digits[E[+-]digits]
//	**
//	** Leading and trailing whitespace is ignored for the purpose of determining
//	** validity.
//	**
//	** If some prefix of the input string is a valid number, this routine
//	** returns FALSE but it still converts the prefix and writes the result
//	** into *pResult.
//	*/
func _sqlite3AtoF(tls *libc.TLS, z uintptr, pResult uintptr, length int32, enc Tu8) (r1 int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var d, e, eType, eValid, esign, i, incr, nDigit, sign, v2 int32
	var r, v3, v4 float64
	var s, s2 Tu64
	var zEnd uintptr
	var _ /* rr at bp+0 */ [2]float64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = d, e, eType, eValid, esign, i, incr, nDigit, r, s, s2, sign, zEnd, v2, v3, v4
	/* sign * significand * (10 ^ (esign * exponent)) */
	sign = int32(1)                                   /* sign of significand */
	s = uint64(0)                                     /* significand */
	d = 0                                             /* adjust exponent for shifting decimal point */
	esign = int32(1)                                  /* sign of exponent */
	e = 0                                             /* exponent */
	eValid = int32(1)                                 /* True exponent is either not used or is well-formed */
	nDigit = 0                                        /* Number of digits processed */
	eType = int32(1)                                  /* 1: pure integer,  2+: fractional  -1 or less: bad UTF16 */
	*(*float64)(unsafe.Pointer(pResult)) = float64(0) /* Default return value, in case of an error */
	if length == 0 {
		return 0
	}
	if int32(int32(enc)) == int32(SQLITE_UTF8) {
		incr = int32(1)
		zEnd = z + uintptr(length)
	} else {
		incr = int32(2)
		length &= ^libc.Int32FromInt32(1)
		i = int32(3) - int32(int32(enc))
		for {
			if !(i < length && int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) == 0) {
				break
			}
			goto _1
		_1:
			;
			i += int32(2)
		}
		if i < length {
			eType = -int32(100)
		}
		zEnd = z + uintptr(i^int32(1))
		z += uintptr(int32(int32(enc)) & libc.Int32FromInt32(1))
	}
	/* skip leading spaces */
	for z < zEnd && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x01) != 0 {
		z += uintptr(incr)
	}
	if z >= zEnd {
		return 0
	}
	/* get sign of significand */
	if int32(*(*int8)(unsafe.Pointer(z))) == int32('-') {
		sign = -int32(1)
		z += uintptr(incr)
	} else {
		if int32(*(*int8)(unsafe.Pointer(z))) == int32('+') {
			z += uintptr(incr)
		}
	}
	/* copy max significant digits to significand */
	for z < zEnd && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x04) != 0 {
		s = s*uint64(10) + uint64(int32(*(*int8)(unsafe.Pointer(z)))-libc.Int32FromUint8('0'))
		z += uintptr(incr)
		nDigit++
		if s >= (libc.Uint64FromUint32(0xffffffff)|libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)-libc.Uint64FromInt32(9))/libc.Uint64FromInt32(10) {
			/* skip non-significant significand digits
			 ** (increase exponent by d to shift decimal left) */
			for z < zEnd && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x04) != 0 {
				z += uintptr(incr)
				d++
			}
		}
	}
	if z >= zEnd {
		goto do_atof_calc
	}
	/* if decimal point is present */
	if int32(*(*int8)(unsafe.Pointer(z))) == int32('.') {
		z += uintptr(incr)
		eType++
		/* copy digits from after decimal to significand
		 ** (decrease exponent by d to shift decimal right) */
		for z < zEnd && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x04) != 0 {
			if s < (libc.Uint64FromUint32(0xffffffff)|libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)-libc.Uint64FromInt32(9))/libc.Uint64FromInt32(10) {
				s = s*uint64(10) + uint64(int32(*(*int8)(unsafe.Pointer(z)))-libc.Int32FromUint8('0'))
				d--
				nDigit++
			}
			z += uintptr(incr)
		}
	}
	if z >= zEnd {
		goto do_atof_calc
	}
	/* if exponent is present */
	if int32(*(*int8)(unsafe.Pointer(z))) == int32('e') || int32(*(*int8)(unsafe.Pointer(z))) == int32('E') {
		z += uintptr(incr)
		eValid = 0
		eType++
		/* This branch is needed to avoid a (harmless) buffer overread.  The
		 ** special comment alerts the mutation tester that the correct answer
		 ** is obtained even if the branch is omitted */
		if z >= zEnd {
			goto do_atof_calc
		} /*PREVENTS-HARMLESS-OVERREAD*/
		/* get sign of exponent */
		if int32(*(*int8)(unsafe.Pointer(z))) == int32('-') {
			esign = -int32(1)
			z += uintptr(incr)
		} else {
			if int32(*(*int8)(unsafe.Pointer(z))) == int32('+') {
				z += uintptr(incr)
			}
		}
		/* copy digits to exponent */
		for z < zEnd && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x04) != 0 {
			if e < int32(10000) {
				v2 = e*int32(10) + (int32(*(*int8)(unsafe.Pointer(z))) - int32('0'))
			} else {
				v2 = int32(10000)
			}
			e = v2
			z += uintptr(incr)
			eValid = int32(1)
		}
	}
	/* skip trailing spaces */
	for z < zEnd && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x01) != 0 {
		z += uintptr(incr)
	}
	goto do_atof_calc
do_atof_calc:
	;
	/* Zero is a special case */
	if s == uint64(0) {
		if sign < 0 {
			v3 = -libc.Float64FromFloat64(0)
		} else {
			v3 = +libc.Float64FromFloat64(0)
		}
		*(*float64)(unsafe.Pointer(pResult)) = v3
		goto atof_return
	}
	/* adjust exponent by d, and update sign */
	e = e*esign + d
	/* Try to adjust the exponent to make it smaller */
	for e > 0 && s < (libc.Uint64FromUint32(0xffffffff)|libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32))/libc.Uint64FromInt32(10) {
		s *= uint64(10)
		e--
	}
	for e < 0 && s%uint64(10) == uint64(0) {
		s /= uint64(10)
		e++
	}
	if e == 0 {
		*(*float64)(unsafe.Pointer(pResult)) = float64(float64(s))
	} else {
		if _sqlite3Config.FbUseLongDouble != 0 {
			r = float64(float64(s))
			if e > 0 {
				for e >= int32(100) {
					e -= int32(100)
					r = float64(float64(r) * libc.Float64FromFloat64(1e+100))
				}
				for e >= int32(10) {
					e -= int32(10)
					r = float64(float64(r) * libc.Float64FromFloat64(1e+10))
				}
				for e >= int32(1) {
					e -= int32(1)
					r = float64(float64(r) * libc.Float64FromFloat64(10))
				}
			} else {
				for e <= -int32(100) {
					e += int32(100)
					r = float64(float64(r) * libc.Float64FromFloat64(1e-100))
				}
				for e <= -int32(10) {
					e += int32(10)
					r = float64(float64(r) * libc.Float64FromFloat64(1e-10))
				}
				for e <= -int32(1) {
					e += int32(1)
					r = float64(float64(r) * libc.Float64FromFloat64(0.1))
				}
			}
			if float64(float64(r)) > +libc.Float64FromFloat64(1.7976931348623157081452742373e+308) {
				*(*float64)(unsafe.Pointer(pResult)) = float64(+libc.X__builtin_inff(tls))
			} else {
				*(*float64)(unsafe.Pointer(pResult)) = r
			}
		} else {
			(*(*[2]float64)(unsafe.Pointer(bp)))[0] = float64(float64(s))
			s2 = uint64((*(*[2]float64)(unsafe.Pointer(bp)))[0])
			if s >= s2 {
				v4 = float64(s - s2)
			} else {
				v4 = -float64(s2 - s)
			}
			(*(*[2]float64)(unsafe.Pointer(bp)))[int32(1)] = v4
			if e > 0 {
				for e >= int32(100) {
					e -= int32(100)
					_dekkerMul2(tls, bp, float64(1e+100), -libc.Float64FromFloat64(1.5902891109759918e+83))
				}
				for e >= int32(10) {
					e -= int32(10)
					_dekkerMul2(tls, bp, float64(1e+10), float64(0))
				}
				for e >= int32(1) {
					e -= int32(1)
					_dekkerMul2(tls, bp, float64(10), float64(0))
				}
			} else {
				for e <= -int32(100) {
					e += int32(100)
					_dekkerMul2(tls, bp, float64(1e-100), -libc.Float64FromFloat64(1.9991899802602883e-117))
				}
				for e <= -int32(10) {
					e += int32(10)
					_dekkerMul2(tls, bp, float64(1e-10), -libc.Float64FromFloat64(3.643219731549774e-27))
				}
				for e <= -int32(1) {
					e += int32(1)
					_dekkerMul2(tls, bp, float64(0.1), -libc.Float64FromFloat64(5.551115123125783e-18))
				}
			}
			*(*float64)(unsafe.Pointer(pResult)) = (*(*[2]float64)(unsafe.Pointer(bp)))[0] + (*(*[2]float64)(unsafe.Pointer(bp)))[int32(1)]
			if _sqlite3IsNaN(tls, *(*float64)(unsafe.Pointer(pResult))) != 0 {
				*(*float64)(unsafe.Pointer(pResult)) = libc.Float64FromFloat64(1e+300) * libc.Float64FromFloat64(1e+300)
			}
		}
	}
	if sign < 0 {
		*(*float64)(unsafe.Pointer(pResult)) = -*(*float64)(unsafe.Pointer(pResult))
	}
	goto atof_return
atof_return:
	;
	/* return true if number and no extra non-whitespace characters after */
	if z == zEnd && nDigit > 0 && eValid != 0 && eType > 0 {
		return eType
	} else {
		if eType >= int32(2) && (eType == int32(3) || eValid != 0) && nDigit > 0 {
			return -int32(1)
		} else {
			return 0
		}
	}
	return r1
}

// C documentation
//
//	/*
//	** Render an signed 64-bit integer as text.  Store the result in zOut[] and
//	** return the length of the string that was stored, in bytes.  The value
//	** returned does not include the zero terminator at the end of the output
//	** string.
//	**
//	** The caller must ensure that zOut[] is at least 21 bytes in size.
//	*/
func _sqlite3Int64ToText(tls *libc.TLS, v Ti64, zOut uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, v2 int32
	var x Tu64
	var v1 uint64
	var _ /* zTemp at bp+0 */ [22]int8
	_, _, _, _ = i, x, v1, v2
	if v < 0 {
		if v == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
			v1 = libc.Uint64FromInt32(1) << libc.Int32FromInt32(63)
		} else {
			v1 = uint64(-v)
		}
		x = v1
	} else {
		x = uint64(uint64(v))
	}
	i = int32(libc.Uint32FromInt64(22) - libc.Uint32FromInt32(2))
	(*(*[22]int8)(unsafe.Pointer(bp)))[libc.Uint32FromInt64(22)-libc.Uint32FromInt32(1)] = 0
	for int32(1) != 0 {
		(*(*[22]int8)(unsafe.Pointer(bp)))[i] = int8(x%uint64(10) + uint64('0'))
		x = x / uint64(10)
		if x == uint64(0) {
			break
		}
		i--
	}
	if v < 0 {
		i--
		v2 = i
		(*(*[22]int8)(unsafe.Pointer(bp)))[v2] = int8('-')
	}
	libc.Xmemcpy(tls, zOut, bp+uintptr(i), uint32(22)-uint32(uint32(i)))
	return int32(libc.Uint32FromInt64(22) - libc.Uint32FromInt32(1) - uint32(uint32(i)))
}

// C documentation
//
//	/*
//	** Compare the 19-character string zNum against the text representation
//	** value 2^63:  9223372036854775808.  Return negative, zero, or positive
//	** if zNum is less than, equal to, or greater than the string.
//	** Note that zNum must contain exactly 19 characters.
//	**
//	** Unlike memcmp() this routine is guaranteed to return the difference
//	** in the values of the last digit if the only difference is in the
//	** last digit.  So, for example,
//	**
//	**      compare2pow63("9223372036854775800", 1)
//	**
//	** will return -8.
//	*/
func _compare2pow63(tls *libc.TLS, zNum uintptr, incr int32) (r int32) {
	var c, i int32
	var pow63 uintptr
	_, _, _ = c, i, pow63
	c = 0
	/* 012345678901234567 */
	pow63 = __ccgo_ts + 1757
	i = 0
	for {
		if !(c == 0 && i < int32(18)) {
			break
		}
		c = (int32(*(*int8)(unsafe.Pointer(zNum + uintptr(i*incr)))) - int32(*(*int8)(unsafe.Pointer(pow63 + uintptr(i))))) * int32(10)
		goto _1
	_1:
		;
		i++
	}
	if c == 0 {
		c = int32(*(*int8)(unsafe.Pointer(zNum + uintptr(int32(18)*incr)))) - int32('8')
	}
	return c
}

// C documentation
//
//	/*
//	** Convert zNum to a 64-bit signed integer.  zNum must be decimal. This
//	** routine does *not* accept hexadecimal notation.
//	**
//	** Returns:
//	**
//	**    -1    Not even a prefix of the input text looks like an integer
//	**     0    Successful transformation.  Fits in a 64-bit signed integer.
//	**     1    Excess non-space text after the integer value
//	**     2    Integer too large for a 64-bit signed integer or is malformed
//	**     3    Special case of 9223372036854775808
//	**
//	** length is the number of bytes in the string (bytes, not characters).
//	** The string is not necessarily zero-terminated.  The encoding is
//	** given by enc.
//	*/
func _sqlite3Atoi64(tls *libc.TLS, zNum uintptr, pNum uintptr, length int32, enc Tu8) (r int32) {
	var c, i, incr, jj, neg, nonNum, rc, v3, v6, v8 int32
	var u Tu64
	var zEnd, zStart uintptr
	var v4 bool
	var v5, v7 int64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, i, incr, jj, neg, nonNum, rc, u, zEnd, zStart, v3, v4, v5, v6, v7, v8
	u = uint64(0)
	neg = 0
	c = 0
	nonNum = 0
	zEnd = zNum + uintptr(length)
	if int32(int32(enc)) == int32(SQLITE_UTF8) {
		incr = int32(1)
	} else {
		incr = int32(2)
		length &= ^libc.Int32FromInt32(1)
		i = int32(3) - int32(int32(enc))
		for {
			if !(i < length && int32(*(*int8)(unsafe.Pointer(zNum + uintptr(i)))) == 0) {
				break
			}
			goto _1
		_1:
			;
			i += int32(2)
		}
		nonNum = libc.BoolInt32(i < length)
		zEnd = zNum + uintptr(i^int32(1))
		zNum += uintptr(int32(int32(enc)) & libc.Int32FromInt32(1))
	}
	for zNum < zEnd && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zNum)))])&int32(0x01) != 0 {
		zNum += uintptr(incr)
	}
	if zNum < zEnd {
		if int32(*(*int8)(unsafe.Pointer(zNum))) == int32('-') {
			neg = int32(1)
			zNum += uintptr(incr)
		} else {
			if int32(*(*int8)(unsafe.Pointer(zNum))) == int32('+') {
				zNum += uintptr(incr)
			}
		}
	}
	zStart = zNum
	for zNum < zEnd && int32(*(*int8)(unsafe.Pointer(zNum))) == int32('0') {
		zNum += uintptr(incr)
	} /* Skip leading zeros. */
	i = 0
	for {
		if v4 = zNum+uintptr(i) < zEnd; v4 {
			v3 = int32(*(*int8)(unsafe.Pointer(zNum + uintptr(i))))
			c = v3
		}
		if !(v4 && v3 >= int32('0') && c <= int32('9')) {
			break
		}
		u = u*uint64(10) + uint64(uint64(c)) - uint64('0')
		goto _2
	_2:
		;
		i += incr
	}
	if u > uint64(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
		/* This test and assignment is needed only to suppress UB warnings
		 ** from clang and -fsanitize=undefined.  This test and assignment make
		 ** the code a little larger and slower, and no harm comes from omitting
		 ** them, but we must appease the undefined-behavior pharisees. */
		if neg != 0 {
			v5 = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
		} else {
			v5 = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
		}
		*(*Ti64)(unsafe.Pointer(pNum)) = v5
	} else {
		if neg != 0 {
			*(*Ti64)(unsafe.Pointer(pNum)) = -int64(int64(u))
		} else {
			*(*Ti64)(unsafe.Pointer(pNum)) = int64(int64(u))
		}
	}
	rc = 0
	if i == 0 && zStart == zNum { /* No digits */
		rc = -int32(1)
	} else {
		if nonNum != 0 { /* UTF16 with high-order bytes non-zero */
			rc = int32(1)
		} else {
			if zNum+uintptr(i) < zEnd { /* Extra bytes at the end */
				jj = i
				for cond := true; cond; cond = zNum+uintptr(jj) < zEnd {
					if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zNum + uintptr(jj))))])&libc.Int32FromInt32(0x01) != 0) {
						rc = int32(1) /* Extra non-space text after the integer */
						break
					}
					jj += incr
				}
			}
		}
	}
	if i < int32(19)*incr {
		/* Less than 19 digits, so we know that it fits in 64 bits */
		return rc
	} else {
		/* zNum is a 19-digit numbers.  Compare it against 9223372036854775808. */
		if i > int32(19)*incr {
			v6 = int32(1)
		} else {
			v6 = _compare2pow63(tls, zNum, incr)
		}
		c = v6
		if c < 0 {
			/* zNum is less than 9223372036854775808 so it fits */
			return rc
		} else {
			if neg != 0 {
				v7 = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
			} else {
				v7 = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
			}
			*(*Ti64)(unsafe.Pointer(pNum)) = v7
			if c > 0 {
				/* zNum is greater than 9223372036854775808 so it overflows */
				return int32(2)
			} else {
				/* zNum is exactly 9223372036854775808.  Fits if negative.  The
				 ** special case 2 overflow if positive */
				if neg != 0 {
					v8 = rc
				} else {
					v8 = int32(3)
				}
				return v8
			}
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Transform a UTF-8 integer literal, in either decimal or hexadecimal,
//	** into a 64-bit signed integer.  This routine accepts hexadecimal literals,
//	** whereas sqlite3Atoi64() does not.
//	**
//	** Returns:
//	**
//	**     0    Successful transformation.  Fits in a 64-bit signed integer.
//	**     1    Excess text after the integer value
//	**     2    Integer too large for a 64-bit signed integer or is malformed
//	**     3    Special case of 9223372036854775808
//	*/
func _sqlite3DecOrHexToI64(tls *libc.TLS, z uintptr, pOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, k, n int32
	var _ /* u at bp+0 */ Tu64
	_, _, _ = i, k, n
	if int32(*(*int8)(unsafe.Pointer(z))) == int32('0') && (int32(*(*int8)(unsafe.Pointer(z + 1))) == int32('x') || int32(*(*int8)(unsafe.Pointer(z + 1))) == int32('X')) {
		*(*Tu64)(unsafe.Pointer(bp)) = uint64(0)
		i = int32(2)
		for {
			if !(int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) == int32('0')) {
				break
			}
			goto _1
		_1:
			;
			i++
		}
		k = i
		for {
			if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(k))))])&int32(0x08) != 0) {
				break
			}
			*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))*uint64(16) + uint64(_sqlite3HexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + uintptr(k))))))
			goto _2
		_2:
			;
			k++
		}
		libc.Xmemcpy(tls, pOut, bp, uint32(8))
		if k-i > int32(16) {
			return int32(2)
		}
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(k)))) != 0 {
			return int32(1)
		}
		return 0
	} else {
		n = int32(libc.Uint32FromInt32(0x3fffffff) & libc.Xstrspn(tls, z, __ccgo_ts+1776))
		if *(*int8)(unsafe.Pointer(z + uintptr(n))) != 0 {
			n++
		}
		return _sqlite3Atoi64(tls, z, pOut, n, uint8(SQLITE_UTF8))
	}
	return r
}

// C documentation
//
//	/*
//	** If zNum represents an integer that will fit in 32-bits, then set
//	** *pValue to that integer and return true.  Otherwise return false.
//	**
//	** This routine accepts both decimal and hexadecimal notation for integers.
//	**
//	** Any non-numeric characters that following zNum are ignored.
//	** This is different from sqlite3Atoi64() which requires the
//	** input number to be zero-terminated.
//	*/
func _sqlite3GetInt32(tls *libc.TLS, zNum uintptr, pValue uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c, i, neg, v3 int32
	var v Tsqlite_int64
	var v4 bool
	var _ /* u at bp+0 */ Tu32
	_, _, _, _, _, _ = c, i, neg, v, v3, v4
	v = 0
	neg = 0
	if int32(*(*int8)(unsafe.Pointer(zNum))) == int32('-') {
		neg = int32(1)
		zNum++
	} else {
		if int32(*(*int8)(unsafe.Pointer(zNum))) == int32('+') {
			zNum++
		} else {
			if int32(*(*int8)(unsafe.Pointer(zNum))) == int32('0') && (int32(*(*int8)(unsafe.Pointer(zNum + 1))) == int32('x') || int32(*(*int8)(unsafe.Pointer(zNum + 1))) == int32('X')) && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zNum + 2)))])&int32(0x08) != 0 {
				*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
				zNum += uintptr(2)
				for int32(*(*int8)(unsafe.Pointer(zNum))) == int32('0') {
					zNum++
				}
				i = 0
				for {
					if !(i < int32(8) && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zNum + uintptr(i))))])&int32(0x08) != 0) {
						break
					}
					*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(bp))*uint32(16) + uint32(_sqlite3HexToInt(tls, int32(*(*int8)(unsafe.Pointer(zNum + uintptr(i))))))
					goto _1
				_1:
					;
					i++
				}
				if *(*Tu32)(unsafe.Pointer(bp))&uint32(0x80000000) == uint32(0) && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zNum + uintptr(i))))])&int32(0x08) == 0 {
					libc.Xmemcpy(tls, pValue, bp, uint32(4))
					return int32(1)
				} else {
					return 0
				}
			}
		}
	}
	if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zNum)))])&libc.Int32FromInt32(0x04) != 0) {
		return 0
	}
	for int32(*(*int8)(unsafe.Pointer(zNum))) == int32('0') {
		zNum++
	}
	i = 0
	for {
		if v4 = i < int32(11); v4 {
			v3 = int32(*(*int8)(unsafe.Pointer(zNum + uintptr(i)))) - libc.Int32FromUint8('0')
			c = v3
		}
		if !(v4 && v3 >= 0 && c <= int32(9)) {
			break
		}
		v = v*int64(10) + int64(int64(c))
		goto _2
	_2:
		;
		i++
	}
	/* The longest decimal representation of a 32 bit integer is 10 digits:
	 **
	 **             1234567890
	 **     2^31 -> 2147483648
	 */
	if i > int32(10) {
		return 0
	}
	if v-int64(int64(neg)) > int64(2147483647) {
		return 0
	}
	if neg != 0 {
		v = -v
	}
	*(*int32)(unsafe.Pointer(pValue)) = int32(int32(v))
	return int32(1)
}

// C documentation
//
//	/*
//	** Return a 32-bit integer value extracted from a string.  If the
//	** string is not an integer, just return 0.
//	*/
func _sqlite3Atoi(tls *libc.TLS, z uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* x at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = 0
	_sqlite3GetInt32(tls, z, bp)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Decode a floating-point value into an approximate decimal
//	** representation.
//	**
//	** Round the decimal representation to n significant digits if
//	** n is positive.  Or round to -n signficant digits after the
//	** decimal point if n is negative.  No rounding is performed if
//	** n is zero.
//	**
//	** The significant digits of the decimal representation are
//	** stored in p->z[] which is a often (but not always) a pointer
//	** into the middle of p->zBuf[].  There are p->n significant digits.
//	** The p->z[] array is *not* zero-terminated.
//	*/
func _sqlite3FpDecode(tls *libc.TLS, p uintptr, _r float64, iRound int32, mxRound int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	*(*float64)(unsafe.Pointer(bp)) = _r
	var e, exp, i, j, v2, v3, v4 int32
	var rr float64
	var z uintptr
	var v1 uint64
	var _ /* rr at bp+16 */ [2]float64
	var _ /* v at bp+8 */ Tu64
	_, _, _, _, _, _, _, _, _, _ = e, exp, i, j, rr, z, v1, v2, v3, v4
	exp = 0
	(*TFpDecode)(unsafe.Pointer(p)).FisSpecial = 0
	(*TFpDecode)(unsafe.Pointer(p)).Fz = p + 16
	/* Convert negative numbers to positive.  Deal with Infinity, 0.0, and
	 ** NaN. */
	if *(*float64)(unsafe.Pointer(bp)) < float64(0) {
		(*TFpDecode)(unsafe.Pointer(p)).Fsign = int8('-')
		*(*float64)(unsafe.Pointer(bp)) = -*(*float64)(unsafe.Pointer(bp))
	} else {
		if *(*float64)(unsafe.Pointer(bp)) == float64(0) {
			(*TFpDecode)(unsafe.Pointer(p)).Fsign = int8('+')
			(*TFpDecode)(unsafe.Pointer(p)).Fn = int32(1)
			(*TFpDecode)(unsafe.Pointer(p)).FiDP = int32(1)
			(*TFpDecode)(unsafe.Pointer(p)).Fz = __ccgo_ts + 1792
			return
		} else {
			(*TFpDecode)(unsafe.Pointer(p)).Fsign = int8('+')
		}
	}
	libc.Xmemcpy(tls, bp+8, bp, uint32(8))
	e = int32(*(*Tu64)(unsafe.Pointer(bp + 8)) >> int32(52))
	if e&int32(0x7ff) == int32(0x7ff) {
		(*TFpDecode)(unsafe.Pointer(p)).FisSpecial = int8(int32(1) + libc.BoolInt32(*(*Tu64)(unsafe.Pointer(bp + 8)) != uint64(0x7ff0000000000000)))
		(*TFpDecode)(unsafe.Pointer(p)).Fn = 0
		(*TFpDecode)(unsafe.Pointer(p)).FiDP = 0
		return
	}
	/* Multiply r by powers of ten until it lands somewhere in between
	 ** 1.0e+19 and 1.0e+17.
	 */
	if _sqlite3Config.FbUseLongDouble != 0 {
		rr = *(*float64)(unsafe.Pointer(bp))
		if rr >= float64(1e+19) {
			for float64(float64(rr)) >= libc.Float64FromFloat64(1e+119) {
				exp += int32(100)
				rr = float64(float64(rr) * libc.Float64FromFloat64(1e-100))
			}
			for float64(float64(rr)) >= libc.Float64FromFloat64(1e+29) {
				exp += int32(10)
				rr = float64(float64(rr) * libc.Float64FromFloat64(1e-10))
			}
			for float64(float64(rr)) >= libc.Float64FromFloat64(1e+19) {
				exp++
				rr = float64(float64(rr) * libc.Float64FromFloat64(0.1))
			}
		} else {
			for float64(float64(rr)) < libc.Float64FromFloat64(1e-97) {
				exp -= int32(100)
				rr = float64(float64(rr) * libc.Float64FromFloat64(1e+100))
			}
			for float64(float64(rr)) < libc.Float64FromFloat64(1e+07) {
				exp -= int32(10)
				rr = float64(float64(rr) * libc.Float64FromFloat64(1e+10))
			}
			for float64(float64(rr)) < libc.Float64FromFloat64(1e+17) {
				exp--
				rr = float64(float64(rr) * libc.Float64FromFloat64(10))
			}
		}
		*(*Tu64)(unsafe.Pointer(bp + 8)) = uint64(uint64(rr))
	} else {
		(*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] = *(*float64)(unsafe.Pointer(bp))
		(*(*[2]float64)(unsafe.Pointer(bp + 16)))[int32(1)] = float64(0)
		if (*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] > float64(9.223372036854775e+18) {
			for (*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] > float64(9.223372036854774e+118) {
				exp += int32(100)
				_dekkerMul2(tls, bp+16, float64(1e-100), -libc.Float64FromFloat64(1.9991899802602883e-117))
			}
			for (*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] > float64(9.223372036854774e+28) {
				exp += int32(10)
				_dekkerMul2(tls, bp+16, float64(1e-10), -libc.Float64FromFloat64(3.643219731549774e-27))
			}
			for (*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] > float64(9.223372036854775e+18) {
				exp += int32(1)
				_dekkerMul2(tls, bp+16, float64(0.1), -libc.Float64FromFloat64(5.551115123125783e-18))
			}
		} else {
			for (*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] < float64(9.223372036854775e-83) {
				exp -= int32(100)
				_dekkerMul2(tls, bp+16, float64(1e+100), -libc.Float64FromFloat64(1.5902891109759918e+83))
			}
			for (*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] < float64(9.223372036854775e+07) {
				exp -= int32(10)
				_dekkerMul2(tls, bp+16, float64(1e+10), float64(0))
			}
			for (*(*[2]float64)(unsafe.Pointer(bp + 16)))[0] < float64(9.223372036854775e+17) {
				exp -= int32(1)
				_dekkerMul2(tls, bp+16, float64(10), float64(0))
			}
		}
		if (*(*[2]float64)(unsafe.Pointer(bp + 16)))[int32(1)] < float64(0) {
			v1 = uint64((*(*[2]float64)(unsafe.Pointer(bp + 16)))[0]) - uint64(-(*(*[2]float64)(unsafe.Pointer(bp + 16)))[int32(1)])
		} else {
			v1 = uint64((*(*[2]float64)(unsafe.Pointer(bp + 16)))[0]) + uint64((*(*[2]float64)(unsafe.Pointer(bp + 16)))[int32(1)])
		}
		*(*Tu64)(unsafe.Pointer(bp + 8)) = v1
	}
	/* Extract significant digits. */
	i = int32(libc.Uint32FromInt64(24) - libc.Uint32FromInt32(1))
	for *(*Tu64)(unsafe.Pointer(bp + 8)) != 0 {
		v2 = i
		i--
		*(*int8)(unsafe.Pointer(p + 16 + uintptr(v2))) = int8(*(*Tu64)(unsafe.Pointer(bp + 8))%uint64(10) + uint64('0'))
		*(*Tu64)(unsafe.Pointer(bp + 8)) /= uint64(10)
	}
	(*TFpDecode)(unsafe.Pointer(p)).Fn = int32(libc.Uint32FromInt64(24) - libc.Uint32FromInt32(1) - uint32(uint32(i)))
	(*TFpDecode)(unsafe.Pointer(p)).FiDP = (*TFpDecode)(unsafe.Pointer(p)).Fn + exp
	if iRound <= 0 {
		iRound = (*TFpDecode)(unsafe.Pointer(p)).FiDP - iRound
		if iRound == 0 && int32(*(*int8)(unsafe.Pointer(p + 16 + uintptr(i+int32(1))))) >= int32('5') {
			iRound = int32(1)
			v3 = i
			i--
			*(*int8)(unsafe.Pointer(p + 16 + uintptr(v3))) = int8('0')
			(*TFpDecode)(unsafe.Pointer(p)).Fn++
			(*TFpDecode)(unsafe.Pointer(p)).FiDP++
		}
	}
	if iRound > 0 && (iRound < (*TFpDecode)(unsafe.Pointer(p)).Fn || (*TFpDecode)(unsafe.Pointer(p)).Fn > mxRound) {
		z = p + 16 + uintptr(i+int32(1))
		if iRound > mxRound {
			iRound = mxRound
		}
		(*TFpDecode)(unsafe.Pointer(p)).Fn = iRound
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(iRound)))) >= int32('5') {
			j = iRound - int32(1)
			for int32(1) != 0 {
				*(*int8)(unsafe.Pointer(z + uintptr(j)))++
				if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) <= int32('9') {
					break
				}
				*(*int8)(unsafe.Pointer(z + uintptr(j))) = int8('0')
				if j == 0 {
					v4 = i
					i--
					*(*int8)(unsafe.Pointer((*TFpDecode)(unsafe.Pointer(p)).Fz + uintptr(v4))) = int8('1')
					(*TFpDecode)(unsafe.Pointer(p)).Fn++
					(*TFpDecode)(unsafe.Pointer(p)).FiDP++
					break
				} else {
					j--
				}
			}
		}
	}
	(*TFpDecode)(unsafe.Pointer(p)).Fz = p + 16 + uintptr(i+int32(1))
	for (*TFpDecode)(unsafe.Pointer(p)).Fn > 0 && int32(*(*int8)(unsafe.Pointer((*TFpDecode)(unsafe.Pointer(p)).Fz + uintptr((*TFpDecode)(unsafe.Pointer(p)).Fn-int32(1))))) == int32('0') {
		(*TFpDecode)(unsafe.Pointer(p)).Fn--
	}
}

// C documentation
//
//	/*
//	** Try to convert z into an unsigned 32-bit integer.  Return true on
//	** success and false if there is an error.
//	**
//	** Only decimal notation is accepted.
//	*/
func _sqlite3GetUInt32(tls *libc.TLS, z uintptr, pI uintptr) (r int32) {
	var i int32
	var v Tu64
	_, _ = i, v
	v = uint64(0)
	i = 0
	for {
		if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i))))])&int32(0x04) != 0) {
			break
		}
		v = v*uint64(10) + uint64(*(*int8)(unsafe.Pointer(z + uintptr(i)))) - uint64('0')
		if v > uint64(4294967296) {
			*(*Tu32)(unsafe.Pointer(pI)) = uint32(0)
			return 0
		}
		goto _1
	_1:
		;
		i++
	}
	if i == 0 || int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) != 0 {
		*(*Tu32)(unsafe.Pointer(pI)) = uint32(0)
		return 0
	}
	*(*Tu32)(unsafe.Pointer(pI)) = uint32(uint32(v))
	return int32(1)
}

/*
** The variable-length integer encoding is as follows:
**
** KEY:
**         A = 0xxxxxxx    7 bits of data and one flag bit
**         B = 1xxxxxxx    7 bits of data and one flag bit
**         C = xxxxxxxx    8 bits of data
**
**  7 bits - A
** 14 bits - BA
** 21 bits - BBA
** 28 bits - BBBA
** 35 bits - BBBBA
** 42 bits - BBBBBA
** 49 bits - BBBBBBA
** 56 bits - BBBBBBBA
** 64 bits - BBBBBBBBC
 */

// C documentation
//
//	/*
//	** Write a 64-bit variable-length integer to memory starting at p[0].
//	** The length of data write will be between 1 and 9 bytes.  The number
//	** of bytes written is returned.
//	**
//	** A variable-length integer consists of the lower 7 bits of each byte
//	** for all bytes that have the 8th bit set and one byte with the 8th
//	** bit clear.  Except, if we get to the 9th byte, it stores the full
//	** 8 bits and is the last byte.
//	*/
func _putVarint64(tls *libc.TLS, p uintptr, v Tu64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, j, n, v2 int32
	var p3 uintptr
	var _ /* buf at bp+0 */ [10]Tu8
	_, _, _, _, _ = i, j, n, v2, p3
	if v&(libc.Uint64FromUint32(0xff000000)<<libc.Int32FromInt32(32)) != 0 {
		*(*uint8)(unsafe.Pointer(p + 8)) = uint8(uint8(v))
		v >>= uint64(8)
		i = int32(7)
		for {
			if !(i >= 0) {
				break
			}
			*(*uint8)(unsafe.Pointer(p + uintptr(i))) = uint8(v&libc.Uint64FromInt32(0x7f) | libc.Uint64FromInt32(0x80))
			v >>= uint64(7)
			goto _1
		_1:
			;
			i--
		}
		return int32(9)
	}
	n = 0
	for cond := true; cond; cond = v != uint64(0) {
		v2 = n
		n++
		(*(*[10]Tu8)(unsafe.Pointer(bp)))[v2] = uint8(v&libc.Uint64FromInt32(0x7f) | libc.Uint64FromInt32(0x80))
		v >>= uint64(7)
	}
	p3 = bp
	*(*Tu8)(unsafe.Pointer(p3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p3))) & libc.Int32FromInt32(0x7f))
	i = 0
	j = n - libc.Int32FromInt32(1)
	for {
		if !(j >= 0) {
			break
		}
		*(*uint8)(unsafe.Pointer(p + uintptr(i))) = (*(*[10]Tu8)(unsafe.Pointer(bp)))[j]
		goto _4
	_4:
		;
		j--
		i++
	}
	return n
}

func _sqlite3PutVarint(tls *libc.TLS, p uintptr, v Tu64) (r int32) {
	if v <= uint64(0x7f) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v & uint64(0x7f))
		return int32(1)
	}
	if v <= uint64(0x3fff) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v>>libc.Int32FromInt32(7)&uint64(0x7f) | uint64(0x80))
		*(*uint8)(unsafe.Pointer(p + 1)) = uint8(v & uint64(0x7f))
		return int32(2)
	}
	return _putVarint64(tls, p, v)
}

/*
** Bitmasks used by sqlite3GetVarint().  These precomputed constants
** are defined here rather than simply putting the constant expressions
** inline in order to work around bugs in the RVT compiler.
**
** SLOT_2_0     A mask for  (0x7f<<14) | 0x7f
**
** SLOT_4_2_0   A mask for  (0x7f<<28) | SLOT_2_0
 */

// C documentation
//
//	/*
//	** Read a 64-bit variable-length integer from memory starting at p[0].
//	** Return the number of bytes read.  The value is stored in *v.
//	*/
func _sqlite3GetVarint(tls *libc.TLS, p uintptr, v uintptr) (r Tu8) {
	var a, b, s Tu32
	_, _, _ = a, b, s
	if int32(*(*int8)(unsafe.Pointer(p))) >= 0 {
		*(*Tu64)(unsafe.Pointer(v)) = uint64(*(*uint8)(unsafe.Pointer(p)))
		return uint8(1)
	}
	if int32(*(*int8)(unsafe.Pointer(p + 1))) >= 0 {
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint32(int32(*(*uint8)(unsafe.Pointer(p)))&libc.Int32FromInt32(0x7f))<<libc.Int32FromInt32(7) | uint32(*(*uint8)(unsafe.Pointer(p + 1))))
		return uint8(2)
	}
	/* Verify that constants are precomputed correctly */
	a = uint32(*(*uint8)(unsafe.Pointer(p))) << int32(14)
	b = uint32(*(*uint8)(unsafe.Pointer(p + 1)))
	p += uintptr(2)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p0<<14 | p2 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		a &= uint32(SLOT_2_0)
		b &= uint32(0x7f)
		b = b << int32(7)
		a |= b
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(a))
		return uint8(3)
	}
	/* CSE1 from below */
	a &= uint32(SLOT_2_0)
	p++
	b = b << int32(14)
	b |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p1<<14 | p3 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		b &= uint32(SLOT_2_0)
		/* moved CSE1 up */
		/* a &= (0x7f<<14)|(0x7f); */
		a = a << int32(7)
		a |= b
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(a))
		return uint8(4)
	}
	/* a: p0<<14 | p2 (masked) */
	/* b: p1<<14 | p3 (unmasked) */
	/* 1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
	/* moved CSE1 up */
	/* a &= (0x7f<<14)|(0x7f); */
	b &= uint32(SLOT_2_0)
	s = a
	/* s: p0<<14 | p2 (masked) */
	p++
	a = a << int32(14)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p0<<28 | p2<<14 | p4 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		/* we can skip these cause they were (effectively) done above
		 ** while calculating s */
		/* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
		/* b &= (0x7f<<14)|(0x7f); */
		b = b << int32(7)
		a |= b
		s = s >> int32(18)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(5)
	}
	/* 2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
	s = s << int32(7)
	s |= b
	/* s: p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
	p++
	b = b << int32(14)
	b |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p1<<28 | p3<<14 | p5 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		/* we can skip this cause it was (effectively) done above in calc'ing s */
		/* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
		a &= uint32(SLOT_2_0)
		a = a << int32(7)
		a |= b
		s = s >> int32(18)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(6)
	}
	p++
	a = a << int32(14)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p2<<28 | p4<<14 | p6 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		a &= uint32(SLOT_4_2_0)
		b &= uint32(SLOT_2_0)
		b = b << int32(7)
		a |= b
		s = s >> int32(11)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(7)
	}
	/* CSE2 from below */
	a &= uint32(SLOT_2_0)
	p++
	b = b << int32(14)
	b |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p3<<28 | p5<<14 | p7 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		b &= uint32(SLOT_4_2_0)
		/* moved CSE2 up */
		/* a &= (0x7f<<14)|(0x7f); */
		a = a << int32(7)
		a |= b
		s = s >> int32(4)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(8)
	}
	p++
	a = a << int32(15)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p4<<29 | p6<<15 | p8 (unmasked) */
	/* moved CSE2 up */
	/* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
	b &= uint32(SLOT_2_0)
	b = b << int32(8)
	a |= b
	s = s << int32(4)
	b = uint32(*(*uint8)(unsafe.Pointer(p + uintptr(-libc.Int32FromInt32(4)))))
	b &= uint32(0x7f)
	b = b >> int32(3)
	s |= b
	*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
	return uint8(9)
}

// C documentation
//
//	/*
//	** Read a 32-bit variable-length integer from memory starting at p[0].
//	** Return the number of bytes read.  The value is stored in *v.
//	**
//	** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
//	** integer, then set *v to 0xffffffff.
//	**
//	** A MACRO version, getVarint32, is provided which inlines the
//	** single-byte case.  All code should use the MACRO version as
//	** this function assumes the single-byte case has already been handled.
//	*/
func _sqlite3GetVarint32(tls *libc.TLS, p uintptr, v uintptr) (r Tu8) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var n Tu8
	var _ /* v64 at bp+0 */ Tu64
	_ = n
	/* Assume that the single-byte case has already been handled by
	 ** the getVarint32() macro */
	if int32(*(*uint8)(unsafe.Pointer(p + 1)))&int32(0x80) == 0 {
		/* This is the two-byte case */
		*(*Tu32)(unsafe.Pointer(v)) = uint32(int32(*(*uint8)(unsafe.Pointer(p)))&int32(0x7f)<<int32(7) | int32(*(*uint8)(unsafe.Pointer(p + 1))))
		return uint8(2)
	}
	if int32(*(*uint8)(unsafe.Pointer(p + 2)))&int32(0x80) == 0 {
		/* This is the three-byte case */
		*(*Tu32)(unsafe.Pointer(v)) = uint32(int32(*(*uint8)(unsafe.Pointer(p)))&int32(0x7f)<<int32(14) | int32(*(*uint8)(unsafe.Pointer(p + 1)))&int32(0x7f)<<int32(7) | int32(*(*uint8)(unsafe.Pointer(p + 2))))
		return uint8(3)
	}
	/* four or more bytes */
	n = _sqlite3GetVarint(tls, p, bp)
	if *(*Tu64)(unsafe.Pointer(bp))&(libc.Uint64FromInt32(1)<<libc.Int32FromInt32(32)-libc.Uint64FromInt32(1)) != *(*Tu64)(unsafe.Pointer(bp)) {
		*(*Tu32)(unsafe.Pointer(v)) = uint32(0xffffffff)
	} else {
		*(*Tu32)(unsafe.Pointer(v)) = uint32(*(*Tu64)(unsafe.Pointer(bp)))
	}
	return n
}

// C documentation
//
//	/*
//	** Return the number of bytes that will be needed to store the given
//	** 64-bit integer.
//	*/
func _sqlite3VarintLen(tls *libc.TLS, v Tu64) (r int32) {
	var i int32
	_ = i
	i = int32(1)
	for {
		v >>= uint64(7)
		if !(v != uint64(0)) {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	return i
}

// 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, uint32(4))
	return libc.X__builtin_bswap32(tls, *(*Tu32)(unsafe.Pointer(bp)))
}

func _sqlite3Put4byte(tls *libc.TLS, p uintptr, v Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* x at bp+0 */ Tu32
	*(*Tu32)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, v)
	libc.Xmemcpy(tls, p, bp, uint32(4))
}

// C documentation
//
//	/*
//	** Translate a single byte of Hex into an integer.
//	** This routine only works if h really is a valid hexadecimal
//	** character:  0..9a..fA..F
//	*/
func _sqlite3HexToInt(tls *libc.TLS, h int32) (r Tu8) {
	h += int32(9) * (int32(1) & (h >> int32(6)))
	return uint8(h & libc.Int32FromInt32(0xf))
}

// C documentation
//
//	/*
//	** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
//	** value.  Return a pointer to its binary value.  Space to hold the
//	** binary value has been obtained from malloc and must be freed by
//	** the calling routine.
//	*/
func _sqlite3HexToBlob(tls *libc.TLS, db uintptr, z uintptr, n int32) (r uintptr) {
	var i int32
	var zBlob uintptr
	_, _ = i, zBlob
	zBlob = _sqlite3DbMallocRawNN(tls, db, uint64(n/int32(2)+int32(1)))
	n--
	if zBlob != 0 {
		i = 0
		for {
			if !(i < n) {
				break
			}
			*(*int8)(unsafe.Pointer(zBlob + uintptr(i/int32(2)))) = int8(int32(_sqlite3HexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + uintptr(i))))))<<int32(4) | int32(_sqlite3HexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + uintptr(i+int32(1))))))))
			goto _1
		_1:
			;
			i += int32(2)
		}
		*(*int8)(unsafe.Pointer(zBlob + uintptr(i/int32(2)))) = 0
	}
	return zBlob
}

// C documentation
//
//	/*
//	** Log an error that is an API call on a connection pointer that should
//	** not have been used.  The "type" of connection pointer is given as the
//	** argument.  The zType is a word like "NULL" or "closed" or "invalid".
//	*/
func _logBadConnection(tls *libc.TLS, zType uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+1794, libc.VaList(bp+8, zType))
}

// C documentation
//
//	/*
//	** Check to make sure we have a valid db pointer.  This test is not
//	** foolproof but it does provide some measure of protection against
//	** misuse of the interface such as passing in db pointers that are
//	** NULL or which have been previously closed.  If this routine returns
//	** 1 it means that the db pointer is valid and 0 if it should not be
//	** dereferenced for any reason.  The calling function should invoke
//	** SQLITE_MISUSE immediately.
//	**
//	** sqlite3SafetyCheckOk() requires that the db pointer be valid for
//	** use.  sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
//	** open properly and is not fit for general use but which can be
//	** used as an argument to sqlite3_errmsg() or sqlite3_close().
//	*/
func _sqlite3SafetyCheckOk(tls *libc.TLS, db uintptr) (r int32) {
	var eOpenState Tu8
	_ = eOpenState
	if db == uintptr(0) {
		_logBadConnection(tls, __ccgo_ts+1673)
		return 0
	}
	eOpenState = (*Tsqlite3)(unsafe.Pointer(db)).FeOpenState
	if int32(int32(eOpenState)) != int32(SQLITE_STATE_OPEN) {
		if _sqlite3SafetyCheckSickOrOk(tls, db) != 0 {
			_logBadConnection(tls, __ccgo_ts+1839)
		}
		return 0
	} else {
		return int32(1)
	}
	return r
}

func _sqlite3SafetyCheckSickOrOk(tls *libc.TLS, db uintptr) (r int32) {
	var eOpenState Tu8
	_ = eOpenState
	eOpenState = (*Tsqlite3)(unsafe.Pointer(db)).FeOpenState
	if int32(int32(eOpenState)) != int32(SQLITE_STATE_SICK) && int32(int32(eOpenState)) != int32(SQLITE_STATE_OPEN) && int32(int32(eOpenState)) != int32(SQLITE_STATE_BUSY) {
		_logBadConnection(tls, __ccgo_ts+1848)
		return 0
	} else {
		return int32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Attempt to add, subtract, or multiply the 64-bit signed value iB against
//	** the other 64-bit signed integer at *pA and store the result in *pA.
//	** Return 0 on success.  Or if the operation would have resulted in an
//	** overflow, leave *pA unchanged and return 1.
//	*/
func _sqlite3AddInt64(tls *libc.TLS, pA uintptr, iB Ti64) (r int32) {
	return libc.X__builtin_add_overflowInt64(tls, *(*Ti64)(unsafe.Pointer(pA)), iB, pA)
}

func _sqlite3SubInt64(tls *libc.TLS, pA uintptr, iB Ti64) (r int32) {
	return libc.X__builtin_sub_overflowInt64(tls, *(*Ti64)(unsafe.Pointer(pA)), iB, pA)
}

func _sqlite3MulInt64(tls *libc.TLS, pA uintptr, iB Ti64) (r int32) {
	return libc.X__builtin_mul_overflowInt64(tls, *(*Ti64)(unsafe.Pointer(pA)), iB, pA)
}

// C documentation
//
//	/*
//	** Compute the absolute value of a 32-bit signed integer, of possible.  Or
//	** if the integer has a value of -2147483648, return +2147483647
//	*/
func _sqlite3AbsInt32(tls *libc.TLS, x int32) (r int32) {
	if x >= 0 {
		return x
	}
	if x == libc.Int32FromUint32(0x80000000) {
		return int32(0x7fffffff)
	}
	return -x
}

// C documentation
//
//	/*
//	** Find (an approximate) sum of two LogEst values.  This computation is
//	** not a simple "+" operator because LogEst is stored as a logarithmic
//	** value.
//	**
//	*/
func _sqlite3LogEstAdd(tls *libc.TLS, a TLogEst, b TLogEst) (r TLogEst) {
	if int32(int32(a)) >= int32(int32(b)) {
		if int32(int32(a)) > int32(int32(b))+int32(49) {
			return a
		}
		if int32(int32(a)) > int32(int32(b))+int32(31) {
			return int16(int32(int32(a)) + int32(1))
		}
		return int16(int32(int32(a)) + int32(_x[int32(int32(a))-int32(int32(b))]))
	} else {
		if int32(int32(b)) > int32(int32(a))+int32(49) {
			return b
		}
		if int32(int32(b)) > int32(int32(a))+int32(31) {
			return int16(int32(int32(b)) + int32(1))
		}
		return int16(int32(int32(b)) + int32(_x[int32(int32(b))-int32(int32(a))]))
	}
	return r
}

var _x = [32]uint8{
	0:  uint8(10),
	1:  uint8(10),
	2:  uint8(9),
	3:  uint8(9),
	4:  uint8(8),
	5:  uint8(8),
	6:  uint8(7),
	7:  uint8(7),
	8:  uint8(7),
	9:  uint8(6),
	10: uint8(6),
	11: uint8(6),
	12: uint8(5),
	13: uint8(5),
	14: uint8(5),
	15: uint8(4),
	16: uint8(4),
	17: uint8(4),
	18: uint8(4),
	19: uint8(3),
	20: uint8(3),
	21: uint8(3),
	22: uint8(3),
	23: uint8(3),
	24: uint8(3),
	25: uint8(2),
	26: uint8(2),
	27: uint8(2),
	28: uint8(2),
	29: uint8(2),
	30: uint8(2),
	31: uint8(2),
}

// C documentation
//
//	/*
//	** Convert an integer into a LogEst.  In other words, compute an
//	** approximation for 10*log2(x).
//	*/
func _sqlite3LogEst(tls *libc.TLS, x Tu64) (r TLogEst) {
	var i int32
	var y TLogEst
	_, _ = i, y
	y = int16(40)
	if x < uint64(8) {
		if x < uint64(2) {
			return 0
		}
		for x < uint64(8) {
			y = TLogEst(int32(y) - libc.Int32FromInt32(10))
			x <<= uint64(1)
		}
	} else {
		i = int32(60) - libc.X__builtin_clzll(tls, x)
		y = TLogEst(int32(y) + i*libc.Int32FromInt32(10))
		x >>= uint64(uint64(i))
	}
	return int16(int32(_a[x&uint64(7)]) + int32(int32(y)) - int32(10))
}

var _a = [8]TLogEst{
	1: int16(2),
	2: int16(3),
	3: int16(5),
	4: int16(6),
	5: int16(7),
	6: int16(8),
	7: int16(9),
}

// C documentation
//
//	/*
//	** Convert a double into a LogEst
//	** In other words, compute an approximation for 10*log2(x).
//	*/
func _sqlite3LogEstFromDouble(tls *libc.TLS, _x float64) (r TLogEst) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = _x
	var e TLogEst
	var _ /* a at bp+8 */ Tu64
	_ = e
	if *(*float64)(unsafe.Pointer(bp)) <= libc.Float64FromInt32(1) {
		return 0
	}
	if *(*float64)(unsafe.Pointer(bp)) <= libc.Float64FromInt32(2000000000) {
		return _sqlite3LogEst(tls, uint64(*(*float64)(unsafe.Pointer(bp))))
	}
	libc.Xmemcpy(tls, bp+8, bp, uint32(8))
	e = int16(*(*Tu64)(unsafe.Pointer(bp + 8))>>libc.Int32FromInt32(52) - uint64(1022))
	return int16(int32(int32(e)) * int32(10))
}

// C documentation
//
//	/*
//	** Convert a LogEst into an integer.
//	*/
func _sqlite3LogEstToInt(tls *libc.TLS, x TLogEst) (r Tu64) {
	var n Tu64
	var v1 uint64
	_, _ = n, v1
	n = uint64(int32(int32(x)) % int32(10))
	x = TLogEst(int32(x) / libc.Int32FromInt32(10))
	if n >= uint64(5) {
		n -= uint64(2)
	} else {
		if n >= uint64(1) {
			n -= uint64(1)
		}
	}
	if int32(int32(x)) > int32(60) {
		return uint64(libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
	}
	if int32(int32(x)) >= int32(3) {
		v1 = (n + uint64(8)) << (int32(int32(x)) - int32(3))
	} else {
		v1 = (n + uint64(8)) >> (int32(3) - int32(int32(x)))
	}
	return v1
}

// C documentation
//
//	/*
//	** Add a new name/number pair to a VList.  This might require that the
//	** VList object be reallocated, so return the new VList.  If an OOM
//	** error occurs, the original VList returned and the
//	** db->mallocFailed flag is set.
//	**
//	** A VList is really just an array of integers.  To destroy a VList,
//	** simply pass it to sqlite3DbFree().
//	**
//	** The first integer is the number of integers allocated for the whole
//	** VList.  The second integer is the number of integers actually used.
//	** Each name/number pair is encoded by subsequent groups of 3 or more
//	** integers.
//	**
//	** Each name/number pair starts with two integers which are the numeric
//	** value for the pair and the size of the name/number pair, respectively.
//	** The text name overlays one or more following integers.  The text name
//	** is always zero-terminated.
//	**
//	** Conceptually:
//	**
//	**    struct VList {
//	**      int nAlloc;   // Number of allocated slots
//	**      int nUsed;    // Number of used slots
//	**      struct VListEntry {
//	**        int iValue;    // Value for this entry
//	**        int nSlot;     // Slots used by this entry
//	**        // ... variable name goes here
//	**      } a[0];
//	**    }
//	**
//	** During code generation, pointers to the variable names within the
//	** VList are taken.  When that happens, nAlloc is set to zero as an
//	** indication that the VList may never again be enlarged, since the
//	** accompanying realloc() would invalidate the pointers.
//	*/
func _sqlite3VListAdd(tls *libc.TLS, db uintptr, pIn uintptr, zName uintptr, nName int32, iVal int32) (r uintptr) {
	var i, nInt int32
	var nAlloc Tsqlite3_int64
	var pOut, z uintptr
	var v1 int64
	_, _, _, _, _, _ = i, nAlloc, nInt, pOut, z, v1 /* Index in pIn[] where zName is stored */
	nInt = nName/int32(4) + int32(3)
	/* Verify ok to add new elements */
	if pIn == uintptr(0) || *(*TVList)(unsafe.Pointer(pIn + 1*4))+nInt > *(*TVList)(unsafe.Pointer(pIn)) {
		if pIn != 0 {
			v1 = int64(2) * int64(*(*TVList)(unsafe.Pointer(pIn)))
		} else {
			v1 = int64(10)
		}
		/* Enlarge the allocation */
		nAlloc = v1 + int64(int64(nInt))
		pOut = _sqlite3DbRealloc(tls, db, pIn, uint64(nAlloc*int64(4)))
		if pOut == uintptr(0) {
			return pIn
		}
		if pIn == uintptr(0) {
			*(*TVList)(unsafe.Pointer(pOut + 1*4)) = int32(2)
		}
		pIn = pOut
		*(*TVList)(unsafe.Pointer(pIn)) = int32(int32(nAlloc))
	}
	i = *(*TVList)(unsafe.Pointer(pIn + 1*4))
	*(*TVList)(unsafe.Pointer(pIn + uintptr(i)*4)) = iVal
	*(*TVList)(unsafe.Pointer(pIn + uintptr(i+int32(1))*4)) = nInt
	z = pIn + uintptr(i+int32(2))*4
	*(*TVList)(unsafe.Pointer(pIn + 1*4)) = i + nInt
	libc.Xmemcpy(tls, z, zName, uint32(uint32(nName)))
	*(*int8)(unsafe.Pointer(z + uintptr(nName))) = 0
	return pIn
}

// C documentation
//
//	/*
//	** Return a pointer to the name of a variable in the given VList that
//	** has the value iVal.  Or return a NULL if there is no such variable in
//	** the list
//	*/
func _sqlite3VListNumToName(tls *libc.TLS, pIn uintptr, iVal int32) (r uintptr) {
	var i, mx int32
	_, _ = i, mx
	if pIn == uintptr(0) {
		return uintptr(0)
	}
	mx = *(*TVList)(unsafe.Pointer(pIn + 1*4))
	i = int32(2)
	for cond := true; cond; cond = i < mx {
		if *(*TVList)(unsafe.Pointer(pIn + uintptr(i)*4)) == iVal {
			return pIn + uintptr(i+int32(2))*4
		}
		i += *(*TVList)(unsafe.Pointer(pIn + uintptr(i+int32(1))*4))
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Return the number of the variable named zName, if it is in VList.
//	** or return 0 if there is no such variable.
//	*/
func _sqlite3VListNameToNum(tls *libc.TLS, pIn uintptr, zName uintptr, nName int32) (r int32) {
	var i, mx int32
	var z uintptr
	_, _, _ = i, mx, z
	if pIn == uintptr(0) {
		return 0
	}
	mx = *(*TVList)(unsafe.Pointer(pIn + 1*4))
	i = int32(2)
	for cond := true; cond; cond = i < mx {
		z = pIn + uintptr(i+int32(2))*4
		if libc.Xstrncmp(tls, z, zName, uint32(uint32(nName))) == 0 && int32(*(*int8)(unsafe.Pointer(z + uintptr(nName)))) == 0 {
			return *(*TVList)(unsafe.Pointer(pIn + uintptr(i)*4))
		}
		i += *(*TVList)(unsafe.Pointer(pIn + uintptr(i+int32(1))*4))
	}
	return 0
}

/*
** High-resolution hardware timer used for debugging and testing only.
 */

/************** End of util.c ************************************************/
/************** Begin file hash.c ********************************************/
/*
** 2001 September 22
**
** 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 is the implementation of generic hash-tables
** used in SQLite.
 */
/* #include "sqliteInt.h" */
/* #include <assert.h> */

// C documentation
//
//	/* Turn bulk memory into a hash table object by initializing the
//	** fields of the Hash structure.
//	**
//	** "pNew" is a pointer to the hash table that is to be initialized.
//	*/
func _sqlite3HashInit(tls *libc.TLS, pNew uintptr) {
	(*THash)(unsafe.Pointer(pNew)).Ffirst = uintptr(0)
	(*THash)(unsafe.Pointer(pNew)).Fcount = uint32(0)
	(*THash)(unsafe.Pointer(pNew)).Fhtsize = uint32(0)
	(*THash)(unsafe.Pointer(pNew)).Fht = uintptr(0)
}

// C documentation
//
//	/* Remove all entries from a hash table.  Reclaim all memory.
//	** Call this routine to delete a hash table or to reset a hash table
//	** to the empty state.
//	*/
func _sqlite3HashClear(tls *libc.TLS, pH uintptr) {
	var elem, next_elem uintptr
	_, _ = elem, next_elem /* For looping over all elements of the table */
	elem = (*THash)(unsafe.Pointer(pH)).Ffirst
	(*THash)(unsafe.Pointer(pH)).Ffirst = uintptr(0)
	Xsqlite3_free(tls, (*THash)(unsafe.Pointer(pH)).Fht)
	(*THash)(unsafe.Pointer(pH)).Fht = uintptr(0)
	(*THash)(unsafe.Pointer(pH)).Fhtsize = uint32(0)
	for elem != 0 {
		next_elem = (*THashElem)(unsafe.Pointer(elem)).Fnext
		Xsqlite3_free(tls, elem)
		elem = next_elem
	}
	(*THash)(unsafe.Pointer(pH)).Fcount = uint32(0)
}

// C documentation
//
//	/*
//	** The hashing function.
//	*/
func _strHash(tls *libc.TLS, z uintptr) (r uint32) {
	var c, v1 uint8
	var h uint32
	var v2 uintptr
	_, _, _, _ = c, h, v1, v2
	h = uint32(0)
	for {
		v2 = z
		z++
		v1 = uint8(*(*int8)(unsafe.Pointer(v2)))
		c = v1
		if !(int32(v1) != 0) {
			break
		} /*OPTIMIZATION-IF-TRUE*/
		/* Knuth multiplicative hashing.  (Sorting & Searching, p. 510).
		 ** 0x9e3779b1 is 2654435761 which is the closest prime number to
		 ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */
		h += uint32(_sqlite3UpperToLower[c])
		h *= uint32(0x9e3779b1)
	}
	return h
}

// C documentation
//
//	/* Link pNew element into the hash table pH.  If pEntry!=0 then also
//	** insert pNew into the pEntry hash bucket.
//	*/
func _insertElement(tls *libc.TLS, pH uintptr, pEntry uintptr, pNew uintptr) {
	var pHead, v1 uintptr
	_, _ = pHead, v1 /* First element already in pEntry */
	if pEntry != 0 {
		if (*T_ht)(unsafe.Pointer(pEntry)).Fcount != 0 {
			v1 = (*T_ht)(unsafe.Pointer(pEntry)).Fchain
		} else {
			v1 = uintptr(0)
		}
		pHead = v1
		(*T_ht)(unsafe.Pointer(pEntry)).Fcount++
		(*T_ht)(unsafe.Pointer(pEntry)).Fchain = pNew
	} else {
		pHead = uintptr(0)
	}
	if pHead != 0 {
		(*THashElem)(unsafe.Pointer(pNew)).Fnext = pHead
		(*THashElem)(unsafe.Pointer(pNew)).Fprev = (*THashElem)(unsafe.Pointer(pHead)).Fprev
		if (*THashElem)(unsafe.Pointer(pHead)).Fprev != 0 {
			(*THashElem)(unsafe.Pointer((*THashElem)(unsafe.Pointer(pHead)).Fprev)).Fnext = pNew
		} else {
			(*THash)(unsafe.Pointer(pH)).Ffirst = pNew
		}
		(*THashElem)(unsafe.Pointer(pHead)).Fprev = pNew
	} else {
		(*THashElem)(unsafe.Pointer(pNew)).Fnext = (*THash)(unsafe.Pointer(pH)).Ffirst
		if (*THash)(unsafe.Pointer(pH)).Ffirst != 0 {
			(*THashElem)(unsafe.Pointer((*THash)(unsafe.Pointer(pH)).Ffirst)).Fprev = pNew
		}
		(*THashElem)(unsafe.Pointer(pNew)).Fprev = uintptr(0)
		(*THash)(unsafe.Pointer(pH)).Ffirst = pNew
	}
}

// C documentation
//
//	/* Resize the hash table so that it contains "new_size" buckets.
//	**
//	** The hash table might fail to resize if sqlite3_malloc() fails or
//	** if the new size is the same as the prior size.
//	** Return TRUE if the resize occurs and false if not.
//	*/
func _rehash(tls *libc.TLS, pH uintptr, new_size uint32) (r int32) {
	var elem, new_ht, next_elem uintptr
	var h, v1 uint32
	_, _, _, _, _ = elem, h, new_ht, next_elem, v1 /* For looping over existing elements */
	if new_size*uint32(8) > uint32(SQLITE_MALLOC_SOFT_LIMIT) {
		new_size = libc.Uint32FromInt32(SQLITE_MALLOC_SOFT_LIMIT) / libc.Uint32FromInt64(8)
	}
	if new_size == (*THash)(unsafe.Pointer(pH)).Fhtsize {
		return 0
	}
	/* The inability to allocates space for a larger hash table is
	 ** a performance hit but it is not a fatal error.  So mark the
	 ** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of
	 ** sqlite3MallocZero() to make the allocation, as sqlite3MallocZero()
	 ** only zeroes the requested number of bytes whereas this module will
	 ** use the actual amount of space allocated for the hash table (which
	 ** may be larger than the requested amount).
	 */
	_sqlite3BeginBenignMalloc(tls)
	new_ht = _sqlite3Malloc(tls, uint64(new_size*uint32(8)))
	_sqlite3EndBenignMalloc(tls)
	if new_ht == uintptr(0) {
		return 0
	}
	Xsqlite3_free(tls, (*THash)(unsafe.Pointer(pH)).Fht)
	(*THash)(unsafe.Pointer(pH)).Fht = new_ht
	v1 = uint32(_sqlite3MallocSize(tls, new_ht)) / libc.Uint32FromInt64(8)
	new_size = v1
	(*THash)(unsafe.Pointer(pH)).Fhtsize = v1
	libc.Xmemset(tls, new_ht, 0, new_size*uint32(8))
	elem = (*THash)(unsafe.Pointer(pH)).Ffirst
	(*THash)(unsafe.Pointer(pH)).Ffirst = libc.UintptrFromInt32(0)
	for {
		if !(elem != 0) {
			break
		}
		h = _strHash(tls, (*THashElem)(unsafe.Pointer(elem)).FpKey) % new_size
		next_elem = (*THashElem)(unsafe.Pointer(elem)).Fnext
		_insertElement(tls, pH, new_ht+uintptr(h)*8, elem)
		goto _2
	_2:
		;
		elem = next_elem
	}
	return int32(1)
}

// C documentation
//
//	/* This function (for internal use only) locates an element in an
//	** hash table that matches the given key.  If no element is found,
//	** a pointer to a static null element with HashElem.data==0 is returned.
//	** If pH is not NULL, then the hash for this key is written to *pH.
//	*/
func _findElementWithHash(tls *libc.TLS, pH uintptr, pKey uintptr, pHash uintptr) (r uintptr) {
	var count, h uint32
	var elem, pEntry uintptr
	_, _, _, _ = count, elem, h, pEntry /* The computed hash */
	if (*THash)(unsafe.Pointer(pH)).Fht != 0 {
		h = _strHash(tls, pKey) % (*THash)(unsafe.Pointer(pH)).Fhtsize
		pEntry = (*THash)(unsafe.Pointer(pH)).Fht + uintptr(h)*8
		elem = (*T_ht)(unsafe.Pointer(pEntry)).Fchain
		count = (*T_ht)(unsafe.Pointer(pEntry)).Fcount
	} else {
		h = uint32(0)
		elem = (*THash)(unsafe.Pointer(pH)).Ffirst
		count = (*THash)(unsafe.Pointer(pH)).Fcount
	}
	if pHash != 0 {
		*(*uint32)(unsafe.Pointer(pHash)) = h
	}
	for count != 0 {
		if _sqlite3StrICmp(tls, (*THashElem)(unsafe.Pointer(elem)).FpKey, pKey) == 0 {
			return elem
		}
		elem = (*THashElem)(unsafe.Pointer(elem)).Fnext
		count--
	}
	return uintptr(unsafe.Pointer(&_nullElement))
}

var _nullElement = THashElem{}

// C documentation
//
//	/* Remove a single entry from the hash table given a pointer to that
//	** element and a hash on the element's key.
//	*/
func _removeElementGivenHash(tls *libc.TLS, pH uintptr, elem uintptr, h uint32) {
	var pEntry uintptr
	_ = pEntry
	if (*THashElem)(unsafe.Pointer(elem)).Fprev != 0 {
		(*THashElem)(unsafe.Pointer((*THashElem)(unsafe.Pointer(elem)).Fprev)).Fnext = (*THashElem)(unsafe.Pointer(elem)).Fnext
	} else {
		(*THash)(unsafe.Pointer(pH)).Ffirst = (*THashElem)(unsafe.Pointer(elem)).Fnext
	}
	if (*THashElem)(unsafe.Pointer(elem)).Fnext != 0 {
		(*THashElem)(unsafe.Pointer((*THashElem)(unsafe.Pointer(elem)).Fnext)).Fprev = (*THashElem)(unsafe.Pointer(elem)).Fprev
	}
	if (*THash)(unsafe.Pointer(pH)).Fht != 0 {
		pEntry = (*THash)(unsafe.Pointer(pH)).Fht + uintptr(h)*8
		if (*T_ht)(unsafe.Pointer(pEntry)).Fchain == elem {
			(*T_ht)(unsafe.Pointer(pEntry)).Fchain = (*THashElem)(unsafe.Pointer(elem)).Fnext
		}
		(*T_ht)(unsafe.Pointer(pEntry)).Fcount--
	}
	Xsqlite3_free(tls, elem)
	(*THash)(unsafe.Pointer(pH)).Fcount--
	if (*THash)(unsafe.Pointer(pH)).Fcount == uint32(0) {
		_sqlite3HashClear(tls, pH)
	}
}

// C documentation
//
//	/* Attempt to locate an element of the hash table pH with a key
//	** that matches pKey.  Return the data for this element if it is
//	** found, or NULL if there is no match.
//	*/
func _sqlite3HashFind(tls *libc.TLS, pH uintptr, pKey uintptr) (r uintptr) {
	return (*THashElem)(unsafe.Pointer(_findElementWithHash(tls, pH, pKey, uintptr(0)))).Fdata
}

// C documentation
//
//	/* Insert an element into the hash table pH.  The key is pKey
//	** and the data is "data".
//	**
//	** If no element exists with a matching key, then a new
//	** element is created and NULL is returned.
//	**
//	** If another element already exists with the same key, then the
//	** new data replaces the old data and the old data is returned.
//	** The key is not copied in this instance.  If a malloc fails, then
//	** the new data is returned and the hash table is unchanged.
//	**
//	** If the "data" parameter to this function is NULL, then the
//	** element corresponding to "key" is removed from the hash table.
//	*/
func _sqlite3HashInsert(tls *libc.TLS, pH uintptr, pKey uintptr, data uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var elem, new_elem, old_data, v1 uintptr
	var _ /* h at bp+0 */ uint32
	_, _, _, _ = elem, new_elem, old_data, v1 /* New element added to the pH */
	elem = _findElementWithHash(tls, pH, pKey, bp)
	if (*THashElem)(unsafe.Pointer(elem)).Fdata != 0 {
		old_data = (*THashElem)(unsafe.Pointer(elem)).Fdata
		if data == uintptr(0) {
			_removeElementGivenHash(tls, pH, elem, *(*uint32)(unsafe.Pointer(bp)))
		} else {
			(*THashElem)(unsafe.Pointer(elem)).Fdata = data
			(*THashElem)(unsafe.Pointer(elem)).FpKey = pKey
		}
		return old_data
	}
	if data == uintptr(0) {
		return uintptr(0)
	}
	new_elem = _sqlite3Malloc(tls, uint64(16))
	if new_elem == uintptr(0) {
		return data
	}
	(*THashElem)(unsafe.Pointer(new_elem)).FpKey = pKey
	(*THashElem)(unsafe.Pointer(new_elem)).Fdata = data
	(*THash)(unsafe.Pointer(pH)).Fcount++
	if (*THash)(unsafe.Pointer(pH)).Fcount >= uint32(10) && (*THash)(unsafe.Pointer(pH)).Fcount > uint32(2)*(*THash)(unsafe.Pointer(pH)).Fhtsize {
		if _rehash(tls, pH, (*THash)(unsafe.Pointer(pH)).Fcount*uint32(2)) != 0 {
			*(*uint32)(unsafe.Pointer(bp)) = _strHash(tls, pKey) % (*THash)(unsafe.Pointer(pH)).Fhtsize
		}
	}
	if (*THash)(unsafe.Pointer(pH)).Fht != 0 {
		v1 = (*THash)(unsafe.Pointer(pH)).Fht + uintptr(*(*uint32)(unsafe.Pointer(bp)))*8
	} else {
		v1 = uintptr(0)
	}
	_insertElement(tls, pH, v1, new_elem)
	return uintptr(0)
}

// C documentation
//
//	/************** End of hash.c ************************************************/
//	/************** Begin file opcodes.c *****************************************/
//	/* Automatically generated.  Do not edit */
//	/* See the tool/mkopcodec.tcl script for details. */
func _sqlite3OpcodeName(tls *libc.TLS, i int32) (r uintptr) {
	return _azName[i]
}

var _azName = [190]uintptr{
	0:   __ccgo_ts + 1856,
	1:   __ccgo_ts + 1866,
	2:   __ccgo_ts + 1877,
	3:   __ccgo_ts + 1889,
	4:   __ccgo_ts + 1900,
	5:   __ccgo_ts + 1912,
	6:   __ccgo_ts + 1919,
	7:   __ccgo_ts + 1927,
	8:   __ccgo_ts + 1935,
	9:   __ccgo_ts + 1940,
	10:  __ccgo_ts + 1945,
	11:  __ccgo_ts + 1951,
	12:  __ccgo_ts + 1965,
	13:  __ccgo_ts + 1971,
	14:  __ccgo_ts + 1981,
	15:  __ccgo_ts + 1986,
	16:  __ccgo_ts + 1991,
	17:  __ccgo_ts + 1994,
	18:  __ccgo_ts + 2000,
	19:  __ccgo_ts + 2007,
	20:  __ccgo_ts + 2011,
	21:  __ccgo_ts + 2021,
	22:  __ccgo_ts + 2028,
	23:  __ccgo_ts + 2035,
	24:  __ccgo_ts + 2042,
	25:  __ccgo_ts + 2049,
	26:  __ccgo_ts + 2059,
	27:  __ccgo_ts + 2068,
	28:  __ccgo_ts + 2079,
	29:  __ccgo_ts + 2088,
	30:  __ccgo_ts + 2094,
	31:  __ccgo_ts + 2104,
	32:  __ccgo_ts + 2114,
	33:  __ccgo_ts + 2119,
	34:  __ccgo_ts + 2133,
	35:  __ccgo_ts + 2144,
	36:  __ccgo_ts + 2149,
	37:  __ccgo_ts + 2156,
	38:  __ccgo_ts + 2167,
	39:  __ccgo_ts + 2172,
	40:  __ccgo_ts + 2177,
	41:  __ccgo_ts + 2183,
	42:  __ccgo_ts + 2189,
	43:  __ccgo_ts + 2195,
	44:  __ccgo_ts + 2198,
	45:  __ccgo_ts + 2202,
	46:  __ccgo_ts + 2208,
	47:  __ccgo_ts + 2219,
	48:  __ccgo_ts + 2230,
	49:  __ccgo_ts + 2238,
	50:  __ccgo_ts + 2247,
	51:  __ccgo_ts + 2254,
	52:  __ccgo_ts + 2262,
	53:  __ccgo_ts + 2265,
	54:  __ccgo_ts + 2268,
	55:  __ccgo_ts + 2271,
	56:  __ccgo_ts + 2274,
	57:  __ccgo_ts + 2277,
	58:  __ccgo_ts + 2280,
	59:  __ccgo_ts + 2287,
	60:  __ccgo_ts + 2293,
	61:  __ccgo_ts + 2303,
	62:  __ccgo_ts + 2316,
	63:  __ccgo_ts + 2327,
	64:  __ccgo_ts + 2333,
	65:  __ccgo_ts + 2340,
	66:  __ccgo_ts + 2349,
	67:  __ccgo_ts + 2358,
	68:  __ccgo_ts + 2365,
	69:  __ccgo_ts + 2378,
	70:  __ccgo_ts + 2389,
	71:  __ccgo_ts + 2394,
	72:  __ccgo_ts + 2402,
	73:  __ccgo_ts + 2408,
	74:  __ccgo_ts + 2415,
	75:  __ccgo_ts + 2427,
	76:  __ccgo_ts + 2432,
	77:  __ccgo_ts + 2441,
	78:  __ccgo_ts + 2446,
	79:  __ccgo_ts + 2455,
	80:  __ccgo_ts + 2460,
	81:  __ccgo_ts + 2465,
	82:  __ccgo_ts + 2471,
	83:  __ccgo_ts + 2479,
	84:  __ccgo_ts + 2487,
	85:  __ccgo_ts + 2497,
	86:  __ccgo_ts + 2505,
	87:  __ccgo_ts + 2512,
	88:  __ccgo_ts + 2525,
	89:  __ccgo_ts + 2530,
	90:  __ccgo_ts + 2542,
	91:  __ccgo_ts + 2550,
	92:  __ccgo_ts + 2557,
	93:  __ccgo_ts + 2568,
	94:  __ccgo_ts + 2575,
	95:  __ccgo_ts + 2582,
	96:  __ccgo_ts + 2592,
	97:  __ccgo_ts + 2601,
	98:  __ccgo_ts + 2612,
	99:  __ccgo_ts + 2618,
	100: __ccgo_ts + 2629,
	101: __ccgo_ts + 2639,
	102: __ccgo_ts + 2649,
	103: __ccgo_ts + 2656,
	104: __ccgo_ts + 2662,
	105: __ccgo_ts + 2672,
	106: __ccgo_ts + 2683,
	107: __ccgo_ts + 2687,
	108: __ccgo_ts + 2696,
	109: __ccgo_ts + 2705,
	110: __ccgo_ts + 2712,
	111: __ccgo_ts + 2722,
	112: __ccgo_ts + 2729,
	113: __ccgo_ts + 2738,
	114: __ccgo_ts + 2748,
	115: __ccgo_ts + 2755,
	116: __ccgo_ts + 2763,
	117: __ccgo_ts + 2777,
	118: __ccgo_ts + 2785,
	119: __ccgo_ts + 2799,
	120: __ccgo_ts + 2810,
	121: __ccgo_ts + 2823,
	122: __ccgo_ts + 2834,
	123: __ccgo_ts + 2840,
	124: __ccgo_ts + 2852,
	125: __ccgo_ts + 2861,
	126: __ccgo_ts + 2869,
	127: __ccgo_ts + 2878,
	128: __ccgo_ts + 2887,
	129: __ccgo_ts + 2894,
	130: __ccgo_ts + 2902,
	131: __ccgo_ts + 2909,
	132: __ccgo_ts + 2920,
	133: __ccgo_ts + 2934,
	134: __ccgo_ts + 2945,
	135: __ccgo_ts + 2953,
	136: __ccgo_ts + 2959,
	137: __ccgo_ts + 2967,
	138: __ccgo_ts + 2975,
	139: __ccgo_ts + 2985,
	140: __ccgo_ts + 2998,
	141: __ccgo_ts + 3008,
	142: __ccgo_ts + 3021,
	143: __ccgo_ts + 3030,
	144: __ccgo_ts + 3041,
	145: __ccgo_ts + 3049,
	146: __ccgo_ts + 3055,
	147: __ccgo_ts + 3067,
	148: __ccgo_ts + 3079,
	149: __ccgo_ts + 3087,
	150: __ccgo_ts + 3099,
	151: __ccgo_ts + 3112,
	152: __ccgo_ts + 3122,
	153: __ccgo_ts + 3132,
	154: __ccgo_ts + 3137,
	155: __ccgo_ts + 3149,
	156: __ccgo_ts + 3161,
	157: __ccgo_ts + 3171,
	158: __ccgo_ts + 3177,
	159: __ccgo_ts + 3187,
	160: __ccgo_ts + 3194,
	161: __ccgo_ts + 3206,
	162: __ccgo_ts + 3217,
	163: __ccgo_ts + 3225,
	164: __ccgo_ts + 3234,
	165: __ccgo_ts + 3243,
	166: __ccgo_ts + 3252,
	167: __ccgo_ts + 3259,
	168: __ccgo_ts + 3270,
	169: __ccgo_ts + 3283,
	170: __ccgo_ts + 3293,
	171: __ccgo_ts + 3300,
	172: __ccgo_ts + 3308,
	173: __ccgo_ts + 3317,
	174: __ccgo_ts + 3323,
	175: __ccgo_ts + 3330,
	176: __ccgo_ts + 3338,
	177: __ccgo_ts + 3346,
	178: __ccgo_ts + 3354,
	179: __ccgo_ts + 3364,
	180: __ccgo_ts + 3373,
	181: __ccgo_ts + 3384,
	182: __ccgo_ts + 3395,
	183: __ccgo_ts + 3406,
	184: __ccgo_ts + 3416,
	185: __ccgo_ts + 3422,
	186: __ccgo_ts + 3433,
	187: __ccgo_ts + 3444,
	188: __ccgo_ts + 3449,
	189: __ccgo_ts + 3457,
}

/************** End of opcodes.c *********************************************/
/************** Begin file os_kv.c *******************************************/
/*
** 2022-09-06
**
** 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 an experimental VFS layer that operates on a
** Key/Value storage engine where both keys and values must be pure
** text.
 */
/* #include <sqliteInt.h> */

/************** End of os_kv.c ***********************************************/
/************** Begin file os_unix.c *****************************************/
/*
** 2004 May 22
**
** 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 VFS implementation for unix-like operating systems
** include Linux, MacOSX, *BSD, QNX, VxWorks, AIX, HPUX, and others.
**
** There are actually several different VFS implementations in this file.
** The differences are in the way that file locking is done.  The default
** implementation uses Posix Advisory Locks.  Alternative implementations
** use flock(), dot-files, various proprietary locking schemas, or simply
** skip locking all together.
**
** This source file is organized into divisions where the logic for various
** subfunctions is contained within the appropriate division.  PLEASE
** KEEP THE STRUCTURE OF THIS FILE INTACT.  New code should be placed
** in the correct division and should be clearly labelled.
**
** The layout of divisions is as follows:
**
**   *  General-purpose declarations and utility functions.
**   *  Unique file ID logic used by VxWorks.
**   *  Various locking primitive implementations (all except proxy locking):
**      + for Posix Advisory Locks
**      + for no-op locks
**      + for dot-file locks
**      + for flock() locking
**      + for named semaphore locks (VxWorks only)
**      + for AFP filesystem locks (MacOSX only)
**   *  sqlite3_file methods not associated with locking.
**   *  Definitions of sqlite3_io_methods objects for all locking
**      methods plus "finder" functions for each locking method.
**   *  sqlite3_vfs method implementations.
**   *  Locking primitives for the proxy uber-locking-method. (MacOSX only)
**   *  Definitions of sqlite3_vfs objects for all locking methods
**      plus implementations of sqlite3_os_init() and sqlite3_os_end().
 */
/* #include "sqliteInt.h" */

/************** End of os_unix.c *********************************************/
/************** Begin file os_win.c ******************************************/
/*
** 2004 May 22
**
** 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 that is specific to Windows.
 */
/* #include "sqliteInt.h" */

/*
** Include code that is common to all os_*.c files
 */
/* #include "os_common.h" */

/*
** Include the header file for the Windows VFS.
 */
/* #include "os_win.h" */

/*
** Compiling and using WAL mode requires several APIs that are only
** available in Windows platforms based on the NT kernel.
 */

/*
** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
** based on the sub-platform)?
 */

/*
** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
** based on the sub-platform)?
 */

/*
** Make sure at least one set of Win32 APIs is available.
 */

/*
** Define the required Windows SDK version constants if they are not
** already available.
 */

/*
** Check to see if the GetVersionEx[AW] functions are deprecated on the
** target system.  GetVersionEx was first deprecated in Win8.1.
 */

/*
** Check to see if the CreateFileMappingA function is supported on the
** target system.  It is unavailable when using "mincore.lib" on Win10.
** When compiling for Windows 10, always assume "mincore.lib" is in use.
 */

/*
** This constant should already be defined (in the "WinDef.h" SDK file).
 */

/*
** Maximum pathname length (in chars) for Win32.  This should normally be
** MAX_PATH.
 */

/*
** This constant should already be defined (in the "WinNT.h" SDK file).
 */

/*
** Maximum pathname length (in chars) for WinNT.  This should normally be
** UNICODE_STRING_MAX_CHARS.
 */

/*
** Maximum pathname length (in bytes) for Win32.  The MAX_PATH macro is in
** characters, so we allocate 4 bytes per character assuming worst-case of
** 4-bytes-per-character for UTF8.
 */

/*
** Maximum pathname length (in bytes) for WinNT.  This should normally be
** UNICODE_STRING_MAX_CHARS * sizeof(WCHAR).
 */

/*
** Maximum error message length (in chars) for WinRT.
 */

/*
** Returns non-zero if the character should be treated as a directory
** separator.
 */

/*
** This macro is used when a local variable is set to a value that is
** [sometimes] not used by the code (e.g. via conditional compilation).
 */

/*
** Returns the character that should be used as the directory separator.
 */

/*
** Do we need to manually define the Win32 file mapping APIs for use with WAL
** mode or memory mapped files (e.g. these APIs are available in the Windows
** CE SDK; however, they are not present in the header file)?
 */

/*
** Some Microsoft compilers lack this definition.
 */

// C documentation
//
//	/* Forward references to structures used for WAL */
type TwinShm = struct {
	FpShmNode   uintptr
	FpNext      uintptr
	FhasMutex   Tu8
	FsharedMask Tu16
	FexclMask   Tu16
}

type winShm = TwinShm

/* A connection to shared-memory */
type TwinShmNode = struct {
	F__ccgo_align [0]uint32
	Fmutex        uintptr
	FzFilename    uintptr
	FhFile        TwinFile
	FszRegion     int32
	FnRegion      int32
	FisReadonly   Tu8
	FisUnlocked   Tu8
	FaRegion      uintptr
	FlastErrno    TDWORD
	FnRef         int32
	FpFirst       uintptr
	FpNext        uintptr
}

type winShmNode = TwinShmNode

/* A region of shared-memory */

/*
** WinCE lacks native support for file locking so we have to fake it
** with some code of our own.
 */

// C documentation
//
//	/*
//	** The winFile structure is a subclass of sqlite3_file* specific to the win32
//	** portability layer.
//	*/
type TwinFile = struct {
	F__ccgo_align   [0]uint32
	FpMethod        uintptr
	FpVfs           uintptr
	Fh              THANDLE
	Flocktype       Tu8
	FsharedLockByte int16
	FctrlFlags      Tu8
	FlastErrno      TDWORD
	FpShm           uintptr
	FzPath          uintptr
	FszChunk        int32
	FnFetchOut      int32
	FhMap           THANDLE
	FpMapRegion     uintptr
	FmmapSize       Tsqlite3_int64
	FmmapSizeMax    Tsqlite3_int64
}

type winFile = TwinFile

type TwinFile1 = struct {
	F__ccgo_align   [0]uint32
	FpMethod        uintptr
	FpVfs           uintptr
	Fh              THANDLE
	Flocktype       Tu8
	FsharedLockByte int16
	FctrlFlags      Tu8
	FlastErrno      TDWORD
	FpShm           uintptr
	FzPath          uintptr
	FszChunk        int32
	FnFetchOut      int32
	FhMap           THANDLE
	FpMapRegion     uintptr
	FmmapSize       Tsqlite3_int64
	FmmapSizeMax    Tsqlite3_int64
}

type winFile1 = TwinFile1

// C documentation
//
//	/*
//	** The winVfsAppData structure is used for the pAppData member for all of the
//	** Win32 VFS variants.
//	*/
type TwinVfsAppData = struct {
	FpMethod  uintptr
	FpAppData uintptr
	FbNoLock  TBOOL
}

type winVfsAppData = TwinVfsAppData

type TwinVfsAppData1 = struct {
	FpMethod  uintptr
	FpAppData uintptr
	FbNoLock  TBOOL
}

type winVfsAppData1 = TwinVfsAppData1

/*
** Allowed values for winFile.ctrlFlags
 */

/*
 * The size of the buffer used by sqlite3_win32_write_debug().
 */

/*
 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
 * various Win32 API heap functions instead of our own.
 */

// C documentation
//
//	/*
//	** The following variable is (normally) set once and never changes
//	** thereafter.  It records whether the operating system is Win9x
//	** or WinNT.
//	**
//	** 0:   Operating system unknown.
//	** 1:   Operating system is Win9x.
//	** 2:   Operating system is WinNT.
//	**
//	** In order to facilitate testing on a WinNT system, the test fixture
//	** can manually set this value to 1 to emulate Win98 behavior.
//	*/
var _sqlite3_os_type = int32(0)

/*
** This function is not available on Windows CE or WinRT.
 */

// C documentation
//
//	/*
//	** Many system calls are accessed through pointer-to-functions so that
//	** they may be overridden at runtime to facilitate fault injection during
//	** testing and sandboxing.  The following array holds the names and pointers
//	** to all overrideable system calls.
//	*/
type Twin_syscall = struct {
	FzName    uintptr
	FpCurrent Tsqlite3_syscall_ptr
	FpDefault Tsqlite3_syscall_ptr
}

type win_syscall = Twin_syscall

/*
** This function is not available on Windows CE or WinRT.
 */

// C documentation
//
//	/*
//	** Many system calls are accessed through pointer-to-functions so that
//	** they may be overridden at runtime to facilitate fault injection during
//	** testing and sandboxing.  The following array holds the names and pointers
//	** to all overrideable system calls.
//	*/
var _aSyscall = [80]Twin_syscall{
	0: {
		FzName: __ccgo_ts + 3467,
	},
	1: {
		FzName: __ccgo_ts + 3483,
	},
	2: {
		FzName: __ccgo_ts + 3494,
	},
	3: {
		FzName: __ccgo_ts + 3505,
	},
	4: {
		FzName: __ccgo_ts + 3517,
	},
	5: {
		FzName: __ccgo_ts + 3529,
	},
	6: {
		FzName: __ccgo_ts + 3541,
	},
	7: {
		FzName: __ccgo_ts + 3560,
	},
	8: {
		FzName: __ccgo_ts + 3579,
	},
	9: {
		FzName: __ccgo_ts + 3592,
	},
	10: {
		FzName: __ccgo_ts + 3604,
	},
	11: {
		FzName: __ccgo_ts + 3616,
	},
	12: {
		FzName: __ccgo_ts + 3640,
	},
	13: {
		FzName: __ccgo_ts + 3661,
	},
	14: {
		FzName: __ccgo_ts + 3678,
	},
	15: {
		FzName: __ccgo_ts + 3693,
	},
	16: {
		FzName: __ccgo_ts + 3708,
	},
	17: {
		FzName: __ccgo_ts + 3720,
	},
	18: {
		FzName: __ccgo_ts + 3740,
	},
	19: {
		FzName: __ccgo_ts + 3758,
	},
	20: {
		FzName: __ccgo_ts + 3776,
	},
	21: {
		FzName: __ccgo_ts + 3795,
	},
	22: {
		FzName: __ccgo_ts + 3814,
	},
	23: {
		FzName: __ccgo_ts + 3835,
	},
	24: {
		FzName: __ccgo_ts + 3847,
	},
	25: {
		FzName: __ccgo_ts + 3864,
	},
	26: {
		FzName: __ccgo_ts + 3881,
	},
	27: {
		FzName: __ccgo_ts + 3894,
	},
	28: {
		FzName: __ccgo_ts + 3910,
	},
	29: {
		FzName: __ccgo_ts + 3924,
	},
	30: {
		FzName: __ccgo_ts + 3938,
	},
	31: {
		FzName: __ccgo_ts + 3962,
	},
	32: {
		FzName: __ccgo_ts + 3975,
	},
	33: {
		FzName: __ccgo_ts + 3988,
	},
	34: {
		FzName: __ccgo_ts + 4001,
	},
	35: {
		FzName: __ccgo_ts + 4015,
	},
	36: {
		FzName: __ccgo_ts + 4029,
	},
	37: {
		FzName: __ccgo_ts + 4039,
	},
	38: {
		FzName: __ccgo_ts + 4050,
	},
	39: {
		FzName: __ccgo_ts + 4062,
	},
	40: {
		FzName: __ccgo_ts + 4071,
	},
	41: {
		FzName: __ccgo_ts + 4083,
	},
	42: {
		FzName: __ccgo_ts + 4092,
	},
	43: {
		FzName: __ccgo_ts + 4105,
	},
	44: {
		FzName: __ccgo_ts + 4117,
	},
	45: {
		FzName: __ccgo_ts + 4130,
	},
	46: {
		FzName: __ccgo_ts + 4143,
	},
	47: {
		FzName: __ccgo_ts + 4153,
	},
	48: {
		FzName: __ccgo_ts + 4162,
	},
	49: {
		FzName: __ccgo_ts + 4173,
	},
	50: {
		FzName: __ccgo_ts + 4187,
	},
	51: {
		FzName: __ccgo_ts + 4207,
	},
	52: {
		FzName: __ccgo_ts + 4231,
	},
	53: {
		FzName: __ccgo_ts + 4240,
	},
	54: {
		FzName: __ccgo_ts + 4253,
	},
	55: {
		FzName: __ccgo_ts + 4268,
	},
	56: {
		FzName: __ccgo_ts + 4274,
	},
	57: {
		FzName: __ccgo_ts + 4295,
	},
	58: {
		FzName: __ccgo_ts + 4306,
	},
	59: {
		FzName: __ccgo_ts + 4319,
	},
	60: {
		FzName: __ccgo_ts + 4335,
	},
	61: {
		FzName: __ccgo_ts + 4355,
	},
	62: {
		FzName: __ccgo_ts + 4365,
	},
	63: {
		FzName: __ccgo_ts + 4380,
	},
	64: {
		FzName: __ccgo_ts + 4400,
	},
	65: {
		FzName: __ccgo_ts + 4422,
	},
	66: {
		FzName: __ccgo_ts + 4439,
	},
	67: {
		FzName: __ccgo_ts + 4468,
	},
	68: {
		FzName: __ccgo_ts + 4489,
	},
	69: {
		FzName: __ccgo_ts + 4501,
	},
	70: {
		FzName: __ccgo_ts + 4521,
	},
	71: {
		FzName: __ccgo_ts + 4536,
	},
	72: {
		FzName: __ccgo_ts + 4556,
	},
	73: {
		FzName: __ccgo_ts + 4575,
	},
	74: {
		FzName: __ccgo_ts + 4594,
	},
	75: {
		FzName: __ccgo_ts + 4609,
	},
	76: {
		FzName: __ccgo_ts + 4634,
	},
	77: {
		FzName: __ccgo_ts + 4661,
	},
	78: {
		FzName: __ccgo_ts + 4672,
	},
	79: {
		FzName: __ccgo_ts + 4693,
	},
}

func init() {
	p := unsafe.Pointer(&_aSyscall)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(libc.XAreFileApisANSI)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(libc.XCloseHandle)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(libc.XCreateFileA)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(libc.XCreateFileW)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(libc.XCreateFileMappingW)
	*(*uintptr)(unsafe.Add(p, 100)) = __ccgo_fp(libc.XCreateMutexW)
	*(*uintptr)(unsafe.Add(p, 112)) = __ccgo_fp(libc.XDeleteFileA)
	*(*uintptr)(unsafe.Add(p, 124)) = __ccgo_fp(libc.XDeleteFileW)
	*(*uintptr)(unsafe.Add(p, 160)) = __ccgo_fp(libc.XFlushFileBuffers)
	*(*uintptr)(unsafe.Add(p, 172)) = __ccgo_fp(libc.XFormatMessageA)
	*(*uintptr)(unsafe.Add(p, 184)) = __ccgo_fp(libc.XFormatMessageW)
	*(*uintptr)(unsafe.Add(p, 196)) = __ccgo_fp(libc.XFreeLibrary)
	*(*uintptr)(unsafe.Add(p, 208)) = __ccgo_fp(libc.XGetCurrentProcessId)
	*(*uintptr)(unsafe.Add(p, 220)) = __ccgo_fp(libc.XGetDiskFreeSpaceA)
	*(*uintptr)(unsafe.Add(p, 232)) = __ccgo_fp(libc.XGetDiskFreeSpaceW)
	*(*uintptr)(unsafe.Add(p, 244)) = __ccgo_fp(libc.XGetFileAttributesA)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(libc.XGetFileAttributesW)
	*(*uintptr)(unsafe.Add(p, 268)) = __ccgo_fp(libc.XGetFileAttributesExW)
	*(*uintptr)(unsafe.Add(p, 280)) = __ccgo_fp(libc.XGetFileSize)
	*(*uintptr)(unsafe.Add(p, 292)) = __ccgo_fp(libc.XGetFullPathNameA)
	*(*uintptr)(unsafe.Add(p, 304)) = __ccgo_fp(libc.XGetFullPathNameW)
	*(*uintptr)(unsafe.Add(p, 316)) = __ccgo_fp(libc.XGetLastError)
	*(*uintptr)(unsafe.Add(p, 328)) = __ccgo_fp(libc.XGetProcAddress)
	*(*uintptr)(unsafe.Add(p, 340)) = __ccgo_fp(libc.XGetSystemInfo)
	*(*uintptr)(unsafe.Add(p, 352)) = __ccgo_fp(libc.XGetSystemTime)
	*(*uintptr)(unsafe.Add(p, 364)) = __ccgo_fp(libc.XGetSystemTimeAsFileTime)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(libc.XGetTempPathA)
	*(*uintptr)(unsafe.Add(p, 388)) = __ccgo_fp(libc.XGetTempPathW)
	*(*uintptr)(unsafe.Add(p, 400)) = __ccgo_fp(libc.XGetTickCount)
	*(*uintptr)(unsafe.Add(p, 436)) = __ccgo_fp(libc.XHeapAlloc)
	*(*uintptr)(unsafe.Add(p, 448)) = __ccgo_fp(libc.XHeapCreate)
	*(*uintptr)(unsafe.Add(p, 460)) = __ccgo_fp(libc.XHeapDestroy)
	*(*uintptr)(unsafe.Add(p, 472)) = __ccgo_fp(libc.XHeapFree)
	*(*uintptr)(unsafe.Add(p, 484)) = __ccgo_fp(libc.XHeapReAlloc)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(libc.XHeapSize)
	*(*uintptr)(unsafe.Add(p, 508)) = __ccgo_fp(libc.XHeapValidate)
	*(*uintptr)(unsafe.Add(p, 520)) = __ccgo_fp(libc.XHeapCompact)
	*(*uintptr)(unsafe.Add(p, 532)) = __ccgo_fp(libc.XLoadLibraryA)
	*(*uintptr)(unsafe.Add(p, 544)) = __ccgo_fp(libc.XLoadLibraryW)
	*(*uintptr)(unsafe.Add(p, 556)) = __ccgo_fp(libc.XLocalFree)
	*(*uintptr)(unsafe.Add(p, 568)) = __ccgo_fp(libc.XLockFile)
	*(*uintptr)(unsafe.Add(p, 580)) = __ccgo_fp(libc.XLockFileEx)
	*(*uintptr)(unsafe.Add(p, 592)) = __ccgo_fp(libc.XMapViewOfFile)
	*(*uintptr)(unsafe.Add(p, 604)) = __ccgo_fp(libc.XMultiByteToWideChar)
	*(*uintptr)(unsafe.Add(p, 616)) = __ccgo_fp(libc.XQueryPerformanceCounter)
	*(*uintptr)(unsafe.Add(p, 628)) = __ccgo_fp(libc.XReadFile)
	*(*uintptr)(unsafe.Add(p, 640)) = __ccgo_fp(libc.XSetEndOfFile)
	*(*uintptr)(unsafe.Add(p, 652)) = __ccgo_fp(libc.XSetFilePointer)
	*(*uintptr)(unsafe.Add(p, 664)) = __ccgo_fp(libc.XSleep)
	*(*uintptr)(unsafe.Add(p, 676)) = __ccgo_fp(libc.XSystemTimeToFileTime)
	*(*uintptr)(unsafe.Add(p, 688)) = __ccgo_fp(libc.XUnlockFile)
	*(*uintptr)(unsafe.Add(p, 700)) = __ccgo_fp(libc.XUnlockFileEx)
	*(*uintptr)(unsafe.Add(p, 712)) = __ccgo_fp(libc.XUnmapViewOfFile)
	*(*uintptr)(unsafe.Add(p, 724)) = __ccgo_fp(libc.XWideCharToMultiByte)
	*(*uintptr)(unsafe.Add(p, 736)) = __ccgo_fp(libc.XWriteFile)
	*(*uintptr)(unsafe.Add(p, 760)) = __ccgo_fp(libc.XWaitForSingleObject)
	*(*uintptr)(unsafe.Add(p, 772)) = __ccgo_fp(libc.XWaitForSingleObjectEx)
	*(*uintptr)(unsafe.Add(p, 868)) = __ccgo_fp(libc.XOutputDebugStringA)
	*(*uintptr)(unsafe.Add(p, 880)) = __ccgo_fp(libc.XOutputDebugStringW)
	*(*uintptr)(unsafe.Add(p, 892)) = __ccgo_fp(libc.XGetProcessHeap)
	*(*uintptr)(unsafe.Add(p, 952)) = __ccgo_fp(libc.XFlushViewOfFile)
}

/* End of the overrideable system calls */

// C documentation
//
//	/*
//	** This is the xSetSystemCall() method of sqlite3_vfs for all of the
//	** "win32" VFSes.  Return SQLITE_OK upon successfully updating the
//	** system call pointer, or SQLITE_NOTFOUND if there is no configurable
//	** system call named zName.
//	*/
func _winSetSystemCall(tls *libc.TLS, pNotUsed uintptr, zName uintptr, pNewFunc Tsqlite3_syscall_ptr) (r int32) {
	var i uint32
	var rc int32
	_, _ = i, rc
	rc = int32(SQLITE_NOTFOUND)
	_ = pNotUsed
	if zName == uintptr(0) {
		/* If no zName is given, restore all system calls to their default
		 ** settings and return NULL
		 */
		rc = SQLITE_OK
		i = uint32(0)
		for {
			if !(i < libc.Uint32FromInt64(960)/libc.Uint32FromInt64(12)) {
				break
			}
			if _aSyscall[i].FpDefault != 0 {
				_aSyscall[i].FpCurrent = _aSyscall[i].FpDefault
			}
			goto _1
		_1:
			;
			i++
		}
	} else {
		/* If zName is specified, operate on only the one system call
		 ** specified.
		 */
		i = uint32(0)
		for {
			if !(i < libc.Uint32FromInt64(960)/libc.Uint32FromInt64(12)) {
				break
			}
			if libc.Xstrcmp(tls, zName, _aSyscall[i].FzName) == 0 {
				if _aSyscall[i].FpDefault == uintptr(0) {
					_aSyscall[i].FpDefault = _aSyscall[i].FpCurrent
				}
				rc = SQLITE_OK
				if pNewFunc == uintptr(0) {
					pNewFunc = _aSyscall[i].FpDefault
				}
				_aSyscall[i].FpCurrent = pNewFunc
				break
			}
			goto _2
		_2:
			;
			i++
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the value of a system call.  Return NULL if zName is not a
//	** recognized system call name.  NULL is also returned if the system call
//	** is currently undefined.
//	*/
func _winGetSystemCall(tls *libc.TLS, pNotUsed uintptr, zName uintptr) (r Tsqlite3_syscall_ptr) {
	var i uint32
	_ = i
	_ = pNotUsed
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(960)/libc.Uint32FromInt64(12)) {
			break
		}
		if libc.Xstrcmp(tls, zName, _aSyscall[i].FzName) == 0 {
			return _aSyscall[i].FpCurrent
		}
		goto _1
	_1:
		;
		i++
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Return the name of the first system call after zName.  If zName==NULL
//	** then return the name of the first system call.  Return NULL if zName
//	** is the last system call or if zName is not the name of a valid
//	** system call.
//	*/
func _winNextSystemCall(tls *libc.TLS, p uintptr, zName uintptr) (r uintptr) {
	var i int32
	_ = i
	i = -int32(1)
	_ = p
	if zName != 0 {
		i = 0
		for {
			if !(i < int32(libc.Uint32FromInt64(960)/libc.Uint32FromInt64(12))-libc.Int32FromInt32(1)) {
				break
			}
			if libc.Xstrcmp(tls, zName, _aSyscall[i].FzName) == 0 {
				break
			}
			goto _1
		_1:
			;
			i++
		}
	}
	i++
	for {
		if !(i < int32(libc.Uint32FromInt64(960)/libc.Uint32FromInt64(12))) {
			break
		}
		if _aSyscall[i].FpCurrent != uintptr(0) {
			return _aSyscall[i].FzName
		}
		goto _2
	_2:
		;
		i++
	}
	return uintptr(0)
}

/*
** This function outputs the specified (ANSI) string to the Win32 debugger
** (if available).
 */
func Xsqlite3_win32_write_debug(tls *libc.TLS, zBuf uintptr, nBuf int32) {
	bp := tls.Alloc(4096)
	defer tls.Free(4096)
	var nMin, v1 int32
	var _ /* zDbgBuf at bp+0 */ [4092]int8
	_, _ = nMin, v1
	if nBuf < int32(libc.Uint32FromInt32(4096)-libc.Uint32FromInt64(4))-libc.Int32FromInt32(1) {
		v1 = nBuf
	} else {
		v1 = int32(libc.Uint32FromInt32(4096)-libc.Uint32FromInt64(4)) - libc.Int32FromInt32(1)
	}
	nMin = v1 /* may be negative. */
	if nMin < -int32(1) {
		nMin = -int32(1)
	} /* all negative values become -1. */
	if nMin > 0 {
		libc.Xmemset(tls, bp, 0, uint32(int32(libc.Uint32FromInt32(4096)-libc.Uint32FromInt64(4))))
		libc.Xmemcpy(tls, bp, zBuf, uint32(uint32(nMin)))
		(*(*func(*libc.TLS, TLPCSTR))(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(72)].FpCurrent})))(tls, bp)
	} else {
		(*(*func(*libc.TLS, TLPCSTR))(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(72)].FpCurrent})))(tls, zBuf)
	}
}

/*
** The following routine suspends the current thread for at least ms
** milliseconds.  This is equivalent to the Win32 Sleep() interface.
 */
func Xsqlite3_win32_sleep(tls *libc.TLS, milliseconds TDWORD) {
	(*(*func(*libc.TLS, TDWORD))(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(55)].FpCurrent})))(tls, milliseconds)
}

func _sqlite3Win32Wait(tls *libc.TLS, hObject THANDLE) (r TDWORD) {
	var rc, v1 TDWORD
	_, _ = rc, v1
	for {
		v1 = (*(*func(*libc.TLS, THANDLE, TDWORD, TBOOL) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(64)].FpCurrent})))(tls, hObject, uint32(INFINITE), int32(TRUE))
		rc = v1
		if !(v1 == libc.Uint32FromInt32(0x000000C0)) {
			break
		}
	}
	return rc
}

/*
** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
** or WinCE.  Return false (zero) for Win95, Win98, or WinME.
**
** Here is an interesting observation:  Win95, Win98, and WinME lack
** the LockFileEx() API.  But we can still statically link against that
** API as long as we don't call it when running Win95/98/ME.  A call to
** this routine is used to determine if the host is Win95/98/ME or
** WinNT/2K/XP so that we will know whether or not we can safely call
** the LockFileEx() API.
 */

// C documentation
//
//	/*
//	** This function determines if the machine is running a version of Windows
//	** based on the NT kernel.
//	*/
func Xsqlite3_win32_is_nt(tls *libc.TLS) (r int32) {
	/*
	 ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
	 **       deprecated are always assumed to be based on the NT kernel.
	 */
	return int32(1)
}

// C documentation
//
//	/*
//	** Convert a UTF-8 string to Microsoft Unicode.
//	**
//	** Space to hold the returned string is obtained from sqlite3_malloc().
//	*/
func _winUtf8ToUnicode(tls *libc.TLS, zText uintptr) (r TLPWSTR) {
	var nChar int32
	var zWideText TLPWSTR
	_, _ = nChar, zWideText
	nChar = (*(*func(*libc.TLS, TUINT, TDWORD, TLPCSTR, int32, TLPWSTR, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(50)].FpCurrent})))(tls, uint32(CP_UTF8), uint32(0), zText, -int32(1), libc.UintptrFromInt32(0), 0)
	if nChar == 0 {
		return uintptr(0)
	}
	zWideText = _sqlite3MallocZero(tls, uint64(uint32(uint32(nChar))*uint32(2)))
	if zWideText == uintptr(0) {
		return uintptr(0)
	}
	nChar = (*(*func(*libc.TLS, TUINT, TDWORD, TLPCSTR, int32, TLPWSTR, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(50)].FpCurrent})))(tls, uint32(CP_UTF8), uint32(0), zText, -int32(1), zWideText, nChar)
	if nChar == 0 {
		Xsqlite3_free(tls, zWideText)
		zWideText = uintptr(0)
	}
	return zWideText
}

// C documentation
//
//	/*
//	** Convert a Microsoft Unicode string to UTF-8.
//	**
//	** Space to hold the returned string is obtained from sqlite3_malloc().
//	*/
func _winUnicodeToUtf8(tls *libc.TLS, zWideText TLPCWSTR) (r uintptr) {
	var nByte int32
	var zText uintptr
	_, _ = nByte, zText
	nByte = (*(*func(*libc.TLS, TUINT, TDWORD, TLPCWSTR, int32, TLPSTR, int32, TLPCSTR, TLPBOOL) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(60)].FpCurrent})))(tls, uint32(CP_UTF8), uint32(0), zWideText, -int32(1), uintptr(0), 0, uintptr(0), uintptr(0))
	if nByte == 0 {
		return uintptr(0)
	}
	zText = _sqlite3MallocZero(tls, uint64(uint64(nByte)))
	if zText == uintptr(0) {
		return uintptr(0)
	}
	nByte = (*(*func(*libc.TLS, TUINT, TDWORD, TLPCWSTR, int32, TLPSTR, int32, TLPCSTR, TLPBOOL) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(60)].FpCurrent})))(tls, uint32(CP_UTF8), uint32(0), zWideText, -int32(1), zText, nByte, uintptr(0), uintptr(0))
	if nByte == 0 {
		Xsqlite3_free(tls, zText)
		zText = uintptr(0)
	}
	return zText
}

// C documentation
//
//	/*
//	** Convert an ANSI string to Microsoft Unicode, using the ANSI or OEM
//	** code page.
//	**
//	** Space to hold the returned string is obtained from sqlite3_malloc().
//	*/
func _winMbcsToUnicode(tls *libc.TLS, zText uintptr, useAnsi int32) (r TLPWSTR) {
	var codepage, nByte, v1 int32
	var zMbcsText TLPWSTR
	_, _, _, _ = codepage, nByte, zMbcsText, v1
	if useAnsi != 0 {
		v1 = CP_ACP
	} else {
		v1 = int32(CP_OEMCP)
	}
	codepage = v1
	nByte = int32(uint32((*(*func(*libc.TLS, TUINT, TDWORD, TLPCSTR, int32, TLPWSTR, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(50)].FpCurrent})))(tls, uint32(uint32(codepage)), uint32(0), zText, -int32(1), libc.UintptrFromInt32(0), 0)) * uint32(2))
	if nByte == 0 {
		return uintptr(0)
	}
	zMbcsText = _sqlite3MallocZero(tls, uint64(uint32(uint32(nByte))*uint32(2)))
	if zMbcsText == uintptr(0) {
		return uintptr(0)
	}
	nByte = (*(*func(*libc.TLS, TUINT, TDWORD, TLPCSTR, int32, TLPWSTR, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(50)].FpCurrent})))(tls, uint32(uint32(codepage)), uint32(0), zText, -int32(1), zMbcsText, nByte)
	if nByte == 0 {
		Xsqlite3_free(tls, zMbcsText)
		zMbcsText = uintptr(0)
	}
	return zMbcsText
}

// C documentation
//
//	/*
//	** Convert a Microsoft Unicode string to a multi-byte character string,
//	** using the ANSI or OEM code page.
//	**
//	** Space to hold the returned string is obtained from sqlite3_malloc().
//	*/
func _winUnicodeToMbcs(tls *libc.TLS, zWideText TLPCWSTR, useAnsi int32) (r uintptr) {
	var codepage, nByte, v1 int32
	var zText uintptr
	_, _, _, _ = codepage, nByte, zText, v1
	if useAnsi != 0 {
		v1 = CP_ACP
	} else {
		v1 = int32(CP_OEMCP)
	}
	codepage = v1
	nByte = (*(*func(*libc.TLS, TUINT, TDWORD, TLPCWSTR, int32, TLPSTR, int32, TLPCSTR, TLPBOOL) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(60)].FpCurrent})))(tls, uint32(uint32(codepage)), uint32(0), zWideText, -int32(1), uintptr(0), 0, uintptr(0), uintptr(0))
	if nByte == 0 {
		return uintptr(0)
	}
	zText = _sqlite3MallocZero(tls, uint64(uint64(nByte)))
	if zText == uintptr(0) {
		return uintptr(0)
	}
	nByte = (*(*func(*libc.TLS, TUINT, TDWORD, TLPCWSTR, int32, TLPSTR, int32, TLPCSTR, TLPBOOL) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(60)].FpCurrent})))(tls, uint32(uint32(codepage)), uint32(0), zWideText, -int32(1), zText, nByte, uintptr(0), uintptr(0))
	if nByte == 0 {
		Xsqlite3_free(tls, zText)
		zText = uintptr(0)
	}
	return zText
}

// C documentation
//
//	/*
//	** Convert a multi-byte character string to UTF-8.
//	**
//	** Space to hold the returned string is obtained from sqlite3_malloc().
//	*/
func _winMbcsToUtf8(tls *libc.TLS, zText uintptr, useAnsi int32) (r uintptr) {
	var zTextUtf8 uintptr
	var zTmpWide TLPWSTR
	_, _ = zTextUtf8, zTmpWide
	zTmpWide = _winMbcsToUnicode(tls, zText, useAnsi)
	if zTmpWide == uintptr(0) {
		return uintptr(0)
	}
	zTextUtf8 = _winUnicodeToUtf8(tls, zTmpWide)
	Xsqlite3_free(tls, zTmpWide)
	return zTextUtf8
}

// C documentation
//
//	/*
//	** Convert a UTF-8 string to a multi-byte character string.
//	**
//	** Space to hold the returned string is obtained from sqlite3_malloc().
//	*/
func _winUtf8ToMbcs(tls *libc.TLS, zText uintptr, useAnsi int32) (r uintptr) {
	var zTextMbcs uintptr
	var zTmpWide TLPWSTR
	_, _ = zTextMbcs, zTmpWide
	zTmpWide = _winUtf8ToUnicode(tls, zText)
	if zTmpWide == uintptr(0) {
		return uintptr(0)
	}
	zTextMbcs = _winUnicodeToMbcs(tls, zTmpWide, useAnsi)
	Xsqlite3_free(tls, zTmpWide)
	return zTextMbcs
}

// C documentation
//
//	/*
//	** This is a public wrapper for the winUtf8ToUnicode() function.
//	*/
func Xsqlite3_win32_utf8_to_unicode(tls *libc.TLS, zText uintptr) (r TLPWSTR) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _winUtf8ToUnicode(tls, zText)
}

// C documentation
//
//	/*
//	** This is a public wrapper for the winUnicodeToUtf8() function.
//	*/
func Xsqlite3_win32_unicode_to_utf8(tls *libc.TLS, zWideText TLPCWSTR) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _winUnicodeToUtf8(tls, zWideText)
}

// C documentation
//
//	/*
//	** This is a public wrapper for the winMbcsToUtf8() function.
//	*/
func Xsqlite3_win32_mbcs_to_utf8(tls *libc.TLS, zText uintptr) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _winMbcsToUtf8(tls, zText, (*(*func(*libc.TLS) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls))
}

// C documentation
//
//	/*
//	** This is a public wrapper for the winMbcsToUtf8() function.
//	*/
func Xsqlite3_win32_mbcs_to_utf8_v2(tls *libc.TLS, zText uintptr, useAnsi int32) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _winMbcsToUtf8(tls, zText, useAnsi)
}

// C documentation
//
//	/*
//	** This is a public wrapper for the winUtf8ToMbcs() function.
//	*/
func Xsqlite3_win32_utf8_to_mbcs(tls *libc.TLS, zText uintptr) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _winUtf8ToMbcs(tls, zText, (*(*func(*libc.TLS) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls))
}

// C documentation
//
//	/*
//	** This is a public wrapper for the winUtf8ToMbcs() function.
//	*/
func Xsqlite3_win32_utf8_to_mbcs_v2(tls *libc.TLS, zText uintptr, useAnsi int32) (r uintptr) {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return _winUtf8ToMbcs(tls, zText, useAnsi)
}

// C documentation
//
//	/*
//	** This function is the same as sqlite3_win32_set_directory (below); however,
//	** it accepts a UTF-8 string.
//	*/
func Xsqlite3_win32_set_directory8(tls *libc.TLS, type1 uint32, zValue uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var ppDirectory, zCopy uintptr
	var rc int32
	_, _, _ = ppDirectory, rc, zCopy
	ppDirectory = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	Xsqlite3_mutex_enter(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
	if type1 == uint32(SQLITE_WIN32_DATA_DIRECTORY_TYPE) {
		ppDirectory = uintptr(unsafe.Pointer(&Xsqlite3_data_directory))
	} else {
		if type1 == uint32(SQLITE_WIN32_TEMP_DIRECTORY_TYPE) {
			ppDirectory = uintptr(unsafe.Pointer(&Xsqlite3_temp_directory))
		}
	}
	if ppDirectory != 0 {
		zCopy = uintptr(0)
		if zValue != 0 && *(*int8)(unsafe.Pointer(zValue)) != 0 {
			zCopy = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, zValue))
			if zCopy == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
				goto set_directory8_done
			}
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(ppDirectory)))
		*(*uintptr)(unsafe.Pointer(ppDirectory)) = zCopy
		rc = SQLITE_OK
	} else {
		rc = int32(SQLITE_ERROR)
	}
	goto set_directory8_done
set_directory8_done:
	;
	Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
	return rc
}

// C documentation
//
//	/*
//	** This function is the same as sqlite3_win32_set_directory (below); however,
//	** it accepts a UTF-16 string.
//	*/
func Xsqlite3_win32_set_directory16(tls *libc.TLS, type1 uint32, zValue uintptr) (r int32) {
	var rc int32
	var zUtf8 uintptr
	_, _ = rc, zUtf8
	zUtf8 = uintptr(0)
	if zValue != 0 {
		zUtf8 = Xsqlite3_win32_unicode_to_utf8(tls, zValue)
		if zUtf8 == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
	}
	rc = Xsqlite3_win32_set_directory8(tls, type1, zUtf8)
	if zUtf8 != 0 {
		Xsqlite3_free(tls, zUtf8)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function sets the data directory or the temporary directory based on
//	** the provided arguments.  The type argument must be 1 in order to set the
//	** data directory or 2 in order to set the temporary directory.  The zValue
//	** argument is the name of the directory to use.  The return value will be
//	** SQLITE_OK if successful.
//	*/
func Xsqlite3_win32_set_directory(tls *libc.TLS, type1 uint32, zValue uintptr) (r int32) {
	return Xsqlite3_win32_set_directory16(tls, type1, zValue)
}

// C documentation
//
//	/*
//	** The return value of winGetLastErrorMsg
//	** is zero if the error message fits in the buffer, or non-zero
//	** otherwise (if the message was truncated).
//	*/
func _winGetLastErrorMsg(tls *libc.TLS, lastErrno TDWORD, nBuf int32, zBuf uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var dwLen TDWORD
	var zOut uintptr
	var _ /* zTemp at bp+4 */ uintptr
	var _ /* zTempWide at bp+0 */ TLPWSTR
	_, _ = dwLen, zOut
	/* FormatMessage returns 0 on failure.  Otherwise it
	 ** returns the number of TCHARs written to the output
	 ** buffer, excluding the terminating null char.
	 */
	dwLen = uint32(0)
	zOut = uintptr(0)
	if int32(1) != 0 {
		*(*TLPWSTR)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
		dwLen = (*(*func(*libc.TLS, TDWORD, TLPCVOID, TDWORD, TDWORD, TLPWSTR, TDWORD, uintptr) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(15)].FpCurrent})))(tls, uint32(libc.Int32FromInt32(FORMAT_MESSAGE_ALLOCATE_BUFFER)|libc.Int32FromInt32(FORMAT_MESSAGE_FROM_SYSTEM)|libc.Int32FromInt32(FORMAT_MESSAGE_IGNORE_INSERTS)), libc.UintptrFromInt32(0), lastErrno, uint32(0), bp, uint32(0), uintptr(0))
		if dwLen > uint32(0) {
			/* allocate a buffer and convert to UTF8 */
			_sqlite3BeginBenignMalloc(tls)
			zOut = _winUnicodeToUtf8(tls, *(*TLPWSTR)(unsafe.Pointer(bp)))
			_sqlite3EndBenignMalloc(tls)
			/* free the system buffer allocated by FormatMessage */
			(*(*func(*libc.TLS, THLOCAL) THLOCAL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(46)].FpCurrent})))(tls, *(*TLPWSTR)(unsafe.Pointer(bp)))
		}
	} else {
		*(*uintptr)(unsafe.Pointer(bp + 4)) = libc.UintptrFromInt32(0)
		dwLen = (*(*func(*libc.TLS, TDWORD, TLPCVOID, TDWORD, TDWORD, TLPSTR, TDWORD, uintptr) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(14)].FpCurrent})))(tls, uint32(libc.Int32FromInt32(FORMAT_MESSAGE_ALLOCATE_BUFFER)|libc.Int32FromInt32(FORMAT_MESSAGE_FROM_SYSTEM)|libc.Int32FromInt32(FORMAT_MESSAGE_IGNORE_INSERTS)), libc.UintptrFromInt32(0), lastErrno, uint32(0), bp+4, uint32(0), uintptr(0))
		if dwLen > uint32(0) {
			/* allocate a buffer and convert to UTF8 */
			_sqlite3BeginBenignMalloc(tls)
			zOut = _winMbcsToUtf8(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), (*(*func(*libc.TLS) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls))
			_sqlite3EndBenignMalloc(tls)
			/* free the system buffer allocated by FormatMessage */
			(*(*func(*libc.TLS, THLOCAL) THLOCAL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(46)].FpCurrent})))(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
		}
	}
	if uint32(0) == dwLen {
		Xsqlite3_snprintf(tls, nBuf, zBuf, __ccgo_ts+4712, libc.VaList(bp+16, lastErrno, lastErrno))
	} else {
		/* copy a maximum of nBuf chars to output buffer */
		Xsqlite3_snprintf(tls, nBuf, zBuf, __ccgo_ts+4709, libc.VaList(bp+16, zOut))
		/* free the UTF8 buffer */
		Xsqlite3_free(tls, zOut)
	}
	return 0
}

// C documentation
//
//	/*
//	**
//	** This function - winLogErrorAtLine() - is only ever called via the macro
//	** winLogError().
//	**
//	** This routine is invoked after an error occurs in an OS function.
//	** It logs a message using sqlite3_log() containing the current value of
//	** error code and, if possible, the human-readable equivalent from
//	** FormatMessage.
//	**
//	** The first argument passed to the macro should be the error code that
//	** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
//	** The two subsequent arguments should be the name of the OS function that
//	** failed and the associated file-system path, if any.
//	*/
func _winLogErrorAtLine(tls *libc.TLS, errcode int32, lastErrno TDWORD, zFunc uintptr, zPath uintptr, iLine int32) (r int32) {
	bp := tls.Alloc(560)
	defer tls.Free(560)
	var i int32
	var _ /* zMsg at bp+0 */ [500]int8
	_ = i /* Loop counter */
	(*(*[500]int8)(unsafe.Pointer(bp)))[0] = 0
	_winGetLastErrorMsg(tls, lastErrno, int32(500), bp)
	if zPath == uintptr(0) {
		zPath = __ccgo_ts + 1672
	}
	i = 0
	for {
		if !((*(*[500]int8)(unsafe.Pointer(bp)))[i] != 0 && int32((*(*[500]int8)(unsafe.Pointer(bp)))[i]) != int32('\r') && int32((*(*[500]int8)(unsafe.Pointer(bp)))[i]) != int32('\n')) {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	(*(*[500]int8)(unsafe.Pointer(bp)))[i] = 0
	Xsqlite3_log(tls, errcode, __ccgo_ts+4732, libc.VaList(bp+512, iLine, lastErrno, zFunc, zPath, bp))
	return errcode
}

// C documentation
//
//	/*
//	** The number of times that a ReadFile(), WriteFile(), and DeleteFile()
//	** will be retried following a locking error - probably caused by
//	** antivirus software.  Also the initial delay before the first retry.
//	** The delay increases linearly with each retry.
//	*/
var _winIoerrRetry = int32(SQLITE_WIN32_IOERR_RETRY)
var _winIoerrRetryDelay = int32(SQLITE_WIN32_IOERR_RETRY_DELAY)

/*
** The "winIoerrCanRetry1" macro is used to determine if a particular I/O
** error code obtained via GetLastError() is eligible to be retried.  It
** must accept the error code DWORD as its only argument and should return
** non-zero if the error code is transient in nature and the operation
** responsible for generating the original error might succeed upon being
** retried.  The argument to this macro should be a variable.
**
** Additionally, a macro named "winIoerrCanRetry2" may be defined.  If it
** is defined, it will be consulted only when the macro "winIoerrCanRetry1"
** returns zero.  The "winIoerrCanRetry2" macro is completely optional and
** may be used to include additional error codes in the set that should
** result in the failing I/O operation being retried by the caller.  If
** defined, the "winIoerrCanRetry2" macro must exhibit external semantics
** identical to those of the "winIoerrCanRetry1" macro.
 */

// C documentation
//
//	/*
//	** If a ReadFile() or WriteFile() error occurs, invoke this routine
//	** to see if it should be retried.  Return TRUE to retry.  Return FALSE
//	** to give up with an error.
//	*/
func _winRetryIoerr(tls *libc.TLS, pnRetry uintptr, pError uintptr) (r int32) {
	var e TDWORD
	_ = e
	e = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
	if *(*int32)(unsafe.Pointer(pnRetry)) >= _winIoerrRetry {
		if pError != 0 {
			*(*TDWORD)(unsafe.Pointer(pError)) = e
		}
		return 0
	}
	if e == uint32(5) || e == uint32(32) || e == uint32(33) || e == uint32(55) || e == uint32(64) || e == uint32(121) || e == uint32(1231) {
		Xsqlite3_win32_sleep(tls, uint32(_winIoerrRetryDelay*(int32(1)+*(*int32)(unsafe.Pointer(pnRetry)))))
		*(*int32)(unsafe.Pointer(pnRetry))++
		return int32(1)
	}
	if pError != 0 {
		*(*TDWORD)(unsafe.Pointer(pError)) = e
	}
	return 0
}

// C documentation
//
//	/*
//	** Log a I/O error retry episode.
//	*/
func _winLogIoerr(tls *libc.TLS, nRetry int32, lineno int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	if nRetry != 0 {
		Xsqlite3_log(tls, int32(SQLITE_NOTICE), __ccgo_ts+4763, libc.VaList(bp+8, _winIoerrRetryDelay*nRetry*(nRetry+int32(1))/int32(2), lineno))
	}
}

/*
** This #if does not rely on the SQLITE_OS_WINCE define because the
** corresponding section in "date.c" cannot use it.
 */

// C documentation
//
//	/*
//	** Lock a file region.
//	*/
func _winLockFile(tls *libc.TLS, phFile TLPHANDLE, flags TDWORD, offsetLow TDWORD, offsetHigh TDWORD, numBytesLow TDWORD, numBytesHigh TDWORD) (r TBOOL) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* ovlp at bp+0 */ TOVERLAPPED
	if int32(1) != 0 {
		libc.Xmemset(tls, bp, 0, uint32(20))
		(*(*TOVERLAPPED)(unsafe.Pointer(bp))).F__ccgo2_8.F__ccgo0_0.FOffset = offsetLow
		(*(*TOVERLAPPED)(unsafe.Pointer(bp))).F__ccgo2_8.F__ccgo0_0.FOffsetHigh = offsetHigh
		return (*(*func(*libc.TLS, THANDLE, TDWORD, TDWORD, TDWORD, TDWORD, TLPOVERLAPPED) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(48)].FpCurrent})))(tls, *(*THANDLE)(unsafe.Pointer(phFile)), flags, uint32(0), numBytesLow, numBytesHigh, bp)
	} else {
		return (*(*func(*libc.TLS, THANDLE, TDWORD, TDWORD, TDWORD, TDWORD) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(47)].FpCurrent})))(tls, *(*THANDLE)(unsafe.Pointer(phFile)), offsetLow, offsetHigh, numBytesLow, numBytesHigh)
	}
	return r
}

// C documentation
//
//	/*
//	** Unlock a file region.
//	 */
func _winUnlockFile(tls *libc.TLS, phFile TLPHANDLE, offsetLow TDWORD, offsetHigh TDWORD, numBytesLow TDWORD, numBytesHigh TDWORD) (r TBOOL) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* ovlp at bp+0 */ TOVERLAPPED
	if int32(1) != 0 {
		libc.Xmemset(tls, bp, 0, uint32(20))
		(*(*TOVERLAPPED)(unsafe.Pointer(bp))).F__ccgo2_8.F__ccgo0_0.FOffset = offsetLow
		(*(*TOVERLAPPED)(unsafe.Pointer(bp))).F__ccgo2_8.F__ccgo0_0.FOffsetHigh = offsetHigh
		return (*(*func(*libc.TLS, THANDLE, TDWORD, TDWORD, TDWORD, TLPOVERLAPPED) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(58)].FpCurrent})))(tls, *(*THANDLE)(unsafe.Pointer(phFile)), uint32(0), numBytesLow, numBytesHigh, bp)
	} else {
		return (*(*func(*libc.TLS, THANDLE, TDWORD, TDWORD, TDWORD, TDWORD) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(57)].FpCurrent})))(tls, *(*THANDLE)(unsafe.Pointer(phFile)), offsetLow, offsetHigh, numBytesLow, numBytesHigh)
	}
	return r
}

/*****************************************************************************
** The next group of routines implement the I/O methods specified
** by the sqlite3_io_methods object.
******************************************************************************/

/*
** Some Microsoft compilers lack this definition.
 */

// C documentation
//
//	/*
//	** Move the current position of the file handle passed as the first
//	** argument to offset iOffset within the file. If successful, return 0.
//	** Otherwise, set pFile->lastErrno and return non-zero.
//	*/
func _winSeekFile(tls *libc.TLS, pFile uintptr, iOffset Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var dwRet, lastErrno, v1 TDWORD
	var lowerBits TLONG
	var v2 bool
	var _ /* upperBits at bp+0 */ TLONG
	_, _, _, _, _ = dwRet, lastErrno, lowerBits, v1, v2 /* Value returned by GetLastError() */
	*(*TLONG)(unsafe.Pointer(bp)) = int32(iOffset >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7fffffff))
	lowerBits = int32(iOffset & libc.Int64FromUint32(0xffffffff))
	/* API oddity: If successful, SetFilePointer() returns a dword
	 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
	 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
	 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
	 ** whether an error has actually occurred, it is also necessary to call
	 ** GetLastError().
	 */
	dwRet = (*(*func(*libc.TLS, THANDLE, TLONG, TPLONG, TDWORD) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(54)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).Fh, lowerBits, bp, uint32(FILE_BEGIN))
	if v2 = dwRet == uint32(-libc.Int32FromInt32(1)); v2 {
		v1 = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		lastErrno = v1
	}
	if v2 && v1 != uint32(0) {
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = lastErrno
		_winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(22)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4813, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49267))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Close a file.
//	**
//	** It is reported that an attempt to close a handle might sometimes
//	** fail.  This is a very unreasonable result, but Windows is notorious
//	** for being unreasonable so I do not doubt that it might happen.  If
//	** the close fails, we pause for 100 milliseconds and try again.  As
//	** many as MX_CLOSE_ATTEMPT attempts to close the handle are made before
//	** giving up and returning an error.
//	*/
func _winClose(tls *libc.TLS, id uintptr) (r int32) {
	var cnt, rc, v1, v5 int32
	var pFile uintptr
	var v2, v3 bool
	_, _, _, _, _, _, _ = cnt, pFile, rc, v1, v2, v3, v5
	cnt = 0
	pFile = id
	_winUnmapfile(tls, pFile)
	for {
		rc = (*(*func(*libc.TLS, THANDLE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(3)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).Fh)
		/* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
		goto _4
	_4:
		;
		if v2 = rc == 0; v2 {
			cnt++
			v1 = cnt
		}
		if v3 = v2 && v1 < int32(MX_CLOSE_ATTEMPT); v3 {
			Xsqlite3_win32_sleep(tls, uint32(100))
		}
		if !(v3 && libc.Bool(libc.Int32FromInt32(1) != 0)) {
			break
		}
	}
	if rc != 0 {
		(*TwinFile)(unsafe.Pointer(pFile)).Fh = libc.UintptrFromInt32(0)
	}
	if rc != 0 {
		v5 = SQLITE_OK
	} else {
		v5 = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(16)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+4825, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49363))
	}
	return v5
}

// C documentation
//
//	/*
//	** Read data from a file into a buffer.  Return SQLITE_OK if all
//	** bytes were read successfully and SQLITE_IOERR if anything goes
//	** wrong.
//	*/
func _winRead(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nCopy int32
	var pFile uintptr
	var _ /* lastErrno at bp+28 */ TDWORD
	var _ /* nRead at bp+20 */ TDWORD
	var _ /* nRetry at bp+24 */ int32
	var _ /* overlapped at bp+0 */ TOVERLAPPED
	_, _ = nCopy, pFile                    /* The offset for ReadFile. */
	pFile = id                             /* Number of bytes actually read from file */
	*(*int32)(unsafe.Pointer(bp + 24)) = 0 /* Number of retrys */
	/* Deal with as much of this read request as possible by transferring
	 ** data from the memory mapping using memcpy().  */
	if offset < (*TwinFile)(unsafe.Pointer(pFile)).FmmapSize {
		if offset+int64(int64(amt)) <= (*TwinFile)(unsafe.Pointer(pFile)).FmmapSize {
			libc.Xmemcpy(tls, pBuf, (*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion+uintptr(offset), uint32(uint32(amt)))
			return SQLITE_OK
		} else {
			nCopy = int32((*TwinFile)(unsafe.Pointer(pFile)).FmmapSize - offset)
			libc.Xmemcpy(tls, pBuf, (*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion+uintptr(offset), uint32(uint32(nCopy)))
			pBuf = pBuf + uintptr(nCopy)
			amt -= nCopy
			offset += int64(int64(nCopy))
		}
	}
	libc.Xmemset(tls, bp, 0, uint32(20))
	(*(*TOVERLAPPED)(unsafe.Pointer(bp))).F__ccgo2_8.F__ccgo0_0.FOffset = uint32(int32(offset & libc.Int64FromUint32(0xffffffff)))
	(*(*TOVERLAPPED)(unsafe.Pointer(bp))).F__ccgo2_8.F__ccgo0_0.FOffsetHigh = uint32(int32(offset >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7fffffff)))
	for !((*(*func(*libc.TLS, THANDLE, TLPVOID, TDWORD, TLPDWORD, TLPOVERLAPPED) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(52)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).Fh, pBuf, uint32(uint32(amt)), bp+20, bp) != 0) && (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls) != uint32(38) {
		if _winRetryIoerr(tls, bp+24, bp+28) != 0 {
			continue
		}
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = *(*TDWORD)(unsafe.Pointer(bp + 28))
		return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4834, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49431))
	}
	_winLogIoerr(tls, *(*int32)(unsafe.Pointer(bp + 24)), int32(49434))
	if *(*TDWORD)(unsafe.Pointer(bp + 20)) < uint32(uint32(amt)) {
		/* Unread parts of the buffer must be zero-filled */
		libc.Xmemset(tls, pBuf+uintptr(*(*TDWORD)(unsafe.Pointer(bp + 20))), 0, uint32(uint32(uint32(amt))-*(*TDWORD)(unsafe.Pointer(bp + 20))))
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Write data from a buffer into a file.  Return SQLITE_OK on success
//	** or some other error code on failure.
//	*/
func _winWrite(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aRem, pFile uintptr
	var nRem, rc int32
	var _ /* lastErrno at bp+28 */ TDWORD
	var _ /* nRetry at bp+0 */ int32
	var _ /* nWrite at bp+24 */ TDWORD
	var _ /* overlapped at bp+4 */ TOVERLAPPED
	_, _, _, _ = aRem, nRem, pFile, rc
	rc = 0                            /* True if error has occurred, else false */
	pFile = id                        /* File handle */
	*(*int32)(unsafe.Pointer(bp)) = 0 /* Number of retries */
	/* The offset for WriteFile. */
	aRem = pBuf                                     /* Data yet to be written */
	nRem = amt                                      /* Bytes written by each WriteFile() call */
	*(*TDWORD)(unsafe.Pointer(bp + 28)) = uint32(0) /* Value returned by GetLastError() */
	libc.Xmemset(tls, bp+4, 0, uint32(20))
	(*(*TOVERLAPPED)(unsafe.Pointer(bp + 4))).F__ccgo2_8.F__ccgo0_0.FOffset = uint32(int32(offset & libc.Int64FromUint32(0xffffffff)))
	(*(*TOVERLAPPED)(unsafe.Pointer(bp + 4))).F__ccgo2_8.F__ccgo0_0.FOffsetHigh = uint32(int32(offset >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7fffffff)))
	for nRem > 0 {
		if !((*(*func(*libc.TLS, THANDLE, TLPCVOID, TDWORD, TLPDWORD, TLPOVERLAPPED) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(61)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).Fh, aRem, uint32(uint32(nRem)), bp+24, bp+4) != 0) {
			if _winRetryIoerr(tls, bp, bp+28) != 0 {
				continue
			}
			break
		}
		if *(*TDWORD)(unsafe.Pointer(bp + 24)) == uint32(0) || *(*TDWORD)(unsafe.Pointer(bp + 24)) > uint32(uint32(nRem)) {
			*(*TDWORD)(unsafe.Pointer(bp + 28)) = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			break
		}
		offset += int64(*(*TDWORD)(unsafe.Pointer(bp + 24)))
		(*(*TOVERLAPPED)(unsafe.Pointer(bp + 4))).F__ccgo2_8.F__ccgo0_0.FOffset = uint32(int32(offset & libc.Int64FromUint32(0xffffffff)))
		(*(*TOVERLAPPED)(unsafe.Pointer(bp + 4))).F__ccgo2_8.F__ccgo0_0.FOffsetHigh = uint32(int32(offset >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7fffffff)))
		aRem += uintptr(*(*TDWORD)(unsafe.Pointer(bp + 24)))
		nRem = int32(uint32(nRem) - *(*TDWORD)(unsafe.Pointer(bp + 24)))
	}
	if nRem > 0 {
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = *(*TDWORD)(unsafe.Pointer(bp + 28))
		rc = int32(1)
	}
	if rc != 0 {
		if (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno == uint32(39) || (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno == uint32(112) {
			return _winLogErrorAtLine(tls, int32(SQLITE_FULL), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4842, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49543))
		}
		return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4852, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49548))
	} else {
		_winLogIoerr(tls, *(*int32)(unsafe.Pointer(bp)), int32(49551))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Truncate an open file to a specified size
//	*/
func _winTruncate(tls *libc.TLS, id uintptr, nByte Tsqlite3_int64) (r int32) {
	var lastErrno, v1 TDWORD
	var oldMmapSize Tsqlite3_int64
	var pFile uintptr
	var rc int32
	var v2 bool
	_, _, _, _, _, _ = lastErrno, oldMmapSize, pFile, rc, v1, v2
	pFile = id /* File handle object */
	rc = SQLITE_OK
	if (*TwinFile)(unsafe.Pointer(pFile)).FnFetchOut > 0 {
		/* File truncation is a no-op if there are outstanding memory mapped
		 ** pages.  This is because truncating the file means temporarily unmapping
		 ** the file, and that might delete memory out from under existing cursors.
		 **
		 ** This can result in incremental vacuum not truncating the file,
		 ** if there is an active read cursor when the incremental vacuum occurs.
		 ** No real harm comes of this - the database file is not corrupted,
		 ** though some folks might complain that the file is bigger than it
		 ** needs to be.
		 **
		 ** The only feasible work-around is to defer the truncation until after
		 ** all references to memory-mapped content are closed.  That is doable,
		 ** but involves adding a few branches in the common write code path which
		 ** could slow down normal operations slightly.  Hence, we have decided for
		 ** now to simply make transactions a no-op if there are pending reads.  We
		 ** can maybe revisit this decision in the future.
		 */
		return SQLITE_OK
	}
	/* If the user has configured a chunk-size for this file, truncate the
	 ** file so that it consists of an integer number of chunks (i.e. the
	 ** actual file size after the operation may be larger than the requested
	 ** size).
	 */
	if (*TwinFile)(unsafe.Pointer(pFile)).FszChunk > 0 {
		nByte = (nByte + int64((*TwinFile)(unsafe.Pointer(pFile)).FszChunk) - int64(1)) / int64((*TwinFile)(unsafe.Pointer(pFile)).FszChunk) * int64((*TwinFile)(unsafe.Pointer(pFile)).FszChunk)
	}
	if (*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion != 0 {
		oldMmapSize = (*TwinFile)(unsafe.Pointer(pFile)).FmmapSize
	} else {
		oldMmapSize = 0
	}
	_winUnmapfile(tls, pFile)
	/* SetEndOfFile() returns non-zero when successful, or zero when it fails. */
	if _winSeekFile(tls, pFile, nByte) != 0 {
		rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(6)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4862, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49614))
	} else {
		if v2 = 0 == (*(*func(*libc.TLS, THANDLE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(53)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).Fh); v2 {
			v1 = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			lastErrno = v1
		}
		if v2 && v1 != uint32(1224) {
			(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = lastErrno
			rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(6)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4875, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49619))
		}
	}
	if rc == SQLITE_OK && oldMmapSize > 0 {
		if oldMmapSize > nByte {
			_winMapfile(tls, pFile, int64(-int32(1)))
		} else {
			_winMapfile(tls, pFile, oldMmapSize)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Make sure all writes to a particular file are committed to disk.
//	*/
func _winSync(tls *libc.TLS, id uintptr, flags int32) (r int32) {
	var pFile uintptr
	var rc TBOOL
	_, _ = pFile, rc
	/*
	 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
	 ** OSTRACE() macros.
	 */
	pFile = id
	/* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */
	/* Unix cannot, but some systems may return SQLITE_FULL from here. This
	 ** line is to test that doing so does not cause any problems.
	 */
	_ = flags
	/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
	 ** no-op
	 */
	if (*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion != 0 {
		if (*(*func(*libc.TLS, TLPCVOID, TSIZE_T) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(79)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion, uint32(0)) != 0 {
		} else {
			(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(24)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4888, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49711))
		}
	}
	rc = (*(*func(*libc.TLS, THANDLE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(13)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).Fh)
	if rc != 0 {
		return SQLITE_OK
	} else {
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(4)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4897, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49726))
	}
	return r
}

// C documentation
//
//	/*
//	** Determine the current size of a file in bytes
//	*/
func _winFileSize(tls *libc.TLS, id uintptr, pSize uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var lastErrno, lowerBits, v1 TDWORD
	var pFile uintptr
	var rc int32
	var v2 bool
	var _ /* upperBits at bp+0 */ TDWORD
	_, _, _, _, _, _ = lastErrno, lowerBits, pFile, rc, v1, v2
	pFile = id
	rc = SQLITE_OK
	lowerBits = (*(*func(*libc.TLS, THANDLE, TLPDWORD) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(23)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).Fh, bp)
	*(*Tsqlite3_int64)(unsafe.Pointer(pSize)) = int64(*(*TDWORD)(unsafe.Pointer(bp)))<<libc.Int32FromInt32(32) + int64(int64(lowerBits))
	if v2 = lowerBits == libc.Uint32FromUint32(0xffffffff); v2 {
		v1 = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		lastErrno = v1
	}
	if v2 && v1 != uint32(0) {
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = lastErrno
		rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(7)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4906, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49767))
	}
	return rc
}

/*
** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
 */

/*
** Historically, SQLite has used both the LockFile and LockFileEx functions.
** When the LockFile function was used, it was always expected to fail
** immediately if the lock could not be obtained.  Also, it always expected to
** obtain an exclusive lock.  These flags are used with the LockFileEx function
** and reflect those expectations; therefore, they should not be changed.
 */

/*
** Currently, SQLite never calls the LockFileEx function without wanting the
** call to fail immediately if the lock cannot be obtained.
 */

// C documentation
//
//	/*
//	** Acquire a reader lock.
//	** Different API routines are called depending on whether or not this
//	** is Win9x or WinNT.
//	*/
func _winGetReadLock(tls *libc.TLS, pFile uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var res int32
	var _ /* lk at bp+0 */ int32
	_ = res
	if int32(1) != 0 {
		res = _winLockFile(tls, pFile+8, uint32(libc.Int32FromInt32(LOCKFILE_FAIL_IMMEDIATELY)), uint32(_sqlite3PendingByte+libc.Int32FromInt32(2)), uint32(0), uint32(SHARED_SIZE), uint32(0))
	} else {
		Xsqlite3_randomness(tls, int32(4), bp)
		(*TwinFile)(unsafe.Pointer(pFile)).FsharedLockByte = int16(*(*int32)(unsafe.Pointer(bp)) & libc.Int32FromInt32(0x7fffffff) % (libc.Int32FromInt32(SHARED_SIZE) - libc.Int32FromInt32(1)))
		res = _winLockFile(tls, pFile+8, uint32(libc.Int32FromInt32(LOCKFILE_FAIL_IMMEDIATELY)|libc.Int32FromInt32(LOCKFILE_EXCLUSIVE_LOCK)), uint32(_sqlite3PendingByte+int32(2)+int32((*TwinFile)(unsafe.Pointer(pFile)).FsharedLockByte)), uint32(0), uint32(1), uint32(0))
	}
	if res == 0 {
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		/* No need to log a failure to lock */
	}
	return res
}

// C documentation
//
//	/*
//	** Undo a readlock
//	*/
func _winUnlockReadLock(tls *libc.TLS, pFile uintptr) (r int32) {
	var lastErrno, v1 TDWORD
	var res int32
	var v2 bool
	_, _, _, _ = lastErrno, res, v1, v2
	if int32(1) != 0 {
		res = _winUnlockFile(tls, pFile+8, uint32(_sqlite3PendingByte+libc.Int32FromInt32(2)), uint32(0), uint32(SHARED_SIZE), uint32(0))
	} else {
		res = _winUnlockFile(tls, pFile+8, uint32(_sqlite3PendingByte+int32(2)+int32((*TwinFile)(unsafe.Pointer(pFile)).FsharedLockByte)), uint32(0), uint32(1), uint32(0))
	}
	if v2 = res == 0; v2 {
		v1 = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		lastErrno = v1
	}
	if v2 && v1 != uint32(158) {
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = lastErrno
		_winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(8)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+4918, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(49862))
	}
	return res
}

// C documentation
//
//	/*
//	** Lock the file with the lock specified by parameter locktype - one
//	** of the following:
//	**
//	**     (1) SHARED_LOCK
//	**     (2) RESERVED_LOCK
//	**     (3) PENDING_LOCK
//	**     (4) EXCLUSIVE_LOCK
//	**
//	** Sometimes when requesting one lock state, additional lock states
//	** are inserted in between.  The locking might fail on one of the later
//	** transitions leaving the lock state different from what it started but
//	** still short of its goal.  The following chart shows the allowed
//	** transitions and the inserted intermediate states:
//	**
//	**    UNLOCKED -> SHARED
//	**    SHARED -> RESERVED
//	**    SHARED -> (PENDING) -> EXCLUSIVE
//	**    RESERVED -> (PENDING) -> EXCLUSIVE
//	**    PENDING -> EXCLUSIVE
//	**
//	** This routine will only increase a lock.  The winUnlock() routine
//	** erases all locks at once and returns us immediately to locking level 0.
//	** It is not possible to lower the locking level one step at a time.  You
//	** must go straight to locking level 0.
//	*/
func _winLock(tls *libc.TLS, id uintptr, locktype int32) (r int32) {
	var cnt, gotPendingLock, newLocktype, rc, res, v1, v2 int32
	var lastErrno TDWORD
	var pFile uintptr
	var v3 bool
	_, _, _, _, _, _, _, _, _, _ = cnt, gotPendingLock, lastErrno, newLocktype, pFile, rc, res, v1, v2, v3
	rc = SQLITE_OK     /* Return code from subroutines */
	res = int32(1)     /* Set pFile->locktype to this value before exiting */
	gotPendingLock = 0 /* True if we acquired a PENDING lock this time */
	pFile = id
	lastErrno = uint32(0)
	/* If there is already a lock of this type or more restrictive on the
	 ** OsFile, do nothing. Don't use the end_lock: exit path, as
	 ** sqlite3OsEnterMutex() hasn't been called yet.
	 */
	if int32((*TwinFile)(unsafe.Pointer(pFile)).Flocktype) >= locktype {
		return SQLITE_OK
	}
	/* Do not allow any kind of write-lock on a read-only database
	 */
	if int32((*TwinFile)(unsafe.Pointer(pFile)).FctrlFlags)&int32(WINFILE_RDONLY) != 0 && locktype >= int32(RESERVED_LOCK) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(15)<<libc.Int32FromInt32(8)
	}
	/* Make sure the locking sequence is correct
	 */
	/* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
	 ** a SHARED lock.  If we are acquiring a SHARED lock, the acquisition of
	 ** the PENDING_LOCK byte is temporary.
	 */
	newLocktype = int32((*TwinFile)(unsafe.Pointer(pFile)).Flocktype)
	if int32((*TwinFile)(unsafe.Pointer(pFile)).Flocktype) == NO_LOCK || locktype == int32(EXCLUSIVE_LOCK) && int32((*TwinFile)(unsafe.Pointer(pFile)).Flocktype) <= int32(RESERVED_LOCK) {
		cnt = int32(3)
		for {
			v1 = cnt
			cnt--
			if v3 = v1 > 0; v3 {
				v2 = _winLockFile(tls, pFile+8, uint32(libc.Int32FromInt32(LOCKFILE_FAIL_IMMEDIATELY)|libc.Int32FromInt32(LOCKFILE_EXCLUSIVE_LOCK)), uint32(uint32(_sqlite3PendingByte)), uint32(0), uint32(1), uint32(0))
				res = v2
			}
			if !(v3 && v2 == 0) {
				break
			}
			/* Try 3 times to get the pending lock.  This is needed to work
			 ** around problems caused by indexing and/or anti-virus software on
			 ** Windows systems.
			 ** If you are using this code as a model for alternative VFSes, do not
			 ** copy this retry logic.  It is a hack intended for Windows only.
			 */
			lastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			if lastErrno == uint32(6) {
				(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = lastErrno
				rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(15)<<libc.Int32FromInt32(8)
				return rc
			}
			if cnt != 0 {
				Xsqlite3_win32_sleep(tls, uint32(1))
			}
		}
		gotPendingLock = res
		if !(res != 0) {
			lastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		}
	}
	/* Acquire a shared lock
	 */
	if locktype == int32(SHARED_LOCK) && res != 0 {
		res = _winGetReadLock(tls, pFile)
		if res != 0 {
			newLocktype = int32(SHARED_LOCK)
		} else {
			lastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		}
	}
	/* Acquire a RESERVED lock
	 */
	if locktype == int32(RESERVED_LOCK) && res != 0 {
		res = _winLockFile(tls, pFile+8, uint32(libc.Int32FromInt32(LOCKFILE_FAIL_IMMEDIATELY)|libc.Int32FromInt32(LOCKFILE_EXCLUSIVE_LOCK)), uint32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint32(0), uint32(1), uint32(0))
		if res != 0 {
			newLocktype = int32(RESERVED_LOCK)
		} else {
			lastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		}
	}
	/* Acquire a PENDING lock
	 */
	if locktype == int32(EXCLUSIVE_LOCK) && res != 0 {
		newLocktype = int32(PENDING_LOCK)
		gotPendingLock = 0
	}
	/* Acquire an EXCLUSIVE lock
	 */
	if locktype == int32(EXCLUSIVE_LOCK) && res != 0 {
		_winUnlockReadLock(tls, pFile)
		res = _winLockFile(tls, pFile+8, uint32(libc.Int32FromInt32(LOCKFILE_FAIL_IMMEDIATELY)|libc.Int32FromInt32(LOCKFILE_EXCLUSIVE_LOCK)), uint32(_sqlite3PendingByte+libc.Int32FromInt32(2)), uint32(0), uint32(SHARED_SIZE), uint32(0))
		if res != 0 {
			newLocktype = int32(EXCLUSIVE_LOCK)
		} else {
			lastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			_winGetReadLock(tls, pFile)
		}
	}
	/* If we are holding a PENDING lock that ought to be released, then
	 ** release it now.
	 */
	if gotPendingLock != 0 && locktype == int32(SHARED_LOCK) {
		_winUnlockFile(tls, pFile+8, uint32(uint32(_sqlite3PendingByte)), uint32(0), uint32(1), uint32(0))
	}
	/* Update the state of the lock has held in the file descriptor then
	 ** return the appropriate result code.
	 */
	if res != 0 {
		rc = SQLITE_OK
	} else {
		(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = lastErrno
		rc = int32(SQLITE_BUSY)
	}
	(*TwinFile)(unsafe.Pointer(pFile)).Flocktype = uint8(uint8(newLocktype))
	return rc
}

// C documentation
//
//	/*
//	** This routine checks if there is a RESERVED lock held on the specified
//	** file by this or any other process. If such a lock is held, return
//	** non-zero, otherwise zero.
//	*/
func _winCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) (r int32) {
	var pFile uintptr
	var res int32
	_, _ = pFile, res
	pFile = id
	if int32((*TwinFile)(unsafe.Pointer(pFile)).Flocktype) >= int32(RESERVED_LOCK) {
		res = int32(1)
	} else {
		res = _winLockFile(tls, pFile+8, uint32(libc.Int32FromInt32(LOCKFILE_FAIL_IMMEDIATELY)), uint32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint32(0), uint32(1), uint32(0))
		if res != 0 {
			_winUnlockFile(tls, pFile+8, uint32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint32(0), uint32(1), uint32(0))
		}
		res = libc.BoolInt32(!(res != 0))
	}
	*(*int32)(unsafe.Pointer(pResOut)) = res
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Lower the locking level on file descriptor id to locktype.  locktype
//	** must be either NO_LOCK or SHARED_LOCK.
//	**
//	** If the locking level of the file descriptor is already at or below
//	** the requested locking level, this routine is a no-op.
//	**
//	** It is not possible for this routine to fail if the second argument
//	** is NO_LOCK.  If the second argument is SHARED_LOCK then this routine
//	** might return SQLITE_IOERR;
//	*/
func _winUnlock(tls *libc.TLS, id uintptr, locktype int32) (r int32) {
	var pFile uintptr
	var rc, type1 int32
	_, _, _ = pFile, rc, type1
	pFile = id
	rc = SQLITE_OK
	type1 = int32((*TwinFile)(unsafe.Pointer(pFile)).Flocktype)
	if type1 >= int32(EXCLUSIVE_LOCK) {
		_winUnlockFile(tls, pFile+8, uint32(_sqlite3PendingByte+libc.Int32FromInt32(2)), uint32(0), uint32(SHARED_SIZE), uint32(0))
		if locktype == int32(SHARED_LOCK) && !(_winGetReadLock(tls, pFile) != 0) {
			/* This should never happen.  We should always be able to
			 ** reacquire the read lock */
			rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(8)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+4936, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(50088))
		}
	}
	if type1 >= int32(RESERVED_LOCK) {
		_winUnlockFile(tls, pFile+8, uint32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint32(0), uint32(1), uint32(0))
	}
	if locktype == NO_LOCK && type1 >= int32(SHARED_LOCK) {
		_winUnlockReadLock(tls, pFile)
	}
	if type1 >= int32(PENDING_LOCK) {
		_winUnlockFile(tls, pFile+8, uint32(uint32(_sqlite3PendingByte)), uint32(0), uint32(1), uint32(0))
	}
	(*TwinFile)(unsafe.Pointer(pFile)).Flocktype = uint8(uint8(locktype))
	return rc
}

/******************************************************************************
****************************** No-op Locking **********************************
**
** Of the various locking implementations available, this is by far the
** simplest:  locking is ignored.  No attempt is made to lock the database
** file for reading or writing.
**
** This locking mode is appropriate for use on read-only databases
** (ex: databases that are burned into CD-ROM, for example.)  It can
** also be used if the application employs some external mechanism to
** prevent simultaneous access of the same database by two or more
** database connections.  But there is a serious risk of database
** corruption if this locking mode is used in situations where multiple
** database connections are accessing the same database file at the same
** time and one or more of those connections are writing.
 */

func _winNolockLock(tls *libc.TLS, id uintptr, locktype int32) (r int32) {
	_ = id
	_ = locktype
	return SQLITE_OK
}

func _winNolockCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) (r int32) {
	_ = id
	_ = pResOut
	return SQLITE_OK
}

func _winNolockUnlock(tls *libc.TLS, id uintptr, locktype int32) (r int32) {
	_ = id
	_ = locktype
	return SQLITE_OK
}

/******************* End of the no-op lock implementation *********************
******************************************************************************/

// C documentation
//
//	/*
//	** If *pArg is initially negative then this is a query.  Set *pArg to
//	** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
//	**
//	** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
//	*/
func _winModeBit(tls *libc.TLS, pFile uintptr, mask uint8, pArg uintptr) {
	var p1, p2 uintptr
	_, _ = p1, p2
	if *(*int32)(unsafe.Pointer(pArg)) < 0 {
		*(*int32)(unsafe.Pointer(pArg)) = libc.BoolInt32(int32((*TwinFile)(unsafe.Pointer(pFile)).FctrlFlags)&int32(int32(mask)) != 0)
	} else {
		if *(*int32)(unsafe.Pointer(pArg)) == 0 {
			p1 = pFile + 16
			*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^int32(int32(mask)))
		} else {
			p2 = pFile + 16
			*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | int32(int32(mask)))
		}
	}
}

// C documentation
//
//	/*
//	** Control and query of the open file handle.
//	*/
func _winFileControl(tls *libc.TLS, id uintptr, op int32, pArg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, pFile uintptr
	var newLimit Ti64
	var newSz Tsqlite3_int64
	var phFile TLPHANDLE
	var rc, rc1, rc2 int32
	var _ /* oldSz at bp+0 */ Tsqlite3_int64
	var _ /* zTFile at bp+8 */ uintptr
	_, _, _, _, _, _, _, _ = a, newLimit, newSz, pFile, phFile, rc, rc1, rc2
	pFile = id
	switch op {
	case int32(SQLITE_FCNTL_LOCKSTATE):
		*(*int32)(unsafe.Pointer(pArg)) = int32((*TwinFile)(unsafe.Pointer(pFile)).Flocktype)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_LAST_ERRNO):
		*(*int32)(unsafe.Pointer(pArg)) = int32((*TwinFile)(unsafe.Pointer(pFile)).FlastErrno)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_CHUNK_SIZE):
		(*TwinFile)(unsafe.Pointer(pFile)).FszChunk = *(*int32)(unsafe.Pointer(pArg))
		return SQLITE_OK
	case int32(SQLITE_FCNTL_SIZE_HINT):
		if (*TwinFile)(unsafe.Pointer(pFile)).FszChunk > 0 {
			rc = _winFileSize(tls, id, bp)
			if rc == SQLITE_OK {
				newSz = *(*Tsqlite3_int64)(unsafe.Pointer(pArg))
				if newSz > *(*Tsqlite3_int64)(unsafe.Pointer(bp)) {
					rc = _winTruncate(tls, id, newSz)
				}
			}
			return rc
		}
		return SQLITE_OK
	case int32(SQLITE_FCNTL_PERSIST_WAL):
		_winModeBit(tls, pFile, uint8(WINFILE_PERSIST_WAL), pArg)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_POWERSAFE_OVERWRITE):
		_winModeBit(tls, pFile, uint8(WINFILE_PSOW), pArg)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_VFSNAME):
		*(*uintptr)(unsafe.Pointer(pArg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+24, (*Tsqlite3_vfs)(unsafe.Pointer((*TwinFile)(unsafe.Pointer(pFile)).FpVfs)).FzName))
		return SQLITE_OK
	case int32(SQLITE_FCNTL_WIN32_AV_RETRY):
		a = pArg
		if *(*int32)(unsafe.Pointer(a)) > 0 {
			_winIoerrRetry = *(*int32)(unsafe.Pointer(a))
		} else {
			*(*int32)(unsafe.Pointer(a)) = _winIoerrRetry
		}
		if *(*int32)(unsafe.Pointer(a + 1*4)) > 0 {
			_winIoerrRetryDelay = *(*int32)(unsafe.Pointer(a + 1*4))
		} else {
			*(*int32)(unsafe.Pointer(a + 1*4)) = _winIoerrRetryDelay
		}
		return SQLITE_OK
	case int32(SQLITE_FCNTL_WIN32_GET_HANDLE):
		phFile = pArg
		*(*THANDLE)(unsafe.Pointer(phFile)) = (*TwinFile)(unsafe.Pointer(pFile)).Fh
		return SQLITE_OK
	case int32(SQLITE_FCNTL_TEMPFILENAME):
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		rc1 = _winGetTempname(tls, (*TwinFile)(unsafe.Pointer(pFile)).FpVfs, bp+8)
		if rc1 == SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pArg)) = *(*uintptr)(unsafe.Pointer(bp + 8))
		}
		return rc1
	case int32(SQLITE_FCNTL_MMAP_SIZE):
		newLimit = *(*Ti64)(unsafe.Pointer(pArg))
		rc2 = SQLITE_OK
		if newLimit > _sqlite3Config.FmxMmap {
			newLimit = _sqlite3Config.FmxMmap
		}
		/* The value of newLimit may be eventually cast to (SIZE_T) and passed
		 ** to MapViewOfFile(). Restrict its value to 2GB if (SIZE_T) is not at
		 ** least a 64-bit type. */
		if newLimit > 0 && libc.Bool(uint32(4) < uint32(8)) {
			newLimit = newLimit & libc.Int64FromInt32(0x7FFFFFFF)
		}
		*(*Ti64)(unsafe.Pointer(pArg)) = (*TwinFile)(unsafe.Pointer(pFile)).FmmapSizeMax
		if newLimit >= 0 && newLimit != (*TwinFile)(unsafe.Pointer(pFile)).FmmapSizeMax && (*TwinFile)(unsafe.Pointer(pFile)).FnFetchOut == 0 {
			(*TwinFile)(unsafe.Pointer(pFile)).FmmapSizeMax = newLimit
			if (*TwinFile)(unsafe.Pointer(pFile)).FmmapSize > 0 {
				_winUnmapfile(tls, pFile)
				rc2 = _winMapfile(tls, pFile, int64(-int32(1)))
			}
		}
		return rc2
	}
	return int32(SQLITE_NOTFOUND)
}

// C documentation
//
//	/*
//	** Return the sector size in bytes of the underlying block device for
//	** the specified file. This is almost always 512 bytes, but may be
//	** larger for some devices.
//	**
//	** SQLite code assumes this function cannot fail. It also assumes that
//	** if two files are created in the same file-system directory (i.e.
//	** a database and its journal file) that the sector size will be the
//	** same for both.
//	*/
func _winSectorSize(tls *libc.TLS, id uintptr) (r int32) {
	_ = id
	return int32(SQLITE_DEFAULT_SECTOR_SIZE)
}

// C documentation
//
//	/*
//	** Return a vector of device characteristics.
//	*/
func _winDeviceCharacteristics(tls *libc.TLS, id uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = id
	if int32((*TwinFile)(unsafe.Pointer(p)).FctrlFlags)&int32(WINFILE_PSOW) != 0 {
		v1 = int32(SQLITE_IOCAP_POWERSAFE_OVERWRITE)
	} else {
		v1 = 0
	}
	return int32(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN) | v1
}

// C documentation
//
//	/*
//	** Windows will only let you create file view mappings
//	** on allocation size granularity boundaries.
//	** During sqlite3_os_init() we do a GetSystemInfo()
//	** to get the granularity size.
//	*/
var _winSysInfo TSYSTEM_INFO

// C documentation
//
//	/*
//	** Helper functions to obtain and relinquish the global mutex. The
//	** global mutex is used to protect the winLockInfo objects used by
//	** this file, all of which may be shared by multiple threads.
//	**
//	** Function winShmMutexHeld() is used to assert() that the global mutex
//	** is held when required. This function is only used as part of assert()
//	** statements. e.g.
//	**
//	**   winShmEnterMutex()
//	**     assert( winShmMutexHeld() );
//	**   winShmLeaveMutex()
//	*/
var _winBigLock = uintptr(0)

func _winShmEnterMutex(tls *libc.TLS) {
	Xsqlite3_mutex_enter(tls, _winBigLock)
}

func _winShmLeaveMutex(tls *libc.TLS) {
	Xsqlite3_mutex_leave(tls, _winBigLock)
}

/*
** Object used to represent a single file opened and mmapped to provide
** shared memory.  When multiple threads all reference the same
** log-summary, each thread has its own winFile object, but they all
** point to a single instance of this object.  In other words, each
** log-summary is opened only once per process.
**
** winShmMutexHeld() must be true when creating or destroying
** this object or while reading or writing the following fields:
**
**      nRef
**      pNext
**
** The following fields are read-only after the object is created:
**
**      fid
**      zFilename
**
** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
** winShmMutexHeld() is true when reading or writing any other field
** in this structure.
**
 */
type TwinShmNode1 = struct {
	F__ccgo_align [0]uint32
	Fmutex        uintptr
	FzFilename    uintptr
	FhFile        TwinFile
	FszRegion     int32
	FnRegion      int32
	FisReadonly   Tu8
	FisUnlocked   Tu8
	FaRegion      uintptr
	FlastErrno    TDWORD
	FnRef         int32
	FpFirst       uintptr
	FpNext        uintptr
}

type winShmNode1 = TwinShmNode1

// C documentation
//
//	/*
//	** A global array of all winShmNode objects.
//	**
//	** The winShmMutexHeld() must be true while reading or writing this list.
//	*/
var _winShmNodeList = uintptr(0)

/*
** Structure used internally by this VFS to record the state of an
** open shared memory connection.
**
** The following fields are initialized when this object is created and
** are read-only thereafter:
**
**    winShm.pShmNode
**    winShm.id
**
** All other fields are read/write.  The winShm.pShmNode->mutex must be held
** while accessing any read/write fields.
 */
type TwinShm1 = struct {
	FpShmNode   uintptr
	FpNext      uintptr
	FhasMutex   Tu8
	FsharedMask Tu16
	FexclMask   Tu16
}

type winShm1 = TwinShm1

/*
** Constants used for locking
 */

// C documentation
//
//	/*
//	** Apply advisory locks for all n bytes beginning at ofst.
//	*/
func _winShmSystemLock(tls *libc.TLS, pFile uintptr, lockType int32, ofst int32, nByte int32) (r int32) {
	var dwFlags TDWORD
	var rc int32
	_, _ = dwFlags, rc
	rc = 0 /* Result code form Lock/UnlockFileEx() */
	/* Access to the winShmNode object is serialized by the caller */
	/* Release/Acquire the system-level lock */
	if lockType == int32(WINSHM_UNLCK) {
		rc = _winUnlockFile(tls, pFile+8+8, uint32(uint32(ofst)), uint32(0), uint32(uint32(nByte)), uint32(0))
	} else {
		/* Initialize the locking parameters */
		dwFlags = uint32(LOCKFILE_FAIL_IMMEDIATELY)
		if lockType == int32(WINSHM_WRLCK) {
			dwFlags |= uint32(LOCKFILE_EXCLUSIVE_LOCK)
		}
		rc = _winLockFile(tls, pFile+8+8, dwFlags, uint32(uint32(ofst)), uint32(0), uint32(uint32(nByte)), uint32(0))
	}
	if rc != 0 {
		rc = SQLITE_OK
	} else {
		(*TwinShmNode)(unsafe.Pointer(pFile)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
		rc = int32(SQLITE_BUSY)
	}
	return rc
}

// C documentation
//
//	/*
//	** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
//	**
//	** This is not a VFS shared-memory method; it is a utility function called
//	** by VFS shared-memory methods.
//	*/
func _winShmPurge(tls *libc.TLS, pVfs uintptr, deleteFlag int32) {
	var bRc TBOOL
	var i int32
	var p, pp, v1 uintptr
	_, _, _, _, _ = bRc, i, p, pp, v1
	pp = uintptr(unsafe.Pointer(&_winShmNodeList))
	for {
		v1 = *(*uintptr)(unsafe.Pointer(pp))
		p = v1
		if !(v1 != uintptr(0)) {
			break
		}
		if (*TwinShmNode)(unsafe.Pointer(p)).FnRef == 0 {
			if (*TwinShmNode)(unsafe.Pointer(p)).Fmutex != 0 {
				Xsqlite3_mutex_free(tls, (*TwinShmNode)(unsafe.Pointer(p)).Fmutex)
			}
			i = 0
			for {
				if !(i < (*TwinShmNode)(unsafe.Pointer(p)).FnRegion) {
					break
				}
				bRc = (*(*func(*libc.TLS, TLPCVOID) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(59)].FpCurrent})))(tls, (*(*TShmRegion)(unsafe.Pointer((*TwinShmNode)(unsafe.Pointer(p)).FaRegion + uintptr(i)*8))).FpMap)
				_ = bRc
				bRc = (*(*func(*libc.TLS, THANDLE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(3)].FpCurrent})))(tls, (*(*TShmRegion)(unsafe.Pointer((*TwinShmNode)(unsafe.Pointer(p)).FaRegion + uintptr(i)*8))).FhMap)
				_ = bRc
				goto _2
			_2:
				;
				i++
			}
			if (*TwinShmNode)(unsafe.Pointer(p)).FhFile.Fh != libc.UintptrFromInt32(0) && (*TwinShmNode)(unsafe.Pointer(p)).FhFile.Fh != uintptr(int32(-libc.Int32FromInt32(1))) {
				_winClose(tls, p+8)
			}
			if deleteFlag != 0 {
				_sqlite3BeginBenignMalloc(tls)
				_winDelete(tls, pVfs, (*TwinShmNode)(unsafe.Pointer(p)).FzFilename, 0)
				_sqlite3EndBenignMalloc(tls)
			}
			*(*uintptr)(unsafe.Pointer(pp)) = (*TwinShmNode)(unsafe.Pointer(p)).FpNext
			Xsqlite3_free(tls, (*TwinShmNode)(unsafe.Pointer(p)).FaRegion)
			Xsqlite3_free(tls, p)
		} else {
			pp = p + 100
		}
	}
}

// C documentation
//
//	/*
//	** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
//	** take it now. Return SQLITE_OK if successful, or an SQLite error
//	** code otherwise.
//	**
//	** If the DMS cannot be locked because this is a readonly_shm=1
//	** connection and no other process already holds a lock, return
//	** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1.
//	*/
func _winLockSharedMemory(tls *libc.TLS, pShmNode uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _winShmSystemLock(tls, pShmNode, int32(WINSHM_WRLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
	if rc == SQLITE_OK {
		if (*TwinShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 {
			(*TwinShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked = uint8(1)
			_winShmSystemLock(tls, pShmNode, int32(WINSHM_UNLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
			return libc.Int32FromInt32(SQLITE_READONLY) | libc.Int32FromInt32(5)<<libc.Int32FromInt32(8)
		} else {
			if _winTruncate(tls, pShmNode+8, 0) != 0 {
				_winShmSystemLock(tls, pShmNode, int32(WINSHM_UNLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
				return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(18)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+4946, (*TwinShmNode)(unsafe.Pointer(pShmNode)).FzFilename, int32(50554))
			}
		}
	}
	if rc == SQLITE_OK {
		_winShmSystemLock(tls, pShmNode, int32(WINSHM_UNLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
	}
	return _winShmSystemLock(tls, pShmNode, int32(WINSHM_RDLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
}

// C documentation
//
//	/*
//	** Open the shared-memory area associated with database file pDbFd.
//	**
//	** When opening a new shared-memory file, if no other instances of that
//	** file are currently open, in this process or in other processes, then
//	** the file must be truncated to zero length or have its header cleared.
//	*/
func _winOpenSharedMemory(tls *libc.TLS, pDbFd uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var inFlags, nName, rc int32
	var p, pNew, pShmNode uintptr
	var _ /* outFlags at bp+0 */ int32
	_, _, _, _, _, _ = inFlags, nName, p, pNew, pShmNode, rc /* The connection to be opened */
	pShmNode = uintptr(0)                                    /* The underlying mmapped file */
	rc = SQLITE_OK                                           /* Size of zName in bytes */
	/* Not previously opened */
	/* Allocate space for the new sqlite3_shm object.  Also speculatively
	 ** allocate space for a new winShmNode and filename.
	 */
	p = _sqlite3MallocZero(tls, uint64(16))
	if p == uintptr(0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	nName = _sqlite3Strlen30(tls, (*TwinFile)(unsafe.Pointer(pDbFd)).FzPath)
	pNew = _sqlite3MallocZero(tls, uint64(uint32(104)+uint32(uint32(nName))+uint32(17)))
	if pNew == uintptr(0) {
		Xsqlite3_free(tls, p)
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	(*TwinShmNode)(unsafe.Pointer(pNew)).FzFilename = pNew + 1*104
	Xsqlite3_snprintf(tls, nName+int32(15), (*TwinShmNode)(unsafe.Pointer(pNew)).FzFilename, __ccgo_ts+4966, libc.VaList(bp+16, (*TwinFile)(unsafe.Pointer(pDbFd)).FzPath))
	/* Look to see if there is an existing winShmNode that can be used.
	 ** If no matching winShmNode currently exists, create a new one.
	 */
	_winShmEnterMutex(tls)
	pShmNode = _winShmNodeList
	for {
		if !(pShmNode != 0) {
			break
		}
		/* TBD need to come up with better match here.  Perhaps
		 ** use FILE_ID_BOTH_DIR_INFO Structure.
		 */
		if _sqlite3StrICmp(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).FzFilename, (*TwinShmNode)(unsafe.Pointer(pNew)).FzFilename) == 0 {
			break
		}
		goto _1
	_1:
		;
		pShmNode = (*TwinShmNode)(unsafe.Pointer(pShmNode)).FpNext
	}
	if pShmNode != 0 {
		Xsqlite3_free(tls, pNew)
	} else {
		inFlags = int32(SQLITE_OPEN_WAL)
		*(*int32)(unsafe.Pointer(bp)) = 0
		pShmNode = pNew
		pNew = uintptr(0)
		(*TwinFile)(unsafe.Pointer(pShmNode + 8)).Fh = uintptr(int32(-libc.Int32FromInt32(1)))
		(*TwinShmNode)(unsafe.Pointer(pShmNode)).FpNext = _winShmNodeList
		_winShmNodeList = pShmNode
		if _sqlite3Config.FbCoreMutex != 0 {
			(*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
			if (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex == uintptr(0) {
				rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
				goto shm_open_err
			}
		}
		if 0 == Xsqlite3_uri_boolean(tls, (*TwinFile)(unsafe.Pointer(pDbFd)).FzPath, __ccgo_ts+4973, 0) {
			inFlags |= libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE)
		} else {
			inFlags |= int32(SQLITE_OPEN_READONLY)
		}
		rc = _winOpen(tls, (*TwinFile)(unsafe.Pointer(pDbFd)).FpVfs, (*TwinShmNode)(unsafe.Pointer(pShmNode)).FzFilename, pShmNode+8, inFlags, bp)
		if rc != SQLITE_OK {
			rc = _winLogErrorAtLine(tls, rc, (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+4986, (*TwinShmNode)(unsafe.Pointer(pShmNode)).FzFilename, int32(50636))
			goto shm_open_err
		}
		if *(*int32)(unsafe.Pointer(bp)) == int32(SQLITE_OPEN_READONLY) {
			(*TwinShmNode)(unsafe.Pointer(pShmNode)).FisReadonly = uint8(1)
		}
		rc = _winLockSharedMemory(tls, pShmNode)
		if rc != SQLITE_OK && rc != libc.Int32FromInt32(SQLITE_READONLY)|libc.Int32FromInt32(5)<<libc.Int32FromInt32(8) {
			goto shm_open_err
		}
	}
	/* Make the new connection a child of the winShmNode */
	(*TwinShm1)(unsafe.Pointer(p)).FpShmNode = pShmNode
	(*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRef++
	(*TwinFile)(unsafe.Pointer(pDbFd)).FpShm = p
	_winShmLeaveMutex(tls)
	/* The reference count on pShmNode has already been incremented under
	 ** the cover of the winShmEnterMutex() mutex and the pointer from the
	 ** new (struct winShm) object to the pShmNode has been set. All that is
	 ** left to do is to link the new object into the linked list starting
	 ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex
	 ** mutex.
	 */
	Xsqlite3_mutex_enter(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	(*TwinShm1)(unsafe.Pointer(p)).FpNext = (*TwinShmNode)(unsafe.Pointer(pShmNode)).FpFirst
	(*TwinShmNode)(unsafe.Pointer(pShmNode)).FpFirst = p
	Xsqlite3_mutex_leave(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	return rc
	/* Jump here on any error */
	goto shm_open_err
shm_open_err:
	;
	_winShmSystemLock(tls, pShmNode, int32(WINSHM_UNLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
	_winShmPurge(tls, (*TwinFile)(unsafe.Pointer(pDbFd)).FpVfs, 0) /* This call frees pShmNode if required */
	Xsqlite3_free(tls, p)
	Xsqlite3_free(tls, pNew)
	_winShmLeaveMutex(tls)
	return rc
}

// C documentation
//
//	/*
//	** Close a connection to shared-memory.  Delete the underlying
//	** storage if deleteFlag is true.
//	*/
func _winShmUnmap(tls *libc.TLS, fd uintptr, deleteFlag int32) (r int32) {
	var p, pDbFd, pShmNode, pp uintptr
	_, _, _, _ = p, pDbFd, pShmNode, pp /* For looping over sibling connections */
	pDbFd = fd
	p = (*TwinFile)(unsafe.Pointer(pDbFd)).FpShm
	if p == uintptr(0) {
		return SQLITE_OK
	}
	pShmNode = (*TwinShm)(unsafe.Pointer(p)).FpShmNode
	/* Remove connection p from the set of connections associated
	 ** with pShmNode */
	Xsqlite3_mutex_enter(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	pp = pShmNode + 96
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != p) {
			break
		}
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 4
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*TwinShm)(unsafe.Pointer(p)).FpNext
	/* Free the connection p */
	Xsqlite3_free(tls, p)
	(*TwinFile)(unsafe.Pointer(pDbFd)).FpShm = uintptr(0)
	Xsqlite3_mutex_leave(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	/* If pShmNode->nRef has reached 0, then close the underlying
	 ** shared-memory file, too */
	_winShmEnterMutex(tls)
	(*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRef--
	if (*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRef == 0 {
		_winShmPurge(tls, (*TwinFile)(unsafe.Pointer(pDbFd)).FpVfs, deleteFlag)
	}
	_winShmLeaveMutex(tls)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Change the lock state for a shared-memory segment.
//	*/
func _winShmLock(tls *libc.TLS, fd uintptr, ofst int32, n int32, flags int32) (r int32) {
	var allMask, allShared, mask Tu16
	var p, pDbFd, pShmNode, pX, p2, p3, p5, p7 uintptr
	var rc int32
	_, _, _, _, _, _, _, _, _, _, _, _ = allMask, allShared, mask, p, pDbFd, pShmNode, pX, rc, p2, p3, p5, p7
	pDbFd = fd /* Connection holding shared memory */
	p = (*TwinFile)(unsafe.Pointer(pDbFd)).FpShm
	rc = SQLITE_OK /* Mask of locks to take or release */
	if p == uintptr(0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(20)<<libc.Int32FromInt32(8)
	}
	pShmNode = (*TwinShm)(unsafe.Pointer(p)).FpShmNode
	if pShmNode == uintptr(0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(20)<<libc.Int32FromInt32(8)
	}
	mask = uint16(libc.Uint32FromUint32(1)<<(ofst+n) - libc.Uint32FromUint32(1)<<ofst)
	Xsqlite3_mutex_enter(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	if flags&int32(SQLITE_SHM_UNLOCK) != 0 {
		allMask = uint16(0) /* Mask of locks held by siblings */
		/* See if any siblings hold this same lock */
		pX = (*TwinShmNode)(unsafe.Pointer(pShmNode)).FpFirst
		for {
			if !(pX != 0) {
				break
			}
			if pX == p {
				goto _1
			}
			allMask = Tu16(int32(allMask) | int32((*TwinShm)(unsafe.Pointer(pX)).FsharedMask))
			goto _1
		_1:
			;
			pX = (*TwinShm)(unsafe.Pointer(pX)).FpNext
		}
		/* Unlock the system-level locks */
		if int32(int32(mask))&int32(int32(allMask)) == 0 {
			rc = _winShmSystemLock(tls, pShmNode, int32(WINSHM_UNLCK), ofst+(libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4), n)
		} else {
			rc = SQLITE_OK
		}
		/* Undo the local locks */
		if rc == SQLITE_OK {
			p2 = p + 12
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^int32(int32(mask)))
			p3 = p + 10
			*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^int32(int32(mask)))
		}
	} else {
		if flags&int32(SQLITE_SHM_SHARED) != 0 {
			allShared = uint16(0) /* Union of locks held by connections other than "p" */
			/* Find out which shared locks are already held by sibling connections.
			 ** If any sibling already holds an exclusive lock, go ahead and return
			 ** SQLITE_BUSY.
			 */
			pX = (*TwinShmNode)(unsafe.Pointer(pShmNode)).FpFirst
			for {
				if !(pX != 0) {
					break
				}
				if int32((*TwinShm)(unsafe.Pointer(pX)).FexclMask)&int32(int32(mask)) != 0 {
					rc = int32(SQLITE_BUSY)
					break
				}
				allShared = Tu16(int32(allShared) | int32((*TwinShm)(unsafe.Pointer(pX)).FsharedMask))
				goto _4
			_4:
				;
				pX = (*TwinShm)(unsafe.Pointer(pX)).FpNext
			}
			/* Get shared locks at the system level, if necessary */
			if rc == SQLITE_OK {
				if int32(int32(allShared))&int32(int32(mask)) == 0 {
					rc = _winShmSystemLock(tls, pShmNode, int32(WINSHM_RDLCK), ofst+(libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4), n)
				} else {
					rc = SQLITE_OK
				}
			}
			/* Get the local shared locks */
			if rc == SQLITE_OK {
				p5 = p + 10
				*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | int32(int32(mask)))
			}
		} else {
			/* Make sure no sibling connections hold locks that will block this
			 ** lock.  If any do, return SQLITE_BUSY right away.
			 */
			pX = (*TwinShmNode)(unsafe.Pointer(pShmNode)).FpFirst
			for {
				if !(pX != 0) {
					break
				}
				if int32((*TwinShm)(unsafe.Pointer(pX)).FexclMask)&int32(int32(mask)) != 0 || int32((*TwinShm)(unsafe.Pointer(pX)).FsharedMask)&int32(int32(mask)) != 0 {
					rc = int32(SQLITE_BUSY)
					break
				}
				goto _6
			_6:
				;
				pX = (*TwinShm)(unsafe.Pointer(pX)).FpNext
			}
			/* Get the exclusive locks at the system level.  Then if successful
			 ** also mark the local connection as being locked.
			 */
			if rc == SQLITE_OK {
				rc = _winShmSystemLock(tls, pShmNode, int32(WINSHM_WRLCK), ofst+(libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4), n)
				if rc == SQLITE_OK {
					p7 = p + 12
					*(*Tu16)(unsafe.Pointer(p7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p7))) | int32(int32(mask)))
				}
			}
		}
	}
	Xsqlite3_mutex_leave(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Implement a memory barrier or memory fence on shared memory.
//	**
//	** All loads and stores begun before the barrier must complete before
//	** any load or store begun after the barrier.
//	*/
func _winShmBarrier(tls *libc.TLS, fd uintptr) {
	_ = fd
	_sqlite3MemoryBarrier(tls) /* compiler-defined memory barrier */
	_winShmEnterMutex(tls)     /* Also mutex, for redundancy */
	_winShmLeaveMutex(tls)
}

// C documentation
//
//	/*
//	** This function is called to obtain a pointer to region iRegion of the
//	** shared-memory associated with the database file fd. Shared-memory regions
//	** are numbered starting from zero. Each shared-memory region is szRegion
//	** bytes in size.
//	**
//	** If an error occurs, an error code is returned and *pp is set to NULL.
//	**
//	** Otherwise, if the isWrite parameter is 0 and the requested shared-memory
//	** region has not been allocated (by any client, including one running in a
//	** separate process), then *pp is set to NULL and SQLITE_OK returned. If
//	** isWrite is non-zero and the requested shared-memory region has not yet
//	** been allocated, it is allocated by this function.
//	**
//	** If the shared-memory region has already been allocated or is allocated by
//	** this call as described above, then it is mapped into this processes
//	** address space (if it is not already), *pp is set to point to the mapped
//	** memory and SQLITE_OK returned.
//	*/
func _winShmMap(tls *libc.TLS, fd uintptr, iRegion int32, szRegion int32, isWrite int32, pp uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var apNew, p, pDbFd, pMap, pShm, pShmNode uintptr
	var flags, protect TDWORD
	var hMap THANDLE
	var iOffset, iOffset1, iOffsetShift, iOffsetShift1, nByte, rc int32
	var _ /* sz at bp+0 */ Tsqlite3_int64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = apNew, flags, hMap, iOffset, iOffset1, iOffsetShift, iOffsetShift1, nByte, p, pDbFd, pMap, pShm, pShmNode, protect, rc
	pDbFd = fd
	pShm = (*TwinFile)(unsafe.Pointer(pDbFd)).FpShm
	protect = uint32(PAGE_READWRITE)
	flags = uint32(libc.Int32FromInt32(SECTION_MAP_WRITE) | libc.Int32FromInt32(SECTION_MAP_READ))
	rc = SQLITE_OK
	if !(pShm != 0) {
		rc = _winOpenSharedMemory(tls, pDbFd)
		if rc != SQLITE_OK {
			return rc
		}
		pShm = (*TwinFile)(unsafe.Pointer(pDbFd)).FpShm
	}
	pShmNode = (*TwinShm)(unsafe.Pointer(pShm)).FpShmNode
	Xsqlite3_mutex_enter(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	if (*TwinShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked != 0 {
		rc = _winLockSharedMemory(tls, pShmNode)
		if rc != SQLITE_OK {
			goto shmpage_out
		}
		(*TwinShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked = uint8(0)
	}
	if (*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRegion <= iRegion { /* New aRegion[] array */
		nByte = (iRegion + int32(1)) * szRegion /* Current size of wal-index file */
		(*TwinShmNode)(unsafe.Pointer(pShmNode)).FszRegion = szRegion
		/* The requested region is not mapped into this processes address space.
		 ** Check to see if it has been allocated (i.e. if the wal-index file is
		 ** large enough to contain the requested region).
		 */
		rc = _winFileSize(tls, pShmNode+8, bp)
		if rc != SQLITE_OK {
			rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(19)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+4997, (*TwinFile)(unsafe.Pointer(pDbFd)).FzPath, int32(50907))
			goto shmpage_out
		}
		if *(*Tsqlite3_int64)(unsafe.Pointer(bp)) < int64(int64(nByte)) {
			/* The requested memory region does not exist. If isWrite is set to
			 ** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
			 **
			 ** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
			 ** the requested memory region.
			 */
			if !(isWrite != 0) {
				goto shmpage_out
			}
			rc = _winTruncate(tls, pShmNode+8, int64(int64(nByte)))
			if rc != SQLITE_OK {
				rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(19)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+5008, (*TwinFile)(unsafe.Pointer(pDbFd)).FzPath, int32(50922))
				goto shmpage_out
			}
		}
		/* Map the requested memory region into this processes address space. */
		apNew = Xsqlite3_realloc64(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).FaRegion, uint64(uint32(iRegion+libc.Int32FromInt32(1))*uint32(8)))
		if !(apNew != 0) {
			rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
			goto shmpage_out
		}
		(*TwinShmNode)(unsafe.Pointer(pShmNode)).FaRegion = apNew
		if (*TwinShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 {
			protect = uint32(PAGE_READONLY)
			flags = uint32(SECTION_MAP_READ)
		}
		for (*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRegion <= iRegion {
			hMap = libc.UintptrFromInt32(0) /* file-mapping handle */
			pMap = uintptr(0)               /* Mapped memory region */
			hMap = (*(*func(*libc.TLS, THANDLE, TLPSECURITY_ATTRIBUTES, TDWORD, TDWORD, TDWORD, TLPCWSTR) THANDLE)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(7)].FpCurrent})))(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).FhFile.Fh, libc.UintptrFromInt32(0), protect, uint32(0), uint32(uint32(nByte)), libc.UintptrFromInt32(0))
			if hMap != 0 {
				iOffset = (*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRegion * szRegion
				iOffsetShift = int32(uint32(uint32(iOffset)) % _winSysInfo.FdwAllocationGranularity)
				pMap = (*(*func(*libc.TLS, THANDLE, TDWORD, TDWORD, TDWORD, TSIZE_T) TLPVOID)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(49)].FpCurrent})))(tls, hMap, flags, uint32(0), uint32(iOffset-iOffsetShift), uint32(szRegion+iOffsetShift))
			}
			if !(pMap != 0) {
				(*TwinShmNode)(unsafe.Pointer(pShmNode)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
				rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(21)<<libc.Int32FromInt32(8), (*TwinShmNode)(unsafe.Pointer(pShmNode)).FlastErrno, __ccgo_ts+5019, (*TwinFile)(unsafe.Pointer(pDbFd)).FzPath, int32(50981))
				if hMap != 0 {
					(*(*func(*libc.TLS, THANDLE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(3)].FpCurrent})))(tls, hMap)
				}
				goto shmpage_out
			}
			(*(*TShmRegion)(unsafe.Pointer((*TwinShmNode)(unsafe.Pointer(pShmNode)).FaRegion + uintptr((*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRegion)*8))).FpMap = pMap
			(*(*TShmRegion)(unsafe.Pointer((*TwinShmNode)(unsafe.Pointer(pShmNode)).FaRegion + uintptr((*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRegion)*8))).FhMap = hMap
			(*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRegion++
		}
	}
	goto shmpage_out
shmpage_out:
	;
	if (*TwinShmNode)(unsafe.Pointer(pShmNode)).FnRegion > iRegion {
		iOffset1 = iRegion * szRegion
		iOffsetShift1 = int32(uint32(uint32(iOffset1)) % _winSysInfo.FdwAllocationGranularity)
		p = (*(*TShmRegion)(unsafe.Pointer((*TwinShmNode)(unsafe.Pointer(pShmNode)).FaRegion + uintptr(iRegion)*8))).FpMap
		*(*uintptr)(unsafe.Pointer(pp)) = p + uintptr(iOffsetShift1)
	} else {
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	}
	if (*TwinShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 && rc == SQLITE_OK {
		rc = int32(SQLITE_READONLY)
	}
	Xsqlite3_mutex_leave(tls, (*TwinShmNode)(unsafe.Pointer(pShmNode)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Cleans up the mapped region of the specified file, if any.
//	*/
func _winUnmapfile(tls *libc.TLS, pFile uintptr) (r int32) {
	if (*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion != 0 {
		if !((*(*func(*libc.TLS, TLPCVOID) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(59)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion) != 0) {
			(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(24)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+5030, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(51030))
		}
		(*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion = uintptr(0)
		(*TwinFile)(unsafe.Pointer(pFile)).FmmapSize = 0
	}
	if (*TwinFile)(unsafe.Pointer(pFile)).FhMap != libc.UintptrFromInt32(0) {
		if !((*(*func(*libc.TLS, THANDLE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(3)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFile)).FhMap) != 0) {
			(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(24)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+5044, (*TwinFile)(unsafe.Pointer(pFile)).FzPath, int32(51041))
		}
		(*TwinFile)(unsafe.Pointer(pFile)).FhMap = libc.UintptrFromInt32(0)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Memory map or remap the file opened by file-descriptor pFd (if the file
//	** is already mapped, the existing mapping is replaced by the new). Or, if
//	** there already exists a mapping for this file, and there are still
//	** outstanding xFetch() references to it, this function is a no-op.
//	**
//	** If parameter nByte is non-negative, then it is the requested size of
//	** the mapping to create. Otherwise, if nByte is less than zero, then the
//	** requested size is the size of the file on disk. The actual size of the
//	** created mapping is either the requested size or the value configured
//	** using SQLITE_FCNTL_MMAP_SIZE, whichever is smaller.
//	**
//	** SQLITE_OK is returned if no error occurs (even if the mapping is not
//	** recreated as a result of outstanding references) or an SQLite error
//	** code otherwise.
//	*/
func _winMapfile(tls *libc.TLS, pFd uintptr, nByte Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var flags, protect TDWORD
	var pNew uintptr
	var rc int32
	var _ /* nMap at bp+0 */ Tsqlite3_int64
	_, _, _, _ = flags, pNew, protect, rc
	*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = nByte
	if (*TwinFile)(unsafe.Pointer(pFd)).FnFetchOut > 0 {
		return SQLITE_OK
	}
	if *(*Tsqlite3_int64)(unsafe.Pointer(bp)) < 0 {
		rc = _winFileSize(tls, pFd, bp)
		if rc != 0 {
			return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
		}
	}
	if *(*Tsqlite3_int64)(unsafe.Pointer(bp)) > (*TwinFile)(unsafe.Pointer(pFd)).FmmapSizeMax {
		*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = (*TwinFile)(unsafe.Pointer(pFd)).FmmapSizeMax
	}
	*(*Tsqlite3_int64)(unsafe.Pointer(bp)) &= ^int64(_winSysInfo.FdwPageSize - libc.Uint32FromInt32(1))
	if *(*Tsqlite3_int64)(unsafe.Pointer(bp)) == 0 && (*TwinFile)(unsafe.Pointer(pFd)).FmmapSize > 0 {
		_winUnmapfile(tls, pFd)
	}
	if *(*Tsqlite3_int64)(unsafe.Pointer(bp)) != (*TwinFile)(unsafe.Pointer(pFd)).FmmapSize {
		pNew = uintptr(0)
		protect = uint32(PAGE_READONLY)
		flags = uint32(SECTION_MAP_READ)
		_winUnmapfile(tls, pFd)
		(*TwinFile)(unsafe.Pointer(pFd)).FhMap = (*(*func(*libc.TLS, THANDLE, TLPSECURITY_ATTRIBUTES, TDWORD, TDWORD, TDWORD, TLPCWSTR) THANDLE)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(7)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFd)).Fh, libc.UintptrFromInt32(0), protect, uint32(*(*Tsqlite3_int64)(unsafe.Pointer(bp))>>libc.Int32FromInt32(32)&libc.Int64FromUint32(0xffffffff)), uint32(*(*Tsqlite3_int64)(unsafe.Pointer(bp))&libc.Int64FromUint32(0xffffffff)), libc.UintptrFromInt32(0))
		if (*TwinFile)(unsafe.Pointer(pFd)).FhMap == libc.UintptrFromInt32(0) {
			(*TwinFile)(unsafe.Pointer(pFd)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(24)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFd)).FlastErrno, __ccgo_ts+5058, (*TwinFile)(unsafe.Pointer(pFd)).FzPath, int32(51118))
			/* Log the error, but continue normal operation using xRead/xWrite */
			return SQLITE_OK
		}
		pNew = (*(*func(*libc.TLS, THANDLE, TDWORD, TDWORD, TDWORD, TSIZE_T) TLPVOID)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(49)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFd)).FhMap, flags, uint32(0), uint32(0), uint32(*(*Tsqlite3_int64)(unsafe.Pointer(bp))))
		if pNew == libc.UintptrFromInt32(0) {
			(*(*func(*libc.TLS, THANDLE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(3)].FpCurrent})))(tls, (*TwinFile)(unsafe.Pointer(pFd)).FhMap)
			(*TwinFile)(unsafe.Pointer(pFd)).FhMap = libc.UintptrFromInt32(0)
			(*TwinFile)(unsafe.Pointer(pFd)).FlastErrno = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
			rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(24)<<libc.Int32FromInt32(8), (*TwinFile)(unsafe.Pointer(pFd)).FlastErrno, __ccgo_ts+5070, (*TwinFile)(unsafe.Pointer(pFd)).FzPath, int32(51136))
			/* Log the error, but continue normal operation using xRead/xWrite */
			return SQLITE_OK
		}
		(*TwinFile)(unsafe.Pointer(pFd)).FpMapRegion = pNew
		(*TwinFile)(unsafe.Pointer(pFd)).FmmapSize = *(*Tsqlite3_int64)(unsafe.Pointer(bp))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If possible, return a pointer to a mapping of file fd starting at offset
//	** iOff. The mapping must be valid for at least nAmt bytes.
//	**
//	** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
//	** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
//	** Finally, if an error does occur, return an SQLite error code. The final
//	** value of *pp is undefined in this case.
//	**
//	** If this function does return a pointer, the caller must eventually
//	** release the reference by calling winUnfetch().
//	*/
func _winFetch(tls *libc.TLS, fd uintptr, iOff Ti64, nAmt int32, pp uintptr) (r int32) {
	var nEofBuffer, rc int32
	var pFd uintptr
	_, _, _ = nEofBuffer, pFd, rc
	pFd = fd /* The underlying database file */
	*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	if (*TwinFile)(unsafe.Pointer(pFd)).FmmapSizeMax > 0 {
		/* Ensure that there is always at least a 256 byte buffer of addressable
		 ** memory following the returned page. If the database is corrupt,
		 ** SQLite may overread the page slightly (in practice only a few bytes,
		 ** but 256 is safe, round, number).  */
		nEofBuffer = int32(256)
		if (*TwinFile)(unsafe.Pointer(pFd)).FpMapRegion == uintptr(0) {
			rc = _winMapfile(tls, pFd, int64(-int32(1)))
			if rc != SQLITE_OK {
				return rc
			}
		}
		if (*TwinFile)(unsafe.Pointer(pFd)).FmmapSize >= iOff+int64(int64(nAmt))+int64(int64(nEofBuffer)) {
			*(*uintptr)(unsafe.Pointer(pp)) = (*TwinFile)(unsafe.Pointer(pFd)).FpMapRegion + uintptr(iOff)
			(*TwinFile)(unsafe.Pointer(pFd)).FnFetchOut++
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If the third argument is non-NULL, then this function releases a
//	** reference obtained by an earlier call to winFetch(). The second
//	** argument passed to this function must be the same as the corresponding
//	** argument that was passed to the winFetch() invocation.
//	**
//	** Or, if the third argument is NULL, then this function is being called
//	** to inform the VFS layer that, according to POSIX, any existing mapping
//	** may now be invalid and should be unmapped.
//	*/
func _winUnfetch(tls *libc.TLS, fd uintptr, iOff Ti64, p uintptr) (r int32) {
	var pFd uintptr
	_ = pFd
	pFd = fd /* The underlying database file */
	/* If p==0 (unmap the entire file) then there must be no outstanding
	 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
	 ** then there must be at least one outstanding.  */
	/* If p!=0, it must match the iOff value. */
	if p != 0 {
		(*TwinFile)(unsafe.Pointer(pFd)).FnFetchOut--
	} else {
		/* FIXME:  If Windows truly always prevents truncating or deleting a
		 ** file while a mapping is held, then the following winUnmapfile() call
		 ** is unnecessary can be omitted - potentially improving
		 ** performance.  */
		_winUnmapfile(tls, pFd)
	}
	return SQLITE_OK
}

/*
** Here ends the implementation of all sqlite3_file methods.
**
********************** End sqlite3_file Methods *******************************
******************************************************************************/

// C documentation
//
//	/*
//	** This vector defines all the methods that can operate on an
//	** sqlite3_file for win32.
//	*/
var _winIoMethod = Tsqlite3_io_methods{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_winIoMethod)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_winClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_winRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_winWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_winTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_winSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_winFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_winLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_winUnlock)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_winCheckReservedLock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_winFileControl)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_winSectorSize)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_winDeviceCharacteristics)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_winShmMap)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_winShmLock)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_winShmBarrier)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_winShmUnmap)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_winFetch)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_winUnfetch)
}

// C documentation
//
//	/*
//	** This vector defines all the methods that can operate on an
//	** sqlite3_file for win32 without performing any locking.
//	*/
var _winIoNolockMethod = Tsqlite3_io_methods{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_winIoNolockMethod)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_winClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_winRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_winWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_winTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_winSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_winFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_winNolockLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_winNolockUnlock)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_winNolockCheckReservedLock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_winFileControl)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_winSectorSize)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_winDeviceCharacteristics)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_winShmMap)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_winShmLock)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_winShmBarrier)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_winShmUnmap)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_winFetch)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_winUnfetch)
}

var _winAppData = TwinVfsAppData{
	FpMethod: uintptr(unsafe.Pointer(&_winIoMethod)),
}

var _winNolockAppData = TwinVfsAppData{
	FpMethod: uintptr(unsafe.Pointer(&_winIoNolockMethod)),
	FbNoLock: int32(1),
}

/****************************************************************************
**************************** sqlite3_vfs methods ****************************
**
** This division contains the implementation of methods on the
** sqlite3_vfs object.
 */

// C documentation
//
//	/*
//	** Convert a UTF-8 filename into whatever form the underlying
//	** operating system wants filenames in.  Space to hold the result
//	** is obtained from malloc and must be freed by the calling
//	** function.
//	*/
func _winConvertFromUtf8Filename(tls *libc.TLS, zFilename uintptr) (r uintptr) {
	var zConverted uintptr
	_ = zConverted
	zConverted = uintptr(0)
	if int32(1) != 0 {
		zConverted = _winUtf8ToUnicode(tls, zFilename)
	} else {
		zConverted = _winUtf8ToMbcs(tls, zFilename, (*(*func(*libc.TLS) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls))
	}
	/* caller will handle out of memory */
	return zConverted
}

// C documentation
//
//	/*
//	** This function returns non-zero if the specified UTF-8 string buffer
//	** ends with a directory separator character or one was successfully
//	** added to it.
//	*/
func _winMakeEndInDirSep(tls *libc.TLS, nBuf int32, zBuf uintptr) (r int32) {
	var nLen int32
	_ = nLen
	if zBuf != 0 {
		nLen = _sqlite3Strlen30(tls, zBuf)
		if nLen > 0 {
			if int32(*(*int8)(unsafe.Pointer(zBuf + uintptr(nLen-int32(1))))) == int32('/') || int32(*(*int8)(unsafe.Pointer(zBuf + uintptr(nLen-int32(1))))) == int32('\\') {
				return int32(1)
			} else {
				if nLen+int32(1) < nBuf {
					*(*int8)(unsafe.Pointer(zBuf + uintptr(nLen))) = int8('\\')
					*(*int8)(unsafe.Pointer(zBuf + uintptr(nLen+int32(1)))) = int8('\000')
					return int32(1)
				}
			}
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** If sqlite3_temp_directory is defined, take the mutex and return true.
//	**
//	** If sqlite3_temp_directory is NULL (undefined), omit the mutex and
//	** return false.
//	*/
func _winTempDirDefined(tls *libc.TLS) (r int32) {
	Xsqlite3_mutex_enter(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
	if Xsqlite3_temp_directory != uintptr(0) {
		return int32(1)
	}
	Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
	return 0
}

// C documentation
//
//	/*
//	** Create a temporary file name and store the resulting pointer into pzBuf.
//	** The pointer returned in pzBuf must be freed via sqlite3_free().
//	*/
func _winGetTempname(tls *libc.TLS, pVfs uintptr, pzBuf uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, j Tsize_t
	var nBuf, nDir, nDirLen, nLen, nMax, nPre int32
	var pid TDWORD
	var zBuf, zMbcsPath, zMulti, zUtf8, p2 uintptr
	var zWidePath TLPWSTR
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, j, nBuf, nDir, nDirLen, nLen, nMax, nPre, pid, zBuf, zMbcsPath, zMulti, zUtf8, zWidePath, p2
	nPre = _sqlite3Strlen30(tls, __ccgo_ts+5082)
	/* It's odd to simulate an io-error here, but really this is just
	 ** using the io-error infrastructure to test that SQLite handles this
	 ** function failing.
	 */
	/* Allocate a temporary buffer to store the fully qualified file
	 ** name for the temporary file.  If this fails, we cannot continue.
	 */
	nMax = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname
	nBuf = nMax + int32(2)
	zBuf = _sqlite3MallocZero(tls, uint64(uint64(nBuf)))
	if !(zBuf != 0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	/* Figure out the effective temporary directory.  First, check if one
	 ** has been explicitly set by the application; otherwise, use the one
	 ** configured by the operating system.
	 */
	nDir = nMax - (nPre + int32(15))
	if _winTempDirDefined(tls) != 0 {
		nDirLen = _sqlite3Strlen30(tls, Xsqlite3_temp_directory)
		if nDirLen > 0 {
			if !(int32(*(*int8)(unsafe.Pointer(Xsqlite3_temp_directory + uintptr(nDirLen-int32(1))))) == int32('/') || int32(*(*int8)(unsafe.Pointer(Xsqlite3_temp_directory + uintptr(nDirLen-int32(1))))) == int32('\\')) {
				nDirLen++
			}
			if nDirLen > nDir {
				Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
				Xsqlite3_free(tls, zBuf)
				return _winLogErrorAtLine(tls, int32(SQLITE_ERROR), uint32(0), __ccgo_ts+5090, uintptr(0), int32(51444))
			}
			Xsqlite3_snprintf(tls, nMax, zBuf, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_temp_directory))
		}
		Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
	} else {
		if int32(1) != 0 {
			zWidePath = _sqlite3MallocZero(tls, uint64(uint32(uint32(nMax))*uint32(2)))
			if !(zWidePath != 0) {
				Xsqlite3_free(tls, zBuf)
				return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
			}
			if (*(*func(*libc.TLS, TDWORD, TLPWSTR) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(32)].FpCurrent})))(tls, uint32(uint32(nMax)), zWidePath) == uint32(0) {
				Xsqlite3_free(tls, zWidePath)
				Xsqlite3_free(tls, zBuf)
				return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(25)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+5106, uintptr(0), int32(51544))
			}
			zMulti = _winUnicodeToUtf8(tls, zWidePath)
			if zMulti != 0 {
				Xsqlite3_snprintf(tls, nMax, zBuf, __ccgo_ts+4709, libc.VaList(bp+8, zMulti))
				Xsqlite3_free(tls, zMulti)
				Xsqlite3_free(tls, zWidePath)
			} else {
				Xsqlite3_free(tls, zWidePath)
				Xsqlite3_free(tls, zBuf)
				return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
			}
		} else {
			zMbcsPath = _sqlite3MallocZero(tls, uint64(uint64(nMax)))
			if !(zMbcsPath != 0) {
				Xsqlite3_free(tls, zBuf)
				return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
			}
			if (*(*func(*libc.TLS, TDWORD, TLPSTR) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(31)].FpCurrent})))(tls, uint32(uint32(nMax)), zMbcsPath) == uint32(0) {
				Xsqlite3_free(tls, zBuf)
				return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(25)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+5122, uintptr(0), int32(51571))
			}
			zUtf8 = _winMbcsToUtf8(tls, zMbcsPath, (*(*func(*libc.TLS) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls))
			if zUtf8 != 0 {
				Xsqlite3_snprintf(tls, nMax, zBuf, __ccgo_ts+4709, libc.VaList(bp+8, zUtf8))
				Xsqlite3_free(tls, zUtf8)
			} else {
				Xsqlite3_free(tls, zBuf)
				return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
			}
		}
	}
	/*
	 ** Check to make sure the temporary directory ends with an appropriate
	 ** separator.  If it does not and there is not enough space left to add
	 ** one, fail.
	 */
	if !(_winMakeEndInDirSep(tls, nDir+int32(1), zBuf) != 0) {
		Xsqlite3_free(tls, zBuf)
		return _winLogErrorAtLine(tls, int32(SQLITE_ERROR), uint32(0), __ccgo_ts+5138, uintptr(0), int32(51595))
	}
	/*
	 ** Check that the output buffer is large enough for the temporary file
	 ** name in the following format:
	 **
	 **   "<temporary_directory>/etilqs_XXXXXXXXXXXXXXX\0\0"
	 **
	 ** If not, return SQLITE_ERROR.  The number 17 is used here in order to
	 ** account for the space used by the 15 character random suffix and the
	 ** two trailing NUL characters.  The final directory separator character
	 ** has already added if it was not already present.
	 */
	nLen = _sqlite3Strlen30(tls, zBuf)
	if nLen+nPre+int32(17) > nBuf {
		Xsqlite3_free(tls, zBuf)
		return _winLogErrorAtLine(tls, int32(SQLITE_ERROR), uint32(0), __ccgo_ts+5154, uintptr(0), int32(51613))
	}
	Xsqlite3_snprintf(tls, nBuf-int32(16)-nLen, zBuf+uintptr(nLen), __ccgo_ts+5082, 0)
	j = uint32(_sqlite3Strlen30(tls, zBuf))
	Xsqlite3_randomness(tls, int32(15), zBuf+uintptr(j))
	pid = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(17)].FpCurrent})))(tls)
	i = uint32(0)
	for {
		if !(i < uint32(15)) {
			break
		}
		p2 = zBuf + uintptr(j)
		*(*int8)(unsafe.Pointer(p2)) = int8(uint32(*(*int8)(unsafe.Pointer(p2))) + pid&libc.Uint32FromInt32(0xff))
		pid >>= uint32(8)
		*(*int8)(unsafe.Pointer(zBuf + uintptr(j))) = _zChars[uint32(uint8(*(*int8)(unsafe.Pointer(zBuf + uintptr(j)))))%(libc.Uint32FromInt64(63)-libc.Uint32FromInt32(1))]
		goto _1
	_1:
		;
		i++
		j++
	}
	*(*int8)(unsafe.Pointer(zBuf + uintptr(j))) = 0
	*(*int8)(unsafe.Pointer(zBuf + uintptr(j+uint32(1)))) = 0
	*(*uintptr)(unsafe.Pointer(pzBuf)) = zBuf
	return SQLITE_OK
}

var _zChars = [63]int8{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}

// C documentation
//
//	/*
//	** Return TRUE if the named file is really a directory.  Return false if
//	** it is something other than a directory, or if there is any kind of memory
//	** allocation failure.
//	*/
func _winIsDir(tls *libc.TLS, zConverted uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var attr TDWORD
	var rc, v1 int32
	var _ /* cnt at bp+4 */ int32
	var _ /* lastErrno at bp+0 */ TDWORD
	var _ /* sAttrData at bp+8 */ TWIN32_FILE_ATTRIBUTE_DATA
	_, _, _ = attr, rc, v1
	rc = 0
	if int32(1) != 0 {
		*(*int32)(unsafe.Pointer(bp + 4)) = 0
		libc.Xmemset(tls, bp+8, 0, uint32(36))
		for {
			v1 = (*(*func(*libc.TLS, TLPCWSTR, TGET_FILEEX_INFO_LEVELS, TLPVOID) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(22)].FpCurrent})))(tls, zConverted, _GetFileExInfoStandard, bp+8)
			rc = v1
			if !(!(v1 != 0) && _winRetryIoerr(tls, bp+4, bp) != 0) {
				break
			}
		}
		if !(rc != 0) {
			return 0 /* Invalid name? */
		}
		attr = (*(*TWIN32_FILE_ATTRIBUTE_DATA)(unsafe.Pointer(bp + 8))).FdwFileAttributes
	} else {
		attr = (*(*func(*libc.TLS, TLPCSTR) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(20)].FpCurrent})))(tls, zConverted)
	}
	return libc.BoolInt32(attr != uint32(-libc.Int32FromInt32(1)) && attr&uint32(FILE_ATTRIBUTE_DIRECTORY) != 0)
}

// C documentation
//
//	/*
//	** Open a file.
//	*/
func _winOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, id uintptr, flags int32, pOutFlags uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var dwCreationDisposition, dwDesiredAccess, dwFlagsAndAttributes, dwShareMode TDWORD
	var h THANDLE
	var isCreate, isDelete, isExclusive, isReadWrite, isReadonly, rc, rc2, rc21 int32
	var pAppData, pFile, zConverted, zUtf8Name, v1, p2, p3 uintptr
	var _ /* cnt at bp+4 */ int32
	var _ /* isRO at bp+12 */ int32
	var _ /* isRO at bp+16 */ int32
	var _ /* lastErrno at bp+0 */ TDWORD
	var _ /* zTmpname at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = dwCreationDisposition, dwDesiredAccess, dwFlagsAndAttributes, dwShareMode, h, isCreate, isDelete, isExclusive, isReadWrite, isReadonly, pAppData, pFile, rc, rc2, rc21, zConverted, zUtf8Name, v1, p2, p3
	*(*TDWORD)(unsafe.Pointer(bp)) = uint32(0)
	dwFlagsAndAttributes = uint32(0)
	pFile = id        /* Filename in OS encoding */
	zUtf8Name = zName /* Filename in UTF-8 encoding */
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	/* If argument zPath is a NULL pointer, this function is required to open
	 ** a temporary file. Use this buffer to store the file name in.
	 */
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0) /* For temporary filename, if necessary. */
	rc = SQLITE_OK                                   /* Function Return Code */
	isExclusive = flags & int32(SQLITE_OPEN_EXCLUSIVE)
	isDelete = flags & int32(SQLITE_OPEN_DELETEONCLOSE)
	isCreate = flags & int32(SQLITE_OPEN_CREATE)
	isReadonly = flags & int32(SQLITE_OPEN_READONLY)
	isReadWrite = flags & int32(SQLITE_OPEN_READWRITE)
	/* Check the following statements are true:
	 **
	 **   (a) Exactly one of the READWRITE and READONLY flags must be set, and
	 **   (b) if CREATE is set, then READWRITE must also be set, and
	 **   (c) if EXCLUSIVE is set, then CREATE must also be set.
	 **   (d) if DELETEONCLOSE is set, then CREATE must also be set.
	 */
	/* The main DB, main journal, WAL file and super-journal are never
	 ** automatically deleted. Nor are they ever temporary files.  */
	/* Assert that the upper layer has set one of the "file-type" flags. */
	libc.Xmemset(tls, pFile, 0, uint32(64))
	(*TwinFile)(unsafe.Pointer(pFile)).Fh = uintptr(int32(-libc.Int32FromInt32(1)))
	/* If the second argument to this function is NULL, generate a
	 ** temporary file name to use
	 */
	if !(zUtf8Name != 0) {
		rc = _winGetTempname(tls, pVfs, bp+8)
		if rc != SQLITE_OK {
			return rc
		}
		zUtf8Name = *(*uintptr)(unsafe.Pointer(bp + 8))
	}
	/* Database filenames are double-zero terminated if they are not
	 ** URIs with parameters.  Hence, they can always be passed into
	 ** sqlite3_uri_parameter().
	 */
	/* Convert the filename to the system encoding. */
	zConverted = _winConvertFromUtf8Filename(tls, zUtf8Name)
	if zConverted == uintptr(0) {
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	if _winIsDir(tls, zConverted) != 0 {
		Xsqlite3_free(tls, zConverted)
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		return libc.Int32FromInt32(SQLITE_CANTOPEN) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	if isReadWrite != 0 {
		dwDesiredAccess = libc.Uint32FromUint32(0x80000000) | uint32(libc.Int32FromInt32(0x40000000))
	} else {
		dwDesiredAccess = libc.Uint32FromUint32(0x80000000)
	}
	/* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
	 ** created. SQLite doesn't use it to indicate "exclusive access"
	 ** as it is usually understood.
	 */
	if isExclusive != 0 {
		/* Creates a new file, only if it does not already exist. */
		/* If the file exists, it fails. */
		dwCreationDisposition = uint32(CREATE_NEW)
	} else {
		if isCreate != 0 {
			/* Open existing file, or create if it doesn't exist */
			dwCreationDisposition = uint32(OPEN_ALWAYS)
		} else {
			/* Opens a file, only if it exists. */
			dwCreationDisposition = uint32(OPEN_EXISTING)
		}
	}
	if 0 == Xsqlite3_uri_boolean(tls, zName, __ccgo_ts+5170, 0) {
		dwShareMode = uint32(libc.Int32FromInt32(FILE_SHARE_READ) | libc.Int32FromInt32(FILE_SHARE_WRITE))
	} else {
		dwShareMode = uint32(0)
	}
	if isDelete != 0 {
		dwFlagsAndAttributes = uint32(libc.Int32FromInt32(FILE_ATTRIBUTE_TEMPORARY) | libc.Int32FromInt32(FILE_ATTRIBUTE_HIDDEN) | libc.Int32FromInt32(FILE_FLAG_DELETE_ON_CLOSE))
	} else {
		dwFlagsAndAttributes = uint32(FILE_ATTRIBUTE_NORMAL)
	}
	/* Reports from the internet are that performance is always
	 ** better if FILE_FLAG_RANDOM_ACCESS is used.  Ticket #2699. */
	if int32(1) != 0 {
		for cond := true; cond; cond = _winRetryIoerr(tls, bp+4, bp) != 0 {
			h = (*(*func(*libc.TLS, TLPCWSTR, TDWORD, TDWORD, TLPSECURITY_ATTRIBUTES, TDWORD, TDWORD, THANDLE) THANDLE)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, zConverted, dwDesiredAccess, dwShareMode, libc.UintptrFromInt32(0), dwCreationDisposition, dwFlagsAndAttributes, libc.UintptrFromInt32(0))
			if h != uintptr(int32(-libc.Int32FromInt32(1))) {
				break
			}
			if isReadWrite != 0 {
				*(*int32)(unsafe.Pointer(bp + 12)) = 0
				_sqlite3BeginBenignMalloc(tls)
				rc2 = _winAccess(tls, pVfs, zUtf8Name, int32(SQLITE_ACCESS_READ), bp+12)
				_sqlite3EndBenignMalloc(tls)
				if rc2 == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
					break
				}
			}
		}
	} else {
		for cond := true; cond; cond = _winRetryIoerr(tls, bp+4, bp) != 0 {
			h = (*(*func(*libc.TLS, TLPCSTR, TDWORD, TDWORD, TLPSECURITY_ATTRIBUTES, TDWORD, TDWORD, THANDLE) THANDLE)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, zConverted, dwDesiredAccess, dwShareMode, libc.UintptrFromInt32(0), dwCreationDisposition, dwFlagsAndAttributes, libc.UintptrFromInt32(0))
			if h != uintptr(int32(-libc.Int32FromInt32(1))) {
				break
			}
			if isReadWrite != 0 {
				*(*int32)(unsafe.Pointer(bp + 16)) = 0
				_sqlite3BeginBenignMalloc(tls)
				rc21 = _winAccess(tls, pVfs, zUtf8Name, int32(SQLITE_ACCESS_READ), bp+16)
				_sqlite3EndBenignMalloc(tls)
				if rc21 == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 16)) != 0 {
					break
				}
			}
		}
	}
	_winLogIoerr(tls, *(*int32)(unsafe.Pointer(bp + 4)), int32(51905))
	if h == uintptr(int32(-libc.Int32FromInt32(1))) {
		Xsqlite3_free(tls, zConverted)
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		if isReadWrite != 0 && !(isExclusive != 0) {
			return _winOpen(tls, pVfs, zName, id, (flags|int32(SQLITE_OPEN_READONLY)) & ^(libc.Int32FromInt32(SQLITE_OPEN_CREATE)|libc.Int32FromInt32(SQLITE_OPEN_READWRITE)), pOutFlags)
		} else {
			(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = *(*TDWORD)(unsafe.Pointer(bp))
			_winLogErrorAtLine(tls, int32(SQLITE_CANTOPEN), (*TwinFile)(unsafe.Pointer(pFile)).FlastErrno, __ccgo_ts+5180, zUtf8Name, int32(51920))
			return _sqlite3CantopenError(tls, int32(51921))
		}
	}
	if pOutFlags != 0 {
		if isReadWrite != 0 {
			*(*int32)(unsafe.Pointer(pOutFlags)) = int32(SQLITE_OPEN_READWRITE)
		} else {
			*(*int32)(unsafe.Pointer(pOutFlags)) = int32(SQLITE_OPEN_READONLY)
		}
	}
	pAppData = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData
	Xsqlite3_free(tls, zConverted)
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	if pAppData != 0 {
		v1 = (*TwinVfsAppData)(unsafe.Pointer(pAppData)).FpMethod
	} else {
		v1 = uintptr(unsafe.Pointer(&_winIoMethod))
	}
	(*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods = v1
	(*TwinFile)(unsafe.Pointer(pFile)).FpVfs = pVfs
	(*TwinFile)(unsafe.Pointer(pFile)).Fh = h
	if isReadonly != 0 {
		p2 = pFile + 16
		*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | libc.Int32FromInt32(WINFILE_RDONLY))
	}
	if flags&int32(SQLITE_OPEN_MAIN_DB) != 0 && Xsqlite3_uri_boolean(tls, zName, __ccgo_ts+5188, int32(SQLITE_POWERSAFE_OVERWRITE)) != 0 {
		p3 = pFile + 16
		*(*Tu8)(unsafe.Pointer(p3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p3))) | libc.Int32FromInt32(WINFILE_PSOW))
	}
	(*TwinFile)(unsafe.Pointer(pFile)).FlastErrno = uint32(0)
	(*TwinFile)(unsafe.Pointer(pFile)).FzPath = zName
	(*TwinFile)(unsafe.Pointer(pFile)).FhMap = libc.UintptrFromInt32(0)
	(*TwinFile)(unsafe.Pointer(pFile)).FpMapRegion = uintptr(0)
	(*TwinFile)(unsafe.Pointer(pFile)).FmmapSize = 0
	(*TwinFile)(unsafe.Pointer(pFile)).FmmapSizeMax = _sqlite3Config.FszMmap
	return rc
}

// C documentation
//
//	/*
//	** Delete the named file.
//	**
//	** Note that Windows does not allow a file to be deleted if some other
//	** process has it open.  Sometimes a virus scanner or indexing program
//	** will open a journal file shortly after it is created in order to do
//	** whatever it does.  While this other process is holding the
//	** file open, we will be unable to delete it.  To work around this
//	** problem, we delay 100 milliseconds and try to delete again.  Up
//	** to MX_DELETION_ATTEMPTs deletion attempts are run before giving
//	** up and returning an error.
//	*/
func _winDelete(tls *libc.TLS, pVfs uintptr, zFilename uintptr, syncDir int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var attr TDWORD
	var rc int32
	var zConverted uintptr
	var _ /* cnt at bp+0 */ int32
	var _ /* lastErrno at bp+4 */ TDWORD
	_, _, _ = attr, rc, zConverted
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*TDWORD)(unsafe.Pointer(bp + 4)) = uint32(0)
	_ = pVfs
	_ = syncDir
	zConverted = _winConvertFromUtf8Filename(tls, zFilename)
	if zConverted == uintptr(0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	if int32(1) != 0 {
		for cond := true; cond; cond = int32(1) != 0 {
			attr = (*(*func(*libc.TLS, TLPCWSTR) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(21)].FpCurrent})))(tls, zConverted)
			if attr == uint32(-libc.Int32FromInt32(1)) {
				*(*TDWORD)(unsafe.Pointer(bp + 4)) = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
				if *(*TDWORD)(unsafe.Pointer(bp + 4)) == uint32(2) || *(*TDWORD)(unsafe.Pointer(bp + 4)) == uint32(3) {
					rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(23)<<libc.Int32FromInt32(8) /* Already gone? */
				} else {
					rc = int32(SQLITE_ERROR)
				}
				break
			}
			if attr&uint32(FILE_ATTRIBUTE_DIRECTORY) != 0 {
				rc = int32(SQLITE_ERROR) /* Files only. */
				break
			}
			if (*(*func(*libc.TLS, TLPCWSTR) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(10)].FpCurrent})))(tls, zConverted) != 0 {
				rc = SQLITE_OK /* Deleted OK. */
				break
			}
			if !(_winRetryIoerr(tls, bp, bp+4) != 0) {
				rc = int32(SQLITE_ERROR) /* No more retries. */
				break
			}
		}
	} else {
		for cond := true; cond; cond = int32(1) != 0 {
			attr = (*(*func(*libc.TLS, TLPCSTR) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(20)].FpCurrent})))(tls, zConverted)
			if attr == uint32(-libc.Int32FromInt32(1)) {
				*(*TDWORD)(unsafe.Pointer(bp + 4)) = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
				if *(*TDWORD)(unsafe.Pointer(bp + 4)) == uint32(2) || *(*TDWORD)(unsafe.Pointer(bp + 4)) == uint32(3) {
					rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(23)<<libc.Int32FromInt32(8) /* Already gone? */
				} else {
					rc = int32(SQLITE_ERROR)
				}
				break
			}
			if attr&uint32(FILE_ATTRIBUTE_DIRECTORY) != 0 {
				rc = int32(SQLITE_ERROR) /* Files only. */
				break
			}
			if (*(*func(*libc.TLS, TLPCSTR) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(9)].FpCurrent})))(tls, zConverted) != 0 {
				rc = SQLITE_OK /* Deleted OK. */
				break
			}
			if !(_winRetryIoerr(tls, bp, bp+4) != 0) {
				rc = int32(SQLITE_ERROR) /* No more retries. */
				break
			}
		}
	}
	if rc != 0 && rc != libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(23)<<libc.Int32FromInt32(8) {
		rc = _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(10)<<libc.Int32FromInt32(8), *(*TDWORD)(unsafe.Pointer(bp + 4)), __ccgo_ts+5193, zFilename, int32(52093))
	} else {
		_winLogIoerr(tls, *(*int32)(unsafe.Pointer(bp)), int32(52095))
	}
	Xsqlite3_free(tls, zConverted)
	return rc
}

// C documentation
//
//	/*
//	** Check the existence and status of a file.
//	*/
func _winAccess(tls *libc.TLS, pVfs uintptr, zFilename uintptr, flags int32, pResOut uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var attr TDWORD
	var rc, v1 int32
	var zConverted uintptr
	var _ /* cnt at bp+4 */ int32
	var _ /* lastErrno at bp+0 */ TDWORD
	var _ /* sAttrData at bp+8 */ TWIN32_FILE_ATTRIBUTE_DATA
	_, _, _, _ = attr, rc, zConverted, v1
	rc = 0
	*(*TDWORD)(unsafe.Pointer(bp)) = uint32(0)
	_ = pVfs
	if zFilename == uintptr(0) {
		*(*int32)(unsafe.Pointer(pResOut)) = 0
		return SQLITE_OK
	}
	zConverted = _winConvertFromUtf8Filename(tls, zFilename)
	if zConverted == uintptr(0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	if int32(1) != 0 {
		*(*int32)(unsafe.Pointer(bp + 4)) = 0
		libc.Xmemset(tls, bp+8, 0, uint32(36))
		for {
			v1 = (*(*func(*libc.TLS, TLPCWSTR, TGET_FILEEX_INFO_LEVELS, TLPVOID) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(22)].FpCurrent})))(tls, zConverted, _GetFileExInfoStandard, bp+8)
			rc = v1
			if !(!(v1 != 0) && _winRetryIoerr(tls, bp+4, bp) != 0) {
				break
			}
		}
		if rc != 0 {
			/* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
			 ** as if it does not exist.
			 */
			if flags == SQLITE_ACCESS_EXISTS && (*(*TWIN32_FILE_ATTRIBUTE_DATA)(unsafe.Pointer(bp + 8))).FnFileSizeHigh == uint32(0) && (*(*TWIN32_FILE_ATTRIBUTE_DATA)(unsafe.Pointer(bp + 8))).FnFileSizeLow == uint32(0) {
				attr = uint32(-libc.Int32FromInt32(1))
			} else {
				attr = (*(*TWIN32_FILE_ATTRIBUTE_DATA)(unsafe.Pointer(bp + 8))).FdwFileAttributes
			}
		} else {
			_winLogIoerr(tls, *(*int32)(unsafe.Pointer(bp + 4)), int32(52152))
			if *(*TDWORD)(unsafe.Pointer(bp)) != uint32(2) && *(*TDWORD)(unsafe.Pointer(bp)) != uint32(3) {
				Xsqlite3_free(tls, zConverted)
				return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(13)<<libc.Int32FromInt32(8), *(*TDWORD)(unsafe.Pointer(bp)), __ccgo_ts+5203, zFilename, int32(52155))
			} else {
				attr = uint32(-libc.Int32FromInt32(1))
			}
		}
	} else {
		attr = (*(*func(*libc.TLS, TLPCSTR) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(20)].FpCurrent})))(tls, zConverted)
	}
	Xsqlite3_free(tls, zConverted)
	switch flags {
	case int32(SQLITE_ACCESS_READ):
		fallthrough
	case SQLITE_ACCESS_EXISTS:
		rc = libc.BoolInt32(attr != uint32(-libc.Int32FromInt32(1)))
	case int32(SQLITE_ACCESS_READWRITE):
		rc = libc.BoolInt32(attr != uint32(-libc.Int32FromInt32(1)) && attr&uint32(FILE_ATTRIBUTE_READONLY) == uint32(0))
	default:
	}
	*(*int32)(unsafe.Pointer(pResOut)) = rc
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Returns non-zero if the specified path name starts with the "long path"
//	** prefix.
//	*/
func _winIsLongPathPrefix(tls *libc.TLS, zPathname uintptr) (r TBOOL) {
	return libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zPathname))) == int32('\\') && int32(*(*int8)(unsafe.Pointer(zPathname + 1))) == int32('\\') && int32(*(*int8)(unsafe.Pointer(zPathname + 2))) == int32('?') && int32(*(*int8)(unsafe.Pointer(zPathname + 3))) == int32('\\'))
}

// C documentation
//
//	/*
//	** Returns non-zero if the specified path name starts with a drive letter
//	** followed by a colon character.
//	*/
func _winIsDriveLetterAndColon(tls *libc.TLS, zPathname uintptr) (r TBOOL) {
	return libc.BoolInt32(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zPathname)))])&int32(0x02) != 0 && int32(*(*int8)(unsafe.Pointer(zPathname + 1))) == int32(':'))
}

// C documentation
//
//	/*
//	** Returns non-zero if the specified path name should be used verbatim.  If
//	** non-zero is returned from this function, the calling function must simply
//	** use the provided path name verbatim -OR- resolve it into a full path name
//	** using the GetFullPathName Win32 API function (if available).
//	*/
func _winIsVerbatimPathname(tls *libc.TLS, zPathname uintptr) (r TBOOL) {
	/*
	 ** If the path name starts with a forward slash or a backslash, it is either
	 ** a legal UNC name, a volume relative path, or an absolute path name in the
	 ** "Unix" format on Windows.  There is no easy way to differentiate between
	 ** the final two cases; therefore, we return the safer return value of TRUE
	 ** so that callers of this function will simply use it verbatim.
	 */
	if int32(*(*int8)(unsafe.Pointer(zPathname))) == int32('/') || int32(*(*int8)(unsafe.Pointer(zPathname))) == int32('\\') {
		return int32(TRUE)
	}
	/*
	 ** If the path name starts with a letter and a colon it is either a volume
	 ** relative path or an absolute path.  Callers of this function must not
	 ** attempt to treat it as a relative path name (i.e. they should simply use
	 ** it verbatim).
	 */
	if _winIsDriveLetterAndColon(tls, zPathname) != 0 {
		return int32(TRUE)
	}
	/*
	 ** If we get to this point, the path name should almost certainly be a purely
	 ** relative one (i.e. not a UNC name, not absolute, and not volume relative).
	 */
	return FALSE
}

// C documentation
//
//	/*
//	** Turn a relative pathname into a full pathname.  Write the full
//	** pathname into zOut[].  zOut[] will be at least pVfs->mxPathname
//	** bytes in size.
//	*/
func _winFullPathnameNoMutex(tls *libc.TLS, pVfs uintptr, zRelative uintptr, nFull int32, zFull uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nByte TDWORD
	var zConverted, zOut, zTemp1 uintptr
	var zTemp TLPWSTR
	var v1, v2 int32
	_, _, _, _, _, _, _ = nByte, zConverted, zOut, zTemp, zTemp1, v1, v2
	/* If this path name begins with "/X:" or "\\?\", where "X" is any
	 ** alphabetic character, discard the initial "/" from the pathname.
	 */
	if int32(*(*int8)(unsafe.Pointer(zRelative))) == int32('/') && (_winIsDriveLetterAndColon(tls, zRelative+uintptr(1)) != 0 || _winIsLongPathPrefix(tls, zRelative+uintptr(1)) != 0) {
		zRelative++
	}
	/* It's odd to simulate an io-error here, but really this is just
	 ** using the io-error infrastructure to test that SQLite handles this
	 ** function failing. This function could fail if, for example, the
	 ** current working directory has been unlinked.
	 */
	if Xsqlite3_data_directory != 0 && !(_winIsVerbatimPathname(tls, zRelative) != 0) {
		/*
		 ** NOTE: We are dealing with a relative path name and the data
		 **       directory has been set.  Therefore, use it as the basis
		 **       for converting the relative path name to an absolute
		 **       one by prepending the data directory and a backslash.
		 */
		if nFull < (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname {
			v1 = nFull
		} else {
			v1 = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname
		}
		Xsqlite3_snprintf(tls, v1, zFull, __ccgo_ts+5213, libc.VaList(bp+8, Xsqlite3_data_directory, int32('\\'), zRelative))
		return SQLITE_OK
	}
	zConverted = _winConvertFromUtf8Filename(tls, zRelative)
	if zConverted == uintptr(0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	if int32(1) != 0 {
		nByte = (*(*func(*libc.TLS, TLPCWSTR, TDWORD, TLPWSTR, uintptr) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(25)].FpCurrent})))(tls, zConverted, uint32(0), uintptr(0), uintptr(0))
		if nByte == uint32(0) {
			Xsqlite3_free(tls, zConverted)
			return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_CANTOPEN)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+5220, zRelative, int32(52372))
		}
		nByte += uint32(3)
		zTemp = _sqlite3MallocZero(tls, uint64(nByte*uint32(2)))
		if zTemp == uintptr(0) {
			Xsqlite3_free(tls, zConverted)
			return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
		}
		nByte = (*(*func(*libc.TLS, TLPCWSTR, TDWORD, TLPWSTR, uintptr) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(25)].FpCurrent})))(tls, zConverted, nByte, zTemp, uintptr(0))
		if nByte == uint32(0) {
			Xsqlite3_free(tls, zConverted)
			Xsqlite3_free(tls, zTemp)
			return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_CANTOPEN)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+5237, zRelative, int32(52385))
		}
		Xsqlite3_free(tls, zConverted)
		zOut = _winUnicodeToUtf8(tls, zTemp)
		Xsqlite3_free(tls, zTemp)
	} else {
		nByte = (*(*func(*libc.TLS, TLPCSTR, TDWORD, TLPSTR, uintptr) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(24)].FpCurrent})))(tls, zConverted, uint32(0), uintptr(0), uintptr(0))
		if nByte == uint32(0) {
			Xsqlite3_free(tls, zConverted)
			return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_CANTOPEN)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+5254, zRelative, int32(52398))
		}
		nByte += uint32(3)
		zTemp1 = _sqlite3MallocZero(tls, uint64(nByte*uint32(1)))
		if zTemp1 == uintptr(0) {
			Xsqlite3_free(tls, zConverted)
			return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
		}
		nByte = (*(*func(*libc.TLS, TLPCSTR, TDWORD, TLPSTR, uintptr) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(24)].FpCurrent})))(tls, zConverted, nByte, zTemp1, uintptr(0))
		if nByte == uint32(0) {
			Xsqlite3_free(tls, zConverted)
			Xsqlite3_free(tls, zTemp1)
			return _winLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_CANTOPEN)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), __ccgo_ts+5271, zRelative, int32(52411))
		}
		Xsqlite3_free(tls, zConverted)
		zOut = _winMbcsToUtf8(tls, zTemp1, (*(*func(*libc.TLS) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls))
		Xsqlite3_free(tls, zTemp1)
	}
	if zOut != 0 {
		if nFull < (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname {
			v2 = nFull
		} else {
			v2 = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname
		}
		Xsqlite3_snprintf(tls, v2, zFull, __ccgo_ts+4709, libc.VaList(bp+8, zOut))
		Xsqlite3_free(tls, zOut)
		return SQLITE_OK
	} else {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	return r
}

func _winFullPathname(tls *libc.TLS, pVfs uintptr, zRelative uintptr, nFull int32, zFull uintptr) (r int32) {
	var pMutex uintptr
	var rc int32
	_, _ = pMutex, rc
	pMutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1))
	Xsqlite3_mutex_enter(tls, pMutex)
	rc = _winFullPathnameNoMutex(tls, pVfs, zRelative, nFull, zFull)
	Xsqlite3_mutex_leave(tls, pMutex)
	return rc
}

// C documentation
//
//	/*
//	** Interfaces for opening a shared library, finding entry points
//	** within the shared library, and closing the shared library.
//	*/
func _winDlOpen(tls *libc.TLS, pVfs uintptr, zFilename uintptr) (r uintptr) {
	var h THANDLE
	var zConverted uintptr
	_, _ = h, zConverted
	zConverted = _winConvertFromUtf8Filename(tls, zFilename)
	_ = pVfs
	if zConverted == uintptr(0) {
		return uintptr(0)
	}
	if int32(1) != 0 {
		h = (*(*func(*libc.TLS, TLPCWSTR) THMODULE)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(45)].FpCurrent})))(tls, zConverted)
	} else {
		h = (*(*func(*libc.TLS, TLPCSTR) THMODULE)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(44)].FpCurrent})))(tls, zConverted)
	}
	Xsqlite3_free(tls, zConverted)
	return h
}

func _winDlError(tls *libc.TLS, pVfs uintptr, nBuf int32, zBufOut uintptr) {
	_ = pVfs
	_winGetLastErrorMsg(tls, (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls), nBuf, zBufOut)
}

func _winDlSym(tls *libc.TLS, pVfs uintptr, pH uintptr, zSym uintptr) (r uintptr) {
	var proc TFARPROC
	_ = proc
	_ = pVfs
	proc = (*(*func(*libc.TLS, THMODULE, TLPCSTR) TFARPROC)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(27)].FpCurrent})))(tls, pH, zSym)
	return proc
}

func _winDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
	_ = pVfs
	(*(*func(*libc.TLS, THMODULE) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(16)].FpCurrent})))(tls, pHandle)
}

// C documentation
//
//	/* State information for the randomness gatherer. */
type TEntropyGatherer = struct {
	Fa    uintptr
	Fna   int32
	Fi    int32
	FnXor int32
}

type EntropyGatherer = TEntropyGatherer

type TEntropyGatherer1 = struct {
	Fa    uintptr
	Fna   int32
	Fi    int32
	FnXor int32
}

type EntropyGatherer1 = TEntropyGatherer1

// C documentation
//
//	/* Mix sz bytes of entropy into p. */
func _xorMemory(tls *libc.TLS, p uintptr, x uintptr, sz int32) {
	var j, k, v3 int32
	var p2 uintptr
	_, _, _, _ = j, k, v3, p2
	j = 0
	k = (*TEntropyGatherer)(unsafe.Pointer(p)).Fi
	for {
		if !(j < sz) {
			break
		}
		v3 = k
		k++
		p2 = (*TEntropyGatherer)(unsafe.Pointer(p)).Fa + uintptr(v3)
		*(*uint8)(unsafe.Pointer(p2)) = uint8(int32(*(*uint8)(unsafe.Pointer(p2))) ^ int32(*(*uint8)(unsafe.Pointer(x + uintptr(j)))))
		if k >= (*TEntropyGatherer)(unsafe.Pointer(p)).Fna {
			k = 0
		}
		goto _1
	_1:
		;
		j++
	}
	(*TEntropyGatherer)(unsafe.Pointer(p)).Fi = k
	*(*int32)(unsafe.Pointer(p + 12)) += sz
}

// C documentation
//
//	/*
//	** Write up to nBuf bytes of randomness into zBuf.
//	*/
func _winRandomness(tls *libc.TLS, pVfs uintptr, nBuf int32, zBuf uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var v1 int32
	var _ /* cnt at bp+36 */ TDWORD
	var _ /* e at bp+0 */ TEntropyGatherer
	var _ /* i at bp+40 */ TLARGE_INTEGER
	var _ /* pid at bp+32 */ TDWORD
	var _ /* x at bp+16 */ TSYSTEMTIME
	_ = v1
	_ = pVfs
	libc.Xmemset(tls, zBuf, 0, uint32(uint32(nBuf)))
	(*(*TEntropyGatherer)(unsafe.Pointer(bp))).Fa = zBuf
	(*(*TEntropyGatherer)(unsafe.Pointer(bp))).Fna = nBuf
	(*(*TEntropyGatherer)(unsafe.Pointer(bp))).FnXor = 0
	(*(*TEntropyGatherer)(unsafe.Pointer(bp))).Fi = 0
	(*(*func(*libc.TLS, TLPSYSTEMTIME))(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(29)].FpCurrent})))(tls, bp+16)
	_xorMemory(tls, bp, bp+16, int32(16))
	*(*TDWORD)(unsafe.Pointer(bp + 32)) = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(17)].FpCurrent})))(tls)
	_xorMemory(tls, bp, bp+32, int32(4))
	*(*TDWORD)(unsafe.Pointer(bp + 36)) = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(33)].FpCurrent})))(tls)
	_xorMemory(tls, bp, bp+36, int32(4))
	(*(*func(*libc.TLS, uintptr) TBOOL)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(51)].FpCurrent})))(tls, bp+40)
	_xorMemory(tls, bp, bp+40, int32(8))
	if (*(*TEntropyGatherer)(unsafe.Pointer(bp))).FnXor > nBuf {
		v1 = nBuf
	} else {
		v1 = (*(*TEntropyGatherer)(unsafe.Pointer(bp))).FnXor
	}
	return v1
}

// C documentation
//
//	/*
//	** Sleep for a little while.  Return the amount of time slept.
//	*/
func _winSleep(tls *libc.TLS, pVfs uintptr, microsec int32) (r int32) {
	Xsqlite3_win32_sleep(tls, uint32((microsec+int32(999))/int32(1000)))
	_ = pVfs
	return (microsec + int32(999)) / int32(1000) * int32(1000)
}

/*
** The following variable, if set to a non-zero value, is interpreted as
** the number of seconds since 1970 and is used to set the result of
** sqlite3OsCurrentTime() during testing.
 */

// C documentation
//
//	/*
//	** Find the current time (in Universal Coordinated Time).  Write into *piNow
//	** the current time and date as a Julian Day number times 86_400_000.  In
//	** other words, write into *piNow the number of milliseconds since the Julian
//	** epoch of noon in Greenwich on November 24, 4714 B.C according to the
//	** proleptic Gregorian calendar.
//	**
//	** On success, return SQLITE_OK.  Return SQLITE_ERROR if the time and date
//	** cannot be found.
//	*/
func _winCurrentTimeInt64(tls *libc.TLS, pVfs uintptr, piNow uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* ft at bp+0 */ TFILETIME
	(*(*func(*libc.TLS, TLPFILETIME))(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(30)].FpCurrent})))(tls, bp)
	*(*Tsqlite3_int64)(unsafe.Pointer(piNow)) = _winFiletimeEpoch + (int64((*(*TFILETIME)(unsafe.Pointer(bp))).FdwHighDateTime)*_max32BitValue+int64((*(*TFILETIME)(unsafe.Pointer(bp))).FdwLowDateTime))/libc.Int64FromInt32(10000)
	_ = pVfs
	return SQLITE_OK
}

var _winFiletimeEpoch = libc.Int64FromInt32(23058135) * libc.Int64FromInt32(8640000)

/* 2^32 - to avoid use of LL and warnings in gcc */
var _max32BitValue = libc.Int64FromInt32(2000000000) + libc.Int64FromInt32(2000000000) + libc.Int64FromInt32(294967296)

// C documentation
//
//	/*
//	** Find the current time (in Universal Coordinated Time).  Write the
//	** current time and date as a Julian Day number into *prNow and
//	** return 0.  Return 1 if the time and date cannot be found.
//	*/
func _winCurrentTime(tls *libc.TLS, pVfs uintptr, prNow uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* i at bp+0 */ Tsqlite3_int64
	_ = rc
	rc = _winCurrentTimeInt64(tls, pVfs, bp)
	if !(rc != 0) {
		*(*float64)(unsafe.Pointer(prNow)) = float64(*(*Tsqlite3_int64)(unsafe.Pointer(bp))) / float64(8.64e+07)
	}
	return rc
}

// C documentation
//
//	/*
//	** The idea is that this function works like a combination of
//	** GetLastError() and FormatMessage() on Windows (or errno and
//	** strerror_r() on Unix). After an error is returned by an OS
//	** function, SQLite calls this function with zBuf pointing to
//	** a buffer of nBuf bytes. The OS layer should populate the
//	** buffer with a nul-terminated UTF-8 encoded error message
//	** describing the last IO error to have occurred within the calling
//	** thread.
//	**
//	** If the error message is too large for the supplied buffer,
//	** it should be truncated. The return value of xGetLastError
//	** is zero if the error message fits in the buffer, or non-zero
//	** otherwise (if the message was truncated). If non-zero is returned,
//	** then it is not necessary to include the nul-terminator character
//	** in the output buffer.
//	**
//	** Not supplying an error message will have no adverse effect
//	** on SQLite. It is fine to have an implementation that never
//	** returns an error message:
//	**
//	**   int xGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
//	**     assert(zBuf[0]=='\0');
//	**     return 0;
//	**   }
//	**
//	** However if an error message is supplied, it will be incorporated
//	** by sqlite into the error message available to the user using
//	** sqlite3_errmsg(), possibly making IO errors easier to debug.
//	*/
func _winGetLastError(tls *libc.TLS, pVfs uintptr, nBuf int32, zBuf uintptr) (r int32) {
	var e TDWORD
	_ = e
	e = (*(*func(*libc.TLS) TDWORD)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls)
	_ = pVfs
	if nBuf > 0 {
		_winGetLastErrorMsg(tls, e, nBuf, zBuf)
	}
	return int32(int32(e))
}

// C documentation
//
//	/*
//	** Initialize and deinitialize the operating system interface.
//	*/
func Xsqlite3_os_init(tls *libc.TLS) (r int32) {
	/* Double-check that the aSyscall[] array has been constructed
	 ** correctly.  See ticket [bb3a86e890c8e96ab] */
	/* get memory map allocation granularity */
	libc.Xmemset(tls, uintptr(unsafe.Pointer(&_winSysInfo)), 0, uint32(36))
	(*(*func(*libc.TLS, TLPSYSTEM_INFO))(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(28)].FpCurrent})))(tls, uintptr(unsafe.Pointer(&_winSysInfo)))
	Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&_winVfs)), int32(1))
	Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&_winLongPathVfs)), 0)
	Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&_winNolockVfs)), 0)
	Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&_winLongPathNolockVfs)), 0)
	_winBigLock = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1))
	return SQLITE_OK
}

var _winVfs = Tsqlite3_vfs{
	FiVersion:   int32(3),
	FszOsFile:   int32(64),
	FmxPathname: libc.Int32FromInt32(MAX_PATH) * libc.Int32FromInt32(4),
	FzName:      __ccgo_ts + 5288,
	FpAppData:   uintptr(unsafe.Pointer(&_winAppData)),
}

func init() {
	p := unsafe.Pointer(&_winVfs)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_winOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_winDelete)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_winAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_winFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_winDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_winDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_winDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_winDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_winRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_winSleep)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_winCurrentTime)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_winGetLastError)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_winCurrentTimeInt64)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_winSetSystemCall)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_winGetSystemCall)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_winNextSystemCall)
}

var _winLongPathVfs = Tsqlite3_vfs{
	FiVersion:   int32(3),
	FszOsFile:   int32(64),
	FmxPathname: int32(libc.Uint32FromInt64(2) * uint32(libc.Int32FromInt32(UNICODE_STRING_MAX_CHARS))),
	FzName:      __ccgo_ts + 5294,
	FpAppData:   uintptr(unsafe.Pointer(&_winAppData)),
}

func init() {
	p := unsafe.Pointer(&_winLongPathVfs)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_winOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_winDelete)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_winAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_winFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_winDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_winDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_winDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_winDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_winRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_winSleep)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_winCurrentTime)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_winGetLastError)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_winCurrentTimeInt64)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_winSetSystemCall)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_winGetSystemCall)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_winNextSystemCall)
}

var _winNolockVfs = Tsqlite3_vfs{
	FiVersion:   int32(3),
	FszOsFile:   int32(64),
	FmxPathname: libc.Int32FromInt32(MAX_PATH) * libc.Int32FromInt32(4),
	FzName:      __ccgo_ts + 5309,
	FpAppData:   uintptr(unsafe.Pointer(&_winNolockAppData)),
}

func init() {
	p := unsafe.Pointer(&_winNolockVfs)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_winOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_winDelete)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_winAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_winFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_winDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_winDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_winDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_winDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_winRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_winSleep)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_winCurrentTime)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_winGetLastError)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_winCurrentTimeInt64)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_winSetSystemCall)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_winGetSystemCall)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_winNextSystemCall)
}

var _winLongPathNolockVfs = Tsqlite3_vfs{
	FiVersion:   int32(3),
	FszOsFile:   int32(64),
	FmxPathname: int32(libc.Uint32FromInt64(2) * uint32(libc.Int32FromInt32(UNICODE_STRING_MAX_CHARS))),
	FzName:      __ccgo_ts + 5320,
	FpAppData:   uintptr(unsafe.Pointer(&_winNolockAppData)),
}

func init() {
	p := unsafe.Pointer(&_winLongPathNolockVfs)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_winOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_winDelete)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_winAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_winFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_winDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_winDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_winDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_winDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_winRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_winSleep)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_winCurrentTime)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_winGetLastError)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_winCurrentTimeInt64)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_winSetSystemCall)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_winGetSystemCall)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_winNextSystemCall)
}

func Xsqlite3_os_end(tls *libc.TLS) (r int32) {
	_winBigLock = uintptr(0)
	return SQLITE_OK
}

/************** End of os_win.c **********************************************/
/************** Begin file memdb.c *******************************************/
/*
** 2016-09-07
**
** 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 implements an in-memory VFS. A database is held as a contiguous
** block of memory.
**
** This file also implements interface sqlite3_serialize() and
** sqlite3_deserialize().
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Forward declaration of objects used by this utility
//	*/
type TMemVfs = struct {
	FiVersion          int32
	FszOsFile          int32
	FmxPathname        int32
	FpNext             uintptr
	FzName             uintptr
	FpAppData          uintptr
	FxOpen             uintptr
	FxDelete           uintptr
	FxAccess           uintptr
	FxFullPathname     uintptr
	FxDlOpen           uintptr
	FxDlError          uintptr
	FxDlSym            uintptr
	FxDlClose          uintptr
	FxRandomness       uintptr
	FxSleep            uintptr
	FxCurrentTime      uintptr
	FxGetLastError     uintptr
	FxCurrentTimeInt64 uintptr
	FxSetSystemCall    uintptr
	FxGetSystemCall    uintptr
	FxNextSystemCall   uintptr
}

type MemVfs = TMemVfs

type TMemFile = struct {
	Fbase   Tsqlite3_file
	FpStore uintptr
	FeLock  int32
}

type MemFile = TMemFile

type TMemStore = struct {
	F__ccgo_align [0]uint32
	Fsz           Tsqlite3_int64
	FszAlloc      Tsqlite3_int64
	FszMax        Tsqlite3_int64
	FaData        uintptr
	FpMutex       uintptr
	FnMmap        int32
	FmFlags       uint32
	FnRdLock      int32
	FnWrLock      int32
	FnRef         int32
	FzFName       uintptr
}

type MemStore = TMemStore

/* Access to a lower-level VFS that (might) implement dynamic loading,
** access to randomness, etc.
 */

/* Storage for a memdb file.
**
** An memdb object can be shared or separate.  Shared memdb objects can be
** used by more than one database connection.  Mutexes are used by shared
** memdb objects to coordinate access.  Separate memdb objects are only
** connected to a single database connection and do not require additional
** mutexes.
**
** Shared memdb objects have .zFName!=0 and .pMutex!=0.  They are created
** using "file:/name?vfs=memdb".  The first character of the name must be
** "/" or else the object will be a separate memdb object.  All shared
** memdb objects are stored in memdb_g.apMemStore[] in an arbitrary order.
**
** Separate memdb objects are created using a name that does not begin
** with "/" or using sqlite3_deserialize().
**
** Access rules for shared MemStore objects:
**
**   *  .zFName is initialized when the object is created and afterwards
**      is unchanged until the object is destroyed.  So it can be accessed
**      at any time as long as we know the object is not being destroyed,
**      which means while either the SQLITE_MUTEX_STATIC_VFS1 or
**      .pMutex is held or the object is not part of memdb_g.apMemStore[].
**
**   *  Can .pMutex can only be changed while holding the
**      SQLITE_MUTEX_STATIC_VFS1 mutex or while the object is not part
**      of memdb_g.apMemStore[].
**
**   *  Other fields can only be changed while holding the .pMutex mutex
**      or when the .nRef is less than zero and the object is not part of
**      memdb_g.apMemStore[].
**
**   *  The .aData pointer has the added requirement that it can can only
**      be changed (for resizing) when nMmap is zero.
**
 */
type TMemStore1 = struct {
	F__ccgo_align [0]uint32
	Fsz           Tsqlite3_int64
	FszAlloc      Tsqlite3_int64
	FszMax        Tsqlite3_int64
	FaData        uintptr
	FpMutex       uintptr
	FnMmap        int32
	FmFlags       uint32
	FnRdLock      int32
	FnWrLock      int32
	FnRef         int32
	FzFName       uintptr
}

type MemStore1 = TMemStore1

/* An open file */
type TMemFile1 = struct {
	Fbase   Tsqlite3_file
	FpStore uintptr
	FeLock  int32
}

type MemFile1 = TMemFile1

// C documentation
//
//	/*
//	** File-scope variables for holding the memdb files that are accessible
//	** to multiple database connections in separate threads.
//	**
//	** Must hold SQLITE_MUTEX_STATIC_VFS1 to access any part of this object.
//	*/
type TMemFS = struct {
	FnMemStore  int32
	FapMemStore uintptr
}

type MemFS = TMemFS

// C documentation
//
//	/*
//	** File-scope variables for holding the memdb files that are accessible
//	** to multiple database connections in separate threads.
//	**
//	** Must hold SQLITE_MUTEX_STATIC_VFS1 to access any part of this object.
//	*/
var _memdb_g TMemFS

var _memdb_vfs = Tsqlite3_vfs{
	FiVersion:   int32(2),
	FmxPathname: int32(1024),
	FzName:      __ccgo_ts + 5340,
}

func init() {
	p := unsafe.Pointer(&_memdb_vfs)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_memdbOpen)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_memdbAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_memdbFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_memdbDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_memdbDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_memdbDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_memdbDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_memdbRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_memdbSleep)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_memdbGetLastError)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_memdbCurrentTimeInt64)
}

var _memdb_io_methods = Tsqlite3_io_methods{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_memdb_io_methods)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_memdbClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_memdbRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_memdbWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_memdbTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_memdbSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_memdbFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_memdbLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_memdbUnlock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_memdbFileControl)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_memdbDeviceCharacteristics)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_memdbFetch)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_memdbUnfetch)
}

// C documentation
//
//	/*
//	** Enter/leave the mutex on a MemStore
//	*/
func _memdbEnter(tls *libc.TLS, p uintptr) {
	Xsqlite3_mutex_enter(tls, (*TMemStore)(unsafe.Pointer(p)).FpMutex)
}

func _memdbLeave(tls *libc.TLS, p uintptr) {
	Xsqlite3_mutex_leave(tls, (*TMemStore)(unsafe.Pointer(p)).FpMutex)
}

// C documentation
//
//	/*
//	** Close an memdb-file.
//	** Free the underlying MemStore object when its refcount drops to zero
//	** or less.
//	*/
func _memdbClose(tls *libc.TLS, pFile uintptr) (r int32) {
	var i, v2 int32
	var p, pVfsMutex, v3 uintptr
	_, _, _, _, _ = i, p, pVfsMutex, v2, v3
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	if (*TMemStore)(unsafe.Pointer(p)).FzFName != 0 {
		pVfsMutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1))
		Xsqlite3_mutex_enter(tls, pVfsMutex)
		i = 0
		for {
			if !(i < _memdb_g.FnMemStore) {
				break
			}
			if *(*uintptr)(unsafe.Pointer(_memdb_g.FapMemStore + uintptr(i)*4)) == p {
				_memdbEnter(tls, p)
				if (*TMemStore)(unsafe.Pointer(p)).FnRef == int32(1) {
					v3 = uintptr(unsafe.Pointer(&_memdb_g))
					*(*int32)(unsafe.Pointer(v3))--
					v2 = *(*int32)(unsafe.Pointer(v3))
					*(*uintptr)(unsafe.Pointer(_memdb_g.FapMemStore + uintptr(i)*4)) = *(*uintptr)(unsafe.Pointer(_memdb_g.FapMemStore + uintptr(v2)*4))
					if _memdb_g.FnMemStore == 0 {
						Xsqlite3_free(tls, _memdb_g.FapMemStore)
						_memdb_g.FapMemStore = uintptr(0)
					}
				}
				break
			}
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_mutex_leave(tls, pVfsMutex)
	} else {
		_memdbEnter(tls, p)
	}
	(*TMemStore)(unsafe.Pointer(p)).FnRef--
	if (*TMemStore)(unsafe.Pointer(p)).FnRef <= 0 {
		if (*TMemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_FREEONCLOSE) != 0 {
			Xsqlite3_free(tls, (*TMemStore)(unsafe.Pointer(p)).FaData)
		}
		_memdbLeave(tls, p)
		Xsqlite3_mutex_free(tls, (*TMemStore)(unsafe.Pointer(p)).FpMutex)
		Xsqlite3_free(tls, p)
	} else {
		_memdbLeave(tls, p)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Read data from an memdb-file.
//	*/
func _memdbRead(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
	var p uintptr
	_ = p
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	_memdbEnter(tls, p)
	if iOfst+int64(int64(iAmt)) > (*TMemStore)(unsafe.Pointer(p)).Fsz {
		libc.Xmemset(tls, zBuf, 0, uint32(uint32(iAmt)))
		if iOfst < (*TMemStore)(unsafe.Pointer(p)).Fsz {
			libc.Xmemcpy(tls, zBuf, (*TMemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), uint32((*TMemStore)(unsafe.Pointer(p)).Fsz-iOfst))
		}
		_memdbLeave(tls, p)
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	libc.Xmemcpy(tls, zBuf, (*TMemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), uint32(uint32(iAmt)))
	_memdbLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Try to enlarge the memory allocation to hold at least sz bytes
//	*/
func _memdbEnlarge(tls *libc.TLS, p uintptr, newSz Tsqlite3_int64) (r int32) {
	var pNew uintptr
	_ = pNew
	if (*TMemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_RESIZEABLE) == uint32(0) || (*TMemStore)(unsafe.Pointer(p)).FnMmap > 0 {
		return int32(SQLITE_FULL)
	}
	if newSz > (*TMemStore)(unsafe.Pointer(p)).FszMax {
		return int32(SQLITE_FULL)
	}
	newSz *= int64(2)
	if newSz > (*TMemStore)(unsafe.Pointer(p)).FszMax {
		newSz = (*TMemStore)(unsafe.Pointer(p)).FszMax
	}
	pNew = _sqlite3Realloc(tls, (*TMemStore)(unsafe.Pointer(p)).FaData, uint64(uint64(newSz)))
	if pNew == uintptr(0) {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
	}
	(*TMemStore)(unsafe.Pointer(p)).FaData = pNew
	(*TMemStore)(unsafe.Pointer(p)).FszAlloc = newSz
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Write data to an memdb-file.
//	*/
func _memdbWrite(tls *libc.TLS, pFile uintptr, z uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
	var p uintptr
	var rc, v1 int32
	var v2 bool
	_, _, _, _ = p, rc, v1, v2
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	_memdbEnter(tls, p)
	if (*TMemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_READONLY) != 0 {
		/* Can't happen: memdbLock() will return SQLITE_READONLY before
		 ** reaching this point */
		_memdbLeave(tls, p)
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
	}
	if iOfst+int64(int64(iAmt)) > (*TMemStore)(unsafe.Pointer(p)).Fsz {
		if v2 = iOfst+int64(int64(iAmt)) > (*TMemStore)(unsafe.Pointer(p)).FszAlloc; v2 {
			v1 = _memdbEnlarge(tls, p, iOfst+int64(int64(iAmt)))
			rc = v1
		}
		if v2 && v1 != SQLITE_OK {
			_memdbLeave(tls, p)
			return rc
		}
		if iOfst > (*TMemStore)(unsafe.Pointer(p)).Fsz {
			libc.Xmemset(tls, (*TMemStore)(unsafe.Pointer(p)).FaData+uintptr((*TMemStore)(unsafe.Pointer(p)).Fsz), 0, uint32(iOfst-(*TMemStore)(unsafe.Pointer(p)).Fsz))
		}
		(*TMemStore)(unsafe.Pointer(p)).Fsz = iOfst + int64(int64(iAmt))
	}
	libc.Xmemcpy(tls, (*TMemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), z, uint32(uint32(iAmt)))
	_memdbLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Truncate an memdb-file.
//	**
//	** In rollback mode (which is always the case for memdb, as it does not
//	** support WAL mode) the truncate() method is only used to reduce
//	** the size of a file, never to increase the size.
//	*/
func _memdbTruncate(tls *libc.TLS, pFile uintptr, size Tsqlite_int64) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	rc = SQLITE_OK
	_memdbEnter(tls, p)
	if size > (*TMemStore)(unsafe.Pointer(p)).Fsz {
		/* This can only happen with a corrupt wal mode db */
		rc = int32(SQLITE_CORRUPT)
	} else {
		(*TMemStore)(unsafe.Pointer(p)).Fsz = size
	}
	_memdbLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Sync an memdb-file.
//	*/
func _memdbSync(tls *libc.TLS, pFile uintptr, flags int32) (r int32) {
	_ = pFile
	_ = flags
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the current file-size of an memdb-file.
//	*/
func _memdbFileSize(tls *libc.TLS, pFile uintptr, pSize uintptr) (r int32) {
	var p uintptr
	_ = p
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	_memdbEnter(tls, p)
	*(*Tsqlite_int64)(unsafe.Pointer(pSize)) = (*TMemStore)(unsafe.Pointer(p)).Fsz
	_memdbLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Lock an memdb-file.
//	*/
func _memdbLock(tls *libc.TLS, pFile uintptr, eLock int32) (r int32) {
	var p, pThis uintptr
	var rc int32
	_, _, _ = p, pThis, rc
	pThis = pFile
	p = (*TMemFile)(unsafe.Pointer(pThis)).FpStore
	rc = SQLITE_OK
	if eLock <= (*TMemFile)(unsafe.Pointer(pThis)).FeLock {
		return SQLITE_OK
	}
	_memdbEnter(tls, p)
	if eLock > int32(SQLITE_LOCK_SHARED) && (*TMemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_READONLY) != 0 {
		rc = int32(SQLITE_READONLY)
	} else {
		switch eLock {
		case int32(SQLITE_LOCK_SHARED):
			if (*TMemStore)(unsafe.Pointer(p)).FnWrLock > 0 {
				rc = int32(SQLITE_BUSY)
			} else {
				(*TMemStore)(unsafe.Pointer(p)).FnRdLock++
			}
		case int32(SQLITE_LOCK_RESERVED):
			fallthrough
		case int32(SQLITE_LOCK_PENDING):
			if (*TMemFile)(unsafe.Pointer(pThis)).FeLock == int32(SQLITE_LOCK_SHARED) {
				if (*TMemStore)(unsafe.Pointer(p)).FnWrLock > 0 {
					rc = int32(SQLITE_BUSY)
				} else {
					(*TMemStore)(unsafe.Pointer(p)).FnWrLock = int32(1)
				}
			}
		default:
			if (*TMemStore)(unsafe.Pointer(p)).FnRdLock > int32(1) {
				rc = int32(SQLITE_BUSY)
			} else {
				if (*TMemFile)(unsafe.Pointer(pThis)).FeLock == int32(SQLITE_LOCK_SHARED) {
					(*TMemStore)(unsafe.Pointer(p)).FnWrLock = int32(1)
				}
			}
			break
		}
	}
	if rc == SQLITE_OK {
		(*TMemFile)(unsafe.Pointer(pThis)).FeLock = eLock
	}
	_memdbLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Unlock an memdb-file.
//	*/
func _memdbUnlock(tls *libc.TLS, pFile uintptr, eLock int32) (r int32) {
	var p, pThis uintptr
	_, _ = p, pThis
	pThis = pFile
	p = (*TMemFile)(unsafe.Pointer(pThis)).FpStore
	if eLock >= (*TMemFile)(unsafe.Pointer(pThis)).FeLock {
		return SQLITE_OK
	}
	_memdbEnter(tls, p)
	if eLock == int32(SQLITE_LOCK_SHARED) {
		if (*TMemFile)(unsafe.Pointer(pThis)).FeLock > int32(SQLITE_LOCK_SHARED) {
			(*TMemStore)(unsafe.Pointer(p)).FnWrLock--
		}
	} else {
		if (*TMemFile)(unsafe.Pointer(pThis)).FeLock > int32(SQLITE_LOCK_SHARED) {
			(*TMemStore)(unsafe.Pointer(p)).FnWrLock--
		}
		(*TMemStore)(unsafe.Pointer(p)).FnRdLock--
	}
	(*TMemFile)(unsafe.Pointer(pThis)).FeLock = eLock
	_memdbLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** File control method. For custom operations on an memdb-file.
//	*/
func _memdbFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iLimit Tsqlite3_int64
	var p uintptr
	var rc int32
	_, _, _ = iLimit, p, rc
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	rc = int32(SQLITE_NOTFOUND)
	_memdbEnter(tls, p)
	if op == int32(SQLITE_FCNTL_VFSNAME) {
		*(*uintptr)(unsafe.Pointer(pArg)) = Xsqlite3_mprintf(tls, __ccgo_ts+5346, libc.VaList(bp+8, (*TMemStore)(unsafe.Pointer(p)).FaData, (*TMemStore)(unsafe.Pointer(p)).Fsz))
		rc = SQLITE_OK
	}
	if op == int32(SQLITE_FCNTL_SIZE_LIMIT) {
		iLimit = *(*Tsqlite3_int64)(unsafe.Pointer(pArg))
		if iLimit < (*TMemStore)(unsafe.Pointer(p)).Fsz {
			if iLimit < 0 {
				iLimit = (*TMemStore)(unsafe.Pointer(p)).FszMax
			} else {
				iLimit = (*TMemStore)(unsafe.Pointer(p)).Fsz
			}
		}
		(*TMemStore)(unsafe.Pointer(p)).FszMax = iLimit
		*(*Tsqlite3_int64)(unsafe.Pointer(pArg)) = iLimit
		rc = SQLITE_OK
	}
	_memdbLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Return the device characteristic flags supported by an memdb-file.
//	*/
func _memdbDeviceCharacteristics(tls *libc.TLS, pFile uintptr) (r int32) {
	_ = pFile
	return libc.Int32FromInt32(SQLITE_IOCAP_ATOMIC) | libc.Int32FromInt32(SQLITE_IOCAP_POWERSAFE_OVERWRITE) | libc.Int32FromInt32(SQLITE_IOCAP_SAFE_APPEND) | libc.Int32FromInt32(SQLITE_IOCAP_SEQUENTIAL)
}

// C documentation
//
//	/* Fetch a page of a memory-mapped file */
func _memdbFetch(tls *libc.TLS, pFile uintptr, iOfst Tsqlite3_int64, iAmt int32, pp uintptr) (r int32) {
	var p uintptr
	_ = p
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	_memdbEnter(tls, p)
	if iOfst+int64(int64(iAmt)) > (*TMemStore)(unsafe.Pointer(p)).Fsz || (*TMemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_RESIZEABLE) != uint32(0) {
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	} else {
		(*TMemStore)(unsafe.Pointer(p)).FnMmap++
		*(*uintptr)(unsafe.Pointer(pp)) = (*TMemStore)(unsafe.Pointer(p)).FaData + uintptr(iOfst)
	}
	_memdbLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/* Release a memory-mapped page */
func _memdbUnfetch(tls *libc.TLS, pFile uintptr, iOfst Tsqlite3_int64, pPage uintptr) (r int32) {
	var p uintptr
	_ = p
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	_ = iOfst
	_ = pPage
	_memdbEnter(tls, p)
	(*TMemStore)(unsafe.Pointer(p)).FnMmap--
	_memdbLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Open an mem file handle.
//	*/
func _memdbOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pFd uintptr, flags int32, pOutFlags uintptr) (r int32) {
	var apNew, p, pFile, pVfsMutex, v3 uintptr
	var i, szName, v2 int32
	_, _, _, _, _, _, _, _ = apNew, i, p, pFile, pVfsMutex, szName, v2, v3
	pFile = pFd
	p = uintptr(0)
	_ = pVfs
	libc.Xmemset(tls, pFile, 0, uint32(12))
	szName = _sqlite3Strlen30(tls, zName)
	if szName > int32(1) && (int32(*(*int8)(unsafe.Pointer(zName))) == int32('/') || int32(*(*int8)(unsafe.Pointer(zName))) == int32('\\')) {
		pVfsMutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1))
		Xsqlite3_mutex_enter(tls, pVfsMutex)
		i = 0
		for {
			if !(i < _memdb_g.FnMemStore) {
				break
			}
			if libc.Xstrcmp(tls, (*TMemStore)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(_memdb_g.FapMemStore + uintptr(i)*4)))).FzFName, zName) == 0 {
				p = *(*uintptr)(unsafe.Pointer(_memdb_g.FapMemStore + uintptr(i)*4))
				break
			}
			goto _1
		_1:
			;
			i++
		}
		if p == uintptr(0) {
			p = _sqlite3Malloc(tls, uint64(uint32(56)+uint32(uint32(szName))+uint32(3)))
			if p == uintptr(0) {
				Xsqlite3_mutex_leave(tls, pVfsMutex)
				return int32(SQLITE_NOMEM)
			}
			apNew = _sqlite3Realloc(tls, _memdb_g.FapMemStore, uint64(uint32(4)*uint32(_memdb_g.FnMemStore+libc.Int32FromInt32(1))))
			if apNew == uintptr(0) {
				Xsqlite3_free(tls, p)
				Xsqlite3_mutex_leave(tls, pVfsMutex)
				return int32(SQLITE_NOMEM)
			}
			v3 = uintptr(unsafe.Pointer(&_memdb_g))
			v2 = *(*int32)(unsafe.Pointer(v3))
			*(*int32)(unsafe.Pointer(v3))++
			*(*uintptr)(unsafe.Pointer(apNew + uintptr(v2)*4)) = p
			_memdb_g.FapMemStore = apNew
			libc.Xmemset(tls, p, 0, uint32(56))
			(*TMemStore)(unsafe.Pointer(p)).FmFlags = uint32(libc.Int32FromInt32(SQLITE_DESERIALIZE_RESIZEABLE) | libc.Int32FromInt32(SQLITE_DESERIALIZE_FREEONCLOSE))
			(*TMemStore)(unsafe.Pointer(p)).FszMax = _sqlite3Config.FmxMemdbSize
			(*TMemStore)(unsafe.Pointer(p)).FzFName = p + 1*56
			libc.Xmemcpy(tls, (*TMemStore)(unsafe.Pointer(p)).FzFName, zName, uint32(szName+int32(1)))
			(*TMemStore)(unsafe.Pointer(p)).FpMutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
			if (*TMemStore)(unsafe.Pointer(p)).FpMutex == uintptr(0) {
				_memdb_g.FnMemStore--
				Xsqlite3_free(tls, p)
				Xsqlite3_mutex_leave(tls, pVfsMutex)
				return int32(SQLITE_NOMEM)
			}
			(*TMemStore)(unsafe.Pointer(p)).FnRef = int32(1)
			_memdbEnter(tls, p)
		} else {
			_memdbEnter(tls, p)
			(*TMemStore)(unsafe.Pointer(p)).FnRef++
		}
		Xsqlite3_mutex_leave(tls, pVfsMutex)
	} else {
		p = _sqlite3Malloc(tls, uint64(56))
		if p == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, p, 0, uint32(56))
		(*TMemStore)(unsafe.Pointer(p)).FmFlags = uint32(libc.Int32FromInt32(SQLITE_DESERIALIZE_RESIZEABLE) | libc.Int32FromInt32(SQLITE_DESERIALIZE_FREEONCLOSE))
		(*TMemStore)(unsafe.Pointer(p)).FszMax = _sqlite3Config.FmxMemdbSize
	}
	(*TMemFile)(unsafe.Pointer(pFile)).FpStore = p
	if pOutFlags != uintptr(0) {
		*(*int32)(unsafe.Pointer(pOutFlags)) = flags | int32(SQLITE_OPEN_MEMORY)
	}
	(*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods = uintptr(unsafe.Pointer(&_memdb_io_methods))
	_memdbLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Test for access permissions. Return true if the requested permission
//	** is available, or false otherwise.
//	**
//	** With memdb, no files ever exist on disk.  So always return false.
//	*/
func _memdbAccess(tls *libc.TLS, pVfs uintptr, zPath uintptr, flags int32, pResOut uintptr) (r int32) {
	_ = pVfs
	_ = zPath
	_ = flags
	*(*int32)(unsafe.Pointer(pResOut)) = 0
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Populate buffer zOut with the full canonical pathname corresponding
//	** to the pathname in zPath. zOut is guaranteed to point to a buffer
//	** of at least (INST_MAX_PATHNAME+1) bytes.
//	*/
func _memdbFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nOut int32, zOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_ = pVfs
	Xsqlite3_snprintf(tls, nOut, zOut, __ccgo_ts+4709, libc.VaList(bp+8, zPath))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Open the dynamic library located at zPath and return a handle.
//	*/
func _memdbDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) (r uintptr) {
	return (*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlOpen})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, zPath)
}

// C documentation
//
//	/*
//	** Populate the buffer zErrMsg (size nByte bytes) with a human readable
//	** utf-8 string describing the most recent error encountered associated
//	** with dynamic libraries.
//	*/
func _memdbDlError(tls *libc.TLS, pVfs uintptr, nByte int32, zErrMsg uintptr) {
	(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlError})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, nByte, zErrMsg)
}

// C documentation
//
//	/*
//	** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
//	*/
func _memdbDlSym(tls *libc.TLS, pVfs uintptr, p uintptr, zSym uintptr) (r uintptr) {
	return (*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlSym})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, p, zSym)
}

// C documentation
//
//	/*
//	** Close the dynamic library handle pHandle.
//	*/
func _memdbDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlClose})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, pHandle)
}

// C documentation
//
//	/*
//	** Populate the buffer pointed to by zBufOut with nByte bytes of
//	** random data.
//	*/
func _memdbRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zBufOut uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxRandomness})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, nByte, zBufOut)
}

// C documentation
//
//	/*
//	** Sleep for nMicro microseconds. Return the number of microseconds
//	** actually slept.
//	*/
func _memdbSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxSleep})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, nMicro)
}

func _memdbGetLastError(tls *libc.TLS, pVfs uintptr, a int32, b uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxGetLastError})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, a, b)
}

func _memdbCurrentTimeInt64(tls *libc.TLS, pVfs uintptr, p uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxCurrentTimeInt64})))(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, p)
}

// C documentation
//
//	/*
//	** Translate a database connection pointer and schema name into a
//	** MemFile pointer.
//	*/
func _memdbFromDbSchema(tls *libc.TLS, db uintptr, zSchema uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pStore uintptr
	var rc int32
	var _ /* p at bp+0 */ uintptr
	_, _ = pStore, rc
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = Xsqlite3_file_control(tls, db, zSchema, int32(SQLITE_FCNTL_FILE_POINTER), bp)
	if rc != 0 {
		return uintptr(0)
	}
	if (*TMemFile)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FpMethods != uintptr(unsafe.Pointer(&_memdb_io_methods)) {
		return uintptr(0)
	}
	pStore = (*TMemFile)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpStore
	_memdbEnter(tls, pStore)
	if (*TMemStore)(unsafe.Pointer(pStore)).FzFName != uintptr(0) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	}
	_memdbLeave(tls, pStore)
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Return the serialization of a database
//	*/
func Xsqlite3_serialize(tls *libc.TLS, db uintptr, zSchema uintptr, piSize uintptr, mFlags uint32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iDb, nPage, pgno, rc, szPage, v1 int32
	var p, pBt, pOut, pPager, pStore, pTo, zSql uintptr
	var sz Tsqlite3_int64
	var _ /* pPage at bp+4 */ uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = iDb, nPage, p, pBt, pOut, pPager, pStore, pTo, pgno, rc, sz, szPage, zSql, v1
	szPage = 0
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	if zSchema == uintptr(0) {
		zSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
	}
	p = _memdbFromDbSchema(tls, db, zSchema)
	iDb = _sqlite3FindDbName(tls, db, zSchema)
	if piSize != 0 {
		*(*Tsqlite3_int64)(unsafe.Pointer(piSize)) = int64(-int32(1))
	}
	if iDb < 0 {
		return uintptr(0)
	}
	if p != 0 {
		pStore = (*TMemFile)(unsafe.Pointer(p)).FpStore
		if piSize != 0 {
			*(*Tsqlite3_int64)(unsafe.Pointer(piSize)) = (*TMemStore)(unsafe.Pointer(pStore)).Fsz
		}
		if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
			pOut = (*TMemStore)(unsafe.Pointer(pStore)).FaData
		} else {
			pOut = Xsqlite3_malloc64(tls, uint64((*TMemStore)(unsafe.Pointer(pStore)).Fsz))
			if pOut != 0 {
				libc.Xmemcpy(tls, pOut, (*TMemStore)(unsafe.Pointer(pStore)).FaData, uint32((*TMemStore)(unsafe.Pointer(pStore)).Fsz))
			}
		}
		return pOut
	}
	pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
	if pBt == uintptr(0) {
		return uintptr(0)
	}
	szPage = _sqlite3BtreeGetPageSize(tls, pBt)
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+5361, libc.VaList(bp+16, zSchema))
	if zSql != 0 {
		v1 = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
	} else {
		v1 = int32(SQLITE_NOMEM)
	}
	rc = v1
	Xsqlite3_free(tls, zSql)
	if rc != 0 {
		return uintptr(0)
	}
	rc = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != int32(SQLITE_ROW) {
		pOut = uintptr(0)
	} else {
		sz = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0) * int64(int64(szPage))
		if sz == 0 {
			Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
			Xsqlite3_exec(tls, db, __ccgo_ts+5384, uintptr(0), uintptr(0), uintptr(0))
			rc = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			if rc == int32(SQLITE_ROW) {
				sz = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0) * int64(int64(szPage))
			}
		}
		if piSize != 0 {
			*(*Tsqlite3_int64)(unsafe.Pointer(piSize)) = sz
		}
		if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
			pOut = uintptr(0)
		} else {
			pOut = Xsqlite3_malloc64(tls, uint64(uint64(sz)))
			if pOut != 0 {
				nPage = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
				pPager = _sqlite3BtreePager(tls, pBt)
				pgno = int32(1)
				for {
					if !(pgno <= nPage) {
						break
					}
					*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
					pTo = pOut + uintptr(int64(int64(szPage))*int64(pgno-libc.Int32FromInt32(1)))
					rc = _sqlite3PagerGet(tls, pPager, uint32(uint32(pgno)), bp+4, 0)
					if rc == SQLITE_OK {
						libc.Xmemcpy(tls, pTo, _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 4))), uint32(uint32(szPage)))
					} else {
						libc.Xmemset(tls, pTo, 0, uint32(uint32(szPage)))
					}
					_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
					goto _2
				_2:
					;
					pgno++
				}
			}
		}
	}
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return pOut
}

// 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)(unsafe.Pointer(bp)) = uintptr(0)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zSchema == uintptr(0) {
		zSchema = (*(*TDb)(unsafe.Pointer((*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+5409, 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 = uint8(uint8(iDb))
	libc.SetBitFieldPtr8Uint32(db+172+8, libc.Uint32FromInt32(1), 2, 0x4)
	rc = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	libc.SetBitFieldPtr8Uint32(db+172+8, libc.Uint32FromInt32(0), 2, 0x4)
	if rc != int32(SQLITE_DONE) {
		rc = int32(SQLITE_ERROR)
		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:
	;
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	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 if the VFS is the memvfs.
//	*/
func _sqlite3IsMemdb(tls *libc.TLS, pVfs uintptr) (r int32) {
	return libc.BoolInt32(pVfs == uintptr(unsafe.Pointer(&_memdb_vfs)))
}

// C documentation
//
//	/*
//	** This routine is called when the extension is loaded.
//	** Register the new VFS.
//	*/
func _sqlite3MemdbInit(tls *libc.TLS) (r int32) {
	var pLower uintptr
	var sz uint32
	_, _ = pLower, sz
	pLower = Xsqlite3_vfs_find(tls, uintptr(0))
	if pLower == uintptr(0) {
		return int32(SQLITE_ERROR)
	}
	sz = uint32((*Tsqlite3_vfs)(unsafe.Pointer(pLower)).FszOsFile)
	_memdb_vfs.FpAppData = pLower
	/* The following conditional can only be true when compiled for
	 ** Windows x86 and SQLITE_MAX_MMAP_SIZE=0.  We always leave
	 ** it in, to be safe, but it is marked as NO_TEST since there
	 ** is no way to reach it under most builds. */
	if sz < uint32(12) {
		sz = uint32(12)
	} /*NO_TEST*/
	_memdb_vfs.FszOsFile = int32(int32(sz))
	return Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&_memdb_vfs)), 0)
}

/************** End of memdb.c ***********************************************/
/************** Begin file bitvec.c ******************************************/
/*
** 2008 February 16
**
** 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 implements an object that represents a fixed-length
** bitmap.  Bits are numbered starting with 1.
**
** A bitmap is used to record which pages of a database file have been
** journalled during a transaction, or which pages have the "dont-write"
** property.  Usually only a few pages are meet either condition.
** So the bitmap is usually sparse and has low cardinality.
** But sometimes (for example when during a DROP of a large table) most
** or all of the pages in a database can get journalled.  In those cases,
** the bitmap becomes dense with high cardinality.  The algorithm needs
** to handle both cases well.
**
** The size of the bitmap is fixed when the object is created.
**
** All bits are clear when the bitmap is created.  Individual bits
** may be set or cleared one at a time.
**
** Test operations are about 100 times more common that set operations.
** Clear operations are exceedingly rare.  There are usually between
** 5 and 500 set operations per Bitvec object, though the number of sets can
** sometimes grow into tens of thousands or larger.  The size of the
** Bitvec object is the number of pages in the database file at the
** start of a transaction, and is thus usually less than a few thousand,
** but can be as large as 2 billion for a really big database.
 */
/* #include "sqliteInt.h" */

/* Size of the Bitvec structure in bytes. */

/* Round the union size down to the nearest pointer boundary, since that's how
** it will be aligned within the Bitvec struct. */

/* Type of the array "element" for the bitmap representation.
** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE.
** Setting this to the "natural word" size of your CPU may improve
** performance. */
/* Size, in bits, of the bitmap element. */
/* Number of elements in a bitmap array. */
/* Number of bits in the bitmap array. */

/* Number of u32 values in hash table. */
/* Maximum number of entries in hash table before
** sub-dividing and re-hashing. */
/* Hashing function for the aHash representation.
** Empirical testing showed that the *37 multiplier
** (an arbitrary prime)in the hash function provided
** no fewer collisions than the no-op *1. */

/*
** A bitmap is an instance of the following structure.
**
** This bitmap records the existence of zero or more bits
** with values between 1 and iSize, inclusive.
**
** There are three possible representations of the bitmap.
** If iSize<=BITVEC_NBIT, then Bitvec.u.aBitmap[] is a straight
** bitmap.  The least significant bit is bit 1.
**
** If iSize>BITVEC_NBIT and iDivisor==0 then Bitvec.u.aHash[] is
** a hash table that will hold up to BITVEC_MXHASH distinct values.
**
** Otherwise, the value i is redirected into one of BITVEC_NPTR
** sub-bitmaps pointed to by Bitvec.u.apSub[].  Each subbitmap
** handles up to iDivisor separate values of i.  apSub[0] holds
** values between 1 and iDivisor.  apSub[1] holds values between
** iDivisor+1 and 2*iDivisor.  apSub[N] holds values between
** N*iDivisor+1 and (N+1)*iDivisor.  Each subbitmap is normalized
** to hold deal with values between 1 and iDivisor.
 */
type TBitvec1 = struct {
	FiSize    Tu32
	FnSet     Tu32
	FiDivisor Tu32
	Fu        struct {
		FaHash   [0][125]Tu32
		FapSub   [0][125]uintptr
		FaBitmap [500]Tu8
	}
}

type Bitvec1 = TBitvec1

// C documentation
//
//	/*
//	** Create a new bitmap object able to handle bits between 0 and iSize,
//	** inclusive.  Return a pointer to the new object.  Return NULL if
//	** malloc fails.
//	*/
func _sqlite3BitvecCreate(tls *libc.TLS, iSize Tu32) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3MallocZero(tls, uint64(512))
	if p != 0 {
		(*TBitvec)(unsafe.Pointer(p)).FiSize = iSize
	}
	return p
}

// C documentation
//
//	/*
//	** Check to see if the i-th bit is set.  Return true or false.
//	** If p is NULL (if the bitmap has not been created) or if
//	** i is out of range, then return false.
//	*/
func _sqlite3BitvecTestNotNull(tls *libc.TLS, p uintptr, i Tu32) (r int32) {
	var bin, h, v1 Tu32
	_, _, _ = bin, h, v1
	i--
	if i >= (*TBitvec)(unsafe.Pointer(p)).FiSize {
		return 0
	}
	for (*TBitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		bin = i / (*TBitvec)(unsafe.Pointer(p)).FiDivisor
		i = i % (*TBitvec)(unsafe.Pointer(p)).FiDivisor
		p = *(*uintptr)(unsafe.Pointer(p + 12 + uintptr(bin)*4))
		if !(p != 0) {
			return 0
		}
	}
	if (*TBitvec)(unsafe.Pointer(p)).FiSize <= (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(1)*libc.Uint32FromInt32(BITVEC_SZELEM) {
		return libc.BoolInt32(int32(*(*Tu8)(unsafe.Pointer(p + 12 + uintptr(i/uint32(BITVEC_SZELEM)))))&(int32(1)<<(i&uint32(libc.Int32FromInt32(BITVEC_SZELEM)-libc.Int32FromInt32(1)))) != 0)
	} else {
		v1 = i
		i++
		h = v1 * libc.Uint32FromInt32(1) % ((libc.Uint32FromInt32(BITVEC_SZ) - libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4)) / libc.Uint32FromInt64(4) * libc.Uint32FromInt64(4) / libc.Uint32FromInt64(4))
		for *(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) != 0 {
			if *(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) == i {
				return int32(1)
			}
			h = (h + uint32(1)) % ((libc.Uint32FromInt32(BITVEC_SZ) - libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4)) / libc.Uint32FromInt64(4) * libc.Uint32FromInt64(4) / libc.Uint32FromInt64(4))
		}
		return 0
	}
	return r
}

func _sqlite3BitvecTest(tls *libc.TLS, p uintptr, i Tu32) (r int32) {
	return libc.BoolInt32(p != uintptr(0) && _sqlite3BitvecTestNotNull(tls, p, i) != 0)
}

// C documentation
//
//	/*
//	** Set the i-th bit.  Return 0 on success and an error code if
//	** anything goes wrong.
//	**
//	** This routine might cause sub-bitmaps to be allocated.  Failing
//	** to get the memory needed to hold the sub-bitmap is the only
//	** that can go wrong with an insert, assuming p and i are valid.
//	**
//	** The calling function must ensure that p is a valid Bitvec object
//	** and that the value for "i" is within range of the Bitvec object.
//	** Otherwise the behavior is undefined.
//	*/
func _sqlite3BitvecSet(tls *libc.TLS, p uintptr, i Tu32) (r int32) {
	var aiValues, p1 uintptr
	var bin, h, v2 Tu32
	var j uint32
	var rc int32
	_, _, _, _, _, _, _ = aiValues, bin, h, j, rc, v2, p1
	if p == uintptr(0) {
		return SQLITE_OK
	}
	i--
	for (*TBitvec)(unsafe.Pointer(p)).FiSize > (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(1)*libc.Uint32FromInt32(BITVEC_SZELEM) && (*TBitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		bin = i / (*TBitvec)(unsafe.Pointer(p)).FiDivisor
		i = i % (*TBitvec)(unsafe.Pointer(p)).FiDivisor
		if *(*uintptr)(unsafe.Pointer(p + 12 + uintptr(bin)*4)) == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(p + 12 + uintptr(bin)*4)) = _sqlite3BitvecCreate(tls, (*TBitvec)(unsafe.Pointer(p)).FiDivisor)
			if *(*uintptr)(unsafe.Pointer(p + 12 + uintptr(bin)*4)) == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
		}
		p = *(*uintptr)(unsafe.Pointer(p + 12 + uintptr(bin)*4))
	}
	if (*TBitvec)(unsafe.Pointer(p)).FiSize <= (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(1)*libc.Uint32FromInt32(BITVEC_SZELEM) {
		p1 = p + 12 + uintptr(i/uint32(BITVEC_SZELEM))
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(1)<<(i&uint32(libc.Int32FromInt32(BITVEC_SZELEM)-libc.Int32FromInt32(1))))
		return SQLITE_OK
	}
	v2 = i
	i++
	h = v2 * libc.Uint32FromInt32(1) % ((libc.Uint32FromInt32(BITVEC_SZ) - libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4)) / libc.Uint32FromInt64(4) * libc.Uint32FromInt64(4) / libc.Uint32FromInt64(4))
	/* if there wasn't a hash collision, and this doesn't */
	/* completely fill the hash, then just add it without */
	/* worrying about sub-dividing and re-hashing. */
	if !(*(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) != 0) {
		if (*TBitvec)(unsafe.Pointer(p)).FnSet < (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)-libc.Uint32FromInt32(1) {
			goto bitvec_set_end
		} else {
			goto bitvec_set_rehash
		}
	}
	/* there was a collision, check to see if it's already */
	/* in hash, if not, try to find a spot for it */
	for cond := true; cond; cond = *(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) != 0 {
		if *(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) == i {
			return SQLITE_OK
		}
		h++
		if h >= (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4) {
			h = uint32(0)
		}
	}
	/* we didn't find it in the hash.  h points to the first */
	/* available free spot. check to see if this is going to */
	/* make our hash too "full".  */
	goto bitvec_set_rehash
bitvec_set_rehash:
	;
	if (*TBitvec)(unsafe.Pointer(p)).FnSet >= (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)/libc.Uint32FromInt32(2) {
		aiValues = _sqlite3DbMallocRaw(tls, uintptr(0), uint64(500))
		if aiValues == uintptr(0) {
			return int32(SQLITE_NOMEM)
		} else {
			libc.Xmemcpy(tls, aiValues, p+12, uint32(500))
			libc.Xmemset(tls, p+12, 0, uint32(500))
			(*TBitvec)(unsafe.Pointer(p)).FiDivisor = ((*TBitvec)(unsafe.Pointer(p)).FiSize + (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4) - uint32(1)) / ((libc.Uint32FromInt32(BITVEC_SZ) - libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4)) / libc.Uint32FromInt64(4) * libc.Uint32FromInt64(4) / libc.Uint32FromInt64(4))
			rc = _sqlite3BitvecSet(tls, p, i)
			j = uint32(0)
			for {
				if !(j < (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)) {
					break
				}
				if *(*Tu32)(unsafe.Pointer(aiValues + uintptr(j)*4)) != 0 {
					rc |= _sqlite3BitvecSet(tls, p, *(*Tu32)(unsafe.Pointer(aiValues + uintptr(j)*4)))
				}
				goto _3
			_3:
				;
				j++
			}
			_sqlite3DbFree(tls, uintptr(0), aiValues)
			return rc
		}
	}
	goto bitvec_set_end
bitvec_set_end:
	;
	(*TBitvec)(unsafe.Pointer(p)).FnSet++
	*(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) = i
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Clear the i-th bit.
//	**
//	** pBuf must be a pointer to at least BITVEC_SZ bytes of temporary storage
//	** that BitvecClear can use to rebuilt its hash table.
//	*/
func _sqlite3BitvecClear(tls *libc.TLS, p uintptr, i Tu32, pBuf uintptr) {
	var aiValues, p1 uintptr
	var bin, h Tu32
	var j uint32
	_, _, _, _, _ = aiValues, bin, h, j, p1
	if p == uintptr(0) {
		return
	}
	i--
	for (*TBitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		bin = i / (*TBitvec)(unsafe.Pointer(p)).FiDivisor
		i = i % (*TBitvec)(unsafe.Pointer(p)).FiDivisor
		p = *(*uintptr)(unsafe.Pointer(p + 12 + uintptr(bin)*4))
		if !(p != 0) {
			return
		}
	}
	if (*TBitvec)(unsafe.Pointer(p)).FiSize <= (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(1)*libc.Uint32FromInt32(BITVEC_SZELEM) {
		p1 = p + 12 + uintptr(i/uint32(BITVEC_SZELEM))
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(1) << (i & uint32(libc.Int32FromInt32(BITVEC_SZELEM)-libc.Int32FromInt32(1)))))
	} else {
		aiValues = pBuf
		libc.Xmemcpy(tls, aiValues, p+12, uint32(500))
		libc.Xmemset(tls, p+12, 0, uint32(500))
		(*TBitvec)(unsafe.Pointer(p)).FnSet = uint32(0)
		j = uint32(0)
		for {
			if !(j < (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)) {
				break
			}
			if *(*Tu32)(unsafe.Pointer(aiValues + uintptr(j)*4)) != 0 && *(*Tu32)(unsafe.Pointer(aiValues + uintptr(j)*4)) != i+uint32(1) {
				h = (*(*Tu32)(unsafe.Pointer(aiValues + uintptr(j)*4)) - libc.Uint32FromInt32(1)) * libc.Uint32FromInt32(1) % ((libc.Uint32FromInt32(BITVEC_SZ) - libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4)) / libc.Uint32FromInt64(4) * libc.Uint32FromInt64(4) / libc.Uint32FromInt64(4))
				(*TBitvec)(unsafe.Pointer(p)).FnSet++
				for *(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) != 0 {
					h++
					if h >= (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4) {
						h = uint32(0)
					}
				}
				*(*Tu32)(unsafe.Pointer(p + 12 + uintptr(h)*4)) = *(*Tu32)(unsafe.Pointer(aiValues + uintptr(j)*4))
			}
			goto _2
		_2:
			;
			j++
		}
	}
}

// C documentation
//
//	/*
//	** Destroy a bitmap object.  Reclaim all memory used.
//	*/
func _sqlite3BitvecDestroy(tls *libc.TLS, p uintptr) {
	var i uint32
	_ = i
	if p == uintptr(0) {
		return
	}
	if (*TBitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		i = uint32(0)
		for {
			if !(i < (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)) {
				break
			}
			_sqlite3BitvecDestroy(tls, *(*uintptr)(unsafe.Pointer(p + 12 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
	}
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Return the value of the iSize parameter specified when Bitvec *p
//	** was created.
//	*/
func _sqlite3BitvecSize(tls *libc.TLS, p uintptr) (r Tu32) {
	return (*TBitvec)(unsafe.Pointer(p)).FiSize
}

/*
** Let V[] be an array of unsigned characters sufficient to hold
** up to N bits.  Let I be an integer between 0 and N.  0<=I<N.
** Then the following macros can be used to set, clear, or test
** individual bits within V.
 */

// C documentation
//
//	/*
//	** This routine runs an extensive test of the Bitvec code.
//	**
//	** The input is an array of integers that acts as a program
//	** to test the Bitvec.  The integers are opcodes followed
//	** by 0, 1, or 3 operands, depending on the opcode.  Another
//	** opcode follows immediately after the last operand.
//	**
//	** There are 6 opcodes numbered from 0 through 5.  0 is the
//	** "halt" opcode and causes the test to end.
//	**
//	**    0          Halt and return the number of errors
//	**    1 N S X    Set N bits beginning with S and incrementing by X
//	**    2 N S X    Clear N bits beginning with S and incrementing by X
//	**    3 N        Set N randomly chosen bits
//	**    4 N        Clear N randomly chosen bits
//	**    5 N S X    Set N bits from S increment X in array only, not in bitvec
//	**
//	** The opcodes 1 through 4 perform set and clear operations are performed
//	** on both a Bitvec object and on a linear array of bits obtained from malloc.
//	** Opcode 5 works on the linear array only, not on the Bitvec.
//	** Opcode 5 is used to deliberately induce a fault in order to
//	** confirm that error detection works.
//	**
//	** At the conclusion of the test the linear array is compared
//	** against the Bitvec object.  If there are any differences,
//	** an error is returned.  If they are the same, zero is returned.
//	**
//	** If a memory allocation error occurs, return -1.
//	*/
func _sqlite3BitvecBuiltinTest(tls *libc.TLS, sz int32, aOp uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nx, op, pc, rc, v1, v2, v3 int32
	var pBitvec, pTmpSpace, pV, v4, p5, p6 uintptr
	var _ /* i at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = nx, op, pBitvec, pTmpSpace, pV, pc, rc, v1, v2, v3, v4, p5, p6
	pBitvec = uintptr(0)
	pV = uintptr(0)
	rc = -int32(1)
	/* Allocate the Bitvec to be tested and a linear array of
	 ** bits to act as the reference */
	pBitvec = _sqlite3BitvecCreate(tls, uint32(uint32(sz)))
	pV = _sqlite3MallocZero(tls, uint64((sz+int32(7))/int32(8)+int32(1)))
	pTmpSpace = Xsqlite3_malloc64(tls, uint64(BITVEC_SZ))
	if pBitvec == uintptr(0) || pV == uintptr(0) || pTmpSpace == uintptr(0) {
		goto bitvec_end
	}
	/* NULL pBitvec tests */
	_sqlite3BitvecSet(tls, uintptr(0), uint32(1))
	_sqlite3BitvecClear(tls, uintptr(0), uint32(1), pTmpSpace)
	/* Run the program */
	v1 = libc.Int32FromInt32(0)
	*(*int32)(unsafe.Pointer(bp)) = v1
	pc = v1
	for {
		v2 = *(*int32)(unsafe.Pointer(aOp + uintptr(pc)*4))
		op = v2
		if !(v2 != 0) {
			break
		}
		switch op {
		case int32(1):
			fallthrough
		case int32(2):
			fallthrough
		case int32(5):
			nx = int32(4)
			*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(aOp + uintptr(pc+int32(2))*4)) - int32(1)
			*(*int32)(unsafe.Pointer(aOp + uintptr(pc+int32(2))*4)) += *(*int32)(unsafe.Pointer(aOp + uintptr(pc+int32(3))*4))
		case int32(3):
			fallthrough
		case int32(4):
			fallthrough
		default:
			nx = int32(2)
			Xsqlite3_randomness(tls, int32(4), bp)
			break
		}
		v4 = aOp + uintptr(pc+int32(1))*4
		*(*int32)(unsafe.Pointer(v4))--
		v3 = *(*int32)(unsafe.Pointer(v4))
		if v3 > 0 {
			nx = 0
		}
		pc += nx
		*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(bp)) & int32(0x7fffffff) % sz
		if op&int32(1) != 0 {
			p5 = pV + uintptr((*(*int32)(unsafe.Pointer(bp))+int32(1))>>int32(3))
			*(*uint8)(unsafe.Pointer(p5)) = uint8(int32(*(*uint8)(unsafe.Pointer(p5))) | libc.Int32FromInt32(1)<<((*(*int32)(unsafe.Pointer(bp))+libc.Int32FromInt32(1))&libc.Int32FromInt32(7)))
			if op != int32(5) {
				if _sqlite3BitvecSet(tls, pBitvec, uint32(*(*int32)(unsafe.Pointer(bp))+int32(1))) != 0 {
					goto bitvec_end
				}
			}
		} else {
			p6 = pV + uintptr((*(*int32)(unsafe.Pointer(bp))+int32(1))>>int32(3))
			*(*uint8)(unsafe.Pointer(p6)) = uint8(int32(*(*uint8)(unsafe.Pointer(p6))) & ^(libc.Int32FromInt32(1) << ((*(*int32)(unsafe.Pointer(bp)) + libc.Int32FromInt32(1)) & libc.Int32FromInt32(7))))
			_sqlite3BitvecClear(tls, pBitvec, uint32(*(*int32)(unsafe.Pointer(bp))+int32(1)), pTmpSpace)
		}
	}
	/* Test to make sure the linear array exactly matches the
	 ** Bitvec object.  Start with the assumption that they do
	 ** match (rc==0).  Change rc to non-zero if a discrepancy
	 ** is found.
	 */
	rc = int32(uint32(_sqlite3BitvecTest(tls, uintptr(0), uint32(0))+_sqlite3BitvecTest(tls, pBitvec, uint32(sz+int32(1)))+_sqlite3BitvecTest(tls, pBitvec, uint32(0))) + (_sqlite3BitvecSize(tls, pBitvec) - uint32(uint32(sz))))
	*(*int32)(unsafe.Pointer(bp)) = int32(1)
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) <= sz) {
			break
		}
		if libc.BoolInt32(int32(*(*uint8)(unsafe.Pointer(pV + uintptr(*(*int32)(unsafe.Pointer(bp))>>int32(3)))))&(int32(1)<<(*(*int32)(unsafe.Pointer(bp))&int32(7))) != 0) != _sqlite3BitvecTest(tls, pBitvec, uint32(*(*int32)(unsafe.Pointer(bp)))) {
			rc = *(*int32)(unsafe.Pointer(bp))
			break
		}
		goto _7
	_7:
		;
		*(*int32)(unsafe.Pointer(bp))++
	}
	/* Free allocated structure */
	goto bitvec_end
bitvec_end:
	;
	Xsqlite3_free(tls, pTmpSpace)
	Xsqlite3_free(tls, pV)
	_sqlite3BitvecDestroy(tls, pBitvec)
	return rc
}

/************** End of bitvec.c **********************************************/
/************** Begin file pcache.c ******************************************/
/*
** 2008 August 05
**
** 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 implements that page cache.
 */
/* #include "sqliteInt.h" */

/*
** A complete page cache is an instance of this structure.  Every
** entry in the cache holds a single page of the database file.  The
** btree layer only operates on the cached copy of the database pages.
**
** A page cache entry is "clean" if it exactly matches what is currently
** on disk.  A page is "dirty" if it has been modified and needs to be
** persisted to disk.
**
** pDirty, pDirtyTail, pSynced:
**   All dirty pages are linked into the doubly linked list using
**   PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order
**   such that p was added to the list more recently than p->pDirtyNext.
**   PCache.pDirty points to the first (newest) element in the list and
**   pDirtyTail to the last (oldest).
**
**   The PCache.pSynced variable is used to optimize searching for a dirty
**   page to eject from the cache mid-transaction. It is better to eject
**   a page that does not require a journal sync than one that does.
**   Therefore, pSynced is maintained so that it *almost* always points
**   to either the oldest page in the pDirty/pDirtyTail list that has a
**   clear PGHDR_NEED_SYNC flag or to a page that is older than this one
**   (so that the right page to eject can be found by following pDirtyPrev
**   pointers).
 */
type TPCache2 = struct {
	F__ccgo_align  [0]uint32
	FpDirty        uintptr
	FpDirtyTail    uintptr
	FpSynced       uintptr
	F__ccgo_align3 [4]byte
	FnRefSum       Ti64
	FszCache       int32
	FszSpill       int32
	FszPage        int32
	FszExtra       int32
	FbPurgeable    Tu8
	FeCreate       Tu8
	FxStress       uintptr
	FpStress       uintptr
	FpCache        uintptr
}

type PCache2 = TPCache2

/********************************** Test and Debug Logic **********************/
/*
** Debug tracing macros.  Enable by by changing the "0" to "1" and
** recompiling.
**
** When sqlite3PcacheTrace is 1, single line trace messages are issued.
** When sqlite3PcacheTrace is 2, a dump of the pcache showing all cache entries
** is displayed for many operations, resulting in a lot of output.
 */

/*
** Return 1 if pPg is on the dirty list for pCache.  Return 0 if not.
** This routine runs inside of assert() statements only.
 */

/*
** Check invariants on a PgHdr entry.  Return true if everything is OK.
** Return false if any invariant is violated.
**
** This routine is for use inside of assert() statements only.  For
** example:
**
**          assert( sqlite3PcachePageSanity(pPg) );
 */

/********************************** Linked List Management ********************/

/* Allowed values for second argument to pcacheManageDirtyList() */

// C documentation
//
//	/*
//	** Manage pPage's participation on the dirty list.  Bits of the addRemove
//	** argument determines what operation to do.  The 0x01 bit means first
//	** remove pPage from the dirty list.  The 0x02 means add pPage back to
//	** the dirty list.  Doing both moves pPage to the front of the dirty list.
//	*/
func _pcacheManageDirtyList(tls *libc.TLS, pPage uintptr, addRemove Tu8) {
	var p uintptr
	_ = p
	p = (*TPgHdr)(unsafe.Pointer(pPage)).FpCache
	if int32(int32(addRemove))&int32(PCACHE_DIRTYLIST_REMOVE) != 0 {
		/* Update the PCache1.pSynced variable if necessary. */
		if (*TPCache)(unsafe.Pointer(p)).FpSynced == pPage {
			(*TPCache)(unsafe.Pointer(p)).FpSynced = (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev
		}
		if (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyNext != 0 {
			(*TPgHdr)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyNext)).FpDirtyPrev = (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev
		} else {
			(*TPCache)(unsafe.Pointer(p)).FpDirtyTail = (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev
		}
		if (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev != 0 {
			(*TPgHdr)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev)).FpDirtyNext = (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyNext
		} else {
			/* If there are now no dirty pages in the cache, set eCreate to 2.
			 ** This is an optimization that allows sqlite3PcacheFetch() to skip
			 ** searching for a dirty page to eject from the cache when it might
			 ** otherwise have to.  */
			(*TPCache)(unsafe.Pointer(p)).FpDirty = (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyNext
			if (*TPCache)(unsafe.Pointer(p)).FpDirty == uintptr(0) { /*OPTIMIZATION-IF-TRUE*/
				(*TPCache)(unsafe.Pointer(p)).FeCreate = uint8(2)
			}
		}
	}
	if int32(int32(addRemove))&int32(PCACHE_DIRTYLIST_ADD) != 0 {
		(*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev = uintptr(0)
		(*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyNext = (*TPCache)(unsafe.Pointer(p)).FpDirty
		if (*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyNext != 0 {
			(*TPgHdr)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(pPage)).FpDirtyNext)).FpDirtyPrev = pPage
		} else {
			(*TPCache)(unsafe.Pointer(p)).FpDirtyTail = pPage
			if (*TPCache)(unsafe.Pointer(p)).FbPurgeable != 0 {
				(*TPCache)(unsafe.Pointer(p)).FeCreate = uint8(1)
			}
		}
		(*TPCache)(unsafe.Pointer(p)).FpDirty = pPage
		/* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
		 ** pSynced to point to it. Checking the NEED_SYNC flag is an
		 ** optimization, as if pSynced points to a page with the NEED_SYNC
		 ** flag set sqlite3PcacheFetchStress() searches through all newer
		 ** entries of the dirty-list for a page with NEED_SYNC clear anyway.  */
		if !((*TPCache)(unsafe.Pointer(p)).FpSynced != 0) && 0 == int32((*TPgHdr)(unsafe.Pointer(pPage)).Fflags)&int32(PGHDR_NEED_SYNC) {
			(*TPCache)(unsafe.Pointer(p)).FpSynced = pPage
		}
	}
}

// C documentation
//
//	/*
//	** Wrapper around the pluggable caches xUnpin method. If the cache is
//	** being used for an in-memory database, this function is a no-op.
//	*/
func _pcacheUnpin(tls *libc.TLS, p uintptr) {
	if (*TPCache)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(p)).FpCache)).FbPurgeable != 0 {
		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxUnpin})))(tls, (*TPCache)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(p)).FpCache)).FpCache, (*TPgHdr)(unsafe.Pointer(p)).FpPage, 0)
	}
}

// C documentation
//
//	/*
//	** Compute the number of pages of cache requested.   p->szCache is the
//	** cache size requested by the "PRAGMA cache_size" statement.
//	*/
func _numberOfCachePages(tls *libc.TLS, p uintptr) (r int32) {
	var n Ti64
	_ = n
	if (*TPCache)(unsafe.Pointer(p)).FszCache >= 0 {
		/* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
		 ** suggested cache size is set to N. */
		return (*TPCache)(unsafe.Pointer(p)).FszCache
	} else {
		/* IMPLEMENTATION-OF: R-59858-46238 If the argument N is negative, then the
		 ** number of cache pages is adjusted to be a number of pages that would
		 ** use approximately abs(N*1024) bytes of memory based on the current
		 ** page size. */
		n = int64(-libc.Int32FromInt32(1024)) * int64((*TPCache)(unsafe.Pointer(p)).FszCache) / int64((*TPCache)(unsafe.Pointer(p)).FszPage+(*TPCache)(unsafe.Pointer(p)).FszExtra)
		if n > int64(1000000000) {
			n = int64(1000000000)
		}
		return int32(int32(n))
	}
	return r
}

// C documentation
//
//	/*************************************************** General Interfaces ******
//	**
//	** Initialize and shutdown the page cache subsystem. Neither of these
//	** functions are threadsafe.
//	*/
func _sqlite3PcacheInitialize(tls *libc.TLS) (r int32) {
	if _sqlite3Config.Fpcache2.FxInit == uintptr(0) {
		/* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the
		 ** built-in default page cache is used instead of the application defined
		 ** page cache. */
		_sqlite3PCacheSetDefault(tls)
	}
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxInit})))(tls, _sqlite3Config.Fpcache2.FpArg)
}

func _sqlite3PcacheShutdown(tls *libc.TLS) {
	if _sqlite3Config.Fpcache2.FxShutdown != 0 {
		/* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxShutdown})))(tls, _sqlite3Config.Fpcache2.FpArg)
	}
}

// C documentation
//
//	/*
//	** Return the size in bytes of a PCache object.
//	*/
func _sqlite3PcacheSize(tls *libc.TLS) (r int32) {
	return int32(56)
}

// C documentation
//
//	/*
//	** Create a new PCache object. Storage space to hold the object
//	** has already been allocated and is passed in as the p pointer.
//	** The caller discovers how much space needs to be allocated by
//	** calling sqlite3PcacheSize().
//	**
//	** szExtra is some extra space allocated for each page.  The first
//	** 8 bytes of the extra space will be zeroed as the page is allocated,
//	** but remaining content will be uninitialized.  Though it is opaque
//	** to this module, the extra space really ends up being the MemPage
//	** structure in the pager.
//	*/
func _sqlite3PcacheOpen(tls *libc.TLS, szPage int32, szExtra int32, bPurgeable int32, xStress uintptr, pStress uintptr, p uintptr) (r int32) {
	libc.Xmemset(tls, p, 0, uint32(56))
	(*TPCache)(unsafe.Pointer(p)).FszPage = int32(1)
	(*TPCache)(unsafe.Pointer(p)).FszExtra = szExtra
	/* First 8 bytes will be zeroed */
	(*TPCache)(unsafe.Pointer(p)).FbPurgeable = uint8(uint8(bPurgeable))
	(*TPCache)(unsafe.Pointer(p)).FeCreate = uint8(2)
	(*TPCache)(unsafe.Pointer(p)).FxStress = xStress
	(*TPCache)(unsafe.Pointer(p)).FpStress = pStress
	(*TPCache)(unsafe.Pointer(p)).FszCache = int32(100)
	(*TPCache)(unsafe.Pointer(p)).FszSpill = int32(1)
	return _sqlite3PcacheSetPageSize(tls, p, szPage)
}

// C documentation
//
//	/*
//	** Change the page size for PCache object. The caller must ensure that there
//	** are no outstanding page references when this function is called.
//	*/
func _sqlite3PcacheSetPageSize(tls *libc.TLS, pCache uintptr, szPage int32) (r int32) {
	var pNew uintptr
	_ = pNew
	if (*TPCache)(unsafe.Pointer(pCache)).FszPage != 0 {
		pNew = (*(*func(*libc.TLS, int32, int32, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxCreate})))(tls, szPage, int32(uint32((*TPCache)(unsafe.Pointer(pCache)).FszExtra)+(libc.Uint32FromInt64(48)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7))), int32((*TPCache)(unsafe.Pointer(pCache)).FbPurgeable))
		if pNew == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxCachesize})))(tls, pNew, _numberOfCachePages(tls, pCache))
		if (*TPCache)(unsafe.Pointer(pCache)).FpCache != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxDestroy})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache)
		}
		(*TPCache)(unsafe.Pointer(pCache)).FpCache = pNew
		(*TPCache)(unsafe.Pointer(pCache)).FszPage = szPage
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Try to obtain a page from the cache.
//	**
//	** This routine returns a pointer to an sqlite3_pcache_page object if
//	** such an object is already in cache, or if a new one is created.
//	** This routine returns a NULL pointer if the object was not in cache
//	** and could not be created.
//	**
//	** The createFlags should be 0 to check for existing pages and should
//	** be 3 (not 1, but 3) to try to create a new page.
//	**
//	** If the createFlag is 0, then NULL is always returned if the page
//	** is not already in the cache.  If createFlag is 1, then a new page
//	** is created only if that can be done without spilling dirty pages
//	** and without exceeding the cache size limit.
//	**
//	** The caller needs to invoke sqlite3PcacheFetchFinish() to properly
//	** initialize the sqlite3_pcache_page object and convert it into a
//	** PgHdr object.  The sqlite3PcacheFetch() and sqlite3PcacheFetchFinish()
//	** routines are split this way for performance reasons. When separated
//	** they can both (usually) operate without having to push values to
//	** the stack on entry and pop them back off on exit, which saves a
//	** lot of pushing and popping.
//	*/
func _sqlite3PcacheFetch(tls *libc.TLS, pCache uintptr, pgno TPgno, createFlag int32) (r uintptr) {
	var eCreate int32
	var pRes uintptr
	_, _ = eCreate, pRes
	/* eCreate defines what to do if the page does not exist.
	 **    0     Do not allocate a new page.  (createFlag==0)
	 **    1     Allocate a new page if doing so is inexpensive.
	 **          (createFlag==1 AND bPurgeable AND pDirty)
	 **    2     Allocate a new page even it doing so is difficult.
	 **          (createFlag==1 AND !(bPurgeable AND pDirty)
	 */
	eCreate = createFlag & int32((*TPCache)(unsafe.Pointer(pCache)).FeCreate)
	pRes = (*(*func(*libc.TLS, uintptr, uint32, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxFetch})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache, pgno, eCreate)
	return pRes
}

// C documentation
//
//	/*
//	** If the sqlite3PcacheFetch() routine is unable to allocate a new
//	** page because no clean pages are available for reuse and the cache
//	** size limit has been reached, then this routine can be invoked to
//	** try harder to allocate a page.  This routine might invoke the stress
//	** callback to spill dirty pages to the journal.  It will then try to
//	** allocate the new page and will only fail to allocate a new page on
//	** an OOM error.
//	**
//	** This routine should be invoked only after sqlite3PcacheFetch() fails.
//	*/
func _sqlite3PcacheFetchStress(tls *libc.TLS, pCache uintptr, pgno TPgno, ppPage uintptr) (r int32) {
	var pPg uintptr
	var rc, v3 int32
	_, _, _ = pPg, rc, v3
	if int32((*TPCache)(unsafe.Pointer(pCache)).FeCreate) == int32(2) {
		return 0
	}
	if _sqlite3PcachePagecount(tls, pCache) > (*TPCache)(unsafe.Pointer(pCache)).FszSpill {
		/* Find a dirty page to write-out and recycle. First try to find a
		 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
		 ** cleared), but if that is not possible settle for any other
		 ** unreferenced dirty page.
		 **
		 ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
		 ** flag is currently referenced, then the following may leave pSynced
		 ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
		 ** cleared). This is Ok, as pSynced is just an optimization.  */
		pPg = (*TPCache)(unsafe.Pointer(pCache)).FpSynced
		for {
			if !(pPg != 0 && ((*TPgHdr)(unsafe.Pointer(pPg)).FnRef != 0 || int32((*TPgHdr)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_NEED_SYNC) != 0)) {
				break
			}
			goto _1
		_1:
			;
			pPg = (*TPgHdr)(unsafe.Pointer(pPg)).FpDirtyPrev
		}
		(*TPCache)(unsafe.Pointer(pCache)).FpSynced = pPg
		if !(pPg != 0) {
			pPg = (*TPCache)(unsafe.Pointer(pCache)).FpDirtyTail
			for {
				if !(pPg != 0 && (*TPgHdr)(unsafe.Pointer(pPg)).FnRef != 0) {
					break
				}
				goto _2
			_2:
				;
				pPg = (*TPgHdr)(unsafe.Pointer(pPg)).FpDirtyPrev
			}
		}
		if pPg != 0 {
			rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPCache)(unsafe.Pointer(pCache)).FxStress})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpStress, pPg)
			if rc != SQLITE_OK && rc != int32(SQLITE_BUSY) {
				return rc
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppPage)) = (*(*func(*libc.TLS, uintptr, uint32, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxFetch})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache, pgno, int32(2))
	if *(*uintptr)(unsafe.Pointer(ppPage)) == uintptr(0) {
		v3 = int32(SQLITE_NOMEM)
	} else {
		v3 = SQLITE_OK
	}
	return v3
}

// C documentation
//
//	/*
//	** This is a helper routine for sqlite3PcacheFetchFinish()
//	**
//	** In the uncommon case where the page being fetched has not been
//	** initialized, this routine is invoked to do the initialization.
//	** This routine is broken out into a separate function since it
//	** requires extra stack manipulation that can be avoided in the common
//	** case.
//	*/
func _pcacheFetchFinishWithInit(tls *libc.TLS, pCache uintptr, pgno TPgno, pPage uintptr) (r uintptr) {
	var pPgHdr uintptr
	_ = pPgHdr
	pPgHdr = (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage)).FpExtra
	libc.Xmemset(tls, pPgHdr+16, 0, libc.Uint32FromInt64(48)-uint32(libc.UintptrFromInt32(0)+16))
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpPage = pPage
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpData = (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage)).FpBuf
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpExtra = pPgHdr + 1*48
	libc.Xmemset(tls, (*TPgHdr)(unsafe.Pointer(pPgHdr)).FpExtra, 0, uint32(8))
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpCache = pCache
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).Fpgno = pgno
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).Fflags = uint16(PGHDR_CLEAN)
	return _sqlite3PcacheFetchFinish(tls, pCache, pgno, pPage)
}

// C documentation
//
//	/*
//	** This routine converts the sqlite3_pcache_page object returned by
//	** sqlite3PcacheFetch() into an initialized PgHdr object.  This routine
//	** must be called after sqlite3PcacheFetch() in order to get a usable
//	** result.
//	*/
func _sqlite3PcacheFetchFinish(tls *libc.TLS, pCache uintptr, pgno TPgno, pPage uintptr) (r uintptr) {
	var pPgHdr uintptr
	_ = pPgHdr
	pPgHdr = (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage)).FpExtra
	if !((*TPgHdr)(unsafe.Pointer(pPgHdr)).FpPage != 0) {
		return _pcacheFetchFinishWithInit(tls, pCache, pgno, pPage)
	}
	(*TPCache)(unsafe.Pointer(pCache)).FnRefSum++
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FnRef++
	return pPgHdr
}

// C documentation
//
//	/*
//	** Decrement the reference count on a page. If the page is clean and the
//	** reference count drops to 0, then it is made eligible for recycling.
//	*/
func _sqlite3PcacheRelease(tls *libc.TLS, p uintptr) {
	var v1 Ti64
	var v2 uintptr
	_, _ = v1, v2
	(*TPCache)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(p)).FpCache)).FnRefSum--
	v2 = p + 32
	*(*Ti64)(unsafe.Pointer(v2))--
	v1 = *(*Ti64)(unsafe.Pointer(v2))
	if v1 == 0 {
		if int32((*TPgHdr)(unsafe.Pointer(p)).Fflags)&int32(PGHDR_CLEAN) != 0 {
			_pcacheUnpin(tls, p)
		} else {
			_pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_FRONT))
		}
	}
}

// C documentation
//
//	/*
//	** Increase the reference count of a supplied page by 1.
//	*/
func _sqlite3PcacheRef(tls *libc.TLS, p uintptr) {
	(*TPgHdr)(unsafe.Pointer(p)).FnRef++
	(*TPCache)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(p)).FpCache)).FnRefSum++
}

// C documentation
//
//	/*
//	** Drop a page from the cache. There must be exactly one reference to the
//	** page. This function deletes that reference, so after it returns the
//	** page pointed to by p is invalid.
//	*/
func _sqlite3PcacheDrop(tls *libc.TLS, p uintptr) {
	if int32((*TPgHdr)(unsafe.Pointer(p)).Fflags)&int32(PGHDR_DIRTY) != 0 {
		_pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_REMOVE))
	}
	(*TPCache)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(p)).FpCache)).FnRefSum--
	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxUnpin})))(tls, (*TPCache)(unsafe.Pointer((*TPgHdr)(unsafe.Pointer(p)).FpCache)).FpCache, (*TPgHdr)(unsafe.Pointer(p)).FpPage, int32(1))
}

// C documentation
//
//	/*
//	** Make sure the page is marked as dirty. If it isn't dirty already,
//	** make it so.
//	*/
func _sqlite3PcacheMakeDirty(tls *libc.TLS, p uintptr) {
	var p1, p2 uintptr
	_, _ = p1, p2
	if int32((*TPgHdr)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(PGHDR_CLEAN)|libc.Int32FromInt32(PGHDR_DONT_WRITE)) != 0 { /*OPTIMIZATION-IF-FALSE*/
		p1 = p + 28
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(PGHDR_DONT_WRITE))
		if int32((*TPgHdr)(unsafe.Pointer(p)).Fflags)&int32(PGHDR_CLEAN) != 0 {
			p2 = p + 28
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) ^ (libc.Int32FromInt32(PGHDR_DIRTY) | libc.Int32FromInt32(PGHDR_CLEAN)))
			_pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_ADD))
		}
	}
}

// C documentation
//
//	/*
//	** Make sure the page is marked as clean. If it isn't clean already,
//	** make it so.
//	*/
func _sqlite3PcacheMakeClean(tls *libc.TLS, p uintptr) {
	var p1, p2 uintptr
	_, _ = p1, p2
	_pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_REMOVE))
	p1 = p + 28
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(PGHDR_DIRTY) | libc.Int32FromInt32(PGHDR_NEED_SYNC) | libc.Int32FromInt32(PGHDR_WRITEABLE)))
	p2 = p + 28
	*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(PGHDR_CLEAN))
	if (*TPgHdr)(unsafe.Pointer(p)).FnRef == 0 {
		_pcacheUnpin(tls, p)
	}
}

// C documentation
//
//	/*
//	** Make every page in the cache clean.
//	*/
func _sqlite3PcacheCleanAll(tls *libc.TLS, pCache uintptr) {
	var p, v1 uintptr
	_, _ = p, v1
	for {
		v1 = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
		p = v1
		if !(v1 != uintptr(0)) {
			break
		}
		_sqlite3PcacheMakeClean(tls, p)
	}
}

// C documentation
//
//	/*
//	** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
//	*/
func _sqlite3PcacheClearWritable(tls *libc.TLS, pCache uintptr) {
	var p, p2 uintptr
	_, _ = p, p2
	p = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
	for {
		if !(p != 0) {
			break
		}
		p2 = p + 28
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^(libc.Int32FromInt32(PGHDR_NEED_SYNC) | libc.Int32FromInt32(PGHDR_WRITEABLE)))
		goto _1
	_1:
		;
		p = (*TPgHdr)(unsafe.Pointer(p)).FpDirtyNext
	}
	(*TPCache)(unsafe.Pointer(pCache)).FpSynced = (*TPCache)(unsafe.Pointer(pCache)).FpDirtyTail
}

// C documentation
//
//	/*
//	** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
//	*/
func _sqlite3PcacheClearSyncFlags(tls *libc.TLS, pCache uintptr) {
	var p, p2 uintptr
	_, _ = p, p2
	p = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
	for {
		if !(p != 0) {
			break
		}
		p2 = p + 28
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(PGHDR_NEED_SYNC))
		goto _1
	_1:
		;
		p = (*TPgHdr)(unsafe.Pointer(p)).FpDirtyNext
	}
	(*TPCache)(unsafe.Pointer(pCache)).FpSynced = (*TPCache)(unsafe.Pointer(pCache)).FpDirtyTail
}

// C documentation
//
//	/*
//	** Change the page number of page p to newPgno.
//	*/
func _sqlite3PcacheMove(tls *libc.TLS, p uintptr, newPgno TPgno) {
	var pCache, pOther, pXPage uintptr
	_, _, _ = pCache, pOther, pXPage
	pCache = (*TPgHdr)(unsafe.Pointer(p)).FpCache
	pOther = (*(*func(*libc.TLS, uintptr, uint32, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxFetch})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache, newPgno, 0)
	if pOther != 0 {
		pXPage = (*Tsqlite3_pcache_page)(unsafe.Pointer(pOther)).FpExtra
		(*TPgHdr)(unsafe.Pointer(pXPage)).FnRef++
		(*TPCache)(unsafe.Pointer(pCache)).FnRefSum++
		_sqlite3PcacheDrop(tls, pXPage)
	}
	(*(*func(*libc.TLS, uintptr, uintptr, uint32, uint32))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxRekey})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache, (*TPgHdr)(unsafe.Pointer(p)).FpPage, (*TPgHdr)(unsafe.Pointer(p)).Fpgno, newPgno)
	(*TPgHdr)(unsafe.Pointer(p)).Fpgno = newPgno
	if int32((*TPgHdr)(unsafe.Pointer(p)).Fflags)&int32(PGHDR_DIRTY) != 0 && int32((*TPgHdr)(unsafe.Pointer(p)).Fflags)&int32(PGHDR_NEED_SYNC) != 0 {
		_pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_FRONT))
	}
}

// C documentation
//
//	/*
//	** Drop every cache entry whose page number is greater than "pgno". The
//	** caller must ensure that there are no outstanding references to any pages
//	** other than page 1 with a page number greater than pgno.
//	**
//	** If there is a reference to page 1 and the pgno parameter passed to this
//	** function is 0, then the data area associated with page 1 is zeroed, but
//	** the page object is not dropped.
//	*/
func _sqlite3PcacheTruncate(tls *libc.TLS, pCache uintptr, pgno TPgno) {
	var p, pNext, pPage1 uintptr
	_, _, _ = p, pNext, pPage1
	if (*TPCache)(unsafe.Pointer(pCache)).FpCache != 0 {
		p = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
		for {
			if !(p != 0) {
				break
			}
			pNext = (*TPgHdr)(unsafe.Pointer(p)).FpDirtyNext
			/* This routine never gets call with a positive pgno except right
			 ** after sqlite3PcacheCleanAll().  So if there are dirty pages,
			 ** it must be that pgno==0.
			 */
			if (*TPgHdr)(unsafe.Pointer(p)).Fpgno > pgno {
				_sqlite3PcacheMakeClean(tls, p)
			}
			goto _1
		_1:
			;
			p = pNext
		}
		if pgno == uint32(0) && (*TPCache)(unsafe.Pointer(pCache)).FnRefSum != 0 {
			pPage1 = (*(*func(*libc.TLS, uintptr, uint32, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxFetch})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache, uint32(1), 0)
			if pPage1 != 0 { /* Page 1 is always available in cache, because
				 ** pCache->nRefSum>0 */
				libc.Xmemset(tls, (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage1)).FpBuf, 0, uint32((*TPCache)(unsafe.Pointer(pCache)).FszPage))
				pgno = uint32(1)
			}
		}
		(*(*func(*libc.TLS, uintptr, uint32))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxTruncate})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache, pgno+uint32(1))
	}
}

// C documentation
//
//	/*
//	** Close a cache.
//	*/
func _sqlite3PcacheClose(tls *libc.TLS, pCache uintptr) {
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxDestroy})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache)
}

// C documentation
//
//	/*
//	** Discard the contents of the cache.
//	*/
func _sqlite3PcacheClear(tls *libc.TLS, pCache uintptr) {
	_sqlite3PcacheTruncate(tls, pCache, uint32(0))
}

// C documentation
//
//	/*
//	** Merge two lists of pages connected by pDirty and in pgno order.
//	** Do not bother fixing the pDirtyPrev pointers.
//	*/
func _pcacheMergeDirtyList(tls *libc.TLS, pA uintptr, pB uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pTail uintptr
	var _ /* result at bp+0 */ TPgHdr
	_ = pTail
	pTail = bp
	for {
		if (*TPgHdr)(unsafe.Pointer(pA)).Fpgno < (*TPgHdr)(unsafe.Pointer(pB)).Fpgno {
			(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pA
			pTail = pA
			pA = (*TPgHdr)(unsafe.Pointer(pA)).FpDirty
			if pA == uintptr(0) {
				(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pB
				break
			}
		} else {
			(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pB
			pTail = pB
			pB = (*TPgHdr)(unsafe.Pointer(pB)).FpDirty
			if pB == uintptr(0) {
				(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pA
				break
			}
		}
		goto _1
	_1:
	}
	return (*(*TPgHdr)(unsafe.Pointer(bp))).FpDirty
}

// C documentation
//
//	/*
//	** Sort the list of pages in ascending order by pgno.  Pages are
//	** connected by pDirty pointers.  The pDirtyPrev pointers are
//	** corrupted by this sort.
//	**
//	** Since there cannot be more than 2^31 distinct pages in a database,
//	** there cannot be more than 31 buckets required by the merge sorter.
//	** One extra bucket is added to catch overflow in case something
//	** ever changes to make the previous sentence incorrect.
//	*/
func _pcacheSortDirtyList(tls *libc.TLS, pIn uintptr) (r uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var i int32
	var p, v3 uintptr
	var _ /* a at bp+0 */ [32]uintptr
	_, _, _ = i, p, v3
	libc.Xmemset(tls, bp, 0, uint32(128))
	for pIn != 0 {
		p = pIn
		pIn = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
		(*TPgHdr)(unsafe.Pointer(p)).FpDirty = uintptr(0)
		i = 0
		for {
			if !(i < libc.Int32FromInt32(N_SORT_BUCKET)-libc.Int32FromInt32(1)) {
				break
			}
			if (*(*[32]uintptr)(unsafe.Pointer(bp)))[i] == uintptr(0) {
				(*(*[32]uintptr)(unsafe.Pointer(bp)))[i] = p
				break
			} else {
				p = _pcacheMergeDirtyList(tls, (*(*[32]uintptr)(unsafe.Pointer(bp)))[i], p)
				(*(*[32]uintptr)(unsafe.Pointer(bp)))[i] = uintptr(0)
			}
			goto _1
		_1:
			;
			i++
		}
		if i == libc.Int32FromInt32(N_SORT_BUCKET)-libc.Int32FromInt32(1) {
			/* To get here, there need to be 2^(N_SORT_BUCKET) elements in
			 ** the input list.  But that is impossible.
			 */
			(*(*[32]uintptr)(unsafe.Pointer(bp)))[i] = _pcacheMergeDirtyList(tls, (*(*[32]uintptr)(unsafe.Pointer(bp)))[i], p)
		}
	}
	p = (*(*[32]uintptr)(unsafe.Pointer(bp)))[0]
	i = int32(1)
	for {
		if !(i < int32(N_SORT_BUCKET)) {
			break
		}
		if (*(*[32]uintptr)(unsafe.Pointer(bp)))[i] == uintptr(0) {
			goto _2
		}
		if p != 0 {
			v3 = _pcacheMergeDirtyList(tls, p, (*(*[32]uintptr)(unsafe.Pointer(bp)))[i])
		} else {
			v3 = (*(*[32]uintptr)(unsafe.Pointer(bp)))[i]
		}
		p = v3
		goto _2
	_2:
		;
		i++
	}
	return p
}

// C documentation
//
//	/*
//	** Return a list of all dirty pages in the cache, sorted by page number.
//	*/
func _sqlite3PcacheDirtyList(tls *libc.TLS, pCache uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
	for {
		if !(p != 0) {
			break
		}
		(*TPgHdr)(unsafe.Pointer(p)).FpDirty = (*TPgHdr)(unsafe.Pointer(p)).FpDirtyNext
		goto _1
	_1:
		;
		p = (*TPgHdr)(unsafe.Pointer(p)).FpDirtyNext
	}
	return _pcacheSortDirtyList(tls, (*TPCache)(unsafe.Pointer(pCache)).FpDirty)
}

// C documentation
//
//	/*
//	** Return the total number of references to all pages held by the cache.
//	**
//	** This is not the total number of pages referenced, but the sum of the
//	** reference count for all pages.
//	*/
func _sqlite3PcacheRefCount(tls *libc.TLS, pCache uintptr) (r Ti64) {
	return (*TPCache)(unsafe.Pointer(pCache)).FnRefSum
}

// C documentation
//
//	/*
//	** Return the number of references to the page supplied as an argument.
//	*/
func _sqlite3PcachePageRefcount(tls *libc.TLS, p uintptr) (r Ti64) {
	return (*TPgHdr)(unsafe.Pointer(p)).FnRef
}

// C documentation
//
//	/*
//	** Return the total number of pages in the cache.
//	*/
func _sqlite3PcachePagecount(tls *libc.TLS, pCache uintptr) (r int32) {
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxPagecount})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache)
}

// C documentation
//
//	/*
//	** Set the suggested cache-size value.
//	*/
func _sqlite3PcacheSetCachesize(tls *libc.TLS, pCache uintptr, mxPage int32) {
	(*TPCache)(unsafe.Pointer(pCache)).FszCache = mxPage
	(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxCachesize})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache, _numberOfCachePages(tls, pCache))
}

// C documentation
//
//	/*
//	** Set the suggested cache-spill value.  Make no changes if if the
//	** argument is zero.  Return the effective cache-spill size, which will
//	** be the larger of the szSpill and szCache.
//	*/
func _sqlite3PcacheSetSpillsize(tls *libc.TLS, p uintptr, mxPage int32) (r int32) {
	var res int32
	_ = res
	if mxPage != 0 {
		if mxPage < 0 {
			mxPage = int32(int64(-libc.Int32FromInt32(1024)) * int64(int64(mxPage)) / int64((*TPCache)(unsafe.Pointer(p)).FszPage+(*TPCache)(unsafe.Pointer(p)).FszExtra))
		}
		(*TPCache)(unsafe.Pointer(p)).FszSpill = mxPage
	}
	res = _numberOfCachePages(tls, p)
	if res < (*TPCache)(unsafe.Pointer(p)).FszSpill {
		res = (*TPCache)(unsafe.Pointer(p)).FszSpill
	}
	return res
}

// C documentation
//
//	/*
//	** Free up as much memory as possible from the page cache.
//	*/
func _sqlite3PcacheShrink(tls *libc.TLS, pCache uintptr) {
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{_sqlite3Config.Fpcache2.FxShrink})))(tls, (*TPCache)(unsafe.Pointer(pCache)).FpCache)
}

// C documentation
//
//	/*
//	** Return the size of the header added by this middleware layer
//	** in the page-cache hierarchy.
//	*/
func _sqlite3HeaderSizePcache(tls *libc.TLS) (r int32) {
	return int32((libc.Uint32FromInt64(48) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
}

// C documentation
//
//	/*
//	** Return the number of dirty pages currently in the cache, as a percentage
//	** of the configured cache size.
//	*/
func _sqlite3PCachePercentDirty(tls *libc.TLS, pCache uintptr) (r int32) {
	var nCache, nDirty, v2 int32
	var pDirty uintptr
	_, _, _, _ = nCache, nDirty, pDirty, v2
	nDirty = 0
	nCache = _numberOfCachePages(tls, pCache)
	pDirty = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
	for {
		if !(pDirty != 0) {
			break
		}
		nDirty++
		goto _1
	_1:
		;
		pDirty = (*TPgHdr)(unsafe.Pointer(pDirty)).FpDirtyNext
	}
	if nCache != 0 {
		v2 = int32(int64(int64(nDirty)) * libc.Int64FromInt32(100) / int64(int64(nCache)))
	} else {
		v2 = 0
	}
	return v2
}

// C documentation
//
//	/*
//	** Return true if there are one or more dirty pages in the cache. Else false.
//	*/
func _sqlite3PCacheIsDirty(tls *libc.TLS, pCache uintptr) (r int32) {
	return libc.BoolInt32((*TPCache)(unsafe.Pointer(pCache)).FpDirty != uintptr(0))
}

/************** End of pcache.c **********************************************/
/************** Begin file pcache1.c *****************************************/
/*
** 2008 November 05
**
** 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 implements the default page cache implementation (the
** sqlite3_pcache interface). It also contains part of the implementation
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
** If the default page cache implementation is overridden, then neither of
** these two features are available.
**
** A Page cache line looks like this:
**
**  -------------------------------------------------------------
**  |  database page content   |  PgHdr1  |  MemPage  |  PgHdr  |
**  -------------------------------------------------------------
**
** The database page content is up front (so that buffer overreads tend to
** flow harmlessly into the PgHdr1, MemPage, and PgHdr extensions).   MemPage
** is the extension added by the btree.c module containing information such
** as the database page number and how that database page is used.  PgHdr
** is added by the pcache.c layer and contains information used to keep track
** of which pages are "dirty".  PgHdr1 is an extension added by this
** module (pcache1.c).  The PgHdr1 header is a subclass of sqlite3_pcache_page.
** PgHdr1 contains information needed to look up a page by its page number.
** The superclass sqlite3_pcache_page.pBuf points to the start of the
** database page content and sqlite3_pcache_page.pExtra points to PgHdr.
**
** The size of the extension (MemPage+PgHdr+PgHdr1) can be determined at
** runtime using sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &size).  The
** sizes of the extensions sum to 272 bytes on x64 for 3.8.10, but this
** size can vary according to architecture, compile-time options, and
** SQLite library version number.
**
** Historical note:  It used to be that if the SQLITE_PCACHE_SEPARATE_HEADER
** was defined, then the page content would be held in a separate memory
** allocation from the PgHdr1.  This was intended to avoid clownshoe memory
** allocations.  However, the btree layer needs a small (16-byte) overrun
** area after the page content buffer.  The header serves as that overrun
** area.  Therefore SQLITE_PCACHE_SEPARATE_HEADER was discontinued to avoid
** any possibility of a memory error.
**
** This module tracks pointers to PgHdr1 objects.  Only pcache.c communicates
** with this module.  Information is passed back and forth as PgHdr1 pointers.
**
** The pcache.c and pager.c modules deal pointers to PgHdr objects.
** The btree.c module deals with pointers to MemPage objects.
**
** SOURCE OF PAGE CACHE MEMORY:
**
** Memory for a page might come from any of three sources:
**
**    (1)  The general-purpose memory allocator - sqlite3Malloc()
**    (2)  Global page-cache memory provided using sqlite3_config() with
**         SQLITE_CONFIG_PAGECACHE.
**    (3)  PCache-local bulk allocation.
**
** The third case is a chunk of heap memory (defaulting to 100 pages worth)
** that is allocated when the page cache is created.  The size of the local
** bulk allocation can be adjusted using
**
**     sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
**
** If N is positive, then N pages worth of memory are allocated using a single
** sqlite3Malloc() call and that memory is used for the first N pages allocated.
** Or if N is negative, then -1024*N bytes of memory are allocated and used
** for as many pages as can be accommodated.
**
** Only one of (2) or (3) can be used.  Once the memory available to (2) or
** (3) is exhausted, subsequent allocations fail over to the general-purpose
** memory allocator (1).
**
** Earlier versions of SQLite used only methods (1) and (2).  But experiments
** show that method (3) with N==100 provides about a 5% performance boost for
** common workloads.
 */
/* #include "sqliteInt.h" */

type TPCache1 = struct {
	FpGroup          uintptr
	FpnPurgeable     uintptr
	FszPage          int32
	FszExtra         int32
	FszAlloc         int32
	FbPurgeable      int32
	FnMin            uint32
	FnMax            uint32
	Fn90pct          uint32
	FiMaxKey         uint32
	FnPurgeableDummy uint32
	FnRecyclable     uint32
	FnPage           uint32
	FnHash           uint32
	FapHash          uintptr
	FpFree           uintptr
	FpBulk           uintptr
}

type PCache1 = TPCache1

type TPgHdr1 = struct {
	Fpage        Tsqlite3_pcache_page
	FiKey        uint32
	FisBulkLocal Tu16
	FisAnchor    Tu16
	FpNext       uintptr
	FpCache      uintptr
	FpLruNext    uintptr
	FpLruPrev    uintptr
}

type PgHdr1 = TPgHdr1

type TPgFreeslot = struct {
	FpNext uintptr
}

type PgFreeslot = TPgFreeslot

type TPGroup = struct {
	Fmutex      uintptr
	FnMaxPage   uint32
	FnMinPage   uint32
	FmxPinned   uint32
	FnPurgeable uint32
	Flru        TPgHdr1
}

type PGroup = TPGroup

/*
** Each cache entry is represented by an instance of the following
** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
** directly before this structure and is used to cache the page content.
**
** When reading a corrupt database file, it is possible that SQLite might
** read a few bytes (no more than 16 bytes) past the end of the page buffer.
** It will only read past the end of the page buffer, never write.  This
** object is positioned immediately after the page buffer to serve as an
** overrun area, so that overreads are harmless.
**
** Variables isBulkLocal and isAnchor were once type "u8". That works,
** but causes a 2-byte gap in the structure for most architectures (since
** pointers must be either 4 or 8-byte aligned). As this structure is located
** in memory directly after the associated page data, if the database is
** corrupt, code at the b-tree layer may overread the page buffer and
** read part of this structure before the corruption is detected. This
** can cause a valgrind error if the uninitialized gap is accessed. Using u16
** ensures there is no such gap, and therefore no bytes of uninitialized
** memory in the structure.
**
** The pLruNext and pLruPrev pointers form a double-linked circular list
** of all pages that are unpinned.  The PGroup.lru element (which should be
** the only element on the list with PgHdr1.isAnchor set to 1) forms the
** beginning and the end of the list.
 */
type TPgHdr11 = struct {
	Fpage        Tsqlite3_pcache_page
	FiKey        uint32
	FisBulkLocal Tu16
	FisAnchor    Tu16
	FpNext       uintptr
	FpCache      uintptr
	FpLruNext    uintptr
	FpLruPrev    uintptr
}

type PgHdr11 = TPgHdr11

/*
** A page is pinned if it is not on the LRU list.  To be "pinned" means
** that the page is in active use and must not be deallocated.
 */

/* Each page cache (or PCache) belongs to a PGroup.  A PGroup is a set
** of one or more PCaches that are able to recycle each other's unpinned
** pages when they are under memory pressure.  A PGroup is an instance of
** the following object.
**
** This page cache implementation works in one of two modes:
**
**   (1)  Every PCache is the sole member of its own PGroup.  There is
**        one PGroup per PCache.
**
**   (2)  There is a single global PGroup that all PCaches are a member
**        of.
**
** Mode 1 uses more memory (since PCache instances are not able to rob
** unused pages from other PCaches) but it also operates without a mutex,
** and is therefore often faster.  Mode 2 requires a mutex in order to be
** threadsafe, but recycles pages more efficiently.
**
** For mode (1), PGroup.mutex is NULL.  For mode (2) there is only a single
** PGroup which is the pcache1.grp global variable and its mutex is
** SQLITE_MUTEX_STATIC_LRU.
 */
type TPGroup1 = struct {
	Fmutex      uintptr
	FnMaxPage   uint32
	FnMinPage   uint32
	FmxPinned   uint32
	FnPurgeable uint32
	Flru        TPgHdr1
}

type PGroup1 = TPGroup1

/* Each page cache is an instance of the following object.  Every
** open database file (including each in-memory database and each
** temporary or transient database) has a single page cache which
** is an instance of this object.
**
** Pointers to structures of this type are cast and returned as
** opaque sqlite3_pcache* handles.
 */
type TPCache11 = struct {
	FpGroup          uintptr
	FpnPurgeable     uintptr
	FszPage          int32
	FszExtra         int32
	FszAlloc         int32
	FbPurgeable      int32
	FnMin            uint32
	FnMax            uint32
	Fn90pct          uint32
	FiMaxKey         uint32
	FnPurgeableDummy uint32
	FnRecyclable     uint32
	FnPage           uint32
	FnHash           uint32
	FapHash          uintptr
	FpFree           uintptr
	FpBulk           uintptr
}

type PCache11 = TPCache11

/*
** Free slots in the allocator used to divide up the global page cache
** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
 */
type TPgFreeslot1 = struct {
	FpNext uintptr
}

type PgFreeslot1 = TPgFreeslot1

// C documentation
//
//	/*
//	** Global data used by this cache.
//	*/
type TPCacheGlobal = struct {
	Fgrp            TPGroup
	FisInit         int32
	FseparateCache  int32
	FnInitPage      int32
	FszSlot         int32
	FnSlot          int32
	FnReserve       int32
	FpStart         uintptr
	FpEnd           uintptr
	Fmutex          uintptr
	FpFree          uintptr
	FnFreeSlot      int32
	FbUnderPressure int32
}

type PCacheGlobal = TPCacheGlobal

// C documentation
//
//	/*
//	** Global data used by this cache.
//	*/
var _pcache1_g TPCacheGlobal

/*
** All code in this file should access the global structure above via the
** alias "pcache1". This ensures that the WSD emulation is used when
** compiling for systems that do not support real WSD.
 */

/*
** Macros to enter and leave the PCache LRU mutex.
 */

/******************************************************************************/
/******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/

// C documentation
//
//	/*
//	** This function is called during initialization if a static buffer is
//	** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
//	** verb to sqlite3_config(). Parameter pBuf points to an allocation large
//	** enough to contain 'n' buffers of 'sz' bytes each.
//	**
//	** This routine is called from sqlite3_initialize() and so it is guaranteed
//	** to be serialized already.  There is no need for further mutexing.
//	*/
func _sqlite3PCacheBufferSetup(tls *libc.TLS, pBuf uintptr, sz int32, n int32) {
	var p uintptr
	var v1, v2, v3, v4 int32
	_, _, _, _, _ = p, v1, v2, v3, v4
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_pcache1_g))+52) != 0 {
		if pBuf == uintptr(0) {
			v1 = libc.Int32FromInt32(0)
			n = v1
			sz = v1
		}
		if n == 0 {
			sz = 0
		}
		sz = sz & ^libc.Int32FromInt32(7)
		_pcache1_g.FszSlot = sz
		v2 = n
		_pcache1_g.FnFreeSlot = v2
		_pcache1_g.FnSlot = v2
		if n > int32(90) {
			v3 = int32(10)
		} else {
			v3 = n/int32(10) + int32(1)
		}
		_pcache1_g.FnReserve = v3
		_pcache1_g.FpStart = pBuf
		_pcache1_g.FpFree = uintptr(0)
		_pcache1_g.FbUnderPressure = 0
		for {
			v4 = n
			n--
			if !(v4 != 0) {
				break
			}
			p = pBuf
			(*TPgFreeslot)(unsafe.Pointer(p)).FpNext = _pcache1_g.FpFree
			_pcache1_g.FpFree = p
			pBuf = pBuf + uintptr(sz)
		}
		_pcache1_g.FpEnd = pBuf
	}
}

// C documentation
//
//	/*
//	** Try to initialize the pCache->pFree and pCache->pBulk fields.  Return
//	** true if pCache->pFree ends up containing one or more free pages.
//	*/
func _pcache1InitBulk(tls *libc.TLS, pCache uintptr) (r int32) {
	var nBulk, v2 int32
	var pX, zBulk, v1 uintptr
	var szBulk Ti64
	_, _, _, _, _, _ = nBulk, pX, szBulk, zBulk, v1, v2
	if _pcache1_g.FnInitPage == 0 {
		return 0
	}
	/* Do not bother with a bulk allocation if the cache size very small */
	if (*TPCache1)(unsafe.Pointer(pCache)).FnMax < uint32(3) {
		return 0
	}
	_sqlite3BeginBenignMalloc(tls)
	if _pcache1_g.FnInitPage > 0 {
		szBulk = int64((*TPCache1)(unsafe.Pointer(pCache)).FszAlloc) * int64(_pcache1_g.FnInitPage)
	} else {
		szBulk = int64(-int32(1024)) * int64(_pcache1_g.FnInitPage)
	}
	if szBulk > int64((*TPCache1)(unsafe.Pointer(pCache)).FszAlloc)*int64((*TPCache1)(unsafe.Pointer(pCache)).FnMax) {
		szBulk = int64((*TPCache1)(unsafe.Pointer(pCache)).FszAlloc) * int64((*TPCache1)(unsafe.Pointer(pCache)).FnMax)
	}
	v1 = _sqlite3Malloc(tls, uint64(uint64(szBulk)))
	(*TPCache1)(unsafe.Pointer(pCache)).FpBulk = v1
	zBulk = v1
	_sqlite3EndBenignMalloc(tls)
	if zBulk != 0 {
		nBulk = _sqlite3MallocSize(tls, zBulk) / (*TPCache1)(unsafe.Pointer(pCache)).FszAlloc
		for {
			pX = zBulk + uintptr((*TPCache1)(unsafe.Pointer(pCache)).FszPage)
			(*TPgHdr1)(unsafe.Pointer(pX)).Fpage.FpBuf = zBulk
			(*TPgHdr1)(unsafe.Pointer(pX)).Fpage.FpExtra = pX + 1*32
			(*TPgHdr1)(unsafe.Pointer(pX)).FisBulkLocal = uint16(1)
			(*TPgHdr1)(unsafe.Pointer(pX)).FisAnchor = uint16(0)
			(*TPgHdr1)(unsafe.Pointer(pX)).FpNext = (*TPCache1)(unsafe.Pointer(pCache)).FpFree
			(*TPgHdr1)(unsafe.Pointer(pX)).FpLruPrev = uintptr(0) /* Initializing this saves a valgrind error */
			(*TPCache1)(unsafe.Pointer(pCache)).FpFree = pX
			zBulk += uintptr((*TPCache1)(unsafe.Pointer(pCache)).FszAlloc)
			goto _3
		_3:
			;
			nBulk--
			v2 = nBulk
			if !(v2 != 0) {
				break
			}
		}
	}
	return libc.BoolInt32((*TPCache1)(unsafe.Pointer(pCache)).FpFree != uintptr(0))
}

// C documentation
//
//	/*
//	** Malloc function used within this file to allocate space from the buffer
//	** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
//	** such buffer exists or there is no space left in it, this function falls
//	** back to sqlite3Malloc().
//	**
//	** Multiple threads can run this routine at the same time.  Global variables
//	** in pcache1 need to be protected via mutex.
//	*/
func _pcache1Alloc(tls *libc.TLS, nByte int32) (r uintptr) {
	var p uintptr
	var sz int32
	_, _ = p, sz
	p = uintptr(0)
	if nByte <= _pcache1_g.FszSlot {
		Xsqlite3_mutex_enter(tls, _pcache1_g.Fmutex)
		p = _pcache1_g.FpFree
		if p != 0 {
			_pcache1_g.FpFree = (*TPgFreeslot)(unsafe.Pointer(_pcache1_g.FpFree)).FpNext
			_pcache1_g.FnFreeSlot--
			_pcache1_g.FbUnderPressure = libc.BoolInt32(_pcache1_g.FnFreeSlot < _pcache1_g.FnReserve)
			_sqlite3StatusHighwater(tls, int32(SQLITE_STATUS_PAGECACHE_SIZE), nByte)
			_sqlite3StatusUp(tls, int32(SQLITE_STATUS_PAGECACHE_USED), int32(1))
		}
		Xsqlite3_mutex_leave(tls, _pcache1_g.Fmutex)
	}
	if p == uintptr(0) {
		/* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool.  Get
		 ** it from sqlite3Malloc instead.
		 */
		p = _sqlite3Malloc(tls, uint64(uint64(nByte)))
		if p != 0 {
			sz = _sqlite3MallocSize(tls, p)
			Xsqlite3_mutex_enter(tls, _pcache1_g.Fmutex)
			_sqlite3StatusHighwater(tls, int32(SQLITE_STATUS_PAGECACHE_SIZE), nByte)
			_sqlite3StatusUp(tls, int32(SQLITE_STATUS_PAGECACHE_OVERFLOW), sz)
			Xsqlite3_mutex_leave(tls, _pcache1_g.Fmutex)
		}
	}
	return p
}

// C documentation
//
//	/*
//	** Free an allocated buffer obtained from pcache1Alloc().
//	*/
func _pcache1Free(tls *libc.TLS, p uintptr) {
	var nFreed int32
	var pSlot uintptr
	_, _ = nFreed, pSlot
	if p == uintptr(0) {
		return
	}
	if uint32(p) >= uint32(_pcache1_g.FpStart) && uint32(p) < uint32(_pcache1_g.FpEnd) {
		Xsqlite3_mutex_enter(tls, _pcache1_g.Fmutex)
		_sqlite3StatusDown(tls, int32(SQLITE_STATUS_PAGECACHE_USED), int32(1))
		pSlot = p
		(*TPgFreeslot)(unsafe.Pointer(pSlot)).FpNext = _pcache1_g.FpFree
		_pcache1_g.FpFree = pSlot
		_pcache1_g.FnFreeSlot++
		_pcache1_g.FbUnderPressure = libc.BoolInt32(_pcache1_g.FnFreeSlot < _pcache1_g.FnReserve)
		Xsqlite3_mutex_leave(tls, _pcache1_g.Fmutex)
	} else {
		nFreed = 0
		nFreed = _sqlite3MallocSize(tls, p)
		Xsqlite3_mutex_enter(tls, _pcache1_g.Fmutex)
		_sqlite3StatusDown(tls, int32(SQLITE_STATUS_PAGECACHE_OVERFLOW), nFreed)
		Xsqlite3_mutex_leave(tls, _pcache1_g.Fmutex)
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Return the size of a pcache allocation
//	*/
func _pcache1MemSize(tls *libc.TLS, p uintptr) (r int32) {
	var iSize int32
	_ = iSize
	if p >= _pcache1_g.FpStart && p < _pcache1_g.FpEnd {
		return _pcache1_g.FszSlot
	} else {
		iSize = _sqlite3MallocSize(tls, p)
		return iSize
	}
	return r
}

// C documentation
//
//	/*
//	** Allocate a new page object initially associated with cache pCache.
//	*/
func _pcache1AllocPage(tls *libc.TLS, pCache uintptr, benignMalloc int32) (r uintptr) {
	var p, pPg uintptr
	_, _ = p, pPg
	p = uintptr(0)
	if (*TPCache1)(unsafe.Pointer(pCache)).FpFree != 0 || (*TPCache1)(unsafe.Pointer(pCache)).FnPage == uint32(0) && _pcache1InitBulk(tls, pCache) != 0 {
		p = (*TPCache1)(unsafe.Pointer(pCache)).FpFree
		(*TPCache1)(unsafe.Pointer(pCache)).FpFree = (*TPgHdr1)(unsafe.Pointer(p)).FpNext
		(*TPgHdr1)(unsafe.Pointer(p)).FpNext = uintptr(0)
	} else {
		/* The group mutex must be released before pcache1Alloc() is called. This
		 ** is because it might call sqlite3_release_memory(), which assumes that
		 ** this mutex is not held. */
		Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
		if benignMalloc != 0 {
			_sqlite3BeginBenignMalloc(tls)
		}
		pPg = _pcache1Alloc(tls, (*TPCache1)(unsafe.Pointer(pCache)).FszAlloc)
		if benignMalloc != 0 {
			_sqlite3EndBenignMalloc(tls)
		}
		Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
		if pPg == uintptr(0) {
			return uintptr(0)
		}
		p = pPg + uintptr((*TPCache1)(unsafe.Pointer(pCache)).FszPage)
		(*TPgHdr1)(unsafe.Pointer(p)).Fpage.FpBuf = pPg
		(*TPgHdr1)(unsafe.Pointer(p)).Fpage.FpExtra = p + 1*32
		(*TPgHdr1)(unsafe.Pointer(p)).FisBulkLocal = uint16(0)
		(*TPgHdr1)(unsafe.Pointer(p)).FisAnchor = uint16(0)
		(*TPgHdr1)(unsafe.Pointer(p)).FpLruPrev = uintptr(0) /* Initializing this saves a valgrind error */
	}
	*(*uint32)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpnPurgeable))++
	return p
}

// C documentation
//
//	/*
//	** Free a page object allocated by pcache1AllocPage().
//	*/
func _pcache1FreePage(tls *libc.TLS, p uintptr) {
	var pCache uintptr
	_ = pCache
	pCache = (*TPgHdr1)(unsafe.Pointer(p)).FpCache
	if (*TPgHdr1)(unsafe.Pointer(p)).FisBulkLocal != 0 {
		(*TPgHdr1)(unsafe.Pointer(p)).FpNext = (*TPCache1)(unsafe.Pointer(pCache)).FpFree
		(*TPCache1)(unsafe.Pointer(pCache)).FpFree = p
	} else {
		_pcache1Free(tls, (*TPgHdr1)(unsafe.Pointer(p)).Fpage.FpBuf)
	}
	*(*uint32)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpnPurgeable))--
}

// C documentation
//
//	/*
//	** Malloc function used by SQLite to obtain space from the buffer configured
//	** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
//	** exists, this function falls back to sqlite3Malloc().
//	*/
func _sqlite3PageMalloc(tls *libc.TLS, sz int32) (r uintptr) {
	/* These allocations are never very large */
	return _pcache1Alloc(tls, sz)
}

// C documentation
//
//	/*
//	** Free an allocated buffer obtained from sqlite3PageMalloc().
//	*/
func _sqlite3PageFree(tls *libc.TLS, p uintptr) {
	_pcache1Free(tls, p)
}

// C documentation
//
//	/*
//	** Return true if it desirable to avoid allocating a new page cache
//	** entry.
//	**
//	** If memory was allocated specifically to the page cache using
//	** SQLITE_CONFIG_PAGECACHE but that memory has all been used, then
//	** it is desirable to avoid allocating a new page cache entry because
//	** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
//	** for all page cache needs and we should not need to spill the
//	** allocation onto the heap.
//	**
//	** Or, the heap is used for all page cache memory but the heap is
//	** under memory pressure, then again it is desirable to avoid
//	** allocating a new page cache entry in order to avoid stressing
//	** the heap even further.
//	*/
func _pcache1UnderMemoryPressure(tls *libc.TLS, pCache uintptr) (r int32) {
	if _pcache1_g.FnSlot != 0 && (*TPCache1)(unsafe.Pointer(pCache)).FszPage+(*TPCache1)(unsafe.Pointer(pCache)).FszExtra <= _pcache1_g.FszSlot {
		return _pcache1_g.FbUnderPressure
	} else {
		return _sqlite3HeapNearlyFull(tls)
	}
	return r
}

/******************************************************************************/
/******** General Implementation Functions ************************************/

// C documentation
//
//	/*
//	** This function is used to resize the hash table used by the cache passed
//	** as the first argument.
//	**
//	** The PCache mutex must be held when this function is called.
//	*/
func _pcache1ResizeHash(tls *libc.TLS, p uintptr) {
	var apNew, pNext, pPage, v2 uintptr
	var h, i, nNew uint32
	_, _, _, _, _, _, _ = apNew, h, i, nNew, pNext, pPage, v2
	nNew = (*TPCache1)(unsafe.Pointer(p)).FnHash * uint32(2)
	if nNew < uint32(256) {
		nNew = uint32(256)
	}
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(p)).FpGroup)).Fmutex)
	if (*TPCache1)(unsafe.Pointer(p)).FnHash != 0 {
		_sqlite3BeginBenignMalloc(tls)
	}
	apNew = _sqlite3MallocZero(tls, uint64(uint32(4)*nNew))
	if (*TPCache1)(unsafe.Pointer(p)).FnHash != 0 {
		_sqlite3EndBenignMalloc(tls)
	}
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(p)).FpGroup)).Fmutex)
	if apNew != 0 {
		i = uint32(0)
		for {
			if !(i < (*TPCache1)(unsafe.Pointer(p)).FnHash) {
				break
			}
			pNext = *(*uintptr)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(p)).FapHash + uintptr(i)*4))
			for {
				v2 = pNext
				pPage = v2
				if !(v2 != uintptr(0)) {
					break
				}
				h = (*TPgHdr1)(unsafe.Pointer(pPage)).FiKey % nNew
				pNext = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
				(*TPgHdr1)(unsafe.Pointer(pPage)).FpNext = *(*uintptr)(unsafe.Pointer(apNew + uintptr(h)*4))
				*(*uintptr)(unsafe.Pointer(apNew + uintptr(h)*4)) = pPage
			}
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, (*TPCache1)(unsafe.Pointer(p)).FapHash)
		(*TPCache1)(unsafe.Pointer(p)).FapHash = apNew
		(*TPCache1)(unsafe.Pointer(p)).FnHash = nNew
	}
}

// C documentation
//
//	/*
//	** This function is used internally to remove the page pPage from the
//	** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
//	** LRU list, then this function is a no-op.
//	**
//	** The PGroup mutex must be held when this function is called.
//	*/
func _pcache1PinPage(tls *libc.TLS, pPage uintptr) (r uintptr) {
	(*TPgHdr1)(unsafe.Pointer((*TPgHdr1)(unsafe.Pointer(pPage)).FpLruPrev)).FpLruNext = (*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext
	(*TPgHdr1)(unsafe.Pointer((*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext)).FpLruPrev = (*TPgHdr1)(unsafe.Pointer(pPage)).FpLruPrev
	(*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext = uintptr(0)
	/* pPage->pLruPrev = 0;
	 ** No need to clear pLruPrev as it is never accessed if pLruNext is 0 */
	(*TPCache1)(unsafe.Pointer((*TPgHdr1)(unsafe.Pointer(pPage)).FpCache)).FnRecyclable--
	return pPage
}

// C documentation
//
//	/*
//	** Remove the page supplied as an argument from the hash table
//	** (PCache1.apHash structure) that it is currently stored in.
//	** Also free the page if freePage is true.
//	**
//	** The PGroup mutex must be held when this function is called.
//	*/
func _pcache1RemoveFromHash(tls *libc.TLS, pPage uintptr, freeFlag int32) {
	var h uint32
	var pCache, pp uintptr
	_, _, _ = h, pCache, pp
	pCache = (*TPgHdr1)(unsafe.Pointer(pPage)).FpCache
	h = (*TPgHdr1)(unsafe.Pointer(pPage)).FiKey % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
	pp = (*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*4
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != pPage) {
			break
		}
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 16
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*TPgHdr1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext
	(*TPCache1)(unsafe.Pointer(pCache)).FnPage--
	if freeFlag != 0 {
		_pcache1FreePage(tls, pPage)
	}
}

// C documentation
//
//	/*
//	** If there are currently more than nMaxPage pages allocated, try
//	** to recycle pages to reduce the number allocated to nMaxPage.
//	*/
func _pcache1EnforceMaxPage(tls *libc.TLS, pCache uintptr) {
	var p, pGroup, v1, v3 uintptr
	var v2 bool
	_, _, _, _, _ = p, pGroup, v1, v2, v3
	pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
	for {
		if v2 = (*TPGroup)(unsafe.Pointer(pGroup)).FnPurgeable > (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage; v2 {
			v1 = (*TPGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev
			p = v1
		}
		if !(v2 && int32((*TPgHdr1)(unsafe.Pointer(v1)).FisAnchor) == 0) {
			break
		}
		_pcache1PinPage(tls, p)
		_pcache1RemoveFromHash(tls, p, int32(1))
	}
	if (*TPCache1)(unsafe.Pointer(pCache)).FnPage == uint32(0) && (*TPCache1)(unsafe.Pointer(pCache)).FpBulk != 0 {
		Xsqlite3_free(tls, (*TPCache1)(unsafe.Pointer(pCache)).FpBulk)
		v3 = libc.UintptrFromInt32(0)
		(*TPCache1)(unsafe.Pointer(pCache)).FpFree = v3
		(*TPCache1)(unsafe.Pointer(pCache)).FpBulk = v3
	}
}

// C documentation
//
//	/*
//	** Discard all pages from cache pCache with a page number (key value)
//	** greater than or equal to iLimit. Any pinned pages that meet this
//	** criteria are unpinned before they are discarded.
//	**
//	** The PCache mutex must be held when this function is called.
//	*/
func _pcache1TruncateUnsafe(tls *libc.TLS, pCache uintptr, iLimit uint32) {
	var h, iStop uint32
	var pPage, pp, v2 uintptr
	_, _, _, _, _ = h, iStop, pPage, pp, v2
	if (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey-iLimit < (*TPCache1)(unsafe.Pointer(pCache)).FnHash {
		/* If we are just shaving the last few pages off the end of the
		 ** cache, then there is no point in scanning the entire hash table.
		 ** Only scan those hash slots that might contain pages that need to
		 ** be removed. */
		h = iLimit % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
		iStop = (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
		/* Disable the pCache->nPage validity check */
	} else {
		/* This is the general case where many pages are being removed.
		 ** It is necessary to scan the entire hash table */
		h = (*TPCache1)(unsafe.Pointer(pCache)).FnHash / uint32(2)
		iStop = h - uint32(1)
	}
	for {
		pp = (*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*4
		for {
			v2 = *(*uintptr)(unsafe.Pointer(pp))
			pPage = v2
			if !(v2 != uintptr(0)) {
				break
			}
			if (*TPgHdr1)(unsafe.Pointer(pPage)).FiKey >= iLimit {
				(*TPCache1)(unsafe.Pointer(pCache)).FnPage--
				*(*uintptr)(unsafe.Pointer(pp)) = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
				if (*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext != uintptr(0) {
					_pcache1PinPage(tls, pPage)
				}
				_pcache1FreePage(tls, pPage)
			} else {
				pp = pPage + 16
			}
		}
		if h == iStop {
			break
		}
		h = (h + uint32(1)) % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
		goto _1
	_1:
	}
}

/******************************************************************************/
/******** sqlite3_pcache Methods **********************************************/

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xInit method.
//	*/
func _pcache1Init(tls *libc.TLS, NotUsed uintptr) (r int32) {
	_ = NotUsed
	libc.Xmemset(tls, uintptr(unsafe.Pointer(&_pcache1_g)), 0, uint32(100))
	/*
	 ** The pcache1.separateCache variable is true if each PCache has its own
	 ** private PGroup (mode-1).  pcache1.separateCache is false if the single
	 ** PGroup in pcache1.grp is used for all page caches (mode-2).
	 **
	 **   *  Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
	 **
	 **   *  Use a unified cache in single-threaded applications that have
	 **      configured a start-time buffer for use as page-cache memory using
	 **      sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
	 **      pBuf argument.
	 **
	 **   *  Otherwise use separate caches (mode-1)
	 */
	_pcache1_g.FseparateCache = 0
	if _sqlite3Config.FbCoreMutex != 0 {
		_pcache1_g.Fgrp.Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_LRU))
		_pcache1_g.Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_PMEM))
	}
	if _pcache1_g.FseparateCache != 0 && _sqlite3Config.FnPage != 0 && _sqlite3Config.FpPage == uintptr(0) {
		_pcache1_g.FnInitPage = _sqlite3Config.FnPage
	} else {
		_pcache1_g.FnInitPage = 0
	}
	_pcache1_g.Fgrp.FmxPinned = uint32(10)
	libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_pcache1_g))+52, int32(1))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xShutdown method.
//	** Note that the static mutex allocated in xInit does
//	** not need to be freed.
//	*/
func _pcache1Shutdown(tls *libc.TLS, NotUsed uintptr) {
	_ = NotUsed
	libc.Xmemset(tls, uintptr(unsafe.Pointer(&_pcache1_g)), 0, uint32(100))
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xCreate method.
//	**
//	** Allocate a new cache.
//	*/
func _pcache1Create(tls *libc.TLS, szPage int32, szExtra int32, bPurgeable int32) (r uintptr) {
	var pCache, pGroup, v1 uintptr
	var sz, v2 int32
	_, _, _, _, _ = pCache, pGroup, sz, v1, v2 /* Bytes of memory required to allocate the new cache */
	sz = int32(uint32(68) + uint32(52)*uint32(_pcache1_g.FseparateCache))
	pCache = _sqlite3MallocZero(tls, uint64(uint64(sz)))
	if pCache != 0 {
		if _pcache1_g.FseparateCache != 0 {
			pGroup = pCache + 1*68
			(*TPGroup)(unsafe.Pointer(pGroup)).FmxPinned = uint32(10)
		} else {
			pGroup = uintptr(unsafe.Pointer(&_pcache1_g))
		}
		Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
		if int32((*TPGroup)(unsafe.Pointer(pGroup)).Flru.FisAnchor) == 0 {
			(*TPGroup)(unsafe.Pointer(pGroup)).Flru.FisAnchor = uint16(1)
			v1 = pGroup + 20
			(*TPGroup)(unsafe.Pointer(pGroup)).Flru.FpLruNext = v1
			(*TPGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev = v1
		}
		(*TPCache1)(unsafe.Pointer(pCache)).FpGroup = pGroup
		(*TPCache1)(unsafe.Pointer(pCache)).FszPage = szPage
		(*TPCache1)(unsafe.Pointer(pCache)).FszExtra = szExtra
		(*TPCache1)(unsafe.Pointer(pCache)).FszAlloc = int32(uint32(szPage+szExtra) + (libc.Uint32FromInt64(32)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
		if bPurgeable != 0 {
			v2 = int32(1)
		} else {
			v2 = 0
		}
		(*TPCache1)(unsafe.Pointer(pCache)).FbPurgeable = v2
		_pcache1ResizeHash(tls, pCache)
		if bPurgeable != 0 {
			(*TPCache1)(unsafe.Pointer(pCache)).FnMin = uint32(10)
			*(*uint32)(unsafe.Pointer(pGroup + 8)) += (*TPCache1)(unsafe.Pointer(pCache)).FnMin
			(*TPGroup)(unsafe.Pointer(pGroup)).FmxPinned = (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage + uint32(10) - (*TPGroup)(unsafe.Pointer(pGroup)).FnMinPage
			(*TPCache1)(unsafe.Pointer(pCache)).FpnPurgeable = pGroup + 16
		} else {
			(*TPCache1)(unsafe.Pointer(pCache)).FpnPurgeable = pCache + 40
		}
		Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
		if (*TPCache1)(unsafe.Pointer(pCache)).FnHash == uint32(0) {
			_pcache1Destroy(tls, pCache)
			pCache = uintptr(0)
		}
	}
	return pCache
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xCachesize method.
//	**
//	** Configure the cache_size limit for a cache.
//	*/
func _pcache1Cachesize(tls *libc.TLS, p uintptr, nMax int32) {
	var n Tu32
	var pCache, pGroup uintptr
	_, _, _ = n, pCache, pGroup
	pCache = p
	if (*TPCache1)(unsafe.Pointer(pCache)).FbPurgeable != 0 {
		pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
		Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
		n = uint32(uint32(nMax))
		if n > uint32(0x7fff0000)-(*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage+(*TPCache1)(unsafe.Pointer(pCache)).FnMax {
			n = uint32(0x7fff0000) - (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage + (*TPCache1)(unsafe.Pointer(pCache)).FnMax
		}
		*(*uint32)(unsafe.Pointer(pGroup + 4)) += n - (*TPCache1)(unsafe.Pointer(pCache)).FnMax
		(*TPGroup)(unsafe.Pointer(pGroup)).FmxPinned = (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage + uint32(10) - (*TPGroup)(unsafe.Pointer(pGroup)).FnMinPage
		(*TPCache1)(unsafe.Pointer(pCache)).FnMax = n
		(*TPCache1)(unsafe.Pointer(pCache)).Fn90pct = (*TPCache1)(unsafe.Pointer(pCache)).FnMax * uint32(9) / uint32(10)
		_pcache1EnforceMaxPage(tls, pCache)
		Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	}
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xShrink method.
//	**
//	** Free up as much memory as possible.
//	*/
func _pcache1Shrink(tls *libc.TLS, p uintptr) {
	var pCache, pGroup uintptr
	var savedMaxPage uint32
	_, _, _ = pCache, pGroup, savedMaxPage
	pCache = p
	if (*TPCache1)(unsafe.Pointer(pCache)).FbPurgeable != 0 {
		pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
		Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
		savedMaxPage = (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage
		(*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage = uint32(0)
		_pcache1EnforceMaxPage(tls, pCache)
		(*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage = savedMaxPage
		Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	}
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xPagecount method.
//	*/
func _pcache1Pagecount(tls *libc.TLS, p uintptr) (r int32) {
	var n int32
	var pCache uintptr
	_, _ = n, pCache
	pCache = p
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	n = int32((*TPCache1)(unsafe.Pointer(pCache)).FnPage)
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	return n
}

// C documentation
//
//	/*
//	** Implement steps 3, 4, and 5 of the pcache1Fetch() algorithm described
//	** in the header of the pcache1Fetch() procedure.
//	**
//	** This steps are broken out into a separate procedure because they are
//	** usually not needed, and by avoiding the stack initialization required
//	** for these steps, the main pcache1Fetch() procedure can run faster.
//	*/
func _pcache1FetchStage2(tls *libc.TLS, pCache uintptr, iKey uint32, createFlag int32) (r uintptr) {
	var h, nPinned uint32
	var pGroup, pOther, pPage uintptr
	_, _, _, _, _ = h, nPinned, pGroup, pOther, pPage
	pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
	pPage = uintptr(0)
	/* Step 3: Abort if createFlag is 1 but the cache is nearly full */
	nPinned = (*TPCache1)(unsafe.Pointer(pCache)).FnPage - (*TPCache1)(unsafe.Pointer(pCache)).FnRecyclable
	if createFlag == int32(1) && (nPinned >= (*TPGroup)(unsafe.Pointer(pGroup)).FmxPinned || nPinned >= (*TPCache1)(unsafe.Pointer(pCache)).Fn90pct || _pcache1UnderMemoryPressure(tls, pCache) != 0 && (*TPCache1)(unsafe.Pointer(pCache)).FnRecyclable < nPinned) {
		return uintptr(0)
	}
	if (*TPCache1)(unsafe.Pointer(pCache)).FnPage >= (*TPCache1)(unsafe.Pointer(pCache)).FnHash {
		_pcache1ResizeHash(tls, pCache)
	}
	/* Step 4. Try to recycle a page. */
	if (*TPCache1)(unsafe.Pointer(pCache)).FbPurgeable != 0 && !((*TPgHdr1)(unsafe.Pointer((*TPGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev)).FisAnchor != 0) && ((*TPCache1)(unsafe.Pointer(pCache)).FnPage+uint32(1) >= (*TPCache1)(unsafe.Pointer(pCache)).FnMax || _pcache1UnderMemoryPressure(tls, pCache) != 0) {
		pPage = (*TPGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev
		_pcache1RemoveFromHash(tls, pPage, 0)
		_pcache1PinPage(tls, pPage)
		pOther = (*TPgHdr1)(unsafe.Pointer(pPage)).FpCache
		if (*TPCache1)(unsafe.Pointer(pOther)).FszAlloc != (*TPCache1)(unsafe.Pointer(pCache)).FszAlloc {
			_pcache1FreePage(tls, pPage)
			pPage = uintptr(0)
		} else {
			*(*uint32)(unsafe.Pointer(pGroup + 16)) -= uint32((*TPCache1)(unsafe.Pointer(pOther)).FbPurgeable - (*TPCache1)(unsafe.Pointer(pCache)).FbPurgeable)
		}
	}
	/* Step 5. If a usable page buffer has still not been found,
	 ** attempt to allocate a new one.
	 */
	if !(pPage != 0) {
		pPage = _pcache1AllocPage(tls, pCache, libc.BoolInt32(createFlag == int32(1)))
	}
	if pPage != 0 {
		h = iKey % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
		(*TPCache1)(unsafe.Pointer(pCache)).FnPage++
		(*TPgHdr1)(unsafe.Pointer(pPage)).FiKey = iKey
		(*TPgHdr1)(unsafe.Pointer(pPage)).FpNext = *(*uintptr)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*4))
		(*TPgHdr1)(unsafe.Pointer(pPage)).FpCache = pCache
		(*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext = uintptr(0)
		/* pPage->pLruPrev = 0;
		 ** No need to clear pLruPrev since it is not accessed when pLruNext==0 */
		*(*uintptr)(unsafe.Pointer((*TPgHdr1)(unsafe.Pointer(pPage)).Fpage.FpExtra)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*4)) = pPage
		if iKey > (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey {
			(*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey = iKey
		}
	}
	return pPage
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xFetch method.
//	**
//	** Fetch a page by key value.
//	**
//	** Whether or not a new page may be allocated by this function depends on
//	** the value of the createFlag argument.  0 means do not allocate a new
//	** page.  1 means allocate a new page if space is easily available.  2
//	** means to try really hard to allocate a new page.
//	**
//	** For a non-purgeable cache (a cache used as the storage for an in-memory
//	** database) there is really no difference between createFlag 1 and 2.  So
//	** the calling function (pcache.c) will never have a createFlag of 1 on
//	** a non-purgeable cache.
//	**
//	** There are three different approaches to obtaining space for a page,
//	** depending on the value of parameter createFlag (which may be 0, 1 or 2).
//	**
//	**   1. Regardless of the value of createFlag, the cache is searched for a
//	**      copy of the requested page. If one is found, it is returned.
//	**
//	**   2. If createFlag==0 and the page is not already in the cache, NULL is
//	**      returned.
//	**
//	**   3. If createFlag is 1, and the page is not already in the cache, then
//	**      return NULL (do not allocate a new page) if any of the following
//	**      conditions are true:
//	**
//	**       (a) the number of pages pinned by the cache is greater than
//	**           PCache1.nMax, or
//	**
//	**       (b) the number of pages pinned by the cache is greater than
//	**           the sum of nMax for all purgeable caches, less the sum of
//	**           nMin for all other purgeable caches, or
//	**
//	**   4. If none of the first three conditions apply and the cache is marked
//	**      as purgeable, and if one of the following is true:
//	**
//	**       (a) The number of pages allocated for the cache is already
//	**           PCache1.nMax, or
//	**
//	**       (b) The number of pages allocated for all purgeable caches is
//	**           already equal to or greater than the sum of nMax for all
//	**           purgeable caches,
//	**
//	**       (c) The system is under memory pressure and wants to avoid
//	**           unnecessary pages cache entry allocations
//	**
//	**      then attempt to recycle a page from the LRU list. If it is the right
//	**      size, return the recycled buffer. Otherwise, free the buffer and
//	**      proceed to step 5.
//	**
//	**   5. Otherwise, allocate and return a new page buffer.
//	**
//	** There are two versions of this routine.  pcache1FetchWithMutex() is
//	** the general case.  pcache1FetchNoMutex() is a faster implementation for
//	** the common case where pGroup->mutex is NULL.  The pcache1Fetch() wrapper
//	** invokes the appropriate routine.
//	*/
func _pcache1FetchNoMutex(tls *libc.TLS, p uintptr, iKey uint32, createFlag int32) (r uintptr) {
	var pCache, pPage uintptr
	_, _ = pCache, pPage
	pCache = p
	pPage = uintptr(0)
	/* Step 1: Search the hash table for an existing entry. */
	pPage = *(*uintptr)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(iKey%(*TPCache1)(unsafe.Pointer(pCache)).FnHash)*4))
	for pPage != 0 && (*TPgHdr1)(unsafe.Pointer(pPage)).FiKey != iKey {
		pPage = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
	}
	/* Step 2: If the page was found in the hash table, then return it.
	 ** If the page was not in the hash table and createFlag is 0, abort.
	 ** Otherwise (page not in hash and createFlag!=0) continue with
	 ** subsequent steps to try to create the page. */
	if pPage != 0 {
		if (*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext != uintptr(0) {
			return _pcache1PinPage(tls, pPage)
		} else {
			return pPage
		}
	} else {
		if createFlag != 0 {
			/* Steps 3, 4, and 5 implemented by this subroutine */
			return _pcache1FetchStage2(tls, pCache, iKey, createFlag)
		} else {
			return uintptr(0)
		}
	}
	return r
}

func _pcache1FetchWithMutex(tls *libc.TLS, p uintptr, iKey uint32, createFlag int32) (r uintptr) {
	var pCache, pPage uintptr
	_, _ = pCache, pPage
	pCache = p
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	pPage = _pcache1FetchNoMutex(tls, p, iKey, createFlag)
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	return pPage
}

func _pcache1Fetch(tls *libc.TLS, p uintptr, iKey uint32, createFlag int32) (r uintptr) {
	var pCache uintptr
	_ = pCache
	pCache = p
	if (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex != 0 {
		return _pcache1FetchWithMutex(tls, p, iKey, createFlag)
	} else {
		return _pcache1FetchNoMutex(tls, p, iKey, createFlag)
	}
	return r
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xUnpin method.
//	**
//	** Mark a page as unpinned (eligible for asynchronous recycling).
//	*/
func _pcache1Unpin(tls *libc.TLS, p uintptr, pPg uintptr, reuseUnlikely int32) {
	var pCache, pGroup, pPage, ppFirst, v1 uintptr
	_, _, _, _, _ = pCache, pGroup, pPage, ppFirst, v1
	pCache = p
	pPage = pPg
	pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	/* It is an error to call this function if the page is already
	 ** part of the PGroup LRU list.
	 */
	if reuseUnlikely != 0 || (*TPGroup)(unsafe.Pointer(pGroup)).FnPurgeable > (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage {
		_pcache1RemoveFromHash(tls, pPage, int32(1))
	} else {
		/* Add the page to the PGroup LRU list. */
		ppFirst = pGroup + 20 + 24
		(*TPgHdr1)(unsafe.Pointer(pPage)).FpLruPrev = pGroup + 20
		v1 = *(*uintptr)(unsafe.Pointer(ppFirst))
		(*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext = v1
		(*TPgHdr1)(unsafe.Pointer(v1)).FpLruPrev = pPage
		*(*uintptr)(unsafe.Pointer(ppFirst)) = pPage
		(*TPCache1)(unsafe.Pointer(pCache)).FnRecyclable++
	}
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xRekey method.
//	*/
func _pcache1Rekey(tls *libc.TLS, p uintptr, pPg uintptr, iOld uint32, iNew uint32) {
	var hNew, hOld uint32
	var pCache, pPage, pp uintptr
	_, _, _, _, _ = hNew, hOld, pCache, pPage, pp
	pCache = p
	pPage = pPg
	/* The page number really is changing */
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	/* pPg really is iOld */
	hOld = iOld % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
	pp = (*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hOld)*4
	for *(*uintptr)(unsafe.Pointer(pp)) != pPage {
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 16
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
	/* iNew not in cache */
	hNew = iNew % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
	(*TPgHdr1)(unsafe.Pointer(pPage)).FiKey = iNew
	(*TPgHdr1)(unsafe.Pointer(pPage)).FpNext = *(*uintptr)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hNew)*4))
	*(*uintptr)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hNew)*4)) = pPage
	if iNew > (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey {
		(*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey = iNew
	}
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xTruncate method.
//	**
//	** Discard all unpinned pages in the cache with a page number equal to
//	** or greater than parameter iLimit. Any pinned pages with a page number
//	** equal to or greater than iLimit are implicitly unpinned.
//	*/
func _pcache1Truncate(tls *libc.TLS, p uintptr, iLimit uint32) {
	var pCache uintptr
	_ = pCache
	pCache = p
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	if iLimit <= (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey {
		_pcache1TruncateUnsafe(tls, pCache, iLimit)
		(*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey = iLimit - uint32(1)
	}
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xDestroy method.
//	**
//	** Destroy a cache allocated using pcache1Create().
//	*/
func _pcache1Destroy(tls *libc.TLS, p uintptr) {
	var pCache, pGroup uintptr
	_, _ = pCache, pGroup
	pCache = p
	pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	if (*TPCache1)(unsafe.Pointer(pCache)).FnPage != 0 {
		_pcache1TruncateUnsafe(tls, pCache, uint32(0))
	}
	*(*uint32)(unsafe.Pointer(pGroup + 4)) -= (*TPCache1)(unsafe.Pointer(pCache)).FnMax
	*(*uint32)(unsafe.Pointer(pGroup + 8)) -= (*TPCache1)(unsafe.Pointer(pCache)).FnMin
	(*TPGroup)(unsafe.Pointer(pGroup)).FmxPinned = (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage + uint32(10) - (*TPGroup)(unsafe.Pointer(pGroup)).FnMinPage
	_pcache1EnforceMaxPage(tls, pCache)
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	Xsqlite3_free(tls, (*TPCache1)(unsafe.Pointer(pCache)).FpBulk)
	Xsqlite3_free(tls, (*TPCache1)(unsafe.Pointer(pCache)).FapHash)
	Xsqlite3_free(tls, pCache)
}

// C documentation
//
//	/*
//	** This function is called during initialization (sqlite3_initialize()) to
//	** install the default pluggable cache module, assuming the user has not
//	** already provided an alternative.
//	*/
func _sqlite3PCacheSetDefault(tls *libc.TLS) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	Xsqlite3_config(tls, int32(SQLITE_CONFIG_PCACHE2), libc.VaList(bp+8, uintptr(unsafe.Pointer(&_defaultMethods1))))
}

var _defaultMethods1 = Tsqlite3_pcache_methods2{
	FiVersion: int32(1),
}

func init() {
	p := unsafe.Pointer(&_defaultMethods1)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_pcache1Init)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_pcache1Shutdown)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_pcache1Create)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_pcache1Cachesize)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_pcache1Pagecount)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_pcache1Fetch)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_pcache1Unpin)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_pcache1Rekey)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_pcache1Truncate)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_pcache1Destroy)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_pcache1Shrink)
}

// C documentation
//
//	/*
//	** Return the size of the header on each page of this PCACHE implementation.
//	*/
func _sqlite3HeaderSizePcache1(tls *libc.TLS) (r int32) {
	return int32((libc.Uint32FromInt64(32) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
}

// C documentation
//
//	/*
//	** Return the global mutex used by this PCACHE implementation.  The
//	** sqlite3_status() routine needs access to this mutex.
//	*/
func _sqlite3Pcache1Mutex(tls *libc.TLS) (r uintptr) {
	return _pcache1_g.Fmutex
}

// C documentation
//
//	/*
//	** This function is called to free superfluous dynamically allocated memory
//	** held by the pager system. Memory in use by any SQLite pager allocated
//	** by the current thread may be sqlite3_free()ed.
//	**
//	** nReq is the number of bytes of memory required. Once this much has
//	** been released, the function returns. The return value is the total number
//	** of bytes of memory released.
//	*/
func _sqlite3PcacheReleaseMemory(tls *libc.TLS, nReq int32) (r int32) {
	var nFree int32
	var p, v1 uintptr
	var v2 bool
	_, _, _, _ = nFree, p, v1, v2
	nFree = 0
	if _sqlite3Config.FpPage == uintptr(0) {
		Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(uintptr(unsafe.Pointer(&_pcache1_g)))).Fmutex)
		for {
			if v2 = nReq < 0 || nFree < nReq; v2 {
				v1 = _pcache1_g.Fgrp.Flru.FpLruPrev
				p = v1
			}
			if !(v2 && v1 != uintptr(0) && int32((*TPgHdr1)(unsafe.Pointer(p)).FisAnchor) == 0) {
				break
			}
			nFree += _pcache1MemSize(tls, (*TPgHdr1)(unsafe.Pointer(p)).Fpage.FpBuf)
			_pcache1PinPage(tls, p)
			_pcache1RemoveFromHash(tls, p, int32(1))
		}
		Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer(uintptr(unsafe.Pointer(&_pcache1_g)))).Fmutex)
	}
	return nFree
}

/************** End of pcache1.c *********************************************/
/************** Begin file rowset.c ******************************************/
/*
** 2008 December 3
**
** 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 implements an object we call a "RowSet".
**
** The RowSet object is a collection of rowids.  Rowids
** are inserted into the RowSet in an arbitrary order.  Inserts
** can be intermixed with tests to see if a given rowid has been
** previously inserted into the RowSet.
**
** After all inserts are finished, it is possible to extract the
** elements of the RowSet in sorted order.  Once this extraction
** process has started, no new elements may be inserted.
**
** Hence, the primitive operations for a RowSet are:
**
**    CREATE
**    INSERT
**    TEST
**    SMALLEST
**    DESTROY
**
** The CREATE and DESTROY primitives are the constructor and destructor,
** obviously.  The INSERT primitive adds a new element to the RowSet.
** TEST checks to see if an element is already in the RowSet.  SMALLEST
** extracts the least value from the RowSet.
**
** The INSERT primitive might allocate additional memory.  Memory is
** allocated in chunks so most INSERTs do no allocation.  There is an
** upper bound on the size of allocated memory.  No memory is freed
** until DESTROY.
**
** The TEST primitive includes a "batch" number.  The TEST primitive
** will only see elements that were inserted before the last change
** in the batch number.  In other words, if an INSERT occurs between
** two TESTs where the TESTs have the same batch number, then the
** value added by the INSERT will not be visible to the second TEST.
** The initial batch number is zero, so if the very first TEST contains
** a non-zero batch number, it will see all prior INSERTs.
**
** No INSERTs may occurs after a SMALLEST.  An assertion will fail if
** that is attempted.
**
** The cost of an INSERT is roughly constant.  (Sometimes new memory
** has to be allocated on an INSERT.)  The cost of a TEST with a new
** batch number is O(NlogN) where N is the number of elements in the RowSet.
** The cost of a TEST using the same batch number is O(logN).  The cost
** of the first SMALLEST is O(NlogN).  Second and subsequent SMALLEST
** primitives are constant time.  The cost of DESTROY is O(N).
**
** TEST and SMALLEST may not be used by the same RowSet.  This used to
** be possible, but the feature was not used, so it was removed in order
** to simplify the code.
 */
/* #include "sqliteInt.h" */

/*
** Target size for allocation chunks.
 */

/*
** The number of rowset entries per allocation chunk.
 */

/*
** Each entry in a RowSet is an instance of the following object.
**
** This same object is reused to store a linked list of trees of RowSetEntry
** objects.  In that alternative use, pRight points to the next entry
** in the list, pLeft points to the tree, and v is unused.  The
** RowSet.pForest value points to the head of this forest list.
 */
type TRowSetEntry = struct {
	F__ccgo_align [0]uint32
	Fv            Ti64
	FpRight       uintptr
	FpLeft        uintptr
}

type RowSetEntry = TRowSetEntry

/*
** RowSetEntry objects are allocated in large chunks (instances of the
** following structure) to reduce memory allocation overhead.  The
** chunks are kept on a linked list so that they can be deallocated
** when the RowSet is destroyed.
 */
type TRowSetChunk = struct {
	F__ccgo_align  [0]uint32
	FpNextChunk    uintptr
	F__ccgo_align1 [4]byte
	FaEntry        [63]TRowSetEntry
}

type RowSetChunk = TRowSetChunk

/*
** A RowSet in an instance of the following structure.
**
** A typedef of this structure if found in sqliteInt.h.
 */
type TRowSet1 = struct {
	FpChunk  uintptr
	Fdb      uintptr
	FpEntry  uintptr
	FpLast   uintptr
	FpFresh  uintptr
	FpForest uintptr
	FnFresh  Tu16
	FrsFlags Tu16
	FiBatch  int32
}

type RowSet1 = TRowSet1

/*
** Allowed values for RowSet.rsFlags
 */

// C documentation
//
//	/*
//	** Allocate a RowSet object.  Return NULL if a memory allocation
//	** error occurs.
//	*/
func _sqlite3RowSetInit(tls *libc.TLS, db uintptr) (r uintptr) {
	var N int32
	var p uintptr
	_, _ = N, p
	p = _sqlite3DbMallocRawNN(tls, db, uint64(32))
	if p != 0 {
		N = _sqlite3DbMallocSize(tls, db, p)
		(*TRowSet)(unsafe.Pointer(p)).FpChunk = uintptr(0)
		(*TRowSet)(unsafe.Pointer(p)).Fdb = db
		(*TRowSet)(unsafe.Pointer(p)).FpEntry = uintptr(0)
		(*TRowSet)(unsafe.Pointer(p)).FpLast = uintptr(0)
		(*TRowSet)(unsafe.Pointer(p)).FpForest = uintptr(0)
		(*TRowSet)(unsafe.Pointer(p)).FpFresh = uintptr((libc.Uint32FromInt64(32)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7))) + p
		(*TRowSet)(unsafe.Pointer(p)).FnFresh = uint16((uint32(uint32(N)) - (libc.Uint32FromInt64(32)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7))) / libc.Uint32FromInt64(16))
		(*TRowSet)(unsafe.Pointer(p)).FrsFlags = uint16(ROWSET_SORTED)
		(*TRowSet)(unsafe.Pointer(p)).FiBatch = 0
	}
	return p
}

// C documentation
//
//	/*
//	** Deallocate all chunks from a RowSet.  This frees all memory that
//	** the RowSet has allocated over its lifetime.  This routine is
//	** the destructor for the RowSet.
//	*/
func _sqlite3RowSetClear(tls *libc.TLS, pArg uintptr) {
	var p, pChunk, pNextChunk uintptr
	_, _, _ = p, pChunk, pNextChunk
	p = pArg
	pChunk = (*TRowSet)(unsafe.Pointer(p)).FpChunk
	for {
		if !(pChunk != 0) {
			break
		}
		pNextChunk = (*TRowSetChunk)(unsafe.Pointer(pChunk)).FpNextChunk
		_sqlite3DbFree(tls, (*TRowSet)(unsafe.Pointer(p)).Fdb, pChunk)
		goto _1
	_1:
		;
		pChunk = pNextChunk
	}
	(*TRowSet)(unsafe.Pointer(p)).FpChunk = uintptr(0)
	(*TRowSet)(unsafe.Pointer(p)).FnFresh = uint16(0)
	(*TRowSet)(unsafe.Pointer(p)).FpEntry = uintptr(0)
	(*TRowSet)(unsafe.Pointer(p)).FpLast = uintptr(0)
	(*TRowSet)(unsafe.Pointer(p)).FpForest = uintptr(0)
	(*TRowSet)(unsafe.Pointer(p)).FrsFlags = uint16(ROWSET_SORTED)
}

// C documentation
//
//	/*
//	** Deallocate all chunks from a RowSet.  This frees all memory that
//	** the RowSet has allocated over its lifetime.  This routine is
//	** the destructor for the RowSet.
//	*/
func _sqlite3RowSetDelete(tls *libc.TLS, pArg uintptr) {
	_sqlite3RowSetClear(tls, pArg)
	_sqlite3DbFree(tls, (*TRowSet)(unsafe.Pointer(pArg)).Fdb, pArg)
}

// C documentation
//
//	/*
//	** Allocate a new RowSetEntry object that is associated with the
//	** given RowSet.  Return a pointer to the new and completely uninitialized
//	** object.
//	**
//	** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
//	** routine returns NULL.
//	*/
func _rowSetEntryAlloc(tls *libc.TLS, p uintptr) (r uintptr) {
	var pNew, v1, v2 uintptr
	_, _, _ = pNew, v1, v2
	if int32((*TRowSet)(unsafe.Pointer(p)).FnFresh) == 0 {
		pNew = _sqlite3DbMallocRawNN(tls, (*TRowSet)(unsafe.Pointer(p)).Fdb, uint64(1016))
		if pNew == uintptr(0) {
			return uintptr(0)
		}
		(*TRowSetChunk)(unsafe.Pointer(pNew)).FpNextChunk = (*TRowSet)(unsafe.Pointer(p)).FpChunk
		(*TRowSet)(unsafe.Pointer(p)).FpChunk = pNew
		(*TRowSet)(unsafe.Pointer(p)).FpFresh = pNew + 8
		(*TRowSet)(unsafe.Pointer(p)).FnFresh = uint16(uint32(libc.Int32FromInt32(ROWSET_ALLOCATION_SIZE)-libc.Int32FromInt32(8)) / libc.Uint32FromInt64(16))
	}
	(*TRowSet)(unsafe.Pointer(p)).FnFresh--
	v2 = p + 16
	v1 = *(*uintptr)(unsafe.Pointer(v2))
	*(*uintptr)(unsafe.Pointer(v2)) += 16
	return v1
}

// C documentation
//
//	/*
//	** Insert a new value into a RowSet.
//	**
//	** The mallocFailed flag of the database connection is set if a
//	** memory allocation fails.
//	*/
func _sqlite3RowSetInsert(tls *libc.TLS, p uintptr, rowid Ti64) {
	var pEntry, pLast, p1 uintptr
	_, _, _ = pEntry, pLast, p1 /* The last prior entry */
	/* This routine is never called after sqlite3RowSetNext() */
	pEntry = _rowSetEntryAlloc(tls, p)
	if pEntry == uintptr(0) {
		return
	}
	(*TRowSetEntry)(unsafe.Pointer(pEntry)).Fv = rowid
	(*TRowSetEntry)(unsafe.Pointer(pEntry)).FpRight = uintptr(0)
	pLast = (*TRowSet)(unsafe.Pointer(p)).FpLast
	if pLast != 0 {
		if rowid <= (*TRowSetEntry)(unsafe.Pointer(pLast)).Fv { /*OPTIMIZATION-IF-FALSE*/
			/* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
			 ** where possible */
			p1 = p + 26
			*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(ROWSET_SORTED))
		}
		(*TRowSetEntry)(unsafe.Pointer(pLast)).FpRight = pEntry
	} else {
		(*TRowSet)(unsafe.Pointer(p)).FpEntry = pEntry
	}
	(*TRowSet)(unsafe.Pointer(p)).FpLast = pEntry
}

// C documentation
//
//	/*
//	** Merge two lists of RowSetEntry objects.  Remove duplicates.
//	**
//	** The input lists are connected via pRight pointers and are
//	** assumed to each already be in sorted order.
//	*/
func _rowSetEntryMerge(tls *libc.TLS, pA uintptr, pB uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pTail, v2, v3 uintptr
	var _ /* head at bp+0 */ TRowSetEntry
	_, _, _ = pTail, v2, v3
	pTail = bp
	for {
		if (*TRowSetEntry)(unsafe.Pointer(pA)).Fv <= (*TRowSetEntry)(unsafe.Pointer(pB)).Fv {
			if (*TRowSetEntry)(unsafe.Pointer(pA)).Fv < (*TRowSetEntry)(unsafe.Pointer(pB)).Fv {
				v2 = pA
				(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = v2
				pTail = v2
			}
			pA = (*TRowSetEntry)(unsafe.Pointer(pA)).FpRight
			if pA == uintptr(0) {
				(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = pB
				break
			}
		} else {
			v3 = pB
			(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = v3
			pTail = v3
			pB = (*TRowSetEntry)(unsafe.Pointer(pB)).FpRight
			if pB == uintptr(0) {
				(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = pA
				break
			}
		}
		goto _1
	_1:
	}
	return (*(*TRowSetEntry)(unsafe.Pointer(bp))).FpRight
}

// C documentation
//
//	/*
//	** Sort all elements on the list of RowSetEntry objects into order of
//	** increasing v.
//	*/
func _rowSetEntrySort(tls *libc.TLS, pIn uintptr) (r uintptr) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var i uint32
	var pNext, v3 uintptr
	var _ /* aBucket at bp+0 */ [40]uintptr
	_, _, _ = i, pNext, v3
	libc.Xmemset(tls, bp, 0, uint32(160))
	for pIn != 0 {
		pNext = (*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight
		(*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight = uintptr(0)
		i = uint32(0)
		for {
			if !((*(*[40]uintptr)(unsafe.Pointer(bp)))[i] != 0) {
				break
			}
			pIn = _rowSetEntryMerge(tls, (*(*[40]uintptr)(unsafe.Pointer(bp)))[i], pIn)
			(*(*[40]uintptr)(unsafe.Pointer(bp)))[i] = uintptr(0)
			goto _1
		_1:
			;
			i++
		}
		(*(*[40]uintptr)(unsafe.Pointer(bp)))[i] = pIn
		pIn = pNext
	}
	pIn = (*(*[40]uintptr)(unsafe.Pointer(bp)))[0]
	i = uint32(1)
	for {
		if !(i < libc.Uint32FromInt64(160)/libc.Uint32FromInt64(4)) {
			break
		}
		if (*(*[40]uintptr)(unsafe.Pointer(bp)))[i] == uintptr(0) {
			goto _2
		}
		if pIn != 0 {
			v3 = _rowSetEntryMerge(tls, pIn, (*(*[40]uintptr)(unsafe.Pointer(bp)))[i])
		} else {
			v3 = (*(*[40]uintptr)(unsafe.Pointer(bp)))[i]
		}
		pIn = v3
		goto _2
	_2:
		;
		i++
	}
	return pIn
}

// C documentation
//
//	/*
//	** The input, pIn, is a binary tree (or subtree) of RowSetEntry objects.
//	** Convert this tree into a linked list connected by the pRight pointers
//	** and return pointers to the first and last elements of the new list.
//	*/
func _rowSetTreeToList(tls *libc.TLS, pIn uintptr, ppFirst uintptr, ppLast uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* p at bp+0 */ uintptr
	if (*TRowSetEntry)(unsafe.Pointer(pIn)).FpLeft != 0 {
		_rowSetTreeToList(tls, (*TRowSetEntry)(unsafe.Pointer(pIn)).FpLeft, ppFirst, bp)
		(*TRowSetEntry)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpRight = pIn
	} else {
		*(*uintptr)(unsafe.Pointer(ppFirst)) = pIn
	}
	if (*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight != 0 {
		_rowSetTreeToList(tls, (*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight, pIn+8, ppLast)
	} else {
		*(*uintptr)(unsafe.Pointer(ppLast)) = pIn
	}
}

// C documentation
//
//	/*
//	** Convert a sorted list of elements (connected by pRight) into a binary
//	** tree with depth of iDepth.  A depth of 1 means the tree contains a single
//	** node taken from the head of *ppList.  A depth of 2 means a tree with
//	** three nodes.  And so forth.
//	**
//	** Use as many entries from the input list as required and update the
//	** *ppList to point to the unused elements of the list.  If the input
//	** list contains too few elements, then construct an incomplete tree
//	** and leave *ppList set to NULL.
//	**
//	** Return a pointer to the root of the constructed binary tree.
//	*/
func _rowSetNDeepTree(tls *libc.TLS, ppList uintptr, iDepth int32) (r uintptr) {
	var p, pLeft, v1 uintptr
	_, _, _ = p, pLeft, v1                                 /* Left subtree */
	if *(*uintptr)(unsafe.Pointer(ppList)) == uintptr(0) { /*OPTIMIZATION-IF-TRUE*/
		/* Prevent unnecessary deep recursion when we run out of entries */
		return uintptr(0)
	}
	if iDepth > int32(1) { /*OPTIMIZATION-IF-TRUE*/
		/* This branch causes a *balanced* tree to be generated.  A valid tree
		 ** is still generated without this branch, but the tree is wildly
		 ** unbalanced and inefficient. */
		pLeft = _rowSetNDeepTree(tls, ppList, iDepth-int32(1))
		p = *(*uintptr)(unsafe.Pointer(ppList))
		if p == uintptr(0) { /*OPTIMIZATION-IF-FALSE*/
			/* It is safe to always return here, but the resulting tree
			 ** would be unbalanced */
			return pLeft
		}
		(*TRowSetEntry)(unsafe.Pointer(p)).FpLeft = pLeft
		*(*uintptr)(unsafe.Pointer(ppList)) = (*TRowSetEntry)(unsafe.Pointer(p)).FpRight
		(*TRowSetEntry)(unsafe.Pointer(p)).FpRight = _rowSetNDeepTree(tls, ppList, iDepth-int32(1))
	} else {
		p = *(*uintptr)(unsafe.Pointer(ppList))
		*(*uintptr)(unsafe.Pointer(ppList)) = (*TRowSetEntry)(unsafe.Pointer(p)).FpRight
		v1 = libc.UintptrFromInt32(0)
		(*TRowSetEntry)(unsafe.Pointer(p)).FpRight = v1
		(*TRowSetEntry)(unsafe.Pointer(p)).FpLeft = v1
	}
	return p
}

// C documentation
//
//	/*
//	** Convert a sorted list of elements into a binary tree. Make the tree
//	** as deep as it needs to be in order to contain the entire list.
//	*/
func _rowSetListToTree(tls *libc.TLS, _pList uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _pList
	var iDepth int32
	var p, pLeft, v1 uintptr
	_, _, _, _ = iDepth, p, pLeft, v1 /* Left subtree */
	p = *(*uintptr)(unsafe.Pointer(bp))
	*(*uintptr)(unsafe.Pointer(bp)) = (*TRowSetEntry)(unsafe.Pointer(p)).FpRight
	v1 = libc.UintptrFromInt32(0)
	(*TRowSetEntry)(unsafe.Pointer(p)).FpRight = v1
	(*TRowSetEntry)(unsafe.Pointer(p)).FpLeft = v1
	iDepth = int32(1)
	for {
		if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
			break
		}
		pLeft = p
		p = *(*uintptr)(unsafe.Pointer(bp))
		*(*uintptr)(unsafe.Pointer(bp)) = (*TRowSetEntry)(unsafe.Pointer(p)).FpRight
		(*TRowSetEntry)(unsafe.Pointer(p)).FpLeft = pLeft
		(*TRowSetEntry)(unsafe.Pointer(p)).FpRight = _rowSetNDeepTree(tls, bp, iDepth)
		goto _2
	_2:
		;
		iDepth++
	}
	return p
}

// C documentation
//
//	/*
//	** Extract the smallest element from the RowSet.
//	** Write the element into *pRowid.  Return 1 on success.  Return
//	** 0 if the RowSet is already empty.
//	**
//	** After this routine has been called, the sqlite3RowSetInsert()
//	** routine may not be called again.
//	**
//	** This routine may not be called after sqlite3RowSetTest() has
//	** been used.  Older versions of RowSet allowed that, but as the
//	** capability was not used by the code generator, it was removed
//	** for code economy.
//	*/
func _sqlite3RowSetNext(tls *libc.TLS, p uintptr, pRowid uintptr) (r int32) {
	var p1 uintptr
	_ = p1
	/* Cannot be used with sqlite3RowSetText() */
	/* Merge the forest into a single sorted list on first call */
	if int32((*TRowSet)(unsafe.Pointer(p)).FrsFlags)&int32(ROWSET_NEXT) == 0 { /*OPTIMIZATION-IF-FALSE*/
		if int32((*TRowSet)(unsafe.Pointer(p)).FrsFlags)&int32(ROWSET_SORTED) == 0 { /*OPTIMIZATION-IF-FALSE*/
			(*TRowSet)(unsafe.Pointer(p)).FpEntry = _rowSetEntrySort(tls, (*TRowSet)(unsafe.Pointer(p)).FpEntry)
		}
		p1 = p + 26
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | (libc.Int32FromInt32(ROWSET_SORTED) | libc.Int32FromInt32(ROWSET_NEXT)))
	}
	/* Return the next entry on the list */
	if (*TRowSet)(unsafe.Pointer(p)).FpEntry != 0 {
		*(*Ti64)(unsafe.Pointer(pRowid)) = (*TRowSetEntry)(unsafe.Pointer((*TRowSet)(unsafe.Pointer(p)).FpEntry)).Fv
		(*TRowSet)(unsafe.Pointer(p)).FpEntry = (*TRowSetEntry)(unsafe.Pointer((*TRowSet)(unsafe.Pointer(p)).FpEntry)).FpRight
		if (*TRowSet)(unsafe.Pointer(p)).FpEntry == uintptr(0) { /*OPTIMIZATION-IF-TRUE*/
			/* Free memory immediately, rather than waiting on sqlite3_finalize() */
			_sqlite3RowSetClear(tls, p)
		}
		return int32(1)
	} else {
		return 0
	}
	return r
}

// C documentation
//
//	/*
//	** Check to see if element iRowid was inserted into the rowset as
//	** part of any insert batch prior to iBatch.  Return 1 or 0.
//	**
//	** If this is the first test of a new batch and if there exist entries
//	** on pRowSet->pEntry, then sort those entries into the forest at
//	** pRowSet->pForest so that they can be tested.
//	*/
func _sqlite3RowSetTest(tls *libc.TLS, pRowSet uintptr, iBatch int32, iRowid Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p, pTree, ppPrevTree, v2, p3 uintptr
	var _ /* pAux at bp+0 */ uintptr
	var _ /* pTail at bp+4 */ uintptr
	_, _, _, _, _ = p, pTree, ppPrevTree, v2, p3
	/* This routine is never called after sqlite3RowSetNext() */
	/* Sort entries into the forest on the first test of a new batch.
	 ** To save unnecessary work, only do this when the batch number changes.
	 */
	if iBatch != (*TRowSet)(unsafe.Pointer(pRowSet)).FiBatch { /*OPTIMIZATION-IF-FALSE*/
		p = (*TRowSet)(unsafe.Pointer(pRowSet)).FpEntry
		if p != 0 {
			ppPrevTree = pRowSet + 20
			if int32((*TRowSet)(unsafe.Pointer(pRowSet)).FrsFlags)&int32(ROWSET_SORTED) == 0 { /*OPTIMIZATION-IF-FALSE*/
				/* Only sort the current set of entries if they need it */
				p = _rowSetEntrySort(tls, p)
			}
			pTree = (*TRowSet)(unsafe.Pointer(pRowSet)).FpForest
			for {
				if !(pTree != 0) {
					break
				}
				ppPrevTree = pTree + 8
				if (*TRowSetEntry)(unsafe.Pointer(pTree)).FpLeft == uintptr(0) {
					(*TRowSetEntry)(unsafe.Pointer(pTree)).FpLeft = _rowSetListToTree(tls, p)
					break
				} else {
					_rowSetTreeToList(tls, (*TRowSetEntry)(unsafe.Pointer(pTree)).FpLeft, bp, bp+4)
					(*TRowSetEntry)(unsafe.Pointer(pTree)).FpLeft = uintptr(0)
					p = _rowSetEntryMerge(tls, *(*uintptr)(unsafe.Pointer(bp)), p)
				}
				goto _1
			_1:
				;
				pTree = (*TRowSetEntry)(unsafe.Pointer(pTree)).FpRight
			}
			if pTree == uintptr(0) {
				v2 = _rowSetEntryAlloc(tls, pRowSet)
				pTree = v2
				*(*uintptr)(unsafe.Pointer(ppPrevTree)) = v2
				if pTree != 0 {
					(*TRowSetEntry)(unsafe.Pointer(pTree)).Fv = 0
					(*TRowSetEntry)(unsafe.Pointer(pTree)).FpRight = uintptr(0)
					(*TRowSetEntry)(unsafe.Pointer(pTree)).FpLeft = _rowSetListToTree(tls, p)
				}
			}
			(*TRowSet)(unsafe.Pointer(pRowSet)).FpEntry = uintptr(0)
			(*TRowSet)(unsafe.Pointer(pRowSet)).FpLast = uintptr(0)
			p3 = pRowSet + 26
			*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(ROWSET_SORTED))
		}
		(*TRowSet)(unsafe.Pointer(pRowSet)).FiBatch = iBatch
	}
	/* Test to see if the iRowid value appears anywhere in the forest.
	 ** Return 1 if it does and 0 if not.
	 */
	pTree = (*TRowSet)(unsafe.Pointer(pRowSet)).FpForest
	for {
		if !(pTree != 0) {
			break
		}
		p = (*TRowSetEntry)(unsafe.Pointer(pTree)).FpLeft
		for p != 0 {
			if (*TRowSetEntry)(unsafe.Pointer(p)).Fv < iRowid {
				p = (*TRowSetEntry)(unsafe.Pointer(p)).FpRight
			} else {
				if (*TRowSetEntry)(unsafe.Pointer(p)).Fv > iRowid {
					p = (*TRowSetEntry)(unsafe.Pointer(p)).FpLeft
				} else {
					return int32(1)
				}
			}
		}
		goto _4
	_4:
		;
		pTree = (*TRowSetEntry)(unsafe.Pointer(pTree)).FpRight
	}
	return 0
}

/************** End of rowset.c **********************************************/
/************** Begin file pager.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 is the implementation of the page cache subsystem or "pager".
**
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
 */
/* #include "sqliteInt.h" */
/************** Include wal.h in the middle of pager.c ***********************/
/************** Begin file wal.h *********************************************/
/*
** 2010 February 1
**
** 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 header file defines the interface to the write-ahead logging
** system. Refer to the comments below and the header comment attached to
** the implementation of each function in log.c for further details.
 */

/* #include "sqliteInt.h" */

/* Macros for extracting appropriate sync flags for either transaction
** commits (WAL_SYNC_FLAGS(X)) or for checkpoint ops (CKPT_SYNC_FLAGS(X)):
 */

// C documentation
//
//	/* Connection to a write-ahead log (WAL) file.
//	** There is one object of this type for each pager.
//	*/
type TWal = struct {
	F__ccgo_align        [0]uint32
	FpVfs                uintptr
	FpDbFd               uintptr
	FpWalFd              uintptr
	FiCallback           Tu32
	FmxWalSize           Ti64
	FnWiData             int32
	FszFirstBlock        int32
	FapWiData            uintptr
	FszPage              Tu32
	FreadLock            Ti16
	FsyncFlags           Tu8
	FexclusiveMode       Tu8
	FwriteLock           Tu8
	FckptLock            Tu8
	FreadOnly            Tu8
	FtruncateOnCommit    Tu8
	FsyncHeader          Tu8
	FpadToSectorBoundary Tu8
	FbShmUnreliable      Tu8
	Fhdr                 TWalIndexHdr
	FminFrame            Tu32
	FiReCksum            Tu32
	FzWalName            uintptr
	FnCkpt               Tu32
	FpSnapshot           uintptr
}

type Wal = TWal

/************** End of wal.h *************************************************/
/************** Continuing where we left off in pager.c **********************/

/******************* NOTES ON THE DESIGN OF THE PAGER ************************
**
** This comment block describes invariants that hold when using a rollback
** journal.  These invariants do not apply for journal_mode=WAL,
** journal_mode=MEMORY, or journal_mode=OFF.
**
** Within this comment block, a page is deemed to have been synced
** automatically as soon as it is written when PRAGMA synchronous=OFF.
** Otherwise, the page is not synced until the xSync method of the VFS
** is called successfully on the file containing the page.
**
** Definition:  A page of the database file is said to be "overwriteable" if
** one or more of the following are true about the page:
**
**     (a)  The original content of the page as it was at the beginning of
**          the transaction has been written into the rollback journal and
**          synced.
**
**     (b)  The page was a freelist leaf page at the start of the transaction.
**
**     (c)  The page number is greater than the largest page that existed in
**          the database file at the start of the transaction.
**
** (1) A page of the database file is never overwritten unless one of the
**     following are true:
**
**     (a) The page and all other pages on the same sector are overwriteable.
**
**     (b) The atomic page write optimization is enabled, and the entire
**         transaction other than the update of the transaction sequence
**         number consists of a single page change.
**
** (2) The content of a page written into the rollback journal exactly matches
**     both the content in the database when the rollback journal was written
**     and the content in the database at the beginning of the current
**     transaction.
**
** (3) Writes to the database file are an integer multiple of the page size
**     in length and are aligned on a page boundary.
**
** (4) Reads from the database file are either aligned on a page boundary and
**     an integer multiple of the page size in length or are taken from the
**     first 100 bytes of the database file.
**
** (5) All writes to the database file are synced prior to the rollback journal
**     being deleted, truncated, or zeroed.
**
** (6) If a super-journal file is used, then all writes to the database file
**     are synced prior to the super-journal being deleted.
**
** Definition: Two databases (or the same database at two points it time)
** are said to be "logically equivalent" if they give the same answer to
** all queries.  Note in particular the content of freelist leaf
** pages can be changed arbitrarily without affecting the logical equivalence
** of the database.
**
** (7) At any time, if any subset, including the empty set and the total set,
**     of the unsynced changes to a rollback journal are removed and the
**     journal is rolled back, the resulting database file will be logically
**     equivalent to the database file at the beginning of the transaction.
**
** (8) When a transaction is rolled back, the xTruncate method of the VFS
**     is called to restore the database file to the same size it was at
**     the beginning of the transaction.  (In some VFSes, the xTruncate
**     method is a no-op, but that does not change the fact the SQLite will
**     invoke it.)
**
** (9) Whenever the database file is modified, at least one bit in the range
**     of bytes from 24 through 39 inclusive will be changed prior to releasing
**     the EXCLUSIVE lock, thus signaling other connections on the same
**     database to flush their caches.
**
** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
**      than one billion transactions.
**
** (11) A database file is well-formed at the beginning and at the conclusion
**      of every transaction.
**
** (12) An EXCLUSIVE lock is held on the database file when writing to
**      the database file.
**
** (13) A SHARED lock is held on the database file while reading any
**      content out of the database file.
**
******************************************************************************/

/*
** Macros for troubleshooting.  Normally turned off
 */

/*
** The following two macros are used within the PAGERTRACE() macros above
** to print out file-descriptors.
**
** PAGERID() takes a pointer to a Pager struct as its argument. The
** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
** struct as its argument.
 */

/*
** The Pager.eState variable stores the current 'state' of a pager. A
** pager may be in any one of the seven states shown in the following
** state diagram.
**
**                            OPEN <------+------+
**                              |         |      |
**                              V         |      |
**               +---------> READER-------+      |
**               |              |                |
**               |              V                |
**               |<-------WRITER_LOCKED------> ERROR
**               |              |                ^
**               |              V                |
**               |<------WRITER_CACHEMOD-------->|
**               |              |                |
**               |              V                |
**               |<-------WRITER_DBMOD---------->|
**               |              |                |
**               |              V                |
**               +<------WRITER_FINISHED-------->+
**
**
** List of state transitions and the C [function] that performs each:
**
**   OPEN              -> READER              [sqlite3PagerSharedLock]
**   READER            -> OPEN                [pager_unlock]
**
**   READER            -> WRITER_LOCKED       [sqlite3PagerBegin]
**   WRITER_LOCKED     -> WRITER_CACHEMOD     [pager_open_journal]
**   WRITER_CACHEMOD   -> WRITER_DBMOD        [syncJournal]
**   WRITER_DBMOD      -> WRITER_FINISHED     [sqlite3PagerCommitPhaseOne]
**   WRITER_***        -> READER              [pager_end_transaction]
**
**   WRITER_***        -> ERROR               [pager_error]
**   ERROR             -> OPEN                [pager_unlock]
**
**
**  OPEN:
**
**    The pager starts up in this state. Nothing is guaranteed in this
**    state - the file may or may not be locked and the database size is
**    unknown. The database may not be read or written.
**
**    * No read or write transaction is active.
**    * Any lock, or no lock at all, may be held on the database file.
**    * The dbSize, dbOrigSize and dbFileSize variables may not be trusted.
**
**  READER:
**
**    In this state all the requirements for reading the database in
**    rollback (non-WAL) mode are met. Unless the pager is (or recently
**    was) in exclusive-locking mode, a user-level read transaction is
**    open. The database size is known in this state.
**
**    A connection running with locking_mode=normal enters this state when
**    it opens a read-transaction on the database and returns to state
**    OPEN after the read-transaction is completed. However a connection
**    running in locking_mode=exclusive (including temp databases) remains in
**    this state even after the read-transaction is closed. The only way
**    a locking_mode=exclusive connection can transition from READER to OPEN
**    is via the ERROR state (see below).
**
**    * A read transaction may be active (but a write-transaction cannot).
**    * A SHARED or greater lock is held on the database file.
**    * The dbSize variable may be trusted (even if a user-level read
**      transaction is not active). The dbOrigSize and dbFileSize variables
**      may not be trusted at this point.
**    * If the database is a WAL database, then the WAL connection is open.
**    * Even if a read-transaction is not open, it is guaranteed that
**      there is no hot-journal in the file-system.
**
**  WRITER_LOCKED:
**
**    The pager moves to this state from READER when a write-transaction
**    is first opened on the database. In WRITER_LOCKED state, all locks
**    required to start a write-transaction are held, but no actual
**    modifications to the cache or database have taken place.
**
**    In rollback mode, a RESERVED or (if the transaction was opened with
**    BEGIN EXCLUSIVE) EXCLUSIVE lock is obtained on the database file when
**    moving to this state, but the journal file is not written to or opened
**    to in this state. If the transaction is committed or rolled back while
**    in WRITER_LOCKED state, all that is required is to unlock the database
**    file.
**
**    IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
**    If the connection is running with locking_mode=exclusive, an attempt
**    is made to obtain an EXCLUSIVE lock on the database file.
**
**    * A write transaction is active.
**    * If the connection is open in rollback-mode, a RESERVED or greater
**      lock is held on the database file.
**    * If the connection is open in WAL-mode, a WAL write transaction
**      is open (i.e. sqlite3WalBeginWriteTransaction() has been successfully
**      called).
**    * The dbSize, dbOrigSize and dbFileSize variables are all valid.
**    * The contents of the pager cache have not been modified.
**    * The journal file may or may not be open.
**    * Nothing (not even the first header) has been written to the journal.
**
**  WRITER_CACHEMOD:
**
**    A pager moves from WRITER_LOCKED state to this state when a page is
**    first modified by the upper layer. In rollback mode the journal file
**    is opened (if it is not already open) and a header written to the
**    start of it. The database file on disk has not been modified.
**
**    * A write transaction is active.
**    * A RESERVED or greater lock is held on the database file.
**    * The journal file is open and the first header has been written
**      to it, but the header has not been synced to disk.
**    * The contents of the page cache have been modified.
**
**  WRITER_DBMOD:
**
**    The pager transitions from WRITER_CACHEMOD into WRITER_DBMOD state
**    when it modifies the contents of the database file. WAL connections
**    never enter this state (since they do not modify the database file,
**    just the log file).
**
**    * A write transaction is active.
**    * An EXCLUSIVE or greater lock is held on the database file.
**    * The journal file is open and the first header has been written
**      and synced to disk.
**    * The contents of the page cache have been modified (and possibly
**      written to disk).
**
**  WRITER_FINISHED:
**
**    It is not possible for a WAL connection to enter this state.
**
**    A rollback-mode pager changes to WRITER_FINISHED state from WRITER_DBMOD
**    state after the entire transaction has been successfully written into the
**    database file. In this state the transaction may be committed simply
**    by finalizing the journal file. Once in WRITER_FINISHED state, it is
**    not possible to modify the database further. At this point, the upper
**    layer must either commit or rollback the transaction.
**
**    * A write transaction is active.
**    * An EXCLUSIVE or greater lock is held on the database file.
**    * All writing and syncing of journal and database data has finished.
**      If no error occurred, all that remains is to finalize the journal to
**      commit the transaction. If an error did occur, the caller will need
**      to rollback the transaction.
**
**  ERROR:
**
**    The ERROR state is entered when an IO or disk-full error (including
**    SQLITE_IOERR_NOMEM) occurs at a point in the code that makes it
**    difficult to be sure that the in-memory pager state (cache contents,
**    db size etc.) are consistent with the contents of the file-system.
**
**    Temporary pager files may enter the ERROR state, but in-memory pagers
**    cannot.
**
**    For example, if an IO error occurs while performing a rollback,
**    the contents of the page-cache may be left in an inconsistent state.
**    At this point it would be dangerous to change back to READER state
**    (as usually happens after a rollback). Any subsequent readers might
**    report database corruption (due to the inconsistent cache), and if
**    they upgrade to writers, they may inadvertently corrupt the database
**    file. To avoid this hazard, the pager switches into the ERROR state
**    instead of READER following such an error.
**
**    Once it has entered the ERROR state, any attempt to use the pager
**    to read or write data returns an error. Eventually, once all
**    outstanding transactions have been abandoned, the pager is able to
**    transition back to OPEN state, discarding the contents of the
**    page-cache and any other in-memory state at the same time. Everything
**    is reloaded from disk (and, if necessary, hot-journal rollback performed)
**    when a read-transaction is next opened on the pager (transitioning
**    the pager into READER state). At that point the system has recovered
**    from the error.
**
**    Specifically, the pager jumps into the ERROR state if:
**
**      1. An error occurs while attempting a rollback. This happens in
**         function sqlite3PagerRollback().
**
**      2. An error occurs while attempting to finalize a journal file
**         following a commit in function sqlite3PagerCommitPhaseTwo().
**
**      3. An error occurs while attempting to write to the journal or
**         database file in function pagerStress() in order to free up
**         memory.
**
**    In other cases, the error is returned to the b-tree layer. The b-tree
**    layer then attempts a rollback operation. If the error condition
**    persists, the pager enters the ERROR state via condition (1) above.
**
**    Condition (3) is necessary because it can be triggered by a read-only
**    statement executed within a transaction. In this case, if the error
**    code were simply returned to the user, the b-tree layer would not
**    automatically attempt a rollback, as it assumes that an error in a
**    read-only statement cannot leave the pager in an internally inconsistent
**    state.
**
**    * The Pager.errCode variable is set to something other than SQLITE_OK.
**    * There are one or more outstanding references to pages (after the
**      last reference is dropped the pager should move back to OPEN state).
**    * The pager is not an in-memory pager.
**
**
** Notes:
**
**   * A pager is never in WRITER_DBMOD or WRITER_FINISHED state if the
**     connection is open in WAL mode. A WAL connection is always in one
**     of the first four states.
**
**   * Normally, a connection open in exclusive mode is never in PAGER_OPEN
**     state. There are two exceptions: immediately after exclusive-mode has
**     been turned on (and before any read or write transactions are
**     executed), and when the pager is leaving the "error state".
**
**   * See also: assert_pager_state().
 */

/*
** The Pager.eLock variable is almost always set to one of the
** following locking-states, according to the lock currently held on
** the database file: NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
** This variable is kept up to date as locks are taken and released by
** the pagerLockDb() and pagerUnlockDb() wrappers.
**
** If the VFS xLock() or xUnlock() returns an error other than SQLITE_BUSY
** (i.e. one of the SQLITE_IOERR subtypes), it is not clear whether or not
** the operation was successful. In these circumstances pagerLockDb() and
** pagerUnlockDb() take a conservative approach - eLock is always updated
** when unlocking the file, and only updated when locking the file if the
** VFS call is successful. This way, the Pager.eLock variable may be set
** to a less exclusive (lower) value than the lock that is actually held
** at the system level, but it is never set to a more exclusive value.
**
** This is usually safe. If an xUnlock fails or appears to fail, there may
** be a few redundant xLock() calls or a lock may be held for longer than
** required, but nothing really goes wrong.
**
** The exception is when the database file is unlocked as the pager moves
** from ERROR to OPEN state. At this point there may be a hot-journal file
** in the file-system that needs to be rolled back (as part of an OPEN->SHARED
** transition, by the same pager or any other). If the call to xUnlock()
** fails at this point and the pager is left holding an EXCLUSIVE lock, this
** can confuse the call to xCheckReservedLock() call made later as part
** of hot-journal detection.
**
** xCheckReservedLock() is defined as returning true "if there is a RESERVED
** lock held by this process or any others". So xCheckReservedLock may
** return true because the caller itself is holding an EXCLUSIVE lock (but
** doesn't know it because of a previous error in xUnlock). If this happens
** a hot-journal may be mistaken for a journal being created by an active
** transaction in another process, causing SQLite to read from the database
** without rolling it back.
**
** To work around this, if a call to xUnlock() fails when unlocking the
** database in the ERROR state, Pager.eLock is set to UNKNOWN_LOCK. It
** is only changed back to a real locking state after a successful call
** to xLock(EXCLUSIVE). Also, the code to do the OPEN->SHARED state transition
** omits the check for a hot-journal if Pager.eLock is set to UNKNOWN_LOCK
** lock. Instead, it assumes a hot-journal exists and obtains an EXCLUSIVE
** lock on the database file before attempting to roll it back. See function
** PagerSharedLock() for more detail.
**
** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in
** PAGER_OPEN state.
 */

/*
** The maximum allowed sector size. 64KiB. If the xSectorsize() method
** returns a value larger than this, then MAX_SECTOR_SIZE is used instead.
** This could conceivably cause corruption following a power failure on
** such a system. This is currently an undocumented limit.
 */

// C documentation
//
//	/*
//	** An instance of the following structure is allocated for each active
//	** savepoint and statement transaction in the system. All such structures
//	** are stored in the Pager.aSavepoint[] array, which is allocated and
//	** resized using sqlite3Realloc().
//	**
//	** When a savepoint is created, the PagerSavepoint.iHdrOffset field is
//	** set to 0. If a journal-header is written into the main journal while
//	** the savepoint is active, then iHdrOffset is set to the byte offset
//	** immediately following the last journal record written into the main
//	** journal before the journal-header. This is required during savepoint
//	** rollback (see pagerPlaybackSavepoint()).
//	*/
type TPagerSavepoint = struct {
	F__ccgo_align       [0]uint32
	FiOffset            Ti64
	FiHdrOffset         Ti64
	FpInSavepoint       uintptr
	FnOrig              TPgno
	FiSubRec            TPgno
	FbTruncateOnRelease int32
	FaWalData           [4]Tu32
}

type PagerSavepoint = TPagerSavepoint

type TPagerSavepoint1 = struct {
	F__ccgo_align       [0]uint32
	FiOffset            Ti64
	FiHdrOffset         Ti64
	FpInSavepoint       uintptr
	FnOrig              TPgno
	FiSubRec            TPgno
	FbTruncateOnRelease int32
	FaWalData           [4]Tu32
}

type PagerSavepoint1 = TPagerSavepoint1

/*
** Bits of the Pager.doNotSpill flag.  See further description below.
 */

/*
** An open page cache is an instance of struct Pager. A description of
** some of the more important member variables follows:
**
** eState
**
**   The current 'state' of the pager object. See the comment and state
**   diagram above for a description of the pager state.
**
** eLock
**
**   For a real on-disk database, the current lock held on the database file -
**   NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
**
**   For a temporary or in-memory database (neither of which require any
**   locks), this variable is always set to EXCLUSIVE_LOCK. Since such
**   databases always have Pager.exclusiveMode==1, this tricks the pager
**   logic into thinking that it already has all the locks it will ever
**   need (and no reason to release them).
**
**   In some (obscure) circumstances, this variable may also be set to
**   UNKNOWN_LOCK. See the comment above the #define of UNKNOWN_LOCK for
**   details.
**
** changeCountDone
**
**   This boolean variable is used to make sure that the change-counter
**   (the 4-byte header field at byte offset 24 of the database file) is
**   not updated more often than necessary.
**
**   It is set to true when the change-counter field is updated, which
**   can only happen if an exclusive lock is held on the database file.
**   It is cleared (set to false) whenever an exclusive lock is
**   relinquished on the database file. Each time a transaction is committed,
**   The changeCountDone flag is inspected. If it is true, the work of
**   updating the change-counter is omitted for the current transaction.
**
**   This mechanism means that when running in exclusive mode, a connection
**   need only update the change-counter once, for the first transaction
**   committed.
**
** setSuper
**
**   When PagerCommitPhaseOne() is called to commit a transaction, it may
**   (or may not) specify a super-journal name to be written into the
**   journal file before it is synced to disk.
**
**   Whether or not a journal file contains a super-journal pointer affects
**   the way in which the journal file is finalized after the transaction is
**   committed or rolled back when running in "journal_mode=PERSIST" mode.
**   If a journal file does not contain a super-journal pointer, it is
**   finalized by overwriting the first journal header with zeroes. If
**   it does contain a super-journal pointer the journal file is finalized
**   by truncating it to zero bytes, just as if the connection were
**   running in "journal_mode=truncate" mode.
**
**   Journal files that contain super-journal pointers cannot be finalized
**   simply by overwriting the first journal-header with zeroes, as the
**   super-journal pointer could interfere with hot-journal rollback of any
**   subsequently interrupted transaction that reuses the journal file.
**
**   The flag is cleared as soon as the journal file is finalized (either
**   by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
**   journal file from being successfully finalized, the setSuper flag
**   is cleared anyway (and the pager will move to ERROR state).
**
** doNotSpill
**
**   This variables control the behavior of cache-spills  (calls made by
**   the pcache module to the pagerStress() routine to write cached data
**   to the file-system in order to free up memory).
**
**   When bits SPILLFLAG_OFF or SPILLFLAG_ROLLBACK of doNotSpill are set,
**   writing to the database from pagerStress() is disabled altogether.
**   The SPILLFLAG_ROLLBACK case is done in a very obscure case that
**   comes up during savepoint rollback that requires the pcache module
**   to allocate a new page to prevent the journal file from being written
**   while it is being traversed by code in pager_playback().  The SPILLFLAG_OFF
**   case is a user preference.
**
**   If the SPILLFLAG_NOSYNC bit is set, writing to the database from
**   pagerStress() is permitted, but syncing the journal file is not.
**   This flag is set by sqlite3PagerWrite() when the file-system sector-size
**   is larger than the database page-size in order to prevent a journal sync
**   from happening in between the journalling of two pages on the same sector.
**
** subjInMemory
**
**   This is a boolean variable. If true, then any required sub-journal
**   is opened as an in-memory journal file. If false, then in-memory
**   sub-journals are only used for in-memory pager files.
**
**   This variable is updated by the upper layer each time a new
**   write-transaction is opened.
**
** dbSize, dbOrigSize, dbFileSize
**
**   Variable dbSize is set to the number of pages in the database file.
**   It is valid in PAGER_READER and higher states (all states except for
**   OPEN and ERROR).
**
**   dbSize is set based on the size of the database file, which may be
**   larger than the size of the database (the value stored at offset
**   28 of the database header by the btree). If the size of the file
**   is not an integer multiple of the page-size, the value stored in
**   dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
**   Except, any file that is greater than 0 bytes in size is considered
**   to have at least one page. (i.e. a 1KB file with 2K page-size leads
**   to dbSize==1).
**
**   During a write-transaction, if pages with page-numbers greater than
**   dbSize are modified in the cache, dbSize is updated accordingly.
**   Similarly, if the database is truncated using PagerTruncateImage(),
**   dbSize is updated.
**
**   Variables dbOrigSize and dbFileSize are valid in states
**   PAGER_WRITER_LOCKED and higher. dbOrigSize is a copy of the dbSize
**   variable at the start of the transaction. It is used during rollback,
**   and to determine whether or not pages need to be journalled before
**   being modified.
**
**   Throughout a write-transaction, dbFileSize contains the size of
**   the file on disk in pages. It is set to a copy of dbSize when the
**   write-transaction is first opened, and updated when VFS calls are made
**   to write or truncate the database file on disk.
**
**   The only reason the dbFileSize variable is required is to suppress
**   unnecessary calls to xTruncate() after committing a transaction. If,
**   when a transaction is committed, the dbFileSize variable indicates
**   that the database file is larger than the database image (Pager.dbSize),
**   pager_truncate() is called. The pager_truncate() call uses xFilesize()
**   to measure the database file on disk, and then truncates it if required.
**   dbFileSize is not used when rolling back a transaction. In this case
**   pager_truncate() is called unconditionally (which means there may be
**   a call to xFilesize() that is not strictly required). In either case,
**   pager_truncate() may cause the file to become smaller or larger.
**
** dbHintSize
**
**   The dbHintSize variable is used to limit the number of calls made to
**   the VFS xFileControl(FCNTL_SIZE_HINT) method.
**
**   dbHintSize is set to a copy of the dbSize variable when a
**   write-transaction is opened (at the same time as dbFileSize and
**   dbOrigSize). If the xFileControl(FCNTL_SIZE_HINT) method is called,
**   dbHintSize is increased to the number of pages that correspond to the
**   size-hint passed to the method call. See pager_write_pagelist() for
**   details.
**
** errCode
**
**   The Pager.errCode variable is only ever used in PAGER_ERROR state. It
**   is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
**   is always set to SQLITE_FULL, SQLITE_IOERR or one of the SQLITE_IOERR_XXX
**   sub-codes.
**
** syncFlags, walSyncFlags
**
**   syncFlags is either SQLITE_SYNC_NORMAL (0x02) or SQLITE_SYNC_FULL (0x03).
**   syncFlags is used for rollback mode.  walSyncFlags is used for WAL mode
**   and contains the flags used to sync the checkpoint operations in the
**   lower two bits, and sync flags used for transaction commits in the WAL
**   file in bits 0x04 and 0x08.  In other words, to get the correct sync flags
**   for checkpoint operations, use (walSyncFlags&0x03) and to get the correct
**   sync flags for transaction commit, use ((walSyncFlags>>2)&0x03).  Note
**   that with synchronous=NORMAL in WAL mode, transaction commit is not synced
**   meaning that the 0x04 and 0x08 bits are both zero.
 */
type TPager1 = struct {
	F__ccgo_align      [0]uint32
	FpVfs              uintptr
	FexclusiveMode     Tu8
	FjournalMode       Tu8
	FuseJournal        Tu8
	FnoSync            Tu8
	FfullSync          Tu8
	FextraSync         Tu8
	FsyncFlags         Tu8
	FwalSyncFlags      Tu8
	FtempFile          Tu8
	FnoLock            Tu8
	FreadOnly          Tu8
	FmemDb             Tu8
	FmemVfs            Tu8
	FeState            Tu8
	FeLock             Tu8
	FchangeCountDone   Tu8
	FsetSuper          Tu8
	FdoNotSpill        Tu8
	FsubjInMemory      Tu8
	FbUseFetch         Tu8
	FhasHeldSharedLock Tu8
	FdbSize            TPgno
	FdbOrigSize        TPgno
	FdbFileSize        TPgno
	FdbHintSize        TPgno
	FerrCode           int32
	FnRec              int32
	FcksumInit         Tu32
	FnSubRec           Tu32
	FpInJournal        uintptr
	Ffd                uintptr
	Fjfd               uintptr
	Fsjfd              uintptr
	F__ccgo_align34    [4]byte
	FjournalOff        Ti64
	FjournalHdr        Ti64
	FpBackup           uintptr
	FaSavepoint        uintptr
	FnSavepoint        int32
	FiDataVersion      Tu32
	FdbFileVers        [16]int8
	FnMmapOut          int32
	F__ccgo_align42    [4]byte
	FszMmap            Tsqlite3_int64
	FpMmapFreelist     uintptr
	FnExtra            Tu16
	FnReserve          Ti16
	FvfsFlags          Tu32
	FsectorSize        Tu32
	FmxPgno            TPgno
	FlckPgno           TPgno
	FpageSize          Ti64
	FjournalSizeLimit  Ti64
	FzFilename         uintptr
	FzJournal          uintptr
	FxBusyHandler      uintptr
	FpBusyHandlerArg   uintptr
	FaStat             [4]Tu32
	FxReiniter         uintptr
	FxGet              uintptr
	FpTmpSpace         uintptr
	FpPCache           uintptr
	FpWal              uintptr
	FzWal              uintptr
}

type Pager1 = TPager1

/*
** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS
** or CACHE_WRITE to sqlite3_db_status().
 */

/*
** The following global variables hold counters used for
** testing purposes only.  These variables do not exist in
** a non-testing build.  These variables are not thread-safe.
 */

// C documentation
//
//	/*
//	** Journal files begin with the following magic string.  The data
//	** was obtained from /dev/random.  It is used only as a sanity check.
//	**
//	** Since version 2.8.0, the journal format contains additional sanity
//	** checking information.  If the power fails while the journal is being
//	** written, semi-random garbage data might appear in the journal
//	** file after power is restored.  If an attempt is then made
//	** to roll the journal back, the database could be corrupted.  The additional
//	** sanity checking data is an attempt to discover the garbage in the
//	** journal and ignore it.
//	**
//	** The sanity checking information for the new journal format consists
//	** of a 32-bit checksum on each page of data.  The checksum covers both
//	** the page number and the pPager->pageSize bytes of data for the page.
//	** This cksum is initialized to a 32-bit random value that appears in the
//	** journal file right after the header.  The random initializer is important,
//	** because garbage data that appears at the end of a journal is likely
//	** data that was once in other files that have now been deleted.  If the
//	** garbage data came from an obsolete journal file, the checksums might
//	** be correct.  But by initializing the checksum to random value which
//	** is different for every journal, we minimize that risk.
//	*/
var _aJournalMagic = [8]uint8{
	0: uint8(0xd9),
	1: uint8(0xd5),
	2: uint8(0x05),
	3: uint8(0xf9),
	4: uint8(0x20),
	5: uint8(0xa1),
	6: uint8(0x63),
	7: uint8(0xd7),
}

/*
** The size of the of each page record in the journal is given by
** the following macro.
 */

/*
** The journal header size for this pager. This is usually the same
** size as a single disk sector. See also setSectorSize().
 */

/*
** The macro MEMDB is true if we are dealing with an in-memory database.
** We do this as a macro so that if the SQLITE_OMIT_MEMORYDB macro is set,
** the value of MEMDB will be a constant and the compiler will optimize
** out code that would never execute.
 */

/*
** The macro USEFETCH is true if we are allowed to use the xFetch and xUnfetch
** interfaces to access the database using memory-mapped I/O.
 */

/*
** The argument to this macro is a file descriptor (type sqlite3_file*).
** Return 0 if it is not open, or non-zero (but not 1) if it is.
**
** This is so that expressions can be written as:
**
**   if( isOpen(pPager->jfd) ){ ...
**
** instead of
**
**   if( pPager->jfd->pMethods ){ ...
 */

// C documentation
//
//	/*
//	** Return true if page pgno can be read directly from the database file
//	** by the b-tree layer. This is the case if:
//	**
//	**   * the database file is open,
//	**   * there are no dirty pages in the cache, and
//	**   * the desired page is not currently in the wal file.
//	*/
func _sqlite3PagerDirectReadOk(tls *libc.TLS, pPager uintptr, pgno TPgno) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* iRead at bp+0 */ Tu32
	if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods == uintptr(0) {
		return 0
	}
	if _sqlite3PCacheIsDirty(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache) != 0 {
		return 0
	}
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		_sqlite3WalFindFrame(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, pgno, bp)
		return libc.BoolInt32(*(*Tu32)(unsafe.Pointer(bp)) == uint32(0))
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Set the Pager.xGet method for the appropriate routine used to fetch
//	** content from the pager.
//	*/
func _setGetterMethod(tls *libc.TLS, pPager uintptr) {
	if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		(*TPager)(unsafe.Pointer(pPager)).FxGet = __ccgo_fp(_getPageError)
	} else {
		if (*TPager)(unsafe.Pointer(pPager)).FbUseFetch != 0 {
			(*TPager)(unsafe.Pointer(pPager)).FxGet = __ccgo_fp(_getPageMMap)
		} else {
			(*TPager)(unsafe.Pointer(pPager)).FxGet = __ccgo_fp(_getPageNormal)
		}
	}
}

// C documentation
//
//	/*
//	** Return true if it is necessary to write page *pPg into the sub-journal.
//	** A page needs to be written into the sub-journal if there exists one
//	** or more open savepoints for which:
//	**
//	**   * The page-number is less than or equal to PagerSavepoint.nOrig, and
//	**   * The bit corresponding to the page-number is not set in
//	**     PagerSavepoint.pInSavepoint.
//	*/
func _subjRequiresPage(tls *libc.TLS, pPg uintptr) (r int32) {
	var i int32
	var p, pPager uintptr
	var pgno TPgno
	_, _, _, _ = i, p, pPager, pgno
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	pgno = (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno
	i = 0
	for {
		if !(i < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
			break
		}
		p = (*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(i)*48
		if (*TPagerSavepoint)(unsafe.Pointer(p)).FnOrig >= pgno && 0 == _sqlite3BitvecTestNotNull(tls, (*TPagerSavepoint)(unsafe.Pointer(p)).FpInSavepoint, pgno) {
			i = i + int32(1)
			for {
				if !(i < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
					break
				}
				(*(*TPagerSavepoint)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(i)*48))).FbTruncateOnRelease = 0
				goto _2
			_2:
				;
				i++
			}
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Read a 32-bit integer from the given file descriptor.  Store the integer
//	** that is read in *pRes.  Return SQLITE_OK if everything worked, or an
//	** error code is something goes wrong.
//	**
//	** All values are stored on disk as big-endian.
//	*/
func _read32bits(tls *libc.TLS, fd uintptr, offset Ti64, pRes uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* ac at bp+0 */ [4]uint8
	_ = rc
	rc = _sqlite3OsRead(tls, fd, bp, int32(4), offset)
	if rc == SQLITE_OK {
		*(*Tu32)(unsafe.Pointer(pRes)) = _sqlite3Get4byte(tls, bp)
	}
	return rc
}

/*
** Write a 32-bit integer into a string buffer in big-endian byte order.
 */

// C documentation
//
//	/*
//	** Write a 32-bit integer into the given file descriptor.  Return SQLITE_OK
//	** on success or an error code is something goes wrong.
//	*/
func _write32bits(tls *libc.TLS, fd uintptr, offset Ti64, val Tu32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* ac at bp+0 */ [4]int8
	_sqlite3Put4byte(tls, bp, val)
	return _sqlite3OsWrite(tls, fd, bp, int32(4), offset)
}

// C documentation
//
//	/*
//	** Unlock the database file to level eLock, which must be either NO_LOCK
//	** or SHARED_LOCK. Regardless of whether or not the call to xUnlock()
//	** succeeds, set the Pager.eLock variable to match the (attempted) new lock.
//	**
//	** Except, if Pager.eLock is set to UNKNOWN_LOCK when this function is
//	** called, do not modify it. See the comment above the #define of
//	** UNKNOWN_LOCK for an explanation of this.
//	*/
func _pagerUnlockDb(tls *libc.TLS, pPager uintptr, eLock int32) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	rc = SQLITE_OK
	if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
		if (*TPager)(unsafe.Pointer(pPager)).FnoLock != 0 {
			v1 = SQLITE_OK
		} else {
			v1 = _sqlite3OsUnlock(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, eLock)
		}
		rc = v1
		if int32((*TPager)(unsafe.Pointer(pPager)).FeLock) != libc.Int32FromInt32(EXCLUSIVE_LOCK)+libc.Int32FromInt32(1) {
			(*TPager)(unsafe.Pointer(pPager)).FeLock = uint8(uint8(eLock))
		}
	}
	(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = (*TPager)(unsafe.Pointer(pPager)).FtempFile /* ticket fb3b3024ea238d5c */
	return rc
}

// C documentation
//
//	/*
//	** Lock the database file to level eLock, which must be either SHARED_LOCK,
//	** RESERVED_LOCK or EXCLUSIVE_LOCK. If the caller is successful, set the
//	** Pager.eLock variable to the new locking state.
//	**
//	** Except, if Pager.eLock is set to UNKNOWN_LOCK when this function is
//	** called, do not modify it unless the new locking state is EXCLUSIVE_LOCK.
//	** See the comment above the #define of UNKNOWN_LOCK for an explanation
//	** of this.
//	*/
func _pagerLockDb(tls *libc.TLS, pPager uintptr, eLock int32) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	rc = SQLITE_OK
	if int32((*TPager)(unsafe.Pointer(pPager)).FeLock) < eLock || int32((*TPager)(unsafe.Pointer(pPager)).FeLock) == libc.Int32FromInt32(EXCLUSIVE_LOCK)+libc.Int32FromInt32(1) {
		if (*TPager)(unsafe.Pointer(pPager)).FnoLock != 0 {
			v1 = SQLITE_OK
		} else {
			v1 = _sqlite3OsLock(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, eLock)
		}
		rc = v1
		if rc == SQLITE_OK && (int32((*TPager)(unsafe.Pointer(pPager)).FeLock) != libc.Int32FromInt32(EXCLUSIVE_LOCK)+libc.Int32FromInt32(1) || eLock == int32(EXCLUSIVE_LOCK)) {
			(*TPager)(unsafe.Pointer(pPager)).FeLock = uint8(uint8(eLock))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function determines whether or not the atomic-write or
//	** atomic-batch-write optimizations can be used with this pager. The
//	** atomic-write optimization can be used if:
//	**
//	**  (a) the value returned by OsDeviceCharacteristics() indicates that
//	**      a database page may be written atomically, and
//	**  (b) the value returned by OsSectorSize() is less than or equal
//	**      to the page size.
//	**
//	** If it can be used, then the value returned is the size of the journal
//	** file when it contains rollback data for exactly one page.
//	**
//	** The atomic-batch-write optimization can be used if OsDeviceCharacteristics()
//	** returns a value with the SQLITE_IOCAP_BATCH_ATOMIC bit set. -1 is
//	** returned in this case.
//	**
//	** If neither optimization can be used, 0 is returned.
//	*/
func _jrnlBufferSize(tls *libc.TLS, pPager uintptr) (r int32) {
	_ = pPager
	return 0
}

/*
** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
** on the cache using a hash function.  This is used for testing
** and debugging only.
 */

// C documentation
//
//	/*
//	** When this is called the journal file for pager pPager must be open.
//	** This function attempts to read a super-journal file name from the
//	** end of the file and, if successful, copies it into memory supplied
//	** by the caller. See comments above writeSuperJournal() for the format
//	** used to store a super-journal file name at the end of a journal file.
//	**
//	** zSuper must point to a buffer of at least nSuper bytes allocated by
//	** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
//	** enough space to write the super-journal name). If the super-journal
//	** name in the journal is longer than nSuper bytes (including a
//	** nul-terminator), then this is handled as if no super-journal name
//	** were present in the journal.
//	**
//	** If a super-journal file name is present at the end of the journal
//	** file, then it is copied into the buffer pointed to by zSuper. A
//	** nul-terminator byte is appended to the buffer following the
//	** super-journal file name.
//	**
//	** If it is determined that no super-journal file name is present
//	** zSuper[0] is set to 0 and SQLITE_OK returned.
//	**
//	** If an error occurs while reading from the journal file, an SQLite
//	** error code is returned.
//	*/
func _readSuperJournal(tls *libc.TLS, pJrnl uintptr, zSuper uintptr, nSuper Tu32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc, v1, v2, v4, v6, v8 int32
	var u Tu32
	var v3, v5, v7, v9 bool
	var _ /* aMagic at bp+24 */ [8]uint8
	var _ /* cksum at bp+16 */ Tu32
	var _ /* len at bp+0 */ Tu32
	var _ /* szJ at bp+8 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _ = rc, u, v1, v2, v3, v4, v5, v6, v7, v8, v9 /* A buffer to hold the magic header */
	*(*int8)(unsafe.Pointer(zSuper)) = int8('\000')
	v1 = _sqlite3OsFileSize(tls, pJrnl, bp+8)
	rc = v1
	if v3 = SQLITE_OK != v1 || *(*Ti64)(unsafe.Pointer(bp + 8)) < int64(16); !v3 {
		v2 = _read32bits(tls, pJrnl, *(*Ti64)(unsafe.Pointer(bp + 8))-int64(16), bp)
		rc = v2
	}
	if v5 = v3 || SQLITE_OK != v2 || *(*Tu32)(unsafe.Pointer(bp)) >= nSuper || int64(*(*Tu32)(unsafe.Pointer(bp))) > *(*Ti64)(unsafe.Pointer(bp + 8))-int64(16) || *(*Tu32)(unsafe.Pointer(bp)) == uint32(0); !v5 {
		v4 = _read32bits(tls, pJrnl, *(*Ti64)(unsafe.Pointer(bp + 8))-int64(12), bp+16)
		rc = v4
	}
	if v7 = v5 || SQLITE_OK != v4; !v7 {
		v6 = _sqlite3OsRead(tls, pJrnl, bp+24, int32(8), *(*Ti64)(unsafe.Pointer(bp + 8))-int64(8))
		rc = v6
	}
	if v9 = v7 || SQLITE_OK != v6 || libc.Xmemcmp(tls, bp+24, uintptr(unsafe.Pointer(&_aJournalMagic)), uint32(8)) != 0; !v9 {
		v8 = _sqlite3OsRead(tls, pJrnl, zSuper, int32(*(*Tu32)(unsafe.Pointer(bp))), *(*Ti64)(unsafe.Pointer(bp + 8))-int64(16)-int64(*(*Tu32)(unsafe.Pointer(bp))))
		rc = v8
	}
	if v9 || SQLITE_OK != v8 {
		return rc
	}
	/* See if the checksum matches the super-journal name */
	u = uint32(0)
	for {
		if !(u < *(*Tu32)(unsafe.Pointer(bp))) {
			break
		}
		*(*Tu32)(unsafe.Pointer(bp + 16)) -= uint32(*(*int8)(unsafe.Pointer(zSuper + uintptr(u))))
		goto _10
	_10:
		;
		u++
	}
	if *(*Tu32)(unsafe.Pointer(bp + 16)) != 0 {
		/* If the checksum doesn't add up, then one or more of the disk sectors
		 ** containing the super-journal filename is corrupted. This means
		 ** definitely roll back, so just return SQLITE_OK and report a (nul)
		 ** super-journal filename.
		 */
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
	}
	*(*int8)(unsafe.Pointer(zSuper + uintptr(*(*Tu32)(unsafe.Pointer(bp))))) = int8('\000')
	*(*int8)(unsafe.Pointer(zSuper + uintptr(*(*Tu32)(unsafe.Pointer(bp))+uint32(1)))) = int8('\000')
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the offset of the sector boundary at or immediately
//	** following the value in pPager->journalOff, assuming a sector
//	** size of pPager->sectorSize bytes.
//	**
//	** i.e for a sector size of 512:
//	**
//	**   Pager.journalOff          Return value
//	**   ---------------------------------------
//	**   0                         0
//	**   512                       512
//	**   100                       512
//	**   2000                      2048
//	**
//	*/
func _journalHdrOffset(tls *libc.TLS, pPager uintptr) (r Ti64) {
	var c, offset Ti64
	_, _ = c, offset
	offset = 0
	c = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
	if c != 0 {
		offset = ((c-int64(1))/int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize) + int64(1)) * int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize)
	}
	return offset
}

// C documentation
//
//	/*
//	** The journal file must be open when this function is called.
//	**
//	** This function is a no-op if the journal file has not been written to
//	** within the current transaction (i.e. if Pager.journalOff==0).
//	**
//	** If doTruncate is non-zero or the Pager.journalSizeLimit variable is
//	** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
//	** zero the 28-byte header at the start of the journal file. In either case,
//	** if the pager is not in no-sync mode, sync the journal file immediately
//	** after writing or truncating it.
//	**
//	** If Pager.journalSizeLimit is set to a positive, non-zero value, and
//	** following the truncation or zeroing described above the size of the
//	** journal file in bytes is larger than this value, then truncate the
//	** journal file to Pager.journalSizeLimit bytes. The journal file does
//	** not need to be synced following this operation.
//	**
//	** If an IO error occurs, abandon processing and return the IO error code.
//	** Otherwise, return SQLITE_OK.
//	*/
func _zeroJournalHdr(tls *libc.TLS, pPager uintptr, doTruncate int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iLimit Ti64
	var rc int32
	var _ /* sz at bp+0 */ Ti64
	_, _ = iLimit, rc
	rc = SQLITE_OK /* Return code */
	if (*TPager)(unsafe.Pointer(pPager)).FjournalOff != 0 {
		iLimit = (*TPager)(unsafe.Pointer(pPager)).FjournalSizeLimit /* Local cache of jsl */
		if doTruncate != 0 || iLimit == 0 {
			rc = _sqlite3OsTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, 0)
		} else {
			rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, uintptr(unsafe.Pointer(&_zeroHdr)), int32(28), 0)
		}
		if rc == SQLITE_OK && !((*TPager)(unsafe.Pointer(pPager)).FnoSync != 0) {
			rc = _sqlite3OsSync(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, int32(SQLITE_SYNC_DATAONLY)|int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags))
		}
		/* At this point the transaction is committed but the write lock
		 ** is still held on the file. If there is a size limit configured for
		 ** the persistent journal and the journal file currently consumes more
		 ** space than that limit allows for, truncate it now. There is no need
		 ** to sync the file following this operation.
		 */
		if rc == SQLITE_OK && iLimit > 0 {
			rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp)
			if rc == SQLITE_OK && *(*Ti64)(unsafe.Pointer(bp)) > iLimit {
				rc = _sqlite3OsTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iLimit)
			}
		}
	}
	return rc
}

var _zeroHdr = [28]int8{}

// C documentation
//
//	/*
//	** The journal file must be open when this routine is called. A journal
//	** header (JOURNAL_HDR_SZ bytes) is written into the journal file at the
//	** current location.
//	**
//	** The format for the journal header is as follows:
//	** - 8 bytes: Magic identifying journal format.
//	** - 4 bytes: Number of records in journal, or -1 no-sync mode is on.
//	** - 4 bytes: Random number used for page hash.
//	** - 4 bytes: Initial database page count.
//	** - 4 bytes: Sector size used by the process that wrote this journal.
//	** - 4 bytes: Database page size.
//	**
//	** Followed by (JOURNAL_HDR_SZ - 28) bytes of unused space.
//	*/
func _writeJournalHdr(tls *libc.TLS, pPager uintptr) (r int32) {
	var ii, rc int32
	var nHeader, nWrite Tu32
	var zHeader uintptr
	var v2 Ti64
	_, _, _, _, _, _ = ii, nHeader, nWrite, rc, zHeader, v2
	rc = SQLITE_OK                                                /* Return code */
	zHeader = (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace        /* Temporary space used to build header */
	nHeader = uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize) /* Loop counter */
	/* Journal file must be open. */
	if nHeader > (*TPager)(unsafe.Pointer(pPager)).FsectorSize {
		nHeader = (*TPager)(unsafe.Pointer(pPager)).FsectorSize
	}
	/* If there are active savepoints and any of them were created
	 ** since the most recent journal header was written, update the
	 ** PagerSavepoint.iHdrOffset fields now.
	 */
	ii = 0
	for {
		if !(ii < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
			break
		}
		if (*(*TPagerSavepoint)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*48))).FiHdrOffset == 0 {
			(*(*TPagerSavepoint)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*48))).FiHdrOffset = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
		}
		goto _1
	_1:
		;
		ii++
	}
	v2 = _journalHdrOffset(tls, pPager)
	(*TPager)(unsafe.Pointer(pPager)).FjournalOff = v2
	(*TPager)(unsafe.Pointer(pPager)).FjournalHdr = v2
	/*
	 ** Write the nRec Field - the number of page records that follow this
	 ** journal header. Normally, zero is written to this value at this time.
	 ** After the records are added to the journal (and the journal synced,
	 ** if in full-sync mode), the zero is overwritten with the true number
	 ** of records (see syncJournal()).
	 **
	 ** A faster alternative is to write 0xFFFFFFFF to the nRec field. When
	 ** reading the journal this value tells SQLite to assume that the
	 ** rest of the journal file contains valid page records. This assumption
	 ** is dangerous, as if a failure occurred whilst writing to the journal
	 ** file it may contain some garbage data. There are two scenarios
	 ** where this risk can be ignored:
	 **
	 **   * When the pager is in no-sync mode. Corruption can follow a
	 **     power failure in this case anyway.
	 **
	 **   * When the SQLITE_IOCAP_SAFE_APPEND flag is set. This guarantees
	 **     that garbage data is never appended to the journal file.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FnoSync != 0 || int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_MEMORY) || _sqlite3OsDeviceCharacteristics(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd)&int32(SQLITE_IOCAP_SAFE_APPEND) != 0 {
		libc.Xmemcpy(tls, zHeader, uintptr(unsafe.Pointer(&_aJournalMagic)), uint32(8))
		_sqlite3Put4byte(tls, zHeader+uintptr(8), uint32(0xffffffff))
	} else {
		libc.Xmemset(tls, zHeader, 0, libc.Uint32FromInt64(8)+libc.Uint32FromInt32(4))
	}
	/* The random check-hash initializer */
	if int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) != int32(PAGER_JOURNALMODE_MEMORY) {
		Xsqlite3_randomness(tls, int32(4), pPager+52)
	}
	_sqlite3Put4byte(tls, zHeader+uintptr(libc.Uint32FromInt64(8)+libc.Uint32FromInt32(4)), (*TPager)(unsafe.Pointer(pPager)).FcksumInit)
	/* The initial database size */
	_sqlite3Put4byte(tls, zHeader+uintptr(libc.Uint32FromInt64(8)+libc.Uint32FromInt32(8)), (*TPager)(unsafe.Pointer(pPager)).FdbOrigSize)
	/* The assumed sector size for this process */
	_sqlite3Put4byte(tls, zHeader+uintptr(libc.Uint32FromInt64(8)+libc.Uint32FromInt32(12)), (*TPager)(unsafe.Pointer(pPager)).FsectorSize)
	/* The page size */
	_sqlite3Put4byte(tls, zHeader+uintptr(libc.Uint32FromInt64(8)+libc.Uint32FromInt32(16)), uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize))
	/* Initializing the tail of the buffer is not necessary.  Everything
	 ** works find if the following memset() is omitted.  But initializing
	 ** the memory prevents valgrind from complaining, so we are willing to
	 ** take the performance hit.
	 */
	libc.Xmemset(tls, zHeader+uintptr(libc.Uint32FromInt64(8)+libc.Uint32FromInt32(20)), 0, nHeader-(libc.Uint32FromInt64(8)+libc.Uint32FromInt32(20)))
	/* In theory, it is only necessary to write the 28 bytes that the
	 ** journal header consumes to the journal file here. Then increment the
	 ** Pager.journalOff variable by JOURNAL_HDR_SZ so that the next
	 ** record is written to the following sector (leaving a gap in the file
	 ** that will be implicitly filled in by the OS).
	 **
	 ** However it has been discovered that on some systems this pattern can
	 ** be significantly slower than contiguously writing data to the file,
	 ** even if that means explicitly writing data to the block of
	 ** (JOURNAL_HDR_SZ - 28) bytes that will not be used. So that is what
	 ** is done.
	 **
	 ** The loop is required here in case the sector-size is larger than the
	 ** database page size. Since the zHeader buffer is only Pager.pageSize
	 ** bytes in size, more than one call to sqlite3OsWrite() may be required
	 ** to populate the entire journal header sector.
	 */
	nWrite = uint32(0)
	for {
		if !(rc == SQLITE_OK && nWrite < (*TPager)(unsafe.Pointer(pPager)).FsectorSize) {
			break
		}
		rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, zHeader, int32(int32(nHeader)), (*TPager)(unsafe.Pointer(pPager)).FjournalOff)
		*(*Ti64)(unsafe.Pointer(pPager + 80)) += int64(int64(nHeader))
		goto _3
	_3:
		;
		nWrite += nHeader
	}
	return rc
}

// C documentation
//
//	/*
//	** The journal file must be open when this is called. A journal header file
//	** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
//	** file. The current location in the journal file is given by
//	** pPager->journalOff. See comments above function writeJournalHdr() for
//	** a description of the journal header format.
//	**
//	** If the header is read successfully, *pNRec is set to the number of
//	** page records following this header and *pDbSize is set to the size of the
//	** database before the transaction began, in pages. Also, pPager->cksumInit
//	** is set to the value read from the journal header. SQLITE_OK is returned
//	** in this case.
//	**
//	** If the journal header file appears to be corrupted, SQLITE_DONE is
//	** returned and *pNRec and *PDbSize are undefined.  If JOURNAL_HDR_SZ bytes
//	** cannot be read from the journal file an error code is returned.
//	*/
func _readJournalHdr(tls *libc.TLS, pPager uintptr, isHot int32, journalSize Ti64, pNRec uintptr, pDbSize uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iHdrOff Ti64
	var rc, v1, v2, v4, v6, v7 int32
	var v3, v5, v8 bool
	var _ /* aMagic at bp+0 */ [8]uint8
	var _ /* iPageSize at bp+8 */ Tu32
	var _ /* iSectorSize at bp+12 */ Tu32
	_, _, _, _, _, _, _, _, _, _ = iHdrOff, rc, v1, v2, v3, v4, v5, v6, v7, v8 /* Offset of journal header being read */
	/* Journal file must be open. */
	/* Advance Pager.journalOff to the start of the next sector. If the
	 ** journal file is too small for there to be a header stored at this
	 ** point, return SQLITE_DONE.
	 */
	(*TPager)(unsafe.Pointer(pPager)).FjournalOff = _journalHdrOffset(tls, pPager)
	if (*TPager)(unsafe.Pointer(pPager)).FjournalOff+int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize) > journalSize {
		return int32(SQLITE_DONE)
	}
	iHdrOff = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
	/* Read in the first 8 bytes of the journal header. If they do not match
	 ** the  magic string found at the start of each journal header, return
	 ** SQLITE_DONE. If an IO error occurs, return an error code. Otherwise,
	 ** proceed.
	 */
	if isHot != 0 || iHdrOff != (*TPager)(unsafe.Pointer(pPager)).FjournalHdr {
		rc = _sqlite3OsRead(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp, int32(8), iHdrOff)
		if rc != 0 {
			return rc
		}
		if libc.Xmemcmp(tls, bp, uintptr(unsafe.Pointer(&_aJournalMagic)), uint32(8)) != 0 {
			return int32(SQLITE_DONE)
		}
	}
	/* Read the first three 32-bit fields of the journal header: The nRec
	 ** field, the checksum-initializer and the database size at the start
	 ** of the transaction. Return an error code if anything goes wrong.
	 */
	v1 = _read32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(8), pNRec)
	rc = v1
	if v3 = SQLITE_OK != v1; !v3 {
		v2 = _read32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(12), pPager+52)
		rc = v2
	}
	if v5 = v3 || SQLITE_OK != v2; !v5 {
		v4 = _read32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(16), pDbSize)
		rc = v4
	}
	if v5 || SQLITE_OK != v4 {
		return rc
	}
	if (*TPager)(unsafe.Pointer(pPager)).FjournalOff == 0 { /* Sector-size field of journal header */
		/* Read the page-size and sector-size journal header fields. */
		v6 = _read32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(20), bp+12)
		rc = v6
		if v8 = SQLITE_OK != v6; !v8 {
			v7 = _read32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(24), bp+8)
			rc = v7
		}
		if v8 || SQLITE_OK != v7 {
			return rc
		}
		/* Versions of SQLite prior to 3.5.8 set the page-size field of the
		 ** journal header to zero. In this case, assume that the Pager.pageSize
		 ** variable is already set to the correct page size.
		 */
		if *(*Tu32)(unsafe.Pointer(bp + 8)) == uint32(0) {
			*(*Tu32)(unsafe.Pointer(bp + 8)) = uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize)
		}
		/* Check that the values read from the page-size and sector-size fields
		 ** are within range. To be 'in range', both values need to be a power
		 ** of two greater than or equal to 512 or 32, and not greater than their
		 ** respective compile time maximum limits.
		 */
		if *(*Tu32)(unsafe.Pointer(bp + 8)) < uint32(512) || *(*Tu32)(unsafe.Pointer(bp + 12)) < uint32(32) || *(*Tu32)(unsafe.Pointer(bp + 8)) > uint32(SQLITE_MAX_PAGE_SIZE) || *(*Tu32)(unsafe.Pointer(bp + 12)) > uint32(MAX_SECTOR_SIZE) || (*(*Tu32)(unsafe.Pointer(bp + 8))-uint32(1))&*(*Tu32)(unsafe.Pointer(bp + 8)) != uint32(0) || (*(*Tu32)(unsafe.Pointer(bp + 12))-uint32(1))&*(*Tu32)(unsafe.Pointer(bp + 12)) != uint32(0) {
			/* If the either the page-size or sector-size in the journal-header is
			 ** invalid, then the process that wrote the journal-header must have
			 ** crashed before the header was synced. In this case stop reading
			 ** the journal file here.
			 */
			return int32(SQLITE_DONE)
		}
		/* Update the page-size to match the value read from the journal.
		 ** Use a testcase() macro to make sure that malloc failure within
		 ** PagerSetPagesize() is tested.
		 */
		rc = _sqlite3PagerSetPagesize(tls, pPager, bp+8, -int32(1))
		/* Update the assumed sector-size to match the value used by
		 ** the process that created this journal. If this journal was
		 ** created by a process other than this one, then this routine
		 ** is being called from within pager_playback(). The local value
		 ** of Pager.sectorSize is restored at the end of that routine.
		 */
		(*TPager)(unsafe.Pointer(pPager)).FsectorSize = *(*Tu32)(unsafe.Pointer(bp + 12))
	}
	*(*Ti64)(unsafe.Pointer(pPager + 80)) += int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize)
	return rc
}

// C documentation
//
//	/*
//	** Write the supplied super-journal name into the journal file for pager
//	** pPager at the current location. The super-journal name must be the last
//	** thing written to a journal file. If the pager is in full-sync mode, the
//	** journal file descriptor is advanced to the next sector boundary before
//	** anything is written. The format is:
//	**
//	**   + 4 bytes: PAGER_SJ_PGNO.
//	**   + N bytes: super-journal filename in utf-8.
//	**   + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
//	**   + 4 bytes: super-journal name checksum.
//	**   + 8 bytes: aJournalMagic[].
//	**
//	** The super-journal page checksum is the sum of the bytes in the super-journal
//	** name, where each byte is interpreted as a signed 8-bit integer.
//	**
//	** If zSuper is a NULL pointer (occurs for a single database transaction),
//	** this call is a no-op.
//	*/
func _writeSuperJournal(tls *libc.TLS, pPager uintptr, zSuper uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var cksum Tu32
	var iHdrOff Ti64
	var nSuper, rc, v11, v2, v3, v5, v7, v9 int32
	var v10, v4, v6, v8 bool
	var _ /* jrnlSize at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = cksum, iHdrOff, nSuper, rc, v10, v11, v2, v3, v4, v5, v6, v7, v8, v9 /* Size of journal file on disk */
	cksum = uint32(0)                                                                                               /* Checksum of string zSuper */
	if !(zSuper != 0) || int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_MEMORY) || !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != libc.UintptrFromInt32(0)) {
		return SQLITE_OK
	}
	(*TPager)(unsafe.Pointer(pPager)).FsetSuper = uint8(1)
	/* Calculate the length in bytes and the checksum of zSuper */
	nSuper = 0
	for {
		if !(*(*int8)(unsafe.Pointer(zSuper + uintptr(nSuper))) != 0) {
			break
		}
		cksum += uint32(*(*int8)(unsafe.Pointer(zSuper + uintptr(nSuper))))
		goto _1
	_1:
		;
		nSuper++
	}
	/* If in full-sync mode, advance to the next disk sector before writing
	 ** the super-journal name. This is in case the previous page written to
	 ** the journal has already been synced.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FfullSync != 0 {
		(*TPager)(unsafe.Pointer(pPager)).FjournalOff = _journalHdrOffset(tls, pPager)
	}
	iHdrOff = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
	/* Write the super-journal data to the end of the journal file. If
	 ** an error occurs, return the error code to the caller.
	 */
	v2 = _write32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff, (*TPager)(unsafe.Pointer(pPager)).FlckPgno)
	rc = v2
	if v4 = 0 != v2; !v4 {
		v3 = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, zSuper, nSuper, iHdrOff+int64(4))
		rc = v3
	}
	if v6 = v4 || 0 != v3; !v6 {
		v5 = _write32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(4)+int64(int64(nSuper)), uint32(uint32(nSuper)))
		rc = v5
	}
	if v8 = v6 || 0 != v5; !v8 {
		v7 = _write32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(4)+int64(int64(nSuper))+int64(4), cksum)
		rc = v7
	}
	if v10 = v8 || 0 != v7; !v10 {
		v9 = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, uintptr(unsafe.Pointer(&_aJournalMagic)), int32(8), iHdrOff+int64(4)+int64(int64(nSuper))+int64(8))
		rc = v9
	}
	if v10 || 0 != v9 {
		return rc
	}
	*(*Ti64)(unsafe.Pointer(pPager + 80)) += int64(nSuper + libc.Int32FromInt32(20))
	/* If the pager is in persistent-journal mode, then the physical
	 ** journal-file may extend past the end of the super-journal name
	 ** and 8 bytes of magic data just written to the file. This is
	 ** dangerous because the code to rollback a hot-journal file
	 ** will not be able to find the super-journal name to determine
	 ** whether or not the journal is hot.
	 **
	 ** Easiest thing to do in this scenario is to truncate the journal
	 ** file to the required size.
	 */
	v11 = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp)
	rc = v11
	if SQLITE_OK == v11 && *(*Ti64)(unsafe.Pointer(bp)) > (*TPager)(unsafe.Pointer(pPager)).FjournalOff {
		rc = _sqlite3OsTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, (*TPager)(unsafe.Pointer(pPager)).FjournalOff)
	}
	return rc
}

// C documentation
//
//	/*
//	** Discard the entire contents of the in-memory page-cache.
//	*/
func _pager_reset(tls *libc.TLS, pPager uintptr) {
	(*TPager)(unsafe.Pointer(pPager)).FiDataVersion++
	_sqlite3BackupRestart(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup)
	_sqlite3PcacheClear(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
}

// C documentation
//
//	/*
//	** Return the pPager->iDataVersion value
//	*/
func _sqlite3PagerDataVersion(tls *libc.TLS, pPager uintptr) (r Tu32) {
	return (*TPager)(unsafe.Pointer(pPager)).FiDataVersion
}

// C documentation
//
//	/*
//	** Free all structures in the Pager.aSavepoint[] array and set both
//	** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
//	** if it is open and the pager is not in exclusive mode.
//	*/
func _releaseAllSavepoints(tls *libc.TLS, pPager uintptr) {
	var ii int32
	_ = ii /* Iterator for looping through Pager.aSavepoint */
	ii = 0
	for {
		if !(ii < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
			break
		}
		_sqlite3BitvecDestroy(tls, (*(*TPagerSavepoint)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*48))).FpInSavepoint)
		goto _1
	_1:
		;
		ii++
	}
	if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) || _sqlite3JournalIsInMemory(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd) != 0 {
		_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd)
	}
	Xsqlite3_free(tls, (*TPager)(unsafe.Pointer(pPager)).FaSavepoint)
	(*TPager)(unsafe.Pointer(pPager)).FaSavepoint = uintptr(0)
	(*TPager)(unsafe.Pointer(pPager)).FnSavepoint = 0
	(*TPager)(unsafe.Pointer(pPager)).FnSubRec = uint32(0)
}

// C documentation
//
//	/*
//	** Set the bit number pgno in the PagerSavepoint.pInSavepoint
//	** bitvecs of all open savepoints. Return SQLITE_OK if successful
//	** or SQLITE_NOMEM if a malloc failure occurs.
//	*/
func _addToSavepointBitvecs(tls *libc.TLS, pPager uintptr, pgno TPgno) (r int32) {
	var ii, rc int32
	var p uintptr
	_, _, _ = ii, p, rc /* Loop counter */
	rc = SQLITE_OK      /* Result code */
	ii = 0
	for {
		if !(ii < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
			break
		}
		p = (*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*48
		if pgno <= (*TPagerSavepoint)(unsafe.Pointer(p)).FnOrig {
			rc |= _sqlite3BitvecSet(tls, (*TPagerSavepoint)(unsafe.Pointer(p)).FpInSavepoint, pgno)
		}
		goto _1
	_1:
		;
		ii++
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is a no-op if the pager is in exclusive mode and not
//	** in the ERROR state. Otherwise, it switches the pager to PAGER_OPEN
//	** state.
//	**
//	** If the pager is not in exclusive-access mode, the database file is
//	** completely unlocked. If the file is unlocked and the file-system does
//	** not exhibit the UNDELETABLE_WHEN_OPEN property, the journal file is
//	** closed (if it is open).
//	**
//	** If the pager is in ERROR state when this function is called, the
//	** contents of the pager cache are discarded before switching back to
//	** the OPEN state. Regardless of whether the pager is in exclusive-mode
//	** or not, any journal file left in the file-system will be treated
//	** as a hot-journal and rolled back the next time a read-transaction
//	** is opened (by this or by any other connection).
//	*/
func _pager_unlock(tls *libc.TLS, pPager uintptr) {
	var iDc, rc, v1, v2 int32
	_, _, _, _ = iDc, rc, v1, v2
	_sqlite3BitvecDestroy(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal)
	(*TPager)(unsafe.Pointer(pPager)).FpInJournal = uintptr(0)
	_releaseAllSavepoints(tls, pPager)
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		_sqlite3WalEndReadTransaction(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
		(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_OPEN)
	} else {
		if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) {
			if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
				v1 = _sqlite3OsDeviceCharacteristics(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd)
			} else {
				v1 = 0
			} /* Error code returned by pagerUnlockDb() */
			iDc = v1
			/* If the operating system support deletion of open files, then
			 ** close the journal file when dropping the database lock.  Otherwise
			 ** another connection with journal_mode=delete might delete the file
			 ** out from under us.
			 */
			if 0 == iDc&int32(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN) || int32(1) != int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode)&int32(5) {
				_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
			}
			/* If the pager is in the ERROR state and the call to unlock the database
			 ** file fails, set the current lock to UNKNOWN_LOCK. See the comment
			 ** above the #define for UNKNOWN_LOCK for an explanation of why this
			 ** is necessary.
			 */
			rc = _pagerUnlockDb(tls, pPager, NO_LOCK)
			if rc != SQLITE_OK && int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_ERROR) {
				(*TPager)(unsafe.Pointer(pPager)).FeLock = uint8(libc.Int32FromInt32(EXCLUSIVE_LOCK) + libc.Int32FromInt32(1))
			}
			/* The pager state may be changed from PAGER_ERROR to PAGER_OPEN here
			 ** without clearing the error code. This is intentional - the error
			 ** code is cleared and the cache reset in the block below.
			 */
			(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_OPEN)
		}
	}
	/* If Pager.errCode is set, the contents of the pager cache cannot be
	 ** trusted. Now that there are no outstanding references to the pager,
	 ** it can safely move back to PAGER_OPEN state. This happens in both
	 ** normal and exclusive-locking mode.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		if int32((*TPager)(unsafe.Pointer(pPager)).FtempFile) == 0 {
			_pager_reset(tls, pPager)
			(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = uint8(0)
			(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_OPEN)
		} else {
			if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
				v2 = PAGER_OPEN
			} else {
				v2 = int32(PAGER_READER)
			}
			(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(v2)
		}
		if (*TPager)(unsafe.Pointer(pPager)).FbUseFetch != 0 {
			_sqlite3OsUnfetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, 0, uintptr(0))
		}
		(*TPager)(unsafe.Pointer(pPager)).FerrCode = SQLITE_OK
		_setGetterMethod(tls, pPager)
	}
	(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
	(*TPager)(unsafe.Pointer(pPager)).FjournalHdr = 0
	(*TPager)(unsafe.Pointer(pPager)).FsetSuper = uint8(0)
}

// C documentation
//
//	/*
//	** This function is called whenever an IOERR or FULL error that requires
//	** the pager to transition into the ERROR state may have occurred.
//	** The first argument is a pointer to the pager structure, the second
//	** the error-code about to be returned by a pager API function. The
//	** value returned is a copy of the second argument to this function.
//	**
//	** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the
//	** IOERR sub-codes, the pager enters the ERROR state and the error code
//	** is stored in Pager.errCode. While the pager remains in the ERROR state,
//	** all major API calls on the Pager will immediately return Pager.errCode.
//	**
//	** The ERROR state indicates that the contents of the pager-cache
//	** cannot be trusted. This state can be cleared by completely discarding
//	** the contents of the pager-cache. If a transaction was active when
//	** the persistent error occurred, then the rollback journal may need
//	** to be replayed to restore the contents of the database file (as if
//	** it were a hot-journal).
//	*/
func _pager_error(tls *libc.TLS, pPager uintptr, rc int32) (r int32) {
	var rc2 int32
	_ = rc2
	rc2 = rc & int32(0xff)
	if rc2 == int32(SQLITE_FULL) || rc2 == int32(SQLITE_IOERR) {
		(*TPager)(unsafe.Pointer(pPager)).FerrCode = rc
		(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_ERROR)
		_setGetterMethod(tls, pPager)
	}
	return rc
}

// C documentation
//
//	/*
//	** The write transaction open on pPager is being committed (bCommit==1)
//	** or rolled back (bCommit==0).
//	**
//	** Return TRUE if and only if all dirty pages should be flushed to disk.
//	**
//	** Rules:
//	**
//	**   *  For non-TEMP databases, always sync to disk.  This is necessary
//	**      for transactions to be durable.
//	**
//	**   *  Sync TEMP database only on a COMMIT (not a ROLLBACK) when the backing
//	**      file has been created already (via a spill on pagerStress()) and
//	**      when the number of dirty pages in memory exceeds 25% of the total
//	**      cache size.
//	*/
func _pagerFlushOnCommit(tls *libc.TLS, pPager uintptr, bCommit int32) (r int32) {
	if int32((*TPager)(unsafe.Pointer(pPager)).FtempFile) == 0 {
		return int32(1)
	}
	if !(bCommit != 0) {
		return 0
	}
	if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != libc.UintptrFromInt32(0)) {
		return 0
	}
	return libc.BoolInt32(_sqlite3PCachePercentDirty(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache) >= int32(25))
}

// C documentation
//
//	/*
//	** This routine ends a transaction. A transaction is usually ended by
//	** either a COMMIT or a ROLLBACK operation. This routine may be called
//	** after rollback of a hot-journal, or if an error occurs while opening
//	** the journal file or writing the very first journal-header of a
//	** database transaction.
//	**
//	** This routine is never called in PAGER_ERROR state. If it is called
//	** in PAGER_NONE or PAGER_SHARED state and the lock held is less
//	** exclusive than a RESERVED lock, it is a no-op.
//	**
//	** Otherwise, any active savepoints are released.
//	**
//	** If the journal file is open, then it is "finalized". Once a journal
//	** file has been finalized it is not possible to use it to roll back a
//	** transaction. Nor will it be considered to be a hot-journal by this
//	** or any other database connection. Exactly how a journal is finalized
//	** depends on whether or not the pager is running in exclusive mode and
//	** the current journal-mode (Pager.journalMode value), as follows:
//	**
//	**   journalMode==MEMORY
//	**     Journal file descriptor is simply closed. This destroys an
//	**     in-memory journal.
//	**
//	**   journalMode==TRUNCATE
//	**     Journal file is truncated to zero bytes in size.
//	**
//	**   journalMode==PERSIST
//	**     The first 28 bytes of the journal file are zeroed. This invalidates
//	**     the first journal header in the file, and hence the entire journal
//	**     file. An invalid journal file cannot be rolled back.
//	**
//	**   journalMode==DELETE
//	**     The journal file is closed and deleted using sqlite3OsDelete().
//	**
//	**     If the pager is running in exclusive mode, this method of finalizing
//	**     the journal file is never used. Instead, if the journalMode is
//	**     DELETE and the pager is in exclusive mode, the method described under
//	**     journalMode==PERSIST is used instead.
//	**
//	** After the journal is finalized, the pager moves to PAGER_READER state.
//	** If running in non-exclusive rollback mode, the lock on the file is
//	** downgraded to a SHARED_LOCK.
//	**
//	** SQLITE_OK is returned if no error occurs. If an error occurs during
//	** any of the IO operations to finalize the journal file or unlock the
//	** database then the IO error code is returned to the user. If the
//	** operation to finalize the journal file fails, then the code still
//	** tries to unlock the database file if not in exclusive mode. If the
//	** unlock operation fails as well, then the first error code related
//	** to the first error encountered (the journal finalization one) is
//	** returned.
//	*/
func _pager_end_transaction(tls *libc.TLS, pPager uintptr, hasSuper int32, bCommit int32) (r int32) {
	var bDelete, rc, rc2, v1 int32
	_, _, _, _ = bDelete, rc, rc2, v1
	rc = SQLITE_OK  /* Error code from journal finalization operation */
	rc2 = SQLITE_OK /* Error code from db file unlock operation */
	/* Do nothing if the pager does not have an open write transaction
	 ** or at least a RESERVED lock. This function may be called when there
	 ** is no write-transaction active but a RESERVED or greater lock is
	 ** held under two circumstances:
	 **
	 **   1. After a successful hot-journal rollback, it is called with
	 **      eState==PAGER_NONE and eLock==EXCLUSIVE_LOCK.
	 **
	 **   2. If a connection with locking_mode=exclusive holding an EXCLUSIVE
	 **      lock switches back to locking_mode=normal and then executes a
	 **      read-transaction, this function is called with eState==PAGER_READER
	 **      and eLock==EXCLUSIVE_LOCK when the read-transaction is closed.
	 */
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) < int32(PAGER_WRITER_LOCKED) && int32((*TPager)(unsafe.Pointer(pPager)).FeLock) < int32(RESERVED_LOCK) {
		return SQLITE_OK
	}
	_releaseAllSavepoints(tls, pPager)
	if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
		/* Finalize the journal file. */
		if _sqlite3JournalIsInMemory(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd) != 0 {
			/* assert( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ); */
			_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
		} else {
			if int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_TRUNCATE) {
				if (*TPager)(unsafe.Pointer(pPager)).FjournalOff == 0 {
					rc = SQLITE_OK
				} else {
					rc = _sqlite3OsTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, 0)
					if rc == SQLITE_OK && (*TPager)(unsafe.Pointer(pPager)).FfullSync != 0 {
						/* Make sure the new file size is written into the inode right away.
						 ** Otherwise the journal might resurrect following a power loss and
						 ** cause the last transaction to roll back.  See
						 ** https://bugzilla.mozilla.org/show_bug.cgi?id=1072773
						 */
						rc = _sqlite3OsSync(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags))
					}
				}
				(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
			} else {
				if int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_PERSIST) || (*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 && int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) != int32(PAGER_JOURNALMODE_WAL) {
					rc = _zeroJournalHdr(tls, pPager, libc.BoolInt32(hasSuper != 0 || (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0))
					(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
				} else {
					/* This branch may be executed with Pager.journalMode==MEMORY if
					 ** a hot-journal was just rolled back. In this case the journal
					 ** file should be closed and deleted. If this connection writes to
					 ** the database file, it will do so using an in-memory journal.
					 */
					bDelete = libc.BoolInt32(!((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0))
					_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
					if bDelete != 0 {
						rc = _sqlite3OsDelete(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, int32((*TPager)(unsafe.Pointer(pPager)).FextraSync))
					}
				}
			}
		}
	}
	_sqlite3BitvecDestroy(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal)
	(*TPager)(unsafe.Pointer(pPager)).FpInJournal = uintptr(0)
	(*TPager)(unsafe.Pointer(pPager)).FnRec = 0
	if rc == SQLITE_OK {
		if (*TPager)(unsafe.Pointer(pPager)).FmemDb != 0 || _pagerFlushOnCommit(tls, pPager, bCommit) != 0 {
			_sqlite3PcacheCleanAll(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
		} else {
			_sqlite3PcacheClearWritable(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
		}
		_sqlite3PcacheTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, (*TPager)(unsafe.Pointer(pPager)).FdbSize)
	}
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		/* Drop the WAL write-lock, if any. Also, if the connection was in
		 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
		 ** lock held on the database file.
		 */
		rc2 = _sqlite3WalEndWriteTransaction(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
	} else {
		if rc == SQLITE_OK && bCommit != 0 && (*TPager)(unsafe.Pointer(pPager)).FdbFileSize > (*TPager)(unsafe.Pointer(pPager)).FdbSize {
			/* This branch is taken when committing a transaction in rollback-journal
			 ** mode if the database file on disk is larger than the database image.
			 ** At this point the journal has been finalized and the transaction
			 ** successfully committed, but the EXCLUSIVE lock is still held on the
			 ** file. So it is safe to truncate the database file to its minimum
			 ** required size.  */
			rc = _pager_truncate(tls, pPager, (*TPager)(unsafe.Pointer(pPager)).FdbSize)
		}
	}
	if rc == SQLITE_OK && bCommit != 0 {
		rc = _sqlite3OsFileControl(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_COMMIT_PHASETWO), uintptr(0))
		if rc == int32(SQLITE_NOTFOUND) {
			rc = SQLITE_OK
		}
	}
	if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) && (!((*TPager)(unsafe.Pointer(pPager)).FpWal != libc.UintptrFromInt32(0)) || _sqlite3WalExclusiveMode(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, 0) != 0) {
		rc2 = _pagerUnlockDb(tls, pPager, int32(SHARED_LOCK))
	}
	(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_READER)
	(*TPager)(unsafe.Pointer(pPager)).FsetSuper = uint8(0)
	if rc == SQLITE_OK {
		v1 = rc2
	} else {
		v1 = rc
	}
	return v1
}

// C documentation
//
//	/*
//	** Execute a rollback if a transaction is active and unlock the
//	** database file.
//	**
//	** If the pager has already entered the ERROR state, do not attempt
//	** the rollback at this time. Instead, pager_unlock() is called. The
//	** call to pager_unlock() will discard all in-memory pages, unlock
//	** the database file and move the pager back to OPEN state. If this
//	** means that there is a hot-journal left in the file-system, the next
//	** connection to obtain a shared lock on the pager (which may be this one)
//	** will roll it back.
//	**
//	** If the pager has not already entered the ERROR state, but an IO or
//	** malloc error occurs during a rollback, then this will itself cause
//	** the pager to enter the ERROR state. Which will be cleared by the
//	** call to pager_unlock(), as described above.
//	*/
func _pagerUnlockAndRollback(tls *libc.TLS, pPager uintptr) {
	var eLock Tu8
	var errCode int32
	_, _ = eLock, errCode
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) != int32(PAGER_ERROR) && int32((*TPager)(unsafe.Pointer(pPager)).FeState) != PAGER_OPEN {
		if int32((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_LOCKED) {
			_sqlite3BeginBenignMalloc(tls)
			_sqlite3PagerRollback(tls, pPager)
			_sqlite3EndBenignMalloc(tls)
		} else {
			if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) {
				_pager_end_transaction(tls, pPager, 0, 0)
			}
		}
	} else {
		if int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_ERROR) && int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_MEMORY) && (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
			/* Special case for a ROLLBACK due to I/O error with an in-memory
			 ** journal:  We have to rollback immediately, before the journal is
			 ** closed, because once it is closed, all content is forgotten. */
			errCode = (*TPager)(unsafe.Pointer(pPager)).FerrCode
			eLock = (*TPager)(unsafe.Pointer(pPager)).FeLock
			(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_OPEN)
			(*TPager)(unsafe.Pointer(pPager)).FerrCode = SQLITE_OK
			(*TPager)(unsafe.Pointer(pPager)).FeLock = uint8(EXCLUSIVE_LOCK)
			_pager_playback(tls, pPager, int32(1))
			(*TPager)(unsafe.Pointer(pPager)).FerrCode = errCode
			(*TPager)(unsafe.Pointer(pPager)).FeLock = eLock
		}
	}
	_pager_unlock(tls, pPager)
}

// C documentation
//
//	/*
//	** Parameter aData must point to a buffer of pPager->pageSize bytes
//	** of data. Compute and return a checksum based on the contents of the
//	** page of data and the current value of pPager->cksumInit.
//	**
//	** This is not a real checksum. It is really just the sum of the
//	** random initial value (pPager->cksumInit) and every 200th byte
//	** of the page data, starting with byte offset (pPager->pageSize%200).
//	** Each byte is interpreted as an 8-bit unsigned integer.
//	**
//	** Changing the formula used to compute this checksum results in an
//	** incompatible journal file format.
//	**
//	** If journal corruption occurs due to a power failure, the most likely
//	** scenario is that one end or the other of the record will be changed.
//	** It is much less likely that the two ends of the journal record will be
//	** correct and the middle be corrupt.  Thus, this "checksum" scheme,
//	** though fast and simple, catches the mostly likely kind of corruption.
//	*/
func _pager_cksum(tls *libc.TLS, pPager uintptr, aData uintptr) (r Tu32) {
	var cksum Tu32
	var i int32
	_, _ = cksum, i
	cksum = (*TPager)(unsafe.Pointer(pPager)).FcksumInit                /* Checksum value to return */
	i = int32((*TPager)(unsafe.Pointer(pPager)).FpageSize - int64(200)) /* Loop counter */
	for i > 0 {
		cksum += uint32(*(*Tu8)(unsafe.Pointer(aData + uintptr(i))))
		i -= int32(200)
	}
	return cksum
}

// C documentation
//
//	/*
//	** Read a single page from either the journal file (if isMainJrnl==1) or
//	** from the sub-journal (if isMainJrnl==0) and playback that page.
//	** The page begins at offset *pOffset into the file. The *pOffset
//	** value is increased to the start of the next page in the journal.
//	**
//	** The main rollback journal uses checksums - the statement journal does
//	** not.
//	**
//	** If the page number of the page record read from the (sub-)journal file
//	** is greater than the current value of Pager.dbSize, then playback is
//	** skipped and SQLITE_OK is returned.
//	**
//	** If pDone is not NULL, then it is a record of pages that have already
//	** been played back.  If the page at *pOffset has already been played back
//	** (if the corresponding pDone bit is set) then skip the playback.
//	** Make sure the pDone bit corresponding to the *pOffset page is set
//	** prior to returning.
//	**
//	** If the page record is successfully read from the (sub-)journal file
//	** and played back, then SQLITE_OK is returned. If an IO error occurs
//	** while reading the record from the (sub-)journal file or while writing
//	** to the database file, then the IO error code is returned. If data
//	** is successfully read from the (sub-)journal file but appears to be
//	** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
//	** two circumstances:
//	**
//	**   * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or
//	**   * If the record is being rolled back from the main journal file
//	**     and the checksum field does not match the record content.
//	**
//	** Neither of these two scenarios are possible during a savepoint rollback.
//	**
//	** If this is a savepoint rollback, then memory may have to be dynamically
//	** allocated by this function. If this is the case and an allocation fails,
//	** SQLITE_NOMEM is returned.
//	*/
func _pager_playback_one_page(tls *libc.TLS, pPager uintptr, pOffset uintptr, pDone uintptr, isMainJrnl int32, isSavepnt int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aData, jfd, pData, v1, p4, p5 uintptr
	var isSynced, rc, v2 int32
	var ofst Ti64
	var v3 bool
	var _ /* cksum at bp+8 */ Tu32
	var _ /* pPg at bp+0 */ uintptr
	var _ /* pgno at bp+4 */ TPgno
	_, _, _, _, _, _, _, _, _, _, _ = aData, isSynced, jfd, ofst, pData, rc, v1, v2, v3, p4, p5 /* True if journal page is synced */
	/* isMainJrnl is 0 or 1 */
	/* isSavepnt is 0 or 1 */
	/* pDone always used on sub-journals */
	/* pDone never used on non-savepoint */
	aData = (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace
	/* Temp storage must have already been allocated */
	/* Either the state is greater than PAGER_WRITER_CACHEMOD (a transaction
	 ** or savepoint rollback done at the request of the caller) or this is
	 ** a hot-journal rollback. If it is a hot-journal rollback, the pager
	 ** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
	 ** only reads from the main journal, not the sub-journal.
	 */
	/* Read the page number and page data from the journal or sub-journal
	 ** file. Return an error code to the caller if an IO error occurs.
	 */
	if isMainJrnl != 0 {
		v1 = (*TPager)(unsafe.Pointer(pPager)).Fjfd
	} else {
		v1 = (*TPager)(unsafe.Pointer(pPager)).Fsjfd
	}
	jfd = v1
	rc = _read32bits(tls, jfd, *(*Ti64)(unsafe.Pointer(pOffset)), bp+4)
	if rc != SQLITE_OK {
		return rc
	}
	rc = _sqlite3OsRead(tls, jfd, aData, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), *(*Ti64)(unsafe.Pointer(pOffset))+int64(4))
	if rc != SQLITE_OK {
		return rc
	}
	*(*Ti64)(unsafe.Pointer(pOffset)) += (*TPager)(unsafe.Pointer(pPager)).FpageSize + int64(4) + int64(isMainJrnl*int32(4))
	/* Sanity checking on the page.  This is more important that I originally
	 ** thought.  If a power failure occurs while the journal is being written,
	 ** it could cause invalid data to be written into the journal.  We need to
	 ** detect this invalid data (with high probability) and ignore it.
	 */
	if *(*TPgno)(unsafe.Pointer(bp + 4)) == uint32(0) || *(*TPgno)(unsafe.Pointer(bp + 4)) == (*TPager)(unsafe.Pointer(pPager)).FlckPgno {
		return int32(SQLITE_DONE)
	}
	if *(*TPgno)(unsafe.Pointer(bp + 4)) > (*TPager)(unsafe.Pointer(pPager)).FdbSize || _sqlite3BitvecTest(tls, pDone, *(*TPgno)(unsafe.Pointer(bp + 4))) != 0 {
		return SQLITE_OK
	}
	if isMainJrnl != 0 {
		rc = _read32bits(tls, jfd, *(*Ti64)(unsafe.Pointer(pOffset))-int64(4), bp+8)
		if rc != 0 {
			return rc
		}
		if !(isSavepnt != 0) && _pager_cksum(tls, pPager, aData) != *(*Tu32)(unsafe.Pointer(bp + 8)) {
			return int32(SQLITE_DONE)
		}
	}
	/* If this page has already been played back before during the current
	 ** rollback, then don't bother to play it back again.
	 */
	if v3 = pDone != 0; v3 {
		v2 = _sqlite3BitvecSet(tls, pDone, *(*TPgno)(unsafe.Pointer(bp + 4)))
		rc = v2
	}
	if v3 && v2 != SQLITE_OK {
		return rc
	}
	/* When playing back page 1, restore the nReserve setting
	 */
	if *(*TPgno)(unsafe.Pointer(bp + 4)) == uint32(1) && int32((*TPager)(unsafe.Pointer(pPager)).FnReserve) != int32(*(*Tu8)(unsafe.Pointer(aData + 20))) {
		(*TPager)(unsafe.Pointer(pPager)).FnReserve = int16(*(*Tu8)(unsafe.Pointer(aData + 20)))
	}
	/* If the pager is in CACHEMOD state, then there must be a copy of this
	 ** page in the pager cache. In this case just update the pager cache,
	 ** not the database file. The page is left marked dirty in this case.
	 **
	 ** An exception to the above rule: If the database is in no-sync mode
	 ** and a page is moved during an incremental vacuum then the page may
	 ** not be in the pager cache. Later: if a malloc() or IO error occurs
	 ** during a Movepage() call, then the page may not be in the cache
	 ** either. So the condition described in the above paragraph is not
	 ** assert()able.
	 **
	 ** If in WRITER_DBMOD, WRITER_FINISHED or OPEN state, then we update the
	 ** pager cache if it exists and the main file. The page is then marked
	 ** not dirty. Since this code is only executed in PAGER_OPEN state for
	 ** a hot-journal rollback, it is guaranteed that the page-cache is empty
	 ** if the pager is in OPEN state.
	 **
	 ** Ticket #1171:  The statement journal might contain page content that is
	 ** different from the page content at the start of the transaction.
	 ** This occurs when a page is changed prior to the start of a statement
	 ** then changed again within the statement.  When rolling back such a
	 ** statement we must not write to the original database unless we know
	 ** for certain that original page contents are synced into the main rollback
	 ** journal.  Otherwise, a power loss might leave modified data in the
	 ** database file without an entry in the rollback journal that can
	 ** restore the database to its original form.  Two conditions must be
	 ** met before writing to the database files. (1) the database must be
	 ** locked.  (2) we know that the original page content is fully synced
	 ** in the main journal either because the page is not in cache or else
	 ** the page is marked as needSync==0.
	 **
	 ** 2008-04-14:  When attempting to vacuum a corrupt database file, it
	 ** is possible to fail a statement on a database that does not yet exist.
	 ** Do not attempt to write if database file has never been opened.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3PagerLookup(tls, pPager, *(*TPgno)(unsafe.Pointer(bp + 4)))
	}
	if isMainJrnl != 0 {
		isSynced = libc.BoolInt32((*TPager)(unsafe.Pointer(pPager)).FnoSync != 0 || *(*Ti64)(unsafe.Pointer(pOffset)) <= (*TPager)(unsafe.Pointer(pPager)).FjournalHdr)
	} else {
		isSynced = libc.BoolInt32(*(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) || 0 == int32((*TPgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags)&int32(PGHDR_NEED_SYNC))
	}
	if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) && (int32((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_DBMOD) || int32((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) && isSynced != 0 {
		ofst = int64(*(*TPgno)(unsafe.Pointer(bp + 4))-libc.Uint32FromInt32(1)) * (*TPager)(unsafe.Pointer(pPager)).FpageSize
		/* Write the data read from the journal back into the database file.
		 ** This is usually safe even for an encrypted database - as the data
		 ** was encrypted before it was written to the journal file. The exception
		 ** is if the data was just read from an in-memory sub-journal. In that
		 ** case it must be encrypted here before it is copied into the database
		 ** file.  */
		rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, aData, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), ofst)
		if *(*TPgno)(unsafe.Pointer(bp + 4)) > (*TPager)(unsafe.Pointer(pPager)).FdbFileSize {
			(*TPager)(unsafe.Pointer(pPager)).FdbFileSize = *(*TPgno)(unsafe.Pointer(bp + 4))
		}
		if (*TPager)(unsafe.Pointer(pPager)).FpBackup != 0 {
			_sqlite3BackupUpdate(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup, *(*TPgno)(unsafe.Pointer(bp + 4)), aData)
		}
	} else {
		if !(isMainJrnl != 0) && *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
			/* If this is a rollback of a savepoint and data was not written to
			 ** the database and the page is not in-memory, there is a potential
			 ** problem. When the page is next fetched by the b-tree layer, it
			 ** will be read from the database file, which may or may not be
			 ** current.
			 **
			 ** There are a couple of different ways this can happen. All are quite
			 ** obscure. When running in synchronous mode, this can only happen
			 ** if the page is on the free-list at the start of the transaction, then
			 ** populated, then moved using sqlite3PagerMovepage().
			 **
			 ** The solution is to add an in-memory page to the cache containing
			 ** the data just read from the sub-journal. Mark the page as dirty
			 ** and if the pager requires a journal-sync, then mark the page as
			 ** requiring a journal-sync before it is written.
			 */
			p4 = pPager + 21
			*(*Tu8)(unsafe.Pointer(p4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p4))) | libc.Int32FromInt32(SPILLFLAG_ROLLBACK))
			rc = _sqlite3PagerGet(tls, pPager, *(*TPgno)(unsafe.Pointer(bp + 4)), bp, int32(1))
			p5 = pPager + 21
			*(*Tu8)(unsafe.Pointer(p5)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p5))) & ^libc.Int32FromInt32(SPILLFLAG_ROLLBACK))
			if rc != SQLITE_OK {
				return rc
			}
			_sqlite3PcacheMakeDirty(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		pData = (*TPgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpData
		libc.Xmemcpy(tls, pData, aData, uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TPager)(unsafe.Pointer(pPager)).FxReiniter})))(tls, *(*uintptr)(unsafe.Pointer(bp)))
		/* It used to be that sqlite3PcacheMakeClean(pPg) was called here.  But
		 ** that call was dangerous and had no detectable benefit since the cache
		 ** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
		 ** has been removed. */
		/* If this was page 1, then restore the value of Pager.dbFileVers.
		 ** Do this before any decoding. */
		if *(*TPgno)(unsafe.Pointer(bp + 4)) == uint32(1) {
			libc.Xmemcpy(tls, pPager+112, pData+24, uint32(16))
		}
		_sqlite3PcacheRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Parameter zSuper is the name of a super-journal file. A single journal
//	** file that referred to the super-journal file has just been rolled back.
//	** This routine checks if it is possible to delete the super-journal file,
//	** and does so if it is.
//	**
//	** Argument zSuper may point to Pager.pTmpSpace. So that buffer is not
//	** available for use within this function.
//	**
//	** When a super-journal file is created, it is populated with the names
//	** of all of its child journals, one after another, formatted as utf-8
//	** encoded text. The end of each child journal file is marked with a
//	** nul-terminator byte (0x00). i.e. the entire contents of a super-journal
//	** file for a transaction involving two databases might be:
//	**
//	**   "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
//	**
//	** A super-journal file may only be deleted once all of its child
//	** journals have been rolled back.
//	**
//	** This function reads the contents of the super-journal file into
//	** memory and loops through each of the child journal names. For
//	** each child journal, it checks if:
//	**
//	**   * if the child journal exists, and if so
//	**   * if the child journal contains a reference to super-journal
//	**     file zSuper
//	**
//	** If a child journal can be found that matches both of the criteria
//	** above, this function returns without doing anything. Otherwise, if
//	** no such child journal can be found, file zSuper is deleted from
//	** the file-system using sqlite3OsDelete().
//	**
//	** If an IO error within this function, an error code is returned. This
//	** function allocates memory by calling sqlite3Malloc(). If an allocation
//	** fails, SQLITE_NOMEM is returned. Otherwise, if no IO or malloc errors
//	** occur, SQLITE_OK is returned.
//	**
//	** TODO: This function allocates a single block of memory to load
//	** the entire contents of the super-journal file. This could be
//	** a couple of kilobytes or so - potentially larger than the page
//	** size.
//	*/
func _pager_delsuper(tls *libc.TLS, pPager uintptr, zSuper uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c, flags, flags1, nSuperPtr, rc int32
	var pJournal, pSuper, pVfs, zFree, zJournal, zSuperJournal, zSuperPtr uintptr
	var v1, v2, v3 int8
	var _ /* exists at bp+8 */ int32
	var _ /* nSuperJournal at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, flags, flags1, nSuperPtr, pJournal, pSuper, pVfs, rc, zFree, zJournal, zSuperJournal, zSuperPtr, v1, v2, v3
	pVfs = (*TPager)(unsafe.Pointer(pPager)).FpVfs /* Malloc'd child-journal file descriptor */
	zSuperJournal = uintptr(0)                     /* Space to hold super-journal filename */
	zFree = uintptr(0)                             /* Amount of space allocated to zSuperPtr[] */
	/* Allocate space for both the pJournal and pSuper file descriptors.
	 ** If successful, open the super-journal file for reading.
	 */
	pSuper = _sqlite3MallocZero(tls, uint64((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile*int32(2)))
	if !(pSuper != 0) {
		rc = int32(SQLITE_NOMEM)
		pJournal = uintptr(0)
	} else {
		flags = libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_SUPER_JOURNAL)
		rc = _sqlite3OsOpen(tls, pVfs, zSuper, pSuper, flags, uintptr(0))
		pJournal = pSuper + uintptr((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile)
	}
	if rc != SQLITE_OK {
		goto delsuper_out
	}
	/* Load the entire super-journal file into space obtained from
	 ** sqlite3_malloc() and pointed to by zSuperJournal.   Also obtain
	 ** sufficient space (in zSuperPtr) to hold the names of super-journal
	 ** files extracted from regular rollback-journals.
	 */
	rc = _sqlite3OsFileSize(tls, pSuper, bp)
	if rc != SQLITE_OK {
		goto delsuper_out
	}
	nSuperPtr = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + int32(1)
	zFree = _sqlite3Malloc(tls, uint64(int64(4)+*(*Ti64)(unsafe.Pointer(bp))+int64(int64(nSuperPtr))+int64(2)))
	if !(zFree != 0) {
		rc = int32(SQLITE_NOMEM)
		goto delsuper_out
	}
	v3 = libc.Int8FromInt32(0)
	*(*int8)(unsafe.Pointer(zFree + 3)) = v3
	v2 = v3
	*(*int8)(unsafe.Pointer(zFree + 2)) = v2
	v1 = v2
	*(*int8)(unsafe.Pointer(zFree + 1)) = v1
	*(*int8)(unsafe.Pointer(zFree)) = v1
	zSuperJournal = zFree + 4
	zSuperPtr = zSuperJournal + uintptr(*(*Ti64)(unsafe.Pointer(bp))+int64(2))
	rc = _sqlite3OsRead(tls, pSuper, zSuperJournal, int32(*(*Ti64)(unsafe.Pointer(bp))), 0)
	if rc != SQLITE_OK {
		goto delsuper_out
	}
	*(*int8)(unsafe.Pointer(zSuperJournal + uintptr(*(*Ti64)(unsafe.Pointer(bp))))) = 0
	*(*int8)(unsafe.Pointer(zSuperJournal + uintptr(*(*Ti64)(unsafe.Pointer(bp))+int64(1)))) = 0
	zJournal = zSuperJournal
	for int64(int32(int32(zJournal))-int32(int32(zSuperJournal))) < *(*Ti64)(unsafe.Pointer(bp)) {
		rc = _sqlite3OsAccess(tls, pVfs, zJournal, SQLITE_ACCESS_EXISTS, bp+8)
		if rc != SQLITE_OK {
			goto delsuper_out
		}
		if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
			flags1 = libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_SUPER_JOURNAL)
			rc = _sqlite3OsOpen(tls, pVfs, zJournal, pJournal, flags1, uintptr(0))
			if rc != SQLITE_OK {
				goto delsuper_out
			}
			rc = _readSuperJournal(tls, pJournal, zSuperPtr, uint32(uint32(nSuperPtr)))
			_sqlite3OsClose(tls, pJournal)
			if rc != SQLITE_OK {
				goto delsuper_out
			}
			c = libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zSuperPtr))) != 0 && libc.Xstrcmp(tls, zSuperPtr, zSuper) == 0)
			if c != 0 {
				/* We have a match. Do not delete the super-journal file. */
				goto delsuper_out
			}
		}
		zJournal += uintptr(_sqlite3Strlen30(tls, zJournal) + libc.Int32FromInt32(1))
	}
	_sqlite3OsClose(tls, pSuper)
	rc = _sqlite3OsDelete(tls, pVfs, zSuper, 0)
	goto delsuper_out
delsuper_out:
	;
	Xsqlite3_free(tls, zFree)
	if pSuper != 0 {
		_sqlite3OsClose(tls, pSuper)
		Xsqlite3_free(tls, pSuper)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is used to change the actual size of the database
//	** file in the file-system. This only happens when committing a transaction,
//	** or rolling back a transaction (including rolling back a hot-journal).
//	**
//	** If the main database file is not open, or the pager is not in either
//	** DBMOD or OPEN state, this function is a no-op. Otherwise, the size
//	** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
//	** If the file on disk is currently larger than nPage pages, then use the VFS
//	** xTruncate() method to truncate it.
//	**
//	** Or, it might be the case that the file on disk is smaller than
//	** nPage pages. Some operating system implementations can get confused if
//	** you try to truncate a file to some size that is larger than it
//	** currently is, so detect this case and write a single zero byte to
//	** the end of the new file instead.
//	**
//	** If successful, return SQLITE_OK. If an IO error occurs while modifying
//	** the database file, return the error code to the caller.
//	*/
func _pager_truncate(tls *libc.TLS, pPager uintptr, nPage TPgno) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pTmp uintptr
	var rc, szPage int32
	var _ /* currentSize at bp+0 */ Ti64
	var _ /* newSize at bp+8 */ Ti64
	_, _, _ = pTmp, rc, szPage
	rc = SQLITE_OK
	if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) && (int32((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_DBMOD) || int32((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) {
		szPage = int32((*TPager)(unsafe.Pointer(pPager)).FpageSize)
		/* TODO: Is it safe to use Pager.dbFileSize here? */
		rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, bp)
		*(*Ti64)(unsafe.Pointer(bp + 8)) = int64(int64(szPage)) * int64(int64(nPage))
		if rc == SQLITE_OK && *(*Ti64)(unsafe.Pointer(bp)) != *(*Ti64)(unsafe.Pointer(bp + 8)) {
			if *(*Ti64)(unsafe.Pointer(bp)) > *(*Ti64)(unsafe.Pointer(bp + 8)) {
				rc = _sqlite3OsTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, *(*Ti64)(unsafe.Pointer(bp + 8)))
			} else {
				if *(*Ti64)(unsafe.Pointer(bp))+int64(int64(szPage)) <= *(*Ti64)(unsafe.Pointer(bp + 8)) {
					pTmp = (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace
					libc.Xmemset(tls, pTmp, 0, uint32(uint32(szPage)))
					_sqlite3OsFileControlHint(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_SIZE_HINT), bp+8)
					rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, pTmp, szPage, *(*Ti64)(unsafe.Pointer(bp + 8))-int64(int64(szPage)))
				}
			}
			if rc == SQLITE_OK {
				(*TPager)(unsafe.Pointer(pPager)).FdbFileSize = nPage
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return a sanitized version of the sector-size of OS file pFile. The
//	** return value is guaranteed to lie between 32 and MAX_SECTOR_SIZE.
//	*/
func _sqlite3SectorSize(tls *libc.TLS, pFile uintptr) (r int32) {
	var iRet int32
	_ = iRet
	iRet = _sqlite3OsSectorSize(tls, pFile)
	if iRet < int32(32) {
		iRet = int32(512)
	} else {
		if iRet > int32(MAX_SECTOR_SIZE) {
			iRet = int32(MAX_SECTOR_SIZE)
		}
	}
	return iRet
}

// C documentation
//
//	/*
//	** Set the value of the Pager.sectorSize variable for the given
//	** pager based on the value returned by the xSectorSize method
//	** of the open database file. The sector size will be used
//	** to determine the size and alignment of journal header and
//	** super-journal pointers within created journal files.
//	**
//	** For temporary files the effective sector size is always 512 bytes.
//	**
//	** Otherwise, for non-temporary files, the effective sector size is
//	** the value returned by the xSectorSize() method rounded up to 32 if
//	** it is less than 32, or rounded down to MAX_SECTOR_SIZE if it
//	** is greater than MAX_SECTOR_SIZE.
//	**
//	** If the file has the SQLITE_IOCAP_POWERSAFE_OVERWRITE property, then set
//	** the effective sector size to its minimum value (512).  The purpose of
//	** pPager->sectorSize is to define the "blast radius" of bytes that
//	** might change if a crash occurs while writing to a single byte in
//	** that range.  But with POWERSAFE_OVERWRITE, the blast radius is zero
//	** (that is what POWERSAFE_OVERWRITE means), so we minimize the sector
//	** size.  For backwards compatibility of the rollback journal file format,
//	** we cannot reduce the effective sector size below 512.
//	*/
func _setSectorSize(tls *libc.TLS, pPager uintptr) {
	if (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 || _sqlite3OsDeviceCharacteristics(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd)&int32(SQLITE_IOCAP_POWERSAFE_OVERWRITE) != 0 {
		/* Sector size doesn't matter for temporary files. Also, the file
		 ** may not have been opened yet, in which case the OsSectorSize()
		 ** call will segfault. */
		(*TPager)(unsafe.Pointer(pPager)).FsectorSize = uint32(512)
	} else {
		(*TPager)(unsafe.Pointer(pPager)).FsectorSize = uint32(_sqlite3SectorSize(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd))
	}
}

// C documentation
//
//	/*
//	** Playback the journal and thus restore the database file to
//	** the state it was in before we started making changes.
//	**
//	** The journal file format is as follows:
//	**
//	**  (1)  8 byte prefix.  A copy of aJournalMagic[].
//	**  (2)  4 byte big-endian integer which is the number of valid page records
//	**       in the journal.  If this value is 0xffffffff, then compute the
//	**       number of page records from the journal size.
//	**  (3)  4 byte big-endian integer which is the initial value for the
//	**       sanity checksum.
//	**  (4)  4 byte integer which is the number of pages to truncate the
//	**       database to during a rollback.
//	**  (5)  4 byte big-endian integer which is the sector size.  The header
//	**       is this many bytes in size.
//	**  (6)  4 byte big-endian integer which is the page size.
//	**  (7)  zero padding out to the next sector size.
//	**  (8)  Zero or more pages instances, each as follows:
//	**        +  4 byte page number.
//	**        +  pPager->pageSize bytes of data.
//	**        +  4 byte checksum
//	**
//	** When we speak of the journal header, we mean the first 7 items above.
//	** Each entry in the journal is an instance of the 8th item.
//	**
//	** Call the value from the second bullet "nRec".  nRec is the number of
//	** valid page entries in the journal.  In most cases, you can compute the
//	** value of nRec from the size of the journal file.  But if a power
//	** failure occurred while the journal was being written, it could be the
//	** case that the size of the journal file had already been increased but
//	** the extra entries had not yet made it safely to disk.  In such a case,
//	** the value of nRec computed from the file size would be too large.  For
//	** that reason, we always use the nRec value in the header.
//	**
//	** If the nRec value is 0xffffffff it means that nRec should be computed
//	** from the file size.  This value is used when the user selects the
//	** no-sync option for the journal.  A power failure could lead to corruption
//	** in this case.  But for things like temporary table (which will be
//	** deleted when the power is restored) we don't care.
//	**
//	** If the file opened as the journal file is not a well-formed
//	** journal file then all pages up to the first corrupted page are rolled
//	** back (or no pages if the journal header is corrupted). The journal file
//	** is then deleted and SQLITE_OK returned, just as if no corruption had
//	** been encountered.
//	**
//	** If an I/O or malloc() error occurs, the journal-file is not deleted
//	** and an error code is returned.
//	**
//	** The isHot parameter indicates that we are trying to rollback a journal
//	** that might be a hot journal.  Or, it could be that the journal is
//	** preserved because of JOURNALMODE_PERSIST or JOURNALMODE_TRUNCATE.
//	** If the journal really is hot, reset the pager cache prior rolling
//	** back any content.  If the journal is merely persistent, no reset is
//	** needed.
//	*/
func _pager_playback(tls *libc.TLS, pPager uintptr, isHot int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var nPlayback, needPagerReset, rc int32
	var pVfs, zSuper uintptr
	var u Tu32
	var _ /* mxPg at bp+12 */ TPgno
	var _ /* nRec at bp+8 */ Tu32
	var _ /* res at bp+16 */ int32
	var _ /* savedPageSize at bp+20 */ Tu32
	var _ /* szJ at bp+0 */ Ti64
	_, _, _, _, _, _ = nPlayback, needPagerReset, pVfs, rc, u, zSuper
	pVfs = (*TPager)(unsafe.Pointer(pPager)).FpVfs /* Unsigned loop counter */
	*(*TPgno)(unsafe.Pointer(bp + 12)) = uint32(0) /* Result code of a subroutine */
	*(*int32)(unsafe.Pointer(bp + 16)) = int32(1)  /* Value returned by sqlite3OsAccess() */
	zSuper = uintptr(0)                            /* True to reset page prior to first page rollback */
	nPlayback = 0                                  /* Total number of pages restored from journal */
	*(*Tu32)(unsafe.Pointer(bp + 20)) = uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize)
	/* Figure out how many records are in the journal.  Abort early if
	 ** the journal is empty.
	 */
	rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp)
	if rc != SQLITE_OK {
		goto end_playback
	}
	/* Read the super-journal name from the journal, if it is present.
	 ** If a super-journal file name is specified, but the file is not
	 ** present on disk, then the journal is not hot and does not need to be
	 ** played back.
	 **
	 ** TODO: Technically the following is an error because it assumes that
	 ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
	 ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
	 ** mxPathname is 512, which is the same as the minimum allowable value
	 ** for pageSize.
	 */
	zSuper = (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace
	rc = _readSuperJournal(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, zSuper, uint32((*Tsqlite3_vfs)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FpVfs)).FmxPathname+int32(1)))
	if rc == SQLITE_OK && *(*int8)(unsafe.Pointer(zSuper)) != 0 {
		rc = _sqlite3OsAccess(tls, pVfs, zSuper, SQLITE_ACCESS_EXISTS, bp+16)
	}
	zSuper = uintptr(0)
	if rc != SQLITE_OK || !(*(*int32)(unsafe.Pointer(bp + 16)) != 0) {
		goto end_playback
	}
	(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
	needPagerReset = isHot
	/* This loop terminates either when a readJournalHdr() or
	 ** pager_playback_one_page() call returns SQLITE_DONE or an IO error
	 ** occurs.
	 */
	for int32(1) != 0 {
		/* Read the next journal header from the journal file.  If there are
		 ** not enough bytes left in the journal file for a complete header, or
		 ** it is corrupted, then a process must have failed while writing it.
		 ** This indicates nothing more needs to be rolled back.
		 */
		rc = _readJournalHdr(tls, pPager, isHot, *(*Ti64)(unsafe.Pointer(bp)), bp+8, bp+12)
		if rc != SQLITE_OK {
			if rc == int32(SQLITE_DONE) {
				rc = SQLITE_OK
			}
			goto end_playback
		}
		/* If nRec is 0xffffffff, then this journal was created by a process
		 ** working in no-sync mode. This means that the rest of the journal
		 ** file consists of pages, there are no more journal headers. Compute
		 ** the value of nRec based on this assumption.
		 */
		if *(*Tu32)(unsafe.Pointer(bp + 8)) == uint32(0xffffffff) {
			*(*Tu32)(unsafe.Pointer(bp + 8)) = uint32(int32((*(*Ti64)(unsafe.Pointer(bp)) - int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize)) / ((*TPager)(unsafe.Pointer(pPager)).FpageSize + libc.Int64FromInt32(8))))
		}
		/* If nRec is 0 and this rollback is of a transaction created by this
		 ** process and if this is the final header in the journal, then it means
		 ** that this part of the journal was being filled but has not yet been
		 ** synced to disk.  Compute the number of pages based on the remaining
		 ** size of the file.
		 **
		 ** The third term of the test was added to fix ticket #2565.
		 ** When rolling back a hot journal, nRec==0 always means that the next
		 ** chunk of the journal contains zero pages to be rolled back.  But
		 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
		 ** the journal, it means that the journal might contain additional
		 ** pages that need to be rolled back and that the number of pages
		 ** should be computed based on the journal file size.
		 */
		if *(*Tu32)(unsafe.Pointer(bp + 8)) == uint32(0) && !(isHot != 0) && (*TPager)(unsafe.Pointer(pPager)).FjournalHdr+int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize) == (*TPager)(unsafe.Pointer(pPager)).FjournalOff {
			*(*Tu32)(unsafe.Pointer(bp + 8)) = uint32(int32((*(*Ti64)(unsafe.Pointer(bp)) - (*TPager)(unsafe.Pointer(pPager)).FjournalOff) / ((*TPager)(unsafe.Pointer(pPager)).FpageSize + libc.Int64FromInt32(8))))
		}
		/* If this is the first header read from the journal, truncate the
		 ** database file back to its original size.
		 */
		if (*TPager)(unsafe.Pointer(pPager)).FjournalOff == int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize) {
			rc = _pager_truncate(tls, pPager, *(*TPgno)(unsafe.Pointer(bp + 12)))
			if rc != SQLITE_OK {
				goto end_playback
			}
			(*TPager)(unsafe.Pointer(pPager)).FdbSize = *(*TPgno)(unsafe.Pointer(bp + 12))
			if (*TPager)(unsafe.Pointer(pPager)).FmxPgno < *(*TPgno)(unsafe.Pointer(bp + 12)) {
				(*TPager)(unsafe.Pointer(pPager)).FmxPgno = *(*TPgno)(unsafe.Pointer(bp + 12))
			}
		}
		/* Copy original pages out of the journal and back into the
		 ** database file and/or page cache.
		 */
		u = uint32(0)
		for {
			if !(u < *(*Tu32)(unsafe.Pointer(bp + 8))) {
				break
			}
			if needPagerReset != 0 {
				_pager_reset(tls, pPager)
				needPagerReset = 0
			}
			rc = _pager_playback_one_page(tls, pPager, pPager+80, uintptr(0), int32(1), 0)
			if rc == SQLITE_OK {
				nPlayback++
			} else {
				if rc == int32(SQLITE_DONE) {
					(*TPager)(unsafe.Pointer(pPager)).FjournalOff = *(*Ti64)(unsafe.Pointer(bp))
					break
				} else {
					if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
						/* If the journal has been truncated, simply stop reading and
						 ** processing the journal. This might happen if the journal was
						 ** not completely written and synced prior to a crash.  In that
						 ** case, the database should have never been written in the
						 ** first place so it is OK to simply abandon the rollback. */
						rc = SQLITE_OK
						goto end_playback
					} else {
						/* If we are unable to rollback, quit and return the error
						 ** code.  This will cause the pager to enter the error state
						 ** so that no further harm will be done.  Perhaps the next
						 ** process to come along will be able to rollback the database.
						 */
						goto end_playback
					}
				}
			}
			goto _1
		_1:
			;
			u++
		}
	}
	/*NOTREACHED*/
	goto end_playback
end_playback:
	;
	if rc == SQLITE_OK {
		rc = _sqlite3PagerSetPagesize(tls, pPager, bp+20, -int32(1))
	}
	/* Following a rollback, the database file should be back in its original
	 ** state prior to the start of the transaction, so invoke the
	 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
	 ** assertion that the transaction counter was modified.
	 */
	/* If this playback is happening automatically as a result of an IO or
	 ** malloc error that occurred after the change-counter was updated but
	 ** before the transaction was committed, then the change-counter
	 ** modification may just have been reverted. If this happens in exclusive
	 ** mode, then subsequent transactions performed by the connection will not
	 ** update the change-counter at all. This may lead to cache inconsistency
	 ** problems for other processes at some point in the future. So, just
	 ** in case this has happened, clear the changeCountDone flag now.
	 */
	(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = (*TPager)(unsafe.Pointer(pPager)).FtempFile
	if rc == SQLITE_OK {
		/* Leave 4 bytes of space before the super-journal filename in memory.
		 ** This is because it may end up being passed to sqlite3OsOpen(), in
		 ** which case it requires 4 0x00 bytes in memory immediately before
		 ** the filename. */
		zSuper = (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace + 4
		rc = _readSuperJournal(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, zSuper, uint32((*Tsqlite3_vfs)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FpVfs)).FmxPathname+int32(1)))
	}
	if rc == SQLITE_OK && (int32((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_DBMOD) || int32((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) {
		rc = _sqlite3PagerSync(tls, pPager, uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = _pager_end_transaction(tls, pPager, libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zSuper))) != int32('\000')), 0)
	}
	if rc == SQLITE_OK && *(*int8)(unsafe.Pointer(zSuper)) != 0 && *(*int32)(unsafe.Pointer(bp + 16)) != 0 {
		/* If there was a super-journal and this routine will return success,
		 ** see if it is possible to delete the super-journal.
		 */
		libc.Xmemset(tls, (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace, 0, uint32(4))
		rc = _pager_delsuper(tls, pPager, zSuper)
	}
	if isHot != 0 && nPlayback != 0 {
		Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_NOTICE)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8), __ccgo_ts+5424, libc.VaList(bp+32, nPlayback, (*TPager)(unsafe.Pointer(pPager)).FzJournal))
	}
	/* The Pager.sectorSize variable may have been updated while rolling
	 ** back a journal created by a process with a different sector size
	 ** value. Reset it to the correct value for this process.
	 */
	_setSectorSize(tls, pPager)
	return rc
}

// C documentation
//
//	/*
//	** Read the content for page pPg out of the database file (or out of
//	** the WAL if that is where the most recent copy if found) into
//	** pPg->pData. A shared lock or greater must be held on the database
//	** file before this function is called.
//	**
//	** If page 1 is read, then the value of Pager.dbFileVers[] is set to
//	** the value read from the database file.
//	**
//	** If an IO error occurs, then the IO error is returned to the caller.
//	** Otherwise, SQLITE_OK is returned.
//	*/
func _readDbPage(tls *libc.TLS, pPg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var dbFileVers, pPager uintptr
	var iOffset Ti64
	var rc int32
	var _ /* iFrame at bp+0 */ Tu32
	_, _, _, _ = dbFileVers, iOffset, pPager, rc
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager /* Pager object associated with page pPg */
	rc = SQLITE_OK                                  /* Return code */
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)        /* Frame of WAL containing pgno */
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc = _sqlite3WalFindFrame(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno, bp)
		if rc != 0 {
			return rc
		}
	}
	if *(*Tu32)(unsafe.Pointer(bp)) != 0 {
		rc = _sqlite3WalReadFrame(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, *(*Tu32)(unsafe.Pointer(bp)), int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), (*TPgHdr)(unsafe.Pointer(pPg)).FpData)
	} else {
		iOffset = int64((*TPgHdr)(unsafe.Pointer(pPg)).Fpgno-libc.Uint32FromInt32(1)) * (*TPager)(unsafe.Pointer(pPager)).FpageSize
		rc = _sqlite3OsRead(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, (*TPgHdr)(unsafe.Pointer(pPg)).FpData, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), iOffset)
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
			rc = SQLITE_OK
		}
	}
	if (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno == uint32(1) {
		if rc != 0 {
			/* If the read is unsuccessful, set the dbFileVers[] to something
			 ** that will never be a valid file version.  dbFileVers[] is a copy
			 ** of bytes 24..39 of the database.  Bytes 28..31 should always be
			 ** zero or the size of the database in page. Bytes 32..35 and 35..39
			 ** should be page numbers which are never 0xffffffff.  So filling
			 ** pPager->dbFileVers[] with all 0xff bytes should suffice.
			 **
			 ** For an encrypted database, the situation is more complex:  bytes
			 ** 24..39 of the database are white noise.  But the probability of
			 ** white noise equaling 16 bytes of 0xff is vanishingly small so
			 ** we should still be ok.
			 */
			libc.Xmemset(tls, pPager+112, int32(0xff), uint32(16))
		} else {
			dbFileVers = (*TPgHdr)(unsafe.Pointer(pPg)).FpData + 24
			libc.Xmemcpy(tls, pPager+112, dbFileVers, uint32(16))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Update the value of the change-counter at offsets 24 and 92 in
//	** the header and the sqlite version number at offset 96.
//	**
//	** This is an unconditional update.  See also the pager_incr_changecounter()
//	** routine which only updates the change-counter if the update is actually
//	** needed, as determined by the pPager->changeCountDone state variable.
//	*/
func _pager_write_changecounter(tls *libc.TLS, pPg uintptr) {
	var change_counter Tu32
	_ = change_counter
	if pPg == uintptr(0) {
		return
	}
	/* Increment the value just read and write it back to byte 24. */
	change_counter = _sqlite3Get4byte(tls, (*TPgHdr)(unsafe.Pointer(pPg)).FpPager+112) + uint32(1)
	_sqlite3Put4byte(tls, (*TPgHdr)(unsafe.Pointer(pPg)).FpData+uintptr(24), change_counter)
	/* Also store the SQLite version number in bytes 96..99 and in
	 ** bytes 92..95 store the change counter for which the version number
	 ** is valid. */
	_sqlite3Put4byte(tls, (*TPgHdr)(unsafe.Pointer(pPg)).FpData+uintptr(92), change_counter)
	_sqlite3Put4byte(tls, (*TPgHdr)(unsafe.Pointer(pPg)).FpData+uintptr(96), uint32(SQLITE_VERSION_NUMBER))
}

// C documentation
//
//	/*
//	** This function is invoked once for each page that has already been
//	** written into the log file when a WAL transaction is rolled back.
//	** Parameter iPg is the page number of said page. The pCtx argument
//	** is actually a pointer to the Pager structure.
//	**
//	** If page iPg is present in the cache, and has no outstanding references,
//	** it is discarded. Otherwise, if there are one or more outstanding
//	** references, the page content is reloaded from the database. If the
//	** attempt to reload content from the database is required and fails,
//	** return an SQLite error code. Otherwise, SQLITE_OK.
//	*/
func _pagerUndoCallback(tls *libc.TLS, pCtx uintptr, iPg TPgno) (r int32) {
	var pPager, pPg uintptr
	var rc int32
	_, _, _ = pPager, pPg, rc
	rc = SQLITE_OK
	pPager = pCtx
	pPg = _sqlite3PagerLookup(tls, pPager, iPg)
	if pPg != 0 {
		if _sqlite3PcachePageRefcount(tls, pPg) == int64(1) {
			_sqlite3PcacheDrop(tls, pPg)
		} else {
			rc = _readDbPage(tls, pPg)
			if rc == SQLITE_OK {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TPager)(unsafe.Pointer(pPager)).FxReiniter})))(tls, pPg)
			}
			_sqlite3PagerUnrefNotNull(tls, pPg)
		}
	}
	/* Normally, if a transaction is rolled back, any backup processes are
	 ** updated as data is copied out of the rollback journal and into the
	 ** database. This is not generally possible with a WAL database, as
	 ** rollback involves simply truncating the log file. Therefore, if one
	 ** or more frames have already been written to the log (and therefore
	 ** also copied into the backup databases) as part of this transaction,
	 ** the backups must be restarted.
	 */
	_sqlite3BackupRestart(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup)
	return rc
}

// C documentation
//
//	/*
//	** This function is called to rollback a transaction on a WAL database.
//	*/
func _pagerRollbackWal(tls *libc.TLS, pPager uintptr) (r int32) {
	var pList, pNext uintptr
	var rc int32
	_, _, _ = pList, pNext, rc /* List of dirty pages to revert */
	/* For all pages in the cache that are currently dirty or have already
	 ** been written (but not committed) to the log file, do one of the
	 ** following:
	 **
	 **   + Discard the cached page (if refcount==0), or
	 **   + Reload page content from the database (if refcount>0).
	 */
	(*TPager)(unsafe.Pointer(pPager)).FdbSize = (*TPager)(unsafe.Pointer(pPager)).FdbOrigSize
	rc = _sqlite3WalUndo(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, __ccgo_fp(_pagerUndoCallback), pPager)
	pList = _sqlite3PcacheDirtyList(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
	for pList != 0 && rc == SQLITE_OK {
		pNext = (*TPgHdr)(unsafe.Pointer(pList)).FpDirty
		rc = _pagerUndoCallback(tls, pPager, (*TPgHdr)(unsafe.Pointer(pList)).Fpgno)
		pList = pNext
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is a wrapper around sqlite3WalFrames(). As well as logging
//	** the contents of the list of pages headed by pList (connected by pDirty),
//	** this function notifies any active backup processes that the pages have
//	** changed.
//	**
//	** The list of pages passed into this routine is always sorted by page number.
//	** Hence, if page 1 appears anywhere on the list, it will be the first page.
//	*/
func _pagerWalFrames(tls *libc.TLS, pPager uintptr, _pList uintptr, nTruncate TPgno, isCommit int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _pList
	var nList, rc int32
	var p, ppNext, v2 uintptr
	_, _, _, _, _ = nList, p, ppNext, rc, v2 /* For looping over pages */
	if isCommit != 0 {
		/* If a WAL transaction is being committed, there is no point in writing
		 ** any pages with page numbers greater than nTruncate into the WAL file.
		 ** They will never be read by any client. So remove them from the pDirty
		 ** list here. */
		ppNext = bp
		nList = 0
		p = *(*uintptr)(unsafe.Pointer(bp))
		for {
			v2 = p
			*(*uintptr)(unsafe.Pointer(ppNext)) = v2
			if !(v2 != uintptr(0)) {
				break
			}
			if (*TPgHdr)(unsafe.Pointer(p)).Fpgno <= nTruncate {
				ppNext = p + 16
				nList++
			}
			goto _1
		_1:
			;
			p = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
		}
	} else {
		nList = int32(1)
	}
	*(*Tu32)(unsafe.Pointer(pPager + 200 + 2*4)) += uint32(uint32(nList))
	if (*TPgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fpgno == uint32(1) {
		_pager_write_changecounter(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	rc = _sqlite3WalFrames(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), *(*uintptr)(unsafe.Pointer(bp)), nTruncate, isCommit, int32((*TPager)(unsafe.Pointer(pPager)).FwalSyncFlags))
	if rc == SQLITE_OK && (*TPager)(unsafe.Pointer(pPager)).FpBackup != 0 {
		p = *(*uintptr)(unsafe.Pointer(bp))
		for {
			if !(p != 0) {
				break
			}
			_sqlite3BackupUpdate(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup, (*TPgHdr)(unsafe.Pointer(p)).Fpgno, (*TPgHdr)(unsafe.Pointer(p)).FpData)
			goto _3
		_3:
			;
			p = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Begin a read transaction on the WAL.
//	**
//	** This routine used to be called "pagerOpenSnapshot()" because it essentially
//	** makes a snapshot of the database at the current point in time and preserves
//	** that snapshot for use by the reader in spite of concurrently changes by
//	** other writers or checkpointers.
//	*/
func _pagerBeginReadTransaction(tls *libc.TLS, pPager uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* changed at bp+0 */ int32
	_ = rc                            /* Return code */
	*(*int32)(unsafe.Pointer(bp)) = 0 /* True if cache must be reset */
	/* sqlite3WalEndReadTransaction() was not called for the previous
	 ** transaction in locking_mode=EXCLUSIVE.  So call it now.  If we
	 ** are in locking_mode=NORMAL and EndRead() was previously called,
	 ** the duplicate call is harmless.
	 */
	_sqlite3WalEndReadTransaction(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
	rc = _sqlite3WalBeginReadTransaction(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, bp)
	if rc != SQLITE_OK || *(*int32)(unsafe.Pointer(bp)) != 0 {
		_pager_reset(tls, pPager)
		if (*TPager)(unsafe.Pointer(pPager)).FbUseFetch != 0 {
			_sqlite3OsUnfetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, 0, uintptr(0))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called as part of the transition from PAGER_OPEN
//	** to PAGER_READER state to determine the size of the database file
//	** in pages (assuming the page size currently stored in Pager.pageSize).
//	**
//	** If no error occurs, SQLITE_OK is returned and the size of the database
//	** in pages is stored in *pnPage. Otherwise, an error code (perhaps
//	** SQLITE_IOERR_FSTAT) is returned and *pnPage is left unmodified.
//	*/
func _pagerPagecount(tls *libc.TLS, pPager uintptr, pnPage uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nPage TPgno
	var rc int32
	var _ /* n at bp+0 */ Ti64
	_, _ = nPage, rc /* Value to return via *pnPage */
	/* Query the WAL sub-system for the database size. The WalDbsize()
	 ** function returns zero if the WAL is not open (i.e. Pager.pWal==0), or
	 ** if the database size is not available. The database size is not
	 ** available from the WAL sub-system if the log file is empty or
	 ** contains no valid committed transactions.
	 */
	nPage = _sqlite3WalDbsize(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
	/* If the number of pages in the database is not available from the
	 ** WAL sub-system, determine the page count based on the size of
	 ** the database file.  If the size of the database file is not an
	 ** integer multiple of the page-size, round up the result.
	 */
	if nPage == uint32(0) && (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
		*(*Ti64)(unsafe.Pointer(bp)) = 0 /* Size of db file in bytes */
		rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, bp)
		if rc != SQLITE_OK {
			return rc
		}
		nPage = uint32((*(*Ti64)(unsafe.Pointer(bp)) + (*TPager)(unsafe.Pointer(pPager)).FpageSize - libc.Int64FromInt32(1)) / (*TPager)(unsafe.Pointer(pPager)).FpageSize)
	}
	/* If the current number of pages in the file is greater than the
	 ** configured maximum pager number, increase the allowed limit so
	 ** that the file can be read.
	 */
	if nPage > (*TPager)(unsafe.Pointer(pPager)).FmxPgno {
		(*TPager)(unsafe.Pointer(pPager)).FmxPgno = nPage
	}
	*(*TPgno)(unsafe.Pointer(pnPage)) = nPage
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Check if the *-wal file that corresponds to the database opened by pPager
//	** exists if the database is not empty, or verify that the *-wal file does
//	** not exist (by deleting it) if the database file is empty.
//	**
//	** If the database is not empty and the *-wal file exists, open the pager
//	** in WAL mode.  If the database is empty or if no *-wal file exists and
//	** if no error occurs, make sure Pager.journalMode is not set to
//	** PAGER_JOURNALMODE_WAL.
//	**
//	** Return SQLITE_OK or an error code.
//	**
//	** The caller must hold a SHARED lock on the database file to call this
//	** function. Because an EXCLUSIVE lock on the db file is required to delete
//	** a WAL on a none-empty database, this ensures there is no race condition
//	** between the xAccess() below and an xDelete() being executed by some
//	** other connection.
//	*/
func _pagerOpenWalIfPresent(tls *libc.TLS, pPager uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* isWal at bp+0 */ int32
	var _ /* nPage at bp+4 */ TPgno
	_ = rc
	rc = SQLITE_OK
	if !((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0) { /* True if WAL file exists */
		rc = _sqlite3OsAccess(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, (*TPager)(unsafe.Pointer(pPager)).FzWal, SQLITE_ACCESS_EXISTS, bp)
		if rc == SQLITE_OK {
			if *(*int32)(unsafe.Pointer(bp)) != 0 { /* Size of the database file */
				rc = _pagerPagecount(tls, pPager, bp+4)
				if rc != 0 {
					return rc
				}
				if *(*TPgno)(unsafe.Pointer(bp + 4)) == uint32(0) {
					rc = _sqlite3OsDelete(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, (*TPager)(unsafe.Pointer(pPager)).FzWal, 0)
				} else {
					rc = _sqlite3PagerOpenWal(tls, pPager, uintptr(0))
				}
			} else {
				if int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_WAL) {
					(*TPager)(unsafe.Pointer(pPager)).FjournalMode = uint8(PAGER_JOURNALMODE_DELETE)
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
//	** the entire super-journal file. The case pSavepoint==NULL occurs when
//	** a ROLLBACK TO command is invoked on a SAVEPOINT that is a transaction
//	** savepoint.
//	**
//	** When pSavepoint is not NULL (meaning a non-transaction savepoint is
//	** being rolled back), then the rollback consists of up to three stages,
//	** performed in the order specified:
//	**
//	**   * Pages are played back from the main journal starting at byte
//	**     offset PagerSavepoint.iOffset and continuing to
//	**     PagerSavepoint.iHdrOffset, or to the end of the main journal
//	**     file if PagerSavepoint.iHdrOffset is zero.
//	**
//	**   * If PagerSavepoint.iHdrOffset is not zero, then pages are played
//	**     back starting from the journal header immediately following
//	**     PagerSavepoint.iHdrOffset to the end of the main journal file.
//	**
//	**   * Pages are then played back from the sub-journal file, starting
//	**     with the PagerSavepoint.iSubRec and continuing to the end of
//	**     the journal file.
//	**
//	** Throughout the rollback process, each time a page is rolled back, the
//	** corresponding bit is set in a bitvec structure (variable pDone in the
//	** implementation below). This is used to ensure that a page is only
//	** rolled back the first time it is encountered in either journal.
//	**
//	** If pSavepoint is NULL, then pages are only played back from the main
//	** journal file. There is no need for a bitvec in this case.
//	**
//	** In either case, before playback commences the Pager.dbSize variable
//	** is reset to the value that it held at the start of the savepoint
//	** (or transaction). No page with a page-number greater than this value
//	** is played back. If one is encountered it is simply skipped.
//	*/
func _pagerPlaybackSavepoint(tls *libc.TLS, pPager uintptr, pSavepoint uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iHdrOff, szJ Ti64
	var ii, ii1 Tu32
	var pDone uintptr
	var rc int32
	var v1 uint32
	var v2 int64
	var _ /* dummy at bp+4 */ Tu32
	var _ /* nJRec at bp+0 */ Tu32
	var _ /* offset at bp+8 */ Ti64
	_, _, _, _, _, _, _, _ = iHdrOff, ii, ii1, pDone, rc, szJ, v1, v2 /* End of first segment of main-journal records */
	rc = SQLITE_OK                                                    /* Return code */
	pDone = uintptr(0)                                                /* Bitvec to ensure pages played back only once */
	/* Allocate a bitvec to use to store the set of pages rolled back */
	if pSavepoint != 0 {
		pDone = _sqlite3BitvecCreate(tls, (*TPagerSavepoint)(unsafe.Pointer(pSavepoint)).FnOrig)
		if !(pDone != 0) {
			return int32(SQLITE_NOMEM)
		}
	}
	/* Set the database size back to the value it was before the savepoint
	 ** being reverted was opened.
	 */
	if pSavepoint != 0 {
		v1 = (*TPagerSavepoint)(unsafe.Pointer(pSavepoint)).FnOrig
	} else {
		v1 = (*TPager)(unsafe.Pointer(pPager)).FdbOrigSize
	}
	(*TPager)(unsafe.Pointer(pPager)).FdbSize = v1
	(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = (*TPager)(unsafe.Pointer(pPager)).FtempFile
	if !(pSavepoint != 0) && (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		return _pagerRollbackWal(tls, pPager)
	}
	/* Use pPager->journalOff as the effective size of the main rollback
	 ** journal.  The actual file might be larger than this in
	 ** PAGER_JOURNALMODE_TRUNCATE or PAGER_JOURNALMODE_PERSIST.  But anything
	 ** past pPager->journalOff is off-limits to us.
	 */
	szJ = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
	/* Begin by rolling back records from the main journal starting at
	 ** PagerSavepoint.iOffset and continuing to the next journal header.
	 ** There might be records in the main journal that have a page number
	 ** greater than the current database size (pPager->dbSize) but those
	 ** will be skipped automatically.  Pages are added to pDone as they
	 ** are played back.
	 */
	if pSavepoint != 0 && !((*TPager)(unsafe.Pointer(pPager)).FpWal != libc.UintptrFromInt32(0)) {
		if (*TPagerSavepoint)(unsafe.Pointer(pSavepoint)).FiHdrOffset != 0 {
			v2 = (*TPagerSavepoint)(unsafe.Pointer(pSavepoint)).FiHdrOffset
		} else {
			v2 = szJ
		}
		iHdrOff = v2
		(*TPager)(unsafe.Pointer(pPager)).FjournalOff = (*TPagerSavepoint)(unsafe.Pointer(pSavepoint)).FiOffset
		for rc == SQLITE_OK && (*TPager)(unsafe.Pointer(pPager)).FjournalOff < iHdrOff {
			rc = _pager_playback_one_page(tls, pPager, pPager+80, pDone, int32(1), int32(1))
		}
	} else {
		(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
	}
	/* Continue rolling back records out of the main journal starting at
	 ** the first journal header seen and continuing until the effective end
	 ** of the main journal file.  Continue to skip out-of-range pages and
	 ** continue adding pages rolled back to pDone.
	 */
	for rc == SQLITE_OK && (*TPager)(unsafe.Pointer(pPager)).FjournalOff < szJ { /* Loop counter */
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		rc = _readJournalHdr(tls, pPager, 0, szJ, bp, bp+4)
		/*
		 ** The "pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff"
		 ** test is related to ticket #2565.  See the discussion in the
		 ** pager_playback() function for additional information.
		 */
		if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) && (*TPager)(unsafe.Pointer(pPager)).FjournalHdr+int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize) == (*TPager)(unsafe.Pointer(pPager)).FjournalOff {
			*(*Tu32)(unsafe.Pointer(bp)) = uint32((szJ - (*TPager)(unsafe.Pointer(pPager)).FjournalOff) / ((*TPager)(unsafe.Pointer(pPager)).FpageSize + libc.Int64FromInt32(8)))
		}
		ii = uint32(0)
		for {
			if !(rc == SQLITE_OK && ii < *(*Tu32)(unsafe.Pointer(bp)) && (*TPager)(unsafe.Pointer(pPager)).FjournalOff < szJ) {
				break
			}
			rc = _pager_playback_one_page(tls, pPager, pPager+80, pDone, int32(1), int32(1))
			goto _3
		_3:
			;
			ii++
		}
	}
	/* Finally,  rollback pages from the sub-journal.  Page that were
	 ** previously rolled back out of the main journal (and are hence in pDone)
	 ** will be skipped.  Out-of-range pages are also skipped.
	 */
	if pSavepoint != 0 { /* Loop counter */
		*(*Ti64)(unsafe.Pointer(bp + 8)) = int64((*TPagerSavepoint)(unsafe.Pointer(pSavepoint)).FiSubRec) * (int64(4) + (*TPager)(unsafe.Pointer(pPager)).FpageSize)
		if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
			rc = _sqlite3WalSavepointUndo(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, pSavepoint+32)
		}
		ii1 = (*TPagerSavepoint)(unsafe.Pointer(pSavepoint)).FiSubRec
		for {
			if !(rc == SQLITE_OK && ii1 < (*TPager)(unsafe.Pointer(pPager)).FnSubRec) {
				break
			}
			rc = _pager_playback_one_page(tls, pPager, bp+8, pDone, 0, int32(1))
			goto _4
		_4:
			;
			ii1++
		}
	}
	_sqlite3BitvecDestroy(tls, pDone)
	if rc == SQLITE_OK {
		(*TPager)(unsafe.Pointer(pPager)).FjournalOff = szJ
	}
	return rc
}

// C documentation
//
//	/*
//	** Change the maximum number of in-memory pages that are allowed
//	** before attempting to recycle clean and unused pages.
//	*/
func _sqlite3PagerSetCachesize(tls *libc.TLS, pPager uintptr, mxPage int32) {
	_sqlite3PcacheSetCachesize(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, mxPage)
}

// C documentation
//
//	/*
//	** Change the maximum number of in-memory pages that are allowed
//	** before attempting to spill pages to journal.
//	*/
func _sqlite3PagerSetSpillsize(tls *libc.TLS, pPager uintptr, mxPage int32) (r int32) {
	return _sqlite3PcacheSetSpillsize(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, mxPage)
}

// C documentation
//
//	/*
//	** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap.
//	*/
func _pagerFixMaplimit(tls *libc.TLS, pPager uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var fd uintptr
	var _ /* sz at bp+0 */ Tsqlite3_int64
	_ = fd
	fd = (*TPager)(unsafe.Pointer(pPager)).Ffd
	if (*Tsqlite3_file)(unsafe.Pointer(fd)).FpMethods != uintptr(0) && (*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(fd)).FpMethods)).FiVersion >= int32(3) {
		*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = (*TPager)(unsafe.Pointer(pPager)).FszMmap
		(*TPager)(unsafe.Pointer(pPager)).FbUseFetch = libc.BoolUint8(*(*Tsqlite3_int64)(unsafe.Pointer(bp)) > libc.Int64FromInt32(0))
		_setGetterMethod(tls, pPager)
		_sqlite3OsFileControlHint(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_MMAP_SIZE), bp)
	}
}

// C documentation
//
//	/*
//	** Change the maximum size of any memory mapping made of the database file.
//	*/
func _sqlite3PagerSetMmapLimit(tls *libc.TLS, pPager uintptr, szMmap Tsqlite3_int64) {
	(*TPager)(unsafe.Pointer(pPager)).FszMmap = szMmap
	_pagerFixMaplimit(tls, pPager)
}

// C documentation
//
//	/*
//	** Free as much memory as possible from the pager.
//	*/
func _sqlite3PagerShrink(tls *libc.TLS, pPager uintptr) {
	_sqlite3PcacheShrink(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
}

// C documentation
//
//	/*
//	** Adjust settings of the pager to those specified in the pgFlags parameter.
//	**
//	** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness
//	** of the database to damage due to OS crashes or power failures by
//	** changing the number of syncs()s when writing the journals.
//	** There are four levels:
//	**
//	**    OFF       sqlite3OsSync() is never called.  This is the default
//	**              for temporary and transient files.
//	**
//	**    NORMAL    The journal is synced once before writes begin on the
//	**              database.  This is normally adequate protection, but
//	**              it is theoretically possible, though very unlikely,
//	**              that an inopertune power failure could leave the journal
//	**              in a state which would cause damage to the database
//	**              when it is rolled back.
//	**
//	**    FULL      The journal is synced twice before writes begin on the
//	**              database (with some additional information - the nRec field
//	**              of the journal header - being written in between the two
//	**              syncs).  If we assume that writing a
//	**              single disk sector is atomic, then this mode provides
//	**              assurance that the journal will not be corrupted to the
//	**              point of causing damage to the database during rollback.
//	**
//	**    EXTRA     This is like FULL except that is also syncs the directory
//	**              that contains the rollback journal after the rollback
//	**              journal is unlinked.
//	**
//	** The above is for a rollback-journal mode.  For WAL mode, OFF continues
//	** to mean that no syncs ever occur.  NORMAL means that the WAL is synced
//	** prior to the start of checkpoint and that the database file is synced
//	** at the conclusion of the checkpoint if the entire content of the WAL
//	** was written back into the database.  But no sync operations occur for
//	** an ordinary commit in NORMAL mode with WAL.  FULL means that the WAL
//	** file is synced following each commit operation, in addition to the
//	** syncs associated with NORMAL.  There is no difference between FULL
//	** and EXTRA for WAL mode.
//	**
//	** Do not confuse synchronous=FULL with SQLITE_SYNC_FULL.  The
//	** SQLITE_SYNC_FULL macro means to use the MacOSX-style full-fsync
//	** using fcntl(F_FULLFSYNC).  SQLITE_SYNC_NORMAL means to do an
//	** ordinary fsync() call.  There is no difference between SQLITE_SYNC_FULL
//	** and SQLITE_SYNC_NORMAL on platforms other than MacOSX.  But the
//	** synchronous=FULL versus synchronous=NORMAL setting determines when
//	** the xSync primitive is called and is relevant to all platforms.
//	**
//	** Numeric values associated with these states are OFF==1, NORMAL=2,
//	** and FULL=3.
//	*/
func _sqlite3PagerSetFlags(tls *libc.TLS, pPager uintptr, pgFlags uint32) {
	var level uint32
	var v1, v2, v3 int32
	var p4, p5, p6, p7 uintptr
	_, _, _, _, _, _, _, _ = level, v1, v2, v3, p4, p5, p6, p7
	level = pgFlags & uint32(PAGER_SYNCHRONOUS_MASK)
	if (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 {
		(*TPager)(unsafe.Pointer(pPager)).FnoSync = uint8(1)
		(*TPager)(unsafe.Pointer(pPager)).FfullSync = uint8(0)
		(*TPager)(unsafe.Pointer(pPager)).FextraSync = uint8(0)
	} else {
		if level == uint32(PAGER_SYNCHRONOUS_OFF) {
			v1 = int32(1)
		} else {
			v1 = 0
		}
		(*TPager)(unsafe.Pointer(pPager)).FnoSync = uint8(v1)
		if level >= uint32(PAGER_SYNCHRONOUS_FULL) {
			v2 = int32(1)
		} else {
			v2 = 0
		}
		(*TPager)(unsafe.Pointer(pPager)).FfullSync = uint8(v2)
		if level == uint32(PAGER_SYNCHRONOUS_EXTRA) {
			v3 = int32(1)
		} else {
			v3 = 0
		}
		(*TPager)(unsafe.Pointer(pPager)).FextraSync = uint8(v3)
	}
	if (*TPager)(unsafe.Pointer(pPager)).FnoSync != 0 {
		(*TPager)(unsafe.Pointer(pPager)).FsyncFlags = uint8(0)
	} else {
		if pgFlags&uint32(PAGER_FULLFSYNC) != 0 {
			(*TPager)(unsafe.Pointer(pPager)).FsyncFlags = uint8(SQLITE_SYNC_FULL)
		} else {
			(*TPager)(unsafe.Pointer(pPager)).FsyncFlags = uint8(SQLITE_SYNC_NORMAL)
		}
	}
	(*TPager)(unsafe.Pointer(pPager)).FwalSyncFlags = uint8(int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags) << libc.Int32FromInt32(2))
	if (*TPager)(unsafe.Pointer(pPager)).FfullSync != 0 {
		p4 = pPager + 11
		*(*Tu8)(unsafe.Pointer(p4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p4))) | int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags))
	}
	if pgFlags&uint32(PAGER_CKPT_FULLFSYNC) != 0 && !((*TPager)(unsafe.Pointer(pPager)).FnoSync != 0) {
		p5 = pPager + 11
		*(*Tu8)(unsafe.Pointer(p5)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p5))) | libc.Int32FromInt32(SQLITE_SYNC_FULL)<<libc.Int32FromInt32(2))
	}
	if pgFlags&uint32(PAGER_CACHESPILL) != 0 {
		p6 = pPager + 21
		*(*Tu8)(unsafe.Pointer(p6)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p6))) & ^libc.Int32FromInt32(SPILLFLAG_OFF))
	} else {
		p7 = pPager + 21
		*(*Tu8)(unsafe.Pointer(p7)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p7))) | libc.Int32FromInt32(SPILLFLAG_OFF))
	}
}

/*
** The following global variable is incremented whenever the library
** attempts to open a temporary file.  This information is used for
** testing and analysis only.
 */

// C documentation
//
//	/*
//	** Open a temporary file.
//	**
//	** Write the file descriptor into *pFile. Return SQLITE_OK on success
//	** or some other error code if we fail. The OS will automatically
//	** delete the temporary file when it is closed.
//	**
//	** The flags passed to the VFS layer xOpen() call are those specified
//	** by parameter vfsFlags ORed with the following:
//	**
//	**     SQLITE_OPEN_READWRITE
//	**     SQLITE_OPEN_CREATE
//	**     SQLITE_OPEN_EXCLUSIVE
//	**     SQLITE_OPEN_DELETEONCLOSE
//	*/
func _pagerOpentemp(tls *libc.TLS, pPager uintptr, pFile uintptr, vfsFlags int32) (r int32) {
	var rc int32
	_ = rc /* Return code */
	vfsFlags |= libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE)
	rc = _sqlite3OsOpen(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, uintptr(0), pFile, vfsFlags, uintptr(0))
	return rc
}

// C documentation
//
//	/*
//	** Set the busy handler function.
//	**
//	** The pager invokes the busy-handler if sqlite3OsLock() returns
//	** SQLITE_BUSY when trying to upgrade from no-lock to a SHARED lock,
//	** or when trying to upgrade from a RESERVED lock to an EXCLUSIVE
//	** lock. It does *not* invoke the busy handler when upgrading from
//	** SHARED to RESERVED, or when upgrading from SHARED to EXCLUSIVE
//	** (which occurs during hot-journal rollback). Summary:
//	**
//	**   Transition                        | Invokes xBusyHandler
//	**   --------------------------------------------------------
//	**   NO_LOCK       -> SHARED_LOCK      | Yes
//	**   SHARED_LOCK   -> RESERVED_LOCK    | No
//	**   SHARED_LOCK   -> EXCLUSIVE_LOCK   | No
//	**   RESERVED_LOCK -> EXCLUSIVE_LOCK   | Yes
//	**
//	** If the busy-handler callback returns non-zero, the lock is
//	** retried. If it returns zero, then the SQLITE_BUSY error is
//	** returned to the caller of the pager API function.
//	*/
func _sqlite3PagerSetBusyHandler(tls *libc.TLS, pPager uintptr, xBusyHandler uintptr, pBusyHandlerArg uintptr) {
	var ap uintptr
	_ = ap
	(*TPager)(unsafe.Pointer(pPager)).FxBusyHandler = xBusyHandler
	(*TPager)(unsafe.Pointer(pPager)).FpBusyHandlerArg = pBusyHandlerArg
	ap = pPager + 192
	_sqlite3OsFileControlHint(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_BUSYHANDLER), ap)
}

// C documentation
//
//	/*
//	** Change the page size used by the Pager object. The new page size
//	** is passed in *pPageSize.
//	**
//	** If the pager is in the error state when this function is called, it
//	** is a no-op. The value returned is the error state error code (i.e.
//	** one of SQLITE_IOERR, an SQLITE_IOERR_xxx sub-code or SQLITE_FULL).
//	**
//	** Otherwise, if all of the following are true:
//	**
//	**   * the new page size (value of *pPageSize) is valid (a power
//	**     of two between 512 and SQLITE_MAX_PAGE_SIZE, inclusive), and
//	**
//	**   * there are no outstanding page references, and
//	**
//	**   * the database is either not an in-memory database or it is
//	**     an in-memory database that currently consists of zero pages.
//	**
//	** then the pager object page size is set to *pPageSize.
//	**
//	** If the page size is changed, then this function uses sqlite3PagerMalloc()
//	** to obtain a new Pager.pTmpSpace buffer. If this allocation attempt
//	** fails, SQLITE_NOMEM is returned and the page size remains unchanged.
//	** In all other cases, SQLITE_OK is returned.
//	**
//	** If the page size is not changed, either because one of the enumerated
//	** conditions above is not true, the pager was in error state when this
//	** function was called, or because the memory allocation attempt failed,
//	** then *pPageSize is set to the old, retained page size before returning.
//	*/
func _sqlite3PagerSetPagesize(tls *libc.TLS, pPager uintptr, pPageSize uintptr, nReserve int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pNew uintptr
	var pageSize Tu32
	var rc int32
	var _ /* nByte at bp+0 */ Ti64
	_, _, _ = pNew, pageSize, rc
	rc = SQLITE_OK
	/* It is not possible to do a full assert_pager_state() here, as this
	 ** function may be called from within PagerOpen(), before the state
	 ** of the Pager object is internally consistent.
	 **
	 ** At one point this function returned an error if the pager was in
	 ** PAGER_ERROR state. But since PAGER_ERROR state guarantees that
	 ** there is at least one outstanding page reference, this function
	 ** is a no-op for that case anyhow.
	 */
	pageSize = *(*Tu32)(unsafe.Pointer(pPageSize))
	if (int32((*TPager)(unsafe.Pointer(pPager)).FmemDb) == 0 || (*TPager)(unsafe.Pointer(pPager)).FdbSize == uint32(0)) && _sqlite3PcacheRefCount(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache) == 0 && pageSize != 0 && pageSize != uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize) {
		pNew = libc.UintptrFromInt32(0) /* New temp space */
		*(*Ti64)(unsafe.Pointer(bp)) = 0
		if int32((*TPager)(unsafe.Pointer(pPager)).FeState) > PAGER_OPEN && (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
			rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, bp)
		}
		if rc == SQLITE_OK {
			/* 8 bytes of zeroed overrun space is sufficient so that the b-tree
			 * cell header parser will never run off the end of the allocation */
			pNew = _sqlite3PageMalloc(tls, int32(pageSize+uint32(8)))
			if !(pNew != 0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemset(tls, pNew+uintptr(pageSize), 0, uint32(8))
			}
		}
		if rc == SQLITE_OK {
			_pager_reset(tls, pPager)
			rc = _sqlite3PcacheSetPageSize(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, int32(int32(pageSize)))
		}
		if rc == SQLITE_OK {
			_sqlite3PageFree(tls, (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace)
			(*TPager)(unsafe.Pointer(pPager)).FpTmpSpace = pNew
			(*TPager)(unsafe.Pointer(pPager)).FdbSize = uint32((*(*Ti64)(unsafe.Pointer(bp)) + int64(int64(pageSize)) - libc.Int64FromInt32(1)) / int64(int64(pageSize)))
			(*TPager)(unsafe.Pointer(pPager)).FpageSize = int64(int64(pageSize))
			(*TPager)(unsafe.Pointer(pPager)).FlckPgno = uint32(uint32(_sqlite3PendingByte))/pageSize + uint32(1)
		} else {
			_sqlite3PageFree(tls, pNew)
		}
	}
	*(*Tu32)(unsafe.Pointer(pPageSize)) = uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize)
	if rc == SQLITE_OK {
		if nReserve < 0 {
			nReserve = int32((*TPager)(unsafe.Pointer(pPager)).FnReserve)
		}
		(*TPager)(unsafe.Pointer(pPager)).FnReserve = int16(int16(nReserve))
		_pagerFixMaplimit(tls, pPager)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return a pointer to the "temporary page" buffer held internally
//	** by the pager.  This is a buffer that is big enough to hold the
//	** entire content of a database page.  This buffer is used internally
//	** during rollback and will be overwritten whenever a rollback
//	** occurs.  But other modules are free to use it too, as long as
//	** no rollbacks are happening.
//	*/
func _sqlite3PagerTempSpace(tls *libc.TLS, pPager uintptr) (r uintptr) {
	return (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace
}

// C documentation
//
//	/*
//	** Attempt to set the maximum database page count if mxPage is positive.
//	** Make no changes if mxPage is zero or negative.  And never reduce the
//	** maximum page count below the current size of the database.
//	**
//	** Regardless of mxPage, return the current maximum page count.
//	*/
func _sqlite3PagerMaxPageCount(tls *libc.TLS, pPager uintptr, mxPage TPgno) (r TPgno) {
	if mxPage > uint32(0) {
		(*TPager)(unsafe.Pointer(pPager)).FmxPgno = mxPage
	}
	/* Called only by OP_MaxPgcnt */
	/* assert( pPager->mxPgno>=pPager->dbSize ); */
	/* OP_MaxPgcnt ensures that the parameter passed to this function is not
	 ** less than the total number of valid pages in the database. But this
	 ** may be less than Pager.dbSize, and so the assert() above is not valid */
	return (*TPager)(unsafe.Pointer(pPager)).FmxPgno
}

/*
** The following set of routines are used to disable the simulated
** I/O error mechanism.  These routines are used to avoid simulated
** errors in places where we do not care about errors.
**
** Unless -DSQLITE_TEST=1 is used, these routines are all no-ops
** and generate no code.
 */

// C documentation
//
//	/*
//	** Read the first N bytes from the beginning of the file into memory
//	** that pDest points to.
//	**
//	** If the pager was opened on a transient file (zFilename==""), or
//	** opened on a file less than N bytes in size, the output buffer is
//	** zeroed and SQLITE_OK returned. The rationale for this is that this
//	** function is used to read database headers, and a new transient or
//	** zero sized database has a header than consists entirely of zeroes.
//	**
//	** If any IO error apart from SQLITE_IOERR_SHORT_READ is encountered,
//	** the error code is returned to the caller and the contents of the
//	** output buffer undefined.
//	*/
func _sqlite3PagerReadFileheader(tls *libc.TLS, pPager uintptr, N int32, pDest uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	libc.Xmemset(tls, pDest, 0, uint32(uint32(N)))
	/* This routine is only called by btree immediately after creating
	 ** the Pager object.  There has not been an opportunity to transition
	 ** to WAL mode yet.
	 */
	if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
		rc = _sqlite3OsRead(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, pDest, N, 0)
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
			rc = SQLITE_OK
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function may only be called when a read-transaction is open on
//	** the pager. It returns the total number of pages in the database.
//	**
//	** However, if the file is between 1 and <page-size> bytes in size, then
//	** this is considered a 1 page file.
//	*/
func _sqlite3PagerPagecount(tls *libc.TLS, pPager uintptr, pnPage uintptr) {
	*(*int32)(unsafe.Pointer(pnPage)) = int32((*TPager)(unsafe.Pointer(pPager)).FdbSize)
}

// C documentation
//
//	/*
//	** Try to obtain a lock of type locktype on the database file. If
//	** a similar or greater lock is already held, this function is a no-op
//	** (returning SQLITE_OK immediately).
//	**
//	** Otherwise, attempt to obtain the lock using sqlite3OsLock(). Invoke
//	** the busy callback if the lock is currently not available. Repeat
//	** until the busy callback returns false or until the attempt to
//	** obtain the lock succeeds.
//	**
//	** Return SQLITE_OK on success and an error code if we cannot obtain
//	** the lock. If the lock is obtained successfully, set the Pager.state
//	** variable to locktype before returning.
//	*/
func _pager_wait_on_lock(tls *libc.TLS, pPager uintptr, locktype int32) (r int32) {
	var rc int32
	_ = rc /* Return code */
	/* Check that this is either a no-op (because the requested lock is
	 ** already held), or one of the transitions that the busy-handler
	 ** may be invoked during, according to the comment above
	 ** sqlite3PagerSetBusyhandler().
	 */
	for cond := true; cond; cond = rc == int32(SQLITE_BUSY) && (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPager)(unsafe.Pointer(pPager)).FxBusyHandler})))(tls, (*TPager)(unsafe.Pointer(pPager)).FpBusyHandlerArg) != 0 {
		rc = _pagerLockDb(tls, pPager, locktype)
	}
	return rc
}

/*
** Function assertTruncateConstraint(pPager) checks that one of the
** following is true for all dirty pages currently in the page-cache:
**
**   a) The page number is less than or equal to the size of the
**      current database image, in pages, OR
**
**   b) if the page content were written at this time, it would not
**      be necessary to write the current content out to the sub-journal.
**
** If the condition asserted by this function were not true, and the
** dirty page were to be discarded from the cache via the pagerStress()
** routine, pagerStress() would not write the current page content to
** the database file. If a savepoint transaction were rolled back after
** this happened, the correct behavior would be to restore the current
** content of the page. However, since this content is not present in either
** the database file or the portion of the rollback journal and
** sub-journal rolled back the content could not be restored and the
** database image would become corrupt. It is therefore fortunate that
** this circumstance cannot arise.
 */

// C documentation
//
//	/*
//	** Truncate the in-memory database file image to nPage pages. This
//	** function does not actually modify the database file on disk. It
//	** just sets the internal state of the pager object so that the
//	** truncation will be done when the current transaction is committed.
//	**
//	** This function is only called right before committing a transaction.
//	** Once this function has been called, the transaction must either be
//	** rolled back or committed. It is not safe to call this function and
//	** then continue writing to the database.
//	*/
func _sqlite3PagerTruncateImage(tls *libc.TLS, pPager uintptr, nPage TPgno) {
	(*TPager)(unsafe.Pointer(pPager)).FdbSize = nPage
	/* At one point the code here called assertTruncateConstraint() to
	 ** ensure that all pages being truncated away by this operation are,
	 ** if one or more savepoints are open, present in the savepoint
	 ** journal so that they can be restored if the savepoint is rolled
	 ** back. This is no longer necessary as this function is now only
	 ** called right before committing a transaction. So although the
	 ** Pager object may still have open savepoints (Pager.nSavepoint!=0),
	 ** they cannot be rolled back. So the assertTruncateConstraint() call
	 ** is no longer correct. */
}

// C documentation
//
//	/*
//	** This function is called before attempting a hot-journal rollback. It
//	** syncs the journal file to disk, then sets pPager->journalHdr to the
//	** size of the journal file so that the pager_playback() routine knows
//	** that the entire journal file has been synced.
//	**
//	** Syncing a hot-journal to disk before attempting to roll it back ensures
//	** that if a power-failure occurs during the rollback, the process that
//	** attempts rollback following system recovery sees the same journal
//	** content as this process.
//	**
//	** If everything goes as planned, SQLITE_OK is returned. Otherwise,
//	** an SQLite error code.
//	*/
func _pagerSyncHotJournal(tls *libc.TLS, pPager uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if !((*TPager)(unsafe.Pointer(pPager)).FnoSync != 0) {
		rc = _sqlite3OsSync(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, int32(SQLITE_SYNC_NORMAL))
	}
	if rc == SQLITE_OK {
		rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, pPager+88)
	}
	return rc
}

// C documentation
//
//	/*
//	** Obtain a reference to a memory mapped page object for page number pgno.
//	** The new object will use the pointer pData, obtained from xFetch().
//	** If successful, set *ppPage to point to the new page reference
//	** and return SQLITE_OK. Otherwise, return an SQLite error code and set
//	** *ppPage to zero.
//	**
//	** Page references obtained by calling this function should be released
//	** by calling pagerReleaseMapPage().
//	*/
func _pagerAcquireMapPage(tls *libc.TLS, pPager uintptr, pgno TPgno, pData uintptr, ppPage uintptr) (r int32) {
	var p, v1, v2 uintptr
	_, _, _ = p, v1, v2 /* Memory mapped page to return */
	if (*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist != 0 {
		v1 = (*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist
		p = v1
		*(*uintptr)(unsafe.Pointer(ppPage)) = v1
		(*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
		(*TPgHdr)(unsafe.Pointer(p)).FpDirty = uintptr(0)
		libc.Xmemset(tls, (*TPgHdr)(unsafe.Pointer(p)).FpExtra, 0, uint32(8))
	} else {
		v2 = _sqlite3MallocZero(tls, uint64(uint32(48)+uint32((*TPager)(unsafe.Pointer(pPager)).FnExtra)))
		p = v2
		*(*uintptr)(unsafe.Pointer(ppPage)) = v2
		if p == uintptr(0) {
			_sqlite3OsUnfetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int64(pgno-libc.Uint32FromInt32(1))*(*TPager)(unsafe.Pointer(pPager)).FpageSize, pData)
			return int32(SQLITE_NOMEM)
		}
		(*TPgHdr)(unsafe.Pointer(p)).FpExtra = p + 1*48
		(*TPgHdr)(unsafe.Pointer(p)).Fflags = uint16(PGHDR_MMAP)
		(*TPgHdr)(unsafe.Pointer(p)).FnRef = int64(1)
		(*TPgHdr)(unsafe.Pointer(p)).FpPager = pPager
	}
	(*TPgHdr)(unsafe.Pointer(p)).Fpgno = pgno
	(*TPgHdr)(unsafe.Pointer(p)).FpData = pData
	(*TPager)(unsafe.Pointer(pPager)).FnMmapOut++
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Release a reference to page pPg. pPg must have been returned by an
//	** earlier call to pagerAcquireMapPage().
//	*/
func _pagerReleaseMapPage(tls *libc.TLS, pPg uintptr) {
	var pPager uintptr
	_ = pPager
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	(*TPager)(unsafe.Pointer(pPager)).FnMmapOut--
	(*TPgHdr)(unsafe.Pointer(pPg)).FpDirty = (*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist
	(*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist = pPg
	_sqlite3OsUnfetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int64((*TPgHdr)(unsafe.Pointer(pPg)).Fpgno-libc.Uint32FromInt32(1))*(*TPager)(unsafe.Pointer(pPager)).FpageSize, (*TPgHdr)(unsafe.Pointer(pPg)).FpData)
}

// C documentation
//
//	/*
//	** Free all PgHdr objects stored in the Pager.pMmapFreelist list.
//	*/
func _pagerFreeMapHdrs(tls *libc.TLS, pPager uintptr) {
	var p, pNext uintptr
	_, _ = p, pNext
	p = (*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist
	for {
		if !(p != 0) {
			break
		}
		pNext = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
		Xsqlite3_free(tls, p)
		goto _1
	_1:
		;
		p = pNext
	}
}

// C documentation
//
//	/* Verify that the database file has not be deleted or renamed out from
//	** under the pager.  Return SQLITE_OK if the database is still where it ought
//	** to be on disk.  Return non-zero (SQLITE_READONLY_DBMOVED or some other error
//	** code from sqlite3OsAccess()) if the database has gone missing.
//	*/
func _databaseIsUnmoved(tls *libc.TLS, pPager uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* bHasMoved at bp+0 */ int32
	_ = rc
	*(*int32)(unsafe.Pointer(bp)) = 0
	if (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 {
		return SQLITE_OK
	}
	if (*TPager)(unsafe.Pointer(pPager)).FdbSize == uint32(0) {
		return SQLITE_OK
	}
	rc = _sqlite3OsFileControl(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_HAS_MOVED), bp)
	if rc == int32(SQLITE_NOTFOUND) {
		/* If the HAS_MOVED file-control is unimplemented, assume that the file
		 ** has not been moved.  That is the historical behavior of SQLite: prior to
		 ** version 3.8.3, it never checked */
		rc = SQLITE_OK
	} else {
		if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
			rc = libc.Int32FromInt32(SQLITE_READONLY) | libc.Int32FromInt32(4)<<libc.Int32FromInt32(8)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Shutdown the page cache.  Free all memory and close all files.
//	**
//	** If a transaction was in progress when this routine is called, that
//	** transaction is rolled back.  All outstanding pages are invalidated
//	** and their memory is freed.  Any attempt to use a page associated
//	** with this page cache after this function returns will likely
//	** result in a coredump.
//	**
//	** This function always succeeds. If a transaction is active an attempt
//	** is made to roll it back. If an error occurs during the rollback
//	** a hot journal may be left in the filesystem but no error is returned
//	** to the caller.
//	*/
func _sqlite3PagerClose(tls *libc.TLS, pPager uintptr, db uintptr) (r int32) {
	var a, pTmp uintptr
	_, _ = a, pTmp
	pTmp = (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace
	_sqlite3BeginBenignMalloc(tls)
	_pagerFreeMapHdrs(tls, pPager)
	/* pPager->errCode = 0; */
	(*TPager)(unsafe.Pointer(pPager)).FexclusiveMode = uint8(0)
	a = uintptr(0)
	if db != 0 && uint64(0) == (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NoCkptOnClose) && SQLITE_OK == _databaseIsUnmoved(tls, pPager) {
		a = pTmp
	}
	_sqlite3WalClose(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, db, int32((*TPager)(unsafe.Pointer(pPager)).FwalSyncFlags), int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), a)
	(*TPager)(unsafe.Pointer(pPager)).FpWal = uintptr(0)
	_pager_reset(tls, pPager)
	if (*TPager)(unsafe.Pointer(pPager)).FmemDb != 0 {
		_pager_unlock(tls, pPager)
	} else {
		/* If it is open, sync the journal file before calling UnlockAndRollback.
		 ** If this is not done, then an unsynced portion of the open journal
		 ** file may be played back into the database. If a power failure occurs
		 ** while this is happening, the database could become corrupt.
		 **
		 ** If an error occurs while trying to sync the journal, shift the pager
		 ** into the ERROR state. This causes UnlockAndRollback to unlock the
		 ** database and close the journal file without attempting to roll it
		 ** back or finalize it. The next database user will have to do hot-journal
		 ** rollback before accessing the database file.
		 */
		if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
			_pager_error(tls, pPager, _pagerSyncHotJournal(tls, pPager))
		}
		_pagerUnlockAndRollback(tls, pPager)
	}
	_sqlite3EndBenignMalloc(tls)
	_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
	_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd)
	_sqlite3PageFree(tls, pTmp)
	_sqlite3PcacheClose(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
	Xsqlite3_free(tls, pPager)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Increment the reference count for page pPg.
//	*/
func _sqlite3PagerRef(tls *libc.TLS, pPg uintptr) {
	_sqlite3PcacheRef(tls, pPg)
}

// C documentation
//
//	/*
//	** Sync the journal. In other words, make sure all the pages that have
//	** been written to the journal have actually reached the surface of the
//	** disk and can be restored in the event of a hot-journal rollback.
//	**
//	** If the Pager.noSync flag is set, then this function is a no-op.
//	** Otherwise, the actions required depend on the journal-mode and the
//	** device characteristics of the file-system, as follows:
//	**
//	**   * If the journal file is an in-memory journal file, no action need
//	**     be taken.
//	**
//	**   * Otherwise, if the device does not support the SAFE_APPEND property,
//	**     then the nRec field of the most recently written journal header
//	**     is updated to contain the number of journal records that have
//	**     been written following it. If the pager is operating in full-sync
//	**     mode, then the journal file is synced before this field is updated.
//	**
//	**   * If the device does not support the SEQUENTIAL property, then
//	**     journal file is synced.
//	**
//	** Or, in pseudo-code:
//	**
//	**   if( NOT <in-memory journal> ){
//	**     if( NOT SAFE_APPEND ){
//	**       if( <full-sync mode> ) xSync(<journal file>);
//	**       <update nRec field>
//	**     }
//	**     if( NOT SEQUENTIAL ) xSync(<journal file>);
//	**   }
//	**
//	** If successful, this routine clears the PGHDR_NEED_SYNC flag of every
//	** page currently held in memory before returning SQLITE_OK. If an IO
//	** error is encountered, then the IO error code is returned to the caller.
//	*/
func _syncJournal(tls *libc.TLS, pPager uintptr, newHdr int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iDc, rc, v1 int32
	var iNextHdrOffset Ti64
	var _ /* aMagic at bp+0 */ [8]Tu8
	var _ /* zHeader at bp+8 */ [12]Tu8
	_, _, _, _ = iDc, iNextHdrOffset, rc, v1 /* Return code */
	rc = _sqlite3PagerExclusiveLock(tls, pPager)
	if rc != SQLITE_OK {
		return rc
	}
	if !((*TPager)(unsafe.Pointer(pPager)).FnoSync != 0) {
		if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) && int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) != int32(PAGER_JOURNALMODE_MEMORY) {
			iDc = _sqlite3OsDeviceCharacteristics(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd)
			if 0 == iDc&int32(SQLITE_IOCAP_SAFE_APPEND) {
				libc.Xmemcpy(tls, bp+8, uintptr(unsafe.Pointer(&_aJournalMagic)), uint32(8))
				_sqlite3Put4byte(tls, bp+8+uintptr(8), uint32((*TPager)(unsafe.Pointer(pPager)).FnRec))
				iNextHdrOffset = _journalHdrOffset(tls, pPager)
				rc = _sqlite3OsRead(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp, int32(8), iNextHdrOffset)
				if rc == SQLITE_OK && 0 == libc.Xmemcmp(tls, bp, uintptr(unsafe.Pointer(&_aJournalMagic)), uint32(8)) {
					rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, uintptr(unsafe.Pointer(&_zerobyte)), int32(1), iNextHdrOffset)
				}
				if rc != SQLITE_OK && rc != libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
					return rc
				}
				/* Write the nRec value into the journal file header. If in
				 ** full-synchronous mode, sync the journal first. This ensures that
				 ** all data has really hit the disk before nRec is updated to mark
				 ** it as a candidate for rollback.
				 **
				 ** This is not required if the persistent media supports the
				 ** SAFE_APPEND property. Because in this case it is not possible
				 ** for garbage data to be appended to the file, the nRec field
				 ** is populated with 0xFFFFFFFF when the journal header is written
				 ** and never needs to be updated.
				 */
				if (*TPager)(unsafe.Pointer(pPager)).FfullSync != 0 && 0 == iDc&int32(SQLITE_IOCAP_SEQUENTIAL) {
					rc = _sqlite3OsSync(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags))
					if rc != SQLITE_OK {
						return rc
					}
				}
				rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp+8, int32(12), (*TPager)(unsafe.Pointer(pPager)).FjournalHdr)
				if rc != SQLITE_OK {
					return rc
				}
			}
			if 0 == iDc&int32(SQLITE_IOCAP_SEQUENTIAL) {
				if int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags) == int32(SQLITE_SYNC_FULL) {
					v1 = int32(SQLITE_SYNC_DATAONLY)
				} else {
					v1 = 0
				}
				rc = _sqlite3OsSync(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags)|v1)
				if rc != SQLITE_OK {
					return rc
				}
			}
			(*TPager)(unsafe.Pointer(pPager)).FjournalHdr = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
			if newHdr != 0 && 0 == iDc&int32(SQLITE_IOCAP_SAFE_APPEND) {
				(*TPager)(unsafe.Pointer(pPager)).FnRec = 0
				rc = _writeJournalHdr(tls, pPager)
				if rc != SQLITE_OK {
					return rc
				}
			}
		} else {
			(*TPager)(unsafe.Pointer(pPager)).FjournalHdr = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
		}
	}
	/* Unless the pager is in noSync mode, the journal file was just
	 ** successfully synced. Either way, clear the PGHDR_NEED_SYNC flag on
	 ** all pages.
	 */
	_sqlite3PcacheClearSyncFlags(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
	(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_WRITER_DBMOD)
	return SQLITE_OK
}

var _zerobyte Tu8

// C documentation
//
//	/*
//	** The argument is the first in a linked list of dirty pages connected
//	** by the PgHdr.pDirty pointer. This function writes each one of the
//	** in-memory pages in the list to the database file. The argument may
//	** be NULL, representing an empty list. In this case this function is
//	** a no-op.
//	**
//	** The pager must hold at least a RESERVED lock when this function
//	** is called. Before writing anything to the database file, this lock
//	** is upgraded to an EXCLUSIVE lock. If the lock cannot be obtained,
//	** SQLITE_BUSY is returned and no data is written to the database file.
//	**
//	** If the pager is a temp-file pager and the actual file-system file
//	** is not yet open, it is created and opened before any data is
//	** written out.
//	**
//	** Once the lock has been upgraded and, if necessary, the file opened,
//	** the pages are written out to the database file in list order. Writing
//	** a page is skipped if it meets either of the following criteria:
//	**
//	**   * The page number is greater than Pager.dbSize, or
//	**   * The PGHDR_DONT_WRITE flag is set on the page.
//	**
//	** If writing out a page causes the database file to grow, Pager.dbFileSize
//	** is updated accordingly. If page 1 is written out, then the value cached
//	** in Pager.dbFileVers[] is updated to match the new value stored in
//	** the database file.
//	**
//	** If everything is successful, SQLITE_OK is returned. If an IO error
//	** occurs, an IO error code is returned. Or, if the EXCLUSIVE lock cannot
//	** be obtained, SQLITE_BUSY is returned.
//	*/
func _pager_write_pagelist(tls *libc.TLS, pPager uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var offset Ti64
	var pData uintptr
	var pgno TPgno
	var rc int32
	var _ /* szFile at bp+0 */ Tsqlite3_int64
	_, _, _, _ = offset, pData, pgno, rc
	rc = SQLITE_OK /* Return code */
	/* This function is only called for rollback pagers in WRITER_DBMOD state. */
	/* If the file is a temp-file has not yet been opened, open it now. It
	 ** is not possible for rc to be other than SQLITE_OK if this branch
	 ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
	 */
	if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != libc.UintptrFromInt32(0)) {
		rc = _pagerOpentemp(tls, pPager, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32((*TPager)(unsafe.Pointer(pPager)).FvfsFlags))
	}
	/* Before the first write, give the VFS a hint of what the final
	 ** file size will be.
	 */
	if rc == SQLITE_OK && (*TPager)(unsafe.Pointer(pPager)).FdbHintSize < (*TPager)(unsafe.Pointer(pPager)).FdbSize && ((*TPgHdr)(unsafe.Pointer(pList)).FpDirty != 0 || (*TPgHdr)(unsafe.Pointer(pList)).Fpgno > (*TPager)(unsafe.Pointer(pPager)).FdbHintSize) {
		*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = (*TPager)(unsafe.Pointer(pPager)).FpageSize * int64((*TPager)(unsafe.Pointer(pPager)).FdbSize)
		_sqlite3OsFileControlHint(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_SIZE_HINT), bp)
		(*TPager)(unsafe.Pointer(pPager)).FdbHintSize = (*TPager)(unsafe.Pointer(pPager)).FdbSize
	}
	for rc == SQLITE_OK && pList != 0 {
		pgno = (*TPgHdr)(unsafe.Pointer(pList)).Fpgno
		/* If there are dirty pages in the page cache with page numbers greater
		 ** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
		 ** make the file smaller (presumably by auto-vacuum code). Do not write
		 ** any such pages to the file.
		 **
		 ** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
		 ** set (set by sqlite3PagerDontWrite()).
		 */
		if pgno <= (*TPager)(unsafe.Pointer(pPager)).FdbSize && 0 == int32((*TPgHdr)(unsafe.Pointer(pList)).Fflags)&int32(PGHDR_DONT_WRITE) {
			offset = int64(pgno-libc.Uint32FromInt32(1)) * (*TPager)(unsafe.Pointer(pPager)).FpageSize /* Data to write */
			if (*TPgHdr)(unsafe.Pointer(pList)).Fpgno == uint32(1) {
				_pager_write_changecounter(tls, pList)
			}
			pData = (*TPgHdr)(unsafe.Pointer(pList)).FpData
			/* Write out the page data. */
			rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, pData, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), offset)
			/* If page 1 was just written, update Pager.dbFileVers to match
			 ** the value now stored in the database file. If writing this
			 ** page caused the database file to grow, update dbFileSize.
			 */
			if pgno == uint32(1) {
				libc.Xmemcpy(tls, pPager+112, pData+24, uint32(16))
			}
			if pgno > (*TPager)(unsafe.Pointer(pPager)).FdbFileSize {
				(*TPager)(unsafe.Pointer(pPager)).FdbFileSize = pgno
			}
			*(*Tu32)(unsafe.Pointer(pPager + 200 + 2*4))++
			/* Update any backup objects copying the contents of this pager. */
			_sqlite3BackupUpdate(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup, pgno, (*TPgHdr)(unsafe.Pointer(pList)).FpData)
		} else {
		}
		pList = (*TPgHdr)(unsafe.Pointer(pList)).FpDirty
	}
	return rc
}

// C documentation
//
//	/*
//	** Ensure that the sub-journal file is open. If it is already open, this
//	** function is a no-op.
//	**
//	** SQLITE_OK is returned if everything goes according to plan. An
//	** SQLITE_IOERR_XXX error code is returned if a call to sqlite3OsOpen()
//	** fails.
//	*/
func _openSubJournal(tls *libc.TLS, pPager uintptr) (r int32) {
	var flags, nStmtSpill, rc int32
	_, _, _ = flags, nStmtSpill, rc
	rc = SQLITE_OK
	if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fsjfd)).FpMethods != libc.UintptrFromInt32(0)) {
		flags = libc.Int32FromInt32(SQLITE_OPEN_SUBJOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE)
		nStmtSpill = _sqlite3Config.FnStmtSpill
		if int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_MEMORY) || (*TPager)(unsafe.Pointer(pPager)).FsubjInMemory != 0 {
			nStmtSpill = -int32(1)
		}
		rc = _sqlite3JournalOpen(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, uintptr(0), (*TPager)(unsafe.Pointer(pPager)).Fsjfd, flags, nStmtSpill)
	}
	return rc
}

// C documentation
//
//	/*
//	** Append a record of the current state of page pPg to the sub-journal.
//	**
//	** If successful, set the bit corresponding to pPg->pgno in the bitvecs
//	** for all open savepoints before returning.
//	**
//	** This function returns SQLITE_OK if everything is successful, an IO
//	** error code if the attempt to write to the sub-journal fails, or
//	** SQLITE_NOMEM if a malloc fails while setting a bit in a savepoint
//	** bitvec.
//	*/
func _subjournalPage(tls *libc.TLS, pPg uintptr) (r int32) {
	var offset Ti64
	var pData, pData2, pPager uintptr
	var rc int32
	_, _, _, _, _ = offset, pData, pData2, pPager, rc
	rc = SQLITE_OK
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	if int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) != int32(PAGER_JOURNALMODE_OFF) {
		/* Open the sub-journal, if it has not already been opened */
		rc = _openSubJournal(tls, pPager)
		/* If the sub-journal was opened successfully (or was already open),
		 ** write the journal record into the file.  */
		if rc == SQLITE_OK {
			pData = (*TPgHdr)(unsafe.Pointer(pPg)).FpData
			offset = int64((*TPager)(unsafe.Pointer(pPager)).FnSubRec) * (int64(4) + (*TPager)(unsafe.Pointer(pPager)).FpageSize)
			pData2 = pData
			rc = _write32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd, offset, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno)
			if rc == SQLITE_OK {
				rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd, pData2, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), offset+int64(4))
			}
		}
	}
	if rc == SQLITE_OK {
		(*TPager)(unsafe.Pointer(pPager)).FnSubRec++
		rc = _addToSavepointBitvecs(tls, pPager, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno)
	}
	return rc
}

func _subjournalPageIfRequired(tls *libc.TLS, pPg uintptr) (r int32) {
	if _subjRequiresPage(tls, pPg) != 0 {
		return _subjournalPage(tls, pPg)
	} else {
		return SQLITE_OK
	}
	return r
}

// C documentation
//
//	/*
//	** This function is called by the pcache layer when it has reached some
//	** soft memory limit. The first argument is a pointer to a Pager object
//	** (cast as a void*). The pager is always 'purgeable' (not an in-memory
//	** database). The second argument is a reference to a page that is
//	** currently dirty but has no outstanding references. The page
//	** is always associated with the Pager object passed as the first
//	** argument.
//	**
//	** The job of this function is to make pPg clean by writing its contents
//	** out to the database file, if possible. This may involve syncing the
//	** journal file.
//	**
//	** If successful, sqlite3PcacheMakeClean() is called on the page and
//	** SQLITE_OK returned. If an IO error occurs while trying to make the
//	** page clean, the IO error code is returned. If the page cannot be
//	** made clean for some other reason, but no error occurs, then SQLITE_OK
//	** is returned by sqlite3PcacheMakeClean() is not called.
//	*/
func _pagerStress(tls *libc.TLS, p uintptr, pPg uintptr) (r int32) {
	var pPager uintptr
	var rc int32
	_, _ = pPager, rc
	pPager = p
	rc = SQLITE_OK
	/* The doNotSpill NOSYNC bit is set during times when doing a sync of
	 ** journal (and adding a new header) is not allowed.  This occurs
	 ** during calls to sqlite3PagerWrite() while trying to journal multiple
	 ** pages belonging to the same sector.
	 **
	 ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
	 ** regardless of whether or not a sync is required.  This is set during
	 ** a rollback or by user request, respectively.
	 **
	 ** Spilling is also prohibited when in an error state since that could
	 ** lead to database corruption.   In the current implementation it
	 ** is impossible for sqlite3PcacheFetch() to be called with createFlag==3
	 ** while in the error state, hence it is impossible for this routine to
	 ** be called in the error state.  Nevertheless, we include a NEVER()
	 ** test for the error state as a safeguard against future changes.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return SQLITE_OK
	}
	if (*TPager)(unsafe.Pointer(pPager)).FdoNotSpill != 0 && (int32((*TPager)(unsafe.Pointer(pPager)).FdoNotSpill)&(libc.Int32FromInt32(SPILLFLAG_ROLLBACK)|libc.Int32FromInt32(SPILLFLAG_OFF)) != 0 || int32((*TPgHdr)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_NEED_SYNC) != 0) {
		return SQLITE_OK
	}
	*(*Tu32)(unsafe.Pointer(pPager + 200 + 3*4))++
	(*TPgHdr)(unsafe.Pointer(pPg)).FpDirty = uintptr(0)
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		/* Write a single frame for this page to the log. */
		rc = _subjournalPageIfRequired(tls, pPg)
		if rc == SQLITE_OK {
			rc = _pagerWalFrames(tls, pPager, pPg, uint32(0), 0)
		}
	} else {
		/* Sync the journal file if required. */
		if int32((*TPgHdr)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_NEED_SYNC) != 0 || int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_WRITER_CACHEMOD) {
			rc = _syncJournal(tls, pPager, int32(1))
		}
		/* Write the contents of the page out to the database file. */
		if rc == SQLITE_OK {
			rc = _pager_write_pagelist(tls, pPager, pPg)
		}
	}
	/* Mark the page as clean. */
	if rc == SQLITE_OK {
		_sqlite3PcacheMakeClean(tls, pPg)
	}
	return _pager_error(tls, pPager, rc)
}

// C documentation
//
//	/*
//	** Flush all unreferenced dirty pages to disk.
//	*/
func _sqlite3PagerFlush(tls *libc.TLS, pPager uintptr) (r int32) {
	var pList, pNext uintptr
	var rc int32
	_, _, _ = pList, pNext, rc
	rc = (*TPager)(unsafe.Pointer(pPager)).FerrCode
	if !((*TPager)(unsafe.Pointer(pPager)).FmemDb != 0) {
		pList = _sqlite3PcacheDirtyList(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
		for rc == SQLITE_OK && pList != 0 {
			pNext = (*TPgHdr)(unsafe.Pointer(pList)).FpDirty
			if (*TPgHdr)(unsafe.Pointer(pList)).FnRef == 0 {
				rc = _pagerStress(tls, pPager, pList)
			}
			pList = pNext
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Allocate and initialize a new Pager object and put a pointer to it
//	** in *ppPager. The pager should eventually be freed by passing it
//	** to sqlite3PagerClose().
//	**
//	** The zFilename argument is the path to the database file to open.
//	** If zFilename is NULL then a randomly-named temporary file is created
//	** and used as the file to be cached. Temporary files are be deleted
//	** automatically when they are closed. If zFilename is ":memory:" then
//	** all information is held in cache. It is never written to disk.
//	** This can be used to implement an in-memory database.
//	**
//	** The nExtra parameter specifies the number of bytes of space allocated
//	** along with each page reference. This space is available to the user
//	** via the sqlite3PagerGetExtra() API.  When a new page is allocated, the
//	** first 8 bytes of this space are zeroed but the remainder is uninitialized.
//	** (The extra space is used by btree as the MemPage object.)
//	**
//	** The flags argument is used to specify properties that affect the
//	** operation of the pager. It should be passed some bitwise combination
//	** of the PAGER_* flags.
//	**
//	** The vfsFlags parameter is a bitmask to pass to the flags parameter
//	** of the xOpen() method of the supplied VFS when opening files.
//	**
//	** If the pager object is allocated and the specified file opened
//	** successfully, SQLITE_OK is returned and *ppPager set to point to
//	** the new pager object. If an error occurs, *ppPager is set to NULL
//	** and error code returned. This function may return SQLITE_NOMEM
//	** (sqlite3Malloc() is used to allocate memory), SQLITE_CANTOPEN or
//	** various SQLITE_IO_XXX errors.
//	*/
func _sqlite3PagerOpen(tls *libc.TLS, pVfs uintptr, ppPager uintptr, zFilename uintptr, nExtra int32, flags int32, vfsFlags int32, xReinit uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iDc, journalFileSize, memDb, memJM, nPathname, nUriByte, pcacheSize, rc, readOnly, tempFile, useJournal, v4 int32
	var pPtr, z, zPathname, zUri, v1, v5 uintptr
	var _ /* fout at bp+8 */ int32
	var _ /* pPager at bp+0 */ uintptr
	var _ /* szPageDflt at bp+4 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = iDc, journalFileSize, memDb, memJM, nPathname, nUriByte, pPtr, pcacheSize, rc, readOnly, tempFile, useJournal, z, zPathname, zUri, v1, v4, v5
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)                        /* Pager object to allocate and return */
	rc = SQLITE_OK                                                      /* Return code */
	tempFile = 0                                                        /* True for temp files (incl. in-memory files) */
	memDb = 0                                                           /* True if this is an in-memory file */
	memJM = 0                                                           /* Memory journal mode */
	readOnly = 0                                                        /* Bytes to allocate for each journal fd */
	zPathname = uintptr(0)                                              /* Full path to database file */
	nPathname = 0                                                       /* Number of bytes in zPathname */
	useJournal = libc.BoolInt32(flags&int32(PAGER_OMIT_JOURNAL) == 0)   /* False to omit journal */
	pcacheSize = _sqlite3PcacheSize(tls)                                /* Bytes to allocate for PCache */
	*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(SQLITE_DEFAULT_PAGE_SIZE) /* Default page size */
	zUri = uintptr(0)                                                   /* URI args to copy */
	nUriByte = int32(1)                                                 /* Number of bytes of URI args at *zUri */
	/* Figure out how much space is required for each journal file-handle
	 ** (there are two of them, the main journal and the sub-journal).  */
	journalFileSize = (_sqlite3JournalSize(tls, pVfs) + int32(7)) & ^libc.Int32FromInt32(7)
	/* Set the output variable to NULL in case an error occurs. */
	*(*uintptr)(unsafe.Pointer(ppPager)) = uintptr(0)
	if flags&int32(PAGER_MEMORY) != 0 {
		memDb = int32(1)
		if zFilename != 0 && *(*int8)(unsafe.Pointer(zFilename)) != 0 {
			zPathname = _sqlite3DbStrDup(tls, uintptr(0), zFilename)
			if zPathname == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
			nPathname = _sqlite3Strlen30(tls, zPathname)
			zFilename = uintptr(0)
		}
	}
	/* Compute and store the full pathname in an allocated buffer pointed
	 ** to by zPathname, length nPathname. Or, if this is a temporary file,
	 ** leave both nPathname and zPathname set to 0.
	 */
	if zFilename != 0 && *(*int8)(unsafe.Pointer(zFilename)) != 0 {
		nPathname = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + int32(1)
		zPathname = _sqlite3DbMallocRaw(tls, uintptr(0), uint64(nPathname*int32(2)))
		if zPathname == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		*(*int8)(unsafe.Pointer(zPathname)) = 0 /* Make sure initialized even if FullPathname() fails */
		rc = _sqlite3OsFullPathname(tls, pVfs, zFilename, nPathname, zPathname)
		if rc != SQLITE_OK {
			if rc == libc.Int32FromInt32(SQLITE_OK)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
				if vfsFlags&int32(SQLITE_OPEN_NOFOLLOW) != 0 {
					rc = libc.Int32FromInt32(SQLITE_CANTOPEN) | libc.Int32FromInt32(6)<<libc.Int32FromInt32(8)
				} else {
					rc = SQLITE_OK
				}
			}
		}
		nPathname = _sqlite3Strlen30(tls, zPathname)
		v1 = zFilename + uintptr(_sqlite3Strlen30(tls, zFilename)+int32(1))
		zUri = v1
		z = v1
		for *(*int8)(unsafe.Pointer(z)) != 0 {
			z += uintptr(libc.Xstrlen(tls, z) + uint32(1))
			z += uintptr(libc.Xstrlen(tls, z) + uint32(1))
		}
		nUriByte = t__predefined_ptrdiff_t(z+1) - int32(int32(zUri))
		if rc == SQLITE_OK && nPathname+int32(8) > (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname {
			/* This branch is taken when the journal path required by
			 ** the database being opened will be more than pVfs->mxPathname
			 ** bytes in length. This means the database cannot be opened,
			 ** as it will not be possible to open the journal file or even
			 ** check for a hot-journal before reading.
			 */
			rc = _sqlite3CantopenError(tls, int32(61898))
		}
		if rc != SQLITE_OK {
			_sqlite3DbFree(tls, uintptr(0), zPathname)
			return rc
		}
	}
	/* Allocate memory for the Pager structure, PCache object, the
	 ** three file descriptors, the database file name and the journal
	 ** file name. The layout in memory is as follows:
	 **
	 **     Pager object                    (sizeof(Pager) bytes)
	 **     PCache object                   (sqlite3PcacheSize() bytes)
	 **     Database file handle            (pVfs->szOsFile bytes)
	 **     Sub-journal file handle         (journalFileSize bytes)
	 **     Main journal file handle        (journalFileSize bytes)
	 **     Ptr back to the Pager           (sizeof(Pager*) bytes)
	 **     \0\0\0\0 database prefix        (4 bytes)
	 **     Database file name              (nPathname+1 bytes)
	 **     URI query parameters            (nUriByte bytes)
	 **     Journal filename                (nPathname+8+1 bytes)
	 **     WAL filename                    (nPathname+4+1 bytes)
	 **     \0\0\0 terminator               (3 bytes)
	 **
	 ** Some 3rd-party software, over which we have no control, depends on
	 ** the specific order of the filenames and the \0 separators between them
	 ** so that it can (for example) find the database filename given the WAL
	 ** filename without using the sqlite3_filename_database() API.  This is a
	 ** misuse of SQLite and a bug in the 3rd-party software, but the 3rd-party
	 ** software is in widespread use, so we try to avoid changing the filename
	 ** order and formatting if possible.  In particular, the details of the
	 ** filename format expected by 3rd-party software should be as follows:
	 **
	 **   - Main Database Path
	 **   - \0
	 **   - Multiple URI components consisting of:
	 **     - Key
	 **     - \0
	 **     - Value
	 **     - \0
	 **   - \0
	 **   - Journal Path
	 **   - \0
	 **   - WAL Path (zWALName)
	 **   - \0
	 **
	 ** The sqlite3_create_filename() interface and the databaseFilename() utility
	 ** that is used by sqlite3_filename_database() and kin also depend on the
	 ** specific formatting and order of the various filenames, so if the format
	 ** changes here, be sure to change it there as well.
	 */
	pPtr = _sqlite3MallocZero(tls, uint64((libc.Uint32FromInt64(240)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7))+uint32((pcacheSize+libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))+uint32(((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile+libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))+uint32(journalFileSize*int32(2))+uint32(__SIZEOF_POINTER__)+uint32(4)+uint32(uint32(nPathname))+uint32(1)+uint32(uint32(nUriByte))+uint32(uint32(nPathname))+uint32(8)+uint32(1)+uint32(uint32(nPathname))+uint32(4)+uint32(1)+uint32(3)))
	if !(pPtr != 0) {
		_sqlite3DbFree(tls, uintptr(0), zPathname)
		return int32(SQLITE_NOMEM)
	}
	*(*uintptr)(unsafe.Pointer(bp)) = pPtr
	pPtr += uintptr((libc.Uint32FromInt64(240) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpPCache = pPtr
	pPtr += uintptr((pcacheSize + libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd = pPtr
	pPtr += uintptr(((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile + libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fsjfd = pPtr
	pPtr += uintptr(journalFileSize)
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fjfd = pPtr
	pPtr += uintptr(journalFileSize)
	libc.Xmemcpy(tls, pPtr, bp, uint32(__SIZEOF_POINTER__))
	pPtr += uintptr(__SIZEOF_POINTER__)
	/* Fill in the Pager.zFilename and pPager.zQueryParam fields */
	pPtr += uintptr(4) /* Skip zero prefix */
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename = pPtr
	if nPathname > 0 {
		libc.Xmemcpy(tls, pPtr, zPathname, uint32(uint32(nPathname)))
		pPtr += uintptr(nPathname + int32(1))
		if zUri != 0 {
			libc.Xmemcpy(tls, pPtr, zUri, uint32(uint32(nUriByte)))
			pPtr += uintptr(nUriByte)
		} else {
			pPtr++
		}
	}
	/* Fill in Pager.zJournal */
	if nPathname > 0 {
		(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzJournal = pPtr
		libc.Xmemcpy(tls, pPtr, zPathname, uint32(uint32(nPathname)))
		pPtr += uintptr(nPathname)
		libc.Xmemcpy(tls, pPtr, __ccgo_ts+5451, uint32(8))
		pPtr += uintptr(libc.Int32FromInt32(8) + libc.Int32FromInt32(1))
	} else {
		(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzJournal = uintptr(0)
	}
	/* Fill in Pager.zWal */
	if nPathname > 0 {
		(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzWal = pPtr
		libc.Xmemcpy(tls, pPtr, zPathname, uint32(uint32(nPathname)))
		pPtr += uintptr(nPathname)
		libc.Xmemcpy(tls, pPtr, __ccgo_ts+5460, uint32(4))
		pPtr += uintptr(libc.Int32FromInt32(4) + libc.Int32FromInt32(1))
	} else {
		(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzWal = uintptr(0)
	}
	_ = pPtr /* Suppress warning about unused pPtr value */
	if nPathname != 0 {
		_sqlite3DbFree(tls, uintptr(0), zPathname)
	}
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpVfs = pVfs
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FvfsFlags = uint32(uint32(vfsFlags))
	/* Open the pager file.
	 */
	if !(zFilename != 0 && *(*int8)(unsafe.Pointer(zFilename)) != 0) {
		goto _2
	}
	*(*int32)(unsafe.Pointer(bp + 8)) = 0 /* VFS flags returned by xOpen() */
	rc = _sqlite3OsOpen(tls, pVfs, (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename, (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd, vfsFlags, bp+8)
	v4 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp + 8))&libc.Int32FromInt32(SQLITE_OPEN_MEMORY) != libc.Int32FromInt32(0))
	memJM = v4
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmemVfs = uint8(v4)
	readOnly = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp + 8))&int32(SQLITE_OPEN_READONLY) != 0)
	/* If the file was successfully opened for read/write access,
	 ** choose a default page size in case we have to create the
	 ** database file. The default page size is the maximum of:
	 **
	 **    + SQLITE_DEFAULT_PAGE_SIZE,
	 **    + The value returned by sqlite3OsSectorSize()
	 **    + The largest page size that can be written atomically.
	 */
	if rc == SQLITE_OK {
		iDc = _sqlite3OsDeviceCharacteristics(tls, (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd)
		if !(readOnly != 0) {
			_setSectorSize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			if *(*Tu32)(unsafe.Pointer(bp + 4)) < (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FsectorSize {
				if (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FsectorSize > uint32(SQLITE_MAX_DEFAULT_PAGE_SIZE) {
					*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(SQLITE_MAX_DEFAULT_PAGE_SIZE)
				} else {
					*(*Tu32)(unsafe.Pointer(bp + 4)) = (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FsectorSize
				}
			}
		}
		(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnoLock = uint8(Xsqlite3_uri_boolean(tls, (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename, __ccgo_ts+5465, 0))
		if iDc&int32(SQLITE_IOCAP_IMMUTABLE) != 0 || Xsqlite3_uri_boolean(tls, (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename, __ccgo_ts+5472, 0) != 0 {
			vfsFlags |= int32(SQLITE_OPEN_READONLY)
			goto act_like_temp_file
		}
	}
	goto _3
_2:
	;
	/* If a temporary file is requested, it is not opened immediately.
	 ** In this case we accept the default page size and delay actually
	 ** opening the file until the first call to OsWrite().
	 **
	 ** This branch is also run for an in-memory database. An in-memory
	 ** database is the same as a temp-file that is never written out to
	 ** disk and uses an in-memory rollback journal.
	 **
	 ** This branch also runs for files marked as immutable.
	 */
	goto act_like_temp_file
act_like_temp_file:
	;
	tempFile = int32(1)
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FeState = uint8(PAGER_READER)  /* Pretend we already have a lock */
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FeLock = uint8(EXCLUSIVE_LOCK) /* Pretend we are in EXCLUSIVE mode */
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnoLock = uint8(1)             /* Do no locking */
	readOnly = vfsFlags & int32(SQLITE_OPEN_READONLY)
_3:
	;
	/* The following call to PagerSetPagesize() serves to set the value of
	 ** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
	 */
	if rc == SQLITE_OK {
		rc = _sqlite3PagerSetPagesize(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+4, -int32(1))
	}
	/* Initialize the PCache object. */
	if rc == SQLITE_OK {
		nExtra = (nExtra + int32(7)) & ^libc.Int32FromInt32(7)
		if !(memDb != 0) {
			v5 = __ccgo_fp(_pagerStress)
		} else {
			v5 = uintptr(0)
		}
		rc = _sqlite3PcacheOpen(tls, int32(*(*Tu32)(unsafe.Pointer(bp + 4))), nExtra, libc.BoolInt32(!(memDb != 0)), v5, *(*uintptr)(unsafe.Pointer(bp)), (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpPCache)
	}
	/* If an error occurred above, free the  Pager structure and close the file.
	 */
	if rc != SQLITE_OK {
		_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd)
		_sqlite3PageFree(tls, (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpTmpSpace)
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return rc
	}
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FuseJournal = uint8(uint8(useJournal))
	/* pPager->stmtOpen = 0; */
	/* pPager->stmtInUse = 0; */
	/* pPager->nRef = 0; */
	/* pPager->stmtSize = 0; */
	/* pPager->stmtJSize = 0; */
	/* pPager->nPage = 0; */
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmxPgno = uint32(SQLITE_MAX_PAGE_COUNT)
	/* pPager->state = PAGER_UNLOCK; */
	/* pPager->errMask = 0; */
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FtempFile = uint8(uint8(tempFile))
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FexclusiveMode = uint8(uint8(tempFile))
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FchangeCountDone = (*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FtempFile
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmemDb = uint8(uint8(memDb))
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FreadOnly = uint8(uint8(readOnly))
	_sqlite3PagerSetFlags(tls, *(*uintptr)(unsafe.Pointer(bp)), uint32(libc.Int32FromInt32(SQLITE_DEFAULT_SYNCHRONOUS)+libc.Int32FromInt32(1)|libc.Int32FromInt32(PAGER_CACHESPILL)))
	/* pPager->pFirst = 0; */
	/* pPager->pFirstSynced = 0; */
	/* pPager->pLast = 0; */
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnExtra = uint16(uint16(nExtra))
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FjournalSizeLimit = int64(-int32(1))
	_setSectorSize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if !(useJournal != 0) {
		(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FjournalMode = uint8(PAGER_JOURNALMODE_OFF)
	} else {
		if memDb != 0 || memJM != 0 {
			(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FjournalMode = uint8(PAGER_JOURNALMODE_MEMORY)
		}
	}
	/* pPager->xBusyHandler = 0; */
	/* pPager->pBusyHandlerArg = 0; */
	(*TPager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxReiniter = xReinit
	_setGetterMethod(tls, *(*uintptr)(unsafe.Pointer(bp)))
	/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
	/* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
	*(*uintptr)(unsafe.Pointer(ppPager)) = *(*uintptr)(unsafe.Pointer(bp))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the sqlite3_file for the main database given the name
//	** of the corresponding WAL or Journal name as passed into
//	** xOpen.
//	*/
func Xsqlite3_database_file_object(tls *libc.TLS, zName uintptr) (r uintptr) {
	var p, pPager uintptr
	_, _ = p, pPager
	for int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(1))))) != 0 || int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(2))))) != 0 || int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(3))))) != 0 || int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(4))))) != 0 {
		zName--
	}
	p = zName - uintptr(4) - uintptr(4)
	pPager = *(*uintptr)(unsafe.Pointer(p))
	return (*TPager)(unsafe.Pointer(pPager)).Ffd
}

// C documentation
//
//	/*
//	** This function is called after transitioning from PAGER_UNLOCK to
//	** PAGER_SHARED state. It tests if there is a hot journal present in
//	** the file-system for the given pager. A hot journal is one that
//	** needs to be played back. According to this function, a hot-journal
//	** file exists if the following criteria are met:
//	**
//	**   * The journal file exists in the file system, and
//	**   * No process holds a RESERVED or greater lock on the database file, and
//	**   * The database file itself is greater than 0 bytes in size, and
//	**   * The first byte of the journal file exists and is not 0x00.
//	**
//	** If the current size of the database file is 0 but a journal file
//	** exists, that is probably an old journal left over from a prior
//	** database with the same name. In this case the journal file is
//	** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
//	** is returned.
//	**
//	** This routine does not check if there is a super-journal filename
//	** at the end of the file. If there is, and that super-journal file
//	** does not exist, then the journal file is not really hot. In this
//	** case this routine will return a false-positive. The pager_playback()
//	** routine will discover that the journal file is not really hot and
//	** will not roll it back.
//	**
//	** If a hot-journal file is found to exist, *pExists is set to 1 and
//	** SQLITE_OK returned. If no hot-journal file is present, *pExists is
//	** set to 0 and SQLITE_OK returned. If an IO error occurs while trying
//	** to determine whether or not a hot-journal file exists, the IO error
//	** code is returned and the value of *pExists is undefined.
//	*/
func _hasHotJournal(tls *libc.TLS, pPager uintptr, pExists uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var jrnlOpen, rc int32
	var pVfs uintptr
	var _ /* exists at bp+0 */ int32
	var _ /* f at bp+12 */ int32
	var _ /* first at bp+16 */ Tu8
	var _ /* locked at bp+4 */ int32
	var _ /* nPage at bp+8 */ TPgno
	_, _, _ = jrnlOpen, pVfs, rc
	pVfs = (*TPager)(unsafe.Pointer(pPager)).FpVfs
	rc = SQLITE_OK                           /* Return code */
	*(*int32)(unsafe.Pointer(bp)) = int32(1) /* True if a journal file is present */
	jrnlOpen = libc.BoolInt32(!!((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != libc.UintptrFromInt32(0)))
	*(*int32)(unsafe.Pointer(pExists)) = 0
	if !(jrnlOpen != 0) {
		rc = _sqlite3OsAccess(tls, pVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, SQLITE_ACCESS_EXISTS, bp)
	}
	if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
		*(*int32)(unsafe.Pointer(bp + 4)) = 0 /* True if some process holds a RESERVED lock */
		/* Race condition here:  Another process might have been holding the
		 ** the RESERVED lock and have a journal open at the sqlite3OsAccess()
		 ** call above, but then delete the journal and drop the lock before
		 ** we get to the following sqlite3OsCheckReservedLock() call.  If that
		 ** is the case, this routine might think there is a hot journal when
		 ** in fact there is none.  This results in a false-positive which will
		 ** be dealt with by the playback routine.  Ticket #3883.
		 */
		rc = _sqlite3OsCheckReservedLock(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, bp+4)
		if rc == SQLITE_OK && !(*(*int32)(unsafe.Pointer(bp + 4)) != 0) { /* Number of pages in database file */
			rc = _pagerPagecount(tls, pPager, bp+8)
			if rc == SQLITE_OK {
				/* If the database is zero pages in size, that means that either (1) the
				 ** journal is a remnant from a prior database with the same name where
				 ** the database file but not the journal was deleted, or (2) the initial
				 ** transaction that populates a new database is being rolled back.
				 ** In either case, the journal file can be deleted.  However, take care
				 ** not to delete the journal file if it is already open due to
				 ** journal_mode=PERSIST.
				 */
				if *(*TPgno)(unsafe.Pointer(bp + 8)) == uint32(0) && !(jrnlOpen != 0) {
					_sqlite3BeginBenignMalloc(tls)
					if _pagerLockDb(tls, pPager, int32(RESERVED_LOCK)) == SQLITE_OK {
						_sqlite3OsDelete(tls, pVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, 0)
						if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) {
							_pagerUnlockDb(tls, pPager, int32(SHARED_LOCK))
						}
					}
					_sqlite3EndBenignMalloc(tls)
				} else {
					/* The journal file exists and no other connection has a reserved
					 ** or greater lock on the database file. Now check that there is
					 ** at least one non-zero bytes at the start of the journal file.
					 ** If there is, then we consider this journal to be hot. If not,
					 ** it can be ignored.
					 */
					if !(jrnlOpen != 0) {
						*(*int32)(unsafe.Pointer(bp + 12)) = libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_JOURNAL)
						rc = _sqlite3OsOpen(tls, pVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, (*TPager)(unsafe.Pointer(pPager)).Fjfd, *(*int32)(unsafe.Pointer(bp + 12)), bp+12)
					}
					if rc == SQLITE_OK {
						*(*Tu8)(unsafe.Pointer(bp + 16)) = uint8(0)
						rc = _sqlite3OsRead(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp+16, int32(1), 0)
						if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
							rc = SQLITE_OK
						}
						if !(jrnlOpen != 0) {
							_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
						}
						*(*int32)(unsafe.Pointer(pExists)) = libc.BoolInt32(int32(*(*Tu8)(unsafe.Pointer(bp + 16))) != 0)
					} else {
						if rc == int32(SQLITE_CANTOPEN) {
							/* If we cannot open the rollback journal file in order to see if
							 ** it has a zero header, that might be due to an I/O error, or
							 ** it might be due to the race condition described above and in
							 ** ticket #3883.  Either way, assume that the journal is hot.
							 ** This might be a false positive.  But if it is, then the
							 ** automatic journal playback and recovery mechanism will deal
							 ** with it under an EXCLUSIVE lock where we do not need to
							 ** worry so much with race conditions.
							 */
							*(*int32)(unsafe.Pointer(pExists)) = int32(1)
							rc = SQLITE_OK
						}
					}
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called to obtain a shared lock on the database file.
//	** It is illegal to call sqlite3PagerGet() until after this function
//	** has been successfully called. If a shared-lock is already held when
//	** this function is called, it is a no-op.
//	**
//	** The following operations are also performed by this function.
//	**
//	**   1) If the pager is currently in PAGER_OPEN state (no lock held
//	**      on the database file), then an attempt is made to obtain a
//	**      SHARED lock on the database file. Immediately after obtaining
//	**      the SHARED lock, the file-system is checked for a hot-journal,
//	**      which is played back if present. Following any hot-journal
//	**      rollback, the contents of the cache are validated by checking
//	**      the 'change-counter' field of the database file header and
//	**      discarded if they are found to be invalid.
//	**
//	**   2) If the pager is running in exclusive-mode, and there are currently
//	**      no outstanding references to any pages, and is in the error state,
//	**      then an attempt is made to clear the error state by discarding
//	**      the contents of the page cache and rolling back any open journal
//	**      file.
//	**
//	** If everything is successful, SQLITE_OK is returned. If an IO error
//	** occurs while locking the database, checking for a hot-journal file or
//	** rolling back a journal file, the IO error code is returned.
//	*/
func _sqlite3PagerSharedLock(tls *libc.TLS, pPager uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var f, rc int32
	var pVfs uintptr
	var _ /* bExists at bp+4 */ int32
	var _ /* bHotJournal at bp+0 */ int32
	var _ /* dbFileVers at bp+12 */ [16]int8
	var _ /* fout at bp+8 */ int32
	_, _, _ = f, pVfs, rc
	rc = SQLITE_OK /* Return code */
	/* This routine is only called from b-tree and only when there are no
	 ** outstanding pages. This implies that the pager state should either
	 ** be OPEN or READER. READER is only possible if the pager is or was in
	 ** exclusive access mode.  */
	if !((*TPager)(unsafe.Pointer(pPager)).FpWal != libc.UintptrFromInt32(0)) && int32((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN {
		*(*int32)(unsafe.Pointer(bp)) = int32(1) /* True if there exists a hot journal-file */
		rc = _pager_wait_on_lock(tls, pPager, int32(SHARED_LOCK))
		if rc != SQLITE_OK {
			goto failed
		}
		/* If a journal file exists, and there is no RESERVED lock on the
		 ** database file, then it either needs to be played back or deleted.
		 */
		if int32((*TPager)(unsafe.Pointer(pPager)).FeLock) <= int32(SHARED_LOCK) {
			rc = _hasHotJournal(tls, pPager, bp)
		}
		if rc != SQLITE_OK {
			goto failed
		}
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			if (*TPager)(unsafe.Pointer(pPager)).FreadOnly != 0 {
				rc = libc.Int32FromInt32(SQLITE_READONLY) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
				goto failed
			}
			/* Get an EXCLUSIVE lock on the database file. At this point it is
			 ** important that a RESERVED lock is not obtained on the way to the
			 ** EXCLUSIVE lock. If it were, another process might open the
			 ** database file, detect the RESERVED lock, and conclude that the
			 ** database is safe to read while this process is still rolling the
			 ** hot-journal back.
			 **
			 ** Because the intermediate RESERVED lock is not requested, any
			 ** other process attempting to access the database file will get to
			 ** this point in the code and fail to obtain its own EXCLUSIVE lock
			 ** on the database file.
			 **
			 ** Unless the pager is in locking_mode=exclusive mode, the lock is
			 ** downgraded to SHARED_LOCK before this function returns.
			 */
			rc = _pagerLockDb(tls, pPager, int32(EXCLUSIVE_LOCK))
			if rc != SQLITE_OK {
				goto failed
			}
			/* If it is not already open and the file exists on disk, open the
			 ** journal for read/write access. Write access is required because
			 ** in exclusive-access mode the file descriptor will be kept open
			 ** and possibly used for a transaction later on. Also, write-access
			 ** is usually required to finalize the journal in journal_mode=persist
			 ** mode (and also for journal_mode=truncate on some systems).
			 **
			 ** If the journal does not exist, it usually means that some
			 ** other connection managed to get in and roll it back before
			 ** this connection obtained the exclusive lock above. Or, it
			 ** may mean that the pager was in the error-state when this
			 ** function was called and the journal file does not exist.
			 */
			if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != libc.UintptrFromInt32(0)) && int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) != int32(PAGER_JOURNALMODE_OFF) {
				pVfs = (*TPager)(unsafe.Pointer(pPager)).FpVfs /* True if journal file exists */
				rc = _sqlite3OsAccess(tls, pVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, SQLITE_ACCESS_EXISTS, bp+4)
				if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
					*(*int32)(unsafe.Pointer(bp + 8)) = 0
					f = libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_JOURNAL)
					rc = _sqlite3OsOpen(tls, pVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, (*TPager)(unsafe.Pointer(pPager)).Fjfd, f, bp+8)
					if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 8))&int32(SQLITE_OPEN_READONLY) != 0 {
						rc = _sqlite3CantopenError(tls, int32(62419))
						_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
					}
				}
			}
			/* Playback and delete the journal.  Drop the database write
			 ** lock and reacquire the read lock. Purge the cache before
			 ** playing back the hot-journal so that we don't end up with
			 ** an inconsistent cache.  Sync the hot journal before playing
			 ** it back since the process that crashed and left the hot journal
			 ** probably did not sync it and we are required to always sync
			 ** the journal before playing it back.
			 */
			if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
				rc = _pagerSyncHotJournal(tls, pPager)
				if rc == SQLITE_OK {
					rc = _pager_playback(tls, pPager, libc.BoolInt32(!((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0)))
					(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_OPEN)
				}
			} else {
				if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) {
					_pagerUnlockDb(tls, pPager, int32(SHARED_LOCK))
				}
			}
			if rc != SQLITE_OK {
				/* This branch is taken if an error occurs while trying to open
				 ** or roll back a hot-journal while holding an EXCLUSIVE lock. The
				 ** pager_unlock() routine will be called before returning to unlock
				 ** the file. If the unlock attempt fails, then Pager.eLock must be
				 ** set to UNKNOWN_LOCK (see the comment above the #define for
				 ** UNKNOWN_LOCK above for an explanation).
				 **
				 ** In order to get pager_unlock() to do this, set Pager.eState to
				 ** PAGER_ERROR now. This is not actually counted as a transition
				 ** to ERROR state in the state diagram at the top of this file,
				 ** since we know that the same call to pager_unlock() will very
				 ** shortly transition the pager object to the OPEN state. Calling
				 ** assert_pager_state() would fail now, as it should not be possible
				 ** to be in ERROR state when there are zero outstanding page
				 ** references.
				 */
				_pager_error(tls, pPager, rc)
				goto failed
			}
		}
		if !((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0) && (*TPager)(unsafe.Pointer(pPager)).FhasHeldSharedLock != 0 {
			rc = _sqlite3OsRead(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, bp+12, int32(16), int64(24))
			if rc != SQLITE_OK {
				if rc != libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
					goto failed
				}
				libc.Xmemset(tls, bp+12, 0, uint32(16))
			}
			if libc.Xmemcmp(tls, pPager+112, bp+12, uint32(16)) != 0 {
				_pager_reset(tls, pPager)
				/* Unmap the database file. It is possible that external processes
				 ** may have truncated the database file and then extended it back
				 ** to its original size while this process was not holding a lock.
				 ** In this case there may exist a Pager.pMap mapping that appears
				 ** to be the right size but is not actually valid. Avoid this
				 ** possibility by unmapping the db here. */
				if (*TPager)(unsafe.Pointer(pPager)).FbUseFetch != 0 {
					_sqlite3OsUnfetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, 0, uintptr(0))
				}
			}
		}
		/* If there is a WAL file in the file-system, open this database in WAL
		 ** mode. Otherwise, the following function call is a no-op.
		 */
		rc = _pagerOpenWalIfPresent(tls, pPager)
	}
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc = _pagerBeginReadTransaction(tls, pPager)
	}
	if int32((*TPager)(unsafe.Pointer(pPager)).FtempFile) == 0 && int32((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN && rc == SQLITE_OK {
		rc = _pagerPagecount(tls, pPager, pPager+28)
	}
	goto failed
failed:
	;
	if rc != SQLITE_OK {
		_pager_unlock(tls, pPager)
	} else {
		(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_READER)
		(*TPager)(unsafe.Pointer(pPager)).FhasHeldSharedLock = uint8(1)
	}
	return rc
}

// C documentation
//
//	/*
//	** If the reference count has reached zero, rollback any active
//	** transaction and unlock the pager.
//	**
//	** Except, in locking_mode=EXCLUSIVE when there is nothing to in
//	** the rollback journal, the unlock is not performed and there is
//	** nothing to rollback, so this routine is a no-op.
//	*/
func _pagerUnlockIfUnused(tls *libc.TLS, pPager uintptr) {
	if _sqlite3PcacheRefCount(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache) == 0 {
		/* because page1 is never memory mapped */
		_pagerUnlockAndRollback(tls, pPager)
	}
}

// C documentation
//
//	/*
//	** The page getter methods each try to acquire a reference to a
//	** page with page number pgno. If the requested reference is
//	** successfully obtained, it is copied to *ppPage and SQLITE_OK returned.
//	**
//	** There are different implementations of the getter method depending
//	** on the current state of the pager.
//	**
//	**     getPageNormal()         --  The normal getter
//	**     getPageError()          --  Used if the pager is in an error state
//	**     getPageMmap()           --  Used if memory-mapped I/O is enabled
//	**
//	** If the requested page is already in the cache, it is returned.
//	** Otherwise, a new page object is allocated and populated with data
//	** read from the database file. In some cases, the pcache module may
//	** choose not to allocate a new page object and may reuse an existing
//	** object with no outstanding references.
//	**
//	** The extra data appended to a page is always initialized to zeros the
//	** first time a page is loaded into memory. If the page requested is
//	** already in the cache when this function is called, then the extra
//	** data is left as it was when the page object was last used.
//	**
//	** If the database image is smaller than the requested page or if
//	** the flags parameter contains the PAGER_GET_NOCONTENT bit and the
//	** requested page is not already stored in the cache, then no
//	** actual disk read occurs. In this case the memory image of the
//	** page is initialized to all zeros.
//	**
//	** If PAGER_GET_NOCONTENT is true, it means that we do not care about
//	** the contents of the page. This occurs in two scenarios:
//	**
//	**   a) When reading a free-list leaf page from the database, and
//	**
//	**   b) When a savepoint is being rolled back and we need to load
//	**      a new page into the cache to be filled with the data read
//	**      from the savepoint journal.
//	**
//	** If PAGER_GET_NOCONTENT is true, then the data returned is zeroed instead
//	** of being read from the database. Additionally, the bits corresponding
//	** to pgno in Pager.pInJournal (bitvec of pages already written to the
//	** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
//	** savepoints are set. This means if the page is made writable at any
//	** point in the future, using a call to sqlite3PagerWrite(), its contents
//	** will not be journaled. This saves IO.
//	**
//	** The acquisition might fail for several reasons.  In all cases,
//	** an appropriate error code is returned and *ppPage is set to NULL.
//	**
//	** See also sqlite3PagerLookup().  Both this routine and Lookup() attempt
//	** to find a page in the in-memory cache first.  If the page is not already
//	** in memory, this routine goes to disk to read it in whereas Lookup()
//	** just returns 0.  This routine acquires a read-lock the first time it
//	** has to go to disk, and could also playback an old journal if necessary.
//	** Since Lookup() never goes to disk, it never has to deal with locks
//	** or journal files.
//	*/
func _getPageNormal(tls *libc.TLS, pPager uintptr, pgno TPgno, ppPage uintptr, flags int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var noContent Tu8
	var pPg, v1 uintptr
	var rc int32
	var _ /* pBase at bp+0 */ uintptr
	_, _, _, _ = noContent, pPg, rc, v1
	rc = SQLITE_OK
	if pgno == uint32(0) {
		return _sqlite3CorruptError(tls, int32(62632))
	}
	*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3PcacheFetch(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, pgno, int32(3))
	if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
		pPg = uintptr(0)
		rc = _sqlite3PcacheFetchStress(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, pgno, bp)
		if rc != SQLITE_OK {
			goto pager_acquire_err
		}
		if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
			goto pager_acquire_err
		}
	}
	v1 = _sqlite3PcacheFetchFinish(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, pgno, *(*uintptr)(unsafe.Pointer(bp)))
	*(*uintptr)(unsafe.Pointer(ppPage)) = v1
	pPg = v1
	noContent = libc.BoolUint8(flags&int32(PAGER_GET_NOCONTENT) != 0)
	if (*TPgHdr)(unsafe.Pointer(pPg)).FpPager != 0 && !(noContent != 0) {
		/* In this case the pcache already contains an initialized copy of
		 ** the page. Return without further ado.  */
		*(*Tu32)(unsafe.Pointer(pPager + 200))++
		return SQLITE_OK
	} else {
		/* The pager cache has created a new page. Its content needs to
		 ** be initialized. But first some error checks:
		 **
		 ** (*) obsolete.  Was: maximum page number is 2^31
		 ** (2) Never try to fetch the locking page
		 */
		if pgno == (*TPager)(unsafe.Pointer(pPager)).FlckPgno {
			rc = _sqlite3CorruptError(tls, int32(62664))
			goto pager_acquire_err
		}
		(*TPgHdr)(unsafe.Pointer(pPg)).FpPager = pPager
		if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != libc.UintptrFromInt32(0)) || (*TPager)(unsafe.Pointer(pPager)).FdbSize < pgno || noContent != 0 {
			if pgno > (*TPager)(unsafe.Pointer(pPager)).FmxPgno {
				rc = int32(SQLITE_FULL)
				if pgno <= (*TPager)(unsafe.Pointer(pPager)).FdbSize {
					_sqlite3PcacheRelease(tls, pPg)
					pPg = uintptr(0)
				}
				goto pager_acquire_err
			}
			if noContent != 0 {
				/* Failure to set the bits in the InJournal bit-vectors is benign.
				 ** It merely means that we might do some extra work to journal a
				 ** page that does not need to be journaled.  Nevertheless, be sure
				 ** to test the case where a malloc error occurs while trying to set
				 ** a bit in a bit vector.
				 */
				_sqlite3BeginBenignMalloc(tls)
				if pgno <= (*TPager)(unsafe.Pointer(pPager)).FdbOrigSize {
					_sqlite3BitvecSet(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal, pgno)
				}
				_addToSavepointBitvecs(tls, pPager, pgno)
				_sqlite3EndBenignMalloc(tls)
			}
			libc.Xmemset(tls, (*TPgHdr)(unsafe.Pointer(pPg)).FpData, 0, uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize))
		} else {
			*(*Tu32)(unsafe.Pointer(pPager + 200 + 1*4))++
			rc = _readDbPage(tls, pPg)
			if rc != SQLITE_OK {
				goto pager_acquire_err
			}
		}
	}
	return SQLITE_OK
	goto pager_acquire_err
pager_acquire_err:
	;
	if pPg != 0 {
		_sqlite3PcacheDrop(tls, pPg)
	}
	_pagerUnlockIfUnused(tls, pPager)
	*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
	return rc
}

// C documentation
//
//	/* The page getter for when memory-mapped I/O is enabled */
func _getPageMMap(tls *libc.TLS, pPager uintptr, pgno TPgno, ppPage uintptr, flags int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bMmapOk, rc int32
	var _ /* iFrame at bp+4 */ Tu32
	var _ /* pData at bp+8 */ uintptr
	var _ /* pPg at bp+0 */ uintptr
	_, _ = bMmapOk, rc
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0) /* Frame to read from WAL file */
	/* It is acceptable to use a read-only (mmap) page for any page except
	 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
	 ** flag was specified by the caller. And so long as the db is not a
	 ** temporary or in-memory database.  */
	bMmapOk = libc.BoolInt32(pgno > uint32(1) && (int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_READER) || flags&int32(PAGER_GET_READONLY) != 0))
	/* Optimization note:  Adding the "pgno<=1" term before "pgno==0" here
	 ** allows the compiler optimizer to reuse the results of the "pgno>1"
	 ** test in the previous statement, and avoid testing pgno==0 in the
	 ** common case where pgno is large. */
	if pgno <= uint32(1) && pgno == uint32(0) {
		return _sqlite3CorruptError(tls, int32(62747))
	}
	if bMmapOk != 0 && (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc = _sqlite3WalFindFrame(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, pgno, bp+4)
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return rc
		}
	}
	if bMmapOk != 0 && *(*Tu32)(unsafe.Pointer(bp + 4)) == uint32(0) {
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		rc = _sqlite3OsFetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int64(pgno-libc.Uint32FromInt32(1))*(*TPager)(unsafe.Pointer(pPager)).FpageSize, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), bp+8)
		if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
			if int32((*TPager)(unsafe.Pointer(pPager)).FeState) > int32(PAGER_READER) || (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 {
				*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3PagerLookup(tls, pPager, pgno)
			}
			if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
				rc = _pagerAcquireMapPage(tls, pPager, pgno, *(*uintptr)(unsafe.Pointer(bp + 8)), bp)
			} else {
				_sqlite3OsUnfetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int64(pgno-libc.Uint32FromInt32(1))*(*TPager)(unsafe.Pointer(pPager)).FpageSize, *(*uintptr)(unsafe.Pointer(bp + 8)))
			}
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp))
				return SQLITE_OK
			}
		}
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return rc
		}
	}
	return _getPageNormal(tls, pPager, pgno, ppPage, flags)
}

// C documentation
//
//	/* The page getter method for when the pager is an error state */
func _getPageError(tls *libc.TLS, pPager uintptr, pgno TPgno, ppPage uintptr, flags int32) (r int32) {
	_ = pgno
	_ = flags
	*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
	return (*TPager)(unsafe.Pointer(pPager)).FerrCode
}

// C documentation
//
//	/* Dispatch all page fetch requests to the appropriate getter method.
//	*/
func _sqlite3PagerGet(tls *libc.TLS, pPager uintptr, pgno TPgno, ppPage uintptr, flags int32) (r int32) {
	/* Normal, high-speed version of sqlite3PagerGet() */
	return (*(*func(*libc.TLS, uintptr, TPgno, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPager)(unsafe.Pointer(pPager)).FxGet})))(tls, pPager, pgno, ppPage, flags)
}

// C documentation
//
//	/*
//	** Acquire a page if it is already in the in-memory cache.  Do
//	** not read the page from disk.  Return a pointer to the page,
//	** or 0 if the page is not in cache.
//	**
//	** See also sqlite3PagerGet().  The difference between this routine
//	** and sqlite3PagerGet() is that _get() will go to the disk and read
//	** in the page if the page is not already in cache.  This routine
//	** returns NULL if the page is not in cache or if a disk I/O error
//	** has ever happened.
//	*/
func _sqlite3PagerLookup(tls *libc.TLS, pPager uintptr, pgno TPgno) (r uintptr) {
	var pPage uintptr
	_ = pPage
	pPage = _sqlite3PcacheFetch(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, pgno, 0)
	if pPage == uintptr(0) {
		return uintptr(0)
	}
	return _sqlite3PcacheFetchFinish(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache, pgno, pPage)
}

// C documentation
//
//	/*
//	** Release a page reference.
//	**
//	** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be used
//	** if we know that the page being released is not the last reference to page1.
//	** The btree layer always holds page1 open until the end, so these first
//	** two routines can be used to release any page other than BtShared.pPage1.
//	** The assert() at tag-20230419-2 proves that this constraint is always
//	** honored.
//	**
//	** Use sqlite3PagerUnrefPageOne() to release page1.  This latter routine
//	** checks the total number of outstanding pages and if the number of
//	** pages reaches zero it drops the database lock.
//	*/
func _sqlite3PagerUnrefNotNull(tls *libc.TLS, pPg uintptr) {
	if int32((*TDbPage)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_MMAP) != 0 {
		/* Page1 is never memory mapped */
		_pagerReleaseMapPage(tls, pPg)
	} else {
		_sqlite3PcacheRelease(tls, pPg)
	}
	/* Do not use this routine to release the last reference to page1 */
	/* tag-20230419-2 */
}

func _sqlite3PagerUnref(tls *libc.TLS, pPg uintptr) {
	if pPg != 0 {
		_sqlite3PagerUnrefNotNull(tls, pPg)
	}
}

func _sqlite3PagerUnrefPageOne(tls *libc.TLS, pPg uintptr) {
	var pPager uintptr
	_ = pPager
	/* Page1 is never memory mapped */
	pPager = (*TDbPage)(unsafe.Pointer(pPg)).FpPager
	_sqlite3PcacheRelease(tls, pPg)
	_pagerUnlockIfUnused(tls, pPager)
}

// C documentation
//
//	/*
//	** This function is called at the start of every write transaction.
//	** There must already be a RESERVED or EXCLUSIVE lock on the database
//	** file when this routine is called.
//	**
//	** Open the journal file for pager pPager and write a journal header
//	** to the start of it. If there are active savepoints, open the sub-journal
//	** as well. This function is only used when the journal file is being
//	** opened to write a rollback log for a transaction. It is not used
//	** when opening a hot journal file to roll it back.
//	**
//	** If the journal file is already open (as it may be in exclusive mode),
//	** then this function just writes a journal header to the start of the
//	** already open file.
//	**
//	** Whether or not the journal file is opened by this function, the
//	** Pager.pInJournal bitvec structure is allocated.
//	**
//	** Return SQLITE_OK if everything is successful. Otherwise, return
//	** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
//	** an IO error code if opening or writing the journal file fails.
//	*/
func _pager_open_journal(tls *libc.TLS, pPager uintptr) (r int32) {
	var flags, nSpill, rc int32
	var pVfs uintptr
	_, _, _, _ = flags, nSpill, pVfs, rc
	rc = SQLITE_OK                                 /* Return code */
	pVfs = (*TPager)(unsafe.Pointer(pPager)).FpVfs /* Local cache of vfs pointer */
	/* If already in the error state, this function is a no-op.  But on
	 ** the other hand, this routine is never called if we are already in
	 ** an error state. */
	if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*TPager)(unsafe.Pointer(pPager)).FerrCode
	}
	if !((*TPager)(unsafe.Pointer(pPager)).FpWal != libc.UintptrFromInt32(0)) && int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) != int32(PAGER_JOURNALMODE_OFF) {
		(*TPager)(unsafe.Pointer(pPager)).FpInJournal = _sqlite3BitvecCreate(tls, (*TPager)(unsafe.Pointer(pPager)).FdbSize)
		if (*TPager)(unsafe.Pointer(pPager)).FpInJournal == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		/* Open the journal file if it is not already open. */
		if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != libc.UintptrFromInt32(0)) {
			if int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_MEMORY) {
				_sqlite3MemJournalOpen(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
			} else {
				flags = libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE)
				if (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 {
					flags |= libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_JOURNAL)
					flags |= int32(SQLITE_OPEN_EXCLUSIVE)
					nSpill = _sqlite3Config.FnStmtSpill
				} else {
					flags |= int32(SQLITE_OPEN_MAIN_JOURNAL)
					nSpill = _jrnlBufferSize(tls, pPager)
				}
				/* Verify that the database still has the same name as it did when
				 ** it was originally opened. */
				rc = _databaseIsUnmoved(tls, pPager)
				if rc == SQLITE_OK {
					rc = _sqlite3JournalOpen(tls, pVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, (*TPager)(unsafe.Pointer(pPager)).Fjfd, flags, nSpill)
				}
			}
		}
		/* Write the first journal header to the journal file and open
		 ** the sub-journal if necessary.
		 */
		if rc == SQLITE_OK {
			/* TODO: Check if all of these are really required. */
			(*TPager)(unsafe.Pointer(pPager)).FnRec = 0
			(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
			(*TPager)(unsafe.Pointer(pPager)).FsetSuper = uint8(0)
			(*TPager)(unsafe.Pointer(pPager)).FjournalHdr = 0
			rc = _writeJournalHdr(tls, pPager)
		}
	}
	if rc != SQLITE_OK {
		_sqlite3BitvecDestroy(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal)
		(*TPager)(unsafe.Pointer(pPager)).FpInJournal = uintptr(0)
		(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
	} else {
		(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_WRITER_CACHEMOD)
	}
	return rc
}

// C documentation
//
//	/*
//	** Begin a write-transaction on the specified pager object. If a
//	** write-transaction has already been opened, this function is a no-op.
//	**
//	** If the exFlag argument is false, then acquire at least a RESERVED
//	** lock on the database file. If exFlag is true, then acquire at least
//	** an EXCLUSIVE lock. If such a lock is already held, no locking
//	** functions need be called.
//	**
//	** If the subjInMemory argument is non-zero, then any sub-journal opened
//	** within this transaction will be opened as an in-memory file. This
//	** has no effect if the sub-journal is already opened (as it may be when
//	** running in exclusive mode) or if the transaction does not require a
//	** sub-journal. If the subjInMemory argument is zero, then any required
//	** sub-journal is implemented in-memory if pPager is an in-memory database,
//	** or using a temporary file otherwise.
//	*/
func _sqlite3PagerBegin(tls *libc.TLS, pPager uintptr, exFlag int32, subjInMemory int32) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*TPager)(unsafe.Pointer(pPager)).FerrCode
	}
	(*TPager)(unsafe.Pointer(pPager)).FsubjInMemory = uint8(uint8(subjInMemory))
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_READER) {
		if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
			/* If the pager is configured to use locking_mode=exclusive, and an
			 ** exclusive lock on the database is not already held, obtain it now.
			 */
			if (*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 && _sqlite3WalExclusiveMode(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, -int32(1)) != 0 {
				rc = _pagerLockDb(tls, pPager, int32(EXCLUSIVE_LOCK))
				if rc != SQLITE_OK {
					return rc
				}
				_sqlite3WalExclusiveMode(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, int32(1))
			}
			/* Grab the write lock on the log file. If successful, upgrade to
			 ** PAGER_RESERVED state. Otherwise, return an error code to the caller.
			 ** The busy-handler is not invoked if another connection already
			 ** holds the write-lock. If possible, the upper layer will call it.
			 */
			rc = _sqlite3WalBeginWriteTransaction(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
		} else {
			/* Obtain a RESERVED lock on the database file. If the exFlag parameter
			 ** is true, then immediately upgrade this to an EXCLUSIVE lock. The
			 ** busy-handler callback can be used when upgrading to the EXCLUSIVE
			 ** lock, but not when obtaining the RESERVED lock.
			 */
			rc = _pagerLockDb(tls, pPager, int32(RESERVED_LOCK))
			if rc == SQLITE_OK && exFlag != 0 {
				rc = _pager_wait_on_lock(tls, pPager, int32(EXCLUSIVE_LOCK))
			}
		}
		if rc == SQLITE_OK {
			/* Change to WRITER_LOCKED state.
			 **
			 ** WAL mode sets Pager.eState to PAGER_WRITER_LOCKED or CACHEMOD
			 ** when it has an open transaction, but never to DBMOD or FINISHED.
			 ** This is because in those states the code to roll back savepoint
			 ** transactions may copy data from the sub-journal into the database
			 ** file as well as into the page cache. Which would be incorrect in
			 ** WAL mode.
			 */
			(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_WRITER_LOCKED)
			(*TPager)(unsafe.Pointer(pPager)).FdbHintSize = (*TPager)(unsafe.Pointer(pPager)).FdbSize
			(*TPager)(unsafe.Pointer(pPager)).FdbFileSize = (*TPager)(unsafe.Pointer(pPager)).FdbSize
			(*TPager)(unsafe.Pointer(pPager)).FdbOrigSize = (*TPager)(unsafe.Pointer(pPager)).FdbSize
			(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Write page pPg onto the end of the rollback journal.
//	*/
func _pagerAddPageToRollbackJournal(tls *libc.TLS, pPg uintptr) (r int32) {
	var cksum Tu32
	var iOff Ti64
	var pData2, pPager, p1 uintptr
	var rc int32
	_, _, _, _, _, _ = cksum, iOff, pData2, pPager, rc, p1
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	iOff = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
	/* We should never write to the journal file the page that
	 ** contains the database locks.  The following assert verifies
	 ** that we do not. */
	pData2 = (*TPgHdr)(unsafe.Pointer(pPg)).FpData
	cksum = _pager_cksum(tls, pPager, pData2)
	/* Even if an IO or diskfull error occurs while journalling the
	 ** page in the block above, set the need-sync flag for the page.
	 ** Otherwise, when the transaction is rolled back, the logic in
	 ** playback_one_page() will think that the page needs to be restored
	 ** in the database file. And if an IO error occurs while doing so,
	 ** then corruption may follow.
	 */
	p1 = pPg + 28
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(PGHDR_NEED_SYNC))
	rc = _write32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iOff, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno)
	if rc != SQLITE_OK {
		return rc
	}
	rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, pData2, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), iOff+int64(4))
	if rc != SQLITE_OK {
		return rc
	}
	rc = _write32bits(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, iOff+(*TPager)(unsafe.Pointer(pPager)).FpageSize+int64(4), cksum)
	if rc != SQLITE_OK {
		return rc
	}
	*(*Ti64)(unsafe.Pointer(pPager + 80)) += int64(8) + (*TPager)(unsafe.Pointer(pPager)).FpageSize
	(*TPager)(unsafe.Pointer(pPager)).FnRec++
	rc = _sqlite3BitvecSet(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno)
	rc |= _addToSavepointBitvecs(tls, pPager, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno)
	return rc
}

// C documentation
//
//	/*
//	** Mark a single data page as writeable. The page is written into the
//	** main journal or sub-journal as required. If the page is written into
//	** one of the journals, the corresponding bit is set in the
//	** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
//	** of any open savepoints as appropriate.
//	*/
func _pager_write(tls *libc.TLS, pPg uintptr) (r int32) {
	var pPager, p1, p2 uintptr
	var rc int32
	_, _, _, _ = pPager, rc, p1, p2
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	rc = SQLITE_OK
	/* This routine is not called unless a write-transaction has already
	 ** been started. The journal file may or may not be open at this point.
	 ** It is never called in the ERROR state.
	 */
	/* The journal file needs to be opened. Higher level routines have already
	 ** obtained the necessary locks to begin the write-transaction, but the
	 ** rollback journal might not yet be open. Open it now if this is the case.
	 **
	 ** This is done before calling sqlite3PcacheMakeDirty() on the page.
	 ** Otherwise, if it were done after calling sqlite3PcacheMakeDirty(), then
	 ** an error might occur and the pager would end up in WRITER_LOCKED state
	 ** with pages marked as dirty in the cache.
	 */
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_WRITER_LOCKED) {
		rc = _pager_open_journal(tls, pPager)
		if rc != SQLITE_OK {
			return rc
		}
	}
	/* Mark the page that is about to be modified as dirty. */
	_sqlite3PcacheMakeDirty(tls, pPg)
	/* If a rollback journal is in use, them make sure the page that is about
	 ** to change is in the rollback journal, or if the page is a new page off
	 ** then end of the file, make sure it is marked as PGHDR_NEED_SYNC.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FpInJournal != uintptr(0) && _sqlite3BitvecTestNotNull(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno) == 0 {
		if (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno <= (*TPager)(unsafe.Pointer(pPager)).FdbOrigSize {
			rc = _pagerAddPageToRollbackJournal(tls, pPg)
			if rc != SQLITE_OK {
				return rc
			}
		} else {
			if int32((*TPager)(unsafe.Pointer(pPager)).FeState) != int32(PAGER_WRITER_DBMOD) {
				p1 = pPg + 28
				*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(PGHDR_NEED_SYNC))
			}
		}
	}
	/* The PGHDR_DIRTY bit is set above when the page was added to the dirty-list
	 ** and before writing the page into the rollback journal.  Wait until now,
	 ** after the page has been successfully journalled, before setting the
	 ** PGHDR_WRITEABLE bit that indicates that the page can be safely modified.
	 */
	p2 = pPg + 28
	*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(PGHDR_WRITEABLE))
	/* If the statement journal is open and the page is not in it,
	 ** then write the page into the statement journal.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FnSavepoint > 0 {
		rc = _subjournalPageIfRequired(tls, pPg)
	}
	/* Update the database size and return. */
	if (*TPager)(unsafe.Pointer(pPager)).FdbSize < (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno {
		(*TPager)(unsafe.Pointer(pPager)).FdbSize = (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno
	}
	return rc
}

// C documentation
//
//	/*
//	** This is a variant of sqlite3PagerWrite() that runs when the sector size
//	** is larger than the page size.  SQLite makes the (reasonable) assumption that
//	** all bytes of a sector are written together by hardware.  Hence, all bytes of
//	** a sector need to be journalled in case of a power loss in the middle of
//	** a write.
//	**
//	** Usually, the sector size is less than or equal to the page size, in which
//	** case pages can be individually written.  This routine only runs in the
//	** exceptional case where the page size is smaller than the sector size.
//	*/
func _pagerWriteLargeSector(tls *libc.TLS, pPg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var ii, nPage, needSync, rc int32
	var nPageCount, nPagePerSector, pg, pg1 TPgno
	var pPage1, pPager, v3, p1, p5, p6 uintptr
	var _ /* pPage at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = ii, nPage, nPageCount, nPagePerSector, needSync, pPage1, pPager, pg, pg1, rc, v3, p1, p5, p6
	rc = SQLITE_OK                                  /* First page of the sector pPg is located on. */
	nPage = 0                                       /* Loop counter */
	needSync = 0                                    /* True if any page has PGHDR_NEED_SYNC */
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager /* The pager that owns pPg */
	nPagePerSector = uint32(int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize) / (*TPager)(unsafe.Pointer(pPager)).FpageSize)
	/* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
	 ** a journal header to be written between the pages journaled by
	 ** this function.
	 */
	p1 = pPager + 21
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(SPILLFLAG_NOSYNC))
	/* This trick assumes that both the page-size and sector-size are
	 ** an integer power of 2. It sets variable pg1 to the identifier
	 ** of the first page of the sector pPg is located on.
	 */
	pg1 = ((*TPgHdr)(unsafe.Pointer(pPg)).Fpgno-uint32(1)) & ^(nPagePerSector-libc.Uint32FromInt32(1)) + uint32(1)
	nPageCount = (*TPager)(unsafe.Pointer(pPager)).FdbSize
	if (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno > nPageCount {
		nPage = int32((*TPgHdr)(unsafe.Pointer(pPg)).Fpgno - pg1 + uint32(1))
	} else {
		if pg1+nPagePerSector-uint32(1) > nPageCount {
			nPage = int32(nPageCount + uint32(1) - pg1)
		} else {
			nPage = int32(int32(nPagePerSector))
		}
	}
	ii = 0
	for {
		if !(ii < nPage && rc == SQLITE_OK) {
			break
		}
		pg = pg1 + uint32(uint32(ii))
		if pg == (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno || !(_sqlite3BitvecTest(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal, pg) != 0) {
			if pg != (*TPager)(unsafe.Pointer(pPager)).FlckPgno {
				rc = _sqlite3PagerGet(tls, pPager, pg, bp, 0)
				if rc == SQLITE_OK {
					rc = _pager_write(tls, *(*uintptr)(unsafe.Pointer(bp)))
					if int32((*TPgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags)&int32(PGHDR_NEED_SYNC) != 0 {
						needSync = int32(1)
					}
					_sqlite3PagerUnrefNotNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
				}
			}
		} else {
			v3 = _sqlite3PagerLookup(tls, pPager, pg)
			*(*uintptr)(unsafe.Pointer(bp)) = v3
			if v3 != uintptr(0) {
				if int32((*TPgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags)&int32(PGHDR_NEED_SYNC) != 0 {
					needSync = int32(1)
				}
				_sqlite3PagerUnrefNotNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		goto _2
	_2:
		;
		ii++
	}
	/* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
	 ** starting at pg1, then it needs to be set for all of them. Because
	 ** writing to any of these nPage pages may damage the others, the
	 ** journal file must contain sync()ed copies of all of them
	 ** before any of them can be written out to the database file.
	 */
	if rc == SQLITE_OK && needSync != 0 {
		ii = 0
		for {
			if !(ii < nPage) {
				break
			}
			pPage1 = _sqlite3PagerLookup(tls, pPager, pg1+uint32(uint32(ii)))
			if pPage1 != 0 {
				p5 = pPage1 + 28
				*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(PGHDR_NEED_SYNC))
				_sqlite3PagerUnrefNotNull(tls, pPage1)
			}
			goto _4
		_4:
			;
			ii++
		}
	}
	p6 = pPager + 21
	*(*Tu8)(unsafe.Pointer(p6)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p6))) & ^libc.Int32FromInt32(SPILLFLAG_NOSYNC))
	return rc
}

// C documentation
//
//	/*
//	** Mark a data page as writeable. This routine must be called before
//	** making changes to a page. The caller must check the return value
//	** of this function and be careful not to change any page data unless
//	** this routine returns SQLITE_OK.
//	**
//	** The difference between this function and pager_write() is that this
//	** function also deals with the special case where 2 or more pages
//	** fit on a single disk sector. In this case all co-resident pages
//	** must have been written to the journal file before returning.
//	**
//	** If an error occurs, SQLITE_NOMEM or an IO error code is returned
//	** as appropriate. Otherwise, SQLITE_OK.
//	*/
func _sqlite3PagerWrite(tls *libc.TLS, pPg uintptr) (r int32) {
	var pPager uintptr
	_ = pPager
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	if int32((*TPgHdr)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_WRITEABLE) != 0 && (*TPager)(unsafe.Pointer(pPager)).FdbSize >= (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno {
		if (*TPager)(unsafe.Pointer(pPager)).FnSavepoint != 0 {
			return _subjournalPageIfRequired(tls, pPg)
		}
		return SQLITE_OK
	} else {
		if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
			return (*TPager)(unsafe.Pointer(pPager)).FerrCode
		} else {
			if (*TPager)(unsafe.Pointer(pPager)).FsectorSize > uint32((*TPager)(unsafe.Pointer(pPager)).FpageSize) {
				return _pagerWriteLargeSector(tls, pPg)
			} else {
				return _pager_write(tls, pPg)
			}
		}
	}
	return r
}

/*
** Return TRUE if the page given in the argument was previously passed
** to sqlite3PagerWrite().  In other words, return TRUE if it is ok
** to change the content of the page.
 */

// C documentation
//
//	/*
//	** A call to this routine tells the pager that it is not necessary to
//	** write the information on page pPg back to the disk, even though
//	** that page might be marked as dirty.  This happens, for example, when
//	** the page has been added as a leaf of the freelist and so its
//	** content no longer matters.
//	**
//	** The overlying software layer calls this routine when all of the data
//	** on the given page is unused. The pager marks the page as clean so
//	** that it does not get written to disk.
//	**
//	** Tests show that this optimization can quadruple the speed of large
//	** DELETE operations.
//	**
//	** This optimization cannot be used with a temp-file, as the page may
//	** have been dirty at the start of the transaction. In that case, if
//	** memory pressure forces page pPg out of the cache, the data does need
//	** to be written out to disk so that it may be read back in if the
//	** current transaction is rolled back.
//	*/
func _sqlite3PagerDontWrite(tls *libc.TLS, pPg uintptr) {
	var pPager, p1, p2 uintptr
	_, _, _ = pPager, p1, p2
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	if !((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0) && int32((*TPgHdr)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_DIRTY) != 0 && (*TPager)(unsafe.Pointer(pPager)).FnSavepoint == 0 {
		p1 = pPg + 28
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(PGHDR_DONT_WRITE))
		p2 = pPg + 28
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(PGHDR_WRITEABLE))
	}
}

// C documentation
//
//	/*
//	** This routine is called to increment the value of the database file
//	** change-counter, stored as a 4-byte big-endian integer starting at
//	** byte offset 24 of the pager file.  The secondary change counter at
//	** 92 is also updated, as is the SQLite version number at offset 96.
//	**
//	** But this only happens if the pPager->changeCountDone flag is false.
//	** To avoid excess churning of page 1, the update only happens once.
//	** See also the pager_write_changecounter() routine that does an
//	** unconditional update of the change counters.
//	**
//	** If the isDirectMode flag is zero, then this is done by calling
//	** sqlite3PagerWrite() on page 1, then modifying the contents of the
//	** page data. In this case the file will be updated when the current
//	** transaction is committed.
//	**
//	** The isDirectMode flag may only be non-zero if the library was compiled
//	** with the SQLITE_ENABLE_ATOMIC_WRITE macro defined. In this case,
//	** if isDirect is non-zero, then the database file is updated directly
//	** by writing an updated version of page 1 using a call to the
//	** sqlite3OsWrite() function.
//	*/
func _pager_incr_changecounter(tls *libc.TLS, pPager uintptr, isDirectMode int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCopy, zBuf uintptr
	var rc int32
	var _ /* pPgHdr at bp+0 */ uintptr
	_, _, _ = pCopy, rc, zBuf
	rc = SQLITE_OK
	/* Declare and initialize constant integer 'isDirect'. If the
	 ** atomic-write optimization is enabled in this build, then isDirect
	 ** is initialized to the value passed as the isDirectMode parameter
	 ** to this function. Otherwise, it is always set to zero.
	 **
	 ** The idea is that if the atomic-write optimization is not
	 ** enabled at compile time, the compiler can omit the tests of
	 ** 'isDirect' below, as well as the block enclosed in the
	 ** "if( isDirect )" condition.
	 */
	_ = isDirectMode
	if !((*TPager)(unsafe.Pointer(pPager)).FchangeCountDone != 0) && (*TPager)(unsafe.Pointer(pPager)).FdbSize > uint32(0) { /* Reference to page 1 */
		/* Open page 1 of the file for writing. */
		rc = _sqlite3PagerGet(tls, pPager, uint32(1), bp, 0)
		/* If page one was fetched successfully, and this function is not
		 ** operating in direct-mode, make page 1 writable.  When not in
		 ** direct mode, page 1 is always held in cache and hence the PagerGet()
		 ** above is always successful - hence the ALWAYS on rc==SQLITE_OK.
		 */
		if libc.Bool(!(libc.Int32FromInt32(DIRECT_MODE) != 0)) && rc == SQLITE_OK {
			rc = _sqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		if rc == SQLITE_OK {
			/* Actually do the update of the change counter */
			_pager_write_changecounter(tls, *(*uintptr)(unsafe.Pointer(bp)))
			/* If running in direct mode, write the contents of page 1 to the file. */
			if DIRECT_MODE != 0 {
				zBuf = (*TPgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpData
				if rc == SQLITE_OK {
					rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, zBuf, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), 0)
					*(*Tu32)(unsafe.Pointer(pPager + 200 + 2*4))++
				}
				if rc == SQLITE_OK {
					/* Update the pager's copy of the change-counter. Otherwise, the
					 ** next time a read transaction is opened the cache will be
					 ** flushed (as the change-counter values will not match).  */
					pCopy = zBuf + 24
					libc.Xmemcpy(tls, pPager+112, pCopy, uint32(16))
					(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = uint8(1)
				}
			} else {
				(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = uint8(1)
			}
		}
		/* Release the page reference. */
		_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Sync the database file to disk. This is a no-op for in-memory databases
//	** or pages with the Pager.noSync flag set.
//	**
//	** If successful, or if called on a pager for which it is a no-op, this
//	** function returns SQLITE_OK. Otherwise, an IO error code is returned.
//	*/
func _sqlite3PagerSync(tls *libc.TLS, pPager uintptr, zSuper uintptr) (r int32) {
	var pArg uintptr
	var rc int32
	_, _ = pArg, rc
	rc = SQLITE_OK
	pArg = zSuper
	rc = _sqlite3OsFileControl(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_SYNC), pArg)
	if rc == int32(SQLITE_NOTFOUND) {
		rc = SQLITE_OK
	}
	if rc == SQLITE_OK && !((*TPager)(unsafe.Pointer(pPager)).FnoSync != 0) {
		rc = _sqlite3OsSync(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32((*TPager)(unsafe.Pointer(pPager)).FsyncFlags))
	}
	return rc
}

// C documentation
//
//	/*
//	** This function may only be called while a write-transaction is active in
//	** rollback. If the connection is in WAL mode, this call is a no-op.
//	** Otherwise, if the connection does not already have an EXCLUSIVE lock on
//	** the database file, an attempt is made to obtain one.
//	**
//	** If the EXCLUSIVE lock is already held or the attempt to obtain it is
//	** successful, or the connection is in WAL mode, SQLITE_OK is returned.
//	** Otherwise, either SQLITE_BUSY or an SQLITE_IOERR_XXX error code is
//	** returned.
//	*/
func _sqlite3PagerExclusiveLock(tls *libc.TLS, pPager uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = (*TPager)(unsafe.Pointer(pPager)).FerrCode
	if rc == SQLITE_OK {
		if 0 == libc.BoolInt32((*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) {
			rc = _pager_wait_on_lock(tls, pPager, int32(EXCLUSIVE_LOCK))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Sync the database file for the pager pPager. zSuper points to the name
//	** of a super-journal file that should be written into the individual
//	** journal file. zSuper may be NULL, which is interpreted as no
//	** super-journal (a single database transaction).
//	**
//	** This routine ensures that:
//	**
//	**   * The database file change-counter is updated,
//	**   * the journal is synced (unless the atomic-write optimization is used),
//	**   * all dirty pages are written to the database file,
//	**   * the database file is truncated (if required), and
//	**   * the database file synced.
//	**
//	** The only thing that remains to commit the transaction is to finalize
//	** (delete, truncate or zero the first part of) the journal file (or
//	** delete the super-journal file if specified).
//	**
//	** Note that if zSuper==NULL, this does not overwrite a previous value
//	** passed to an sqlite3PagerCommitPhaseOne() call.
//	**
//	** If the final parameter - noSync - is true, then the database file itself
//	** is not synced. The caller must call sqlite3PagerSync() directly to
//	** sync the database file before calling CommitPhaseTwo() to delete the
//	** journal file in this case.
//	*/
func _sqlite3PagerCommitPhaseOne(tls *libc.TLS, pPager uintptr, zSuper uintptr, noSync int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nNew TPgno
	var pList uintptr
	var rc int32
	var _ /* pPageOne at bp+0 */ uintptr
	_, _, _ = nNew, pList, rc
	rc = SQLITE_OK /* Return code */
	/* If a prior error occurred, report that error again. */
	if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*TPager)(unsafe.Pointer(pPager)).FerrCode
	}
	/* Provide the ability to easily simulate an I/O error during testing */
	if _sqlite3FaultSim(tls, int32(400)) != 0 {
		return int32(SQLITE_IOERR)
	}
	/* If no database changes have been made, return early. */
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) < int32(PAGER_WRITER_CACHEMOD) {
		return SQLITE_OK
	}
	if 0 == _pagerFlushOnCommit(tls, pPager, int32(1)) {
		/* If this is an in-memory db, or no pages have been written to, or this
		 ** function has already been called, it is mostly a no-op.  However, any
		 ** backup in progress needs to be restarted.  */
		_sqlite3BackupRestart(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup)
	} else {
		if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			pList = _sqlite3PcacheDirtyList(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
			if pList == uintptr(0) {
				/* Must have at least one page for the WAL commit flag.
				 ** Ticket [2d1a5c67dfc2363e44f29d9bbd57f] 2011-05-18 */
				rc = _sqlite3PagerGet(tls, pPager, uint32(1), bp, 0)
				pList = *(*uintptr)(unsafe.Pointer(bp))
				(*TPgHdr)(unsafe.Pointer(pList)).FpDirty = uintptr(0)
			}
			if pList != 0 {
				rc = _pagerWalFrames(tls, pPager, pList, (*TPager)(unsafe.Pointer(pPager)).FdbSize, int32(1))
			}
			_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
			if rc == SQLITE_OK {
				_sqlite3PcacheCleanAll(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
			}
		} else {
			/* The bBatch boolean is true if the batch-atomic-write commit method
			 ** should be used.  No rollback journal is created if batch-atomic-write
			 ** is enabled.
			 */
			rc = _pager_incr_changecounter(tls, pPager, 0)
			if rc != SQLITE_OK {
				goto commit_phase_one_exit
			}
			/* Write the super-journal name into the journal file. If a
			 ** super-journal file name has already been written to the journal file,
			 ** or if zSuper is NULL (no super-journal), then this call is a no-op.
			 */
			rc = _writeSuperJournal(tls, pPager, zSuper)
			if rc != SQLITE_OK {
				goto commit_phase_one_exit
			}
			/* Sync the journal file and write all dirty pages to the database.
			 ** If the atomic-update optimization is being used, this sync will not
			 ** create the journal file or perform any real IO.
			 **
			 ** Because the change-counter page was just modified, unless the
			 ** atomic-update optimization is used it is almost certain that the
			 ** journal requires a sync here. However, in locking_mode=exclusive
			 ** on a system under memory pressure it is just possible that this is
			 ** not the case. In this case it is likely enough that the redundant
			 ** xSync() call will be changed to a no-op by the OS anyhow.
			 */
			rc = _syncJournal(tls, pPager, 0)
			if rc != SQLITE_OK {
				goto commit_phase_one_exit
			}
			pList = _sqlite3PcacheDirtyList(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
			if true {
				rc = _pager_write_pagelist(tls, pPager, pList)
			}
			if rc != SQLITE_OK {
				goto commit_phase_one_exit
			}
			_sqlite3PcacheCleanAll(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)
			/* If the file on disk is smaller than the database image, use
			 ** pager_truncate to grow the file here. This can happen if the database
			 ** image was extended as part of the current transaction and then the
			 ** last page in the db image moved to the free-list. In this case the
			 ** last page is never written out to disk, leaving the database file
			 ** undersized. Fix this now if it is the case.  */
			if (*TPager)(unsafe.Pointer(pPager)).FdbSize > (*TPager)(unsafe.Pointer(pPager)).FdbFileSize {
				nNew = (*TPager)(unsafe.Pointer(pPager)).FdbSize - libc.BoolUint32((*TPager)(unsafe.Pointer(pPager)).FdbSize == (*TPager)(unsafe.Pointer(pPager)).FlckPgno)
				rc = _pager_truncate(tls, pPager, nNew)
				if rc != SQLITE_OK {
					goto commit_phase_one_exit
				}
			}
			/* Finally, sync the database file. */
			if !(noSync != 0) {
				rc = _sqlite3PagerSync(tls, pPager, zSuper)
			}
		}
	}
	goto commit_phase_one_exit
commit_phase_one_exit:
	;
	if rc == SQLITE_OK && !((*TPager)(unsafe.Pointer(pPager)).FpWal != libc.UintptrFromInt32(0)) {
		(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_WRITER_FINISHED)
	}
	return rc
}

// C documentation
//
//	/*
//	** When this function is called, the database file has been completely
//	** updated to reflect the changes made by the current transaction and
//	** synced to disk. The journal file still exists in the file-system
//	** though, and if a failure occurs at this point it will eventually
//	** be used as a hot-journal and the current transaction rolled back.
//	**
//	** This function finalizes the journal file, either by deleting,
//	** truncating or partially zeroing it, so that it cannot be used
//	** for hot-journal rollback. Once this is done the transaction is
//	** irrevocably committed.
//	**
//	** If an error occurs, an IO error code is returned and the pager
//	** moves into the error state. Otherwise, SQLITE_OK is returned.
//	*/
func _sqlite3PagerCommitPhaseTwo(tls *libc.TLS, pPager uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK /* Return code */
	/* This routine should not be called if a prior error has occurred.
	 ** But if (due to a coding error elsewhere in the system) it does get
	 ** called, just return the same error code without doing anything. */
	if (*TPager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*TPager)(unsafe.Pointer(pPager)).FerrCode
	}
	(*TPager)(unsafe.Pointer(pPager)).FiDataVersion++
	/* An optimization. If the database was not actually modified during
	 ** this transaction, the pager is running in exclusive-mode and is
	 ** using persistent journals, then this function is a no-op.
	 **
	 ** The start of the journal file currently contains a single journal
	 ** header with the nRec field set to 0. If such a journal is used as
	 ** a hot-journal during hot-journal rollback, 0 changes will be made
	 ** to the database file. So there is no need to zero the journal
	 ** header. Since the pager is in exclusive mode, there is no need
	 ** to drop any locks either.
	 */
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_WRITER_LOCKED) && (*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 && int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_PERSIST) {
		(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_READER)
		return SQLITE_OK
	}
	rc = _pager_end_transaction(tls, pPager, int32((*TPager)(unsafe.Pointer(pPager)).FsetSuper), int32(1))
	return _pager_error(tls, pPager, rc)
}

// C documentation
//
//	/*
//	** If a write transaction is open, then all changes made within the
//	** transaction are reverted and the current write-transaction is closed.
//	** The pager falls back to PAGER_READER state if successful, or PAGER_ERROR
//	** state if an error occurs.
//	**
//	** If the pager is already in PAGER_ERROR state when this function is called,
//	** it returns Pager.errCode immediately. No work is performed in this case.
//	**
//	** Otherwise, in rollback mode, this function performs two functions:
//	**
//	**   1) It rolls back the journal file, restoring all database file and
//	**      in-memory cache pages to the state they were in when the transaction
//	**      was opened, and
//	**
//	**   2) It finalizes the journal file, so that it is not used for hot
//	**      rollback at any point in the future.
//	**
//	** Finalization of the journal file (task 2) is only performed if the
//	** rollback is successful.
//	**
//	** In WAL mode, all cache-entries containing data modified within the
//	** current transaction are either expelled from the cache or reverted to
//	** their pre-transaction state by re-reading data from the database or
//	** WAL files. The WAL transaction is then closed.
//	*/
func _sqlite3PagerRollback(tls *libc.TLS, pPager uintptr) (r int32) {
	var eState, rc, rc2 int32
	_, _, _ = eState, rc, rc2
	rc = SQLITE_OK /* Return code */
	/* PagerRollback() is a no-op if called in READER or OPEN state. If
	 ** the pager is already in the ERROR state, the rollback is not
	 ** attempted here. Instead, the error code is returned to the caller.
	 */
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_ERROR) {
		return (*TPager)(unsafe.Pointer(pPager)).FerrCode
	}
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) <= int32(PAGER_READER) {
		return SQLITE_OK
	}
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc = _sqlite3PagerSavepoint(tls, pPager, int32(SAVEPOINT_ROLLBACK), -int32(1))
		rc2 = _pager_end_transaction(tls, pPager, int32((*TPager)(unsafe.Pointer(pPager)).FsetSuper), 0)
		if rc == SQLITE_OK {
			rc = rc2
		}
	} else {
		if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != libc.UintptrFromInt32(0)) || int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_WRITER_LOCKED) {
			eState = int32((*TPager)(unsafe.Pointer(pPager)).FeState)
			rc = _pager_end_transaction(tls, pPager, 0, 0)
			if !((*TPager)(unsafe.Pointer(pPager)).FmemDb != 0) && eState > int32(PAGER_WRITER_LOCKED) {
				/* This can happen using journal_mode=off. Move the pager to the error
				 ** state to indicate that the contents of the cache may not be trusted.
				 ** Any active readers will get SQLITE_ABORT.
				 */
				(*TPager)(unsafe.Pointer(pPager)).FerrCode = int32(SQLITE_ABORT)
				(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_ERROR)
				_setGetterMethod(tls, pPager)
				return rc
			}
		} else {
			rc = _pager_playback(tls, pPager, 0)
		}
	}
	/* If an error occurs during a ROLLBACK, we can no longer trust the pager
	 ** cache. So call pager_error() on the way out to make any error persistent.
	 */
	return _pager_error(tls, pPager, rc)
}

// C documentation
//
//	/*
//	** Return TRUE if the database file is opened read-only.  Return FALSE
//	** if the database is (in theory) writable.
//	*/
func _sqlite3PagerIsreadonly(tls *libc.TLS, pPager uintptr) (r Tu8) {
	return (*TPager)(unsafe.Pointer(pPager)).FreadOnly
}

// C documentation
//
//	/*
//	** Return the approximate number of bytes of memory currently
//	** used by the pager and its associated cache.
//	*/
func _sqlite3PagerMemUsed(tls *libc.TLS, pPager uintptr) (r int32) {
	var perPageSize int32
	_ = perPageSize
	perPageSize = int32((*TPager)(unsafe.Pointer(pPager)).FpageSize + int64((*TPager)(unsafe.Pointer(pPager)).FnExtra) + int64(int32(libc.Uint32FromInt64(48)+libc.Uint32FromInt32(5)*libc.Uint32FromInt64(4))))
	return int32(int64(perPageSize*_sqlite3PcachePagecount(tls, (*TPager)(unsafe.Pointer(pPager)).FpPCache)+_sqlite3MallocSize(tls, pPager)) + (*TPager)(unsafe.Pointer(pPager)).FpageSize)
}

// C documentation
//
//	/*
//	** Return the number of references to the specified page.
//	*/
func _sqlite3PagerPageRefcount(tls *libc.TLS, pPage uintptr) (r int32) {
	return int32(_sqlite3PcachePageRefcount(tls, pPage))
}

// C documentation
//
//	/*
//	** Parameter eStat must be one of SQLITE_DBSTATUS_CACHE_HIT, _MISS, _WRITE,
//	** or _WRITE+1.  The SQLITE_DBSTATUS_CACHE_WRITE+1 case is a translation
//	** of SQLITE_DBSTATUS_CACHE_SPILL.  The _SPILL case is not contiguous because
//	** it was added later.
//	**
//	** Before returning, *pnVal is incremented by the
//	** current cache hit or miss count, according to the value of eStat. If the
//	** reset parameter is non-zero, the cache hit or miss count is zeroed before
//	** returning.
//	*/
func _sqlite3PagerCacheStat(tls *libc.TLS, pPager uintptr, eStat int32, reset int32, pnVal uintptr) {
	eStat -= int32(SQLITE_DBSTATUS_CACHE_HIT)
	*(*Tu64)(unsafe.Pointer(pnVal)) += uint64(*(*Tu32)(unsafe.Pointer(pPager + 200 + uintptr(eStat)*4)))
	if reset != 0 {
		*(*Tu32)(unsafe.Pointer(pPager + 200 + uintptr(eStat)*4)) = uint32(0)
	}
}

// C documentation
//
//	/*
//	** Return true if this is an in-memory or temp-file backed pager.
//	*/
func _sqlite3PagerIsMemdb(tls *libc.TLS, pPager uintptr) (r int32) {
	return libc.BoolInt32((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 || (*TPager)(unsafe.Pointer(pPager)).FmemVfs != 0)
}

// C documentation
//
//	/*
//	** Check that there are at least nSavepoint savepoints open. If there are
//	** currently less than nSavepoints open, then open one or more savepoints
//	** to make up the difference. If the number of savepoints is already
//	** equal to nSavepoint, then this function is a no-op.
//	**
//	** If a memory allocation fails, SQLITE_NOMEM is returned. If an error
//	** occurs while opening the sub-journal file, then an IO error code is
//	** returned. Otherwise, SQLITE_OK.
//	*/
func _pagerOpenSavepoint(tls *libc.TLS, pPager uintptr, nSavepoint int32) (r int32) {
	var aNew uintptr
	var ii, nCurrent, rc int32
	_, _, _, _ = aNew, ii, nCurrent, rc
	rc = SQLITE_OK                                           /* Return code */
	nCurrent = (*TPager)(unsafe.Pointer(pPager)).FnSavepoint /* New Pager.aSavepoint array */
	/* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
	 ** if the allocation fails. Otherwise, zero the new portion in case a
	 ** malloc failure occurs while populating it in the for(...) loop below.
	 */
	aNew = _sqlite3Realloc(tls, (*TPager)(unsafe.Pointer(pPager)).FaSavepoint, uint64(uint32(48)*uint32(uint32(nSavepoint))))
	if !(aNew != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, aNew+uintptr(nCurrent)*48, 0, uint32(nSavepoint-nCurrent)*uint32(48))
	(*TPager)(unsafe.Pointer(pPager)).FaSavepoint = aNew
	/* Populate the PagerSavepoint structures just allocated. */
	ii = nCurrent
	for {
		if !(ii < nSavepoint) {
			break
		}
		(*(*TPagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*48))).FnOrig = (*TPager)(unsafe.Pointer(pPager)).FdbSize
		if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) && (*TPager)(unsafe.Pointer(pPager)).FjournalOff > 0 {
			(*(*TPagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*48))).FiOffset = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
		} else {
			(*(*TPagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*48))).FiOffset = int64((*TPager)(unsafe.Pointer(pPager)).FsectorSize)
		}
		(*(*TPagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*48))).FiSubRec = (*TPager)(unsafe.Pointer(pPager)).FnSubRec
		(*(*TPagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*48))).FpInSavepoint = _sqlite3BitvecCreate(tls, (*TPager)(unsafe.Pointer(pPager)).FdbSize)
		(*(*TPagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*48))).FbTruncateOnRelease = int32(1)
		if !((*(*TPagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*48))).FpInSavepoint != 0) {
			return int32(SQLITE_NOMEM)
		}
		if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
			_sqlite3WalSavepoint(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, aNew+uintptr(ii)*48+32)
		}
		(*TPager)(unsafe.Pointer(pPager)).FnSavepoint = ii + int32(1)
		goto _1
	_1:
		;
		ii++
	}
	return rc
}

func _sqlite3PagerOpenSavepoint(tls *libc.TLS, pPager uintptr, nSavepoint int32) (r int32) {
	if nSavepoint > (*TPager)(unsafe.Pointer(pPager)).FnSavepoint && (*TPager)(unsafe.Pointer(pPager)).FuseJournal != 0 {
		return _pagerOpenSavepoint(tls, pPager, nSavepoint)
	} else {
		return SQLITE_OK
	}
	return r
}

// C documentation
//
//	/*
//	** This function is called to rollback or release (commit) a savepoint.
//	** The savepoint to release or rollback need not be the most recently
//	** created savepoint.
//	**
//	** Parameter op is always either SAVEPOINT_ROLLBACK or SAVEPOINT_RELEASE.
//	** If it is SAVEPOINT_RELEASE, then release and destroy the savepoint with
//	** index iSavepoint. If it is SAVEPOINT_ROLLBACK, then rollback all changes
//	** that have occurred since the specified savepoint was created.
//	**
//	** The savepoint to rollback or release is identified by parameter
//	** iSavepoint. A value of 0 means to operate on the outermost savepoint
//	** (the first created). A value of (Pager.nSavepoint-1) means operate
//	** on the most recently created savepoint. If iSavepoint is greater than
//	** (Pager.nSavepoint-1), then this function is a no-op.
//	**
//	** If a negative value is passed to this function, then the current
//	** transaction is rolled back. This is different to calling
//	** sqlite3PagerRollback() because this function does not terminate
//	** the transaction or unlock the database, it just restores the
//	** contents of the database to its original state.
//	**
//	** In any case, all savepoints with an index greater than iSavepoint
//	** are destroyed. If this is a release operation (op==SAVEPOINT_RELEASE),
//	** then savepoint iSavepoint is also destroyed.
//	**
//	** This function may return SQLITE_NOMEM if a memory allocation fails,
//	** or an IO error code if an IO error occurs while rolling back a
//	** savepoint. If no errors occur, SQLITE_OK is returned.
//	*/
func _sqlite3PagerSavepoint(tls *libc.TLS, pPager uintptr, op int32, iSavepoint int32) (r int32) {
	var ii, nNew, rc, v1 int32
	var pRel, pSavepoint, v3 uintptr
	var sz Ti64
	_, _, _, _, _, _, _, _ = ii, nNew, pRel, pSavepoint, rc, sz, v1, v3
	rc = (*TPager)(unsafe.Pointer(pPager)).FerrCode
	if rc == SQLITE_OK && iSavepoint < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint { /* Number of remaining savepoints after this op. */
		/* Figure out how many savepoints will still be active after this
		 ** operation. Store this value in nNew. Then free resources associated
		 ** with any savepoints that are destroyed by this operation.
		 */
		if op == int32(SAVEPOINT_RELEASE) {
			v1 = 0
		} else {
			v1 = int32(1)
		}
		nNew = iSavepoint + v1
		ii = nNew
		for {
			if !(ii < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
				break
			}
			_sqlite3BitvecDestroy(tls, (*(*TPagerSavepoint)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*48))).FpInSavepoint)
			goto _2
		_2:
			;
			ii++
		}
		(*TPager)(unsafe.Pointer(pPager)).FnSavepoint = nNew
		/* Truncate the sub-journal so that it only includes the parts
		 ** that are still in use. */
		if op == int32(SAVEPOINT_RELEASE) {
			pRel = (*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(nNew)*48
			if (*TPagerSavepoint)(unsafe.Pointer(pRel)).FbTruncateOnRelease != 0 && (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fsjfd)).FpMethods != uintptr(0) {
				/* Only truncate if it is an in-memory sub-journal. */
				if _sqlite3JournalIsInMemory(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd) != 0 {
					sz = ((*TPager)(unsafe.Pointer(pPager)).FpageSize + int64(4)) * int64((*TPagerSavepoint)(unsafe.Pointer(pRel)).FiSubRec)
					rc = _sqlite3OsTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd, sz)
				}
				(*TPager)(unsafe.Pointer(pPager)).FnSubRec = (*TPagerSavepoint)(unsafe.Pointer(pRel)).FiSubRec
			}
		} else {
			if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) || (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
				if nNew == 0 {
					v3 = uintptr(0)
				} else {
					v3 = (*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(nNew-int32(1))*48
				}
				pSavepoint = v3
				rc = _pagerPlaybackSavepoint(tls, pPager, pSavepoint)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the full pathname of the database file.
//	**
//	** Except, if the pager is in-memory only, then return an empty string if
//	** nullIfMemDb is true.  This routine is called with nullIfMemDb==1 when
//	** used to report the filename to the user, for compatibility with legacy
//	** behavior.  But when the Btree needs to know the filename for matching to
//	** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
//	** participate in shared-cache.
//	**
//	** The return value to this routine is always safe to use with
//	** sqlite3_uri_parameter() and sqlite3_filename_database() and friends.
//	*/
func _sqlite3PagerFilename(tls *libc.TLS, pPager uintptr, nullIfMemDb int32) (r uintptr) {
	if nullIfMemDb != 0 && ((*TPager)(unsafe.Pointer(pPager)).FmemDb != 0 || _sqlite3IsMemdb(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs) != 0) {
		return uintptr(unsafe.Pointer(&_zFake)) + 4
	} else {
		return (*TPager)(unsafe.Pointer(pPager)).FzFilename
	}
	return r
}

var _zFake = [8]int8{}

// C documentation
//
//	/*
//	** Return the VFS structure for the pager.
//	*/
func _sqlite3PagerVfs(tls *libc.TLS, pPager uintptr) (r uintptr) {
	return (*TPager)(unsafe.Pointer(pPager)).FpVfs
}

// C documentation
//
//	/*
//	** Return the file handle for the database file associated
//	** with the pager.  This might return NULL if the file has
//	** not yet been opened.
//	*/
func _sqlite3PagerFile(tls *libc.TLS, pPager uintptr) (r uintptr) {
	return (*TPager)(unsafe.Pointer(pPager)).Ffd
}

// C documentation
//
//	/*
//	** Return the file handle for the journal file (if it exists).
//	** This will be either the rollback journal or the WAL file.
//	*/
func _sqlite3PagerJrnlFile(tls *libc.TLS, pPager uintptr) (r uintptr) {
	var v1 uintptr
	_ = v1
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		v1 = _sqlite3WalFile(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
	} else {
		v1 = (*TPager)(unsafe.Pointer(pPager)).Fjfd
	}
	return v1
}

// C documentation
//
//	/*
//	** Return the full pathname of the journal file.
//	*/
func _sqlite3PagerJournalname(tls *libc.TLS, pPager uintptr) (r uintptr) {
	return (*TPager)(unsafe.Pointer(pPager)).FzJournal
}

// C documentation
//
//	/*
//	** Move the page pPg to location pgno in the file.
//	**
//	** There must be no references to the page previously located at
//	** pgno (which we call pPgOld) though that page is allowed to be
//	** in cache.  If the page previously located at pgno is not already
//	** in the rollback journal, it is not put there by by this routine.
//	**
//	** References to the page pPg remain valid. Updating any
//	** meta-data associated with pPg (i.e. data stored in the nExtra bytes
//	** allocated along with the page) is the responsibility of the caller.
//	**
//	** A transaction must be active when this routine is called. It used to be
//	** required that a statement transaction was not active, but this restriction
//	** has been removed (CREATE INDEX needs to move a page when a statement
//	** transaction is active).
//	**
//	** If the fourth argument, isCommit, is non-zero, then this page is being
//	** moved as part of a database reorganization just before the transaction
//	** is being committed. In this case, it is guaranteed that the database page
//	** pPg refers to will not be written to again within this transaction.
//	**
//	** This function may return SQLITE_NOMEM or an IO error code if an error
//	** occurs. Otherwise, it returns SQLITE_OK.
//	*/
func _sqlite3PagerMovepage(tls *libc.TLS, pPager uintptr, pPg uintptr, pgno TPgno, isCommit int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var needSyncPgno, origPgno TPgno
	var pPgOld, p3, p4, p5 uintptr
	var rc, v1 int32
	var v2 bool
	var _ /* pPgHdr at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _ = needSyncPgno, origPgno, pPgOld, rc, v1, v2, p3, p4, p5 /* The page being overwritten. */
	needSyncPgno = uint32(0)                                                           /* The original page number */
	/* In order to be able to rollback, an in-memory database must journal
	 ** the page we are moving from.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 {
		rc = _sqlite3PagerWrite(tls, pPg)
		if rc != 0 {
			return rc
		}
	}
	/* If the page being moved is dirty and has not been saved by the latest
	 ** savepoint, then save the current contents of the page into the
	 ** sub-journal now. This is required to handle the following scenario:
	 **
	 **   BEGIN;
	 **     <journal page X, then modify it in memory>
	 **     SAVEPOINT one;
	 **       <Move page X to location Y>
	 **     ROLLBACK TO one;
	 **
	 ** If page X were not written to the sub-journal here, it would not
	 ** be possible to restore its contents when the "ROLLBACK TO one"
	 ** statement were is processed.
	 **
	 ** subjournalPage() may need to allocate space to store pPg->pgno into
	 ** one or more savepoint bitvecs. This is the reason this function
	 ** may return SQLITE_NOMEM.
	 */
	if v2 = int32((*TDbPage)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_DIRTY) != 0; v2 {
		v1 = _subjournalPageIfRequired(tls, pPg)
		rc = v1
	}
	if v2 && SQLITE_OK != v1 {
		return rc
	}
	/* If the journal needs to be sync()ed before page pPg->pgno can
	 ** be written to, store pPg->pgno in local variable needSyncPgno.
	 **
	 ** If the isCommit flag is set, there is no need to remember that
	 ** the journal needs to be sync()ed before database page pPg->pgno
	 ** can be written to. The caller has already promised not to write to it.
	 */
	if int32((*TDbPage)(unsafe.Pointer(pPg)).Fflags)&int32(PGHDR_NEED_SYNC) != 0 && !(isCommit != 0) {
		needSyncPgno = (*TDbPage)(unsafe.Pointer(pPg)).Fpgno
	}
	/* If the cache contains a page with page-number pgno, remove it
	 ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
	 ** page pgno before the 'move' operation, it needs to be retained
	 ** for the page moved there.
	 */
	p3 = pPg + 28
	*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(PGHDR_NEED_SYNC))
	pPgOld = _sqlite3PagerLookup(tls, pPager, pgno)
	if pPgOld != 0 {
		if (*TPgHdr)(unsafe.Pointer(pPgOld)).FnRef > int64(1) {
			_sqlite3PagerUnrefNotNull(tls, pPgOld)
			return _sqlite3CorruptError(tls, int32(64313))
		}
		p4 = pPg + 28
		*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | int32((*TPgHdr)(unsafe.Pointer(pPgOld)).Fflags)&libc.Int32FromInt32(PGHDR_NEED_SYNC))
		if (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 {
			/* Do not discard pages from an in-memory database since we might
			 ** need to rollback later.  Just move the page out of the way. */
			_sqlite3PcacheMove(tls, pPgOld, (*TPager)(unsafe.Pointer(pPager)).FdbSize+uint32(1))
		} else {
			_sqlite3PcacheDrop(tls, pPgOld)
		}
	}
	origPgno = (*TDbPage)(unsafe.Pointer(pPg)).Fpgno
	_sqlite3PcacheMove(tls, pPg, pgno)
	_sqlite3PcacheMakeDirty(tls, pPg)
	/* For an in-memory database, make sure the original page continues
	 ** to exist, in case the transaction needs to roll back.  Use pPgOld
	 ** as the original page since it has already been allocated.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FtempFile != 0 && pPgOld != 0 {
		_sqlite3PcacheMove(tls, pPgOld, origPgno)
		_sqlite3PagerUnrefNotNull(tls, pPgOld)
	}
	if needSyncPgno != 0 {
		rc = _sqlite3PagerGet(tls, pPager, needSyncPgno, bp, 0)
		if rc != SQLITE_OK {
			if needSyncPgno <= (*TPager)(unsafe.Pointer(pPager)).FdbOrigSize {
				_sqlite3BitvecClear(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal, needSyncPgno, (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace)
			}
			return rc
		}
		p5 = *(*uintptr)(unsafe.Pointer(bp)) + 28
		*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(PGHDR_NEED_SYNC))
		_sqlite3PcacheMakeDirty(tls, *(*uintptr)(unsafe.Pointer(bp)))
		_sqlite3PagerUnrefNotNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The page handle passed as the first argument refers to a dirty page
//	** with a page number other than iNew. This function changes the page's
//	** page number to iNew and sets the value of the PgHdr.flags field to
//	** the value passed as the third parameter.
//	*/
func _sqlite3PagerRekey(tls *libc.TLS, pPg uintptr, iNew TPgno, flags Tu16) {
	(*TDbPage)(unsafe.Pointer(pPg)).Fflags = flags
	_sqlite3PcacheMove(tls, pPg, iNew)
}

// C documentation
//
//	/*
//	** Return a pointer to the data for the specified page.
//	*/
func _sqlite3PagerGetData(tls *libc.TLS, pPg uintptr) (r uintptr) {
	return (*TDbPage)(unsafe.Pointer(pPg)).FpData
}

// C documentation
//
//	/*
//	** Return a pointer to the Pager.nExtra bytes of "extra" space
//	** allocated along with the specified page.
//	*/
func _sqlite3PagerGetExtra(tls *libc.TLS, pPg uintptr) (r uintptr) {
	return (*TDbPage)(unsafe.Pointer(pPg)).FpExtra
}

// C documentation
//
//	/*
//	** Get/set the locking-mode for this pager. Parameter eMode must be one
//	** of PAGER_LOCKINGMODE_QUERY, PAGER_LOCKINGMODE_NORMAL or
//	** PAGER_LOCKINGMODE_EXCLUSIVE. If the parameter is not _QUERY, then
//	** the locking-mode is set to the value specified.
//	**
//	** The returned value is either PAGER_LOCKINGMODE_NORMAL or
//	** PAGER_LOCKINGMODE_EXCLUSIVE, indicating the current (possibly updated)
//	** locking-mode.
//	*/
func _sqlite3PagerLockingMode(tls *libc.TLS, pPager uintptr, eMode int32) (r int32) {
	if eMode >= 0 && !((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0) && !(_sqlite3WalHeapMemory(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal) != 0) {
		(*TPager)(unsafe.Pointer(pPager)).FexclusiveMode = uint8(uint8(eMode))
	}
	return int32((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode)
}

// C documentation
//
//	/*
//	** Set the journal-mode for this pager. Parameter eMode must be one of:
//	**
//	**    PAGER_JOURNALMODE_DELETE
//	**    PAGER_JOURNALMODE_TRUNCATE
//	**    PAGER_JOURNALMODE_PERSIST
//	**    PAGER_JOURNALMODE_OFF
//	**    PAGER_JOURNALMODE_MEMORY
//	**    PAGER_JOURNALMODE_WAL
//	**
//	** The journalmode is set to the value specified if the change is allowed.
//	** The change may be disallowed for the following reasons:
//	**
//	**   *  An in-memory database can only have its journal_mode set to _OFF
//	**      or _MEMORY.
//	**
//	**   *  Temporary databases cannot have _WAL journalmode.
//	**
//	** The returned indicate the current (possibly updated) journal-mode.
//	*/
func _sqlite3PagerSetJournalMode(tls *libc.TLS, pPager uintptr, eMode int32) (r int32) {
	var eOld Tu8
	var rc, state int32
	_, _, _ = eOld, rc, state
	eOld = (*TPager)(unsafe.Pointer(pPager)).FjournalMode /* Prior journalmode */
	/* The eMode parameter is always valid */
	/* This routine is only called from the OP_JournalMode opcode, and
	 ** the logic there will never allow a temporary file to be changed
	 ** to WAL mode.
	 */
	/* Do allow the journalmode of an in-memory database to be set to
	 ** anything other than MEMORY or OFF
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FmemDb != 0 {
		if eMode != int32(PAGER_JOURNALMODE_MEMORY) && eMode != int32(PAGER_JOURNALMODE_OFF) {
			eMode = int32(int32(eOld))
		}
	}
	if eMode != int32(int32(eOld)) {
		/* Change the journal mode. */
		(*TPager)(unsafe.Pointer(pPager)).FjournalMode = uint8(uint8(eMode))
		/* When transitioning from TRUNCATE or PERSIST to any other journal
		 ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
		 ** delete the journal file.
		 */
		if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) && int32(int32(eOld))&int32(5) == int32(1) && eMode&int32(1) == 0 {
			/* In this case we would like to delete the journal file. If it is
			 ** not possible, then that is not a problem. Deleting the journal file
			 ** here is an optimization only.
			 **
			 ** Before deleting the journal file, obtain a RESERVED lock on the
			 ** database file. This ensures that the journal file is not deleted
			 ** while it is in use by some other client.
			 */
			_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
			if int32((*TPager)(unsafe.Pointer(pPager)).FeLock) >= int32(RESERVED_LOCK) {
				_sqlite3OsDelete(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, 0)
			} else {
				rc = SQLITE_OK
				state = int32((*TPager)(unsafe.Pointer(pPager)).FeState)
				if state == PAGER_OPEN {
					rc = _sqlite3PagerSharedLock(tls, pPager)
				}
				if int32((*TPager)(unsafe.Pointer(pPager)).FeState) == int32(PAGER_READER) {
					rc = _pagerLockDb(tls, pPager, int32(RESERVED_LOCK))
				}
				if rc == SQLITE_OK {
					_sqlite3OsDelete(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, (*TPager)(unsafe.Pointer(pPager)).FzJournal, 0)
				}
				if rc == SQLITE_OK && state == int32(PAGER_READER) {
					_pagerUnlockDb(tls, pPager, int32(SHARED_LOCK))
				} else {
					if state == PAGER_OPEN {
						_pager_unlock(tls, pPager)
					}
				}
			}
		} else {
			if eMode == int32(PAGER_JOURNALMODE_OFF) || eMode == int32(PAGER_JOURNALMODE_MEMORY) {
				_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
			}
		}
	}
	/* Return the new journal mode */
	return int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode)
}

// C documentation
//
//	/*
//	** Return the current journal mode.
//	*/
func _sqlite3PagerGetJournalMode(tls *libc.TLS, pPager uintptr) (r int32) {
	return int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode)
}

// C documentation
//
//	/*
//	** Return TRUE if the pager is in a state where it is OK to change the
//	** journalmode.  Journalmode changes can only happen when the database
//	** is unmodified.
//	*/
func _sqlite3PagerOkToChangeJournalMode(tls *libc.TLS, pPager uintptr) (r int32) {
	if int32((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_CACHEMOD) {
		return 0
	}
	if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) && (*TPager)(unsafe.Pointer(pPager)).FjournalOff > 0 {
		return 0
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Get/set the size-limit used for persistent journal files.
//	**
//	** Setting the size limit to -1 means no limit is enforced.
//	** An attempt to set a limit smaller than -1 is a no-op.
//	*/
func _sqlite3PagerJournalSizeLimit(tls *libc.TLS, pPager uintptr, iLimit Ti64) (r Ti64) {
	if iLimit >= int64(-int32(1)) {
		(*TPager)(unsafe.Pointer(pPager)).FjournalSizeLimit = iLimit
		_sqlite3WalLimit(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, iLimit)
	}
	return (*TPager)(unsafe.Pointer(pPager)).FjournalSizeLimit
}

// C documentation
//
//	/*
//	** Return a pointer to the pPager->pBackup variable. The backup module
//	** in backup.c maintains the content of this variable. This module
//	** uses it opaquely as an argument to sqlite3BackupRestart() and
//	** sqlite3BackupUpdate() only.
//	*/
func _sqlite3PagerBackupPtr(tls *libc.TLS, pPager uintptr) (r uintptr) {
	return pPager + 96
}

// C documentation
//
//	/*
//	** Unless this is an in-memory or temporary database, clear the pager cache.
//	*/
func _sqlite3PagerClearCache(tls *libc.TLS, pPager uintptr) {
	if int32((*TPager)(unsafe.Pointer(pPager)).FtempFile) == 0 {
		_pager_reset(tls, pPager)
	}
}

// C documentation
//
//	/*
//	** This function is called when the user invokes "PRAGMA wal_checkpoint",
//	** "PRAGMA wal_blocking_checkpoint" or calls the sqlite3_wal_checkpoint()
//	** or wal_blocking_checkpoint() API functions.
//	**
//	** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
//	*/
func _sqlite3PagerCheckpoint(tls *libc.TLS, pPager uintptr, db uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) (r int32) {
	var rc int32
	var v1 uintptr
	_, _ = rc, v1
	rc = SQLITE_OK
	if (*TPager)(unsafe.Pointer(pPager)).FpWal == uintptr(0) && int32((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_WAL) {
		/* This only happens when a database file is zero bytes in size opened and
		 ** then "PRAGMA journal_mode=WAL" is run and then sqlite3_wal_checkpoint()
		 ** is invoked without any intervening transactions.  We need to start
		 ** a transaction to initialize pWal.  The PRAGMA table_list statement is
		 ** used for this since it starts transactions on every database file,
		 ** including all ATTACHed databases.  This seems expensive for a single
		 ** sqlite3_wal_checkpoint() call, but it happens very rarely.
		 ** https://sqlite.org/forum/forumpost/fd0f19d229156939
		 */
		Xsqlite3_exec(tls, db, __ccgo_ts+5482, uintptr(0), uintptr(0), uintptr(0))
	}
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		if eMode == SQLITE_CHECKPOINT_PASSIVE {
			v1 = uintptr(0)
		} else {
			v1 = (*TPager)(unsafe.Pointer(pPager)).FxBusyHandler
		}
		rc = _sqlite3WalCheckpoint(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, db, eMode, v1, (*TPager)(unsafe.Pointer(pPager)).FpBusyHandlerArg, int32((*TPager)(unsafe.Pointer(pPager)).FwalSyncFlags), int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace, pnLog, pnCkpt)
	}
	return rc
}

func _sqlite3PagerWalCallback(tls *libc.TLS, pPager uintptr) (r int32) {
	return _sqlite3WalCallback(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
}

// C documentation
//
//	/*
//	** Return true if the underlying VFS for the given pager supports the
//	** primitives necessary for write-ahead logging.
//	*/
func _sqlite3PagerWalSupported(tls *libc.TLS, pPager uintptr) (r int32) {
	var pMethods uintptr
	_ = pMethods
	pMethods = (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods
	if (*TPager)(unsafe.Pointer(pPager)).FnoLock != 0 {
		return 0
	}
	return libc.BoolInt32((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 || (*Tsqlite3_io_methods)(unsafe.Pointer(pMethods)).FiVersion >= int32(2) && (*Tsqlite3_io_methods)(unsafe.Pointer(pMethods)).FxShmMap != 0)
}

// C documentation
//
//	/*
//	** Attempt to take an exclusive lock on the database file. If a PENDING lock
//	** is obtained instead, immediately release it.
//	*/
func _pagerExclusiveLock(tls *libc.TLS, pPager uintptr) (r int32) {
	var eOrigLock Tu8
	var rc int32
	_, _ = eOrigLock, rc /* Original lock */
	eOrigLock = (*TPager)(unsafe.Pointer(pPager)).FeLock
	rc = _pagerLockDb(tls, pPager, int32(EXCLUSIVE_LOCK))
	if rc != SQLITE_OK {
		/* If the attempt to grab the exclusive lock failed, release the
		 ** pending lock that may have been obtained instead.  */
		_pagerUnlockDb(tls, pPager, int32(int32(eOrigLock)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Call sqlite3WalOpen() to open the WAL handle. If the pager is in
//	** exclusive-locking mode when this function is called, take an EXCLUSIVE
//	** lock on the database file and use heap-memory to store the wal-index
//	** in. Otherwise, use the normal shared-memory.
//	*/
func _pagerOpenWal(tls *libc.TLS, pPager uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	/* If the pager is already in exclusive-mode, the WAL module will use
	 ** heap-memory for the wal-index instead of the VFS shared-memory
	 ** implementation. Take the exclusive lock now, before opening the WAL
	 ** file, to make sure this is safe.
	 */
	if (*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 {
		rc = _pagerExclusiveLock(tls, pPager)
	}
	/* Open the connection to the log file. If this operation fails,
	 ** (e.g. due to malloc() failure), return an error code.
	 */
	if rc == SQLITE_OK {
		rc = _sqlite3WalOpen(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, (*TPager)(unsafe.Pointer(pPager)).Ffd, (*TPager)(unsafe.Pointer(pPager)).FzWal, int32((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode), (*TPager)(unsafe.Pointer(pPager)).FjournalSizeLimit, pPager+232)
	}
	_pagerFixMaplimit(tls, pPager)
	return rc
}

// C documentation
//
//	/*
//	** The caller must be holding a SHARED lock on the database file to call
//	** this function.
//	**
//	** If the pager passed as the first argument is open on a real database
//	** file (not a temp file or an in-memory database), and the WAL file
//	** is not already open, make an attempt to open it now. If successful,
//	** return SQLITE_OK. If an error occurs or the VFS used by the pager does
//	** not support the xShmXXX() methods, return an error code. *pbOpen is
//	** not modified in either case.
//	**
//	** If the pager is open on a temp-file (or in-memory database), or if
//	** the WAL file is already open, set *pbOpen to 1 and return SQLITE_OK
//	** without doing anything.
//	*/
func _sqlite3PagerOpenWal(tls *libc.TLS, pPager uintptr, pbOpen uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK /* Return code */
	if !((*TPager)(unsafe.Pointer(pPager)).FtempFile != 0) && !((*TPager)(unsafe.Pointer(pPager)).FpWal != 0) {
		if !(_sqlite3PagerWalSupported(tls, pPager) != 0) {
			return int32(SQLITE_CANTOPEN)
		}
		/* Close any rollback journal previously open */
		_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd)
		rc = _pagerOpenWal(tls, pPager)
		if rc == SQLITE_OK {
			(*TPager)(unsafe.Pointer(pPager)).FjournalMode = uint8(PAGER_JOURNALMODE_WAL)
			(*TPager)(unsafe.Pointer(pPager)).FeState = uint8(PAGER_OPEN)
		}
	} else {
		*(*int32)(unsafe.Pointer(pbOpen)) = int32(1)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called to close the connection to the log file prior
//	** to switching from WAL to rollback mode.
//	**
//	** Before closing the log file, this function attempts to take an
//	** EXCLUSIVE lock on the database file. If this cannot be obtained, an
//	** error (SQLITE_BUSY) is returned and the log connection is not closed.
//	** If successful, the EXCLUSIVE lock is not released before returning.
//	*/
func _sqlite3PagerCloseWal(tls *libc.TLS, pPager uintptr, db uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* logexists at bp+0 */ int32
	_ = rc
	rc = SQLITE_OK
	/* If the log file is not already open, but does exist in the file-system,
	 ** it may need to be checkpointed before the connection can switch to
	 ** rollback mode. Open it now so this can happen.
	 */
	if !((*TPager)(unsafe.Pointer(pPager)).FpWal != 0) {
		*(*int32)(unsafe.Pointer(bp)) = 0
		rc = _pagerLockDb(tls, pPager, int32(SHARED_LOCK))
		if rc == SQLITE_OK {
			rc = _sqlite3OsAccess(tls, (*TPager)(unsafe.Pointer(pPager)).FpVfs, (*TPager)(unsafe.Pointer(pPager)).FzWal, SQLITE_ACCESS_EXISTS, bp)
		}
		if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
			rc = _pagerOpenWal(tls, pPager)
		}
	}
	/* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
	 ** the database file, the log and log-summary files will be deleted.
	 */
	if rc == SQLITE_OK && (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		rc = _pagerExclusiveLock(tls, pPager)
		if rc == SQLITE_OK {
			rc = _sqlite3WalClose(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, db, int32((*TPager)(unsafe.Pointer(pPager)).FwalSyncFlags), int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace)
			(*TPager)(unsafe.Pointer(pPager)).FpWal = uintptr(0)
			_pagerFixMaplimit(tls, pPager)
			if rc != 0 && !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) {
				_pagerUnlockDb(tls, pPager, int32(SHARED_LOCK))
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** If this is a WAL database, obtain a snapshot handle for the snapshot
//	** currently open. Otherwise, return an error.
//	*/
func _sqlite3PagerSnapshotGet(tls *libc.TLS, pPager uintptr, ppSnapshot uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = int32(SQLITE_ERROR)
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		rc = _sqlite3WalSnapshotGet(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, ppSnapshot)
	}
	return rc
}

// C documentation
//
//	/*
//	** If this is a WAL database, store a pointer to pSnapshot. Next time a
//	** read transaction is opened, attempt to read from the snapshot it
//	** identifies. If this is not a WAL database, return an error.
//	*/
func _sqlite3PagerSnapshotOpen(tls *libc.TLS, pPager uintptr, pSnapshot uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		_sqlite3WalSnapshotOpen(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, pSnapshot)
	} else {
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

// C documentation
//
//	/*
//	** If this is a WAL database, call sqlite3WalSnapshotRecover(). If this
//	** is not a WAL database, return an error.
//	*/
func _sqlite3PagerSnapshotRecover(tls *libc.TLS, pPager uintptr) (r int32) {
	var rc int32
	_ = rc
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		rc = _sqlite3WalSnapshotRecover(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
	} else {
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

// C documentation
//
//	/*
//	** The caller currently has a read transaction open on the database.
//	** If this is not a WAL database, SQLITE_ERROR is returned. Otherwise,
//	** this function takes a SHARED lock on the CHECKPOINTER slot and then
//	** checks if the snapshot passed as the second argument is still
//	** available. If so, SQLITE_OK is returned.
//	**
//	** If the snapshot is not available, SQLITE_ERROR is returned. Or, if
//	** the CHECKPOINTER lock cannot be obtained, SQLITE_BUSY. If any error
//	** occurs (any value other than SQLITE_OK is returned), the CHECKPOINTER
//	** lock is released before returning.
//	*/
func _sqlite3PagerSnapshotCheck(tls *libc.TLS, pPager uintptr, pSnapshot uintptr) (r int32) {
	var rc int32
	_ = rc
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		rc = _sqlite3WalSnapshotCheck(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, pSnapshot)
	} else {
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

// C documentation
//
//	/*
//	** Release a lock obtained by an earlier successful call to
//	** sqlite3PagerSnapshotCheck().
//	*/
func _sqlite3PagerSnapshotUnlock(tls *libc.TLS, pPager uintptr) {
	_sqlite3WalSnapshotUnlock(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal)
}

/************** End of pager.c ***********************************************/
/************** Begin file wal.c *********************************************/
/*
** 2010 February 1
**
** 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 implementation of a write-ahead log (WAL) used in
** "journal_mode=WAL" mode.
**
** WRITE-AHEAD LOG (WAL) FILE FORMAT
**
** A WAL file consists of a header followed by zero or more "frames".
** Each frame records the revised content of a single page from the
** database file.  All changes to the database are recorded by writing
** frames into the WAL.  Transactions commit when a frame is written that
** contains a commit marker.  A single WAL can and usually does record
** multiple transactions.  Periodically, the content of the WAL is
** transferred back into the database file in an operation called a
** "checkpoint".
**
** A single WAL file can be used multiple times.  In other words, the
** WAL can fill up with frames and then be checkpointed and then new
** frames can overwrite the old ones.  A WAL always grows from beginning
** toward the end.  Checksums and counters attached to each frame are
** used to determine which frames within the WAL are valid and which
** are leftovers from prior checkpoints.
**
** The WAL header is 32 bytes in size and consists of the following eight
** big-endian 32-bit unsigned integer values:
**
**     0: Magic number.  0x377f0682 or 0x377f0683
**     4: File format version.  Currently 3007000
**     8: Database page size.  Example: 1024
**    12: Checkpoint sequence number
**    16: Salt-1, random integer incremented with each checkpoint
**    20: Salt-2, a different random integer changing with each ckpt
**    24: Checksum-1 (first part of checksum for first 24 bytes of header).
**    28: Checksum-2 (second part of checksum for first 24 bytes of header).
**
** Immediately following the wal-header are zero or more frames. Each
** frame consists of a 24-byte frame-header followed by a <page-size> bytes
** of page data. The frame-header is six big-endian 32-bit unsigned
** integer values, 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 header)
**    12: Salt-2 (copied from the header)
**    16: Checksum-1.
**    20: Checksum-2.
**
** A frame is considered valid if and only if the following conditions are
** true:
**
**    (1) The salt-1 and salt-2 values in the frame-header match
**        salt values in the wal-header
**
**    (2) The checksum values in the final 8 bytes of the frame-header
**        exactly match the checksum computed consecutively on the
**        WAL header and the first 8 bytes and the content of all frames
**        up to and including the current frame.
**
** The checksum is computed using 32-bit big-endian integers if the
** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
** is computed using little-endian if the magic number is 0x377f0682.
** The checksum values are always stored in the frame header in a
** big-endian format regardless of which byte order is used to compute
** the checksum.  The checksum is computed by interpreting the input as
** an even number of unsigned 32-bit integers: x[0] through x[N].  The
** algorithm used for the checksum is as follows:
**
**   for i from 0 to n-1 step 2:
**     s0 += x[i] + s1;
**     s1 += x[i+1] + s0;
**   endfor
**
** Note that s0 and s1 are both weighted checksums using fibonacci weights
** in reverse order (the largest fibonacci weight occurs on the first element
** of the sequence being summed.)  The s1 value spans all 32-bit
** terms of the sequence whereas s0 omits the final term.
**
** On a checkpoint, the WAL is first VFS.xSync-ed, then valid content of the
** WAL is transferred into the database, then the database is VFS.xSync-ed.
** The VFS.xSync operations serve as write barriers - all writes launched
** before the xSync must complete before any write that launches after the
** xSync begins.
**
** After each checkpoint, the salt-1 value is incremented and the salt-2
** value is randomized.  This prevents old and new frames in the WAL from
** being considered valid at the same time and being checkpointing together
** following a crash.
**
** READER ALGORITHM
**
** To read a page from the database (call it page number P), a reader
** first checks the WAL to see if it contains page P.  If so, then the
** last valid instance of page P that is a followed by a commit frame
** or is a commit frame itself becomes the value read.  If the WAL
** contains no copies of page P that are valid and which are a commit
** frame or are followed by a commit frame, then page P is read from
** the database file.
**
** To start a read transaction, the reader records the index of the last
** valid frame in the WAL.  The reader uses this recorded "mxFrame" value
** for all subsequent read operations.  New transactions can be appended
** to the WAL, but as long as the reader uses its original mxFrame value
** and ignores the newly appended content, it will see a consistent snapshot
** of the database from a single point in time.  This technique allows
** multiple concurrent readers to view different versions of the database
** content simultaneously.
**
** The reader algorithm in the previous paragraphs works correctly, but
** because frames for page P can appear anywhere within the WAL, the
** reader has to scan the entire WAL looking for page P frames.  If the
** WAL is large (multiple megabytes is typical) that scan can be slow,
** and read performance suffers.  To overcome this problem, a separate
** data structure called the wal-index is maintained to expedite the
** search for frames of a particular page.
**
** WAL-INDEX FORMAT
**
** Conceptually, the wal-index is shared memory, though VFS implementations
** might choose to implement the wal-index using a mmapped file.  Because
** the wal-index is shared memory, SQLite does not support journal_mode=WAL
** on a network filesystem.  All users of the database must be able to
** share memory.
**
** In the default unix and windows implementation, the wal-index is a mmapped
** file whose name is the database name with a "-shm" suffix added.  For that
** reason, the wal-index is sometimes called the "shm" file.
**
** The wal-index is transient.  After a crash, the wal-index can (and should
** be) reconstructed from the original WAL file.  In fact, the VFS is required
** to either truncate or zero the header of the wal-index when the last
** connection to it closes.  Because the wal-index is transient, it can
** use an architecture-specific format; it does not have to be cross-platform.
** Hence, unlike the database and WAL file formats which store all values
** as big endian, the wal-index can store multi-byte values in the native
** byte order of the host computer.
**
** The purpose of the wal-index is to answer this question quickly:  Given
** a page number P and a maximum frame index M, return the index of the
** last frame in the wal before frame M for page P in the WAL, or return
** NULL if there are no frames for page P in the WAL prior to M.
**
** The wal-index consists of a header region, followed by an one or
** more index blocks.
**
** The wal-index header contains the total number of frames within the WAL
** in the mxFrame field.
**
** Each index block except for the first contains information on
** HASHTABLE_NPAGE frames. The first index block contains information on
** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and
** HASHTABLE_NPAGE are selected so that together the wal-index header and
** first index block are the same size as all other index blocks in the
** wal-index.  The values are:
**
**   HASHTABLE_NPAGE      4096
**   HASHTABLE_NPAGE_ONE  4062
**
** Each index block contains two sections, a page-mapping that contains the
** database page number associated with each wal frame, and a hash-table
** that allows readers to query an index block for a specific page number.
** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
** for the first index block) 32-bit page numbers. The first entry in the
** first index-block contains the database page number corresponding to the
** first frame in the WAL file. The first entry in the second index block
** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
** the log, and so on.
**
** The last index block in a wal-index usually contains less than the full
** complement of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE) page-numbers,
** depending on the contents of the WAL file. This does not change the
** allocated size of the page-mapping array - the page-mapping array merely
** contains unused entries.
**
** Even without using the hash table, the last frame for page P
** can be found by scanning the page-mapping sections of each index block
** starting with the last index block and moving toward the first, and
** within each index block, starting at the end and moving toward the
** beginning.  The first entry that equals P corresponds to the frame
** holding the content for that page.
**
** The hash table consists of HASHTABLE_NSLOT 16-bit unsigned integers.
** HASHTABLE_NSLOT = 2*HASHTABLE_NPAGE, and there is one entry in the
** hash table for each page number in the mapping section, so the hash
** table is never more than half full.  The expected number of collisions
** prior to finding a match is 1.  Each entry of the hash table is an
** 1-based index of an entry in the mapping section of the same
** index block.   Let K be the 1-based index of the largest entry in
** the mapping section.  (For index blocks other than the last, K will
** always be exactly HASHTABLE_NPAGE (4096) and for the last index block
** K will be (mxFrame%HASHTABLE_NPAGE).)  Unused slots of the hash table
** contain a value of 0.
**
** To look for page P in the hash table, first compute a hash iKey on
** P as follows:
**
**      iKey = (P * 383) % HASHTABLE_NSLOT
**
** Then start scanning entries of the hash table, starting with iKey
** (wrapping around to the beginning when the end of the hash table is
** reached) until an unused hash slot is found. Let the first unused slot
** be at index iUnused.  (iUnused might be less than iKey if there was
** wrap-around.) Because the hash table is never more than half full,
** the search is guaranteed to eventually hit an unused entry.  Let
** iMax be the value between iKey and iUnused, closest to iUnused,
** where aHash[iMax]==P.  If there is no iMax entry (if there exists
** no hash slot such that aHash[i]==p) then page P is not in the
** current index block.  Otherwise the iMax-th mapping entry of the
** current index block corresponds to the last entry that references
** page P.
**
** A hash search begins with the last index block and moves toward the
** first index block, looking for entries corresponding to page P.  On
** average, only two or three slots in each index block need to be
** examined in order to either find the last entry for page P, or to
** establish that no such entry exists in the block.  Each index block
** holds over 4000 entries.  So two or three index blocks are sufficient
** to cover a typical 10 megabyte WAL file, assuming 1K pages.  8 or 10
** comparisons (on average) suffice to either locate a frame in the
** WAL or to establish that the frame does not exist in the WAL.  This
** is much faster than scanning the entire 10MB WAL.
**
** Note that entries are added in order of increasing K.  Hence, one
** reader might be using some value K0 and a second reader that started
** at a later time (after additional transactions were added to the WAL
** and to the wal-index) might be using a different value K1, where K1>K0.
** Both readers can use the same hash table and mapping section to get
** the correct result.  There may be entries in the hash table with
** K>K0 but to the first reader, those entries will appear to be unused
** slots in the hash table and so the first reader will get an answer as
** if no values greater than K0 had ever been inserted into the hash table
** in the first place - which is what reader one wants.  Meanwhile, the
** second reader using K1 will see additional values that were inserted
** later, which is exactly what reader two wants.
**
** When a rollback occurs, the value of K is decreased. Hash table entries
** that correspond to frames greater than the new K value are removed
** from the hash table at this point.
 */

/* #include "wal.h" */

/*
** Trace output macros
 */

/*
** The maximum (and only) versions of the wal and wal-index formats
** that may be interpreted by this version of SQLite.
**
** If a client begins recovering a WAL file and finds that (a) the checksum
** values in the wal-header are correct and (b) the version field is not
** WAL_MAX_VERSION, recovery fails and SQLite returns SQLITE_CANTOPEN.
**
** Similarly, if a client successfully reads a wal-index header (i.e. the
** checksum test is successful) and finds that the version field is not
** WALINDEX_MAX_VERSION, then no read-transaction is opened and SQLite
** returns SQLITE_CANTOPEN.
 */

/*
** Index numbers for various locking bytes.   WAL_NREADER is the number
** of available reader locks and should be at least 3.  The default
** is SQLITE_SHM_NLOCK==8 and  WAL_NREADER==5.
**
** Technically, the various VFSes are free to implement these locks however
** they see fit.  However, compatibility is encouraged so that VFSes can
** interoperate.  The standard implementation used on both unix and windows
** is for the index number to indicate a byte offset into the
** WalCkptInfo.aLock[] array in the wal-index header.  In other words, all
** locks are on the shm file.  The WALINDEX_LOCK_OFFSET constant (which
** should be 120) is the location in the shm file for the first locking
** byte.
 */

// C documentation
//
//	/* Object declarations */
type TWalIndexHdr = struct {
	FiVersion    Tu32
	Funused      Tu32
	FiChange     Tu32
	FisInit      Tu8
	FbigEndCksum Tu8
	FszPage      Tu16
	FmxFrame     Tu32
	FnPage       Tu32
	FaFrameCksum [2]Tu32
	FaSalt       [2]Tu32
	FaCksum      [2]Tu32
}

type WalIndexHdr = TWalIndexHdr

type TWalIterator = struct {
	FiPrior   Tu32
	FnSegment int32
	FaSegment [1]TWalSegment
}

type WalIterator = TWalIterator

type TWalCkptInfo = struct {
	FnBackfill          Tu32
	FaReadMark          [5]Tu32
	FaLock              [8]Tu8
	FnBackfillAttempted Tu32
	FnotUsed0           Tu32
}

type WalCkptInfo = TWalCkptInfo

/*
** The following object holds a copy of the wal-index header content.
**
** The actual header in the wal-index consists of two copies of this
** object followed by one instance of the WalCkptInfo object.
** For all versions of SQLite through 3.10.0 and probably beyond,
** the locking bytes (WalCkptInfo.aLock) start at offset 120 and
** the total header size is 136 bytes.
**
** The szPage value can be any power of 2 between 512 and 32768, inclusive.
** Or it can be 1 to represent a 65536-byte page.  The latter case was
** added in 3.7.1 when support for 64K pages was added.
 */
type TWalIndexHdr1 = struct {
	FiVersion    Tu32
	Funused      Tu32
	FiChange     Tu32
	FisInit      Tu8
	FbigEndCksum Tu8
	FszPage      Tu16
	FmxFrame     Tu32
	FnPage       Tu32
	FaFrameCksum [2]Tu32
	FaSalt       [2]Tu32
	FaCksum      [2]Tu32
}

type WalIndexHdr1 = TWalIndexHdr1

/*
** A copy of the following object occurs in the wal-index immediately
** following the second copy of the WalIndexHdr.  This object stores
** information used by checkpoint.
**
** nBackfill is the number of frames in the WAL that have been written
** back into the database. (We call the act of moving content from WAL to
** database "backfilling".)  The nBackfill number is never greater than
** WalIndexHdr.mxFrame.  nBackfill can only be increased by threads
** holding the WAL_CKPT_LOCK lock (which includes a recovery thread).
** However, a WAL_WRITE_LOCK thread can move the value of nBackfill from
** mxFrame back to zero when the WAL is reset.
**
** nBackfillAttempted is the largest value of nBackfill that a checkpoint
** has attempted to achieve.  Normally nBackfill==nBackfillAtempted, however
** the nBackfillAttempted is set before any backfilling is done and the
** nBackfill is only set after all backfilling completes.  So if a checkpoint
** crashes, nBackfillAttempted might be larger than nBackfill.  The
** WalIndexHdr.mxFrame must never be less than nBackfillAttempted.
**
** The aLock[] field is a set of bytes used for locking.  These bytes should
** never be read or written.
**
** There is one entry in aReadMark[] for each reader lock.  If a reader
** holds read-lock K, then the value in aReadMark[K] is no greater than
** the mxFrame for that reader.  The value READMARK_NOT_USED (0xffffffff)
** for any aReadMark[] means that entry is unused.  aReadMark[0] is
** a special case; its value is never used and it exists as a place-holder
** to avoid having to offset aReadMark[] indexes by one.  Readers holding
** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
** directly from the database.
**
** The value of aReadMark[K] may only be changed by a thread that
** is holding an exclusive lock on WAL_READ_LOCK(K).  Thus, the value of
** aReadMark[K] cannot changed while there is a reader is using that mark
** since the reader will be holding a shared lock on WAL_READ_LOCK(K).
**
** The checkpointer may only transfer frames from WAL to database where
** the frame numbers are less than or equal to every aReadMark[] that is
** in use (that is, every aReadMark[j] for which there is a corresponding
** WAL_READ_LOCK(j)).  New readers (usually) pick the aReadMark[] with the
** largest value and will increase an unused aReadMark[] to mxFrame if there
** is not already an aReadMark[] equal to mxFrame.  The exception to the
** previous sentence is when nBackfill equals mxFrame (meaning that everything
** in the WAL has been backfilled into the database) then new readers
** will choose aReadMark[0] which has value 0 and hence such reader will
** get all their all content directly from the database file and ignore
** the WAL.
**
** Writers normally append new frames to the end of the WAL.  However,
** if nBackfill equals mxFrame (meaning that all WAL content has been
** written back into the database) and if no readers are using the WAL
** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
** the writer will first "reset" the WAL back to the beginning and start
** writing new content beginning at frame 1.
**
** We assume that 32-bit loads are atomic and so no locks are needed in
** order to read from any aReadMark[] entries.
 */
type TWalCkptInfo1 = struct {
	FnBackfill          Tu32
	FaReadMark          [5]Tu32
	FaLock              [8]Tu8
	FnBackfillAttempted Tu32
	FnotUsed0           Tu32
}

type WalCkptInfo1 = TWalCkptInfo1

/*
** This is a schematic view of the complete 136-byte header of the
** wal-index file (also known as the -shm file):
**
**      +-----------------------------+
**   0: | iVersion                    | **      +-----------------------------+  |
**   4: | (unused padding)            |  |
**      +-----------------------------+  |
**   8: | iChange                     |  |
**      +-------+-------+-------------+  |
**  12: | bInit |  bBig |   szPage    |  |
**      +-------+-------+-------------+  |
**  16: | mxFrame                     |  |  First copy of the
**      +-----------------------------+  |  WalIndexHdr object
**  20: | nPage                       |  |
**      +-----------------------------+  |
**  24: | aFrameCksum                 |  |
**      |                             |  |
**      +-----------------------------+  |
**  32: | aSalt                       |  |
**      |                             |  |
**      +-----------------------------+  |
**  40: | aCksum                      |  |
**      |                             | /
**      +-----------------------------+
**  48: | iVersion                    | **      +-----------------------------+  |
**  52: | (unused padding)            |  |
**      +-----------------------------+  |
**  56: | iChange                     |  |
**      +-------+-------+-------------+  |
**  60: | bInit |  bBig |   szPage    |  |
**      +-------+-------+-------------+  |  Second copy of the
**  64: | mxFrame                     |  |  WalIndexHdr
**      +-----------------------------+  |
**  68: | nPage                       |  |
**      +-----------------------------+  |
**  72: | aFrameCksum                 |  |
**      |                             |  |
**      +-----------------------------+  |
**  80: | aSalt                       |  |
**      |                             |  |
**      +-----------------------------+  |
**  88: | aCksum                      |  |
**      |                             | /
**      +-----------------------------+
**  96: | nBackfill                   |
**      +-----------------------------+
** 100: | 5 read marks                |
**      |                             |
**      |                             |
**      |                             |
**      |                             |
**      +-------+-------+------+------+
** 120: | Write | Ckpt  | Rcvr | Rd0  | **      +-------+-------+------+------+  ) 8 lock bytes
**      | Read1 | Read2 | Rd3  | Rd4  | /
**      +-------+-------+------+------+
** 128: | nBackfillAttempted          |
**      +-----------------------------+
** 132: | (unused padding)            |
**      +-----------------------------+
 */

/* A block of WALINDEX_LOCK_RESERVED bytes beginning at
** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems
** only support mandatory file-locks, we do not read or write data
** from the region of the file on which locks are applied.
 */

/* Size of header before each frame in wal */

/* Size of write ahead log header, including checksum. */

/* WAL magic value. Either this value, or the same value with the least
** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
** big-endian format in the first 4 bytes of a WAL file.
**
** If the LSB is set, then the checksums for each frame within the WAL
** file are calculated by treating all data as an array of 32-bit
** big-endian words. Otherwise, they are calculated by interpreting
** all data as 32-bit little-endian words.
 */

/*
** Return the offset of frame iFrame in the write-ahead log file,
** assuming a database page size of szPage bytes. The offset returned
** is to the start of the write-ahead log frame-header.
 */

/*
** An open write-ahead log file is represented by an instance of the
** following object.
 */
type TWal1 = struct {
	F__ccgo_align        [0]uint32
	FpVfs                uintptr
	FpDbFd               uintptr
	FpWalFd              uintptr
	FiCallback           Tu32
	FmxWalSize           Ti64
	FnWiData             int32
	FszFirstBlock        int32
	FapWiData            uintptr
	FszPage              Tu32
	FreadLock            Ti16
	FsyncFlags           Tu8
	FexclusiveMode       Tu8
	FwriteLock           Tu8
	FckptLock            Tu8
	FreadOnly            Tu8
	FtruncateOnCommit    Tu8
	FsyncHeader          Tu8
	FpadToSectorBoundary Tu8
	FbShmUnreliable      Tu8
	Fhdr                 TWalIndexHdr
	FminFrame            Tu32
	FiReCksum            Tu32
	FzWalName            uintptr
	FnCkpt               Tu32
	FpSnapshot           uintptr
}

type Wal1 = TWal1

/*
** Candidate values for Wal.exclusiveMode.
 */

/*
** Possible values for WAL.readOnly
 */

// C documentation
//
//	/*
//	** Each page of the wal-index mapping contains a hash-table made up of
//	** an array of HASHTABLE_NSLOT elements of the following type.
//	*/
type Tht_slot = uint16

type ht_slot = Tht_slot

/*
** This structure is used to implement an iterator that loops through
** all frames in the WAL in database page order. Where two or more frames
** correspond to the same database page, the iterator visits only the
** frame most recently written to the WAL (in other words, the frame with
** the largest index).
**
** The internals of this structure are only accessed by:
**
**   walIteratorInit() - Create a new iterator,
**   walIteratorNext() - Step an iterator,
**   walIteratorFree() - Free an iterator.
**
** This functionality is used by the checkpoint code (see walCheckpoint()).
 */
type TWalIterator1 = struct {
	FiPrior   Tu32
	FnSegment int32
	FaSegment [1]TWalSegment
}

type WalIterator1 = TWalIterator1

/*
** Define the parameters of the hash tables in the wal-index file. There
** is a hash-table following every HASHTABLE_NPAGE page numbers in the
** wal-index.
**
** Changing any of these constants will alter the wal-index format and
** create incompatibilities.
 */

/*
** The block of page numbers associated with the first hash-table in a
** wal-index is smaller than usual. This is so that there is a complete
** hash-table on each aligned 32KB page of the wal-index.
 */

/* The wal-index is divided into pages of WALINDEX_PGSZ bytes each. */

/*
** Structured Exception Handling (SEH) is a Windows-specific technique
** for catching exceptions raised while accessing memory-mapped files.
**
** The -DSQLITE_USE_SEH compile-time option means to use SEH to catch and
** deal with system-level errors that arise during WAL -shm file processing.
** Without this compile-time option, any system-level faults that appear
** while accessing the memory-mapped -shm file will cause a process-wide
** signal to be deliver, which will more than likely cause the entire
** process to exit.
 */

// C documentation
//
//	/*
//	** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
//	** is broken into pages of WALINDEX_PGSZ bytes. Wal-index pages are
//	** numbered from zero.
//	**
//	** If the wal-index is currently smaller the iPage pages then the size
//	** of the wal-index might be increased, but only if it is safe to do
//	** so.  It is safe to enlarge the wal-index if pWal->writeLock is true
//	** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE.
//	**
//	** Three possible result scenarios:
//	**
//	**   (1)  rc==SQLITE_OK    and *ppPage==Requested-Wal-Index-Page
//	**   (2)  rc>=SQLITE_ERROR and *ppPage==NULL
//	**   (3)  rc==SQLITE_OK    and *ppPage==NULL  // only if iPage==0
//	**
//	** Scenario (3) can only occur when pWal->writeLock is false and iPage==0
//	*/
func _walIndexPageRealloc(tls *libc.TLS, pWal uintptr, iPage int32, ppPage uintptr) (r int32) {
	var apNew, p1 uintptr
	var nByte Tsqlite3_int64
	var rc int32
	_, _, _, _ = apNew, nByte, rc, p1
	rc = SQLITE_OK
	/* Enlarge the pWal->apWiData[] array if required */
	if (*TWal)(unsafe.Pointer(pWal)).FnWiData <= iPage {
		nByte = int64(uint32(4) * uint32(iPage+libc.Int32FromInt32(1)))
		apNew = _sqlite3Realloc(tls, (*TWal)(unsafe.Pointer(pWal)).FapWiData, uint64(uint64(nByte)))
		if !(apNew != 0) {
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, apNew+uintptr((*TWal)(unsafe.Pointer(pWal)).FnWiData)*4, 0, uint32(4)*uint32(iPage+libc.Int32FromInt32(1)-(*TWal)(unsafe.Pointer(pWal)).FnWiData))
		(*TWal)(unsafe.Pointer(pWal)).FapWiData = apNew
		(*TWal)(unsafe.Pointer(pWal)).FnWiData = iPage + int32(1)
	}
	/* Request a pointer to the required page from the VFS */
	if int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) == int32(WAL_HEAPMEMORY_MODE) {
		*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*4)) = _sqlite3MallocZero(tls, uint64(libc.Uint32FromInt64(2)*uint32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint32FromInt32(HASHTABLE_NPAGE)*libc.Uint32FromInt64(4)))
		if !(*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*4)) != 0) {
			rc = int32(SQLITE_NOMEM)
		}
	} else {
		rc = _sqlite3OsShmMap(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, iPage, int32(libc.Uint32FromInt64(2)*uint32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint32FromInt32(HASHTABLE_NPAGE)*libc.Uint32FromInt64(4)), int32((*TWal)(unsafe.Pointer(pWal)).FwriteLock), (*TWal)(unsafe.Pointer(pWal)).FapWiData+uintptr(iPage)*4)
		if rc == SQLITE_OK {
			if iPage > 0 && _sqlite3FaultSim(tls, int32(600)) != 0 {
				rc = int32(SQLITE_NOMEM)
			}
		} else {
			if rc&int32(0xff) == int32(SQLITE_READONLY) {
				p1 = pWal + 46
				*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(WAL_SHM_RDONLY))
				if rc == int32(SQLITE_READONLY) {
					rc = SQLITE_OK
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*4))
	return rc
}

func _walIndexPage(tls *libc.TLS, pWal uintptr, iPage int32, ppPage uintptr) (r int32) {
	var v1 uintptr
	var v2 bool
	_, _ = v1, v2
	if v2 = (*TWal)(unsafe.Pointer(pWal)).FnWiData <= iPage; !v2 {
		v1 = *(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*4))
		*(*uintptr)(unsafe.Pointer(ppPage)) = v1
	}
	if v2 || v1 == uintptr(0) {
		return _walIndexPageRealloc(tls, pWal, iPage, ppPage)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return a pointer to the WalCkptInfo structure in the wal-index.
//	*/
func _walCkptInfo(tls *libc.TLS, pWal uintptr) (r uintptr) {
	return *(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData)) + uintptr(libc.Uint32FromInt64(48)/libc.Uint32FromInt32(2))*4
}

// C documentation
//
//	/*
//	** Return a pointer to the WalIndexHdr structure in the wal-index.
//	*/
func _walIndexHdr(tls *libc.TLS, pWal uintptr) (r uintptr) {
	return *(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData))
}

/*
** The argument to this macro must be of type u32. On a little-endian
** architecture, it returns the u32 value that results from interpreting
** the 4 bytes as a big-endian value. On a big-endian architecture, it
** returns the value that would be produced by interpreting the 4 bytes
** of the input value as a little-endian integer.
 */

// C documentation
//
//	/*
//	** Generate or extend an 8 byte checksum based on the data in
//	** array aByte[] and the initial values of aIn[0] and aIn[1] (or
//	** initial values of 0 and 0 if aIn==NULL).
//	**
//	** The checksum is written back into aOut[] before returning.
//	**
//	** nByte must be a positive multiple of 8.
//	*/
func _walChecksumBytes(tls *libc.TLS, nativeCksum int32, a uintptr, nByte int32, aIn uintptr, aOut uintptr) {
	var aData, aEnd, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v2, v3, v4, v5, v6, v7, v8, v9 uintptr
	var s1, s2, v1 Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aEnd, s1, s2, v1, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v2, v3, v4, v5, v6, v7, v8, v9
	aData = a
	aEnd = a + uintptr(nByte)
	if aIn != 0 {
		s1 = *(*Tu32)(unsafe.Pointer(aIn))
		s2 = *(*Tu32)(unsafe.Pointer(aIn + 1*4))
	} else {
		v1 = libc.Uint32FromInt32(0)
		s2 = v1
		s1 = v1
	}
	if !(nativeCksum != 0) {
		for cond := true; cond; cond = aData < aEnd {
			s1 += *(*Tu32)(unsafe.Pointer(aData))&uint32(0x000000FF)<<int32(24) + *(*Tu32)(unsafe.Pointer(aData))&uint32(0x0000FF00)<<int32(8) + *(*Tu32)(unsafe.Pointer(aData))&uint32(0x00FF0000)>>int32(8) + *(*Tu32)(unsafe.Pointer(aData))&uint32(0xFF000000)>>int32(24) + s2
			s2 += *(*Tu32)(unsafe.Pointer(aData + 1*4))&uint32(0x000000FF)<<int32(24) + *(*Tu32)(unsafe.Pointer(aData + 1*4))&uint32(0x0000FF00)<<int32(8) + *(*Tu32)(unsafe.Pointer(aData + 1*4))&uint32(0x00FF0000)>>int32(8) + *(*Tu32)(unsafe.Pointer(aData + 1*4))&uint32(0xFF000000)>>int32(24) + s1
			aData += uintptr(2) * 4
		}
	} else {
		if nByte%int32(64) == 0 {
			for cond := true; cond; cond = aData < aEnd {
				v2 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v2)) + s2
				v3 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v3)) + s1
				v4 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v4)) + s2
				v5 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v5)) + s1
				v6 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v6)) + s2
				v7 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v7)) + s1
				v8 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v8)) + s2
				v9 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v9)) + s1
				v10 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v10)) + s2
				v11 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v11)) + s1
				v12 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v12)) + s2
				v13 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v13)) + s1
				v14 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v14)) + s2
				v15 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v15)) + s1
				v16 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v16)) + s2
				v17 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v17)) + s1
			}
		} else {
			for cond := true; cond; cond = aData < aEnd {
				v18 = aData
				aData += 4
				s1 += *(*Tu32)(unsafe.Pointer(v18)) + s2
				v19 = aData
				aData += 4
				s2 += *(*Tu32)(unsafe.Pointer(v19)) + s1
			}
		}
	}
	*(*Tu32)(unsafe.Pointer(aOut)) = s1
	*(*Tu32)(unsafe.Pointer(aOut + 1*4)) = s2
}

// C documentation
//
//	/*
//	** If there is the possibility of concurrent access to the SHM file
//	** from multiple threads and/or processes, then do a memory barrier.
//	*/
func _walShmBarrier(tls *libc.TLS, pWal uintptr) {
	if int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) != int32(WAL_HEAPMEMORY_MODE) {
		_sqlite3OsShmBarrier(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd)
	}
}

/*
** Add the SQLITE_NO_TSAN as part of the return-type of a function
** definition as a hint that the function contains constructs that
** might give false-positive TSAN warnings.
**
** See tag-20200519-1.
 */

// C documentation
//
//	/*
//	** Write the header information in pWal->hdr into the wal-index.
//	**
//	** The checksum on pWal->hdr is updated before it is written.
//	*/
func _walIndexWriteHdr(tls *libc.TLS, pWal uintptr) {
	var aHdr uintptr
	var nCksum int32
	_, _ = aHdr, nCksum
	aHdr = _walIndexHdr(tls, pWal)
	nCksum = int32(uint32(libc.UintptrFromInt32(0) + 40))
	(*TWal)(unsafe.Pointer(pWal)).Fhdr.FisInit = uint8(1)
	(*TWal)(unsafe.Pointer(pWal)).Fhdr.FiVersion = uint32(WALINDEX_MAX_VERSION)
	_walChecksumBytes(tls, int32(1), pWal+52, nCksum, uintptr(0), pWal+52+40)
	/* Possible TSAN false-positive.  See tag-20200519-1 */
	libc.Xmemcpy(tls, aHdr+1*48, pWal+52, uint32(48))
	_walShmBarrier(tls, pWal)
	libc.Xmemcpy(tls, aHdr, pWal+52, uint32(48))
}

// 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 + 52 + 24
	_sqlite3Put4byte(tls, aFrame, iPage)
	_sqlite3Put4byte(tls, aFrame+4, nTruncate)
	if (*TWal)(unsafe.Pointer(pWal)).FiReCksum == uint32(0) {
		libc.Xmemcpy(tls, aFrame+8, pWal+52+32, uint32(8))
		nativeCksum = libc.BoolInt32(int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == SQLITE_BIGENDIAN)
		_walChecksumBytes(tls, nativeCksum, aFrame, int32(8), aCksum, aCksum)
		_walChecksumBytes(tls, nativeCksum, aData, int32((*TWal)(unsafe.Pointer(pWal)).FszPage), aCksum, aCksum)
		_sqlite3Put4byte(tls, aFrame+16, *(*Tu32)(unsafe.Pointer(aCksum)))
		_sqlite3Put4byte(tls, aFrame+20, *(*Tu32)(unsafe.Pointer(aCksum + 1*4)))
	} else {
		libc.Xmemset(tls, aFrame+8, 0, uint32(16))
	}
}

// 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 + 52 + 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+52+32, aFrame+8, uint32(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
	}
	/* 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(int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == SQLITE_BIGENDIAN)
	_walChecksumBytes(tls, nativeCksum, aFrame, int32(8), aCksum, aCksum)
	_walChecksumBytes(tls, nativeCksum, aData, int32((*TWal)(unsafe.Pointer(pWal)).FszPage), aCksum, aCksum)
	if *(*Tu32)(unsafe.Pointer(aCksum)) != _sqlite3Get4byte(tls, aFrame+16) || *(*Tu32)(unsafe.Pointer(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)(unsafe.Pointer(piPage)) = pgno
	*(*Tu32)(unsafe.Pointer(pnTruncate)) = _sqlite3Get4byte(tls, aFrame+4)
	return int32(1)
}

// C documentation
//
//	/*
//	** Set or release locks on the WAL.  Locks are either shared or exclusive.
//	** A lock cannot be moved directly between shared and exclusive - it must go
//	** through the unlocked state first.
//	**
//	** In locking_mode=EXCLUSIVE, all of these routines become no-ops.
//	*/
func _walLockShared(tls *libc.TLS, pWal uintptr, lockIdx int32) (r int32) {
	var rc int32
	_ = rc
	if (*TWal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return SQLITE_OK
	}
	rc = _sqlite3OsShmLock(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, int32(1), libc.Int32FromInt32(SQLITE_SHM_LOCK)|libc.Int32FromInt32(SQLITE_SHM_SHARED))
	return rc
}

func _walUnlockShared(tls *libc.TLS, pWal uintptr, lockIdx int32) {
	if (*TWal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return
	}
	_sqlite3OsShmLock(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, int32(1), libc.Int32FromInt32(SQLITE_SHM_UNLOCK)|libc.Int32FromInt32(SQLITE_SHM_SHARED))
}

func _walLockExclusive(tls *libc.TLS, pWal uintptr, lockIdx int32, n int32) (r int32) {
	var rc int32
	_ = rc
	if (*TWal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return SQLITE_OK
	}
	rc = _sqlite3OsShmLock(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, n, libc.Int32FromInt32(SQLITE_SHM_LOCK)|libc.Int32FromInt32(SQLITE_SHM_EXCLUSIVE))
	return rc
}

func _walUnlockExclusive(tls *libc.TLS, pWal uintptr, lockIdx int32, n int32) {
	if (*TWal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return
	}
	_sqlite3OsShmLock(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, n, libc.Int32FromInt32(SQLITE_SHM_UNLOCK)|libc.Int32FromInt32(SQLITE_SHM_EXCLUSIVE))
}

// C documentation
//
//	/*
//	** Compute a hash on a page number.  The resulting hash value must land
//	** between 0 and (HASHTABLE_NSLOT-1).  The walHashNext() function advances
//	** the hash to the next value in the event of a collision.
//	*/
func _walHash(tls *libc.TLS, iPage Tu32) (r int32) {
	return int32(iPage * uint32(HASHTABLE_HASH_1) & uint32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2)-libc.Int32FromInt32(1)))
}

func _walNextHash(tls *libc.TLS, iPriorHash int32) (r int32) {
	return (iPriorHash + int32(1)) & (libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2) - libc.Int32FromInt32(1))
}

// C documentation
//
//	/*
//	** An instance of the WalHashLoc object is used to describe the location
//	** of a page hash table in the wal-index.  This becomes the return value
//	** from walHashGet().
//	*/
type TWalHashLoc = struct {
	FaHash uintptr
	FaPgno uintptr
	FiZero Tu32
}

type WalHashLoc = TWalHashLoc

type TWalHashLoc1 = struct {
	FaHash uintptr
	FaPgno uintptr
	FiZero Tu32
}

type WalHashLoc1 = TWalHashLoc1

// C documentation
//
//	/*
//	** Return pointers to the hash table and page number array stored on
//	** page iHash of the wal-index. The wal-index is broken into 32KB pages
//	** numbered starting from 0.
//	**
//	** Set output variable pLoc->aHash to point to the start of the hash table
//	** in the wal-index file. Set pLoc->iZero to one less than the frame
//	** number of the first frame indexed by this hash table. If a
//	** slot in the hash table is set to N, it refers to frame number
//	** (pLoc->iZero+N) in the log.
//	**
//	** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the
//	** first frame indexed by the hash table, frame (pLoc->iZero).
//	*/
func _walHashGet(tls *libc.TLS, pWal uintptr, iHash int32, pLoc uintptr) (r int32) {
	var rc int32
	_ = rc /* Return code */
	rc = _walIndexPage(tls, pWal, iHash, pLoc+4)
	if (*TWalHashLoc)(unsafe.Pointer(pLoc)).FaPgno != 0 {
		(*TWalHashLoc)(unsafe.Pointer(pLoc)).FaHash = (*TWalHashLoc)(unsafe.Pointer(pLoc)).FaPgno + 4096*4
		if iHash == 0 {
			(*TWalHashLoc)(unsafe.Pointer(pLoc)).FaPgno = (*TWalHashLoc)(unsafe.Pointer(pLoc)).FaPgno + uintptr((libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4))*4
			(*TWalHashLoc)(unsafe.Pointer(pLoc)).FiZero = uint32(0)
		} else {
			(*TWalHashLoc)(unsafe.Pointer(pLoc)).FiZero = libc.Uint32FromInt32(HASHTABLE_NPAGE) - (libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4) + uint32((iHash-int32(1))*int32(HASHTABLE_NPAGE))
		}
	} else {
		if rc == SQLITE_OK {
			rc = int32(SQLITE_ERROR)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the number of the wal-index page that contains the hash-table
//	** and page-number array that contain entries corresponding to WAL frame
//	** iFrame. The wal-index is broken up into 32KB pages. Wal-index pages
//	** are numbered starting from 0.
//	*/
func _walFramePage(tls *libc.TLS, iFrame Tu32) (r int32) {
	var iHash int32
	_ = iHash
	iHash = int32((iFrame + uint32(HASHTABLE_NPAGE) - (libc.Uint32FromInt32(HASHTABLE_NPAGE) - (libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4)) - uint32(1)) / uint32(HASHTABLE_NPAGE))
	return iHash
}

// C documentation
//
//	/*
//	** Return the page number associated with frame iFrame in this WAL.
//	*/
func _walFramePgno(tls *libc.TLS, pWal uintptr, iFrame Tu32) (r Tu32) {
	var iHash int32
	_ = iHash
	iHash = _walFramePage(tls, iFrame)
	if iHash == 0 {
		return *(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData)) + uintptr((libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4)+iFrame-uint32(1))*4))
	}
	return *(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iHash)*4)) + uintptr((iFrame-uint32(1)-(libc.Uint32FromInt32(HASHTABLE_NPAGE)-(libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4)))%uint32(HASHTABLE_NPAGE))*4))
}

// C documentation
//
//	/*
//	** Remove entries from the hash table that point to WAL slots greater
//	** than pWal->hdr.mxFrame.
//	**
//	** This function is called whenever pWal->hdr.mxFrame is decreased due
//	** to a rollback or savepoint.
//	**
//	** At most only the hash table containing pWal->hdr.mxFrame needs to be
//	** updated.  Any later hash tables will be automatically cleared when
//	** pWal->hdr.mxFrame advances to the point where those hash tables are
//	** actually needed.
//	*/
func _walCleanupHash(tls *libc.TLS, pWal uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iLimit, nByte int32
	var _ /* sLoc at bp+0 */ TWalHashLoc
	_, _, _ = i, iLimit, nByte /* Hash table location */
	iLimit = 0                 /* Used to iterate through aHash[] */
	if (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame == uint32(0) {
		return
	}
	/* Obtain pointers to the hash-table and page-number array containing
	 ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
	 ** that the page said hash-table and array reside on is already mapped.(1)
	 */
	i = _walHashGet(tls, pWal, _walFramePage(tls, (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame), bp)
	if i != 0 {
		return
	} /* Defense-in-depth, in case (1) above is wrong */
	/* Zero all hash-table entries that correspond to frame numbers greater
	 ** than pWal->hdr.mxFrame.
	 */
	iLimit = int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame - (*(*TWalHashLoc)(unsafe.Pointer(bp))).FiZero)
	i = 0
	for {
		if !(i < libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2)) {
			break
		}
		if int32(*(*Tht_slot)(unsafe.Pointer((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash + uintptr(i)*2))) > iLimit {
			*(*Tht_slot)(unsafe.Pointer((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash + uintptr(i)*2)) = uint16(0)
		}
		goto _1
	_1:
		;
		i++
	}
	/* Zero the entries in the aPgno array that correspond to frames with
	 ** frame numbers greater than pWal->hdr.mxFrame.
	 */
	nByte = int32((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash) - int32((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno+uintptr(iLimit)*4)
	libc.Xmemset(tls, (*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno+uintptr(iLimit)*4, 0, uint32(uint32(nByte)))
}

// C documentation
//
//	/*
//	** Set an entry in the wal-index that will map database page number
//	** pPage into WAL frame iFrame.
//	*/
func _walIndexAppend(tls *libc.TLS, pWal uintptr, iFrame Tu32, iPage Tu32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iKey, idx, nByte, nCollide, rc, v2 int32
	var _ /* sLoc at bp+0 */ TWalHashLoc
	_, _, _, _, _, _ = iKey, idx, nByte, nCollide, rc, v2 /* Wal-index hash table location */
	rc = _walHashGet(tls, pWal, _walFramePage(tls, iFrame), bp)
	/* Assuming the wal-index file was successfully mapped, populate the
	 ** page number array and hash table entry.
	 */
	if rc == SQLITE_OK { /* Number of hash collisions */
		idx = int32(iFrame - (*(*TWalHashLoc)(unsafe.Pointer(bp))).FiZero)
		/* If this is the first entry to be added to this hash-table, zero the
		 ** entire hash table and aPgno[] array before proceeding.
		 */
		if idx == int32(1) {
			nByte = int32((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash+uintptr(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))*2) - int32((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno)
			libc.Xmemset(tls, (*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno, 0, uint32(uint32(nByte)))
		}
		/* If the entry in aPgno[] is already set, then the previous writer
		 ** must have exited unexpectedly in the middle of a transaction (after
		 ** writing one or more dirty pages to the WAL to free up memory).
		 ** Remove the remnants of that writers uncommitted transaction from
		 ** the hash-table before writing any new entries.
		 */
		if *(*Tu32)(unsafe.Pointer((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno + uintptr(idx-int32(1))*4)) != 0 {
			_walCleanupHash(tls, pWal)
		}
		/* Write the aPgno[] array entry and the hash-table slot. */
		nCollide = idx
		iKey = _walHash(tls, iPage)
		for {
			if !(*(*Tht_slot)(unsafe.Pointer((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash + uintptr(iKey)*2)) != 0) {
				break
			}
			v2 = nCollide
			nCollide--
			if v2 == 0 {
				return _sqlite3CorruptError(tls, int32(66239))
			}
			goto _1
		_1:
			;
			iKey = _walNextHash(tls, iKey)
		}
		*(*Tu32)(unsafe.Pointer((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno + uintptr(idx-int32(1))*4)) = iPage
		libc.AtomicStoreNUint16((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash+uintptr(iKey)*2, uint16(uint16(idx)), libc.Int32FromInt32(__ATOMIC_RELAXED))
	}
	return rc
}

// 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, v5 uint32
	var _ /* aBuf at bp+8 */ [32]Tu8
	var _ /* aShare at bp+40 */ uintptr
	var _ /* nSize at bp+0 */ Ti64
	var _ /* nTruncate at bp+48 */ Tu32
	var _ /* pgno at bp+44 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aFrame, aFrameCksum, aPrivate, i, iFirst, iFrame, iLast, iLastFrame, iLock, iOffset, iPg, isValid, magic, nHdr, nHdr32, pInfo, rc, szFrame, szPage, version, v2, v3, v5 /* 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) + int32((*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+52, 0, uint32(48))
	rc = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp)
	if rc != SQLITE_OK {
		goto recovery_error
	}
	if *(*Ti64)(unsafe.Pointer(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 = int32(_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 = uint32(uint32(szPage))
		(*TWal)(unsafe.Pointer(pWal)).FnCkpt = _sqlite3Get4byte(tls, bp+8+12)
		libc.Xmemcpy(tls, pWal+52+32, bp+8+16, uint32(8))
		/* Verify that the WAL header checksum is correct */
		_walChecksumBytes(tls, libc.BoolInt32(int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == SQLITE_BIGENDIAN), bp+8, libc.Int32FromInt32(WAL_HDRSIZE)-libc.Int32FromInt32(2)*libc.Int32FromInt32(4), uintptr(0), pWal+52+24)
		if *(*Tu32)(unsafe.Pointer(pWal + 52 + 24)) != _sqlite3Get4byte(tls, bp+8+24) || *(*Tu32)(unsafe.Pointer(pWal + 52 + 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(66371))
			goto finished
		}
		/* Malloc a buffer to read frames into. */
		szFrame = szPage + int32(WAL_FRAME_HDRSIZE)
		aFrame = Xsqlite3_malloc64(tls, uint64(uint32(uint32(szFrame))+(libc.Uint32FromInt64(2)*uint32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint32FromInt32(HASHTABLE_NPAGE)*libc.Uint32FromInt64(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 = uint32((*(*Ti64)(unsafe.Pointer(bp)) - int64(WAL_HDRSIZE)) / int64(int64(szFrame)))
		iPg = uint32(0)
		for {
			if !(iPg <= uint32(_walFramePage(tls, iLastFrame))) {
				break
			}
			if iLastFrame < libc.Uint32FromInt32(HASHTABLE_NPAGE)-(libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4)+iPg*uint32(HASHTABLE_NPAGE) {
				v2 = iLastFrame
			} else {
				v2 = libc.Uint32FromInt32(HASHTABLE_NPAGE) - (libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4) + iPg*uint32(HASHTABLE_NPAGE)
			} /* Index of last frame read */
			iLast = v2
			if iPg == uint32(0) {
				v3 = uint32(0)
			} else {
				v3 = libc.Uint32FromInt32(HASHTABLE_NPAGE) - (libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4) + (iPg-uint32(1))*uint32(HASHTABLE_NPAGE)
			}
			iFirst = uint32(1) + v3
			rc = _walIndexPage(tls, pWal, int32(int32(iPg)), bp+40)
			if *(*uintptr)(unsafe.Pointer(bp + 40)) == uintptr(0) {
				break
			}
			*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*4)) = aPrivate
			iFrame = iFirst
			for {
				if !(iFrame <= iLast) {
					break
				}
				iOffset = libc.Int64FromInt32(WAL_HDRSIZE) + int64(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+44, bp+48, aData, aFrame)
				if !(isValid != 0) {
					break
				}
				rc = _walIndexAppend(tls, pWal, iFrame, *(*Tu32)(unsafe.Pointer(bp + 44)))
				if rc != SQLITE_OK {
					break
				}
				/* If nTruncate is non-zero, this is a commit record. */
				if *(*Tu32)(unsafe.Pointer(bp + 48)) != 0 {
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = iFrame
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage = *(*Tu32)(unsafe.Pointer(bp + 48))
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage = uint16(szPage&libc.Int32FromInt32(0xff00) | szPage>>libc.Int32FromInt32(16))
					aFrameCksum[0] = *(*Tu32)(unsafe.Pointer(pWal + 52 + 24))
					aFrameCksum[int32(1)] = *(*Tu32)(unsafe.Pointer(pWal + 52 + 24 + 1*4))
				}
				goto _4
			_4:
				;
				iFrame++
			}
			*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*4)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			if iPg == uint32(0) {
				v5 = libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2) + libc.Uint32FromInt64(40)
			} else {
				v5 = uint32(0)
			}
			nHdr = v5
			nHdr32 = nHdr / uint32(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)(unsafe.Pointer(bp + 40))+uintptr(nHdr32)*4, aPrivate+uintptr(nHdr32)*4, libc.Uint32FromInt64(2)*uint32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint32FromInt32(HASHTABLE_NPAGE)*libc.Uint32FromInt64(4)-nHdr)
			if iFrame <= iLast {
				break
			}
			goto _1
		_1:
			;
			iPg++
		}
		Xsqlite3_free(tls, aFrame)
	}
	goto finished
finished:
	;
	if rc == SQLITE_OK {
		*(*Tu32)(unsafe.Pointer(pWal + 52 + 24)) = aFrameCksum[0]
		*(*Tu32)(unsafe.Pointer(pWal + 52 + 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)(unsafe.Pointer(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)(unsafe.Pointer(pInfo + 4 + uintptr(i)*4)) = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
				} else {
					*(*Tu32)(unsafe.Pointer(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++
		}
		/* 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+5500, 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
//
//	/*
//	** Close an open wal-index.
//	*/
func _walIndexClose(tls *libc.TLS, pWal uintptr, isDelete int32) {
	var i int32
	_ = i
	if int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) == int32(WAL_HEAPMEMORY_MODE) || (*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable != 0 {
		i = 0
		for {
			if !(i < (*TWal)(unsafe.Pointer(pWal)).FnWiData) {
				break
			}
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*4)))
			*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*4)) = uintptr(0)
			goto _1
		_1:
			;
			i++
		}
	}
	if int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) != int32(WAL_HEAPMEMORY_MODE) {
		_sqlite3OsShmUnmap(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, isDelete)
	}
}

// C documentation
//
//	/*
//	** Open a connection to the WAL file zWalName. The database file must
//	** already be opened on connection pDbFd. The buffer that zWalName points
//	** to must remain valid for the lifetime of the returned Wal* handle.
//	**
//	** A SHARED lock should be held on the database file when this function
//	** is called. The purpose of this SHARED lock is to prevent any other
//	** client from unlinking the WAL or wal-index file. If another process
//	** were to do this just after this client opened one of these files, the
//	** system would be badly broken.
//	**
//	** If the log file is successfully opened, SQLITE_OK is returned and
//	** *ppWal is set to point to a new WAL handle. If an error occurs,
//	** an SQLite error code is returned and *ppWal is left unmodified.
//	*/
func _sqlite3WalOpen(tls *libc.TLS, pVfs uintptr, pDbFd uintptr, zWalName uintptr, bNoShm int32, mxWalSize Ti64, ppWal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iDC, rc, v1 int32
	var pRet uintptr
	var _ /* flags at bp+0 */ int32
	_, _, _, _ = iDC, pRet, rc, v1 /* Flags passed to OsOpen() */
	/* Verify the values of various constants.  Any changes to the values
	 ** of these constants would result in an incompatible on-disk format
	 ** for the -shm file.  Any change that causes one of these asserts to
	 ** fail is a backward compatibility problem, even if the change otherwise
	 ** works.
	 **
	 ** This table also serves as a helpful cross-reference when trying to
	 ** interpret hex dumps of the -shm file.
	 */
	/* In the amalgamation, the os_unix.c and os_win.c source files come before
	 ** this source file.  Verify that the #defines of the locking byte offsets
	 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
	 ** For that matter, if the lock offset ever changes from its initial design
	 ** value of 120, we need to know that so there is an assert() to check it.
	 */
	/* Allocate an instance of struct Wal to return. */
	*(*uintptr)(unsafe.Pointer(ppWal)) = uintptr(0)
	pRet = _sqlite3MallocZero(tls, uint64(uint32(120)+uint32((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile)))
	if !(pRet != 0) {
		return int32(SQLITE_NOMEM)
	}
	(*TWal)(unsafe.Pointer(pRet)).FpVfs = pVfs
	(*TWal)(unsafe.Pointer(pRet)).FpWalFd = pRet + 1*120
	(*TWal)(unsafe.Pointer(pRet)).FpDbFd = pDbFd
	(*TWal)(unsafe.Pointer(pRet)).FreadLock = int16(-int32(1))
	(*TWal)(unsafe.Pointer(pRet)).FmxWalSize = mxWalSize
	(*TWal)(unsafe.Pointer(pRet)).FzWalName = zWalName
	(*TWal)(unsafe.Pointer(pRet)).FsyncHeader = uint8(1)
	(*TWal)(unsafe.Pointer(pRet)).FpadToSectorBoundary = uint8(1)
	if bNoShm != 0 {
		v1 = int32(WAL_HEAPMEMORY_MODE)
	} else {
		v1 = WAL_NORMAL_MODE
	}
	(*TWal)(unsafe.Pointer(pRet)).FexclusiveMode = uint8(v1)
	/* Open file handle on the write-ahead log file. */
	*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_WAL)
	rc = _sqlite3OsOpen(tls, pVfs, zWalName, (*TWal)(unsafe.Pointer(pRet)).FpWalFd, *(*int32)(unsafe.Pointer(bp)), bp)
	if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp))&int32(SQLITE_OPEN_READONLY) != 0 {
		(*TWal)(unsafe.Pointer(pRet)).FreadOnly = uint8(WAL_RDONLY)
	}
	if rc != SQLITE_OK {
		_walIndexClose(tls, pRet, 0)
		_sqlite3OsClose(tls, (*TWal)(unsafe.Pointer(pRet)).FpWalFd)
		Xsqlite3_free(tls, pRet)
	} else {
		iDC = _sqlite3OsDeviceCharacteristics(tls, pDbFd)
		if iDC&int32(SQLITE_IOCAP_SEQUENTIAL) != 0 {
			(*TWal)(unsafe.Pointer(pRet)).FsyncHeader = uint8(0)
		}
		if iDC&int32(SQLITE_IOCAP_POWERSAFE_OVERWRITE) != 0 {
			(*TWal)(unsafe.Pointer(pRet)).FpadToSectorBoundary = uint8(0)
		}
		*(*uintptr)(unsafe.Pointer(ppWal)) = pRet
	}
	return rc
}

// C documentation
//
//	/*
//	** Change the size to which the WAL file is truncated on each reset.
//	*/
func _sqlite3WalLimit(tls *libc.TLS, pWal uintptr, iLimit Ti64) {
	if pWal != 0 {
		(*TWal)(unsafe.Pointer(pWal)).FmxWalSize = iLimit
	}
}

// C documentation
//
//	/*
//	** Find the smallest page number out of all pages held in the WAL that
//	** has not been returned by any prior invocation of this method on the
//	** same WalIterator object.   Write into *piFrame the frame index where
//	** that page was last written into the WAL.  Write into *piPage the page
//	** number.
//	**
//	** Return 0 on success.  If there are no pages in the WAL with a page
//	** number larger than *piPage, then return 1.
//	*/
func _walIteratorNext(tls *libc.TLS, p uintptr, piPage uintptr, piFrame uintptr) (r int32) {
	var i int32
	var iMin, iPg, iRet, v2 Tu32
	var pSegment uintptr
	_, _, _, _, _, _ = i, iMin, iPg, iRet, pSegment, v2 /* Result pgno must be greater than iMin */
	iRet = uint32(0xFFFFFFFF)                           /* For looping through segments */
	iMin = (*TWalIterator)(unsafe.Pointer(p)).FiPrior
	i = (*TWalIterator)(unsafe.Pointer(p)).FnSegment - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		pSegment = p + 8 + uintptr(i)*20
		for (*TWalSegment)(unsafe.Pointer(pSegment)).FiNext < (*TWalSegment)(unsafe.Pointer(pSegment)).FnEntry {
			iPg = *(*Tu32)(unsafe.Pointer((*TWalSegment)(unsafe.Pointer(pSegment)).FaPgno + uintptr(*(*Tht_slot)(unsafe.Pointer((*TWalSegment)(unsafe.Pointer(pSegment)).FaIndex + uintptr((*TWalSegment)(unsafe.Pointer(pSegment)).FiNext)*2)))*4))
			if iPg > iMin {
				if iPg < iRet {
					iRet = iPg
					*(*Tu32)(unsafe.Pointer(piFrame)) = uint32((*TWalSegment)(unsafe.Pointer(pSegment)).FiZero + int32(*(*Tht_slot)(unsafe.Pointer((*TWalSegment)(unsafe.Pointer(pSegment)).FaIndex + uintptr((*TWalSegment)(unsafe.Pointer(pSegment)).FiNext)*2))))
				}
				break
			}
			(*TWalSegment)(unsafe.Pointer(pSegment)).FiNext++
		}
		goto _1
	_1:
		;
		i--
	}
	v2 = iRet
	(*TWalIterator)(unsafe.Pointer(p)).FiPrior = v2
	*(*Tu32)(unsafe.Pointer(piPage)) = v2
	return libc.BoolInt32(iRet == uint32(0xFFFFFFFF))
}

// C documentation
//
//	/*
//	** This function merges two sorted lists into a single sorted list.
//	**
//	** aLeft[] and aRight[] are arrays of indices.  The sort key is
//	** aContent[aLeft[]] and aContent[aRight[]].  Upon entry, the following
//	** is guaranteed for all J<K:
//	**
//	**        aContent[aLeft[J]] < aContent[aLeft[K]]
//	**        aContent[aRight[J]] < aContent[aRight[K]]
//	**
//	** This routine overwrites aRight[] with a new (probably longer) sequence
//	** of indices such that the aRight[] contains every index that appears in
//	** either aLeft[] or the old aRight[] and such that the second condition
//	** above is still met.
//	**
//	** The aContent[aLeft[X]] values will be unique for all X.  And the
//	** aContent[aRight[X]] values will be unique too.  But there might be
//	** one or more combinations of X and Y such that
//	**
//	**      aLeft[X]!=aRight[Y]  &&  aContent[aLeft[X]] == aContent[aRight[Y]]
//	**
//	** When that happens, omit the aLeft[X] and use the aRight[Y] index.
//	*/
func _walMerge(tls *libc.TLS, aContent uintptr, aLeft uintptr, nLeft int32, paRight uintptr, pnRight uintptr, aTmp uintptr) {
	var aRight uintptr
	var dbpage TPgno
	var iLeft, iOut, iRight, nRight, v1, v2, v3 int32
	var logpage Tht_slot
	_, _, _, _, _, _, _, _, _, _ = aRight, dbpage, iLeft, iOut, iRight, logpage, nRight, v1, v2, v3
	iLeft = 0  /* Current index in aLeft */
	iRight = 0 /* Current index in aRight */
	iOut = 0   /* Current index in output buffer */
	nRight = *(*int32)(unsafe.Pointer(pnRight))
	aRight = *(*uintptr)(unsafe.Pointer(paRight))
	for iRight < nRight || iLeft < nLeft {
		if iLeft < nLeft && (iRight >= nRight || *(*Tu32)(unsafe.Pointer(aContent + uintptr(*(*Tht_slot)(unsafe.Pointer(aLeft + uintptr(iLeft)*2)))*4)) < *(*Tu32)(unsafe.Pointer(aContent + uintptr(*(*Tht_slot)(unsafe.Pointer(aRight + uintptr(iRight)*2)))*4))) {
			v1 = iLeft
			iLeft++
			logpage = *(*Tht_slot)(unsafe.Pointer(aLeft + uintptr(v1)*2))
		} else {
			v2 = iRight
			iRight++
			logpage = *(*Tht_slot)(unsafe.Pointer(aRight + uintptr(v2)*2))
		}
		dbpage = *(*Tu32)(unsafe.Pointer(aContent + uintptr(logpage)*4))
		v3 = iOut
		iOut++
		*(*Tht_slot)(unsafe.Pointer(aTmp + uintptr(v3)*2)) = logpage
		if iLeft < nLeft && *(*Tu32)(unsafe.Pointer(aContent + uintptr(*(*Tht_slot)(unsafe.Pointer(aLeft + uintptr(iLeft)*2)))*4)) == dbpage {
			iLeft++
		}
	}
	*(*uintptr)(unsafe.Pointer(paRight)) = aLeft
	*(*int32)(unsafe.Pointer(pnRight)) = iOut
	libc.Xmemcpy(tls, aLeft, aTmp, uint32(2)*uint32(uint32(iOut)))
}

// C documentation
//
//	/*
//	** Sort the elements in list aList using aContent[] as the sort key.
//	** Remove elements with duplicate keys, preferring to keep the
//	** larger aList[] values.
//	**
//	** The aList[] entries are indices into aContent[].  The values in
//	** aList[] are to be sorted so that for all J<K:
//	**
//	**      aContent[aList[J]] < aContent[aList[K]]
//	**
//	** For any X and Y such that
//	**
//	**      aContent[aList[X]] == aContent[aList[Y]]
//	**
//	** Keep the larger of the two values aList[X] and aList[Y] and discard
//	** the smaller.
//	*/
func _walMergesort(tls *libc.TLS, aContent uintptr, aBuffer uintptr, aList uintptr, pnList uintptr) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var iList, nList int32
	var iSub Tu32
	var p, p1 uintptr
	var _ /* aMerge at bp+4 */ uintptr
	var _ /* aSub at bp+8 */ [13]struct {
		FnList int32
		FaList uintptr
	}
	var _ /* nMerge at bp+0 */ int32
	_, _, _, _, _ = iList, iSub, nList, p, p1
	nList = *(*int32)(unsafe.Pointer(pnList))        /* Size of input list */
	*(*int32)(unsafe.Pointer(bp)) = 0                /* Number of elements in list aMerge */
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* Index into input list */
	iSub = uint32(0)                                 /* Array of sub-lists */
	libc.Xmemset(tls, bp+8, 0, uint32(104))
	iList = 0
	for {
		if !(iList < nList) {
			break
		}
		*(*int32)(unsafe.Pointer(bp)) = int32(1)
		*(*uintptr)(unsafe.Pointer(bp + 4)) = aList + uintptr(iList)*2
		iSub = uint32(0)
		for {
			if !(iList&(int32(1)<<iSub) != 0) {
				break
			}
			p = bp + 8 + uintptr(iSub)*8
			_walMerge(tls, aContent, (*struct {
				FnList int32
				FaList uintptr
			})(unsafe.Pointer(p)).FaList, (*struct {
				FnList int32
				FaList uintptr
			})(unsafe.Pointer(p)).FnList, bp+4, bp, aBuffer)
			goto _2
		_2:
			;
			iSub++
		}
		(*(*[13]struct {
			FnList int32
			FaList uintptr
		})(unsafe.Pointer(bp + 8)))[iSub].FaList = *(*uintptr)(unsafe.Pointer(bp + 4))
		(*(*[13]struct {
			FnList int32
			FaList uintptr
		})(unsafe.Pointer(bp + 8)))[iSub].FnList = *(*int32)(unsafe.Pointer(bp))
		goto _1
	_1:
		;
		iList++
	}
	iSub++
	for {
		if !(iSub < uint32(int32(libc.Uint32FromInt64(104)/libc.Uint32FromInt64(8)))) {
			break
		}
		if nList&(int32(1)<<iSub) != 0 {
			p1 = bp + 8 + uintptr(iSub)*8
			_walMerge(tls, aContent, (*struct {
				FnList int32
				FaList uintptr
			})(unsafe.Pointer(p1)).FaList, (*struct {
				FnList int32
				FaList uintptr
			})(unsafe.Pointer(p1)).FnList, bp+4, bp, aBuffer)
		}
		goto _3
	_3:
		;
		iSub++
	}
	*(*int32)(unsafe.Pointer(pnList)) = *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Free an iterator allocated by walIteratorInit().
//	*/
func _walIteratorFree(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Construct a WalInterator object that can be used to loop over all
//	** pages in the WAL following frame nBackfill in ascending order. Frames
//	** nBackfill or earlier may be included - excluding them is an optimization
//	** only. The caller must hold the checkpoint lock.
//	**
//	** On success, make *pp point to the newly allocated WalInterator object
//	** return SQLITE_OK. Otherwise, return an error code. If this routine
//	** returns an error, the value of *pp is undefined.
//	**
//	** The calling routine should invoke walIteratorFree() to destroy the
//	** WalIterator object when it has finished with it.
//	*/
func _walIteratorInit(tls *libc.TLS, pWal uintptr, nBackfill Tu32, pp uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aIndex, aTmp, p uintptr
	var i, j, nSegment, rc int32
	var iLast Tu32
	var nByte Tsqlite3_int64
	var v1 uint32
	var _ /* nEntry at bp+12 */ int32
	var _ /* sLoc at bp+0 */ TWalHashLoc
	_, _, _, _, _, _, _, _, _, _ = aIndex, aTmp, i, iLast, j, nByte, nSegment, p, rc, v1 /* Temp space used by merge-sort */
	rc = SQLITE_OK                                                                       /* Return Code */
	/* This routine only runs while holding the checkpoint lock. And
	 ** it only runs if there is actually content in the log (mxFrame>0).
	 */
	iLast = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	/* Allocate space for the WalIterator object. */
	nSegment = _walFramePage(tls, iLast) + int32(1)
	nByte = int64(uint32(28) + uint32(nSegment-libc.Int32FromInt32(1))*uint32(20) + iLast*uint32(2))
	if iLast > uint32(HASHTABLE_NPAGE) {
		v1 = uint32(HASHTABLE_NPAGE)
	} else {
		v1 = iLast
	}
	p = Xsqlite3_malloc64(tls, uint64(nByte+int64(uint32(2)*v1)))
	if !(p != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, p, 0, uint32(uint32(nByte)))
	(*TWalIterator)(unsafe.Pointer(p)).FnSegment = nSegment
	aTmp = p + uintptr(nByte)
	i = _walFramePage(tls, nBackfill+uint32(1))
	for {
		if !(rc == SQLITE_OK && i < nSegment) {
			break
		}
		rc = _walHashGet(tls, pWal, i, bp)
		if rc == SQLITE_OK { /* Sorted index for this segment */
			if i+int32(1) == nSegment {
				*(*int32)(unsafe.Pointer(bp + 12)) = int32(iLast - (*(*TWalHashLoc)(unsafe.Pointer(bp))).FiZero)
			} else {
				*(*int32)(unsafe.Pointer(bp + 12)) = (int32((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash) - int32((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno)) / 4
			}
			aIndex = p + 8 + uintptr((*TWalIterator)(unsafe.Pointer(p)).FnSegment)*20 + uintptr((*(*TWalHashLoc)(unsafe.Pointer(bp))).FiZero)*2
			(*(*TWalHashLoc)(unsafe.Pointer(bp))).FiZero++
			j = 0
			for {
				if !(j < *(*int32)(unsafe.Pointer(bp + 12))) {
					break
				}
				*(*Tht_slot)(unsafe.Pointer(aIndex + uintptr(j)*2)) = uint16(uint16(j))
				goto _3
			_3:
				;
				j++
			}
			_walMergesort(tls, (*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno, aTmp, aIndex, bp+12)
			(*(*TWalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*20))).FiZero = int32((*(*TWalHashLoc)(unsafe.Pointer(bp))).FiZero)
			(*(*TWalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*20))).FnEntry = *(*int32)(unsafe.Pointer(bp + 12))
			(*(*TWalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*20))).FaIndex = aIndex
			(*(*TWalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*20))).FaPgno = (*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno
		}
		goto _2
	_2:
		;
		i++
	}
	if rc != SQLITE_OK {
		_walIteratorFree(tls, p)
		p = uintptr(0)
	}
	*(*uintptr)(unsafe.Pointer(pp)) = p
	return rc
}

// C documentation
//
//	/*
//	** Attempt to obtain the exclusive WAL lock defined by parameters lockIdx and
//	** n. If the attempt fails and parameter xBusy is not NULL, then it is a
//	** busy-handler function. Invoke it and retry the lock until either the
//	** lock is successfully obtained or the busy-handler returns 0.
//	*/
func _walBusyLock(tls *libc.TLS, pWal uintptr, xBusy uintptr, pBusyArg uintptr, lockIdx int32, n int32) (r int32) {
	var rc int32
	_ = rc
	for cond := true; cond; cond = xBusy != 0 && rc == int32(SQLITE_BUSY) && (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xBusy})))(tls, pBusyArg) != 0 {
		rc = _walLockExclusive(tls, pWal, lockIdx, n)
	}
	return rc
}

// C documentation
//
//	/*
//	** The cache of the wal-index header must be valid to call this function.
//	** Return the page-size in bytes used by the database.
//	*/
func _walPagesize(tls *libc.TLS, pWal uintptr) (r int32) {
	return int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&int32(0xfe00) + int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&int32(0x0001)<<int32(16)
}

// C documentation
//
//	/*
//	** The following is guaranteed when this function is called:
//	**
//	**   a) the WRITER lock is held,
//	**   b) the entire log file has been checkpointed, and
//	**   c) any existing readers are reading exclusively from the database
//	**      file - there are no readers that may attempt to read a frame from
//	**      the log file.
//	**
//	** This function updates the shared-memory structures so that the next
//	** client to write to the database (which may be this one) does so by
//	** writing frames into the start of the log file.
//	**
//	** The value of parameter salt1 is used as the aSalt[1] value in the
//	** new wal-index header. It should be passed a pseudo-random value (i.e.
//	** one obtained from sqlite3_randomness()).
//	*/
func _walRestartHdr(tls *libc.TLS, pWal uintptr, _salt1 Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*Tu32)(unsafe.Pointer(bp)) = _salt1
	var aSalt, pInfo uintptr
	var i int32
	_, _, _ = aSalt, i, pInfo
	pInfo = _walCkptInfo(tls, pWal) /* Loop counter */
	aSalt = pWal + 52 + 32          /* Big-endian salt values */
	(*TWal)(unsafe.Pointer(pWal)).FnCkpt++
	(*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = uint32(0)
	_sqlite3Put4byte(tls, aSalt, uint32(1)+_sqlite3Get4byte(tls, aSalt))
	libc.Xmemcpy(tls, pWal+52+32+1*4, bp, uint32(4))
	_walIndexWriteHdr(tls, pWal)
	libc.AtomicStoreNUint32(pInfo, uint32(libc.Int32FromInt32(0)), libc.Int32FromInt32(__ATOMIC_RELAXED))
	(*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = uint32(0)
	*(*Tu32)(unsafe.Pointer(pInfo + 4 + 1*4)) = uint32(0)
	i = int32(2)
	for {
		if !(i < libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)) {
			break
		}
		*(*Tu32)(unsafe.Pointer(pInfo + 4 + uintptr(i)*4)) = uint32(READMARK_NOT_USED)
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Copy as much content as we can from the WAL back into the database file
//	** in response to an sqlite3_wal_checkpoint() request or the equivalent.
//	**
//	** The amount of information copies from WAL to database might be limited
//	** by active readers.  This routine will never overwrite a database page
//	** that a concurrent reader might be using.
//	**
//	** All I/O barrier operations (a.k.a fsyncs) occur in this routine when
//	** SQLite is in WAL-mode in synchronous=NORMAL.  That means that if
//	** checkpoints are always run by a background thread or background
//	** process, foreground threads will never block on a lengthy fsync call.
//	**
//	** Fsync is called on the WAL before writing content out of the WAL and
//	** into the database.  This ensures that if the new content is persistent
//	** in the WAL and can be recovered following a power-loss or hard reset.
//	**
//	** Fsync is also called on the database file if (and only if) the entire
//	** WAL content is copied into the database file.  This second fsync makes
//	** it safe to delete the WAL since the new content will persist in the
//	** database file.
//	**
//	** This routine uses and updates the nBackfill field of the wal-index header.
//	** This is the only routine that will increase the value of nBackfill.
//	** (A WAL reset or recovery will revert nBackfill to zero, but not increase
//	** its value.)
//	**
//	** The caller must be holding sufficient locks to ensure that no other
//	** checkpoint is running (in any other thread or process) at the same
//	** time.
//	*/
func _walCheckpoint(tls *libc.TLS, pWal uintptr, db uintptr, eMode int32, xBusy uintptr, pBusyArg uintptr, sync_flags int32, zBuf uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, rc, szPage, v3, v5 int32
	var iMark, mxPage, mxSafeFrame, nBackfill, y Tu32
	var iOffset, szDb Ti64
	var pInfo uintptr
	var v2 uint32
	var v4 bool
	var _ /* iDbpage at bp+4 */ Tu32
	var _ /* iFrame at bp+8 */ Tu32
	var _ /* nReq at bp+16 */ Ti64
	var _ /* nSize at bp+24 */ Ti64
	var _ /* pIter at bp+0 */ uintptr
	var _ /* salt1 at bp+32 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iMark, iOffset, mxPage, mxSafeFrame, nBackfill, pInfo, rc, szDb, szPage, y, v2, v3, v4, v5
	rc = SQLITE_OK                               /* Database page-size */
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Wal iterator context */
	*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0) /* Next database page to write */
	*(*Tu32)(unsafe.Pointer(bp + 8)) = uint32(0) /* The checkpoint status information */
	szPage = _walPagesize(tls, pWal)
	pInfo = _walCkptInfo(tls, pWal)
	if (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill < (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
		/* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
		 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
		/* Compute in mxSafeFrame the index of the last frame of the WAL that is
		 ** safe to write into the database.  Frames beyond mxSafeFrame might
		 ** overwrite database pages that are in use by active readers and thus
		 ** cannot be backfilled from the WAL.
		 */
		mxSafeFrame = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
		mxPage = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage
		i = int32(1)
		for {
			if !(i < libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)) {
				break
			}
			y = libc.AtomicLoadNUint32(pInfo+4+uintptr(i)*4, libc.Int32FromInt32(__ATOMIC_RELAXED))
			if mxSafeFrame > y {
				rc = _walBusyLock(tls, pWal, xBusy, pBusyArg, int32(3)+i, int32(1))
				if rc == SQLITE_OK {
					if i == int32(1) {
						v2 = mxSafeFrame
					} else {
						v2 = uint32(READMARK_NOT_USED)
					}
					iMark = v2
					libc.AtomicStoreNUint32(pInfo+4+uintptr(i)*4, iMark, libc.Int32FromInt32(__ATOMIC_RELAXED))
					_walUnlockExclusive(tls, pWal, int32(3)+i, int32(1))
				} else {
					if rc == int32(SQLITE_BUSY) {
						mxSafeFrame = y
						xBusy = uintptr(0)
					} else {
						goto walcheckpoint_out
					}
				}
			}
			goto _1
		_1:
			;
			i++
		}
		/* Allocate the iterator */
		if (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill < mxSafeFrame {
			rc = _walIteratorInit(tls, pWal, (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill, bp)
		}
		if v4 = *(*uintptr)(unsafe.Pointer(bp)) != 0; v4 {
			v3 = _walBusyLock(tls, pWal, xBusy, pBusyArg, libc.Int32FromInt32(3)+libc.Int32FromInt32(0), int32(1))
			rc = v3
		}
		if v4 && v3 == SQLITE_OK {
			nBackfill = (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill
			(*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = mxSafeFrame
			/* Sync the WAL to disk */
			rc = _sqlite3OsSync(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, sync_flags>>int32(2)&int32(0x03))
			/* If the database may grow as a result of this checkpoint, hint
			 ** about the eventual size of the db file to the VFS layer.
			 */
			if rc == SQLITE_OK {
				*(*Ti64)(unsafe.Pointer(bp + 16)) = int64(int64(mxPage)) * int64(int64(szPage)) /* Current size of database file */
				_sqlite3OsFileControl(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, int32(SQLITE_FCNTL_CKPT_START), uintptr(0))
				rc = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, bp+24)
				if rc == SQLITE_OK && *(*Ti64)(unsafe.Pointer(bp + 24)) < *(*Ti64)(unsafe.Pointer(bp + 16)) {
					if *(*Ti64)(unsafe.Pointer(bp + 24))+int64(65536)+int64((*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame)*int64(int64(szPage)) < *(*Ti64)(unsafe.Pointer(bp + 16)) {
						/* If the size of the final database is larger than the current
						 ** database plus the amount of data in the wal file, plus the
						 ** maximum size of the pending-byte page (65536 bytes), then
						 ** must be corruption somewhere.  */
						rc = _sqlite3CorruptError(tls, int32(67181))
					} else {
						_sqlite3OsFileControlHint(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, int32(SQLITE_FCNTL_SIZE_HINT), bp+16)
					}
				}
			}
			/* Iterate through the contents of the WAL, copying data to the db file */
			for rc == SQLITE_OK && 0 == _walIteratorNext(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+4, bp+8) {
				if libc.AtomicLoadNInt32(db+312, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
					if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
						v5 = int32(SQLITE_NOMEM)
					} else {
						v5 = int32(SQLITE_INTERRUPT)
					}
					rc = v5
					break
				}
				if *(*Tu32)(unsafe.Pointer(bp + 8)) <= nBackfill || *(*Tu32)(unsafe.Pointer(bp + 8)) > mxSafeFrame || *(*Tu32)(unsafe.Pointer(bp + 4)) > mxPage {
					continue
				}
				iOffset = int64(WAL_HDRSIZE) + int64(*(*Tu32)(unsafe.Pointer(bp + 8))-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) + int64(WAL_FRAME_HDRSIZE)
				/* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
				rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, zBuf, szPage, iOffset)
				if rc != SQLITE_OK {
					break
				}
				iOffset = int64(*(*Tu32)(unsafe.Pointer(bp + 4))-libc.Uint32FromInt32(1)) * int64(int64(szPage))
				rc = _sqlite3OsWrite(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, zBuf, szPage, iOffset)
				if rc != SQLITE_OK {
					break
				}
			}
			_sqlite3OsFileControl(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, int32(SQLITE_FCNTL_CKPT_DONE), uintptr(0))
			/* If work was actually accomplished... */
			if rc == SQLITE_OK {
				if mxSafeFrame == (*TWalIndexHdr)(unsafe.Pointer(_walIndexHdr(tls, pWal))).FmxFrame {
					szDb = int64((*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage) * int64(int64(szPage))
					rc = _sqlite3OsTruncate(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, szDb)
					if rc == SQLITE_OK {
						rc = _sqlite3OsSync(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, sync_flags>>int32(2)&int32(0x03))
					}
				}
				if rc == SQLITE_OK {
					libc.AtomicStoreNUint32(pInfo, mxSafeFrame, libc.Int32FromInt32(__ATOMIC_RELAXED))
				}
			}
			/* Release the reader lock held while backfilling */
			_walUnlockExclusive(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(0), int32(1))
		}
		if rc == int32(SQLITE_BUSY) {
			/* Reset the return code so as not to report a checkpoint failure
			 ** just because there are active readers.  */
			rc = SQLITE_OK
		}
	}
	/* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the
	 ** entire wal file has been copied into the database file, then block
	 ** until all readers have finished using the wal file. This ensures that
	 ** the next process to write to the database restarts the wal file.
	 */
	if rc == SQLITE_OK && eMode != SQLITE_CHECKPOINT_PASSIVE {
		if (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill < (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
			rc = int32(SQLITE_BUSY)
		} else {
			if eMode >= int32(SQLITE_CHECKPOINT_RESTART) {
				Xsqlite3_randomness(tls, int32(4), bp+32)
				rc = _walBusyLock(tls, pWal, xBusy, pBusyArg, libc.Int32FromInt32(3)+libc.Int32FromInt32(1), libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
				if rc == SQLITE_OK {
					if eMode == int32(SQLITE_CHECKPOINT_TRUNCATE) {
						/* IMPLEMENTATION-OF: R-44699-57140 This mode works the same way as
						 ** SQLITE_CHECKPOINT_RESTART with the addition that it also
						 ** truncates the log file to zero bytes just prior to a
						 ** successful return.
						 **
						 ** In theory, it might be safe to do this without updating the
						 ** wal-index header in shared memory, as all subsequent reader or
						 ** writer clients should see that the entire log file has been
						 ** checkpointed and behave accordingly. This seems unsafe though,
						 ** as it would leave the system in a state where the contents of
						 ** the wal-index header do not match the contents of the
						 ** file-system. To avoid this, update the wal-index header to
						 ** indicate that the log file contains zero valid frames.  */
						_walRestartHdr(tls, pWal, *(*Tu32)(unsafe.Pointer(bp + 32)))
						rc = _sqlite3OsTruncate(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, 0)
					}
					_walUnlockExclusive(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(1), libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
				}
			}
		}
	}
	goto walcheckpoint_out
walcheckpoint_out:
	;
	_walIteratorFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

// C documentation
//
//	/*
//	** If the WAL file is currently larger than nMax bytes in size, truncate
//	** it to exactly nMax bytes. If an error occurs while doing so, ignore it.
//	*/
func _walLimitSize(tls *libc.TLS, pWal uintptr, nMax Ti64) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rx int32
	var _ /* sz at bp+0 */ Ti64
	_ = rx
	_sqlite3BeginBenignMalloc(tls)
	rx = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp)
	if rx == SQLITE_OK && *(*Ti64)(unsafe.Pointer(bp)) > nMax {
		rx = _sqlite3OsTruncate(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, nMax)
	}
	_sqlite3EndBenignMalloc(tls)
	if rx != 0 {
		Xsqlite3_log(tls, rx, __ccgo_ts+5537, libc.VaList(bp+16, (*TWal)(unsafe.Pointer(pWal)).FzWalName))
	}
}

// C documentation
//
//	/*
//	** Close a connection to a log file.
//	*/
func _sqlite3WalClose(tls *libc.TLS, pWal uintptr, db uintptr, sync_flags int32, nBuf int32, zBuf uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var isDelete, rc, v1 int32
	var v2 bool
	var _ /* bPersist at bp+0 */ int32
	_, _, _, _ = isDelete, rc, v1, v2
	rc = SQLITE_OK
	if pWal != 0 {
		isDelete = 0 /* True to unlink wal and wal-index files */
		/* If an EXCLUSIVE lock can be obtained on the database file (using the
		 ** ordinary, rollback-mode locking methods, this guarantees that the
		 ** connection associated with this log file is the only connection to
		 ** the database. In this case checkpoint the database and unlink both
		 ** the wal and wal-index files.
		 **
		 ** The EXCLUSIVE lock is not released before returning.
		 */
		if v2 = zBuf != uintptr(0); v2 {
			v1 = _sqlite3OsLock(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, int32(SQLITE_LOCK_EXCLUSIVE))
			rc = v1
		}
		if v2 && SQLITE_OK == v1 {
			if int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_NORMAL_MODE {
				(*TWal)(unsafe.Pointer(pWal)).FexclusiveMode = uint8(WAL_EXCLUSIVE_MODE)
			}
			rc = _sqlite3WalCheckpoint(tls, pWal, db, SQLITE_CHECKPOINT_PASSIVE, uintptr(0), uintptr(0), sync_flags, nBuf, zBuf, uintptr(0), uintptr(0))
			if rc == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp)) = -int32(1)
				_sqlite3OsFileControlHint(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, int32(SQLITE_FCNTL_PERSIST_WAL), bp)
				if *(*int32)(unsafe.Pointer(bp)) != int32(1) {
					/* Try to delete the WAL file if the checkpoint completed and
					 ** fsynced (rc==SQLITE_OK) and if we are not in persistent-wal
					 ** mode (!bPersist) */
					isDelete = int32(1)
				} else {
					if (*TWal)(unsafe.Pointer(pWal)).FmxWalSize >= 0 {
						/* Try to truncate the WAL file to zero bytes if the checkpoint
						 ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
						 ** WAL mode (bPersist) and if the PRAGMA journal_size_limit is a
						 ** non-negative value (pWal->mxWalSize>=0).  Note that we truncate
						 ** to zero bytes as truncating to the journal_size_limit might
						 ** leave a corrupt WAL file on disk. */
						_walLimitSize(tls, pWal, 0)
					}
				}
			}
		}
		_walIndexClose(tls, pWal, isDelete)
		_sqlite3OsClose(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd)
		if isDelete != 0 {
			_sqlite3BeginBenignMalloc(tls)
			_sqlite3OsDelete(tls, (*TWal)(unsafe.Pointer(pWal)).FpVfs, (*TWal)(unsafe.Pointer(pWal)).FzWalName, 0)
			_sqlite3EndBenignMalloc(tls)
		}
		Xsqlite3_free(tls, (*TWal)(unsafe.Pointer(pWal)).FapWiData)
		Xsqlite3_free(tls, pWal)
	}
	return rc
}

// C documentation
//
//	/*
//	** Try to read the wal-index header.  Return 0 on success and 1 if
//	** there is a problem.
//	**
//	** The wal-index is in shared memory.  Another thread or process might
//	** be writing the header at the same time this procedure is trying to
//	** read it, which might result in inconsistency.  A dirty read is detected
//	** by verifying that both copies of the header are the same and also by
//	** a checksum on the header.
//	**
//	** If and only if the read is consistent and the header is different from
//	** pWal->hdr, then pWal->hdr is updated to the content of the new header
//	** and *pChanged is set to 1.
//	**
//	** If the checksum cannot be verified return non-zero. If the header
//	** is read successfully and the checksum verified, return zero.
//	*/
func _walIndexTryHdr(tls *libc.TLS, pWal uintptr, pChanged uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var aHdr uintptr
	var _ /* aCksum at bp+0 */ [2]Tu32
	var _ /* h1 at bp+8 */ TWalIndexHdr
	var _ /* h2 at bp+56 */ TWalIndexHdr
	_ = aHdr /* Header in shared memory */
	/* The first page of the wal-index must be mapped at this point. */
	/* Read the header. This might happen concurrently with a write to the
	 ** same area of shared memory on a different CPU in a SMP,
	 ** meaning it is possible that an inconsistent snapshot is read
	 ** from the file. If this happens, return non-zero.
	 **
	 ** tag-20200519-1:
	 ** There are two copies of the header at the beginning of the wal-index.
	 ** When reading, read [0] first then [1].  Writes are in the reverse order.
	 ** Memory barriers are used to prevent the compiler or the hardware from
	 ** reordering the reads and writes.  TSAN and similar tools can sometimes
	 ** give false-positive warnings about these accesses because the tools do not
	 ** account for the double-read and the memory barrier. The use of mutexes
	 ** here would be problematic as the memory being accessed is potentially
	 ** shared among multiple processes and not all mutex implementations work
	 ** reliably in that environment.
	 */
	aHdr = _walIndexHdr(tls, pWal)
	libc.Xmemcpy(tls, bp+8, aHdr, uint32(48)) /* Possible TSAN false-positive */
	_walShmBarrier(tls, pWal)
	libc.Xmemcpy(tls, bp+56, aHdr+1*48, uint32(48))
	if libc.Xmemcmp(tls, bp+8, bp+56, uint32(48)) != 0 {
		return int32(1) /* Dirty read */
	}
	if int32((*(*TWalIndexHdr)(unsafe.Pointer(bp + 8))).FisInit) == 0 {
		return int32(1) /* Malformed header - probably all zeros */
	}
	_walChecksumBytes(tls, int32(1), bp+8, int32(libc.Uint32FromInt64(48)-libc.Uint32FromInt64(8)), uintptr(0), bp)
	if (*(*[2]Tu32)(unsafe.Pointer(bp)))[0] != *(*Tu32)(unsafe.Pointer(bp + 8 + 40)) || (*(*[2]Tu32)(unsafe.Pointer(bp)))[int32(1)] != *(*Tu32)(unsafe.Pointer(bp + 8 + 40 + 1*4)) {
		return int32(1) /* Checksum does not match */
	}
	if libc.Xmemcmp(tls, pWal+52, bp+8, uint32(48)) != 0 {
		*(*int32)(unsafe.Pointer(pChanged)) = int32(1)
		libc.Xmemcpy(tls, pWal+52, bp+8, uint32(48))
		(*TWal)(unsafe.Pointer(pWal)).FszPage = uint32(int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&int32(0xfe00) + int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&int32(0x0001)<<int32(16))
	}
	/* The header was successfully read. Return zero. */
	return 0
}

/*
** This is the value that walTryBeginRead returns when it needs to
** be retried.
 */

// C documentation
//
//	/*
//	** Read the wal-index header from the wal-index and into pWal->hdr.
//	** If the wal-header appears to be corrupt, try to reconstruct the
//	** wal-index from the WAL before returning.
//	**
//	** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
//	** changed by this operation.  If pWal->hdr is unchanged, set *pChanged
//	** to 0.
//	**
//	** If the wal-index header is successfully read, return SQLITE_OK.
//	** Otherwise an SQLite error code.
//	*/
func _walIndexReadHdr(tls *libc.TLS, pWal uintptr, pChanged uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bWriteLock, badHdr, rc, v1, v2, v3, v5 int32
	var v4 bool
	var _ /* page0 at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = bWriteLock, badHdr, rc, v1, v2, v3, v4, v5 /* Chunk of wal-index containing header */
	/* Ensure that page 0 of the wal-index (the page that contains the
	 ** wal-index header) is mapped. Return early if an error occurs here.
	 */
	rc = _walIndexPage(tls, pWal, 0, bp)
	if rc != SQLITE_OK {
		/* READONLY changed to OK in walIndexPage */
		if rc == libc.Int32FromInt32(SQLITE_READONLY)|libc.Int32FromInt32(5)<<libc.Int32FromInt32(8) {
			/* The SQLITE_READONLY_CANTINIT return means that the shared-memory
			 ** was openable but is not writable, and this thread is unable to
			 ** confirm that another write-capable connection has the shared-memory
			 ** open, and hence the content of the shared-memory is unreliable,
			 ** since the shared-memory might be inconsistent with the WAL file
			 ** and there is no writer on hand to fix it. */
			(*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable = uint8(1)
			(*TWal)(unsafe.Pointer(pWal)).FexclusiveMode = uint8(WAL_HEAPMEMORY_MODE)
			*(*int32)(unsafe.Pointer(pChanged)) = int32(1)
		} else {
			return rc /* Any other non-OK return is just an error */
		}
	} else {
		/* page0 can be NULL if the SHM is zero bytes in size and pWal->writeLock
		 ** is zero, which prevents the SHM from growing */
	}
	/* If the first page of the wal-index has been mapped, try to read the
	 ** wal-index header immediately, without holding any lock. This usually
	 ** works, but may fail if the wal-index header is corrupt or currently
	 ** being modified by another thread or process.
	 */
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		v1 = _walIndexTryHdr(tls, pWal, pChanged)
	} else {
		v1 = int32(1)
	}
	badHdr = v1
	/* If the first attempt failed, it might have been due to a race
	 ** with a writer.  So get a WRITE lock and try again.
	 */
	if badHdr != 0 {
		if int32((*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable) == 0 && int32((*TWal)(unsafe.Pointer(pWal)).FreadOnly)&int32(WAL_SHM_RDONLY) != 0 {
			v2 = _walLockShared(tls, pWal, WAL_WRITE_LOCK)
			rc = v2
			if SQLITE_OK == v2 {
				_walUnlockShared(tls, pWal, WAL_WRITE_LOCK)
				rc = libc.Int32FromInt32(SQLITE_READONLY) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		} else {
			bWriteLock = int32((*TWal)(unsafe.Pointer(pWal)).FwriteLock)
			if v4 = bWriteLock != 0; !v4 {
				v3 = _walLockExclusive(tls, pWal, WAL_WRITE_LOCK, int32(1))
				rc = v3
			}
			if v4 || SQLITE_OK == v3 {
				(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(1)
				v5 = _walIndexPage(tls, pWal, 0, bp)
				rc = v5
				if SQLITE_OK == v5 {
					badHdr = _walIndexTryHdr(tls, pWal, pChanged)
					if badHdr != 0 {
						/* If the wal-index header is still malformed even while holding
						 ** a WRITE lock, it can only mean that the header is corrupted and
						 ** needs to be reconstructed.  So run recovery to do exactly that.
						 ** Disable blocking locks first.  */
						rc = _walIndexRecover(tls, pWal)
						*(*int32)(unsafe.Pointer(pChanged)) = int32(1)
					}
				}
				if bWriteLock == 0 {
					(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(0)
					_walUnlockExclusive(tls, pWal, WAL_WRITE_LOCK, int32(1))
				}
			}
		}
	}
	/* If the header is read successfully, check the version number to make
	 ** sure the wal-index was not constructed with some future format that
	 ** this version of SQLite cannot understand.
	 */
	if badHdr == 0 && (*TWal)(unsafe.Pointer(pWal)).Fhdr.FiVersion != uint32(WALINDEX_MAX_VERSION) {
		rc = _sqlite3CantopenError(tls, int32(67625))
	}
	if (*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable != 0 {
		if rc != SQLITE_OK {
			_walIndexClose(tls, pWal, 0)
			(*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable = uint8(0)
			/* walIndexRecover() might have returned SHORT_READ if a concurrent
			 ** writer truncated the WAL out from under it.  If that happens, it
			 ** indicates that a writer has fixed the SHM file for us, so retry */
			if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
				rc = -int32(1)
			}
		}
		(*TWal)(unsafe.Pointer(pWal)).FexclusiveMode = uint8(WAL_NORMAL_MODE)
	}
	return rc
}

// C documentation
//
//	/*
//	** Open a transaction in a connection where the shared-memory is read-only
//	** and where we cannot verify that there is a separate write-capable connection
//	** on hand to keep the shared-memory up-to-date with the WAL file.
//	**
//	** This can happen, for example, when the shared-memory is implemented by
//	** memory-mapping a *-shm file, where a prior writer has shut down and
//	** left the *-shm file on disk, and now the present connection is trying
//	** to use that database but lacks write permission on the *-shm file.
//	** Other scenarios are also possible, depending on the VFS implementation.
//	**
//	** Precondition:
//	**
//	**    The *-wal file has been read and an appropriate wal-index has been
//	**    constructed in pWal->apWiData[] using heap memory instead of shared
//	**    memory.
//	**
//	** If this function returns SQLITE_OK, then the read transaction has
//	** been successfully opened. In this case output variable (*pChanged)
//	** is set to true before returning if the caller should discard the
//	** contents of the page cache before proceeding. Or, if it returns
//	** WAL_RETRY, then the heap memory wal-index has been discarded and
//	** the caller should retry opening the read transaction from the
//	** beginning (including attempting to map the *-shm file).
//	**
//	** If an error occurs, an SQLite error code is returned.
//	*/
func _walBeginShmUnreliable(tls *libc.TLS, pWal uintptr, pChanged uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aData, aFrame uintptr
	var aSaveCksum [2]Tu32
	var i, rc, szFrame, v1, v2 int32
	var iOffset Ti64
	var _ /* aBuf at bp+8 */ [32]Tu8
	var _ /* nTruncate at bp+48 */ Tu32
	var _ /* pDummy at bp+40 */ uintptr
	var _ /* pgno at bp+44 */ Tu32
	var _ /* szWal at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _ = aData, aFrame, aSaveCksum, i, iOffset, rc, szFrame, v1, v2 /* Buffer to load WAL header into */
	aFrame = uintptr(0)                                                                    /* Saved copy of pWal->hdr.aFrameCksum */
	/* Take WAL_READ_LOCK(0). This has the effect of preventing any
	 ** writers from running a checkpoint, but does not stop them
	 ** from running recovery.  */
	rc = _walLockShared(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(0))
	if rc != SQLITE_OK {
		if rc == int32(SQLITE_BUSY) {
			rc = -int32(1)
		}
		goto begin_unreliable_shm_out
	}
	(*TWal)(unsafe.Pointer(pWal)).FreadLock = 0
	/* Check to see if a separate writer has attached to the shared-memory area,
	 ** thus making the shared-memory "reliable" again.  Do this by invoking
	 ** the xShmMap() routine of the VFS and looking to see if the return
	 ** is SQLITE_READONLY instead of SQLITE_READONLY_CANTINIT.
	 **
	 ** If the shared-memory is now "reliable" return WAL_RETRY, which will
	 ** cause the heap-memory WAL-index to be discarded and the actual
	 ** shared memory to be used in its place.
	 **
	 ** This step is important because, even though this connection is holding
	 ** the WAL_READ_LOCK(0) which prevents a checkpoint, a writer might
	 ** have already checkpointed the WAL file and, while the current
	 ** is active, wrap the WAL and start overwriting frames that this
	 ** process wants to use.
	 **
	 ** Once sqlite3OsShmMap() has been called for an sqlite3_file and has
	 ** returned any SQLITE_READONLY value, it must return only SQLITE_READONLY
	 ** or SQLITE_READONLY_CANTINIT or some error for all subsequent invocations,
	 ** even if some external agent does a "chmod" to make the shared-memory
	 ** writable by us, until sqlite3OsShmUnmap() has been called.
	 ** This is a requirement on the VFS implementation.
	 */
	rc = _sqlite3OsShmMap(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, 0, int32(libc.Uint32FromInt64(2)*uint32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint32FromInt32(HASHTABLE_NPAGE)*libc.Uint32FromInt64(4)), 0, bp+40)
	/* SQLITE_OK not possible for read-only connection */
	if rc != libc.Int32FromInt32(SQLITE_READONLY)|libc.Int32FromInt32(5)<<libc.Int32FromInt32(8) {
		if rc == int32(SQLITE_READONLY) {
			v1 = -int32(1)
		} else {
			v1 = rc
		}
		rc = v1
		goto begin_unreliable_shm_out
	}
	/* We reach this point only if the real shared-memory is still unreliable.
	 ** Assume the in-memory WAL-index substitute is correct and load it
	 ** into pWal->hdr.
	 */
	libc.Xmemcpy(tls, pWal+52, _walIndexHdr(tls, pWal), uint32(48))
	/* Make sure some writer hasn't come in and changed the WAL file out
	 ** from under us, then disconnected, while we were not looking.
	 */
	rc = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp)
	if rc != SQLITE_OK {
		goto begin_unreliable_shm_out
	}
	if *(*Ti64)(unsafe.Pointer(bp)) < int64(WAL_HDRSIZE) {
		/* If the wal file is too small to contain a wal-header and the
		 ** wal-index header has mxFrame==0, then it must be safe to proceed
		 ** reading the database file only. However, the page cache cannot
		 ** be trusted, as a read/write connection may have connected, written
		 ** the db, run a checkpoint, truncated the wal file and disconnected
		 ** since this client's last read transaction.  */
		*(*int32)(unsafe.Pointer(pChanged)) = int32(1)
		if (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame == uint32(0) {
			v2 = SQLITE_OK
		} else {
			v2 = -int32(1)
		}
		rc = v2
		goto begin_unreliable_shm_out
	}
	/* Check the salt keys at the start of the wal file still match. */
	rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp+8, int32(WAL_HDRSIZE), 0)
	if rc != SQLITE_OK {
		goto begin_unreliable_shm_out
	}
	if libc.Xmemcmp(tls, pWal+52+32, bp+8+16, uint32(8)) != 0 {
		/* Some writer has wrapped the WAL file while we were not looking.
		 ** Return WAL_RETRY which will cause the in-memory WAL-index to be
		 ** rebuilt. */
		rc = -int32(1)
		goto begin_unreliable_shm_out
	}
	/* Allocate a buffer to read frames into */
	szFrame = int32((*TWal)(unsafe.Pointer(pWal)).FszPage + uint32(WAL_FRAME_HDRSIZE))
	aFrame = Xsqlite3_malloc64(tls, uint64(uint64(szFrame)))
	if aFrame == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
		goto begin_unreliable_shm_out
	}
	aData = aFrame + 24
	/* Check to see if a complete transaction has been appended to the
	 ** wal file since the heap-memory wal-index was created. If so, the
	 ** heap-memory wal-index is discarded and WAL_RETRY returned to
	 ** the caller.  */
	aSaveCksum[0] = *(*Tu32)(unsafe.Pointer(pWal + 52 + 24))
	aSaveCksum[int32(1)] = *(*Tu32)(unsafe.Pointer(pWal + 52 + 24 + 1*4))
	iOffset = libc.Int64FromInt32(WAL_HDRSIZE) + int64((*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame+libc.Uint32FromInt32(1)-libc.Uint32FromInt32(1))*int64((*TWal)(unsafe.Pointer(pWal)).FszPage+libc.Uint32FromInt32(WAL_FRAME_HDRSIZE))
	for {
		if !(iOffset+int64(int64(szFrame)) <= *(*Ti64)(unsafe.Pointer(bp))) {
			break
		} /* 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
		}
		if !(_walDecodeFrame(tls, pWal, bp+44, bp+48, aData, aFrame) != 0) {
			break
		}
		/* If nTruncate is non-zero, then a complete transaction has been
		 ** appended to this wal file. Set rc to WAL_RETRY and break out of
		 ** the loop.  */
		if *(*Tu32)(unsafe.Pointer(bp + 48)) != 0 {
			rc = -int32(1)
			break
		}
		goto _3
	_3:
		;
		iOffset += int64(int64(szFrame))
	}
	*(*Tu32)(unsafe.Pointer(pWal + 52 + 24)) = aSaveCksum[0]
	*(*Tu32)(unsafe.Pointer(pWal + 52 + 24 + 1*4)) = aSaveCksum[int32(1)]
	goto begin_unreliable_shm_out
begin_unreliable_shm_out:
	;
	Xsqlite3_free(tls, aFrame)
	if rc != SQLITE_OK {
		i = 0
		for {
			if !(i < (*TWal)(unsafe.Pointer(pWal)).FnWiData) {
				break
			}
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*4)))
			*(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*4)) = uintptr(0)
			goto _4
		_4:
			;
			i++
		}
		(*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable = uint8(0)
		_sqlite3WalEndReadTransaction(tls, pWal)
		*(*int32)(unsafe.Pointer(pChanged)) = int32(1)
	}
	return rc
}

/*
** The final argument passed to walTryBeginRead() is of type (int*). The
** caller should invoke walTryBeginRead as follows:
**
**   int cnt = 0;
**   do {
**     rc = walTryBeginRead(..., &cnt);
**   }while( rc==WAL_RETRY );
**
** The final value of "cnt" is of no use to the caller. It is used by
** the implementation of walTryBeginRead() as follows:
**
**   + Each time walTryBeginRead() is called, it is incremented. Once
**     it reaches WAL_RETRY_PROTOCOL_LIMIT - indicating that walTryBeginRead()
**     has many times been invoked and failed with WAL_RETRY - walTryBeginRead()
**     returns SQLITE_PROTOCOL.
**
**   + If SQLITE_ENABLE_SETLK_TIMEOUT is defined and walTryBeginRead() failed
**     because a blocking lock timed out (SQLITE_BUSY_TIMEOUT from the OS
**     layer), the WAL_RETRY_BLOCKED_MASK bit is set in "cnt". In this case
**     the next invocation of walTryBeginRead() may omit an expected call to
**     sqlite3OsSleep(). There has already been a delay when the previous call
**     waited on a lock.
 */

// C documentation
//
//	/*
//	** Attempt to start a read transaction.  This might fail due to a race or
//	** other transient condition.  When that happens, it returns WAL_RETRY to
//	** indicate to the caller that it is safe to retry immediately.
//	**
//	** On success return SQLITE_OK.  On a permanent failure (such an
//	** I/O error or an SQLITE_BUSY because another process is running
//	** recovery) return a positive error code.
//	**
//	** The useWal parameter is true to force the use of the WAL and disable
//	** the case where the WAL is bypassed because it has been completely
//	** checkpointed.  If useWal==0 then this routine calls walIndexReadHdr()
//	** to make a copy of the wal-index header into pWal->hdr.  If the
//	** wal-index header has changed, *pChanged is set to 1 (as an indication
//	** to the caller that the local page cache is obsolete and needs to be
//	** flushed.)  When useWal==1, the wal-index header is assumed to already
//	** be loaded and the pChanged parameter is unused.
//	**
//	** The caller must set the cnt parameter to the number of prior calls to
//	** this routine during the current read attempt that returned WAL_RETRY.
//	** This routine will start taking more aggressive measures to clear the
//	** race conditions after multiple WAL_RETRY returns, and after an excessive
//	** number of errors will ultimately return SQLITE_PROTOCOL.  The
//	** SQLITE_PROTOCOL return indicates that some other process has gone rogue
//	** and is not honoring the locking protocol.  There is a vanishingly small
//	** chance that SQLITE_PROTOCOL could be returned because of a run of really
//	** bad luck when there is lots of contention for the wal-index, but that
//	** possibility is so small that it can be safely neglected, we believe.
//	**
//	** On success, this routine obtains a read lock on
//	** WAL_READ_LOCK(pWal->readLock).  The pWal->readLock integer is
//	** in the range 0 <= pWal->readLock < WAL_NREADER.  If pWal->readLock==(-1)
//	** that means the Wal does not hold any read lock.  The reader must not
//	** access any database page that is modified by a WAL frame up to and
//	** including frame number aReadMark[pWal->readLock].  The reader will
//	** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0
//	** Or if pWal->readLock==0, then the reader will ignore the WAL
//	** completely and get all content directly from the database file.
//	** If the useWal parameter is 1 then the WAL will never be ignored and
//	** this routine will always set pWal->readLock>0 on success.
//	** When the read transaction is completed, the caller must release the
//	** lock on WAL_READ_LOCK(pWal->readLock) and set pWal->readLock to -1.
//	**
//	** This routine uses the nBackfill and aReadMark[] fields of the header
//	** to select a particular WAL_READ_LOCK() that strives to let the
//	** checkpoint process do as much work as possible.  This routine might
//	** update values of the aReadMark[] array in the header, but if it does
//	** so it takes care to hold an exclusive lock on the corresponding
//	** WAL_READ_LOCK() while changing values.
//	*/
func _walTryBeginRead(tls *libc.TLS, pWal uintptr, pChanged uintptr, useWal int32, pCnt uintptr) (r int32) {
	var cnt, i, mxI, nDelay, rc, v1, v4, v5 int32
	var mxFrame, mxReadMark, thisMark Tu32
	var pInfo uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = cnt, i, mxFrame, mxI, mxReadMark, nDelay, pInfo, rc, thisMark, v1, v4, v5 /* Loop counter */
	rc = SQLITE_OK                                                                                                 /* Wal frame to lock to */
	/* Not currently locked */
	/* useWal may only be set for read/write connections */
	/* Take steps to avoid spinning forever if there is a protocol error.
	 **
	 ** Circumstances that cause a RETRY should only last for the briefest
	 ** instances of time.  No I/O or other system calls are done while the
	 ** locks are held, so the locks should not be held for very long. But
	 ** if we are unlucky, another process that is holding a lock might get
	 ** paged out or take a page-fault that is time-consuming to resolve,
	 ** during the few nanoseconds that it is holding the lock.  In that case,
	 ** it might take longer than normal for the lock to free.
	 **
	 ** After 5 RETRYs, we begin calling sqlite3OsSleep().  The first few
	 ** calls to sqlite3OsSleep() have a delay of 1 microsecond.  Really this
	 ** is more of a scheduler yield than an actual delay.  But on the 10th
	 ** an subsequent retries, the delays start becoming longer and longer,
	 ** so that on the 100th (and last) RETRY we delay for 323 milliseconds.
	 ** The total delay time before giving up is less than 10 seconds.
	 */
	*(*int32)(unsafe.Pointer(pCnt))++
	if *(*int32)(unsafe.Pointer(pCnt)) > int32(5) {
		nDelay = int32(1) /* Pause time in microseconds */
		cnt = *(*int32)(unsafe.Pointer(pCnt)) & ^libc.Int32FromInt32(WAL_RETRY_BLOCKED_MASK)
		if cnt > int32(WAL_RETRY_PROTOCOL_LIMIT) {
			return int32(SQLITE_PROTOCOL)
		}
		if *(*int32)(unsafe.Pointer(pCnt)) >= int32(10) {
			nDelay = (cnt - int32(9)) * (cnt - int32(9)) * int32(39)
		}
		_sqlite3OsSleep(tls, (*TWal)(unsafe.Pointer(pWal)).FpVfs, nDelay)
		*(*int32)(unsafe.Pointer(pCnt)) &= ^libc.Int32FromInt32(WAL_RETRY_BLOCKED_MASK)
	}
	if !(useWal != 0) {
		if int32((*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable) == 0 {
			rc = _walIndexReadHdr(tls, pWal, pChanged)
		}
		if rc == int32(SQLITE_BUSY) {
			/* If there is not a recovery running in another thread or process
			 ** then convert BUSY errors to WAL_RETRY.  If recovery is known to
			 ** be running, convert BUSY to BUSY_RECOVERY.  There is a race here
			 ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
			 ** would be technically correct.  But the race is benign since with
			 ** WAL_RETRY this routine will be called again and will probably be
			 ** right on the second iteration.
			 */
			if *(*uintptr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FapWiData)) == uintptr(0) {
				/* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
				 ** We assume this is a transient condition, so return WAL_RETRY. The
				 ** xShmMap() implementation used by the default unix and win32 VFS
				 ** modules may return SQLITE_BUSY due to a race condition in the
				 ** code that determines whether or not the shared-memory region
				 ** must be zeroed before the requested page is returned.
				 */
				rc = -int32(1)
			} else {
				v1 = _walLockShared(tls, pWal, int32(WAL_RECOVER_LOCK))
				rc = v1
				if SQLITE_OK == v1 {
					_walUnlockShared(tls, pWal, int32(WAL_RECOVER_LOCK))
					rc = -int32(1)
				} else {
					if rc == int32(SQLITE_BUSY) {
						rc = libc.Int32FromInt32(SQLITE_BUSY) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					}
				}
			}
		}
		if rc != SQLITE_OK {
			return rc
		} else {
			if (*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable != 0 {
				return _walBeginShmUnreliable(tls, pWal, pChanged)
			}
		}
	}
	pInfo = _walCkptInfo(tls, pWal)
	if !(useWal != 0) && libc.AtomicLoadNUint32(pInfo, libc.Int32FromInt32(__ATOMIC_RELAXED)) == (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame && ((*TWal)(unsafe.Pointer(pWal)).FpSnapshot == uintptr(0) || (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame == uint32(0)) {
		/* The WAL has been completely backfilled (or it is empty).
		 ** and can be safely ignored.
		 */
		rc = _walLockShared(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(0))
		_walShmBarrier(tls, pWal)
		if rc == SQLITE_OK {
			if libc.Xmemcmp(tls, _walIndexHdr(tls, pWal), pWal+52, uint32(48)) != 0 {
				/* It is not safe to allow the reader to continue here if frames
				 ** may have been appended to the log before READ_LOCK(0) was obtained.
				 ** When holding READ_LOCK(0), the reader ignores the entire log file,
				 ** which implies that the database file contains a trustworthy
				 ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
				 ** happening, this is usually correct.
				 **
				 ** However, if frames have been appended to the log (or if the log
				 ** is wrapped and written for that matter) before the READ_LOCK(0)
				 ** is obtained, that is not necessarily true. A checkpointer may
				 ** have started to backfill the appended frames but crashed before
				 ** it finished. Leaving a corrupt image in the database file.
				 */
				_walUnlockShared(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(0))
				return -int32(1)
			}
			(*TWal)(unsafe.Pointer(pWal)).FreadLock = 0
			return SQLITE_OK
		} else {
			if rc != int32(SQLITE_BUSY) {
				return rc
			}
		}
	}
	/* If we get this far, it means that the reader will want to use
	 ** the WAL to get at content from recent commits.  The job now is
	 ** to select one of the aReadMark[] entries that is closest to
	 ** but not exceeding pWal->hdr.mxFrame and lock that entry.
	 */
	mxReadMark = uint32(0)
	mxI = 0
	mxFrame = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	if (*TWal)(unsafe.Pointer(pWal)).FpSnapshot != 0 && (*TWalIndexHdr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FpSnapshot)).FmxFrame < mxFrame {
		mxFrame = (*TWalIndexHdr)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FpSnapshot)).FmxFrame
	}
	i = int32(1)
	for {
		if !(i < libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)) {
			break
		}
		thisMark = libc.AtomicLoadNUint32(pInfo+4+uintptr(i)*4, libc.Int32FromInt32(__ATOMIC_RELAXED))
		if mxReadMark <= thisMark && thisMark <= mxFrame {
			mxReadMark = thisMark
			mxI = i
		}
		goto _2
	_2:
		;
		i++
	}
	if int32((*TWal)(unsafe.Pointer(pWal)).FreadOnly)&int32(WAL_SHM_RDONLY) == 0 && (mxReadMark < mxFrame || mxI == 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 {
				libc.AtomicStoreNUint32(pInfo+4+uintptr(i)*4, mxFrame, libc.Int32FromInt32(__ATOMIC_RELAXED))
				mxReadMark = mxFrame
				mxI = i
				_walUnlockExclusive(tls, pWal, int32(3)+i, int32(1))
				break
			} else {
				if rc != int32(SQLITE_BUSY) {
					return rc
				}
			}
			goto _3
		_3:
			;
			i++
		}
	}
	if mxI == 0 {
		if rc == int32(SQLITE_BUSY) {
			v4 = -int32(1)
		} else {
			v4 = libc.Int32FromInt32(SQLITE_READONLY) | libc.Int32FromInt32(5)<<libc.Int32FromInt32(8)
		}
		return v4
	}
	rc = _walLockShared(tls, pWal, int32(3)+mxI)
	if rc != 0 {
		if rc&int32(0xFF) == int32(SQLITE_BUSY) {
			v5 = -int32(1)
		} else {
			v5 = rc
		}
		return v5
	}
	/* Now that the read-lock has been obtained, check that neither the
	 ** value in the aReadMark[] array or the contents of the wal-index
	 ** header have changed.
	 **
	 ** It is necessary to check that the wal-index header did not change
	 ** between the time it was read and when the shared-lock was obtained
	 ** on WAL_READ_LOCK(mxI) was obtained to account for the possibility
	 ** that the log file may have been wrapped by a writer, or that frames
	 ** that occur later in the log than pWal->hdr.mxFrame may have been
	 ** copied into the database by a checkpointer. If either of these things
	 ** happened, then reading the database with the current value of
	 ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
	 ** instead.
	 **
	 ** Before checking that the live wal-index header has not changed
	 ** since it was read, set Wal.minFrame to the first frame in the wal
	 ** file that has not yet been checkpointed. This client will not need
	 ** to read any frames earlier than minFrame from the wal file - they
	 ** can be safely read directly from the database file.
	 **
	 ** Because a ShmBarrier() call is made between taking the copy of
	 ** nBackfill and checking that the wal-header in shared-memory still
	 ** matches the one cached in pWal->hdr, it is guaranteed that the
	 ** checkpointer that set nBackfill was not working with a wal-index
	 ** header newer than that cached in pWal->hdr. If it were, that could
	 ** cause a problem. The checkpointer could omit to checkpoint
	 ** a version of page X that lies before pWal->minFrame (call that version
	 ** A) on the basis that there is a newer version (version B) of the same
	 ** page later in the wal file. But if version B happens to like past
	 ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
	 ** that it can read version A from the database file. However, since
	 ** we can guarantee that the checkpointer that set nBackfill could not
	 ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
	 */
	(*TWal)(unsafe.Pointer(pWal)).FminFrame = uint32(int32(libc.AtomicLoadNUint32(pInfo, libc.Int32FromInt32(__ATOMIC_RELAXED))) + int32(1))
	_walShmBarrier(tls, pWal)
	if libc.AtomicLoadNUint32(pInfo+4+uintptr(mxI)*4, libc.Int32FromInt32(__ATOMIC_RELAXED)) != mxReadMark || libc.Xmemcmp(tls, _walIndexHdr(tls, pWal), pWal+52, uint32(48)) != 0 {
		_walUnlockShared(tls, pWal, int32(3)+mxI)
		return -int32(1)
	} else {
		(*TWal)(unsafe.Pointer(pWal)).FreadLock = int16(int16(mxI))
	}
	return rc
}

// C documentation
//
//	/*
//	** This function does the work of sqlite3WalSnapshotRecover().
//	*/
func _walSnapshotRecover(tls *libc.TLS, pWal uintptr, pBuf1 uintptr, pBuf2 uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, pgno Tu32
	var iDbOff, iWalOff Ti64
	var pInfo uintptr
	var rc, szPage int32
	var _ /* sLoc at bp+8 */ TWalHashLoc
	var _ /* szDb at bp+0 */ Ti64
	_, _, _, _, _, _, _ = i, iDbOff, iWalOff, pInfo, pgno, rc, szPage
	szPage = int32((*TWal)(unsafe.Pointer(pWal)).FszPage) /* Size of db file in bytes */
	rc = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, bp)
	if rc == SQLITE_OK {
		pInfo = _walCkptInfo(tls, pWal)
		i = (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted
		i = (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted
		for {
			if !(i > libc.AtomicLoadNUint32(pInfo, libc.Int32FromInt32(__ATOMIC_RELAXED))) {
				break
			} /* Offset of wal file entry */
			rc = _walHashGet(tls, pWal, _walFramePage(tls, i), bp+8)
			if rc != SQLITE_OK {
				break
			}
			pgno = *(*Tu32)(unsafe.Pointer((*(*TWalHashLoc)(unsafe.Pointer(bp + 8))).FaPgno + uintptr(i-(*(*TWalHashLoc)(unsafe.Pointer(bp + 8))).FiZero-uint32(1))*4))
			iDbOff = int64(pgno-libc.Uint32FromInt32(1)) * int64(int64(szPage))
			if iDbOff+int64(int64(szPage)) <= *(*Ti64)(unsafe.Pointer(bp)) {
				iWalOff = int64(WAL_HDRSIZE) + int64(i-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) + int64(WAL_FRAME_HDRSIZE)
				rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, pBuf1, szPage, iWalOff)
				if rc == SQLITE_OK {
					rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, pBuf2, szPage, iDbOff)
				}
				if rc != SQLITE_OK || 0 == libc.Xmemcmp(tls, pBuf1, pBuf2, uint32(uint32(szPage))) {
					break
				}
			}
			(*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = i - uint32(1)
			goto _1
		_1:
			;
			i--
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Attempt to reduce the value of the WalCkptInfo.nBackfillAttempted
//	** variable so that older snapshots can be accessed. To do this, loop
//	** through all wal frames from nBackfillAttempted to (nBackfill+1),
//	** comparing their content to the corresponding page with the database
//	** file, if any. Set nBackfillAttempted to the frame number of the
//	** first frame for which the wal file content matches the db file.
//	**
//	** This is only really safe if the file-system is such that any page
//	** writes made by earlier checkpointers were atomic operations, which
//	** is not always true. It is also possible that nBackfillAttempted
//	** may be left set to a value larger than expected, if a wal frame
//	** contains content that duplicate of an earlier version of the same
//	** page.
//	**
//	** SQLITE_OK is returned if successful, or an SQLite error code if an
//	** error occurs. It is not an error if nBackfillAttempted cannot be
//	** decreased at all.
//	*/
func _sqlite3WalSnapshotRecover(tls *libc.TLS, pWal uintptr) (r int32) {
	var pBuf1, pBuf2 uintptr
	var rc int32
	_, _, _ = pBuf1, pBuf2, rc
	rc = _walLockExclusive(tls, pWal, int32(WAL_CKPT_LOCK), int32(1))
	if rc == SQLITE_OK {
		pBuf1 = Xsqlite3_malloc(tls, int32((*TWal)(unsafe.Pointer(pWal)).FszPage))
		pBuf2 = Xsqlite3_malloc(tls, int32((*TWal)(unsafe.Pointer(pWal)).FszPage))
		if pBuf1 == uintptr(0) || pBuf2 == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			(*TWal)(unsafe.Pointer(pWal)).FckptLock = uint8(1)
			rc = _walSnapshotRecover(tls, pWal, pBuf1, pBuf2)
			(*TWal)(unsafe.Pointer(pWal)).FckptLock = uint8(0)
		}
		Xsqlite3_free(tls, pBuf1)
		Xsqlite3_free(tls, pBuf2)
		_walUnlockExclusive(tls, pWal, int32(WAL_CKPT_LOCK), int32(1))
	}
	return rc
}

// C documentation
//
//	/*
//	** This function does the work of sqlite3WalBeginReadTransaction() (see
//	** below). That function simply calls this one inside an SEH_TRY{...} block.
//	*/
func _walBeginReadTransaction(tls *libc.TLS, pWal uintptr, pChanged uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bChanged, ckptLock, rc int32
	var pInfo, pSnapshot uintptr
	var _ /* cnt at bp+0 */ int32
	_, _, _, _, _ = bChanged, ckptLock, pInfo, pSnapshot, rc /* Return code */
	*(*int32)(unsafe.Pointer(bp)) = 0                        /* Number of TryBeginRead attempts */
	ckptLock = 0
	bChanged = 0
	pSnapshot = (*TWal)(unsafe.Pointer(pWal)).FpSnapshot
	if pSnapshot != 0 {
		if libc.Xmemcmp(tls, pSnapshot, pWal+52, uint32(48)) != 0 {
			bChanged = int32(1)
		}
		/* It is possible that there is a checkpointer thread running
		 ** concurrent with this code. If this is the case, it may be that the
		 ** checkpointer has already determined that it will checkpoint
		 ** snapshot X, where X is later in the wal file than pSnapshot, but
		 ** has not yet set the pInfo->nBackfillAttempted variable to indicate
		 ** its intent. To avoid the race condition this leads to, ensure that
		 ** there is no checkpointer process by taking a shared CKPT lock
		 ** before checking pInfo->nBackfillAttempted.  */
		rc = _walLockShared(tls, pWal, int32(WAL_CKPT_LOCK))
		if rc != SQLITE_OK {
			return rc
		}
		ckptLock = int32(1)
	}
	for cond := true; cond; cond = rc == -int32(1) {
		rc = _walTryBeginRead(tls, pWal, pChanged, 0, bp)
	}
	if rc == SQLITE_OK {
		if pSnapshot != 0 && libc.Xmemcmp(tls, pSnapshot, pWal+52, uint32(48)) != 0 {
			/* At this point the client has a lock on an aReadMark[] slot holding
			 ** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr
			 ** is populated with the wal-index header corresponding to the head
			 ** of the wal file. Verify that pSnapshot is still valid before
			 ** continuing.  Reasons why pSnapshot might no longer be valid:
			 **
			 **    (1)  The WAL file has been reset since the snapshot was taken.
			 **         In this case, the salt will have changed.
			 **
			 **    (2)  A checkpoint as been attempted that wrote frames past
			 **         pSnapshot->mxFrame into the database file.  Note that the
			 **         checkpoint need not have completed for this to cause problems.
			 */
			pInfo = _walCkptInfo(tls, pWal)
			/* Check that the wal file has not been wrapped. Assuming that it has
			 ** not, also check that no checkpointer has attempted to checkpoint any
			 ** frames beyond pSnapshot->mxFrame. If either of these conditions are
			 ** true, return SQLITE_ERROR_SNAPSHOT. Otherwise, overwrite pWal->hdr
			 ** with *pSnapshot and set *pChanged as appropriate for opening the
			 ** snapshot.  */
			if !(libc.Xmemcmp(tls, pSnapshot+32, pWal+52+32, uint32(8)) != 0) && (*TWalIndexHdr)(unsafe.Pointer(pSnapshot)).FmxFrame >= (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted {
				libc.Xmemcpy(tls, pWal+52, pSnapshot, uint32(48))
				*(*int32)(unsafe.Pointer(pChanged)) = bChanged
			} else {
				rc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
			}
			/* A client using a non-current snapshot may not ignore any frames
			 ** from the start of the wal file. This is because, for a system
			 ** where (minFrame < iSnapshot < maxFrame), a checkpointer may
			 ** have omitted to checkpoint a frame earlier than minFrame in
			 ** the file because there exists a frame after iSnapshot that
			 ** is the same database page.  */
			(*TWal)(unsafe.Pointer(pWal)).FminFrame = uint32(1)
			if rc != SQLITE_OK {
				_sqlite3WalEndReadTransaction(tls, pWal)
			}
		}
	}
	/* Release the shared CKPT lock obtained above. */
	if ckptLock != 0 {
		_walUnlockShared(tls, pWal, int32(WAL_CKPT_LOCK))
	}
	return rc
}

// C documentation
//
//	/*
//	** Begin a read transaction on the database.
//	**
//	** This routine used to be called sqlite3OpenSnapshot() and with good reason:
//	** it takes a snapshot of the state of the WAL and wal-index for the current
//	** instant in time.  The current thread will continue to use this snapshot.
//	** Other threads might append new content to the WAL and wal-index but
//	** that extra content is ignored by the current thread.
//	**
//	** If the database contents have changes since the previous read
//	** transaction, then *pChanged is set to 1 before returning.  The
//	** Pager layer will use this to know that its cache is stale and
//	** needs to be flushed.
//	*/
func _sqlite3WalBeginReadTransaction(tls *libc.TLS, pWal uintptr, pChanged uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _walBeginReadTransaction(tls, pWal, pChanged)
	return rc
}

// C documentation
//
//	/*
//	** Finish with a read transaction.  All this does is release the
//	** read-lock.
//	*/
func _sqlite3WalEndReadTransaction(tls *libc.TLS, pWal uintptr) {
	_sqlite3WalEndWriteTransaction(tls, pWal)
	if int32((*TWal)(unsafe.Pointer(pWal)).FreadLock) >= 0 {
		_walUnlockShared(tls, pWal, int32(3)+int32((*TWal)(unsafe.Pointer(pWal)).FreadLock))
		(*TWal)(unsafe.Pointer(pWal)).FreadLock = int16(-int32(1))
	}
}

// C documentation
//
//	/*
//	** Search the wal file for page pgno. If found, set *piRead to the frame that
//	** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
//	** to zero.
//	**
//	** Return SQLITE_OK if successful, or an error code if an error occurs. If an
//	** error does occur, the final value of *piRead is undefined.
//	*/
func _walFindFrame(tls *libc.TLS, pWal uintptr, pgno TPgno, piRead uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iFrame, iH, iLast, iRead, v2 Tu32
	var iHash, iKey, iMinHash, nCollide, rc, v3 int32
	var _ /* sLoc at bp+0 */ TWalHashLoc
	_, _, _, _, _, _, _, _, _, _, _ = iFrame, iH, iHash, iKey, iLast, iMinHash, iRead, nCollide, rc, v2, v3
	iRead = uint32(0) /* If !=0, WAL frame to return data from */
	iLast = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	/* This routine is only be called from within a read transaction. */
	/* If the "last page" field of the wal-index header snapshot is 0, then
	 ** no data will be read from the wal under any circumstances. Return early
	 ** in this case as an optimization.  Likewise, if pWal->readLock==0,
	 ** then the WAL is ignored by the reader so return early, as if the
	 ** WAL were empty.
	 */
	if iLast == uint32(0) || int32((*TWal)(unsafe.Pointer(pWal)).FreadLock) == 0 && int32((*TWal)(unsafe.Pointer(pWal)).FbShmUnreliable) == 0 {
		*(*Tu32)(unsafe.Pointer(piRead)) = uint32(0)
		return SQLITE_OK
	}
	/* Search the hash table or tables for an entry matching page number
	 ** pgno. Each iteration of the following for() loop searches one
	 ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames).
	 **
	 ** This code might run concurrently to the code in walIndexAppend()
	 ** that adds entries to the wal-index (and possibly to this hash
	 ** table). This means the value just read from the hash
	 ** slot (aHash[iKey]) may have been added before or after the
	 ** current read transaction was opened. Values added after the
	 ** read transaction was opened may have been written incorrectly -
	 ** i.e. these slots may contain garbage data. However, we assume
	 ** that any slots written before the current read transaction was
	 ** opened remain unmodified.
	 **
	 ** For the reasons above, the if(...) condition featured in the inner
	 ** loop of the following block is more stringent that would be required
	 ** if we had exclusive access to the hash-table:
	 **
	 **   (aPgno[iFrame]==pgno):
	 **     This condition filters out normal hash-table collisions.
	 **
	 **   (iFrame<=iLast):
	 **     This condition filters out entries that were added to the hash
	 **     table after the current read-transaction had started.
	 */
	iMinHash = _walFramePage(tls, (*TWal)(unsafe.Pointer(pWal)).FminFrame)
	iHash = _walFramePage(tls, iLast)
	for {
		if !(iHash >= iMinHash) {
			break
		}
		rc = _walHashGet(tls, pWal, iHash, bp)
		if rc != SQLITE_OK {
			return rc
		}
		nCollide = libc.Int32FromInt32(HASHTABLE_NPAGE) * libc.Int32FromInt32(2)
		iKey = _walHash(tls, pgno)
		for {
			v2 = uint32(libc.AtomicLoadNUint16((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaHash+uintptr(iKey)*2, libc.Int32FromInt32(__ATOMIC_RELAXED)))
			iH = v2
			if !(v2 != uint32(0)) {
				break
			}
			iFrame = iH + (*(*TWalHashLoc)(unsafe.Pointer(bp))).FiZero
			if iFrame <= iLast && iFrame >= (*TWal)(unsafe.Pointer(pWal)).FminFrame && *(*Tu32)(unsafe.Pointer((*(*TWalHashLoc)(unsafe.Pointer(bp))).FaPgno + uintptr(iH-uint32(1))*4)) == pgno {
				iRead = iFrame
			}
			v3 = nCollide
			nCollide--
			if v3 == 0 {
				*(*Tu32)(unsafe.Pointer(piRead)) = uint32(0)
				return _sqlite3CorruptError(tls, int32(68469))
			}
			iKey = _walNextHash(tls, iKey)
		}
		if iRead != 0 {
			break
		}
		goto _1
	_1:
		;
		iHash--
	}
	*(*Tu32)(unsafe.Pointer(piRead)) = iRead
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Search the wal file for page pgno. If found, set *piRead to the frame that
//	** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
//	** to zero.
//	**
//	** Return SQLITE_OK if successful, or an error code if an error occurs. If an
//	** error does occur, the final value of *piRead is undefined.
//	**
//	** The difference between this function and walFindFrame() is that this
//	** function wraps walFindFrame() in an SEH_TRY{...} block.
//	*/
func _sqlite3WalFindFrame(tls *libc.TLS, pWal uintptr, pgno TPgno, piRead uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _walFindFrame(tls, pWal, pgno, piRead)
	return rc
}

// C documentation
//
//	/*
//	** Read the contents of frame iRead from the wal file into buffer pOut
//	** (which is nOut bytes in size). Return SQLITE_OK if successful, or an
//	** error code otherwise.
//	*/
func _sqlite3WalReadFrame(tls *libc.TLS, pWal uintptr, iRead Tu32, nOut int32, pOut uintptr) (r int32) {
	var iOffset Ti64
	var sz, v1 int32
	_, _, _ = iOffset, sz, v1
	sz = int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage)
	sz = sz&int32(0xfe00) + sz&int32(0x0001)<<int32(16)
	iOffset = int64(WAL_HDRSIZE) + int64(iRead-libc.Uint32FromInt32(1))*int64(sz+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) + int64(WAL_FRAME_HDRSIZE)
	/* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
	if nOut > sz {
		v1 = sz
	} else {
		v1 = nOut
	}
	return _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, pOut, v1, iOffset)
}

// C documentation
//
//	/*
//	** Return the size of the database in pages (or zero, if unknown).
//	*/
func _sqlite3WalDbsize(tls *libc.TLS, pWal uintptr) (r TPgno) {
	if pWal != 0 && int32((*TWal)(unsafe.Pointer(pWal)).FreadLock) >= 0 {
		return (*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage
	}
	return uint32(0)
}

// C documentation
//
//	/*
//	** This function starts a write transaction on the WAL.
//	**
//	** A read transaction must have already been started by a prior call
//	** to sqlite3WalBeginReadTransaction().
//	**
//	** If another thread or process has written into the database since
//	** the read transaction was started, then it is not possible for this
//	** thread to write as doing so would cause a fork.  So this routine
//	** returns SQLITE_BUSY in that case and no write transaction is started.
//	**
//	** There can only be a single writer active at a time.
//	*/
func _sqlite3WalBeginWriteTransaction(tls *libc.TLS, pWal uintptr) (r int32) {
	var rc int32
	_ = rc
	/* Cannot start a write transaction without first holding a read
	 ** transaction. */
	if (*TWal)(unsafe.Pointer(pWal)).FreadOnly != 0 {
		return int32(SQLITE_READONLY)
	}
	/* Only one writer allowed at a time.  Get the write lock.  Return
	 ** SQLITE_BUSY if unable.
	 */
	rc = _walLockExclusive(tls, pWal, WAL_WRITE_LOCK, int32(1))
	if rc != 0 {
		return rc
	}
	(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(1)
	/* If another connection has written to the database file since the
	 ** time the read transaction on this connection was started, then
	 ** the write is disallowed.
	 */
	if libc.Xmemcmp(tls, pWal+52, _walIndexHdr(tls, pWal), uint32(48)) != 0 {
		rc = libc.Int32FromInt32(SQLITE_BUSY) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	if rc != SQLITE_OK {
		_walUnlockExclusive(tls, pWal, WAL_WRITE_LOCK, int32(1))
		(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** End a write transaction.  The commit has already been done.  This
//	** routine merely releases the lock.
//	*/
func _sqlite3WalEndWriteTransaction(tls *libc.TLS, pWal uintptr) (r int32) {
	if (*TWal)(unsafe.Pointer(pWal)).FwriteLock != 0 {
		_walUnlockExclusive(tls, pWal, WAL_WRITE_LOCK, int32(1))
		(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(0)
		(*TWal)(unsafe.Pointer(pWal)).FiReCksum = uint32(0)
		(*TWal)(unsafe.Pointer(pWal)).FtruncateOnCommit = uint8(0)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If any data has been written (but not committed) to the log file, this
//	** function moves the write-pointer back to the start of the transaction.
//	**
//	** Additionally, the callback function is invoked for each frame written
//	** to the WAL since the start of the transaction. If the callback returns
//	** other than SQLITE_OK, it is not invoked again and the error code is
//	** returned to the caller.
//	**
//	** Otherwise, if the callback function does not return an error, this
//	** function returns SQLITE_OK.
//	*/
func _sqlite3WalUndo(tls *libc.TLS, pWal uintptr, xUndo uintptr, pUndoCtx uintptr) (r int32) {
	var iFrame, iMax TPgno
	var rc int32
	_, _, _ = iFrame, iMax, rc
	rc = SQLITE_OK
	if (*TWal)(unsafe.Pointer(pWal)).FwriteLock != 0 {
		iMax = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
		/* Restore the clients cache of the wal-index header to the state it
		 ** was in before the client began writing to the database.
		 */
		libc.Xmemcpy(tls, pWal+52, _walIndexHdr(tls, pWal), uint32(48))
		iFrame = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame + uint32(1)
		for {
			if !(rc == SQLITE_OK && iFrame <= iMax) {
				break
			}
			/* This call cannot fail. Unless the page for which the page number
			 ** is passed as the second argument is (a) in the cache and
			 ** (b) has an outstanding reference, then xUndo is either a no-op
			 ** (if (a) is false) or simply expels the page from the cache (if (b)
			 ** is false).
			 **
			 ** If the upper layer is doing a rollback, it is guaranteed that there
			 ** are no outstanding references to any page other than page 1. And
			 ** page 1 is never written to the log until the transaction is
			 ** committed. As a result, the call to xUndo may not fail.
			 */
			rc = (*(*func(*libc.TLS, uintptr, TPgno) int32)(unsafe.Pointer(&struct{ uintptr }{xUndo})))(tls, pUndoCtx, _walFramePgno(tls, pWal, iFrame))
			goto _1
		_1:
			;
			iFrame++
		}
		if iMax != (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
			_walCleanupHash(tls, pWal)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32
//	** values. This function populates the array with values required to
//	** "rollback" the write position of the WAL handle back to the current
//	** point in the event of a savepoint rollback (via WalSavepointUndo()).
//	*/
func _sqlite3WalSavepoint(tls *libc.TLS, pWal uintptr, aWalData uintptr) {
	*(*Tu32)(unsafe.Pointer(aWalData)) = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	*(*Tu32)(unsafe.Pointer(aWalData + 1*4)) = *(*Tu32)(unsafe.Pointer(pWal + 52 + 24))
	*(*Tu32)(unsafe.Pointer(aWalData + 2*4)) = *(*Tu32)(unsafe.Pointer(pWal + 52 + 24 + 1*4))
	*(*Tu32)(unsafe.Pointer(aWalData + 3*4)) = (*TWal)(unsafe.Pointer(pWal)).FnCkpt
}

// C documentation
//
//	/*
//	** Move the write position of the WAL back to the point identified by
//	** the values in the aWalData[] array. aWalData must point to an array
//	** of WAL_SAVEPOINT_NDATA u32 values that has been previously populated
//	** by a call to WalSavepoint().
//	*/
func _sqlite3WalSavepointUndo(tls *libc.TLS, pWal uintptr, aWalData uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if *(*Tu32)(unsafe.Pointer(aWalData + 3*4)) != (*TWal)(unsafe.Pointer(pWal)).FnCkpt {
		/* This savepoint was opened immediately after the write-transaction
		 ** was started. Right after that, the writer decided to wrap around
		 ** to the start of the log. Update the savepoint values to match.
		 */
		*(*Tu32)(unsafe.Pointer(aWalData)) = uint32(0)
		*(*Tu32)(unsafe.Pointer(aWalData + 3*4)) = (*TWal)(unsafe.Pointer(pWal)).FnCkpt
	}
	if *(*Tu32)(unsafe.Pointer(aWalData)) < (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
		(*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = *(*Tu32)(unsafe.Pointer(aWalData))
		*(*Tu32)(unsafe.Pointer(pWal + 52 + 24)) = *(*Tu32)(unsafe.Pointer(aWalData + 1*4))
		*(*Tu32)(unsafe.Pointer(pWal + 52 + 24 + 1*4)) = *(*Tu32)(unsafe.Pointer(aWalData + 2*4))
		_walCleanupHash(tls, pWal)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called just before writing a set of frames to the log
//	** file (see sqlite3WalFrames()). It checks to see if, instead of appending
//	** to the current log file, it is possible to overwrite the start of the
//	** existing log file with the new frames (i.e. "reset" the log). If so,
//	** it sets pWal->hdr.mxFrame to 0. Otherwise, pWal->hdr.mxFrame is left
//	** unchanged.
//	**
//	** SQLITE_OK is returned if no error is encountered (regardless of whether
//	** or not pWal->hdr.mxFrame is modified). An SQLite error code is returned
//	** if an error occurs.
//	*/
func _walRestartLog(tls *libc.TLS, pWal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pInfo uintptr
	var rc int32
	var _ /* cnt at bp+0 */ int32
	var _ /* notUsed at bp+8 */ int32
	var _ /* salt1 at bp+4 */ Tu32
	_, _ = pInfo, rc
	rc = SQLITE_OK
	if int32((*TWal)(unsafe.Pointer(pWal)).FreadLock) == 0 {
		pInfo = _walCkptInfo(tls, pWal)
		if (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill > uint32(0) {
			Xsqlite3_randomness(tls, int32(4), bp+4)
			rc = _walLockExclusive(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(1), libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
			if rc == SQLITE_OK {
				/* If all readers are using WAL_READ_LOCK(0) (in other words if no
				 ** readers are currently using the WAL), then the transactions
				 ** frames will overwrite the start of the existing log. Update the
				 ** wal-index header to reflect this.
				 **
				 ** In theory it would be Ok to update the cache of the header only
				 ** at this point. But updating the actual wal-index header is also
				 ** safe and means there is no special case for sqlite3WalUndo()
				 ** to handle if this transaction is rolled back.  */
				_walRestartHdr(tls, pWal, *(*Tu32)(unsafe.Pointer(bp + 4)))
				_walUnlockExclusive(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(1), libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
			} else {
				if rc != int32(SQLITE_BUSY) {
					return rc
				}
			}
		}
		_walUnlockShared(tls, pWal, libc.Int32FromInt32(3)+libc.Int32FromInt32(0))
		(*TWal)(unsafe.Pointer(pWal)).FreadLock = int16(-int32(1))
		*(*int32)(unsafe.Pointer(bp)) = 0
		for cond := true; cond; cond = rc == -int32(1) {
			rc = _walTryBeginRead(tls, pWal, bp+8, int32(1), bp)
		}
		/* BUSY not possible when useWal==1 */
	}
	return rc
}

// C documentation
//
//	/*
//	** Information about the current state of the WAL file and where
//	** the next fsync should occur - passed from sqlite3WalFrames() into
//	** walWriteToLog().
//	*/
type TWalWriter = struct {
	F__ccgo_align [0]uint32
	FpWal         uintptr
	FpFd          uintptr
	FiSyncPoint   Tsqlite3_int64
	FsyncFlags    int32
	FszPage       int32
}

type WalWriter = TWalWriter

// C documentation
//
//	/*
//	** Write iAmt bytes of content into the WAL file beginning at iOffset.
//	** Do a sync when crossing the p->iSyncPoint boundary.
//	**
//	** In other words, if iSyncPoint is in between iOffset and iOffset+iAmt,
//	** first write the part before iSyncPoint, then sync, then write the
//	** rest.
//	*/
func _walWriteToLog(tls *libc.TLS, p uintptr, pContent uintptr, iAmt int32, iOffset Tsqlite3_int64) (r int32) {
	var iFirstAmt, rc int32
	_, _ = iFirstAmt, rc
	if iOffset < (*TWalWriter)(unsafe.Pointer(p)).FiSyncPoint && iOffset+int64(int64(iAmt)) >= (*TWalWriter)(unsafe.Pointer(p)).FiSyncPoint {
		iFirstAmt = int32((*TWalWriter)(unsafe.Pointer(p)).FiSyncPoint - iOffset)
		rc = _sqlite3OsWrite(tls, (*TWalWriter)(unsafe.Pointer(p)).FpFd, pContent, iFirstAmt, iOffset)
		if rc != 0 {
			return rc
		}
		iOffset += int64(int64(iFirstAmt))
		iAmt -= iFirstAmt
		pContent = uintptr(iFirstAmt) + pContent
		rc = _sqlite3OsSync(tls, (*TWalWriter)(unsafe.Pointer(p)).FpFd, (*TWalWriter)(unsafe.Pointer(p)).FsyncFlags&int32(0x03))
		if iAmt == 0 || rc != 0 {
			return rc
		}
	}
	rc = _sqlite3OsWrite(tls, (*TWalWriter)(unsafe.Pointer(p)).FpFd, pContent, iAmt, iOffset)
	return rc
}

// C documentation
//
//	/*
//	** Write out a single frame of the WAL
//	*/
func _walWriteOneFrame(tls *libc.TLS, p uintptr, pPage uintptr, nTruncate int32, iOffset Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pData uintptr
	var rc int32
	var _ /* aFrame at bp+0 */ [24]Tu8
	_, _ = pData, rc /* Buffer to assemble frame-header in */
	pData = (*TPgHdr)(unsafe.Pointer(pPage)).FpData
	_walEncodeFrame(tls, (*TWalWriter)(unsafe.Pointer(p)).FpWal, (*TPgHdr)(unsafe.Pointer(pPage)).Fpgno, uint32(uint32(nTruncate)), pData, bp)
	rc = _walWriteToLog(tls, p, bp, int32(24), iOffset)
	if rc != 0 {
		return rc
	}
	/* Write the page data */
	rc = _walWriteToLog(tls, p, pData, (*TWalWriter)(unsafe.Pointer(p)).FszPage, iOffset+int64(24))
	return rc
}

// C documentation
//
//	/*
//	** This function is called as part of committing a transaction within which
//	** one or more frames have been overwritten. It updates the checksums for
//	** all frames written to the wal file by the current transaction starting
//	** with the earliest to have been overwritten.
//	**
//	** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
//	*/
func _walRewriteChecksums(tls *libc.TLS, pWal uintptr, iLast Tu32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aBuf uintptr
	var iCksumOff, iOff Ti64
	var iPgno, iRead, nDbSize Tu32
	var rc, szPage int32
	var _ /* aFrame at bp+0 */ [24]Tu8
	_, _, _, _, _, _, _, _ = aBuf, iCksumOff, iOff, iPgno, iRead, nDbSize, rc, szPage
	szPage = int32((*TWal)(unsafe.Pointer(pWal)).FszPage) /* Database page size */
	rc = SQLITE_OK
	aBuf = Xsqlite3_malloc(tls, szPage+int32(WAL_FRAME_HDRSIZE))
	if aBuf == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	/* Find the checksum values to use as input for the recalculating the
	 ** first checksum. If the first frame is frame 1 (implying that the current
	 ** transaction restarted the wal file), these values must be read from the
	 ** wal-file header. Otherwise, read them from the frame header of the
	 ** previous frame.  */
	if (*TWal)(unsafe.Pointer(pWal)).FiReCksum == uint32(1) {
		iCksumOff = int64(24)
	} else {
		iCksumOff = int64(WAL_HDRSIZE) + int64((*TWal)(unsafe.Pointer(pWal)).FiReCksum-libc.Uint32FromInt32(1)-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) + int64(16)
	}
	rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, aBuf, int32(libc.Uint32FromInt64(4)*libc.Uint32FromInt32(2)), iCksumOff)
	*(*Tu32)(unsafe.Pointer(pWal + 52 + 24)) = _sqlite3Get4byte(tls, aBuf)
	*(*Tu32)(unsafe.Pointer(pWal + 52 + 24 + 1*4)) = _sqlite3Get4byte(tls, aBuf+uintptr(4))
	iRead = (*TWal)(unsafe.Pointer(pWal)).FiReCksum
	(*TWal)(unsafe.Pointer(pWal)).FiReCksum = uint32(0)
	for {
		if !(rc == SQLITE_OK && iRead <= iLast) {
			break
		}
		iOff = libc.Int64FromInt32(WAL_HDRSIZE) + int64(iRead-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE))
		rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, aBuf, szPage+int32(WAL_FRAME_HDRSIZE), iOff)
		if rc == SQLITE_OK {
			iPgno = _sqlite3Get4byte(tls, aBuf)
			nDbSize = _sqlite3Get4byte(tls, aBuf+4)
			_walEncodeFrame(tls, pWal, iPgno, nDbSize, aBuf+24, bp)
			rc = _sqlite3OsWrite(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp, int32(24), iOff)
		}
		goto _1
	_1:
		;
		iRead++
	}
	Xsqlite3_free(tls, aBuf)
	return rc
}

// C documentation
//
//	/*
//	** Write a set of frames to the log. The caller must hold the write-lock
//	** on the log file (obtained using sqlite3WalBeginWriteTransaction()).
//	*/
func _walFrames(tls *libc.TLS, pWal uintptr, szPage int32, pList uintptr, nTruncate TPgno, isCommit int32, sync_flags int32) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var bSync, nDbSize, nExtra, rc, sectorSize, szFrame, v1 int32
	var iFirst, iFrame Tu32
	var iOff, iOffset, sz Ti64
	var p, pData, pLast, pLive, p3, p5 uintptr
	var v4 uint32
	var _ /* aCksum at bp+56 */ [2]Tu32
	var _ /* aWalHdr at bp+24 */ [32]Tu8
	var _ /* iWrite at bp+64 */ Tu32
	var _ /* w at bp+0 */ TWalWriter
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bSync, iFirst, iFrame, iOff, iOffset, nDbSize, nExtra, p, pData, pLast, pLive, rc, sectorSize, sz, szFrame, v1, v4, p3, p5 /* Iterator to run through pList with. */
	pLast = uintptr(0)                                                                                                                                                                   /* Last frame in list */
	nExtra = 0                                                                                                                                                                           /* The writer */
	iFirst = uint32(0)                                                                                                                                                                   /* Pointer to shared header */
	/* If this frame set completes a transaction, then nTruncate>0.  If
	 ** nTruncate==0 then this frame set does not complete the transaction. */
	pLive = _walIndexHdr(tls, pWal)
	if libc.Xmemcmp(tls, pWal+52, pLive, uint32(48)) != 0 {
		iFirst = (*TWalIndexHdr)(unsafe.Pointer(pLive)).FmxFrame + uint32(1)
	}
	/* See if it is possible to write these frames into the start of the
	 ** log file, instead of appending to it at pWal->hdr.mxFrame.
	 */
	v1 = _walRestartLog(tls, pWal)
	rc = v1
	if SQLITE_OK != v1 {
		return rc
	}
	/* If this is the first frame written into the log, write the WAL
	 ** header to the start of the WAL file. See comments at the top of
	 ** this source file for a description of the WAL header format.
	 */
	iFrame = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	if iFrame == uint32(0) { /* Checksum for wal-header */
		_sqlite3Put4byte(tls, bp+24, uint32(libc.Int32FromInt32(WAL_MAGIC)|libc.Int32FromInt32(SQLITE_BIGENDIAN)))
		_sqlite3Put4byte(tls, bp+24+4, uint32(WAL_MAX_VERSION))
		_sqlite3Put4byte(tls, bp+24+8, uint32(uint32(szPage)))
		_sqlite3Put4byte(tls, bp+24+12, (*TWal)(unsafe.Pointer(pWal)).FnCkpt)
		if (*TWal)(unsafe.Pointer(pWal)).FnCkpt == uint32(0) {
			Xsqlite3_randomness(tls, int32(8), pWal+52+32)
		}
		libc.Xmemcpy(tls, bp+24+16, pWal+52+32, uint32(8))
		_walChecksumBytes(tls, int32(1), bp+24, libc.Int32FromInt32(WAL_HDRSIZE)-libc.Int32FromInt32(2)*libc.Int32FromInt32(4), uintptr(0), bp+56)
		_sqlite3Put4byte(tls, bp+24+24, (*(*[2]Tu32)(unsafe.Pointer(bp + 56)))[0])
		_sqlite3Put4byte(tls, bp+24+28, (*(*[2]Tu32)(unsafe.Pointer(bp + 56)))[int32(1)])
		(*TWal)(unsafe.Pointer(pWal)).FszPage = uint32(uint32(szPage))
		(*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum = uint8(SQLITE_BIGENDIAN)
		*(*Tu32)(unsafe.Pointer(pWal + 52 + 24)) = (*(*[2]Tu32)(unsafe.Pointer(bp + 56)))[0]
		*(*Tu32)(unsafe.Pointer(pWal + 52 + 24 + 1*4)) = (*(*[2]Tu32)(unsafe.Pointer(bp + 56)))[int32(1)]
		(*TWal)(unsafe.Pointer(pWal)).FtruncateOnCommit = uint8(1)
		rc = _sqlite3OsWrite(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp+24, int32(32), 0)
		if rc != SQLITE_OK {
			return rc
		}
		/* Sync the header (unless SQLITE_IOCAP_SEQUENTIAL is true or unless
		 ** all syncing is turned off by PRAGMA synchronous=OFF).  Otherwise
		 ** an out-of-order write following a WAL restart could result in
		 ** database corruption.  See the ticket:
		 **
		 **     https://sqlite.org/src/info/ff5be73dee
		 */
		if (*TWal)(unsafe.Pointer(pWal)).FsyncHeader != 0 {
			rc = _sqlite3OsSync(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, sync_flags>>int32(2)&int32(0x03))
			if rc != 0 {
				return rc
			}
		}
	}
	if int32((*TWal)(unsafe.Pointer(pWal)).FszPage) != szPage {
		return _sqlite3CorruptError(tls, int32(68992)) /* TH3 test case: cov1/corrupt155.test */
	}
	/* Setup information needed to write frames into the WAL */
	(*(*TWalWriter)(unsafe.Pointer(bp))).FpWal = pWal
	(*(*TWalWriter)(unsafe.Pointer(bp))).FpFd = (*TWal)(unsafe.Pointer(pWal)).FpWalFd
	(*(*TWalWriter)(unsafe.Pointer(bp))).FiSyncPoint = 0
	(*(*TWalWriter)(unsafe.Pointer(bp))).FsyncFlags = sync_flags
	(*(*TWalWriter)(unsafe.Pointer(bp))).FszPage = szPage
	iOffset = libc.Int64FromInt32(WAL_HDRSIZE) + int64(iFrame+libc.Uint32FromInt32(1)-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE))
	szFrame = szPage + int32(WAL_FRAME_HDRSIZE)
	/* Write all frames into the log file exactly once */
	p = pList
	for {
		if !(p != 0) {
			break
		} /* 0 normally.  Positive == commit flag */
		/* Check if this page has already been written into the wal file by
		 ** the current transaction. If so, overwrite the existing frame and
		 ** set Wal.writeLock to WAL_WRITELOCK_RECKSUM - indicating that
		 ** checksums must be recomputed when the transaction is committed.  */
		if iFirst != 0 && ((*TPgHdr)(unsafe.Pointer(p)).FpDirty != 0 || isCommit == 0) {
			*(*Tu32)(unsafe.Pointer(bp + 64)) = uint32(0)
			_walFindFrame(tls, pWal, (*TPgHdr)(unsafe.Pointer(p)).Fpgno, bp+64)
			if *(*Tu32)(unsafe.Pointer(bp + 64)) >= iFirst {
				iOff = int64(WAL_HDRSIZE) + int64(*(*Tu32)(unsafe.Pointer(bp + 64))-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) + int64(WAL_FRAME_HDRSIZE)
				if (*TWal)(unsafe.Pointer(pWal)).FiReCksum == uint32(0) || *(*Tu32)(unsafe.Pointer(bp + 64)) < (*TWal)(unsafe.Pointer(pWal)).FiReCksum {
					(*TWal)(unsafe.Pointer(pWal)).FiReCksum = *(*Tu32)(unsafe.Pointer(bp + 64))
				}
				pData = (*TPgHdr)(unsafe.Pointer(p)).FpData
				rc = _sqlite3OsWrite(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, pData, szPage, iOff)
				if rc != 0 {
					return rc
				}
				p3 = p + 28
				*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(PGHDR_WAL_APPEND))
				goto _2
			}
		}
		iFrame++
		if isCommit != 0 && (*TPgHdr)(unsafe.Pointer(p)).FpDirty == uintptr(0) {
			v4 = nTruncate
		} else {
			v4 = uint32(0)
		}
		nDbSize = int32(v4)
		rc = _walWriteOneFrame(tls, bp, p, nDbSize, iOffset)
		if rc != 0 {
			return rc
		}
		pLast = p
		iOffset += int64(int64(szFrame))
		p5 = p + 28
		*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(PGHDR_WAL_APPEND))
		goto _2
	_2:
		;
		p = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
	}
	/* Recalculate checksums within the wal file if required. */
	if isCommit != 0 && (*TWal)(unsafe.Pointer(pWal)).FiReCksum != 0 {
		rc = _walRewriteChecksums(tls, pWal, iFrame)
		if rc != 0 {
			return rc
		}
	}
	/* If this is the end of a transaction, then we might need to pad
	 ** the transaction and/or sync the WAL file.
	 **
	 ** Padding and syncing only occur if this set of frames complete a
	 ** transaction and if PRAGMA synchronous=FULL.  If synchronous==NORMAL
	 ** or synchronous==OFF, then no padding or syncing are needed.
	 **
	 ** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not
	 ** needed and only the sync is done.  If padding is needed, then the
	 ** final frame is repeated (with its commit mark) until the next sector
	 ** boundary is crossed.  Only the part of the WAL prior to the last
	 ** sector boundary is synced; the part of the last frame that extends
	 ** past the sector boundary is written after the sync.
	 */
	if isCommit != 0 && sync_flags&int32(0x03) != 0 {
		bSync = int32(1)
		if (*TWal)(unsafe.Pointer(pWal)).FpadToSectorBoundary != 0 {
			sectorSize = _sqlite3SectorSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd)
			(*(*TWalWriter)(unsafe.Pointer(bp))).FiSyncPoint = (iOffset + int64(int64(sectorSize)) - int64(1)) / int64(int64(sectorSize)) * int64(int64(sectorSize))
			bSync = libc.BoolInt32((*(*TWalWriter)(unsafe.Pointer(bp))).FiSyncPoint == iOffset)
			for iOffset < (*(*TWalWriter)(unsafe.Pointer(bp))).FiSyncPoint {
				rc = _walWriteOneFrame(tls, bp, pLast, int32(int32(nTruncate)), iOffset)
				if rc != 0 {
					return rc
				}
				iOffset += int64(int64(szFrame))
				nExtra++
			}
		}
		if bSync != 0 {
			rc = _sqlite3OsSync(tls, (*(*TWalWriter)(unsafe.Pointer(bp))).FpFd, sync_flags&int32(0x03))
		}
	}
	/* If this frame set completes the first transaction in the WAL and
	 ** if PRAGMA journal_size_limit is set, then truncate the WAL to the
	 ** journal size limit, if possible.
	 */
	if isCommit != 0 && (*TWal)(unsafe.Pointer(pWal)).FtruncateOnCommit != 0 && (*TWal)(unsafe.Pointer(pWal)).FmxWalSize >= 0 {
		sz = (*TWal)(unsafe.Pointer(pWal)).FmxWalSize
		if int64(WAL_HDRSIZE)+int64(iFrame+uint32(uint32(nExtra))+libc.Uint32FromInt32(1)-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) > (*TWal)(unsafe.Pointer(pWal)).FmxWalSize {
			sz = libc.Int64FromInt32(WAL_HDRSIZE) + int64(iFrame+uint32(uint32(nExtra))+libc.Uint32FromInt32(1)-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE))
		}
		_walLimitSize(tls, pWal, sz)
		(*TWal)(unsafe.Pointer(pWal)).FtruncateOnCommit = uint8(0)
	}
	/* Append data to the wal-index. It is not necessary to lock the
	 ** wal-index to do this as the SQLITE_SHM_WRITE lock held on the wal-index
	 ** guarantees that there are no other writers, and no data that may
	 ** be in use by existing readers is being overwritten.
	 */
	iFrame = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	p = pList
	for {
		if !(p != 0 && rc == SQLITE_OK) {
			break
		}
		if int32((*TPgHdr)(unsafe.Pointer(p)).Fflags)&int32(PGHDR_WAL_APPEND) == 0 {
			goto _6
		}
		iFrame++
		rc = _walIndexAppend(tls, pWal, iFrame, (*TPgHdr)(unsafe.Pointer(p)).Fpgno)
		goto _6
	_6:
		;
		p = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
	}
	for rc == SQLITE_OK && nExtra > 0 {
		iFrame++
		nExtra--
		rc = _walIndexAppend(tls, pWal, iFrame, (*TPgHdr)(unsafe.Pointer(pLast)).Fpgno)
	}
	if rc == SQLITE_OK {
		/* Update the private copy of the header. */
		(*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage = uint16(szPage&libc.Int32FromInt32(0xff00) | szPage>>libc.Int32FromInt32(16))
		(*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = iFrame
		if isCommit != 0 {
			(*TWal)(unsafe.Pointer(pWal)).Fhdr.FiChange++
			(*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage = nTruncate
		}
		/* If this is a commit, update the wal-index header too. */
		if isCommit != 0 {
			_walIndexWriteHdr(tls, pWal)
			(*TWal)(unsafe.Pointer(pWal)).FiCallback = iFrame
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Write a set of frames to the log. The caller must hold the write-lock
//	** on the log file (obtained using sqlite3WalBeginWriteTransaction()).
//	**
//	** The difference between this function and walFrames() is that this
//	** function wraps walFrames() in an SEH_TRY{...} block.
//	*/
func _sqlite3WalFrames(tls *libc.TLS, pWal uintptr, szPage int32, pList uintptr, nTruncate TPgno, isCommit int32, sync_flags int32) (r int32) {
	var rc int32
	_ = rc
	rc = _walFrames(tls, pWal, szPage, pList, nTruncate, isCommit, sync_flags)
	return rc
}

// C documentation
//
//	/*
//	** This routine is called to implement sqlite3_wal_checkpoint() and
//	** related interfaces.
//	**
//	** Obtain a CHECKPOINT lock and then backfill as much information as
//	** we can from WAL into the database.
//	**
//	** If parameter xBusy is not NULL, it is a pointer to a busy-handler
//	** callback. In this case this function runs a blocking checkpoint.
//	*/
func _sqlite3WalCheckpoint(tls *libc.TLS, pWal uintptr, db uintptr, eMode int32, xBusy uintptr, pBusyArg uintptr, sync_flags int32, nBuf int32, zBuf uintptr, pnLog uintptr, pnCkpt uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eMode2, rc, v1 int32
	var xBusy2 uintptr
	var _ /* isChanged at bp+0 */ int32
	_, _, _, _ = eMode2, rc, xBusy2, v1 /* Return code */
	*(*int32)(unsafe.Pointer(bp)) = 0   /* True if a new wal-index header is loaded */
	eMode2 = eMode                      /* Mode to pass to walCheckpoint() */
	xBusy2 = xBusy                      /* Busy handler for eMode2 */
	/* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
	 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
	if (*TWal)(unsafe.Pointer(pWal)).FreadOnly != 0 {
		return int32(SQLITE_READONLY)
	}
	/* Enable blocking locks, if possible. */
	if xBusy2 != 0 {
	}
	/* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
	 ** "checkpoint" lock on the database file.
	 ** EVIDENCE-OF: R-10421-19736 If any other process is running a
	 ** checkpoint operation at the same time, the lock cannot be obtained and
	 ** SQLITE_BUSY is returned.
	 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
	 ** it will not be invoked in this case.
	 */
	rc = _walLockExclusive(tls, pWal, int32(WAL_CKPT_LOCK), int32(1))
	if rc == SQLITE_OK {
		(*TWal)(unsafe.Pointer(pWal)).FckptLock = uint8(1)
		/* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
		 ** TRUNCATE modes also obtain the exclusive "writer" lock on the database
		 ** file.
		 **
		 ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
		 ** immediately, and a busy-handler is configured, it is invoked and the
		 ** writer lock retried until either the busy-handler returns 0 or the
		 ** lock is successfully obtained.
		 */
		if eMode != SQLITE_CHECKPOINT_PASSIVE {
			rc = _walBusyLock(tls, pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, int32(1))
			if rc == SQLITE_OK {
				(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(1)
			} else {
				if rc == int32(SQLITE_BUSY) {
					eMode2 = SQLITE_CHECKPOINT_PASSIVE
					xBusy2 = uintptr(0)
					rc = SQLITE_OK
				}
			}
		}
	}
	/* Read the wal-index header. */
	if rc == SQLITE_OK {
		/* For a passive checkpoint, do not re-enable blocking locks after
		 ** reading the wal-index header. A passive checkpoint should not block
		 ** or invoke the busy handler. The only lock such a checkpoint may
		 ** attempt to obtain is a lock on a read-slot, and it should give up
		 ** immediately and do a partial checkpoint if it cannot obtain it. */
		rc = _walIndexReadHdr(tls, pWal, bp)
		if eMode2 != SQLITE_CHECKPOINT_PASSIVE {
		}
		if *(*int32)(unsafe.Pointer(bp)) != 0 && (*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*TWal)(unsafe.Pointer(pWal)).FpDbFd)).FpMethods)).FiVersion >= int32(3) {
			_sqlite3OsUnfetch(tls, (*TWal)(unsafe.Pointer(pWal)).FpDbFd, 0, uintptr(0))
		}
	}
	/* Copy data from the log to the database file. */
	if rc == SQLITE_OK {
		if (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame != 0 && _walPagesize(tls, pWal) != nBuf {
			rc = _sqlite3CorruptError(tls, int32(69252))
		} else {
			rc = _walCheckpoint(tls, pWal, db, eMode2, xBusy2, pBusyArg, sync_flags, zBuf)
		}
		/* If no error occurred, set the output variables. */
		if rc == SQLITE_OK || rc == int32(SQLITE_BUSY) {
			if pnLog != 0 {
				*(*int32)(unsafe.Pointer(pnLog)) = int32((*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame)
			}
			if pnCkpt != 0 {
				*(*int32)(unsafe.Pointer(pnCkpt)) = int32((*TWalCkptInfo)(unsafe.Pointer(_walCkptInfo(tls, pWal))).FnBackfill)
			}
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		/* If a new wal-index header was loaded before the checkpoint was
		 ** performed, then the pager-cache associated with pWal is now
		 ** out of date. So zero the cached wal-index header to ensure that
		 ** next time the pager opens a snapshot on this database it knows that
		 ** the cache needs to be reset.
		 */
		libc.Xmemset(tls, pWal+52, 0, uint32(48))
	}
	/* Release the locks. */
	_sqlite3WalEndWriteTransaction(tls, pWal)
	if (*TWal)(unsafe.Pointer(pWal)).FckptLock != 0 {
		_walUnlockExclusive(tls, pWal, int32(WAL_CKPT_LOCK), int32(1))
		(*TWal)(unsafe.Pointer(pWal)).FckptLock = uint8(0)
	}
	if rc == SQLITE_OK && eMode != eMode2 {
		v1 = int32(SQLITE_BUSY)
	} else {
		v1 = rc
	}
	return v1
}

// C documentation
//
//	/* Return the value to pass to a sqlite3_wal_hook callback, the
//	** number of frames in the WAL at the point of the last commit since
//	** sqlite3WalCallback() was called.  If no commits have occurred since
//	** the last call, then return 0.
//	*/
func _sqlite3WalCallback(tls *libc.TLS, pWal uintptr) (r int32) {
	var ret Tu32
	_ = ret
	ret = uint32(0)
	if pWal != 0 {
		ret = (*TWal)(unsafe.Pointer(pWal)).FiCallback
		(*TWal)(unsafe.Pointer(pWal)).FiCallback = uint32(0)
	}
	return int32(int32(ret))
}

// C documentation
//
//	/*
//	** This function is called to change the WAL subsystem into or out
//	** of locking_mode=EXCLUSIVE.
//	**
//	** If op is zero, then attempt to change from locking_mode=EXCLUSIVE
//	** into locking_mode=NORMAL.  This means that we must acquire a lock
//	** on the pWal->readLock byte.  If the WAL is already in locking_mode=NORMAL
//	** or if the acquisition of the lock fails, then return 0.  If the
//	** transition out of exclusive-mode is successful, return 1.  This
//	** operation must occur while the pager is still holding the exclusive
//	** lock on the main database file.
//	**
//	** If op is one, then change from locking_mode=NORMAL into
//	** locking_mode=EXCLUSIVE.  This means that the pWal->readLock must
//	** be released.  Return 1 if the transition is made and 0 if the
//	** WAL is already in exclusive-locking mode - meaning that this
//	** routine is a no-op.  The pager must already hold the exclusive lock
//	** on the main database file before invoking this operation.
//	**
//	** If op is negative, then do a dry-run of the op==1 case but do
//	** not actually change anything. The pager uses this to see if it
//	** should acquire the database exclusive lock prior to invoking
//	** the op==1 case.
//	*/
func _sqlite3WalExclusiveMode(tls *libc.TLS, pWal uintptr, op int32) (r int32) {
	var rc int32
	_ = rc
	/* pWal->readLock is usually set, but might be -1 if there was a
	 ** prior error while attempting to acquire are read-lock. This cannot
	 ** happen if the connection is actually in exclusive mode (as no xShmLock
	 ** locks are taken in this case). Nor should the pager attempt to
	 ** upgrade to exclusive-mode following such an error.
	 */
	if op == 0 {
		if int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) != WAL_NORMAL_MODE {
			(*TWal)(unsafe.Pointer(pWal)).FexclusiveMode = uint8(WAL_NORMAL_MODE)
			if _walLockShared(tls, pWal, int32(3)+int32((*TWal)(unsafe.Pointer(pWal)).FreadLock)) != SQLITE_OK {
				(*TWal)(unsafe.Pointer(pWal)).FexclusiveMode = uint8(WAL_EXCLUSIVE_MODE)
			}
			rc = libc.BoolInt32(int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_NORMAL_MODE)
		} else {
			/* Already in locking_mode=NORMAL */
			rc = 0
		}
	} else {
		if op > 0 {
			_walUnlockShared(tls, pWal, int32(3)+int32((*TWal)(unsafe.Pointer(pWal)).FreadLock))
			(*TWal)(unsafe.Pointer(pWal)).FexclusiveMode = uint8(WAL_EXCLUSIVE_MODE)
			rc = int32(1)
		} else {
			rc = libc.BoolInt32(int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_NORMAL_MODE)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if the argument is non-NULL and the WAL module is using
//	** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
//	** WAL module is using shared-memory, return false.
//	*/
func _sqlite3WalHeapMemory(tls *libc.TLS, pWal uintptr) (r int32) {
	return libc.BoolInt32(pWal != 0 && int32((*TWal)(unsafe.Pointer(pWal)).FexclusiveMode) == int32(WAL_HEAPMEMORY_MODE))
}

// C documentation
//
//	/* Create a snapshot object.  The content of a snapshot is opaque to
//	** every other subsystem, so the WAL module can put whatever it needs
//	** in the object.
//	*/
func _sqlite3WalSnapshotGet(tls *libc.TLS, pWal uintptr, ppSnapshot uintptr) (r int32) {
	var pRet uintptr
	var rc int32
	_, _ = pRet, rc
	rc = SQLITE_OK
	if libc.Xmemcmp(tls, pWal+52+24, uintptr(unsafe.Pointer(&_aZero)), uint32(16)) == 0 {
		*(*uintptr)(unsafe.Pointer(ppSnapshot)) = uintptr(0)
		return int32(SQLITE_ERROR)
	}
	pRet = Xsqlite3_malloc(tls, int32(48))
	if pRet == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemcpy(tls, pRet, pWal+52, uint32(48))
		*(*uintptr)(unsafe.Pointer(ppSnapshot)) = pRet
	}
	return rc
}

var _aZero = [4]Tu32{}

// C documentation
//
//	/* Try to open on pSnapshot when the next read-transaction starts
//	*/
func _sqlite3WalSnapshotOpen(tls *libc.TLS, pWal uintptr, pSnapshot uintptr) {
	(*TWal)(unsafe.Pointer(pWal)).FpSnapshot = pSnapshot
}

// C documentation
//
//	/*
//	** Return a +ve value if snapshot p1 is newer than p2. A -ve value if
//	** p1 is older than p2 and zero if p1 and p2 are the same snapshot.
//	*/
func Xsqlite3_snapshot_cmp(tls *libc.TLS, p1 uintptr, p2 uintptr) (r int32) {
	var pHdr1, pHdr2 uintptr
	_, _ = pHdr1, pHdr2
	pHdr1 = p1
	pHdr2 = p2
	/* aSalt[0] is a copy of the value stored in the wal file header. It
	 ** is incremented each time the wal file is restarted.  */
	if *(*Tu32)(unsafe.Pointer(pHdr1 + 32)) < *(*Tu32)(unsafe.Pointer(pHdr2 + 32)) {
		return -int32(1)
	}
	if *(*Tu32)(unsafe.Pointer(pHdr1 + 32)) > *(*Tu32)(unsafe.Pointer(pHdr2 + 32)) {
		return +libc.Int32FromInt32(1)
	}
	if (*TWalIndexHdr)(unsafe.Pointer(pHdr1)).FmxFrame < (*TWalIndexHdr)(unsafe.Pointer(pHdr2)).FmxFrame {
		return -int32(1)
	}
	if (*TWalIndexHdr)(unsafe.Pointer(pHdr1)).FmxFrame > (*TWalIndexHdr)(unsafe.Pointer(pHdr2)).FmxFrame {
		return +libc.Int32FromInt32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** The caller currently has a read transaction open on the database.
//	** This function takes a SHARED lock on the CHECKPOINTER slot and then
//	** checks if the snapshot passed as the second argument is still
//	** available. If so, SQLITE_OK is returned.
//	**
//	** If the snapshot is not available, SQLITE_ERROR is returned. Or, if
//	** the CHECKPOINTER lock cannot be obtained, SQLITE_BUSY. If any error
//	** occurs (any value other than SQLITE_OK is returned), the CHECKPOINTER
//	** lock is released before returning.
//	*/
func _sqlite3WalSnapshotCheck(tls *libc.TLS, pWal uintptr, pSnapshot uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	rc = _walLockShared(tls, pWal, int32(WAL_CKPT_LOCK))
	if rc == SQLITE_OK {
		pNew = pSnapshot
		if libc.Xmemcmp(tls, pNew+32, pWal+52+32, uint32(8)) != 0 || (*TWalIndexHdr)(unsafe.Pointer(pNew)).FmxFrame < (*TWalCkptInfo)(unsafe.Pointer(_walCkptInfo(tls, pWal))).FnBackfillAttempted {
			rc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
			_walUnlockShared(tls, pWal, int32(WAL_CKPT_LOCK))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Release a lock obtained by an earlier successful call to
//	** sqlite3WalSnapshotCheck().
//	*/
func _sqlite3WalSnapshotUnlock(tls *libc.TLS, pWal uintptr) {
	_walUnlockShared(tls, pWal, int32(WAL_CKPT_LOCK))
}

// C documentation
//
//	/* Return the sqlite3_file object for the WAL file
//	*/
func _sqlite3WalFile(tls *libc.TLS, pWal uintptr) (r uintptr) {
	return (*TWal)(unsafe.Pointer(pWal)).FpWalFd
}

/************** End of wal.c *************************************************/
/************** Begin file btmutex.c *****************************************/
/*
** 2007 August 27
**
** 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 mutexes on Btree objects.
** This code really belongs in btree.c.  But btree.c is getting too
** big and we want to break it down some.  This packaged seemed like
** a good breakout.
 */
/************** Include btreeInt.h in the middle of btmutex.c ****************/
/************** Begin file btreeInt.h ****************************************/
/*
** 2004 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 implements an external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
**     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
**     "Sorting And Searching", pages 473-480. Addison-Wesley
**     Publishing Company, Reading, Massachusetts.
**
** The basic idea is that each page of the file contains N database
** entries and N+1 pointers to subpages.
**
**   ----------------------------------------------------------------
**   |  Ptr(0) | Key(0) | Ptr(1) | Key(1) | ... | Key(N-1) | Ptr(N) |
**   ----------------------------------------------------------------
**
** All of the keys on the page that Ptr(0) points to have values less
** than Key(0).  All of the keys on page Ptr(1) and its subpages have
** values greater than Key(0) and less than Key(1).  All of the keys
** on Ptr(N) and its subpages have values greater than Key(N-1).  And
** so forth.
**
** Finding a particular key requires reading O(log(M)) pages from the
** disk where M is the number of entries in the tree.
**
** In this implementation, a single file can hold one or more separate
** BTrees.  Each BTree is identified by the index of its root page.  The
** key and data for any entry are combined to form the "payload".  A
** fixed amount of payload can be carried directly on the database
** page.  If the payload is larger than the preset amount then surplus
** bytes are stored on overflow pages.  The payload for an entry
** and the preceding pointer are combined to form a "Cell".  Each
** page has a small header which contains the Ptr(N) pointer and other
** information such as the size of key and data.
**
** FORMAT DETAILS
**
** The file is divided into pages.  The first page is called page 1,
** the second is page 2, and so forth.  A page number of zero indicates
** "no such page".  The page size can be any power of 2 between 512 and 65536.
** Each page can be either a btree page, a freelist page, an overflow
** page, or a pointer-map page.
**
** The first page is always a btree page.  The first 100 bytes of the first
** page contain a special header (the "file header") that describes the file.
** The format of the file header is as follows:
**
**   OFFSET   SIZE    DESCRIPTION
**      0      16     Header string: "SQLite format 3\000"
**     16       2     Page size in bytes.  (1 means 65536)
**     18       1     File format write version
**     19       1     File format read version
**     20       1     Bytes of unused space at the end of each page
**     21       1     Max embedded payload fraction (must be 64)
**     22       1     Min embedded payload fraction (must be 32)
**     23       1     Min leaf payload fraction (must be 32)
**     24       4     File change counter
**     28       4     The size of the database in pages
**     32       4     First freelist page
**     36       4     Number of freelist pages in the file
**     40      60     15 4-byte meta values passed to higher layers
**
**     40       4     Schema cookie
**     44       4     File format of schema layer
**     48       4     Size of page cache
**     52       4     Largest root-page (auto/incr_vacuum)
**     56       4     1=UTF-8 2=UTF16le 3=UTF16be
**     60       4     User version
**     64       4     Incremental vacuum mode
**     68       4     Application-ID
**     72      20     unused
**     92       4     The version-valid-for number
**     96       4     SQLITE_VERSION_NUMBER
**
** All of the integer values are big-endian (most significant byte first).
**
** The file change counter is incremented when the database is changed
** This counter allows other processes to know when the file has changed
** and thus when they need to flush their cache.
**
** The max embedded payload fraction is the amount of the total usable
** space in a page that can be consumed by a single cell for standard
** B-tree (non-LEAFDATA) tables.  A value of 255 means 100%.  The default
** is to limit the maximum cell size so that at least 4 cells will fit
** on one page.  Thus the default max embedded payload fraction is 64.
**
** If the payload for a cell is larger than the max payload, then extra
** payload is spilled to overflow pages.  Once an overflow page is allocated,
** as many bytes as possible are moved into the overflow pages without letting
** the cell size drop below the min embedded payload fraction.
**
** The min leaf payload fraction is like the min embedded payload fraction
** except that it applies to leaf nodes in a LEAFDATA tree.  The maximum
** payload fraction for a LEAFDATA tree is always 100% (or 255) and it
** not specified in the header.
**
** Each btree pages is divided into three sections:  The header, the
** cell pointer array, and the cell content area.  Page 1 also has a 100-byte
** file header that occurs before the page header.
**
**      |----------------|
**      | file header    |   100 bytes.  Page 1 only.
**      |----------------|
**      | page header    |   8 bytes for leaves.  12 bytes for interior nodes
**      |----------------|
**      | cell pointer   |   |  2 bytes per cell.  Sorted order.
**      | array          |   |  Grows downward
**      |                |   v
**      |----------------|
**      | unallocated    |
**      | space          |
**      |----------------|   ^  Grows upwards
**      | cell content   |   |  Arbitrary order interspersed with freeblocks.
**      | area           |   |  and free space fragments.
**      |----------------|
**
** The page headers looks like this:
**
**   OFFSET   SIZE     DESCRIPTION
**      0       1      Flags. 1: intkey, 2: zerodata, 4: leafdata, 8: leaf
**      1       2      byte offset to the first freeblock
**      3       2      number of cells on this page
**      5       2      first byte of the cell content area
**      7       1      number of fragmented free bytes
**      8       4      Right child (the Ptr(N) value).  Omitted on leaves.
**
** The flags define the format of this btree page.  The leaf flag means that
** this page has no children.  The zerodata flag means that this page carries
** only keys and no data.  The intkey flag means that the key is an integer
** which is stored in the key size entry of the cell header rather than in
** the payload area.
**
** The cell pointer array begins on the first byte after the page header.
** The cell pointer array contains zero or more 2-byte numbers which are
** offsets from the beginning of the page to the cell content in the cell
** content area.  The cell pointers occur in sorted order.  The system strives
** to keep free space after the last cell pointer so that new cells can
** be easily added without having to defragment the page.
**
** Cell content is stored at the very end of the page and grows toward the
** beginning of the page.
**
** Unused space within the cell content area is collected into a linked list of
** freeblocks.  Each freeblock is at least 4 bytes in size.  The byte offset
** to the first freeblock is given in the header.  Freeblocks occur in
** increasing order.  Because a freeblock must be at least 4 bytes in size,
** any group of 3 or fewer unused bytes in the cell content area cannot
** exist on the freeblock chain.  A group of 3 or fewer free bytes is called
** a fragment.  The total number of bytes in all fragments is recorded.
** in the page header at offset 7.
**
**    SIZE    DESCRIPTION
**      2     Byte offset of the next freeblock
**      2     Bytes in this freeblock
**
** Cells are of variable length.  Cells are stored in the cell content area at
** the end of the page.  Pointers to the cells are in the cell pointer array
** that immediately follows the page header.  Cells is not necessarily
** contiguous or in order, but cell pointers are contiguous and in order.
**
** Cell content makes use of variable length integers.  A variable
** length integer is 1 to 9 bytes where the lower 7 bits of each
** byte are used.  The integer consists of all bytes that have bit 8 set and
** the first byte with bit 8 clear.  The most significant byte of the integer
** appears first.  A variable-length integer may not be more than 9 bytes long.
** As a special case, all 8 bits of the 9th byte are used as data.  This
** allows a 64-bit integer to be encoded in 9 bytes.
**
**    0x00                      becomes  0x00000000
**    0x7f                      becomes  0x0000007f
**    0x81 0x00                 becomes  0x00000080
**    0x82 0x00                 becomes  0x00000100
**    0x80 0x7f                 becomes  0x0000007f
**    0x81 0x91 0xd1 0xac 0x78  becomes  0x12345678
**    0x81 0x81 0x81 0x81 0x01  becomes  0x10204081
**
** Variable length integers are used for rowids and to hold the number of
** bytes of key and data in a btree cell.
**
** The content of a cell looks like this:
**
**    SIZE    DESCRIPTION
**      4     Page number of the left child. Omitted if leaf flag is set.
**     var    Number of bytes of data. Omitted if the zerodata flag is set.
**     var    Number of bytes of key. Or the key itself if intkey flag is set.
**      *     Payload
**      4     First page of the overflow chain.  Omitted if no overflow
**
** Overflow pages form a linked list.  Each page except the last is completely
** filled with data (pagesize - 4 bytes).  The last page can have as little
** as 1 byte of data.
**
**    SIZE    DESCRIPTION
**      4     Page number of next overflow page
**      *     Data
**
** Freelist pages come in two subtypes: trunk pages and leaf pages.  The
** file header points to the first in a linked list of trunk page.  Each trunk
** page points to multiple leaf pages.  The content of a leaf page is
** unspecified.  A trunk page looks like this:
**
**    SIZE    DESCRIPTION
**      4     Page number of next trunk page
**      4     Number of leaf pointers on this page
**      *     zero or more pages numbers of leaves
 */
/* #include "sqliteInt.h" */

/* The following value is the maximum cell size assuming a maximum page
** size give above.
 */

/* The maximum number of cells on a single page of the database.  This
** assumes a minimum cell size of 6 bytes  (4 bytes for the cell itself
** plus 2 bytes for the index to the cell in the page header).  Such
** small cells will be rare, but they are possible.
 */

// C documentation
//
//	/* Forward declarations */
type TMemPage = struct {
	FisInit          Tu8
	FintKey          Tu8
	FintKeyLeaf      Tu8
	Fpgno            TPgno
	Fleaf            Tu8
	FhdrOffset       Tu8
	FchildPtrSize    Tu8
	Fmax1bytePayload Tu8
	FnOverflow       Tu8
	FmaxLocal        Tu16
	FminLocal        Tu16
	FcellOffset      Tu16
	FnFree           int32
	FnCell           Tu16
	FmaskPage        Tu16
	FaiOvfl          [4]Tu16
	FapOvfl          [4]uintptr
	FpBt             uintptr
	FaData           uintptr
	FaDataEnd        uintptr
	FaCellIdx        uintptr
	FaDataOfst       uintptr
	FpDbPage         uintptr
	FxCellSize       uintptr
	FxParseCell      uintptr
}

type MemPage = TMemPage

type TBtLock = struct {
	FpBtree uintptr
	FiTable TPgno
	FeLock  Tu8
	FpNext  uintptr
}

type BtLock = TBtLock

type TCellInfo = struct {
	F__ccgo_align [0]uint32
	FnKey         Ti64
	FpPayload     uintptr
	FnPayload     Tu32
	FnLocal       Tu16
	FnSize        Tu16
	F__ccgo_pad5  [4]byte
}

type CellInfo = TCellInfo

/*
** This is a magic string that appears at the beginning of every
** SQLite database in order to identify the file as a real database.
**
** You can change this value at compile-time by specifying a
** -DSQLITE_FILE_HEADER="..." on the compiler command-line.  The
** header must be exactly 16 bytes including the zero-terminator so
** the string itself should be 15 characters long.  If you change
** the header, then your custom library will not be able to read
** databases generated by the standard tools and the standard tools
** will not be able to read databases created by your custom library.
 */

/*
** Page type flags.  An ORed combination of these flags appear as the
** first byte of on-disk image of every BTree page.
 */

/*
** An instance of this object stores information about each a single database
** page that has been loaded into memory.  The information in this object
** is derived from the raw on-disk page content.
**
** As each database page is loaded into memory, the pager allocates an
** instance of this object and zeros the first 8 bytes.  (This is the
** "extra" information associated with each page of the pager.)
**
** Access to all fields of this structure is controlled by the mutex
** stored in MemPage.pBt->mutex.
 */
type TMemPage1 = struct {
	FisInit          Tu8
	FintKey          Tu8
	FintKeyLeaf      Tu8
	Fpgno            TPgno
	Fleaf            Tu8
	FhdrOffset       Tu8
	FchildPtrSize    Tu8
	Fmax1bytePayload Tu8
	FnOverflow       Tu8
	FmaxLocal        Tu16
	FminLocal        Tu16
	FcellOffset      Tu16
	FnFree           int32
	FnCell           Tu16
	FmaskPage        Tu16
	FaiOvfl          [4]Tu16
	FapOvfl          [4]uintptr
	FpBt             uintptr
	FaData           uintptr
	FaDataEnd        uintptr
	FaCellIdx        uintptr
	FaDataOfst       uintptr
	FpDbPage         uintptr
	FxCellSize       uintptr
	FxParseCell      uintptr
}

type MemPage1 = TMemPage1

/*
** A linked list of the following structures is stored at BtShared.pLock.
** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
** is opened on the table with root page BtShared.iTable. Locks are removed
** from this list when a transaction is committed or rolled back, or when
** a btree handle is closed.
 */
type TBtLock1 = struct {
	FpBtree uintptr
	FiTable TPgno
	FeLock  Tu8
	FpNext  uintptr
}

type BtLock1 = TBtLock1

/* Candidate values for BtLock.eLock */

/* A Btree handle
**
** A database connection contains a pointer to an instance of
** this object for every database file that it has open.  This structure
** is opaque to the database connection.  The database connection cannot
** see the internals of this structure and only deals with pointers to
** this structure.
**
** For some database files, the same underlying database cache might be
** shared between multiple connections.  In that case, each connection
** has it own instance of this object.  But each instance of this object
** points to the same BtShared object.  The database cache and the
** schema associated with the database file are all contained within
** the BtShared object.
**
** All fields in this structure are accessed under sqlite3.mutex.
** The pBt pointer itself may not be changed while there exists cursors
** in the referenced BtShared that point back to this Btree since those
** cursors have to go through this Btree to find their BtShared and
** they often do so without holding sqlite3.mutex.
 */
type TBtree1 = struct {
	Fdb             uintptr
	FpBt            uintptr
	FinTrans        Tu8
	Fsharable       Tu8
	Flocked         Tu8
	FhasIncrblobCur Tu8
	FwantToLock     int32
	FnBackup        int32
	FiBDataVersion  Tu32
	FpNext          uintptr
	FpPrev          uintptr
	Flock           TBtLock
}

type Btree1 = TBtree1

/*
** Btree.inTrans may take one of the following values.
**
** If the shared-data extension is enabled, there may be multiple users
** of the Btree structure. At most one of these may open a write transaction,
** but any number may have active read transactions.
**
** These values must match SQLITE_TXN_NONE, SQLITE_TXN_READ, and
** SQLITE_TXN_WRITE
 */

/*
** An instance of this object represents a single database file.
**
** A single database file can be in use at the same time by two
** or more database connections.  When two or more connections are
** sharing the same database file, each connection has it own
** private Btree object for the file and each of those Btrees points
** to this one BtShared object.  BtShared.nRef is the number of
** connections currently sharing this database file.
**
** Fields in this structure are accessed under the BtShared.mutex
** mutex, except for nRef and pNext which are accessed under the
** global SQLITE_MUTEX_STATIC_MAIN mutex.  The pPager field
** may not be modified once it is initially set as long as nRef>0.
** The pSchema field may be set once under BtShared.mutex and
** thereafter is unchanged as long as nRef>0.
**
** isPending:
**
**   If a BtShared client fails to obtain a write-lock on a database
**   table (because there exists one or more read-locks on the table),
**   the shared-cache enters 'pending-lock' state and isPending is
**   set to true.
**
**   The shared-cache leaves the 'pending lock' state when either of
**   the following occur:
**
**     1) The current writer (BtShared.pWriter) concludes its transaction, OR
**     2) The number of locks held by other connections drops to zero.
**
**   while in the 'pending-lock' state, no connection may start a new
**   transaction.
**
**   This feature is included to help prevent writer-starvation.
 */
type TBtShared1 = struct {
	FpPager          uintptr
	Fdb              uintptr
	FpCursor         uintptr
	FpPage1          uintptr
	FopenFlags       Tu8
	FautoVacuum      Tu8
	FincrVacuum      Tu8
	FbDoTruncate     Tu8
	FinTransaction   Tu8
	Fmax1bytePayload Tu8
	FnReserveWanted  Tu8
	FbtsFlags        Tu16
	FmaxLocal        Tu16
	FminLocal        Tu16
	FmaxLeaf         Tu16
	FminLeaf         Tu16
	FpageSize        Tu32
	FusableSize      Tu32
	FnTransaction    int32
	FnPage           Tu32
	FpSchema         uintptr
	FxFreeSchema     uintptr
	Fmutex           uintptr
	FpHasContent     uintptr
	FnRef            int32
	FpNext           uintptr
	FpLock           uintptr
	FpWriter         uintptr
	FpTmpSpace       uintptr
	FnPreformatSize  int32
}

type BtShared1 = TBtShared1

/*
** Allowed values for BtShared.btsFlags
 */

/*
** An instance of the following structure is used to hold information
** about a cell.  The parseCellPtr() function fills in this structure
** based on information extract from the raw disk page.
 */
type TCellInfo1 = struct {
	F__ccgo_align [0]uint32
	FnKey         Ti64
	FpPayload     uintptr
	FnPayload     Tu32
	FnLocal       Tu16
	FnSize        Tu16
	F__ccgo_pad5  [4]byte
}

type CellInfo1 = TCellInfo1

/*
** Maximum depth of an SQLite B-Tree structure. Any B-Tree deeper than
** this will be declared corrupt. This value is calculated based on a
** maximum database size of 2^31 pages a minimum fanout of 2 for a
** root-node and 3 for all other internal nodes.
**
** If a tree that appears to be taller than this is encountered, it is
** assumed that the database is corrupt.
 */

/*
** A cursor is a pointer to a particular entry within a particular
** b-tree within a database file.
**
** The entry is identified by its MemPage and the index in
** MemPage.aCell[] of the entry.
**
** A single database file can be shared by two more database connections,
** but cursors cannot be shared.  Each cursor is associated with a
** particular database connection identified BtCursor.pBtree.db.
**
** Fields in this structure are accessed under the BtShared.mutex
** found at self->pBt->mutex.
**
** skipNext meaning:
** The meaning of skipNext depends on the value of eState:
**
**   eState            Meaning of skipNext
**   VALID             skipNext is meaningless and is ignored
**   INVALID           skipNext is meaningless and is ignored
**   SKIPNEXT          sqlite3BtreeNext() is a no-op if skipNext>0 and
**                     sqlite3BtreePrevious() is no-op if skipNext<0.
**   REQUIRESEEK       restoreCursorPosition() restores the cursor to
**                     eState=SKIPNEXT if skipNext!=0
**   FAULT             skipNext holds the cursor fault error code.
 */
type TBtCursor1 = struct {
	F__ccgo_align   [0]uint32
	FeState         Tu8
	FcurFlags       Tu8
	FcurPagerFlags  Tu8
	Fhints          Tu8
	FskipNext       int32
	FpBtree         uintptr
	FaOverflow      uintptr
	FpKey           uintptr
	FpBt            uintptr
	FpNext          uintptr
	F__ccgo_align10 [4]byte
	Finfo           TCellInfo
	FnKey           Ti64
	FpgnoRoot       TPgno
	FiPage          Ti8
	FcurIntKey      Tu8
	Fix             Tu16
	FaiIdx          [19]Tu16
	FpKeyInfo       uintptr
	FpPage          uintptr
	FapPage         [19]uintptr
	F__ccgo_pad20   [4]byte
}

type BtCursor1 = TBtCursor1

/*
** Legal values for BtCursor.curFlags
 */

/*
** Potential values for BtCursor.eState.
**
** CURSOR_INVALID:
**   Cursor does not point to a valid entry. This can happen (for example)
**   because the table is empty or because BtreeCursorFirst() has not been
**   called.
**
** CURSOR_VALID:
**   Cursor points to a valid entry. getPayload() etc. may be called.
**
** CURSOR_SKIPNEXT:
**   Cursor is valid except that the Cursor.skipNext field is non-zero
**   indicating that the next sqlite3BtreeNext() or sqlite3BtreePrevious()
**   operation should be a no-op.
**
** CURSOR_REQUIRESEEK:
**   The table that this cursor was opened on still exists, but has been
**   modified since the cursor was last used. The cursor position is saved
**   in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
**   this state, restoreCursorPosition() can be called to attempt to
**   seek the cursor to the saved position.
**
** CURSOR_FAULT:
**   An unrecoverable error (an I/O error or a malloc failure) has occurred
**   on a different connection that shares the BtShared cache with this
**   cursor.  The error has left the cache in an inconsistent state.
**   Do nothing else with this cursor.  Any attempt to use the cursor
**   should return the error code stored in BtCursor.skipNext
 */

/*
** The database page the PENDING_BYTE occupies. This page is never used.
 */

/*
** These macros define the location of the pointer-map entry for a
** database page. The first argument to each is the number of usable
** bytes on each page of the database (often 1024). The second is the
** page number to look up in the pointer map.
**
** PTRMAP_PAGENO returns the database page number of the pointer-map
** page that stores the required pointer. PTRMAP_PTROFFSET returns
** the offset of the requested map entry.
**
** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
** then pgno is returned. So (pgno==PTRMAP_PAGENO(pgsz, pgno)) can be
** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
** this test.
 */

/*
** The pointer map is a lookup table that identifies the parent page for
** each child page in the database file.  The parent page is the page that
** contains a pointer to the child.  Every page in the database contains
** 0 or 1 parent pages.  (In this context 'database page' refers
** to any page that is not part of the pointer map itself.)  Each pointer map
** entry consists of a single byte 'type' and a 4 byte parent page number.
** The PTRMAP_XXX identifiers below are the valid types.
**
** The purpose of the pointer map is to facility moving pages from one
** position in the file to another as part of autovacuum.  When a page
** is moved, the pointer in its parent must be updated to point to the
** new location.  The pointer map is used to locate the parent page quickly.
**
** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
**                  used in this case.
**
** PTRMAP_FREEPAGE: The database page is an unused (free) page. The page-number
**                  is not used in this case.
**
** PTRMAP_OVERFLOW1: The database page is the first page in a list of
**                   overflow pages. The page number identifies the page that
**                   contains the cell with a pointer to this overflow page.
**
** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
**                   overflow pages. The page-number identifies the previous
**                   page in the overflow page list.
**
** PTRMAP_BTREE: The database page is a non-root btree page. The page number
**               identifies the parent page in the btree.
 */

/* A bunch of assert() statements to check the transaction state variables
** of handle p (type Btree*) are internally consistent.
 */

/*
** The ISAUTOVACUUM macro is used within balance_nonroot() to determine
** if the database supports auto-vacuum or not. Because it is used
** within an expression that is an argument to another macro
** (sqliteMallocRaw), it is not possible to use conditional compilation.
** So, this macro is defined instead.
 */

// C documentation
//
//	/*
//	** This structure is passed around through all the PRAGMA integrity_check
//	** checking routines in order to keep track of some global state information.
//	**
//	** The aRef[] array is allocated so that there is 1 bit for each page in
//	** the database. As the integrity-check proceeds, for each page used in
//	** the database the corresponding bit is set. This allows integrity-check to
//	** detect pages that are used twice and orphaned pages (both of which
//	** indicate corruption).
//	*/
type TIntegrityCk = struct {
	F__ccgo_align [0]uint32
	FpBt          uintptr
	FpPager       uintptr
	FaPgRef       uintptr
	FnCkPage      TPgno
	FmxErr        int32
	FnErr         int32
	Frc           int32
	FnStep        Tu32
	FzPfx         uintptr
	Fv0           TPgno
	Fv1           TPgno
	Fv2           int32
	FerrMsg       TStrAccum
	Fheap         uintptr
	Fdb           uintptr
	FnRow         Ti64
}

type IntegrityCk = TIntegrityCk

type TIntegrityCk1 = struct {
	F__ccgo_align [0]uint32
	FpBt          uintptr
	FpPager       uintptr
	FaPgRef       uintptr
	FnCkPage      TPgno
	FmxErr        int32
	FnErr         int32
	Frc           int32
	FnStep        Tu32
	FzPfx         uintptr
	Fv0           TPgno
	Fv1           TPgno
	Fv2           int32
	FerrMsg       TStrAccum
	Fheap         uintptr
	Fdb           uintptr
	FnRow         Ti64
}

type IntegrityCk1 = TIntegrityCk1

/*
** Routines to read or write a two- and four-byte big-endian integer values.
 */

/*
** get2byteAligned(), unlike get2byte(), requires that its argument point to a
** two-byte aligned address.  get2byteAligned() is only used for accessing the
** cell addresses in a btree header.
 */

/************** End of btreeInt.h ********************************************/
/************** Continuing where we left off in btmutex.c ********************/

// C documentation
//
//	/*
//	** Obtain the BtShared mutex associated with B-Tree handle p. Also,
//	** set BtShared.db to the database handle associated with p and the
//	** p->locked boolean to true.
//	*/
func _lockBtreeMutex(tls *libc.TLS, p uintptr) {
	Xsqlite3_mutex_enter(tls, (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).Fmutex)
	(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).Fdb = (*TBtree)(unsafe.Pointer(p)).Fdb
	(*TBtree)(unsafe.Pointer(p)).Flocked = uint8(1)
}

// C documentation
//
//	/*
//	** Release the BtShared mutex associated with B-Tree handle p and
//	** clear the p->locked boolean.
//	*/
func _unlockBtreeMutex(tls *libc.TLS, p uintptr) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	Xsqlite3_mutex_leave(tls, (*TBtShared)(unsafe.Pointer(pBt)).Fmutex)
	(*TBtree)(unsafe.Pointer(p)).Flocked = uint8(0)
}

// C documentation
//
//	/*
//	** Enter a mutex on the given BTree object.
//	**
//	** If the object is not sharable, then no mutex is ever required
//	** and this routine is a no-op.  The underlying mutex is non-recursive.
//	** But we keep a reference count in Btree.wantToLock so the behavior
//	** of this interface is recursive.
//	**
//	** To avoid deadlocks, multiple Btrees are locked in the same order
//	** by all database connections.  The p->pNext is a list of other
//	** Btrees belonging to the same database connection as the p Btree
//	** which need to be locked after p.  If we cannot get a lock on
//	** p, then first unlock all of the others on p->pNext, then wait
//	** for the lock to become available on p, then relock all of the
//	** subsequent Btrees that desire a lock.
//	*/
func _sqlite3BtreeEnter(tls *libc.TLS, p uintptr) {
	/* Some basic sanity checking on the Btree.  The list of Btrees
	 ** connected by pNext and pPrev should be in sorted order by
	 ** Btree.pBt value. All elements of the list should belong to
	 ** the same connection. Only shared Btrees are on the list. */
	/* Check for locking consistency */
	/* We should already hold a lock on the database connection */
	/* Unless the database is sharable and unlocked, then BtShared.db
	 ** should already be set correctly. */
	if !((*TBtree)(unsafe.Pointer(p)).Fsharable != 0) {
		return
	}
	(*TBtree)(unsafe.Pointer(p)).FwantToLock++
	if (*TBtree)(unsafe.Pointer(p)).Flocked != 0 {
		return
	}
	_btreeLockCarefully(tls, p)
}

// C documentation
//
//	/* This is a helper function for sqlite3BtreeLock(). By moving
//	** complex, but seldom used logic, out of sqlite3BtreeLock() and
//	** into this routine, we avoid unnecessary stack pointer changes
//	** and thus help the sqlite3BtreeLock() routine to run much faster
//	** in the common case.
//	*/
func _btreeLockCarefully(tls *libc.TLS, p uintptr) {
	var pLater uintptr
	_ = pLater
	/* In most cases, we should be able to acquire the lock we
	 ** want without having to go through the ascending lock
	 ** procedure that follows.  Just be sure not to block.
	 */
	if Xsqlite3_mutex_try(tls, (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).Fmutex) == SQLITE_OK {
		(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).Fdb = (*TBtree)(unsafe.Pointer(p)).Fdb
		(*TBtree)(unsafe.Pointer(p)).Flocked = uint8(1)
		return
	}
	/* To avoid deadlock, first release all locks with a larger
	 ** BtShared address.  Then acquire our lock.  Then reacquire
	 ** the other BtShared locks that we used to hold in ascending
	 ** order.
	 */
	pLater = (*TBtree)(unsafe.Pointer(p)).FpNext
	for {
		if !(pLater != 0) {
			break
		}
		if (*TBtree)(unsafe.Pointer(pLater)).Flocked != 0 {
			_unlockBtreeMutex(tls, pLater)
		}
		goto _1
	_1:
		;
		pLater = (*TBtree)(unsafe.Pointer(pLater)).FpNext
	}
	_lockBtreeMutex(tls, p)
	pLater = (*TBtree)(unsafe.Pointer(p)).FpNext
	for {
		if !(pLater != 0) {
			break
		}
		if (*TBtree)(unsafe.Pointer(pLater)).FwantToLock != 0 {
			_lockBtreeMutex(tls, pLater)
		}
		goto _2
	_2:
		;
		pLater = (*TBtree)(unsafe.Pointer(pLater)).FpNext
	}
}

// C documentation
//
//	/*
//	** Exit the recursive mutex on a Btree.
//	*/
func _sqlite3BtreeLeave(tls *libc.TLS, p uintptr) {
	if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
		(*TBtree)(unsafe.Pointer(p)).FwantToLock--
		if (*TBtree)(unsafe.Pointer(p)).FwantToLock == 0 {
			_unlockBtreeMutex(tls, p)
		}
	}
}

// C documentation
//
//	/*
//	** Enter the mutex on every Btree associated with a database
//	** connection.  This is needed (for example) prior to parsing
//	** a statement since we will be comparing table and column names
//	** against all schemas and we do not want those schemas being
//	** reset out from under us.
//	**
//	** There is a corresponding leave-all procedures.
//	**
//	** Enter the mutexes in ascending order by BtShared pointer address
//	** to avoid the possibility of deadlock when two threads with
//	** two or more btrees in common both try to lock all their btrees
//	** at the same instant.
//	*/
func _btreeEnterAll(tls *libc.TLS, db uintptr) {
	var i, skipOk int32
	var p uintptr
	_, _, _ = i, p, skipOk
	skipOk = int32(1)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		p = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if p != 0 && (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
			_sqlite3BtreeEnter(tls, p)
			skipOk = 0
		}
		goto _1
	_1:
		;
		i++
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache = uint8(uint8(skipOk))
}

func _sqlite3BtreeEnterAll(tls *libc.TLS, db uintptr) {
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache) == 0 {
		_btreeEnterAll(tls, db)
	}
}

func _btreeLeaveAll(tls *libc.TLS, db uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		p = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if p != 0 {
			_sqlite3BtreeLeave(tls, p)
		}
		goto _1
	_1:
		;
		i++
	}
}

func _sqlite3BtreeLeaveAll(tls *libc.TLS, db uintptr) {
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache) == 0 {
		_btreeLeaveAll(tls, db)
	}
}

// C documentation
//
//	/*
//	** Enter a mutex on a Btree given a cursor owned by that Btree.
//	**
//	** These entry points are used by incremental I/O only. Enter() is required
//	** any time OMIT_SHARED_CACHE is not defined, regardless of whether or not
//	** the build is threadsafe. Leave() is only required by threadsafe builds.
//	*/
func _sqlite3BtreeEnterCursor(tls *libc.TLS, pCur uintptr) {
	_sqlite3BtreeEnter(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBtree)
}

func _sqlite3BtreeLeaveCursor(tls *libc.TLS, pCur uintptr) {
	_sqlite3BtreeLeave(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBtree)
}

/************** End of btmutex.c *********************************************/
/************** Begin file btree.c *******************************************/
/*
** 2004 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 implements an external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
** Including a description of file format and an overview of operation.
 */
/* #include "btreeInt.h" */

// C documentation
//
//	/*
//	** The header string that appears at the beginning of every
//	** SQLite database.
//	*/
var _zMagicHeader = [16]int8{'S', 'Q', 'L', 'i', 't', 'e', ' ', 'f', 'o', 'r', 'm', 'a', 't', ' ', '3'}

/*
** Set this global variable to 1 to enable tracing using the TRACE
** macro.
 */

/*
** Extract a 2-byte big-endian integer from an array of unsigned bytes.
** But if the value is zero, make it 65536.
**
** This routine is used to extract the "offset to cell content area" value
** from the header of a btree page.  If the page size is 65536 and the page
** is empty, the offset should be 65536, but the 2-byte value stores zero.
** This routine makes the necessary adjustment to 65536.
 */

/*
** Values passed as the 5th argument to allocateBtreePage()
 */

/*
** Macro IfNotOmitAV(x) returns (x) if SQLITE_OMIT_AUTOVACUUM is not
** defined, or 0 if it is. For example:
**
**   bIncrVacuum = IfNotOmitAV(pBtShared->incrVacuum);
 */

// C documentation
//
//	/*
//	** A list of BtShared objects that are eligible for participation
//	** in shared cache.  This variable has file scope during normal builds,
//	** but the test harness needs to access it so we make it global for
//	** test builds.
//	**
//	** Access to this variable is protected by SQLITE_MUTEX_STATIC_MAIN.
//	*/
var _sqlite3SharedCacheList = uintptr(0)

// C documentation
//
//	/*
//	** Enable or disable the shared pager and schema features.
//	**
//	** This routine has no effect on existing database connections.
//	** The shared cache setting effects only future calls to
//	** sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2().
//	*/
func Xsqlite3_enable_shared_cache(tls *libc.TLS, enable int32) (r int32) {
	_sqlite3Config.FsharedCacheEnabled = enable
	return SQLITE_OK
}

/*
** Implementation of the SQLITE_CORRUPT_PAGE() macro. Takes a single
** (MemPage*) as an argument. The (MemPage*) must not be NULL.
**
** If SQLITE_DEBUG is not defined, then this macro is equivalent to
** SQLITE_CORRUPT_BKPT. Or, if SQLITE_DEBUG is set, then the log message
** normally produced as a side-effect of SQLITE_CORRUPT_BKPT is augmented
** with the page number and filename associated with the (MemPage*).
 */

/* Default value for SHARED_LOCK_TRACE macro if shared-cache is disabled
** or if the lock tracking is disabled.  This is always the value for
** release builds.
 */

// C documentation
//
//	/*
//	** Query to see if Btree handle p may obtain a lock of type eLock
//	** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
//	** SQLITE_OK if the lock may be obtained (by calling
//	** setSharedCacheTableLock()), or SQLITE_LOCKED if not.
//	*/
func _querySharedCacheTableLock(tls *libc.TLS, p uintptr, iTab TPgno, eLock Tu8) (r int32) {
	var pBt, pIter, p2 uintptr
	_, _, _ = pBt, pIter, p2
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	/* If requesting a write-lock, then the Btree must have an open write
	 ** transaction on this file. And, obviously, for this to be so there
	 ** must be an open write transaction on the file itself.
	 */
	/* This routine is a no-op if the shared-cache is not enabled */
	if !((*TBtree)(unsafe.Pointer(p)).Fsharable != 0) {
		return SQLITE_OK
	}
	/* If some other connection is holding an exclusive lock, the
	 ** requested lock may not be obtained.
	 */
	if (*TBtShared)(unsafe.Pointer(pBt)).FpWriter != p && int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_EXCLUSIVE) != 0 {
		_sqlite3ConnectionBlocked(tls, (*TBtree)(unsafe.Pointer(p)).Fdb, (*TBtree)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpWriter)).Fdb)
		return libc.Int32FromInt32(SQLITE_LOCKED) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	}
	pIter = (*TBtShared)(unsafe.Pointer(pBt)).FpLock
	for {
		if !(pIter != 0) {
			break
		}
		/* The condition (pIter->eLock!=eLock) in the following if(...)
		 ** statement is a simplification of:
		 **
		 **   (eLock==WRITE_LOCK || pIter->eLock==WRITE_LOCK)
		 **
		 ** since we know that if eLock==WRITE_LOCK, then no other connection
		 ** may hold a WRITE_LOCK on any table in this file (since there can
		 ** only be a single writer).
		 */
		if (*TBtLock)(unsafe.Pointer(pIter)).FpBtree != p && (*TBtLock)(unsafe.Pointer(pIter)).FiTable == iTab && int32((*TBtLock)(unsafe.Pointer(pIter)).FeLock) != int32(int32(eLock)) {
			_sqlite3ConnectionBlocked(tls, (*TBtree)(unsafe.Pointer(p)).Fdb, (*TBtree)(unsafe.Pointer((*TBtLock)(unsafe.Pointer(pIter)).FpBtree)).Fdb)
			if int32(int32(eLock)) == int32(WRITE_LOCK) {
				p2 = pBt + 24
				*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(BTS_PENDING))
			}
			return libc.Int32FromInt32(SQLITE_LOCKED) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		goto _1
	_1:
		;
		pIter = (*TBtLock)(unsafe.Pointer(pIter)).FpNext
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Add a lock on the table with root-page iTable to the shared-btree used
//	** by Btree handle p. Parameter eLock must be either READ_LOCK or
//	** WRITE_LOCK.
//	**
//	** This function assumes the following:
//	**
//	**   (a) The specified Btree object p is connected to a sharable
//	**       database (one with the BtShared.sharable flag set), and
//	**
//	**   (b) No other Btree objects hold a lock that conflicts
//	**       with the requested lock (i.e. querySharedCacheTableLock() has
//	**       already been called and returned SQLITE_OK).
//	**
//	** SQLITE_OK is returned if the lock is added successfully. SQLITE_NOMEM
//	** is returned if a malloc attempt fails.
//	*/
func _setSharedCacheTableLock(tls *libc.TLS, p uintptr, iTable TPgno, eLock Tu8) (r int32) {
	var pBt, pIter, pLock uintptr
	_, _, _ = pBt, pIter, pLock
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	pLock = uintptr(0)
	/* A connection with the read-uncommitted flag set will never try to
	 ** obtain a read-lock using this function. The only read-lock obtained
	 ** by a connection in read-uncommitted mode is on the sqlite_schema
	 ** table, and that lock is obtained in BtreeBeginTrans().  */
	/* This function should only be called on a sharable b-tree after it
	 ** has been determined that no other b-tree holds a conflicting lock.  */
	/* First search the list for an existing lock on this table. */
	pIter = (*TBtShared)(unsafe.Pointer(pBt)).FpLock
	for {
		if !(pIter != 0) {
			break
		}
		if (*TBtLock)(unsafe.Pointer(pIter)).FiTable == iTable && (*TBtLock)(unsafe.Pointer(pIter)).FpBtree == p {
			pLock = pIter
			break
		}
		goto _1
	_1:
		;
		pIter = (*TBtLock)(unsafe.Pointer(pIter)).FpNext
	}
	/* If the above search did not find a BtLock struct associating Btree p
	 ** with table iTable, allocate one and link it into the list.
	 */
	if !(pLock != 0) {
		pLock = _sqlite3MallocZero(tls, uint64(16))
		if !(pLock != 0) {
			return int32(SQLITE_NOMEM)
		}
		(*TBtLock)(unsafe.Pointer(pLock)).FiTable = iTable
		(*TBtLock)(unsafe.Pointer(pLock)).FpBtree = p
		(*TBtLock)(unsafe.Pointer(pLock)).FpNext = (*TBtShared)(unsafe.Pointer(pBt)).FpLock
		(*TBtShared)(unsafe.Pointer(pBt)).FpLock = pLock
	}
	/* Set the BtLock.eLock variable to the maximum of the current lock
	 ** and the requested lock. This means if a write-lock was already held
	 ** and a read-lock requested, we don't incorrectly downgrade the lock.
	 */
	if int32(int32(eLock)) > int32((*TBtLock)(unsafe.Pointer(pLock)).FeLock) {
		(*TBtLock)(unsafe.Pointer(pLock)).FeLock = eLock
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Release all the table locks (locks obtained via calls to
//	** the setSharedCacheTableLock() procedure) held by Btree object p.
//	**
//	** This function assumes that Btree p has an open read or write
//	** transaction. If it does not, then the BTS_PENDING flag
//	** may be incorrectly cleared.
//	*/
func _clearAllSharedCacheTableLocks(tls *libc.TLS, p uintptr) {
	var pBt, pLock, ppIter, p1, p2 uintptr
	_, _, _, _, _ = pBt, pLock, ppIter, p1, p2
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	ppIter = pBt + 76
	for *(*uintptr)(unsafe.Pointer(ppIter)) != 0 {
		pLock = *(*uintptr)(unsafe.Pointer(ppIter))
		if (*TBtLock)(unsafe.Pointer(pLock)).FpBtree == p {
			*(*uintptr)(unsafe.Pointer(ppIter)) = (*TBtLock)(unsafe.Pointer(pLock)).FpNext
			if (*TBtLock)(unsafe.Pointer(pLock)).FiTable != uint32(1) {
				Xsqlite3_free(tls, pLock)
			}
		} else {
			ppIter = pLock + 12
		}
	}
	if (*TBtShared)(unsafe.Pointer(pBt)).FpWriter == p {
		(*TBtShared)(unsafe.Pointer(pBt)).FpWriter = uintptr(0)
		p1 = pBt + 24
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(BTS_EXCLUSIVE) | libc.Int32FromInt32(BTS_PENDING)))
	} else {
		if (*TBtShared)(unsafe.Pointer(pBt)).FnTransaction == int32(2) {
			/* This function is called when Btree p is concluding its
			 ** transaction. If there currently exists a writer, and p is not
			 ** that writer, then the number of locks held by connections other
			 ** than the writer must be about to drop to zero. In this case
			 ** set the BTS_PENDING flag to 0.
			 **
			 ** If there is not currently a writer, then BTS_PENDING must
			 ** be zero already. So this next line is harmless in that case.
			 */
			p2 = pBt + 24
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(BTS_PENDING))
		}
	}
}

// C documentation
//
//	/*
//	** This function changes all write-locks held by Btree p into read-locks.
//	*/
func _downgradeAllSharedCacheTableLocks(tls *libc.TLS, p uintptr) {
	var pBt, pLock, p1 uintptr
	_, _, _ = pBt, pLock, p1
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	if (*TBtShared)(unsafe.Pointer(pBt)).FpWriter == p {
		(*TBtShared)(unsafe.Pointer(pBt)).FpWriter = uintptr(0)
		p1 = pBt + 24
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(BTS_EXCLUSIVE) | libc.Int32FromInt32(BTS_PENDING)))
		pLock = (*TBtShared)(unsafe.Pointer(pBt)).FpLock
		for {
			if !(pLock != 0) {
				break
			}
			(*TBtLock)(unsafe.Pointer(pLock)).FeLock = uint8(READ_LOCK)
			goto _2
		_2:
			;
			pLock = (*TBtLock)(unsafe.Pointer(pLock)).FpNext
		}
	}
}

/* Forward reference */

/*
***** This routine is used inside of assert() only ****
**
** Verify that the cursor holds the mutex on its BtShared
 */

/*
** Invalidate the overflow cache of the cursor passed as the first argument.
** on the shared btree structure pBt.
 */

// C documentation
//
//	/*
//	** Invalidate the overflow page-list cache for all cursors opened
//	** on the shared btree structure pBt.
//	*/
func _invalidateAllOverflowCache(tls *libc.TLS, pBt uintptr) {
	var p, p2 uintptr
	_, _ = p, p2
	p = (*TBtShared)(unsafe.Pointer(pBt)).FpCursor
	for {
		if !(p != 0) {
			break
		}
		p2 = p + 1
		*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(BTCF_ValidOvfl))
		goto _1
	_1:
		;
		p = (*TBtCursor)(unsafe.Pointer(p)).FpNext
	}
}

// C documentation
//
//	/*
//	** This function is called before modifying the contents of a table
//	** to invalidate any incrblob cursors that are open on the
//	** row or one of the rows being modified.
//	**
//	** If argument isClearTable is true, then the entire contents of the
//	** table is about to be deleted. In this case invalidate all incrblob
//	** cursors open on any row within the table with root-page pgnoRoot.
//	**
//	** Otherwise, if argument isClearTable is false, then the row with
//	** rowid iRow is being replaced or deleted. In this case invalidate
//	** only those incrblob cursors open on that specific row.
//	*/
func _invalidateIncrblobCursors(tls *libc.TLS, pBtree uintptr, pgnoRoot TPgno, iRow Ti64, isClearTable int32) {
	var p uintptr
	_ = p
	(*TBtree)(unsafe.Pointer(pBtree)).FhasIncrblobCur = uint8(0)
	p = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(pBtree)).FpBt)).FpCursor
	for {
		if !(p != 0) {
			break
		}
		if int32((*TBtCursor)(unsafe.Pointer(p)).FcurFlags)&int32(BTCF_Incrblob) != 0 {
			(*TBtree)(unsafe.Pointer(pBtree)).FhasIncrblobCur = uint8(1)
			if (*TBtCursor)(unsafe.Pointer(p)).FpgnoRoot == pgnoRoot && (isClearTable != 0 || (*TBtCursor)(unsafe.Pointer(p)).Finfo.FnKey == iRow) {
				(*TBtCursor)(unsafe.Pointer(p)).FeState = uint8(CURSOR_INVALID)
			}
		}
		goto _1
	_1:
		;
		p = (*TBtCursor)(unsafe.Pointer(p)).FpNext
	}
}

// C documentation
//
//	/*
//	** Set bit pgno of the BtShared.pHasContent bitvec. This is called
//	** when a page that previously contained data becomes a free-list leaf
//	** page.
//	**
//	** The BtShared.pHasContent bitvec exists to work around an obscure
//	** bug caused by the interaction of two useful IO optimizations surrounding
//	** free-list leaf pages:
//	**
//	**   1) When all data is deleted from a page and the page becomes
//	**      a free-list leaf page, the page is not written to the database
//	**      (as free-list leaf pages contain no meaningful data). Sometimes
//	**      such a page is not even journalled (as it will not be modified,
//	**      why bother journalling it?).
//	**
//	**   2) When a free-list leaf page is reused, its content is not read
//	**      from the database or written to the journal file (why should it
//	**      be, if it is not at all meaningful?).
//	**
//	** By themselves, these optimizations work fine and provide a handy
//	** performance boost to bulk delete or insert operations. However, if
//	** a page is moved to the free-list and then reused within the same
//	** transaction, a problem comes up. If the page is not journalled when
//	** it is moved to the free-list and it is also not journalled when it
//	** is extracted from the free-list and reused, then the original data
//	** may be lost. In the event of a rollback, it may not be possible
//	** to restore the database to its original configuration.
//	**
//	** The solution is the BtShared.pHasContent bitvec. Whenever a page is
//	** moved to become a free-list leaf page, the corresponding bit is
//	** set in the bitvec. Whenever a leaf page is extracted from the free-list,
//	** optimization 2 above is omitted if the corresponding bit is already
//	** set in BtShared.pHasContent. The contents of the bitvec are cleared
//	** at the end of every transaction.
//	*/
func _btreeSetHasContent(tls *libc.TLS, pBt uintptr, pgno TPgno) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if !((*TBtShared)(unsafe.Pointer(pBt)).FpHasContent != 0) {
		(*TBtShared)(unsafe.Pointer(pBt)).FpHasContent = _sqlite3BitvecCreate(tls, (*TBtShared)(unsafe.Pointer(pBt)).FnPage)
		if !((*TBtShared)(unsafe.Pointer(pBt)).FpHasContent != 0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	if rc == SQLITE_OK && pgno <= _sqlite3BitvecSize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpHasContent) {
		rc = _sqlite3BitvecSet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpHasContent, pgno)
	}
	return rc
}

// C documentation
//
//	/*
//	** Query the BtShared.pHasContent vector.
//	**
//	** This function is called when a free-list leaf page is removed from the
//	** free-list for reuse. It returns false if it is safe to retrieve the
//	** page from the pager layer with the 'no-content' flag set. True otherwise.
//	*/
func _btreeGetHasContent(tls *libc.TLS, pBt uintptr, pgno TPgno) (r int32) {
	var p uintptr
	_ = p
	p = (*TBtShared)(unsafe.Pointer(pBt)).FpHasContent
	return libc.BoolInt32(p != 0 && (pgno > _sqlite3BitvecSize(tls, p) || _sqlite3BitvecTestNotNull(tls, p, pgno) != 0))
}

// C documentation
//
//	/*
//	** Clear (destroy) the BtShared.pHasContent bitvec. This should be
//	** invoked at the conclusion of each write-transaction.
//	*/
func _btreeClearHasContent(tls *libc.TLS, pBt uintptr) {
	_sqlite3BitvecDestroy(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpHasContent)
	(*TBtShared)(unsafe.Pointer(pBt)).FpHasContent = uintptr(0)
}

// C documentation
//
//	/*
//	** Release all of the apPage[] pages for a cursor.
//	*/
func _btreeReleaseAllCursorPages(tls *libc.TLS, pCur uintptr) {
	var i int32
	_ = i
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) >= 0 {
		i = 0
		for {
			if !(i < int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)) {
				break
			}
			_releasePageNotNull(tls, *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		_releasePageNotNull(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
		(*TBtCursor)(unsafe.Pointer(pCur)).FiPage = int8(-int32(1))
	}
}

// C documentation
//
//	/*
//	** The cursor passed as the only argument must point to a valid entry
//	** when this function is called (i.e. have eState==CURSOR_VALID). This
//	** function saves the current cursor key in variables pCur->nKey and
//	** pCur->pKey. SQLITE_OK is returned if successful or an SQLite error
//	** code otherwise.
//	**
//	** If the cursor is open on an intkey table, then the integer key
//	** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to
//	** NULL. If the cursor is open on a non-intkey table, then pCur->pKey is
//	** set to point to a malloced buffer pCur->nKey bytes in size containing
//	** the key.
//	*/
func _saveCursorKey(tls *libc.TLS, pCur uintptr) (r int32) {
	var pKey uintptr
	var rc int32
	_, _ = pKey, rc
	rc = SQLITE_OK
	if (*TBtCursor)(unsafe.Pointer(pCur)).FcurIntKey != 0 {
		/* Only the rowid is required for a table btree */
		(*TBtCursor)(unsafe.Pointer(pCur)).FnKey = _sqlite3BtreeIntegerKey(tls, pCur)
	} else {
		(*TBtCursor)(unsafe.Pointer(pCur)).FnKey = int64(_sqlite3BtreePayloadSize(tls, pCur))
		pKey = _sqlite3Malloc(tls, uint64((*TBtCursor)(unsafe.Pointer(pCur)).FnKey+int64(9)+int64(8)))
		if pKey != 0 {
			rc = _sqlite3BtreePayload(tls, pCur, uint32(0), uint32(int32((*TBtCursor)(unsafe.Pointer(pCur)).FnKey)), pKey)
			if rc == SQLITE_OK {
				libc.Xmemset(tls, pKey+uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FnKey), 0, uint32(libc.Int32FromInt32(9)+libc.Int32FromInt32(8)))
				(*TBtCursor)(unsafe.Pointer(pCur)).FpKey = pKey
			} else {
				Xsqlite3_free(tls, pKey)
			}
		} else {
			rc = int32(SQLITE_NOMEM)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Save the current cursor position in the variables BtCursor.nKey
//	** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK.
//	**
//	** The caller must ensure that the cursor is valid (has eState==CURSOR_VALID)
//	** prior to calling this routine.
//	*/
func _saveCursorPosition(tls *libc.TLS, pCur uintptr) (r int32) {
	var rc int32
	var p1 uintptr
	_, _ = rc, p1
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_Pinned) != 0 {
		return libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(11)<<libc.Int32FromInt32(8)
	}
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == int32(CURSOR_SKIPNEXT) {
		(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_VALID)
	} else {
		(*TBtCursor)(unsafe.Pointer(pCur)).FskipNext = 0
	}
	rc = _saveCursorKey(tls, pCur)
	if rc == SQLITE_OK {
		_btreeReleaseAllCursorPages(tls, pCur)
		(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_REQUIRESEEK)
	}
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl) | libc.Int32FromInt32(BTCF_AtLast)))
	return rc
}

// C documentation
//
//	/*
//	** Save the positions of all cursors (except pExcept) that are open on
//	** the table with root-page iRoot.  "Saving the cursor position" means that
//	** the location in the btree is remembered in such a way that it can be
//	** moved back to the same spot after the btree has been modified.  This
//	** routine is called just before cursor pExcept is used to modify the
//	** table, for example in BtreeDelete() or BtreeInsert().
//	**
//	** If there are two or more cursors on the same btree, then all such
//	** cursors should have their BTCF_Multiple flag set.  The btreeCursor()
//	** routine enforces that rule.  This routine only needs to be called in
//	** the uncommon case when pExpect has the BTCF_Multiple flag set.
//	**
//	** If pExpect!=NULL and if no other cursors are found on the same root-page,
//	** then the BTCF_Multiple flag on pExpect is cleared, to avoid another
//	** pointless call to this routine.
//	**
//	** Implementation note:  This routine merely checks to see if any cursors
//	** need to be saved.  It calls out to saveCursorsOnList() in the (unusual)
//	** event that cursors are in need to being saved.
//	*/
func _saveAllCursors(tls *libc.TLS, pBt uintptr, iRoot TPgno, pExcept uintptr) (r int32) {
	var p, p2 uintptr
	_, _ = p, p2
	p = (*TBtShared)(unsafe.Pointer(pBt)).FpCursor
	for {
		if !(p != 0) {
			break
		}
		if p != pExcept && (uint32(0) == iRoot || (*TBtCursor)(unsafe.Pointer(p)).FpgnoRoot == iRoot) {
			break
		}
		goto _1
	_1:
		;
		p = (*TBtCursor)(unsafe.Pointer(p)).FpNext
	}
	if p != 0 {
		return _saveCursorsOnList(tls, p, iRoot, pExcept)
	}
	if pExcept != 0 {
		p2 = pExcept + 1
		*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(BTCF_Multiple))
	}
	return SQLITE_OK
}

// C documentation
//
//	/* This helper routine to saveAllCursors does the actual work of saving
//	** the cursors if and when a cursor is found that actually requires saving.
//	** The common case is that no cursors need to be saved, so this routine is
//	** broken out from its caller to avoid unnecessary stack pointer movement.
//	*/
func _saveCursorsOnList(tls *libc.TLS, p uintptr, iRoot TPgno, pExcept uintptr) (r int32) {
	var rc int32
	_ = rc
	for cond := true; cond; cond = p != 0 {
		if p != pExcept && (uint32(0) == iRoot || (*TBtCursor)(unsafe.Pointer(p)).FpgnoRoot == iRoot) {
			if int32((*TBtCursor)(unsafe.Pointer(p)).FeState) == CURSOR_VALID || int32((*TBtCursor)(unsafe.Pointer(p)).FeState) == int32(CURSOR_SKIPNEXT) {
				rc = _saveCursorPosition(tls, p)
				if SQLITE_OK != rc {
					return rc
				}
			} else {
				_btreeReleaseAllCursorPages(tls, p)
			}
		}
		p = (*TBtCursor)(unsafe.Pointer(p)).FpNext
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Clear the current cursor position.
//	*/
func _sqlite3BtreeClearCursor(tls *libc.TLS, pCur uintptr) {
	Xsqlite3_free(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpKey)
	(*TBtCursor)(unsafe.Pointer(pCur)).FpKey = uintptr(0)
	(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
}

// C documentation
//
//	/*
//	** In this version of BtreeMoveto, pKey is a packed index record
//	** such as is generated by the OP_MakeRecord opcode.  Unpack the
//	** record and then call sqlite3BtreeIndexMoveto() to do the work.
//	*/
func _btreeMoveto(tls *libc.TLS, pCur uintptr, pKey uintptr, nKey Ti64, bias int32, pRes uintptr) (r int32) {
	var pIdxKey, pKeyInfo uintptr
	var rc int32
	_, _, _ = pIdxKey, pKeyInfo, rc /* Unpacked index key */
	if pKey != 0 {
		pKeyInfo = (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo
		pIdxKey = _sqlite3VdbeAllocUnpackedRecord(tls, pKeyInfo)
		if pIdxKey == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		_sqlite3VdbeRecordUnpack(tls, pKeyInfo, int32(int32(nKey)), pKey, pIdxKey)
		if int32((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FnField) == 0 || int32((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FnField) > int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnAllField) {
			rc = _sqlite3CorruptError(tls, int32(71421))
		} else {
			rc = _sqlite3BtreeIndexMoveto(tls, pCur, pIdxKey, pRes)
		}
		_sqlite3DbFree(tls, (*TKeyInfo1)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo)).Fdb, pIdxKey)
	} else {
		pIdxKey = uintptr(0)
		rc = _sqlite3BtreeTableMoveto(tls, pCur, nKey, bias, pRes)
	}
	return rc
}

// C documentation
//
//	/*
//	** Restore the cursor to the position it was in (or as close to as possible)
//	** when saveCursorPosition() was called. Note that this call deletes the
//	** saved position info stored by saveCursorPosition(), so there can be
//	** at most one effective restoreCursorPosition() call after each
//	** saveCursorPosition().
//	*/
func _btreeRestoreCursorPosition(tls *libc.TLS, pCur uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* skipNext at bp+0 */ int32
	_ = rc
	*(*int32)(unsafe.Pointer(bp)) = 0
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == int32(CURSOR_FAULT) {
		return (*TBtCursor)(unsafe.Pointer(pCur)).FskipNext
	}
	(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
	if _sqlite3FaultSim(tls, int32(410)) != 0 {
		rc = int32(SQLITE_IOERR)
	} else {
		rc = _btreeMoveto(tls, pCur, (*TBtCursor)(unsafe.Pointer(pCur)).FpKey, (*TBtCursor)(unsafe.Pointer(pCur)).FnKey, 0, bp)
	}
	if rc == SQLITE_OK {
		Xsqlite3_free(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpKey)
		(*TBtCursor)(unsafe.Pointer(pCur)).FpKey = uintptr(0)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			(*TBtCursor)(unsafe.Pointer(pCur)).FskipNext = *(*int32)(unsafe.Pointer(bp))
		}
		if (*TBtCursor)(unsafe.Pointer(pCur)).FskipNext != 0 && int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID {
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_SKIPNEXT)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Determine whether or not a cursor has moved from the position where
//	** it was last placed, or has been invalidated for any other reason.
//	** Cursors can move when the row they are pointing at is deleted out
//	** from under them, for example.  Cursor might also move if a btree
//	** is rebalanced.
//	**
//	** Calling this routine with a NULL cursor pointer returns false.
//	**
//	** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
//	** back to where it ought to be if this routine returns true.
//	*/
func _sqlite3BtreeCursorHasMoved(tls *libc.TLS, pCur uintptr) (r int32) {
	return libc.BoolInt32(CURSOR_VALID != int32(*(*Tu8)(unsafe.Pointer(pCur))))
}

// C documentation
//
//	/*
//	** Return a pointer to a fake BtCursor object that will always answer
//	** false to the sqlite3BtreeCursorHasMoved() routine above.  The fake
//	** cursor returned must not be used with any other Btree interface.
//	*/
func _sqlite3BtreeFakeValidCursor(tls *libc.TLS) (r uintptr) {
	return uintptr(unsafe.Pointer(&_fakeCursor))
}

var _fakeCursor Tu8

// C documentation
//
//	/*
//	** This routine restores a cursor back to its original position after it
//	** has been moved by some outside activity (such as a btree rebalance or
//	** a row having been deleted out from under the cursor).
//	**
//	** On success, the *pDifferentRow parameter is false if the cursor is left
//	** pointing at exactly the same row.  *pDifferntRow is the row the cursor
//	** was pointing to has been deleted, forcing the cursor to point to some
//	** nearby row.
//	**
//	** This routine should only be called for a cursor that just returned
//	** TRUE from sqlite3BtreeCursorHasMoved().
//	*/
func _sqlite3BtreeCursorRestore(tls *libc.TLS, pCur uintptr, pDifferentRow uintptr) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
		v1 = _btreeRestoreCursorPosition(tls, pCur)
	} else {
		v1 = SQLITE_OK
	}
	rc = v1
	if rc != 0 {
		*(*int32)(unsafe.Pointer(pDifferentRow)) = int32(1)
		return rc
	}
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		*(*int32)(unsafe.Pointer(pDifferentRow)) = int32(1)
	} else {
		*(*int32)(unsafe.Pointer(pDifferentRow)) = 0
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Provide flag hints to the cursor.
//	*/
func _sqlite3BtreeCursorHintFlags(tls *libc.TLS, pCur uintptr, x uint32) {
	(*TBtCursor)(unsafe.Pointer(pCur)).Fhints = uint8(uint8(x))
}

// C documentation
//
//	/*
//	** Given a page number of a regular database page, return the page
//	** number for the pointer-map page that contains the entry for the
//	** input page number.
//	**
//	** Return 0 (not a valid page) for pgno==1 since there is
//	** no pointer map associated with page 1.  The integrity_check logic
//	** requires that ptrmapPageno(*,1)!=1.
//	*/
func _ptrmapPageno(tls *libc.TLS, pBt uintptr, pgno TPgno) (r TPgno) {
	var iPtrMap, ret TPgno
	var nPagesPerMapPage int32
	_, _, _ = iPtrMap, nPagesPerMapPage, ret
	if pgno < uint32(2) {
		return uint32(0)
	}
	nPagesPerMapPage = int32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize/uint32(5) + uint32(1))
	iPtrMap = (pgno - uint32(2)) / uint32(uint32(nPagesPerMapPage))
	ret = iPtrMap*uint32(uint32(nPagesPerMapPage)) + uint32(2)
	if ret == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
		ret++
	}
	return ret
}

// C documentation
//
//	/*
//	** Write an entry into the pointer map.
//	**
//	** This routine updates the pointer map entry for page number 'key'
//	** so that it maps to type 'eType' and parent page number 'pgno'.
//	**
//	** If *pRC is initially non-zero (non-SQLITE_OK) then this routine is
//	** a no-op.  If an error occurs, the appropriate error code is written
//	** into *pRC.
//	*/
func _ptrmapPut(tls *libc.TLS, pBt uintptr, key TPgno, eType Tu8, parent TPgno, pRC uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPtrmap TPgno
	var offset, rc, v1 int32
	var pPtrmap uintptr
	var _ /* pDbPage at bp+0 */ uintptr
	_, _, _, _, _ = iPtrmap, offset, pPtrmap, rc, v1 /* Return code from subfunctions */
	if *(*int32)(unsafe.Pointer(pRC)) != 0 {
		return
	}
	/* The super-journal page number must never be used as a pointer map page */
	if key == uint32(0) {
		*(*int32)(unsafe.Pointer(pRC)) = _sqlite3CorruptError(tls, int32(71619))
		return
	}
	iPtrmap = _ptrmapPageno(tls, pBt, key)
	rc = _sqlite3PagerGet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, iPtrmap, bp, 0)
	if rc != SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRC)) = rc
		return
	}
	if int32(*(*int8)(unsafe.Pointer(_sqlite3PagerGetExtra(tls, *(*uintptr)(unsafe.Pointer(bp)))))) != 0 {
		/* The first byte of the extra data is the MemPage.isInit byte.
		 ** If that byte is set, it means this page is also being used
		 ** as a btree page. */
		*(*int32)(unsafe.Pointer(pRC)) = _sqlite3CorruptError(tls, int32(71632))
		goto ptrmap_exit
	}
	offset = int32(libc.Uint32FromInt32(5) * (key - iPtrmap - libc.Uint32FromInt32(1)))
	if offset < 0 {
		*(*int32)(unsafe.Pointer(pRC)) = _sqlite3CorruptError(tls, int32(71637))
		goto ptrmap_exit
	}
	pPtrmap = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if int32(int32(eType)) != int32(*(*Tu8)(unsafe.Pointer(pPtrmap + uintptr(offset)))) || _sqlite3Get4byte(tls, pPtrmap+uintptr(offset+int32(1))) != parent {
		v1 = _sqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp)))
		rc = v1
		*(*int32)(unsafe.Pointer(pRC)) = v1
		if rc == SQLITE_OK {
			*(*Tu8)(unsafe.Pointer(pPtrmap + uintptr(offset))) = eType
			_sqlite3Put4byte(tls, pPtrmap+uintptr(offset+int32(1)), parent)
		}
	}
	goto ptrmap_exit
ptrmap_exit:
	;
	_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Read an entry from the pointer map.
//	**
//	** This routine retrieves the pointer map entry for page 'key', writing
//	** the type and parent page number to *pEType and *pPgno respectively.
//	** An error code is returned if something goes wrong, otherwise SQLITE_OK.
//	*/
func _ptrmapGet(tls *libc.TLS, pBt uintptr, key TPgno, pEType uintptr, pPgno uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPtrmap, offset, rc int32
	var pPtrmap uintptr
	var _ /* pDbPage at bp+0 */ uintptr
	_, _, _, _ = iPtrmap, offset, pPtrmap, rc
	iPtrmap = int32(_ptrmapPageno(tls, pBt, key))
	rc = _sqlite3PagerGet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, uint32(uint32(iPtrmap)), bp, 0)
	if rc != 0 {
		return rc
	}
	pPtrmap = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
	offset = int32(libc.Uint32FromInt32(5) * (key - uint32(uint32(iPtrmap)) - libc.Uint32FromInt32(1)))
	if offset < 0 {
		_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return _sqlite3CorruptError(tls, int32(71682))
	}
	*(*Tu8)(unsafe.Pointer(pEType)) = *(*Tu8)(unsafe.Pointer(pPtrmap + uintptr(offset)))
	if pPgno != 0 {
		*(*TPgno)(unsafe.Pointer(pPgno)) = _sqlite3Get4byte(tls, pPtrmap+uintptr(offset+int32(1)))
	}
	_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if int32(*(*Tu8)(unsafe.Pointer(pEType))) < int32(1) || int32(*(*Tu8)(unsafe.Pointer(pEType))) > int32(5) {
		return _sqlite3CorruptError(tls, int32(71690))
	}
	return SQLITE_OK
}

/*
** Given a btree page and a cell index (0 means the first cell on
** the page, 1 means the second cell, and so forth) return a pointer
** to the cell content.
**
** findCellPastPtr() does the same except it skips past the initial
** 4-byte child pointer found on interior pages, if there is one.
**
** This routine works only for pages that do not contain overflow cells.
 */

// C documentation
//
//	/*
//	** This is common tail processing for btreeParseCellPtr() and
//	** btreeParseCellPtrIndex() for the case when the cell does not fit entirely
//	** on a single B-tree page.  Make necessary adjustments to the CellInfo
//	** structure.
//	*/
func _btreeParseCellAdjustSizeForOverflow(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	var maxLocal, minLocal, surplus int32
	_, _, _ = maxLocal, minLocal, surplus /* Overflow payload available for local storage */
	minLocal = int32((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)
	maxLocal = int32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal)
	surplus = int32(uint32(uint32(minLocal)) + ((*TCellInfo)(unsafe.Pointer(pInfo)).FnPayload-uint32(uint32(minLocal)))%((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-uint32(4)))
	if surplus <= maxLocal {
		(*TCellInfo)(unsafe.Pointer(pInfo)).FnLocal = uint16(uint16(surplus))
	} else {
		(*TCellInfo)(unsafe.Pointer(pInfo)).FnLocal = uint16(uint16(minLocal))
	}
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnSize = uint16(int32(uint16(t__predefined_ptrdiff_t((*TCellInfo)(unsafe.Pointer(pInfo)).FpPayload+uintptr((*TCellInfo)(unsafe.Pointer(pInfo)).FnLocal))-int32(int32(pCell)))) + int32(4))
}

// C documentation
//
//	/*
//	** Given a record with nPayload bytes of payload stored within btree
//	** page pPage, return the number of bytes of payload stored locally.
//	*/
func _btreePayloadToLocal(tls *libc.TLS, pPage uintptr, nPayload Ti64) (r int32) {
	var maxLocal, minLocal, surplus, v1 int32
	_, _, _, _ = maxLocal, minLocal, surplus, v1 /* Maximum amount of payload held locally */
	maxLocal = int32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal)
	if nPayload <= int64(int64(maxLocal)) {
		return int32(int32(nPayload))
	} else { /* Overflow payload available for local storage */
		minLocal = int32((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)
		surplus = int32(int64(int64(minLocal)) + (nPayload-int64(int64(minLocal)))%int64((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-libc.Uint32FromInt32(4)))
		if surplus <= maxLocal {
			v1 = surplus
		} else {
			v1 = minLocal
		}
		return v1
	}
	return r
}

// C documentation
//
//	/*
//	** The following routines are implementations of the MemPage.xParseCell()
//	** method.
//	**
//	** Parse a cell content block and fill in the CellInfo structure.
//	**
//	** btreeParseCellPtr()        =>   table btree leaf nodes
//	** btreeParseCellNoPayload()  =>   table btree internal nodes
//	** btreeParseCellPtrIndex()   =>   index btree nodes
//	**
//	** There is also a wrapper function btreeParseCell() that works for
//	** all MemPage types and that references the cell by index rather than
//	** by pointer.
//	*/
func _btreeParseCellPtrNoPayload(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	_ = pPage
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnSize = uint16(int32(4) + int32(_sqlite3GetVarint(tls, pCell+4, pInfo)))
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnPayload = uint32(0)
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnLocal = uint16(0)
	(*TCellInfo)(unsafe.Pointer(pInfo)).FpPayload = uintptr(0)
	return
}

func _btreeParseCellPtr(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nPayload Tu32
	var pEnd, pIter, v1, v11, v13, v15, v16, v3, v5, v7, v9 uintptr
	var x, v10, v12, v14, v2, v4, v6, v8 Tu8
	var _ /* iKey at bp+0 */ Tu64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = nPayload, pEnd, pIter, x, v1, v10, v11, v12, v13, v14, v15, v16, v2, v3, v4, v5, v6, v7, v8, v9 /* Extracted Key value */
	pIter = pCell
	/* The next block of code is equivalent to:
	 **
	 **     pIter += getVarint32(pIter, nPayload);
	 **
	 ** The code is inlined to avoid a function call.
	 */
	nPayload = uint32(*(*Tu8)(unsafe.Pointer(pIter)))
	if nPayload >= uint32(0x80) {
		pEnd = pIter + 8
		nPayload &= uint32(0x7f)
		for cond := true; cond; cond = int32(*(*Tu8)(unsafe.Pointer(pIter))) >= int32(0x80) && pIter < pEnd {
			pIter++
			v1 = pIter
			nPayload = nPayload<<libc.Int32FromInt32(7) | uint32(int32(*(*Tu8)(unsafe.Pointer(v1)))&libc.Int32FromInt32(0x7f))
		}
	}
	pIter++
	/* The next block of code is equivalent to:
	 **
	 **     pIter += getVarint(pIter, (u64*)&pInfo->nKey);
	 **
	 ** The code is inlined and the loop is unrolled for performance.
	 ** This routine is a high-runner.
	 */
	*(*Tu64)(unsafe.Pointer(bp)) = uint64(*(*Tu8)(unsafe.Pointer(pIter)))
	if *(*Tu64)(unsafe.Pointer(bp)) >= uint64(0x80) {
		pIter++
		v3 = pIter
		v2 = *(*Tu8)(unsafe.Pointer(v3))
		x = v2
		*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(7) ^ uint64(v2)
		if int32(int32(x)) >= int32(0x80) {
			pIter++
			v5 = pIter
			v4 = *(*Tu8)(unsafe.Pointer(v5))
			x = v4
			*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(7) ^ uint64(v4)
			if int32(int32(x)) >= int32(0x80) {
				pIter++
				v7 = pIter
				v6 = *(*Tu8)(unsafe.Pointer(v7))
				x = v6
				*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(7) ^ uint64(0x10204000) ^ uint64(v6)
				if int32(int32(x)) >= int32(0x80) {
					pIter++
					v9 = pIter
					v8 = *(*Tu8)(unsafe.Pointer(v9))
					x = v8
					*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(7) ^ uint64(0x4000) ^ uint64(v8)
					if int32(int32(x)) >= int32(0x80) {
						pIter++
						v11 = pIter
						v10 = *(*Tu8)(unsafe.Pointer(v11))
						x = v10
						*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(7) ^ uint64(0x4000) ^ uint64(v10)
						if int32(int32(x)) >= int32(0x80) {
							pIter++
							v13 = pIter
							v12 = *(*Tu8)(unsafe.Pointer(v13))
							x = v12
							*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(7) ^ uint64(0x4000) ^ uint64(v12)
							if int32(int32(x)) >= int32(0x80) {
								pIter++
								v15 = pIter
								v14 = *(*Tu8)(unsafe.Pointer(v15))
								x = v14
								*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(7) ^ uint64(0x4000) ^ uint64(v14)
								if int32(int32(x)) >= int32(0x80) {
									pIter++
									v16 = pIter
									*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(8) ^ uint64(0x8000) ^ uint64(*(*Tu8)(unsafe.Pointer(v16)))
								}
							}
						}
					}
				}
			} else {
				*(*Tu64)(unsafe.Pointer(bp)) ^= uint64(0x204000)
			}
		} else {
			*(*Tu64)(unsafe.Pointer(bp)) ^= uint64(0x4000)
		}
	}
	pIter++
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnKey = *(*Ti64)(unsafe.Pointer(bp))
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnPayload = nPayload
	(*TCellInfo)(unsafe.Pointer(pInfo)).FpPayload = pIter
	if nPayload <= uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		/* This is the (easy) common case where the entire payload fits
		 ** on the local page.  No overflow is required.
		 */
		(*TCellInfo)(unsafe.Pointer(pInfo)).FnSize = uint16(nPayload + uint32(uint16(int32(int32(pIter))-int32(int32(pCell)))))
		if int32((*TCellInfo)(unsafe.Pointer(pInfo)).FnSize) < int32(4) {
			(*TCellInfo)(unsafe.Pointer(pInfo)).FnSize = uint16(4)
		}
		(*TCellInfo)(unsafe.Pointer(pInfo)).FnLocal = uint16(uint16(nPayload))
	} else {
		_btreeParseCellAdjustSizeForOverflow(tls, pPage, pCell, pInfo)
	}
}

func _btreeParseCellPtrIndex(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	var nPayload Tu32
	var pEnd, pIter, v1 uintptr
	_, _, _, _ = nPayload, pEnd, pIter, v1 /* Number of bytes of cell payload */
	pIter = pCell + uintptr((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	nPayload = uint32(*(*Tu8)(unsafe.Pointer(pIter)))
	if nPayload >= uint32(0x80) {
		pEnd = pIter + 8
		nPayload &= uint32(0x7f)
		for cond := true; cond; cond = int32(*(*Tu8)(unsafe.Pointer(pIter))) >= int32(0x80) && pIter < pEnd {
			pIter++
			v1 = pIter
			nPayload = nPayload<<libc.Int32FromInt32(7) | uint32(int32(*(*Tu8)(unsafe.Pointer(v1)))&libc.Int32FromInt32(0x7f))
		}
	}
	pIter++
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnKey = int64(int64(nPayload))
	(*TCellInfo)(unsafe.Pointer(pInfo)).FnPayload = nPayload
	(*TCellInfo)(unsafe.Pointer(pInfo)).FpPayload = pIter
	if nPayload <= uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		/* This is the (easy) common case where the entire payload fits
		 ** on the local page.  No overflow is required.
		 */
		(*TCellInfo)(unsafe.Pointer(pInfo)).FnSize = uint16(nPayload + uint32(uint16(int32(int32(pIter))-int32(int32(pCell)))))
		if int32((*TCellInfo)(unsafe.Pointer(pInfo)).FnSize) < int32(4) {
			(*TCellInfo)(unsafe.Pointer(pInfo)).FnSize = uint16(4)
		}
		(*TCellInfo)(unsafe.Pointer(pInfo)).FnLocal = uint16(uint16(nPayload))
	} else {
		_btreeParseCellAdjustSizeForOverflow(tls, pPage, pCell, pInfo)
	}
}

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(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*iCell)))))), pInfo)
}

// C documentation
//
//	/*
//	** The following routines are implementations of the MemPage.xCellSize
//	** method.
//	**
//	** Compute the total number of bytes that a Cell needs in the cell
//	** data area of the btree-page.  The return number includes the cell
//	** data header and the local payload, but not any overflow page or
//	** the space used by the cell pointer.
//	**
//	** cellSizePtrNoPayload()    =>   table internal nodes
//	** cellSizePtrTableLeaf()    =>   table leaf nodes
//	** cellSizePtr()             =>   index internal nodes
//	** cellSizeIdxLeaf()         =>   index leaf nodes
//	*/
func _cellSizePtr(tls *libc.TLS, pPage uintptr, pCell uintptr) (r Tu16) {
	var minLocal int32
	var nSize Tu32
	var pEnd, pIter, v1 uintptr
	_, _, _, _, _ = minLocal, nSize, pEnd, pIter, v1
	pIter = pCell + uintptr(4) /* Size value to return */
	nSize = uint32(*(*Tu8)(unsafe.Pointer(pIter)))
	if nSize >= uint32(0x80) {
		pEnd = pIter + 8
		nSize &= uint32(0x7f)
		for cond := true; cond; cond = int32(*(*Tu8)(unsafe.Pointer(pIter))) >= int32(0x80) && pIter < pEnd {
			pIter++
			v1 = pIter
			nSize = nSize<<libc.Int32FromInt32(7) | uint32(int32(*(*Tu8)(unsafe.Pointer(v1)))&libc.Int32FromInt32(0x7f))
		}
	}
	pIter++
	if nSize <= uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		nSize += uint32(int32(int32(pIter)) - int32(int32(pCell)))
	} else {
		minLocal = int32((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)
		nSize = uint32(uint32(minLocal)) + (nSize-uint32(uint32(minLocal)))%((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-uint32(4))
		if nSize > uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			nSize = uint32(uint32(minLocal))
		}
		nSize += uint32(int32(4) + int32(uint16(int32(int32(pIter))-int32(int32(pCell)))))
	}
	return uint16(uint16(nSize))
}

func _cellSizePtrIdxLeaf(tls *libc.TLS, pPage uintptr, pCell uintptr) (r Tu16) {
	var minLocal int32
	var nSize Tu32
	var pEnd, pIter, v1 uintptr
	_, _, _, _, _ = minLocal, nSize, pEnd, pIter, v1
	pIter = pCell /* Size value to return */
	nSize = uint32(*(*Tu8)(unsafe.Pointer(pIter)))
	if nSize >= uint32(0x80) {
		pEnd = pIter + 8
		nSize &= uint32(0x7f)
		for cond := true; cond; cond = int32(*(*Tu8)(unsafe.Pointer(pIter))) >= int32(0x80) && pIter < pEnd {
			pIter++
			v1 = pIter
			nSize = nSize<<libc.Int32FromInt32(7) | uint32(int32(*(*Tu8)(unsafe.Pointer(v1)))&libc.Int32FromInt32(0x7f))
		}
	}
	pIter++
	if nSize <= uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		nSize += uint32(int32(int32(pIter)) - int32(int32(pCell)))
		if nSize < uint32(4) {
			nSize = uint32(4)
		}
	} else {
		minLocal = int32((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)
		nSize = uint32(uint32(minLocal)) + (nSize-uint32(uint32(minLocal)))%((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-uint32(4))
		if nSize > uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			nSize = uint32(uint32(minLocal))
		}
		nSize += uint32(int32(4) + int32(uint16(int32(int32(pIter))-int32(int32(pCell)))))
	}
	return uint16(uint16(nSize))
}

func _cellSizePtrNoPayload(tls *libc.TLS, pPage uintptr, pCell uintptr) (r Tu16) {
	var pEnd, pIter, v1 uintptr
	_, _, _ = pEnd, pIter, v1
	pIter = pCell + uintptr(4) /* End mark for a varint */
	_ = pPage
	pEnd = pIter + uintptr(9)
	for {
		v1 = pIter
		pIter++
		if !(int32(*(*Tu8)(unsafe.Pointer(v1)))&int32(0x80) != 0 && pIter < pEnd) {
			break
		}
	}
	return uint16(int32(int32(pIter)) - int32(int32(pCell)))
}

func _cellSizePtrTableLeaf(tls *libc.TLS, pPage uintptr, pCell uintptr) (r Tu16) {
	var minLocal int32
	var nSize Tu32
	var pEnd, pIter, v1, v11, v13, v15, v2, v3, v5, v7, v9 uintptr
	var v10, v12, v14, v16, v4, v6, v8 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = minLocal, nSize, pEnd, pIter, v1, v10, v11, v12, v13, v14, v15, v16, v2, v3, v4, v5, v6, v7, v8, v9
	pIter = pCell /* Size value to return */
	nSize = uint32(*(*Tu8)(unsafe.Pointer(pIter)))
	if nSize >= uint32(0x80) {
		pEnd = pIter + 8
		nSize &= uint32(0x7f)
		for cond := true; cond; cond = int32(*(*Tu8)(unsafe.Pointer(pIter))) >= int32(0x80) && pIter < pEnd {
			pIter++
			v1 = pIter
			nSize = nSize<<libc.Int32FromInt32(7) | uint32(int32(*(*Tu8)(unsafe.Pointer(v1)))&libc.Int32FromInt32(0x7f))
		}
	}
	pIter++
	/* pIter now points at the 64-bit integer key value, a variable length
	 ** integer. The following block moves pIter to point at the first byte
	 ** past the end of the key value. */
	v2 = pIter
	pIter++
	if v4 = int32(*(*Tu8)(unsafe.Pointer(v2)))&int32(0x80) != 0; v4 {
		v3 = pIter
		pIter++
	}
	if v6 = v4 && int32(*(*Tu8)(unsafe.Pointer(v3)))&int32(0x80) != 0; v6 {
		v5 = pIter
		pIter++
	}
	if v8 = v6 && int32(*(*Tu8)(unsafe.Pointer(v5)))&int32(0x80) != 0; v8 {
		v7 = pIter
		pIter++
	}
	if v10 = v8 && int32(*(*Tu8)(unsafe.Pointer(v7)))&int32(0x80) != 0; v10 {
		v9 = pIter
		pIter++
	}
	if v12 = v10 && int32(*(*Tu8)(unsafe.Pointer(v9)))&int32(0x80) != 0; v12 {
		v11 = pIter
		pIter++
	}
	if v14 = v12 && int32(*(*Tu8)(unsafe.Pointer(v11)))&int32(0x80) != 0; v14 {
		v13 = pIter
		pIter++
	}
	if v16 = v14 && int32(*(*Tu8)(unsafe.Pointer(v13)))&int32(0x80) != 0; v16 {
		v15 = pIter
		pIter++
	}
	if v16 && int32(*(*Tu8)(unsafe.Pointer(v15)))&int32(0x80) != 0 {
		pIter++
	}
	if nSize <= uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		nSize += uint32(int32(int32(pIter)) - int32(int32(pCell)))
		if nSize < uint32(4) {
			nSize = uint32(4)
		}
	} else {
		minLocal = int32((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)
		nSize = uint32(uint32(minLocal)) + (nSize-uint32(uint32(minLocal)))%((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-uint32(4))
		if nSize > uint32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			nSize = uint32(uint32(minLocal))
		}
		nSize += uint32(int32(4) + int32(uint16(int32(int32(pIter))-int32(int32(pCell)))))
	}
	return uint16(uint16(nSize))
}

// C documentation
//
//	/*
//	** The cell pCell is currently part of page pSrc but will ultimately be part
//	** of pPage.  (pSrc and pPage are often the same.)  If pCell contains a
//	** pointer to an overflow page, insert an entry into the pointer-map for
//	** the overflow page that will be valid after pCell has been moved to pPage.
//	*/
func _ptrmapPutOvflPtr(tls *libc.TLS, pPage uintptr, pSrc uintptr, pCell uintptr, pRC uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ovfl TPgno
	var _ /* info at bp+0 */ TCellInfo
	_ = ovfl
	if *(*int32)(unsafe.Pointer(pRC)) != 0 {
		return
	}
	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, pCell, bp)
	if uint32((*(*TCellInfo)(unsafe.Pointer(bp))).FnLocal) < (*(*TCellInfo)(unsafe.Pointer(bp))).FnPayload {
		if uint32(pCell) < uint32((*TMemPage)(unsafe.Pointer(pSrc)).FaDataEnd) && uint32(pCell+uintptr((*(*TCellInfo)(unsafe.Pointer(bp))).FnLocal)) > uint32((*TMemPage)(unsafe.Pointer(pSrc)).FaDataEnd) {
			*(*int32)(unsafe.Pointer(pRC)) = _sqlite3CorruptError(tls, int32(72130))
			return
		}
		ovfl = _sqlite3Get4byte(tls, pCell+uintptr(int32((*(*TCellInfo)(unsafe.Pointer(bp))).FnSize)-int32(4)))
		_ptrmapPut(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpBt, ovfl, uint8(PTRMAP_OVERFLOW1), (*TMemPage)(unsafe.Pointer(pPage)).Fpgno, pRC)
	}
}

// C documentation
//
//	/*
//	** Defragment the page given. This routine reorganizes cells within the
//	** page so that there are no free-blocks on the free-block list.
//	**
//	** Parameter nMaxFrag is the maximum amount of fragmented space that may be
//	** present in the page after this routine returns.
//	**
//	** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
//	** b-tree page so that there are no freeblocks or fragment bytes, all
//	** unused bytes are contained in the unallocated space region, and all
//	** cells are packed tightly at the end of the page.
//	*/
func _defragmentPage(tls *libc.TLS, pPage uintptr, nMaxFrag int32) (r int32) {
	var cbrk, cellOffset, hdr, i, iCellFirst, iCellLast, iCellStart, iFree, iFree2, nCell, pc, size, sz, sz2, top, usableSize int32
	var data, pAddr, pAddr1, pEnd, src, temp uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cbrk, cellOffset, data, hdr, i, iCellFirst, iCellLast, iCellStart, iFree, iFree2, nCell, pAddr, pAddr1, pEnd, pc, size, src, sz, sz2, temp, top, usableSize /* First cell offset in input */
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
	hdr = int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)
	cellOffset = int32((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset)
	nCell = int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
	iCellFirst = cellOffset + int32(2)*nCell
	usableSize = int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
	/* This block handles pages with two or fewer free blocks and nMaxFrag
	 ** or fewer fragmented bytes. In this case it is faster to move the
	 ** two (or one) blocks of cells using memmove() and add the required
	 ** offsets to each pointer in the cell-pointer array than it is to
	 ** reconstruct the entire page.  */
	if int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(7))))) <= nMaxFrag {
		iFree = int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(1)))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(1)) + 1)))
		if iFree > usableSize-int32(4) {
			return _sqlite3CorruptError(tls, int32(72188))
		}
		if iFree != 0 {
			iFree2 = int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree) + 1)))
			if iFree2 > usableSize-int32(4) {
				return _sqlite3CorruptError(tls, int32(72191))
			}
			if 0 == iFree2 || int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2)))) == 0 && int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2+int32(1))))) == 0 {
				pEnd = data + uintptr(cellOffset+nCell*int32(2))
				sz2 = 0
				sz = int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree+int32(2)))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree+int32(2)) + 1)))
				top = int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(5)))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(5)) + 1)))
				if top >= iFree {
					return _sqlite3CorruptError(tls, int32(72199))
				}
				if iFree2 != 0 {
					if iFree+sz > iFree2 {
						return _sqlite3CorruptError(tls, int32(72202))
					}
					sz2 = int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2+int32(2)))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2+int32(2)) + 1)))
					if iFree2+sz2 > usableSize {
						return _sqlite3CorruptError(tls, int32(72204))
					}
					libc.Xmemmove(tls, data+uintptr(iFree+sz+sz2), data+uintptr(iFree+sz), uint32(iFree2-(iFree+sz)))
					sz += sz2
				} else {
					if iFree+sz > usableSize {
						return _sqlite3CorruptError(tls, int32(72208))
					}
				}
				cbrk = top + sz
				libc.Xmemmove(tls, data+uintptr(cbrk), data+uintptr(top), uint32(iFree-top))
				pAddr = data + uintptr(cellOffset)
				for {
					if !(pAddr < pEnd) {
						break
					}
					pc = int32(*(*Tu8)(unsafe.Pointer(pAddr)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(pAddr + 1)))
					if pc < iFree {
						*(*Tu8)(unsafe.Pointer(pAddr)) = uint8((pc + sz) >> libc.Int32FromInt32(8))
						*(*Tu8)(unsafe.Pointer(pAddr + 1)) = uint8(pc + sz)
					} else {
						if pc < iFree2 {
							*(*Tu8)(unsafe.Pointer(pAddr)) = uint8((pc + sz2) >> libc.Int32FromInt32(8))
							*(*Tu8)(unsafe.Pointer(pAddr + 1)) = uint8(pc + sz2)
						}
					}
					goto _1
				_1:
					;
					pAddr += uintptr(2)
				}
				goto defragment_out
			}
		}
	}
	cbrk = usableSize
	iCellLast = usableSize - int32(4)
	iCellStart = int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(5)))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(5)) + 1)))
	if nCell > 0 {
		temp = _sqlite3PagerTempSpace(tls, (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FpPager)
		libc.Xmemcpy(tls, temp, data, uint32(uint32(usableSize)))
		src = temp
		i = 0
		for {
			if !(i < nCell) {
				break
			} /* The i-th cell pointer */
			pAddr1 = data + uintptr(cellOffset+i*int32(2))
			pc = int32(*(*Tu8)(unsafe.Pointer(pAddr1)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(pAddr1 + 1)))
			/* These conditions have already been verified in btreeInitPage()
			 ** if PRAGMA cell_size_check=ON.
			 */
			if pc > iCellLast {
				return _sqlite3CorruptError(tls, int32(72241))
			}
			size = int32((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, src+uintptr(pc)))
			cbrk -= size
			if cbrk < iCellStart || pc+size > usableSize {
				return _sqlite3CorruptError(tls, int32(72247))
			}
			*(*Tu8)(unsafe.Pointer(pAddr1)) = uint8(cbrk >> libc.Int32FromInt32(8))
			*(*Tu8)(unsafe.Pointer(pAddr1 + 1)) = uint8(cbrk)
			libc.Xmemcpy(tls, data+uintptr(cbrk), src+uintptr(pc), uint32(uint32(size)))
			goto _2
		_2:
			;
			i++
		}
	}
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(7)))) = uint8(0)
	goto defragment_out
defragment_out:
	;
	if int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(7)))))+cbrk-iCellFirst != (*TMemPage)(unsafe.Pointer(pPage)).FnFree {
		return _sqlite3CorruptError(tls, int32(72261))
	}
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(5)))) = uint8(cbrk >> libc.Int32FromInt32(8))
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(5)) + 1)) = uint8(cbrk)
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(1)))) = uint8(0)
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+int32(2)))) = uint8(0)
	libc.Xmemset(tls, data+uintptr(iCellFirst), 0, uint32(cbrk-iCellFirst))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Search the free-list on page pPg for space to store a cell nByte bytes in
//	** size. If one can be found, return a pointer to the space and remove it
//	** from the free-list.
//	**
//	** If no suitable space can be found on the free-list, return NULL.
//	**
//	** This function may detect corruption within pPg.  If corruption is
//	** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
//	**
//	** Slots on the free list that are between 1 and 3 bytes larger than nByte
//	** will be ignored if adding the extra space to the fragmentation count
//	** causes the fragmentation count to exceed 60.
//	*/
func _pageFindSlot(tls *libc.TLS, pPg uintptr, nByte int32, pRc uintptr) (r uintptr) {
	var aData, pTmp, p2 uintptr
	var hdr, iAddr, maxPC, pc, size, x, v1 int32
	_, _, _, _, _, _, _, _, _, _ = aData, hdr, iAddr, maxPC, pTmp, pc, size, x, v1, p2
	hdr = int32((*TMemPage)(unsafe.Pointer(pPg)).FhdrOffset)                                                               /* Offset to page header */
	aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData                                                                        /* Page data */
	iAddr = hdr + int32(1)                                                                                                 /* Address of ptr to pc */
	pTmp = aData + uintptr(iAddr)                                                                                          /* Temporary ptr into aData[] */
	pc = int32(*(*Tu8)(unsafe.Pointer(pTmp)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(pTmp + 1)))                         /* Excess size of the slot */
	maxPC = int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPg)).FpBt)).FusableSize - uint32(uint32(nByte))) /* Size of the free slot */
	for pc <= maxPC {
		/* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
		 ** freeblock form a big-endian integer which is the size of the freeblock
		 ** in bytes, including the 4-byte header. */
		pTmp = aData + uintptr(pc+int32(2))
		size = int32(*(*Tu8)(unsafe.Pointer(pTmp)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(pTmp + 1)))
		v1 = size - nByte
		x = v1
		if v1 >= 0 {
			if x < int32(4) {
				/* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
				 ** number of bytes in fragments may not exceed 60. */
				if int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(7))))) > int32(57) {
					return uintptr(0)
				}
				/* Remove the slot from the free-list. Update the number of
				 ** fragmented bytes within the page. */
				libc.Xmemcpy(tls, aData+uintptr(iAddr), aData+uintptr(pc), uint32(2))
				p2 = aData + uintptr(hdr+int32(7))
				*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) + int32(uint8(uint8(x))))
				return aData + uintptr(pc)
			} else {
				if x+pc > maxPC {
					/* This slot extends off the end of the usable part of the page */
					*(*int32)(unsafe.Pointer(pRc)) = _sqlite3CorruptError(tls, int32(72318))
					return uintptr(0)
				} else {
					/* The slot remains on the free-list. Reduce its size to account
					 ** for the portion used by the new allocation. */
					*(*Tu8)(unsafe.Pointer(aData + uintptr(pc+int32(2)))) = uint8(x >> libc.Int32FromInt32(8))
					*(*Tu8)(unsafe.Pointer(aData + uintptr(pc+int32(2)) + 1)) = uint8(x)
				}
			}
			return aData + uintptr(pc+x)
		}
		iAddr = pc
		pTmp = aData + uintptr(pc)
		pc = int32(*(*Tu8)(unsafe.Pointer(pTmp)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(pTmp + 1)))
		if pc <= iAddr {
			if pc != 0 {
				/* The next slot in the chain comes before the current slot */
				*(*int32)(unsafe.Pointer(pRc)) = _sqlite3CorruptError(tls, int32(72333))
			}
			return uintptr(0)
		}
	}
	if pc > maxPC+nByte-int32(4) {
		/* The free slot chain extends off the end of the page */
		*(*int32)(unsafe.Pointer(pRc)) = _sqlite3CorruptError(tls, int32(72340))
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Allocate nByte bytes of space from within the B-Tree page passed
//	** as the first argument. Write into *pIdx the index into pPage->aData[]
//	** of the first byte of allocated space. Return either SQLITE_OK or
//	** an error code (usually SQLITE_CORRUPT).
//	**
//	** The caller guarantees that there is sufficient space to make the
//	** allocation.  This routine might need to defragment in order to bring
//	** all the space together, however.  This routine will avoid using
//	** the first two bytes past the cell pointer area since presumably this
//	** allocation is being made in order to insert a new cell, so we will
//	** also end up needing a new cell pointer.
//	*/
func _allocateSpace(tls *libc.TLS, pPage uintptr, nByte int32, pIdx uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var data, pSpace, pTmp uintptr
	var g2, gap, hdr, top, v1, v2 int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _ = data, g2, gap, hdr, pSpace, pTmp, top, v1, v2
	hdr = int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset) /* Local cache of pPage->hdrOffset */
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData           /* First byte of cell content area */
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK                  /* First byte of gap between cell pointers and cell content */
	/* Minimum cell size is 4 */
	gap = int32((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset) + int32(2)*int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
	/* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size
	 ** and the reserved space is zero (the usual value for reserved space)
	 ** then the cell content offset of an empty page wants to be 65536.
	 ** However, that integer is too large to be stored in a 2-byte unsigned
	 ** integer, so a value of 0 is used in its place. */
	pTmp = data + uintptr(hdr+int32(5))
	top = int32(*(*Tu8)(unsafe.Pointer(pTmp)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(pTmp + 1)))
	if gap > top {
		if top == 0 && (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize == uint32(65536) {
			top = int32(65536)
		} else {
			return _sqlite3CorruptError(tls, int32(72388))
		}
	} else {
		if top > int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) {
			return _sqlite3CorruptError(tls, int32(72391))
		}
	}
	/* If there is enough space between gap and top for one more cell pointer,
	 ** and if the freelist is not empty, then search the
	 ** freelist looking for a slot big enough to satisfy the request.
	 */
	if (*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(2)))) != 0 || *(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(1)))) != 0) && gap+int32(2) <= top {
		pSpace = _pageFindSlot(tls, pPage, nByte, bp)
		if pSpace != 0 {
			v1 = int32(int32(pSpace)) - int32(int32(data))
			g2 = v1
			*(*int32)(unsafe.Pointer(pIdx)) = v1
			if g2 <= gap {
				return _sqlite3CorruptError(tls, int32(72408))
			} else {
				return SQLITE_OK
			}
		} else {
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				return *(*int32)(unsafe.Pointer(bp))
			}
		}
	}
	/* The request could not be fulfilled using a freelist slot.  Check
	 ** to see if defragmentation is necessary.
	 */
	if gap+int32(2)+nByte > top {
		if int32(4) < (*TMemPage)(unsafe.Pointer(pPage)).FnFree-(int32(2)+nByte) {
			v2 = int32(4)
		} else {
			v2 = (*TMemPage)(unsafe.Pointer(pPage)).FnFree - (int32(2) + nByte)
		}
		*(*int32)(unsafe.Pointer(bp)) = _defragmentPage(tls, pPage, v2)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(bp))
		}
		top = (int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(5)))))<<libc.Int32FromInt32(8)|int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(5)) + 1)))-int32(1))&int32(0xffff) + int32(1)
	}
	/* Allocate memory from the gap in between the cell pointer array
	 ** and the cell content area.  The btreeComputeFreeSpace() call has already
	 ** validated the freelist.  Given that the freelist is valid, there
	 ** is no way that the allocation can extend off the end of the page.
	 ** The assert() below verifies the previous sentence.
	 */
	top -= nByte
	*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(5)))) = uint8(top >> libc.Int32FromInt32(8))
	*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(5)) + 1)) = uint8(top)
	*(*int32)(unsafe.Pointer(pIdx)) = top
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return a section of the pPage->aData to the freelist.
//	** The first byte of the new free block is pPage->aData[iStart]
//	** and the size of the block is iSize bytes.
//	**
//	** Adjacent freeblocks are coalesced.
//	**
//	** Even though the freeblock list was checked by btreeComputeFreeSpace(),
//	** that routine will not detect overlap between cells or freeblocks.  Nor
//	** does it detect cells or freeblocks that encroach into the reserved bytes
//	** at the end of the page.  So do additional corruption checks inside this
//	** routine and return SQLITE_CORRUPT if any problems are found.
//	*/
func _freeSpace(tls *libc.TLS, pPage uintptr, iStart Tu16, iSize Tu16) (r int32) {
	var data, pTmp, p2 uintptr
	var hdr, nFrag Tu8
	var iEnd Tu32
	var iFreeBlk, iOrigSize, iPtr, x, v1 Tu16
	var iPtrEnd int32
	_, _, _, _, _, _, _, _, _, _, _, _ = data, hdr, iEnd, iFreeBlk, iOrigSize, iPtr, iPtrEnd, nFrag, pTmp, x, v1, p2 /* Page header size.  0 or 100 */
	nFrag = uint8(0)                                                                                                 /* Reduction in fragmentation */
	iOrigSize = iSize                                                                                                /* Offset to cell content area */
	iEnd = uint32(int32(int32(iStart)) + int32(int32(iSize)))                                                        /* First byte past the iStart buffer */
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData                                                                 /* Temporary ptr into data[] */
	/* Minimum cell size is 4 */
	/* The list of freeblocks must be in ascending order.  Find the
	 ** spot on the list where iStart should be inserted.
	 */
	hdr = (*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset
	iPtr = uint16(int32(int32(hdr)) + int32(1))
	if int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(iPtr))+int32(1))))) == 0 && int32(*(*uint8)(unsafe.Pointer(data + uintptr(iPtr)))) == 0 {
		iFreeBlk = uint16(0) /* Shortcut for the case when the freelist is empty */
	} else {
		for {
			v1 = uint16(int32(*(*uint8)(unsafe.Pointer(data + uintptr(iPtr))))<<libc.Int32FromInt32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iPtr) + 1))))
			iFreeBlk = v1
			if !(int32(v1) < int32(int32(iStart))) {
				break
			}
			if int32(int32(iFreeBlk)) <= int32(int32(iPtr)) {
				if int32(int32(iFreeBlk)) == 0 {
					break
				} /* TH3: corrupt082.100 */
				return _sqlite3CorruptError(tls, int32(72487))
			}
			iPtr = iFreeBlk
		}
		if uint32(uint32(iFreeBlk)) > (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-uint32(4) { /* TH3: corrupt081.100 */
			return _sqlite3CorruptError(tls, int32(72492))
		}
		/* At this point:
		 **    iFreeBlk:   First freeblock after iStart, or zero if none
		 **    iPtr:       The address of a pointer to iFreeBlk
		 **
		 ** Check to see if iFreeBlk should be coalesced onto the end of iStart.
		 */
		if iFreeBlk != 0 && iEnd+uint32(3) >= uint32(uint32(iFreeBlk)) {
			nFrag = uint8(uint32(uint32(iFreeBlk)) - iEnd)
			if iEnd > uint32(uint32(iFreeBlk)) {
				return _sqlite3CorruptError(tls, int32(72504))
			}
			iEnd = uint32(int32(int32(iFreeBlk)) + (int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(iFreeBlk))+int32(2)))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(iFreeBlk))+int32(2)) + 1)))))
			if iEnd > (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize {
				return _sqlite3CorruptError(tls, int32(72507))
			}
			iSize = uint16(iEnd - uint32(uint32(iStart)))
			iFreeBlk = uint16(int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFreeBlk))))<<libc.Int32FromInt32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFreeBlk) + 1))))
		}
		/* If iPtr is another freeblock (that is, if iPtr is not the freelist
		 ** pointer in the page header) then check to see if iStart should be
		 ** coalesced onto the end of iPtr.
		 */
		if int32(int32(iPtr)) > int32(int32(hdr))+int32(1) {
			iPtrEnd = int32(int32(iPtr)) + (int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(iPtr))+int32(2)))))<<int32(8) | int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(iPtr))+int32(2)) + 1))))
			if iPtrEnd+int32(3) >= int32(int32(iStart)) {
				if iPtrEnd > int32(int32(iStart)) {
					return _sqlite3CorruptError(tls, int32(72520))
				}
				nFrag = Tu8(int32(nFrag) + (int32(int32(iStart)) - iPtrEnd))
				iSize = uint16(iEnd - uint32(uint32(iPtr)))
				iStart = iPtr
			}
		}
		if int32(int32(nFrag)) > int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(7))))) {
			return _sqlite3CorruptError(tls, int32(72526))
		}
		p2 = data + uintptr(int32(int32(hdr))+int32(7))
		*(*uint8)(unsafe.Pointer(p2)) = uint8(int32(*(*uint8)(unsafe.Pointer(p2))) - int32(int32(nFrag)))
	}
	pTmp = data + uintptr(int32(int32(hdr))+int32(5))
	x = uint16(int32(*(*Tu8)(unsafe.Pointer(pTmp)))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(pTmp + 1))))
	if int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FbtsFlags)&int32(BTS_FAST_SECURE) != 0 {
		/* Overwrite deleted information with zeros when the secure_delete
		 ** option is enabled */
		libc.Xmemset(tls, data+uintptr(iStart), 0, uint32(uint32(iSize)))
	}
	if int32(int32(iStart)) <= int32(int32(x)) {
		/* The new freeblock is at the beginning of the cell content area,
		 ** so just extend the cell content area rather than create another
		 ** freelist entry */
		if int32(int32(iStart)) < int32(int32(x)) {
			return _sqlite3CorruptError(tls, int32(72540))
		}
		if int32(int32(iPtr)) != int32(int32(hdr))+int32(1) {
			return _sqlite3CorruptError(tls, int32(72541))
		}
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(1)))) = uint8(int32(iFreeBlk) >> libc.Int32FromInt32(8))
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(1)) + 1)) = uint8(iFreeBlk)
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(5)))) = uint8(iEnd >> libc.Int32FromInt32(8))
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(5)) + 1)) = uint8(iEnd)
	} else {
		/* Insert the new freeblock into the freelist */
		*(*uint8)(unsafe.Pointer(data + uintptr(iPtr))) = uint8(int32(iStart) >> libc.Int32FromInt32(8))
		*(*uint8)(unsafe.Pointer(data + uintptr(iPtr) + 1)) = uint8(iStart)
		*(*uint8)(unsafe.Pointer(data + uintptr(iStart))) = uint8(int32(iFreeBlk) >> libc.Int32FromInt32(8))
		*(*uint8)(unsafe.Pointer(data + uintptr(iStart) + 1)) = uint8(iFreeBlk)
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(iStart))+int32(2)))) = uint8(int32(iSize) >> libc.Int32FromInt32(8))
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(iStart))+int32(2)) + 1)) = uint8(iSize)
	}
	*(*int32)(unsafe.Pointer(pPage + 20)) += int32(int32(iOrigSize))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Decode the flags byte (the first byte of the header) for a page
//	** and initialize fields of the MemPage structure accordingly.
//	**
//	** Only the following combinations are supported.  Anything different
//	** indicates a corrupt database files:
//	**
//	**         PTF_ZERODATA                             (0x02,  2)
//	**         PTF_LEAFDATA | PTF_INTKEY                (0x05,  5)
//	**         PTF_ZERODATA | PTF_LEAF                  (0x0a, 10)
//	**         PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF     (0x0d, 13)
//	*/
func _decodeFlags(tls *libc.TLS, pPage uintptr, flagByte int32) (r int32) {
	var pBt uintptr
	_ = pBt /* A copy of pPage->pBt */
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt
	(*TMemPage)(unsafe.Pointer(pPage)).Fmax1bytePayload = (*TBtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload
	if flagByte >= libc.Int32FromInt32(PTF_ZERODATA)|libc.Int32FromInt32(PTF_LEAF) {
		(*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize = uint8(0)
		(*TMemPage)(unsafe.Pointer(pPage)).Fleaf = uint8(1)
		if flagByte == libc.Int32FromInt32(PTF_LEAFDATA)|libc.Int32FromInt32(PTF_INTKEY)|libc.Int32FromInt32(PTF_LEAF) {
			(*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = uint8(1)
			(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize = __ccgo_fp(_cellSizePtrTableLeaf)
			(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell = __ccgo_fp(_btreeParseCellPtr)
			(*TMemPage)(unsafe.Pointer(pPage)).FintKey = uint8(1)
			(*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*TBtShared)(unsafe.Pointer(pBt)).FmaxLeaf
			(*TMemPage)(unsafe.Pointer(pPage)).FminLocal = (*TBtShared)(unsafe.Pointer(pBt)).FminLeaf
		} else {
			if flagByte == libc.Int32FromInt32(PTF_ZERODATA)|libc.Int32FromInt32(PTF_LEAF) {
				(*TMemPage)(unsafe.Pointer(pPage)).FintKey = uint8(0)
				(*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = uint8(0)
				(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize = __ccgo_fp(_cellSizePtrIdxLeaf)
				(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell = __ccgo_fp(_btreeParseCellPtrIndex)
				(*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal
				(*TMemPage)(unsafe.Pointer(pPage)).FminLocal = (*TBtShared)(unsafe.Pointer(pBt)).FminLocal
			} else {
				(*TMemPage)(unsafe.Pointer(pPage)).FintKey = uint8(0)
				(*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = uint8(0)
				(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize = __ccgo_fp(_cellSizePtrIdxLeaf)
				(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell = __ccgo_fp(_btreeParseCellPtrIndex)
				return _sqlite3CorruptError(tls, int32(72595))
			}
		}
	} else {
		(*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize = uint8(4)
		(*TMemPage)(unsafe.Pointer(pPage)).Fleaf = uint8(0)
		if flagByte == int32(PTF_ZERODATA) {
			(*TMemPage)(unsafe.Pointer(pPage)).FintKey = uint8(0)
			(*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = uint8(0)
			(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize = __ccgo_fp(_cellSizePtr)
			(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell = __ccgo_fp(_btreeParseCellPtrIndex)
			(*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal
			(*TMemPage)(unsafe.Pointer(pPage)).FminLocal = (*TBtShared)(unsafe.Pointer(pBt)).FminLocal
		} else {
			if flagByte == libc.Int32FromInt32(PTF_LEAFDATA)|libc.Int32FromInt32(PTF_INTKEY) {
				(*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = uint8(0)
				(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize = __ccgo_fp(_cellSizePtrNoPayload)
				(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell = __ccgo_fp(_btreeParseCellPtrNoPayload)
				(*TMemPage)(unsafe.Pointer(pPage)).FintKey = uint8(1)
				(*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*TBtShared)(unsafe.Pointer(pBt)).FmaxLeaf
				(*TMemPage)(unsafe.Pointer(pPage)).FminLocal = (*TBtShared)(unsafe.Pointer(pBt)).FminLeaf
			} else {
				(*TMemPage)(unsafe.Pointer(pPage)).FintKey = uint8(0)
				(*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = uint8(0)
				(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize = __ccgo_fp(_cellSizePtr)
				(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell = __ccgo_fp(_btreeParseCellPtrIndex)
				return _sqlite3CorruptError(tls, int32(72619))
			}
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Compute the amount of freespace on the page.  In other words, fill
//	** in the pPage->nFree field.
//	*/
func _btreeComputeFreeSpace(tls *libc.TLS, pPage uintptr) (r int32) {
	var data uintptr
	var hdr Tu8
	var iCellFirst, iCellLast, nFree, pc, top, usableSize int32
	var next, size Tu32
	_, _, _, _, _, _, _, _, _, _ = data, hdr, iCellFirst, iCellLast, nFree, next, pc, size, top, usableSize /* Last possible cell or freeblock offset */
	usableSize = int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
	hdr = (*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
	/* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
	 ** the start of the cell content area. A zero value for this integer is
	 ** interpreted as 65536. */
	top = (int32(*(*Tu8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(5)))))<<libc.Int32FromInt32(8)|int32(*(*Tu8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(5)) + 1)))-int32(1))&int32(0xffff) + int32(1)
	iCellFirst = int32(int32(hdr)) + int32(8) + int32((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize) + int32(2)*int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
	iCellLast = usableSize - int32(4)
	/* Compute the total free space on the page
	 ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
	 ** start of the first freeblock on the page, or is zero if there are no
	 ** freeblocks. */
	pc = int32(*(*Tu8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(1)))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(1)) + 1)))
	nFree = int32(*(*Tu8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(7))))) + top /* Init nFree to non-freeblock free space */
	if pc > 0 {
		if pc < top {
			/* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
			 ** always be at least one cell before the first freeblock.
			 */
			return _sqlite3CorruptError(tls, int32(72670))
		}
		for int32(1) != 0 {
			if pc > iCellLast {
				/* Freeblock off the end of the page */
				return _sqlite3CorruptError(tls, int32(72675))
			}
			next = uint32(int32(*(*Tu8)(unsafe.Pointer(data + uintptr(pc))))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(data + uintptr(pc) + 1))))
			size = uint32(int32(*(*Tu8)(unsafe.Pointer(data + uintptr(pc+int32(2)))))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(data + uintptr(pc+int32(2)) + 1))))
			nFree = int32(uint32(uint32(nFree)) + size)
			if next <= uint32(uint32(pc))+size+uint32(3) {
				break
			}
			pc = int32(int32(next))
		}
		if next > uint32(0) {
			/* Freeblock not in ascending order */
			return _sqlite3CorruptError(tls, int32(72685))
		}
		if uint32(uint32(pc))+size > uint32(uint32(usableSize)) {
			/* Last freeblock extends past page end */
			return _sqlite3CorruptError(tls, int32(72689))
		}
	}
	/* At this point, nFree contains the sum of the offset to the start
	 ** of the cell-content area plus the number of free bytes within
	 ** the cell-content area. If this is greater than the usable-size
	 ** of the page, then the page must be corrupted. This check also
	 ** serves to verify that the offset to the start of the cell-content
	 ** area, according to the page header, lies within the page.
	 */
	if nFree > usableSize || nFree < iCellFirst {
		return _sqlite3CorruptError(tls, int32(72701))
	}
	(*TMemPage)(unsafe.Pointer(pPage)).FnFree = int32(uint16(nFree - iCellFirst))
	return SQLITE_OK
}

// 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 = int32((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset) + int32(2)*int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
	usableSize = int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
	iCellLast = usableSize - int32(4)
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
	cellOffset = int32((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset)
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		iCellLast--
	}
	i = 0
	for {
		if !(i < int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)) {
			break
		}
		pc = int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer(data + uintptr(cellOffset+i*int32(2))))))
		if pc < iCellFirst || pc > iCellLast {
			return _sqlite3CorruptError(tls, int32(72732))
		}
		sz = int32((*(*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(72737))
		}
		goto _1
	_1:
		;
		i++
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Initialize the auxiliary information for a disk block.
//	**
//	** Return SQLITE_OK on success.  If we see that the page does
//	** not contain a well-formed database page, then return
//	** SQLITE_CORRUPT.  Note that a return of SQLITE_OK does not
//	** guarantee that the page is well-formed.  It only shows that
//	** we failed to detect any corruption.
//	*/
func _btreeInitPage(tls *libc.TLS, pPage uintptr) (r int32) {
	var data, pBt uintptr
	_, _ = data, pBt /* The main btree structure */
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)
	/* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
	 ** the b-tree page type. */
	if _decodeFlags(tls, pPage, int32(*(*Tu8)(unsafe.Pointer(data)))) != 0 {
		return _sqlite3CorruptError(tls, int32(72769))
	}
	(*TMemPage)(unsafe.Pointer(pPage)).FmaskPage = uint16((*TBtShared)(unsafe.Pointer(pBt)).FpageSize - libc.Uint32FromInt32(1))
	(*TMemPage)(unsafe.Pointer(pPage)).FnOverflow = uint8(0)
	(*TMemPage)(unsafe.Pointer(pPage)).FcellOffset = uint16(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset) + int32(8) + int32((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize))
	(*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx = data + uintptr((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize) + uintptr(8)
	(*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr((*TBtShared)(unsafe.Pointer(pBt)).FpageSize)
	(*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
	 ** number of cells on the page. */
	(*TMemPage)(unsafe.Pointer(pPage)).FnCell = uint16(int32(*(*Tu8)(unsafe.Pointer(data + 3)))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(data + 3 + 1))))
	if uint32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) > ((*TBtShared)(unsafe.Pointer(pBt)).FpageSize-uint32(8))/uint32(6) {
		/* To many cells for a single page.  The page must be corrupt */
		return _sqlite3CorruptError(tls, int32(72783))
	}
	/* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
	 ** possible for a root page of a table that contains no rows) then the
	 ** offset to the cell content area will equal the page size minus the
	 ** bytes of reserved space. */
	(*TMemPage)(unsafe.Pointer(pPage)).FnFree = -int32(1) /* Indicate that this value is yet uncomputed */
	(*TMemPage)(unsafe.Pointer(pPage)).FisInit = uint8(1)
	if (*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags&uint64(SQLITE_CellSizeCk) != 0 {
		return _btreeCellSizeCheck(tls, pPage)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Set up a raw page so that it looks like a database page holding
//	** no entries.
//	*/
func _zeroPage(tls *libc.TLS, pPage uintptr, flags int32) {
	var data, pBt uintptr
	var first Tu16
	var hdr Tu8
	var v1 int32
	_, _, _, _, _ = data, first, hdr, pBt, v1
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt
	hdr = (*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_FAST_SECURE) != 0 {
		libc.Xmemset(tls, data+uintptr(hdr), 0, (*TBtShared)(unsafe.Pointer(pBt)).FusableSize-uint32(uint32(hdr)))
	}
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr))) = uint8(int8(int8(flags)))
	if flags&int32(PTF_LEAF) == 0 {
		v1 = int32(12)
	} else {
		v1 = int32(8)
	}
	first = uint16(int32(int32(hdr)) + v1)
	libc.Xmemset(tls, data+uintptr(int32(int32(hdr))+int32(1)), 0, uint32(4))
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(7)))) = uint8(0)
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(5)))) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FusableSize >> libc.Int32FromInt32(8))
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(int32(hdr))+int32(5)) + 1)) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FusableSize)
	(*TMemPage)(unsafe.Pointer(pPage)).FnFree = int32(uint16((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(uint32(first))))
	_decodeFlags(tls, pPage, flags)
	(*TMemPage)(unsafe.Pointer(pPage)).FcellOffset = first
	(*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd = data + uintptr((*TBtShared)(unsafe.Pointer(pBt)).FpageSize)
	(*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx = data + uintptr(first)
	(*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst = data + uintptr((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	(*TMemPage)(unsafe.Pointer(pPage)).FnOverflow = uint8(0)
	(*TMemPage)(unsafe.Pointer(pPage)).FmaskPage = uint16((*TBtShared)(unsafe.Pointer(pBt)).FpageSize - libc.Uint32FromInt32(1))
	(*TMemPage)(unsafe.Pointer(pPage)).FnCell = uint16(0)
	(*TMemPage)(unsafe.Pointer(pPage)).FisInit = uint8(1)
}

// C documentation
//
//	/*
//	** Convert a DbPage obtained from the pager into a MemPage used by
//	** the btree layer.
//	*/
func _btreePageFromDbPage(tls *libc.TLS, pDbPage uintptr, pgno TPgno, pBt uintptr) (r uintptr) {
	var pPage uintptr
	var v1 int32
	_, _ = pPage, v1
	pPage = _sqlite3PagerGetExtra(tls, pDbPage)
	if pgno != (*TMemPage)(unsafe.Pointer(pPage)).Fpgno {
		(*TMemPage)(unsafe.Pointer(pPage)).FaData = _sqlite3PagerGetData(tls, pDbPage)
		(*TMemPage)(unsafe.Pointer(pPage)).FpDbPage = pDbPage
		(*TMemPage)(unsafe.Pointer(pPage)).FpBt = pBt
		(*TMemPage)(unsafe.Pointer(pPage)).Fpgno = pgno
		if pgno == uint32(1) {
			v1 = int32(100)
		} else {
			v1 = 0
		}
		(*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset = uint8(v1)
	}
	return pPage
}

// C documentation
//
//	/*
//	** Get a page from the pager.  Initialize the MemPage.pBt and
//	** MemPage.aData elements if needed.  See also: btreeGetUnusedPage().
//	**
//	** If the PAGER_GET_NOCONTENT flag is set, it means that we do not care
//	** about the content of the page at this time.  So do not go to the disk
//	** to fetch the content.  Just fill in the content with zeros for now.
//	** If in the future we call sqlite3PagerWrite() on this page, that
//	** means we have started to be concerned about content and the disk
//	** read should occur at that point.
//	*/
func _btreeGetPage(tls *libc.TLS, pBt uintptr, pgno TPgno, ppPage uintptr, flags int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pDbPage at bp+0 */ uintptr
	_ = rc
	rc = _sqlite3PagerGet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pgno, bp, flags)
	if rc != 0 {
		return rc
	}
	*(*uintptr)(unsafe.Pointer(ppPage)) = _btreePageFromDbPage(tls, *(*uintptr)(unsafe.Pointer(bp)), pgno, pBt)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Retrieve a page from the pager cache. If the requested page is not
//	** already in the pager cache return NULL. Initialize the MemPage.pBt and
//	** MemPage.aData elements if needed.
//	*/
func _btreePageLookup(tls *libc.TLS, pBt uintptr, pgno TPgno) (r uintptr) {
	var pDbPage uintptr
	_ = pDbPage
	pDbPage = _sqlite3PagerLookup(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pgno)
	if pDbPage != 0 {
		return _btreePageFromDbPage(tls, pDbPage, pgno, pBt)
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Return the size of the database file in pages. If there is any kind of
//	** error, return ((unsigned int)-1).
//	*/
func _btreePagecount(tls *libc.TLS, pBt uintptr) (r TPgno) {
	return (*TBtShared)(unsafe.Pointer(pBt)).FnPage
}

func _sqlite3BtreeLastPage(tls *libc.TLS, p uintptr) (r TPgno) {
	return _btreePagecount(tls, (*TBtree)(unsafe.Pointer(p)).FpBt)
}

// C documentation
//
//	/*
//	** Get a page from the pager and initialize it.
//	*/
func _getAndInitPage(tls *libc.TLS, pBt uintptr, pgno TPgno, ppPage uintptr, bReadOnly int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pPage uintptr
	var rc int32
	var _ /* pDbPage at bp+0 */ uintptr
	_, _ = pPage, rc
	if pgno > _btreePagecount(tls, pBt) {
		*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
		return _sqlite3CorruptError(tls, int32(72926))
	}
	rc = _sqlite3PagerGet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pgno, bp, bReadOnly)
	if rc != 0 {
		*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
		return rc
	}
	pPage = _sqlite3PagerGetExtra(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if int32((*TMemPage)(unsafe.Pointer(pPage)).FisInit) == 0 {
		_btreePageFromDbPage(tls, *(*uintptr)(unsafe.Pointer(bp)), pgno, pBt)
		rc = _btreeInitPage(tls, pPage)
		if rc != SQLITE_OK {
			_releasePage(tls, pPage)
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return rc
		}
	}
	*(*uintptr)(unsafe.Pointer(ppPage)) = pPage
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Release a MemPage.  This should be called once for each prior
//	** call to btreeGetPage.
//	**
//	** Page1 is a special case and must be released using releasePageOne().
//	*/
func _releasePageNotNull(tls *libc.TLS, pPage uintptr) {
	_sqlite3PagerUnrefNotNull(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
}

func _releasePage(tls *libc.TLS, pPage uintptr) {
	if pPage != 0 {
		_releasePageNotNull(tls, pPage)
	}
}

func _releasePageOne(tls *libc.TLS, pPage uintptr) {
	_sqlite3PagerUnrefPageOne(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
}

// C documentation
//
//	/*
//	** Get an unused page.
//	**
//	** This works just like btreeGetPage() with the addition:
//	**
//	**   *  If the page is already in use for some other purpose, immediately
//	**      release it and return an SQLITE_CURRUPT error.
//	**   *  Make sure the isInit flag is clear
//	*/
func _btreeGetUnusedPage(tls *libc.TLS, pBt uintptr, pgno TPgno, ppPage uintptr, flags int32) (r int32) {
	var rc int32
	_ = rc
	rc = _btreeGetPage(tls, pBt, pgno, ppPage, flags)
	if rc == SQLITE_OK {
		if _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FpDbPage) > int32(1) {
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return _sqlite3CorruptError(tls, int32(72998))
		}
		(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FisInit = uint8(0)
	} else {
		*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** During a rollback, when the pager reloads information into the cache
//	** so that the cache is restored to its original state at the start of
//	** the transaction, for each page restored this routine is called.
//	**
//	** This routine needs to reset the extra data section at the end of the
//	** page to agree with the restored data.
//	*/
func _pageReinit(tls *libc.TLS, pData uintptr) {
	var pPage uintptr
	_ = pPage
	pPage = _sqlite3PagerGetExtra(tls, pData)
	if (*TMemPage)(unsafe.Pointer(pPage)).FisInit != 0 {
		(*TMemPage)(unsafe.Pointer(pPage)).FisInit = uint8(0)
		if _sqlite3PagerPageRefcount(tls, pData) > int32(1) {
			/* pPage might not be a btree page;  it might be an overflow page
			 ** or ptrmap page or a free page.  In those cases, the following
			 ** call to btreeInitPage() will likely return SQLITE_CORRUPT.
			 ** But no harm is done by this.  And it is very important that
			 ** btreeInitPage() be called on every btree page so we make
			 ** the call for every page that comes in for re-initializing. */
			_btreeInitPage(tls, pPage)
		}
	}
}

// C documentation
//
//	/*
//	** Invoke the busy handler for a btree.
//	*/
func _btreeInvokeBusyHandler(tls *libc.TLS, pArg uintptr) (r int32) {
	var pBt uintptr
	_ = pBt
	pBt = pArg
	return _sqlite3InvokeBusyHandler(tls, (*TBtShared)(unsafe.Pointer(pBt)).Fdb+464)
}

// C documentation
//
//	/*
//	** Open a database file.
//	**
//	** zFilename is the name of the database file.  If zFilename is NULL
//	** then an ephemeral database is created.  The ephemeral database might
//	** be exclusively in memory, or it might use a disk-based memory cache.
//	** Either way, the ephemeral database will be automatically deleted
//	** when sqlite3BtreeClose() is called.
//	**
//	** If zFilename is ":memory:" then an in-memory database is created
//	** that is automatically destroyed when it is closed.
//	**
//	** The "flags" parameter is a bitmask that might contain bits like
//	** BTREE_OMIT_JOURNAL and/or BTREE_MEMORY.
//	**
//	** If the database is already opened in the same database connection
//	** and we are in shared cache mode, then the open will fail with an
//	** SQLITE_CONSTRAINT error.  We cannot allow two or more BtShared
//	** objects in the same database connection since doing so will lead
//	** to problems with locking.
//	*/
func _sqlite3BtreeOpen(tls *libc.TLS, pVfs uintptr, zFilename uintptr, db uintptr, ppBtree uintptr, flags int32, vfsFlags int32) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var i, iDb, isMemdb, isTempDb, nFilename, nFullPathname, rc, v1, v6, v7 int32
	var mutexOpen, mutexShared, mutexShared1, p, pBt, pExisting, pFile, pSib, zFullPathname, v9, p4, p5 uintptr
	var nReserve Tu8
	var _ /* zDbHeader at bp+0 */ [100]uint8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iDb, isMemdb, isTempDb, mutexOpen, mutexShared, mutexShared1, nFilename, nFullPathname, nReserve, p, pBt, pExisting, pFile, pSib, rc, zFullPathname, v1, v6, v7, v9, p4, p5
	pBt = uintptr(0)       /* Handle to return */
	mutexOpen = uintptr(0) /* Prevents a race condition. Ticket #3537 */
	rc = SQLITE_OK         /* Database header content */
	/* True if opening an ephemeral, temporary database */
	isTempDb = libc.BoolInt32(zFilename == uintptr(0) || int32(*(*int8)(unsafe.Pointer(zFilename))) == 0)
	/* Set the variable isMemdb to true for an in-memory database, or
	 ** false for a file-based database.
	 */
	isMemdb = libc.BoolInt32(zFilename != 0 && libc.Xstrcmp(tls, zFilename, __ccgo_ts+5563) == 0 || isTempDb != 0 && _sqlite3TempInMemory(tls, db) != 0 || vfsFlags&int32(SQLITE_OPEN_MEMORY) != 0)
	/* flags fit in 8 bits */
	/* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
	/* A BTREE_SINGLE database is always a temporary and/or ephemeral */
	if isMemdb != 0 {
		flags |= int32(BTREE_MEMORY)
	}
	if vfsFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 && (isMemdb != 0 || isTempDb != 0) {
		vfsFlags = vfsFlags & ^libc.Int32FromInt32(SQLITE_OPEN_MAIN_DB) | int32(SQLITE_OPEN_TEMP_DB)
	}
	p = _sqlite3MallocZero(tls, uint64(48))
	if !(p != 0) {
		return int32(SQLITE_NOMEM)
	}
	(*TBtree)(unsafe.Pointer(p)).FinTrans = uint8(TRANS_NONE)
	(*TBtree)(unsafe.Pointer(p)).Fdb = db
	(*TBtree)(unsafe.Pointer(p)).Flock.FpBtree = p
	(*TBtree)(unsafe.Pointer(p)).Flock.FiTable = uint32(1)
	/*
	 ** If this Btree is a candidate for shared cache, try to find an
	 ** existing BtShared object that we can share with
	 */
	if isTempDb == 0 && (isMemdb == 0 || vfsFlags&int32(SQLITE_OPEN_URI) != 0) {
		if vfsFlags&int32(SQLITE_OPEN_SHAREDCACHE) != 0 {
			nFilename = _sqlite3Strlen30(tls, zFilename) + int32(1)
			nFullPathname = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + int32(1)
			if nFullPathname > nFilename {
				v1 = nFullPathname
			} else {
				v1 = nFilename
			}
			zFullPathname = _sqlite3Malloc(tls, uint64(v1))
			(*TBtree)(unsafe.Pointer(p)).Fsharable = uint8(1)
			if !(zFullPathname != 0) {
				Xsqlite3_free(tls, p)
				return int32(SQLITE_NOMEM)
			}
			if isMemdb != 0 {
				libc.Xmemcpy(tls, zFullPathname, zFilename, uint32(uint32(nFilename)))
			} else {
				rc = _sqlite3OsFullPathname(tls, pVfs, zFilename, nFullPathname, zFullPathname)
				if rc != 0 {
					if rc == libc.Int32FromInt32(SQLITE_OK)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
						rc = SQLITE_OK
					} else {
						Xsqlite3_free(tls, zFullPathname)
						Xsqlite3_free(tls, p)
						return rc
					}
				}
			}
			mutexOpen = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_OPEN))
			Xsqlite3_mutex_enter(tls, mutexOpen)
			mutexShared = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
			Xsqlite3_mutex_enter(tls, mutexShared)
			pBt = _sqlite3SharedCacheList
			for {
				if !(pBt != 0) {
					break
				}
				if 0 == libc.Xstrcmp(tls, zFullPathname, _sqlite3PagerFilename(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, 0)) && _sqlite3PagerVfs(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager) == pVfs {
					iDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
					for {
						if !(iDb >= 0) {
							break
						}
						pExisting = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
						if pExisting != 0 && (*TBtree)(unsafe.Pointer(pExisting)).FpBt == pBt {
							Xsqlite3_mutex_leave(tls, mutexShared)
							Xsqlite3_mutex_leave(tls, mutexOpen)
							Xsqlite3_free(tls, zFullPathname)
							Xsqlite3_free(tls, p)
							return int32(SQLITE_CONSTRAINT)
						}
						goto _3
					_3:
						;
						iDb--
					}
					(*TBtree)(unsafe.Pointer(p)).FpBt = pBt
					(*TBtShared)(unsafe.Pointer(pBt)).FnRef++
					break
				}
				goto _2
			_2:
				;
				pBt = (*TBtShared)(unsafe.Pointer(pBt)).FpNext
			}
			Xsqlite3_mutex_leave(tls, mutexShared)
			Xsqlite3_free(tls, zFullPathname)
		}
	}
	if pBt == uintptr(0) {
		/*
		 ** The following asserts make sure that structures used by the btree are
		 ** the right size.  This is to guard against size changes that result
		 ** when compiling on a different architecture.
		 */
		/* Suppress false-positive compiler warning from PVS-Studio */
		libc.Xmemset(tls, bp+16, 0, uint32(8))
		pBt = _sqlite3MallocZero(tls, uint64(92))
		if pBt == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
			goto btree_open_out
		}
		rc = _sqlite3PagerOpen(tls, pVfs, pBt, zFilename, int32(84), flags, vfsFlags, __ccgo_fp(_pageReinit))
		if rc == SQLITE_OK {
			_sqlite3PagerSetMmapLimit(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, (*Tsqlite3)(unsafe.Pointer(db)).FszMmap)
			rc = _sqlite3PagerReadFileheader(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, int32(100), bp)
		}
		if rc != SQLITE_OK {
			goto btree_open_out
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FopenFlags = uint8(uint8(flags))
		(*TBtShared)(unsafe.Pointer(pBt)).Fdb = db
		_sqlite3PagerSetBusyHandler(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, __ccgo_fp(_btreeInvokeBusyHandler), pBt)
		(*TBtree)(unsafe.Pointer(p)).FpBt = pBt
		(*TBtShared)(unsafe.Pointer(pBt)).FpCursor = uintptr(0)
		(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
		if _sqlite3PagerIsreadonly(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager) != 0 {
			p4 = pBt + 24
			*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(BTS_READ_ONLY))
		}
		/* EVIDENCE-OF: R-51873-39618 The page size for a database file is
		 ** determined by the 2-byte integer located at an offset of 16 bytes from
		 ** the beginning of the database file. */
		(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = uint32(int32((*(*[100]uint8)(unsafe.Pointer(bp)))[int32(16)])<<int32(8) | int32((*(*[100]uint8)(unsafe.Pointer(bp)))[int32(17)])<<int32(16))
		if (*TBtShared)(unsafe.Pointer(pBt)).FpageSize < uint32(512) || (*TBtShared)(unsafe.Pointer(pBt)).FpageSize > uint32(SQLITE_MAX_PAGE_SIZE) || ((*TBtShared)(unsafe.Pointer(pBt)).FpageSize-uint32(1))&(*TBtShared)(unsafe.Pointer(pBt)).FpageSize != uint32(0) {
			(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = uint32(0)
			/* If the magic name ":memory:" will create an in-memory database, then
			 ** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
			 ** SQLITE_DEFAULT_AUTOVACUUM is true. On the other hand, if
			 ** SQLITE_OMIT_MEMORYDB has been defined, then ":memory:" is just a
			 ** regular file-name. In this case the auto-vacuum applies as per normal.
			 */
			if zFilename != 0 && !(isMemdb != 0) {
				(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = uint8(libc.Int32FromInt32(0))
				(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = uint8(libc.Int32FromInt32(0))
			}
			nReserve = uint8(0)
		} else {
			/* EVIDENCE-OF: R-37497-42412 The size of the reserved region is
			 ** determined by the one-byte unsigned integer found at an offset of 20
			 ** into the database file header. */
			nReserve = (*(*[100]uint8)(unsafe.Pointer(bp)))[int32(20)]
			p5 = pBt + 24
			*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
			if _sqlite3Get4byte(tls, bp+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(4)*libc.Int32FromInt32(4))) != 0 {
				v6 = int32(1)
			} else {
				v6 = 0
			}
			(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = uint8(v6)
			if _sqlite3Get4byte(tls, bp+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(7)*libc.Int32FromInt32(4))) != 0 {
				v7 = int32(1)
			} else {
				v7 = 0
			}
			(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = uint8(v7)
		}
		rc = _sqlite3PagerSetPagesize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pBt+36, int32(int32(nReserve)))
		if rc != 0 {
			goto btree_open_out
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = (*TBtShared)(unsafe.Pointer(pBt)).FpageSize - uint32(uint32(nReserve))
		/* 8-byte alignment of pageSize */
		/* Add the new BtShared object to the linked list sharable BtShareds.
		 */
		(*TBtShared)(unsafe.Pointer(pBt)).FnRef = int32(1)
		if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
			mutexShared1 = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
			if libc.Bool(int32(SQLITE_THREADSAFE) != 0) && _sqlite3Config.FbCoreMutex != 0 {
				(*TBtShared)(unsafe.Pointer(pBt)).Fmutex = _sqlite3MutexAlloc(tls, SQLITE_MUTEX_FAST)
				if (*TBtShared)(unsafe.Pointer(pBt)).Fmutex == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
					goto btree_open_out
				}
			}
			Xsqlite3_mutex_enter(tls, mutexShared1)
			(*TBtShared)(unsafe.Pointer(pBt)).FpNext = _sqlite3SharedCacheList
			_sqlite3SharedCacheList = pBt
			Xsqlite3_mutex_leave(tls, mutexShared1)
		}
	}
	/* If the new Btree uses a sharable pBtShared, then link the new
	 ** Btree into the list of all sharable Btrees for the same connection.
	 ** The list is kept in ascending order by pBt address.
	 */
	if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			v9 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			pSib = v9
			if v9 != uintptr(0) && (*TBtree)(unsafe.Pointer(pSib)).Fsharable != 0 {
				for (*TBtree)(unsafe.Pointer(pSib)).FpPrev != 0 {
					pSib = (*TBtree)(unsafe.Pointer(pSib)).FpPrev
				}
				if uint32((*TBtree)(unsafe.Pointer(p)).FpBt) < uint32((*TBtree)(unsafe.Pointer(pSib)).FpBt) {
					(*TBtree)(unsafe.Pointer(p)).FpNext = pSib
					(*TBtree)(unsafe.Pointer(p)).FpPrev = uintptr(0)
					(*TBtree)(unsafe.Pointer(pSib)).FpPrev = p
				} else {
					for (*TBtree)(unsafe.Pointer(pSib)).FpNext != 0 && uint32((*TBtree)(unsafe.Pointer((*TBtree)(unsafe.Pointer(pSib)).FpNext)).FpBt) < uint32((*TBtree)(unsafe.Pointer(p)).FpBt) {
						pSib = (*TBtree)(unsafe.Pointer(pSib)).FpNext
					}
					(*TBtree)(unsafe.Pointer(p)).FpNext = (*TBtree)(unsafe.Pointer(pSib)).FpNext
					(*TBtree)(unsafe.Pointer(p)).FpPrev = pSib
					if (*TBtree)(unsafe.Pointer(p)).FpNext != 0 {
						(*TBtree)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpNext)).FpPrev = p
					}
					(*TBtree)(unsafe.Pointer(pSib)).FpNext = p
				}
				break
			}
			goto _8
		_8:
			;
			i++
		}
	}
	*(*uintptr)(unsafe.Pointer(ppBtree)) = p
	goto btree_open_out
btree_open_out:
	;
	if rc != SQLITE_OK {
		if pBt != 0 && (*TBtShared)(unsafe.Pointer(pBt)).FpPager != 0 {
			_sqlite3PagerClose(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, uintptr(0))
		}
		Xsqlite3_free(tls, pBt)
		Xsqlite3_free(tls, p)
		*(*uintptr)(unsafe.Pointer(ppBtree)) = uintptr(0)
	} else {
		/* If the B-Tree was successfully opened, set the pager-cache size to the
		 ** default value. Except, when opening on an existing shared pager-cache,
		 ** do not change the pager-cache size.
		 */
		if _sqlite3BtreeSchema(tls, p, 0, uintptr(0)) == uintptr(0) {
			_sqlite3BtreeSetCacheSize(tls, p, -int32(2000))
		}
		pFile = _sqlite3PagerFile(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
		if (*Tsqlite3_file)(unsafe.Pointer(pFile)).FpMethods != 0 {
			_sqlite3OsFileControlHint(tls, pFile, int32(SQLITE_FCNTL_PDB), pBt+4)
		}
	}
	if mutexOpen != 0 {
		Xsqlite3_mutex_leave(tls, mutexOpen)
	}
	return rc
}

// C documentation
//
//	/*
//	** Decrement the BtShared.nRef counter.  When it reaches zero,
//	** remove the BtShared structure from the sharing list.  Return
//	** true if the BtShared.nRef counter reaches zero and return
//	** false if it is still positive.
//	*/
func _removeFromSharingList(tls *libc.TLS, pBt uintptr) (r int32) {
	var pList, pMainMtx uintptr
	var removed int32
	_, _, _ = pList, pMainMtx, removed
	removed = 0
	pMainMtx = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
	Xsqlite3_mutex_enter(tls, pMainMtx)
	(*TBtShared)(unsafe.Pointer(pBt)).FnRef--
	if (*TBtShared)(unsafe.Pointer(pBt)).FnRef <= 0 {
		if _sqlite3SharedCacheList == pBt {
			_sqlite3SharedCacheList = (*TBtShared)(unsafe.Pointer(pBt)).FpNext
		} else {
			pList = _sqlite3SharedCacheList
			for pList != 0 && (*TBtShared)(unsafe.Pointer(pList)).FpNext != pBt {
				pList = (*TBtShared)(unsafe.Pointer(pList)).FpNext
			}
			if pList != 0 {
				(*TBtShared)(unsafe.Pointer(pList)).FpNext = (*TBtShared)(unsafe.Pointer(pBt)).FpNext
			}
		}
		if int32(SQLITE_THREADSAFE) != 0 {
			Xsqlite3_mutex_free(tls, (*TBtShared)(unsafe.Pointer(pBt)).Fmutex)
		}
		removed = int32(1)
	}
	Xsqlite3_mutex_leave(tls, pMainMtx)
	return removed
}

// C documentation
//
//	/*
//	** Make sure pBt->pTmpSpace points to an allocation of
//	** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
//	** pointer.
//	*/
func _allocateTempSpace(tls *libc.TLS, pBt uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	/* This routine is called only by btreeCursor() when allocating the
	 ** first write cursor for the BtShared object */
	(*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace = _sqlite3PageMalloc(tls, int32((*TBtShared)(unsafe.Pointer(pBt)).FpageSize))
	if (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace == uintptr(0) {
		pCur = (*TBtShared)(unsafe.Pointer(pBt)).FpCursor
		(*TBtShared)(unsafe.Pointer(pBt)).FpCursor = (*TBtCursor)(unsafe.Pointer(pCur)).FpNext /* Unlink the cursor */
		libc.Xmemset(tls, pCur, 0, uint32(200))
		return int32(SQLITE_NOMEM)
	}
	/* One of the uses of pBt->pTmpSpace is to format cells before
	 ** inserting them into a leaf page (function fillInCell()). If
	 ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
	 ** by the various routines that manipulate binary cells. Which
	 ** can mean that fillInCell() only initializes the first 2 or 3
	 ** bytes of pTmpSpace, but that the first 4 bytes are copied from
	 ** it into a database page. This is not actually a problem, but it
	 ** does cause a valgrind error when the 1 or 2 bytes of uninitialized
	 ** data is passed to system call write(). So to avoid this error,
	 ** zero the first 4 bytes of temp space here.
	 **
	 ** Also:  Provide four bytes of initialized space before the
	 ** beginning of pTmpSpace as an area available to prepend the
	 ** left-child pointer to the beginning of a cell.
	 */
	libc.Xmemset(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace, 0, uint32(8))
	*(*uintptr)(unsafe.Pointer(pBt + 84)) += uintptr(4)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Free the pBt->pTmpSpace allocation
//	*/
func _freeTempSpace(tls *libc.TLS, pBt uintptr) {
	if (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace != 0 {
		*(*uintptr)(unsafe.Pointer(pBt + 84)) -= uintptr(4)
		_sqlite3PageFree(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace)
		(*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Close an open database and invalidate all cursors.
//	*/
func _sqlite3BtreeClose(tls *libc.TLS, p uintptr) (r int32) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	/* Close all cursors opened via this handle.  */
	_sqlite3BtreeEnter(tls, p)
	/* Verify that no other cursors have this Btree open */
	/* Rollback any active transaction and free the handle structure.
	 ** The call to sqlite3BtreeRollback() drops any table-locks held by
	 ** this handle.
	 */
	_sqlite3BtreeRollback(tls, p, SQLITE_OK, 0)
	_sqlite3BtreeLeave(tls, p)
	/* If there are still other outstanding references to the shared-btree
	 ** structure, return now. The remainder of this procedure cleans
	 ** up the shared-btree.
	 */
	if !((*TBtree)(unsafe.Pointer(p)).Fsharable != 0) || _removeFromSharingList(tls, pBt) != 0 {
		/* The pBt is no longer on the sharing list, so we can access
		 ** it without having to hold the mutex.
		 **
		 ** Clean out and delete the BtShared object.
		 */
		_sqlite3PagerClose(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, (*TBtree)(unsafe.Pointer(p)).Fdb)
		if (*TBtShared)(unsafe.Pointer(pBt)).FxFreeSchema != 0 && (*TBtShared)(unsafe.Pointer(pBt)).FpSchema != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TBtShared)(unsafe.Pointer(pBt)).FxFreeSchema})))(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpSchema)
		}
		_sqlite3DbFree(tls, uintptr(0), (*TBtShared)(unsafe.Pointer(pBt)).FpSchema)
		_freeTempSpace(tls, pBt)
		Xsqlite3_free(tls, pBt)
	}
	if (*TBtree)(unsafe.Pointer(p)).FpPrev != 0 {
		(*TBtree)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpPrev)).FpNext = (*TBtree)(unsafe.Pointer(p)).FpNext
	}
	if (*TBtree)(unsafe.Pointer(p)).FpNext != 0 {
		(*TBtree)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpNext)).FpPrev = (*TBtree)(unsafe.Pointer(p)).FpPrev
	}
	Xsqlite3_free(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Change the "soft" limit on the number of pages in the cache.
//	** Unused and unmodified pages will be recycled when the number of
//	** pages in the cache exceeds this soft limit.  But the size of the
//	** cache is allowed to grow larger than this limit if it contains
//	** dirty pages or pages still in active use.
//	*/
func _sqlite3BtreeSetCacheSize(tls *libc.TLS, p uintptr, mxPage int32) (r int32) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	_sqlite3PagerSetCachesize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, mxPage)
	_sqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Change the "spill" limit on the number of pages in the cache.
//	** If the number of pages exceeds this limit during a write transaction,
//	** the pager might attempt to "spill" pages to the journal early in
//	** order to free up memory.
//	**
//	** The value returned is the current spill size.  If zero is passed
//	** as an argument, no changes are made to the spill size setting, so
//	** using mxPage of 0 is a way to query the current spill size.
//	*/
func _sqlite3BtreeSetSpillSize(tls *libc.TLS, p uintptr, mxPage int32) (r int32) {
	var pBt uintptr
	var res int32
	_, _ = pBt, res
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	res = _sqlite3PagerSetSpillsize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, mxPage)
	_sqlite3BtreeLeave(tls, p)
	return res
}

// C documentation
//
//	/*
//	** Change the limit on the amount of the database file that may be
//	** memory mapped.
//	*/
func _sqlite3BtreeSetMmapLimit(tls *libc.TLS, p uintptr, szMmap Tsqlite3_int64) (r int32) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	_sqlite3PagerSetMmapLimit(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, szMmap)
	_sqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Change the way data is synced to disk in order to increase or decrease
//	** how well the database resists damage due to OS crashes and power
//	** failures.  Level 1 is the same as asynchronous (no syncs() occur and
//	** there is a high probability of damage)  Level 2 is the default.  There
//	** is a very low but non-zero probability of damage.  Level 3 reduces the
//	** probability of damage to near zero but with a write performance reduction.
//	*/
func _sqlite3BtreeSetPagerFlags(tls *libc.TLS, p uintptr, pgFlags uint32) (r int32) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	_sqlite3PagerSetFlags(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pgFlags)
	_sqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Change the default pages size and the number of reserved bytes per page.
//	** Or, if the page size has already been fixed, return SQLITE_READONLY
//	** without changing anything.
//	**
//	** The page size must be a power of 2 between 512 and 65536.  If the page
//	** size supplied does not meet this constraint then the page size is not
//	** changed.
//	**
//	** Page sizes are constrained to be a power of two so that the region
//	** of the database file used for locking (beginning at PENDING_BYTE,
//	** the first byte past the 1GB boundary, 0x40000000) needs to occur
//	** at the beginning of a page.
//	**
//	** If parameter nReserve is less than zero, then the number of reserved
//	** bytes per page is left unchanged.
//	**
//	** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
//	** and autovacuum mode can no longer be changed.
//	*/
func _sqlite3BtreeSetPageSize(tls *libc.TLS, p uintptr, pageSize int32, nReserve int32, iFix int32) (r int32) {
	var pBt, p1 uintptr
	var rc, x int32
	_, _, _, _ = pBt, rc, x, p1
	rc = SQLITE_OK
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	(*TBtShared)(unsafe.Pointer(pBt)).FnReserveWanted = uint8(uint8(nReserve))
	x = int32((*TBtShared)(unsafe.Pointer(pBt)).FpageSize - (*TBtShared)(unsafe.Pointer(pBt)).FusableSize)
	if nReserve < x {
		nReserve = x
	}
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_PAGESIZE_FIXED) != 0 {
		_sqlite3BtreeLeave(tls, p)
		return int32(SQLITE_READONLY)
	}
	if pageSize >= int32(512) && pageSize <= int32(SQLITE_MAX_PAGE_SIZE) && (pageSize-int32(1))&pageSize == 0 {
		if nReserve > int32(32) && pageSize == int32(512) {
			pageSize = int32(1024)
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = uint32(uint32(pageSize))
		_freeTempSpace(tls, pBt)
	}
	rc = _sqlite3PagerSetPagesize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pBt+36, nReserve)
	(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = (*TBtShared)(unsafe.Pointer(pBt)).FpageSize - uint32(uint16(uint16(nReserve)))
	if iFix != 0 {
		p1 = pBt + 24
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
	}
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Return the currently defined page size
//	*/
func _sqlite3BtreeGetPageSize(tls *libc.TLS, p uintptr) (r int32) {
	return int32((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpageSize)
}

// C documentation
//
//	/*
//	** This function is similar to sqlite3BtreeGetReserve(), except that it
//	** may only be called if it is guaranteed that the b-tree mutex is already
//	** held.
//	**
//	** This is useful in one special case in the backup API code where it is
//	** known that the shared b-tree mutex is held, but the mutex on the
//	** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
//	** were to be called, it might collide with some other operation on the
//	** database handle that owns *p, causing undefined behavior.
//	*/
func _sqlite3BtreeGetReserveNoMutex(tls *libc.TLS, p uintptr) (r int32) {
	var n int32
	_ = n
	n = int32((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpageSize - (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FusableSize)
	return n
}

// C documentation
//
//	/*
//	** Return the number of bytes of space at the end of every page that
//	** are intentionally left unused.  This is the "reserved" space that is
//	** sometimes used by extensions.
//	**
//	** The value returned is the larger of the current reserve size and
//	** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES.
//	** The amount of reserve can only grow - never shrink.
//	*/
func _sqlite3BtreeGetRequestedReserve(tls *libc.TLS, p uintptr) (r int32) {
	var n1, n2, v1 int32
	_, _, _ = n1, n2, v1
	_sqlite3BtreeEnter(tls, p)
	n1 = int32((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FnReserveWanted)
	n2 = _sqlite3BtreeGetReserveNoMutex(tls, p)
	_sqlite3BtreeLeave(tls, p)
	if n1 > n2 {
		v1 = n1
	} else {
		v1 = n2
	}
	return v1
}

// C documentation
//
//	/*
//	** Set the maximum page count for a database if mxPage is positive.
//	** No changes are made if mxPage is 0 or negative.
//	** Regardless of the value of mxPage, return the maximum page count.
//	*/
func _sqlite3BtreeMaxPageCount(tls *libc.TLS, p uintptr, mxPage TPgno) (r TPgno) {
	var n TPgno
	_ = n
	_sqlite3BtreeEnter(tls, p)
	n = _sqlite3PagerMaxPageCount(tls, (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpPager, mxPage)
	_sqlite3BtreeLeave(tls, p)
	return n
}

// C documentation
//
//	/*
//	** Change the values for the BTS_SECURE_DELETE and BTS_OVERWRITE flags:
//	**
//	**    newFlag==0       Both BTS_SECURE_DELETE and BTS_OVERWRITE are cleared
//	**    newFlag==1       BTS_SECURE_DELETE set and BTS_OVERWRITE is cleared
//	**    newFlag==2       BTS_SECURE_DELETE cleared and BTS_OVERWRITE is set
//	**    newFlag==(-1)    No changes
//	**
//	** This routine acts as a query if newFlag is less than zero
//	**
//	** With BTS_OVERWRITE set, deleted content is overwritten by zeros, but
//	** freelist leaf pages are not written back to the database.  Thus in-page
//	** deleted content is cleared, but freelist deleted content is not.
//	**
//	** With BTS_SECURE_DELETE, operation is like BTS_OVERWRITE with the addition
//	** that freelist leaf pages are written back into the database, increasing
//	** the amount of disk I/O.
//	*/
func _sqlite3BtreeSecureDelete(tls *libc.TLS, p uintptr, newFlag int32) (r int32) {
	var b int32
	var p1, p2 uintptr
	_, _, _ = b, p1, p2
	if p == uintptr(0) {
		return 0
	}
	_sqlite3BtreeEnter(tls, p)
	if newFlag >= 0 {
		p1 = (*TBtree)(unsafe.Pointer(p)).FpBt + 24
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(BTS_FAST_SECURE))
		p2 = (*TBtree)(unsafe.Pointer(p)).FpBt + 24
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(BTS_SECURE_DELETE)*newFlag)
	}
	b = int32((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FbtsFlags) & int32(BTS_FAST_SECURE) / int32(BTS_SECURE_DELETE)
	_sqlite3BtreeLeave(tls, p)
	return b
}

// C documentation
//
//	/*
//	** Change the 'auto-vacuum' property of the database. If the 'autoVacuum'
//	** parameter is non-zero, then auto-vacuum mode is enabled. If zero, it
//	** is disabled. The default value for the auto-vacuum property is
//	** determined by the SQLITE_DEFAULT_AUTOVACUUM macro.
//	*/
func _sqlite3BtreeSetAutoVacuum(tls *libc.TLS, p uintptr, autoVacuum int32) (r int32) {
	var av Tu8
	var pBt uintptr
	var rc, v1, v3, v4 int32
	var v2 bool
	_, _, _, _, _, _, _ = av, pBt, rc, v1, v2, v3, v4
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	rc = SQLITE_OK
	av = uint8(uint8(autoVacuum))
	_sqlite3BtreeEnter(tls, p)
	if v2 = int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_PAGESIZE_FIXED) != 0; v2 {
		if av != 0 {
			v1 = int32(1)
		} else {
			v1 = 0
		}
	}
	if v2 && v1 != int32((*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum) {
		rc = int32(SQLITE_READONLY)
	} else {
		if av != 0 {
			v3 = int32(1)
		} else {
			v3 = 0
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = uint8(v3)
		if int32(int32(av)) == int32(2) {
			v4 = int32(1)
		} else {
			v4 = 0
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = uint8(v4)
	}
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Return the value of the 'auto-vacuum' property. If auto-vacuum is
//	** enabled 1 is returned. Otherwise 0.
//	*/
func _sqlite3BtreeGetAutoVacuum(tls *libc.TLS, p uintptr) (r int32) {
	var rc, v1, v2 int32
	_, _, _ = rc, v1, v2
	_sqlite3BtreeEnter(tls, p)
	if !((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FautoVacuum != 0) {
		v1 = BTREE_AUTOVACUUM_NONE
	} else {
		if !((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FincrVacuum != 0) {
			v2 = int32(BTREE_AUTOVACUUM_FULL)
		} else {
			v2 = int32(BTREE_AUTOVACUUM_INCR)
		}
		v1 = v2
	}
	rc = v1
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Get a reference to pPage1 of the database file.  This will
//	** also acquire a readlock on that file.
//	**
//	** SQLITE_OK is returned on success.  If the file is not a
//	** well-formed database file, then SQLITE_CORRUPT is returned.
//	** SQLITE_BUSY is returned if the database is locked.  SQLITE_NOMEM
//	** is returned if we run out of memory.
//	*/
func _lockBtree(tls *libc.TLS, pBt uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nPage, pageSize, usableSize Tu32
	var page1, p1, p2, p3 uintptr
	var rc, v4, v5 int32
	var _ /* isOpen at bp+8 */ int32
	var _ /* nPageFile at bp+4 */ Tu32
	var _ /* pPage1 at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = nPage, page1, pageSize, rc, usableSize, v4, v5, p1, p2, p3 /* Number of pages in the database */
	*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0)                                              /* Number of pages in the database file */
	rc = _sqlite3PagerSharedLock(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
	if rc != SQLITE_OK {
		return rc
	}
	rc = _btreeGetPage(tls, pBt, uint32(1), bp, 0)
	if rc != SQLITE_OK {
		return rc
	}
	/* Do some checking to help insure the file we opened really is
	 ** a valid database file.
	 */
	nPage = _sqlite3Get4byte(tls, uintptr(28)+(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData)
	_sqlite3PagerPagecount(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, bp+4)
	if nPage == uint32(0) || libc.Xmemcmp(tls, uintptr(24)+(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uintptr(92)+(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uint32(4)) != 0 {
		nPage = *(*Tu32)(unsafe.Pointer(bp + 4))
	}
	if (*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0) {
		nPage = uint32(0)
	}
	if nPage > uint32(0) {
		page1 = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData
		rc = int32(SQLITE_NOTADB)
		/* EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
		 ** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
		 ** 61 74 20 33 00. */
		if libc.Xmemcmp(tls, page1, uintptr(unsafe.Pointer(&_zMagicHeader)), uint32(16)) != 0 {
			goto page1_init_failed
		}
		if int32(*(*Tu8)(unsafe.Pointer(page1 + 18))) > int32(2) {
			p1 = pBt + 24
			*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTS_READ_ONLY))
		}
		if int32(*(*Tu8)(unsafe.Pointer(page1 + 19))) > int32(2) {
			goto page1_init_failed
		}
		/* If the read version is set to 2, this database should be accessed
		 ** in WAL mode. If the log is not already open, open it now. Then
		 ** return SQLITE_OK and return without populating BtShared.pPage1.
		 ** The caller detects this and calls this function again. This is
		 ** required as the version of page 1 currently in the page1 buffer
		 ** may not be the latest version - there may be a newer one in the log
		 ** file.
		 */
		if int32(*(*Tu8)(unsafe.Pointer(page1 + 19))) == int32(2) && int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_NO_WAL) == 0 {
			*(*int32)(unsafe.Pointer(bp + 8)) = 0
			rc = _sqlite3PagerOpenWal(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, bp+8)
			if rc != SQLITE_OK {
				goto page1_init_failed
			} else {
				if *(*int32)(unsafe.Pointer(bp + 8)) == 0 {
					_releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
					return SQLITE_OK
				}
			}
			rc = int32(SQLITE_NOTADB)
		} else {
		}
		/* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
		 ** fractions and the leaf payload fraction values must be 64, 32, and 32.
		 **
		 ** The original design allowed these amounts to vary, but as of
		 ** version 3.6.0, we require them to be fixed.
		 */
		if libc.Xmemcmp(tls, page1+21, __ccgo_ts+5572, uint32(3)) != 0 {
			goto page1_init_failed
		}
		/* EVIDENCE-OF: R-51873-39618 The page size for a database file is
		 ** determined by the 2-byte integer located at an offset of 16 bytes from
		 ** the beginning of the database file. */
		pageSize = uint32(int32(*(*Tu8)(unsafe.Pointer(page1 + 16)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(page1 + 17)))<<int32(16))
		/* EVIDENCE-OF: R-25008-21688 The size of a page is a power of two
		 ** between 512 and 65536 inclusive. */
		if (pageSize-uint32(1))&pageSize != uint32(0) || pageSize > uint32(SQLITE_MAX_PAGE_SIZE) || pageSize <= uint32(256) {
			goto page1_init_failed
		}
		/* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
		 ** integer at offset 20 is the number of bytes of space at the end of
		 ** each page to reserve for extensions.
		 **
		 ** EVIDENCE-OF: R-37497-42412 The size of the reserved region is
		 ** determined by the one-byte unsigned integer found at an offset of 20
		 ** into the database file header. */
		usableSize = pageSize - uint32(*(*Tu8)(unsafe.Pointer(page1 + 20)))
		if pageSize != (*TBtShared)(unsafe.Pointer(pBt)).FpageSize {
			/* After reading the first page of the database assuming a page size
			 ** of BtShared.pageSize, we have discovered that the page-size is
			 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
			 ** zero and return SQLITE_OK. The caller will call this function
			 ** again with the correct page-size.
			 */
			_releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
			(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
			(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
			p2 = pBt + 24
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
			_freeTempSpace(tls, pBt)
			rc = _sqlite3PagerSetPagesize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pBt+36, int32(pageSize-usableSize))
			return rc
		}
		if nPage > *(*Tu32)(unsafe.Pointer(bp + 4)) {
			if _sqlite3WritableSchema(tls, (*TBtShared)(unsafe.Pointer(pBt)).Fdb) == 0 {
				rc = _sqlite3CorruptError(tls, int32(73936))
				goto page1_init_failed
			} else {
				nPage = *(*Tu32)(unsafe.Pointer(bp + 4))
			}
		}
		/* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
		 ** be less than 480. In other words, if the page size is 512, then the
		 ** reserved space size cannot exceed 32. */
		if usableSize < uint32(480) {
			goto page1_init_failed
		}
		p3 = pBt + 24
		*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
		(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
		(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
		if _sqlite3Get4byte(tls, page1+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(4)*libc.Int32FromInt32(4))) != 0 {
			v4 = int32(1)
		} else {
			v4 = 0
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = uint8(v4)
		if _sqlite3Get4byte(tls, page1+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(7)*libc.Int32FromInt32(4))) != 0 {
			v5 = int32(1)
		} else {
			v5 = 0
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = uint8(v5)
	}
	/* maxLocal is the maximum amount of payload to store locally for
	 ** a cell.  Make sure it is small enough so that at least minFanout
	 ** cells can will fit on one page.  We assume a 10-byte page header.
	 ** Besides the payload, the cell must store:
	 **     2-byte pointer to the cell
	 **     4-byte child pointer
	 **     9-byte nKey value
	 **     4-byte nData value
	 **     4-byte overflow page pointer
	 ** So a cell consists of a 2-byte pointer, a header which is as much as
	 ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
	 ** page pointer.
	 */
	(*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(64)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
	(*TBtShared)(unsafe.Pointer(pBt)).FminLocal = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(32)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
	(*TBtShared)(unsafe.Pointer(pBt)).FmaxLeaf = uint16((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - libc.Uint32FromInt32(35))
	(*TBtShared)(unsafe.Pointer(pBt)).FminLeaf = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(32)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal) > int32(127) {
		(*TBtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = uint8(127)
	} else {
		(*TBtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = uint8((*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal)
	}
	(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = *(*uintptr)(unsafe.Pointer(bp))
	(*TBtShared)(unsafe.Pointer(pBt)).FnPage = nPage
	return SQLITE_OK
	goto page1_init_failed
page1_init_failed:
	;
	_releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
	return rc
}

// C documentation
//
//	/*
//	** If there are no outstanding cursors and we are not in the middle
//	** of a transaction but there is a read lock on the database, then
//	** this routine unrefs the first page of the database file which
//	** has the effect of releasing the read lock.
//	**
//	** If there is a transaction in progress, this routine is a no-op.
//	*/
func _unlockBtreeIfUnused(tls *libc.TLS, pBt uintptr) {
	var pPage1 uintptr
	_ = pPage1
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE && (*TBtShared)(unsafe.Pointer(pBt)).FpPage1 != uintptr(0) {
		pPage1 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1
		(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
		_releasePageOne(tls, pPage1)
	}
}

// C documentation
//
//	/*
//	** If pBt points to an empty file then convert that empty file
//	** into a new empty database by initializing the first page of
//	** the database.
//	*/
func _newDatabase(tls *libc.TLS, pBt uintptr) (r int32) {
	var data, pP1, p1 uintptr
	var rc int32
	_, _, _, _ = data, pP1, rc, p1
	if (*TBtShared)(unsafe.Pointer(pBt)).FnPage > uint32(0) {
		return SQLITE_OK
	}
	pP1 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1
	data = (*TMemPage)(unsafe.Pointer(pP1)).FaData
	rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pP1)).FpDbPage)
	if rc != 0 {
		return rc
	}
	libc.Xmemcpy(tls, data, uintptr(unsafe.Pointer(&_zMagicHeader)), uint32(16))
	*(*uint8)(unsafe.Pointer(data + 16)) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FpageSize >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0xff))
	*(*uint8)(unsafe.Pointer(data + 17)) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FpageSize >> libc.Int32FromInt32(16) & libc.Uint32FromInt32(0xff))
	*(*uint8)(unsafe.Pointer(data + 18)) = uint8(1)
	*(*uint8)(unsafe.Pointer(data + 19)) = uint8(1)
	*(*uint8)(unsafe.Pointer(data + 20)) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FpageSize - (*TBtShared)(unsafe.Pointer(pBt)).FusableSize)
	*(*uint8)(unsafe.Pointer(data + 21)) = uint8(64)
	*(*uint8)(unsafe.Pointer(data + 22)) = uint8(32)
	*(*uint8)(unsafe.Pointer(data + 23)) = uint8(32)
	libc.Xmemset(tls, data+24, 0, uint32(libc.Int32FromInt32(100)-libc.Int32FromInt32(24)))
	_zeroPage(tls, pP1, libc.Int32FromInt32(PTF_INTKEY)|libc.Int32FromInt32(PTF_LEAF)|libc.Int32FromInt32(PTF_LEAFDATA))
	p1 = pBt + 24
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
	_sqlite3Put4byte(tls, data+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(4)*libc.Int32FromInt32(4)), uint32((*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum))
	_sqlite3Put4byte(tls, data+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(7)*libc.Int32FromInt32(4)), uint32((*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum))
	(*TBtShared)(unsafe.Pointer(pBt)).FnPage = uint32(1)
	*(*uint8)(unsafe.Pointer(data + 31)) = uint8(1)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Initialize the first page of the database file (creating a database
//	** consisting of a single page and no schema objects). Return SQLITE_OK
//	** if successful, or an SQLite error code otherwise.
//	*/
func _sqlite3BtreeNewDb(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	_sqlite3BtreeEnter(tls, p)
	(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FnPage = uint32(0)
	rc = _newDatabase(tls, (*TBtree)(unsafe.Pointer(p)).FpBt)
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Attempt to start a new transaction. A write-transaction
//	** is started if the second argument is nonzero, otherwise a read-
//	** transaction.  If the second argument is 2 or more and exclusive
//	** transaction is started, meaning that no other process is allowed
//	** to access the database.  A preexisting transaction may not be
//	** upgraded to exclusive by calling this routine a second time - the
//	** exclusivity flag only works for a new transaction.
//	**
//	** A write-transaction must be started before attempting any
//	** changes to the database.  None of the following routines
//	** will work unless a transaction is started first:
//	**
//	**      sqlite3BtreeCreateTable()
//	**      sqlite3BtreeCreateIndex()
//	**      sqlite3BtreeClearTable()
//	**      sqlite3BtreeDropTable()
//	**      sqlite3BtreeInsert()
//	**      sqlite3BtreeDelete()
//	**      sqlite3BtreeUpdateMeta()
//	**
//	** If an initial attempt to acquire the lock fails because of lock contention
//	** and the database was previously unlocked, then invoke the busy handler
//	** if there is one.  But if there was previously a read-lock, do not
//	** invoke the busy handler - just return SQLITE_BUSY.  SQLITE_BUSY is
//	** returned when there is already a read-lock in order to avoid a deadlock.
//	**
//	** Suppose there are two processes A and B.  A has a read lock and B has
//	** a reserved lock.  B tries to promote to exclusive but is blocked because
//	** of A's read lock.  A tries to promote to reserved but is blocked by B.
//	** One or the other of the two processes must give way or there can be
//	** no progress.  By returning SQLITE_BUSY and not invoking the busy callback
//	** when A already has a read lock, we encourage A to give up and let B
//	** proceed.
//	*/
func _btreeBeginTrans(tls *libc.TLS, p uintptr, wrflag int32, pSchemaVersion uintptr) (r int32) {
	var pBlock, pBt, pIter, pPage1, pPager, p1, p3, p4, p8, p9 uintptr
	var rc, v5, v7 int32
	var v6 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = pBlock, pBt, pIter, pPage1, pPager, rc, v5, v6, v7, p1, p3, p4, p8, p9
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	pPager = (*TBtShared)(unsafe.Pointer(pBt)).FpPager
	rc = SQLITE_OK
	_sqlite3BtreeEnter(tls, p)
	/* If the btree is already in a write-transaction, or it
	 ** is already in a read-transaction and a read-transaction
	 ** is requested, this is a no-op.
	 */
	if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == int32(TRANS_WRITE) || int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == int32(TRANS_READ) && !(wrflag != 0) {
		goto trans_begun
	}
	if (*Tsqlite3)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).Fdb)).Fflags&uint64(SQLITE_ResetDatabase) != 0 && int32(_sqlite3PagerIsreadonly(tls, pPager)) == 0 {
		p1 = pBt + 24
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(BTS_READ_ONLY))
	}
	/* Write transactions are not possible on a read-only database */
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_READ_ONLY) != 0 && wrflag != 0 {
		rc = int32(SQLITE_READONLY)
		goto trans_begun
	}
	pBlock = uintptr(0)
	/* If another database handle has already opened a write transaction
	 ** on this shared-btree structure and a second write transaction is
	 ** requested, return SQLITE_LOCKED.
	 */
	if wrflag != 0 && int32((*TBtShared)(unsafe.Pointer(pBt)).FinTransaction) == int32(TRANS_WRITE) || int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_PENDING) != 0 {
		pBlock = (*TBtree)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpWriter)).Fdb
	} else {
		if wrflag > int32(1) {
			pIter = (*TBtShared)(unsafe.Pointer(pBt)).FpLock
			for {
				if !(pIter != 0) {
					break
				}
				if (*TBtLock)(unsafe.Pointer(pIter)).FpBtree != p {
					pBlock = (*TBtree)(unsafe.Pointer((*TBtLock)(unsafe.Pointer(pIter)).FpBtree)).Fdb
					break
				}
				goto _2
			_2:
				;
				pIter = (*TBtLock)(unsafe.Pointer(pIter)).FpNext
			}
		}
	}
	if pBlock != 0 {
		_sqlite3ConnectionBlocked(tls, (*TBtree)(unsafe.Pointer(p)).Fdb, pBlock)
		rc = libc.Int32FromInt32(SQLITE_LOCKED) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		goto trans_begun
	}
	/* Any read-only or read-write transaction implies a read-lock on
	 ** page 1. So if some other shared-cache client already has a write-lock
	 ** on page 1, the transaction cannot be opened. */
	rc = _querySharedCacheTableLock(tls, p, uint32(SCHEMA_ROOT), uint8(READ_LOCK))
	if SQLITE_OK != rc {
		goto trans_begun
	}
	p3 = pBt + 24
	*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(BTS_INITIALLY_EMPTY))
	if (*TBtShared)(unsafe.Pointer(pBt)).FnPage == uint32(0) {
		p4 = pBt + 24
		*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(BTS_INITIALLY_EMPTY))
	}
	for cond := true; cond; cond = rc&int32(0xFF) == int32(SQLITE_BUSY) && int32((*TBtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE && _btreeInvokeBusyHandler(tls, pBt) != 0 {
		/* Call lockBtree() until either pBt->pPage1 is populated or
		 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
		 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
		 ** reading page 1 it discovers that the page-size of the database
		 ** file is not pBt->pageSize. In this case lockBtree() will update
		 ** pBt->pageSize to the page-size of the file on disk.
		 */
		for {
			if v6 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1 == uintptr(0); v6 {
				v5 = _lockBtree(tls, pBt)
				rc = v5
			}
			if !(v6 && SQLITE_OK == v5) {
				break
			}
		}
		if rc == SQLITE_OK && wrflag != 0 {
			if int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_READ_ONLY) != 0 {
				rc = int32(SQLITE_READONLY)
			} else {
				rc = _sqlite3PagerBegin(tls, pPager, libc.BoolInt32(wrflag > int32(1)), _sqlite3TempInMemory(tls, (*TBtree)(unsafe.Pointer(p)).Fdb))
				if rc == SQLITE_OK {
					rc = _newDatabase(tls, pBt)
				} else {
					if rc == libc.Int32FromInt32(SQLITE_BUSY)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) && int32((*TBtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE {
						/* if there was no transaction opened when this function was
						 ** called and SQLITE_BUSY_SNAPSHOT is returned, change the error
						 ** code to SQLITE_BUSY. */
						rc = int32(SQLITE_BUSY)
					}
				}
			}
		}
		if rc != SQLITE_OK {
			_ = SQLITE_OK
			_unlockBtreeIfUnused(tls, pBt)
		}
	}
	if rc == SQLITE_OK {
		if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == TRANS_NONE {
			(*TBtShared)(unsafe.Pointer(pBt)).FnTransaction++
			if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
				(*TBtree)(unsafe.Pointer(p)).Flock.FeLock = uint8(READ_LOCK)
				(*TBtree)(unsafe.Pointer(p)).Flock.FpNext = (*TBtShared)(unsafe.Pointer(pBt)).FpLock
				(*TBtShared)(unsafe.Pointer(pBt)).FpLock = p + 32
			}
		}
		if wrflag != 0 {
			v7 = int32(TRANS_WRITE)
		} else {
			v7 = int32(TRANS_READ)
		}
		(*TBtree)(unsafe.Pointer(p)).FinTrans = uint8(v7)
		if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) > int32((*TBtShared)(unsafe.Pointer(pBt)).FinTransaction) {
			(*TBtShared)(unsafe.Pointer(pBt)).FinTransaction = (*TBtree)(unsafe.Pointer(p)).FinTrans
		}
		if wrflag != 0 {
			pPage1 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1
			(*TBtShared)(unsafe.Pointer(pBt)).FpWriter = p
			p8 = pBt + 24
			*(*Tu16)(unsafe.Pointer(p8)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p8))) & ^libc.Int32FromInt32(BTS_EXCLUSIVE))
			if wrflag > int32(1) {
				p9 = pBt + 24
				*(*Tu16)(unsafe.Pointer(p9)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p9))) | libc.Int32FromInt32(BTS_EXCLUSIVE))
			}
			/* If the db-size header field is incorrect (as it may be if an old
			 ** client has been writing the database file), update it now. Doing
			 ** this sooner rather than later means the database size can safely
			 ** re-read the database size from page 1 if a savepoint or transaction
			 ** rollback occurs within the transaction.
			 */
			if (*TBtShared)(unsafe.Pointer(pBt)).FnPage != _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+28) {
				rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FpDbPage)
				if rc == SQLITE_OK {
					_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+28, (*TBtShared)(unsafe.Pointer(pBt)).FnPage)
				}
			}
		}
	}
	goto trans_begun
trans_begun:
	;
	if rc == SQLITE_OK {
		if pSchemaVersion != 0 {
			*(*int32)(unsafe.Pointer(pSchemaVersion)) = int32(_sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+40))
		}
		if wrflag != 0 {
			/* This call makes sure that the pager has the correct number of
			 ** open savepoints. If the second parameter is greater than 0 and
			 ** the sub-journal is not already open, then it will be opened here.
			 */
			rc = _sqlite3PagerOpenSavepoint(tls, pPager, (*Tsqlite3)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).Fdb)).FnSavepoint)
		}
	}
	_sqlite3BtreeLeave(tls, p)
	return rc
}

func _sqlite3BtreeBeginTrans(tls *libc.TLS, p uintptr, wrflag int32, pSchemaVersion uintptr) (r int32) {
	var pBt uintptr
	_ = pBt
	if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 || int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == TRANS_NONE || int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == int32(TRANS_READ) && wrflag != 0 {
		return _btreeBeginTrans(tls, p, wrflag, pSchemaVersion)
	}
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	if pSchemaVersion != 0 {
		*(*int32)(unsafe.Pointer(pSchemaVersion)) = int32(_sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+40))
	}
	if wrflag != 0 {
		/* This call makes sure that the pager has the correct number of
		 ** open savepoints. If the second parameter is greater than 0 and
		 ** the sub-journal is not already open, then it will be opened here.
		 */
		return _sqlite3PagerOpenSavepoint(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, (*Tsqlite3)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).Fdb)).FnSavepoint)
	} else {
		return SQLITE_OK
	}
	return r
}

// 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)(unsafe.Pointer(bp)) = v1
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp))
	}
	nCell = int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
	i = 0
	for {
		if !(i < nCell) {
			break
		}
		pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*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++
	}
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		childPgno1 = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
		_ptrmapPut(tls, pBt, childPgno1, uint8(PTRMAP_BTREE), pgno, bp)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// 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 int32(int32(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(74384))
		}
		_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 = int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
		i = 0
		for {
			if !(i < nCell) {
				break
			}
			pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*i))))))
			if int32(int32(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)(unsafe.Pointer(bp))).FnLocal) < (*(*TCellInfo)(unsafe.Pointer(bp))).FnPayload {
					if pCell+uintptr((*(*TCellInfo)(unsafe.Pointer(bp))).FnSize) > (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) {
						return _sqlite3CorruptError(tls, int32(74403))
					}
					if iFrom == _sqlite3Get4byte(tls, pCell+uintptr((*(*TCellInfo)(unsafe.Pointer(bp))).FnSize)-uintptr(4)) {
						_sqlite3Put4byte(tls, pCell+uintptr((*(*TCellInfo)(unsafe.Pointer(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(74412))
				}
				if _sqlite3Get4byte(tls, pCell) == iFrom {
					_sqlite3Put4byte(tls, pCell, iTo)
					break
				}
			}
			goto _2
		_2:
			;
			i++
		}
		if i == nCell {
			if int32(int32(eType)) != int32(PTRMAP_BTREE) || _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8))) != iFrom {
				return _sqlite3CorruptError(tls, int32(74424))
			}
			_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)), iTo)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Move the open database page pDbPage to location iFreePage in the
//	** database. The pDbPage reference remains valid.
//	**
//	** The isCommit flag indicates that there is no need to remember that
//	** the journal needs to be sync()ed before database page pDbPage->pgno
//	** can be written to. The caller has already promised not to write to that
//	** page.
//	*/
func _relocatePage(tls *libc.TLS, pBt uintptr, pDbPage uintptr, eType Tu8, iPtrPage TPgno, iFreePage TPgno, isCommit int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iDbPage, nextOvfl TPgno
	var pPager uintptr
	var _ /* pPtrPage at bp+0 */ uintptr
	var _ /* rc at bp+4 */ int32
	_, _, _ = iDbPage, nextOvfl, pPager /* The page that contains a pointer to pDbPage */
	iDbPage = (*TMemPage)(unsafe.Pointer(pDbPage)).Fpgno
	pPager = (*TBtShared)(unsafe.Pointer(pBt)).FpPager
	if iDbPage < uint32(3) {
		return _sqlite3CorruptError(tls, int32(74459))
	}
	/* Move page iDbPage from its current location to page number iFreePage */
	*(*int32)(unsafe.Pointer(bp + 4)) = _sqlite3PagerMovepage(tls, pPager, (*TMemPage)(unsafe.Pointer(pDbPage)).FpDbPage, iFreePage, isCommit)
	if *(*int32)(unsafe.Pointer(bp + 4)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp + 4))
	}
	(*TMemPage)(unsafe.Pointer(pDbPage)).Fpgno = iFreePage
	/* If pDbPage was a btree-page, then it may have child pages and/or cells
	 ** that point to overflow pages. The pointer map entries for all these
	 ** pages need to be changed.
	 **
	 ** If pDbPage is an overflow page, then the first 4 bytes may store a
	 ** pointer to a subsequent overflow page. If this is the case, then
	 ** the pointer map needs to be updated for the subsequent overflow page.
	 */
	if int32(int32(eType)) == int32(PTRMAP_BTREE) || int32(int32(eType)) == int32(PTRMAP_ROOTPAGE) {
		*(*int32)(unsafe.Pointer(bp + 4)) = _setChildPtrmaps(tls, pDbPage)
		if *(*int32)(unsafe.Pointer(bp + 4)) != SQLITE_OK {
			return *(*int32)(unsafe.Pointer(bp + 4))
		}
	} else {
		nextOvfl = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pDbPage)).FaData)
		if nextOvfl != uint32(0) {
			_ptrmapPut(tls, pBt, nextOvfl, uint8(PTRMAP_OVERFLOW2), iFreePage, bp+4)
			if *(*int32)(unsafe.Pointer(bp + 4)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 4))
			}
		}
	}
	/* Fix the database pointer on page iPtrPage that pointed at iDbPage so
	 ** that it points at iFreePage. Also fix the pointer map entry for
	 ** iPtrPage.
	 */
	if int32(int32(eType)) != int32(PTRMAP_ROOTPAGE) {
		*(*int32)(unsafe.Pointer(bp + 4)) = _btreeGetPage(tls, pBt, iPtrPage, bp, 0)
		if *(*int32)(unsafe.Pointer(bp + 4)) != SQLITE_OK {
			return *(*int32)(unsafe.Pointer(bp + 4))
		}
		*(*int32)(unsafe.Pointer(bp + 4)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
		if *(*int32)(unsafe.Pointer(bp + 4)) != SQLITE_OK {
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return *(*int32)(unsafe.Pointer(bp + 4))
		}
		*(*int32)(unsafe.Pointer(bp + 4)) = _modifyPagePointer(tls, *(*uintptr)(unsafe.Pointer(bp)), iDbPage, iFreePage, eType)
		_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
			_ptrmapPut(tls, pBt, iFreePage, eType, iPtrPage, bp+4)
		}
	}
	return *(*int32)(unsafe.Pointer(bp + 4))
}

// C documentation
//
//	/*
//	** Perform a single step of an incremental-vacuum. If successful, return
//	** SQLITE_OK. If there is no work to do (and therefore no point in
//	** calling this function again), return SQLITE_DONE. Or, if an error
//	** occurs, return some other error code.
//	**
//	** More specifically, this function attempts to re-organize the database so
//	** that the last page of the file currently in use is no longer in use.
//	**
//	** Parameter nFin is the number of pages that this database would contain
//	** were this function called until it returns SQLITE_DONE.
//	**
//	** If the bCommit parameter is non-zero, this function assumes that the
//	** caller will keep calling incrVacuumStep() until it returns SQLITE_DONE
//	** or an error. bCommit is passed true for an auto-vacuum-on-commit
//	** operation, or false for an incremental vacuum.
//	*/
func _incrVacuumStep(tls *libc.TLS, pBt uintptr, nFin TPgno, iLastPg TPgno, bCommit int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var dbSize, iNear, nFreeList TPgno
	var eMode Tu8
	var rc int32
	var _ /* eType at bp+0 */ Tu8
	var _ /* iFreePg at bp+16 */ TPgno
	var _ /* iFreePg at bp+8 */ TPgno
	var _ /* iPtrPage at bp+4 */ TPgno
	var _ /* pFreePg at bp+12 */ uintptr
	var _ /* pFreePg at bp+24 */ uintptr
	var _ /* pLastPg at bp+20 */ uintptr
	_, _, _, _, _ = dbSize, eMode, iNear, nFreeList, rc
	if !(_ptrmapPageno(tls, pBt, iLastPg) == iLastPg) && iLastPg != uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
		nFreeList = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36)
		if nFreeList == uint32(0) {
			return int32(SQLITE_DONE)
		}
		rc = _ptrmapGet(tls, pBt, iLastPg, bp, bp+4)
		if rc != SQLITE_OK {
			return rc
		}
		if int32(*(*Tu8)(unsafe.Pointer(bp))) == int32(PTRMAP_ROOTPAGE) {
			return _sqlite3CorruptError(tls, int32(74557))
		}
		if int32(*(*Tu8)(unsafe.Pointer(bp))) == int32(PTRMAP_FREEPAGE) {
			if bCommit == 0 {
				rc = _allocateBtreePage(tls, pBt, bp+12, bp+8, iLastPg, uint8(BTALLOC_EXACT))
				if rc != SQLITE_OK {
					return rc
				}
				_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
			}
		} else {
			eMode = uint8(BTALLOC_ANY) /* Mode parameter for allocateBtreePage() */
			iNear = uint32(0)          /* nearby parameter for allocateBtreePage() */
			rc = _btreeGetPage(tls, pBt, iLastPg, bp+20, 0)
			if rc != SQLITE_OK {
				return rc
			}
			/* If bCommit is zero, this loop runs exactly once and page pLastPg
			 ** is swapped with the first free page pulled off the free list.
			 **
			 ** On the other hand, if bCommit is greater than zero, then keep
			 ** looping until a free-page located within the first nFin pages
			 ** of the file is found.
			 */
			if bCommit == 0 {
				eMode = uint8(BTALLOC_LE)
				iNear = nFin
			}
			for cond := true; cond; cond = bCommit != 0 && *(*TPgno)(unsafe.Pointer(bp + 16)) > nFin {
				dbSize = _btreePagecount(tls, pBt)
				rc = _allocateBtreePage(tls, pBt, bp+24, bp+16, iNear, eMode)
				if rc != SQLITE_OK {
					_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 20)))
					return rc
				}
				_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
				if *(*TPgno)(unsafe.Pointer(bp + 16)) > dbSize {
					_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 20)))
					return _sqlite3CorruptError(tls, int32(74609))
				}
			}
			rc = _relocatePage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp + 20)), *(*Tu8)(unsafe.Pointer(bp)), *(*TPgno)(unsafe.Pointer(bp + 4)), *(*TPgno)(unsafe.Pointer(bp + 16)), bCommit)
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 20)))
			if rc != SQLITE_OK {
				return rc
			}
		}
	}
	if bCommit == 0 {
		for cond := true; cond; cond = iLastPg == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) || _ptrmapPageno(tls, pBt, iLastPg) == iLastPg {
			iLastPg--
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FbDoTruncate = uint8(1)
		(*TBtShared)(unsafe.Pointer(pBt)).FnPage = iLastPg
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The database opened by the first argument is an auto-vacuum database
//	** nOrig pages in size containing nFree free pages. Return the expected
//	** size of the database in pages following an auto-vacuum operation.
//	*/
func _finalDbSize(tls *libc.TLS, pBt uintptr, nOrig TPgno, nFree TPgno) (r TPgno) {
	var nEntry int32
	var nFin, nPtrmap TPgno
	_, _, _ = nEntry, nFin, nPtrmap /* Return value */
	nEntry = int32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize / uint32(5))
	nPtrmap = (nFree - nOrig + _ptrmapPageno(tls, pBt, nOrig) + uint32(uint32(nEntry))) / uint32(uint32(nEntry))
	nFin = nOrig - nFree - nPtrmap
	if nOrig > uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) && nFin < uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
		nFin--
	}
	for _ptrmapPageno(tls, pBt, nFin) == nFin || nFin == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
		nFin--
	}
	return nFin
}

// C documentation
//
//	/*
//	** A write-transaction must be opened before calling this function.
//	** It performs a single unit of work towards an incremental vacuum.
//	**
//	** If the incremental vacuum is finished after this function has run,
//	** SQLITE_DONE is returned. If it is not finished, but no error occurred,
//	** SQLITE_OK is returned. Otherwise an SQLite error code.
//	*/
func _sqlite3BtreeIncrVacuum(tls *libc.TLS, p uintptr) (r int32) {
	var nFin, nFree, nOrig TPgno
	var pBt uintptr
	var rc int32
	_, _, _, _, _ = nFin, nFree, nOrig, pBt, rc
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	if !((*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		rc = int32(SQLITE_DONE)
	} else {
		nOrig = _btreePagecount(tls, pBt)
		nFree = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36)
		nFin = _finalDbSize(tls, pBt, nOrig, nFree)
		if nOrig < nFin || nFree >= nOrig {
			rc = _sqlite3CorruptError(tls, int32(74677))
		} else {
			if nFree > uint32(0) {
				rc = _saveAllCursors(tls, pBt, uint32(0), uintptr(0))
				if rc == SQLITE_OK {
					_invalidateAllOverflowCache(tls, pBt)
					rc = _incrVacuumStep(tls, pBt, nFin, nOrig, 0)
				}
				if rc == SQLITE_OK {
					rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
					_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+28, (*TBtShared)(unsafe.Pointer(pBt)).FnPage)
				}
			} else {
				rc = int32(SQLITE_DONE)
			}
		}
	}
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** This routine is called prior to sqlite3PagerCommit when a transaction
//	** is committed for an auto-vacuum database.
//	*/
func _autoVacuumCommit(tls *libc.TLS, p uintptr) (r int32) {
	var db, pBt, pPager uintptr
	var iDb, rc int32
	var iFree, nFin, nFree, nOrig, nVac TPgno
	_, _, _, _, _, _, _, _, _, _ = db, iDb, iFree, nFin, nFree, nOrig, nVac, pBt, pPager, rc
	rc = SQLITE_OK
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	pPager = (*TBtShared)(unsafe.Pointer(pBt)).FpPager
	_invalidateAllOverflowCache(tls, pBt)
	if !((*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum != 0) { /* Database size before freeing */
		nOrig = _btreePagecount(tls, pBt)
		if _ptrmapPageno(tls, pBt, nOrig) == nOrig || nOrig == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
			/* It is not possible to create a database for which the final page
			 ** is either a pointer-map page or the pending-byte page. If one
			 ** is encountered, this indicates corruption.
			 */
			return _sqlite3CorruptError(tls, int32(74728))
		}
		nFree = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36)
		db = (*TBtree)(unsafe.Pointer(p)).Fdb
		if (*Tsqlite3)(unsafe.Pointer(db)).FxAutovacPages != 0 {
			iDb = 0
			for {
				if !(iDb < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
					break
				}
				if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt == p {
					break
				}
				goto _1
			_1:
				;
				iDb++
			}
			nVac = (*(*func(*libc.TLS, uintptr, uintptr, Tu32, Tu32, Tu32) uint32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAutovacPages})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, nOrig, nFree, (*TBtShared)(unsafe.Pointer(pBt)).FpageSize)
			if nVac > nFree {
				nVac = nFree
			}
			if nVac == uint32(0) {
				return SQLITE_OK
			}
		} else {
			nVac = nFree
		}
		nFin = _finalDbSize(tls, pBt, nOrig, nVac)
		if nFin > nOrig {
			return _sqlite3CorruptError(tls, int32(74755))
		}
		if nFin < nOrig {
			rc = _saveAllCursors(tls, pBt, uint32(0), uintptr(0))
		}
		iFree = nOrig
		for {
			if !(iFree > nFin && rc == SQLITE_OK) {
				break
			}
			rc = _incrVacuumStep(tls, pBt, nFin, iFree, libc.BoolInt32(nVac == nFree))
			goto _2
		_2:
			;
			iFree--
		}
		if (rc == int32(SQLITE_DONE) || rc == SQLITE_OK) && nFree > uint32(0) {
			rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
			if nVac == nFree {
				_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+32, uint32(0))
				_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36, uint32(0))
			}
			_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+28, nFin)
			(*TBtShared)(unsafe.Pointer(pBt)).FbDoTruncate = uint8(1)
			(*TBtShared)(unsafe.Pointer(pBt)).FnPage = nFin
		}
		if rc != SQLITE_OK {
			_sqlite3PagerRollback(tls, pPager)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This routine does the first phase of a two-phase commit.  This routine
//	** causes a rollback journal to be created (if it does not already exist)
//	** and populated with enough information so that if a power loss occurs
//	** the database can be restored to its original state by playing back
//	** the journal.  Then the contents of the journal are flushed out to
//	** the disk.  After the journal is safely on oxide, the changes to the
//	** database are written into the database file and flushed to oxide.
//	** At the end of this call, the rollback journal still exists on the
//	** disk and we are still holding all locks, so the transaction has not
//	** committed.  See sqlite3BtreeCommitPhaseTwo() for the second phase of the
//	** commit process.
//	**
//	** This call is a no-op if no write-transaction is currently active on pBt.
//	**
//	** Otherwise, sync the database file for the btree pBt. zSuperJrnl points to
//	** the name of a super-journal file that should be written into the
//	** individual journal file, or is NULL, indicating no super-journal file
//	** (single database transaction).
//	**
//	** When this is called, the super-journal should already have been
//	** created, populated with this journal pointer and synced to disk.
//	**
//	** Once this is routine has returned, the only thing required to commit
//	** the write-transaction for this database file is to delete the journal.
//	*/
func _sqlite3BtreeCommitPhaseOne(tls *libc.TLS, p uintptr, zSuperJrnl uintptr) (r int32) {
	var pBt uintptr
	var rc int32
	_, _ = pBt, rc
	rc = SQLITE_OK
	if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == int32(TRANS_WRITE) {
		pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
		_sqlite3BtreeEnter(tls, p)
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			rc = _autoVacuumCommit(tls, p)
			if rc != SQLITE_OK {
				_sqlite3BtreeLeave(tls, p)
				return rc
			}
		}
		if (*TBtShared)(unsafe.Pointer(pBt)).FbDoTruncate != 0 {
			_sqlite3PagerTruncateImage(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, (*TBtShared)(unsafe.Pointer(pBt)).FnPage)
		}
		rc = _sqlite3PagerCommitPhaseOne(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, zSuperJrnl, 0)
		_sqlite3BtreeLeave(tls, p)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called from both BtreeCommitPhaseTwo() and BtreeRollback()
//	** at the conclusion of a transaction.
//	*/
func _btreeEndTransaction(tls *libc.TLS, p uintptr) {
	var db, pBt uintptr
	_, _ = db, pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	db = (*TBtree)(unsafe.Pointer(p)).Fdb
	(*TBtShared)(unsafe.Pointer(pBt)).FbDoTruncate = uint8(0)
	if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) > TRANS_NONE && (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead > int32(1) {
		/* If there are other active statements that belong to this database
		 ** handle, downgrade to a read-only transaction. The other statements
		 ** may still be reading from the database.  */
		_downgradeAllSharedCacheTableLocks(tls, p)
		(*TBtree)(unsafe.Pointer(p)).FinTrans = uint8(TRANS_READ)
	} else {
		/* If the handle had any kind of transaction open, decrement the
		 ** transaction count of the shared btree. If the transaction count
		 ** reaches 0, set the shared state to TRANS_NONE. The unlockBtreeIfUnused()
		 ** call below will unlock the pager.  */
		if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) != TRANS_NONE {
			_clearAllSharedCacheTableLocks(tls, p)
			(*TBtShared)(unsafe.Pointer(pBt)).FnTransaction--
			if 0 == (*TBtShared)(unsafe.Pointer(pBt)).FnTransaction {
				(*TBtShared)(unsafe.Pointer(pBt)).FinTransaction = uint8(TRANS_NONE)
			}
		}
		/* Set the current transaction state to TRANS_NONE and unlock the
		 ** pager if this call closed the only read or write transaction.  */
		(*TBtree)(unsafe.Pointer(p)).FinTrans = uint8(TRANS_NONE)
		_unlockBtreeIfUnused(tls, pBt)
	}
}

// C documentation
//
//	/*
//	** Commit the transaction currently in progress.
//	**
//	** This routine implements the second phase of a 2-phase commit.  The
//	** sqlite3BtreeCommitPhaseOne() routine does the first phase and should
//	** be invoked prior to calling this routine.  The sqlite3BtreeCommitPhaseOne()
//	** routine did all the work of writing information out to disk and flushing the
//	** contents so that they are written onto the disk platter.  All this
//	** routine has to do is delete or truncate or zero the header in the
//	** the rollback journal (which causes the transaction to commit) and
//	** drop locks.
//	**
//	** Normally, if an error occurs while the pager layer is attempting to
//	** finalize the underlying journal file, this function returns an error and
//	** the upper layer will attempt a rollback. However, if the second argument
//	** is non-zero then this b-tree transaction is part of a multi-file
//	** transaction. In this case, the transaction has already been committed
//	** (by deleting a super-journal file) and the caller will ignore this
//	** functions return code. So, even if an error occurs in the pager layer,
//	** reset the b-tree objects internal state to indicate that the write
//	** transaction has been closed. This is quite safe, as the pager will have
//	** transitioned to the error state.
//	**
//	** This will release the write lock on the database file.  If there
//	** are no active cursors, it also releases the read lock.
//	*/
func _sqlite3BtreeCommitPhaseTwo(tls *libc.TLS, p uintptr, bCleanup int32) (r int32) {
	var pBt uintptr
	var rc int32
	_, _ = pBt, rc
	if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == TRANS_NONE {
		return SQLITE_OK
	}
	_sqlite3BtreeEnter(tls, p)
	/* If the handle has a write-transaction open, commit the shared-btrees
	 ** transaction and set the shared state to TRANS_READ.
	 */
	if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == int32(TRANS_WRITE) {
		pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
		rc = _sqlite3PagerCommitPhaseTwo(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
		if rc != SQLITE_OK && bCleanup == 0 {
			_sqlite3BtreeLeave(tls, p)
			return rc
		}
		(*TBtree)(unsafe.Pointer(p)).FiBDataVersion-- /* Compensate for pPager->iDataVersion++; */
		(*TBtShared)(unsafe.Pointer(pBt)).FinTransaction = uint8(TRANS_READ)
		_btreeClearHasContent(tls, pBt)
	}
	_btreeEndTransaction(tls, p)
	_sqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Do both phases of a commit.
//	*/
func _sqlite3BtreeCommit(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	_sqlite3BtreeEnter(tls, p)
	rc = _sqlite3BtreeCommitPhaseOne(tls, p, uintptr(0))
	if rc == SQLITE_OK {
		rc = _sqlite3BtreeCommitPhaseTwo(tls, p, 0)
	}
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** This routine sets the state to CURSOR_FAULT and the error
//	** code to errCode for every cursor on any BtShared that pBtree
//	** references.  Or if the writeOnly flag is set to 1, then only
//	** trip write cursors and leave read cursors unchanged.
//	**
//	** Every cursor is a candidate to be tripped, including cursors
//	** that belong to other database connections that happen to be
//	** sharing the cache with pBtree.
//	**
//	** This routine gets called when a rollback occurs. If the writeOnly
//	** flag is true, then only write-cursors need be tripped - read-only
//	** cursors save their current positions so that they may continue
//	** following the rollback. Or, if writeOnly is false, all cursors are
//	** tripped. In general, writeOnly is false if the transaction being
//	** rolled back modified the database schema. In this case b-tree root
//	** pages may be moved or deleted from the database altogether, making
//	** it unsafe for read cursors to continue.
//	**
//	** If the writeOnly flag is true and an error is encountered while
//	** saving the current position of a read-only cursor, all cursors,
//	** including all read-cursors are tripped.
//	**
//	** SQLITE_OK is returned if successful, or if an error occurs while
//	** saving a cursor position, an SQLite error code.
//	*/
func _sqlite3BtreeTripAllCursors(tls *libc.TLS, pBtree uintptr, errCode int32, writeOnly int32) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	rc = SQLITE_OK
	if pBtree != 0 {
		_sqlite3BtreeEnter(tls, pBtree)
		p = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(pBtree)).FpBt)).FpCursor
		for {
			if !(p != 0) {
				break
			}
			if writeOnly != 0 && int32((*TBtCursor)(unsafe.Pointer(p)).FcurFlags)&int32(BTCF_WriteFlag) == 0 {
				if int32((*TBtCursor)(unsafe.Pointer(p)).FeState) == CURSOR_VALID || int32((*TBtCursor)(unsafe.Pointer(p)).FeState) == int32(CURSOR_SKIPNEXT) {
					rc = _saveCursorPosition(tls, p)
					if rc != SQLITE_OK {
						_sqlite3BtreeTripAllCursors(tls, pBtree, rc, 0)
						break
					}
				}
			} else {
				_sqlite3BtreeClearCursor(tls, p)
				(*TBtCursor)(unsafe.Pointer(p)).FeState = uint8(CURSOR_FAULT)
				(*TBtCursor)(unsafe.Pointer(p)).FskipNext = errCode
			}
			_btreeReleaseAllCursorPages(tls, p)
			goto _1
		_1:
			;
			p = (*TBtCursor)(unsafe.Pointer(p)).FpNext
		}
		_sqlite3BtreeLeave(tls, pBtree)
	}
	return rc
}

// C documentation
//
//	/*
//	** Set the pBt->nPage field correctly, according to the current
//	** state of the database.  Assume pBt->pPage1 is valid.
//	*/
func _btreeSetNPage(tls *libc.TLS, pBt uintptr, pPage1 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* nPage at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = int32(_sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+28))
	if *(*int32)(unsafe.Pointer(bp)) == 0 {
		_sqlite3PagerPagecount(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, bp)
	}
	(*TBtShared)(unsafe.Pointer(pBt)).FnPage = uint32(*(*int32)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Rollback the transaction in progress.
//	**
//	** If tripCode is not SQLITE_OK then cursors will be invalidated (tripped).
//	** Only write cursors are tripped if writeOnly is true but all cursors are
//	** tripped if writeOnly is false.  Any attempt to use
//	** a tripped cursor will result in an error.
//	**
//	** This will release the write lock on the database file.  If there
//	** are no active cursors, it also releases the read lock.
//	*/
func _sqlite3BtreeRollback(tls *libc.TLS, p uintptr, tripCode int32, writeOnly int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pBt uintptr
	var rc, rc2, rc21, v1 int32
	var _ /* pPage1 at bp+0 */ uintptr
	_, _, _, _, _ = pBt, rc, rc2, rc21, v1
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	if tripCode == SQLITE_OK {
		v1 = _saveAllCursors(tls, pBt, uint32(0), uintptr(0))
		tripCode = v1
		rc = v1
		if rc != 0 {
			writeOnly = 0
		}
	} else {
		rc = SQLITE_OK
	}
	if tripCode != 0 {
		rc2 = _sqlite3BtreeTripAllCursors(tls, p, tripCode, writeOnly)
		if rc2 != SQLITE_OK {
			rc = rc2
		}
	}
	if int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == int32(TRANS_WRITE) {
		rc21 = _sqlite3PagerRollback(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
		if rc21 != SQLITE_OK {
			rc = rc21
		}
		/* The rollback may have destroyed the pPage1->aData value.  So
		 ** call btreeGetPage() on page 1 again to make
		 ** sure pPage1->aData is set correctly. */
		if _btreeGetPage(tls, pBt, uint32(1), bp, 0) == SQLITE_OK {
			_btreeSetNPage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp)))
			_releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FinTransaction = uint8(TRANS_READ)
		_btreeClearHasContent(tls, pBt)
	}
	_btreeEndTransaction(tls, p)
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Start a statement subtransaction. The subtransaction can be rolled
//	** back independently of the main transaction. You must start a transaction
//	** before starting a subtransaction. The subtransaction is ended automatically
//	** if the main transaction commits or rolls back.
//	**
//	** Statement subtransactions are used around individual SQL statements
//	** that are contained within a BEGIN...COMMIT block.  If a constraint
//	** error occurs within the statement, the effect of that one statement
//	** can be rolled back without having to rollback the entire transaction.
//	**
//	** A statement sub-transaction is implemented as an anonymous savepoint. The
//	** value passed as the second parameter is the total number of savepoints,
//	** including the new anonymous savepoint, open on the B-Tree. i.e. if there
//	** are no active savepoints and no other statement-transactions open,
//	** iStatement is 1. This anonymous savepoint can be released or rolled back
//	** using the sqlite3BtreeSavepoint() function.
//	*/
func _sqlite3BtreeBeginStmt(tls *libc.TLS, p uintptr, iStatement int32) (r int32) {
	var pBt uintptr
	var rc int32
	_, _ = pBt, rc
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	/* At the pager level, a statement transaction is a savepoint with
	 ** an index greater than all savepoints created explicitly using
	 ** SQL statements. It is illegal to open, release or rollback any
	 ** such savepoints while the statement transaction savepoint is active.
	 */
	rc = _sqlite3PagerOpenSavepoint(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, iStatement)
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** The second argument to this function, op, is always SAVEPOINT_ROLLBACK
//	** or SAVEPOINT_RELEASE. This function either releases or rolls back the
//	** savepoint identified by parameter iSavepoint, depending on the value
//	** of op.
//	**
//	** Normally, iSavepoint is greater than or equal to zero. However, if op is
//	** SAVEPOINT_ROLLBACK, then iSavepoint may also be -1. In this case the
//	** contents of the entire transaction are rolled back. This is different
//	** from a normal transaction rollback, as no locks are released and the
//	** transaction remains open.
//	*/
func _sqlite3BtreeSavepoint(tls *libc.TLS, p uintptr, op int32, iSavepoint int32) (r int32) {
	var pBt uintptr
	var rc int32
	_, _ = pBt, rc
	rc = SQLITE_OK
	if p != 0 && int32((*TBtree)(unsafe.Pointer(p)).FinTrans) == int32(TRANS_WRITE) {
		pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
		_sqlite3BtreeEnter(tls, p)
		if op == int32(SAVEPOINT_ROLLBACK) {
			rc = _saveAllCursors(tls, pBt, uint32(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = _sqlite3PagerSavepoint(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, op, iSavepoint)
		}
		if rc == SQLITE_OK {
			if iSavepoint < 0 && int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_INITIALLY_EMPTY) != 0 {
				(*TBtShared)(unsafe.Pointer(pBt)).FnPage = uint32(0)
			}
			rc = _newDatabase(tls, pBt)
			_btreeSetNPage(tls, pBt, (*TBtShared)(unsafe.Pointer(pBt)).FpPage1)
			/* pBt->nPage might be zero if the database was corrupt when
			 ** the transaction was started. Otherwise, it must be at least 1.  */
		}
		_sqlite3BtreeLeave(tls, p)
	}
	return rc
}

// C documentation
//
//	/*
//	** Create a new cursor for the BTree whose root is on the page
//	** iTable. If a read-only cursor is requested, it is assumed that
//	** the caller already has at least a read-only transaction open
//	** on the database already. If a write-cursor is requested, then
//	** the caller is assumed to have an open write transaction.
//	**
//	** If the BTREE_WRCSR bit of wrFlag is clear, then the cursor can only
//	** be used for reading.  If the BTREE_WRCSR bit is set, then the cursor
//	** can be used for reading or for writing if other conditions for writing
//	** are also met.  These are the conditions that must be met in order
//	** for writing to be allowed:
//	**
//	** 1:  The cursor must have been opened with wrFlag containing BTREE_WRCSR
//	**
//	** 2:  Other database connections that share the same pager cache
//	**     but which are not in the READ_UNCOMMITTED state may not have
//	**     cursors open with wrFlag==0 on the same table.  Otherwise
//	**     the changes made by this write cursor would be visible to
//	**     the read cursors in the other database connection.
//	**
//	** 3:  The database must be writable (not on read-only media)
//	**
//	** 4:  There must be an active transaction.
//	**
//	** The BTREE_FORDELETE bit of wrFlag may optionally be set if BTREE_WRCSR
//	** is set.  If FORDELETE is set, that is a hint to the implementation that
//	** this cursor will only be used to seek to and delete entries of an index
//	** as part of a larger DELETE statement.  The FORDELETE hint is not used by
//	** this implementation.  But in a hypothetical alternative storage engine
//	** in which index entries are automatically deleted when corresponding table
//	** rows are deleted, the FORDELETE flag is a hint that all SEEK and DELETE
//	** operations on this cursor can be no-ops and all READ operations can
//	** return a null row (2-bytes: 0x01 0x00).
//	**
//	** No checking is done to make sure that page iTable really is the
//	** root page of a b-tree.  If it is not, then the cursor acquired
//	** will not work correctly.
//	**
//	** It is assumed that the sqlite3BtreeCursorZero() has been called
//	** on pCur to initialize the memory space prior to invoking this routine.
//	*/
func _btreeCursor(tls *libc.TLS, p uintptr, iTable TPgno, wrFlag int32, pKeyInfo uintptr, pCur uintptr) (r int32) {
	var pBt, pX, p2, p3 uintptr
	_, _, _, _ = pBt, pX, p2, p3
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt /* Looping over other all cursors */
	/* The following assert statements verify that if this is a sharable
	 ** b-tree database, the connection is holding the required table locks,
	 ** and that no other connection has any open cursor that conflicts with
	 ** this lock.  The iTable<1 term disables the check for corrupt schemas. */
	/* Assert that the caller has opened the required transaction. */
	if iTable <= uint32(1) {
		if iTable < uint32(1) {
			return _sqlite3CorruptError(tls, int32(75219))
		} else {
			if _btreePagecount(tls, pBt) == uint32(0) {
				iTable = uint32(0)
			}
		}
	}
	/* Now that no other errors can occur, finish filling in the BtCursor
	 ** variables and link the cursor into the BtShared list.  */
	(*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot = iTable
	(*TBtCursor)(unsafe.Pointer(pCur)).FiPage = int8(-int32(1))
	(*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo = pKeyInfo
	(*TBtCursor)(unsafe.Pointer(pCur)).FpBtree = p
	(*TBtCursor)(unsafe.Pointer(pCur)).FpBt = pBt
	(*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags = uint8(0)
	/* If there are two or more cursors on the same btree, then all such
	 ** cursors *must* have the BTCF_Multiple flag set. */
	pX = (*TBtShared)(unsafe.Pointer(pBt)).FpCursor
	for {
		if !(pX != 0) {
			break
		}
		if (*TBtCursor)(unsafe.Pointer(pX)).FpgnoRoot == iTable {
			p2 = pX + 1
			*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | libc.Int32FromInt32(BTCF_Multiple))
			(*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags = uint8(BTCF_Multiple)
		}
		goto _1
	_1:
		;
		pX = (*TBtCursor)(unsafe.Pointer(pX)).FpNext
	}
	(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
	(*TBtCursor)(unsafe.Pointer(pCur)).FpNext = (*TBtShared)(unsafe.Pointer(pBt)).FpCursor
	(*TBtShared)(unsafe.Pointer(pBt)).FpCursor = pCur
	if wrFlag != 0 {
		p3 = pCur + 1
		*(*Tu8)(unsafe.Pointer(p3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p3))) | libc.Int32FromInt32(BTCF_WriteFlag))
		(*TBtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags = uint8(0)
		if (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace == uintptr(0) {
			return _allocateTempSpace(tls, pBt)
		}
	} else {
		(*TBtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags = uint8(PAGER_GET_READONLY)
	}
	return SQLITE_OK
}

func _btreeCursorWithLock(tls *libc.TLS, p uintptr, iTable TPgno, wrFlag int32, pKeyInfo uintptr, pCur uintptr) (r int32) {
	var rc int32
	_ = rc
	_sqlite3BtreeEnter(tls, p)
	rc = _btreeCursor(tls, p, iTable, wrFlag, pKeyInfo, pCur)
	_sqlite3BtreeLeave(tls, p)
	return rc
}

func _sqlite3BtreeCursor(tls *libc.TLS, p uintptr, iTable TPgno, wrFlag int32, pKeyInfo uintptr, pCur uintptr) (r int32) {
	if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
		return _btreeCursorWithLock(tls, p, iTable, wrFlag, pKeyInfo, pCur)
	} else {
		return _btreeCursor(tls, p, iTable, wrFlag, pKeyInfo, pCur)
	}
	return r
}

// C documentation
//
//	/*
//	** Return the size of a BtCursor object in bytes.
//	**
//	** This interfaces is needed so that users of cursors can preallocate
//	** sufficient storage to hold a cursor.  The BtCursor object is opaque
//	** to users so they cannot do the sizeof() themselves - they must call
//	** this routine.
//	*/
func _sqlite3BtreeCursorSize(tls *libc.TLS) (r int32) {
	return int32((libc.Uint32FromInt64(200) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
}

// C documentation
//
//	/*
//	** Initialize memory that will be converted into a BtCursor object.
//	**
//	** The simple approach here would be to memset() the entire object
//	** to zero.  But it turns out that the apPage[] and aiIdx[] arrays
//	** do not need to be zeroed and they are large, so we can save a lot
//	** of run-time by skipping the initialization of those elements.
//	*/
func _sqlite3BtreeCursorZero(tls *libc.TLS, p uintptr) {
	libc.Xmemset(tls, p, 0, uint32(libc.UintptrFromInt32(0)+20))
}

// C documentation
//
//	/*
//	** Close a cursor.  The read lock on the database file is released
//	** when the last cursor is closed.
//	*/
func _sqlite3BtreeCloseCursor(tls *libc.TLS, pCur uintptr) (r int32) {
	var pBt, pBtree, pPrev uintptr
	_, _, _ = pBt, pBtree, pPrev
	pBtree = (*TBtCursor)(unsafe.Pointer(pCur)).FpBtree
	if pBtree != 0 {
		pBt = (*TBtCursor)(unsafe.Pointer(pCur)).FpBt
		_sqlite3BtreeEnter(tls, pBtree)
		if (*TBtShared)(unsafe.Pointer(pBt)).FpCursor == pCur {
			(*TBtShared)(unsafe.Pointer(pBt)).FpCursor = (*TBtCursor)(unsafe.Pointer(pCur)).FpNext
		} else {
			pPrev = (*TBtShared)(unsafe.Pointer(pBt)).FpCursor
			for cond := true; cond; cond = pPrev != 0 {
				if (*TBtCursor)(unsafe.Pointer(pPrev)).FpNext == pCur {
					(*TBtCursor)(unsafe.Pointer(pPrev)).FpNext = (*TBtCursor)(unsafe.Pointer(pCur)).FpNext
					break
				}
				pPrev = (*TBtCursor)(unsafe.Pointer(pPrev)).FpNext
			}
		}
		_btreeReleaseAllCursorPages(tls, pCur)
		_unlockBtreeIfUnused(tls, pBt)
		Xsqlite3_free(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow)
		Xsqlite3_free(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpKey)
		if int32((*TBtShared)(unsafe.Pointer(pBt)).FopenFlags)&int32(BTREE_SINGLE) != 0 && (*TBtShared)(unsafe.Pointer(pBt)).FpCursor == uintptr(0) {
			/* Since the BtShared is not sharable, there is no need to
			 ** worry about the missing sqlite3BtreeLeave() call here.  */
			_sqlite3BtreeClose(tls, pBtree)
		} else {
			_sqlite3BtreeLeave(tls, pBtree)
		}
		(*TBtCursor)(unsafe.Pointer(pCur)).FpBtree = uintptr(0)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Make sure the BtCursor* given in the argument has a valid
//	** BtCursor.info structure.  If it is not already valid, call
//	** btreeParseCell() to fill it in.
//	**
//	** BtCursor.info is a cache of the information in the current cell.
//	** Using this cache reduces the number of calls to btreeParseCell().
//	*/
func _getCellInfo(tls *libc.TLS, pCur uintptr) {
	var p1 uintptr
	_ = p1
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize) == 0 {
		p1 = pCur + 1
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTCF_ValidNKey))
		_btreeParseCell(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage, int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix), pCur+32)
	} else {
	}
}

func _sqlite3BtreeCursorIsValidNN(tls *libc.TLS, pCur uintptr) (r int32) {
	return libc.BoolInt32(int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID)
}

// C documentation
//
//	/*
//	** Return the value of the integer key or "rowid" for a table btree.
//	** This routine is only valid for a cursor that is pointing into a
//	** ordinary table btree.  If the cursor points to an index btree or
//	** is invalid, the result of this routine is undefined.
//	*/
func _sqlite3BtreeIntegerKey(tls *libc.TLS, pCur uintptr) (r Ti64) {
	_getCellInfo(tls, pCur)
	return (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey
}

// C documentation
//
//	/*
//	** Pin or unpin a cursor.
//	*/
func _sqlite3BtreeCursorPin(tls *libc.TLS, pCur uintptr) {
	var p1 uintptr
	_ = p1
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTCF_Pinned))
}

func _sqlite3BtreeCursorUnpin(tls *libc.TLS, pCur uintptr) {
	var p1 uintptr
	_ = p1
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(BTCF_Pinned))
}

// C documentation
//
//	/*
//	** Return the offset into the database file for the start of the
//	** payload to which the cursor is pointing.
//	*/
func _sqlite3BtreeOffset(tls *libc.TLS, pCur uintptr) (r Ti64) {
	_getCellInfo(tls, pCur)
	return int64((*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FpageSize)*(int64((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fpgno)-int64(1)) + int64(int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload)-int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FaData))
}

// C documentation
//
//	/*
//	** Return the number of bytes of payload for the entry that pCur is
//	** currently pointing to.  For table btrees, this will be the amount
//	** of data.  For index btrees, this will be the size of the key.
//	**
//	** The caller must guarantee that the cursor is pointing to a non-NULL
//	** valid entry.  In other words, the calling procedure must guarantee
//	** that the cursor has Cursor.eState==CURSOR_VALID.
//	*/
func _sqlite3BtreePayloadSize(tls *libc.TLS, pCur uintptr) (r Tu32) {
	_getCellInfo(tls, pCur)
	return (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload
}

// C documentation
//
//	/*
//	** Return an upper bound on the size of any record for the table
//	** that the cursor is pointing into.
//	**
//	** This is an optimization.  Everything will still work if this
//	** routine always returns 2147483647 (which is the largest record
//	** that SQLite can handle) or more.  But returning a smaller value might
//	** prevent large memory allocations when trying to interpret a
//	** corrupt database.
//	**
//	** The current implementation merely returns the size of the underlying
//	** database file.
//	*/
func _sqlite3BtreeMaxRecordSize(tls *libc.TLS, pCur uintptr) (r Tsqlite3_int64) {
	return int64((*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FpageSize) * int64((*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FnPage)
}

// C documentation
//
//	/*
//	** Given the page number of an overflow page in the database (parameter
//	** ovfl), this function finds the page number of the next page in the
//	** linked list of overflow pages. If possible, it uses the auto-vacuum
//	** pointer-map data instead of reading the content of page ovfl to do so.
//	**
//	** If an error occurs an SQLite error code is returned. Otherwise:
//	**
//	** The page number of the next overflow page in the linked list is
//	** written to *pPgnoNext. If page ovfl is the last page in its linked
//	** list, *pPgnoNext is set to zero.
//	**
//	** If ppPage is not NULL, and a reference to the MemPage object corresponding
//	** to page number pOvfl was obtained, then *ppPage is set to point to that
//	** reference. It is the responsibility of the caller to call releasePage()
//	** on *ppPage to free the reference. In no reference was obtained (because
//	** the pointer-map was used to obtain the value for *pPgnoNext), then
//	** *ppPage is set to zero.
//	*/
func _getOverflowPage(tls *libc.TLS, pBt uintptr, ovfl TPgno, ppPage uintptr, pPgnoNext uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iGuess, next TPgno
	var rc, v1, v2 int32
	var _ /* eType at bp+8 */ Tu8
	var _ /* pPage at bp+0 */ uintptr
	var _ /* pgno at bp+4 */ TPgno
	_, _, _, _, _ = iGuess, next, rc, v1, v2
	next = uint32(0)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = SQLITE_OK
	/* Try to find the next page in the overflow list using the
	 ** autovacuum pointer-map pages. Guess that the next page in
	 ** the overflow list is page number (ovfl+1). If that guess turns
	 ** out to be wrong, fall back to loading the data of page
	 ** number ovfl to determine the next page number.
	 */
	if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
		iGuess = ovfl + uint32(1)
		for _ptrmapPageno(tls, pBt, iGuess) == iGuess || iGuess == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
			iGuess++
		}
		if iGuess <= _btreePagecount(tls, pBt) {
			rc = _ptrmapGet(tls, pBt, iGuess, bp+8, bp+4)
			if rc == SQLITE_OK && int32(*(*Tu8)(unsafe.Pointer(bp + 8))) == int32(PTRMAP_OVERFLOW2) && *(*TPgno)(unsafe.Pointer(bp + 4)) == ovfl {
				next = iGuess
				rc = int32(SQLITE_DONE)
			}
		}
	}
	if rc == SQLITE_OK {
		if ppPage == uintptr(0) {
			v1 = int32(PAGER_GET_READONLY)
		} else {
			v1 = 0
		}
		rc = _btreeGetPage(tls, pBt, ovfl, bp, v1)
		if rc == SQLITE_OK {
			next = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData)
		}
	}
	*(*TPgno)(unsafe.Pointer(pPgnoNext)) = next
	if ppPage != 0 {
		*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp))
	} else {
		_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	if rc == int32(SQLITE_DONE) {
		v2 = SQLITE_OK
	} else {
		v2 = rc
	}
	return v2
}

// C documentation
//
//	/*
//	** Copy data from a buffer to a page, or from a page to a buffer.
//	**
//	** pPayload is a pointer to data stored on database page pDbPage.
//	** If argument eOp is false, then nByte bytes of data are copied
//	** from pPayload to the buffer pointed at by pBuf. If eOp is true,
//	** then sqlite3PagerWrite() is called on pDbPage and nByte bytes
//	** of data are copied from the buffer pBuf to pPayload.
//	**
//	** SQLITE_OK is returned on success, otherwise an error code.
//	*/
func _copyPayload(tls *libc.TLS, pPayload uintptr, pBuf uintptr, nByte int32, eOp int32, pDbPage uintptr) (r int32) {
	var rc int32
	_ = rc
	if eOp != 0 {
		/* Copy data from buffer to page (a write operation) */
		rc = _sqlite3PagerWrite(tls, pDbPage)
		if rc != SQLITE_OK {
			return rc
		}
		libc.Xmemcpy(tls, pPayload, pBuf, uint32(uint32(nByte)))
	} else {
		/* Copy data from page to buffer (a read operation) */
		libc.Xmemcpy(tls, pBuf, pPayload, uint32(uint32(nByte)))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function is used to read or overwrite payload information
//	** for the entry that the pCur cursor is pointing to. The eOp
//	** argument is interpreted as follows:
//	**
//	**   0: The operation is a read. Populate the overflow cache.
//	**   1: The operation is a write. Populate the overflow cache.
//	**
//	** A total of "amt" bytes are read or written beginning at "offset".
//	** Data is read to or from the buffer pBuf.
//	**
//	** The content being read or written might appear on the main page
//	** or be scattered out on multiple overflow pages.
//	**
//	** If the current cursor entry uses one or more overflow pages
//	** this function may allocate space for and lazily populate
//	** the overflow page-list cache array (BtCursor.aOverflow).
//	** Subsequent calls use this cache to make seeking to the supplied offset
//	** more efficient.
//	**
//	** Once an overflow page-list cache has been allocated, it must be
//	** invalidated if some other cursor writes to the same table, or if
//	** the cursor is moved to a different row. Additionally, in auto-vacuum
//	** mode, the following events may invalidate an overflow page-list cache.
//	**
//	**   * An incremental vacuum,
//	**   * A commit in auto_vacuum="full" mode,
//	**   * Creating a table (may require moving an overflow page).
//	*/
func _accessPayload(tls *libc.TLS, pCur uintptr, offset Tu32, amt Tu32, pBuf uintptr, eOp int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, a1, iIdx, nOvfl, rc, v2 int32
	var aNew, aPayload, aWrite, fd, pBt, pBufStart, pPage, p1 uintptr
	var ovflSize Tu32
	var _ /* aSave at bp+4 */ [4]Tu8
	var _ /* nextPage at bp+0 */ TPgno
	var _ /* pDbPage at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, a1, aNew, aPayload, aWrite, fd, iIdx, nOvfl, ovflSize, pBt, pBufStart, pPage, rc, v2, p1
	rc = SQLITE_OK
	iIdx = 0
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage /* Btree page of current entry */
	pBt = (*TBtCursor)(unsafe.Pointer(pCur)).FpBt     /* Btree this cursor belongs to */
	pBufStart = pBuf                                  /* Start of original out buffer */
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix) >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
		return _sqlite3CorruptError(tls, int32(75624))
	}
	_getCellInfo(tls, pCur)
	aPayload = (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload
	if uint32(int32(int32(aPayload))-int32((*TMemPage)(unsafe.Pointer(pPage)).FaData)) > (*TBtShared)(unsafe.Pointer(pBt)).FusableSize-uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) {
		/* Trying to read or write past the end of the data is an error.  The
		 ** conditional above is really:
		 **    &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
		 ** but is recast into its current form to avoid integer overflow problems
		 */
		return _sqlite3CorruptError(tls, int32(75639))
	}
	/* Check if data must be read/written to/from the btree page itself. */
	if offset < uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) {
		a = int32(int32(amt))
		if uint32(uint32(a))+offset > uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) {
			a = int32(uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) - offset)
		}
		rc = _copyPayload(tls, aPayload+uintptr(offset), pBuf, a, eOp, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
		offset = uint32(0)
		pBuf += uintptr(a)
		amt -= uint32(uint32(a))
	} else {
		offset -= uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)
	}
	if rc == SQLITE_OK && amt > uint32(0) {
		ovflSize = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4)
		*(*TPgno)(unsafe.Pointer(bp)) = _sqlite3Get4byte(tls, aPayload+uintptr((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal))
		/* If the BtCursor.aOverflow[] has not been allocated, allocate it now.
		 **
		 ** The aOverflow[] array is sized at one entry for each overflow page
		 ** in the overflow chain. The page number of the first overflow page is
		 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
		 ** means "not yet known" (the cache is lazily populated).
		 */
		if int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_ValidOvfl) == 0 {
			nOvfl = int32(((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload - uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) + ovflSize - uint32(1)) / ovflSize)
			if (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow == uintptr(0) || nOvfl*libc.Int32FromInt64(4) > _sqlite3MallocSize(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow) {
				if _sqlite3FaultSim(tls, int32(413)) != 0 {
					aNew = uintptr(0)
				} else {
					aNew = _sqlite3Realloc(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow, uint64(uint32(nOvfl*int32(2))*uint32(4)))
				}
				if aNew == uintptr(0) {
					return int32(SQLITE_NOMEM)
				} else {
					(*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow = aNew
				}
			}
			libc.Xmemset(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow, 0, uint32(uint32(nOvfl))*uint32(4))
			p1 = pCur + 1
			*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTCF_ValidOvfl))
		} else {
			/* Sanity check the validity of the overflow page cache */
			/* If the overflow page-list cache has been allocated and the
			 ** entry for the first required overflow page is valid, skip
			 ** directly to it.
			 */
			if *(*TPgno)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(offset/ovflSize)*4)) != 0 {
				iIdx = int32(offset / ovflSize)
				*(*TPgno)(unsafe.Pointer(bp)) = *(*TPgno)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx)*4))
				offset = offset % ovflSize
			}
		}
		for *(*TPgno)(unsafe.Pointer(bp)) != 0 {
			/* If required, populate the overflow page-list cache. */
			if *(*TPgno)(unsafe.Pointer(bp)) > (*TBtShared)(unsafe.Pointer(pBt)).FnPage {
				return _sqlite3CorruptError(tls, int32(75710))
			}
			*(*TPgno)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx)*4)) = *(*TPgno)(unsafe.Pointer(bp))
			if offset >= ovflSize {
				/* The only reason to read this page is to obtain the page
				 ** number for the next page in the overflow chain. The page
				 ** data is not required. So first try to lookup the overflow
				 ** page-list cache, if any, then fall back to the getOverflowPage()
				 ** function.
				 */
				if *(*TPgno)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx+int32(1))*4)) != 0 {
					*(*TPgno)(unsafe.Pointer(bp)) = *(*TPgno)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx+int32(1))*4))
				} else {
					rc = _getOverflowPage(tls, pBt, *(*TPgno)(unsafe.Pointer(bp)), uintptr(0), bp)
				}
				offset -= ovflSize
			} else {
				/* Need to read this page properly. It contains some of the
				 ** range of data that is being read (eOp==0) or written (eOp!=0).
				 */
				a1 = int32(int32(amt))
				if uint32(uint32(a1))+offset > ovflSize {
					a1 = int32(ovflSize - offset)
				}
				/* If all the following are true:
				 **
				 **   1) this is a read operation, and
				 **   2) data is required from the start of this overflow page, and
				 **   3) there are no dirty pages in the page-cache
				 **   4) the database is file-backed, and
				 **   5) the page is not in the WAL file
				 **   6) at least 4 bytes have already been read into the output buffer
				 **
				 ** then data can be read directly from the database file into the
				 ** output buffer, bypassing the page-cache altogether. This speeds
				 ** up loading large records that span many overflow pages.
				 */
				if eOp == 0 && offset == uint32(0) && _sqlite3PagerDirectReadOk(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, *(*TPgno)(unsafe.Pointer(bp))) != 0 && pBuf+uintptr(-libc.Int32FromInt32(4)) >= pBufStart {
					fd = _sqlite3PagerFile(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
					aWrite = pBuf + uintptr(-libc.Int32FromInt32(4))
					/* due to (6) */
					libc.Xmemcpy(tls, bp+4, aWrite, uint32(4))
					rc = _sqlite3OsRead(tls, fd, aWrite, a1+int32(4), int64((*TBtShared)(unsafe.Pointer(pBt)).FpageSize)*int64(*(*TPgno)(unsafe.Pointer(bp))-libc.Uint32FromInt32(1)))
					*(*TPgno)(unsafe.Pointer(bp)) = _sqlite3Get4byte(tls, aWrite)
					libc.Xmemcpy(tls, aWrite, bp+4, uint32(4))
				} else {
					if eOp == 0 {
						v2 = int32(PAGER_GET_READONLY)
					} else {
						v2 = 0
					}
					rc = _sqlite3PagerGet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, *(*TPgno)(unsafe.Pointer(bp)), bp+8, v2)
					if rc == SQLITE_OK {
						aPayload = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
						*(*TPgno)(unsafe.Pointer(bp)) = _sqlite3Get4byte(tls, aPayload)
						rc = _copyPayload(tls, aPayload+uintptr(offset+uint32(4)), pBuf, a1, eOp, *(*uintptr)(unsafe.Pointer(bp + 8)))
						_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
						offset = uint32(0)
					}
				}
				amt -= uint32(uint32(a1))
				if amt == uint32(0) {
					return rc
				}
				pBuf += uintptr(a1)
			}
			if rc != 0 {
				break
			}
			iIdx++
		}
	}
	if rc == SQLITE_OK && amt > uint32(0) {
		/* Overflow chain ends prematurely */
		return _sqlite3CorruptError(tls, int32(75794))
	}
	return rc
}

// C documentation
//
//	/*
//	** Read part of the payload for the row at which that cursor pCur is currently
//	** pointing.  "amt" bytes will be transferred into pBuf[].  The transfer
//	** begins at "offset".
//	**
//	** pCur can be pointing to either a table or an index b-tree.
//	** If pointing to a table btree, then the content section is read.  If
//	** pCur is pointing to an index b-tree then the key section is read.
//	**
//	** For sqlite3BtreePayload(), the caller must ensure that pCur is pointing
//	** to a valid row in the table.  For sqlite3BtreePayloadChecked(), the
//	** cursor might be invalid or might need to be restored before being read.
//	**
//	** Return SQLITE_OK on success or an error code if anything goes
//	** wrong.  An error is returned if "offset+amt" is larger than
//	** the available payload.
//	*/
func _sqlite3BtreePayload(tls *libc.TLS, pCur uintptr, offset Tu32, amt Tu32, pBuf uintptr) (r int32) {
	return _accessPayload(tls, pCur, offset, amt, pBuf, 0)
}

// C documentation
//
//	/*
//	** This variant of sqlite3BtreePayload() works even if the cursor has not
//	** in the CURSOR_VALID state.  It is only used by the sqlite3_blob_read()
//	** interface.
//	*/
func _accessPayloadChecked(tls *libc.TLS, pCur uintptr, offset Tu32, amt Tu32, pBuf uintptr) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == int32(CURSOR_INVALID) {
		return int32(SQLITE_ABORT)
	}
	rc = _btreeRestoreCursorPosition(tls, pCur)
	if rc != 0 {
		v1 = rc
	} else {
		v1 = _accessPayload(tls, pCur, offset, amt, pBuf, 0)
	}
	return v1
}

func _sqlite3BtreePayloadChecked(tls *libc.TLS, pCur uintptr, offset Tu32, amt Tu32, pBuf uintptr) (r int32) {
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID {
		return _accessPayload(tls, pCur, offset, amt, pBuf, 0)
	} else {
		return _accessPayloadChecked(tls, pCur, offset, amt, pBuf)
	}
	return r
}

// C documentation
//
//	/*
//	** Return a pointer to payload information from the entry that the
//	** pCur cursor is pointing to.  The pointer is to the beginning of
//	** the key if index btrees (pPage->intKey==0) and is the data for
//	** table btrees (pPage->intKey==1). The number of bytes of available
//	** key/data is written into *pAmt.  If *pAmt==0, then the value
//	** returned will not be a valid pointer.
//	**
//	** This routine is an optimization.  It is common for the entire key
//	** and data to fit on the local page and for there to be no overflow
//	** pages.  When that is so, this routine can be used to access the
//	** key and data without making a copy.  If the key and/or data spills
//	** onto overflow pages, then accessPayload() must be used to reassemble
//	** the key/data and copy it into a preallocated buffer.
//	**
//	** The pointer returned by this routine looks directly into the cached
//	** page of the database.  The data might change or move the next time
//	** any btree routine is called.
//	*/
func _fetchPayload(tls *libc.TLS, pCur uintptr, pAmt uintptr) (r uintptr) {
	var amt, v1 int32
	_, _ = amt, v1
	amt = int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)
	if amt > int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FaDataEnd)-int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload) {
		/* There is too little space on the page for the expected amount
		 ** of local content. Database must be corrupt. */
		if 0 > int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FaDataEnd)-int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload) {
			v1 = 0
		} else {
			v1 = int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FaDataEnd) - int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload)
		}
		amt = v1
	}
	*(*Tu32)(unsafe.Pointer(pAmt)) = uint32(uint32(amt))
	return (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload
}

// C documentation
//
//	/*
//	** For the entry that cursor pCur is point to, return as
//	** many bytes of the key or data as are available on the local
//	** b-tree page.  Write the number of available bytes into *pAmt.
//	**
//	** The pointer returned is ephemeral.  The key/data may move
//	** or be destroyed on the next call to any Btree routine,
//	** including calls from other threads against the same cache.
//	** Hence, a mutex on the BtShared should be held prior to calling
//	** this routine.
//	**
//	** These routines is used to get quick access to key and data
//	** in the common case where no overflow pages are used.
//	*/
func _sqlite3BtreePayloadFetch(tls *libc.TLS, pCur uintptr, pAmt uintptr) (r uintptr) {
	return _fetchPayload(tls, pCur, pAmt)
}

// C documentation
//
//	/*
//	** Move the cursor down to a new child page.  The newPgno argument is the
//	** page number of the child page to move to.
//	**
//	** This function returns SQLITE_CORRUPT if the page-header flags field of
//	** the new child page does not match the flags field of the parent (i.e.
//	** if an intkey page appears to be the parent of a non-intkey page, or
//	** vice-versa).
//	*/
func _moveToChild(tls *libc.TLS, pCur uintptr, newPgno Tu32) (r int32) {
	var rc int32
	var v2 Ti8
	var v3, p1 uintptr
	_, _, _, _ = rc, v2, v3, p1
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) >= libc.Int32FromInt32(BTCURSOR_MAX_DEPTH)-libc.Int32FromInt32(1) {
		return _sqlite3CorruptError(tls, int32(75932))
	}
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
	*(*Tu16)(unsafe.Pointer(pCur + 72 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*2)) = (*TBtCursor)(unsafe.Pointer(pCur)).Fix
	*(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*4)) = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(0)
	(*TBtCursor)(unsafe.Pointer(pCur)).FiPage++
	rc = _getAndInitPage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBt, newPgno, pCur+116, int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags))
	if rc == SQLITE_OK && (int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell) < int32(1) || int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FintKey) != int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurIntKey)) {
		_releasePage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
		rc = _sqlite3CorruptError(tls, int32(75946))
	}
	if rc != 0 {
		v3 = pCur + 68
		*(*Ti8)(unsafe.Pointer(v3))--
		v2 = *(*Ti8)(unsafe.Pointer(v3))
		(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(v2)*4))
	}
	return rc
}

// C documentation
//
//	/*
//	** Move the cursor up to the parent page.
//	**
//	** pCur->idx is set to the cell index that contains the pointer
//	** to the page we are coming from.  If we are coming from the
//	** right-most child page then pCur->idx is set to one more than
//	** the largest cell index.
//	*/
func _moveToParent(tls *libc.TLS, pCur uintptr) {
	var pLeaf, v3, p1 uintptr
	var v2 Ti8
	_, _, _, _ = pLeaf, v2, v3, p1
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
	(*TBtCursor)(unsafe.Pointer(pCur)).Fix = *(*Tu16)(unsafe.Pointer(pCur + 72 + uintptr(int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)-int32(1))*2))
	pLeaf = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	v3 = pCur + 68
	*(*Ti8)(unsafe.Pointer(v3))--
	v2 = *(*Ti8)(unsafe.Pointer(v3))
	(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(v2)*4))
	_releasePageNotNull(tls, pLeaf)
}

// C documentation
//
//	/*
//	** Move the cursor to point to the root page of its b-tree structure.
//	**
//	** If the table has a virtual root page, then the cursor is moved to point
//	** to the virtual root page instead of the actual root page. A table has a
//	** virtual root page when the actual root page contains no cells and a
//	** single child page. This can only happen with the table rooted at page 1.
//	**
//	** If the b-tree structure is empty, the cursor state is set to
//	** CURSOR_INVALID and this routine returns SQLITE_EMPTY. Otherwise,
//	** the cursor is set to point to the first cell located on the root
//	** (or virtual root) page and the cursor state is set to CURSOR_VALID.
//	**
//	** If this function returns successfully, it may be assumed that the
//	** page-header flags indicate that the [virtual] root-page is the expected
//	** kind of b-tree page (i.e. if when opening the cursor the caller did not
//	** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
//	** indicating a table b-tree, or if the caller did specify a KeyInfo
//	** structure the flags byte is set to 0x02 or 0x0A, indicating an index
//	** b-tree).
//	*/
func _moveToRoot(tls *libc.TLS, pCur uintptr) (r int32) {
	var pRoot, v2, v3, p4 uintptr
	var rc int32
	var subpage TPgno
	var v1 Ti8
	_, _, _, _, _, _, _ = pRoot, rc, subpage, v1, v2, v3, p4
	rc = SQLITE_OK
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) >= 0 {
		if (*TBtCursor)(unsafe.Pointer(pCur)).FiPage != 0 {
			_releasePageNotNull(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
			for {
				v2 = pCur + 68
				*(*Ti8)(unsafe.Pointer(v2))--
				v1 = *(*Ti8)(unsafe.Pointer(v2))
				if !(v1 != 0) {
					break
				}
				_releasePageNotNull(tls, *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*4)))
			}
			v3 = *(*uintptr)(unsafe.Pointer(pCur + 120))
			(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = v3
			pRoot = v3
			goto skip_init
		}
	} else {
		if (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot == uint32(0) {
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
			return int32(SQLITE_EMPTY)
		} else {
			if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
				if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == int32(CURSOR_FAULT) {
					return (*TBtCursor)(unsafe.Pointer(pCur)).FskipNext
				}
				_sqlite3BtreeClearCursor(tls, pCur)
			}
			rc = _getAndInitPage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBt, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur+116, int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags))
			if rc != SQLITE_OK {
				(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
				return rc
			}
			(*TBtCursor)(unsafe.Pointer(pCur)).FiPage = 0
			(*TBtCursor)(unsafe.Pointer(pCur)).FcurIntKey = (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FintKey
		}
	}
	pRoot = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	/* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
	 ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
	 ** NULL, the caller expects a table b-tree. If this is not the case,
	 ** return an SQLITE_CORRUPT error.
	 **
	 ** Earlier versions of SQLite assumed that this test could not fail
	 ** if the root page was already loaded when this function was called (i.e.
	 ** if pCur->iPage>=0). But this is not so if the database is corrupted
	 ** in such a way that page pRoot is linked into a second b-tree table
	 ** (or the freelist).  */
	if int32((*TMemPage)(unsafe.Pointer(pRoot)).FisInit) == 0 || libc.BoolInt32((*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo == uintptr(0)) != int32((*TMemPage)(unsafe.Pointer(pRoot)).FintKey) {
		return _sqlite3CorruptError(tls, int32(76081))
	}
	goto skip_init
skip_init:
	;
	(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(0)
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	p4 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p4))) & ^(libc.Int32FromInt32(BTCF_AtLast) | libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
	if int32((*TMemPage)(unsafe.Pointer(pRoot)).FnCell) > 0 {
		(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_VALID)
	} else {
		if !((*TMemPage)(unsafe.Pointer(pRoot)).Fleaf != 0) {
			if (*TMemPage)(unsafe.Pointer(pRoot)).Fpgno != uint32(1) {
				return _sqlite3CorruptError(tls, int32(76093))
			}
			subpage = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pRoot)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pRoot)).FhdrOffset)+int32(8)))
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_VALID)
			rc = _moveToChild(tls, pCur, subpage)
		} else {
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
			rc = int32(SQLITE_EMPTY)
		}
	}
	return rc
}

// 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(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix))))))))
		rc = _moveToChild(tls, pCur, pgno)
	}
	return rc
}

// C documentation
//
//	/*
//	** Move the cursor down to the right-most leaf entry beneath the
//	** page to which it is currently pointing.  Notice the difference
//	** between moveToLeftmost() and moveToRightmost().  moveToLeftmost()
//	** finds the left-most entry beneath the *entry* whereas moveToRightmost()
//	** finds the right-most entry beneath the *page*.
//	**
//	** The right-most entry is the one with the largest key - the last
//	** key in ascending order.
//	*/
func _moveToRightmost(tls *libc.TLS, pCur uintptr) (r int32) {
	var pPage, v1 uintptr
	var pgno TPgno
	var rc int32
	_, _, _, _ = pPage, pgno, rc, v1
	rc = SQLITE_OK
	pPage = uintptr(0)
	for {
		v1 = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		pPage = v1
		if !!((*TMemPage)(unsafe.Pointer(v1)).Fleaf != 0) {
			break
		}
		pgno = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
		(*TBtCursor)(unsafe.Pointer(pCur)).Fix = (*TMemPage)(unsafe.Pointer(pPage)).FnCell
		rc = _moveToChild(tls, pCur, pgno)
		if rc != 0 {
			return rc
		}
	}
	(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) - int32(1))
	return SQLITE_OK
}

// C documentation
//
//	/* Move the cursor to the first entry in the table.  Return SQLITE_OK
//	** on success.  Set *pRes to 0 if the cursor actually points to something
//	** or set *pRes to 1 if the table is empty.
//	*/
func _sqlite3BtreeFirst(tls *libc.TLS, pCur uintptr, pRes uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _moveToRoot(tls, pCur)
	if rc == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRes)) = 0
		rc = _moveToLeftmost(tls, pCur)
	} else {
		if rc == int32(SQLITE_EMPTY) {
			*(*int32)(unsafe.Pointer(pRes)) = int32(1)
			rc = SQLITE_OK
		}
	}
	return rc
}

// C documentation
//
//	/* Move the cursor to the last entry in the table.  Return SQLITE_OK
//	** on success.  Set *pRes to 0 if the cursor actually points to something
//	** or set *pRes to 1 if the table is empty.
//	*/
func _btreeLast(tls *libc.TLS, pCur uintptr, pRes uintptr) (r int32) {
	var rc int32
	var p1, p2 uintptr
	_, _, _ = rc, p1, p2
	rc = _moveToRoot(tls, pCur)
	if rc == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRes)) = 0
		rc = _moveToRightmost(tls, pCur)
		if rc == SQLITE_OK {
			p1 = pCur + 1
			*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTCF_AtLast))
		} else {
			p2 = pCur + 1
			*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(BTCF_AtLast))
		}
	} else {
		if rc == int32(SQLITE_EMPTY) {
			*(*int32)(unsafe.Pointer(pRes)) = int32(1)
			rc = SQLITE_OK
		}
	}
	return rc
}

func _sqlite3BtreeLast(tls *libc.TLS, pCur uintptr, pRes uintptr) (r int32) {
	/* If the cursor already points to the last entry, this is a no-op. */
	if CURSOR_VALID == int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) && int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_AtLast) != 0 {
		*(*int32)(unsafe.Pointer(pRes)) = 0
		return SQLITE_OK
	}
	return _btreeLast(tls, pCur, pRes)
}

// 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, p4 uintptr
	var _ /* nCellKey at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _, _ = c, chldPg, idx, lwr, pCell, pPage, rc, upr, v3, p4
	/* If the cursor is already positioned at the point we are trying
	 ** to move to, then just return without doing any work */
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID && int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_ValidNKey) != 0 {
		if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == intKey {
			*(*int32)(unsafe.Pointer(pRes)) = 0
			return SQLITE_OK
		}
		if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey < intKey {
			if int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_AtLast) != 0 {
				*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(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)(unsafe.Pointer(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 = int32((*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(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))))
			if (*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf != 0 {
				for {
					v3 = pCell
					pCell++
					if !(int32(0x80) <= int32(*(*Tu8)(unsafe.Pointer(v3)))) {
						break
					}
					if pCell >= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
						return _sqlite3CorruptError(tls, int32(76342))
					}
				}
			}
			_sqlite3GetVarint(tls, pCell, bp)
			if *(*Ti64)(unsafe.Pointer(bp)) < intKey {
				lwr = idx + int32(1)
				if lwr > upr {
					c = -int32(1)
					break
				}
			} else {
				if *(*Ti64)(unsafe.Pointer(bp)) > intKey {
					upr = idx - int32(1)
					if lwr > upr {
						c = +libc.Int32FromInt32(1)
						break
					}
				} else {
					(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(uint16(idx))
					if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
						lwr = idx
						goto moveto_table_next_layer
					} else {
						p4 = pCur + 1
						*(*Tu8)(unsafe.Pointer(p4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p4))) | libc.Int32FromInt32(BTCF_ValidNKey))
						(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey = *(*Ti64)(unsafe.Pointer(bp))
						(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
						*(*int32)(unsafe.Pointer(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 = uint16(uint16(idx))
			*(*int32)(unsafe.Pointer(pRes)) = c
			rc = SQLITE_OK
			goto moveto_table_finish
		}
		goto moveto_table_next_layer
	moveto_table_next_layer:
		;
		if lwr >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
		} else {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*lwr)))))))
		}
		(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(uint16(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
//
//	/*
//	** Compare the "idx"-th cell on the page the cursor pCur is currently
//	** pointing to to 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, pCur uintptr, idx int32, pIdxKey uintptr, xRecordCompare TRecordCompare) (r int32) {
	var c, nCell, v1 int32
	var pCell, pPage uintptr
	var v2 bool
	_, _, _, _, _, _ = c, nCell, pCell, pPage, v1, v2
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage /* Size of the pCell cell in bytes */
	pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))))
	nCell = int32(*(*Tu8)(unsafe.Pointer(pCell)))
	if nCell <= int32((*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.  */
		c = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})))(tls, nCell, pCell+1, pIdxKey)
	} else {
		if v2 = !(int32(*(*Tu8)(unsafe.Pointer(pCell + 1)))&libc.Int32FromInt32(0x80) != 0); v2 {
			v1 = nCell&libc.Int32FromInt32(0x7f)<<libc.Int32FromInt32(7) + int32(*(*Tu8)(unsafe.Pointer(pCell + 1)))
			nCell = v1
		}
		if v2 && v1 <= int32((*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.  */
			c = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{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 (non-zero) if pCur is current pointing to the last
//	** page of a table.
//	*/
func _cursorOnLastPage(tls *libc.TLS, pCur uintptr) (r int32) {
	var i int32
	var pPage uintptr
	_, _ = i, pPage
	i = 0
	for {
		if !(i < int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)) {
			break
		}
		pPage = *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(i)*4))
		if int32(*(*Tu16)(unsafe.Pointer(pCur + 72 + uintptr(i)*2))) < int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			return 0
		}
		goto _1
	_1:
		;
		i++
	}
	return int32(1)
}

// 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, v6 int32
	var chldPg TPgno
	var pCell, pCellBody, pCellKey, pPage, v11, p3, p8, p9 uintptr
	var xRecordCompare TRecordCompare
	var v10 Ti8
	var v2, v7 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, c1, chldPg, idx, lwr, nCell, nOverrun, pCell, pCellBody, pCellKey, pPage, rc, upr, xRecordCompare, v1, v10, v11, v2, v6, v7, p3, p8, p9
	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 int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID && (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf != 0 && _cursorOnLastPage(tls, pCur) != 0 {
		if v2 = int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix) == int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell)-int32(1); v2 {
			v1 = _indexCellCompare(tls, pCur, int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix), pIdxKey, xRecordCompare)
			c = v1
		}
		if v2 && v1 <= 0 && int32((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(pRes)) = c
			return SQLITE_OK /* Cursor already pointing at the correct spot */
		}
		if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) > 0 && _indexCellCompare(tls, pCur, 0, pIdxKey, xRecordCompare) <= 0 && int32((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK {
			p3 = pCur + 1
			*(*Tu8)(unsafe.Pointer(p3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(BTCF_ValidOvfl))
			if !((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FisInit != 0) {
				return _sqlite3CorruptError(tls, int32(76538))
			}
			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)(unsafe.Pointer(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 = int32((*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(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*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 = int32(*(*Tu8)(unsafe.Pointer(pCell)))
			if nCell <= int32((*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.  */
				c1 = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})))(tls, nCell, pCell+1, pIdxKey)
			} else {
				if v7 = !(int32(*(*Tu8)(unsafe.Pointer(pCell + 1)))&libc.Int32FromInt32(0x80) != 0); v7 {
					v6 = nCell&libc.Int32FromInt32(0x7f)<<libc.Int32FromInt32(7) + int32(*(*Tu8)(unsafe.Pointer(pCell + 1)))
					nCell = v6
				}
				if v7 && v6 <= int32((*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.  */
					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+32)
					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) || uint32(uint32(nCell))/(*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FusableSize > (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FnPage {
						rc = _sqlite3CorruptError(tls, int32(76625))
						goto moveto_index_finish
					}
					pCellKey = _sqlite3Malloc(tls, uint64(nCell+nOverrun))
					if pCellKey == uintptr(0) {
						rc = int32(SQLITE_NOMEM)
						goto moveto_index_finish
					}
					(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(uint16(idx))
					rc = _accessPayload(tls, pCur, uint32(0), uint32(uint32(nCell)), pCellKey, 0)
					libc.Xmemset(tls, pCellKey+uintptr(nCell), 0, uint32(uint32(nOverrun))) /* Fix uninit warnings */
					p8 = pCur + 1
					*(*Tu8)(unsafe.Pointer(p8)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p8))) & ^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)(unsafe.Pointer(pRes)) = 0
					rc = SQLITE_OK
					(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(uint16(idx))
					if (*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode != 0 {
						rc = _sqlite3CorruptError(tls, int32(76657))
					}
					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 = uint16(uint16(idx))
			*(*int32)(unsafe.Pointer(pRes)) = c1
			rc = SQLITE_OK
			goto moveto_index_finish
		}
		if lwr >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
		} else {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*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)
		p9 = pCur + 1
		*(*Tu8)(unsafe.Pointer(p9)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p9))) & ^(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(76688))
		}
		*(*Tu16)(unsafe.Pointer(pCur + 72 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*2)) = uint16(uint16(lwr))
		*(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*4)) = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(0)
		(*TBtCursor)(unsafe.Pointer(pCur)).FiPage++
		rc = _getAndInitPage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBt, chldPg, pCur+116, int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags))
		if rc == SQLITE_OK && (int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell) < int32(1) || int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FintKey) != int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurIntKey)) {
			_releasePage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
			rc = _sqlite3CorruptError(tls, int32(76699))
		}
		if rc != 0 {
			v11 = pCur + 68
			*(*Ti8)(unsafe.Pointer(v11))--
			v10 = *(*Ti8)(unsafe.Pointer(v11))
			(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(v10)*4))
			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
//
//	/*
//	** Return TRUE if the cursor is not pointing at an entry of the table.
//	**
//	** TRUE will be returned after a call to sqlite3BtreeNext() moves
//	** past the last entry in the table or sqlite3BtreePrev() moves past
//	** the first entry.  TRUE is also returned if the table is empty.
//	*/
func _sqlite3BtreeEof(tls *libc.TLS, pCur uintptr) (r int32) {
	/* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
	 ** have been deleted? This API will need to change to return an error code
	 ** as well as the boolean result value.
	 */
	return libc.BoolInt32(CURSOR_VALID != int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState))
}

// C documentation
//
//	/*
//	** Return an estimate for the number of rows in the table that pCur is
//	** pointing to.  Return a negative number if no estimate is currently
//	** available.
//	*/
func _sqlite3BtreeRowCountEst(tls *libc.TLS, pCur uintptr) (r Ti64) {
	var i Tu8
	var n Ti64
	_, _ = i, n
	/* Currently this interface is only called by the OP_IfSizeBetween
	 ** opcode and the OP_Count opcode with P3=1.  In either case,
	 ** the cursor will always be valid unless the btree is empty. */
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		return 0
	}
	if int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf) == 0 {
		return int64(-int32(1))
	}
	n = int64((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell)
	i = uint8(0)
	for {
		if !(int32(int32(i)) < int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)) {
			break
		}
		n *= int64((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(i)*4)))).FnCell)
		goto _1
	_1:
		;
		i++
	}
	return n
}

// C documentation
//
//	/*
//	** Advance the cursor to the next entry in the database.
//	** Return value:
//	**
//	**    SQLITE_OK        success
//	**    SQLITE_DONE      cursor is already pointing at the last element
//	**    otherwise        some kind of error occurred
//	**
//	** The main entry point is sqlite3BtreeNext().  That routine is optimized
//	** for the common case of merely incrementing the cell counter BtCursor.aiIdx
//	** to the next cell on the current page.  The (slower) btreeNext() 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 in sqlite3BtreeNext(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.  SQLite btree implementation does not use
//	** this hint, but COMDB2 does.
//	*/
func _btreeNext(tls *libc.TLS, pCur uintptr) (r int32) {
	var idx, rc, v1 int32
	var pPage, v3 uintptr
	var v2 Tu16
	_, _, _, _, _, _ = idx, pPage, rc, v1, v2, v3
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		if int32((*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) == int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) {
			return int32(SQLITE_DONE)
		}
		if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == int32(CURSOR_SKIPNEXT) {
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_VALID)
			if (*TBtCursor)(unsafe.Pointer(pCur)).FskipNext > 0 {
				return SQLITE_OK
			}
		}
	}
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	v3 = pCur + 70
	*(*Tu16)(unsafe.Pointer(v3))++
	v2 = *(*Tu16)(unsafe.Pointer(v3))
	idx = int32(v2)
	if _sqlite3FaultSim(tls, int32(412)) != 0 {
		(*TMemPage)(unsafe.Pointer(pPage)).FisInit = uint8(0)
	}
	if !((*TMemPage)(unsafe.Pointer(pPage)).FisInit != 0) {
		return _sqlite3CorruptError(tls, int32(76800))
	}
	if idx >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
		if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
			rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8))))
			if rc != 0 {
				return rc
			}
			return _moveToLeftmost(tls, pCur)
		}
		for cond := true; cond; cond = int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix) >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) == 0 {
				(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
				return int32(SQLITE_DONE)
			}
			_moveToParent(tls, pCur)
			pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		}
		if (*TMemPage)(unsafe.Pointer(pPage)).FintKey != 0 {
			return _sqlite3BtreeNext(tls, pCur, 0)
		} else {
			return SQLITE_OK
		}
	}
	if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
		return SQLITE_OK
	} else {
		return _moveToLeftmost(tls, pCur)
	}
	return r
}

func _sqlite3BtreeNext(tls *libc.TLS, pCur uintptr, flags int32) (r int32) {
	var pPage, v3, p1 uintptr
	var v2 Tu16
	_, _, _, _ = pPage, v2, v3, p1
	_ = flags /* Used in COMDB2 but not native SQLite */
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		return _btreeNext(tls, pCur)
	}
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	v3 = pCur + 70
	*(*Tu16)(unsafe.Pointer(v3))++
	v2 = *(*Tu16)(unsafe.Pointer(v3))
	if int32(v2) >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
		(*TBtCursor)(unsafe.Pointer(pCur)).Fix--
		return _btreeNext(tls, pCur)
	}
	if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
		return SQLITE_OK
	} else {
		return _moveToLeftmost(tls, pCur)
	}
	return r
}

// 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 int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		if int32((*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) == int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) {
			return int32(SQLITE_DONE)
		}
		if int32(CURSOR_SKIPNEXT) == int32((*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(76893))
	}
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		idx = int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
		rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))))))
		if rc != 0 {
			return rc
		}
		rc = _moveToRightmost(tls, pCur)
	} else {
		for int32((*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--
		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
}

func _sqlite3BtreePrevious(tls *libc.TLS, pCur uintptr, flags int32) (r int32) {
	var p1 uintptr
	_ = p1
	_ = flags /* Used in COMDB2 but not native SQLite */
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(BTCF_AtLast) | libc.Int32FromInt32(BTCF_ValidOvfl) | libc.Int32FromInt32(BTCF_ValidNKey)))
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID || int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix) == 0 || int32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf) == 0 {
		return _btreePrevious(tls, pCur)
	}
	(*TBtCursor)(unsafe.Pointer(pCur)).Fix--
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Allocate a new page from the database file.
//	**
//	** The new page is marked as dirty.  (In other words, sqlite3PagerWrite()
//	** has already been called on the new page.)  The new page has also
//	** been referenced and the calling routine is responsible for calling
//	** sqlite3PagerUnref() on the new page when it is done.
//	**
//	** SQLITE_OK is returned on success.  Any other return value indicates
//	** an error.  *ppPage is set to NULL in the event of an error.
//	**
//	** If the "nearby" parameter is not 0, then an effort is made to
//	** locate a page close to the page number "nearby".  This can be used in an
//	** attempt to keep related pages close to each other in the database file,
//	** which in turn can make database access faster.
//	**
//	** If the eMode parameter is BTALLOC_EXACT and the nearby page exists
//	** anywhere on the free-list, then it is guaranteed to be returned.  If
//	** eMode is BTALLOC_LT then the page returned will be less than or equal
//	** to nearby if any such page exists.  If eMode is BTALLOC_ANY then there
//	** are no restrictions on which page is returned.
//	*/
func _allocateBtreePage(tls *libc.TLS, pBt uintptr, ppPage uintptr, pPgno uintptr, nearby TPgno, eMode Tu8) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aData, pPage1, pPrevTrunk uintptr
	var bNoContent, d2, dist, noContent, rc, v5, v6 int32
	var closest, i, k, n, nSearch, v1 Tu32
	var iNewTrunk, iPage, iTrunk, mxPage TPgno
	var searchList Tu8
	var v2 bool
	var _ /* eType at bp+4 */ Tu8
	var _ /* pNewTrunk at bp+8 */ uintptr
	var _ /* pPg at bp+12 */ uintptr
	var _ /* pTrunk at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, bNoContent, closest, d2, dist, i, iNewTrunk, iPage, iTrunk, k, mxPage, n, nSearch, noContent, pPage1, pPrevTrunk, rc, searchList, v1, v2, v5, v6 /* Number of leaves on the trunk of the freelist */
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pPrevTrunk = uintptr(0) /* Total size of the database file */
	pPage1 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1
	mxPage = _btreePagecount(tls, pBt)
	/* EVIDENCE-OF: R-21003-45125 The 4-byte big-endian integer at offset 36
	 ** stores the total number of pages on the freelist. */
	n = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36)
	if n >= mxPage {
		return _sqlite3CorruptError(tls, int32(76983))
	}
	if n > uint32(0) {
		searchList = uint8(0) /* If the free-list must be searched for 'nearby' */
		nSearch = uint32(0)   /* Count of the number of search attempts */
		/* If eMode==BTALLOC_EXACT and a query of the pointer-map
		 ** shows that the page 'nearby' is somewhere on the free-list, then
		 ** the entire-list will be searched for that page.
		 */
		if int32(int32(eMode)) == int32(BTALLOC_EXACT) {
			if nearby <= mxPage {
				rc = _ptrmapGet(tls, pBt, nearby, bp+4, uintptr(0))
				if rc != 0 {
					return rc
				}
				if int32(*(*Tu8)(unsafe.Pointer(bp + 4))) == int32(PTRMAP_FREEPAGE) {
					searchList = uint8(1)
				}
			}
		} else {
			if int32(int32(eMode)) == int32(BTALLOC_LE) {
				searchList = uint8(1)
			}
		}
		/* Decrement the free-list count by 1. Set iTrunk to the index of the
		 ** first free-list trunk page. iPrevTrunk is initially 1.
		 */
		rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FpDbPage)
		if rc != 0 {
			return rc
		}
		_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36, n-uint32(1))
		/* The code within this loop is run only once if the 'searchList' variable
		 ** is not true. Otherwise, it runs once for each trunk-page on the
		 ** free-list until the page 'nearby' is located (eMode==BTALLOC_EXACT)
		 ** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
		 */
		for cond := true; cond; cond = searchList != 0 {
			pPrevTrunk = *(*uintptr)(unsafe.Pointer(bp))
			if pPrevTrunk != 0 {
				/* EVIDENCE-OF: R-01506-11053 The first integer on a freelist trunk page
				 ** is the page number of the next freelist trunk page in the list or
				 ** zero if this is the last freelist trunk page. */
				iTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FaData)
			} else {
				/* EVIDENCE-OF: R-59841-13798 The 4-byte big-endian integer at offset 32
				 ** stores the page number of the first page of the freelist, or zero if
				 ** the freelist is empty. */
				iTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32)
			}
			if v2 = iTrunk > mxPage; !v2 {
				v1 = nSearch
				nSearch++
			}
			if v2 || v1 > n {
				rc = _sqlite3CorruptError(tls, int32(77039))
			} else {
				rc = _btreeGetUnusedPage(tls, pBt, iTrunk, bp, 0)
			}
			if rc != 0 {
				*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
				goto end_allocate_page
			}
			/* EVIDENCE-OF: R-13523-04394 The second integer on a freelist trunk page
			 ** is the number of leaf page pointers to follow. */
			k = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+4)
			if k == uint32(0) && !(searchList != 0) {
				/* The trunk has no leaves and the list is not being searched.
				 ** So extract the trunk page itself and use it as the newly
				 ** allocated page */
				rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
				if rc != 0 {
					goto end_allocate_page
				}
				*(*TPgno)(unsafe.Pointer(pPgno)) = iTrunk
				libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uint32(4))
				*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp))
				*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			} else {
				if k > (*TBtShared)(unsafe.Pointer(pBt)).FusableSize/libc.Uint32FromInt32(4)-libc.Uint32FromInt32(2) {
					/* Value of k is out of range.  Database corruption */
					rc = _sqlite3CorruptError(tls, int32(77068))
					goto end_allocate_page
				} else {
					if searchList != 0 && (nearby == iTrunk || iTrunk < nearby && int32(int32(eMode)) == int32(BTALLOC_LE)) {
						/* The list is being searched and this trunk page is the page
						 ** to allocate, regardless of whether it has leaves.
						 */
						*(*TPgno)(unsafe.Pointer(pPgno)) = iTrunk
						*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp))
						searchList = uint8(0)
						rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
						if rc != 0 {
							goto end_allocate_page
						}
						if k == uint32(0) {
							if !(pPrevTrunk != 0) {
								libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uint32(4))
							} else {
								rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FpDbPage)
								if rc != SQLITE_OK {
									goto end_allocate_page
								}
								libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FaData, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uint32(4))
							}
						} else {
							iNewTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+8)
							if iNewTrunk > mxPage {
								rc = _sqlite3CorruptError(tls, int32(77102))
								goto end_allocate_page
							}
							rc = _btreeGetUnusedPage(tls, pBt, iNewTrunk, bp+8, 0)
							if rc != SQLITE_OK {
								goto end_allocate_page
							}
							rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpDbPage)
							if rc != SQLITE_OK {
								_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
								goto end_allocate_page
							}
							libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uint32(4))
							_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData+4, k-uint32(1))
							libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData+8, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+12, (k-uint32(1))*uint32(4))
							_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
							if !(pPrevTrunk != 0) {
								_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, iNewTrunk)
							} else {
								rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FpDbPage)
								if rc != 0 {
									goto end_allocate_page
								}
								_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FaData, iNewTrunk)
							}
						}
						*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
					} else {
						if k > uint32(0) {
							aData = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData
							if nearby > uint32(0) {
								closest = uint32(0)
								if int32(int32(eMode)) == int32(BTALLOC_LE) {
									i = uint32(0)
									for {
										if !(i < k) {
											break
										}
										iPage = _sqlite3Get4byte(tls, aData+uintptr(uint32(8)+i*uint32(4)))
										if iPage <= nearby {
											closest = i
											break
										}
										goto _3
									_3:
										;
										i++
									}
								} else {
									dist = _sqlite3AbsInt32(tls, int32(_sqlite3Get4byte(tls, aData+8)-nearby))
									i = uint32(1)
									for {
										if !(i < k) {
											break
										}
										d2 = _sqlite3AbsInt32(tls, int32(_sqlite3Get4byte(tls, aData+uintptr(uint32(8)+i*uint32(4)))-nearby))
										if d2 < dist {
											closest = i
											dist = d2
										}
										goto _4
									_4:
										;
										i++
									}
								}
							} else {
								closest = uint32(0)
							}
							iPage = _sqlite3Get4byte(tls, aData+uintptr(uint32(8)+closest*uint32(4)))
							if iPage > mxPage || iPage < uint32(2) {
								rc = _sqlite3CorruptError(tls, int32(77167))
								goto end_allocate_page
							}
							if !(searchList != 0) || (iPage == nearby || iPage < nearby && int32(int32(eMode)) == int32(BTALLOC_LE)) {
								*(*TPgno)(unsafe.Pointer(pPgno)) = iPage
								rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
								if rc != 0 {
									goto end_allocate_page
								}
								if closest < k-uint32(1) {
									libc.Xmemcpy(tls, aData+uintptr(uint32(8)+closest*uint32(4)), aData+uintptr(uint32(4)+k*uint32(4)), uint32(4))
								}
								_sqlite3Put4byte(tls, aData+4, k-uint32(1))
								if !(_btreeGetHasContent(tls, pBt, *(*TPgno)(unsafe.Pointer(pPgno))) != 0) {
									v5 = int32(PAGER_GET_NOCONTENT)
								} else {
									v5 = 0
								}
								noContent = v5
								rc = _btreeGetUnusedPage(tls, pBt, *(*TPgno)(unsafe.Pointer(pPgno)), ppPage, noContent)
								if rc == SQLITE_OK {
									rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FpDbPage)
									if rc != SQLITE_OK {
										_releasePage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
										*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
									}
								}
								searchList = uint8(0)
							}
						}
					}
				}
			}
			_releasePage(tls, pPrevTrunk)
			pPrevTrunk = uintptr(0)
		}
	} else {
		if 0 == int32((*TBtShared)(unsafe.Pointer(pBt)).FbDoTruncate) {
			v6 = int32(PAGER_GET_NOCONTENT)
		} else {
			v6 = 0
		}
		/* There are no pages on the freelist, so append a new page to the
		 ** database image.
		 **
		 ** Normally, new pages allocated by this block can be requested from the
		 ** pager layer with the 'no-content' flag set. This prevents the pager
		 ** from trying to read the pages content from disk. However, if the
		 ** current transaction has already run one or more incremental-vacuum
		 ** steps, then the page we are about to allocate may contain content
		 ** that is required in the event of a rollback. In this case, do
		 ** not set the no-content flag. This causes the pager to load and journal
		 ** the current page content before overwriting it.
		 **
		 ** Note that the pager will not actually attempt to load or journal
		 ** content for any page that really does lie past the end of the database
		 ** file on disk. So the effects of disabling the no-content optimization
		 ** here are confined to those pages that lie between the end of the
		 ** database image and the end of the database file.
		 */
		bNoContent = v6
		rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
		if rc != 0 {
			return rc
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FnPage++
		if (*TBtShared)(unsafe.Pointer(pBt)).FnPage == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
			(*TBtShared)(unsafe.Pointer(pBt)).FnPage++
		}
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && _ptrmapPageno(tls, pBt, (*TBtShared)(unsafe.Pointer(pBt)).FnPage) == (*TBtShared)(unsafe.Pointer(pBt)).FnPage {
			/* If *pPgno refers to a pointer-map page, allocate two new pages
			 ** at the end of the file instead of one. The first allocated page
			 ** becomes a new pointer-map page, the second is used by the caller.
			 */
			*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
			rc = _btreeGetUnusedPage(tls, pBt, (*TBtShared)(unsafe.Pointer(pBt)).FnPage, bp+12, bNoContent)
			if rc == SQLITE_OK {
				rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FpDbPage)
				_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
			}
			if rc != 0 {
				return rc
			}
			(*TBtShared)(unsafe.Pointer(pBt)).FnPage++
			if (*TBtShared)(unsafe.Pointer(pBt)).FnPage == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
				(*TBtShared)(unsafe.Pointer(pBt)).FnPage++
			}
		}
		_sqlite3Put4byte(tls, uintptr(28)+(*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData, (*TBtShared)(unsafe.Pointer(pBt)).FnPage)
		*(*TPgno)(unsafe.Pointer(pPgno)) = (*TBtShared)(unsafe.Pointer(pBt)).FnPage
		rc = _btreeGetUnusedPage(tls, pBt, *(*TPgno)(unsafe.Pointer(pPgno)), ppPage, bNoContent)
		if rc != 0 {
			return rc
		}
		rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FpDbPage)
		if rc != SQLITE_OK {
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
		}
	}
	goto end_allocate_page
end_allocate_page:
	;
	_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	_releasePage(tls, pPrevTrunk)
	return rc
}

// C documentation
//
//	/*
//	** This function is used to add page iPage to the database file free-list.
//	** It is assumed that the page is not already a part of the free-list.
//	**
//	** The value passed as the second argument to this function is optional.
//	** If the caller happens to have a pointer to the MemPage object
//	** corresponding to page iPage handy, it may pass it as the second value.
//	** Otherwise, it may pass NULL.
//	**
//	** If a pointer to a MemPage object is passed as the second argument,
//	** its reference count is not altered by this function.
//	*/
func _freePage2(tls *libc.TLS, pBt uintptr, pMemPage uintptr, iPage TPgno) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iTrunk TPgno
	var nFree, nLeaf Tu32
	var pPage1 uintptr
	var v1, v3, v5 int32
	var v2, v4, v6 bool
	var _ /* pPage at bp+4 */ uintptr
	var _ /* pTrunk at bp+0 */ uintptr
	var _ /* rc at bp+8 */ int32
	_, _, _, _, _, _, _, _, _, _ = iTrunk, nFree, nLeaf, pPage1, v1, v2, v3, v4, v5, v6
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)       /* Free-list trunk page */
	iTrunk = uint32(0)                                 /* Page number of free-list trunk page */
	pPage1 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1 /* Initial number of pages on free-list */
	if iPage < uint32(2) || iPage > (*TBtShared)(unsafe.Pointer(pBt)).FnPage {
		return _sqlite3CorruptError(tls, int32(77294))
	}
	if pMemPage != 0 {
		*(*uintptr)(unsafe.Pointer(bp + 4)) = pMemPage
		_sqlite3PagerRef(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpDbPage)
	} else {
		*(*uintptr)(unsafe.Pointer(bp + 4)) = _btreePageLookup(tls, pBt, iPage)
	}
	/* Increment the free page count on pPage1 */
	*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FpDbPage)
	if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
		goto freepage_out
	}
	nFree = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36)
	_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36, nFree+uint32(1))
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_SECURE_DELETE) != 0 {
		/* If the secure_delete option is enabled, then
		 ** always fully overwrite deleted information with zeros.
		 */
		if v2 = !(*(*uintptr)(unsafe.Pointer(bp + 4)) != 0); v2 {
			v1 = _btreeGetPage(tls, pBt, iPage, bp+4, 0)
			*(*int32)(unsafe.Pointer(bp + 8)) = v1
		}
		if v4 = v2 && v1 != 0; !v4 {
			v3 = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpDbPage)
			*(*int32)(unsafe.Pointer(bp + 8)) = v3
		}
		if v4 || v3 != 0 {
			goto freepage_out
		}
		libc.Xmemset(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FaData, 0, (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpBt)).FpageSize)
	}
	/* If the database supports auto-vacuum, write an entry in the pointer-map
	 ** to indicate that the page is free.
	 */
	if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
		_ptrmapPut(tls, pBt, iPage, uint8(PTRMAP_FREEPAGE), uint32(0), bp+8)
		if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
			goto freepage_out
		}
	}
	/* Now manipulate the actual database free-list structure. There are two
	 ** possibilities. If the free-list is currently empty, or if the first
	 ** trunk page in the free-list is full, then this page will become a
	 ** new free-list trunk page. Otherwise, it will become a leaf of the
	 ** first trunk page in the current free-list. This block tests if it
	 ** is possible to add the page as a new free-list leaf.
	 */
	if nFree != uint32(0) { /* Initial number of leaf cells on trunk page */
		iTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32)
		if iTrunk > _btreePagecount(tls, pBt) {
			*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3CorruptError(tls, int32(77341))
			goto freepage_out
		}
		*(*int32)(unsafe.Pointer(bp + 8)) = _btreeGetPage(tls, pBt, iTrunk, bp, 0)
		if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
			goto freepage_out
		}
		nLeaf = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+4)
		if nLeaf > (*TBtShared)(unsafe.Pointer(pBt)).FusableSize/uint32(4)-uint32(2) {
			*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3CorruptError(tls, int32(77352))
			goto freepage_out
		}
		if nLeaf < (*TBtShared)(unsafe.Pointer(pBt)).FusableSize/uint32(4)-uint32(8) {
			/* In this case there is room on the trunk page to insert the page
			 ** being freed as a new leaf.
			 **
			 ** Note that the trunk page is not really full until it contains
			 ** usableSize/4 - 2 entries, not usableSize/4 - 8 entries as we have
			 ** coded.  But due to a coding error in versions of SQLite prior to
			 ** 3.6.0, databases with freelist trunk pages holding more than
			 ** usableSize/4 - 8 entries will be reported as corrupt.  In order
			 ** to maintain backwards compatibility with older versions of SQLite,
			 ** we will continue to restrict the number of entries to usableSize/4 - 8
			 ** for now.  At some point in the future (once everyone has upgraded
			 ** to 3.6.0 or later) we should consider fixing the conditional above
			 ** to read "usableSize/4-2" instead of "usableSize/4-8".
			 **
			 ** EVIDENCE-OF: R-19920-11576 However, newer versions of SQLite still
			 ** avoid using the last six entries in the freelist trunk page array in
			 ** order that database files created by newer versions of SQLite can be
			 ** read by older versions of SQLite.
			 */
			*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
			if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
				_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+4, nLeaf+uint32(1))
				_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+uintptr(uint32(8)+nLeaf*uint32(4)), iPage)
				if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 && int32((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_SECURE_DELETE) == 0 {
					_sqlite3PagerDontWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpDbPage)
				}
				*(*int32)(unsafe.Pointer(bp + 8)) = _btreeSetHasContent(tls, pBt, iPage)
			}
			goto freepage_out
		}
	}
	/* If control flows to this point, then it was not possible to add the
	 ** the page being freed as a leaf page of the first trunk in the free-list.
	 ** Possibly because the free-list is empty, or possibly because the
	 ** first trunk in the free-list is full. Either way, the page being freed
	 ** will become the new first trunk page in the free-list.
	 */
	if v6 = *(*uintptr)(unsafe.Pointer(bp + 4)) == uintptr(0); v6 {
		v5 = _btreeGetPage(tls, pBt, iPage, bp+4, 0)
		*(*int32)(unsafe.Pointer(bp + 8)) = v5
	}
	if v6 && SQLITE_OK != v5 {
		goto freepage_out
	}
	*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpDbPage)
	if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
		goto freepage_out
	}
	_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FaData, iTrunk)
	_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FaData+4, uint32(0))
	_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, iPage)
	goto freepage_out
freepage_out:
	;
	if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
		(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FisInit = uint8(0)
	}
	_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return *(*int32)(unsafe.Pointer(bp + 8))
}

func _freePage(tls *libc.TLS, pPage uintptr, pRC uintptr) {
	if *(*int32)(unsafe.Pointer(pRC)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRC)) = _freePage2(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpBt, pPage, (*TMemPage)(unsafe.Pointer(pPage)).Fpgno)
	}
}

// C documentation
//
//	/*
//	** Free the overflow pages associated with the given Cell.
//	*/
func _clearCellOverflow(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nOvfl, rc, v1 int32
	var ovflPageSize Tu32
	var ovflPgno TPgno
	var pBt, v2 uintptr
	var v3 bool
	var _ /* iNext at bp+0 */ TPgno
	var _ /* pOvfl at bp+4 */ uintptr
	_, _, _, _, _, _, _, _ = nOvfl, ovflPageSize, ovflPgno, pBt, rc, v1, v2, v3
	if pCell+uintptr((*TCellInfo)(unsafe.Pointer(pInfo)).FnSize) > (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
		/* Cell extends past end of page */
		return _sqlite3CorruptError(tls, int32(77441))
	}
	ovflPgno = _sqlite3Get4byte(tls, pCell+uintptr((*TCellInfo)(unsafe.Pointer(pInfo)).FnSize)-uintptr(4))
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt
	ovflPageSize = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4)
	nOvfl = int32(((*TCellInfo)(unsafe.Pointer(pInfo)).FnPayload - uint32((*TCellInfo)(unsafe.Pointer(pInfo)).FnLocal) + ovflPageSize - uint32(1)) / ovflPageSize)
	for {
		v1 = nOvfl
		nOvfl--
		if !(v1 != 0) {
			break
		}
		*(*TPgno)(unsafe.Pointer(bp)) = uint32(0)
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		if ovflPgno < uint32(2) || ovflPgno > _btreePagecount(tls, pBt) {
			/* 0 is not a legal page number and page 1 cannot be an
			 ** overflow page. Therefore if ovflPgno<2 or past the end of the
			 ** file the database must be corrupt. */
			return _sqlite3CorruptError(tls, int32(77458))
		}
		if nOvfl != 0 {
			rc = _getOverflowPage(tls, pBt, ovflPgno, bp+4, bp)
			if rc != 0 {
				return rc
			}
		}
		if v3 = *(*uintptr)(unsafe.Pointer(bp + 4)) != 0; !v3 {
			v2 = _btreePageLookup(tls, pBt, ovflPgno)
			*(*uintptr)(unsafe.Pointer(bp + 4)) = v2
		}
		if (v3 || v2 != uintptr(0)) && _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpDbPage) != int32(1) {
			/* There is no reason any cursor should have an outstanding reference
			 ** to an overflow page belonging to a cell that is being deleted/updated.
			 ** So if there exists more than one reference to this page, then it
			 ** must not really be an overflow page and the database must be corrupt.
			 ** It is helpful to detect this before calling freePage2(), as
			 ** freePage2() may zero the page contents if secure-delete mode is
			 ** enabled. If this 'overflow' page happens to be a page that the
			 ** caller is iterating through or using in some other way, this
			 ** can be problematic.
			 */
			rc = _sqlite3CorruptError(tls, int32(77478))
		} else {
			rc = _freePage2(tls, pBt, *(*uintptr)(unsafe.Pointer(bp + 4)), ovflPgno)
		}
		if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
			_sqlite3PagerUnref(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpDbPage)
		}
		if rc != 0 {
			return rc
		}
		ovflPgno = *(*TPgno)(unsafe.Pointer(bp))
	}
	return SQLITE_OK
}

/* Call xParseCell to compute the size of a cell.  If the cell contains
** overflow, then invoke cellClearOverflow to clear out that overflow.
** Store the result code (SQLITE_OK or some error code) in rc.
**
** Implemented as macro to force inlining for performance.
 */

// C documentation
//
//	/*
//	** Create the byte sequence used to represent a cell on page pPage
//	** and write that byte sequence into pCell[].  Overflow pages are
//	** allocated and filled in as necessary.  The calling procedure
//	** is responsible for making sure sufficient space has been allocated
//	** for pCell[].
//	**
//	** Note that pCell does not necessary need to point to the pPage->aData
//	** area.  pCell might point to some temporary storage.  The cell will
//	** be constructed in this temporary area then copied into pPage->aData
//	** later.
//	*/
func _fillInCell(tls *libc.TLS, pPage uintptr, pCell uintptr, pX uintptr, pnSize uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType Tu8
	var mn, n, nHeader, nPayload, nSrc, spaceLeft, v1, v2, v3, v4 int32
	var pBt, pPayload, pPrior, pSrc, pToRelease uintptr
	var pgnoPtrmap TPgno
	var _ /* pOvfl at bp+8 */ uintptr
	var _ /* pgnoOvfl at bp+4 */ TPgno
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = eType, mn, n, nHeader, nPayload, nSrc, pBt, pPayload, pPrior, pSrc, pToRelease, pgnoPtrmap, spaceLeft, v1, v2, v3, v4
	/* pPage is not necessarily writeable since pCell might be auxiliary
	 ** buffer space that is separate from the pPage buffer area */
	/* Fill in the header. */
	nHeader = int32((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	if (*TMemPage)(unsafe.Pointer(pPage)).FintKey != 0 {
		nPayload = (*TBtreePayload)(unsafe.Pointer(pX)).FnData + (*TBtreePayload)(unsafe.Pointer(pX)).FnZero
		pSrc = (*TBtreePayload)(unsafe.Pointer(pX)).FpData
		nSrc = (*TBtreePayload)(unsafe.Pointer(pX)).FnData
		/* fillInCell() only called for leaves */
		if uint32(nPayload) < libc.Uint32FromInt32(0x80) {
			*(*uint8)(unsafe.Pointer(pCell + uintptr(nHeader))) = uint8(nPayload)
			v1 = libc.Int32FromInt32(1)
		} else {
			v1 = _sqlite3PutVarint(tls, pCell+uintptr(nHeader), uint64(nPayload))
		}
		nHeader += int32(uint8(v1))
		nHeader += _sqlite3PutVarint(tls, pCell+uintptr(nHeader), *(*Tu64)(unsafe.Pointer(pX + 8)))
	} else {
		v2 = int32((*TBtreePayload)(unsafe.Pointer(pX)).FnKey)
		nPayload = v2
		nSrc = v2
		pSrc = (*TBtreePayload)(unsafe.Pointer(pX)).FpKey
		if uint32(nPayload) < libc.Uint32FromInt32(0x80) {
			*(*uint8)(unsafe.Pointer(pCell + uintptr(nHeader))) = uint8(nPayload)
			v3 = libc.Int32FromInt32(1)
		} else {
			v3 = _sqlite3PutVarint(tls, pCell+uintptr(nHeader), uint64(nPayload))
		}
		nHeader += int32(uint8(v3))
	}
	/* Fill in the payload */
	pPayload = pCell + uintptr(nHeader)
	if nPayload <= int32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		/* This is the common case where everything fits on the btree page
		 ** and no overflow pages are required. */
		n = nHeader + nPayload
		if n < int32(4) {
			n = int32(4)
			*(*uint8)(unsafe.Pointer(pPayload + uintptr(nPayload))) = uint8(0)
		}
		*(*int32)(unsafe.Pointer(pnSize)) = n
		libc.Xmemcpy(tls, pPayload, pSrc, uint32(uint32(nSrc)))
		libc.Xmemset(tls, pPayload+uintptr(nSrc), 0, uint32(nPayload-nSrc))
		return SQLITE_OK
	}
	/* If we reach this point, it means that some of the content will need
	 ** to spill onto overflow pages.
	 */
	mn = int32((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)
	n = int32(uint32(uint32(mn)) + uint32(nPayload-mn)%((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-uint32(4)))
	if n > int32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		n = mn
	}
	spaceLeft = n
	*(*int32)(unsafe.Pointer(pnSize)) = n + nHeader + int32(4)
	pPrior = pCell + uintptr(nHeader+n)
	pToRelease = uintptr(0)
	*(*TPgno)(unsafe.Pointer(bp + 4)) = uint32(0)
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt
	/* At this point variables should be set as follows:
	 **
	 **   nPayload           Total payload size in bytes
	 **   pPayload           Begin writing payload here
	 **   spaceLeft          Space available at pPayload.  If nPayload>spaceLeft,
	 **                      that means content must spill into overflow pages.
	 **   *pnSize            Size of the local cell (not counting overflow pages)
	 **   pPrior             Where to write the pgno of the first overflow page
	 **
	 ** Use a call to btreeParseCellPtr() to verify that the values above
	 ** were computed correctly.
	 */
	/* Write the payload into the local Cell and any extra into overflow pages */
	for int32(1) != 0 {
		n = nPayload
		if n > spaceLeft {
			n = spaceLeft
		}
		/* If pToRelease is not zero than pPayload points into the data area
		 ** of pToRelease.  Make sure pToRelease is still writeable. */
		/* If pPayload is part of the data area of pPage, then make sure pPage
		 ** is still writeable */
		if nSrc >= n {
			libc.Xmemcpy(tls, pPayload, pSrc, uint32(uint32(n)))
		} else {
			if nSrc > 0 {
				n = nSrc
				libc.Xmemcpy(tls, pPayload, pSrc, uint32(uint32(n)))
			} else {
				libc.Xmemset(tls, pPayload, 0, uint32(uint32(n)))
			}
		}
		nPayload -= n
		if nPayload <= 0 {
			break
		}
		pPayload += uintptr(n)
		pSrc += uintptr(n)
		nSrc -= n
		spaceLeft -= n
		if spaceLeft == 0 {
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
			pgnoPtrmap = *(*TPgno)(unsafe.Pointer(bp + 4)) /* Overflow page pointer-map entry page */
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				for cond := true; cond; cond = _ptrmapPageno(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 4))) == *(*TPgno)(unsafe.Pointer(bp + 4)) || *(*TPgno)(unsafe.Pointer(bp + 4)) == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
					*(*TPgno)(unsafe.Pointer(bp + 4))++
				}
			}
			*(*int32)(unsafe.Pointer(bp)) = _allocateBtreePage(tls, pBt, bp+8, bp+4, *(*TPgno)(unsafe.Pointer(bp + 4)), uint8(0))
			/* If the database supports auto-vacuum, and the second or subsequent
			 ** overflow page is being allocated, add an entry to the pointer-map
			 ** for that page now.
			 **
			 ** If this is the first overflow page, then write a partial entry
			 ** to the pointer-map. If we write nothing to this pointer-map slot,
			 ** then the optimistic overflow chain processing in clearCell()
			 ** may misinterpret the uninitialized values and delete the
			 ** wrong pages from the database.
			 */
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				if pgnoPtrmap != 0 {
					v4 = int32(PTRMAP_OVERFLOW2)
				} else {
					v4 = int32(PTRMAP_OVERFLOW1)
				}
				eType = uint8(v4)
				_ptrmapPut(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 4)), eType, pgnoPtrmap, bp)
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
				}
			}
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				_releasePage(tls, pToRelease)
				return *(*int32)(unsafe.Pointer(bp))
			}
			/* If pToRelease is not zero than pPrior points into the data area
			 ** of pToRelease.  Make sure pToRelease is still writeable. */
			/* If pPrior is part of the data area of pPage, then make sure pPage
			 ** is still writeable */
			_sqlite3Put4byte(tls, pPrior, *(*TPgno)(unsafe.Pointer(bp + 4)))
			_releasePage(tls, pToRelease)
			pToRelease = *(*uintptr)(unsafe.Pointer(bp + 8))
			pPrior = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData
			_sqlite3Put4byte(tls, pPrior, uint32(0))
			pPayload = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData + 4
			spaceLeft = int32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4))
		}
	}
	_releasePage(tls, pToRelease)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Remove the i-th cell from pPage.  This routine effects pPage only.
//	** The cell content is not freed or deallocated.  It is assumed that
//	** the cell content has been copied someplace else.  This routine just
//	** removes the reference to the cell from pPage.
//	**
//	** "sz" must be the number of bytes in the cell.
//	*/
func _dropCell(tls *libc.TLS, pPage uintptr, idx int32, sz int32, pRC uintptr) {
	var data, ptr uintptr
	var hdr, rc int32
	var pc Tu32
	_, _, _, _, _ = data, hdr, pc, ptr, rc /* Beginning of the header.  0 most pages.  100 page 1 */
	if *(*int32)(unsafe.Pointer(pRC)) != 0 {
		return
	}
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
	ptr = (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx)
	pc = uint32(int32(*(*Tu8)(unsafe.Pointer(ptr)))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(ptr + 1))))
	hdr = int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)
	if pc+uint32(uint32(sz)) > (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize {
		*(*int32)(unsafe.Pointer(pRC)) = _sqlite3CorruptError(tls, int32(77734))
		return
	}
	rc = _freeSpace(tls, pPage, uint16(uint16(pc)), uint16(uint16(sz)))
	if rc != 0 {
		*(*int32)(unsafe.Pointer(pRC)) = rc
		return
	}
	(*TMemPage)(unsafe.Pointer(pPage)).FnCell--
	if int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) == 0 {
		libc.Xmemset(tls, data+uintptr(hdr+int32(1)), 0, uint32(4))
		*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(7)))) = uint8(0)
		*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(5)))) = uint8((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize >> libc.Int32FromInt32(8))
		*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(5)) + 1)) = uint8((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
		(*TMemPage)(unsafe.Pointer(pPage)).FnFree = int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize - uint32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset) - uint32((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize) - uint32(8))
	} else {
		libc.Xmemmove(tls, ptr, ptr+uintptr(2), uint32(int32(2)*(int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-idx)))
		*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(3)))) = uint8(int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) >> libc.Int32FromInt32(8))
		*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(3)) + 1)) = uint8((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
		*(*int32)(unsafe.Pointer(pPage + 20)) += int32(2)
	}
}

// C documentation
//
//	/*
//	** Insert a new cell on pPage at cell index "i".  pCell points to the
//	** content of the cell.
//	**
//	** If the cell content will fit on the page, then put it there.  If it
//	** will not fit, then make a copy of the cell content into pTemp if
//	** pTemp is not null.  Regardless of pTemp, allocate a new entry
//	** in pPage->apOvfl[] and make it point to the cell content (either
//	** in pTemp or the original pCell) and also record its index.
//	** Allocating a new entry in pPage->aCell[] implies that
//	** pPage->nOverflow is incremented.
//	**
//	** The insertCellFast() routine below works exactly the same as
//	** insertCell() except that it lacks the pTemp and iChild parameters
//	** which are assumed zero.  Other than that, the two routines are the
//	** same.
//	**
//	** Fixes or enhancements to this routine should be reflected in
//	** insertCellFast()!
//	*/
func _insertCell(tls *libc.TLS, pPage uintptr, i int32, pCell uintptr, sz int32, pTemp uintptr, iChild TPgno) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var data, pIns, v2, v4 uintptr
	var j, rc int32
	var v1, v3 Tu8
	var _ /* idx at bp+0 */ int32
	var _ /* rc2 at bp+4 */ int32
	_, _, _, _, _, _, _, _ = data, j, pIns, rc, v1, v2, v3, v4
	*(*int32)(unsafe.Pointer(bp)) = 0 /* The point in pPage->aCellIdx[] where no cell inserted */
	if (*TMemPage)(unsafe.Pointer(pPage)).FnOverflow != 0 || sz+int32(2) > (*TMemPage)(unsafe.Pointer(pPage)).FnFree {
		if pTemp != 0 {
			libc.Xmemcpy(tls, pTemp, pCell, uint32(uint32(sz)))
			pCell = pTemp
		}
		_sqlite3Put4byte(tls, pCell, iChild)
		v2 = pPage + 12
		v1 = *(*Tu8)(unsafe.Pointer(v2))
		*(*Tu8)(unsafe.Pointer(v2))++
		j = int32(v1)
		/* Comparison against ArraySize-1 since we hold back one extra slot
		 ** as a contingency.  In other words, never need more than 3 overflow
		 ** slots but 4 are allocated, just to be safe. */
		*(*uintptr)(unsafe.Pointer(pPage + 36 + uintptr(j)*4)) = pCell
		*(*Tu16)(unsafe.Pointer(pPage + 28 + uintptr(j)*2)) = uint16(uint16(i))
		/* When multiple overflows occur, they are always sequential and in
		 ** sorted order.  This invariants arise because multiple overflows can
		 ** only occur when inserting divider cells into the parent page during
		 ** balancing, and the dividers are adjacent and sorted.
		 */
		/* Overflows in sorted order */
		/* Overflows are sequential */
	} else {
		rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
		if rc != SQLITE_OK {
			return rc
		}
		data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
		rc = _allocateSpace(tls, pPage, sz, bp)
		if rc != 0 {
			return rc
		}
		/* The allocateSpace() routine guarantees the following properties
		 ** if it returns successfully */
		*(*int32)(unsafe.Pointer(pPage + 20)) -= int32(uint16(libc.Int32FromInt32(2) + sz))
		/* In a corrupt database where an entry in the cell index section of
		 ** a btree page has a value of 3 or less, the pCell value might point
		 ** as many as 4 bytes in front of the start of the aData buffer for
		 ** the source page.  Make sure this does not cause problems by not
		 ** reading the first 4 bytes */
		libc.Xmemcpy(tls, data+uintptr(*(*int32)(unsafe.Pointer(bp))+int32(4)), pCell+uintptr(4), uint32(sz-int32(4)))
		_sqlite3Put4byte(tls, data+uintptr(*(*int32)(unsafe.Pointer(bp))), iChild)
		pIns = (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(i*int32(2))
		libc.Xmemmove(tls, pIns+uintptr(2), pIns, uint32(int32(2)*(int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-i)))
		*(*Tu8)(unsafe.Pointer(pIns)) = uint8(*(*int32)(unsafe.Pointer(bp)) >> libc.Int32FromInt32(8))
		*(*Tu8)(unsafe.Pointer(pIns + 1)) = uint8(*(*int32)(unsafe.Pointer(bp)))
		(*TMemPage)(unsafe.Pointer(pPage)).FnCell++
		/* increment the cell count */
		v4 = data + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(4))
		*(*Tu8)(unsafe.Pointer(v4))++
		v3 = *(*Tu8)(unsafe.Pointer(v4))
		if int32(v3) == 0 {
			*(*Tu8)(unsafe.Pointer(data + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(3))))++
		}
		if (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FautoVacuum != 0 {
			*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
			/* The cell may contain a pointer to an overflow page. If so, write
			 ** the entry for the overflow page into the pointer map.
			 */
			_ptrmapPutOvflPtr(tls, pPage, pPage, pCell, bp+4)
			if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
				return *(*int32)(unsafe.Pointer(bp + 4))
			}
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This variant of insertCell() assumes that the pTemp and iChild
//	** parameters are both zero.  Use this variant in sqlite3BtreeInsert()
//	** for performance improvement, and also so that this variant is only
//	** called from that one place, and is thus inlined, and thus runs must
//	** faster.
//	**
//	** Fixes or enhancements to this routine should be reflected into
//	** the insertCell() routine.
//	*/
func _insertCellFast(tls *libc.TLS, pPage uintptr, i int32, pCell uintptr, sz int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var data, pIns, v2, v4 uintptr
	var j, rc int32
	var v1, v3 Tu8
	var _ /* idx at bp+0 */ int32
	var _ /* rc2 at bp+4 */ int32
	_, _, _, _, _, _, _, _ = data, j, pIns, rc, v1, v2, v3, v4
	*(*int32)(unsafe.Pointer(bp)) = 0 /* The point in pPage->aCellIdx[] where no cell inserted */
	if sz+int32(2) > (*TMemPage)(unsafe.Pointer(pPage)).FnFree {
		v2 = pPage + 12
		v1 = *(*Tu8)(unsafe.Pointer(v2))
		*(*Tu8)(unsafe.Pointer(v2))++
		j = int32(v1)
		/* Comparison against ArraySize-1 since we hold back one extra slot
		 ** as a contingency.  In other words, never need more than 3 overflow
		 ** slots but 4 are allocated, just to be safe. */
		*(*uintptr)(unsafe.Pointer(pPage + 36 + uintptr(j)*4)) = pCell
		*(*Tu16)(unsafe.Pointer(pPage + 28 + uintptr(j)*2)) = uint16(uint16(i))
		/* When multiple overflows occur, they are always sequential and in
		 ** sorted order.  This invariants arise because multiple overflows can
		 ** only occur when inserting divider cells into the parent page during
		 ** balancing, and the dividers are adjacent and sorted.
		 */
		/* Overflows in sorted order */
		/* Overflows are sequential */
	} else {
		rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
		if rc != SQLITE_OK {
			return rc
		}
		data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
		rc = _allocateSpace(tls, pPage, sz, bp)
		if rc != 0 {
			return rc
		}
		/* The allocateSpace() routine guarantees the following properties
		 ** if it returns successfully */
		*(*int32)(unsafe.Pointer(pPage + 20)) -= int32(uint16(libc.Int32FromInt32(2) + sz))
		libc.Xmemcpy(tls, data+uintptr(*(*int32)(unsafe.Pointer(bp))), pCell, uint32(uint32(sz)))
		pIns = (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(i*int32(2))
		libc.Xmemmove(tls, pIns+uintptr(2), pIns, uint32(int32(2)*(int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-i)))
		*(*Tu8)(unsafe.Pointer(pIns)) = uint8(*(*int32)(unsafe.Pointer(bp)) >> libc.Int32FromInt32(8))
		*(*Tu8)(unsafe.Pointer(pIns + 1)) = uint8(*(*int32)(unsafe.Pointer(bp)))
		(*TMemPage)(unsafe.Pointer(pPage)).FnCell++
		/* increment the cell count */
		v4 = data + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(4))
		*(*Tu8)(unsafe.Pointer(v4))++
		v3 = *(*Tu8)(unsafe.Pointer(v4))
		if int32(v3) == 0 {
			*(*Tu8)(unsafe.Pointer(data + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(3))))++
		}
		if (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FautoVacuum != 0 {
			*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
			/* The cell may contain a pointer to an overflow page. If so, write
			 ** the entry for the overflow page into the pointer map.
			 */
			_ptrmapPutOvflPtr(tls, pPage, pPage, pCell, bp+4)
			if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
				return *(*int32)(unsafe.Pointer(bp + 4))
			}
		}
	}
	return SQLITE_OK
}

/*
** The following parameters determine how many adjacent pages get involved
** in a balancing operation.  NN is the number of neighbors on either side
** of the page that participate in the balancing operation.  NB is the
** total number of pages that participate, including the target page and
** NN neighbors on either side.
**
** The minimum value of NN is 1 (of course).  Increasing NN above 1
** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
** in exchange for a larger degradation in INSERT and UPDATE performance.
** The value of NN appears to give the best results overall.
**
** (Later:) The description above makes it seem as if these values are
** tunable - as if you could change them and recompile and it would all work.
** But that is unlikely.  NB has been 3 since the inception of SQLite and
** we have never tested any other value.
 */

// C documentation
//
//	/*
//	** A CellArray object contains a cache of pointers and sizes for a
//	** consecutive sequence of cells that might be held on multiple pages.
//	**
//	** The cells in this array are the divider cell or cells from the pParent
//	** page plus up to three child pages.  There are a total of nCell cells.
//	**
//	** pRef is a pointer to one of the pages that contributes cells.  This is
//	** used to access information such as MemPage.intKey and MemPage.pBt->pageSize
//	** which should be common to all pages that contribute cells to this array.
//	**
//	** apCell[] and szCell[] hold, respectively, pointers to the start of each
//	** cell and the size of each cell.  Some of the apCell[] pointers might refer
//	** to overflow cells.  In other words, some apCel[] pointers might not point
//	** to content area of the pages.
//	**
//	** A szCell[] of zero means the size of that cell has not yet been computed.
//	**
//	** The cells come from as many as four different pages:
//	**
//	**             -----------
//	**             | Parent  |
//	**             -----------
//	**            /     |     **           /      |      **  ---------   ---------   ---------
//	**  |Child-1|   |Child-2|   |Child-3|
//	**  ---------   ---------   ---------
//	**
//	** The order of cells is in the array is for an index btree is:
//	**
//	**       1.  All cells from Child-1 in order
//	**       2.  The first divider cell from Parent
//	**       3.  All cells from Child-2 in order
//	**       4.  The second divider cell from Parent
//	**       5.  All cells from Child-3 in order
//	**
//	** For a table-btree (with rowids) the items 2 and 4 are empty because
//	** content exists only in leaves and there are no divider cells.
//	**
//	** For an index btree, the apEnd[] array holds pointer to the end of page
//	** for Child-1, the Parent, Child-2, the Parent (again), and Child-3,
//	** respectively. The ixNx[] array holds the number of cells contained in
//	** each of these 5 stages, and all stages to the left.  Hence:
//	**
//	**    ixNx[0] = Number of cells in Child-1.
//	**    ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
//	**    ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
//	**    ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
//	**    ixNx[4] = Total number of cells.
//	**
//	** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
//	** are used and they point to the leaf pages only, and the ixNx value are:
//	**
//	**    ixNx[0] = Number of cells in Child-1.
//	**    ixNx[1] = Number of cells in Child-1 and Child-2.
//	**    ixNx[2] = Total number of cells.
//	**
//	** Sometimes when deleting, a child page can have zero cells.  In those
//	** cases, ixNx[] entries with higher indexes, and the corresponding apEnd[]
//	** entries, shift down.  The end result is that each ixNx[] entry should
//	** be larger than the previous
//	*/
type TCellArray = struct {
	FnCell  int32
	FpRef   uintptr
	FapCell uintptr
	FszCell uintptr
	FapEnd  [6]uintptr
	FixNx   [6]int32
}

type CellArray = TCellArray

type TCellArray1 = struct {
	FnCell  int32
	FpRef   uintptr
	FapCell uintptr
	FszCell uintptr
	FapEnd  [6]uintptr
	FixNx   [6]int32
}

type CellArray1 = TCellArray1

// C documentation
//
//	/*
//	** Make sure the cell sizes at idx, idx+1, ..., idx+N-1 have been
//	** computed.
//	*/
func _populateCellCache(tls *libc.TLS, p uintptr, idx int32, N int32) {
	var pRef, szCell uintptr
	_, _ = pRef, szCell
	pRef = (*TCellArray)(unsafe.Pointer(p)).FpRef
	szCell = (*TCellArray)(unsafe.Pointer(p)).FszCell
	for N > 0 {
		if int32(*(*Tu16)(unsafe.Pointer(szCell + uintptr(idx)*2))) == 0 {
			*(*Tu16)(unsafe.Pointer(szCell + uintptr(idx)*2)) = (*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pRef)).FxCellSize})))(tls, pRef, *(*uintptr)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FapCell + uintptr(idx)*4)))
		} else {
		}
		idx++
		N--
	}
}

// C documentation
//
//	/*
//	** Return the size of the Nth element of the cell array
//	*/
func _computeCellSize(tls *libc.TLS, p uintptr, N int32) (r Tu16) {
	*(*Tu16)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2)) = (*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FpRef)).FxCellSize})))(tls, (*TCellArray)(unsafe.Pointer(p)).FpRef, *(*uintptr)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FapCell + uintptr(N)*4)))
	return *(*Tu16)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2))
}

func _cachedCellSize(tls *libc.TLS, p uintptr, N int32) (r Tu16) {
	if *(*Tu16)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2)) != 0 {
		return *(*Tu16)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2))
	}
	return _computeCellSize(tls, p, N)
}

// C documentation
//
//	/*
//	** Array apCell[] contains pointers to nCell b-tree page cells. The
//	** szCell[] array contains the size in bytes of each cell. This function
//	** replaces the current contents of page pPg with the contents of the cell
//	** array.
//	**
//	** Some of the cells in apCell[] may currently be stored in pPg. This
//	** function works around problems caused by this by making a copy of any
//	** such cells before overwriting the page data.
//	**
//	** The MemPage.nFree field is invalidated by this function. It is the
//	** responsibility of the caller to set it correctly.
//	*/
func _rebuildPage(tls *libc.TLS, pCArray uintptr, iFirst int32, nCell int32, pPg uintptr) (r int32) {
	var aData, pCell, pCellptr, pData, pEnd, pSrcEnd, pTmp uintptr
	var hdr, i, iEnd, k, usableSize int32
	var j Tu32
	var sz Tu16
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, hdr, i, iEnd, j, k, pCell, pCellptr, pData, pEnd, pSrcEnd, pTmp, sz, usableSize
	hdr = int32((*TMemPage)(unsafe.Pointer(pPg)).FhdrOffset) /* Offset of header on pPg */
	aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData          /* Pointer to data for pPg */
	usableSize = int32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPg)).FpBt)).FusableSize)
	pEnd = aData + uintptr(usableSize)
	i = iFirst       /* Start of cell content area */
	iEnd = i + nCell /* Loop terminator */
	pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx
	pTmp = _sqlite3PagerTempSpace(tls, (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPg)).FpBt)).FpPager) /* Current pCArray->apEnd[k] value */
	j = uint32(int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)))))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)) + 1))))
	if j > uint32(uint32(usableSize)) {
		j = uint32(0)
	}
	libc.Xmemcpy(tls, pTmp+uintptr(j), aData+uintptr(j), uint32(uint32(usableSize))-j)
	k = 0
	for {
		if !(k < libc.Int32FromInt32(NB)*libc.Int32FromInt32(2) && *(*int32)(unsafe.Pointer(pCArray + 40 + uintptr(k)*4)) <= i) {
			break
		}
		goto _1
	_1:
		;
		k++
	}
	pSrcEnd = *(*uintptr)(unsafe.Pointer(pCArray + 16 + uintptr(k)*4))
	pData = pEnd
	for int32(1) != 0 {
		pCell = *(*uintptr)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*4))
		sz = *(*Tu16)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2))
		if uint32(pCell) >= uint32(aData+uintptr(j)) && uint32(pCell) < uint32(pEnd) {
			if uint32(pCell+uintptr(sz)) > uint32(uint32(pEnd)) {
				return _sqlite3CorruptError(tls, int32(78123))
			}
			pCell = pTmp + uintptr(int32(int32(pCell))-int32(int32(aData)))
		} else {
			if uint32(pCell+uintptr(sz)) > uint32(uint32(pSrcEnd)) && uint32(pCell) < uint32(uint32(pSrcEnd)) {
				return _sqlite3CorruptError(tls, int32(78128))
			}
		}
		pData -= uintptr(sz)
		*(*Tu8)(unsafe.Pointer(pCellptr)) = uint8((int32(int32(pData)) - int32(int32(aData))) >> libc.Int32FromInt32(8))
		*(*Tu8)(unsafe.Pointer(pCellptr + 1)) = uint8(int32(int32(pData)) - int32(int32(aData)))
		pCellptr += uintptr(2)
		if pData < pCellptr {
			return _sqlite3CorruptError(tls, int32(78134))
		}
		libc.Xmemmove(tls, pData, pCell, uint32(uint32(sz)))
		i++
		if i >= iEnd {
			break
		}
		if *(*int32)(unsafe.Pointer(pCArray + 40 + uintptr(k)*4)) <= i {
			k++
			pSrcEnd = *(*uintptr)(unsafe.Pointer(pCArray + 16 + uintptr(k)*4))
		}
	}
	/* The pPg->nFree field is now set incorrectly. The caller will fix it. */
	(*TMemPage)(unsafe.Pointer(pPg)).FnCell = uint16(uint16(nCell))
	(*TMemPage)(unsafe.Pointer(pPg)).FnOverflow = uint8(0)
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(1)))) = uint8(libc.Int32FromInt32(0) >> libc.Int32FromInt32(8))
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(1)) + 1)) = uint8(libc.Int32FromInt32(0))
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(3)))) = uint8(int32((*TMemPage)(unsafe.Pointer(pPg)).FnCell) >> libc.Int32FromInt32(8))
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(3)) + 1)) = uint8((*TMemPage)(unsafe.Pointer(pPg)).FnCell)
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)))) = uint8((int32(int32(pData)) - int32(int32(aData))) >> libc.Int32FromInt32(8))
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)) + 1)) = uint8(int32(int32(pData)) - int32(int32(aData)))
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(7)))) = uint8(0x00)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The pCArray objects contains pointers to b-tree cells and the cell sizes.
//	** This function attempts to add the cells stored in the array to page pPg.
//	** If it cannot (because the page needs to be defragmented before the cells
//	** will fit), non-zero is returned. Otherwise, if the cells are added
//	** successfully, zero is returned.
//	**
//	** Argument pCellptr points to the first entry in the cell-pointer array
//	** (part of page pPg) to populate. After cell apCell[0] is written to the
//	** page body, a 16-bit offset is written to pCellptr. And so on, for each
//	** cell in the array. It is the responsibility of the caller to ensure
//	** that it is safe to overwrite this part of the cell-pointer array.
//	**
//	** When this function is called, *ppData points to the start of the
//	** content area on page pPg. If the size of the content area is extended,
//	** *ppData is updated to point to the new start of the content area
//	** before returning.
//	**
//	** Finally, argument pBegin points to the byte immediately following the
//	** end of the space required by this page for the cell-pointer area (for
//	** all cells - not just those inserted by the current call). If the content
//	** area must be extended to before this point in order to accommodate all
//	** cells in apCell[], then the cells do not fit and non-zero is returned.
//	*/
func _pageInsertArray(tls *libc.TLS, pPg uintptr, pBegin uintptr, ppData uintptr, pCellptr uintptr, iFirst int32, nCell int32, pCArray uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aData, pData, pEnd, pSlot, v2 uintptr
	var i, iEnd, k, sz int32
	var v3 bool
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = aData, i, iEnd, k, pData, pEnd, pSlot, sz, v2, v3
	i = iFirst                                      /* Loop counter - cell index to insert */
	aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData /* Complete page */
	pData = *(*uintptr)(unsafe.Pointer(ppData))     /* Content area.  A subset of aData[] */
	iEnd = iFirst + nCell                           /* Maximum extent of cell data */
	/* Never called on page 1 */
	if iEnd <= iFirst {
		return 0
	}
	k = 0
	for {
		if !(k < libc.Int32FromInt32(NB)*libc.Int32FromInt32(2) && *(*int32)(unsafe.Pointer(pCArray + 40 + uintptr(k)*4)) <= i) {
			break
		}
		goto _1
	_1:
		;
		k++
	}
	pEnd = *(*uintptr)(unsafe.Pointer(pCArray + 16 + uintptr(k)*4))
	for int32(1) != 0 {
		sz = int32(*(*Tu16)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2)))
		if v3 = int32(*(*Tu8)(unsafe.Pointer(aData + 1))) == 0 && int32(*(*Tu8)(unsafe.Pointer(aData + 2))) == 0; !v3 {
			v2 = _pageFindSlot(tls, pPg, sz, bp)
			pSlot = v2
		}
		if v3 || v2 == uintptr(0) {
			if int32(int32(pData))-int32(int32(pBegin)) < sz {
				return int32(1)
			}
			pData -= uintptr(sz)
			pSlot = pData
		}
		/* pSlot and pCArray->apCell[i] will never overlap on a well-formed
		 ** database.  But they might for a corrupt database.  Hence use memmove()
		 ** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD */
		if uint32(*(*uintptr)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*4))+uintptr(sz)) > uint32(uint32(pEnd)) && uint32(*(*uintptr)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*4))) < uint32(uint32(pEnd)) {
			_sqlite3CorruptError(tls, int32(78219))
			return int32(1)
		}
		libc.Xmemmove(tls, pSlot, *(*uintptr)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*4)), uint32(uint32(sz)))
		*(*Tu8)(unsafe.Pointer(pCellptr)) = uint8((int32(int32(pSlot)) - int32(int32(aData))) >> libc.Int32FromInt32(8))
		*(*Tu8)(unsafe.Pointer(pCellptr + 1)) = uint8(int32(int32(pSlot)) - int32(int32(aData)))
		pCellptr += uintptr(2)
		i++
		if i >= iEnd {
			break
		}
		if *(*int32)(unsafe.Pointer(pCArray + 40 + uintptr(k)*4)) <= i {
			k++
			pEnd = *(*uintptr)(unsafe.Pointer(pCArray + 16 + uintptr(k)*4))
		}
	}
	*(*uintptr)(unsafe.Pointer(ppData)) = pData
	return 0
}

// C documentation
//
//	/*
//	** The pCArray object contains pointers to b-tree cells and their sizes.
//	**
//	** This function adds the space associated with each cell in the array
//	** that is currently stored within the body of pPg to the pPg free-list.
//	** The cell-pointers and other fields of the page are not updated.
//	**
//	** This function returns the total number of cells added to the free-list.
//	*/
func _pageFreeArray(tls *libc.TLS, pPg uintptr, iFirst int32, nCell int32, pCArray uintptr) (r int32) {
	var aAfter, aOfst [10]int32
	var aData, pCell, pEnd, pStart uintptr
	var i, iAfter, iEnd, iOfst, j, nFree, nRet, sz int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aAfter, aData, aOfst, i, iAfter, iEnd, iOfst, j, nFree, nRet, pCell, pEnd, pStart, sz
	aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData
	pEnd = aData + uintptr((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPg)).FpBt)).FusableSize)
	pStart = aData + uintptr(int32((*TMemPage)(unsafe.Pointer(pPg)).FhdrOffset)+int32(8)+int32((*TMemPage)(unsafe.Pointer(pPg)).FchildPtrSize))
	nRet = 0
	iEnd = iFirst + nCell
	nFree = 0
	i = iFirst
	for {
		if !(i < iEnd) {
			break
		}
		pCell = *(*uintptr)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*4))
		if uint32(pCell) >= uint32(pStart) && uint32(pCell) < uint32(pEnd) {
			/* No need to use cachedCellSize() here.  The sizes of all cells that
			 ** are to be freed have already been computing while deciding which
			 ** cells need freeing */
			sz = int32(*(*Tu16)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2)))
			iOfst = int32(uint16(int32(int32(pCell)) - int32(int32(aData))))
			iAfter = iOfst + sz
			j = 0
			for {
				if !(j < nFree) {
					break
				}
				if aOfst[j] == iAfter {
					aOfst[j] = iOfst
					break
				} else {
					if aAfter[j] == iOfst {
						aAfter[j] = iAfter
						break
					}
				}
				goto _2
			_2:
				;
				j++
			}
			if j >= nFree {
				if nFree >= int32(libc.Uint32FromInt64(40)/libc.Uint32FromInt64(4)) {
					j = 0
					for {
						if !(j < nFree) {
							break
						}
						_freeSpace(tls, pPg, uint16(aOfst[j]), uint16(aAfter[j]-aOfst[j]))
						goto _3
					_3:
						;
						j++
					}
					nFree = 0
				}
				aOfst[nFree] = iOfst
				aAfter[nFree] = iAfter
				if aData+uintptr(iAfter) > pEnd {
					return 0
				}
				nFree++
			}
			nRet++
		}
		goto _1
	_1:
		;
		i++
	}
	j = 0
	for {
		if !(j < nFree) {
			break
		}
		_freeSpace(tls, pPg, uint16(aOfst[j]), uint16(aAfter[j]-aOfst[j]))
		goto _4
	_4:
		;
		j++
	}
	return nRet
}

// C documentation
//
//	/*
//	** pCArray contains pointers to and sizes of all cells in the page being
//	** balanced.  The current page, pPg, has pPg->nCell cells starting with
//	** pCArray->apCell[iOld].  After balancing, this page should hold nNew cells
//	** starting at apCell[iNew].
//	**
//	** This routine makes the necessary adjustments to pPg so that it contains
//	** the correct cells after being balanced.
//	**
//	** The pPg->nFree field is invalid when this function returns. It is the
//	** responsibility of the caller to set it correctly.
//	*/
func _editPage(tls *libc.TLS, pPg uintptr, iOld int32, iNew int32, nNew int32, pCArray uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aData, pBegin, pCellptr uintptr
	var hdr, i, iCell, iNewEnd, iOldEnd, nAdd, nCell, nShift, nTail, v1 int32
	var _ /* pData at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = aData, hdr, i, iCell, iNewEnd, iOldEnd, nAdd, nCell, nShift, nTail, pBegin, pCellptr, v1
	aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData
	hdr = int32((*TMemPage)(unsafe.Pointer(pPg)).FhdrOffset)
	pBegin = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(nNew*int32(2))
	nCell = int32((*TMemPage)(unsafe.Pointer(pPg)).FnCell)
	iOldEnd = iOld + int32((*TMemPage)(unsafe.Pointer(pPg)).FnCell) + int32((*TMemPage)(unsafe.Pointer(pPg)).FnOverflow)
	iNewEnd = iNew + nNew
	/* Remove cells from the start and end of the page */
	if iOld < iNew {
		nShift = _pageFreeArray(tls, pPg, iOld, iNew-iOld, pCArray)
		if nShift > nCell {
			return _sqlite3CorruptError(tls, int32(78341))
		}
		libc.Xmemmove(tls, (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx, (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx+uintptr(nShift*int32(2)), uint32(nCell*int32(2)))
		nCell -= nShift
	}
	if iNewEnd < iOldEnd {
		nTail = _pageFreeArray(tls, pPg, iNewEnd, iOldEnd-iNewEnd, pCArray)
		nCell -= nTail
	}
	*(*uintptr)(unsafe.Pointer(bp)) = aData + uintptr(int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)))))<<libc.Int32FromInt32(8)|int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)) + 1))))
	if *(*uintptr)(unsafe.Pointer(bp)) < pBegin {
		goto editpage_fail
	}
	if *(*uintptr)(unsafe.Pointer(bp)) > (*TMemPage)(unsafe.Pointer(pPg)).FaDataEnd {
		goto editpage_fail
	}
	/* Add cells to the start of the page */
	if iNew < iOld {
		if nNew < iOld-iNew {
			v1 = nNew
		} else {
			v1 = iOld - iNew
		}
		nAdd = v1
		pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx
		libc.Xmemmove(tls, pCellptr+uintptr(nAdd*int32(2)), pCellptr, uint32(nCell*int32(2)))
		if _pageInsertArray(tls, pPg, pBegin, bp, pCellptr, iNew, nAdd, pCArray) != 0 {
			goto editpage_fail
		}
		nCell += nAdd
	}
	/* Add any overflow cells */
	i = 0
	for {
		if !(i < int32((*TMemPage)(unsafe.Pointer(pPg)).FnOverflow)) {
			break
		}
		iCell = iOld + int32(*(*Tu16)(unsafe.Pointer(pPg + 28 + uintptr(i)*2))) - iNew
		if iCell >= 0 && iCell < nNew {
			pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(iCell*int32(2))
			if nCell > iCell {
				libc.Xmemmove(tls, pCellptr+2, pCellptr, uint32((nCell-iCell)*int32(2)))
			}
			nCell++
			_cachedCellSize(tls, pCArray, iCell+iNew)
			if _pageInsertArray(tls, pPg, pBegin, bp, pCellptr, iCell+iNew, int32(1), pCArray) != 0 {
				goto editpage_fail
			}
		}
		goto _2
	_2:
		;
		i++
	}
	/* Append cells to the end of the page */
	pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(nCell*int32(2))
	if _pageInsertArray(tls, pPg, pBegin, bp, pCellptr, iNew+nCell, nNew-nCell, pCArray) != 0 {
		goto editpage_fail
	}
	(*TMemPage)(unsafe.Pointer(pPg)).FnCell = uint16(uint16(nNew))
	(*TMemPage)(unsafe.Pointer(pPg)).FnOverflow = uint8(0)
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(3)))) = uint8(int32((*TMemPage)(unsafe.Pointer(pPg)).FnCell) >> libc.Int32FromInt32(8))
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(3)) + 1)) = uint8((*TMemPage)(unsafe.Pointer(pPg)).FnCell)
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)))) = uint8((int32(*(*uintptr)(unsafe.Pointer(bp))) - int32(int32(aData))) >> libc.Int32FromInt32(8))
	*(*Tu8)(unsafe.Pointer(aData + uintptr(hdr+int32(5)) + 1)) = uint8(int32(*(*uintptr)(unsafe.Pointer(bp))) - int32(int32(aData)))
	return SQLITE_OK
	goto editpage_fail
editpage_fail:
	;
	/* Unable to edit this page. Rebuild it from scratch instead. */
	if nNew < int32(1) {
		return _sqlite3CorruptError(tls, int32(78415))
	}
	_populateCellCache(tls, pCArray, iNew, nNew)
	return _rebuildPage(tls, pCArray, iNew, nNew, pPg)
}

// 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(96)
	defer tls.Free(96)
	var pBt, pOut, pStop, v1, v3, v4 uintptr
	var v2 Tu8
	var _ /* b at bp+20 */ TCellArray
	var _ /* pCell at bp+12 */ uintptr
	var _ /* pNew at bp+0 */ uintptr
	var _ /* pgnoNew at bp+8 */ TPgno
	var _ /* rc at bp+4 */ int32
	var _ /* szCell at bp+16 */ Tu16
	_, _, _, _, _, _, _ = pBt, pOut, pStop, v1, v2, v3, v4
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt /* Page number of pNew */
	if int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) == 0 {
		return _sqlite3CorruptError(tls, int32(78455))
	} /* 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)(unsafe.Pointer(bp + 4)) = _allocateBtreePage(tls, pBt, bp, bp+8, uint32(0), uint8(0))
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		pOut = pSpace + 4
		*(*uintptr)(unsafe.Pointer(bp + 12)) = *(*uintptr)(unsafe.Pointer(pPage + 36))
		*(*Tu16)(unsafe.Pointer(bp + 16)) = (*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, *(*uintptr)(unsafe.Pointer(bp + 12)))
		_zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp)), libc.Int32FromInt32(PTF_INTKEY)|libc.Int32FromInt32(PTF_LEAFDATA)|libc.Int32FromInt32(PTF_LEAF))
		(*(*TCellArray)(unsafe.Pointer(bp + 20))).FnCell = int32(1)
		(*(*TCellArray)(unsafe.Pointer(bp + 20))).FpRef = pPage
		(*(*TCellArray)(unsafe.Pointer(bp + 20))).FapCell = bp + 12
		(*(*TCellArray)(unsafe.Pointer(bp + 20))).FszCell = bp + 16
		*(*uintptr)(unsafe.Pointer(bp + 20 + 16)) = (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd
		*(*int32)(unsafe.Pointer(bp + 20 + 40)) = int32(2)
		*(*int32)(unsafe.Pointer(bp + 4)) = _rebuildPage(tls, bp+20, 0, int32(1), *(*uintptr)(unsafe.Pointer(bp)))
		if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return *(*int32)(unsafe.Pointer(bp + 4))
		}
		(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnFree = int32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FcellOffset) - uint32(2) - uint32(*(*Tu16)(unsafe.Pointer(bp + 16))))
		/* 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)(unsafe.Pointer(bp + 8)), uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pParent)).Fpgno, bp+4)
			if int32(*(*Tu16)(unsafe.Pointer(bp + 16))) > int32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FminLocal) {
				_ptrmapPutOvflPtr(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 12)), bp+4)
			}
		}
		/* 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)(unsafe.Pointer(bp + 12)) = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*(int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-int32(1))))))))
		pStop = *(*uintptr)(unsafe.Pointer(bp + 12)) + 9
		for {
			v1 = *(*uintptr)(unsafe.Pointer(bp + 12))
			*(*uintptr)(unsafe.Pointer(bp + 12))++
			if !(int32(*(*Tu8)(unsafe.Pointer(v1)))&int32(0x80) != 0 && *(*uintptr)(unsafe.Pointer(bp + 12)) < pStop) {
				break
			}
		}
		pStop = *(*uintptr)(unsafe.Pointer(bp + 12)) + 9
		for {
			v3 = *(*uintptr)(unsafe.Pointer(bp + 12))
			*(*uintptr)(unsafe.Pointer(bp + 12))++
			v2 = *(*Tu8)(unsafe.Pointer(v3))
			v4 = pOut
			pOut++
			*(*Tu8)(unsafe.Pointer(v4)) = v2
			if !(int32(v2)&int32(0x80) != 0 && *(*uintptr)(unsafe.Pointer(bp + 12)) < pStop) {
				break
			}
		}
		/* Insert the new divider cell into pParent. */
		if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 4)) = _insertCell(tls, pParent, int32((*TMemPage)(unsafe.Pointer(pParent)).FnCell), pSpace, int32(int32(pOut))-int32(int32(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(int32((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset)+int32(8)), *(*TPgno)(unsafe.Pointer(bp + 8)))
		/* Release the reference to the new page. */
		_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return *(*int32)(unsafe.Pointer(bp + 4))
}

// C documentation
//
//	/*
//	** This function is used to copy the contents of the b-tree node stored
//	** on page pFrom to page pTo. If page pFrom was not a leaf page, then
//	** the pointer-map entries for each child page are updated so that the
//	** parent page stored in the pointer map is page pTo. If pFrom contained
//	** any cells with overflow page pointers, then the corresponding pointer
//	** map entries are also updated so that the parent page is page pTo.
//	**
//	** If pFrom is currently carrying any overflow cells (entries in the
//	** MemPage.apOvfl[] array), they are not copied to pTo.
//	**
//	** Before returning, page pTo is reinitialized using btreeInitPage().
//	**
//	** The performance of this function is not critical. It is only used by
//	** the balance_shallower() and balance_deeper() procedures, neither of
//	** which are called often under normal circumstances.
//	*/
func _copyNodeContent(tls *libc.TLS, pFrom uintptr, pTo uintptr, pRC uintptr) {
	var aFrom, aTo, pBt uintptr
	var iData, iFromHdr, iToHdr, rc, v1 int32
	_, _, _, _, _, _, _, _ = aFrom, aTo, iData, iFromHdr, iToHdr, pBt, rc, v1
	if *(*int32)(unsafe.Pointer(pRC)) == SQLITE_OK {
		pBt = (*TMemPage)(unsafe.Pointer(pFrom)).FpBt
		aFrom = (*TMemPage)(unsafe.Pointer(pFrom)).FaData
		aTo = (*TMemPage)(unsafe.Pointer(pTo)).FaData
		iFromHdr = int32((*TMemPage)(unsafe.Pointer(pFrom)).FhdrOffset)
		if (*TMemPage)(unsafe.Pointer(pTo)).Fpgno == uint32(1) {
			v1 = int32(100)
		} else {
			v1 = 0
		}
		iToHdr = v1
		/* Copy the b-tree node content from page pFrom to page pTo. */
		iData = int32(*(*Tu8)(unsafe.Pointer(aFrom + uintptr(iFromHdr+int32(5)))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(aFrom + uintptr(iFromHdr+int32(5)) + 1)))
		libc.Xmemcpy(tls, aTo+uintptr(iData), aFrom+uintptr(iData), (*TBtShared)(unsafe.Pointer(pBt)).FusableSize-uint32(uint32(iData)))
		libc.Xmemcpy(tls, aTo+uintptr(iToHdr), aFrom+uintptr(iFromHdr), uint32(int32((*TMemPage)(unsafe.Pointer(pFrom)).FcellOffset)+int32(2)*int32((*TMemPage)(unsafe.Pointer(pFrom)).FnCell)))
		/* Reinitialize page pTo so that the contents of the MemPage structure
		 ** match the new data. The initialization of pTo can actually fail under
		 ** fairly obscure circumstances, even though it is a copy of initialized
		 ** page pFrom.
		 */
		(*TMemPage)(unsafe.Pointer(pTo)).FisInit = uint8(0)
		rc = _btreeInitPage(tls, pTo)
		if rc == SQLITE_OK {
			rc = _btreeComputeFreeSpace(tls, pTo)
		}
		if rc != SQLITE_OK {
			*(*int32)(unsafe.Pointer(pRC)) = rc
			return
		}
		/* If this is an auto-vacuum database, update the pointer-map entries
		 ** for any b-tree or overflow pages that pTo now contains the pointers to.
		 */
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			*(*int32)(unsafe.Pointer(pRC)) = _setChildPtrmaps(tls, pTo)
		}
	}
}

// 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(160)
	defer tls.Free(160)
	var aData, aSpace1, p, pBt, pCell, pCell1, pNew1, pNew2, pOld, pOld1, pOld2, pRight, pSrcEnd, pTemp, pTemp1, piCell, piEnd, v17, v22, v23, v25 uintptr
	var aPgno [5]TPgno
	var apDiv [2]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, szScratch, usableSpace, v1, v10, v12, v15, v26, v30, v31, v32, v5, v7 int32
	var fgA, fgB, leafCorrection, maskPage, sz Tu16
	var key Tu32
	var pgnoA, pgnoB, pgnoTemp TPgno
	var v13, v14 bool
	var v18 uint32
	var _ /* abDone at bp+60 */ [5]Tu8
	var _ /* apNew at bp+16 */ [5]uintptr
	var _ /* apOld at bp+4 */ [3]uintptr
	var _ /* b at bp+68 */ TCellArray
	var _ /* info at bp+136 */ TCellInfo
	var _ /* pNew at bp+132 */ uintptr
	var _ /* pgno at bp+56 */ TPgno
	var _ /* rc at bp+0 */ int32
	var _ /* szNew at bp+36 */ [5]int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aPgno, aSpace1, apDiv, 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, v10, v12, v13, v14, v15, v17, v18, v22, v23, v25, v26, v30, v31, v32, v5, v7 /* The whole database */
	nMaxCells = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    /* Allocated size of apCell, szCell, aFrom. */
	nNew = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         /* Next divider slot in pParent->aCell[] */
	*(*int32)(unsafe.Pointer(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, uint32(5))
	libc.Xmemset(tls, bp+68, 0, uint32(64))
	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 = int32((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow) + int32((*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-int32((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow) == int32((*TMemPage)(unsafe.Pointer(pParent)).FnCell) {
		pRight = (*TMemPage)(unsafe.Pointer(pParent)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset)+int32(8))
	} else {
		pRight = (*TMemPage)(unsafe.Pointer(pParent)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pParent)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pParent)).FaCellIdx + uintptr(int32(2)*(i+nxDiv-int32((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow))))))))
	}
	*(*TPgno)(unsafe.Pointer(bp + 56)) = _sqlite3Get4byte(tls, pRight)
	for int32(1) != 0 {
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = _getAndInitPage(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 56)), bp+4+uintptr(i)*4, 0)
		}
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			libc.Xmemset(tls, bp+4, 0, uint32(i+libc.Int32FromInt32(1))*uint32(4))
			goto balance_cleanup
		}
		if (*TMemPage)(unsafe.Pointer((*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i])).FnFree < 0 {
			*(*int32)(unsafe.Pointer(bp)) = _btreeComputeFreeSpace(tls, (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i])
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				libc.Xmemset(tls, bp+4, 0, uint32(i)*uint32(4))
				goto balance_cleanup
			}
		}
		nMaxCells += int32((*TMemPage)(unsafe.Pointer((*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i])).FnCell) + int32(libc.Uint32FromInt64(16)/libc.Uint32FromInt64(4))
		v1 = i
		i--
		if v1 == 0 {
			break
		}
		if (*TMemPage)(unsafe.Pointer(pParent)).FnOverflow != 0 && i+nxDiv == int32(*(*Tu16)(unsafe.Pointer(pParent + 28))) {
			apDiv[i] = *(*uintptr)(unsafe.Pointer(pParent + 36))
			*(*TPgno)(unsafe.Pointer(bp + 56)) = _sqlite3Get4byte(tls, apDiv[i])
			(*(*[5]int32)(unsafe.Pointer(bp + 36)))[i] = int32((*(*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(int32((*TMemPage)(unsafe.Pointer(pParent)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pParent)).FaCellIdx + uintptr(int32(2)*(i+nxDiv-int32((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow))))))))
			*(*TPgno)(unsafe.Pointer(bp + 56)) = _sqlite3Get4byte(tls, apDiv[i])
			(*(*[5]int32)(unsafe.Pointer(bp + 36)))[i] = int32((*(*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 int32((*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(apDiv[i]) - int32((*TMemPage)(unsafe.Pointer(pParent)).FaData)
				if iOff+(*(*[5]int32)(unsafe.Pointer(bp + 36)))[i] <= int32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize) {
					libc.Xmemcpy(tls, aOvflSpace+uintptr(iOff), apDiv[i], uint32((*(*[5]int32)(unsafe.Pointer(bp + 36)))[i]))
					apDiv[i] = aOvflSpace + uintptr(int32(apDiv[i])-int32((*TMemPage)(unsafe.Pointer(pParent)).FaData))
				}
			}
			_dropCell(tls, pParent, i+nxDiv-int32((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow), (*(*[5]int32)(unsafe.Pointer(bp + 36)))[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 = int32(uint32(uint32(nMaxCells))*uint32(4) + uint32(uint32(nMaxCells))*uint32(2) + (*TBtShared)(unsafe.Pointer(pBt)).FpageSize) /* aSpace1 */
	(*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell = _sqlite3DbMallocRaw(tls, uintptr(0), uint64(uint64(szScratch)))
	if (*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell == uintptr(0) {
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
		goto balance_cleanup
	}
	(*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell = (*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr(nMaxCells)*4
	aSpace1 = (*(*TCellArray)(unsafe.Pointer(bp + 68))).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)(unsafe.Pointer(bp + 68))).FpRef = (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[0]
	leafCorrection = uint16(int32((*TMemPage)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FpRef)).Fleaf) * int32(4))
	leafData = int32((*TMemPage)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FpRef)).FintKeyLeaf)
	i = 0
	for {
		if !(i < nOld) {
			break
		}
		pOld = (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i]
		limit = int32((*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 int32(*(*Tu8)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pOld)).FaData))) != int32(*(*Tu8)(unsafe.Pointer((*TMemPage)(unsafe.Pointer((*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[0])).FaData))) {
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(78876))
			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)(unsafe.Pointer(bp + 68))).FszCell+uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*2, 0, uint32(2)*uint32(limit+int32((*TMemPage)(unsafe.Pointer(pOld)).FnOverflow)))
		if int32((*TMemPage)(unsafe.Pointer(pOld)).FnOverflow) > 0 {
			if limit < int32(*(*Tu16)(unsafe.Pointer(pOld + 28))) {
				*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(78900))
				goto balance_cleanup
			}
			limit = int32(*(*Tu16)(unsafe.Pointer(pOld + 28)))
			j = 0
			for {
				if !(j < limit) {
					break
				}
				*(*uintptr)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*4)) = aData + uintptr(int32(int32(maskPage))&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer(piCell)))))
				piCell += uintptr(2)
				(*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell++
				goto _3
			_3:
				;
				j++
			}
			k = 0
			for {
				if !(k < int32((*TMemPage)(unsafe.Pointer(pOld)).FnOverflow)) {
					break
				}
				/* NOTE 1 */
				*(*uintptr)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*4)) = *(*uintptr)(unsafe.Pointer(pOld + 36 + uintptr(k)*4))
				(*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell++
				goto _4
			_4:
				;
				k++
			}
		}
		piEnd = aData + uintptr((*TMemPage)(unsafe.Pointer(pOld)).FcellOffset) + uintptr(int32(2)*int32((*TMemPage)(unsafe.Pointer(pOld)).FnCell))
		for piCell < piEnd {
			*(*uintptr)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*4)) = aData + uintptr(int32(int32(maskPage))&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer(piCell)))))
			piCell += uintptr(2)
			(*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell++
		}
		cntOld[i] = (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell
		if i < nOld-int32(1) && !(leafData != 0) {
			sz = uint16((*(*[5]int32)(unsafe.Pointer(bp + 36)))[i])
			*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*2)) = sz
			pTemp = aSpace1 + uintptr(iSpace1)
			iSpace1 += int32(int32(sz))
			libc.Xmemcpy(tls, pTemp, apDiv[i], uint32(uint32(sz)))
			*(*uintptr)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*4)) = pTemp + uintptr(leafCorrection)
			*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*2)) = uint16(int32(*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*2))) - int32(int32(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)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*4)), (*TMemPage)(unsafe.Pointer(pOld)).FaData+8, uint32(4))
			} else {
				for int32(*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*2))) < int32(4) {
					/* Do not allow any cells smaller than 4 bytes. If a smaller cell
					 ** does exist, pad it with 0x00 bytes. */
					v5 = iSpace1
					iSpace1++
					*(*Tu8)(unsafe.Pointer(aSpace1 + uintptr(v5))) = uint8(0x00)
					*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr((*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell)*2))++
				}
			}
			(*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell++
		}
		goto _2
	_2:
		;
		i++
	}
	/*
	 ** 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 = int32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(12) + uint32(uint32(leafCorrection)))
	v7 = libc.Int32FromInt32(0)
	k = v7
	i = v7
	for {
		if !(i < nOld) {
			break
		}
		p = (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i]
		*(*uintptr)(unsafe.Pointer(bp + 68 + 16 + uintptr(k)*4)) = (*TMemPage)(unsafe.Pointer(p)).FaDataEnd
		*(*int32)(unsafe.Pointer(bp + 68 + 40 + uintptr(k)*4)) = cntOld[i]
		if k != 0 && *(*int32)(unsafe.Pointer(bp + 68 + 40 + uintptr(k)*4)) == *(*int32)(unsafe.Pointer(bp + 68 + 40 + uintptr(k-int32(1))*4)) {
			k-- /* Omit b.ixNx[] entry for child pages with no cells */
		}
		if !(leafData != 0) {
			k++
			*(*uintptr)(unsafe.Pointer(bp + 68 + 16 + uintptr(k)*4)) = (*TMemPage)(unsafe.Pointer(pParent)).FaDataEnd
			*(*int32)(unsafe.Pointer(bp + 68 + 40 + uintptr(k)*4)) = cntOld[i] + int32(1)
		}
		(*(*[5]int32)(unsafe.Pointer(bp + 36)))[i] = usableSpace - (*TMemPage)(unsafe.Pointer(p)).FnFree
		j = 0
		for {
			if !(j < int32((*TMemPage)(unsafe.Pointer(p)).FnOverflow)) {
				break
			}
			*(*int32)(unsafe.Pointer(bp + 36 + uintptr(i)*4)) += int32(2) + int32((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(p)).FxCellSize})))(tls, p, *(*uintptr)(unsafe.Pointer(p + 36 + uintptr(j)*4))))
			goto _8
		_8:
			;
			j++
		}
		cntNew[i] = cntOld[i]
		goto _6
	_6:
		;
		i++
		k++
	}
	k = nOld
	i = 0
	for {
		if !(i < k) {
			break
		}
		for (*(*[5]int32)(unsafe.Pointer(bp + 36)))[i] > usableSpace {
			if i+int32(1) >= k {
				k = i + int32(2)
				if k > libc.Int32FromInt32(NB)+libc.Int32FromInt32(2) {
					*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(79001))
					goto balance_cleanup
				}
				(*(*[5]int32)(unsafe.Pointer(bp + 36)))[k-int32(1)] = 0
				cntNew[k-int32(1)] = (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell
			}
			sz1 = int32(2) + int32(_cachedCellSize(tls, bp+68, cntNew[i]-int32(1)))
			*(*int32)(unsafe.Pointer(bp + 36 + uintptr(i)*4)) -= sz1
			if !(leafData != 0) {
				if cntNew[i] < (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell {
					sz1 = int32(2) + int32(_cachedCellSize(tls, bp+68, cntNew[i]))
				} else {
					sz1 = 0
				}
			}
			*(*int32)(unsafe.Pointer(bp + 36 + uintptr(i+int32(1))*4)) += sz1
			cntNew[i]--
		}
		for cntNew[i] < (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell {
			sz1 = int32(2) + int32(_cachedCellSize(tls, bp+68, cntNew[i]))
			if (*(*[5]int32)(unsafe.Pointer(bp + 36)))[i]+sz1 > usableSpace {
				break
			}
			*(*int32)(unsafe.Pointer(bp + 36 + uintptr(i)*4)) += sz1
			cntNew[i]++
			if !(leafData != 0) {
				if cntNew[i] < (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell {
					sz1 = int32(2) + int32(_cachedCellSize(tls, bp+68, cntNew[i]))
				} else {
					sz1 = 0
				}
			}
			*(*int32)(unsafe.Pointer(bp + 36 + uintptr(i+int32(1))*4)) -= sz1
		}
		if cntNew[i] >= (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell {
			k = i + int32(1)
		} else {
			if i > 0 {
				v10 = cntNew[i-int32(1)]
			} else {
				v10 = 0
			}
			if cntNew[i] <= v10 {
				*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(79034))
				goto balance_cleanup
			}
		}
		goto _9
	_9:
		;
		i++
	}
	/*
	 ** 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)(unsafe.Pointer(bp + 36)))[i]         /* Size of sibling on the right */
		szLeft = (*(*[5]int32)(unsafe.Pointer(bp + 36)))[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+68, d)
		for cond := true; cond; cond = r >= 0 {
			szR = int32(_cachedCellSize(tls, bp+68, r))
			szD = int32(*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr(d)*2)))
			if v14 = szRight != 0; v14 {
				if v13 = bBulk != 0; !v13 {
					if i == k-int32(1) {
						v12 = 0
					} else {
						v12 = int32(2)
					}
				}
			}
			if v14 && (v13 || szRight+szD+int32(2) > szLeft-(szR+v12)) {
				break
			}
			szRight += szD + int32(2)
			szLeft -= szR + int32(2)
			cntNew[i-int32(1)] = r
			r--
			d--
		}
		(*(*[5]int32)(unsafe.Pointer(bp + 36)))[i] = szRight
		(*(*[5]int32)(unsafe.Pointer(bp + 36)))[i-int32(1)] = szLeft
		if i > int32(1) {
			v15 = cntNew[i-int32(2)]
		} else {
			v15 = 0
		}
		if cntNew[i-int32(1)] <= v15 {
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(79078))
			goto balance_cleanup
		}
		goto _11
	_11:
		;
		i--
	}
	/* 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 = int32(*(*Tu8)(unsafe.Pointer((*TMemPage)(unsafe.Pointer((*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[0])).FaData)))
	i = 0
	for {
		if !(i < k) {
			break
		}
		if i < nOld {
			v17 = (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i]
			(*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i] = v17
			*(*uintptr)(unsafe.Pointer(bp + 132)) = v17
			(*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i] = uintptr(0)
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 132)))).FpDbPage)
			nNew++
			if _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 132)))).FpDbPage) != int32(1)+libc.BoolInt32(i == iParentIdx-nxDiv) && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(79111))
			}
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				goto balance_cleanup
			}
		} else {
			if bBulk != 0 {
				v18 = uint32(1)
			} else {
				v18 = *(*TPgno)(unsafe.Pointer(bp + 56))
			}
			*(*int32)(unsafe.Pointer(bp)) = _allocateBtreePage(tls, pBt, bp+132, bp+56, v18, uint8(0))
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				goto balance_cleanup
			}
			_zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp + 132)), pageFlags)
			(*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i] = *(*uintptr)(unsafe.Pointer(bp + 132))
			nNew++
			cntOld[i] = (*(*TCellArray)(unsafe.Pointer(bp + 68))).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)(unsafe.Pointer(bp + 132)))).Fpgno, uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pParent)).Fpgno, bp)
				if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
					goto balance_cleanup
				}
			}
		}
		goto _16
	_16:
		;
		i++
	}
	/*
	 ** 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((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).Fpgno
		goto _19
	_19:
		;
		i++
	}
	i = 0
	for {
		if !(i < nNew-int32(1)) {
			break
		}
		iB = i
		j = i + int32(1)
		for {
			if !(j < nNew) {
				break
			}
			if (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[j])).Fpgno < (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iB])).Fpgno {
				iB = j
			}
			goto _21
		_21:
			;
			j++
		}
		/* 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((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).Fpgno
			pgnoB = (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iB])).Fpgno
			pgnoTemp = uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize + uint32(1)
			fgA = (*TDbPage)(unsafe.Pointer((*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).FpDbPage)).Fflags
			fgB = (*TDbPage)(unsafe.Pointer((*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iB])).FpDbPage)).Fflags
			_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).FpDbPage, pgnoTemp, fgB)
			_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iB])).FpDbPage, pgnoA, fgA)
			_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).FpDbPage, pgnoB, fgB)
			(*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).Fpgno = pgnoB
			(*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iB])).Fpgno = pgnoA
		}
		goto _20
	_20:
		;
		i++
	}
	_sqlite3Put4byte(tls, pRight, (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[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 {
			v22 = bp + 16
		} else {
			v22 = bp + 4
		}
		pOld1 = *(*uintptr)(unsafe.Pointer(v22 + uintptr(nOld-int32(1))*4))
		libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[nNew-int32(1)])).FaData+8, (*TMemPage)(unsafe.Pointer(pOld1)).FaData+8, uint32(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 {
		v23 = (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[0]
		pOld2 = v23
		pNew1 = v23
		cntOldNext = int32((*TMemPage)(unsafe.Pointer(pNew1)).FnCell) + int32((*TMemPage)(unsafe.Pointer(pNew1)).FnOverflow)
		iNew = 0
		iOld = 0
		i = 0
		for {
			if !(i < (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell) {
				break
			}
			pCell = *(*uintptr)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr(i)*4))
			for i == cntOldNext {
				iOld++
				if iOld < nNew {
					v25 = (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iOld]
				} else {
					v25 = (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[iOld]
				}
				pOld2 = v25
				cntOldNext += int32((*TMemPage)(unsafe.Pointer(pOld2)).FnCell) + int32((*TMemPage)(unsafe.Pointer(pOld2)).FnOverflow) + libc.BoolInt32(!(leafData != 0))
			}
			if i == cntNew[iNew] {
				iNew++
				v26 = iNew
				pNew1 = (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[v26]
				if !(leafData != 0) {
					goto _24
				}
			}
			/* 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] || !(uint32(pCell) >= uint32((*TMemPage)(unsafe.Pointer(pOld2)).FaData) && uint32(pCell) < uint32((*TMemPage)(unsafe.Pointer(pOld2)).FaDataEnd)) {
				if !(leafCorrection != 0) {
					_ptrmapPut(tls, pBt, _sqlite3Get4byte(tls, pCell), uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pNew1)).Fpgno, bp)
				}
				if int32(_cachedCellSize(tls, bp+68, i)) > int32((*TMemPage)(unsafe.Pointer(pNew1)).FminLocal) {
					_ptrmapPutOvflPtr(tls, pNew1, pOld2, pCell, bp)
				}
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					goto balance_cleanup
				}
			}
			goto _24
		_24:
			;
			i++
		}
	}
	/* Insert new divider cells into pParent. */
	i = 0
	for {
		if !(i < nNew-int32(1)) {
			break
		}
		pNew2 = (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i]
		j = cntNew[i]
		pCell1 = *(*uintptr)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr(j)*4))
		sz2 = int32(*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr(j)*2))) + int32(int32(leafCorrection))
		pTemp1 = aOvflSpace + uintptr(iOvflSpace)
		if !((*TMemPage)(unsafe.Pointer(pNew2)).Fleaf != 0) {
			libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(pNew2)).FaData+8, pCell1, uint32(4))
		} else {
			if leafData != 0 {
				j--
				(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pNew2)).FxParseCell})))(tls, pNew2, *(*uintptr)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell + uintptr(j)*4)), bp+136)
				pCell1 = pTemp1
				sz2 = int32(4) + _sqlite3PutVarint(tls, pCell1+4, uint64((*(*TCellInfo)(unsafe.Pointer(bp + 136))).FnKey))
				pTemp1 = uintptr(0)
			} else {
				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 int32(*(*Tu16)(unsafe.Pointer((*(*TCellArray)(unsafe.Pointer(bp + 68))).FszCell + uintptr(j)*2))) == int32(4) {
					sz2 = int32((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pParent)).FxCellSize})))(tls, pParent, pCell1))
				}
			}
		}
		iOvflSpace += sz2
		k = 0
		for {
			if !(k < libc.Int32FromInt32(NB)*libc.Int32FromInt32(2) && *(*int32)(unsafe.Pointer(bp + 68 + 40 + uintptr(k)*4)) <= j) {
				break
			}
			goto _28
		_28:
			;
			k++
		}
		pSrcEnd = *(*uintptr)(unsafe.Pointer(bp + 68 + 16 + uintptr(k)*4))
		if uint32(pCell1) < uint32(pSrcEnd) && uint32(pCell1+uintptr(sz2)) > uint32(pSrcEnd) {
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(79311))
			goto balance_cleanup
		}
		*(*int32)(unsafe.Pointer(bp)) = _insertCell(tls, pParent, nxDiv+i, pCell1, sz2, pTemp1, (*TMemPage)(unsafe.Pointer(pNew2)).Fpgno)
		if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
			goto balance_cleanup
		}
		goto _27
	_27:
		;
		i++
	}
	/* 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 {
			v30 = -i
		} else {
			v30 = i
		}
		iPg = v30
		if (*(*[5]Tu8)(unsafe.Pointer(bp + 60)))[iPg] != 0 {
			goto _29
		} /* 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 {
				v31 = libc.Int32FromInt32(0)
				iOld1 = v31
				iNew1 = v31
				nNewCell = cntNew[0]
			} else {
				if iPg < nOld {
					v32 = cntOld[iPg-int32(1)] + libc.BoolInt32(!(leafData != 0))
				} else {
					v32 = (*(*TCellArray)(unsafe.Pointer(bp + 68))).FnCell
				}
				iOld1 = v32
				iNew1 = cntNew[iPg-int32(1)] + libc.BoolInt32(!(leafData != 0))
				nNewCell = cntNew[iPg] - iNew1
			}
			*(*int32)(unsafe.Pointer(bp)) = _editPage(tls, (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iPg], iOld1, iNew1, nNewCell, bp+68)
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				goto balance_cleanup
			}
			(*(*[5]Tu8)(unsafe.Pointer(bp + 60)))[iPg]++
			(*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[iPg])).FnFree = usableSpace - (*(*[5]int32)(unsafe.Pointer(bp + 36)))[iPg]
		}
		goto _29
	_29:
		;
		i++
	}
	/* All pages have been processed exactly once */
	if isRoot != 0 && int32((*TMemPage)(unsafe.Pointer(pParent)).FnCell) == 0 && int32((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset) <= (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[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)(unsafe.Pointer(bp)) = _defragmentPage(tls, (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[0], -int32(1))
		_copyNodeContent(tls, (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[0], pParent, bp)
		_freePage(tls, (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[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((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).FaData+8)
				_ptrmapPut(tls, pBt, key, uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer((*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])).Fpgno, bp)
				goto _33
			_33:
				;
				i++
			}
		}
	}
	/* Free any old pages that were not reused as new pages.
	 */
	i = nNew
	for {
		if !(i < nOld) {
			break
		}
		_freePage(tls, (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i], bp)
		goto _34
	_34:
		;
		i++
	}
	/*
	 ** Cleanup before returning.
	 */
	goto balance_cleanup
balance_cleanup:
	;
	_sqlite3DbFree(tls, uintptr(0), (*(*TCellArray)(unsafe.Pointer(bp + 68))).FapCell)
	i = 0
	for {
		if !(i < nOld) {
			break
		}
		_releasePage(tls, (*(*[3]uintptr)(unsafe.Pointer(bp + 4)))[i])
		goto _35
	_35:
		;
		i++
	}
	i = 0
	for {
		if !(i < nNew) {
			break
		}
		_releasePage(tls, (*(*[5]uintptr)(unsafe.Pointer(bp + 16)))[i])
		goto _36
	_36:
		;
		i++
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** This function is called when the root page of a b-tree structure is
//	** overfull (has one or more overflow pages).
//	**
//	** A new child page is allocated and the contents of the current root
//	** page, including overflow cells, are copied into the child. The root
//	** page is then overwritten to make it an empty page with the right-child
//	** pointer pointing to the new page.
//	**
//	** Before returning, all pointer-map entries corresponding to pages
//	** that the new child-page now contains pointers to are updated. The
//	** entry corresponding to the new right-child pointer of the root
//	** page is also updated.
//	**
//	** If successful, *ppChild is set to contain a reference to the child
//	** page and SQLITE_OK is returned. In this case the caller is required
//	** to call releasePage() on *ppChild exactly once. If an error occurs,
//	** an error code is returned and *ppChild is set to 0.
//	*/
func _balance_deeper(tls *libc.TLS, pRoot uintptr, ppChild uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pBt uintptr
	var _ /* pChild at bp+4 */ uintptr
	var _ /* pgnoChild at bp+8 */ TPgno
	var _ /* rc at bp+0 */ int32
	_ = pBt                                          /* Return value from subprocedures */
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* Pointer to a new child page */
	*(*TPgno)(unsafe.Pointer(bp + 8)) = uint32(0)    /* Page number of the new child page */
	pBt = (*TMemPage)(unsafe.Pointer(pRoot)).FpBt    /* The BTree */
	/* Make pRoot, the root page of the b-tree, writable. Allocate a new
	 ** page that will become the new right-child of pPage. Copy the contents
	 ** of the node stored on pRoot into the new child page.
	 */
	*(*int32)(unsafe.Pointer(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pRoot)).FpDbPage)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _allocateBtreePage(tls, pBt, bp+4, bp+8, (*TMemPage)(unsafe.Pointer(pRoot)).Fpgno, uint8(0))
		_copyNodeContent(tls, pRoot, *(*uintptr)(unsafe.Pointer(bp + 4)), bp)
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			_ptrmapPut(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 8)), uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pRoot)).Fpgno, bp)
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		*(*uintptr)(unsafe.Pointer(ppChild)) = uintptr(0)
		_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
		return *(*int32)(unsafe.Pointer(bp))
	}
	/* Copy the overflow cells from pRoot to pChild */
	libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp + 4))+28, pRoot+28, uint32((*TMemPage)(unsafe.Pointer(pRoot)).FnOverflow)*uint32(2))
	libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp + 4))+36, pRoot+36, uint32((*TMemPage)(unsafe.Pointer(pRoot)).FnOverflow)*uint32(4))
	(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FnOverflow = (*TMemPage)(unsafe.Pointer(pRoot)).FnOverflow
	/* Zero the contents of pRoot. Then install pChild as the right-child. */
	_zeroPage(tls, pRoot, int32(*(*Tu8)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FaData))) & ^libc.Int32FromInt32(PTF_LEAF))
	_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pRoot)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pRoot)).FhdrOffset)+int32(8)), *(*TPgno)(unsafe.Pointer(bp + 8)))
	*(*uintptr)(unsafe.Pointer(ppChild)) = *(*uintptr)(unsafe.Pointer(bp + 4))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return SQLITE_CORRUPT if any cursor other than pCur is currently valid
//	** on the same B-tree as pCur.
//	**
//	** This can occur if a database is corrupt with two or more SQL tables
//	** pointing to the same b-tree.  If an insert occurs on one SQL table
//	** and causes a BEFORE TRIGGER to do a secondary insert on the other SQL
//	** table linked to the same b-tree.  If the secondary insert causes a
//	** rebalance, that can change content out from under the cursor on the
//	** first SQL table, violating invariants on the first insert.
//	*/
func _anotherValidCursor(tls *libc.TLS, pCur uintptr) (r int32) {
	var pOther uintptr
	_ = pOther
	pOther = (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FpCursor
	for {
		if !(pOther != 0) {
			break
		}
		if pOther != pCur && int32((*TBtCursor)(unsafe.Pointer(pOther)).FeState) == CURSOR_VALID && (*TBtCursor)(unsafe.Pointer(pOther)).FpPage == (*TBtCursor)(unsafe.Pointer(pCur)).FpPage {
			return _sqlite3CorruptError(tls, int32(79543))
		}
		goto _1
	_1:
		;
		pOther = (*TBtCursor)(unsafe.Pointer(pOther)).FpNext
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The page that pCur currently points to has just been modified in
//	** some way. This function figures out if this modification means the
//	** tree needs to be balanced, and if so calls the appropriate balancing
//	** routine. Balancing routines are:
//	**
//	**   balance_quick()
//	**   balance_deeper()
//	**   balance_nonroot()
//	*/
func _balance(tls *libc.TLS, pCur uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iIdx, iPage, rc, v1, v2 int32
	var pFree, pPage, pParent, pSpace uintptr
	var v3 bool
	var _ /* aBalanceQuickSpace at bp+0 */ [13]Tu8
	_, _, _, _, _, _, _, _, _, _ = iIdx, iPage, pFree, pPage, pParent, pSpace, rc, v1, v2, v3
	rc = SQLITE_OK
	pFree = uintptr(0)
	for cond := true; cond; cond = rc == SQLITE_OK {
		pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		if (*TMemPage)(unsafe.Pointer(pPage)).FnFree < 0 && _btreeComputeFreeSpace(tls, pPage) != 0 {
			break
		}
		if int32((*TMemPage)(unsafe.Pointer(pPage)).FnOverflow) == 0 && (*TMemPage)(unsafe.Pointer(pPage)).FnFree*int32(3) <= int32((*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FusableSize)*int32(2) {
			/* No rebalance required as long as:
			 **   (1) There are no overflow cells
			 **   (2) The amount of free space on the page is less than 2/3rds of
			 **       the total usable space on the page. */
			break
		} else {
			v1 = int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)
			iPage = v1
			if v1 == 0 {
				if v3 = (*TMemPage)(unsafe.Pointer(pPage)).FnOverflow != 0; v3 {
					v2 = _anotherValidCursor(tls, pCur)
					rc = v2
				}
				if v3 && v2 == SQLITE_OK {
					/* The root page of the b-tree is overfull. In this case call the
					 ** balance_deeper() function to create a new child for the root-page
					 ** and copy the current contents of the root-page to it. The
					 ** next iteration of the do-loop will balance the child page.
					 */
					rc = _balance_deeper(tls, pPage, pCur+120+1*4)
					if rc == SQLITE_OK {
						(*TBtCursor)(unsafe.Pointer(pCur)).FiPage = int8(1)
						(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(0)
						*(*Tu16)(unsafe.Pointer(pCur + 72)) = uint16(0)
						*(*uintptr)(unsafe.Pointer(pCur + 120)) = pPage
						(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 120 + 1*4))
					}
				} else {
					break
				}
			} else {
				if _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage) > int32(1) {
					/* The page being written is not a root page, and there is currently
					 ** more than one reference to it. This only happens if the page is one
					 ** of its own ancestor pages. Corruption. */
					rc = _sqlite3CorruptError(tls, int32(79603))
				} else {
					pParent = *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(iPage-int32(1))*4))
					iIdx = int32(*(*Tu16)(unsafe.Pointer(pCur + 72 + uintptr(iPage-int32(1))*2)))
					rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pParent)).FpDbPage)
					if rc == SQLITE_OK && (*TMemPage)(unsafe.Pointer(pParent)).FnFree < 0 {
						rc = _btreeComputeFreeSpace(tls, pParent)
					}
					if rc == SQLITE_OK {
						if (*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf != 0 && int32((*TMemPage)(unsafe.Pointer(pPage)).FnOverflow) == int32(1) && int32(*(*Tu16)(unsafe.Pointer(pPage + 28))) == int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) && (*TMemPage)(unsafe.Pointer(pParent)).Fpgno != uint32(1) && int32((*TMemPage)(unsafe.Pointer(pParent)).FnCell) == iIdx {
							/* Call balance_quick() to create a new sibling of pPage on which
							 ** to store the overflow cell. balance_quick() inserts a new cell
							 ** into pParent, which may cause pParent overflow. If this
							 ** happens, the next iteration of the do-loop will balance pParent
							 ** use either balance_nonroot() or balance_deeper(). Until this
							 ** happens, the overflow cell is stored in the aBalanceQuickSpace[]
							 ** buffer.
							 **
							 ** The purpose of the following assert() is to check that only a
							 ** single call to balance_quick() is made for each call to this
							 ** function. If this were not verified, a subtle bug involving reuse
							 ** of the aBalanceQuickSpace[] might sneak in.
							 */
							rc = _balance_quick(tls, pParent, pPage, bp)
						} else {
							/* In this case, call balance_nonroot() to redistribute cells
							 ** between pPage and up to 2 of its sibling pages. This involves
							 ** modifying the contents of pParent, which may cause pParent to
							 ** become overfull or underfull. The next iteration of the do-loop
							 ** will balance the parent page to correct this.
							 **
							 ** If the parent page becomes overfull, the overflow cell or cells
							 ** are stored in the pSpace buffer allocated immediately below.
							 ** A subsequent iteration of the do-loop will deal with this by
							 ** calling balance_nonroot() (balance_deeper() may be called first,
							 ** but it doesn't deal with overflow cells - just moves them to a
							 ** different page). Once this subsequent call to balance_nonroot()
							 ** has completed, it is safe to release the pSpace buffer used by
							 ** the previous call, as the overflow cell data will have been
							 ** copied either into the body of a database page or into the new
							 ** pSpace buffer passed to the latter call to balance_nonroot().
							 */
							pSpace = _sqlite3PageMalloc(tls, int32((*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FpageSize))
							rc = _balance_nonroot(tls, pParent, iIdx, pSpace, libc.BoolInt32(iPage == int32(1)), int32((*TBtCursor)(unsafe.Pointer(pCur)).Fhints)&int32(BTREE_BULKLOAD))
							if pFree != 0 {
								/* If pFree is not NULL, it points to the pSpace buffer used
								 ** by a previous call to balance_nonroot(). Its contents are
								 ** now stored either on real database pages or within the
								 ** new pSpace buffer, so it may be safely freed here. */
								_sqlite3PageFree(tls, pFree)
							}
							/* The pSpace buffer will be freed after the next call to
							 ** balance_nonroot(), or just before this function returns, whichever
							 ** comes first. */
							pFree = pSpace
						}
					}
					(*TMemPage)(unsafe.Pointer(pPage)).FnOverflow = uint8(0)
					/* The next iteration of the do-loop balances the parent page. */
					_releasePage(tls, pPage)
					(*TBtCursor)(unsafe.Pointer(pCur)).FiPage--
					(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*4))
				}
			}
		}
	}
	if pFree != 0 {
		_sqlite3PageFree(tls, pFree)
	}
	return rc
}

// C documentation
//
//	/* Overwrite content from pX into pDest.  Only do the write if the
//	** content is different from what is already there.
//	*/
func _btreeOverwriteContent(tls *libc.TLS, pPage uintptr, pDest uintptr, pX uintptr, iOffset int32, iAmt int32) (r int32) {
	var i, nData, rc, rc1, rc2 int32
	_, _, _, _, _ = i, nData, rc, rc1, rc2
	nData = (*TBtreePayload)(unsafe.Pointer(pX)).FnData - iOffset
	if nData <= 0 {
		i = 0
		for {
			if !(i < iAmt && int32(*(*Tu8)(unsafe.Pointer(pDest + uintptr(i)))) == 0) {
				break
			}
			goto _1
		_1:
			;
			i++
		}
		if i < iAmt {
			rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
			if rc != 0 {
				return rc
			}
			libc.Xmemset(tls, pDest+uintptr(i), 0, uint32(iAmt-i))
		}
	} else {
		if nData < iAmt {
			/* Mixed read data and zeros at the end.  Make a recursive call
			 ** to write the zeros then fall through to write the real data */
			rc1 = _btreeOverwriteContent(tls, pPage, pDest+uintptr(nData), pX, iOffset+nData, iAmt-nData)
			if rc1 != 0 {
				return rc1
			}
			iAmt = nData
		}
		if libc.Xmemcmp(tls, pDest, (*TBtreePayload)(unsafe.Pointer(pX)).FpData+uintptr(iOffset), uint32(uint32(iAmt))) != 0 {
			rc2 = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
			if rc2 != 0 {
				return rc2
			}
			/* In a corrupt database, it is possible for the source and destination
			 ** buffers to overlap.  This is harmless since the database is already
			 ** corrupt but it does cause valgrind and ASAN warnings.  So use
			 ** memmove(). */
			libc.Xmemmove(tls, pDest, (*TBtreePayload)(unsafe.Pointer(pX)).FpData+uintptr(iOffset), uint32(uint32(iAmt)))
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Overwrite the cell that cursor pCur is pointing to with fresh content
//	** contained in pX.  In this variant, pCur is pointing to an overflow
//	** cell.
//	*/
func _btreeOverwriteOverflowCell(tls *libc.TLS, pCur uintptr, pX uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iOffset, nTotal, rc int32
	var ovflPageSize Tu32
	var ovflPgno TPgno
	var pBt uintptr
	var _ /* pPage at bp+0 */ uintptr
	_, _, _, _, _, _ = iOffset, nTotal, ovflPageSize, ovflPgno, pBt, rc                                /* Next byte of pX->pData to write */
	nTotal = (*TBtreePayload)(unsafe.Pointer(pX)).FnData + (*TBtreePayload)(unsafe.Pointer(pX)).FnZero /* Return code */
	*(*uintptr)(unsafe.Pointer(bp)) = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage                        /* Size to write on overflow page */
	/* pCur is an overflow cell */
	/* Overwrite the local portion first */
	rc = _btreeOverwriteContent(tls, *(*uintptr)(unsafe.Pointer(bp)), (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload, pX, 0, int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal))
	if rc != 0 {
		return rc
	}
	/* Now overwrite the overflow pages */
	iOffset = int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)
	ovflPgno = _sqlite3Get4byte(tls, (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload+uintptr(iOffset))
	pBt = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpBt
	ovflPageSize = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4)
	for cond := true; cond; cond = iOffset < nTotal {
		rc = _btreeGetPage(tls, pBt, ovflPgno, bp, 0)
		if rc != 0 {
			return rc
		}
		if _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage) != int32(1) || (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FisInit != 0 {
			rc = _sqlite3CorruptError(tls, int32(79767))
		} else {
			if uint32(uint32(iOffset))+ovflPageSize < uint32(uint32(nTotal)) {
				ovflPgno = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData)
			} else {
				ovflPageSize = uint32(nTotal - iOffset)
			}
			rc = _btreeOverwriteContent(tls, *(*uintptr)(unsafe.Pointer(bp)), (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+uintptr(4), pX, iOffset, int32(int32(ovflPageSize)))
		}
		_sqlite3PagerUnref(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
		if rc != 0 {
			return rc
		}
		iOffset = int32(uint32(iOffset) + ovflPageSize)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Overwrite the cell that cursor pCur is pointing to with fresh content
//	** contained in pX.
//	*/
func _btreeOverwriteCell(tls *libc.TLS, pCur uintptr, pX uintptr) (r int32) {
	var nTotal int32
	var pPage uintptr
	_, _ = nTotal, pPage
	nTotal = (*TBtreePayload)(unsafe.Pointer(pX)).FnData + (*TBtreePayload)(unsafe.Pointer(pX)).FnZero /* Total bytes of to write */
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage                                                  /* Page being written */
	if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload+uintptr((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) > (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd || (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload < (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset) {
		return _sqlite3CorruptError(tls, int32(79795))
	}
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) == nTotal {
		/* The entire cell is local */
		return _btreeOverwriteContent(tls, pPage, (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload, pX, 0, int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal))
	} else {
		/* The cell contains overflow content */
		return _btreeOverwriteOverflowCell(tls, pCur, pX)
	}
	return r
}

// 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(144)
	defer tls.Free(144)
	var idx int32
	var newCell, oldCell, p, pPage, v3, p1, p4, p5 uintptr
	var ovfl TPgno
	var v2 Tu16
	var _ /* info at bp+112 */ TCellInfo
	var _ /* info at bp+88 */ 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+48 */ TBtreePayload
	_, _, _, _, _, _, _, _, _, _, _ = idx, newCell, oldCell, ovfl, p, pPage, v2, v3, p1, p4, p5
	*(*int32)(unsafe.Pointer(bp + 4)) = seekResult /* -1: before desired location  +1: after */
	*(*int32)(unsafe.Pointer(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 int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_Multiple) != 0 {
		*(*int32)(unsafe.Pointer(bp)) = _saveAllCursors(tls, (*TBtree)(unsafe.Pointer(p)).FpBt, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(bp))
		}
		if *(*int32)(unsafe.Pointer(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(79876))
		}
	}
	/* Ensure that the cursor is not in the CURSOR_FAULT state and that it
	 ** points to a valid cell.
	 */
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
		*(*int32)(unsafe.Pointer(bp)) = _moveToRoot(tls, pCur)
		if *(*int32)(unsafe.Pointer(bp)) != 0 && *(*int32)(unsafe.Pointer(bp)) != int32(SQLITE_EMPTY) {
			return *(*int32)(unsafe.Pointer(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 int32((*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 int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize) != 0 && (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload == uint32((*TBtreePayload)(unsafe.Pointer(pX)).FnData)+uint32((*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)(unsafe.Pointer(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)(unsafe.Pointer(bp)) = _sqlite3BtreeTableMoveto(tls, pCur, (*TBtreePayload)(unsafe.Pointer(pX)).FnKey, libc.BoolInt32(flags&int32(BTREE_APPEND) != 0), bp+4)
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					return *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp + 4)) == 0 && flags&int32(BTREE_SAVEPOSITION) == 0 {
			if (*TBtreePayload)(unsafe.Pointer(pX)).FnMem != 0 {
				(*(*TUnpackedRecord)(unsafe.Pointer(bp + 16))).FpKeyInfo = (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo
				(*(*TUnpackedRecord)(unsafe.Pointer(bp + 16))).FaMem = (*TBtreePayload)(unsafe.Pointer(pX)).FaMem
				(*(*TUnpackedRecord)(unsafe.Pointer(bp + 16))).FnField = (*TBtreePayload)(unsafe.Pointer(pX)).FnMem
				(*(*TUnpackedRecord)(unsafe.Pointer(bp + 16))).Fdefault_rc = 0
				(*(*TUnpackedRecord)(unsafe.Pointer(bp + 16))).FeqSeen = uint8(0)
				*(*int32)(unsafe.Pointer(bp)) = _sqlite3BtreeIndexMoveto(tls, pCur, bp+16, bp+4)
			} else {
				*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp)) != 0 {
				return *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp + 4)) == 0 {
			_getCellInfo(tls, pCur)
			if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == (*TBtreePayload)(unsafe.Pointer(pX)).FnKey {
				(*(*TBtreePayload)(unsafe.Pointer(bp + 48))).FpData = (*TBtreePayload)(unsafe.Pointer(pX)).FpKey
				(*(*TBtreePayload)(unsafe.Pointer(bp + 48))).FnData = int32((*TBtreePayload)(unsafe.Pointer(pX)).FnKey)
				(*(*TBtreePayload)(unsafe.Pointer(bp + 48))).FnZero = 0
				return _btreeOverwriteCell(tls, pCur, bp+48)
			}
		}
	}
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	if (*TMemPage)(unsafe.Pointer(pPage)).FnFree < 0 {
		if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) > int32(CURSOR_INVALID) {
			/* ^^^^^--- due to the moveToRoot() call above */
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(79999))
		} else {
			*(*int32)(unsafe.Pointer(bp)) = _btreeComputeFreeSpace(tls, pPage)
		}
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(bp))
		}
	}
	newCell = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpTmpSpace
	if flags&int32(BTREE_PREFORMAT) != 0 {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
		*(*int32)(unsafe.Pointer(bp + 8)) = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FnPreformatSize
		if *(*int32)(unsafe.Pointer(bp + 8)) < int32(4) {
			*(*int32)(unsafe.Pointer(bp + 8)) = int32(4)
			*(*uint8)(unsafe.Pointer(newCell + 3)) = uint8(0)
		}
		if (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FautoVacuum != 0 && *(*int32)(unsafe.Pointer(bp + 8)) > int32((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, newCell, bp+88)
			if (*(*TCellInfo)(unsafe.Pointer(bp + 88))).FnPayload != uint32((*(*TCellInfo)(unsafe.Pointer(bp + 88))).FnLocal) {
				ovfl = _sqlite3Get4byte(tls, newCell+uintptr(*(*int32)(unsafe.Pointer(bp + 8))-int32(4)))
				_ptrmapPut(tls, (*TBtree)(unsafe.Pointer(p)).FpBt, ovfl, uint8(PTRMAP_OVERFLOW1), (*TMemPage)(unsafe.Pointer(pPage)).Fpgno, bp)
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					goto end_insert
				}
			}
		}
	} else {
		*(*int32)(unsafe.Pointer(bp)) = _fillInCell(tls, pPage, newCell, pX, bp+8)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			goto end_insert
		}
	}
	idx = int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
		if idx >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			return _sqlite3CorruptError(tls, int32(80041))
		}
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			goto end_insert
		}
		oldCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))))
		if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
			libc.Xmemcpy(tls, newCell, oldCell, uint32(4))
		}
		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, oldCell, bp+112)
		if uint32((*(*TCellInfo)(unsafe.Pointer(bp + 112))).FnLocal) != (*(*TCellInfo)(unsafe.Pointer(bp + 112))).FnPayload {
			*(*int32)(unsafe.Pointer(bp)) = _clearCellOverflow(tls, pPage, oldCell, bp+112)
		} else {
			*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
		}
		p1 = pCur + 1
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(BTCF_ValidOvfl))
		if int32((*(*TCellInfo)(unsafe.Pointer(bp + 112))).FnSize) == *(*int32)(unsafe.Pointer(bp + 8)) && uint32((*(*TCellInfo)(unsafe.Pointer(bp + 112))).FnLocal) == (*(*TCellInfo)(unsafe.Pointer(bp + 112))).FnPayload && (!((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FautoVacuum != 0) || *(*int32)(unsafe.Pointer(bp + 8)) < int32((*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(80068))
			}
			if oldCell+uintptr(*(*int32)(unsafe.Pointer(bp + 8))) > (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
				return _sqlite3CorruptError(tls, int32(80071))
			}
			libc.Xmemcpy(tls, oldCell, newCell, uint32(*(*int32)(unsafe.Pointer(bp + 8))))
			return SQLITE_OK
		}
		_dropCell(tls, pPage, idx, int32((*(*TCellInfo)(unsafe.Pointer(bp + 112))).FnSize), bp)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			goto end_insert
		}
	} else {
		if *(*int32)(unsafe.Pointer(bp + 4)) < 0 && int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) > 0 {
			v3 = pCur + 70
			*(*Tu16)(unsafe.Pointer(v3))++
			v2 = *(*Tu16)(unsafe.Pointer(v3))
			idx = int32(v2)
			p4 = pCur + 1
			*(*Tu8)(unsafe.Pointer(p4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p4))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
		} else {
		}
	}
	*(*int32)(unsafe.Pointer(bp)) = _insertCellFast(tls, pPage, idx, newCell, *(*int32)(unsafe.Pointer(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 {
		p5 = pCur + 1
		*(*Tu8)(unsafe.Pointer(p5)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p5))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
		*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp)) == SQLITE_OK {
			_btreeReleaseAllCursorPages(tls, pCur)
			if (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo != 0 {
				(*TBtCursor)(unsafe.Pointer(pCur)).FpKey = _sqlite3Malloc(tls, uint64((*TBtreePayload)(unsafe.Pointer(pX)).FnKey))
				if (*TBtCursor)(unsafe.Pointer(pCur)).FpKey == uintptr(0) {
					*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
				} else {
					libc.Xmemcpy(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpKey, (*TBtreePayload)(unsafe.Pointer(pX)).FpKey, uint32((*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)(unsafe.Pointer(bp))
	return r
}

// C documentation
//
//	/*
//	** This function is used as part of copying the current row from cursor
//	** pSrc into cursor pDest. If the cursors are open on intkey tables, then
//	** parameter iKey is used as the rowid value when the record is copied
//	** into pDest. Otherwise, the record is copied verbatim.
//	**
//	** This function does not actually write the new value to cursor pDest.
//	** Instead, it creates and populates any required overflow pages and
//	** writes the data for the new cell into the BtShared.pTmpSpace buffer
//	** for the destination database. The size of the cell, in bytes, is left
//	** in BtShared.nPreformatSize. The caller completes the insertion by
//	** calling sqlite3BtreeInsert() with the BTREE_PREFORMAT flag specified.
//	**
//	** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
//	*/
func _sqlite3BtreeTransferRow(tls *libc.TLS, pDest uintptr, pSrc uintptr, iKey Ti64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aIn, aOut, pBt, pPageOut, pPgnoOut, pSrcPager, v1 uintptr
	var nCopy int32
	var nIn, nOut, nRem Tu32
	var ovflIn TPgno
	var v2, v3 uint32
	var _ /* pNew at bp+12 */ uintptr
	var _ /* pPageIn at bp+4 */ uintptr
	var _ /* pgnoNew at bp+8 */ TPgno
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aIn, aOut, nCopy, nIn, nOut, nRem, ovflIn, pBt, pPageOut, pPgnoOut, pSrcPager, v1, v2, v3
	pBt = (*TBtCursor)(unsafe.Pointer(pDest)).FpBt
	aOut = (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace /* Bytes of data still to copy */
	_getCellInfo(tls, pSrc)
	if (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload < uint32(0x80) {
		v1 = aOut
		aOut++
		*(*Tu8)(unsafe.Pointer(v1)) = uint8((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)
	} else {
		aOut += uintptr(_sqlite3PutVarint(tls, aOut, uint64((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)))
	}
	if (*TBtCursor)(unsafe.Pointer(pDest)).FpKeyInfo == uintptr(0) {
		aOut += uintptr(_sqlite3PutVarint(tls, aOut, uint64(uint64(iKey))))
	}
	nIn = uint32((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnLocal)
	aIn = (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FpPayload
	if aIn+uintptr(nIn) > (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpPage)).FaDataEnd {
		return _sqlite3CorruptError(tls, int32(80173))
	}
	nRem = (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload
	if nIn == nRem && nIn < uint32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pDest)).FpPage)).FmaxLocal) {
		libc.Xmemcpy(tls, aOut, aIn, nIn)
		(*TBtShared)(unsafe.Pointer(pBt)).FnPreformatSize = int32(nIn + uint32(int32(int32(aOut))-int32((*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace)))
		return SQLITE_OK
	} else {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
		pSrcPager = (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpBt)).FpPager
		pPgnoOut = uintptr(0)
		ovflIn = uint32(0)
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		pPageOut = uintptr(0) /* Size of output buffer aOut[] */
		nOut = uint32(_btreePayloadToLocal(tls, (*TBtCursor)(unsafe.Pointer(pDest)).FpPage, int64((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)))
		(*TBtShared)(unsafe.Pointer(pBt)).FnPreformatSize = int32(nOut + uint32(int32(int32(aOut))-int32((*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace)))
		if nOut < (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload {
			pPgnoOut = aOut + uintptr(nOut)
			*(*int32)(unsafe.Pointer(pBt + 88)) += int32(4)
		}
		if nRem > nIn {
			if aIn+uintptr(nIn)+uintptr(4) > (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpPage)).FaDataEnd {
				return _sqlite3CorruptError(tls, int32(80198))
			}
			ovflIn = _sqlite3Get4byte(tls, (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FpPayload+uintptr(nIn))
		}
		for cond := true; cond; cond = nRem > uint32(0) && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			nRem -= nOut
			for cond := true; cond; cond = *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && nOut > uint32(0) {
				if nIn > uint32(0) {
					if nOut < nIn {
						v2 = nOut
					} else {
						v2 = nIn
					}
					nCopy = int32(v2)
					libc.Xmemcpy(tls, aOut, aIn, uint32(uint32(nCopy)))
					nOut -= uint32(uint32(nCopy))
					nIn -= uint32(uint32(nCopy))
					aOut += uintptr(nCopy)
					aIn += uintptr(nCopy)
				}
				if nOut > uint32(0) {
					_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
					*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
					*(*int32)(unsafe.Pointer(bp)) = _sqlite3PagerGet(tls, pSrcPager, ovflIn, bp+4, int32(PAGER_GET_READONLY))
					if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
						aIn = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
						ovflIn = _sqlite3Get4byte(tls, aIn)
						aIn += uintptr(4)
						nIn = (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpBt)).FusableSize - uint32(4)
					}
				}
			}
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && nRem > uint32(0) && pPgnoOut != 0 {
				*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
				*(*int32)(unsafe.Pointer(bp)) = _allocateBtreePage(tls, pBt, bp+12, bp+8, uint32(0), uint8(0))
				_sqlite3Put4byte(tls, pPgnoOut, *(*TPgno)(unsafe.Pointer(bp + 8)))
				if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && pPageOut != 0 {
					_ptrmapPut(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 8)), uint8(PTRMAP_OVERFLOW2), (*TMemPage)(unsafe.Pointer(pPageOut)).Fpgno, bp)
				}
				_releasePage(tls, pPageOut)
				pPageOut = *(*uintptr)(unsafe.Pointer(bp + 12))
				if pPageOut != 0 {
					pPgnoOut = (*TMemPage)(unsafe.Pointer(pPageOut)).FaData
					_sqlite3Put4byte(tls, pPgnoOut, uint32(0))
					aOut = pPgnoOut + 4
					if (*TBtShared)(unsafe.Pointer(pBt)).FusableSize-uint32(4) < nRem {
						v3 = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4)
					} else {
						v3 = nRem
					}
					nOut = v3
				}
			}
		}
		_releasePage(tls, pPageOut)
		_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
		return *(*int32)(unsafe.Pointer(bp))
	}
	return r
}

// 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 int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		if int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
			*(*int32)(unsafe.Pointer(bp)) = _btreeRestoreCursorPosition(tls, pCur)
			if *(*int32)(unsafe.Pointer(bp)) != 0 || int32((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
				return *(*int32)(unsafe.Pointer(bp))
			}
		} else {
			return _sqlite3CorruptError(tls, int32(80294))
		}
	}
	iCellDepth = int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)
	iCellIdx = int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	if int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) <= iCellIdx {
		return _sqlite3CorruptError(tls, int32(80303))
	}
	pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*iCellIdx))))))
	if (*TMemPage)(unsafe.Pointer(pPage)).FnFree < 0 && _btreeComputeFreeSpace(tls, pPage) != 0 {
		return _sqlite3CorruptError(tls, int32(80307))
	}
	if pCell < (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx+uintptr((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
		return _sqlite3CorruptError(tls, int32(80310))
	}
	/* 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(int32(int32(flags))&int32(BTREE_SAVEPOSITION) != 0)
	if bPreserve != 0 {
		if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) || (*TMemPage)(unsafe.Pointer(pPage)).FnFree+int32((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, pCell))+int32(2) > int32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize*libc.Uint32FromInt32(2)/libc.Uint32FromInt32(3)) || int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) == int32(1) {
			/* A b-tree rebalance will be required after deleting this entry.
			 ** Save the cursor key.  */
			*(*int32)(unsafe.Pointer(bp)) = _saveCursorKey(tls, pCur)
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				return *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp)) = _sqlite3BtreePrevious(tls, pCur, 0)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(bp))
		}
	}
	/* Save the positions of any other cursors open on this table before
	 ** making any modifications.  */
	if int32((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_Multiple) != 0 {
		*(*int32)(unsafe.Pointer(bp)) = _saveAllCursors(tls, pBt, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		return *(*int32)(unsafe.Pointer(bp))
	}
	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, pCell, bp+8)
	if uint32((*(*TCellInfo)(unsafe.Pointer(bp + 8))).FnLocal) != (*(*TCellInfo)(unsafe.Pointer(bp + 8))).FnPayload {
		*(*int32)(unsafe.Pointer(bp)) = _clearCellOverflow(tls, pPage, pCell, bp+8)
	} else {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	}
	_dropCell(tls, pPage, iCellIdx, int32((*(*TCellInfo)(unsafe.Pointer(bp + 8))).FnSize), bp)
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		return *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp)) = _btreeComputeFreeSpace(tls, pLeaf)
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				return *(*int32)(unsafe.Pointer(bp))
			}
		}
		if iCellDepth < int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)-int32(1) {
			n = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(iCellDepth+int32(1))*4)))).Fpgno
		} else {
			n = (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fpgno
		}
		pCell = (*TMemPage)(unsafe.Pointer(pLeaf)).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(pLeaf)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pLeaf)).FaCellIdx + uintptr(int32(2)*(int32((*TMemPage)(unsafe.Pointer(pLeaf)).FnCell)-int32(1))))))))
		if pCell < (*TMemPage)(unsafe.Pointer(pLeaf)).FaData+4 {
			return _sqlite3CorruptError(tls, int32(80401))
		}
		nCell = int32((*(*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)(unsafe.Pointer(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pLeaf)).FpDbPage)
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = _insertCell(tls, pPage, iCellIdx, pCell-uintptr(4), nCell+int32(4), pTmp, n)
		}
		_dropCell(tls, pLeaf, int32((*TMemPage)(unsafe.Pointer(pLeaf)).FnCell)-int32(1), nCell, bp)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(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) <= int32((*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)(unsafe.Pointer(bp)) = SQLITE_OK
	} else {
		*(*int32)(unsafe.Pointer(bp)) = _balance(tls, pCur)
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) > iCellDepth {
		_releasePageNotNull(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
		(*TBtCursor)(unsafe.Pointer(pCur)).FiPage--
		for int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) > iCellDepth {
			v2 = pCur + 68
			v1 = *(*Ti8)(unsafe.Pointer(v2))
			*(*Ti8)(unsafe.Pointer(v2))--
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr(v1)*4)))
		}
		(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 120 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*4))
		*(*int32)(unsafe.Pointer(bp)) = _balance(tls, pCur)
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		if int32(int32(bPreserve)) > int32(1) {
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_SKIPNEXT)
			if iCellIdx >= int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
				(*TBtCursor)(unsafe.Pointer(pCur)).FskipNext = -int32(1)
				(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) - int32(1))
			} else {
				(*TBtCursor)(unsafe.Pointer(pCur)).FskipNext = int32(1)
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) = _moveToRoot(tls, pCur)
			if bPreserve != 0 {
				_btreeReleaseAllCursorPages(tls, pCur)
				(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_REQUIRESEEK)
			}
			if *(*int32)(unsafe.Pointer(bp)) == int32(SQLITE_EMPTY) {
				*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
			}
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Create a new BTree table.  Write into *piTable the page
//	** number for the root page of the new table.
//	**
//	** The type of type is determined by the flags parameter.  Only the
//	** following values of flags are currently in use.  Other values for
//	** flags might not work:
//	**
//	**     BTREE_INTKEY|BTREE_LEAFDATA     Used for SQL tables with rowid keys
//	**     BTREE_ZERODATA                  Used for SQL indices
//	*/
func _btreeCreateTable(tls *libc.TLS, p uintptr, piTable uintptr, createTabFlags int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pBt uintptr
	var ptfFlags int32
	var _ /* eType at bp+20 */ Tu8
	var _ /* iPtrPage at bp+24 */ TPgno
	var _ /* pPageMove at bp+16 */ uintptr
	var _ /* pRoot at bp+0 */ uintptr
	var _ /* pgnoMove at bp+12 */ TPgno
	var _ /* pgnoRoot at bp+4 */ TPgno
	var _ /* rc at bp+8 */ int32
	_, _ = pBt, ptfFlags
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt                 /* Page-type flags for the root page of new table */
	if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 { /* The page to move to. */
		/* Creating a new table may probably require moving an existing database
		 ** to make room for the new tables root page. In case this page turns
		 ** out to be an overflow page, delete all overflow page-map caches
		 ** held by open cursors.
		 */
		_invalidateAllOverflowCache(tls, pBt)
		/* Read the value of meta[3] from the database to determine where the
		 ** root page of the new table should go. meta[3] is the largest root-page
		 ** created so far, so the new root-page is (meta[3]+1).
		 */
		_sqlite3BtreeGetMeta(tls, p, int32(BTREE_LARGEST_ROOT_PAGE), bp+4)
		if *(*TPgno)(unsafe.Pointer(bp + 4)) > _btreePagecount(tls, pBt) {
			return _sqlite3CorruptError(tls, int32(80517))
		}
		*(*TPgno)(unsafe.Pointer(bp + 4))++
		/* The new root-page may not be allocated on a pointer-map page, or the
		 ** PENDING_BYTE page.
		 */
		for *(*TPgno)(unsafe.Pointer(bp + 4)) == _ptrmapPageno(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 4))) || *(*TPgno)(unsafe.Pointer(bp + 4)) == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
			*(*TPgno)(unsafe.Pointer(bp + 4))++
		}
		/* Allocate a page. The page that currently resides at pgnoRoot will
		 ** be moved to the allocated page (unless the allocated page happens
		 ** to reside at pgnoRoot).
		 */
		*(*int32)(unsafe.Pointer(bp + 8)) = _allocateBtreePage(tls, pBt, bp+16, bp+12, *(*TPgno)(unsafe.Pointer(bp + 4)), uint8(BTALLOC_EXACT))
		if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
			return *(*int32)(unsafe.Pointer(bp + 8))
		}
		if *(*TPgno)(unsafe.Pointer(bp + 12)) != *(*TPgno)(unsafe.Pointer(bp + 4)) {
			/* pgnoRoot is the page that will be used for the root-page of
			 ** the new table (assuming an error did not occur). But we were
			 ** allocated pgnoMove. If required (i.e. if it was not allocated
			 ** by extending the file), the current page at position pgnoMove
			 ** is already journaled.
			 */
			*(*Tu8)(unsafe.Pointer(bp + 20)) = uint8(0)
			*(*TPgno)(unsafe.Pointer(bp + 24)) = uint32(0)
			/* Save the positions of any open cursors. This is required in
			 ** case they are holding a reference to an xFetch reference
			 ** corresponding to page pgnoRoot.  */
			*(*int32)(unsafe.Pointer(bp + 8)) = _saveAllCursors(tls, pBt, uint32(0), uintptr(0))
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
			if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 8))
			}
			/* Move the page currently at pgnoRoot to pgnoMove. */
			*(*int32)(unsafe.Pointer(bp + 8)) = _btreeGetPage(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 4)), bp, 0)
			if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 8))
			}
			*(*int32)(unsafe.Pointer(bp + 8)) = _ptrmapGet(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 4)), bp+20, bp+24)
			if int32(*(*Tu8)(unsafe.Pointer(bp + 20))) == int32(PTRMAP_ROOTPAGE) || int32(*(*Tu8)(unsafe.Pointer(bp + 20))) == int32(PTRMAP_FREEPAGE) {
				*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3CorruptError(tls, int32(80565))
			}
			if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
				_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
				return *(*int32)(unsafe.Pointer(bp + 8))
			}
			*(*int32)(unsafe.Pointer(bp + 8)) = _relocatePage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp)), *(*Tu8)(unsafe.Pointer(bp + 20)), *(*TPgno)(unsafe.Pointer(bp + 24)), *(*TPgno)(unsafe.Pointer(bp + 12)), 0)
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			/* Obtain the page at pgnoRoot */
			if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 8))
			}
			*(*int32)(unsafe.Pointer(bp + 8)) = _btreeGetPage(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 4)), bp, 0)
			if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 8))
			}
			*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
			if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
				_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
				return *(*int32)(unsafe.Pointer(bp + 8))
			}
		} else {
			*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(bp + 16))
		}
		/* Update the pointer-map and meta-data with the new root-page number. */
		_ptrmapPut(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 4)), uint8(PTRMAP_ROOTPAGE), uint32(0), bp+8)
		if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return *(*int32)(unsafe.Pointer(bp + 8))
		}
		/* When the new root page was allocated, page 1 was made writable in
		 ** order either to increase the database filesize, or to decrement the
		 ** freelist count.  Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
		 */
		*(*int32)(unsafe.Pointer(bp + 8)) = _sqlite3BtreeUpdateMeta(tls, p, int32(4), *(*TPgno)(unsafe.Pointer(bp + 4)))
		if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return *(*int32)(unsafe.Pointer(bp + 8))
		}
	} else {
		*(*int32)(unsafe.Pointer(bp + 8)) = _allocateBtreePage(tls, pBt, bp, bp+4, uint32(1), uint8(0))
		if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
			return *(*int32)(unsafe.Pointer(bp + 8))
		}
	}
	if createTabFlags&int32(BTREE_INTKEY) != 0 {
		ptfFlags = libc.Int32FromInt32(PTF_INTKEY) | libc.Int32FromInt32(PTF_LEAFDATA) | libc.Int32FromInt32(PTF_LEAF)
	} else {
		ptfFlags = libc.Int32FromInt32(PTF_ZERODATA) | libc.Int32FromInt32(PTF_LEAF)
	}
	_zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp)), ptfFlags)
	_sqlite3PagerUnref(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
	*(*TPgno)(unsafe.Pointer(piTable)) = *(*TPgno)(unsafe.Pointer(bp + 4))
	return SQLITE_OK
}

func _sqlite3BtreeCreateTable(tls *libc.TLS, p uintptr, piTable uintptr, flags int32) (r int32) {
	var rc int32
	_ = rc
	_sqlite3BtreeEnter(tls, p)
	rc = _btreeCreateTable(tls, p, piTable, flags)
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// 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(32)
	defer tls.Free(32)
	var hdr, i, v2 int32
	var pCell uintptr
	var _ /* info at bp+8 */ TCellInfo
	var _ /* pPage at bp+0 */ uintptr
	var _ /* rc at bp+4 */ int32
	_, _, _, _ = hdr, i, pCell, v2
	if pgno > _btreePagecount(tls, pBt) {
		return _sqlite3CorruptError(tls, int32(80655))
	}
	*(*int32)(unsafe.Pointer(bp + 4)) = _getAndInitPage(tls, pBt, pgno, bp, 0)
	if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
		return *(*int32)(unsafe.Pointer(bp + 4))
	}
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FopenFlags)&int32(BTREE_SINGLE) == 0 && _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage) != int32(1)+libc.BoolInt32(pgno == uint32(1)) {
		*(*int32)(unsafe.Pointer(bp + 4)) = _sqlite3CorruptError(tls, int32(80662))
		goto cleardatabasepage_out
	}
	hdr = int32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FhdrOffset)
	i = 0
	for {
		if !(i < int32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnCell)) {
			break
		}
		pCell = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData + uintptr(int32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaCellIdx + uintptr(int32(2)*i))))))
		if !((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fleaf != 0) {
			*(*int32)(unsafe.Pointer(bp + 4)) = _clearDatabasePage(tls, pBt, _sqlite3Get4byte(tls, pCell), int32(1), pnChange)
			if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
				goto cleardatabasepage_out
			}
		}
		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxParseCell})))(tls, *(*uintptr)(unsafe.Pointer(bp)), pCell, bp+8)
		if uint32((*(*TCellInfo)(unsafe.Pointer(bp + 8))).FnLocal) != (*(*TCellInfo)(unsafe.Pointer(bp + 8))).FnPayload {
			*(*int32)(unsafe.Pointer(bp + 4)) = _clearCellOverflow(tls, *(*uintptr)(unsafe.Pointer(bp)), pCell, bp+8)
		} else {
			*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
		}
		if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
			goto cleardatabasepage_out
		}
		goto _1
	_1:
		;
		i++
	}
	if !((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fleaf != 0) {
		*(*int32)(unsafe.Pointer(bp + 4)) = _clearDatabasePage(tls, pBt, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+uintptr(hdr+int32(8))), int32(1), pnChange)
		if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
			goto cleardatabasepage_out
		}
		if (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FintKey != 0 {
			pnChange = uintptr(0)
		}
	}
	if pnChange != 0 {
		*(*Ti64)(unsafe.Pointer(pnChange)) += int64((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnCell)
	}
	if freePageFlag != 0 {
		_freePage(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+4)
	} else {
		v2 = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
		*(*int32)(unsafe.Pointer(bp + 4)) = v2
		if v2 == 0 {
			_zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(*(*Tu8)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData + uintptr(hdr))))|int32(PTF_LEAF))
		}
	}
	goto cleardatabasepage_out
cleardatabasepage_out:
	;
	_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return *(*int32)(unsafe.Pointer(bp + 4))
}

// C documentation
//
//	/*
//	** Delete all information from a single table in the database.  iTable is
//	** the page number of the root of the table.  After this routine returns,
//	** the root page is empty, but still exists.
//	**
//	** This routine will fail with SQLITE_LOCKED if there are any open
//	** read cursors on the table.  Open write cursors are moved to the
//	** root of the table.
//	**
//	** If pnChange is not NULL, then the integer value pointed to by pnChange
//	** is incremented by the number of entries in the table.
//	*/
func _sqlite3BtreeClearTable(tls *libc.TLS, p uintptr, iTable int32, pnChange uintptr) (r int32) {
	var pBt uintptr
	var rc int32
	_, _ = pBt, rc
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	rc = _saveAllCursors(tls, pBt, uint32(uint32(iTable)), uintptr(0))
	if SQLITE_OK == rc {
		/* Invalidate all incrblob cursors open on table iTable (assuming iTable
		 ** is the root of a table b-tree - if it is not, the following call is
		 ** a no-op).  */
		if (*TBtree)(unsafe.Pointer(p)).FhasIncrblobCur != 0 {
			_invalidateIncrblobCursors(tls, p, uint32(uint32(iTable)), 0, int32(1))
		}
		rc = _clearDatabasePage(tls, pBt, uint32(uint32(iTable)), 0, pnChange)
	}
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Delete all information from the single table that pCur is open on.
//	**
//	** This routine only work for pCur on an ephemeral table.
//	*/
func _sqlite3BtreeClearTableOfCursor(tls *libc.TLS, pCur uintptr) (r int32) {
	return _sqlite3BtreeClearTable(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBtree, int32((*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot), uintptr(0))
}

// C documentation
//
//	/*
//	** Erase all information in a table and add the root of the table to
//	** the freelist.  Except, the root of the principle table (the one on
//	** page 1) is never added to the freelist.
//	**
//	** This routine will fail with SQLITE_LOCKED if there are any open
//	** cursors on the table.
//	**
//	** If AUTOVACUUM is enabled and the page at iTable is not the last
//	** root page in the database file, then the last root page
//	** in the database file is moved into the slot formerly occupied by
//	** iTable and that last slot formerly occupied by the last root page
//	** is added to the freelist instead of iTable.  In this say, all
//	** root pages are kept at the beginning of the database file, which
//	** is necessary for AUTOVACUUM to work right.  *piMoved is set to the
//	** page number that used to be the last root page in the file before
//	** the move.  If no page gets moved, *piMoved is set to 0.
//	** The last root page is recorded in meta[3] and the value of
//	** meta[3] is updated by this procedure.
//	*/
func _btreeDropTable(tls *libc.TLS, p uintptr, iTable TPgno, piMoved uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pBt uintptr
	var _ /* maxRootPgno at bp+8 */ TPgno
	var _ /* pMove at bp+12 */ uintptr
	var _ /* pPage at bp+4 */ uintptr
	var _ /* rc at bp+0 */ int32
	_ = pBt
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	if iTable > _btreePagecount(tls, pBt) {
		return _sqlite3CorruptError(tls, int32(80766))
	}
	*(*int32)(unsafe.Pointer(bp)) = _sqlite3BtreeClearTable(tls, p, int32(int32(iTable)), uintptr(0))
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		return *(*int32)(unsafe.Pointer(bp))
	}
	*(*int32)(unsafe.Pointer(bp)) = _btreeGetPage(tls, pBt, iTable, bp+4, 0)
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
		return *(*int32)(unsafe.Pointer(bp))
	}
	*(*int32)(unsafe.Pointer(piMoved)) = 0
	if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
		_sqlite3BtreeGetMeta(tls, p, int32(BTREE_LARGEST_ROOT_PAGE), bp+8)
		if iTable == *(*TPgno)(unsafe.Pointer(bp + 8)) {
			/* If the table being dropped is the table with the largest root-page
			 ** number in the database, put the root page on the free list.
			 */
			_freePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), bp)
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
			if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp))
			}
		} else {
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
			*(*int32)(unsafe.Pointer(bp)) = _btreeGetPage(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 8)), bp+12, 0)
			if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp))
			}
			*(*int32)(unsafe.Pointer(bp)) = _relocatePage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp + 12)), uint8(PTRMAP_ROOTPAGE), uint32(0), iTable, 0)
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
			if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp))
			}
			*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
			*(*int32)(unsafe.Pointer(bp)) = _btreeGetPage(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 8)), bp+12, 0)
			_freePage(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), bp)
			_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
			if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp))
			}
			*(*int32)(unsafe.Pointer(piMoved)) = int32(*(*TPgno)(unsafe.Pointer(bp + 8)))
		}
		/* Set the new 'max-root-page' value in the database header. This
		 ** is the old value less one, less one more if that happens to
		 ** be a root-page number, less one again if that is the
		 ** PENDING_BYTE_PAGE.
		 */
		*(*TPgno)(unsafe.Pointer(bp + 8))--
		for *(*TPgno)(unsafe.Pointer(bp + 8)) == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) || _ptrmapPageno(tls, pBt, *(*TPgno)(unsafe.Pointer(bp + 8))) == *(*TPgno)(unsafe.Pointer(bp + 8)) {
			*(*TPgno)(unsafe.Pointer(bp + 8))--
		}
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3BtreeUpdateMeta(tls, p, int32(4), *(*TPgno)(unsafe.Pointer(bp + 8)))
	} else {
		_freePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), bp)
		_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func _sqlite3BtreeDropTable(tls *libc.TLS, p uintptr, iTable int32, piMoved uintptr) (r int32) {
	var rc int32
	_ = rc
	_sqlite3BtreeEnter(tls, p)
	rc = _btreeDropTable(tls, p, uint32(uint32(iTable)), piMoved)
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** This function may only be called if the b-tree connection already
//	** has a read or write transaction open on the database.
//	**
//	** Read the meta-information out of a database file.  Meta[0]
//	** is the number of free pages currently in the database.  Meta[1]
//	** through meta[15] are available for use by higher layers.  Meta[0]
//	** is read-only, the others are read/write.
//	**
//	** The schema layer numbers meta values differently.  At the schema
//	** layer (and the SetCookie and ReadCookie opcodes) the number of
//	** free pages is not visible.  So Cookie[0] is the same as Meta[1].
//	**
//	** This routine treats Meta[BTREE_DATA_VERSION] as a special case.  Instead
//	** of reading the value out of the header, it instead loads the "DataVersion"
//	** from the pager.  The BTREE_DATA_VERSION value is not actually stored in the
//	** database file.  It is a number computed by the pager.  But its access
//	** pattern is the same as header meta values, and so it is convenient to
//	** read it from this routine.
//	*/
func _sqlite3BtreeGetMeta(tls *libc.TLS, p uintptr, idx int32, pMeta uintptr) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	if idx == int32(BTREE_DATA_VERSION) {
		*(*Tu32)(unsafe.Pointer(pMeta)) = _sqlite3PagerDataVersion(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager) + (*TBtree)(unsafe.Pointer(p)).FiBDataVersion
	} else {
		*(*Tu32)(unsafe.Pointer(pMeta)) = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+uintptr(int32(36)+idx*int32(4)))
	}
	/* If auto-vacuum is disabled in this build and this is an auto-vacuum
	 ** database, mark the database as read-only.  */
	_sqlite3BtreeLeave(tls, p)
}

// C documentation
//
//	/*
//	** Write meta-information back into the database.  Meta[0] is
//	** read-only and may not be written.
//	*/
func _sqlite3BtreeUpdateMeta(tls *libc.TLS, p uintptr, idx int32, iMeta Tu32) (r int32) {
	var pBt, pP1 uintptr
	var rc int32
	_, _, _ = pBt, pP1, rc
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	pP1 = (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData
	rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
	if rc == SQLITE_OK {
		_sqlite3Put4byte(tls, pP1+uintptr(int32(36)+idx*int32(4)), iMeta)
		if idx == int32(BTREE_INCR_VACUUM) {
			(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = uint8(uint8(iMeta))
		}
	}
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// 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)(unsafe.Pointer(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+312, 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 += int64((*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 = int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix) >= int32((*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)(unsafe.Pointer(pnEntry)) = nEntry
					return _moveToRoot(tls, pCur)
				}
				_moveToParent(tls, pCur)
			}
			(*TBtCursor)(unsafe.Pointer(pCur)).Fix++
			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 = int32((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
		if iIdx == int32((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8))))
		} else {
			rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*iIdx))))))))
		}
	}
	/* An error has occurred. Return an error code. */
	return rc
}

// C documentation
//
//	/*
//	** Return the pager associated with a BTree.  This routine is used for
//	** testing and debugging only.
//	*/
func _sqlite3BtreePager(tls *libc.TLS, p uintptr) (r uintptr) {
	return (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpPager
}

// C documentation
//
//	/*
//	** Record an OOM error during integrity_check
//	*/
func _checkOom(tls *libc.TLS, pCheck uintptr) {
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = 0 /* Causes integrity_check processing to stop */
	if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr == 0 {
		(*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
	}
}

// C documentation
//
//	/*
//	** Invoke the progress handler, if appropriate.  Also check for an
//	** interrupt.
//	*/
func _checkProgress(tls *libc.TLS, pCheck uintptr) {
	var db uintptr
	_ = db
	db = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fdb
	if libc.AtomicLoadNInt32(db+312, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
		(*TIntegrityCk)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_INTERRUPT)
		(*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
		(*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = 0
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != 0 {
		(*TIntegrityCk)(unsafe.Pointer(pCheck)).FnStep++
		if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnStep%(*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps == uint32(0) && (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxProgress})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0 {
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_INTERRUPT)
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = 0
		}
	}
}

// C documentation
//
//	/*
//	** Append a message to the error message string.
//	*/
func _checkAppendMsg(tls *libc.TLS, pCheck uintptr, zFormat uintptr, va uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap Tva_list
	_ = ap
	_checkProgress(tls, pCheck)
	if !((*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
		return
	}
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr--
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
	ap = va
	if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FnChar != 0 {
		Xsqlite3_str_append(tls, pCheck+48, __ccgo_ts+5576, int32(1))
	}
	if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx != 0 {
		Xsqlite3_str_appendf(tls, pCheck+48, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx, libc.VaList(bp+8, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv0, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2))
	}
	Xsqlite3_str_vappendf(tls, pCheck+48, zFormat, ap)
	_ = ap
	if int32((*TIntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FaccError) == int32(SQLITE_NOMEM) {
		_checkOom(tls, pCheck)
	}
}

// C documentation
//
//	/*
//	** Return non-zero if the bit in the IntegrityCk.aPgRef[] array that
//	** corresponds to page iPg is already set.
//	*/
func _getPageReferenced(tls *libc.TLS, pCheck uintptr, iPg TPgno) (r int32) {
	return int32(*(*Tu8)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FaPgRef + uintptr(iPg/uint32(8))))) & (int32(1) << (iPg & uint32(0x07)))
}

// C documentation
//
//	/*
//	** Set the bit in the IntegrityCk.aPgRef[] array that corresponds to page iPg.
//	*/
func _setPageReferenced(tls *libc.TLS, pCheck uintptr, iPg TPgno) {
	var p1 uintptr
	_ = p1
	p1 = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FaPgRef + uintptr(iPg/uint32(8))
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(1)<<(iPg&libc.Uint32FromInt32(0x07)))
}

// C documentation
//
//	/*
//	** Add 1 to the reference count for page iPage.  If this is the second
//	** reference to the page, add an error message to pCheck->zErrMsg.
//	** Return 1 if there are 2 or more references to the page and 0 if
//	** if this is the first reference to the page.
//	**
//	** Also check that the page number is in bounds.
//	*/
func _checkRef(tls *libc.TLS, pCheck uintptr, iPage TPgno) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if iPage > (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnCkPage || iPage == uint32(0) {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5578, libc.VaList(bp+8, iPage))
		return int32(1)
	}
	if _getPageReferenced(tls, pCheck, iPage) != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5601, libc.VaList(bp+8, iPage))
		return int32(1)
	}
	_setPageReferenced(tls, pCheck, iPage)
	return 0
}

// C documentation
//
//	/*
//	** Check that the entry in the pointer-map for page iChild maps to
//	** page iParent, pointer type ptrType. If not, append an error message
//	** to pCheck.
//	*/
func _checkPtrmap(tls *libc.TLS, pCheck uintptr, iChild TPgno, eType Tu8, iParent TPgno) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var _ /* ePtrmapType at bp+0 */ Tu8
	var _ /* iPtrmapParent at bp+4 */ TPgno
	_ = rc
	rc = _ptrmapGet(tls, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt, iChild, bp, bp+4)
	if rc != SQLITE_OK {
		if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			_checkOom(tls, pCheck)
		}
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5626, libc.VaList(bp+16, iChild))
		return
	}
	if int32(*(*Tu8)(unsafe.Pointer(bp))) != int32(int32(eType)) || *(*TPgno)(unsafe.Pointer(bp + 4)) != iParent {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5655, libc.VaList(bp+16, iChild, int32(int32(eType)), iParent, int32(*(*Tu8)(unsafe.Pointer(bp))), *(*TPgno)(unsafe.Pointer(bp + 4))))
	}
}

// C documentation
//
//	/*
//	** Check the integrity of the freelist or of an overflow page list.
//	** Verify that the number of pages on the list is N.
//	*/
func _checkList(tls *libc.TLS, pCheck uintptr, isFreeList int32, iPage TPgno, N Tu32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var expected, n Tu32
	var i, nErrAtStart int32
	var iFreePage TPgno
	var pOvflData, v2 uintptr
	var _ /* pOvflPage at bp+0 */ uintptr
	_, _, _, _, _, _, _ = expected, i, iFreePage, n, nErrAtStart, pOvflData, v2
	expected = N
	nErrAtStart = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr
	for iPage != uint32(0) && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0 {
		if _checkRef(tls, pCheck, iPage) != 0 {
			break
		}
		N--
		if _sqlite3PagerGet(tls, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpPager, iPage, bp, 0) != 0 {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+5709, libc.VaList(bp+16, iPage))
			break
		}
		pOvflData = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if isFreeList != 0 {
			n = _sqlite3Get4byte(tls, pOvflData+4)
			if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
				_checkPtrmap(tls, pCheck, iPage, uint8(PTRMAP_FREEPAGE), uint32(0))
			}
			if n > (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FusableSize/uint32(4)-uint32(2) {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+5731, libc.VaList(bp+16, iPage))
				N--
			} else {
				i = 0
				for {
					if !(i < int32(int32(n))) {
						break
					}
					iFreePage = _sqlite3Get4byte(tls, pOvflData+uintptr(int32(8)+i*int32(4)))
					if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
						_checkPtrmap(tls, pCheck, iFreePage, uint8(PTRMAP_FREEPAGE), uint32(0))
					}
					_checkRef(tls, pCheck, iFreePage)
					goto _1
				_1:
					;
					i++
				}
				N -= n
			}
		} else {
			/* If this database supports auto-vacuum and iPage is not the last
			 ** page in this overflow list, check that the pointer-map entry for
			 ** the following page matches iPage.
			 */
			if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 && N > uint32(0) {
				i = int32(_sqlite3Get4byte(tls, pOvflData))
				_checkPtrmap(tls, pCheck, uint32(uint32(i)), uint8(PTRMAP_OVERFLOW2), iPage)
			}
		}
		iPage = _sqlite3Get4byte(tls, pOvflData)
		_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	if N != 0 && nErrAtStart == (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr {
		if isFreeList != 0 {
			v2 = __ccgo_ts + 5770
		} else {
			v2 = __ccgo_ts + 5775
		}
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5796, libc.VaList(bp+16, v2, expected-N, expected))
	}
}

// C documentation
//
//	/*
//	** An implementation of a min-heap.
//	**
//	** aHeap[0] is the number of elements on the heap.  aHeap[1] is the
//	** root element.  The daughter nodes of aHeap[N] are aHeap[N*2]
//	** and aHeap[N*2+1].
//	**
//	** The heap property is this:  Every node is less than or equal to both
//	** of its daughter nodes.  A consequence of the heap property is that the
//	** root node aHeap[1] is always the minimum value currently in the heap.
//	**
//	** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
//	** the heap, preserving the heap property.  The btreeHeapPull() routine
//	** removes the root element from the heap (the minimum value in the heap)
//	** and then moves other nodes around as necessary to preserve the heap
//	** property.
//	**
//	** This heap is used for cell overlap and coverage testing.  Each u32
//	** entry represents the span of a cell or freeblock on a btree page.
//	** The upper 16 bits are the index of the first byte of a range and the
//	** lower 16 bits are the index of the last byte of that range.
//	*/
func _btreeHeapInsert(tls *libc.TLS, aHeap uintptr, x Tu32) {
	var i, j, v1, v3 Tu32
	var v2 uintptr
	_, _, _, _, _ = i, j, v1, v2, v3
	v2 = aHeap
	*(*Tu32)(unsafe.Pointer(v2))++
	v1 = *(*Tu32)(unsafe.Pointer(v2))
	i = v1
	*(*Tu32)(unsafe.Pointer(aHeap + uintptr(i)*4)) = x
	for {
		v3 = i / libc.Uint32FromInt32(2)
		j = v3
		if !(v3 > uint32(0) && *(*Tu32)(unsafe.Pointer(aHeap + uintptr(j)*4)) > *(*Tu32)(unsafe.Pointer(aHeap + uintptr(i)*4))) {
			break
		}
		x = *(*Tu32)(unsafe.Pointer(aHeap + uintptr(j)*4))
		*(*Tu32)(unsafe.Pointer(aHeap + uintptr(j)*4)) = *(*Tu32)(unsafe.Pointer(aHeap + uintptr(i)*4))
		*(*Tu32)(unsafe.Pointer(aHeap + uintptr(i)*4)) = x
		i = j
	}
}

func _btreeHeapPull(tls *libc.TLS, aHeap uintptr, pOut uintptr) (r int32) {
	var i, j, x, v1, v2 Tu32
	_, _, _, _, _ = i, j, x, v1, v2
	v1 = *(*Tu32)(unsafe.Pointer(aHeap))
	x = v1
	if v1 == uint32(0) {
		return 0
	}
	*(*Tu32)(unsafe.Pointer(pOut)) = *(*Tu32)(unsafe.Pointer(aHeap + 1*4))
	*(*Tu32)(unsafe.Pointer(aHeap + 1*4)) = *(*Tu32)(unsafe.Pointer(aHeap + uintptr(x)*4))
	*(*Tu32)(unsafe.Pointer(aHeap + uintptr(x)*4)) = uint32(0xffffffff)
	*(*Tu32)(unsafe.Pointer(aHeap))--
	i = uint32(1)
	for {
		v2 = i * libc.Uint32FromInt32(2)
		j = v2
		if !(v2 <= *(*Tu32)(unsafe.Pointer(aHeap))) {
			break
		}
		if *(*Tu32)(unsafe.Pointer(aHeap + uintptr(j)*4)) > *(*Tu32)(unsafe.Pointer(aHeap + uintptr(j+uint32(1))*4)) {
			j++
		}
		if *(*Tu32)(unsafe.Pointer(aHeap + uintptr(i)*4)) < *(*Tu32)(unsafe.Pointer(aHeap + uintptr(j)*4)) {
			break
		}
		x = *(*Tu32)(unsafe.Pointer(aHeap + uintptr(i)*4))
		*(*Tu32)(unsafe.Pointer(aHeap + uintptr(i)*4)) = *(*Tu32)(unsafe.Pointer(aHeap + uintptr(j)*4))
		*(*Tu32)(unsafe.Pointer(aHeap + uintptr(j)*4)) = x
		i = j
	}
	return int32(1)
}

// 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, v2, v3, v5 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+16 */ TCellInfo
	var _ /* pPage at bp+8 */ uintptr
	var _ /* x at bp+12 */ 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, v2, v3, v5
	*(*uintptr)(unsafe.Pointer(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 = int32((*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 + 5822
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = iPage
	v1 = _btreeGetPage(tls, pBt, iPage, bp+8, 0)
	rc = v1
	if v1 != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5840, libc.VaList(bp+48, 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)(unsafe.Pointer(bp + 8)))).FisInit
	(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FisInit = uint8(0)
	v2 = _btreeInitPage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	rc = v2
	if v2 != 0 {
		/* The only possible error from InitPage */
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5878, libc.VaList(bp+48, rc))
		goto end_of_check
	}
	v3 = _btreeComputeFreeSpace(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	rc = v3
	if v3 != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+5916, libc.VaList(bp+48, rc))
		goto end_of_check
	}
	data = (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData
	hdr = int32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FhdrOffset)
	/* Set up for cell analysis */
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 5938
	contentOffset = uint32((int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(5)))))<<libc.Int32FromInt32(8)|int32(*(*Tu8)(unsafe.Pointer(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 = int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(3)))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(3)) + 1)))
	if (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).Fleaf != 0 || int32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FintKey) == 0 {
		*(*Ti64)(unsafe.Pointer(pCheck + 80)) += int64(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)*int32((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).Fleaf)
	pCellIdx = data + uintptr(cellStart+int32(2)*(nCell-int32(1)))
	if !((*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).Fleaf != 0) {
		/* Analyze the right-child page of internal pages */
		pgno = int32(_sqlite3Get4byte(tls, data+uintptr(hdr+int32(8))))
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 5964
			_checkPtrmap(tls, pCheck, uint32(uint32(pgno)), uint8(PTRMAP_BTREE), iPage)
		}
		depth = _checkTreePage(tls, pCheck, uint32(uint32(pgno)), bp, *(*Ti64)(unsafe.Pointer(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)(unsafe.Pointer(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(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer(pCellIdx))))
		pCellIdx -= uintptr(2)
		if pc < contentOffset || pc > usableSize-uint32(4) {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+5994, libc.VaList(bp+48, 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)(unsafe.Pointer(bp + 8)))).FxParseCell})))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), pCell, bp+16)
		if pc+uint32((*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnSize) > usableSize {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+6024, 0)
			doCoverageCheck = 0
			goto _4
		}
		/* Check for integer primary key out of range */
		if (*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FintKey != 0 {
			if keyCanBeEqual != 0 {
				v5 = libc.BoolInt32((*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnKey > *(*Ti64)(unsafe.Pointer(bp)))
			} else {
				v5 = libc.BoolInt32((*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnKey >= *(*Ti64)(unsafe.Pointer(bp)))
			}
			if v5 != 0 {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+6048, libc.VaList(bp+48, (*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnKey))
			}
			*(*Ti64)(unsafe.Pointer(bp)) = (*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnKey
			keyCanBeEqual = 0 /* Only the first key on the page may ==maxKey */
		}
		/* Check the content overflow list */
		if (*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnPayload > uint32((*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnLocal) { /* First page of the overflow chain */
			nPage = ((*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnPayload - uint32((*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnLocal) + usableSize - uint32(5)) / (usableSize - uint32(4))
			pgnoOvfl = _sqlite3Get4byte(tls, pCell+uintptr(int32((*(*TCellInfo)(unsafe.Pointer(bp + 16))).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)(unsafe.Pointer(bp + 8)))).Fleaf != 0) {
			/* Check sanity of left child page for internal pages */
			pgno = int32(_sqlite3Get4byte(tls, pCell))
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				_checkPtrmap(tls, pCheck, uint32(uint32(pgno)), uint8(PTRMAP_BTREE), iPage)
			}
			d2 = _checkTreePage(tls, pCheck, uint32(uint32(pgno)), bp, *(*Ti64)(unsafe.Pointer(bp)))
			keyCanBeEqual = 0
			if d2 != depth {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+6072, 0)
				depth = d2
			}
		} else {
			/* Populate the coverage-checking heap for leaf pages */
			_btreeHeapInsert(tls, heap, pc<<libc.Int32FromInt32(16)|(pc+uint32((*(*TCellInfo)(unsafe.Pointer(bp + 16))).FnSize)-uint32(1)))
		}
		goto _4
	_4:
		;
		i--
	}
	*(*Ti64)(unsafe.Pointer(piMinKey)) = *(*Ti64)(unsafe.Pointer(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)(unsafe.Pointer(bp + 8)))).Fleaf != 0) {
			heap = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fheap
			*(*Tu32)(unsafe.Pointer(heap)) = uint32(0)
			i = nCell - int32(1)
			for {
				if !(i >= 0) {
					break
				}
				pc = uint32(libc.X__builtin_bswap16(tls, *(*Tu16)(unsafe.Pointer(data + uintptr(cellStart+i*int32(2))))))
				size = uint32((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FxCellSize})))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), data+uintptr(pc)))
				_btreeHeapInsert(tls, heap, pc<<libc.Int32FromInt32(16)|(pc+size-uint32(1)))
				goto _6
			_6:
				;
				i--
			}
		}
		/* 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 = int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(1)))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(1)) + 1)))
		for i > 0 {
			/* Enforced by btreeComputeFreeSpace() */
			size1 = int32(*(*Tu8)(unsafe.Pointer(data + uintptr(i+int32(2)))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(data + uintptr(i+int32(2)) + 1)))
			/* due to btreeComputeFreeSpace() */
			_btreeHeapInsert(tls, heap, uint32(uint32(i))<<libc.Int32FromInt32(16)|uint32(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 = int32(*(*Tu8)(unsafe.Pointer(data + uintptr(i))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(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+12) != 0 {
			if prev&uint32(0xffff) >= *(*Tu32)(unsafe.Pointer(bp + 12))>>libc.Int32FromInt32(16) {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+6097, libc.VaList(bp+48, *(*Tu32)(unsafe.Pointer(bp + 12))>>int32(16), iPage))
				break
			} else {
				nFrag = int32(uint32(nFrag) + (*(*Tu32)(unsafe.Pointer(bp + 12))>>libc.Int32FromInt32(16) - prev&libc.Uint32FromInt32(0xffff) - libc.Uint32FromInt32(1)))
				prev = *(*Tu32)(unsafe.Pointer(bp + 12))
			}
		}
		nFrag = int32(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)(unsafe.Pointer(heap)) == uint32(0) && nFrag != int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(7))))) {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+6134, libc.VaList(bp+48, nFrag, int32(*(*Tu8)(unsafe.Pointer(data + uintptr(hdr+int32(7))))), iPage))
		}
	}
	goto end_of_check
end_of_check:
	;
	if !(doCoverageCheck != 0) {
		(*TMemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FisInit = savedIsInit
	}
	_releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = saved_zPfx
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = uint32(uint32(saved_v1))
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = saved_v2
	return depth + int32(1)
}

// C documentation
//
//	/*
//	** This routine does a complete check of the given BTree file.  aRoot[] is
//	** an array of pages numbers were each page number is the root page of
//	** a table.  nRoot is the number of entries in aRoot.
//	**
//	** A read-only or read-write transaction must be opened before calling
//	** this function.
//	**
//	** Write the number of error seen in *pnErr.  Except for some memory
//	** allocation errors,  an error message held in memory obtained from
//	** malloc is returned if *pnErr is non-zero.  If *pnErr==0 then NULL is
//	** returned.  If a memory allocation error occurs, NULL is returned.
//	**
//	** If the first entry in aRoot[] is 0, that indicates that the list of
//	** root pages is incomplete.  This is a "partial integrity-check".  This
//	** happens when performing an integrity check on a single table.  The
//	** zero is skipped, of course.  But in addition, the freelist checks
//	** and the checks to make sure every page is referenced are also skipped,
//	** since obviously it is not possible to know which pages are covered by
//	** the unverified btrees.  Except, if aRoot[1] is 1, then the freelist
//	** checks are still performed.
//	*/
func _sqlite3BtreeIntegrityCheck(tls *libc.TLS, db uintptr, p uintptr, aRoot uintptr, aCnt uintptr, nRoot int32, mxErr int32, pnErr uintptr, pzOut uintptr) (r int32) {
	bp := tls.Alloc(224)
	defer tls.Free(224)
	var bCkFreelist, bPartial int32
	var i, mx, mxInHdr TPgno
	var pBt uintptr
	var savedDbFlags Tu64
	var _ /* notUsed at bp+192 */ Ti64
	var _ /* sCheck at bp+0 */ TIntegrityCk
	var _ /* zErr at bp+88 */ [100]int8
	_, _, _, _, _, _, _ = bCkFreelist, bPartial, i, mx, mxInHdr, pBt, savedDbFlags
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	savedDbFlags = (*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags
	bPartial = 0           /* True if not checking all btrees */
	bCkFreelist = int32(1) /* True to scan the freelist */
	/* aRoot[0]==0 means this is a partial check */
	if *(*TPgno)(unsafe.Pointer(aRoot)) == uint32(0) {
		bPartial = int32(1)
		if *(*TPgno)(unsafe.Pointer(aRoot + 1*4)) != uint32(1) {
			bCkFreelist = 0
		}
	}
	_sqlite3BtreeEnter(tls, p)
	libc.Xmemset(tls, bp, 0, uint32(88))
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).Fdb = db
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).FpBt = pBt
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).FpPager = (*TBtShared)(unsafe.Pointer(pBt)).FpPager
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).FnCkPage = _btreePagecount(tls, (*(*TIntegrityCk)(unsafe.Pointer(bp))).FpBt)
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).FmxErr = mxErr
	_sqlite3StrAccumInit(tls, bp+48, uintptr(0), bp+88, int32(100), int32(SQLITE_MAX_LENGTH))
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).FerrMsg.FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
	if (*(*TIntegrityCk)(unsafe.Pointer(bp))).FnCkPage == uint32(0) {
		goto integrity_ck_cleanup
	}
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).FaPgRef = _sqlite3MallocZero(tls, uint64((*(*TIntegrityCk)(unsafe.Pointer(bp))).FnCkPage/uint32(8)+uint32(1)))
	if !((*(*TIntegrityCk)(unsafe.Pointer(bp))).FaPgRef != 0) {
		_checkOom(tls, bp)
		goto integrity_ck_cleanup
	}
	(*(*TIntegrityCk)(unsafe.Pointer(bp))).Fheap = _sqlite3PageMalloc(tls, int32((*TBtShared)(unsafe.Pointer(pBt)).FpageSize))
	if (*(*TIntegrityCk)(unsafe.Pointer(bp))).Fheap == uintptr(0) {
		_checkOom(tls, bp)
		goto integrity_ck_cleanup
	}
	i = uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize + libc.Uint32FromInt32(1)
	if i <= (*(*TIntegrityCk)(unsafe.Pointer(bp))).FnCkPage {
		_setPageReferenced(tls, bp, i)
	}
	/* Check the integrity of the freelist
	 */
	if bCkFreelist != 0 {
		(*(*TIntegrityCk)(unsafe.Pointer(bp))).FzPfx = __ccgo_ts + 6186
		_checkList(tls, bp, int32(1), _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+32), _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36))
		(*(*TIntegrityCk)(unsafe.Pointer(bp))).FzPfx = uintptr(0)
	}
	/* Check all the tables.
	 */
	if !(bPartial != 0) {
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			mx = uint32(0)
			i = uint32(0)
			for {
				if !(int32(int32(i)) < nRoot) {
					break
				}
				if mx < *(*TPgno)(unsafe.Pointer(aRoot + uintptr(i)*4)) {
					mx = *(*TPgno)(unsafe.Pointer(aRoot + uintptr(i)*4))
				}
				goto _1
			_1:
				;
				i++
			}
			mxInHdr = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+52)
			if mx != mxInHdr {
				_checkAppendMsg(tls, bp, __ccgo_ts+6197, libc.VaList(bp+208, mx, mxInHdr))
			}
		} else {
			if _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+64) != uint32(0) {
				_checkAppendMsg(tls, bp, __ccgo_ts+6242, 0)
			}
		}
	}
	*(*Tu64)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb + 32)) &= ^libc.Uint64FromInt32(SQLITE_CellSizeCk)
	i = uint32(0)
	for {
		if !(int32(int32(i)) < nRoot && (*(*TIntegrityCk)(unsafe.Pointer(bp))).FmxErr != 0) {
			break
		}
		(*(*TIntegrityCk)(unsafe.Pointer(bp))).FnRow = 0
		if *(*TPgno)(unsafe.Pointer(aRoot + uintptr(i)*4)) != 0 {
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && *(*TPgno)(unsafe.Pointer(aRoot + uintptr(i)*4)) > uint32(1) && !(bPartial != 0) {
				_checkPtrmap(tls, bp, *(*TPgno)(unsafe.Pointer(aRoot + uintptr(i)*4)), uint8(PTRMAP_ROOTPAGE), uint32(0))
			}
			(*(*TIntegrityCk)(unsafe.Pointer(bp))).Fv0 = *(*TPgno)(unsafe.Pointer(aRoot + uintptr(i)*4))
			_checkTreePage(tls, bp, *(*TPgno)(unsafe.Pointer(aRoot + uintptr(i)*4)), bp+192, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
		}
		_sqlite3MemSetArrayInt64(tls, aCnt, int32(int32(i)), (*(*TIntegrityCk)(unsafe.Pointer(bp))).FnRow)
		goto _2
	_2:
		;
		i++
	}
	(*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags = savedDbFlags
	/* Make sure every page in the file is referenced
	 */
	if !(bPartial != 0) {
		i = uint32(1)
		for {
			if !(i <= (*(*TIntegrityCk)(unsafe.Pointer(bp))).FnCkPage && (*(*TIntegrityCk)(unsafe.Pointer(bp))).FmxErr != 0) {
				break
			}
			/* If the database supports auto-vacuum, make sure no tables contain
			 ** references to pointer-map pages.
			 */
			if _getPageReferenced(tls, bp, i) == 0 && (_ptrmapPageno(tls, pBt, i) != i || !((*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0)) {
				_checkAppendMsg(tls, bp, __ccgo_ts+6297, libc.VaList(bp+208, i))
			}
			if _getPageReferenced(tls, bp, i) != 0 && (_ptrmapPageno(tls, pBt, i) == i && (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
				_checkAppendMsg(tls, bp, __ccgo_ts+6317, libc.VaList(bp+208, i))
			}
			goto _3
		_3:
			;
			i++
		}
	}
	/* Clean  up and report errors.
	 */
	goto integrity_ck_cleanup
integrity_ck_cleanup:
	;
	_sqlite3PageFree(tls, (*(*TIntegrityCk)(unsafe.Pointer(bp))).Fheap)
	Xsqlite3_free(tls, (*(*TIntegrityCk)(unsafe.Pointer(bp))).FaPgRef)
	*(*int32)(unsafe.Pointer(pnErr)) = (*(*TIntegrityCk)(unsafe.Pointer(bp))).FnErr
	if (*(*TIntegrityCk)(unsafe.Pointer(bp))).FnErr == 0 {
		Xsqlite3_str_reset(tls, bp+48)
		*(*uintptr)(unsafe.Pointer(pzOut)) = uintptr(0)
	} else {
		*(*uintptr)(unsafe.Pointer(pzOut)) = _sqlite3StrAccumFinish(tls, bp+48)
	}
	/* Make sure this analysis did not leave any unref() pages. */
	_sqlite3BtreeLeave(tls, p)
	return (*(*TIntegrityCk)(unsafe.Pointer(bp))).Frc
}

// C documentation
//
//	/*
//	** Return the full pathname of the underlying database file.  Return
//	** an empty string if the database is in-memory or a TEMP database.
//	**
//	** The pager filename is invariant as long as the pager is
//	** open so it is safe to access without the BtShared mutex.
//	*/
func _sqlite3BtreeGetFilename(tls *libc.TLS, p uintptr) (r uintptr) {
	return _sqlite3PagerFilename(tls, (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpPager, int32(1))
}

// C documentation
//
//	/*
//	** Return the pathname of the journal file for this database. The return
//	** value of this routine is the same regardless of whether the journal file
//	** has been created or not.
//	**
//	** The pager journal filename is invariant as long as the pager is
//	** open so it is safe to access without the BtShared mutex.
//	*/
func _sqlite3BtreeGetJournalname(tls *libc.TLS, p uintptr) (r uintptr) {
	return _sqlite3PagerJournalname(tls, (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpPager)
}

// C documentation
//
//	/*
//	** Return one of SQLITE_TXN_NONE, SQLITE_TXN_READ, or SQLITE_TXN_WRITE
//	** to describe the current transaction state of Btree p.
//	*/
func _sqlite3BtreeTxnState(tls *libc.TLS, p uintptr) (r int32) {
	var v1 int32
	_ = v1
	if p != 0 {
		v1 = int32((*TBtree)(unsafe.Pointer(p)).FinTrans)
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Run a checkpoint on the Btree passed as the first argument.
//	**
//	** Return SQLITE_LOCKED if this or any other connection has an open
//	** transaction on the shared-cache the argument Btree is connected to.
//	**
//	** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
//	*/
func _sqlite3BtreeCheckpoint(tls *libc.TLS, p uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) (r int32) {
	var pBt uintptr
	var rc int32
	_, _ = pBt, rc
	rc = SQLITE_OK
	if p != 0 {
		pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
		_sqlite3BtreeEnter(tls, p)
		if int32((*TBtShared)(unsafe.Pointer(pBt)).FinTransaction) != TRANS_NONE {
			rc = int32(SQLITE_LOCKED)
		} else {
			rc = _sqlite3PagerCheckpoint(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, (*TBtree)(unsafe.Pointer(p)).Fdb, eMode, pnLog, pnCkpt)
		}
		_sqlite3BtreeLeave(tls, p)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if there is currently a backup running on Btree p.
//	*/
func _sqlite3BtreeIsInBackup(tls *libc.TLS, p uintptr) (r int32) {
	return libc.BoolInt32((*TBtree)(unsafe.Pointer(p)).FnBackup != 0)
}

// C documentation
//
//	/*
//	** This function returns a pointer to a blob of memory associated with
//	** a single shared-btree. The memory is used by client code for its own
//	** purposes (for example, to store a high-level schema associated with
//	** the shared-btree). The btree layer manages reference counting issues.
//	**
//	** The first time this is called on a shared-btree, nBytes bytes of memory
//	** are allocated, zeroed, and returned to the caller. For each subsequent
//	** call the nBytes parameter is ignored and a pointer to the same blob
//	** of memory returned.
//	**
//	** If the nBytes parameter is 0 and the blob of memory has not yet been
//	** allocated, a null pointer is returned. If the blob has already been
//	** allocated, it is returned as normal.
//	**
//	** Just before the shared-btree is closed, the function passed as the
//	** xFree argument when the memory allocation was made is invoked on the
//	** blob of allocated memory. The xFree function should not call sqlite3_free()
//	** on the memory, the btree layer does that.
//	*/
func _sqlite3BtreeSchema(tls *libc.TLS, p uintptr, nBytes int32, xFree uintptr) (r uintptr) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	_sqlite3BtreeEnter(tls, p)
	if !((*TBtShared)(unsafe.Pointer(pBt)).FpSchema != 0) && nBytes != 0 {
		(*TBtShared)(unsafe.Pointer(pBt)).FpSchema = _sqlite3DbMallocZero(tls, uintptr(0), uint64(uint64(nBytes)))
		(*TBtShared)(unsafe.Pointer(pBt)).FxFreeSchema = xFree
	}
	_sqlite3BtreeLeave(tls, p)
	return (*TBtShared)(unsafe.Pointer(pBt)).FpSchema
}

// C documentation
//
//	/*
//	** Return SQLITE_LOCKED_SHAREDCACHE if another user of the same shared
//	** btree as the argument handle holds an exclusive lock on the
//	** sqlite_schema table. Otherwise SQLITE_OK.
//	*/
func _sqlite3BtreeSchemaLocked(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	_sqlite3BtreeEnter(tls, p)
	rc = _querySharedCacheTableLock(tls, p, uint32(SCHEMA_ROOT), uint8(READ_LOCK))
	_sqlite3BtreeLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Obtain a lock on the table whose root page is iTab.  The
//	** lock is a write lock if isWritelock is true or a read lock
//	** if it is false.
//	*/
func _sqlite3BtreeLockTable(tls *libc.TLS, p uintptr, iTab int32, isWriteLock Tu8) (r int32) {
	var lockType Tu8
	var rc int32
	_, _ = lockType, rc
	rc = SQLITE_OK
	if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
		lockType = uint8(int32(READ_LOCK) + int32(int32(isWriteLock)))
		_sqlite3BtreeEnter(tls, p)
		rc = _querySharedCacheTableLock(tls, p, uint32(uint32(iTab)), lockType)
		if rc == SQLITE_OK {
			rc = _setSharedCacheTableLock(tls, p, uint32(uint32(iTab)), lockType)
		}
		_sqlite3BtreeLeave(tls, p)
	}
	return rc
}

// C documentation
//
//	/*
//	** Argument pCsr must be a cursor opened for writing on an
//	** INTKEY table currently pointing at a valid table entry.
//	** This function modifies the data stored as part of that entry.
//	**
//	** Only the data content may only be modified, it is not possible to
//	** change the length of the data stored. If this function is called with
//	** parameters that attempt to write past the end of the existing data,
//	** no modifications are made and SQLITE_CORRUPT is returned.
//	*/
func _sqlite3BtreePutData(tls *libc.TLS, pCsr uintptr, offset Tu32, amt Tu32, z uintptr) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	if int32((*TBtCursor)(unsafe.Pointer(pCsr)).FeState) >= int32(CURSOR_REQUIRESEEK) {
		v1 = _btreeRestoreCursorPosition(tls, pCsr)
	} else {
		v1 = SQLITE_OK
	}
	rc = v1
	if rc != SQLITE_OK {
		return rc
	}
	if int32((*TBtCursor)(unsafe.Pointer(pCsr)).FeState) != CURSOR_VALID {
		return int32(SQLITE_ABORT)
	}
	/* Save the positions of all other cursors open on this table. This is
	 ** required in case any of them are holding references to an xFetch
	 ** version of the b-tree page modified by the accessPayload call below.
	 **
	 ** Note that pCsr must be open on a INTKEY table and saveCursorPosition()
	 ** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
	 ** saveAllCursors can only return SQLITE_OK.
	 */
	_saveAllCursors(tls, (*TBtCursor)(unsafe.Pointer(pCsr)).FpBt, (*TBtCursor)(unsafe.Pointer(pCsr)).FpgnoRoot, pCsr)
	/* Check some assumptions:
	 **   (a) the cursor is open for writing,
	 **   (b) there is a read/write transaction open,
	 **   (c) the connection holds a write-lock on the table (if required),
	 **   (d) there are no conflicting read-locks, and
	 **   (e) the cursor points at a valid row of an intKey table.
	 */
	if int32((*TBtCursor)(unsafe.Pointer(pCsr)).FcurFlags)&int32(BTCF_WriteFlag) == 0 {
		return int32(SQLITE_READONLY)
	}
	return _accessPayload(tls, pCsr, offset, amt, z, int32(1))
}

// C documentation
//
//	/*
//	** Mark this cursor as an incremental blob cursor.
//	*/
func _sqlite3BtreeIncrblobCursor(tls *libc.TLS, pCur uintptr) {
	var p1 uintptr
	_ = p1
	p1 = pCur + 1
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(BTCF_Incrblob))
	(*TBtree)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBtree)).FhasIncrblobCur = uint8(1)
}

// C documentation
//
//	/*
//	** Set both the "read version" (single byte at byte offset 18) and
//	** "write version" (single byte at byte offset 19) fields in the database
//	** header to iVersion.
//	*/
func _sqlite3BtreeSetVersion(tls *libc.TLS, pBtree uintptr, iVersion int32) (r int32) {
	var aData, pBt, p1, p2, p3 uintptr
	var rc int32
	_, _, _, _, _, _ = aData, pBt, rc, p1, p2, p3
	pBt = (*TBtree)(unsafe.Pointer(pBtree)).FpBt /* Return code */
	/* If setting the version fields to 1, do not automatically open the
	 ** WAL connection, even if the version fields are currently set to 2.
	 */
	p1 = pBt + 24
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(BTS_NO_WAL))
	if iVersion == int32(1) {
		p2 = pBt + 24
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(BTS_NO_WAL))
	}
	rc = _sqlite3BtreeBeginTrans(tls, pBtree, 0, uintptr(0))
	if rc == SQLITE_OK {
		aData = (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData
		if int32(*(*Tu8)(unsafe.Pointer(aData + 18))) != int32(uint8(uint8(iVersion))) || int32(*(*Tu8)(unsafe.Pointer(aData + 19))) != int32(uint8(uint8(iVersion))) {
			rc = _sqlite3BtreeBeginTrans(tls, pBtree, int32(2), uintptr(0))
			if rc == SQLITE_OK {
				rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
				if rc == SQLITE_OK {
					*(*Tu8)(unsafe.Pointer(aData + 18)) = uint8(uint8(iVersion))
					*(*Tu8)(unsafe.Pointer(aData + 19)) = uint8(uint8(iVersion))
				}
			}
		}
	}
	p3 = pBt + 24
	*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(BTS_NO_WAL))
	return rc
}

// C documentation
//
//	/*
//	** Return true if the cursor has a hint specified.  This routine is
//	** only used from within assert() statements
//	*/
func _sqlite3BtreeCursorHasHint(tls *libc.TLS, pCsr uintptr, mask uint32) (r int32) {
	return libc.BoolInt32(uint32((*TBtCursor)(unsafe.Pointer(pCsr)).Fhints)&mask != uint32(0))
}

// C documentation
//
//	/*
//	** Return true if the given Btree is read-only.
//	*/
func _sqlite3BtreeIsReadonly(tls *libc.TLS, p uintptr) (r int32) {
	return libc.BoolInt32(int32((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FbtsFlags)&int32(BTS_READ_ONLY) != 0)
}

// C documentation
//
//	/*
//	** Return the size of the header added to each page by this module.
//	*/
func _sqlite3HeaderSizeBtree(tls *libc.TLS) (r int32) {
	return int32((libc.Uint32FromInt64(84) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
}

// C documentation
//
//	/*
//	** If no transaction is active and the database is not a temp-db, clear
//	** the in-memory pager cache.
//	*/
func _sqlite3BtreeClearCache(tls *libc.TLS, p uintptr) {
	var pBt uintptr
	_ = pBt
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	if int32((*TBtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE {
		_sqlite3PagerClearCache(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
	}
}

// C documentation
//
//	/*
//	** Return true if the Btree passed as the only argument is sharable.
//	*/
func _sqlite3BtreeSharable(tls *libc.TLS, p uintptr) (r int32) {
	return int32((*TBtree)(unsafe.Pointer(p)).Fsharable)
}

// C documentation
//
//	/*
//	** Return the number of connections to the BtShared object accessed by
//	** the Btree handle passed as the only argument. For private caches
//	** this is always 1. For shared caches it may be 1 or greater.
//	*/
func _sqlite3BtreeConnectionCount(tls *libc.TLS, p uintptr) (r int32) {
	return (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FnRef
}

/************** End of btree.c ***********************************************/
/************** Begin file backup.c ******************************************/
/*
** 2009 January 28
**
** 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 implementation of the sqlite3_backup_XXX()
** API functions and the related features.
 */
/* #include "sqliteInt.h" */
/* #include "btreeInt.h" */

/*
** Structure allocated for each backup operation.
 */
type Tsqlite3_backup1 = struct {
	FpDestDb     uintptr
	FpDest       uintptr
	FiDestSchema Tu32
	FbDestLocked int32
	FiNext       TPgno
	FpSrcDb      uintptr
	FpSrc        uintptr
	Frc          int32
	FnRemaining  TPgno
	FnPagecount  TPgno
	FisAttached  int32
	FpNext       uintptr
}

type sqlite3_backup1 = Tsqlite3_backup1

/*
** THREAD SAFETY NOTES:
**
**   Once it has been created using backup_init(), a single sqlite3_backup
**   structure may be accessed via two groups of thread-safe entry points:
**
**     * Via the sqlite3_backup_XXX() API function backup_step() and
**       backup_finish(). Both these functions obtain the source database
**       handle mutex and the mutex associated with the source BtShared
**       structure, in that order.
**
**     * Via the BackupUpdate() and BackupRestart() functions, which are
**       invoked by the pager layer to report various state changes in
**       the page cache associated with the source database. The mutex
**       associated with the source database BtShared structure will always
**       be held when either of these functions are invoked.
**
**   The other sqlite3_backup_XXX() API functions, backup_remaining() and
**   backup_pagecount() are not thread-safe functions. If they are called
**   while some other thread is calling backup_step() or backup_finish(),
**   the values returned may be invalid. There is no way for a call to
**   BackupUpdate() or BackupRestart() to interfere with backup_remaining()
**   or backup_pagecount().
**
**   Depending on the SQLite configuration, the database handles and/or
**   the Btree objects may have their own mutexes that require locking.
**   Non-sharable Btrees (in-memory databases for example), do not have
**   associated mutexes.
 */

// C documentation
//
//	/*
//	** Return a pointer corresponding to database zDb (i.e. "main", "temp")
//	** in connection handle pDb. If such a database cannot be found, return
//	** a NULL pointer and write an error message to pErrorDb.
//	**
//	** If the "temp" database is requested, it may need to be opened by this
//	** function. If an error occurs while doing so, return 0 and write an
//	** error message to pErrorDb.
//	*/
func _findBtree(tls *libc.TLS, pErrorDb uintptr, pDb uintptr, zDb uintptr) (r uintptr) {
	bp := tls.Alloc(304)
	defer tls.Free(304)
	var i, rc int32
	var _ /* sParse at bp+0 */ TParse
	_, _ = i, rc
	i = _sqlite3FindDbName(tls, pDb, zDb)
	if i == int32(1) {
		rc = 0
		_sqlite3ParseObjectInit(tls, bp, pDb)
		if _sqlite3OpenTempDatabase(tls, bp) != 0 {
			_sqlite3ErrorWithMsg(tls, pErrorDb, (*(*TParse)(unsafe.Pointer(bp))).Frc, __ccgo_ts+4709, libc.VaList(bp+296, (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg))
			rc = int32(SQLITE_ERROR)
		}
		_sqlite3DbFree(tls, pErrorDb, (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg)
		_sqlite3ParseObjectReset(tls, bp)
		if rc != 0 {
			return uintptr(0)
		}
	}
	if i < 0 {
		_sqlite3ErrorWithMsg(tls, pErrorDb, int32(SQLITE_ERROR), __ccgo_ts+6349, libc.VaList(bp+296, zDb))
		return uintptr(0)
	}
	return (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(pDb)).FaDb + uintptr(i)*16))).FpBt
}

// C documentation
//
//	/*
//	** Attempt to set the page size of the destination to match the page size
//	** of the source.
//	*/
func _setDestPgsz(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _sqlite3BtreeSetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest, _sqlite3BtreeGetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc), 0, 0)
	return rc
}

// C documentation
//
//	/*
//	** Check that there is no open read-transaction on the b-tree passed as the
//	** second argument. If there is not, return SQLITE_OK. Otherwise, if there
//	** is an open read-transaction, return SQLITE_ERROR and leave an error
//	** message in database handle db.
//	*/
func _checkReadTransaction(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	if _sqlite3BtreeTxnState(tls, p) != SQLITE_TXN_NONE {
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+6369, 0)
		return int32(SQLITE_ERROR)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Create an sqlite3_backup process to copy the contents of zSrcDb from
//	** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
//	** a pointer to the new sqlite3_backup object.
//	**
//	** If an error occurs, NULL is returned and an error code and error message
//	** stored in database handle pDestDb.
//	*/
func Xsqlite3_backup_init(tls *libc.TLS, pDestDb uintptr, zDestDb uintptr, pSrcDb uintptr, zSrcDb uintptr) (r uintptr) {
	var p uintptr
	_ = p /* Value to return */
	/* Lock the source database handle. The destination database
	 ** handle is not locked in this routine, but it is locked in
	 ** sqlite3_backup_step(). The user is required to ensure that no
	 ** other thread accesses the destination handle for the duration
	 ** of the backup operation.  Any attempt to use the destination
	 ** database connection while a backup is in progress may cause
	 ** a malfunction or a deadlock.
	 */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pDestDb)).Fmutex)
	if pSrcDb == pDestDb {
		_sqlite3ErrorWithMsg(tls, pDestDb, int32(SQLITE_ERROR), __ccgo_ts+6400, 0)
		p = uintptr(0)
	} else {
		/* Allocate space for a new sqlite3_backup object...
		 ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
		 ** call to sqlite3_backup_init() and is destroyed by a call to
		 ** sqlite3_backup_finish(). */
		p = _sqlite3MallocZero(tls, uint64(48))
		if !(p != 0) {
			_sqlite3Error(tls, pDestDb, int32(SQLITE_NOMEM))
		}
	}
	/* If the allocation succeeded, populate the new object. */
	if p != 0 {
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc = _findBtree(tls, pDestDb, pSrcDb, zSrcDb)
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest = _findBtree(tls, pDestDb, pDestDb, zDestDb)
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb = pDestDb
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrcDb = pSrcDb
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext = uint32(1)
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FisAttached = 0
		if uintptr(0) == (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc || uintptr(0) == (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest || _checkReadTransaction(tls, pDestDb, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest) != SQLITE_OK {
			/* One (or both) of the named databases did not exist or an OOM
			 ** error was hit. Or there is a transaction open on the destination
			 ** database. The error has already been written into the pDestDb
			 ** handle. All that is left to do here is free the sqlite3_backup
			 ** structure.  */
			Xsqlite3_free(tls, p)
			p = uintptr(0)
		}
	}
	if p != 0 {
		(*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup++
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(pDestDb)).Fmutex)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	return p
}

// C documentation
//
//	/*
//	** Argument rc is an SQLite error code. Return true if this error is
//	** considered fatal if encountered during a backup operation. All errors
//	** are considered fatal except for SQLITE_BUSY and SQLITE_LOCKED.
//	*/
func _isFatalError(tls *libc.TLS, rc int32) (r int32) {
	return libc.BoolInt32(rc != SQLITE_OK && rc != int32(SQLITE_BUSY) && rc != int32(SQLITE_LOCKED))
}

// C documentation
//
//	/*
//	** Parameter zSrcData points to a buffer containing the data for
//	** page iSrcPg from the source database. Copy this data into the
//	** destination database.
//	*/
func _backupOnePage(tls *libc.TLS, p uintptr, iSrcPg TPgno, zSrcData uintptr, bUpdate int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iDest TPgno
	var iEnd, iOff Ti64
	var nCopy, nDestPgsz, nSrcPgsz, rc, v1, v3, v4 int32
	var pDestPager, zDestData, zIn, zOut uintptr
	var v5 bool
	var _ /* pDestPg at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = iDest, iEnd, iOff, nCopy, nDestPgsz, nSrcPgsz, pDestPager, rc, zDestData, zIn, zOut, v1, v3, v4, v5
	pDestPager = _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)
	nSrcPgsz = _sqlite3BtreeGetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	nDestPgsz = _sqlite3BtreeGetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)
	if nSrcPgsz < nDestPgsz {
		v1 = nSrcPgsz
	} else {
		v1 = nDestPgsz
	}
	nCopy = v1
	iEnd = int64(int64(iSrcPg)) * int64(int64(nSrcPgsz))
	rc = SQLITE_OK
	/* This loop runs once for each destination page spanned by the source
	 ** page. For each iteration, variable iOff is set to the byte offset
	 ** of the destination page.
	 */
	iOff = iEnd - int64(int64(nSrcPgsz))
	for {
		if !(rc == SQLITE_OK && iOff < iEnd) {
			break
		}
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		iDest = uint32(iOff/int64(int64(nDestPgsz))) + uint32(1)
		if iDest == uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)).FpBt)).FpageSize+libc.Uint32FromInt32(1) {
			goto _2
		}
		v3 = _sqlite3PagerGet(tls, pDestPager, iDest, bp, 0)
		rc = v3
		if v5 = SQLITE_OK == v3; v5 {
			v4 = _sqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = v4
		}
		if v5 && SQLITE_OK == v4 {
			zIn = zSrcData + uintptr(iOff%int64(int64(nSrcPgsz)))
			zDestData = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
			zOut = zDestData + uintptr(iOff%int64(int64(nDestPgsz)))
			/* Copy the data from the source page into the destination page.
			 ** Then clear the Btree layer MemPage.isInit flag. Both this module
			 ** and the pager code use this trick (clearing the first byte
			 ** of the page 'extra' space to invalidate the Btree layers
			 ** cached parse of the page). MemPage.isInit is marked
			 ** "MUST BE FIRST" for this purpose.
			 */
			libc.Xmemcpy(tls, zOut, zIn, uint32(uint32(nCopy)))
			*(*Tu8)(unsafe.Pointer(_sqlite3PagerGetExtra(tls, *(*uintptr)(unsafe.Pointer(bp))))) = uint8(0)
			if iOff == 0 && bUpdate == 0 {
				_sqlite3Put4byte(tls, zOut+28, _sqlite3BtreeLastPage(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc))
			}
		}
		_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
		goto _2
	_2:
		;
		iOff += int64(int64(nDestPgsz))
	}
	return rc
}

// C documentation
//
//	/*
//	** If pFile is currently larger than iSize bytes, then truncate it to
//	** exactly iSize bytes. If pFile is not larger than iSize bytes, then
//	** this function is a no-op.
//	**
//	** Return SQLITE_OK if everything is successful, or an SQLite error
//	** code if an error occurs.
//	*/
func _backupTruncateFile(tls *libc.TLS, pFile uintptr, iSize Ti64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* iCurrent at bp+0 */ Ti64
	_ = rc
	rc = _sqlite3OsFileSize(tls, pFile, bp)
	if rc == SQLITE_OK && *(*Ti64)(unsafe.Pointer(bp)) > iSize {
		rc = _sqlite3OsTruncate(tls, pFile, iSize)
	}
	return rc
}

// C documentation
//
//	/*
//	** Register this backup object with the associated source pager for
//	** callbacks when pages are changed or the cache invalidated.
//	*/
func _attachBackupObject(tls *libc.TLS, p uintptr) {
	var pp uintptr
	_ = pp
	pp = _sqlite3PagerBackupPtr(tls, _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc))
	(*Tsqlite3_backup)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(pp))
	*(*uintptr)(unsafe.Pointer(pp)) = p
	(*Tsqlite3_backup)(unsafe.Pointer(p)).FisAttached = int32(1)
}

// C documentation
//
//	/*
//	** Copy nPage pages from the source b-tree to the destination.
//	*/
func Xsqlite3_backup_step(tls *libc.TLS, p uintptr, nPage int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bCloseTrans, destMode, ii, nDestTruncate, nSrcPage, pgszDest, pgszSrc, ratio, rc, v1, v7 int32
	var iEnd, iOff, iSize Ti64
	var iPg, iSrcPg, iSrcPg1 TPgno
	var pDestPager, pFile, pSrcPager, zData uintptr
	var v2, v8 bool
	var v5 int64
	var _ /* nDstPage at bp+4 */ int32
	var _ /* pPg at bp+8 */ uintptr
	var _ /* pSrcPg at bp+0 */ uintptr
	var _ /* pSrcPg at bp+12 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bCloseTrans, destMode, iEnd, iOff, iPg, iSize, iSrcPg, iSrcPg1, ii, nDestTruncate, nSrcPage, pDestPager, pFile, pSrcPager, pgszDest, pgszSrc, ratio, rc, zData, v1, v2, v5, v7, v8 /* Destination journal mode */
	pgszSrc = 0                                                                                                                                                                                                                                                 /* Source page size */
	pgszDest = 0                                                                                                                                                                                                                                                /* Destination page size */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrcDb)).Fmutex)
	_sqlite3BtreeEnter(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
	}
	rc = (*Tsqlite3_backup)(unsafe.Pointer(p)).Frc
	if !(_isFatalError(tls, rc) != 0) {
		pSrcPager = _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)   /* Source pager */
		pDestPager = _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest) /* Iterator variable */
		nSrcPage = -int32(1)                                                               /* Size of source db in pages */
		bCloseTrans = 0                                                                    /* True if src db requires unlocking */
		/* If the source pager is currently in a write-transaction, return
		 ** SQLITE_BUSY immediately.
		 */
		if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 && int32((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FpBt)).FinTransaction) == int32(TRANS_WRITE) {
			rc = int32(SQLITE_BUSY)
		} else {
			rc = SQLITE_OK
		}
		/* If there is no open read-transaction on the source database, open
		 ** one now. If a transaction is opened here, then it will be closed
		 ** before this function exits.
		 */
		if rc == SQLITE_OK && SQLITE_TXN_NONE == _sqlite3BtreeTxnState(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc) {
			rc = _sqlite3BtreeBeginTrans(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc, 0, uintptr(0))
			bCloseTrans = int32(1)
		}
		/* If the destination database has not yet been locked (i.e. if this
		 ** is the first call to backup_step() for the current backup operation),
		 ** try to set its page size to the same as the source database. This
		 ** is especially important on ZipVFS systems, as in that case it is
		 ** not possible to create a database file that uses one page size by
		 ** writing to it with another.  */
		if (*Tsqlite3_backup)(unsafe.Pointer(p)).FbDestLocked == 0 && rc == SQLITE_OK && _setDestPgsz(tls, p) == int32(SQLITE_NOMEM) {
			rc = int32(SQLITE_NOMEM)
		}
		/* Lock the destination database, if it is not locked already. */
		if v2 = SQLITE_OK == rc && (*Tsqlite3_backup)(unsafe.Pointer(p)).FbDestLocked == 0; v2 {
			v1 = _sqlite3BtreeBeginTrans(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest, int32(2), p+8)
			rc = v1
		}
		if v2 && SQLITE_OK == v1 {
			(*Tsqlite3_backup)(unsafe.Pointer(p)).FbDestLocked = int32(1)
		}
		/* Do not allow backup if the destination database is in WAL mode
		 ** and the page sizes are different between source and destination */
		pgszSrc = _sqlite3BtreeGetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
		pgszDest = _sqlite3BtreeGetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)
		destMode = _sqlite3PagerGetJournalMode(tls, _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest))
		if SQLITE_OK == rc && (destMode == int32(PAGER_JOURNALMODE_WAL) || _sqlite3PagerIsMemdb(tls, pDestPager) != 0) && pgszSrc != pgszDest {
			rc = int32(SQLITE_READONLY)
		}
		/* Now that there is a read-lock on the source database, query the
		 ** source pager for the number of pages in the database.
		 */
		nSrcPage = int32(_sqlite3BtreeLastPage(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc))
		ii = 0
		for {
			if !((nPage < 0 || ii < nPage) && (*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext <= uint32(uint32(nSrcPage)) && !(rc != 0)) {
				break
			}
			iSrcPg = (*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext                                                                                                                                          /* Source page number */
			if iSrcPg != uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FpBt)).FpageSize+libc.Uint32FromInt32(1) { /* Source page object */
				rc = _sqlite3PagerGet(tls, pSrcPager, iSrcPg, bp, int32(PAGER_GET_READONLY))
				if rc == SQLITE_OK {
					rc = _backupOnePage(tls, p, iSrcPg, _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp))), 0)
					_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
				}
			}
			(*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext++
			goto _3
		_3:
			;
			ii++
		}
		if rc == SQLITE_OK {
			(*Tsqlite3_backup)(unsafe.Pointer(p)).FnPagecount = uint32(uint32(nSrcPage))
			(*Tsqlite3_backup)(unsafe.Pointer(p)).FnRemaining = uint32(nSrcPage+int32(1)) - (*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext
			if (*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext > uint32(uint32(nSrcPage)) {
				rc = int32(SQLITE_DONE)
			} else {
				if !((*Tsqlite3_backup)(unsafe.Pointer(p)).FisAttached != 0) {
					_attachBackupObject(tls, p)
				}
			}
		}
		/* Update the schema version field in the destination database. This
		 ** is to make sure that the schema-version really does change in
		 ** the case where the source and destination databases have the
		 ** same schema version.
		 */
		if rc == int32(SQLITE_DONE) {
			if nSrcPage == 0 {
				rc = _sqlite3BtreeNewDb(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)
				nSrcPage = int32(1)
			}
			if rc == SQLITE_OK || rc == int32(SQLITE_DONE) {
				rc = _sqlite3BtreeUpdateMeta(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest, int32(1), (*Tsqlite3_backup)(unsafe.Pointer(p)).FiDestSchema+uint32(1))
			}
			if rc == SQLITE_OK {
				if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
					_sqlite3ResetAllSchemasOfConnection(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)
				}
				if destMode == int32(PAGER_JOURNALMODE_WAL) {
					rc = _sqlite3BtreeSetVersion(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest, int32(2))
				}
			}
			if rc == SQLITE_OK {
				/* Set nDestTruncate to the final number of pages in the destination
				 ** database. The complication here is that the destination page
				 ** size may be different to the source page size.
				 **
				 ** If the source page size is smaller than the destination page size,
				 ** round up. In this case the call to sqlite3OsTruncate() below will
				 ** fix the size of the file. However it is important to call
				 ** sqlite3PagerTruncateImage() here so that any pages in the
				 ** destination file that lie beyond the nDestTruncate page mark are
				 ** journalled by PagerCommitPhaseOne() before they are destroyed
				 ** by the file truncation.
				 */
				if pgszSrc < pgszDest {
					ratio = pgszDest / pgszSrc
					nDestTruncate = (nSrcPage + ratio - int32(1)) / ratio
					if nDestTruncate == int32(uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)).FpBt)).FpageSize+libc.Uint32FromInt32(1)) {
						nDestTruncate--
					}
				} else {
					nDestTruncate = nSrcPage * (pgszSrc / pgszDest)
				}
				if pgszSrc < pgszDest {
					/* If the source page-size is smaller than the destination page-size,
					 ** two extra things may need to happen:
					 **
					 **   * The destination may need to be truncated, and
					 **
					 **   * Data stored on the pages immediately following the
					 **     pending-byte page in the source database may need to be
					 **     copied into the destination database.
					 */
					iSize = int64(int64(pgszSrc)) * int64(int64(nSrcPage))
					pFile = _sqlite3PagerFile(tls, pDestPager)
					/* This block ensures that all data required to recreate the original
					 ** database has been stored in the journal for pDestPager and the
					 ** journal synced to disk. So at this point we may safely modify
					 ** the database file in any way, knowing that if a power failure
					 ** occurs, the original database will be reconstructed from the
					 ** journal file.  */
					_sqlite3PagerPagecount(tls, pDestPager, bp+4)
					iPg = uint32(uint32(nDestTruncate))
					for {
						if !(rc == SQLITE_OK && iPg <= uint32(*(*int32)(unsafe.Pointer(bp + 4)))) {
							break
						}
						if iPg != uint32(uint32(_sqlite3PendingByte))/(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)).FpBt)).FpageSize+libc.Uint32FromInt32(1) {
							rc = _sqlite3PagerGet(tls, pDestPager, iPg, bp+8, 0)
							if rc == SQLITE_OK {
								rc = _sqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
								_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
							}
						}
						goto _4
					_4:
						;
						iPg++
					}
					if rc == SQLITE_OK {
						rc = _sqlite3PagerCommitPhaseOne(tls, pDestPager, uintptr(0), int32(1))
					}
					/* Write the extra pages and truncate the database file as required */
					if int64(_sqlite3PendingByte+pgszDest) < iSize {
						v5 = int64(_sqlite3PendingByte + pgszDest)
					} else {
						v5 = iSize
					}
					iEnd = v5
					iOff = int64(_sqlite3PendingByte + pgszSrc)
					for {
						if !(rc == SQLITE_OK && iOff < iEnd) {
							break
						}
						*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
						iSrcPg1 = uint32(iOff/int64(int64(pgszSrc)) + libc.Int64FromInt32(1))
						rc = _sqlite3PagerGet(tls, pSrcPager, iSrcPg1, bp+12, 0)
						if rc == SQLITE_OK {
							zData = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
							rc = _sqlite3OsWrite(tls, pFile, zData, pgszSrc, iOff)
						}
						_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
						goto _6
					_6:
						;
						iOff += int64(int64(pgszSrc))
					}
					if rc == SQLITE_OK {
						rc = _backupTruncateFile(tls, pFile, iSize)
					}
					/* Sync the database file to disk. */
					if rc == SQLITE_OK {
						rc = _sqlite3PagerSync(tls, pDestPager, uintptr(0))
					}
				} else {
					_sqlite3PagerTruncateImage(tls, pDestPager, uint32(uint32(nDestTruncate)))
					rc = _sqlite3PagerCommitPhaseOne(tls, pDestPager, uintptr(0), 0)
				}
				/* Finish committing the transaction to the destination database. */
				if v8 = SQLITE_OK == rc; v8 {
					v7 = _sqlite3BtreeCommitPhaseTwo(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest, 0)
					rc = v7
				}
				if v8 && SQLITE_OK == v7 {
					rc = int32(SQLITE_DONE)
				}
			}
		}
		/* If bCloseTrans is true, then this function opened a read transaction
		 ** on the source database. Close the read transaction here. There is
		 ** no need to check the return values of the btree methods here, as
		 ** "committing" a read-only transaction cannot fail.
		 */
		if bCloseTrans != 0 {
			_sqlite3BtreeCommitPhaseOne(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc, uintptr(0))
			_sqlite3BtreeCommitPhaseTwo(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc, 0)
		}
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			rc = int32(SQLITE_NOMEM)
		}
		(*Tsqlite3_backup)(unsafe.Pointer(p)).Frc = rc
	}
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
	}
	_sqlite3BtreeLeave(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrcDb)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Release all resources associated with an sqlite3_backup* handle.
//	*/
func Xsqlite3_backup_finish(tls *libc.TLS, p uintptr) (r int32) {
	var pSrcDb, pp uintptr
	var rc, v1 int32
	_, _, _, _ = pSrcDb, pp, rc, v1 /* Value to return */
	/* Enter the mutexes */
	if p == uintptr(0) {
		return SQLITE_OK
	}
	pSrcDb = (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrcDb
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	_sqlite3BtreeEnter(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
	}
	/* Detach this backup from the source pager. */
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		(*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup--
	}
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FisAttached != 0 {
		pp = _sqlite3PagerBackupPtr(tls, _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc))
		for *(*uintptr)(unsafe.Pointer(pp)) != p {
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 44
		}
		*(*uintptr)(unsafe.Pointer(pp)) = (*Tsqlite3_backup)(unsafe.Pointer(p)).FpNext
	}
	/* If a transaction is still open on the Btree, roll it back. */
	_sqlite3BtreeRollback(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest, SQLITE_OK, 0)
	/* Set the error code of the destination database handle. */
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).Frc == int32(SQLITE_DONE) {
		v1 = SQLITE_OK
	} else {
		v1 = (*Tsqlite3_backup)(unsafe.Pointer(p)).Frc
	}
	rc = v1
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		_sqlite3Error(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb, rc)
		/* Exit the mutexes and free the backup context structure. */
		_sqlite3LeaveMutexAndCloseZombie(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)
	}
	_sqlite3BtreeLeave(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		/* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
		 ** call to sqlite3_backup_init() and is destroyed by a call to
		 ** sqlite3_backup_finish(). */
		Xsqlite3_free(tls, p)
	}
	_sqlite3LeaveMutexAndCloseZombie(tls, pSrcDb)
	return rc
}

// C documentation
//
//	/*
//	** Return the number of pages still to be backed up as of the most recent
//	** call to sqlite3_backup_step().
//	*/
func Xsqlite3_backup_remaining(tls *libc.TLS, p uintptr) (r int32) {
	return int32((*Tsqlite3_backup)(unsafe.Pointer(p)).FnRemaining)
}

// C documentation
//
//	/*
//	** Return the total number of pages in the source database as of the most
//	** recent call to sqlite3_backup_step().
//	*/
func Xsqlite3_backup_pagecount(tls *libc.TLS, p uintptr) (r int32) {
	return int32((*Tsqlite3_backup)(unsafe.Pointer(p)).FnPagecount)
}

// C documentation
//
//	/*
//	** This function is called after the contents of page iPage of the
//	** source database have been modified. If page iPage has already been
//	** copied into the destination database, then the data written to the
//	** destination is now invalidated. The destination copy of iPage needs
//	** to be updated with the new data before the backup operation is
//	** complete.
//	**
//	** It is assumed that the mutex associated with the BtShared object
//	** corresponding to the source database is held when this function is
//	** called.
//	*/
func _backupUpdate(tls *libc.TLS, p uintptr, iPage TPgno, aData uintptr) {
	var rc int32
	var v1 uintptr
	_, _ = rc, v1
	for {
		if !(_isFatalError(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).Frc) != 0) && iPage < (*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext {
			Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
			rc = _backupOnePage(tls, p, iPage, aData, int32(1))
			Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
			if rc != SQLITE_OK {
				(*Tsqlite3_backup)(unsafe.Pointer(p)).Frc = rc
			}
		}
		goto _2
	_2:
		;
		v1 = (*Tsqlite3_backup)(unsafe.Pointer(p)).FpNext
		p = v1
		if !(v1 != uintptr(0)) {
			break
		}
	}
}

func _sqlite3BackupUpdate(tls *libc.TLS, pBackup uintptr, iPage TPgno, aData uintptr) {
	if pBackup != 0 {
		_backupUpdate(tls, pBackup, iPage, aData)
	}
}

// C documentation
//
//	/*
//	** Restart the backup process. This is called when the pager layer
//	** detects that the database has been modified by an external database
//	** connection. In this case there is no way of knowing which of the
//	** pages that have been copied into the destination database are still
//	** valid and which are not, so the entire process needs to be restarted.
//	**
//	** It is assumed that the mutex associated with the BtShared object
//	** corresponding to the source database is held when this function is
//	** called.
//	*/
func _sqlite3BackupRestart(tls *libc.TLS, pBackup uintptr) {
	var p uintptr
	_ = p /* Iterator variable */
	p = pBackup
	for {
		if !(p != 0) {
			break
		}
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext = uint32(1)
		goto _1
	_1:
		;
		p = (*Tsqlite3_backup)(unsafe.Pointer(p)).FpNext
	}
}

// C documentation
//
//	/*
//	** Copy the complete content of pBtFrom into pBtTo.  A transaction
//	** must be active for both files.
//	**
//	** The size of file pTo may be reduced by this operation. If anything
//	** goes wrong, the transaction on pTo is rolled back. If successful, the
//	** transaction is committed before returning.
//	*/
func _sqlite3BtreeCopyFile(tls *libc.TLS, pTo uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var pFd, p1 uintptr
	var rc int32
	var _ /* b at bp+0 */ Tsqlite3_backup
	var _ /* nByte at bp+48 */ Ti64
	_, _, _ = pFd, rc, p1
	_sqlite3BtreeEnter(tls, pTo)
	_sqlite3BtreeEnter(tls, pFrom)
	pFd = _sqlite3PagerFile(tls, _sqlite3BtreePager(tls, pTo))
	if (*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods != 0 {
		*(*Ti64)(unsafe.Pointer(bp + 48)) = int64(_sqlite3BtreeGetPageSize(tls, pFrom)) * int64(_sqlite3BtreeLastPage(tls, pFrom))
		rc = _sqlite3OsFileControl(tls, pFd, int32(SQLITE_FCNTL_OVERWRITE), bp+48)
		if rc == int32(SQLITE_NOTFOUND) {
			rc = SQLITE_OK
		}
		if rc != 0 {
			goto copy_finished
		}
	}
	/* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
	 ** to 0. This is used by the implementations of sqlite3_backup_step()
	 ** and sqlite3_backup_finish() to detect that they are being called
	 ** from this function, not directly by the user.
	 */
	libc.Xmemset(tls, bp, 0, uint32(48))
	(*(*Tsqlite3_backup)(unsafe.Pointer(bp))).FpSrcDb = (*TBtree)(unsafe.Pointer(pFrom)).Fdb
	(*(*Tsqlite3_backup)(unsafe.Pointer(bp))).FpSrc = pFrom
	(*(*Tsqlite3_backup)(unsafe.Pointer(bp))).FpDest = pTo
	(*(*Tsqlite3_backup)(unsafe.Pointer(bp))).FiNext = uint32(1)
	/* 0x7FFFFFFF is the hard limit for the number of pages in a database
	 ** file. By passing this as the number of pages to copy to
	 ** sqlite3_backup_step(), we can guarantee that the copy finishes
	 ** within a single call (unless an error occurs). The assert() statement
	 ** checks this assumption - (p->rc) should be set to either SQLITE_DONE
	 ** or an error code.  */
	Xsqlite3_backup_step(tls, bp, int32(0x7FFFFFFF))
	rc = Xsqlite3_backup_finish(tls, bp)
	if rc == SQLITE_OK {
		p1 = (*TBtree)(unsafe.Pointer(pTo)).FpBt + 24
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
	} else {
		_sqlite3PagerClearCache(tls, _sqlite3BtreePager(tls, (*(*Tsqlite3_backup)(unsafe.Pointer(bp))).FpDest))
	}
	goto copy_finished
copy_finished:
	;
	_sqlite3BtreeLeave(tls, pFrom)
	_sqlite3BtreeLeave(tls, pTo)
	return rc
}

/************** End of backup.c **********************************************/
/************** Begin file vdbemem.c *****************************************/
/*
** 2004 May 26
**
** 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 use to manipulate "Mem" structure.  A "Mem"
** stores a single value in the VDBE.  Mem is an opaque structure visible
** only within the VDBE.  Interface routines refer to a Mem using the
** name sqlite_value
 */
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */

/* True if X is a power of two.  0 is considered a power of two here.
** In other words, return true if X has at most one bit set.
 */

// C documentation
//
//	/*
//	** Render a Mem object which is one of MEM_Int, MEM_Real, or MEM_IntReal
//	** into a buffer.
//	*/
func _vdbeMemRenderNum(tls *libc.TLS, sz int32, zBuf uintptr, p uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var v1 float64
	var _ /* acc at bp+0 */ TStrAccum
	var _ /* x at bp+24 */ Ti64
	_ = v1
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Int) != 0 {
		libc.Xmemcpy(tls, bp+24, p, uint32(int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Int)*int32(2)))
		(*TMem)(unsafe.Pointer(p)).Fn = _sqlite3Int64ToText(tls, *(*Ti64)(unsafe.Pointer(bp + 24)), zBuf)
	} else {
		_sqlite3StrAccumInit(tls, bp, uintptr(0), zBuf, sz, 0)
		if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_IntReal) != 0 {
			v1 = float64(*(*Ti64)(unsafe.Pointer(p)))
		} else {
			v1 = *(*float64)(unsafe.Pointer(p))
		}
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6440, libc.VaList(bp+40, v1))
		*(*int8)(unsafe.Pointer(zBuf + uintptr((*(*TStrAccum)(unsafe.Pointer(bp))).FnChar))) = 0 /* Fast version of sqlite3StrAccumFinish(&acc) */
		(*TMem)(unsafe.Pointer(p)).Fn = int32((*(*TStrAccum)(unsafe.Pointer(bp))).FnChar)
	}
}

// C documentation
//
//	/*
//	** If pMem is an object with a valid string representation, this routine
//	** ensures the internal encoding for the string representation is
//	** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
//	**
//	** If pMem is not a string object, or the encoding of the string
//	** representation is already stored using the requested encoding, then this
//	** routine is a no-op.
//	**
//	** SQLITE_OK is returned if the conversion is successful (or not required).
//	** SQLITE_NOMEM may be returned if a malloc() fails during conversion
//	** between formats.
//	*/
func _sqlite3VdbeChangeEncoding(tls *libc.TLS, pMem uintptr, desiredEnc int32) (r int32) {
	var rc int32
	_ = rc
	if !(int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&libc.Int32FromInt32(MEM_Str) != 0) {
		(*TMem)(unsafe.Pointer(pMem)).Fenc = uint8(uint8(desiredEnc))
		return SQLITE_OK
	}
	if int32((*TMem)(unsafe.Pointer(pMem)).Fenc) == desiredEnc {
		return SQLITE_OK
	}
	/* MemTranslate() may return SQLITE_OK or SQLITE_NOMEM. If NOMEM is returned,
	 ** then the encoding of the value may not have changed.
	 */
	rc = _sqlite3VdbeMemTranslate(tls, pMem, uint8(uint8(desiredEnc)))
	return rc
}

// C documentation
//
//	/*
//	** Make sure pMem->z points to a writable allocation of at least n bytes.
//	**
//	** If the bPreserve argument is true, then copy of the content of
//	** pMem->z into the new allocation.  pMem must be either a string or
//	** blob if bPreserve is true.  If bPreserve is false, any prior content
//	** in pMem->z is discarded.
//	*/
func _sqlite3VdbeMemGrow(tls *libc.TLS, pMem uintptr, n int32, bPreserve int32) (r int32) {
	var v1, p2 uintptr
	_, _ = v1, p2
	/* If the bPreserve flag is set to true, then the memory cell must already
	 ** contain a valid string or blob value.  */
	if (*TMem)(unsafe.Pointer(pMem)).FszMalloc > 0 && bPreserve != 0 && (*TMem)(unsafe.Pointer(pMem)).Fz == (*TMem)(unsafe.Pointer(pMem)).FzMalloc {
		if (*TMem)(unsafe.Pointer(pMem)).Fdb != 0 {
			v1 = _sqlite3DbReallocOrFree(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).Fz, uint64(uint64(n)))
			(*TMem)(unsafe.Pointer(pMem)).FzMalloc = v1
			(*TMem)(unsafe.Pointer(pMem)).Fz = v1
		} else {
			(*TMem)(unsafe.Pointer(pMem)).FzMalloc = _sqlite3Realloc(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, uint64(uint64(n)))
			if (*TMem)(unsafe.Pointer(pMem)).FzMalloc == uintptr(0) {
				Xsqlite3_free(tls, (*TMem)(unsafe.Pointer(pMem)).Fz)
			}
			(*TMem)(unsafe.Pointer(pMem)).Fz = (*TMem)(unsafe.Pointer(pMem)).FzMalloc
		}
		bPreserve = 0
	} else {
		if (*TMem)(unsafe.Pointer(pMem)).FszMalloc > 0 {
			_sqlite3DbFreeNN(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).FzMalloc)
		}
		(*TMem)(unsafe.Pointer(pMem)).FzMalloc = _sqlite3DbMallocRaw(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, uint64(uint64(n)))
	}
	if (*TMem)(unsafe.Pointer(pMem)).FzMalloc == uintptr(0) {
		_sqlite3VdbeMemSetNull(tls, pMem)
		(*TMem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
		(*TMem)(unsafe.Pointer(pMem)).FszMalloc = 0
		return int32(SQLITE_NOMEM)
	} else {
		(*TMem)(unsafe.Pointer(pMem)).FszMalloc = _sqlite3DbMallocSize(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).FzMalloc)
	}
	if bPreserve != 0 && (*TMem)(unsafe.Pointer(pMem)).Fz != 0 {
		libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pMem)).FzMalloc, (*TMem)(unsafe.Pointer(pMem)).Fz, uint32((*TMem)(unsafe.Pointer(pMem)).Fn))
	}
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Dyn) != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMem)(unsafe.Pointer(pMem)).FxDel})))(tls, (*TMem)(unsafe.Pointer(pMem)).Fz)
	}
	(*TMem)(unsafe.Pointer(pMem)).Fz = (*TMem)(unsafe.Pointer(pMem)).FzMalloc
	p2 = pMem + 16
	*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^(libc.Int32FromInt32(MEM_Dyn) | libc.Int32FromInt32(MEM_Ephem) | libc.Int32FromInt32(MEM_Static)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Change the pMem->zMalloc allocation to be at least szNew bytes.
//	** If pMem->zMalloc already meets or exceeds the requested size, this
//	** routine is a no-op.
//	**
//	** Any prior string or blob content in the pMem object may be discarded.
//	** The pMem->xDel destructor is called, if it exists.  Though MEM_Str
//	** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, MEM_IntReal,
//	** and MEM_Null values are preserved.
//	**
//	** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
//	** if unable to complete the resizing.
//	*/
func _sqlite3VdbeMemClearAndResize(tls *libc.TLS, pMem uintptr, szNew int32) (r int32) {
	var p1 uintptr
	_ = p1
	if (*TMem)(unsafe.Pointer(pMem)).FszMalloc < szNew {
		return _sqlite3VdbeMemGrow(tls, pMem, szNew, 0)
	}
	(*TMem)(unsafe.Pointer(pMem)).Fz = (*TMem)(unsafe.Pointer(pMem)).FzMalloc
	p1 = pMem + 16
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & (libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If pMem is already a string, detect if it is a zero-terminated
//	** string, or make it into one if possible, and mark it as such.
//	**
//	** This is an optimization.  Correct operation continues even if
//	** this routine is a no-op.
//	*/
func _sqlite3VdbeMemZeroTerminateIfAble(tls *libc.TLS, pMem uintptr) {
	var p1, p2, p3 uintptr
	_, _, _ = p1, p2, p3
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Term)|libc.Int32FromInt32(MEM_Ephem)|libc.Int32FromInt32(MEM_Static)) != int32(MEM_Str) {
		/* pMem must be a string, and it cannot be an ephemeral or static string */
		return
	}
	if int32((*TMem)(unsafe.Pointer(pMem)).Fenc) != int32(SQLITE_UTF8) {
		return
	}
	if (*TMem)(unsafe.Pointer(pMem)).Fz == uintptr(0) {
		return
	}
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Dyn) != 0 {
		if (*TMem)(unsafe.Pointer(pMem)).FxDel == __ccgo_fp(Xsqlite3_free) && Xsqlite3_msize(tls, (*TMem)(unsafe.Pointer(pMem)).Fz) >= uint64((*TMem)(unsafe.Pointer(pMem)).Fn+libc.Int32FromInt32(1)) {
			*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn))) = 0
			p1 = pMem + 16
			*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(MEM_Term))
			return
		}
		if (*TMem)(unsafe.Pointer(pMem)).FxDel == __ccgo_fp(_sqlite3RCStrUnref) {
			/* Blindly assume that all RCStr objects are zero-terminated */
			p2 = pMem + 16
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_Term))
			return
		}
	} else {
		if (*TMem)(unsafe.Pointer(pMem)).FszMalloc >= (*TMem)(unsafe.Pointer(pMem)).Fn+int32(1) {
			*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn))) = 0
			p3 = pMem + 16
			*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(MEM_Term))
			return
		}
	}
}

// C documentation
//
//	/*
//	** It is already known that pMem contains an unterminated string.
//	** Add the zero terminator.
//	**
//	** Three bytes of zero are added.  In this way, there is guaranteed
//	** to be a double-zero byte at an even byte boundary in order to
//	** terminate a UTF16 string, even if the initial size of the buffer
//	** is an odd number of bytes.
//	*/
func _vdbeMemAddTerminator(tls *libc.TLS, pMem uintptr) (r int32) {
	var p1 uintptr
	_ = p1
	if _sqlite3VdbeMemGrow(tls, pMem, (*TMem)(unsafe.Pointer(pMem)).Fn+int32(3), int32(1)) != 0 {
		return int32(SQLITE_NOMEM)
	}
	*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn))) = 0
	*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn+int32(1)))) = 0
	*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((*TMem)(unsafe.Pointer(pMem)).Fn+int32(2)))) = 0
	p1 = pMem + 16
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(MEM_Term))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Change pMem so that its MEM_Str or MEM_Blob value is stored in
//	** MEM.zMalloc, where it can be safely written.
//	**
//	** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
//	*/
func _sqlite3VdbeMemMakeWriteable(tls *libc.TLS, pMem uintptr) (r int32) {
	var rc, v1 int32
	var p2 uintptr
	_, _, _ = rc, v1, p2
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 {
		if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Zero) != 0 {
			v1 = _sqlite3VdbeMemExpandBlob(tls, pMem)
		} else {
			v1 = 0
		}
		if v1 != 0 {
			return int32(SQLITE_NOMEM)
		}
		if (*TMem)(unsafe.Pointer(pMem)).FszMalloc == 0 || (*TMem)(unsafe.Pointer(pMem)).Fz != (*TMem)(unsafe.Pointer(pMem)).FzMalloc {
			rc = _vdbeMemAddTerminator(tls, pMem)
			if rc != 0 {
				return rc
			}
		}
	}
	p2 = pMem + 16
	*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(MEM_Ephem))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If the given Mem* has a zero-filled tail, turn it into an ordinary
//	** blob stored in dynamically allocated space.
//	*/
func _sqlite3VdbeMemExpandBlob(tls *libc.TLS, pMem uintptr) (r int32) {
	var nByte int32
	var p1 uintptr
	_, _ = nByte, p1
	/* Set nByte to the number of bytes required to store the expanded blob. */
	nByte = (*TMem)(unsafe.Pointer(pMem)).Fn + *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pMem)).Fu))
	if nByte <= 0 {
		if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Blob) == 0 {
			return SQLITE_OK
		}
		nByte = int32(1)
	}
	if _sqlite3VdbeMemGrow(tls, pMem, nByte, int32(1)) != 0 {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, (*TMem)(unsafe.Pointer(pMem)).Fz+uintptr((*TMem)(unsafe.Pointer(pMem)).Fn), 0, uint32(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pMem)).Fu))))
	*(*int32)(unsafe.Pointer(pMem + 12)) += *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pMem)).Fu))
	p1 = pMem + 16
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(MEM_Zero) | libc.Int32FromInt32(MEM_Term)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Make sure the given Mem is \u0000 terminated.
//	*/
func _sqlite3VdbeMemNulTerminate(tls *libc.TLS, pMem uintptr) (r int32) {
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Term)|libc.Int32FromInt32(MEM_Str)) != int32(MEM_Str) {
		return SQLITE_OK /* Nothing to do */
	} else {
		return _vdbeMemAddTerminator(tls, pMem)
	}
	return r
}

// C documentation
//
//	/*
//	** Add MEM_Str to the set of representations for the given Mem.  This
//	** routine is only called if pMem is a number of some kind, not a NULL
//	** or a BLOB.
//	**
//	** Existing representations MEM_Int, MEM_Real, or MEM_IntReal are invalidated
//	** if bForce is true but are retained if bForce is false.
//	**
//	** A MEM_Null value will never be passed to this function. This function is
//	** used for converting values to text for returning to the user (i.e. via
//	** sqlite3_value_text()), or for ensuring that values to be used as btree
//	** keys are strings. In the former case a NULL pointer is returned the
//	** user and the latter is an internal programming error.
//	*/
func _sqlite3VdbeMemStringify(tls *libc.TLS, pMem uintptr, enc Tu8, bForce Tu8) (r int32) {
	var nByte int32
	var p1, p2 uintptr
	_, _, _ = nByte, p1, p2
	nByte = int32(32)
	if _sqlite3VdbeMemClearAndResize(tls, pMem, nByte) != 0 {
		(*TMem)(unsafe.Pointer(pMem)).Fenc = uint8(0)
		return int32(SQLITE_NOMEM)
	}
	_vdbeMemRenderNum(tls, nByte, (*TMem)(unsafe.Pointer(pMem)).Fz, pMem)
	(*TMem)(unsafe.Pointer(pMem)).Fenc = uint8(SQLITE_UTF8)
	p1 = pMem + 16
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | (libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Term)))
	if bForce != 0 {
		p2 = pMem + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
	}
	_sqlite3VdbeChangeEncoding(tls, pMem, int32(int32(enc)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Memory cell pMem contains the context of an aggregate function.
//	** This routine calls the finalize method for that function.  The
//	** result of the aggregate is stored back into pMem.
//	**
//	** Return SQLITE_ERROR if the finalizer reports an error.  SQLITE_OK
//	** otherwise.
//	*/
func _sqlite3VdbeMemFinalize(tls *libc.TLS, pMem uintptr, pFunc uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var _ /* ctx at bp+0 */ Tsqlite3_context
	var _ /* t at bp+32 */ TMem
	libc.Xmemset(tls, bp, 0, uint32(32))
	libc.Xmemset(tls, bp+32, 0, uint32(40))
	(*(*TMem)(unsafe.Pointer(bp + 32))).Fflags = uint16(MEM_Null)
	(*(*TMem)(unsafe.Pointer(bp + 32))).Fdb = (*TMem)(unsafe.Pointer(pMem)).Fdb
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpOut = bp + 32
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpMem = pMem
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpFunc = pFunc
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).Fenc = (*Tsqlite3)(unsafe.Pointer((*(*TMem)(unsafe.Pointer(bp + 32))).Fdb)).Fenc
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer(pFunc)).FxFinalize})))(tls, bp) /* IMP: R-24505-23230 */
	if (*TMem)(unsafe.Pointer(pMem)).FszMalloc > 0 {
		_sqlite3DbFreeNN(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).FzMalloc)
	}
	libc.Xmemcpy(tls, pMem, bp+32, uint32(40))
	return (*(*Tsqlite3_context)(unsafe.Pointer(bp))).FisError
}

// C documentation
//
//	/*
//	** Memory cell pAccum contains the context of an aggregate function.
//	** This routine calls the xValue method for that function and stores
//	** the results in memory cell pMem.
//	**
//	** SQLITE_ERROR is returned if xValue() reports an error. SQLITE_OK
//	** otherwise.
//	*/
func _sqlite3VdbeMemAggValue(tls *libc.TLS, pAccum uintptr, pOut uintptr, pFunc uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* ctx at bp+0 */ Tsqlite3_context
	libc.Xmemset(tls, bp, 0, uint32(32))
	_sqlite3VdbeMemSetNull(tls, pOut)
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpOut = pOut
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpMem = pAccum
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpFunc = pFunc
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).Fenc = (*Tsqlite3)(unsafe.Pointer((*TMem)(unsafe.Pointer(pAccum)).Fdb)).Fenc
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer(pFunc)).FxValue})))(tls, bp)
	return (*(*Tsqlite3_context)(unsafe.Pointer(bp))).FisError
}

// C documentation
//
//	/*
//	** If the memory cell contains a value that must be freed by
//	** invoking the external callback in Mem.xDel, then this routine
//	** will free that value.  It also sets Mem.flags to MEM_Null.
//	**
//	** This is a helper routine for sqlite3VdbeMemSetNull() and
//	** for sqlite3VdbeMemRelease().  Use those other routines as the
//	** entry point for releasing Mem resources.
//	*/
func _vdbeMemClearExternAndSetNull(tls *libc.TLS, p uintptr) {
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Agg) != 0 {
		_sqlite3VdbeMemFinalize(tls, p, *(*uintptr)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(p)).Fu)))
	}
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Dyn) != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMem)(unsafe.Pointer(p)).FxDel})))(tls, (*TMem)(unsafe.Pointer(p)).Fz)
	}
	(*TMem)(unsafe.Pointer(p)).Fflags = uint16(MEM_Null)
}

// C documentation
//
//	/*
//	** Release memory held by the Mem p, both external memory cleared
//	** by p->xDel and memory in p->zMalloc.
//	**
//	** This is a helper routine invoked by sqlite3VdbeMemRelease() in
//	** the unusual case where there really is memory in p that needs
//	** to be freed.
//	*/
func _vdbeMemClear(tls *libc.TLS, p uintptr) {
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
		_vdbeMemClearExternAndSetNull(tls, p)
	}
	if (*TMem)(unsafe.Pointer(p)).FszMalloc != 0 {
		_sqlite3DbFreeNN(tls, (*TMem)(unsafe.Pointer(p)).Fdb, (*TMem)(unsafe.Pointer(p)).FzMalloc)
		(*TMem)(unsafe.Pointer(p)).FszMalloc = 0
	}
	(*TMem)(unsafe.Pointer(p)).Fz = uintptr(0)
}

// C documentation
//
//	/*
//	** Release any memory resources held by the Mem.  Both the memory that is
//	** free by Mem.xDel and the Mem.zMalloc allocation are freed.
//	**
//	** Use this routine prior to clean up prior to abandoning a Mem, or to
//	** reset a Mem back to its minimum memory utilization.
//	**
//	** Use sqlite3VdbeMemSetNull() to release just the Mem.xDel space
//	** prior to inserting new content into the Mem.
//	*/
func _sqlite3VdbeMemRelease(tls *libc.TLS, p uintptr) {
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 || (*TMem)(unsafe.Pointer(p)).FszMalloc != 0 {
		_vdbeMemClear(tls, p)
	}
}

// C documentation
//
//	/* Like sqlite3VdbeMemRelease() but faster for cases where we
//	** know in advance that the Mem is not MEM_Dyn or MEM_Agg.
//	*/
func _sqlite3VdbeMemReleaseMalloc(tls *libc.TLS, p uintptr) {
	if (*TMem)(unsafe.Pointer(p)).FszMalloc != 0 {
		_vdbeMemClear(tls, p)
	}
}

// C documentation
//
//	/*
//	** Return some kind of integer value which is the best we can do
//	** at representing the value that *pMem describes as an integer.
//	** If pMem is an integer, then the value is exact.  If pMem is
//	** a floating-point then the value returned is the integer part.
//	** If pMem is a string or blob, then we make an attempt to convert
//	** it into an integer and return that.  If pMem represents an
//	** an SQL-NULL value, return 0.
//	**
//	** If pMem represents a string value, its encoding might be changed.
//	*/
func _memIntValue(tls *libc.TLS, pMem uintptr) (r Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* value at bp+0 */ Ti64
	*(*Ti64)(unsafe.Pointer(bp)) = 0
	_sqlite3Atoi64(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, bp, (*TMem)(unsafe.Pointer(pMem)).Fn, (*TMem)(unsafe.Pointer(pMem)).Fenc)
	return *(*Ti64)(unsafe.Pointer(bp))
}

func _sqlite3VdbeIntValue(tls *libc.TLS, pMem uintptr) (r Ti64) {
	var flags int32
	_ = flags
	flags = int32((*TMem)(unsafe.Pointer(pMem)).Fflags)
	if flags&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
		return *(*Ti64)(unsafe.Pointer(pMem))
	} else {
		if flags&int32(MEM_Real) != 0 {
			return _sqlite3RealToI64(tls, *(*float64)(unsafe.Pointer(pMem)))
		} else {
			if flags&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 && (*TMem)(unsafe.Pointer(pMem)).Fz != uintptr(0) {
				return _memIntValue(tls, pMem)
			} else {
				return 0
			}
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Return the best representation of pMem that we can get into a
//	** double.  If pMem is already a double or an integer, return its
//	** value.  If it is a string or blob, try to convert it to a double.
//	** If it is a NULL, return 0.0.
//	*/
func _memRealValue(tls *libc.TLS, pMem uintptr) (r float64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* val at bp+0 */ float64
	/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
	*(*float64)(unsafe.Pointer(bp)) = libc.Float64FromInt32(0)
	_sqlite3AtoF(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, bp, (*TMem)(unsafe.Pointer(pMem)).Fn, (*TMem)(unsafe.Pointer(pMem)).Fenc)
	return *(*float64)(unsafe.Pointer(bp))
}

func _sqlite3VdbeRealValue(tls *libc.TLS, pMem uintptr) (r float64) {
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Real) != 0 {
		return *(*float64)(unsafe.Pointer(pMem))
	} else {
		if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
			return float64(*(*Ti64)(unsafe.Pointer(pMem)))
		} else {
			if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 {
				return _memRealValue(tls, pMem)
			} else {
				/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
				return libc.Float64FromInt32(0)
			}
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Return 1 if pMem represents true, and return 0 if pMem represents false.
//	** Return the value ifNull if pMem is NULL.
//	*/
func _sqlite3VdbeBooleanValue(tls *libc.TLS, pMem uintptr, ifNull int32) (r int32) {
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
		return libc.BoolInt32(*(*Ti64)(unsafe.Pointer(pMem)) != 0)
	}
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Null) != 0 {
		return ifNull
	}
	return libc.BoolInt32(_sqlite3VdbeRealValue(tls, pMem) != float64(0))
}

// C documentation
//
//	/*
//	** The MEM structure is already a MEM_Real or MEM_IntReal. Try to
//	** make it a MEM_Int if we can.
//	*/
func _sqlite3VdbeIntegerAffinity(tls *libc.TLS, pMem uintptr) {
	var ix Ti64
	_ = ix
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_IntReal) != 0 {
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
	} else {
		ix = _sqlite3RealToI64(tls, *(*float64)(unsafe.Pointer(pMem)))
		/* Only mark the value as an integer if
		 **
		 **    (1) the round-trip conversion real->int->real is a no-op, and
		 **    (2) The integer is neither the largest nor the smallest
		 **        possible integer (ticket #3922)
		 **
		 ** The second and third terms in the following conditional enforces
		 ** the second condition under the assumption that addition overflow causes
		 ** values to wrap around.
		 */
		if *(*float64)(unsafe.Pointer(pMem)) == float64(float64(ix)) && ix > int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) && ix < libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32) {
			*(*Ti64)(unsafe.Pointer(pMem)) = ix
			(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		}
	}
}

// C documentation
//
//	/*
//	** Convert pMem to type integer.  Invalidate any prior representations.
//	*/
func _sqlite3VdbeMemIntegerify(tls *libc.TLS, pMem uintptr) (r int32) {
	*(*Ti64)(unsafe.Pointer(pMem)) = _sqlite3VdbeIntValue(tls, pMem)
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Convert pMem so that it is of type MEM_Real.
//	** Invalidate any prior representations.
//	*/
func _sqlite3VdbeMemRealify(tls *libc.TLS, pMem uintptr) (r int32) {
	*(*float64)(unsafe.Pointer(pMem)) = _sqlite3VdbeRealValue(tls, pMem)
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Real))
	return SQLITE_OK
}

// C documentation
//
//	/* Compare a floating point value to an integer.  Return true if the two
//	** values are the same within the precision of the floating point value.
//	**
//	** This function assumes that i was obtained by assignment from r1.
//	**
//	** For some versions of GCC on 32-bit machines, if you do the more obvious
//	** comparison of "r1==(double)i" you sometimes get an answer of false even
//	** though the r1 and (double)i values are bit-for-bit the same.
//	*/
func _sqlite3RealSameAsInt(tls *libc.TLS, _r1 float64, i Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = _r1
	var _ /* r2 at bp+8 */ float64
	*(*float64)(unsafe.Pointer(bp + 8)) = float64(float64(i))
	return libc.BoolInt32(*(*float64)(unsafe.Pointer(bp)) == float64(0) || libc.Xmemcmp(tls, bp, bp+8, uint32(8)) == 0 && i >= -int64(2251799813685248) && i < int64(2251799813685248))
}

// C documentation
//
//	/* Convert a floating point value to its closest integer.  Do so in
//	** a way that avoids 'outside the range of representable values' warnings
//	** from UBSAN.
//	*/
func _sqlite3RealToI64(tls *libc.TLS, r float64) (r1 Ti64) {
	if r < -libc.Float64FromFloat64(9.223372036854775e+18) {
		return int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
	}
	if r > +libc.Float64FromFloat64(9.223372036854775e+18) {
		return libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
	}
	return int64(int64(r))
}

// C documentation
//
//	/*
//	** Convert pMem so that it has type MEM_Real or MEM_Int.
//	** Invalidate any prior representations.
//	**
//	** Every effort is made to force the conversion, even if the input
//	** is a string that does not look completely like a number.  Convert
//	** as much of the string as we can and ignore the rest.
//	*/
func _sqlite3VdbeMemNumerify(tls *libc.TLS, pMem uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var v1 Tsqlite3_int64
	var v2 bool
	var p3 uintptr
	var _ /* ix at bp+0 */ Tsqlite3_int64
	_, _, _, _ = rc, v1, v2, p3
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Null)) == 0 {
		rc = _sqlite3AtoF(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, pMem, (*TMem)(unsafe.Pointer(pMem)).Fn, (*TMem)(unsafe.Pointer(pMem)).Fenc)
		if v2 = (rc == 0 || rc == int32(1)) && _sqlite3Atoi64(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, bp, (*TMem)(unsafe.Pointer(pMem)).Fn, (*TMem)(unsafe.Pointer(pMem)).Fenc) <= int32(1); !v2 {
			v1 = _sqlite3RealToI64(tls, *(*float64)(unsafe.Pointer(pMem)))
			*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = v1
		}
		if v2 || _sqlite3RealSameAsInt(tls, *(*float64)(unsafe.Pointer(pMem)), v1) != 0 {
			*(*Ti64)(unsafe.Pointer(pMem)) = *(*Tsqlite3_int64)(unsafe.Pointer(bp))
			(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		} else {
			(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Real))
		}
	}
	p3 = pMem + 16
	*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Zero)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Cast the datatype of the value in pMem according to the affinity
//	** "aff".  Casting is different from applying affinity in that a cast
//	** is forced.  In other words, the value is converted into the desired
//	** affinity even if that results in loss of data.  This routine is
//	** used (for example) to implement the SQL "cast()" operator.
//	*/
func _sqlite3VdbeMemCast(tls *libc.TLS, pMem uintptr, aff Tu8, encoding Tu8) (r int32) {
	var rc int32
	var p1, p2, p3 uintptr
	_, _, _, _ = rc, p1, p2, p3
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Null) != 0 {
		return SQLITE_OK
	}
	switch int32(int32(aff)) {
	case int32(SQLITE_AFF_BLOB): /* Really a cast to BLOB */
		if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Blob) == 0 {
			_sqlite3ValueApplyAffinity(tls, pMem, uint8(SQLITE_AFF_TEXT), encoding)
			if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Str) != 0 {
				(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Blob))
			}
		} else {
			p1 = pMem + 16
			*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(MEM_TypeMask) & ^libc.Int32FromInt32(MEM_Blob)))
		}
	case int32(SQLITE_AFF_NUMERIC):
		_sqlite3VdbeMemNumerify(tls, pMem)
	case int32(SQLITE_AFF_INTEGER):
		_sqlite3VdbeMemIntegerify(tls, pMem)
	case int32(SQLITE_AFF_REAL):
		_sqlite3VdbeMemRealify(tls, pMem)
	default:
		p2 = pMem + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&libc.Int32FromInt32(MEM_Blob)>>libc.Int32FromInt32(3))
		_sqlite3ValueApplyAffinity(tls, pMem, uint8(SQLITE_AFF_TEXT), encoding)
		p3 = pMem + 16
		*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal) | libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Zero)))
		if int32(int32(encoding)) != int32(SQLITE_UTF8) {
			*(*int32)(unsafe.Pointer(pMem + 12)) &= ^libc.Int32FromInt32(1)
		}
		rc = _sqlite3VdbeChangeEncoding(tls, pMem, int32(int32(encoding)))
		if rc != 0 {
			return rc
		}
		_sqlite3VdbeMemZeroTerminateIfAble(tls, pMem)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Initialize bulk memory to be a consistent Mem object.
//	**
//	** The minimum amount of initialization feasible is performed.
//	*/
func _sqlite3VdbeMemInit(tls *libc.TLS, pMem uintptr, db uintptr, flags Tu16) {
	(*TMem)(unsafe.Pointer(pMem)).Fflags = flags
	(*TMem)(unsafe.Pointer(pMem)).Fdb = db
	(*TMem)(unsafe.Pointer(pMem)).FszMalloc = 0
}

// C documentation
//
//	/*
//	** Delete any previous value and set the value stored in *pMem to NULL.
//	**
//	** This routine calls the Mem.xDel destructor to dispose of values that
//	** require the destructor.  But it preserves the Mem.zMalloc memory allocation.
//	** To free all resources, use sqlite3VdbeMemRelease(), which both calls this
//	** routine to invoke the destructor and deallocates Mem.zMalloc.
//	**
//	** Use this routine to reset the Mem prior to insert a new value.
//	**
//	** Use sqlite3VdbeMemRelease() to complete erase the Mem prior to abandoning it.
//	*/
func _sqlite3VdbeMemSetNull(tls *libc.TLS, pMem uintptr) {
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
		_vdbeMemClearExternAndSetNull(tls, pMem)
	} else {
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Null)
	}
}

func _sqlite3ValueSetNull(tls *libc.TLS, p uintptr) {
	_sqlite3VdbeMemSetNull(tls, p)
}

// C documentation
//
//	/*
//	** Delete any previous value and set the value to be a BLOB of length
//	** n containing all zeros.
//	*/
func _sqlite3VdbeMemSetZeroBlob(tls *libc.TLS, pMem uintptr, n int32) {
	_sqlite3VdbeMemRelease(tls, pMem)
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Zero))
	(*TMem)(unsafe.Pointer(pMem)).Fn = 0
	if n < 0 {
		n = 0
	}
	*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pMem)).Fu)) = n
	(*TMem)(unsafe.Pointer(pMem)).Fenc = uint8(SQLITE_UTF8)
	(*TMem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
}

// C documentation
//
//	/*
//	** The pMem is known to contain content that needs to be destroyed prior
//	** to a value change.  So invoke the destructor, then set the value to
//	** a 64-bit integer.
//	*/
func _vdbeReleaseAndSetInt64(tls *libc.TLS, pMem uintptr, val Ti64) {
	_sqlite3VdbeMemSetNull(tls, pMem)
	*(*Ti64)(unsafe.Pointer(pMem)) = val
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
}

// C documentation
//
//	/*
//	** Delete any previous value and set the value stored in *pMem to val,
//	** manifest type INTEGER.
//	*/
func _sqlite3VdbeMemSetInt64(tls *libc.TLS, pMem uintptr, val Ti64) {
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
		_vdbeReleaseAndSetInt64(tls, pMem, val)
	} else {
		*(*Ti64)(unsafe.Pointer(pMem)) = val
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
	}
}

// C documentation
//
//	/*
//	** Set the iIdx'th entry of array aMem[] to contain integer value val.
//	*/
func _sqlite3MemSetArrayInt64(tls *libc.TLS, aMem uintptr, iIdx int32, val Ti64) {
	_sqlite3VdbeMemSetInt64(tls, aMem+uintptr(iIdx)*40, val)
}

// C documentation
//
//	/* A no-op destructor */
func _sqlite3NoopDestructor(tls *libc.TLS, p uintptr) {
	_ = p
}

// C documentation
//
//	/*
//	** Set the value stored in *pMem should already be a NULL.
//	** Also store a pointer to go with it.
//	*/
func _sqlite3VdbeMemSetPointer(tls *libc.TLS, pMem uintptr, pPtr uintptr, zPType uintptr, xDestructor uintptr) {
	var v1, v2 uintptr
	_, _ = v1, v2
	_vdbeMemClear(tls, pMem)
	if zPType != 0 {
		v1 = zPType
	} else {
		v1 = __ccgo_ts + 1672
	}
	*(*uintptr)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pMem)).Fu)) = v1
	(*TMem)(unsafe.Pointer(pMem)).Fz = pPtr
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Dyn) | libc.Int32FromInt32(MEM_Subtype) | libc.Int32FromInt32(MEM_Term))
	(*TMem)(unsafe.Pointer(pMem)).FeSubtype = uint8('p')
	if xDestructor != 0 {
		v2 = xDestructor
	} else {
		v2 = __ccgo_fp(_sqlite3NoopDestructor)
	}
	(*TMem)(unsafe.Pointer(pMem)).FxDel = v2
}

// C documentation
//
//	/*
//	** Delete any previous value and set the value stored in *pMem to val,
//	** manifest type REAL.
//	*/
func _sqlite3VdbeMemSetDouble(tls *libc.TLS, pMem uintptr, val float64) {
	_sqlite3VdbeMemSetNull(tls, pMem)
	if !(_sqlite3IsNaN(tls, val) != 0) {
		*(*float64)(unsafe.Pointer(pMem)) = val
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Real)
	}
}

// C documentation
//
//	/*
//	** Delete any previous value and set the value of pMem to be an
//	** empty boolean index.
//	**
//	** Return SQLITE_OK on success and SQLITE_NOMEM if a memory allocation
//	** error occurs.
//	*/
func _sqlite3VdbeMemSetRowSet(tls *libc.TLS, pMem uintptr) (r int32) {
	var db, p uintptr
	_, _ = db, p
	db = (*TMem)(unsafe.Pointer(pMem)).Fdb
	_sqlite3VdbeMemRelease(tls, pMem)
	p = _sqlite3RowSetInit(tls, db)
	if p == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TMem)(unsafe.Pointer(pMem)).Fz = p
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Dyn))
	(*TMem)(unsafe.Pointer(pMem)).FxDel = __ccgo_fp(_sqlite3RowSetDelete)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return true if the Mem object contains a TEXT or BLOB that is
//	** too large - whose size exceeds SQLITE_MAX_LENGTH.
//	*/
func _sqlite3VdbeMemTooBig(tls *libc.TLS, p uintptr) (r int32) {
	var n int32
	_ = n
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 {
		n = (*TMem)(unsafe.Pointer(p)).Fn
		if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Zero) != 0 {
			n += *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(p)).Fu))
		}
		return libc.BoolInt32(n > *(*int32)(unsafe.Pointer((*TMem)(unsafe.Pointer(p)).Fdb + 120)))
	}
	return 0
}

// C documentation
//
//	/*
//	** Make an shallow copy of pFrom into pTo.  Prior contents of
//	** pTo are freed.  The pFrom->z field is not duplicated.  If
//	** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
//	** and flags gets srcType (either MEM_Ephem or MEM_Static).
//	*/
func _vdbeClrCopy(tls *libc.TLS, pTo uintptr, pFrom uintptr, eType int32) {
	_vdbeMemClearExternAndSetNull(tls, pTo)
	_sqlite3VdbeMemShallowCopy(tls, pTo, pFrom, eType)
}

func _sqlite3VdbeMemShallowCopy(tls *libc.TLS, pTo uintptr, pFrom uintptr, srcType int32) {
	var p1, p2 uintptr
	_, _ = p1, p2
	if int32((*TMem)(unsafe.Pointer(pTo)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
		_vdbeClrCopy(tls, pTo, pFrom, srcType)
		return
	}
	libc.Xmemcpy(tls, pTo, pFrom, uint32(libc.UintptrFromInt32(0)+20))
	if int32((*TMem)(unsafe.Pointer(pFrom)).Fflags)&int32(MEM_Static) == 0 {
		p1 = pTo + 16
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(MEM_Dyn) | libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_Ephem)))
		p2 = pTo + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | srcType)
	}
}

// C documentation
//
//	/*
//	** Make a full copy of pFrom into pTo.  Prior contents of pTo are
//	** freed before the copy is made.
//	*/
func _sqlite3VdbeMemCopy(tls *libc.TLS, pTo uintptr, pFrom uintptr) (r int32) {
	var rc int32
	var p1, p2 uintptr
	_, _, _ = rc, p1, p2
	rc = SQLITE_OK
	if int32((*TMem)(unsafe.Pointer(pTo)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
		_vdbeMemClearExternAndSetNull(tls, pTo)
	}
	libc.Xmemcpy(tls, pTo, pFrom, uint32(libc.UintptrFromInt32(0)+20))
	p1 = pTo + 16
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(MEM_Dyn))
	if int32((*TMem)(unsafe.Pointer(pTo)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 {
		if 0 == int32((*TMem)(unsafe.Pointer(pFrom)).Fflags)&int32(MEM_Static) {
			p2 = pTo + 16
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_Ephem))
			rc = _sqlite3VdbeMemMakeWriteable(tls, pTo)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Transfer the contents of pFrom to pTo. Any existing value in pTo is
//	** freed. If pFrom contains ephemeral data, a copy is made.
//	**
//	** pFrom contains an SQL NULL when this routine returns.
//	*/
func _sqlite3VdbeMemMove(tls *libc.TLS, pTo uintptr, pFrom uintptr) {
	_sqlite3VdbeMemRelease(tls, pTo)
	libc.Xmemcpy(tls, pTo, pFrom, uint32(40))
	(*TMem)(unsafe.Pointer(pFrom)).Fflags = uint16(MEM_Null)
	(*TMem)(unsafe.Pointer(pFrom)).FszMalloc = 0
}

// C documentation
//
//	/*
//	** Change the value of a Mem to be a string or a BLOB.
//	**
//	** The memory management strategy depends on the value of the xDel
//	** parameter. If the value passed is SQLITE_TRANSIENT, then the
//	** string is copied into a (possibly existing) buffer managed by the
//	** Mem structure. Otherwise, any existing buffer is freed and the
//	** pointer copied.
//	**
//	** If the string is too large (if it exceeds the SQLITE_LIMIT_LENGTH
//	** size limit) then no memory allocation occurs.  If the string can be
//	** stored without allocating memory, then it is.  If a memory allocation
//	** is required to store the string, then value of pMem is unchanged.  In
//	** either case, SQLITE_TOOBIG is returned.
//	**
//	** The "enc" parameter is the text encoding for the string, or zero
//	** to store a blob.
//	**
//	** If n is negative, then the string consists of all bytes up to but
//	** excluding the first zero character.  The n parameter must be
//	** non-negative for blobs.
//	*/
func _sqlite3VdbeMemSetStr(tls *libc.TLS, pMem uintptr, z uintptr, n Ti64, enc Tu8, xDel uintptr) (r int32) {
	var flags Tu16
	var iLimit, v2, v4 int32
	var nAlloc, nByte Ti64
	var v3 int64
	_, _, _, _, _, _, _ = flags, iLimit, nAlloc, nByte, v2, v3, v4
	nByte = n /* New value for pMem->flags */
	/* If z is a NULL pointer, set pMem to contain an SQL NULL. */
	if !(z != 0) {
		_sqlite3VdbeMemSetNull(tls, pMem)
		return SQLITE_OK
	}
	if (*TMem)(unsafe.Pointer(pMem)).Fdb != 0 {
		iLimit = *(*int32)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fdb + 120))
	} else {
		iLimit = int32(SQLITE_MAX_LENGTH)
	}
	if nByte < 0 {
		if int32(int32(enc)) == int32(SQLITE_UTF8) {
			nByte = int64(libc.Xstrlen(tls, z))
		} else {
			nByte = 0
			for {
				if !(nByte <= int64(int64(iLimit)) && int32(*(*int8)(unsafe.Pointer(z + uintptr(nByte))))|int32(*(*int8)(unsafe.Pointer(z + uintptr(nByte+int64(1))))) != 0) {
					break
				}
				goto _1
			_1:
				;
				nByte += int64(2)
			}
		}
		flags = uint16(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Term))
	} else {
		if int32(int32(enc)) == 0 {
			flags = uint16(MEM_Blob)
			enc = uint8(SQLITE_UTF8)
		} else {
			flags = uint16(MEM_Str)
		}
	}
	if nByte > int64(int64(iLimit)) {
		if xDel != 0 && xDel != uintptr(-libc.Int32FromInt32(1)) {
			if xDel == __ccgo_fp(_sqlite3OomClear) {
				_sqlite3DbFree(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, z)
			} else {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDel})))(tls, z)
			}
		}
		_sqlite3VdbeMemSetNull(tls, pMem)
		return _sqlite3ErrorToParser(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, int32(SQLITE_TOOBIG))
	}
	/* The following block sets the new values of Mem.z and Mem.xDel. It
	 ** also sets a flag in local variable "flags" to indicate the memory
	 ** management (one of MEM_Dyn or MEM_Static).
	 */
	if xDel == uintptr(-libc.Int32FromInt32(1)) {
		nAlloc = nByte
		if int32(int32(flags))&int32(MEM_Term) != 0 {
			if int32(int32(enc)) == int32(SQLITE_UTF8) {
				v2 = int32(1)
			} else {
				v2 = int32(2)
			}
			nAlloc += int64(v2)
		}
		if nAlloc > int64(libc.Int32FromInt32(32)) {
			v3 = nAlloc
		} else {
			v3 = int64(libc.Int32FromInt32(32))
		}
		if _sqlite3VdbeMemClearAndResize(tls, pMem, int32(v3)) != 0 {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, z, uint32(uint32(nAlloc)))
	} else {
		_sqlite3VdbeMemRelease(tls, pMem)
		(*TMem)(unsafe.Pointer(pMem)).Fz = z
		if xDel == __ccgo_fp(_sqlite3OomClear) {
			(*TMem)(unsafe.Pointer(pMem)).FzMalloc = (*TMem)(unsafe.Pointer(pMem)).Fz
			(*TMem)(unsafe.Pointer(pMem)).FszMalloc = _sqlite3DbMallocSize(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).FzMalloc)
		} else {
			(*TMem)(unsafe.Pointer(pMem)).FxDel = xDel
			if xDel == libc.UintptrFromInt32(0) {
				v4 = int32(MEM_Static)
			} else {
				v4 = int32(MEM_Dyn)
			}
			flags = Tu16(int32(flags) | v4)
		}
	}
	(*TMem)(unsafe.Pointer(pMem)).Fn = int32(nByte & libc.Int64FromInt32(0x7fffffff))
	(*TMem)(unsafe.Pointer(pMem)).Fflags = flags
	(*TMem)(unsafe.Pointer(pMem)).Fenc = enc
	if int32(int32(enc)) > int32(SQLITE_UTF8) && _sqlite3VdbeMemHandleBom(tls, pMem) != 0 {
		return int32(SQLITE_NOMEM)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Move data out of a btree key or data field and into a Mem structure.
//	** The data is payload from the entry that pCur is currently pointing
//	** to.  offset and amt determine what portion of the data or key to retrieve.
//	** The result is written into the pMem element.
//	**
//	** The pMem object must have been initialized.  This routine will use
//	** pMem->zMalloc to hold the content from the btree, if possible.  New
//	** pMem->zMalloc space will be allocated if necessary.  The calling routine
//	** is responsible for making sure that the pMem object is eventually
//	** destroyed.
//	**
//	** If this routine fails for any reason (malloc returns NULL or unable
//	** to read from the disk) then the pMem is left in an inconsistent state.
//	*/
func _sqlite3VdbeMemFromBtree(tls *libc.TLS, pCur uintptr, offset Tu32, amt Tu32, pMem uintptr) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Null)
	if _sqlite3BtreeMaxRecordSize(tls, pCur) < int64(offset+amt) {
		return _sqlite3CorruptError(tls, int32(84060))
	}
	v1 = _sqlite3VdbeMemClearAndResize(tls, pMem, int32(amt+uint32(1)))
	rc = v1
	if SQLITE_OK == v1 {
		rc = _sqlite3BtreePayload(tls, pCur, offset, amt, (*TMem)(unsafe.Pointer(pMem)).Fz)
		if rc == SQLITE_OK {
			*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr(amt))) = 0 /* Overrun area used when reading malformed records */
			(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Blob)
			(*TMem)(unsafe.Pointer(pMem)).Fn = int32(int32(amt))
		} else {
			_sqlite3VdbeMemRelease(tls, pMem)
		}
	}
	return rc
}

func _sqlite3VdbeMemFromBtreeZeroOffset(tls *libc.TLS, pCur uintptr, amt Tu32, pMem uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* available at bp+0 */ Tu32
	_ = rc
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(0) /* Number of bytes available on the local btree page */
	rc = SQLITE_OK                           /* Return code */
	/* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
	 ** that both the BtShared and database handle mutexes are held. */
	(*TMem)(unsafe.Pointer(pMem)).Fz = _sqlite3BtreePayloadFetch(tls, pCur, bp)
	if amt <= *(*Tu32)(unsafe.Pointer(bp)) {
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Ephem))
		(*TMem)(unsafe.Pointer(pMem)).Fn = int32(int32(amt))
	} else {
		rc = _sqlite3VdbeMemFromBtree(tls, pCur, uint32(0), amt, pMem)
	}
	return rc
}

// C documentation
//
//	/*
//	** The pVal argument is known to be a value other than NULL.
//	** Convert it into a string with encoding enc and return a pointer
//	** to a zero-terminated version of that string.
//	*/
func _valueToText(tls *libc.TLS, pVal uintptr, enc Tu8) (r uintptr) {
	var v1 int32
	var p2 uintptr
	_, _ = v1, p2
	if int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&(libc.Int32FromInt32(MEM_Blob)|libc.Int32FromInt32(MEM_Str)) != 0 {
		if int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&int32(MEM_Zero) != 0 {
			v1 = _sqlite3VdbeMemExpandBlob(tls, pVal)
		} else {
			v1 = 0
		}
		if v1 != 0 {
			return uintptr(0)
		}
		p2 = pVal + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_Str))
		if int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fenc) != int32(int32(enc)) & ^libc.Int32FromInt32(SQLITE_UTF16_ALIGNED) {
			_sqlite3VdbeChangeEncoding(tls, pVal, int32(int32(enc)) & ^libc.Int32FromInt32(SQLITE_UTF16_ALIGNED))
		}
		if int32(int32(enc))&int32(SQLITE_UTF16_ALIGNED) != 0 && int32(1) == int32(1)&int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fz) {
			if _sqlite3VdbeMemMakeWriteable(tls, pVal) != SQLITE_OK {
				return uintptr(0)
			}
		}
		_sqlite3VdbeMemNulTerminate(tls, pVal) /* IMP: R-31275-44060 */
	} else {
		_sqlite3VdbeMemStringify(tls, pVal, enc, uint8(0))
	}
	if int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fenc) == int32(int32(enc)) & ^libc.Int32FromInt32(SQLITE_UTF16_ALIGNED) {
		return (*Tsqlite3_value)(unsafe.Pointer(pVal)).Fz
	} else {
		return uintptr(0)
	}
	return r
}

// C documentation
//
//	/* This function is only available internally, it is not part of the
//	** external API. It works in a similar way to sqlite3_value_text(),
//	** except the data returned is in the encoding specified by the second
//	** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or
//	** SQLITE_UTF8.
//	**
//	** (2006-02-16:)  The enc value can be or-ed with SQLITE_UTF16_ALIGNED.
//	** If that is the case, then the result must be aligned on an even byte
//	** boundary.
//	*/
func _sqlite3ValueText(tls *libc.TLS, pVal uintptr, enc Tu8) (r uintptr) {
	if !(pVal != 0) {
		return uintptr(0)
	}
	if int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Term)) == libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Term) && int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fenc) == int32(int32(enc)) {
		return (*Tsqlite3_value)(unsafe.Pointer(pVal)).Fz
	}
	if int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&int32(MEM_Null) != 0 {
		return uintptr(0)
	}
	return _valueToText(tls, pVal, enc)
}

// C documentation
//
//	/* Return true if sqlit3_value object pVal is a string or blob value
//	** that uses the destructor specified in the second argument.
//	**
//	** TODO:  Maybe someday promote this interface into a published API so
//	** that third-party extensions can get access to it?
//	*/
func _sqlite3ValueIsOfClass(tls *libc.TLS, pVal uintptr, xFree uintptr) (r int32) {
	if pVal != uintptr(0) && int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 && int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&int32(MEM_Dyn) != 0 && (*Tsqlite3_value)(unsafe.Pointer(pVal)).FxDel == xFree {
		return int32(1)
	} else {
		return 0
	}
	return r
}

// C documentation
//
//	/*
//	** Create a new sqlite3_value object.
//	*/
func _sqlite3ValueNew(tls *libc.TLS, db uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3DbMallocZero(tls, db, uint64(40))
	if p != 0 {
		(*TMem)(unsafe.Pointer(p)).Fflags = uint16(MEM_Null)
		(*TMem)(unsafe.Pointer(p)).Fdb = db
	}
	return p
}

/*
** Context object passed by sqlite3Stat4ProbeSetValue() through to
** valueNew(). See comments above valueNew() for details.
 */
type TValueNewStat4Ctx = struct {
	FpParse uintptr
	FpIdx   uintptr
	FppRec  uintptr
	FiVal   int32
}

type ValueNewStat4Ctx = TValueNewStat4Ctx

// C documentation
//
//	/*
//	** Allocate and return a pointer to a new sqlite3_value object. If
//	** the second argument to this function is NULL, the object is allocated
//	** by calling sqlite3ValueNew().
//	**
//	** Otherwise, if the second argument is non-zero, then this function is
//	** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not
//	** already been allocated, allocate the UnpackedRecord structure that
//	** that function will return to its caller here. Then return a pointer to
//	** an sqlite3_value within the UnpackedRecord.a[] array.
//	*/
func _valueNew(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	var i, nByte, nCol int32
	var pIdx, pRec uintptr
	_, _, _, _, _ = i, nByte, nCol, pIdx, pRec
	if p != 0 {
		pRec = *(*uintptr)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(p)).FppRec))
		if pRec == uintptr(0) {
			pIdx = (*TValueNewStat4Ctx)(unsafe.Pointer(p)).FpIdx   /* Counter variable */
			nCol = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) /* Number of index columns including rowid */
			nByte = int32(uint32(40)*uint32(uint32(nCol)) + (libc.Uint32FromInt64(32)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
			pRec = _sqlite3DbMallocZero(tls, db, uint64(uint64(nByte)))
			if pRec != 0 {
				(*TUnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo = _sqlite3KeyInfoOfIndex(tls, (*TValueNewStat4Ctx)(unsafe.Pointer(p)).FpParse, pIdx)
				if (*TUnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo != 0 {
					(*TUnpackedRecord)(unsafe.Pointer(pRec)).FaMem = pRec + uintptr((libc.Uint32FromInt64(32)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
					i = 0
					for {
						if !(i < nCol) {
							break
						}
						(*(*TMem)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(pRec)).FaMem + uintptr(i)*40))).Fflags = uint16(MEM_Null)
						(*(*TMem)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(pRec)).FaMem + uintptr(i)*40))).Fdb = db
						goto _1
					_1:
						;
						i++
					}
				} else {
					_sqlite3DbFreeNN(tls, db, pRec)
					pRec = uintptr(0)
				}
			}
			if pRec == uintptr(0) {
				return uintptr(0)
			}
			*(*uintptr)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(p)).FppRec)) = pRec
		}
		(*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField = uint16((*TValueNewStat4Ctx)(unsafe.Pointer(p)).FiVal + int32(1))
		_sqlite3VdbeMemSetNull(tls, (*TUnpackedRecord)(unsafe.Pointer(pRec)).FaMem+uintptr((*TValueNewStat4Ctx)(unsafe.Pointer(p)).FiVal)*40)
		return (*TUnpackedRecord)(unsafe.Pointer(pRec)).FaMem + uintptr((*TValueNewStat4Ctx)(unsafe.Pointer(p)).FiVal)*40
	}
	return _sqlite3ValueNew(tls, db)
}

// C documentation
//
//	/*
//	** The expression object indicated by the second argument is guaranteed
//	** to be a scalar SQL function. If
//	**
//	**   * all function arguments are SQL literals,
//	**   * one of the SQLITE_FUNC_CONSTANT or _SLOCHNG function flags is set, and
//	**   * the SQLITE_FUNC_NEEDCOLL function flag is not set,
//	**
//	** then this routine attempts to invoke the SQL function. Assuming no
//	** error occurs, output parameter (*ppVal) is set to point to a value
//	** object containing the result before returning SQLITE_OK.
//	**
//	** Affinity aff is applied to the result of the function before returning.
//	** If the result is a text value, the sqlite3_value object uses encoding
//	** enc.
//	**
//	** If the conditions above are not met, this function returns SQLITE_OK
//	** and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to
//	** NULL and an SQLite error code returned.
//	*/
func _valueFromFunction(tls *libc.TLS, db uintptr, p uintptr, enc Tu8, aff Tu8, ppVal uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var apVal, pFunc, pList, pVal uintptr
	var i, nVal, rc int32
	var _ /* ctx at bp+0 */ Tsqlite3_context
	_, _, _, _, _, _, _ = apVal, i, nVal, pFunc, pList, pVal, rc /* Context object for function invocation */
	apVal = uintptr(0)                                           /* Function arguments */
	nVal = 0                                                     /* Size of apVal[] array */
	pFunc = uintptr(0)                                           /* Function definition */
	pVal = uintptr(0)                                            /* New value */
	rc = SQLITE_OK                                               /* Return code */
	pList = uintptr(0)                                           /* Iterator variable */
	pList = *(*uintptr)(unsafe.Pointer(p + 20))
	if pList != 0 {
		nVal = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	}
	pFunc = _sqlite3FindFunction(tls, db, *(*uintptr)(unsafe.Pointer(p + 8)), nVal, enc, uint8(0))
	if (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)|libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG)) == uint32(0) || (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)|libc.Int32FromInt32(SQLITE_FUNC_RUNONLY)) != uint32(0) {
		return SQLITE_OK
	}
	if pList != 0 {
		apVal = _sqlite3DbMallocZero(tls, db, uint64(uint32(4)*uint32(uint32(nVal))))
		if apVal == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
			goto value_from_function_out
		}
		i = 0
		for {
			if !(i < nVal) {
				break
			}
			rc = _sqlite3ValueFromExpr(tls, db, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr, enc, aff, apVal+uintptr(i)*4)
			if *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4)) == uintptr(0) || rc != SQLITE_OK {
				goto value_from_function_out
			}
			goto _1
		_1:
			;
			i++
		}
	}
	pVal = _valueNew(tls, db, pCtx)
	if pVal == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
		goto value_from_function_out
	}
	libc.Xmemset(tls, bp, 0, uint32(32))
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpOut = pVal
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).FpFunc = pFunc
	(*(*Tsqlite3_context)(unsafe.Pointer(bp))).Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
	(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer(pFunc)).FxSFunc})))(tls, bp, nVal, apVal)
	if (*(*Tsqlite3_context)(unsafe.Pointer(bp))).FisError != 0 {
		rc = (*(*Tsqlite3_context)(unsafe.Pointer(bp))).FisError
		_sqlite3ErrorMsg(tls, (*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse, __ccgo_ts+4709, libc.VaList(bp+40, Xsqlite3_value_text(tls, pVal)))
	} else {
		_sqlite3ValueApplyAffinity(tls, pVal, aff, uint8(SQLITE_UTF8))
		rc = _sqlite3VdbeChangeEncoding(tls, pVal, int32(int32(enc)))
		if rc == SQLITE_OK && _sqlite3VdbeMemTooBig(tls, pVal) != 0 {
			rc = int32(SQLITE_TOOBIG)
			(*TParse)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).FnErr++
		}
	}
	goto value_from_function_out
value_from_function_out:
	;
	if rc != SQLITE_OK {
		pVal = uintptr(0)
		(*TParse)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).Frc = rc
	}
	if apVal != 0 {
		i = 0
		for {
			if !(i < nVal) {
				break
			}
			_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4)))
			goto _2
		_2:
			;
			i++
		}
		_sqlite3DbFreeNN(tls, db, apVal)
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = pVal
	return rc
}

// C documentation
//
//	/*
//	** Extract a value from the supplied expression in the manner described
//	** above sqlite3ValueFromExpr(). Allocate the sqlite3_value object
//	** using valueNew().
//	**
//	** If pCtx is NULL and an error occurs after the sqlite3_value object
//	** has been allocated, it is freed before returning. Or, if pCtx is not
//	** NULL, it is assumed that the caller will free any allocated object
//	** in all cases.
//	*/
func _valueFromExpr(tls *libc.TLS, db uintptr, pExpr uintptr, enc Tu8, affinity Tu8, ppVal uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aff Tu8
	var nVal, negInt, op, rc, v1, v2 int32
	var pLeft, zNeg, zVal, p3 uintptr
	var _ /* iVal at bp+8 */ Ti64
	var _ /* pVal at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = aff, nVal, negInt, op, pLeft, rc, zNeg, zVal, v1, v2, p3
	zVal = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	negInt = int32(1)
	zNeg = __ccgo_ts + 1672
	rc = SQLITE_OK
	for {
		v1 = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop)
		op = v1
		if !(v1 == int32(TK_UPLUS) || op == int32(TK_SPAN)) {
			break
		}
		pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	}
	if op == int32(TK_REGISTER) {
		op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2)
	}
	/* Compressed expressions only appear when parsing the DEFAULT clause
	 ** on a table column definition, and hence only when pCtx==0.  This
	 ** check ensures that an EP_TokenOnly expression is never passed down
	 ** into valueFromFunction(). */
	if op == int32(TK_CAST) {
		aff = uint8(_sqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0)))
		rc = _valueFromExpr(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, enc, aff, ppVal, pCtx)
		if *(*uintptr)(unsafe.Pointer(ppVal)) != 0 {
			if int32((*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppVal)))).Fflags)&int32(MEM_Zero) != 0 {
				v2 = _sqlite3VdbeMemExpandBlob(tls, *(*uintptr)(unsafe.Pointer(ppVal)))
			} else {
				v2 = 0
			}
			rc = v2
			_sqlite3VdbeMemCast(tls, *(*uintptr)(unsafe.Pointer(ppVal)), aff, enc)
			_sqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(ppVal)), affinity, enc)
		}
		return rc
	}
	/* Handle negative integers in a single step.  This is needed in the
	 ** case when the value is -9223372036854775808. Except - do not do this
	 ** for hexadecimal literals.  */
	if op == int32(TK_UMINUS) {
		pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		if int32((*TExpr)(unsafe.Pointer(pLeft)).Fop) == int32(TK_INTEGER) || int32((*TExpr)(unsafe.Pointer(pLeft)).Fop) == int32(TK_FLOAT) {
			if (*TExpr)(unsafe.Pointer(pLeft)).Fflags&uint32(libc.Int32FromInt32(EP_IntValue)) != uint32(0) || int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 8))))) != int32('0') || int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 8)) + 1))) & ^libc.Int32FromInt32(0x20) != int32('X') {
				pExpr = pLeft
				op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop)
				negInt = -int32(1)
				zNeg = __ccgo_ts + 6447
			}
		}
	}
	if op == int32(TK_STRING) || op == int32(TK_FLOAT) || op == int32(TK_INTEGER) {
		*(*uintptr)(unsafe.Pointer(bp)) = _valueNew(tls, db, pCtx)
		if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
			goto no_mem
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_IntValue)) != uint32(0) {
			_sqlite3VdbeMemSetInt64(tls, *(*uintptr)(unsafe.Pointer(bp)), int64(*(*int32)(unsafe.Pointer(pExpr + 8)))*int64(int64(negInt)))
		} else {
			if op == int32(TK_INTEGER) && 0 == _sqlite3DecOrHexToI64(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), bp+8) {
				_sqlite3VdbeMemSetInt64(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*Ti64)(unsafe.Pointer(bp + 8))*int64(int64(negInt)))
			} else {
				zVal = _sqlite3MPrintf(tls, db, __ccgo_ts+6449, libc.VaList(bp+24, zNeg, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
				if zVal == uintptr(0) {
					goto no_mem
				}
				_sqlite3ValueSetStr(tls, *(*uintptr)(unsafe.Pointer(bp)), -int32(1), zVal, uint8(SQLITE_UTF8), __ccgo_fp(_sqlite3OomClear))
			}
		}
		if int32(int32(affinity)) == int32(SQLITE_AFF_BLOB) {
			if op == int32(TK_FLOAT) {
				_sqlite3AtoF(tls, (*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fz, *(*uintptr)(unsafe.Pointer(bp)), (*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fn, uint8(SQLITE_UTF8))
				(*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags = uint16(MEM_Real)
			} else {
				if op == int32(TK_INTEGER) {
					/* This case is required by -9223372036854775808 and other strings
					 ** that look like integers but cannot be handled by the
					 ** sqlite3DecOrHexToI64() call above.  */
					_sqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp)), uint8(SQLITE_AFF_NUMERIC), uint8(SQLITE_UTF8))
				}
			}
		} else {
			_sqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp)), affinity, uint8(SQLITE_UTF8))
		}
		if int32((*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Real)) != 0 {
			p3 = *(*uintptr)(unsafe.Pointer(bp)) + 16
			*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(MEM_Str))
		}
		if int32(int32(enc)) != int32(SQLITE_UTF8) {
			rc = _sqlite3VdbeChangeEncoding(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(int32(enc)))
		}
	} else {
		if op == int32(TK_UMINUS) {
			/* This branch happens for multiple negative signs.  Ex: -(-5) */
			if SQLITE_OK == _valueFromExpr(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, enc, affinity, bp, pCtx) && *(*uintptr)(unsafe.Pointer(bp)) != uintptr(0) {
				_sqlite3VdbeMemNumerify(tls, *(*uintptr)(unsafe.Pointer(bp)))
				if int32((*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags)&int32(MEM_Real) != 0 {
					*(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) = -*(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))
				} else {
					if *(*Ti64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
						*(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) = -float64(int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
						(*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags = uint16(int32((*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Real))
					} else {
						*(*Ti64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) = -*(*Ti64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))
					}
				}
				_sqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp)), affinity, enc)
			}
		} else {
			if op == int32(TK_NULL) {
				*(*uintptr)(unsafe.Pointer(bp)) = _valueNew(tls, db, pCtx)
				if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
					goto no_mem
				}
				_sqlite3VdbeMemSetNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
			} else {
				if op == int32(TK_BLOB) {
					*(*uintptr)(unsafe.Pointer(bp)) = _valueNew(tls, db, pCtx)
					if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
						goto no_mem
					}
					zVal = *(*uintptr)(unsafe.Pointer(pExpr + 8)) + 2
					nVal = _sqlite3Strlen30(tls, zVal) - int32(1)
					_sqlite3VdbeMemSetStr(tls, *(*uintptr)(unsafe.Pointer(bp)), _sqlite3HexToBlob(tls, db, zVal, nVal), int64(nVal/int32(2)), uint8(0), __ccgo_fp(_sqlite3OomClear))
				} else {
					if op == int32(TK_FUNCTION) && pCtx != uintptr(0) {
						rc = _valueFromFunction(tls, db, pExpr, enc, affinity, bp, pCtx)
					} else {
						if op == int32(TK_TRUEFALSE) {
							*(*uintptr)(unsafe.Pointer(bp)) = _valueNew(tls, db, pCtx)
							if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
								(*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags = uint16(MEM_Int)
								*(*Ti64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) = libc.BoolInt64(int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 8)) + 4))) == 0)
								_sqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp)), affinity, enc)
							}
						}
					}
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
	goto no_mem
no_mem:
	;
	if pCtx == uintptr(0) || (*TParse)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).FnErr == 0 {
		_sqlite3OomFault(tls, db)
	}
	_sqlite3DbFree(tls, db, zVal)
	if pCtx == uintptr(0) {
		_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return int32(SQLITE_NOMEM)
}

// C documentation
//
//	/*
//	** Create a new sqlite3_value object, containing the value of pExpr.
//	**
//	** This only works for very simple expressions that consist of one constant
//	** token (i.e. "5", "5.1", "'a string'"). If the expression can
//	** be converted directly into a value, then the value is allocated and
//	** a pointer written to *ppVal. The caller is responsible for deallocating
//	** the value by passing it to sqlite3ValueFree() later on. If the expression
//	** cannot be converted to a value, then *ppVal is set to NULL.
//	*/
func _sqlite3ValueFromExpr(tls *libc.TLS, db uintptr, pExpr uintptr, enc Tu8, affinity Tu8, ppVal uintptr) (r int32) {
	var v1 int32
	_ = v1
	if pExpr != 0 {
		v1 = _valueFromExpr(tls, db, pExpr, enc, affinity, ppVal, uintptr(0))
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Attempt to extract a value from pExpr and use it to construct *ppVal.
//	**
//	** If pAlloc is not NULL, then an UnpackedRecord object is created for
//	** pAlloc if one does not exist and the new value is added to the
//	** UnpackedRecord object.
//	**
//	** A value is extracted in the following cases:
//	**
//	**  * (pExpr==0). In this case the value is assumed to be an SQL NULL,
//	**
//	**  * The expression is a bound variable, and this is a reprepare, or
//	**
//	**  * The expression is a literal value.
//	**
//	** On success, *ppVal is made to point to the extracted value.  The caller
//	** is responsible for ensuring that the value is eventually freed.
//	*/
func _stat4ValueFromExpr(tls *libc.TLS, pParse uintptr, pExpr uintptr, affinity Tu8, pAlloc uintptr, ppVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, v, v1 uintptr
	var iBindVar, rc int32
	var _ /* pVal at bp+0 */ uintptr
	_, _, _, _, _ = db, iBindVar, rc, v, v1
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Skip over any TK_COLLATE nodes */
	pExpr = _sqlite3ExprSkipCollate(tls, pExpr)
	if !(pExpr != 0) {
		*(*uintptr)(unsafe.Pointer(bp)) = _valueNew(tls, db, pAlloc)
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			_sqlite3VdbeMemSetNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	} else {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VARIABLE) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableQPSG) == uint64(0) {
			iBindVar = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
			_sqlite3VdbeSetVarmask(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, iBindVar)
			v1 = (*TParse)(unsafe.Pointer(pParse)).FpReprepare
			v = v1
			if v1 != uintptr(0) {
				*(*uintptr)(unsafe.Pointer(bp)) = _valueNew(tls, db, pAlloc)
				if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
					rc = _sqlite3VdbeMemCopy(tls, *(*uintptr)(unsafe.Pointer(bp)), (*TVdbe)(unsafe.Pointer(v)).FaVar+uintptr(iBindVar-int32(1))*40)
					_sqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp)), affinity, (*Tsqlite3)(unsafe.Pointer(db)).Fenc)
					(*Tsqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fdb = (*TParse)(unsafe.Pointer(pParse)).Fdb
				}
			}
		} else {
			rc = _valueFromExpr(tls, db, pExpr, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, affinity, bp, pAlloc)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

// C documentation
//
//	/*
//	** This function is used to allocate and populate UnpackedRecord
//	** structures intended to be compared against sample index keys stored
//	** in the sqlite_stat4 table.
//	**
//	** A single call to this function populates zero or more fields of the
//	** record starting with field iVal (fields are numbered from left to
//	** right starting with 0). A single field is populated if:
//	**
//	**  * (pExpr==0). In this case the value is assumed to be an SQL NULL,
//	**
//	**  * The expression is a bound variable, and this is a reprepare, or
//	**
//	**  * The sqlite3ValueFromExpr() function is able to extract a value
//	**    from the expression (i.e. the expression is a literal value).
//	**
//	** Or, if pExpr is a TK_VECTOR, one field is populated for each of the
//	** vector components that match either of the two latter criteria listed
//	** above.
//	**
//	** Before any value is appended to the record, the affinity of the
//	** corresponding column within index pIdx is applied to it. Before
//	** this function returns, output parameter *pnExtract is set to the
//	** number of values appended to the record.
//	**
//	** When this function is called, *ppRec must either point to an object
//	** allocated by an earlier call to this function, or must be NULL. If it
//	** is NULL and a value can be successfully extracted, a new UnpackedRecord
//	** is allocated (and *ppRec set to point to it) before returning.
//	**
//	** Unless an error is encountered, SQLITE_OK is returned. It is not an
//	** error if a value cannot be extracted from pExpr. If an error does
//	** occur, an SQLite error code is returned.
//	*/
func _sqlite3Stat4ProbeSetValue(tls *libc.TLS, pParse uintptr, pIdx uintptr, ppRec uintptr, pExpr uintptr, nElem int32, iVal int32, pnExtract uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aff Tu8
	var i, nExtract, rc int32
	var pElem, v2 uintptr
	var _ /* alloc at bp+0 */ TValueNewStat4Ctx
	var _ /* pVal at bp+16 */ uintptr
	_, _, _, _, _, _ = aff, i, nExtract, pElem, rc, v2
	rc = SQLITE_OK
	nExtract = 0
	if pExpr == uintptr(0) || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_SELECT) {
		(*(*TValueNewStat4Ctx)(unsafe.Pointer(bp))).FpParse = pParse
		(*(*TValueNewStat4Ctx)(unsafe.Pointer(bp))).FpIdx = pIdx
		(*(*TValueNewStat4Ctx)(unsafe.Pointer(bp))).FppRec = ppRec
		i = 0
		for {
			if !(i < nElem) {
				break
			}
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
			if pExpr != 0 {
				v2 = _sqlite3VectorFieldSubexpr(tls, pExpr, i)
			} else {
				v2 = uintptr(0)
			}
			pElem = v2
			aff = uint8(_sqlite3IndexColumnAffinity(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pIdx, iVal+i))
			(*(*TValueNewStat4Ctx)(unsafe.Pointer(bp))).FiVal = iVal + i
			rc = _stat4ValueFromExpr(tls, pParse, pElem, aff, bp, bp+16)
			if !(*(*uintptr)(unsafe.Pointer(bp + 16)) != 0) {
				break
			}
			nExtract++
			goto _1
		_1:
			;
			i++
		}
	}
	*(*int32)(unsafe.Pointer(pnExtract)) = nExtract
	return rc
}

// C documentation
//
//	/*
//	** Attempt to extract a value from expression pExpr using the methods
//	** as described for sqlite3Stat4ProbeSetValue() above.
//	**
//	** If successful, set *ppVal to point to a new value object and return
//	** SQLITE_OK. If no value can be extracted, but no other error occurs
//	** (e.g. OOM), return SQLITE_OK and set *ppVal to NULL. Or, if an error
//	** does occur, return an SQLite error code. The final value of *ppVal
//	** is undefined in this case.
//	*/
func _sqlite3Stat4ValueFromExpr(tls *libc.TLS, pParse uintptr, pExpr uintptr, affinity Tu8, ppVal uintptr) (r int32) {
	return _stat4ValueFromExpr(tls, pParse, pExpr, affinity, uintptr(0), ppVal)
}

// C documentation
//
//	/*
//	** Extract the iCol-th column from the nRec-byte record in pRec.  Write
//	** the column value into *ppVal.  If *ppVal is initially NULL then a new
//	** sqlite3_value object is allocated.
//	**
//	** If *ppVal is initially NULL then the caller is responsible for
//	** ensuring that the value written into *ppVal is eventually freed.
//	*/
func _sqlite3Stat4Column(tls *libc.TLS, db uintptr, pRec uintptr, nRec int32, iCol int32, ppVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, pMem, v4 uintptr
	var i, v1, v3 int32
	var iField Ti64
	var iHdr, szField Tu32
	var _ /* nHdr at bp+4 */ Tu32
	var _ /* t at bp+0 */ Tu32
	_, _, _, _, _, _, _, _, _ = a, i, iField, iHdr, pMem, szField, v1, v3, v4
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)  /* Next unread data byte */
	szField = uint32(0)                       /* Column index */
	a = pRec                                  /* Typecast byte array */
	pMem = *(*uintptr)(unsafe.Pointer(ppVal)) /* Write result into this Mem object */
	if int32(*(*Tu8)(unsafe.Pointer(a))) < int32(libc.Uint8FromInt32(0x80)) {
		*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(*(*Tu8)(unsafe.Pointer(a)))
		v1 = libc.Int32FromInt32(1)
	} else {
		v1 = int32(_sqlite3GetVarint32(tls, a, bp+4))
	}
	iHdr = uint32(uint8(v1))
	if *(*Tu32)(unsafe.Pointer(bp + 4)) > uint32(uint32(nRec)) || iHdr >= *(*Tu32)(unsafe.Pointer(bp + 4)) {
		return _sqlite3CorruptError(tls, int32(84745))
	}
	iField = int64(*(*Tu32)(unsafe.Pointer(bp + 4)))
	i = 0
	for {
		if !(i <= iCol) {
			break
		}
		if int32(*(*Tu8)(unsafe.Pointer(a + uintptr(iHdr)))) < int32(libc.Uint8FromInt32(0x80)) {
			*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(a + uintptr(iHdr))))
			v3 = libc.Int32FromInt32(1)
		} else {
			v3 = int32(_sqlite3GetVarint32(tls, a+uintptr(iHdr), bp))
		}
		iHdr += uint32(uint8(v3))
		if iHdr > *(*Tu32)(unsafe.Pointer(bp + 4)) {
			return _sqlite3CorruptError(tls, int32(84751))
		}
		szField = _sqlite3VdbeSerialTypeLen(tls, *(*Tu32)(unsafe.Pointer(bp)))
		iField += int64(int64(szField))
		goto _2
	_2:
		;
		i++
	}
	if iField > int64(int64(nRec)) {
		return _sqlite3CorruptError(tls, int32(84757))
	}
	if pMem == uintptr(0) {
		v4 = _sqlite3ValueNew(tls, db)
		*(*uintptr)(unsafe.Pointer(ppVal)) = v4
		pMem = v4
		if pMem == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
	}
	_sqlite3VdbeSerialGet(tls, a+uintptr(iField-int64(int64(szField))), *(*Tu32)(unsafe.Pointer(bp)), pMem)
	(*TMem)(unsafe.Pointer(pMem)).Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Unless it is NULL, the argument must be an UnpackedRecord object returned
//	** by an earlier call to sqlite3Stat4ProbeSetValue(). This call deletes
//	** the object.
//	*/
func _sqlite3Stat4ProbeFree(tls *libc.TLS, pRec uintptr) {
	var aMem, db uintptr
	var i, nCol int32
	_, _, _, _ = aMem, db, i, nCol
	if pRec != 0 {
		nCol = int32((*TKeyInfo)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo)).FnAllField)
		aMem = (*TUnpackedRecord)(unsafe.Pointer(pRec)).FaMem
		db = (*(*TMem)(unsafe.Pointer(aMem))).Fdb
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			_sqlite3VdbeMemRelease(tls, aMem+uintptr(i)*40)
			goto _1
		_1:
			;
			i++
		}
		_sqlite3KeyInfoUnref(tls, (*TUnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo)
		_sqlite3DbFreeNN(tls, db, pRec)
	}
}

// C documentation
//
//	/*
//	** Change the string value of an sqlite3_value object
//	*/
func _sqlite3ValueSetStr(tls *libc.TLS, v uintptr, n int32, z uintptr, enc Tu8, xDel uintptr) {
	if v != 0 {
		_sqlite3VdbeMemSetStr(tls, v, z, int64(int64(n)), enc, xDel)
	}
}

// C documentation
//
//	/*
//	** Free an sqlite3_value object
//	*/
func _sqlite3ValueFree(tls *libc.TLS, v uintptr) {
	if !(v != 0) {
		return
	}
	_sqlite3VdbeMemRelease(tls, v)
	_sqlite3DbFreeNN(tls, (*TMem)(unsafe.Pointer(v)).Fdb, v)
}

// C documentation
//
//	/*
//	** The sqlite3ValueBytes() routine returns the number of bytes in the
//	** sqlite3_value object assuming that it uses the encoding "enc".
//	** The valueBytes() routine is a helper function.
//	*/
func _valueBytes(tls *libc.TLS, pVal uintptr, enc Tu8) (r int32) {
	var v1 int32
	_ = v1
	if _valueToText(tls, pVal, enc) != uintptr(0) {
		v1 = (*Tsqlite3_value)(unsafe.Pointer(pVal)).Fn
	} else {
		v1 = 0
	}
	return v1
}

func _sqlite3ValueBytes(tls *libc.TLS, pVal uintptr, enc Tu8) (r int32) {
	var p uintptr
	_ = p
	p = pVal
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Str) != 0 && int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fenc) == int32(int32(enc)) {
		return (*TMem)(unsafe.Pointer(p)).Fn
	}
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Str) != 0 && int32(int32(enc)) != int32(SQLITE_UTF8) && int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fenc) != int32(SQLITE_UTF8) {
		return (*TMem)(unsafe.Pointer(p)).Fn
	}
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Blob) != 0 {
		if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Zero) != 0 {
			return (*TMem)(unsafe.Pointer(p)).Fn + *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(p)).Fu))
		} else {
			return (*TMem)(unsafe.Pointer(p)).Fn
		}
	}
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Null) != 0 {
		return 0
	}
	return _valueBytes(tls, pVal, enc)
}

// C documentation
//
//	/*
//	** Create a new virtual database engine.
//	*/
func _sqlite3VdbeCreate(tls *libc.TLS, pParse uintptr) (r uintptr) {
	var db, p uintptr
	_, _ = db, p
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	p = _sqlite3DbMallocRawNN(tls, db, uint64(232))
	if p == uintptr(0) {
		return uintptr(0)
	}
	libc.Xmemset(tls, p+104, 0, libc.Uint32FromInt64(232)-uint32(libc.UintptrFromInt32(0)+104))
	(*TVdbe)(unsafe.Pointer(p)).Fdb = db
	if (*Tsqlite3)(unsafe.Pointer(db)).FpVdbe != 0 {
		(*TVdbe1)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpVdbe)).FppVPrev = p + 8
	}
	(*TVdbe)(unsafe.Pointer(p)).FpVNext = (*Tsqlite3)(unsafe.Pointer(db)).FpVdbe
	(*TVdbe)(unsafe.Pointer(p)).FppVPrev = db + 4
	(*Tsqlite3)(unsafe.Pointer(db)).FpVdbe = p
	(*TVdbe)(unsafe.Pointer(p)).FpParse = pParse
	(*TParse)(unsafe.Pointer(pParse)).FpVdbe = p
	_sqlite3VdbeAddOp2(tls, p, int32(OP_Init), 0, int32(1))
	return p
}

// C documentation
//
//	/*
//	** Return the Parse object that owns a Vdbe object.
//	*/
func _sqlite3VdbeParser(tls *libc.TLS, p uintptr) (r uintptr) {
	return (*TVdbe)(unsafe.Pointer(p)).FpParse
}

// C documentation
//
//	/*
//	** Change the error string stored in Vdbe.zErrMsg
//	*/
func _sqlite3VdbeError(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Tva_list
	_ = ap
	_sqlite3DbFree(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg)
	ap = va
	(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = _sqlite3VMPrintf(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, zFormat, ap)
	_ = ap
}

// C documentation
//
//	/*
//	** Remember the SQL string for a prepared statement.
//	*/
func _sqlite3VdbeSetSql(tls *libc.TLS, p uintptr, z uintptr, n int32, prepFlags Tu8) {
	if p == uintptr(0) {
		return
	}
	(*TVdbe)(unsafe.Pointer(p)).FprepFlags = prepFlags
	if int32(int32(prepFlags))&int32(SQLITE_PREPARE_SAVESQL) == 0 {
		(*TVdbe)(unsafe.Pointer(p)).Fexpmask = uint32(0)
	}
	(*TVdbe)(unsafe.Pointer(p)).FzSql = _sqlite3DbStrNDup(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, z, uint64(uint64(n)))
}

// C documentation
//
//	/*
//	** Swap byte-code between two VDBE structures.
//	**
//	** This happens after pB was previously run and returned
//	** SQLITE_SCHEMA.  The statement was then reprepared in pA.
//	** This routine transfers the new bytecode in pA over to pB
//	** so that pB can be run again.  The old pB byte code is
//	** moved back to pA so that it will be cleaned up when pA is
//	** finalized.
//	*/
func _sqlite3VdbeSwap(tls *libc.TLS, pA uintptr, pB uintptr) {
	var pTmp, ppTmp, zTmp uintptr
	var tmp TVdbe
	_, _, _, _ = pTmp, ppTmp, tmp, zTmp
	tmp = *(*TVdbe)(unsafe.Pointer(pA))
	*(*TVdbe)(unsafe.Pointer(pA)) = *(*TVdbe)(unsafe.Pointer(pB))
	*(*TVdbe)(unsafe.Pointer(pB)) = tmp
	pTmp = (*TVdbe)(unsafe.Pointer(pA)).FpVNext
	(*TVdbe)(unsafe.Pointer(pA)).FpVNext = (*TVdbe)(unsafe.Pointer(pB)).FpVNext
	(*TVdbe)(unsafe.Pointer(pB)).FpVNext = pTmp
	ppTmp = (*TVdbe)(unsafe.Pointer(pA)).FppVPrev
	(*TVdbe)(unsafe.Pointer(pA)).FppVPrev = (*TVdbe)(unsafe.Pointer(pB)).FppVPrev
	(*TVdbe)(unsafe.Pointer(pB)).FppVPrev = ppTmp
	zTmp = (*TVdbe)(unsafe.Pointer(pA)).FzSql
	(*TVdbe)(unsafe.Pointer(pA)).FzSql = (*TVdbe)(unsafe.Pointer(pB)).FzSql
	(*TVdbe)(unsafe.Pointer(pB)).FzSql = zTmp
	(*TVdbe)(unsafe.Pointer(pB)).Fexpmask = (*TVdbe)(unsafe.Pointer(pA)).Fexpmask
	(*TVdbe)(unsafe.Pointer(pB)).FprepFlags = (*TVdbe)(unsafe.Pointer(pA)).FprepFlags
	libc.Xmemcpy(tls, pB+164, pA+164, uint32(36))
	*(*Tu32)(unsafe.Pointer(pB + 164 + 5*4))++
}

// C documentation
//
//	/*
//	** Resize the Vdbe.aOp array so that it is at least nOp elements larger
//	** than its current size. nOp is guaranteed to be less than or equal
//	** to 1024/sizeof(Op).
//	**
//	** If an out-of-memory error occurs while resizing the array, return
//	** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
//	** unchanged (this is so that any opcodes already allocated can be
//	** correctly deallocated along with the rest of the Vdbe).
//	*/
func _growOpArray(tls *libc.TLS, v uintptr, nOp int32) (r int32) {
	var nNew Tsqlite3_int64
	var p, pNew uintptr
	var v1 int64
	var v2 int32
	_, _, _, _, _ = nNew, p, pNew, v1, v2
	p = (*TVdbe)(unsafe.Pointer(v)).FpParse
	if (*TVdbe)(unsafe.Pointer(v)).FnOpAlloc != 0 {
		v1 = int64(2) * int64((*TVdbe)(unsafe.Pointer(v)).FnOpAlloc)
	} else {
		v1 = int64(libc.Uint32FromInt32(1024) / libc.Uint32FromInt64(20))
	}
	/* The SQLITE_TEST_REALLOC_STRESS compile-time option is designed to force
	 ** more frequent reallocs and hence provide more opportunities for
	 ** simulated OOM faults.  SQLITE_TEST_REALLOC_STRESS is generally used
	 ** during testing only.  With SQLITE_TEST_REALLOC_STRESS grow the op array
	 ** by the minimum* amount required until the size reaches 512.  Normal
	 ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
	 ** size of the op array or add 1KB of space, whichever is smaller. */
	nNew = v1
	_ = nOp
	/* Ensure that the size of a VDBE does not grow too large */
	if nNew > int64(*(*int32)(unsafe.Pointer((*TParse)(unsafe.Pointer(p)).Fdb + 120 + 5*4))) {
		_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(p)).Fdb)
		return int32(SQLITE_NOMEM)
	}
	pNew = _sqlite3DbRealloc(tls, (*TParse)(unsafe.Pointer(p)).Fdb, (*TVdbe)(unsafe.Pointer(v)).FaOp, uint64(nNew*int64(20)))
	if pNew != 0 {
		(*TParse)(unsafe.Pointer(p)).FszOpAlloc = _sqlite3DbMallocSize(tls, (*TParse)(unsafe.Pointer(p)).Fdb, pNew)
		(*TVdbe)(unsafe.Pointer(v)).FnOpAlloc = int32(uint32((*TParse)(unsafe.Pointer(p)).FszOpAlloc) / uint32(20))
		(*TVdbe)(unsafe.Pointer(v)).FaOp = pNew
	}
	if pNew != 0 {
		v2 = SQLITE_OK
	} else {
		v2 = int32(SQLITE_NOMEM)
	}
	return v2
}

// C documentation
//
//	/*
//	** Slow paths for sqlite3VdbeAddOp3() and sqlite3VdbeAddOp4Int() for the
//	** unusual case when we need to increase the size of the Vdbe.aOp[] array
//	** before adding the new opcode.
//	*/
func _growOp3(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32) (r int32) {
	if _growOpArray(tls, p, int32(1)) != 0 {
		return int32(1)
	}
	return _sqlite3VdbeAddOp3(tls, p, op, p1, p2, p3)
}

func _addOp4IntSlow(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, p4 int32) (r int32) {
	var addr int32
	var pOp uintptr
	_, _ = addr, pOp
	addr = _sqlite3VdbeAddOp3(tls, p, op, p1, p2, p3)
	if int32((*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed) == 0 {
		pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*20
		(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(3))
		*(*int32)(unsafe.Pointer(pOp + 16)) = p4
	}
	return addr
}

// C documentation
//
//	/*
//	** Add a new instruction to the list of instructions current in the
//	** VDBE.  Return the address of the new instruction.
//	**
//	** Parameters:
//	**
//	**    p               Pointer to the VDBE
//	**
//	**    op              The opcode for this instruction
//	**
//	**    p1, p2, p3, p4  Operands
//	*/
func _sqlite3VdbeAddOp0(tls *libc.TLS, p uintptr, op int32) (r int32) {
	return _sqlite3VdbeAddOp3(tls, p, op, 0, 0, 0)
}

func _sqlite3VdbeAddOp1(tls *libc.TLS, p uintptr, op int32, p1 int32) (r int32) {
	return _sqlite3VdbeAddOp3(tls, p, op, p1, 0, 0)
}

func _sqlite3VdbeAddOp2(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32) (r int32) {
	return _sqlite3VdbeAddOp3(tls, p, op, p1, p2, 0)
}

func _sqlite3VdbeAddOp3(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32) (r int32) {
	var i int32
	var pOp uintptr
	_, _ = i, pOp
	i = (*TVdbe)(unsafe.Pointer(p)).FnOp
	if (*TVdbe)(unsafe.Pointer(p)).FnOpAlloc <= i {
		return _growOp3(tls, p, op, p1, p2, p3)
	}
	(*TVdbe)(unsafe.Pointer(p)).FnOp++
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i)*20
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(uint8(op))
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp5 = uint16(0)
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = p1
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = p2
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 = p3
	*(*uintptr)(unsafe.Pointer(pOp + 16)) = uintptr(0)
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = P4_NOTUSED
	/* Replicate this logic in sqlite3VdbeAddOp4Int()
	 ** vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv   */
	/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	 ** Replicate in sqlite3VdbeAddOp4Int() */
	return i
}

func _sqlite3VdbeAddOp4Int(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, p4 int32) (r int32) {
	var i int32
	var pOp uintptr
	_, _ = i, pOp
	i = (*TVdbe)(unsafe.Pointer(p)).FnOp
	if (*TVdbe)(unsafe.Pointer(p)).FnOpAlloc <= i {
		return _addOp4IntSlow(tls, p, op, p1, p2, p3, p4)
	}
	(*TVdbe)(unsafe.Pointer(p)).FnOp++
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i)*20
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(uint8(op))
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp5 = uint16(0)
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = p1
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = p2
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 = p3
	*(*int32)(unsafe.Pointer(pOp + 16)) = p4
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(3))
	/* Replicate this logic in sqlite3VdbeAddOp3()
	 ** vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv   */
	/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	 ** Replicate in sqlite3VdbeAddOp3() */
	return i
}

// C documentation
//
//	/* Generate code for an unconditional jump to instruction iDest
//	*/
func _sqlite3VdbeGoto(tls *libc.TLS, p uintptr, iDest int32) (r int32) {
	return _sqlite3VdbeAddOp3(tls, p, int32(OP_Goto), 0, iDest, 0)
}

// C documentation
//
//	/* Generate code to cause the string zStr to be loaded into
//	** register iDest
//	*/
func _sqlite3VdbeLoadString(tls *libc.TLS, p uintptr, iDest int32, zStr uintptr) (r int32) {
	return _sqlite3VdbeAddOp4(tls, p, int32(OP_String8), 0, iDest, 0, zStr, 0)
}

// C documentation
//
//	/*
//	** Generate code that initializes multiple registers to string or integer
//	** constants.  The registers begin with iDest and increase consecutively.
//	** One register is initialized for each characgter in zTypes[].  For each
//	** "s" character in zTypes[], the register is a string if the argument is
//	** not NULL, or OP_Null if the value is a null pointer.  For each "i" character
//	** in zTypes[], the register is initialized to an integer.
//	**
//	** If the input string does not end with "X" then an OP_ResultRow instruction
//	** is generated for the values inserted.
//	*/
func _sqlite3VdbeMultiLoad(tls *libc.TLS, p uintptr, iDest int32, zTypes uintptr, va uintptr) {
	var ap Tva_list
	var c, v2 int8
	var i, v3 int32
	var z uintptr
	_, _, _, _, _, _ = ap, c, i, z, v2, v3
	ap = va
	i = 0
	for {
		v2 = *(*int8)(unsafe.Pointer(zTypes + uintptr(i)))
		c = v2
		if !(int32(v2) != 0) {
			break
		}
		if int32(int32(c)) == int32('s') {
			z = libc.VaUintptr(&ap)
			if z == uintptr(0) {
				v3 = int32(OP_Null)
			} else {
				v3 = int32(OP_String8)
			}
			_sqlite3VdbeAddOp4(tls, p, v3, 0, iDest+i, 0, z, 0)
		} else {
			if int32(int32(c)) == int32('i') {
				_sqlite3VdbeAddOp2(tls, p, int32(OP_Integer), libc.VaInt32(&ap), iDest+i)
			} else {
				goto skip_op_resultrow
			}
		}
		goto _1
	_1:
		;
		i++
	}
	_sqlite3VdbeAddOp2(tls, p, int32(OP_ResultRow), iDest, i)
	goto skip_op_resultrow
skip_op_resultrow:
	;
	_ = ap
}

// C documentation
//
//	/*
//	** Add an opcode that includes the p4 value as a pointer.
//	*/
func _sqlite3VdbeAddOp4(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, zP4 uintptr, p4type int32) (r int32) {
	var addr int32
	_ = addr
	addr = _sqlite3VdbeAddOp3(tls, p, op, p1, p2, p3)
	_sqlite3VdbeChangeP4(tls, p, addr, zP4, p4type)
	return addr
}

// C documentation
//
//	/*
//	** Add an OP_Function or OP_PureFunc opcode.
//	**
//	** The eCallCtx argument is information (typically taken from Expr.op2)
//	** that describes the calling context of the function.  0 means a general
//	** function call.  NC_IsCheck means called by a check constraint,
//	** NC_IdxExpr means called as part of an index expression.  NC_PartIdx
//	** means in the WHERE clause of a partial index.  NC_GenCol means called
//	** while computing a generated column value.  0 is the usual case.
//	*/
func _sqlite3VdbeAddFunctionCall(tls *libc.TLS, pParse uintptr, p1 int32, p2 int32, p3 int32, nArg int32, pFunc uintptr, eCallCtx int32) (r int32) {
	var addr, nByte, v1 int32
	var pCtx, v uintptr
	_, _, _, _, _ = addr, nByte, pCtx, v, v1
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	nByte = int32(uint32(32) + uint32(nArg-libc.Int32FromInt32(1))*uint32(4))
	pCtx = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(nByte)))
	if pCtx == uintptr(0) {
		_freeEphemeralFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pFunc)
		return 0
	}
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut = uintptr(0)
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpFunc = pFunc
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe = uintptr(0)
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = 0
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).Fargc = uint8(uint8(nArg))
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp = _sqlite3VdbeCurrentAddr(tls, v)
	if eCallCtx != 0 {
		v1 = int32(OP_PureFunc)
	} else {
		v1 = int32(OP_Function)
	}
	addr = _sqlite3VdbeAddOp4(tls, v, v1, p1, p2, p3, pCtx, -int32(15))
	_sqlite3VdbeChangeP5(tls, v, uint16(eCallCtx&int32(NC_SelfRef)))
	_sqlite3MayAbort(tls, pParse)
	return addr
}

// C documentation
//
//	/*
//	** Add an opcode that includes the p4 value with a P4_INT64 or
//	** P4_REAL type.
//	*/
func _sqlite3VdbeAddOp4Dup8(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, zP4 uintptr, p4type int32) (r int32) {
	var p4copy uintptr
	_ = p4copy
	p4copy = _sqlite3DbMallocRawNN(tls, _sqlite3VdbeDb(tls, p), uint64(8))
	if p4copy != 0 {
		libc.Xmemcpy(tls, p4copy, zP4, uint32(8))
	}
	return _sqlite3VdbeAddOp4(tls, p, op, p1, p2, p3, p4copy, p4type)
}

// C documentation
//
//	/*
//	** Return the address of the current EXPLAIN QUERY PLAN baseline.
//	** 0 means "none".
//	*/
func _sqlite3VdbeExplainParent(tls *libc.TLS, pParse uintptr) (r int32) {
	var pOp uintptr
	_ = pOp
	if (*TParse)(unsafe.Pointer(pParse)).FaddrExplain == 0 {
		return 0
	}
	pOp = _sqlite3VdbeGetOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TParse)(unsafe.Pointer(pParse)).FaddrExplain)
	return (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2
}

/*
** Set a debugger breakpoint on the following routine in order to
** monitor the EXPLAIN QUERY PLAN code generation.
 */

// C documentation
//
//	/*
//	** Add a new OP_Explain opcode.
//	**
//	** If the bPush flag is true, then make this opcode the parent for
//	** subsequent Explains until sqlite3VdbeExplainPop() is called.
//	*/
func _sqlite3VdbeExplain(tls *libc.TLS, pParse uintptr, bPush Tu8, zFmt uintptr, va uintptr) (r int32) {
	var addr, iThis int32
	var ap Tva_list
	var v, zMsg uintptr
	_, _, _, _, _ = addr, ap, iThis, v, zMsg
	addr = 0
	/* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
	 ** But omit them (for performance) during production builds */
	if int32((*TParse)(unsafe.Pointer(pParse)).Fexplain) == int32(2) || libc.Bool(0 != 0) {
		ap = va
		zMsg = _sqlite3VMPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zFmt, ap)
		_ = ap
		v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
		iThis = (*TVdbe)(unsafe.Pointer(v)).FnOp
		addr = _sqlite3VdbeAddOp4(tls, v, int32(OP_Explain), iThis, (*TParse)(unsafe.Pointer(pParse)).FaddrExplain, 0, zMsg, -int32(6))
		if bPush != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FaddrExplain = iThis
		}
	}
	return addr
}

// C documentation
//
//	/*
//	** Pop the EXPLAIN QUERY PLAN stack one level.
//	*/
func _sqlite3VdbeExplainPop(tls *libc.TLS, pParse uintptr) {
	(*TParse)(unsafe.Pointer(pParse)).FaddrExplain = _sqlite3VdbeExplainParent(tls, pParse)
}

// C documentation
//
//	/*
//	** Add an OP_ParseSchema opcode.  This routine is broken out from
//	** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees
//	** as having been used.
//	**
//	** The zWhere string must have been obtained from sqlite3_malloc().
//	** This routine will take ownership of the allocated memory.
//	*/
func _sqlite3VdbeAddParseSchemaOp(tls *libc.TLS, p uintptr, iDb int32, zWhere uintptr, p5 Tu16) {
	var j int32
	_ = j
	_sqlite3VdbeAddOp4(tls, p, int32(OP_ParseSchema), iDb, 0, 0, zWhere, -int32(6))
	_sqlite3VdbeChangeP5(tls, p, p5)
	j = 0
	for {
		if !(j < (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FnDb) {
			break
		}
		_sqlite3VdbeUsesBtree(tls, p, j)
		goto _1
	_1:
		;
		j++
	}
	_sqlite3MayAbort(tls, (*TVdbe)(unsafe.Pointer(p)).FpParse)
}

// C documentation
//
//	/* Insert the end of a co-routine
//	*/
func _sqlite3VdbeEndCoroutine(tls *libc.TLS, v uintptr, regYield int32) {
	_sqlite3VdbeAddOp1(tls, v, int32(OP_EndCoroutine), regYield)
	/* Clear the temporary register cache, thereby ensuring that each
	 ** co-routine has its own independent set of registers, because co-routines
	 ** might expect their registers to be preserved across an OP_Yield, and
	 ** that could cause problems if two or more co-routines are using the same
	 ** temporary register.
	 */
	(*TParse)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).FpParse)).FnTempReg = uint8(0)
	(*TParse)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).FpParse)).FnRangeReg = 0
}

// C documentation
//
//	/*
//	** Create a new symbolic label for an instruction that has yet to be
//	** coded.  The symbolic label is really just a negative number.  The
//	** label can be used as the P2 value of an operation.  Later, when
//	** the label is resolved to a specific address, the VDBE will scan
//	** through its operation list and change all values of P2 which match
//	** the label into the resolved address.
//	**
//	** The VDBE knows that a P2 value is a label because labels are
//	** always negative and P2 values are suppose to be non-negative.
//	** Hence, a negative P2 value is a label that has yet to be resolved.
//	** (Later:) This is only true for opcodes that have the OPFLG_JUMP
//	** property.
//	**
//	** Variable usage notes:
//	**
//	**     Parse.aLabel[x]     Stores the address that the x-th label resolves
//	**                         into.  For testing (SQLITE_DEBUG), unresolved
//	**                         labels stores -1, but that is not required.
//	**     Parse.nLabelAlloc   Number of slots allocated to Parse.aLabel[]
//	**     Parse.nLabel        The *negative* of the number of labels that have
//	**                         been issued.  The negative is stored because
//	**                         that gives a performance improvement over storing
//	**                         the equivalent positive value.
//	*/
func _sqlite3VdbeMakeLabel(tls *libc.TLS, pParse uintptr) (r int32) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	v2 = pParse + 56
	*(*int32)(unsafe.Pointer(v2))--
	v1 = *(*int32)(unsafe.Pointer(v2))
	return v1
}

// C documentation
//
//	/*
//	** Resolve label "x" to be the address of the next instruction to
//	** be inserted.  The parameter "x" must have been obtained from
//	** a prior call to sqlite3VdbeMakeLabel().
//	*/
func _resizeResolveLabel(tls *libc.TLS, p uintptr, v uintptr, j int32) {
	var nNewSize int32
	_ = nNewSize
	nNewSize = int32(10) - (*TParse)(unsafe.Pointer(p)).FnLabel
	(*TParse)(unsafe.Pointer(p)).FaLabel = _sqlite3DbReallocOrFree(tls, (*TParse)(unsafe.Pointer(p)).Fdb, (*TParse)(unsafe.Pointer(p)).FaLabel, uint64(uint32(uint32(nNewSize))*uint32(4)))
	if (*TParse)(unsafe.Pointer(p)).FaLabel == uintptr(0) {
		(*TParse)(unsafe.Pointer(p)).FnLabelAlloc = 0
	} else {
		if nNewSize >= int32(100) && nNewSize/int32(100) > (*TParse)(unsafe.Pointer(p)).FnLabelAlloc/int32(100) {
			_sqlite3ProgressCheck(tls, p)
		}
		(*TParse)(unsafe.Pointer(p)).FnLabelAlloc = nNewSize
		*(*int32)(unsafe.Pointer((*TParse)(unsafe.Pointer(p)).FaLabel + uintptr(j)*4)) = (*TVdbe)(unsafe.Pointer(v)).FnOp
	}
}

func _sqlite3VdbeResolveLabel(tls *libc.TLS, v uintptr, x int32) {
	var j int32
	var p uintptr
	_, _ = j, p
	p = (*TVdbe)(unsafe.Pointer(v)).FpParse
	j = ^x
	if (*TParse)(unsafe.Pointer(p)).FnLabelAlloc+(*TParse)(unsafe.Pointer(p)).FnLabel < 0 {
		_resizeResolveLabel(tls, p, v, j)
	} else {
		/* Labels may only be resolved once */
		*(*int32)(unsafe.Pointer((*TParse)(unsafe.Pointer(p)).FaLabel + uintptr(j)*4)) = (*TVdbe)(unsafe.Pointer(v)).FnOp
	}
}

// C documentation
//
//	/*
//	** Mark the VDBE as one that can only be run one time.
//	*/
func _sqlite3VdbeRunOnlyOnce(tls *libc.TLS, p uintptr) {
	_sqlite3VdbeAddOp2(tls, p, int32(OP_Expire), int32(1), int32(1))
}

// C documentation
//
//	/*
//	** Mark the VDBE as one that can be run multiple times.
//	*/
func _sqlite3VdbeReusable(tls *libc.TLS, p uintptr) {
	var i int32
	_ = i
	i = int32(1)
	for {
		if !(i < (*TVdbe)(unsafe.Pointer(p)).FnOp) {
			break
		}
		if int32((*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i)*20))).Fopcode) == int32(OP_Expire) {
			(*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp + 1*20))).Fopcode = uint8(OP_Noop)
			break
		}
		goto _1
	_1:
		;
		i++
	}
}

// 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 any SQL function
//	**     and store that value in *pMaxFuncArgs.
//	**
//	** (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, pMaxFuncArgs uintptr) {
	var aLabel, pOp, pParse uintptr
	var n, nMaxArgs int32
	_, _, _, _, _ = aLabel, n, nMaxArgs, pOp, pParse
	nMaxArgs = *(*int32)(unsafe.Pointer(pMaxFuncArgs))
	pParse = (*TVdbe)(unsafe.Pointer(p)).FpParse
	aLabel = (*TParse)(unsafe.Pointer(pParse)).FaLabel
	/* tag-20230419-1 */
	libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(1), 6, 0x40)
	libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(0), 7, 0x80)
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))*20
	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 int32((*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 int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
			case int32(OP_Transaction):
				if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 {
					libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(0), 6, 0x40)
				}
				fallthrough
			case int32(OP_AutoCommit):
				fallthrough
			case OP_Savepoint:
				libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(1), 7, 0x80)
			case int32(OP_Checkpoint):
				fallthrough
			case int32(OP_Vacuum):
				fallthrough
			case int32(OP_JournalMode):
				libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(0), 6, 0x40)
				libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(1), 7, 0x80)
			case int32(OP_Init):
				goto resolve_p2_values_loop_exit
			case int32(OP_VUpdate):
				if (*TOp)(unsafe.Pointer(pOp)).Fp2 > nMaxArgs {
					nMaxArgs = (*TOp)(unsafe.Pointer(pOp)).Fp2
				}
			case int32(OP_VFilter):
				n = (*(*TOp)(unsafe.Pointer(pOp + uintptr(-libc.Int32FromInt32(1))*20))).Fp1
				if n > nMaxArgs {
					nMaxArgs = n
				}
				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)(unsafe.Pointer(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 -= 20
	}
	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)(unsafe.Pointer(pMaxFuncArgs)) = nMaxArgs
}

// C documentation
//
//	/*
//	** Return the address of the next instruction to be inserted.
//	*/
func _sqlite3VdbeCurrentAddr(tls *libc.TLS, p uintptr) (r int32) {
	return (*TVdbe)(unsafe.Pointer(p)).FnOp
}

/*
** Verify that at least N opcode slots are available in p without
** having to malloc for more space (except when compiled using
** SQLITE_TEST_REALLOC_STRESS).  This interface is used during testing
** to verify that certain calls to sqlite3VdbeAddOpList() can never
** fail due to a OOM fault and hence that the return value from
** sqlite3VdbeAddOpList() will always be non-NULL.
 */

/*
** Verify that the VM passed as the only argument does not contain
** an OP_ResultRow opcode. Fail an assert() if it does. This is used
** by code in pragma.c to ensure that the implementation of certain
** pragmas comports with the flags specified in the mkpragmatab.tcl
** script.
 */

/*
** Generate code (a single OP_Abortable opcode) that will
** verify that the VDBE program can safely call Abort in the current
** context.
 */

// C documentation
//
//	/*
//	** This function returns a pointer to the array of opcodes associated with
//	** the Vdbe passed as the first argument. It is the callers responsibility
//	** to arrange for the returned array to be eventually freed using the
//	** vdbeFreeOpArray() function.
//	**
//	** Before returning, *pnOp is set to the number of entries in the returned
//	** array. Also, *pnMaxArg is set to the larger of its current value and
//	** the number of entries in the Vdbe.apArg[] array required to execute the
//	** returned program.
//	*/
func _sqlite3VdbeTakeOpArray(tls *libc.TLS, p uintptr, pnOp uintptr, pnMaxArg uintptr) (r uintptr) {
	var aOp uintptr
	_ = aOp
	aOp = (*TVdbe)(unsafe.Pointer(p)).FaOp
	/* Check that sqlite3VdbeUsesBtree() was not called on this VM */
	_resolveP2Values(tls, p, pnMaxArg)
	*(*int32)(unsafe.Pointer(pnOp)) = (*TVdbe)(unsafe.Pointer(p)).FnOp
	(*TVdbe)(unsafe.Pointer(p)).FaOp = uintptr(0)
	return aOp
}

// C documentation
//
//	/*
//	** Add a whole list of operations to the operation stack.  Return a
//	** pointer to the first operation inserted.
//	**
//	** Non-zero P2 arguments to jump instructions are automatically adjusted
//	** so that the jump target is relative to the first operation inserted.
//	*/
func _sqlite3VdbeAddOpList(tls *libc.TLS, p uintptr, nOp int32, aOp uintptr, iLineno int32) (r uintptr) {
	var i int32
	var pFirst, pOut, v1 uintptr
	_, _, _, _ = i, pFirst, pOut, v1
	if (*TVdbe)(unsafe.Pointer(p)).FnOp+nOp > (*TVdbe)(unsafe.Pointer(p)).FnOpAlloc && _growOpArray(tls, p, nOp) != 0 {
		return uintptr(0)
	}
	v1 = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp)*20
	pOut = v1
	pFirst = v1
	i = 0
	for {
		if !(i < nOp) {
			break
		}
		(*TVdbeOp)(unsafe.Pointer(pOut)).Fopcode = (*TVdbeOpList)(unsafe.Pointer(aOp)).Fopcode
		(*TVdbeOp)(unsafe.Pointer(pOut)).Fp1 = int32((*TVdbeOpList)(unsafe.Pointer(aOp)).Fp1)
		(*TVdbeOp)(unsafe.Pointer(pOut)).Fp2 = int32((*TVdbeOpList)(unsafe.Pointer(aOp)).Fp2)
		if int32(_sqlite3OpcodeProperty[(*TVdbeOpList)(unsafe.Pointer(aOp)).Fopcode])&int32(OPFLG_JUMP) != 0 && int32((*TVdbeOpList)(unsafe.Pointer(aOp)).Fp2) > 0 {
			*(*int32)(unsafe.Pointer(pOut + 8)) += (*TVdbe)(unsafe.Pointer(p)).FnOp
		}
		(*TVdbeOp)(unsafe.Pointer(pOut)).Fp3 = int32((*TVdbeOpList)(unsafe.Pointer(aOp)).Fp3)
		(*TVdbeOp)(unsafe.Pointer(pOut)).Fp4type = P4_NOTUSED
		*(*uintptr)(unsafe.Pointer(pOut + 16)) = uintptr(0)
		(*TVdbeOp)(unsafe.Pointer(pOut)).Fp5 = uint16(0)
		_ = iLineno
		goto _2
	_2:
		;
		i++
		aOp += 4
		pOut += 20
	}
	*(*int32)(unsafe.Pointer(p + 108)) += nOp
	return pFirst
}

// C documentation
//
//	/*
//	** Change the value of the opcode, or P1, P2, P3, or P5 operands
//	** for a specific instruction.
//	*/
func _sqlite3VdbeChangeOpcode(tls *libc.TLS, p uintptr, addr int32, iNewOpcode Tu8) {
	(*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, p, addr))).Fopcode = iNewOpcode
}

func _sqlite3VdbeChangeP1(tls *libc.TLS, p uintptr, addr int32, val int32) {
	(*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, p, addr))).Fp1 = val
}

func _sqlite3VdbeChangeP2(tls *libc.TLS, p uintptr, addr int32, val int32) {
	(*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, p, addr))).Fp2 = val
}

func _sqlite3VdbeChangeP3(tls *libc.TLS, p uintptr, addr int32, val int32) {
	(*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, p, addr))).Fp3 = val
}

func _sqlite3VdbeChangeP5(tls *libc.TLS, p uintptr, p5 Tu16) {
	if (*TVdbe)(unsafe.Pointer(p)).FnOp > 0 {
		(*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))*20))).Fp5 = p5
	}
}

// C documentation
//
//	/*
//	** If the previous opcode is an OP_Column that delivers results
//	** into register iDest, then add the OPFLAG_TYPEOFARG flag to that
//	** opcode.
//	*/
func _sqlite3VdbeTypeofColumn(tls *libc.TLS, p uintptr, iDest int32) {
	var pOp, p1 uintptr
	_, _ = pOp, p1
	pOp = _sqlite3VdbeGetLastOp(tls, p)
	if (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 == iDest && int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) {
		p1 = pOp + 2
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(OPFLAG_TYPEOFARG))
	}
}

// C documentation
//
//	/*
//	** Change the P2 operand of instruction addr so that it points to
//	** the address of the next instruction to be coded.
//	*/
func _sqlite3VdbeJumpHere(tls *libc.TLS, p uintptr, addr int32) {
	_sqlite3VdbeChangeP2(tls, p, addr, (*TVdbe)(unsafe.Pointer(p)).FnOp)
}

// C documentation
//
//	/*
//	** Change the P2 operand of the jump instruction at addr so that
//	** the jump lands on the next opcode.  Or if the jump instruction was
//	** the previous opcode (and is thus a no-op) then simply back up
//	** the next instruction counter by one slot so that the jump is
//	** overwritten by the next inserted opcode.
//	**
//	** This routine is an optimization of sqlite3VdbeJumpHere() that
//	** strives to omit useless byte-code like this:
//	**
//	**        7   Once 0 8 0
//	**        8   ...
//	*/
func _sqlite3VdbeJumpHereOrPopInst(tls *libc.TLS, p uintptr, addr int32) {
	if addr == (*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1) {
		(*TVdbe)(unsafe.Pointer(p)).FnOp--
	} else {
		_sqlite3VdbeChangeP2(tls, p, addr, (*TVdbe)(unsafe.Pointer(p)).FnOp)
	}
}

// C documentation
//
//	/*
//	** If the input FuncDef structure is ephemeral, then free it.  If
//	** the FuncDef is not ephemeral, then do nothing.
//	*/
func _freeEphemeralFunction(tls *libc.TLS, db uintptr, pDef uintptr) {
	if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_EPHEM) != uint32(0) {
		_sqlite3DbNNFreeNN(tls, db, pDef)
	}
}

// C documentation
//
//	/*
//	** Delete a P4 value if necessary.
//	*/
func _freeP4Mem(tls *libc.TLS, db uintptr, p uintptr) {
	if (*TMem)(unsafe.Pointer(p)).FszMalloc != 0 {
		_sqlite3DbFree(tls, db, (*TMem)(unsafe.Pointer(p)).FzMalloc)
	}
	_sqlite3DbNNFreeNN(tls, db, p)
}

func _freeP4FuncCtx(tls *libc.TLS, db uintptr, p uintptr) {
	_freeEphemeralFunction(tls, db, (*Tsqlite3_context)(unsafe.Pointer(p)).FpFunc)
	_sqlite3DbNNFreeNN(tls, db, p)
}

func _freeP4(tls *libc.TLS, db uintptr, p4type int32, p4 uintptr) {
	switch p4type {
	case -int32(15):
		_freeP4FuncCtx(tls, db, p4)
	case -int32(12):
		fallthrough
	case -int32(13):
		fallthrough
	case -int32(6):
		fallthrough
	case -int32(14):
		if p4 != 0 {
			_sqlite3DbNNFreeNN(tls, db, p4)
		}
	case -int32(8):
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			_sqlite3KeyInfoUnref(tls, p4)
		}
	case -int32(7):
		_freeEphemeralFunction(tls, db, p4)
	case -int32(10):
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			_sqlite3ValueFree(tls, p4)
		} else {
			_freeP4Mem(tls, db, p4)
		}
	case -int32(11):
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			_sqlite3VtabUnlock(tls, p4)
		}
	case -int32(16):
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			_sqlite3DeleteTable(tls, db, p4)
		}
		break
	}
}

// C documentation
//
//	/*
//	** Free the space allocated for aOp and any p4 values allocated for the
//	** opcodes contained within. If aOp is not NULL it is assumed to contain
//	** nOp entries.
//	*/
func _vdbeFreeOpArray(tls *libc.TLS, db uintptr, aOp uintptr, nOp int32) {
	var pOp uintptr
	_ = pOp
	if aOp != 0 {
		pOp = aOp + uintptr(nOp-int32(1))*20
		for int32(1) != 0 { /* Exit via break */
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) <= -int32(6) {
				_freeP4(tls, db, int32((*TOp)(unsafe.Pointer(pOp)).Fp4type), *(*uintptr)(unsafe.Pointer(pOp + 16)))
			}
			if pOp == aOp {
				break
			}
			pOp -= 20
		}
		_sqlite3DbNNFreeNN(tls, db, aOp)
	}
}

// C documentation
//
//	/*
//	** Link the SubProgram object passed as the second argument into the linked
//	** list at Vdbe.pSubProgram. This list is used to delete all sub-program
//	** objects when the VM is no longer required.
//	*/
func _sqlite3VdbeLinkSubProgram(tls *libc.TLS, pVdbe uintptr, p uintptr) {
	(*TSubProgram)(unsafe.Pointer(p)).FpNext = (*TVdbe)(unsafe.Pointer(pVdbe)).FpProgram
	(*TVdbe)(unsafe.Pointer(pVdbe)).FpProgram = p
}

// C documentation
//
//	/*
//	** Return true if the given Vdbe has any SubPrograms.
//	*/
func _sqlite3VdbeHasSubProgram(tls *libc.TLS, pVdbe uintptr) (r int32) {
	return libc.BoolInt32((*TVdbe)(unsafe.Pointer(pVdbe)).FpProgram != uintptr(0))
}

// C documentation
//
//	/*
//	** Change the opcode at addr into OP_Noop
//	*/
func _sqlite3VdbeChangeToNoop(tls *libc.TLS, p uintptr, addr int32) (r int32) {
	var pOp uintptr
	_ = pOp
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return 0
	}
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*20
	_freeP4(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type), *(*uintptr)(unsafe.Pointer(pOp + 16)))
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = P4_NOTUSED
	*(*uintptr)(unsafe.Pointer(pOp + 16)) = uintptr(0)
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_Noop)
	return int32(1)
}

// C documentation
//
//	/*
//	** If the last opcode is "op" and it is not a jump destination,
//	** then remove it.  Return true if and only if an opcode was removed.
//	*/
func _sqlite3VdbeDeletePriorOpcode(tls *libc.TLS, p uintptr, op Tu8) (r int32) {
	if (*TVdbe)(unsafe.Pointer(p)).FnOp > 0 && int32((*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))*20))).Fopcode) == int32(int32(op)) {
		return _sqlite3VdbeChangeToNoop(tls, p, (*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))
	} else {
		return 0
	}
	return r
}

// C documentation
//
//	/*
//	** Change the value of the P4 operand for a specific instruction.
//	** This routine is useful when a large program is loaded from a
//	** static array using sqlite3VdbeAddOpList but we want to make a
//	** few minor changes to the program.
//	**
//	** If n>=0 then the P4 operand is dynamic, meaning that a copy of
//	** the string is made into memory obtained from sqlite3_malloc().
//	** A value of n==0 means copy bytes of zP4 up to and including the
//	** first null byte.  If n>0 then copy n+1 bytes of zP4.
//	**
//	** Other values of n (P4_STATIC, P4_COLLSEQ etc.) indicate that zP4 points
//	** to a string or structure that is guaranteed to exist for the lifetime of
//	** the Vdbe. In these cases we can just copy the pointer.
//	**
//	** If addr<0 then change P4 on the most recently inserted instruction.
//	*/
func _vdbeChangeP4Full(tls *libc.TLS, p uintptr, pOp uintptr, zP4 uintptr, n int32) {
	if (*TOp)(unsafe.Pointer(pOp)).Fp4type != 0 {
		(*TOp)(unsafe.Pointer(pOp)).Fp4type = 0
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = uintptr(0)
	}
	if n < 0 {
		_sqlite3VdbeChangeP4(tls, p, (int32(int32(pOp))-int32((*TVdbe)(unsafe.Pointer(p)).FaOp))/20, zP4, n)
	} else {
		if n == 0 {
			n = _sqlite3Strlen30(tls, zP4)
		}
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = _sqlite3DbStrNDup(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, zP4, uint64(uint64(n)))
		(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(6))
	}
}

func _sqlite3VdbeChangeP4(tls *libc.TLS, p uintptr, addr int32, _zP4 uintptr, n int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _zP4
	var db, pOp uintptr
	_, _ = db, pOp
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		if n != -int32(11) {
			_freeP4(tls, db, n, *(*uintptr)(unsafe.Pointer(bp)))
		}
		return
	}
	if addr < 0 {
		addr = (*TVdbe)(unsafe.Pointer(p)).FnOp - int32(1)
	}
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*20
	if n >= 0 || (*TOp)(unsafe.Pointer(pOp)).Fp4type != 0 {
		_vdbeChangeP4Full(tls, p, pOp, *(*uintptr)(unsafe.Pointer(bp)), n)
		return
	}
	if n == -int32(3) {
		/* Note: this cast is safe, because the origin data point was an int
		 ** that was cast to a (const char *). */
		*(*int32)(unsafe.Pointer(pOp + 16)) = int32(*(*uintptr)(unsafe.Pointer(bp)))
		(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(3))
	} else {
		if *(*uintptr)(unsafe.Pointer(bp)) != uintptr(0) {
			*(*uintptr)(unsafe.Pointer(pOp + 16)) = *(*uintptr)(unsafe.Pointer(bp))
			(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(int8(n))
			if n == -int32(11) {
				_sqlite3VtabLock(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
	}
}

// C documentation
//
//	/*
//	** Change the P4 operand of the most recently coded instruction
//	** to the value defined by the arguments.  This is a high-speed
//	** version of sqlite3VdbeChangeP4().
//	**
//	** The P4 operand must not have been previously defined.  And the new
//	** P4 must not be P4_INT32.  Use sqlite3VdbeChangeP4() in either of
//	** those cases.
//	*/
func _sqlite3VdbeAppendP4(tls *libc.TLS, p uintptr, pP4 uintptr, n int32) {
	var pOp uintptr
	_ = pOp
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		_freeP4(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, n, pP4)
	} else {
		pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))*20
		(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(int8(n))
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = pP4
	}
}

// C documentation
//
//	/*
//	** Set the P4 on the most recently added opcode to the KeyInfo for the
//	** index given.
//	*/
func _sqlite3VdbeSetP4KeyInfo(tls *libc.TLS, pParse uintptr, pIdx uintptr) {
	var pKeyInfo, v uintptr
	_, _ = pKeyInfo, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pKeyInfo = _sqlite3KeyInfoOfIndex(tls, pParse, pIdx)
	if pKeyInfo != 0 {
		_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(8))
	}
}

// C documentation
//
//	/*
//	** Return the opcode for a given address.  The address must be non-negative.
//	** See sqlite3VdbeGetLastOp() to get the most recently added opcode.
//	**
//	** If a memory allocation error has occurred prior to the calling of this
//	** routine, then a pointer to a dummy VdbeOp will be returned.  That opcode
//	** is readable but not writable, though it is cast to a writable value.
//	** The return of a dummy opcode allows the call to continue functioning
//	** after an OOM fault without having to check to see if the return from
//	** this routine is a valid pointer.  But because the dummy.opcode is 0,
//	** dummy will never be written to.  This is verified by code inspection and
//	** by running with Valgrind.
//	*/
func _sqlite3VdbeGetOp(tls *libc.TLS, p uintptr, addr int32) (r uintptr) {
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return uintptr(unsafe.Pointer(&_dummy))
	} else {
		return (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*20
	}
	return r
}

/* C89 specifies that the constant "dummy" will be initialized to all
 ** zeros, which is correct.  MSVC generates a warning, nevertheless. */
var _dummy TVdbeOp

// C documentation
//
//	/* Return the most recently added opcode
//	*/
func _sqlite3VdbeGetLastOp(tls *libc.TLS, p uintptr) (r uintptr) {
	return _sqlite3VdbeGetOp(tls, p, (*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))
}

// C documentation
//
//	/*
//	** Compute a string that describes the P4 parameter for an opcode.
//	** Use zTemp for any required temporary buffer space.
//	*/
func _sqlite3VdbeDisplayP4(tls *libc.TLS, db uintptr, pOp uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var ai, pColl, pColl1, pDef, pDef1, pKeyInfo, pMem, pVtab, zColl, zP4, v2, v3, v4 uintptr
	var i, n Tu32
	var j, v6 int32
	var _ /* x at bp+0 */ TStrAccum
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ai, i, j, n, pColl, pColl1, pDef, pDef1, pKeyInfo, pMem, pVtab, zColl, zP4, v2, v3, v4, v6
	zP4 = uintptr(0)
	_sqlite3StrAccumInit(tls, bp, uintptr(0), uintptr(0), 0, int32(SQLITE_MAX_LENGTH))
	switch int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) {
	case -int32(8):
		pKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6454, libc.VaList(bp+32, int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)))
		j = 0
		for {
			if !(j < int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)) {
				break
			}
			pColl = *(*uintptr)(unsafe.Pointer(pKeyInfo + 20 + uintptr(j)*4))
			if pColl != 0 {
				v2 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
			} else {
				v2 = __ccgo_ts + 1672
			}
			zColl = v2
			if libc.Xstrcmp(tls, zColl, __ccgo_ts+6459) == 0 {
				zColl = __ccgo_ts + 6466
			}
			if int32(*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(j))))&int32(KEYINFO_ORDER_DESC) != 0 {
				v3 = __ccgo_ts + 6447
			} else {
				v3 = __ccgo_ts + 1672
			}
			if int32(*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(j))))&int32(KEYINFO_ORDER_BIGNULL) != 0 {
				v4 = __ccgo_ts + 6468
			} else {
				v4 = __ccgo_ts + 1672
			}
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6471, libc.VaList(bp+32, v3, v4, zColl))
			goto _1
		_1:
			;
			j++
		}
		Xsqlite3_str_append(tls, bp, __ccgo_ts+6479, int32(1))
	case -int32(2):
		pColl1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6495, libc.VaList(bp+32, (*TCollSeq)(unsafe.Pointer(pColl1)).FzName, _encnames[(*TCollSeq)(unsafe.Pointer(pColl1)).Fenc]))
	case -int32(7):
		pDef = *(*uintptr)(unsafe.Pointer(pOp + 16))
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6504, libc.VaList(bp+32, (*TFuncDef)(unsafe.Pointer(pDef)).FzName, int32((*TFuncDef)(unsafe.Pointer(pDef)).FnArg)))
	case -int32(15):
		pDef1 = (*Tsqlite3_context)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpFunc
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6504, libc.VaList(bp+32, (*TFuncDef)(unsafe.Pointer(pDef1)).FzName, int32((*TFuncDef)(unsafe.Pointer(pDef1)).FnArg)))
	case -int32(13):
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1433, libc.VaList(bp+32, *(*Ti64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))))
	case -int32(3):
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6511, libc.VaList(bp+32, *(*int32)(unsafe.Pointer(pOp + 16))))
	case -int32(12):
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1400, libc.VaList(bp+32, *(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))))
	case -int32(10):
		pMem = *(*uintptr)(unsafe.Pointer(pOp + 16))
		if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Str) != 0 {
			zP4 = (*TMem)(unsafe.Pointer(pMem)).Fz
		} else {
			if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
				Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1433, libc.VaList(bp+32, *(*Ti64)(unsafe.Pointer(pMem))))
			} else {
				if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Real) != 0 {
					Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1400, libc.VaList(bp+32, *(*float64)(unsafe.Pointer(pMem))))
				} else {
					if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Null) != 0 {
						zP4 = __ccgo_ts + 1673
					} else {
						zP4 = __ccgo_ts + 6514
					}
				}
			}
		}
	case -int32(11):
		pVtab = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6521, libc.VaList(bp+32, pVtab))
	case -int32(14):
		ai = *(*uintptr)(unsafe.Pointer(pOp + 16))
		n = *(*Tu32)(unsafe.Pointer(ai)) /* The first element of an INTARRAY is always the
		 ** count of the number of elements to follow */
		i = uint32(1)
		for {
			if !(i <= n) {
				break
			}
			if i == uint32(1) {
				v6 = int32('[')
			} else {
				v6 = int32(',')
			}
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+6529, libc.VaList(bp+32, v6, *(*Tu32)(unsafe.Pointer(ai + uintptr(i)*4))))
			goto _5
		_5:
			;
			i++
		}
		Xsqlite3_str_append(tls, bp, __ccgo_ts+6534, int32(1))
	case -int32(4):
		zP4 = __ccgo_ts + 6536
	case -int32(5):
		zP4 = (*TTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FzName
	default:
		zP4 = *(*uintptr)(unsafe.Pointer(pOp + 16))
	}
	if zP4 != 0 {
		Xsqlite3_str_appendall(tls, bp, zP4)
	}
	if int32((*(*TStrAccum)(unsafe.Pointer(bp))).FaccError)&int32(SQLITE_NOMEM) != 0 {
		_sqlite3OomFault(tls, db)
	}
	return _sqlite3StrAccumFinish(tls, bp)
}

var _encnames = [4]uintptr{
	0: __ccgo_ts + 6481,
	1: __ccgo_ts + 6483,
	2: __ccgo_ts + 6485,
	3: __ccgo_ts + 6490,
}

// C documentation
//
//	/*
//	** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
//	**
//	** The prepared statements need to know in advance the complete set of
//	** attached databases that will be use.  A mask of these databases
//	** is maintained in p->btreeMask.  The p->lockMask value is the subset of
//	** p->btreeMask of databases that will require a lock.
//	*/
func _sqlite3VdbeUsesBtree(tls *libc.TLS, p uintptr, i int32) {
	*(*TyDbMask)(unsafe.Pointer(p + 156)) |= libc.Uint32FromInt32(1) << i
	if i != int32(1) && _sqlite3BtreeSharable(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FaDb + uintptr(i)*16))).FpBt) != 0 {
		*(*TyDbMask)(unsafe.Pointer(p + 160)) |= libc.Uint32FromInt32(1) << i
	}
}

// C documentation
//
//	/*
//	** If SQLite is compiled to support shared-cache mode and to be threadsafe,
//	** this routine obtains the mutex associated with each BtShared structure
//	** that may be accessed by the VM passed as an argument. In doing so it also
//	** sets the BtShared.db member of each of the BtShared structures, ensuring
//	** that the correct busy-handler callback is invoked if required.
//	**
//	** If SQLite is not threadsafe but does support shared-cache mode, then
//	** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
//	** of all of BtShared structures accessible via the database handle
//	** associated with the VM.
//	**
//	** If SQLite is not threadsafe and does not support shared-cache mode, this
//	** function is a no-op.
//	**
//	** The p->btreeMask field is a bitmask of all btrees that the prepared
//	** statement p will ever use.  Let N be the number of bits in p->btreeMask
//	** corresponding to btrees that use shared cache.  Then the runtime of
//	** this routine is N*N.  But as N is rarely more than 1, this should not
//	** be a problem.
//	*/
func _sqlite3VdbeEnter(tls *libc.TLS, p uintptr) {
	var aDb, db uintptr
	var i, nDb int32
	_, _, _, _ = aDb, db, i, nDb
	if (*TVdbe)(unsafe.Pointer(p)).FlockMask == uint32(0) {
		return
	} /* The common case */
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	aDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
	nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
	i = 0
	for {
		if !(i < nDb) {
			break
		}
		if i != int32(1) && (*TVdbe)(unsafe.Pointer(p)).FlockMask&(libc.Uint32FromInt32(1)<<i) != uint32(0) && (*(*TDb)(unsafe.Pointer(aDb + uintptr(i)*16))).FpBt != uintptr(0) {
			_sqlite3BtreeEnter(tls, (*(*TDb)(unsafe.Pointer(aDb + uintptr(i)*16))).FpBt)
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
//	*/
func _vdbeLeave(tls *libc.TLS, p uintptr) {
	var aDb, db uintptr
	var i, nDb int32
	_, _, _, _ = aDb, db, i, nDb
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	aDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
	nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
	i = 0
	for {
		if !(i < nDb) {
			break
		}
		if i != int32(1) && (*TVdbe)(unsafe.Pointer(p)).FlockMask&(libc.Uint32FromInt32(1)<<i) != uint32(0) && (*(*TDb)(unsafe.Pointer(aDb + uintptr(i)*16))).FpBt != uintptr(0) {
			_sqlite3BtreeLeave(tls, (*(*TDb)(unsafe.Pointer(aDb + uintptr(i)*16))).FpBt)
		}
		goto _1
	_1:
		;
		i++
	}
}

func _sqlite3VdbeLeave(tls *libc.TLS, p uintptr) {
	if (*TVdbe)(unsafe.Pointer(p)).FlockMask == uint32(0) {
		return
	} /* The common case */
	_vdbeLeave(tls, p)
}

// C documentation
//
//	/*
//	** Initialize an array of N Mem element.
//	**
//	** This is a high-runner, so only those fields that really do need to
//	** be initialized are set.  The Mem structure is organized so that
//	** the fields that get initialized are nearby and hopefully on the same
//	** cache line.
//	**
//	**    Mem.flags = flags
//	**    Mem.db = db
//	**    Mem.szMalloc = 0
//	**
//	** All other fields of Mem can safely remain uninitialized for now.  They
//	** will be initialized before use.
//	*/
func _initMemArray(tls *libc.TLS, p uintptr, N int32, db uintptr, flags Tu16) {
	var v1 int32
	_ = v1
	if N > 0 {
		for {
			(*TMem)(unsafe.Pointer(p)).Fflags = flags
			(*TMem)(unsafe.Pointer(p)).Fdb = db
			(*TMem)(unsafe.Pointer(p)).FszMalloc = 0
			p += 40
			goto _2
		_2:
			;
			N--
			v1 = N
			if !(v1 > 0) {
				break
			}
		}
	}
}

// C documentation
//
//	/*
//	** Release auxiliary memory held in an array of N Mem elements.
//	**
//	** After this routine returns, all Mem elements in the array will still
//	** be valid.  Those Mem elements that were not holding auxiliary resources
//	** will be unchanged.  Mem elements which had something freed will be
//	** set to MEM_Undefined.
//	*/
func _releaseMemArray(tls *libc.TLS, p uintptr, N int32) {
	var db, pEnd, v1, v3 uintptr
	_, _, _, _ = db, pEnd, v1, v3
	if p != 0 && N != 0 {
		pEnd = p + uintptr(N)*40
		db = (*TMem)(unsafe.Pointer(p)).Fdb
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
			for {
				if (*TMem)(unsafe.Pointer(p)).FszMalloc != 0 {
					_sqlite3DbFree(tls, db, (*TMem)(unsafe.Pointer(p)).FzMalloc)
				}
				goto _2
			_2:
				;
				p += 40
				v1 = p
				if !(v1 < pEnd) {
					break
				}
			}
			return
		}
		for {
			/* This block is really an inlined version of sqlite3VdbeMemRelease()
			 ** that takes advantage of the fact that the memory cell value is
			 ** being set to NULL after releasing any dynamic resources.
			 **
			 ** The justification for duplicating code is that according to
			 ** callgrind, this causes a certain test case to hit the CPU 4.7
			 ** percent less (x86 linux, gcc version 4.1.2, -O6) than if
			 ** sqlite3MemRelease() were called from here. With -O2, this jumps
			 ** to 6.6 percent. The test case is inserting 1000 rows into a table
			 ** with no indexes using a single prepared INSERT statement, bind()
			 ** and reset(). Inserts are grouped into a transaction.
			 */
			if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
				_sqlite3VdbeMemRelease(tls, p)
				(*TMem)(unsafe.Pointer(p)).Fflags = uint16(MEM_Undefined)
			} else {
				if (*TMem)(unsafe.Pointer(p)).FszMalloc != 0 {
					_sqlite3DbNNFreeNN(tls, db, (*TMem)(unsafe.Pointer(p)).FzMalloc)
					(*TMem)(unsafe.Pointer(p)).FszMalloc = 0
					(*TMem)(unsafe.Pointer(p)).Fflags = uint16(MEM_Undefined)
				}
			}
			goto _4
		_4:
			;
			p += 40
			v3 = p
			if !(v3 < pEnd) {
				break
			}
		}
	}
}

// C documentation
//
//	/*
//	** This is a destructor on a Mem object (which is really an sqlite3_value)
//	** that deletes the Frame object that is attached to it as a blob.
//	**
//	** This routine does not delete the Frame right away.  It merely adds the
//	** frame to a list of frames to be deleted when the Vdbe halts.
//	*/
func _sqlite3VdbeFrameMemDel(tls *libc.TLS, pArg uintptr) {
	var pFrame uintptr
	_ = pFrame
	pFrame = pArg
	(*TVdbeFrame)(unsafe.Pointer(pFrame)).FpParent = (*TVdbe)(unsafe.Pointer((*TVdbeFrame)(unsafe.Pointer(pFrame)).Fv)).FpDelFrame
	(*TVdbe)(unsafe.Pointer((*TVdbeFrame)(unsafe.Pointer(pFrame)).Fv)).FpDelFrame = pFrame
}

// C documentation
//
//	/*
//	** Locate the next opcode to be displayed in EXPLAIN or EXPLAIN
//	** QUERY PLAN output.
//	**
//	** Return SQLITE_ROW on success.  Return SQLITE_DONE if there are no
//	** more opcodes to be displayed.
//	*/
func _sqlite3VdbeNextOpcode(tls *libc.TLS, p uintptr, pSub uintptr, eMode int32, piPc uintptr, piAddr uintptr, paOp uintptr) (r int32) {
	var aOp, apSub uintptr
	var i, iPc, j, j1, nByte, nRow, nSub, rc, v2, v5 int32
	_, _, _, _, _, _, _, _, _, _, _, _ = aOp, apSub, i, iPc, j, j1, nByte, nRow, nSub, rc, v2, v5 /* Stop when row count reaches this */
	nSub = 0                                                                                      /* Number of sub-vdbes seen so far */
	apSub = uintptr(0)                                                                            /* Next instruction address */
	rc = SQLITE_OK                                                                                /* Result code */
	aOp = uintptr(0)                                                                              /* Rowid.  Copy of value in *piPc */
	/* When the number of output rows reaches nRow, that means the
	 ** listing has finished and sqlite3_step() should return SQLITE_DONE.
	 ** nRow is the sum of the number of rows in the main program, plus
	 ** the sum of the number of rows in all trigger subprograms encountered
	 ** so far.  The nRow value will increase as new trigger subprograms are
	 ** encountered, but p->pc will eventually catch up to nRow.
	 */
	nRow = (*TVdbe)(unsafe.Pointer(p)).FnOp
	if pSub != uintptr(0) {
		if int32((*TMem)(unsafe.Pointer(pSub)).Fflags)&int32(MEM_Blob) != 0 {
			/* pSub is initiallly NULL.  It is initialized to a BLOB by
			 ** the P4_SUBPROGRAM processing logic below */
			nSub = int32(uint32((*TMem)(unsafe.Pointer(pSub)).Fn) / uint32(4))
			apSub = (*TMem)(unsafe.Pointer(pSub)).Fz
		}
		i = 0
		for {
			if !(i < nSub) {
				break
			}
			nRow += (*TSubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(i)*4)))).FnOp
			goto _1
		_1:
			;
			i++
		}
	}
	iPc = *(*int32)(unsafe.Pointer(piPc))
	for int32(1) != 0 { /* Loop exits via break */
		v2 = iPc
		iPc++
		i = v2
		if i >= nRow {
			(*TVdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
			rc = int32(SQLITE_DONE)
			break
		}
		if i < (*TVdbe)(unsafe.Pointer(p)).FnOp {
			/* The rowid is small enough that we are still in the
			 ** main program. */
			aOp = (*TVdbe)(unsafe.Pointer(p)).FaOp
		} else {
			i -= (*TVdbe)(unsafe.Pointer(p)).FnOp
			j = 0
			for {
				if !(i >= (*TSubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(j)*4)))).FnOp) {
					break
				}
				i -= (*TSubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(j)*4)))).FnOp
				goto _3
			_3:
				;
				j++
			}
			aOp = (*TSubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(j)*4)))).FaOp
		}
		/* When an OP_Program opcode is encounter (the only opcode that has
		 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
		 ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
		 ** has not already been seen.
		 */
		if pSub != uintptr(0) && int32((*(*TOp)(unsafe.Pointer(aOp + uintptr(i)*20))).Fp4type) == -int32(4) {
			nByte = int32(uint32(nSub+libc.Int32FromInt32(1)) * uint32(4))
			j1 = 0
			for {
				if !(j1 < nSub) {
					break
				}
				if *(*uintptr)(unsafe.Pointer(apSub + uintptr(j1)*4)) == *(*uintptr)(unsafe.Pointer(aOp + uintptr(i)*20 + 16)) {
					break
				}
				goto _4
			_4:
				;
				j1++
			}
			if j1 == nSub {
				(*TVdbe)(unsafe.Pointer(p)).Frc = _sqlite3VdbeMemGrow(tls, pSub, nByte, libc.BoolInt32(nSub != 0))
				if (*TVdbe)(unsafe.Pointer(p)).Frc != SQLITE_OK {
					rc = int32(SQLITE_ERROR)
					break
				}
				apSub = (*TMem)(unsafe.Pointer(pSub)).Fz
				v5 = nSub
				nSub++
				*(*uintptr)(unsafe.Pointer(apSub + uintptr(v5)*4)) = *(*uintptr)(unsafe.Pointer(aOp + uintptr(i)*20 + 16))
				(*TMem)(unsafe.Pointer(pSub)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pSub)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Blob))
				(*TMem)(unsafe.Pointer(pSub)).Fn = int32(uint32(uint32(nSub)) * uint32(4))
				nRow += (*TSubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aOp + uintptr(i)*20 + 16)))).FnOp
			}
		}
		if eMode == 0 {
			break
		}
		if int32((*(*TOp)(unsafe.Pointer(aOp + uintptr(i)*20))).Fopcode) == int32(OP_Explain) {
			break
		}
		if int32((*(*TOp)(unsafe.Pointer(aOp + uintptr(i)*20))).Fopcode) == int32(OP_Init) && iPc > int32(1) {
			break
		}
	}
	*(*int32)(unsafe.Pointer(piPc)) = iPc
	*(*int32)(unsafe.Pointer(piAddr)) = i
	*(*uintptr)(unsafe.Pointer(paOp)) = aOp
	return rc
}

// C documentation
//
//	/*
//	** Delete a VdbeFrame object and its contents. VdbeFrame objects are
//	** allocated by the OP_Program opcode in sqlite3VdbeExec().
//	*/
func _sqlite3VdbeFrameDelete(tls *libc.TLS, p uintptr) {
	var aMem, apCsr uintptr
	var i int32
	_, _, _ = aMem, apCsr, i
	aMem = p + uintptr((libc.Uint32FromInt64(88)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
	apCsr = aMem + uintptr((*TVdbeFrame)(unsafe.Pointer(p)).FnChildMem)*40
	i = 0
	for {
		if !(i < (*TVdbeFrame)(unsafe.Pointer(p)).FnChildCsr) {
			break
		}
		if *(*uintptr)(unsafe.Pointer(apCsr + uintptr(i)*4)) != 0 {
			_sqlite3VdbeFreeCursorNN(tls, (*TVdbeFrame)(unsafe.Pointer(p)).Fv, *(*uintptr)(unsafe.Pointer(apCsr + uintptr(i)*4)))
		}
		goto _1
	_1:
		;
		i++
	}
	_releaseMemArray(tls, aMem, (*TVdbeFrame)(unsafe.Pointer(p)).FnChildMem)
	_sqlite3VdbeDeleteAuxData(tls, (*TVdbe)(unsafe.Pointer((*TVdbeFrame)(unsafe.Pointer(p)).Fv)).Fdb, p+40, -int32(1), 0)
	_sqlite3DbFree(tls, (*TVdbe)(unsafe.Pointer((*TVdbeFrame)(unsafe.Pointer(p)).Fv)).Fdb, p)
}

// 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+4 */ 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*40                                                                                                                                      /* First Mem of result set */
	bListSubprogs = libc.BoolInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0xc>>2)) == 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*40
	} 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 + 152))&0xc>>2)) == int32(2)), p+32, bp, bp+4)
	if rc == SQLITE_OK {
		pOp = *(*uintptr)(unsafe.Pointer(bp + 4)) + uintptr(*(*int32)(unsafe.Pointer(bp)))*20
		if libc.AtomicLoadNInt32(db+312, 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 + 152))&0xc>>2)) == int32(2) {
				_sqlite3VdbeMemSetInt64(tls, pMem, int64((*TOp)(unsafe.Pointer(pOp)).Fp1))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(1)*40, int64((*TOp)(unsafe.Pointer(pOp)).Fp2))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(2)*40, int64((*TOp)(unsafe.Pointer(pOp)).Fp3))
				_sqlite3VdbeMemSetStr(tls, pMem+uintptr(3)*40, zP4, int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
			} else {
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(0)*40, int64(*(*int32)(unsafe.Pointer(bp))))
				_sqlite3VdbeMemSetStr(tls, pMem+uintptr(1)*40, _sqlite3OpcodeName(tls, int32((*TOp)(unsafe.Pointer(pOp)).Fopcode)), int64(-int32(1)), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(2)*40, int64((*TOp)(unsafe.Pointer(pOp)).Fp1))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(3)*40, int64((*TOp)(unsafe.Pointer(pOp)).Fp2))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(4)*40, int64((*TOp)(unsafe.Pointer(pOp)).Fp3))
				/* pMem+5 for p4 is done last */
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(6)*40, int64((*TOp)(unsafe.Pointer(pOp)).Fp5))
				_sqlite3VdbeMemSetNull(tls, pMem+uintptr(7)*40)
				_sqlite3VdbeMemSetStr(tls, pMem+uintptr(5)*40, 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
}

/* An instance of this object describes bulk memory available for use
** by subcomponents of a prepared statement.  Space is allocated out
** of a ReusableSpace object by the allocSpace() routine below.
 */
type TReusableSpace = struct {
	F__ccgo_align  [0]uint32
	FpSpace        uintptr
	F__ccgo_align1 [4]byte
	FnFree         Tsqlite3_int64
	FnNeeded       Tsqlite3_int64
}

type ReusableSpace = TReusableSpace

// C documentation
//
//	/* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
//	** from the ReusableSpace object.  Return a pointer to the allocated
//	** memory on success.  If insufficient memory is available in the
//	** ReusableSpace object, increase the ReusableSpace.nNeeded
//	** value by the amount needed and return NULL.
//	**
//	** If pBuf is not initially NULL, that means that the memory has already
//	** been allocated by a prior call to this routine, so just return a copy
//	** of pBuf and leave ReusableSpace unchanged.
//	**
//	** This allocator is employed to repurpose unused slots at the end of the
//	** opcode array of prepared state for other memory needs of the prepared
//	** statement.
//	*/
func _allocSpace(tls *libc.TLS, p uintptr, pBuf uintptr, nByte Tsqlite3_int64) (r uintptr) {
	if pBuf == uintptr(0) {
		nByte = (nByte + libc.Int64FromInt32(7)) & int64(^libc.Int32FromInt32(7))
		if nByte <= (*TReusableSpace)(unsafe.Pointer(p)).FnFree {
			*(*Tsqlite3_int64)(unsafe.Pointer(p + 8)) -= nByte
			pBuf = (*TReusableSpace)(unsafe.Pointer(p)).FpSpace + uintptr((*TReusableSpace)(unsafe.Pointer(p)).FnFree)
		} else {
			*(*Tsqlite3_int64)(unsafe.Pointer(p + 16)) += nByte
		}
	}
	return pBuf
}

// C documentation
//
//	/*
//	** Rewind the VDBE back to the beginning in preparation for
//	** running it.
//	*/
func _sqlite3VdbeRewind(tls *libc.TLS, p uintptr) {
	/* There should be at least one opcode.
	 */
	(*TVdbe)(unsafe.Pointer(p)).FeVdbeState = uint8(VDBE_READY_STATE)
	(*TVdbe)(unsafe.Pointer(p)).Fpc = -int32(1)
	(*TVdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
	(*TVdbe)(unsafe.Pointer(p)).FerrorAction = uint8(OE_Abort)
	(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
	(*TVdbe)(unsafe.Pointer(p)).FcacheCtr = uint32(1)
	(*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat = uint8(255)
	(*TVdbe)(unsafe.Pointer(p)).FiStatement = 0
	(*TVdbe)(unsafe.Pointer(p)).FnFkConstraint = 0
}

// 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)(unsafe.Pointer(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 += nCursor
	if nCursor == 0 && nMem > 0 {
		nMem++
	} /* 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 = int32((libc.Uint32FromInt64(20)*uint32((*TVdbe)(unsafe.Pointer(p)).FnOp) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7))) /* Bytes of opcode memory used */
	(*(*TReusableSpace)(unsafe.Pointer(bp + 8))).FpSpace = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(n)                                       /* Unused opcode memory */
	(*(*TReusableSpace)(unsafe.Pointer(bp + 8))).FnFree = int64(((*TParse)(unsafe.Pointer(pParse)).FszOpAlloc - n) & ^libc.Int32FromInt32(7))  /* Bytes of unused memory */
	_resolveP2Values(tls, p, bp)
	libc.SetBitFieldPtr16Uint32(p+152, uint32(libc.BoolUint8((*TParse)(unsafe.Pointer(pParse)).FisMultiWrite != 0 && (*TParse)(unsafe.Pointer(pParse)).FmayAbort != 0)), 5, 0x20)
	if (*TParse)(unsafe.Pointer(pParse)).Fexplain != 0 {
		if nMem < int32(10) {
			nMem = int32(10)
		}
		libc.SetBitFieldPtr16Uint32(p+152, uint32((*TParse)(unsafe.Pointer(pParse)).Fexplain), 2, 0xc)
		(*TVdbe)(unsafe.Pointer(p)).FnResColumn = uint16(int32(12) - int32(4)*int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0xc>>2)))
	}
	libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(0), 0, 0x3)
	/* 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)(unsafe.Pointer(bp + 8))).FnNeeded = 0
	(*TVdbe)(unsafe.Pointer(p)).FaMem = _allocSpace(tls, bp+8, uintptr(0), int64(uint32(uint32(nMem))*uint32(40)))
	(*TVdbe)(unsafe.Pointer(p)).FaVar = _allocSpace(tls, bp+8, uintptr(0), int64(uint32(uint32(nVar))*uint32(40)))
	(*TVdbe)(unsafe.Pointer(p)).FapArg = _allocSpace(tls, bp+8, uintptr(0), int64(uint32(*(*int32)(unsafe.Pointer(bp)))*uint32(4)))
	(*TVdbe)(unsafe.Pointer(p)).FapCsr = _allocSpace(tls, bp+8, uintptr(0), int64(uint32(uint32(nCursor))*uint32(4)))
	if (*(*TReusableSpace)(unsafe.Pointer(bp + 8))).FnNeeded != 0 {
		v1 = _sqlite3DbMallocRawNN(tls, db, uint64((*(*TReusableSpace)(unsafe.Pointer(bp + 8))).FnNeeded))
		(*TVdbe)(unsafe.Pointer(p)).FpFree = v1
		(*(*TReusableSpace)(unsafe.Pointer(bp + 8))).FpSpace = v1
		(*(*TReusableSpace)(unsafe.Pointer(bp + 8))).FnFree = (*(*TReusableSpace)(unsafe.Pointer(bp + 8))).FnNeeded
		if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
			(*TVdbe)(unsafe.Pointer(p)).FaMem = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FaMem, int64(uint32(uint32(nMem))*uint32(40)))
			(*TVdbe)(unsafe.Pointer(p)).FaVar = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FaVar, int64(uint32(uint32(nVar))*uint32(40)))
			(*TVdbe)(unsafe.Pointer(p)).FapArg = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FapArg, int64(uint32(*(*int32)(unsafe.Pointer(bp)))*uint32(4)))
			(*TVdbe)(unsafe.Pointer(p)).FapCsr = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FapCsr, int64(uint32(uint32(nCursor))*uint32(4)))
		}
	}
	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(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, uint32(uint32(nCursor))*uint32(4))
	}
	_sqlite3VdbeRewind(tls, p)
}

// C documentation
//
//	/*
//	** Close a VDBE cursor and release all the resources that cursor
//	** happens to hold.
//	*/
func _sqlite3VdbeFreeCursor(tls *libc.TLS, p uintptr, pCx uintptr) {
	if pCx != 0 {
		_sqlite3VdbeFreeCursorNN(tls, p, pCx)
	}
}

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), 4, 0x10)
	(*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)
}

func _sqlite3VdbeFreeCursorNN(tls *libc.TLS, p uintptr, pCx uintptr) {
	var pModule, pVCur uintptr
	_, _ = pModule, pVCur
	if int32(TBool(*(*uint8)(unsafe.Pointer(pCx + 8))&0x10>>4)) != 0 {
		_freeCursorWithCache(tls, p, pCx)
		return
	}
	switch int32((*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 + 36)))
	case int32(CURTYPE_VTAB):
		pVCur = *(*uintptr)(unsafe.Pointer(pCx + 36))
		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--
		(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxClose})))(tls, pVCur)
		break
	}
}

// C documentation
//
//	/*
//	** Close all cursors in the current frame.
//	*/
func _closeCursorsInFrame(tls *libc.TLS, p uintptr) {
	var i int32
	var pC uintptr
	_, _ = i, pC
	i = 0
	for {
		if !(i < (*TVdbe)(unsafe.Pointer(p)).FnCursor) {
			break
		}
		pC = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(i)*4))
		if pC != 0 {
			_sqlite3VdbeFreeCursorNN(tls, p, pC)
			*(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(i)*4)) = uintptr(0)
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Copy the values stored in the VdbeFrame structure to its Vdbe. This
//	** is used, for example, when a trigger sub-program is halted to restore
//	** control to the main program.
//	*/
func _sqlite3VdbeFrameRestore(tls *libc.TLS, pFrame uintptr) (r int32) {
	var v uintptr
	_ = v
	v = (*TVdbeFrame)(unsafe.Pointer(pFrame)).Fv
	_closeCursorsInFrame(tls, v)
	(*TVdbe)(unsafe.Pointer(v)).FaOp = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FaOp
	(*TVdbe)(unsafe.Pointer(v)).FnOp = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FnOp
	(*TVdbe)(unsafe.Pointer(v)).FaMem = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FaMem
	(*TVdbe)(unsafe.Pointer(v)).FnMem = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FnMem
	(*TVdbe)(unsafe.Pointer(v)).FapCsr = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FapCsr
	(*TVdbe)(unsafe.Pointer(v)).FnCursor = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FnCursor
	(*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).Fdb)).FlastRowid = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FlastRowid
	(*TVdbe)(unsafe.Pointer(v)).FnChange = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FnChange
	(*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).Fdb)).FnChange = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FnDbChange
	_sqlite3VdbeDeleteAuxData(tls, (*TVdbe)(unsafe.Pointer(v)).Fdb, v+228, -int32(1), 0)
	(*TVdbe)(unsafe.Pointer(v)).FpAuxData = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FpAuxData
	(*TVdbeFrame)(unsafe.Pointer(pFrame)).FpAuxData = uintptr(0)
	return (*TVdbeFrame)(unsafe.Pointer(pFrame)).Fpc
}

// C documentation
//
//	/*
//	** Close all cursors.
//	**
//	** Also release any dynamic memory held by the VM in the Vdbe.aMem memory
//	** cell array. This is necessary as the memory cell array may contain
//	** pointers to VdbeFrame objects, which may in turn contain pointers to
//	** open cursors.
//	*/
func _closeAllCursors(tls *libc.TLS, p uintptr) {
	var pDel, pFrame uintptr
	_, _ = pDel, pFrame
	if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
		pFrame = (*TVdbe)(unsafe.Pointer(p)).FpFrame
		for {
			if !((*TVdbeFrame)(unsafe.Pointer(pFrame)).FpParent != 0) {
				break
			}
			goto _1
		_1:
			;
			pFrame = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FpParent
		}
		_sqlite3VdbeFrameRestore(tls, pFrame)
		(*TVdbe)(unsafe.Pointer(p)).FpFrame = uintptr(0)
		(*TVdbe)(unsafe.Pointer(p)).FnFrame = 0
	}
	_closeCursorsInFrame(tls, p)
	_releaseMemArray(tls, (*TVdbe)(unsafe.Pointer(p)).FaMem, (*TVdbe)(unsafe.Pointer(p)).FnMem)
	for (*TVdbe)(unsafe.Pointer(p)).FpDelFrame != 0 {
		pDel = (*TVdbe)(unsafe.Pointer(p)).FpDelFrame
		(*TVdbe)(unsafe.Pointer(p)).FpDelFrame = (*TVdbeFrame)(unsafe.Pointer(pDel)).FpParent
		_sqlite3VdbeFrameDelete(tls, pDel)
	}
	/* Delete any auxdata allocations made by the VM */
	if (*TVdbe)(unsafe.Pointer(p)).FpAuxData != 0 {
		_sqlite3VdbeDeleteAuxData(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, p+228, -int32(1), 0)
	}
}

// C documentation
//
//	/*
//	** Set the number of result columns that will be returned by this SQL
//	** statement. This is now set at compile time, rather than during
//	** execution of the vdbe program so that sqlite3_column_count() can
//	** be called on an SQL statement before sqlite3_step().
//	*/
func _sqlite3VdbeSetNumCols(tls *libc.TLS, p uintptr, nResColumn int32) {
	var db uintptr
	var n int32
	var v1 Tu16
	_, _, _ = db, n, v1
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	if (*TVdbe)(unsafe.Pointer(p)).FnResAlloc != 0 {
		_releaseMemArray(tls, (*TVdbe)(unsafe.Pointer(p)).FaColName, int32((*TVdbe)(unsafe.Pointer(p)).FnResAlloc)*int32(COLNAME_N))
		_sqlite3DbFree(tls, db, (*TVdbe)(unsafe.Pointer(p)).FaColName)
	}
	n = nResColumn * int32(COLNAME_N)
	v1 = uint16(uint16(nResColumn))
	(*TVdbe)(unsafe.Pointer(p)).FnResAlloc = v1
	(*TVdbe)(unsafe.Pointer(p)).FnResColumn = v1
	(*TVdbe)(unsafe.Pointer(p)).FaColName = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(40)*uint32(uint32(n))))
	if (*TVdbe)(unsafe.Pointer(p)).FaColName == uintptr(0) {
		return
	}
	_initMemArray(tls, (*TVdbe)(unsafe.Pointer(p)).FaColName, n, db, uint16(MEM_Null))
}

// C documentation
//
//	/*
//	** Set the name of the idx'th column to be returned by the SQL statement.
//	** zName must be a pointer to a nul terminated string.
//	**
//	** This call must be made after a call to sqlite3VdbeSetNumCols().
//	**
//	** The final parameter, xDel, must be one of SQLITE_DYNAMIC, SQLITE_STATIC
//	** or SQLITE_TRANSIENT. If it is SQLITE_DYNAMIC, then the buffer pointed
//	** to by zName will be freed by sqlite3DbFree() when the vdbe is destroyed.
//	*/
func _sqlite3VdbeSetColName(tls *libc.TLS, p uintptr, idx int32, var1 int32, zName uintptr, xDel uintptr) (r int32) {
	var pColName uintptr
	var rc int32
	_, _ = pColName, rc
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return int32(SQLITE_NOMEM)
	}
	pColName = (*TVdbe)(unsafe.Pointer(p)).FaColName + uintptr(idx+var1*int32((*TVdbe)(unsafe.Pointer(p)).FnResAlloc))*40
	rc = _sqlite3VdbeMemSetStr(tls, pColName, zName, int64(-int32(1)), uint8(SQLITE_UTF8), xDel)
	return rc
}

// C documentation
//
//	/*
//	** A read or write transaction may or may not be active on database handle
//	** db. If a transaction is active, commit it. If there is a
//	** write-transaction spanning more than one database file, this routine
//	** takes care of the super-journal trickery.
//	*/
func _vdbeCommit(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, nMainFile, nTrans, needXcommit, rc, retryCount, v5 int32
	var offset Ti64
	var pBt, pBt1, pBt2, pBt3, pBt4, pBt5, pPager, pVfs, zFile, zMainFile, zSuper uintptr
	var v6 bool
	var _ /* iRandom at bp+8 */ Tu32
	var _ /* pSuperJrnl at bp+0 */ uintptr
	var _ /* res at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, nMainFile, nTrans, needXcommit, offset, pBt, pBt1, pBt2, pBt3, pBt4, pBt5, pPager, pVfs, rc, retryCount, zFile, zMainFile, zSuper, v5, v6
	nTrans = 0 /* Number of databases with an active write-transaction
	 ** that are candidates for a two-phase commit using a
	 ** super-journal */
	rc = SQLITE_OK
	needXcommit = 0
	/* Before doing anything else, call the xSync() callback for any
	 ** virtual module tables written in this transaction. This has to
	 ** be done before determining whether a super-journal file is
	 ** required, as an xSync() callback may add an attached database
	 ** to the transaction.
	 */
	rc = _sqlite3VtabSync(tls, db, p)
	/* This loop determines (a) if the commit hook should be invoked and
	 ** (b) how many database files have open write transactions, not
	 ** including the temp database. (b) is important because if more than
	 ** one database file has an open write transaction, a super-journal
	 ** file is required for an atomic commit.
	 */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if _sqlite3BtreeTxnState(tls, pBt) == int32(SQLITE_TXN_WRITE) {
			needXcommit = int32(1)
			_sqlite3BtreeEnter(tls, pBt)
			pPager = _sqlite3BtreePager(tls, pBt)
			if int32((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).Fsafety_level) != int32(PAGER_SYNCHRONOUS_OFF) && _aMJNeeded[_sqlite3PagerGetJournalMode(tls, pPager)] != 0 && _sqlite3PagerIsMemdb(tls, pPager) == 0 {
				nTrans++
			}
			rc = _sqlite3PagerExclusiveLock(tls, pPager)
			_sqlite3BtreeLeave(tls, pBt)
		}
		goto _1
	_1:
		;
		i++
	}
	if rc != SQLITE_OK {
		return rc
	}
	/* If there are any write-transactions at all, invoke the commit hook */
	if needXcommit != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FxCommitCallback != 0 {
		rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxCommitCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpCommitArg)
		if rc != 0 {
			return libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
		}
	}
	/* The simple case - no more than one database file (not counting the
	 ** TEMP database) has a transaction active.   There is no need for the
	 ** super-journal.
	 **
	 ** If the return value of sqlite3BtreeGetFilename() is a zero length
	 ** string, it means the main database is :memory: or a temp file.  In
	 ** that case we do not support atomic multi-file commits, so use the
	 ** simple case then too.
	 */
	if 0 == _sqlite3Strlen30(tls, _sqlite3BtreeGetFilename(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)) || nTrans <= int32(1) {
		i = 0
		for {
			if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt1 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if pBt1 != 0 {
				rc = _sqlite3BtreeCommitPhaseOne(tls, pBt1, uintptr(0))
			}
			goto _2
		_2:
			;
			i++
		}
		/* Do the commit only if all databases successfully complete phase 1.
		 ** If one of the BtreeCommitPhaseOne() calls fails, this indicates an
		 ** IO error while deleting or truncating a journal file. It is unlikely,
		 ** but could happen. In this case abandon processing and return the error.
		 */
		i = 0
		for {
			if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt2 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if pBt2 != 0 {
				rc = _sqlite3BtreeCommitPhaseTwo(tls, pBt2, 0)
			}
			goto _3
		_3:
			;
			i++
		}
		if rc == SQLITE_OK {
			_sqlite3VtabCommit(tls, db)
		}
	} else {
		pVfs = (*Tsqlite3)(unsafe.Pointer(db)).FpVfs
		zSuper = uintptr(0) /* File-name for the super-journal */
		zMainFile = _sqlite3BtreeGetFilename(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		offset = 0
		retryCount = 0
		/* Select a super-journal file name */
		nMainFile = _sqlite3Strlen30(tls, zMainFile)
		zSuper = _sqlite3MPrintf(tls, db, __ccgo_ts+6544, libc.VaList(bp+24, 0, zMainFile, 0))
		if zSuper == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		zSuper += uintptr(4)
		for cond := true; cond; cond = rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
			if retryCount != 0 {
				if retryCount > int32(100) {
					Xsqlite3_log(tls, int32(SQLITE_FULL), __ccgo_ts+6556, libc.VaList(bp+24, zSuper))
					_sqlite3OsDelete(tls, pVfs, zSuper, 0)
					break
				} else {
					if retryCount == int32(1) {
						Xsqlite3_log(tls, int32(SQLITE_FULL), __ccgo_ts+6570, libc.VaList(bp+24, zSuper))
					}
				}
			}
			retryCount++
			Xsqlite3_randomness(tls, int32(4), bp+8)
			Xsqlite3_snprintf(tls, int32(13), zSuper+uintptr(nMainFile), __ccgo_ts+6585, libc.VaList(bp+24, *(*Tu32)(unsafe.Pointer(bp + 8))>>libc.Int32FromInt32(8)&uint32(0xffffff), *(*Tu32)(unsafe.Pointer(bp + 8))&uint32(0xff)))
			/* The antipenultimate character of the super-journal name must
			 ** be "9" to avoid name collisions when using 8+3 filenames. */
			rc = _sqlite3OsAccess(tls, pVfs, zSuper, SQLITE_ACCESS_EXISTS, bp+4)
		}
		if rc == SQLITE_OK {
			/* Open the super-journal. */
			rc = _sqlite3OsOpenMalloc(tls, pVfs, zSuper, bp, libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)|libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE)|libc.Int32FromInt32(SQLITE_OPEN_SUPER_JOURNAL), uintptr(0))
		}
		if rc != SQLITE_OK {
			_sqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}
		/* Write the name of each database file in the transaction into the new
		 ** super-journal file. If an error occurs at this point close
		 ** and delete the super-journal file. All the individual journal files
		 ** still have 'null' as the super-journal pointer, so they will roll
		 ** back independently if a failure occurs.
		 */
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt3 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if _sqlite3BtreeTxnState(tls, pBt3) == int32(SQLITE_TXN_WRITE) {
				zFile = _sqlite3BtreeGetJournalname(tls, pBt3)
				if zFile == uintptr(0) {
					goto _4 /* Ignore TEMP and :memory: databases */
				}
				rc = _sqlite3OsWrite(tls, *(*uintptr)(unsafe.Pointer(bp)), zFile, _sqlite3Strlen30(tls, zFile)+int32(1), offset)
				offset += int64(_sqlite3Strlen30(tls, zFile) + int32(1))
				if rc != SQLITE_OK {
					_sqlite3OsCloseFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
					_sqlite3OsDelete(tls, pVfs, zSuper, 0)
					_sqlite3DbFree(tls, db, zSuper-uintptr(4))
					return rc
				}
			}
			goto _4
		_4:
			;
			i++
		}
		/* Sync the super-journal file. If the IOCAP_SEQUENTIAL device
		 ** flag is set this is not required.
		 */
		if v6 = 0 == _sqlite3OsDeviceCharacteristics(tls, *(*uintptr)(unsafe.Pointer(bp)))&int32(SQLITE_IOCAP_SEQUENTIAL); v6 {
			v5 = _sqlite3OsSync(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(SQLITE_SYNC_NORMAL))
			rc = v5
		}
		if v6 && SQLITE_OK != v5 {
			_sqlite3OsCloseFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
			_sqlite3OsDelete(tls, pVfs, zSuper, 0)
			_sqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}
		/* Sync all the db files involved in the transaction. The same call
		 ** sets the super-journal pointer in each individual journal. If
		 ** an error occurs here, do not delete the super-journal file.
		 **
		 ** If the error occurs during the first call to
		 ** sqlite3BtreeCommitPhaseOne(), then there is a chance that the
		 ** super-journal file will be orphaned. But we cannot delete it,
		 ** in case the super-journal file name was written into the journal
		 ** file before the failure occurred.
		 */
		i = 0
		for {
			if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt4 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if pBt4 != 0 {
				rc = _sqlite3BtreeCommitPhaseOne(tls, pBt4, zSuper)
			}
			goto _7
		_7:
			;
			i++
		}
		_sqlite3OsCloseFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if rc != SQLITE_OK {
			_sqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}
		/* Delete the super-journal file. This commits the transaction. After
		 ** doing this the directory is synced again before any individual
		 ** transaction files are deleted.
		 */
		rc = _sqlite3OsDelete(tls, pVfs, zSuper, int32(1))
		_sqlite3DbFree(tls, db, zSuper-uintptr(4))
		zSuper = uintptr(0)
		if rc != 0 {
			return rc
		}
		/* All files and directories have already been synced, so the following
		 ** calls to sqlite3BtreeCommitPhaseTwo() are only closing files and
		 ** deleting or truncating journals. If something goes wrong while
		 ** this is happening we don't really care. The integrity of the
		 ** transaction is already guaranteed, but some stray 'cold' journals
		 ** may be lying around. Returning an error code won't help matters.
		 */
		_sqlite3BeginBenignMalloc(tls)
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt5 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if pBt5 != 0 {
				_sqlite3BtreeCommitPhaseTwo(tls, pBt5, int32(1))
			}
			goto _8
		_8:
			;
			i++
		}
		_sqlite3EndBenignMalloc(tls)
		_sqlite3VtabCommit(tls, db)
	}
	return rc
}

/* Whether or not a database might need a super-journal depends upon
 ** its journal mode (among other things).  This matrix determines which
 ** journal modes use a super-journal and which do not */
var _aMJNeeded = [6]Tu8{
	0: uint8(1),
	1: uint8(1),
	3: uint8(1),
}

/*
** This routine checks that the sqlite3.nVdbeActive count variable
** matches the number of vdbe's in the list sqlite3.pVdbe that are
** currently active. An assertion fails if the two counts do not match.
** This is an internal self-check only - it is not an essential processing
** step.
**
** This is a no-op if NDEBUG is defined.
 */

// C documentation
//
//	/*
//	** If the Vdbe passed as the first argument opened a statement-transaction,
//	** close it now. Argument eOp must be either SAVEPOINT_ROLLBACK or
//	** SAVEPOINT_RELEASE. If it is SAVEPOINT_ROLLBACK, then the statement
//	** transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the
//	** statement transaction is committed.
//	**
//	** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned.
//	** Otherwise SQLITE_OK.
//	*/
func _vdbeCloseStatement(tls *libc.TLS, p uintptr, eOp int32) (r int32) {
	var db, pBt uintptr
	var i, iSavepoint, rc, rc2 int32
	_, _, _, _, _, _ = db, i, iSavepoint, pBt, rc, rc2
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	rc = SQLITE_OK
	iSavepoint = (*TVdbe)(unsafe.Pointer(p)).FiStatement - int32(1)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		rc2 = SQLITE_OK
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 {
			if eOp == int32(SAVEPOINT_ROLLBACK) {
				rc2 = _sqlite3BtreeSavepoint(tls, pBt, int32(SAVEPOINT_ROLLBACK), iSavepoint)
			}
			if rc2 == SQLITE_OK {
				rc2 = _sqlite3BtreeSavepoint(tls, pBt, int32(SAVEPOINT_RELEASE), iSavepoint)
			}
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
		goto _1
	_1:
		;
		i++
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FnStatement--
	(*TVdbe)(unsafe.Pointer(p)).FiStatement = 0
	if rc == SQLITE_OK {
		if eOp == int32(SAVEPOINT_ROLLBACK) {
			rc = _sqlite3VtabSavepoint(tls, db, int32(SAVEPOINT_ROLLBACK), iSavepoint)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3VtabSavepoint(tls, db, int32(SAVEPOINT_RELEASE), iSavepoint)
		}
	}
	/* If the statement transaction is being rolled back, also restore the
	 ** database handles deferred constraint counter to the value it had when
	 ** the statement transaction was opened.  */
	if eOp == int32(SAVEPOINT_ROLLBACK) {
		(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = (*TVdbe)(unsafe.Pointer(p)).FnStmtDefCons
		(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = (*TVdbe)(unsafe.Pointer(p)).FnStmtDefImmCons
	}
	return rc
}

func _sqlite3VdbeCloseStatement(tls *libc.TLS, p uintptr, eOp int32) (r int32) {
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FnStatement != 0 && (*TVdbe)(unsafe.Pointer(p)).FiStatement != 0 {
		return _vdbeCloseStatement(tls, p, eOp)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function is called when a transaction opened by the database
//	** handle associated with the VM passed as an argument is about to be
//	** committed. If there are outstanding deferred foreign key constraint
//	** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK.
//	**
//	** If there are outstanding FK violations and this function returns
//	** SQLITE_ERROR, set the result of the VM to SQLITE_CONSTRAINT_FOREIGNKEY
//	** and write an error message to it. Then return SQLITE_ERROR.
//	*/
func _sqlite3VdbeCheckFk(tls *libc.TLS, p uintptr, deferred int32) (r int32) {
	var db uintptr
	_ = db
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	if deferred != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons+(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons > 0 || !(deferred != 0) && (*TVdbe)(unsafe.Pointer(p)).FnFkConstraint > 0 {
		(*TVdbe)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
		(*TVdbe)(unsafe.Pointer(p)).FerrorAction = uint8(OE_Abort)
		_sqlite3VdbeError(tls, p, __ccgo_ts+6598, 0)
		if int32((*TVdbe)(unsafe.Pointer(p)).FprepFlags)&int32(SQLITE_PREPARE_SAVESQL) == 0 {
			return int32(SQLITE_ERROR)
		}
		return libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
	}
	return SQLITE_OK
}

// 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, v2 int32
	_, _, _, _, _, _, _ = db, eStatementOp, isSpecialError, mrc, rc, v1, v2 /* 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 + 152))&0x80>>7)) != 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 + 152))&0x40>>6)) != 0) || mrc != int32(SQLITE_INTERRUPT) {
				if (mrc == int32(SQLITE_NOMEM) || mrc == int32(SQLITE_FULL)) && int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x20>>5)) != 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 || int32((*TVdbe)(unsafe.Pointer(p)).FerrorAction) == int32(OE_Fail) && !(isSpecialError != 0) {
			_sqlite3VdbeCheckFk(tls, p, 0)
		}
		/* 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 + 152))&0x40>>6)) == 0) {
			if (*TVdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || int32((*TVdbe)(unsafe.Pointer(p)).FerrorAction) == int32(OE_Fail) && !(isSpecialError != 0) {
				rc = _sqlite3VdbeCheckFk(tls, p, int32(1))
				if rc != SQLITE_OK {
					if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x40>>6)) != 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&(uint64(libc.Int32FromInt32(0x00002))<<libc.Int32FromInt32(32)) != 0 {
						rc = int32(SQLITE_CORRUPT)
						*(*Tu64)(unsafe.Pointer(db + 32)) &= ^(uint64(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 + 152))&0x40>>6)) != 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)(unsafe.Pointer(db + 32)) &= ^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 || int32((*TVdbe)(unsafe.Pointer(p)).FerrorAction) == int32(OE_Fail) {
					eStatementOp = int32(SAVEPOINT_RELEASE)
				} else {
					if int32((*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 + 152))&0x10>>4)) != 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--
	if !(int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x40>>6)) != 0) {
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite--
	}
	if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x80>>7)) != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead--
	}
	(*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) {
		v2 = int32(SQLITE_BUSY)
	} else {
		v2 = SQLITE_OK
	}
	return v2
}

// C documentation
//
//	/*
//	** Each VDBE holds the result of the most recent sqlite3_step() call
//	** in p->rc.  This routine sets that result back to SQLITE_OK.
//	*/
func _sqlite3VdbeResetStepResult(tls *libc.TLS, p uintptr) {
	(*TVdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
}

// C documentation
//
//	/*
//	** Copy the error code and error message belonging to the VDBE passed
//	** as the first argument to its database handle (so that they will be
//	** returned by calls to sqlite3_errcode() and sqlite3_errmsg()).
//	**
//	** This function does not clear the VDBE error code or message, just
//	** copies them to the database handle.
//	*/
func _sqlite3VdbeTransferError(tls *libc.TLS, p uintptr) (r int32) {
	var db uintptr
	var rc int32
	_, _ = db, rc
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	rc = (*TVdbe)(unsafe.Pointer(p)).Frc
	if (*TVdbe)(unsafe.Pointer(p)).FzErrMsg != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FbBenignMalloc++
		_sqlite3BeginBenignMalloc(tls)
		if (*Tsqlite3)(unsafe.Pointer(db)).FpErr == uintptr(0) {
			(*Tsqlite3)(unsafe.Pointer(db)).FpErr = _sqlite3ValueNew(tls, db)
		}
		_sqlite3ValueSetStr(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr, -int32(1), (*TVdbe)(unsafe.Pointer(p)).FzErrMsg, uint8(SQLITE_UTF8), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3EndBenignMalloc(tls)
		(*Tsqlite3)(unsafe.Pointer(db)).FbBenignMalloc--
	} else {
		if (*Tsqlite3)(unsafe.Pointer(db)).FpErr != 0 {
			_sqlite3ValueSetNull(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
		}
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = rc
	(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = -int32(1)
	return rc
}

// C documentation
//
//	/*
//	** Clean up a VDBE after execution but do not delete the VDBE just yet.
//	** Write any error messages into *pzErrMsg.  Return the result code.
//	**
//	** After this routine is run, the VDBE should be ready to be executed
//	** again.
//	**
//	** To look at it another way, this routine resets the state of the
//	** virtual machine from VDBE_RUN_STATE or VDBE_HALT_STATE back to
//	** VDBE_READY_STATE.
//	*/
func _sqlite3VdbeReset(tls *libc.TLS, p uintptr) (r int32) {
	var db uintptr
	_ = db
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	/* If the VM did not run to completion or if it encountered an
	 ** error, then it might not have been halted properly.  So halt
	 ** it now.
	 */
	if int32((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_RUN_STATE) {
		_sqlite3VdbeHalt(tls, p)
	}
	/* If the VDBE has been run even partially, then transfer the error code
	 ** and error message from the VDBE into the main database structure.  But
	 ** if the VDBE has just been set to run but has not actually executed any
	 ** instructions yet, leave the main database error information unchanged.
	 */
	if (*TVdbe)(unsafe.Pointer(p)).Fpc >= 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FpErr != 0 || (*TVdbe)(unsafe.Pointer(p)).FzErrMsg != 0 {
			_sqlite3VdbeTransferError(tls, p)
		} else {
			(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = (*TVdbe)(unsafe.Pointer(p)).Frc
		}
	}
	/* Reset register contents and reclaim error message memory.
	 */
	if (*TVdbe)(unsafe.Pointer(p)).FzErrMsg != 0 {
		_sqlite3DbFree(tls, db, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg)
		(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = uintptr(0)
	}
	(*TVdbe)(unsafe.Pointer(p)).FpResultRow = uintptr(0)
	/* Save profiling information from this VDBE run.
	 */
	return (*TVdbe)(unsafe.Pointer(p)).Frc & (*Tsqlite3)(unsafe.Pointer(db)).FerrMask
}

// C documentation
//
//	/*
//	** Clean up and delete a VDBE after execution.  Return an integer which is
//	** the result code.  Write any error message text into *pzErrMsg.
//	*/
func _sqlite3VdbeFinalize(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if int32((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) >= int32(VDBE_READY_STATE) {
		rc = _sqlite3VdbeReset(tls, p)
	}
	_sqlite3VdbeDelete(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** If parameter iOp is less than zero, then invoke the destructor for
//	** all auxiliary data pointers currently cached by the VM passed as
//	** the first argument.
//	**
//	** Or, if iOp is greater than or equal to zero, then the destructor is
//	** only invoked for those auxiliary data pointers created by the user
//	** function invoked by the OP_Function opcode at instruction iOp of
//	** VM pVdbe, and only then if:
//	**
//	**    * the associated function parameter is the 32nd or later (counting
//	**      from left to right), or
//	**
//	**    * the corresponding bit in argument mask is clear (where the first
//	**      function parameter corresponds to bit 0 etc.).
//	*/
func _sqlite3VdbeDeleteAuxData(tls *libc.TLS, db uintptr, pp uintptr, iOp int32, mask int32) {
	var pAux uintptr
	_ = pAux
	for *(*uintptr)(unsafe.Pointer(pp)) != 0 {
		pAux = *(*uintptr)(unsafe.Pointer(pp))
		if iOp < 0 || (*TAuxData)(unsafe.Pointer(pAux)).FiAuxOp == iOp && (*TAuxData)(unsafe.Pointer(pAux)).FiAuxArg >= 0 && ((*TAuxData)(unsafe.Pointer(pAux)).FiAuxArg > int32(31) || !(uint32(uint32(mask))&(libc.Uint32FromInt32(1)<<(*TAuxData)(unsafe.Pointer(pAux)).FiAuxArg) != 0)) {
			if (*TAuxData)(unsafe.Pointer(pAux)).FxDeleteAux != 0 {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TAuxData)(unsafe.Pointer(pAux)).FxDeleteAux})))(tls, (*TAuxData)(unsafe.Pointer(pAux)).FpAux)
			}
			*(*uintptr)(unsafe.Pointer(pp)) = (*TAuxData)(unsafe.Pointer(pAux)).FpNextAux
			_sqlite3DbFree(tls, db, pAux)
		} else {
			pp = pAux + 16
		}
	}
}

// C documentation
//
//	/*
//	** Free all memory associated with the Vdbe passed as the second argument,
//	** except for object itself, which is preserved.
//	**
//	** The difference between this function and sqlite3VdbeDelete() is that
//	** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
//	** the database connection and frees the object itself.
//	*/
func _sqlite3VdbeClearObject(tls *libc.TLS, db uintptr, p uintptr) {
	var pNext, pSub uintptr
	_, _ = pNext, pSub
	if (*TVdbe)(unsafe.Pointer(p)).FaColName != 0 {
		_releaseMemArray(tls, (*TVdbe)(unsafe.Pointer(p)).FaColName, int32((*TVdbe)(unsafe.Pointer(p)).FnResAlloc)*int32(COLNAME_N))
		_sqlite3DbNNFreeNN(tls, db, (*TVdbe)(unsafe.Pointer(p)).FaColName)
	}
	pSub = (*TVdbe)(unsafe.Pointer(p)).FpProgram
	for {
		if !(pSub != 0) {
			break
		}
		pNext = (*TSubProgram)(unsafe.Pointer(pSub)).FpNext
		_vdbeFreeOpArray(tls, db, (*TSubProgram)(unsafe.Pointer(pSub)).FaOp, (*TSubProgram)(unsafe.Pointer(pSub)).FnOp)
		_sqlite3DbFree(tls, db, pSub)
		goto _1
	_1:
		;
		pSub = pNext
	}
	if int32((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) != VDBE_INIT_STATE {
		_releaseMemArray(tls, (*TVdbe)(unsafe.Pointer(p)).FaVar, int32((*TVdbe)(unsafe.Pointer(p)).FnVar))
		if (*TVdbe)(unsafe.Pointer(p)).FpVList != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TVdbe)(unsafe.Pointer(p)).FpVList)
		}
		if (*TVdbe)(unsafe.Pointer(p)).FpFree != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TVdbe)(unsafe.Pointer(p)).FpFree)
		}
	}
	_vdbeFreeOpArray(tls, db, (*TVdbe)(unsafe.Pointer(p)).FaOp, (*TVdbe)(unsafe.Pointer(p)).FnOp)
	if (*TVdbe)(unsafe.Pointer(p)).FzSql != 0 {
		_sqlite3DbNNFreeNN(tls, db, (*TVdbe)(unsafe.Pointer(p)).FzSql)
	}
}

// C documentation
//
//	/*
//	** Delete an entire VDBE.
//	*/
func _sqlite3VdbeDelete(tls *libc.TLS, p uintptr) {
	var db uintptr
	_ = db
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	_sqlite3VdbeClearObject(tls, db, p)
	if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		*(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FppVPrev)) = (*TVdbe)(unsafe.Pointer(p)).FpVNext
		if (*TVdbe)(unsafe.Pointer(p)).FpVNext != 0 {
			(*TVdbe)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FpVNext)).FppVPrev = (*TVdbe)(unsafe.Pointer(p)).FppVPrev
		}
	}
	_sqlite3DbNNFreeNN(tls, db, p)
}

// C documentation
//
//	/*
//	** The cursor "p" has a pending seek operation that has not yet been
//	** carried out.  Seek the cursor now.  If an error occurs, return
//	** the appropriate error code.
//	*/
func _sqlite3VdbeFinishMoveto(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* res at bp+0 */ int32
	_ = rc
	rc = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(p + 36)), (*TVdbeCursor)(unsafe.Pointer(p)).FmovetoTarget, 0, bp)
	if rc != 0 {
		return rc
	}
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		return _sqlite3CorruptError(tls, int32(88615))
	}
	(*TVdbeCursor)(unsafe.Pointer(p)).FdeferredMoveto = uint8(0)
	(*TVdbeCursor)(unsafe.Pointer(p)).FcacheStatus = uint32(CACHE_STALE)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Something has moved cursor "p" out of place.  Maybe the row it was
//	** pointed to was deleted out from under it.  Or maybe the btree was
//	** rebalanced.  Whatever the cause, try to restore "p" to the place it
//	** is supposed to be pointing.  If the row was deleted out from under the
//	** cursor, set the cursor to point to a NULL row.
//	*/
func _sqlite3VdbeHandleMovedCursor(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* isDifferentRow at bp+0 */ int32
	_ = rc
	rc = _sqlite3BtreeCursorRestore(tls, *(*uintptr)(unsafe.Pointer(p + 36)), bp)
	(*TVdbeCursor)(unsafe.Pointer(p)).FcacheStatus = uint32(CACHE_STALE)
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		(*TVdbeCursor)(unsafe.Pointer(p)).FnullRow = uint8(1)
	}
	return rc
}

// C documentation
//
//	/*
//	** Check to ensure that the cursor is valid.  Restore the cursor
//	** if need be.  Return any I/O error from the restore operation.
//	*/
func _sqlite3VdbeCursorRestore(tls *libc.TLS, p uintptr) (r int32) {
	if _sqlite3BtreeCursorHasMoved(tls, *(*uintptr)(unsafe.Pointer(p + 36))) != 0 {
		return _sqlite3VdbeHandleMovedCursor(tls, p)
	}
	return SQLITE_OK
}

/*
** The following functions:
**
** sqlite3VdbeSerialType()
** sqlite3VdbeSerialTypeLen()
** sqlite3VdbeSerialLen()
** sqlite3VdbeSerialPut()  <--- in-lined into OP_MakeRecord as of 2022-04-02
** sqlite3VdbeSerialGet()
**
** encapsulate the code that serializes values for storage in SQLite
** data and index records. Each serialized value consists of a
** 'serial-type' and a blob of data. The serial type is an 8-byte unsigned
** integer, stored as a varint.
**
** In an SQLite index record, the serial type is stored directly before
** the blob of data that it corresponds to. In a table record, all serial
** types are stored at the start of the record, and the blobs of data at
** the end. Hence these functions allow the caller to handle the
** serial-type and data blob separately.
**
** The following table describes the various storage classes for data:
**
**   serial type        bytes of data      type
**   --------------     ---------------    ---------------
**      0                     0            NULL
**      1                     1            signed integer
**      2                     2            signed integer
**      3                     3            signed integer
**      4                     4            signed integer
**      5                     6            signed integer
**      6                     8            signed integer
**      7                     8            IEEE float
**      8                     0            Integer constant 0
**      9                     0            Integer constant 1
**     10,11                               reserved for expansion
**    N>=12 and even       (N-12)/2        BLOB
**    N>=13 and odd        (N-13)/2        text
**
** The 8 and 9 types were added in 3.3.0, file format 4.  Prior versions
** of SQLite will not understand those serial types.
 */

// C documentation
//
//	/*
//	** The sizes for serial types less than 128
//	*/
var _sqlite3SmallTypeSizes = [128]Tu8{
	1:   uint8(1),
	2:   uint8(2),
	3:   uint8(3),
	4:   uint8(4),
	5:   uint8(6),
	6:   uint8(8),
	7:   uint8(8),
	14:  uint8(1),
	15:  uint8(1),
	16:  uint8(2),
	17:  uint8(2),
	18:  uint8(3),
	19:  uint8(3),
	20:  uint8(4),
	21:  uint8(4),
	22:  uint8(5),
	23:  uint8(5),
	24:  uint8(6),
	25:  uint8(6),
	26:  uint8(7),
	27:  uint8(7),
	28:  uint8(8),
	29:  uint8(8),
	30:  uint8(9),
	31:  uint8(9),
	32:  uint8(10),
	33:  uint8(10),
	34:  uint8(11),
	35:  uint8(11),
	36:  uint8(12),
	37:  uint8(12),
	38:  uint8(13),
	39:  uint8(13),
	40:  uint8(14),
	41:  uint8(14),
	42:  uint8(15),
	43:  uint8(15),
	44:  uint8(16),
	45:  uint8(16),
	46:  uint8(17),
	47:  uint8(17),
	48:  uint8(18),
	49:  uint8(18),
	50:  uint8(19),
	51:  uint8(19),
	52:  uint8(20),
	53:  uint8(20),
	54:  uint8(21),
	55:  uint8(21),
	56:  uint8(22),
	57:  uint8(22),
	58:  uint8(23),
	59:  uint8(23),
	60:  uint8(24),
	61:  uint8(24),
	62:  uint8(25),
	63:  uint8(25),
	64:  uint8(26),
	65:  uint8(26),
	66:  uint8(27),
	67:  uint8(27),
	68:  uint8(28),
	69:  uint8(28),
	70:  uint8(29),
	71:  uint8(29),
	72:  uint8(30),
	73:  uint8(30),
	74:  uint8(31),
	75:  uint8(31),
	76:  uint8(32),
	77:  uint8(32),
	78:  uint8(33),
	79:  uint8(33),
	80:  uint8(34),
	81:  uint8(34),
	82:  uint8(35),
	83:  uint8(35),
	84:  uint8(36),
	85:  uint8(36),
	86:  uint8(37),
	87:  uint8(37),
	88:  uint8(38),
	89:  uint8(38),
	90:  uint8(39),
	91:  uint8(39),
	92:  uint8(40),
	93:  uint8(40),
	94:  uint8(41),
	95:  uint8(41),
	96:  uint8(42),
	97:  uint8(42),
	98:  uint8(43),
	99:  uint8(43),
	100: uint8(44),
	101: uint8(44),
	102: uint8(45),
	103: uint8(45),
	104: uint8(46),
	105: uint8(46),
	106: uint8(47),
	107: uint8(47),
	108: uint8(48),
	109: uint8(48),
	110: uint8(49),
	111: uint8(49),
	112: uint8(50),
	113: uint8(50),
	114: uint8(51),
	115: uint8(51),
	116: uint8(52),
	117: uint8(52),
	118: uint8(53),
	119: uint8(53),
	120: uint8(54),
	121: uint8(54),
	122: uint8(55),
	123: uint8(55),
	124: uint8(56),
	125: uint8(56),
	126: uint8(57),
	127: uint8(57),
}

// C documentation
//
//	/*
//	** Return the length of the data corresponding to the supplied serial-type.
//	*/
func _sqlite3VdbeSerialTypeLen(tls *libc.TLS, serial_type Tu32) (r Tu32) {
	if serial_type >= uint32(128) {
		return (serial_type - uint32(12)) / uint32(2)
	} else {
		return uint32(_sqlite3SmallTypeSizes[serial_type])
	}
	return r
}

func _sqlite3VdbeOneByteSerialTypeLen(tls *libc.TLS, serial_type Tu8) (r Tu8) {
	return _sqlite3SmallTypeSizes[serial_type]
}

/*
** If we are on an architecture with mixed-endian floating
** points (ex: ARM7) then swap the lower 4 bytes with the
** upper 4 bytes.  Return the result.
**
** For most architectures, this is a no-op.
**
** (later):  It is reported to me that the mixed-endian problem
** on ARM7 is an issue with GCC, not with the ARM7 chip.  It seems
** that early versions of GCC stored the two words of a 64-bit
** float in the wrong order.  And that error has been propagated
** ever since.  The blame is not necessarily with GCC, though.
** GCC might have just copying the problem from a prior compiler.
** I am also told that newer versions of GCC that follow a different
** ABI get the byte order right.
**
** Developers using SQLite on an ARM7 should compile and run their
** application using -DSQLITE_DEBUG=1 at least once.  With DEBUG
** enabled, some asserts below will ensure that the byte order of
** floating point values is correct.
**
** (2007-08-30)  Frank van Vugt has studied this problem closely
** and has send his findings to the SQLite developers.  Frank
** writes that some Linux kernels offer floating point hardware
** emulation that uses only 32-bit mantissas instead of a full
** 48-bits as required by the IEEE standard.  (This is the
** CONFIG_FPE_FASTFPE option.)  On such systems, floating point
** byte swapping becomes very complicated.  To avoid problems,
** the necessary byte swapping is carried out using a 64-bit integer
** rather than a 64-bit float.  Frank assures us that the code here
** works for him.  We, the developers, have no way to independently
** verify this, but Frank seems to know what he is talking about
** so we trust him.
 */

/* Input "x" is a sequence of unsigned characters that represent a
** big-endian integer.  Return the equivalent native integer
 */

// C documentation
//
//	/*
//	** Deserialize the data blob pointed to by buf as serial type serial_type
//	** and store the result in pMem.
//	**
//	** This function is implemented as two separate routines for performance.
//	** The few cases that require local variables are broken out into a separate
//	** routine so that in most cases the overhead of moving the stack pointer
//	** is avoided.
//	*/
func _serialGet(tls *libc.TLS, buf uintptr, serial_type Tu32, pMem uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var y Tu32
	var v1 int32
	var _ /* x at bp+0 */ Tu64
	_, _ = y, v1
	*(*Tu64)(unsafe.Pointer(bp)) = uint64(uint32(*(*uint8)(unsafe.Pointer(buf)))<<libc.Int32FromInt32(24) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*uint8)(unsafe.Pointer(buf + 3))))
	y = uint32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4))))<<libc.Int32FromInt32(24) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4) + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4) + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4) + 3)))
	*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(32) + uint64(uint64(y))
	if serial_type == uint32(6) {
		/* EVIDENCE-OF: R-29851-52272 Value is a big-endian 64-bit
		 ** twos-complement integer. */
		*(*Ti64)(unsafe.Pointer(pMem)) = *(*Ti64)(unsafe.Pointer(bp))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
	} else {
		/* EVIDENCE-OF: R-57343-49114 Value is a big-endian IEEE 754-2008 64-bit
		 ** floating point number. */
		libc.Xmemcpy(tls, pMem, bp, uint32(8))
		if *(*Tu64)(unsafe.Pointer(bp))&(libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52)) == libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52) && *(*Tu64)(unsafe.Pointer(bp))&(libc.Uint64FromInt32(1)<<libc.Int32FromInt32(52)-libc.Uint64FromInt32(1)) != uint64(0) {
			v1 = int32(MEM_Null)
		} else {
			v1 = int32(MEM_Real)
		}
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(v1)
	}
}

func _serialGet7(tls *libc.TLS, buf uintptr, pMem uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var y Tu32
	var _ /* x at bp+0 */ Tu64
	_ = y
	*(*Tu64)(unsafe.Pointer(bp)) = uint64(uint32(*(*uint8)(unsafe.Pointer(buf)))<<libc.Int32FromInt32(24) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*uint8)(unsafe.Pointer(buf + 3))))
	y = uint32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4))))<<libc.Int32FromInt32(24) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4) + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4) + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(4) + 3)))
	*(*Tu64)(unsafe.Pointer(bp)) = *(*Tu64)(unsafe.Pointer(bp))<<libc.Int32FromInt32(32) + uint64(uint64(y))
	libc.Xmemcpy(tls, pMem, bp, uint32(8))
	if *(*Tu64)(unsafe.Pointer(bp))&(libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52)) == libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52) && *(*Tu64)(unsafe.Pointer(bp))&(libc.Uint64FromInt32(1)<<libc.Int32FromInt32(52)-libc.Uint64FromInt32(1)) != uint64(0) {
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Null)
		return int32(1)
	}
	(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Real)
	return 0
}

func _sqlite3VdbeSerialGet(tls *libc.TLS, buf uintptr, serial_type Tu32, pMem uintptr) {
	switch serial_type {
	case uint32(10): /* Internal use only: NULL with virtual table
		 ** UPDATE no-change flag set */
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Zero))
		(*TMem)(unsafe.Pointer(pMem)).Fn = 0
		*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pMem)).Fu)) = 0
		return
	case uint32(11): /* Reserved for future use */
		fallthrough
	case uint32(0): /* Null */
		/* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Null)
		return
	case uint32(1):
		/* EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement
		 ** integer. */
		*(*Ti64)(unsafe.Pointer(pMem)) = int64(int8(*(*uint8)(unsafe.Pointer(buf))))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
		return
	case uint32(2): /* 2-byte signed integer */
		/* EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit
		 ** twos-complement integer. */
		*(*Ti64)(unsafe.Pointer(pMem)) = int64(libc.Int32FromInt32(256)*int32(int8(*(*uint8)(unsafe.Pointer(buf)))) | int32(*(*uint8)(unsafe.Pointer(buf + 1))))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
		return
	case uint32(3): /* 3-byte signed integer */
		/* EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit
		 ** twos-complement integer. */
		*(*Ti64)(unsafe.Pointer(pMem)) = int64(libc.Int32FromInt32(65536)*int32(int8(*(*uint8)(unsafe.Pointer(buf)))) | int32(*(*uint8)(unsafe.Pointer(buf + 1)))<<libc.Int32FromInt32(8) | int32(*(*uint8)(unsafe.Pointer(buf + 2))))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
		return
	case uint32(4): /* 4-byte signed integer */
		/* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit
		 ** twos-complement integer. */
		*(*Ti64)(unsafe.Pointer(pMem)) = int64(libc.Int32FromInt32(16777216)*int32(int8(*(*uint8)(unsafe.Pointer(buf)))) | int32(*(*uint8)(unsafe.Pointer(buf + 1)))<<libc.Int32FromInt32(16) | int32(*(*uint8)(unsafe.Pointer(buf + 2)))<<libc.Int32FromInt32(8) | int32(*(*uint8)(unsafe.Pointer(buf + 3))))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
		return
	case uint32(5): /* 6-byte signed integer */
		/* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit
		 ** twos-complement integer. */
		*(*Ti64)(unsafe.Pointer(pMem)) = int64(uint32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(2))))<<libc.Int32FromInt32(24)|uint32(int32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(2) + 1)))<<libc.Int32FromInt32(16))|uint32(int32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(2) + 2)))<<libc.Int32FromInt32(8))|uint32(*(*uint8)(unsafe.Pointer(buf + libc.UintptrFromInt32(2) + 3)))) + libc.Int64FromInt32(1)<<libc.Int32FromInt32(32)*int64(libc.Int32FromInt32(256)*int32(int8(*(*uint8)(unsafe.Pointer(buf))))|int32(*(*uint8)(unsafe.Pointer(buf + 1))))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
		return
	case uint32(6): /* 8-byte signed integer */
		fallthrough
	case uint32(7): /* IEEE floating point */
		/* These use local variables, so do them in a separate routine
		 ** to avoid having to move the frame pointer in the common case */
		_serialGet(tls, buf, serial_type, pMem)
		return
	case uint32(8): /* Integer 0 */
		fallthrough
	case uint32(9): /* Integer 1 */
		/* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */
		/* EVIDENCE-OF: R-18143-12121 Value is the integer 1. */
		*(*Ti64)(unsafe.Pointer(pMem)) = int64(serial_type - uint32(8))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Int)
		return
	default:
		(*TMem)(unsafe.Pointer(pMem)).Fz = buf
		(*TMem)(unsafe.Pointer(pMem)).Fn = int32((serial_type - uint32(12)) / uint32(2))
		(*TMem)(unsafe.Pointer(pMem)).Fflags = _aFlag[serial_type&uint32(1)]
		return
	}
	return
}

/* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in
 ** length.
 ** EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and
 ** (N-13)/2 bytes in length. */
var _aFlag = [2]Tu16{
	0: uint16(libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Ephem)),
	1: uint16(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Ephem)),
}

// C documentation
//
//	/*
//	** This routine is used to allocate sufficient space for an UnpackedRecord
//	** structure large enough to be used with sqlite3VdbeRecordUnpack() if
//	** the first argument is a pointer to KeyInfo structure pKeyInfo.
//	**
//	** The space is either allocated using sqlite3DbMallocRaw() or from within
//	** the unaligned buffer passed via the second and third arguments (presumably
//	** stack space). If the former, then *ppFree is set to a pointer that should
//	** be eventually freed by the caller using sqlite3DbFree(). Or, if the
//	** allocation comes from the pSpace/szSpace buffer, *ppFree is set to NULL
//	** before returning.
//	**
//	** If an OOM error occurs, NULL is returned.
//	*/
func _sqlite3VdbeAllocUnpackedRecord(tls *libc.TLS, pKeyInfo uintptr) (r uintptr) {
	var nByte int32
	var p uintptr
	_, _ = nByte, p /* Number of bytes required for *p */
	nByte = int32((libc.Uint32FromInt64(32)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)) + uint32(40)*uint32(int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)+libc.Int32FromInt32(1)))
	p = _sqlite3DbMallocRaw(tls, (*TKeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb, uint64(uint64(nByte)))
	if !(p != 0) {
		return uintptr(0)
	}
	(*TUnpackedRecord)(unsafe.Pointer(p)).FaMem = p + uintptr((libc.Uint32FromInt64(32)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
	(*TUnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo = pKeyInfo
	(*TUnpackedRecord)(unsafe.Pointer(p)).FnField = uint16(int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField) + int32(1))
	return p
}

// C documentation
//
//	/*
//	** Given the nKey-byte encoding of a record in pKey[], populate the
//	** UnpackedRecord structure indicated by the fourth argument with the
//	** contents of the decoded record.
//	*/
func _sqlite3VdbeRecordUnpack(tls *libc.TLS, pKeyInfo uintptr, nKey int32, pKey uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aKey, pMem uintptr
	var d, idx Tu32
	var u, v3 Tu16
	var v1, v2 int32
	var _ /* serial_type at bp+4 */ Tu32
	var _ /* szHdr at bp+0 */ Tu32
	_, _, _, _, _, _, _, _ = aKey, d, idx, pMem, u, v1, v2, v3
	aKey = pKey
	pMem = (*TUnpackedRecord)(unsafe.Pointer(p)).FaMem
	(*TUnpackedRecord)(unsafe.Pointer(p)).Fdefault_rc = 0
	if int32(*(*uint8)(unsafe.Pointer(aKey))) < int32(libc.Uint8FromInt32(0x80)) {
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*uint8)(unsafe.Pointer(aKey)))
		v1 = libc.Int32FromInt32(1)
	} else {
		v1 = int32(_sqlite3GetVarint32(tls, aKey, bp))
	}
	idx = uint32(uint8(v1))
	d = *(*Tu32)(unsafe.Pointer(bp))
	u = uint16(0)
	for idx < *(*Tu32)(unsafe.Pointer(bp)) && d <= uint32(uint32(nKey)) {
		if int32(*(*uint8)(unsafe.Pointer(aKey + uintptr(idx)))) < int32(libc.Uint8FromInt32(0x80)) {
			*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(*(*uint8)(unsafe.Pointer(aKey + uintptr(idx))))
			v2 = libc.Int32FromInt32(1)
		} else {
			v2 = int32(_sqlite3GetVarint32(tls, aKey+uintptr(idx), bp+4))
		}
		idx += uint32(uint8(v2))
		(*TMem)(unsafe.Pointer(pMem)).Fenc = (*TKeyInfo)(unsafe.Pointer(pKeyInfo)).Fenc
		(*TMem)(unsafe.Pointer(pMem)).Fdb = (*TKeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb
		/* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
		(*TMem)(unsafe.Pointer(pMem)).FszMalloc = 0
		(*TMem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
		_sqlite3VdbeSerialGet(tls, aKey+uintptr(d), *(*Tu32)(unsafe.Pointer(bp + 4)), pMem)
		d += _sqlite3VdbeSerialTypeLen(tls, *(*Tu32)(unsafe.Pointer(bp + 4)))
		pMem += 40
		u++
		v3 = u
		if int32(v3) >= int32((*TUnpackedRecord)(unsafe.Pointer(p)).FnField) {
			break
		}
	}
	if d > uint32(uint32(nKey)) && u != 0 {
		/* In a corrupt record entry, the last pMem might have been set up using
		 ** uninitialized memory. Overwrite its value with NULL, to prevent
		 ** warnings from MSAN. */
		_sqlite3VdbeMemSetNull(tls, pMem-uintptr(1)*40)
	}
	(*TUnpackedRecord)(unsafe.Pointer(p)).FnField = u
}

// C documentation
//
//	/*
//	** Both *pMem1 and *pMem2 contain string values. Compare the two values
//	** using the collation sequence pColl. As usual, return a negative , zero
//	** or positive value if *pMem1 is less than, equal to or greater than
//	** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
//	*/
func _vdbeCompareMemString(tls *libc.TLS, pMem1 uintptr, pMem2 uintptr, pColl uintptr, prcErr uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var rc int32
	var v1, v2 uintptr
	var _ /* c1 at bp+0 */ TMem
	var _ /* c2 at bp+40 */ TMem
	_, _, _ = rc, v1, v2
	if int32((*TMem)(unsafe.Pointer(pMem1)).Fenc) == int32((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) {
		/* The strings are already in the correct encoding.  Call the
		 ** comparison function directly */
		return (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TCollSeq)(unsafe.Pointer(pColl)).FxCmp})))(tls, (*TCollSeq)(unsafe.Pointer(pColl)).FpUser, (*TMem)(unsafe.Pointer(pMem1)).Fn, (*TMem)(unsafe.Pointer(pMem1)).Fz, (*TMem)(unsafe.Pointer(pMem2)).Fn, (*TMem)(unsafe.Pointer(pMem2)).Fz)
	} else {
		_sqlite3VdbeMemInit(tls, bp, (*TMem)(unsafe.Pointer(pMem1)).Fdb, uint16(MEM_Null))
		_sqlite3VdbeMemInit(tls, bp+40, (*TMem)(unsafe.Pointer(pMem1)).Fdb, uint16(MEM_Null))
		_sqlite3VdbeMemShallowCopy(tls, bp, pMem1, int32(MEM_Ephem))
		_sqlite3VdbeMemShallowCopy(tls, bp+40, pMem2, int32(MEM_Ephem))
		v1 = _sqlite3ValueText(tls, bp, (*TCollSeq)(unsafe.Pointer(pColl)).Fenc)
		v2 = _sqlite3ValueText(tls, bp+40, (*TCollSeq)(unsafe.Pointer(pColl)).Fenc)
		if v1 == uintptr(0) || v2 == uintptr(0) {
			if prcErr != 0 {
				*(*Tu8)(unsafe.Pointer(prcErr)) = uint8(SQLITE_NOMEM)
			}
			rc = 0
		} else {
			rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TCollSeq)(unsafe.Pointer(pColl)).FxCmp})))(tls, (*TCollSeq)(unsafe.Pointer(pColl)).FpUser, (*(*TMem)(unsafe.Pointer(bp))).Fn, v1, (*(*TMem)(unsafe.Pointer(bp + 40))).Fn, v2)
		}
		_sqlite3VdbeMemReleaseMalloc(tls, bp)
		_sqlite3VdbeMemReleaseMalloc(tls, bp+40)
		return rc
	}
	return r
}

// C documentation
//
//	/*
//	** The input pBlob is guaranteed to be a Blob that is not marked
//	** with MEM_Zero.  Return true if it could be a zero-blob.
//	*/
func _isAllZero(tls *libc.TLS, z uintptr, n int32) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < n) {
			break
		}
		if *(*int8)(unsafe.Pointer(z + uintptr(i))) != 0 {
			return 0
		}
		goto _1
	_1:
		;
		i++
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Compare two blobs.  Return negative, zero, or positive if the first
//	** is less than, equal to, or greater than the second, respectively.
//	** If one blob is a prefix of the other, then the shorter is the lessor.
//	*/
func _sqlite3BlobCompare(tls *libc.TLS, pB1 uintptr, pB2 uintptr) (r int32) {
	var c, n1, n2, v1 int32
	_, _, _, _ = c, n1, n2, v1
	n1 = (*TMem)(unsafe.Pointer(pB1)).Fn
	n2 = (*TMem)(unsafe.Pointer(pB2)).Fn
	/* It is possible to have a Blob value that has some non-zero content
	 ** followed by zero content.  But that only comes up for Blobs formed
	 ** by the OP_MakeRecord opcode, and such Blobs never get passed into
	 ** sqlite3MemCompare(). */
	if (int32((*TMem)(unsafe.Pointer(pB1)).Fflags)|int32((*TMem)(unsafe.Pointer(pB2)).Fflags))&int32(MEM_Zero) != 0 {
		if int32((*TMem)(unsafe.Pointer(pB1)).Fflags)&int32((*TMem)(unsafe.Pointer(pB2)).Fflags)&int32(MEM_Zero) != 0 {
			return *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pB1)).Fu)) - *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pB2)).Fu))
		} else {
			if int32((*TMem)(unsafe.Pointer(pB1)).Fflags)&int32(MEM_Zero) != 0 {
				if !(_isAllZero(tls, (*TMem)(unsafe.Pointer(pB2)).Fz, (*TMem)(unsafe.Pointer(pB2)).Fn) != 0) {
					return -int32(1)
				}
				return *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pB1)).Fu)) - n2
			} else {
				if !(_isAllZero(tls, (*TMem)(unsafe.Pointer(pB1)).Fz, (*TMem)(unsafe.Pointer(pB1)).Fn) != 0) {
					return +libc.Int32FromInt32(1)
				}
				return n1 - *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pB2)).Fu))
			}
		}
	}
	if n1 > n2 {
		v1 = n2
	} else {
		v1 = n1
	}
	c = libc.Xmemcmp(tls, (*TMem)(unsafe.Pointer(pB1)).Fz, (*TMem)(unsafe.Pointer(pB2)).Fz, uint32(v1))
	if c != 0 {
		return c
	}
	return n1 - n2
}

/* The following two functions are used only within testcase() to prove
** test coverage.  These functions do no exist for production builds.
** We must use separate SQLITE_NOINLINE functions here, since otherwise
** optimizer code movement causes gcov to become very confused.
 */

// C documentation
//
//	/*
//	** Do a comparison between a 64-bit signed integer and a 64-bit floating-point
//	** number.  Return negative, zero, or positive if the first (i64) is less than,
//	** equal to, or greater than the second (double).
//	*/
func _sqlite3IntFloatCompare(tls *libc.TLS, i Ti64, r float64) (r1 int32) {
	var x float64
	var y Ti64
	var v1, v2 int32
	_, _, _, _ = x, y, v1, v2
	if _sqlite3IsNaN(tls, r) != 0 {
		/* SQLite considers NaN to be a NULL. And all integer values are greater
		 ** than NULL */
		return int32(1)
	}
	if _sqlite3Config.FbUseLongDouble != 0 {
		x = float64(float64(i))
		if x < r {
			v1 = -int32(1)
		} else {
			v1 = libc.BoolInt32(x > r)
		}
		return v1
	} else {
		if r < -libc.Float64FromFloat64(9.223372036854776e+18) {
			return +libc.Int32FromInt32(1)
		}
		if r >= float64(9.223372036854776e+18) {
			return -int32(1)
		}
		y = int64(int64(r))
		if i < y {
			return -int32(1)
		}
		if i > y {
			return +libc.Int32FromInt32(1)
		}
		if float64(float64(i)) < r {
			v2 = -int32(1)
		} else {
			v2 = libc.BoolInt32(float64(float64(i)) > r)
		}
		return v2
	}
	return r1
}

// C documentation
//
//	/*
//	** Compare the values contained by the two memory cells, returning
//	** negative, zero or positive if pMem1 is less than, equal to, or greater
//	** than pMem2. Sorting order is NULL's first, followed by numbers (integers
//	** and reals) sorted numerically, followed by text ordered by the collating
//	** sequence pColl and finally blob's ordered by memcmp().
//	**
//	** Two NULL values are considered equal by this function.
//	*/
func _sqlite3MemCompare(tls *libc.TLS, pMem1 uintptr, pMem2 uintptr, pColl uintptr) (r int32) {
	var combined_flags, f1, f2 int32
	_, _, _ = combined_flags, f1, f2
	f1 = int32((*TMem)(unsafe.Pointer(pMem1)).Fflags)
	f2 = int32((*TMem)(unsafe.Pointer(pMem2)).Fflags)
	combined_flags = f1 | f2
	/* If one value is NULL, it is less than the other. If both values
	 ** are NULL, return 0.
	 */
	if combined_flags&int32(MEM_Null) != 0 {
		return f2&int32(MEM_Null) - f1&int32(MEM_Null)
	}
	/* At least one of the two values is a number
	 */
	if combined_flags&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
		if f1&f2&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
			if *(*Ti64)(unsafe.Pointer(pMem1)) < *(*Ti64)(unsafe.Pointer(pMem2)) {
				return -int32(1)
			}
			if *(*Ti64)(unsafe.Pointer(pMem1)) > *(*Ti64)(unsafe.Pointer(pMem2)) {
				return +libc.Int32FromInt32(1)
			}
			return 0
		}
		if f1&f2&int32(MEM_Real) != 0 {
			if *(*float64)(unsafe.Pointer(pMem1)) < *(*float64)(unsafe.Pointer(pMem2)) {
				return -int32(1)
			}
			if *(*float64)(unsafe.Pointer(pMem1)) > *(*float64)(unsafe.Pointer(pMem2)) {
				return +libc.Int32FromInt32(1)
			}
			return 0
		}
		if f1&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
			if f2&int32(MEM_Real) != 0 {
				return _sqlite3IntFloatCompare(tls, *(*Ti64)(unsafe.Pointer(pMem1)), *(*float64)(unsafe.Pointer(pMem2)))
			} else {
				if f2&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
					if *(*Ti64)(unsafe.Pointer(pMem1)) < *(*Ti64)(unsafe.Pointer(pMem2)) {
						return -int32(1)
					}
					if *(*Ti64)(unsafe.Pointer(pMem1)) > *(*Ti64)(unsafe.Pointer(pMem2)) {
						return +libc.Int32FromInt32(1)
					}
					return 0
				} else {
					return -int32(1)
				}
			}
		}
		if f1&int32(MEM_Real) != 0 {
			if f2&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
				return -_sqlite3IntFloatCompare(tls, *(*Ti64)(unsafe.Pointer(pMem2)), *(*float64)(unsafe.Pointer(pMem1)))
			} else {
				return -int32(1)
			}
		}
		return +libc.Int32FromInt32(1)
	}
	/* If one value is a string and the other is a blob, the string is less.
	 ** If both are strings, compare using the collating functions.
	 */
	if combined_flags&int32(MEM_Str) != 0 {
		if f1&int32(MEM_Str) == 0 {
			return int32(1)
		}
		if f2&int32(MEM_Str) == 0 {
			return -int32(1)
		}
		/* The collation sequence must be defined at this point, even if
		 ** the user deletes the collation sequence after the vdbe program is
		 ** compiled (this was not always the case).
		 */
		if pColl != 0 {
			return _vdbeCompareMemString(tls, pMem1, pMem2, pColl, uintptr(0))
		}
		/* If a NULL pointer was passed as the collate function, fall through
		 ** to the blob case and use memcmp().  */
	}
	/* Both values must be blobs.  Compare using memcmp().  */
	return _sqlite3BlobCompare(tls, pMem1, pMem2)
}

// C documentation
//
//	/*
//	** The first argument passed to this function is a serial-type that
//	** corresponds to an integer - all values between 1 and 9 inclusive
//	** except 7. The second points to a buffer containing an integer value
//	** serialized according to serial_type. This function deserializes
//	** and returns the value.
//	*/
func _vdbeRecordDecodeInt(tls *libc.TLS, serial_type Tu32, aKey uintptr) (r Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* x at bp+8 */ Tu64
	var _ /* y at bp+0 */ Tu32
	switch serial_type {
	case uint32(0):
		fallthrough
	case uint32(1):
		return int64(int8(*(*Tu8)(unsafe.Pointer(aKey))))
	case uint32(2):
		return int64(libc.Int32FromInt32(256)*int32(int8(*(*Tu8)(unsafe.Pointer(aKey)))) | int32(*(*Tu8)(unsafe.Pointer(aKey + 1))))
	case uint32(3):
		return int64(libc.Int32FromInt32(65536)*int32(int8(*(*Tu8)(unsafe.Pointer(aKey)))) | int32(*(*Tu8)(unsafe.Pointer(aKey + 1)))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(aKey + 2))))
	case uint32(4):
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(aKey)))<<libc.Int32FromInt32(24) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*Tu8)(unsafe.Pointer(aKey + 3)))
		return int64(*(*int32)(unsafe.Pointer(bp)))
	case uint32(5):
		return int64(uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2))))<<libc.Int32FromInt32(24)|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2) + 1)))<<libc.Int32FromInt32(16))|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2) + 2)))<<libc.Int32FromInt32(8))|uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2) + 3)))) + libc.Int64FromInt32(1)<<libc.Int32FromInt32(32)*int64(libc.Int32FromInt32(256)*int32(int8(*(*Tu8)(unsafe.Pointer(aKey))))|int32(*(*Tu8)(unsafe.Pointer(aKey + 1))))
	case uint32(6):
		*(*Tu64)(unsafe.Pointer(bp + 8)) = uint64(uint32(*(*Tu8)(unsafe.Pointer(aKey)))<<libc.Int32FromInt32(24) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*Tu8)(unsafe.Pointer(aKey + 3))))
		*(*Tu64)(unsafe.Pointer(bp + 8)) = *(*Tu64)(unsafe.Pointer(bp + 8))<<libc.Int32FromInt32(32) | uint64(uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4))))<<libc.Int32FromInt32(24)|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4) + 1)))<<libc.Int32FromInt32(16))|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4) + 2)))<<libc.Int32FromInt32(8))|uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4) + 3))))
		return *(*Ti64)(unsafe.Pointer(bp + 8))
	}
	return int64(serial_type - libc.Uint32FromInt32(8))
}

// C documentation
//
//	/*
//	** This function compares the two table rows or index records
//	** specified by {nKey1, pKey1} and pPKey2.  It returns a negative, zero
//	** or positive integer if key1 is less than, equal to or
//	** greater than key2.  The {nKey1, pKey1} key must be a blob
//	** created by the OP_MakeRecord opcode of the VDBE.  The pPKey2
//	** key must be a parsed key such as obtained from
//	** sqlite3VdbeParseRecord.
//	**
//	** If argument bSkip is non-zero, it is assumed that the caller has already
//	** determined that the first fields of the keys are equal.
//	**
//	** Key1 and Key2 do not have to contain the same number of fields. If all
//	** fields that appear in both keys are equal, then pPKey2->default_rc is
//	** returned.
//	**
//	** If database corruption is discovered, set pPKey2->errCode to
//	** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
//	** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
//	** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
//	*/
func _sqlite3VdbeRecordCompareWithSkip(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr, bSkip int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aKey1, pKeyInfo, pRhs, v4 uintptr
	var d1, idx1, v1 Tu32
	var i, nCmp, nCmp1, nStr, rc, sortFlags, v2, v3, v6, v7 int32
	var lhs, rhs Ti64
	var v5 bool
	var _ /* mem1 at bp+8 */ TMem
	var _ /* s1 at bp+48 */ Tu32
	var _ /* serial_type at bp+52 */ Tu32
	var _ /* szHdr1 at bp+0 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aKey1, d1, i, idx1, lhs, nCmp, nCmp1, nStr, pKeyInfo, pRhs, rc, rhs, sortFlags, v1, v2, v3, v4, v5, v6, v7 /* Offset of first type in header */
	rc = 0                                                                                                                                                                  /* Return value */
	pRhs = (*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FaMem
	aKey1 = pKey1
	/* If bSkip is true, then the caller has already determined that the first
	 ** two elements in the keys are equal. Fix the various stack variables so
	 ** that this routine begins comparing at the second field. */
	if bSkip != 0 {
		*(*Tu32)(unsafe.Pointer(bp + 48)) = uint32(*(*uint8)(unsafe.Pointer(aKey1 + 1)))
		if *(*Tu32)(unsafe.Pointer(bp + 48)) < uint32(0x80) {
			idx1 = uint32(2)
		} else {
			idx1 = uint32(int32(1) + int32(_sqlite3GetVarint32(tls, aKey1+1, bp+48)))
		}
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*uint8)(unsafe.Pointer(aKey1)))
		d1 = *(*Tu32)(unsafe.Pointer(bp)) + _sqlite3VdbeSerialTypeLen(tls, *(*Tu32)(unsafe.Pointer(bp + 48)))
		i = int32(1)
		pRhs += 40
	} else {
		v1 = uint32(*(*uint8)(unsafe.Pointer(aKey1)))
		*(*Tu32)(unsafe.Pointer(bp)) = v1
		if v1 < uint32(0x80) {
			idx1 = uint32(1)
		} else {
			idx1 = uint32(_sqlite3GetVarint32(tls, aKey1, bp))
		}
		d1 = *(*Tu32)(unsafe.Pointer(bp))
		i = 0
	}
	if d1 > uint32(uint32(nKey1)) {
		(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = uint8(_sqlite3CorruptError(tls, int32(89580)))
		return 0 /* Corruption */
	}
	/* Only needed by assert() statements */
	for int32(1) != 0 {
		/* RHS is an integer */
		if int32((*TMem)(unsafe.Pointer(pRhs)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
			*(*Tu32)(unsafe.Pointer(bp + 52)) = uint32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
			if *(*Tu32)(unsafe.Pointer(bp + 52)) >= uint32(10) {
				if *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(10) {
					v2 = -int32(1)
				} else {
					v2 = +libc.Int32FromInt32(1)
				}
				rc = v2
			} else {
				if *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(0) {
					rc = -int32(1)
				} else {
					if *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(7) {
						_serialGet7(tls, aKey1+uintptr(d1), bp+8)
						rc = -_sqlite3IntFloatCompare(tls, *(*Ti64)(unsafe.Pointer(pRhs)), *(*float64)(unsafe.Pointer(bp + 8)))
					} else {
						lhs = _vdbeRecordDecodeInt(tls, *(*Tu32)(unsafe.Pointer(bp + 52)), aKey1+uintptr(d1))
						rhs = *(*Ti64)(unsafe.Pointer(pRhs))
						if lhs < rhs {
							rc = -int32(1)
						} else {
							if lhs > rhs {
								rc = +libc.Int32FromInt32(1)
							}
						}
					}
				}
			}
		} else {
			if int32((*TMem)(unsafe.Pointer(pRhs)).Fflags)&int32(MEM_Real) != 0 {
				*(*Tu32)(unsafe.Pointer(bp + 52)) = uint32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
				if *(*Tu32)(unsafe.Pointer(bp + 52)) >= uint32(10) {
					/* Serial types 12 or greater are strings and blobs (greater than
					 ** numbers). Types 10 and 11 are currently "reserved for future
					 ** use", so it doesn't really matter what the results of comparing
					 ** them to numeric values are.  */
					if *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(10) {
						v3 = -int32(1)
					} else {
						v3 = +libc.Int32FromInt32(1)
					}
					rc = v3
				} else {
					if *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(0) {
						rc = -int32(1)
					} else {
						if *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(7) {
							if _serialGet7(tls, aKey1+uintptr(d1), bp+8) != 0 {
								rc = -int32(1) /* mem1 is a NaN */
							} else {
								if *(*float64)(unsafe.Pointer(bp + 8)) < *(*float64)(unsafe.Pointer(pRhs)) {
									rc = -int32(1)
								} else {
									if *(*float64)(unsafe.Pointer(bp + 8)) > *(*float64)(unsafe.Pointer(pRhs)) {
										rc = +libc.Int32FromInt32(1)
									} else {
									}
								}
							}
						} else {
							_sqlite3VdbeSerialGet(tls, aKey1+uintptr(d1), *(*Tu32)(unsafe.Pointer(bp + 52)), bp+8)
							rc = _sqlite3IntFloatCompare(tls, *(*Ti64)(unsafe.Pointer(bp + 8)), *(*float64)(unsafe.Pointer(pRhs)))
						}
					}
				}
			} else {
				if int32((*TMem)(unsafe.Pointer(pRhs)).Fflags)&int32(MEM_Str) != 0 {
					*(*Tu32)(unsafe.Pointer(bp + 52)) = uint32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
					if *(*Tu32)(unsafe.Pointer(bp + 52)) >= uint32(0x80) {
						_sqlite3GetVarint32(tls, aKey1+uintptr(idx1), bp+52)
					}
					if *(*Tu32)(unsafe.Pointer(bp + 52)) < uint32(12) {
						rc = -int32(1)
					} else {
						if !(*(*Tu32)(unsafe.Pointer(bp + 52))&libc.Uint32FromInt32(0x01) != 0) {
							rc = +libc.Int32FromInt32(1)
						} else {
							(*(*TMem)(unsafe.Pointer(bp + 8))).Fn = int32((*(*Tu32)(unsafe.Pointer(bp + 52)) - uint32(12)) / uint32(2))
							if v5 = d1+uint32((*(*TMem)(unsafe.Pointer(bp + 8))).Fn) > uint32(uint32(nKey1)); !v5 {
								v4 = (*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FpKeyInfo
								pKeyInfo = v4
							}
							if v5 || int32((*TKeyInfo)(unsafe.Pointer(v4)).FnAllField) <= i {
								(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = uint8(_sqlite3CorruptError(tls, int32(89661)))
								return 0 /* Corruption */
							} else {
								if *(*uintptr)(unsafe.Pointer(pKeyInfo + 20 + uintptr(i)*4)) != 0 {
									(*(*TMem)(unsafe.Pointer(bp + 8))).Fenc = (*TKeyInfo)(unsafe.Pointer(pKeyInfo)).Fenc
									(*(*TMem)(unsafe.Pointer(bp + 8))).Fdb = (*TKeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb
									(*(*TMem)(unsafe.Pointer(bp + 8))).Fflags = uint16(MEM_Str)
									(*(*TMem)(unsafe.Pointer(bp + 8))).Fz = aKey1 + uintptr(d1)
									rc = _vdbeCompareMemString(tls, bp+8, pRhs, *(*uintptr)(unsafe.Pointer(pKeyInfo + 20 + uintptr(i)*4)), pPKey2+23)
								} else {
									if (*(*TMem)(unsafe.Pointer(bp + 8))).Fn < (*TMem)(unsafe.Pointer(pRhs)).Fn {
										v6 = (*(*TMem)(unsafe.Pointer(bp + 8))).Fn
									} else {
										v6 = (*TMem)(unsafe.Pointer(pRhs)).Fn
									}
									nCmp = v6
									rc = libc.Xmemcmp(tls, aKey1+uintptr(d1), (*TMem)(unsafe.Pointer(pRhs)).Fz, uint32(uint32(nCmp)))
									if rc == 0 {
										rc = (*(*TMem)(unsafe.Pointer(bp + 8))).Fn - (*TMem)(unsafe.Pointer(pRhs)).Fn
									}
								}
							}
						}
					}
				} else {
					if int32((*TMem)(unsafe.Pointer(pRhs)).Fflags)&int32(MEM_Blob) != 0 {
						*(*Tu32)(unsafe.Pointer(bp + 52)) = uint32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
						if *(*Tu32)(unsafe.Pointer(bp + 52)) >= uint32(0x80) {
							_sqlite3GetVarint32(tls, aKey1+uintptr(idx1), bp+52)
						}
						if *(*Tu32)(unsafe.Pointer(bp + 52)) < uint32(12) || *(*Tu32)(unsafe.Pointer(bp + 52))&uint32(0x01) != 0 {
							rc = -int32(1)
						} else {
							nStr = int32((*(*Tu32)(unsafe.Pointer(bp + 52)) - uint32(12)) / uint32(2))
							if d1+uint32(uint32(nStr)) > uint32(uint32(nKey1)) {
								(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = uint8(_sqlite3CorruptError(tls, int32(89691)))
								return 0 /* Corruption */
							} else {
								if int32((*TMem)(unsafe.Pointer(pRhs)).Fflags)&int32(MEM_Zero) != 0 {
									if !(_isAllZero(tls, aKey1+uintptr(d1), nStr) != 0) {
										rc = int32(1)
									} else {
										rc = nStr - *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRhs)).Fu))
									}
								} else {
									if nStr < (*TMem)(unsafe.Pointer(pRhs)).Fn {
										v7 = nStr
									} else {
										v7 = (*TMem)(unsafe.Pointer(pRhs)).Fn
									}
									nCmp1 = v7
									rc = libc.Xmemcmp(tls, aKey1+uintptr(d1), (*TMem)(unsafe.Pointer(pRhs)).Fz, uint32(uint32(nCmp1)))
									if rc == 0 {
										rc = nStr - (*TMem)(unsafe.Pointer(pRhs)).Fn
									}
								}
							}
						}
					} else {
						*(*Tu32)(unsafe.Pointer(bp + 52)) = uint32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
						if *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(0) || *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(10) || *(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(7) && _serialGet7(tls, aKey1+uintptr(d1), bp+8) != 0 {
						} else {
							rc = int32(1)
						}
					}
				}
			}
		}
		if rc != 0 {
			sortFlags = int32(*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FpKeyInfo)).FaSortFlags + uintptr(i))))
			if sortFlags != 0 {
				if sortFlags&int32(KEYINFO_ORDER_BIGNULL) == 0 || sortFlags&int32(KEYINFO_ORDER_DESC) != libc.BoolInt32(*(*Tu32)(unsafe.Pointer(bp + 52)) == uint32(0) || int32((*TMem)(unsafe.Pointer(pRhs)).Fflags)&int32(MEM_Null) != 0) {
					rc = -rc
				}
			}
			/* See comment below */
			return rc
		}
		i++
		if i == int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FnField) {
			break
		}
		pRhs += 40
		d1 += _sqlite3VdbeSerialTypeLen(tls, *(*Tu32)(unsafe.Pointer(bp + 52)))
		if d1 > uint32(uint32(nKey1)) {
			break
		}
		idx1 += uint32(_sqlite3VarintLen(tls, uint64(*(*Tu32)(unsafe.Pointer(bp + 52)))))
		if idx1 >= *(*Tu32)(unsafe.Pointer(bp)) {
			(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = uint8(_sqlite3CorruptError(tls, int32(89742)))
			return 0 /* Corrupt index */
		}
	}
	/* No memory allocation is ever used on mem1.  Prove this using
	 ** the following assert().  If the assert() fails, it indicates a
	 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).  */
	/* rc==0 here means that one or both of the keys ran out of fields and
	 ** all the fields up to that point were equal. Return the default_rc
	 ** value.  */
	(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FeqSeen = uint8(1)
	return int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fdefault_rc)
}

func _sqlite3VdbeRecordCompare(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr) (r int32) {
	return _sqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, pPKey2, 0)
}

// C documentation
//
//	/*
//	** This function is an optimized version of sqlite3VdbeRecordCompare()
//	** that (a) the first field of pPKey2 is an integer, and (b) the
//	** size-of-header varint at the start of (pKey1/nKey1) fits in a single
//	** byte (i.e. is less than 128).
//	**
//	** To avoid concerns about buffer overreads, this routine is only used
//	** on schemas where the maximum valid header size is 63 bytes or less.
//	*/
func _vdbeRecordCompareInt(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aKey uintptr
	var lhs, v Ti64
	var res, serial_type int32
	var _ /* x at bp+8 */ Tu64
	var _ /* y at bp+0 */ Tu32
	_, _, _, _, _ = aKey, lhs, res, serial_type, v
	aKey = pKey1 + uintptr(int32(*(*Tu8)(unsafe.Pointer(pKey1)))&int32(0x3F))
	serial_type = int32(*(*Tu8)(unsafe.Pointer(pKey1 + 1)))
	switch serial_type {
	case int32(1): /* 1-byte signed integer */
		lhs = int64(int8(*(*Tu8)(unsafe.Pointer(aKey))))
	case int32(2): /* 2-byte signed integer */
		lhs = int64(libc.Int32FromInt32(256)*int32(int8(*(*Tu8)(unsafe.Pointer(aKey)))) | int32(*(*Tu8)(unsafe.Pointer(aKey + 1))))
	case int32(3): /* 3-byte signed integer */
		lhs = int64(libc.Int32FromInt32(65536)*int32(int8(*(*Tu8)(unsafe.Pointer(aKey)))) | int32(*(*Tu8)(unsafe.Pointer(aKey + 1)))<<libc.Int32FromInt32(8) | int32(*(*Tu8)(unsafe.Pointer(aKey + 2))))
	case int32(4): /* 4-byte signed integer */
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(aKey)))<<libc.Int32FromInt32(24) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*Tu8)(unsafe.Pointer(aKey + 3)))
		lhs = int64(*(*int32)(unsafe.Pointer(bp)))
	case int32(5): /* 6-byte signed integer */
		lhs = int64(uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2))))<<libc.Int32FromInt32(24)|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2) + 1)))<<libc.Int32FromInt32(16))|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2) + 2)))<<libc.Int32FromInt32(8))|uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(2) + 3)))) + libc.Int64FromInt32(1)<<libc.Int32FromInt32(32)*int64(libc.Int32FromInt32(256)*int32(int8(*(*Tu8)(unsafe.Pointer(aKey))))|int32(*(*Tu8)(unsafe.Pointer(aKey + 1))))
	case int32(6): /* 8-byte signed integer */
		*(*Tu64)(unsafe.Pointer(bp + 8)) = uint64(uint32(*(*Tu8)(unsafe.Pointer(aKey)))<<libc.Int32FromInt32(24) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*Tu8)(unsafe.Pointer(aKey + 3))))
		*(*Tu64)(unsafe.Pointer(bp + 8)) = *(*Tu64)(unsafe.Pointer(bp + 8))<<libc.Int32FromInt32(32) | uint64(uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4))))<<libc.Int32FromInt32(24)|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4) + 1)))<<libc.Int32FromInt32(16))|uint32(int32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4) + 2)))<<libc.Int32FromInt32(8))|uint32(*(*Tu8)(unsafe.Pointer(aKey + libc.UintptrFromInt32(4) + 3))))
		lhs = *(*Ti64)(unsafe.Pointer(bp + 8))
	case int32(8):
		lhs = 0
	case int32(9):
		lhs = int64(1)
		break
		/* This case could be removed without changing the results of running
		 ** this code. Including it causes gcc to generate a faster switch
		 ** statement (since the range of switch targets now starts at zero and
		 ** is contiguous) but does not cause any duplicate code to be generated
		 ** (as gcc is clever enough to combine the two like cases). Other
		 ** compilers might be similar.  */
		fallthrough
	case 0:
		fallthrough
	case int32(7):
		return _sqlite3VdbeRecordCompare(tls, nKey1, pKey1, pPKey2)
	default:
		return _sqlite3VdbeRecordCompare(tls, nKey1, pKey1, pPKey2)
	}
	v = *(*Ti64)(unsafe.Pointer(pPKey2 + 8))
	if v > lhs {
		res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1)
	} else {
		if v < lhs {
			res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2)
		} else {
			if int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FnField) > int32(1) {
				/* The first fields of the two keys are equal. Compare the trailing
				 ** fields.  */
				res = _sqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, pPKey2, int32(1))
			} else {
				/* The first fields of the two keys are equal and there are no trailing
				 ** fields. Return pPKey2->default_rc in this case. */
				res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fdefault_rc)
				(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FeqSeen = uint8(1)
			}
		}
	}
	return res
}

// C documentation
//
//	/*
//	** This function is an optimized version of sqlite3VdbeRecordCompare()
//	** that (a) the first field of pPKey2 is a string, that (b) the first field
//	** uses the collation sequence BINARY and (c) that the size-of-header varint
//	** at the start of (pKey1/nKey1) fits in a single byte.
//	*/
func _vdbeRecordCompareString(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aKey1 uintptr
	var nCmp, nStr, res, szHdr, v1 int32
	var _ /* serial_type at bp+0 */ int32
	_, _, _, _, _, _ = aKey1, nCmp, nStr, res, szHdr, v1
	aKey1 = pKey1
	*(*int32)(unsafe.Pointer(bp)) = int32(int8(*(*Tu8)(unsafe.Pointer(aKey1 + 1))))
	goto vrcs_restart
vrcs_restart:
	;
	if *(*int32)(unsafe.Pointer(bp)) < int32(12) {
		if *(*int32)(unsafe.Pointer(bp)) < 0 {
			_sqlite3GetVarint32(tls, aKey1+1, bp)
			if *(*int32)(unsafe.Pointer(bp)) >= int32(12) {
				goto vrcs_restart
			}
		}
		res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1) /* (pKey1/nKey1) is a number or a null */
	} else {
		if !(*(*int32)(unsafe.Pointer(bp))&libc.Int32FromInt32(0x01) != 0) {
			res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2) /* (pKey1/nKey1) is a blob */
		} else {
			szHdr = int32(*(*Tu8)(unsafe.Pointer(aKey1)))
			nStr = (*(*int32)(unsafe.Pointer(bp)) - int32(12)) / int32(2)
			if szHdr+nStr > nKey1 {
				(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = uint8(_sqlite3CorruptError(tls, int32(89905)))
				return 0 /* Corruption */
			}
			if (*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fn < nStr {
				v1 = (*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fn
			} else {
				v1 = nStr
			}
			nCmp = v1
			res = libc.Xmemcmp(tls, aKey1+uintptr(szHdr), (*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fu.Fz, uint32(uint32(nCmp)))
			if res > 0 {
				res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2)
			} else {
				if res < 0 {
					res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1)
				} else {
					res = nStr - (*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fn
					if res == 0 {
						if int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FnField) > int32(1) {
							res = _sqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, pPKey2, int32(1))
						} else {
							res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fdefault_rc)
							(*TUnpackedRecord)(unsafe.Pointer(pPKey2)).FeqSeen = uint8(1)
						}
					} else {
						if res > 0 {
							res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2)
						} else {
							res = int32((*TUnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1)
						}
					}
				}
			}
		}
	}
	return res
}

// C documentation
//
//	/*
//	** Return a pointer to an sqlite3VdbeRecordCompare() compatible function
//	** suitable for comparing serialized records to the unpacked record passed
//	** as the only argument.
//	*/
func _sqlite3VdbeFindCompare(tls *libc.TLS, p uintptr) (r TRecordCompare) {
	var flags int32
	_ = flags
	/* varintRecordCompareInt() and varintRecordCompareString() both assume
	 ** that the size-of-header varint that occurs at the start of each record
	 ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
	 ** also assumes that it is safe to overread a buffer by at least the
	 ** maximum possible legal header size plus 8 bytes. Because there is
	 ** guaranteed to be at least 74 (but not 136) bytes of padding following each
	 ** buffer passed to varintRecordCompareInt() this makes it convenient to
	 ** limit the size of the header to 64 bytes in cases where the first field
	 ** is an integer.
	 **
	 ** The easiest way to enforce this limit is to consider only records with
	 ** 13 fields or less. If the first field is an integer, the maximum legal
	 ** header size is (12*5 + 1 + 1) bytes.  */
	if int32((*TKeyInfo)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo)).FnAllField) <= int32(13) {
		flags = int32((*(*TMem)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FaMem))).Fflags)
		if *(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo)).FaSortFlags)) != 0 {
			if int32(*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo)).FaSortFlags)))&int32(KEYINFO_ORDER_BIGNULL) != 0 {
				return __ccgo_fp(_sqlite3VdbeRecordCompare)
			}
			(*TUnpackedRecord)(unsafe.Pointer(p)).Fr1 = int8(1)
			(*TUnpackedRecord)(unsafe.Pointer(p)).Fr2 = int8(-int32(1))
		} else {
			(*TUnpackedRecord)(unsafe.Pointer(p)).Fr1 = int8(-int32(1))
			(*TUnpackedRecord)(unsafe.Pointer(p)).Fr2 = int8(1)
		}
		if flags&int32(MEM_Int) != 0 {
			*(*Ti64)(unsafe.Pointer(p + 8)) = *(*Ti64)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FaMem))
			return __ccgo_fp(_vdbeRecordCompareInt)
		}
		if flags&(libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Null)|libc.Int32FromInt32(MEM_Blob)) == 0 && *(*uintptr)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo + 20)) == uintptr(0) {
			(*TUnpackedRecord)(unsafe.Pointer(p)).Fu.Fz = (*(*TMem)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FaMem))).Fz
			(*TUnpackedRecord)(unsafe.Pointer(p)).Fn = (*(*TMem)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(p)).FaMem))).Fn
			return __ccgo_fp(_vdbeRecordCompareString)
		}
	}
	return __ccgo_fp(_sqlite3VdbeRecordCompare)
}

// C documentation
//
//	/*
//	** pCur points at an index entry created using the OP_MakeRecord opcode.
//	** Read the rowid (the last field in the record) and store it in *rowid.
//	** Return SQLITE_OK if everything works, or an error code otherwise.
//	**
//	** pCur might be pointing to text obtained from a corrupt database file.
//	** So the content cannot be trusted.  Do appropriate checks on the content.
//	*/
func _sqlite3VdbeIdxRowid(tls *libc.TLS, db uintptr, pCur uintptr, rowid uintptr) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var lenRowid Tu32
	var nCellKey Ti64
	var rc int32
	var _ /* m at bp+8 */ TMem
	var _ /* szHdr at bp+0 */ Tu32
	var _ /* typeRowid at bp+4 */ Tu32
	var _ /* v at bp+48 */ TMem
	_, _, _ = lenRowid, nCellKey, rc
	nCellKey = 0
	/* Get the size of the index entry.  Only indices entries of less
	 ** than 2GiB are support - anything large must be database corruption.
	 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
	 ** this code can safely assume that nCellKey is 32-bits
	 */
	nCellKey = int64(_sqlite3BtreePayloadSize(tls, pCur))
	/* Read in the complete content of the index entry */
	_sqlite3VdbeMemInit(tls, bp+8, db, uint16(0))
	rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, pCur, uint32(uint32(nCellKey)), bp+8)
	if rc != 0 {
		return rc
	}
	/* The index entry must begin with a header size */
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer((*(*TMem)(unsafe.Pointer(bp + 8))).Fz)))
	if *(*Tu32)(unsafe.Pointer(bp)) >= uint32(0x80) {
		_sqlite3GetVarint32(tls, (*(*TMem)(unsafe.Pointer(bp + 8))).Fz, bp)
	}
	if *(*Tu32)(unsafe.Pointer(bp)) < uint32(3) || *(*Tu32)(unsafe.Pointer(bp)) > uint32((*(*TMem)(unsafe.Pointer(bp + 8))).Fn) {
		goto idx_rowid_corruption
	}
	/* The last field of the index should be an integer - the ROWID.
	 ** Verify that the last entry really is an integer. */
	*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(*(*Tu8)(unsafe.Pointer((*(*TMem)(unsafe.Pointer(bp + 8))).Fz + uintptr(*(*Tu32)(unsafe.Pointer(bp))-uint32(1)))))
	if *(*Tu32)(unsafe.Pointer(bp + 4)) >= uint32(0x80) {
		_sqlite3GetVarint32(tls, (*(*TMem)(unsafe.Pointer(bp + 8))).Fz+uintptr(*(*Tu32)(unsafe.Pointer(bp))-uint32(1)), bp+4)
	}
	if *(*Tu32)(unsafe.Pointer(bp + 4)) < uint32(1) || *(*Tu32)(unsafe.Pointer(bp + 4)) > uint32(9) || *(*Tu32)(unsafe.Pointer(bp + 4)) == uint32(7) {
		goto idx_rowid_corruption
	}
	lenRowid = uint32(_sqlite3SmallTypeSizes[*(*Tu32)(unsafe.Pointer(bp + 4))])
	if uint32((*(*TMem)(unsafe.Pointer(bp + 8))).Fn) < *(*Tu32)(unsafe.Pointer(bp))+lenRowid {
		goto idx_rowid_corruption
	}
	/* Fetch the integer off the end of the index record */
	_sqlite3VdbeSerialGet(tls, (*(*TMem)(unsafe.Pointer(bp + 8))).Fz+uintptr(uint32((*(*TMem)(unsafe.Pointer(bp + 8))).Fn)-lenRowid), *(*Tu32)(unsafe.Pointer(bp + 4)), bp+48)
	*(*Ti64)(unsafe.Pointer(rowid)) = *(*Ti64)(unsafe.Pointer(bp + 48))
	_sqlite3VdbeMemReleaseMalloc(tls, bp+8)
	return SQLITE_OK
	/* Jump here if database corruption is detected after m has been
	 ** allocated.  Free the m object and return SQLITE_CORRUPT. */
	goto idx_rowid_corruption
idx_rowid_corruption:
	;
	_sqlite3VdbeMemReleaseMalloc(tls, bp+8)
	return _sqlite3CorruptError(tls, int32(90063))
}

// C documentation
//
//	/*
//	** Compare the key of the index entry that cursor pC is pointing to against
//	** the key string in pUnpacked.  Write into *pRes a number
//	** that is negative, zero, or positive if pC is less than, equal to,
//	** or greater than pUnpacked.  Return SQLITE_OK on success.
//	**
//	** pUnpacked is either created without a rowid or is truncated so that it
//	** omits the rowid at the end.  The rowid at the end of the index entry
//	** is ignored as well.  Hence, this routine only compares the prefixes
//	** of the keys prior to the final rowid, not the entire key.
//	*/
func _sqlite3VdbeIdxKeyCompare(tls *libc.TLS, db uintptr, pC uintptr, pUnpacked uintptr, res uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var nCellKey Ti64
	var pCur uintptr
	var rc int32
	var _ /* m at bp+0 */ TMem
	_, _, _ = nCellKey, pCur, rc
	nCellKey = 0
	pCur = *(*uintptr)(unsafe.Pointer(pC + 36))
	nCellKey = int64(_sqlite3BtreePayloadSize(tls, pCur))
	/* nCellKey will always be between 0 and 0xffffffff because of the way
	 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
	if nCellKey <= 0 || nCellKey > int64(0x7fffffff) {
		*(*int32)(unsafe.Pointer(res)) = 0
		return _sqlite3CorruptError(tls, int32(90096))
	}
	_sqlite3VdbeMemInit(tls, bp, db, uint16(0))
	rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, pCur, uint32(uint32(nCellKey)), bp)
	if rc != 0 {
		return rc
	}
	*(*int32)(unsafe.Pointer(res)) = _sqlite3VdbeRecordCompareWithSkip(tls, (*(*TMem)(unsafe.Pointer(bp))).Fn, (*(*TMem)(unsafe.Pointer(bp))).Fz, pUnpacked, 0)
	_sqlite3VdbeMemReleaseMalloc(tls, bp)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This routine sets the value to be returned by subsequent calls to
//	** sqlite3_changes() on the database handle 'db'.
//	*/
func _sqlite3VdbeSetChanges(tls *libc.TLS, db uintptr, nChange Ti64) {
	(*Tsqlite3)(unsafe.Pointer(db)).FnChange = nChange
	*(*Ti64)(unsafe.Pointer(db + 112)) += nChange
}

// 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+152, libc.Uint32FromInt32(1), 4, 0x10)
}

// 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+152, uint32(iCode+libc.Int32FromInt32(1)), 0, 0x3)
		goto _1
	_1:
		;
		p = (*TVdbe)(unsafe.Pointer(p)).FpVNext
	}
}

// C documentation
//
//	/*
//	** Return the database associated with the Vdbe.
//	*/
func _sqlite3VdbeDb(tls *libc.TLS, v uintptr) (r uintptr) {
	return (*TVdbe)(unsafe.Pointer(v)).Fdb
}

// C documentation
//
//	/*
//	** Return the SQLITE_PREPARE flags for a Vdbe.
//	*/
func _sqlite3VdbePrepareFlags(tls *libc.TLS, v uintptr) (r Tu8) {
	return (*TVdbe)(unsafe.Pointer(v)).FprepFlags
}

// C documentation
//
//	/*
//	** Return a pointer to an sqlite3_value structure containing the value bound
//	** parameter iVar of VM v. Except, if the value is an SQL NULL, return
//	** 0 instead. Unless it is NULL, apply affinity aff (one of the SQLITE_AFF_*
//	** constants) to the value before returning it.
//	**
//	** The returned value must be freed by the caller using sqlite3ValueFree().
//	*/
func _sqlite3VdbeGetBoundValue(tls *libc.TLS, v uintptr, iVar int32, aff Tu8) (r uintptr) {
	var pMem, pRet uintptr
	_, _ = pMem, pRet
	if v != 0 {
		pMem = (*TVdbe)(unsafe.Pointer(v)).FaVar + uintptr(iVar-int32(1))*40
		if 0 == int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Null) {
			pRet = _sqlite3ValueNew(tls, (*TVdbe)(unsafe.Pointer(v)).Fdb)
			if pRet != 0 {
				_sqlite3VdbeMemCopy(tls, pRet, pMem)
				_sqlite3ValueApplyAffinity(tls, pRet, aff, uint8(SQLITE_UTF8))
			}
			return pRet
		}
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Configure SQL variable iVar so that binding a new value to it signals
//	** to sqlite3_reoptimize() that re-preparing the statement may result
//	** in a better query plan.
//	*/
func _sqlite3VdbeSetVarmask(tls *libc.TLS, v uintptr, iVar int32) {
	if iVar >= int32(32) {
		*(*Tu32)(unsafe.Pointer(v + 220)) |= uint32(0x80000000)
	} else {
		*(*Tu32)(unsafe.Pointer(v + 220)) |= libc.Uint32FromInt32(1) << (iVar - libc.Int32FromInt32(1))
	}
}

// C documentation
//
//	/*
//	** Cause a function to throw an error if it was call from OP_PureFunc
//	** rather than OP_Function.
//	**
//	** OP_PureFunc means that the function must be deterministic, and should
//	** throw an error if it is given inputs that would make it non-deterministic.
//	** This routine is invoked by date/time functions that use non-deterministic
//	** features such as 'now'.
//	*/
func _sqlite3NotPureFunc(tls *libc.TLS, pCtx uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pOp, zContext, zMsg uintptr
	_, _, _ = pOp, zContext, zMsg
	if (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe == uintptr(0) {
		return int32(1)
	}
	pOp = (*TVdbe)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe)).FaOp + uintptr((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp)*20
	if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_PureFunc) {
		if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fp5)&int32(NC_IsCheck) != 0 {
			zContext = __ccgo_ts + 6628
		} else {
			if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fp5)&int32(NC_GenCol) != 0 {
				zContext = __ccgo_ts + 6647
			} else {
				zContext = __ccgo_ts + 6666
			}
		}
		zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+6675, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpFunc)).FzName, zContext))
		Xsqlite3_result_error(tls, pCtx, zMsg, -int32(1))
		Xsqlite3_free(tls, zMsg)
		return 0
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
//	** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
//	** in memory obtained from sqlite3DbMalloc).
//	*/
func _sqlite3VtabImportErrmsg(tls *libc.TLS, p uintptr, pVtab uintptr) {
	var db uintptr
	_ = db
	if (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg != 0 {
		db = (*TVdbe)(unsafe.Pointer(p)).Fdb
		_sqlite3DbFree(tls, db, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg)
		(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = _sqlite3DbStrDup(tls, db, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
		Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
		(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** If the second argument is not NULL, release any allocations associated
//	** with the memory cells in the p->aMem[] array. Also free the UnpackedRecord
//	** structure itself, using sqlite3DbFree().
//	**
//	** This function is used to free UnpackedRecord structures allocated by
//	** the vdbeUnpackRecord() function found in vdbeapi.c.
//	*/
func _vdbeFreeUnpacked(tls *libc.TLS, db uintptr, nField int32, p uintptr) {
	var i int32
	var pMem uintptr
	_, _ = i, pMem
	if p != 0 {
		i = 0
		for {
			if !(i < nField) {
				break
			}
			pMem = (*TUnpackedRecord)(unsafe.Pointer(p)).FaMem + uintptr(i)*40
			if (*TMem)(unsafe.Pointer(pMem)).FzMalloc != 0 {
				_sqlite3VdbeMemReleaseMalloc(tls, pMem)
			}
			goto _1
		_1:
			;
			i++
		}
		_sqlite3DbNNFreeNN(tls, db, p)
	}
}

// C documentation
//
//	/*
//	** Invoke the pre-update hook. If this is an UPDATE or DELETE pre-update call,
//	** then cursor passed as the second argument should point to the row about
//	** to be update or deleted. If the application calls sqlite3_preupdate_old(),
//	** the required value will be read from the row the cursor points to.
//	*/
func _sqlite3VdbePreUpdateHook(tls *libc.TLS, v uintptr, pCsr uintptr, op int32, zDb uintptr, pTab uintptr, iKey1 Ti64, iReg int32, iBlobWrite int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var db, zTbl uintptr
	var i int32
	var iKey2, v1 Ti64
	var _ /* preupdate at bp+0 */ TPreUpdate
	_, _, _, _, _ = db, i, iKey2, zTbl, v1
	db = (*TVdbe)(unsafe.Pointer(v)).Fdb
	zTbl = (*TTable)(unsafe.Pointer(pTab)).FzName
	libc.Xmemset(tls, bp, 0, uint32(88))
	if libc.BoolInt32((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0)) == 0 {
		v1 = libc.Int64FromInt32(0)
		iKey2 = v1
		iKey1 = v1
		(*(*TPreUpdate)(unsafe.Pointer(bp))).FpPk = _sqlite3PrimaryKeyIndex(tls, pTab)
	} else {
		if op == int32(SQLITE_UPDATE) {
			iKey2 = *(*Ti64)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).FaMem + uintptr(iReg)*40))
		} else {
			iKey2 = iKey1
		}
	}
	(*(*TPreUpdate)(unsafe.Pointer(bp))).Fv = v
	(*(*TPreUpdate)(unsafe.Pointer(bp))).FpCsr = pCsr
	(*(*TPreUpdate)(unsafe.Pointer(bp))).Fop = op
	(*(*TPreUpdate)(unsafe.Pointer(bp))).FiNewReg = iReg
	(*(*TPreUpdate)(unsafe.Pointer(bp))).Fkeyinfo.Fdb = db
	(*(*TPreUpdate)(unsafe.Pointer(bp))).Fkeyinfo.Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
	(*(*TPreUpdate)(unsafe.Pointer(bp))).Fkeyinfo.FnKeyField = uint16((*TTable)(unsafe.Pointer(pTab)).FnCol)
	(*(*TPreUpdate)(unsafe.Pointer(bp))).Fkeyinfo.FaSortFlags = uintptr(unsafe.Pointer(&_fakeSortOrder))
	(*(*TPreUpdate)(unsafe.Pointer(bp))).FiKey1 = iKey1
	(*(*TPreUpdate)(unsafe.Pointer(bp))).FiKey2 = iKey2
	(*(*TPreUpdate)(unsafe.Pointer(bp))).FpTab = pTab
	(*(*TPreUpdate)(unsafe.Pointer(bp))).FiBlobWrite = iBlobWrite
	(*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdate = bp
	(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, Tsqlite3_int64, Tsqlite3_int64))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2)
	(*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdate = uintptr(0)
	_sqlite3DbFree(tls, db, (*(*TPreUpdate)(unsafe.Pointer(bp))).FaRecord)
	_vdbeFreeUnpacked(tls, db, int32((*(*TPreUpdate)(unsafe.Pointer(bp))).Fkeyinfo.FnKeyField)+int32(1), (*(*TPreUpdate)(unsafe.Pointer(bp))).FpUnpacked)
	_vdbeFreeUnpacked(tls, db, int32((*(*TPreUpdate)(unsafe.Pointer(bp))).Fkeyinfo.FnKeyField)+int32(1), (*(*TPreUpdate)(unsafe.Pointer(bp))).FpNewUnpacked)
	if (*(*TPreUpdate)(unsafe.Pointer(bp))).FaNew != 0 {
		i = 0
		for {
			if !(i < int32((*TVdbeCursor)(unsafe.Pointer(pCsr)).FnField)) {
				break
			}
			_sqlite3VdbeMemRelease(tls, (*(*TPreUpdate)(unsafe.Pointer(bp))).FaNew+uintptr(i)*40)
			goto _2
		_2:
			;
			i++
		}
		_sqlite3DbNNFreeNN(tls, db, (*(*TPreUpdate)(unsafe.Pointer(bp))).FaNew)
	}
}

var _fakeSortOrder Tu8

/************** End of vdbeaux.c *********************************************/
/************** Begin file vdbeapi.c *****************************************/
/*
** 2004 May 26
**
** 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 use to implement APIs that are part of the
** VDBE.
 */
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */
/* #include "opcodes.h" */

// 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 p uintptr
	_ = p
	p = pStmt
	return libc.BoolInt32(p == uintptr(0) || int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x3>>0)) != 0)
}

// C documentation
//
//	/*
//	** Check on a Vdbe to make sure it has not been finalized.  Log
//	** an error and return true if it has been finalized (or is otherwise
//	** invalid).  Return false if it is ok.
//	*/
func _vdbeSafety(tls *libc.TLS, p uintptr) (r int32) {
	if (*TVdbe)(unsafe.Pointer(p)).Fdb == uintptr(0) {
		Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+6711, 0)
		return int32(1)
	} else {
		return 0
	}
	return r
}

func _vdbeSafetyNotNull(tls *libc.TLS, p uintptr) (r int32) {
	if p == uintptr(0) {
		Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+6756, 0)
		return int32(1)
	} else {
		return _vdbeSafety(tls, p)
	}
	return r
}

// C documentation
//
//	/*
//	** Invoke the profile callback.  This routine is only called if we already
//	** know that the profile callback is defined and needs to be invoked.
//	*/
func _invokeProfileCallback(tls *libc.TLS, db uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* iElapse at bp+8 */ Tsqlite3_int64
	var _ /* iNow at bp+0 */ Tsqlite3_int64
	_sqlite3OsCurrentTimeInt64(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, bp)
	*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)) = (*(*Tsqlite3_int64)(unsafe.Pointer(bp)) - (*TVdbe)(unsafe.Pointer(p)).FstartTime) * int64(1000000)
	if (*Tsqlite3)(unsafe.Pointer(db)).FxProfile != 0 {
		(*(*func(*libc.TLS, uintptr, uintptr, Tu64))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxProfile})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpProfileArg, (*TVdbe)(unsafe.Pointer(p)).FzSql, uint64(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8))))
	}
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_PROFILE) != 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_PROFILE), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, p, bp+8)
	}
	(*TVdbe)(unsafe.Pointer(p)).FstartTime = 0
}

/*
** The checkProfileCallback(DB,P) macro checks to see if a profile callback
** is needed, and it invokes the callback if it is needed.
 */

// C documentation
//
//	/*
//	** The following routine destroys a virtual machine that is created by
//	** the sqlite3_compile() routine. The integer returned is an SQLITE_
//	** success/failure code that describes the result of executing the virtual
//	** machine.
//	**
//	** This routine sets the error code and string returned by
//	** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
//	*/
func Xsqlite3_finalize(tls *libc.TLS, pStmt uintptr) (r int32) {
	var db, v uintptr
	var rc int32
	_, _, _ = db, rc, v
	if pStmt == uintptr(0) {
		/* IMPLEMENTATION-OF: R-57228-12904 Invoking sqlite3_finalize() on a NULL
		 ** pointer is a harmless no-op. */
		rc = SQLITE_OK
	} else {
		v = pStmt
		db = (*TVdbe)(unsafe.Pointer(v)).Fdb
		if _vdbeSafety(tls, v) != 0 {
			return _sqlite3MisuseError(tls, int32(90484))
		}
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		if (*TVdbe)(unsafe.Pointer(v)).FstartTime > 0 {
			_invokeProfileCallback(tls, db, v)
		}
		rc = _sqlite3VdbeReset(tls, v)
		_sqlite3VdbeDelete(tls, v)
		rc = _sqlite3ApiExit(tls, db, rc)
		_sqlite3LeaveMutexAndCloseZombie(tls, db)
	}
	return rc
}

// C documentation
//
//	/*
//	** Terminate the current execution of an SQL statement and reset it
//	** back to its starting state so that it can be reused. A success code from
//	** the prior execution is returned.
//	**
//	** This routine sets the error code and string returned by
//	** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
//	*/
func Xsqlite3_reset(tls *libc.TLS, pStmt uintptr) (r int32) {
	var db, v uintptr
	var rc int32
	_, _, _ = db, rc, v
	if pStmt == uintptr(0) {
		rc = SQLITE_OK
	} else {
		v = pStmt
		db = (*TVdbe)(unsafe.Pointer(v)).Fdb
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		if (*TVdbe)(unsafe.Pointer(v)).FstartTime > 0 {
			_invokeProfileCallback(tls, db, v)
		}
		rc = _sqlite3VdbeReset(tls, v)
		_sqlite3VdbeRewind(tls, v)
		rc = _sqlite3ApiExit(tls, db, rc)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	}
	return rc
}

// 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)*40)
		(*(*TMem)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr(i)*40))).Fflags = uint16(MEM_Null)
		goto _1
	_1:
		;
		i++
	}
	if (*TVdbe)(unsafe.Pointer(p)).Fexpmask != 0 {
		libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(1), 0, 0x3)
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return rc
}

// C documentation
//
//	/**************************** sqlite3_value_  *******************************
//	** The following routines extract information from a Mem or sqlite3_value
//	** structure.
//	*/
func Xsqlite3_value_blob(tls *libc.TLS, pVal uintptr) (r uintptr) {
	var p, v3, p2 uintptr
	var v1 int32
	_, _, _, _ = p, v1, v3, p2
	p = pVal
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Blob)|libc.Int32FromInt32(MEM_Str)) != 0 {
		if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Zero) != 0 {
			v1 = _sqlite3VdbeMemExpandBlob(tls, p)
		} else {
			v1 = 0
		}
		if v1 != SQLITE_OK {
			return uintptr(0)
		}
		p2 = p + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_Blob))
		if (*TMem)(unsafe.Pointer(p)).Fn != 0 {
			v3 = (*TMem)(unsafe.Pointer(p)).Fz
		} else {
			v3 = uintptr(0)
		}
		return v3
	} else {
		return Xsqlite3_value_text(tls, pVal)
	}
	return r
}

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

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

func Xsqlite3_value_double(tls *libc.TLS, pVal uintptr) (r float64) {
	return _sqlite3VdbeRealValue(tls, pVal)
}

func Xsqlite3_value_int(tls *libc.TLS, pVal uintptr) (r int32) {
	return int32(_sqlite3VdbeIntValue(tls, pVal))
}

func Xsqlite3_value_int64(tls *libc.TLS, pVal uintptr) (r Tsqlite_int64) {
	return _sqlite3VdbeIntValue(tls, pVal)
}

func Xsqlite3_value_subtype(tls *libc.TLS, pVal uintptr) (r uint32) {
	var pMem uintptr
	var v1 int32
	_, _ = pMem, v1
	pMem = pVal
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Subtype) != 0 {
		v1 = int32((*TMem)(unsafe.Pointer(pMem)).FeSubtype)
	} else {
		v1 = 0
	}
	return uint32(v1)
}

func Xsqlite3_value_pointer(tls *libc.TLS, pVal uintptr, zPType uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = pVal
	if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Term)|libc.Int32FromInt32(MEM_Subtype)) == libc.Int32FromInt32(MEM_Null)|libc.Int32FromInt32(MEM_Term)|libc.Int32FromInt32(MEM_Subtype) && zPType != uintptr(0) && int32((*TMem)(unsafe.Pointer(p)).FeSubtype) == int32('p') && libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(p)).Fu)), zPType) == 0 {
		return (*TMem)(unsafe.Pointer(p)).Fz
	} else {
		return uintptr(0)
	}
	return r
}

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

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

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

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

// C documentation
//
//	/* EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five
//	** fundamental datatypes: 64-bit signed integer 64-bit IEEE floating
//	** point number string BLOB NULL
//	*/
func Xsqlite3_value_type(tls *libc.TLS, pVal uintptr) (r int32) {
	return int32(_aType[int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&int32(MEM_AffMask)])
}

var _aType = [64]Tu8{
	0:  uint8(SQLITE_BLOB),
	1:  uint8(SQLITE_NULL),
	2:  uint8(SQLITE_TEXT),
	3:  uint8(SQLITE_NULL),
	4:  uint8(SQLITE_INTEGER),
	5:  uint8(SQLITE_NULL),
	6:  uint8(SQLITE_INTEGER),
	7:  uint8(SQLITE_NULL),
	8:  uint8(SQLITE_FLOAT),
	9:  uint8(SQLITE_NULL),
	10: uint8(SQLITE_FLOAT),
	11: uint8(SQLITE_NULL),
	12: uint8(SQLITE_INTEGER),
	13: uint8(SQLITE_NULL),
	14: uint8(SQLITE_INTEGER),
	15: uint8(SQLITE_NULL),
	16: uint8(SQLITE_BLOB),
	17: uint8(SQLITE_NULL),
	18: uint8(SQLITE_TEXT),
	19: uint8(SQLITE_NULL),
	20: uint8(SQLITE_INTEGER),
	21: uint8(SQLITE_NULL),
	22: uint8(SQLITE_INTEGER),
	23: uint8(SQLITE_NULL),
	24: uint8(SQLITE_FLOAT),
	25: uint8(SQLITE_NULL),
	26: uint8(SQLITE_FLOAT),
	27: uint8(SQLITE_NULL),
	28: uint8(SQLITE_INTEGER),
	29: uint8(SQLITE_NULL),
	30: uint8(SQLITE_INTEGER),
	31: uint8(SQLITE_NULL),
	32: uint8(SQLITE_FLOAT),
	33: uint8(SQLITE_NULL),
	34: uint8(SQLITE_FLOAT),
	35: uint8(SQLITE_NULL),
	36: uint8(SQLITE_FLOAT),
	37: uint8(SQLITE_NULL),
	38: uint8(SQLITE_FLOAT),
	39: uint8(SQLITE_NULL),
	40: uint8(SQLITE_FLOAT),
	41: uint8(SQLITE_NULL),
	42: uint8(SQLITE_FLOAT),
	43: uint8(SQLITE_NULL),
	44: uint8(SQLITE_FLOAT),
	45: uint8(SQLITE_NULL),
	46: uint8(SQLITE_FLOAT),
	47: uint8(SQLITE_NULL),
	48: uint8(SQLITE_BLOB),
	49: uint8(SQLITE_NULL),
	50: uint8(SQLITE_TEXT),
	51: uint8(SQLITE_NULL),
	52: uint8(SQLITE_FLOAT),
	53: uint8(SQLITE_NULL),
	54: uint8(SQLITE_FLOAT),
	55: uint8(SQLITE_NULL),
	56: uint8(SQLITE_FLOAT),
	57: uint8(SQLITE_NULL),
	58: uint8(SQLITE_FLOAT),
	59: uint8(SQLITE_NULL),
	60: uint8(SQLITE_FLOAT),
	61: uint8(SQLITE_NULL),
	62: uint8(SQLITE_FLOAT),
	63: uint8(SQLITE_NULL),
}

func Xsqlite3_value_encoding(tls *libc.TLS, pVal uintptr) (r int32) {
	return int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fenc)
}

// C documentation
//
//	/* Return true if a parameter to xUpdate represents an unchanged column */
func Xsqlite3_value_nochange(tls *libc.TLS, pVal uintptr) (r int32) {
	return libc.BoolInt32(int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&(libc.Int32FromInt32(MEM_Null)|libc.Int32FromInt32(MEM_Zero)) == libc.Int32FromInt32(MEM_Null)|libc.Int32FromInt32(MEM_Zero))
}

// C documentation
//
//	/* Return true if a parameter value originated from an sqlite3_bind() */
func Xsqlite3_value_frombind(tls *libc.TLS, pVal uintptr) (r int32) {
	return libc.BoolInt32(int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&int32(MEM_FromBind) != 0)
}

// C documentation
//
//	/* Make a copy of an sqlite3_value object
//	*/
func Xsqlite3_value_dup(tls *libc.TLS, pOrig uintptr) (r uintptr) {
	var pNew, p1, p2, p3, p4 uintptr
	_, _, _, _, _ = pNew, p1, p2, p3, p4
	if pOrig == uintptr(0) {
		return uintptr(0)
	}
	pNew = Xsqlite3_malloc(tls, int32(40))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	libc.Xmemset(tls, pNew, 0, uint32(40))
	libc.Xmemcpy(tls, pNew, pOrig, uint32(libc.UintptrFromInt32(0)+20))
	p1 = pNew + 16
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(MEM_Dyn))
	(*Tsqlite3_value)(unsafe.Pointer(pNew)).Fdb = uintptr(0)
	if int32((*Tsqlite3_value)(unsafe.Pointer(pNew)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 {
		p2 = pNew + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^(libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_Dyn)))
		p3 = pNew + 16
		*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(MEM_Ephem))
		if _sqlite3VdbeMemMakeWriteable(tls, pNew) != SQLITE_OK {
			_sqlite3ValueFree(tls, pNew)
			pNew = uintptr(0)
		}
	} else {
		if int32((*Tsqlite3_value)(unsafe.Pointer(pNew)).Fflags)&int32(MEM_Null) != 0 {
			/* Do not duplicate pointer values */
			p4 = pNew + 16
			*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) & ^(libc.Int32FromInt32(MEM_Term) | libc.Int32FromInt32(MEM_Subtype)))
		}
	}
	return pNew
}

// C documentation
//
//	/* Destroy an sqlite3_value object previously obtained from
//	** sqlite3_value_dup().
//	*/
func Xsqlite3_value_free(tls *libc.TLS, pOld uintptr) {
	_sqlite3ValueFree(tls, pOld)
}

// C documentation
//
//	/**************************** sqlite3_result_  *******************************
//	** The following routines are used by user-defined functions to specify
//	** the function result.
//	**
//	** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
//	** result as a string or blob.  Appropriate errors are set if the string/blob
//	** is too big or if an OOM occurs.
//	**
//	** The invokeValueDestructor(P,X) routine invokes destructor function X()
//	** on value P if P is not going to be used and need to be destroyed.
//	*/
func _setResultStrOrError(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, enc Tu8, xDel uintptr) {
	var pOut uintptr
	var rc int32
	_, _ = pOut, rc
	pOut = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut
	rc = _sqlite3VdbeMemSetStr(tls, pOut, z, int64(int64(n)), enc, xDel)
	if rc != 0 {
		if rc == int32(SQLITE_TOOBIG) {
			Xsqlite3_result_error_toobig(tls, pCtx)
		} else {
			/* The only errors possible from sqlite3VdbeMemSetStr are
			 ** SQLITE_TOOBIG and SQLITE_NOMEM */
			Xsqlite3_result_error_nomem(tls, pCtx)
		}
		return
	}
	_sqlite3VdbeChangeEncoding(tls, pOut, int32((*Tsqlite3_context)(unsafe.Pointer(pCtx)).Fenc))
	if _sqlite3VdbeMemTooBig(tls, pOut) != 0 {
		Xsqlite3_result_error_toobig(tls, pCtx)
	}
}

func _invokeValueDestructor(tls *libc.TLS, p uintptr, xDel uintptr, pCtx uintptr) (r int32) {
	if xDel == uintptr(0) {
		/* noop */
	} else {
		if xDel == uintptr(-libc.Int32FromInt32(1)) {
			/* noop */
		} else {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDel})))(tls, p)
		}
	}
	Xsqlite3_result_error_toobig(tls, pCtx)
	return int32(SQLITE_TOOBIG)
}

func Xsqlite3_result_blob(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, xDel uintptr) {
	_setResultStrOrError(tls, pCtx, z, n, uint8(0), xDel)
}

func Xsqlite3_result_blob64(tls *libc.TLS, pCtx uintptr, z uintptr, n Tsqlite3_uint64, xDel uintptr) {
	if n > uint64(0x7fffffff) {
		_invokeValueDestructor(tls, z, xDel, pCtx)
	} else {
		_setResultStrOrError(tls, pCtx, z, int32(int32(n)), uint8(0), xDel)
	}
}

func Xsqlite3_result_double(tls *libc.TLS, pCtx uintptr, rVal float64) {
	_sqlite3VdbeMemSetDouble(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, rVal)
}

func Xsqlite3_result_error(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(int64(n)), uint8(SQLITE_UTF8), uintptr(-libc.Int32FromInt32(1)))
}

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(int64(n)), uint8(SQLITE_UTF16LE), uintptr(-libc.Int32FromInt32(1)))
}

func Xsqlite3_result_int(tls *libc.TLS, pCtx uintptr, iVal int32) {
	_sqlite3VdbeMemSetInt64(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, int64(int64(iVal)))
}

func Xsqlite3_result_int64(tls *libc.TLS, pCtx uintptr, iVal Ti64) {
	_sqlite3VdbeMemSetInt64(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, iVal)
}

func Xsqlite3_result_null(tls *libc.TLS, pCtx uintptr) {
	_sqlite3VdbeMemSetNull(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut)
}

func Xsqlite3_result_pointer(tls *libc.TLS, pCtx uintptr, pPtr uintptr, zPType uintptr, xDestructor uintptr) {
	var pOut uintptr
	_ = pOut
	pOut = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut
	_sqlite3VdbeMemRelease(tls, pOut)
	(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
	_sqlite3VdbeMemSetPointer(tls, pOut, pPtr, zPType, xDestructor)
}

func Xsqlite3_result_subtype(tls *libc.TLS, pCtx uintptr, eSubtype uint32) {
	var pOut, p1 uintptr
	_, _ = pOut, p1
	pOut = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut
	(*TMem)(unsafe.Pointer(pOut)).FeSubtype = uint8(eSubtype & uint32(0xff))
	p1 = pOut + 16
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(MEM_Subtype))
}

func Xsqlite3_result_text(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, xDel uintptr) {
	_setResultStrOrError(tls, pCtx, z, n, uint8(SQLITE_UTF8), xDel)
}

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

func Xsqlite3_result_text16(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, xDel uintptr) {
	_setResultStrOrError(tls, pCtx, z, int32(uint64(uint64(n)) & ^libc.Uint64FromInt32(1)), uint8(SQLITE_UTF16LE), xDel)
}

func Xsqlite3_result_text16be(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, xDel uintptr) {
	_setResultStrOrError(tls, pCtx, z, int32(uint64(uint64(n)) & ^libc.Uint64FromInt32(1)), uint8(SQLITE_UTF16BE), xDel)
}

func Xsqlite3_result_text16le(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, xDel uintptr) {
	_setResultStrOrError(tls, pCtx, z, int32(uint64(uint64(n)) & ^libc.Uint64FromInt32(1)), uint8(SQLITE_UTF16LE), xDel)
}

func Xsqlite3_result_value(tls *libc.TLS, pCtx uintptr, pValue uintptr) {
	var pOut uintptr
	_ = pOut
	pOut = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut
	_sqlite3VdbeMemCopy(tls, pOut, pValue)
	_sqlite3VdbeChangeEncoding(tls, pOut, int32((*Tsqlite3_context)(unsafe.Pointer(pCtx)).Fenc))
	if _sqlite3VdbeMemTooBig(tls, pOut) != 0 {
		Xsqlite3_result_error_toobig(tls, pCtx)
	}
}

func Xsqlite3_result_zeroblob(tls *libc.TLS, pCtx uintptr, n int32) {
	var v1 int32
	_ = v1
	if n > 0 {
		v1 = n
	} else {
		v1 = 0
	}
	Xsqlite3_result_zeroblob64(tls, pCtx, uint64(v1))
}

func Xsqlite3_result_zeroblob64(tls *libc.TLS, pCtx uintptr, n Tu64) (r int32) {
	var pOut uintptr
	_ = pOut
	pOut = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut
	if n > uint64(*(*int32)(unsafe.Pointer((*TMem)(unsafe.Pointer(pOut)).Fdb + 120))) {
		Xsqlite3_result_error_toobig(tls, pCtx)
		return int32(SQLITE_TOOBIG)
	}
	_sqlite3VdbeMemSetZeroBlob(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, int32(int32(n)))
	return SQLITE_OK
}

func Xsqlite3_result_error_code(tls *libc.TLS, pCtx uintptr, errCode int32) {
	var v1 int32
	_ = v1
	if errCode != 0 {
		v1 = errCode
	} else {
		v1 = -int32(1)
	}
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = v1
	if int32((*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut)).Fflags)&int32(MEM_Null) != 0 {
		_setResultStrOrError(tls, pCtx, _sqlite3ErrStr(tls, errCode), -int32(1), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
	}
}

// C documentation
//
//	/* Force an SQLITE_TOOBIG error. */
func Xsqlite3_result_error_toobig(tls *libc.TLS, pCtx uintptr) {
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = int32(SQLITE_TOOBIG)
	_sqlite3VdbeMemSetStr(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, __ccgo_ts+6796, int64(-int32(1)), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
}

// C documentation
//
//	/* An SQLITE_NOMEM error. */
func Xsqlite3_result_error_nomem(tls *libc.TLS, pCtx uintptr) {
	_sqlite3VdbeMemSetNull(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut)
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = int32(SQLITE_NOMEM)
	_sqlite3OomFault(tls, (*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut)).Fdb)
}

// C documentation
//
//	/* Force the INT64 value currently stored as the result to be
//	** a MEM_IntReal value.  See the SQLITE_TESTCTRL_RESULT_INTREAL
//	** test-control.
//	*/
func _sqlite3ResultIntReal(tls *libc.TLS, pCtx uintptr) {
	var p1, p2 uintptr
	_, _ = p1, p2
	if int32((*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut)).Fflags)&int32(MEM_Int) != 0 {
		p1 = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut + 16
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(MEM_Int))
		p2 = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_IntReal))
	}
}

// C documentation
//
//	/*
//	** This function is called after a transaction has been committed. It
//	** invokes callbacks registered with sqlite3_wal_hook() as required.
//	*/
func _doWalCallbacks(tls *libc.TLS, db uintptr) (r int32) {
	var i, nEntry, rc int32
	var pBt uintptr
	_, _, _, _ = i, nEntry, pBt, rc
	rc = SQLITE_OK
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 {
			_sqlite3BtreeEnter(tls, pBt)
			nEntry = _sqlite3PagerWalCallback(tls, _sqlite3BtreePager(tls, pBt))
			_sqlite3BtreeLeave(tls, pBt)
			if nEntry > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FxWalCallback != 0 && rc == SQLITE_OK {
				rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxWalCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpWalArg, db, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FzDbSName, nEntry)
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return rc
}

// 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 int32((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) != int32(VDBE_RUN_STATE) {
		goto restart_step
	restart_step:
		;
		if int32((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_READY_STATE) {
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x3>>0)) != 0 {
				(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_SCHEMA)
				rc = int32(SQLITE_ERROR)
				if int32((*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+312, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
			}
			if int32((*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+136)
			} else {
			}
			(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive++
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x40>>6)) == 0 {
				(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite++
			}
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x80>>7)) != 0 {
				(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead++
			}
			(*TVdbe)(unsafe.Pointer(p)).Fpc = 0
			(*TVdbe)(unsafe.Pointer(p)).FeVdbeState = uint8(VDBE_RUN_STATE)
		} else {
			if int32((*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 + 152))&0xc>>2)) != 0 {
		rc = _sqlite3VdbeList(tls, p)
	} else {
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec++
		rc = _sqlite3VdbeExec(tls, p)
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec--
	}
	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) && int32((*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 int32((*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
//
//	/*
//	** This is the top-level implementation of sqlite3_step().  Call
//	** sqlite3Step() to do most of the work.  If a schema error occurs,
//	** call sqlite3Reprepare() and try again.
//	*/
func Xsqlite3_step(tls *libc.TLS, pStmt uintptr) (r int32) {
	var cnt, rc, savedPc, v1, v2, v4, v5 int32
	var db, v, zErr uintptr
	var v3 bool
	_, _, _, _, _, _, _, _, _, _, _ = cnt, db, rc, savedPc, v, zErr, v1, v2, v3, v4, v5
	rc = SQLITE_OK /* Result from sqlite3Step() */
	v = pStmt      /* the prepared statement */
	cnt = 0        /* The database connection */
	if _vdbeSafetyNotNull(tls, v) != 0 {
		return _sqlite3MisuseError(tls, int32(91278))
	}
	db = (*TVdbe)(unsafe.Pointer(v)).Fdb
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	for {
		v1 = _sqlite3Step(tls, v)
		rc = v1
		if v3 = v1 == int32(SQLITE_SCHEMA); v3 {
			v2 = cnt
			cnt++
		}
		if !(v3 && v2 < int32(SQLITE_MAX_SCHEMA_RETRY)) {
			break
		}
		savedPc = (*TVdbe)(unsafe.Pointer(v)).Fpc
		rc = _sqlite3Reprepare(tls, v)
		if rc != SQLITE_OK {
			/* This case occurs after failing to recompile an sql statement.
			 ** The error message from the SQL compiler has already been loaded
			 ** into the database handle. This block copies the error message
			 ** from the database handle into the statement and sets the statement
			 ** program counter to 0 to ensure that when the statement is
			 ** finalized or reset the parser error message is available via
			 ** sqlite3_errmsg() and sqlite3_errcode().
			 */
			zErr = Xsqlite3_value_text(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
			_sqlite3DbFree(tls, db, (*TVdbe)(unsafe.Pointer(v)).FzErrMsg)
			if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
				(*TVdbe)(unsafe.Pointer(v)).FzErrMsg = _sqlite3DbStrDup(tls, db, zErr)
				v4 = _sqlite3ApiExit(tls, db, rc)
				rc = v4
				(*TVdbe)(unsafe.Pointer(v)).Frc = v4
			} else {
				(*TVdbe)(unsafe.Pointer(v)).FzErrMsg = uintptr(0)
				v5 = libc.Int32FromInt32(SQLITE_NOMEM)
				rc = v5
				(*TVdbe)(unsafe.Pointer(v)).Frc = v5
			}
			break
		}
		Xsqlite3_reset(tls, pStmt)
		if savedPc >= 0 {
			/* Setting minWriteFileFormat to 254 is a signal to the OP_Init and
			 ** OP_Trace opcodes to *not* perform SQLITE_TRACE_STMT because it has
			 ** already been done once on a prior invocation that failed due to
			 ** SQLITE_SCHEMA.   tag-20220401a  */
			(*TVdbe)(unsafe.Pointer(v)).FminWriteFileFormat = uint8(254)
		}
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Extract the user data from a sqlite3_context structure and return a
//	** pointer to it.
//	*/
func Xsqlite3_user_data(tls *libc.TLS, p uintptr) (r uintptr) {
	return (*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(p)).FpFunc)).FpUserData
}

// C documentation
//
//	/*
//	** Extract the user data from a sqlite3_context structure and return a
//	** pointer to it.
//	**
//	** IMPLEMENTATION-OF: R-46798-50301 The sqlite3_context_db_handle() interface
//	** returns a copy of the pointer to the database connection (the 1st
//	** parameter) of the sqlite3_create_function() and
//	** sqlite3_create_function16() routines that originally registered the
//	** application defined function.
//	*/
func Xsqlite3_context_db_handle(tls *libc.TLS, p uintptr) (r uintptr) {
	return (*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(p)).FpOut)).Fdb
}

// C documentation
//
//	/*
//	** If this routine is invoked from within an xColumn method of a virtual
//	** table, then it returns true if and only if the the call is during an
//	** UPDATE operation and the value of the column will not be modified
//	** by the UPDATE.
//	**
//	** If this routine is called from any context other than within the
//	** xColumn method of a virtual table, then the return value is meaningless
//	** and arbitrary.
//	**
//	** Virtual table implements might use this routine to optimize their
//	** performance by substituting a NULL result, or some other light-weight
//	** value, as a signal to the xUpdate routine that the column is unchanged.
//	*/
func Xsqlite3_vtab_nochange(tls *libc.TLS, p uintptr) (r int32) {
	return Xsqlite3_value_nochange(tls, (*Tsqlite3_context)(unsafe.Pointer(p)).FpOut)
}

// C documentation
//
//	/*
//	** The destructor function for a ValueList object.  This needs to be
//	** a separate function, unknowable to the application, to ensure that
//	** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not
//	** preceded by activation of IN processing via sqlite3_vtab_int() do not
//	** try to access a fake ValueList object inserted by a hostile extension.
//	*/
func _sqlite3VdbeValueListFree(tls *libc.TLS, pToDelete uintptr) {
	Xsqlite3_free(tls, pToDelete)
}

// C documentation
//
//	/*
//	** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
//	** sqlite3_vtab_in_next() (if bNext!=0).
//	*/
func _valueFromValueList(tls *libc.TLS, pVal uintptr, ppOut uintptr, bNext int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var iOff, rc, v1 int32
	var pOut, pRhs, zBuf uintptr
	var sz Tu32
	var _ /* dummy at bp+0 */ int32
	var _ /* iSerial at bp+48 */ Tu32
	var _ /* sMem at bp+8 */ TMem
	_, _, _, _, _, _, _ = iOff, pOut, pRhs, rc, sz, zBuf, v1
	*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
	if pVal == uintptr(0) {
		return _sqlite3MisuseError(tls, int32(91399))
	}
	if int32((*Tsqlite3_value)(unsafe.Pointer(pVal)).Fflags)&int32(MEM_Dyn) == 0 || (*Tsqlite3_value)(unsafe.Pointer(pVal)).FxDel != __ccgo_fp(_sqlite3VdbeValueListFree) {
		return int32(SQLITE_ERROR)
	} else {
		pRhs = (*Tsqlite3_value)(unsafe.Pointer(pVal)).Fz
	}
	if bNext != 0 {
		rc = _sqlite3BtreeNext(tls, (*TValueList)(unsafe.Pointer(pRhs)).FpCsr, 0)
	} else {
		*(*int32)(unsafe.Pointer(bp)) = 0
		rc = _sqlite3BtreeFirst(tls, (*TValueList)(unsafe.Pointer(pRhs)).FpCsr, bp)
		if _sqlite3BtreeEof(tls, (*TValueList)(unsafe.Pointer(pRhs)).FpCsr) != 0 {
			rc = int32(SQLITE_DONE)
		}
	}
	if rc == SQLITE_OK { /* Raw content of current row */
		libc.Xmemset(tls, bp+8, 0, uint32(40))
		sz = _sqlite3BtreePayloadSize(tls, (*TValueList)(unsafe.Pointer(pRhs)).FpCsr)
		rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, (*TValueList)(unsafe.Pointer(pRhs)).FpCsr, uint32(int32(int32(sz))), bp+8)
		if rc == SQLITE_OK {
			zBuf = (*(*TMem)(unsafe.Pointer(bp + 8))).Fz
			pOut = (*TValueList)(unsafe.Pointer(pRhs)).FpOut
			if int32(*(*Tu8)(unsafe.Pointer(zBuf + 1))) < int32(libc.Uint8FromInt32(0x80)) {
				*(*Tu32)(unsafe.Pointer(bp + 48)) = uint32(*(*Tu8)(unsafe.Pointer(zBuf + 1)))
				v1 = libc.Int32FromInt32(1)
			} else {
				v1 = int32(_sqlite3GetVarint32(tls, zBuf+1, bp+48))
			}
			iOff = int32(1) + int32(uint8(v1))
			_sqlite3VdbeSerialGet(tls, zBuf+uintptr(iOff), *(*Tu32)(unsafe.Pointer(bp + 48)), pOut)
			(*Tsqlite3_value)(unsafe.Pointer(pOut)).Fenc = (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_value)(unsafe.Pointer(pOut)).Fdb)).Fenc
			if int32((*Tsqlite3_value)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				rc = int32(SQLITE_NOMEM)
			} else {
				*(*uintptr)(unsafe.Pointer(ppOut)) = pOut
			}
		}
		_sqlite3VdbeMemRelease(tls, bp+8)
	}
	return rc
}

// C documentation
//
//	/*
//	** Set the iterator value pVal to point to the first value in the set.
//	** Set (*ppOut) to point to this value before returning.
//	*/
func Xsqlite3_vtab_in_first(tls *libc.TLS, pVal uintptr, ppOut uintptr) (r int32) {
	return _valueFromValueList(tls, pVal, ppOut, 0)
}

// C documentation
//
//	/*
//	** Set the iterator value pVal to point to the next value in the set.
//	** Set (*ppOut) to point to this value before returning.
//	*/
func Xsqlite3_vtab_in_next(tls *libc.TLS, pVal uintptr, ppOut uintptr) (r int32) {
	return _valueFromValueList(tls, pVal, ppOut, int32(1))
}

// C documentation
//
//	/*
//	** Return the current time for a statement.  If the current time
//	** is requested more than once within the same run of a single prepared
//	** statement, the exact same time is returned for each invocation regardless
//	** of the amount of time that elapses between invocations.  In other words,
//	** the time returned is always the time of the first call.
//	*/
func _sqlite3StmtCurrentTime(tls *libc.TLS, p uintptr) (r Tsqlite3_int64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var piTime, v1 uintptr
	var rc int32
	var _ /* iTime at bp+0 */ Tsqlite3_int64
	_, _, _ = piTime, rc, v1
	*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = 0
	if (*Tsqlite3_context)(unsafe.Pointer(p)).FpVdbe != uintptr(0) {
		v1 = (*Tsqlite3_context)(unsafe.Pointer(p)).FpVdbe + 56
	} else {
		v1 = bp
	}
	piTime = v1
	if *(*Tsqlite3_int64)(unsafe.Pointer(piTime)) == 0 {
		rc = _sqlite3OsCurrentTimeInt64(tls, (*Tsqlite3)(unsafe.Pointer((*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(p)).FpOut)).Fdb)).FpVfs, piTime)
		if rc != 0 {
			*(*Tsqlite3_int64)(unsafe.Pointer(piTime)) = 0
		}
	}
	return *(*Tsqlite3_int64)(unsafe.Pointer(piTime))
}

// C documentation
//
//	/*
//	** Create a new aggregate context for p and return a pointer to
//	** its pMem->z element.
//	*/
func _createAggContext(tls *libc.TLS, p uintptr, nByte int32) (r uintptr) {
	var pMem uintptr
	_ = pMem
	pMem = (*Tsqlite3_context)(unsafe.Pointer(p)).FpMem
	if nByte <= 0 {
		_sqlite3VdbeMemSetNull(tls, pMem)
		(*TMem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
	} else {
		_sqlite3VdbeMemClearAndResize(tls, pMem, nByte)
		(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Agg)
		*(*uintptr)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pMem)).Fu)) = (*Tsqlite3_context)(unsafe.Pointer(p)).FpFunc
		if (*TMem)(unsafe.Pointer(pMem)).Fz != 0 {
			libc.Xmemset(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, 0, uint32(uint32(nByte)))
		}
	}
	return (*TMem)(unsafe.Pointer(pMem)).Fz
}

// C documentation
//
//	/*
//	** Allocate or return the aggregate context for a user function.  A new
//	** context is allocated on the first call.  Subsequent calls return the
//	** same context that was returned on prior calls.
//	*/
func Xsqlite3_aggregate_context(tls *libc.TLS, p uintptr, nByte int32) (r uintptr) {
	if int32((*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(p)).FpMem)).Fflags)&int32(MEM_Agg) == 0 {
		return _createAggContext(tls, p, nByte)
	} else {
		return (*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(p)).FpMem)).Fz
	}
	return r
}

// C documentation
//
//	/*
//	** Return the auxiliary data pointer, if any, for the iArg'th argument to
//	** the user-function defined by pCtx.
//	**
//	** The left-most argument is 0.
//	**
//	** Undocumented behavior:  If iArg is negative then access a cache of
//	** auxiliary data pointers that is available to all functions within a
//	** single prepared statement.  The iArg values must match.
//	*/
func Xsqlite3_get_auxdata(tls *libc.TLS, pCtx uintptr, iArg int32) (r uintptr) {
	var pAuxData uintptr
	_ = pAuxData
	if (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe == uintptr(0) {
		return uintptr(0)
	}
	pAuxData = (*TVdbe)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe)).FpAuxData
	for {
		if !(pAuxData != 0) {
			break
		}
		if (*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxArg == iArg && ((*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxOp == (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp || iArg < 0) {
			return (*TAuxData)(unsafe.Pointer(pAuxData)).FpAux
		}
		goto _1
	_1:
		;
		pAuxData = (*TAuxData)(unsafe.Pointer(pAuxData)).FpNextAux
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Set the auxiliary data pointer and delete function, for the iArg'th
//	** argument to the user-function defined by pCtx. Any previous value is
//	** deleted by calling the delete function specified when it was set.
//	**
//	** The left-most argument is 0.
//	**
//	** Undocumented behavior:  If iArg is negative then make the data available
//	** to all functions within the current prepared statement using iArg as an
//	** access code.
//	*/
func Xsqlite3_set_auxdata(tls *libc.TLS, pCtx uintptr, iArg int32, pAux uintptr, xDelete uintptr) {
	var pAuxData, pVdbe uintptr
	_, _ = pAuxData, pVdbe
	pVdbe = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe
	if pVdbe == uintptr(0) {
		goto failed
	}
	pAuxData = (*TVdbe)(unsafe.Pointer(pVdbe)).FpAuxData
	for {
		if !(pAuxData != 0) {
			break
		}
		if (*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxArg == iArg && ((*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxOp == (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp || iArg < 0) {
			break
		}
		goto _1
	_1:
		;
		pAuxData = (*TAuxData)(unsafe.Pointer(pAuxData)).FpNextAux
	}
	if pAuxData == uintptr(0) {
		pAuxData = _sqlite3DbMallocZero(tls, (*TVdbe)(unsafe.Pointer(pVdbe)).Fdb, uint64(20))
		if !(pAuxData != 0) {
			goto failed
		}
		(*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxOp = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp
		(*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxArg = iArg
		(*TAuxData)(unsafe.Pointer(pAuxData)).FpNextAux = (*TVdbe)(unsafe.Pointer(pVdbe)).FpAuxData
		(*TVdbe)(unsafe.Pointer(pVdbe)).FpAuxData = pAuxData
		if (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError == 0 {
			(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = -int32(1)
		}
	} else {
		if (*TAuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TAuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux})))(tls, (*TAuxData)(unsafe.Pointer(pAuxData)).FpAux)
		}
	}
	(*TAuxData)(unsafe.Pointer(pAuxData)).FpAux = pAux
	(*TAuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux = xDelete
	return
	goto failed
failed:
	;
	if xDelete != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDelete})))(tls, pAux)
	}
}

// C documentation
//
//	/*
//	** Return the number of times the Step function of an aggregate has been
//	** called.
//	**
//	** This function is deprecated.  Do not use it for new code.  It is
//	** provide only to avoid breaking legacy code.  New aggregate function
//	** implementations should keep their own counts within their aggregate
//	** context.
//	*/
func Xsqlite3_aggregate_count(tls *libc.TLS, p uintptr) (r int32) {
	return (*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(p)).FpMem)).Fn
}

// C documentation
//
//	/*
//	** Return the number of columns in the result set for the statement pStmt.
//	*/
func Xsqlite3_column_count(tls *libc.TLS, pStmt uintptr) (r int32) {
	var pVm uintptr
	_ = pVm
	pVm = pStmt
	if pVm == uintptr(0) {
		return 0
	}
	return int32((*TVdbe)(unsafe.Pointer(pVm)).FnResColumn)
}

// C documentation
//
//	/*
//	** Return the number of values available from the current row of the
//	** currently executing statement pStmt.
//	*/
func Xsqlite3_data_count(tls *libc.TLS, pStmt uintptr) (r int32) {
	var pVm uintptr
	_ = pVm
	pVm = pStmt
	if pVm == uintptr(0) || (*TVdbe)(unsafe.Pointer(pVm)).FpResultRow == uintptr(0) {
		return 0
	}
	return int32((*TVdbe)(unsafe.Pointer(pVm)).FnResColumn)
}

// C documentation
//
//	/*
//	** Return a pointer to static memory containing an SQL NULL value.
//	*/
func _columnNullValue(tls *libc.TLS) (r uintptr) {
	return uintptr(unsafe.Pointer(&_nullMem))
}

/* Even though the Mem structure contains an element
 ** of type i64, on certain architectures (x86) with certain compiler
 ** switches (-Os), gcc may align this Mem object on a 4-byte boundary
 ** instead of an 8-byte one. This all works fine, except that when
 ** running with SQLITE_DEBUG defined the SQLite code sometimes assert()s
 ** that a Mem structure is located on an 8-byte boundary. To prevent
 ** these assert()s from failing, when building with SQLITE_DEBUG defined
 ** using gcc, we force nullMem to be 8-byte aligned using the magical
 ** __attribute__((aligned(8))) macro.  */
var _nullMem = TMem{
	Fflags: libc.Uint16FromInt32(MEM_Null),
}

// C documentation
//
//	/*
//	** Check to see if column iCol of the given statement is valid.  If
//	** it is, return a pointer to the Mem for the value of that column.
//	** If iCol is not valid, return a pointer to a Mem which has a value
//	** of NULL.
//	*/
func _columnMem(tls *libc.TLS, pStmt uintptr, i int32) (r uintptr) {
	var pOut, pVm uintptr
	_, _ = pOut, pVm
	pVm = pStmt
	if pVm == uintptr(0) {
		return _columnNullValue(tls)
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(pVm)).Fdb)).Fmutex)
	if (*TVdbe)(unsafe.Pointer(pVm)).FpResultRow != uintptr(0) && i < int32((*TVdbe)(unsafe.Pointer(pVm)).FnResColumn) && i >= 0 {
		pOut = (*TVdbe)(unsafe.Pointer(pVm)).FpResultRow + uintptr(i)*40
	} else {
		_sqlite3Error(tls, (*TVdbe)(unsafe.Pointer(pVm)).Fdb, int32(SQLITE_RANGE))
		pOut = _columnNullValue(tls)
	}
	return pOut
}

// C documentation
//
//	/*
//	** This function is called after invoking an sqlite3_value_XXX function on a
//	** column value (i.e. a value returned by evaluating an SQL expression in the
//	** select list of a SELECT statement) that may cause a malloc() failure. If
//	** malloc() has failed, the threads mallocFailed flag is cleared and the result
//	** code of statement pStmt set to SQLITE_NOMEM.
//	**
//	** Specifically, this is called from within:
//	**
//	**     sqlite3_column_int()
//	**     sqlite3_column_int64()
//	**     sqlite3_column_text()
//	**     sqlite3_column_text16()
//	**     sqlite3_column_real()
//	**     sqlite3_column_bytes()
//	**     sqlite3_column_bytes16()
//	**     sqlite3_column_blob()
//	*/
func _columnMallocFailure(tls *libc.TLS, pStmt uintptr) {
	var p uintptr
	_ = p
	/* If malloc() failed during an encoding conversion within an
	 ** sqlite3_column_XXX API, then set the return code of the statement to
	 ** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
	 ** and _finalize() will return NOMEM.
	 */
	p = pStmt
	if p != 0 {
		(*TVdbe)(unsafe.Pointer(p)).Frc = _sqlite3ApiExit(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, (*TVdbe)(unsafe.Pointer(p)).Frc)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
}

// C documentation
//
//	/**************************** sqlite3_column_  *******************************
//	** The following routines are used to access elements of the current row
//	** in the result set.
//	*/
func Xsqlite3_column_blob(tls *libc.TLS, pStmt uintptr, i int32) (r uintptr) {
	var val uintptr
	_ = val
	val = Xsqlite3_value_blob(tls, _columnMem(tls, pStmt, i))
	/* Even though there is no encoding conversion, value_blob() might
	 ** need to call malloc() to expand the result of a zeroblob()
	 ** expression.
	 */
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_bytes(tls *libc.TLS, pStmt uintptr, i int32) (r int32) {
	var val int32
	_ = val
	val = Xsqlite3_value_bytes(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_bytes16(tls *libc.TLS, pStmt uintptr, i int32) (r int32) {
	var val int32
	_ = val
	val = Xsqlite3_value_bytes16(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_double(tls *libc.TLS, pStmt uintptr, i int32) (r float64) {
	var val float64
	_ = val
	val = Xsqlite3_value_double(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_int(tls *libc.TLS, pStmt uintptr, i int32) (r int32) {
	var val int32
	_ = val
	val = Xsqlite3_value_int(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_int64(tls *libc.TLS, pStmt uintptr, i int32) (r Tsqlite_int64) {
	var val Tsqlite_int64
	_ = val
	val = Xsqlite3_value_int64(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_text(tls *libc.TLS, pStmt uintptr, i int32) (r uintptr) {
	var val uintptr
	_ = val
	val = Xsqlite3_value_text(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_value(tls *libc.TLS, pStmt uintptr, i int32) (r uintptr) {
	var pOut, p1, p2 uintptr
	_, _, _ = pOut, p1, p2
	pOut = _columnMem(tls, pStmt, i)
	if int32((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Static) != 0 {
		p1 = pOut + 16
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(MEM_Static))
		p2 = pOut + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_Ephem))
	}
	_columnMallocFailure(tls, pStmt)
	return pOut
}

func Xsqlite3_column_text16(tls *libc.TLS, pStmt uintptr, i int32) (r uintptr) {
	var val uintptr
	_ = val
	val = Xsqlite3_value_text16(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_type(tls *libc.TLS, pStmt uintptr, i int32) (r int32) {
	var iType int32
	_ = iType
	iType = Xsqlite3_value_type(tls, _columnMem(tls, pStmt, i))
	_columnMallocFailure(tls, pStmt)
	return iType
}

// C documentation
//
//	/*
//	** Column names appropriate for EXPLAIN or EXPLAIN QUERY PLAN.
//	*/
var _azExplainColNames8 = [12]uintptr{
	0:  __ccgo_ts + 6819,
	1:  __ccgo_ts + 6824,
	2:  __ccgo_ts + 6831,
	3:  __ccgo_ts + 6834,
	4:  __ccgo_ts + 6837,
	5:  __ccgo_ts + 6840,
	6:  __ccgo_ts + 6843,
	7:  __ccgo_ts + 6846,
	8:  __ccgo_ts + 6854,
	9:  __ccgo_ts + 6857,
	10: __ccgo_ts + 6864,
	11: __ccgo_ts + 6872,
}
var _azExplainColNames16data = [60]Tu16{
	0:  uint16('a'),
	1:  uint16('d'),
	2:  uint16('d'),
	3:  uint16('r'),
	5:  uint16('o'),
	6:  uint16('p'),
	7:  uint16('c'),
	8:  uint16('o'),
	9:  uint16('d'),
	10: uint16('e'),
	12: uint16('p'),
	13: uint16('1'),
	15: uint16('p'),
	16: uint16('2'),
	18: uint16('p'),
	19: uint16('3'),
	21: uint16('p'),
	22: uint16('4'),
	24: uint16('p'),
	25: uint16('5'),
	27: uint16('c'),
	28: uint16('o'),
	29: uint16('m'),
	30: uint16('m'),
	31: uint16('e'),
	32: uint16('n'),
	33: uint16('t'),
	35: uint16('i'),
	36: uint16('d'),
	38: uint16('p'),
	39: uint16('a'),
	40: uint16('r'),
	41: uint16('e'),
	42: uint16('n'),
	43: uint16('t'),
	45: uint16('n'),
	46: uint16('o'),
	47: uint16('t'),
	48: uint16('u'),
	49: uint16('s'),
	50: uint16('e'),
	51: uint16('d'),
	53: uint16('d'),
	54: uint16('e'),
	55: uint16('t'),
	56: uint16('a'),
	57: uint16('i'),
	58: uint16('l'),
}
var _iExplainColNames16 = [12]Tu8{
	1:  uint8(5),
	2:  uint8(12),
	3:  uint8(15),
	4:  uint8(18),
	5:  uint8(21),
	6:  uint8(24),
	7:  uint8(27),
	8:  uint8(35),
	9:  uint8(38),
	10: uint8(45),
	11: uint8(53),
}

// 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 + 152))&0xc>>2)) != 0 {
		if useType > 0 {
			goto columnName_end
		}
		if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0xc>>2)) == int32(1) {
			v1 = int32(8)
		} else {
			v1 = int32(4)
		}
		n = v1
		if N >= n {
			goto columnName_end
		}
		if useUtf16 != 0 {
			i = int32(_iExplainColNames16[N+int32(8)*int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0xc>>2))-int32(8)])
			ret = uintptr(unsafe.Pointer(&_azExplainColNames16data)) + uintptr(i)*2
		} else {
			ret = _azExplainColNames8[N+int32(8)*int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0xc>>2))-int32(8)]
		}
		goto columnName_end
	}
	n = int32((*TVdbe)(unsafe.Pointer(p)).FnResColumn)
	if N < n {
		prior_mallocFailed = (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed
		N += useType * n
		if useUtf16 != 0 {
			ret = Xsqlite3_value_text16(tls, (*TVdbe)(unsafe.Pointer(p)).FaColName+uintptr(N)*40)
		} else {
			ret = Xsqlite3_value_text(tls, (*TVdbe)(unsafe.Pointer(p)).FaColName+uintptr(N)*40)
		}
		/* A malloc may have failed inside of the _text() call. If this
		 ** is the case, clear the mallocFailed flag and return NULL.
		 */
		if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) > int32(int32(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 the name of the Nth column of the result set returned by SQL
//	** statement pStmt.
//	*/
func Xsqlite3_column_name(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, 0, COLNAME_NAME)
}

func Xsqlite3_column_name16(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, int32(1), COLNAME_NAME)
}

/*
** Constraint:  If you have ENABLE_COLUMN_METADATA then you must
** not define OMIT_DECLTYPE.
 */

// C documentation
//
//	/*
//	** Return the column declaration type (if applicable) of the 'i'th column
//	** of the result set of SQL statement pStmt.
//	*/
func Xsqlite3_column_decltype(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, 0, int32(COLNAME_DECLTYPE))
}

func Xsqlite3_column_decltype16(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, int32(1), int32(COLNAME_DECLTYPE))
}

// C documentation
//
//	/*
//	** Return the name of the database from which a result column derives.
//	** NULL is returned if the result column is an expression or constant or
//	** anything else which is not an unambiguous reference to a database column.
//	*/
func Xsqlite3_column_database_name(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, 0, int32(COLNAME_DATABASE))
}

func Xsqlite3_column_database_name16(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, int32(1), int32(COLNAME_DATABASE))
}

// C documentation
//
//	/*
//	** Return the name of the table from which a result column derives.
//	** NULL is returned if the result column is an expression or constant or
//	** anything else which is not an unambiguous reference to a database column.
//	*/
func Xsqlite3_column_table_name(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, 0, int32(COLNAME_TABLE))
}

func Xsqlite3_column_table_name16(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, int32(1), int32(COLNAME_TABLE))
}

// C documentation
//
//	/*
//	** Return the name of the table column from which a result column derives.
//	** NULL is returned if the result column is an expression or constant or
//	** anything else which is not an unambiguous reference to a database column.
//	*/
func Xsqlite3_column_origin_name(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, 0, int32(COLNAME_COLUMN))
}

func Xsqlite3_column_origin_name16(tls *libc.TLS, pStmt uintptr, N int32) (r uintptr) {
	return _columnName(tls, pStmt, N, int32(1), int32(COLNAME_COLUMN))
}

// 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.
//	*/
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(92003))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	if int32((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) != int32(VDBE_READY_STATE) {
		_sqlite3Error(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, _sqlite3MisuseError(tls, int32(92007)))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+6879, libc.VaList(bp+8, (*TVdbe)(unsafe.Pointer(p)).FzSql))
		return _sqlite3MisuseError(tls, int32(92011))
	}
	if i >= uint32((*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)*40
	_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+152, libc.Uint32FromInt32(1), 0, 0x3)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Bind a text or BLOB value.
//	*/
func _bindText(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData Ti64, xDel uintptr, encoding Tu8) (r int32) {
	var p, pVar uintptr
	var rc int32
	_, _, _ = p, pVar, rc
	p = pStmt
	rc = _vdbeUnbind(tls, p, uint32(i-libc.Int32FromInt32(1)))
	if rc == SQLITE_OK {
		if zData != uintptr(0) {
			pVar = (*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr(i-int32(1))*40
			rc = _sqlite3VdbeMemSetStr(tls, pVar, zData, nData, encoding, xDel)
			if rc == SQLITE_OK && int32(int32(encoding)) != 0 {
				rc = _sqlite3VdbeChangeEncoding(tls, pVar, int32((*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fenc))
			}
			if rc != 0 {
				_sqlite3Error(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, rc)
				rc = _sqlite3ApiExit(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, rc)
			}
		}
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	} else {
		if xDel != libc.UintptrFromInt32(0) && xDel != uintptr(-libc.Int32FromInt32(1)) {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDel})))(tls, zData)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Bind a blob value to an SQL statement variable.
//	*/
func Xsqlite3_bind_blob(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData int32, xDel uintptr) (r int32) {
	return _bindText(tls, pStmt, i, zData, int64(int64(nData)), xDel, uint8(0))
}

func Xsqlite3_bind_blob64(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData Tsqlite3_uint64, xDel uintptr) (r int32) {
	return _bindText(tls, pStmt, i, zData, int64(int64(nData)), xDel, uint8(0))
}

func Xsqlite3_bind_double(tls *libc.TLS, pStmt uintptr, i int32, rValue float64) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pStmt
	rc = _vdbeUnbind(tls, p, uint32(i-libc.Int32FromInt32(1)))
	if rc == SQLITE_OK {
		_sqlite3VdbeMemSetDouble(tls, (*TVdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-int32(1))*40, rValue)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_int(tls *libc.TLS, p uintptr, i int32, iValue int32) (r int32) {
	return Xsqlite3_bind_int64(tls, p, i, int64(int64(iValue)))
}

func Xsqlite3_bind_int64(tls *libc.TLS, pStmt uintptr, i int32, iValue Tsqlite_int64) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pStmt
	rc = _vdbeUnbind(tls, p, uint32(i-libc.Int32FromInt32(1)))
	if rc == SQLITE_OK {
		_sqlite3VdbeMemSetInt64(tls, (*TVdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-int32(1))*40, iValue)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_null(tls *libc.TLS, pStmt uintptr, i int32) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pStmt
	rc = _vdbeUnbind(tls, p, uint32(i-libc.Int32FromInt32(1)))
	if rc == SQLITE_OK {
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_pointer(tls *libc.TLS, pStmt uintptr, i int32, pPtr uintptr, zPTtype uintptr, xDestructor uintptr) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pStmt
	rc = _vdbeUnbind(tls, p, uint32(i-libc.Int32FromInt32(1)))
	if rc == SQLITE_OK {
		_sqlite3VdbeMemSetPointer(tls, (*TVdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-int32(1))*40, pPtr, zPTtype, xDestructor)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	} else {
		if xDestructor != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDestructor})))(tls, pPtr)
		}
	}
	return rc
}

func Xsqlite3_bind_text(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData int32, xDel uintptr) (r int32) {
	return _bindText(tls, pStmt, i, zData, int64(int64(nData)), xDel, uint8(SQLITE_UTF8))
}

func Xsqlite3_bind_text64(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData Tsqlite3_uint64, xDel uintptr, enc uint8) (r int32) {
	if int32(int32(enc)) != int32(SQLITE_UTF8) {
		if int32(int32(enc)) == int32(SQLITE_UTF16) {
			enc = uint8(SQLITE_UTF16LE)
		}
		nData &= uint64(^int32(libc.Uint16FromInt32(1)))
	}
	return _bindText(tls, pStmt, i, zData, int64(int64(nData)), xDel, enc)
}

func Xsqlite3_bind_text16(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, n int32, xDel uintptr) (r int32) {
	return _bindText(tls, pStmt, i, zData, int64(uint64(uint64(n)) & ^libc.Uint64FromInt32(1)), xDel, uint8(SQLITE_UTF16LE))
}

func Xsqlite3_bind_value(tls *libc.TLS, pStmt uintptr, i int32, pValue uintptr) (r int32) {
	var rc int32
	var v1 float64
	_, _ = rc, v1
	switch Xsqlite3_value_type(tls, pValue) {
	case int32(SQLITE_INTEGER):
		rc = Xsqlite3_bind_int64(tls, pStmt, i, *(*Ti64)(unsafe.Pointer(pValue)))
	case int32(SQLITE_FLOAT):
		if int32((*Tsqlite3_value)(unsafe.Pointer(pValue)).Fflags)&int32(MEM_Real) != 0 {
			v1 = *(*float64)(unsafe.Pointer(pValue))
		} else {
			v1 = float64(*(*Ti64)(unsafe.Pointer(pValue)))
		}
		rc = Xsqlite3_bind_double(tls, pStmt, i, v1)
	case int32(SQLITE_BLOB):
		if int32((*Tsqlite3_value)(unsafe.Pointer(pValue)).Fflags)&int32(MEM_Zero) != 0 {
			rc = Xsqlite3_bind_zeroblob(tls, pStmt, i, *(*int32)(unsafe.Pointer(&(*Tsqlite3_value)(unsafe.Pointer(pValue)).Fu)))
		} else {
			rc = Xsqlite3_bind_blob(tls, pStmt, i, (*Tsqlite3_value)(unsafe.Pointer(pValue)).Fz, (*Tsqlite3_value)(unsafe.Pointer(pValue)).Fn, uintptr(-libc.Int32FromInt32(1)))
		}
	case int32(SQLITE_TEXT):
		rc = _bindText(tls, pStmt, i, (*Tsqlite3_value)(unsafe.Pointer(pValue)).Fz, int64((*Tsqlite3_value)(unsafe.Pointer(pValue)).Fn), uintptr(-libc.Int32FromInt32(1)), (*Tsqlite3_value)(unsafe.Pointer(pValue)).Fenc)
	default:
		rc = Xsqlite3_bind_null(tls, pStmt, i)
		break
	}
	return rc
}

func Xsqlite3_bind_zeroblob(tls *libc.TLS, pStmt uintptr, i int32, n int32) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pStmt
	rc = _vdbeUnbind(tls, p, uint32(i-libc.Int32FromInt32(1)))
	if rc == SQLITE_OK {
		_sqlite3VdbeMemSetZeroBlob(tls, (*TVdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-int32(1))*40, n)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_zeroblob64(tls *libc.TLS, pStmt uintptr, i int32, n Tsqlite3_uint64) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pStmt
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	if n > uint64(*(*int32)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb + 120))) {
		rc = int32(SQLITE_TOOBIG)
	} else {
		rc = Xsqlite3_bind_zeroblob(tls, pStmt, i, int32(int32(n)))
	}
	rc = _sqlite3ApiExit(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Return the number of wildcards that can be potentially bound to.
//	** This routine is added to support DBD::SQLite.
//	*/
func Xsqlite3_bind_parameter_count(tls *libc.TLS, pStmt uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = pStmt
	if p != 0 {
		v1 = int32((*TVdbe)(unsafe.Pointer(p)).FnVar)
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Return the name of a wildcard parameter.  Return NULL if the index
//	** is out of range or if the wildcard is unnamed.
//	**
//	** The result is always UTF-8.
//	*/
func Xsqlite3_bind_parameter_name(tls *libc.TLS, pStmt uintptr, i int32) (r uintptr) {
	var p uintptr
	_ = p
	p = pStmt
	if p == uintptr(0) {
		return uintptr(0)
	}
	return _sqlite3VListNumToName(tls, (*TVdbe)(unsafe.Pointer(p)).FpVList, i)
}

// C documentation
//
//	/*
//	** Given a wildcard parameter name, return the index of the variable
//	** with that name.  If there is no variable with the given name,
//	** return 0.
//	*/
func _sqlite3VdbeParameterIndex(tls *libc.TLS, p uintptr, zName uintptr, nName int32) (r int32) {
	if p == uintptr(0) || zName == uintptr(0) {
		return 0
	}
	return _sqlite3VListNameToNum(tls, (*TVdbe)(unsafe.Pointer(p)).FpVList, zName, nName)
}

func Xsqlite3_bind_parameter_index(tls *libc.TLS, pStmt uintptr, zName uintptr) (r int32) {
	return _sqlite3VdbeParameterIndex(tls, pStmt, zName, _sqlite3Strlen30(tls, zName))
}

// C documentation
//
//	/*
//	** Transfer all bindings from the first statement over to the second.
//	*/
func _sqlite3TransferBindings(tls *libc.TLS, pFromStmt uintptr, pToStmt uintptr) (r int32) {
	var i int32
	var pFrom, pTo uintptr
	_, _, _ = i, pFrom, pTo
	pFrom = pFromStmt
	pTo = pToStmt
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(pTo)).Fdb)).Fmutex)
	i = 0
	for {
		if !(i < int32((*TVdbe)(unsafe.Pointer(pFrom)).FnVar)) {
			break
		}
		_sqlite3VdbeMemMove(tls, (*TVdbe)(unsafe.Pointer(pTo)).FaVar+uintptr(i)*40, (*TVdbe)(unsafe.Pointer(pFrom)).FaVar+uintptr(i)*40)
		goto _1
	_1:
		;
		i++
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(pTo)).Fdb)).Fmutex)
	return SQLITE_OK
}

// 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+152, libc.Uint32FromInt32(1), 0, 0x3)
	}
	if (*TVdbe)(unsafe.Pointer(pFrom)).Fexpmask != 0 {
		libc.SetBitFieldPtr16Uint32(pFrom+152, libc.Uint32FromInt32(1), 0, 0x3)
	}
	return _sqlite3TransferBindings(tls, pFromStmt, pToStmt)
}

// C documentation
//
//	/*
//	** Return the sqlite3* database handle to which the prepared statement given
//	** in the argument belongs.  This is the same database handle that was
//	** the first argument to the sqlite3_prepare() that was used to create
//	** the statement in the first place.
//	*/
func Xsqlite3_db_handle(tls *libc.TLS, pStmt uintptr) (r uintptr) {
	var v1 uintptr
	_ = v1
	if pStmt != 0 {
		v1 = (*TVdbe)(unsafe.Pointer(pStmt)).Fdb
	} else {
		v1 = uintptr(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 + 152)) & 0x40 >> 6))
	} else {
		v1 = int32(1)
	}
	return v1
}

// 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 + 152)) & 0xc >> 2))
	} else {
		v1 = 0
	}
	return v1
}

// 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 + 152))&0xc>>2)) == eMode {
		rc = SQLITE_OK
	} else {
		if eMode < 0 || eMode > int32(2) {
			rc = int32(SQLITE_ERROR)
		} else {
			if int32((*TVdbe)(unsafe.Pointer(v)).FprepFlags)&int32(SQLITE_PREPARE_SAVESQL) == 0 {
				rc = int32(SQLITE_ERROR)
			} else {
				if int32((*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 + 152))&0x100>>8)) != 0) {
						/* No reprepare necessary */
						libc.SetBitFieldPtr16Uint32(v+152, uint32(uint32(eMode)), 2, 0xc)
						rc = SQLITE_OK
					} else {
						libc.SetBitFieldPtr16Uint32(v+152, uint32(uint32(eMode)), 2, 0xc)
						rc = _sqlite3Reprepare(tls, v)
						libc.SetBitFieldPtr16Uint32(v+152, libc.BoolUint32(eMode == libc.Int32FromInt32(2)), 8, 0x100)
					}
				}
			}
		}
	}
	if int32(Tbft(*(*uint16)(unsafe.Pointer(v + 152))&0xc>>2)) != 0 {
		(*TVdbe)(unsafe.Pointer(v)).FnResColumn = uint16(int32(12) - int32(4)*int32(Tbft(*(*uint16)(unsafe.Pointer(v + 152))&0xc>>2)))
	} 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 true if the prepared statement is in need of being reset.
//	*/
func Xsqlite3_stmt_busy(tls *libc.TLS, pStmt uintptr) (r int32) {
	var v uintptr
	_ = v
	v = pStmt
	return libc.BoolInt32(v != uintptr(0) && int32((*TVdbe)(unsafe.Pointer(v)).FeVdbeState) == int32(VDBE_RUN_STATE))
}

// C documentation
//
//	/*
//	** Return a pointer to the next prepared statement after pStmt associated
//	** with database connection pDb.  If pStmt is NULL, return the first
//	** prepared statement for the database connection.  Return NULL if there
//	** are no more.
//	*/
func Xsqlite3_next_stmt(tls *libc.TLS, pDb uintptr, pStmt uintptr) (r uintptr) {
	var pNext uintptr
	_ = pNext
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pDb)).Fmutex)
	if pStmt == uintptr(0) {
		pNext = (*Tsqlite3)(unsafe.Pointer(pDb)).FpVdbe
	} else {
		pNext = (*TVdbe)(unsafe.Pointer(pStmt)).FpVNext
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(pDb)).Fmutex)
	return pNext
}

// C documentation
//
//	/*
//	** Return the value of a status counter for a prepared statement
//	*/
func Xsqlite3_stmt_status(tls *libc.TLS, pStmt uintptr, op int32, resetFlag int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pVdbe uintptr
	var _ /* v at bp+0 */ Tu32
	_, _ = db, pVdbe
	pVdbe = pStmt
	if op == int32(SQLITE_STMTSTATUS_MEMUSED) {
		db = (*TVdbe)(unsafe.Pointer(pVdbe)).Fdb
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed = bp
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart
		_sqlite3VdbeDelete(tls, pVdbe)
		(*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	} else {
		*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(pVdbe + 164 + uintptr(op)*4))
		if resetFlag != 0 {
			*(*Tu32)(unsafe.Pointer(pVdbe + 164 + uintptr(op)*4)) = uint32(0)
		}
	}
	return int32(*(*Tu32)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Return the SQL associated with a prepared statement
//	*/
func Xsqlite3_sql(tls *libc.TLS, pStmt uintptr) (r uintptr) {
	var p, v1 uintptr
	_, _ = p, v1
	p = pStmt
	if p != 0 {
		v1 = (*TVdbe)(unsafe.Pointer(p)).FzSql
	} else {
		v1 = uintptr(0)
	}
	return v1
}

// C documentation
//
//	/*
//	** Return the SQL associated with a prepared statement with
//	** bound parameters expanded.  Space to hold the returned string is
//	** obtained from sqlite3_malloc().  The caller is responsible for
//	** freeing the returned string by passing it to sqlite3_free().
//	**
//	** The SQLITE_TRACE_SIZE_LIMIT puts an upper bound on the size of
//	** expanded bound parameters.
//	*/
func Xsqlite3_expanded_sql(tls *libc.TLS, pStmt uintptr) (r uintptr) {
	var p, z, zSql uintptr
	_, _, _ = p, z, zSql
	z = uintptr(0)
	zSql = Xsqlite3_sql(tls, pStmt)
	if zSql != 0 {
		p = pStmt
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		z = _sqlite3VdbeExpandSql(tls, p, zSql)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return z
}

// C documentation
//
//	/*
//	** Allocate and populate an UnpackedRecord structure based on the serialized
//	** record in nKey/pKey. Return a pointer to the new UnpackedRecord structure
//	** if successful, or a NULL pointer if an OOM error is encountered.
//	*/
func _vdbeUnpackRecord(tls *libc.TLS, pKeyInfo uintptr, nKey int32, pKey uintptr) (r uintptr) {
	var pRet uintptr
	_ = pRet /* Return value */
	pRet = _sqlite3VdbeAllocUnpackedRecord(tls, pKeyInfo)
	if pRet != 0 {
		libc.Xmemset(tls, (*TUnpackedRecord)(unsafe.Pointer(pRet)).FaMem, 0, uint32(40)*uint32(int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)+libc.Int32FromInt32(1)))
		_sqlite3VdbeRecordUnpack(tls, pKeyInfo, nKey, pKey, pRet)
	}
	return pRet
}

// C documentation
//
//	/*
//	** This function is called from within a pre-update callback to retrieve
//	** a field of the row currently being updated or deleted.
//	*/
func Xsqlite3_preupdate_old(tls *libc.TLS, db uintptr, iIdx int32, ppValue uintptr) (r int32) {
	var aRec, p, pMem, v1 uintptr
	var nRec Tu32
	var rc int32
	_, _, _, _, _, _ = aRec, nRec, p, pMem, rc, v1
	rc = SQLITE_OK
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdate
	/* Test that this call is being made from within an SQLITE_DELETE or
	 ** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */
	if !(p != 0) || (*TPreUpdate)(unsafe.Pointer(p)).Fop == int32(SQLITE_INSERT) {
		rc = _sqlite3MisuseError(tls, int32(92547))
		goto preupdate_old_out
	}
	if (*TPreUpdate)(unsafe.Pointer(p)).FpPk != 0 {
		iIdx = int32(_sqlite3TableColumnToIndex(tls, (*TPreUpdate)(unsafe.Pointer(p)).FpPk, int16(int16(iIdx))))
	}
	if iIdx >= int32((*TVdbeCursor)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpCsr)).FnField) || iIdx < 0 {
		rc = int32(SQLITE_RANGE)
		goto preupdate_old_out
	}
	/* If the old.* record has not yet been loaded into memory, do so now. */
	if (*TPreUpdate)(unsafe.Pointer(p)).FpUnpacked == uintptr(0) {
		nRec = _sqlite3BtreePayloadSize(tls, *(*uintptr)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpCsr + 36)))
		aRec = _sqlite3DbMallocRaw(tls, db, uint64(uint64(nRec)))
		if !(aRec != 0) {
			goto preupdate_old_out
		}
		rc = _sqlite3BtreePayload(tls, *(*uintptr)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpCsr + 36)), uint32(0), nRec, aRec)
		if rc == SQLITE_OK {
			(*TPreUpdate)(unsafe.Pointer(p)).FpUnpacked = _vdbeUnpackRecord(tls, p+16, int32(int32(nRec)), aRec)
			if !((*TPreUpdate)(unsafe.Pointer(p)).FpUnpacked != 0) {
				rc = int32(SQLITE_NOMEM)
			}
		}
		if rc != SQLITE_OK {
			_sqlite3DbFree(tls, db, aRec)
			goto preupdate_old_out
		}
		(*TPreUpdate)(unsafe.Pointer(p)).FaRecord = aRec
	}
	v1 = (*TUnpackedRecord)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpUnpacked)).FaMem + uintptr(iIdx)*40
	*(*uintptr)(unsafe.Pointer(ppValue)) = v1
	pMem = v1
	if iIdx == int32((*TTable)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpTab)).FiPKey) {
		_sqlite3VdbeMemSetInt64(tls, pMem, (*TPreUpdate)(unsafe.Pointer(p)).FiKey1)
	} else {
		if iIdx >= int32((*TUnpackedRecord)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpUnpacked)).FnField) {
			*(*uintptr)(unsafe.Pointer(ppValue)) = _columnNullValue(tls)
		} else {
			if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpTab)).FaCol + uintptr(iIdx)*12))).Faffinity) == int32(SQLITE_AFF_REAL) {
				if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
					_sqlite3VdbeMemRealify(tls, pMem)
				}
			}
		}
	}
	goto preupdate_old_out
preupdate_old_out:
	;
	_sqlite3Error(tls, db, rc)
	return _sqlite3ApiExit(tls, db, rc)
}

// C documentation
//
//	/*
//	** This function is called from within a pre-update callback to retrieve
//	** the number of columns in the row being updated, deleted or inserted.
//	*/
func Xsqlite3_preupdate_count(tls *libc.TLS, db uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdate
	if p != 0 {
		v1 = int32((*TPreUpdate)(unsafe.Pointer(p)).Fkeyinfo.FnKeyField)
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** This function is designed to be called from within a pre-update callback
//	** only. It returns zero if the change that caused the callback was made
//	** immediately by a user SQL statement. Or, if the change was made by a
//	** trigger program, it returns the number of trigger programs currently
//	** on the stack (1 for a top-level trigger, 2 for a trigger fired by a
//	** top-level trigger etc.).
//	**
//	** For the purposes of the previous paragraph, a foreign key CASCADE, SET NULL
//	** or SET DEFAULT action is considered a trigger.
//	*/
func Xsqlite3_preupdate_depth(tls *libc.TLS, db uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdate
	if p != 0 {
		v1 = (*TVdbe)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).Fv)).FnFrame
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** This function is designed to be called from within a pre-update callback
//	** only.
//	*/
func Xsqlite3_preupdate_blobwrite(tls *libc.TLS, db uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdate
	if p != 0 {
		v1 = (*TPreUpdate)(unsafe.Pointer(p)).FiBlobWrite
	} else {
		v1 = -int32(1)
	}
	return v1
}

// C documentation
//
//	/*
//	** This function is called from within a pre-update callback to retrieve
//	** a field of the row currently being updated or inserted.
//	*/
func Xsqlite3_preupdate_new(tls *libc.TLS, db uintptr, iIdx int32, ppValue uintptr) (r int32) {
	var p, pData, pMem, pUnpack uintptr
	var rc, v1 int32
	_, _, _, _, _, _ = p, pData, pMem, pUnpack, rc, v1
	rc = SQLITE_OK
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdate
	if !(p != 0) || (*TPreUpdate)(unsafe.Pointer(p)).Fop == int32(SQLITE_DELETE) {
		rc = _sqlite3MisuseError(tls, int32(92670))
		goto preupdate_new_out
	}
	if (*TPreUpdate)(unsafe.Pointer(p)).FpPk != 0 && (*TPreUpdate)(unsafe.Pointer(p)).Fop != int32(SQLITE_UPDATE) {
		iIdx = int32(_sqlite3TableColumnToIndex(tls, (*TPreUpdate)(unsafe.Pointer(p)).FpPk, int16(int16(iIdx))))
	}
	if iIdx >= int32((*TVdbeCursor)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpCsr)).FnField) || iIdx < 0 {
		rc = int32(SQLITE_RANGE)
		goto preupdate_new_out
	}
	if (*TPreUpdate)(unsafe.Pointer(p)).Fop == int32(SQLITE_INSERT) {
		/* For an INSERT, memory cell p->iNewReg contains the serialized record
		 ** that is being inserted. Deserialize it. */
		pUnpack = (*TPreUpdate)(unsafe.Pointer(p)).FpNewUnpacked
		if !(pUnpack != 0) {
			pData = (*TVdbe)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).Fv)).FaMem + uintptr((*TPreUpdate)(unsafe.Pointer(p)).FiNewReg)*40
			if int32((*TMem)(unsafe.Pointer(pData)).Fflags)&int32(MEM_Zero) != 0 {
				v1 = _sqlite3VdbeMemExpandBlob(tls, pData)
			} else {
				v1 = 0
			}
			rc = v1
			if rc != SQLITE_OK {
				goto preupdate_new_out
			}
			pUnpack = _vdbeUnpackRecord(tls, p+16, (*TMem)(unsafe.Pointer(pData)).Fn, (*TMem)(unsafe.Pointer(pData)).Fz)
			if !(pUnpack != 0) {
				rc = int32(SQLITE_NOMEM)
				goto preupdate_new_out
			}
			(*TPreUpdate)(unsafe.Pointer(p)).FpNewUnpacked = pUnpack
		}
		pMem = (*TUnpackedRecord)(unsafe.Pointer(pUnpack)).FaMem + uintptr(iIdx)*40
		if iIdx == int32((*TTable)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpTab)).FiPKey) {
			_sqlite3VdbeMemSetInt64(tls, pMem, (*TPreUpdate)(unsafe.Pointer(p)).FiKey2)
		} else {
			if iIdx >= int32((*TUnpackedRecord)(unsafe.Pointer(pUnpack)).FnField) {
				pMem = _columnNullValue(tls)
			}
		}
	} else {
		/* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
		 ** value. Make a copy of the cell contents and return a pointer to it.
		 ** It is not safe to return a pointer to the memory cell itself as the
		 ** caller may modify the value text encoding.
		 */
		if !((*TPreUpdate)(unsafe.Pointer(p)).FaNew != 0) {
			(*TPreUpdate)(unsafe.Pointer(p)).FaNew = _sqlite3DbMallocZero(tls, db, uint64(uint32(40)*uint32((*TVdbeCursor)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpCsr)).FnField)))
			if !((*TPreUpdate)(unsafe.Pointer(p)).FaNew != 0) {
				rc = int32(SQLITE_NOMEM)
				goto preupdate_new_out
			}
		}
		pMem = (*TPreUpdate)(unsafe.Pointer(p)).FaNew + uintptr(iIdx)*40
		if int32((*TMem)(unsafe.Pointer(pMem)).Fflags) == 0 {
			if iIdx == int32((*TTable)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).FpTab)).FiPKey) {
				_sqlite3VdbeMemSetInt64(tls, pMem, (*TPreUpdate)(unsafe.Pointer(p)).FiKey2)
			} else {
				rc = _sqlite3VdbeMemCopy(tls, pMem, (*TVdbe)(unsafe.Pointer((*TPreUpdate)(unsafe.Pointer(p)).Fv)).FaMem+uintptr((*TPreUpdate)(unsafe.Pointer(p)).FiNewReg+int32(1)+iIdx)*40)
				if rc != SQLITE_OK {
					goto preupdate_new_out
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = pMem
	goto preupdate_new_out
preupdate_new_out:
	;
	_sqlite3Error(tls, db, rc)
	return _sqlite3ApiExit(tls, db, rc)
}

/************** End of vdbeapi.c *********************************************/
/************** Begin file vdbetrace.c ***************************************/
/*
** 2009 November 25
**
** 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 insert the values of host parameters
** (aka "wildcards") into the SQL text output by sqlite3_trace().
**
** The Vdbe parse-tree explainer is also found here.
 */
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */

// C documentation
//
//	/*
//	** zSql is a zero-terminated string of UTF-8 SQL text.  Return the number of
//	** bytes in this text up to but excluding the first character in
//	** a host parameter.  If the text contains no host parameters, return
//	** the total number of bytes in the text.
//	*/
func _findNextHostParameter(tls *libc.TLS, zSql uintptr, pnToken uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var n, nTotal int32
	var _ /* tokenType at bp+0 */ int32
	_, _ = n, nTotal
	nTotal = 0
	*(*int32)(unsafe.Pointer(pnToken)) = 0
	for *(*int8)(unsafe.Pointer(zSql)) != 0 {
		n = _sqlite3GetToken(tls, zSql, bp)
		if *(*int32)(unsafe.Pointer(bp)) == int32(TK_VARIABLE) {
			*(*int32)(unsafe.Pointer(pnToken)) = n
			break
		}
		nTotal += n
		zSql += uintptr(n)
	}
	return nTotal
}

// C documentation
//
//	/*
//	** This function returns a pointer to a nul-terminated string in memory
//	** obtained from sqlite3DbMalloc(). If sqlite3.nVdbeExec is 1, then the
//	** string contains a copy of zRawSql but with host parameters expanded to
//	** their current bindings. Or, if sqlite3.nVdbeExec is greater than 1,
//	** then the returned string holds a copy of zRawSql with "-- " prepended
//	** to each line of text.
//	**
//	** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then
//	** then long strings and blobs are truncated to that many bytes.  This
//	** can be used to prevent unreasonably large trace strings when dealing
//	** with large (multi-megabyte) strings and blobs.
//	**
//	** The calling function is responsible for making sure the memory returned
//	** is eventually freed.
//	**
//	** ALGORITHM:  Scan the input string looking for host parameters in any of
//	** these forms:  ?, ?N, $A, @A, :A.  Take care to avoid text within
//	** string literals, quoted identifier names, and comments.  For text forms,
//	** the host parameter index is found by scanning the prepared
//	** statement for the corresponding OP_Variable opcode.  Once the host
//	** parameter index is known, locate the value in p->aVar[].  Then render
//	** the value as a literal in place of the host parameter name.
//	*/
func _sqlite3VdbeExpandSql(tls *libc.TLS, p uintptr, zRawSql uintptr) (r uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var db, pVar, zStart, v1 uintptr
	var enc Tu8
	var i, n, nOut, nOut1, nextIndex, v2 int32
	var _ /* idx at bp+0 */ int32
	var _ /* nToken at bp+4 */ int32
	var _ /* out at bp+8 */ TStrAccum
	var _ /* utf8 at bp+32 */ TMem
	_, _, _, _, _, _, _, _, _, _, _ = db, enc, i, n, nOut, nOut1, nextIndex, pVar, zStart, v1, v2 /* The database connection */
	*(*int32)(unsafe.Pointer(bp)) = 0                                                             /* Index of a host parameter */
	nextIndex = int32(1)                                                                          /* Used to convert UTF16 into UTF8 for display */
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	_sqlite3StrAccumInit(tls, bp+8, uintptr(0), uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 120)))
	if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec > int32(1) {
		for *(*int8)(unsafe.Pointer(zRawSql)) != 0 {
			zStart = zRawSql
			for {
				v1 = zRawSql
				zRawSql++
				if !(int32(*(*int8)(unsafe.Pointer(v1))) != int32('\n') && *(*int8)(unsafe.Pointer(zRawSql)) != 0) {
					break
				}
			}
			Xsqlite3_str_append(tls, bp+8, __ccgo_ts+6919, int32(3))
			Xsqlite3_str_append(tls, bp+8, zStart, int32(int32(zRawSql))-int32(int32(zStart)))
		}
	} else {
		if int32((*TVdbe)(unsafe.Pointer(p)).FnVar) == 0 {
			Xsqlite3_str_append(tls, bp+8, zRawSql, _sqlite3Strlen30(tls, zRawSql))
		} else {
			for *(*int8)(unsafe.Pointer(zRawSql)) != 0 {
				n = _findNextHostParameter(tls, zRawSql, bp+4)
				Xsqlite3_str_append(tls, bp+8, zRawSql, n)
				zRawSql += uintptr(n)
				if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
					break
				}
				if int32(*(*int8)(unsafe.Pointer(zRawSql))) == int32('?') {
					if *(*int32)(unsafe.Pointer(bp + 4)) > int32(1) {
						_sqlite3GetInt32(tls, zRawSql+1, bp)
					} else {
						*(*int32)(unsafe.Pointer(bp)) = nextIndex
					}
				} else {
					*(*int32)(unsafe.Pointer(bp)) = _sqlite3VdbeParameterIndex(tls, p, zRawSql, *(*int32)(unsafe.Pointer(bp + 4)))
				}
				zRawSql += uintptr(*(*int32)(unsafe.Pointer(bp + 4)))
				if *(*int32)(unsafe.Pointer(bp))+int32(1) > nextIndex {
					v2 = *(*int32)(unsafe.Pointer(bp)) + int32(1)
				} else {
					v2 = nextIndex
				}
				nextIndex = v2
				pVar = (*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(1))*40
				if int32((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Null) != 0 {
					Xsqlite3_str_append(tls, bp+8, __ccgo_ts+1673, int32(4))
				} else {
					if int32((*TMem)(unsafe.Pointer(pVar)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
						Xsqlite3_str_appendf(tls, bp+8, __ccgo_ts+1433, libc.VaList(bp+80, *(*Ti64)(unsafe.Pointer(pVar))))
					} else {
						if int32((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Real) != 0 {
							Xsqlite3_str_appendf(tls, bp+8, __ccgo_ts+6440, libc.VaList(bp+80, *(*float64)(unsafe.Pointer(pVar))))
						} else {
							if int32((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Str) != 0 { /* Number of bytes of the string text to include in output */
								enc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
								if int32(int32(enc)) != int32(SQLITE_UTF8) {
									libc.Xmemset(tls, bp+32, 0, uint32(40))
									(*(*TMem)(unsafe.Pointer(bp + 32))).Fdb = db
									_sqlite3VdbeMemSetStr(tls, bp+32, (*TMem)(unsafe.Pointer(pVar)).Fz, int64((*TMem)(unsafe.Pointer(pVar)).Fn), enc, libc.UintptrFromInt32(0))
									if int32(SQLITE_NOMEM) == _sqlite3VdbeChangeEncoding(tls, bp+32, int32(SQLITE_UTF8)) {
										(*(*TStrAccum)(unsafe.Pointer(bp + 8))).FaccError = uint8(SQLITE_NOMEM)
										(*(*TStrAccum)(unsafe.Pointer(bp + 8))).FnAlloc = uint32(0)
									}
									pVar = bp + 32
								}
								nOut = (*TMem)(unsafe.Pointer(pVar)).Fn
								Xsqlite3_str_appendf(tls, bp+8, __ccgo_ts+6923, libc.VaList(bp+80, nOut, (*TMem)(unsafe.Pointer(pVar)).Fz))
								if int32(int32(enc)) != int32(SQLITE_UTF8) {
									_sqlite3VdbeMemRelease(tls, bp+32)
								}
							} else {
								if int32((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Zero) != 0 {
									Xsqlite3_str_appendf(tls, bp+8, __ccgo_ts+6930, libc.VaList(bp+80, *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pVar)).Fu))))
								} else { /* Number of bytes of the blob to include in output */
									Xsqlite3_str_append(tls, bp+8, __ccgo_ts+6943, int32(2))
									nOut1 = (*TMem)(unsafe.Pointer(pVar)).Fn
									i = 0
									for {
										if !(i < nOut1) {
											break
										}
										Xsqlite3_str_appendf(tls, bp+8, __ccgo_ts+6946, libc.VaList(bp+80, int32(*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pVar)).Fz + uintptr(i))))&int32(0xff)))
										goto _3
									_3:
										;
										i++
									}
									Xsqlite3_str_append(tls, bp+8, __ccgo_ts+6951, int32(1))
								}
							}
						}
					}
				}
			}
		}
	}
	if (*(*TStrAccum)(unsafe.Pointer(bp + 8))).FaccError != 0 {
		Xsqlite3_str_reset(tls, bp+8)
	}
	return _sqlite3StrAccumFinish(tls, bp+8)
}

/************** End of vdbetrace.c *******************************************/
/************** Begin file vdbe.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.
**
*************************************************************************
** The code in this file implements the function that runs the
** bytecode of a prepared statement.
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
 */
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */

/*
** Invoke this macro on memory cells just prior to changing the
** value of the cell.  This macro verifies that shallow copies are
** not misused.  A shallow copy of a string or blob just copies a
** pointer to the string or blob, not the content.  If the original
** is changed while the copy is still in use, the string or blob might
** be changed out from under the copy.  This macro verifies that nothing
** like that ever happens.
 */

/*
** The following global variable is incremented every time a cursor
** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes.  The test
** procedures use this information to make sure that indices are
** working correctly.  This variable has no function other than to
** help verify the correct operation of the library.
 */

/*
** When this global variable is positive, it gets decremented once before
** each instruction in the VDBE.  When it reaches zero, the u1.isInterrupted
** field of the sqlite3 structure is set in order to simulate an interrupt.
**
** This facility is used for testing purposes only.  It does not function
** in an ordinary build.
 */

/*
** The next global variable is incremented each type the OP_Sort opcode
** is executed.  The test procedures use this information to make sure that
** sorting is occurring or not occurring at appropriate times.   This variable
** has no function other than to help verify the correct operation of the
** library.
 */

/*
** The next global variable records the size of the largest MEM_Blob
** or MEM_Str that has been used by a VDBE opcode.  The test procedures
** use this information to make sure that the zero-blob functionality
** is working correctly.   This variable has no function other than to
** help verify the correct operation of the library.
 */

/*
** This macro evaluates to true if either the update hook or the preupdate
** hook are enabled for database connect DB.
 */

/*
** The next global variable is incremented each time the OP_Found opcode
** is executed. This is used to test whether or not the foreign key
** operation implemented using OP_FkIsZero is working. This variable
** has no function other than to help verify the correct operation of the
** library.
 */

/*
** Test a register to see if it exceeds the current maximum blob size.
** If it does, record the new maximum blob size.
 */

/*
** Invoke the VDBE coverage callback, if that callback is defined.  This
** feature is used for test suite validation only and does not appear an
** production builds.
**
** M is the type of branch.  I is the direction taken for this instance of
** the branch.
**
**   M: 2 - two-way branch (I=0: fall-thru   1: jump                )
**      3 - two-way + NULL (I=0: fall-thru   1: jump      2: NULL   )
**      4 - OP_Jump        (I=0: jump p1     1: jump p2   2: jump p3)
**
** In other words, if M is 2, then I is either 0 (for fall-through) or
** 1 (for when the branch is taken).  If M is 3, the I is 0 for an
** ordinary fall-through, I is 1 if the branch was taken, and I is 2
** if the result of comparison is NULL.  For M=3, I=2 the jump may or
** may not be taken, depending on the SQLITE_JUMPIFNULL flags in p5.
** When M is 4, that means that an OP_Jump is being run.  I is 0, 1, or 2
** depending on if the operands are less than, equal, or greater than.
**
** iSrcLine is the source code line (from the __LINE__ macro) that
** generated the VDBE instruction combined with flag bits.  The source
** code line number is in the lower 24 bits of iSrcLine and the upper
** 8 bytes are flags.  The lower three bits of the flags indicate
** values for I that should never occur.  For example, if the branch is
** always taken, the flags should be 0x05 since the fall-through and
** alternate branch are never taken.  If a branch is never taken then
** flags should be 0x06 since only the fall-through approach is allowed.
**
** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
** interested in equal or not-equal.  In other words, I==0 and I==2
** should be treated as equivalent
**
** Since only a line number is retained, not the filename, this macro
** only works for amalgamation builds.  But that is ok, since these macros
** should be no-ops except for special builds used to measure test coverage.
 */

/*
** An ephemeral string value (signified by the MEM_Ephem flag) contains
** a pointer to a dynamically allocated string where some other entity
** is responsible for deallocating that string.  Because the register
** does not control the string, it might be deleted without the register
** knowing it.
**
** This routine converts an ephemeral string into a dynamically allocated
** string that the register itself controls.  In other words, it
** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
 */

/* Return true if the cursor was opened using the OP_OpenSorter opcode. */

// C documentation
//
//	/*
//	** Allocate VdbeCursor number iCur.  Return a pointer to it.  Return NULL
//	** if we run out of memory.
//	*/
func _allocateCursor(tls *libc.TLS, p uintptr, iCur int32, nField int32, eCurType Tu8) (r uintptr) {
	var nByte, v2 int32
	var pCx, pMem, v1, v3, v4 uintptr
	_, _, _, _, _, _, _ = nByte, pCx, pMem, v1, v2, v3, v4
	if iCur > 0 {
		v1 = (*TVdbe)(unsafe.Pointer(p)).FaMem + uintptr((*TVdbe)(unsafe.Pointer(p)).FnMem-iCur)*40
	} else {
		v1 = (*TVdbe)(unsafe.Pointer(p)).FaMem
	}
	/* Find the memory cell that will be used to store the blob of memory
	 ** required for this VdbeCursor structure. It is convenient to use a
	 ** vdbe memory cell to manage the memory allocation required for a
	 ** VdbeCursor structure for the following reasons:
	 **
	 **   * Sometimes cursor numbers are used for a couple of different
	 **     purposes in a vdbe program. The different uses might require
	 **     different sized allocations. Memory cells provide growable
	 **     allocations.
	 **
	 **   * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
	 **     be freed lazily via the sqlite3_release_memory() API. This
	 **     minimizes the number of malloc calls made by the system.
	 **
	 ** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
	 ** the top of the register space.  Cursor 1 is at Mem[p->nMem-1].
	 ** Cursor 2 is at Mem[p->nMem-2]. And so forth.
	 */
	pMem = v1
	pCx = uintptr(0)
	if int32(int32(eCurType)) == CURTYPE_BTREE {
		v2 = _sqlite3BtreeCursorSize(tls)
	} else {
		v2 = 0
	}
	nByte = int32((libc.Uint32FromInt64(88)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)) + libc.Uint32FromInt32(2)*libc.Uint32FromInt64(4)*uint32(uint32(nField)) + uint32(v2))
	if *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*4)) != 0 { /*OPTIMIZATION-IF-FALSE*/
		_sqlite3VdbeFreeCursorNN(tls, p, *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*4)))
		*(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*4)) = uintptr(0)
	}
	/* There used to be a call to sqlite3VdbeMemClearAndResize() to make sure
	 ** the pMem used to hold space for the cursor has enough storage available
	 ** in pMem->zMalloc.  But for the special case of the aMem[] entries used
	 ** to hold cursors, it is faster to in-line the logic. */
	if (*TMem)(unsafe.Pointer(pMem)).FszMalloc < nByte {
		if (*TMem)(unsafe.Pointer(pMem)).FszMalloc > 0 {
			_sqlite3DbFreeNN(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).FzMalloc)
		}
		v3 = _sqlite3DbMallocRaw(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, uint64(uint64(nByte)))
		(*TMem)(unsafe.Pointer(pMem)).FzMalloc = v3
		(*TMem)(unsafe.Pointer(pMem)).Fz = v3
		if (*TMem)(unsafe.Pointer(pMem)).FzMalloc == uintptr(0) {
			(*TMem)(unsafe.Pointer(pMem)).FszMalloc = 0
			return uintptr(0)
		}
		(*TMem)(unsafe.Pointer(pMem)).FszMalloc = nByte
	}
	v4 = (*TMem)(unsafe.Pointer(pMem)).FzMalloc
	pCx = v4
	*(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*4)) = v4
	libc.Xmemset(tls, pCx, 0, uint32(libc.UintptrFromInt32(0)+32))
	(*TVdbeCursor)(unsafe.Pointer(pCx)).FeCurType = eCurType
	(*TVdbeCursor)(unsafe.Pointer(pCx)).FnField = int16(int16(nField))
	(*TVdbeCursor)(unsafe.Pointer(pCx)).FaOffset = pCx + 84 + uintptr(nField)*4
	if int32(int32(eCurType)) == CURTYPE_BTREE {
		*(*uintptr)(unsafe.Pointer(pCx + 36)) = (*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((libc.Uint32FromInt64(88)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7))+libc.Uint32FromInt32(2)*libc.Uint32FromInt64(4)*uint32(uint32(nField)))
		_sqlite3BtreeCursorZero(tls, *(*uintptr)(unsafe.Pointer(pCx + 36)))
	}
	return pCx
}

// C documentation
//
//	/*
//	** The string in pRec is known to look like an integer and to have a
//	** floating point value of rValue.  Return true and set *piValue to the
//	** integer value if the string is in range to be an integer.  Otherwise,
//	** return false.
//	*/
func _alsoAnInt(tls *libc.TLS, pRec uintptr, rValue float64, piValue uintptr) (r int32) {
	var iValue Ti64
	_ = iValue
	iValue = _sqlite3RealToI64(tls, rValue)
	if _sqlite3RealSameAsInt(tls, rValue, iValue) != 0 {
		*(*Ti64)(unsafe.Pointer(piValue)) = iValue
		return int32(1)
	}
	return libc.BoolInt32(0 == _sqlite3Atoi64(tls, (*TMem)(unsafe.Pointer(pRec)).Fz, piValue, (*TMem)(unsafe.Pointer(pRec)).Fn, (*TMem)(unsafe.Pointer(pRec)).Fenc))
}

// C documentation
//
//	/*
//	** Try to convert a value into a numeric representation if we can
//	** do so without loss of information.  In other words, if the string
//	** looks like a number, convert it into a number.  If it does not
//	** look like a number, leave it alone.
//	**
//	** If the bTryForInt flag is true, then extra effort is made to give
//	** an integer representation.  Strings that look like floating point
//	** values but which have no fractional component (example: '48.00')
//	** will have a MEM_Int representation when bTryForInt is true.
//	**
//	** If bTryForInt is false, then if the input string contains a decimal
//	** point or exponential notation, the result is only MEM_Real, even
//	** if there is an exact integer representation of the quantity.
//	*/
func _applyNumericAffinity(tls *libc.TLS, pRec uintptr, bTryForInt int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var enc Tu8
	var rc int32
	var p1, p2, p3 uintptr
	var _ /* rValue at bp+0 */ float64
	_, _, _, _, _ = enc, rc, p1, p2, p3
	enc = (*TMem)(unsafe.Pointer(pRec)).Fenc
	rc = _sqlite3AtoF(tls, (*TMem)(unsafe.Pointer(pRec)).Fz, bp, (*TMem)(unsafe.Pointer(pRec)).Fn, enc)
	if rc <= 0 {
		return
	}
	if rc == int32(1) && _alsoAnInt(tls, pRec, *(*float64)(unsafe.Pointer(bp)), pRec) != 0 {
		p1 = pRec + 16
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(MEM_Int))
	} else {
		*(*float64)(unsafe.Pointer(pRec)) = *(*float64)(unsafe.Pointer(bp))
		p2 = pRec + 16
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_Real))
		if bTryForInt != 0 {
			_sqlite3VdbeIntegerAffinity(tls, pRec)
		}
	}
	/* TEXT->NUMERIC is many->one.  Hence, it is important to invalidate the
	 ** string representation after computing a numeric equivalent, because the
	 ** string representation might not be the canonical representation for the
	 ** numeric value.  Ticket [343634942dd54ab57b7024] 2018-01-31. */
	p3 = pRec + 16
	*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(MEM_Str))
}

// C documentation
//
//	/*
//	** Processing is determine by the affinity parameter:
//	**
//	** SQLITE_AFF_INTEGER:
//	** SQLITE_AFF_REAL:
//	** SQLITE_AFF_NUMERIC:
//	**    Try to convert pRec to an integer representation or a
//	**    floating-point representation if an integer representation
//	**    is not possible.  Note that the integer representation is
//	**    always preferred, even if the affinity is REAL, because
//	**    an integer representation is more space efficient on disk.
//	**
//	** SQLITE_AFF_FLEXNUM:
//	**    If the value is text, then try to convert it into a number of
//	**    some kind (integer or real) but do not make any other changes.
//	**
//	** SQLITE_AFF_TEXT:
//	**    Convert pRec to a text representation.
//	**
//	** SQLITE_AFF_BLOB:
//	** SQLITE_AFF_NONE:
//	**    No-op.  pRec is unchanged.
//	*/
func _applyAffinity(tls *libc.TLS, pRec uintptr, affinity int8, enc Tu8) {
	var p1 uintptr
	_ = p1
	if int32(int32(affinity)) >= int32(SQLITE_AFF_NUMERIC) {
		if int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Int) == 0 { /*OPTIMIZATION-IF-FALSE*/
			if int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&(libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
				if int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Str) != 0 {
					_applyNumericAffinity(tls, pRec, int32(1))
				}
			} else {
				if int32(int32(affinity)) <= int32(SQLITE_AFF_REAL) {
					_sqlite3VdbeIntegerAffinity(tls, pRec)
				}
			}
		}
	} else {
		if int32(int32(affinity)) == int32(SQLITE_AFF_TEXT) {
			/* Only attempt the conversion to TEXT if there is an integer or real
			 ** representation (blob and NULL do not get converted) but no string
			 ** representation.  It would be harmless to repeat the conversion if
			 ** there is already a string rep, but it is pointless to waste those
			 ** CPU cycles. */
			if 0 == int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Str) { /*OPTIMIZATION-IF-FALSE*/
				if int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&(libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
					_sqlite3VdbeMemStringify(tls, pRec, enc, uint8(1))
				}
			}
			p1 = pRec + 16
			*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^(libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_IntReal)))
		}
	}
}

// C documentation
//
//	/*
//	** Try to convert the type of a function argument or a result column
//	** into a numeric representation.  Use either INTEGER or REAL whichever
//	** is appropriate.  But only do the conversion if it is possible without
//	** loss of information and return the revised type of the argument.
//	*/
func Xsqlite3_value_numeric_type(tls *libc.TLS, pVal uintptr) (r int32) {
	var eType int32
	var pMem uintptr
	_, _ = eType, pMem
	eType = Xsqlite3_value_type(tls, pVal)
	if eType == int32(SQLITE_TEXT) {
		pMem = pVal
		_applyNumericAffinity(tls, pMem, 0)
		eType = Xsqlite3_value_type(tls, pVal)
	}
	return eType
}

// C documentation
//
//	/*
//	** Exported version of applyAffinity(). This one works on sqlite3_value*,
//	** not the internal Mem* type.
//	*/
func _sqlite3ValueApplyAffinity(tls *libc.TLS, pVal uintptr, affinity Tu8, enc Tu8) {
	_applyAffinity(tls, pVal, int8(int8(affinity)), enc)
}

// C documentation
//
//	/*
//	** pMem currently only holds a string type (or maybe a BLOB that we can
//	** interpret as a string if we want to).  Compute its corresponding
//	** numeric type, if has one.  Set the pMem->u.r and pMem->u.i fields
//	** accordingly.
//	*/
func _computeNumericType(tls *libc.TLS, pMem uintptr) (r Tu16) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc, v1 int32
	var _ /* ix at bp+0 */ Tsqlite3_int64
	_, _ = rc, v1
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Zero) != 0 {
		v1 = _sqlite3VdbeMemExpandBlob(tls, pMem)
	} else {
		v1 = 0
	}
	if v1 != 0 {
		*(*Ti64)(unsafe.Pointer(pMem)) = 0
		return uint16(MEM_Int)
	}
	rc = _sqlite3AtoF(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, pMem, (*TMem)(unsafe.Pointer(pMem)).Fn, (*TMem)(unsafe.Pointer(pMem)).Fenc)
	if rc <= 0 {
		if rc == 0 && _sqlite3Atoi64(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, bp, (*TMem)(unsafe.Pointer(pMem)).Fn, (*TMem)(unsafe.Pointer(pMem)).Fenc) <= int32(1) {
			*(*Ti64)(unsafe.Pointer(pMem)) = *(*Tsqlite3_int64)(unsafe.Pointer(bp))
			return uint16(MEM_Int)
		} else {
			return uint16(MEM_Real)
		}
	} else {
		if rc == int32(1) && _sqlite3Atoi64(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, bp, (*TMem)(unsafe.Pointer(pMem)).Fn, (*TMem)(unsafe.Pointer(pMem)).Fenc) == 0 {
			*(*Ti64)(unsafe.Pointer(pMem)) = *(*Tsqlite3_int64)(unsafe.Pointer(bp))
			return uint16(MEM_Int)
		}
	}
	return uint16(MEM_Real)
}

// C documentation
//
//	/*
//	** Return the numeric type for pMem, either MEM_Int or MEM_Real or both or
//	** none.
//	**
//	** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
//	** But it does set pMem->u.r and pMem->u.i appropriately.
//	*/
func _numericType(tls *libc.TLS, pMem uintptr) (r Tu16) {
	if int32((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Null)) != 0 {
		return uint16(int32((*TMem)(unsafe.Pointer(pMem)).Fflags) & (libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal) | libc.Int32FromInt32(MEM_Null)))
	}
	return _computeNumericType(tls, pMem)
	return uint16(0)
}

// C documentation
//
//	/*
//	** Return the register of pOp->p2 after first preparing it to be
//	** overwritten with an integer value.
//	*/
func _out2PrereleaseWithClear(tls *libc.TLS, pOut uintptr) (r uintptr) {
	_sqlite3VdbeMemSetNull(tls, pOut)
	(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
	return pOut
}

func _out2Prerelease(tls *libc.TLS, p uintptr, pOp uintptr) (r uintptr) {
	var pOut uintptr
	_ = pOut
	pOut = (*TVdbe)(unsafe.Pointer(p)).FaMem + uintptr((*TVdbeOp)(unsafe.Pointer(pOp)).Fp2)*40
	if int32((*TMem)(unsafe.Pointer(pOut)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 { /*OPTIMIZATION-IF-FALSE*/
		return _out2PrereleaseWithClear(tls, pOut)
	} else {
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
		return pOut
	}
	return r
}

// C documentation
//
//	/*
//	** Compute a bloom filter hash using pOp->p4.i registers from aMem[] beginning
//	** with pOp->p3.  Return the hash.
//	*/
func _filterHash(tls *libc.TLS, aMem uintptr, pOp uintptr) (r Tu64) {
	var h Tu64
	var i, mx int32
	var p uintptr
	_, _, _, _ = h, i, mx, p
	h = uint64(0)
	i = (*TOp)(unsafe.Pointer(pOp)).Fp3
	mx = i + *(*int32)(unsafe.Pointer(pOp + 16))
	for {
		if !(i < mx) {
			break
		}
		p = aMem + uintptr(i)*40
		if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
			h += uint64(*(*Ti64)(unsafe.Pointer(p)))
		} else {
			if int32((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_Real) != 0 {
				h += uint64(_sqlite3VdbeIntValue(tls, p))
			} else {
				if int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 {
					/* All strings have the same hash and all blobs have the same hash,
					 ** though, at least, those hashes are different from each other and
					 ** from NULL. */
					h += uint64(int32(4093) + int32((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)))
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return h
}

// 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 int32, iOffset Ti64, cacheStatus Tu32, colCacheCtr Tu32, pDest uintptr) (r int32) {
	var db, pBuf, pCache, v1, p2, p3, p4 uintptr
	var encoding, len1, rc int32
	_, _, _, _, _, _, _, _, _, _ = db, encoding, len1, pBuf, pCache, rc, v1, p2, p3, p4
	db = (*TMem)(unsafe.Pointer(pDest)).Fdb
	encoding = int32((*TMem)(unsafe.Pointer(pDest)).Fenc)
	len1 = int32(_sqlite3VdbeSerialTypeLen(tls, uint32(uint32(t))))
	if len1 > *(*int32)(unsafe.Pointer(db + 120)) {
		return int32(SQLITE_TOOBIG)
	}
	if len1 > int32(4000) && (*TVdbeCursor)(unsafe.Pointer(pC)).FpKeyInfo == uintptr(0) {
		if int32(TBool(*(*uint8)(unsafe.Pointer(pC + 8))&0x10>>4)) == 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), 4, 0x10)
		}
		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 + 36))) {
			if (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue != 0 {
				_sqlite3RCStrUnref(tls, (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue)
			}
			v1 = _sqlite3RCStrNew(tls, uint64(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 + 36)), uint32(uint32(iOffset)), uint32(uint32(len1)), pBuf)
			if rc != 0 {
				return rc
			}
			*(*int8)(unsafe.Pointer(pBuf + uintptr(len1))) = 0
			*(*int8)(unsafe.Pointer(pBuf + uintptr(len1+int32(1)))) = 0
			*(*int8)(unsafe.Pointer(pBuf + uintptr(len1+int32(2)))) = 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 + 36)))
		} else {
			pBuf = (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue
		}
		_sqlite3RCStrRef(tls, pBuf)
		if t&int32(1) != 0 {
			rc = _sqlite3VdbeMemSetStr(tls, pDest, pBuf, int64(int64(len1)), uint8(uint8(encoding)), __ccgo_fp(_sqlite3RCStrUnref))
			p2 = pDest + 16
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(MEM_Term))
		} else {
			rc = _sqlite3VdbeMemSetStr(tls, pDest, pBuf, int64(int64(len1)), uint8(0), __ccgo_fp(_sqlite3RCStrUnref))
		}
	} else {
		rc = _sqlite3VdbeMemFromBtree(tls, *(*uintptr)(unsafe.Pointer(pC + 36)), uint32(uint32(iOffset)), uint32(uint32(len1)), pDest)
		if rc != 0 {
			return rc
		}
		_sqlite3VdbeSerialGet(tls, (*TMem)(unsafe.Pointer(pDest)).Fz, uint32(uint32(t)), pDest)
		if t&int32(1) != 0 && encoding == int32(SQLITE_UTF8) {
			*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1))) = 0
			p3 = pDest + 16
			*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(MEM_Term))
		}
	}
	p4 = pDest + 16
	*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) & ^libc.Int32FromInt32(MEM_Ephem))
	return rc
}

// C documentation
//
//	/*
//	** Return the symbolic name for the data type of a pMem
//	*/
func _vdbeMemTypeName(tls *libc.TLS, pMem uintptr) (r uintptr) {
	return _azTypes[Xsqlite3_value_type(tls, pMem)-int32(1)]
}

var _azTypes = [5]uintptr{
	0: __ccgo_ts + 1142,
	1: __ccgo_ts + 1154,
	2: __ccgo_ts + 1159,
	3: __ccgo_ts + 1137,
	4: __ccgo_ts + 1673,
}

// 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(768)
	defer tls.Free(768)
	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, pC4, pC5, pC6, pC7, pC8, pC9, pCaller, pColl, pCrsr, pCrsr1, pCrsr2, pCrsr3, pCrsr4, pCrsr5, pCrsr6, pCrsr7, 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, zFilename, zHdr, zHdr1, zName, zPayload, zSchema, zSql, zTab, zTrace, v240, v241, v242, v250, v251, v252, v253, v255, v263, v278, v279, v286, v288, v297, v298, p189, p192, p193, p196, p199, p208, p209, p212, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p293, p294, p295, p296 uintptr
	var affinity int8
	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, nByte2, nField, nField1, nField2, nHdr, nKeyCol, nMem, nName, nRoot, nStep, nVarint, oc, opflags, p1, p11, p12, p13, p2, p21, pcDest, pcx, rc, res, res10, res11, res12, res21, savedAnalysisLimit, seekResult, v11, v21, wrFlag, v188, v191, v194, v197, v198, v205, v206, v207, v223, v224, v244, v245, v248, v249, v256, v260, v265, v266, v269, v270, v272, v273, v274, v275, v284, v287, v291 int32
	var colCacheCtr, iAddr, iMap, iPrior, idx, len11, n3, p22, p23, serialType, serial_type, v213, v214, v216, v221, v222 Tu32
	var encoding, isWriteLock, mTrace, op, p5, resetSchemaOnFault, vtabOnConflict, v225 Tu8
	var flags1, flags11, flags2, flags3, flags31, newType, nullFlag, type1, type2, typeMask, v190 Tu16
	var h, h1, iKey1, nData, nProgressLimit, nVmStep, offset64, uu Tu64
	var i3, iA, iB1, iKey, iKey2, nByte, nByte1, nCellKey, nZero, sz, v254, v262 Ti64
	var newMax, v211 uint32
	var rA, rB float64
	var xAuth Tsqlite3_xauth
	var v204, v271, v281 int64
	var v215, v267, v282, v299 bool
	var _ /* aRes at bp+584 */ [3]int32
	var _ /* iA at bp+8 */ Ti64
	var _ /* iB at bp+0 */ Ti64
	var _ /* iMeta at bp+88 */ int32
	var _ /* iMeta at bp+92 */ int32
	var _ /* iMoved at bp+504 */ int32
	var _ /* initData at bp+528 */ TInitData
	var _ /* m at bp+464 */ TMem
	var _ /* nChange at bp+512 */ Ti64
	var _ /* nEntry at bp+80 */ Ti64
	var _ /* nErr at bp+556 */ int32
	var _ /* nullFunc at bp+680 */ TFuncDef
	var _ /* pVCur at bp+640 */ uintptr
	var _ /* pgno at bp+520 */ TPgno
	var _ /* r at bp+104 */ TUnpackedRecord
	var _ /* r at bp+144 */ TUnpackedRecord
	var _ /* r at bp+176 */ TUnpackedRecord
	var _ /* r at bp+392 */ TUnpackedRecord
	var _ /* r at bp+432 */ TUnpackedRecord
	var _ /* res at bp+136 */ int32
	var _ /* res at bp+208 */ int32
	var _ /* res at bp+264 */ int32
	var _ /* res at bp+312 */ int32
	var _ /* res at bp+328 */ int32
	var _ /* res at bp+332 */ int32
	var _ /* res at bp+336 */ int32
	var _ /* res at bp+384 */ int32
	var _ /* res at bp+96 */ int32
	var _ /* rowid at bp+424 */ Ti64
	var _ /* rowid at bp+720 */ Tsqlite_int64
	var _ /* sContext at bp+648 */ Tsqlite3_context
	var _ /* sMem at bp+24 */ TMem
	var _ /* sMem at bp+600 */ TMem
	var _ /* t at bp+64 */ Tu32
	var _ /* uA at bp+16 */ Tu64
	var _ /* v at bp+256 */ Ti64
	var _ /* v at bp+320 */ Ti64
	var _ /* v at bp+72 */ Tu64
	var _ /* val at bp+568 */ Ti64
	var _ /* x at bp+216 */ TMem
	var _ /* x at bp+272 */ TBtreePayload
	var _ /* x at bp+344 */ TBtreePayload
	var _ /* x at bp+576 */ Ti64
	var _ /* z at bp+560 */ uintptr
	var _ /* zErr at bp+524 */ uintptr
	var _ /* zErr at bp+644 */ 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, nArg, nArg1, nByte, nByte1, nByte2, nCellKey, 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, pC4, pC5, pC6, pC7, pC8, pC9, pCaller, pColl, pCrsr, pCrsr1, pCrsr2, pCrsr3, pCrsr4, pCrsr5, pCrsr6, pCrsr7, 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, res10, res11, res12, 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, zFilename, zHdr, zHdr1, zName, zPayload, zSchema, zSql, zTab, zTrace, v188, v190, v191, v194, v197, v198, v204, v205, v206, v207, v211, v213, v214, v215, v216, v221, v222, v223, v224, v225, v240, v241, v242, v244, v245, v248, v249, v250, v251, v252, v253, v254, v255, v256, v260, v262, v263, v265, v266, v267, v269, v270, v271, v272, v273, v274, v275, v278, v279, v281, v282, v284, v286, v287, v288, v291, v297, v298, v299, p189, p192, p193, p196, p199, p208, p209, p212, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p293, p294, p295, p296
	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)(unsafe.Pointer(p + 164 + 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+312, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
		goto abort_due_to_interrupt
	}
	pOp = aOp + uintptr((*TVdbe)(unsafe.Pointer(p)).Fpc)*20
	for {
		if !(int32(1) != 0) {
			break
		}
		/* Errors are detected by individual opcodes, with an immediate
		 ** jumps to abort_due_to_error. */
		nVmStep++
		/* 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 int32((*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_Prev):
			goto _115
		case int32(OP_Next):
			goto _116
		case int32(OP_SorterNext):
			goto _117
		case int32(OP_IdxInsert):
			goto _118
		case int32(OP_SorterInsert):
			goto _119
		case int32(OP_IdxDelete):
			goto _120
		case int32(OP_IdxRowid):
			goto _121
		case int32(OP_DeferredSeek):
			goto _122
		case int32(OP_FinishSeek):
			goto _123
		case int32(OP_IdxGE):
			goto _124
		case int32(OP_IdxLT):
			goto _125
		case int32(OP_IdxGT):
			goto _126
		case int32(OP_IdxLE):
			goto _127
		case int32(OP_Destroy):
			goto _128
		case int32(OP_Clear):
			goto _129
		case int32(OP_ResetSorter):
			goto _130
		case int32(OP_CreateBtree):
			goto _131
		case int32(OP_SqlExec):
			goto _132
		case int32(OP_ParseSchema):
			goto _133
		case int32(OP_LoadAnalysis):
			goto _134
		case int32(OP_DropTable):
			goto _135
		case int32(OP_DropIndex):
			goto _136
		case int32(OP_DropTrigger):
			goto _137
		case int32(OP_IntegrityCk):
			goto _138
		case int32(OP_RowSetAdd):
			goto _139
		case int32(OP_RowSetRead):
			goto _140
		case int32(OP_RowSetTest):
			goto _141
		case int32(OP_Program):
			goto _142
		case int32(OP_Param):
			goto _143
		case int32(OP_FkCounter):
			goto _144
		case int32(OP_FkIfZero):
			goto _145
		case int32(OP_MemMax):
			goto _146
		case int32(OP_IfPos):
			goto _147
		case int32(OP_OffsetLimit):
			goto _148
		case int32(OP_IfNotZero):
			goto _149
		case int32(OP_DecrJumpZero):
			goto _150
		case int32(OP_AggStep):
			goto _151
		case int32(OP_AggInverse):
			goto _152
		case int32(OP_AggStep1):
			goto _153
		case int32(OP_AggFinal):
			goto _154
		case int32(OP_AggValue):
			goto _155
		case int32(OP_Checkpoint):
			goto _156
		case int32(OP_JournalMode):
			goto _157
		case int32(OP_Vacuum):
			goto _158
		case int32(OP_IncrVacuum):
			goto _159
		case int32(OP_Expire):
			goto _160
		case int32(OP_CursorLock):
			goto _161
		case int32(OP_CursorUnlock):
			goto _162
		case int32(OP_TableLock):
			goto _163
		case int32(OP_VBegin):
			goto _164
		case int32(OP_VCreate):
			goto _165
		case int32(OP_VDestroy):
			goto _166
		case int32(OP_VOpen):
			goto _167
		case int32(OP_VCheck):
			goto _168
		case int32(OP_VInitIn):
			goto _169
		case int32(OP_VFilter):
			goto _170
		case int32(OP_VColumn):
			goto _171
		case int32(OP_VNext):
			goto _172
		case int32(OP_VRename):
			goto _173
		case int32(OP_VUpdate):
			goto _174
		case int32(OP_Pagecount):
			goto _175
		case int32(OP_MaxPgcnt):
			goto _176
		case int32(OP_Function):
			goto _177
		case int32(OP_PureFunc):
			goto _178
		case int32(OP_ClrSubtype):
			goto _179
		case int32(OP_GetSubtype):
			goto _180
		case int32(OP_SetSubtype):
			goto _181
		case int32(OP_FilterAdd):
			goto _182
		case int32(OP_Filter):
			goto _183
		case int32(OP_Init):
			goto _184
		case int32(OP_Trace):
			goto _185
		default:
			goto _186
		}
		goto _187
		/*****************************************************************************
		 ** 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))*20
		/* 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+312, 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 += 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 _187
		/* 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)*40
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = uint16(MEM_Int)
		*(*Ti64)(unsafe.Pointer(pIn1)) = int64((int32(int32(pOp)) - int32(int32(aOp))) / 20)
		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)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) != 0 {
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			}
			pOp = aOp + uintptr(*(*Ti64)(unsafe.Pointer(pIn1)))*20
		} else {
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			}
		}
		goto _187
		/* 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)*40
		*(*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 _187
		}
		/* 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))*20
		goto _187
		/* 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)*40
		pCaller = aOp + uintptr(*(*Ti64)(unsafe.Pointer(pIn1)))*20
		*(*Ti64)(unsafe.Pointer(pIn1)) = int64((int32(int32(pOp))-int32((*TVdbe)(unsafe.Pointer(p)).FaOp))/20 - int32(1))
		pOp = aOp + uintptr((*TVdbeOp)(unsafe.Pointer(pCaller)).Fp2-int32(1))*20
		goto _187
		/* 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)*40
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = uint16(MEM_Int)
		pcDest = int32(*(*Ti64)(unsafe.Pointer(pIn1)))
		*(*Ti64)(unsafe.Pointer(pIn1)) = int64((int32(int32(pOp)) - int32(int32(aOp))) / 20)
		pOp = aOp + uintptr(pcDest)*20
		goto _187
		/* 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)*40
		if int32((*TMem)(unsafe.Pointer(pIn3)).Fflags)&int32(MEM_Null) == 0 {
			goto _187
		}
		/* Opcode:  Halt P1 P2 * 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 P4 is not null then it is an error message string.
		 **
		 ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
		 **
		 **    0:  (no change)
		 **    1:  NOT NULL constraint failed: P4
		 **    2:  UNIQUE constraint failed: P4
		 **    3:  CHECK constraint failed: P4
		 **    4:  FOREIGN KEY constraint failed: P4
		 **
		 ** If 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--
			_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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(pcx)*20))).Fp2 - int32(1)
			}
			aOp = (*TVdbe)(unsafe.Pointer(p)).FaOp
			aMem = (*TVdbe)(unsafe.Pointer(p)).FaMem
			pOp = aOp + uintptr(pcx)*20
			goto _187
		}
		(*TVdbe)(unsafe.Pointer(p)).Frc = (*TOp)(unsafe.Pointer(pOp)).Fp1
		(*TVdbe)(unsafe.Pointer(p)).FerrorAction = uint8((*TOp)(unsafe.Pointer(pOp)).Fp2)
		if (*TVdbe)(unsafe.Pointer(p)).Frc != 0 {
			if (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 {
				_sqlite3VdbeError(tls, p, __ccgo_ts+6987, libc.VaList(bp+736, _azType[int32((*TOp)(unsafe.Pointer(pOp)).Fp5)-int32(1)]))
				if *(*uintptr)(unsafe.Pointer(pOp + 16)) != 0 {
					(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = _sqlite3MPrintf(tls, db, __ccgo_ts+7008, libc.VaList(bp+736, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg, *(*uintptr)(unsafe.Pointer(pOp + 16))))
				}
			} else {
				_sqlite3VdbeError(tls, p, __ccgo_ts+4709, libc.VaList(bp+736, *(*uintptr)(unsafe.Pointer(pOp + 16))))
			}
			pcx = (int32(int32(pOp)) - int32(int32(aOp))) / 20
			Xsqlite3_log(tls, (*TOp)(unsafe.Pointer(pOp)).Fp1, __ccgo_ts+7015, libc.VaList(bp+736, pcx, (*TVdbe)(unsafe.Pointer(p)).FzSql, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg))
		}
		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 {
				v188 = int32(SQLITE_ERROR)
			} else {
				v188 = int32(SQLITE_DONE)
			}
			rc = v188
		}
		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 _187
		/* 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)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))
		goto _187
		/* 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)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))
		goto _187
		/* 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 int32(int32(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, int32(int32(encoding))) {
				goto no_mem
			}
			(*TMem)(unsafe.Pointer(pOut)).FszMalloc = 0
			p189 = pOut + 16
			*(*Tu16)(unsafe.Pointer(p189)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p189))) | libc.Int32FromInt32(MEM_Static))
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(6) {
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)))
			}
			(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(6))
			*(*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)(unsafe.Pointer(db + 120)) {
			goto too_big
		}
		(*TOp)(unsafe.Pointer(pOp)).Fopcode = uint8(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 = uint16(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 _187
		/* 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 {
			v191 = libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Cleared)
		} else {
			v191 = int32(MEM_Null)
		}
		v190 = uint16(v191)
		nullFlag = v190
		(*TMem)(unsafe.Pointer(pOut)).Fflags = v190
		(*TMem)(unsafe.Pointer(pOut)).Fn = 0
		for cnt > 0 {
			pOut += 40
			_sqlite3VdbeMemSetNull(tls, pOut)
			(*TMem)(unsafe.Pointer(pOut)).Fflags = nullFlag
			(*TMem)(unsafe.Pointer(pOut)).Fn = 0
			cnt--
		}
		goto _187
		/* 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)*40
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_Undefined)|libc.Int32FromInt32(MEM_AffMask)) | int32(MEM_Null))
		goto _187
		/* 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 _187
		/* 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))*40
		if _sqlite3VdbeMemTooBig(tls, pVar) != 0 {
			goto too_big
		}
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		if int32((*TMem)(unsafe.Pointer(pOut)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
			_sqlite3VdbeMemSetNull(tls, pOut)
		}
		libc.Xmemcpy(tls, pOut, pVar, uint32(libc.UintptrFromInt32(0)+20))
		p192 = pOut + 16
		*(*Tu16)(unsafe.Pointer(p192)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p192))) & ^(libc.Int32FromInt32(MEM_Dyn) | libc.Int32FromInt32(MEM_Ephem)))
		p193 = pOut + 16
		*(*Tu16)(unsafe.Pointer(p193)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p193))) | (libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_FromBind)))
		goto _187
		/* 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)*40
		pOut = aMem + uintptr(p2)*40
		for {
			_sqlite3VdbeMemMove(tls, pOut, pIn1)
			if int32((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				goto no_mem
			}
			pIn1 += 40
			pOut += 40
			goto _195
		_195:
			;
			n--
			v194 = n
			if !(v194 != 0) {
				break
			}
		}
		goto _187
		/* 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)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		for int32(1) != 0 {
			_sqlite3VdbeMemShallowCopy(tls, pOut, pIn1, int32(MEM_Ephem))
			if int32((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				goto no_mem
			}
			if int32((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Subtype) != 0 && int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(0x0002) != 0 {
				p196 = pOut + 16
				*(*Tu16)(unsafe.Pointer(p196)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p196))) & ^libc.Int32FromInt32(MEM_Subtype))
			}
			v197 = n1
			n1--
			if v197 == 0 {
				break
			}
			pOut += 40
			pIn1 += 40
		}
		goto _187
		/* 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)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		_sqlite3VdbeMemShallowCopy(tls, pOut, pIn1, int32(MEM_Ephem))
		goto _187
		/* 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)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		_sqlite3VdbeMemSetInt64(tls, pOut, *(*Ti64)(unsafe.Pointer(pIn1)))
		goto _187
		/* 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:
		;
		v198 = _sqlite3VdbeCheckFk(tls, p, 0)
		rc = v198
		if v198 != SQLITE_OK {
			goto abort_due_to_error
		}
		goto _187
		/* 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)*40
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto no_mem
		}
		if int32((*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(int32(pOp))-int32(int32(aOp)))/20 + 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)*40
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		flags1 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
		if (int32(int32(flags1))|int32((*TMem)(unsafe.Pointer(pIn2)).Fflags))&int32(MEM_Null) != 0 {
			_sqlite3VdbeMemSetNull(tls, pOut)
			goto _187
		}
		if int32(int32(flags1))&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) == 0 {
			if _sqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(0)) != 0 {
				goto no_mem
			}
			flags1 = uint16(int32((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
		} else {
			if int32(int32(flags1))&int32(MEM_Zero) != 0 {
				if _sqlite3VdbeMemExpandBlob(tls, pIn1) != 0 {
					goto no_mem
				}
				flags1 = uint16(int32((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
			}
		}
		flags2 = (*TMem)(unsafe.Pointer(pIn2)).Fflags
		if int32(int32(flags2))&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) == 0 {
			if _sqlite3VdbeMemStringify(tls, pIn2, encoding, uint8(0)) != 0 {
				goto no_mem
			}
			flags2 = uint16(int32((*TMem)(unsafe.Pointer(pIn2)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
		} else {
			if int32(int32(flags2))&int32(MEM_Zero) != 0 {
				if _sqlite3VdbeMemExpandBlob(tls, pIn2) != 0 {
					goto no_mem
				}
				flags2 = uint16(int32((*TMem)(unsafe.Pointer(pIn2)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
			}
		}
		nByte = int64((*TMem)(unsafe.Pointer(pIn1)).Fn + (*TMem)(unsafe.Pointer(pIn2)).Fn)
		if nByte > int64(*(*int32)(unsafe.Pointer(db + 120))) {
			goto too_big
		}
		if _sqlite3VdbeMemGrow(tls, pOut, int32(int32(nByte))+int32(2), libc.BoolInt32(pOut == pIn2)) != 0 {
			goto no_mem
		}
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*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, uint32((*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, uint32((*TMem)(unsafe.Pointer(pIn1)).Fn))
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = flags1
		if int32(int32(encoding)) > int32(SQLITE_UTF8) {
			nByte &= int64(^libc.Int32FromInt32(1))
		}
		*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte))) = 0
		*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte+int64(1)))) = 0
		p199 = pOut + 16
		*(*Tu16)(unsafe.Pointer(p199)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p199))) | libc.Int32FromInt32(MEM_Term))
		(*TMem)(unsafe.Pointer(pOut)).Fn = int32(int32(nByte))
		(*TMem)(unsafe.Pointer(pOut)).Fenc = encoding
		goto _187
		/* 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)*40
		type1 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		type2 = (*TMem)(unsafe.Pointer(pIn2)).Fflags
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		if !(int32(int32(type1))&int32(int32(type2))&int32(MEM_Int) != 0) {
			goto _200
		}
		goto int_math
	int_math:
		;
		iA = *(*Ti64)(unsafe.Pointer(pIn1))
		*(*Ti64)(unsafe.Pointer(bp)) = *(*Ti64)(unsafe.Pointer(pIn2))
		switch int32((*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)(unsafe.Pointer(bp)) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
				goto fp_math
			}
			*(*Ti64)(unsafe.Pointer(bp)) /= iA
		default:
			if iA == 0 {
				goto arithmetic_result_is_null
			}
			if iA == int64(-int32(1)) {
				iA = int64(1)
			}
			*(*Ti64)(unsafe.Pointer(bp)) %= iA
			break
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = *(*Ti64)(unsafe.Pointer(bp))
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		goto _201
	_200:
		;
		if !((int32(int32(type1))|int32(int32(type2)))&int32(MEM_Null) != 0) {
			goto _202
		}
		goto arithmetic_result_is_null
		goto _203
	_202:
		;
		type1 = _numericType(tls, pIn1)
		type2 = _numericType(tls, pIn2)
		if int32(int32(type1))&int32(int32(type2))&int32(MEM_Int) != 0 {
			goto int_math
		}
		goto fp_math
	fp_math:
		;
		rA = _sqlite3VdbeRealValue(tls, pIn1)
		rB = _sqlite3VdbeRealValue(tls, pIn2)
		switch int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
		case int32(OP_Add):
			rB += rA
		case int32(OP_Subtract):
			rB -= rA
		case int32(OP_Multiply):
			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 /= rA
		default:
			iA = _sqlite3VdbeIntValue(tls, pIn1)
			*(*Ti64)(unsafe.Pointer(bp)) = _sqlite3VdbeIntValue(tls, pIn2)
			if iA == 0 {
				goto arithmetic_result_is_null
			}
			if iA == int64(-int32(1)) {
				iA = int64(1)
			}
			rB = float64(*(*Ti64)(unsafe.Pointer(bp)) % iA)
			break
		}
		if _sqlite3IsNaN(tls, rB) != 0 {
			goto arithmetic_result_is_null
		}
		*(*float64)(unsafe.Pointer(pOut)) = rB
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Real))
	_203:
		;
	_201:
		;
		goto _187
		goto arithmetic_result_is_null
	arithmetic_result_is_null:
		;
		_sqlite3VdbeMemSetNull(tls, pOut)
		goto _187
		/* 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)*40, 0)
		}
		goto _187
		/* 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)*40
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		if (int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)|int32((*TMem)(unsafe.Pointer(pIn2)).Fflags))&int32(MEM_Null) != 0 {
			_sqlite3VdbeMemSetNull(tls, pOut)
			goto _187
		}
		*(*Ti64)(unsafe.Pointer(bp + 8)) = _sqlite3VdbeIntValue(tls, pIn2)
		iB1 = _sqlite3VdbeIntValue(tls, pIn1)
		op = (*TOp)(unsafe.Pointer(pOp)).Fopcode
		if int32(int32(op)) == int32(OP_BitAnd) {
			*(*Ti64)(unsafe.Pointer(bp + 8)) &= iB1
		} else {
			if int32(int32(op)) == int32(OP_BitOr) {
				*(*Ti64)(unsafe.Pointer(bp + 8)) |= iB1
			} else {
				if iB1 != 0 {
					/* If shifting by a negative amount, shift in the other direction */
					if iB1 < 0 {
						op = uint8(libc.Int32FromInt32(2)*libc.Int32FromInt32(OP_ShiftLeft) + libc.Int32FromInt32(1) - int32(int32(op)))
						if iB1 > int64(-libc.Int32FromInt32(64)) {
							v204 = -iB1
						} else {
							v204 = int64(64)
						}
						iB1 = v204
					}
					if iB1 >= int64(64) {
						if *(*Ti64)(unsafe.Pointer(bp + 8)) >= 0 || int32(int32(op)) == int32(OP_ShiftLeft) {
							v205 = 0
						} else {
							v205 = -int32(1)
						}
						*(*Ti64)(unsafe.Pointer(bp + 8)) = int64(v205)
					} else {
						libc.Xmemcpy(tls, bp+16, bp+8, uint32(8))
						if int32(int32(op)) == int32(OP_ShiftLeft) {
							*(*Tu64)(unsafe.Pointer(bp + 16)) <<= uint64(uint64(iB1))
						} else {
							*(*Tu64)(unsafe.Pointer(bp + 16)) >>= uint64(uint64(iB1))
							/* Sign-extend on a right shift of a negative number */
							if *(*Ti64)(unsafe.Pointer(bp + 8)) < 0 {
								*(*Tu64)(unsafe.Pointer(bp + 16)) |= (libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32) | libc.Uint64FromUint32(0xffffffff)) << (int64(64) - iB1)
							}
						}
						libc.Xmemcpy(tls, bp+8, bp+16, uint32(8))
					}
				}
			}
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = *(*Ti64)(unsafe.Pointer(bp + 8))
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		goto _187
		/* 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)*40
		_sqlite3VdbeMemIntegerify(tls, pIn1)
		*(*Tu64)(unsafe.Pointer(pIn1)) += uint64((*TOp)(unsafe.Pointer(pOp)).Fp2)
		goto _187
		/* 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)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
			_applyAffinity(tls, pIn1, int8(SQLITE_AFF_NUMERIC), encoding)
			if int32((*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 = uint16(int32((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		goto _187
		/* 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)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
			_sqlite3VdbeMemRealify(tls, pIn1)
		}
		goto _187
		/* 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)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Zero) != 0 {
			v206 = _sqlite3VdbeMemExpandBlob(tls, pIn1)
		} else {
			v206 = 0
		}
		rc = v206
		if rc != 0 {
			goto abort_due_to_error
		}
		rc = _sqlite3VdbeMemCast(tls, pIn1, uint8((*TOp)(unsafe.Pointer(pOp)).Fp2), encoding)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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)*40
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		flags11 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
		flags3 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
		if int32(int32(flags11))&int32(int32(flags3))&int32(MEM_Int) != 0 {
			/* Common case of comparison of two integers */
			if *(*Ti64)(unsafe.Pointer(pIn3)) > *(*Ti64)(unsafe.Pointer(pIn1)) {
				if *(*uint8)(unsafe.Pointer(_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)(unsafe.Pointer(_sqlite3aLTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
						goto jump_to_p2
					}
					iCompare = -int32(1)
				} else {
					if *(*uint8)(unsafe.Pointer(_sqlite3aEQb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
						goto jump_to_p2
					}
					iCompare = 0
				}
			}
			goto _187
		}
		if (int32(int32(flags11))|int32(int32(flags3)))&int32(MEM_Null) != 0 {
			/* One or both operands are NULL */
			if int32((*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 int32(int32(flags11))&int32(int32(flags3))&int32(MEM_Null) != 0 && int32(int32(flags3))&int32(MEM_Cleared) == 0 {
					res = 0 /* Operands are equal */
				} else {
					if int32(int32(flags3))&int32(MEM_Null) != 0 {
						v207 = -int32(1)
					} else {
						v207 = +libc.Int32FromInt32(1)
					}
					res = v207 /* 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 int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(SQLITE_JUMPIFNULL) != 0 {
					goto jump_to_p2
				}
				iCompare = int32(1) /* Operands are not equal */
				goto _187
			}
		} else {
			/* Neither operand is NULL and we couldn't do the special high-speed
			 ** integer comparison case.  So do a general-case comparison. */
			affinity = int8(int32((*TOp)(unsafe.Pointer(pOp)).Fp5) & int32(SQLITE_AFF_MASK))
			if int32(int32(affinity)) >= int32(SQLITE_AFF_NUMERIC) {
				if (int32(int32(flags11))|int32(int32(flags3)))&int32(MEM_Str) != 0 {
					if int32(int32(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 int32(int32(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 int32(int32(affinity)) == int32(SQLITE_AFF_TEXT) && (int32(int32(flags11))|int32(int32(flags3)))&int32(MEM_Str) != 0 {
					if int32(int32(flags11))&int32(MEM_Str) != 0 {
						p208 = pIn1 + 16
						*(*Tu16)(unsafe.Pointer(p208)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p208))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
					} else {
						if int32(int32(flags11))&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
							_sqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(1))
							flags11 = uint16(int32((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_TypeMask) | int32(int32(flags11))&int32(MEM_TypeMask))
							if pIn1 == pIn3 {
								flags3 = uint16(int32(int32(flags11)) | int32(MEM_Str))
							}
						}
					}
					if int32(int32(flags3))&int32(MEM_Str) != 0 {
						p209 = pIn3 + 16
						*(*Tu16)(unsafe.Pointer(p209)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p209))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
					} else {
						if int32(int32(flags3))&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
							_sqlite3VdbeMemStringify(tls, pIn3, encoding, uint8(1))
							flags3 = uint16(int32((*TMem)(unsafe.Pointer(pIn3)).Fflags) & ^libc.Int32FromInt32(MEM_TypeMask) | int32(int32(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 = int32(*(*uint8)(unsafe.Pointer(_sqlite3aLTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
		} else {
			if res == 0 {
				res21 = int32(*(*uint8)(unsafe.Pointer(_sqlite3aEQb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
			} else {
				res21 = int32(*(*uint8)(unsafe.Pointer(_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 _187
		/* 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 _187
		/* 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 _187
		/* 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 int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_PERMUTE) == 0 {
			aPermute = uintptr(0)
		} else {
			aPermute = *(*uintptr)(unsafe.Pointer(pOp + uintptr(-libc.Int32FromInt32(1))*20 + 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 {
				v211 = *(*Tu32)(unsafe.Pointer(aPermute + uintptr(i)*4))
			} else {
				v211 = uint32(uint32(i))
			}
			idx = v211
			pColl = *(*uintptr)(unsafe.Pointer(pKeyInfo + 20 + uintptr(i)*4))
			bRev = int32(*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i)))) & int32(KEYINFO_ORDER_DESC)
			iCompare = _sqlite3MemCompare(tls, aMem+uintptr(uint32(uint32(p11))+idx)*40, aMem+uintptr(uint32(uint32(p21))+idx)*40, pColl)
			if iCompare != 0 {
				if int32(*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i))))&int32(KEYINFO_ORDER_BIGNULL) != 0 && (int32((*(*TMem)(unsafe.Pointer(aMem + uintptr(uint32(uint32(p11))+idx)*40))).Fflags)&int32(MEM_Null) != 0 || int32((*(*TMem)(unsafe.Pointer(aMem + uintptr(uint32(uint32(p21))+idx)*40))).Fflags)&int32(MEM_Null) != 0) {
					iCompare = -iCompare
				}
				if bRev != 0 {
					iCompare = -iCompare
				}
				break
			}
			goto _210
		_210:
			;
			i++
		}
		goto _187
		/* 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))*20
		} else {
			if iCompare == 0 {
				pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2-int32(1))*20
			} else {
				pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3-int32(1))*20
			}
		}
		goto _187
		/* 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)*40, int32(2))
		v21 = _sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40, int32(2))
		if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_And) {
			v11 = int32(_and_logic[v11*int32(3)+v21])
		} else {
			v11 = int32(_or_logic[v11*int32(3)+v21])
		}
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		if v11 == int32(2) {
			(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Null))
		} else {
			*(*Ti64)(unsafe.Pointer(pOut)) = int64(int64(v11))
			(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		}
		goto _187
		/* 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)*40, int64(_sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40, (*TOp)(unsafe.Pointer(pOp)).Fp3)^*(*int32)(unsafe.Pointer(pOp + 16))))
		goto _187
		/* 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)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
			_sqlite3VdbeMemSetInt64(tls, pOut, libc.BoolInt64(!(_sqlite3VdbeBooleanValue(tls, pIn1, 0) != 0)))
		} else {
			_sqlite3VdbeMemSetNull(tls, pOut)
		}
		goto _187
		/* 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)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		_sqlite3VdbeMemSetNull(tls, pOut)
		if int32((*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 _187
		/* Opcode: Once P1 P2 * * *
		 **
		 ** 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.
		 */
	_56:
		; /* Address of this instruction */
		if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
			iAddr = uint32((int32(int32(pOp)) - int32((*TVdbe)(unsafe.Pointer(p)).FaOp)) / 20)
			if int32(*(*Tu8)(unsafe.Pointer((*TVdbeFrame)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/uint32(8)))))&(int32(1)<<(iAddr&uint32(7))) != 0 {
				goto jump_to_p2
			}
			p212 = (*TVdbeFrame)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/uint32(8))
			*(*Tu8)(unsafe.Pointer(p212)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p212))) | libc.Int32FromInt32(1)<<(iAddr&libc.Uint32FromInt32(7)))
		} else {
			if (*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp))).Fp1 == (*TOp)(unsafe.Pointer(pOp)).Fp1 {
				goto jump_to_p2
			}
		}
		(*TOp)(unsafe.Pointer(pOp)).Fp1 = (*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp))).Fp1
		goto _187
		/* 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)*40, (*TOp)(unsafe.Pointer(pOp)).Fp3)
		if c != 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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)*40, libc.BoolInt32(!((*TOp)(unsafe.Pointer(pOp)).Fp3 != 0))) != 0))
		if c1 != 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) != 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 < int32((*TVdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed) {
				serialType = *(*Tu32)(unsafe.Pointer(pC + 84 + 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 = uint16(int32(1) << (*(*int32)(unsafe.Pointer(pOp + 16)) - int32(1)))
			}
		} else {
			typeMask = uint16(int32(1) << (Xsqlite3_value_type(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40) - int32(1)))
		}
		if int32(int32(typeMask))&int32((*TOp)(unsafe.Pointer(pOp)).Fp5) != 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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 int32((*(*TMem)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40))).Fflags)&int32(MEM_Null) != 0 || int32((*(*TMem)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))).Fflags)&int32(MEM_Null) != 0 {
			_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40)
		} else {
			_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40, 0)
		}
		goto _187
		/* 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)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if pC1 != 0 && (*TVdbeCursor)(unsafe.Pointer(pC1)).FnullRow != 0 {
			_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40)
			goto jump_to_p2
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pOut = (*TVdbe)(unsafe.Pointer(p)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		if pC2 == uintptr(0) || int32((*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 + 36))) != 0 {
				_sqlite3VdbeMemSetNull(tls, pOut)
			} else {
				_sqlite3VdbeMemSetInt64(tls, pOut, _sqlite3BtreeOffset(tls, *(*uintptr)(unsafe.Pointer(pC2 + 36))))
			}
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		p22 = uint32((*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 int32((*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)*40
					v213 = uint32((*TMem)(unsafe.Pointer(pReg)).Fn)
					(*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow = v213
					(*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize = v213
					(*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow = (*TMem)(unsafe.Pointer(pReg)).Fz
				} else {
					pDest = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
					_sqlite3VdbeMemSetNull(tls, pDest)
					goto op_column_out
				}
			} else {
				pCrsr = *(*uintptr)(unsafe.Pointer(pC3 + 36))
				if (*TVdbeCursor)(unsafe.Pointer(pC3)).FdeferredMoveto != 0 {
					if v215 = *(*uintptr)(unsafe.Pointer(pC3 + 12)) != 0; v215 {
						v214 = *(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pC3 + 12)) + uintptr(uint32(1)+p22)*4))
						iMap = v214
					}
					if v215 && v214 > 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+76)
				/* Maximum page size is 64KiB */
			}
			(*TVdbeCursor)(unsafe.Pointer(pC3)).FcacheStatus = (*TVdbe)(unsafe.Pointer(p)).FcacheCtr
			v216 = uint32(*(*Tu8)(unsafe.Pointer((*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow)))
			*(*Tu32)(unsafe.Pointer(aOffset)) = v216
			if v216 < 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)(unsafe.Pointer(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)(unsafe.Pointer(aOffset)) > uint32(98307) || *(*Tu32)(unsafe.Pointer(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 + 36))) != 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 _217
		}
		/* 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)(unsafe.Pointer(aOffset))) {
			goto _219
		}
		/* 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, uint32(40))
			rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, *(*uintptr)(unsafe.Pointer(pC3 + 36)), *(*Tu32)(unsafe.Pointer(aOffset)), bp+24)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			zData = (*(*TMem)(unsafe.Pointer(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 = int32((*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed)
		offset64 = uint64(*(*Tu32)(unsafe.Pointer(aOffset + uintptr(i1)*4)))
		zHdr = zData + uintptr((*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset)
		zEndHdr = zData + uintptr(*(*Tu32)(unsafe.Pointer(aOffset)))
		for cond := true; cond; cond = uint32(uint32(i1)) <= p22 && zHdr < zEndHdr {
			v222 = uint32(*(*Tu8)(unsafe.Pointer(zHdr)))
			*(*Tu32)(unsafe.Pointer(bp + 64)) = v222
			v221 = v222
			*(*Tu32)(unsafe.Pointer(pC3 + 84 + uintptr(i1)*4)) = v221
			if v221 < uint32(0x80) {
				zHdr++
				offset64 += uint64(_sqlite3VdbeOneByteSerialTypeLen(tls, uint8(*(*Tu32)(unsafe.Pointer(bp + 64)))))
			} else {
				zHdr += uintptr(_sqlite3GetVarint32(tls, zHdr, bp+64))
				*(*Tu32)(unsafe.Pointer(pC3 + 84 + uintptr(i1)*4)) = *(*Tu32)(unsafe.Pointer(bp + 64))
				offset64 += uint64(_sqlite3VdbeSerialTypeLen(tls, *(*Tu32)(unsafe.Pointer(bp + 64))))
			}
			i1++
			v223 = i1
			*(*Tu32)(unsafe.Pointer(aOffset + uintptr(v223)*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)(unsafe.Pointer(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 = uint16(uint16(i1))
		(*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = uint32(int32(int32(zHdr)) - int32(int32(zData)))
		if (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0) {
			_sqlite3VdbeMemRelease(tls, bp+24)
		}
		goto _220
	_219:
		;
		*(*Tu32)(unsafe.Pointer(bp + 64)) = uint32(0)
	_220:
		;
		/* 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)*40
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(10) {
				_sqlite3VdbeMemShallowCopy(tls, pDest, *(*uintptr)(unsafe.Pointer(pOp + 16)), int32(MEM_Static))
			} else {
				_sqlite3VdbeMemSetNull(tls, pDest)
			}
			goto op_column_out
		}
		goto _218
	_217:
		;
		*(*Tu32)(unsafe.Pointer(bp + 64)) = *(*Tu32)(unsafe.Pointer(pC3 + 84 + uintptr(p22)*4))
	_218:
		;
		/* 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)*40
		if int32((*TMem)(unsafe.Pointer(pDest)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
			_sqlite3VdbeMemSetNull(tls, pDest)
		}
		if (*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow >= *(*Tu32)(unsafe.Pointer(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)(unsafe.Pointer(aOffset + uintptr(p22)*4)))
			if *(*Tu32)(unsafe.Pointer(bp + 64)) < uint32(12) {
				_sqlite3VdbeSerialGet(tls, zData, *(*Tu32)(unsafe.Pointer(bp + 64)), pDest)
			} else {
				v224 = int32((*(*Tu32)(unsafe.Pointer(bp + 64)) - libc.Uint32FromInt32(12)) / libc.Uint32FromInt32(2))
				len1 = v224
				(*TMem)(unsafe.Pointer(pDest)).Fn = v224
				(*TMem)(unsafe.Pointer(pDest)).Fenc = encoding
				if (*TMem)(unsafe.Pointer(pDest)).FszMalloc < len1+int32(2) {
					if len1 > *(*int32)(unsafe.Pointer(db + 120)) {
						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, uint32(uint32(len1)))
				*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1))) = 0
				*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1+int32(1)))) = 0
				(*TMem)(unsafe.Pointer(pDest)).Fflags = _aFlag1[*(*Tu32)(unsafe.Pointer(bp + 64))&uint32(1)]
			}
		} else {
			(*TMem)(unsafe.Pointer(pDest)).Fenc = encoding
			/* This branch happens only when content is on overflow pages */
			v225 = uint8(int32((*TOp)(unsafe.Pointer(pOp)).Fp5) & libc.Int32FromInt32(OPFLAG_BYTELENARG))
			p5 = v225
			if int32(v225) != 0 && (int32(int32(p5)) == int32(OPFLAG_TYPEOFARG) || *(*Tu32)(unsafe.Pointer(bp + 64)) >= uint32(12) && (*(*Tu32)(unsafe.Pointer(bp + 64))&uint32(1) == uint32(0) || int32(int32(p5)) == int32(OPFLAG_BYTELENARG))) || _sqlite3VdbeSerialTypeLen(tls, *(*Tu32)(unsafe.Pointer(bp + 64))) == 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)(unsafe.Pointer(bp + 64)), pDest)
			} else {
				rc = _vdbeColumnFromOverflow(tls, pC3, int32(int32(p22)), int32(*(*Tu32)(unsafe.Pointer(bp + 64))), int64(*(*Tu32)(unsafe.Pointer(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 _187
		goto op_column_corrupt
	op_column_corrupt:
		;
		if (*(*TOp)(unsafe.Pointer(aOp))).Fp3 > 0 {
			pOp = aOp + uintptr((*(*TOp)(unsafe.Pointer(aOp))).Fp3-int32(1))*20
			goto _187
		} else {
			rc = _sqlite3CorruptError(tls, int32(96311))
			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.
		 **
		 ** 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.
		 ** <li> Table P4 should be 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)*40
		i2 = 0
		for {
			if !(i2 < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if int32((*(*TColumn)(unsafe.Pointer(aCol + uintptr(i2)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
				if int32((*(*TColumn)(unsafe.Pointer(aCol + uintptr(i2)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					goto _226
				}
				if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
					pIn1 += 40
					goto _226
				}
			}
			_applyAffinity(tls, pIn1, (*(*TColumn)(unsafe.Pointer(aCol + uintptr(i2)*12))).Faffinity, encoding)
			if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
				switch int32(uint32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*12 + 4)) & 0xf0 >> 4)) {
				case int32(COLTYPE_BLOB):
					if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 {
						goto vdbe_type_error
					}
				case int32(COLTYPE_INTEGER):
					fallthrough
				case int32(COLTYPE_INT):
					if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
						goto vdbe_type_error
					}
				case int32(COLTYPE_TEXT):
					if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Str) == 0 {
						goto vdbe_type_error
					}
				case int32(COLTYPE_REAL):
					if int32((*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) {
							p227 = pIn1 + 16
							*(*Tu16)(unsafe.Pointer(p227)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p227))) | libc.Int32FromInt32(MEM_IntReal))
							p228 = pIn1 + 16
							*(*Tu16)(unsafe.Pointer(p228)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p228))) & ^libc.Int32FromInt32(MEM_Int))
						} else {
							*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*Ti64)(unsafe.Pointer(pIn1)))
							p229 = pIn1 + 16
							*(*Tu16)(unsafe.Pointer(p229)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p229))) | libc.Int32FromInt32(MEM_Real))
							p230 = pIn1 + 16
							*(*Tu16)(unsafe.Pointer(p230)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p230))) & ^libc.Int32FromInt32(MEM_Int))
						}
					} else {
						if int32((*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 += 40
			goto _226
		_226:
			;
			i2++
		}
		goto _187
		goto vdbe_type_error
	vdbe_type_error:
		;
		_sqlite3VdbeError(tls, p, __ccgo_ts+7039, libc.VaList(bp+736, _vdbeMemTypeName(tls, pIn1), _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*12 + 4))&0xf0>>4))-int32(1)], (*TTable)(unsafe.Pointer(pTab)).FzName, (*(*TColumn)(unsafe.Pointer(aCol + uintptr(i2)*12))).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)*40
		for int32(1) != 0 {
			_applyAffinity(tls, pIn1, *(*int8)(unsafe.Pointer(zAffinity)), encoding)
			if int32(*(*int8)(unsafe.Pointer(zAffinity))) == int32(SQLITE_AFF_REAL) && int32((*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) {
					p231 = pIn1 + 16
					*(*Tu16)(unsafe.Pointer(p231)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p231))) | libc.Int32FromInt32(MEM_IntReal))
					p232 = pIn1 + 16
					*(*Tu16)(unsafe.Pointer(p232)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p232))) & ^libc.Int32FromInt32(MEM_Int))
				} else {
					*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*Ti64)(unsafe.Pointer(pIn1)))
					p233 = pIn1 + 16
					*(*Tu16)(unsafe.Pointer(p233)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p233))) | libc.Int32FromInt32(MEM_Real))
					p234 = pIn1 + 16
					*(*Tu16)(unsafe.Pointer(p234)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p234))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Str)))
				}
			}
			zAffinity++
			if int32(*(*int8)(unsafe.Pointer(zAffinity))) == 0 {
				break
			}
			pIn1 += 40
		}
		goto _187
		/* 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)*40
		nField = (*TOp)(unsafe.Pointer(pOp)).Fp2
		pLast = pData0 + uintptr(nField-int32(1))*40
		/* Identify the output register */
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		/* Apply the requested affinity to all inputs
		 */
		if zAffinity1 != 0 {
			pRec = pData0
			for cond := true; cond; cond = *(*int8)(unsafe.Pointer(zAffinity1)) != 0 {
				_applyAffinity(tls, pRec, *(*int8)(unsafe.Pointer(zAffinity1)), encoding)
				if int32(*(*int8)(unsafe.Pointer(zAffinity1))) == int32(SQLITE_AFF_REAL) && int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Int) != 0 {
					p235 = pRec + 16
					*(*Tu16)(unsafe.Pointer(p235)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p235))) | libc.Int32FromInt32(MEM_IntReal))
					p236 = pRec + 16
					*(*Tu16)(unsafe.Pointer(p236)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p236))) & ^libc.Int32FromInt32(MEM_Int))
				}
				zAffinity1++
				pRec += 40
			}
		}
		/* 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 int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Null) != 0 {
				if int32((*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++
			} else {
				if int32((*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 = uint64(^i3)
					} else {
						uu = uint64(uint64(i3))
					}
					nHdr++
					if uu <= uint64(127) {
						if i3&int64(1) == i3 && int32((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) >= int32(4) {
							(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(8) + uint32(uint32(uu))
						} else {
							nData++
							(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(1)
						}
					} else {
						if uu <= uint64(32767) {
							nData += uint64(2)
							(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(2)
						} else {
							if uu <= uint64(8388607) {
								nData += uint64(3)
								(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(3)
							} else {
								if uu <= uint64(2147483647) {
									nData += uint64(4)
									(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(4)
								} else {
									if uu <= uint64(140737488355327) {
										nData += uint64(6)
										(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(5)
									} else {
										nData += uint64(8)
										if int32((*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)))
											p237 = pRec + 16
											*(*Tu16)(unsafe.Pointer(p237)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p237))) & ^libc.Int32FromInt32(MEM_IntReal))
											p238 = pRec + 16
											*(*Tu16)(unsafe.Pointer(p238)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p238))) | libc.Int32FromInt32(MEM_Real))
											(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(7)
										} else {
											(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(6)
										}
									}
								}
							}
						}
					}
				} else {
					if int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Real) != 0 {
						nHdr++
						nData += uint64(8)
						(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(7)
					} else {
						len11 = uint32((*TMem)(unsafe.Pointer(pRec)).Fn)
						serial_type = len11*uint32(2) + uint32(12) + libc.BoolUint32(int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&libc.Int32FromInt32(MEM_Str) != libc.Int32FromInt32(0))
						if int32((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Zero) != 0 {
							serial_type += uint32(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)) * int32(2))
							if nData != 0 {
								if _sqlite3VdbeMemExpandBlob(tls, pRec) != 0 {
									goto no_mem
								}
								len11 += uint32(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))
							} else {
								nZero += int64(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))
							}
						}
						nData += uint64(uint64(len11))
						nHdr += _sqlite3VarintLen(tls, uint64(uint64(serial_type)))
						(*TMem)(unsafe.Pointer(pRec)).FuTemp = serial_type
					}
				}
			}
			if pRec == pData0 {
				break
			}
			pRec -= 40
		}
		/* 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 += int32(1)
		} else {
			/* Rare case of a really large header */
			nVarint = _sqlite3VarintLen(tls, uint64(uint64(nHdr)))
			nHdr += nVarint
			if nVarint < _sqlite3VarintLen(tls, uint64(uint64(nHdr))) {
				nHdr++
			}
		}
		nByte1 = int64(uint64(uint64(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)(unsafe.Pointer(db + 120))) {
				goto too_big
			}
			if _sqlite3VdbeMemClearAndResize(tls, pOut, int32(int32(nByte1))) != 0 {
				goto no_mem
			}
		}
		(*TMem)(unsafe.Pointer(pOut)).Fn = int32(int32(nByte1))
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Blob)
		if nZero != 0 {
			*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pOut)).Fu)) = int32(int32(nZero))
			p239 = pOut + 16
			*(*Tu16)(unsafe.Pointer(p239)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p239))) | libc.Int32FromInt32(MEM_Zero))
		}
		zHdr1 = (*TMem)(unsafe.Pointer(pOut)).Fz
		zPayload = zHdr1 + uintptr(nHdr)
		/* Write the record */
		if nHdr < int32(0x80) {
			v240 = zHdr1
			zHdr1++
			*(*Tu8)(unsafe.Pointer(v240)) = uint8(uint8(nHdr))
		} else {
			zHdr1 += uintptr(_sqlite3PutVarint(tls, zHdr1, uint64(uint64(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) {
				v241 = zHdr1
				zHdr1++
				*(*Tu8)(unsafe.Pointer(v241)) = uint8(uint8(serial_type))
				if serial_type == uint32(0) {
					/* NULL value.  No change in zPayload */
				} else {
					if serial_type == uint32(7) {
						libc.Xmemcpy(tls, bp+72, pRec, uint32(8))
					} else {
						*(*Tu64)(unsafe.Pointer(bp + 72)) = uint64(*(*Ti64)(unsafe.Pointer(pRec)))
					}
					len11 = uint32(_sqlite3SmallTypeSizes[serial_type])
					switch len11 {
					default:
						*(*Tu8)(unsafe.Pointer(zPayload + 7)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
						*(*Tu64)(unsafe.Pointer(bp + 72)) >>= uint64(8)
						*(*Tu8)(unsafe.Pointer(zPayload + 6)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
						*(*Tu64)(unsafe.Pointer(bp + 72)) >>= uint64(8)
						fallthrough
					case uint32(6):
						*(*Tu8)(unsafe.Pointer(zPayload + 5)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
						*(*Tu64)(unsafe.Pointer(bp + 72)) >>= uint64(8)
						*(*Tu8)(unsafe.Pointer(zPayload + 4)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
						*(*Tu64)(unsafe.Pointer(bp + 72)) >>= uint64(8)
						fallthrough
					case uint32(4):
						*(*Tu8)(unsafe.Pointer(zPayload + 3)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
						*(*Tu64)(unsafe.Pointer(bp + 72)) >>= uint64(8)
						fallthrough
					case uint32(3):
						*(*Tu8)(unsafe.Pointer(zPayload + 2)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
						*(*Tu64)(unsafe.Pointer(bp + 72)) >>= uint64(8)
						fallthrough
					case uint32(2):
						*(*Tu8)(unsafe.Pointer(zPayload + 1)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
						*(*Tu64)(unsafe.Pointer(bp + 72)) >>= uint64(8)
						fallthrough
					case uint32(1):
						*(*Tu8)(unsafe.Pointer(zPayload)) = uint8(*(*Tu64)(unsafe.Pointer(bp + 72)) & libc.Uint64FromInt32(0xff))
					}
					zPayload += uintptr(len11)
				}
			} else {
				if serial_type < uint32(0x80) {
					v242 = zHdr1
					zHdr1++
					*(*Tu8)(unsafe.Pointer(v242)) = uint8(uint8(serial_type))
					if serial_type >= uint32(14) && (*TMem)(unsafe.Pointer(pRec)).Fn > 0 {
						libc.Xmemcpy(tls, zPayload, (*TMem)(unsafe.Pointer(pRec)).Fz, uint32((*TMem)(unsafe.Pointer(pRec)).Fn))
						zPayload += uintptr((*TMem)(unsafe.Pointer(pRec)).Fn)
					}
				} else {
					zHdr1 += uintptr(_sqlite3PutVarint(tls, zHdr1, uint64(uint64(serial_type))))
					if (*TMem)(unsafe.Pointer(pRec)).Fn != 0 {
						libc.Xmemcpy(tls, zPayload, (*TMem)(unsafe.Pointer(pRec)).Fz, uint32((*TMem)(unsafe.Pointer(pRec)).Fn))
						zPayload += uintptr((*TMem)(unsafe.Pointer(pRec)).Fn)
					}
				}
			}
			if pRec == pLast {
				break
			}
			pRec += 40
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)) + 36))
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			*(*Ti64)(unsafe.Pointer(bp + 80)) = _sqlite3BtreeRowCountEst(tls, pCrsr1)
		} else {
			*(*Ti64)(unsafe.Pointer(bp + 80)) = 0 /* Not needed.  Only used to silence a warning. */
			rc = _sqlite3BtreeCount(tls, db, pCrsr1, bp+80)
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = *(*Ti64)(unsafe.Pointer(bp + 80))
		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+7080, 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(uint32(32)+uint32(uint32(nName))+uint32(1)))
				if pNew != 0 {
					(*TSavepoint)(unsafe.Pointer(pNew)).FzName = pNew + 1*32
					libc.Xmemcpy(tls, (*TSavepoint)(unsafe.Pointer(pNew)).FzName, zName, uint32(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++
					}
					/* 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++
				goto _243
			_243:
				;
				pSavepoint = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FpNext
			}
			if !(pSavepoint != 0) {
				_sqlite3VdbeError(tls, p, __ccgo_ts+7131, libc.VaList(bp+736, 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+7153, 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) {
						v244 = _sqlite3VdbeCheckFk(tls, p, int32(1))
						rc = v244
						if v244 != 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(int32(pOp)) - int32(int32(aOp))) / 20
							(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(0)
							v245 = libc.Int32FromInt32(SQLITE_BUSY)
							rc = v245
							(*TVdbe)(unsafe.Pointer(p)).Frc = v245
							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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*16))).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 _246
							_246:
								;
								ii++
							}
						} else {
							isSchemaChange = 0
						}
						ii = 0
						for {
							if !(ii < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
								break
							}
							rc = _sqlite3BtreeSavepoint(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*16))).FpBt, p12, iSavepoint)
							if rc != SQLITE_OK {
								goto abort_due_to_error
							}
							goto _247
						_247:
							;
							ii++
						}
						if isSchemaChange != 0 {
							_sqlite3ExpirePreparedStatements(tls, db, 0)
							_sqlite3ResetAllSchemasOfConnection(tls, db)
							*(*Tu32)(unsafe.Pointer(db + 24)) |= 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--
					}
					/* 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--
						}
					} 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 int32((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_HALT_STATE) {
			rc = int32(SQLITE_DONE)
			goto vdbe_return
		}
		goto _187
		/* 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 != int32((*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+7207, 0)
					rc = int32(SQLITE_BUSY)
					goto abort_due_to_error
				} else {
					v248 = _sqlite3VdbeCheckFk(tls, p, int32(1))
					rc = v248
					if v248 != SQLITE_OK {
						goto vdbe_return
					} else {
						(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(uint8(desiredAutoCommit))
					}
				}
			}
			if _sqlite3VdbeHalt(tls, p) == int32(SQLITE_BUSY) {
				(*TVdbe)(unsafe.Pointer(p)).Fpc = (int32(int32(pOp)) - int32(int32(aOp))) / 20
				(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(libc.Int32FromInt32(1) - desiredAutoCommit)
				v249 = libc.Int32FromInt32(SQLITE_BUSY)
				rc = v249
				(*TVdbe)(unsafe.Pointer(p)).Frc = v249
				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) {
				v250 = __ccgo_ts + 7262
			} else {
				if iRollback != 0 {
					v251 = __ccgo_ts + 7310
				} else {
					v251 = __ccgo_ts + 7353
				}
				v250 = v251
			}
			_sqlite3VdbeError(tls, p, v250, 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)(unsafe.Pointer(bp + 88)) = 0
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(SQLITE_QueryOnly)|uint64(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)*16
		pBt = (*TDb)(unsafe.Pointer(pDb)).FpBt
		if pBt != 0 {
			rc = _sqlite3BtreeBeginTrans(tls, pBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, bp+88)
			if rc != SQLITE_OK {
				if rc&int32(0xff) == int32(SQLITE_BUSY) {
					(*TVdbe)(unsafe.Pointer(p)).Fpc = (int32(int32(pOp)) - int32(int32(aOp))) / 20
					(*TVdbe)(unsafe.Pointer(p)).Frc = rc
					goto vdbe_return
				}
				goto abort_due_to_error
			}
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 152))&0x20>>5)) != 0 && (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 && (int32((*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++
					(*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)(unsafe.Pointer(bp + 88)) != (*TOp)(unsafe.Pointer(pOp)).Fp3 || (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FiGeneration != *(*int32)(unsafe.Pointer(pOp + 16))) {
			/*
			 ** 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+7394)
			/* 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpSchema)).Fschema_cookie != *(*int32)(unsafe.Pointer(bp + 88)) {
				_sqlite3ResetOneSchema(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
			}
			libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(1), 0, 0x3)
			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+152, libc.Uint32FromInt32(0), 4, 0x10)
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt, iCookie, bp+92)
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = int64(*(*int32)(unsafe.Pointer(bp + 92)))
		goto _187
		/* 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)*16
		/* See note about index shifting on OP_ReadCookie */
		rc = _sqlite3BtreeUpdateMeta(tls, (*TDb)(unsafe.Pointer(pDb1)).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, uint32((*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)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb1)).FpSchema)) = *(*Tu32)(unsafe.Pointer(pOp + 12)) - uint32((*TOp)(unsafe.Pointer(pOp)).Fp5)
			*(*Tu32)(unsafe.Pointer(db + 24)) |= 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 = uint8((*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+152, libc.Uint32FromInt32(0), 0, 0x3)
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if pCur != 0 && (*TVdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot == uint32((*TOp)(unsafe.Pointer(pOp)).Fp2) {
			/* Guaranteed by the code generator */
			_sqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pCur + 36)))
			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 + 152))&0x3>>0)) == int32(1) {
			rc = libc.Int32FromInt32(SQLITE_ABORT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
			goto abort_due_to_error
		}
		nField1 = 0
		pKeyInfo1 = uintptr(0)
		p23 = uint32((*TOp)(unsafe.Pointer(pOp)).Fp2)
		iDb1 = (*TOp)(unsafe.Pointer(pOp)).Fp3
		pDb2 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb1)*16
		pX = (*TDb)(unsafe.Pointer(pDb2)).FpBt
		if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_OpenWrite) {
			wrFlag = int32(BTREE_WRCSR) | int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_FORDELETE)
			if int32((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format) < int32((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) {
				(*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat = (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format
			}
		} else {
			wrFlag = 0
		}
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_P2ISREG) != 0 {
			pIn2 = aMem + uintptr(p23)*40
			_sqlite3VdbeMemIntegerify(tls, pIn2)
			p23 = uint32(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. */
		}
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(8) {
			pKeyInfo1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
			nField1 = int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnAllField)
		} else {
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(3) {
				nField1 = *(*int32)(unsafe.Pointer(pOp + 16))
			}
		}
		/* 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(int8(iDb1))
		(*TVdbeCursor)(unsafe.Pointer(pCur)).FnullRow = uint8(1)
		libc.SetBitFieldPtr8Uint32(pCur+8, libc.Uint32FromInt32(1), 2, 0x4)
		(*TVdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot = p23
		rc = _sqlite3BtreeCursor(tls, pX, p23, wrFlag, pKeyInfo1, *(*uintptr)(unsafe.Pointer(pCur + 36)))
		(*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(8))
		goto open_cursor_set_hints
	open_cursor_set_hints:
		;
		_sqlite3BtreeCursorHintFlags(tls, *(*uintptr)(unsafe.Pointer(pCur + 36)), uint32(int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_BULKCSR)|libc.Int32FromInt32(OPFLAG_SEEKEQ))))
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*4))
		/* 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), 0, 0x1)
		(*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, uint32(int32(TBool(*(*uint8)(unsafe.Pointer(pOrig + 8))&0x4>>2))), 2, 0x4)
		*(*uintptr)(unsafe.Pointer(pCx + 12)) = *(*uintptr)(unsafe.Pointer(pOrig + 12))
		libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(1), 3, 0x8)
		libc.SetBitFieldPtr8Uint32(pOrig+8, libc.Uint32FromInt32(1), 3, 0x8)
		rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx + 12)), (*TVdbeCursor)(unsafe.Pointer(pCx)).FpgnoRoot, int32(BTREE_WRCSR), (*TVdbeCursor)(unsafe.Pointer(pCx)).FpKeyInfo, *(*uintptr)(unsafe.Pointer(pCx + 36)))
		/* 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 _187
		/* 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)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))).Fn = 0
			(*(*TMem)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))).Fz = __ccgo_ts + 1672
		}
		pCx1 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if pCx1 != 0 && !(int32(TBool(*(*uint8)(unsafe.Pointer(pCx1 + 8))&0x8>>3)) != 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 + 12)), int32((*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), 0, 0x1)
			rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), db, pCx1+12, libc.Int32FromInt32(BTREE_OMIT_JOURNAL)|libc.Int32FromInt32(BTREE_SINGLE)|int32((*TOp)(unsafe.Pointer(pOp)).Fp5), _vfsFlags)
			if rc == SQLITE_OK {
				rc = _sqlite3BtreeBeginTrans(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), 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).
					 */
					v253 = *(*uintptr)(unsafe.Pointer(pOp + 16))
					pKeyInfo2 = v253
					v252 = v253
					(*TVdbeCursor)(unsafe.Pointer(pCx1)).FpKeyInfo = v252
					if v252 != uintptr(0) {
						rc = _sqlite3BtreeCreateTable(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), pCx1+48, int32(BTREE_BLOBKEY)|int32((*TOp)(unsafe.Pointer(pOp)).Fp5))
						if rc == SQLITE_OK {
							rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), (*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot, int32(BTREE_WRCSR), pKeyInfo2, *(*uintptr)(unsafe.Pointer(pCx1 + 36)))
						}
						(*TVdbeCursor)(unsafe.Pointer(pCx1)).FisTable = uint8(0)
					} else {
						(*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot = uint32(SCHEMA_ROOT)
						rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), uint32(SCHEMA_ROOT), int32(BTREE_WRCSR), uintptr(0), *(*uintptr)(unsafe.Pointer(pCx1 + 36)))
						(*TVdbeCursor)(unsafe.Pointer(pCx1)).FisTable = uint8(1)
					}
				}
				libc.SetBitFieldPtr8Uint32(pCx1+8, libc.BoolUint32(int32((*TOp)(unsafe.Pointer(pOp)).Fp5) != libc.Int32FromInt32(BTREE_UNORDERED)), 2, 0x4)
				if rc != 0 {
					_sqlite3BtreeClose(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)))
				}
			}
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		(*TVdbeCursor)(unsafe.Pointer(pCx1)).FnullRow = uint8(1)
		goto _187
		/* 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 _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		v255 = pC4 + 16
		v254 = *(*Ti64)(unsafe.Pointer(v255))
		*(*Ti64)(unsafe.Pointer(v255))++
		if v254 == 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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 + 36)) = _sqlite3BtreeFakeValidCursor(tls)
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)))
		*(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)) = uintptr(0)
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		oc = int32((*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)*40
			flags31 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
			if int32(int32(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 int32(int32(newType))&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
				if int32(int32(newType))&int32(MEM_Real) == 0 {
					if int32(int32(newType))&int32(MEM_Null) != 0 || oc >= int32(OP_SeekGE) {
						goto jump_to_p2
					} else {
						rc = _sqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), bp+96)
						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--
					}
				} else {
					if c2 < 0 {
						if oc&int32(0x0001) == libc.Int32FromInt32(OP_SeekLT)&libc.Int32FromInt32(0x0001) {
							oc++
						}
					}
				}
			}
			rc = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), int64(uint64(uint64(iKey))), 0, bp+96)
			(*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 + 36)), uint32(BTREE_SEEK_EQ)) != 0 {
				eqOnly = int32(1)
			}
			nField2 = *(*int32)(unsafe.Pointer(pOp + 16))
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 104))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC5)).FpKeyInfo
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 104))).FnField = uint16(uint16(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 {
				v256 = -int32(1)
			} else {
				v256 = +libc.Int32FromInt32(1)
			}
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 104))).Fdefault_rc = int8(v256)
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 104))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 104))).FeqSeen = uint8(0)
			rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), bp+104, bp+96)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			if eqOnly != 0 && int32((*(*TUnpackedRecord)(unsafe.Pointer(bp + 104))).FeqSeen) == 0 {
				goto seek_not_found
			}
		}
		if oc >= int32(OP_SeekGE) {
			if *(*int32)(unsafe.Pointer(bp + 96)) < 0 || *(*int32)(unsafe.Pointer(bp + 96)) == 0 && oc == int32(OP_SeekGT) {
				*(*int32)(unsafe.Pointer(bp + 96)) = 0
				rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), 0)
				if rc != SQLITE_OK {
					if rc == int32(SQLITE_DONE) {
						rc = SQLITE_OK
						*(*int32)(unsafe.Pointer(bp + 96)) = int32(1)
					} else {
						goto abort_due_to_error
					}
				}
			} else {
				*(*int32)(unsafe.Pointer(bp + 96)) = 0
			}
		} else {
			if *(*int32)(unsafe.Pointer(bp + 96)) > 0 || *(*int32)(unsafe.Pointer(bp + 96)) == 0 && oc == int32(OP_SeekLT) {
				*(*int32)(unsafe.Pointer(bp + 96)) = 0
				rc = _sqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), 0)
				if rc != SQLITE_OK {
					if rc == int32(SQLITE_DONE) {
						rc = SQLITE_OK
						*(*int32)(unsafe.Pointer(bp + 96)) = 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)(unsafe.Pointer(bp + 96)) = _sqlite3BtreeEof(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)))
			}
		}
		goto seek_not_found
	seek_not_found:
		;
		if *(*int32)(unsafe.Pointer(bp + 96)) != 0 {
			goto jump_to_p2
		} else {
			if eqOnly != 0 {
				pOp += 20 /* Skip the OP_IdxLt or OP_IdxGT that follows */
			}
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*(*TOp)(unsafe.Pointer(pOp + 1*20))).Fp1)*4))
		if !(_sqlite3BtreeCursorIsValidNN(tls, *(*uintptr)(unsafe.Pointer(pC6 + 36))) != 0) {
			goto _187
		}
		nStep = (*TOp)(unsafe.Pointer(pOp)).Fp1
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 144))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC6)).FpKeyInfo
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 144))).FnField = uint16(*(*int32)(unsafe.Pointer(pOp + 1*20 + 16)))
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 144))).Fdefault_rc = 0
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 144))).FaMem = aMem + uintptr((*(*TOp)(unsafe.Pointer(pOp + 1*20))).Fp3)*40
		*(*int32)(unsafe.Pointer(bp + 136)) = 0 /* Not needed.  Only used to silence a warning. */
	_258:
		;
		if !(int32(1) != 0) {
			goto _257
		}
		rc = _sqlite3VdbeIdxKeyCompare(tls, db, pC6, bp+144, bp+136)
		if rc != 0 {
			goto abort_due_to_error
		}
		if !(*(*int32)(unsafe.Pointer(bp + 136)) > 0 && int32((*TOp)(unsafe.Pointer(pOp)).Fp5) == 0) {
			goto _259
		}
		goto seekscan_search_fail
	seekscan_search_fail:
		;
		/* Jump to SeekGE.P2, ending the loop */
		pOp += 20
		goto jump_to_p2
	_259:
		;
		if *(*int32)(unsafe.Pointer(bp + 136)) >= 0 {
			/* Jump to This.P2, bypassing the OP_SeekGE opcode */
			goto jump_to_p2
			goto _257
		}
		if nStep <= 0 {
			goto _257
		}
		nStep--
		(*TVdbeCursor)(unsafe.Pointer(pC6)).FcacheStatus = uint32(CACHE_STALE)
		rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC6 + 36)), 0)
		if rc != 0 {
			if rc == int32(SQLITE_DONE) {
				rc = SQLITE_OK
				goto seekscan_search_fail
			} else {
				goto abort_due_to_error
			}
		}
		goto _258
	_257:
		;
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if int32((*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit) < (*TOp)(unsafe.Pointer(pOp)).Fp2 {
			(*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit = uint16((*TOp)(unsafe.Pointer(pOp)).Fp2)
		} else {
			if int32((*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit) > (*TOp)(unsafe.Pointer(pOp)).Fp3 {
				(*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit = uint16((*TOp)(unsafe.Pointer(pOp)).Fp3)
			}
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if pCur1 == uintptr(0) || (*TVdbeCursor)(unsafe.Pointer(pCur1)).FnullRow != 0 {
			goto jump_to_p2_and_check_for_interrupt
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if int32((*TVdbeCursor)(unsafe.Pointer(pC8)).FseekHit) >= *(*int32)(unsafe.Pointer(pOp + 16)) {
			goto _187
		}
	_95:
		; /* jump, in3, ncycle */
	_94:
		; /* jump, in3, ncycle */
	_93:
		;
		pC9 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FnField = uint16(*(*int32)(unsafe.Pointer(pOp + 16)))
		if int32((*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FnField) > 0 {
			/* Key values in an array of registers */
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).Fdefault_rc = 0
			rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 36)), bp+176, pC9+28)
		} else {
			/* Composite key generated by OP_MakeRecord */
			if int32((*TMem)(unsafe.Pointer((*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FaMem)).Fflags)&int32(MEM_Zero) != 0 {
				v260 = _sqlite3VdbeMemExpandBlob(tls, (*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FaMem)
			} else {
				v260 = 0
			}
			rc = v260
			if rc != 0 {
				goto no_mem
			}
			pIdxKey = _sqlite3VdbeAllocUnpackedRecord(tls, (*TVdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo)
			if pIdxKey == uintptr(0) {
				goto no_mem
			}
			_sqlite3VdbeRecordUnpack(tls, (*TVdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo, (*TMem)(unsafe.Pointer((*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FaMem)).Fn, (*TMem)(unsafe.Pointer((*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FaMem)).Fz, pIdxKey)
			(*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).Fdefault_rc = 0
			rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 36)), pIdxKey, pC9+28)
			_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 = uint8(int32(1) - alreadyExists)
		(*TVdbeCursor)(unsafe.Pointer(pC9)).FdeferredMoveto = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC9)).FcacheStatus = uint32(CACHE_STALE)
		if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Found) {
			if alreadyExists != 0 {
				goto jump_to_p2
			}
		} else {
			if !(alreadyExists != 0) {
				goto jump_to_p2
			}
			if int32((*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 < int32((*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FnField)) {
						break
					}
					if int32((*(*TMem)(unsafe.Pointer((*(*TUnpackedRecord)(unsafe.Pointer(bp + 176))).FaMem + uintptr(ii1)*40))).Fflags)&int32(MEM_Null) != 0 {
						goto jump_to_p2
					}
					goto _261
				_261:
					;
					ii1++
				}
			}
			if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_IfNoHope) {
				(*TVdbeCursor)(unsafe.Pointer(pC9)).FseekHit = uint16(*(*int32)(unsafe.Pointer(pOp + 16)))
			}
		}
		goto _187
		/* 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)*40
		if int32((*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 + 216)) = 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_value1)(unsafe.Pointer(bp + 216)) = *(*TMem)(unsafe.Pointer(pIn3))
			_applyAffinity(tls, bp+216, int8(SQLITE_AFF_NUMERIC), encoding)
			if int32((*(*TMem)(unsafe.Pointer(bp + 216))).Fflags)&int32(MEM_Int) == 0 {
				goto jump_to_p2
			}
			iKey1 = uint64(*(*Ti64)(unsafe.Pointer(bp + 216)))
			goto notExistsWithKey
		}
	_96:
		; /* jump, in3, ncycle */
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		iKey1 = uint64(*(*Ti64)(unsafe.Pointer(pIn3)))
		goto notExistsWithKey
	notExistsWithKey:
		;
		pC10 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pCrsr2 = *(*uintptr)(unsafe.Pointer(pC10 + 36))
		*(*int32)(unsafe.Pointer(bp + 208)) = 0
		rc = _sqlite3BtreeTableMoveto(tls, pCrsr2, int64(int64(iKey1)), 0, bp+208)
		(*TVdbeCursor)(unsafe.Pointer(pC10)).FmovetoTarget = int64(int64(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)(unsafe.Pointer(bp + 208))
		if *(*int32)(unsafe.Pointer(bp + 208)) != 0 {
			if (*TOp)(unsafe.Pointer(pOp)).Fp2 == 0 {
				rc = _sqlite3CorruptError(tls, int32(98565))
			} else {
				goto jump_to_p2
			}
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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)
		v263 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)) + 16
		v262 = *(*Ti64)(unsafe.Pointer(v263))
		*(*Ti64)(unsafe.Pointer(v263))++
		*(*Ti64)(unsafe.Pointer(pOut)) = v262
		goto _187
		/* 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)(unsafe.Pointer(bp + 256)) = 0
		*(*int32)(unsafe.Pointer(bp + 264)) = 0
		pOut = _out2Prerelease(tls, p, pOp)
		pC11 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		/* 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))&0x2>>1)) != 0) {
			rc = _sqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC11 + 36)), bp+264)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			if *(*int32)(unsafe.Pointer(bp + 264)) != 0 {
				*(*Ti64)(unsafe.Pointer(bp + 256)) = int64(1) /* IMP: R-61914-48074 */
			} else {
				*(*Ti64)(unsafe.Pointer(bp + 256)) = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC11 + 36)))
				if *(*Ti64)(unsafe.Pointer(bp + 256)) >= int64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) {
					libc.SetBitFieldPtr8Uint32(pC11+8, libc.Uint32FromInt32(1), 1, 0x2)
				} else {
					*(*Ti64)(unsafe.Pointer(bp + 256))++ /* 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 _264
				_264:
					;
					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)*40
			} else {
				/* Assert that P3 is a valid memory cell. */
				pMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
			}
			_sqlite3VdbeMemIntegerify(tls, pMem)
			/* mem(P3) holds an integer */
			if *(*Ti64)(unsafe.Pointer(pMem)) == int64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) || int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1)) != 0 {
				rc = int32(SQLITE_FULL) /* IMP: R-17817-00630 */
				goto abort_due_to_error
			}
			if *(*Ti64)(unsafe.Pointer(bp + 256)) < *(*Ti64)(unsafe.Pointer(pMem))+int64(1) {
				*(*Ti64)(unsafe.Pointer(bp + 256)) = *(*Ti64)(unsafe.Pointer(pMem)) + int64(1)
			}
			*(*Ti64)(unsafe.Pointer(pMem)) = *(*Ti64)(unsafe.Pointer(bp + 256))
		}
		if int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1)) != 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+256)
				*(*Ti64)(unsafe.Pointer(bp + 256)) &= int64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) >> libc.Int32FromInt32(1)
				*(*Ti64)(unsafe.Pointer(bp + 256))++ /* Ensure that v is greater than zero */
				goto _268
			_268:
				;
				v265 = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC11 + 36)), int64(uint64(*(*Ti64)(unsafe.Pointer(bp + 256)))), 0, bp+264)
				rc = v265
				if v267 = v265 == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 264)) == 0; v267 {
					cnt1++
					v266 = cnt1
				}
				if !(v267 && v266 < int32(100)) {
					break
				}
			}
			if rc != 0 {
				goto abort_due_to_error
			}
			if *(*int32)(unsafe.Pointer(bp + 264)) == 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)(unsafe.Pointer(bp + 256))
		goto _187
		/* 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)*40
		pC12 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pKey = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		(*(*TBtreePayload)(unsafe.Pointer(bp + 272))).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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TVdbeCursor)(unsafe.Pointer(pC12)).FiDb)*16))).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 && !(int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&libc.Int32FromInt32(OPFLAG_ISUPDATE) != 0) {
				_sqlite3VdbePreUpdateHook(tls, p, pC12, int32(SQLITE_INSERT), zDb, pTab1, (*(*TBtreePayload)(unsafe.Pointer(bp + 272))).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 int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_ISNOOP) != 0 {
			goto _187
		}
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NCHANGE) != 0 {
			(*TVdbe)(unsafe.Pointer(p)).FnChange++
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_LASTROWID) != 0 {
				(*Tsqlite3)(unsafe.Pointer(db)).FlastRowid = (*(*TBtreePayload)(unsafe.Pointer(bp + 272))).FnKey
			}
		}
		(*(*TBtreePayload)(unsafe.Pointer(bp + 272))).FpData = (*TMem)(unsafe.Pointer(pData)).Fz
		(*(*TBtreePayload)(unsafe.Pointer(bp + 272))).FnData = (*TMem)(unsafe.Pointer(pData)).Fn
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_USESEEKRESULT) != 0 {
			v269 = (*TVdbeCursor)(unsafe.Pointer(pC12)).FseekResult
		} else {
			v269 = 0
		}
		seekResult = v269
		if int32((*TMem)(unsafe.Pointer(pData)).Fflags)&int32(MEM_Zero) != 0 {
			(*(*TBtreePayload)(unsafe.Pointer(bp + 272))).FnZero = *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pData)).Fu))
		} else {
			(*(*TBtreePayload)(unsafe.Pointer(bp + 272))).FnZero = 0
		}
		(*(*TBtreePayload)(unsafe.Pointer(bp + 272))).FpKey = uintptr(0)
		rc = _sqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC12 + 36)), bp+272, int32((*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++
		/* Invoke the update-hook if required. */
		if rc != 0 {
			goto abort_due_to_error
		}
		if pTab1 != 0 {
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_ISUPDATE) != 0 {
				v270 = int32(SQLITE_UPDATE)
			} else {
				v270 = 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, v270, zDb, (*TTable)(unsafe.Pointer(pTab1)).FzName, (*(*TBtreePayload)(unsafe.Pointer(bp + 272))).FnKey)
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pSrc = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*4))
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			v271 = *(*Ti64)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))
		} else {
			v271 = 0
		}
		iKey2 = v271
		rc = _sqlite3BtreeTransferRow(tls, *(*uintptr)(unsafe.Pointer(pDest1 + 36)), *(*uintptr)(unsafe.Pointer(pSrc + 36)), iKey2)
		if rc != SQLITE_OK {
			goto abort_due_to_error
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		/* 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TVdbeCursor)(unsafe.Pointer(pC13)).FiDb)*16))).FzDbSName
			pTab2 = *(*uintptr)(unsafe.Pointer(pOp + 16))
			if int32((*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 + 36)))
			}
		} 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 {
				v272 = int32(SQLITE_UPDATE)
			} else {
				v272 = int32(SQLITE_DELETE)
			}
			_sqlite3VdbePreUpdateHook(tls, p, pC13, v272, zDb1, pTab2, (*TVdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget, (*TOp)(unsafe.Pointer(pOp)).Fp3, -int32(1))
		}
		if opflags&int32(OPFLAG_ISNOOP) != 0 {
			goto _187
		}
		/* Only flags that can be set are SAVEPOISTION and AUXDELETE */
		rc = _sqlite3BtreeDelete(tls, *(*uintptr)(unsafe.Pointer(pC13 + 36)), uint8((*TOp)(unsafe.Pointer(pOp)).Fp5))
		(*TVdbeCursor)(unsafe.Pointer(pC13)).FcacheStatus = uint32(CACHE_STALE)
		colCacheCtr++
		(*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++
			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 _187
		/* 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 _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		nKeyCol = *(*int32)(unsafe.Pointer(pOp + 16))
		*(*int32)(unsafe.Pointer(bp + 312)) = 0
		rc = _sqlite3VdbeSorterCompare(tls, pC14, pIn3, nKeyCol, bp+312)
		if rc != 0 {
			goto abort_due_to_error
		}
		if *(*int32)(unsafe.Pointer(bp + 312)) != 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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)*40
		pC15 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		rc = _sqlite3VdbeSorterRowkey(tls, pC15, pOut)
		if rc != 0 {
			goto abort_due_to_error
		}
		(*TVdbeCursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*4)))).FcacheStatus = uint32(CACHE_STALE)
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pCrsr3 = *(*uintptr)(unsafe.Pointer(pC16 + 36))
		/* 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 where not the case, on 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 > uint32(*(*int32)(unsafe.Pointer(db + 120))) {
			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 int32((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				goto no_mem
			}
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if (*TVdbeCursor)(unsafe.Pointer(pC17)).FnullRow != 0 {
			(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
			goto _187
		} else {
			if (*TVdbeCursor)(unsafe.Pointer(pC17)).FdeferredMoveto != 0 {
				*(*Ti64)(unsafe.Pointer(bp + 320)) = (*TVdbeCursor)(unsafe.Pointer(pC17)).FmovetoTarget
			} else {
				if int32((*TVdbeCursor)(unsafe.Pointer(pC17)).FeCurType) == int32(CURTYPE_VTAB) {
					pVtab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pC17 + 36)))).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 + 36)), bp+320)
					_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 _187
					}
					*(*Ti64)(unsafe.Pointer(bp + 320)) = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC17 + 36)))
				}
			}
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = *(*Ti64)(unsafe.Pointer(bp + 320))
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		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), 3, 0x8)
			*(*uintptr)(unsafe.Pointer(pC18 + 36)) = _sqlite3BtreeFakeValidCursor(tls)
		}
		(*TVdbeCursor)(unsafe.Pointer(pC18)).FnullRow = uint8(1)
		(*TVdbeCursor)(unsafe.Pointer(pC18)).FcacheStatus = uint32(CACHE_STALE)
		if int32((*TVdbeCursor)(unsafe.Pointer(pC18)).FeCurType) == CURTYPE_BTREE {
			_sqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pC18 + 36)))
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pCrsr4 = *(*uintptr)(unsafe.Pointer(pC19 + 36))
		*(*int32)(unsafe.Pointer(bp + 328)) = 0
		if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_SeekEnd) {
			(*TVdbeCursor)(unsafe.Pointer(pC19)).FseekResult = -int32(1)
			if _sqlite3BtreeCursorIsValidNN(tls, pCrsr4) != 0 {
				goto _187
			}
		}
		rc = _sqlite3BtreeLast(tls, pCrsr4, bp+328)
		(*TVdbeCursor)(unsafe.Pointer(pC19)).FnullRow = uint8(*(*int32)(unsafe.Pointer(bp + 328)))
		(*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)(unsafe.Pointer(bp + 328)) != 0 {
				goto jump_to_p2
			}
		}
		goto _187
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pCrsr5 = *(*uintptr)(unsafe.Pointer(pC20 + 36))
		rc = _sqlite3BtreeFirst(tls, pCrsr5, bp+332)
		if rc != 0 {
			goto abort_due_to_error
		}
		if *(*int32)(unsafe.Pointer(bp + 332)) != 0 {
			sz = int64(-int32(1)) /* -Infinity encoding */
		} else {
			sz = _sqlite3BtreeRowCountEst(tls, pCrsr5)
			sz = int64(_sqlite3LogEst(tls, uint64(uint64(sz))))
		}
		*(*int32)(unsafe.Pointer(bp + 332)) = libc.BoolInt32(sz >= int64((*TOp)(unsafe.Pointer(pOp)).Fp3) && sz <= int64(*(*int32)(unsafe.Pointer(pOp + 16))))
		if *(*int32)(unsafe.Pointer(bp + 332)) != 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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)(unsafe.Pointer(p + 164 + 2*4))++
		/* 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)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		*(*int32)(unsafe.Pointer(bp + 336)) = int32(1)
		if int32((*TVdbeCursor)(unsafe.Pointer(pC21)).FeCurType) == int32(CURTYPE_SORTER) {
			rc = _sqlite3VdbeSorterRewind(tls, pC21, bp+336)
		} else {
			pCrsr6 = *(*uintptr)(unsafe.Pointer(pC21 + 36))
			rc = _sqlite3BtreeFirst(tls, pCrsr6, bp+336)
			(*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 = uint8(*(*int32)(unsafe.Pointer(bp + 336)))
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 > 0 {
			if *(*int32)(unsafe.Pointer(bp + 336)) != 0 {
				goto jump_to_p2
			}
		}
		goto _187
		/* 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.
		 */
	_117:
		;
		pC22 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		rc = _sqlite3VdbeSorterNext(tls, db, pC22)
		goto next_tail
	_115:
		; /* jump, ncycle */
		pC22 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		rc = _sqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC22 + 36)), (*TOp)(unsafe.Pointer(pOp)).Fp3)
		goto next_tail
	_116:
		; /* jump, ncycle */
		pC22 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC22 + 36)), (*TOp)(unsafe.Pointer(pOp)).Fp3)
		goto next_tail
	next_tail:
		;
		(*TVdbeCursor)(unsafe.Pointer(pC22)).FcacheStatus = uint32(CACHE_STALE)
		if rc == SQLITE_OK {
			(*TVdbeCursor)(unsafe.Pointer(pC22)).FnullRow = uint8(0)
			*(*Tu32)(unsafe.Pointer(p + 164 + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*4))++
			goto jump_to_p2_and_check_for_interrupt
		}
		if rc != int32(SQLITE_DONE) {
			goto abort_due_to_error
		}
		rc = SQLITE_OK
		(*TVdbeCursor)(unsafe.Pointer(pC22)).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.
		 */
	_118:
		;
		pC23 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NCHANGE) != 0 {
			(*TVdbe)(unsafe.Pointer(p)).FnChange++
		}
		if int32((*TMem)(unsafe.Pointer(pIn2)).Fflags)&int32(MEM_Zero) != 0 {
			v273 = _sqlite3VdbeMemExpandBlob(tls, pIn2)
		} else {
			v273 = 0
		}
		rc = v273
		if rc != 0 {
			goto abort_due_to_error
		}
		(*(*TBtreePayload)(unsafe.Pointer(bp + 344))).FnKey = int64((*TMem)(unsafe.Pointer(pIn2)).Fn)
		(*(*TBtreePayload)(unsafe.Pointer(bp + 344))).FpKey = (*TMem)(unsafe.Pointer(pIn2)).Fz
		(*(*TBtreePayload)(unsafe.Pointer(bp + 344))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		(*(*TBtreePayload)(unsafe.Pointer(bp + 344))).FnMem = uint16(*(*int32)(unsafe.Pointer(pOp + 16)))
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_USESEEKRESULT) != 0 {
			v274 = (*TVdbeCursor)(unsafe.Pointer(pC23)).FseekResult
		} else {
			v274 = 0
		}
		rc = _sqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC23 + 36)), bp+344, int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_APPEND)|libc.Int32FromInt32(OPFLAG_SAVEPOSITION)|libc.Int32FromInt32(OPFLAG_PREFORMAT)), v274)
		(*TVdbeCursor)(unsafe.Pointer(pC23)).FcacheStatus = uint32(CACHE_STALE)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_119:
		;
		pC24 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		if int32((*TMem)(unsafe.Pointer(pIn2)).Fflags)&int32(MEM_Zero) != 0 {
			v275 = _sqlite3VdbeMemExpandBlob(tls, pIn2)
		} else {
			v275 = 0
		}
		rc = v275
		if rc != 0 {
			goto abort_due_to_error
		}
		rc = _sqlite3VdbeSorterWrite(tls, pC24, pIn2)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* Opcode: IdxDelete P1 P2 P3 * P5
		 ** 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.
		 **
		 ** If P5 is not zero, then raise an SQLITE_CORRUPT_INDEX error
		 ** if no matching index entry is found.  This happens when running
		 ** an UPDATE or DELETE statement and the index entry to be updated
		 ** or deleted is not found.  For some uses of IdxDelete
		 ** (example:  the EXCEPT operator) it does not matter that no matching
		 ** entry is found.  For those cases, P5 is zero.  Also, do not raise
		 ** this (self-correcting and non-critical) error if in writable_schema mode.
		 */
	_120:
		;
		pC25 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pCrsr7 = *(*uintptr)(unsafe.Pointer(pC25 + 36))
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 392))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC25)).FpKeyInfo
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 392))).FnField = uint16((*TOp)(unsafe.Pointer(pOp)).Fp3)
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 392))).Fdefault_rc = 0
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 392))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		rc = _sqlite3BtreeIndexMoveto(tls, pCrsr7, bp+392, bp+384)
		if rc != 0 {
			goto abort_due_to_error
		}
		if *(*int32)(unsafe.Pointer(bp + 384)) == 0 {
			rc = _sqlite3BtreeDelete(tls, pCrsr7, uint8(BTREE_AUXDELETE))
			if rc != 0 {
				goto abort_due_to_error
			}
		} else {
			if (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 && !(_sqlite3WritableSchema(tls, db) != 0) {
				rc = _sqlite3ReportError(tls, libc.Int32FromInt32(SQLITE_CORRUPT)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), int32(99657), __ccgo_ts+7422)
				goto abort_due_to_error
			}
		}
		(*TVdbeCursor)(unsafe.Pointer(pC25)).FcacheStatus = uint32(CACHE_STALE)
		(*TVdbeCursor)(unsafe.Pointer(pC25)).FseekResult = 0
		goto _187
		/* 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.
		 */
	_122:
		; /* ncycle */
	_121:
		; /* Rowid that P1 current points to */
		pC26 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		/* The IdxRowid and Seek opcodes are combined because of the commonality
		 ** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */
		rc = _sqlite3VdbeCursorRestore(tls, pC26)
		/* 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(pC26)).FnullRow != 0) {
			*(*Ti64)(unsafe.Pointer(bp + 424)) = 0 /* Not needed.  Only used to silence a warning. */
			rc = _sqlite3VdbeIdxRowid(tls, db, *(*uintptr)(unsafe.Pointer(pC26 + 36)), bp+424)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_DeferredSeek) {
				pTabCur = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*4))
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FnullRow = uint8(0)
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FmovetoTarget = *(*Ti64)(unsafe.Pointer(bp + 424))
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FdeferredMoveto = uint8(1)
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FcacheStatus = uint32(CACHE_STALE)
				*(*uintptr)(unsafe.Pointer(pTabCur + 12)) = *(*uintptr)(unsafe.Pointer(pOp + 16))
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FpAltCursor = pC26
			} else {
				pOut = _out2Prerelease(tls, p, pOp)
				*(*Ti64)(unsafe.Pointer(pOut)) = *(*Ti64)(unsafe.Pointer(bp + 424))
			}
		} else {
			_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40)
		}
		goto _187
		/* 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.
		 */
	_123:
		; /* The P1 index cursor */
		pC27 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if (*TVdbeCursor)(unsafe.Pointer(pC27)).FdeferredMoveto != 0 {
			rc = _sqlite3VdbeFinishMoveto(tls, pC27)
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _187
		/* 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.
		 */
	_127:
		; /* jump, ncycle */
	_126:
		; /* jump, ncycle */
	_125:
		; /* jump, ncycle */
	_124:
		;
		pC28 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 432))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC28)).FpKeyInfo
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 432))).FnField = uint16(*(*int32)(unsafe.Pointer(pOp + 16)))
		if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) < int32(OP_IdxLT) {
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 432))).Fdefault_rc = int8(-int32(1))
		} else {
			(*(*TUnpackedRecord)(unsafe.Pointer(bp + 432))).Fdefault_rc = 0
		}
		(*(*TUnpackedRecord)(unsafe.Pointer(bp + 432))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		/* Inlined version of sqlite3VdbeIdxKeyCompare() */
		nCellKey = 0
		pCur2 = *(*uintptr)(unsafe.Pointer(pC28 + 36))
		nCellKey = int64(_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(99862))
			goto abort_due_to_error
		}
		_sqlite3VdbeMemInit(tls, bp+464, db, uint16(0))
		rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, pCur2, uint32(uint32(nCellKey)), bp+464)
		if rc != 0 {
			goto abort_due_to_error
		}
		res10 = _sqlite3VdbeRecordCompareWithSkip(tls, (*(*TMem)(unsafe.Pointer(bp + 464))).Fn, (*(*TMem)(unsafe.Pointer(bp + 464))).Fz, bp+432, 0)
		_sqlite3VdbeMemReleaseMalloc(tls, bp+464)
		/* End of inlined sqlite3VdbeIdxKeyCompare() */
		if int32((*TOp)(unsafe.Pointer(pOp)).Fopcode)&int32(1) == libc.Int32FromInt32(OP_IdxLT)&libc.Int32FromInt32(1) {
			res10 = -res10
		} else {
			res10++
		}
		if res10 > 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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
		 */
	_128:
		;
		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)(unsafe.Pointer(bp + 504)) = 0 /* Not needed.  Only to silence a warning. */
			rc = _sqlite3BtreeDropTable(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb2)*16))).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp1, bp+504)
			(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
			*(*Ti64)(unsafe.Pointer(pOut)) = int64(*(*int32)(unsafe.Pointer(bp + 504)))
			if rc != 0 {
				goto abort_due_to_error
			}
			if *(*int32)(unsafe.Pointer(bp + 504)) != 0 {
				_sqlite3RootPageMoved(tls, db, iDb2, uint32(*(*int32)(unsafe.Pointer(bp + 504))), uint32((*TOp)(unsafe.Pointer(pOp)).Fp1))
				/* All OP_Destroy operations occur on the same btree */
				resetSchemaOnFault = uint8(iDb2 + int32(1))
			}
		}
		goto _187
		/* 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
		 */
	_129:
		;
		*(*Ti64)(unsafe.Pointer(bp + 512)) = 0
		rc = _sqlite3BtreeClearTable(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*16))).FpBt, int32(uint32((*TOp)(unsafe.Pointer(pOp)).Fp1)), bp+512)
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			*(*Ti64)(unsafe.Pointer(p + 40)) += *(*Ti64)(unsafe.Pointer(bp + 512))
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 > 0 {
				*(*Ti64)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40)) += *(*Ti64)(unsafe.Pointer(bp + 512))
			}
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_130:
		;
		pC29 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if int32((*TVdbeCursor)(unsafe.Pointer(pC29)).FeCurType) == int32(CURTYPE_SORTER) {
			_sqlite3VdbeSorterReset(tls, db, *(*uintptr)(unsafe.Pointer(pC29 + 36)))
		} else {
			rc = _sqlite3BtreeClearTableOfCursor(tls, *(*uintptr)(unsafe.Pointer(pC29 + 36)))
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _187
		/* 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.
		 */
	_131:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		*(*TPgno)(unsafe.Pointer(bp + 520)) = uint32(0)
		pDb3 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16
		rc = _sqlite3BtreeCreateTable(tls, (*TDb)(unsafe.Pointer(pDb3)).FpBt, bp+520, (*TOp)(unsafe.Pointer(pOp)).Fp3)
		if rc != 0 {
			goto abort_due_to_error
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = int64(*(*TPgno)(unsafe.Pointer(bp + 520)))
		goto _187
		/* 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.
		 **
		 */
	_132:
		;
		(*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec++
		*(*uintptr)(unsafe.Pointer(bp + 524)) = 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+524)
		(*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec--
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
		(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = mTrace
		(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = savedAnalysisLimit
		if *(*uintptr)(unsafe.Pointer(bp + 524)) != 0 || rc != 0 {
			_sqlite3VdbeError(tls, p, __ccgo_ts+4709, libc.VaList(bp+736, *(*uintptr)(unsafe.Pointer(bp + 524))))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 524)))
			if rc == int32(SQLITE_NOMEM) {
				goto no_mem
			}
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_133:
		;
		/* 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*16))).FpSchema)
			*(*Tu32)(unsafe.Pointer(db + 24)) &= uint32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
			rc = _sqlite3InitOne(tls, db, iDb3, p+124, uint32((*TOp)(unsafe.Pointer(pOp)).Fp5))
			*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_SchemaChange)
			libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(0), 0, 0x3)
		} else {
			zSchema = __ccgo_ts + 7439
			(*(*TInitData)(unsafe.Pointer(bp + 528))).Fdb = db
			(*(*TInitData)(unsafe.Pointer(bp + 528))).FiDb = iDb3
			(*(*TInitData)(unsafe.Pointer(bp + 528))).FpzErrMsg = p + 124
			(*(*TInitData)(unsafe.Pointer(bp + 528))).FmInitFlags = uint32(0)
			(*(*TInitData)(unsafe.Pointer(bp + 528))).FmxPage = _sqlite3BtreeLastPage(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*16))).FpBt)
			zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+7453, libc.VaList(bp+736, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*16))).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)(unsafe.Pointer(bp + 528))).Frc = SQLITE_OK
				(*(*TInitData)(unsafe.Pointer(bp + 528))).FnInitRow = uint32(0)
				rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3InitCallback), bp+528, uintptr(0))
				if rc == SQLITE_OK {
					rc = (*(*TInitData)(unsafe.Pointer(bp + 528))).Frc
				}
				if rc == SQLITE_OK && (*(*TInitData)(unsafe.Pointer(bp + 528))).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(100155))
				}
				_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 _187
		/* 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.
		 */
	_134:
		;
		rc = _sqlite3AnalysisLoad(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_135:
		;
		_sqlite3UnlinkAndDeleteTable(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		goto _187
		/* 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.
		 */
	_136:
		;
		_sqlite3UnlinkAndDeleteIndex(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		goto _187
		/* 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.
		 */
	_137:
		;
		_sqlite3UnlinkAndDeleteTrigger(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		goto _187
		/* 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.
		 */
	_138:
		; /* 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)*40
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1+int32(1))*40
		rc = _sqlite3BtreeIntegrityCheck(tls, db, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*16))).FpBt, aRoot+1*4, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40, nRoot, int32(*(*Ti64)(unsafe.Pointer(pnErr)))+int32(1), bp+556, bp+560)
		_sqlite3VdbeMemSetNull(tls, pIn1)
		if *(*int32)(unsafe.Pointer(bp + 556)) == 0 {
		} else {
			if rc != 0 {
				Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 560)))
				goto abort_due_to_error
			} else {
				*(*Ti64)(unsafe.Pointer(pnErr)) -= int64(*(*int32)(unsafe.Pointer(bp + 556)) - int32(1))
				_sqlite3VdbeMemSetStr(tls, pIn1, *(*uintptr)(unsafe.Pointer(bp + 560)), int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
			}
		}
		_sqlite3VdbeChangeEncoding(tls, pIn1, int32(int32(encoding)))
		goto check_for_interrupt
		/* 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.
		 */
	_139:
		; /* in1, in2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		if int32((*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 _187
		/* 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.
		 */
	_140:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 || _sqlite3RowSetNext(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, bp+568) == 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)*40, *(*Ti64)(unsafe.Pointer(bp + 568)))
		}
		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).
		 */
	_141:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		iSet = *(*int32)(unsafe.Pointer(pOp + 16))
		/* If there is anything other than a rowset object in memory cell P1,
		 ** delete it now and initialize P1 with an empty rowset
		 */
		if int32((*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 _187
		/* 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.
		 */
	_142:
		; /* Token identifying trigger */
		pProgram = *(*uintptr)(unsafe.Pointer(pOp + 16))
		pRt = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		/* 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 _276
			_276:
				;
				pFrame2 = (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FpParent
			}
			if pFrame2 != 0 {
				goto _187
			}
		}
		if (*TVdbe)(unsafe.Pointer(p)).FnFrame >= *(*int32)(unsafe.Pointer(db + 120 + 10*4)) {
			rc = int32(SQLITE_ERROR)
			_sqlite3VdbeError(tls, p, __ccgo_ts+7496, 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 int32((*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++
			}
			nByte2 = int32((libc.Uint32FromInt64(88)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)) + uint32(uint32(nMem))*uint32(40) + uint32((*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr)*uint32(4) + uint32(((*TSubProgram)(unsafe.Pointer(pProgram)).FnOp+int32(7))/int32(8)))
			pFrame2 = _sqlite3DbMallocZero(tls, db, uint64(uint64(nByte2)))
			if !(pFrame2 != 0) {
				goto no_mem
			}
			_sqlite3VdbeMemRelease(tls, pRt)
			(*TMem)(unsafe.Pointer(pRt)).Fflags = uint16(libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Dyn))
			(*TMem)(unsafe.Pointer(pRt)).Fz = pFrame2
			(*TMem)(unsafe.Pointer(pRt)).Fn = 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(int32(pOp)) - int32(int32(aOp))) / 20
			(*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.Uint32FromInt64(88)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7))) + uintptr((*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem)*40
			pMem1 = pFrame2 + uintptr((libc.Uint32FromInt64(88)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
			for {
				if !(pMem1 != pEnd) {
					break
				}
				(*TMem)(unsafe.Pointer(pMem1)).Fflags = uint16(MEM_Undefined)
				(*TMem)(unsafe.Pointer(pMem1)).Fdb = db
				goto _277
			_277:
				;
				pMem1 += 40
			}
		} else {
			pFrame2 = (*TMem)(unsafe.Pointer(pRt)).Fz
		}
		(*TVdbe)(unsafe.Pointer(p)).FnFrame++
		(*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
		v278 = pFrame2 + uintptr((libc.Uint32FromInt64(88)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
		aMem = v278
		(*TVdbe)(unsafe.Pointer(p)).FaMem = v278
		(*TVdbe)(unsafe.Pointer(p)).FnMem = (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem
		(*TVdbe)(unsafe.Pointer(p)).FnCursor = int32(uint16((*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildCsr))
		(*TVdbe)(unsafe.Pointer(p)).FapCsr = aMem + uintptr((*TVdbe)(unsafe.Pointer(p)).FnMem)*40
		(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce = (*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr)*4
		libc.Xmemset(tls, (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce, 0, uint32(((*TSubProgram)(unsafe.Pointer(pProgram)).FnOp+int32(7))/int32(8)))
		v279 = (*TSubProgram)(unsafe.Pointer(pProgram)).FaOp
		aOp = v279
		(*TVdbe)(unsafe.Pointer(p)).FaOp = v279
		(*TVdbe)(unsafe.Pointer(p)).FnOp = (*TSubProgram)(unsafe.Pointer(pProgram)).FnOp
		pOp = aOp + uintptr(-libc.Int32FromInt32(1))*20
		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.
		 */
	_143:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		pFrame3 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
		pIn = (*TVdbeFrame)(unsafe.Pointer(pFrame3)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1+(*(*TOp)(unsafe.Pointer((*TVdbeFrame)(unsafe.Pointer(pFrame3)).FaOp + uintptr((*TVdbeFrame)(unsafe.Pointer(pFrame3)).Fpc)*20))).Fp1)*40
		_sqlite3VdbeMemShallowCopy(tls, pOut, pIn, int32(MEM_Ephem))
		goto _187
		/* 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).
		 */
	_144:
		;
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
			*(*Ti64)(unsafe.Pointer(db + 536)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
		} else {
			if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
				*(*Ti64)(unsafe.Pointer(db + 528)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
			} else {
				*(*Ti64)(unsafe.Pointer(p + 64)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
			}
		}
		goto _187
		/* 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).
		 */
	_145:
		; /* 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 _187
		/* 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.
		 */
	_146:
		;
		if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
			pFrame4 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
			for {
				if !((*TVdbeFrame)(unsafe.Pointer(pFrame4)).FpParent != 0) {
					break
				}
				goto _280
			_280:
				;
				pFrame4 = (*TVdbeFrame)(unsafe.Pointer(pFrame4)).FpParent
			}
			pIn1 = (*TVdbeFrame)(unsafe.Pointer(pFrame4)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		} else {
			pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		}
		_sqlite3VdbeMemIntegerify(tls, pIn1)
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		_sqlite3VdbeMemIntegerify(tls, pIn2)
		if *(*Ti64)(unsafe.Pointer(pIn1)) < *(*Ti64)(unsafe.Pointer(pIn2)) {
			*(*Ti64)(unsafe.Pointer(pIn1)) = *(*Ti64)(unsafe.Pointer(pIn2))
		}
		goto _187
		/* 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.
		 */
	_147:
		; /* jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		if *(*Ti64)(unsafe.Pointer(pIn1)) > 0 {
			*(*Ti64)(unsafe.Pointer(pIn1)) -= int64((*TOp)(unsafe.Pointer(pOp)).Fp3)
			goto jump_to_p2
		}
		goto _187
		/* 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].
		 */
	_148:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(bp + 576)) = *(*Ti64)(unsafe.Pointer(pIn1))
		if v282 = *(*Ti64)(unsafe.Pointer(bp + 576)) <= 0; !v282 {
			if *(*Ti64)(unsafe.Pointer(pIn3)) > 0 {
				v281 = *(*Ti64)(unsafe.Pointer(pIn3))
			} else {
				v281 = 0
			}
		}
		if v282 || _sqlite3AddInt64(tls, bp+576, v281) != 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)(unsafe.Pointer(bp + 576))
		}
		goto _187
		/* 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.
		 */
	_149:
		; /* jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		if *(*Ti64)(unsafe.Pointer(pIn1)) != 0 {
			if *(*Ti64)(unsafe.Pointer(pIn1)) > 0 {
				*(*Ti64)(unsafe.Pointer(pIn1))--
			}
			goto jump_to_p2
		}
		goto _187
		/* 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.
		 */
	_150:
		; /* jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		if *(*Ti64)(unsafe.Pointer(pIn1)) > int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
			*(*Ti64)(unsafe.Pointer(pIn1))--
		}
		if *(*Ti64)(unsafe.Pointer(pIn1)) == 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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.
		 */
	_152:
		;
	_151:
		;
		n4 = int32((*TOp)(unsafe.Pointer(pOp)).Fp5)
		pCtx = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(uint32(n4))*uint32(4)+(libc.Uint32FromInt64(32)+libc.Uint32FromInt64(40)-libc.Uint32FromInt64(4))))
		if pCtx == uintptr(0) {
			goto no_mem
		}
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpMem = uintptr(0)
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut = pCtx + 28 + uintptr(n4)*4
		_sqlite3VdbeMemInit(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, db, uint16(MEM_Null))
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpFunc = *(*uintptr)(unsafe.Pointer(pOp + 16))
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp = (int32(int32(pOp)) - int32(int32(aOp))) / 20
		(*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 = uint8(uint8(n4))
		(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(15))
		*(*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)
	_153:
		;
		pCtx1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		pMem2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		/* 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 = int32((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc) - int32(1)
			for {
				if !(i4 >= 0) {
					break
				}
				*(*uintptr)(unsafe.Pointer(pCtx1 + 28 + uintptr(i4)*4)) = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2+i4)*40
				goto _283
			_283:
				;
				i4--
			}
		}
		(*TMem)(unsafe.Pointer(pMem2)).Fn++
		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, int32((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+28)
		} else {
			(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpFunc)).FxSFunc})))(tls, pCtx1, int32((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+28)
		} /* 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+4709, libc.VaList(bp+736, 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)(unsafe.Pointer(pOp + uintptr(-libc.Int32FromInt32(1))*20))).Fp1
				if i4 != 0 {
					_sqlite3VdbeMemSetInt64(tls, aMem+uintptr(i4)*40, 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 _187
		/* 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.
		 */
	_155:
		;
	_154:
		;
		pMem3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			rc = _sqlite3VdbeMemAggValue(tls, pMem3, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40, *(*uintptr)(unsafe.Pointer(pOp + 16)))
			pMem3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		} else {
			rc = _sqlite3VdbeMemFinalize(tls, pMem3, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		}
		if rc != 0 {
			_sqlite3VdbeError(tls, p, __ccgo_ts+4709, libc.VaList(bp+736, Xsqlite3_value_text(tls, pMem3)))
			goto abort_due_to_error
		}
		_sqlite3VdbeChangeEncoding(tls, pMem3, int32(int32(encoding)))
		goto _187
		/* 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.
		 */
	_156:
		; /* Write results here */
		(*(*[3]int32)(unsafe.Pointer(bp + 584)))[0] = 0
		v284 = -libc.Int32FromInt32(1)
		(*(*[3]int32)(unsafe.Pointer(bp + 584)))[int32(2)] = v284
		(*(*[3]int32)(unsafe.Pointer(bp + 584)))[int32(1)] = v284
		rc = _sqlite3Checkpoint(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp2, bp+584+1*4, bp+584+2*4)
		if rc != 0 {
			if rc != int32(SQLITE_BUSY) {
				goto abort_due_to_error
			}
			rc = SQLITE_OK
			(*(*[3]int32)(unsafe.Pointer(bp + 584)))[0] = int32(1)
		}
		i5 = 0
		pMem4 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		for {
			if !(i5 < int32(3)) {
				break
			}
			_sqlite3VdbeMemSetInt64(tls, pMem4, int64((*(*[3]int32)(unsafe.Pointer(bp + 584)))[i5]))
			goto _285
		_285:
			;
			i5++
			pMem4 += 40
		}
		goto _187
		/* 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.
		 */
	_157:
		; /* Name of database file for pPager */
		pOut = _out2Prerelease(tls, p, pOp)
		eNew = (*TOp)(unsafe.Pointer(pOp)).Fp3
		pBt1 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).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) {
					v286 = __ccgo_ts + 7533
				} else {
					v286 = __ccgo_ts + 7538
				}
				_sqlite3VdbeError(tls, p, __ccgo_ts+7545, libc.VaList(bp+736, v286))
				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) {
						v287 = int32(2)
					} else {
						v287 = int32(1)
					}
					rc = _sqlite3BtreeSetVersion(tls, pBt1, v287)
				}
			}
		}
		if rc != 0 {
			eNew = eOld
		}
		eNew = _sqlite3PagerSetJournalMode(tls, pPager, eNew)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(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, int32(int32(encoding)))
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_158:
		;
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 {
			v288 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		} else {
			v288 = uintptr(0)
		}
		rc = _sqlite3RunVacuum(tls, p+124, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, v288)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_159:
		;
		pBt2 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).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 _187
		/* 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.
		 */
	_160:
		;
		if !((*TOp)(unsafe.Pointer(pOp)).Fp1 != 0) {
			_sqlite3ExpirePreparedStatements(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp2)
		} else {
			libc.SetBitFieldPtr16Uint32(p+152, uint32((*TOp)(unsafe.Pointer(pOp)).Fp2+libc.Int32FromInt32(1)), 0, 0x3)
		}
		goto _187
		/* Opcode: CursorLock P1 * * * *
		 **
		 ** Lock the btree to which cursor P1 is pointing so that the btree cannot be
		 ** written by an other cursor.
		 */
	_161:
		;
		pC30 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		_sqlite3BtreeCursorPin(tls, *(*uintptr)(unsafe.Pointer(pC30 + 36)))
		goto _187
		/* Opcode: CursorUnlock P1 * * * *
		 **
		 ** Unlock the btree to which cursor P1 is pointing so that it can be
		 ** written by other cursors.
		 */
	_162:
		;
		pC31 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		_sqlite3BtreeCursorUnpin(tls, *(*uintptr)(unsafe.Pointer(pC31 + 36)))
		goto _187
		/* 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.
		 */
	_163:
		;
		isWriteLock = uint8((*TOp)(unsafe.Pointer(pOp)).Fp3)
		if isWriteLock != 0 || uint64(0) == (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(uint64(libc.Int32FromInt32(0x00004))<<libc.Int32FromInt32(32)) {
			p13 = (*TOp)(unsafe.Pointer(pOp)).Fp1
			rc = _sqlite3BtreeLockTable(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(p13)*16))).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+7597, libc.VaList(bp+736, z1))
				}
				goto abort_due_to_error
			}
		}
		goto _187
		/* 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.
		 */
	_164:
		;
		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 _187
		/* 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.
		 */
	_165:
		; /* Name of the virtual table */
		libc.Xmemset(tls, bp+600, 0, uint32(40))
		(*(*TMem)(unsafe.Pointer(bp + 600))).Fdb = db
		/* Because P2 is always a static string, it is impossible for the
		 ** sqlite3VdbeMemCopy() to fail */
		rc = _sqlite3VdbeMemCopy(tls, bp+600, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40)
		zTab = Xsqlite3_value_text(tls, bp+600)
		if zTab != 0 {
			rc = _sqlite3VtabCallCreate(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, zTab, p+124)
		}
		_sqlite3VdbeMemRelease(tls, bp+600)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* Opcode: VDestroy P1 * * P4 *
		 **
		 ** P4 is the name of a virtual table in database P1.  Call the xDestroy method
		 ** of that table.
		 */
	_166:
		;
		(*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy++
		rc = _sqlite3VtabCallDestroy(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		(*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy--
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_167:
		;
		pCur3 = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 640)) = 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+640)
		_sqlite3VtabImportErrmsg(tls, p, pVtab1)
		if rc != 0 {
			goto abort_due_to_error
		}
		/* Initialize sqlite3_vtab_cursor base class */
		(*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 640)))).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 + 36)) = *(*uintptr)(unsafe.Pointer(bp + 640))
			(*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FnRef++
		} else {
			(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule1)).FxClose})))(tls, *(*uintptr)(unsafe.Pointer(bp + 640)))
			goto no_mem
		}
		goto _187
		/* 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.
		 */
	_168:
		;
		*(*uintptr)(unsafe.Pointer(bp + 644)) = uintptr(0)
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		_sqlite3VdbeMemSetNull(tls, pOut) /* Innocent until proven guilty */
		pTab3 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		if (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 44))).Fp == uintptr(0) {
			goto _187
		}
		pVtab2 = (*TVTable)(unsafe.Pointer((*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 44))).Fp)).FpVtab
		pModule2 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab2)).FpModule
		_sqlite3VtabLock(tls, (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 44))).Fp)
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule2)).FxIntegrity})))(tls, pVtab2, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FzDbSName, (*TTable)(unsafe.Pointer(pTab3)).FzName, (*TOp)(unsafe.Pointer(pOp)).Fp3, bp+644)
		_sqlite3VtabUnlock(tls, (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 44))).Fp)
		if rc != 0 {
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 644)))
			goto abort_due_to_error
		}
		if *(*uintptr)(unsafe.Pointer(bp + 644)) != 0 {
			_sqlite3VdbeMemSetStr(tls, pOut, *(*uintptr)(unsafe.Pointer(bp + 644)), int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
		}
		goto _187
		/* 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().
		 */
	_169:
		; /* New ValueList object to put in reg[P2] */
		pC32 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pRhs = Xsqlite3_malloc64(tls, uint64(8))
		if pRhs == uintptr(0) {
			goto no_mem
		}
		(*TValueList)(unsafe.Pointer(pRhs)).FpCsr = *(*uintptr)(unsafe.Pointer(pC32 + 36))
		(*TValueList)(unsafe.Pointer(pRhs)).FpOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		pOut = _out2Prerelease(tls, p, pOp)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
		_sqlite3VdbeMemSetPointer(tls, pOut, pRhs, __ccgo_ts+7626, __ccgo_fp(_sqlite3VdbeValueListFree))
		goto _187
		/* 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.
		 */
	_170:
		;
		pQuery = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		pArgc = pQuery + 1*40
		pCur4 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pVCur1 = *(*uintptr)(unsafe.Pointer(pCur4 + 36))
		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)(unsafe.Pointer(apArg + uintptr(i6)*4)) = pArgc + uintptr(i6+int32(1))*40
			goto _289
		_289:
			;
			i6++
		}
		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
		}
		res11 = (*(*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 res11 != 0 {
			goto jump_to_p2
		}
		goto _187
		/* 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.
		 */
	_171:
		;
		pCur5 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		pDest2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
		if (*TVdbeCursor)(unsafe.Pointer(pCur5)).FnullRow != 0 {
			_sqlite3VdbeMemSetNull(tls, pDest2)
			goto _187
		}
		pVtab4 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur5 + 36)))).FpVtab
		pModule4 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab4)).FpModule
		libc.Xmemset(tls, bp+648, 0, uint32(32))
		(*(*Tsqlite3_context)(unsafe.Pointer(bp + 648))).FpOut = pDest2
		(*(*Tsqlite3_context)(unsafe.Pointer(bp + 648))).Fenc = encoding
		(*(*TFuncDef)(unsafe.Pointer(bp + 680))).FpUserData = uintptr(0)
		(*(*TFuncDef)(unsafe.Pointer(bp + 680))).FfuncFlags = uint32(SQLITE_RESULT_SUBTYPE)
		(*(*Tsqlite3_context)(unsafe.Pointer(bp + 648))).FpFunc = bp + 680
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NOCHNG) != 0 {
			_sqlite3VdbeMemSetNull(tls, pDest2)
			(*TMem)(unsafe.Pointer(pDest2)).Fflags = uint16(libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Zero))
			*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pDest2)).Fu)) = 0
		} else {
			(*TMem)(unsafe.Pointer(pDest2)).Fflags = uint16(int32((*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 + 36)), bp+648, (*TOp)(unsafe.Pointer(pOp)).Fp2)
		_sqlite3VtabImportErrmsg(tls, p, pVtab4)
		if (*(*Tsqlite3_context)(unsafe.Pointer(bp + 648))).FisError > 0 {
			_sqlite3VdbeError(tls, p, __ccgo_ts+4709, libc.VaList(bp+736, Xsqlite3_value_text(tls, pDest2)))
			rc = (*(*Tsqlite3_context)(unsafe.Pointer(bp + 648))).FisError
		}
		_sqlite3VdbeChangeEncoding(tls, pDest2, int32(int32(encoding)))
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_172:
		;
		pCur6 = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
		if (*TVdbeCursor)(unsafe.Pointer(pCur6)).FnullRow != 0 {
			goto _187
		}
		pVtab5 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur6 + 36)))).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 + 36)))
		_sqlite3VtabImportErrmsg(tls, p, pVtab5)
		if rc != 0 {
			goto abort_due_to_error
		}
		res12 = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule5)).FxEof})))(tls, *(*uintptr)(unsafe.Pointer(pCur6 + 36)))
		if !(res12 != 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.
		 */
	_173:
		;
		isLegacy = int32((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
		*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(SQLITE_LegacyAlter)
		pVtab6 = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
		pName = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		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)(unsafe.Pointer(db + 32)) &= ^libc.Uint64FromInt32(SQLITE_LegacyAlter)
		}
		_sqlite3VtabImportErrmsg(tls, p, pVtab6)
		libc.SetBitFieldPtr16Uint32(p+152, libc.Uint32FromInt32(0), 0, 0x3)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _187
		/* 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.
		 */
	_174:
		;
		*(*Tsqlite_int64)(unsafe.Pointer(bp + 720)) = 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)*40
			i7 = 0
			for {
				if !(i7 < nArg1) {
					break
				}
				*(*uintptr)(unsafe.Pointer(apArg1 + uintptr(i7)*4)) = pX1
				pX1 += 40
				goto _290
			_290:
				;
				i7++
			}
			(*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+720)
			(*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)(unsafe.Pointer(bp + 720))
			}
			if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) && (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FbConstraint != 0 {
				if int32((*TOp)(unsafe.Pointer(pOp)).Fp5) == int32(OE_Ignore) {
					rc = SQLITE_OK
				} else {
					if int32((*TOp)(unsafe.Pointer(pOp)).Fp5) == int32(OE_Replace) {
						v291 = int32(OE_Abort)
					} else {
						v291 = int32((*TOp)(unsafe.Pointer(pOp)).Fp5)
					}
					(*TVdbe)(unsafe.Pointer(p)).FerrorAction = uint8(v291)
				}
			} else {
				(*TVdbe)(unsafe.Pointer(p)).FnChange++
			}
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _187
		/* Opcode: Pagecount P1 P2 * * *
		 **
		 ** Write the current number of pages in database P1 to memory cell P2.
		 */
	_175:
		; /* out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = int64(_sqlite3BtreeLastPage(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpBt))
		goto _187
		/* 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.
		 */
	_176:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		pBt3 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpBt
		newMax = uint32(0)
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			newMax = _sqlite3BtreeLastPage(tls, pBt3)
			if newMax < uint32((*TOp)(unsafe.Pointer(pOp)).Fp3) {
				newMax = uint32((*TOp)(unsafe.Pointer(pOp)).Fp3)
			}
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = int64(_sqlite3BtreeMaxPageCount(tls, pBt3, newMax))
		goto _187
		/* 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
		 */
	_178:
		; /* group */
	_177:
		;
		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)*40
		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 = int32((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fargc) - int32(1)
			for {
				if !(i8 >= 0) {
					break
				}
				*(*uintptr)(unsafe.Pointer(pCtx2 + 28 + uintptr(i8)*4)) = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2+i8)*40
				goto _292
			_292:
				;
				i8--
			}
		}
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*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, int32((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fargc), pCtx2+28) /* 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+4709, libc.VaList(bp+736, Xsqlite3_value_text(tls, pOut)))
				rc = (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError
			}
			_sqlite3VdbeDeleteAuxData(tls, db, p+228, (*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 _187
		/* Opcode: ClrSubtype P1 * * * *
		 ** Synopsis:  r[P1].subtype = 0
		 **
		 ** Clear the subtype from register P1.
		 */
	_179:
		; /* in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		p293 = pIn1 + 16
		*(*Tu16)(unsafe.Pointer(p293)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p293))) & ^libc.Int32FromInt32(MEM_Subtype))
		goto _187
		/* 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.
		 */
	_180:
		; /* in1 out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Subtype) != 0 {
			_sqlite3VdbeMemSetInt64(tls, pOut, int64((*TMem)(unsafe.Pointer(pIn1)).FeSubtype))
		} else {
			_sqlite3VdbeMemSetNull(tls, pOut)
		}
		goto _187
		/* 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.
		 */
	_181:
		; /* in1 out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
		if int32((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) != 0 {
			p294 = pOut + 16
			*(*Tu16)(unsafe.Pointer(p294)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p294))) & ^libc.Int32FromInt32(MEM_Subtype))
		} else {
			p295 = pOut + 16
			*(*Tu16)(unsafe.Pointer(p295)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p295))) | libc.Int32FromInt32(MEM_Subtype))
			(*TMem)(unsafe.Pointer(pOut)).FeSubtype = uint8(*(*Ti64)(unsafe.Pointer(pIn1)) & libc.Int64FromInt32(0xff))
		}
		goto _187
		/* 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].
		 */
	_182:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		h = _filterHash(tls, aMem, pOp)
		h %= uint64((*TMem)(unsafe.Pointer(pIn1)).Fn * libc.Int32FromInt32(8))
		p296 = (*TMem)(unsafe.Pointer(pIn1)).Fz + uintptr(h/uint64(8))
		*(*int8)(unsafe.Pointer(p296)) = int8(int32(*(*int8)(unsafe.Pointer(p296))) | libc.Int32FromInt32(1)<<(h&libc.Uint64FromInt32(7)))
		goto _187
		/* 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.
		 */
	_183:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
		h1 = _filterHash(tls, aMem, pOp)
		h1 %= uint64((*TMem)(unsafe.Pointer(pIn1)).Fn * libc.Int32FromInt32(8))
		if int32(*(*int8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pIn1)).Fz + uintptr(h1/uint64(8)))))&(int32(1)<<(h1&uint64(7))) == 0 {
			*(*Tu32)(unsafe.Pointer(p + 164 + 8*4))++
			goto jump_to_p2
		} else {
			*(*Tu32)(unsafe.Pointer(p + 164 + 7*4))++
		}
		goto _187
		/* 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.
		 */
	_185:
		;
	_184:
		;
		/* 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 v299 = int32((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&(libc.Int32FromInt32(SQLITE_TRACE_STMT)|libc.Int32FromInt32(SQLITE_TRACE_LEGACY)) != 0 && int32((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) != int32(254); v299 {
			if *(*uintptr)(unsafe.Pointer(pOp + 16)) != 0 {
				v298 = *(*uintptr)(unsafe.Pointer(pOp + 16))
			} else {
				v298 = (*TVdbe)(unsafe.Pointer(p)).FzSql
			}
			v297 = v298
			zTrace = v297
		}
		if v299 && v297 != uintptr(0) {
			if int32((*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+7636, libc.VaList(bp+736, 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 int32((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Trace) {
				goto _187
			}
			i9 = int32(1)
			for {
				if !(i9 < (*TVdbe)(unsafe.Pointer(p)).FnOp) {
					break
				}
				if int32((*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i9)*20))).Fopcode) == int32(OP_Once) {
					(*(*TOp)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i9)*20))).Fp1 = 0
				}
				goto _300
			_300:
				;
				i9++
			}
			(*TOp)(unsafe.Pointer(pOp)).Fp1 = 0
		}
		(*TOp)(unsafe.Pointer(pOp)).Fp1++
		*(*Tu32)(unsafe.Pointer(p + 164 + 6*4))++
		goto jump_to_p2
		/* Opcode: Noop * * * * *
		 **
		 ** Do nothing.  This instruction is often useful as a jump
		 ** destination.
		 */
		/*
		 ** The magic Explain opcode are only inserted when explain==2 (which
		 ** is to say when the EXPLAIN QUERY PLAN syntax is used.)
		 ** This opcode records information from the optimizer.  It is the
		 ** the same as a no-op.  This opcodesnever appears in a real VM program.
		 */
	_186:
		; /* This is really OP_Noop, OP_Explain */
		goto _187
		/*****************************************************************************
		 ** 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.
		 *****************************************************************************/
	_187:
		;
		/* 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 += 20
	} /* 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(102187))
		}
	}
	if (*TVdbe)(unsafe.Pointer(p)).FzErrMsg == uintptr(0) && rc != libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
		_sqlite3VdbeError(tls, p, __ccgo_ts+4709, libc.VaList(bp+736, _sqlite3ErrStr(tls, rc)))
	}
	(*TVdbe)(unsafe.Pointer(p)).Frc = rc
	_sqlite3SystemError(tls, db, rc)
	Xsqlite3_log(tls, rc, __ccgo_ts+7642, libc.VaList(bp+736, (int32(int32(pOp))-int32(int32(aOp)))/20, (*TVdbe)(unsafe.Pointer(p)).FzSql, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg))
	if int32((*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) && int32((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
		*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(libc.Int32FromInt32(0x00002)) << libc.Int32FromInt32(32)
	}
	rc = int32(SQLITE_ERROR)
	if int32(int32(resetSchemaOnFault)) > 0 {
		_sqlite3ResetOneSchema(tls, db, int32(int32(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 += 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)(unsafe.Pointer(p + 164 + 4*4)) += uint32(int32(int32(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+6796, 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+1642, 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
}

var _azType = [4]uintptr{
	0: __ccgo_ts + 6953,
	1: __ccgo_ts + 6962,
	2: __ccgo_ts + 6969,
	3: __ccgo_ts + 6975,
}

var _and_logic = [9]uint8{
	4: uint8(1),
	5: uint8(2),
	7: uint8(2),
	8: uint8(2),
}

var _or_logic = [9]uint8{
	1: uint8(1),
	2: uint8(2),
	3: uint8(1),
	4: uint8(1),
	5: uint8(1),
	6: uint8(2),
	7: uint8(1),
	8: uint8(2),
}

var _aMask = [12]uint8{
	0:  uint8(0x10),
	1:  uint8(0x01),
	2:  uint8(0x01),
	3:  uint8(0x01),
	4:  uint8(0x01),
	5:  uint8(0x01),
	6:  uint8(0x01),
	7:  uint8(0x2),
	8:  uint8(0x01),
	9:  uint8(0x01),
	10: uint8(0x10),
	11: uint8(0x10),
}

/* If the column value is a string, we need a persistent value, not
 ** a MEM_Ephem value.  This branch is a fast short-cut that is equivalent
 ** to calling sqlite3VdbeSerialGet() and sqlite3VdbeDeephemeralize().
 */
var _aFlag1 = [2]Tu16{
	0: uint16(MEM_Blob),
	1: uint16(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Term)),
}

var _vfsFlags = libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE) | libc.Int32FromInt32(SQLITE_OPEN_TRANSIENT_DB)

/************** End of vdbe.c ************************************************/
/************** Begin file vdbeblob.c ****************************************/
/*
** 2007 May 1
**
** 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 incremental BLOB I/O.
 */

/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */

// C documentation
//
//	/*
//	** Valid sqlite3_blob* handles point to Incrblob structures.
//	*/
type TIncrblob = struct {
	FnByte   int32
	FiOffset int32
	FiCol    Tu16
	FpCsr    uintptr
	FpStmt   uintptr
	Fdb      uintptr
	FzDb     uintptr
	FpTab    uintptr
}

type Incrblob = TIncrblob

type TIncrblob1 = struct {
	FnByte   int32
	FiOffset int32
	FiCol    Tu16
	FpCsr    uintptr
	FpStmt   uintptr
	Fdb      uintptr
	FzDb     uintptr
	FpTab    uintptr
}

type Incrblob1 = TIncrblob1

// C documentation
//
//	/*
//	** This function is used by both blob_open() and blob_reopen(). It seeks
//	** the b-tree cursor associated with blob handle p to point to row iRow.
//	** If successful, SQLITE_OK is returned and subsequent calls to
//	** sqlite3_blob_read() or sqlite3_blob_write() access the specified row.
//	**
//	** If an error occurs, or if the specified row does not exist or does not
//	** contain a value of type TEXT or BLOB in the column nominated when the
//	** blob handle was opened, then an error code is returned and *pzErr may
//	** be set to point to a buffer containing an error message. It is the
//	** responsibility of the caller to free the error message buffer using
//	** sqlite3DbFree().
//	**
//	** If an error does occur, then the b-tree cursor is closed. All subsequent
//	** calls to sqlite3_blob_read(), blob_write() or blob_reopen() will
//	** immediately return SQLITE_ABORT.
//	*/
func _blobSeekToRow(tls *libc.TLS, p uintptr, iRow Tsqlite3_int64, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pC, v, zErr, v2, v3 uintptr
	var rc int32
	var type1 Tu32
	var v1 uint32
	_, _, _, _, _, _, _, _ = pC, rc, type1, v, zErr, v1, v2, v3 /* Error code */
	zErr = uintptr(0)                                           /* Error message */
	v = (*TIncrblob)(unsafe.Pointer(p)).FpStmt
	/* Set the value of register r[1] in the SQL statement to integer iRow.
	 ** This is done directly as a performance optimization
	 */
	_sqlite3VdbeMemSetInt64(tls, (*TVdbe)(unsafe.Pointer(v)).FaMem+1*40, iRow)
	/* If the statement has been run before (and is paused at the OP_ResultRow)
	 ** then back it up to the point where it does the OP_NotExists.  This could
	 ** have been down with an extra OP_Goto, but simply setting the program
	 ** counter is faster. */
	if (*TVdbe)(unsafe.Pointer(v)).Fpc > int32(4) {
		(*TVdbe)(unsafe.Pointer(v)).Fpc = int32(4)
		rc = _sqlite3VdbeExec(tls, v)
	} else {
		rc = Xsqlite3_step(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
	}
	if rc == int32(SQLITE_ROW) {
		pC = *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).FapCsr))
		if int32((*TVdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed) > int32((*TIncrblob)(unsafe.Pointer(p)).FiCol) {
			v1 = *(*Tu32)(unsafe.Pointer(pC + 84 + uintptr((*TIncrblob)(unsafe.Pointer(p)).FiCol)*4))
		} else {
			v1 = uint32(0)
		}
		type1 = v1
		if type1 < uint32(12) {
			if type1 == uint32(0) {
				v2 = __ccgo_ts + 1658
			} else {
				if type1 == uint32(7) {
					v3 = __ccgo_ts + 7674
				} else {
					v3 = __ccgo_ts + 7679
				}
				v2 = v3
			}
			zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+7687, libc.VaList(bp+8, v2))
			rc = int32(SQLITE_ERROR)
			Xsqlite3_finalize(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
			(*TIncrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
		} else {
			(*TIncrblob)(unsafe.Pointer(p)).FiOffset = int32(*(*Tu32)(unsafe.Pointer(pC + 84 + uintptr(int32((*TIncrblob)(unsafe.Pointer(p)).FiCol)+int32((*TVdbeCursor)(unsafe.Pointer(pC)).FnField))*4)))
			(*TIncrblob)(unsafe.Pointer(p)).FnByte = int32(_sqlite3VdbeSerialTypeLen(tls, type1))
			(*TIncrblob)(unsafe.Pointer(p)).FpCsr = *(*uintptr)(unsafe.Pointer(pC + 36))
			_sqlite3BtreeIncrblobCursor(tls, (*TIncrblob)(unsafe.Pointer(p)).FpCsr)
		}
	}
	if rc == int32(SQLITE_ROW) {
		rc = SQLITE_OK
	} else {
		if (*TIncrblob)(unsafe.Pointer(p)).FpStmt != 0 {
			rc = Xsqlite3_finalize(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
			(*TIncrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
			if rc == SQLITE_OK {
				zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+7716, libc.VaList(bp+8, iRow))
				rc = int32(SQLITE_ERROR)
			} else {
				zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb)))
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = zErr
	return rc
}

// C documentation
//
//	/*
//	** Open a blob handle.
//	*/
func Xsqlite3_blob_open(tls *libc.TLS, db uintptr, zDb uintptr, zTable uintptr, zColumn uintptr, iRow Tsqlite_int64, wrFlag int32, ppBlob uintptr) (r int32) {
	bp := tls.Alloc(304)
	defer tls.Free(304)
	var aOp, pBlob, pFKey, pIdx, pTab, v, zFault, v7 uintptr
	var iCol, iDb, j, j1, nAttempt, rc, v6 int32
	var _ /* sParse at bp+4 */ TParse
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aOp, iCol, iDb, j, j1, nAttempt, pBlob, pFKey, pIdx, pTab, rc, v, zFault, v6, v7
	nAttempt = 0 /* Index of zColumn in row-record */
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pBlob = uintptr(0)
	*(*uintptr)(unsafe.Pointer(ppBlob)) = uintptr(0)
	wrFlag = libc.BoolInt32(!!(wrFlag != 0)) /* wrFlag = (wrFlag ? 1 : 0); */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pBlob = _sqlite3DbMallocZero(tls, db, uint64(32))
	for int32(1) != 0 {
		_sqlite3ParseObjectInit(tls, bp+4, db)
		if !(pBlob != 0) {
			goto blob_open_out
		}
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		_sqlite3BtreeEnterAll(tls, db)
		pTab = _sqlite3LocateTable(tls, bp+4, uint32(0), zTable, zDb)
		if pTab != 0 && int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			pTab = uintptr(0)
			_sqlite3ErrorMsg(tls, bp+4, __ccgo_ts+7736, libc.VaList(bp+296, zTable))
		}
		if pTab != 0 && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			pTab = uintptr(0)
			_sqlite3ErrorMsg(tls, bp+4, __ccgo_ts+7766, libc.VaList(bp+296, zTable))
		}
		if pTab != 0 && int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			pTab = uintptr(0)
			_sqlite3ErrorMsg(tls, bp+4, __ccgo_ts+7802, libc.VaList(bp+296, zTable))
		}
		if !(pTab != 0) {
			if (*(*TParse)(unsafe.Pointer(bp + 4))).FzErrMsg != 0 {
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
				*(*uintptr)(unsafe.Pointer(bp)) = (*(*TParse)(unsafe.Pointer(bp + 4))).FzErrMsg
				(*(*TParse)(unsafe.Pointer(bp + 4))).FzErrMsg = uintptr(0)
			}
			rc = int32(SQLITE_ERROR)
			_sqlite3BtreeLeaveAll(tls, db)
			goto blob_open_out
		}
		(*TIncrblob)(unsafe.Pointer(pBlob)).FpTab = pTab
		(*TIncrblob)(unsafe.Pointer(pBlob)).FzDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(_sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema))*16))).FzDbSName
		/* Now search pTab for the exact column. */
		iCol = 0
		for {
			if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if _sqlite3StrICmp(tls, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName, zColumn) == 0 {
				break
			}
			goto _1
		_1:
			;
			iCol++
		}
		if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
			_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
			*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+7823, libc.VaList(bp+296, zColumn))
			rc = int32(SQLITE_ERROR)
			_sqlite3BtreeLeaveAll(tls, db)
			goto blob_open_out
		}
		/* If the value is being opened for writing, check that the
		 ** column is not indexed, and that it is not part of a foreign key.
		 */
		if wrFlag != 0 {
			zFault = uintptr(0)
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 {
				pFKey = (*(*struct {
					FaddColOffset int32
					FpFKey        uintptr
					FpDfltList    uintptr
				})(unsafe.Pointer(pTab + 44))).FpFKey
				for {
					if !(pFKey != 0) {
						break
					}
					j = 0
					for {
						if !(j < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
							break
						}
						if (*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(j)*8))).FiFrom == iCol {
							zFault = __ccgo_ts + 7844
						}
						goto _3
					_3:
						;
						j++
					}
					goto _2
				_2:
					;
					pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
				}
			}
			pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
			for {
				if !(pIdx != 0) {
					break
				}
				j1 = 0
				for {
					if !(j1 < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
						break
					}
					/* FIXME: Be smarter about indexes that use expressions */
					if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == iCol || int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == -int32(2) {
						zFault = __ccgo_ts + 7856
					}
					goto _5
				_5:
					;
					j1++
				}
				goto _4
			_4:
				;
				pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
			}
			if zFault != 0 {
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
				*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+7864, libc.VaList(bp+296, zFault))
				rc = int32(SQLITE_ERROR)
				_sqlite3BtreeLeaveAll(tls, db)
				goto blob_open_out
			}
		}
		(*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt = _sqlite3VdbeCreate(tls, bp+4)
		if (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt != 0 {
			v = (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt
			iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Transaction), iDb, wrFlag, (*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpSchema)).Fschema_cookie, (*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpSchema)).FiGeneration)
			_sqlite3VdbeChangeP5(tls, v, uint16(1))
			aOp = _sqlite3VdbeAddOpList(tls, v, int32(libc.Uint32FromInt64(24)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_openBlob)), _iLn)
			/* Make sure a mutex is held on the table to be accessed */
			_sqlite3VdbeUsesBtree(tls, v, iDb)
			if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
				/* Configure the OP_TableLock instruction */
				(*(*TVdbeOp)(unsafe.Pointer(aOp))).Fp1 = iDb
				(*(*TVdbeOp)(unsafe.Pointer(aOp))).Fp2 = int32((*TTable)(unsafe.Pointer(pTab)).Ftnum)
				(*(*TVdbeOp)(unsafe.Pointer(aOp))).Fp3 = wrFlag
				_sqlite3VdbeChangeP4(tls, v, int32(2), (*TTable)(unsafe.Pointer(pTab)).FzName, P4_TRANSIENT)
			}
			if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
				/* Remove either the OP_OpenWrite or OpenRead. Set the P2
				 ** parameter of the other to pTab->tnum.  */
				if wrFlag != 0 {
					(*(*TVdbeOp)(unsafe.Pointer(aOp + 1*20))).Fopcode = uint8(OP_OpenWrite)
				}
				(*(*TVdbeOp)(unsafe.Pointer(aOp + 1*20))).Fp2 = int32((*TTable)(unsafe.Pointer(pTab)).Ftnum)
				(*(*TVdbeOp)(unsafe.Pointer(aOp + 1*20))).Fp3 = iDb
				/* Configure the number of columns. Configure the cursor to
				 ** think that the table has one more column than it really
				 ** does. An OP_Column to retrieve this imaginary column will
				 ** always return an SQL NULL. This is useful because it means
				 ** we can invoke OP_Column to fill in the vdbe cursors type
				 ** and offset cache without causing any IO.
				 */
				(*(*TVdbeOp)(unsafe.Pointer(aOp + 1*20))).Fp4type = int8(-libc.Int32FromInt32(3))
				*(*int32)(unsafe.Pointer(aOp + 1*20 + 16)) = int32((*TTable)(unsafe.Pointer(pTab)).FnCol) + int32(1)
				(*(*TVdbeOp)(unsafe.Pointer(aOp + 3*20))).Fp2 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
				(*(*TParse)(unsafe.Pointer(bp + 4))).FnVar = 0
				(*(*TParse)(unsafe.Pointer(bp + 4))).FnMem = int32(1)
				(*(*TParse)(unsafe.Pointer(bp + 4))).FnTab = int32(1)
				_sqlite3VdbeMakeReady(tls, v, bp+4)
			}
		}
		(*TIncrblob)(unsafe.Pointer(pBlob)).FiCol = uint16(uint16(iCol))
		(*TIncrblob)(unsafe.Pointer(pBlob)).Fdb = db
		_sqlite3BtreeLeaveAll(tls, db)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto blob_open_out
		}
		rc = _blobSeekToRow(tls, pBlob, iRow, bp)
		nAttempt++
		v6 = nAttempt
		if v6 >= int32(SQLITE_MAX_SCHEMA_RETRY) || rc != int32(SQLITE_SCHEMA) {
			break
		}
		_sqlite3ParseObjectReset(tls, bp+4)
	}
	goto blob_open_out
blob_open_out:
	;
	if rc == SQLITE_OK && int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		*(*uintptr)(unsafe.Pointer(ppBlob)) = pBlob
	} else {
		if pBlob != 0 && (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt != 0 {
			_sqlite3VdbeFinalize(tls, (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt)
		}
		_sqlite3DbFree(tls, db, pBlob)
	}
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		v7 = __ccgo_ts + 4709
	} else {
		v7 = libc.UintptrFromInt32(0)
	}
	_sqlite3ErrorWithMsg(tls, db, rc, v7, libc.VaList(bp+296, *(*uintptr)(unsafe.Pointer(bp))))
	_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
	_sqlite3ParseObjectReset(tls, bp+4)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

/* This VDBE program seeks a btree cursor to the identified
 ** db/table/row entry. The reason for using a vdbe program instead
 ** of writing code to use the b-tree layer directly is that the
 ** vdbe program will take advantage of the various transaction,
 ** locking and error handling infrastructure built into the vdbe.
 **
 ** After seeking the cursor, the vdbe executes an OP_ResultRow.
 ** Code external to the Vdbe then "borrows" the b-tree cursor and
 ** uses it to implement the blob_read(), blob_write() and
 ** blob_bytes() functions.
 **
 ** The sqlite3_blob_close() function finalizes the vdbe program,
 ** which closes the b-tree cursor and (possibly) commits the
 ** transaction.
 */
var _iLn int32

var _openBlob = [6]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_TableLock),
	},
	1: {
		Fopcode: uint8(OP_OpenRead),
	},
	2: {
		Fopcode: uint8(OP_NotExists),
		Fp2:     int8(5),
		Fp3:     int8(1),
	},
	3: {
		Fopcode: uint8(OP_Column),
		Fp3:     int8(1),
	},
	4: {
		Fopcode: uint8(OP_ResultRow),
		Fp1:     int8(1),
	},
	5: {
		Fopcode: uint8(OP_Halt),
	},
}

// C documentation
//
//	/*
//	** Close a blob handle that was previously created using
//	** sqlite3_blob_open().
//	*/
func Xsqlite3_blob_close(tls *libc.TLS, pBlob uintptr) (r int32) {
	var db, p, pStmt uintptr
	var rc int32
	_, _, _, _ = db, p, pStmt, rc
	p = pBlob
	if p != 0 {
		pStmt = (*TIncrblob)(unsafe.Pointer(p)).FpStmt
		db = (*TIncrblob)(unsafe.Pointer(p)).Fdb
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		_sqlite3DbFree(tls, db, p)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		rc = Xsqlite3_finalize(tls, pStmt)
	} else {
		rc = SQLITE_OK
	}
	return rc
}

// C documentation
//
//	/*
//	** Perform a read or write operation on a blob
//	*/
func _blobReadWrite(tls *libc.TLS, pBlob uintptr, z uintptr, n int32, iOffset int32, xCall uintptr) (r int32) {
	var db, p, v uintptr
	var iKey Tsqlite3_int64
	var rc int32
	_, _, _, _, _ = db, iKey, p, rc, v
	p = pBlob
	if p == uintptr(0) {
		return _sqlite3MisuseError(tls, int32(102671))
	}
	db = (*TIncrblob)(unsafe.Pointer(p)).Fdb
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	v = (*TIncrblob)(unsafe.Pointer(p)).FpStmt
	if n < 0 || iOffset < 0 || int64(int64(iOffset))+int64(int64(n)) > int64((*TIncrblob)(unsafe.Pointer(p)).FnByte) {
		/* Request is out of range. Return a transient error. */
		rc = int32(SQLITE_ERROR)
	} else {
		if v == uintptr(0) {
			/* If there is no statement handle, then the blob-handle has
			 ** already been invalidated. Return SQLITE_ABORT in this case.
			 */
			rc = int32(SQLITE_ABORT)
		} else {
			/* Call either BtreeData() or BtreePutData(). If SQLITE_ABORT is
			 ** returned, clean-up the statement handle.
			 */
			_sqlite3BtreeEnterCursor(tls, (*TIncrblob)(unsafe.Pointer(p)).FpCsr)
			if xCall == __ccgo_fp(_sqlite3BtreePutData) && (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
				iKey = _sqlite3BtreeIntegerKey(tls, (*TIncrblob)(unsafe.Pointer(p)).FpCsr)
				_sqlite3VdbePreUpdateHook(tls, v, *(*uintptr)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).FapCsr)), int32(SQLITE_DELETE), (*TIncrblob)(unsafe.Pointer(p)).FzDb, (*TIncrblob)(unsafe.Pointer(p)).FpTab, iKey, -int32(1), int32((*TIncrblob)(unsafe.Pointer(p)).FiCol))
			}
			rc = (*(*func(*libc.TLS, uintptr, Tu32, Tu32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xCall})))(tls, (*TIncrblob)(unsafe.Pointer(p)).FpCsr, uint32(iOffset+(*TIncrblob)(unsafe.Pointer(p)).FiOffset), uint32(uint32(n)), z)
			_sqlite3BtreeLeaveCursor(tls, (*TIncrblob)(unsafe.Pointer(p)).FpCsr)
			if rc == int32(SQLITE_ABORT) {
				_sqlite3VdbeFinalize(tls, v)
				(*TIncrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
			} else {
				(*TVdbe)(unsafe.Pointer(v)).Frc = rc
			}
		}
	}
	_sqlite3Error(tls, db, rc)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Read data from a blob handle.
//	*/
func Xsqlite3_blob_read(tls *libc.TLS, pBlob uintptr, z uintptr, n int32, iOffset int32) (r int32) {
	return _blobReadWrite(tls, pBlob, z, n, iOffset, __ccgo_fp(_sqlite3BtreePayloadChecked))
}

// C documentation
//
//	/*
//	** Write data to a blob handle.
//	*/
func Xsqlite3_blob_write(tls *libc.TLS, pBlob uintptr, z uintptr, n int32, iOffset int32) (r int32) {
	return _blobReadWrite(tls, pBlob, z, n, iOffset, __ccgo_fp(_sqlite3BtreePutData))
}

// C documentation
//
//	/*
//	** Query a blob handle for the size of the data.
//	**
//	** The Incrblob.nByte field is fixed for the lifetime of the Incrblob
//	** so no mutex is required for access.
//	*/
func Xsqlite3_blob_bytes(tls *libc.TLS, pBlob uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = pBlob
	if p != 0 && (*TIncrblob)(unsafe.Pointer(p)).FpStmt != 0 {
		v1 = (*TIncrblob)(unsafe.Pointer(p)).FnByte
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Move an existing blob handle to point to a different row of the same
//	** database table.
//	**
//	** If an error occurs, or if the specified row does not exist or does not
//	** contain a blob or text value, then an error code is returned and the
//	** database handle error code and message set. If this happens, then all
//	** subsequent calls to sqlite3_blob_xxx() functions (except blob_close())
//	** immediately return SQLITE_ABORT.
//	*/
func Xsqlite3_blob_reopen(tls *libc.TLS, pBlob uintptr, iRow Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, v1 uintptr
	var rc int32
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _ = db, p, rc, v1
	p = pBlob
	if p == uintptr(0) {
		return _sqlite3MisuseError(tls, int32(102771))
	}
	db = (*TIncrblob)(unsafe.Pointer(p)).Fdb
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*TIncrblob)(unsafe.Pointer(p)).FpStmt == uintptr(0) {
		/* If there is no statement handle, then the blob-handle has
		 ** already been invalidated. Return SQLITE_ABORT in this case.
		 */
		rc = int32(SQLITE_ABORT)
	} else {
		(*TVdbe)(unsafe.Pointer((*TIncrblob)(unsafe.Pointer(p)).FpStmt)).Frc = SQLITE_OK
		rc = _blobSeekToRow(tls, p, iRow, bp)
		if rc != SQLITE_OK {
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				v1 = __ccgo_ts + 4709
			} else {
				v1 = libc.UintptrFromInt32(0)
			}
			_sqlite3ErrorWithMsg(tls, db, rc, v1, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp))))
			_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

/************** End of vdbeblob.c ********************************************/
/************** Begin file vdbesort.c ****************************************/
/*
** 2011-07-09
**
** 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 for the VdbeSorter object, used in concert with
** a VdbeCursor to sort large numbers of keys for CREATE INDEX statements
** or by SELECT statements with ORDER BY clauses that cannot be satisfied
** using indexes and without LIMIT clauses.
**
** The VdbeSorter object implements a multi-threaded external merge sort
** algorithm that is efficient even if the number of elements being sorted
** exceeds the available memory.
**
** Here is the (internal, non-API) interface between this module and the
** rest of the SQLite system:
**
**    sqlite3VdbeSorterInit()       Create a new VdbeSorter object.
**
**    sqlite3VdbeSorterWrite()      Add a single new row to the VdbeSorter
**                                  object.  The row is a binary blob in the
**                                  OP_MakeRecord format that contains both
**                                  the ORDER BY key columns and result columns
**                                  in the case of a SELECT w/ ORDER BY, or
**                                  the complete record for an index entry
**                                  in the case of a CREATE INDEX.
**
**    sqlite3VdbeSorterRewind()     Sort all content previously added.
**                                  Position the read cursor on the
**                                  first sorted element.
**
**    sqlite3VdbeSorterNext()       Advance the read cursor to the next sorted
**                                  element.
**
**    sqlite3VdbeSorterRowkey()     Return the complete binary blob for the
**                                  row currently under the read cursor.
**
**    sqlite3VdbeSorterCompare()    Compare the binary blob for the row
**                                  currently under the read cursor against
**                                  another binary blob X and report if
**                                  X is strictly less than the read cursor.
**                                  Used to enforce uniqueness in a
**                                  CREATE UNIQUE INDEX statement.
**
**    sqlite3VdbeSorterClose()      Close the VdbeSorter object and reclaim
**                                  all resources.
**
**    sqlite3VdbeSorterReset()      Refurbish the VdbeSorter for reuse.  This
**                                  is like Close() followed by Init() only
**                                  much faster.
**
** The interfaces above must be called in a particular order.  Write() can
** only occur in between Init()/Reset() and Rewind().  Next(), Rowkey(), and
** Compare() can only occur in between Rewind() and Close()/Reset(). i.e.
**
**   Init()
**   for each record: Write()
**   Rewind()
**     Rowkey()/Compare()
**   Next()
**   Close()
**
** Algorithm:
**
** Records passed to the sorter via calls to Write() are initially held
** unsorted in main memory. Assuming the amount of memory used never exceeds
** a threshold, when Rewind() is called the set of records is sorted using
** an in-memory merge sort. In this case, no temporary files are required
** and subsequent calls to Rowkey(), Next() and Compare() read records
** directly from main memory.
**
** If the amount of space used to store records in main memory exceeds the
** threshold, then the set of records currently in memory are sorted and
** written to a temporary file in "Packed Memory Array" (PMA) format.
** A PMA created at this point is known as a "level-0 PMA". Higher levels
** of PMAs may be created by merging existing PMAs together - for example
** merging two or more level-0 PMAs together creates a level-1 PMA.
**
** The threshold for the amount of main memory to use before flushing
** records to a PMA is roughly the same as the limit configured for the
** page-cache of the main database. Specifically, the threshold is set to
** the value returned by "PRAGMA main.page_size" multiplied by
** that returned by "PRAGMA main.cache_size", in bytes.
**
** If the sorter is running in single-threaded mode, then all PMAs generated
** are appended to a single temporary file. Or, if the sorter is running in
** multi-threaded mode then up to (N+1) temporary files may be opened, where
** N is the configured number of worker threads. In this case, instead of
** sorting the records and writing the PMA to a temporary file itself, the
** calling thread usually launches a worker thread to do so. Except, if
** there are already N worker threads running, the main thread does the work
** itself.
**
** The sorter is running in multi-threaded mode if (a) the library was built
** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
** than zero, and (b) worker threads have been enabled at runtime by calling
** "PRAGMA threads=N" with some value of N greater than 0.
**
** When Rewind() is called, any data remaining in memory is flushed to a
** final PMA. So at this point the data is stored in some number of sorted
** PMAs within temporary files on disk.
**
** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the
** sorter is running in single-threaded mode, then these PMAs are merged
** incrementally as keys are retrieved from the sorter by the VDBE.  The
** MergeEngine object, described in further detail below, performs this
** merge.
**
** Or, if running in multi-threaded mode, then a background thread is
** launched to merge the existing PMAs. Once the background thread has
** merged T bytes of data into a single sorted PMA, the main thread
** begins reading keys from that PMA while the background thread proceeds
** with merging the next T bytes of data. And so on.
**
** Parameter T is set to half the value of the memory threshold used
** by Write() above to determine when to create a new PMA.
**
** If there are more than SORTER_MAX_MERGE_COUNT PMAs in total when
** Rewind() is called, then a hierarchy of incremental-merges is used.
** First, T bytes of data from the first SORTER_MAX_MERGE_COUNT PMAs on
** disk are merged together. Then T bytes of data from the second set, and
** so on, such that no operation ever merges more than SORTER_MAX_MERGE_COUNT
** PMAs at a time. This done is to improve locality.
**
** If running in multi-threaded mode and there are more than
** SORTER_MAX_MERGE_COUNT PMAs on disk when Rewind() is called, then more
** than one background thread may be created. Specifically, there may be
** one background thread for each temporary file on disk, and one background
** thread to merge the output of each of the others to a single PMA for
** the main thread to read from.
 */
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */

/*
** If SQLITE_DEBUG_SORTER_THREADS is defined, this module outputs various
** messages to stderr that may be helpful in understanding the performance
** characteristics of the sorter in multi-threaded mode.
 */

/*
** Hard-coded maximum amount of data to accumulate in memory before flushing
** to a level 0 PMA. The purpose of this limit is to prevent various integer
** overflows. 512MiB.
 */

// C documentation
//
//	/*
//	** Private objects used by the sorter
//	*/
type TMergeEngine = struct {
	FnTree  int32
	FpTask  uintptr
	FaTree  uintptr
	FaReadr uintptr
}

type MergeEngine = TMergeEngine

/* Merge PMAs together */
type TPmaReader = struct {
	F__ccgo_align [0]uint32
	FiReadOff     Ti64
	FiEof         Ti64
	FnAlloc       int32
	FnKey         int32
	FpFd          uintptr
	FaAlloc       uintptr
	FaKey         uintptr
	FaBuffer      uintptr
	FnBuffer      int32
	FaMap         uintptr
	FpIncr        uintptr
	F__ccgo_pad11 [4]byte
}

type PmaReader = TPmaReader

/* Incrementally read one PMA */
type TPmaWriter = struct {
	F__ccgo_align  [0]uint32
	FeFWErr        int32
	FaBuffer       uintptr
	FnBuffer       int32
	FiBufStart     int32
	FiBufEnd       int32
	F__ccgo_align5 [4]byte
	FiWriteOff     Ti64
	FpFd           uintptr
	F__ccgo_pad7   [4]byte
}

type PmaWriter = TPmaWriter

/* Incrementally write one PMA */
type TSorterRecord = struct {
	FnVal int32
	Fu    struct {
		FiNext [0]int32
		FpNext uintptr
	}
}

type SorterRecord = TSorterRecord

/* A record being sorted */
type TSortSubtask = struct {
	F__ccgo_align  [0]uint32
	FpThread       uintptr
	FbDone         int32
	FnPMA          int32
	FpSorter       uintptr
	FpUnpacked     uintptr
	F__ccgo_align5 [4]byte
	Flist          TSorterList
	FxCompare      TSorterCompare
	F__ccgo_align7 [4]byte
	Ffile          TSorterFile
	Ffile2         TSorterFile
}

type SortSubtask = TSortSubtask

/* A sub-task in the sort process */
type TSorterFile = struct {
	F__ccgo_align  [0]uint32
	FpFd           uintptr
	F__ccgo_align1 [4]byte
	FiEof          Ti64
}

type SorterFile = TSorterFile

/* Temporary file object wrapper */
type TSorterList = struct {
	F__ccgo_align [0]uint32
	FpList        uintptr
	FaMemory      uintptr
	FszPMA        Ti64
}

type SorterList = TSorterList

/* In-memory list of records */
type TIncrMerger = struct {
	F__ccgo_align  [0]uint32
	FpTask         uintptr
	FpMerger       uintptr
	FiStartOff     Ti64
	FmxSz          int32
	FbEof          int32
	FbUseThread    int32
	F__ccgo_align6 [4]byte
	FaFile         [2]TSorterFile
}

type IncrMerger = TIncrMerger

/* Read & merge multiple PMAs */

/*
** A container for a temp file handle and the current amount of data
** stored in the file.
 */
type TSorterFile1 = struct {
	F__ccgo_align  [0]uint32
	FpFd           uintptr
	F__ccgo_align1 [4]byte
	FiEof          Ti64
}

type SorterFile1 = TSorterFile1

/*
** An in-memory list of objects to be sorted.
**
** If aMemory==0 then each object is allocated separately and the objects
** are connected using SorterRecord.u.pNext.  If aMemory!=0 then all objects
** are stored in the aMemory[] bulk memory, one right after the other, and
** are connected using SorterRecord.u.iNext.
 */
type TSorterList1 = struct {
	F__ccgo_align [0]uint32
	FpList        uintptr
	FaMemory      uintptr
	FszPMA        Ti64
}

type SorterList1 = TSorterList1

/*
** The MergeEngine object is used to combine two or more smaller PMAs into
** one big PMA using a merge operation.  Separate PMAs all need to be
** combined into one big PMA in order to be able to step through the sorted
** records in order.
**
** The aReadr[] array contains a PmaReader object for each of the PMAs being
** merged.  An aReadr[] object either points to a valid key or else is at EOF.
** ("EOF" means "End Of File".  When aReadr[] is at EOF there is no more data.)
** For the purposes of the paragraphs below, we assume that the array is
** actually N elements in size, where N is the smallest power of 2 greater
** to or equal to the number of PMAs being merged. The extra aReadr[] elements
** are treated as if they are empty (always at EOF).
**
** The aTree[] array is also N elements in size. The value of N is stored in
** the MergeEngine.nTree variable.
**
** The final (N/2) elements of aTree[] contain the results of comparing
** pairs of PMA keys together. Element i contains the result of
** comparing aReadr[2*i-N] and aReadr[2*i-N+1]. Whichever key is smaller, the
** aTree element is set to the index of it.
**
** For the purposes of this comparison, EOF is considered greater than any
** other key value. If the keys are equal (only possible with two EOF
** values), it doesn't matter which index is stored.
**
** The (N/4) elements of aTree[] that precede the final (N/2) described
** above contains the index of the smallest of each block of 4 PmaReaders
** And so on. So that aTree[1] contains the index of the PmaReader that
** currently points to the smallest key value. aTree[0] is unused.
**
** Example:
**
**     aReadr[0] -> Banana
**     aReadr[1] -> Feijoa
**     aReadr[2] -> Elderberry
**     aReadr[3] -> Currant
**     aReadr[4] -> Grapefruit
**     aReadr[5] -> Apple
**     aReadr[6] -> Durian
**     aReadr[7] -> EOF
**
**     aTree[] = { X, 5   0, 5    0, 3, 5, 6 }
**
** The current element is "Apple" (the value of the key indicated by
** PmaReader 5). When the Next() operation is invoked, PmaReader 5 will
** be advanced to the next key in its segment. Say the next key is
** "Eggplant":
**
**     aReadr[5] -> Eggplant
**
** The contents of aTree[] are updated first by comparing the new PmaReader
** 5 key to the current key of PmaReader 4 (still "Grapefruit"). The PmaReader
** 5 value is still smaller, so aTree[6] is set to 5. And so on up the tree.
** The value of PmaReader 6 - "Durian" - is now smaller than that of PmaReader
** 5, so aTree[3] is set to 6. Key 0 is smaller than key 6 (Banana<Durian),
** so the value written into element 1 of the array is 0. As follows:
**
**     aTree[] = { X, 0   0, 6    0, 3, 5, 6 }
**
** In other words, each time we advance to the next sorter element, log2(N)
** key comparison operations are required, where N is the number of segments
** being merged (rounded up to the next power of 2).
 */
type TMergeEngine1 = struct {
	FnTree  int32
	FpTask  uintptr
	FaTree  uintptr
	FaReadr uintptr
}

type MergeEngine1 = TMergeEngine1

// C documentation
//
//	/*
//	** This object represents a single thread of control in a sort operation.
//	** Exactly VdbeSorter.nTask instances of this object are allocated
//	** as part of each VdbeSorter object. Instances are never allocated any
//	** other way. VdbeSorter.nTask is set to the number of worker threads allowed
//	** (see SQLITE_CONFIG_WORKER_THREADS) plus one (the main thread).  Thus for
//	** single-threaded operation, there is exactly one instance of this object
//	** and for multi-threaded operation there are two or more instances.
//	**
//	** Essentially, this structure contains all those fields of the VdbeSorter
//	** structure for which each thread requires a separate instance. For example,
//	** each thread requeries its own UnpackedRecord object to unpack records in
//	** as part of comparison operations.
//	**
//	** Before a background thread is launched, variable bDone is set to 0. Then,
//	** right before it exits, the thread itself sets bDone to 1. This is used for
//	** two purposes:
//	**
//	**   1. When flushing the contents of memory to a level-0 PMA on disk, to
//	**      attempt to select a SortSubtask for which there is not already an
//	**      active background thread (since doing so causes the main thread
//	**      to block until it finishes).
//	**
//	**   2. If SQLITE_DEBUG_SORTER_THREADS is defined, to determine if a call
//	**      to sqlite3ThreadJoin() is likely to block. Cases that are likely to
//	**      block provoke debugging output.
//	**
//	** In both cases, the effects of the main thread seeing (bDone==0) even
//	** after the thread has finished are not dire. So we don't worry about
//	** memory barriers and such here.
//	*/
type TSorterCompare = uintptr

type SorterCompare = TSorterCompare

type TSortSubtask1 = struct {
	F__ccgo_align  [0]uint32
	FpThread       uintptr
	FbDone         int32
	FnPMA          int32
	FpSorter       uintptr
	FpUnpacked     uintptr
	F__ccgo_align5 [4]byte
	Flist          TSorterList
	FxCompare      TSorterCompare
	F__ccgo_align7 [4]byte
	Ffile          TSorterFile
	Ffile2         TSorterFile
}

type SortSubtask1 = TSortSubtask1

/*
** Main sorter structure. A single instance of this is allocated for each
** sorter cursor created by the VDBE.
**
** mxKeysize:
**   As records are added to the sorter by calls to sqlite3VdbeSorterWrite(),
**   this variable is updated so as to be set to the size on disk of the
**   largest record in the sorter.
 */
type TVdbeSorter1 = struct {
	F__ccgo_align   [0]uint32
	FmnPmaSize      int32
	FmxPmaSize      int32
	FmxKeysize      int32
	Fpgsz           int32
	FpReader        uintptr
	FpMerger        uintptr
	Fdb             uintptr
	FpKeyInfo       uintptr
	FpUnpacked      uintptr
	F__ccgo_align9  [4]byte
	Flist           TSorterList
	FiMemory        int32
	FnMemory        int32
	FbUsePMA        Tu8
	FbUseThreads    Tu8
	FiPrev          Tu8
	FnTask          Tu8
	FtypeMask       Tu8
	F__ccgo_align17 [3]byte
	FaTask          [1]TSortSubtask
}

type VdbeSorter1 = TVdbeSorter1

/*
** An instance of the following object is used to read records out of a
** PMA, in sorted order.  The next key to be read is cached in nKey/aKey.
** aKey might point into aMap or into aBuffer.  If neither of those locations
** contain a contiguous representation of the key, then aAlloc is allocated
** and the key is copied into aAlloc and aKey is made to point to aAlloc.
**
** pFd==0 at EOF.
 */
type TPmaReader1 = struct {
	F__ccgo_align [0]uint32
	FiReadOff     Ti64
	FiEof         Ti64
	FnAlloc       int32
	FnKey         int32
	FpFd          uintptr
	FaAlloc       uintptr
	FaKey         uintptr
	FaBuffer      uintptr
	FnBuffer      int32
	FaMap         uintptr
	FpIncr        uintptr
	F__ccgo_pad11 [4]byte
}

type PmaReader1 = TPmaReader1

/*
** Normally, a PmaReader object iterates through an existing PMA stored
** within a temp file. However, if the PmaReader.pIncr variable points to
** an object of the following type, it may be used to iterate/merge through
** multiple PMAs simultaneously.
**
** There are two types of IncrMerger object - single (bUseThread==0) and
** multi-threaded (bUseThread==1).
**
** A multi-threaded IncrMerger object uses two temporary files - aFile[0]
** and aFile[1]. Neither file is allowed to grow to more than mxSz bytes in
** size. When the IncrMerger is initialized, it reads enough data from
** pMerger to populate aFile[0]. It then sets variables within the
** corresponding PmaReader object to read from that file and kicks off
** a background thread to populate aFile[1] with the next mxSz bytes of
** sorted record data from pMerger.
**
** When the PmaReader reaches the end of aFile[0], it blocks until the
** background thread has finished populating aFile[1]. It then exchanges
** the contents of the aFile[0] and aFile[1] variables within this structure,
** sets the PmaReader fields to read from the new aFile[0] and kicks off
** another background thread to populate the new aFile[1]. And so on, until
** the contents of pMerger are exhausted.
**
** A single-threaded IncrMerger does not open any temporary files of its
** own. Instead, it has exclusive access to mxSz bytes of space beginning
** at offset iStartOff of file pTask->file2. And instead of using a
** background thread to prepare data for the PmaReader, with a single
** threaded IncrMerger the allocate part of pTask->file2 is "refilled" with
** keys from pMerger by the calling thread whenever the PmaReader runs out
** of data.
 */
type TIncrMerger1 = struct {
	F__ccgo_align  [0]uint32
	FpTask         uintptr
	FpMerger       uintptr
	FiStartOff     Ti64
	FmxSz          int32
	FbEof          int32
	FbUseThread    int32
	F__ccgo_align6 [4]byte
	FaFile         [2]TSorterFile
}

type IncrMerger1 = TIncrMerger1

/*
** An instance of this object is used for writing a PMA.
**
** The PMA is written one record at a time.  Each record is of an arbitrary
** size.  But I/O is more efficient if it occurs in page-sized blocks where
** each block is aligned on a page boundary.  This object caches writes to
** the PMA so that aligned, page-size blocks are written.
 */
type TPmaWriter1 = struct {
	F__ccgo_align  [0]uint32
	FeFWErr        int32
	FaBuffer       uintptr
	FnBuffer       int32
	FiBufStart     int32
	FiBufEnd       int32
	F__ccgo_align5 [4]byte
	FiWriteOff     Ti64
	FpFd           uintptr
	F__ccgo_pad7   [4]byte
}

type PmaWriter1 = TPmaWriter1

/*
** This object is the header on a single record while that record is being
** held in memory and prior to being written out as part of a PMA.
**
** How the linked list is connected depends on how memory is being managed
** by this module. If using a separate allocation for each in-memory record
** (VdbeSorter.list.aMemory==0), then the list is always connected using the
** SorterRecord.u.pNext pointers.
**
** Or, if using the single large allocation method (VdbeSorter.list.aMemory!=0),
** then while records are being accumulated the list is linked using the
** SorterRecord.u.iNext offset. This is because the aMemory[] array may
** be sqlite3Realloc()ed while records are being accumulated. Once the VM
** has finished passing records to the sorter, or when the in-memory buffer
** is full, the list is sorted. As part of the sorting process, it is
** converted to use the SorterRecord.u.pNext pointers. See function
** vdbeSorterSort() for details.
 */
type TSorterRecord1 = struct {
	FnVal int32
	Fu    struct {
		FiNext [0]int32
		FpNext uintptr
	}
}

type SorterRecord1 = TSorterRecord1

// C documentation
//
//	/*
//	** Free all memory belonging to the PmaReader object passed as the
//	** argument. All structure fields are set to zero before returning.
//	*/
func _vdbePmaReaderClear(tls *libc.TLS, pReadr uintptr) {
	Xsqlite3_free(tls, (*TPmaReader)(unsafe.Pointer(pReadr)).FaAlloc)
	Xsqlite3_free(tls, (*TPmaReader)(unsafe.Pointer(pReadr)).FaBuffer)
	if (*TPmaReader)(unsafe.Pointer(pReadr)).FaMap != 0 {
		_sqlite3OsUnfetch(tls, (*TPmaReader)(unsafe.Pointer(pReadr)).FpFd, 0, (*TPmaReader)(unsafe.Pointer(pReadr)).FaMap)
	}
	_vdbeIncrFree(tls, (*TPmaReader)(unsafe.Pointer(pReadr)).FpIncr)
	libc.Xmemset(tls, pReadr, 0, uint32(56))
}

// C documentation
//
//	/*
//	** Read the next nByte bytes of data from the PMA p.
//	** If successful, set *ppOut to point to a buffer containing the data
//	** and return SQLITE_OK. Otherwise, if an error occurs, return an SQLite
//	** error code.
//	**
//	** The buffer returned in *ppOut is only valid until the
//	** next call to this function.
//	*/
func _vdbePmaReadBlob(tls *libc.TLS, p uintptr, nByte int32, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aNew uintptr
	var iBuf, nAvail, nCopy, nRead, nRem, rc, rc1 int32
	var nNew Tsqlite3_int64
	var v1 int64
	var _ /* aNext at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = aNew, iBuf, nAvail, nCopy, nNew, nRead, nRem, rc, rc1, v1 /* Bytes of data available in buffer */
	if (*TPmaReader)(unsafe.Pointer(p)).FaMap != 0 {
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*TPmaReader)(unsafe.Pointer(p)).FaMap + uintptr((*TPmaReader)(unsafe.Pointer(p)).FiReadOff)
		*(*Ti64)(unsafe.Pointer(p)) += int64(int64(nByte))
		return SQLITE_OK
	}
	/* If there is no more data to be read from the buffer, read the next
	 ** p->nBuffer bytes of data from the file into it. Or, if there are less
	 ** than p->nBuffer bytes remaining in the PMA, read all remaining data.  */
	iBuf = int32((*TPmaReader)(unsafe.Pointer(p)).FiReadOff % int64((*TPmaReader)(unsafe.Pointer(p)).FnBuffer))
	if iBuf == 0 { /* sqlite3OsRead() return code */
		/* Determine how many bytes of data to read. */
		if (*TPmaReader)(unsafe.Pointer(p)).FiEof-(*TPmaReader)(unsafe.Pointer(p)).FiReadOff > int64((*TPmaReader)(unsafe.Pointer(p)).FnBuffer) {
			nRead = (*TPmaReader)(unsafe.Pointer(p)).FnBuffer
		} else {
			nRead = int32((*TPmaReader)(unsafe.Pointer(p)).FiEof - (*TPmaReader)(unsafe.Pointer(p)).FiReadOff)
		}
		/* Readr data from the file. Return early if an error occurs. */
		rc = _sqlite3OsRead(tls, (*TPmaReader)(unsafe.Pointer(p)).FpFd, (*TPmaReader)(unsafe.Pointer(p)).FaBuffer, nRead, (*TPmaReader)(unsafe.Pointer(p)).FiReadOff)
		if rc != SQLITE_OK {
			return rc
		}
	}
	nAvail = (*TPmaReader)(unsafe.Pointer(p)).FnBuffer - iBuf
	if nByte <= nAvail {
		/* The requested data is available in the in-memory buffer. In this
		 ** case there is no need to make a copy of the data, just return a
		 ** pointer into the buffer to the caller.  */
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*TPmaReader)(unsafe.Pointer(p)).FaBuffer + uintptr(iBuf)
		*(*Ti64)(unsafe.Pointer(p)) += int64(int64(nByte))
	} else { /* Bytes remaining to copy */
		/* Extend the p->aAlloc[] allocation if required. */
		if (*TPmaReader)(unsafe.Pointer(p)).FnAlloc < nByte {
			if int64(libc.Int32FromInt32(128)) > int64(2)*int64((*TPmaReader)(unsafe.Pointer(p)).FnAlloc) {
				v1 = int64(libc.Int32FromInt32(128))
			} else {
				v1 = int64(2) * int64((*TPmaReader)(unsafe.Pointer(p)).FnAlloc)
			}
			nNew = v1
			for int64(int64(nByte)) > nNew {
				nNew = nNew * int64(2)
			}
			aNew = _sqlite3Realloc(tls, (*TPmaReader)(unsafe.Pointer(p)).FaAlloc, uint64(uint64(nNew)))
			if !(aNew != 0) {
				return int32(SQLITE_NOMEM)
			}
			(*TPmaReader)(unsafe.Pointer(p)).FnAlloc = int32(int32(nNew))
			(*TPmaReader)(unsafe.Pointer(p)).FaAlloc = aNew
		}
		/* Copy as much data as is available in the buffer into the start of
		 ** p->aAlloc[].  */
		libc.Xmemcpy(tls, (*TPmaReader)(unsafe.Pointer(p)).FaAlloc, (*TPmaReader)(unsafe.Pointer(p)).FaBuffer+uintptr(iBuf), uint32(uint32(nAvail)))
		*(*Ti64)(unsafe.Pointer(p)) += int64(int64(nAvail))
		nRem = nByte - nAvail
		/* The following loop copies up to p->nBuffer bytes per iteration into
		 ** the p->aAlloc[] buffer.  */
		for nRem > 0 { /* Pointer to buffer to copy data from */
			nCopy = nRem
			if nRem > (*TPmaReader)(unsafe.Pointer(p)).FnBuffer {
				nCopy = (*TPmaReader)(unsafe.Pointer(p)).FnBuffer
			}
			rc1 = _vdbePmaReadBlob(tls, p, nCopy, bp)
			if rc1 != SQLITE_OK {
				return rc1
			}
			libc.Xmemcpy(tls, (*TPmaReader)(unsafe.Pointer(p)).FaAlloc+uintptr(nByte-nRem), *(*uintptr)(unsafe.Pointer(bp)), uint32(uint32(nCopy)))
			nRem -= nCopy
		}
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*TPmaReader)(unsafe.Pointer(p)).FaAlloc
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Read a varint from the stream of data accessed by p. Set *pnOut to
//	** the value read.
//	*/
func _vdbePmaReadVarint(tls *libc.TLS, p uintptr, pnOut uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, iBuf, rc, v1 int32
	var _ /* a at bp+16 */ uintptr
	var _ /* aVarint at bp+0 */ [16]Tu8
	_, _, _, _ = i, iBuf, rc, v1
	if (*TPmaReader)(unsafe.Pointer(p)).FaMap != 0 {
		*(*Ti64)(unsafe.Pointer(p)) += int64(_sqlite3GetVarint(tls, (*TPmaReader)(unsafe.Pointer(p)).FaMap+uintptr((*TPmaReader)(unsafe.Pointer(p)).FiReadOff), pnOut))
	} else {
		iBuf = int32((*TPmaReader)(unsafe.Pointer(p)).FiReadOff % int64((*TPmaReader)(unsafe.Pointer(p)).FnBuffer))
		if iBuf != 0 && (*TPmaReader)(unsafe.Pointer(p)).FnBuffer-iBuf >= int32(9) {
			*(*Ti64)(unsafe.Pointer(p)) += int64(_sqlite3GetVarint(tls, (*TPmaReader)(unsafe.Pointer(p)).FaBuffer+uintptr(iBuf), pnOut))
		} else {
			i = 0
			for cond := true; cond; cond = int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))))&int32(0x80) != 0 {
				rc = _vdbePmaReadBlob(tls, p, int32(1), bp+16)
				if rc != 0 {
					return rc
				}
				v1 = i
				i++
				(*(*[16]Tu8)(unsafe.Pointer(bp)))[v1&int32(0xf)] = *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16))))
			}
			_sqlite3GetVarint(tls, bp, pnOut)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Attempt to memory map file pFile. If successful, set *pp to point to the
//	** new mapping and return SQLITE_OK. If the mapping is not attempted
//	** (because the file is too large or the VFS layer is configured not to use
//	** mmap), return SQLITE_OK and set *pp to NULL.
//	**
//	** Or, if an error occurs, return an SQLite error code. The final value of
//	** *pp is undefined in this case.
//	*/
func _vdbeSorterMapFile(tls *libc.TLS, pTask uintptr, pFile uintptr, pp uintptr) (r int32) {
	var pFd uintptr
	var rc int32
	_, _ = pFd, rc
	rc = SQLITE_OK
	if (*TSorterFile)(unsafe.Pointer(pFile)).FiEof <= int64((*Tsqlite3)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fdb)).FnMaxSorterMmap) {
		pFd = (*TSorterFile)(unsafe.Pointer(pFile)).FpFd
		if (*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods)).FiVersion >= int32(3) {
			rc = _sqlite3OsFetch(tls, pFd, 0, int32((*TSorterFile)(unsafe.Pointer(pFile)).FiEof), pp)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Attach PmaReader pReadr to file pFile (if it is not already attached to
//	** that file) and seek it to offset iOff within the file.  Return SQLITE_OK
//	** if successful, or an SQLite error code if an error occurs.
//	*/
func _vdbePmaReaderSeek(tls *libc.TLS, pTask uintptr, pReadr uintptr, pFile uintptr, iOff Ti64) (r int32) {
	var iBuf, nRead, pgsz, rc int32
	_, _, _, _ = iBuf, nRead, pgsz, rc
	rc = SQLITE_OK
	if _sqlite3FaultSim(tls, int32(201)) != 0 {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	}
	if (*TPmaReader)(unsafe.Pointer(pReadr)).FaMap != 0 {
		_sqlite3OsUnfetch(tls, (*TPmaReader)(unsafe.Pointer(pReadr)).FpFd, 0, (*TPmaReader)(unsafe.Pointer(pReadr)).FaMap)
		(*TPmaReader)(unsafe.Pointer(pReadr)).FaMap = uintptr(0)
	}
	(*TPmaReader)(unsafe.Pointer(pReadr)).FiReadOff = iOff
	(*TPmaReader)(unsafe.Pointer(pReadr)).FiEof = (*TSorterFile)(unsafe.Pointer(pFile)).FiEof
	(*TPmaReader)(unsafe.Pointer(pReadr)).FpFd = (*TSorterFile)(unsafe.Pointer(pFile)).FpFd
	rc = _vdbeSorterMapFile(tls, pTask, pFile, pReadr+44)
	if rc == SQLITE_OK && (*TPmaReader)(unsafe.Pointer(pReadr)).FaMap == uintptr(0) {
		pgsz = (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fpgsz
		iBuf = int32((*TPmaReader)(unsafe.Pointer(pReadr)).FiReadOff % int64(int64(pgsz)))
		if (*TPmaReader)(unsafe.Pointer(pReadr)).FaBuffer == uintptr(0) {
			(*TPmaReader)(unsafe.Pointer(pReadr)).FaBuffer = _sqlite3Malloc(tls, uint64(uint64(pgsz)))
			if (*TPmaReader)(unsafe.Pointer(pReadr)).FaBuffer == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			}
			(*TPmaReader)(unsafe.Pointer(pReadr)).FnBuffer = pgsz
		}
		if rc == SQLITE_OK && iBuf != 0 {
			nRead = pgsz - iBuf
			if (*TPmaReader)(unsafe.Pointer(pReadr)).FiReadOff+int64(int64(nRead)) > (*TPmaReader)(unsafe.Pointer(pReadr)).FiEof {
				nRead = int32((*TPmaReader)(unsafe.Pointer(pReadr)).FiEof - (*TPmaReader)(unsafe.Pointer(pReadr)).FiReadOff)
			}
			rc = _sqlite3OsRead(tls, (*TPmaReader)(unsafe.Pointer(pReadr)).FpFd, (*TPmaReader)(unsafe.Pointer(pReadr)).FaBuffer+uintptr(iBuf), nRead, (*TPmaReader)(unsafe.Pointer(pReadr)).FiReadOff)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Advance PmaReader pReadr to the next key in its PMA. Return SQLITE_OK if
//	** no error occurs, or an SQLite error code if one does.
//	*/
func _vdbePmaReaderNext(tls *libc.TLS, pReadr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bEof, rc int32
	var pIncr uintptr
	var _ /* nRec at bp+0 */ Tu64
	_, _, _ = bEof, pIncr, rc
	rc = SQLITE_OK                           /* Return Code */
	*(*Tu64)(unsafe.Pointer(bp)) = uint64(0) /* Size of record in bytes */
	if (*TPmaReader)(unsafe.Pointer(pReadr)).FiReadOff >= (*TPmaReader)(unsafe.Pointer(pReadr)).FiEof {
		pIncr = (*TPmaReader)(unsafe.Pointer(pReadr)).FpIncr
		bEof = int32(1)
		if pIncr != 0 {
			rc = _vdbeIncrSwap(tls, pIncr)
			if rc == SQLITE_OK && (*TIncrMerger)(unsafe.Pointer(pIncr)).FbEof == 0 {
				rc = _vdbePmaReaderSeek(tls, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask, pReadr, pIncr+32, (*TIncrMerger)(unsafe.Pointer(pIncr)).FiStartOff)
				bEof = 0
			}
		}
		if bEof != 0 {
			/* This is an EOF condition */
			_vdbePmaReaderClear(tls, pReadr)
			return rc
		}
	}
	if rc == SQLITE_OK {
		rc = _vdbePmaReadVarint(tls, pReadr, bp)
	}
	if rc == SQLITE_OK {
		(*TPmaReader)(unsafe.Pointer(pReadr)).FnKey = int32(*(*Tu64)(unsafe.Pointer(bp)))
		rc = _vdbePmaReadBlob(tls, pReadr, int32(*(*Tu64)(unsafe.Pointer(bp))), pReadr+32)
	}
	return rc
}

// C documentation
//
//	/*
//	** Initialize PmaReader pReadr to scan through the PMA stored in file pFile
//	** starting at offset iStart and ending at offset iEof-1. This function
//	** leaves the PmaReader pointing to the first key in the PMA (or EOF if the
//	** PMA is empty).
//	**
//	** If the pnByte parameter is NULL, then it is assumed that the file
//	** contains a single PMA, and that that PMA omits the initial length varint.
//	*/
func _vdbePmaReaderInit(tls *libc.TLS, pTask uintptr, pFile uintptr, iStart Ti64, pReadr uintptr, pnByte uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var p1 uintptr
	var _ /* nByte at bp+0 */ Tu64
	_, _ = rc, p1
	rc = _vdbePmaReaderSeek(tls, pTask, pReadr, pFile, iStart)
	if rc == SQLITE_OK {
		*(*Tu64)(unsafe.Pointer(bp)) = uint64(0) /* Size of PMA in bytes */
		rc = _vdbePmaReadVarint(tls, pReadr, bp)
		(*TPmaReader)(unsafe.Pointer(pReadr)).FiEof = int64(uint64((*TPmaReader)(unsafe.Pointer(pReadr)).FiReadOff) + *(*Tu64)(unsafe.Pointer(bp)))
		p1 = pnByte
		*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) + *(*Tu64)(unsafe.Pointer(bp)))
	}
	if rc == SQLITE_OK {
		rc = _vdbePmaReaderNext(tls, pReadr)
	}
	return rc
}

// C documentation
//
//	/*
//	** A version of vdbeSorterCompare() that assumes that it has already been
//	** determined that the first field of key1 is equal to the first field of
//	** key2.
//	*/
func _vdbeSorterCompareTail(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) (r int32) {
	var r2 uintptr
	_ = r2
	r2 = (*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked
	if *(*int32)(unsafe.Pointer(pbKey2Cached)) == 0 {
		_sqlite3VdbeRecordUnpack(tls, (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo, nKey2, pKey2, r2)
		*(*int32)(unsafe.Pointer(pbKey2Cached)) = int32(1)
	}
	return _sqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, r2, int32(1))
}

// C documentation
//
//	/*
//	** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
//	** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
//	** used by the comparison. Return the result of the comparison.
//	**
//	** If IN/OUT parameter *pbKey2Cached is true when this function is called,
//	** it is assumed that (pTask->pUnpacked) contains the unpacked version
//	** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
//	** version of key2 and *pbKey2Cached set to true before returning.
//	**
//	** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
//	** to SQLITE_NOMEM.
//	*/
func _vdbeSorterCompare(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) (r int32) {
	var r2 uintptr
	_ = r2
	r2 = (*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked
	if !(*(*int32)(unsafe.Pointer(pbKey2Cached)) != 0) {
		_sqlite3VdbeRecordUnpack(tls, (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo, nKey2, pKey2, r2)
		*(*int32)(unsafe.Pointer(pbKey2Cached)) = int32(1)
	}
	return _sqlite3VdbeRecordCompare(tls, nKey1, pKey1, r2)
}

// C documentation
//
//	/*
//	** A specially optimized version of vdbeSorterCompare() that assumes that
//	** the first field of each key is a TEXT value and that the collation
//	** sequence to compare them with is BINARY.
//	*/
func _vdbeSorterCompareText(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p1, p2, v1, v2 uintptr
	var res, v11 int32
	var _ /* n1 at bp+0 */ int32
	var _ /* n2 at bp+4 */ int32
	_, _, _, _, _, _ = p1, p2, res, v1, v2, v11
	p1 = pKey1
	p2 = pKey2
	v1 = p1 + uintptr(*(*Tu8)(unsafe.Pointer(p1))) /* Pointer to value 1 */
	v2 = p2 + uintptr(*(*Tu8)(unsafe.Pointer(p2)))
	*(*int32)(unsafe.Pointer(bp)) = int32(uint32(*(*Tu8)(unsafe.Pointer(p1 + 1))))
	if *(*int32)(unsafe.Pointer(bp)) >= int32(0x80) {
		_sqlite3GetVarint32(tls, p1+1, bp)
	}
	*(*int32)(unsafe.Pointer(bp + 4)) = int32(uint32(*(*Tu8)(unsafe.Pointer(p2 + 1))))
	if *(*int32)(unsafe.Pointer(bp + 4)) >= int32(0x80) {
		_sqlite3GetVarint32(tls, p2+1, bp+4)
	}
	if *(*int32)(unsafe.Pointer(bp)) < *(*int32)(unsafe.Pointer(bp + 4)) {
		v11 = *(*int32)(unsafe.Pointer(bp))
	} else {
		v11 = *(*int32)(unsafe.Pointer(bp + 4))
	}
	res = libc.Xmemcmp(tls, v1, v2, uint32((v11-int32(13))/int32(2)))
	if res == 0 {
		res = *(*int32)(unsafe.Pointer(bp)) - *(*int32)(unsafe.Pointer(bp + 4))
	}
	if res == 0 {
		if int32((*TKeyInfo)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FnKeyField) > int32(1) {
			res = _vdbeSorterCompareTail(tls, pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2)
		}
	} else {
		if *(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FaSortFlags)) != 0 {
			res = res * -int32(1)
		}
	}
	return res
}

// C documentation
//
//	/*
//	** A specially optimized version of vdbeSorterCompare() that assumes that
//	** the first field of each key is an INTEGER value.
//	*/
func _vdbeSorterCompareInt(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) (r int32) {
	var i, res, s1, s2, v21, v3 int32
	var n Tu8
	var p1, p2, v1, v2 uintptr
	_, _, _, _, _, _, _, _, _, _, _ = i, n, p1, p2, res, s1, s2, v1, v2, v21, v3
	p1 = pKey1
	p2 = pKey2
	s1 = int32(*(*Tu8)(unsafe.Pointer(p1 + 1)))    /* Left hand serial type */
	s2 = int32(*(*Tu8)(unsafe.Pointer(p2 + 1)))    /* Right hand serial type */
	v1 = p1 + uintptr(*(*Tu8)(unsafe.Pointer(p1))) /* Pointer to value 1 */
	v2 = p2 + uintptr(*(*Tu8)(unsafe.Pointer(p2))) /* Return value */
	if s1 == s2 {
		n = _aLen[s1]
		res = 0
		i = 0
		for {
			if !(i < int32(int32(n))) {
				break
			}
			v21 = int32(*(*Tu8)(unsafe.Pointer(v1 + uintptr(i)))) - int32(*(*Tu8)(unsafe.Pointer(v2 + uintptr(i))))
			res = v21
			if v21 != 0 {
				if (int32(*(*Tu8)(unsafe.Pointer(v1)))^int32(*(*Tu8)(unsafe.Pointer(v2))))&int32(0x80) != 0 {
					if int32(*(*Tu8)(unsafe.Pointer(v1)))&int32(0x80) != 0 {
						v3 = -int32(1)
					} else {
						v3 = +libc.Int32FromInt32(1)
					}
					res = v3
				}
				break
			}
			goto _1
		_1:
			;
			i++
		}
	} else {
		if s1 > int32(7) && s2 > int32(7) {
			res = s1 - s2
		} else {
			if s2 > int32(7) {
				res = +libc.Int32FromInt32(1)
			} else {
				if s1 > int32(7) {
					res = -int32(1)
				} else {
					res = s1 - s2
				}
			}
			if res > 0 {
				if int32(*(*Tu8)(unsafe.Pointer(v1)))&int32(0x80) != 0 {
					res = -int32(1)
				}
			} else {
				if int32(*(*Tu8)(unsafe.Pointer(v2)))&int32(0x80) != 0 {
					res = +libc.Int32FromInt32(1)
				}
			}
		}
	}
	if res == 0 {
		if int32((*TKeyInfo)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FnKeyField) > int32(1) {
			res = _vdbeSorterCompareTail(tls, pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2)
		}
	} else {
		if *(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FaSortFlags)) != 0 {
			res = res * -int32(1)
		}
	}
	return res
}

/* The two values have the same sign. Compare using memcmp(). */
var _aLen = [10]Tu8{
	1: uint8(1),
	2: uint8(2),
	3: uint8(3),
	4: uint8(4),
	5: uint8(6),
	6: uint8(8),
}

// C documentation
//
//	/*
//	** Initialize the temporary index cursor just opened as a sorter cursor.
//	**
//	** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nKeyField)
//	** to determine the number of fields that should be compared from the
//	** records being sorted. However, if the value passed as argument nField
//	** is non-zero and the sorter is able to guarantee a stable sort, nField
//	** is used instead. This is used when sorting records for a CREATE INDEX
//	** statement. In this case, keys are always delivered to the sorter in
//	** order of the primary key, which happens to be make up the final part
//	** of the records being sorted. So if the sort is stable, there is never
//	** any reason to compare PK fields and they can be ignored for a small
//	** performance boost.
//	**
//	** The sorter can guarantee a stable sort when running in single-threaded
//	** mode, but not in multi-threaded mode.
//	**
//	** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
//	*/
func _sqlite3VdbeSorterInit(tls *libc.TLS, db uintptr, nField int32, pCsr uintptr) (r int32) {
	var i, nWorker, pgsz, rc, sz, szKeyInfo, v2, v5 int32
	var mxCache Ti64
	var pBt, pKeyInfo, pSorter, pTask, v1 uintptr
	var szPma Tu32
	var v4 int64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, mxCache, nWorker, pBt, pKeyInfo, pSorter, pTask, pgsz, rc, sz, szKeyInfo, szPma, v1, v2, v4, v5 /* Size of pSorter in bytes */
	rc = SQLITE_OK
	/* Initialize the upper limit on the number of worker threads */
	if _sqlite3TempInMemory(tls, db) != 0 || int32(_sqlite3Config.FbCoreMutex) == 0 {
		nWorker = 0
	} else {
		nWorker = *(*int32)(unsafe.Pointer(db + 120 + 11*4))
	}
	/* Do not allow the total number of threads (main thread + all workers)
	 ** to exceed the maximum merge count */
	szKeyInfo = int32(uint32(24) + uint32(int32((*TKeyInfo)(unsafe.Pointer((*TVdbeCursor)(unsafe.Pointer(pCsr)).FpKeyInfo)).FnKeyField)-libc.Int32FromInt32(1))*uint32(4))
	sz = int32(uint32(152) + uint32(uint32(nWorker))*uint32(80))
	pSorter = _sqlite3DbMallocZero(tls, db, uint64(sz+szKeyInfo))
	*(*uintptr)(unsafe.Pointer(pCsr + 36)) = pSorter
	if pSorter == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt
		v1 = pSorter + uintptr(sz)
		pKeyInfo = v1
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).FpKeyInfo = v1
		libc.Xmemcpy(tls, pKeyInfo, (*TVdbeCursor)(unsafe.Pointer(pCsr)).FpKeyInfo, uint32(uint32(szKeyInfo)))
		(*TKeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb = uintptr(0)
		if nField != 0 && nWorker == 0 {
			(*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField = uint16(uint16(nField))
		}
		_sqlite3BtreeEnter(tls, pBt)
		v2 = _sqlite3BtreeGetPageSize(tls, pBt)
		pgsz = v2
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).Fpgsz = v2
		_sqlite3BtreeLeave(tls, pBt)
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask = uint8(nWorker + int32(1))
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).FiPrev = uint8(nWorker - libc.Int32FromInt32(1))
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads = libc.BoolUint8(int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask) > libc.Int32FromInt32(1))
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).Fdb = db
		i = 0
		for {
			if !(i < int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask)) {
				break
			}
			pTask = pSorter + 72 + uintptr(i)*80
			(*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter = pSorter
			goto _3
		_3:
			;
			i++
		}
		if !(_sqlite3TempInMemory(tls, db) != 0) { /* Cache size in bytes*/
			szPma = _sqlite3Config.FszPma
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize = int32(szPma * uint32(uint32(pgsz)))
			mxCache = int64((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fcache_size)
			if mxCache < 0 {
				/* A negative cache-size value C indicates that the cache is abs(C)
				 ** KiB in size.  */
				mxCache = mxCache * int64(-int32(1024))
			} else {
				mxCache = mxCache * int64(int64(pgsz))
			}
			if mxCache < int64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(29)) {
				v4 = mxCache
			} else {
				v4 = int64(libc.Int32FromInt32(1) << libc.Int32FromInt32(29))
			}
			mxCache = v4
			if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize > int32(int32(mxCache)) {
				v5 = (*TVdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize
			} else {
				v5 = int32(int32(mxCache))
			}
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize = v5
			/* Avoid large memory allocations if the application has requested
			 ** SQLITE_CONFIG_SMALL_MALLOC. */
			if int32(_sqlite3Config.FbSmallMalloc) == 0 {
				(*TVdbeSorter)(unsafe.Pointer(pSorter)).FnMemory = pgsz
				(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = _sqlite3Malloc(tls, uint64(uint64(pgsz)))
				if !((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0) {
					rc = int32(SQLITE_NOMEM)
				}
			}
		}
		if int32((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnAllField) < int32(13) && (*(*uintptr)(unsafe.Pointer(pKeyInfo + 20)) == uintptr(0) || *(*uintptr)(unsafe.Pointer(pKeyInfo + 20)) == (*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl) && int32(*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags)))&int32(KEYINFO_ORDER_BIGNULL) == 0 {
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FtypeMask = uint8(libc.Int32FromInt32(SORTER_TYPE_INTEGER) | libc.Int32FromInt32(SORTER_TYPE_TEXT))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Free the list of sorted records starting at pRecord.
//	*/
func _vdbeSorterRecordFree(tls *libc.TLS, db uintptr, pRecord uintptr) {
	var p, pNext uintptr
	_, _ = p, pNext
	p = pRecord
	for {
		if !(p != 0) {
			break
		}
		pNext = *(*uintptr)(unsafe.Pointer(p + 4))
		_sqlite3DbFree(tls, db, p)
		goto _1
	_1:
		;
		p = pNext
	}
}

// C documentation
//
//	/*
//	** Free all resources owned by the object indicated by argument pTask. All
//	** fields of *pTask are zeroed before returning.
//	*/
func _vdbeSortSubtaskCleanup(tls *libc.TLS, db uintptr, pTask uintptr) {
	_sqlite3DbFree(tls, db, (*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)
	/* pTask->list.aMemory can only be non-zero if it was handed memory
	 ** from the main thread.  That only occurs SQLITE_MAX_WORKER_THREADS>0 */
	if (*TSortSubtask)(unsafe.Pointer(pTask)).Flist.FaMemory != 0 {
		Xsqlite3_free(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).Flist.FaMemory)
	} else {
		_vdbeSorterRecordFree(tls, uintptr(0), (*TSortSubtask)(unsafe.Pointer(pTask)).Flist.FpList)
	}
	if (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd != 0 {
		_sqlite3OsCloseFree(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd)
	}
	if (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd != 0 {
		_sqlite3OsCloseFree(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd)
	}
	libc.Xmemset(tls, pTask, 0, uint32(80))
}

// C documentation
//
//	/*
//	** Join thread pTask->thread.
//	*/
func _vdbeSorterJoinThread(tls *libc.TLS, pTask uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pRet at bp+0 */ uintptr
	_ = rc
	rc = SQLITE_OK
	if (*TSortSubtask)(unsafe.Pointer(pTask)).FpThread != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(libc.Int32FromInt32(SQLITE_ERROR))
		_sqlite3ThreadJoin(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).FpThread, bp)
		rc = int32(*(*uintptr)(unsafe.Pointer(bp)))
		(*TSortSubtask)(unsafe.Pointer(pTask)).FbDone = 0
		(*TSortSubtask)(unsafe.Pointer(pTask)).FpThread = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Launch a background thread to run xTask(pIn).
//	*/
func _vdbeSorterCreateThread(tls *libc.TLS, pTask uintptr, xTask uintptr, pIn uintptr) (r int32) {
	return _sqlite3ThreadCreate(tls, pTask, xTask, pIn)
}

// C documentation
//
//	/*
//	** Join all outstanding threads launched by SorterWrite() to create
//	** level-0 PMAs.
//	*/
func _vdbeSorterJoinAll(tls *libc.TLS, pSorter uintptr, rcin int32) (r int32) {
	var i, rc, rc2 int32
	var pTask uintptr
	_, _, _, _ = i, pTask, rc, rc2
	rc = rcin
	/* This function is always called by the main user thread.
	 **
	 ** If this function is being called after SorterRewind() has been called,
	 ** it is possible that thread pSorter->aTask[pSorter->nTask-1].pThread
	 ** is currently attempt to join one of the other threads. To avoid a race
	 ** condition where this thread also attempts to join the same object, join
	 ** thread pSorter->aTask[pSorter->nTask-1].pThread first. */
	i = int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		pTask = pSorter + 72 + uintptr(i)*80
		rc2 = _vdbeSorterJoinThread(tls, pTask)
		if rc == SQLITE_OK {
			rc = rc2
		}
		goto _1
	_1:
		;
		i--
	}
	return rc
}

// C documentation
//
//	/*
//	** Allocate a new MergeEngine object capable of handling up to
//	** nReader PmaReader inputs.
//	**
//	** nReader is automatically rounded up to the next power of two.
//	** nReader may not exceed SORTER_MAX_MERGE_COUNT even after rounding up.
//	*/
func _vdbeMergeEngineNew(tls *libc.TLS, nReader int32) (r uintptr) {
	var N, nByte int32
	var pNew, v1 uintptr
	_, _, _, _ = N, nByte, pNew, v1
	N = int32(2) /* Pointer to allocated object to return */
	for N < nReader {
		N += N
	}
	nByte = int32(uint32(16) + uint32(uint32(N))*(libc.Uint32FromInt64(4)+libc.Uint32FromInt64(56)))
	if _sqlite3FaultSim(tls, int32(100)) != 0 {
		v1 = uintptr(0)
	} else {
		v1 = _sqlite3MallocZero(tls, uint64(uint64(nByte)))
	}
	pNew = v1
	if pNew != 0 {
		(*TMergeEngine)(unsafe.Pointer(pNew)).FnTree = N
		(*TMergeEngine)(unsafe.Pointer(pNew)).FpTask = uintptr(0)
		(*TMergeEngine)(unsafe.Pointer(pNew)).FaReadr = pNew + 1*16
		(*TMergeEngine)(unsafe.Pointer(pNew)).FaTree = (*TMergeEngine)(unsafe.Pointer(pNew)).FaReadr + uintptr(N)*56
	}
	return pNew
}

// C documentation
//
//	/*
//	** Free the MergeEngine object passed as the only argument.
//	*/
func _vdbeMergeEngineFree(tls *libc.TLS, pMerger uintptr) {
	var i int32
	_ = i
	if pMerger != 0 {
		i = 0
		for {
			if !(i < (*TMergeEngine)(unsafe.Pointer(pMerger)).FnTree) {
				break
			}
			_vdbePmaReaderClear(tls, (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(i)*56)
			goto _1
		_1:
			;
			i++
		}
	}
	Xsqlite3_free(tls, pMerger)
}

// C documentation
//
//	/*
//	** Free all resources associated with the IncrMerger object indicated by
//	** the first argument.
//	*/
func _vdbeIncrFree(tls *libc.TLS, pIncr uintptr) {
	if pIncr != 0 {
		if (*TIncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
			_vdbeSorterJoinThread(tls, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask)
			if (*(*TSorterFile)(unsafe.Pointer(pIncr + 32))).FpFd != 0 {
				_sqlite3OsCloseFree(tls, (*(*TSorterFile)(unsafe.Pointer(pIncr + 32))).FpFd)
			}
			if (*(*TSorterFile)(unsafe.Pointer(pIncr + 32 + 1*16))).FpFd != 0 {
				_sqlite3OsCloseFree(tls, (*(*TSorterFile)(unsafe.Pointer(pIncr + 32 + 1*16))).FpFd)
			}
		}
		_vdbeMergeEngineFree(tls, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpMerger)
		Xsqlite3_free(tls, pIncr)
	}
}

// C documentation
//
//	/*
//	** Reset a sorting cursor back to its original empty state.
//	*/
func _sqlite3VdbeSorterReset(tls *libc.TLS, db uintptr, pSorter uintptr) {
	var i int32
	var pTask uintptr
	_, _ = i, pTask
	_vdbeSorterJoinAll(tls, pSorter, SQLITE_OK)
	if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader != 0 {
		_vdbePmaReaderClear(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader)
		_sqlite3DbFree(tls, db, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader)
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader = uintptr(0)
	}
	_vdbeMergeEngineFree(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpMerger)
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).FpMerger = uintptr(0)
	i = 0
	for {
		if !(i < int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask)) {
			break
		}
		pTask = pSorter + 72 + uintptr(i)*80
		_vdbeSortSubtaskCleanup(tls, db, pTask)
		(*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter = pSorter
		goto _1
	_1:
		;
		i++
	}
	if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory == uintptr(0) {
		_vdbeSorterRecordFree(tls, uintptr(0), (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList)
	}
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = uintptr(0)
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA = 0
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA = uint8(0)
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).FiMemory = 0
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxKeysize = 0
	_sqlite3DbFree(tls, db, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpUnpacked)
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).FpUnpacked = uintptr(0)
}

// C documentation
//
//	/*
//	** Free any cursor components allocated by sqlite3VdbeSorterXXX routines.
//	*/
func _sqlite3VdbeSorterClose(tls *libc.TLS, db uintptr, pCsr uintptr) {
	var pSorter uintptr
	_ = pSorter
	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 36))
	if pSorter != 0 {
		_sqlite3VdbeSorterReset(tls, db, pSorter)
		Xsqlite3_free(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory)
		_sqlite3DbFree(tls, db, pSorter)
		*(*uintptr)(unsafe.Pointer(pCsr + 36)) = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** The first argument is a file-handle open on a temporary file. The file
//	** is guaranteed to be nByte bytes or smaller in size. This function
//	** attempts to extend the file to nByte bytes in size and to ensure that
//	** the VFS has memory mapped it.
//	**
//	** Whether or not the file does end up memory mapped of course depends on
//	** the specific VFS implementation.
//	*/
func _vdbeSorterExtendFile(tls *libc.TLS, db uintptr, pFd uintptr, _nByte Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*Ti64)(unsafe.Pointer(bp)) = _nByte
	var _ /* chunksize at bp+12 */ int32
	var _ /* p at bp+8 */ uintptr
	if *(*Ti64)(unsafe.Pointer(bp)) <= int64((*Tsqlite3)(unsafe.Pointer(db)).FnMaxSorterMmap) && (*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods)).FiVersion >= int32(3) {
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		*(*int32)(unsafe.Pointer(bp + 12)) = libc.Int32FromInt32(4) * libc.Int32FromInt32(1024)
		_sqlite3OsFileControlHint(tls, pFd, int32(SQLITE_FCNTL_CHUNK_SIZE), bp+12)
		_sqlite3OsFileControlHint(tls, pFd, int32(SQLITE_FCNTL_SIZE_HINT), bp)
		_sqlite3OsFetch(tls, pFd, 0, int32(*(*Ti64)(unsafe.Pointer(bp))), bp+8)
		if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
			_sqlite3OsUnfetch(tls, pFd, 0, *(*uintptr)(unsafe.Pointer(bp + 8)))
		}
	}
}

// C documentation
//
//	/*
//	** Allocate space for a file-handle and open a temporary file. If successful,
//	** set *ppFd to point to the malloc'd file-handle and return SQLITE_OK.
//	** Otherwise, set *ppFd to 0 and return an SQLite error code.
//	*/
func _vdbeSorterOpenTempFile(tls *libc.TLS, db uintptr, nExtend Ti64, ppFd uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* max at bp+8 */ Ti64
	var _ /* rc at bp+0 */ int32
	if _sqlite3FaultSim(tls, int32(202)) != 0 {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(13)<<libc.Int32FromInt32(8)
	}
	*(*int32)(unsafe.Pointer(bp)) = _sqlite3OsOpenMalloc(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), ppFd, libc.Int32FromInt32(SQLITE_OPEN_TEMP_JOURNAL)|libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)|libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE)|libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE), bp)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*Ti64)(unsafe.Pointer(bp + 8)) = int64(SQLITE_MAX_MMAP_SIZE)
		_sqlite3OsFileControlHint(tls, *(*uintptr)(unsafe.Pointer(ppFd)), int32(SQLITE_FCNTL_MMAP_SIZE), bp+8)
		if nExtend > 0 {
			_vdbeSorterExtendFile(tls, db, *(*uintptr)(unsafe.Pointer(ppFd)), nExtend)
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** If it has not already been allocated, allocate the UnpackedRecord
//	** structure at pTask->pUnpacked. Return SQLITE_OK if successful (or
//	** if no allocation was required), or SQLITE_NOMEM otherwise.
//	*/
func _vdbeSortAllocUnpacked(tls *libc.TLS, pTask uintptr) (r int32) {
	if (*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked == uintptr(0) {
		(*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked = _sqlite3VdbeAllocUnpackedRecord(tls, (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)
		if (*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		(*TUnpackedRecord)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FnField = (*TKeyInfo)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FnKeyField
		(*TUnpackedRecord)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode = uint8(0)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Merge the two sorted lists p1 and p2 into a single list.
//	*/
func _vdbeSorterMerge(tls *libc.TLS, pTask uintptr, p1 uintptr, p2 uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pp uintptr
	var res int32
	var _ /* bCached at bp+4 */ int32
	var _ /* pFinal at bp+0 */ uintptr
	_, _ = pp, res
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pp = bp
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	for {
		res = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSortSubtask)(unsafe.Pointer(pTask)).FxCompare})))(tls, pTask, bp+4, p1+libc.UintptrFromInt32(1)*8, (*TSorterRecord)(unsafe.Pointer(p1)).FnVal, p2+libc.UintptrFromInt32(1)*8, (*TSorterRecord)(unsafe.Pointer(p2)).FnVal)
		if res <= 0 {
			*(*uintptr)(unsafe.Pointer(pp)) = p1
			pp = p1 + 4
			p1 = *(*uintptr)(unsafe.Pointer(p1 + 4))
			if p1 == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(pp)) = p2
				break
			}
		} else {
			*(*uintptr)(unsafe.Pointer(pp)) = p2
			pp = p2 + 4
			p2 = *(*uintptr)(unsafe.Pointer(p2 + 4))
			*(*int32)(unsafe.Pointer(bp + 4)) = 0
			if p2 == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(pp)) = p1
				break
			}
		}
		goto _1
	_1:
	}
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Return the SorterCompare function to compare values collected by the
//	** sorter object passed as the only argument.
//	*/
func _vdbeSorterGetCompare(tls *libc.TLS, p uintptr) (r TSorterCompare) {
	if int32((*TVdbeSorter)(unsafe.Pointer(p)).FtypeMask) == int32(SORTER_TYPE_INTEGER) {
		return __ccgo_fp(_vdbeSorterCompareInt)
	} else {
		if int32((*TVdbeSorter)(unsafe.Pointer(p)).FtypeMask) == int32(SORTER_TYPE_TEXT) {
			return __ccgo_fp(_vdbeSorterCompareText)
		}
	}
	return __ccgo_fp(_vdbeSorterCompare)
}

// C documentation
//
//	/*
//	** Sort the linked list of records headed at pTask->pList. Return
//	** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
//	** an error occurs.
//	*/
func _vdbeSorterSort(tls *libc.TLS, pTask uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(256)
	defer tls.Free(256)
	var i, rc int32
	var p, pNext, v3 uintptr
	var _ /* aSlot at bp+0 */ [64]uintptr
	_, _, _, _, _ = i, p, pNext, rc, v3
	rc = _vdbeSortAllocUnpacked(tls, pTask)
	if rc != SQLITE_OK {
		return rc
	}
	p = (*TSorterList)(unsafe.Pointer(pList)).FpList
	(*TSortSubtask)(unsafe.Pointer(pTask)).FxCompare = _vdbeSorterGetCompare(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)
	libc.Xmemset(tls, bp, 0, uint32(256))
	for p != 0 {
		if (*TSorterList)(unsafe.Pointer(pList)).FaMemory != 0 {
			if p == (*TSorterList)(unsafe.Pointer(pList)).FaMemory {
				pNext = uintptr(0)
			} else {
				pNext = (*TSorterList)(unsafe.Pointer(pList)).FaMemory + uintptr(*(*int32)(unsafe.Pointer(p + 4)))
			}
		} else {
			pNext = *(*uintptr)(unsafe.Pointer(p + 4))
		}
		*(*uintptr)(unsafe.Pointer(p + 4)) = uintptr(0)
		i = 0
		for {
			if !((*(*[64]uintptr)(unsafe.Pointer(bp)))[i] != 0) {
				break
			}
			p = _vdbeSorterMerge(tls, pTask, p, (*(*[64]uintptr)(unsafe.Pointer(bp)))[i])
			(*(*[64]uintptr)(unsafe.Pointer(bp)))[i] = uintptr(0)
			goto _1
		_1:
			;
			i++
		}
		(*(*[64]uintptr)(unsafe.Pointer(bp)))[i] = p
		p = pNext
	}
	p = uintptr(0)
	i = 0
	for {
		if !(i < int32(libc.Uint32FromInt64(256)/libc.Uint32FromInt64(4))) {
			break
		}
		if (*(*[64]uintptr)(unsafe.Pointer(bp)))[i] == uintptr(0) {
			goto _2
		}
		if p != 0 {
			v3 = _vdbeSorterMerge(tls, pTask, p, (*(*[64]uintptr)(unsafe.Pointer(bp)))[i])
		} else {
			v3 = (*(*[64]uintptr)(unsafe.Pointer(bp)))[i]
		}
		p = v3
		goto _2
	_2:
		;
		i++
	}
	(*TSorterList)(unsafe.Pointer(pList)).FpList = p
	return int32((*TUnpackedRecord)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode)
}

// C documentation
//
//	/*
//	** Initialize a PMA-writer object.
//	*/
func _vdbePmaWriterInit(tls *libc.TLS, pFd uintptr, p uintptr, nBuf int32, iStart Ti64) {
	var v1 int32
	_ = v1
	libc.Xmemset(tls, p, 0, uint32(40))
	(*TPmaWriter)(unsafe.Pointer(p)).FaBuffer = _sqlite3Malloc(tls, uint64(uint64(nBuf)))
	if !((*TPmaWriter)(unsafe.Pointer(p)).FaBuffer != 0) {
		(*TPmaWriter)(unsafe.Pointer(p)).FeFWErr = int32(SQLITE_NOMEM)
	} else {
		v1 = int32(iStart % int64(int64(nBuf)))
		(*TPmaWriter)(unsafe.Pointer(p)).FiBufStart = v1
		(*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd = v1
		(*TPmaWriter)(unsafe.Pointer(p)).FiWriteOff = iStart - int64((*TPmaWriter)(unsafe.Pointer(p)).FiBufStart)
		(*TPmaWriter)(unsafe.Pointer(p)).FnBuffer = nBuf
		(*TPmaWriter)(unsafe.Pointer(p)).FpFd = pFd
	}
}

// C documentation
//
//	/*
//	** Write nData bytes of data to the PMA. Return SQLITE_OK
//	** if successful, or an SQLite error code if an error occurs.
//	*/
func _vdbePmaWriteBlob(tls *libc.TLS, p uintptr, pData uintptr, nData int32) {
	var nCopy, nRem, v1 int32
	_, _, _ = nCopy, nRem, v1
	nRem = nData
	for nRem > 0 && (*TPmaWriter)(unsafe.Pointer(p)).FeFWErr == 0 {
		nCopy = nRem
		if nCopy > (*TPmaWriter)(unsafe.Pointer(p)).FnBuffer-(*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd {
			nCopy = (*TPmaWriter)(unsafe.Pointer(p)).FnBuffer - (*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd
		}
		libc.Xmemcpy(tls, (*TPmaWriter)(unsafe.Pointer(p)).FaBuffer+uintptr((*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd), pData+uintptr(nData-nRem), uint32(uint32(nCopy)))
		*(*int32)(unsafe.Pointer(p + 16)) += nCopy
		if (*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd == (*TPmaWriter)(unsafe.Pointer(p)).FnBuffer {
			(*TPmaWriter)(unsafe.Pointer(p)).FeFWErr = _sqlite3OsWrite(tls, (*TPmaWriter)(unsafe.Pointer(p)).FpFd, (*TPmaWriter)(unsafe.Pointer(p)).FaBuffer+uintptr((*TPmaWriter)(unsafe.Pointer(p)).FiBufStart), (*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd-(*TPmaWriter)(unsafe.Pointer(p)).FiBufStart, (*TPmaWriter)(unsafe.Pointer(p)).FiWriteOff+int64((*TPmaWriter)(unsafe.Pointer(p)).FiBufStart))
			v1 = libc.Int32FromInt32(0)
			(*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd = v1
			(*TPmaWriter)(unsafe.Pointer(p)).FiBufStart = v1
			*(*Ti64)(unsafe.Pointer(p + 24)) += int64((*TPmaWriter)(unsafe.Pointer(p)).FnBuffer)
		}
		nRem -= nCopy
	}
}

// C documentation
//
//	/*
//	** Flush any buffered data to disk and clean up the PMA-writer object.
//	** The results of using the PMA-writer after this call are undefined.
//	** Return SQLITE_OK if flushing the buffered data succeeds or is not
//	** required. Otherwise, return an SQLite error code.
//	**
//	** Before returning, set *piEof to the offset immediately following the
//	** last byte written to the file.
//	*/
func _vdbePmaWriterFinish(tls *libc.TLS, p uintptr, piEof uintptr) (r int32) {
	var rc int32
	_ = rc
	if (*TPmaWriter)(unsafe.Pointer(p)).FeFWErr == 0 && (*TPmaWriter)(unsafe.Pointer(p)).FaBuffer != 0 && (*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd > (*TPmaWriter)(unsafe.Pointer(p)).FiBufStart {
		(*TPmaWriter)(unsafe.Pointer(p)).FeFWErr = _sqlite3OsWrite(tls, (*TPmaWriter)(unsafe.Pointer(p)).FpFd, (*TPmaWriter)(unsafe.Pointer(p)).FaBuffer+uintptr((*TPmaWriter)(unsafe.Pointer(p)).FiBufStart), (*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd-(*TPmaWriter)(unsafe.Pointer(p)).FiBufStart, (*TPmaWriter)(unsafe.Pointer(p)).FiWriteOff+int64((*TPmaWriter)(unsafe.Pointer(p)).FiBufStart))
	}
	*(*Ti64)(unsafe.Pointer(piEof)) = (*TPmaWriter)(unsafe.Pointer(p)).FiWriteOff + int64((*TPmaWriter)(unsafe.Pointer(p)).FiBufEnd)
	Xsqlite3_free(tls, (*TPmaWriter)(unsafe.Pointer(p)).FaBuffer)
	rc = (*TPmaWriter)(unsafe.Pointer(p)).FeFWErr
	libc.Xmemset(tls, p, 0, uint32(40))
	return rc
}

// C documentation
//
//	/*
//	** Write value iVal encoded as a varint to the PMA. Return
//	** SQLITE_OK if successful, or an SQLite error code if an error occurs.
//	*/
func _vdbePmaWriteVarint(tls *libc.TLS, p uintptr, iVal Tu64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nByte int32
	var _ /* aByte at bp+0 */ [10]Tu8
	_ = nByte
	nByte = _sqlite3PutVarint(tls, bp, iVal)
	_vdbePmaWriteBlob(tls, p, bp, nByte)
}

// C documentation
//
//	/*
//	** Write the current contents of in-memory linked-list pList to a level-0
//	** PMA in the temp file belonging to sub-task pTask. Return SQLITE_OK if
//	** successful, or an SQLite error code otherwise.
//	**
//	** The format of a PMA is:
//	**
//	**     * A varint. This varint contains the total number of bytes of content
//	**       in the PMA (not including the varint itself).
//	**
//	**     * One or more records packed end-to-end in order of ascending keys.
//	**       Each record consists of a varint followed by a blob of data (the
//	**       key). The varint is the number of bytes in the blob of data.
//	*/
func _vdbeSorterListToPMA(tls *libc.TLS, pTask uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, p, pNext uintptr
	var rc int32
	var _ /* writer at bp+0 */ TPmaWriter
	_, _, _, _ = db, p, pNext, rc
	db = (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fdb
	rc = SQLITE_OK /* Object used to write to the file */
	libc.Xmemset(tls, bp, 0, uint32(40))
	/* If the first temporary PMA file has not been opened, open it now. */
	if (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd == uintptr(0) {
		rc = _vdbeSorterOpenTempFile(tls, db, 0, pTask+48)
	}
	/* Try to get the file to memory map */
	if rc == SQLITE_OK {
		_vdbeSorterExtendFile(tls, db, (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd, (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile.FiEof+(*TSorterList)(unsafe.Pointer(pList)).FszPMA+int64(9))
	}
	/* Sort the list */
	if rc == SQLITE_OK {
		rc = _vdbeSorterSort(tls, pTask, pList)
	}
	if rc == SQLITE_OK {
		pNext = uintptr(0)
		_vdbePmaWriterInit(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd, bp, (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fpgsz, (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile.FiEof)
		(*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA++
		_vdbePmaWriteVarint(tls, bp, uint64((*TSorterList)(unsafe.Pointer(pList)).FszPMA))
		p = (*TSorterList)(unsafe.Pointer(pList)).FpList
		for {
			if !(p != 0) {
				break
			}
			pNext = *(*uintptr)(unsafe.Pointer(p + 4))
			_vdbePmaWriteVarint(tls, bp, uint64((*TSorterRecord)(unsafe.Pointer(p)).FnVal))
			_vdbePmaWriteBlob(tls, bp, p+libc.UintptrFromInt32(1)*8, (*TSorterRecord)(unsafe.Pointer(p)).FnVal)
			if (*TSorterList)(unsafe.Pointer(pList)).FaMemory == uintptr(0) {
				Xsqlite3_free(tls, p)
			}
			goto _1
		_1:
			;
			p = pNext
		}
		(*TSorterList)(unsafe.Pointer(pList)).FpList = p
		rc = _vdbePmaWriterFinish(tls, bp, pTask+48+8)
	}
	return rc
}

// C documentation
//
//	/*
//	** Advance the MergeEngine to its next entry.
//	** Set *pbEof to true there is no next entry because
//	** the MergeEngine has reached the end of all its inputs.
//	**
//	** Return SQLITE_OK if successful or an error code if an error occurs.
//	*/
func _vdbeMergeEngineStep(tls *libc.TLS, pMerger uintptr, pbEof uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iPrev, iRes, rc, v2 int32
	var pReadr1, pReadr2, pTask uintptr
	var _ /* bCached at bp+0 */ int32
	_, _, _, _, _, _, _, _ = i, iPrev, iRes, pReadr1, pReadr2, pTask, rc, v2
	iPrev = *(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + 1*4)) /* Index of PmaReader to advance */
	pTask = (*TMergeEngine)(unsafe.Pointer(pMerger)).FpTask
	/* Advance the current PmaReader */
	rc = _vdbePmaReaderNext(tls, (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(iPrev)*56)
	/* Update contents of aTree[] */
	if rc == SQLITE_OK { /* Second PmaReader to compare */
		*(*int32)(unsafe.Pointer(bp)) = 0
		/* Find the first two PmaReaders to compare. The one that was just
		 ** advanced (iPrev) and the one next to it in the array.  */
		pReadr1 = (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(iPrev&libc.Int32FromInt32(0xFFFE))*56
		pReadr2 = (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(iPrev|libc.Int32FromInt32(0x0001))*56
		i = ((*TMergeEngine)(unsafe.Pointer(pMerger)).FnTree + iPrev) / int32(2)
		for {
			if !(i > 0) {
				break
			}
			if (*TPmaReader)(unsafe.Pointer(pReadr1)).FpFd == uintptr(0) {
				iRes = +libc.Int32FromInt32(1)
			} else {
				if (*TPmaReader)(unsafe.Pointer(pReadr2)).FpFd == uintptr(0) {
					iRes = -int32(1)
				} else {
					iRes = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSortSubtask)(unsafe.Pointer(pTask)).FxCompare})))(tls, pTask, bp, (*TPmaReader)(unsafe.Pointer(pReadr1)).FaKey, (*TPmaReader)(unsafe.Pointer(pReadr1)).FnKey, (*TPmaReader)(unsafe.Pointer(pReadr2)).FaKey, (*TPmaReader)(unsafe.Pointer(pReadr2)).FnKey)
				}
			}
			/* If pReadr1 contained the smaller value, set aTree[i] to its index.
			 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
			 ** case there is no cache of pReadr2 in pTask->pUnpacked, so set
			 ** pKey2 to point to the record belonging to pReadr2.
			 **
			 ** Alternatively, if pReadr2 contains the smaller of the two values,
			 ** set aTree[i] to its index and update pReadr1. If vdbeSorterCompare()
			 ** was actually called above, then pTask->pUnpacked now contains
			 ** a value equivalent to pReadr2. So set pKey2 to NULL to prevent
			 ** vdbeSorterCompare() from decoding pReadr2 again.
			 **
			 ** If the two values were equal, then the value from the oldest
			 ** PMA should be considered smaller. The VdbeSorter.aReadr[] array
			 ** is sorted from oldest to newest, so pReadr1 contains older values
			 ** than pReadr2 iff (pReadr1<pReadr2).  */
			if iRes < 0 || iRes == 0 && pReadr1 < pReadr2 {
				*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i)*4)) = (int32(int32(pReadr1)) - int32((*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr)) / 56
				pReadr2 = (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i^int32(0x0001))*4)))*56
				*(*int32)(unsafe.Pointer(bp)) = 0
			} else {
				if (*TPmaReader)(unsafe.Pointer(pReadr1)).FpFd != 0 {
					*(*int32)(unsafe.Pointer(bp)) = 0
				}
				*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i)*4)) = (int32(int32(pReadr2)) - int32((*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr)) / 56
				pReadr1 = (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i^int32(0x0001))*4)))*56
			}
			goto _1
		_1:
			;
			i = i / int32(2)
		}
		*(*int32)(unsafe.Pointer(pbEof)) = libc.BoolInt32((*(*TPmaReader)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + 1*4)))*56))).FpFd == uintptr(0))
	}
	if rc == SQLITE_OK {
		v2 = int32((*TUnpackedRecord)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode)
	} else {
		v2 = rc
	}
	return v2
}

// C documentation
//
//	/*
//	** The main routine for background threads that write level-0 PMAs.
//	*/
func _vdbeSorterFlushThread(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pTask uintptr
	var rc int32
	_, _ = pTask, rc
	pTask = pCtx /* Return code */
	rc = _vdbeSorterListToPMA(tls, pTask, pTask+24)
	(*TSortSubtask)(unsafe.Pointer(pTask)).FbDone = int32(1)
	return uintptr(rc)
}

// C documentation
//
//	/*
//	** Flush the current contents of VdbeSorter.list to a new PMA, possibly
//	** using a background thread.
//	*/
func _vdbeSorterFlushPMA(tls *libc.TLS, pSorter uintptr) (r int32) {
	var aMem, pCtx, pTask uintptr
	var i, iTest, nWorker, rc int32
	_, _, _, _, _, _, _ = aMem, i, iTest, nWorker, pCtx, pTask, rc
	rc = SQLITE_OK
	pTask = uintptr(0) /* Thread context used to create new PMA */
	nWorker = int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask) - int32(1)
	/* Set the flag to indicate that at least one PMA has been written.
	 ** Or will be, anyhow.  */
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA = uint8(1)
	/* Select a sub-task to sort and flush the current list of in-memory
	 ** records to disk. If the sorter is running in multi-threaded mode,
	 ** round-robin between the first (pSorter->nTask-1) tasks. Except, if
	 ** the background thread from a sub-tasks previous turn is still running,
	 ** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy,
	 ** fall back to using the final sub-task. The first (pSorter->nTask-1)
	 ** sub-tasks are preferred as they use background threads - the final
	 ** sub-task uses the main thread. */
	i = 0
	for {
		if !(i < nWorker) {
			break
		}
		iTest = (int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FiPrev) + i + int32(1)) % nWorker
		pTask = pSorter + 72 + uintptr(iTest)*80
		if (*TSortSubtask)(unsafe.Pointer(pTask)).FbDone != 0 {
			rc = _vdbeSorterJoinThread(tls, pTask)
		}
		if rc != SQLITE_OK || (*TSortSubtask)(unsafe.Pointer(pTask)).FpThread == uintptr(0) {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	if rc == SQLITE_OK {
		if i == nWorker {
			/* Use the foreground thread for this operation */
			rc = _vdbeSorterListToPMA(tls, pSorter+72+uintptr(nWorker)*80, pSorter+40)
		} else {
			aMem = (*TSortSubtask)(unsafe.Pointer(pTask)).Flist.FaMemory
			pCtx = pTask
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FiPrev = uint8((int32(int32(pTask)) - t__predefined_ptrdiff_t(pSorter+72)) / 80)
			(*TSortSubtask)(unsafe.Pointer(pTask)).Flist = (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = uintptr(0)
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA = 0
			if aMem != 0 {
				(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = aMem
				(*TVdbeSorter)(unsafe.Pointer(pSorter)).FnMemory = _sqlite3MallocSize(tls, aMem)
			} else {
				if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0 {
					(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = _sqlite3Malloc(tls, uint64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnMemory))
					if !((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0) {
						return int32(SQLITE_NOMEM)
					}
				}
			}
			rc = _vdbeSorterCreateThread(tls, pTask, __ccgo_fp(_vdbeSorterFlushThread), pCtx)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Add a record to the sorter.
//	*/
func _sqlite3VdbeSorterWrite(tls *libc.TLS, pCsr uintptr, pVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aNew, pNew, pSorter, p1, p2, p3 uintptr
	var bFlush, iListOff, nMin, rc int32
	var nNew Tsqlite3_int64
	var nPMA, nReq Ti64
	var _ /* t at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = aNew, bFlush, iListOff, nMin, nNew, nPMA, nReq, pNew, pSorter, rc, p1, p2, p3
	rc = SQLITE_OK /* serial type of first record field */
	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 36))
	*(*int32)(unsafe.Pointer(bp)) = int32(uint32(*(*Tu8)(unsafe.Pointer((*TMem)(unsafe.Pointer(pVal)).Fz + 1))))
	if *(*int32)(unsafe.Pointer(bp)) >= int32(0x80) {
		_sqlite3GetVarint32(tls, (*TMem)(unsafe.Pointer(pVal)).Fz+1, bp)
	}
	if *(*int32)(unsafe.Pointer(bp)) > 0 && *(*int32)(unsafe.Pointer(bp)) < int32(10) && *(*int32)(unsafe.Pointer(bp)) != int32(7) {
		p1 = pSorter + 68
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & libc.Int32FromInt32(SORTER_TYPE_INTEGER))
	} else {
		if *(*int32)(unsafe.Pointer(bp)) > int32(10) && *(*int32)(unsafe.Pointer(bp))&int32(0x01) != 0 {
			p2 = pSorter + 68
			*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) & libc.Int32FromInt32(SORTER_TYPE_TEXT))
		} else {
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FtypeMask = uint8(0)
		}
	}
	/* Figure out whether or not the current contents of memory should be
	 ** flushed to a PMA before continuing. If so, do so.
	 **
	 ** If using the single large allocation mode (pSorter->aMemory!=0), then
	 ** flush the contents of memory to a new PMA if (a) at least one value is
	 ** already in memory and (b) the new value will not fit in memory.
	 **
	 ** Or, if using separate allocations for each record, flush the contents
	 ** of memory to a PMA if either of the following are true:
	 **
	 **   * The total memory allocated for the in-memory list is greater
	 **     than (page-size * cache-size), or
	 **
	 **   * The total memory allocated for the in-memory list is greater
	 **     than (page-size * 10) and sqlite3HeapNearlyFull() returns true.
	 */
	nReq = int64(uint32((*TMem)(unsafe.Pointer(pVal)).Fn) + uint32(8))
	nPMA = int64((*TMem)(unsafe.Pointer(pVal)).Fn + _sqlite3VarintLen(tls, uint64((*TMem)(unsafe.Pointer(pVal)).Fn)))
	if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize != 0 {
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0 {
			bFlush = libc.BoolInt32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FiMemory != 0 && int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FiMemory)+nReq > int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize))
		} else {
			bFlush = libc.BoolInt32((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA > int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize) || (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA > int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize) && _sqlite3HeapNearlyFull(tls) != 0)
		}
		if bFlush != 0 {
			rc = _vdbeSorterFlushPMA(tls, pSorter)
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA = 0
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FiMemory = 0
		}
	}
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA += nPMA
	if nPMA > int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxKeysize) {
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxKeysize = int32(int32(nPMA))
	}
	if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0 {
		nMin = int32(int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FiMemory) + nReq)
		if nMin > (*TVdbeSorter)(unsafe.Pointer(pSorter)).FnMemory {
			nNew = int64(2) * int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnMemory)
			iListOff = -int32(1)
			if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
				iListOff = int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList) - int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory)
			}
			for nNew < int64(int64(nMin)) {
				nNew = nNew * int64(2)
			}
			if nNew > int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize) {
				nNew = int64((*TVdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize)
			}
			if nNew < int64(int64(nMin)) {
				nNew = int64(int64(nMin))
			}
			aNew = _sqlite3Realloc(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory, uint64(uint64(nNew)))
			if !(aNew != 0) {
				return int32(SQLITE_NOMEM)
			}
			if iListOff >= 0 {
				(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = aNew + uintptr(iListOff)
			}
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = aNew
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FnMemory = int32(int32(nNew))
		}
		pNew = (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory + uintptr((*TVdbeSorter)(unsafe.Pointer(pSorter)).FiMemory)
		p3 = pSorter + 56
		*(*int32)(unsafe.Pointer(p3)) = int32(int64(*(*int32)(unsafe.Pointer(p3))) + (nReq+libc.Int64FromInt32(7))&int64(^libc.Int32FromInt32(7)))
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
			*(*int32)(unsafe.Pointer(pNew + 4)) = int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList) - int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory)
		}
	} else {
		pNew = _sqlite3Malloc(tls, uint64(uint64(nReq)))
		if pNew == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		*(*uintptr)(unsafe.Pointer(pNew + 4)) = (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList
	}
	libc.Xmemcpy(tls, pNew+libc.UintptrFromInt32(1)*8, (*TMem)(unsafe.Pointer(pVal)).Fz, uint32((*TMem)(unsafe.Pointer(pVal)).Fn))
	(*TSorterRecord)(unsafe.Pointer(pNew)).FnVal = (*TMem)(unsafe.Pointer(pVal)).Fn
	(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = pNew
	return rc
}

// C documentation
//
//	/*
//	** Read keys from pIncr->pMerger and populate pIncr->aFile[1]. The format
//	** of the data stored in aFile[1] is the same as that used by regular PMAs,
//	** except that the number-of-bytes varint is omitted from the start.
//	*/
func _vdbeIncrPopulate(tls *libc.TLS, pIncr uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iEof, iStart Ti64
	var nKey, rc, rc2 int32
	var pMerger, pOut, pReader, pTask uintptr
	var _ /* dummy at bp+40 */ int32
	var _ /* writer at bp+0 */ TPmaWriter
	_, _, _, _, _, _, _, _, _ = iEof, iStart, nKey, pMerger, pOut, pReader, pTask, rc, rc2
	rc = SQLITE_OK
	iStart = (*TIncrMerger)(unsafe.Pointer(pIncr)).FiStartOff
	pOut = pIncr + 32 + 1*16
	pTask = (*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask
	pMerger = (*TIncrMerger)(unsafe.Pointer(pIncr)).FpMerger
	_vdbePmaWriterInit(tls, (*TSorterFile)(unsafe.Pointer(pOut)).FpFd, bp, (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fpgsz, iStart)
	for rc == SQLITE_OK {
		pReader = (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + 1*4)))*56
		nKey = (*TPmaReader)(unsafe.Pointer(pReader)).FnKey
		iEof = (*(*TPmaWriter)(unsafe.Pointer(bp))).FiWriteOff + int64((*(*TPmaWriter)(unsafe.Pointer(bp))).FiBufEnd)
		/* Check if the output file is full or if the input has been exhausted.
		 ** In either case exit the loop. */
		if (*TPmaReader)(unsafe.Pointer(pReader)).FpFd == uintptr(0) {
			break
		}
		if iEof+int64(int64(nKey))+int64(_sqlite3VarintLen(tls, uint64(uint64(nKey)))) > iStart+int64((*TIncrMerger)(unsafe.Pointer(pIncr)).FmxSz) {
			break
		}
		/* Write the next key to the output. */
		_vdbePmaWriteVarint(tls, bp, uint64(uint64(nKey)))
		_vdbePmaWriteBlob(tls, bp, (*TPmaReader)(unsafe.Pointer(pReader)).FaKey, nKey)
		rc = _vdbeMergeEngineStep(tls, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpMerger, bp+40)
	}
	rc2 = _vdbePmaWriterFinish(tls, bp, pOut+8)
	if rc == SQLITE_OK {
		rc = rc2
	}
	return rc
}

// C documentation
//
//	/*
//	** The main routine for background threads that populate aFile[1] of
//	** multi-threaded IncrMerger objects.
//	*/
func _vdbeIncrPopulateThread(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pIncr, pRet uintptr
	_, _ = pIncr, pRet
	pIncr = pCtx
	pRet = uintptr(_vdbeIncrPopulate(tls, pIncr))
	(*TSortSubtask)(unsafe.Pointer((*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask)).FbDone = int32(1)
	return pRet
}

// C documentation
//
//	/*
//	** Launch a background thread to populate aFile[1] of pIncr.
//	*/
func _vdbeIncrBgPopulate(tls *libc.TLS, pIncr uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pIncr
	return _vdbeSorterCreateThread(tls, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask, __ccgo_fp(_vdbeIncrPopulateThread), p)
}

// C documentation
//
//	/*
//	** This function is called when the PmaReader corresponding to pIncr has
//	** finished reading the contents of aFile[0]. Its purpose is to "refill"
//	** aFile[0] such that the PmaReader should start rereading it from the
//	** beginning.
//	**
//	** For single-threaded objects, this is accomplished by literally reading
//	** keys from pIncr->pMerger and repopulating aFile[0].
//	**
//	** For multi-threaded objects, all that is required is to wait until the
//	** background thread is finished (if it is not already) and then swap
//	** aFile[0] and aFile[1] in place. If the contents of pMerger have not
//	** been exhausted, this function also launches a new background thread
//	** to populate the new aFile[1].
//	**
//	** SQLITE_OK is returned on success, or an SQLite error code otherwise.
//	*/
func _vdbeIncrSwap(tls *libc.TLS, pIncr uintptr) (r int32) {
	var f0 TSorterFile
	var rc int32
	_, _ = f0, rc
	rc = SQLITE_OK
	if (*TIncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
		rc = _vdbeSorterJoinThread(tls, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask)
		if rc == SQLITE_OK {
			f0 = *(*TSorterFile)(unsafe.Pointer(pIncr + 32))
			*(*TSorterFile)(unsafe.Pointer(pIncr + 32)) = *(*TSorterFile)(unsafe.Pointer(pIncr + 32 + 1*16))
			*(*TSorterFile)(unsafe.Pointer(pIncr + 32 + 1*16)) = f0
		}
		if rc == SQLITE_OK {
			if (*(*TSorterFile)(unsafe.Pointer(pIncr + 32))).FiEof == (*TIncrMerger)(unsafe.Pointer(pIncr)).FiStartOff {
				(*TIncrMerger)(unsafe.Pointer(pIncr)).FbEof = int32(1)
			} else {
				rc = _vdbeIncrBgPopulate(tls, pIncr)
			}
		}
	} else {
		rc = _vdbeIncrPopulate(tls, pIncr)
		*(*TSorterFile)(unsafe.Pointer(pIncr + 32)) = *(*TSorterFile)(unsafe.Pointer(pIncr + 32 + 1*16))
		if (*(*TSorterFile)(unsafe.Pointer(pIncr + 32))).FiEof == (*TIncrMerger)(unsafe.Pointer(pIncr)).FiStartOff {
			(*TIncrMerger)(unsafe.Pointer(pIncr)).FbEof = int32(1)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Allocate and return a new IncrMerger object to read data from pMerger.
//	**
//	** If an OOM condition is encountered, return NULL. In this case free the
//	** pMerger argument before returning.
//	*/
func _vdbeIncrMergerNew(tls *libc.TLS, pTask uintptr, pMerger uintptr, ppOut uintptr) (r int32) {
	var pIncr, v1, v2 uintptr
	var rc, v3 int32
	_, _, _, _, _ = pIncr, rc, v1, v2, v3
	rc = SQLITE_OK
	if _sqlite3FaultSim(tls, int32(100)) != 0 {
		v2 = uintptr(0)
	} else {
		v2 = _sqlite3MallocZero(tls, uint64(64))
	}
	v1 = v2
	*(*uintptr)(unsafe.Pointer(ppOut)) = v1
	pIncr = v1
	if pIncr != 0 {
		(*TIncrMerger)(unsafe.Pointer(pIncr)).FpMerger = pMerger
		(*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask = pTask
		if (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxKeysize+int32(9) > (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxPmaSize/int32(2) {
			v3 = (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxKeysize + int32(9)
		} else {
			v3 = (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxPmaSize / int32(2)
		}
		(*TIncrMerger)(unsafe.Pointer(pIncr)).FmxSz = v3
		(*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof += int64((*TIncrMerger)(unsafe.Pointer(pIncr)).FmxSz)
	} else {
		_vdbeMergeEngineFree(tls, pMerger)
		rc = int32(SQLITE_NOMEM)
	}
	return rc
}

// C documentation
//
//	/*
//	** Set the "use-threads" flag on object pIncr.
//	*/
func _vdbeIncrMergerSetThreads(tls *libc.TLS, pIncr uintptr) {
	(*TIncrMerger)(unsafe.Pointer(pIncr)).FbUseThread = int32(1)
	(*TSortSubtask)(unsafe.Pointer((*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask)).Ffile2.FiEof -= int64((*TIncrMerger)(unsafe.Pointer(pIncr)).FmxSz)
}

// C documentation
//
//	/*
//	** Recompute pMerger->aTree[iOut] by comparing the next keys on the
//	** two PmaReaders that feed that entry.  Neither of the PmaReaders
//	** are advanced.  This routine merely does the comparison.
//	*/
func _vdbeMergeEngineCompare(tls *libc.TLS, pMerger uintptr, iOut int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i1, i2, iRes, res int32
	var p1, p2, pTask uintptr
	var _ /* bCached at bp+0 */ int32
	_, _, _, _, _, _, _ = i1, i2, iRes, p1, p2, pTask, res
	if iOut >= (*TMergeEngine)(unsafe.Pointer(pMerger)).FnTree/int32(2) {
		i1 = (iOut - (*TMergeEngine)(unsafe.Pointer(pMerger)).FnTree/int32(2)) * int32(2)
		i2 = i1 + int32(1)
	} else {
		i1 = *(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(iOut*int32(2))*4))
		i2 = *(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(iOut*int32(2)+int32(1))*4))
	}
	p1 = (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(i1)*56
	p2 = (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(i2)*56
	if (*TPmaReader)(unsafe.Pointer(p1)).FpFd == uintptr(0) {
		iRes = i2
	} else {
		if (*TPmaReader)(unsafe.Pointer(p2)).FpFd == uintptr(0) {
			iRes = i1
		} else {
			pTask = (*TMergeEngine)(unsafe.Pointer(pMerger)).FpTask
			*(*int32)(unsafe.Pointer(bp)) = 0
			/* from vdbeSortSubtaskMain() */
			res = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSortSubtask)(unsafe.Pointer(pTask)).FxCompare})))(tls, pTask, bp, (*TPmaReader)(unsafe.Pointer(p1)).FaKey, (*TPmaReader)(unsafe.Pointer(p1)).FnKey, (*TPmaReader)(unsafe.Pointer(p2)).FaKey, (*TPmaReader)(unsafe.Pointer(p2)).FnKey)
			if res <= 0 {
				iRes = i1
			} else {
				iRes = i2
			}
		}
	}
	*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(iOut)*4)) = iRes
}

// C documentation
//
//	/*
//	** Initialize the MergeEngine object passed as the second argument. Once this
//	** function returns, the first key of merged data may be read from the
//	** MergeEngine object in the usual fashion.
//	**
//	** If argument eMode is INCRINIT_ROOT, then it is assumed that any IncrMerge
//	** objects attached to the PmaReader objects that the merger reads from have
//	** already been populated, but that they have not yet populated aFile[0] and
//	** set the PmaReader objects up to read from it. In this case all that is
//	** required is to call vdbePmaReaderNext() on each PmaReader to point it at
//	** its first key.
//	**
//	** Otherwise, if eMode is any value other than INCRINIT_ROOT, then use
//	** vdbePmaReaderIncrMergeInit() to initialize each PmaReader that feeds data
//	** to pMerger.
//	**
//	** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
//	*/
func _vdbeMergeEngineInit(tls *libc.TLS, pTask uintptr, pMerger uintptr, eMode int32) (r int32) {
	var i, nTree, rc int32
	_, _, _ = i, nTree, rc
	rc = SQLITE_OK /* Number of subtrees to merge */
	/* Failure to allocate the merge would have been detected prior to
	 ** invoking this routine */
	/* eMode is always INCRINIT_NORMAL in single-threaded mode */
	/* Verify that the MergeEngine is assigned to a single thread */
	(*TMergeEngine)(unsafe.Pointer(pMerger)).FpTask = pTask
	nTree = (*TMergeEngine)(unsafe.Pointer(pMerger)).FnTree
	i = 0
	for {
		if !(i < nTree) {
			break
		}
		if libc.Bool(int32(SQLITE_MAX_WORKER_THREADS) > 0) && eMode == int32(INCRINIT_ROOT) {
			/* PmaReaders should be normally initialized in order, as if they are
			 ** reading from the same temp file this makes for more linear file IO.
			 ** However, in the INCRINIT_ROOT case, if PmaReader aReadr[nTask-1] is
			 ** in use it will block the vdbePmaReaderNext() call while it uses
			 ** the main thread to fill its buffer. So calling PmaReaderNext()
			 ** on this PmaReader before any of the multi-threaded PmaReaders takes
			 ** better advantage of multi-processor hardware. */
			rc = _vdbePmaReaderNext(tls, (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(nTree-i-int32(1))*56)
		} else {
			rc = _vdbePmaReaderIncrInit(tls, (*TMergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(i)*56, INCRINIT_NORMAL)
		}
		if rc != SQLITE_OK {
			return rc
		}
		goto _1
	_1:
		;
		i++
	}
	i = (*TMergeEngine)(unsafe.Pointer(pMerger)).FnTree - int32(1)
	for {
		if !(i > 0) {
			break
		}
		_vdbeMergeEngineCompare(tls, pMerger, i)
		goto _2
	_2:
		;
		i--
	}
	return int32((*TUnpackedRecord)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode)
}

// C documentation
//
//	/*
//	** The PmaReader passed as the first argument is guaranteed to be an
//	** incremental-reader (pReadr->pIncr!=0). This function serves to open
//	** and/or initialize the temp file related fields of the IncrMerge
//	** object at (pReadr->pIncr).
//	**
//	** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
//	** in the sub-tree headed by pReadr are also initialized. Data is then
//	** loaded into the buffers belonging to pReadr and it is set to point to
//	** the first key in its range.
//	**
//	** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
//	** to be a multi-threaded PmaReader and this function is being called in a
//	** background thread. In this case all PmaReaders in the sub-tree are
//	** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
//	** pReadr is populated. However, pReadr itself is not set up to point
//	** to its first key. A call to vdbePmaReaderNext() is still required to do
//	** that.
//	**
//	** The reason this function does not call vdbePmaReaderNext() immediately
//	** in the INCRINIT_TASK case is that vdbePmaReaderNext() assumes that it has
//	** to block on thread (pTask->thread) before accessing aFile[1]. But, since
//	** this entire function is being run by thread (pTask->thread), that will
//	** lead to the current background thread attempting to join itself.
//	**
//	** Finally, if argument eMode is set to INCRINIT_ROOT, it may be assumed
//	** that pReadr->pIncr is a multi-threaded IncrMerge objects, and that all
//	** child-trees have already been initialized using IncrInit(INCRINIT_TASK).
//	** In this case vdbePmaReaderNext() is called on all child PmaReaders and
//	** the current PmaReader set to point to the first key in its range.
//	**
//	** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
//	*/
func _vdbePmaReaderIncrMergeInit(tls *libc.TLS, pReadr uintptr, eMode int32) (r int32) {
	var db, pIncr, pTask uintptr
	var mxSz, rc int32
	_, _, _, _, _ = db, mxSz, pIncr, pTask, rc
	rc = SQLITE_OK
	pIncr = (*TPmaReader)(unsafe.Pointer(pReadr)).FpIncr
	pTask = (*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask
	db = (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fdb
	/* eMode is always INCRINIT_NORMAL in single-threaded mode */
	rc = _vdbeMergeEngineInit(tls, pTask, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpMerger, eMode)
	/* Set up the required files for pIncr. A multi-threaded IncrMerge object
	 ** requires two temp files to itself, whereas a single-threaded object
	 ** only requires a region of pTask->file2. */
	if rc == SQLITE_OK {
		mxSz = (*TIncrMerger)(unsafe.Pointer(pIncr)).FmxSz
		if (*TIncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
			rc = _vdbeSorterOpenTempFile(tls, db, int64(int64(mxSz)), pIncr+32)
			if rc == SQLITE_OK {
				rc = _vdbeSorterOpenTempFile(tls, db, int64(int64(mxSz)), pIncr+32+1*16)
			}
		} else {
			/*if( !pIncr->bUseThread )*/
			if (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd == uintptr(0) {
				rc = _vdbeSorterOpenTempFile(tls, db, (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof, pTask+64)
				(*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof = 0
			}
			if rc == SQLITE_OK {
				(*(*TSorterFile)(unsafe.Pointer(pIncr + 32 + 1*16))).FpFd = (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd
				(*TIncrMerger)(unsafe.Pointer(pIncr)).FiStartOff = (*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof
				(*TSortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof += int64(int64(mxSz))
			}
		}
	}
	if rc == SQLITE_OK && (*TIncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
		/* Use the current thread to populate aFile[1], even though this
		 ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
		 ** then this function is already running in background thread
		 ** pIncr->pTask->thread.
		 **
		 ** If this is the INCRINIT_ROOT object, then it is running in the
		 ** main VDBE thread. But that is Ok, as that thread cannot return
		 ** control to the VDBE or proceed with anything useful until the
		 ** first results are ready from this merger object anyway.
		 */
		rc = _vdbeIncrPopulate(tls, pIncr)
	}
	if rc == SQLITE_OK && (libc.Bool(false) || eMode != int32(INCRINIT_TASK)) {
		rc = _vdbePmaReaderNext(tls, pReadr)
	}
	return rc
}

// C documentation
//
//	/*
//	** The main routine for vdbePmaReaderIncrMergeInit() operations run in
//	** background threads.
//	*/
func _vdbePmaReaderBgIncrInit(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pReader, pRet uintptr
	_, _ = pReader, pRet
	pReader = pCtx
	pRet = uintptr(_vdbePmaReaderIncrMergeInit(tls, pReader, int32(INCRINIT_TASK)))
	(*TSortSubtask)(unsafe.Pointer((*TIncrMerger)(unsafe.Pointer((*TPmaReader)(unsafe.Pointer(pReader)).FpIncr)).FpTask)).FbDone = int32(1)
	return pRet
}

// C documentation
//
//	/*
//	** If the PmaReader passed as the first argument is not an incremental-reader
//	** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
//	** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
//	** this routine to initialize the incremental merge.
//	**
//	** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
//	** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
//	** Or, if the IncrMerger is single threaded, the same function is called
//	** using the current thread.
//	*/
func _vdbePmaReaderIncrInit(tls *libc.TLS, pReadr uintptr, eMode int32) (r int32) {
	var pCtx, pIncr uintptr
	var rc int32
	_, _, _ = pCtx, pIncr, rc
	pIncr = (*TPmaReader)(unsafe.Pointer(pReadr)).FpIncr /* Incremental merger */
	rc = SQLITE_OK                                       /* Return code */
	if pIncr != 0 {
		if (*TIncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
			pCtx = pReadr
			rc = _vdbeSorterCreateThread(tls, (*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask, __ccgo_fp(_vdbePmaReaderBgIncrInit), pCtx)
		} else {
			rc = _vdbePmaReaderIncrMergeInit(tls, pReadr, eMode)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Allocate a new MergeEngine object to merge the contents of nPMA level-0
//	** PMAs from pTask->file. If no error occurs, set *ppOut to point to
//	** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
//	** to NULL and return an SQLite error code.
//	**
//	** When this function is called, *piOffset is set to the offset of the
//	** first PMA to read from pTask->file. Assuming no error occurs, it is
//	** set to the offset immediately following the last byte of the last
//	** PMA before returning. If an error does occur, then the final value of
//	** *piOffset is undefined.
//	*/
func _vdbeMergeEngineLevel0(tls *libc.TLS, pTask uintptr, nPMA int32, piOffset uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var iOff Ti64
	var pNew, pReadr, v1 uintptr
	var _ /* nDummy at bp+0 */ Ti64
	_, _, _, _, _, _ = i, iOff, pNew, pReadr, rc, v1 /* Merge engine to return */
	iOff = *(*Ti64)(unsafe.Pointer(piOffset))
	rc = SQLITE_OK
	v1 = _vdbeMergeEngineNew(tls, nPMA)
	pNew = v1
	*(*uintptr)(unsafe.Pointer(ppOut)) = v1
	if pNew == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	}
	i = 0
	for {
		if !(i < nPMA && rc == SQLITE_OK) {
			break
		}
		*(*Ti64)(unsafe.Pointer(bp)) = 0
		pReadr = (*TMergeEngine)(unsafe.Pointer(pNew)).FaReadr + uintptr(i)*56
		rc = _vdbePmaReaderInit(tls, pTask, pTask+48, iOff, pReadr, bp)
		iOff = (*TPmaReader)(unsafe.Pointer(pReadr)).FiEof
		goto _2
	_2:
		;
		i++
	}
	if rc != SQLITE_OK {
		_vdbeMergeEngineFree(tls, pNew)
		*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
	}
	*(*Ti64)(unsafe.Pointer(piOffset)) = iOff
	return rc
}

// C documentation
//
//	/*
//	** Return the depth of a tree comprising nPMA PMAs, assuming a fanout of
//	** SORTER_MAX_MERGE_COUNT. The returned value does not include leaf nodes.
//	**
//	** i.e.
//	**
//	**   nPMA<=16    -> TreeDepth() == 0
//	**   nPMA<=256   -> TreeDepth() == 1
//	**   nPMA<=65536 -> TreeDepth() == 2
//	*/
func _vdbeSorterTreeDepth(tls *libc.TLS, nPMA int32) (r int32) {
	var nDepth int32
	var nDiv Ti64
	_, _ = nDepth, nDiv
	nDepth = 0
	nDiv = int64(SORTER_MAX_MERGE_COUNT)
	for nDiv < int64(int64(nPMA)) {
		nDiv = nDiv * int64(SORTER_MAX_MERGE_COUNT)
		nDepth++
	}
	return nDepth
}

// C documentation
//
//	/*
//	** pRoot is the root of an incremental merge-tree with depth nDepth (according
//	** to vdbeSorterTreeDepth()). pLeaf is the iSeq'th leaf to be added to the
//	** tree, counting from zero. This function adds pLeaf to the tree.
//	**
//	** If successful, SQLITE_OK is returned. If an error occurs, an SQLite error
//	** code is returned and pLeaf is freed.
//	*/
func _vdbeSorterAddToTree(tls *libc.TLS, pTask uintptr, nDepth int32, iSeq int32, pRoot uintptr, pLeaf uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iIter, nDiv, rc int32
	var p, pNew, pReadr uintptr
	var _ /* pIncr at bp+0 */ uintptr
	_, _, _, _, _, _, _ = i, iIter, nDiv, p, pNew, pReadr, rc
	rc = SQLITE_OK
	nDiv = int32(1)
	p = pRoot
	rc = _vdbeIncrMergerNew(tls, pTask, pLeaf, bp)
	i = int32(1)
	for {
		if !(i < nDepth) {
			break
		}
		nDiv = nDiv * int32(SORTER_MAX_MERGE_COUNT)
		goto _1
	_1:
		;
		i++
	}
	i = int32(1)
	for {
		if !(i < nDepth && rc == SQLITE_OK) {
			break
		}
		iIter = iSeq / nDiv % int32(SORTER_MAX_MERGE_COUNT)
		pReadr = (*TMergeEngine)(unsafe.Pointer(p)).FaReadr + uintptr(iIter)*56
		if (*TPmaReader)(unsafe.Pointer(pReadr)).FpIncr == uintptr(0) {
			pNew = _vdbeMergeEngineNew(tls, int32(SORTER_MAX_MERGE_COUNT))
			if pNew == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				rc = _vdbeIncrMergerNew(tls, pTask, pNew, pReadr+48)
			}
		}
		if rc == SQLITE_OK {
			p = (*TIncrMerger)(unsafe.Pointer((*TPmaReader)(unsafe.Pointer(pReadr)).FpIncr)).FpMerger
			nDiv = nDiv / int32(SORTER_MAX_MERGE_COUNT)
		}
		goto _2
	_2:
		;
		i++
	}
	if rc == SQLITE_OK {
		(*(*TPmaReader)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(p)).FaReadr + uintptr(iSeq%int32(SORTER_MAX_MERGE_COUNT))*56))).FpIncr = *(*uintptr)(unsafe.Pointer(bp))
	} else {
		_vdbeIncrFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called as part of a SorterRewind() operation on a sorter
//	** that has already written two or more level-0 PMAs to one or more temp
//	** files. It builds a tree of MergeEngine/IncrMerger/PmaReader objects that
//	** can be used to incrementally merge all PMAs on disk.
//	**
//	** If successful, SQLITE_OK is returned and *ppOut set to point to the
//	** MergeEngine object at the root of the tree before returning. Or, if an
//	** error occurs, an SQLite error code is returned and the final value
//	** of *ppOut is undefined.
//	*/
func _vdbeSorterMergeTreeBuild(tls *libc.TLS, pSorter uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, iSeq, iTask, nDepth, nReader, rc, v3, v4 int32
	var pMain, pTask uintptr
	var _ /* iReadOff at bp+8 */ Ti64
	var _ /* pMerger at bp+16 */ uintptr
	var _ /* pRoot at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = i, iSeq, iTask, nDepth, nReader, pMain, pTask, rc, v3, v4
	pMain = uintptr(0)
	rc = SQLITE_OK
	/* If the sorter uses more than one task, then create the top-level
	 ** MergeEngine here. This MergeEngine will read data from exactly
	 ** one PmaReader per sub-task.  */
	if int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask) > int32(1) {
		pMain = _vdbeMergeEngineNew(tls, int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask))
		if pMain == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	iTask = 0
	for {
		if !(rc == SQLITE_OK && iTask < int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask)) {
			break
		}
		pTask = pSorter + 72 + uintptr(iTask)*80
		if libc.Bool(false) || (*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA != 0 {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Root node of tree for this task */
			nDepth = _vdbeSorterTreeDepth(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA)
			*(*Ti64)(unsafe.Pointer(bp + 8)) = 0
			if (*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA <= int32(SORTER_MAX_MERGE_COUNT) {
				rc = _vdbeMergeEngineLevel0(tls, pTask, (*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA, bp+8, bp)
			} else {
				iSeq = 0
				*(*uintptr)(unsafe.Pointer(bp)) = _vdbeMergeEngineNew(tls, int32(SORTER_MAX_MERGE_COUNT))
				if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				}
				i = 0
				for {
					if !(i < (*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA && rc == SQLITE_OK) {
						break
					}
					*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0) /* Number of level-0 PMAs to merge */
					if (*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA-i < int32(SORTER_MAX_MERGE_COUNT) {
						v3 = (*TSortSubtask)(unsafe.Pointer(pTask)).FnPMA - i
					} else {
						v3 = int32(SORTER_MAX_MERGE_COUNT)
					}
					nReader = v3
					rc = _vdbeMergeEngineLevel0(tls, pTask, nReader, bp+8, bp+16)
					if rc == SQLITE_OK {
						v4 = iSeq
						iSeq++
						rc = _vdbeSorterAddToTree(tls, pTask, nDepth, v4, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 16)))
					}
					goto _2
				_2:
					;
					i += int32(SORTER_MAX_MERGE_COUNT)
				}
			}
			if rc == SQLITE_OK {
				if pMain != uintptr(0) {
					rc = _vdbeIncrMergerNew(tls, pTask, *(*uintptr)(unsafe.Pointer(bp)), (*TMergeEngine)(unsafe.Pointer(pMain)).FaReadr+uintptr(iTask)*56+48)
				} else {
					pMain = *(*uintptr)(unsafe.Pointer(bp))
				}
			} else {
				_vdbeMergeEngineFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		goto _1
	_1:
		;
		iTask++
	}
	if rc != SQLITE_OK {
		_vdbeMergeEngineFree(tls, pMain)
		pMain = uintptr(0)
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = pMain
	return rc
}

// C documentation
//
//	/*
//	** This function is called as part of an sqlite3VdbeSorterRewind() operation
//	** on a sorter that has written two or more PMAs to temporary files. It sets
//	** up either VdbeSorter.pMerger (for single threaded sorters) or pReader
//	** (for multi-threaded sorters) so that it can be used to iterate through
//	** all records stored in the sorter.
//	**
//	** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
//	*/
func _vdbeSorterSetupMerge(tls *libc.TLS, pSorter uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, p, pIncr, pLast, pReadr, pTask0, v3 uintptr
	var i, iTask, rc int32
	var xCompare TSorterCompare
	var _ /* pMain at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = db, i, iTask, p, pIncr, pLast, pReadr, pTask0, rc, xCompare, v3 /* Return code */
	pTask0 = pSorter + 72
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	db = (*TVdbeSorter)(unsafe.Pointer((*TSortSubtask)(unsafe.Pointer(pTask0)).FpSorter)).Fdb
	xCompare = _vdbeSorterGetCompare(tls, pSorter)
	i = 0
	for {
		if !(i < int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask)) {
			break
		}
		(*(*TSortSubtask)(unsafe.Pointer(pSorter + 72 + uintptr(i)*80))).FxCompare = xCompare
		goto _1
	_1:
		;
		i++
	}
	rc = _vdbeSorterMergeTreeBuild(tls, pSorter, bp)
	if rc == SQLITE_OK {
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads != 0 {
			pReadr = uintptr(0)
			pLast = pSorter + 72 + uintptr(int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask)-int32(1))*80
			rc = _vdbeSortAllocUnpacked(tls, pLast)
			if rc == SQLITE_OK {
				pReadr = _sqlite3DbMallocZero(tls, db, uint64(56))
				(*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader = pReadr
				if pReadr == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				}
			}
			if rc == SQLITE_OK {
				rc = _vdbeIncrMergerNew(tls, pLast, *(*uintptr)(unsafe.Pointer(bp)), pReadr+48)
				if rc == SQLITE_OK {
					_vdbeIncrMergerSetThreads(tls, (*TPmaReader)(unsafe.Pointer(pReadr)).FpIncr)
					iTask = 0
					for {
						if !(iTask < int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask)-int32(1)) {
							break
						}
						v3 = (*(*TPmaReader)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaReadr + uintptr(iTask)*56))).FpIncr
						pIncr = v3
						if v3 != 0 {
							_vdbeIncrMergerSetThreads(tls, pIncr)
						}
						goto _2
					_2:
						;
						iTask++
					}
					iTask = 0
					for {
						if !(rc == SQLITE_OK && iTask < int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FnTask)) {
							break
						}
						/* Check that:
						 **
						 **   a) The incremental merge object is configured to use the
						 **      right task, and
						 **   b) If it is using task (nTask-1), it is configured to run
						 **      in single-threaded mode. This is important, as the
						 **      root merge (INCRINIT_ROOT) will be using the same task
						 **      object.
						 */
						p = (*TMergeEngine)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaReadr + uintptr(iTask)*56
						rc = _vdbePmaReaderIncrInit(tls, p, int32(INCRINIT_TASK))
						goto _4
					_4:
						;
						iTask++
					}
				}
				*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			}
			if rc == SQLITE_OK {
				rc = _vdbePmaReaderIncrMergeInit(tls, pReadr, int32(INCRINIT_ROOT))
			}
		} else {
			rc = _vdbeMergeEngineInit(tls, pTask0, *(*uintptr)(unsafe.Pointer(bp)), INCRINIT_NORMAL)
			(*TVdbeSorter)(unsafe.Pointer(pSorter)).FpMerger = *(*uintptr)(unsafe.Pointer(bp))
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		}
	}
	if rc != SQLITE_OK {
		_vdbeMergeEngineFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Once the sorter has been populated by calls to sqlite3VdbeSorterWrite,
//	** this function is called to prepare for iterating through the records
//	** in sorted order.
//	*/
func _sqlite3VdbeSorterRewind(tls *libc.TLS, pCsr uintptr, pbEof uintptr) (r int32) {
	var pSorter uintptr
	var rc int32
	_, _ = pSorter, rc
	rc = SQLITE_OK /* Return code */
	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 36))
	/* If no data has been written to disk, then do not do so now. Instead,
	 ** sort the VdbeSorter.pRecord list. The vdbe layer will read data directly
	 ** from the in-memory list.  */
	if int32((*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA) == 0 {
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
			*(*int32)(unsafe.Pointer(pbEof)) = 0
			rc = _vdbeSorterSort(tls, pSorter+72, pSorter+40)
		} else {
			*(*int32)(unsafe.Pointer(pbEof)) = int32(1)
		}
		return rc
	}
	/* Write the current in-memory list to a PMA. When the VdbeSorterWrite()
	 ** function flushes the contents of memory to disk, it immediately always
	 ** creates a new list consisting of a single key immediately afterwards.
	 ** So the list is never empty at this point.  */
	rc = _vdbeSorterFlushPMA(tls, pSorter)
	/* Join all threads */
	rc = _vdbeSorterJoinAll(tls, pSorter, rc)
	/* Assuming no errors have occurred, set up a merger structure to
	 ** incrementally read and merge all remaining PMAs.  */
	if rc == SQLITE_OK {
		rc = _vdbeSorterSetupMerge(tls, pSorter)
		*(*int32)(unsafe.Pointer(pbEof)) = 0
	}
	return rc
}

// C documentation
//
//	/*
//	** Advance to the next element in the sorter.  Return value:
//	**
//	**    SQLITE_OK     success
//	**    SQLITE_DONE   end of data
//	**    otherwise     some kind of error.
//	*/
func _sqlite3VdbeSorterNext(tls *libc.TLS, db uintptr, pCsr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pFree, pSorter uintptr
	var rc, v1 int32
	var _ /* res at bp+0 */ int32
	_, _, _, _ = pFree, pSorter, rc, v1 /* Return code */
	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 36))
	if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA != 0 {
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads != 0 {
			rc = _vdbePmaReaderNext(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader)
			if rc == SQLITE_OK && (*TPmaReader)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader)).FpFd == uintptr(0) {
				rc = int32(SQLITE_DONE)
			}
		} else {
			/*if( !pSorter->bUseThreads )*/
			*(*int32)(unsafe.Pointer(bp)) = 0
			rc = _vdbeMergeEngineStep(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpMerger, bp)
			if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
				rc = int32(SQLITE_DONE)
			}
		}
	} else {
		pFree = (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = *(*uintptr)(unsafe.Pointer(pFree + 4))
		*(*uintptr)(unsafe.Pointer(pFree + 4)) = uintptr(0)
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory == uintptr(0) {
			_vdbeSorterRecordFree(tls, db, pFree)
		}
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
			v1 = SQLITE_OK
		} else {
			v1 = int32(SQLITE_DONE)
		}
		rc = v1
	}
	return rc
}

// C documentation
//
//	/*
//	** Return a pointer to a buffer owned by the sorter that contains the
//	** current key.
//	*/
func _vdbeSorterRowkey(tls *libc.TLS, pSorter uintptr, pnKey uintptr) (r uintptr) {
	var pKey, pReader uintptr
	_, _ = pKey, pReader
	if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA != 0 {
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads != 0 {
			pReader = (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader
		} else {
			/*if( !pSorter->bUseThreads )*/
			pReader = (*TMergeEngine)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer(pSorter)).FpMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*TMergeEngine)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer(pSorter)).FpMerger)).FaTree + 1*4)))*56
		}
		*(*int32)(unsafe.Pointer(pnKey)) = (*TPmaReader)(unsafe.Pointer(pReader)).FnKey
		pKey = (*TPmaReader)(unsafe.Pointer(pReader)).FaKey
	} else {
		*(*int32)(unsafe.Pointer(pnKey)) = (*TSorterRecord)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList)).FnVal
		pKey = (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList + libc.UintptrFromInt32(1)*8
	}
	return pKey
}

// C documentation
//
//	/*
//	** Copy the current sorter key into the memory cell pOut.
//	*/
func _sqlite3VdbeSorterRowkey(tls *libc.TLS, pCsr uintptr, pOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pKey, pSorter uintptr
	var _ /* nKey at bp+0 */ int32
	_, _ = pKey, pSorter /* Sorter key to copy into pOut */
	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 36))
	pKey = _vdbeSorterRowkey(tls, pSorter, bp)
	if _sqlite3VdbeMemClearAndResize(tls, pOut, *(*int32)(unsafe.Pointer(bp))) != 0 {
		return int32(SQLITE_NOMEM)
	}
	(*TMem)(unsafe.Pointer(pOut)).Fn = *(*int32)(unsafe.Pointer(bp))
	(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(int32((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Blob))
	libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pOut)).Fz, pKey, uint32(*(*int32)(unsafe.Pointer(bp))))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Compare the key in memory cell pVal with the key that the sorter cursor
//	** passed as the first argument currently points to. For the purposes of
//	** the comparison, ignore the rowid field at the end of each record.
//	**
//	** If the sorter cursor key contains any NULL values, consider it to be
//	** less than pVal. Even if pVal also contains NULL values.
//	**
//	** If an error occurs, return an SQLite error code (i.e. SQLITE_NOMEM).
//	** Otherwise, set *pRes to a negative, zero or positive value if the
//	** key in pVal is smaller than, equal to or larger than the current sorter
//	** key.
//	**
//	** This routine forms the core of the OP_SorterCompare opcode, which in
//	** turn is used to verify uniqueness when constructing a UNIQUE INDEX.
//	*/
func _sqlite3VdbeSorterCompare(tls *libc.TLS, pCsr uintptr, pVal uintptr, nKeyCol int32, pRes uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var pKey, pKeyInfo, pSorter, r2, v1 uintptr
	var _ /* nKey at bp+0 */ int32
	_, _, _, _, _, _ = i, pKey, pKeyInfo, pSorter, r2, v1 /* Sorter key to compare pVal with */
	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 36))
	r2 = (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpUnpacked
	pKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pCsr)).FpKeyInfo
	if r2 == uintptr(0) {
		v1 = _sqlite3VdbeAllocUnpackedRecord(tls, pKeyInfo)
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).FpUnpacked = v1
		r2 = v1
		if r2 == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		(*TUnpackedRecord)(unsafe.Pointer(r2)).FnField = uint16(uint16(nKeyCol))
	}
	pKey = _vdbeSorterRowkey(tls, pSorter, bp)
	_sqlite3VdbeRecordUnpack(tls, pKeyInfo, *(*int32)(unsafe.Pointer(bp)), pKey, r2)
	i = 0
	for {
		if !(i < nKeyCol) {
			break
		}
		if int32((*(*TMem)(unsafe.Pointer((*TUnpackedRecord)(unsafe.Pointer(r2)).FaMem + uintptr(i)*40))).Fflags)&int32(MEM_Null) != 0 {
			*(*int32)(unsafe.Pointer(pRes)) = -int32(1)
			return SQLITE_OK
		}
		goto _2
	_2:
		;
		i++
	}
	*(*int32)(unsafe.Pointer(pRes)) = _sqlite3VdbeRecordCompare(tls, (*TMem)(unsafe.Pointer(pVal)).Fn, (*TMem)(unsafe.Pointer(pVal)).Fz, r2)
	return SQLITE_OK
}

/************** End of vdbesort.c ********************************************/
/************** Begin file vdbevtab.c ****************************************/
/*
** 2020-03-23
**
** 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 implements virtual-tables for examining the bytecode content
** of a prepared statement.
 */
/* #include "sqliteInt.h" */

/************** End of vdbevtab.c ********************************************/
/************** Begin file memjournal.c **************************************/
/*
** 2008 October 7
**
** 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 use to implement an in-memory rollback journal.
** The in-memory rollback journal is used to journal transactions for
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
**
** Update:  The in-memory journal is also used to temporarily cache
** smaller journals that are not critical for power-loss recovery.
** For example, statement journals that are not too big will be held
** entirely in memory, thus reducing the number of file I/O calls, and
** more importantly, reducing temporary file creation events.  If these
** journals become too large for memory, they are spilled to disk.  But
** in the common case, they are usually small and no file I/O needs to
** occur.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/* Forward references to internal structures */
type TMemJournal = struct {
	F__ccgo_align [0]uint32
	FpMethod      uintptr
	FnChunkSize   int32
	FnSpill       int32
	FpFirst       uintptr
	Fendpoint     TFilePoint
	Freadpoint    TFilePoint
	Fflags        int32
	FpVfs         uintptr
	FzJournal     uintptr
	F__ccgo_pad9  [4]byte
}

type MemJournal = TMemJournal

type TFilePoint = struct {
	F__ccgo_align [0]uint32
	FiOffset      Tsqlite3_int64
	FpChunk       uintptr
	F__ccgo_pad2  [4]byte
}

type FilePoint = TFilePoint

type TFileChunk = struct {
	FpNext  uintptr
	FzChunk [8]Tu8
}

type FileChunk = TFileChunk

/*
** The rollback journal is composed of a linked list of these structures.
**
** The zChunk array is always at least 8 bytes in size - usually much more.
** Its actual size is stored in the MemJournal.nChunkSize variable.
 */
type TFileChunk1 = struct {
	FpNext  uintptr
	FzChunk [8]Tu8
}

type FileChunk1 = TFileChunk1

/*
** By default, allocate this many bytes of memory for each FileChunk object.
 */

/*
** For chunk size nChunkSize, return the number of bytes that should
** be allocated for each FileChunk structure.
 */

/*
** An instance of this object serves as a cursor into the rollback journal.
** The cursor can be either for reading or writing.
 */
type TFilePoint1 = struct {
	F__ccgo_align [0]uint32
	FiOffset      Tsqlite3_int64
	FpChunk       uintptr
	F__ccgo_pad2  [4]byte
}

type FilePoint1 = TFilePoint1

/*
** This structure is a subclass of sqlite3_file. Each open memory-journal
** is an instance of this class.
 */
type TMemJournal1 = struct {
	F__ccgo_align [0]uint32
	FpMethod      uintptr
	FnChunkSize   int32
	FnSpill       int32
	FpFirst       uintptr
	Fendpoint     TFilePoint
	Freadpoint    TFilePoint
	Fflags        int32
	FpVfs         uintptr
	FzJournal     uintptr
	F__ccgo_pad9  [4]byte
}

type MemJournal1 = TMemJournal1

// C documentation
//
//	/*
//	** Read data from the in-memory journal file.  This is the implementation
//	** of the sqlite3_vfs.xRead method.
//	*/
func _memjrnlRead(tls *libc.TLS, pJfd uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
	var iChunkOffset, iSpace, nCopy, nRead, v5 int32
	var iOff Tsqlite3_int64
	var p, pChunk, zOut, v2 uintptr
	var v3 bool
	var v6 int64
	_, _, _, _, _, _, _, _, _, _, _, _ = iChunkOffset, iOff, iSpace, nCopy, nRead, p, pChunk, zOut, v2, v3, v5, v6
	p = pJfd
	zOut = zBuf
	nRead = iAmt
	if int64(int64(iAmt))+iOfst > (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	if (*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FiOffset != iOfst || iOfst == 0 {
		iOff = 0
		pChunk = (*TMemJournal)(unsafe.Pointer(p)).FpFirst
		for {
			if !(pChunk != 0 && iOff+int64((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize) <= iOfst) {
				break
			}
			iOff += int64((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize)
			goto _1
		_1:
			;
			pChunk = (*TFileChunk)(unsafe.Pointer(pChunk)).FpNext
		}
	} else {
		pChunk = (*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FpChunk
	}
	iChunkOffset = int32(iOfst % int64((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize))
	for {
		iSpace = (*TMemJournal)(unsafe.Pointer(p)).FnChunkSize - iChunkOffset
		if nRead < (*TMemJournal)(unsafe.Pointer(p)).FnChunkSize-iChunkOffset {
			v5 = nRead
		} else {
			v5 = (*TMemJournal)(unsafe.Pointer(p)).FnChunkSize - iChunkOffset
		}
		nCopy = v5
		libc.Xmemcpy(tls, zOut, pChunk+4+uintptr(iChunkOffset), uint32(uint32(nCopy)))
		zOut += uintptr(nCopy)
		nRead -= iSpace
		iChunkOffset = 0
		goto _4
	_4:
		;
		if v3 = nRead >= 0; v3 {
			v2 = (*TFileChunk)(unsafe.Pointer(pChunk)).FpNext
			pChunk = v2
		}
		if !(v3 && v2 != uintptr(0) && nRead > 0) {
			break
		}
	}
	if pChunk != 0 {
		v6 = iOfst + int64(int64(iAmt))
	} else {
		v6 = 0
	}
	(*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FiOffset = v6
	(*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FpChunk = pChunk
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Free the list of FileChunk structures headed at MemJournal.pFirst.
//	*/
func _memjrnlFreeChunks(tls *libc.TLS, pFirst uintptr) {
	var pIter, pNext uintptr
	_, _ = pIter, pNext
	pIter = pFirst
	for {
		if !(pIter != 0) {
			break
		}
		pNext = (*TFileChunk)(unsafe.Pointer(pIter)).FpNext
		Xsqlite3_free(tls, pIter)
		goto _1
	_1:
		;
		pIter = pNext
	}
}

// C documentation
//
//	/*
//	** Flush the contents of memory to a real file on disk.
//	*/
func _memjrnlCreateFile(tls *libc.TLS, p uintptr) (r int32) {
	var copy1 TMemJournal
	var iOff Ti64
	var nChunk, rc int32
	var pIter, pReal uintptr
	_, _, _, _, _, _ = copy1, iOff, nChunk, pIter, pReal, rc
	pReal = p
	copy1 = *(*TMemJournal)(unsafe.Pointer(p))
	libc.Xmemset(tls, p, 0, uint32(64))
	rc = _sqlite3OsOpen(tls, copy1.FpVfs, copy1.FzJournal, pReal, copy1.Fflags, uintptr(0))
	if rc == SQLITE_OK {
		nChunk = copy1.FnChunkSize
		iOff = 0
		pIter = copy1.FpFirst
		for {
			if !(pIter != 0) {
				break
			}
			if iOff+int64(int64(nChunk)) > copy1.Fendpoint.FiOffset {
				nChunk = int32(copy1.Fendpoint.FiOffset - iOff)
			}
			rc = _sqlite3OsWrite(tls, pReal, pIter+4, nChunk, iOff)
			if rc != 0 {
				break
			}
			iOff += int64(int64(nChunk))
			goto _1
		_1:
			;
			pIter = (*TFileChunk)(unsafe.Pointer(pIter)).FpNext
		}
		if rc == SQLITE_OK {
			/* No error has occurred. Free the in-memory buffers. */
			_memjrnlFreeChunks(tls, copy1.FpFirst)
		}
	}
	if rc != SQLITE_OK {
		/* If an error occurred while creating or writing to the file, restore
		 ** the original before returning. This way, SQLite uses the in-memory
		 ** journal data to roll back changes made to the internal page-cache
		 ** before this function was called.  */
		_sqlite3OsClose(tls, pReal)
		*(*TMemJournal)(unsafe.Pointer(p)) = copy1
	}
	return rc
}

// C documentation
//
//	/*
//	** Write data to the file.
//	*/
func _memjrnlWrite(tls *libc.TLS, pJfd uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
	var iChunkOffset, iSpace, nWrite, rc, v1 int32
	var p, pChunk, pNew, zWrite, v2 uintptr
	_, _, _, _, _, _, _, _, _, _ = iChunkOffset, iSpace, nWrite, p, pChunk, pNew, rc, zWrite, v1, v2
	p = pJfd
	nWrite = iAmt
	zWrite = zBuf
	/* If the file should be created now, create it and write the new data
	 ** into the file on disk. */
	if (*TMemJournal)(unsafe.Pointer(p)).FnSpill > 0 && int64(int64(iAmt))+iOfst > int64((*TMemJournal)(unsafe.Pointer(p)).FnSpill) {
		rc = _memjrnlCreateFile(tls, p)
		if rc == SQLITE_OK {
			rc = _sqlite3OsWrite(tls, pJfd, zBuf, iAmt, iOfst)
		}
		return rc
	} else {
		/* An in-memory journal file should only ever be appended to. Random
		 ** access writes are not required. The only exception to this is when
		 ** the in-memory journal is being used by a connection using the
		 ** atomic-write optimization. In this case the first 28 bytes of the
		 ** journal file may be written as part of committing the transaction. */
		if iOfst > 0 && iOfst != (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
			_memjrnlTruncate(tls, pJfd, iOfst)
		}
		if iOfst == 0 && (*TMemJournal)(unsafe.Pointer(p)).FpFirst != 0 {
			libc.Xmemcpy(tls, (*TMemJournal)(unsafe.Pointer(p)).FpFirst+4, zBuf, uint32(uint32(iAmt)))
		} else {
			for nWrite > 0 {
				pChunk = (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FpChunk
				iChunkOffset = int32((*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset % int64((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize))
				if nWrite < (*TMemJournal)(unsafe.Pointer(p)).FnChunkSize-iChunkOffset {
					v1 = nWrite
				} else {
					v1 = (*TMemJournal)(unsafe.Pointer(p)).FnChunkSize - iChunkOffset
				}
				iSpace = v1
				if iChunkOffset == 0 {
					/* New chunk is required to extend the file. */
					pNew = Xsqlite3_malloc(tls, int32(libc.Uint32FromInt64(12)+uint32((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize-libc.Int32FromInt32(8))))
					if !(pNew != 0) {
						return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
					}
					(*TFileChunk)(unsafe.Pointer(pNew)).FpNext = uintptr(0)
					if pChunk != 0 {
						(*TFileChunk)(unsafe.Pointer(pChunk)).FpNext = pNew
					} else {
						(*TMemJournal)(unsafe.Pointer(p)).FpFirst = pNew
					}
					v2 = pNew
					(*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FpChunk = v2
					pChunk = v2
				}
				libc.Xmemcpy(tls, pChunk+4+uintptr(iChunkOffset), zWrite, uint32(uint32(iSpace)))
				zWrite += uintptr(iSpace)
				nWrite -= iSpace
				(*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset += int64(int64(iSpace))
			}
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Truncate the in-memory file.
//	*/
func _memjrnlTruncate(tls *libc.TLS, pJfd uintptr, size Tsqlite_int64) (r int32) {
	var iOff Ti64
	var p, pIter uintptr
	_, _, _ = iOff, p, pIter
	p = pJfd
	if size < (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
		pIter = uintptr(0)
		if size == 0 {
			_memjrnlFreeChunks(tls, (*TMemJournal)(unsafe.Pointer(p)).FpFirst)
			(*TMemJournal)(unsafe.Pointer(p)).FpFirst = uintptr(0)
		} else {
			iOff = int64((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize)
			pIter = (*TMemJournal)(unsafe.Pointer(p)).FpFirst
			for {
				if !(pIter != 0 && iOff < size) {
					break
				}
				iOff += int64((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize)
				goto _1
			_1:
				;
				pIter = (*TFileChunk)(unsafe.Pointer(pIter)).FpNext
			}
			if pIter != 0 {
				_memjrnlFreeChunks(tls, (*TFileChunk)(unsafe.Pointer(pIter)).FpNext)
				(*TFileChunk)(unsafe.Pointer(pIter)).FpNext = uintptr(0)
			}
		}
		(*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FpChunk = pIter
		(*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset = size
		(*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FpChunk = uintptr(0)
		(*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FiOffset = 0
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Close the file.
//	*/
func _memjrnlClose(tls *libc.TLS, pJfd uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pJfd
	_memjrnlFreeChunks(tls, (*TMemJournal)(unsafe.Pointer(p)).FpFirst)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Sync the file.
//	**
//	** If the real file has been created, call its xSync method. Otherwise,
//	** syncing an in-memory journal is a no-op.
//	*/
func _memjrnlSync(tls *libc.TLS, pJfd uintptr, flags int32) (r int32) {
	_ = pJfd
	_ = flags
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Query the size of the file in bytes.
//	*/
func _memjrnlFileSize(tls *libc.TLS, pJfd uintptr, pSize uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pJfd
	*(*Tsqlite_int64)(unsafe.Pointer(pSize)) = (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Table of methods for MemJournal sqlite3_file object.
//	*/
var _MemJournalMethods = Tsqlite3_io_methods1{
	FiVersion: int32(1),
}

func init() {
	p := unsafe.Pointer(&_MemJournalMethods)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_memjrnlClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_memjrnlRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_memjrnlWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_memjrnlTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_memjrnlSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_memjrnlFileSize)
}

// C documentation
//
//	/*
//	** Open a journal file.
//	**
//	** The behaviour of the journal file depends on the value of parameter
//	** nSpill. If nSpill is 0, then the journal file is always create and
//	** accessed using the underlying VFS. If nSpill is less than zero, then
//	** all content is always stored in main-memory. Finally, if nSpill is a
//	** positive value, then the journal file is initially created in-memory
//	** but may be flushed to disk later on. In this case the journal file is
//	** flushed to disk either when it grows larger than nSpill bytes in size,
//	** or when sqlite3JournalCreate() is called.
//	*/
func _sqlite3JournalOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pJfd uintptr, flags int32, nSpill int32) (r int32) {
	var p uintptr
	_ = p
	p = pJfd
	/* Zero the file-handle object. If nSpill was passed zero, initialize
	 ** it using the sqlite3OsOpen() function of the underlying VFS. In this
	 ** case none of the code in this module is executed as a result of calls
	 ** made on the journal file-handle.  */
	libc.Xmemset(tls, p, 0, uint32(64))
	if nSpill == 0 {
		return _sqlite3OsOpen(tls, pVfs, zName, pJfd, flags, uintptr(0))
	}
	if nSpill > 0 {
		(*TMemJournal)(unsafe.Pointer(p)).FnChunkSize = nSpill
	} else {
		(*TMemJournal)(unsafe.Pointer(p)).FnChunkSize = int32(uint32(libc.Int32FromInt32(8)+libc.Int32FromInt32(MEMJOURNAL_DFLT_FILECHUNKSIZE)) - libc.Uint32FromInt64(12))
	}
	(*Tsqlite3_file)(unsafe.Pointer(pJfd)).FpMethods = uintptr(unsafe.Pointer(&_MemJournalMethods))
	(*TMemJournal)(unsafe.Pointer(p)).FnSpill = nSpill
	(*TMemJournal)(unsafe.Pointer(p)).Fflags = flags
	(*TMemJournal)(unsafe.Pointer(p)).FzJournal = zName
	(*TMemJournal)(unsafe.Pointer(p)).FpVfs = pVfs
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Open an in-memory journal file.
//	*/
func _sqlite3MemJournalOpen(tls *libc.TLS, pJfd uintptr) {
	_sqlite3JournalOpen(tls, uintptr(0), uintptr(0), pJfd, 0, -int32(1))
}

// C documentation
//
//	/*
//	** The file-handle passed as the only argument is open on a journal file.
//	** Return true if this "journal file" is currently stored in heap memory,
//	** or false otherwise.
//	*/
func _sqlite3JournalIsInMemory(tls *libc.TLS, p uintptr) (r int32) {
	return libc.BoolInt32((*Tsqlite3_file)(unsafe.Pointer(p)).FpMethods == uintptr(unsafe.Pointer(&_MemJournalMethods)))
}

// C documentation
//
//	/*
//	** Return the number of bytes required to store a JournalFile that uses vfs
//	** pVfs to create the underlying on-disk files.
//	*/
func _sqlite3JournalSize(tls *libc.TLS, pVfs uintptr) (r int32) {
	var v1 int32
	_ = v1
	if (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile > libc.Int32FromInt64(64) {
		v1 = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile
	} else {
		v1 = libc.Int32FromInt64(64)
	}
	return v1
}

/************** End of memjournal.c ******************************************/
/************** Begin file walker.c ******************************************/
/*
** 2008 August 16
**
** 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 routines used for walking the parser tree for
** an SQL statement.
 */
/* #include "sqliteInt.h" */
/* #include <stdlib.h> */
/* #include <string.h> */

// C documentation
//
//	/*
//	** Walk all expressions linked into the list of Window objects passed
//	** as the second argument.
//	*/
func _walkWindowList(tls *libc.TLS, pWalker uintptr, pList uintptr, bOneOnly int32) (r int32) {
	var pWin uintptr
	var rc int32
	_, _ = pWin, rc
	pWin = pList
	for {
		if !(pWin != 0) {
			break
		}
		rc = _sqlite3WalkExprList(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy)
		if rc != 0 {
			return int32(WRC_Abort)
		}
		rc = _sqlite3WalkExprList(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpPartition)
		if rc != 0 {
			return int32(WRC_Abort)
		}
		rc = _sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpFilter)
		if rc != 0 {
			return int32(WRC_Abort)
		}
		rc = _sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpStart)
		if rc != 0 {
			return int32(WRC_Abort)
		}
		rc = _sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpEnd)
		if rc != 0 {
			return int32(WRC_Abort)
		}
		if bOneOnly != 0 {
			break
		}
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Walk an expression tree.  Invoke the callback once for each node
//	** of the expression, while descending.  (In other words, the callback
//	** is invoked before visiting children.)
//	**
//	** The return value from the callback should be one of the WRC_*
//	** constants to specify how to proceed with the walk.
//	**
//	**    WRC_Continue      Continue descending down the tree.
//	**
//	**    WRC_Prune         Do not descend into child nodes, but allow
//	**                      the walk to continue with sibling nodes.
//	**
//	**    WRC_Abort         Do no more callbacks.  Unwind the stack and
//	**                      return from the top-level walk call.
//	**
//	** The return value from this routine is WRC_Abort to abandon the tree walk
//	** and WRC_Continue to continue.
//	*/
func _sqlite3WalkExprNN(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var rc int32
	_ = rc
	for int32(1) != 0 {
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TWalker)(unsafe.Pointer(pWalker)).FxExprCallback})))(tls, pWalker, pExpr)
		if rc != 0 {
			return rc & int32(WRC_Abort)
		}
		if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Leaf)) != libc.Uint32FromInt32(0)) {
			if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 && _sqlite3WalkExprNN(tls, pWalker, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft) != 0 {
				return int32(WRC_Abort)
			}
			if (*TExpr)(unsafe.Pointer(pExpr)).FpRight != 0 {
				pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
				continue
			} else {
				if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
					if _sqlite3WalkSelect(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 20))) != 0 {
						return int32(WRC_Abort)
					}
				} else {
					if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != 0 {
						if _sqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 20))) != 0 {
							return int32(WRC_Abort)
						}
					}
					if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
						if _walkWindowList(tls, pWalker, *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)), int32(1)) != 0 {
							return int32(WRC_Abort)
						}
					}
				}
			}
		}
		break
	}
	return WRC_Continue
}

func _sqlite3WalkExpr(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var v1 int32
	_ = v1
	if pExpr != 0 {
		v1 = _sqlite3WalkExprNN(tls, pWalker, pExpr)
	} else {
		v1 = WRC_Continue
	}
	return v1
}

// C documentation
//
//	/*
//	** Call sqlite3WalkExpr() for every expression in list p or until
//	** an abort request is seen.
//	*/
func _sqlite3WalkExprList(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var i int32
	var pItem uintptr
	_, _ = i, pItem
	if p != 0 {
		i = (*TExprList)(unsafe.Pointer(p)).FnExpr
		pItem = p + 8
		for {
			if !(i > 0) {
				break
			}
			if _sqlite3WalkExpr(tls, pWalker, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr) != 0 {
				return int32(WRC_Abort)
			}
			goto _1
		_1:
			;
			i--
			pItem += 20
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This is a no-op callback for Walker->xSelectCallback2.  If this
//	** callback is set, then the Select->pWinDefn list is traversed.
//	*/
func _sqlite3WalkWinDefnDummyCallback(tls *libc.TLS, pWalker uintptr, p uintptr) {
	_ = pWalker
	_ = p
	/* No-op */
}

// C documentation
//
//	/*
//	** Walk all expressions associated with SELECT statement p.  Do
//	** not invoke the SELECT callback on p, but do (of course) invoke
//	** any expr callbacks and SELECT callbacks that come from subqueries.
//	** Return WRC_Abort or WRC_Continue.
//	*/
func _sqlite3WalkSelectExpr(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var pParse, v1 uintptr
	var rc int32
	var v2 bool
	_, _, _, _ = pParse, rc, v1, v2
	if _sqlite3WalkExprList(tls, pWalker, (*TSelect)(unsafe.Pointer(p)).FpEList) != 0 {
		return int32(WRC_Abort)
	}
	if _sqlite3WalkExpr(tls, pWalker, (*TSelect)(unsafe.Pointer(p)).FpWhere) != 0 {
		return int32(WRC_Abort)
	}
	if _sqlite3WalkExprList(tls, pWalker, (*TSelect)(unsafe.Pointer(p)).FpGroupBy) != 0 {
		return int32(WRC_Abort)
	}
	if _sqlite3WalkExpr(tls, pWalker, (*TSelect)(unsafe.Pointer(p)).FpHaving) != 0 {
		return int32(WRC_Abort)
	}
	if _sqlite3WalkExprList(tls, pWalker, (*TSelect)(unsafe.Pointer(p)).FpOrderBy) != 0 {
		return int32(WRC_Abort)
	}
	if _sqlite3WalkExpr(tls, pWalker, (*TSelect)(unsafe.Pointer(p)).FpLimit) != 0 {
		return int32(WRC_Abort)
	}
	if (*TSelect)(unsafe.Pointer(p)).FpWinDefn != 0 {
		if v2 = (*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback2 == __ccgo_fp(_sqlite3WalkWinDefnDummyCallback); !v2 {
			v1 = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
			pParse = v1
		}
		if v2 || v1 != uintptr(0) && int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) || (*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback2 == __ccgo_fp(_sqlite3SelectPopWith) {
			/* The following may return WRC_Abort if there are unresolvable
			 ** symbols (e.g. a table that does not exist) in a window definition. */
			rc = _walkWindowList(tls, pWalker, (*TSelect)(unsafe.Pointer(p)).FpWinDefn, 0)
			return rc
		}
	}
	return WRC_Continue
}

// 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 (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 && _sqlite3WalkSelect(tls, pWalker, (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect) != 0 {
				return int32(WRC_Abort)
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x4>>2)) != 0 && _sqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer(pItem + 64))) != 0 {
				return int32(WRC_Abort)
			}
			goto _1
		_1:
			;
			i--
			pItem += 72
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Call sqlite3WalkExpr() for every expression in Select statement p.
//	** Invoke sqlite3WalkSelect() for subqueries in the FROM clause and
//	** on the compound select chain, p->pPrior.
//	**
//	** If it is not NULL, the xSelectCallback() callback is invoked before
//	** the walk of the expressions and FROM clause. The xSelectCallback2()
//	** method is invoked following the walk of the expressions and FROM clause,
//	** but only if both xSelectCallback and xSelectCallback2 are both non-NULL
//	** and if the expressions and FROM clause both return WRC_Continue;
//	**
//	** Return WRC_Continue under normal conditions.  Return WRC_Abort if
//	** there is an abort request.
//	**
//	** If the Walker does not have an xSelectCallback() then this routine
//	** is a no-op returning WRC_Continue.
//	*/
func _sqlite3WalkSelect(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var rc int32
	_ = rc
	if p == uintptr(0) {
		return WRC_Continue
	}
	if (*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback == uintptr(0) {
		return WRC_Continue
	}
	for cond := true; cond; cond = p != uintptr(0) {
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback})))(tls, pWalker, p)
		if rc != 0 {
			return rc & int32(WRC_Abort)
		}
		if _sqlite3WalkSelectExpr(tls, pWalker, p) != 0 || _sqlite3WalkSelectFrom(tls, pWalker, p) != 0 {
			return int32(WRC_Abort)
		}
		if (*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback2 != 0 {
			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback2})))(tls, pWalker, p)
		}
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
	}
	return WRC_Continue
}

// C documentation
//
//	/* Increase the walkerDepth when entering a subquery, and
//	** decrease when leaving the subquery.
//	*/
func _sqlite3WalkerDepthIncrease(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	_ = pSelect
	(*TWalker)(unsafe.Pointer(pWalker)).FwalkerDepth++
	return WRC_Continue
}

func _sqlite3WalkerDepthDecrease(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	_ = pSelect
	(*TWalker)(unsafe.Pointer(pWalker)).FwalkerDepth--
}

// C documentation
//
//	/*
//	** No-op routine for the parse-tree walker.
//	**
//	** When this routine is the Walker.xExprCallback then expression trees
//	** are walked without any actions being taken at each node.  Presumably,
//	** when this routine is used for Walker.xExprCallback then
//	** Walker.xSelectCallback is set to do something useful for every
//	** subquery in the parser tree.
//	*/
func _sqlite3ExprWalkNoop(tls *libc.TLS, NotUsed uintptr, NotUsed2 uintptr) (r int32) {
	_ = NotUsed
	_ = NotUsed2
	return WRC_Continue
}

// C documentation
//
//	/*
//	** No-op routine for the parse-tree walker for SELECT statements.
//	** subquery in the parser tree.
//	*/
func _sqlite3SelectWalkNoop(tls *libc.TLS, NotUsed uintptr, NotUsed2 uintptr) (r int32) {
	_ = NotUsed
	_ = NotUsed2
	return WRC_Continue
}

/************** End of walker.c **********************************************/
/************** Begin file resolve.c *****************************************/
/*
** 2008 August 18
**
** 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 routines used for walking the parser tree and
** resolve all identifiers by associating them with a particular
** table and column.
 */
/* #include "sqliteInt.h" */

/*
** Magic table number to mean the EXCLUDED table in an UPSERT statement.
 */

// C documentation
//
//	/*
//	** Walk the expression tree pExpr and increase the aggregate function
//	** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node.
//	** This needs to occur when copying a TK_AGG_FUNCTION node from an
//	** outer query into an inner subquery.
//	**
//	** incrAggFunctionDepth(pExpr,n) is the main routine.  incrAggDepth(..)
//	** is a helper function - a callback for the tree walker.
//	**
//	** See also the sqlite3WindowExtraAggFuncDepth() routine in window.c
//	*/
func _incrAggDepth(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var p1 uintptr
	_ = p1
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_FUNCTION) {
		p1 = pExpr + 2
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) + *(*int32)(unsafe.Pointer(pWalker + 24)))
	}
	return WRC_Continue
}

func _incrAggFunctionDepth(tls *libc.TLS, pExpr uintptr, N int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	if N > 0 {
		libc.Xmemset(tls, bp, 0, uint32(28))
		(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_incrAggDepth)
		*(*int32)(unsafe.Pointer(bp + 24)) = N
		_sqlite3WalkExpr(tls, bp, pExpr)
	}
}

// C documentation
//
//	/*
//	** Turn the pExpr expression into an alias for the iCol-th column of the
//	** result set in pEList.
//	**
//	** If the reference is followed by a COLLATE operator, then make sure
//	** the COLLATE operator is preserved.  For example:
//	**
//	**     SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
//	**
//	** Should be transformed into:
//	**
//	**     SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
//	**
//	** The nSubquery parameter specifies how many levels of subquery the
//	** alias is removed from the original expression.  The usual value is
//	** zero but it might be more if the alias is contained within a subquery
//	** of the original expression.  The Expr.op2 field of TK_AGG_FUNCTION
//	** structures must be increased by the nSubquery amount.
//	*/
func _resolveAlias(tls *libc.TLS, pParse uintptr, pEList uintptr, iCol int32, pExpr uintptr, nSubquery int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pDup, pOrig uintptr
	var _ /* temp at bp+0 */ TExpr
	_, _, _ = db, pDup, pOrig /* The database connection */
	pOrig = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(iCol)*20))).FpExpr
	if (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo != 0 {
		return
	}
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pDup = _sqlite3ExprDup(tls, db, pOrig, 0)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3ExprDelete(tls, db, pDup)
		pDup = uintptr(0)
	} else {
		_incrAggFunctionDepth(tls, pDup, nSubquery)
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE) {
			pDup = _sqlite3ExprAddCollateString(tls, pParse, pDup, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
		}
		libc.Xmemcpy(tls, bp, pDup, uint32(52))
		libc.Xmemcpy(tls, pDup, pExpr, uint32(52))
		libc.Xmemcpy(tls, pExpr, bp, uint32(52))
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
			if *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)) != uintptr(0) {
				(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FpOwner = pExpr
			}
		}
		_sqlite3ExprDeferredDelete(tls, pParse, pDup)
	}
}

// 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 + 8 + 4)) & 0x3 >> 0))
	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 !(*(*int8)(unsafe.Pointer(zSpan + uintptr(n))) != 0 && int32(*(*int8)(unsafe.Pointer(zSpan + uintptr(n)))) != int32('.')) {
			break
		}
		goto _1
	_1:
		;
		n++
	}
	if zDb != 0 && (Xsqlite3_strnicmp(tls, zSpan, zDb, n) != 0 || int32(*(*int8)(unsafe.Pointer(zDb + uintptr(n)))) != 0) {
		return 0
	}
	zSpan += uintptr(n + int32(1))
	n = 0
	for {
		if !(*(*int8)(unsafe.Pointer(zSpan + uintptr(n))) != 0 && int32(*(*int8)(unsafe.Pointer(zSpan + uintptr(n)))) != int32('.')) {
			break
		}
		goto _2
	_2:
		;
		n++
	}
	if zTab != 0 && (Xsqlite3_strnicmp(tls, zSpan, zTab, n) != 0 || int32(*(*int8)(unsafe.Pointer(zTab + uintptr(n)))) != 0) {
		return 0
	}
	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)(unsafe.Pointer(pbRowid)) = int32(1)
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Return TRUE if the double-quoted string  mis-feature should be supported.
//	*/
func _areDoubleQuotedStringsEnabled(tls *libc.TLS, db uintptr, pTopNC uintptr) (r int32) {
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		return int32(1)
	} /* Always support for legacy schemas */
	if (*TNameContext)(unsafe.Pointer(pTopNC)).FncFlags&int32(NC_IsDDL) != 0 {
		/* Currently parsing a DDL statement */
		if _sqlite3WritableSchema(tls, db) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DqsDML) != uint64(0) {
			return int32(1)
		}
		return libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DqsDDL) != uint64(0))
	} else {
		/* Currently parsing a DML statement */
		return libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DqsDML) != uint64(0))
	}
	return r
}

// C documentation
//
//	/*
//	** The argument is guaranteed to be a non-NULL Expr node of type TK_COLUMN.
//	** return the appropriate colUsed mask.
//	*/
func _sqlite3ExprColUsed(tls *libc.TLS, pExpr uintptr) (r TBitmask) {
	var n int32
	var pExTab uintptr
	var v1 uint64
	_, _, _ = n, pExTab, v1
	n = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
	pExTab = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
	if (*TTable)(unsafe.Pointer(pExTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pExTab)).FaCol + uintptr(n)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
		if int32((*TTable)(unsafe.Pointer(pExTab)).FnCol) >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
			v1 = uint64(-libc.Int32FromInt32(1))
		} else {
			v1 = libc.Uint64FromInt32(1)<<(*TTable)(unsafe.Pointer(pExTab)).FnCol - uint64(1)
		}
		return v1
	} else {
		if n >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
			n = int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
		}
		return libc.Uint64FromInt32(1) << n
	}
	return r
}

// C documentation
//
//	/*
//	** Create a new expression term for the column specified by pMatch and
//	** iColumn.  Append this new expression term to the FULL JOIN Match set
//	** in *ppList.  Create a new *ppList if this is the first term in the
//	** set.
//	*/
func _extendFJMatch(tls *libc.TLS, pParse uintptr, ppList uintptr, pMatch uintptr, iColumn Ti16) {
	var pNew uintptr
	_ = pNew
	pNew = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_COLUMN), uintptr(0), 0)
	if pNew != 0 {
		(*TExpr)(unsafe.Pointer(pNew)).FiTable = (*TSrcItem)(unsafe.Pointer(pMatch)).FiCursor
		(*TExpr)(unsafe.Pointer(pNew)).FiColumn = iColumn
		(*TExpr)(unsafe.Pointer(pNew)).Fy.FpTab = (*TSrcItem)(unsafe.Pointer(pMatch)).FpTab
		*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(libc.Int32FromInt32(EP_CanBeNull))
		*(*uintptr)(unsafe.Pointer(ppList)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(ppList)), pNew)
	}
}

// C documentation
//
//	/*
//	** Return TRUE (non-zero) if zTab is a valid name for the schema table pTab.
//	*/
func _isValidSchemaTableName(tls *libc.TLS, zTab uintptr, pTab uintptr, pSchema uintptr) (r int32) {
	var zLegacy uintptr
	_ = zLegacy
	if Xsqlite3_strnicmp(tls, zTab, __ccgo_ts+7898, int32(7)) != 0 {
		return 0
	}
	zLegacy = (*TTable)(unsafe.Pointer(pTab)).FzName
	if libc.Xstrcmp(tls, zLegacy+uintptr(7), __ccgo_ts+7906+7) == 0 {
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+7925+7) == 0 {
			return int32(1)
		}
		if pSchema == uintptr(0) {
			return 0
		}
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+7439+7) == 0 {
			return int32(1)
		}
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+7944+7) == 0 {
			return int32(1)
		}
	} else {
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+7944+7) == 0 {
			return int32(1)
		}
	}
	return 0
}

// 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(48)
	defer tls.Free(48)
	var cnt, cntTab, eNewExprOp, hit, i, iCol, j, nSubquery, op, v5 int32
	var db, pCol, pEList, pItem, pMatch, pOrig, pSchema, pSrcList, pTab, pTopNC, pUpsert, zAs, zCol, zErr, v10 uintptr
	var hCol, hCol1 Tu8
	var v7, v8 uint32
	var _ /* bRowid at bp+4 */ int32
	var _ /* pFJMatch at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cnt, cntTab, db, eNewExprOp, hCol, hCol1, hit, i, iCol, j, nSubquery, op, pCol, pEList, pItem, pMatch, pOrig, pSchema, pSrcList, pTab, pTopNC, pUpsert, zAs, zCol, zErr, v10, v5, v7, 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)                                                                                                                                                                                                                                                                /* A column of pTab */
	*(*uintptr)(unsafe.Pointer(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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FzDbSName, zDb) == 0 {
					pSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema
					break
				}
				goto _1
			_1:
				;
				i++
			}
			if i == (*Tsqlite3)(unsafe.Pointer(db)).FnDb && _sqlite3StrICmp(tls, __ccgo_ts+7958, zDb) == 0 {
				/* This branch is taken when the main database has been renamed
				 ** using SQLITE_DBCONFIG_MAINDBNAME. */
				pSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema
				zDb = (*(*TDb)(unsafe.Pointer((*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)).FpTab
				if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x2000>>13)) != 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
					pEList = (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpEList
					j = 0
					for {
						if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
							break
						}
						*(*int32)(unsafe.Pointer(bp + 4)) = 0 /* True if possible rowid match */
						if !(_sqlite3MatchEName(tls, pEList+8+uintptr(j)*20, zCol, zTab, zDb, bp+4) != 0) {
							goto _3
						}
						if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
							if cnt > 0 {
								if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x400>>10)) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 48)), 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)(unsafe.Pointer(bp)))
									*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
								} else {
									if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
										/* An INNER or LEFT JOIN.  Use the left-most table */
										goto _3
									} else {
										if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) == 0 {
											/* A RIGHT JOIN.  Use the right-most table */
											cnt = 0
											_sqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
											*(*uintptr)(unsafe.Pointer(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++
							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++
						pMatch = pItem
						(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(int16(j))
						libc.SetBitFieldPtr16Uint32(pEList+8+uintptr(j)*20+8+4, libc.Uint32FromInt32(1), 6, 0x40)
						/* rowid cannot be part of a USING clause - assert() this. */
						if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*20 + 8 + 4))&0x80>>7)) != 0 {
							break
						}
						goto _3
					_3:
						;
						j++
					}
					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+7963) != 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, pSchema) != 0) {
								goto _2
							}
						}
					}
					if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
						_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr+44)
					}
				}
				hCol = _sqlite3StrIHash(tls, zCol)
				j = 0
				pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
				for {
					if !(j < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
						break
					}
					if int32((*TColumn)(unsafe.Pointer(pCol)).FhName) == int32(int32(hCol)) && _sqlite3StrICmp(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, zCol) == 0 {
						if cnt > 0 {
							if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x400>>10)) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 48)), 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)(unsafe.Pointer(bp)))
								*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
							} else {
								if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
									/* An INNER or LEFT JOIN.  Use the left-most table */
									goto _4
								} else {
									if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) == 0 {
										/* A RIGHT JOIN.  Use the right-most table */
										cnt = 0
										_sqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
										*(*uintptr)(unsafe.Pointer(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++
						pMatch = pItem
						/* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
						if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
							v5 = -int32(1)
						} else {
							v5 = int32(int16(int16(j)))
						}
						(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(v5)
						if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x2000>>13)) != 0 {
							_sqlite3SrcItemColumnUsed(tls, pItem, j)
						}
						break
					}
					goto _4
				_4:
					;
					j++
					pCol += 12
				}
				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++
					pMatch = pItem
				}
				goto _2
			_2:
				;
				i++
				pItem += 72
			}
			if pMatch != 0 {
				(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSrcItem)(unsafe.Pointer(pMatch)).FiCursor
				(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = (*TSrcItem)(unsafe.Pointer(pMatch)).FpTab
				if int32((*TSrcItem)(unsafe.Pointer(pMatch)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
					*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_CanBeNull))
				}
				pSchema = (*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab)).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 = int32((*TParse)(unsafe.Pointer(pParse)).FeTriggerOp)
				if (*TParse)(unsafe.Pointer(pParse)).FbReturning != 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+7965, 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+7969, 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 + 8))
				if pUpsert != 0 && _sqlite3StrICmp(tls, __ccgo_ts+7973, zTab) == 0 {
					pTab = (*(*TSrcItem)(unsafe.Pointer((*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc + 8))).FpTab
					(*TExpr)(unsafe.Pointer(pExpr)).FiTable = int32(EXCLUDED_TABLE_NUMBER)
				}
			}
			if pTab != 0 {
				hCol1 = _sqlite3StrIHash(tls, zCol)
				pSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
				cntTab++
				iCol = 0
				pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
				for {
					if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
						break
					}
					if int32((*TColumn)(unsafe.Pointer(pCol)).FhName) == int32(int32(hCol1)) && _sqlite3StrICmp(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, zCol) == 0 {
						if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
							iCol = -int32(1)
						}
						break
					}
					goto _6
				_6:
					;
					iCol++
					pCol += 12
				}
				if iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) && _sqlite3IsRowid(tls, zCol) != 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) {
					/* IMP: R-51414-32910 */
					iCol = -int32(1)
				}
				if iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
					cnt++
					pMatch = uintptr(0)
					if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == int32(EXCLUDED_TABLE_NUMBER) {
						if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
							(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(int16(iCol))
							(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = pTab
							eNewExprOp = int32(TK_COLUMN)
						} else {
							(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TUpsert)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNC + 8)))).FregData + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(int16(iCol))))
							eNewExprOp = int32(TK_REGISTER)
						}
					} else {
						(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = pTab
						if (*TParse)(unsafe.Pointer(pParse)).FbReturning != 0 {
							eNewExprOp = int32(TK_REGISTER)
							(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = uint8(TK_COLUMN)
							(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(int16(iCol))
							(*TExpr)(unsafe.Pointer(pExpr)).FiTable = *(*int32)(unsafe.Pointer(pNC + 8)) + (int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1))*(*TExpr)(unsafe.Pointer(pExpr)).FiTable + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(int16(iCol)))) + int32(1)
						} else {
							(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(int16(iCol))
							eNewExprOp = int32(TK_TRIGGER)
							if iCol < 0 {
								(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(SQLITE_AFF_INTEGER)
							} else {
								if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == 0 {
									if iCol >= int32(32) {
										v7 = uint32(0xffffffff)
									} else {
										v7 = libc.Uint32FromInt32(1) << iCol
									}
									*(*Tu32)(unsafe.Pointer(pParse + 148)) |= v7
								} else {
									if iCol >= int32(32) {
										v8 = uint32(0xffffffff)
									} else {
										v8 = libc.Uint32FromInt32(1) << iCol
									}
									*(*Tu32)(unsafe.Pointer(pParse + 152)) |= v8
								}
							}
						}
					}
				}
			}
		}
		/*
		 ** 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)).FpTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) || int32(uint32(*(*uint16)(unsafe.Pointer(pMatch + 36 + 4))&0x2000>>13)) != 0) {
			cnt = cntTab
			if int32(uint32(*(*uint16)(unsafe.Pointer(pMatch + 36 + 4))&0x2000>>13)) == 0 {
				(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(-int32(1))
			}
			(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(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 + 8))
			j = 0
			for {
				if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
					break
				}
				zAs = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*20))).FzEName
				if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME && Xsqlite3_stricmp(tls, zAs, zCol) == 0 {
					pOrig = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*20))).FpExpr
					if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowAgg) == 0 && (*TExpr)(unsafe.Pointer(pOrig)).Fflags&uint32(libc.Int32FromInt32(EP_Agg)) != uint32(0) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7982, libc.VaList(bp+16, zAs))
						return int32(WRC_Abort)
					}
					if (*TExpr)(unsafe.Pointer(pOrig)).Fflags&uint32(libc.Int32FromInt32(EP_Win)) != uint32(0) && ((*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowWin) == 0 || pNC != pTopNC) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8013, libc.VaList(bp+16, zAs))
						return int32(WRC_Abort)
					}
					if _sqlite3ExprVectorSize(tls, pOrig) != int32(1) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8050, 0)
						return int32(WRC_Abort)
					}
					_resolveAlias(tls, pParse, pEList, j, pExpr, nSubquery)
					cnt = int32(1)
					pMatch = uintptr(0)
					if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
						_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr)
					}
					goto lookupname_end
				}
				goto _9
			_9:
				;
				j++
			}
		}
		/* 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++
	}
	/*
	 ** 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&uint32(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+8068, libc.VaList(bp+16, zCol))
			(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_STRING)
			libc.Xmemset(tls, pExpr+44, 0, uint32(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)(unsafe.Pointer(bp)) != 0 {
			if (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnExpr == cnt-int32(1) {
				if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Leaf)) != uint32(0) {
					*(*Tu32)(unsafe.Pointer(pExpr + 4)) &= uint32(^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 + 8103
				*(*uintptr)(unsafe.Pointer(pExpr + 20)) = *(*uintptr)(unsafe.Pointer(bp))
				cnt = int32(1)
				goto lookupname_end
			} else {
				_sqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
				*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			}
		}
		if cnt == 0 {
			v10 = __ccgo_ts + 8112
		} else {
			v10 = __ccgo_ts + 8127
		}
		zErr = v10
		if zDb != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8149, libc.VaList(bp+16, zErr, zDb, zTab, zCol))
		} else {
			if zTab != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8162, libc.VaList(bp+16, zErr, zTab, zCol))
			} else {
				if cnt == 0 && (*TExpr)(unsafe.Pointer(pRight)).Fflags&uint32(libc.Int32FromInt32(EP_DblQuoted)) != uint32(0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8172, libc.VaList(bp+16, zErr, zCol))
				} else {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8233, libc.VaList(bp+16, zErr, zCol))
				}
			}
		}
		_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
		(*TNameContext)(unsafe.Pointer(pTopNC)).FnNcErr++
		eNewExprOp = int32(TK_NULL)
	}
	/* Remove all substructure from pExpr */
	if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(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)(unsafe.Pointer(pExpr + 4)) |= uint32(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)(unsafe.Pointer(pMatch + 56)) |= _sqlite3ExprColUsed(tls, pExpr)
		} else {
			libc.SetBitFieldPtr16Uint32(pMatch+36+4, libc.Uint32FromInt32(1), 14, 0x4000)
		}
	}
	(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(uint8(eNewExprOp))
	goto lookupname_end
lookupname_end:
	;
	if cnt == int32(1) {
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FxAuth != 0 && (int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || int32((*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++
			if pTopNC == pNC {
				break
			}
			pTopNC = (*TNameContext)(unsafe.Pointer(pTopNC)).FpNext
			goto _11
		_11:
		}
		return int32(WRC_Prune)
	} else {
		return int32(WRC_Abort)
	}
	return r
}

// C documentation
//
//	/*
//	** Allocate and return a pointer to an expression to load the column iCol
//	** from datasource iSrc in SrcList pSrc.
//	*/
func _sqlite3CreateColumnExpr(tls *libc.TLS, db uintptr, pSrc uintptr, iSrc int32, iCol int32) (r uintptr) {
	var p, pItem, pTab, v1 uintptr
	var v2 uint64
	var v3 int32
	_, _, _, _, _, _ = p, pItem, pTab, v1, v2, v3
	p = _sqlite3ExprAlloc(tls, db, int32(TK_COLUMN), uintptr(0), 0)
	if p != 0 {
		pItem = pSrc + 8 + uintptr(iSrc)*72
		v1 = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
		(*TExpr)(unsafe.Pointer(p)).Fy.FpTab = v1
		pTab = v1
		(*TExpr)(unsafe.Pointer(p)).FiTable = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
		if int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).Fy.FpTab)).FiPKey) == iCol {
			(*TExpr)(unsafe.Pointer(p)).FiColumn = int16(-int32(1))
		} else {
			(*TExpr)(unsafe.Pointer(p)).FiColumn = int16(int16(iCol))
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
				if int32((*TTable)(unsafe.Pointer(pTab)).FnCol) >= int32(64) {
					v2 = uint64(-libc.Int32FromInt32(1))
				} else {
					v2 = libc.Uint64FromInt32(1)<<(*TTable)(unsafe.Pointer(pTab)).FnCol - uint64(1)
				}
				(*TSrcItem)(unsafe.Pointer(pItem)).FcolUsed = v2
			} else {
				if iCol >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
					v3 = int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
				} else {
					v3 = iCol
				}
				*(*TBitmask)(unsafe.Pointer(pItem + 56)) |= libc.Uint64FromInt32(1) << v3
			}
		}
	}
	return p
}

// C documentation
//
//	/*
//	** Report an error that an expression is not valid for some set of
//	** pNC->ncFlags values determined by validMask.
//	**
//	** static void notValid(
//	**   Parse *pParse,       // Leave error message here
//	**   NameContext *pNC,    // The name context
//	**   const char *zMsg,    // Type of error
//	**   int validMask,       // Set of contexts for which prohibited
//	**   Expr *pExpr          // Invalidate this expression on error
//	** ){...}
//	**
//	** As an optimization, since the conditional is almost always false
//	** (because errors are rare), the conditional is moved outside of the
//	** function call using a macro.
//	*/
func _notValidImpl(tls *libc.TLS, pParse uintptr, pNC uintptr, zMsg uintptr, pExpr uintptr, pError uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zIn uintptr
	_ = zIn
	zIn = __ccgo_ts + 8240
	if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_IdxExpr) != 0 {
		zIn = __ccgo_ts + 8268
	} else {
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_IsCheck) != 0 {
			zIn = __ccgo_ts + 8286
		} else {
			if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_GenCol) != 0 {
				zIn = __ccgo_ts + 8304
			}
		}
	}
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8322, libc.VaList(bp+8, zMsg, zIn))
	if pExpr != 0 {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
	}
	_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pError)
}

// C documentation
//
//	/*
//	** Expression p should encode a floating point value between 1.0 and 0.0.
//	** Return 1024 times this value.  Or return -1 if p is not a floating point
//	** value between 1.0 and 0.0.
//	*/
func _exprProbability(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* r at bp+0 */ float64
	*(*float64)(unsafe.Pointer(bp)) = -libc.Float64FromFloat64(1)
	if int32((*TExpr)(unsafe.Pointer(p)).Fop) != int32(TK_FLOAT) {
		return -int32(1)
	}
	_sqlite3AtoF(tls, *(*uintptr)(unsafe.Pointer(p + 8)), bp, _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(p + 8))), uint8(SQLITE_UTF8))
	if *(*float64)(unsafe.Pointer(bp)) > float64(1) {
		return -int32(1)
	}
	return int32(*(*float64)(unsafe.Pointer(bp)) * libc.Float64FromFloat64(1.34217728e+08))
}

// 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, v12, v4, v6, v7 int32
	var enc Tu8
	var p, pDef, pItem, pLeft, pList, pNC, pNC2, pParse, pRight, pRight1, pSel, pSrcList, pWin, zDb, zId, zTable, zType, v5, v8, p10, p11, p9 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, v12, v4, v5, v6, v7, v8, p10, p11, p9
	pNC = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
	switch int32((*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)
		(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
		(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
		(*TExpr)(unsafe.Pointer(pExpr)).FiColumn--
		(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(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 < int32(libc.Uint32FromInt64(32)/libc.Uint32FromInt64(4))) {
				break
			}
			anRef[i] = (*TNameContext)(unsafe.Pointer(p)).FnRef
			goto _1
		_1:
			;
			p = (*TNameContext)(unsafe.Pointer(p)).FpNext
			i++
		}
		_sqlite3WalkExpr(tls, pWalker, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		if int32((*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++
		}
		*(*int32)(unsafe.Pointer(pExpr + 8)) = libc.BoolInt32(int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NOTNULL))
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(EP_IntValue)
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_INTEGER)
		i = 0
		p = pNC
		for {
			if !(p != 0 && i < int32(libc.Uint32FromInt64(32)/libc.Uint32FromInt64(4))) {
				break
			}
			(*TNameContext)(unsafe.Pointer(p)).FnRef = anRef[i]
			goto _3
		_3:
			;
			p = (*TNameContext)(unsafe.Pointer(p)).FpNext
			i++
		}
		_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 int32((*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+8342, uintptr(0), pExpr)
			}
			pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
			if int32((*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 int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
				_sqlite3RenameTokenRemap(tls, pParse, pExpr, pRight)
				_sqlite3RenameTokenRemap(tls, pParse, pExpr+44, pLeft)
			}
		}
		return _lookupName(tls, pParse, zDb, zTable, pRight, pNC, pExpr)
		/* Resolve function names
		 */
		fallthrough
	case int32(TK_FUNCTION):
		pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
		if pList != 0 {
			v4 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
		} else {
			v4 = 0
		} /* The argument list */
		n = v4                                                                        /* 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&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) && int32((*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FeFrmType) != int32(TK_FILTER) {
			v5 = *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy))
		} else {
			v5 = uintptr(0)
		}
		pWin = 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)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_Unlikely))
				if n == int32(2) {
					(*TExpr)(unsafe.Pointer(pExpr)).FiTable = _exprProbability(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + 1*20))).FpExpr)
					if (*TExpr)(unsafe.Pointer(pExpr)).FiTable < 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8359, libc.VaList(bp+8, pExpr))
						(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
					}
				} 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 int32(*(*int8)(unsafe.Pointer((*TFuncDef)(unsafe.Pointer(pDef)).FzName))) == int32('u') {
						v6 = int32(8388608)
					} else {
						v6 = int32(125829120)
					}
					(*TExpr)(unsafe.Pointer(pExpr)).FiTable = v6
				}
			}
			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+8423, libc.VaList(bp+8, pExpr))
					(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
				}
				(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
				return int32(WRC_Prune)
			}
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(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)(unsafe.Pointer(pExpr + 4)) |= uint32(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
				 ** all 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+8459, uintptr(0), pExpr)
				}
			} else {
				/* Must fit in 8 bits */
				(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = uint8((*TNameContext)(unsafe.Pointer(pNC)).FncFlags & int32(NC_SelfRef))
				if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_FromDDL) != 0 {
					*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_FromDDL))
				}
			}
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_INTERNAL) != uint32(0) && int32((*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&uint32(libc.Int32FromInt32(SQLITE_FUNC_DIRECT)|libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)) != uint32(0) && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
					_sqlite3ExprFunctionUsable(tls, pParse, pExpr, pDef)
				}
			}
		}
		if 0 == libc.BoolInt32(int32((*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+8487, libc.VaList(bp+8, pExpr))
				(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
			} 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 + 8530
					} else {
						zType = __ccgo_ts + 8537
					}
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8547, libc.VaList(bp+8, zType, pExpr))
					(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
					is_agg = 0
				} else {
					if no_such_func != 0 && int32((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8575, libc.VaList(bp+8, pExpr))
						(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
					} else {
						if wrong_num_args != 0 {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8597, libc.VaList(bp+8, pExpr))
							(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
						} else {
							if is_agg == 0 && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
								_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8641, libc.VaList(bp+8, pExpr))
								(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
							} else {
								if is_agg == 0 && (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
									_sqlite3ExprOrderByAggregateError(tls, pParse, pExpr)
									(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr++
								}
							}
						}
					}
				}
			}
			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) {
					v7 = int32(NC_AllowAgg)
				} else {
					v7 = 0
				}
				*(*int32)(unsafe.Pointer(pNC + 24)) &= ^(libc.Int32FromInt32(NC_AllowWin) | v7)
			}
		} else {
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(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 + 20)))
			}
			if pWin != 0 {
				pSel = (*TNameContext)(unsafe.Pointer(pNC)).FpWinSelect
				if libc.BoolInt32(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME)) == 0 {
					if pSel != 0 {
						v8 = (*TSelect)(unsafe.Pointer(pSel)).FpWinDefn
					} else {
						v8 = uintptr(0)
					}
					_sqlite3WindowUpdate(tls, pParse, v8, 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)(unsafe.Pointer(pNC + 24)) |= 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&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
					_sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FpFilter)
				}
				pNC2 = pNC
				for pNC2 != 0 && _sqlite3ReferencesSrcList(tls, pParse, pExpr, (*TNameContext)(unsafe.Pointer(pNC2)).FpSrcList) == 0 {
					p9 = pExpr + 2
					*(*Tu8)(unsafe.Pointer(p9)) = Tu8(uint32(*(*Tu8)(unsafe.Pointer(p9))) + (libc.Uint32FromInt32(1) + (*TNameContext)(unsafe.Pointer(pNC2)).FnNestedSelect))
					pNC2 = (*TNameContext)(unsafe.Pointer(pNC2)).FpNext
				}
				if pNC2 != 0 && pDef != 0 {
					p10 = pExpr + 2
					*(*Tu8)(unsafe.Pointer(p10)) = Tu8(uint32(*(*Tu8)(unsafe.Pointer(p10))) + (*TNameContext)(unsafe.Pointer(pNC2)).FnNestedSelect)
					p11 = pNC2 + 24
					*(*int32)(unsafe.Pointer(p11)) = int32(uint32(*(*int32)(unsafe.Pointer(p11))) | (libc.Uint32FromInt32(NC_HasAgg) | ((*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags^libc.Uint32FromInt32(SQLITE_FUNC_ANYORDER))&uint32(libc.Int32FromInt32(SQLITE_FUNC_MINMAX)|libc.Int32FromInt32(SQLITE_FUNC_ANYORDER))))
				}
			}
			*(*int32)(unsafe.Pointer(pNC + 24)) |= savedAllowFlags
		}
		/* FIX ME:  Compute pExpr->affinity based on the expected return
		 ** type of the function
		 */
		return int32(WRC_Prune)
	case int32(TK_SELECT):
		fallthrough
	case int32(TK_EXISTS):
		fallthrough
	case int32(TK_IN):
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			nRef = (*TNameContext)(unsafe.Pointer(pNC)).FnRef
			if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_SelfRef) != 0 {
				_notValidImpl(tls, pParse, pNC, __ccgo_ts+8689, pExpr, pExpr)
			} else {
				_sqlite3WalkSelect(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
			}
			if nRef != (*TNameContext)(unsafe.Pointer(pNC)).FnRef {
				*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_VarSelect))
				*(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 4)) |= uint32(SF_Correlated)
			}
			*(*int32)(unsafe.Pointer(pNC + 24)) |= 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+8700, 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 && (int32((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_ID) || int32((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_TRUEFALSE)) {
			rc = _resolveExprStep(tls, pWalker, pRight1)
			if rc == int32(WRC_Abort) {
				return int32(WRC_Abort)
			}
			if int32((*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 int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_BETWEEN) {
			nRight = _sqlite3ExprVectorSize(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr)
			if nRight == nLeft {
				nRight = _sqlite3ExprVectorSize(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8 + 1*20))).FpExpr)
			}
		} else {
			nRight = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		}
		if nLeft != nRight {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8050, 0)
			_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		}
		break
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		v12 = int32(WRC_Abort)
	} else {
		v12 = WRC_Continue
	}
	return v12
}

// 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 int32((*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)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME && Xsqlite3_stricmp(tls, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FzEName, zCol) == 0 {
				return i + int32(1)
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** pE is a pointer to an expression which is a single term in the
//	** ORDER BY of a compound SELECT.  The expression has not been
//	** name resolved.
//	**
//	** At the point this routine is called, we already know that the
//	** ORDER BY term is not an integer index into the result set.  That
//	** case is handled by the calling routine.
//	**
//	** Attempt to match pE against result set columns in the left-most
//	** SELECT statement.  Return the index i of the matching column,
//	** as an indication to the caller that it should sort by the i-th column.
//	** The left-most column is 1.  In other words, the value returned is the
//	** same integer value that would be used in the SQL statement to indicate
//	** the column.
//	**
//	** If there is no match, return 0.  Return -1 if an error occurs.
//	*/
func _resolveOrderByTermToExprList(tls *libc.TLS, pParse uintptr, pSelect uintptr, pE uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, pEList uintptr
	var i, rc int32
	var savedSuppErr Tu8
	var _ /* nc at bp+0 */ TNameContext
	_, _, _, _, _ = db, i, pEList, rc, savedSuppErr /* Saved value of db->suppressErr */
	pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
	/* Resolve all names in the ORDER BY term expression
	 */
	libc.Xmemset(tls, bp, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TNameContext)(unsafe.Pointer(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	*(*uintptr)(unsafe.Pointer(bp + 8)) = pEList
	(*(*TNameContext)(unsafe.Pointer(bp))).FncFlags = libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_UEList) | libc.Int32FromInt32(NC_NoSelect)
	(*(*TNameContext)(unsafe.Pointer(bp))).FnNcErr = 0
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	savedSuppErr = (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr
	(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = uint8(1)
	rc = _sqlite3ResolveExprNames(tls, bp, pE)
	(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = savedSuppErr
	if rc != 0 {
		return 0
	}
	/* Try to match the ORDER BY expression against an expression
	 ** in the result set.  Return an 1-based index of the matching
	 ** result-set entry.
	 */
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		if _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr, pE, -int32(1)) < int32(2) {
			return i + int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	/* If no match, return 0. */
	return 0
}

// C documentation
//
//	/*
//	** Generate an ORDER BY or GROUP BY term out-of-range error.
//	*/
func _resolveOutOfRangeError(tls *libc.TLS, pParse uintptr, zType uintptr, i int32, mx int32, pError uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8711, libc.VaList(bp+8, i, zType, mx))
	_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pError)
}

// 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)(unsafe.Pointer(db + 120 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8767, 0)
		return int32(1)
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		libc.SetBitFieldPtr16Uint32(pOrderBy+8+uintptr(i)*20+8+4, libc.Uint32FromInt32(0), 2, 0x4)
		goto _1
	_1:
		;
		i++
	}
	(*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)(unsafe.Pointer(bp)) = -int32(1)
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 8 + 4))&0x4>>2)) != 0 {
				goto _2
			}
			pE = _sqlite3ExprSkipCollateAndLikely(tls, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			if pE == uintptr(0) {
				goto _2
			}
			if _sqlite3ExprIsInteger(tls, pE, bp) != 0 {
				if *(*int32)(unsafe.Pointer(bp)) <= 0 || *(*int32)(unsafe.Pointer(bp)) > (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
					_resolveOutOfRangeError(tls, pParse, __ccgo_ts+8801, i+int32(1), (*TExprList)(unsafe.Pointer(pEList)).FnExpr, pE)
					return int32(1)
				}
			} else {
				*(*int32)(unsafe.Pointer(bp)) = _resolveAsName(tls, pParse, pEList, pE)
				if *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp)) = _resolveOrderByTermToExprList(tls, pParse, pSelect, pDup)
						if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && *(*int32)(unsafe.Pointer(bp)) > 0 {
							_resolveOrderByTermToExprList(tls, pParse, pSelect, pE)
						}
					}
					_sqlite3ExprDelete(tls, db, pDup)
				}
			}
			if *(*int32)(unsafe.Pointer(bp)) > 0 {
				/* Convert the ORDER BY term into an integer column number iCol,
				 ** taking care to preserve the COLLATE clause if it exists. */
				if !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
					pNew = _sqlite3Expr(tls, db, int32(TK_INTEGER), uintptr(0))
					if pNew == uintptr(0) {
						return int32(1)
					}
					*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(EP_IntValue)
					*(*int32)(unsafe.Pointer(pNew + 8)) = *(*int32)(unsafe.Pointer(bp))
					if (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr == pE {
						(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pNew
					} else {
						pParent = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
						for int32((*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 + 16))).FiOrderByCol = uint16(*(*int32)(unsafe.Pointer(bp)))
				}
				libc.SetBitFieldPtr16Uint32(pItem+8+4, libc.Uint32FromInt32(1), 2, 0x4)
			} else {
				moreToDo = int32(1)
			}
			goto _2
		_2:
			;
			i++
			pItem += 20
		}
		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)*20 + 8 + 4))&0x4>>2)) == 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8807, libc.VaList(bp+16, i+int32(1)))
			return int32(1)
		}
		goto _3
	_3:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
//	** the SELECT statement pSelect.  If any term is reference to a
//	** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
//	** field) then convert that term into a copy of the corresponding result set
//	** column.
//	**
//	** If any errors are detected, add an error message to pParse and
//	** return non-zero.  Return zero if no errors are seen.
//	*/
func _sqlite3ResolveOrderGroupBy(tls *libc.TLS, pParse uintptr, pSelect uintptr, pOrderBy uintptr, zType uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pEList, pItem uintptr
	var i int32
	_, _, _, _ = db, i, pEList, pItem
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pOrderBy == uintptr(0) || (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 || int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		return 0
	}
	if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > *(*int32)(unsafe.Pointer(db + 120 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8868, libc.VaList(bp+8, zType))
		return int32(1)
	}
	pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
	/* sqlite3SelectNew() guarantees this */
	i = 0
	pItem = pOrderBy + 8
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		if (*(*struct {
			FiOrderByCol Tu16
			FiAlias      Tu16
		})(unsafe.Pointer(pItem + 16))).FiOrderByCol != 0 {
			if int32((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem + 16))).FiOrderByCol) > (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
				_resolveOutOfRangeError(tls, pParse, zType, i+int32(1), (*TExprList)(unsafe.Pointer(pEList)).FnExpr, uintptr(0))
				return int32(1)
			}
			_resolveAlias(tls, pParse, pEList, int32((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem + 16))).FiOrderByCol)-int32(1), (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr, 0)
		}
		goto _1
	_1:
		;
		i++
		pItem += 20
	}
	return 0
}

// C documentation
//
//	/*
//	** Walker callback for windowRemoveExprFromSelect().
//	*/
func _resolveRemoveWindowsCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var pWin uintptr
	_ = pWin
	_ = pWalker
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		pWin = *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy))
		_sqlite3WindowUnlinkFromSelect(tls, pWin)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Remove any Window objects owned by the expression pExpr from the
//	** Select.pWin list of Select object pSelect.
//	*/
func _windowRemoveExprFromSelect(tls *libc.TLS, pSelect uintptr, pExpr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* sWalker at bp+0 */ TWalker
	if (*TSelect)(unsafe.Pointer(pSelect)).FpWin != 0 {
		libc.Xmemset(tls, bp, 0, uint32(28))
		(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_resolveRemoveWindowsCb)
		*(*uintptr)(unsafe.Pointer(bp + 24)) = pSelect
		_sqlite3WalkExpr(tls, bp, pExpr)
	}
}

// C documentation
//
//	/*
//	** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
//	** The Name context of the SELECT statement is pNC.  zType is either
//	** "ORDER" or "GROUP" depending on which type of clause pOrderBy is.
//	**
//	** This routine resolves each term of the clause into an expression.
//	** If the order-by term is an integer I between 1 and N (where N is the
//	** number of columns in the result set of the SELECT) then the expression
//	** in the resolution is a copy of the I-th result-set expression.  If
//	** the order-by term is an identifier that corresponds to the AS-name of
//	** a result-set expression, then the term resolves to a copy of the
//	** result-set expression.  Otherwise, the expression is resolved in
//	** the usual way - using sqlite3ResolveExprNames().
//	**
//	** This routine returns the number of errors.  If errors occur, then
//	** an appropriate error message might be left in pParse.  (OOM errors
//	** excepted.)
//	*/
func _resolveOrderGroupBy(tls *libc.TLS, pNC uintptr, pSelect uintptr, pOrderBy uintptr, zType uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, j, nResult int32
	var pE, pE2, pItem, pParse uintptr
	var _ /* iCol at bp+0 */ int32
	_, _, _, _, _, _, _ = i, j, nResult, pE, pE2, pItem, pParse /* Number of terms in the result set */
	nResult = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpEList)).FnExpr
	pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
	i = 0
	pItem = pOrderBy + 8
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		pE = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
		pE2 = _sqlite3ExprSkipCollateAndLikely(tls, pE)
		if pE2 == uintptr(0) {
			goto _1
		}
		if int32(*(*int8)(unsafe.Pointer(zType))) != int32('G') {
			*(*int32)(unsafe.Pointer(bp)) = _resolveAsName(tls, pParse, (*TSelect)(unsafe.Pointer(pSelect)).FpEList, pE2)
			if *(*int32)(unsafe.Pointer(bp)) > 0 {
				/* If an AS-name match is found, mark this ORDER BY column as being
				 ** a copy of the iCol-th result-set column.  The subsequent call to
				 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
				 ** copy of the iCol-th result-set expression. */
				(*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem + 16))).FiOrderByCol = uint16(*(*int32)(unsafe.Pointer(bp)))
				goto _1
			}
		}
		if _sqlite3ExprIsInteger(tls, pE2, bp) != 0 {
			/* The ORDER BY term is an integer constant.  Again, set the column
			 ** number so that sqlite3ResolveOrderGroupBy() will convert the
			 ** order-by term to a copy of the result-set expression */
			if *(*int32)(unsafe.Pointer(bp)) < int32(1) || *(*int32)(unsafe.Pointer(bp)) > int32(0xffff) {
				_resolveOutOfRangeError(tls, pParse, zType, i+int32(1), nResult, pE2)
				return int32(1)
			}
			(*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem + 16))).FiOrderByCol = uint16(*(*int32)(unsafe.Pointer(bp)))
			goto _1
		}
		/* Otherwise, treat the ORDER BY term as an ordinary expression */
		(*(*struct {
			FiOrderByCol Tu16
			FiAlias      Tu16
		})(unsafe.Pointer(pItem + 16))).FiOrderByCol = uint16(0)
		if _sqlite3ResolveExprNames(tls, pNC, pE) != 0 {
			return int32(1)
		}
		j = 0
		for {
			if !(j < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpEList)).FnExpr) {
				break
			}
			if _sqlite3ExprCompare(tls, uintptr(0), pE, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpEList + 8 + uintptr(j)*20))).FpExpr, -int32(1)) == 0 {
				/* Since this expression is being changed into a reference
				 ** to an identical expression in the result set, remove all Window
				 ** objects belonging to the expression from the Select.pWin list. */
				_windowRemoveExprFromSelect(tls, pSelect, pE)
				(*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem + 16))).FiOrderByCol = uint16(j + int32(1))
			}
			goto _2
		_2:
			;
			j++
		}
		goto _1
	_1:
		;
		i++
		pItem += 20
	}
	return _sqlite3ResolveOrderGroupBy(tls, pParse, pSelect, pOrderBy, zType)
}

// 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(48)
	defer tls.Free(48)
	var db, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext uintptr
	var i, isCompound, nCompound, nRef, v1, v3 int32
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, isCompound, nCompound, nRef, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext, v1, v3 /* Database connection */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Resolved) != 0 {
		return int32(WRC_Prune)
	}
	pOuterNC = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	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)(unsafe.Pointer(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, uint32(36))
		(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
		(*(*TNameContext)(unsafe.Pointer(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 = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).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++
		}
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc) {
				break
			}
			pItem = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*72
			/* Test of tag-20240424-1*/
			if (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 && (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)).FselFlags&uint32(SF_Resolved) == uint32(0) {
				if pOuterNC != 0 {
					v3 = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef
				} else {
					v3 = 0
				}
				nRef = v3
				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, (*TSrcItem)(unsafe.Pointer(pItem)).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.SetBitFieldPtr16Uint32(pItem+36+4, libc.BoolUint32((*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef > nRef), 3, 0x8)
				}
			}
			goto _2
		_2:
			;
			i++
		}
		if pOuterNC != 0 && (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect > uint32(0) {
			(*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect--
		}
		/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
		 ** resolve the result-set expression list.
		 */
		(*(*TNameContext)(unsafe.Pointer(bp))).FncFlags = libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin)
		(*(*TNameContext)(unsafe.Pointer(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(p)).FpSrc
		(*(*TNameContext)(unsafe.Pointer(bp))).FpNext = pOuterNC
		/* Resolve names in the result set. */
		if _sqlite3ResolveExprListNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpEList) != 0 {
			return int32(WRC_Abort)
		}
		(*(*TNameContext)(unsafe.Pointer(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)(unsafe.Pointer(bp))).FncFlags&int32(NC_HasAgg) != 0 {
			*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(int32(SF_Aggregate) | (*(*TNameContext)(unsafe.Pointer(bp))).FncFlags&(libc.Int32FromInt32(NC_MinMaxAgg)|libc.Int32FromInt32(NC_OrderAgg)))
		} else {
			(*(*TNameContext)(unsafe.Pointer(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 + 8)) = (*TSelect)(unsafe.Pointer(p)).FpEList
		(*(*TNameContext)(unsafe.Pointer(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+8899, 0)
				return int32(WRC_Abort)
			}
			if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpHaving) != 0 {
				return int32(WRC_Abort)
			}
		}
		(*(*TNameContext)(unsafe.Pointer(bp))).FncFlags |= int32(NC_Where)
		if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpWhere) != 0 {
			return int32(WRC_Abort)
		}
		(*(*TNameContext)(unsafe.Pointer(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)*72
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem1 + 36 + 4))&0x4>>2)) != 0 && _sqlite3ResolveExprListNames(tls, bp, *(*uintptr)(unsafe.Pointer(pItem1 + 64))) != 0 {
				return int32(WRC_Abort)
			}
			goto _4
		_4:
			;
			i++
		}
		if int32((*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
			}
		}
		/* The ORDER BY and GROUP BY clauses may not refer to terms in
		 ** outer queries
		 */
		(*(*TNameContext)(unsafe.Pointer(bp))).FpNext = uintptr(0)
		(*(*TNameContext)(unsafe.Pointer(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 = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).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+8801) != 0 {
			return int32(WRC_Abort)
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return int32(WRC_Abort)
		}
		(*(*TNameContext)(unsafe.Pointer(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+8938) != 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&uint32(libc.Int32FromInt32(EP_Agg)) != uint32(0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8944, 0)
					return int32(WRC_Abort)
				}
				goto _6
			_6:
				;
				i++
				pItem2 += 20
			}
		}
		/* 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)
		}
		/* Advance to the next term of the compound
		 */
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
		nCompound++
	}
	/* 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
//
//	/*
//	** This routine walks an expression tree and resolves references to
//	** table columns and result-set columns.  At the same time, do error
//	** checking on function usage and set a flag if any aggregate functions
//	** are seen.
//	**
//	** To resolve table columns references we look for nodes (or subtrees) of the
//	** form X.Y.Z or Y.Z or just Z where
//	**
//	**      X:   The name of a database.  Ex:  "main" or "temp" or
//	**           the symbolic name assigned to an ATTACH-ed database.
//	**
//	**      Y:   The name of a table in a FROM clause.  Or in a trigger
//	**           one of the special names "old" or "new".
//	**
//	**      Z:   The name of a column in table Y.
//	**
//	** The node at the root of the subtree is modified as follows:
//	**
//	**    Expr.op        Changed to TK_COLUMN
//	**    Expr.pTab      Points to the Table object for X.Y
//	**    Expr.iColumn   The column index in X.Y.  -1 for the rowid.
//	**    Expr.iTable    The VDBE cursor number for X.Y
//	**
//	**
//	** To resolve result-set references, look for expression nodes of the
//	** form Z (with no X and Y prefix) where the Z matches the right-hand
//	** size of an AS clause in the result-set of a SELECT.  The Z expression
//	** is replaced by a copy of the left-hand side of the result-set expression.
//	** Table-name and function resolution occurs on the substituted expression
//	** tree.  For example, in:
//	**
//	**      SELECT a+b AS x, c+d AS y FROM t1 ORDER BY x;
//	**
//	** The "x" term of the order by is replaced by "a+b" to render:
//	**
//	**      SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b;
//	**
//	** Function calls are checked to make sure that the function is
//	** defined and that the correct number of arguments are specified.
//	** If the function is an aggregate function, then the NC_HasAgg flag is
//	** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION.
//	** If an expression contains aggregate functions then the EP_Agg
//	** property on the expression is set.
//	**
//	** An error message is left in pParse if anything is amiss.  The number
//	** if errors is returned.
//	*/
func _sqlite3ResolveExprNames(tls *libc.TLS, pNC uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var savedHasAgg int32
	var v1 uintptr
	var _ /* w at bp+0 */ TWalker
	_, _ = savedHasAgg, v1
	if pExpr == uintptr(0) {
		return SQLITE_OK
	}
	savedHasAgg = (*TNameContext)(unsafe.Pointer(pNC)).FncFlags & (libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_MinMaxAgg) | libc.Int32FromInt32(NC_HasWin) | libc.Int32FromInt32(NC_OrderAgg))
	*(*int32)(unsafe.Pointer(pNC + 24)) &= ^(libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_MinMaxAgg) | libc.Int32FromInt32(NC_HasWin) | libc.Int32FromInt32(NC_OrderAgg))
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_resolveExprStep)
	if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_NoSelect) != 0 {
		v1 = uintptr(0)
	} else {
		v1 = __ccgo_fp(_resolveSelectStep)
	}
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = v1
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pNC
	*(*int32)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse + 228)) += (*TExpr)(unsafe.Pointer(pExpr)).FnHeight
	if _sqlite3ExprCheckHeight(tls, (*(*TWalker)(unsafe.Pointer(bp))).FpParse, (*TParse)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse)).FnHeight) != 0 {
		return int32(SQLITE_ERROR)
	}
	_sqlite3WalkExprNN(tls, bp, pExpr)
	*(*int32)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse + 228)) -= (*TExpr)(unsafe.Pointer(pExpr)).FnHeight
	*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32((*TNameContext)(unsafe.Pointer(pNC)).FncFlags & (libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_HasWin)))
	*(*int32)(unsafe.Pointer(pNC + 24)) |= savedHasAgg
	return libc.BoolInt32((*TNameContext)(unsafe.Pointer(pNC)).FnNcErr > 0 || (*TParse)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse)).FnErr > 0)
}

// C documentation
//
//	/*
//	** Resolve all names for all expression in an expression list.  This is
//	** just like sqlite3ResolveExprNames() except that it works for an expression
//	** list rather than a single expression.
//	*/
func _sqlite3ResolveExprListNames(tls *libc.TLS, pNC uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, savedHasAgg int32
	var pExpr uintptr
	var _ /* w at bp+0 */ TWalker
	_, _, _ = i, pExpr, savedHasAgg
	savedHasAgg = 0
	if pList == uintptr(0) {
		return WRC_Continue
	}
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_resolveExprStep)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_resolveSelectStep)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pNC
	savedHasAgg = (*TNameContext)(unsafe.Pointer(pNC)).FncFlags & (libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_MinMaxAgg) | libc.Int32FromInt32(NC_HasWin) | libc.Int32FromInt32(NC_OrderAgg))
	*(*int32)(unsafe.Pointer(pNC + 24)) &= ^(libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_MinMaxAgg) | libc.Int32FromInt32(NC_HasWin) | libc.Int32FromInt32(NC_OrderAgg))
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		pExpr = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr
		if pExpr == uintptr(0) {
			goto _1
		}
		*(*int32)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse + 228)) += (*TExpr)(unsafe.Pointer(pExpr)).FnHeight
		if _sqlite3ExprCheckHeight(tls, (*(*TWalker)(unsafe.Pointer(bp))).FpParse, (*TParse)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse)).FnHeight) != 0 {
			return int32(WRC_Abort)
		}
		_sqlite3WalkExprNN(tls, bp, pExpr)
		*(*int32)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse + 228)) -= (*TExpr)(unsafe.Pointer(pExpr)).FnHeight
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_HasAgg)|libc.Int32FromInt32(NC_MinMaxAgg)|libc.Int32FromInt32(NC_HasWin)|libc.Int32FromInt32(NC_OrderAgg)) != 0 {
			*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32((*TNameContext)(unsafe.Pointer(pNC)).FncFlags & (libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_HasWin)))
			savedHasAgg |= (*TNameContext)(unsafe.Pointer(pNC)).FncFlags & (libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_MinMaxAgg) | libc.Int32FromInt32(NC_HasWin) | libc.Int32FromInt32(NC_OrderAgg))
			*(*int32)(unsafe.Pointer(pNC + 24)) &= ^(libc.Int32FromInt32(NC_HasAgg) | libc.Int32FromInt32(NC_MinMaxAgg) | libc.Int32FromInt32(NC_HasWin) | libc.Int32FromInt32(NC_OrderAgg))
		}
		if (*TParse)(unsafe.Pointer((*(*TWalker)(unsafe.Pointer(bp))).FpParse)).FnErr > 0 {
			return int32(WRC_Abort)
		}
		goto _1
	_1:
		;
		i++
	}
	*(*int32)(unsafe.Pointer(pNC + 24)) |= savedHasAgg
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Resolve all names in all expressions of a SELECT and in all
//	** descendants of the SELECT, including compounds off of p->pPrior,
//	** subqueries in expressions, and subqueries used as FROM clause
//	** terms.
//	**
//	** See sqlite3ResolveExprNames() for a description of the kinds of
//	** transformations that occur.
//	**
//	** All SELECT statements should have been expanded using
//	** sqlite3SelectExpand() prior to invoking this routine.
//	*/
func _sqlite3ResolveSelectNames(tls *libc.TLS, pParse uintptr, p uintptr, pOuterNC uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_resolveExprStep)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_resolveSelectStep)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = uintptr(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pOuterNC
	_sqlite3WalkSelect(tls, bp, p)
}

// C documentation
//
//	/*
//	** Resolve names in expressions that can only reference a single table
//	** or which cannot reference any tables at all.  Examples:
//	**
//	**                                                    "type" flag
//	**                                                    ------------
//	**    (1)   CHECK constraints                         NC_IsCheck
//	**    (2)   WHERE clauses on partial indices          NC_PartIdx
//	**    (3)   Expressions in indexes on expressions     NC_IdxExpr
//	**    (4)   Expression arguments to VACUUM INTO.      0
//	**    (5)   GENERATED ALWAYS as expressions           NC_GenCol
//	**
//	** In all cases except (4), the Expr.iTable value for Expr.op==TK_COLUMN
//	** nodes of the expression is set to -1 and the Expr.iColumn value is
//	** set to the column number.  In case (4), TK_COLUMN nodes cause an error.
//	**
//	** Any errors cause an error message to be set in pParse.
//	*/
func _sqlite3ResolveSelfReference(tls *libc.TLS, pParse uintptr, pTab uintptr, type1 int32, pExpr uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var rc, v1 int32
	var _ /* sNC at bp+80 */ TNameContext
	var _ /* sSrc at bp+0 */ TSrcList
	_, _ = rc, v1
	libc.Xmemset(tls, bp+80, 0, uint32(36))
	libc.Xmemset(tls, bp, 0, uint32(80))
	if pTab != 0 {
		(*(*TSrcList)(unsafe.Pointer(bp))).FnSrc = int32(1)
		(*(*TSrcItem)(unsafe.Pointer(bp + 8))).FzName = (*TTable)(unsafe.Pointer(pTab)).FzName
		(*(*TSrcItem)(unsafe.Pointer(bp + 8))).FpTab = pTab
		(*(*TSrcItem)(unsafe.Pointer(bp + 8))).FiCursor = -int32(1)
		if (*TTable)(unsafe.Pointer(pTab)).FpSchema != (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + 1*16))).FpSchema {
			/* Cause EP_FromDDL to be set on TK_FUNCTION nodes of non-TEMP
			 ** schema elements */
			type1 |= int32(NC_FromDDL)
		}
	}
	(*(*TNameContext)(unsafe.Pointer(bp + 80))).FpParse = pParse
	(*(*TNameContext)(unsafe.Pointer(bp + 80))).FpSrcList = bp
	(*(*TNameContext)(unsafe.Pointer(bp + 80))).FncFlags = type1 | int32(NC_IsDDL)
	v1 = _sqlite3ResolveExprNames(tls, bp+80, pExpr)
	rc = v1
	if v1 != SQLITE_OK {
		return rc
	}
	if pList != 0 {
		rc = _sqlite3ResolveExprListNames(tls, bp+80, pList)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the affinity character for a single column of a table.
//	*/
func _sqlite3TableColumnAffinity(tls *libc.TLS, pTab uintptr, iCol int32) (r int8) {
	if iCol < 0 || iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		return int8(SQLITE_AFF_INTEGER)
	}
	return (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).Faffinity
}

// C documentation
//
//	/*
//	** Return the 'affinity' of the expression pExpr if any.
//	**
//	** If pExpr is a column, a reference to a column via an 'AS' alias,
//	** or a sub-select with a column as the return value, then the
//	** affinity of that column is returned. Otherwise, 0x00 is returned,
//	** indicating no affinity for the expression.
//	**
//	** i.e. the WHERE clause expressions in the following statements all
//	** have an affinity:
//	**
//	** CREATE TABLE t1(a);
//	** SELECT * FROM t1 WHERE a;
//	** SELECT a AS b FROM t1 WHERE b;
//	** SELECT * FROM t1 WHERE (select a from t1);
//	*/
func _sqlite3ExprAffinity(tls *libc.TLS, pExpr uintptr) (r int8) {
	var op, v1 int32
	var v2 bool
	_, _, _ = op, v1, v2
	op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop)
	for int32(1) != 0 {
		if op == int32(TK_COLUMN) || op == int32(TK_AGG_COLUMN) && (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab != uintptr(0) {
			return _sqlite3TableColumnAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab, int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn))
		}
		if op == int32(TK_SELECT) {
			return _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpEList + 8))).FpExpr)
		}
		if op == int32(TK_CAST) {
			return _sqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0))
		}
		if op == int32(TK_SELECT_COLUMN) {
			return _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 20)))).FpEList + 8 + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)*20))).FpExpr)
		}
		if op == int32(TK_VECTOR) {
			return _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr)
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Skip)|libc.Int32FromInt32(EP_IfNullRow)) != uint32(0) {
			pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
			op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop)
			continue
		}
		if v2 = op != int32(TK_REGISTER); !v2 {
			v1 = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2)
			op = v1
		}
		if v2 || v1 == int32(TK_REGISTER) {
			break
		}
	}
	return (*TExpr)(unsafe.Pointer(pExpr)).FaffExpr
}

// C documentation
//
//	/*
//	** Make a guess at all the possible datatypes of the result that could
//	** be returned by an expression.  Return a bitmask indicating the answer:
//	**
//	**     0x01         Numeric
//	**     0x02         Text
//	**     0x04         Blob
//	**
//	** If the expression must return NULL, then 0x00 is returned.
//	*/
func _sqlite3ExprDataType(tls *libc.TLS, pExpr uintptr) (r int32) {
	var aff, ii, res int32
	var pList uintptr
	_, _, _, _ = aff, ii, pList, res
	for pExpr != 0 {
		switch int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
		case int32(TK_COLLATE):
			fallthrough
		case int32(TK_IF_NULL_ROW):
			fallthrough
		case int32(TK_UPLUS):
			pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		case int32(TK_NULL):
			pExpr = uintptr(0)
		case int32(TK_STRING):
			return int32(0x02)
		case int32(TK_BLOB):
			return int32(0x04)
		case int32(TK_CONCAT):
			return int32(0x06)
		case int32(TK_VARIABLE):
			fallthrough
		case int32(TK_AGG_FUNCTION):
			fallthrough
		case int32(TK_FUNCTION):
			return int32(0x07)
		case int32(TK_COLUMN):
			fallthrough
		case int32(TK_AGG_COLUMN):
			fallthrough
		case int32(TK_SELECT):
			fallthrough
		case int32(TK_CAST):
			fallthrough
		case int32(TK_SELECT_COLUMN):
			fallthrough
		case int32(TK_VECTOR):
			aff = int32(_sqlite3ExprAffinity(tls, pExpr))
			if aff >= int32(SQLITE_AFF_NUMERIC) {
				return int32(0x05)
			}
			if aff == int32(SQLITE_AFF_TEXT) {
				return int32(0x06)
			}
			return int32(0x07)
		case int32(TK_CASE):
			res = 0
			pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
			ii = int32(1)
			for {
				if !(ii < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
					break
				}
				res |= _sqlite3ExprDataType(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ii)*20))).FpExpr)
				goto _1
			_1:
				;
				ii += int32(2)
			}
			if (*TExprList)(unsafe.Pointer(pList)).FnExpr%int32(2) != 0 {
				res |= _sqlite3ExprDataType(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr((*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1))*20))).FpExpr)
			}
			return res
		default:
			return int32(0x01)
		} /* End of switch(op) */
	} /* End of while(pExpr) */
	return 0x00
}

// C documentation
//
//	/*
//	** Set the collating sequence for expression pExpr to be the collating
//	** sequence named by pToken.   Return a pointer to a new Expr node that
//	** implements the COLLATE operator.
//	**
//	** If a memory allocation error occurs, that fact is recorded in pParse->db
//	** and the pExpr parameter is returned unchanged.
//	*/
func _sqlite3ExprAddCollateToken(tls *libc.TLS, pParse uintptr, pExpr uintptr, pCollName uintptr, dequote int32) (r uintptr) {
	var pNew uintptr
	_ = pNew
	if (*TToken)(unsafe.Pointer(pCollName)).Fn > uint32(0) {
		pNew = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_COLLATE), pCollName, dequote)
		if pNew != 0 {
			(*TExpr)(unsafe.Pointer(pNew)).FpLeft = pExpr
			*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(libc.Int32FromInt32(EP_Collate) | libc.Int32FromInt32(EP_Skip))
			pExpr = pNew
		}
	}
	return pExpr
}

func _sqlite3ExprAddCollateString(tls *libc.TLS, pParse uintptr, pExpr uintptr, zC uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* s at bp+0 */ TToken
	_sqlite3TokenInit(tls, bp, zC)
	return _sqlite3ExprAddCollateToken(tls, pParse, pExpr, bp, 0)
}

// C documentation
//
//	/*
//	** Skip over any TK_COLLATE operators.
//	*/
func _sqlite3ExprSkipCollate(tls *libc.TLS, pExpr uintptr) (r uintptr) {
	for pExpr != 0 && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Skip)) != uint32(0) {
		pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	}
	return pExpr
}

// C documentation
//
//	/*
//	** Skip over any TK_COLLATE operators and/or any unlikely()
//	** or likelihood() or likely() functions at the root of an
//	** expression.
//	*/
func _sqlite3ExprSkipCollateAndLikely(tls *libc.TLS, pExpr uintptr) (r uintptr) {
	for pExpr != 0 && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Skip)|libc.Int32FromInt32(EP_Unlikely)) != uint32(0) {
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Unlikely)) != uint32(0) {
			pExpr = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr
		} else {
			if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE) {
				pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
			} else {
				break
			}
		}
	}
	return pExpr
}

// C documentation
//
//	/*
//	** Return the collation sequence for the expression pExpr. If
//	** there is no defined collating sequence, return NULL.
//	**
//	** See also: sqlite3ExprNNCollSeq()
//	**
//	** The sqlite3ExprNNCollSeq() works the same exact that it returns the
//	** default collation if pExpr has no defined collation.
//	**
//	** The collating sequence might be determined by a COLLATE operator
//	** or by the presence of a column with a defined collating sequence.
//	** COLLATE operators take first precedence.  Left operands take
//	** precedence over right operands.
//	*/
func _sqlite3ExprCollSeq(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r uintptr) {
	var db, p, pColl, pNext, zColl uintptr
	var i, j, op, v1 int32
	_, _, _, _, _, _, _, _, _ = db, i, j, op, p, pColl, pNext, zColl, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pColl = uintptr(0)
	p = pExpr
	for p != 0 {
		op = int32((*TExpr)(unsafe.Pointer(p)).Fop)
		if op == int32(TK_REGISTER) {
			op = int32((*TExpr)(unsafe.Pointer(p)).Fop2)
		}
		if op == int32(TK_AGG_COLUMN) && (*TExpr)(unsafe.Pointer(p)).Fy.FpTab != uintptr(0) || op == int32(TK_COLUMN) || op == int32(TK_TRIGGER) {
			v1 = int32((*TExpr)(unsafe.Pointer(p)).FiColumn)
			j = v1
			if v1 >= 0 {
				zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).Fy.FpTab)).FaCol+uintptr(j)*12)
				pColl = _sqlite3FindCollSeq(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, zColl, 0)
			}
			break
		}
		if op == int32(TK_CAST) || op == int32(TK_UPLUS) {
			p = (*TExpr)(unsafe.Pointer(p)).FpLeft
			continue
		}
		if op == int32(TK_VECTOR) {
			p = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)) + 8))).FpExpr
			continue
		}
		if op == int32(TK_COLLATE) {
			pColl = _sqlite3GetCollSeq(tls, pParse, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, uintptr(0), *(*uintptr)(unsafe.Pointer(p + 8)))
			break
		}
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_Collate) != 0 {
			if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 && (*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).FpLeft)).Fflags&uint32(EP_Collate) != uint32(0) {
				p = (*TExpr)(unsafe.Pointer(p)).FpLeft
			} else {
				pNext = (*TExpr)(unsafe.Pointer(p)).FpRight
				/* The Expr.x union is never used at the same time as Expr.pRight */
				if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) == uint32(0) && *(*uintptr)(unsafe.Pointer(p + 20)) != uintptr(0) && !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
					i = 0
					for {
						if !(i < (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)))).FnExpr) {
							break
						}
						if (*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)) + 8 + uintptr(i)*20))).FpExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Collate)) != uint32(0) {
							pNext = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)) + 8 + uintptr(i)*20))).FpExpr
							break
						}
						goto _2
					_2:
						;
						i++
					}
				}
				p = pNext
			}
		} else {
			break
		}
	}
	if _sqlite3CheckCollSeq(tls, pParse, pColl) != 0 {
		pColl = uintptr(0)
	}
	return pColl
}

// C documentation
//
//	/*
//	** Return the collation sequence for the expression pExpr. If
//	** there is no defined collating sequence, return a pointer to the
//	** default collation sequence.
//	**
//	** See also: sqlite3ExprCollSeq()
//	**
//	** The sqlite3ExprCollSeq() routine works the same except that it
//	** returns NULL if there is no defined collation.
//	*/
func _sqlite3ExprNNCollSeq(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3ExprCollSeq(tls, pParse, pExpr)
	if p == uintptr(0) {
		p = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
	}
	return p
}

// C documentation
//
//	/*
//	** Return TRUE if the two expressions have equivalent collating sequences.
//	*/
func _sqlite3ExprCollSeqMatch(tls *libc.TLS, pParse uintptr, pE1 uintptr, pE2 uintptr) (r int32) {
	var pColl1, pColl2 uintptr
	_, _ = pColl1, pColl2
	pColl1 = _sqlite3ExprNNCollSeq(tls, pParse, pE1)
	pColl2 = _sqlite3ExprNNCollSeq(tls, pParse, pE2)
	return libc.BoolInt32(_sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pColl1)).FzName, (*TCollSeq)(unsafe.Pointer(pColl2)).FzName) == 0)
}

// C documentation
//
//	/*
//	** pExpr is an operand of a comparison operator.  aff2 is the
//	** type affinity of the other operand.  This routine returns the
//	** type affinity that should be used for the comparison operator.
//	*/
func _sqlite3CompareAffinity(tls *libc.TLS, pExpr uintptr, aff2 int8) (r int8) {
	var aff1 int8
	var v1 int32
	_, _ = aff1, v1
	aff1 = _sqlite3ExprAffinity(tls, pExpr)
	if int32(int32(aff1)) > int32(SQLITE_AFF_NONE) && int32(int32(aff2)) > int32(SQLITE_AFF_NONE) {
		/* Both sides of the comparison are columns. If one has numeric
		 ** affinity, use that. Otherwise use no affinity.
		 */
		if int32(aff1) >= int32(SQLITE_AFF_NUMERIC) || int32(aff2) >= int32(SQLITE_AFF_NUMERIC) {
			return int8(SQLITE_AFF_NUMERIC)
		} else {
			return int8(SQLITE_AFF_BLOB)
		}
	} else {
		/* One side is a column, the other is not. Use the columns affinity. */
		if int32(int32(aff1)) <= int32(SQLITE_AFF_NONE) {
			v1 = int32(int32(aff2))
		} else {
			v1 = int32(int32(aff1))
		}
		return int8(v1 | int32(SQLITE_AFF_NONE))
	}
	return r
}

// C documentation
//
//	/*
//	** pExpr is a comparison operator.  Return the type affinity that should
//	** be applied to both operands prior to doing the comparison.
//	*/
func _comparisonAffinity(tls *libc.TLS, pExpr uintptr) (r int8) {
	var aff int8
	_ = aff
	aff = _sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
	if (*TExpr)(unsafe.Pointer(pExpr)).FpRight != 0 {
		aff = _sqlite3CompareAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, aff)
	} else {
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			aff = _sqlite3CompareAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpEList + 8))).FpExpr, aff)
		} else {
			if int32(int32(aff)) == 0 {
				aff = int8(SQLITE_AFF_BLOB)
			}
		}
	}
	return aff
}

// C documentation
//
//	/*
//	** pExpr is a comparison expression, eg. '=', '<', IN(...) etc.
//	** idx_affinity is the affinity of an indexed column. Return true
//	** if the index with affinity idx_affinity may be used to implement
//	** the comparison in pExpr.
//	*/
func _sqlite3IndexAffinityOk(tls *libc.TLS, pExpr uintptr, idx_affinity int8) (r int32) {
	var aff int8
	_ = aff
	aff = _comparisonAffinity(tls, pExpr)
	if int32(int32(aff)) < int32(SQLITE_AFF_TEXT) {
		return int32(1)
	}
	if int32(int32(aff)) == int32(SQLITE_AFF_TEXT) {
		return libc.BoolInt32(int32(int32(idx_affinity)) == int32(SQLITE_AFF_TEXT))
	}
	return libc.BoolInt32(int32(idx_affinity) >= int32(SQLITE_AFF_NUMERIC))
}

// C documentation
//
//	/*
//	** Return the P5 value that should be used for a binary comparison
//	** opcode (OP_Eq, OP_Ge etc.) used to compare pExpr1 and pExpr2.
//	*/
func _binaryCompareP5(tls *libc.TLS, pExpr1 uintptr, pExpr2 uintptr, jumpIfNull int32) (r Tu8) {
	var aff Tu8
	_ = aff
	aff = uint8(_sqlite3ExprAffinity(tls, pExpr2))
	aff = uint8(int32(uint8(_sqlite3CompareAffinity(tls, pExpr1, int8(int8(aff))))) | int32(uint8(uint8(jumpIfNull))))
	return aff
}

// C documentation
//
//	/*
//	** Return a pointer to the collation sequence that should be used by
//	** a binary comparison operator comparing pLeft and pRight.
//	**
//	** If the left hand expression has a collating sequence type, then it is
//	** used. Otherwise the collation sequence for the right hand expression
//	** is used, or the default (BINARY) if neither expression has a collating
//	** type.
//	**
//	** Argument pRight (but not pLeft) may be a null pointer. In this case,
//	** it is not considered.
//	*/
func _sqlite3BinaryCompareCollSeq(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr) (r uintptr) {
	var pColl uintptr
	_ = pColl
	if (*TExpr)(unsafe.Pointer(pLeft)).Fflags&uint32(EP_Collate) != 0 {
		pColl = _sqlite3ExprCollSeq(tls, pParse, pLeft)
	} else {
		if pRight != 0 && (*TExpr)(unsafe.Pointer(pRight)).Fflags&uint32(EP_Collate) != uint32(0) {
			pColl = _sqlite3ExprCollSeq(tls, pParse, pRight)
		} else {
			pColl = _sqlite3ExprCollSeq(tls, pParse, pLeft)
			if !(pColl != 0) {
				pColl = _sqlite3ExprCollSeq(tls, pParse, pRight)
			}
		}
	}
	return pColl
}

// C documentation
//
//	/* Expression p is a comparison operator.  Return a collation sequence
//	** appropriate for the comparison operator.
//	**
//	** This is normally just a wrapper around sqlite3BinaryCompareCollSeq().
//	** However, if the OP_Commuted flag is set, then the order of the operands
//	** is reversed in the sqlite3BinaryCompareCollSeq() call so that the
//	** correct collating sequence is found.
//	*/
func _sqlite3ExprCompareCollSeq(tls *libc.TLS, pParse uintptr, p uintptr) (r uintptr) {
	if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_Commuted)) != uint32(0) {
		return _sqlite3BinaryCompareCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpRight, (*TExpr)(unsafe.Pointer(p)).FpLeft)
	} else {
		return _sqlite3BinaryCompareCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpLeft, (*TExpr)(unsafe.Pointer(p)).FpRight)
	}
	return r
}

// C documentation
//
//	/*
//	** Generate code for a comparison operator.
//	*/
func _codeCompare(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr, opcode int32, in1 int32, in2 int32, dest int32, jumpIfNull int32, isCommuted int32) (r int32) {
	var addr, p5 int32
	var p4 uintptr
	_, _, _ = addr, p4, p5
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return 0
	}
	if isCommuted != 0 {
		p4 = _sqlite3BinaryCompareCollSeq(tls, pParse, pRight, pLeft)
	} else {
		p4 = _sqlite3BinaryCompareCollSeq(tls, pParse, pLeft, pRight)
	}
	p5 = int32(_binaryCompareP5(tls, pLeft, pRight, jumpIfNull))
	addr = _sqlite3VdbeAddOp4(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, opcode, in2, dest, in1, p4, -int32(2))
	_sqlite3VdbeChangeP5(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, uint16(uint8(uint8(p5))))
	return addr
}

// C documentation
//
//	/*
//	** Return true if expression pExpr is a vector, or false otherwise.
//	**
//	** A vector is defined as any expression that results in two or more
//	** columns of result.  Every TK_VECTOR node is an vector because the
//	** parser will not generate a TK_VECTOR with fewer than two entries.
//	** But a TK_SELECT might be either a vector or a scalar. It is only
//	** considered a vector if it has two or more result columns.
//	*/
func _sqlite3ExprIsVector(tls *libc.TLS, pExpr uintptr) (r int32) {
	return libc.BoolInt32(_sqlite3ExprVectorSize(tls, pExpr) > int32(1))
}

// C documentation
//
//	/*
//	** If the expression passed as the only argument is of type TK_VECTOR
//	** return the number of expressions in the vector. Or, if the expression
//	** is a sub-select, return the number of columns in the sub-select. For
//	** any other type of expression, return 1.
//	*/
func _sqlite3ExprVectorSize(tls *libc.TLS, pExpr uintptr) (r int32) {
	var op Tu8
	_ = op
	op = (*TExpr)(unsafe.Pointer(pExpr)).Fop
	if int32(int32(op)) == int32(TK_REGISTER) {
		op = (*TExpr)(unsafe.Pointer(pExpr)).Fop2
	}
	if int32(int32(op)) == int32(TK_VECTOR) {
		return (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr
	} else {
		if int32(int32(op)) == int32(TK_SELECT) {
			return (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpEList)).FnExpr
		} else {
			return int32(1)
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Return a pointer to a subexpression of pVector that is the i-th
//	** column of the vector (numbered starting with 0).  The caller must
//	** ensure that i is within range.
//	**
//	** If pVector is really a scalar (and "scalar" here includes subqueries
//	** that return a single column!) then return pVector unmodified.
//	**
//	** pVector retains ownership of the returned subexpression.
//	**
//	** If the vector is a (SELECT ...) then the expression returned is
//	** just the expression for the i-th term of the result set, and may
//	** not be ready for evaluation because the table cursor has not yet
//	** been positioned.
//	*/
func _sqlite3VectorFieldSubexpr(tls *libc.TLS, pVector uintptr, i int32) (r uintptr) {
	if _sqlite3ExprIsVector(tls, pVector) != 0 {
		if int32((*TExpr)(unsafe.Pointer(pVector)).Fop) == int32(TK_SELECT) || int32((*TExpr)(unsafe.Pointer(pVector)).Fop2) == int32(TK_SELECT) {
			return (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 20)))).FpEList + 8 + uintptr(i)*20))).FpExpr
		} else {
			return (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 20)) + 8 + uintptr(i)*20))).FpExpr
		}
	}
	return pVector
}

// C documentation
//
//	/*
//	** Compute and return a new Expr object which when passed to
//	** sqlite3ExprCode() will generate all necessary code to compute
//	** the iField-th column of the vector expression pVector.
//	**
//	** It is ok for pVector to be a scalar (as long as iField==0).
//	** In that case, this routine works like sqlite3ExprDup().
//	**
//	** The caller owns the returned Expr object and is responsible for
//	** ensuring that the returned value eventually gets freed.
//	**
//	** The caller retains ownership of pVector.  If pVector is a TK_SELECT,
//	** then the returned object will reference pVector and so pVector must remain
//	** valid for the life of the returned object.  If pVector is a TK_VECTOR
//	** or a scalar expression, then it can be deleted as soon as this routine
//	** returns.
//	**
//	** A trick to cause a TK_SELECT pVector to be deleted together with
//	** the returned Expr object is to attach the pVector to the pRight field
//	** of the returned TK_SELECT_COLUMN Expr object.
//	*/
func _sqlite3ExprForVectorField(tls *libc.TLS, pParse uintptr, pVector uintptr, iField int32, nField int32) (r uintptr) {
	var pRet, ppVector uintptr
	_, _ = pRet, ppVector
	if int32((*TExpr)(unsafe.Pointer(pVector)).Fop) == int32(TK_SELECT) {
		/* The TK_SELECT_COLUMN Expr node:
		 **
		 ** pLeft:           pVector containing TK_SELECT.  Not deleted.
		 ** pRight:          not used.  But recursively deleted.
		 ** iColumn:         Index of a column in pVector
		 ** iTable:          0 or the number of columns on the LHS of an assignment
		 ** pLeft->iTable:   First in an array of register holding result, or 0
		 **                  if the result is not yet computed.
		 **
		 ** sqlite3ExprDelete() specifically skips the recursive delete of
		 ** pLeft on TK_SELECT_COLUMN nodes.  But pRight is followed, so pVector
		 ** can be attached to pRight to cause this node to take ownership of
		 ** pVector.  Typically there will be multiple TK_SELECT_COLUMN nodes
		 ** with the same pLeft pointer to the pVector, but only one of them
		 ** will own the pVector.
		 */
		pRet = _sqlite3PExpr(tls, pParse, int32(TK_SELECT_COLUMN), uintptr(0), uintptr(0))
		if pRet != 0 {
			*(*Tu32)(unsafe.Pointer(pRet + 4)) |= uint32(libc.Int32FromInt32(EP_FullSize))
			(*TExpr)(unsafe.Pointer(pRet)).FiTable = nField
			(*TExpr)(unsafe.Pointer(pRet)).FiColumn = int16(int16(iField))
			(*TExpr)(unsafe.Pointer(pRet)).FpLeft = pVector
		}
	} else {
		if int32((*TExpr)(unsafe.Pointer(pVector)).Fop) == int32(TK_VECTOR) {
			ppVector = *(*uintptr)(unsafe.Pointer(pVector + 20)) + 8 + uintptr(iField)*20
			pVector = *(*uintptr)(unsafe.Pointer(ppVector))
			if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
				/* This must be a vector UPDATE inside a trigger */
				*(*uintptr)(unsafe.Pointer(ppVector)) = uintptr(0)
				return pVector
			}
		}
		pRet = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pVector, 0)
	}
	return pRet
}

// C documentation
//
//	/*
//	** If expression pExpr is of type TK_SELECT, generate code to evaluate
//	** it. Return the register in which the result is stored (or, if the
//	** sub-select returns more than one column, the first in an array
//	** of registers in which the result is stored).
//	**
//	** If pExpr is not a TK_SELECT expression, return 0.
//	*/
func _exprCodeSubselect(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
	var reg int32
	_ = reg
	reg = 0
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) {
		reg = _sqlite3CodeSubselect(tls, pParse, pExpr)
	}
	return reg
}

// C documentation
//
//	/*
//	** Argument pVector points to a vector expression - either a TK_VECTOR
//	** or TK_SELECT that returns more than one column. This function returns
//	** the register number of a register that contains the value of
//	** element iField of the vector.
//	**
//	** If pVector is a TK_SELECT expression, then code for it must have
//	** already been generated using the exprCodeSubselect() routine. In this
//	** case parameter regSelect should be the first in an array of registers
//	** containing the results of the sub-select.
//	**
//	** If pVector is of type TK_VECTOR, then code for the requested field
//	** is generated. In this case (*pRegFree) may be set to the number of
//	** a temporary register to be freed by the caller before returning.
//	**
//	** Before returning, output parameter (*ppExpr) is set to point to the
//	** Expr object corresponding to element iElem of the vector.
//	*/
func _exprVectorRegister(tls *libc.TLS, pParse uintptr, pVector uintptr, iField int32, regSelect int32, ppExpr uintptr, pRegFree uintptr) (r int32) {
	var op Tu8
	_ = op
	op = (*TExpr)(unsafe.Pointer(pVector)).Fop
	if int32(int32(op)) == int32(TK_REGISTER) {
		*(*uintptr)(unsafe.Pointer(ppExpr)) = _sqlite3VectorFieldSubexpr(tls, pVector, iField)
		return (*TExpr)(unsafe.Pointer(pVector)).FiTable + iField
	}
	if int32(int32(op)) == int32(TK_SELECT) {
		*(*uintptr)(unsafe.Pointer(ppExpr)) = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 20)))).FpEList + 8 + uintptr(iField)*20))).FpExpr
		return regSelect + iField
	}
	if int32(int32(op)) == int32(TK_VECTOR) {
		*(*uintptr)(unsafe.Pointer(ppExpr)) = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 20)) + 8 + uintptr(iField)*20))).FpExpr
		return _sqlite3ExprCodeTemp(tls, pParse, *(*uintptr)(unsafe.Pointer(ppExpr)), pRegFree)
	}
	return 0
}

// C documentation
//
//	/*
//	** Expression pExpr is a comparison between two vector values. Compute
//	** the result of the comparison (1, 0, or NULL) and write that
//	** result into register dest.
//	**
//	** The caller must satisfy the following preconditions:
//	**
//	**    if pExpr->op==TK_IS:      op==TK_EQ and p5==SQLITE_NULLEQ
//	**    if pExpr->op==TK_ISNOT:   op==TK_NE and p5==SQLITE_NULLEQ
//	**    otherwise:                op==pExpr->op and p5==0
//	*/
func _codeVectorCompare(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, op Tu8, p5 Tu8) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var addrCmp, addrDone, i, isCommuted, nLeft, r1, r2, regLeft, regRight int32
	var opx Tu8
	var pLeft, pRight, v uintptr
	var _ /* pL at bp+8 */ uintptr
	var _ /* pR at bp+12 */ uintptr
	var _ /* regFree1 at bp+0 */ int32
	var _ /* regFree2 at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = addrCmp, addrDone, i, isCommuted, nLeft, opx, pLeft, pRight, r1, r2, regLeft, regRight, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
	nLeft = _sqlite3ExprVectorSize(tls, pLeft)
	regLeft = 0
	regRight = 0
	opx = op
	addrCmp = 0
	addrDone = _sqlite3VdbeMakeLabel(tls, pParse)
	isCommuted = libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Commuted)) != uint32(0))
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	if nLeft != _sqlite3ExprVectorSize(tls, pRight) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8050, 0)
		return
	}
	if int32(int32(op)) == int32(TK_LE) {
		opx = uint8(TK_LT)
	}
	if int32(int32(op)) == int32(TK_GE) {
		opx = uint8(TK_GT)
	}
	if int32(int32(op)) == int32(TK_NE) {
		opx = uint8(TK_EQ)
	}
	regLeft = _exprCodeSubselect(tls, pParse, pLeft)
	regRight = _exprCodeSubselect(tls, pParse, pRight)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), dest)
	i = 0
	for {
		if !(int32(1) != 0) {
			break
		}
		*(*int32)(unsafe.Pointer(bp)) = 0
		*(*int32)(unsafe.Pointer(bp + 4)) = 0
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
		if addrCmp != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrCmp)
		}
		r1 = _exprVectorRegister(tls, pParse, pLeft, i, regLeft, bp+8, bp)
		r2 = _exprVectorRegister(tls, pParse, pRight, i, regRight, bp+12, bp+4)
		addrCmp = _sqlite3VdbeCurrentAddr(tls, v)
		_codeCompare(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 8)), *(*uintptr)(unsafe.Pointer(bp + 12)), int32(int32(opx)), r1, r2, addrDone, int32(int32(p5)), isCommuted)
		_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
		_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 4)))
		if (int32(int32(opx)) == int32(TK_LT) || int32(int32(opx)) == int32(TK_GT)) && i < nLeft-int32(1) {
			addrCmp = _sqlite3VdbeAddOp0(tls, v, int32(OP_ElseEq))
		}
		if int32(int32(p5)) == int32(SQLITE_NULLEQ) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, dest)
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_ZeroOrNull), r1, dest, r2)
		}
		if i == nLeft-int32(1) {
			break
		}
		if int32(int32(opx)) == int32(TK_EQ) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), dest, addrDone)
		} else {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrDone)
			if i == nLeft-int32(2) {
				opx = op
			}
		}
		goto _1
	_1:
		;
		i++
	}
	_sqlite3VdbeJumpHere(tls, v, addrCmp)
	_sqlite3VdbeResolveLabel(tls, v, addrDone)
	if int32(int32(op)) == int32(TK_NE) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Not), dest, dest)
	}
}

// C documentation
//
//	/*
//	** Check that argument nHeight is less than or equal to the maximum
//	** expression depth allowed. If it is not, leave an error message in
//	** pParse.
//	*/
func _sqlite3ExprCheckHeight(tls *libc.TLS, pParse uintptr, nHeight int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var mxHeight, rc int32
	_, _ = mxHeight, rc
	rc = SQLITE_OK
	mxHeight = *(*int32)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb + 120 + 3*4))
	if nHeight > mxHeight {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9003, libc.VaList(bp+8, mxHeight))
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

// C documentation
//
//	/* The following three functions, heightOfExpr(), heightOfExprList()
//	** and heightOfSelect(), are used to determine the maximum height
//	** of any expression tree referenced by the structure passed as the
//	** first argument.
//	**
//	** If this maximum height is greater than the current value pointed
//	** to by pnHeight, the second parameter, then set *pnHeight to that
//	** value.
//	*/
func _heightOfExpr(tls *libc.TLS, p uintptr, pnHeight uintptr) {
	if p != 0 {
		if (*TExpr)(unsafe.Pointer(p)).FnHeight > *(*int32)(unsafe.Pointer(pnHeight)) {
			*(*int32)(unsafe.Pointer(pnHeight)) = (*TExpr)(unsafe.Pointer(p)).FnHeight
		}
	}
}

func _heightOfExprList(tls *libc.TLS, p uintptr, pnHeight uintptr) {
	var i int32
	_ = i
	if p != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(p)).FnExpr) {
				break
			}
			_heightOfExpr(tls, (*(*TExprList_item)(unsafe.Pointer(p + 8 + uintptr(i)*20))).FpExpr, pnHeight)
			goto _1
		_1:
			;
			i++
		}
	}
}

func _heightOfSelect(tls *libc.TLS, pSelect uintptr, pnHeight uintptr) {
	var p uintptr
	_ = p
	p = pSelect
	for {
		if !(p != 0) {
			break
		}
		_heightOfExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, pnHeight)
		_heightOfExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpHaving, pnHeight)
		_heightOfExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpLimit, pnHeight)
		_heightOfExprList(tls, (*TSelect)(unsafe.Pointer(p)).FpEList, pnHeight)
		_heightOfExprList(tls, (*TSelect)(unsafe.Pointer(p)).FpGroupBy, pnHeight)
		_heightOfExprList(tls, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, pnHeight)
		goto _1
	_1:
		;
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
	}
}

// C documentation
//
//	/*
//	** Set the Expr.nHeight variable in the structure passed as an
//	** argument. An expression with no children, Expr.pList or
//	** Expr.pSelect member has a height of 1. Any other expression
//	** has a height equal to the maximum height of any other
//	** referenced Expr plus one.
//	**
//	** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
//	** if appropriate.
//	*/
func _exprSetHeight(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var v1 int32
	var _ /* nHeight at bp+0 */ int32
	_ = v1
	if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 {
		v1 = (*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).FpLeft)).FnHeight
	} else {
		v1 = 0
	}
	*(*int32)(unsafe.Pointer(bp)) = v1
	if (*TExpr)(unsafe.Pointer(p)).FpRight != 0 && (*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).FpRight)).FnHeight > *(*int32)(unsafe.Pointer(bp)) {
		*(*int32)(unsafe.Pointer(bp)) = (*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).FpRight)).FnHeight
	}
	if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		_heightOfSelect(tls, *(*uintptr)(unsafe.Pointer(p + 20)), bp)
	} else {
		if *(*uintptr)(unsafe.Pointer(p + 20)) != 0 {
			_heightOfExprList(tls, *(*uintptr)(unsafe.Pointer(p + 20)), bp)
			*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(libc.Int32FromInt32(EP_Collate)|libc.Int32FromInt32(EP_Subquery)|libc.Int32FromInt32(EP_HasFunc)) & _sqlite3ExprListFlags(tls, *(*uintptr)(unsafe.Pointer(p + 20)))
		}
	}
	(*TExpr)(unsafe.Pointer(p)).FnHeight = *(*int32)(unsafe.Pointer(bp)) + int32(1)
}

// C documentation
//
//	/*
//	** Set the Expr.nHeight variable using the exprSetHeight() function. If
//	** the height is greater than the maximum allowed expression depth,
//	** leave an error in pParse.
//	**
//	** Also propagate all EP_Propagate flags from the Expr.x.pList into
//	** Expr.flags.
//	*/
func _sqlite3ExprSetHeightAndFlags(tls *libc.TLS, pParse uintptr, p uintptr) {
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	_exprSetHeight(tls, p)
	_sqlite3ExprCheckHeight(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FnHeight)
}

// C documentation
//
//	/*
//	** Return the maximum height of any expression tree referenced
//	** by the select statement passed as an argument.
//	*/
func _sqlite3SelectExprHeight(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* nHeight at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = 0
	_heightOfSelect(tls, p, bp)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Set the error offset for an Expr node, if possible.
//	*/
func _sqlite3ExprSetErrorOffset(tls *libc.TLS, pExpr uintptr, iOfst int32) {
	if pExpr == uintptr(0) {
		return
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_InnerON)|libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
		return
	}
	*(*int32)(unsafe.Pointer(pExpr + 36)) = iOfst
}

// C documentation
//
//	/*
//	** This routine is the core allocator for Expr nodes.
//	**
//	** Construct a new expression node and return a pointer to it.  Memory
//	** for this node and for the pToken argument is a single allocation
//	** obtained from sqlite3DbMalloc().  The calling function
//	** is responsible for making sure the node eventually gets freed.
//	**
//	** If dequote is true, then the token (if it exists) is dequoted.
//	** If dequote is false, no dequoting is performed.  The deQuote
//	** parameter is ignored if pToken is NULL or if the token does not
//	** appear to be quoted.  If the quotes were of the form "..." (double-quotes)
//	** then the EP_DblQuoted flag is set on the expression node.
//	**
//	** Special case (tag-20240227-a):  If op==TK_INTEGER and pToken points to
//	** a string that can be translated into a 32-bit integer, then the token is
//	** not stored in u.zToken.  Instead, the integer values is written
//	** into u.iValue and the EP_IntValue flag is set. No extra storage
//	** is allocated to hold the integer text and the dequote flag is ignored.
//	** See also tag-20240227-b.
//	*/
func _sqlite3ExprAlloc(tls *libc.TLS, db uintptr, op int32, pToken uintptr, dequote int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nExtra, v1 int32
	var pNew uintptr
	var _ /* iValue at bp+0 */ int32
	_, _, _ = nExtra, pNew, v1
	nExtra = 0
	*(*int32)(unsafe.Pointer(bp)) = 0
	if pToken != 0 {
		if op != int32(TK_INTEGER) || (*TToken)(unsafe.Pointer(pToken)).Fz == uintptr(0) || _sqlite3GetInt32(tls, (*TToken)(unsafe.Pointer(pToken)).Fz, bp) == 0 {
			nExtra = int32((*TToken)(unsafe.Pointer(pToken)).Fn + uint32(1)) /* tag-20240227-a */
		}
	}
	pNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(52)+uint32(uint32(nExtra))))
	if pNew != 0 {
		libc.Xmemset(tls, pNew, 0, uint32(52))
		(*TExpr)(unsafe.Pointer(pNew)).Fop = uint8(uint8(op))
		(*TExpr)(unsafe.Pointer(pNew)).FiAgg = int16(-int32(1))
		if pToken != 0 {
			if nExtra == 0 {
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					v1 = int32(EP_IsTrue)
				} else {
					v1 = int32(EP_IsFalse)
				}
				*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(libc.Int32FromInt32(EP_IntValue) | libc.Int32FromInt32(EP_Leaf) | v1)
				*(*int32)(unsafe.Pointer(pNew + 8)) = *(*int32)(unsafe.Pointer(bp))
			} else {
				*(*uintptr)(unsafe.Pointer(pNew + 8)) = pNew + 1*52
				if (*TToken)(unsafe.Pointer(pToken)).Fn != 0 {
					libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(pNew + 8)), (*TToken)(unsafe.Pointer(pToken)).Fz, (*TToken)(unsafe.Pointer(pToken)).Fn)
				}
				*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNew + 8)) + uintptr((*TToken)(unsafe.Pointer(pToken)).Fn))) = 0
				if dequote != 0 && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNew + 8)))))])&int32(0x80) != 0 {
					_sqlite3DequoteExpr(tls, pNew)
				}
			}
		}
		(*TExpr)(unsafe.Pointer(pNew)).FnHeight = int32(1)
	}
	return pNew
}

// C documentation
//
//	/*
//	** Allocate a new expression node from a zero-terminated token that has
//	** already been dequoted.
//	*/
func _sqlite3Expr(tls *libc.TLS, db uintptr, op int32, zToken uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* x at bp+0 */ TToken
	(*(*TToken)(unsafe.Pointer(bp))).Fz = zToken
	(*(*TToken)(unsafe.Pointer(bp))).Fn = uint32(_sqlite3Strlen30(tls, zToken))
	return _sqlite3ExprAlloc(tls, db, op, bp, 0)
}

// C documentation
//
//	/*
//	** Attach subtrees pLeft and pRight to the Expr node pRoot.
//	**
//	** If pRoot==NULL that means that a memory allocation error has occurred.
//	** In that case, delete the subtrees pLeft and pRight.
//	*/
func _sqlite3ExprAttachSubtrees(tls *libc.TLS, db uintptr, pRoot uintptr, pLeft uintptr, pRight uintptr) {
	if pRoot == uintptr(0) {
		_sqlite3ExprDelete(tls, db, pLeft)
		_sqlite3ExprDelete(tls, db, pRight)
	} else {
		if pRight != 0 {
			(*TExpr)(unsafe.Pointer(pRoot)).FpRight = pRight
			*(*Tu32)(unsafe.Pointer(pRoot + 4)) |= uint32(libc.Int32FromInt32(EP_Collate)|libc.Int32FromInt32(EP_Subquery)|libc.Int32FromInt32(EP_HasFunc)) & (*TExpr)(unsafe.Pointer(pRight)).Fflags
			(*TExpr)(unsafe.Pointer(pRoot)).FnHeight = (*TExpr)(unsafe.Pointer(pRight)).FnHeight + int32(1)
		} else {
			(*TExpr)(unsafe.Pointer(pRoot)).FnHeight = int32(1)
		}
		if pLeft != 0 {
			(*TExpr)(unsafe.Pointer(pRoot)).FpLeft = pLeft
			*(*Tu32)(unsafe.Pointer(pRoot + 4)) |= uint32(libc.Int32FromInt32(EP_Collate)|libc.Int32FromInt32(EP_Subquery)|libc.Int32FromInt32(EP_HasFunc)) & (*TExpr)(unsafe.Pointer(pLeft)).Fflags
			if (*TExpr)(unsafe.Pointer(pLeft)).FnHeight >= (*TExpr)(unsafe.Pointer(pRoot)).FnHeight {
				(*TExpr)(unsafe.Pointer(pRoot)).FnHeight = (*TExpr)(unsafe.Pointer(pLeft)).FnHeight + int32(1)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Allocate an Expr node which joins as many as two subtrees.
//	**
//	** One or both of the subtrees can be NULL.  Return a pointer to the new
//	** Expr node.  Or, if an OOM error occurs, set pParse->db->mallocFailed,
//	** free the subtrees and return NULL.
//	*/
func _sqlite3PExpr(tls *libc.TLS, pParse uintptr, op int32, pLeft uintptr, pRight uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(52))
	if p != 0 {
		libc.Xmemset(tls, p, 0, uint32(52))
		(*TExpr)(unsafe.Pointer(p)).Fop = uint8(op & int32(0xff))
		(*TExpr)(unsafe.Pointer(p)).FiAgg = int16(-int32(1))
		_sqlite3ExprAttachSubtrees(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, p, pLeft, pRight)
		_sqlite3ExprCheckHeight(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FnHeight)
	} else {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pLeft)
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pRight)
	}
	return p
}

// C documentation
//
//	/*
//	** Add pSelect to the Expr.x.pSelect field.  Or, if pExpr is NULL (due
//	** do a memory allocation failure) then delete the pSelect object.
//	*/
func _sqlite3PExprAddSelect(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSelect uintptr) {
	if pExpr != 0 {
		*(*uintptr)(unsafe.Pointer(pExpr + 20)) = pSelect
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_xIsSelect) | libc.Int32FromInt32(EP_Subquery))
		_sqlite3ExprSetHeightAndFlags(tls, pParse, pExpr)
	} else {
		_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSelect)
	}
}

// C documentation
//
//	/*
//	** Expression list pEList is a list of vector values. This function
//	** converts the contents of pEList to a VALUES(...) Select statement
//	** returning 1 row for each element of the list. For example, the
//	** expression list:
//	**
//	**   ( (1,2), (3,4) (5,6) )
//	**
//	** is translated to the equivalent of:
//	**
//	**   VALUES(1,2), (3,4), (5,6)
//	**
//	** Each of the vector values in pEList must contain exactly nElem terms.
//	** If a list element that is not a vector or does not contain nElem terms,
//	** an error message is left in pParse.
//	**
//	** This is used as part of processing IN(...) expressions with a list
//	** of vectors on the RHS. e.g. "... IN ((1,2), (3,4), (5,6))".
//	*/
func _sqlite3ExprListToValues(tls *libc.TLS, pParse uintptr, nElem int32, pEList uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ii, nExprElem int32
	var pExpr, pRet, pSel, v2 uintptr
	_, _, _, _, _, _ = ii, nExprElem, pExpr, pRet, pSel, v2
	pRet = uintptr(0)
	ii = 0
	for {
		if !(ii < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		pExpr = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*20))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VECTOR) {
			nExprElem = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr
		} else {
			nExprElem = int32(1)
		}
		if nExprElem != nElem {
			if nExprElem > int32(1) {
				v2 = __ccgo_ts + 9051
			} else {
				v2 = __ccgo_ts + 1672
			}
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9053, libc.VaList(bp+8, nExprElem, v2, nElem))
			break
		}
		pSel = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(pExpr + 20)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
		*(*uintptr)(unsafe.Pointer(pExpr + 20)) = uintptr(0)
		if pSel != 0 {
			if pRet != 0 {
				(*TSelect)(unsafe.Pointer(pSel)).Fop = uint8(TK_ALL)
				(*TSelect)(unsafe.Pointer(pSel)).FpPrior = pRet
			}
			pRet = pSel
		}
		goto _1
	_1:
		;
		ii++
	}
	if pRet != 0 && (*TSelect)(unsafe.Pointer(pRet)).FpPrior != 0 {
		*(*Tu32)(unsafe.Pointer(pRet + 4)) |= uint32(SF_MultiValue)
	}
	_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pEList)
	return pRet
}

// C documentation
//
//	/*
//	** Join two expressions using an AND operator.  If either expression is
//	** NULL, then just return the other expression.
//	**
//	** If one side or the other of the AND is known to be false, and neither side
//	** is part of an ON clause, then instead of returning an AND expression,
//	** just return a constant expression with a value of false.
//	*/
func _sqlite3ExprAnd(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr) (r uintptr) {
	var db uintptr
	var f Tu32
	_, _ = db, f
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pLeft == uintptr(0) {
		return pRight
	} else {
		if pRight == uintptr(0) {
			return pLeft
		} else {
			f = (*TExpr)(unsafe.Pointer(pLeft)).Fflags | (*TExpr)(unsafe.Pointer(pRight)).Fflags
			if f&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)|libc.Int32FromInt32(EP_IsFalse)) == uint32(EP_IsFalse) && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
				_sqlite3ExprDeferredDelete(tls, pParse, pLeft)
				_sqlite3ExprDeferredDelete(tls, pParse, pRight)
				return _sqlite3Expr(tls, db, int32(TK_INTEGER), __ccgo_ts+1792)
			} else {
				return _sqlite3PExpr(tls, pParse, int32(TK_AND), pLeft, pRight)
			}
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Construct a new expression node for a function with multiple
//	** arguments.
//	*/
func _sqlite3ExprFunction(tls *libc.TLS, pParse uintptr, pList uintptr, pToken uintptr, eDistinct int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pNew uintptr
	_, _ = db, pNew
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = _sqlite3ExprAlloc(tls, db, int32(TK_FUNCTION), pToken, int32(1))
	if pNew == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pList) /* Avoid memory leak when malloc fails */
		return uintptr(0)
	}
	*(*int32)(unsafe.Pointer(pNew + 36)) = int32((*TToken)(unsafe.Pointer(pToken)).Fz) - int32((*TParse)(unsafe.Pointer(pParse)).FzTail)
	if pList != 0 && (*TExprList)(unsafe.Pointer(pList)).FnExpr > *(*int32)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb + 120 + 6*4)) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9097, libc.VaList(bp+8, pToken))
	}
	*(*uintptr)(unsafe.Pointer(pNew + 20)) = pList
	*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(libc.Int32FromInt32(EP_HasFunc))
	_sqlite3ExprSetHeightAndFlags(tls, pParse, pNew)
	if eDistinct == int32(SF_Distinct) {
		*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(libc.Int32FromInt32(EP_Distinct))
	}
	return pNew
}

// C documentation
//
//	/*
//	** Report an error when attempting to use an ORDER BY clause within
//	** the arguments of a non-aggregate function.
//	*/
func _sqlite3ExprOrderByAggregateError(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9131, libc.VaList(bp+8, p))
}

// C documentation
//
//	/*
//	** Attach an ORDER BY clause to a function call.
//	**
//	**     functionname( arguments ORDER BY sortlist )
//	**     \_____________________/          \______/
//	**             pExpr                    pOrderBy
//	**
//	** The ORDER BY clause is inserted into a new Expr node of type TK_ORDER
//	** and added to the Expr.pLeft field of the parent TK_FUNCTION node.
//	*/
func _sqlite3ExprAddFunctionOrderBy(tls *libc.TLS, pParse uintptr, pExpr uintptr, pOrderBy uintptr) {
	var db, pOB uintptr
	_, _ = db, pOB
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pOrderBy == uintptr(0) {
		return
	}
	if pExpr == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pOrderBy)
		return
	}
	if *(*uintptr)(unsafe.Pointer(pExpr + 20)) == uintptr(0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr == 0 {
		/* Ignore ORDER BY on zero-argument aggregates */
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), pOrderBy)
		return
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) && int32((*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FeFrmType) != int32(TK_FILTER) {
		_sqlite3ExprOrderByAggregateError(tls, pParse, pExpr)
		_sqlite3ExprListDelete(tls, db, pOrderBy)
		return
	}
	pOB = _sqlite3ExprAlloc(tls, db, int32(TK_ORDER), uintptr(0), 0)
	if pOB == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pOrderBy)
		return
	}
	*(*uintptr)(unsafe.Pointer(pOB + 20)) = pOrderBy
	(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = pOB
	*(*Tu32)(unsafe.Pointer(pOB + 4)) |= uint32(libc.Int32FromInt32(EP_FullSize))
}

// C documentation
//
//	/*
//	** Check to see if a function is usable according to current access
//	** rules:
//	**
//	**    SQLITE_FUNC_DIRECT    -     Only usable from top-level SQL
//	**
//	**    SQLITE_FUNC_UNSAFE    -     Usable if TRUSTED_SCHEMA or from
//	**                                top-level SQL
//	**
//	** If the function is not usable, create an error.
//	*/
func _sqlite3ExprFunctionUsable(tls *libc.TLS, pParse uintptr, pExpr uintptr, pDef uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_FromDDL)) != uint32(0) {
		if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_DIRECT) != uint32(0) || (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_TrustedSchema) == uint64(0) {
			/* Functions prohibited in triggers and views if:
			 **     (1) tagged with SQLITE_DIRECTONLY
			 **     (2) not tagged with SQLITE_INNOCUOUS (which means it
			 **         is tagged with SQLITE_FUNC_UNSAFE) and
			 **         SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
			 **         that the schema is possibly tainted).
			 */
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9181, libc.VaList(bp+8, pExpr))
		}
	}
}

// C documentation
//
//	/*
//	** Assign a variable number to an expression that encodes a wildcard
//	** in the original SQL statement.
//	**
//	** Wildcards consisting of a single "?" are assigned the next sequential
//	** variable number.
//	**
//	** Wildcards of the form "?nnn" are assigned the number "nnn".  We make
//	** sure "nnn" is not too big to avoid a denial of service attack when
//	** the SQL statement comes from an external source.
//	**
//	** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
//	** as the previous instance of the same wildcard.  Or if this is the first
//	** instance of the wildcard, the next sequential variable number is
//	** assigned.
//	*/
func _sqlite3ExprAssignVarNumber(tls *libc.TLS, pParse uintptr, pExpr uintptr, n Tu32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bOk, doAdd int32
	var db, z, v2, v4 uintptr
	var x, v1, v3 TynVar
	var _ /* i at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _ = bOk, db, doAdd, x, z, v1, v2, v3, v4
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pExpr == uintptr(0) {
		return
	}
	z = *(*uintptr)(unsafe.Pointer(pExpr + 8))
	if int32(*(*int8)(unsafe.Pointer(z + 1))) == 0 {
		/* Wildcard of the form "?".  Assign the next variable number */
		v2 = pParse + 216
		*(*TynVar)(unsafe.Pointer(v2))++
		v1 = *(*TynVar)(unsafe.Pointer(v2))
		x = v1
	} else {
		doAdd = 0
		if int32(*(*int8)(unsafe.Pointer(z))) == int32('?') {
			if n == uint32(2) { /*OPTIMIZATION-IF-TRUE*/
				*(*Ti64)(unsafe.Pointer(bp)) = int64(int32(*(*int8)(unsafe.Pointer(z + 1))) - int32('0')) /* The common case of ?N for a single digit N */
				bOk = int32(1)
			} else {
				bOk = libc.BoolInt32(0 == _sqlite3Atoi64(tls, z+1, bp, int32(n-uint32(1)), uint8(SQLITE_UTF8)))
			}
			if bOk == 0 || *(*Ti64)(unsafe.Pointer(bp)) < int64(1) || *(*Ti64)(unsafe.Pointer(bp)) > int64(*(*int32)(unsafe.Pointer(db + 120 + 9*4))) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9201, libc.VaList(bp+16, *(*int32)(unsafe.Pointer(db + 120 + 9*4))))
				_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
				return
			}
			x = int16(*(*Ti64)(unsafe.Pointer(bp)))
			if int32(int32(x)) > int32((*TParse)(unsafe.Pointer(pParse)).FnVar) {
				(*TParse)(unsafe.Pointer(pParse)).FnVar = int16(int32(int32(x)))
				doAdd = int32(1)
			} else {
				if _sqlite3VListNumToName(tls, (*TParse)(unsafe.Pointer(pParse)).FpVList, int32(int32(x))) == uintptr(0) {
					doAdd = int32(1)
				}
			}
		} else {
			/* Wildcards like ":aaa", "$aaa" or "@aaa".  Reuse the same variable
			 ** number as the prior appearance of the same name, or if the name
			 ** has never appeared before, reuse the same variable number
			 */
			x = int16(_sqlite3VListNameToNum(tls, (*TParse)(unsafe.Pointer(pParse)).FpVList, z, int32(int32(n))))
			if int32(int32(x)) == 0 {
				v4 = pParse + 216
				*(*TynVar)(unsafe.Pointer(v4))++
				v3 = *(*TynVar)(unsafe.Pointer(v4))
				x = v3
				doAdd = int32(1)
			}
		}
		if doAdd != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FpVList = _sqlite3VListAdd(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpVList, z, int32(int32(n)), int32(int32(x)))
		}
	}
	(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = x
	if int32(int32(x)) > *(*int32)(unsafe.Pointer(db + 120 + 9*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9244, 0)
		_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
	}
}

// C documentation
//
//	/*
//	** Recursively delete an expression tree.
//	*/
func _sqlite3ExprDeleteNN(tls *libc.TLS, db uintptr, p uintptr) {
	var pLeft uintptr
	_ = pLeft
	goto exprDeleteRestart
exprDeleteRestart:
	;
	if !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Leaf)) != libc.Uint32FromInt32(0)) {
		/* The Expr.x union is never used at the same time as Expr.pRight */
		if (*TExpr)(unsafe.Pointer(p)).FpRight != 0 {
			_sqlite3ExprDeleteNN(tls, db, (*TExpr)(unsafe.Pointer(p)).FpRight)
		} else {
			if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
				_sqlite3SelectDelete(tls, db, *(*uintptr)(unsafe.Pointer(p + 20)))
			} else {
				_sqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(p + 20)))
				if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
					_sqlite3WindowDelete(tls, db, *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(p)).Fy)))
				}
			}
		}
		if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 && int32((*TExpr)(unsafe.Pointer(p)).Fop) != int32(TK_SELECT_COLUMN) {
			pLeft = (*TExpr)(unsafe.Pointer(p)).FpLeft
			if !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_Static)) != libc.Uint32FromInt32(0)) && !((*TExpr)(unsafe.Pointer(pLeft)).Fflags&uint32(libc.Int32FromInt32(EP_Static)) != libc.Uint32FromInt32(0)) {
				/* Avoid unnecessary recursion on unary operators */
				_sqlite3DbNNFreeNN(tls, db, p)
				p = pLeft
				goto exprDeleteRestart
			} else {
				_sqlite3ExprDeleteNN(tls, db, pLeft)
			}
		}
	}
	if !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_Static)) != libc.Uint32FromInt32(0)) {
		_sqlite3DbNNFreeNN(tls, db, p)
	}
}

func _sqlite3ExprDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		_sqlite3ExprDeleteNN(tls, db, p)
	}
}

func _sqlite3ExprDeleteGeneric(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		_sqlite3ExprDeleteNN(tls, db, p)
	}
}

// C documentation
//
//	/*
//	** Clear both elements of an OnOrUsing object
//	*/
func _sqlite3ClearOnOrUsing(tls *libc.TLS, db uintptr, p uintptr) {
	if p == uintptr(0) {
		/* Nothing to clear */
	} else {
		if (*TOnOrUsing)(unsafe.Pointer(p)).FpOn != 0 {
			_sqlite3ExprDeleteNN(tls, db, (*TOnOrUsing)(unsafe.Pointer(p)).FpOn)
		} else {
			if (*TOnOrUsing)(unsafe.Pointer(p)).FpUsing != 0 {
				_sqlite3IdListDelete(tls, db, (*TOnOrUsing)(unsafe.Pointer(p)).FpUsing)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Arrange to cause pExpr to be deleted when the pParse is deleted.
//	** This is similar to sqlite3ExprDelete() except that the delete is
//	** deferred until the pParse is deleted.
//	**
//	** The pExpr might be deleted immediately on an OOM error.
//	**
//	** Return 0 if the delete was successfully deferred.  Return non-zero
//	** if the delete happened immediately because of an OOM.
//	*/
func _sqlite3ExprDeferredDelete(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
	return libc.BoolInt32(uintptr(0) == _sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprDeleteGeneric), pExpr))
}

// C documentation
//
//	/* Invoke sqlite3RenameExprUnmap() and sqlite3ExprDelete() on the
//	** expression.
//	*/
func _sqlite3ExprUnmapAndDelete(tls *libc.TLS, pParse uintptr, p uintptr) {
	if p != 0 {
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameExprUnmap(tls, pParse, p)
		}
		_sqlite3ExprDeleteNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, p)
	}
}

// C documentation
//
//	/*
//	** Return the number of bytes allocated for the expression structure
//	** passed as the first argument. This is always one of EXPR_FULLSIZE,
//	** EXPR_REDUCEDSIZE or EXPR_TOKENONLYSIZE.
//	*/
func _exprStructSize(tls *libc.TLS, p uintptr) (r int32) {
	if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_TokenOnly)) != uint32(0) {
		return int32(uint32(libc.UintptrFromInt32(0) + 12))
	}
	if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_Reduced)) != uint32(0) {
		return int32(uint32(libc.UintptrFromInt32(0) + 28))
	}
	return int32(52)
}

// C documentation
//
//	/*
//	** The dupedExpr*Size() routines each return the number of bytes required
//	** to store a copy of an expression or expression tree.  They differ in
//	** how much of the tree is measured.
//	**
//	**     dupedExprStructSize()     Size of only the Expr structure
//	**     dupedExprNodeSize()       Size of Expr + space for token
//	**     dupedExprSize()           Expr + token + subtree components
//	**
//	***************************************************************************
//	**
//	** The dupedExprStructSize() function returns two values OR-ed together:
//	** (1) the space required for a copy of the Expr structure only and
//	** (2) the EP_xxx flags that indicate what the structure size should be.
//	** The return values is always one of:
//	**
//	**      EXPR_FULLSIZE
//	**      EXPR_REDUCEDSIZE   | EP_Reduced
//	**      EXPR_TOKENONLYSIZE | EP_TokenOnly
//	**
//	** The size of the structure can be found by masking the return value
//	** of this routine with 0xfff.  The flags can be found by masking the
//	** return value with EP_Reduced|EP_TokenOnly.
//	**
//	** Note that with flags==EXPRDUP_REDUCE, this routines works on full-size
//	** (unreduced) Expr objects as they or originally constructed by the parser.
//	** During expression analysis, extra information is computed and moved into
//	** later parts of the Expr object and that extra information might get chopped
//	** off if the expression is reduced.  Note also that it does not work to
//	** make an EXPRDUP_REDUCE copy of a reduced expression.  It is only legal
//	** to reduce a pristine expression tree from the parser.  The implementation
//	** of dupedExprStructSize() contain multiple assert() statements that attempt
//	** to enforce this constraint.
//	*/
func _dupedExprStructSize(tls *libc.TLS, p uintptr, flags int32) (r int32) {
	var nSize int32
	_ = nSize
	/* Only one flag value allowed */
	if 0 == flags || (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_FullSize)) != uint32(0) {
		nSize = int32(52)
	} else {
		if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 || *(*uintptr)(unsafe.Pointer(p + 20)) != 0 {
			nSize = int32(uint32(libc.UintptrFromInt32(0)+28) | libc.Uint32FromInt32(EP_Reduced))
		} else {
			nSize = int32(uint32(libc.UintptrFromInt32(0)+12) | libc.Uint32FromInt32(EP_TokenOnly))
		}
	}
	return nSize
}

// C documentation
//
//	/*
//	** This function returns the space in bytes required to store the copy
//	** of the Expr structure and a copy of the Expr.u.zToken string (if that
//	** string is defined.)
//	*/
func _dupedExprNodeSize(tls *libc.TLS, p uintptr, flags int32) (r int32) {
	var nByte int32
	_ = nByte
	nByte = _dupedExprStructSize(tls, p, flags) & int32(0xfff)
	if !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)) && *(*uintptr)(unsafe.Pointer(p + 8)) != 0 {
		nByte = int32(uint32(nByte) + (libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(p + 8)))&libc.Uint32FromInt32(0x3fffffff) + libc.Uint32FromInt32(1)))
	}
	return (nByte + int32(7)) & ^libc.Int32FromInt32(7)
}

// C documentation
//
//	/*
//	** Return the number of bytes required to create a duplicate of the
//	** expression passed as the first argument.
//	**
//	** The value returned includes space to create a copy of the Expr struct
//	** itself and the buffer referred to by Expr.u.zToken, if any.
//	**
//	** The return value includes space to duplicate all Expr nodes in the
//	** tree formed by Expr.pLeft and Expr.pRight, but not any other
//	** substructure such as Expr.x.pList, Expr.x.pSelect, and Expr.y.pWin.
//	*/
func _dupedExprSize(tls *libc.TLS, p uintptr) (r int32) {
	var nByte int32
	_ = nByte
	nByte = _dupedExprNodeSize(tls, p, int32(EXPRDUP_REDUCE))
	if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 {
		nByte += _dupedExprSize(tls, (*TExpr)(unsafe.Pointer(p)).FpLeft)
	}
	if (*TExpr)(unsafe.Pointer(p)).FpRight != 0 {
		nByte += _dupedExprSize(tls, (*TExpr)(unsafe.Pointer(p)).FpRight)
	}
	return nByte
}

// C documentation
//
//	/*
//	** An EdupBuf is a memory allocation used to stored multiple Expr objects
//	** together with their Expr.zToken content.  This is used to help implement
//	** compression while doing sqlite3ExprDup().  The top-level Expr does the
//	** allocation for itself and many of its decendents, then passes an instance
//	** of the structure down into exprDup() so that they decendents can have
//	** access to that memory.
//	*/
type TEdupBuf = struct {
	FzAlloc uintptr
}

type EdupBuf = TEdupBuf

type TEdupBuf1 = struct {
	FzAlloc uintptr
}

type EdupBuf1 = TEdupBuf1

// C documentation
//
//	/*
//	** This function is similar to sqlite3ExprDup(), except that if pEdupBuf
//	** is not NULL then it points to memory that can be used to store a copy
//	** of the input Expr p together with its p->u.zToken (if any).  pEdupBuf
//	** is updated with the new buffer tail prior to returning.
//	*/
func _exprDup(tls *libc.TLS, db uintptr, p uintptr, dupFlags int32, pEdupBuf uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nAlloc, nNewSize, nToken, v2 int32
	var nSize, staticFlag Tu32
	var nStructSize uint32
	var pNew, zToken, v1, v3, v4 uintptr
	var _ /* sEdupBuf at bp+0 */ TEdupBuf
	_, _, _, _, _, _, _, _, _, _, _, _ = nAlloc, nNewSize, nSize, nStructSize, nToken, pNew, staticFlag, zToken, v1, v2, v3, v4 /* EP_Static if space not obtained from malloc */
	nToken = -int32(1)                                                                                                          /* Space needed for p->u.zToken.  -1 means unknown */
	/* Figure out where to write the new Expr structure. */
	if pEdupBuf != 0 {
		(*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc = (*TEdupBuf)(unsafe.Pointer(pEdupBuf)).FzAlloc
		staticFlag = uint32(EP_Static)
	} else {
		if dupFlags != 0 {
			nAlloc = _dupedExprSize(tls, p)
		} else {
			if !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)) && *(*uintptr)(unsafe.Pointer(p + 8)) != 0 {
				nToken = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(p + 8)))&uint32(0x3fffffff) + uint32(1))
				nAlloc = int32((libc.Uint32FromInt64(52) + uint32(uint32(nToken)) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
			} else {
				nToken = 0
				nAlloc = int32((libc.Uint32FromInt64(52) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
			}
		}
		(*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(nAlloc)))
		staticFlag = uint32(0)
	}
	pNew = (*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc
	if pNew != 0 {
		/* Set nNewSize to the size allocated for the structure pointed to
		 ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
		 ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
		 ** by the copy of the p->u.zToken string (if any).
		 */
		nStructSize = uint32(_dupedExprStructSize(tls, p, dupFlags))
		nNewSize = int32(nStructSize & uint32(0xfff))
		if nToken < 0 {
			if !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)) && *(*uintptr)(unsafe.Pointer(p + 8)) != 0 {
				nToken = _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(p + 8))) + int32(1)
			} else {
				nToken = 0
			}
		}
		if dupFlags != 0 {
			libc.Xmemcpy(tls, (*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc, p, uint32(uint32(nNewSize)))
		} else {
			nSize = uint32(_exprStructSize(tls, p))
			libc.Xmemcpy(tls, (*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc, p, nSize)
			if nSize < uint32(52) {
				libc.Xmemset(tls, (*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc+uintptr(nSize), 0, uint32(52)-nSize)
			}
			nNewSize = int32(52)
		}
		/* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
		*(*Tu32)(unsafe.Pointer(pNew + 4)) &= uint32(^(libc.Int32FromInt32(EP_Reduced) | libc.Int32FromInt32(EP_TokenOnly) | libc.Int32FromInt32(EP_Static)))
		*(*Tu32)(unsafe.Pointer(pNew + 4)) |= nStructSize & uint32(libc.Int32FromInt32(EP_Reduced)|libc.Int32FromInt32(EP_TokenOnly))
		*(*Tu32)(unsafe.Pointer(pNew + 4)) |= staticFlag
		if dupFlags != 0 {
		}
		/* Copy the p->u.zToken string, if any. */
		if nToken > 0 {
			v1 = (*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc + uintptr(nNewSize)
			*(*uintptr)(unsafe.Pointer(pNew + 8)) = v1
			zToken = v1
			libc.Xmemcpy(tls, zToken, *(*uintptr)(unsafe.Pointer(p + 8)), uint32(uint32(nToken)))
			nNewSize += nToken
		}
		(*(*TEdupBuf)(unsafe.Pointer(bp))).FzAlloc += uintptr((nNewSize + libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))
		if ((*TExpr)(unsafe.Pointer(p)).Fflags|(*TExpr)(unsafe.Pointer(pNew)).Fflags)&uint32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Leaf)) == uint32(0) {
			/* Fill in the pNew->x.pSelect or pNew->x.pList member. */
			if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
				*(*uintptr)(unsafe.Pointer(pNew + 20)) = _sqlite3SelectDup(tls, db, *(*uintptr)(unsafe.Pointer(p + 20)), dupFlags)
			} else {
				if int32((*TExpr)(unsafe.Pointer(p)).Fop) != int32(TK_ORDER) {
					v2 = dupFlags
				} else {
					v2 = 0
				}
				*(*uintptr)(unsafe.Pointer(pNew + 20)) = _sqlite3ExprListDup(tls, db, *(*uintptr)(unsafe.Pointer(p + 20)), v2)
			}
			if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
				*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pNew)).Fy)) = _sqlite3WindowDup(tls, db, pNew, *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(p)).Fy)))
			}
			/* Fill in pNew->pLeft and pNew->pRight. */
			if dupFlags != 0 {
				if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_SELECT_COLUMN) {
					(*TExpr)(unsafe.Pointer(pNew)).FpLeft = (*TExpr)(unsafe.Pointer(p)).FpLeft
				} else {
					if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 {
						v3 = _exprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpLeft, int32(EXPRDUP_REDUCE), bp)
					} else {
						v3 = uintptr(0)
					}
					(*TExpr)(unsafe.Pointer(pNew)).FpLeft = v3
				}
				if (*TExpr)(unsafe.Pointer(p)).FpRight != 0 {
					v4 = _exprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpRight, int32(EXPRDUP_REDUCE), bp)
				} else {
					v4 = uintptr(0)
				}
				(*TExpr)(unsafe.Pointer(pNew)).FpRight = v4
			} else {
				if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_SELECT_COLUMN) {
					(*TExpr)(unsafe.Pointer(pNew)).FpLeft = (*TExpr)(unsafe.Pointer(p)).FpLeft
				} else {
					(*TExpr)(unsafe.Pointer(pNew)).FpLeft = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpLeft, 0)
				}
				(*TExpr)(unsafe.Pointer(pNew)).FpRight = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpRight, 0)
			}
		}
	}
	if pEdupBuf != 0 {
		libc.Xmemcpy(tls, pEdupBuf, bp, uint32(4))
	}
	return pNew
}

// C documentation
//
//	/*
//	** Create and return a deep copy of the object passed as the second
//	** argument. If an OOM condition is encountered, NULL is returned
//	** and the db->mallocFailed flag set.
//	*/
func _sqlite3WithDup(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	var i int32
	var nByte Tsqlite3_int64
	var pRet uintptr
	_, _, _ = i, nByte, pRet
	pRet = uintptr(0)
	if p != 0 {
		nByte = int64(uint32(36) + uint32(24)*uint32((*TWith)(unsafe.Pointer(p)).FnCte-libc.Int32FromInt32(1)))
		pRet = _sqlite3DbMallocZero(tls, db, uint64(uint64(nByte)))
		if pRet != 0 {
			(*TWith)(unsafe.Pointer(pRet)).FnCte = (*TWith)(unsafe.Pointer(p)).FnCte
			i = 0
			for {
				if !(i < (*TWith)(unsafe.Pointer(p)).FnCte) {
					break
				}
				(*(*TCte)(unsafe.Pointer(pRet + 12 + uintptr(i)*24))).FpSelect = _sqlite3SelectDup(tls, db, (*(*TCte)(unsafe.Pointer(p + 12 + uintptr(i)*24))).FpSelect, 0)
				(*(*TCte)(unsafe.Pointer(pRet + 12 + uintptr(i)*24))).FpCols = _sqlite3ExprListDup(tls, db, (*(*TCte)(unsafe.Pointer(p + 12 + uintptr(i)*24))).FpCols, 0)
				(*(*TCte)(unsafe.Pointer(pRet + 12 + uintptr(i)*24))).FzName = _sqlite3DbStrDup(tls, db, (*(*TCte)(unsafe.Pointer(p + 12 + uintptr(i)*24))).FzName)
				(*(*TCte)(unsafe.Pointer(pRet + 12 + uintptr(i)*24))).FeM10d = (*(*TCte)(unsafe.Pointer(p + 12 + uintptr(i)*24))).FeM10d
				goto _1
			_1:
				;
				i++
			}
		}
	}
	return pRet
}

// C documentation
//
//	/*
//	** The gatherSelectWindows() procedure and its helper routine
//	** gatherSelectWindowsCallback() are used to scan all the expressions
//	** an a newly duplicated SELECT statement and gather all of the Window
//	** objects found there, assembling them onto the linked list at Select->pWin.
//	*/
func _gatherSelectWindowsCallback(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var pSelect, pWin uintptr
	_, _ = pSelect, pWin
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_FUNCTION) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		pSelect = *(*uintptr)(unsafe.Pointer(pWalker + 24))
		pWin = *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy))
		_sqlite3WindowLink(tls, pSelect, pWin)
	}
	return WRC_Continue
}

func _gatherSelectWindowsSelectCallback(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var v1 int32
	_ = v1
	if p == *(*uintptr)(unsafe.Pointer(pWalker + 24)) {
		v1 = WRC_Continue
	} else {
		v1 = int32(WRC_Prune)
	}
	return v1
}

func _gatherSelectWindows(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_gatherSelectWindowsCallback)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_gatherSelectWindowsSelectCallback)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = uintptr(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = p
	_sqlite3WalkSelect(tls, bp, p)
}

// C documentation
//
//	/*
//	** The following group of routines make deep copies of expressions,
//	** expression lists, ID lists, and select statements.  The copies can
//	** be deleted (by being passed to their respective ...Delete() routines)
//	** without effecting the originals.
//	**
//	** The expression list, ID, and source lists return by sqlite3ExprListDup(),
//	** sqlite3IdListDup(), and sqlite3SrcListDup() can not be further expanded
//	** by subsequent calls to sqlite*ListAppend() routines.
//	**
//	** Any tables that the SrcList might point to are not duplicated.
//	**
//	** The flags parameter contains a combination of the EXPRDUP_XXX flags.
//	** If the EXPRDUP_REDUCE flag is set, then the structure returned is a
//	** truncated version of the usual Expr structure that will be stored as
//	** part of the in-memory representation of the database schema.
//	*/
func _sqlite3ExprDup(tls *libc.TLS, db uintptr, p uintptr, flags int32) (r uintptr) {
	var v1 uintptr
	_ = v1
	if p != 0 {
		v1 = _exprDup(tls, db, p, flags, uintptr(0))
	} else {
		v1 = uintptr(0)
	}
	return v1
}

func _sqlite3ExprListDup(tls *libc.TLS, db uintptr, p uintptr, flags int32) (r uintptr) {
	var i int32
	var pItem, pNew, pNewExpr, pOldExpr, pOldItem, pPriorSelectColNew, pPriorSelectColOld, v2 uintptr
	var v3 bool
	_, _, _, _, _, _, _, _, _, _ = i, pItem, pNew, pNewExpr, pOldExpr, pOldItem, pPriorSelectColNew, pPriorSelectColOld, v2, v3
	pPriorSelectColOld = uintptr(0)
	pPriorSelectColNew = uintptr(0)
	if p == uintptr(0) {
		return uintptr(0)
	}
	pNew = _sqlite3DbMallocRawNN(tls, db, uint64(_sqlite3DbMallocSize(tls, db, p)))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	(*TExprList)(unsafe.Pointer(pNew)).FnExpr = (*TExprList)(unsafe.Pointer(p)).FnExpr
	(*TExprList)(unsafe.Pointer(pNew)).FnAlloc = (*TExprList)(unsafe.Pointer(p)).FnAlloc
	pItem = pNew + 8
	pOldItem = p + 8
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(p)).FnExpr) {
			break
		}
		pOldExpr = (*TExprList_item)(unsafe.Pointer(pOldItem)).FpExpr
		(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = _sqlite3ExprDup(tls, db, pOldExpr, flags)
		if v3 = pOldExpr != 0 && int32((*TExpr)(unsafe.Pointer(pOldExpr)).Fop) == int32(TK_SELECT_COLUMN); v3 {
			v2 = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
			pNewExpr = v2
		}
		if v3 && v2 != uintptr(0) {
			if (*TExpr)(unsafe.Pointer(pNewExpr)).FpRight != 0 {
				pPriorSelectColOld = (*TExpr)(unsafe.Pointer(pOldExpr)).FpRight
				pPriorSelectColNew = (*TExpr)(unsafe.Pointer(pNewExpr)).FpRight
				(*TExpr)(unsafe.Pointer(pNewExpr)).FpLeft = (*TExpr)(unsafe.Pointer(pNewExpr)).FpRight
			} else {
				if (*TExpr)(unsafe.Pointer(pOldExpr)).FpLeft != pPriorSelectColOld {
					pPriorSelectColOld = (*TExpr)(unsafe.Pointer(pOldExpr)).FpLeft
					pPriorSelectColNew = _sqlite3ExprDup(tls, db, pPriorSelectColOld, flags)
					(*TExpr)(unsafe.Pointer(pNewExpr)).FpRight = pPriorSelectColNew
				}
				(*TExpr)(unsafe.Pointer(pNewExpr)).FpLeft = pPriorSelectColNew
			}
		}
		(*TExprList_item)(unsafe.Pointer(pItem)).FzEName = _sqlite3DbStrDup(tls, db, (*TExprList_item)(unsafe.Pointer(pOldItem)).FzEName)
		(*TExprList_item)(unsafe.Pointer(pItem)).Ffg = (*TExprList_item)(unsafe.Pointer(pOldItem)).Ffg
		libc.SetBitFieldPtr16Uint32(pItem+8+4, libc.Uint32FromInt32(0), 2, 0x4)
		(*TExprList_item)(unsafe.Pointer(pItem)).Fu = (*TExprList_item)(unsafe.Pointer(pOldItem)).Fu
		goto _1
	_1:
		;
		i++
		pItem += 20
		pOldItem += 20
	}
	return pNew
}

// 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, nByte int32
	var pNew, pNewItem, pOldItem, pTab, v4 uintptr
	var v1 uint32
	var v2 Tu32
	_, _, _, _, _, _, _, _, _ = i, nByte, pNew, pNewItem, pOldItem, pTab, v1, v2, v4
	if p == uintptr(0) {
		return uintptr(0)
	}
	if (*TSrcList)(unsafe.Pointer(p)).FnSrc > 0 {
		v1 = uint32(72) * uint32((*TSrcList)(unsafe.Pointer(p)).FnSrc-libc.Int32FromInt32(1))
	} else {
		v1 = uint32(0)
	}
	nByte = int32(uint32(80) + v1)
	pNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(nByte)))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	v2 = uint32((*TSrcList)(unsafe.Pointer(p)).FnSrc)
	(*TSrcList)(unsafe.Pointer(pNew)).FnAlloc = v2
	(*TSrcList)(unsafe.Pointer(pNew)).FnSrc = int32(v2)
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(p)).FnSrc) {
			break
		}
		pNewItem = pNew + 8 + uintptr(i)*72
		pOldItem = p + 8 + uintptr(i)*72
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FpSchema = (*TSrcItem)(unsafe.Pointer(pOldItem)).FpSchema
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FzDatabase = _sqlite3DbStrDup(tls, db, (*TSrcItem)(unsafe.Pointer(pOldItem)).FzDatabase)
		(*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)).Ffg = (*TSrcItem)(unsafe.Pointer(pOldItem)).Ffg
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FiCursor = (*TSrcItem)(unsafe.Pointer(pOldItem)).FiCursor
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FaddrFillSub = (*TSrcItem)(unsafe.Pointer(pOldItem)).FaddrFillSub
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FregReturn = (*TSrcItem)(unsafe.Pointer(pOldItem)).FregReturn
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FregResult = (*TSrcItem)(unsafe.Pointer(pOldItem)).FregResult
		if int32(uint32(*(*uint16)(unsafe.Pointer(pNewItem + 36 + 4))&0x2>>1)) != 0 {
			*(*uintptr)(unsafe.Pointer(pNewItem + 64)) = _sqlite3DbStrDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 64)))
		} else {
			if int32(uint32(*(*uint16)(unsafe.Pointer(pNewItem + 36 + 4))&0x4>>2)) != 0 {
				*(*uintptr)(unsafe.Pointer(pNewItem + 64)) = _sqlite3ExprListDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 64)), flags)
			} else {
				*(*Tu32)(unsafe.Pointer(pNewItem + 64)) = *(*Tu32)(unsafe.Pointer(pOldItem + 64))
			}
		}
		(*TSrcItem)(unsafe.Pointer(pNewItem)).Fu2 = (*TSrcItem)(unsafe.Pointer(pOldItem)).Fu2
		if int32(uint32(*(*uint16)(unsafe.Pointer(pNewItem + 36 + 4))&0x100>>8)) != 0 {
			(*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNewItem + 68)))).FnUse++
		}
		v4 = (*TSrcItem)(unsafe.Pointer(pOldItem)).FpTab
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FpTab = v4
		pTab = v4
		if pTab != 0 {
			(*TTable)(unsafe.Pointer(pTab)).FnTabRef++
		}
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FpSelect = _sqlite3SelectDup(tls, db, (*TSrcItem)(unsafe.Pointer(pOldItem)).FpSelect, flags)
		if int32(uint32(*(*uint16)(unsafe.Pointer(pOldItem + 36 + 4))&0x400>>10)) != 0 {
			*(*uintptr)(unsafe.Pointer(pNewItem + 48)) = _sqlite3IdListDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 48)))
		} else {
			*(*uintptr)(unsafe.Pointer(pNewItem + 48)) = _sqlite3ExprDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 48)), flags)
		}
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FcolUsed = (*TSrcItem)(unsafe.Pointer(pOldItem)).FcolUsed
		goto _3
	_3:
		;
		i++
	}
	return pNew
}

func _sqlite3IdListDup(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	var i int32
	var pNew, pNewItem, pOldItem uintptr
	_, _, _, _ = i, pNew, pNewItem, pOldItem
	if p == uintptr(0) {
		return uintptr(0)
	}
	pNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(16)+uint32((*TIdList)(unsafe.Pointer(p)).FnId-libc.Int32FromInt32(1))*uint32(8)))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	(*TIdList)(unsafe.Pointer(pNew)).FnId = (*TIdList)(unsafe.Pointer(p)).FnId
	(*TIdList)(unsafe.Pointer(pNew)).FeU4 = (*TIdList)(unsafe.Pointer(p)).FeU4
	i = 0
	for {
		if !(i < (*TIdList)(unsafe.Pointer(p)).FnId) {
			break
		}
		pNewItem = pNew + 8 + uintptr(i)*8
		pOldItem = p + 8 + uintptr(i)*8
		(*TIdList_item)(unsafe.Pointer(pNewItem)).FzName = _sqlite3DbStrDup(tls, db, (*TIdList_item)(unsafe.Pointer(pOldItem)).FzName)
		(*TIdList_item)(unsafe.Pointer(pNewItem)).Fu4 = (*TIdList_item)(unsafe.Pointer(pOldItem)).Fu4
		goto _1
	_1:
		;
		i++
	}
	return pNew
}

func _sqlite3SelectDup(tls *libc.TLS, db uintptr, pDup uintptr, flags int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p, pNew, pNext, pp uintptr
	var _ /* pRet at bp+0 */ uintptr
	_, _, _, _ = p, pNew, pNext, pp
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pNext = uintptr(0)
	pp = bp
	p = pDup
	for {
		if !(p != 0) {
			break
		}
		pNew = _sqlite3DbMallocRawNN(tls, db, uint64(76))
		if pNew == uintptr(0) {
			break
		}
		(*TSelect)(unsafe.Pointer(pNew)).FpEList = _sqlite3ExprListDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpEList, flags)
		(*TSelect)(unsafe.Pointer(pNew)).FpSrc = _sqlite3SrcListDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpSrc, flags)
		(*TSelect)(unsafe.Pointer(pNew)).FpWhere = _sqlite3ExprDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpWhere, flags)
		(*TSelect)(unsafe.Pointer(pNew)).FpGroupBy = _sqlite3ExprListDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpGroupBy, flags)
		(*TSelect)(unsafe.Pointer(pNew)).FpHaving = _sqlite3ExprDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpHaving, flags)
		(*TSelect)(unsafe.Pointer(pNew)).FpOrderBy = _sqlite3ExprListDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, flags)
		(*TSelect)(unsafe.Pointer(pNew)).Fop = (*TSelect)(unsafe.Pointer(p)).Fop
		(*TSelect)(unsafe.Pointer(pNew)).FpNext = pNext
		(*TSelect)(unsafe.Pointer(pNew)).FpPrior = uintptr(0)
		(*TSelect)(unsafe.Pointer(pNew)).FpLimit = _sqlite3ExprDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit, flags)
		(*TSelect)(unsafe.Pointer(pNew)).FiLimit = 0
		(*TSelect)(unsafe.Pointer(pNew)).FiOffset = 0
		(*TSelect)(unsafe.Pointer(pNew)).FselFlags = (*TSelect)(unsafe.Pointer(p)).FselFlags & uint32(^libc.Int32FromInt32(SF_UsesEphemeral))
		*(*int32)(unsafe.Pointer(pNew + 20)) = -int32(1)
		*(*int32)(unsafe.Pointer(pNew + 20 + 1*4)) = -int32(1)
		(*TSelect)(unsafe.Pointer(pNew)).FnSelectRow = (*TSelect)(unsafe.Pointer(p)).FnSelectRow
		(*TSelect)(unsafe.Pointer(pNew)).FpWith = _sqlite3WithDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpWith)
		(*TSelect)(unsafe.Pointer(pNew)).FpWin = uintptr(0)
		(*TSelect)(unsafe.Pointer(pNew)).FpWinDefn = _sqlite3WindowListDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpWinDefn)
		if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 && int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
			_gatherSelectWindows(tls, pNew)
		}
		(*TSelect)(unsafe.Pointer(pNew)).FselId = (*TSelect)(unsafe.Pointer(p)).FselId
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			/* Any prior OOM might have left the Select object incomplete.
			 ** Delete the whole thing rather than allow an incomplete Select
			 ** to be used by the code generator. */
			(*TSelect)(unsafe.Pointer(pNew)).FpNext = uintptr(0)
			_sqlite3SelectDelete(tls, db, pNew)
			break
		}
		*(*uintptr)(unsafe.Pointer(pp)) = pNew
		pp = pNew + 52
		pNext = pNew
		goto _1
	_1:
		;
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
	}
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Add a new element to the end of an expression list.  If pList is
//	** initially NULL, then create a new expression list.
//	**
//	** The pList argument must be either NULL or a pointer to an ExprList
//	** obtained from a prior call to sqlite3ExprListAppend().
//	**
//	** If a memory allocation error occurs, the entire list is freed and
//	** NULL is returned.  If non-NULL is returned, then it is guaranteed
//	** that the new entry was successfully appended.
//	*/
type TExprList_item = struct {
	FpExpr  uintptr
	FzEName uintptr
	Ffg     struct {
		F__ccgo_align  [0]uint32
		FsortFlags     Tu8
		F__ccgo_align1 [2]byte
		F__ccgo4       uint16
	}
	Fu struct {
		FiConstExprReg [0]int32
		Fx             struct {
			FiOrderByCol Tu16
			FiAlias      Tu16
		}
	}
}

type ExprList_item = TExprList_item

// C documentation
//
//	/*
//	** Add a new element to the end of an expression list.  If pList is
//	** initially NULL, then create a new expression list.
//	**
//	** The pList argument must be either NULL or a pointer to an ExprList
//	** obtained from a prior call to sqlite3ExprListAppend().
//	**
//	** If a memory allocation error occurs, the entire list is freed and
//	** NULL is returned.  If non-NULL is returned, then it is guaranteed
//	** that the new entry was successfully appended.
//	*/
var _zeroItem = TExprList_item{}

func _sqlite3ExprListAppendNew(tls *libc.TLS, db uintptr, pExpr uintptr) (r uintptr) {
	var pItem, pList uintptr
	_, _ = pItem, pList
	pList = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint32FromInt64(28)+libc.Uint32FromInt64(20)*libc.Uint32FromInt32(4)))
	if pList == uintptr(0) {
		_sqlite3ExprDelete(tls, db, pExpr)
		return uintptr(0)
	}
	(*TExprList)(unsafe.Pointer(pList)).FnAlloc = int32(4)
	(*TExprList)(unsafe.Pointer(pList)).FnExpr = int32(1)
	pItem = pList + 8
	*(*TExprList_item)(unsafe.Pointer(pItem)) = _zeroItem
	(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pExpr
	return pList
}

func _sqlite3ExprListAppendGrow(tls *libc.TLS, db uintptr, pList uintptr, pExpr uintptr) (r uintptr) {
	var pItem, pNew, v2 uintptr
	var v1 int32
	_, _, _, _ = pItem, pNew, v1, v2
	*(*int32)(unsafe.Pointer(pList + 4)) *= int32(2)
	pNew = _sqlite3DbRealloc(tls, db, pList, uint64(uint32(28)+uint32((*TExprList)(unsafe.Pointer(pList)).FnAlloc-libc.Int32FromInt32(1))*uint32(20)))
	if pNew == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pList)
		_sqlite3ExprDelete(tls, db, pExpr)
		return uintptr(0)
	} else {
		pList = pNew
	}
	v2 = pList
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	pItem = pList + 8 + uintptr(v1)*20
	*(*TExprList_item)(unsafe.Pointer(pItem)) = _zeroItem
	(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pExpr
	return pList
}

func _sqlite3ExprListAppend(tls *libc.TLS, pParse uintptr, pList uintptr, pExpr uintptr) (r uintptr) {
	var pItem, v2 uintptr
	var v1 int32
	_, _, _ = pItem, v1, v2
	if pList == uintptr(0) {
		return _sqlite3ExprListAppendNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
	}
	if (*TExprList)(unsafe.Pointer(pList)).FnAlloc < (*TExprList)(unsafe.Pointer(pList)).FnExpr+int32(1) {
		return _sqlite3ExprListAppendGrow(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList, pExpr)
	}
	v2 = pList
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	pItem = pList + 8 + uintptr(v1)*20
	*(*TExprList_item)(unsafe.Pointer(pItem)) = _zeroItem
	(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pExpr
	return pList
}

// C documentation
//
//	/*
//	** pColumns and pExpr form a vector assignment which is part of the SET
//	** clause of an UPDATE statement.  Like this:
//	**
//	**        (a,b,c) = (expr1,expr2,expr3)
//	** Or:    (a,b,c) = (SELECT x,y,z FROM ....)
//	**
//	** For each term of the vector assignment, append new entries to the
//	** expression list pList.  In the case of a subquery on the RHS, append
//	** TK_SELECT_COLUMN expressions.
//	*/
func _sqlite3ExprListAppendVector(tls *libc.TLS, pParse uintptr, pList uintptr, pColumns uintptr, pExpr uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pFirst, pSubExpr uintptr
	var i, iFirst, n, v1, v2 int32
	var v3 bool
	_, _, _, _, _, _, _, _, _ = db, i, iFirst, n, pFirst, pSubExpr, v1, v2, v3
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pList != 0 {
		v1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	} else {
		v1 = 0
	}
	iFirst = v1
	/* pColumns can only be NULL due to an OOM but an OOM will cause an
	 ** exit prior to this routine being invoked */
	if pColumns == uintptr(0) {
		goto vector_append_error
	}
	if pExpr == uintptr(0) {
		goto vector_append_error
	}
	/* If the RHS is a vector, then we can immediately check to see that
	 ** the size of the RHS and LHS match.  But if the RHS is a SELECT,
	 ** wildcards ("*") in the result set of the SELECT must be expanded before
	 ** we can do the size check, so defer the size check until code generation.
	 */
	if v3 = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_SELECT); v3 {
		v2 = _sqlite3ExprVectorSize(tls, pExpr)
		n = v2
	}
	if v3 && (*TIdList)(unsafe.Pointer(pColumns)).FnId != v2 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9267, libc.VaList(bp+8, (*TIdList)(unsafe.Pointer(pColumns)).FnId, n))
		goto vector_append_error
	}
	i = 0
	for {
		if !(i < (*TIdList)(unsafe.Pointer(pColumns)).FnId) {
			break
		}
		pSubExpr = _sqlite3ExprForVectorField(tls, pParse, pExpr, i, (*TIdList)(unsafe.Pointer(pColumns)).FnId)
		if pSubExpr == uintptr(0) {
			goto _4
		}
		pList = _sqlite3ExprListAppend(tls, pParse, pList, pSubExpr)
		if pList != 0 {
			(*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr((*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1))*20))).FzEName = (*(*TIdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*8))).FzName
			(*(*TIdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*8))).FzName = uintptr(0)
		}
		goto _4
	_4:
		;
		i++
	}
	if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) && pList != uintptr(0) {
		pFirst = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(iFirst)*20))).FpExpr
		/* Store the SELECT statement in pRight so it will be deleted when
		 ** sqlite3ExprListDelete() is called */
		(*TExpr)(unsafe.Pointer(pFirst)).FpRight = pExpr
		pExpr = uintptr(0)
		/* Remember the size of the LHS in iTable so that we can check that
		 ** the RHS and LHS sizes match during code generation. */
		(*TExpr)(unsafe.Pointer(pFirst)).FiTable = (*TIdList)(unsafe.Pointer(pColumns)).FnId
	}
	goto vector_append_error
vector_append_error:
	;
	_sqlite3ExprUnmapAndDelete(tls, pParse, pExpr)
	_sqlite3IdListDelete(tls, db, pColumns)
	return pList
}

// 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, p1 uintptr
	_, _ = pItem, p1
	if p == uintptr(0) {
		return
	}
	pItem = p + 8 + uintptr((*TExprList)(unsafe.Pointer(p)).FnExpr-int32(1))*20
	if iSortOrder == -int32(1) {
		iSortOrder = SQLITE_SO_ASC
	}
	(*TExprList_item)(unsafe.Pointer(pItem)).Ffg.FsortFlags = uint8(uint8(iSortOrder))
	if eNulls != -int32(1) {
		libc.SetBitFieldPtr16Uint32(pItem+8+4, libc.Uint32FromInt32(1), 5, 0x20)
		if iSortOrder != eNulls {
			p1 = pItem + 8
			*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(KEYINFO_ORDER_BIGNULL))
		}
	}
}

// C documentation
//
//	/*
//	** Set the ExprList.a[].zEName element of the most recently added item
//	** on the expression list.
//	**
//	** pList might be NULL following an OOM error.  But pName should never be
//	** NULL.  If a memory allocation fails, the pParse->db->mallocFailed flag
//	** is set.
//	*/
func _sqlite3ExprListSetName(tls *libc.TLS, pParse uintptr, pList uintptr, pName uintptr, dequote int32) {
	var pItem uintptr
	_ = pItem
	if pList != 0 {
		pItem = pList + 8 + uintptr((*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1))*20
		(*TExprList_item)(unsafe.Pointer(pItem)).FzEName = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TToken)(unsafe.Pointer(pName)).Fz, uint64((*TToken)(unsafe.Pointer(pName)).Fn))
		if dequote != 0 {
			/* If dequote==0, then pName->z does not point to part of a DDL
			 ** statement handled by the parser. And so no token need be added
			 ** to the token-map.  */
			_sqlite3Dequote(tls, (*TExprList_item)(unsafe.Pointer(pItem)).FzEName)
			if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
				_sqlite3RenameTokenMap(tls, pParse, (*TExprList_item)(unsafe.Pointer(pItem)).FzEName, pName)
			}
		}
	}
}

// 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))*20
		if (*TExprList_item)(unsafe.Pointer(pItem)).FzEName == uintptr(0) {
			(*TExprList_item)(unsafe.Pointer(pItem)).FzEName = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
			libc.SetBitFieldPtr16Uint32(pItem+8+4, libc.Uint32FromInt32(ENAME_SPAN), 0, 0x3)
		}
	}
}

// C documentation
//
//	/*
//	** If the expression list pEList contains more than iLimit elements,
//	** leave an error message in pParse.
//	*/
func _sqlite3ExprListCheckLength(tls *libc.TLS, pParse uintptr, pEList uintptr, zObject uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var mx int32
	_ = mx
	mx = *(*int32)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb + 120 + 2*4))
	if pEList != 0 && (*TExprList)(unsafe.Pointer(pEList)).FnExpr > mx {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9297, libc.VaList(bp+8, zObject))
	}
}

// C documentation
//
//	/*
//	** Delete an entire expression list.
//	*/
func _exprListDeleteNN(tls *libc.TLS, db uintptr, pList uintptr) {
	var i, v1 int32
	var pItem uintptr
	_, _, _ = i, pItem, v1
	i = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	pItem = pList + 8
	for {
		_sqlite3ExprDelete(tls, db, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
		if (*TExprList_item)(unsafe.Pointer(pItem)).FzEName != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TExprList_item)(unsafe.Pointer(pItem)).FzEName)
		}
		pItem += 20
		goto _2
	_2:
		;
		i--
		v1 = i
		if !(v1 > 0) {
			break
		}
	}
	_sqlite3DbNNFreeNN(tls, db, pList)
}

func _sqlite3ExprListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	if pList != 0 {
		_exprListDeleteNN(tls, db, pList)
	}
}

func _sqlite3ExprListDeleteGeneric(tls *libc.TLS, db uintptr, pList uintptr) {
	if pList != 0 {
		_exprListDeleteNN(tls, db, pList)
	}
}

// C documentation
//
//	/*
//	** Return the bitwise-OR of all Expr.flags fields in the given
//	** ExprList.
//	*/
func _sqlite3ExprListFlags(tls *libc.TLS, pList uintptr) (r Tu32) {
	var i int32
	var m Tu32
	var pExpr uintptr
	_, _, _ = i, m, pExpr
	m = uint32(0)
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		pExpr = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr
		m |= (*TExpr)(unsafe.Pointer(pExpr)).Fflags
		goto _1
	_1:
		;
		i++
	}
	return m
}

// C documentation
//
//	/*
//	** This is a SELECT-node callback for the expression walker that
//	** always "fails".  By "fail" in this case, we mean set
//	** pWalker->eCode to zero and abort.
//	**
//	** This callback is used by multiple expression walkers.
//	*/
func _sqlite3SelectWalkFail(tls *libc.TLS, pWalker uintptr, NotUsed uintptr) (r int32) {
	_ = NotUsed
	(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
	return int32(WRC_Abort)
}

// C documentation
//
//	/*
//	** Check the input string to see if it is "true" or "false" (in any case).
//	**
//	**       If the string is....           Return
//	**         "true"                         EP_IsTrue
//	**         "false"                        EP_IsFalse
//	**         anything else                  0
//	*/
func _sqlite3IsTrueOrFalse(tls *libc.TLS, zIn uintptr) (r Tu32) {
	if _sqlite3StrICmp(tls, zIn, __ccgo_ts+9320) == 0 {
		return uint32(EP_IsTrue)
	}
	if _sqlite3StrICmp(tls, zIn, __ccgo_ts+9325) == 0 {
		return uint32(EP_IsFalse)
	}
	return uint32(0)
}

// C documentation
//
//	/*
//	** If the input expression is an ID with the name "true" or "false"
//	** then convert it into an TK_TRUEFALSE term.  Return non-zero if
//	** the conversion happened, and zero if the expression is unaltered.
//	*/
func _sqlite3ExprIdToTrueFalse(tls *libc.TLS, pExpr uintptr) (r int32) {
	var v, v1 Tu32
	var v2 bool
	_, _, _ = v, v1, v2
	if v2 = !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Quoted)|libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)); v2 {
		v1 = _sqlite3IsTrueOrFalse(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
		v = v1
	}
	if v2 && v1 != uint32(0) {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_TRUEFALSE)
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= v
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** The argument must be a TK_TRUEFALSE Expr node.  Return 1 if it is TRUE
//	** and 0 if it is FALSE.
//	*/
func _sqlite3ExprTruthValue(tls *libc.TLS, pExpr uintptr) (r int32) {
	pExpr = _sqlite3ExprSkipCollateAndLikely(tls, pExpr)
	return libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 8)) + 4))) == 0)
}

// C documentation
//
//	/*
//	** If pExpr is an AND or OR expression, try to simplify it by eliminating
//	** terms that are always true or false.  Return the simplified expression.
//	** Or return the original expression if no simplification is possible.
//	**
//	** Examples:
//	**
//	**     (x<10) AND true                =>   (x<10)
//	**     (x<10) AND false               =>   false
//	**     (x<10) AND (y=22 OR false)     =>   (x<10) AND (y=22)
//	**     (x<10) AND (y=22 OR true)      =>   (x<10)
//	**     (y=22) OR true                 =>   true
//	*/
func _sqlite3ExprSimplifiedAndOr(tls *libc.TLS, pExpr uintptr) (r uintptr) {
	var pLeft, pRight, v1, v2 uintptr
	_, _, _, _ = pLeft, pRight, v1, v2
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AND) || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_OR) {
		pRight = _sqlite3ExprSimplifiedAndOr(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		pLeft = _sqlite3ExprSimplifiedAndOr(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		if (*TExpr)(unsafe.Pointer(pLeft)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsTrue)) == uint32(EP_IsTrue) || (*TExpr)(unsafe.Pointer(pRight)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsFalse)) == uint32(EP_IsFalse) {
			if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AND) {
				v1 = pRight
			} else {
				v1 = pLeft
			}
			pExpr = v1
		} else {
			if (*TExpr)(unsafe.Pointer(pRight)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsTrue)) == uint32(EP_IsTrue) || (*TExpr)(unsafe.Pointer(pLeft)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsFalse)) == uint32(EP_IsFalse) {
				if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AND) {
					v2 = pLeft
				} else {
					v2 = pRight
				}
				pExpr = v2
			}
		}
	}
	return pExpr
}

// C documentation
//
//	/*
//	** pExpr is a TK_FUNCTION node.  Try to determine whether or not the
//	** function is a constant function.  A function is constant if all of
//	** the following are true:
//	**
//	**    (1)  It is a scalar function (not an aggregate or window function)
//	**    (2)  It has either the SQLITE_FUNC_CONSTANT or SQLITE_FUNC_SLOCHNG
//	**         property.
//	**    (3)  All of its arguments are constants
//	**
//	** This routine sets pWalker->eCode to 0 if pExpr is not a constant.
//	** It makes no changes to pWalker->eCode if pExpr is constant.  In
//	** every case, it returns WRC_Abort.
//	**
//	** Called as a service subroutine from exprNodeIsConstant().
//	*/
func _exprNodeIsConstantFunction(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var db, pDef, pList, v1 uintptr
	var n int32
	var v2 bool
	_, _, _, _, _, _ = db, n, pDef, pList, v1, v2 /* The database */
	if v2 = (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_TokenOnly)) != uint32(0); !v2 {
		v1 = *(*uintptr)(unsafe.Pointer(pExpr + 20))
		pList = v1
	}
	if v2 || v1 == uintptr(0) {
		n = 0
	} else {
		n = (*TExprList)(unsafe.Pointer(pList)).FnExpr
		_sqlite3WalkExprList(tls, pWalker, pList)
		if int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) == 0 {
			return int32(WRC_Abort)
		}
	}
	db = (*TParse)(unsafe.Pointer((*TWalker)(unsafe.Pointer(pWalker)).FpParse)).Fdb
	pDef = _sqlite3FindFunction(tls, db, *(*uintptr)(unsafe.Pointer(pExpr + 8)), n, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, uint8(0))
	if pDef == uintptr(0) || (*TFuncDef)(unsafe.Pointer(pDef)).FxFinalize != uintptr(0) || (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)|libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG)) == uint32(0) || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
		return int32(WRC_Abort)
	}
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** These routines are Walker callbacks used to check expressions to
//	** see if they are "constant" for some definition of constant.  The
//	** Walker.eCode value determines the type of "constant" we are looking
//	** for.
//	**
//	** These callback routines are used to implement the following:
//	**
//	**     sqlite3ExprIsConstant()                  pWalker->eCode==1
//	**     sqlite3ExprIsConstantNotJoin()           pWalker->eCode==2
//	**     sqlite3ExprIsTableConstant()             pWalker->eCode==3
//	**     sqlite3ExprIsConstantOrFunction()        pWalker->eCode==4 or 5
//	**
//	** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
//	** is found to not be a constant.
//	**
//	** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
//	** expressions in a CREATE TABLE statement.  The Walker.eCode value is 5
//	** when parsing an existing schema out of the sqlite_schema table and 4
//	** when processing a new CREATE TABLE statement.  A bound parameter raises
//	** an error for new statements, but is silently converted
//	** to NULL for existing schemas.  This allows sqlite_schema tables that
//	** contain a bound parameter because they were generated by older versions
//	** of SQLite to be parsed by newer versions of SQLite without raising a
//	** malformed schema error.
//	*/
func _exprNodeIsConstant(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	/* If pWalker->eCode is 2 then any term of the expression that comes from
	 ** the ON or USING clauses of an outer join disqualifies the expression
	 ** from being considered constant. */
	if int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) == int32(2) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
		return int32(WRC_Abort)
	}
	switch int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	/* Consider functions to be constant if all their arguments are constant
	 ** and either pWalker->eCode==4 or 5 or the function has the
	 ** SQLITE_FUNC_CONST flag. */
	case int32(TK_FUNCTION):
		if (int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) >= int32(4) || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_ConstFunc)) != uint32(0)) && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != libc.Uint32FromInt32(0)) {
			if int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) == int32(5) {
				*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_FromDDL))
			}
			return WRC_Continue
		} else {
			if (*TWalker)(unsafe.Pointer(pWalker)).FpParse != 0 {
				return _exprNodeIsConstantFunction(tls, pWalker, pExpr)
			} else {
				(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
				return int32(WRC_Abort)
			}
		}
		fallthrough
	case int32(TK_ID):
		/* Convert "true" or "false" in a DEFAULT clause into the
		 ** appropriate TK_TRUEFALSE operator */
		if _sqlite3ExprIdToTrueFalse(tls, pExpr) != 0 {
			return int32(WRC_Prune)
		}
		fallthrough
	case int32(TK_COLUMN):
		fallthrough
	case int32(TK_AGG_FUNCTION):
		fallthrough
	case int32(TK_AGG_COLUMN):
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_FixedCol)) != uint32(0) && int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) != int32(2) {
			return WRC_Continue
		}
		if int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) == int32(3) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == *(*int32)(unsafe.Pointer(pWalker + 24)) {
			return WRC_Continue
		}
		fallthrough
	case int32(TK_IF_NULL_ROW):
		fallthrough
	case int32(TK_REGISTER):
		fallthrough
	case int32(TK_DOT):
		fallthrough
	case int32(TK_RAISE):
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
		return int32(WRC_Abort)
	case int32(TK_VARIABLE):
		if int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) == int32(5) {
			/* Silently convert bound parameters that appear inside of CREATE
			 ** statements into a NULL when parsing the CREATE statement text out
			 ** of the sqlite_schema table */
			(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
		} else {
			if int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) == int32(4) {
				/* A bound parameter in a CREATE statement that originates from
				 ** sqlite3_prepare() causes an error */
				(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
				return int32(WRC_Abort)
			}
		}
		fallthrough
	default:
		/* sqlite3SelectWalkFail() disallows */
		/* sqlite3SelectWalkFail() disallows */
		return WRC_Continue
	}
	return r
}

func _exprIsConst(tls *libc.TLS, pParse uintptr, p uintptr, initFlag int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(uint16(initFlag))
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprNodeIsConstant)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkFail)
	_sqlite3WalkExpr(tls, bp, p)
	return int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)
}

// C documentation
//
//	/*
//	** Walk an expression tree.  Return non-zero if the expression is constant
//	** and 0 if it involves variables or function calls.
//	**
//	** For the purposes of this function, a double-quoted string (ex: "abc")
//	** is considered a variable but a single-quoted string (ex: 'abc') is
//	** a constant.
//	**
//	** The pParse parameter may be NULL.  But if it is NULL, there is no way
//	** to determine if function calls are constant or not, and hence all
//	** function calls will be considered to be non-constant.  If pParse is
//	** not NULL, then a function call might be constant, depending on the
//	** function and on its parameters.
//	*/
func _sqlite3ExprIsConstant(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	return _exprIsConst(tls, pParse, p, int32(1))
}

// C documentation
//
//	/*
//	** Walk an expression tree.  Return non-zero if
//	**
//	**   (1) the expression is constant, and
//	**   (2) the expression does originate in the ON or USING clause
//	**       of a LEFT JOIN, and
//	**   (3) the expression does not contain any EP_FixedCol TK_COLUMN
//	**       operands created by the constant propagation optimization.
//	**
//	** When this routine returns true, it indicates that the expression
//	** can be added to the pParse->pConstExpr list and evaluated once when
//	** the prepared statement starts up.  See sqlite3ExprCodeRunJustOnce().
//	*/
func _sqlite3ExprIsConstantNotJoin(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	return _exprIsConst(tls, pParse, p, int32(2))
}

// C documentation
//
//	/*
//	** This routine examines sub-SELECT statements as an expression is being
//	** walked as part of sqlite3ExprIsTableConstant().  Sub-SELECTs are considered
//	** constant as long as they are uncorrelated - meaning that they do not
//	** contain any terms from outer contexts.
//	*/
func _exprSelectWalkTableConstant(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	if (*TSelect)(unsafe.Pointer(pSelect)).FselFlags&uint32(SF_Correlated) != uint32(0) {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
		return int32(WRC_Abort)
	}
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** Walk an expression tree.  Return non-zero if the expression is constant
//	** for any single row of the table with cursor iCur.  In other words, the
//	** expression must not refer to any non-deterministic function nor any
//	** table other than iCur.
//	**
//	** Consider uncorrelated subqueries to be constants if the bAllowSubq
//	** parameter is true.
//	*/
func _sqlite3ExprIsTableConstant(tls *libc.TLS, p uintptr, iCur int32, bAllowSubq int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(3)
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = uintptr(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprNodeIsConstant)
	if bAllowSubq != 0 {
		(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_exprSelectWalkTableConstant)
	} else {
		(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkFail)
	}
	*(*int32)(unsafe.Pointer(bp + 24)) = iCur
	_sqlite3WalkExpr(tls, bp, p)
	return int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)
}

// C documentation
//
//	/*
//	** Check pExpr to see if it is an constraint on the single data source
//	** pSrc = &pSrcList->a[iSrc].  In other words, check to see if pExpr
//	** constrains pSrc but does not depend on any other tables or data
//	** sources anywhere else in the query.  Return true (non-zero) if pExpr
//	** is a constraint on pSrc only.
//	**
//	** This is an optimization.  False negatives will perhaps cause slower
//	** queries, but false positives will yield incorrect answers.  So when in
//	** doubt, return 0.
//	**
//	** To be an single-source constraint, the following must be true:
//	**
//	**   (1)  pExpr cannot refer to any table other than pSrc->iCursor.
//	**
//	**   (2a) pExpr cannot use subqueries unless the bAllowSubq parameter is
//	**        true and the subquery is non-correlated
//	**
//	**   (2b) pExpr cannot use non-deterministic functions.
//	**
//	**   (3)  pSrc cannot be part of the left operand for a RIGHT JOIN.
//	**        (Is there some way to relax this constraint?)
//	**
//	**   (4)  If pSrc is the right operand of a LEFT JOIN, then...
//	**         (4a)  pExpr must come from an ON clause..
//	**         (4b)  and specifically the ON clause associated with the LEFT JOIN.
//	**
//	**   (5)  If pSrc is not the right operand of a LEFT JOIN or the left
//	**        operand of a RIGHT JOIN, then pExpr must be from the WHERE
//	**        clause, not an ON clause.
//	**
//	**   (6) Either:
//	**
//	**       (6a) pExpr does not originate in an ON or USING clause, or
//	**
//	**       (6b) The ON or USING clause from which pExpr is derived is
//	**            not to the left of a RIGHT JOIN (or FULL JOIN).
//	**
//	**       Without this restriction, accepting pExpr as a single-table
//	**       constraint might move the the ON/USING filter expression
//	**       from the left side of a RIGHT JOIN over to the right side,
//	**       which leads to incorrect answers.  See also restriction (9)
//	**       on push-down.
//	*/
func _sqlite3ExprIsSingleTableConstraint(tls *libc.TLS, pExpr uintptr, pSrcList uintptr, iSrc int32, bAllowSubq int32) (r int32) {
	var jj int32
	var pSrc uintptr
	_, _ = jj, pSrc
	pSrc = pSrcList + 8 + uintptr(iSrc)*72
	if int32((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
		return 0 /* rule (3) */
	}
	if int32((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
		if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) {
			return 0
		} /* rule (4a) */
		if *(*int32)(unsafe.Pointer(pExpr + 36)) != (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
			return 0
		} /* rule (4b) */
	} else {
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
			return 0
		} /* rule (5) */
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) && int32((*(*TSrcItem)(unsafe.Pointer(pSrcList + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
		jj = 0
		for {
			if !(jj < iSrc) {
				break
			}
			if *(*int32)(unsafe.Pointer(pExpr + 36)) == (*(*TSrcItem)(unsafe.Pointer(pSrcList + 8 + uintptr(jj)*72))).FiCursor {
				if int32((*(*TSrcItem)(unsafe.Pointer(pSrcList + 8 + uintptr(jj)*72))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
					return 0 /* restriction (6) */
				}
				break
			}
			goto _1
		_1:
			;
			jj++
		}
	}
	/* Rules (1), (2a), and (2b) handled by the following: */
	return _sqlite3ExprIsTableConstant(tls, pExpr, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor, bAllowSubq)
}

// C documentation
//
//	/*
//	** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
//	*/
func _exprNodeIsConstantOrGroupBy(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var i int32
	var p, pColl, pGroupBy uintptr
	_, _, _, _ = i, p, pColl, pGroupBy
	pGroupBy = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	/* Check if pExpr is identical to any GROUP BY term. If so, consider
	 ** it constant.  */
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
			break
		}
		p = (*(*TExprList_item)(unsafe.Pointer(pGroupBy + 8 + uintptr(i)*20))).FpExpr
		if _sqlite3ExprCompare(tls, uintptr(0), pExpr, p, -int32(1)) < int32(2) {
			pColl = _sqlite3ExprNNCollSeq(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, p)
			if _sqlite3IsBinary(tls, pColl) != 0 {
				return int32(WRC_Prune)
			}
		}
		goto _1
	_1:
		;
		i++
	}
	/* Check if pExpr is a sub-select. If so, consider it variable. */
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
		return int32(WRC_Abort)
	}
	return _exprNodeIsConstant(tls, pWalker, pExpr)
}

// C documentation
//
//	/*
//	** Walk the expression tree passed as the first argument. Return non-zero
//	** if the expression consists entirely of constants or copies of terms
//	** in pGroupBy that sort with the BINARY collation sequence.
//	**
//	** This routine is used to determine if a term of the HAVING clause can
//	** be promoted into the WHERE clause.  In order for such a promotion to work,
//	** the value of the HAVING clause term must be the same for all members of
//	** a "group".  The requirement that the GROUP BY term must be BINARY
//	** assumes that no other collating sequence will have a finer-grained
//	** grouping than binary.  In other words (A=B COLLATE binary) implies
//	** A=B in every other collating sequence.  The requirement that the
//	** GROUP BY be BINARY is stricter than necessary.  It would also work
//	** to promote HAVING clauses that use the same alternative collating
//	** sequence as the GROUP BY term, but that is much harder to check,
//	** alternative collating sequences are uncommon, and this is only an
//	** optimization, so we take the easy way out and simply require the
//	** GROUP BY to use the BINARY collating sequence.
//	*/
func _sqlite3ExprIsConstantOrGroupBy(tls *libc.TLS, pParse uintptr, p uintptr, pGroupBy uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(1)
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprNodeIsConstantOrGroupBy)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pGroupBy
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	_sqlite3WalkExpr(tls, bp, p)
	return int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)
}

// C documentation
//
//	/*
//	** Walk an expression tree for the DEFAULT field of a column definition
//	** in a CREATE TABLE statement.  Return non-zero if the expression is
//	** acceptable for use as a DEFAULT.  That is to say, return non-zero if
//	** the expression is constant or a function call with constant arguments.
//	** Return and 0 if there are any variables.
//	**
//	** isInit is true when parsing from sqlite_schema.  isInit is false when
//	** processing a new CREATE TABLE statement.  When isInit is true, parameters
//	** (such as ? or $abc) in the expression are converted into NULL.  When
//	** isInit is false, parameters raise an error.  Parameters should not be
//	** allowed in a CREATE TABLE statement, but some legacy versions of SQLite
//	** allowed it, so we need to support it when reading sqlite_schema for
//	** backwards compatibility.
//	**
//	** If isInit is true, set EP_FromDDL on every TK_FUNCTION node.
//	**
//	** For the purposes of this function, a double-quoted string (ex: "abc")
//	** is considered a variable but a single-quoted string (ex: 'abc') is
//	** a constant.
//	*/
func _sqlite3ExprIsConstantOrFunction(tls *libc.TLS, p uintptr, isInit Tu8) (r int32) {
	return _exprIsConst(tls, uintptr(0), p, int32(4)+int32(int32(isInit)))
}

// C documentation
//
//	/*
//	** If the expression p codes a constant integer that is small enough
//	** to fit in a 32-bit integer, return 1 and put the value of the integer
//	** in *pValue.  If the expression is not an integer or if it is too big
//	** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
//	*/
func _sqlite3ExprIsInteger(tls *libc.TLS, p uintptr, pValue uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* v at bp+0 */ int32
	_ = rc
	rc = 0
	if p == uintptr(0) {
		return 0
	} /* Used to only happen following on OOM */
	/* If an expression is an integer literal that fits in a signed 32-bit
	 ** integer, then the EP_IntValue flag will have already been set */
	if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_IntValue) != 0 {
		*(*int32)(unsafe.Pointer(pValue)) = *(*int32)(unsafe.Pointer(p + 8))
		return int32(1)
	}
	switch int32((*TExpr)(unsafe.Pointer(p)).Fop) {
	case int32(TK_UPLUS):
		rc = _sqlite3ExprIsInteger(tls, (*TExpr)(unsafe.Pointer(p)).FpLeft, pValue)
	case int32(TK_UMINUS):
		*(*int32)(unsafe.Pointer(bp)) = 0
		if _sqlite3ExprIsInteger(tls, (*TExpr)(unsafe.Pointer(p)).FpLeft, bp) != 0 {
			*(*int32)(unsafe.Pointer(pValue)) = -*(*int32)(unsafe.Pointer(bp))
			rc = int32(1)
		}
	default:
		break
	}
	return rc
}

// 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 int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UPLUS) || int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UMINUS) {
		p = (*TExpr)(unsafe.Pointer(p)).FpLeft
	}
	op = (*TExpr)(unsafe.Pointer(p)).Fop
	if int32(int32(op)) == int32(TK_REGISTER) {
		op = (*TExpr)(unsafe.Pointer(p)).Fop2
	}
	switch int32(int32(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&uint32(libc.Int32FromInt32(EP_CanBeNull)) != uint32(0) || (*TExpr)(unsafe.Pointer(p)).Fy.FpTab == uintptr(0) || int32((*TExpr)(unsafe.Pointer(p)).FiColumn) >= 0 && (*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).Fy.FpTab)).FaCol != uintptr(0) && int32((*TExpr)(unsafe.Pointer(p)).FiColumn) < int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).Fy.FpTab)).FnCol) && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).Fy.FpTab)).FaCol + uintptr((*TExpr)(unsafe.Pointer(p)).FiColumn)*12 + 4))&0xf>>0)) == 0)
	default:
		return int32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Return TRUE if the given expression is a constant which would be
//	** unchanged by OP_Affinity with the affinity given in the second
//	** argument.
//	**
//	** This routine is used to determine if the OP_Affinity operation
//	** can be omitted.  When in doubt return FALSE.  A false negative
//	** is harmless.  A false positive, however, can result in the wrong
//	** answer.
//	*/
func _sqlite3ExprNeedsNoAffinityChange(tls *libc.TLS, p uintptr, aff int8) (r int32) {
	var op Tu8
	var unaryMinus int32
	_, _ = op, unaryMinus
	unaryMinus = 0
	if int32(int32(aff)) == int32(SQLITE_AFF_BLOB) {
		return int32(1)
	}
	for int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UPLUS) || int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UMINUS) {
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UMINUS) {
			unaryMinus = int32(1)
		}
		p = (*TExpr)(unsafe.Pointer(p)).FpLeft
	}
	op = (*TExpr)(unsafe.Pointer(p)).Fop
	if int32(int32(op)) == int32(TK_REGISTER) {
		op = (*TExpr)(unsafe.Pointer(p)).Fop2
	}
	switch int32(int32(op)) {
	case int32(TK_INTEGER):
		return libc.BoolInt32(int32(int32(aff)) >= int32(SQLITE_AFF_NUMERIC))
	case int32(TK_FLOAT):
		return libc.BoolInt32(int32(int32(aff)) >= int32(SQLITE_AFF_NUMERIC))
	case int32(TK_STRING):
		return libc.BoolInt32(!(unaryMinus != 0) && int32(int32(aff)) == int32(SQLITE_AFF_TEXT))
	case int32(TK_BLOB):
		return libc.BoolInt32(!(unaryMinus != 0))
	case int32(TK_COLUMN):
		/* p cannot be part of a CHECK constraint */
		return libc.BoolInt32(int32(int32(aff)) >= int32(SQLITE_AFF_NUMERIC) && int32((*TExpr)(unsafe.Pointer(p)).FiColumn) < 0)
	default:
		return 0
	}
	return r
}

// C documentation
//
//	/*
//	** Return TRUE if the given string is a row-id column name.
//	*/
func _sqlite3IsRowid(tls *libc.TLS, z uintptr) (r int32) {
	if _sqlite3StrICmp(tls, z, __ccgo_ts+9331) == 0 {
		return int32(1)
	}
	if _sqlite3StrICmp(tls, z, __ccgo_ts+9339) == 0 {
		return int32(1)
	}
	if _sqlite3StrICmp(tls, z, __ccgo_ts+9345) == 0 {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Return a pointer to a buffer containing a usable rowid alias for table
//	** pTab. An alias is usable if there is not an explicit user-defined column
//	** of the same name.
//	*/
func _sqlite3RowidAlias(tls *libc.TLS, pTab uintptr) (r uintptr) {
	var azOpt [3]uintptr
	var iCol, ii int32
	_, _, _ = azOpt, iCol, ii
	azOpt = [3]uintptr{
		0: __ccgo_ts + 9331,
		1: __ccgo_ts + 9339,
		2: __ccgo_ts + 9345,
	}
	ii = 0
	for {
		if !(ii < int32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(4))) {
			break
		}
		iCol = 0
		for {
			if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if Xsqlite3_stricmp(tls, azOpt[ii], (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName) == 0 {
				break
			}
			goto _2
		_2:
			;
			iCol++
		}
		if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
			return azOpt[ii]
		}
		goto _1
	_1:
		;
		ii++
	}
	return uintptr(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&uint32(libc.Int32FromInt32(EP_VarSelect)) != uint32(0) {
		return uintptr(0)
	} /* Correlated subq */
	p = *(*uintptr)(unsafe.Pointer(pX + 20))
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		return uintptr(0)
	} /* Not a compound SELECT */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(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 (*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FpSelect != 0 {
		return uintptr(0)
	} /* FROM is not a subquery or view */
	pTab = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FpTab
	/* FROM clause is not a view */
	if int32((*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)*20))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pRes)).Fop) != int32(TK_COLUMN) {
			return uintptr(0)
		}
		/* Not a correlated subquery */
		goto _1
	_1:
		;
		i++
	}
	return p
}

// C documentation
//
//	/*
//	** Generate code that checks the left-most column of index table iCur to see if
//	** it contains any NULL entries.  Cause the register at regHasNull to be set
//	** to a non-NULL value if iCur contains no NULLs.  Cause register regHasNull
//	** to be set to NULL if iCur contains one or more NULL values.
//	*/
func _sqlite3SetHasNullFlag(tls *libc.TLS, v uintptr, iCur int32, regHasNull int32) {
	var addr1 int32
	_ = addr1
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regHasNull)
	addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iCur)
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iCur, 0, regHasNull)
	_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_TYPEOFARG))
	_sqlite3VdbeJumpHere(tls, v, addr1)
}

// C documentation
//
//	/*
//	** The argument is an IN operator with a list (not a subquery) on the
//	** right-hand side.  Return TRUE if that list is constant.
//	*/
func _sqlite3InRhsIsConstant(tls *libc.TLS, pParse uintptr, pIn uintptr) (r int32) {
	var pLHS uintptr
	var res int32
	_, _ = pLHS, res
	pLHS = (*TExpr)(unsafe.Pointer(pIn)).FpLeft
	(*TExpr)(unsafe.Pointer(pIn)).FpLeft = uintptr(0)
	res = _sqlite3ExprIsConstant(tls, pParse, pIn)
	(*TExpr)(unsafe.Pointer(pIn)).FpLeft = pLHS
	return res
}

// C documentation
//
//	/*
//	** This function is used by the implementation of the IN (...) operator.
//	** The pX parameter is the expression on the RHS of the IN operator, which
//	** might be either a list of expressions or a subquery.
//	**
//	** The job of this routine is to find or create a b-tree object that can
//	** be used either to test for membership in the RHS set or to iterate through
//	** all members of the RHS set, skipping duplicates.
//	**
//	** A cursor is opened on the b-tree object that is the RHS of the IN operator
//	** and the *piTab parameter is set to the index of that cursor.
//	**
//	** The returned value of this function indicates the b-tree type, as follows:
//	**
//	**   IN_INDEX_ROWID      - The cursor was opened on a database table.
//	**   IN_INDEX_INDEX_ASC  - The cursor was opened on an ascending index.
//	**   IN_INDEX_INDEX_DESC - The cursor was opened on a descending index.
//	**   IN_INDEX_EPH        - The cursor was opened on a specially created and
//	**                         populated ephemeral table.
//	**   IN_INDEX_NOOP       - No cursor was allocated.  The IN operator must be
//	**                         implemented as a sequence of comparisons.
//	**
//	** An existing b-tree might be used if the RHS expression pX is a simple
//	** subquery such as:
//	**
//	**     SELECT <column1>, <column2>... FROM <table>
//	**
//	** If the RHS of the IN operator is a list or a more complex subquery, then
//	** an ephemeral table might need to be generated from the RHS and then
//	** pX->iTable made to point to the ephemeral table instead of an
//	** existing table.  In this case, the creation and initialization of the
//	** ephemeral table might be put inside of a subroutine, the EP_Subrtn flag
//	** will be set on pX and the pX->y.sub fields will be set to show where
//	** the subroutine is coded.
//	**
//	** The inFlags parameter must contain, at a minimum, one of the bits
//	** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both.  If inFlags contains
//	** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
//	** membership test.  When the IN_INDEX_LOOP bit is set, the IN index will
//	** be used to loop over all values of the RHS of the IN operator.
//	**
//	** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
//	** through the set members) then the b-tree must not contain duplicates.
//	** An ephemeral table will be created unless the selected columns are guaranteed
//	** to be unique - either because it is an INTEGER PRIMARY KEY or due to
//	** a UNIQUE constraint or index.
//	**
//	** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
//	** for fast set membership tests) then an ephemeral table must
//	** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
//	** index can be found with the specified <columns> as its left-most.
//	**
//	** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and
//	** if the RHS of the IN operator is a list (not a subquery) then this
//	** routine might decide that creating an ephemeral b-tree for membership
//	** testing is too expensive and return IN_INDEX_NOOP.  In that case, the
//	** calling routine should implement the IN operator using a sequence
//	** of Eq or Ne comparison operations.
//	**
//	** When the b-tree is being used for membership tests, the calling function
//	** might need to know whether or not the RHS side of the IN operator
//	** contains a NULL.  If prRhsHasNull is not a NULL pointer and
//	** if there is any chance that the (...) might contain a NULL value at
//	** runtime, then a register is allocated and the register number written
//	** to *prRhsHasNull. If there is no chance that the (...) contains a
//	** NULL value, then *prRhsHasNull is left unchanged.
//	**
//	** If a register is allocated and its location stored in *prRhsHasNull, then
//	** the value in that register will be NULL if the b-tree contains one or more
//	** NULL values, and it will be some non-NULL value if the b-tree contains no
//	** NULL values.
//	**
//	** If the aiMap parameter is not NULL, it must point to an array containing
//	** one element for each column returned by the SELECT statement on the RHS
//	** of the IN(...) operator. The i'th entry of the array is populated with the
//	** offset of the index column that matches the i'th column returned by the
//	** SELECT. For example, if the expression and selected index are:
//	**
//	**   (?,?,?) IN (SELECT a, b, c FROM t1)
//	**   CREATE INDEX i1 ON t1(b, c, a);
//	**
//	** then aiMap[] is populated with {2, 0, 1}.
//	*/
func _sqlite3FindInIndex(tls *libc.TLS, pParse uintptr, pX uintptr, inFlags Tu32, prRhsHasNull uintptr, aiMap uintptr, piTab uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var affinity_ok, eType, i, i1, i2, iAddr, iAddr1, iCol, iDb, iTab, j, mustBeUnique, n, nExpr, rMayHaveNull, v1, v10, v12, v13 int32
	var cmpaff, idxaff int8
	var colUsed, mCol TBitmask
	var db, p, pEList, pEList1, pIdx, pLhs, pLhs1, pReq, pRhs, pTab, v, v11, v14, v2, v4 uintptr
	var savedNQueryLoop Tu32
	var v5 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = affinity_ok, cmpaff, colUsed, db, eType, i, i1, i2, iAddr, iAddr1, iCol, iDb, iTab, idxaff, j, mCol, mustBeUnique, n, nExpr, p, pEList, pEList1, pIdx, pLhs, pLhs1, pReq, pRhs, pTab, rMayHaveNull, savedNQueryLoop, v, v1, v10, v11, v12, v13, v14, v2, v4, v5 /* SELECT to the right of IN operator */
	eType = 0                                                                                                                                                                                                                                                                                                                                                                                /* True if RHS must be unique */
	v = _sqlite3GetVdbe(tls, pParse)                                                                                                                                                                                                                                                                                                                                                         /* Virtual machine being coded */
	mustBeUnique = libc.BoolInt32(inFlags&uint32(IN_INDEX_LOOP) != uint32(0))
	v2 = pParse + 40
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	iTab = v1
	/* If the RHS of this IN(...) operator is a SELECT, and if it matters
	 ** whether or not the SELECT result contains NULL values, check whether
	 ** or not NULL is actually possible (it may not be, for example, due
	 ** to NOT NULL constraints in the schema). If no NULL values are possible,
	 ** set prRhsHasNull to 0 before continuing.  */
	if prRhsHasNull != 0 && (*TExpr)(unsafe.Pointer(pX)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		pEList = (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 20)))).FpEList
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			if _sqlite3ExprCanBeNull(tls, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr) != 0 {
				break
			}
			goto _3
		_3:
			;
			i++
		}
		if i == (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
			prRhsHasNull = uintptr(0)
		}
	}
	/* Check to see if an existing table or index can be used to
	 ** satisfy the query.  This is preferable to generating a new
	 ** ephemeral table.  */
	if v5 = (*TParse)(unsafe.Pointer(pParse)).FnErr == 0; v5 {
		v4 = _isCandidateForInOpt(tls, pX)
		p = v4
	}
	if v5 && v4 != uintptr(0) {
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database idx for pTab */
		pEList1 = (*TSelect)(unsafe.Pointer(p)).FpEList
		nExpr = (*TExprList)(unsafe.Pointer(pEList1)).FnExpr
		/* Because of isCandidateForInOpt(p) */
		/* Because of isCandidateForInOpt(p) */
		/* Because of isCandidateForInOpt(p) */
		pTab = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpTab
		/* Code an OP_Transaction and OP_TableLock for <table>. */
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		_sqlite3CodeVerifySchema(tls, pParse, iDb)
		_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab)).FzName)
		/* sqlite3GetVdbe() has always been previously called */
		if nExpr == int32(1) && int32((*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList1 + 8))).FpExpr)).FiColumn) < 0 {
			/* The "x IN (SELECT rowid FROM table)" case */
			iAddr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			_sqlite3OpenTable(tls, pParse, iTab, iDb, pTab, int32(OP_OpenRead))
			eType = int32(IN_INDEX_ROWID)
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+9349, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
			_sqlite3VdbeJumpHere(tls, v, iAddr)
		} else { /* Iterator variable */
			affinity_ok = int32(1)
			/* Check that the affinity that will be used to perform each
			 ** comparison is the same as the affinity of each column in table
			 ** on the RHS of the IN operator.  If it not, it is not possible to
			 ** use any index of the RHS table.  */
			i1 = 0
			for {
				if !(i1 < nExpr && affinity_ok != 0) {
					break
				}
				pLhs = _sqlite3VectorFieldSubexpr(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft, i1)
				iCol = int32((*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList1 + 8 + uintptr(i1)*20))).FpExpr)).FiColumn)
				idxaff = _sqlite3TableColumnAffinity(tls, pTab, iCol) /* RHS table */
				cmpaff = _sqlite3CompareAffinity(tls, pLhs, idxaff)
				switch int32(int32(cmpaff)) {
				case int32(SQLITE_AFF_BLOB):
				case int32(SQLITE_AFF_TEXT):
					/* sqlite3CompareAffinity() only returns TEXT if one side or the
					 ** other has no affinity and the other side is TEXT.  Hence,
					 ** the only way for cmpaff to be TEXT is for idxaff to be TEXT
					 ** and for the term on the LHS of the IN to have no affinity. */
				default:
					affinity_ok = libc.BoolInt32(int32(idxaff) >= int32(SQLITE_AFF_NUMERIC))
				}
				goto _6
			_6:
				;
				i1++
			}
			if affinity_ok != 0 {
				/* Search for an existing index that will work for this IN operator */
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0 && eType == 0) {
						break
					} /* Mask for the current column */
					if int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) < nExpr {
						goto _7
					}
					if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) {
						goto _7
					}
					/* Maximum nColumn is BMS-2, not BMS-1, so that we can compute
					 ** BITMASK(nExpr) without overflowing */
					if int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
						goto _7
					}
					if mustBeUnique != 0 {
						if int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) > nExpr || int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) > nExpr && !(int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromInt32(OE_None)) {
							goto _7 /* This index is not unique over the IN RHS columns */
						}
					}
					colUsed = uint64(0) /* Columns of index used so far */
					i1 = 0
					for {
						if !(i1 < nExpr) {
							break
						}
						pLhs1 = _sqlite3VectorFieldSubexpr(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft, i1)
						pRhs = (*(*TExprList_item)(unsafe.Pointer(pEList1 + 8 + uintptr(i1)*20))).FpExpr
						pReq = _sqlite3BinaryCompareCollSeq(tls, pParse, pLhs1, pRhs)
						j = 0
						for {
							if !(j < nExpr) {
								break
							}
							if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) != int32((*TExpr)(unsafe.Pointer(pRhs)).FiColumn) {
								goto _9
							}
							if pReq != uintptr(0) && _sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pReq)).FzName, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*4))) != 0 {
								goto _9
							}
							break
							goto _9
						_9:
							;
							j++
						}
						if j == nExpr {
							break
						}
						mCol = libc.Uint64FromInt32(1) << j
						if mCol&colUsed != 0 {
							break
						} /* Each column used only once */
						colUsed |= mCol
						if aiMap != 0 {
							*(*int32)(unsafe.Pointer(aiMap + uintptr(i1)*4)) = j
						}
						goto _8
					_8:
						;
						i1++
					}
					if colUsed == libc.Uint64FromInt32(1)<<nExpr-uint64(1) {
						/* If we reach this point, that means the index pIdx is usable */
						iAddr1 = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
						_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+9396, libc.VaList(bp+8, (*TIndex)(unsafe.Pointer(pIdx)).FzName))
						_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), iTab, int32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
						_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
						eType = int32(IN_INDEX_INDEX_ASC) + int32(*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder)))
						if prRhsHasNull != 0 {
							v11 = pParse + 44
							*(*int32)(unsafe.Pointer(v11))++
							v10 = *(*int32)(unsafe.Pointer(v11))
							*(*int32)(unsafe.Pointer(prRhsHasNull)) = v10
							if nExpr == int32(1) {
								_sqlite3SetHasNullFlag(tls, v, iTab, *(*int32)(unsafe.Pointer(prRhsHasNull)))
							}
						}
						_sqlite3VdbeJumpHere(tls, v, iAddr1)
					}
					goto _7
				_7:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
				} /* End loop over indexes */
			} /* End if( affinity_ok ) */
		} /* End if not an rowid index */
	} /* End attempt to optimize using an index */
	/* If no preexisting index is available for the IN clause
	 ** and IN_INDEX_NOOP is an allowed reply
	 ** and the RHS of the IN operator is a list, not a subquery
	 ** and the RHS is not constant or has two or fewer terms,
	 ** then it is not worth creating an ephemeral table to evaluate
	 ** the IN operator so return IN_INDEX_NOOP.
	 */
	if eType == 0 && inFlags&uint32(IN_INDEX_NOOP_OK) != 0 && (*TExpr)(unsafe.Pointer(pX)).Fflags&uint32(EP_xIsSelect) == uint32(0) && (!(_sqlite3InRhsIsConstant(tls, pParse, pX) != 0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 20)))).FnExpr <= int32(2)) {
		(*TParse)(unsafe.Pointer(pParse)).FnTab-- /* Back out the allocation of the unused cursor */
		iTab = -int32(1)                          /* Cursor is not allocated */
		eType = int32(IN_INDEX_NOOP)
	}
	if eType == 0 {
		/* Could not find an existing table or index to use as the RHS b-tree.
		 ** We will have to generate an ephemeral table to do the job.
		 */
		savedNQueryLoop = uint32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
		rMayHaveNull = 0
		eType = int32(IN_INDEX_EPH)
		if inFlags&uint32(IN_INDEX_LOOP) != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = 0
		} else {
			if prRhsHasNull != 0 {
				v14 = pParse + 44
				*(*int32)(unsafe.Pointer(v14))++
				v13 = *(*int32)(unsafe.Pointer(v14))
				v12 = v13
				rMayHaveNull = v12
				*(*int32)(unsafe.Pointer(prRhsHasNull)) = v12
			}
		}
		_sqlite3CodeRhsOfIN(tls, pParse, pX, iTab)
		if rMayHaveNull != 0 {
			_sqlite3SetHasNullFlag(tls, v, iTab, rMayHaveNull)
		}
		(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = int16(int16(savedNQueryLoop))
	}
	if aiMap != 0 && eType != int32(IN_INDEX_INDEX_ASC) && eType != int32(IN_INDEX_INDEX_DESC) {
		n = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft)
		i2 = 0
		for {
			if !(i2 < n) {
				break
			}
			*(*int32)(unsafe.Pointer(aiMap + uintptr(i2)*4)) = i2
			goto _15
		_15:
			;
			i2++
		}
	}
	*(*int32)(unsafe.Pointer(piTab)) = iTab
	return eType
}

// C documentation
//
//	/*
//	** Argument pExpr is an (?, ?...) IN(...) expression. This
//	** function allocates and returns a nul-terminated string containing
//	** the affinities to be used for each column of the comparison.
//	**
//	** It is the responsibility of the caller to ensure that the returned
//	** string is eventually freed using sqlite3DbFree().
//	*/
func _exprINAffinity(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r uintptr) {
	var a int8
	var i, nVal int32
	var pA, pLeft, pSelect, zRet, v1 uintptr
	_, _, _, _, _, _, _, _ = a, i, nVal, pA, pLeft, pSelect, zRet, v1
	pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	nVal = _sqlite3ExprVectorSize(tls, pLeft)
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		v1 = *(*uintptr)(unsafe.Pointer(pExpr + 20))
	} else {
		v1 = uintptr(0)
	}
	pSelect = v1
	zRet = _sqlite3DbMallocRaw(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(nVal+int32(1)))
	if zRet != 0 {
		i = 0
		for {
			if !(i < nVal) {
				break
			}
			pA = _sqlite3VectorFieldSubexpr(tls, pLeft, i)
			a = _sqlite3ExprAffinity(tls, pA)
			if pSelect != 0 {
				*(*int8)(unsafe.Pointer(zRet + uintptr(i))) = _sqlite3CompareAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpEList + 8 + uintptr(i)*20))).FpExpr, a)
			} else {
				*(*int8)(unsafe.Pointer(zRet + uintptr(i))) = a
			}
			goto _2
		_2:
			;
			i++
		}
		*(*int8)(unsafe.Pointer(zRet + uintptr(nVal))) = int8('\000')
	}
	return zRet
}

// C documentation
//
//	/*
//	** Load the Parse object passed as the first argument with an error
//	** message of the form:
//	**
//	**   "sub-select returns N columns - expected M"
//	*/
func _sqlite3SubselectError(tls *libc.TLS, pParse uintptr, nActual int32, nExpect int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zFmt uintptr
	_ = zFmt
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		zFmt = __ccgo_ts + 9427
		_sqlite3ErrorMsg(tls, pParse, zFmt, libc.VaList(bp+8, nActual, nExpect))
	}
}

// C documentation
//
//	/*
//	** Expression pExpr is a vector that has been used in a context where
//	** it is not permitted. If pExpr is a sub-select vector, this routine
//	** loads the Parse object with a message of the form:
//	**
//	**   "sub-select returns N columns - expected 1"
//	**
//	** Or, if it is a regular scalar vector:
//	**
//	**   "row value misused"
//	*/
func _sqlite3VectorErrorMsg(tls *libc.TLS, pParse uintptr, pExpr uintptr) {
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		_sqlite3SubselectError(tls, pParse, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpEList)).FnExpr, int32(1))
	} else {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8050, 0)
	}
}

// C documentation
//
//	/*
//	** Generate code that will construct an ephemeral table containing all terms
//	** in the RHS of an IN operator.  The IN operator can be in either of two
//	** forms:
//	**
//	**     x IN (4,5,11)              -- IN operator with list on right-hand side
//	**     x IN (SELECT a FROM b)     -- IN operator with subquery on the right
//	**
//	** The pExpr parameter is the IN operator.  The cursor number for the
//	** constructed ephemeral table is returned.  The first time the ephemeral
//	** table is computed, the cursor number is also stored in pExpr->iTable,
//	** however the cursor number returned might not be the same, as it might
//	** have been duplicated using OP_OpenDup.
//	**
//	** If the LHS expression ("x" in the examples) is a column value, or
//	** the SELECT statement returns a column value, then the affinity of that
//	** column is used to build the index keys. If both 'x' and the
//	** SELECT... statement are columns, then numeric affinity is used
//	** if either column has NUMERIC or INTEGER affinity. If neither
//	** 'x' nor the SELECT... statement are columns, then numeric affinity
//	** is used.
//	*/
func _sqlite3CodeRhsOfIN(tls *libc.TLS, pParse uintptr, pExpr uintptr, iTab int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var addr, addrOnce, i, i1, nVal, r1, r2, rc, v1, v4 int32
	var p, pCopy, pE2, pEList, pItem, pKeyInfo, pLeft, pList, pSelect, v, v2, v3 uintptr
	var _ /* affinity at bp+28 */ int8
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrOnce, i, i1, nVal, p, pCopy, pE2, pEList, pItem, pKeyInfo, pLeft, pList, pSelect, r1, r2, rc, v, v1, v2, v3, v4
	addrOnce = 0          /* the LHS of the IN operator */
	pKeyInfo = uintptr(0) /* The prepared statement under construction */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* The evaluation of the IN must be repeated every time it
	 ** is encountered if any of the following is true:
	 **
	 **    *  The right-hand side is a correlated subquery
	 **    *  The right-hand side is an expression list containing variables
	 **    *  We are inside a trigger
	 **
	 ** If all of the above are false, then we can compute the RHS just once
	 ** and reuse it many names.
	 */
	if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_VarSelect)) != libc.Uint32FromInt32(0)) && (*TParse)(unsafe.Pointer(pParse)).FiSelfTab == 0 {
		/* Reuse of the RHS is allowed */
		/* If this routine has already been coded, but the previous code
		 ** might not have been invoked yet, so invoke it now as a subroutine.
		 */
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Subrtn)) != uint32(0) {
			addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
				_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+9471, libc.VaList(bp+40, (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FselId))
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*(*struct {
				FiAddr     int32
				FregReturn int32
			})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
				FiAddr     int32
				FregReturn int32
			})(unsafe.Pointer(pExpr + 44))).FiAddr)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), iTab, (*TExpr)(unsafe.Pointer(pExpr)).FiTable)
			_sqlite3VdbeJumpHere(tls, v, addrOnce)
			return
		}
		/* Begin coding the subroutine */
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_Subrtn))
		v2 = pParse + 44
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		(*(*struct {
			FiAddr     int32
			FregReturn int32
		})(unsafe.Pointer(pExpr + 44))).FregReturn = v1
		(*(*struct {
			FiAddr     int32
			FregReturn int32
		})(unsafe.Pointer(pExpr + 44))).FiAddr = _sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*(*struct {
			FiAddr     int32
			FregReturn int32
		})(unsafe.Pointer(pExpr + 44))).FregReturn) + int32(1)
		addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
	}
	/* Check to see if this is a vector IN operator */
	pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	nVal = _sqlite3ExprVectorSize(tls, pLeft)
	/* Construct the ephemeral table that will contain the content of
	 ** RHS of the IN operator.
	 */
	(*TExpr)(unsafe.Pointer(pExpr)).FiTable = iTab
	addr = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TExpr)(unsafe.Pointer(pExpr)).FiTable, nVal)
	pKeyInfo = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nVal, int32(1))
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		/* Case 1:     expr IN (SELECT ...)
		 **
		 ** Generate code to write the results of the select into the temporary
		 ** table allocated and opened above.
		 */
		pSelect = *(*uintptr)(unsafe.Pointer(pExpr + 20))
		pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
		if addrOnce != 0 {
			v3 = __ccgo_ts + 1672
		} else {
			v3 = __ccgo_ts + 9494
		}
		_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+9506, libc.VaList(bp+40, v3, (*TSelect)(unsafe.Pointer(pSelect)).FselId))
		/* If the LHS and RHS of the IN operator do not match, that
		 ** error will have been caught long before we reach this point. */
		if (*TExprList)(unsafe.Pointer(pEList)).FnExpr == nVal {
			_sqlite3SelectDestInit(tls, bp, int32(SRT_Set), iTab)
			(*(*TSelectDest)(unsafe.Pointer(bp))).FzAffSdst = _exprINAffinity(tls, pParse, pExpr)
			(*TSelect)(unsafe.Pointer(pSelect)).FiLimit = 0
			/* Caused by OOM in sqlite3KeyInfoAlloc() */
			pCopy = _sqlite3SelectDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSelect, 0)
			if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
				v4 = int32(1)
			} else {
				v4 = _sqlite3Select(tls, pParse, pCopy, bp)
			}
			rc = v4
			_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pCopy)
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*(*TSelectDest)(unsafe.Pointer(bp))).FzAffSdst)
			if rc != 0 {
				_sqlite3KeyInfoUnref(tls, pKeyInfo)
				return
			}
			/* OOM will cause exit after sqlite3Select() */
			i = 0
			for {
				if !(i < nVal) {
					break
				}
				p = _sqlite3VectorFieldSubexpr(tls, pLeft, i)
				*(*uintptr)(unsafe.Pointer(pKeyInfo + 20 + uintptr(i)*4)) = _sqlite3BinaryCompareCollSeq(tls, pParse, p, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr)
				goto _5
			_5:
				;
				i++
			}
		}
	} else {
		if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != uintptr(0) {
			pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
			*(*int8)(unsafe.Pointer(bp + 28)) = _sqlite3ExprAffinity(tls, pLeft)
			if int32(*(*int8)(unsafe.Pointer(bp + 28))) <= int32(SQLITE_AFF_NONE) {
				*(*int8)(unsafe.Pointer(bp + 28)) = int8(SQLITE_AFF_BLOB)
			} else {
				if int32(*(*int8)(unsafe.Pointer(bp + 28))) == int32(SQLITE_AFF_REAL) {
					*(*int8)(unsafe.Pointer(bp + 28)) = int8(SQLITE_AFF_NUMERIC)
				}
			}
			if pKeyInfo != 0 {
				*(*uintptr)(unsafe.Pointer(pKeyInfo + 20)) = _sqlite3ExprCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
			}
			/* Loop through each expression in <exprlist>. */
			r1 = _sqlite3GetTempReg(tls, pParse)
			r2 = _sqlite3GetTempReg(tls, pParse)
			i1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
			pItem = pList + 8
			for {
				if !(i1 > 0) {
					break
				}
				pE2 = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
				/* If the expression is not constant then we will need to
				 ** disable the test that was generated above that makes sure
				 ** this code only executes once.  Because for a non-constant
				 ** expression we need to rerun this code each time.
				 */
				if addrOnce != 0 && !(_sqlite3ExprIsConstant(tls, pParse, pE2) != 0) {
					_sqlite3VdbeChangeToNoop(tls, v, addrOnce-int32(1))
					_sqlite3VdbeChangeToNoop(tls, v, addrOnce)
					*(*Tu32)(unsafe.Pointer(pExpr + 4)) &= uint32(^libc.Int32FromInt32(EP_Subrtn))
					addrOnce = 0
				}
				/* Evaluate the expression and insert it into the temp table */
				_sqlite3ExprCode(tls, pParse, pE2, r1)
				_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), r1, int32(1), r2, bp+28, int32(1))
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iTab, r2, r1, int32(1))
				goto _6
			_6:
				;
				i1--
				pItem += 20
			}
			_sqlite3ReleaseTempReg(tls, pParse, r1)
			_sqlite3ReleaseTempReg(tls, pParse, r2)
		}
	}
	if pKeyInfo != 0 {
		_sqlite3VdbeChangeP4(tls, v, addr, pKeyInfo, -int32(8))
	}
	if addrOnce != 0 {
		_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iTab)
		_sqlite3VdbeJumpHere(tls, v, addrOnce)
		/* Subroutine return */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*(*struct {
			FiAddr     int32
			FregReturn int32
		})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
			FiAddr     int32
			FregReturn int32
		})(unsafe.Pointer(pExpr + 44))).FiAddr, int32(1))
		_sqlite3ClearTempRegCache(tls, pParse)
	}
}

// C documentation
//
//	/*
//	** Generate code for scalar subqueries used as a subquery expression
//	** or EXISTS operator:
//	**
//	**     (SELECT a FROM b)          -- subquery
//	**     EXISTS (SELECT a FROM b)   -- EXISTS subquery
//	**
//	** The pExpr parameter is the SELECT or EXISTS operator to be coded.
//	**
//	** Return the register that holds the result.  For a multi-column SELECT,
//	** the result is stored in a contiguous array of registers and the
//	** return value is the register of the left-most result column.
//	** Return 0 if an error occurs.
//	*/
func _sqlite3CodeSubselect(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var addrOnce, nReg, rReg, v1, v4, v5 int32
	var db, pLimit, pSel, v, v2, v3 uintptr
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _ = addrOnce, db, nReg, pLimit, pSel, rReg, v, v1, v2, v3, v4, v5
	addrOnce = 0 /* Address of OP_Once at top of subroutine */
	rReg = 0     /* New limit expression */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return 0
	}
	pSel = *(*uintptr)(unsafe.Pointer(pExpr + 20))
	/* If this routine has already been coded, then invoke it as a
	 ** subroutine. */
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Subrtn)) != uint32(0) {
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+9525, libc.VaList(bp+40, (*TSelect)(unsafe.Pointer(pSel)).FselId))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*(*struct {
			FiAddr     int32
			FregReturn int32
		})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
			FiAddr     int32
			FregReturn int32
		})(unsafe.Pointer(pExpr + 44))).FiAddr)
		return (*TExpr)(unsafe.Pointer(pExpr)).FiTable
	}
	/* Begin coding the subroutine */
	*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_Subrtn))
	v2 = pParse + 44
	*(*int32)(unsafe.Pointer(v2))++
	v1 = *(*int32)(unsafe.Pointer(v2))
	(*(*struct {
		FiAddr     int32
		FregReturn int32
	})(unsafe.Pointer(pExpr + 44))).FregReturn = v1
	(*(*struct {
		FiAddr     int32
		FregReturn int32
	})(unsafe.Pointer(pExpr + 44))).FiAddr = _sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*(*struct {
		FiAddr     int32
		FregReturn int32
	})(unsafe.Pointer(pExpr + 44))).FregReturn) + int32(1)
	/* The evaluation of the EXISTS/SELECT must be repeated every time it
	 ** is encountered if any of the following is true:
	 **
	 **    *  The right-hand side is a correlated subquery
	 **    *  The right-hand side is an expression list containing variables
	 **    *  We are inside a trigger
	 **
	 ** If all of the above are false, then we can run this code just once
	 ** save the results, and reuse the same result on subsequent invocations.
	 */
	if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_VarSelect)) != libc.Uint32FromInt32(0)) {
		addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
	}
	/* For a SELECT, generate code to put the values for all columns of
	 ** the first row into an array of registers and return the index of
	 ** the first register.
	 **
	 ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
	 ** into a register and return that register number.
	 **
	 ** In both cases, the query is augmented with "LIMIT 1".  Any
	 ** preexisting limit is discarded in place of the new LIMIT 1.
	 */
	if addrOnce != 0 {
		v3 = __ccgo_ts + 1672
	} else {
		v3 = __ccgo_ts + 9494
	}
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+9543, libc.VaList(bp+40, v3, (*TSelect)(unsafe.Pointer(pSel)).FselId))
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) {
		v4 = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpEList)).FnExpr
	} else {
		v4 = int32(1)
	}
	nReg = v4
	_sqlite3SelectDestInit(tls, bp, 0, (*TParse)(unsafe.Pointer(pParse)).FnMem+int32(1))
	*(*int32)(unsafe.Pointer(pParse + 44)) += nReg
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) {
		(*(*TSelectDest)(unsafe.Pointer(bp))).FeDest = uint8(SRT_Mem)
		(*(*TSelectDest)(unsafe.Pointer(bp))).FiSdst = (*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm
		(*(*TSelectDest)(unsafe.Pointer(bp))).FnSdst = nReg
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm, (*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm+nReg-int32(1))
	} else {
		(*(*TSelectDest)(unsafe.Pointer(bp))).FeDest = uint8(SRT_Exists)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm)
	}
	if (*TSelect)(unsafe.Pointer(pSel)).FpLimit != 0 {
		/* The subquery already has a limit.  If the pre-existing limit is X
		 ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		pLimit = _sqlite3Expr(tls, db, int32(TK_INTEGER), __ccgo_ts+1792)
		if pLimit != 0 {
			(*TExpr)(unsafe.Pointer(pLimit)).FaffExpr = int8(SQLITE_AFF_NUMERIC)
			pLimit = _sqlite3PExpr(tls, pParse, int32(TK_NE), _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpLimit)).FpLeft, 0), pLimit)
		}
		_sqlite3ExprDeferredDelete(tls, pParse, (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpLimit)).FpLeft)
		(*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpLimit)).FpLeft = pLimit
	} else {
		/* If there is no pre-existing limit add a limit of 1 */
		pLimit = _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_INTEGER), __ccgo_ts+9564)
		(*TSelect)(unsafe.Pointer(pSel)).FpLimit = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), pLimit, uintptr(0))
	}
	(*TSelect)(unsafe.Pointer(pSel)).FiLimit = 0
	if _sqlite3Select(tls, pParse, pSel, bp) != 0 {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = (*TExpr)(unsafe.Pointer(pExpr)).Fop
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_ERROR)
		return 0
	}
	v5 = (*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm
	rReg = v5
	(*TExpr)(unsafe.Pointer(pExpr)).FiTable = v5
	if addrOnce != 0 {
		_sqlite3VdbeJumpHere(tls, v, addrOnce)
	}
	/* Subroutine return */
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*(*struct {
		FiAddr     int32
		FregReturn int32
	})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
		FiAddr     int32
		FregReturn int32
	})(unsafe.Pointer(pExpr + 44))).FiAddr, int32(1))
	_sqlite3ClearTempRegCache(tls, pParse)
	return rReg
}

// C documentation
//
//	/*
//	** Expr pIn is an IN(...) expression. This function checks that the
//	** sub-select on the RHS of the IN() operator has the same number of
//	** columns as the vector on the LHS. Or, if the RHS of the IN() is not
//	** a sub-query, that the LHS is a vector of size 1.
//	*/
func _sqlite3ExprCheckIN(tls *libc.TLS, pParse uintptr, pIn uintptr) (r int32) {
	var nVector int32
	_ = nVector
	nVector = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pIn)).FpLeft)
	if (*TExpr)(unsafe.Pointer(pIn)).Fflags&uint32(EP_xIsSelect) != uint32(0) && !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
		if nVector != (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIn + 20)))).FpEList)).FnExpr {
			_sqlite3SubselectError(tls, pParse, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIn + 20)))).FpEList)).FnExpr, nVector)
			return int32(1)
		}
	} else {
		if nVector != int32(1) {
			_sqlite3VectorErrorMsg(tls, pParse, (*TExpr)(unsafe.Pointer(pIn)).FpLeft)
			return int32(1)
		}
	}
	return 0
}

// 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, v5, v6, v7 int32
	var aiMap, p, p1, pColl, pColl1, pLeft, pList, 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, r2, r3, rLhs, rLhsOrig, regCkNull, v, zAff, v1, v5, v6, v7
	*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp + 8)) = 0 /* Index to use */
	okConstFactor = (*TParse)(unsafe.Pointer(pParse)).FokConstFactor
	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(uint32(uint32(nVector))*(libc.Uint32FromInt64(4)+libc.Uint32FromInt64(1))+uint32(1)))
	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, uint32(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.  */
	(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = uint8(0)
	rLhsOrig = _exprCodeVector(tls, pParse, pLeft, bp+4)
	(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = okConstFactor
	i = 0
	for {
		if !(i < nVector && *(*int32)(unsafe.Pointer(aiMap + uintptr(i)*4)) == i) {
			break
		}
		goto _2
	_2:
		;
		i++
	} /* Are LHS fields reordered? */
	if i == nVector {
		/* LHS fields are not reordered */
		rLhs = rLhsOrig
	} else {
		/* Need to reorder the LHS fields according to aiMap */
		rLhs = _sqlite3GetTempRange(tls, pParse, nVector)
		i = 0
		for {
			if !(i < nVector) {
				break
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), rLhsOrig+i, rLhs+*(*int32)(unsafe.Pointer(aiMap + uintptr(i)*4)), 0)
			goto _3
		_3:
			;
			i++
		}
	}
	/* 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 + 20))
		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)*20))).FpExpr, bp+12)
			if regCkNull != 0 && _sqlite3ExprCanBeNull(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ii)*20))).FpExpr) != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_BitAnd), regCkNull, r2, regCkNull)
			}
			_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 12)))
			if ii < (*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1) || destIfNull != destIfFalse {
				if rLhs != r2 {
					v5 = int32(OP_Eq)
				} else {
					v5 = int32(OP_NotNull)
				}
				op = v5
				_sqlite3VdbeAddOp4(tls, v, op, rLhs, labelOk, r2, pColl, -int32(2))
				_sqlite3VdbeChangeP5(tls, v, uint16(*(*int8)(unsafe.Pointer(zAff))))
			} else {
				if rLhs != r2 {
					v6 = int32(OP_Ne)
				} else {
					v6 = int32(OP_IsNull)
				}
				op1 = v6
				_sqlite3VdbeAddOp4(tls, v, op1, rLhs, destIfFalse, r2, pColl, -int32(2))
				_sqlite3VdbeChangeP5(tls, v, uint16(int32(*(*int8)(unsafe.Pointer(zAff)))|int32(SQLITE_JUMPIFNULL)))
			}
			goto _4
		_4:
			;
			ii++
		}
		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
	}
	/* 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 {
		v7 = _sqlite3VdbeMakeLabel(tls, pParse)
		destStep6 = v7
		destStep2 = v7
	}
	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+i, destStep2)
		}
		goto _8
	_8:
		;
		i++
	}
	/* 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)(unsafe.Pointer(bp + 8)), destIfFalse, rLhs)
		addrTruthOp = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto)) /* Return True */
	} else {
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), rLhs, nVector, 0, zAff, nVector)
		if destIfFalse == destIfNull {
			/* Combine Step 3 and Step 5 into a single opcode */
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(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)(unsafe.Pointer(bp)) != 0 && nVector == int32(1) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(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)
		pColl1 = _sqlite3ExprCollSeq(tls, pParse, p1)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), *(*int32)(unsafe.Pointer(bp + 8)), i, r3)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Ne), rLhs+i, destNotNull, r3, pColl1, -int32(2))
		_sqlite3ReleaseTempReg(tls, pParse, r3)
		goto _9
	_9:
		;
		i++
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, destIfNull)
	if nVector > int32(1) {
		_sqlite3VdbeResolveLabel(tls, v, destNotNull)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), *(*int32)(unsafe.Pointer(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:
	;
	if rLhs != rLhsOrig {
		_sqlite3ReleaseTempReg(tls, pParse, rLhs)
	}
	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 an instruction that will put the floating point
//	** value described by z[0..n-1] into register iMem.
//	**
//	** The z[] string will probably not be zero-terminated.  But the
//	** z[n] character is guaranteed to be something that does not look
//	** like the continuation of the number.
//	*/
func _codeReal(tls *libc.TLS, v uintptr, z uintptr, negateFlag int32, iMem int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* value at bp+0 */ float64
	if z != uintptr(0) {
		_sqlite3AtoF(tls, z, bp, _sqlite3Strlen30(tls, z), uint8(SQLITE_UTF8))
		/* The new AtoF never returns NaN */
		if negateFlag != 0 {
			*(*float64)(unsafe.Pointer(bp)) = -*(*float64)(unsafe.Pointer(bp))
		}
		_sqlite3VdbeAddOp4Dup8(tls, v, int32(OP_Real), 0, iMem, 0, bp, -int32(12))
	}
}

// C documentation
//
//	/*
//	** Generate an instruction that will put the integer describe by
//	** text z[0..n-1] into register iMem.
//	**
//	** Expr.u.zToken is always UTF8 and zero-terminated.
//	*/
func _codeInteger(tls *libc.TLS, pParse uintptr, pExpr uintptr, negFlag int32, iMem int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var c, i int32
	var v, z, v1 uintptr
	var v2 int64
	var _ /* value at bp+0 */ Ti64
	_, _, _, _, _, _ = c, i, v, z, v1, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_IntValue) != 0 {
		i = *(*int32)(unsafe.Pointer(pExpr + 8))
		if negFlag != 0 {
			i = -i
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), i, iMem)
	} else {
		z = *(*uintptr)(unsafe.Pointer(pExpr + 8))
		c = _sqlite3DecOrHexToI64(tls, z, bp)
		if c == int32(3) && !(negFlag != 0) || c == int32(2) || negFlag != 0 && *(*Ti64)(unsafe.Pointer(bp)) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
			if Xsqlite3_strnicmp(tls, z, __ccgo_ts+9566, int32(2)) == 0 {
				if negFlag != 0 {
					v1 = __ccgo_ts + 6447
				} else {
					v1 = __ccgo_ts + 1672
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9569, libc.VaList(bp+16, v1, pExpr))
			} else {
				_codeReal(tls, v, z, negFlag, iMem)
			}
		} else {
			if negFlag != 0 {
				if c == int32(3) {
					v2 = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
				} else {
					v2 = -*(*Ti64)(unsafe.Pointer(bp))
				}
				*(*Ti64)(unsafe.Pointer(bp)) = v2
			}
			_sqlite3VdbeAddOp4Dup8(tls, v, int32(OP_Int64), 0, iMem, 0, bp, -int32(13))
		}
	}
}

// C documentation
//
//	/* Generate code that will load into register regOut a value that is
//	** appropriate for the iIdxCol-th column of index pIdx.
//	*/
func _sqlite3ExprCodeLoadIndexColumn(tls *libc.TLS, pParse uintptr, pIdx uintptr, iTabCur int32, iIdxCol int32, regOut int32) {
	var iTabCol Ti16
	_ = iTabCol
	iTabCol = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iIdxCol)*2))
	if int32(int32(iTabCol)) == -int32(2) {
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = iTabCur + int32(1)
		_sqlite3ExprCodeCopy(tls, pParse, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(iIdxCol)*20))).FpExpr, regOut)
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
	} else {
		_sqlite3ExprCodeGetColumnOfTable(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TIndex)(unsafe.Pointer(pIdx)).FpTable, iTabCur, int32(int32(iTabCol)), regOut)
	}
}

// C documentation
//
//	/*
//	** Generate code that will compute the value of generated column pCol
//	** and store the result in register regOut
//	*/
func _sqlite3ExprCodeGeneratedColumn(tls *libc.TLS, pParse uintptr, pTab uintptr, pCol uintptr, regOut int32) {
	var iAddr, nErr int32
	var v uintptr
	_, _, _ = iAddr, nErr, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	nErr = (*TParse)(unsafe.Pointer(pParse)).FnErr
	if (*TParse)(unsafe.Pointer(pParse)).FiSelfTab > 0 {
		iAddr = _sqlite3VdbeAddOp3(tls, v, int32(OP_IfNullRow), (*TParse)(unsafe.Pointer(pParse)).FiSelfTab-int32(1), 0, regOut)
	} else {
		iAddr = 0
	}
	_sqlite3ExprCodeCopy(tls, pParse, _sqlite3ColumnExpr(tls, pTab, pCol), regOut)
	if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) >= int32(SQLITE_AFF_TEXT) {
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), regOut, int32(1), 0, pCol+5, int32(1))
	}
	if iAddr != 0 {
		_sqlite3VdbeJumpHere(tls, v, iAddr)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr > nErr {
		(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FerrByteOffset = -int32(1)
	}
}

// C documentation
//
//	/*
//	** Generate code to extract the value of the iCol-th column of a table.
//	*/
func _sqlite3ExprCodeGetColumnOfTable(tls *libc.TLS, v uintptr, pTab uintptr, iTabCur int32, iCol int32, regOut int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var op, savedSelfTab, x int32
	var pCol, pParse, v1, p2, p3 uintptr
	_, _, _, _, _, _, _, _ = op, pCol, pParse, savedSelfTab, x, v1, p2, p3
	if iCol < 0 || iCol == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iTabCur, regOut)
	} else {
		if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			op = int32(OP_VColumn)
			x = iCol
		} else {
			v1 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12
			pCol = v1
			if int32((*TColumn)(unsafe.Pointer(v1)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
				pParse = _sqlite3VdbeParser(tls, v)
				if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_BUSY) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9596, libc.VaList(bp+8, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
				} else {
					savedSelfTab = (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
					p2 = pCol + 10
					*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(COLFLAG_BUSY))
					(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = iTabCur + int32(1)
					_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab, pCol, regOut)
					(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = savedSelfTab
					p3 = pCol + 10
					*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(COLFLAG_BUSY))
				}
				return
			} else {
				if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
					x = int32(_sqlite3TableColumnToIndex(tls, _sqlite3PrimaryKeyIndex(tls, pTab), int16(int16(iCol))))
					op = int32(OP_Column)
				} else {
					x = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(int16(iCol))))
					op = int32(OP_Column)
				}
			}
		}
		_sqlite3VdbeAddOp3(tls, v, op, iTabCur, x, regOut)
		_sqlite3ColumnDefault(tls, v, pTab, iCol, regOut)
	}
}

// C documentation
//
//	/*
//	** Generate code that will extract the iColumn-th column from
//	** table pTab and store the column value in register iReg.
//	**
//	** There must be an open cursor to pTab in iTable when this routine
//	** is called.  If iColumn<0 then code is generated that extracts the rowid.
//	*/
func _sqlite3ExprCodeGetColumn(tls *libc.TLS, pParse uintptr, pTab uintptr, iColumn int32, iTable int32, iReg int32, p5 Tu8) (r int32) {
	var pOp uintptr
	_ = pOp
	_sqlite3ExprCodeGetColumnOfTable(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, pTab, iTable, iColumn, iReg)
	if p5 != 0 {
		pOp = _sqlite3VdbeGetLastOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe)
		if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) {
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp5 = uint16(uint16(p5))
		}
		if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_VColumn) {
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp5 = uint16(int32(int32(p5)) & libc.Int32FromInt32(OPFLAG_NOCHNG))
		}
	}
	return iReg
}

// C documentation
//
//	/*
//	** Generate code to move content from registers iFrom...iFrom+nReg-1
//	** over to iTo..iTo+nReg-1.
//	*/
func _sqlite3ExprCodeMove(tls *libc.TLS, pParse uintptr, iFrom int32, iTo int32, nReg int32) {
	_sqlite3VdbeAddOp3(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Move), iFrom, iTo, nReg)
}

// C documentation
//
//	/*
//	** Convert a scalar expression node to a TK_REGISTER referencing
//	** register iReg.  The caller must ensure that iReg already contains
//	** the correct value for the expression.
//	*/
func _exprToRegister(tls *libc.TLS, pExpr uintptr, iReg int32) {
	var p uintptr
	_ = p
	p = _sqlite3ExprSkipCollateAndLikely(tls, pExpr)
	if p == uintptr(0) {
		return
	}
	(*TExpr)(unsafe.Pointer(p)).Fop2 = (*TExpr)(unsafe.Pointer(p)).Fop
	(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_REGISTER)
	(*TExpr)(unsafe.Pointer(p)).FiTable = iReg
	*(*Tu32)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(EP_Skip))
}

// C documentation
//
//	/*
//	** Evaluate an expression (either a vector or a scalar expression) and store
//	** the result in contiguous temporary registers.  Return the index of
//	** the first register used to store the result.
//	**
//	** If the returned result register is a temporary scalar, then also write
//	** that register number into *piFreeable.  If the returned result register
//	** is not a temporary or if the expression is a vector set *piFreeable
//	** to 0.
//	*/
func _exprCodeVector(tls *libc.TLS, pParse uintptr, p uintptr, piFreeable uintptr) (r int32) {
	var i, iResult, nResult int32
	_, _, _ = i, iResult, nResult
	nResult = _sqlite3ExprVectorSize(tls, p)
	if nResult == int32(1) {
		iResult = _sqlite3ExprCodeTemp(tls, pParse, p, piFreeable)
	} else {
		*(*int32)(unsafe.Pointer(piFreeable)) = 0
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_SELECT) {
			iResult = _sqlite3CodeSubselect(tls, pParse, p)
		} else {
			iResult = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			*(*int32)(unsafe.Pointer(pParse + 44)) += nResult
			i = 0
			for {
				if !(i < nResult) {
					break
				}
				_sqlite3ExprCodeFactorable(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)) + 8 + uintptr(i)*20))).FpExpr, i+iResult)
				goto _1
			_1:
				;
				i++
			}
		}
	}
	return iResult
}

// C documentation
//
//	/*
//	** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5)
//	** so that a subsequent copy will not be merged into this one.
//	*/
func _setDoNotMergeFlagOnCopy(tls *libc.TLS, v uintptr) {
	if int32((*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetLastOp(tls, v))).Fopcode) == int32(OP_Copy) {
		_sqlite3VdbeChangeP5(tls, v, uint16(1)) /* Tag trailing OP_Copy as not mergeable */
	}
}

// C documentation
//
//	/*
//	** Generate code to implement special SQL functions that are implemented
//	** in-line rather than by using the usual callbacks.
//	*/
func _exprCodeInlineFunction(tls *libc.TLS, pParse uintptr, pFarg uintptr, iFuncId int32, target int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aff int8
	var azAff [6]uintptr
	var endCoalesce, i, nFarg int32
	var pA1, pArg, v, v2 uintptr
	var _ /* caseExpr at bp+0 */ TExpr
	_, _, _, _, _, _, _, _, _ = aff, azAff, endCoalesce, i, nFarg, pA1, pArg, v, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	nFarg = (*TExprList)(unsafe.Pointer(pFarg)).FnExpr
	/* All in-line functions have at least one argument */
	switch iFuncId {
	case INLINEFUNC_coalesce:
		/* Attempt a direct implementation of the built-in COALESCE() and
		 ** IFNULL() functions.  This avoids unnecessary evaluation of
		 ** arguments past the first non-NULL argument.
		 */
		endCoalesce = _sqlite3VdbeMakeLabel(tls, pParse)
		_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, target)
		i = int32(1)
		for {
			if !(i < nFarg) {
				break
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), target, endCoalesce)
			_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + uintptr(i)*20))).FpExpr, target)
			goto _1
		_1:
			;
			i++
		}
		_setDoNotMergeFlagOnCopy(tls, v)
		_sqlite3VdbeResolveLabel(tls, v, endCoalesce)
	case int32(INLINEFUNC_iif):
		libc.Xmemset(tls, bp, 0, uint32(52))
		(*(*TExpr)(unsafe.Pointer(bp))).Fop = uint8(TK_CASE)
		*(*uintptr)(unsafe.Pointer(bp + 20)) = pFarg
		return _sqlite3ExprCodeTarget(tls, pParse, bp, target)
	case int32(INLINEFUNC_sqlite_offset):
		pArg = (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pArg)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pArg)).FiTable >= 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Offset), (*TExpr)(unsafe.Pointer(pArg)).FiTable, int32((*TExpr)(unsafe.Pointer(pArg)).FiColumn), target)
		} else {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
		}
	default:
		/* The UNLIKELY() function is a no-op.  The result is the value
		 ** of the first argument.
		 */
		target = _sqlite3ExprCodeTarget(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, target)
		break
		/***********************************************************************
		 ** Test-only SQL functions that are only usable if enabled
		 ** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
		 */
		fallthrough
	case int32(INLINEFUNC_expr_compare):
		/* Compare two expressions using sqlite3ExprCompare() */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).FpExpr, -int32(1)), target)
	case int32(INLINEFUNC_expr_implies_expr):
		/* Compare two expressions using sqlite3ExprImpliesExpr() */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprImpliesExpr(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).FpExpr, -int32(1)), target)
	case int32(INLINEFUNC_implies_nonnull_row):
		pA1 = (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pA1)).Fop) == int32(TK_COLUMN) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprImpliesNonNullRow(tls, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, (*TExpr)(unsafe.Pointer(pA1)).FiTable, int32(1)), target)
		} else {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
		}
	case int32(INLINEFUNC_affinity):
		/* The AFFINITY() function evaluates to a string that describes
		 ** the type affinity of the argument.  This is used for testing of
		 ** the SQLite type logic.
		 */
		azAff = [6]uintptr{
			0: __ccgo_ts + 9626,
			1: __ccgo_ts + 9631,
			2: __ccgo_ts + 9636,
			3: __ccgo_ts + 7679,
			4: __ccgo_ts + 7674,
			5: __ccgo_ts + 9644,
		}
		aff = _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)
		if int32(int32(aff)) <= int32(SQLITE_AFF_NONE) {
			v2 = __ccgo_ts + 9652
		} else {
			v2 = azAff[int32(int32(aff))-int32(SQLITE_AFF_BLOB)]
		}
		_sqlite3VdbeLoadString(tls, v, target, v2)
		break
	}
	return target
}

// C documentation
//
//	/*
//	** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr.
//	** If it is, then resolve the expression by reading from the index and
//	** return the register into which the value has been read.  If pExpr is
//	** not an indexed expression, then return negative.
//	*/
func _sqlite3IndexedExprLookup(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) (r int32) {
	var addr, iDataCur int32
	var exprAff Tu8
	var p, v uintptr
	_, _, _, _, _ = addr, exprAff, iDataCur, p, v
	p = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
	for {
		if !(p != 0) {
			break
		}
		iDataCur = (*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur
		if iDataCur < 0 {
			goto _1
		}
		if (*TParse)(unsafe.Pointer(pParse)).FiSelfTab != 0 {
			if (*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur != (*TParse)(unsafe.Pointer(pParse)).FiSelfTab-int32(1) {
				goto _1
			}
			iDataCur = -int32(1)
		}
		if _sqlite3ExprCompare(tls, uintptr(0), pExpr, (*TIndexedExpr)(unsafe.Pointer(p)).FpExpr, iDataCur) != 0 {
			goto _1
		}
		exprAff = uint8(_sqlite3ExprAffinity(tls, pExpr))
		if int32(int32(exprAff)) <= int32(SQLITE_AFF_BLOB) && int32((*TIndexedExpr)(unsafe.Pointer(p)).Faff) != int32(SQLITE_AFF_BLOB) || int32(int32(exprAff)) == int32(SQLITE_AFF_TEXT) && int32((*TIndexedExpr)(unsafe.Pointer(p)).Faff) != int32(SQLITE_AFF_TEXT) || int32(int32(exprAff)) >= int32(SQLITE_AFF_NUMERIC) && int32((*TIndexedExpr)(unsafe.Pointer(p)).Faff) != int32(SQLITE_AFF_NUMERIC) {
			/* Affinity mismatch on a generated column */
			goto _1
		}
		v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
		if (*TIndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow != 0 {
			/* If the index is on a NULL row due to an outer join, then we
			 ** cannot extract the value from the index.  The value must be
			 ** computed using the original expression. */
			addr = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_IfNullRow), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur, addr+int32(3), target)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur, (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol, target)
			_sqlite3VdbeGoto(tls, v, 0)
			p = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
			(*TParse)(unsafe.Pointer(pParse)).FpIdxEpr = uintptr(0)
			_sqlite3ExprCode(tls, pParse, pExpr, target)
			(*TParse)(unsafe.Pointer(pParse)).FpIdxEpr = p
			_sqlite3VdbeJumpHere(tls, v, addr+int32(2))
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur, (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol, target)
		}
		return target
		goto _1
	_1:
		;
		p = (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext
	}
	return -int32(1) /* Not found */
}

// C documentation
//
//	/*
//	** Expresion pExpr is guaranteed to be a TK_COLUMN or equivalent. This
//	** function checks the Parse.pIdxPartExpr list to see if this column
//	** can be replaced with a constant value. If so, it generates code to
//	** put the constant value in a register (ideally, but not necessarily,
//	** register iTarget) and returns the register number.
//	**
//	** Or, if the TK_COLUMN cannot be replaced by a constant, zero is
//	** returned.
//	*/
func _exprPartidxExprLookup(tls *libc.TLS, pParse uintptr, pExpr uintptr, iTarget int32) (r int32) {
	var addr, ret int32
	var p, v uintptr
	_, _, _, _ = addr, p, ret, v
	p = (*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr
	for {
		if !(p != 0) {
			break
		}
		if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) == (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur {
			v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
			addr = 0
			if (*TIndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow != 0 {
				addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNullRow), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur)
			}
			ret = _sqlite3ExprCodeTarget(tls, pParse, (*TIndexedExpr)(unsafe.Pointer(p)).FpExpr, iTarget)
			_sqlite3VdbeAddOp4(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Affinity), ret, int32(1), 0, p+17, int32(1))
			if addr != 0 {
				_sqlite3VdbeJumpHere(tls, v, addr)
				_sqlite3VdbeChangeP3(tls, v, addr, ret)
			}
			return ret
		}
		goto _1
	_1:
		;
		p = (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext
	}
	return 0
}

// 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(144)
	defer tls.Free(144)
	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, v12, p3, p4 uintptr
	var addr, addrINR, aff, bNormal, destIfFalse, destIfNull, endLabel, i, i1, iCol, iCol1, iReg, iSrc, iTab, inReg, isTrue, n, n1, nCol, nExpr, nFarg, nextCase, op, p1, p5, r1, r2, v1, v10, v14, v5, v7, v8 int32
	var constMask Tu32
	var enc, exprOp, okConstFactor Tu8
	var v11, v2, v6 bool
	var _ /* opCompare at bp+60 */ TExpr
	var _ /* regFree1 at bp+0 */ int32
	var _ /* regFree2 at bp+4 */ int32
	var _ /* tempX at bp+8 */ TExpr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aListelem, addr, addrINR, 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, r1, r2, v, z, zBlob, zId, v1, v10, v11, v12, v14, v2, v5, v6, v7, v8, p3, p4
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* The opcode being coded */
	inReg = target                               /* Results stored in register inReg */
	*(*int32)(unsafe.Pointer(bp)) = 0            /* If non-zero free this temporary register */
	*(*int32)(unsafe.Pointer(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&uint32(libc.Int32FromInt32(EP_Leaf)) != libc.Uint32FromInt32(0)); v2 {
			v1 = _sqlite3IndexedExprLookup(tls, pParse, pExpr, target)
			r1 = v1
		}
		if v2 && v1 >= 0 {
			return r1
		} else {
			op = int32((*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)*16
		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, int32((*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn), target)
				if pTab == uintptr(0) {
					/* No comment added */
				} else {
					if int32((*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn) < 0 {
					} else {
						if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn)*12))).Faffinity) == int32(SQLITE_AFF_REAL) {
							_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
						}
					}
				}
				return target
			} else {
				if (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab == 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
				}
			}
		}
		fallthrough
	case int32(TK_COLUMN):
		iTab = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_FixedCol)) != uint32(0) {
			iReg = _sqlite3ExprCodeTarget(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
			aff = int32(_sqlite3TableColumnAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab, 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 = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
				if iCol < 0 {
					return -int32(1) - (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
				}
				pCol1 = (*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(iCol)*12
				iSrc = int32(_sqlite3TableColumnToStorage(tls, pTab1, int16(int16(iCol)))) - (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
				if int32((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					if int32((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_BUSY) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9596, libc.VaList(bp+120, (*TColumn)(unsafe.Pointer(pCol1)).FzCnName))
						return 0
					}
					p3 = pCol1 + 10
					*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(COLFLAG_BUSY))
					if int32((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_NOTAVAIL) != 0 {
						_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab1, pCol1, iSrc)
					}
					p4 = pCol1 + 10
					*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) & ^(libc.Int32FromInt32(COLFLAG_BUSY) | libc.Int32FromInt32(COLFLAG_NOTAVAIL)))
					return iSrc
				} else {
					if int32((*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 v6 = (*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr != 0; v6 {
				v5 = _exprPartidxExprLookup(tls, pParse, pExpr, target)
				r1 = v5
			}
			if v6 && 0 != v5 {
				return r1
			}
		}
		iReg = _sqlite3ExprCodeGetColumn(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab, 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
	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(6))
		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, int32(_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) {
			v7 = int32(TK_EQ)
		} else {
			v7 = int32(TK_NE)
		}
		op = v7
		p5 = int32(SQLITE_NULLEQ)
		/* fall-through */
		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
		if _sqlite3ExprIsVector(tls, pLeft) != 0 {
			_codeVectorCompare(tls, pParse, pExpr, target, uint8(uint8(op)), uint8(uint8(p5)))
		} else {
			r1 = _sqlite3ExprCodeTemp(tls, pParse, pLeft, bp)
			r2 = _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, r1, r2, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), p5, libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(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), r1, inReg, r2)
			}
		}
	case int32(TK_AND):
		fallthrough
	case int32(TK_OR):
		fallthrough
	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):
		r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
		r2 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
		_sqlite3VdbeAddOp3(tls, v, op, r2, r1, target)
	case int32(TK_UMINUS):
		pLeft1 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		if int32((*TExpr)(unsafe.Pointer(pLeft1)).Fop) == int32(TK_INTEGER) {
			_codeInteger(tls, pParse, pLeft1, int32(1), target)
			return target
		} else {
			if int32((*TExpr)(unsafe.Pointer(pLeft1)).Fop) == int32(TK_FLOAT) {
				_codeReal(tls, v, *(*uintptr)(unsafe.Pointer(pLeft1 + 8)), int32(1), target)
				return target
			} else {
				(*(*TExpr)(unsafe.Pointer(bp + 8))).Fop = uint8(TK_INTEGER)
				(*(*TExpr)(unsafe.Pointer(bp + 8))).Fflags = uint32(libc.Int32FromInt32(EP_IntValue) | libc.Int32FromInt32(EP_TokenOnly))
				*(*int32)(unsafe.Pointer(bp + 8 + 8)) = 0
				r1 = _sqlite3ExprCodeTemp(tls, pParse, bp+8, bp)
				r2 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp+4)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Subtract), r2, r1, target)
			}
		}
	case int32(TK_BITNOT):
		fallthrough
	case int32(TK_NOT):
		r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
		_sqlite3VdbeAddOp2(tls, v, op, r1, inReg)
	case int32(TK_TRUTH): /* IS TRUE or IS FALSE */
		r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
		isTrue = _sqlite3ExprTruthValue(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		bNormal = libc.BoolInt32(int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2) == int32(TK_IS))
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsTrue), r1, 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)
		r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
		addr = _sqlite3VdbeAddOp1(tls, v, op, r1)
		_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+9657, libc.VaList(bp+120, 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&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
			return (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FregResult
		}
		if (*TParse)(unsafe.Pointer(pParse)).FokConstFactor != 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 + 20))
		if pFarg != 0 {
			v8 = (*TExprList)(unsafe.Pointer(pFarg)).FnExpr
		} else {
			v8 = 0
		}
		nFarg = v8
		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+9684, libc.VaList(bp+120, pExpr))
			break
		}
		if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_INLINE) != uint32(0) && pFarg != uintptr(0) {
			return _exprCodeInlineFunction(tls, pParse, pFarg, int32((*TFuncDef)(unsafe.Pointer(pDef)).FpUserData), target)
		} else {
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(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)*20))).FpExpr) != 0 {
				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)*20))).FpExpr)
			}
			goto _9
		_9:
			;
			i++
		}
		if pFarg != 0 {
			if constMask != 0 {
				r1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
				*(*int32)(unsafe.Pointer(pParse + 44)) += nFarg
			} else {
				r1 = _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&uint32(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 int32(int32(exprOp)) == int32(TK_COLUMN) || int32(int32(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, r1, 0, uint8(SQLITE_ECEL_FACTOR))
		} else {
			r1 = 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&uint32(libc.Int32FromInt32(EP_InfixFunc)) != uint32(0) {
			pDef = _sqlite3VtabOverloadFunction(tls, db, pDef, nFarg, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).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, int32(int32(constMask)), r1, target, nFarg, pDef, int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2))
		if nFarg != 0 {
			if constMask == uint32(0) {
				_sqlite3ReleaseTempRange(tls, pParse, r1, 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 v11 = op == int32(TK_SELECT) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0); v11 {
				v10 = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpEList)).FnExpr
				nCol = v10
			}
			if v11 && v10 != 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 || int32((*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn) > int32((*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+9267, libc.VaList(bp+120, (*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&uint32(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 = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
		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(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 && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab2)).FaCol + uintptr(iCol1)*12))).Faffinity) == int32(SQLITE_AFF_REAL) {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
		}
	case int32(TK_VECTOR):
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8050, 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 = (*TParse)(unsafe.Pointer(pParse)).FokConstFactor
		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, int32((*(*TAggInfo_col)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo1)).FaCol + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)*16))).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.
		 */
		(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = uint8(0) /* note (1) above */
		_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
		(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = okConstFactor
		_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 + 20))
		aListelem = pEList + 8
		nExpr = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
		endLabel = _sqlite3VdbeMakeLabel(tls, pParse)
		v12 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		pX = v12
		if v12 != uintptr(0) {
			pDel = _sqlite3ExprDup(tls, db1, pX, 0)
			if (*Tsqlite3)(unsafe.Pointer(db1)).FmallocFailed != 0 {
				_sqlite3ExprDelete(tls, db1, pDel)
				break
			}
			_exprToRegister(tls, pDel, _exprCodeVector(tls, pParse, pDel, bp))
			libc.Xmemset(tls, bp+60, 0, uint32(52))
			(*(*TExpr)(unsafe.Pointer(bp + 60))).Fop = uint8(TK_EQ)
			(*(*TExpr)(unsafe.Pointer(bp + 60))).FpLeft = pDel
			pTest = bp + 60
			/* 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)(unsafe.Pointer(bp)) = 0
		}
		i1 = 0
		for {
			if !(i1 < nExpr-int32(1)) {
				break
			}
			if pX != 0 {
				(*(*TExpr)(unsafe.Pointer(bp + 60))).FpRight = (*(*TExprList_item)(unsafe.Pointer(aListelem + uintptr(i1)*20))).FpExpr
			} else {
				pTest = (*(*TExprList_item)(unsafe.Pointer(aListelem + uintptr(i1)*20))).FpExpr
			}
			nextCase = _sqlite3VdbeMakeLabel(tls, pParse)
			_sqlite3ExprIfFalse(tls, pParse, pTest, nextCase, int32(SQLITE_JUMPIFNULL))
			_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(aListelem + uintptr(i1+int32(1))*20))).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))*20))).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+9708, 0)
			return 0
		}
		if int32((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr) == int32(OE_Abort) {
			_sqlite3MayAbort(tls, pParse)
		}
		if int32((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr) == int32(OE_Ignore) {
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Halt), SQLITE_OK, int32(OE_Ignore), 0, *(*uintptr)(unsafe.Pointer(pExpr + 8)), 0)
		} else {
			if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
				v14 = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
			} else {
				v14 = int32(SQLITE_ERROR)
			}
			_sqlite3HaltConstraint(tls, pParse, v14, int32((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr), *(*uintptr)(unsafe.Pointer(pExpr + 8)), 0, uint8(0))
		}
		break
	}
	_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
	_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 4)))
	return inReg
}

var _zAff = [10]int8{'B', 0, 'C', 0, 'D', 0, 'E', 0, 'F'}

// 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, v4 int32
	var p, pItem, pItem1, v, v3, v5 uintptr
	_, _, _, _, _, _, _, _, _, _ = addr, i, p, pItem, pItem1, v, v2, v3, v4, v5
	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 + 8 + 4))&0x8>>3)) != 0 && _sqlite3ExprCompare(tls, uintptr(0), (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr, pExpr, -int32(1)) == 0 {
				return *(*int32)(unsafe.Pointer(pItem + 16))
			}
			goto _1
		_1:
			;
			pItem += 20
			i--
		}
	}
	pExpr = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
	if pExpr != uintptr(0) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_HasFunc)) != uint32(0) {
		v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
		addr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
		(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = uint8(0)
		if !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
			if regDest < 0 {
				v3 = pParse + 44
				*(*int32)(unsafe.Pointer(v3))++
				v2 = *(*int32)(unsafe.Pointer(v3))
				regDest = v2
			}
			_sqlite3ExprCode(tls, pParse, pExpr, regDest)
		}
		(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = uint8(1)
		_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))*20
			libc.SetBitFieldPtr16Uint32(pItem1+8+4, libc.BoolUint32(regDest < libc.Int32FromInt32(0)), 3, 0x8)
			if regDest < 0 {
				v5 = pParse + 44
				*(*int32)(unsafe.Pointer(v5))++
				v4 = *(*int32)(unsafe.Pointer(v5))
				regDest = v4
			}
			*(*int32)(unsafe.Pointer(pItem1 + 16)) = regDest
		}
		(*TParse)(unsafe.Pointer(pParse)).FpConstExpr = p
	}
	return regDest
}

// 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 (*TParse)(unsafe.Pointer(pParse)).FokConstFactor != 0 && pExpr != uintptr(0) && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_REGISTER) && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
		*(*int32)(unsafe.Pointer(pReg)) = 0
		r2 = _sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, -int32(1))
	} else {
		r1 = _sqlite3GetTempReg(tls, pParse)
		r2 = _sqlite3ExprCodeTarget(tls, pParse, pExpr, r1)
		if r2 == r1 {
			*(*int32)(unsafe.Pointer(pReg)) = r1
		} else {
			_sqlite3ReleaseTempReg(tls, pParse, r1)
			*(*int32)(unsafe.Pointer(pReg)) = 0
		}
	}
	return r2
}

// 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.
//	*/
func _sqlite3ExprCode(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) {
	var inReg int32
	var op Tu8
	var pX uintptr
	_, _, _ = inReg, op, pX
	if (*TParse)(unsafe.Pointer(pParse)).FpVdbe == uintptr(0) {
		return
	}
	inReg = _sqlite3ExprCodeTarget(tls, pParse, pExpr, target)
	if inReg != target {
		pX = _sqlite3ExprSkipCollateAndLikely(tls, pExpr)
		if pX != 0 && ((*TExpr)(unsafe.Pointer(pX)).Fflags&uint32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) || int32((*TExpr)(unsafe.Pointer(pX)).Fop) == int32(TK_REGISTER)) {
			op = uint8(OP_Copy)
		} else {
			op = uint8(OP_SCopy)
		}
		_sqlite3VdbeAddOp2(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(int32(op)), inReg, target)
	}
}

// C documentation
//
//	/*
//	** Make a transient copy of expression pExpr and then code it using
//	** sqlite3ExprCode().  This routine works just like sqlite3ExprCode()
//	** except that the input expression is guaranteed to be unchanged.
//	*/
func _sqlite3ExprCodeCopy(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
	if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		_sqlite3ExprCode(tls, pParse, pExpr, target)
	}
	_sqlite3ExprDelete(tls, db, pExpr)
}

// 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 (*TParse)(unsafe.Pointer(pParse)).FokConstFactor != 0 && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
		_sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, target)
	} else {
		_sqlite3ExprCodeCopy(tls, pParse, pExpr, target)
	}
}

// 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, v3 int32
	var pExpr, pItem, pOp, v, v5 uintptr
	var v4, v6 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = copyOp, i, inReg, j, n, pExpr, pItem, pOp, v, v1, v3, v4, v5, v6
	if int32(int32(flags))&int32(SQLITE_ECEL_DUP) != 0 {
		v1 = int32(OP_Copy)
	} else {
		v1 = int32(OP_SCopy)
	}
	copyOp = uint8(v1)
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* Never gets this far otherwise */
	n = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	if !((*TParse)(unsafe.Pointer(pParse)).FokConstFactor != 0) {
		flags = Tu8(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 = int32(int32(flags))&int32(SQLITE_ECEL_REF) != 0; v4 {
			v3 = int32((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem + 16))).FiOrderByCol)
			j = v3
		}
		if v4 && v3 > 0 {
			if int32(int32(flags))&int32(SQLITE_ECEL_OMITREF) != 0 {
				i--
				n--
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(int32(copyOp)), j+srcReg-int32(1), target+i)
			}
		} else {
			if int32(int32(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 v6 = int32(int32(copyOp)) == int32(OP_Copy); v6 {
						v5 = _sqlite3VdbeGetLastOp(tls, v)
						pOp = v5
					}
					if v6 && int32((*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 && int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fp5) == 0 {
						(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3++
					} else {
						_sqlite3VdbeAddOp2(tls, v, int32(int32(copyOp)), inReg, target+i)
					}
				}
			}
		}
		goto _2
	_2:
		;
		i++
		pItem += 20
	}
	return n
}

// C documentation
//
//	/*
//	** Generate code for a BETWEEN operator.
//	**
//	**    x BETWEEN y AND z
//	**
//	** The above is equivalent to
//	**
//	**    x>=y AND x<=z
//	**
//	** Code it as such, taking care to do the common subexpression
//	** elimination of x.
//	**
//	** The xJumpIf parameter determines details:
//	**
//	**    NULL:                   Store the boolean result in reg[dest]
//	**    sqlite3ExprIfTrue:      Jump to dest if true
//	**    sqlite3ExprIfFalse:     Jump to dest if false
//	**
//	** The jumpIfNull parameter is ignored if xJumpIf is NULL.
//	*/
func _exprCodeBetween(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, xJump uintptr, jumpIfNull int32) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var db, pDel uintptr
	var _ /* compLeft at bp+52 */ TExpr
	var _ /* compRight at bp+104 */ TExpr
	var _ /* exprAnd at bp+0 */ TExpr
	var _ /* regFree1 at bp+156 */ int32
	_, _ = db, pDel                         /* The  x<=z  term */
	*(*int32)(unsafe.Pointer(bp + 156)) = 0 /* Temporary use register */
	pDel = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	libc.Xmemset(tls, bp+52, 0, uint32(52))
	libc.Xmemset(tls, bp+104, 0, uint32(52))
	libc.Xmemset(tls, bp, 0, uint32(52))
	pDel = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, 0)
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		(*(*TExpr)(unsafe.Pointer(bp))).Fop = uint8(TK_AND)
		(*(*TExpr)(unsafe.Pointer(bp))).FpLeft = bp + 52
		(*(*TExpr)(unsafe.Pointer(bp))).FpRight = bp + 104
		(*(*TExpr)(unsafe.Pointer(bp + 52))).Fop = uint8(TK_GE)
		(*(*TExpr)(unsafe.Pointer(bp + 52))).FpLeft = pDel
		(*(*TExpr)(unsafe.Pointer(bp + 52))).FpRight = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr
		(*(*TExpr)(unsafe.Pointer(bp + 104))).Fop = uint8(TK_LE)
		(*(*TExpr)(unsafe.Pointer(bp + 104))).FpLeft = pDel
		(*(*TExpr)(unsafe.Pointer(bp + 104))).FpRight = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8 + 1*20))).FpExpr
		_exprToRegister(tls, pDel, _exprCodeVector(tls, pParse, pDel, bp+156))
		if xJump != 0 {
			(*(*func(*libc.TLS, uintptr, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{xJump})))(tls, pParse, bp, dest, jumpIfNull)
		} else {
			/* Mark the expression is being from the ON or USING clause of a join
			 ** so that the sqlite3ExprCodeTarget() routine will not attempt to move
			 ** it into the Parse.pConstExpr list.  We should use a new bit for this,
			 ** for clarity, but we are out of bits in the Expr.flags field so we
			 ** have to reuse the EP_OuterON bit.  Bummer. */
			*(*Tu32)(unsafe.Pointer(pDel + 4)) |= uint32(EP_OuterON)
			_sqlite3ExprCodeTarget(tls, pParse, bp, dest)
		}
		_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 156)))
	}
	_sqlite3ExprDelete(tls, db, pDel)
	/* Ensure adequate test coverage */
}

// C documentation
//
//	/*
//	** Generate code for a boolean expression such that a jump is made
//	** to the label "dest" if the expression is true but execution
//	** continues straight thru if the expression is false.
//	**
//	** If the expression evaluates to NULL (neither true nor false), then
//	** take the jump if the jumpIfNull flag is SQLITE_JUMPIFNULL.
//	**
//	** This code depends on the fact that certain token values (ex: TK_EQ)
//	** are the same as opcode values (ex: OP_Eq) that implement the corresponding
//	** operation.  Special comments in vdbe.c and the mkopcodeh.awk script in
//	** the make process cause these values to align.  Assert()s in the code
//	** below verify that the numbers are aligned correctly.
//	*/
func _sqlite3ExprIfTrue(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, jumpIfNull int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var d2, destIfFalse, destIfNull, isNot, isTrue, op, r1, r2, v19, v20, v21, v22 int32
	var pAlt, v uintptr
	var _ /* regFree1 at bp+0 */ int32
	var _ /* regFree2 at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = d2, destIfFalse, destIfNull, isNot, isTrue, op, pAlt, r1, r2, v, v19, v20, v21, v22
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	op = 0
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	if v == uintptr(0) {
		return
	} /* Existence of VDBE checked by caller */
	if pExpr == uintptr(0) {
		return
	} /* No way this can happen */
	op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop)
	switch op {
	case int32(TK_OR):
		goto _1
	case int32(TK_AND):
		goto _2
	case int32(TK_NOT):
		goto _3
	case int32(TK_TRUTH):
		goto _4
	case int32(TK_ISNOT):
		goto _5
	case int32(TK_IS):
		goto _6
	case int32(TK_EQ):
		goto _7
	case int32(TK_NE):
		goto _8
	case int32(TK_GE):
		goto _9
	case int32(TK_GT):
		goto _10
	case int32(TK_LE):
		goto _11
	case int32(TK_LT):
		goto _12
	case int32(TK_NOTNULL):
		goto _13
	case int32(TK_ISNULL):
		goto _14
	case int32(TK_BETWEEN):
		goto _15
	case int32(TK_IN):
		goto _16
	default:
		goto _17
	}
	goto _18
_2:
	;
_1:
	;
	pAlt = _sqlite3ExprSimplifiedAndOr(tls, pExpr)
	if pAlt != pExpr {
		_sqlite3ExprIfTrue(tls, pParse, pAlt, dest, jumpIfNull)
	} else {
		if op == int32(TK_AND) {
			d2 = _sqlite3VdbeMakeLabel(tls, pParse)
			_sqlite3ExprIfFalse(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, d2, jumpIfNull^int32(SQLITE_JUMPIFNULL))
			_sqlite3ExprIfTrue(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
			_sqlite3VdbeResolveLabel(tls, v, d2)
		} else {
			_sqlite3ExprIfTrue(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
			_sqlite3ExprIfTrue(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
		}
	}
	goto _18
_3:
	;
	_sqlite3ExprIfFalse(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
	goto _18
_4:
	; /* IS TRUE or IS NOT TRUE */
	isNot = libc.BoolInt32(int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2) == int32(TK_ISNOT))
	isTrue = _sqlite3ExprTruthValue(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
	if isTrue^isNot != 0 {
		if isNot != 0 {
			v19 = int32(SQLITE_JUMPIFNULL)
		} else {
			v19 = 0
		}
		_sqlite3ExprIfTrue(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, v19)
	} else {
		if isNot != 0 {
			v20 = int32(SQLITE_JUMPIFNULL)
		} else {
			v20 = 0
		}
		_sqlite3ExprIfFalse(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, v20)
	}
	goto _18
_6:
	;
_5:
	;
	if op == int32(TK_IS) {
		v21 = int32(TK_EQ)
	} else {
		v21 = int32(TK_NE)
	}
	op = v21
	jumpIfNull = int32(SQLITE_NULLEQ)
_12:
	;
_11:
	;
_10:
	;
_9:
	;
_8:
	;
_7:
	;
	if _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft) != 0 {
		goto default_expr
	}
	r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	r2 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
	_codeCompare(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, op, r1, r2, dest, jumpIfNull, libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Commuted)) != uint32(0)))
	goto _18
_14:
	;
_13:
	;
	r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	_sqlite3VdbeTypeofColumn(tls, v, r1)
	_sqlite3VdbeAddOp2(tls, v, op, r1, dest)
	goto _18
_15:
	;
	_exprCodeBetween(tls, pParse, pExpr, dest, __ccgo_fp(_sqlite3ExprIfTrue), jumpIfNull)
	goto _18
_16:
	;
	destIfFalse = _sqlite3VdbeMakeLabel(tls, pParse)
	if jumpIfNull != 0 {
		v22 = dest
	} else {
		v22 = destIfFalse
	}
	destIfNull = v22
	_sqlite3ExprCodeIN(tls, pParse, pExpr, destIfFalse, destIfNull)
	_sqlite3VdbeGoto(tls, v, dest)
	_sqlite3VdbeResolveLabel(tls, v, destIfFalse)
	goto _18
_17:
	;
	goto default_expr
default_expr:
	;
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsTrue)) == uint32(EP_IsTrue) {
		_sqlite3VdbeGoto(tls, v, dest)
	} else {
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsFalse)) == uint32(EP_IsFalse) {
			/* No-op */
		} else {
			r1 = _sqlite3ExprCodeTemp(tls, pParse, pExpr, bp)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_If), r1, dest, libc.BoolInt32(jumpIfNull != 0))
		}
	}
	goto _18
_18:
	;
	_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
	_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 4)))
}

// C documentation
//
//	/*
//	** Generate code for a boolean expression such that a jump is made
//	** to the label "dest" if the expression is false but execution
//	** continues straight thru if the expression is true.
//	**
//	** If the expression evaluates to NULL (neither true nor false) then
//	** jump if jumpIfNull is SQLITE_JUMPIFNULL or fall through if jumpIfNull
//	** is 0.
//	*/
func _sqlite3ExprIfFalse(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, jumpIfNull int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var d2, destIfNull, isNot, isTrue, op, r1, r2, v19, v20, v21 int32
	var pAlt, v uintptr
	var _ /* regFree1 at bp+0 */ int32
	var _ /* regFree2 at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _ = d2, destIfNull, isNot, isTrue, op, pAlt, r1, r2, v, v19, v20, v21
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	op = 0
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	if v == uintptr(0) {
		return
	} /* Existence of VDBE checked by caller */
	if pExpr == uintptr(0) {
		return
	}
	/* The value of pExpr->op and op are related as follows:
	 **
	 **       pExpr->op            op
	 **       ---------          ----------
	 **       TK_ISNULL          OP_NotNull
	 **       TK_NOTNULL         OP_IsNull
	 **       TK_NE              OP_Eq
	 **       TK_EQ              OP_Ne
	 **       TK_GT              OP_Le
	 **       TK_LE              OP_Gt
	 **       TK_GE              OP_Lt
	 **       TK_LT              OP_Ge
	 **
	 ** For other values of pExpr->op, op is undefined and unused.
	 ** The value of TK_ and OP_ constants are arranged such that we
	 ** can compute the mapping above using the following expression.
	 ** Assert()s verify that the computation is correct.
	 */
	op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) + libc.Int32FromInt32(TK_ISNULL)&libc.Int32FromInt32(1) ^ int32(1) - libc.Int32FromInt32(TK_ISNULL)&libc.Int32FromInt32(1)
	/* Verify correct alignment of TK_ and OP_ constants
	 */
	switch int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	case int32(TK_OR):
		goto _1
	case int32(TK_AND):
		goto _2
	case int32(TK_NOT):
		goto _3
	case int32(TK_TRUTH):
		goto _4
	case int32(TK_ISNOT):
		goto _5
	case int32(TK_IS):
		goto _6
	case int32(TK_EQ):
		goto _7
	case int32(TK_NE):
		goto _8
	case int32(TK_GE):
		goto _9
	case int32(TK_GT):
		goto _10
	case int32(TK_LE):
		goto _11
	case int32(TK_LT):
		goto _12
	case int32(TK_NOTNULL):
		goto _13
	case int32(TK_ISNULL):
		goto _14
	case int32(TK_BETWEEN):
		goto _15
	case int32(TK_IN):
		goto _16
	default:
		goto _17
	}
	goto _18
_2:
	;
_1:
	;
	pAlt = _sqlite3ExprSimplifiedAndOr(tls, pExpr)
	if pAlt != pExpr {
		_sqlite3ExprIfFalse(tls, pParse, pAlt, dest, jumpIfNull)
	} else {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AND) {
			_sqlite3ExprIfFalse(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
			_sqlite3ExprIfFalse(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
		} else {
			d2 = _sqlite3VdbeMakeLabel(tls, pParse)
			_sqlite3ExprIfTrue(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, d2, jumpIfNull^int32(SQLITE_JUMPIFNULL))
			_sqlite3ExprIfFalse(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
			_sqlite3VdbeResolveLabel(tls, v, d2)
		}
	}
	goto _18
_3:
	;
	_sqlite3ExprIfTrue(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
	goto _18
_4:
	; /* IS TRUE or IS NOT TRUE */
	isNot = libc.BoolInt32(int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2) == int32(TK_ISNOT))
	isTrue = _sqlite3ExprTruthValue(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
	if isTrue^isNot != 0 {
		/* IS TRUE and IS NOT FALSE */
		if isNot != 0 {
			v19 = 0
		} else {
			v19 = int32(SQLITE_JUMPIFNULL)
		}
		_sqlite3ExprIfFalse(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, v19)
	} else {
		/* IS FALSE and IS NOT TRUE */
		if isNot != 0 {
			v20 = 0
		} else {
			v20 = int32(SQLITE_JUMPIFNULL)
		}
		_sqlite3ExprIfTrue(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, dest, v20)
	}
	goto _18
_6:
	;
_5:
	;
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IS) {
		v21 = int32(TK_NE)
	} else {
		v21 = int32(TK_EQ)
	}
	op = v21
	jumpIfNull = int32(SQLITE_NULLEQ)
_12:
	;
_11:
	;
_10:
	;
_9:
	;
_8:
	;
_7:
	;
	if _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft) != 0 {
		goto default_expr
	}
	r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	r2 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
	_codeCompare(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, op, r1, r2, dest, jumpIfNull, libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Commuted)) != uint32(0)))
	goto _18
_14:
	;
_13:
	;
	r1 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	_sqlite3VdbeTypeofColumn(tls, v, r1)
	_sqlite3VdbeAddOp2(tls, v, op, r1, dest)
	goto _18
_15:
	;
	_exprCodeBetween(tls, pParse, pExpr, dest, __ccgo_fp(_sqlite3ExprIfFalse), jumpIfNull)
	goto _18
_16:
	;
	if jumpIfNull != 0 {
		_sqlite3ExprCodeIN(tls, pParse, pExpr, dest, dest)
	} else {
		destIfNull = _sqlite3VdbeMakeLabel(tls, pParse)
		_sqlite3ExprCodeIN(tls, pParse, pExpr, dest, destIfNull)
		_sqlite3VdbeResolveLabel(tls, v, destIfNull)
	}
	goto _18
_17:
	;
	goto default_expr
default_expr:
	;
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsFalse)) == uint32(EP_IsFalse) {
		_sqlite3VdbeGoto(tls, v, dest)
	} else {
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsTrue)) == uint32(EP_IsTrue) {
			/* no-op */
		} else {
			r1 = _sqlite3ExprCodeTemp(tls, pParse, pExpr, bp)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_IfNot), r1, dest, libc.BoolInt32(jumpIfNull != 0))
		}
	}
	goto _18
_18:
	;
	_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
	_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 4)))
}

// C documentation
//
//	/*
//	** Like sqlite3ExprIfFalse() except that a copy is made of pExpr before
//	** code generation, and that copy is deleted after code generation. This
//	** ensures that the original pExpr is unchanged.
//	*/
func _sqlite3ExprIfFalseDup(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, jumpIfNull int32) {
	var db, pCopy uintptr
	_, _ = db, pCopy
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pCopy = _sqlite3ExprDup(tls, db, pExpr, 0)
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		_sqlite3ExprIfFalse(tls, pParse, pCopy, dest, jumpIfNull)
	}
	_sqlite3ExprDelete(tls, db, pCopy)
}

// C documentation
//
//	/*
//	** Expression pVar is guaranteed to be an SQL variable. pExpr may be any
//	** type of expression.
//	**
//	** If pExpr is a simple SQL value - an integer, real, string, blob
//	** or NULL value - then the VDBE currently being prepared is configured
//	** to re-prepare each time a new value is bound to variable pVar.
//	**
//	** Additionally, if pExpr is a simple SQL value and the value is the
//	** same as that currently bound to variable pVar, non-zero is returned.
//	** Otherwise, if the values are not the same or if pExpr is not a simple
//	** SQL value, zero is returned.
//	*/
func _exprCompareVariable(tls *libc.TLS, pParse uintptr, pVar uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iVar, res int32
	var pL uintptr
	var _ /* pR at bp+0 */ uintptr
	_, _, _ = iVar, pL, res
	res = 0
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	_sqlite3ValueFromExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, uint8(SQLITE_UTF8), uint8(SQLITE_AFF_BLOB), bp)
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		iVar = int32((*TExpr)(unsafe.Pointer(pVar)).FiColumn)
		_sqlite3VdbeSetVarmask(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, iVar)
		pL = _sqlite3VdbeGetBoundValue(tls, (*TParse)(unsafe.Pointer(pParse)).FpReprepare, iVar, uint8(SQLITE_AFF_BLOB))
		if pL != 0 {
			if Xsqlite3_value_type(tls, pL) == int32(SQLITE_TEXT) {
				Xsqlite3_value_text(tls, pL) /* Make sure the encoding is UTF-8 */
			}
			res = libc.BoolInt32(0 == _sqlite3MemCompare(tls, pL, *(*uintptr)(unsafe.Pointer(bp)), uintptr(0)))
		}
		_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
		_sqlite3ValueFree(tls, pL)
	}
	return res
}

// C documentation
//
//	/*
//	** Do a deep comparison of two expression trees.  Return 0 if the two
//	** expressions are completely identical.  Return 1 if they differ only
//	** by a COLLATE operator at the top level.  Return 2 if there are differences
//	** other than the top-level COLLATE operator.
//	**
//	** If any subelement of pB has Expr.iTable==(-1) then it is allowed
//	** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
//	**
//	** The pA side might be using TK_REGISTER.  If that is the case and pB is
//	** not using TK_REGISTER but is otherwise equivalent, then still return 0.
//	**
//	** Sometimes this routine will return 2 even if the two expressions
//	** really are equivalent.  If we cannot prove that the expressions are
//	** identical, we return 2 just to be safe.  So if this routine
//	** returns 2, then you do not really know for certain if the two
//	** expressions are the same.  But if you get a 0 or 1 return, then you
//	** can be sure the expressions are the same.  In the places where
//	** this routine is used, it does not hurt to get an extra 2 - that
//	** just might result in some slightly slower code.  But returning
//	** an incorrect 0 or 1 could lead to a malfunction.
//	**
//	** If pParse is not NULL then TK_VARIABLE terms in pA with bindings in
//	** pParse->pReprepare can be matched against literals in pB.  The
//	** pParse->pVdbe->expmask bitmask is updated for each variable referenced.
//	** If pParse is NULL (the normal case) then any TK_VARIABLE term in
//	** Argument pParse should normally be NULL. If it is not NULL and pA or
//	** pB causes a return value of 2.
//	*/
func _sqlite3ExprCompare(tls *libc.TLS, pParse uintptr, pA uintptr, pB uintptr, iTab int32) (r int32) {
	var combinedFlags Tu32
	var v1 int32
	_, _ = combinedFlags, v1
	if pA == uintptr(0) || pB == uintptr(0) {
		if pB == pA {
			v1 = 0
		} else {
			v1 = int32(2)
		}
		return v1
	}
	if pParse != 0 && int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_VARIABLE) && _exprCompareVariable(tls, pParse, pA, pB) != 0 {
		return 0
	}
	combinedFlags = (*TExpr)(unsafe.Pointer(pA)).Fflags | (*TExpr)(unsafe.Pointer(pB)).Fflags
	if combinedFlags&uint32(EP_IntValue) != 0 {
		if (*TExpr)(unsafe.Pointer(pA)).Fflags&(*TExpr)(unsafe.Pointer(pB)).Fflags&uint32(EP_IntValue) != uint32(0) && *(*int32)(unsafe.Pointer(pA + 8)) == *(*int32)(unsafe.Pointer(pB + 8)) {
			return 0
		}
		return int32(2)
	}
	if int32((*TExpr)(unsafe.Pointer(pA)).Fop) != int32((*TExpr)(unsafe.Pointer(pB)).Fop) || int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_RAISE) {
		if int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_COLLATE) && _sqlite3ExprCompare(tls, pParse, (*TExpr)(unsafe.Pointer(pA)).FpLeft, pB, iTab) < int32(2) {
			return int32(1)
		}
		if int32((*TExpr)(unsafe.Pointer(pB)).Fop) == int32(TK_COLLATE) && _sqlite3ExprCompare(tls, pParse, pA, (*TExpr)(unsafe.Pointer(pB)).FpLeft, iTab) < int32(2) {
			return int32(1)
		}
		if int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_AGG_COLUMN) && int32((*TExpr)(unsafe.Pointer(pB)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pB)).FiTable < 0 && (*TExpr)(unsafe.Pointer(pA)).FiTable == iTab {
			/* fall through */
		} else {
			return int32(2)
		}
	}
	if *(*uintptr)(unsafe.Pointer(pA + 8)) != 0 {
		if int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_FUNCTION) || int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_AGG_FUNCTION) {
			if _sqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer(pA + 8)), *(*uintptr)(unsafe.Pointer(pB + 8))) != 0 {
				return int32(2)
			}
			if libc.BoolInt32((*TExpr)(unsafe.Pointer(pA)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0)) != libc.BoolInt32((*TExpr)(unsafe.Pointer(pB)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0)) {
				return int32(2)
			}
			if (*TExpr)(unsafe.Pointer(pA)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
				if _sqlite3WindowCompare(tls, pParse, *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pA)).Fy)), *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pB)).Fy)), int32(1)) != 0 {
					return int32(2)
				}
			}
		} else {
			if int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_NULL) {
				return 0
			} else {
				if int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_COLLATE) {
					if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(pA + 8)), *(*uintptr)(unsafe.Pointer(pB + 8))) != 0 {
						return int32(2)
					}
				} else {
					if *(*uintptr)(unsafe.Pointer(pB + 8)) != uintptr(0) && int32((*TExpr)(unsafe.Pointer(pA)).Fop) != int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(pA)).Fop) != int32(TK_AGG_COLUMN) && libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(pA + 8)), *(*uintptr)(unsafe.Pointer(pB + 8))) != 0 {
						return int32(2)
					}
				}
			}
		}
	}
	if (*TExpr)(unsafe.Pointer(pA)).Fflags&uint32(libc.Int32FromInt32(EP_Distinct)|libc.Int32FromInt32(EP_Commuted)) != (*TExpr)(unsafe.Pointer(pB)).Fflags&uint32(libc.Int32FromInt32(EP_Distinct)|libc.Int32FromInt32(EP_Commuted)) {
		return int32(2)
	}
	if combinedFlags&uint32(EP_TokenOnly) == uint32(0) {
		if combinedFlags&uint32(EP_xIsSelect) != 0 {
			return int32(2)
		}
		if combinedFlags&uint32(EP_FixedCol) == uint32(0) && _sqlite3ExprCompare(tls, pParse, (*TExpr)(unsafe.Pointer(pA)).FpLeft, (*TExpr)(unsafe.Pointer(pB)).FpLeft, iTab) != 0 {
			return int32(2)
		}
		if _sqlite3ExprCompare(tls, pParse, (*TExpr)(unsafe.Pointer(pA)).FpRight, (*TExpr)(unsafe.Pointer(pB)).FpRight, iTab) != 0 {
			return int32(2)
		}
		if _sqlite3ExprListCompare(tls, *(*uintptr)(unsafe.Pointer(pA + 20)), *(*uintptr)(unsafe.Pointer(pB + 20)), iTab) != 0 {
			return int32(2)
		}
		if int32((*TExpr)(unsafe.Pointer(pA)).Fop) != int32(TK_STRING) && int32((*TExpr)(unsafe.Pointer(pA)).Fop) != int32(TK_TRUEFALSE) && combinedFlags&uint32(EP_Reduced) == uint32(0) {
			if int32((*TExpr)(unsafe.Pointer(pA)).FiColumn) != int32((*TExpr)(unsafe.Pointer(pB)).FiColumn) {
				return int32(2)
			}
			if int32((*TExpr)(unsafe.Pointer(pA)).Fop2) != int32((*TExpr)(unsafe.Pointer(pB)).Fop2) && int32((*TExpr)(unsafe.Pointer(pA)).Fop) == int32(TK_TRUTH) {
				return int32(2)
			}
			if int32((*TExpr)(unsafe.Pointer(pA)).Fop) != int32(TK_IN) && (*TExpr)(unsafe.Pointer(pA)).FiTable != (*TExpr)(unsafe.Pointer(pB)).FiTable && (*TExpr)(unsafe.Pointer(pA)).FiTable != iTab {
				return int32(2)
			}
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Compare two ExprList objects.  Return 0 if they are identical, 1
//	** if they are certainly different, or 2 if it is not possible to
//	** determine if they are identical or not.
//	**
//	** If any subelement of pB has Expr.iTable==(-1) then it is allowed
//	** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
//	**
//	** This routine might return non-zero for equivalent ExprLists.  The
//	** only consequence will be disabled optimizations.  But this routine
//	** must never return 0 if the two ExprList objects are different, or
//	** a malfunction will result.
//	**
//	** Two NULL pointers are considered to be the same.  But a NULL pointer
//	** always differs from a non-NULL pointer.
//	*/
func _sqlite3ExprListCompare(tls *libc.TLS, pA uintptr, pB uintptr, iTab int32) (r int32) {
	var i, res, v2 int32
	var pExprA, pExprB uintptr
	_, _, _, _, _ = i, pExprA, pExprB, res, v2
	if pA == uintptr(0) && pB == uintptr(0) {
		return 0
	}
	if pA == uintptr(0) || pB == uintptr(0) {
		return int32(1)
	}
	if (*TExprList)(unsafe.Pointer(pA)).FnExpr != (*TExprList)(unsafe.Pointer(pB)).FnExpr {
		return int32(1)
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pA)).FnExpr) {
			break
		}
		pExprA = (*(*TExprList_item)(unsafe.Pointer(pA + 8 + uintptr(i)*20))).FpExpr
		pExprB = (*(*TExprList_item)(unsafe.Pointer(pB + 8 + uintptr(i)*20))).FpExpr
		if int32((*(*TExprList_item)(unsafe.Pointer(pA + 8 + uintptr(i)*20))).Ffg.FsortFlags) != int32((*(*TExprList_item)(unsafe.Pointer(pB + 8 + uintptr(i)*20))).Ffg.FsortFlags) {
			return int32(1)
		}
		v2 = _sqlite3ExprCompare(tls, uintptr(0), pExprA, pExprB, iTab)
		res = v2
		if v2 != 0 {
			return res
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Like sqlite3ExprCompare() except COLLATE operators at the top-level
//	** are ignored.
//	*/
func _sqlite3ExprCompareSkip(tls *libc.TLS, pA uintptr, pB uintptr, iTab int32) (r int32) {
	return _sqlite3ExprCompare(tls, uintptr(0), _sqlite3ExprSkipCollate(tls, pA), _sqlite3ExprSkipCollate(tls, pB), iTab)
}

// C documentation
//
//	/*
//	** Return non-zero if Expr p can only be true if pNN is not NULL.
//	**
//	** Or if seenNot is true, return non-zero if Expr p can only be
//	** non-NULL if pNN is not NULL
//	*/
func _exprImpliesNotNull(tls *libc.TLS, pParse uintptr, p uintptr, pNN uintptr, iTab int32, seenNot int32) (r int32) {
	var pList uintptr
	_ = pList
	if _sqlite3ExprCompare(tls, pParse, p, pNN, iTab) == 0 {
		return libc.BoolInt32(int32((*TExpr)(unsafe.Pointer(pNN)).Fop) != int32(TK_NULL))
	}
	switch int32((*TExpr)(unsafe.Pointer(p)).Fop) {
	case int32(TK_IN):
		if seenNot != 0 && (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_xIsSelect)) != uint32(0) {
			return 0
		}
		return _exprImpliesNotNull(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, int32(1))
	case int32(TK_BETWEEN):
		pList = *(*uintptr)(unsafe.Pointer(p + 20))
		if seenNot != 0 {
			return 0
		}
		if _exprImpliesNotNull(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr, pNN, iTab, int32(1)) != 0 || _exprImpliesNotNull(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + 1*20))).FpExpr, pNN, iTab, int32(1)) != 0 {
			return int32(1)
		}
		return _exprImpliesNotNull(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, int32(1))
	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):
		fallthrough
	case int32(TK_PLUS):
		fallthrough
	case int32(TK_MINUS):
		fallthrough
	case int32(TK_BITOR):
		fallthrough
	case int32(TK_LSHIFT):
		fallthrough
	case int32(TK_RSHIFT):
		fallthrough
	case int32(TK_CONCAT):
		seenNot = int32(1)
		fallthrough
	case int32(TK_STAR):
		fallthrough
	case int32(TK_REM):
		fallthrough
	case int32(TK_BITAND):
		fallthrough
	case int32(TK_SLASH):
		if _exprImpliesNotNull(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpRight, pNN, iTab, seenNot) != 0 {
			return int32(1)
		}
		fallthrough
	case int32(TK_SPAN):
		fallthrough
	case int32(TK_COLLATE):
		fallthrough
	case int32(TK_UPLUS):
		fallthrough
	case int32(TK_UMINUS):
		return _exprImpliesNotNull(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, seenNot)
	case int32(TK_TRUTH):
		if seenNot != 0 {
			return 0
		}
		if int32((*TExpr)(unsafe.Pointer(p)).Fop2) != int32(TK_IS) {
			return 0
		}
		return _exprImpliesNotNull(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, int32(1))
	case int32(TK_BITNOT):
		fallthrough
	case int32(TK_NOT):
		return _exprImpliesNotNull(tls, pParse, (*TExpr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, int32(1))
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if we can prove the pE2 will always be true if pE1 is
//	** true.  Return false if we cannot complete the proof or if pE2 might
//	** be false.  Examples:
//	**
//	**     pE1: x==5       pE2: x==5             Result: true
//	**     pE1: x>0        pE2: x==5             Result: false
//	**     pE1: x=21       pE2: x=21 OR y=43     Result: true
//	**     pE1: x!=123     pE2: x IS NOT NULL    Result: true
//	**     pE1: x!=?1      pE2: x IS NOT NULL    Result: true
//	**     pE1: x IS NULL  pE2: x IS NOT NULL    Result: false
//	**     pE1: x IS ?2    pE2: x IS NOT NULL    Result: false
//	**
//	** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has
//	** Expr.iTable<0 then assume a table number given by iTab.
//	**
//	** If pParse is not NULL, then the values of bound variables in pE1 are
//	** compared against literal values in pE2 and pParse->pVdbe->expmask is
//	** modified to record which bound variables are referenced.  If pParse
//	** is NULL, then false will be returned if pE1 contains any bound variables.
//	**
//	** When in doubt, return false.  Returning true might give a performance
//	** improvement.  Returning false might cause a performance reduction, but
//	** it will always give the correct answer and is hence always safe.
//	*/
func _sqlite3ExprImpliesExpr(tls *libc.TLS, pParse uintptr, pE1 uintptr, pE2 uintptr, iTab int32) (r int32) {
	if _sqlite3ExprCompare(tls, pParse, pE1, pE2, iTab) == 0 {
		return int32(1)
	}
	if int32((*TExpr)(unsafe.Pointer(pE2)).Fop) == int32(TK_OR) && (_sqlite3ExprImpliesExpr(tls, pParse, pE1, (*TExpr)(unsafe.Pointer(pE2)).FpLeft, iTab) != 0 || _sqlite3ExprImpliesExpr(tls, pParse, pE1, (*TExpr)(unsafe.Pointer(pE2)).FpRight, iTab) != 0) {
		return int32(1)
	}
	if int32((*TExpr)(unsafe.Pointer(pE2)).Fop) == int32(TK_NOTNULL) && _exprImpliesNotNull(tls, pParse, pE1, (*TExpr)(unsafe.Pointer(pE2)).FpLeft, iTab, 0) != 0 {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/* This is a helper function to impliesNotNullRow().  In this routine,
//	** set pWalker->eCode to one only if *both* of the input expressions
//	** separately have the implies-not-null-row property.
//	*/
func _bothImplyNotNullRow(tls *libc.TLS, pWalker uintptr, pE1 uintptr, pE2 uintptr) {
	if int32((*TWalker)(unsafe.Pointer(pWalker)).FeCode) == 0 {
		_sqlite3WalkExpr(tls, pWalker, pE1)
		if (*TWalker)(unsafe.Pointer(pWalker)).FeCode != 0 {
			(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
			_sqlite3WalkExpr(tls, pWalker, pE2)
		}
	}
}

// C documentation
//
//	/*
//	** This is the Expr node callback for sqlite3ExprImpliesNonNullRow().
//	** If the expression node requires that the table at pWalker->iCur
//	** have one or more non-NULL column, then set pWalker->eCode to 1 and abort.
//	**
//	** pWalker->mWFlags is non-zero if this inquiry is being undertaking on
//	** behalf of a RIGHT JOIN (or FULL JOIN).  That makes a difference when
//	** evaluating terms in the ON clause of an inner join.
//	**
//	** This routine controls an optimization.  False positives (setting
//	** pWalker->eCode to 1 when it should not be) are deadly, but false-negatives
//	** (never setting pWalker->eCode) is a harmless missed optimization.
//	*/
func _impliesNotNullRow(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var pLeft, pRight uintptr
	_, _ = pLeft, pRight
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
		return int32(WRC_Prune)
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) && (*TWalker)(unsafe.Pointer(pWalker)).FmWFlags != 0 {
		/* If iCur is used in an inner-join ON clause to the left of a
		 ** RIGHT JOIN, that does *not* mean that the table must be non-null.
		 ** But it is difficult to check for that condition precisely.
		 ** To keep things simple, any use of iCur from any inner-join is
		 ** ignored while attempting to simplify a RIGHT JOIN. */
		return int32(WRC_Prune)
	}
	switch int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	case int32(TK_ISNOT):
		fallthrough
	case int32(TK_ISNULL):
		fallthrough
	case int32(TK_NOTNULL):
		fallthrough
	case int32(TK_IS):
		fallthrough
	case int32(TK_VECTOR):
		fallthrough
	case int32(TK_FUNCTION):
		fallthrough
	case int32(TK_TRUTH):
		fallthrough
	case int32(TK_CASE):
		return int32(WRC_Prune)
	case int32(TK_COLUMN):
		if *(*int32)(unsafe.Pointer(pWalker + 24)) == (*TExpr)(unsafe.Pointer(pExpr)).FiTable {
			(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1)
			return int32(WRC_Abort)
		}
		return int32(WRC_Prune)
	case int32(TK_OR):
		fallthrough
	case int32(TK_AND):
		/* Both sides of an AND or OR must separately imply non-null-row.
		 ** Consider these cases:
		 **    1.  NOT (x AND y)
		 **    2.  x OR y
		 ** If only one of x or y is non-null-row, then the overall expression
		 ** can be true if the other arm is false (case 1) or true (case 2).
		 */
		_bothImplyNotNullRow(tls, pWalker, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		return int32(WRC_Prune)
	case int32(TK_IN):
		/* Beware of "x NOT IN ()" and "x NOT IN (SELECT 1 WHERE false)",
		 ** both of which can be true.  But apart from these cases, if
		 ** the left-hand side of the IN is NULL then the IN itself will be
		 ** NULL. */
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) == uint32(0) && (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr > 0 {
			_sqlite3WalkExpr(tls, pWalker, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		}
		return int32(WRC_Prune)
	case int32(TK_BETWEEN):
		/* In "x NOT BETWEEN y AND z" either x must be non-null-row or else
		 ** both y and z must be non-null row */
		_sqlite3WalkExpr(tls, pWalker, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		_bothImplyNotNullRow(tls, pWalker, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8 + 1*20))).FpExpr)
		return int32(WRC_Prune)
		/* Virtual tables are allowed to use constraints like x=NULL.  So
		 ** a term of the form x=y does not prove that y is not null if x
		 ** is the column of a virtual table */
		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):
		pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
		/* The y.pTab=0 assignment in wherecode.c always happens after the
		 ** impliesNotNullRow() test */
		if int32((*TExpr)(unsafe.Pointer(pLeft)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pLeft)).Fy.FpTab != uintptr(0) && int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pLeft)).Fy.FpTab)).FeTabType) == int32(TABTYP_VTAB) || int32((*TExpr)(unsafe.Pointer(pRight)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pRight)).Fy.FpTab != uintptr(0) && int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pRight)).Fy.FpTab)).FeTabType) == int32(TABTYP_VTAB) {
			return int32(WRC_Prune)
		}
		fallthrough
	default:
		return WRC_Continue
	}
	return r
}

// C documentation
//
//	/*
//	** Return true (non-zero) if expression p can only be true if at least
//	** one column of table iTab is non-null.  In other words, return true
//	** if expression p will always be NULL or false if every column of iTab
//	** is NULL.
//	**
//	** False negatives are acceptable.  In other words, it is ok to return
//	** zero even if expression p will never be true of every column of iTab
//	** is NULL.  A false negative is merely a missed optimization opportunity.
//	**
//	** False positives are not allowed, however.  A false positive may result
//	** in an incorrect answer.
//	**
//	** Terms of p that are marked with EP_OuterON (and hence that come from
//	** the ON or USING clauses of OUTER JOINS) are excluded from the analysis.
//	**
//	** This routine is used to check if a LEFT JOIN can be converted into
//	** an ordinary JOIN.  The p argument is the WHERE clause.  If the WHERE
//	** clause requires that some column of the right table of the LEFT JOIN
//	** be non-NULL, then the LEFT JOIN can be safely converted into an
//	** ordinary join.
//	*/
func _sqlite3ExprImpliesNonNullRow(tls *libc.TLS, p uintptr, iTab int32, isRJ int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	p = _sqlite3ExprSkipCollateAndLikely(tls, p)
	if p == uintptr(0) {
		return 0
	}
	if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_NOTNULL) {
		p = (*TExpr)(unsafe.Pointer(p)).FpLeft
	} else {
		for int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_AND) {
			if _sqlite3ExprImpliesNonNullRow(tls, (*TExpr)(unsafe.Pointer(p)).FpLeft, iTab, isRJ) != 0 {
				return int32(1)
			}
			p = (*TExpr)(unsafe.Pointer(p)).FpRight
		}
	}
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_impliesNotNullRow)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = uintptr(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = uintptr(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FmWFlags = libc.BoolUint16(isRJ != 0)
	*(*int32)(unsafe.Pointer(bp + 24)) = iTab
	_sqlite3WalkExpr(tls, bp, p)
	return int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)
}

/*
** An instance of the following structure is used by the tree walker
** to determine if an expression can be evaluated by reference to the
** index only, without having to do a search for the corresponding
** table entry.  The IdxCover.pIdx field is the index.  IdxCover.iCur
** is the cursor for the table.
 */
type TIdxCover = struct {
	FpIdx uintptr
	FiCur int32
}

type IdxCover = TIdxCover

// C documentation
//
//	/*
//	** Check to see if there are references to columns in table
//	** pWalker->u.pIdxCover->iCur can be satisfied using the index
//	** pWalker->u.pIdxCover->pIdx.
//	*/
func _exprIdxCover(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TIdxCover)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 24)))).FiCur && int32(_sqlite3TableColumnToIndex(tls, (*TIdxCover)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 24)))).FpIdx, (*TExpr)(unsafe.Pointer(pExpr)).FiColumn)) < 0 {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1)
		return int32(WRC_Abort)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Determine if an index pIdx on table with cursor iCur contains will
//	** the expression pExpr.  Return true if the index does cover the
//	** expression and false if the pExpr expression references table columns
//	** that are not found in the index pIdx.
//	**
//	** An index covering an expression means that the expression can be
//	** evaluated using only the index and without having to lookup the
//	** corresponding table entry.
//	*/
func _sqlite3ExprCoveredByIndex(tls *libc.TLS, pExpr uintptr, iCur int32, pIdx uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* w at bp+0 */ TWalker
	var _ /* xcov at bp+32 */ TIdxCover
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TIdxCover)(unsafe.Pointer(bp + 32))).FiCur = iCur
	(*(*TIdxCover)(unsafe.Pointer(bp + 32))).FpIdx = pIdx
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprIdxCover)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = bp + 32
	_sqlite3WalkExpr(tls, bp, pExpr)
	return libc.BoolInt32(!((*(*TWalker)(unsafe.Pointer(bp))).FeCode != 0))
}

/* Structure used to pass information throughout the Walker in order to
** implement sqlite3ReferencesSrcList().
 */
type TRefSrcList = struct {
	F__ccgo_align [0]uint32
	Fdb           uintptr
	FpRef         uintptr
	FnExclude     Ti64
	FaiExclude    uintptr
	F__ccgo_pad4  [4]byte
}

type RefSrcList = TRefSrcList

// C documentation
//
//	/*
//	** Walker SELECT callbacks for sqlite3ReferencesSrcList().
//	**
//	** When entering a new subquery on the pExpr argument, add all FROM clause
//	** entries for that subquery to the exclude list.
//	**
//	** When leaving the subquery, remove those entries from the exclude list.
//	*/
func _selectRefEnter(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	var i, j Ti64
	var p, pSrc, piNew uintptr
	_, _, _, _, _ = i, j, p, pSrc, piNew
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc == 0 {
		return WRC_Continue
	}
	j = (*TRefSrcList)(unsafe.Pointer(p)).FnExclude
	*(*Ti64)(unsafe.Pointer(p + 8)) += int64((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc)
	piNew = _sqlite3DbRealloc(tls, (*TRefSrcList)(unsafe.Pointer(p)).Fdb, (*TRefSrcList)(unsafe.Pointer(p)).FaiExclude, uint64((*TRefSrcList)(unsafe.Pointer(p)).FnExclude*int64(4)))
	if piNew == uintptr(0) {
		(*TRefSrcList)(unsafe.Pointer(p)).FnExclude = 0
		return int32(WRC_Abort)
	} else {
		(*TRefSrcList)(unsafe.Pointer(p)).FaiExclude = piNew
	}
	i = 0
	for {
		if !(i < int64((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc)) {
			break
		}
		*(*int32)(unsafe.Pointer((*TRefSrcList)(unsafe.Pointer(p)).FaiExclude + uintptr(j)*4)) = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FiCursor
		goto _1
	_1:
		;
		i++
		j++
	}
	return WRC_Continue
}

func _selectRefLeave(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	var p, pSrc uintptr
	_, _ = p, pSrc
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	if (*TRefSrcList)(unsafe.Pointer(p)).FnExclude != 0 {
		*(*Ti64)(unsafe.Pointer(p + 8)) -= int64((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc)
	}
}

// C documentation
//
//	/* This is the Walker EXPR callback for sqlite3ReferencesSrcList().
//	**
//	** Set the 0x01 bit of pWalker->eCode if there is a reference to any
//	** of the tables shown in RefSrcList.pRef.
//	**
//	** Set the 0x02 bit of pWalker->eCode if there is a reference to a
//	** table is in neither RefSrcList.pRef nor RefSrcList.aiExclude.
//	*/
func _exprRefToSrcList(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var i, nSrc, v1 int32
	var p, pSrc, p3, p5 uintptr
	_, _, _, _, _, _, _ = i, nSrc, p, pSrc, v1, p3, p5
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_COLUMN) {
		p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
		pSrc = (*TRefSrcList)(unsafe.Pointer(p)).FpRef
		if pSrc != 0 {
			v1 = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc
		} else {
			v1 = 0
		}
		nSrc = v1
		i = 0
		for {
			if !(i < nSrc) {
				break
			}
			if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FiCursor {
				p3 = pWalker + 20
				*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(1))
				return WRC_Continue
			}
			goto _2
		_2:
			;
			i++
		}
		i = 0
		for {
			if !(int64(int64(i)) < (*TRefSrcList)(unsafe.Pointer(p)).FnExclude && *(*int32)(unsafe.Pointer((*TRefSrcList)(unsafe.Pointer(p)).FaiExclude + uintptr(i)*4)) != (*TExpr)(unsafe.Pointer(pExpr)).FiTable) {
				break
			}
			goto _4
		_4:
			;
			i++
		}
		if int64(int64(i)) >= (*TRefSrcList)(unsafe.Pointer(p)).FnExclude {
			p5 = pWalker + 20
			*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(2))
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Check to see if pExpr references any tables in pSrcList.
//	** Possible return values:
//	**
//	**    1         pExpr does references a table in pSrcList.
//	**
//	**    0         pExpr references some table that is not defined in either
//	**              pSrcList or in subqueries of pExpr itself.
//	**
//	**   -1         pExpr only references no tables at all, or it only
//	**              references tables defined in subqueries of pExpr itself.
//	**
//	** As currently used, pExpr is always an aggregate function call.  That
//	** fact is exploited for efficiency.
//	*/
func _sqlite3ReferencesSrcList(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSrcList uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var _ /* w at bp+0 */ TWalker
	var _ /* x at bp+32 */ TRefSrcList
	libc.Xmemset(tls, bp, 0, uint32(28))
	libc.Xmemset(tls, bp+32, 0, uint32(24))
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprRefToSrcList)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_selectRefEnter)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = __ccgo_fp(_selectRefLeave)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = bp + 32
	(*(*TRefSrcList)(unsafe.Pointer(bp + 32))).Fdb = (*TParse)(unsafe.Pointer(pParse)).Fdb
	(*(*TRefSrcList)(unsafe.Pointer(bp + 32))).FpRef = pSrcList
	_sqlite3WalkExprList(tls, bp, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
	if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
		_sqlite3WalkExprList(tls, bp, *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 20)))
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		_sqlite3WalkExpr(tls, bp, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FpFilter)
	}
	if (*(*TRefSrcList)(unsafe.Pointer(bp + 32))).FaiExclude != 0 {
		_sqlite3DbNNFreeNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*(*TRefSrcList)(unsafe.Pointer(bp + 32))).FaiExclude)
	}
	if int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)&int32(0x01) != 0 {
		return int32(1)
	} else {
		if (*(*TWalker)(unsafe.Pointer(bp))).FeCode != 0 {
			return 0
		} else {
			return -int32(1)
		}
	}
	return r
}

// C documentation
//
//	/*
//	** This is a Walker expression node callback.
//	**
//	** For Expr nodes that contain pAggInfo pointers, make sure the AggInfo
//	** object that is referenced does not refer directly to the Expr.  If
//	** it does, make a copy.  This is done because the pExpr argument is
//	** subject to change.
//	**
//	** The copy is scheduled for deletion using the sqlite3ExprDeferredDelete()
//	** which builds on the sqlite3ParserAddCleanup() mechanism.
//	*/
func _agginfoPersistExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var db, pAggInfo, pParse uintptr
	var iAgg int32
	_, _, _, _ = db, iAgg, pAggInfo, pParse
	if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Reduced)) != libc.Uint32FromInt32(0)) && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo != uintptr(0) {
		pAggInfo = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
		iAgg = int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)
		pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_AGG_FUNCTION) {
			if iAgg < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn && (*(*TAggInfo_col)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(iAgg)*16))).FpCExpr == pExpr {
				pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
				if pExpr != 0 && !(_sqlite3ExprDeferredDelete(tls, pParse, pExpr) != 0) {
					(*(*TAggInfo_col)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(iAgg)*16))).FpCExpr = pExpr
				}
			}
		} else {
			if iAgg < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc && (*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(iAgg)*24))).FpFExpr == pExpr {
				pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
				if pExpr != 0 && !(_sqlite3ExprDeferredDelete(tls, pParse, pExpr) != 0) {
					(*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(iAgg)*24))).FpFExpr = pExpr
				}
			}
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Initialize a Walker object so that will persist AggInfo entries referenced
//	** by the tree that is walked.
//	*/
func _sqlite3AggInfoPersistWalkerInit(tls *libc.TLS, pWalker uintptr, pParse uintptr) {
	libc.Xmemset(tls, pWalker, 0, uint32(28))
	(*TWalker)(unsafe.Pointer(pWalker)).FpParse = pParse
	(*TWalker)(unsafe.Pointer(pWalker)).FxExprCallback = __ccgo_fp(_agginfoPersistExprCb)
	(*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
}

// C documentation
//
//	/*
//	** Add a new element to the pAggInfo->aCol[] array.  Return the index of
//	** the new element.  Return a negative number if malloc fails.
//	*/
func _addAggInfoColumn(tls *libc.TLS, db uintptr, pInfo uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* i at bp+0 */ int32
	(*TAggInfo)(unsafe.Pointer(pInfo)).FaCol = _sqlite3ArrayAllocate(tls, db, (*TAggInfo)(unsafe.Pointer(pInfo)).FaCol, int32(16), pInfo+24, bp)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Add a new element to the pAggInfo->aFunc[] array.  Return the index of
//	** the new element.  Return a negative number if malloc fails.
//	*/
func _addAggInfoFunc(tls *libc.TLS, db uintptr, pInfo uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* i at bp+0 */ int32
	(*TAggInfo)(unsafe.Pointer(pInfo)).FaFunc = _sqlite3ArrayAllocate(tls, db, (*TAggInfo)(unsafe.Pointer(pInfo)).FaFunc, int32(24), pInfo+36, bp)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Search the AggInfo object for an aCol[] entry that has iTable and iColumn.
//	** Return the index in aCol[] of the entry that describes that column.
//	**
//	** If no prior entry is found, create a new one and return -1.  The
//	** new column will have an index of pAggInfo->nColumn-1.
//	*/
func _findOrCreateAggInfoColumn(tls *libc.TLS, pParse uintptr, pAggInfo uintptr, pExpr uintptr) {
	var j, k, n int32
	var pCol, pE, pGB, pTerm, v4 uintptr
	var v3 Tu16
	_, _, _, _, _, _, _, _, _ = j, k, n, pCol, pE, pGB, pTerm, v3, v4
	pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol
	k = 0
	for {
		if !(k < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
			break
		}
		if (*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr == pExpr {
			return
		}
		if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiTable == (*TExpr)(unsafe.Pointer(pExpr)).FiTable && int32((*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn) == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IF_NULL_ROW) {
			goto fix_up_expr
		}
		goto _1
	_1:
		;
		k++
		pCol += 16
	}
	k = _addAggInfoColumn(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
	if k < 0 {
		/* OOM on resize */
		return
	}
	pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(k)*16
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FpTab = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FiTable = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn = (*TExpr)(unsafe.Pointer(pExpr)).FiColumn
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = int16(-int32(1))
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr = pExpr
	if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy != 0 && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IF_NULL_ROW) {
		pGB = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy
		pTerm = pGB + 8
		n = (*TExprList)(unsafe.Pointer(pGB)).FnExpr
		j = 0
		for {
			if !(j < n) {
				break
			}
			pE = (*TExprList_item)(unsafe.Pointer(pTerm)).FpExpr
			if int32((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pE)).FiTable == (*TExpr)(unsafe.Pointer(pExpr)).FiTable && int32((*TExpr)(unsafe.Pointer(pE)).FiColumn) == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) {
				(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = int16(int16(j))
				break
			}
			goto _2
		_2:
			;
			j++
			pTerm += 20
		}
	}
	if int32((*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn) < 0 {
		v4 = pAggInfo + 2
		v3 = *(*Tu16)(unsafe.Pointer(v4))
		*(*Tu16)(unsafe.Pointer(v4))++
		(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = int16(v3)
	}
	goto fix_up_expr
fix_up_expr:
	;
	(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_AGG_COLUMN)
	}
	(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = int16(int16(k))
}

// C documentation
//
//	/*
//	** This is the xExprCallback for a tree walker.  It is used to
//	** implement sqlite3ExprAnalyzeAggregates().  See sqlite3ExprAnalyzeAggregates
//	** for additional information.
//	*/
func _analyzeAggregate(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var enc Tu8
	var i, iDataCur, nArg, v5, v6, v8 int32
	var pAggInfo, pIEpr, pItem, pItem1, pNC, pOBList, pParse, pSrcList, v7, v9 uintptr
	var _ /* tmp at bp+0 */ TExpr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, i, iDataCur, nArg, pAggInfo, pIEpr, pItem, pItem1, pNC, pOBList, pParse, pSrcList, v5, v6, v7, v8, v9
	pNC = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
	pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
	pAggInfo = *(*uintptr)(unsafe.Pointer(pNC + 8))
	switch int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	default:
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_InAggFunc) == 0 {
			break
		}
		if (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr == uintptr(0) {
			break
		}
		pIEpr = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
		for {
			if !(pIEpr != 0) {
				break
			}
			iDataCur = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiDataCur
			if iDataCur < 0 {
				goto _1
			}
			if _sqlite3ExprCompare(tls, uintptr(0), pExpr, (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FpExpr, iDataCur) == 0 {
				break
			}
			goto _1
		_1:
			;
			pIEpr = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FpIENext
		}
		if pIEpr == uintptr(0) {
			break
		}
		if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == libc.Uint32FromInt32(0)) {
			break
		}
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
				break
			}
			if (*(*TSrcItem)(unsafe.Pointer(pSrcList + 8))).FiCursor == (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiDataCur {
				break
			}
			goto _2
		_2:
			;
			i++
		}
		if i >= (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc {
			break
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo != uintptr(0) {
			break
		} /* Resolved by outer context */
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			return int32(WRC_Abort)
		}
		/* If we reach this point, it means that expression pExpr can be
		 ** translated into a reference to an index column as described by
		 ** pIEpr.
		 */
		libc.Xmemset(tls, bp, 0, uint32(52))
		(*(*TExpr)(unsafe.Pointer(bp))).Fop = uint8(TK_AGG_COLUMN)
		(*(*TExpr)(unsafe.Pointer(bp))).FiTable = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCur
		(*(*TExpr)(unsafe.Pointer(bp))).FiColumn = int16((*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCol)
		_findOrCreateAggInfoColumn(tls, pParse, pAggInfo, bp)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			return int32(WRC_Abort)
		}
		(*(*TAggInfo_col)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((*(*TExpr)(unsafe.Pointer(bp))).FiAgg)*16))).FpCExpr = pExpr
		(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
		(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = (*(*TExpr)(unsafe.Pointer(bp))).FiAgg
		return int32(WRC_Prune)
	case int32(TK_IF_NULL_ROW):
		fallthrough
	case int32(TK_AGG_COLUMN):
		fallthrough
	case int32(TK_COLUMN):
		/* Check to see if the column is in one of the tables in the FROM
		 ** clause of the aggregate query */
		if pSrcList != uintptr(0) {
			pItem = pSrcList + 8
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
					break
				}
				if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor {
					_findOrCreateAggInfoColumn(tls, pParse, pAggInfo, pExpr)
					break
				} /* endif pExpr->iTable==pItem->iCursor */
				goto _3
			_3:
				;
				i++
				pItem += 72
			} /* end loop over pSrcList */
		}
		return WRC_Continue
	case int32(TK_AGG_FUNCTION):
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_InAggFunc) == 0 && (*TWalker)(unsafe.Pointer(pWalker)).FwalkerDepth == int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2) && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
			/* Check to see if pExpr is a duplicate of another aggregate
			 ** function that is already in the pAggInfo structure
			 */
			pItem1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
			i = 0
			for {
				if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
					break
				}
				if (*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr == pExpr {
					break
				}
				if _sqlite3ExprCompare(tls, uintptr(0), (*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr, pExpr, -int32(1)) == 0 {
					break
				}
				goto _4
			_4:
				;
				i++
				pItem1 += 24
			}
			if i >= (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc {
				/* pExpr is original.  Make a new entry in pAggInfo->aFunc[]
				 */
				enc = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fenc
				i = _addAggInfoFunc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
				if i >= 0 {
					pItem1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24
					(*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr = pExpr
					if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != 0 {
						v5 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr
					} else {
						v5 = 0
					}
					nArg = v5
					(*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc = _sqlite3FindFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(pExpr + 8)), nArg, enc, uint8(0))
					if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 && (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) == uint32(0) {
						v7 = pParse + 40
						v6 = *(*int32)(unsafe.Pointer(v7))
						*(*int32)(unsafe.Pointer(v7))++
						(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiOBTab = v6
						pOBList = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 20))
						if (*TExprList)(unsafe.Pointer(pOBList)).FnExpr == int32(1) && nArg == int32(1) && _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pOBList + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr, 0) == 0 {
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBPayload = uint8(0)
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBUnique = libc.BoolUint8((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Distinct)) != libc.Uint32FromInt32(0))
						} else {
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBPayload = uint8(1)
						}
						(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbUseSubtype = libc.BoolUint8((*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc)).FfuncFlags&uint32(SQLITE_SUBTYPE) != uint32(0))
					} else {
						(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiOBTab = -int32(1)
					}
					if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Distinct)) != uint32(0) && !((*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBUnique != 0) {
						v9 = pParse + 40
						v8 = *(*int32)(unsafe.Pointer(v9))
						*(*int32)(unsafe.Pointer(v9))++
						(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiDistinct = v8
					} else {
						(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiDistinct = -int32(1)
					}
				}
			}
			/* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
			 */
			(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = int16(int16(i))
			(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
			return int32(WRC_Prune)
		} else {
			return WRC_Continue
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Analyze the pExpr expression looking for aggregate functions and
//	** for variables that need to be added to AggInfo object that pNC->pAggInfo
//	** points to.  Additional entries are made on the AggInfo object as
//	** necessary.
//	**
//	** This routine should only be called after the expression has been
//	** analyzed by sqlite3ResolveExprNames().
//	*/
func _sqlite3ExprAnalyzeAggregates(tls *libc.TLS, pNC uintptr, pExpr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_analyzeAggregate)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3WalkerDepthIncrease)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = __ccgo_fp(_sqlite3WalkerDepthDecrease)
	(*(*TWalker)(unsafe.Pointer(bp))).FwalkerDepth = 0
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pNC
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = uintptr(0)
	_sqlite3WalkExpr(tls, bp, pExpr)
}

// C documentation
//
//	/*
//	** Call sqlite3ExprAnalyzeAggregates() for every expression in an
//	** expression list.  Return the number of errors.
//	**
//	** If an error is found, the analysis is cut short.
//	*/
func _sqlite3ExprAnalyzeAggList(tls *libc.TLS, pNC uintptr, pList uintptr) {
	var i int32
	var pItem uintptr
	_, _ = i, pItem
	if pList != 0 {
		pItem = pList + 8
		i = libc.Int32FromInt32(0)
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			_sqlite3ExprAnalyzeAggregates(tls, pNC, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			goto _1
		_1:
			;
			i++
			pItem += 20
		}
	}
}

// C documentation
//
//	/*
//	** Allocate a single new register for use to hold some intermediate result.
//	*/
func _sqlite3GetTempReg(tls *libc.TLS, pParse uintptr) (r int32) {
	var v1 int32
	var v2, v4 uintptr
	var v3 Tu8
	_, _, _, _ = v1, v2, v3, v4
	if int32((*TParse)(unsafe.Pointer(pParse)).FnTempReg) == 0 {
		v2 = pParse + 44
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		return v1
	}
	v4 = pParse + 19
	*(*Tu8)(unsafe.Pointer(v4))--
	v3 = *(*Tu8)(unsafe.Pointer(v4))
	return *(*int32)(unsafe.Pointer(pParse + 164 + uintptr(v3)*4))
}

// C documentation
//
//	/*
//	** Deallocate a register, making available for reuse for some other
//	** purpose.
//	*/
func _sqlite3ReleaseTempReg(tls *libc.TLS, pParse uintptr, iReg int32) {
	var v1 Tu8
	var v2 uintptr
	_, _ = v1, v2
	if iReg != 0 {
		if int32((*TParse)(unsafe.Pointer(pParse)).FnTempReg) < int32(libc.Uint32FromInt64(32)/libc.Uint32FromInt64(4)) {
			v2 = pParse + 19
			v1 = *(*Tu8)(unsafe.Pointer(v2))
			*(*Tu8)(unsafe.Pointer(v2))++
			*(*int32)(unsafe.Pointer(pParse + 164 + uintptr(v1)*4)) = iReg
		}
	}
}

// C documentation
//
//	/*
//	** Allocate or deallocate a block of nReg consecutive registers.
//	*/
func _sqlite3GetTempRange(tls *libc.TLS, pParse uintptr, nReg int32) (r int32) {
	var i, n int32
	_, _ = i, n
	if nReg == int32(1) {
		return _sqlite3GetTempReg(tls, pParse)
	}
	i = (*TParse)(unsafe.Pointer(pParse)).FiRangeReg
	n = (*TParse)(unsafe.Pointer(pParse)).FnRangeReg
	if nReg <= n {
		*(*int32)(unsafe.Pointer(pParse + 32)) += nReg
		*(*int32)(unsafe.Pointer(pParse + 28)) -= nReg
	} else {
		i = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nReg
	}
	return i
}

func _sqlite3ReleaseTempRange(tls *libc.TLS, pParse uintptr, iReg int32, nReg int32) {
	if nReg == int32(1) {
		_sqlite3ReleaseTempReg(tls, pParse, iReg)
		return
	}
	if nReg > (*TParse)(unsafe.Pointer(pParse)).FnRangeReg {
		(*TParse)(unsafe.Pointer(pParse)).FnRangeReg = nReg
		(*TParse)(unsafe.Pointer(pParse)).FiRangeReg = iReg
	}
}

// C documentation
//
//	/*
//	** Mark all temporary registers as being unavailable for reuse.
//	**
//	** Always invoke this procedure after coding a subroutine or co-routine
//	** that might be invoked from other parts of the code, to ensure that
//	** the sub/co-routine does not use registers in common with the code that
//	** invokes the sub/co-routine.
//	*/
func _sqlite3ClearTempRegCache(tls *libc.TLS, pParse uintptr) {
	(*TParse)(unsafe.Pointer(pParse)).FnTempReg = uint8(0)
	(*TParse)(unsafe.Pointer(pParse)).FnRangeReg = 0
}

// C documentation
//
//	/*
//	** Make sure sufficient registers have been allocated so that
//	** iReg is a valid register number.
//	*/
func _sqlite3TouchRegister(tls *libc.TLS, pParse uintptr, iReg int32) {
	if (*TParse)(unsafe.Pointer(pParse)).FnMem < iReg {
		(*TParse)(unsafe.Pointer(pParse)).FnMem = iReg
	}
}

// C documentation
//
//	/*
//	** Return the latest reusable register in the set of all registers.
//	** The value returned is no less than iMin.  If any register iMin or
//	** greater is in permanent use, then return one more than that last
//	** permanent register.
//	*/
func _sqlite3FirstAvailableRegister(tls *libc.TLS, pParse uintptr, iMin int32) (r int32) {
	var i int32
	var pList uintptr
	_, _ = i, pList
	pList = (*TParse)(unsafe.Pointer(pParse)).FpConstExpr
	if pList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			if *(*int32)(unsafe.Pointer(pList + 8 + uintptr(i)*20 + 16)) >= iMin {
				iMin = *(*int32)(unsafe.Pointer(pList + 8 + uintptr(i)*20 + 16)) + int32(1)
			}
			goto _1
		_1:
			;
			i++
		}
	}
	(*TParse)(unsafe.Pointer(pParse)).FnTempReg = uint8(0)
	(*TParse)(unsafe.Pointer(pParse)).FnRangeReg = 0
	return iMin
}

/*
** Validate that no temporary register falls within the range of
** iFirst..iLast, inclusive.  This routine is only call from within assert()
** statements.
 */

/************** End of expr.c ************************************************/
/************** Begin file alter.c *******************************************/
/*
** 2005 February 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 C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
 */
/* #include "sqliteInt.h" */

/*
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.
 */

// C documentation
//
//	/*
//	** Parameter zName is the name of a table that is about to be altered
//	** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
//	** If the table is a system table, this function leaves an error message
//	** in pParse->zErr (system tables may not be altered) and returns non-zero.
//	**
//	** Or, if zName is not a system table, zero is returned.
//	*/
func _isAlterableTable(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if 0 == Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+7898, int32(7)) || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Eponymous) != uint32(0) || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Shadow) != uint32(0) && _sqlite3ReadOnlyShadowTables(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9758, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	return 0
}

// 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)
	(*TParse)(unsafe.Pointer(pParse)).FcolNamesSet = uint8(1)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+9786, libc.VaList(bp+8, zDb, zDb, bTemp, zWhen, bNoDQS))
	if bTemp == 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+9961, libc.VaList(bp+8, zDb, zWhen, bNoDQS))
	}
}

// C documentation
//
//	/*
//	** Generate VM code to replace any double-quoted strings (but not double-quoted
//	** identifiers) within the "sql" column of the sqlite_schema table in
//	** database zDb with their single-quoted equivalents. If argument bTemp is
//	** not true, similarly update all SQL statements in the sqlite_schema table
//	** of the temp db.
//	*/
func _renameFixQuotes(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+10135, libc.VaList(bp+8, zDb, zDb))
	if bTemp == 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+10282, 0)
	}
}

// C documentation
//
//	/*
//	** Generate code to reload the schema for database iDb. And, if iDb!=1, for
//	** the temp database as well.
//	*/
func _renameReloadSchema(tls *libc.TLS, pParse uintptr, iDb int32, p5 Tu16) {
	var v uintptr
	_ = v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if v != 0 {
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_sqlite3VdbeAddParseSchemaOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, iDb, uintptr(0), p5)
		if iDb != int32(1) {
			_sqlite3VdbeAddParseSchemaOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(1), uintptr(0), p5)
		}
	}
}

// C documentation
//
//	/*
//	** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
//	** command.
//	*/
func _sqlite3AlterRenameTable(tls *libc.TLS, pParse uintptr, pSrc uintptr, pName uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pTab, pVTab, v, zDb, zName, zTabName, v2 uintptr
	var i, iDb, nTabName, v1 int32
	_, _, _, _, _, _, _, _, _, _, _, _ = db, i, iDb, nTabName, pTab, pVTab, v, zDb, zName, zTabName, v1, v2 /* Table being renamed */
	zName = uintptr(0)                                                                                      /* NULL-terminated version of pName */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pVTab = uintptr(0) /* Non-zero if this is a v-tab with an xRename() */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_rename_table
	}
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !(pTab != 0) {
		goto exit_rename_table
	}
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	/* Get a NULL terminated version of the new table name. */
	zName = _sqlite3NameFromToken(tls, db, pName)
	if !(zName != 0) {
		goto exit_rename_table
	}
	/* Check that a table or index named 'zName' does not already exist
	 ** in database iDb. If so, this is an error.
	 */
	if _sqlite3FindTable(tls, db, zName, zDb) != 0 || _sqlite3FindIndex(tls, db, zName, zDb) != 0 || _sqlite3IsShadowTableOf(tls, db, pTab, zName) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+10433, libc.VaList(bp+8, zName))
		goto exit_rename_table
	}
	/* Make sure it is not a system table being altered, or a reserved name
	 ** that the table is being renamed to.
	 */
	if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
		goto exit_rename_table
	}
	if SQLITE_OK != _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+10492, zName) {
		goto exit_rename_table
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+10498, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_rename_table
	}
	/* Invoke the authorization callback. */
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
		goto exit_rename_table
	}
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto exit_rename_table
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		pVTab = _sqlite3GetVTable(tls, db, pTab)
		if (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTab)).FpVtab)).FpModule)).FxRename == uintptr(0) {
			pVTab = uintptr(0)
		}
	}
	/* Begin a transaction for database iDb. Then modify the schema cookie
	 ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
	 ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
	 ** nested SQL may raise an exception.  */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto exit_rename_table
	}
	_sqlite3MayAbort(tls, pParse)
	/* figure out how many UTF-8 characters are in zName */
	zTabName = (*TTable)(unsafe.Pointer(pTab)).FzName
	nTabName = _sqlite3Utf8CharLen(tls, zTabName, -int32(1))
	/* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
	 ** the schema to use the new table name.  */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+10525, libc.VaList(bp+8, zDb, zDb, zTabName, zName, libc.BoolInt32(iDb == int32(1)), zTabName))
	/* Update the tbl_name and name columns of the sqlite_schema table
	 ** as required.  */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+10709, libc.VaList(bp+8, zDb, zName, zName, zName, nTabName, zTabName))
	/* If the sqlite_sequence table exists in this database, then update
	 ** it with the new table name.
	 */
	if _sqlite3FindTable(tls, db, __ccgo_ts+11014, zDb) != 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+11030, libc.VaList(bp+8, zDb, zName, (*TTable)(unsafe.Pointer(pTab)).FzName))
	}
	/* If the table being renamed is not itself part of the temp database,
	 ** edit view and trigger definitions within the temp database
	 ** as required.  */
	if iDb != int32(1) {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+11088, libc.VaList(bp+8, zDb, zTabName, zName, zTabName, zDb, zName))
	}
	/* If this is a virtual table, invoke the xRename() function if
	 ** one is defined. The xRename() callback will modify the names
	 ** of any resources used by the v-table implementation (including other
	 ** SQLite tables) that are identified by the name of the virtual table.
	 */
	if pVTab != 0 {
		v2 = pParse + 44
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		i = v1
		_sqlite3VdbeLoadString(tls, v, i, zName)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_VRename), i, 0, 0, pVTab, -int32(11))
	}
	_renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterRename))
	_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)), __ccgo_ts+11353, 0)
	goto exit_rename_table
exit_rename_table:
	;
	_sqlite3SrcListDelete(tls, db, pSrc)
	_sqlite3DbFree(tls, db, zName)
}

// C documentation
//
//	/*
//	** Write code that will raise an error if the table described by
//	** zDb and zTab is not empty.
//	*/
func _sqlite3ErrorIfNotEmpty(tls *libc.TLS, pParse uintptr, zDb uintptr, zTab uintptr, zErr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+11366, libc.VaList(bp+8, zErr, zDb, zTab))
}

// 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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))*12
	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 int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11404, 0)
		return
	}
	if (*TTable)(unsafe.Pointer(pNew)).FpIndex != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11436, 0)
		return
	}
	if int32((*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 && int32((*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 + 44))).FpFKey != 0 && pDflt != 0 {
			_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+11463)
		}
		if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf>>0)) != 0 && !(pDflt != 0) {
			_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+11522)
		}
		/* Ensure the default expression is something that sqlite3ValueFromExpr()
		 ** can handle (i.e. not CURRENT_TIME etc.)
		 */
		if pDflt != 0 {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			rc = _sqlite3ValueFromExpr(tls, db, pDflt, uint8(SQLITE_UTF8), uint8(SQLITE_AFF_BLOB), bp)
			if rc != SQLITE_OK {
				return
			}
			if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
				_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+11575)
			}
			_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	} else {
		if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_STORED) != 0 {
			_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+11621)
		}
	}
	/* 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 && (int32(*(*int8)(unsafe.Pointer(zEnd))) == int32(';') || int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zEnd)))])&int32(0x01) != 0) {
			v1 = zEnd
			zEnd--
			*(*int8)(unsafe.Pointer(v1)) = int8('\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+11648, libc.VaList(bp+16, zDb, (*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pNew + 44))).FaddColOffset, zCol, (*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pNew + 44))).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 + 4))&0xf>>0)) != 0 && int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Strict) != uint32(0) {
			_sqlite3NestedParse(tls, pParse, __ccgo_ts+11794, libc.VaList(bp+16, zTab, zDb))
		}
	}
}

// C documentation
//
//	/*
//	** This function is called by the parser after the table-name in
//	** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
//	** pSrc is the full-name of the table being altered.
//	**
//	** This routine makes a (partial) copy of the Table structure
//	** for the table being altered and sets Parse.pNewTable to point
//	** to it. Routines called by the parser as the column definition
//	** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
//	** the copy. The copy of the Table structure is deleted by tokenize.c
//	** after parsing is finished.
//	**
//	** Routine sqlite3AlterFinishAddColumn() will be called to complete
//	** coding the "ALTER TABLE ... ADD" statement.
//	*/
func _sqlite3AlterBeginAddColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pCol, pNew, pTab uintptr
	var i, iDb, nAlloc int32
	_, _, _, _, _, _, _ = db, i, iDb, nAlloc, pCol, pNew, pTab
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Look up the table being altered. */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_begin_add_column
	}
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !(pTab != 0) {
		goto exit_begin_add_column
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12147, 0)
		goto exit_begin_add_column
	}
	/* Make sure this is not an attempt to ALTER a view. */
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12181, 0)
		goto exit_begin_add_column
	}
	if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
		goto exit_begin_add_column
	}
	_sqlite3MayAbort(tls, pParse)
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	/* Put a copy of the Table struct in Parse.pNewTable for the
	 ** sqlite3AddColumn() function and friends to modify.  But modify
	 ** the name by adding an "sqlite_altertab_" prefix.  By adding this
	 ** prefix, we insure that the name will not collide with an existing
	 ** table because user table are not allowed to have the "sqlite_"
	 ** prefix on their name.
	 */
	pNew = _sqlite3DbMallocZero(tls, db, uint64(64))
	if !(pNew != 0) {
		goto exit_begin_add_column
	}
	(*TParse)(unsafe.Pointer(pParse)).FpNewTable = pNew
	(*TTable)(unsafe.Pointer(pNew)).FnTabRef = uint32(1)
	(*TTable)(unsafe.Pointer(pNew)).FnCol = (*TTable)(unsafe.Pointer(pTab)).FnCol
	nAlloc = (int32((*TTable)(unsafe.Pointer(pNew)).FnCol)-int32(1))/int32(8)*int32(8) + int32(8)
	(*TTable)(unsafe.Pointer(pNew)).FaCol = _sqlite3DbMallocZero(tls, db, uint64(uint32(12)*uint32(uint32(nAlloc))))
	(*TTable)(unsafe.Pointer(pNew)).FzName = _sqlite3MPrintf(tls, db, __ccgo_ts+12211, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
	if !((*TTable)(unsafe.Pointer(pNew)).FaCol != 0) || !((*TTable)(unsafe.Pointer(pNew)).FzName != 0) {
		goto exit_begin_add_column
	}
	libc.Xmemcpy(tls, (*TTable)(unsafe.Pointer(pNew)).FaCol, (*TTable)(unsafe.Pointer(pTab)).FaCol, uint32(12)*uint32((*TTable)(unsafe.Pointer(pNew)).FnCol))
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pNew)).FnCol)) {
			break
		}
		pCol = (*TTable)(unsafe.Pointer(pNew)).FaCol + uintptr(i)*12
		(*TColumn)(unsafe.Pointer(pCol)).FzCnName = _sqlite3DbStrDup(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
		(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
		goto _1
	_1:
		;
		i++
	}
	(*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pNew + 44))).FpDfltList = _sqlite3ExprListDup(tls, db, (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpDfltList, 0)
	(*TTable)(unsafe.Pointer(pNew)).FpSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	(*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pNew + 44))).FaddColOffset = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FaddColOffset
	goto exit_begin_add_column
exit_begin_add_column:
	;
	_sqlite3SrcListDelete(tls, db, pSrc)
	return
}

// C documentation
//
//	/*
//	** Parameter pTab is the subject of an ALTER TABLE ... RENAME COLUMN
//	** command. This function checks if the table is a view or virtual
//	** table (columns of views or virtual tables may not be renamed). If so,
//	** it loads an error message into pParse and returns non-zero.
//	**
//	** Or, if pTab is not a view or virtual table, zero is returned.
//	*/
func _isRealTable(tls *libc.TLS, pParse uintptr, pTab uintptr, bDrop int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zType, v1 uintptr
	_, _ = zType, v1
	zType = uintptr(0)
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		zType = __ccgo_ts + 12230
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		zType = __ccgo_ts + 12235
	}
	if zType != 0 {
		if bDrop != 0 {
			v1 = __ccgo_ts + 12249
		} else {
			v1 = __ccgo_ts + 12266
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12284, libc.VaList(bp+8, v1, zType, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Handles the following parser reduction:
//	**
//	**  cmd ::= ALTER TABLE pSrc RENAME COLUMN pOld TO pNew
//	*/
func _sqlite3AlterRenameColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr, pOld uintptr, pNew uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var bQuote, iCol, iSchema int32
	var db, pTab, zDb, zNew, zOld uintptr
	_, _, _, _, _, _, _, _ = bQuote, db, iCol, iSchema, pTab, zDb, zNew, zOld
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Index of column being renamed */
	zOld = uintptr(0)                          /* Old column name */
	zNew = uintptr(0)                          /* True to quote the new name */
	/* Locate the table to be altered */
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !(pTab != 0) {
		goto exit_rename_column
	}
	/* Cannot alter a system table */
	if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
		goto exit_rename_column
	}
	if SQLITE_OK != _isRealTable(tls, pParse, pTab, 0) {
		goto exit_rename_column
	}
	/* Which schema holds the table to be altered */
	iSchema = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iSchema)*16))).FzDbSName
	/* Invoke the authorization callback. */
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
		goto exit_rename_column
	}
	/* Make sure the old name really is a column name in the table to be
	 ** altered.  Set iCol to be the index of the column being renamed */
	zOld = _sqlite3NameFromToken(tls, db, pOld)
	if !(zOld != 0) {
		goto exit_rename_column
	}
	iCol = 0
	for {
		if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if 0 == _sqlite3StrICmp(tls, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName, zOld) {
			break
		}
		goto _1
	_1:
		;
		iCol++
	}
	if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12302, libc.VaList(bp+8, pOld))
		goto exit_rename_column
	}
	/* Ensure the schema contains no double-quoted strings */
	_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iSchema == int32(1)), __ccgo_ts+1672, 0)
	_renameFixQuotes(tls, pParse, zDb, libc.BoolInt32(iSchema == int32(1)))
	/* Do the rename operation using a recursive UPDATE statement that
	 ** uses the sqlite_rename_column() SQL function to compute the new
	 ** CREATE statement text for the sqlite_schema table.
	 */
	_sqlite3MayAbort(tls, pParse)
	zNew = _sqlite3NameFromToken(tls, db, pNew)
	if !(zNew != 0) {
		goto exit_rename_column
	}
	bQuote = int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer((*TToken)(unsafe.Pointer(pNew)).Fz)))]) & int32(0x80)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+12323, libc.VaList(bp+8, zDb, zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, iCol, zNew, bQuote, libc.BoolInt32(iSchema == int32(1)), (*TTable)(unsafe.Pointer(pTab)).FzName))
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+12505, libc.VaList(bp+8, zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, iCol, zNew, bQuote))
	/* Drop and reload the database schema. */
	_renameReloadSchema(tls, pParse, iSchema, uint16(INITFLAG_AlterRename))
	_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iSchema == int32(1)), __ccgo_ts+11353, int32(1))
	goto exit_rename_column
exit_rename_column:
	;
	_sqlite3SrcListDelete(tls, db, pSrc)
	_sqlite3DbFree(tls, db, zOld)
	_sqlite3DbFree(tls, db, zNew)
	return
}

/*
** Each RenameToken object maps an element of the parse tree into
** the token that generated that element.  The parse tree element
** might be one of:
**
**     *  A pointer to an Expr that represents an ID
**     *  The name of a table column in Column.zName
**
** A list of RenameToken objects can be constructed during parsing.
** Each new object is created by sqlite3RenameTokenMap().
** As the parse tree is transformed, the sqlite3RenameTokenRemap()
** routine is used to keep the mapping current.
**
** After the parse finishes, renameTokenFind() routine can be used
** to look up the actual token value that created some element in
** the parse tree.
 */
type TRenameToken1 = struct {
	Fp     uintptr
	Ft     TToken
	FpNext uintptr
}

type RenameToken1 = TRenameToken1

// C documentation
//
//	/*
//	** The context of an ALTER TABLE RENAME COLUMN operation that gets passed
//	** down into the Walker.
//	*/
type TRenameCtx = struct {
	FpList uintptr
	FnList int32
	FiCol  int32
	FpTab  uintptr
	FzOld  uintptr
}

type RenameCtx = TRenameCtx

type TRenameCtx1 = struct {
	FpList uintptr
	FnList int32
	FiCol  int32
	FpTab  uintptr
	FzOld  uintptr
}

type RenameCtx1 = TRenameCtx1

// C documentation
//
//	/*
//	** Remember that the parser tree element pPtr was created using
//	** the token pToken.
//	**
//	** In other words, construct a new RenameToken object and add it
//	** to the list of RenameToken objects currently being built up
//	** in pParse->pRename.
//	**
//	** The pPtr argument is returned so that this routine can be used
//	** with tail recursion in tokenExpr() routine, for a small performance
//	** improvement.
//	*/
func _sqlite3RenameTokenMap(tls *libc.TLS, pParse uintptr, pPtr uintptr, pToken uintptr) (r uintptr) {
	var pNew uintptr
	_ = pNew
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != int32(PARSE_MODE_UNMAP) {
		pNew = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(16))
		if pNew != 0 {
			(*TRenameToken)(unsafe.Pointer(pNew)).Fp = pPtr
			(*TRenameToken)(unsafe.Pointer(pNew)).Ft = *(*TToken)(unsafe.Pointer(pToken))
			(*TRenameToken)(unsafe.Pointer(pNew)).FpNext = (*TParse)(unsafe.Pointer(pParse)).FpRename
			(*TParse)(unsafe.Pointer(pParse)).FpRename = pNew
		}
	}
	return pPtr
}

// C documentation
//
//	/*
//	** It is assumed that there is already a RenameToken object associated
//	** with parse tree element pFrom. This function remaps the associated token
//	** to parse tree element pTo.
//	*/
func _sqlite3RenameTokenRemap(tls *libc.TLS, pParse uintptr, pTo uintptr, pFrom uintptr) {
	var p uintptr
	_ = p
	p = (*TParse)(unsafe.Pointer(pParse)).FpRename
	for {
		if !(p != 0) {
			break
		}
		if (*TRenameToken)(unsafe.Pointer(p)).Fp == pFrom {
			(*TRenameToken)(unsafe.Pointer(p)).Fp = pTo
			break
		}
		goto _1
	_1:
		;
		p = (*TRenameToken)(unsafe.Pointer(p)).FpNext
	}
}

// C documentation
//
//	/*
//	** Walker callback used by sqlite3RenameExprUnmap().
//	*/
func _renameUnmapExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var pParse uintptr
	_ = pParse
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr)
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == uint32(0) {
		_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr+44)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Iterate through the Select objects that are part of WITH clauses attached
//	** to select statement pSelect.
//	*/
func _renameWalkWith(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var p, pCopy, pParse, pWith uintptr
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _ = i, p, pCopy, pParse, pWith
	pWith = (*TSelect)(unsafe.Pointer(pSelect)).FpWith
	if pWith != 0 {
		pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
		pCopy = uintptr(0)
		if (*TSelect)(unsafe.Pointer((*(*TCte)(unsafe.Pointer(pWith + 12))).FpSelect)).FselFlags&uint32(SF_Expanded) == uint32(0) {
			/* Push a copy of the With object onto the with-stack. We use a copy
			 ** here as the original will be expanded and resolved (flags SF_Expanded
			 ** and SF_Resolved) below. And the parser code that uses the with-stack
			 ** fails if the Select objects on it have already been expanded and
			 ** resolved.  */
			pCopy = _sqlite3WithDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pWith)
			pCopy = _sqlite3WithPush(tls, pParse, pCopy, uint8(1))
		}
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(pWith)).FnCte) {
				break
			}
			p = (*(*TCte)(unsafe.Pointer(pWith + 12 + uintptr(i)*24))).FpSelect
			libc.Xmemset(tls, bp, 0, uint32(36))
			(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
			if pCopy != 0 {
				_sqlite3SelectPrep(tls, (*(*TNameContext)(unsafe.Pointer(bp))).FpParse, p, bp)
			}
			if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*(*TNameContext)(unsafe.Pointer(bp))).FpParse)).Fdb)).FmallocFailed != 0 {
				return
			}
			_sqlite3WalkSelect(tls, pWalker, p)
			_sqlite3RenameExprlistUnmap(tls, pParse, (*(*TCte)(unsafe.Pointer(pWith + 12 + uintptr(i)*24))).FpCols)
			goto _1
		_1:
			;
			i++
		}
		if pCopy != 0 && (*TParse)(unsafe.Pointer(pParse)).FpWith == pCopy {
			(*TParse)(unsafe.Pointer(pParse)).FpWith = (*TWith)(unsafe.Pointer(pCopy)).FpOuter
		}
	}
}

// C documentation
//
//	/*
//	** Unmap all tokens in the IdList object passed as the second argument.
//	*/
func _unmapColumnIdlistNames(tls *libc.TLS, pParse uintptr, pIdList uintptr) {
	var ii int32
	_ = ii
	ii = 0
	for {
		if !(ii < (*TIdList)(unsafe.Pointer(pIdList)).FnId) {
			break
		}
		_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TIdList_item)(unsafe.Pointer(pIdList + 8 + uintptr(ii)*8))).FzName)
		goto _1
	_1:
		;
		ii++
	}
}

// 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&uint32(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)*20))).FzEName != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME {
				_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FzEName)
			}
			goto _1
		_1:
			;
			i++
		}
	}
	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)*72))).FzName)
			if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 36 + 4))&0x400>>10)) == 0 {
				_sqlite3WalkExpr(tls, pWalker, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 48)))
			} else {
				_unmapColumnIdlistNames(tls, pParse, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 48)))
			}
			goto _2
		_2:
			;
			i++
		}
	}
	_renameWalkWith(tls, pWalker, p)
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Remove all nodes that are part of expression pExpr from the rename list.
//	*/
func _sqlite3RenameExprUnmap(tls *libc.TLS, pParse uintptr, pExpr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eMode Tu8
	var _ /* sWalker at bp+0 */ TWalker
	_ = eMode
	eMode = (*TParse)(unsafe.Pointer(pParse)).FeParseMode
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_renameUnmapExprCb)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_renameUnmapSelectCb)
	(*TParse)(unsafe.Pointer(pParse)).FeParseMode = uint8(PARSE_MODE_UNMAP)
	_sqlite3WalkExpr(tls, bp, pExpr)
	(*TParse)(unsafe.Pointer(pParse)).FeParseMode = eMode
}

// 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(32)
	defer tls.Free(32)
	var i int32
	var _ /* sWalker at bp+0 */ TWalker
	_ = i
	if pEList != 0 {
		libc.Xmemset(tls, bp, 0, uint32(28))
		(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
		(*(*TWalker)(unsafe.Pointer(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)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME {
				_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FzEName)
			}
			goto _1
		_1:
			;
			i++
		}
	}
}

// C documentation
//
//	/*
//	** Free the list of RenameToken objects given in the second argument
//	*/
func _renameTokenFree(tls *libc.TLS, db uintptr, pToken uintptr) {
	var p, pNext uintptr
	_, _ = p, pNext
	p = pToken
	for {
		if !(p != 0) {
			break
		}
		pNext = (*TRenameToken)(unsafe.Pointer(p)).FpNext
		_sqlite3DbFree(tls, db, p)
		goto _1
	_1:
		;
		p = pNext
	}
}

// C documentation
//
//	/*
//	** Search the Parse object passed as the first argument for a RenameToken
//	** object associated with parse tree element pPtr. If found, return a pointer
//	** to it. Otherwise, return NULL.
//	**
//	** If the second argument passed to this function is not NULL and a matching
//	** RenameToken object is found, remove it from the Parse object and add it to
//	** the list maintained by the RenameCtx object.
//	*/
func _renameTokenFind(tls *libc.TLS, pParse uintptr, pCtx uintptr, pPtr uintptr) (r uintptr) {
	var pToken, pp uintptr
	_, _ = pToken, pp
	if pPtr == uintptr(0) {
		return uintptr(0)
	}
	pp = pParse + 280
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != 0) {
			break
		}
		if (*TRenameToken)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).Fp == pPtr {
			pToken = *(*uintptr)(unsafe.Pointer(pp))
			if pCtx != 0 {
				*(*uintptr)(unsafe.Pointer(pp)) = (*TRenameToken)(unsafe.Pointer(pToken)).FpNext
				(*TRenameToken)(unsafe.Pointer(pToken)).FpNext = (*TRenameCtx1)(unsafe.Pointer(pCtx)).FpList
				(*TRenameCtx1)(unsafe.Pointer(pCtx)).FpList = pToken
				(*TRenameCtx1)(unsafe.Pointer(pCtx)).FnList++
			}
			return pToken
		}
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 12
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** This is a Walker select callback. It does nothing. It is only required
//	** because without a dummy callback, sqlite3WalkExpr() and similar do not
//	** descend into sub-select statements.
//	*/
func _renameColumnSelectCb(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(libc.Int32FromInt32(SF_View)|libc.Int32FromInt32(SF_CopyCte)) != 0 {
		return int32(WRC_Prune)
	}
	_renameWalkWith(tls, pWalker, p)
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This is a Walker expression callback.
//	**
//	** For every TK_COLUMN node in the expression tree, search to see
//	** if the column being references is the column being renamed by an
//	** ALTER TABLE statement.  If it is, then attach its associated
//	** RenameToken object to the list of RenameToken objects being
//	** constructed in RenameCtx object at pWalker->u.pRename.
//	*/
func _renameColumnExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var p uintptr
	_ = p
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_TRIGGER) && int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) == (*TRenameCtx)(unsafe.Pointer(p)).FiCol && (*TParse)(unsafe.Pointer((*TWalker)(unsafe.Pointer(pWalker)).FpParse)).FpTriggerTab == (*TRenameCtx)(unsafe.Pointer(p)).FpTab {
		_renameTokenFind(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, p, pExpr)
	} else {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) == (*TRenameCtx)(unsafe.Pointer(p)).FiCol && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == uint32(0) && (*TRenameCtx)(unsafe.Pointer(p)).FpTab == (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab {
			_renameTokenFind(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, p, pExpr)
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** The RenameCtx contains a list of tokens that reference a column that
//	** is being renamed by an ALTER TABLE statement.  Return the "last"
//	** RenameToken in the RenameCtx and remove that RenameToken from the
//	** RenameContext.  "Last" means the last RenameToken encountered when
//	** the input SQL is parsed from left to right.  Repeated calls to this routine
//	** return all column name tokens in the order that they are encountered
//	** in the SQL statement.
//	*/
func _renameColumnTokenNext(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pBest, pToken, pp uintptr
	_, _, _ = pBest, pToken, pp
	pBest = (*TRenameCtx)(unsafe.Pointer(pCtx)).FpList
	pToken = (*TRenameToken)(unsafe.Pointer(pBest)).FpNext
	for {
		if !(pToken != 0) {
			break
		}
		if (*TRenameToken)(unsafe.Pointer(pToken)).Ft.Fz > (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz {
			pBest = pToken
		}
		goto _1
	_1:
		;
		pToken = (*TRenameToken)(unsafe.Pointer(pToken)).FpNext
	}
	pp = pCtx
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != pBest) {
			break
		}
		goto _2
	_2:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 12
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*TRenameToken)(unsafe.Pointer(pBest)).FpNext
	return pBest
}

// C documentation
//
//	/*
//	** An error occurred while parsing or otherwise processing a database
//	** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an
//	** ALTER TABLE RENAME COLUMN program. The error message emitted by the
//	** sub-routine is currently stored in pParse->zErrMsg. This function
//	** adds context to the error message and then stores it in pCtx.
//	*/
func _renameColumnParseError(tls *libc.TLS, pCtx uintptr, zWhen uintptr, pType uintptr, pObject uintptr, pParse uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var zErr, zN, zT, v1 uintptr
	_, _, _, _ = zErr, zN, zT, v1
	zT = Xsqlite3_value_text(tls, pType)
	zN = Xsqlite3_value_text(tls, pObject)
	if *(*int8)(unsafe.Pointer(zWhen)) != 0 {
		v1 = __ccgo_ts + 12636
	} else {
		v1 = __ccgo_ts + 1672
	}
	zErr = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+12638, libc.VaList(bp+8, zT, zN, v1, zWhen, (*TParse)(unsafe.Pointer(pParse)).FzErrMsg))
	Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
	_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zErr)
}

// 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)*20))).FzEName
			if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME && zName != uintptr(0) && 0 == Xsqlite3_stricmp(tls, zName, zOld) {
				_renameTokenFind(tls, pParse, pCtx, zName)
			}
			goto _1
		_1:
			;
			i++
		}
	}
}

// C documentation
//
//	/*
//	** For each name in the the id-list pIdList (i.e. each pIdList->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 _renameColumnIdlistNames(tls *libc.TLS, pParse uintptr, pCtx uintptr, pIdList uintptr, zOld uintptr) {
	var i int32
	var zName uintptr
	_, _ = i, zName
	if pIdList != 0 {
		i = 0
		for {
			if !(i < (*TIdList)(unsafe.Pointer(pIdList)).FnId) {
				break
			}
			zName = (*(*TIdList_item)(unsafe.Pointer(pIdList + 8 + uintptr(i)*8))).FzName
			if 0 == Xsqlite3_stricmp(tls, zName, zOld) {
				_renameTokenFind(tls, pParse, pCtx, zName)
			}
			goto _1
		_1:
			;
			i++
		}
	}
}

// C documentation
//
//	/*
//	** Parse the SQL statement zSql using Parse object (*p). The Parse object
//	** is initialized by this function before it is used.
//	*/
func _renameParseSql(tls *libc.TLS, p uintptr, zDb uintptr, db uintptr, zSql uintptr, bTemp int32) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	_sqlite3ParseObjectInit(tls, p, db)
	if zSql == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	if Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+12661, int32(7)) != 0 {
		return _sqlite3CorruptError(tls, int32(117285))
	}
	if bTemp != 0 {
		v1 = int32(1)
	} else {
		v1 = _sqlite3FindDbName(tls, db, zDb)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(v1)
	(*TParse)(unsafe.Pointer(p)).FeParseMode = uint8(PARSE_MODE_RENAME)
	(*TParse)(unsafe.Pointer(p)).Fdb = db
	(*TParse)(unsafe.Pointer(p)).FnQueryLoop = int16(1)
	rc = _sqlite3RunParser(tls, p, zSql)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = int32(SQLITE_NOMEM)
	}
	if rc == SQLITE_OK && ((*TParse)(unsafe.Pointer(p)).FpNewTable == uintptr(0) && (*TParse)(unsafe.Pointer(p)).FpNewIndex == uintptr(0) && (*TParse)(unsafe.Pointer(p)).FpNewTrigger == uintptr(0)) {
		rc = _sqlite3CorruptError(tls, int32(117296))
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
	return rc
}

// C documentation
//
//	/*
//	** This function edits SQL statement zSql, replacing each token identified
//	** by the linked list pRename with the text of zNew. If argument bQuote is
//	** true, then zNew is always quoted first. If no error occurs, the result
//	** is loaded into context object pCtx as the result.
//	**
//	** Or, if an error occurs (i.e. an OOM condition), an error is left in
//	** pCtx and an SQLite error code returned.
//	*/
func _renameEditSql(tls *libc.TLS, pCtx uintptr, pRename uintptr, zSql uintptr, zNew uintptr, bQuote int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pBest, zBuf1, zBuf2, zOut, zQuot, zReplace, v1 uintptr
	var iOff, nOut, rc int32
	var nNew, nQuot, nSql Ti64
	var nReplace Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, iOff, nNew, nOut, nQuot, nReplace, nSql, pBest, rc, zBuf1, zBuf2, zOut, zQuot, zReplace, v1
	nNew = int64(_sqlite3Strlen30(tls, zNew))
	nSql = int64(_sqlite3Strlen30(tls, zSql))
	db = Xsqlite3_context_db_handle(tls, pCtx)
	rc = SQLITE_OK
	zQuot = uintptr(0)
	nQuot = 0
	zBuf1 = uintptr(0)
	zBuf2 = uintptr(0)
	if zNew != 0 {
		/* Set zQuot to point to a buffer containing a quoted copy of the
		 ** identifier zNew. If the corresponding identifier in the original
		 ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
		 ** point to zQuot so that all substitutions are made using the
		 ** quoted version of the new column name.  */
		zQuot = _sqlite3MPrintf(tls, db, __ccgo_ts+12669, libc.VaList(bp+8, zNew))
		if zQuot == uintptr(0) {
			return int32(SQLITE_NOMEM)
		} else {
			nQuot = int64(_sqlite3Strlen30(tls, zQuot) - int32(1))
		}
		zOut = _sqlite3DbMallocZero(tls, db, uint64(nSql+int64((*TRenameCtx)(unsafe.Pointer(pRename)).FnList)*nQuot+int64(1)))
	} else {
		zOut = _sqlite3DbMallocZero(tls, db, uint64((nSql*int64(2)+int64(1))*int64(3)))
		if zOut != 0 {
			zBuf1 = zOut + uintptr(nSql*int64(2)+int64(1))
			zBuf2 = zOut + uintptr(nSql*int64(4)+int64(2))
		}
	}
	/* At this point pRename->pList contains a list of RenameToken objects
	 ** corresponding to all tokens in the input SQL that must be replaced
	 ** with the new column name, or with single-quoted versions of themselves.
	 ** All that remains is to construct and return the edited SQL string. */
	if zOut != 0 {
		nOut = int32(int32(nSql))
		libc.Xmemcpy(tls, zOut, zSql, uint32(uint32(nSql)))
		for (*TRenameCtx)(unsafe.Pointer(pRename)).FpList != 0 {
			pBest = _renameColumnTokenNext(tls, pRename)
			if zNew != 0 {
				if bQuote == 0 && _sqlite3IsIdChar(tls, uint8(*(*int8)(unsafe.Pointer((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz)))) != 0 {
					nReplace = uint32(uint32(nNew))
					zReplace = zNew
				} else {
					nReplace = uint32(uint32(nQuot))
					zReplace = zQuot
					if int32(*(*int8)(unsafe.Pointer((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz + uintptr((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))) == int32('"') {
						nReplace++
					}
				}
			} else {
				/* Dequote the double-quoted token. Then requote it again, this time
				 ** using single quotes. If the character immediately following the
				 ** original token within the input SQL was a single quote ('), then
				 ** add another space after the new, single-quoted version of the
				 ** token. This is so that (SELECT "string"'alias') maps to
				 ** (SELECT 'string' 'alias'), and not (SELECT 'string''alias').  */
				libc.Xmemcpy(tls, zBuf1, (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz, (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)
				*(*int8)(unsafe.Pointer(zBuf1 + uintptr((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn))) = 0
				_sqlite3Dequote(tls, zBuf1)
				if int32(*(*int8)(unsafe.Pointer((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz + uintptr((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))) == int32('\'') {
					v1 = __ccgo_ts + 12636
				} else {
					v1 = __ccgo_ts + 1672
				}
				Xsqlite3_snprintf(tls, int32(nSql*int64(2)), zBuf2, __ccgo_ts+12675, libc.VaList(bp+8, zBuf1, v1))
				zReplace = zBuf2
				nReplace = uint32(_sqlite3Strlen30(tls, zReplace))
			}
			iOff = int32((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz) - int32(int32(zSql))
			if (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn != nReplace {
				libc.Xmemmove(tls, zOut+uintptr(uint32(uint32(iOff))+nReplace), zOut+uintptr(uint32(uint32(iOff))+(*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn), uint32(uint32(nOut))-(uint32(uint32(iOff))+(*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn))
				nOut = int32(uint32(nOut) + (nReplace - (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn))
				*(*int8)(unsafe.Pointer(zOut + uintptr(nOut))) = int8('\000')
			}
			libc.Xmemcpy(tls, zOut+uintptr(iOff), zReplace, nReplace)
			_sqlite3DbFree(tls, db, pBest)
		}
		Xsqlite3_result_text(tls, pCtx, zOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3DbFree(tls, db, zOut)
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	Xsqlite3_free(tls, zQuot)
	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)*20+8+4, uint32(uint32(val)), 0, 0x3)
			goto _1
		_1:
			;
			i++
		}
	}
}

// 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(48)
	defer tls.Free(48)
	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, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
	(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = _sqlite3FindTable(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).Ftable, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(_sqlite3SchemaToIndex(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).FpTabSchema))*16))).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 = _sqlite3ViewGetColumnNames(tls, pParse, (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab)
	}
	/* 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)).FzTarget != 0 {
			pSrc = _sqlite3TriggerStepSrc(tls, pParse, pStep)
			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)).FpFrom != 0 {
					i = 0
					for {
						if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom)).FnSrc && rc == SQLITE_OK) {
							break
						}
						p = (*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom + 8 + uintptr(i)*72
						if (*TSrcItem)(unsafe.Pointer(p)).FpSelect != 0 {
							_sqlite3SelectPrep(tls, pParse, (*TSrcItem)(unsafe.Pointer(p)).FpSelect, uintptr(0))
						}
						goto _3
					_3:
						;
						i++
					}
				}
				if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
					rc = int32(SQLITE_NOMEM)
				}
				(*(*TNameContext)(unsafe.Pointer(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 + 8)) = pUpsert
					(*(*TNameContext)(unsafe.Pointer(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)(unsafe.Pointer(bp))).FncFlags = 0
				}
				(*(*TNameContext)(unsafe.Pointer(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
//
//	/*
//	** 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 pStep, pUpsert uintptr
	_, _, _ = i, 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)).FpFrom != 0 {
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom)).FnSrc) {
					break
				}
				_sqlite3WalkSelect(tls, pWalker, (*(*TSrcItem)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom + 8 + uintptr(i)*72))).FpSelect)
				goto _2
			_2:
				;
				i++
			}
		}
		goto _1
	_1:
		;
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
}

// C documentation
//
//	/*
//	** Free the contents of Parse object (*pParse). Do not free the memory
//	** occupied by the Parse object itself.
//	*/
func _renameParseCleanup(tls *libc.TLS, pParse uintptr) {
	var db, pIdx, v1 uintptr
	_, _, _ = db, pIdx, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FpVdbe != 0 {
		_sqlite3VdbeFinalize(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe)
	}
	_sqlite3DeleteTable(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpNewTable)
	for {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpNewIndex
		pIdx = v1
		if !(v1 != uintptr(0)) {
			break
		}
		(*TParse)(unsafe.Pointer(pParse)).FpNewIndex = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		_sqlite3FreeIndex(tls, db, pIdx)
	}
	_sqlite3DeleteTrigger(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger)
	_sqlite3DbFree(tls, db, (*TParse)(unsafe.Pointer(pParse)).FzErrMsg)
	_renameTokenFree(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpRename)
	_sqlite3ParseObjectReset(tls, pParse)
}

// C documentation
//
//	/*
//	** SQL function:
//	**
//	**     sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP)
//	**
//	**   0. zSql:     SQL statement to rewrite
//	**   1. type:     Type of object ("table", "view" etc.)
//	**   2. object:   Name of object
//	**   3. Database: Database name (e.g. "main")
//	**   4. Table:    Table name
//	**   5. iCol:     Index of column to rename
//	**   6. zNew:     New column name
//	**   7. bQuote:   Non-zero if the new column name should be quoted.
//	**   8. bTemp:    True if zSql comes from temp schema
//	**
//	** Do a column rename operation on the CREATE statement given in zSql.
//	** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
//	** into zNew.  The name should be quoted if bQuote is true.
//	**
//	** This function is used internally by the ALTER TABLE RENAME COLUMN command.
//	** It is only accessible to SQL created using sqlite3NestedParse().  It is
//	** not reachable from ordinary SQL passed into sqlite3_prepare() unless the
//	** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled.
//	*/
func _renameColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(336)
	defer tls.Free(336)
	var bFKOnly, bQuote, bTemp, i, iCol, rc, v1, v2 int32
	var db, pExpr, pFKey, pIdx, pSelect, pStep, pTab, pTarget, pUpsertSet, zDb, zNew, zOld, zSql, zTable uintptr
	var xAuth Tsqlite3_xauth
	var _ /* sCtx at bp+0 */ TRenameCtx
	var _ /* sParse at bp+20 */ TParse
	var _ /* sWalker at bp+304 */ TWalker
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bFKOnly, bQuote, bTemp, db, i, iCol, pExpr, pFKey, pIdx, pSelect, pStep, pTab, pTarget, pUpsertSet, rc, xAuth, zDb, zNew, zOld, zSql, zTable, v1, v2
	db = Xsqlite3_context_db_handle(tls, context)
	zSql = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zDb = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4)))
	zTable = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 4*4)))
	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 5*4)))
	zNew = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 6*4)))
	bQuote = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 7*4)))
	bTemp = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 8*4)))
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	_ = NotUsed
	if zSql == uintptr(0) {
		return
	}
	if zTable == uintptr(0) {
		return
	}
	if zNew == uintptr(0) {
		return
	}
	if iCol < 0 {
		return
	}
	_sqlite3BtreeEnterAll(tls, db)
	pTab = _sqlite3FindTable(tls, db, zTable, zDb)
	if pTab == uintptr(0) || iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		_sqlite3BtreeLeaveAll(tls, db)
		return
	}
	zOld = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName
	libc.Xmemset(tls, bp, 0, uint32(20))
	if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
		v1 = -int32(1)
	} else {
		v1 = iCol
	}
	(*(*TRenameCtx)(unsafe.Pointer(bp))).FiCol = v1
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	rc = _renameParseSql(tls, bp+20, zDb, db, zSql, bTemp)
	/* Find tokens that need to be replaced. */
	libc.Xmemset(tls, bp+304, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp + 304))).FpParse = bp + 20
	(*(*TWalker)(unsafe.Pointer(bp + 304))).FxExprCallback = __ccgo_fp(_renameColumnExprCb)
	(*(*TWalker)(unsafe.Pointer(bp + 304))).FxSelectCallback = __ccgo_fp(_renameColumnSelectCb)
	*(*uintptr)(unsafe.Pointer(bp + 304 + 24)) = bp
	(*(*TRenameCtx)(unsafe.Pointer(bp))).FpTab = pTab
	if rc != SQLITE_OK {
		goto renameColumnFunc_done
	}
	if (*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable != 0 {
		if int32((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FeTabType) == int32(TABTYP_VIEW) {
			pSelect = (*(*struct {
				FpSelect uintptr
			})(unsafe.Pointer(&(*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).Fu))).FpSelect
			*(*Tu32)(unsafe.Pointer(pSelect + 4)) &= uint32(^libc.Int32FromInt32(SF_View))
			(*(*TParse)(unsafe.Pointer(bp + 20))).Frc = SQLITE_OK
			_sqlite3SelectPrep(tls, bp+20, pSelect, uintptr(0))
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				v2 = int32(SQLITE_NOMEM)
			} else {
				v2 = (*(*TParse)(unsafe.Pointer(bp + 20))).Frc
			}
			rc = v2
			if rc == SQLITE_OK {
				_sqlite3WalkSelect(tls, bp+304, pSelect)
			}
			if rc != SQLITE_OK {
				goto renameColumnFunc_done
			}
		} else {
			if int32((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FeTabType) == TABTYP_NORM {
				/* A regular table */
				bFKOnly = Xsqlite3_stricmp(tls, zTable, (*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FzName)
				(*(*TRenameCtx)(unsafe.Pointer(bp))).FpTab = (*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable
				if bFKOnly == 0 {
					if iCol < int32((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FnCol) {
						_renameTokenFind(tls, bp+20, bp, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FaCol + uintptr(iCol)*12))).FzCnName)
					}
					if (*(*TRenameCtx)(unsafe.Pointer(bp))).FiCol < 0 {
						_renameTokenFind(tls, bp+20, bp, (*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable+32)
					}
					_sqlite3WalkExprList(tls, bp+304, (*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FpCheck)
					pIdx = (*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FpIndex
					for {
						if !(pIdx != 0) {
							break
						}
						_sqlite3WalkExprList(tls, bp+304, (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr)
						goto _3
					_3:
						;
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					}
					pIdx = (*(*TParse)(unsafe.Pointer(bp + 20))).FpNewIndex
					for {
						if !(pIdx != 0) {
							break
						}
						_sqlite3WalkExprList(tls, bp+304, (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr)
						goto _4
					_4:
						;
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					}
					i = 0
					for {
						if !(i < int32((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FnCol)) {
							break
						}
						pExpr = _sqlite3ColumnExpr(tls, (*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable, (*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable)).FaCol+uintptr(i)*12)
						_sqlite3WalkExpr(tls, bp+304, pExpr)
						goto _5
					_5:
						;
						i++
					}
				}
				pFKey = (*(*struct {
					FaddColOffset int32
					FpFKey        uintptr
					FpDfltList    uintptr
				})(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTable + 44))).FpFKey
				for {
					if !(pFKey != 0) {
						break
					}
					i = 0
					for {
						if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
							break
						}
						if bFKOnly == 0 && (*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FiFrom == iCol {
							_renameTokenFind(tls, bp+20, bp, pFKey+36+uintptr(i)*8)
						}
						if 0 == Xsqlite3_stricmp(tls, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zTable) && 0 == Xsqlite3_stricmp(tls, (*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FzCol, zOld) {
							_renameTokenFind(tls, bp+20, bp, (*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FzCol)
						}
						goto _7
					_7:
						;
						i++
					}
					goto _6
				_6:
					;
					pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
				}
			}
		}
	} else {
		if (*(*TParse)(unsafe.Pointer(bp + 20))).FpNewIndex != 0 {
			_sqlite3WalkExprList(tls, bp+304, (*TIndex)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewIndex)).FaColExpr)
			_sqlite3WalkExpr(tls, bp+304, (*TIndex)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewIndex)).FpPartIdxWhere)
		} else {
			rc = _renameResolveTrigger(tls, bp+20)
			if rc != SQLITE_OK {
				goto renameColumnFunc_done
			}
			pStep = (*TTrigger)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTrigger)).Fstep_list
			for {
				if !(pStep != 0) {
					break
				}
				if (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget != 0 {
					pTarget = _sqlite3LocateTable(tls, bp+20, uint32(0), (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget, zDb)
					if pTarget == pTab {
						if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 {
							pUpsertSet = (*TUpsert)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert)).FpUpsertSet
							_renameColumnElistNames(tls, bp+20, bp, pUpsertSet, zOld)
						}
						_renameColumnIdlistNames(tls, bp+20, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpIdList, zOld)
						_renameColumnElistNames(tls, bp+20, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, zOld)
					}
				}
				goto _8
			_8:
				;
				pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
			}
			/* Find tokens to edit in UPDATE OF clause */
			if (*(*TParse)(unsafe.Pointer(bp + 20))).FpTriggerTab == pTab {
				_renameColumnIdlistNames(tls, bp+20, bp, (*TTrigger)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTrigger)).FpColumns, zOld)
			}
			/* Find tokens to edit in various expressions and selects */
			_renameWalkTrigger(tls, bp+304, (*(*TParse)(unsafe.Pointer(bp + 20))).FpNewTrigger)
		}
	}
	rc = _renameEditSql(tls, context, bp, zSql, zNew, bQuote)
	goto renameColumnFunc_done
renameColumnFunc_done:
	;
	if rc != SQLITE_OK {
		if rc == int32(SQLITE_ERROR) && _sqlite3WritableSchema(tls, db) != 0 {
			Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv)))
		} else {
			if (*(*TParse)(unsafe.Pointer(bp + 20))).FzErrMsg != 0 {
				_renameColumnParseError(tls, context, __ccgo_ts+1672, *(*uintptr)(unsafe.Pointer(argv + 1*4)), *(*uintptr)(unsafe.Pointer(argv + 2*4)), bp+20)
			} else {
				Xsqlite3_result_error_code(tls, context, rc)
			}
		}
	}
	_renameParseCleanup(tls, bp+20)
	_renameTokenFree(tls, db, (*(*TRenameCtx)(unsafe.Pointer(bp))).FpList)
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	_sqlite3BtreeLeaveAll(tls, db)
}

// C documentation
//
//	/*
//	** Walker expression callback used by "RENAME TABLE".
//	*/
func _renameTableExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var p uintptr
	_ = p
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == uint32(0) && (*TRenameCtx)(unsafe.Pointer(p)).FpTab == (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab {
		_renameTokenFind(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, p, pExpr+44)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Walker select callback used by "RENAME TABLE".
//	*/
func _renameTableSelectCb(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	var i int32
	var p, pItem, pSrc uintptr
	_, _, _, _ = i, p, pItem, pSrc
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	if (*TSelect)(unsafe.Pointer(pSelect)).FselFlags&uint32(libc.Int32FromInt32(SF_View)|libc.Int32FromInt32(SF_CopyCte)) != 0 {
		return int32(WRC_Prune)
	}
	if pSrc == uintptr(0) {
		return int32(WRC_Abort)
	}
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		pItem = pSrc + 8 + uintptr(i)*72
		if (*TSrcItem)(unsafe.Pointer(pItem)).FpTab == (*TRenameCtx)(unsafe.Pointer(p)).FpTab {
			_renameTokenFind(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, p, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
		}
		goto _1
	_1:
		;
		i++
	}
	_renameWalkWith(tls, pWalker, pSelect)
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This C function implements an SQL user function that is used by SQL code
//	** generated by the ALTER TABLE ... RENAME command to modify the definition
//	** of any foreign key constraints that use the table being renamed as the
//	** parent table. It is passed three arguments:
//	**
//	**   0: The database containing the table being renamed.
//	**   1. type:     Type of object ("table", "view" etc.)
//	**   2. object:   Name of object
//	**   3: The complete text of the schema statement being modified,
//	**   4: The old name of the table being renamed, and
//	**   5: The new name of the table being renamed.
//	**   6: True if the schema statement comes from the temp db.
//	**
//	** It returns the new schema statement. For example:
//	**
//	** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
//	**       -> 'CREATE TABLE t1(a REFERENCES t3)'
//	*/
func _renameTableFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(368)
	defer tls.Free(368)
	var bQuote, bTemp, i, isLegacy, rc int32
	var db, pFKey, pItem, pSelect, pStep, pTab, pTrigger, zDb, zInput, zNew, zOld uintptr
	var xAuth Tsqlite3_xauth
	var _ /* sCtx at bp+284 */ TRenameCtx
	var _ /* sNC at bp+332 */ TNameContext
	var _ /* sParse at bp+0 */ TParse
	var _ /* sWalker at bp+304 */ TWalker
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bQuote, bTemp, db, i, isLegacy, pFKey, pItem, pSelect, pStep, pTab, pTrigger, rc, xAuth, zDb, zInput, zNew, zOld
	db = Xsqlite3_context_db_handle(tls, context)
	zDb = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zInput = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4)))
	zOld = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 4*4)))
	zNew = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 5*4)))
	bTemp = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 6*4)))
	_ = NotUsed
	if zInput != 0 && zOld != 0 && zNew != 0 {
		bQuote = int32(1)
		xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
		_sqlite3BtreeEnterAll(tls, db)
		libc.Xmemset(tls, bp+284, 0, uint32(20))
		(*(*TRenameCtx)(unsafe.Pointer(bp + 284))).FpTab = _sqlite3FindTable(tls, db, zOld, zDb)
		libc.Xmemset(tls, bp+304, 0, uint32(28))
		(*(*TWalker)(unsafe.Pointer(bp + 304))).FpParse = bp
		(*(*TWalker)(unsafe.Pointer(bp + 304))).FxExprCallback = __ccgo_fp(_renameTableExprCb)
		(*(*TWalker)(unsafe.Pointer(bp + 304))).FxSelectCallback = __ccgo_fp(_renameTableSelectCb)
		*(*uintptr)(unsafe.Pointer(bp + 304 + 24)) = bp + 284
		rc = _renameParseSql(tls, bp, zDb, db, zInput, bTemp)
		if rc == SQLITE_OK {
			isLegacy = int32((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
			if (*(*TParse)(unsafe.Pointer(bp))).FpNewTable != 0 {
				pTab = (*(*TParse)(unsafe.Pointer(bp))).FpNewTable
				if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
					if isLegacy == 0 {
						pSelect = (*(*struct {
							FpSelect uintptr
						})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect
						libc.Xmemset(tls, bp+332, 0, uint32(36))
						(*(*TNameContext)(unsafe.Pointer(bp + 332))).FpParse = bp
						*(*Tu32)(unsafe.Pointer(pSelect + 4)) &= uint32(^libc.Int32FromInt32(SF_View))
						_sqlite3SelectPrep(tls, bp, (*(*struct {
							FpSelect uintptr
						})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect, bp+332)
						if (*(*TParse)(unsafe.Pointer(bp))).FnErr != 0 {
							rc = (*(*TParse)(unsafe.Pointer(bp))).Frc
						} else {
							_sqlite3WalkSelect(tls, bp+304, (*(*struct {
								FpSelect uintptr
							})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect)
						}
					}
				} else {
					/* Modify any FK definitions to point to the new table. */
					if (isLegacy == 0 || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0) && !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
						pFKey = (*(*struct {
							FaddColOffset int32
							FpFKey        uintptr
							FpDfltList    uintptr
						})(unsafe.Pointer(pTab + 44))).FpFKey
						for {
							if !(pFKey != 0) {
								break
							}
							if Xsqlite3_stricmp(tls, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zOld) == 0 {
								_renameTokenFind(tls, bp, bp+284, (*TFKey)(unsafe.Pointer(pFKey)).FzTo)
							}
							goto _1
						_1:
							;
							pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
						}
					}
					/* If this is the table being altered, fix any table refs in CHECK
					 ** expressions. Also update the name that appears right after the
					 ** "CREATE [VIRTUAL] TABLE" bit. */
					if Xsqlite3_stricmp(tls, zOld, (*TTable)(unsafe.Pointer(pTab)).FzName) == 0 {
						(*(*TRenameCtx)(unsafe.Pointer(bp + 284))).FpTab = pTab
						if isLegacy == 0 {
							_sqlite3WalkExprList(tls, bp+304, (*TTable)(unsafe.Pointer(pTab)).FpCheck)
						}
						_renameTokenFind(tls, bp, bp+284, (*TTable)(unsafe.Pointer(pTab)).FzName)
					}
				}
			} else {
				if (*(*TParse)(unsafe.Pointer(bp))).FpNewIndex != 0 {
					_renameTokenFind(tls, bp, bp+284, (*TIndex)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewIndex)).FzName)
					if isLegacy == 0 {
						_sqlite3WalkExpr(tls, bp+304, (*TIndex)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewIndex)).FpPartIdxWhere)
					}
				} else {
					pTrigger = (*(*TParse)(unsafe.Pointer(bp))).FpNewTrigger
					if 0 == Xsqlite3_stricmp(tls, (*TTrigger)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTrigger)).Ftable, zOld) && (*TTable)(unsafe.Pointer((*(*TRenameCtx)(unsafe.Pointer(bp + 284))).FpTab)).FpSchema == (*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema {
						_renameTokenFind(tls, bp, bp+284, (*TTrigger)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTrigger)).Ftable)
					}
					if isLegacy == 0 {
						rc = _renameResolveTrigger(tls, bp)
						if rc == SQLITE_OK {
							_renameWalkTrigger(tls, bp+304, pTrigger)
							pStep = (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list
							for {
								if !(pStep != 0) {
									break
								}
								if (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget != 0 && 0 == Xsqlite3_stricmp(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget, zOld) {
									_renameTokenFind(tls, bp, bp+284, (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget)
								}
								if (*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom != 0 {
									i = 0
									for {
										if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom)).FnSrc) {
											break
										}
										pItem = (*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom + 8 + uintptr(i)*72
										if 0 == Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, zOld) {
											_renameTokenFind(tls, bp, bp+284, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
										}
										goto _3
									_3:
										;
										i++
									}
								}
								goto _2
							_2:
								;
								pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
							}
						}
					}
				}
			}
		}
		if rc == SQLITE_OK {
			rc = _renameEditSql(tls, context, bp+284, zInput, zNew, bQuote)
		}
		if rc != SQLITE_OK {
			if rc == int32(SQLITE_ERROR) && _sqlite3WritableSchema(tls, db) != 0 {
				Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv + 3*4)))
			} else {
				if (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg != 0 {
					_renameColumnParseError(tls, context, __ccgo_ts+1672, *(*uintptr)(unsafe.Pointer(argv + 1*4)), *(*uintptr)(unsafe.Pointer(argv + 2*4)), bp)
				} else {
					Xsqlite3_result_error_code(tls, context, rc)
				}
			}
		}
		_renameParseCleanup(tls, bp)
		_renameTokenFree(tls, db, (*(*TRenameCtx)(unsafe.Pointer(bp + 284))).FpList)
		_sqlite3BtreeLeaveAll(tls, db)
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	}
	return
}

func _renameQuotefixExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_STRING) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_DblQuoted) != 0 {
		_renameTokenFind(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, *(*uintptr)(unsafe.Pointer(pWalker + 24)), pExpr)
	}
	return WRC_Continue
}

// C documentation
//
//	/* SQL function: sqlite_rename_quotefix(DB,SQL)
//	**
//	** Rewrite the DDL statement "SQL" so that any string literals that use
//	** double-quotes use single quotes instead.
//	**
//	** Two arguments must be passed:
//	**
//	**   0: Database name ("main", "temp" etc.).
//	**   1: SQL statement to edit.
//	**
//	** The returned value is the modified SQL statement. For example, given
//	** the database schema:
//	**
//	**   CREATE TABLE t1(a, b, c);
//	**
//	**   SELECT sqlite_rename_quotefix('main',
//	**       'CREATE VIEW v1 AS SELECT "a", "string" FROM t1'
//	**   );
//	**
//	** returns the string:
//	**
//	**   CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
//	**
//	** If there is a error in the input SQL, then raise an error, except
//	** if PRAGMA writable_schema=ON, then just return the input string
//	** unmodified following an error.
//	*/
func _renameQuotefixFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(336)
	defer tls.Free(336)
	var db, pSelect, zDb, zInput uintptr
	var i, rc, v1 int32
	var xAuth Tsqlite3_xauth
	var _ /* sCtx at bp+284 */ TRenameCtx
	var _ /* sParse at bp+0 */ TParse
	var _ /* sWalker at bp+304 */ TWalker
	_, _, _, _, _, _, _, _ = db, i, pSelect, rc, xAuth, zDb, zInput, v1
	db = Xsqlite3_context_db_handle(tls, context)
	zDb = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zInput = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	_sqlite3BtreeEnterAll(tls, db)
	_ = NotUsed
	if zDb != 0 && zInput != 0 {
		rc = _renameParseSql(tls, bp, zDb, db, zInput, 0)
		if rc == SQLITE_OK {
			/* Walker to find tokens that need to be replaced. */
			libc.Xmemset(tls, bp+284, 0, uint32(20))
			libc.Xmemset(tls, bp+304, 0, uint32(28))
			(*(*TWalker)(unsafe.Pointer(bp + 304))).FpParse = bp
			(*(*TWalker)(unsafe.Pointer(bp + 304))).FxExprCallback = __ccgo_fp(_renameQuotefixExprCb)
			(*(*TWalker)(unsafe.Pointer(bp + 304))).FxSelectCallback = __ccgo_fp(_renameColumnSelectCb)
			*(*uintptr)(unsafe.Pointer(bp + 304 + 24)) = bp + 284
			if (*(*TParse)(unsafe.Pointer(bp))).FpNewTable != 0 {
				if int32((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTable)).FeTabType) == int32(TABTYP_VIEW) {
					pSelect = (*(*struct {
						FpSelect uintptr
					})(unsafe.Pointer(&(*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTable)).Fu))).FpSelect
					*(*Tu32)(unsafe.Pointer(pSelect + 4)) &= uint32(^libc.Int32FromInt32(SF_View))
					(*(*TParse)(unsafe.Pointer(bp))).Frc = SQLITE_OK
					_sqlite3SelectPrep(tls, bp, pSelect, uintptr(0))
					if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
						v1 = int32(SQLITE_NOMEM)
					} else {
						v1 = (*(*TParse)(unsafe.Pointer(bp))).Frc
					}
					rc = v1
					if rc == SQLITE_OK {
						_sqlite3WalkSelect(tls, bp+304, pSelect)
					}
				} else {
					_sqlite3WalkExprList(tls, bp+304, (*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTable)).FpCheck)
					i = 0
					for {
						if !(i < int32((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTable)).FnCol)) {
							break
						}
						_sqlite3WalkExpr(tls, bp+304, _sqlite3ColumnExpr(tls, (*(*TParse)(unsafe.Pointer(bp))).FpNewTable, (*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTable)).FaCol+uintptr(i)*12))
						goto _2
					_2:
						;
						i++
					}
				}
			} else {
				if (*(*TParse)(unsafe.Pointer(bp))).FpNewIndex != 0 {
					_sqlite3WalkExprList(tls, bp+304, (*TIndex)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewIndex)).FaColExpr)
					_sqlite3WalkExpr(tls, bp+304, (*TIndex)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewIndex)).FpPartIdxWhere)
				} else {
					rc = _renameResolveTrigger(tls, bp)
					if rc == SQLITE_OK {
						_renameWalkTrigger(tls, bp+304, (*(*TParse)(unsafe.Pointer(bp))).FpNewTrigger)
					}
				}
			}
			if rc == SQLITE_OK {
				rc = _renameEditSql(tls, context, bp+284, zInput, uintptr(0), 0)
			}
			_renameTokenFree(tls, db, (*(*TRenameCtx)(unsafe.Pointer(bp + 284))).FpList)
		}
		if rc != SQLITE_OK {
			if _sqlite3WritableSchema(tls, db) != 0 && rc == int32(SQLITE_ERROR) {
				Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
			} else {
				Xsqlite3_result_error_code(tls, context, rc)
			}
		}
		_renameParseCleanup(tls, bp)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	_sqlite3BtreeLeaveAll(tls, db)
}

// C documentation
//
//	/* Function:  sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS)
//	**
//	** An SQL user function that checks that there are no parse or symbol
//	** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
//	** After an ALTER TABLE .. RENAME operation is performed and the schema
//	** reloaded, this function is called on each SQL statement in the schema
//	** to ensure that it is still usable.
//	**
//	**   0: Database name ("main", "temp" etc.).
//	**   1: SQL statement.
//	**   2: Object type ("view", "table", "trigger" or "index").
//	**   3: Object name.
//	**   4: True if object is from temp schema.
//	**   5: "when" part of error message.
//	**   6: True to disable the DQS quirk when parsing SQL.
//	**
//	** The return value is computed as follows:
//	**
//	**   A. If an error is seen and not in PRAGMA writable_schema=ON mode,
//	**      then raise the error.
//	**   B. Else if a trigger is created and the the table that the trigger is
//	**      attached to is in database zDb, then return 1.
//	**   C. Otherwise return NULL.
//	*/
func _renameTableTest(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(320)
	defer tls.Free(320)
	var bNoDQS, bTemp, flags, i1, i2, isLegacy, rc int32
	var db, zDb, zInput, zWhen uintptr
	var xAuth Tsqlite3_xauth
	var _ /* sNC at bp+284 */ TNameContext
	var _ /* sParse at bp+0 */ TParse
	_, _, _, _, _, _, _, _, _, _, _, _ = bNoDQS, bTemp, db, flags, i1, i2, isLegacy, rc, xAuth, zDb, zInput, zWhen
	db = Xsqlite3_context_db_handle(tls, context)
	zDb = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zInput = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	bTemp = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 4*4)))
	isLegacy = int32((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
	zWhen = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 5*4)))
	bNoDQS = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 6*4)))
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	_ = NotUsed
	if zDb != 0 && zInput != 0 {
		flags = int32((*Tsqlite3)(unsafe.Pointer(db)).Fflags)
		if bNoDQS != 0 {
			*(*Tu64)(unsafe.Pointer(db + 32)) &= uint64(^(libc.Int32FromInt32(SQLITE_DqsDML) | libc.Int32FromInt32(SQLITE_DqsDDL)))
		}
		rc = _renameParseSql(tls, bp, zDb, db, zInput, bTemp)
		*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(flags & (libc.Int32FromInt32(SQLITE_DqsDML) | libc.Int32FromInt32(SQLITE_DqsDDL)))
		if rc == SQLITE_OK {
			if isLegacy == 0 && (*(*TParse)(unsafe.Pointer(bp))).FpNewTable != 0 && int32((*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTable)).FeTabType) == int32(TABTYP_VIEW) {
				libc.Xmemset(tls, bp+284, 0, uint32(36))
				(*(*TNameContext)(unsafe.Pointer(bp + 284))).FpParse = bp
				_sqlite3SelectPrep(tls, bp, (*(*struct {
					FpSelect uintptr
				})(unsafe.Pointer(&(*TTable)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTable)).Fu))).FpSelect, bp+284)
				if (*(*TParse)(unsafe.Pointer(bp))).FnErr != 0 {
					rc = (*(*TParse)(unsafe.Pointer(bp))).Frc
				}
			} else {
				if (*(*TParse)(unsafe.Pointer(bp))).FpNewTrigger != 0 {
					if isLegacy == 0 {
						rc = _renameResolveTrigger(tls, bp)
					}
					if rc == SQLITE_OK {
						i1 = _sqlite3SchemaToIndex(tls, db, (*TTrigger)(unsafe.Pointer((*(*TParse)(unsafe.Pointer(bp))).FpNewTrigger)).FpTabSchema)
						i2 = _sqlite3FindDbName(tls, db, zDb)
						if i1 == i2 {
							/* Handle output case B */
							Xsqlite3_result_int(tls, context, int32(1))
						}
					}
				}
			}
		}
		if rc != SQLITE_OK && zWhen != 0 && !(_sqlite3WritableSchema(tls, db) != 0) {
			/* Output case A */
			_renameColumnParseError(tls, context, zWhen, *(*uintptr)(unsafe.Pointer(argv + 2*4)), *(*uintptr)(unsafe.Pointer(argv + 3*4)), bp)
		}
		_renameParseCleanup(tls, bp)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
}

// C documentation
//
//	/*
//	** The implementation of internal UDF sqlite_drop_column().
//	**
//	** Arguments:
//	**
//	**  argv[0]: An integer - the index of the schema containing the table
//	**  argv[1]: CREATE TABLE statement to modify.
//	**  argv[2]: An integer - the index of the column to remove.
//	**
//	** The value returned is a string containing the CREATE TABLE statement
//	** with column argv[2] removed.
//	*/
func _dropColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(320)
	defer tls.Free(320)
	var db, pCol, pEnd, pTab, zDb, zEnd, zNew, zSql uintptr
	var iCol, iSchema, rc int32
	var xAuth Tsqlite3_xauth
	var _ /* sParse at bp+0 */ TParse
	_, _, _, _, _, _, _, _, _, _, _, _ = db, iCol, iSchema, pCol, pEnd, pTab, rc, xAuth, zDb, zEnd, zNew, zSql
	db = Xsqlite3_context_db_handle(tls, context)
	iSchema = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zSql = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4)))
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iSchema)*16))).FzDbSName
	zNew = uintptr(0)
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	_ = NotUsed
	rc = _renameParseSql(tls, bp, zDb, db, zSql, libc.BoolInt32(iSchema == int32(1)))
	if rc != SQLITE_OK {
		goto drop_column_done
	}
	pTab = (*(*TParse)(unsafe.Pointer(bp))).FpNewTable
	if pTab == uintptr(0) || int32((*TTable)(unsafe.Pointer(pTab)).FnCol) == int32(1) || iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		/* This can happen if the sqlite_schema table is corrupt */
		rc = _sqlite3CorruptError(tls, int32(118255))
		goto drop_column_done
	}
	pCol = _renameTokenFind(tls, bp, uintptr(0), (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName)
	if iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1) {
		pEnd = _renameTokenFind(tls, bp, uintptr(0), (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol+int32(1))*12))).FzCnName)
		zEnd = (*TRenameToken)(unsafe.Pointer(pEnd)).Ft.Fz
	} else {
		zEnd = zSql + uintptr((*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pTab + 44))).FaddColOffset)
		for int32(*(*int8)(unsafe.Pointer((*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz))) != 0 && int32(*(*int8)(unsafe.Pointer((*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz))) != int32(',') {
			(*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz--
		}
	}
	zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+12680, libc.VaList(bp+296, int32((*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz)-int32(int32(zSql)), zSql, zEnd))
	Xsqlite3_result_text(tls, context, zNew, -int32(1), uintptr(-libc.Int32FromInt32(1)))
	Xsqlite3_free(tls, zNew)
	goto drop_column_done
drop_column_done:
	;
	_renameParseCleanup(tls, bp)
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	if rc != SQLITE_OK {
		Xsqlite3_result_error_code(tls, context, rc)
	}
}

// C documentation
//
//	/*
//	** This function is called by the parser upon parsing an
//	**
//	**     ALTER TABLE pSrc DROP COLUMN pName
//	**
//	** statement. Argument pSrc contains the possibly qualified name of the
//	** table being edited, and token pName the name of the column to drop.
//	*/
func _sqlite3AlterDropColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr, pName uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var addr, i, iCol, iColPos, iCur, iDb, iPos, nField, reg, regOut, regRec, v2, v4, v7 int32
	var aff int8
	var db, pPk, pTab, v, zCol, zDb, v1, v3, v5, v8 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, aff, db, i, iCol, iColPos, iCur, iDb, iPos, nField, pPk, pTab, reg, regOut, regRec, v, zCol, zDb, v1, v2, v3, v4, v5, v7, v8
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database containing pTab ("main" etc.) */
	zCol = uintptr(0)                          /* Index of column zCol in pTab->aCol[] */
	/* Look up the table being altered. */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_drop_column
	}
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !(pTab != 0) {
		goto exit_drop_column
	}
	/* Make sure this is not an attempt to ALTER a view, virtual table or
	 ** system table. */
	if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
		goto exit_drop_column
	}
	if SQLITE_OK != _isRealTable(tls, pParse, pTab, int32(1)) {
		goto exit_drop_column
	}
	/* Find the index of the column being dropped. */
	zCol = _sqlite3NameFromToken(tls, db, pName)
	if zCol == uintptr(0) {
		goto exit_drop_column
	}
	iCol = _sqlite3ColumnIndex(tls, pTab, zCol)
	if iCol < 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12302, libc.VaList(bp+8, pName))
		goto exit_drop_column
	}
	/* Do not allow the user to drop a PRIMARY KEY column or a column
	 ** constrained by a UNIQUE constraint.  */
	if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FcolFlags)&(libc.Int32FromInt32(COLFLAG_PRIMKEY)|libc.Int32FromInt32(COLFLAG_UNIQUE)) != 0 {
		if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
			v1 = __ccgo_ts + 12687
		} else {
			v1 = __ccgo_ts + 6962
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12699, libc.VaList(bp+8, v1, zCol))
		goto exit_drop_column
	}
	/* Do not allow the number of columns to go to zero */
	if int32((*TTable)(unsafe.Pointer(pTab)).FnCol) <= int32(1) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12727, libc.VaList(bp+8, zCol))
		goto exit_drop_column
	}
	/* Edit the sqlite_schema table */
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	/* Invoke the authorization callback. */
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol) != 0 {
		goto exit_drop_column
	}
	_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)), __ccgo_ts+1672, 0)
	_renameFixQuotes(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)))
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+12775, libc.VaList(bp+8, zDb, iDb, iCol, (*TTable)(unsafe.Pointer(pTab)).FzName))
	/* Drop and reload the database schema. */
	_renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterDrop))
	_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)), __ccgo_ts+12896, int32(1))
	/* Edit rows of table on disk */
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
		pPk = uintptr(0)
		nField = 0
		v = _sqlite3GetVdbe(tls, pParse)
		v3 = pParse + 40
		v2 = *(*int32)(unsafe.Pointer(v3))
		*(*int32)(unsafe.Pointer(v3))++
		iCur = v2
		_sqlite3OpenTable(tls, pParse, iCur, iDb, pTab, int32(OP_OpenWrite))
		addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iCur)
		v5 = pParse + 44
		*(*int32)(unsafe.Pointer(v5))++
		v4 = *(*int32)(unsafe.Pointer(v5))
		reg = v4
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCur, reg)
			*(*int32)(unsafe.Pointer(pParse + 44)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
		} else {
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
			*(*int32)(unsafe.Pointer(pParse + 44)) += int32((*TIndex)(unsafe.Pointer(pPk)).FnColumn)
			i = 0
			for {
				if !(i < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
					break
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iCur, i, reg+i+int32(1))
				goto _6
			_6:
				;
				i++
			}
			nField = int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
		}
		v8 = pParse + 44
		*(*int32)(unsafe.Pointer(v8))++
		v7 = *(*int32)(unsafe.Pointer(v8))
		regRec = v7
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if i != iCol && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
				if pPk != 0 {
					iPos = int32(_sqlite3TableColumnToIndex(tls, pPk, int16(int16(i))))
					iColPos = int32(_sqlite3TableColumnToIndex(tls, pPk, int16(int16(iCol))))
					if iPos < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol) {
						goto _9
					}
					regOut = reg + int32(1) + iPos - libc.BoolInt32(iPos > iColPos)
				} else {
					regOut = reg + int32(1) + nField
				}
				if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regOut)
				} else {
					aff = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity
					if int32(int32(aff)) == int32(SQLITE_AFF_REAL) {
						(*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity = int8(SQLITE_AFF_NUMERIC)
					}
					_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, i, regOut)
					(*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity = aff
				}
				nField++
			}
			goto _9
		_9:
			;
			i++
		}
		if nField == 0 {
			/* dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef */
			(*TParse)(unsafe.Pointer(pParse)).FnMem++
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, reg+int32(1))
			nField = int32(1)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), reg+int32(1), nField, regRec)
		if pPk != 0 {
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iCur, regRec, reg+int32(1), int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iCur, regRec, reg)
		}
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iCur, addr+int32(1))
		_sqlite3VdbeJumpHere(tls, v, addr)
	}
	goto exit_drop_column
exit_drop_column:
	;
	_sqlite3DbFree(tls, db, zCol)
	_sqlite3SrcListDelete(tls, db, pSrc)
}

// C documentation
//
//	/*
//	** Register built-in functions used to help implement ALTER TABLE
//	*/
func _sqlite3AlterFunctions(tls *libc.TLS) {
	_sqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&_aAlterTableFuncs)), int32(libc.Uint32FromInt64(200)/libc.Uint32FromInt64(40)))
}

var _aAlterTableFuncs = [5]TFuncDef{
	0: {
		FnArg:      int8(9),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12914,
	},
	1: {
		FnArg:      int8(7),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12935,
	},
	2: {
		FnArg:      int8(7),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12955,
	},
	3: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12974,
	},
	4: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12993,
	},
}

func init() {
	p := unsafe.Pointer(&_aAlterTableFuncs)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_renameColumnFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_renameTableFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_renameTableTest)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_dropColumnFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_renameQuotefixFunc)
}

/************** End of alter.c ***********************************************/
/************** Begin file analyze.c *****************************************/
/*
** 2005-07-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.
**
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** The ANALYZE command gather statistics about the content of tables
** and indices.  These statistics are made available to the query planner
** to help it make better decisions about how to perform queries.
**
** The following system tables are or have been supported:
**
**    CREATE TABLE sqlite_stat1(tbl, idx, stat);
**    CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
**    CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
**    CREATE TABLE sqlite_stat4(tbl, idx, nEq, nLt, nDLt, sample);
**
** Additional tables might be added in future releases of SQLite.
** The sqlite_stat2 table is not created or used unless the SQLite version
** is between 3.6.18 and 3.7.8, inclusive, and unless SQLite is compiled
** with SQLITE_ENABLE_STAT2.  The sqlite_stat2 table is deprecated.
** The sqlite_stat2 table is superseded by sqlite_stat3, which is only
** created and used by SQLite versions 3.7.9 through 3.29.0 when
** SQLITE_ENABLE_STAT3 defined.  The functionality of sqlite_stat3
** is a superset of sqlite_stat2 and is also now deprecated.  The
** sqlite_stat4 is an enhanced version of sqlite_stat3 and is only
** available when compiled with SQLITE_ENABLE_STAT4 and in SQLite
** versions 3.8.1 and later.  STAT4 is the only variant that is still
** supported.
**
** For most applications, sqlite_stat1 provides all the statistics required
** for the query planner to make good choices.
**
** Format of sqlite_stat1:
**
** There is normally one row per index, with the index identified by the
** name in the idx column.  The tbl column is the name of the table to
** which the index belongs.  In each such row, the stat column will be
** a string consisting of a list of integers.  The first integer in this
** list is the number of rows in the index.  (This is the same as the
** number of rows in the table, except for partial indices.)  The second
** integer is the average number of rows in the index that have the same
** value in the first column of the index.  The third integer is the average
** number of rows in the index that have the same value for the first two
** columns.  The N-th integer (for N>1) is the average number of rows in
** the index which have the same value for the first N-1 columns.  For
** a K-column index, there will be K+1 integers in the stat column.  If
** the index is unique, then the last integer will be 1.
**
** The list of integers in the stat column can optionally be followed
** by the keyword "unordered".  The "unordered" keyword, if it is present,
** must be separated from the last integer by a single space.  If the
** "unordered" keyword is present, then the query planner assumes that
** the index is unordered and will not use the index for a range query.
**
** If the sqlite_stat1.idx column is NULL, then the sqlite_stat1.stat
** column contains a single integer which is the (estimated) number of
** rows in the table identified by sqlite_stat1.tbl.
**
** Format of sqlite_stat2:
**
** The sqlite_stat2 is only created and is only used if SQLite is compiled
** with SQLITE_ENABLE_STAT2 and if the SQLite version number is between
** 3.6.18 and 3.7.8.  The "stat2" table contains additional information
** about the distribution of keys within an index.  The index is identified by
** the "idx" column and the "tbl" column is the name of the table to which
** the index belongs.  There are usually 10 rows in the sqlite_stat2
** table for each index.
**
** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
** inclusive are samples of the left-most key value in the index taken at
** evenly spaced points along the index.  Let the number of samples be S
** (10 in the standard build) and let C be the number of rows in the index.
** Then the sampled rows are given by:
**
**     rownumber = (i*C*2 + C)/(S*2)
**
** For i between 0 and S-1.  Conceptually, the index space is divided into
** S uniform buckets and the samples are the middle row from each bucket.
**
** The format for sqlite_stat2 is recorded here for legacy reference.  This
** version of SQLite does not support sqlite_stat2.  It neither reads nor
** writes the sqlite_stat2 table.  This version of SQLite only supports
** sqlite_stat3.
**
** Format for sqlite_stat3:
**
** The sqlite_stat3 format is a subset of sqlite_stat4.  Hence, the
** sqlite_stat4 format will be described first.  Further information
** about sqlite_stat3 follows the sqlite_stat4 description.
**
** Format for sqlite_stat4:
**
** As with sqlite_stat2, the sqlite_stat4 table contains histogram data
** to aid the query planner in choosing good indices based on the values
** that indexed columns are compared against in the WHERE clauses of
** queries.
**
** The sqlite_stat4 table contains multiple entries for each index.
** The idx column names the index and the tbl column is the table of the
** index.  If the idx and tbl columns are the same, then the sample is
** of the INTEGER PRIMARY KEY.  The sample column is a blob which is the
** binary encoding of a key from the index.  The nEq column is a
** list of integers.  The first integer is the approximate number
** of entries in the index whose left-most column exactly matches
** the left-most column of the sample.  The second integer in nEq
** is the approximate number of entries in the index where the
** first two columns match the first two columns of the sample.
** And so forth.  nLt is another list of integers that show the approximate
** number of entries that are strictly less than the sample.  The first
** integer in nLt contains the number of entries in the index where the
** left-most column is less than the left-most column of the sample.
** The K-th integer in the nLt entry is the number of index entries
** where the first K columns are less than the first K columns of the
** sample.  The nDLt column is like nLt except that it contains the
** number of distinct entries in the index that are less than the
** sample.
**
** There can be an arbitrary number of sqlite_stat4 entries per index.
** The ANALYZE command will typically generate sqlite_stat4 tables
** that contain between 10 and 40 samples which are distributed across
** the key space, though not uniformly, and which include samples with
** large nEq values.
**
** Format for sqlite_stat3 redux:
**
** The sqlite_stat3 table is like sqlite_stat4 except that it only
** looks at the left-most column of the index.  The sqlite_stat3.sample
** column contains the actual value of the left-most column instead
** of a blob encoding of the complete index key as is found in
** sqlite_stat4.sample.  The nEq, nLt, and nDLt entries of sqlite_stat3
** all contain just a single integer which is the same as the first
** integer in the equivalent columns in sqlite_stat4.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** This routine generates code that opens the sqlite_statN tables.
//	** The sqlite_stat1 table is always relevant.  sqlite_stat2 is now
//	** obsolete.  sqlite_stat3 and sqlite_stat4 are only opened when
//	** appropriate compile-time options are provided.
//	**
//	** If the sqlite_statN tables do not previously exist, it is created.
//	**
//	** Argument zWhere may be a pointer to a buffer containing a table name,
//	** or it may be a NULL pointer. If it is not NULL, then all entries in
//	** the sqlite_statN tables associated with the named table are deleted.
//	** If zWhere==0, then code is generated to delete all stat table entries.
//	*/
func _openStatTable(tls *libc.TLS, pParse uintptr, iDb int32, iStatCur int32, zWhere uintptr, zWhereType uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aCreateTbl [3]Tu8
	var aRoot [3]Tu32
	var db, pDb, pStat, v, zTab, v3 uintptr
	var i, nToOpen, v1 int32
	_, _, _, _, _, _, _, _, _, _, _ = aCreateTbl, aRoot, db, i, nToOpen, pDb, pStat, v, zTab, v1, v3
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = _sqlite3GetVdbe(tls, pParse)
	if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
		v1 = int32(2)
	} else {
		v1 = int32(1)
	}
	nToOpen = v1
	if v == uintptr(0) {
		return
	}
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	/* Create new statistic tables if they do not exist, or clear them
	 ** if they do already exist.
	 */
	i = 0
	for {
		if !(i < int32(libc.Uint32FromInt64(24)/libc.Uint32FromInt64(8))) {
			break
		}
		zTab = _aTable[i].FzName
		aCreateTbl[i] = uint8(0)
		v3 = _sqlite3FindTable(tls, db, zTab, (*TDb)(unsafe.Pointer(pDb)).FzDbSName)
		pStat = v3
		if v3 == uintptr(0) {
			if i < nToOpen {
				/* The sqlite_statN table does not exist. Create it. Note that a
				 ** side-effect of the CREATE TABLE statement is to leave the rootpage
				 ** of the new table in register pParse->regRoot. This is important
				 ** because the OpenWrite opcode below will be needing it. */
				_sqlite3NestedParse(tls, pParse, __ccgo_ts+13096, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab, _aTable[i].FzCols))
				aRoot[i] = uint32((*TParse)(unsafe.Pointer(pParse)).FregRoot)
				aCreateTbl[i] = uint8(OPFLAG_P2ISREG)
			}
		} else {
			/* The table already exists. If zWhere is not NULL, delete all entries
			 ** associated with the table zWhere. If zWhere is NULL, delete the
			 ** entire contents of the table. */
			aRoot[i] = (*TTable)(unsafe.Pointer(pStat)).Ftnum
			_sqlite3TableLock(tls, pParse, iDb, aRoot[i], uint8(1), zTab)
			if zWhere != 0 {
				_sqlite3NestedParse(tls, pParse, __ccgo_ts+13119, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab, zWhereType, zWhere))
			} else {
				if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
					_sqlite3NestedParse(tls, pParse, __ccgo_ts+13149, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab))
				} else {
					/* The sqlite_stat[134] table already exists.  Delete all rows. */
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), int32(aRoot[i]), iDb)
				}
			}
		}
		goto _2
	_2:
		;
		i++
	}
	/* Open the sqlite_stat[134] tables for writing. */
	i = 0
	for {
		if !(i < nToOpen) {
			break
		}
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_OpenWrite), iStatCur+i, int32(aRoot[i]), iDb, int32(3))
		_sqlite3VdbeChangeP5(tls, v, uint16(aCreateTbl[i]))
		goto _4
	_4:
		;
		i++
	}
}

var _aTable = [3]struct {
	FzName uintptr
	FzCols uintptr
}{
	0: {
		FzName: __ccgo_ts + 13016,
		FzCols: __ccgo_ts + 13029,
	},
	1: {
		FzName: __ccgo_ts + 13042,
		FzCols: __ccgo_ts + 13055,
	},
	2: {
		FzName: __ccgo_ts + 13083,
	},
}

/*
** Recommended number of samples for sqlite_stat4
 */

// C documentation
//
//	/*
//	** Three SQL functions - stat_init(), stat_push(), and stat_get() -
//	** share an instance of the following structure to hold their state
//	** information.
//	*/
type TStatAccum = struct {
	F__ccgo_align  [0]uint32
	Fdb            uintptr
	F__ccgo_align1 [4]byte
	FnEst          TtRowcnt
	FnRow          TtRowcnt
	FnLimit        int32
	FnCol          int32
	FnKeyCol       int32
	FnSkipAhead    Tu8
	F__ccgo_align7 [3]byte
	Fcurrent       TStatSample
	FnPSample      TtRowcnt
	FmxSample      int32
	FiPrn          Tu32
	FaBest         uintptr
	FiMin          int32
	FnSample       int32
	FnMaxEqZero    int32
	FiGet          int32
	Fa             uintptr
}

type StatAccum = TStatAccum

type TStatSample = struct {
	F__ccgo_align  [0]uint32
	FanDLt         uintptr
	FanEq          uintptr
	FanLt          uintptr
	F__ccgo_align3 [4]byte
	Fu             struct {
		F__ccgo_align [0]uint32
		FaRowid       [0]uintptr
		FiRowid       Ti64
	}
	FnRowid    Tu32
	FisPSample Tu8
	FiCol      int32
	FiHash     Tu32
}

type StatSample = TStatSample

type TStatSample1 = struct {
	F__ccgo_align  [0]uint32
	FanDLt         uintptr
	FanEq          uintptr
	FanLt          uintptr
	F__ccgo_align3 [4]byte
	Fu             struct {
		F__ccgo_align [0]uint32
		FaRowid       [0]uintptr
		FiRowid       Ti64
	}
	FnRowid    Tu32
	FisPSample Tu8
	FiCol      int32
	FiHash     Tu32
}

type StatSample1 = TStatSample1

type TStatAccum1 = struct {
	F__ccgo_align  [0]uint32
	Fdb            uintptr
	F__ccgo_align1 [4]byte
	FnEst          TtRowcnt
	FnRow          TtRowcnt
	FnLimit        int32
	FnCol          int32
	FnKeyCol       int32
	FnSkipAhead    Tu8
	F__ccgo_align7 [3]byte
	Fcurrent       TStatSample
	FnPSample      TtRowcnt
	FmxSample      int32
	FiPrn          Tu32
	FaBest         uintptr
	FiMin          int32
	FnSample       int32
	FnMaxEqZero    int32
	FiGet          int32
	Fa             uintptr
}

type StatAccum1 = TStatAccum1

// C documentation
//
//	/* Reclaim memory used by a StatSample
//	*/
func _sampleClear(tls *libc.TLS, db uintptr, p uintptr) {
	if (*TStatSample)(unsafe.Pointer(p)).FnRowid != 0 {
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(p)).Fu)))
		(*TStatSample)(unsafe.Pointer(p)).FnRowid = uint32(0)
	}
}

// C documentation
//
//	/* Initialize the BLOB value of a ROWID
//	*/
func _sampleSetRowid(tls *libc.TLS, db uintptr, p uintptr, n int32, pData uintptr) {
	if (*TStatSample)(unsafe.Pointer(p)).FnRowid != 0 {
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(p)).Fu)))
	}
	*(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(p)).Fu)) = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(n)))
	if *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(p)).Fu)) != 0 {
		(*TStatSample)(unsafe.Pointer(p)).FnRowid = uint32(uint32(n))
		libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(p)).Fu)), pData, uint32(uint32(n)))
	} else {
		(*TStatSample)(unsafe.Pointer(p)).FnRowid = uint32(0)
	}
}

// C documentation
//
//	/* Initialize the INTEGER value of a ROWID.
//	*/
func _sampleSetRowidInt64(tls *libc.TLS, db uintptr, p uintptr, iRowid Ti64) {
	if (*TStatSample)(unsafe.Pointer(p)).FnRowid != 0 {
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(p)).Fu)))
	}
	(*TStatSample)(unsafe.Pointer(p)).FnRowid = uint32(0)
	*(*Ti64)(unsafe.Pointer(p + 16)) = iRowid
}

// C documentation
//
//	/*
//	** Copy the contents of object (*pFrom) into (*pTo).
//	*/
func _sampleCopy(tls *libc.TLS, p uintptr, pTo uintptr, pFrom uintptr) {
	(*TStatSample)(unsafe.Pointer(pTo)).FisPSample = (*TStatSample)(unsafe.Pointer(pFrom)).FisPSample
	(*TStatSample)(unsafe.Pointer(pTo)).FiCol = (*TStatSample)(unsafe.Pointer(pFrom)).FiCol
	(*TStatSample)(unsafe.Pointer(pTo)).FiHash = (*TStatSample)(unsafe.Pointer(pFrom)).FiHash
	libc.Xmemcpy(tls, (*TStatSample)(unsafe.Pointer(pTo)).FanEq, (*TStatSample)(unsafe.Pointer(pFrom)).FanEq, uint32(8)*uint32((*TStatAccum)(unsafe.Pointer(p)).FnCol))
	libc.Xmemcpy(tls, (*TStatSample)(unsafe.Pointer(pTo)).FanLt, (*TStatSample)(unsafe.Pointer(pFrom)).FanLt, uint32(8)*uint32((*TStatAccum)(unsafe.Pointer(p)).FnCol))
	libc.Xmemcpy(tls, (*TStatSample)(unsafe.Pointer(pTo)).FanDLt, (*TStatSample)(unsafe.Pointer(pFrom)).FanDLt, uint32(8)*uint32((*TStatAccum)(unsafe.Pointer(p)).FnCol))
	if (*TStatSample)(unsafe.Pointer(pFrom)).FnRowid != 0 {
		_sampleSetRowid(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, pTo, int32((*TStatSample)(unsafe.Pointer(pFrom)).FnRowid), *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(pFrom)).Fu)))
	} else {
		_sampleSetRowidInt64(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, pTo, *(*Ti64)(unsafe.Pointer(pFrom + 16)))
	}
}

// C documentation
//
//	/*
//	** Reclaim all memory of a StatAccum structure.
//	*/
func _statAccumDestructor(tls *libc.TLS, pOld uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	p = pOld
	if (*TStatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
		i = 0
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FnCol) {
				break
			}
			_sampleClear(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, (*TStatAccum)(unsafe.Pointer(p)).FaBest+uintptr(i)*40)
			goto _1
		_1:
			;
			i++
		}
		i = 0
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FmxSample) {
				break
			}
			_sampleClear(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, (*TStatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*40)
			goto _2
		_2:
			;
			i++
		}
		_sampleClear(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, p+40)
	}
	_sqlite3DbFree(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, p)
}

// C documentation
//
//	/*
//	** Implementation of the stat_init(N,K,C,L) SQL function. The four parameters
//	** are:
//	**     N:    The number of columns in the index including the rowid/pk (note 1)
//	**     K:    The number of columns in the index excluding the rowid/pk.
//	**     C:    Estimated number of rows in the index
//	**     L:    A limit on the number of rows to scan, or 0 for no-limit
//	**
//	** Note 1:  In the special case of the covering index that implements a
//	** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
//	** total number of columns in the table.
//	**
//	** For indexes on ordinary rowid tables, N==K+1.  But for indexes on
//	** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
//	** PRIMARY KEY of the table.  The covering index that implements the
//	** original WITHOUT ROWID table as N==K as a special case.
//	**
//	** This routine allocates the StatAccum object in heap memory. The return
//	** value is a pointer to the StatAccum object.  The datatype of the
//	** return value is BLOB, but it is really just a pointer to the StatAccum
//	** object.
//	*/
func _statInit(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var db, p, pSpace uintptr
	var i, mxSample, n, nCol, nColUp, nKeyCol, v1, v2 int32
	_, _, _, _, _, _, _, _, _, _, _ = db, i, mxSample, n, nCol, nColUp, nKeyCol, p, pSpace, v1, v2 /* Bytes of space to allocate */
	db = Xsqlite3_context_db_handle(tls, context)
	if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
		v1 = int32(SQLITE_STAT4_SAMPLES)
	} else {
		v1 = 0
	} /* Database connection */
	/* Maximum number of samples.  0 if STAT4 data is not collected */
	mxSample = v1
	/* Decode the three function arguments */
	_ = argc
	nCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv)))
	nColUp = nCol
	nKeyCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	/* Allocate the space required for the StatAccum object */
	n = int32(uint32(120) + uint32(8)*uint32(uint32(nColUp)))             /* StatAccum.anDLt */
	n = int32(uint32(n) + libc.Uint32FromInt64(8)*uint32(uint32(nColUp))) /* StatAccum.anEq */
	if mxSample != 0 {
		n = int32(uint32(n) + (libc.Uint32FromInt64(8)*uint32(uint32(nColUp)) + libc.Uint32FromInt64(40)*uint32(nCol+mxSample) + libc.Uint32FromInt64(8)*libc.Uint32FromInt32(3)*uint32(uint32(nColUp))*uint32(nCol+mxSample)))
	}
	p = _sqlite3DbMallocZero(tls, db, uint64(uint64(n)))
	if p == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
		return
	}
	(*TStatAccum)(unsafe.Pointer(p)).Fdb = db
	(*TStatAccum)(unsafe.Pointer(p)).FnEst = uint64(Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))))
	(*TStatAccum)(unsafe.Pointer(p)).FnRow = uint64(0)
	(*TStatAccum)(unsafe.Pointer(p)).FnLimit = int32(Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4))))
	(*TStatAccum)(unsafe.Pointer(p)).FnCol = nCol
	(*TStatAccum)(unsafe.Pointer(p)).FnKeyCol = nKeyCol
	(*TStatAccum)(unsafe.Pointer(p)).FnSkipAhead = uint8(0)
	(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt = p + 1*120
	(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq = (*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt + uintptr(nColUp)*8
	if (*TStatAccum)(unsafe.Pointer(p)).FnLimit == 0 {
		v2 = mxSample
	} else {
		v2 = 0
	}
	(*TStatAccum)(unsafe.Pointer(p)).FmxSample = v2
	if mxSample != 0 { /* Used to iterate through p->aSample[] */
		(*TStatAccum)(unsafe.Pointer(p)).FiGet = -int32(1)
		(*TStatAccum)(unsafe.Pointer(p)).FnPSample = (*TStatAccum)(unsafe.Pointer(p)).FnEst/uint64(mxSample/libc.Int32FromInt32(3)+libc.Int32FromInt32(1)) + libc.Uint64FromInt32(1)
		(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt = (*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(nColUp)*8
		(*TStatAccum)(unsafe.Pointer(p)).FiPrn = uint32(0x689e962d)*uint32(uint32(nCol)) ^ uint32(0xd0944565)*uint32(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))))
		/* Set up the StatAccum.a[] and aBest[] arrays */
		(*TStatAccum)(unsafe.Pointer(p)).Fa = (*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt + uintptr(nColUp)*8
		(*TStatAccum)(unsafe.Pointer(p)).FaBest = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(mxSample)*40
		pSpace = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(mxSample+nCol)*40
		i = 0
		for {
			if !(i < mxSample+nCol) {
				break
			}
			(*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*40))).FanEq = pSpace
			pSpace += uintptr(libc.Uint32FromInt64(8) * uint32(uint32(nColUp)))
			(*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*40))).FanLt = pSpace
			pSpace += uintptr(libc.Uint32FromInt64(8) * uint32(uint32(nColUp)))
			(*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*40))).FanDLt = pSpace
			pSpace += uintptr(libc.Uint32FromInt64(8) * uint32(uint32(nColUp)))
			goto _3
		_3:
			;
			i++
		}
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			(*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).FaBest + uintptr(i)*40))).FiCol = i
			goto _4
		_4:
			;
			i++
		}
	}
	/* Return a pointer to the allocated object to the caller.  Note that
	 ** only the pointer (the 2nd parameter) matters.  The size of the object
	 ** (given by the 3rd parameter) is never used and can be any positive
	 ** value. */
	Xsqlite3_result_blob(tls, context, p, int32(120), __ccgo_fp(_statAccumDestructor))
}

var _statInitFuncdef = TFuncDef{
	FnArg:      int8(4),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13167,
}

func init() {
	p := unsafe.Pointer(&_statInitFuncdef)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statInit)
}

// C documentation
//
//	/*
//	** pNew and pOld are both candidate non-periodic samples selected for
//	** the same column (pNew->iCol==pOld->iCol). Ignoring this column and
//	** considering only any trailing columns and the sample hash value, this
//	** function returns true if sample pNew is to be preferred over pOld.
//	** In other words, if we assume that the cardinalities of the selected
//	** column for pNew and pOld are equal, is pNew to be preferred over pOld.
//	**
//	** This function assumes that for each argument sample, the contents of
//	** the anEq[] array from pSample->anEq[pSample->iCol+1] onwards are valid.
//	*/
func _sampleIsBetterPost(tls *libc.TLS, pAccum uintptr, pNew uintptr, pOld uintptr) (r int32) {
	var i, nCol int32
	_, _ = i, nCol
	nCol = (*TStatAccum)(unsafe.Pointer(pAccum)).FnCol
	i = (*TStatSample)(unsafe.Pointer(pNew)).FiCol + int32(1)
	for {
		if !(i < nCol) {
			break
		}
		if *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pNew)).FanEq + uintptr(i)*8)) > *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pOld)).FanEq + uintptr(i)*8)) {
			return int32(1)
		}
		if *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pNew)).FanEq + uintptr(i)*8)) < *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pOld)).FanEq + uintptr(i)*8)) {
			return 0
		}
		goto _1
	_1:
		;
		i++
	}
	if (*TStatSample)(unsafe.Pointer(pNew)).FiHash > (*TStatSample)(unsafe.Pointer(pOld)).FiHash {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if pNew is to be preferred over pOld.
//	**
//	** This function assumes that for each argument sample, the contents of
//	** the anEq[] array from pSample->anEq[pSample->iCol] onwards are valid.
//	*/
func _sampleIsBetter(tls *libc.TLS, pAccum uintptr, pNew uintptr, pOld uintptr) (r int32) {
	var nEqNew, nEqOld TtRowcnt
	_, _ = nEqNew, nEqOld
	nEqNew = *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pNew)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pNew)).FiCol)*8))
	nEqOld = *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pOld)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pOld)).FiCol)*8))
	if nEqNew > nEqOld {
		return int32(1)
	}
	if nEqNew == nEqOld {
		if (*TStatSample)(unsafe.Pointer(pNew)).FiCol < (*TStatSample)(unsafe.Pointer(pOld)).FiCol {
			return int32(1)
		}
		return libc.BoolInt32((*TStatSample)(unsafe.Pointer(pNew)).FiCol == (*TStatSample)(unsafe.Pointer(pOld)).FiCol && _sampleIsBetterPost(tls, pAccum, pNew, pOld) != 0)
	}
	return 0
}

// C documentation
//
//	/*
//	** Copy the contents of sample *pNew into the p->a[] array. If necessary,
//	** remove the least desirable sample from p->a[] to make room.
//	*/
func _sampleInsert(tls *libc.TLS, p uintptr, pNew uintptr, nEqZero int32) {
	var anDLt, anEq, anLt, pMin, pOld, pSample, pUpgrade uintptr
	var i, iMin int32
	_, _, _, _, _, _, _, _, _ = anDLt, anEq, anLt, i, iMin, pMin, pOld, pSample, pUpgrade
	pSample = uintptr(0)
	/* StatAccum.nMaxEqZero is set to the maximum number of leading 0
	 ** values in the anEq[] array of any sample in StatAccum.a[]. In
	 ** other words, if nMaxEqZero is n, then it is guaranteed that there
	 ** are no samples with StatSample.anEq[m]==0 for (m>=n). */
	if nEqZero > (*TStatAccum)(unsafe.Pointer(p)).FnMaxEqZero {
		(*TStatAccum)(unsafe.Pointer(p)).FnMaxEqZero = nEqZero
	}
	if int32((*TStatSample)(unsafe.Pointer(pNew)).FisPSample) == 0 {
		pUpgrade = uintptr(0)
		/* This sample is being added because the prefix that ends in column
		 ** iCol occurs many times in the table. However, if we have already
		 ** added a sample that shares this prefix, there is no need to add
		 ** this one. Instead, upgrade the priority of the highest priority
		 ** existing sample that shares this prefix.  */
		i = (*TStatAccum)(unsafe.Pointer(p)).FnSample - int32(1)
		for {
			if !(i >= 0) {
				break
			}
			pOld = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*40
			if *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pOld)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pNew)).FiCol)*8)) == uint64(0) {
				if (*TStatSample)(unsafe.Pointer(pOld)).FisPSample != 0 {
					return
				}
				if pUpgrade == uintptr(0) || _sampleIsBetter(tls, p, pOld, pUpgrade) != 0 {
					pUpgrade = pOld
				}
			}
			goto _1
		_1:
			;
			i--
		}
		if pUpgrade != 0 {
			(*TStatSample)(unsafe.Pointer(pUpgrade)).FiCol = (*TStatSample)(unsafe.Pointer(pNew)).FiCol
			*(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pUpgrade)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pUpgrade)).FiCol)*8)) = *(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pNew)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pUpgrade)).FiCol)*8))
			goto find_new_min
		}
	}
	/* If necessary, remove sample iMin to make room for the new sample. */
	if (*TStatAccum)(unsafe.Pointer(p)).FnSample >= (*TStatAccum)(unsafe.Pointer(p)).FmxSample {
		pMin = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiMin)*40
		anEq = (*TStatSample)(unsafe.Pointer(pMin)).FanEq
		anLt = (*TStatSample)(unsafe.Pointer(pMin)).FanLt
		anDLt = (*TStatSample)(unsafe.Pointer(pMin)).FanDLt
		_sampleClear(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, pMin)
		libc.Xmemmove(tls, pMin, pMin+1*40, uint32(40)*uint32((*TStatAccum)(unsafe.Pointer(p)).FnSample-(*TStatAccum)(unsafe.Pointer(p)).FiMin-libc.Int32FromInt32(1)))
		pSample = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FnSample-int32(1))*40
		(*TStatSample)(unsafe.Pointer(pSample)).FnRowid = uint32(0)
		(*TStatSample)(unsafe.Pointer(pSample)).FanEq = anEq
		(*TStatSample)(unsafe.Pointer(pSample)).FanDLt = anDLt
		(*TStatSample)(unsafe.Pointer(pSample)).FanLt = anLt
		(*TStatAccum)(unsafe.Pointer(p)).FnSample = (*TStatAccum)(unsafe.Pointer(p)).FmxSample - int32(1)
	}
	/* The "rows less-than" for the rowid column must be greater than that
	 ** for the last sample in the p->a[] array. Otherwise, the samples would
	 ** be out of order. */
	/* Insert the new sample */
	pSample = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FnSample)*40
	_sampleCopy(tls, p, pSample, pNew)
	(*TStatAccum)(unsafe.Pointer(p)).FnSample++
	/* Zero the first nEqZero entries in the anEq[] array. */
	libc.Xmemset(tls, (*TStatSample)(unsafe.Pointer(pSample)).FanEq, 0, uint32(8)*uint32(uint32(nEqZero)))
	goto find_new_min
find_new_min:
	;
	if (*TStatAccum)(unsafe.Pointer(p)).FnSample >= (*TStatAccum)(unsafe.Pointer(p)).FmxSample {
		iMin = -int32(1)
		i = 0
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FmxSample) {
				break
			}
			if (*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*40))).FisPSample != 0 {
				goto _2
			}
			if iMin < 0 || _sampleIsBetter(tls, p, (*TStatAccum)(unsafe.Pointer(p)).Fa+uintptr(iMin)*40, (*TStatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*40) != 0 {
				iMin = i
			}
			goto _2
		_2:
			;
			i++
		}
		(*TStatAccum)(unsafe.Pointer(p)).FiMin = iMin
	}
}

// C documentation
//
//	/*
//	** Field iChng of the index being scanned has changed. So at this point
//	** p->current contains a sample that reflects the previous row of the
//	** index. The value of anEq[iChng] and subsequent anEq[] elements are
//	** correct at this point.
//	*/
func _samplePushPrevious(tls *libc.TLS, p uintptr, iChng int32) {
	var i, j, j1 int32
	var pBest uintptr
	_, _, _, _ = i, j, j1, pBest
	/* Check if any samples from the aBest[] array should be pushed
	 ** into IndexSample.a[] at this point.  */
	i = (*TStatAccum)(unsafe.Pointer(p)).FnCol - int32(2)
	for {
		if !(i >= iChng) {
			break
		}
		pBest = (*TStatAccum)(unsafe.Pointer(p)).FaBest + uintptr(i)*40
		*(*TtRowcnt)(unsafe.Pointer((*TStatSample)(unsafe.Pointer(pBest)).FanEq + uintptr(i)*8)) = *(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8))
		if (*TStatAccum)(unsafe.Pointer(p)).FnSample < (*TStatAccum)(unsafe.Pointer(p)).FmxSample || _sampleIsBetter(tls, p, pBest, (*TStatAccum)(unsafe.Pointer(p)).Fa+uintptr((*TStatAccum)(unsafe.Pointer(p)).FiMin)*40) != 0 {
			_sampleInsert(tls, p, pBest, i)
		}
		goto _1
	_1:
		;
		i--
	}
	/* Check that no sample contains an anEq[] entry with an index of
	 ** p->nMaxEqZero or greater set to zero. */
	i = (*TStatAccum)(unsafe.Pointer(p)).FnSample - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		j = (*TStatAccum)(unsafe.Pointer(p)).FnMaxEqZero
		for {
			if !(j < (*TStatAccum)(unsafe.Pointer(p)).FnCol) {
				break
			}
			goto _3
		_3:
			;
			j++
		}
		goto _2
	_2:
		;
		i--
	}
	/* Update the anEq[] fields of any samples already collected. */
	if iChng < (*TStatAccum)(unsafe.Pointer(p)).FnMaxEqZero {
		i = (*TStatAccum)(unsafe.Pointer(p)).FnSample - int32(1)
		for {
			if !(i >= 0) {
				break
			}
			j1 = iChng
			for {
				if !(j1 < (*TStatAccum)(unsafe.Pointer(p)).FnCol) {
					break
				}
				if *(*TtRowcnt)(unsafe.Pointer((*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*40))).FanEq + uintptr(j1)*8)) == uint64(0) {
					*(*TtRowcnt)(unsafe.Pointer((*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*40))).FanEq + uintptr(j1)*8)) = *(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(j1)*8))
				}
				goto _5
			_5:
				;
				j1++
			}
			goto _4
		_4:
			;
			i--
		}
		(*TStatAccum)(unsafe.Pointer(p)).FnMaxEqZero = iChng
	}
}

// C documentation
//
//	/*
//	** Implementation of the stat_push SQL function:  stat_push(P,C,R)
//	** Arguments:
//	**
//	**    P     Pointer to the StatAccum object created by stat_init()
//	**    C     Index of left-most column to differ from previous row
//	**    R     Rowid for the current row.  Might be a key record for
//	**          WITHOUT ROWID tables.
//	**
//	** The purpose of this routine is to collect statistical data and/or
//	** samples from the index being analyzed into the StatAccum object.
//	** The stat_get() SQL function will be used afterwards to
//	** retrieve the information gathered.
//	**
//	** This SQL function usually returns NULL, but might return an integer
//	** if it wants the byte-code to do special processing.
//	**
//	** The R parameter is only used for STAT4
//	*/
func _statPush(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i, iChng int32
	var nLt TtRowcnt
	var p uintptr
	var v4 Tu32
	_, _, _, _, _ = i, iChng, nLt, p, v4
	/* The three function arguments */
	p = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	iChng = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	_ = argc
	_ = context
	if (*TStatAccum)(unsafe.Pointer(p)).FnRow == uint64(0) {
		/* This is the first call to this function. Do initialization. */
		i = 0
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FnCol) {
				break
			}
			*(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8)) = uint64(1)
			goto _1
		_1:
			;
			i++
		}
	} else {
		/* Second and subsequent calls get processed here */
		if (*TStatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
			_samplePushPrevious(tls, p, iChng)
		}
		/* Update anDLt[], anLt[] and anEq[] to reflect the values that apply
		 ** to the current row of the index. */
		i = 0
		for {
			if !(i < iChng) {
				break
			}
			*(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8))++
			goto _2
		_2:
			;
			i++
		}
		i = iChng
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FnCol) {
				break
			}
			*(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt + uintptr(i)*8))++
			if (*TStatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
				*(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt + uintptr(i)*8)) += *(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8))
			}
			*(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8)) = uint64(1)
			goto _3
		_3:
			;
			i++
		}
	}
	(*TStatAccum)(unsafe.Pointer(p)).FnRow++
	if (*TStatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))) == int32(SQLITE_INTEGER) {
			_sampleSetRowidInt64(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, p+40, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))))
		} else {
			_sampleSetRowid(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, p+40, Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))), Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))))
		}
		v4 = (*TStatAccum)(unsafe.Pointer(p)).FiPrn*libc.Uint32FromInt32(1103515245) + libc.Uint32FromInt32(12345)
		(*TStatAccum)(unsafe.Pointer(p)).FiPrn = v4
		(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FiHash = v4
		nLt = *(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt + uintptr((*TStatAccum)(unsafe.Pointer(p)).FnCol-int32(1))*8))
		/* Check if this is to be a periodic sample. If so, add it. */
		if nLt/(*TStatAccum)(unsafe.Pointer(p)).FnPSample != (nLt+uint64(1))/(*TStatAccum)(unsafe.Pointer(p)).FnPSample {
			(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FisPSample = uint8(1)
			(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FiCol = 0
			_sampleInsert(tls, p, p+40, (*TStatAccum)(unsafe.Pointer(p)).FnCol-int32(1))
			(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FisPSample = uint8(0)
		}
		/* Update the aBest[] array. */
		i = 0
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FnCol-int32(1)) {
				break
			}
			(*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FiCol = i
			if i >= iChng || _sampleIsBetterPost(tls, p, p+40, (*TStatAccum)(unsafe.Pointer(p)).FaBest+uintptr(i)*40) != 0 {
				_sampleCopy(tls, p, (*TStatAccum)(unsafe.Pointer(p)).FaBest+uintptr(i)*40, p+40)
			}
			goto _5
		_5:
			;
			i++
		}
	} else {
		if (*TStatAccum)(unsafe.Pointer(p)).FnLimit != 0 && (*TStatAccum)(unsafe.Pointer(p)).FnRow > uint64((*TStatAccum)(unsafe.Pointer(p)).FnLimit)*uint64(int32((*TStatAccum)(unsafe.Pointer(p)).FnSkipAhead)+libc.Int32FromInt32(1)) {
			(*TStatAccum)(unsafe.Pointer(p)).FnSkipAhead++
			Xsqlite3_result_int(tls, context, libc.BoolInt32(*(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt)) > uint64(0)))
		}
	}
}

var _statPushFuncdef = TFuncDef{
	FnArg:      int8(libc.Int32FromInt32(2) + libc.Int32FromInt32(IsStat4)),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13177,
}

func init() {
	p := unsafe.Pointer(&_statPushFuncdef)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statPush)
}

// C documentation
//
//	/*
//	** Implementation of the stat_get(P,J) SQL function.  This routine is
//	** used to query statistical information that has been gathered into
//	** the StatAccum object by prior calls to stat_push().  The P parameter
//	** has type BLOB but it is really just a pointer to the StatAccum object.
//	** The content to returned is determined by the parameter J
//	** which is one of the STAT_GET_xxxx values defined above.
//	**
//	** The stat_get(P,J) function is not available to generic SQL.  It is
//	** inserted as part of a manually constructed bytecode program.  (See
//	** the callStatGet() routine below.)  It is guaranteed that the P
//	** parameter will always be a pointer to a StatAccum object, never a
//	** NULL.
//	**
//	** If STAT4 is not enabled, then J is always
//	** STAT_GET_STAT1 and is hence omitted and this routine becomes
//	** a one-parameter function, stat_get(P), that always returns the
//	** stat1 table entry information.
//	*/
func _statGet(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aCnt, p, pS uintptr
	var eCall, i, i1 int32
	var iVal, nDistinct Tu64
	var v1 uint64
	var _ /* sStat at bp+0 */ Tsqlite3_str
	var _ /* sStat at bp+24 */ Tsqlite3_str
	_, _, _, _, _, _, _, _, _ = aCnt, eCall, i, i1, iVal, nDistinct, p, pS, v1
	p = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	/* STAT4 has a parameter on this routine. */
	eCall = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	if eCall == STAT_GET_STAT1 {
		/* Loop counter */
		_sqlite3StrAccumInit(tls, bp, uintptr(0), uintptr(0), 0, ((*TStatAccum)(unsafe.Pointer(p)).FnKeyCol+int32(1))*int32(100))
		if (*TStatAccum)(unsafe.Pointer(p)).FnSkipAhead != 0 {
			v1 = (*TStatAccum)(unsafe.Pointer(p)).FnEst
		} else {
			v1 = (*TStatAccum)(unsafe.Pointer(p)).FnRow
		}
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+13187, libc.VaList(bp+56, v1))
		i = 0
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FnKeyCol) {
				break
			}
			nDistinct = *(*TtRowcnt)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt + uintptr(i)*8)) + uint64(1)
			iVal = ((*TStatAccum)(unsafe.Pointer(p)).FnRow + nDistinct - uint64(1)) / nDistinct
			if iVal == uint64(2) && (*TStatAccum)(unsafe.Pointer(p)).FnRow*uint64(10) <= nDistinct*uint64(11) {
				iVal = uint64(1)
			}
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+13192, libc.VaList(bp+56, iVal))
			goto _2
		_2:
			;
			i++
		}
		_sqlite3ResultStrAccum(tls, context, bp)
	} else {
		if eCall == int32(STAT_GET_ROWID) {
			if (*TStatAccum)(unsafe.Pointer(p)).FiGet < 0 {
				_samplePushPrevious(tls, p, 0)
				(*TStatAccum)(unsafe.Pointer(p)).FiGet = 0
			}
			if (*TStatAccum)(unsafe.Pointer(p)).FiGet < (*TStatAccum)(unsafe.Pointer(p)).FnSample {
				pS = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*40
				if (*TStatSample)(unsafe.Pointer(pS)).FnRowid == uint32(0) {
					Xsqlite3_result_int64(tls, context, *(*Ti64)(unsafe.Pointer(pS + 16)))
				} else {
					Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(pS)).Fu)), int32((*TStatSample)(unsafe.Pointer(pS)).FnRowid), uintptr(-libc.Int32FromInt32(1)))
				}
			}
		} else {
			aCnt = uintptr(0)
			switch eCall {
			case int32(STAT_GET_NEQ):
				aCnt = (*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*40))).FanEq
			case int32(STAT_GET_NLT):
				aCnt = (*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*40))).FanLt
			default:
				aCnt = (*(*TStatSample)(unsafe.Pointer((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*40))).FanDLt
				(*TStatAccum)(unsafe.Pointer(p)).FiGet++
				break
			}
			_sqlite3StrAccumInit(tls, bp+24, uintptr(0), uintptr(0), 0, (*TStatAccum)(unsafe.Pointer(p)).FnCol*int32(100))
			i1 = 0
			for {
				if !(i1 < (*TStatAccum)(unsafe.Pointer(p)).FnCol) {
					break
				}
				Xsqlite3_str_appendf(tls, bp+24, __ccgo_ts+13198, libc.VaList(bp+56, *(*TtRowcnt)(unsafe.Pointer(aCnt + uintptr(i1)*8))))
				goto _3
			_3:
				;
				i1++
			}
			if (*(*Tsqlite3_str)(unsafe.Pointer(bp + 24))).FnChar != 0 {
				(*(*Tsqlite3_str)(unsafe.Pointer(bp + 24))).FnChar--
			}
			_sqlite3ResultStrAccum(tls, context, bp+24)
		}
	}
	_ = argc
}

var _statGetFuncdef = TFuncDef{
	FnArg:      int8(libc.Int32FromInt32(1) + libc.Int32FromInt32(IsStat4)),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13204,
}

func init() {
	p := unsafe.Pointer(&_statGetFuncdef)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statGet)
}

func _callStatGet(tls *libc.TLS, pParse uintptr, regStat int32, iParam int32, regOut int32) {
	_sqlite3VdbeAddOp2(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Integer), iParam, regStat+int32(1))
	_sqlite3VdbeAddFunctionCall(tls, pParse, 0, regStat, regOut, libc.Int32FromInt32(1)+libc.Int32FromInt32(IsStat4), uintptr(unsafe.Pointer(&_statGetFuncdef)), 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, v10, v11, v12, v14, v18, 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, v10, v11, v12, v14, v18, 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++ /* True to count the table */
	regNewRowid = v1
	v2 = iMem
	iMem++ /* Rowid for the inserted record */
	regStat = v2
	v3 = iMem
	iMem++ /* Register to hold StatAccum object */
	regChng = v3
	v4 = iMem
	iMem++ /* Index of changed index field */
	regRowid = v4
	v5 = iMem
	iMem++ /* Rowid argument passed to stat_push() */
	regTemp = v5
	v6 = iMem
	iMem++ /* Temporary use register */
	regTemp2 = v6
	v7 = iMem
	iMem++ /* Second temporary use register */
	regTabname = v7
	v8 = iMem
	iMem++ /* Register containing table name */
	regIdxname = v8
	v9 = iMem
	iMem++            /* 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 !(int32((*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+13213, (*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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName) != 0 {
		return
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
		pStat1 = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint32FromInt64(64)+libc.Uint32FromInt32(13)))
		if pStat1 == uintptr(0) {
			return
		}
		(*TTable)(unsafe.Pointer(pStat1)).FzName = pStat1 + 1*64
		libc.Xmemcpy(tls, (*TTable)(unsafe.Pointer(pStat1)).FzName, __ccgo_ts+13016, uint32(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(6))
	}
	/* 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)
	v10 = iTab
	iTab++
	iTabCur = v10
	v11 = iTab
	iTab++
	iIdxCur = v11
	if (*TParse)(unsafe.Pointer(pParse)).FnTab > iTab {
		v12 = (*TParse)(unsafe.Pointer(pParse)).FnTab
	} else {
		v12 = iTab
	}
	(*TParse)(unsafe.Pointer(pParse)).FnTab = v12
	_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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
			nCol = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
			zIdxName = (*TTable)(unsafe.Pointer(pTab)).FzName
			nColTest = nCol - int32(1)
		} else {
			nCol = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
			zIdxName = (*TIndex)(unsafe.Pointer(pIdx)).FzName
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x8>>3)) != 0 {
				v14 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) - int32(1)
			} else {
				v14 = nCol - int32(1)
			}
			nColTest = v14
		}
		/* 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, int32((*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), int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), regRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Count), iIdxCur, regTemp, libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(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(uint32(4)*uint32(uint32(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) && int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == int32(1) && int32((*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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*4)))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), i, regChng)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regTemp)
				*(*int32)(unsafe.Pointer(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++
			}
			_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)(unsafe.Pointer(aGotoChng + uintptr(i)*4)))
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regPrev+i)
				goto _16
			_16:
				;
				i++
			}
			_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&uint32(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, int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
				j = 0
				for {
					if !(j < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
						break
					}
					k = int32(_sqlite3TableColumnToIndex(tls, pIdx, *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, k, regKey+j)
					goto _17
				_17:
					;
					j++
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regKey, int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol), regRowid)
				_sqlite3ReleaseTempRange(tls, pParse, regKey, int32((*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+13223, 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&uint32(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) {
				v18 = int32(OP_NotExists)
			} else {
				v18 = int32(OP_NotFound)
			}
			seekOp = uint8(v18)
			/* 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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
						nColX = int32((*TIndex)(unsafe.Pointer(pX)).FnKeyCol)
					} else {
						nColX = int32((*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, int32(int32(seekOp)), iTabCur, addrNext, regSampleRowid, 0)
			i = 0
			for {
				if !(i < nCol) {
					break
				}
				_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iTabCur, i, regCol+i)
				goto _20
			_20:
				;
				i++
			}
			_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+13223, 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
//
//	/*
//	** Generate code that will cause the most recent index analysis to
//	** be loaded into internal hash tables where is can be used.
//	*/
func _loadAnalysis(tls *libc.TLS, pParse uintptr, iDb int32) {
	var v uintptr
	_ = v
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3VdbeAddOp1(tls, v, int32(OP_LoadAnalysis), iDb)
	}
}

// C documentation
//
//	/*
//	** Generate code that will do an analysis of an entire database
//	*/
func _analyzeDatabase(tls *libc.TLS, pParse uintptr, iDb int32) {
	var db, k, pSchema, pTab uintptr
	var iMem, iStatCur, iTab int32
	_, _, _, _, _, _, _ = db, iMem, iStatCur, iTab, k, pSchema, pTab
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	iStatCur = (*TParse)(unsafe.Pointer(pParse)).FnTab
	*(*int32)(unsafe.Pointer(pParse + 40)) += int32(3)
	_openStatTable(tls, pParse, iDb, iStatCur, uintptr(0), uintptr(0))
	iMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	iTab = (*TParse)(unsafe.Pointer(pParse)).FnTab
	k = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
	for {
		if !(k != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(k)).Fdata
		_analyzeOneTable(tls, pParse, pTab, uintptr(0), iStatCur, iMem, iTab)
		iMem = _sqlite3FirstAvailableRegister(tls, pParse, iMem)
		goto _1
	_1:
		;
		k = (*THashElem)(unsafe.Pointer(k)).Fnext
	}
	_loadAnalysis(tls, pParse, iDb)
}

// C documentation
//
//	/*
//	** Generate code that will do an analysis of a single table in
//	** a database.  If pOnlyIdx is not NULL then it is a single index
//	** in pTab that should be analyzed.
//	*/
func _analyzeTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr) {
	var iDb, iStatCur int32
	_, _ = iDb, iStatCur
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	iStatCur = (*TParse)(unsafe.Pointer(pParse)).FnTab
	*(*int32)(unsafe.Pointer(pParse + 40)) += int32(3)
	if pOnlyIdx != 0 {
		_openStatTable(tls, pParse, iDb, iStatCur, (*TIndex)(unsafe.Pointer(pOnlyIdx)).FzName, __ccgo_ts+13227)
	} else {
		_openStatTable(tls, pParse, iDb, iStatCur, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+13231)
	}
	_analyzeOneTable(tls, pParse, pTab, pOnlyIdx, iStatCur, (*TParse)(unsafe.Pointer(pParse)).FnMem+int32(1), (*TParse)(unsafe.Pointer(pParse)).FnTab)
	_loadAnalysis(tls, pParse, iDb)
}

// C documentation
//
//	/*
//	** Generate code for the ANALYZE command.  The parser calls this routine
//	** when it recognizes an ANALYZE command.
//	**
//	**        ANALYZE                            -- 1
//	**        ANALYZE  <database>                -- 2
//	**        ANALYZE  ?<database>.?<tablename>  -- 3
//	**
//	** Form 1 causes all indices in all attached databases to be analyzed.
//	** Form 2 analyzes all indices the single database named.
//	** Form 3 analyzes all indices associated with the named table.
//	*/
func _sqlite3Analyze(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pIdx, pTab, v, z, zDb, v4, v5, v6, v7 uintptr
	var i, iDb, v2 int32
	var v3, v8 bool
	var _ /* pTableName at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, iDb, pIdx, pTab, v, z, zDb, v2, v3, v4, v5, v6, v7, v8
	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 SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		return
	}
	if pName1 == uintptr(0) {
		/* Form 1:  Analyze everything */
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if i == int32(1) {
				goto _1
			} /* Do not analyze the TEMP database */
			_analyzeDatabase(tls, pParse, i)
			goto _1
		_1:
			;
			i++
		}
	} else {
		if v3 = (*TToken)(unsafe.Pointer(pName2)).Fn == uint32(0); v3 {
			v2 = _sqlite3FindDb(tls, db, pName1)
			iDb = v2
		}
		if v3 && v2 >= 0 {
			/* Analyze the schema named as the argument */
			_analyzeDatabase(tls, pParse, iDb)
		} else {
			/* Form 3: Analyze the table or index named as an argument */
			iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
			if iDb >= 0 {
				if (*TToken)(unsafe.Pointer(pName2)).Fn != 0 {
					v4 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
				} else {
					v4 = uintptr(0)
				}
				zDb = v4
				z = _sqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
				if z != 0 {
					v5 = _sqlite3FindIndex(tls, db, z, zDb)
					pIdx = v5
					if v5 != uintptr(0) {
						_analyzeTable(tls, pParse, (*TIndex)(unsafe.Pointer(pIdx)).FpTable, pIdx)
					} else {
						v6 = _sqlite3LocateTable(tls, pParse, uint32(0), z, zDb)
						pTab = v6
						if v6 != uintptr(0) {
							_analyzeTable(tls, pParse, pTab, uintptr(0))
						}
					}
					_sqlite3DbFree(tls, db, z)
				}
			}
		}
	}
	if v8 = int32((*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec) == 0; v8 {
		v7 = _sqlite3GetVdbe(tls, pParse)
		v = v7
	}
	if v8 && v7 != uintptr(0) {
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Expire))
	}
}

// C documentation
//
//	/*
//	** Used to pass information from the analyzer reader through to the
//	** callback routine.
//	*/
type TanalysisInfo = struct {
	Fdb        uintptr
	FzDatabase uintptr
}

type analysisInfo = TanalysisInfo

type TanalysisInfo1 = struct {
	Fdb        uintptr
	FzDatabase uintptr
}

type analysisInfo1 = TanalysisInfo1

// 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 + 1672
	}
	i = 0
	for {
		if !(*(*int8)(unsafe.Pointer(z)) != 0 && i < nOut) {
			break
		}
		v = uint64(0)
		for {
			v2 = int32(*(*int8)(unsafe.Pointer(z)))
			c = v2
			if !(v2 >= int32('0') && c <= int32('9')) {
				break
			}
			v = v*uint64(10) + uint64(uint64(c)) - uint64('0')
			z++
		}
		if aOut != 0 {
			*(*TtRowcnt)(unsafe.Pointer(aOut + uintptr(i)*8)) = v
		}
		if aLog != 0 {
			*(*TLogEst)(unsafe.Pointer(aLog + uintptr(i)*2)) = _sqlite3LogEst(tls, v)
		}
		if int32(*(*int8)(unsafe.Pointer(z))) == int32(' ') {
			z++
		}
		goto _1
	_1:
		;
		i++
	}
	if pIndex != 0 {
		libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 2, 0x4)
		libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 6, 0x40)
		for *(*int8)(unsafe.Pointer(z)) != 0 {
			if Xsqlite3_strglob(tls, __ccgo_ts+13235, z) == 0 {
				libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 2, 0x4)
			} else {
				if Xsqlite3_strglob(tls, __ccgo_ts+13246, z) == 0 {
					sz = _sqlite3Atoi(tls, z+uintptr(3))
					if sz < int32(2) {
						sz = int32(2)
					}
					(*TIndex)(unsafe.Pointer(pIndex)).FszIdxRow = _sqlite3LogEst(tls, uint64(uint64(sz)))
				} else {
					if Xsqlite3_strglob(tls, __ccgo_ts+13256, z) == 0 {
						libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 6, 0x40)
					}
				}
			}
			for int32(*(*int8)(unsafe.Pointer(z))) != 0 && int32(*(*int8)(unsafe.Pointer(z))) != int32(' ') {
				z++
			}
			for int32(*(*int8)(unsafe.Pointer(z))) == int32(' ') {
				z++
			}
		}
		/* Set the bLowQual flag if the peak number of rows obtained
		 ** from a full equality match is so large that a full table scan
		 ** seems likely to be faster than using the index.
		 */
		if int32(*(*TLogEst)(unsafe.Pointer(aLog))) > int32(66) && int32(*(*TLogEst)(unsafe.Pointer(aLog))) <= int32(*(*TLogEst)(unsafe.Pointer(aLog + uintptr(nOut-int32(1))*2))) {
			libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 8, 0x100)
		}
	}
}

// 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(112)
	defer tls.Free(112)
	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)(unsafe.Pointer(argv)) == uintptr(0) || *(*uintptr)(unsafe.Pointer(argv + 2*4)) == uintptr(0) {
		return 0
	}
	pTable = _sqlite3FindTable(tls, (*TanalysisInfo)(unsafe.Pointer(pInfo)).Fdb, *(*uintptr)(unsafe.Pointer(argv)), (*TanalysisInfo)(unsafe.Pointer(pInfo)).FzDatabase)
	if pTable == uintptr(0) {
		return 0
	}
	if *(*uintptr)(unsafe.Pointer(argv + 1*4)) == uintptr(0) {
		pIndex = uintptr(0)
	} else {
		if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*4))) == 0 {
			pIndex = _sqlite3PrimaryKeyIndex(tls, pTable)
		} else {
			pIndex = _sqlite3FindIndex(tls, (*TanalysisInfo)(unsafe.Pointer(pInfo)).Fdb, *(*uintptr)(unsafe.Pointer(argv + 1*4)), (*TanalysisInfo)(unsafe.Pointer(pInfo)).FzDatabase)
		}
	}
	z = *(*uintptr)(unsafe.Pointer(argv + 2*4))
	if pIndex != 0 {
		aiRowEst = uintptr(0)
		nCol = int32((*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(uint32(8)*uint32(uint32(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+56, libc.Uint32FromInt32(0), 2, 0x4)
		_decodeIntArray(tls, z, nCol, aiRowEst, (*TIndex)(unsafe.Pointer(pIndex)).FaiRowLogEst, pIndex)
		libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 7, 0x80)
		if (*TIndex)(unsafe.Pointer(pIndex)).FpPartIdxWhere == uintptr(0) {
			(*TTable)(unsafe.Pointer(pTable)).FnRowLogEst = *(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiRowLogEst))
			*(*Tu32)(unsafe.Pointer(pTable + 28)) |= uint32(TF_HasStat1)
		}
	} else {
		(*(*TIndex)(unsafe.Pointer(bp))).FszIdxRow = (*TTable)(unsafe.Pointer(pTable)).FszTabRow
		_decodeIntArray(tls, z, int32(1), uintptr(0), pTable+38, bp)
		(*TTable)(unsafe.Pointer(pTable)).FszTabRow = (*(*TIndex)(unsafe.Pointer(bp))).FszIdxRow
		*(*Tu32)(unsafe.Pointer(pTable + 28)) |= uint32(TF_HasStat1)
	}
	return 0
}

// C documentation
//
//	/*
//	** If the Index.aSample variable is not NULL, delete the aSample[] array
//	** and its contents.
//	*/
func _sqlite3DeleteIndexSamples(tls *libc.TLS, db uintptr, pIdx uintptr) {
	var j int32
	var p uintptr
	_, _ = j, p
	if (*TIndex)(unsafe.Pointer(pIdx)).FaSample != 0 {
		j = 0
		for {
			if !(j < (*TIndex)(unsafe.Pointer(pIdx)).FnSample) {
				break
			}
			p = (*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(j)*20
			_sqlite3DbFree(tls, db, (*TIndexSample)(unsafe.Pointer(p)).Fp)
			goto _1
		_1:
			;
			j++
		}
		_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer(pIdx)).FaSample)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		(*TIndex)(unsafe.Pointer(pIdx)).FnSample = 0
		(*TIndex)(unsafe.Pointer(pIdx)).FaSample = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Populate the pIdx->aAvgEq[] array based on the samples currently
//	** stored in pIdx->aSample[].
//	*/
func _initAvgEq(tls *libc.TLS, pIdx uintptr) {
	var aSample, pFinal uintptr
	var avgEq, nRow, sumEq TtRowcnt
	var i, iCol, nCol, nSample int32
	var nDist100, nSum100 Ti64
	_, _, _, _, _, _, _, _, _, _, _ = aSample, avgEq, i, iCol, nCol, nDist100, nRow, nSample, nSum100, pFinal, sumEq
	if pIdx != 0 {
		aSample = (*TIndex)(unsafe.Pointer(pIdx)).FaSample
		pFinal = aSample + uintptr((*TIndex)(unsafe.Pointer(pIdx)).FnSample-int32(1))*20
		nCol = int32(1)
		if (*TIndex)(unsafe.Pointer(pIdx)).FnSampleCol > int32(1) {
			/* If this is stat4 data, then calculate aAvgEq[] values for all
			 ** sample columns except the last. The last is always set to 1, as
			 ** once the trailing PK fields are considered all index keys are
			 ** unique.  */
			nCol = (*TIndex)(unsafe.Pointer(pIdx)).FnSampleCol - int32(1)
			*(*TtRowcnt)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaAvgEq + uintptr(nCol)*8)) = uint64(1)
		}
		iCol = 0
		for {
			if !(iCol < nCol) {
				break
			}
			nSample = (*TIndex)(unsafe.Pointer(pIdx)).FnSample /* Used to iterate through samples */
			sumEq = uint64(0)                                  /* Sum of the nEq values */
			avgEq = uint64(0)                                  /* Number of rows in index */
			nSum100 = 0                                        /* Number of distinct values in index */
			if !((*TIndex)(unsafe.Pointer(pIdx)).FaiRowEst != 0) || iCol >= int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) || *(*TtRowcnt)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiRowEst + uintptr(iCol+int32(1))*8)) == uint64(0) {
				nRow = *(*TtRowcnt)(unsafe.Pointer((*TIndexSample)(unsafe.Pointer(pFinal)).FanLt + uintptr(iCol)*8))
				nDist100 = int64(uint64(libc.Int64FromInt32(100)) * *(*TtRowcnt)(unsafe.Pointer((*TIndexSample)(unsafe.Pointer(pFinal)).FanDLt + uintptr(iCol)*8)))
				nSample--
			} else {
				nRow = *(*TtRowcnt)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiRowEst))
				nDist100 = int64(uint64(libc.Int64FromInt32(100)) * *(*TtRowcnt)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiRowEst)) / *(*TtRowcnt)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiRowEst + uintptr(iCol+int32(1))*8)))
			}
			(*TIndex)(unsafe.Pointer(pIdx)).FnRowEst0 = nRow
			/* Set nSum to the number of distinct (iCol+1) field prefixes that
			 ** occur in the stat4 table for this index. Set sumEq to the sum of
			 ** the nEq values for column iCol for the same set (adding the value
			 ** only once where there exist duplicate prefixes).  */
			i = 0
			for {
				if !(i < nSample) {
					break
				}
				if i == (*TIndex)(unsafe.Pointer(pIdx)).FnSample-int32(1) || *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(i)*20))).FanDLt + uintptr(iCol)*8)) != *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(i+int32(1))*20))).FanDLt + uintptr(iCol)*8)) {
					sumEq += *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(i)*20))).FanEq + uintptr(iCol)*8))
					nSum100 += int64(100)
				}
				goto _2
			_2:
				;
				i++
			}
			if nDist100 > nSum100 && sumEq < nRow {
				avgEq = uint64(libc.Int64FromInt32(100)) * (nRow - sumEq) / uint64(nDist100-nSum100)
			}
			if avgEq == uint64(0) {
				avgEq = uint64(1)
			}
			*(*TtRowcnt)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaAvgEq + uintptr(iCol)*8)) = avgEq
			goto _1
		_1:
			;
			iCol++
		}
	}
}

// C documentation
//
//	/*
//	** Look up an index by name.  Or, if the name of a WITHOUT ROWID table
//	** is supplied instead, find the PRIMARY KEY index for that table.
//	*/
func _findIndexOrPrimaryKey(tls *libc.TLS, db uintptr, zName uintptr, zDb uintptr) (r uintptr) {
	var pIdx, pTab uintptr
	_, _ = pIdx, pTab
	pIdx = _sqlite3FindIndex(tls, db, zName, zDb)
	if pIdx == uintptr(0) {
		pTab = _sqlite3FindTable(tls, db, zName, zDb)
		if pTab != 0 && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			pIdx = _sqlite3PrimaryKeyIndex(tls, pTab)
		}
	}
	return pIdx
}

// 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, nCol, nIdxCol, nSample, rc int32
	var pIdx, pIdx1, pPrevIdx, pSample, pSpace, zIndex, zIndex1, zSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, nByte, nCol, nIdxCol, nSample, pIdx, pIdx1, pPrevIdx, pSample, pSpace, rc, zIndex, zIndex1, zSql /* Result codes from subroutines */
	*(*uintptr)(unsafe.Pointer(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)(unsafe.Pointer(bp))) == int32(SQLITE_ROW) {
		nIdxCol = int32(1)
		zIndex = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
		if zIndex == uintptr(0) {
			continue
		}
		nSample = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
			nIdxCol = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		} else {
			nIdxCol = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		}
		(*TIndex)(unsafe.Pointer(pIdx)).FnSampleCol = nIdxCol
		(*TIndex)(unsafe.Pointer(pIdx)).FmxSample = nSample
		nByte = int32(uint32(20) * uint32(uint32(nSample)))
		nByte = int32(uint32(nByte) + libc.Uint32FromInt64(8)*uint32(uint32(nIdxCol))*libc.Uint32FromInt32(3)*uint32(uint32(nSample)))
		nByte = int32(uint32(nByte) + uint32(uint32(nIdxCol))*libc.Uint32FromInt64(8)) /* Space for Index.aAvgEq[] */
		(*TIndex)(unsafe.Pointer(pIdx)).FaSample = _sqlite3DbMallocZero(tls, db, uint64(uint64(nByte)))
		if (*TIndex)(unsafe.Pointer(pIdx)).FaSample == uintptr(0) {
			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return int32(SQLITE_NOMEM)
		}
		pSpace = (*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(nSample)*20
		(*TIndex)(unsafe.Pointer(pIdx)).FaAvgEq = pSpace
		pSpace += uintptr(nIdxCol) * 8
		*(*Tu32)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable + 28)) |= uint32(TF_HasStat4)
		i = 0
		for {
			if !(i < nSample) {
				break
			}
			(*(*TIndexSample)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*20))).FanEq = pSpace
			pSpace += uintptr(nIdxCol) * 8
			(*(*TIndexSample)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*20))).FanLt = pSpace
			pSpace += uintptr(nIdxCol) * 8
			(*(*TIndexSample)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*20))).FanDLt = pSpace
			pSpace += uintptr(nIdxCol) * 8
			goto _1
		_1:
			;
			i++
		}
	}
	rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(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)(unsafe.Pointer(bp))) == int32(SQLITE_ROW) { /* Pointer to the index object */
		nCol = int32(1) /* Number of columns in index */
		zIndex1 = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(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)*20
		_decodeIntArray(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanEq, uintptr(0), uintptr(0))
		_decodeIntArray(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanLt, uintptr(0), uintptr(0))
		_decodeIntArray(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(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)(unsafe.Pointer(bp)), int32(4))
		(*TIndexSample)(unsafe.Pointer(pSample)).Fp = _sqlite3DbMallocZero(tls, db, uint64((*TIndexSample)(unsafe.Pointer(pSample)).Fn+int32(8)))
		if (*TIndexSample)(unsafe.Pointer(pSample)).Fp == uintptr(0) {
			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(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)(unsafe.Pointer(bp)), int32(4)), uint32((*TIndexSample)(unsafe.Pointer(pSample)).Fn))
		}
		(*TIndex)(unsafe.Pointer(pIdx1)).FnSample++
	}
	rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == SQLITE_OK {
		_initAvgEq(tls, pPrevIdx)
	}
	return rc
}

// C documentation
//
//	/*
//	** Load content from the sqlite_stat4 table into
//	** the Index.aSample[] arrays of all indices.
//	*/
func _loadStat4(tls *libc.TLS, db uintptr, zDb uintptr) (r int32) {
	var pStat4, v1 uintptr
	var rc int32
	var v2 bool
	_, _, _, _ = pStat4, rc, v1, v2
	rc = SQLITE_OK
	if v2 = (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0); v2 {
		v1 = _sqlite3FindTable(tls, db, __ccgo_ts+13042, zDb)
		pStat4 = v1
	}
	if v2 && v1 != uintptr(0) && int32((*TTable)(unsafe.Pointer(pStat4)).FeTabType) == TABTYP_NORM {
		rc = _loadStatTbl(tls, db, __ccgo_ts+13268, __ccgo_ts+13337, zDb)
	}
	return rc
}

// 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	/* Clear any prior statistics */
	i = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(i)).Fdata
		*(*Tu32)(unsafe.Pointer(pTab + 28)) &= uint32(^libc.Int32FromInt32(TF_HasStat1))
		goto _1
	_1:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	i = (*THash)(unsafe.Pointer(pSchema + 24)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx = (*THashElem)(unsafe.Pointer(i)).Fdata
		libc.SetBitFieldPtr16Uint32(pIdx+56, libc.Uint32FromInt32(0), 7, 0x80)
		_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)(unsafe.Pointer(bp))).Fdb = db
	(*(*TanalysisInfo)(unsafe.Pointer(bp))).FzDatabase = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	v3 = _sqlite3FindTable(tls, db, __ccgo_ts+13016, (*(*TanalysisInfo)(unsafe.Pointer(bp))).FzDatabase)
	pStat1 = v3
	if v3 != 0 && int32((*TTable)(unsafe.Pointer(pStat1)).FeTabType) == TABTYP_NORM {
		zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+13389, libc.VaList(bp+16, (*(*TanalysisInfo)(unsafe.Pointer(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 + 24)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx1 = (*THashElem)(unsafe.Pointer(i)).Fdata
		if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 56))&0x80>>7)) != 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.Fsz = uint16(0)
		rc = _loadStat4(tls, db, (*(*TanalysisInfo)(unsafe.Pointer(bp))).FzDatabase)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable--
		if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			v5 = 0
		} else {
			v5 = int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(v5)
	}
	i = (*THash)(unsafe.Pointer(pSchema + 24)).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
//
//	/*
//	** Resolve an expression that was part of an ATTACH or DETACH statement. This
//	** is slightly different from resolving a normal SQL expression, because simple
//	** identifiers are treated as strings, not possible column names or aliases.
//	**
//	** i.e. if the parser sees:
//	**
//	**     ATTACH DATABASE abc AS def
//	**
//	** it treats the two expressions as literal strings 'abc' and 'def' instead of
//	** looking for columns of the same name.
//	**
//	** This only applies to the root node of pExpr, so the statement:
//	**
//	**     ATTACH DATABASE abc||def AS 'db2'
//	**
//	** will fail because neither abc or def can be resolved.
//	*/
func _resolveAttachExpr(tls *libc.TLS, pName uintptr, pExpr uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if pExpr != 0 {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_ID) {
			rc = _sqlite3ResolveExprNames(tls, pName, pExpr)
		} else {
			(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_STRING)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if zName points to a name that may be used to refer to
//	** database iDb attached to handle db.
//	*/
func _sqlite3DbIsNamed(tls *libc.TLS, db uintptr, iDb int32, zName uintptr) (r int32) {
	return libc.BoolInt32(_sqlite3StrICmp(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, zName) == 0 || iDb == 0 && _sqlite3StrICmp(tls, __ccgo_ts+7958, zName) == 0)
}

// 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(48)
	defer tls.Free(48)
	var aNew, db, pNew, pNewSchema, pPager, zFile, zName uintptr
	var i, iDb, rc int32
	var _ /* flags at bp+8 */ uint32
	var _ /* pNewBt at bp+20 */ uintptr
	var _ /* pVfs at bp+16 */ uintptr
	var _ /* zErr at bp+4 */ uintptr
	var _ /* zErrDyn at bp+12 */ 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)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* New array of Db pointers */
	pNew = uintptr(0)                                /* Db object for the newly attached database */
	*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
	_ = NotUsed
	zFile = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zName = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	if zFile == uintptr(0) {
		zFile = __ccgo_ts + 1672
	}
	if zName == uintptr(0) {
		zName = __ccgo_ts + 1672
	}
	if int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x4>>2)) != 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)(unsafe.Pointer(bp + 20)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 16)) = Xsqlite3_vfs_find(tls, __ccgo_ts+5340)
		if *(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0) {
			return
		}
		rc = _sqlite3BtreeOpen(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), __ccgo_ts+13430, db, bp+20, 0, int32(SQLITE_OPEN_MAIN_DB))
		if rc == SQLITE_OK {
			pNewSchema = _sqlite3SchemaGet(tls, db, *(*uintptr)(unsafe.Pointer(bp + 20)))
			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.  */
				pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)*16
				if (*TDb)(unsafe.Pointer(pNew)).FpBt != 0 {
					_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
				}
				(*TDb)(unsafe.Pointer(pNew)).FpBt = *(*uintptr)(unsafe.Pointer(bp + 20))
				(*TDb)(unsafe.Pointer(pNew)).FpSchema = pNewSchema
			} else {
				_sqlite3BtreeClose(tls, *(*uintptr)(unsafe.Pointer(bp + 20)))
				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)(unsafe.Pointer(db + 120 + 7*4))+int32(2) {
			*(*uintptr)(unsafe.Pointer(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13433, libc.VaList(bp+32, *(*int32)(unsafe.Pointer(db + 120 + 7*4))))
			goto attach_error
		}
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if _sqlite3DbIsNamed(tls, db, i, zName) != 0 {
				*(*uintptr)(unsafe.Pointer(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13470, libc.VaList(bp+32, zName))
				goto attach_error
			}
			goto _1
		_1:
			;
			i++
		}
		/* Allocate the new entry in the db->aDb[] array and initialize the schema
		 ** hash tables.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FaDb == db+476 {
			aNew = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint32FromInt64(16)*libc.Uint32FromInt32(3)))
			if aNew == uintptr(0) {
				return
			}
			libc.Xmemcpy(tls, aNew, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint32FromInt64(16)*libc.Uint32FromInt32(2))
		} else {
			aNew = _sqlite3DbRealloc(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, uint64(uint32(16)*uint32((*Tsqlite3)(unsafe.Pointer(db)).FnDb+libc.Int32FromInt32(1))))
			if aNew == uintptr(0) {
				return
			}
		}
		(*Tsqlite3)(unsafe.Pointer(db)).FaDb = aNew
		pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).FnDb)*16
		libc.Xmemset(tls, pNew, 0, uint32(16))
		/* 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)(unsafe.Pointer(bp + 8)) = (*Tsqlite3)(unsafe.Pointer(db)).FopenFlags
		rc = _sqlite3ParseUri(tls, (*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpVfs)).FzName, zFile, bp+8, bp+16, bp, bp+4)
		if rc != SQLITE_OK {
			if rc == int32(SQLITE_NOMEM) {
				_sqlite3OomFault(tls, db)
			}
			Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 4)), -int32(1))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
			return
		}
		*(*uint32)(unsafe.Pointer(bp + 8)) |= uint32(SQLITE_OPEN_MAIN_DB)
		rc = _sqlite3BtreeOpen(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), *(*uintptr)(unsafe.Pointer(bp)), db, pNew+4, 0, int32(*(*uint32)(unsafe.Pointer(bp + 8))))
		(*Tsqlite3)(unsafe.Pointer(db)).FnDb++
		(*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)(unsafe.Pointer(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13500, 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 && int32((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pNew)).FpSchema)).Fenc) != int32((*Tsqlite3)(unsafe.Pointer(db)).Fenc) {
					*(*uintptr)(unsafe.Pointer(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13529, 0)
					rc = int32(SQLITE_ERROR)
				}
			}
			_sqlite3BtreeEnter(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			pPager = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			_sqlite3PagerLockingMode(tls, pPager, int32((*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode))
			_sqlite3BtreeSecureDelete(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt, _sqlite3BtreeSecureDelete(tls, (*(*TDb)(unsafe.Pointer((*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 = uint8(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)(unsafe.Pointer(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)(unsafe.Pointer(db + 24)) &= uint32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
		if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x4>>2)) != 0) {
			rc = _sqlite3Init(tls, db, bp+12)
		}
		_sqlite3BtreeLeaveAll(tls, db)
	}
	if rc != 0 {
		if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x4>>2)) != 0) {
			iDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
			if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt != 0 {
				_sqlite3BtreeClose(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt)
				(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt = uintptr(0)
				(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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)(unsafe.Pointer(bp + 12)))
				*(*uintptr)(unsafe.Pointer(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+1642, 0)
			} else {
				if *(*uintptr)(unsafe.Pointer(bp + 12)) == uintptr(0) {
					*(*uintptr)(unsafe.Pointer(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13597, libc.VaList(bp+32, zFile))
				}
			}
		}
		goto attach_error
	}
	return
	goto attach_error
attach_error:
	;
	/* Return an error if we get here */
	if *(*uintptr)(unsafe.Pointer(bp + 12)) != 0 {
		Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 12)), -int32(1))
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 12)))
	}
	if rc != 0 {
		Xsqlite3_result_error_code(tls, context, rc)
	}
}

// C documentation
//
//	/*
//	** An SQL user-function registered to do the work of an DETACH statement. The
//	** three arguments to the function come directly from a detach statement:
//	**
//	**     DETACH DATABASE x
//	**
//	**     SELECT sqlite_detach(x)
//	*/
func _detachFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var db, pDb, pEntry, pTrig, zName uintptr
	var i int32
	var _ /* zErr at bp+0 */ [128]int8
	_, _, _, _, _, _ = db, i, pDb, pEntry, pTrig, zName
	zName = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	db = Xsqlite3_context_db_handle(tls, context)
	pDb = uintptr(0)
	_ = NotUsed
	if zName == uintptr(0) {
		zName = __ccgo_ts + 1672
	}
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16
		if (*TDb)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
			goto _1
		}
		if _sqlite3DbIsNamed(tls, db, i, zName) != 0 {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	if i >= (*Tsqlite3)(unsafe.Pointer(db)).FnDb {
		Xsqlite3_snprintf(tls, int32(128), bp, __ccgo_ts+13625, libc.VaList(bp+136, zName))
		goto detach_error
	}
	if i < int32(2) {
		Xsqlite3_snprintf(tls, int32(128), bp, __ccgo_ts+13646, libc.VaList(bp+136, zName))
		goto detach_error
	}
	if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt) != SQLITE_TXN_NONE || _sqlite3BtreeIsInBackup(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt) != 0 {
		Xsqlite3_snprintf(tls, int32(128), bp, __ccgo_ts+13672, libc.VaList(bp+136, zName))
		goto detach_error
	}
	/* If any TEMP triggers reference the schema being detached, move those
	 ** triggers to reference the TEMP schema itself. */
	pEntry = (*THash)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 40)).Ffirst
	for pEntry != 0 {
		pTrig = (*THashElem)(unsafe.Pointer(pEntry)).Fdata
		if (*TTrigger)(unsafe.Pointer(pTrig)).FpTabSchema == (*TDb)(unsafe.Pointer(pDb)).FpSchema {
			(*TTrigger)(unsafe.Pointer(pTrig)).FpTabSchema = (*TTrigger)(unsafe.Pointer(pTrig)).FpSchema
		}
		pEntry = (*THashElem)(unsafe.Pointer(pEntry)).Fnext
	}
	_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	(*TDb)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
	(*TDb)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
	_sqlite3CollapseDatabaseArray(tls, db)
	return
	goto detach_error
detach_error:
	;
	Xsqlite3_result_error(tls, context, bp, -int32(1))
}

// C documentation
//
//	/*
//	** This procedure generates VDBE code for a single invocation of either the
//	** sqlite_detach() or sqlite_attach() SQL user functions.
//	*/
func _codeAttach(tls *libc.TLS, pParse uintptr, type1 int32, pFunc uintptr, pAuthArg uintptr, pFilename uintptr, pDbname uintptr, pKey uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, v, zAuthArg uintptr
	var rc, regArgs int32
	var _ /* sName at bp+0 */ TNameContext
	_, _, _, _, _ = db, rc, regArgs, v, zAuthArg
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		goto attach_end
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto attach_end
	}
	libc.Xmemset(tls, bp, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
	if SQLITE_OK != _resolveAttachExpr(tls, bp, pFilename) || SQLITE_OK != _resolveAttachExpr(tls, bp, pDbname) || SQLITE_OK != _resolveAttachExpr(tls, bp, pKey) {
		goto attach_end
	}
	if pAuthArg != 0 {
		if int32((*TExpr)(unsafe.Pointer(pAuthArg)).Fop) == int32(TK_STRING) {
			zAuthArg = *(*uintptr)(unsafe.Pointer(pAuthArg + 8))
		} else {
			zAuthArg = uintptr(0)
		}
		rc = _sqlite3AuthCheck(tls, pParse, type1, zAuthArg, uintptr(0), uintptr(0))
		if rc != SQLITE_OK {
			goto attach_end
		}
	}
	v = _sqlite3GetVdbe(tls, pParse)
	regArgs = _sqlite3GetTempRange(tls, pParse, int32(4))
	_sqlite3ExprCode(tls, pParse, pFilename, regArgs)
	_sqlite3ExprCode(tls, pParse, pDbname, regArgs+int32(1))
	_sqlite3ExprCode(tls, pParse, pKey, regArgs+int32(2))
	if v != 0 {
		_sqlite3VdbeAddFunctionCall(tls, pParse, 0, regArgs+int32(3)-int32((*TFuncDef)(unsafe.Pointer(pFunc)).FnArg), regArgs+int32(3), int32((*TFuncDef)(unsafe.Pointer(pFunc)).FnArg), pFunc, 0)
		/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
		 ** statement only). For DETACH, set it to false (expire all existing
		 ** statements).
		 */
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Expire), libc.BoolInt32(type1 == int32(SQLITE_ATTACH)))
	}
	goto attach_end
attach_end:
	;
	_sqlite3ExprDelete(tls, db, pFilename)
	_sqlite3ExprDelete(tls, db, pDbname)
	_sqlite3ExprDelete(tls, db, pKey)
}

// C documentation
//
//	/*
//	** Called by the parser to compile a DETACH statement.
//	**
//	**     DETACH pDbname
//	*/
func _sqlite3Detach(tls *libc.TLS, pParse uintptr, pDbname uintptr) {
	_codeAttach(tls, pParse, int32(SQLITE_DETACH), uintptr(unsafe.Pointer(&_detach_func)), pDbname, uintptr(0), uintptr(0), pDbname)
}

var _detach_func = TFuncDef{
	FnArg:      int8(1),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13694,
}

func init() {
	p := unsafe.Pointer(&_detach_func)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_detachFunc)
}

// C documentation
//
//	/*
//	** Called by the parser to compile an ATTACH statement.
//	**
//	**     ATTACH p AS pDbname KEY pKey
//	*/
func _sqlite3Attach(tls *libc.TLS, pParse uintptr, p uintptr, pDbname uintptr, pKey uintptr) {
	_codeAttach(tls, pParse, int32(SQLITE_ATTACH), uintptr(unsafe.Pointer(&_attach_func)), p, p, pDbname, pKey)
}

var _attach_func = TFuncDef{
	FnArg:      int8(3),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13708,
}

func init() {
	p := unsafe.Pointer(&_attach_func)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_attachFunc)
}

// C documentation
//
//	/*
//	** Expression callback used by sqlite3FixAAAA() routines.
//	*/
func _fixExprCb(tls *libc.TLS, p uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pFix uintptr
	_ = pFix
	pFix = *(*uintptr)(unsafe.Pointer(p + 24))
	if !((*TDbFixer)(unsafe.Pointer(pFix)).FbTemp != 0) {
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_FromDDL))
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VARIABLE) {
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TDbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb)).Finit1.Fbusy != 0 {
			(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
		} else {
			_sqlite3ErrorMsg(tls, (*TDbFixer)(unsafe.Pointer(pFix)).FpParse, __ccgo_ts+13722, libc.VaList(bp+8, (*TDbFixer)(unsafe.Pointer(pFix)).FzType))
			return int32(WRC_Abort)
		}
	}
	return WRC_Continue
}

// 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 + 24))
	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 int32((*TDbFixer)(unsafe.Pointer(pFix)).FbTemp) == 0 {
			if (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase != 0 {
				if iDb != _sqlite3FindDbName(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase) {
					_sqlite3ErrorMsg(tls, (*TDbFixer)(unsafe.Pointer(pFix)).FpParse, __ccgo_ts+13746, libc.VaList(bp+8, (*TDbFixer)(unsafe.Pointer(pFix)).FzType, (*TDbFixer)(unsafe.Pointer(pFix)).FpName, (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase))
					return int32(WRC_Abort)
				}
				_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase)
				(*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase = uintptr(0)
				libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 9, 0x200)
			}
			(*TSrcItem)(unsafe.Pointer(pItem)).FpSchema = (*TDbFixer)(unsafe.Pointer(pFix)).FpSchema
			libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 7, 0x80)
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*72 + 36 + 4))&0x400>>10)) == 0 && _sqlite3WalkExpr(tls, pFix+4, *(*uintptr)(unsafe.Pointer(pList + 8 + uintptr(i)*72 + 48))) != 0 {
			return int32(WRC_Abort)
		}
		goto _1
	_1:
		;
		i++
		pItem += 72
	}
	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 + 12 + uintptr(i)*24))).FpSelect) != 0 {
				return int32(WRC_Abort)
			}
			goto _2
		_2:
			;
			i++
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Initialize a DbFixer structure.  This routine must be called prior
//	** to passing the structure to one of the sqliteFixAAAA() routines below.
//	*/
func _sqlite3FixInit(tls *libc.TLS, pFix uintptr, pParse uintptr, iDb int32, zType uintptr, pName uintptr) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	(*TDbFixer)(unsafe.Pointer(pFix)).FpParse = pParse
	(*TDbFixer)(unsafe.Pointer(pFix)).FzDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	(*TDbFixer)(unsafe.Pointer(pFix)).FpSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	(*TDbFixer)(unsafe.Pointer(pFix)).FzType = zType
	(*TDbFixer)(unsafe.Pointer(pFix)).FpName = pName
	(*TDbFixer)(unsafe.Pointer(pFix)).FbTemp = libc.BoolUint8(iDb == libc.Int32FromInt32(1))
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FpParse = pParse
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FxExprCallback = __ccgo_fp(_fixExprCb)
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FxSelectCallback = __ccgo_fp(_fixSelectCb)
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FxSelectCallback2 = __ccgo_fp(_sqlite3WalkWinDefnDummyCallback)
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FwalkerDepth = 0
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FeCode = uint16(0)
	*(*uintptr)(unsafe.Pointer(pFix + 4 + 24)) = pFix
}

// C documentation
//
//	/*
//	** The following set of routines walk through the parse tree and assign
//	** a specific database to all table references where the database name
//	** was left unspecified in the original SQL statement.  The pFix structure
//	** must have been initialized by a prior call to sqlite3FixInit().
//	**
//	** These routines are used to make sure that an index, trigger, or
//	** view in one database does not refer to objects in a different database.
//	** (Exception: indices, triggers, and views in the TEMP database are
//	** allowed to refer to anything.)  If a reference is explicitly made
//	** to an object in a different database, an error message is added to
//	** pParse->zErrMsg and these routines return non-zero.  If everything
//	** checks out, these routines return 0.
//	*/
func _sqlite3FixSrcList(tls *libc.TLS, pFix uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var res int32
	var _ /* s at bp+0 */ TSelect
	_ = res
	res = 0
	if pList != 0 {
		libc.Xmemset(tls, bp, 0, uint32(76))
		(*(*TSelect)(unsafe.Pointer(bp))).FpSrc = pList
		res = _sqlite3WalkSelect(tls, pFix+4, bp)
	}
	return res
}

func _sqlite3FixSelect(tls *libc.TLS, pFix uintptr, pSelect uintptr) (r int32) {
	return _sqlite3WalkSelect(tls, pFix+4, pSelect)
}

func _sqlite3FixExpr(tls *libc.TLS, pFix uintptr, pExpr uintptr) (r int32) {
	return _sqlite3WalkExpr(tls, pFix+4, pExpr)
}

func _sqlite3FixTriggerStep(tls *libc.TLS, pFix uintptr, pStep uintptr) (r int32) {
	var pUp uintptr
	_ = pUp
	for pStep != 0 {
		if _sqlite3WalkSelect(tls, pFix+4, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect) != 0 || _sqlite3WalkExpr(tls, pFix+4, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere) != 0 || _sqlite3WalkExprList(tls, pFix+4, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList) != 0 || _sqlite3FixSrcList(tls, pFix, (*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom) != 0 {
			return int32(1)
		}
		pUp = (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert
		for {
			if !(pUp != 0) {
				break
			}
			if _sqlite3WalkExprList(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertTarget) != 0 || _sqlite3WalkExpr(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertTargetWhere) != 0 || _sqlite3WalkExprList(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertSet) != 0 || _sqlite3WalkExpr(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertWhere) != 0 {
				return int32(1)
			}
			goto _1
		_1:
			;
			pUp = (*TUpsert)(unsafe.Pointer(pUp)).FpNextUpsert
		}
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
	return 0
}

/************** End of attach.c **********************************************/
/************** Begin file auth.c ********************************************/
/*
** 2003 January 11
**
** 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 sqlite3_set_authorizer()
** API.  This facility is an optional feature of the library.  Embedded
** systems that do not need this facility may omit it by recompiling
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
 */
/* #include "sqliteInt.h" */

/*
** All of the code in this file may be omitted by defining a single
** macro.
 */

// C documentation
//
//	/*
//	** Set or clear the access authorization function.
//	**
//	** The access authorization function is be called during the compilation
//	** phase to verify that the user has read and/or write access permission on
//	** various fields of the database.  The first argument to the auth function
//	** is a copy of the 3rd argument to this routine.  The second argument
//	** to the auth function is one of these constants:
//	**
//	**       SQLITE_CREATE_INDEX
//	**       SQLITE_CREATE_TABLE
//	**       SQLITE_CREATE_TEMP_INDEX
//	**       SQLITE_CREATE_TEMP_TABLE
//	**       SQLITE_CREATE_TEMP_TRIGGER
//	**       SQLITE_CREATE_TEMP_VIEW
//	**       SQLITE_CREATE_TRIGGER
//	**       SQLITE_CREATE_VIEW
//	**       SQLITE_DELETE
//	**       SQLITE_DROP_INDEX
//	**       SQLITE_DROP_TABLE
//	**       SQLITE_DROP_TEMP_INDEX
//	**       SQLITE_DROP_TEMP_TABLE
//	**       SQLITE_DROP_TEMP_TRIGGER
//	**       SQLITE_DROP_TEMP_VIEW
//	**       SQLITE_DROP_TRIGGER
//	**       SQLITE_DROP_VIEW
//	**       SQLITE_INSERT
//	**       SQLITE_PRAGMA
//	**       SQLITE_READ
//	**       SQLITE_SELECT
//	**       SQLITE_TRANSACTION
//	**       SQLITE_UPDATE
//	**
//	** The third and fourth arguments to the auth function are the name of
//	** the table and the column that are being accessed.  The auth function
//	** should return either SQLITE_OK, SQLITE_DENY, or SQLITE_IGNORE.  If
//	** SQLITE_OK is returned, it means that access is allowed.  SQLITE_DENY
//	** means that the SQL statement will never-run - the sqlite3_exec() call
//	** will return with an error.  SQLITE_IGNORE means that the SQL statement
//	** should run but attempts to read the specified column will return NULL
//	** and attempts to write the column will be ignored.
//	**
//	** Setting the auth function to NULL disables this hook.  The default
//	** setting of the auth function is NULL.
//	*/
func Xsqlite3_set_authorizer(tls *libc.TLS, db uintptr, xAuth uintptr, pArg uintptr) (r int32) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	(*Tsqlite3)(unsafe.Pointer(db)).FpAuthArg = pArg
	if (*Tsqlite3)(unsafe.Pointer(db)).FxAuth != 0 {
		_sqlite3ExpirePreparedStatements(tls, db, int32(1))
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Write an error message into pParse->zErrMsg that explains that the
//	** user-supplied authorization function returned an illegal value.
//	*/
func _sqliteAuthBadReturnCode(tls *libc.TLS, pParse uintptr) {
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13792, 0)
	(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
}

// C documentation
//
//	/*
//	** Invoke the authorization callback for permission to read column zCol from
//	** table zTab in database zDb. This function assumes that an authorization
//	** callback has been registered (i.e. that sqlite3.xAuth is not NULL).
//	**
//	** If SQLITE_IGNORE is returned and pExpr is not NULL, then pExpr is changed
//	** to an SQL NULL expression. Otherwise, if pExpr is NULL, then SQLITE_IGNORE
//	** is treated as SQLITE_DENY. In this case an error is left in pParse.
//	*/
func _sqlite3AuthReadCol(tls *libc.TLS, pParse uintptr, zTab uintptr, zCol uintptr, iDb int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, z, zDb uintptr
	var rc int32
	_, _, _, _ = db, rc, z, zDb
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                                                        /* Database handle */
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName /* Auth callback return code */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		return SQLITE_OK
	}
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAuth})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAuthArg, int32(SQLITE_READ), zTab, zCol, zDb, (*TParse)(unsafe.Pointer(pParse)).FzAuthContext)
	if rc == int32(SQLITE_DENY) {
		z = Xsqlite3_mprintf(tls, __ccgo_ts+13815, libc.VaList(bp+8, zTab, zCol))
		if (*Tsqlite3)(unsafe.Pointer(db)).FnDb > int32(2) || iDb != 0 {
			z = Xsqlite3_mprintf(tls, __ccgo_ts+13821, libc.VaList(bp+8, zDb, z))
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13827, libc.VaList(bp+8, z))
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_AUTH)
	} else {
		if rc != int32(SQLITE_IGNORE) && rc != SQLITE_OK {
			_sqliteAuthBadReturnCode(tls, pParse)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** The pExpr should be a TK_COLUMN expression.  The table referred to
//	** is in pTabList or else it is the NEW or OLD table of a trigger.
//	** Check to see if it is OK to read this particular column.
//	**
//	** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
//	** instruction into a TK_NULL.  If the auth function returns SQLITE_DENY,
//	** then generate an error.
//	*/
func _sqlite3AuthRead(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSchema uintptr, pTabList uintptr) {
	var iCol, iDb, iSrc int32
	var pTab, zCol uintptr
	_, _, _, _, _ = iCol, iDb, iSrc, pTab, zCol
	pTab = uintptr(0) /* Index of column in table */
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSchema)
	if iDb < 0 {
		/* An attempt to read a column out of a subquery or other
		 ** temporary table. */
		return
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_TRIGGER) {
		pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
	} else {
		iSrc = 0
		for {
			if !(iSrc < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
				break
			}
			if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(iSrc)*72))).FiCursor {
				pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(iSrc)*72))).FpTab
				break
			}
			goto _1
		_1:
			;
			iSrc++
		}
	}
	iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
	if pTab == uintptr(0) {
		return
	}
	if iCol >= 0 {
		zCol = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName
	} else {
		if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
			zCol = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*12))).FzCnName
		} else {
			zCol = __ccgo_ts + 9339
		}
	}
	if int32(SQLITE_IGNORE) == _sqlite3AuthReadCol(tls, pParse, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol, iDb) {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
	}
}

// C documentation
//
//	/*
//	** Do an authorization check using the code and arguments given.  Return
//	** either SQLITE_OK (zero) or SQLITE_IGNORE or SQLITE_DENY.  If SQLITE_DENY
//	** is returned, then the error count and error message in pParse are
//	** modified appropriately.
//	*/
func _sqlite3AuthCheck(tls *libc.TLS, pParse uintptr, code int32, zArg1 uintptr, zArg2 uintptr, zArg3 uintptr) (r int32) {
	var db uintptr
	var rc int32
	_, _ = db, rc
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Don't do any authorization checks if the database is initializing
	 ** or if the parser is being invoked from within sqlite3_declare_vtab.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FxAuth == uintptr(0) || (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 || int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
		return SQLITE_OK
	}
	/* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
	 ** callback are either NULL pointers or zero-terminated strings that
	 ** contain additional details about the action to be authorized.
	 **
	 ** The following testcase() macros show that any of the 3rd through 6th
	 ** parameters can be either NULL or a string. */
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAuth})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAuthArg, code, zArg1, zArg2, zArg3, (*TParse)(unsafe.Pointer(pParse)).FzAuthContext)
	if rc == int32(SQLITE_DENY) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13854, 0)
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_AUTH)
	} else {
		if rc != SQLITE_OK && rc != int32(SQLITE_IGNORE) {
			rc = int32(SQLITE_DENY)
			_sqliteAuthBadReturnCode(tls, pParse)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Push an authorization context.  After this routine is called, the
//	** zArg3 argument to authorization callbacks will be zContext until
//	** popped.  Or if pParse==0, this routine is a no-op.
//	*/
func _sqlite3AuthContextPush(tls *libc.TLS, pParse uintptr, pContext uintptr, zContext uintptr) {
	(*TAuthContext)(unsafe.Pointer(pContext)).FpParse = pParse
	(*TAuthContext)(unsafe.Pointer(pContext)).FzAuthContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext
	(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zContext
}

// C documentation
//
//	/*
//	** Pop an authorization context that was previously pushed
//	** by sqlite3AuthContextPush
//	*/
func _sqlite3AuthContextPop(tls *libc.TLS, pContext uintptr) {
	if (*TAuthContext)(unsafe.Pointer(pContext)).FpParse != 0 {
		(*TParse)(unsafe.Pointer((*TAuthContext)(unsafe.Pointer(pContext)).FpParse)).FzAuthContext = (*TAuthContext)(unsafe.Pointer(pContext)).FzAuthContext
		(*TAuthContext)(unsafe.Pointer(pContext)).FpParse = uintptr(0)
	}
}

/************** End of auth.c ************************************************/
/************** Begin file build.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 C code routines that are called by the SQLite parser
** when syntax rules are reduced.  The routines in this file handle the
** following kinds of SQL syntax:
**
**     CREATE TABLE
**     DROP TABLE
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
 */
/* #include "sqliteInt.h" */

/*
** The TableLock structure is only used by the sqlite3TableLock() and
** codeTableLocks() functions.
 */
type TTableLock1 = struct {
	FiDb         int32
	FiTab        TPgno
	FisWriteLock Tu8
	FzLockName   uintptr
}

type TableLock1 = TTableLock1

// C documentation
//
//	/*
//	** Record the fact that we want to lock a table at run-time.
//	**
//	** The table to be locked has root page iTab and is found in database iDb.
//	** A read or a write lock can be taken depending on isWritelock.
//	**
//	** This routine just records the fact that the lock is desired.  The
//	** code to make the lock occur is generated by a later call to
//	** codeTableLocks() which occurs during sqlite3FinishCoding().
//	*/
func _lockTable(tls *libc.TLS, pParse uintptr, iDb int32, iTab TPgno, isWriteLock Tu8, zName uintptr) {
	var i, nBytes, v3 int32
	var p, pToplevel, v1, v4 uintptr
	_, _, _, _, _, _, _ = i, nBytes, p, pToplevel, v1, v3, v4
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pToplevel = v1
	i = 0
	for {
		if !(i < (*TParse)(unsafe.Pointer(pToplevel)).FnTableLock) {
			break
		}
		p = (*TParse)(unsafe.Pointer(pToplevel)).FaTableLock + uintptr(i)*16
		if (*TTableLock)(unsafe.Pointer(p)).FiDb == iDb && (*TTableLock)(unsafe.Pointer(p)).FiTab == iTab {
			(*TTableLock)(unsafe.Pointer(p)).FisWriteLock = libc.BoolUint8((*TTableLock)(unsafe.Pointer(p)).FisWriteLock != 0 || isWriteLock != 0)
			return
		}
		goto _2
	_2:
		;
		i++
	}
	nBytes = int32(uint32(16) * uint32((*TParse)(unsafe.Pointer(pToplevel)).FnTableLock+libc.Int32FromInt32(1)))
	(*TParse)(unsafe.Pointer(pToplevel)).FaTableLock = _sqlite3DbReallocOrFree(tls, (*TParse)(unsafe.Pointer(pToplevel)).Fdb, (*TParse)(unsafe.Pointer(pToplevel)).FaTableLock, uint64(uint64(nBytes)))
	if (*TParse)(unsafe.Pointer(pToplevel)).FaTableLock != 0 {
		v4 = pToplevel + 116
		v3 = *(*int32)(unsafe.Pointer(v4))
		*(*int32)(unsafe.Pointer(v4))++
		p = (*TParse)(unsafe.Pointer(pToplevel)).FaTableLock + uintptr(v3)*16
		(*TTableLock)(unsafe.Pointer(p)).FiDb = iDb
		(*TTableLock)(unsafe.Pointer(p)).FiTab = iTab
		(*TTableLock)(unsafe.Pointer(p)).FisWriteLock = isWriteLock
		(*TTableLock)(unsafe.Pointer(p)).FzLockName = zName
	} else {
		(*TParse)(unsafe.Pointer(pToplevel)).FnTableLock = 0
		_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(pToplevel)).Fdb)
	}
}

func _sqlite3TableLock(tls *libc.TLS, pParse uintptr, iDb int32, iTab TPgno, isWriteLock Tu8, zName uintptr) {
	if iDb == int32(1) {
		return
	}
	if !(_sqlite3BtreeSharable(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FpBt) != 0) {
		return
	}
	_lockTable(tls, pParse, iDb, iTab, isWriteLock, zName)
}

// C documentation
//
//	/*
//	** Code an OP_TableLock instruction for each table locked by the
//	** statement (configured by calls to sqlite3TableLock()).
//	*/
func _codeTableLocks(tls *libc.TLS, pParse uintptr) {
	var i, p1 int32
	var p, pVdbe uintptr
	_, _, _, _ = i, p, p1, pVdbe
	pVdbe = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	i = 0
	for {
		if !(i < (*TParse)(unsafe.Pointer(pParse)).FnTableLock) {
			break
		}
		p = (*TParse)(unsafe.Pointer(pParse)).FaTableLock + uintptr(i)*16
		p1 = (*TTableLock)(unsafe.Pointer(p)).FiDb
		_sqlite3VdbeAddOp4(tls, pVdbe, int32(OP_TableLock), p1, int32((*TTableLock)(unsafe.Pointer(p)).FiTab), int32((*TTableLock)(unsafe.Pointer(p)).FisWriteLock), (*TTableLock)(unsafe.Pointer(p)).FzLockName, -int32(1))
		goto _1
	_1:
		;
		i++
	}
}

/*
** Return TRUE if the given yDbMask object is empty - if it contains no
** 1 bits.  This routine is used by the DbMaskAllZero() and DbMaskNotZero()
** macros when SQLITE_MAX_ATTACHED is greater than 30.
 */

// 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 (*TParse)(unsafe.Pointer(pParse)).FbReturning != 0 {
			pReturning = *(*uintptr)(unsafe.Pointer(pParse + 144))
			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++
				}
				_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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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 int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
				_sqlite3VdbeChangeP5(tls, v, uint16(1))
			}
			goto _3
		_3:
			;
			iDb++
			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)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).FapVtabLock + uintptr(i)*4)))
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VBegin), 0, 0, 0, vtab, -int32(11))
			goto _4
		_4:
			;
			i++
		}
		(*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
			(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = uint8(0)
			i = 0
			for {
				if !(i < (*TExprList)(unsafe.Pointer(pEL)).FnExpr) {
					break
				}
				_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pEL + 8 + uintptr(i)*20))).FpExpr, *(*int32)(unsafe.Pointer(pEL + 8 + uintptr(i)*20 + 16)))
				goto _5
			_5:
				;
				i++
			}
		}
		if (*TParse)(unsafe.Pointer(pParse)).FbReturning != 0 {
			pRet = *(*uintptr)(unsafe.Pointer(pParse + 144))
			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
//
//	/*
//	** Run the parser and code generator recursively in order to generate
//	** code for the SQL statement given onto the end of the pParse context
//	** currently under construction.  Notes:
//	**
//	**   *  The final OP_Halt is not appended and other initialization
//	**      and finalization steps are omitted because those are handling by the
//	**      outermost parser.
//	**
//	**   *  Built-in SQL functions always take precedence over application-defined
//	**      SQL functions.  In other words, it is not possible to override a
//	**      built-in function.
//	*/
func _sqlite3NestedParse(tls *libc.TLS, pParse uintptr, zFormat uintptr, va uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var ap Tva_list
	var db, zSql uintptr
	var savedDbFlags Tu32
	var _ /* saveBuf at bp+0 */ [76]int8
	_, _, _, _ = ap, db, savedDbFlags, zSql
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	savedDbFlags = (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	if (*TParse)(unsafe.Pointer(pParse)).FeParseMode != 0 {
		return
	}
	/* Nesting should only be of limited depth */
	ap = va
	zSql = _sqlite3VMPrintf(tls, db, zFormat, ap)
	_ = ap
	if zSql == uintptr(0) {
		/* This can result either from an OOM or because the formatted string
		 ** exceeds SQLITE_LIMIT_LENGTH.  In the latter case, we need to set
		 ** an error */
		if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
			(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_TOOBIG)
		}
		(*TParse)(unsafe.Pointer(pParse)).FnErr++
		return
	}
	(*TParse)(unsafe.Pointer(pParse)).Fnested++
	libc.Xmemcpy(tls, bp, pParse+uintptr(uint32(libc.UintptrFromInt32(0)+208)), libc.Uint32FromInt64(284)-uint32(libc.UintptrFromInt32(0)+208))
	libc.Xmemset(tls, pParse+uintptr(uint32(libc.UintptrFromInt32(0)+208)), 0, libc.Uint32FromInt64(284)-uint32(libc.UintptrFromInt32(0)+208))
	*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_PreferBuiltin)
	_sqlite3RunParser(tls, pParse, zSql)
	(*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags = savedDbFlags
	_sqlite3DbFree(tls, db, zSql)
	libc.Xmemcpy(tls, pParse+uintptr(uint32(libc.UintptrFromInt32(0)+208)), bp, libc.Uint32FromInt64(284)-uint32(libc.UintptrFromInt32(0)+208))
	(*TParse)(unsafe.Pointer(pParse)).Fnested--
}

// 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.
//	**
//	** If zDatabase is 0, all databases are searched for the table and the
//	** first matching table is returned.  (No checking for duplicate table
//	** names is done.)  The search order is TEMP first, then MAIN, then any
//	** auxiliary databases added using the ATTACH command.
//	**
//	** See also sqlite3LocateTable().
//	*/
func _sqlite3FindTable(tls *libc.TLS, db uintptr, zName uintptr, zDatabase uintptr) (r uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	p = uintptr(0)
	/* All mutexes are required for schema access.  Make sure we hold them. */
	if zDatabase != 0 {
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if _sqlite3StrICmp(tls, zDatabase, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FzDbSName) == 0 {
				break
			}
			goto _1
		_1:
			;
			i++
		}
		if i >= (*Tsqlite3)(unsafe.Pointer(db)).FnDb {
			/* No match against the official names.  But always match "main"
			 ** to schema 0 as a legacy fallback. */
			if _sqlite3StrICmp(tls, zDatabase, __ccgo_ts+7958) == 0 {
				i = 0
			} else {
				return uintptr(0)
			}
		}
		p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema+8, zName)
		if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+7898, int32(7)) == 0 {
			if i == int32(1) {
				if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7925+7) == 0 || _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7944+7) == 0 || _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7439+7) == 0 {
					p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema+8, __ccgo_ts+7906)
				}
			} else {
				if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7944+7) == 0 {
					p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema+8, __ccgo_ts+7439)
				}
			}
		}
	} else {
		/* Match against TEMP first */
		p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema+8, zName)
		if p != 0 {
			return p
		}
		/* The main database is second */
		p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema+8, zName)
		if p != 0 {
			return p
		}
		/* Attached databases are in order of attachment */
		i = int32(2)
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema+8, zName)
			if p != 0 {
				break
			}
			goto _2
		_2:
			;
			i++
		}
		if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+7898, int32(7)) == 0 {
			if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7944+7) == 0 {
				p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema+8, __ccgo_ts+7439)
			} else {
				if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7925+7) == 0 {
					p = _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema+8, __ccgo_ts+7906)
				}
			}
		}
	}
	return p
}

// 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 int32((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_NO_VTAB) == 0 && int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
			pMod = _sqlite3HashFind(tls, db+404, zName)
			if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+13869, int32(7)) == 0 {
				pMod = _sqlite3PragmaVtabRegister(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)
		}
		(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
	} else {
		if int32((*TTable)(unsafe.Pointer(p)).FeTabType) == int32(TABTYP_VTAB) && int32((*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 + 13877
		} else {
			v1 = __ccgo_ts + 13890
		}
		zMsg = v1
		if zDbase != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8162, libc.VaList(bp+8, zMsg, zDbase, zName))
		} else {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8233, 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 (*TSrcItem)(unsafe.Pointer(p)).FpSchema != 0 {
		iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSrcItem)(unsafe.Pointer(p)).FpSchema)
		zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FzDbSName
	} else {
		zDb = (*TSrcItem)(unsafe.Pointer(p)).FzDatabase
	}
	return _sqlite3LocateTable(tls, pParse, flags, (*TSrcItem)(unsafe.Pointer(p)).FzName, zDb)
}

// C documentation
//
//	/*
//	** Return the preferred table name for system tables.  Translate legacy
//	** names into the new preferred names, as appropriate.
//	*/
func _sqlite3PreferredTableName(tls *libc.TLS, zName uintptr) (r uintptr) {
	if Xsqlite3_strnicmp(tls, zName, __ccgo_ts+7898, int32(7)) == 0 {
		if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7439+7) == 0 {
			return __ccgo_ts + 7944
		}
		if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7906+7) == 0 {
			return __ccgo_ts + 7925
		}
	}
	return zName
}

// C documentation
//
//	/*
//	** Locate the in-memory structure that describes
//	** a particular index given the name of that index
//	** and the name of the database that contains the index.
//	** Return NULL if not found.
//	**
//	** If zDatabase is 0, all databases are searched for the
//	** table and the first matching index is returned.  (No checking
//	** for duplicate index names is done.)  The search order is
//	** TEMP first, then MAIN, then any auxiliary databases added
//	** using the ATTACH command.
//	*/
func _sqlite3FindIndex(tls *libc.TLS, db uintptr, zName uintptr, zDb uintptr) (r uintptr) {
	var i, j, v2 int32
	var p, pSchema uintptr
	_, _, _, _, _ = i, j, p, pSchema, v2
	p = uintptr(0)
	/* All mutexes are required for schema access.  Make sure we hold them. */
	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 */
		pSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*16))).FpSchema
		if zDb != 0 && _sqlite3DbIsNamed(tls, db, j, zDb) == 0 {
			goto _1
		}
		p = _sqlite3HashFind(tls, pSchema+24, zName)
		if p != 0 {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	return p
}

// 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 + 56))&0x10>>4)) != 0 {
		_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer(p)).FazColl)
	}
	Xsqlite3_free(tls, (*TIndex)(unsafe.Pointer(p)).FaiRowEst)
	_sqlite3DbFree(tls, db, p)
}

// C documentation
//
//	/*
//	** For the index called zIdxName which is found in the database iDb,
//	** unlike that index from its Table then remove the index from
//	** the index hash table and free all memory structures associated
//	** with the index.
//	*/
func _sqlite3UnlinkAndDeleteIndex(tls *libc.TLS, db uintptr, iDb int32, zIdxName uintptr) {
	var p, pHash, pIndex uintptr
	_, _, _ = p, pHash, pIndex
	pHash = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 24
	pIndex = _sqlite3HashInsert(tls, pHash, zIdxName, uintptr(0))
	if pIndex != 0 {
		if (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpIndex == pIndex {
			(*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpIndex = (*TIndex)(unsafe.Pointer(pIndex)).FpNext
		} else {
			/* Justification of ALWAYS();  The index must be on the list of
			 ** indices. */
			p = (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpIndex
			for p != 0 && (*TIndex)(unsafe.Pointer(p)).FpNext != pIndex {
				p = (*TIndex)(unsafe.Pointer(p)).FpNext
			}
			if p != 0 && (*TIndex)(unsafe.Pointer(p)).FpNext == pIndex {
				(*TIndex)(unsafe.Pointer(p)).FpNext = (*TIndex)(unsafe.Pointer(pIndex)).FpNext
			}
		}
		_sqlite3FreeIndex(tls, db, pIndex)
	}
	*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_SchemaChange)
}

// C documentation
//
//	/*
//	** Look through the list of open database files in db->aDb[] and if
//	** any have been closed, remove them from the list.  Reallocate the
//	** db->aDb[] structure to a smaller size, if possible.
//	**
//	** Entry 0 (the "main" database) and entry 1 (the "temp" database)
//	** are never candidates for being collapsed.
//	*/
func _sqlite3CollapseDatabaseArray(tls *libc.TLS, db uintptr) {
	var i, j, v2 int32
	var pDb uintptr
	_, _, _, _ = i, j, pDb, v2
	v2 = libc.Int32FromInt32(2)
	j = v2
	i = v2
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16
		if (*TDb1)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
			_sqlite3DbFree(tls, db, (*TDb1)(unsafe.Pointer(pDb)).FzDbSName)
			(*TDb1)(unsafe.Pointer(pDb)).FzDbSName = uintptr(0)
			goto _1
		}
		if j < i {
			*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*16)) = *(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))
		}
		j++
		goto _1
	_1:
		;
		i++
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FnDb = j
	if (*Tsqlite3)(unsafe.Pointer(db)).FnDb <= int32(2) && (*Tsqlite3)(unsafe.Pointer(db)).FaDb != db+476 {
		libc.Xmemcpy(tls, db+476, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint32FromInt32(2)*libc.Uint32FromInt64(16))
		_sqlite3DbFree(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb)
		(*Tsqlite3)(unsafe.Pointer(db)).FaDb = db + 476
	}
}

// C documentation
//
//	/*
//	** Reset the schema for the database at index iDb.  Also reset the
//	** TEMP schema.  The reset is deferred if db->nSchemaLock is not zero.
//	** Deferred resets may be run by calling with iDb<0.
//	*/
func _sqlite3ResetOneSchema(tls *libc.TLS, db uintptr, iDb int32) {
	var i int32
	var p1, p2 uintptr
	_, _, _ = i, p1, p2
	if iDb >= 0 {
		p1 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 78
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(DB_ResetWanted))
		p2 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 78
		*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(DB_ResetWanted))
		*(*Tu32)(unsafe.Pointer(db + 24)) &= uint32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock == uint32(0) {
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if int32((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema)).FschemaFlags)&int32(DB_ResetWanted) == int32(DB_ResetWanted) {
				_sqlite3SchemaClear(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema)
			}
			goto _3
		_3:
			;
			i++
		}
	}
}

// C documentation
//
//	/*
//	** Erase all schema information from all attached databases (including
//	** "main" and "temp") for a single database connection.
//	*/
func _sqlite3ResetAllSchemasOfConnection(tls *libc.TLS, db uintptr) {
	var i int32
	var pDb, p2 uintptr
	_, _, _ = i, pDb, p2
	_sqlite3BtreeEnterAll(tls, db)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16
		if (*TDb)(unsafe.Pointer(pDb)).FpSchema != 0 {
			if (*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock == uint32(0) {
				_sqlite3SchemaClear(tls, (*TDb)(unsafe.Pointer(pDb)).FpSchema)
			} else {
				p2 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema + 78
				*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(DB_ResetWanted))
			}
		}
		goto _1
	_1:
		;
		i++
	}
	*(*Tu32)(unsafe.Pointer(db + 24)) &= uint32(^(libc.Int32FromInt32(DBFLAG_SchemaChange) | libc.Int32FromInt32(DBFLAG_SchemaKnownOk)))
	_sqlite3VtabUnlockList(tls, db)
	_sqlite3BtreeLeaveAll(tls, db)
	if (*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock == uint32(0) {
		_sqlite3CollapseDatabaseArray(tls, db)
	}
}

// C documentation
//
//	/*
//	** This routine is called when a commit occurs.
//	*/
func _sqlite3CommitInternalChanges(tls *libc.TLS, db uintptr) {
	*(*Tu32)(unsafe.Pointer(db + 24)) &= uint32(^libc.Int32FromInt32(DBFLAG_SchemaChange))
}

// C documentation
//
//	/*
//	** Set the expression associated with a column.  This is usually
//	** the DEFAULT value, but might also be the expression that computes
//	** the value for a generated column.
//	*/
func _sqlite3ColumnSetExpr(tls *libc.TLS, pParse uintptr, pTab uintptr, pCol uintptr, pExpr uintptr) {
	var pList uintptr
	var v1 int32
	_, _ = pList, v1
	pList = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpDfltList
	if int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt) == 0 || pList == uintptr(0) || (*TExprList)(unsafe.Pointer(pList)).FnExpr < int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt) {
		if pList == uintptr(0) {
			v1 = int32(1)
		} else {
			v1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr + int32(1)
		}
		(*TColumn)(unsafe.Pointer(pCol)).FiDflt = uint16(v1)
		(*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pTab + 44))).FpDfltList = _sqlite3ExprListAppend(tls, pParse, pList, pExpr)
	} else {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt)-int32(1))*20))).FpExpr)
		(*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt)-int32(1))*20))).FpExpr = pExpr
	}
}

// C documentation
//
//	/*
//	** Return the expression associated with a column.  The expression might be
//	** the DEFAULT clause or the AS clause of a generated column.
//	** Return NULL if the column has no associated expression.
//	*/
func _sqlite3ColumnExpr(tls *libc.TLS, pTab uintptr, pCol uintptr) (r uintptr) {
	if int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt) == 0 {
		return uintptr(0)
	}
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		return uintptr(0)
	}
	if (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpDfltList == uintptr(0) {
		return uintptr(0)
	}
	if (*TExprList)(unsafe.Pointer((*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpDfltList)).FnExpr < int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt) {
		return uintptr(0)
	}
	return (*(*TExprList_item)(unsafe.Pointer((*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpDfltList + 8 + uintptr(int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt)-int32(1))*20))).FpExpr
}

// C documentation
//
//	/*
//	** Set the collating sequence name for a column.
//	*/
func _sqlite3ColumnSetColl(tls *libc.TLS, db uintptr, pCol uintptr, zColl uintptr) {
	var n, nColl Ti64
	var zNew, p1 uintptr
	_, _, _, _ = n, nColl, zNew, p1
	n = int64(_sqlite3Strlen30(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName) + int32(1))
	if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
		n += int64(_sqlite3Strlen30(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName+uintptr(n)) + int32(1))
	}
	nColl = int64(_sqlite3Strlen30(tls, zColl) + int32(1))
	zNew = _sqlite3DbRealloc(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, uint64(nColl+n))
	if zNew != 0 {
		(*TColumn)(unsafe.Pointer(pCol)).FzCnName = zNew
		libc.Xmemcpy(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName+uintptr(n), zColl, uint32(uint32(nColl)))
		p1 = pCol + 10
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(COLFLAG_HASCOLL))
	}
}

// C documentation
//
//	/*
//	** Return the collating sequence name for a column
//	*/
func _sqlite3ColumnColl(tls *libc.TLS, pCol uintptr) (r uintptr) {
	var z uintptr
	_ = z
	if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASCOLL) == 0 {
		return uintptr(0)
	}
	z = (*TColumn)(unsafe.Pointer(pCol)).FzCnName
	for *(*int8)(unsafe.Pointer(z)) != 0 {
		z++
	}
	if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
		for cond := true; cond; cond = *(*int8)(unsafe.Pointer(z)) != 0 {
			z++
		}
	}
	return z + uintptr(1)
}

// C documentation
//
//	/*
//	** Delete memory allocated for the column names of a table or view (the
//	** Table.aCol[] array).
//	*/
func _sqlite3DeleteColumnNames(tls *libc.TLS, db uintptr, pTable uintptr) {
	var i int32
	var pCol, v1 uintptr
	_, _, _ = i, pCol, v1
	v1 = (*TTable)(unsafe.Pointer(pTable)).FaCol
	pCol = v1
	if v1 != uintptr(0) {
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTable)).FnCol)) {
				break
			}
			_sqlite3DbFree(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
			goto _2
		_2:
			;
			i++
			pCol += 12
		}
		_sqlite3DbNNFreeNN(tls, db, (*TTable)(unsafe.Pointer(pTable)).FaCol)
		if int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_NORM {
			_sqlite3ExprListDelete(tls, db, (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTable + 44))).FpDfltList)
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			(*TTable)(unsafe.Pointer(pTable)).FaCol = uintptr(0)
			(*TTable)(unsafe.Pointer(pTable)).FnCol = 0
			if int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_NORM {
				(*(*struct {
					FaddColOffset int32
					FpFKey        uintptr
					FpDfltList    uintptr
				})(unsafe.Pointer(pTable + 44))).FpDfltList = uintptr(0)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Remove the memory data structures associated with the given
//	** Table.  No changes are made to disk by this routine.
//	**
//	** This routine just deletes the data structure.  It does not unlink
//	** the table data structure from the hash table.  But it does destroy
//	** memory structures of the indices and foreign keys associated with
//	** the table.
//	**
//	** The db parameter is optional.  It is needed if the Table object
//	** contains lookaside memory.  (Table objects in the schema do not use
//	** lookaside memory, but some ephemeral Table objects do.)  Or the
//	** db parameter can be used with db->pnBytesFreed to measure the memory
//	** used by the Table object.
//	*/
func _deleteTable(tls *libc.TLS, db uintptr, pTable uintptr) {
	var pIndex, pNext, zName uintptr
	_, _, _ = pIndex, pNext, zName
	/* Delete all indices associated with this table. */
	pIndex = (*TTable)(unsafe.Pointer(pTable)).FpIndex
	for {
		if !(pIndex != 0) {
			break
		}
		pNext = (*TIndex)(unsafe.Pointer(pIndex)).FpNext
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) && !(int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
			zName = (*TIndex)(unsafe.Pointer(pIndex)).FzName
			_sqlite3HashInsert(tls, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema+24, zName, uintptr(0))
		}
		_sqlite3FreeIndex(tls, db, pIndex)
		goto _1
	_1:
		;
		pIndex = pNext
	}
	if int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_NORM {
		_sqlite3FkDelete(tls, db, pTable)
	} else {
		if int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VTAB) {
			_sqlite3VtabClear(tls, db, pTable)
		} else {
			_sqlite3SelectDelete(tls, db, (*(*struct {
				FpSelect uintptr
			})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTable)).Fu))).FpSelect)
		}
	}
	/* Delete the Table structure itself.
	 */
	_sqlite3DeleteColumnNames(tls, db, pTable)
	_sqlite3DbFree(tls, db, (*TTable)(unsafe.Pointer(pTable)).FzName)
	_sqlite3DbFree(tls, db, (*TTable)(unsafe.Pointer(pTable)).FzColAff)
	_sqlite3ExprListDelete(tls, db, (*TTable)(unsafe.Pointer(pTable)).FpCheck)
	_sqlite3DbFree(tls, db, pTable)
	/* Verify that no lookaside memory was used by schema tables */
}

func _sqlite3DeleteTable(tls *libc.TLS, db uintptr, pTable uintptr) {
	var v1 Tu32
	var v2 uintptr
	var v3 bool
	_, _, _ = v1, v2, v3
	/* Do not delete the table until the reference count reaches zero. */
	if !(pTable != 0) {
		return
	}
	if v3 = (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0); v3 {
		v2 = pTable + 24
		*(*Tu32)(unsafe.Pointer(v2))--
		v1 = *(*Tu32)(unsafe.Pointer(v2))
	}
	if v3 && v1 > uint32(0) {
		return
	}
	_deleteTable(tls, db, pTable)
}

func _sqlite3DeleteTableGeneric(tls *libc.TLS, db uintptr, pTable uintptr) {
	_sqlite3DeleteTable(tls, db, pTable)
}

// C documentation
//
//	/*
//	** Unlink the given table from the hash tables and the delete the
//	** table structure with all its indices and foreign keys.
//	*/
func _sqlite3UnlinkAndDeleteTable(tls *libc.TLS, db uintptr, iDb int32, zTabName uintptr) {
	var p, pDb uintptr
	_, _ = p, pDb
	/* Zero-length table names are allowed */
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	p = _sqlite3HashInsert(tls, (*TDb)(unsafe.Pointer(pDb)).FpSchema+8, zTabName, uintptr(0))
	_sqlite3DeleteTable(tls, db, p)
	*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_SchemaChange)
}

// C documentation
//
//	/*
//	** Given a token, return a string that consists of the text of that
//	** token.  Space to hold the returned string
//	** is obtained from sqliteMalloc() and must be freed by the calling
//	** function.
//	**
//	** Any quotation marks (ex:  "name", 'name', [name], or `name`) that
//	** surround the body of the token are removed.
//	**
//	** Tokens are often just pointers into the original SQL text and so
//	** are not \000 terminated and are not persistent.  The returned string
//	** is \000 terminated and is persistent.
//	*/
func _sqlite3NameFromToken(tls *libc.TLS, db uintptr, pName uintptr) (r uintptr) {
	var zName uintptr
	_ = zName
	if pName != 0 {
		zName = _sqlite3DbStrNDup(tls, db, (*TToken)(unsafe.Pointer(pName)).Fz, uint64((*TToken)(unsafe.Pointer(pName)).Fn))
		_sqlite3Dequote(tls, zName)
	} else {
		zName = uintptr(0)
	}
	return zName
}

// C documentation
//
//	/*
//	** Open the sqlite_schema table stored in database number iDb for
//	** writing. The table is opened using cursor 0.
//	*/
func _sqlite3OpenSchemaTable(tls *libc.TLS, p uintptr, iDb int32) {
	var v uintptr
	_ = v
	v = _sqlite3GetVdbe(tls, p)
	_sqlite3TableLock(tls, p, iDb, uint32(SCHEMA_ROOT), uint8(1), __ccgo_ts+7439)
	_sqlite3VdbeAddOp4Int(tls, v, int32(OP_OpenWrite), 0, int32(SCHEMA_ROOT), iDb, int32(5))
	if (*TParse)(unsafe.Pointer(p)).FnTab == 0 {
		(*TParse)(unsafe.Pointer(p)).FnTab = int32(1)
	}
}

// C documentation
//
//	/*
//	** Parameter zName points to a nul-terminated buffer containing the name
//	** of a database ("main", "temp" or the name of an attached db). This
//	** function returns the index of the named database in db->aDb[], or
//	** -1 if the named db cannot be found.
//	*/
func _sqlite3FindDbName(tls *libc.TLS, db uintptr, zName uintptr) (r int32) {
	var i int32
	var pDb uintptr
	_, _ = i, pDb
	i = -int32(1) /* Database number */
	if zName != 0 {
		i = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16
		for {
			if !(i >= 0) {
				break
			}
			if 0 == Xsqlite3_stricmp(tls, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zName) {
				break
			}
			/* "main" is always an acceptable alias for the primary database
			 ** even if it has been renamed using SQLITE_DBCONFIG_MAINDBNAME. */
			if i == 0 && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+7958, zName) {
				break
			}
			goto _1
		_1:
			;
			i--
			pDb -= 16
		}
	}
	return i
}

// C documentation
//
//	/*
//	** The token *pName contains the name of a database (either "main" or
//	** "temp" or the name of an attached db). This routine returns the
//	** index of the named database in db->aDb[], or -1 if the named db
//	** does not exist.
//	*/
func _sqlite3FindDb(tls *libc.TLS, db uintptr, pName uintptr) (r int32) {
	var i int32
	var zName uintptr
	_, _ = i, zName /* Name we are searching for */
	zName = _sqlite3NameFromToken(tls, db, pName)
	i = _sqlite3FindDbName(tls, db, zName)
	_sqlite3DbFree(tls, db, zName)
	return i
}

// C documentation
//
//	/* The table or view or trigger name is passed to this routine via tokens
//	** pName1 and pName2. If the table name was fully qualified, for example:
//	**
//	** CREATE TABLE xxx.yyy (...);
//	**
//	** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if
//	** the table name is not fully qualified, i.e.:
//	**
//	** CREATE TABLE yyy(...);
//	**
//	** Then pName1 is set to "yyy" and pName2 is "".
//	**
//	** This routine sets the *ppUnqual pointer to point at the token (pName1 or
//	** pName2) that stores the unqualified table name.  The index of the
//	** database "xxx" is returned.
//	*/
func _sqlite3TwoPartName(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pUnqual uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	var iDb int32
	_, _ = db, iDb /* Database holding the object */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TToken)(unsafe.Pointer(pName2)).Fn > uint32(0) {
		if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13904, 0)
			return -int32(1)
		}
		*(*uintptr)(unsafe.Pointer(pUnqual)) = pName2
		iDb = _sqlite3FindDb(tls, db, pName1)
		if iDb < 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13921, libc.VaList(bp+8, pName1))
			return -int32(1)
		}
	} else {
		iDb = int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)
		*(*uintptr)(unsafe.Pointer(pUnqual)) = pName1
	}
	return iDb
}

// C documentation
//
//	/*
//	** True if PRAGMA writable_schema is ON
//	*/
func _sqlite3WritableSchema(tls *libc.TLS, db uintptr) (r int32) {
	return libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(libc.Int32FromInt32(SQLITE_WriteSchema)|libc.Int32FromInt32(SQLITE_Defensive)) == uint64(SQLITE_WriteSchema))
}

// 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 + 172 + 8))&0x2>>1)) != 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit))) != 0 || Xsqlite3_stricmp(tls, zName, *(*uintptr)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 1*4))) != 0 || Xsqlite3_stricmp(tls, zTblName, *(*uintptr)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 2*4))) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1672, 0) /* corruptSchema() will supply the error */
			return int32(SQLITE_ERROR)
		}
	} else {
		if int32((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && 0 == Xsqlite3_strnicmp(tls, zName, __ccgo_ts+7898, int32(7)) || _sqlite3ReadOnlyShadowTables(tls, db) != 0 && _sqlite3ShadowTableName(tls, db, zName) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13941, libc.VaList(bp+8, zName))
			return int32(SQLITE_ERROR)
		}
	}
	return SQLITE_OK
}

// 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 + 56))&0x3>>0)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))) {
			break
		}
		goto _1
	_1:
		;
		p = (*TIndex)(unsafe.Pointer(p)).FpNext
	}
	return p
}

// C documentation
//
//	/*
//	** Convert an table column number into a index column number.  That is,
//	** for the column iCol in the table (as defined by the CREATE TABLE statement)
//	** find the (first) offset of that column in index pIdx.  Or return -1
//	** if column iCol is not used in index pIdx.
//	*/
func _sqlite3TableColumnToIndex(tls *libc.TLS, pIdx uintptr, iCol Ti16) (r Ti16) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
			break
		}
		if int32(int32(iCol)) == int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) {
			return int16(int16(i))
		}
		goto _1
	_1:
		;
		i++
	}
	return int16(-int32(1))
}

// C documentation
//
//	/* Convert a storage column number into a table column number.
//	**
//	** The storage column number (0,1,2,....) is the index of the value
//	** as it appears in the record on disk.  The true column number
//	** is the index (0,1,2,...) of the column in the CREATE TABLE statement.
//	**
//	** The storage column number is less than the table column number if
//	** and only there are VIRTUAL columns to the left.
//	**
//	** If SQLITE_OMIT_GENERATED_COLUMNS, this routine is a no-op macro.
//	*/
func _sqlite3StorageColumnToTable(tls *libc.TLS, pTab uintptr, iCol Ti16) (r Ti16) {
	var i int32
	_ = i
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasVirtual) != 0 {
		i = 0
		for {
			if !(i <= int32(int32(iCol))) {
				break
			}
			if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
				iCol++
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return iCol
}

// C documentation
//
//	/* Convert a table column number into a storage column number.
//	**
//	** The storage column number (0,1,2,....) is the index of the value
//	** as it appears in the record on disk.  Or, if the input column is
//	** the N-th virtual column (zero-based) then the storage number is
//	** the number of non-virtual columns in the table plus N.
//	**
//	** The true column number is the index (0,1,2,...) of the column in
//	** the CREATE TABLE statement.
//	**
//	** If the input column is a VIRTUAL column, then it should not appear
//	** in storage.  But the value sometimes is cached in registers that
//	** follow the range of registers used to construct storage.  This
//	** avoids computing the same VIRTUAL column multiple times, and provides
//	** values for use by OP_Param opcodes in triggers.  Hence, if the
//	** input column is a VIRTUAL table, put it after all the other columns.
//	**
//	** In the following, N means "normal column", S means STORED, and
//	** V means VIRTUAL.  Suppose the CREATE TABLE has columns like this:
//	**
//	**        CREATE TABLE ex(N,S,V,N,S,V,N,S,V);
//	**                     -- 0 1 2 3 4 5 6 7 8
//	**
//	** Then the mapping from this function is as follows:
//	**
//	**    INPUTS:     0 1 2 3 4 5 6 7 8
//	**    OUTPUTS:    0 1 6 2 3 7 4 5 8
//	**
//	** So, in other words, this routine shifts all the virtual columns to
//	** the end.
//	**
//	** If SQLITE_OMIT_GENERATED_COLUMNS then there are no virtual columns and
//	** this routine is a no-op macro.  If the pTab does not have any virtual
//	** columns, then this routine is no-op that always return iCol.  If iCol
//	** is negative (indicating the ROWID column) then this routine return iCol.
//	*/
func _sqlite3TableColumnToStorage(tls *libc.TLS, pTab uintptr, iCol Ti16) (r Ti16) {
	var i int32
	var n Ti16
	_, _ = i, n
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasVirtual) == uint32(0) || int32(int32(iCol)) < 0 {
		return iCol
	}
	i = 0
	n = libc.Int16FromInt32(0)
	for {
		if !(i < int32(int32(iCol))) {
			break
		}
		if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
			n++
		}
		goto _1
	_1:
		;
		i++
	}
	if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
		/* iCol is a virtual column itself */
		return int16(int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol) + i - int32(int32(n)))
	} else {
		/* iCol is a normal or stored column */
		return n
	}
	return r
}

// C documentation
//
//	/*
//	** Insert a single OP_JournalMode query opcode in order to force the
//	** prepared statement to return false for sqlite3_stmt_readonly().  This
//	** is used by CREATE TABLE IF NOT EXISTS and similar if the table already
//	** exists, so that the prepared statement for CREATE TABLE IF NOT EXISTS
//	** will return false for sqlite3_stmt_readonly() even if that statement
//	** is a read-only no-op.
//	*/
func _sqlite3ForceNotReadOnly(tls *libc.TLS, pParse uintptr) {
	var iReg, v1 int32
	var v, v2 uintptr
	_, _, _, _ = iReg, v, v1, v2
	v2 = pParse + 44
	*(*int32)(unsafe.Pointer(v2))++
	v1 = *(*int32)(unsafe.Pointer(v2))
	iReg = v1
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_JournalMode), 0, iReg, -int32(1))
		_sqlite3VdbeUsesBtree(tls, v, 0)
	}
}

// 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, v10, v11, v13, v15, v7, v8 int32
	var db, pTable, v, zDb, zDb1, zName, v1, v12, v14, v2, v3, v4, v5, v9 uintptr
	var v6 bool
	var _ /* pName at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, db, fileFormat, iDb, pTable, reg1, reg2, reg3, v, zDb, zDb1, zName, v1, v10, v11, v12, v13, v14, v15, v2, v3, v4, v5, v6, v7, v8, v9
	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 = int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			v1 = __ccgo_ts + 7906
		} else {
			v1 = __ccgo_ts + 7439
		}
		zName = _sqlite3DbStrDup(tls, db, v1)
		*(*uintptr)(unsafe.Pointer(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+13983, 0)
			return
		}
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp != 0 {
			iDb = int32(1)
		}
		zName = _sqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenMap(tls, pParse, zName, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	(*TParse)(unsafe.Pointer(pParse)).FsNameToken = *(*TToken)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))
	if zName == uintptr(0) {
		return
	}
	if isView != 0 {
		v2 = __ccgo_ts + 12230
	} else {
		v2 = __ccgo_ts + 10492
	}
	if _sqlite3CheckObjectName(tls, pParse, zName, v2, zName) != 0 {
		goto begin_table_error
	}
	if int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) == int32(1) {
		isTemp = int32(1)
	}
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp == int32(1) {
		v3 = __ccgo_ts + 7906
	} else {
		v3 = __ccgo_ts + 7439
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v3, uintptr(0), zDb) != 0 {
		goto begin_table_error
	}
	if !(isVirtual != 0) && _sqlite3AuthCheck(tls, pParse, int32(_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 !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
		zDb1 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
		if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
			goto begin_table_error
		}
		pTable = _sqlite3FindTable(tls, db, zName, zDb1)
		if pTable != 0 {
			if !(noErr != 0) {
				if int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VIEW) {
					v4 = __ccgo_ts + 12230
				} else {
					v4 = __ccgo_ts + 10492
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14024, libc.VaList(bp+16, v4, *(*uintptr)(unsafe.Pointer(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+14045, libc.VaList(bp+16, zName))
			goto begin_table_error
		}
	}
	pTable = _sqlite3DbMallocZero(tls, db, uint64(64))
	if pTable == uintptr(0) {
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
		(*TParse)(unsafe.Pointer(pParse)).FnErr++
		goto begin_table_error
	}
	(*TTable)(unsafe.Pointer(pTable)).FzName = zName
	(*TTable)(unsafe.Pointer(pTable)).FiPKey = int16(-int32(1))
	(*TTable)(unsafe.Pointer(pTable)).FpSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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 {
		v5 = _sqlite3GetVdbe(tls, pParse)
		v = v5
	}
	if v6 && v5 != 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.
		 */
		v9 = pParse + 44
		*(*int32)(unsafe.Pointer(v9))++
		v8 = *(*int32)(unsafe.Pointer(v9))
		v7 = v8
		(*TParse)(unsafe.Pointer(pParse)).FregRowid = v7
		reg1 = v7
		v12 = pParse + 44
		*(*int32)(unsafe.Pointer(v12))++
		v11 = *(*int32)(unsafe.Pointer(v12))
		v10 = v11
		(*TParse)(unsafe.Pointer(pParse)).FregRoot = v10
		reg2 = v10
		v14 = pParse + 44
		*(*int32)(unsafe.Pointer(v14))++
		v13 = *(*int32)(unsafe.Pointer(v14))
		reg3 = v13
		_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) {
			v15 = int32(1)
		} else {
			v15 = int32(SQLITE_MAX_FILE_FORMAT)
		}
		fileFormat = v15
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_FILE_FORMAT), fileFormat)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_TEXT_ENCODING), int32((*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->regRowid.
		 ** The root page number of the new table is left in reg pParse->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 {
			*(*int32)(unsafe.Pointer(pParse + 144)) = _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))
	}
	/* Normal (non-error) return. */
	return
	/* If an error occurs, we jump here */
	goto begin_table_error
begin_table_error:
	;
	(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
	_sqlite3DbFree(tls, db, zName)
	return
}

var _aCode = [4]Tu8{
	0: uint8(SQLITE_CREATE_TABLE),
	1: uint8(SQLITE_CREATE_TEMP_TABLE),
	2: uint8(SQLITE_CREATE_VIEW),
	3: uint8(SQLITE_CREATE_TEMP_VIEW),
}

/* nullRow[] is an OP_Record encoding of a row containing 5 NULLs */
var _nullRow = [6]int8{
	0: int8(6),
}

/* Set properties of a table column based on the (magical)
** name of the column.
 */

// C documentation
//
//	/*
//	** Clean up the data structures associated with the RETURNING clause.
//	*/
func _sqlite3DeleteReturning(tls *libc.TLS, db uintptr, pArg uintptr) {
	var pHash, pRet uintptr
	_, _ = pHash, pRet
	pRet = pArg
	pHash = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 40
	_sqlite3HashInsert(tls, pHash, pRet+104, uintptr(0))
	_sqlite3ExprListDelete(tls, db, (*TReturning)(unsafe.Pointer(pRet)).FpReturnEL)
	_sqlite3DbFree(tls, db, pRet)
}

// 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+14080, 0)
	} else {
	}
	(*TParse)(unsafe.Pointer(pParse)).FbReturning = uint8(1)
	pRet = _sqlite3DbMallocZero(tls, db, uint64(144))
	if pRet == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pList)
		return
	}
	*(*uintptr)(unsafe.Pointer(pParse + 144)) = 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+104, __ccgo_ts+14114, libc.VaList(bp+8, pParse))
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FzName = pRet + 104
	(*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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FpTabSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Fstep_list = pRet + 44
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.Fop = uint8(TK_RETURNING)
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpTrig = pRet + 8
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpExprList = pList
	pHash = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 40
	if _sqlite3HashInsert(tls, pHash, pRet+104, pRet+8) == pRet+8 {
		_sqlite3OomFault(tls, db)
	}
}

// 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(32)
	defer tls.Free(32)
	*(*TToken)(unsafe.Pointer(bp)) = _sName
	*(*TToken)(unsafe.Pointer(bp + 8)) = _sType
	var aNew, db, p, pCol, z, zType, v1, p4 uintptr
	var affinity int8
	var eType, hName, szEst Tu8
	var i int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = aNew, affinity, db, eType, hName, i, p, pCol, szEst, z, zType, v1, p4
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	eType = uint8(COLTYPE_CUSTOM)
	szEst = uint8(1)
	affinity = int8(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)(unsafe.Pointer(db + 120 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14134, libc.VaList(bp+24, (*TTable)(unsafe.Pointer(p)).FzName))
		return
	}
	if !(int32((*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)(unsafe.Pointer(bp + 8))).Fn >= uint32(16) && Xsqlite3_strnicmp(tls, (*(*TToken)(unsafe.Pointer(bp + 8))).Fz+uintptr((*(*TToken)(unsafe.Pointer(bp + 8))).Fn-libc.Uint32FromInt32(6)), __ccgo_ts+14157, int32(6)) == 0 {
		(*(*TToken)(unsafe.Pointer(bp + 8))).Fn -= uint32(6)
		for (*(*TToken)(unsafe.Pointer(bp + 8))).Fn > uint32(0) && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer((*(*TToken)(unsafe.Pointer(bp + 8))).Fz + uintptr((*(*TToken)(unsafe.Pointer(bp + 8))).Fn-uint32(1)))))])&int32(0x01) != 0 {
			(*(*TToken)(unsafe.Pointer(bp + 8))).Fn--
		}
		if (*(*TToken)(unsafe.Pointer(bp + 8))).Fn >= uint32(9) && Xsqlite3_strnicmp(tls, (*(*TToken)(unsafe.Pointer(bp + 8))).Fz+uintptr((*(*TToken)(unsafe.Pointer(bp + 8))).Fn-libc.Uint32FromInt32(9)), __ccgo_ts+14164, int32(9)) == 0 {
			(*(*TToken)(unsafe.Pointer(bp + 8))).Fn -= uint32(9)
			for (*(*TToken)(unsafe.Pointer(bp + 8))).Fn > uint32(0) && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer((*(*TToken)(unsafe.Pointer(bp + 8))).Fz + uintptr((*(*TToken)(unsafe.Pointer(bp + 8))).Fn-uint32(1)))))])&int32(0x01) != 0 {
				(*(*TToken)(unsafe.Pointer(bp + 8))).Fn--
			}
		}
	}
	/* 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)(unsafe.Pointer(bp + 8))).Fn >= uint32(3) {
		_sqlite3DequoteToken(tls, bp+8)
		i = 0
		for {
			if !(i < int32(SQLITE_N_STDTYPE)) {
				break
			}
			if (*(*TToken)(unsafe.Pointer(bp + 8))).Fn == uint32(_sqlite3StdTypeLen[i]) && Xsqlite3_strnicmp(tls, (*(*TToken)(unsafe.Pointer(bp + 8))).Fz, _sqlite3StdType[i], int32((*(*TToken)(unsafe.Pointer(bp + 8))).Fn)) == 0 {
				(*(*TToken)(unsafe.Pointer(bp + 8))).Fn = uint32(0)
				eType = uint8(i + int32(1))
				affinity = _sqlite3StdTypeAffinity[i]
				if int32(int32(affinity)) <= int32(SQLITE_AFF_TEXT) {
					szEst = uint8(5)
				}
				break
			}
			goto _2
		_2:
			;
			i++
		}
	}
	z = _sqlite3DbMallocRaw(tls, db, uint64(int64((*(*TToken)(unsafe.Pointer(bp))).Fn)+int64(1)+int64((*(*TToken)(unsafe.Pointer(bp + 8))).Fn)+libc.BoolInt64((*(*TToken)(unsafe.Pointer(bp + 8))).Fn > libc.Uint32FromInt32(0))))
	if z == uintptr(0) {
		return
	}
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameTokenMap(tls, pParse, z, bp)
	}
	libc.Xmemcpy(tls, z, (*(*TToken)(unsafe.Pointer(bp))).Fz, (*(*TToken)(unsafe.Pointer(bp))).Fn)
	*(*int8)(unsafe.Pointer(z + uintptr((*(*TToken)(unsafe.Pointer(bp))).Fn))) = 0
	_sqlite3Dequote(tls, z)
	hName = _sqlite3StrIHash(tls, z)
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
			break
		}
		if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(i)*12))).FhName) == int32(int32(hName)) && _sqlite3StrICmp(tls, z, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(i)*12))).FzCnName) == 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14174, libc.VaList(bp+24, z))
			_sqlite3DbFree(tls, db, z)
			return
		}
		goto _3
	_3:
		;
		i++
	}
	aNew = _sqlite3DbRealloc(tls, db, (*TTable)(unsafe.Pointer(p)).FaCol, uint64((int64((*TTable)(unsafe.Pointer(p)).FnCol)+int64(1))*int64(12)))
	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)*12
	libc.Xmemset(tls, pCol, 0, uint32(12))
	(*TColumn)(unsafe.Pointer(pCol)).FzCnName = z
	(*TColumn)(unsafe.Pointer(pCol)).FhName = hName
	if (*(*TToken)(unsafe.Pointer(bp + 8))).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+4, uint32(uint32(eType)), 4, 0xf0)
		(*TColumn)(unsafe.Pointer(pCol)).FszEst = szEst
	} else {
		zType = z + uintptr(_sqlite3Strlen30(tls, z)) + uintptr(1)
		libc.Xmemcpy(tls, zType, (*(*TToken)(unsafe.Pointer(bp + 8))).Fz, (*(*TToken)(unsafe.Pointer(bp + 8))).Fn)
		*(*int8)(unsafe.Pointer(zType + uintptr((*(*TToken)(unsafe.Pointer(bp + 8))).Fn))) = 0
		_sqlite3Dequote(tls, zType)
		(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3AffinityType(tls, zType, pCol)
		p4 = pCol + 10
		*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(COLFLAG_HASTYPE))
	}
	(*TTable)(unsafe.Pointer(p)).FnCol++
	(*TTable)(unsafe.Pointer(p)).FnNVCol++
	(*TParse)(unsafe.Pointer(pParse)).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))*12
	libc.SetBitFieldPtr8Uint32(pCol+4, uint32(uint8(uint8(onError))), 0, 0xf)
	*(*Tu32)(unsafe.Pointer(p + 28)) |= uint32(TF_HasNotNull)
	/* Set the uniqNotNull flag on any UNIQUE or PK indexes already created
	 ** on this column.  */
	if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_UNIQUE) != 0 {
		pIdx = (*TTable)(unsafe.Pointer(p)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn))) == int32((*TTable)(unsafe.Pointer(p)).FnCol)-int32(1) {
				libc.SetBitFieldPtr16Uint32(pIdx+56, libc.Uint32FromInt32(1), 3, 0x8)
			}
			goto _1
		_1:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	}
}

// C documentation
//
//	/*
//	** Scan the column type name zType (length nType) and return the
//	** associated affinity type.
//	**
//	** This routine does a case-independent search of zType for the
//	** substrings in the following table. If one of the substrings is
//	** found, the corresponding affinity is returned. If zType contains
//	** more than one of the substrings, entries toward the top of
//	** the table take priority. For example, if zType is 'BLOBINT',
//	** SQLITE_AFF_INTEGER is returned.
//	**
//	** Substring     | Affinity
//	** --------------------------------
//	** 'INT'         | SQLITE_AFF_INTEGER
//	** 'CHAR'        | SQLITE_AFF_TEXT
//	** 'CLOB'        | SQLITE_AFF_TEXT
//	** 'TEXT'        | SQLITE_AFF_TEXT
//	** 'BLOB'        | SQLITE_AFF_BLOB
//	** 'REAL'        | SQLITE_AFF_REAL
//	** 'FLOA'        | SQLITE_AFF_REAL
//	** 'DOUB'        | SQLITE_AFF_REAL
//	**
//	** If none of the substrings in the above table are found,
//	** SQLITE_AFF_NUMERIC is returned.
//	*/
func _sqlite3AffinityType(tls *libc.TLS, zIn uintptr, pCol uintptr) (r int8) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aff int8
	var h Tu32
	var x Tu8
	var zChar uintptr
	var _ /* v at bp+0 */ int32
	_, _, _, _ = aff, h, x, zChar
	h = uint32(0)
	aff = int8(SQLITE_AFF_NUMERIC)
	zChar = uintptr(0)
	for *(*int8)(unsafe.Pointer(zIn)) != 0 {
		x = *(*Tu8)(unsafe.Pointer(zIn))
		h = h<<libc.Int32FromInt32(8) + uint32(_sqlite3UpperToLower[x])
		zIn++
		if h == uint32(libc.Int32FromUint8('c')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('h')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('a')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('r')) { /* CHAR */
			aff = int8(SQLITE_AFF_TEXT)
			zChar = zIn
		} else {
			if h == uint32(libc.Int32FromUint8('c')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('l')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('b')) { /* CLOB */
				aff = int8(SQLITE_AFF_TEXT)
			} else {
				if h == uint32(libc.Int32FromUint8('t')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('e')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('x')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('t')) { /* TEXT */
					aff = int8(SQLITE_AFF_TEXT)
				} else {
					if h == uint32(libc.Int32FromUint8('b')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('l')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('b')) && (int32(int32(aff)) == int32(SQLITE_AFF_NUMERIC) || int32(int32(aff)) == int32(SQLITE_AFF_REAL)) {
						aff = int8(SQLITE_AFF_BLOB)
						if int32(*(*int8)(unsafe.Pointer(zIn))) == int32('(') {
							zChar = zIn
						}
					} else {
						if h == uint32(libc.Int32FromUint8('r')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('e')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('a')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('l')) && int32(int32(aff)) == int32(SQLITE_AFF_NUMERIC) {
							aff = int8(SQLITE_AFF_REAL)
						} else {
							if h == uint32(libc.Int32FromUint8('f')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('l')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('a')) && int32(int32(aff)) == int32(SQLITE_AFF_NUMERIC) {
								aff = int8(SQLITE_AFF_REAL)
							} else {
								if h == uint32(libc.Int32FromUint8('d')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('u')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('b')) && int32(int32(aff)) == int32(SQLITE_AFF_NUMERIC) {
									aff = int8(SQLITE_AFF_REAL)
								} else {
									if h&uint32(0x00FFFFFF) == uint32(libc.Int32FromUint8('i')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('n')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('t')) { /* INT */
										aff = int8(SQLITE_AFF_INTEGER)
										break
									}
								}
							}
						}
					}
				}
			}
		}
	}
	/* If pCol is not NULL, store an estimate of the field size.  The
	 ** estimate is scaled so that the size of an integer is 1.  */
	if pCol != 0 {
		*(*int32)(unsafe.Pointer(bp)) = 0 /* default size is approx 4 bytes */
		if int32(int32(aff)) < int32(SQLITE_AFF_NUMERIC) {
			if zChar != 0 {
				for *(*int8)(unsafe.Pointer(zChar)) != 0 {
					if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zChar)))])&int32(0x04) != 0 {
						/* BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1) */
						_sqlite3GetInt32(tls, zChar, bp)
						break
					}
					zChar++
				}
			} else {
				*(*int32)(unsafe.Pointer(bp)) = int32(16) /* BLOB, TEXT, CLOB -> r=5  (approx 20 bytes)*/
			}
		}
		*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(bp))/int32(4) + int32(1)
		if *(*int32)(unsafe.Pointer(bp)) > int32(255) {
			*(*int32)(unsafe.Pointer(bp)) = int32(255)
		}
		(*TColumn)(unsafe.Pointer(pCol)).FszEst = uint8(*(*int32)(unsafe.Pointer(bp)))
	}
	return aff
}

// C documentation
//
//	/*
//	** The expression is the default value for the most recently added column
//	** of the table currently under construction.
//	**
//	** Default value expressions must be constant.  Raise an exception if this
//	** is not the case.
//	**
//	** This routine is called by the parser while in the middle of
//	** parsing a CREATE TABLE statement.
//	*/
func _sqlite3AddDefaultValue(tls *libc.TLS, pParse uintptr, pExpr uintptr, zStart uintptr, zEnd uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var db, p, pCol, pDfltExpr uintptr
	var isInit int32
	var _ /* x at bp+0 */ TExpr
	_, _, _, _, _ = db, isInit, p, pCol, pDfltExpr
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if p != uintptr(0) {
		isInit = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) != int32(1))
		pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(p)).FnCol)-int32(1))*12
		if !(_sqlite3ExprIsConstantOrFunction(tls, pExpr, uint8(uint8(isInit))) != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14200, libc.VaList(bp+64, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
		} else {
			if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14245, 0)
			} else {
				libc.Xmemset(tls, bp, 0, uint32(52))
				(*(*TExpr)(unsafe.Pointer(bp))).Fop = uint8(TK_SPAN)
				*(*uintptr)(unsafe.Pointer(bp + 8)) = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
				(*(*TExpr)(unsafe.Pointer(bp))).FpLeft = pExpr
				(*(*TExpr)(unsafe.Pointer(bp))).Fflags = uint32(EP_Skip)
				pDfltExpr = _sqlite3ExprDup(tls, db, bp, int32(EXPRDUP_REDUCE))
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)))
				_sqlite3ColumnSetExpr(tls, pParse, p, pCol, pDfltExpr)
			}
		}
	}
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameExprUnmap(tls, pParse, pExpr)
	}
	_sqlite3ExprDelete(tls, db, pExpr)
}

// C documentation
//
//	/*
//	** Backwards Compatibility Hack:
//	**
//	** Historical versions of SQLite accepted strings as column names in
//	** indexes and PRIMARY KEY constraints and in UNIQUE constraints.  Example:
//	**
//	**     CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
//	**     CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
//	**
//	** This is goofy.  But to preserve backwards compatibility we continue to
//	** accept it.  This routine does the necessary conversion.  It converts
//	** the expression given in its argument from a TK_STRING into a TK_ID
//	** if the expression is just a TK_STRING with an optional COLLATE clause.
//	** If the expression is anything other than TK_STRING, the expression is
//	** unchanged.
//	*/
func _sqlite3StringToId(tls *libc.TLS, p uintptr) {
	if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_STRING) {
		(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_ID)
	} else {
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLLATE) && int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).FpLeft)).Fop) == int32(TK_STRING) {
			(*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(p)).FpLeft)).Fop = uint8(TK_ID)
		}
	}
}

// C documentation
//
//	/*
//	** Tag the given column as being part of the PRIMARY KEY
//	*/
func _makeColumnPartOfPrimaryKey(tls *libc.TLS, pParse uintptr, pCol uintptr) {
	var p1 uintptr
	_ = p1
	p1 = pCol + 10
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(COLFLAG_PRIMKEY))
	if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14286, 0)
	}
}

// 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, zCName uintptr
	_, _, _, _, _, _, _, _ = i, iCol, nTerm, pCExpr, pCExpr1, pCol, pTab, zCName
	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+14338, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto primary_key_exit
	}
	*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(TF_HasPrimaryKey)
	if pList == uintptr(0) {
		iCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol) - int32(1)
		pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12
		_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)*20))).FpExpr)
			_sqlite3StringToId(tls, pCExpr)
			if int32((*TExpr)(unsafe.Pointer(pCExpr)).Fop) == int32(TK_ID) {
				zCName = *(*uintptr)(unsafe.Pointer(pCExpr + 8))
				iCol = 0
				for {
					if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
						break
					}
					if _sqlite3StrICmp(tls, zCName, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName) == 0 {
						pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12
						_makeColumnPartOfPrimaryKey(tls, pParse, pCol)
						break
					}
					goto _2
				_2:
					;
					iCol++
				}
			}
			goto _1
		_1:
			;
			i++
		}
	}
	if nTerm == int32(1) && pCol != 0 && int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf0>>4)) == int32(COLTYPE_INTEGER) && sortOrder != int32(SQLITE_SO_DESC) {
		if int32((*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+32, pCExpr1)
		}
		(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(int16(iCol))
		(*TTable)(unsafe.Pointer(pTab)).FkeyConf = uint8(uint8(onError))
		*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(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+14379, 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 a new CHECK constraint to the table currently under construction.
//	*/
func _sqlite3AddCheckConstraint(tls *libc.TLS, pParse uintptr, pCheckExpr uintptr, zStart uintptr, zEnd uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pTab uintptr
	var _ /* t at bp+0 */ TToken
	_, _ = db, pTab
	pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pTab != 0 && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == libc.Int32FromInt32(PARSE_MODE_DECLARE_VTAB)) && !(_sqlite3BtreeIsReadonly(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)*16))).FpBt) != 0) {
		(*TTable)(unsafe.Pointer(pTab)).FpCheck = _sqlite3ExprListAppend(tls, pParse, (*TTable)(unsafe.Pointer(pTab)).FpCheck, pCheckExpr)
		if (*TParse)(unsafe.Pointer(pParse)).FconstraintName.Fn != 0 {
			_sqlite3ExprListSetName(tls, pParse, (*TTable)(unsafe.Pointer(pTab)).FpCheck, pParse+80, int32(1))
		} else {
			zStart++
			for {
				if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zStart)))])&int32(0x01) != 0) {
					break
				}
				goto _1
			_1:
				;
				zStart++
			}
			for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zEnd + uintptr(-libc.Int32FromInt32(1)))))])&int32(0x01) != 0 {
				zEnd--
			}
			(*(*TToken)(unsafe.Pointer(bp))).Fz = zStart
			(*(*TToken)(unsafe.Pointer(bp))).Fn = uint32(int32(int32(zEnd)) - int32((*(*TToken)(unsafe.Pointer(bp))).Fz))
			_sqlite3ExprListSetName(tls, pParse, (*TTable)(unsafe.Pointer(pTab)).FpCheck, bp, int32(1))
		}
	} else {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pCheckExpr)
	}
}

// C documentation
//
//	/*
//	** Set the collation function of the most recently parsed table column
//	** to the CollSeq given.
//	*/
func _sqlite3AddCollateType(tls *libc.TLS, pParse uintptr, pToken uintptr) {
	var db, p, pIdx, zColl, v1 uintptr
	var i int32
	_, _, _, _, _, _ = db, i, p, pIdx, zColl, v1
	v1 = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	p = v1
	if v1 == uintptr(0) || int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		return
	}
	i = int32((*TTable)(unsafe.Pointer(p)).FnCol) - int32(1)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	zColl = _sqlite3NameFromToken(tls, db, pToken)
	if !(zColl != 0) {
		return
	}
	if _sqlite3LocateCollSeq(tls, pParse, zColl) != 0 {
		_sqlite3ColumnSetColl(tls, db, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(i)*12, zColl)
		/* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
		 ** then an index may have been created on this column before the
		 ** collation type was added. Correct this if it is the case.
		 */
		pIdx = (*TTable)(unsafe.Pointer(p)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn))) == i {
				*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl)) = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(i)*12)
			}
			goto _2
		_2:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	}
	_sqlite3DbFree(tls, db, zColl)
}

// C documentation
//
//	/* Change the most recently parsed column to be a GENERATED ALWAYS AS
//	** column.
//	*/
func _sqlite3AddGenerated(tls *libc.TLS, pParse uintptr, pExpr uintptr, pType uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType Tu8
	var pCol, pTab, p1 uintptr
	_, _, _, _ = eType, pCol, pTab, p1
	eType = uint8(COLFLAG_VIRTUAL)
	pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if pTab == uintptr(0) {
		/* generated column in an CREATE TABLE IF NOT EXISTS that already exists */
		goto generated_done
	}
	pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1))*12
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14435, 0)
		goto generated_done
	}
	if int32((*TColumn)(unsafe.Pointer(pCol)).FiDflt) > 0 {
		goto generated_error
	}
	if pType != 0 {
		if (*TToken)(unsafe.Pointer(pType)).Fn == uint32(7) && Xsqlite3_strnicmp(tls, __ccgo_ts+14478, (*TToken)(unsafe.Pointer(pType)).Fz, int32(7)) == 0 {
			/* no-op */
		} else {
			if (*TToken)(unsafe.Pointer(pType)).Fn == uint32(6) && Xsqlite3_strnicmp(tls, __ccgo_ts+14486, (*TToken)(unsafe.Pointer(pType)).Fz, int32(6)) == 0 {
				eType = uint8(COLFLAG_STORED)
			} else {
				goto generated_error
			}
		}
	}
	if int32(int32(eType)) == int32(COLFLAG_VIRTUAL) {
		(*TTable)(unsafe.Pointer(pTab)).FnNVCol--
	}
	p1 = pCol + 10
	*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | int32(int32(eType)))
	*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(uint32(eType))
	if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
		_makeColumnPartOfPrimaryKey(tls, pParse, pCol) /* For the error message */
	}
	if pExpr != 0 && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_ID) {
		/* The value of a generated column needs to be a real expression, not
		 ** just a reference to another column, in order for covering index
		 ** optimizations to work correctly.  So if the value is not an expression,
		 ** turn it into one by adding a unary "+" operator. */
		pExpr = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), pExpr, uintptr(0))
	}
	if pExpr != 0 && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_RAISE) {
		(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = (*TColumn)(unsafe.Pointer(pCol)).Faffinity
	}
	_sqlite3ColumnSetExpr(tls, pParse, pTab, pCol, pExpr)
	pExpr = uintptr(0)
	goto generated_done
	goto generated_error
generated_error:
	;
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14493, libc.VaList(bp+8, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
	goto generated_done
generated_done:
	;
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
}

// C documentation
//
//	/*
//	** Generate code that will increment the schema cookie.
//	**
//	** The schema cookie is used to determine when the schema for the
//	** database changes.  After each schema change, the cookie value
//	** changes.  When a process first reads the schema it records the
//	** cookie.  Thereafter, whenever it goes to access the database,
//	** it checks the cookie to make sure the schema has not changed
//	** since it was last read.
//	**
//	** This plan is not completely bullet-proof.  It is possible for
//	** the schema to change multiple times and for the cookie to be
//	** set back to prior value.  But schema changes are infrequent
//	** and the probability of hitting the same cookie value is only
//	** 1 chance in 2^32.  So we're safe enough.
//	**
//	** IMPLEMENTATION-OF: R-34230-56049 SQLite automatically increments
//	** the schema-version whenever the schema changes.
//	*/
func _sqlite3ChangeCookie(tls *libc.TLS, pParse uintptr, iDb int32) {
	var db, v uintptr
	_, _ = db, v
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_SCHEMA_VERSION), int32(libc.Uint32FromInt32(1)+uint32((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema)).Fschema_cookie)))
}

// C documentation
//
//	/*
//	** Measure the number of characters needed to output the given
//	** identifier.  The number returned includes any quotes used
//	** but does not include the null terminator.
//	**
//	** The estimate is conservative.  It might be larger that what is
//	** really needed.
//	*/
func _identLength(tls *libc.TLS, z uintptr) (r int32) {
	var n int32
	_ = n
	n = 0
	for {
		if !(*(*int8)(unsafe.Pointer(z)) != 0) {
			break
		}
		if int32(*(*int8)(unsafe.Pointer(z))) == int32('"') {
			n++
		}
		goto _1
	_1:
		;
		n++
		z++
	}
	return n + int32(2)
}

// C documentation
//
//	/*
//	** The first parameter is a pointer to an output buffer. The second
//	** parameter is a pointer to an integer that contains the offset at
//	** which to write into the output buffer. This function copies the
//	** nul-terminated string pointed to by the third parameter, zSignedIdent,
//	** to the specified offset in the buffer and updates *pIdx to refer
//	** to the first byte after the last byte written before returning.
//	**
//	** If the string zSignedIdent consists entirely of alphanumeric
//	** characters, does not begin with a digit and is not an SQL keyword,
//	** then it is copied to the output buffer exactly as it is. Otherwise,
//	** it is quoted using double-quotes.
//	*/
func _identPut(tls *libc.TLS, z uintptr, pIdx uintptr, zSignedIdent uintptr) {
	var i, j, needQuote, v2, v4, v5, v6 int32
	var zIdent uintptr
	_, _, _, _, _, _, _, _ = i, j, needQuote, zIdent, v2, v4, v5, v6
	zIdent = zSignedIdent
	i = *(*int32)(unsafe.Pointer(pIdx))
	j = 0
	for {
		if !(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j))) != 0) {
			break
		}
		if !(int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))])&libc.Int32FromInt32(0x06) != 0) && int32(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))) != int32('_') {
			break
		}
		goto _1
	_1:
		;
		j++
	}
	needQuote = libc.BoolInt32(int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zIdent))])&int32(0x04) != 0 || _sqlite3KeywordCode(tls, zIdent, j) != int32(TK_ID) || int32(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))) != 0 || j == 0)
	if needQuote != 0 {
		v2 = i
		i++
		*(*int8)(unsafe.Pointer(z + uintptr(v2))) = int8('"')
	}
	j = 0
	for {
		if !(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j))) != 0) {
			break
		}
		v4 = i
		i++
		*(*int8)(unsafe.Pointer(z + uintptr(v4))) = int8(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j))))
		if int32(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))) == int32('"') {
			v5 = i
			i++
			*(*int8)(unsafe.Pointer(z + uintptr(v5))) = int8('"')
		}
		goto _3
	_3:
		;
		j++
	}
	if needQuote != 0 {
		v6 = i
		i++
		*(*int8)(unsafe.Pointer(z + uintptr(v6))) = int8('"')
	}
	*(*int8)(unsafe.Pointer(z + uintptr(i))) = 0
	*(*int32)(unsafe.Pointer(pIdx)) = i
}

// C documentation
//
//	/*
//	** Generate a CREATE TABLE statement appropriate for the given
//	** table.  Memory to hold the text of the statement is obtained
//	** from sqliteMalloc() and must be freed by the calling function.
//	*/
func _createTableStmt(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, len1, n, v2 int32
	var pCol, zEnd, zSep, zSep2, zStmt, zType uintptr
	var _ /* k at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = i, len1, n, pCol, zEnd, zSep, zSep2, zStmt, zType, v2
	n = 0
	pCol = (*TTable)(unsafe.Pointer(p)).FaCol
	i = libc.Int32FromInt32(0)
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
			break
		}
		n += _identLength(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName) + int32(5)
		goto _1
	_1:
		;
		i++
		pCol += 12
	}
	n += _identLength(tls, (*TTable)(unsafe.Pointer(p)).FzName)
	if n < int32(50) {
		zSep = __ccgo_ts + 1672
		zSep2 = __ccgo_ts + 14524
		zEnd = __ccgo_ts + 6479
	} else {
		zSep = __ccgo_ts + 14526
		zSep2 = __ccgo_ts + 14530
		zEnd = __ccgo_ts + 14535
	}
	n += int32(35) + int32(6)*int32((*TTable)(unsafe.Pointer(p)).FnCol)
	zStmt = _sqlite3DbMallocRaw(tls, uintptr(0), uint64(uint64(n)))
	if zStmt == uintptr(0) {
		_sqlite3OomFault(tls, db)
		return uintptr(0)
	}
	Xsqlite3_snprintf(tls, n, zStmt, __ccgo_ts+14538, 0)
	*(*int32)(unsafe.Pointer(bp)) = _sqlite3Strlen30(tls, zStmt)
	_identPut(tls, zStmt, bp, (*TTable)(unsafe.Pointer(p)).FzName)
	v2 = *(*int32)(unsafe.Pointer(bp))
	*(*int32)(unsafe.Pointer(bp))++
	*(*int8)(unsafe.Pointer(zStmt + uintptr(v2))) = int8('(')
	pCol = (*TTable)(unsafe.Pointer(p)).FaCol
	i = libc.Int32FromInt32(0)
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
			break
		}
		Xsqlite3_snprintf(tls, n-*(*int32)(unsafe.Pointer(bp)), zStmt+uintptr(*(*int32)(unsafe.Pointer(bp))), zSep, 0)
		*(*int32)(unsafe.Pointer(bp)) += _sqlite3Strlen30(tls, zStmt+uintptr(*(*int32)(unsafe.Pointer(bp))))
		zSep = zSep2
		_identPut(tls, zStmt, bp, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
		zType = _azType1[int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity)-int32(SQLITE_AFF_BLOB)]
		len1 = _sqlite3Strlen30(tls, zType)
		libc.Xmemcpy(tls, zStmt+uintptr(*(*int32)(unsafe.Pointer(bp))), zType, uint32(uint32(len1)))
		*(*int32)(unsafe.Pointer(bp)) += len1
		goto _3
	_3:
		;
		i++
		pCol += 12
	}
	Xsqlite3_snprintf(tls, n-*(*int32)(unsafe.Pointer(bp)), zStmt+uintptr(*(*int32)(unsafe.Pointer(bp))), __ccgo_ts+4709, libc.VaList(bp+16, zEnd))
	return zStmt
}

var _azType1 = [6]uintptr{
	0: __ccgo_ts + 1672,
	1: __ccgo_ts + 14552,
	2: __ccgo_ts + 14558,
	3: __ccgo_ts + 14563,
	4: __ccgo_ts + 14568,
	5: __ccgo_ts + 14558,
}

// 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, db uintptr, pIdx uintptr, N int32) (r int32) {
	var nByte int32
	var zExtra uintptr
	_, _ = nByte, zExtra
	if int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) >= N {
		return SQLITE_OK
	}
	nByte = int32((libc.Uint32FromInt64(4) + libc.Uint32FromInt64(2) + libc.Uint32FromInt64(2) + libc.Uint32FromInt32(1)) * uint32(uint32(N)))
	zExtra = _sqlite3DbMallocZero(tls, db, uint64(uint64(nByte)))
	if zExtra == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FazColl, uint32(4)*uint32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn))
	(*TIndex)(unsafe.Pointer(pIdx)).FazColl = zExtra
	zExtra += uintptr(uint32(4) * uint32(uint32(N)))
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst, uint32(2)*uint32(int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)+libc.Int32FromInt32(1)))
	(*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst = zExtra
	zExtra += uintptr(uint32(2) * uint32(uint32(N)))
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaiColumn, uint32(2)*uint32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn))
	(*TIndex)(unsafe.Pointer(pIdx)).FaiColumn = zExtra
	zExtra += uintptr(uint32(2) * uint32(uint32(N)))
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder, uint32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn))
	(*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder = zExtra
	(*TIndex)(unsafe.Pointer(pIdx)).FnColumn = uint16(uint16(N))
	libc.SetBitFieldPtr16Uint32(pIdx+56, libc.Uint32FromInt32(1), 4, 0x10)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Estimate the total row width for a table.
//	*/
func _estimateTableWidth(tls *libc.TLS, pTab uintptr) {
	var i int32
	var pTabCol uintptr
	var wTable uint32
	_, _, _ = i, pTabCol, wTable
	wTable = uint32(0)
	i = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	pTabCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
	for {
		if !(i > 0) {
			break
		}
		wTable += uint32((*TColumn)(unsafe.Pointer(pTabCol)).FszEst)
		goto _1
	_1:
		;
		i--
		pTabCol += 12
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) < 0 {
		wTable++
	}
	(*TTable)(unsafe.Pointer(pTab)).FszTabRow = _sqlite3LogEst(tls, uint64(wTable*uint32(4)))
}

// C documentation
//
//	/*
//	** Estimate the average size of a row for an index.
//	*/
func _estimateIndexWidth(tls *libc.TLS, pIdx uintptr) {
	var aCol uintptr
	var i, v2 int32
	var wIndex uint32
	var x Ti16
	_, _, _, _, _ = aCol, i, wIndex, x, v2
	wIndex = uint32(0)
	aCol = (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol
	i = 0
	for {
		if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
			break
		}
		x = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))
		if int32(int32(x)) < 0 {
			v2 = int32(1)
		} else {
			v2 = int32((*(*TColumn)(unsafe.Pointer(aCol + uintptr(x)*12))).FszEst)
		}
		wIndex += uint32(v2)
		goto _1
	_1:
		;
		i++
	}
	(*TIndex)(unsafe.Pointer(pIdx)).FszIdxRow = _sqlite3LogEst(tls, uint64(wIndex*uint32(4)))
}

// C documentation
//
//	/* Return true if column number x is any of the first nCol entries of aiCol[].
//	** This is used to determine if the column number x appears in any of the
//	** first nCol entries of an index.
//	*/
func _hasColumn(tls *libc.TLS, aiCol uintptr, nCol int32, x int32) (r int32) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	for {
		v1 = nCol
		nCol--
		if !(v1 > 0) {
			break
		}
		v2 = aiCol
		aiCol += 2
		if x == int32(*(*Ti16)(unsafe.Pointer(v2))) {
			return int32(1)
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if any of the first nKey entries of index pIdx exactly
//	** match the iCol-th entry of pPk.  pPk is always a WITHOUT ROWID
//	** PRIMARY KEY index.  pIdx is an index on the same table.  pIdx may
//	** or may not be the same index as pPk.
//	**
//	** The first nKey entries of pIdx are guaranteed to be ordinary columns,
//	** not a rowid or expression.
//	**
//	** This routine differs from hasColumn() in that both the column and the
//	** collating sequence must match for this routine, but for hasColumn() only
//	** the column name must match.
//	*/
func _isDupColumn(tls *libc.TLS, pIdx uintptr, nKey int32, pPk uintptr, iCol int32) (r int32) {
	var i, j int32
	_, _ = i, j
	j = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(iCol)*2)))
	i = 0
	for {
		if !(i < nKey) {
			break
		}
		if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) == j && _sqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*4)), *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(iCol)*4))) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/* Recompute the colNotIdxed field of the Index.
//	**
//	** colNotIdxed is a bitmask that has a 0 bit representing each indexed
//	** columns that are within the first 63 columns of the table and a 1 for
//	** all other bits (all columns that are not in the index).  The
//	** high-order bit of colNotIdxed is always 1.  All unindexed columns
//	** of the table have a 1.
//	**
//	** 2019-10-24:  For the purpose of this computation, virtual columns are
//	** not considered to be covered by the index, even if they are in the
//	** index, because we do not trust the logic in whereIndexExprTrans() to be
//	** able to find all instances of a reference to the indexed table column
//	** and convert them into references to the index.  Hence we always want
//	** the actual table at hand in order to recompute the virtual column, if
//	** necessary.
//	**
//	** The colNotIdxed mask is AND-ed with the SrcList.a[].colUsed mask
//	** to determine if the index is covering index.
//	*/
func _recomputeColumnsNotIndexed(tls *libc.TLS, pIdx uintptr) {
	var j, x int32
	var m TBitmask
	var pTab uintptr
	_, _, _, _ = j, m, pTab, x
	m = uint64(0)
	pTab = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
	j = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) - int32(1)
	for {
		if !(j >= 0) {
			break
		}
		x = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))
		if x >= 0 && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(x)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
			if x < int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
				m |= libc.Uint64FromInt32(1) << x
			}
		}
		goto _1
	_1:
		;
		j--
	}
	(*TIndex)(unsafe.Pointer(pIdx)).FcolNotIdxed = ^m
	/* See note-20221022-a */
}

// 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 uintptr
	var i, j, n, nExtra, nPk, v3, v4, v8 int32
	var v5 Tu16
	var _ /* ipkToken at bp+0 */ TToken
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, j, n, nExtra, nPk, pIdx, pList, pPk, v, v3, v4, v5, v8
	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 + 172 + 8))&0x2>>1)) != 0) {
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12 + 4))&0xf>>0)) == OE_None {
				libc.SetBitFieldPtr8Uint32((*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*12+4, libc.Uint32FromInt32(OE_Abort), 0, 0xf)
			}
			goto _1
		_1:
			;
			i++
		}
		*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(TF_HasNotNull)
	}
	/* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
	 ** into BTREE_BLOBKEY.
	 */
	if *(*int32)(unsafe.Pointer(pParse + 144)) != 0 {
		_sqlite3VdbeChangeP3(tls, v, *(*int32)(unsafe.Pointer(pParse + 144)), 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)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*12))).FzCnName)
		pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp, 0))
		if pList == uintptr(0) {
			*(*Tu32)(unsafe.Pointer(pTab + 28)) &= uint32(^libc.Int32FromInt32(TF_WithoutRowid))
			return
		}
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenRemap(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr, pTab+32)
		}
		(*(*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, int32((*TTable)(unsafe.Pointer(pTab)).FkeyConf), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_PRIMARYKEY))
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			*(*Tu32)(unsafe.Pointer(pTab + 28)) &= uint32(^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 < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
				break
			}
			if _isDupColumn(tls, pPk, j, pPk, i) != 0 {
				(*TIndex)(unsafe.Pointer(pPk)).FnColumn--
			} else {
				*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*4)) = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*4))
				*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(j))) = *(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(i)))
				v4 = j
				j++
				*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(v4)*2)) = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))
			}
			goto _2
		_2:
			;
			i++
		}
		(*TIndex)(unsafe.Pointer(pPk)).FnKeyCol = uint16(uint16(j))
	}
	libc.SetBitFieldPtr16Uint32(pPk+56, libc.Uint32FromInt32(1), 5, 0x20)
	if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x2>>1)) != 0) {
		libc.SetBitFieldPtr16Uint32(pPk+56, libc.Uint32FromInt32(1), 3, 0x8)
	}
	v5 = (*TIndex)(unsafe.Pointer(pPk)).FnKeyCol
	(*TIndex)(unsafe.Pointer(pPk)).FnColumn = v5
	nPk = int32(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, int32((*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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
			goto _6
		}
		v8 = libc.Int32FromInt32(0)
		n = v8
		i = v8
		for {
			if !(i < nPk) {
				break
			}
			if !(_isDupColumn(tls, pIdx, int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), pPk, i) != 0) {
				n++
			}
			goto _7
		_7:
			;
			i++
		}
		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, db, pIdx, int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)+n) != 0 {
			return
		}
		i = 0
		j = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		for {
			if !(i < nPk) {
				break
			}
			if !(_isDupColumn(tls, pIdx, int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), pPk, i) != 0) {
				*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)) = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))
				*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*4)) = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*4))
				if *(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(i))) != 0 {
					/* See ticket https://www.sqlite.org/src/info/bba7b69f9849b5bf */
					libc.SetBitFieldPtr16Uint32(pIdx+56, libc.Uint32FromInt32(1), 10, 0x400)
				}
				j++
			}
			goto _9
		_9:
			;
			i++
		}
		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) && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
			nExtra++
		}
		goto _10
	_10:
		;
		i++
	}
	if _resizeIndexObject(tls, db, 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) && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
			*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2)) = int16(int16(i))
			*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
			j++
		}
		goto _11
	_11:
		;
		i++
	}
	_recomputeColumnsNotIndexed(tls, pPk)
}

// C documentation
//
//	/*
//	** Return true if pTab is a virtual table and zName is a shadow table name
//	** for that virtual table.
//	*/
func _sqlite3IsShadowTableOf(tls *libc.TLS, db uintptr, pTab uintptr, zName uintptr) (r int32) {
	var nName int32
	var pMod uintptr
	_, _ = nName, pMod /* Module for the virtual table */
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		return 0
	}
	nName = _sqlite3Strlen30(tls, (*TTable)(unsafe.Pointer(pTab)).FzName)
	if Xsqlite3_strnicmp(tls, zName, (*TTable)(unsafe.Pointer(pTab)).FzName, nName) != 0 {
		return 0
	}
	if int32(*(*int8)(unsafe.Pointer(zName + uintptr(nName)))) != int32('_') {
		return 0
	}
	pMod = _sqlite3HashFind(tls, db+404, *(*uintptr)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FazArg)))
	if pMod == uintptr(0) {
		return 0
	}
	if (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FiVersion < int32(3) {
		return 0
	}
	if (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxShadowName == uintptr(0) {
		return 0
	}
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxShadowName})))(tls, zName+uintptr(nName)+uintptr(1))
}

// C documentation
//
//	/*
//	** Table pTab is a virtual table.  If it the virtual table implementation
//	** exists and has an xShadowName method, then loop over all other ordinary
//	** tables within the same schema looking for shadow tables of pTab, and mark
//	** any shadow tables seen using the TF_Shadow flag.
//	*/
func _sqlite3MarkAllShadowTablesOf(tls *libc.TLS, db uintptr, pTab uintptr) {
	var k, pMod, pOther uintptr
	var nName int32
	_, _, _, _ = k, nName, pMod, pOther /* For looping through the symbol table */
	pMod = _sqlite3HashFind(tls, db+404, *(*uintptr)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FazArg)))
	if pMod == uintptr(0) {
		return
	}
	if (*TModule)(unsafe.Pointer(pMod)).FpModule == uintptr(0) {
		return
	}
	if (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FiVersion < int32(3) {
		return
	}
	if (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxShadowName == uintptr(0) {
		return
	}
	nName = _sqlite3Strlen30(tls, (*TTable)(unsafe.Pointer(pTab)).FzName)
	k = (*THash)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpSchema + 8)).Ffirst
	for {
		if !(k != 0) {
			break
		}
		pOther = (*THashElem)(unsafe.Pointer(k)).Fdata
		if !(int32((*TTable)(unsafe.Pointer(pOther)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
			goto _1
		}
		if (*TTable)(unsafe.Pointer(pOther)).FtabFlags&uint32(TF_Shadow) != 0 {
			goto _1
		}
		if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pOther)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, nName) == 0 && int32(*(*int8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pOther)).FzName + uintptr(nName)))) == int32('_') && (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxShadowName})))(tls, (*TTable)(unsafe.Pointer(pOther)).FzName+uintptr(nName)+uintptr(1)) != 0 {
			*(*Tu32)(unsafe.Pointer(pOther + 28)) |= uint32(TF_Shadow)
		}
		goto _1
	_1:
		;
		k = (*THashElem)(unsafe.Pointer(k)).Fnext
	}
}

// C documentation
//
//	/*
//	** Return true if zName is a shadow table name in the current database
//	** connection.
//	**
//	** zName is temporarily modified while this routine is running, but is
//	** restored to its original value prior to this routine returning.
//	*/
func _sqlite3ShadowTableName(tls *libc.TLS, db uintptr, zName uintptr) (r int32) {
	var pTab, zTail uintptr
	_, _ = pTab, zTail /* Table that zName is a shadow of */
	zTail = libc.Xstrrchr(tls, zName, int32('_'))
	if zTail == uintptr(0) {
		return 0
	}
	*(*int8)(unsafe.Pointer(zTail)) = 0
	pTab = _sqlite3FindTable(tls, db, zName, uintptr(0))
	*(*int8)(unsafe.Pointer(zTail)) = int8('_')
	if pTab == uintptr(0) {
		return 0
	}
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		return 0
	}
	return _sqlite3IsShadowTableOf(tls, db, pTab, zName)
}

// 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(96)
	defer tls.Free(96)
	var addrInsLoop, addrTop, iCsr, iDb, ii, ii1, n, nNG, regRec, regRowid, regYield, v10, v4, v6, v8 int32
	var colFlags Tu32
	var db, p, pCol, pDb, pEnd2, pIdx, pOld, pSchema, pSelTab, pX, v, zStmt, zType, zType2, v11, v13, v5, v7, v9 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, v10, v11, v12, v13, v4, v5, v6, v7, v8, v9 /* 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)(unsafe.Pointer(p + 28)) |= 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 || !(int32((*TTable)(unsafe.Pointer(p)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) && (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1672, 0)
			return
		}
		(*TTable)(unsafe.Pointer(p)).Ftnum = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum
		if (*TTable)(unsafe.Pointer(p)).Ftnum == uint32(1) {
			*(*Tu32)(unsafe.Pointer(p + 28)) |= 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)(unsafe.Pointer(p + 28)) |= uint32(TF_Strict)
		ii = 0
		for {
			if !(ii < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
				break
			}
			pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(ii)*12
			if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf0>>4)) == COLTYPE_CUSTOM {
				if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14574, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, _sqlite3ColumnType(tls, pCol, __ccgo_ts+1672)))
				} else {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14607, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
				}
				return
			} else {
				if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf0>>4)) == int32(COLTYPE_ANY) {
					(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_BLOB)
				}
			}
			if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 && int32((*TTable)(unsafe.Pointer(p)).FiPKey) != ii && int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf>>0)) == OE_None {
				libc.SetBitFieldPtr8Uint32(pCol+4, libc.Uint32FromInt32(OE_Abort), 0, 0xf)
				*(*Tu32)(unsafe.Pointer(p + 28)) |= uint32(TF_HasNotNull)
			}
			goto _1
		_1:
			;
			ii++
		}
	}
	/* 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+14634, 0)
			return
		}
		if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasPrimaryKey) == uint32(0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14684, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName))
			return
		}
		*(*Tu32)(unsafe.Pointer(p + 28)) |= uint32(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)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(ii1)*12))).FcolFlags)
			if colFlags&uint32(COLFLAG_GENERATED) != uint32(0) {
				pX = _sqlite3ColumnExpr(tls, p, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(ii1)*12)
				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)*12, _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0))
				}
			} else {
				nNG++
			}
			goto _2
		_2:
			;
			ii1++
		}
		if nNG == 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14716, 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 int32((*TTable)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM {
			/* A regular table */
			zType = __ccgo_ts + 10492
			zType2 = __ccgo_ts + 14760
		} else {
			/* A view */
			zType = __ccgo_ts + 12230
			zType2 = __ccgo_ts + 14766
		}
		/* 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->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 int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
				(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
				(*TParse)(unsafe.Pointer(pParse)).FnErr++
				return
			}
			v5 = pParse + 40
			v4 = *(*int32)(unsafe.Pointer(v5))
			*(*int32)(unsafe.Pointer(v5))++
			iCsr = v4
			v7 = pParse + 44
			*(*int32)(unsafe.Pointer(v7))++
			v6 = *(*int32)(unsafe.Pointer(v7))
			regYield = v6
			v9 = pParse + 44
			*(*int32)(unsafe.Pointer(v9))++
			v8 = *(*int32)(unsafe.Pointer(v9))
			regRec = v8
			v11 = pParse + 44
			*(*int32)(unsafe.Pointer(v11))++
			v10 = *(*int32)(unsafe.Pointer(v11))
			regRowid = v10
			_sqlite3MayAbort(tls, pParse)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenWrite), iCsr, (*TParse)(unsafe.Pointer(pParse)).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, int8(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)(unsafe.Pointer(bp))).FiSDParm)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*(*TSelectDest)(unsafe.Pointer(bp))).FiSdst, (*(*TSelectDest)(unsafe.Pointer(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 {
				v13 = pParse + 208
			} else {
				v13 = pEnd
			}
			pEnd2 = v13
			n = int32((*TToken)(unsafe.Pointer(pEnd2)).Fz) - int32((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz)
			if int32(*(*int8)(unsafe.Pointer((*TToken)(unsafe.Pointer(pEnd2)).Fz))) != int32(';') {
				n = int32(uint32(n) + (*TToken)(unsafe.Pointer(pEnd2)).Fn)
			}
			zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+14771, libc.VaList(bp+40, 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+14786, libc.VaList(bp+40, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, zType, (*TTable)(unsafe.Pointer(p)).FzName, (*TTable)(unsafe.Pointer(p)).FzName, (*TParse)(unsafe.Pointer(pParse)).FregRoot, zStmt, (*TParse)(unsafe.Pointer(pParse)).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) && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
			pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
			if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab == uintptr(0) {
				_sqlite3NestedParse(tls, pParse, __ccgo_ts+14884, libc.VaList(bp+40, (*TDb)(unsafe.Pointer(pDb)).FzDbSName))
			}
		}
		/* Reparse everything to update our internal data structures */
		_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+14926, libc.VaList(bp+40, (*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+14960, libc.VaList(bp+40, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, (*TTable)(unsafe.Pointer(p)).FzName)), -int32(6))
		}
	}
	/* 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)(unsafe.Pointer(db + 24)) |= 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+11014) == 0 {
			(*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FpSchema)).FpSeqTab = p
		}
	}
	if !(pSelect != 0) && int32((*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 + 44))).FaddColOffset = int32(13) + (int32((*TToken)(unsafe.Pointer(pCons)).Fz) - int32((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
	}
}

// C documentation
//
//	/*
//	** The parser calls this routine in order to create a new VIEW
//	*/
func _sqlite3CreateView(tls *libc.TLS, pParse uintptr, pBegin uintptr, pName1 uintptr, pName2 uintptr, pCNames uintptr, pSelect uintptr, isTemp int32, noErr int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, p, z uintptr
	var iDb, n int32
	var _ /* pName at bp+60 */ uintptr
	var _ /* sEnd at bp+0 */ TToken
	var _ /* sFix at bp+8 */ TDbFixer
	_, _, _, _, _ = db, iDb, n, p, z
	*(*uintptr)(unsafe.Pointer(bp + 60)) = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if int32((*TParse)(unsafe.Pointer(pParse)).FnVar) > 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14981, 0)
		goto create_view_fail
	}
	_sqlite3StartTable(tls, pParse, pName1, pName2, isTemp, int32(1), 0, noErr)
	p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if p == uintptr(0) || (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto create_view_fail
	}
	/* Legacy versions of SQLite allowed the use of the magic "rowid" column
	 ** on a view, even though views do not have rowids.  The following flag
	 ** setting fixes this problem.  But the fix can be disabled by compiling
	 ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
	 ** depend upon the old buggy behavior.  The ability can also be toggled
	 ** using sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW,...) */
	*(*Tu32)(unsafe.Pointer(p + 28)) |= uint32(TF_NoVisibleRowid) /* Never allow rowid in view */
	_sqlite3TwoPartName(tls, pParse, pName1, pName2, bp+60)
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(p)).FpSchema)
	_sqlite3FixInit(tls, bp+8, pParse, iDb, __ccgo_ts+12230, *(*uintptr)(unsafe.Pointer(bp + 60)))
	if _sqlite3FixSelect(tls, bp+8, pSelect) != 0 {
		goto create_view_fail
	}
	/* Make a copy of the entire SELECT statement that defines the view.
	 ** This will force all the Expr.token.z values to be dynamically
	 ** allocated rather than point to the input string - which means that
	 ** they will persist after the current sqlite3_exec() call returns.
	 */
	*(*Tu32)(unsafe.Pointer(pSelect + 4)) |= uint32(SF_View)
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		(*(*struct {
			FpSelect uintptr
		})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(p)).Fu))).FpSelect = pSelect
		pSelect = uintptr(0)
	} else {
		(*(*struct {
			FpSelect uintptr
		})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(p)).Fu))).FpSelect = _sqlite3SelectDup(tls, db, pSelect, int32(EXPRDUP_REDUCE))
	}
	(*TTable)(unsafe.Pointer(p)).FpCheck = _sqlite3ExprListDup(tls, db, pCNames, int32(EXPRDUP_REDUCE))
	(*TTable)(unsafe.Pointer(p)).FeTabType = uint8(TABTYP_VIEW)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto create_view_fail
	}
	/* Locate the end of the CREATE VIEW statement.  Make sEnd point to
	 ** the end.
	 */
	*(*TToken)(unsafe.Pointer(bp)) = (*TParse)(unsafe.Pointer(pParse)).FsLastToken
	if int32(*(*int8)(unsafe.Pointer((*(*TToken)(unsafe.Pointer(bp))).Fz))) != int32(';') {
		(*(*TToken)(unsafe.Pointer(bp))).Fz += uintptr((*(*TToken)(unsafe.Pointer(bp))).Fn)
	}
	(*(*TToken)(unsafe.Pointer(bp))).Fn = uint32(0)
	n = int32((*(*TToken)(unsafe.Pointer(bp))).Fz) - int32((*TToken)(unsafe.Pointer(pBegin)).Fz)
	z = (*TToken)(unsafe.Pointer(pBegin)).Fz
	for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(n-int32(1)))))])&int32(0x01) != 0 {
		n--
	}
	(*(*TToken)(unsafe.Pointer(bp))).Fz = z + uintptr(n-int32(1))
	(*(*TToken)(unsafe.Pointer(bp))).Fn = uint32(1)
	/* Use sqlite3EndTable() to add the view to the schema table */
	_sqlite3EndTable(tls, pParse, uintptr(0), bp, uint32(0), uintptr(0))
	goto create_view_fail
create_view_fail:
	;
	_sqlite3SelectDelete(tls, db, pSelect)
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameExprlistUnmap(tls, pParse, pCNames)
	}
	_sqlite3ExprListDelete(tls, db, pCNames)
	return
}

// C documentation
//
//	/*
//	** The Table structure pTable is really a VIEW.  Fill in the names of
//	** the columns of the view in the pTable structure.  Return the number
//	** of errors.  If an error is seen leave an error message in pParse->zErrMsg.
//	*/
func _viewGetColumnNames(tls *libc.TLS, pParse uintptr, pTable uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pSel, pSelTab, p2 uintptr
	var eParseMode Tu8
	var nErr, nSelect, nTab, rc, v1 int32
	var xAuth Tsqlite3_xauth
	_, _, _, _, _, _, _, _, _, _, _ = db, eParseMode, nErr, nSelect, nTab, pSel, pSelTab, rc, xAuth, v1, p2 /* Copy of the SELECT that implements the view */
	nErr = 0                                                                                                /* Number of errors encountered */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                                                              /* Saved xAuth pointer */
	if int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VTAB) {
		(*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock++
		rc = _sqlite3VtabCallConnect(tls, pParse, pTable)
		(*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock--
		return rc
	}
	/* A positive nCol means the columns names for this view are
	 ** already known.  This routine is not called unless either the
	 ** table is virtual or nCol is zero.
	 */
	/* A negative nCol is a special marker meaning that we are currently
	 ** trying to compute the column names.  If we enter this routine with
	 ** a negative nCol, it means two or more views form a loop, like this:
	 **
	 **     CREATE VIEW one AS SELECT * FROM two;
	 **     CREATE VIEW two AS SELECT * FROM one;
	 **
	 ** Actually, the error above is now caught prior to reaching this point.
	 ** But the following test is still important as it does come up
	 ** in the following:
	 **
	 **     CREATE TABLE main.ex1(a);
	 **     CREATE TEMP VIEW ex1 AS SELECT a FROM ex1;
	 **     SELECT * FROM temp.ex1;
	 */
	if int32((*TTable)(unsafe.Pointer(pTable)).FnCol) < 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15017, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTable)).FzName))
		return int32(1)
	}
	/* If we get this far, it means we need to compute the table names.
	 ** Note that the call to sqlite3ResultSetOfSelect() will expand any
	 ** "*" elements in the results set of the view and will assign cursors
	 ** to the elements of the FROM clause.  But we do not want these changes
	 ** to be permanent.  So the computation is done on a copy of the SELECT
	 ** statement that defines the view.
	 */
	pSel = _sqlite3SelectDup(tls, db, (*(*struct {
		FpSelect uintptr
	})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTable)).Fu))).FpSelect, 0)
	if pSel != 0 {
		eParseMode = (*TParse)(unsafe.Pointer(pParse)).FeParseMode
		nTab = (*TParse)(unsafe.Pointer(pParse)).FnTab
		nSelect = (*TParse)(unsafe.Pointer(pParse)).FnSelect
		(*TParse)(unsafe.Pointer(pParse)).FeParseMode = uint8(PARSE_MODE_NORMAL)
		_sqlite3SrcListAssignCursors(tls, pParse, (*TSelect)(unsafe.Pointer(pSel)).FpSrc)
		(*TTable)(unsafe.Pointer(pTable)).FnCol = int16(-int32(1))
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
		xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
		pSelTab = _sqlite3ResultSetOfSelect(tls, pParse, pSel, int8(SQLITE_AFF_NONE))
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
		(*TParse)(unsafe.Pointer(pParse)).FnTab = nTab
		(*TParse)(unsafe.Pointer(pParse)).FnSelect = nSelect
		if pSelTab == uintptr(0) {
			(*TTable)(unsafe.Pointer(pTable)).FnCol = 0
			nErr++
		} else {
			if (*TTable)(unsafe.Pointer(pTable)).FpCheck != 0 {
				/* CREATE VIEW name(arglist) AS ...
				 ** The names of the columns in the table are taken from
				 ** arglist which is stored in pTable->pCheck.  The pCheck field
				 ** normally holds CHECK constraints on an ordinary table, but for
				 ** a VIEW it holds the list of column names.
				 */
				_sqlite3ColumnsFromExprList(tls, pParse, (*TTable)(unsafe.Pointer(pTable)).FpCheck, pTable+34, pTable+4)
				if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 && int32((*TTable)(unsafe.Pointer(pTable)).FnCol) == (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpEList)).FnExpr {
					_sqlite3SubqueryColumnTypes(tls, pParse, pTable, pSel, int8(SQLITE_AFF_NONE))
				}
			} else {
				/* CREATE VIEW name AS...  without an argument list.  Construct
				 ** the column names from the SELECT statement that defines the view.
				 */
				(*TTable)(unsafe.Pointer(pTable)).FnCol = (*TTable)(unsafe.Pointer(pSelTab)).FnCol
				(*TTable)(unsafe.Pointer(pTable)).FaCol = (*TTable)(unsafe.Pointer(pSelTab)).FaCol
				*(*Tu32)(unsafe.Pointer(pTable + 28)) |= (*TTable)(unsafe.Pointer(pSelTab)).FtabFlags & uint32(COLFLAG_NOINSERT)
				(*TTable)(unsafe.Pointer(pSelTab)).FnCol = 0
				(*TTable)(unsafe.Pointer(pSelTab)).FaCol = uintptr(0)
			}
		}
		(*TTable)(unsafe.Pointer(pTable)).FnNVCol = (*TTable)(unsafe.Pointer(pTable)).FnCol
		_sqlite3DeleteTable(tls, db, pSelTab)
		_sqlite3SelectDelete(tls, db, pSel)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable--
		if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			v1 = 0
		} else {
			v1 = int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(v1)
		(*TParse)(unsafe.Pointer(pParse)).FeParseMode = eParseMode
	} else {
		nErr++
	}
	p2 = (*TTable)(unsafe.Pointer(pTable)).FpSchema + 78
	*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(DB_UnresetViews))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3DeleteColumnNames(tls, db, pTable)
	}
	return nErr
}

func _sqlite3ViewGetColumnNames(tls *libc.TLS, pParse uintptr, pTable uintptr) (r int32) {
	if !(int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && int32((*TTable)(unsafe.Pointer(pTable)).FnCol) > 0 {
		return 0
	}
	return _viewGetColumnNames(tls, pParse, pTable)
}

// C documentation
//
//	/*
//	** Clear the column names from every VIEW in database idx.
//	*/
func _sqliteViewResetAll(tls *libc.TLS, db uintptr, idx int32) {
	var i, pTab, p2 uintptr
	_, _, _ = i, pTab, p2
	if !(int32((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(idx)*16))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_UnresetViews) == libc.Int32FromInt32(DB_UnresetViews)) {
		return
	}
	i = (*THash)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(idx)*16))).FpSchema + 8)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(i)).Fdata
		if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			_sqlite3DeleteColumnNames(tls, db, pTab)
		}
		goto _1
	_1:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	p2 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(idx)*16))).FpSchema + 78
	*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) & ^libc.Int32FromInt32(DB_UnresetViews))
}

// C documentation
//
//	/*
//	** This function is called by the VDBE to adjust the internal schema
//	** used by SQLite when the btree layer moves a table root page. The
//	** root-page of a table or index in database iDb has changed from iFrom
//	** to iTo.
//	**
//	** Ticket #1728:  The symbol table might still contain information
//	** on tables and/or indices that are the process of being deleted.
//	** If you are unlucky, one of those deleted indices or tables might
//	** have the same rootpage number as the real table or index that is
//	** being moved.  So we cannot stop searching after the first match
//	** because the first match might be for one of the deleted indices
//	** or tables and not the table/index that is actually being moved.
//	** We must continue looping until all tables and indices with
//	** rootpage==iFrom have been converted to have a rootpage of iTo
//	** in order to be certain that we got the right one.
//	*/
func _sqlite3RootPageMoved(tls *libc.TLS, db uintptr, iDb int32, iFrom TPgno, iTo TPgno) {
	var pDb, pElem, pHash, pIdx, pTab uintptr
	_, _, _, _, _ = pDb, pElem, pHash, pIdx, pTab
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	pHash = (*TDb)(unsafe.Pointer(pDb)).FpSchema + 8
	pElem = (*THash)(unsafe.Pointer(pHash)).Ffirst
	for {
		if !(pElem != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(pElem)).Fdata
		if (*TTable)(unsafe.Pointer(pTab)).Ftnum == iFrom {
			(*TTable)(unsafe.Pointer(pTab)).Ftnum = iTo
		}
		goto _1
	_1:
		;
		pElem = (*THashElem)(unsafe.Pointer(pElem)).Fnext
	}
	pHash = (*TDb)(unsafe.Pointer(pDb)).FpSchema + 24
	pElem = (*THash)(unsafe.Pointer(pHash)).Ffirst
	for {
		if !(pElem != 0) {
			break
		}
		pIdx = (*THashElem)(unsafe.Pointer(pElem)).Fdata
		if (*TIndex)(unsafe.Pointer(pIdx)).Ftnum == iFrom {
			(*TIndex)(unsafe.Pointer(pIdx)).Ftnum = iTo
		}
		goto _2
	_2:
		;
		pElem = (*THashElem)(unsafe.Pointer(pElem)).Fnext
	}
}

// C documentation
//
//	/*
//	** Write code to erase the table with root-page iTable from database iDb.
//	** Also write code to modify the sqlite_schema table and internal schema
//	** if a root-page of another table is moved by the btree-layer whilst
//	** erasing iTable (this can happen with an auto-vacuum database).
//	*/
func _destroyRootPage(tls *libc.TLS, pParse uintptr, iTable int32, iDb int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var r1 int32
	var v uintptr
	_, _ = r1, v
	v = _sqlite3GetVdbe(tls, pParse)
	r1 = _sqlite3GetTempReg(tls, pParse)
	if iTable < int32(2) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15047, 0)
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Destroy), iTable, r1, iDb)
	_sqlite3MayAbort(tls, pParse)
	/* OP_Destroy stores an in integer r1. If this integer
	 ** is non-zero, then it is the root page number of a table moved to
	 ** location iTable. The following code modifies the sqlite_schema table to
	 ** reflect this.
	 **
	 ** The "#NNN" in the SQL is a special constant that means whatever value
	 ** is in register NNN.  See grammar rules associated with the TK_REGISTER
	 ** token for additional information.
	 */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+15062, libc.VaList(bp+8, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FzDbSName, iTable, r1, r1))
	_sqlite3ReleaseTempReg(tls, pParse, r1)
}

// C documentation
//
//	/*
//	** Write VDBE code to erase table pTab and all associated indices on disk.
//	** Code to update the sqlite_schema tables and internal schema definitions
//	** in case a root-page belonging to another table is moved by the btree layer
//	** is also added (this can happen with an auto-vacuum database).
//	*/
func _destroyTable(tls *libc.TLS, pParse uintptr, pTab uintptr) {
	var iDb int32
	var iDestroyed, iIdx, iLargest, iTab TPgno
	var pIdx uintptr
	_, _, _, _, _, _ = iDb, iDestroyed, iIdx, iLargest, iTab, pIdx
	/* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
	 ** is not defined), then it is important to call OP_Destroy on the
	 ** table and index root-pages in order, starting with the numerically
	 ** largest root-page number. This guarantees that none of the root-pages
	 ** to be destroyed is relocated by an earlier OP_Destroy. i.e. if the
	 ** following were coded:
	 **
	 ** OP_Destroy 4 0
	 ** ...
	 ** OP_Destroy 5 0
	 **
	 ** and root page 5 happened to be the largest root-page number in the
	 ** database, then root page 5 would be moved to page 4 by the
	 ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
	 ** a free-list page.
	 */
	iTab = (*TTable)(unsafe.Pointer(pTab)).Ftnum
	iDestroyed = uint32(0)
	for int32(1) != 0 {
		iLargest = uint32(0)
		if iDestroyed == uint32(0) || iTab < iDestroyed {
			iLargest = iTab
		}
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			iIdx = (*TIndex)(unsafe.Pointer(pIdx)).Ftnum
			if (iDestroyed == uint32(0) || iIdx < iDestroyed) && iIdx > iLargest {
				iLargest = iIdx
			}
			goto _1
		_1:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
		if iLargest == uint32(0) {
			return
		} else {
			iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
			_destroyRootPage(tls, pParse, int32(int32(iLargest)), iDb)
			iDestroyed = iLargest
		}
	}
}

// C documentation
//
//	/*
//	** Remove entries from the sqlite_statN tables (for N in (1,2,3))
//	** after a DROP INDEX or DROP TABLE command.
//	*/
func _sqlite3ClearStatTables(tls *libc.TLS, pParse uintptr, iDb int32, zType uintptr, zName uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var i int32
	var zDbName uintptr
	var _ /* zTab at bp+0 */ [24]int8
	_, _ = i, zDbName
	zDbName = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FzDbSName
	i = int32(1)
	for {
		if !(i <= int32(4)) {
			break
		}
		Xsqlite3_snprintf(tls, int32(24), bp, __ccgo_ts+15129, libc.VaList(bp+32, i))
		if _sqlite3FindTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, bp, zDbName) != 0 {
			_sqlite3NestedParse(tls, pParse, __ccgo_ts+13119, libc.VaList(bp+32, zDbName, bp, zType, zName))
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Generate code to drop a table.
//	*/
func _sqlite3CodeDropTable(tls *libc.TLS, pParse uintptr, pTab uintptr, iDb int32, isView int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pDb, pTrigger, v uintptr
	_, _, _, _ = db, pDb, pTrigger, v
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	v = _sqlite3GetVdbe(tls, pParse)
	_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3VdbeAddOp0(tls, v, int32(OP_VBegin))
	}
	/* Drop all triggers associated with the table being dropped. Code
	 ** is generated to remove entries from sqlite_schema and/or
	 ** sqlite_temp_schema if required.
	 */
	pTrigger = _sqlite3TriggerList(tls, pParse, pTab)
	for pTrigger != 0 {
		_sqlite3DropTriggerPtr(tls, pParse, pTrigger)
		pTrigger = (*TTrigger)(unsafe.Pointer(pTrigger)).FpNext
	}
	/* Remove any entries of the sqlite_sequence table associated with
	 ** the table being dropped. This is done before the table is dropped
	 ** at the btree level, in case the sqlite_sequence table needs to
	 ** move as a result of the drop (can happen in auto-vacuum mode).
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Autoincrement) != 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+15143, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName))
	}
	/* Drop all entries in the schema table that refer to the
	 ** table. The program name loops through the schema table and deletes
	 ** every row that refers to a table of the same name as the one being
	 ** dropped. Triggers are handled separately because a trigger can be
	 ** created in the temp database that refers to a table in another
	 ** database.
	 */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+15188, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName))
	if !(isView != 0) && !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		_destroyTable(tls, pParse, pTab)
	}
	/* Remove the table entry from SQLite's internal schema and modify
	 ** the schema cookie.
	 */
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3VdbeAddOp4(tls, v, int32(OP_VDestroy), iDb, 0, 0, (*TTable)(unsafe.Pointer(pTab)).FzName, 0)
		_sqlite3MayAbort(tls, pParse)
	}
	_sqlite3VdbeAddOp4(tls, v, int32(OP_DropTable), iDb, 0, 0, (*TTable)(unsafe.Pointer(pTab)).FzName, 0)
	_sqlite3ChangeCookie(tls, pParse, iDb)
	_sqliteViewResetAll(tls, db, iDb)
}

// C documentation
//
//	/*
//	** Return TRUE if shadow tables should be read-only in the current
//	** context.
//	*/
func _sqlite3ReadOnlyShadowTables(tls *libc.TLS, db uintptr) (r int32) {
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0) && (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec == 0 && !((*Tsqlite3)(unsafe.Pointer(db)).FnVTrans > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans == uintptr(0)) {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if it is not allowed to drop the given table
//	*/
func _tableMayNotBeDropped(tls *libc.TLS, db uintptr, pTab uintptr) (r int32) {
	if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+7898, int32(7)) == 0 {
		if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName+uintptr(7), __ccgo_ts+15255, int32(4)) == 0 {
			return 0
		}
		if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName+uintptr(7), __ccgo_ts+8700, int32(10)) == 0 {
			return 0
		}
		return int32(1)
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Shadow) != uint32(0) && _sqlite3ReadOnlyShadowTables(tls, db) != 0 {
		return int32(1)
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Eponymous) != 0 {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** This routine is called to do the work of a DROP TABLE statement.
//	** pName is the name of the table to be dropped.
//	*/
func _sqlite3DropTable(tls *libc.TLS, pParse uintptr, pName uintptr, isView int32, noErr int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var code, iDb int32
	var db, pTab, v, zArg2, zDb, zTab, v1 uintptr
	_, _, _, _, _, _, _, _, _ = code, db, iDb, pTab, v, zArg2, zDb, zTab, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_drop_table
	}
	if _sqlite3ReadSchema(tls, pParse) != 0 {
		goto exit_drop_table
	}
	if noErr != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr++
	}
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(uint32(isView)), pName+8)
	if noErr != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr--
	}
	if pTab == uintptr(0) {
		if noErr != 0 {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzDatabase)
			_sqlite3ForceNotReadOnly(tls, pParse)
		}
		goto exit_drop_table
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	/* If pTab is a virtual table, call ViewGetColumnNames() to ensure
	 ** it is initialized.
	 */
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto exit_drop_table
	}
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		v1 = __ccgo_ts + 7906
	} else {
		v1 = __ccgo_ts + 7439
	}
	zTab = v1
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	zArg2 = uintptr(0)
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
		goto exit_drop_table
	}
	if isView != 0 {
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			code = int32(SQLITE_DROP_TEMP_VIEW)
		} else {
			code = int32(SQLITE_DROP_VIEW)
		}
	} else {
		if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			code = int32(SQLITE_DROP_VTABLE)
			zArg2 = (*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, db, pTab))).FpMod)).FzName
		} else {
			if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
				code = int32(SQLITE_DROP_TEMP_TABLE)
			} else {
				code = int32(SQLITE_DROP_TABLE)
			}
		}
	}
	if _sqlite3AuthCheck(tls, pParse, code, (*TTable)(unsafe.Pointer(pTab)).FzName, zArg2, zDb) != 0 {
		goto exit_drop_table
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), zDb) != 0 {
		goto exit_drop_table
	}
	if _tableMayNotBeDropped(tls, db, pTab) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15260, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_drop_table
	}
	/* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
	 ** on a table.
	 */
	if isView != 0 && !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15288, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_drop_table
	}
	if !(isView != 0) && int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15322, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_drop_table
	}
	/* Generate code to remove the table from the schema table
	 ** on disk.
	 */
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
		if !(isView != 0) {
			_sqlite3ClearStatTables(tls, pParse, iDb, __ccgo_ts+13231, (*TTable)(unsafe.Pointer(pTab)).FzName)
			_sqlite3FkDropTable(tls, pParse, pName, pTab)
		}
		_sqlite3CodeDropTable(tls, pParse, pTab, iDb, isView)
	}
	goto exit_drop_table
exit_drop_table:
	;
	_sqlite3SrcListDelete(tls, db, pName)
}

// C documentation
//
//	/*
//	** This routine is called to create a new foreign key on the table
//	** currently under construction.  pFromCol determines which columns
//	** in the current table point to the foreign key.  If pFromCol==0 then
//	** connect the key to the last column inserted.  pTo is the name of
//	** the table referred to (a.k.a the "parent" table).  pToCol is a list
//	** of tables in the parent pTo table.  flags contains all
//	** information about the conflict resolution algorithms specified
//	** in the ON DELETE, ON UPDATE and ON INSERT clauses.
//	**
//	** An FKey structure is created and added to the table currently
//	** under construction in the pParse->pNewTable field.
//	**
//	** The foreign key is set for IMMEDIATE processing.  A subsequent call
//	** to sqlite3DeferForeignKey() might change this to DEFERRED.
//	*/
func _sqlite3CreateForeignKey(tls *libc.TLS, pParse uintptr, pFromCol uintptr, pTo uintptr, pToCol uintptr, flags int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pFKey, pNextTo, z uintptr
	var i, iCol, j, n, nCol int32
	var nByte Ti64
	_, _, _, _, _, _, _, _, _, _, _ = db, i, iCol, j, n, nByte, nCol, p, pFKey, pNextTo, z
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pFKey = uintptr(0)
	p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if p == uintptr(0) || int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) {
		goto fk_end
	}
	if pFromCol == uintptr(0) {
		iCol = int32((*TTable)(unsafe.Pointer(p)).FnCol) - int32(1)
		if iCol < 0 {
			goto fk_end
		}
		if pToCol != 0 && (*TExprList)(unsafe.Pointer(pToCol)).FnExpr != int32(1) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15354, libc.VaList(bp+8, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(iCol)*12))).FzCnName, pTo))
			goto fk_end
		}
		nCol = int32(1)
	} else {
		if pToCol != 0 && (*TExprList)(unsafe.Pointer(pToCol)).FnExpr != (*TExprList)(unsafe.Pointer(pFromCol)).FnExpr {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15417, 0)
			goto fk_end
		} else {
			nCol = (*TExprList)(unsafe.Pointer(pFromCol)).FnExpr
		}
	}
	nByte = int64(uint32(44) + uint32(nCol-libc.Int32FromInt32(1))*uint32(8) + (*TToken)(unsafe.Pointer(pTo)).Fn + uint32(1))
	if pToCol != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pToCol)).FnExpr) {
				break
			}
			nByte += int64(_sqlite3Strlen30(tls, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName) + int32(1))
			goto _1
		_1:
			;
			i++
		}
	}
	pFKey = _sqlite3DbMallocZero(tls, db, uint64(uint64(nByte)))
	if pFKey == uintptr(0) {
		goto fk_end
	}
	(*TFKey)(unsafe.Pointer(pFKey)).FpFrom = p
	(*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(p + 44))).FpFKey
	z = pFKey + 36 + uintptr(nCol)*8
	(*TFKey)(unsafe.Pointer(pFKey)).FzTo = z
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameTokenMap(tls, pParse, z, pTo)
	}
	libc.Xmemcpy(tls, z, (*TToken)(unsafe.Pointer(pTo)).Fz, (*TToken)(unsafe.Pointer(pTo)).Fn)
	*(*int8)(unsafe.Pointer(z + uintptr((*TToken)(unsafe.Pointer(pTo)).Fn))) = 0
	_sqlite3Dequote(tls, z)
	z += uintptr((*TToken)(unsafe.Pointer(pTo)).Fn + uint32(1))
	(*TFKey)(unsafe.Pointer(pFKey)).FnCol = nCol
	if pFromCol == uintptr(0) {
		(*(*TsColMap)(unsafe.Pointer(pFKey + 36))).FiFrom = int32((*TTable)(unsafe.Pointer(p)).FnCol) - int32(1)
	} else {
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			j = 0
			for {
				if !(j < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
					break
				}
				if _sqlite3StrICmp(tls, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(j)*12))).FzCnName, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*20))).FzEName) == 0 {
					(*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FiFrom = j
					break
				}
				goto _3
			_3:
				;
				j++
			}
			if j >= int32((*TTable)(unsafe.Pointer(p)).FnCol) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15511, libc.VaList(bp+8, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*20))).FzEName))
				goto fk_end
			}
			if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
				_sqlite3RenameTokenRemap(tls, pParse, pFKey+36+uintptr(i)*8, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*20))).FzEName)
			}
			goto _2
		_2:
			;
			i++
		}
	}
	if pToCol != 0 {
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			n = _sqlite3Strlen30(tls, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName)
			(*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FzCol = z
			if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
				_sqlite3RenameTokenRemap(tls, pParse, z, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName)
			}
			libc.Xmemcpy(tls, z, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName, uint32(uint32(n)))
			*(*int8)(unsafe.Pointer(z + uintptr(n))) = 0
			z += uintptr(n + int32(1))
			goto _4
		_4:
			;
			i++
		}
	}
	(*TFKey)(unsafe.Pointer(pFKey)).FisDeferred = uint8(0)
	*(*Tu8)(unsafe.Pointer(pFKey + 25)) = uint8(flags & libc.Int32FromInt32(0xff))                               /* ON DELETE action */
	*(*Tu8)(unsafe.Pointer(pFKey + 25 + 1)) = uint8(flags >> libc.Int32FromInt32(8) & libc.Int32FromInt32(0xff)) /* ON UPDATE action */
	pNextTo = _sqlite3HashInsert(tls, (*TTable)(unsafe.Pointer(p)).FpSchema+56, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, pFKey)
	if pNextTo == pFKey {
		_sqlite3OomFault(tls, db)
		goto fk_end
	}
	if pNextTo != 0 {
		(*TFKey)(unsafe.Pointer(pFKey)).FpNextTo = pNextTo
		(*TFKey)(unsafe.Pointer(pNextTo)).FpPrevTo = pFKey
	}
	/* Link the foreign key to the table as the last step.
	 */
	(*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(p + 44))).FpFKey = pFKey
	pFKey = uintptr(0)
	goto fk_end
fk_end:
	;
	_sqlite3DbFree(tls, db, pFKey)
	_sqlite3ExprListDelete(tls, db, pFromCol)
	_sqlite3ExprListDelete(tls, db, pToCol)
}

// C documentation
//
//	/*
//	** This routine is called when an INITIALLY IMMEDIATE or INITIALLY DEFERRED
//	** clause is seen as part of a foreign key definition.  The isDeferred
//	** parameter is 1 for INITIALLY DEFERRED and 0 for INITIALLY IMMEDIATE.
//	** The behavior of the most recently created foreign key is adjusted
//	** accordingly.
//	*/
func _sqlite3DeferForeignKey(tls *libc.TLS, pParse uintptr, isDeferred int32) {
	var pFKey, pTab, v1, v2 uintptr
	_, _, _, _ = pFKey, pTab, v1, v2
	v1 = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	pTab = v1
	if v1 == uintptr(0) {
		return
	}
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		return
	}
	v2 = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpFKey
	pFKey = v2
	if v2 == uintptr(0) {
		return
	}
	/* EV: R-30323-21917 */
	(*TFKey)(unsafe.Pointer(pFKey)).FisDeferred = uint8(uint8(isDeferred))
}

// 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, v5, v7 int32
	var db, pKey, pTab, v, v2, v4, v6 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, v5, v6, v7
	pTab = (*TIndex)(unsafe.Pointer(pIndex)).FpTable
	v2 = pParse + 40
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++ /* The table that is indexed */
	iTab = v1
	v4 = pParse + 40
	v3 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4))++            /* 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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 = uint32(uint32(memRootPage))
	} else {
		tnum = (*TIndex)(unsafe.Pointer(pIndex)).Ftnum
	}
	pKey = _sqlite3KeyInfoOfIndex(tls, pParse, pIndex)
	/* Open the sorter cursor if we are to use one. */
	v6 = pParse + 40
	v5 = *(*int32)(unsafe.Pointer(v6))
	*(*int32)(unsafe.Pointer(v6))++
	iSorter = v5
	_sqlite3VdbeAddOp4(tls, v, int32(OP_SorterOpen), iSorter, 0, int32((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol), _sqlite3KeyInfoRef(tls, pKey), -int32(8))
	/* 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)(unsafe.Pointer(bp)))
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iTab, addr1+int32(1))
	_sqlite3VdbeJumpHere(tls, v, addr1)
	if memRootPage < 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), int32(int32(tnum)), iDb)
	}
	_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenWrite), iIdx, int32(int32(tnum)), iDb, pKey, -int32(8))
	if memRootPage >= 0 {
		v7 = int32(OPFLAG_P2ISREG)
	} else {
		v7 = 0
	}
	_sqlite3VdbeChangeP5(tls, v, uint16(int32(OPFLAG_BULKCSR)|v7))
	addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_SorterSort), iSorter, 0)
	if int32((*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, int32((*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 + 56))&0x400>>10)) != 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://www.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
//
//	/*
//	** Allocate heap space to hold an Index object with nCol columns.
//	**
//	** Increase the allocation size to provide an extra nExtra bytes
//	** of 8-byte aligned space after the Index object and return a
//	** pointer to this extra space in *ppExtra.
//	*/
func _sqlite3AllocateIndexObject(tls *libc.TLS, db uintptr, nCol Ti16, nExtra int32, ppExtra uintptr) (r uintptr) {
	var nByte int32
	var p, pExtra uintptr
	_, _, _ = nByte, p, pExtra                                                                                                                                                                                                                                                                                                                              /* Bytes of space for Index object + arrays */
	nByte = int32((libc.Uint32FromInt64(104)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)) + (uint32(4)*uint32(uint32(nCol))+uint32(7))&uint32(^libc.Int32FromInt32(7)) + (uint32(2)*uint32(int32(int32(nCol))+libc.Int32FromInt32(1))+uint32(2)*uint32(uint32(nCol))+uint32(1)*uint32(uint32(nCol))+uint32(7))&uint32(^libc.Int32FromInt32(7))) /* Index.aSortOrder */
	p = _sqlite3DbMallocZero(tls, db, uint64(nByte+nExtra))
	if p != 0 {
		pExtra = p + uintptr((libc.Uint32FromInt64(104)+libc.Uint32FromInt32(7))&uint32(^libc.Int32FromInt32(7)))
		(*TIndex)(unsafe.Pointer(p)).FazColl = pExtra
		pExtra += uintptr((libc.Uint32FromInt64(4)*uint32(uint32(nCol)) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
		(*TIndex)(unsafe.Pointer(p)).FaiRowLogEst = pExtra
		pExtra += uintptr(uint32(2) * uint32(int32(int32(nCol))+libc.Int32FromInt32(1)))
		(*TIndex)(unsafe.Pointer(p)).FaiColumn = pExtra
		pExtra += uintptr(uint32(2) * uint32(uint32(nCol)))
		(*TIndex)(unsafe.Pointer(p)).FaSortOrder = pExtra
		(*TIndex)(unsafe.Pointer(p)).FnColumn = uint16(uint16(nCol))
		(*TIndex)(unsafe.Pointer(p)).FnKeyCol = uint16(int32(int32(nCol)) - int32(1))
		*(*uintptr)(unsafe.Pointer(ppExtra)) = p + uintptr(nByte)
	}
	return p
}

// 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)*20 + 8 + 4))&0x20>>5)) != 0 {
				sf = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).Ffg.FsortFlags
				if int32(int32(sf)) == 0 || int32(int32(sf)) == int32(3) {
					v2 = __ccgo_ts + 15557
				} else {
					v2 = __ccgo_ts + 15563
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15568, libc.VaList(bp+8, v2))
				return int32(1)
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return 0
}

// 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(128)
	defer tls.Free(128)
	var db, p, pCExpr, pCol, pDb, pExpr, pIdx, pIndex, pListItem, pLoop, pNext, pPk, pTab, pThis, ppFrom, v, z1, z2, zColl, zDb, zName, zStmt, v12, v13, v15, v16, v2, p3 uintptr
	var i, iDb, iMem, j, k, n, n1, nColl, nExtra, nExtraCol, nName, requestedSortOrder, sortOrderMask, x, v11, v5 int32
	var _ /* pName at bp+52 */ uintptr
	var _ /* prevCol at bp+64 */ TToken
	var _ /* sFix at bp+0 */ TDbFixer
	var _ /* zExtra at bp+56 */ 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, v11, v12, v13, v15, v16, v2, v5, p3
	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)(unsafe.Pointer(bp + 52)) = uintptr(0) /* For looping over pList */
	nExtra = 0                                        /* Number of extra columns needed */
	*(*uintptr)(unsafe.Pointer(bp + 56)) = 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 int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) && int32(int32(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+52)
		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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema {
				iDb = int32(1)
			}
		}
		_sqlite3FixInit(tls, bp, pParse, iDb, __ccgo_ts+15596, *(*uintptr)(unsafe.Pointer(bp + 52)))
		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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema != (*TTable)(unsafe.Pointer(pTab)).FpSchema {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15602, libc.VaList(bp+80, (*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)*16
	if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+7898, int32(7)) == 0 && int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && pTblName != uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15652, libc.VaList(bp+80, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_create_index
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15680, 0)
		goto exit_create_index
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15705, 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)(unsafe.Pointer(bp + 52)) != 0 {
		zName = _sqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp + 52)))
		if zName == uintptr(0) {
			goto exit_create_index
		}
		if SQLITE_OK != _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+15596, (*TTable)(unsafe.Pointer(pTab)).FzName) {
			goto exit_create_index
		}
		if !(int32((*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+15739, libc.VaList(bp+80, 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+15773, libc.VaList(bp+80, 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++
		}
		zName = _sqlite3MPrintf(tls, db, __ccgo_ts+15797, libc.VaList(bp+80, (*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 int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
			*(*int8)(unsafe.Pointer(zName + 7))++
		}
	}
	/* Check for authorization to create an index.
	 */
	if !(int32((*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 + 7906
		} else {
			v2 = __ccgo_ts + 7439
		}
		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))*12
		p3 = pCol + 10
		*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(COLFLAG_UNIQUE))
		_sqlite3TokenInit(tls, bp+64, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
		pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0))
		if pList == uintptr(0) {
			goto exit_create_index
		}
		_sqlite3ExprListSetSortOrder(tls, pList, sortOrder, -int32(1))
	} else {
		_sqlite3ExprListCheckLength(tls, pParse, pList, __ccgo_ts+15596)
		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)*20))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE) {
			nExtra += int32(1) + _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
		}
		goto _4
	_4:
		;
		i++
	}
	/*
	 ** Allocate the index structure.
	 */
	nName = _sqlite3Strlen30(tls, zName)
	if pPk != 0 {
		v5 = int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
	} else {
		v5 = int32(1)
	}
	nExtraCol = v5
	pIndex = _sqlite3AllocateIndexObject(tls, db, int16((*TExprList)(unsafe.Pointer(pList)).FnExpr+nExtraCol), nName+nExtra+int32(1), bp+56)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_create_index
	}
	(*TIndex)(unsafe.Pointer(pIndex)).FzName = *(*uintptr)(unsafe.Pointer(bp + 56))
	*(*uintptr)(unsafe.Pointer(bp + 56)) += uintptr(nName + int32(1))
	libc.Xmemcpy(tls, (*TIndex)(unsafe.Pointer(pIndex)).FzName, zName, uint32(nName+int32(1)))
	(*TIndex)(unsafe.Pointer(pIndex)).FpTable = pTab
	(*TIndex)(unsafe.Pointer(pIndex)).FonError = uint8(uint8(onError))
	libc.SetBitFieldPtr16Uint32(pIndex+56, libc.BoolUint32(onError != libc.Int32FromInt32(OE_None)), 3, 0x8)
	libc.SetBitFieldPtr16Uint32(pIndex+56, uint32(uint32(idxType)), 0, 0x3)
	(*TIndex)(unsafe.Pointer(pIndex)).FpSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	(*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol = uint16((*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 int32((*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 int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		(*TIndex)(unsafe.Pointer(pIndex)).FaColExpr = pList
		pList = uintptr(0)
	}
	i = 0
	for {
		if !(i < int32((*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 int32((*TExpr)(unsafe.Pointer(pCExpr)).Fop) != int32(TK_COLUMN) {
			if pTab == (*TParse)(unsafe.Pointer(pParse)).FpNewTable {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15820, 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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-libc.Int32FromInt32(2))
			libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 3, 0x8)
			libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 12, 0x1000)
		} 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)*12 + 4))&0xf>>0)) == 0 {
					libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 3, 0x8)
				}
				if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 11, 0x800)
					libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 12, 0x1000)
				}
			}
			*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(int16(j))
		}
		zColl = uintptr(0)
		if int32((*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)(unsafe.Pointer(bp + 56)), zColl, uint32(uint32(nColl)))
			zColl = *(*uintptr)(unsafe.Pointer(bp + 56))
			*(*uintptr)(unsafe.Pointer(bp + 56)) += uintptr(nColl)
			nExtra -= nColl
		} else {
			if j >= 0 {
				zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*12)
			}
		}
		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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*4)) = zColl
		requestedSortOrder = int32((*TExprList_item)(unsafe.Pointer(pListItem)).Ffg.FsortFlags) & sortOrderMask
		*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = uint8(uint8(requestedSortOrder))
		goto _6
	_6:
		;
		i++
		pListItem += 20
	}
	/* 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 < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
				break
			}
			x = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2)))
			if _isDupColumn(tls, pIndex, int32((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol), pPk, j) != 0 {
				(*TIndex)(unsafe.Pointer(pIndex)).FnColumn--
			} else {
				*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(int16(x))
				*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*4)) = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*4))
				*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = *(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(j)))
				i++
			}
			goto _7
		_7:
			;
			j++
		}
	} else {
		*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-libc.Int32FromInt32(1))
		*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*4)) = 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) && int32((*TIndex)(unsafe.Pointer(pIndex)).FnColumn) >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 5, 0x20)
		j = 0
		for {
			if !(j < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
				goto _8
			}
			if int32(_sqlite3TableColumnToIndex(tls, pIndex, int16(int16(j)))) >= 0 {
				goto _8
			}
			libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 5, 0x20)
			break
			goto _8
		_8:
			;
			j++
		}
	}
	if pTab == (*TParse)(unsafe.Pointer(pParse)).FpNewTable {
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) != int32((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol) {
				goto _9
			}
			k = 0
			for {
				if !(k < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(k)*2))) != int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(k)*2))) {
					break
				}
				z1 = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(k)*4))
				z2 = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(k)*4))
				if _sqlite3StrICmp(tls, z1, z2) != 0 {
					break
				}
				goto _10
			_10:
				;
				k++
			}
			if k == int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
				if int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) != int32((*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 !(int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Default) || int32((*TIndex)(unsafe.Pointer(pIndex)).FonError) == int32(OE_Default)) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15881, libc.VaList(bp+80, 0))
					}
					if int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Default) {
						(*TIndex)(unsafe.Pointer(pIdx)).FonError = (*TIndex)(unsafe.Pointer(pIndex)).FonError
					}
				}
				if int32(int32(idxType)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
					libc.SetBitFieldPtr16Uint32(pIdx+56, uint32(uint32(idxType)), 0, 0x3)
				}
				if int32((*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 !(int32((*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+15923, 0)
					(*TParse)(unsafe.Pointer(pParse)).Frc = _sqlite3CorruptError(tls, int32(125741))
					goto exit_create_index
				}
			}
			p = _sqlite3HashInsert(tls, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema+24, (*TIndex)(unsafe.Pointer(pIndex)).FzName, pIndex)
			if p != 0 {
				/* Malloc must have failed */
				_sqlite3OomFault(tls, db)
				goto exit_create_index
			}
			*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_SchemaChange)
		} else {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || pTblName != uintptr(0) {
				v12 = pParse + 44
				*(*int32)(unsafe.Pointer(v12))++
				v11 = *(*int32)(unsafe.Pointer(v12))
				iMem = v11
				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 = uint32(_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 = int32(uint32(int32((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int32((*TToken)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 52)))).Fz)) + (*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn)
					if int32(*(*int8)(unsafe.Pointer((*TToken)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 52)))).Fz + uintptr(n1-int32(1))))) == int32(';') {
						n1--
					}
					/* A named index with an explicit CREATE INDEX statement */
					if onError == OE_None {
						v13 = __ccgo_ts + 1672
					} else {
						v13 = __ccgo_ts + 15940
					}
					zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+15948, libc.VaList(bp+80, v13, n1, (*TToken)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 52)))).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+15968, libc.VaList(bp+80, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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+16027, libc.VaList(bp+80, (*TIndex)(unsafe.Pointer(pIndex)).FzName)), uint16(0))
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Expire), 0, int32(1))
				}
				_sqlite3VdbeJumpHere(tls, v, int32((*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 int32((*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 + 8
		for {
			v15 = *(*uintptr)(unsafe.Pointer(ppFrom))
			pThis = v15
			if !(v15 != uintptr(0)) {
				break
			}
			if int32((*TIndex)(unsafe.Pointer(pThis)).FonError) != int32(OE_Replace) {
				goto _14
			}
			for {
				v16 = (*TIndex)(unsafe.Pointer(pThis)).FpNext
				pNext = v16
				if !(v16 != uintptr(0) && int32((*TIndex)(unsafe.Pointer(pNext)).FonError) != int32(OE_Replace)) {
					break
				}
				*(*uintptr)(unsafe.Pointer(ppFrom)) = pNext
				(*TIndex)(unsafe.Pointer(pThis)).FpNext = (*TIndex)(unsafe.Pointer(pNext)).FpNext
				(*TIndex)(unsafe.Pointer(pNext)).FpNext = pThis
				ppFrom = pNext + 20
			}
			break
			goto _14
		_14:
			;
			ppFrom = pThis + 20
		}
	}
	_sqlite3ExprDelete(tls, db, pPIWhere)
	_sqlite3ExprListDelete(tls, db, pList)
	_sqlite3SrcListDelete(tls, db, pTblName)
	_sqlite3DbFree(tls, db, zName)
}

// C documentation
//
//	/*
//	** Fill the Index.aiRowEst[] array with default information - information
//	** to be used when we have not run the ANALYZE command.
//	**
//	** aiRowEst[0] is supposed to contain the number of elements in the index.
//	** Since we do not know, guess 1 million.  aiRowEst[1] is an estimate of the
//	** number of rows in the table that match any particular value of the
//	** first column of the index.  aiRowEst[2] is an estimate of the number
//	** of rows that match any particular combination of the first 2 columns
//	** of the index.  And so forth.  It must always be the case that
//	*
//	**           aiRowEst[N]<=aiRowEst[N-1]
//	**           aiRowEst[N]>=1
//	**
//	** Apart from that, we have little to go on besides intuition as to
//	** how aiRowEst[] should be initialized.  The numbers generated here
//	** are based on typical values found in actual indices.
//	*/
func _sqlite3DefaultRowEst(tls *libc.TLS, pIdx uintptr) {
	var a uintptr
	var i, nCopy, v1 int32
	var x, v2 TLogEst
	_, _, _, _, _, _ = a, i, nCopy, x, v1, v2
	a = (*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst
	if int32(libc.Uint32FromInt64(10)/libc.Uint32FromInt64(2)) < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
		v1 = int32(libc.Uint32FromInt64(10) / libc.Uint32FromInt64(2))
	} else {
		v1 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
	}
	nCopy = v1
	/* Indexes with default row estimates should not have stat1 data */
	/* Set the first entry (number of rows in the index) to the estimated
	 ** number of rows in the table, or half the number of rows in the table
	 ** for a partial index.
	 **
	 ** 2020-05-27:  If some of the stat data is coming from the sqlite_stat1
	 ** table but other parts we are having to guess at, then do not let the
	 ** estimated number of rows in the table be less than 1000 (LogEst 99).
	 ** Failure to do this can cause the indexes for which we do not have
	 ** stat1 data to be ignored by the query planner.
	 */
	x = (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FnRowLogEst
	if int32(int32(x)) < int32(99) {
		v2 = libc.Int16FromInt32(99)
		x = v2
		(*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FnRowLogEst = v2
	}
	if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) {
		x = TLogEst(int32(x) - libc.Int32FromInt32(10))
	}
	*(*TLogEst)(unsafe.Pointer(a)) = x
	/* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
	 ** 6 and each subsequent value (if any) is 5.  */
	libc.Xmemcpy(tls, a+1*2, uintptr(unsafe.Pointer(&_aVal)), uint32(uint32(nCopy))*uint32(2))
	i = nCopy + int32(1)
	for {
		if !(i <= int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
			break
		}
		*(*TLogEst)(unsafe.Pointer(a + uintptr(i)*2)) = int16(23)
		goto _3
	_3:
		;
		i++
	}
	if int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None {
		*(*TLogEst)(unsafe.Pointer(a + uintptr((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)*2)) = 0
	}
}

/*                10,  9,  8,  7,  6 */
var _aVal = [5]TLogEst{
	0: int16(33),
	1: int16(32),
	2: int16(30),
	3: int16(28),
	4: int16(26),
}

// 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, (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzDatabase)
	if pIndex == uintptr(0) {
		if !(ifExists != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16054, libc.VaList(bp+8, pName+8))
		} else {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzDatabase)
			_sqlite3ForceNotReadOnly(tls, pParse)
		}
		(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
		goto exit_drop_index
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 56))&0x3>>0)) != SQLITE_IDXTYPE_APPDEF {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16072, 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		v1 = __ccgo_ts + 7906
	} else {
		v1 = __ccgo_ts + 7439
	}
	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+16145, libc.VaList(bp+8, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, (*TIndex)(unsafe.Pointer(pIndex)).FzName))
		_sqlite3ClearStatTables(tls, pParse, iDb, __ccgo_ts+13227, (*TIndex)(unsafe.Pointer(pIndex)).FzName)
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_destroyRootPage(tls, pParse, int32((*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
//
//	/*
//	** pArray is a pointer to an array of objects. Each object in the
//	** array is szEntry bytes in size. This routine uses sqlite3DbRealloc()
//	** to extend the array so that there is space for a new object at the end.
//	**
//	** When this function is called, *pnEntry contains the current size of
//	** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes
//	** in total).
//	**
//	** If the realloc() is successful (i.e. if no OOM condition occurs), the
//	** space allocated for the new object is zeroed, *pnEntry updated to
//	** reflect the new size of the array and a pointer to the new allocation
//	** returned. *pIdx is set to the index of the new array entry in this case.
//	**
//	** Otherwise, if the realloc() fails, *pIdx is set to -1, *pnEntry remains
//	** unchanged and a copy of pArray returned.
//	*/
func _sqlite3ArrayAllocate(tls *libc.TLS, db uintptr, pArray uintptr, szEntry int32, pnEntry uintptr, pIdx uintptr) (r uintptr) {
	var n, sz Tsqlite3_int64
	var pNew, z uintptr
	var v1 int32
	var v2 int64
	_, _, _, _, _, _ = n, pNew, sz, z, v1, v2
	v1 = *(*int32)(unsafe.Pointer(pnEntry))
	*(*int32)(unsafe.Pointer(pIdx)) = v1
	n = int64(v1)
	if n&(n-int64(1)) == 0 {
		if n == 0 {
			v2 = int64(1)
		} else {
			v2 = int64(2) * n
		}
		sz = v2
		pNew = _sqlite3DbRealloc(tls, db, pArray, uint64(sz*int64(int64(szEntry))))
		if pNew == uintptr(0) {
			*(*int32)(unsafe.Pointer(pIdx)) = -int32(1)
			return pArray
		}
		pArray = pNew
	}
	z = pArray
	libc.Xmemset(tls, z+uintptr(n*int64(int64(szEntry))), 0, uint32(uint32(szEntry)))
	*(*int32)(unsafe.Pointer(pnEntry))++
	return pArray
}

// C documentation
//
//	/*
//	** Append a new element to the given IdList.  Create a new IdList if
//	** need be.
//	**
//	** A new IdList is returned, or NULL if malloc() fails.
//	*/
func _sqlite3IdListAppend(tls *libc.TLS, pParse uintptr, pList uintptr, pToken uintptr) (r uintptr) {
	var db, pNew, v2 uintptr
	var i, v1 int32
	_, _, _, _, _ = db, i, pNew, v1, v2
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pList == uintptr(0) {
		pList = _sqlite3DbMallocZero(tls, db, uint64(16))
		if pList == uintptr(0) {
			return uintptr(0)
		}
	} else {
		pNew = _sqlite3DbRealloc(tls, db, pList, uint64(uint32(16)+uint32((*TIdList)(unsafe.Pointer(pList)).FnId)*uint32(8)))
		if pNew == uintptr(0) {
			_sqlite3IdListDelete(tls, db, pList)
			return uintptr(0)
		}
		pList = pNew
	}
	v2 = pList
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	i = v1
	(*(*TIdList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*8))).FzName = _sqlite3NameFromToken(tls, db, pToken)
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*(*TIdList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*8))).FzName != 0 {
		_sqlite3RenameTokenMap(tls, pParse, (*(*TIdList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*8))).FzName, pToken)
	}
	return pList
}

// C documentation
//
//	/*
//	** Delete an IdList.
//	*/
func _sqlite3IdListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	var i int32
	_ = i
	if pList == uintptr(0) {
		return
	}
	/* EU4_EXPR mode is not currently used */
	i = 0
	for {
		if !(i < (*TIdList)(unsafe.Pointer(pList)).FnId) {
			break
		}
		_sqlite3DbFree(tls, db, (*(*TIdList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*8))).FzName)
		goto _1
	_1:
		;
		i++
	}
	_sqlite3DbNNFreeNN(tls, db, pList)
}

// C documentation
//
//	/*
//	** Return the index in pList of the identifier named zId.  Return -1
//	** if not found.
//	*/
func _sqlite3IdListIndex(tls *libc.TLS, pList uintptr, zName uintptr) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TIdList)(unsafe.Pointer(pList)).FnId) {
			break
		}
		if _sqlite3StrICmp(tls, (*(*TIdList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*8))).FzName, zName) == 0 {
			return i
		}
		goto _1
	_1:
		;
		i++
	}
	return -int32(1)
}

/*
** Maximum size of a SrcList object.
** The SrcList object is used to represent the FROM clause of a
** SELECT statement, and the query planner cannot deal with more
** than 64 tables in a join.  So any value larger than 64 here
** is sufficient for most uses.  Smaller values, like say 10, are
** appropriate for small and memory-limited applications.
 */

// C documentation
//
//	/*
//	** Expand the space allocated for the given SrcList object by
//	** creating nExtra new slots beginning at iStart.  iStart is zero based.
//	** New slots are zeroed.
//	**
//	** For example, suppose a SrcList initially contains two entries: A,B.
//	** To append 3 new entries onto the end, do this:
//	**
//	**    sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
//	**
//	** After the call above it would contain:  A, B, nil, nil, nil.
//	** If the iStart argument had been 1 instead of 2, then the result
//	** would have been:  A, nil, nil, nil, B.  To prepend the new slots,
//	** the iStart value would be 0.  The result then would
//	** be: nil, nil, nil, A, B.
//	**
//	** If a memory allocation fails or the SrcList becomes too large, leave
//	** the original SrcList unchanged, return NULL, and leave an error message
//	** in pParse.
//	*/
func _sqlite3SrcListEnlarge(tls *libc.TLS, pParse uintptr, pSrc uintptr, nExtra int32, iStart int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pNew uintptr
	var i int32
	var nAlloc Tsqlite3_int64
	_, _, _, _ = db, i, nAlloc, pNew
	/* Sanity checking on calling parameters */
	/* Allocate additional space if needed */
	if uint32((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc)+uint32(uint32(nExtra)) > (*TSrcList)(unsafe.Pointer(pSrc)).FnAlloc {
		nAlloc = int64(2)*int64((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) + int64(int64(nExtra))
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc+nExtra >= int32(SQLITE_MAX_SRCLIST) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16205, libc.VaList(bp+8, int32(SQLITE_MAX_SRCLIST)))
			return uintptr(0)
		}
		if nAlloc > int64(SQLITE_MAX_SRCLIST) {
			nAlloc = int64(SQLITE_MAX_SRCLIST)
		}
		pNew = _sqlite3DbRealloc(tls, db, pSrc, uint64(int64(80)+(nAlloc-int64(1))*int64(72)))
		if pNew == uintptr(0) {
			return uintptr(0)
		}
		pSrc = pNew
		(*TSrcList)(unsafe.Pointer(pSrc)).FnAlloc = uint32(uint32(nAlloc))
	}
	/* Move existing slots that come after the newly inserted slots
	 ** out of the way */
	i = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc - int32(1)
	for {
		if !(i >= iStart) {
			break
		}
		*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i+nExtra)*72)) = *(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))
		goto _1
	_1:
		;
		i--
	}
	*(*int32)(unsafe.Pointer(pSrc)) += nExtra
	/* Zero the newly allocated slots */
	libc.Xmemset(tls, pSrc+8+uintptr(iStart)*72, 0, uint32(72)*uint32(uint32(nExtra)))
	i = iStart
	for {
		if !(i < iStart+nExtra) {
			break
		}
		(*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FiCursor = -int32(1)
		goto _2
	_2:
		;
		i++
	}
	/* Return a pointer to the enlarged SrcList */
	return pSrc
}

// C documentation
//
//	/*
//	** Append a new table name to the given SrcList.  Create a new SrcList if
//	** need be.  A new entry is created in the SrcList even if pTable is NULL.
//	**
//	** A SrcList is returned, or NULL if there is an OOM error or if the
//	** SrcList grows to large.  The returned
//	** SrcList might be the same as the SrcList that was input or it might be
//	** a new one.  If an OOM error does occurs, then the prior value of pList
//	** that is input to this routine is automatically freed.
//	**
//	** If pDatabase is not null, it means that the table has an optional
//	** database name prefix.  Like this:  "database.table".  The pDatabase
//	** points to the table name and the pTable points to the database name.
//	** The SrcList.a[].zName field is filled with the table name which might
//	** come from pTable (if pDatabase is NULL) or from pDatabase.
//	** SrcList.a[].zDatabase is filled with the database name from pTable,
//	** or with NULL if no database is specified.
//	**
//	** In other words, if call like this:
//	**
//	**         sqlite3SrcListAppend(D,A,B,0);
//	**
//	** Then B is a table name and the database name is unspecified.  If called
//	** like this:
//	**
//	**         sqlite3SrcListAppend(D,A,B,C);
//	**
//	** Then C is the table name and B is the database name.  If C is defined
//	** then so is B.  In other words, we never have a case where:
//	**
//	**         sqlite3SrcListAppend(D,A,0,C);
//	**
//	** Both pTable and pDatabase are assumed to be quoted.  They are dequoted
//	** before being added to the SrcList.
//	*/
func _sqlite3SrcListAppend(tls *libc.TLS, pParse uintptr, pList uintptr, pTable uintptr, pDatabase uintptr) (r uintptr) {
	var db, pItem, pNew uintptr
	_, _, _ = db, pItem, pNew
	/* Cannot have C without B */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pList == uintptr(0) {
		pList = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(80))
		if pList == uintptr(0) {
			return uintptr(0)
		}
		(*TSrcList)(unsafe.Pointer(pList)).FnAlloc = uint32(1)
		(*TSrcList)(unsafe.Pointer(pList)).FnSrc = int32(1)
		libc.Xmemset(tls, pList+8, 0, uint32(72))
		(*(*TSrcItem)(unsafe.Pointer(pList + 8))).FiCursor = -int32(1)
	} else {
		pNew = _sqlite3SrcListEnlarge(tls, pParse, pList, int32(1), (*TSrcList)(unsafe.Pointer(pList)).FnSrc)
		if pNew == uintptr(0) {
			_sqlite3SrcListDelete(tls, db, pList)
			return uintptr(0)
		} else {
			pList = pNew
		}
	}
	pItem = pList + 8 + uintptr((*TSrcList)(unsafe.Pointer(pList)).FnSrc-int32(1))*72
	if pDatabase != 0 && (*TToken)(unsafe.Pointer(pDatabase)).Fz == uintptr(0) {
		pDatabase = uintptr(0)
	}
	if pDatabase != 0 {
		(*TSrcItem)(unsafe.Pointer(pItem)).FzName = _sqlite3NameFromToken(tls, db, pDatabase)
		(*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase = _sqlite3NameFromToken(tls, db, pTable)
	} else {
		(*TSrcItem)(unsafe.Pointer(pItem)).FzName = _sqlite3NameFromToken(tls, db, pTable)
		(*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase = uintptr(0)
	}
	return pList
}

// 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 + 40
			v2 = *(*int32)(unsafe.Pointer(v3))
			*(*int32)(unsafe.Pointer(v3))++
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = v2
			if (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 {
				_sqlite3SrcListAssignCursors(tls, pParse, (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpSrc)
			}
			goto _1
		_1:
			;
			i++
			pItem += 72
		}
	}
}

// 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
		}
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase)
		}
		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(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x2>>1)) != 0 {
			_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 64)))
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x4>>2)) != 0 {
			_sqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 64)))
		}
		_sqlite3DeleteTable(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FpTab)
		if (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 {
			_sqlite3SelectDelete(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x400>>10)) != 0 {
			_sqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 48)))
		} else {
			if *(*uintptr)(unsafe.Pointer(pItem + 48)) != 0 {
				_sqlite3ExprDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 48)))
			}
		}
		goto _1
	_1:
		;
		i++
		pItem += 72
	}
	_sqlite3DbNNFreeNN(tls, db, pList)
}

// 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, v2 uintptr
	_, _, _, _, _ = db, pItem, pToken, v1, v2
	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 + 16241
		} else {
			v1 = __ccgo_ts + 16244
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16250, 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))*72
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
		if pDatabase != 0 && (*TToken)(unsafe.Pointer(pDatabase)).Fz != 0 {
			v2 = pDatabase
		} else {
			v2 = pTable
		}
		pToken = v2
		_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 {
		(*TSrcItem)(unsafe.Pointer(pItem)).FpSelect = pSubquery
		if (*TSelect)(unsafe.Pointer(pSubquery)).FselFlags&uint32(SF_NestedFrom) != 0 {
			libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 13, 0x2000)
		}
	}
	if pOnUsing == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pItem + 48)) = uintptr(0)
	} else {
		if (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing != 0 {
			libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 10, 0x400)
			*(*uintptr)(unsafe.Pointer(pItem + 48)) = (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing
		} else {
			*(*uintptr)(unsafe.Pointer(pItem + 48)) = (*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
//
//	/*
//	** 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))*72
		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.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 0, 0x1)
		} else {
			*(*uintptr)(unsafe.Pointer(pItem + 64)) = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pIndexedBy)
			libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 1, 0x2)
			/* No collision on union u2 */
		}
	}
}

// C documentation
//
//	/*
//	** Append the contents of SrcList p2 to SrcList p1 and return the resulting
//	** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
//	** are deleted by this function.
//	*/
func _sqlite3SrcListAppendList(tls *libc.TLS, pParse uintptr, p1 uintptr, p2 uintptr) (r uintptr) {
	var pNew, p11 uintptr
	_, _ = pNew, p11
	if p2 != 0 {
		pNew = _sqlite3SrcListEnlarge(tls, pParse, p1, (*TSrcList)(unsafe.Pointer(p2)).FnSrc, int32(1))
		if pNew == uintptr(0) {
			_sqlite3SrcListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, p2)
		} else {
			p1 = pNew
			libc.Xmemcpy(tls, p1+8+1*72, p2+8, uint32((*TSrcList)(unsafe.Pointer(p2)).FnSrc)*uint32(72))
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, p2)
			p11 = p1 + 8 + 36
			*(*Tu8)(unsafe.Pointer(p11)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p11))) | libc.Int32FromInt32(JT_LTORJ)&int32((*(*TSrcItem)(unsafe.Pointer(p1 + 8 + 1*72))).Ffg.Fjointype))
		}
	}
	return p1
}

// 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))*72
		*(*uintptr)(unsafe.Pointer(pItem + 64)) = pList
		libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 2, 0x4)
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
	}
}

// C documentation
//
//	/*
//	** When building up a FROM clause in the parser, the join operator
//	** is initially attached to the left operand.  But the code generator
//	** expects the join operator to be on the right operand.  This routine
//	** Shifts all join operators from left to right for an entire FROM
//	** clause.
//	**
//	** Example: Suppose the join is like this:
//	**
//	**           A natural cross join B
//	**
//	** The operator is "natural cross join".  The A and B operands are stored
//	** in p->a[0] and p->a[1], respectively.  The parser initially stores the
//	** operator with A.  This routine shifts that operator over to B.
//	**
//	** Additional changes:
//	**
//	**   *   All tables to the left of the right-most RIGHT JOIN are tagged with
//	**       JT_LTORJ (mnemonic: Left Table Of Right Join) so that the
//	**       code generator can easily tell that the table is part of
//	**       the left operand of at least one RIGHT JOIN.
//	*/
func _sqlite3SrcListShiftJoinType(tls *libc.TLS, pParse uintptr, p uintptr) {
	var allFlags, v3 Tu8
	var i, v1, v5 int32
	var p7 uintptr
	_, _, _, _, _, _ = allFlags, i, v1, v3, v5, p7
	_ = pParse
	if p != 0 && (*TSrcList)(unsafe.Pointer(p)).FnSrc > int32(1) {
		i = (*TSrcList)(unsafe.Pointer(p)).FnSrc - int32(1)
		allFlags = uint8(0)
		for {
			v3 = (*(*TSrcItem)(unsafe.Pointer(p + 8 + uintptr(i-int32(1))*72))).Ffg.Fjointype
			(*(*TSrcItem)(unsafe.Pointer(p + 8 + uintptr(i)*72))).Ffg.Fjointype = v3
			allFlags = Tu8(int32(allFlags) | int32(v3))
			goto _2
		_2:
			;
			i--
			v1 = i
			if !(v1 > 0) {
				break
			}
		}
		(*(*TSrcItem)(unsafe.Pointer(p + 8))).Ffg.Fjointype = uint8(0)
		/* All terms to the left of a RIGHT JOIN should be tagged with the
		 ** JT_LTORJ flags */
		if int32(int32(allFlags))&int32(JT_RIGHT) != 0 {
			i = (*TSrcList)(unsafe.Pointer(p)).FnSrc - int32(1)
			for {
				if !(i > 0 && int32((*(*TSrcItem)(unsafe.Pointer(p + 8 + uintptr(i)*72))).Ffg.Fjointype)&int32(JT_RIGHT) == 0) {
					break
				}
				goto _4
			_4:
				;
				i--
			}
			i--
			for {
				p7 = p + 8 + uintptr(i)*72 + 36
				*(*Tu8)(unsafe.Pointer(p7)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p7))) | libc.Int32FromInt32(JT_LTORJ))
				goto _6
			_6:
				;
				i--
				v5 = i
				if !(v5 >= 0) {
					break
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Generate VDBE code for a BEGIN statement.
//	*/
func _sqlite3BeginTransaction(tls *libc.TLS, pParse uintptr, type1 int32) {
	var db, pBt, v uintptr
	var eTxnType, i int32
	_, _, _, _, _ = db, eTxnType, i, pBt, v
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_TRANSACTION), __ccgo_ts+16286, uintptr(0), uintptr(0)) != 0 {
		return
	}
	v = _sqlite3GetVdbe(tls, pParse)
	if !(v != 0) {
		return
	}
	if type1 != int32(TK_DEFERRED) {
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if pBt != 0 && _sqlite3BtreeIsReadonly(tls, pBt) != 0 {
				eTxnType = 0 /* Read txn */
			} else {
				if type1 == int32(TK_EXCLUSIVE) {
					eTxnType = int32(2) /* Exclusive txn */
				} else {
					eTxnType = int32(1) /* Write txn */
				}
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Transaction), i, eTxnType)
			_sqlite3VdbeUsesBtree(tls, v, i)
			goto _1
		_1:
			;
			i++
		}
	}
	_sqlite3VdbeAddOp0(tls, v, int32(OP_AutoCommit))
}

// C documentation
//
//	/*
//	** Generate VDBE code for a COMMIT or ROLLBACK statement.
//	** Code for ROLLBACK is generated if eType==TK_ROLLBACK.  Otherwise
//	** code is generated for a COMMIT.
//	*/
func _sqlite3EndTransaction(tls *libc.TLS, pParse uintptr, eType int32) {
	var isRollback int32
	var v, v1 uintptr
	_, _, _ = isRollback, v, v1
	isRollback = libc.BoolInt32(eType == int32(TK_ROLLBACK))
	if isRollback != 0 {
		v1 = __ccgo_ts + 16292
	} else {
		v1 = __ccgo_ts + 16301
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_TRANSACTION), v1, uintptr(0), uintptr(0)) != 0 {
		return
	}
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AutoCommit), int32(1), isRollback)
	}
}

// C documentation
//
//	/*
//	** This function is called by the parser when it parses a command to create,
//	** release or rollback an SQL savepoint.
//	*/
func _sqlite3Savepoint(tls *libc.TLS, pParse uintptr, op int32, pName uintptr) {
	var v, zName uintptr
	_, _ = v, zName
	zName = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName)
	if zName != 0 {
		v = _sqlite3GetVdbe(tls, pParse)
		if !(v != 0) || _sqlite3AuthCheck(tls, pParse, int32(SQLITE_SAVEPOINT), _az[op], zName, uintptr(0)) != 0 {
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zName)
			return
		}
		_sqlite3VdbeAddOp4(tls, v, OP_Savepoint, op, 0, 0, zName, -int32(6))
	}
}

var _az = [3]uintptr{
	0: __ccgo_ts + 16286,
	1: __ccgo_ts + 16308,
	2: __ccgo_ts + 16292,
}

// C documentation
//
//	/*
//	** Make sure the TEMP database is open and available for use.  Return
//	** the number of errors.  Leave any error messages in the pParse structure.
//	*/
func _sqlite3OpenTempDatabase(tls *libc.TLS, pParse uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	var rc int32
	var _ /* pBt at bp+0 */ uintptr
	_, _ = db, rc
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpBt == uintptr(0) && !((*TParse)(unsafe.Pointer(pParse)).Fexplain != 0) {
		rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), db, bp, 0, _flags)
		if rc != SQLITE_OK {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16316, 0)
			(*TParse)(unsafe.Pointer(pParse)).Frc = rc
			return int32(1)
		}
		(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpBt = *(*uintptr)(unsafe.Pointer(bp))
		if int32(SQLITE_NOMEM) == _sqlite3BtreeSetPageSize(tls, *(*uintptr)(unsafe.Pointer(bp)), (*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize, 0, 0) {
			_sqlite3OomFault(tls, db)
			return int32(1)
		}
	}
	return 0
}

var _flags = libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_DB)

// C documentation
//
//	/*
//	** Record the fact that the schema cookie will need to be verified
//	** for database iDb.  The code to actually verify the schema cookie
//	** will occur at the end of the top-level VDBE and will be generated
//	** later, by sqlite3FinishCoding().
//	*/
func _sqlite3CodeVerifySchemaAtToplevel(tls *libc.TLS, pToplevel uintptr, iDb int32) {
	if libc.BoolInt32((*TParse)(unsafe.Pointer(pToplevel)).FcookieMask&(libc.Uint32FromInt32(1)<<iDb) != uint32(0)) == 0 {
		*(*TyDbMask)(unsafe.Pointer(pToplevel + 92)) |= libc.Uint32FromInt32(1) << iDb
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			_sqlite3OpenTempDatabase(tls, pToplevel)
		}
	}
}

func _sqlite3CodeVerifySchema(tls *libc.TLS, pParse uintptr, iDb int32) {
	var v1 uintptr
	_ = v1
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	_sqlite3CodeVerifySchemaAtToplevel(tls, v1, iDb)
}

// C documentation
//
//	/*
//	** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
//	** attached database. Otherwise, invoke it for the database named zDb only.
//	*/
func _sqlite3CodeVerifyNamedSchema(tls *libc.TLS, pParse uintptr, zDb uintptr) {
	var db, pDb uintptr
	var i int32
	_, _, _ = db, i, pDb
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16
		if (*TDb)(unsafe.Pointer(pDb)).FpBt != 0 && (!(zDb != 0) || 0 == _sqlite3StrICmp(tls, zDb, (*TDb)(unsafe.Pointer(pDb)).FzDbSName)) {
			_sqlite3CodeVerifySchema(tls, pParse, i)
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Generate VDBE code that prepares for doing an operation that
//	** might change the database.
//	**
//	** This routine starts a new transaction if we are not already within
//	** a transaction.  If we are already within a transaction, then a checkpoint
//	** is set if the setStatement parameter is true.  A checkpoint should
//	** be set for operations that might fail (due to a constraint) part of
//	** the way through and which will need to undo some writes without having to
//	** rollback the whole transaction.  For operations where all constraints
//	** can be checked before any changes are made to the database, it is never
//	** necessary to undo a write and the checkpoint should not be set.
//	*/
func _sqlite3BeginWriteOperation(tls *libc.TLS, pParse uintptr, setStatement int32, iDb int32) {
	var pToplevel, v1, p2 uintptr
	_, _, _ = pToplevel, v1, p2
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pToplevel = v1
	_sqlite3CodeVerifySchemaAtToplevel(tls, pToplevel, iDb)
	*(*TyDbMask)(unsafe.Pointer(pToplevel + 88)) |= libc.Uint32FromInt32(1) << iDb
	p2 = pToplevel + 20
	*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | setStatement)
}

// C documentation
//
//	/*
//	** Indicate that the statement currently under construction might write
//	** more than one entry (example: deleting one row then inserting another,
//	** inserting multiple rows in a table, or inserting a row and index entries.)
//	** If an abort occurs after some of these writes have completed, then it will
//	** be necessary to undo the completed writes.
//	*/
func _sqlite3MultiWrite(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
	(*TParse)(unsafe.Pointer(pToplevel)).FisMultiWrite = uint8(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
	(*TParse)(unsafe.Pointer(pToplevel)).FmayAbort = uint8(1)
}

// C documentation
//
//	/*
//	** Code an OP_Halt that causes the vdbe to return an SQLITE_CONSTRAINT
//	** error. The onError parameter determines which (if any) of the statement
//	** and/or current transaction is rolled back.
//	*/
func _sqlite3HaltConstraint(tls *libc.TLS, pParse uintptr, errCode int32, onError int32, p4 uintptr, p4type Ti8, p5Errmsg Tu8) {
	var v uintptr
	_ = v
	v = _sqlite3GetVdbe(tls, pParse)
	if onError == int32(OE_Abort) {
		_sqlite3MayAbort(tls, pParse)
	}
	_sqlite3VdbeAddOp4(tls, v, int32(OP_Halt), errCode, onError, 0, p4, int32(int32(p4type)))
	_sqlite3VdbeChangeP5(tls, v, uint16(uint16(p5Errmsg)))
}

// 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)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb + 120)))
	if (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr != 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+16386, libc.VaList(bp+32, (*TIndex)(unsafe.Pointer(pIdx)).FzName))
	} else {
		j = 0
		for {
			if !(j < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
				break
			}
			zCol = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))*12))).FzCnName
			if j != 0 {
				Xsqlite3_str_append(tls, bp, __ccgo_ts+16397, int32(2))
			}
			Xsqlite3_str_appendall(tls, bp, (*TTable)(unsafe.Pointer(pTab)).FzName)
			Xsqlite3_str_append(tls, bp, __ccgo_ts+1685, int32(1))
			Xsqlite3_str_appendall(tls, bp, zCol)
			goto _1
		_1:
			;
			j++
		}
	}
	zErr = _sqlite3StrAccumFinish(tls, bp)
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x3>>0)) == 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(6)), uint8(P5_ConstraintUnique))
}

// C documentation
//
//	/*
//	** Code an OP_Halt due to non-unique rowid.
//	*/
func _sqlite3RowidConstraint(tls *libc.TLS, pParse uintptr, onError int32, pTab uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zMsg uintptr
	_, _ = rc, zMsg
	if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
		zMsg = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+13815, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*12))).FzCnName))
		rc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(6)<<libc.Int32FromInt32(8)
	} else {
		zMsg = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+16400, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		rc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(10)<<libc.Int32FromInt32(8)
	}
	_sqlite3HaltConstraint(tls, pParse, rc, onError, zMsg, int8(-libc.Int32FromInt32(6)), uint8(P5_ConstraintUnique))
}

// C documentation
//
//	/*
//	** Check to see if pIndex uses the collating sequence pColl.  Return
//	** true if it does and false if it does not.
//	*/
func _collationMatch(tls *libc.TLS, zColl uintptr, pIndex uintptr) (r int32) {
	var i int32
	var z uintptr
	_, _ = i, z
	i = 0
	for {
		if !(i < int32((*TIndex)(unsafe.Pointer(pIndex)).FnColumn)) {
			break
		}
		z = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*4))
		if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2))) >= 0 && 0 == _sqlite3StrICmp(tls, z, zColl) {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Recompute all indices of pTab that use the collating sequence pColl.
//	** If pColl==0 then recompute all indices of pTab.
//	*/
func _reindexTable(tls *libc.TLS, pParse uintptr, pTab uintptr, zColl uintptr) {
	var iDb int32
	var pIndex uintptr
	_, _ = iDb, pIndex
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) { /* An index associated with pTab */
		pIndex = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIndex != 0) {
				break
			}
			if zColl == uintptr(0) || _collationMatch(tls, zColl, pIndex) != 0 {
				iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
				_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
				_sqlite3RefillIndex(tls, pParse, pIndex, -int32(1))
			}
			goto _1
		_1:
			;
			pIndex = (*TIndex)(unsafe.Pointer(pIndex)).FpNext
		}
	}
}

// C documentation
//
//	/*
//	** Recompute all indices of all tables in all databases where the
//	** indices use the collating sequence pColl.  If pColl==0 then recompute
//	** all indices everywhere.
//	*/
func _reindexDatabases(tls *libc.TLS, pParse uintptr, zColl uintptr) {
	var db, k, pDb, pTab uintptr
	var iDb int32
	_, _, _, _, _ = db, iDb, k, pDb, pTab      /* The database index number */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* A table in the database */
	/* Needed for schema access */
	iDb = 0
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
	for {
		if !(iDb < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		k = (*THash)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema + 8)).Ffirst
		for {
			if !(k != 0) {
				break
			}
			pTab = (*THashElem)(unsafe.Pointer(k)).Fdata
			_reindexTable(tls, pParse, pTab, zColl)
			goto _2
		_2:
			;
			k = (*THashElem)(unsafe.Pointer(k)).Fnext
		}
		goto _1
	_1:
		;
		iDb++
		pDb += 16
	}
}

// C documentation
//
//	/*
//	** Generate code for the REINDEX command.
//	**
//	**        REINDEX                            -- 1
//	**        REINDEX  <collation>               -- 2
//	**        REINDEX  ?<database>.?<tablename>  -- 3
//	**        REINDEX  ?<database>.?<indexname>  -- 4
//	**
//	** Form 1 causes all indices in all attached databases to be rebuilt.
//	** Form 2 rebuilds all indices in all databases that use the named
//	** collating function.  Forms 3 and 4 rebuild the named index or all
//	** indices associated with the named table.
//	*/
func _sqlite3Reindex(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pColl, pIndex, pTab, z, zColl, zDb, v1 uintptr
	var iDb int32
	var _ /* pObjName at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _ = db, iDb, pColl, pIndex, pTab, z, zColl, zDb, v1 /* The database index number */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                                  /* Name of the table or index to be reindexed */
	/* 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) {
		_reindexDatabases(tls, pParse, uintptr(0))
		return
	} else {
		if pName2 == uintptr(0) || (*TToken)(unsafe.Pointer(pName2)).Fz == uintptr(0) {
			zColl = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName1)
			if !(zColl != 0) {
				return
			}
			pColl = _sqlite3FindCollSeq(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, zColl, 0)
			if pColl != 0 {
				_reindexDatabases(tls, pParse, zColl)
				_sqlite3DbFree(tls, db, zColl)
				return
			}
			_sqlite3DbFree(tls, db, zColl)
		}
	}
	iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
	if iDb < 0 {
		return
	}
	z = _sqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
	if z == uintptr(0) {
		return
	}
	if (*TToken)(unsafe.Pointer(pName2)).Fn != 0 {
		v1 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	} else {
		v1 = uintptr(0)
	}
	zDb = v1
	pTab = _sqlite3FindTable(tls, db, z, zDb)
	if pTab != 0 {
		_reindexTable(tls, pParse, pTab, uintptr(0))
		_sqlite3DbFree(tls, db, z)
		return
	}
	pIndex = _sqlite3FindIndex(tls, db, z, zDb)
	_sqlite3DbFree(tls, db, z)
	if pIndex != 0 {
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpSchema)
		_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
		_sqlite3RefillIndex(tls, pParse, pIndex, -int32(1))
		return
	}
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16409, 0)
}

// 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 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
	nKey = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return uintptr(0)
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x8>>3)) != 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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*4))
			if zColl == uintptr(unsafe.Pointer(&_sqlite3StrBINARY)) {
				v2 = uintptr(0)
			} else {
				v2 = _sqlite3LocateCollSeq(tls, pParse, zColl)
			}
			*(*uintptr)(unsafe.Pointer(pKey + 20 + uintptr(i)*4)) = v2
			*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKey)).FaSortFlags + uintptr(i))) = *(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i)))
			goto _1
		_1:
			;
			i++
		}
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x200>>9)) == 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.
				 */
				libc.SetBitFieldPtr16Uint32(pIdx+56, libc.Uint32FromInt32(1), 9, 0x200)
				(*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
//
//	/*
//	** Create a new CTE object
//	*/
func _sqlite3CteNew(tls *libc.TLS, pParse uintptr, pName uintptr, pArglist uintptr, pQuery uintptr, eM10d Tu8) (r uintptr) {
	var db, pNew uintptr
	_, _ = db, pNew
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = _sqlite3DbMallocZero(tls, db, uint64(24))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3ExprListDelete(tls, db, pArglist)
		_sqlite3SelectDelete(tls, db, pQuery)
	} else {
		(*TCte)(unsafe.Pointer(pNew)).FpSelect = pQuery
		(*TCte)(unsafe.Pointer(pNew)).FpCols = pArglist
		(*TCte)(unsafe.Pointer(pNew)).FzName = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName)
		(*TCte)(unsafe.Pointer(pNew)).FeM10d = eM10d
	}
	return pNew
}

// C documentation
//
//	/*
//	** Clear information from a Cte object, but do not deallocate storage
//	** for the object itself.
//	*/
func _cteClear(tls *libc.TLS, db uintptr, pCte uintptr) {
	_sqlite3ExprListDelete(tls, db, (*TCte)(unsafe.Pointer(pCte)).FpCols)
	_sqlite3SelectDelete(tls, db, (*TCte)(unsafe.Pointer(pCte)).FpSelect)
	_sqlite3DbFree(tls, db, (*TCte)(unsafe.Pointer(pCte)).FzName)
}

// C documentation
//
//	/*
//	** Free the contents of the CTE object passed as the second argument.
//	*/
func _sqlite3CteDelete(tls *libc.TLS, db uintptr, pCte uintptr) {
	_cteClear(tls, db, pCte)
	_sqlite3DbFree(tls, db, pCte)
}

// C documentation
//
//	/*
//	** This routine is invoked once per CTE by the parser while parsing a
//	** WITH clause.  The CTE described by the third argument is added to
//	** the WITH clause of the second argument.  If the second argument is
//	** NULL, then a new WITH argument is created.
//	*/
func _sqlite3WithAdd(tls *libc.TLS, pParse uintptr, pWith uintptr, pCte uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pNew, zName, v3 uintptr
	var i, v2 int32
	var nByte Tsqlite3_int64
	_, _, _, _, _, _, _ = db, i, nByte, pNew, zName, v2, v3
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pCte == uintptr(0) {
		return pWith
	}
	/* Check that the CTE name is unique within this WITH clause. If
	 ** not, store an error in the Parse structure. */
	zName = (*TCte)(unsafe.Pointer(pCte)).FzName
	if zName != 0 && pWith != 0 {
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(pWith)).FnCte) {
				break
			}
			if _sqlite3StrICmp(tls, zName, (*(*TCte)(unsafe.Pointer(pWith + 12 + uintptr(i)*24))).FzName) == 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16455, libc.VaList(bp+8, zName))
			}
			goto _1
		_1:
			;
			i++
		}
	}
	if pWith != 0 {
		nByte = int64(uint32(36) + uint32(24)*uint32((*TWith)(unsafe.Pointer(pWith)).FnCte))
		pNew = _sqlite3DbRealloc(tls, db, pWith, uint64(uint64(nByte)))
	} else {
		pNew = _sqlite3DbMallocZero(tls, db, uint64(36))
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3CteDelete(tls, db, pCte)
		pNew = pWith
	} else {
		v3 = pNew
		v2 = *(*int32)(unsafe.Pointer(v3))
		*(*int32)(unsafe.Pointer(v3))++
		*(*TCte)(unsafe.Pointer(pNew + 12 + uintptr(v2)*24)) = *(*TCte)(unsafe.Pointer(pCte))
		_sqlite3DbFree(tls, db, pCte)
	}
	return pNew
}

// C documentation
//
//	/*
//	** Free the contents of the With object passed as the second argument.
//	*/
func _sqlite3WithDelete(tls *libc.TLS, db uintptr, pWith uintptr) {
	var i int32
	_ = i
	if pWith != 0 {
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(pWith)).FnCte) {
				break
			}
			_cteClear(tls, db, pWith+12+uintptr(i)*24)
			goto _1
		_1:
			;
			i++
		}
		_sqlite3DbFree(tls, db, pWith)
	}
}

func _sqlite3WithDeleteGeneric(tls *libc.TLS, db uintptr, pWith uintptr) {
	_sqlite3WithDelete(tls, db, pWith)
}

/************** End of build.c ***********************************************/
/************** Begin file callback.c ****************************************/
/*
** 2005 May 23
**
** 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 functions used to access the internal hash tables
** of user defined functions and collation sequences.
 */

/* #include "sqliteInt.h" */

// 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_UTF16LE))
		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, int32((*Tsqlite3)(unsafe.Pointer(db)).Fenc), zExternal1)
		}
		_sqlite3ValueFree(tls, pTmp)
	}
}

// C documentation
//
//	/*
//	** This routine is called if the collation factory fails to deliver a
//	** collation function in the best encoding but there may be other versions
//	** of this collation function (for other text encodings) available. Use one
//	** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
//	** possible.
//	*/
func _synthCollSeq(tls *libc.TLS, db uintptr, pColl uintptr) (r int32) {
	var i int32
	var pColl2, z uintptr
	_, _, _ = i, pColl2, z
	z = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
	i = 0
	for {
		if !(i < int32(3)) {
			break
		}
		pColl2 = _sqlite3FindCollSeq(tls, db, _aEnc[i], z, 0)
		if (*TCollSeq)(unsafe.Pointer(pColl2)).FxCmp != uintptr(0) {
			libc.Xmemcpy(tls, pColl, pColl2, uint32(20))
			(*TCollSeq)(unsafe.Pointer(pColl)).FxDel = uintptr(0) /* Do not copy the destructor */
			return SQLITE_OK
		}
		goto _1
	_1:
		;
		i++
	}
	return int32(SQLITE_ERROR)
}

var _aEnc = [3]Tu8{
	0: uint8(SQLITE_UTF16BE),
	1: uint8(SQLITE_UTF16LE),
	2: uint8(SQLITE_UTF8),
}

// C documentation
//
//	/*
//	** This routine is called on a collation sequence before it is used to
//	** check that it is defined. An undefined collation sequence exists when
//	** a database is loaded that contains references to collation sequences
//	** that have not been defined by sqlite3_create_collation() etc.
//	**
//	** If required, this routine calls the 'collation needed' callback to
//	** request a definition of the collating sequence. If this doesn't work,
//	** an equivalent collating sequence that uses a text encoding different
//	** from the main database is substituted, if one is available.
//	*/
func _sqlite3CheckCollSeq(tls *libc.TLS, pParse uintptr, pColl uintptr) (r int32) {
	var db, p, zName uintptr
	_, _, _ = db, p, zName
	if pColl != 0 && (*TCollSeq)(unsafe.Pointer(pColl)).FxCmp == uintptr(0) {
		zName = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		p = _sqlite3GetCollSeq(tls, pParse, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, pColl, zName)
		if !(p != 0) {
			return int32(SQLITE_ERROR)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Locate and return an entry from the db.aCollSeq hash table. If the entry
//	** specified by zName and nName is not found and parameter 'create' is
//	** true, then create a new entry. Otherwise return NULL.
//	**
//	** Each pointer stored in the sqlite3.aCollSeq hash table contains an
//	** array of three CollSeq structures. The first is the collation sequence
//	** preferred for UTF-8, the second UTF-16le, and the third UTF-16be.
//	**
//	** Stored immediately after the three collation sequences is a copy of
//	** the collation sequence name. A pointer to this string is stored in
//	** each collation sequence structure.
//	*/
func _findCollSeqEntry(tls *libc.TLS, db uintptr, zName uintptr, create int32) (r uintptr) {
	var nName int32
	var pColl, pDel uintptr
	_, _, _ = nName, pColl, pDel
	pColl = _sqlite3HashFind(tls, db+448, zName)
	if uintptr(0) == pColl && create != 0 {
		nName = _sqlite3Strlen30(tls, zName) + int32(1)
		pColl = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint32FromInt32(3)*libc.Uint32FromInt64(20)+uint32(uint32(nName))))
		if pColl != 0 {
			pDel = uintptr(0)
			(*(*TCollSeq)(unsafe.Pointer(pColl))).FzName = pColl + 3*20
			(*(*TCollSeq)(unsafe.Pointer(pColl))).Fenc = uint8(SQLITE_UTF8)
			(*(*TCollSeq)(unsafe.Pointer(pColl + 1*20))).FzName = pColl + 3*20
			(*(*TCollSeq)(unsafe.Pointer(pColl + 1*20))).Fenc = uint8(SQLITE_UTF16LE)
			(*(*TCollSeq)(unsafe.Pointer(pColl + 2*20))).FzName = pColl + 3*20
			(*(*TCollSeq)(unsafe.Pointer(pColl + 2*20))).Fenc = uint8(SQLITE_UTF16BE)
			libc.Xmemcpy(tls, (*(*TCollSeq)(unsafe.Pointer(pColl))).FzName, zName, uint32(uint32(nName)))
			pDel = _sqlite3HashInsert(tls, db+448, (*(*TCollSeq)(unsafe.Pointer(pColl))).FzName, pColl)
			/* If a malloc() failure occurred in sqlite3HashInsert(), it will
			 ** return the pColl pointer to be deleted (because it wasn't added
			 ** to the hash table).
			 */
			if pDel != uintptr(0) {
				_sqlite3OomFault(tls, db)
				_sqlite3DbFree(tls, db, pDel)
				pColl = uintptr(0)
			}
		}
	}
	return pColl
}

// C documentation
//
//	/*
//	** Parameter zName points to a UTF-8 encoded string nName bytes long.
//	** Return the CollSeq* pointer for the collation sequence named zName
//	** for the encoding 'enc' from the database 'db'.
//	**
//	** If the entry specified is not found and 'create' is true, then create a
//	** new entry.  Otherwise return NULL.
//	**
//	** A separate function sqlite3LocateCollSeq() is a wrapper around
//	** this routine.  sqlite3LocateCollSeq() invokes the collation factory
//	** if necessary and generates an error message if the collating sequence
//	** cannot be found.
//	**
//	** See also: sqlite3LocateCollSeq(), sqlite3GetCollSeq()
//	*/
func _sqlite3FindCollSeq(tls *libc.TLS, db uintptr, enc Tu8, zName uintptr, create int32) (r uintptr) {
	var pColl uintptr
	_ = pColl
	if zName != 0 {
		pColl = _findCollSeqEntry(tls, db, zName, create)
		if pColl != 0 {
			pColl += uintptr(int32(int32(enc))-int32(1)) * 20
		}
	} else {
		pColl = (*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl
	}
	return pColl
}

// C documentation
//
//	/*
//	** Change the text encoding for a database connection. This means that
//	** the pDfltColl must change as well.
//	*/
func _sqlite3SetTextEncoding(tls *libc.TLS, db uintptr, enc Tu8) {
	(*Tsqlite3)(unsafe.Pointer(db)).Fenc = enc
	/* EVIDENCE-OF: R-08308-17224 The default collating function for all
	 ** strings is BINARY.
	 */
	(*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl = _sqlite3FindCollSeq(tls, db, enc, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), 0)
	_sqlite3ExpirePreparedStatements(tls, db, int32(1))
}

// C documentation
//
//	/*
//	** This function is responsible for invoking the collation factory callback
//	** or substituting a collation sequence of a different encoding when the
//	** requested collation sequence is not available in the desired encoding.
//	**
//	** If it is not NULL, then pColl must point to the database native encoding
//	** collation sequence with name zName, length nName.
//	**
//	** The return value is either the collation sequence to be used in database
//	** db for collation type name zName, length nName, or NULL, if no collation
//	** sequence can be found.  If no collation is found, leave an error message.
//	**
//	** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq()
//	*/
func _sqlite3GetCollSeq(tls *libc.TLS, pParse uintptr, enc Tu8, pColl uintptr, zName uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, p uintptr
	_, _ = db, p
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	p = pColl
	if !(p != 0) {
		p = _sqlite3FindCollSeq(tls, db, enc, zName, 0)
	}
	if !(p != 0) || !((*TCollSeq)(unsafe.Pointer(p)).FxCmp != 0) {
		/* No collation sequence of this type for this encoding is registered.
		 ** Call the collation factory to see if it can supply us with one.
		 */
		_callCollNeeded(tls, db, int32(int32(enc)), zName)
		p = _sqlite3FindCollSeq(tls, db, enc, zName, 0)
	}
	if p != 0 && !((*TCollSeq)(unsafe.Pointer(p)).FxCmp != 0) && _synthCollSeq(tls, db, p) != 0 {
		p = uintptr(0)
	}
	if p == uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16485, libc.VaList(bp+8, zName))
		(*TParse)(unsafe.Pointer(pParse)).Frc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	}
	return p
}

// C documentation
//
//	/*
//	** This function returns the collation sequence for database native text
//	** encoding identified by the string zName.
//	**
//	** If the requested collation sequence is not available, or not available
//	** in the database native encoding, the collation factory is invoked to
//	** request it. If the collation factory does not supply such a sequence,
//	** and the sequence is available in another text encoding, then that is
//	** returned instead.
//	**
//	** If no versions of the requested collations sequence are available, or
//	** another error occurs, NULL is returned and an error message written into
//	** pParse.
//	**
//	** This routine is a wrapper around sqlite3FindCollSeq().  This routine
//	** invokes the collation factory if the named collation cannot be found
//	** and generates an error message.
//	**
//	** See also: sqlite3FindCollSeq(), sqlite3GetCollSeq()
//	*/
func _sqlite3LocateCollSeq(tls *libc.TLS, pParse uintptr, zName uintptr) (r uintptr) {
	var db, pColl uintptr
	var enc, initbusy Tu8
	_, _, _, _ = db, enc, initbusy, pColl
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	enc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
	initbusy = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy
	pColl = _sqlite3FindCollSeq(tls, db, enc, zName, int32(int32(initbusy)))
	if !(initbusy != 0) && (!(pColl != 0) || !((*TCollSeq)(unsafe.Pointer(pColl)).FxCmp != 0)) {
		pColl = _sqlite3GetCollSeq(tls, pParse, enc, pColl, zName)
	}
	return pColl
}

// C documentation
//
//	/* During the search for the best function definition, this procedure
//	** is called to test how well the function passed as the first argument
//	** matches the request for a function with nArg arguments in a system
//	** that uses encoding enc. The value returned indicates how well the
//	** request is matched. A higher value indicates a better match.
//	**
//	** If nArg is -1 that means to only return a match (non-zero) if p->nArg
//	** is also -1.  In other words, we are searching for a function that
//	** takes a variable number of arguments.
//	**
//	** If nArg is -2 that means that we are searching for any function
//	** regardless of the number of arguments it uses, so return a positive
//	** match score for any
//	**
//	** The returned value is always between 0 and 6, as follows:
//	**
//	** 0: Not a match.
//	** 1: UTF8/16 conversion required and function takes any number of arguments.
//	** 2: UTF16 byte order change required and function takes any number of args.
//	** 3: encoding matches and function takes any number of arguments
//	** 4: UTF8/16 conversion required - argument count matches exactly
//	** 5: UTF16 byte order conversion required - argument count matches exactly
//	** 6: Perfect match:  encoding and argument count match exactly.
//	**
//	** If nArg==(-2) then any function with a non-null xSFunc is
//	** a perfect match and any function with xSFunc NULL is
//	** a non-match.
//	*/
func _matchQuality(tls *libc.TLS, p uintptr, nArg int32, enc Tu8) (r int32) {
	var match, v1 int32
	_, _ = match, v1
	/* Wrong number of arguments means "no match" */
	if int32((*TFuncDef)(unsafe.Pointer(p)).FnArg) != nArg {
		if nArg == -int32(2) {
			if (*TFuncDef)(unsafe.Pointer(p)).FxSFunc == uintptr(0) {
				v1 = 0
			} else {
				v1 = int32(FUNC_PERFECT_MATCH)
			}
			return v1
		}
		if int32((*TFuncDef)(unsafe.Pointer(p)).FnArg) >= 0 {
			return 0
		}
	}
	/* Give a better score to a function with a specific number of arguments
	 ** than to function that accepts any number of arguments. */
	if int32((*TFuncDef)(unsafe.Pointer(p)).FnArg) == nArg {
		match = int32(4)
	} else {
		match = int32(1)
	}
	/* Bonus points if the text encoding matches */
	if uint32(uint32(enc)) == (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) {
		match += int32(2) /* Exact encoding match */
	} else {
		if uint32(uint32(enc))&(*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(2) != uint32(0) {
			match += int32(1) /* Both are UTF16, but with different byte orders */
		}
	}
	return match
}

// C documentation
//
//	/*
//	** Search a FuncDefHash for a function with the given name.  Return
//	** a pointer to the matching FuncDef if found, or 0 if there is no match.
//	*/
func _sqlite3FunctionSearch(tls *libc.TLS, h int32, zFunc uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)) + uintptr(h)*4))
	for {
		if !(p != 0) {
			break
		}
		if _sqlite3StrICmp(tls, (*TFuncDef)(unsafe.Pointer(p)).FzName, zFunc) == 0 {
			return p
		}
		goto _1
	_1:
		;
		p = *(*uintptr)(unsafe.Pointer(p + 36))
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Insert a new FuncDef into a FuncDefHash hash table.
//	*/
func _sqlite3InsertBuiltinFuncs(tls *libc.TLS, aDef uintptr, nDef int32) {
	var h, i, nName int32
	var pOther, zName uintptr
	_, _, _, _, _ = h, i, nName, pOther, zName
	i = 0
	for {
		if !(i < nDef) {
			break
		}
		zName = (*(*TFuncDef)(unsafe.Pointer(aDef + uintptr(i)*40))).FzName
		nName = _sqlite3Strlen30(tls, zName)
		h = (int32(*(*int8)(unsafe.Pointer(zName))) + nName) % int32(SQLITE_FUNC_HASH_SZ)
		pOther = _sqlite3FunctionSearch(tls, h, zName)
		if pOther != 0 {
			(*(*TFuncDef)(unsafe.Pointer(aDef + uintptr(i)*40))).FpNext = (*TFuncDef)(unsafe.Pointer(pOther)).FpNext
			(*TFuncDef)(unsafe.Pointer(pOther)).FpNext = aDef + uintptr(i)*40
		} else {
			(*(*TFuncDef)(unsafe.Pointer(aDef + uintptr(i)*40))).FpNext = uintptr(0)
			*(*uintptr)(unsafe.Pointer(aDef + uintptr(i)*40 + 36)) = *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)) + uintptr(h)*4))
			*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)) + uintptr(h)*4)) = aDef + uintptr(i)*40
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Locate a user function given a name, a number of arguments and a flag
//	** indicating whether the function prefers UTF-16 over UTF-8.  Return a
//	** pointer to the FuncDef structure that defines that function, or return
//	** NULL if the function does not exist.
//	**
//	** If the createFlag argument is true, then a new (blank) FuncDef
//	** structure is created and liked into the "db" structure if a
//	** no matching function previously existed.
//	**
//	** If nArg is -2, then the first valid function found is returned.  A
//	** function is valid if xSFunc is non-zero.  The nArg==(-2)
//	** case is used to see if zName is a valid function name for some number
//	** of arguments.  If nArg is -2, then createFlag must be 0.
//	**
//	** If createFlag is false, then a function with the required name and
//	** number of arguments may be returned even if the eTextRep flag does not
//	** match that requested.
//	*/
func _sqlite3FindFunction(tls *libc.TLS, db uintptr, zName uintptr, nArg int32, enc Tu8, createFlag Tu8) (r uintptr) {
	var bestScore, h, nName, score, score1 int32
	var p, pBest, pOther, z, v1 uintptr
	var v2 bool
	_, _, _, _, _, _, _, _, _, _, _ = bestScore, h, nName, p, pBest, pOther, score, score1, z, v1, v2 /* Iterator variable */
	pBest = uintptr(0)                                                                                /* Best match found so far */
	bestScore = 0                                                                                     /* Length of the name */
	nName = _sqlite3Strlen30(tls, zName)
	/* First search for a match amongst the application-defined functions.
	 */
	p = _sqlite3HashFind(tls, db+432, zName)
	for p != 0 {
		score = _matchQuality(tls, p, nArg, enc)
		if score > bestScore {
			pBest = p
			bestScore = score
		}
		p = (*TFuncDef)(unsafe.Pointer(p)).FpNext
	}
	/* If no match is found, search the built-in functions.
	 **
	 ** If the DBFLAG_PreferBuiltin flag is set, then search the built-in
	 ** functions even if a prior app-defined function was found.  And give
	 ** priority to built-in functions.
	 **
	 ** Except, if createFlag is true, that means that we are trying to
	 ** install a new function.  Whatever FuncDef structure is returned it will
	 ** have fields overwritten with new information appropriate for the
	 ** new function.  But the FuncDefs for built-in functions are read-only.
	 ** So we must not search for built-ins when creating a new function.
	 */
	if !(createFlag != 0) && (pBest == uintptr(0) || (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_PreferBuiltin) != uint32(0)) {
		bestScore = 0
		h = (int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(zName)))]) + nName) % int32(SQLITE_FUNC_HASH_SZ)
		p = _sqlite3FunctionSearch(tls, h, zName)
		for p != 0 {
			score1 = _matchQuality(tls, p, nArg, enc)
			if score1 > bestScore {
				pBest = p
				bestScore = score1
			}
			p = (*TFuncDef)(unsafe.Pointer(p)).FpNext
		}
	}
	/* If the createFlag parameter is true and the search did not reveal an
	 ** exact match for the name, number of arguments and encoding, then add a
	 ** new entry to the hash table and return it.
	 */
	if v2 = createFlag != 0 && bestScore < int32(FUNC_PERFECT_MATCH); v2 {
		v1 = _sqlite3DbMallocZero(tls, db, uint64(uint32(40)+uint32(uint32(nName))+uint32(1)))
		pBest = v1
	}
	if v2 && v1 != uintptr(0) {
		(*TFuncDef)(unsafe.Pointer(pBest)).FzName = pBest + 1*40
		(*TFuncDef)(unsafe.Pointer(pBest)).FnArg = int8(uint16(uint16(nArg)))
		(*TFuncDef)(unsafe.Pointer(pBest)).FfuncFlags = uint32(uint32(enc))
		libc.Xmemcpy(tls, pBest+1*40, zName, uint32(nName+int32(1)))
		z = (*TFuncDef)(unsafe.Pointer(pBest)).FzName
		for {
			if !(*(*Tu8)(unsafe.Pointer(z)) != 0) {
				break
			}
			*(*Tu8)(unsafe.Pointer(z)) = _sqlite3UpperToLower[*(*Tu8)(unsafe.Pointer(z))]
			goto _3
		_3:
			;
			z++
		}
		pOther = _sqlite3HashInsert(tls, db+432, (*TFuncDef)(unsafe.Pointer(pBest)).FzName, pBest)
		if pOther == pBest {
			_sqlite3DbFree(tls, db, pBest)
			_sqlite3OomFault(tls, db)
			return uintptr(0)
		} else {
			(*TFuncDef)(unsafe.Pointer(pBest)).FpNext = pOther
		}
	}
	if pBest != 0 && ((*TFuncDef)(unsafe.Pointer(pBest)).FxSFunc != 0 || createFlag != 0) {
		return pBest
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Free all resources held by the schema structure. The void* argument points
//	** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
//	** pointer itself, it just cleans up subsidiary resources (i.e. the contents
//	** of the schema hash tables).
//	**
//	** The Schema.cache_size variable is not cleared.
//	*/
func _sqlite3SchemaClear(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(608)
	defer tls.Free(608)
	var pElem, pSchema, pTab, p3 uintptr
	var _ /* temp1 at bp+0 */ THash
	var _ /* temp2 at bp+16 */ THash
	var _ /* xdb at bp+32 */ Tsqlite3
	_, _, _, _ = pElem, pSchema, pTab, p3
	pSchema = p
	libc.Xmemset(tls, bp+32, 0, uint32(576))
	*(*THash)(unsafe.Pointer(bp)) = (*TSchema)(unsafe.Pointer(pSchema)).FtblHash
	*(*THash)(unsafe.Pointer(bp + 16)) = (*TSchema)(unsafe.Pointer(pSchema)).FtrigHash
	_sqlite3HashInit(tls, pSchema+40)
	_sqlite3HashClear(tls, pSchema+24)
	pElem = (*THash)(unsafe.Pointer(bp + 16)).Ffirst
	for {
		if !(pElem != 0) {
			break
		}
		_sqlite3DeleteTrigger(tls, bp+32, (*THashElem)(unsafe.Pointer(pElem)).Fdata)
		goto _1
	_1:
		;
		pElem = (*THashElem)(unsafe.Pointer(pElem)).Fnext
	}
	_sqlite3HashClear(tls, bp+16)
	_sqlite3HashInit(tls, pSchema+8)
	pElem = (*THash)(unsafe.Pointer(bp)).Ffirst
	for {
		if !(pElem != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(pElem)).Fdata
		_sqlite3DeleteTable(tls, bp+32, pTab)
		goto _2
	_2:
		;
		pElem = (*THashElem)(unsafe.Pointer(pElem)).Fnext
	}
	_sqlite3HashClear(tls, bp)
	_sqlite3HashClear(tls, pSchema+56)
	(*TSchema)(unsafe.Pointer(pSchema)).FpSeqTab = uintptr(0)
	if int32((*TSchema)(unsafe.Pointer(pSchema)).FschemaFlags)&int32(DB_SchemaLoaded) != 0 {
		(*TSchema)(unsafe.Pointer(pSchema)).FiGeneration++
	}
	p3 = pSchema + 78
	*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^(libc.Int32FromInt32(DB_SchemaLoaded) | libc.Int32FromInt32(DB_ResetWanted)))
}

// C documentation
//
//	/*
//	** Find and return the schema associated with a BTree.  Create
//	** a new one if necessary.
//	*/
func _sqlite3SchemaGet(tls *libc.TLS, db uintptr, pBt uintptr) (r uintptr) {
	var p uintptr
	_ = p
	if pBt != 0 {
		p = _sqlite3BtreeSchema(tls, pBt, int32(84), __ccgo_fp(_sqlite3SchemaClear))
	} else {
		p = _sqlite3DbMallocZero(tls, uintptr(0), uint64(84))
	}
	if !(p != 0) {
		_sqlite3OomFault(tls, db)
	} else {
		if 0 == int32((*TSchema)(unsafe.Pointer(p)).Ffile_format) {
			_sqlite3HashInit(tls, p+8)
			_sqlite3HashInit(tls, p+24)
			_sqlite3HashInit(tls, p+40)
			_sqlite3HashInit(tls, p+56)
			(*TSchema)(unsafe.Pointer(p)).Fenc = uint8(SQLITE_UTF8)
		}
	}
	return p
}

/************** End of callback.c ********************************************/
/************** Begin file delete.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 C code routines that are called by the parser
** in order to generate code for DELETE FROM statements.
 */
/* #include "sqliteInt.h" */

// 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].pTab       Pointer to the Table object
//	**    pSrc->a[0].pIndex     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)).FpTab != 0 {
		_sqlite3DeleteTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSrcItem)(unsafe.Pointer(pItem)).FpTab)
	}
	(*TSrcItem)(unsafe.Pointer(pItem)).FpTab = pTab
	libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 9, 0x200)
	if pTab != 0 {
		(*TTable)(unsafe.Pointer(pTab)).FnTabRef++
		if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x2>>1)) != 0 && _sqlite3IndexedByLookup(tls, pParse, pItem) != 0 {
			pTab = uintptr(0)
		}
	}
	return pTab
}

// C documentation
//
//	/* Generate byte-code that will report the number of rows modified
//	** by a DELETE, INSERT, or UPDATE statement.
//	*/
func _sqlite3CodeChangeCount(tls *libc.TLS, v uintptr, regCounter int32, zColName uintptr) {
	_sqlite3VdbeAddOp0(tls, v, int32(OP_FkCheck))
	_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), regCounter, int32(1))
	_sqlite3VdbeSetNumCols(tls, v, int32(1))
	_sqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, zColName, libc.UintptrFromInt32(0))
}

// C documentation
//
//	/* Return true if table pTab is read-only.
//	**
//	** A table is read-only if any of the following are true:
//	**
//	**   1) It is a virtual table and no implementation of the xUpdate method
//	**      has been provided
//	**
//	**   2) A trigger is currently being coded and the table is a virtual table
//	**      that is SQLITE_VTAB_DIRECTONLY or if PRAGMA trusted_schema=OFF and
//	**      the table is not SQLITE_VTAB_INNOCUOUS.
//	**
//	**   3) It is a system table (i.e. sqlite_schema), this call is not
//	**      part of a nested parse and writable_schema pragma has not
//	**      been specified
//	**
//	**   4) The table is a shadow table, the database connection is in
//	**      defensive mode, and the current sqlite3_prepare()
//	**      is for a top-level SQL statement.
//	*/
func _vtabIsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pTab))).FpMod)).FpModule)).FxUpdate == uintptr(0) {
		return int32(1)
	}
	/* Within triggers:
	 **   *  Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
	 **      virtual tables
	 **   *  Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
	 **      virtual tables if PRAGMA trusted_schema=ON.
	 */
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != uintptr(0) && int32((*TVTable)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).Fp)).FeVtabRisk) > libc.BoolInt32((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16516, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
	}
	return 0
}

func _tabIsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
	var db uintptr
	_ = db
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		return _vtabIsReadOnly(tls, pParse, pTab)
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(libc.Int32FromInt32(TF_Readonly)|libc.Int32FromInt32(TF_Shadow)) == uint32(0) {
		return 0
	}
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Readonly) != uint32(0) {
		return libc.BoolInt32(_sqlite3WritableSchema(tls, db) == 0 && int32((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0)
	}
	return _sqlite3ReadOnlyShadowTables(tls, db)
}

// C documentation
//
//	/*
//	** Check to make sure the given table is writable.
//	**
//	** If pTab is not writable  ->  generate an error message and return 1.
//	** If pTab is writable but other errors have occurred -> return 1.
//	** If pTab is writable and no prior errors -> return 0;
//	*/
func _sqlite3IsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr, pTrigger uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if _tabIsReadOnly(tls, pParse, pTab) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16549, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) && (pTrigger == uintptr(0) || (*TTrigger)(unsafe.Pointer(pTrigger)).FbReturning != 0 && (*TTrigger)(unsafe.Pointer(pTrigger)).FpNext == uintptr(0)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16578, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Evaluate a view and store its result in an ephemeral table.  The
//	** pWhere argument is an optional WHERE clause that restricts the
//	** set of rows in the view that are to be added to the ephemeral table.
//	*/
func _sqlite3MaterializeView(tls *libc.TLS, pParse uintptr, pView uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr, iCur int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pFrom, pSel uintptr
	var iDb int32
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _ = db, iDb, pFrom, pSel
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pView)).FpSchema)
	pWhere = _sqlite3ExprDup(tls, db, pWhere, 0)
	pFrom = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
	if pFrom != 0 {
		(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FzName = _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pView)).FzName)
		(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FzDatabase = _sqlite3DbStrDup(tls, db, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
	}
	pSel = _sqlite3SelectNew(tls, pParse, uintptr(0), pFrom, pWhere, uintptr(0), uintptr(0), pOrderBy, uint32(SF_IncludeHidden), pLimit)
	_sqlite3SelectDestInit(tls, bp, int32(SRT_EphemTab), iCur)
	_sqlite3Select(tls, pParse, pSel, bp)
	_sqlite3SelectDelete(tls, db, pSel)
}

/*      && !defined(SQLITE_OMIT_SUBQUERY) */

// 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(64)
	defer tls.Free(64)
	var aToOpen, db, pIdx, pPk, pTab, pTrigger, pVTab, pWInfo, v, v13, v15, v18, v20, v3, v7 uintptr
	var addrBypass, addrEphOpen, addrLoop, bComplex, count, eOnePass, i, iAddrOnce, iDb, iEphCur, iKey, iPk, iRowSet, iTabCur, isView, memCnt, nIdx, rcauth, v1, v10, v11, v12, v14, v17, v19, v2, v5, v6, v8 int32
	var nKey, nPk Ti16
	var wcf Tu16
	var _ /* aiCurOnePass at bp+56 */ [2]int32
	var _ /* iDataCur at bp+0 */ int32
	var _ /* iIdxCur at bp+4 */ int32
	var _ /* sContext at bp+8 */ TAuthContext
	var _ /* sNC at bp+16 */ 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, v10, v11, v12, v13, v14, v15, v17, v18, v19, v2, v20, v3, v5, v6, v7, v8 /* Cursor number for the table */
	*(*int32)(unsafe.Pointer(bp)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                         /* VDBE cursor for the canonical data source */
	*(*int32)(unsafe.Pointer(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, uint32(8))
	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(int32((*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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
	if rcauth == int32(SQLITE_DENY) {
		goto delete_from_cleanup
	}
	/* Assign cursor numbers to the table and all its indices.
	 */
	v3 = pParse + 40
	v2 = *(*int32)(unsafe.Pointer(v3))
	*(*int32)(unsafe.Pointer(v3))++
	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++
		goto _4
	_4:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nIdx++
	}
	/* 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 int32((*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)
		v5 = iTabCur
		*(*int32)(unsafe.Pointer(bp + 4)) = v5
		*(*int32)(unsafe.Pointer(bp)) = v5
		pOrderBy = uintptr(0)
		pLimit = uintptr(0)
	}
	/* Resolve the column names in the WHERE clause.
	 */
	libc.Xmemset(tls, bp+16, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp + 16))).FpParse = pParse
	(*(*TNameContext)(unsafe.Pointer(bp + 16))).FpSrcList = pTabList
	if _sqlite3ResolveExprNames(tls, bp+16, 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&(uint64(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !((*TParse)(unsafe.Pointer(pParse)).FbReturning != 0) {
		v7 = pParse + 44
		*(*int32)(unsafe.Pointer(v7))++
		v6 = *(*int32)(unsafe.Pointer(v7))
		memCnt = v6
		_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) && !(int32((*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 {
				v8 = memCnt
			} else {
				v8 = -int32(1)
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Clear), int32((*TTable)(unsafe.Pointer(pTab)).Ftnum), iDb, v8, (*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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
				if memCnt != 0 {
					v10 = memCnt
				} else {
					v10 = -int32(1)
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Clear), int32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb, v10)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), int32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			}
			goto _9
		_9:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	} else {
		wcf = uint16(libc.Int32FromInt32(WHERE_ONEPASS_DESIRED) | libc.Int32FromInt32(WHERE_DUPLICATES_OK))
		if (*(*TNameContext)(unsafe.Pointer(bp + 16))).FncFlags&int32(NC_Subquery) != 0 {
			bComplex = int32(1)
		}
		if bComplex != 0 {
			v11 = 0
		} else {
			v11 = int32(WHERE_ONEPASS_MULTIROW)
		}
		wcf = Tu16(int32(wcf) | v11)
		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)
			v13 = pParse + 44
			*(*int32)(unsafe.Pointer(v13))++
			v12 = *(*int32)(unsafe.Pointer(v13))
			iRowSet = v12
			_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 = int16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
			iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			*(*int32)(unsafe.Pointer(pParse + 44)) += int32(int32(nPk))
			v15 = pParse + 40
			v14 = *(*int32)(unsafe.Pointer(v15))
			*(*int32)(unsafe.Pointer(v15))++
			iEphCur = v14
			addrEphOpen = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iEphCur, int32(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+56)
		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(int32(nPk))) {
					break
				}
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
				goto _16
			_16:
				;
				i++
			}
			iKey = iPk
		} else {
			v18 = pParse + 44
			*(*int32)(unsafe.Pointer(v18))++
			v17 = *(*int32)(unsafe.Pointer(v18))
			iKey = v17
			_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, uint64(nIdx+int32(2)))
			if aToOpen == uintptr(0) {
				_sqlite3WhereEnd(tls, pWInfo)
				goto delete_from_cleanup
			}
			libc.Xmemset(tls, aToOpen, int32(1), uint32(nIdx+int32(1)))
			*(*Tu8)(unsafe.Pointer(aToOpen + uintptr(nIdx+int32(1)))) = uint8(0)
			if (*(*[2]int32)(unsafe.Pointer(bp + 56)))[0] >= 0 {
				*(*Tu8)(unsafe.Pointer(aToOpen + uintptr((*(*[2]int32)(unsafe.Pointer(bp + 56)))[0]-iTabCur))) = uint8(0)
			}
			if (*(*[2]int32)(unsafe.Pointer(bp + 56)))[int32(1)] >= 0 {
				*(*Tu8)(unsafe.Pointer(aToOpen + uintptr((*(*[2]int32)(unsafe.Pointer(bp + 56)))[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 */
				v20 = pParse + 44
				*(*int32)(unsafe.Pointer(v20))++
				v19 = *(*int32)(unsafe.Pointer(v20))
				iKey = v19
				nKey = 0 /* Zero tells OP_Found to use a composite key */
				_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), iPk, int32(int32(nPk)), iKey, _sqlite3IndexAffinityStr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPk), int32(int32(nPk)))
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iEphCur, iKey, iPk, int32(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 !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && *(*Tu8)(unsafe.Pointer(aToOpen + uintptr(*(*int32)(unsafe.Pointer(bp))-iTabCur))) != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), *(*int32)(unsafe.Pointer(bp)), addrBypass, iKey, int32(int32(nKey)))
			}
		} else {
			if pPk != 0 {
				addrLoop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iEphCur)
				if int32((*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 int32((*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(11))
			_sqlite3VdbeChangeP5(tls, v, uint16(OE_Abort))
		} else {
			count = libc.BoolInt32(int32((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0) /* True to count changes */
			_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, *(*int32)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)), iKey, nKey, uint8(uint8(count)), uint8(OE_Default), uint8(uint8(eOnePass)), (*(*[2]int32)(unsafe.Pointer(bp + 56)))[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 int32((*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+16616)
	}
	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 generates VDBE code that causes a single row of a
//	** single table to be deleted.  Both the original table entry and
//	** all indices are removed.
//	**
//	** Preconditions:
//	**
//	**   1.  iDataCur is an open cursor on the btree that is the canonical data
//	**       store for the table.  (This will be either the table itself,
//	**       in the case of a rowid table, or the PRIMARY KEY index in the case
//	**       of a WITHOUT ROWID table.)
//	**
//	**   2.  Read/write cursors for all indices of pTab must be open as
//	**       cursor number iIdxCur+i for the i-th index.
//	**
//	**   3.  The primary key for the row to be deleted must be stored in a
//	**       sequence of nPk memory cells starting at iPk.  If nPk==0 that means
//	**       that a search record formed from OP_MakeRecord is contained in the
//	**       single memory location iPk.
//	**
//	** eMode:
//	**   Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or
//	**   ONEPASS_MULTI.  If eMode is not ONEPASS_OFF, then the cursor
//	**   iDataCur already points to the row to delete. If eMode is ONEPASS_OFF
//	**   then this function must seek iDataCur to the entry identified by iPk
//	**   and nPk before reading from it.
//	**
//	**   If eMode is ONEPASS_MULTI, then this call is being made as part
//	**   of a ONEPASS delete that affects multiple rows. In this case, if
//	**   iIdxNoSeek is a valid cursor number (>=0) and is not the same as
//	**   iDataCur, then its position should be preserved following the delete
//	**   operation. Or, if iIdxNoSeek is not a valid cursor number, the
//	**   position of iDataCur should be preserved instead.
//	**
//	** iIdxNoSeek:
//	**   If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
//	**   then it identifies an index cursor (from within array of cursors
//	**   starting at iIdxCur) that already points to the index entry to be deleted.
//	**   Except, this optimization is disabled if there are BEFORE triggers since
//	**   the trigger body might have moved the cursor.
//	*/
func _sqlite3GenerateRowDelete(tls *libc.TLS, pParse uintptr, pTab uintptr, pTrigger uintptr, iDataCur int32, iIdxCur int32, iPk int32, nPk Ti16, count Tu8, onconf Tu8, eMode Tu8, iIdxNoSeek int32) {
	var addrStart, iCol, iLabel, iOld, kk, v1, v3 int32
	var mask Tu32
	var opSeek, p5 Tu8
	var v uintptr
	_, _, _, _, _, _, _, _, _, _, _ = addrStart, iCol, iLabel, iOld, kk, mask, opSeek, p5, v, v1, v3
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* Vdbe */
	iOld = 0                                     /* Seek opcode */
	/* Vdbe is guaranteed to have been allocated by this stage. */
	/* Seek cursor iCur to the row to delete. If this row no longer exists
	 ** (this can happen if a trigger program has already deleted it), do
	 ** not attempt to delete it or fire any DELETE triggers.  */
	iLabel = _sqlite3VdbeMakeLabel(tls, pParse)
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		v1 = int32(OP_NotExists)
	} else {
		v1 = int32(OP_NotFound)
	}
	opSeek = uint8(v1)
	if int32(int32(eMode)) == ONEPASS_OFF {
		_sqlite3VdbeAddOp4Int(tls, v, int32(int32(opSeek)), iDataCur, iLabel, iPk, int32(int32(nPk)))
	}
	/* If there are any triggers to fire, allocate a range of registers to
	 ** use for the old.* references in the triggers.  */
	if _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0 || pTrigger != 0 { /* Start of BEFORE trigger programs */
		/* TODO: Could use temporary registers here. Also could attempt to
		 ** avoid copying the contents of the rowid register.  */
		mask = _sqlite3TriggerColmask(tls, pParse, pTrigger, uintptr(0), 0, libc.Int32FromInt32(TRIGGER_BEFORE)|libc.Int32FromInt32(TRIGGER_AFTER), pTab, int32(int32(onconf)))
		mask |= _sqlite3FkOldmask(tls, pParse, pTab)
		iOld = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += int32(1) + int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
		/* Populate the OLD.* pseudo-table register array. These values will be
		 ** used by any BEFORE and AFTER triggers that exist.  */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), iPk, iOld)
		iCol = 0
		for {
			if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if mask == uint32(0xffffffff) || iCol <= int32(31) && mask&(libc.Uint32FromInt32(1)<<iCol) != uint32(0) {
				kk = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(int16(iCol))))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, iCol, iOld+kk+int32(1))
			}
			goto _2
		_2:
			;
			iCol++
		}
		/* Invoke BEFORE DELETE trigger programs. */
		addrStart = _sqlite3VdbeCurrentAddr(tls, v)
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_DELETE), uintptr(0), int32(TRIGGER_BEFORE), pTab, iOld, int32(int32(onconf)), iLabel)
		/* If any BEFORE triggers were coded, then seek the cursor to the
		 ** row to be deleted again. It may be that the BEFORE triggers moved
		 ** the cursor or already deleted the row that the cursor was
		 ** pointing to.
		 **
		 ** Also disable the iIdxNoSeek optimization since the BEFORE trigger
		 ** may have moved that cursor.
		 */
		if addrStart < _sqlite3VdbeCurrentAddr(tls, v) {
			_sqlite3VdbeAddOp4Int(tls, v, int32(int32(opSeek)), iDataCur, iLabel, iPk, int32(int32(nPk)))
			iIdxNoSeek = -int32(1)
		}
		/* Do FK processing. This call checks that any FK constraints that
		 ** refer to this table (i.e. constraints attached to other tables)
		 ** are not violated by deleting this row.  */
		_sqlite3FkCheck(tls, pParse, pTab, iOld, 0, uintptr(0), 0)
	}
	/* Delete the index and table entries. Skip this step if pTab is really
	 ** a view (in which case the only effect of the DELETE statement is to
	 ** fire the INSTEAD OF triggers).
	 **
	 ** If variable 'count' is non-zero, then this OP_Delete instruction should
	 ** invoke the update-hook. The pre-update-hook, on the other hand should
	 ** be invoked unless table pTab is a system table. The difference is that
	 ** the update-hook is not invoked for rows removed by REPLACE, but the
	 ** pre-update-hook is.
	 */
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) {
		p5 = uint8(0)
		_sqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, uintptr(0), iIdxNoSeek)
		if count != 0 {
			v3 = int32(OPFLAG_NCHANGE)
		} else {
			v3 = 0
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Delete), iDataCur, v3)
		if int32((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 || 0 == Xsqlite3_stricmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+13016) {
			_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
		}
		if int32(int32(eMode)) != ONEPASS_OFF {
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_AUXDELETE))
		}
		if iIdxNoSeek >= 0 && iIdxNoSeek != iDataCur {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iIdxNoSeek)
		}
		if int32(int32(eMode)) == int32(ONEPASS_MULTI) {
			p5 = Tu8(int32(p5) | libc.Int32FromInt32(OPFLAG_SAVEPOSITION))
		}
		_sqlite3VdbeChangeP5(tls, v, uint16(uint16(p5)))
	}
	/* 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 deleted. */
	_sqlite3FkActions(tls, pParse, pTab, uintptr(0), iOld, uintptr(0), 0)
	/* Invoke AFTER DELETE trigger programs. */
	if pTrigger != 0 {
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_DELETE), uintptr(0), int32(TRIGGER_AFTER), pTab, iOld, int32(int32(onconf)), iLabel)
	}
	/* Jump here if the row had already been deleted before any BEFORE
	 ** trigger programs were invoked. Or if a trigger program throws a
	 ** RAISE(IGNORE) exception.  */
	_sqlite3VdbeResolveLabel(tls, v, iLabel)
}

// 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)(unsafe.Pointer(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 + 56))&0x8>>3)) != 0 {
			v3 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		} else {
			v3 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_IdxDelete), iIdxCur+i, r1, v3)
		_sqlite3VdbeChangeP5(tls, v, uint16(1)) /* Cause IdxDelete to error if no entry found */
		_sqlite3ResolvePartIdxLabel(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
		pPrior = pIdx
		goto _2
	_2:
		;
		i++
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
}

// 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)(unsafe.Pointer(piPartIdxLabel)) = _sqlite3VdbeMakeLabel(tls, pParse)
			(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = iDataCur + int32(1)
			_sqlite3ExprIfFalseDup(tls, pParse, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(piPartIdxLabel)) = 0
		}
	}
	if prefixOnly != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x8>>3)) != 0 {
		v1 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
	} else {
		v1 = int32((*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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPrior)).FaiColumn + uintptr(j)*2))) == int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) && int32(*(*Ti16)(unsafe.Pointer((*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)(unsafe.Pointer((*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++
	}
	if regOut != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regBase, nCol, regOut)
	}
	_sqlite3ReleaseTempRange(tls, pParse, regBase, nCol)
	return regBase
}

// C documentation
//
//	/*
//	** If a prior call to sqlite3GenerateIndexKey() generated a jump-over label
//	** because it was a partial index, then this routine should be called to
//	** resolve that label.
//	*/
func _sqlite3ResolvePartIdxLabel(tls *libc.TLS, pParse uintptr, iLabel int32) {
	if iLabel != 0 {
		_sqlite3VdbeResolveLabel(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, iLabel)
	}
}

/************** End of delete.c **********************************************/
/************** Begin file func.c ********************************************/
/*
** 2002 February 23
**
** 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 C-language implementations for many of the SQL
** functions of SQLite.  (Some function, and in particular the date and
** time functions, are implemented separately.)
 */
/* #include "sqliteInt.h" */
/* #include <stdlib.h> */
/* #include <assert.h> */
/* #include <math.h> */
/* #include "vdbeInt.h" */

// C documentation
//
//	/*
//	** Return the collating function associated with a function.
//	*/
func _sqlite3GetFuncCollSeq(tls *libc.TLS, context uintptr) (r uintptr) {
	var pOp uintptr
	_ = pOp
	pOp = (*TVdbe)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(context)).FpVdbe)).FaOp + uintptr((*Tsqlite3_context)(unsafe.Pointer(context)).FiOp-int32(1))*20
	return *(*uintptr)(unsafe.Pointer(pOp + 16))
}

// C documentation
//
//	/*
//	** Indicate that the accumulator load should be skipped on this
//	** iteration of the aggregate loop.
//	*/
func _sqlite3SkipAccumulatorLoad(tls *libc.TLS, context uintptr) {
	(*Tsqlite3_context)(unsafe.Pointer(context)).FisError = -int32(1)
	(*Tsqlite3_context)(unsafe.Pointer(context)).FskipFlag = uint8(1)
}

// C documentation
//
//	/*
//	** Implementation of the non-aggregate min() and max() functions
//	*/
func _minmaxFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i, iBest, mask, v1 int32
	var pColl uintptr
	_, _, _, _, _ = i, iBest, mask, pColl, v1
	if Xsqlite3_user_data(tls, context) == uintptr(0) {
		v1 = 0
	} else {
		v1 = -int32(1)
	}
	mask = v1
	pColl = _sqlite3GetFuncCollSeq(tls, context)
	iBest = 0
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(SQLITE_NULL) {
		return
	}
	i = int32(1)
	for {
		if !(i < argc) {
			break
		}
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))) == int32(SQLITE_NULL) {
			return
		}
		if _sqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(iBest)*4)), *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)), pColl)^mask >= 0 {
			iBest = i
		}
		goto _2
	_2:
		;
		i++
	}
	Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv + uintptr(iBest)*4)))
}

// C documentation
//
//	/*
//	** Return the type of the argument.
//	*/
func _typeofFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var i int32
	_ = i
	i = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) - int32(1)
	_ = NotUsed
	/* EVIDENCE-OF: R-01470-60482 The sqlite3_value_type(V) interface returns
	 ** the datatype code for the initial datatype of the sqlite3_value object
	 ** V. The returned value is one of SQLITE_INTEGER, SQLITE_FLOAT,
	 ** SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL. */
	Xsqlite3_result_text(tls, context, _azType2[i], -int32(1), libc.UintptrFromInt32(0))
}

var _azType2 = [5]uintptr{
	0: __ccgo_ts + 7679,
	1: __ccgo_ts + 7674,
	2: __ccgo_ts + 9631,
	3: __ccgo_ts + 9626,
	4: __ccgo_ts + 1658,
}

// C documentation
//
//	/* subtype(X)
//	**
//	** Return the subtype of X
//	*/
func _subtypeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = argc
	Xsqlite3_result_int(tls, context, int32(Xsqlite3_value_subtype(tls, *(*uintptr)(unsafe.Pointer(argv)))))
}

// C documentation
//
//	/*
//	** Implementation of the length() function
//	*/
func _lengthFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var c, v1 uint8
	var z, z0 uintptr
	_, _, _, _ = c, z, z0, v1
	_ = argc
	switch Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case int32(SQLITE_BLOB):
		fallthrough
	case int32(SQLITE_INTEGER):
		fallthrough
	case int32(SQLITE_FLOAT):
		Xsqlite3_result_int(tls, context, Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
	case int32(SQLITE_TEXT):
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if z == uintptr(0) {
			return
		}
		z0 = z
		for {
			v1 = *(*uint8)(unsafe.Pointer(z))
			c = v1
			if !(int32(v1) != 0) {
				break
			}
			z++
			if int32(int32(c)) >= int32(0xc0) {
				for int32(*(*uint8)(unsafe.Pointer(z)))&int32(0xc0) == int32(0x80) {
					z++
					z0++
				}
			}
		}
		Xsqlite3_result_int(tls, context, int32(int32(z))-int32(int32(z0)))
	default:
		Xsqlite3_result_null(tls, context)
		break
	}
}

// C documentation
//
//	/*
//	** Implementation of the octet_length() function
//	*/
func _bytelengthFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var m Ti64
	var v1 int32
	_, _ = m, v1
	_ = argc
	switch Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case int32(SQLITE_BLOB):
		Xsqlite3_result_int(tls, context, Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
	case int32(SQLITE_INTEGER):
		fallthrough
	case int32(SQLITE_FLOAT):
		if int32((*Tsqlite3)(unsafe.Pointer(Xsqlite3_context_db_handle(tls, context))).Fenc) <= int32(SQLITE_UTF8) {
			v1 = int32(1)
		} else {
			v1 = int32(2)
		}
		m = int64(v1)
		Xsqlite3_result_int64(tls, context, int64(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))*m)
	case int32(SQLITE_TEXT):
		if Xsqlite3_value_encoding(tls, *(*uintptr)(unsafe.Pointer(argv))) <= int32(SQLITE_UTF8) {
			Xsqlite3_result_int(tls, context, Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
		} else {
			Xsqlite3_result_int(tls, context, Xsqlite3_value_bytes16(tls, *(*uintptr)(unsafe.Pointer(argv))))
		}
	default:
		Xsqlite3_result_null(tls, context)
		break
	}
}

// C documentation
//
//	/*
//	** Implementation of the abs() function.
//	**
//	** IMP: R-23979-26855 The abs(X) function returns the absolute value of
//	** the numeric argument X.
//	*/
func _absFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var iVal Ti64
	var rVal float64
	_, _ = iVal, rVal
	_ = argc
	switch Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case int32(SQLITE_INTEGER):
		iVal = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if iVal < 0 {
			if iVal == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
				/* IMP: R-31676-45509 If X is the integer -9223372036854775808
				 ** then abs(X) throws an integer overflow error since there is no
				 ** equivalent positive 64-bit two complement value. */
				Xsqlite3_result_error(tls, context, __ccgo_ts+16629, -int32(1))
				return
			}
			iVal = -iVal
		}
		Xsqlite3_result_int64(tls, context, iVal)
	case int32(SQLITE_NULL):
		/* IMP: R-37434-19929 Abs(X) returns NULL if X is NULL. */
		Xsqlite3_result_null(tls, context)
	default:
		/* Because sqlite3_value_double() returns 0.0 if the argument is not
		 ** something that can be converted into a number, we have:
		 ** IMP: R-01992-00519 Abs(X) returns 0.0 if X is a string or blob
		 ** that cannot be converted to a numeric value.
		 */
		rVal = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if rVal < libc.Float64FromInt32(0) {
			rVal = -rVal
		}
		Xsqlite3_result_double(tls, context, rVal)
		break
	}
}

// C documentation
//
//	/*
//	** Implementation of the instr() function.
//	**
//	** instr(haystack,needle) finds the first occurrence of needle
//	** in haystack and returns the number of previous characters plus 1,
//	** or 0 if needle does not occur within haystack.
//	**
//	** If both haystack and needle are BLOBs, then the result is one more than
//	** the number of bytes in haystack prior to the first occurrence of needle,
//	** or 0 if needle never occurs in haystack.
//	*/
func _instrFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var N, isText, nHaystack, nNeedle, typeHaystack, typeNeedle int32
	var firstChar uint8
	var pC1, pC2, zHaystack, zNeedle uintptr
	_, _, _, _, _, _, _, _, _, _, _ = N, firstChar, isText, nHaystack, nNeedle, pC1, pC2, typeHaystack, typeNeedle, zHaystack, zNeedle
	N = int32(1)
	pC1 = uintptr(0)
	pC2 = uintptr(0)
	_ = argc
	typeHaystack = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	typeNeedle = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	if typeHaystack == int32(SQLITE_NULL) || typeNeedle == int32(SQLITE_NULL) {
		return
	}
	nHaystack = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	nNeedle = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	if nNeedle > 0 {
		if typeHaystack == int32(SQLITE_BLOB) && typeNeedle == int32(SQLITE_BLOB) {
			zHaystack = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
			zNeedle = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
			isText = 0
		} else {
			if typeHaystack != int32(SQLITE_BLOB) && typeNeedle != int32(SQLITE_BLOB) {
				zHaystack = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
				zNeedle = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
				isText = int32(1)
			} else {
				pC1 = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(argv)))
				zHaystack = Xsqlite3_value_text(tls, pC1)
				if zHaystack == uintptr(0) {
					goto endInstrOOM
				}
				nHaystack = Xsqlite3_value_bytes(tls, pC1)
				pC2 = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
				zNeedle = Xsqlite3_value_text(tls, pC2)
				if zNeedle == uintptr(0) {
					goto endInstrOOM
				}
				nNeedle = Xsqlite3_value_bytes(tls, pC2)
				isText = int32(1)
			}
		}
		if zNeedle == uintptr(0) || nHaystack != 0 && zHaystack == uintptr(0) {
			goto endInstrOOM
		}
		firstChar = *(*uint8)(unsafe.Pointer(zNeedle))
		for nNeedle <= nHaystack && (int32(*(*uint8)(unsafe.Pointer(zHaystack))) != int32(int32(firstChar)) || libc.Xmemcmp(tls, zHaystack, zNeedle, uint32(uint32(nNeedle))) != 0) {
			N++
			for cond := true; cond; cond = isText != 0 && int32(*(*uint8)(unsafe.Pointer(zHaystack)))&int32(0xc0) == int32(0x80) {
				nHaystack--
				zHaystack++
			}
		}
		if nNeedle > nHaystack {
			N = 0
		}
	}
	Xsqlite3_result_int(tls, context, N)
	goto endInstr
endInstr:
	;
	Xsqlite3_value_free(tls, pC1)
	Xsqlite3_value_free(tls, pC2)
	return
	goto endInstrOOM
endInstrOOM:
	;
	Xsqlite3_result_error_nomem(tls, context)
	goto endInstr
}

// C documentation
//
//	/*
//	** Implementation of the printf() (a.k.a. format()) SQL function.
//	*/
func _printfFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, zFormat, v1 uintptr
	var n int32
	var v2 bool
	var _ /* str at bp+12 */ TStrAccum
	var _ /* x at bp+0 */ TPrintfArguments
	_, _, _, _, _ = db, n, zFormat, v1, v2
	db = Xsqlite3_context_db_handle(tls, context)
	if v2 = argc >= int32(1); v2 {
		v1 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		zFormat = v1
	}
	if v2 && v1 != uintptr(0) {
		(*(*TPrintfArguments)(unsafe.Pointer(bp))).FnArg = argc - int32(1)
		(*(*TPrintfArguments)(unsafe.Pointer(bp))).FnUsed = 0
		(*(*TPrintfArguments)(unsafe.Pointer(bp))).FapArg = argv + uintptr(1)*4
		_sqlite3StrAccumInit(tls, bp+12, db, uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 120)))
		(*(*TStrAccum)(unsafe.Pointer(bp + 12))).FprintfFlags = uint8(SQLITE_PRINTF_SQLFUNC)
		Xsqlite3_str_appendf(tls, bp+12, zFormat, libc.VaList(bp+48, bp))
		n = int32((*(*TStrAccum)(unsafe.Pointer(bp + 12))).FnChar)
		Xsqlite3_result_text(tls, context, _sqlite3StrAccumFinish(tls, bp+12), n, __ccgo_fp(_sqlite3OomClear))
	}
}

// C documentation
//
//	/*
//	** Implementation of the substr() function.
//	**
//	** substr(x,p1,p2)  returns p2 characters of x[] beginning with p1.
//	** p1 is 1-indexed.  So substr(x,1,1) returns the first character
//	** of x.  If x is text, then we actually count UTF-8 characters.
//	** If x is a blob, then we count bytes.
//	**
//	** If p1 is negative, then we begin abs(p1) from the end of x[].
//	**
//	** If p2 is negative, return the p2 characters preceding p1.
//	*/
func _substrFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var len1, negP2, p0type int32
	var p1, p2 Ti64
	var z, z2, v2, v3, v5 uintptr
	_, _, _, _, _, _, _, _, _, _ = len1, negP2, p0type, p1, p2, z, z2, v2, v3, v5
	negP2 = 0
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))) == int32(SQLITE_NULL) || argc == int32(3) && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))) == int32(SQLITE_NULL) {
		return
	}
	p0type = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	p1 = int64(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))))
	if p0type == int32(SQLITE_BLOB) {
		len1 = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
		z = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if z == uintptr(0) {
			return
		}
	} else {
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if z == uintptr(0) {
			return
		}
		len1 = 0
		if p1 < 0 {
			z2 = z
			for {
				if !(*(*uint8)(unsafe.Pointer(z2)) != 0) {
					break
				}
				v2 = z2
				z2++
				if int32(*(*uint8)(unsafe.Pointer(v2))) >= int32(0xc0) {
					for int32(*(*uint8)(unsafe.Pointer(z2)))&int32(0xc0) == int32(0x80) {
						z2++
					}
				}
				goto _1
			_1:
				;
				len1++
			}
		}
	}
	if argc == int32(3) {
		p2 = int64(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))))
		if p2 < 0 {
			p2 = -p2
			negP2 = int32(1)
		}
	} else {
		p2 = int64(*(*int32)(unsafe.Pointer(Xsqlite3_context_db_handle(tls, context) + 120)))
	}
	if p1 < 0 {
		p1 += int64(int64(len1))
		if p1 < 0 {
			p2 += p1
			if p2 < 0 {
				p2 = 0
			}
			p1 = 0
		}
	} else {
		if p1 > 0 {
			p1--
		} else {
			if p2 > 0 {
				p2--
			}
		}
	}
	if negP2 != 0 {
		p1 -= p2
		if p1 < 0 {
			p2 += p1
			p1 = 0
		}
	}
	if p0type != int32(SQLITE_BLOB) {
		for *(*uint8)(unsafe.Pointer(z)) != 0 && p1 != 0 {
			v3 = z
			z++
			if int32(*(*uint8)(unsafe.Pointer(v3))) >= int32(0xc0) {
				for int32(*(*uint8)(unsafe.Pointer(z)))&int32(0xc0) == int32(0x80) {
					z++
				}
			}
			p1--
		}
		z2 = z
		for {
			if !(*(*uint8)(unsafe.Pointer(z2)) != 0 && p2 != 0) {
				break
			}
			v5 = z2
			z2++
			if int32(*(*uint8)(unsafe.Pointer(v5))) >= int32(0xc0) {
				for int32(*(*uint8)(unsafe.Pointer(z2)))&int32(0xc0) == int32(0x80) {
					z2++
				}
			}
			goto _4
		_4:
			;
			p2--
		}
		Xsqlite3_result_text64(tls, context, z, uint64(int32(int32(z2))-int32(int32(z))), uintptr(-libc.Int32FromInt32(1)), uint8(SQLITE_UTF8))
	} else {
		if p1+p2 > int64(int64(len1)) {
			p2 = int64(int64(len1)) - p1
			if p2 < 0 {
				p2 = 0
			}
		}
		Xsqlite3_result_blob64(tls, context, z+uintptr(p1), uint64(uint64(p2)), uintptr(-libc.Int32FromInt32(1)))
	}
}

// C documentation
//
//	/*
//	** Implementation of the round() function
//	*/
func _roundFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var n int32
	var zBuf uintptr
	var v1 float64
	var _ /* r at bp+0 */ float64
	_, _, _ = n, zBuf, v1
	n = 0
	if argc == int32(2) {
		if int32(SQLITE_NULL) == Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))) {
			return
		}
		n = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		if n > int32(30) {
			n = int32(30)
		}
		if n < 0 {
			n = 0
		}
	}
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(SQLITE_NULL) {
		return
	}
	*(*float64)(unsafe.Pointer(bp)) = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	/* If Y==0 and X will fit in a 64-bit int,
	 ** handle the rounding directly,
	 ** otherwise use printf.
	 */
	if *(*float64)(unsafe.Pointer(bp)) < -libc.Float64FromFloat64(4.503599627370496e+15) || *(*float64)(unsafe.Pointer(bp)) > +libc.Float64FromFloat64(4.503599627370496e+15) {
		/* The value has no fractional part so there is nothing to round */
	} else {
		if n == 0 {
			if *(*float64)(unsafe.Pointer(bp)) < libc.Float64FromInt32(0) {
				v1 = -libc.Float64FromFloat64(0.5)
			} else {
				v1 = +libc.Float64FromFloat64(0.5)
			}
			*(*float64)(unsafe.Pointer(bp)) = float64(int64(*(*float64)(unsafe.Pointer(bp)) + v1))
		} else {
			zBuf = Xsqlite3_mprintf(tls, __ccgo_ts+16646, libc.VaList(bp+16, n, *(*float64)(unsafe.Pointer(bp))))
			if zBuf == uintptr(0) {
				Xsqlite3_result_error_nomem(tls, context)
				return
			}
			_sqlite3AtoF(tls, zBuf, bp, _sqlite3Strlen30(tls, zBuf), uint8(SQLITE_UTF8))
			Xsqlite3_free(tls, zBuf)
		}
	}
	Xsqlite3_result_double(tls, context, *(*float64)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Allocate nByte bytes of space using sqlite3Malloc(). If the
//	** allocation fails, call sqlite3_result_error_nomem() to notify
//	** the database handle that malloc() has failed and return NULL.
//	** If nByte is larger than the maximum string or blob length, then
//	** raise an SQLITE_TOOBIG exception and return NULL.
//	*/
func _contextMalloc(tls *libc.TLS, context uintptr, nByte Ti64) (r uintptr) {
	var db, z uintptr
	_, _ = db, z
	db = Xsqlite3_context_db_handle(tls, context)
	if nByte > int64(*(*int32)(unsafe.Pointer(db + 120))) {
		Xsqlite3_result_error_toobig(tls, context)
		z = uintptr(0)
	} else {
		z = _sqlite3Malloc(tls, uint64(uint64(nByte)))
		if !(z != 0) {
			Xsqlite3_result_error_nomem(tls, context)
		}
	}
	return z
}

// C documentation
//
//	/*
//	** Implementation of the upper() and lower() SQL functions.
//	*/
func _upperFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i, n int32
	var z1, z2 uintptr
	_, _, _, _ = i, n, z1, z2
	_ = argc
	z2 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	/* Verify that the call to _bytes() does not invalidate the _text() pointer */
	if z2 != 0 {
		z1 = _contextMalloc(tls, context, int64(int64(n))+int64(1))
		if z1 != 0 {
			i = 0
			for {
				if !(i < n) {
					break
				}
				*(*int8)(unsafe.Pointer(z1 + uintptr(i))) = int8(int32(*(*int8)(unsafe.Pointer(z2 + uintptr(i)))) & ^(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z2 + uintptr(i))))]) & libc.Int32FromInt32(0x20)))
				goto _1
			_1:
				;
				i++
			}
			Xsqlite3_result_text(tls, context, z1, n, __ccgo_fp(Xsqlite3_free))
		}
	}
}

func _lowerFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i, n int32
	var z1, z2 uintptr
	_, _, _, _ = i, n, z1, z2
	_ = argc
	z2 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	/* Verify that the call to _bytes() does not invalidate the _text() pointer */
	if z2 != 0 {
		z1 = _contextMalloc(tls, context, int64(int64(n))+int64(1))
		if z1 != 0 {
			i = 0
			for {
				if !(i < n) {
					break
				}
				*(*int8)(unsafe.Pointer(z1 + uintptr(i))) = int8(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(z2 + uintptr(i))))])
				goto _1
			_1:
				;
				i++
			}
			Xsqlite3_result_text(tls, context, z1, n, __ccgo_fp(Xsqlite3_free))
		}
	}
}

/*
** Some functions like COALESCE() and IFNULL() and UNLIKELY() are implemented
** as VDBE code so that unused argument values do not have to be computed.
** However, we still need some kind of function implementation for this
** routines in the function table.  The noopFunc macro provides this.
** noopFunc will never be called so it doesn't matter what the implementation
** is.  We might as well use the "version()" function as a substitute.
 */

// C documentation
//
//	/*
//	** Implementation of random().  Return a random integer.
//	*/
func _randomFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* r at bp+0 */ Tsqlite_int64
	_ = NotUsed
	_ = NotUsed2
	Xsqlite3_randomness(tls, int32(8), bp)
	if *(*Tsqlite_int64)(unsafe.Pointer(bp)) < 0 {
		/* We need to prevent a random number of 0x8000000000000000
		 ** (or -9223372036854775808) since when you do abs() of that
		 ** number of you get the same value back again.  To do this
		 ** in a way that is testable, mask the sign bit off of negative
		 ** values, resulting in a positive value.  Then take the
		 ** 2s complement of that positive value.  The end result can
		 ** therefore be no less than -9223372036854775807.
		 */
		*(*Tsqlite_int64)(unsafe.Pointer(bp)) = -(*(*Tsqlite_int64)(unsafe.Pointer(bp)) & (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
	}
	Xsqlite3_result_int64(tls, context, *(*Tsqlite_int64)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Implementation of randomblob(N).  Return a random blob
//	** that is N bytes long.
//	*/
func _randomBlob(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var n Tsqlite3_int64
	var p uintptr
	_, _ = n, p
	_ = argc
	n = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if n < int64(1) {
		n = int64(1)
	}
	p = _contextMalloc(tls, context, n)
	if p != 0 {
		Xsqlite3_randomness(tls, int32(int32(n)), p)
		Xsqlite3_result_blob(tls, context, p, int32(int32(n)), __ccgo_fp(Xsqlite3_free))
	}
}

// C documentation
//
//	/*
//	** Implementation of the last_insert_rowid() SQL function.  The return
//	** value is the same as the sqlite3_last_insert_rowid() API function.
//	*/
func _last_insert_rowid(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	var db uintptr
	_ = db
	db = Xsqlite3_context_db_handle(tls, context)
	_ = NotUsed
	_ = NotUsed2
	/* IMP: R-51513-12026 The last_insert_rowid() SQL function is a
	 ** wrapper around the sqlite3_last_insert_rowid() C/C++ interface
	 ** function. */
	Xsqlite3_result_int64(tls, context, Xsqlite3_last_insert_rowid(tls, db))
}

// C documentation
//
//	/*
//	** Implementation of the changes() SQL function.
//	**
//	** IMP: R-32760-32347 The changes() SQL function is a wrapper
//	** around the sqlite3_changes64() C/C++ function and hence follows the
//	** same rules for counting changes.
//	*/
func _changes(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	var db uintptr
	_ = db
	db = Xsqlite3_context_db_handle(tls, context)
	_ = NotUsed
	_ = NotUsed2
	Xsqlite3_result_int64(tls, context, Xsqlite3_changes64(tls, db))
}

// C documentation
//
//	/*
//	** Implementation of the total_changes() SQL function.  The return value is
//	** the same as the sqlite3_total_changes64() API function.
//	*/
func _total_changes(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	var db uintptr
	_ = db
	db = Xsqlite3_context_db_handle(tls, context)
	_ = NotUsed
	_ = NotUsed2
	/* IMP: R-11217-42568 This function is a wrapper around the
	 ** sqlite3_total_changes64() C/C++ interface. */
	Xsqlite3_result_int64(tls, context, Xsqlite3_total_changes64(tls, db))
}

/*
** A structure defining how to do GLOB-style comparisons.
 */
type TcompareInfo = struct {
	FmatchAll Tu8
	FmatchOne Tu8
	FmatchSet Tu8
	FnoCase   Tu8
}

type compareInfo = TcompareInfo

/*
** For LIKE and GLOB matching on EBCDIC machines, assume that every
** character is exactly one byte in size.  Also, provide the Utf8Read()
** macro for fast reading of the next character in the common case where
** the next character is ASCII.
 */

var _globInfo = TcompareInfo{
	FmatchAll: uint8('*'),
	FmatchOne: uint8('?'),
	FmatchSet: uint8('['),
}

// C documentation
//
//	/* The correct SQL-92 behavior is for the LIKE operator to ignore
//	** case.  Thus  'a' LIKE 'A' would be true. */
var _likeInfoNorm = TcompareInfo{
	FmatchAll: uint8('%'),
	FmatchOne: uint8('_'),
	FnoCase:   uint8(1),
}

// C documentation
//
//	/* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
//	** is case sensitive causing 'a' LIKE 'A' to be false */
var _likeInfoAlt = TcompareInfo{
	FmatchAll: uint8('%'),
	FmatchOne: uint8('_'),
}

/*
** Possible error returns from patternMatch()
 */

// C documentation
//
//	/*
//	** Compare two UTF-8 strings for equality where the first string is
//	** a GLOB or LIKE expression.  Return values:
//	**
//	**    SQLITE_MATCH:            Match
//	**    SQLITE_NOMATCH:          No match
//	**    SQLITE_NOWILDCARDMATCH:  No match in spite of having * or % wildcards.
//	**
//	** Globbing rules:
//	**
//	**      '*'       Matches any sequence of zero or more characters.
//	**
//	**      '?'       Matches exactly one character.
//	**
//	**     [...]      Matches one character from the enclosed list of
//	**                characters.
//	**
//	**     [^...]     Matches one character not in the enclosed list.
//	**
//	** With the [...] and [^...] matching, a ']' character can be included
//	** in the list by making it the first character after '[' or '^'.  A
//	** range of characters can be specified using '-'.  Example:
//	** "[a-z]" matches any single lower-case letter.  To match a '-', make
//	** it the last character in the list.
//	**
//	** Like matching rules:
//	**
//	**      '%'       Matches any sequence of zero or more characters
//	**
//	***     '_'       Matches any one character
//	**
//	**      Ec        Where E is the "esc" character and c is any other
//	**                character, including '%', '_', and esc, match exactly c.
//	**
//	** The comments within this routine usually assume glob matching.
//	**
//	** This routine is usually quick, but can be N**2 in the worst case.
//	*/
func _patternCompare(tls *libc.TLS, _zPattern uintptr, _zString uintptr, pInfo uintptr, matchOther Tu32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _zPattern
	*(*uintptr)(unsafe.Pointer(bp + 4)) = _zString
	var bMatch, bMatch1, bMatch2, invert, seen, v13 int32
	var c, c2, matchAll, matchOne, prior_c, v1, v4, v8 Tu32
	var noCase Tu8
	var zEscaped, v10, v12, v3, v6, v7 uintptr
	var v11, v2, v5, v9 uint32
	var _ /* zStop at bp+9 */ [3]int8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bMatch, bMatch1, bMatch2, c, c2, invert, matchAll, matchOne, noCase, prior_c, seen, zEscaped, v1, v10, v11, v12, v13, v2, v3, v4, v5, v6, v7, v8, v9 /* Next pattern and input string chars */
	matchOne = uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne)                                                                                                                                                              /* "?" or "_" */
	matchAll = uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll)                                                                                                                                                              /* "*" or "%" */
	noCase = (*TcompareInfo)(unsafe.Pointer(pInfo)).FnoCase                                                                                                                                                                          /* True if uppercase==lowercase */
	zEscaped = uintptr(0)                                                                                                                                                                                                            /* One past the last escaped input char */
	for {
		if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < int32(0x80) {
			v3 = *(*uintptr)(unsafe.Pointer(bp))
			*(*uintptr)(unsafe.Pointer(bp))++
			v2 = uint32(*(*Tu8)(unsafe.Pointer(v3)))
		} else {
			v2 = _sqlite3Utf8Read(tls, bp)
		}
		v1 = v2
		c = v1
		if !(v1 != uint32(0)) {
			break
		}
		if c == matchAll { /* Match "*" */
			/* Skip over multiple "*" characters in the pattern.  If there
			 ** are also "?" characters, skip those as well, but consume a
			 ** single character of the input string for each "?" skipped */
			for {
				if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < int32(0x80) {
					v6 = *(*uintptr)(unsafe.Pointer(bp))
					*(*uintptr)(unsafe.Pointer(bp))++
					v5 = uint32(*(*Tu8)(unsafe.Pointer(v6)))
				} else {
					v5 = _sqlite3Utf8Read(tls, bp)
				}
				v4 = v5
				c = v4
				if !(v4 == matchAll || c == matchOne && matchOne != uint32(0)) {
					break
				}
				if c == matchOne && _sqlite3Utf8Read(tls, bp+4) == uint32(0) {
					return int32(SQLITE_NOWILDCARDMATCH)
				}
			}
			if c == uint32(0) {
				return SQLITE_MATCH /* "*" at the end of the pattern matches */
			} else {
				if c == matchOther {
					if int32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchSet) == 0 {
						c = _sqlite3Utf8Read(tls, bp)
						if c == uint32(0) {
							return int32(SQLITE_NOWILDCARDMATCH)
						}
					} else {
						/* "[...]" immediately follows the "*".  We have to do a slow
						 ** recursive search in this case, but it is an unusual case. */
						/* '[' is a single-byte character */
						for *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))) != 0 {
							bMatch = _patternCompare(tls, *(*uintptr)(unsafe.Pointer(bp))+uintptr(-libc.Int32FromInt32(1)), *(*uintptr)(unsafe.Pointer(bp + 4)), pInfo, matchOther)
							if bMatch != int32(SQLITE_NOMATCH) {
								return bMatch
							}
							v7 = *(*uintptr)(unsafe.Pointer(bp + 4))
							*(*uintptr)(unsafe.Pointer(bp + 4))++
							if int32(*(*Tu8)(unsafe.Pointer(v7))) >= int32(0xc0) {
								for int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))))&int32(0xc0) == int32(0x80) {
									*(*uintptr)(unsafe.Pointer(bp + 4))++
								}
							}
						}
						return int32(SQLITE_NOWILDCARDMATCH)
					}
				}
			}
			/* At this point variable c contains the first character of the
			 ** pattern string past the "*".  Search in the input string for the
			 ** first matching character and recursively continue the match from
			 ** that point.
			 **
			 ** For a case-insensitive search, set variable cx to be the same as
			 ** c but in the other case and search the input string for either
			 ** c or cx.
			 */
			if c < uint32(0x80) {
				if noCase != 0 {
					(*(*[3]int8)(unsafe.Pointer(bp + 9)))[0] = int8(c & uint32(^(int32(_sqlite3CtypeMap[uint8(c)]) & libc.Int32FromInt32(0x20))))
					(*(*[3]int8)(unsafe.Pointer(bp + 9)))[int32(1)] = int8(_sqlite3UpperToLower[uint8(c)])
					(*(*[3]int8)(unsafe.Pointer(bp + 9)))[int32(2)] = 0
				} else {
					(*(*[3]int8)(unsafe.Pointer(bp + 9)))[0] = int8(int8(c))
					(*(*[3]int8)(unsafe.Pointer(bp + 9)))[int32(1)] = 0
				}
				for int32(1) != 0 {
					*(*uintptr)(unsafe.Pointer(bp + 4)) += uintptr(libc.Xstrcspn(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), bp+9))
					if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4))))) == 0 {
						break
					}
					*(*uintptr)(unsafe.Pointer(bp + 4))++
					bMatch1 = _patternCompare(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 4)), pInfo, matchOther)
					if bMatch1 != int32(SQLITE_NOMATCH) {
						return bMatch1
					}
				}
			} else {
				for {
					if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4))))) < int32(0x80) {
						v10 = *(*uintptr)(unsafe.Pointer(bp + 4))
						*(*uintptr)(unsafe.Pointer(bp + 4))++
						v9 = uint32(*(*Tu8)(unsafe.Pointer(v10)))
					} else {
						v9 = _sqlite3Utf8Read(tls, bp+4)
					}
					v8 = v9
					c2 = v8
					if !(v8 != uint32(0)) {
						break
					}
					if c2 != c {
						continue
					}
					bMatch2 = _patternCompare(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 4)), pInfo, matchOther)
					if bMatch2 != int32(SQLITE_NOMATCH) {
						return bMatch2
					}
				}
			}
			return int32(SQLITE_NOWILDCARDMATCH)
		}
		if c == matchOther {
			if int32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchSet) == 0 {
				c = _sqlite3Utf8Read(tls, bp)
				if c == uint32(0) {
					return int32(SQLITE_NOMATCH)
				}
				zEscaped = *(*uintptr)(unsafe.Pointer(bp))
			} else {
				prior_c = uint32(0)
				seen = 0
				invert = 0
				c = _sqlite3Utf8Read(tls, bp+4)
				if c == uint32(0) {
					return int32(SQLITE_NOMATCH)
				}
				c2 = _sqlite3Utf8Read(tls, bp)
				if c2 == uint32('^') {
					invert = int32(1)
					c2 = _sqlite3Utf8Read(tls, bp)
				}
				if c2 == uint32(']') {
					if c == uint32(']') {
						seen = int32(1)
					}
					c2 = _sqlite3Utf8Read(tls, bp)
				}
				for c2 != 0 && c2 != uint32(']') {
					if c2 == uint32('-') && int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != int32(']') && int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != 0 && prior_c > uint32(0) {
						c2 = _sqlite3Utf8Read(tls, bp)
						if c >= prior_c && c <= c2 {
							seen = int32(1)
						}
						prior_c = uint32(0)
					} else {
						if c == c2 {
							seen = int32(1)
						}
						prior_c = c2
					}
					c2 = _sqlite3Utf8Read(tls, bp)
				}
				if c2 == uint32(0) || seen^invert == 0 {
					return int32(SQLITE_NOMATCH)
				}
				continue
			}
		}
		if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4))))) < int32(0x80) {
			v12 = *(*uintptr)(unsafe.Pointer(bp + 4))
			*(*uintptr)(unsafe.Pointer(bp + 4))++
			v11 = uint32(*(*Tu8)(unsafe.Pointer(v12)))
		} else {
			v11 = _sqlite3Utf8Read(tls, bp+4)
		}
		c2 = v11
		if c == c2 {
			continue
		}
		if noCase != 0 && int32(_sqlite3UpperToLower[uint8(c)]) == int32(_sqlite3UpperToLower[uint8(c2)]) && c < uint32(0x80) && c2 < uint32(0x80) {
			continue
		}
		if c == matchOne && *(*uintptr)(unsafe.Pointer(bp)) != zEscaped && c2 != uint32(0) {
			continue
		}
		return int32(SQLITE_NOMATCH)
	}
	if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4))))) == 0 {
		v13 = SQLITE_MATCH
	} else {
		v13 = int32(SQLITE_NOMATCH)
	}
	return v13
}

// C documentation
//
//	/*
//	** The sqlite3_strglob() interface.  Return 0 on a match (like strcmp()) and
//	** non-zero if there is no match.
//	*/
func Xsqlite3_strglob(tls *libc.TLS, zGlobPattern uintptr, zString uintptr) (r int32) {
	if zString == uintptr(0) {
		return libc.BoolInt32(zGlobPattern != uintptr(0))
	} else {
		if zGlobPattern == uintptr(0) {
			return int32(1)
		} else {
			return _patternCompare(tls, zGlobPattern, zString, uintptr(unsafe.Pointer(&_globInfo)), uint32('['))
		}
	}
	return r
}

// C documentation
//
//	/*
//	** The sqlite3_strlike() interface.  Return 0 on a match and non-zero for
//	** a miss - like strcmp().
//	*/
func Xsqlite3_strlike(tls *libc.TLS, zPattern uintptr, zStr uintptr, esc uint32) (r int32) {
	if zStr == uintptr(0) {
		return libc.BoolInt32(zPattern != uintptr(0))
	} else {
		if zPattern == uintptr(0) {
			return int32(1)
		} else {
			return _patternCompare(tls, zPattern, zStr, uintptr(unsafe.Pointer(&_likeInfoNorm)), esc)
		}
	}
	return r
}

/*
** Count the number of times that the LIKE operator (or GLOB which is
** just a variation of LIKE) gets called.  This is used for testing
** only.
 */

// C documentation
//
//	/*
//	** Implementation of the like() SQL function.  This function implements
//	** the built-in LIKE operator.  The first argument to the function is the
//	** pattern and the second argument is the string.  So, the SQL statements:
//	**
//	**       A LIKE B
//	**
//	** is implemented as like(B,A).
//	**
//	** This same function (with a different compareInfo structure) computes
//	** the GLOB operator.
//	*/
func _likeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pInfo, zA, zB uintptr
	var escape Tu32
	var nPat int32
	var _ /* backupInfo at bp+0 */ TcompareInfo
	var _ /* zEsc at bp+4 */ uintptr
	_, _, _, _, _, _ = db, escape, nPat, pInfo, zA, zB
	db = Xsqlite3_context_db_handle(tls, context)
	pInfo = Xsqlite3_user_data(tls, context)
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(SQLITE_BLOB) || Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))) == int32(SQLITE_BLOB) {
		Xsqlite3_result_int(tls, context, 0)
		return
	}
	/* Limit the length of the LIKE or GLOB pattern to avoid problems
	 ** of deep recursion and N*N behavior in patternCompare().
	 */
	nPat = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if nPat > *(*int32)(unsafe.Pointer(db + 120 + 8*4)) {
		Xsqlite3_result_error(tls, context, __ccgo_ts+16652, -int32(1))
		return
	}
	if argc == int32(3) {
		/* The escape character string must consist of a single UTF-8 character.
		 ** Otherwise, return an error.
		 */
		*(*uintptr)(unsafe.Pointer(bp + 4)) = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4)))
		if *(*uintptr)(unsafe.Pointer(bp + 4)) == uintptr(0) {
			return
		}
		if _sqlite3Utf8CharLen(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), -int32(1)) != int32(1) {
			Xsqlite3_result_error(tls, context, __ccgo_ts+16685, -int32(1))
			return
		}
		escape = _sqlite3Utf8Read(tls, bp+4)
		if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll) || escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
			libc.Xmemcpy(tls, bp, pInfo, uint32(4))
			pInfo = bp
			if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll) {
				(*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll = uint8(0)
			}
			if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
				(*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne = uint8(0)
			}
		}
	} else {
		escape = uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchSet)
	}
	zB = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zA = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	if zA != 0 && zB != 0 {
		Xsqlite3_result_int(tls, context, libc.BoolInt32(_patternCompare(tls, zB, zA, pInfo, escape) == SQLITE_MATCH))
	}
}

// C documentation
//
//	/*
//	** Implementation of the NULLIF(x,y) function.  The result is the first
//	** argument if the arguments are different.  The result is NULL if the
//	** arguments are equal to each other.
//	*/
func _nullifFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var pColl uintptr
	_ = pColl
	pColl = _sqlite3GetFuncCollSeq(tls, context)
	_ = NotUsed
	if _sqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*4)), pColl) != 0 {
		Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv)))
	}
}

// C documentation
//
//	/*
//	** Implementation of the sqlite_version() function.  The result is the version
//	** of the SQLite library that is running.
//	*/
func _versionFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	/* IMP: R-48699-48617 This function is an SQL wrapper around the
	 ** sqlite3_libversion() C-interface. */
	Xsqlite3_result_text(tls, context, Xsqlite3_libversion(tls), -int32(1), libc.UintptrFromInt32(0))
}

// C documentation
//
//	/*
//	** Implementation of the sqlite_source_id() function. The result is a string
//	** that identifies the particular version of the source code used to build
//	** SQLite.
//	*/
func _sourceidFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	/* IMP: R-24470-31136 This function is an SQL wrapper around the
	 ** sqlite3_sourceid() C interface. */
	Xsqlite3_result_text(tls, context, Xsqlite3_sourceid(tls), -int32(1), libc.UintptrFromInt32(0))
}

// C documentation
//
//	/*
//	** Implementation of the sqlite_log() function.  This is a wrapper around
//	** sqlite3_log().  The return value is NULL.  The function exists purely for
//	** its side-effects.
//	*/
func _errlogFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_ = argc
	_ = context
	Xsqlite3_log(tls, Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv))), __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))))
}

// C documentation
//
//	/*
//	** Implementation of the sqlite_compileoption_used() function.
//	** The result is an integer that identifies if the compiler option
//	** was used to build SQLite.
//	*/
func _compileoptionusedFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var zOptName, v1 uintptr
	_, _ = zOptName, v1
	_ = argc
	/* IMP: R-39564-36305 The sqlite_compileoption_used() SQL
	 ** function is a wrapper around the sqlite3_compileoption_used() C/C++
	 ** function.
	 */
	v1 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zOptName = v1
	if v1 != uintptr(0) {
		Xsqlite3_result_int(tls, context, Xsqlite3_compileoption_used(tls, zOptName))
	}
}

// C documentation
//
//	/*
//	** Implementation of the sqlite_compileoption_get() function.
//	** The result is a string that identifies the compiler options
//	** used to build SQLite.
//	*/
func _compileoptiongetFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var n int32
	_ = n
	_ = argc
	/* IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
	 ** is a wrapper around the sqlite3_compileoption_get() C/C++ function.
	 */
	n = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv)))
	Xsqlite3_result_text(tls, context, Xsqlite3_compileoption_get(tls, n), -int32(1), libc.UintptrFromInt32(0))
}

// C documentation
//
//	/* Array for converting from half-bytes (nybbles) into ASCII hex
//	** digits. */
var _hexdigits = [16]int8{
	0:  int8('0'),
	1:  int8('1'),
	2:  int8('2'),
	3:  int8('3'),
	4:  int8('4'),
	5:  int8('5'),
	6:  int8('6'),
	7:  int8('7'),
	8:  int8('8'),
	9:  int8('9'),
	10: int8('A'),
	11: int8('B'),
	12: int8('C'),
	13: int8('D'),
	14: int8('E'),
	15: int8('F'),
}

// C documentation
//
//	/*
//	** Append to pStr text that is the SQL literal representation of the
//	** value contained in pValue.
//	*/
func _sqlite3QuoteValue(tls *libc.TLS, pStr uintptr, pValue uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var nBlob Ti64
	var r1 float64
	var zArg, zBlob, zText, zVal uintptr
	var _ /* r2 at bp+0 */ float64
	_, _, _, _, _, _, _ = i, nBlob, r1, zArg, zBlob, zText, zVal
	/* As currently implemented, the string must be initially empty.
	 ** we might relax this requirement in the future, but that will
	 ** require enhancements to the implementation. */
	switch Xsqlite3_value_type(tls, pValue) {
	case int32(SQLITE_FLOAT):
		r1 = Xsqlite3_value_double(tls, pValue)
		Xsqlite3_str_appendf(tls, pStr, __ccgo_ts+16730, libc.VaList(bp+16, r1))
		zVal = Xsqlite3_str_value(tls, pStr)
		if zVal != 0 {
			_sqlite3AtoF(tls, zVal, bp, int32((*TStrAccum)(unsafe.Pointer(pStr)).FnChar), uint8(SQLITE_UTF8))
			if r1 != *(*float64)(unsafe.Pointer(bp)) {
				Xsqlite3_str_reset(tls, pStr)
				Xsqlite3_str_appendf(tls, pStr, __ccgo_ts+16738, libc.VaList(bp+16, r1))
			}
		}
	case int32(SQLITE_INTEGER):
		Xsqlite3_str_appendf(tls, pStr, __ccgo_ts+1433, libc.VaList(bp+16, Xsqlite3_value_int64(tls, pValue)))
	case int32(SQLITE_BLOB):
		zBlob = Xsqlite3_value_blob(tls, pValue)
		nBlob = int64(Xsqlite3_value_bytes(tls, pValue))
		/* No encoding change */
		_sqlite3StrAccumEnlarge(tls, pStr, nBlob*int64(2)+int64(4))
		if int32((*TStrAccum)(unsafe.Pointer(pStr)).FaccError) == 0 {
			zText = (*TStrAccum)(unsafe.Pointer(pStr)).FzText
			i = 0
			for {
				if !(int64(int64(i)) < nBlob) {
					break
				}
				*(*int8)(unsafe.Pointer(zText + uintptr(i*int32(2)+int32(2)))) = _hexdigits[int32(*(*int8)(unsafe.Pointer(zBlob + uintptr(i))))>>int32(4)&int32(0x0F)]
				*(*int8)(unsafe.Pointer(zText + uintptr(i*int32(2)+int32(3)))) = _hexdigits[int32(*(*int8)(unsafe.Pointer(zBlob + uintptr(i))))&int32(0x0F)]
				goto _1
			_1:
				;
				i++
			}
			*(*int8)(unsafe.Pointer(zText + uintptr(nBlob*int64(2)+int64(2)))) = int8('\'')
			*(*int8)(unsafe.Pointer(zText + uintptr(nBlob*int64(2)+int64(3)))) = int8('\000')
			*(*int8)(unsafe.Pointer(zText)) = int8('X')
			*(*int8)(unsafe.Pointer(zText + 1)) = int8('\'')
			(*TStrAccum)(unsafe.Pointer(pStr)).FnChar = uint32(nBlob*int64(2) + int64(3))
		}
	case int32(SQLITE_TEXT):
		zArg = Xsqlite3_value_text(tls, pValue)
		Xsqlite3_str_appendf(tls, pStr, __ccgo_ts+16746, libc.VaList(bp+16, zArg))
	default:
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+1673, int32(4))
		break
	}
}

// C documentation
//
//	/*
//	** Implementation of the QUOTE() function.
//	**
//	** The quote(X) function returns the text of an SQL literal which is the
//	** value of its argument suitable for inclusion into an SQL statement.
//	** Strings are surrounded by single-quotes with escapes on interior quotes
//	** as needed. BLOBs are encoded as hexadecimal literals. Strings with
//	** embedded NUL characters cannot be represented as string literals in SQL
//	** and hence the returned string literal is truncated prior to the first NUL.
//	*/
func _quoteFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db uintptr
	var _ /* str at bp+0 */ Tsqlite3_str
	_ = db
	db = Xsqlite3_context_db_handle(tls, context)
	_ = argc
	_sqlite3StrAccumInit(tls, bp, db, uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 120)))
	_sqlite3QuoteValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv)))
	Xsqlite3_result_text(tls, context, _sqlite3StrAccumFinish(tls, bp), int32((*(*Tsqlite3_str)(unsafe.Pointer(bp))).FnChar), __ccgo_fp(_sqlite3OomClear))
	if int32((*(*Tsqlite3_str)(unsafe.Pointer(bp))).FaccError) != SQLITE_OK {
		Xsqlite3_result_null(tls, context)
		Xsqlite3_result_error_code(tls, context, int32((*(*Tsqlite3_str)(unsafe.Pointer(bp))).FaccError))
	}
}

// C documentation
//
//	/*
//	** The unicode() function.  Return the integer unicode code-point value
//	** for the first character of the input string.
//	*/
func _unicodeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* z at bp+0 */ uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	_ = argc
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 && *(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) != 0 {
		Xsqlite3_result_int(tls, context, int32(_sqlite3Utf8Read(tls, bp)))
	}
}

// C documentation
//
//	/*
//	** The char() function takes zero or more arguments, each of which is
//	** an integer.  It constructs a string where each character of the string
//	** is the unicode character for the corresponding integer argument.
//	*/
func _charFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var c uint32
	var i int32
	var x Tsqlite3_int64
	var z, zOut, v1, v10, v11, v12, v3, v4, v5, v6, v7, v8, v9 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, i, x, z, zOut, v1, v10, v11, v12, v3, v4, v5, v6, v7, v8, v9
	v1 = Xsqlite3_malloc64(tls, uint64(argc*int32(4)+int32(1)))
	z = v1
	zOut = v1
	if z == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
		return
	}
	i = 0
	for {
		if !(i < argc) {
			break
		}
		x = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		if x < 0 || x > int64(0x10ffff) {
			x = int64(0xfffd)
		}
		c = uint32(x & libc.Int64FromInt32(0x1fffff))
		if c < uint32(0x00080) {
			v3 = zOut
			zOut++
			*(*uint8)(unsafe.Pointer(v3)) = uint8(c & libc.Uint32FromInt32(0xFF))
		} else {
			if c < uint32(0x00800) {
				v4 = zOut
				zOut++
				*(*uint8)(unsafe.Pointer(v4)) = uint8(int32(0xC0) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
				v5 = zOut
				zOut++
				*(*uint8)(unsafe.Pointer(v5)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
			} else {
				if c < uint32(0x10000) {
					v6 = zOut
					zOut++
					*(*uint8)(unsafe.Pointer(v6)) = uint8(int32(0xE0) + int32(uint8(c>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
					v7 = zOut
					zOut++
					*(*uint8)(unsafe.Pointer(v7)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v8 = zOut
					zOut++
					*(*uint8)(unsafe.Pointer(v8)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
				} else {
					v9 = zOut
					zOut++
					*(*uint8)(unsafe.Pointer(v9)) = uint8(int32(0xF0) + int32(uint8(c>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
					v10 = zOut
					zOut++
					*(*uint8)(unsafe.Pointer(v10)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
					v11 = zOut
					zOut++
					*(*uint8)(unsafe.Pointer(v11)) = uint8(int32(0x80) + int32(uint8(c>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v12 = zOut
					zOut++
					*(*uint8)(unsafe.Pointer(v12)) = uint8(int32(0x80) + int32(uint8(c&libc.Uint32FromInt32(0x3F))))
				}
			}
		}
		goto _2
	_2:
		;
		i++
	}
	*(*uint8)(unsafe.Pointer(zOut)) = uint8(0)
	Xsqlite3_result_text64(tls, context, z, uint64(int32(int32(zOut))-int32(int32(z))), __ccgo_fp(Xsqlite3_free), uint8(SQLITE_UTF8))
}

// C documentation
//
//	/*
//	** The hex() function.  Interpret the argument as a blob.  Return
//	** a hexadecimal rendering as text.
//	*/
func _hexFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var c uint8
	var i, n int32
	var pBlob, z, zHex, v1, v3, v4 uintptr
	_, _, _, _, _, _, _, _, _ = c, i, n, pBlob, z, zHex, v1, v3, v4
	_ = argc
	pBlob = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	/* No encoding change */
	v1 = _contextMalloc(tls, context, int64(int64(n))*int64(2)+int64(1))
	zHex = v1
	z = v1
	if zHex != 0 {
		i = 0
		for {
			if !(i < n) {
				break
			}
			c = *(*uint8)(unsafe.Pointer(pBlob))
			v3 = z
			z++
			*(*int8)(unsafe.Pointer(v3)) = _hexdigits[int32(int32(c))>>int32(4)&int32(0xf)]
			v4 = z
			z++
			*(*int8)(unsafe.Pointer(v4)) = _hexdigits[int32(int32(c))&int32(0xf)]
			goto _2
		_2:
			;
			i++
			pBlob++
		}
		*(*int8)(unsafe.Pointer(z)) = 0
		Xsqlite3_result_text64(tls, context, zHex, uint64(int32(int32(z))-int32(int32(zHex))), __ccgo_fp(Xsqlite3_free), uint8(SQLITE_UTF8))
	}
}

// C documentation
//
//	/*
//	** Buffer zStr contains nStr bytes of utf-8 encoded text. Return 1 if zStr
//	** contains character ch, or 0 if it does not.
//	*/
func _strContainsChar(tls *libc.TLS, zStr uintptr, nStr int32, ch Tu32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var tst Tu32
	var zEnd, v2 uintptr
	var v1 uint32
	var _ /* z at bp+0 */ uintptr
	_, _, _, _ = tst, zEnd, v1, v2
	zEnd = zStr + uintptr(nStr)
	*(*uintptr)(unsafe.Pointer(bp)) = zStr
	for *(*uintptr)(unsafe.Pointer(bp)) < zEnd {
		if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < int32(0x80) {
			v2 = *(*uintptr)(unsafe.Pointer(bp))
			*(*uintptr)(unsafe.Pointer(bp))++
			v1 = uint32(*(*Tu8)(unsafe.Pointer(v2)))
		} else {
			v1 = _sqlite3Utf8Read(tls, bp)
		}
		tst = v1
		if tst == ch {
			return int32(1)
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** The unhex() function. This function may be invoked with either one or
//	** two arguments. In both cases the first argument is interpreted as text
//	** a text value containing a set of pairs of hexadecimal digits which are
//	** decoded and returned as a blob.
//	**
//	** If there is only a single argument, then it must consist only of an
//	** even number of hexadecimal digits. Otherwise, return NULL.
//	**
//	** Or, if there is a second argument, then any character that appears in
//	** the second argument is also allowed to appear between pairs of hexadecimal
//	** digits in the first argument. If any other character appears in the
//	** first argument, or if one of the allowed characters appears between
//	** two hexadecimal digits that make up a single byte, NULL is returned.
//	**
//	** The following expressions are all true:
//	**
//	**     unhex('ABCD')       IS x'ABCD'
//	**     unhex('AB CD')      IS NULL
//	**     unhex('AB CD', ' ') IS x'ABCD'
//	**     unhex('A BCD', ' ') IS NULL
//	*/
func _unhexFunc(tls *libc.TLS, pCtx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c, d, v2 Tu8
	var ch Tu32
	var nHex, nPass int32
	var p, pBlob, zPass, v1, v4, v5, v6 uintptr
	var v3 uint32
	var _ /* zHex at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, ch, d, nHex, nPass, p, pBlob, zPass, v1, v2, v3, v4, v5, v6
	zPass = __ccgo_ts + 1672
	nPass = 0
	*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	nHex = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	pBlob = uintptr(0)
	p = uintptr(0)
	if argc == int32(2) {
		zPass = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		nPass = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	}
	if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) || !(zPass != 0) {
		return
	}
	v1 = _contextMalloc(tls, pCtx, int64(nHex/int32(2)+int32(1)))
	pBlob = v1
	p = v1
	if pBlob != 0 { /* Least significant digit of next byte */
		for {
			v2 = *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))
			c = v2
			if !(int32(v2) != 0x00) {
				break
			}
			for !(int32(_sqlite3CtypeMap[c])&libc.Int32FromInt32(0x08) != 0) {
				if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < int32(0x80) {
					v4 = *(*uintptr)(unsafe.Pointer(bp))
					*(*uintptr)(unsafe.Pointer(bp))++
					v3 = uint32(*(*Tu8)(unsafe.Pointer(v4)))
				} else {
					v3 = _sqlite3Utf8Read(tls, bp)
				}
				ch = v3
				if !(_strContainsChar(tls, zPass, nPass, ch) != 0) {
					goto unhex_null
				}
				c = *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))
				if int32(int32(c)) == 0x00 {
					goto unhex_done
				}
			}
			*(*uintptr)(unsafe.Pointer(bp))++
			v5 = *(*uintptr)(unsafe.Pointer(bp))
			*(*uintptr)(unsafe.Pointer(bp))++
			d = *(*Tu8)(unsafe.Pointer(v5))
			if !(int32(_sqlite3CtypeMap[d])&libc.Int32FromInt32(0x08) != 0) {
				goto unhex_null
			}
			v6 = p
			p++
			*(*Tu8)(unsafe.Pointer(v6)) = uint8(int32(_sqlite3HexToInt(tls, int32(int32(c))))<<int32(4) | int32(_sqlite3HexToInt(tls, int32(int32(d)))))
		}
	}
	goto unhex_done
unhex_done:
	;
	Xsqlite3_result_blob(tls, pCtx, pBlob, int32(int32(p))-int32(int32(pBlob)), __ccgo_fp(Xsqlite3_free))
	return
	goto unhex_null
unhex_null:
	;
	Xsqlite3_free(tls, pBlob)
	return
}

// C documentation
//
//	/*
//	** The zeroblob(N) function returns a zero-filled blob of size N bytes.
//	*/
func _zeroblobFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var n Ti64
	var rc int32
	_, _ = n, rc
	_ = argc
	n = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if n < 0 {
		n = 0
	}
	rc = Xsqlite3_result_zeroblob64(tls, context, uint64(uint64(n))) /* IMP: R-00293-64994 */
	if rc != 0 {
		Xsqlite3_result_error_code(tls, context, rc)
	}
}

// C documentation
//
//	/*
//	** The replace() function.  Three arguments are all strings: call
//	** them A, B, and C. The result is also a string which is derived
//	** from A by replacing every occurrence of B with C.  The match
//	** must be exact.  Collating sequences are not used.
//	*/
func _replaceFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var cntExpand uint32
	var db, zOld, zOut, zPattern, zRep, zStr uintptr
	var i, j, loopLimit, nPattern, nRep, nStr, v2, v3 int32
	var nOut Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cntExpand, db, i, j, loopLimit, nOut, nPattern, nRep, nStr, zOld, zOut, zPattern, zRep, zStr, v2, v3 /* Number zOut expansions */
	db = Xsqlite3_context_db_handle(tls, context)
	_ = argc
	zStr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zStr == uintptr(0) {
		return
	}
	nStr = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	/* No encoding change */
	zPattern = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	if zPattern == uintptr(0) {
		return
	}
	if int32(*(*uint8)(unsafe.Pointer(zPattern))) == 0 {
		Xsqlite3_result_text(tls, context, zStr, nStr, uintptr(-libc.Int32FromInt32(1)))
		return
	}
	nPattern = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	/* No encoding change */
	zRep = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4)))
	if zRep == uintptr(0) {
		return
	}
	nRep = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4)))
	nOut = int64(nStr + int32(1))
	zOut = _contextMalloc(tls, context, nOut)
	if zOut == uintptr(0) {
		return
	}
	loopLimit = nStr - nPattern
	cntExpand = uint32(0)
	v2 = libc.Int32FromInt32(0)
	j = v2
	i = v2
	for {
		if !(i <= loopLimit) {
			break
		}
		if int32(*(*uint8)(unsafe.Pointer(zStr + uintptr(i)))) != int32(*(*uint8)(unsafe.Pointer(zPattern))) || libc.Xmemcmp(tls, zStr+uintptr(i), zPattern, uint32(uint32(nPattern))) != 0 {
			v3 = j
			j++
			*(*uint8)(unsafe.Pointer(zOut + uintptr(v3))) = *(*uint8)(unsafe.Pointer(zStr + uintptr(i)))
		} else {
			if nRep > nPattern {
				nOut += int64(nRep - nPattern)
				if nOut-int64(1) > int64(*(*int32)(unsafe.Pointer(db + 120))) {
					Xsqlite3_result_error_toobig(tls, context)
					Xsqlite3_free(tls, zOut)
					return
				}
				cntExpand++
				if cntExpand&(cntExpand-uint32(1)) == uint32(0) {
					zOld = zOut
					zOut = _sqlite3Realloc(tls, zOut, uint64(int64(int32(int32(nOut)))+(nOut-int64(int64(nStr))-int64(1))))
					if zOut == uintptr(0) {
						Xsqlite3_result_error_nomem(tls, context)
						Xsqlite3_free(tls, zOld)
						return
					}
				}
			}
			libc.Xmemcpy(tls, zOut+uintptr(j), zRep, uint32(uint32(nRep)))
			j += nRep
			i += nPattern - int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	libc.Xmemcpy(tls, zOut+uintptr(j), zStr+uintptr(i), uint32(nStr-i))
	j += nStr - i
	*(*uint8)(unsafe.Pointer(zOut + uintptr(j))) = uint8(0)
	Xsqlite3_result_text(tls, context, zOut, j, __ccgo_fp(Xsqlite3_free))
}

// C documentation
//
//	/*
//	** Implementation of the TRIM(), LTRIM(), and RTRIM() functions.
//	** The userdata is 0x1 for left trim, 0x2 for right trim, 0x3 for both.
//	*/
func _trimFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var aLen, azChar, z, zCharSet, zIn, v1, v3, v5 uintptr
	var flags, i, nChar int32
	var len1, len11, nIn uint32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aLen, azChar, flags, i, len1, len11, nChar, nIn, z, zCharSet, zIn, v1, v3, v5 /* Loop counter */
	aLen = uintptr(0)                                                                                                        /* Length of each character in zCharSet */
	azChar = uintptr(0)                                                                                                      /* Number of characters in zCharSet */
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(SQLITE_NULL) {
		return
	}
	zIn = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zIn == uintptr(0) {
		return
	}
	nIn = uint32(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
	if argc == int32(1) {
		nChar = int32(1)
		aLen = uintptr(unsafe.Pointer(&_lenOne))
		azChar = uintptr(unsafe.Pointer(&_azOne))
		zCharSet = uintptr(0)
	} else {
		v1 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		zCharSet = v1
		if v1 == uintptr(0) {
			return
		} else {
			z = zCharSet
			nChar = libc.Int32FromInt32(0)
			for {
				if !(*(*uint8)(unsafe.Pointer(z)) != 0) {
					break
				}
				v3 = z
				z++
				if int32(*(*uint8)(unsafe.Pointer(v3))) >= int32(0xc0) {
					for int32(*(*uint8)(unsafe.Pointer(z)))&int32(0xc0) == int32(0x80) {
						z++
					}
				}
				goto _2
			_2:
				;
				nChar++
			}
			if nChar > 0 {
				azChar = _contextMalloc(tls, context, int64(int64(nChar))*int64(libc.Uint32FromInt64(4)+libc.Uint32FromInt64(4)))
				if azChar == uintptr(0) {
					return
				}
				aLen = azChar + uintptr(nChar)*4
				z = zCharSet
				nChar = libc.Int32FromInt32(0)
				for {
					if !(*(*uint8)(unsafe.Pointer(z)) != 0) {
						break
					}
					*(*uintptr)(unsafe.Pointer(azChar + uintptr(nChar)*4)) = z
					v5 = z
					z++
					if int32(*(*uint8)(unsafe.Pointer(v5))) >= int32(0xc0) {
						for int32(*(*uint8)(unsafe.Pointer(z)))&int32(0xc0) == int32(0x80) {
							z++
						}
					}
					*(*uint32)(unsafe.Pointer(aLen + uintptr(nChar)*4)) = uint32(int32(int32(z)) - int32(*(*uintptr)(unsafe.Pointer(azChar + uintptr(nChar)*4))))
					goto _4
				_4:
					;
					nChar++
				}
			}
		}
	}
	if nChar > 0 {
		flags = int32(Xsqlite3_user_data(tls, context))
		if flags&int32(1) != 0 {
			for nIn > uint32(0) {
				len1 = uint32(0)
				i = 0
				for {
					if !(i < nChar) {
						break
					}
					len1 = *(*uint32)(unsafe.Pointer(aLen + uintptr(i)*4))
					if len1 <= nIn && libc.Xmemcmp(tls, zIn, *(*uintptr)(unsafe.Pointer(azChar + uintptr(i)*4)), len1) == 0 {
						break
					}
					goto _6
				_6:
					;
					i++
				}
				if i >= nChar {
					break
				}
				zIn += uintptr(len1)
				nIn -= len1
			}
		}
		if flags&int32(2) != 0 {
			for nIn > uint32(0) {
				len11 = uint32(0)
				i = 0
				for {
					if !(i < nChar) {
						break
					}
					len11 = *(*uint32)(unsafe.Pointer(aLen + uintptr(i)*4))
					if len11 <= nIn && libc.Xmemcmp(tls, zIn+uintptr(nIn-len11), *(*uintptr)(unsafe.Pointer(azChar + uintptr(i)*4)), len11) == 0 {
						break
					}
					goto _7
				_7:
					;
					i++
				}
				if i >= nChar {
					break
				}
				nIn -= len11
			}
		}
		if zCharSet != 0 {
			Xsqlite3_free(tls, azChar)
		}
	}
	Xsqlite3_result_text(tls, context, zIn, int32(int32(nIn)), uintptr(-libc.Int32FromInt32(1)))
}

var _lenOne = [1]uint32{
	0: uint32(1),
}

var _azOne = [1]uintptr{
	0: __ccgo_ts + 12636,
}

// C documentation
//
//	/* The core implementation of the CONCAT(...) and CONCAT_WS(SEP,...)
//	** functions.
//	**
//	** Return a string value that is the concatenation of all non-null
//	** entries in argv[].  Use zSep as the separator.
//	*/
func _concatFuncCore(tls *libc.TLS, context uintptr, argc int32, argv uintptr, nSep int32, zSep uintptr) {
	var i int32
	var j, k, n Ti64
	var v, z uintptr
	_, _, _, _, _, _ = i, j, k, n, v, z
	n = 0
	i = 0
	for {
		if !(i < argc) {
			break
		}
		n += int64(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))))
		goto _1
	_1:
		;
		i++
	}
	n += int64((argc - int32(1)) * nSep)
	z = Xsqlite3_malloc64(tls, uint64(n+int64(1)))
	if z == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
		return
	}
	j = 0
	i = 0
	for {
		if !(i < argc) {
			break
		}
		k = int64(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))))
		if k > 0 {
			v = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
			if v != uintptr(0) {
				if j > 0 && nSep > 0 {
					libc.Xmemcpy(tls, z+uintptr(j), zSep, uint32(uint32(nSep)))
					j += int64(int64(nSep))
				}
				libc.Xmemcpy(tls, z+uintptr(j), v, uint32(uint32(k)))
				j += k
			}
		}
		goto _2
	_2:
		;
		i++
	}
	*(*int8)(unsafe.Pointer(z + uintptr(j))) = 0
	Xsqlite3_result_text64(tls, context, z, uint64(uint64(j)), __ccgo_fp(Xsqlite3_free), uint8(SQLITE_UTF8))
}

// C documentation
//
//	/*
//	** The CONCAT(...) function.  Generate a string result that is the
//	** concatentation of all non-null arguments.
//	*/
func _concatFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_concatFuncCore(tls, context, argc, argv, 0, __ccgo_ts+1672)
}

// C documentation
//
//	/*
//	** The CONCAT_WS(separator, ...) function.
//	**
//	** Generate a string that is the concatenation of 2nd through the Nth
//	** argument.  Use the first argument (which must be non-NULL) as the
//	** separator.
//	*/
func _concatwsFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var nSep int32
	var zSep uintptr
	_, _ = nSep, zSep
	nSep = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zSep = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zSep == uintptr(0) {
		return
	}
	_concatFuncCore(tls, context, argc-int32(1), argv+uintptr(1)*4, nSep, zSep)
}

// C documentation
//
//	/* IMP: R-25361-16150 This function is omitted from SQLite by default. It
//	** is only available if the SQLITE_SOUNDEX compile-time option is used
//	** when SQLite is built.
//	*/
//	/*
//	** Compute the soundex encoding of a word.
//	**
//	** IMP: R-59782-00072 The soundex(X) function returns a string that is the
//	** soundex encoding of the string X.
//	*/
func _soundexFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var code, i, j, v3, v4 int32
	var prevcode Tu8
	var zIn uintptr
	var _ /* zResult at bp+0 */ [8]int8
	_, _, _, _, _, _, _ = code, i, j, prevcode, zIn, v3, v4
	zIn = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zIn == uintptr(0) {
		zIn = __ccgo_ts + 1672
	}
	i = 0
	for {
		if !(*(*Tu8)(unsafe.Pointer(zIn + uintptr(i))) != 0 && !(int32(_sqlite3CtypeMap[*(*Tu8)(unsafe.Pointer(zIn + uintptr(i)))])&libc.Int32FromInt32(0x02) != 0)) {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	if *(*Tu8)(unsafe.Pointer(zIn + uintptr(i))) != 0 {
		prevcode = _iCode[int32(*(*Tu8)(unsafe.Pointer(zIn + uintptr(i))))&int32(0x7f)]
		(*(*[8]int8)(unsafe.Pointer(bp)))[0] = int8(int32(*(*Tu8)(unsafe.Pointer(zIn + uintptr(i)))) & ^(int32(_sqlite3CtypeMap[*(*Tu8)(unsafe.Pointer(zIn + uintptr(i)))]) & libc.Int32FromInt32(0x20)))
		j = int32(1)
		for {
			if !(j < int32(4) && *(*Tu8)(unsafe.Pointer(zIn + uintptr(i))) != 0) {
				break
			}
			code = int32(_iCode[int32(*(*Tu8)(unsafe.Pointer(zIn + uintptr(i))))&int32(0x7f)])
			if code > 0 {
				if code != int32(int32(prevcode)) {
					prevcode = uint8(uint8(code))
					v3 = j
					j++
					(*(*[8]int8)(unsafe.Pointer(bp)))[v3] = int8(code + int32('0'))
				}
			} else {
				prevcode = uint8(0)
			}
			goto _2
		_2:
			;
			i++
		}
		for j < int32(4) {
			v4 = j
			j++
			(*(*[8]int8)(unsafe.Pointer(bp)))[v4] = int8('0')
		}
		(*(*[8]int8)(unsafe.Pointer(bp)))[j] = 0
		Xsqlite3_result_text(tls, context, bp, int32(4), uintptr(-libc.Int32FromInt32(1)))
	} else {
		/* IMP: R-64894-50321 The string "?000" is returned if the argument
		 ** is NULL or contains no ASCII alphabetic characters. */
		Xsqlite3_result_text(tls, context, __ccgo_ts+16749, int32(4), libc.UintptrFromInt32(0))
	}
}

var _iCode = [128]uint8{
	66:  uint8(1),
	67:  uint8(2),
	68:  uint8(3),
	70:  uint8(1),
	71:  uint8(2),
	74:  uint8(2),
	75:  uint8(2),
	76:  uint8(4),
	77:  uint8(5),
	78:  uint8(5),
	80:  uint8(1),
	81:  uint8(2),
	82:  uint8(6),
	83:  uint8(2),
	84:  uint8(3),
	86:  uint8(1),
	88:  uint8(2),
	90:  uint8(2),
	98:  uint8(1),
	99:  uint8(2),
	100: uint8(3),
	102: uint8(1),
	103: uint8(2),
	106: uint8(2),
	107: uint8(2),
	108: uint8(4),
	109: uint8(5),
	110: uint8(5),
	112: uint8(1),
	113: uint8(2),
	114: uint8(6),
	115: uint8(2),
	116: uint8(3),
	118: uint8(1),
	120: uint8(2),
	122: uint8(2),
}

// C documentation
//
//	/*
//	** A function that loads a shared-library extension then returns NULL.
//	*/
func _loadExt(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, zFile, zProc uintptr
	var _ /* zErrMsg at bp+0 */ uintptr
	_, _, _ = db, zFile, zProc
	zFile = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	db = Xsqlite3_context_db_handle(tls, context)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	/* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
	 ** flag is set.  See the sqlite3_enable_load_extension() API.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LoadExtFunc) == uint64(0) {
		Xsqlite3_result_error(tls, context, __ccgo_ts+13854, -int32(1))
		return
	}
	if argc == int32(2) {
		zProc = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	} else {
		zProc = uintptr(0)
	}
	if zFile != 0 && Xsqlite3_load_extension(tls, db, zFile, zProc, bp) != 0 {
		Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp)), -int32(1))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
}

// C documentation
//
//	/*
//	** An instance of the following structure holds the context of a
//	** sum() or avg() aggregate computation.
//	*/
type TSumCtx = struct {
	F__ccgo_align [0]uint32
	FrSum         float64
	FrErr         float64
	FiSum         Ti64
	Fcnt          Ti64
	Fapprox       Tu8
	Fovrfl        Tu8
	F__ccgo_pad6  [6]byte
}

type SumCtx = TSumCtx

type TSumCtx1 = struct {
	F__ccgo_align [0]uint32
	FrSum         float64
	FrErr         float64
	FiSum         Ti64
	Fcnt          Ti64
	Fapprox       Tu8
	Fovrfl        Tu8
	F__ccgo_pad6  [6]byte
}

type SumCtx1 = TSumCtx1

// C documentation
//
//	/*
//	** Do one step of the Kahan-Babushka-Neumaier summation.
//	**
//	** https://en.wikipedia.org/wiki/Kahan_summation_algorithm
//	**
//	** Variables are marked "volatile" to defeat c89 x86 floating point
//	** optimizations can mess up this algorithm.
//	*/
func _kahanBabuskaNeumaierStep(tls *libc.TLS, pSum uintptr, r float64) {
	var s, t float64
	_, _ = s, t
	s = (*TSumCtx)(unsafe.Pointer(pSum)).FrSum
	t = s + r
	if libc.Xfabs(tls, s) > libc.Xfabs(tls, r) {
		*(*float64)(unsafe.Pointer(pSum + 8)) += s - t + r
	} else {
		*(*float64)(unsafe.Pointer(pSum + 8)) += r - t + s
	}
	(*TSumCtx)(unsafe.Pointer(pSum)).FrSum = t
}

// C documentation
//
//	/*
//	** Add a (possibly large) integer to the running sum.
//	*/
func _kahanBabuskaNeumaierStepInt64(tls *libc.TLS, pSum uintptr, iVal Ti64) {
	var iBig, iSm Ti64
	_, _ = iBig, iSm
	if iVal <= -int64(4503599627370496) || iVal >= +libc.Int64FromInt64(4503599627370496) {
		iSm = iVal % int64(16384)
		iBig = iVal - iSm
		_kahanBabuskaNeumaierStep(tls, pSum, float64(float64(iBig)))
		_kahanBabuskaNeumaierStep(tls, pSum, float64(float64(iSm)))
	} else {
		_kahanBabuskaNeumaierStep(tls, pSum, float64(float64(iVal)))
	}
}

// C documentation
//
//	/*
//	** Initialize the Kahan-Babaska-Neumaier sum from a 64-bit integer
//	*/
func _kahanBabuskaNeumaierInit(tls *libc.TLS, p uintptr, iVal Ti64) {
	var iSm Ti64
	_ = iSm
	if iVal <= -int64(4503599627370496) || iVal >= +libc.Int64FromInt64(4503599627370496) {
		iSm = iVal % int64(16384)
		(*TSumCtx)(unsafe.Pointer(p)).FrSum = float64(iVal - iSm)
		(*TSumCtx)(unsafe.Pointer(p)).FrErr = float64(float64(iSm))
	} else {
		(*TSumCtx)(unsafe.Pointer(p)).FrSum = float64(float64(iVal))
		(*TSumCtx)(unsafe.Pointer(p)).FrErr = float64(0)
	}
}

// C documentation
//
//	/*
//	** Routines used to compute the sum, average, and total.
//	**
//	** The SUM() function follows the (broken) SQL standard which means
//	** that it returns NULL if it sums over no inputs.  TOTAL returns
//	** 0.0 in that case.  In addition, TOTAL always returns a float where
//	** SUM might return an integer if it never encounters a floating point
//	** value.  TOTAL never fails, but SUM might through an exception if
//	** it overflows an integer.
//	*/
func _sumStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	var type1 int32
	var _ /* x at bp+0 */ Ti64
	_, _ = p, type1
	_ = argc
	p = Xsqlite3_aggregate_context(tls, context, int32(40))
	type1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if p != 0 && type1 != int32(SQLITE_NULL) {
		(*TSumCtx)(unsafe.Pointer(p)).Fcnt++
		if int32((*TSumCtx)(unsafe.Pointer(p)).Fapprox) == 0 {
			if type1 != int32(SQLITE_INTEGER) {
				_kahanBabuskaNeumaierInit(tls, p, (*TSumCtx)(unsafe.Pointer(p)).FiSum)
				(*TSumCtx)(unsafe.Pointer(p)).Fapprox = uint8(1)
				_kahanBabuskaNeumaierStep(tls, p, Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv))))
			} else {
				*(*Ti64)(unsafe.Pointer(bp)) = (*TSumCtx)(unsafe.Pointer(p)).FiSum
				if _sqlite3AddInt64(tls, bp, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))) == 0 {
					(*TSumCtx)(unsafe.Pointer(p)).FiSum = *(*Ti64)(unsafe.Pointer(bp))
				} else {
					(*TSumCtx)(unsafe.Pointer(p)).Fovrfl = uint8(1)
					_kahanBabuskaNeumaierInit(tls, p, (*TSumCtx)(unsafe.Pointer(p)).FiSum)
					(*TSumCtx)(unsafe.Pointer(p)).Fapprox = uint8(1)
					_kahanBabuskaNeumaierStepInt64(tls, p, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv))))
				}
			}
		} else {
			if type1 == int32(SQLITE_INTEGER) {
				_kahanBabuskaNeumaierStepInt64(tls, p, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv))))
			} else {
				(*TSumCtx)(unsafe.Pointer(p)).Fovrfl = uint8(0)
				_kahanBabuskaNeumaierStep(tls, p, Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv))))
			}
		}
	}
}

func _sumInverse(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var iVal Ti64
	var p uintptr
	var type1 int32
	_, _, _ = iVal, p, type1
	_ = argc
	p = Xsqlite3_aggregate_context(tls, context, int32(40))
	type1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	/* p is always non-NULL because sumStep() will have been called first
	 ** to initialize it */
	if p != 0 && type1 != int32(SQLITE_NULL) {
		(*TSumCtx)(unsafe.Pointer(p)).Fcnt--
		if !((*TSumCtx)(unsafe.Pointer(p)).Fapprox != 0) {
			*(*Ti64)(unsafe.Pointer(p + 16)) -= Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
		} else {
			if type1 == int32(SQLITE_INTEGER) {
				iVal = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
				if iVal != int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
					_kahanBabuskaNeumaierStepInt64(tls, p, -iVal)
				} else {
					_kahanBabuskaNeumaierStepInt64(tls, p, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
					_kahanBabuskaNeumaierStepInt64(tls, p, int64(1))
				}
			} else {
				_kahanBabuskaNeumaierStep(tls, p, -Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv))))
			}
		}
	}
}

func _sumFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, context, 0)
	if p != 0 && (*TSumCtx)(unsafe.Pointer(p)).Fcnt > 0 {
		if (*TSumCtx)(unsafe.Pointer(p)).Fapprox != 0 {
			if (*TSumCtx)(unsafe.Pointer(p)).Fovrfl != 0 {
				Xsqlite3_result_error(tls, context, __ccgo_ts+16629, -int32(1))
			} else {
				if !(_sqlite3IsOverflow(tls, (*TSumCtx)(unsafe.Pointer(p)).FrErr) != 0) {
					Xsqlite3_result_double(tls, context, (*TSumCtx)(unsafe.Pointer(p)).FrSum+(*TSumCtx)(unsafe.Pointer(p)).FrErr)
				} else {
					Xsqlite3_result_double(tls, context, (*TSumCtx)(unsafe.Pointer(p)).FrSum)
				}
			}
		} else {
			Xsqlite3_result_int64(tls, context, (*TSumCtx)(unsafe.Pointer(p)).FiSum)
		}
	}
}

func _avgFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	var r float64
	_, _ = p, r
	p = Xsqlite3_aggregate_context(tls, context, 0)
	if p != 0 && (*TSumCtx)(unsafe.Pointer(p)).Fcnt > 0 {
		if (*TSumCtx)(unsafe.Pointer(p)).Fapprox != 0 {
			r = (*TSumCtx)(unsafe.Pointer(p)).FrSum
			if !(_sqlite3IsOverflow(tls, (*TSumCtx)(unsafe.Pointer(p)).FrErr) != 0) {
				r += (*TSumCtx)(unsafe.Pointer(p)).FrErr
			}
		} else {
			r = float64((*TSumCtx)(unsafe.Pointer(p)).FiSum)
		}
		Xsqlite3_result_double(tls, context, r/float64((*TSumCtx)(unsafe.Pointer(p)).Fcnt))
	}
}

func _totalFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	var r float64
	_, _ = p, r
	r = float64(0)
	p = Xsqlite3_aggregate_context(tls, context, 0)
	if p != 0 {
		if (*TSumCtx)(unsafe.Pointer(p)).Fapprox != 0 {
			r = (*TSumCtx)(unsafe.Pointer(p)).FrSum
			if !(_sqlite3IsOverflow(tls, (*TSumCtx)(unsafe.Pointer(p)).FrErr) != 0) {
				r += (*TSumCtx)(unsafe.Pointer(p)).FrErr
			}
		} else {
			r = float64((*TSumCtx)(unsafe.Pointer(p)).FiSum)
		}
	}
	Xsqlite3_result_double(tls, context, r)
}

// C documentation
//
//	/*
//	** The following structure keeps track of state information for the
//	** count() aggregate function.
//	*/
type TCountCtx = struct {
	F__ccgo_align [0]uint32
	Fn            Ti64
}

type CountCtx = TCountCtx

type TCountCtx1 = struct {
	F__ccgo_align [0]uint32
	Fn            Ti64
}

type CountCtx1 = TCountCtx1

// C documentation
//
//	/*
//	** Routines to implement the count() aggregate function.
//	*/
func _countStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, context, int32(8))
	if (argc == 0 || int32(SQLITE_NULL) != Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))) && p != 0 {
		(*TCountCtx)(unsafe.Pointer(p)).Fn++
	}
	/* The sqlite3_aggregate_count() function is deprecated.  But just to make
	 ** sure it still operates correctly, verify that its count agrees with our
	 ** internal count when using count(*) and when the total count can be
	 ** expressed as a 32-bit integer. */
}

func _countFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	var v1 int64
	_, _ = p, v1
	p = Xsqlite3_aggregate_context(tls, context, 0)
	if p != 0 {
		v1 = (*TCountCtx)(unsafe.Pointer(p)).Fn
	} else {
		v1 = 0
	}
	Xsqlite3_result_int64(tls, context, v1)
}

func _countInverse(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, ctx, int32(8))
	/* p is always non-NULL since countStep() will have been called first */
	if (argc == 0 || int32(SQLITE_NULL) != Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))) && p != 0 {
		(*TCountCtx)(unsafe.Pointer(p)).Fn--
	}
}

// C documentation
//
//	/*
//	** Routines to implement min() and max() aggregate functions.
//	*/
func _minmaxStep(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var cmp, max int32
	var pArg, pBest, pColl uintptr
	_, _, _, _, _ = cmp, max, pArg, pBest, pColl
	pArg = *(*uintptr)(unsafe.Pointer(argv))
	_ = NotUsed
	pBest = Xsqlite3_aggregate_context(tls, context, int32(40))
	if !(pBest != 0) {
		return
	}
	if Xsqlite3_value_type(tls, pArg) == int32(SQLITE_NULL) {
		if (*TMem)(unsafe.Pointer(pBest)).Fflags != 0 {
			_sqlite3SkipAccumulatorLoad(tls, context)
		}
	} else {
		if (*TMem)(unsafe.Pointer(pBest)).Fflags != 0 {
			pColl = _sqlite3GetFuncCollSeq(tls, context)
			/* This step function is used for both the min() and max() aggregates,
			 ** the only difference between the two being that the sense of the
			 ** comparison is inverted. For the max() aggregate, the
			 ** sqlite3_user_data() function returns (void *)-1. For min() it
			 ** returns (void *)db, where db is the sqlite3* database pointer.
			 ** Therefore the next statement sets variable 'max' to 1 for the max()
			 ** aggregate, or 0 for min().
			 */
			max = libc.BoolInt32(Xsqlite3_user_data(tls, context) != uintptr(0))
			cmp = _sqlite3MemCompare(tls, pBest, pArg, pColl)
			if max != 0 && cmp < 0 || !(max != 0) && cmp > 0 {
				_sqlite3VdbeMemCopy(tls, pBest, pArg)
			} else {
				_sqlite3SkipAccumulatorLoad(tls, context)
			}
		} else {
			(*TMem)(unsafe.Pointer(pBest)).Fdb = Xsqlite3_context_db_handle(tls, context)
			_sqlite3VdbeMemCopy(tls, pBest, pArg)
		}
	}
}

func _minMaxValueFinalize(tls *libc.TLS, context uintptr, bValue int32) {
	var pRes uintptr
	_ = pRes
	pRes = Xsqlite3_aggregate_context(tls, context, 0)
	if pRes != 0 {
		if (*Tsqlite3_value)(unsafe.Pointer(pRes)).Fflags != 0 {
			Xsqlite3_result_value(tls, context, pRes)
		}
		if bValue == 0 {
			_sqlite3VdbeMemRelease(tls, pRes)
		}
	}
}

func _minMaxValue(tls *libc.TLS, context uintptr) {
	_minMaxValueFinalize(tls, context, int32(1))
}

func _minMaxFinalize(tls *libc.TLS, context uintptr) {
	_minMaxValueFinalize(tls, context, 0)
}

// C documentation
//
//	/*
//	** group_concat(EXPR, ?SEPARATOR?)
//	** string_agg(EXPR, SEPARATOR)
//	**
//	** The SEPARATOR goes before the EXPR string.  This is tragic.  The
//	** groupConcatInverse() implementation would have been easier if the
//	** SEPARATOR were appended after EXPR.  And the order is undocumented,
//	** so we could change it, in theory.  But the old behavior has been
//	** around for so long that we dare not, for fear of breaking something.
//	*/
type TGroupConcatCtx = struct {
	Fstr             TStrAccum
	FnAccum          int32
	FnFirstSepLength int32
	FpnSepLengths    uintptr
}

type GroupConcatCtx = TGroupConcatCtx

func _groupConcatStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var db, pGCC, pnsl, zSep, zVal uintptr
	var firstTerm, i, nA, nSep, nVal, v1 int32
	_, _, _, _, _, _, _, _, _, _, _ = db, firstTerm, i, nA, nSep, nVal, pGCC, pnsl, zSep, zVal, v1
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(SQLITE_NULL) {
		return
	}
	pGCC = Xsqlite3_aggregate_context(tls, context, int32(36))
	if pGCC != 0 {
		db = Xsqlite3_context_db_handle(tls, context)
		firstTerm = libc.BoolInt32((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FmxAlloc == uint32(0))
		(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FmxAlloc = uint32(*(*int32)(unsafe.Pointer(db + 120)))
		if argc == int32(1) {
			if !(firstTerm != 0) {
				Xsqlite3_str_appendchar(tls, pGCC, int32(1), int8(','))
			} else {
				(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength = int32(1)
			}
		} else {
			if !(firstTerm != 0) {
				zSep = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
				nSep = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
				if zSep != 0 {
					Xsqlite3_str_append(tls, pGCC, zSep, nSep)
				} else {
					nSep = 0
				}
				if nSep != (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength || (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths != uintptr(0) {
					pnsl = (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths
					if pnsl == uintptr(0) {
						/* First separator length variation seen, start tracking them. */
						pnsl = Xsqlite3_malloc64(tls, uint64(uint32((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum+libc.Int32FromInt32(1))*uint32(4)))
						if pnsl != uintptr(0) {
							i = 0
							nA = (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum - int32(1)
							for i < nA {
								v1 = i
								i++
								*(*int32)(unsafe.Pointer(pnsl + uintptr(v1)*4)) = (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength
							}
						}
					} else {
						pnsl = Xsqlite3_realloc64(tls, pnsl, uint64(uint32((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum)*uint32(4)))
					}
					if pnsl != uintptr(0) {
						if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum > 0 {
							*(*int32)(unsafe.Pointer(pnsl + uintptr((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum-int32(1))*4)) = nSep
						}
						(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths = pnsl
					} else {
						_sqlite3StrAccumSetError(tls, pGCC, uint8(SQLITE_NOMEM))
					}
				}
			} else {
				(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
			}
		}
		*(*int32)(unsafe.Pointer(pGCC + 24)) += int32(1)
		zVal = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		nVal = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if zVal != 0 {
			Xsqlite3_str_append(tls, pGCC, zVal, nVal)
		}
	}
}

func _groupConcatInverse(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var nVS int32
	var pGCC uintptr
	_, _ = nVS, pGCC
	_ = argc /* Suppress unused parameter warning */
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(SQLITE_NULL) {
		return
	}
	pGCC = Xsqlite3_aggregate_context(tls, context, int32(36))
	/* pGCC is always non-NULL since groupConcatStep() will have always
	 ** run first to initialize it */
	if pGCC != 0 {
		/* Must call sqlite3_value_text() to convert the argument into text prior
		 ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
		Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		nVS = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
		*(*int32)(unsafe.Pointer(pGCC + 24)) -= int32(1)
		if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths != uintptr(0) {
			if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum > 0 {
				nVS += *(*int32)(unsafe.Pointer((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths))
				libc.Xmemmove(tls, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths+uintptr(1)*4, uint32((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum-libc.Int32FromInt32(1))*uint32(4))
			}
		} else {
			/* If removing single accumulated string, harmlessly over-do. */
			nVS += (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength
		}
		if nVS >= int32((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar) {
			(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar = uint32(0)
		} else {
			(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar -= uint32(uint32(nVS))
			libc.Xmemmove(tls, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FzText, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FzText+uintptr(nVS), (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar)
		}
		if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar == uint32(0) {
			(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FmxAlloc = uint32(0)
			Xsqlite3_free(tls, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths)
			(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths = uintptr(0)
		}
	}
}

func _groupConcatFinalize(tls *libc.TLS, context uintptr) {
	var pGCC uintptr
	_ = pGCC
	pGCC = Xsqlite3_aggregate_context(tls, context, 0)
	if pGCC != 0 {
		_sqlite3ResultStrAccum(tls, context, pGCC)
		Xsqlite3_free(tls, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths)
	}
}

func _groupConcatValue(tls *libc.TLS, context uintptr) {
	var pAccum, pGCC, zText uintptr
	_, _, _ = pAccum, pGCC, zText
	pGCC = Xsqlite3_aggregate_context(tls, context, 0)
	if pGCC != 0 {
		pAccum = pGCC
		if int32((*TStrAccum)(unsafe.Pointer(pAccum)).FaccError) == int32(SQLITE_TOOBIG) {
			Xsqlite3_result_error_toobig(tls, context)
		} else {
			if int32((*TStrAccum)(unsafe.Pointer(pAccum)).FaccError) == int32(SQLITE_NOMEM) {
				Xsqlite3_result_error_nomem(tls, context)
			} else {
				zText = Xsqlite3_str_value(tls, pAccum)
				Xsqlite3_result_text(tls, context, zText, int32((*TStrAccum)(unsafe.Pointer(pAccum)).FnChar), uintptr(-libc.Int32FromInt32(1)))
			}
		}
	}
}

// C documentation
//
//	/*
//	** This routine does per-connection function registration.  Most
//	** of the built-in functions above are part of the global function set.
//	** This routine only deals with those that are not global.
//	*/
func _sqlite3RegisterPerConnectionBuiltinFunctions(tls *libc.TLS, db uintptr) {
	var rc int32
	_ = rc
	rc = Xsqlite3_overload_function(tls, db, __ccgo_ts+16754, int32(2))
	if rc == int32(SQLITE_NOMEM) {
		_sqlite3OomFault(tls, db)
	}
}

// C documentation
//
//	/*
//	** Re-register the built-in LIKE functions.  The caseSensitive
//	** parameter determines whether or not the LIKE operator is case
//	** sensitive.
//	*/
func _sqlite3RegisterLikeFunctions(tls *libc.TLS, db uintptr, caseSensitive int32) {
	var flags, nArg int32
	var pDef, pInfo uintptr
	_, _, _, _ = flags, nArg, pDef, pInfo
	if caseSensitive != 0 {
		pInfo = uintptr(unsafe.Pointer(&_likeInfoAlt))
		flags = libc.Int32FromInt32(SQLITE_FUNC_LIKE) | libc.Int32FromInt32(SQLITE_FUNC_CASE)
	} else {
		pInfo = uintptr(unsafe.Pointer(&_likeInfoNorm))
		flags = int32(SQLITE_FUNC_LIKE)
	}
	nArg = int32(2)
	for {
		if !(nArg <= int32(3)) {
			break
		}
		_sqlite3CreateFunc(tls, db, __ccgo_ts+16760, nArg, int32(SQLITE_UTF8), pInfo, __ccgo_fp(_likeFunc), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
		pDef = _sqlite3FindFunction(tls, db, __ccgo_ts+16760, nArg, uint8(SQLITE_UTF8), uint8(0))
		*(*Tu32)(unsafe.Pointer(pDef + 4)) |= uint32(uint32(flags))
		*(*Tu32)(unsafe.Pointer(pDef + 4)) &= uint32(^libc.Int32FromInt32(SQLITE_FUNC_UNSAFE))
		goto _1
	_1:
		;
		nArg++
	}
}

// C documentation
//
//	/*
//	** pExpr points to an expression which implements a function.  If
//	** it is appropriate to apply the LIKE optimization to that function
//	** then set aWc[0] through aWc[2] to the wildcard characters and the
//	** escape character and then return TRUE.  If the function is not a
//	** LIKE-style function then return FALSE.
//	**
//	** The expression "a LIKE b ESCAPE c" is only considered a valid LIKE
//	** operator if c is a string literal that is exactly one byte in length.
//	** That one byte is stored in aWc[3].  aWc[3] is set to zero if there is
//	** no ESCAPE clause.
//	**
//	** *pIsNocase is set to true if uppercase and lowercase are equivalent for
//	** the function (default for LIKE).  If the function makes the distinction
//	** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to
//	** false.
//	*/
func _sqlite3IsLikeFunction(tls *libc.TLS, db uintptr, pExpr uintptr, pIsNocase uintptr, aWc uintptr) (r int32) {
	var nExpr int32
	var pDef, pEscape, zEscape uintptr
	_, _, _, _ = nExpr, pDef, pEscape, zEscape
	if !(*(*uintptr)(unsafe.Pointer(pExpr + 20)) != 0) {
		return 0
	}
	nExpr = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr
	pDef = _sqlite3FindFunction(tls, db, *(*uintptr)(unsafe.Pointer(pExpr + 8)), nExpr, uint8(SQLITE_UTF8), uint8(0))
	if pDef == uintptr(0) || (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_LIKE) == uint32(0) {
		return 0
	}
	/* The memcpy() statement assumes that the wildcard characters are
	 ** the first three statements in the compareInfo structure.  The
	 ** asserts() that follow verify that assumption
	 */
	libc.Xmemcpy(tls, aWc, (*TFuncDef)(unsafe.Pointer(pDef)).FpUserData, uint32(3))
	if nExpr < int32(3) {
		*(*int8)(unsafe.Pointer(aWc + 3)) = 0
	} else {
		pEscape = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8 + 2*20))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pEscape)).Fop) != int32(TK_STRING) {
			return 0
		}
		zEscape = *(*uintptr)(unsafe.Pointer(pEscape + 8))
		if int32(*(*int8)(unsafe.Pointer(zEscape))) == 0 || int32(*(*int8)(unsafe.Pointer(zEscape + 1))) != 0 {
			return 0
		}
		if int32(*(*int8)(unsafe.Pointer(zEscape))) == int32(*(*int8)(unsafe.Pointer(aWc))) {
			return 0
		}
		if int32(*(*int8)(unsafe.Pointer(zEscape))) == int32(*(*int8)(unsafe.Pointer(aWc + 1))) {
			return 0
		}
		*(*int8)(unsafe.Pointer(aWc + 3)) = *(*int8)(unsafe.Pointer(zEscape))
	}
	*(*int32)(unsafe.Pointer(pIsNocase)) = libc.BoolInt32((*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_CASE) == uint32(0))
	return int32(1)
}

/* Mathematical Constants */

// C documentation
//
//	/* Extra math functions that require linking with -lm
//	*/
//	/*
//	** Implementation SQL functions:
//	**
//	**   ceil(X)
//	**   ceiling(X)
//	**   floor(X)
//	**
//	** The sqlite3_user_data() pointer is a pointer to the libm implementation
//	** of the underlying C function.
//	*/
func _ceilingFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var x uintptr
	_ = x
	switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case int32(SQLITE_INTEGER):
		Xsqlite3_result_int64(tls, context, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv))))
	case int32(SQLITE_FLOAT):
		x = Xsqlite3_user_data(tls, context)
		Xsqlite3_result_double(tls, context, (*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))))
	default:
		break
	}
}

// C documentation
//
//	/*
//	** On some systems, ceil() and floor() are intrinsic function.  You are
//	** unable to take a pointer to these functions.  Hence, we here wrap them
//	** in our own actual functions.
//	*/
func _xCeil(tls *libc.TLS, x float64) (r float64) {
	return libc.Xceil(tls, x)
}

func _xFloor(tls *libc.TLS, x float64) (r float64) {
	return libc.Xfloor(tls, x)
}

/*
** Some systems do not have log2() and log10() in their standard math
** libraries.
 */

// C documentation
//
//	/*
//	** Implementation of SQL functions:
//	**
//	**   ln(X)       - natural logarithm
//	**   log(X)      - log X base 10
//	**   log10(X)    - log X base 10
//	**   log(B,X)    - log X base B
//	*/
func _logFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var ans, b, x float64
	_, _, _ = ans, b, x
	switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case int32(SQLITE_INTEGER):
		fallthrough
	case int32(SQLITE_FLOAT):
		x = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if x <= float64(0) {
			return
		}
	default:
		return
	}
	if argc == int32(2) {
		switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
		case int32(SQLITE_INTEGER):
			fallthrough
		case int32(SQLITE_FLOAT):
			b = libc.Xlog(tls, x)
			if b <= float64(0) {
				return
			}
			x = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
			if x <= float64(0) {
				return
			}
		default:
			return
		}
		ans = libc.Xlog(tls, x) / b
	} else {
		switch int32(Xsqlite3_user_data(tls, context)) {
		case int32(1):
			ans = libc.Xlog10(tls, x)
		case int32(2):
			ans = libc.X__builtin_log2(tls, x)
		default:
			ans = libc.Xlog(tls, x)
			break
		}
	}
	Xsqlite3_result_double(tls, context, ans)
}

// C documentation
//
//	/*
//	** Functions to converts degrees to radians and radians to degrees.
//	*/
func _degToRad(tls *libc.TLS, x float64) (r float64) {
	return x * (libc.Float64FromFloat64(3.141592653589793) / libc.Float64FromFloat64(180))
}

func _radToDeg(tls *libc.TLS, x float64) (r float64) {
	return x * (libc.Float64FromFloat64(180) / libc.Float64FromFloat64(3.141592653589793))
}

// C documentation
//
//	/*
//	** Implementation of 1-argument SQL math functions:
//	**
//	**   exp(X)  - Compute e to the X-th power
//	*/
func _math1Func(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var ans, v0 float64
	var type0 int32
	var x uintptr
	_, _, _, _ = ans, type0, v0, x
	type0 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if type0 != int32(SQLITE_INTEGER) && type0 != int32(SQLITE_FLOAT) {
		return
	}
	v0 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	x = Xsqlite3_user_data(tls, context)
	ans = (*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, v0)
	Xsqlite3_result_double(tls, context, ans)
}

// C documentation
//
//	/*
//	** Implementation of 2-argument SQL math functions:
//	**
//	**   power(X,Y)  - Compute X to the Y-th power
//	*/
func _math2Func(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var ans, v0, v1 float64
	var type0, type1 int32
	var x uintptr
	_, _, _, _, _, _ = ans, type0, type1, v0, v1, x
	type0 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if type0 != int32(SQLITE_INTEGER) && type0 != int32(SQLITE_FLOAT) {
		return
	}
	type1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	if type1 != int32(SQLITE_INTEGER) && type1 != int32(SQLITE_FLOAT) {
		return
	}
	v0 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	v1 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	x = Xsqlite3_user_data(tls, context)
	ans = (*(*func(*libc.TLS, float64, float64) float64)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, v0, v1)
	Xsqlite3_result_double(tls, context, ans)
}

// C documentation
//
//	/*
//	** Implementation of 0-argument pi() function.
//	*/
func _piFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = argv
	Xsqlite3_result_double(tls, context, float64(3.141592653589793))
}

// C documentation
//
//	/*
//	** Implementation of sign(X) function.
//	*/
func _signFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var type0, v1, v2 int32
	var x float64
	_, _, _, _ = type0, x, v1, v2
	_ = argc
	type0 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if type0 != int32(SQLITE_INTEGER) && type0 != int32(SQLITE_FLOAT) {
		return
	}
	x = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if x < float64(0) {
		v1 = -int32(1)
	} else {
		if x > float64(0) {
			v2 = +libc.Int32FromInt32(1)
		} else {
			v2 = 0
		}
		v1 = v2
	}
	Xsqlite3_result_int(tls, context, v1)
}

// C documentation
//
//	/*
//	** All of the FuncDef structures in the aBuiltinFunc[] array above
//	** to the global function hash table.  This occurs at start-time (as
//	** a consequence of calling sqlite3_initialize()).
//	**
//	** After this routine runs
//	*/
func _sqlite3RegisterBuiltinFunctions(tls *libc.TLS) {
	_sqlite3AlterFunctions(tls)
	_sqlite3WindowFunctions(tls)
	_sqlite3RegisterDateTimeFunctions(tls)
	_sqlite3RegisterJsonFunctions(tls)
	_sqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&_aBuiltinFunc)), int32(libc.Uint32FromInt64(4400)/libc.Uint32FromInt64(40)))
}

/*
 ** The following array holds FuncDef structures for all of the functions
 ** defined in this file.
 **
 ** The array cannot be constant since changes are made to the
 ** FuncDef.pHash elements at start-time.  The elements of this array
 ** are read-only after initialization is complete.
 **
 ** For peak efficiency, put the most frequently used function last.
 */
var _aBuiltinFunc = [110]TFuncDef{
	0: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_implies_nonnull_row)),
		FzName:     __ccgo_ts + 16765,
	},
	1: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_expr_compare)),
		FzName:     __ccgo_ts + 16785,
	},
	2: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_expr_implies_expr)),
		FzName:     __ccgo_ts + 16798,
	},
	3: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_affinity)),
		FzName:     __ccgo_ts + 16816,
	},
	4: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16825,
	},
	5: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)),
		FzName:     __ccgo_ts + 16833,
	},
	6: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)),
		FzName:     __ccgo_ts + 16833,
	},
	7: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 16848,
	},
	8: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 16874,
	},
	9: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_unlikely)),
		FzName:     __ccgo_ts + 16899,
	},
	10: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_unlikely)),
		FzName:     __ccgo_ts + 16908,
	},
	11: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_unlikely)),
		FzName:     __ccgo_ts + 16919,
	},
	12: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_sqlite_offset)),
		FzName:     __ccgo_ts + 16926,
	},
	13: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(1)),
		FzName:     __ccgo_ts + 16940,
	},
	14: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(1)),
		FzName:     __ccgo_ts + 16940,
	},
	15: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(2)),
		FzName:     __ccgo_ts + 16946,
	},
	16: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(2)),
		FzName:     __ccgo_ts + 16946,
	},
	17: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(3)),
		FzName:     __ccgo_ts + 16952,
	},
	18: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(3)),
		FzName:     __ccgo_ts + 16952,
	},
	19: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16957,
	},
	20: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16957,
	},
	21: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_MINMAX) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FzName:     __ccgo_ts + 16957,
	},
	22: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(1)),
		FzName:     __ccgo_ts + 16961,
	},
	23: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(1)),
		FzName:     __ccgo_ts + 16961,
	},
	24: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_MINMAX) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FpUserData: uintptr(libc.Int32FromInt32(1)),
		FzName:     __ccgo_ts + 16961,
	},
	25: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_TYPEOF)),
		FzName:     __ccgo_ts + 16965,
	},
	26: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_TYPEOF)),
		FzName:     __ccgo_ts + 16972,
	},
	27: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_LENGTH)),
		FzName:     __ccgo_ts + 16980,
	},
	28: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_BYTELEN)),
		FzName:     __ccgo_ts + 16987,
	},
	29: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17000,
	},
	30: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17006,
	},
	31: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17013,
	},
	32: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17020,
	},
	33: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17028,
	},
	34: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17033,
	},
	35: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17037,
	},
	36: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17037,
	},
	37: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17043,
	},
	38: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17049,
	},
	39: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17055,
	},
	40: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17059,
	},
	41: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17059,
	},
	42: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17065,
	},
	43: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17065,
	},
	44: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17072,
	},
	45: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17072,
	},
	46: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17072,
	},
	47: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17082,
	},
	48: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17089,
	},
	49: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17096,
	},
	50: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17107,
	},
	51: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17114,
	},
	52: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17129,
	},
	53: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17146,
	},
	54: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17157,
	},
	55: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17163,
	},
	56: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17181,
	},
	57: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17189,
	},
	58: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17203,
	},
	59: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17211,
	},
	60: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17220,
	},
	61: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17220,
	},
	62: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17227,
	},
	63: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17227,
	},
	64: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17237,
	},
	65: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17241,
	},
	66: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17247,
	},
	67: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_COUNT) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FzName:     __ccgo_ts + 17251,
	},
	68: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FzName:     __ccgo_ts + 17251,
	},
	69: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17257,
	},
	70: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17257,
	},
	71: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17270,
	},
	72: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE) | libc.Int32FromInt32(SQLITE_FUNC_CASE)),
		FpUserData: uintptr(unsafe.Pointer(&_globInfo)),
		FzName:     __ccgo_ts + 17281,
	},
	73: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE)),
		FpUserData: uintptr(unsafe.Pointer(&_likeInfoNorm)),
		FzName:     __ccgo_ts + 16760,
	},
	74: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE)),
		FpUserData: uintptr(unsafe.Pointer(&_likeInfoNorm)),
		FzName:     __ccgo_ts + 16760,
	},
	75: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 8103,
	},
	76: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 8103,
	},
	77: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17286,
	},
	78: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1245,
	},
	79: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1253,
	},
	80: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17291,
	},
	81: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17297,
	},
	82: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(1)),
		FzName:     __ccgo_ts + 17300,
	},
	83: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(1)),
		FzName:     __ccgo_ts + 17304,
	},
	84: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(libc.Int32FromInt32(2)),
		FzName:     __ccgo_ts + 17310,
	},
	85: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17300,
	},
	86: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17315,
	},
	87: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17319,
	},
	88: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17323,
	},
	89: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17329,
	},
	90: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17333,
	},
	91: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17338,
	},
	92: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17343,
	},
	93: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17348,
	},
	94: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17354,
	},
	95: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17358,
	},
	96: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17362,
	},
	97: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17366,
	},
	98: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17371,
	},
	99: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17376,
	},
	100: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17381,
	},
	101: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17387,
	},
	102: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17393,
	},
	103: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17399,
	},
	104: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17404,
	},
	105: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17412,
	},
	106: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17420,
	},
	107: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17423,
	},
	108: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 8103,
	},
	109: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(libc.Int32FromInt32(INLINEFUNC_iif)),
		FzName:     __ccgo_ts + 17428,
	},
}

func init() {
	p := unsafe.Pointer(&_aBuiltinFunc)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_soundexFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_loadExt)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_loadExt)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_compileoptionusedFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_compileoptiongetFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 616)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 656)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 696)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 736)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 776)) = __ccgo_fp(_minmaxFunc)
	*(*uintptr)(unsafe.Add(p, 856)) = __ccgo_fp(_minmaxStep)
	*(*uintptr)(unsafe.Add(p, 860)) = __ccgo_fp(_minMaxFinalize)
	*(*uintptr)(unsafe.Add(p, 864)) = __ccgo_fp(_minMaxValue)
	*(*uintptr)(unsafe.Add(p, 896)) = __ccgo_fp(_minmaxFunc)
	*(*uintptr)(unsafe.Add(p, 976)) = __ccgo_fp(_minmaxStep)
	*(*uintptr)(unsafe.Add(p, 980)) = __ccgo_fp(_minMaxFinalize)
	*(*uintptr)(unsafe.Add(p, 984)) = __ccgo_fp(_minMaxValue)
	*(*uintptr)(unsafe.Add(p, 1016)) = __ccgo_fp(_typeofFunc)
	*(*uintptr)(unsafe.Add(p, 1056)) = __ccgo_fp(_subtypeFunc)
	*(*uintptr)(unsafe.Add(p, 1096)) = __ccgo_fp(_lengthFunc)
	*(*uintptr)(unsafe.Add(p, 1136)) = __ccgo_fp(_bytelengthFunc)
	*(*uintptr)(unsafe.Add(p, 1176)) = __ccgo_fp(_instrFunc)
	*(*uintptr)(unsafe.Add(p, 1216)) = __ccgo_fp(_printfFunc)
	*(*uintptr)(unsafe.Add(p, 1256)) = __ccgo_fp(_printfFunc)
	*(*uintptr)(unsafe.Add(p, 1296)) = __ccgo_fp(_unicodeFunc)
	*(*uintptr)(unsafe.Add(p, 1336)) = __ccgo_fp(_charFunc)
	*(*uintptr)(unsafe.Add(p, 1376)) = __ccgo_fp(_absFunc)
	*(*uintptr)(unsafe.Add(p, 1416)) = __ccgo_fp(_roundFunc)
	*(*uintptr)(unsafe.Add(p, 1456)) = __ccgo_fp(_roundFunc)
	*(*uintptr)(unsafe.Add(p, 1496)) = __ccgo_fp(_upperFunc)
	*(*uintptr)(unsafe.Add(p, 1536)) = __ccgo_fp(_lowerFunc)
	*(*uintptr)(unsafe.Add(p, 1576)) = __ccgo_fp(_hexFunc)
	*(*uintptr)(unsafe.Add(p, 1616)) = __ccgo_fp(_unhexFunc)
	*(*uintptr)(unsafe.Add(p, 1656)) = __ccgo_fp(_unhexFunc)
	*(*uintptr)(unsafe.Add(p, 1696)) = __ccgo_fp(_concatFunc)
	*(*uintptr)(unsafe.Add(p, 1776)) = __ccgo_fp(_concatwsFunc)
	*(*uintptr)(unsafe.Add(p, 1896)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 1936)) = __ccgo_fp(_randomFunc)
	*(*uintptr)(unsafe.Add(p, 1976)) = __ccgo_fp(_randomBlob)
	*(*uintptr)(unsafe.Add(p, 2016)) = __ccgo_fp(_nullifFunc)
	*(*uintptr)(unsafe.Add(p, 2056)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 2096)) = __ccgo_fp(_sourceidFunc)
	*(*uintptr)(unsafe.Add(p, 2136)) = __ccgo_fp(_errlogFunc)
	*(*uintptr)(unsafe.Add(p, 2176)) = __ccgo_fp(_quoteFunc)
	*(*uintptr)(unsafe.Add(p, 2216)) = __ccgo_fp(_last_insert_rowid)
	*(*uintptr)(unsafe.Add(p, 2256)) = __ccgo_fp(_changes)
	*(*uintptr)(unsafe.Add(p, 2296)) = __ccgo_fp(_total_changes)
	*(*uintptr)(unsafe.Add(p, 2336)) = __ccgo_fp(_replaceFunc)
	*(*uintptr)(unsafe.Add(p, 2376)) = __ccgo_fp(_zeroblobFunc)
	*(*uintptr)(unsafe.Add(p, 2416)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2456)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2496)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2536)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2576)) = __ccgo_fp(_sumStep)
	*(*uintptr)(unsafe.Add(p, 2580)) = __ccgo_fp(_sumFinalize)
	*(*uintptr)(unsafe.Add(p, 2584)) = __ccgo_fp(_sumFinalize)
	*(*uintptr)(unsafe.Add(p, 2588)) = __ccgo_fp(_sumInverse)
	*(*uintptr)(unsafe.Add(p, 2616)) = __ccgo_fp(_sumStep)
	*(*uintptr)(unsafe.Add(p, 2620)) = __ccgo_fp(_totalFinalize)
	*(*uintptr)(unsafe.Add(p, 2624)) = __ccgo_fp(_totalFinalize)
	*(*uintptr)(unsafe.Add(p, 2628)) = __ccgo_fp(_sumInverse)
	*(*uintptr)(unsafe.Add(p, 2656)) = __ccgo_fp(_sumStep)
	*(*uintptr)(unsafe.Add(p, 2660)) = __ccgo_fp(_avgFinalize)
	*(*uintptr)(unsafe.Add(p, 2664)) = __ccgo_fp(_avgFinalize)
	*(*uintptr)(unsafe.Add(p, 2668)) = __ccgo_fp(_sumInverse)
	*(*uintptr)(unsafe.Add(p, 2696)) = __ccgo_fp(_countStep)
	*(*uintptr)(unsafe.Add(p, 2700)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2704)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2708)) = __ccgo_fp(_countInverse)
	*(*uintptr)(unsafe.Add(p, 2736)) = __ccgo_fp(_countStep)
	*(*uintptr)(unsafe.Add(p, 2740)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2744)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2748)) = __ccgo_fp(_countInverse)
	*(*uintptr)(unsafe.Add(p, 2776)) = __ccgo_fp(_groupConcatStep)
	*(*uintptr)(unsafe.Add(p, 2780)) = __ccgo_fp(_groupConcatFinalize)
	*(*uintptr)(unsafe.Add(p, 2784)) = __ccgo_fp(_groupConcatValue)
	*(*uintptr)(unsafe.Add(p, 2788)) = __ccgo_fp(_groupConcatInverse)
	*(*uintptr)(unsafe.Add(p, 2816)) = __ccgo_fp(_groupConcatStep)
	*(*uintptr)(unsafe.Add(p, 2820)) = __ccgo_fp(_groupConcatFinalize)
	*(*uintptr)(unsafe.Add(p, 2824)) = __ccgo_fp(_groupConcatValue)
	*(*uintptr)(unsafe.Add(p, 2828)) = __ccgo_fp(_groupConcatInverse)
	*(*uintptr)(unsafe.Add(p, 2856)) = __ccgo_fp(_groupConcatStep)
	*(*uintptr)(unsafe.Add(p, 2860)) = __ccgo_fp(_groupConcatFinalize)
	*(*uintptr)(unsafe.Add(p, 2864)) = __ccgo_fp(_groupConcatValue)
	*(*uintptr)(unsafe.Add(p, 2868)) = __ccgo_fp(_groupConcatInverse)
	*(*uintptr)(unsafe.Add(p, 2896)) = __ccgo_fp(_likeFunc)
	*(*uintptr)(unsafe.Add(p, 2936)) = __ccgo_fp(_likeFunc)
	*(*uintptr)(unsafe.Add(p, 2976)) = __ccgo_fp(_likeFunc)
	*(*uintptr)(unsafe.Add(p, 3088)) = __ccgo_fp(_xCeil)
	*(*uintptr)(unsafe.Add(p, 3096)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 3128)) = __ccgo_fp(_xCeil)
	*(*uintptr)(unsafe.Add(p, 3136)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 3168)) = __ccgo_fp(_xFloor)
	*(*uintptr)(unsafe.Add(p, 3176)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 3208)) = __ccgo_fp(libc.Xtrunc)
	*(*uintptr)(unsafe.Add(p, 3216)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 3256)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3296)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3336)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3376)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3416)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3448)) = __ccgo_fp(libc.Xexp)
	*(*uintptr)(unsafe.Add(p, 3456)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3488)) = __ccgo_fp(libc.Xpow)
	*(*uintptr)(unsafe.Add(p, 3496)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3528)) = __ccgo_fp(libc.Xpow)
	*(*uintptr)(unsafe.Add(p, 3536)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3568)) = __ccgo_fp(libc.Xfmod)
	*(*uintptr)(unsafe.Add(p, 3576)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3608)) = __ccgo_fp(libc.Xacos)
	*(*uintptr)(unsafe.Add(p, 3616)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3648)) = __ccgo_fp(libc.Xasin)
	*(*uintptr)(unsafe.Add(p, 3656)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3688)) = __ccgo_fp(libc.Xatan)
	*(*uintptr)(unsafe.Add(p, 3696)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3728)) = __ccgo_fp(libc.Xatan2)
	*(*uintptr)(unsafe.Add(p, 3736)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3768)) = __ccgo_fp(libc.Xcos)
	*(*uintptr)(unsafe.Add(p, 3776)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3808)) = __ccgo_fp(libc.Xsin)
	*(*uintptr)(unsafe.Add(p, 3816)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3848)) = __ccgo_fp(libc.Xtan)
	*(*uintptr)(unsafe.Add(p, 3856)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3888)) = __ccgo_fp(libc.Xcosh)
	*(*uintptr)(unsafe.Add(p, 3896)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3928)) = __ccgo_fp(libc.Xsinh)
	*(*uintptr)(unsafe.Add(p, 3936)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3968)) = __ccgo_fp(libc.Xtanh)
	*(*uintptr)(unsafe.Add(p, 3976)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4008)) = __ccgo_fp(libc.Xacosh)
	*(*uintptr)(unsafe.Add(p, 4016)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4048)) = __ccgo_fp(libc.Xasinh)
	*(*uintptr)(unsafe.Add(p, 4056)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4088)) = __ccgo_fp(libc.Xatanh)
	*(*uintptr)(unsafe.Add(p, 4096)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4128)) = __ccgo_fp(libc.Xsqrt)
	*(*uintptr)(unsafe.Add(p, 4136)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4168)) = __ccgo_fp(_degToRad)
	*(*uintptr)(unsafe.Add(p, 4176)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4208)) = __ccgo_fp(_radToDeg)
	*(*uintptr)(unsafe.Add(p, 4216)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4256)) = __ccgo_fp(_piFunc)
	*(*uintptr)(unsafe.Add(p, 4296)) = __ccgo_fp(_signFunc)
	*(*uintptr)(unsafe.Add(p, 4336)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 4376)) = __ccgo_fp(_versionFunc)
}

/************** End of func.c ************************************************/
/************** Begin file fkey.c ********************************************/
/*
**
** 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 by the compiler to add foreign key
** support to compiled SQL statements.
 */
/* #include "sqliteInt.h" */

/*
** Deferred and Immediate FKs
** --------------------------
**
** Foreign keys in SQLite come in two flavours: deferred and immediate.
** If an immediate foreign key constraint is violated,
** SQLITE_CONSTRAINT_FOREIGNKEY is returned and the current
** statement transaction rolled back. If a
** deferred foreign key constraint is violated, no action is taken
** immediately. However if the application attempts to commit the
** transaction before fixing the constraint violation, the attempt fails.
**
** Deferred constraints are implemented using a simple counter associated
** with the database handle. The counter is set to zero each time a
** database transaction is opened. Each time a statement is executed
** that causes a foreign key violation, the counter is incremented. Each
** time a statement is executed that removes an existing violation from
** the database, the counter is decremented. When the transaction is
** committed, the commit fails if the current value of the counter is
** greater than zero. This scheme has two big drawbacks:
**
**   * When a commit fails due to a deferred foreign key constraint,
**     there is no way to tell which foreign constraint is not satisfied,
**     or which row it is not satisfied for.
**
**   * If the database contains foreign key violations when the
**     transaction is opened, this may cause the mechanism to malfunction.
**
** Despite these problems, this approach is adopted as it seems simpler
** than the alternatives.
**
** INSERT operations:
**
**   I.1) For each FK for which the table is the child table, search
**        the parent table for a match. If none is found increment the
**        constraint counter.
**
**   I.2) For each FK for which the table is the parent table,
**        search the child table for rows that correspond to the new
**        row in the parent table. Decrement the counter for each row
**        found (as the constraint is now satisfied).
**
** DELETE operations:
**
**   D.1) For each FK for which the table is the child table,
**        search the parent table for a row that corresponds to the
**        deleted row in the child table. If such a row is not found,
**        decrement the counter.
**
**   D.2) For each FK for which the table is the parent table, search
**        the child table for rows that correspond to the deleted row
**        in the parent table. For each found increment the counter.
**
** UPDATE operations:
**
**   An UPDATE command requires that all 4 steps above are taken, but only
**   for FK constraints for which the affected columns are actually
**   modified (values must be compared at runtime).
**
** Note that I.1 and D.1 are very similar operations, as are I.2 and D.2.
** This simplifies the implementation a bit.
**
** For the purposes of immediate FK constraints, the OR REPLACE conflict
** resolution is considered to delete rows before the new row is inserted.
** If a delete caused by OR REPLACE violates an FK constraint, an exception
** is thrown, even if the FK constraint would be satisfied after the new
** row is inserted.
**
** Immediate constraints are usually handled similarly. The only difference
** is that the counter used is stored as part of each individual statement
** object (struct Vdbe). If, after the statement has run, its immediate
** constraint counter is greater than zero,
** it returns SQLITE_CONSTRAINT_FOREIGNKEY
** and the statement transaction is rolled back. An exception is an INSERT
** statement that inserts a single row only (no triggers). In this case,
** instead of using a counter, an exception is thrown immediately if the
** INSERT violates a foreign key constraint. This is necessary as such
** an INSERT does not open a statement transaction.
**
** TODO: How should dropping a table be handled? How should renaming a
** table be handled?
**
**
** Query API Notes
** ---------------
**
** Before coding an UPDATE or DELETE row operation, the code-generator
** for those two operations needs to know whether or not the operation
** requires any FK processing and, if so, which columns of the original
** row are required by the FK processing VDBE code (i.e. if FKs were
** implemented using triggers, which of the old.* columns would be
** accessed). No information is required by the code-generator before
** coding an INSERT operation. The functions used by the UPDATE/DELETE
** generation code to query for this information are:
**
**   sqlite3FkRequired() - Test to see if FK processing is required.
**   sqlite3FkOldmask()  - Query for the set of required old.* columns.
**
**
** Externally accessible module functions
** --------------------------------------
**
**   sqlite3FkCheck()    - Check for foreign key violations.
**   sqlite3FkActions()  - Code triggers for ON UPDATE/ON DELETE actions.
**   sqlite3FkDelete()   - Delete an FKey structure.
 */

/*
** VDBE Calling Convention
** -----------------------
**
** Example:
**
**   For the following INSERT statement:
**
**     CREATE TABLE t1(a, b INTEGER PRIMARY KEY, c);
**     INSERT INTO t1 VALUES(1, 2, 3.1);
**
**   Register (x):        2    (type integer)
**   Register (x+1):      1    (type integer)
**   Register (x+2):      NULL (type NULL)
**   Register (x+3):      3.1  (type real)
 */

// 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 + 36))).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)(unsafe.Pointer((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr((*TTable)(unsafe.Pointer(pParent)).FiPKey)*12))).FzCnName, zKey) != 0) {
				return 0
			}
		}
	} else {
		if paiCol != 0 {
			aiCol = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint32(uint32(nCol))*uint32(4)))
			if !(aiCol != 0) {
				return int32(1)
			}
			*(*uintptr)(unsafe.Pointer(paiCol)) = aiCol
		}
	}
	pIdx = (*TTable)(unsafe.Pointer(pParent)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == nCol && int32((*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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
					if aiCol != 0 {
						i = 0
						for {
							if !(i < nCol) {
								break
							}
							*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FiFrom
							goto _2
						_2:
							;
							i++
						}
					}
					break
				}
			} else {
				i1 = 0
				for {
					if !(i1 < nCol) {
						break
					}
					iCol = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2)) /* Name of indexed column */
					if int32(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)*12)
					if !(zDfltColl != 0) {
						zDfltColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
					}
					if _sqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*4)), zDfltColl) != 0 {
						break
					}
					zIdxCol = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr(iCol)*12))).FzCnName
					j = 0
					for {
						if !(j < nCol) {
							break
						}
						if _sqlite3StrICmp(tls, (*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(j)*8))).FzCol, zIdxCol) == 0 {
							if aiCol != 0 {
								*(*int32)(unsafe.Pointer(aiCol + uintptr(i1)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(j)*8))).FiFrom
							}
							break
						}
						goto _4
					_4:
						;
						j++
					}
					if j == nCol {
						break
					}
					goto _3
				_3:
					;
					i1++
				}
				if i1 == nCol {
					break
				} /* pIdx is usable */
			}
		}
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	if !(pIdx != 0) {
		if !((*TParse)(unsafe.Pointer(pParse)).FdisableTriggers != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17432, 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)(unsafe.Pointer(ppIdx)) = pIdx
	return 0
}

// C documentation
//
//	/*
//	** This function is called when a row is inserted into or deleted from the
//	** child table of foreign key constraint pFKey. If an SQL UPDATE is executed
//	** on the child table of pFKey, this function is invoked twice for each row
//	** affected - once to "delete" the old row, and then again to "insert" the
//	** new row.
//	**
//	** Each time it is called, this function generates VDBE code to locate the
//	** row in the parent table that corresponds to the row being inserted into
//	** or deleted from the child table. If the parent row can be found, no
//	** special action is taken. Otherwise, if the parent row can *not* be
//	** found in the parent table:
//	**
//	**   Operation | FK type   | Action taken
//	**   --------------------------------------------------------------------------
//	**   INSERT      immediate   Increment the "immediate constraint counter".
//	**
//	**   DELETE      immediate   Decrement the "immediate constraint counter".
//	**
//	**   INSERT      deferred    Increment the "deferred constraint counter".
//	**
//	**   DELETE      deferred    Decrement the "deferred constraint counter".
//	**
//	** These operations are identified in the comment at the top of this file
//	** (fkey.c) as "I.1" and "D.1".
//	*/
func _fkLookupParent(tls *libc.TLS, pParse uintptr, iDb int32, pTab uintptr, pIdx uintptr, pFKey uintptr, aiCol uintptr, regData int32, nIncr int32, isIgnore int32) {
	var i, iChild, iCur, iJump, iMustBeInt, iOk, iParent, iReg, nCol, regTemp, regTemp1 int32
	var v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = i, iChild, iCur, iJump, iMustBeInt, iOk, iParent, iReg, nCol, regTemp, regTemp1, v /* Iterator variable */
	v = _sqlite3GetVdbe(tls, pParse)                                                                                        /* Vdbe to add code to */
	iCur = (*TParse)(unsafe.Pointer(pParse)).FnTab - int32(1)                                                               /* Cursor number to use */
	iOk = _sqlite3VdbeMakeLabel(tls, pParse)                                                                                /* jump here if parent key found */
	/* If nIncr is less than zero, then check at runtime if there are any
	 ** outstanding constraints to resolve. If there are not, there is no need
	 ** to check if deleting this row resolves any outstanding violations.
	 **
	 ** Check if any of the key columns in the child table row are NULL. If
	 ** any are, then the constraint is considered satisfied. No need to
	 ** search for a matching row in the parent table.  */
	if nIncr < 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_FkIfZero), int32((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), iOk)
	}
	i = 0
	for {
		if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
			break
		}
		iReg = int32(_sqlite3TableColumnToStorage(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4))))) + regData + int32(1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), iReg, iOk)
		goto _1
	_1:
		;
		i++
	}
	if isIgnore == 0 {
		if pIdx == uintptr(0) { /* Address of MustBeInt instruction */
			regTemp = _sqlite3GetTempReg(tls, pParse)
			/* Invoke MustBeInt to coerce the child key value to an integer (i.e.
			 ** apply the affinity of the parent key). If this fails, then there
			 ** is no matching parent key. Before using MustBeInt, make a copy of
			 ** the value. Otherwise, the value inserted into the child key column
			 ** will have INTEGER affinity applied to it, which may not be correct.  */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), int32(_sqlite3TableColumnToStorage(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol)))))+int32(1)+regData, regTemp)
			iMustBeInt = _sqlite3VdbeAddOp2(tls, v, int32(OP_MustBeInt), regTemp, 0)
			/* If the parent table is the same as the child table, and we are about
			 ** to increment the constraint-counter (i.e. this is an INSERT operation),
			 ** then check if the row being inserted matches itself. If so, do not
			 ** increment the constraint-counter.  */
			if pTab == (*TFKey)(unsafe.Pointer(pFKey)).FpFrom && nIncr == int32(1) {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regData, iOk, regTemp)
				_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
			}
			_sqlite3OpenTable(tls, pParse, iCur, iDb, pTab, int32(OP_OpenRead))
			_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iCur, 0, regTemp)
			_sqlite3VdbeGoto(tls, v, iOk)
			_sqlite3VdbeJumpHere(tls, v, _sqlite3VdbeCurrentAddr(tls, v)-int32(2))
			_sqlite3VdbeJumpHere(tls, v, iMustBeInt)
			_sqlite3ReleaseTempReg(tls, pParse, regTemp)
		} else {
			nCol = (*TFKey)(unsafe.Pointer(pFKey)).FnCol
			regTemp1 = _sqlite3GetTempRange(tls, pParse, nCol)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), iCur, int32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
			i = 0
			for {
				if !(i < nCol) {
					break
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), int32(_sqlite3TableColumnToStorage(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)))))+int32(1)+regData, regTemp1+i)
				goto _2
			_2:
				;
				i++
			}
			/* If the parent table is the same as the child table, and we are about
			 ** to increment the constraint-counter (i.e. this is an INSERT operation),
			 ** then check if the row being inserted matches itself. If so, do not
			 ** increment the constraint-counter.
			 **
			 ** If any of the parent-key values are NULL, then the row cannot match
			 ** itself. So set JUMPIFNULL to make sure we do the OP_Found if any
			 ** of the parent-key values are NULL (at this point it is known that
			 ** none of the child key values are).
			 */
			if pTab == (*TFKey)(unsafe.Pointer(pFKey)).FpFrom && nIncr == int32(1) {
				iJump = _sqlite3VdbeCurrentAddr(tls, v) + nCol + int32(1)
				i = 0
				for {
					if !(i < nCol) {
						break
					}
					iChild = int32(_sqlite3TableColumnToStorage(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4))))) + int32(1) + regData
					iParent = int32(1) + regData
					iParent += int32(_sqlite3TableColumnToStorage(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpTable, *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))))
					if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
						/* The parent key is a composite key that includes the IPK column */
						iParent = regData
					}
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Ne), iChild, iJump, iParent)
					_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_JUMPIFNULL))
					goto _3
				_3:
					;
					i++
				}
				_sqlite3VdbeGoto(tls, v, iOk)
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), regTemp1, nCol, 0, _sqlite3IndexAffinityStr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pIdx), nCol)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iCur, iOk, regTemp1, nCol)
			_sqlite3ReleaseTempRange(tls, pParse, regTemp1, nCol)
		}
	}
	if !((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred != 0) && !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&libc.Uint64FromInt32(SQLITE_DeferFKs) != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0) && !((*TParse)(unsafe.Pointer(pParse)).FisMultiWrite != 0) {
		/* Special case: If this is an INSERT statement that will insert exactly
		 ** one row into the table, raise a constraint immediately instead of
		 ** incrementing a counter. This is necessary as the VM code is being
		 ** generated for will not open a statement transaction.  */
		_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))
	} else {
		if nIncr > 0 && int32((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred) == 0 {
			_sqlite3MayAbort(tls, pParse)
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_FkCounter), int32((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), nIncr)
	}
	_sqlite3VdbeResolveLabel(tls, v, iOk)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iCur)
}

// C documentation
//
//	/*
//	** Return an Expr object that refers to a memory register corresponding
//	** to column iCol of table pTab.
//	**
//	** regBase is the first of an array of register that contains the data
//	** for pTab.  regBase itself holds the rowid.  regBase+1 holds the first
//	** column.  regBase+2 holds the second column, and so forth.
//	*/
func _exprTableRegister(tls *libc.TLS, pParse uintptr, pTab uintptr, regBase int32, iCol Ti16) (r uintptr) {
	var db, pCol, pExpr, zColl uintptr
	_, _, _, _ = db, pCol, pExpr, zColl
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pExpr = _sqlite3Expr(tls, db, int32(TK_REGISTER), uintptr(0))
	if pExpr != 0 {
		if int32(int32(iCol)) >= 0 && int32(int32(iCol)) != int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
			pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12
			(*TExpr)(unsafe.Pointer(pExpr)).FiTable = regBase + int32(_sqlite3TableColumnToStorage(tls, pTab, iCol)) + int32(1)
			(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = (*TColumn)(unsafe.Pointer(pCol)).Faffinity
			zColl = _sqlite3ColumnColl(tls, pCol)
			if zColl == uintptr(0) {
				zColl = (*TCollSeq)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl)).FzName
			}
			pExpr = _sqlite3ExprAddCollateString(tls, pParse, pExpr, zColl)
		} else {
			(*TExpr)(unsafe.Pointer(pExpr)).FiTable = regBase
			(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(SQLITE_AFF_INTEGER)
		}
	}
	return pExpr
}

// C documentation
//
//	/*
//	** Return an Expr object that refers to column iCol of table pTab which
//	** has cursor iCur.
//	*/
func _exprTableColumn(tls *libc.TLS, db uintptr, pTab uintptr, iCursor int32, iCol Ti16) (r uintptr) {
	var pExpr uintptr
	_ = pExpr
	pExpr = _sqlite3Expr(tls, db, int32(TK_COLUMN), uintptr(0))
	if pExpr != 0 {
		(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = pTab
		(*TExpr)(unsafe.Pointer(pExpr)).FiTable = iCursor
		(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = iCol
	}
	return pExpr
}

// C documentation
//
//	/*
//	** This function is called to generate code executed when a row is deleted
//	** from the parent table of foreign key constraint pFKey and, if pFKey is
//	** deferred, when a row is inserted into the same table. When generating
//	** code for an SQL UPDATE operation, this function may be called twice -
//	** once to "delete" the old row and once to "insert" the new row.
//	**
//	** Parameter nIncr is passed -1 when inserting a row (as this may decrease
//	** the number of FK violations in the db) or +1 when deleting one (as this
//	** may increase the number of FK constraint problems).
//	**
//	** The code generated by this function scans through the rows in the child
//	** table that correspond to the parent table row being deleted or inserted.
//	** For each child row found, one of the following actions is taken:
//	**
//	**   Operation | FK type   | Action taken
//	**   --------------------------------------------------------------------------
//	**   DELETE      immediate   Increment the "immediate constraint counter".
//	**
//	**   INSERT      immediate   Decrement the "immediate constraint counter".
//	**
//	**   DELETE      deferred    Increment the "deferred constraint counter".
//	**
//	**   INSERT      deferred    Decrement the "deferred constraint counter".
//	**
//	** These operations are identified in the comment at the top of this file
//	** (fkey.c) as "I.2" and "D.2".
//	*/
func _fkScanChildren(tls *libc.TLS, pParse uintptr, pSrc uintptr, pTab uintptr, pIdx uintptr, pFKey uintptr, aiCol uintptr, regData int32, nIncr int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, pAll, pEq, pEq1, pLeft, pLeft1, pNe, pRight, pRight1, pWInfo, pWhere, v, zCol uintptr
	var i, iFkIfZero, v2, v3 int32
	var iCol, iCol1 Ti16
	var _ /* sNameContext at bp+0 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, iCol, iCol1, iFkIfZero, pAll, pEq, pEq1, pLeft, pLeft1, pNe, pRight, pRight1, pWInfo, pWhere, v, zCol, v2, v3
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Iterator variable */
	pWhere = uintptr(0)                        /* Context used by sqlite3WhereXXX() */
	iFkIfZero = 0                              /* Address of OP_FkIfZero */
	v = _sqlite3GetVdbe(tls, pParse)
	if nIncr < 0 {
		iFkIfZero = _sqlite3VdbeAddOp2(tls, v, int32(OP_FkIfZero), int32((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), 0)
	}
	/* Create an Expr object representing an SQL expression like:
	 **
	 **   <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
	 **
	 ** The collation sequence used for the comparison should be that of
	 ** the parent key columns. The affinity of the parent key column should
	 ** be applied to each child key value before the comparison takes place.
	 */
	i = 0
	for {
		if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
			break
		} /* Name of column in child table */
		if pIdx != 0 {
			v2 = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
		} else {
			v2 = -int32(1)
		}
		iCol = int16(v2)
		pLeft = _exprTableRegister(tls, pParse, pTab, regData, iCol)
		if aiCol != 0 {
			v3 = *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4))
		} else {
			v3 = (*(*TsColMap)(unsafe.Pointer(pFKey + 36))).FiFrom
		}
		iCol = int16(v3)
		zCol = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iCol)*12))).FzCnName
		pRight = _sqlite3Expr(tls, db, int32(TK_ID), zCol)
		pEq = _sqlite3PExpr(tls, pParse, int32(TK_EQ), pLeft, pRight)
		pWhere = _sqlite3ExprAnd(tls, pParse, pWhere, pEq)
		goto _1
	_1:
		;
		i++
	}
	/* If the child table is the same as the parent table, then add terms
	 ** to the WHERE clause that prevent this entry from being scanned.
	 ** The added WHERE clause terms are like this:
	 **
	 **     $current_rowid!=rowid
	 **     NOT( $current_a==a AND $current_b==b AND ... )
	 **
	 ** The first form is used for rowid tables.  The second form is used
	 ** for WITHOUT ROWID tables. In the second form, the *parent* key is
	 ** (a,b,...). Either the parent or primary key could be used to
	 ** uniquely identify the current row, but the parent key is more convenient
	 ** as the required values have already been loaded into registers
	 ** by the caller.
	 */
	if pTab == (*TFKey)(unsafe.Pointer(pFKey)).FpFrom && nIncr > 0 { /* Column ref to child table */
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			pLeft1 = _exprTableRegister(tls, pParse, pTab, regData, int16(-int32(1)))
			pRight1 = _exprTableColumn(tls, db, pTab, (*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FiCursor, int16(-int32(1)))
			pNe = _sqlite3PExpr(tls, pParse, int32(TK_NE), pLeft1, pRight1)
		} else {
			pAll = uintptr(0)
			i = 0
			for {
				if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				iCol1 = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))
				pLeft1 = _exprTableRegister(tls, pParse, pTab, regData, iCol1)
				pRight1 = _sqlite3Expr(tls, db, int32(TK_ID), (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol1)*12))).FzCnName)
				pEq1 = _sqlite3PExpr(tls, pParse, int32(TK_IS), pLeft1, pRight1)
				pAll = _sqlite3ExprAnd(tls, pParse, pAll, pEq1)
				goto _4
			_4:
				;
				i++
			}
			pNe = _sqlite3PExpr(tls, pParse, int32(TK_NOT), pAll, uintptr(0))
		}
		pWhere = _sqlite3ExprAnd(tls, pParse, pWhere, pNe)
	}
	/* Resolve the references in the WHERE clause. */
	libc.Xmemset(tls, bp, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp))).FpSrcList = pSrc
	(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
	_sqlite3ResolveExprNames(tls, bp, pWhere)
	/* Create VDBE to loop through the entries in pSrc that match the WHERE
	 ** clause. For each row found, increment either the deferred or immediate
	 ** foreign key constraint counter. */
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		pWInfo = _sqlite3WhereBegin(tls, pParse, pSrc, pWhere, uintptr(0), uintptr(0), uintptr(0), uint16(0), 0)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_FkCounter), int32((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), nIncr)
		if pWInfo != 0 {
			_sqlite3WhereEnd(tls, pWInfo)
		}
	}
	/* Clean up the WHERE clause constructed above. */
	_sqlite3ExprDelete(tls, db, pWhere)
	if iFkIfZero != 0 {
		_sqlite3VdbeJumpHereOrPopInst(tls, v, iFkIfZero)
	}
}

// C documentation
//
//	/*
//	** This function returns a linked list of FKey objects (connected by
//	** FKey.pNextTo) holding all children of table pTab.  For example,
//	** given the following schema:
//	**
//	**   CREATE TABLE t1(a PRIMARY KEY);
//	**   CREATE TABLE t2(b REFERENCES t1(a);
//	**
//	** Calling this function with table "t1" as an argument returns a pointer
//	** to the FKey structure representing the foreign key constraint on table
//	** "t2". Calling this function with "t2" as the argument would return a
//	** NULL pointer (as there are no FK constraints for which t2 is the parent
//	** table).
//	*/
func _sqlite3FkReferences(tls *libc.TLS, pTab uintptr) (r uintptr) {
	return _sqlite3HashFind(tls, (*TTable)(unsafe.Pointer(pTab)).FpSchema+56, (*TTable)(unsafe.Pointer(pTab)).FzName)
}

// C documentation
//
//	/*
//	** The second argument is a Trigger structure allocated by the
//	** fkActionTrigger() routine. This function deletes the Trigger structure
//	** and all of its sub-components.
//	**
//	** The Trigger structure or any of its sub-components may be allocated from
//	** the lookaside buffer belonging to database handle dbMem.
//	*/
func _fkTriggerDelete(tls *libc.TLS, dbMem uintptr, p uintptr) {
	var pStep uintptr
	_ = pStep
	if p != 0 {
		pStep = (*TTrigger)(unsafe.Pointer(p)).Fstep_list
		_sqlite3ExprDelete(tls, dbMem, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere)
		_sqlite3ExprListDelete(tls, dbMem, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList)
		_sqlite3SelectDelete(tls, dbMem, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect)
		_sqlite3ExprDelete(tls, dbMem, (*TTrigger)(unsafe.Pointer(p)).FpWhen)
		_sqlite3DbFree(tls, dbMem, p)
	}
}

// C documentation
//
//	/*
//	** Clear the apTrigger[] cache of CASCADE triggers for all foreign keys
//	** in a particular database.  This needs to happen when the schema
//	** changes.
//	*/
func _sqlite3FkClearTriggerCache(tls *libc.TLS, db uintptr, iDb int32) {
	var k, pFKey, pHash, pTab uintptr
	_, _, _, _ = k, pFKey, pHash, pTab
	pHash = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 8
	k = (*THash)(unsafe.Pointer(pHash)).Ffirst
	for {
		if !(k != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(k)).Fdata
		if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
			goto _1
		}
		pFKey = (*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pTab + 44))).FpFKey
		for {
			if !(pFKey != 0) {
				break
			}
			_fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 28)))
			*(*uintptr)(unsafe.Pointer(pFKey + 28)) = uintptr(0)
			_fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 28 + 1*4)))
			*(*uintptr)(unsafe.Pointer(pFKey + 28 + 1*4)) = uintptr(0)
			goto _2
		_2:
			;
			pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
		}
		goto _1
	_1:
		;
		k = (*THashElem)(unsafe.Pointer(k)).Fnext
	}
}

// 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 && int32((*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 + 44))).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)
		}
		(*TParse)(unsafe.Pointer(pParse)).FdisableTriggers = uint8(1)
		_sqlite3DeleteFrom(tls, pParse, _sqlite3SrcListDup(tls, db, pName, 0), uintptr(0), uintptr(0), uintptr(0))
		(*TParse)(unsafe.Pointer(pParse)).FdisableTriggers = uint8(0)
		/* 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
//
//	/*
//	** The second argument points to an FKey object representing a foreign key
//	** for which pTab is the child table. An UPDATE statement against pTab
//	** is currently being processed. For each column of the table that is
//	** actually updated, the corresponding element in the aChange[] array
//	** is zero or greater (if a column is unmodified the corresponding element
//	** is set to -1). If the rowid column is modified by the UPDATE statement
//	** the bChngRowid argument is non-zero.
//	**
//	** This function returns true if any of the columns that are part of the
//	** child key for FK constraint *p are modified.
//	*/
func _fkChildIsModified(tls *libc.TLS, pTab uintptr, p uintptr, aChange uintptr, bChngRowid int32) (r int32) {
	var i, iChildKey int32
	_, _ = i, iChildKey
	i = 0
	for {
		if !(i < (*TFKey)(unsafe.Pointer(p)).FnCol) {
			break
		}
		iChildKey = (*(*TsColMap)(unsafe.Pointer(p + 36 + uintptr(i)*8))).FiFrom
		if *(*int32)(unsafe.Pointer(aChange + uintptr(iChildKey)*4)) >= 0 {
			return int32(1)
		}
		if iChildKey == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) && bChngRowid != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** The second argument points to an FKey object representing a foreign key
//	** for which pTab is the parent table. An UPDATE statement against pTab
//	** is currently being processed. For each column of the table that is
//	** actually updated, the corresponding element in the aChange[] array
//	** is zero or greater (if a column is unmodified the corresponding element
//	** is set to -1). If the rowid column is modified by the UPDATE statement
//	** the bChngRowid argument is non-zero.
//	**
//	** This function returns true if any of the columns that are part of the
//	** parent key for FK constraint *p are modified.
//	*/
func _fkParentIsModified(tls *libc.TLS, pTab uintptr, p uintptr, aChange uintptr, bChngRowid int32) (r int32) {
	var i, iKey int32
	var pCol, zKey uintptr
	_, _, _, _ = i, iKey, pCol, zKey
	i = 0
	for {
		if !(i < (*TFKey)(unsafe.Pointer(p)).FnCol) {
			break
		}
		zKey = (*(*TsColMap)(unsafe.Pointer(p + 36 + uintptr(i)*8))).FzCol
		iKey = 0
		for {
			if !(iKey < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if *(*int32)(unsafe.Pointer(aChange + uintptr(iKey)*4)) >= 0 || iKey == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) && bChngRowid != 0 {
				pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iKey)*12
				if zKey != 0 {
					if 0 == _sqlite3StrICmp(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, zKey) {
						return int32(1)
					}
				} else {
					if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
						return int32(1)
					}
				}
			}
			goto _2
		_2:
			;
			iKey++
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if the parser passed as the first argument is being
//	** used to code a trigger that is really a "SET NULL" action belonging
//	** to trigger pFKey.
//	*/
func _isSetNullAction(tls *libc.TLS, pParse uintptr, pFKey uintptr) (r int32) {
	var p, pTop, v1 uintptr
	_, _, _ = p, pTop, v1
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pTop = v1
	if (*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg != 0 {
		p = (*TTriggerPrg)(unsafe.Pointer((*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg)).FpTrigger
		if p == *(*uintptr)(unsafe.Pointer(pFKey + 28)) && int32(*(*Tu8)(unsafe.Pointer(pFKey + 25))) == int32(OE_SetNull) || p == *(*uintptr)(unsafe.Pointer(pFKey + 28 + 1*4)) && int32(*(*Tu8)(unsafe.Pointer(pFKey + 25 + 1))) == int32(OE_SetNull) {
			return int32(1)
		}
	}
	return 0
}

// 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(32)
	defer tls.Free(32)
	var aiCol, db, pFKey, pItem, pSrc, pTo, v, zCol, zDb, v7 uintptr
	var bIgnore, eAction, i, iDb, iFromCol, iJump, iReg, isIgnoreErrors, rcauth, v4, v6 int32
	var _ /* aiCol at bp+16 */ uintptr
	var _ /* aiFree at bp+4 */ uintptr
	var _ /* iCol at bp+8 */ int32
	var _ /* pIdx at bp+0 */ uintptr
	var _ /* pIdx at bp+12 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aiCol, bIgnore, db, eAction, i, iDb, iFromCol, iJump, iReg, isIgnoreErrors, pFKey, pItem, pSrc, pTo, rcauth, v, zCol, zDb, v4, v6, v7
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Name of database containing pTab */
	isIgnoreErrors = int32((*TParse)(unsafe.Pointer(pParse)).FdisableTriggers)
	/* 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 !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		return
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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 + 44))).FpFKey
	for {
		if !(pFKey != 0) {
			break
		} /* Parent table of foreign key pFKey */
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Index on key columns in pTo */
		*(*uintptr)(unsafe.Pointer(bp + 4)) = 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 (*TParse)(unsafe.Pointer(pParse)).FdisableTriggers != 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+4) != 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 + 36 + uintptr(i)*8))).FiFrom
					iReg = int32(_sqlite3TableColumnToStorage(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, int16(int16(iFromCol)))) + regOld + int32(1)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), iReg, iJump)
					goto _2
				_2:
					;
					i++
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_FkCounter), int32((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), -int32(1))
			}
			goto _1
		}
		if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
			aiCol = *(*uintptr)(unsafe.Pointer(bp + 4))
		} else {
			*(*int32)(unsafe.Pointer(bp + 8)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 36))).FiFrom
			aiCol = bp + 8
		}
		i = 0
		for {
			if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
				break
			}
			if *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
				*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp)) != 0 {
					v4 = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2)))
				} else {
					v4 = int32((*TTable)(unsafe.Pointer(pTo)).FiPKey)
				}
				zCol = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTo)).FaCol + uintptr(v4)*12))).FzCnName
				rcauth = _sqlite3AuthReadCol(tls, pParse, (*TTable)(unsafe.Pointer(pTo)).FzName, zCol, iDb)
				bIgnore = libc.BoolInt32(rcauth == int32(SQLITE_IGNORE))
			}
			goto _3
		_3:
			;
			i++
		}
		/* 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++
		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)(unsafe.Pointer(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)(unsafe.Pointer(bp)), pFKey, aiCol, regNew, +libc.Int32FromInt32(1), bIgnore)
		}
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 4)))
		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)(unsafe.Pointer(bp + 12)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 16)) = 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+12, bp+16) != 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)).FpTab = (*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)).FpTab)).FnTabRef++
			v7 = pParse + 40
			v6 = *(*int32)(unsafe.Pointer(v7))
			*(*int32)(unsafe.Pointer(v7))++
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = v6
			if regNew != 0 {
				_fkScanChildren(tls, pParse, pSrc, pTab, *(*uintptr)(unsafe.Pointer(bp + 12)), pFKey, *(*uintptr)(unsafe.Pointer(bp + 16)), regNew, -int32(1))
			}
			if regOld != 0 {
				eAction = int32(*(*Tu8)(unsafe.Pointer(pFKey + 25 + libc.BoolUintptr(aChange != uintptr(0)))))
				if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(uint64(libc.Int32FromInt32(0x00008))<<libc.Int32FromInt32(32)) != 0 {
					eAction = OE_None
				}
				_fkScanChildren(tls, pParse, pSrc, pTab, *(*uintptr)(unsafe.Pointer(bp + 12)), pFKey, *(*uintptr)(unsafe.Pointer(bp + 16)), 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)(unsafe.Pointer(bp + 16)))
		goto _5
	_5:
		;
		pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo
	}
}

// C documentation
//
//	/*
//	** This function is called before generating code to update or delete a
//	** row contained in table pTab.
//	*/
func _sqlite3FkOldmask(tls *libc.TLS, pParse uintptr, pTab uintptr) (r Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var mask Tu32
	var p uintptr
	var v3, v6 uint32
	var _ /* pIdx at bp+0 */ uintptr
	_, _, _, _, _ = i, mask, p, v3, v6
	mask = uint32(0)
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM {
		p = (*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pTab + 44))).FpFKey
		for {
			if !(p != 0) {
				break
			}
			i = 0
			for {
				if !(i < (*TFKey)(unsafe.Pointer(p)).FnCol) {
					break
				}
				if (*(*TsColMap)(unsafe.Pointer(p + 36 + uintptr(i)*8))).FiFrom > int32(31) {
					v3 = uint32(0xffffffff)
				} else {
					v3 = libc.Uint32FromInt32(1) << (*(*TsColMap)(unsafe.Pointer(p + 36 + uintptr(i)*8))).FiFrom
				}
				mask |= v3
				goto _2
			_2:
				;
				i++
			}
			goto _1
		_1:
			;
			p = (*TFKey)(unsafe.Pointer(p)).FpNextFrom
		}
		p = _sqlite3FkReferences(tls, pTab)
		for {
			if !(p != 0) {
				break
			}
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			_sqlite3FkLocateIndex(tls, pParse, pTab, p, bp, uintptr(0))
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				i = 0
				for {
					if !(i < int32((*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnKeyCol)) {
						break
					}
					if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2))) > int32(31) {
						v6 = uint32(0xffffffff)
					} else {
						v6 = libc.Uint32FromInt32(1) << *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2))
					}
					mask |= v6
					goto _5
				_5:
					;
					i++
				}
			}
			goto _4
		_4:
			;
			p = (*TFKey)(unsafe.Pointer(p)).FpNextTo
		}
	}
	return mask
}

// C documentation
//
//	/*
//	** This function is called before generating code to update or delete a
//	** row contained in table pTab. If the operation is a DELETE, then
//	** parameter aChange is passed a NULL value. For an UPDATE, aChange points
//	** to an array of size N, where N is the number of columns in table pTab.
//	** If the i'th column is not modified by the UPDATE, then the corresponding
//	** entry in the aChange[] array is set to -1. If the column is modified,
//	** the value is 0 or greater. Parameter chngRowid is set to true if the
//	** UPDATE statement modifies the rowid fields of the table.
//	**
//	** If any foreign key processing will be required, this function returns
//	** non-zero. If there is no foreign key related processing, this function
//	** returns zero.
//	**
//	** For an UPDATE, this function returns 2 if:
//	**
//	**   * There are any FKs for which pTab is the child and the parent table
//	**     and any FK processing at all is required (even of a different FK), or
//	**
//	**   * the UPDATE modifies one or more parent keys for which the action is
//	**     not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
//	**
//	** Or, assuming some other foreign key processing is required, 1.
//	*/
func _sqlite3FkRequired(tls *libc.TLS, pParse uintptr, pTab uintptr, aChange uintptr, chngRowid int32) (r int32) {
	var bHaveFK, eRet, v3 int32
	var p uintptr
	_, _, _, _ = bHaveFK, eRet, p, v3
	eRet = int32(1) /* Value to return if bHaveFK is true */
	bHaveFK = 0     /* If FK processing is required */
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM {
		if !(aChange != 0) {
			/* A DELETE operation. Foreign key processing is required if the
			 ** table in question is either the child or parent table for any
			 ** foreign key constraint.  */
			bHaveFK = libc.BoolInt32(_sqlite3FkReferences(tls, pTab) != 0 || (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTab + 44))).FpFKey != 0)
		} else {
			/* Check if any child key columns are being modified. */
			p = (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTab + 44))).FpFKey
			for {
				if !(p != 0) {
					break
				}
				if _fkChildIsModified(tls, pTab, p, aChange, chngRowid) != 0 {
					if 0 == Xsqlite3_stricmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, (*TFKey)(unsafe.Pointer(p)).FzTo) {
						eRet = int32(2)
					}
					bHaveFK = int32(1)
				}
				goto _1
			_1:
				;
				p = (*TFKey)(unsafe.Pointer(p)).FpNextFrom
			}
			/* Check if any parent key columns are being modified. */
			p = _sqlite3FkReferences(tls, pTab)
			for {
				if !(p != 0) {
					break
				}
				if _fkParentIsModified(tls, pTab, p, aChange, chngRowid) != 0 {
					if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&(uint64(libc.Int32FromInt32(0x00008))<<libc.Int32FromInt32(32)) == uint64(0) && int32(*(*Tu8)(unsafe.Pointer(p + 25 + 1))) != OE_None {
						return int32(2)
					}
					bHaveFK = int32(1)
				}
				goto _2
			_2:
				;
				p = (*TFKey)(unsafe.Pointer(p)).FpNextTo
			}
		}
	}
	if bHaveFK != 0 {
		v3 = eRet
	} else {
		v3 = 0
	}
	return v3
}

// 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(48)
	defer tls.Free(48)
	var action, i, iAction, iDb, iFromCol, nFrom, v2, v3, v5, v6 int32
	var db, pCol, pDflt, pEq, pList, pNew, pRaise, pSelect, pSrc, pStep, pTrigger, pWhen, pWhere, zFrom, v4 uintptr
	var _ /* aiCol at bp+4 */ uintptr
	var _ /* pIdx at bp+0 */ uintptr
	var _ /* tFromCol at bp+24 */ TToken
	var _ /* tNew at bp+16 */ TToken
	var _ /* tOld at bp+8 */ TToken
	var _ /* tToCol at bp+32 */ TToken
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = action, db, i, iAction, iDb, iFromCol, nFrom, pCol, pDflt, pEq, pList, pNew, pRaise, pSelect, pSrc, pStep, pTrigger, pWhen, pWhere, zFrom, v2, v3, v4, v5, v6
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb       /* Trigger definition to return */
	iAction = libc.BoolInt32(pChanges != uintptr(0)) /* 1 for UPDATE, 0 for DELETE */
	action = int32(*(*Tu8)(unsafe.Pointer(pFKey + 25 + uintptr(iAction))))
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(uint64(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)(unsafe.Pointer(pFKey + 28 + uintptr(iAction)*4))
	if action != OE_None && !(pTrigger != 0) { /* Length in bytes of zFrom */
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)     /* Parent key index for this FK */
		*(*uintptr)(unsafe.Pointer(bp + 4)) = 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+4) != 0 {
			return uintptr(0)
		}
		i = 0
		for {
			if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
				break
			}
			*(*TToken)(unsafe.Pointer(bp + 8)) = TToken{
				Fz: __ccgo_ts + 7969,
				Fn: uint32(3),
			} /* Literal "old" token */
			*(*TToken)(unsafe.Pointer(bp + 16)) = TToken{
				Fz: __ccgo_ts + 7965,
				Fn: uint32(3),
			} /* tFromCol = OLD.tToCol */
			if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
				v2 = *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)) + uintptr(i)*4))
			} else {
				v2 = (*(*TsColMap)(unsafe.Pointer(pFKey + 36))).FiFrom
			}
			iFromCol = v2
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				v3 = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2)))
			} else {
				v3 = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
			}
			_sqlite3TokenInit(tls, bp+32, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(v3)*12))).FzCnName)
			_sqlite3TokenInit(tls, bp+24, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*12))).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+8, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0)), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+24, 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+8, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0)), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 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+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0))
				} else {
					if action == int32(OE_SetDflt) {
						pCol = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*12
						if int32((*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+24, 0)
			}
			goto _1
		_1:
			;
			i++
		}
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 4)))
		zFrom = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName
		nFrom = _sqlite3Strlen30(tls, zFrom)
		if action == int32(OE_Restrict) {
			iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
			pRaise = _sqlite3Expr(tls, db, int32(TK_RAISE), __ccgo_ts+6598)
			if pRaise != 0 {
				(*TExpr)(unsafe.Pointer(pRaise)).FaffExpr = int8(OE_Abort)
			}
			pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
			if pSrc != 0 {
				(*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FzName = _sqlite3DbStrDup(tls, db, zFrom)
				(*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FzDatabase = _sqlite3DbStrDup(tls, db, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
			}
			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.Fsz = uint16(0)
		pTrigger = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint32FromInt64(36)+libc.Uint32FromInt64(48)+uint32(uint32(nFrom))+uint32(1)))
		if pTrigger != 0 {
			v4 = pTrigger + 1*36
			(*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list = v4
			pStep = v4
			(*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget = pStep + 1*48
			libc.Xmemcpy(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget, zFrom, uint32(uint32(nFrom)))
			(*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--
		if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			v5 = 0
		} else {
			v5 = int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(v5)
		_sqlite3ExprDelete(tls, db, pWhere)
		_sqlite3ExprDelete(tls, db, pWhen)
		_sqlite3ExprListDelete(tls, db, pList)
		_sqlite3SelectDelete(tls, db, pSelect)
		if int32((*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)(unsafe.Pointer(pFKey + 28 + uintptr(iAction)*4)) = pTrigger
		if pChanges != 0 {
			v6 = int32(TK_UPDATE)
		} else {
			v6 = int32(TK_DELETE)
		}
		(*TTrigger)(unsafe.Pointer(pTrigger)).Fop = uint8(v6)
	}
	return pTrigger
}

// C documentation
//
//	/*
//	** This function is called when deleting or updating a row to implement
//	** any required CASCADE, SET NULL or SET DEFAULT actions.
//	*/
func _sqlite3FkActions(tls *libc.TLS, pParse uintptr, pTab uintptr, pChanges uintptr, regOld int32, aChange uintptr, bChngRowid int32) {
	var pAct, pFKey uintptr
	_, _ = pAct, pFKey
	/* If foreign-key support is enabled, iterate through all FKs that
	 ** refer to table pTab. If there is an action associated with the FK
	 ** for this operation (either update or delete), invoke the associated
	 ** trigger sub-program.  */
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_ForeignKeys) != 0 { /* Iterator variable */
		pFKey = _sqlite3FkReferences(tls, pTab)
		for {
			if !(pFKey != 0) {
				break
			}
			if aChange == uintptr(0) || _fkParentIsModified(tls, pTab, pFKey, aChange, bChngRowid) != 0 {
				pAct = _fkActionTrigger(tls, pParse, pTab, pFKey, pChanges)
				if pAct != 0 {
					_sqlite3CodeRowTriggerDirect(tls, pParse, pAct, pTab, regOld, int32(OE_Abort), 0)
				}
			}
			goto _1
		_1:
			;
			pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo
		}
	}
}

// C documentation
//
//	/*
//	** Free all memory associated with foreign key definitions attached to
//	** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
//	** hash table.
//	*/
func _sqlite3FkDelete(tls *libc.TLS, db uintptr, pTab uintptr) {
	var pFKey, pNext, z, v2 uintptr
	_, _, _, _ = pFKey, pNext, z, v2 /* Copy of pFKey->pNextFrom */
	pFKey = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpFKey
	for {
		if !(pFKey != 0) {
			break
		}
		/* Remove the FK from the fkeyHash hash table. */
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			if (*TFKey)(unsafe.Pointer(pFKey)).FpPrevTo != 0 {
				(*TFKey)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpPrevTo)).FpNextTo = (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo
			} else {
				if (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo != 0 {
					v2 = (*TFKey)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpNextTo)).FzTo
				} else {
					v2 = (*TFKey)(unsafe.Pointer(pFKey)).FzTo
				}
				z = v2
				_sqlite3HashInsert(tls, (*TTable)(unsafe.Pointer(pTab)).FpSchema+56, z, (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo)
			}
			if (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo != 0 {
				(*TFKey)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpNextTo)).FpPrevTo = (*TFKey)(unsafe.Pointer(pFKey)).FpPrevTo
			}
		}
		/* EV: R-30323-21917 Each foreign key constraint in SQLite is
		 ** classified as either immediate or deferred.
		 */
		/* Delete any triggers created to implement actions for this FK. */
		_fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 28)))
		_fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 28 + 1*4)))
		pNext = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
		_sqlite3DbFree(tls, db, pFKey)
		goto _1
	_1:
		;
		pFKey = pNext
	}
}

/************** End of fkey.c ************************************************/
/************** Begin file insert.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 C code routines that are called by the parser
** to handle INSERT statements in SQLite.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Generate code that will
//	**
//	**   (1) acquire a lock for table pTab then
//	**   (2) open pTab as cursor iCur.
//	**
//	** If pTab is a WITHOUT ROWID table, then it is the PRIMARY KEY index
//	** for that table that is actually opened.
//	*/
func _sqlite3OpenTable(tls *libc.TLS, pParse uintptr, iCur int32, iDb int32, pTab uintptr, opcode int32) {
	var pPk, v uintptr
	var v1 int32
	_, _, _ = pPk, v, v1
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnoSharedCache != 0) {
		if opcode == int32(OP_OpenWrite) {
			v1 = int32(1)
		} else {
			v1 = 0
		}
		_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(v1), (*TTable)(unsafe.Pointer(pTab)).FzName)
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		_sqlite3VdbeAddOp4Int(tls, v, opcode, iCur, int32((*TTable)(unsafe.Pointer(pTab)).Ftnum), iDb, int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol))
	} else {
		pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
		_sqlite3VdbeAddOp3(tls, v, opcode, iCur, int32((*TIndex)(unsafe.Pointer(pPk)).Ftnum), iDb)
		_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
	}
}

// C documentation
//
//	/*
//	** Return a pointer to the column affinity string associated with index
//	** pIdx. A column affinity string has one character for each column in
//	** the table, according to the affinity of the column:
//	**
//	**  Character      Column affinity
//	**  ------------------------------
//	**  'A'            BLOB
//	**  'B'            TEXT
//	**  'C'            NUMERIC
//	**  'D'            INTEGER
//	**  'F'            REAL
//	**
//	** An extra 'D' is appended to the end of the string to cover the
//	** rowid that appears as the last column in every index.
//	**
//	** Memory for the buffer containing the column index affinity string
//	** is managed along with the rest of the Index structure. It will be
//	** released when sqlite3DeleteIndex() is called.
//	*/
func _computeIndexAffStr(tls *libc.TLS, db uintptr, pIdx uintptr) (r uintptr) {
	var aff int8
	var n int32
	var pTab uintptr
	var x Ti16
	_, _, _, _ = aff, n, pTab, x
	pTab = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
	(*TIndex)(unsafe.Pointer(pIdx)).FzColAff = _sqlite3DbMallocRaw(tls, uintptr(0), uint64(int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)+int32(1)))
	if !((*TIndex)(unsafe.Pointer(pIdx)).FzColAff != 0) {
		_sqlite3OomFault(tls, db)
		return uintptr(0)
	}
	n = 0
	for {
		if !(n < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
			break
		}
		x = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2))
		if int32(int32(x)) >= 0 {
			aff = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(x)*12))).Faffinity
		} else {
			if int32(int32(x)) == -int32(1) {
				aff = int8(SQLITE_AFF_INTEGER)
			} else {
				aff = _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(n)*20))).FpExpr)
			}
		}
		if int32(int32(aff)) < int32(SQLITE_AFF_BLOB) {
			aff = int8(SQLITE_AFF_BLOB)
		}
		if int32(int32(aff)) > int32(SQLITE_AFF_NUMERIC) {
			aff = int8(SQLITE_AFF_NUMERIC)
		}
		*(*int8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FzColAff + uintptr(n))) = aff
		goto _1
	_1:
		;
		n++
	}
	*(*int8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FzColAff + uintptr(n))) = 0
	return (*TIndex)(unsafe.Pointer(pIdx)).FzColAff
}

func _sqlite3IndexAffinityStr(tls *libc.TLS, db uintptr, pIdx uintptr) (r uintptr) {
	if !((*TIndex)(unsafe.Pointer(pIdx)).FzColAff != 0) {
		return _computeIndexAffStr(tls, db, pIdx)
	}
	return (*TIndex)(unsafe.Pointer(pIdx)).FzColAff
}

// C documentation
//
//	/*
//	** Compute an affinity string for a table.   Space is obtained
//	** from sqlite3DbMalloc().  The caller is responsible for freeing
//	** the space when done.
//	*/
func _sqlite3TableAffinityStr(tls *libc.TLS, db uintptr, pTab uintptr) (r uintptr) {
	var i, j, v2, v3, v4 int32
	var zColAff uintptr
	_, _, _, _, _, _ = i, j, zColAff, v2, v3, v4
	zColAff = _sqlite3DbMallocRaw(tls, db, uint64(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1)))
	if zColAff != 0 {
		v2 = libc.Int32FromInt32(0)
		j = v2
		i = v2
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
				v3 = j
				j++
				*(*int8)(unsafe.Pointer(zColAff + uintptr(v3))) = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity
			}
			goto _1
		_1:
			;
			i++
		}
		for cond := true; cond; cond = j >= 0 && int32(*(*int8)(unsafe.Pointer(zColAff + uintptr(j)))) <= int32(SQLITE_AFF_BLOB) {
			v4 = j
			j--
			*(*int8)(unsafe.Pointer(zColAff + uintptr(v4))) = 0
		}
	}
	return zColAff
}

// C documentation
//
//	/*
//	** Make changes to the evolving bytecode to do affinity transformations
//	** of values that are about to be gathered into a row for table pTab.
//	**
//	** For ordinary (legacy, non-strict) tables:
//	** -----------------------------------------
//	**
//	** Compute the affinity string for table pTab, if it has not already been
//	** computed.  As an optimization, omit trailing SQLITE_AFF_BLOB affinities.
//	**
//	** If the affinity string is empty (because it was all SQLITE_AFF_BLOB entries
//	** which were then optimized out) then this routine becomes a no-op.
//	**
//	** Otherwise if iReg>0 then code an OP_Affinity opcode that will set the
//	** affinities for register iReg and following.  Or if iReg==0,
//	** then just set the P4 operand of the previous opcode (which should  be
//	** an OP_MakeRecord) to the affinity string.
//	**
//	** A column affinity string has one character per column:
//	**
//	**    Character      Column affinity
//	**    ---------      ---------------
//	**    'A'            BLOB
//	**    'B'            TEXT
//	**    'C'            NUMERIC
//	**    'D'            INTEGER
//	**    'E'            REAL
//	**
//	** For STRICT tables:
//	** ------------------
//	**
//	** Generate an appropriate OP_TypeCheck opcode that will verify the
//	** datatypes against the column definitions in pTab.  If iReg==0, that
//	** means an OP_MakeRecord opcode has already been generated and should be
//	** the last opcode generated.  The new OP_TypeCheck needs to be inserted
//	** before the OP_MakeRecord.  The new OP_TypeCheck should use the same
//	** register set as the OP_MakeRecord.  If iReg>0 then register iReg is
//	** the first of a series of registers that will form the new record.
//	** Apply the type checking to that array of registers.
//	*/
func _sqlite3TableAffinity(tls *libc.TLS, v uintptr, pTab uintptr, iReg int32) {
	var i int32
	var pPrev, zColAff uintptr
	_, _, _ = i, pPrev, zColAff
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Strict) != 0 {
		if iReg == 0 {
			_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
			pPrev = _sqlite3VdbeGetLastOp(tls, v)
			(*TVdbeOp)(unsafe.Pointer(pPrev)).Fopcode = uint8(OP_TypeCheck)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*TVdbeOp)(unsafe.Pointer(pPrev)).Fp1, (*TVdbeOp)(unsafe.Pointer(pPrev)).Fp2, (*TVdbeOp)(unsafe.Pointer(pPrev)).Fp3)
		} else {
			/* Insert an isolated OP_Typecheck */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_TypeCheck), iReg, int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol))
			_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
		}
		return
	}
	zColAff = (*TTable)(unsafe.Pointer(pTab)).FzColAff
	if zColAff == uintptr(0) {
		zColAff = _sqlite3TableAffinityStr(tls, uintptr(0), pTab)
		if !(zColAff != 0) {
			_sqlite3OomFault(tls, _sqlite3VdbeDb(tls, v))
			return
		}
		(*TTable)(unsafe.Pointer(pTab)).FzColAff = zColAff
	}
	i = int32(libc.Xstrlen(tls, zColAff) & libc.Uint32FromInt32(0x3fffffff))
	if i != 0 {
		if iReg != 0 {
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), iReg, i, 0, zColAff, i)
		} else {
			_sqlite3VdbeChangeP4(tls, v, -int32(1), zColAff, i)
		}
	}
}

// C documentation
//
//	/*
//	** Return non-zero if the table pTab in database iDb or any of its indices
//	** have been opened at any point in the VDBE program. This is used to see if
//	** a statement of the form  "INSERT INTO <iDb, pTab> SELECT ..." can
//	** run without using a temporary table for the results of the SELECT.
//	*/
func _readsTable(tls *libc.TLS, p uintptr, iDb int32, pTab uintptr) (r int32) {
	var i, iEnd int32
	var pIndex, pOp, pVTab, v, v1 uintptr
	var tnum TPgno
	_, _, _, _, _, _, _, _ = i, iEnd, pIndex, pOp, pVTab, tnum, v, v1
	v = _sqlite3GetVdbe(tls, p)
	iEnd = _sqlite3VdbeCurrentAddr(tls, v)
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		v1 = _sqlite3GetVTable(tls, (*TParse)(unsafe.Pointer(p)).Fdb, pTab)
	} else {
		v1 = uintptr(0)
	}
	pVTab = v1
	i = int32(1)
	for {
		if !(i < iEnd) {
			break
		}
		pOp = _sqlite3VdbeGetOp(tls, v, i)
		if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_OpenRead) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 == iDb {
			tnum = uint32((*TVdbeOp)(unsafe.Pointer(pOp)).Fp2)
			if tnum == (*TTable)(unsafe.Pointer(pTab)).Ftnum {
				return int32(1)
			}
			pIndex = (*TTable)(unsafe.Pointer(pTab)).FpIndex
			for {
				if !(pIndex != 0) {
					break
				}
				if tnum == (*TIndex)(unsafe.Pointer(pIndex)).Ftnum {
					return int32(1)
				}
				goto _3
			_3:
				;
				pIndex = (*TIndex)(unsafe.Pointer(pIndex)).FpNext
			}
		}
		if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_VOpen) && *(*uintptr)(unsafe.Pointer(pOp + 16)) == pVTab {
			return int32(1)
		}
		goto _2
	_2:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/* This walker callback will compute the union of colFlags flags for all
//	** referenced columns in a CHECK constraint or generated column expression.
//	*/
func _exprColumnFlagUnion(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var p1 uintptr
	_ = p1
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) >= 0 {
		p1 = pWalker + 20
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | int32((*(*TColumn)(unsafe.Pointer((*TTable1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 24)))).FaCol + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)*12))).FcolFlags))
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** All regular columns for table pTab have been puts into registers
//	** starting with iRegStore.  The registers that correspond to STORED
//	** or VIRTUAL columns have not yet been initialized.  This routine goes
//	** back and computes the values for those columns based on the previously
//	** computed normal columns.
//	*/
func _sqlite3ComputeGeneratedColumns(tls *libc.TLS, pParse uintptr, iRegStore int32, pTab uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var eProgress, i, ii, jj, x, v2 int32
	var pCol, pOp, pRedo, zP4, p4, p6, p7, p8 uintptr
	var _ /* w at bp+0 */ TWalker
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = eProgress, i, ii, jj, pCol, pOp, pRedo, x, zP4, v2, p4, p6, p7, p8
	/* Before computing generated columns, first go through and make sure
	 ** that appropriate affinity has been applied to the regular columns
	 */
	_sqlite3TableAffinity(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, pTab, iRegStore)
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasStored) != uint32(0) {
		pOp = _sqlite3VdbeGetLastOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe)
		if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Affinity) {
			zP4 = *(*uintptr)(unsafe.Pointer(pOp + 16))
			v2 = libc.Int32FromInt32(0)
			jj = v2
			ii = v2
			for {
				if !(*(*int8)(unsafe.Pointer(zP4 + uintptr(jj))) != 0) {
					break
				}
				if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(ii)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					goto _1
				}
				if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(ii)*12))).FcolFlags)&int32(COLFLAG_STORED) != 0 {
					*(*int8)(unsafe.Pointer(zP4 + uintptr(jj))) = int8(SQLITE_AFF_NONE)
				}
				jj++
				goto _1
			_1:
				;
				ii++
			}
		} else {
			if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_TypeCheck) {
				/* If an OP_TypeCheck was generated because the table is STRICT,
				 ** then set the P3 operand to indicate that generated columns should
				 ** not be checked */
				(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 = int32(1)
			}
		}
	}
	/* Because there can be multiple generated columns that refer to one another,
	 ** this is a two-pass algorithm.  On the first pass, mark all generated
	 ** columns as "not available".
	 */
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
			p4 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12 + 10
			*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(COLFLAG_NOTAVAIL))
		}
		goto _3
	_3:
		;
		i++
	}
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pTab
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprColumnFlagUnion)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = uintptr(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = uintptr(0)
	/* On the second pass, compute the value of each NOT-AVAILABLE column.
	 ** Companion code in the TK_COLUMN case of sqlite3ExprCodeTarget() will
	 ** compute dependencies and mark remove the COLSPAN_NOTAVAIL mark, as
	 ** they are needed.
	 */
	(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -iRegStore
	for cond := true; cond; cond = pRedo != 0 && eProgress != 0 {
		eProgress = 0
		pRedo = uintptr(0)
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12
			if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_NOTAVAIL) != 0 {
				p6 = pCol + 10
				*(*Tu16)(unsafe.Pointer(p6)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p6))) | libc.Int32FromInt32(COLFLAG_BUSY))
				(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(0)
				_sqlite3WalkExpr(tls, bp, _sqlite3ColumnExpr(tls, pTab, pCol))
				p7 = pCol + 10
				*(*Tu16)(unsafe.Pointer(p7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p7))) & ^libc.Int32FromInt32(COLFLAG_BUSY))
				if int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)&int32(COLFLAG_NOTAVAIL) != 0 {
					pRedo = pCol
					goto _5
				}
				eProgress = int32(1)
				x = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(int16(i)))) + iRegStore
				_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab, pCol, x)
				p8 = pCol + 10
				*(*Tu16)(unsafe.Pointer(p8)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p8))) & ^libc.Int32FromInt32(COLFLAG_NOTAVAIL))
			}
			goto _5
		_5:
			;
			i++
		}
	}
	if pRedo != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9596, libc.VaList(bp+40, (*TColumn)(unsafe.Pointer(pRedo)).FzCnName))
	}
	(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
}

// C documentation
//
//	/*
//	** Locate or create an AutoincInfo structure associated with table pTab
//	** which is in database iDb.  Return the register number for the register
//	** that holds the maximum rowid.  Return zero if pTab is not an AUTOINCREMENT
//	** table.  (Also return zero when doing a VACUUM since we do not want to
//	** update the AUTOINCREMENT counters during a VACUUM.)
//	**
//	** There is at most one AutoincInfo structure per table even if the
//	** same table is autoincremented multiple times due to inserts within
//	** triggers.  A new AutoincInfo structure is created if this is the
//	** first use of table pTab.  On 2nd and subsequent uses, the original
//	** AutoincInfo structure is used.
//	**
//	** Four consecutive registers are allocated:
//	**
//	**   (1)  The name of the pTab table.
//	**   (2)  The maximum ROWID of pTab.
//	**   (3)  The rowid in sqlite_sequence of pTab
//	**   (4)  The original value of the max ROWID in pTab, or NULL if none
//	**
//	** The 2nd register is the one that is returned.  That is all the
//	** insert routine needs to know about.
//	*/
func _autoIncBegin(tls *libc.TLS, pParse uintptr, iDb int32, pTab uintptr) (r int32) {
	var memId, v2 int32
	var pInfo, pSeqTab, pToplevel, v1, v3 uintptr
	_, _, _, _, _, _, _ = memId, pInfo, pSeqTab, pToplevel, v1, v2, v3
	memId = 0 /* Register holding maximum rowid */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Autoincrement) != uint32(0) && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) {
		if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
		} else {
			v1 = pParse
		}
		pToplevel = v1
		pSeqTab = (*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FpSchema)).FpSeqTab
		/* Verify that the sqlite_sequence table exists and is an ordinary
		 ** rowid table with exactly two columns.
		 ** Ticket d8dc2b3a58cd5dc2918a1d4acb 2018-05-23 */
		if pSeqTab == uintptr(0) || !((*TTable)(unsafe.Pointer(pSeqTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) || int32((*TTable)(unsafe.Pointer(pSeqTab)).FeTabType) == int32(TABTYP_VTAB) || int32((*TTable)(unsafe.Pointer(pSeqTab)).FnCol) != int32(2) {
			(*TParse)(unsafe.Pointer(pParse)).FnErr++
			(*TParse)(unsafe.Pointer(pParse)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
			return 0
		}
		pInfo = (*TParse)(unsafe.Pointer(pToplevel)).FpAinc
		for pInfo != 0 && (*TAutoincInfo)(unsafe.Pointer(pInfo)).FpTab != pTab {
			pInfo = (*TAutoincInfo)(unsafe.Pointer(pInfo)).FpNext
		}
		if pInfo == uintptr(0) {
			pInfo = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(16))
			_sqlite3ParserAddCleanup(tls, pToplevel, __ccgo_fp(_sqlite3DbFree), pInfo)
			if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
				return 0
			}
			(*TAutoincInfo)(unsafe.Pointer(pInfo)).FpNext = (*TParse)(unsafe.Pointer(pToplevel)).FpAinc
			(*TParse)(unsafe.Pointer(pToplevel)).FpAinc = pInfo
			(*TAutoincInfo)(unsafe.Pointer(pInfo)).FpTab = pTab
			(*TAutoincInfo)(unsafe.Pointer(pInfo)).FiDb = iDb
			(*TParse)(unsafe.Pointer(pToplevel)).FnMem++ /* Register to hold name of table */
			v3 = pToplevel + 44
			*(*int32)(unsafe.Pointer(v3))++
			v2 = *(*int32)(unsafe.Pointer(v3))
			(*TAutoincInfo)(unsafe.Pointer(pInfo)).FregCtr = v2   /* Max rowid register */
			*(*int32)(unsafe.Pointer(pToplevel + 44)) += int32(2) /* Rowid in sqlite_sequence + orig max val */
		}
		memId = (*TAutoincInfo)(unsafe.Pointer(pInfo)).FregCtr
	}
	return memId
}

// C documentation
//
//	/*
//	** This routine generates code that will initialize all of the
//	** register used by the autoincrement tracker.
//	*/
func _sqlite3AutoincrementBegin(tls *libc.TLS, pParse uintptr) {
	var aOp, db, p, pDb, v uintptr
	var memId int32
	_, _, _, _, _, _ = aOp, db, memId, p, pDb, v /* Information about an AUTOINCREMENT */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb   /* Register holding max rowid */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* VDBE under construction */
	/* This routine is never called during trigger-generation.  It is
	 ** only called from the top-level */
	/* We failed long ago if this is not so */
	p = (*TParse)(unsafe.Pointer(pParse)).FpAinc
	for {
		if !(p != 0) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TAutoincInfo)(unsafe.Pointer(p)).FiDb)*16
		memId = (*TAutoincInfo)(unsafe.Pointer(p)).FregCtr
		_sqlite3OpenTable(tls, pParse, 0, (*TAutoincInfo)(unsafe.Pointer(p)).FiDb, (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab, int32(OP_OpenRead))
		_sqlite3VdbeLoadString(tls, v, memId-int32(1), (*TTable)(unsafe.Pointer((*TAutoincInfo)(unsafe.Pointer(p)).FpTab)).FzName)
		aOp = _sqlite3VdbeAddOpList(tls, v, int32(libc.Uint32FromInt64(48)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_autoInc)), _iLn1)
		if aOp == uintptr(0) {
			break
		}
		(*(*TVdbeOp)(unsafe.Pointer(aOp))).Fp2 = memId
		(*(*TVdbeOp)(unsafe.Pointer(aOp))).Fp3 = memId + int32(2)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 2*20))).Fp3 = memId
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 3*20))).Fp1 = memId - int32(1)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 3*20))).Fp3 = memId
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 3*20))).Fp5 = uint16(SQLITE_JUMPIFNULL)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 4*20))).Fp2 = memId + int32(1)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 5*20))).Fp3 = memId
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 6*20))).Fp1 = memId
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 7*20))).Fp2 = memId + int32(2)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 7*20))).Fp1 = memId
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 10*20))).Fp2 = memId
		if (*TParse)(unsafe.Pointer(pParse)).FnTab == 0 {
			(*TParse)(unsafe.Pointer(pParse)).FnTab = int32(1)
		}
		goto _1
	_1:
		;
		p = (*TAutoincInfo)(unsafe.Pointer(p)).FpNext
	}
}

var _iLn1 int32

var _autoInc = [12]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_Null),
	},
	1: {
		Fopcode: uint8(OP_Rewind),
		Fp2:     int8(10),
	},
	2: {
		Fopcode: uint8(OP_Column),
	},
	3: {
		Fopcode: uint8(OP_Ne),
		Fp2:     int8(9),
	},
	4: {
		Fopcode: uint8(OP_Rowid),
	},
	5: {
		Fopcode: uint8(OP_Column),
		Fp2:     int8(1),
	},
	6: {
		Fopcode: uint8(OP_AddImm),
	},
	7: {
		Fopcode: uint8(OP_Copy),
	},
	8: {
		Fopcode: uint8(OP_Goto),
		Fp2:     int8(11),
	},
	9: {
		Fopcode: uint8(OP_Next),
		Fp2:     int8(2),
	},
	10: {
		Fopcode: uint8(OP_Integer),
	},
	11: {
		Fopcode: uint8(OP_Close),
	},
}

// C documentation
//
//	/*
//	** Update the maximum rowid for an autoincrement calculation.
//	**
//	** This routine should be called when the regRowid register holds a
//	** new rowid that is about to be inserted.  If that new rowid is
//	** larger than the maximum rowid in the memId memory cell, then the
//	** memory cell is updated.
//	*/
func _autoIncStep(tls *libc.TLS, pParse uintptr, memId int32, regRowid int32) {
	if memId > 0 {
		_sqlite3VdbeAddOp2(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_MemMax), memId, regRowid)
	}
}

// C documentation
//
//	/*
//	** This routine generates the code needed to write autoincrement
//	** maximum rowid values back into the sqlite_sequence register.
//	** Every statement that might do an INSERT into an autoincrement
//	** table (either directly or through triggers) needs to call this
//	** routine just before the "exit" code.
//	*/
func _autoIncrementEnd(tls *libc.TLS, pParse uintptr) {
	var aOp, db, p, pDb, v uintptr
	var iRec, memId int32
	_, _, _, _, _, _, _ = aOp, db, iRec, memId, p, pDb, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	p = (*TParse)(unsafe.Pointer(pParse)).FpAinc
	for {
		if !(p != 0) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TAutoincInfo)(unsafe.Pointer(p)).FiDb)*16
		memId = (*TAutoincInfo)(unsafe.Pointer(p)).FregCtr
		iRec = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Le), memId+int32(2), _sqlite3VdbeCurrentAddr(tls, v)+int32(7), memId)
		_sqlite3OpenTable(tls, pParse, 0, (*TAutoincInfo)(unsafe.Pointer(p)).FiDb, (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab, int32(OP_OpenWrite))
		aOp = _sqlite3VdbeAddOpList(tls, v, int32(libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_autoIncEnd)), _iLn2)
		if aOp == uintptr(0) {
			break
		}
		(*(*TVdbeOp)(unsafe.Pointer(aOp))).Fp1 = memId + int32(1)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 1*20))).Fp2 = memId + int32(1)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 2*20))).Fp1 = memId - int32(1)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 2*20))).Fp3 = iRec
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 3*20))).Fp2 = iRec
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 3*20))).Fp3 = memId + int32(1)
		(*(*TVdbeOp)(unsafe.Pointer(aOp + 3*20))).Fp5 = uint16(OPFLAG_APPEND)
		_sqlite3ReleaseTempReg(tls, pParse, iRec)
		goto _1
	_1:
		;
		p = (*TAutoincInfo)(unsafe.Pointer(p)).FpNext
	}
}

var _iLn2 int32

var _autoIncEnd = [5]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_NotNull),
		Fp2:     int8(2),
	},
	1: {
		Fopcode: uint8(OP_NewRowid),
	},
	2: {
		Fopcode: uint8(OP_MakeRecord),
		Fp2:     int8(2),
	},
	3: {
		Fopcode: uint8(OP_Insert),
	},
	4: {
		Fopcode: uint8(OP_Close),
	},
}

func _sqlite3AutoincrementEnd(tls *libc.TLS, pParse uintptr) {
	if (*TParse)(unsafe.Pointer(pParse)).FpAinc != 0 {
		_autoIncrementEnd(tls, pParse)
	}
}

// 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
		_sqlite3VdbeEndCoroutine(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TSrcItem)(unsafe.Pointer(pItem)).FregReturn)
		_sqlite3VdbeJumpHere(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TSrcItem)(unsafe.Pointer(pItem)).FaddrFillSub-int32(1))
	}
}

// C documentation
//
//	/*
//	** Return true if all expressions in the expression-list passed as the
//	** only argument are constant.
//	*/
func _exprListIsConstant(tls *libc.TLS, pParse uintptr, pRow uintptr) (r int32) {
	var ii int32
	_ = ii
	ii = 0
	for {
		if !(ii < (*TExprList)(unsafe.Pointer(pRow)).FnExpr) {
			break
		}
		if 0 == _sqlite3ExprIsConstant(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pRow + 8 + uintptr(ii)*20))).FpExpr) {
			return 0
		}
		goto _1
	_1:
		;
		ii++
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Return true if all expressions in the expression-list passed as the
//	** only argument are both constant and have no affinity.
//	*/
func _exprListIsNoAffinity(tls *libc.TLS, pParse uintptr, pRow uintptr) (r int32) {
	var ii int32
	var pExpr uintptr
	_, _ = ii, pExpr
	if _exprListIsConstant(tls, pParse, pRow) == 0 {
		return 0
	}
	ii = 0
	for {
		if !(ii < (*TExprList)(unsafe.Pointer(pRow)).FnExpr) {
			break
		}
		pExpr = (*(*TExprList_item)(unsafe.Pointer(pRow + 8 + uintptr(ii)*20))).FpExpr
		if 0 != int32(_sqlite3ExprAffinity(tls, pExpr)) {
			return 0
		}
		goto _1
	_1:
		;
		ii++
	}
	return int32(1)
}

// 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(32)
	defer tls.Free(32)
	var f, v1 int32
	var p, pRet, pSelect, v, v2 uintptr
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _, _, _, _ = f, p, pRet, pSelect, v, v1, v2
	if (*TParse)(unsafe.Pointer(pParse)).FbHasWith != 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 || int32((*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 = int32(uint32(uint32(f)) & (*TSelect)(unsafe.Pointer(pLeft)).FselFlags)
			}
		}
		pSelect = _sqlite3SelectNew(tls, pParse, pRow, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(uint32(f)), uintptr(0))
		*(*Tu32)(unsafe.Pointer(pLeft + 4)) &= uint32(^libc.Int32FromInt32(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
				(*TSelect)(unsafe.Pointer(pLeft)).FpPrior = uintptr(0)
				(*TSelect)(unsafe.Pointer(pLeft)).Fop = uint8(TK_SELECT)
				p = (*TSelect)(unsafe.Pointer(pRet)).FpSrc + 8
				(*TSrcItem)(unsafe.Pointer(p)).FpSelect = pLeft
				libc.SetBitFieldPtr16Uint32(p+36+4, libc.Uint32FromInt32(1), 5, 0x20)
				(*TSrcItem)(unsafe.Pointer(p)).FaddrFillSub = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
				v2 = pParse + 44
				*(*int32)(unsafe.Pointer(v2))++
				v1 = *(*int32)(unsafe.Pointer(v2))
				(*TSrcItem)(unsafe.Pointer(p)).FregReturn = v1
				(*TSrcItem)(unsafe.Pointer(p)).FiCursor = -int32(1)
				*(*Tu32)(unsafe.Pointer(p + 64)) = uint32(2)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), (*TSrcItem)(unsafe.Pointer(p)).FregReturn, 0, (*TSrcItem)(unsafe.Pointer(p)).FaddrFillSub)
				_sqlite3SelectDestInit(tls, bp, int32(SRT_Coroutine), (*TSrcItem)(unsafe.Pointer(p)).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)(unsafe.Pointer(bp))).FiSdst = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(3)
				(*(*TSelectDest)(unsafe.Pointer(bp))).FnSdst = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pLeft)).FpEList)).FnExpr
				*(*int32)(unsafe.Pointer(pParse + 44)) += int32(2) + (*(*TSelectDest)(unsafe.Pointer(bp))).FnSdst
				*(*Tu32)(unsafe.Pointer(pLeft + 4)) |= uint32(SF_MultiValue)
				_sqlite3Select(tls, pParse, pLeft, bp)
				(*TSrcItem)(unsafe.Pointer(p)).FregResult = (*(*TSelectDest)(unsafe.Pointer(bp))).FiSdst
				pLeft = pRet
			}
		} else {
			p = (*TSelect)(unsafe.Pointer(pLeft)).FpSrc + 8
			*(*Tu32)(unsafe.Pointer(p + 64))++
		}
		if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
			if (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(p)).FpSelect)).FpEList)).FnExpr != (*TExprList)(unsafe.Pointer(pRow)).FnExpr {
				_sqlite3SelectWrongNumTermsError(tls, pParse, (*TSrcItem)(unsafe.Pointer(p)).FpSelect)
			} else {
				_sqlite3ExprCodeExprList(tls, pParse, pRow, (*TSrcItem)(unsafe.Pointer(p)).FregResult, 0, uint8(0))
				_sqlite3VdbeAddOp1(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Yield), (*TSrcItem)(unsafe.Pointer(p)).FregReturn)
			}
		}
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pRow)
	}
	return pLeft
}

// 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(112)
	defer tls.Free(112)
	var aRegIdx, db, pIdx, pIpk, pItem, pList, pNx, pTab, pTrigger, pVTab, pX, v, v10, v14, v17, v19, v7 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, v13, v16, v18, v20, v24, v25, v5, v6, v8, v9 int32
	var appendFlag, bIdListInOrder, useTempTable, withoutRowid Tu8
	var colFlags, v22 Tu32
	var _ /* dest at bp+8 */ TSelectDest
	var _ /* iDataCur at bp+0 */ int32
	var _ /* iIdxCur at bp+4 */ int32
	var _ /* isReplace at bp+76 */ int32
	var _ /* sNC at bp+40 */ TNameContext
	var _ /* tmask at bp+36 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aRegIdx, 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, pTab, pTrigger, pVTab, pX, rc, regAutoinc, regCols, regData, regFromSelect, regIns, regRec, regRowCount, regRowid, regTempRowid, regYield, srcTab, useTempTable, v, withoutRowid, y, v1, v10, v13, v14, v16, v17, v18, v19, v20, v22, v24, v25, v5, v6, v7, v8, v9 /* Number of columns in the data */
	nHidden = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            /* Number of hidden columns if TABLE is virtual */
	*(*int32)(unsafe.Pointer(bp)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* VDBE cursor that is the main data repository */
	*(*int32)(unsafe.Pointer(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) /* Mask of trigger times */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto insert_cleanup
	}
	(*(*TSelectDest)(unsafe.Pointer(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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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+36)
	isView = libc.BoolInt32(int32((*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 int32((*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)(unsafe.Pointer(pParse + 44)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol) + int32(1)
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		regRowid++
		(*TParse)(unsafe.Pointer(pParse)).FnMem++
	}
	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&uint32(libc.Int32FromInt32(TF_OOOHidden)|libc.Int32FromInt32(TF_HasStored)) == uint32(0))
	if pColumn != 0 {
		(*TIdList)(unsafe.Pointer(pColumn)).FeU4 = uint8(EU4_IDX)
		i = 0
		for {
			if !(i < (*TIdList)(unsafe.Pointer(pColumn)).FnId) {
				break
			}
			*(*int32)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8 + 4)) = -int32(1)
			goto _2
		_2:
			;
			i++
		}
		i = 0
		for {
			if !(i < (*TIdList)(unsafe.Pointer(pColumn)).FnId) {
				break
			}
			j = 0
			for {
				if !(j < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if _sqlite3StrICmp(tls, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FzCnName) == 0 {
					*(*int32)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8 + 4)) = j
					if i != j {
						bIdListInOrder = uint8(0)
					}
					if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
						ipkColumn = i
					}
					if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FcolFlags)&(libc.Int32FromInt32(COLFLAG_STORED)|libc.Int32FromInt32(COLFLAG_VIRTUAL)) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17477, libc.VaList(bp+88, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FzCnName))
						goto insert_cleanup
					}
					break
				}
				goto _4
			_4:
				;
				j++
			}
			if j >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
				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+17518, libc.VaList(bp+88, pTabList+8, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName))
					(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
					goto insert_cleanup
				}
			}
			goto _3
		_3:
			;
			i++
		}
	}
	/* 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(*(*uint16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8 + 36 + 4))&0x20>>5)) != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FpPrior == uintptr(0) {
			pItem = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8
			(*(*TSelectDest)(unsafe.Pointer(bp + 8))).FiSDParm = (*TSrcItem)(unsafe.Pointer(pItem)).FregReturn
			regFromSelect = (*TSrcItem)(unsafe.Pointer(pItem)).FregResult
			nColumn = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpEList)).FnExpr
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+17550, libc.VaList(bp+88, pItem))
			if bIdListInOrder != 0 && nColumn == int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
				regData = regFromSelect
				regRowid = regData - int32(1)
				if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					v5 = int32(1)
				} else {
					v5 = 0
				}
				regIns = regRowid - v5
			}
		} else {
			v7 = pParse + 44
			*(*int32)(unsafe.Pointer(v7))++
			v6 = *(*int32)(unsafe.Pointer(v7)) /* Top of the co-routine */
			regYield = v6
			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 {
				v8 = regData
			} else {
				v8 = 0
			}
			(*(*TSelectDest)(unsafe.Pointer(bp + 8))).FiSdst = v8
			(*(*TSelectDest)(unsafe.Pointer(bp + 8))).FnSdst = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
			rc = _sqlite3Select(tls, pParse, pSelect, bp+8)
			regFromSelect = (*(*TSelectDest)(unsafe.Pointer(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" */
			v10 = pParse + 40
			v9 = *(*int32)(unsafe.Pointer(v10))
			*(*int32)(unsafe.Pointer(v10))++
			srcTab = v9
			regRec = _sqlite3GetTempReg(tls, pParse)
			regTempRowid = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), srcTab, nColumn)
			addrL = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*(*TSelectDest)(unsafe.Pointer(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+40, 0, uint32(36))
		(*(*TNameContext)(unsafe.Pointer(bp + 40))).FpParse = pParse
		srcTab = -int32(1)
		if pList != 0 {
			nColumn = (*TExprList)(unsafe.Pointer(pList)).FnExpr
			if _sqlite3ResolveExprListNames(tls, bp+40, 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 int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					ipkColumn--
				}
				goto _11
			_11:
				;
				i--
			}
		}
		/* 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&uint32(libc.Int32FromInt32(TF_HasGenerated)|libc.Int32FromInt32(TF_HasHidden)) != uint32(0) {
			i = 0
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_NOINSERT) != 0 {
					nHidden++
				}
				goto _12
			_12:
				;
				i++
			}
		}
		if nColumn != int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-nHidden {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17558, libc.VaList(bp+88, 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+17610, libc.VaList(bp+88, nColumn, (*TIdList)(unsafe.Pointer(pColumn)).FnId))
		goto insert_cleanup
	}
	/* Initialize the count of rows to be inserted
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(uint64(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !((*TParse)(unsafe.Pointer(pParse)).FbReturning != 0) {
		v14 = pParse + 44
		*(*int32)(unsafe.Pointer(v14))++
		v13 = *(*int32)(unsafe.Pointer(v14))
		regRowCount = v13
		_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(uint32(4)*uint32(nIdx+libc.Int32FromInt32(2))))
		if aRegIdx == uintptr(0) {
			goto insert_cleanup
		}
		i = 0
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(i < nIdx) {
				break
			}
			v17 = pParse + 44
			*(*int32)(unsafe.Pointer(v17))++
			v16 = *(*int32)(unsafe.Pointer(v17))
			*(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)) = v16
			*(*int32)(unsafe.Pointer(pParse + 44)) += int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
			goto _15
		_15:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
			i++
		}
		v19 = pParse + 44
		*(*int32)(unsafe.Pointer(v19))++
		v18 = *(*int32)(unsafe.Pointer(v19))
		*(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)) = v18 /* Register to store the table record */
	}
	if pUpsert != 0 {
		if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17635, libc.VaList(bp+88, (*TTable)(unsafe.Pointer(pTab)).FzName))
			goto insert_cleanup
		}
		if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17681, 0)
			goto insert_cleanup
		}
		if _sqlite3HasExplicitNulls(tls, pParse, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget) != 0 {
			goto insert_cleanup
		}
		(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp))
			(*TUpsert)(unsafe.Pointer(pNx)).FiIdxCur = *(*int32)(unsafe.Pointer(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: ...
			 */
			v20 = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*(*TSelectDest)(unsafe.Pointer(bp + 8))).FiSDParm)
			addrCont = v20
			addrInsTop = v20
			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 _21
		}
		v22 = uint32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)
		colFlags = v22
		if v22&uint32(COLFLAG_NOINSERT) != uint32(0) {
			nHidden++
			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--
				goto _21
			} 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)(unsafe.Pointer(bp + 36))&int32(TRIGGER_BEFORE) != 0 {
						_sqlite3VdbeAddOp1(tls, v, int32(OP_SoftNull), iRegStore)
					}
					goto _21
				} else {
					if pColumn == uintptr(0) {
						/* Hidden columns that are not explicitly named in the INSERT
						 ** get there default value */
						_sqlite3ExprCodeFactorable(tls, pParse, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*12), iRegStore)
						goto _21
					}
				}
			}
		}
		if pColumn != 0 {
			j = 0
			for {
				if !(j < (*TIdList)(unsafe.Pointer(pColumn)).FnId && *(*int32)(unsafe.Pointer(pColumn + 8 + uintptr(j)*8 + 4)) != i) {
					break
				}
				goto _23
			_23:
				;
				j++
			}
			if j >= (*TIdList)(unsafe.Pointer(pColumn)).FnId {
				/* 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)*12), iRegStore)
				goto _21
			}
			k = j
		} 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)*12), iRegStore)
				goto _21
			} 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)*20))).FpExpr
				y = _sqlite3ExprCodeTarget(tls, pParse, pX, iRegStore)
				if y != iRegStore {
					if (*TExpr)(unsafe.Pointer(pX)).Fflags&uint32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
						v24 = int32(OP_Copy)
					} else {
						v24 = int32(OP_SCopy)
					}
					_sqlite3VdbeAddOp2(tls, v, v24, y, iRegStore)
				}
			}
		}
		goto _21
	_21:
		;
		i++
		iRegStore++
	}
	/* Run the BEFORE and INSTEAD OF triggers, if there are any
	 */
	endOfLoop = _sqlite3VdbeMakeLabel(tls, pParse)
	if *(*int32)(unsafe.Pointer(bp + 36))&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)*20))).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 int32((*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)*20))).FpExpr
					if int32((*TExpr)(unsafe.Pointer(pIpk)).Fop) == int32(TK_NULL) && !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), *(*int32)(unsafe.Pointer(bp)), regRowid, regAutoinc)
						appendFlag = uint8(1)
					} else {
						_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*20))).FpExpr, regRowid)
					}
				}
			}
			/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
			 ** to generate a unique primary key value.
			 */
			if !(appendFlag != 0) {
				if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
					addr11 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), regRowid)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), *(*int32)(unsafe.Pointer(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 int32((*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)(unsafe.Pointer(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 int32((*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(11))
			if onError == int32(OE_Default) {
				v25 = int32(OE_Abort)
			} else {
				v25 = onError
			}
			_sqlite3VdbeChangeP5(tls, v, uint16(v25))
			_sqlite3MayAbort(tls, pParse)
		} else {
			*(*int32)(unsafe.Pointer(bp + 76)) = 0 /* True to use OPFLAG_SEEKRESULT */
			_sqlite3GenerateConstraintChecks(tls, pParse, pTab, aRegIdx, *(*int32)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)), regIns, 0, libc.BoolUint8(ipkColumn >= 0), uint8(uint8(onError)), endOfLoop, bp+76, 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)(unsafe.Pointer(bp + 76)) == 0 || !(_sqlite3VdbeHasSubProgram(tls, v) != 0))
			_sqlite3CompleteInsertion(tls, pParse, pTab, *(*int32)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)), regIns, aRegIdx, 0, int32(int32(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 int32((*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+17702)
	}
	goto insert_cleanup
insert_cleanup:
	;
	_sqlite3SrcListDelete(tls, db, pTabList)
	_sqlite3ExprListDelete(tls, db, pList)
	_sqlite3UpsertDelete(tls, db, pUpsert)
	_sqlite3SelectDelete(tls, db, pSelect)
	_sqlite3IdListDelete(tls, db, pColumn)
	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
//
//	/* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn().
//	*  Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this
//	** expression node references any of the
//	** columns that are being modified by an UPDATE statement.
//	*/
func _checkConstraintExprNode(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var p1, p2 uintptr
	_, _ = p1, p2
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) >= 0 {
			if *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 24)) + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)*4)) >= 0 {
				p1 = pWalker + 20
				*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(CKCNSTRNT_COLUMN))
			}
		} else {
			p2 = pWalker + 20
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(CKCNSTRNT_ROWID))
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** pExpr is a CHECK constraint on a row that is being UPDATE-ed.  The
//	** only columns that are modified by the UPDATE are those for which
//	** aiChng[i]>=0, and also the ROWID is modified if chngRowid is true.
//	**
//	** Return true if CHECK constraint pExpr uses any of the
//	** changing columns (or the rowid if it is changing).  In other words,
//	** return true if this CHECK constraint must be validated for
//	** the new row in the UPDATE statement.
//	**
//	** 2018-09-15: pExpr might also be an expression for an index-on-expressions.
//	** The operation of this routine is the same - return true if an only if
//	** the expression uses one or more of columns identified by the second and
//	** third arguments.
//	*/
func _sqlite3ExprReferencesUpdatedColumn(tls *libc.TLS, pExpr uintptr, aiChng uintptr, chngRowid int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p1 uintptr
	var _ /* w at bp+0 */ TWalker
	_ = p1
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(0)
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_checkConstraintExprNode)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = aiChng
	_sqlite3WalkExpr(tls, bp, pExpr)
	if !(chngRowid != 0) {
		p1 = bp + 20
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) & ^libc.Int32FromInt32(CKCNSTRNT_ROWID))
	}
	return libc.BoolInt32(int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode) != 0)
}

// C documentation
//
//	/*
//	** The sqlite3GenerateConstraintChecks() routine usually wants to visit
//	** the indexes of a table in the order provided in the Table->pIndex list.
//	** However, sometimes (rarely - when there is an upsert) it wants to visit
//	** the indexes in a different order.  The following data structures accomplish
//	** this.
//	**
//	** The IndexIterator object is used to walk through all of the indexes
//	** of a table in either Index.pNext order, or in some other order established
//	** by an array of IndexListTerm objects.
//	*/
type TIndexListTerm = struct {
	Fp  uintptr
	Fix int32
}

type IndexListTerm = TIndexListTerm

type TIndexIterator = struct {
	FeType int32
	Fi     int32
	Fu     struct {
		Fax [0]struct {
			FnIdx int32
			FaIdx uintptr
		}
		Flx struct {
			FpIdx uintptr
		}
		F__ccgo_pad2 [4]byte
	}
}

type IndexIterator = TIndexIterator

type TIndexIterator1 = struct {
	FeType int32
	Fi     int32
	Fu     struct {
		Fax [0]struct {
			FnIdx int32
			FaIdx uintptr
		}
		Flx struct {
			FpIdx uintptr
		}
		F__ccgo_pad2 [4]byte
	}
}

type IndexIterator1 = TIndexIterator1

/* When IndexIterator.eType==1, then each index is an array of instances
** of the following object
 */
type TIndexListTerm1 = struct {
	Fp  uintptr
	Fix int32
}

type IndexListTerm1 = TIndexListTerm1

// C documentation
//
//	/* Return the first index on the list */
func _indexIteratorFirst(tls *libc.TLS, pIter uintptr, pIx uintptr) (r uintptr) {
	if (*TIndexIterator)(unsafe.Pointer(pIter)).FeType != 0 {
		*(*int32)(unsafe.Pointer(pIx)) = (*(*TIndexListTerm)(unsafe.Pointer((*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FaIdx))).Fix
		return (*(*TIndexListTerm)(unsafe.Pointer((*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FaIdx))).Fp
	} else {
		*(*int32)(unsafe.Pointer(pIx)) = 0
		return (*TIndexIterator)(unsafe.Pointer(pIter)).Fu.Flx.FpIdx
	}
	return r
}

// C documentation
//
//	/* Return the next index from the list.  Return NULL when out of indexes */
func _indexIteratorNext(tls *libc.TLS, pIter uintptr, pIx uintptr) (r uintptr) {
	var i, v1 int32
	var v2 uintptr
	_, _, _ = i, v1, v2
	if (*TIndexIterator)(unsafe.Pointer(pIter)).FeType != 0 {
		v2 = pIter + 4
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		i = v1
		if i >= (*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FnIdx {
			*(*int32)(unsafe.Pointer(pIx)) = i
			return uintptr(0)
		}
		*(*int32)(unsafe.Pointer(pIx)) = (*(*TIndexListTerm)(unsafe.Pointer((*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FaIdx + uintptr(i)*8))).Fix
		return (*(*TIndexListTerm)(unsafe.Pointer((*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FaIdx + uintptr(i)*8))).Fp
	} else {
		*(*int32)(unsafe.Pointer(pIx))++
		(*TIndexIterator)(unsafe.Pointer(pIter)).Fu.Flx.FpIdx = (*TIndex)(unsafe.Pointer((*TIndexIterator)(unsafe.Pointer(pIter)).Fu.Flx.FpIdx)).FpNext
		return (*TIndexIterator)(unsafe.Pointer(pIter)).Fu.Flx.FpIdx
	}
	return r
}

// 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(64)
	defer tls.Free(64)
	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, v11, v13, v15, v2, v7 int32
	var bAffinityDone, isUpdate Tu8
	var bUsed, db, p4, pCheck, pCol, pCopy, pExpr, pIdx, pPk, pTerm, pTrigger, pUpsertClause, v, zMsg, zName, zP4, v16, v8 uintptr
	var nByte Tu64
	var _ /* ix at bp+0 */ int32
	var _ /* sIdxIter at bp+4 */ TIndexIterator
	var _ /* x at bp+20 */ 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, v11, v13, v15, v16, v2, v7, 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 = int32((*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)*12 /* non-zero if column is generated */
				onError = int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4)) & 0xf >> 0))
				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 = int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags) & int32(COLFLAG_GENERATED)
				if isGenerated != 0 && !(b2ndPass != 0) {
					nGenerated++
					goto _1 /* Generated columns processed on 2nd pass */
				}
				if aiChng != 0 && *(*int32)(unsafe.Pointer(aiChng + uintptr(i)*4)) < 0 && !(isGenerated != 0) {
					/* Do not check NOT NULL on columns that do not change */
					goto _1
				}
				if int32(int32(overrideError)) != int32(OE_Default) {
					onError = int32(int32(overrideError))
				} else {
					if onError == int32(OE_Default) {
						onError = int32(OE_Abort)
					}
				}
				if onError == int32(OE_Replace) {
					if b2ndPass != 0 || int32((*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(int16(i)))) + regNewData + int32(1)
				switch onError {
				case int32(OE_Replace):
					addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), iReg)
					nSeenReplace++
					_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+13815, libc.VaList(bp+48, (*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(6))
					_sqlite3VdbeChangeP5(tls, v, uint16(P5_ConstraintNotNull))
				default:
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), iReg, ignoreDest)
					break
				} /* end switch(onError) */
				goto _1
			_1:
				;
				i++
			} /* 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 int32(int32(overrideError)) != int32(OE_Default) {
			v2 = int32(int32(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)*20))).FpExpr
			if aiChng != 0 && !(_sqlite3ExprReferencesUpdatedColumn(tls, pExpr, aiChng, int32(int32(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 int32(int32(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)*20))).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++
		}
		(*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://www.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)(unsafe.Pointer(bp + 4))).FeType = 0
	(*(*TIndexIterator)(unsafe.Pointer(bp + 4))).Fi = 0
	*(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) = uintptr(0) /* Silence harmless compiler warning */
	*(*uintptr)(unsafe.Pointer(bp + 4 + 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 int32((*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++
				}
				(*(*TIndexIterator)(unsafe.Pointer(bp + 4))).FeType = int32(1)
				*(*int32)(unsafe.Pointer(bp + 4 + 8)) = nIdx
				nByte = uint64((libc.Uint32FromInt64(8)+libc.Uint32FromInt32(1))*uint32(uint32(nIdx)) + uint32(uint32(nIdx)))
				*(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) = _sqlite3DbMallocZero(tls, db, nByte)
				if *(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) == uintptr(0) {
					return
				} /* OOM */
				bUsed = *(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) + uintptr(nIdx)*8
				(*TUpsert)(unsafe.Pointer(pUpsert)).FpToFree = *(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4))
				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++
					}
					if *(*Tu8)(unsafe.Pointer(bUsed + uintptr(jj))) != 0 {
						goto _5
					} /* Duplicate ON CONFLICT clause ignored */
					*(*Tu8)(unsafe.Pointer(bUsed + uintptr(jj))) = uint8(1)
					(*(*TIndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) + uintptr(i)*8))).Fp = pIdx
					(*(*TIndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) + uintptr(i)*8))).Fix = jj
					i++
					goto _5
				_5:
					;
					pTerm = (*TUpsert)(unsafe.Pointer(pTerm)).FpNextUpsert
				}
				jj = 0
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0) {
						break
					}
					if *(*Tu8)(unsafe.Pointer(bUsed + uintptr(jj))) != 0 {
						goto _6
					}
					(*(*TIndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) + uintptr(i)*8))).Fp = pIdx
					(*(*TIndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4 + 8 + 4)) + uintptr(i)*8))).Fix = jj
					i++
					goto _6
				_6:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					jj++
				}
			}
		}
	}
	/* 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&uint64(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 + 44
			*(*int32)(unsafe.Pointer(v8))++
			v7 = *(*int32)(unsafe.Pointer(v8))
			regTrigCnt = v7
			_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 = int32((*TTable)(unsafe.Pointer(pTab)).FkeyConf)
		if int32(int32(overrideError)) != int32(OE_Default) {
			onError = int32(int32(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 int32((*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 != int32(int32(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++
			} 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+4, bp)
	for {
		if !(pIdx != 0) {
			break
		} /* First opcode in the conflict check logic */
		if *(*int32)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(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 int32(int32(bAffinityDone)) == 0 {
			_sqlite3TableAffinity(tls, v, pTab, regNewData+int32(1))
			bAffinityDone = uint8(1)
		}
		iThisCur = iIdxCur + *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(bp)))*4)) + int32(1)
		i = 0
		for {
			if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
				break
			}
			iField = int32(*(*Ti16)(unsafe.Pointer((*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)*20))).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(int16(iField)))) + regNewData + int32(1)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), x, regIdx+i)
				}
			}
			goto _10
		_10:
			;
			i++
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regIdx, int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn), *(*int32)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(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 && int32(int32(pkChng)) == 0 {
			_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			goto _9
		}
		/* Find out what action to take in case there is a uniqueness conflict */
		onError = int32((*TIndex)(unsafe.Pointer(pIdx)).FonError)
		if onError == OE_None {
			_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			goto _9 /* pIdx is not a UNIQUE index */
		}
		if int32(int32(overrideError)) != int32(OE_Default) {
			onError = int32(int32(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 int32((*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, int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol))
		/* Generate code to handle collisions */
		if pIdx == pPk {
			v11 = regIdx
		} else {
			v11 = _sqlite3GetTempRange(tls, pParse, nPkField)
		}
		regR = v11
		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 < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
							break
						}
						x1 = int32(_sqlite3TableColumnToIndex(tls, pIdx, *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iThisCur, x1, regR+i)
						goto _12
					_12:
						;
						i++
					}
				}
				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) + int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
					op = int32(OP_Ne)
					if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
						v13 = regIdx
					} else {
						v13 = regR
					}
					regCmp = v13
					i = 0
					for {
						if !(i < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
							break
						}
						p4 = _sqlite3LocateCollSeq(tls, pParse, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*4)))
						x1 = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))
						if i == int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)-int32(1) {
							addrJump = addrUniqueOk
							op = int32(OP_Eq)
						}
						x1 = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(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++
					}
				}
			}
		}
		/* 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)(unsafe.Pointer(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++
			}
			if pTrigger != 0 && isUpdate != 0 {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_CursorLock), iDataCur)
			}
			if pIdx == pPk {
				v15 = int32(ONEPASS_SINGLE)
			} else {
				v15 = ONEPASS_OFF
			}
			_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur, regR, int16(int16(nPkField)), uint8(0), uint8(OE_Replace), uint8(v15), 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)(unsafe.Pointer(bp + 20)) = *(*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, v, addrConflictCk)))
					if int32((*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fopcode) != int32(OP_IdxRowid) {
						if int32(_sqlite3OpcodeProperty[(*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fopcode])&int32(OPFLG_JUMP) != 0 {
							p2 = lblRecheckOk
						} else {
							p2 = (*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fp2
						}
						if int32((*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fp4type) == -int32(3) {
							v16 = uintptr(*(*int32)(unsafe.Pointer(bp + 20 + 16)))
						} else {
							v16 = *(*uintptr)(unsafe.Pointer(bp + 20 + 16))
						}
						zP4 = v16
						_sqlite3VdbeAddOp4(tls, v, int32((*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fopcode), (*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fp1, p2, (*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fp3, zP4, int32((*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fp4type))
						_sqlite3VdbeChangeP5(tls, v, (*(*TVdbeOp)(unsafe.Pointer(bp + 20))).Fp5)
					}
					nConflictCk--
					addrConflictCk++
				}
				/* 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+4, 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)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(pbMayReplace)) = seenReplace
}

// C documentation
//
//	/*
//	** Table pTab is a WITHOUT ROWID table that is being written to. The cursor
//	** number is iCur, and register regData contains the new record for the
//	** PK index. This function adds code to invoke the pre-update hook,
//	** if one is registered.
//	*/
func _codeWithoutRowidPreupdate(tls *libc.TLS, pParse uintptr, pTab uintptr, iCur int32, regData int32) {
	var r int32
	var v uintptr
	_, _ = r, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	r = _sqlite3GetTempReg(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, r)
	_sqlite3VdbeAddOp4(tls, v, int32(OP_Insert), iCur, regData, r, pTab, -int32(5))
	_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_ISNOOP))
	_sqlite3ReleaseTempReg(tls, pParse, r)
}

// 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, v3, v4 int32
	var pIdx, v uintptr
	var pik_flags Tu8
	_, _, _, _, _, _, _ = i, pIdx, pik_flags, v, v2, v3, v4 /* 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)(unsafe.Pointer(aRegIdx + uintptr(i)*4)) == 0 {
			goto _1
		}
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)), _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
		}
		if useSeekResult != 0 {
			v2 = int32(OPFLAG_USESEEKRESULT)
		} else {
			v2 = 0
		}
		pik_flags = uint8(v2)
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			pik_flags = Tu8(int32(pik_flags) | libc.Int32FromInt32(OPFLAG_NCHANGE))
			pik_flags = Tu8(int32(pik_flags) | update_flags&libc.Int32FromInt32(OPFLAG_SAVEPOSITION))
			if update_flags == 0 {
				_codeWithoutRowidPreupdate(tls, pParse, pTab, iIdxCur+i, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)))
			}
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x8>>3)) != 0 {
			v3 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		} else {
			v3 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		}
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iIdxCur+i, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)), *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4))+int32(1), v3)
		_sqlite3VdbeChangeP5(tls, v, uint16(uint16(pik_flags)))
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		i++
	}
	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 {
			v4 = update_flags
		} else {
			v4 = int32(OPFLAG_LASTROWID)
		}
		pik_flags = Tu8(int32(pik_flags) | v4)
	}
	if appendBias != 0 {
		pik_flags = Tu8(int32(pik_flags) | libc.Int32FromInt32(OPFLAG_APPEND))
	}
	if useSeekResult != 0 {
		pik_flags = Tu8(int32(pik_flags) | libc.Int32FromInt32(OPFLAG_USESEEKRESULT))
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iDataCur, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)), regNewData)
	if !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
		_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
	}
	_sqlite3VdbeChangeP5(tls, v, uint16(uint16(pik_flags)))
}

// 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, v2, v4 int32
	var pIdx, v uintptr
	_, _, _, _, _, _, _, _, _ = i, iDataCur, iDb, iIdxCur, pIdx, v, v1, v2, v4
	if int32((*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)(unsafe.Pointer(piIdxCur)) = v1
		*(*int32)(unsafe.Pointer(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
	}
	v2 = iBase
	iBase++
	iDataCur = v2
	*(*int32)(unsafe.Pointer(piDataCur)) = iDataCur
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && (aToOpen == uintptr(0) || *(*Tu8)(unsafe.Pointer(aToOpen)) != 0) {
		_sqlite3OpenTable(tls, pParse, iDataCur, iDb, pTab, op)
	} else {
		if int32((*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)(unsafe.Pointer(piIdxCur)) = iBase
	i = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		v4 = iBase
		iBase++
		iIdxCur = v4
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			*(*int32)(unsafe.Pointer(piDataCur)) = iIdxCur
			p5 = uint8(0)
		}
		if aToOpen == uintptr(0) || *(*Tu8)(unsafe.Pointer(aToOpen + uintptr(i+int32(1)))) != 0 {
			_sqlite3VdbeAddOp3(tls, v, op, iIdxCur, int32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
			_sqlite3VdbeChangeP5(tls, v, uint16(uint16(p5)))
		}
		goto _3
	_3:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		i++
	}
	if iBase > (*TParse)(unsafe.Pointer(pParse)).FnTab {
		(*TParse)(unsafe.Pointer(pParse)).FnTab = iBase
	}
	return i
}

// C documentation
//
//	/*
//	** Check to see if index pSrc is compatible as a source of data
//	** for index pDest in an insert transfer optimization.  The rules
//	** for a compatible index:
//	**
//	**    *   The index is over the same set of columns
//	**    *   The same DESC and ASC markings occurs on all columns
//	**    *   The same onError processing (OE_Abort, OE_Ignore, etc)
//	**    *   The same collating sequence on each column
//	**    *   The index has the exact same WHERE clause
//	*/
func _xferCompatibleIndex(tls *libc.TLS, pDest uintptr, pSrc uintptr) (r int32) {
	var i int32
	_ = i
	if int32((*TIndex)(unsafe.Pointer(pDest)).FnKeyCol) != int32((*TIndex)(unsafe.Pointer(pSrc)).FnKeyCol) || int32((*TIndex)(unsafe.Pointer(pDest)).FnColumn) != int32((*TIndex)(unsafe.Pointer(pSrc)).FnColumn) {
		return 0 /* Different number of columns */
	}
	if int32((*TIndex)(unsafe.Pointer(pDest)).FonError) != int32((*TIndex)(unsafe.Pointer(pSrc)).FonError) {
		return 0 /* Different conflict resolution strategies */
	}
	i = 0
	for {
		if !(i < int32((*TIndex)(unsafe.Pointer(pSrc)).FnKeyCol)) {
			break
		}
		if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pSrc)).FaiColumn + uintptr(i)*2))) != int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pDest)).FaiColumn + uintptr(i)*2))) {
			return 0 /* Different columns indexed */
		}
		if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pSrc)).FaiColumn + uintptr(i)*2))) == -int32(2) {
			if _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pSrc)).FaColExpr + 8 + uintptr(i)*20))).FpExpr, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pDest)).FaColExpr + 8 + uintptr(i)*20))).FpExpr, -int32(1)) != 0 {
				return 0 /* Different expressions in the index */
			}
		}
		if int32(*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pSrc)).FaSortOrder + uintptr(i)))) != int32(*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pDest)).FaSortOrder + uintptr(i)))) {
			return 0 /* Different sort orders */
		}
		if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pSrc)).FazColl + uintptr(i)*4)), *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pDest)).FazColl + uintptr(i)*4))) != 0 {
			return 0 /* Different collating sequences */
		}
		goto _1
	_1:
		;
		i++
	}
	if _sqlite3ExprCompare(tls, uintptr(0), (*TIndex)(unsafe.Pointer(pSrc)).FpPartIdxWhere, (*TIndex)(unsafe.Pointer(pDest)).FpPartIdxWhere, -int32(1)) != 0 {
		return 0 /* Different WHERE clauses */
	}
	/* If no test above fails then the indices must be compatible */
	return int32(1)
}

// 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, v6 int32
	var db, pDestCol, pDestExpr, pDestIdx, pEList, pItem, pSrc, pSrcCol, pSrcExpr, pSrcIdx, v, zColl, v5, v7 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, v6, v7
	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 int32((*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 = int32((*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 (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8))).FpSelect != 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 int32((*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 !(int32((*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)*12
		pSrcCol = (*TTable)(unsafe.Pointer(pSrc)).FaCol + uintptr(i)*12
		/* 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 int32((*TColumn)(unsafe.Pointer(pDestCol)).FcolFlags)&int32(COLFLAG_GENERATED) != int32((*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 int32((*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 int32((*TColumn)(unsafe.Pointer(pDestCol)).Faffinity) != int32((*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 + 4))&0xf>>0)) != 0 && !(int32(uint32(*(*uint8)(unsafe.Pointer(pSrcCol + 4))&0xf>>0)) != 0) {
			return 0 /* tab2 must be NOT NULL if tab1 is */
		}
		/* Default values for second and subsequent columns need to match. */
		if int32((*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++
	}
	pDestIdx = (*TTable)(unsafe.Pointer(pDest)).FpIndex
	for {
		if !(pDestIdx != 0) {
			break
		}
		if int32((*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 + 44))).FpFKey != uintptr(0) {
		return 0
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(uint64(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 + 40
	v4 = *(*int32)(unsafe.Pointer(v5))
	*(*int32)(unsafe.Pointer(v5))++
	iSrc = v4
	v7 = pParse + 40
	v6 = *(*int32)(unsafe.Pointer(v7))
	*(*int32)(unsafe.Pointer(v7))++
	iDest = v6
	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 = uint8(libc.Int32FromInt32(OPFLAG_APPEND) | libc.Int32FromInt32(OPFLAG_USESEEKRESULT) | libc.Int32FromInt32(OPFLAG_PREFORMAT))
		} else {
			insFlags = uint8(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 = Tu8(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(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, int32((*TIndex)(unsafe.Pointer(pSrcIdx)).Ftnum), iDbSrc)
		_sqlite3VdbeSetP4KeyInfo(tls, pParse, pSrcIdx)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenWrite), iDest, int32((*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 < int32((*TIndex)(unsafe.Pointer(pSrcIdx)).FnColumn)) {
					break
				}
				zColl = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pSrcIdx)).FazColl + uintptr(i)*4))
				if Xsqlite3_stricmp(tls, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), zColl) != 0 {
					break
				}
				goto _10
			_10:
				;
				i++
			}
			if i == int32((*TIndex)(unsafe.Pointer(pSrcIdx)).FnColumn) {
				idxInsFlags = uint8(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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
				idxInsFlags = Tu8(int32(idxInsFlags) | libc.Int32FromInt32(OPFLAG_NCHANGE))
			}
		}
		if int32(int32(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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
				_codeWithoutRowidPreupdate(tls, pParse, pDest, iDest, regData)
			}
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iDest, regData)
		_sqlite3VdbeChangeP5(tls, v, uint16(int32(int32(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
}

/************** End of insert.c **********************************************/
/************** Begin file legacy.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.
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
 */

/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Execute SQL code.  Return one of the SQLITE_ success/failure
//	** codes.  Also write an error message into memory obtained from
//	** malloc() and make *pzErrMsg point to that message.
//	**
//	** If the SQL is a query, then for each row in the query result
//	** the xCallback() function is called.  pArg becomes the first
//	** argument to xCallback().  If xCallback=NULL then no callback
//	** is invoked, even for queries.
//	*/
func Xsqlite3_exec(tls *libc.TLS, db uintptr, zSql uintptr, xCallback Tsqlite3_callback, pArg uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azCols, azVals uintptr
	var callbackIsInit, i, nCol, rc int32
	var _ /* pStmt at bp+4 */ uintptr
	var _ /* zLeftover at bp+0 */ uintptr
	_, _, _, _, _, _ = azCols, azVals, callbackIsInit, i, nCol, rc
	rc = SQLITE_OK                                   /* Tail of unprocessed SQL */
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* The current SQL statement */
	azCols = uintptr(0)                              /* True if callback data is initialized */
	if !(_sqlite3SafetyCheckOk(tls, db) != 0) {
		return _sqlite3MisuseError(tls, int32(136304))
	}
	if zSql == uintptr(0) {
		zSql = __ccgo_ts + 1672
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3Error(tls, db, SQLITE_OK)
	for rc == SQLITE_OK && *(*int8)(unsafe.Pointer(zSql)) != 0 {
		nCol = 0
		azVals = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp+4, bp)
		if rc != SQLITE_OK {
			continue
		}
		if !(*(*uintptr)(unsafe.Pointer(bp + 4)) != 0) {
			/* this happens for a comment or white-space */
			zSql = *(*uintptr)(unsafe.Pointer(bp))
			continue
		}
		callbackIsInit = 0
		for int32(1) != 0 {
			rc = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
			/* Invoke the callback function if required */
			if xCallback != 0 && (int32(SQLITE_ROW) == rc || int32(SQLITE_DONE) == rc && !(callbackIsInit != 0) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NullCallback) != 0) {
				if !(callbackIsInit != 0) {
					nCol = Xsqlite3_column_count(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
					azCols = _sqlite3DbMallocRaw(tls, db, uint64(uint32(libc.Int32FromInt32(2)*nCol+libc.Int32FromInt32(1))*uint32(4)))
					if azCols == uintptr(0) {
						goto exec_out
					}
					i = 0
					for {
						if !(i < nCol) {
							break
						}
						*(*uintptr)(unsafe.Pointer(azCols + uintptr(i)*4)) = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), i)
						/* sqlite3VdbeSetColName() installs column names as UTF8
						 ** strings so there is no way for sqlite3_column_name() to fail. */
						goto _1
					_1:
						;
						i++
					}
					callbackIsInit = int32(1)
				}
				if rc == int32(SQLITE_ROW) {
					azVals = azCols + uintptr(nCol)*4
					i = 0
					for {
						if !(i < nCol) {
							break
						}
						*(*uintptr)(unsafe.Pointer(azVals + uintptr(i)*4)) = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), i)
						if !(*(*uintptr)(unsafe.Pointer(azVals + uintptr(i)*4)) != 0) && Xsqlite3_column_type(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), i) != int32(SQLITE_NULL) {
							_sqlite3OomFault(tls, db)
							goto exec_out
						}
						goto _2
					_2:
						;
						i++
					}
					*(*uintptr)(unsafe.Pointer(azVals + uintptr(i)*4)) = uintptr(0)
				}
				if (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xCallback})))(tls, pArg, nCol, azVals, azCols) != 0 {
					/* EVIDENCE-OF: R-38229-40159 If the callback function to
					 ** sqlite3_exec() returns non-zero, then sqlite3_exec() will
					 ** return SQLITE_ABORT. */
					rc = int32(SQLITE_ABORT)
					_sqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
					*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
					_sqlite3Error(tls, db, int32(SQLITE_ABORT))
					goto exec_out
				}
			}
			if rc != int32(SQLITE_ROW) {
				rc = _sqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
				*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
				zSql = *(*uintptr)(unsafe.Pointer(bp))
				for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zSql)))])&int32(0x01) != 0 {
					zSql++
				}
				break
			}
		}
		_sqlite3DbFree(tls, db, azCols)
		azCols = uintptr(0)
	}
	goto exec_out
exec_out:
	;
	if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
		_sqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	_sqlite3DbFree(tls, db, azCols)
	rc = _sqlite3ApiExit(tls, db, rc)
	if rc != SQLITE_OK && pzErrMsg != 0 {
		*(*uintptr)(unsafe.Pointer(pzErrMsg)) = _sqlite3DbStrDup(tls, uintptr(0), Xsqlite3_errmsg(tls, db))
		if *(*uintptr)(unsafe.Pointer(pzErrMsg)) == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
			_sqlite3Error(tls, db, int32(SQLITE_NOMEM))
		}
	} else {
		if pzErrMsg != 0 {
			*(*uintptr)(unsafe.Pointer(pzErrMsg)) = uintptr(0)
		}
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

/************** End of legacy.c **********************************************/
/************** Begin file loadext.c *****************************************/
/*
** 2006 June 7
**
** 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 dynamically load extensions into
** the SQLite library.
 */

/************** Include sqlite3ext.h in the middle of loadext.c **************/
/************** Begin file sqlite3ext.h **************************************/
/*
** 2006 June 7
**
** 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 header file defines the SQLite interface for use by
** shared libraries that want to be imported as extensions into
** an SQLite instance.  Shared libraries that intend to be loaded
** as extensions by SQLite should #include this file instead of
** sqlite3.h.
 */
/* #include "sqlite3.h" */

/*
** The following structure holds pointers to all of the SQLite API
** routines.
**
** WARNING:  In order to maintain backwards compatibility, add new
** interfaces to the end of this structure only.  If you insert new
** interfaces in the middle of this structure, then older different
** versions of SQLite will not be able to load each other's shared
** libraries!
 */
type Tsqlite3_api_routines1 = struct {
	Faggregate_context      uintptr
	Faggregate_count        uintptr
	Fbind_blob              uintptr
	Fbind_double            uintptr
	Fbind_int               uintptr
	Fbind_int64             uintptr
	Fbind_null              uintptr
	Fbind_parameter_count   uintptr
	Fbind_parameter_index   uintptr
	Fbind_parameter_name    uintptr
	Fbind_text              uintptr
	Fbind_text16            uintptr
	Fbind_value             uintptr
	Fbusy_handler           uintptr
	Fbusy_timeout           uintptr
	Fchanges                uintptr
	Fclose1                 uintptr
	Fcollation_needed       uintptr
	Fcollation_needed16     uintptr
	Fcolumn_blob            uintptr
	Fcolumn_bytes           uintptr
	Fcolumn_bytes16         uintptr
	Fcolumn_count           uintptr
	Fcolumn_database_name   uintptr
	Fcolumn_database_name16 uintptr
	Fcolumn_decltype        uintptr
	Fcolumn_decltype16      uintptr
	Fcolumn_double          uintptr
	Fcolumn_int             uintptr
	Fcolumn_int64           uintptr
	Fcolumn_name            uintptr
	Fcolumn_name16          uintptr
	Fcolumn_origin_name     uintptr
	Fcolumn_origin_name16   uintptr
	Fcolumn_table_name      uintptr
	Fcolumn_table_name16    uintptr
	Fcolumn_text            uintptr
	Fcolumn_text16          uintptr
	Fcolumn_type            uintptr
	Fcolumn_value           uintptr
	Fcommit_hook            uintptr
	Fcomplete               uintptr
	Fcomplete16             uintptr
	Fcreate_collation       uintptr
	Fcreate_collation16     uintptr
	Fcreate_function        uintptr
	Fcreate_function16      uintptr
	Fcreate_module          uintptr
	Fdata_count             uintptr
	Fdb_handle              uintptr
	Fdeclare_vtab           uintptr
	Fenable_shared_cache    uintptr
	Ferrcode                uintptr
	Ferrmsg                 uintptr
	Ferrmsg16               uintptr
	Fexec                   uintptr
	Fexpired                uintptr
	Ffinalize               uintptr
	Ffree                   uintptr
	Ffree_table             uintptr
	Fget_autocommit         uintptr
	Fget_auxdata            uintptr
	Fget_table              uintptr
	Fglobal_recover         uintptr
	Finterruptx             uintptr
	Flast_insert_rowid      uintptr
	Flibversion             uintptr
	Flibversion_number      uintptr
	Fmalloc                 uintptr
	Fmprintf                uintptr
	Fopen                   uintptr
	Fopen16                 uintptr
	Fprepare                uintptr
	Fprepare16              uintptr
	Fprofile                uintptr
	Fprogress_handler       uintptr
	Frealloc                uintptr
	Freset                  uintptr
	Fresult_blob            uintptr
	Fresult_double          uintptr
	Fresult_error           uintptr
	Fresult_error16         uintptr
	Fresult_int             uintptr
	Fresult_int64           uintptr
	Fresult_null            uintptr
	Fresult_text            uintptr
	Fresult_text16          uintptr
	Fresult_text16be        uintptr
	Fresult_text16le        uintptr
	Fresult_value           uintptr
	Frollback_hook          uintptr
	Fset_authorizer         uintptr
	Fset_auxdata            uintptr
	Fxsnprintf              uintptr
	Fstep                   uintptr
	Ftable_column_metadata  uintptr
	Fthread_cleanup         uintptr
	Ftotal_changes          uintptr
	Ftrace                  uintptr
	Ftransfer_bindings      uintptr
	Fupdate_hook            uintptr
	Fuser_data              uintptr
	Fvalue_blob             uintptr
	Fvalue_bytes            uintptr
	Fvalue_bytes16          uintptr
	Fvalue_double           uintptr
	Fvalue_int              uintptr
	Fvalue_int64            uintptr
	Fvalue_numeric_type     uintptr
	Fvalue_text             uintptr
	Fvalue_text16           uintptr
	Fvalue_text16be         uintptr
	Fvalue_text16le         uintptr
	Fvalue_type             uintptr
	Fvmprintf               uintptr
	Foverload_function      uintptr
	Fprepare_v2             uintptr
	Fprepare16_v2           uintptr
	Fclear_bindings         uintptr
	Fcreate_module_v2       uintptr
	Fbind_zeroblob          uintptr
	Fblob_bytes             uintptr
	Fblob_close             uintptr
	Fblob_open              uintptr
	Fblob_read              uintptr
	Fblob_write             uintptr
	Fcreate_collation_v2    uintptr
	Ffile_control           uintptr
	Fmemory_highwater       uintptr
	Fmemory_used            uintptr
	Fmutex_alloc            uintptr
	Fmutex_enter            uintptr
	Fmutex_free             uintptr
	Fmutex_leave            uintptr
	Fmutex_try              uintptr
	Fopen_v2                uintptr
	Frelease_memory         uintptr
	Fresult_error_nomem     uintptr
	Fresult_error_toobig    uintptr
	Fsleep                  uintptr
	Fsoft_heap_limit        uintptr
	Fvfs_find               uintptr
	Fvfs_register           uintptr
	Fvfs_unregister         uintptr
	Fxthreadsafe            uintptr
	Fresult_zeroblob        uintptr
	Fresult_error_code      uintptr
	Ftest_control           uintptr
	Frandomness             uintptr
	Fcontext_db_handle      uintptr
	Fextended_result_codes  uintptr
	Flimit                  uintptr
	Fnext_stmt              uintptr
	Fsql                    uintptr
	Fstatus                 uintptr
	Fbackup_finish          uintptr
	Fbackup_init            uintptr
	Fbackup_pagecount       uintptr
	Fbackup_remaining       uintptr
	Fbackup_step            uintptr
	Fcompileoption_get      uintptr
	Fcompileoption_used     uintptr
	Fcreate_function_v2     uintptr
	Fdb_config              uintptr
	Fdb_mutex               uintptr
	Fdb_status              uintptr
	Fextended_errcode       uintptr
	Flog                    uintptr
	Fsoft_heap_limit64      uintptr
	Fsourceid               uintptr
	Fstmt_status            uintptr
	Fstrnicmp               uintptr
	Funlock_notify          uintptr
	Fwal_autocheckpoint     uintptr
	Fwal_checkpoint         uintptr
	Fwal_hook               uintptr
	Fblob_reopen            uintptr
	Fvtab_config            uintptr
	Fvtab_on_conflict       uintptr
	Fclose_v2               uintptr
	Fdb_filename            uintptr
	Fdb_readonly            uintptr
	Fdb_release_memory      uintptr
	Ferrstr                 uintptr
	Fstmt_busy              uintptr
	Fstmt_readonly          uintptr
	Fstricmp                uintptr
	Furi_boolean            uintptr
	Furi_int64              uintptr
	Furi_parameter          uintptr
	Fxvsnprintf             uintptr
	Fwal_checkpoint_v2      uintptr
	Fauto_extension         uintptr
	Fbind_blob64            uintptr
	Fbind_text64            uintptr
	Fcancel_auto_extension  uintptr
	Fload_extension         uintptr
	Fmalloc64               uintptr
	Fmsize                  uintptr
	Frealloc64              uintptr
	Freset_auto_extension   uintptr
	Fresult_blob64          uintptr
	Fresult_text64          uintptr
	Fstrglob                uintptr
	Fvalue_dup              uintptr
	Fvalue_free             uintptr
	Fresult_zeroblob64      uintptr
	Fbind_zeroblob64        uintptr
	Fvalue_subtype          uintptr
	Fresult_subtype         uintptr
	Fstatus64               uintptr
	Fstrlike                uintptr
	Fdb_cacheflush          uintptr
	Fsystem_errno           uintptr
	Ftrace_v2               uintptr
	Fexpanded_sql           uintptr
	Fset_last_insert_rowid  uintptr
	Fprepare_v3             uintptr
	Fprepare16_v3           uintptr
	Fbind_pointer           uintptr
	Fresult_pointer         uintptr
	Fvalue_pointer          uintptr
	Fvtab_nochange          uintptr
	Fvalue_nochange         uintptr
	Fvtab_collation         uintptr
	Fkeyword_count          uintptr
	Fkeyword_name           uintptr
	Fkeyword_check          uintptr
	Fstr_new                uintptr
	Fstr_finish             uintptr
	Fstr_appendf            uintptr
	Fstr_vappendf           uintptr
	Fstr_append             uintptr
	Fstr_appendall          uintptr
	Fstr_appendchar         uintptr
	Fstr_reset              uintptr
	Fstr_errcode            uintptr
	Fstr_length             uintptr
	Fstr_value              uintptr
	Fcreate_window_function uintptr
	Fnormalized_sql         uintptr
	Fstmt_isexplain         uintptr
	Fvalue_frombind         uintptr
	Fdrop_modules           uintptr
	Fhard_heap_limit64      uintptr
	Furi_key                uintptr
	Ffilename_database      uintptr
	Ffilename_journal       uintptr
	Ffilename_wal           uintptr
	Fcreate_filename        uintptr
	Ffree_filename          uintptr
	Fdatabase_file_object   uintptr
	Ftxn_state              uintptr
	Fchanges64              uintptr
	Ftotal_changes64        uintptr
	Fautovacuum_pages       uintptr
	Ferror_offset           uintptr
	Fvtab_rhs_value         uintptr
	Fvtab_distinct          uintptr
	Fvtab_in                uintptr
	Fvtab_in_first          uintptr
	Fvtab_in_next           uintptr
	Fdeserialize            uintptr
	Fserialize              uintptr
	Fdb_name                uintptr
	Fvalue_encoding         uintptr
	Fis_interrupted         uintptr
	Fstmt_explain           uintptr
	Fget_clientdata         uintptr
	Fset_clientdata         uintptr
}

type sqlite3_api_routines1 = Tsqlite3_api_routines1

// C documentation
//
//	/*
//	** This is the function signature used for all extension entry points.  It
//	** is also defined in the file "loadext.c".
//	*/
type Tsqlite3_loadext_entry = uintptr

type sqlite3_loadext_entry = Tsqlite3_loadext_entry

/*
** The following macros redefine the API routines so that they are
** redirected through the global sqlite3_api structure.
**
** This header file is also used by the loadext.c source file
** (part of the main SQLite library - not an extension) so that
** it can get access to the sqlite3_api_routines structure
** definition.  But the main library does not want to redefine
** the API.  So the redefinition macros are only valid if the
** SQLITE_CORE macros is undefined.
 */

/* This case when the file is being statically linked into the
 ** application */

/************** End of sqlite3ext.h ******************************************/
/************** Continuing where we left off in loadext.c ********************/
/* #include "sqliteInt.h" */

/*
** Some API routines are omitted when various features are
** excluded from a build of SQLite.  Substitute a NULL pointer
** for any missing APIs.
 */

// C documentation
//
//	/*
//	** The following structure contains pointers to all SQLite API routines.
//	** A pointer to this structure is passed into extensions when they are
//	** loaded so that the extension can make calls back into the SQLite
//	** library.
//	**
//	** When adding new APIs, add them to the bottom of this structure
//	** in order to preserve backwards compatibility.
//	**
//	** Extensions that use newer APIs should first call the
//	** sqlite3_libversion_number() to make sure that the API they
//	** intend to use is supported by the library.  Extensions should
//	** also check to make sure that the pointer to the function is
//	** not NULL before calling it.
//	*/
var _sqlite3Apis = Tsqlite3_api_routines{}

func init() {
	p := unsafe.Pointer(&_sqlite3Apis)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(Xsqlite3_aggregate_context)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(Xsqlite3_aggregate_count)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(Xsqlite3_bind_blob)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(Xsqlite3_bind_double)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(Xsqlite3_bind_int)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(Xsqlite3_bind_int64)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(Xsqlite3_bind_null)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(Xsqlite3_bind_parameter_count)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(Xsqlite3_bind_parameter_index)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(Xsqlite3_bind_parameter_name)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(Xsqlite3_bind_text)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(Xsqlite3_bind_text16)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(Xsqlite3_bind_value)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(Xsqlite3_busy_handler)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(Xsqlite3_busy_timeout)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(Xsqlite3_changes)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(Xsqlite3_close)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(Xsqlite3_collation_needed)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(Xsqlite3_collation_needed16)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(Xsqlite3_column_blob)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(Xsqlite3_column_bytes)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(Xsqlite3_column_bytes16)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(Xsqlite3_column_count)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(Xsqlite3_column_database_name)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(Xsqlite3_column_database_name16)
	*(*uintptr)(unsafe.Add(p, 100)) = __ccgo_fp(Xsqlite3_column_decltype)
	*(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(Xsqlite3_column_decltype16)
	*(*uintptr)(unsafe.Add(p, 108)) = __ccgo_fp(Xsqlite3_column_double)
	*(*uintptr)(unsafe.Add(p, 112)) = __ccgo_fp(Xsqlite3_column_int)
	*(*uintptr)(unsafe.Add(p, 116)) = __ccgo_fp(Xsqlite3_column_int64)
	*(*uintptr)(unsafe.Add(p, 120)) = __ccgo_fp(Xsqlite3_column_name)
	*(*uintptr)(unsafe.Add(p, 124)) = __ccgo_fp(Xsqlite3_column_name16)
	*(*uintptr)(unsafe.Add(p, 128)) = __ccgo_fp(Xsqlite3_column_origin_name)
	*(*uintptr)(unsafe.Add(p, 132)) = __ccgo_fp(Xsqlite3_column_origin_name16)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(Xsqlite3_column_table_name)
	*(*uintptr)(unsafe.Add(p, 140)) = __ccgo_fp(Xsqlite3_column_table_name16)
	*(*uintptr)(unsafe.Add(p, 144)) = __ccgo_fp(Xsqlite3_column_text)
	*(*uintptr)(unsafe.Add(p, 148)) = __ccgo_fp(Xsqlite3_column_text16)
	*(*uintptr)(unsafe.Add(p, 152)) = __ccgo_fp(Xsqlite3_column_type)
	*(*uintptr)(unsafe.Add(p, 156)) = __ccgo_fp(Xsqlite3_column_value)
	*(*uintptr)(unsafe.Add(p, 160)) = __ccgo_fp(Xsqlite3_commit_hook)
	*(*uintptr)(unsafe.Add(p, 164)) = __ccgo_fp(Xsqlite3_complete)
	*(*uintptr)(unsafe.Add(p, 168)) = __ccgo_fp(Xsqlite3_complete16)
	*(*uintptr)(unsafe.Add(p, 172)) = __ccgo_fp(Xsqlite3_create_collation)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(Xsqlite3_create_collation16)
	*(*uintptr)(unsafe.Add(p, 180)) = __ccgo_fp(Xsqlite3_create_function)
	*(*uintptr)(unsafe.Add(p, 184)) = __ccgo_fp(Xsqlite3_create_function16)
	*(*uintptr)(unsafe.Add(p, 188)) = __ccgo_fp(Xsqlite3_create_module)
	*(*uintptr)(unsafe.Add(p, 192)) = __ccgo_fp(Xsqlite3_data_count)
	*(*uintptr)(unsafe.Add(p, 196)) = __ccgo_fp(Xsqlite3_db_handle)
	*(*uintptr)(unsafe.Add(p, 200)) = __ccgo_fp(Xsqlite3_declare_vtab)
	*(*uintptr)(unsafe.Add(p, 204)) = __ccgo_fp(Xsqlite3_enable_shared_cache)
	*(*uintptr)(unsafe.Add(p, 208)) = __ccgo_fp(Xsqlite3_errcode)
	*(*uintptr)(unsafe.Add(p, 212)) = __ccgo_fp(Xsqlite3_errmsg)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(Xsqlite3_errmsg16)
	*(*uintptr)(unsafe.Add(p, 220)) = __ccgo_fp(Xsqlite3_exec)
	*(*uintptr)(unsafe.Add(p, 224)) = __ccgo_fp(Xsqlite3_expired)
	*(*uintptr)(unsafe.Add(p, 228)) = __ccgo_fp(Xsqlite3_finalize)
	*(*uintptr)(unsafe.Add(p, 232)) = __ccgo_fp(Xsqlite3_free)
	*(*uintptr)(unsafe.Add(p, 236)) = __ccgo_fp(Xsqlite3_free_table)
	*(*uintptr)(unsafe.Add(p, 240)) = __ccgo_fp(Xsqlite3_get_autocommit)
	*(*uintptr)(unsafe.Add(p, 244)) = __ccgo_fp(Xsqlite3_get_auxdata)
	*(*uintptr)(unsafe.Add(p, 248)) = __ccgo_fp(Xsqlite3_get_table)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(Xsqlite3_interrupt)
	*(*uintptr)(unsafe.Add(p, 260)) = __ccgo_fp(Xsqlite3_last_insert_rowid)
	*(*uintptr)(unsafe.Add(p, 264)) = __ccgo_fp(Xsqlite3_libversion)
	*(*uintptr)(unsafe.Add(p, 268)) = __ccgo_fp(Xsqlite3_libversion_number)
	*(*uintptr)(unsafe.Add(p, 272)) = __ccgo_fp(Xsqlite3_malloc)
	*(*uintptr)(unsafe.Add(p, 276)) = __ccgo_fp(Xsqlite3_mprintf)
	*(*uintptr)(unsafe.Add(p, 280)) = __ccgo_fp(Xsqlite3_open)
	*(*uintptr)(unsafe.Add(p, 284)) = __ccgo_fp(Xsqlite3_open16)
	*(*uintptr)(unsafe.Add(p, 288)) = __ccgo_fp(Xsqlite3_prepare)
	*(*uintptr)(unsafe.Add(p, 292)) = __ccgo_fp(Xsqlite3_prepare16)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(Xsqlite3_profile)
	*(*uintptr)(unsafe.Add(p, 300)) = __ccgo_fp(Xsqlite3_progress_handler)
	*(*uintptr)(unsafe.Add(p, 304)) = __ccgo_fp(Xsqlite3_realloc)
	*(*uintptr)(unsafe.Add(p, 308)) = __ccgo_fp(Xsqlite3_reset)
	*(*uintptr)(unsafe.Add(p, 312)) = __ccgo_fp(Xsqlite3_result_blob)
	*(*uintptr)(unsafe.Add(p, 316)) = __ccgo_fp(Xsqlite3_result_double)
	*(*uintptr)(unsafe.Add(p, 320)) = __ccgo_fp(Xsqlite3_result_error)
	*(*uintptr)(unsafe.Add(p, 324)) = __ccgo_fp(Xsqlite3_result_error16)
	*(*uintptr)(unsafe.Add(p, 328)) = __ccgo_fp(Xsqlite3_result_int)
	*(*uintptr)(unsafe.Add(p, 332)) = __ccgo_fp(Xsqlite3_result_int64)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(Xsqlite3_result_null)
	*(*uintptr)(unsafe.Add(p, 340)) = __ccgo_fp(Xsqlite3_result_text)
	*(*uintptr)(unsafe.Add(p, 344)) = __ccgo_fp(Xsqlite3_result_text16)
	*(*uintptr)(unsafe.Add(p, 348)) = __ccgo_fp(Xsqlite3_result_text16be)
	*(*uintptr)(unsafe.Add(p, 352)) = __ccgo_fp(Xsqlite3_result_text16le)
	*(*uintptr)(unsafe.Add(p, 356)) = __ccgo_fp(Xsqlite3_result_value)
	*(*uintptr)(unsafe.Add(p, 360)) = __ccgo_fp(Xsqlite3_rollback_hook)
	*(*uintptr)(unsafe.Add(p, 364)) = __ccgo_fp(Xsqlite3_set_authorizer)
	*(*uintptr)(unsafe.Add(p, 368)) = __ccgo_fp(Xsqlite3_set_auxdata)
	*(*uintptr)(unsafe.Add(p, 372)) = __ccgo_fp(Xsqlite3_snprintf)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(Xsqlite3_step)
	*(*uintptr)(unsafe.Add(p, 380)) = __ccgo_fp(Xsqlite3_table_column_metadata)
	*(*uintptr)(unsafe.Add(p, 384)) = __ccgo_fp(Xsqlite3_thread_cleanup)
	*(*uintptr)(unsafe.Add(p, 388)) = __ccgo_fp(Xsqlite3_total_changes)
	*(*uintptr)(unsafe.Add(p, 392)) = __ccgo_fp(Xsqlite3_trace)
	*(*uintptr)(unsafe.Add(p, 396)) = __ccgo_fp(Xsqlite3_transfer_bindings)
	*(*uintptr)(unsafe.Add(p, 400)) = __ccgo_fp(Xsqlite3_update_hook)
	*(*uintptr)(unsafe.Add(p, 404)) = __ccgo_fp(Xsqlite3_user_data)
	*(*uintptr)(unsafe.Add(p, 408)) = __ccgo_fp(Xsqlite3_value_blob)
	*(*uintptr)(unsafe.Add(p, 412)) = __ccgo_fp(Xsqlite3_value_bytes)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(Xsqlite3_value_bytes16)
	*(*uintptr)(unsafe.Add(p, 420)) = __ccgo_fp(Xsqlite3_value_double)
	*(*uintptr)(unsafe.Add(p, 424)) = __ccgo_fp(Xsqlite3_value_int)
	*(*uintptr)(unsafe.Add(p, 428)) = __ccgo_fp(Xsqlite3_value_int64)
	*(*uintptr)(unsafe.Add(p, 432)) = __ccgo_fp(Xsqlite3_value_numeric_type)
	*(*uintptr)(unsafe.Add(p, 436)) = __ccgo_fp(Xsqlite3_value_text)
	*(*uintptr)(unsafe.Add(p, 440)) = __ccgo_fp(Xsqlite3_value_text16)
	*(*uintptr)(unsafe.Add(p, 444)) = __ccgo_fp(Xsqlite3_value_text16be)
	*(*uintptr)(unsafe.Add(p, 448)) = __ccgo_fp(Xsqlite3_value_text16le)
	*(*uintptr)(unsafe.Add(p, 452)) = __ccgo_fp(Xsqlite3_value_type)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(Xsqlite3_vmprintf)
	*(*uintptr)(unsafe.Add(p, 460)) = __ccgo_fp(Xsqlite3_overload_function)
	*(*uintptr)(unsafe.Add(p, 464)) = __ccgo_fp(Xsqlite3_prepare_v2)
	*(*uintptr)(unsafe.Add(p, 468)) = __ccgo_fp(Xsqlite3_prepare16_v2)
	*(*uintptr)(unsafe.Add(p, 472)) = __ccgo_fp(Xsqlite3_clear_bindings)
	*(*uintptr)(unsafe.Add(p, 476)) = __ccgo_fp(Xsqlite3_create_module_v2)
	*(*uintptr)(unsafe.Add(p, 480)) = __ccgo_fp(Xsqlite3_bind_zeroblob)
	*(*uintptr)(unsafe.Add(p, 484)) = __ccgo_fp(Xsqlite3_blob_bytes)
	*(*uintptr)(unsafe.Add(p, 488)) = __ccgo_fp(Xsqlite3_blob_close)
	*(*uintptr)(unsafe.Add(p, 492)) = __ccgo_fp(Xsqlite3_blob_open)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(Xsqlite3_blob_read)
	*(*uintptr)(unsafe.Add(p, 500)) = __ccgo_fp(Xsqlite3_blob_write)
	*(*uintptr)(unsafe.Add(p, 504)) = __ccgo_fp(Xsqlite3_create_collation_v2)
	*(*uintptr)(unsafe.Add(p, 508)) = __ccgo_fp(Xsqlite3_file_control)
	*(*uintptr)(unsafe.Add(p, 512)) = __ccgo_fp(Xsqlite3_memory_highwater)
	*(*uintptr)(unsafe.Add(p, 516)) = __ccgo_fp(Xsqlite3_memory_used)
	*(*uintptr)(unsafe.Add(p, 520)) = __ccgo_fp(Xsqlite3_mutex_alloc)
	*(*uintptr)(unsafe.Add(p, 524)) = __ccgo_fp(Xsqlite3_mutex_enter)
	*(*uintptr)(unsafe.Add(p, 528)) = __ccgo_fp(Xsqlite3_mutex_free)
	*(*uintptr)(unsafe.Add(p, 532)) = __ccgo_fp(Xsqlite3_mutex_leave)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(Xsqlite3_mutex_try)
	*(*uintptr)(unsafe.Add(p, 540)) = __ccgo_fp(Xsqlite3_open_v2)
	*(*uintptr)(unsafe.Add(p, 544)) = __ccgo_fp(Xsqlite3_release_memory)
	*(*uintptr)(unsafe.Add(p, 548)) = __ccgo_fp(Xsqlite3_result_error_nomem)
	*(*uintptr)(unsafe.Add(p, 552)) = __ccgo_fp(Xsqlite3_result_error_toobig)
	*(*uintptr)(unsafe.Add(p, 556)) = __ccgo_fp(Xsqlite3_sleep)
	*(*uintptr)(unsafe.Add(p, 560)) = __ccgo_fp(Xsqlite3_soft_heap_limit)
	*(*uintptr)(unsafe.Add(p, 564)) = __ccgo_fp(Xsqlite3_vfs_find)
	*(*uintptr)(unsafe.Add(p, 568)) = __ccgo_fp(Xsqlite3_vfs_register)
	*(*uintptr)(unsafe.Add(p, 572)) = __ccgo_fp(Xsqlite3_vfs_unregister)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(Xsqlite3_threadsafe)
	*(*uintptr)(unsafe.Add(p, 580)) = __ccgo_fp(Xsqlite3_result_zeroblob)
	*(*uintptr)(unsafe.Add(p, 584)) = __ccgo_fp(Xsqlite3_result_error_code)
	*(*uintptr)(unsafe.Add(p, 588)) = __ccgo_fp(Xsqlite3_test_control)
	*(*uintptr)(unsafe.Add(p, 592)) = __ccgo_fp(Xsqlite3_randomness)
	*(*uintptr)(unsafe.Add(p, 596)) = __ccgo_fp(Xsqlite3_context_db_handle)
	*(*uintptr)(unsafe.Add(p, 600)) = __ccgo_fp(Xsqlite3_extended_result_codes)
	*(*uintptr)(unsafe.Add(p, 604)) = __ccgo_fp(Xsqlite3_limit)
	*(*uintptr)(unsafe.Add(p, 608)) = __ccgo_fp(Xsqlite3_next_stmt)
	*(*uintptr)(unsafe.Add(p, 612)) = __ccgo_fp(Xsqlite3_sql)
	*(*uintptr)(unsafe.Add(p, 616)) = __ccgo_fp(Xsqlite3_status)
	*(*uintptr)(unsafe.Add(p, 620)) = __ccgo_fp(Xsqlite3_backup_finish)
	*(*uintptr)(unsafe.Add(p, 624)) = __ccgo_fp(Xsqlite3_backup_init)
	*(*uintptr)(unsafe.Add(p, 628)) = __ccgo_fp(Xsqlite3_backup_pagecount)
	*(*uintptr)(unsafe.Add(p, 632)) = __ccgo_fp(Xsqlite3_backup_remaining)
	*(*uintptr)(unsafe.Add(p, 636)) = __ccgo_fp(Xsqlite3_backup_step)
	*(*uintptr)(unsafe.Add(p, 640)) = __ccgo_fp(Xsqlite3_compileoption_get)
	*(*uintptr)(unsafe.Add(p, 644)) = __ccgo_fp(Xsqlite3_compileoption_used)
	*(*uintptr)(unsafe.Add(p, 648)) = __ccgo_fp(Xsqlite3_create_function_v2)
	*(*uintptr)(unsafe.Add(p, 652)) = __ccgo_fp(Xsqlite3_db_config)
	*(*uintptr)(unsafe.Add(p, 656)) = __ccgo_fp(Xsqlite3_db_mutex)
	*(*uintptr)(unsafe.Add(p, 660)) = __ccgo_fp(Xsqlite3_db_status)
	*(*uintptr)(unsafe.Add(p, 664)) = __ccgo_fp(Xsqlite3_extended_errcode)
	*(*uintptr)(unsafe.Add(p, 668)) = __ccgo_fp(Xsqlite3_log)
	*(*uintptr)(unsafe.Add(p, 672)) = __ccgo_fp(Xsqlite3_soft_heap_limit64)
	*(*uintptr)(unsafe.Add(p, 676)) = __ccgo_fp(Xsqlite3_sourceid)
	*(*uintptr)(unsafe.Add(p, 680)) = __ccgo_fp(Xsqlite3_stmt_status)
	*(*uintptr)(unsafe.Add(p, 684)) = __ccgo_fp(Xsqlite3_strnicmp)
	*(*uintptr)(unsafe.Add(p, 688)) = __ccgo_fp(Xsqlite3_unlock_notify)
	*(*uintptr)(unsafe.Add(p, 692)) = __ccgo_fp(Xsqlite3_wal_autocheckpoint)
	*(*uintptr)(unsafe.Add(p, 696)) = __ccgo_fp(Xsqlite3_wal_checkpoint)
	*(*uintptr)(unsafe.Add(p, 700)) = __ccgo_fp(Xsqlite3_wal_hook)
	*(*uintptr)(unsafe.Add(p, 704)) = __ccgo_fp(Xsqlite3_blob_reopen)
	*(*uintptr)(unsafe.Add(p, 708)) = __ccgo_fp(Xsqlite3_vtab_config)
	*(*uintptr)(unsafe.Add(p, 712)) = __ccgo_fp(Xsqlite3_vtab_on_conflict)
	*(*uintptr)(unsafe.Add(p, 716)) = __ccgo_fp(Xsqlite3_close_v2)
	*(*uintptr)(unsafe.Add(p, 720)) = __ccgo_fp(Xsqlite3_db_filename)
	*(*uintptr)(unsafe.Add(p, 724)) = __ccgo_fp(Xsqlite3_db_readonly)
	*(*uintptr)(unsafe.Add(p, 728)) = __ccgo_fp(Xsqlite3_db_release_memory)
	*(*uintptr)(unsafe.Add(p, 732)) = __ccgo_fp(Xsqlite3_errstr)
	*(*uintptr)(unsafe.Add(p, 736)) = __ccgo_fp(Xsqlite3_stmt_busy)
	*(*uintptr)(unsafe.Add(p, 740)) = __ccgo_fp(Xsqlite3_stmt_readonly)
	*(*uintptr)(unsafe.Add(p, 744)) = __ccgo_fp(Xsqlite3_stricmp)
	*(*uintptr)(unsafe.Add(p, 748)) = __ccgo_fp(Xsqlite3_uri_boolean)
	*(*uintptr)(unsafe.Add(p, 752)) = __ccgo_fp(Xsqlite3_uri_int64)
	*(*uintptr)(unsafe.Add(p, 756)) = __ccgo_fp(Xsqlite3_uri_parameter)
	*(*uintptr)(unsafe.Add(p, 760)) = __ccgo_fp(Xsqlite3_vsnprintf)
	*(*uintptr)(unsafe.Add(p, 764)) = __ccgo_fp(Xsqlite3_wal_checkpoint_v2)
	*(*uintptr)(unsafe.Add(p, 768)) = __ccgo_fp(Xsqlite3_auto_extension)
	*(*uintptr)(unsafe.Add(p, 772)) = __ccgo_fp(Xsqlite3_bind_blob64)
	*(*uintptr)(unsafe.Add(p, 776)) = __ccgo_fp(Xsqlite3_bind_text64)
	*(*uintptr)(unsafe.Add(p, 780)) = __ccgo_fp(Xsqlite3_cancel_auto_extension)
	*(*uintptr)(unsafe.Add(p, 784)) = __ccgo_fp(Xsqlite3_load_extension)
	*(*uintptr)(unsafe.Add(p, 788)) = __ccgo_fp(Xsqlite3_malloc64)
	*(*uintptr)(unsafe.Add(p, 792)) = __ccgo_fp(Xsqlite3_msize)
	*(*uintptr)(unsafe.Add(p, 796)) = __ccgo_fp(Xsqlite3_realloc64)
	*(*uintptr)(unsafe.Add(p, 800)) = __ccgo_fp(Xsqlite3_reset_auto_extension)
	*(*uintptr)(unsafe.Add(p, 804)) = __ccgo_fp(Xsqlite3_result_blob64)
	*(*uintptr)(unsafe.Add(p, 808)) = __ccgo_fp(Xsqlite3_result_text64)
	*(*uintptr)(unsafe.Add(p, 812)) = __ccgo_fp(Xsqlite3_strglob)
	*(*uintptr)(unsafe.Add(p, 816)) = __ccgo_fp(Xsqlite3_value_dup)
	*(*uintptr)(unsafe.Add(p, 820)) = __ccgo_fp(Xsqlite3_value_free)
	*(*uintptr)(unsafe.Add(p, 824)) = __ccgo_fp(Xsqlite3_result_zeroblob64)
	*(*uintptr)(unsafe.Add(p, 828)) = __ccgo_fp(Xsqlite3_bind_zeroblob64)
	*(*uintptr)(unsafe.Add(p, 832)) = __ccgo_fp(Xsqlite3_value_subtype)
	*(*uintptr)(unsafe.Add(p, 836)) = __ccgo_fp(Xsqlite3_result_subtype)
	*(*uintptr)(unsafe.Add(p, 840)) = __ccgo_fp(Xsqlite3_status64)
	*(*uintptr)(unsafe.Add(p, 844)) = __ccgo_fp(Xsqlite3_strlike)
	*(*uintptr)(unsafe.Add(p, 848)) = __ccgo_fp(Xsqlite3_db_cacheflush)
	*(*uintptr)(unsafe.Add(p, 852)) = __ccgo_fp(Xsqlite3_system_errno)
	*(*uintptr)(unsafe.Add(p, 856)) = __ccgo_fp(Xsqlite3_trace_v2)
	*(*uintptr)(unsafe.Add(p, 860)) = __ccgo_fp(Xsqlite3_expanded_sql)
	*(*uintptr)(unsafe.Add(p, 864)) = __ccgo_fp(Xsqlite3_set_last_insert_rowid)
	*(*uintptr)(unsafe.Add(p, 868)) = __ccgo_fp(Xsqlite3_prepare_v3)
	*(*uintptr)(unsafe.Add(p, 872)) = __ccgo_fp(Xsqlite3_prepare16_v3)
	*(*uintptr)(unsafe.Add(p, 876)) = __ccgo_fp(Xsqlite3_bind_pointer)
	*(*uintptr)(unsafe.Add(p, 880)) = __ccgo_fp(Xsqlite3_result_pointer)
	*(*uintptr)(unsafe.Add(p, 884)) = __ccgo_fp(Xsqlite3_value_pointer)
	*(*uintptr)(unsafe.Add(p, 888)) = __ccgo_fp(Xsqlite3_vtab_nochange)
	*(*uintptr)(unsafe.Add(p, 892)) = __ccgo_fp(Xsqlite3_value_nochange)
	*(*uintptr)(unsafe.Add(p, 896)) = __ccgo_fp(Xsqlite3_vtab_collation)
	*(*uintptr)(unsafe.Add(p, 900)) = __ccgo_fp(Xsqlite3_keyword_count)
	*(*uintptr)(unsafe.Add(p, 904)) = __ccgo_fp(Xsqlite3_keyword_name)
	*(*uintptr)(unsafe.Add(p, 908)) = __ccgo_fp(Xsqlite3_keyword_check)
	*(*uintptr)(unsafe.Add(p, 912)) = __ccgo_fp(Xsqlite3_str_new)
	*(*uintptr)(unsafe.Add(p, 916)) = __ccgo_fp(Xsqlite3_str_finish)
	*(*uintptr)(unsafe.Add(p, 920)) = __ccgo_fp(Xsqlite3_str_appendf)
	*(*uintptr)(unsafe.Add(p, 924)) = __ccgo_fp(Xsqlite3_str_vappendf)
	*(*uintptr)(unsafe.Add(p, 928)) = __ccgo_fp(Xsqlite3_str_append)
	*(*uintptr)(unsafe.Add(p, 932)) = __ccgo_fp(Xsqlite3_str_appendall)
	*(*uintptr)(unsafe.Add(p, 936)) = __ccgo_fp(Xsqlite3_str_appendchar)
	*(*uintptr)(unsafe.Add(p, 940)) = __ccgo_fp(Xsqlite3_str_reset)
	*(*uintptr)(unsafe.Add(p, 944)) = __ccgo_fp(Xsqlite3_str_errcode)
	*(*uintptr)(unsafe.Add(p, 948)) = __ccgo_fp(Xsqlite3_str_length)
	*(*uintptr)(unsafe.Add(p, 952)) = __ccgo_fp(Xsqlite3_str_value)
	*(*uintptr)(unsafe.Add(p, 956)) = __ccgo_fp(Xsqlite3_create_window_function)
	*(*uintptr)(unsafe.Add(p, 964)) = __ccgo_fp(Xsqlite3_stmt_isexplain)
	*(*uintptr)(unsafe.Add(p, 968)) = __ccgo_fp(Xsqlite3_value_frombind)
	*(*uintptr)(unsafe.Add(p, 972)) = __ccgo_fp(Xsqlite3_drop_modules)
	*(*uintptr)(unsafe.Add(p, 976)) = __ccgo_fp(Xsqlite3_hard_heap_limit64)
	*(*uintptr)(unsafe.Add(p, 980)) = __ccgo_fp(Xsqlite3_uri_key)
	*(*uintptr)(unsafe.Add(p, 984)) = __ccgo_fp(Xsqlite3_filename_database)
	*(*uintptr)(unsafe.Add(p, 988)) = __ccgo_fp(Xsqlite3_filename_journal)
	*(*uintptr)(unsafe.Add(p, 992)) = __ccgo_fp(Xsqlite3_filename_wal)
	*(*uintptr)(unsafe.Add(p, 996)) = __ccgo_fp(Xsqlite3_create_filename)
	*(*uintptr)(unsafe.Add(p, 1000)) = __ccgo_fp(Xsqlite3_free_filename)
	*(*uintptr)(unsafe.Add(p, 1004)) = __ccgo_fp(Xsqlite3_database_file_object)
	*(*uintptr)(unsafe.Add(p, 1008)) = __ccgo_fp(Xsqlite3_txn_state)
	*(*uintptr)(unsafe.Add(p, 1012)) = __ccgo_fp(Xsqlite3_changes64)
	*(*uintptr)(unsafe.Add(p, 1016)) = __ccgo_fp(Xsqlite3_total_changes64)
	*(*uintptr)(unsafe.Add(p, 1020)) = __ccgo_fp(Xsqlite3_autovacuum_pages)
	*(*uintptr)(unsafe.Add(p, 1024)) = __ccgo_fp(Xsqlite3_error_offset)
	*(*uintptr)(unsafe.Add(p, 1028)) = __ccgo_fp(Xsqlite3_vtab_rhs_value)
	*(*uintptr)(unsafe.Add(p, 1032)) = __ccgo_fp(Xsqlite3_vtab_distinct)
	*(*uintptr)(unsafe.Add(p, 1036)) = __ccgo_fp(Xsqlite3_vtab_in)
	*(*uintptr)(unsafe.Add(p, 1040)) = __ccgo_fp(Xsqlite3_vtab_in_first)
	*(*uintptr)(unsafe.Add(p, 1044)) = __ccgo_fp(Xsqlite3_vtab_in_next)
	*(*uintptr)(unsafe.Add(p, 1048)) = __ccgo_fp(Xsqlite3_deserialize)
	*(*uintptr)(unsafe.Add(p, 1052)) = __ccgo_fp(Xsqlite3_serialize)
	*(*uintptr)(unsafe.Add(p, 1056)) = __ccgo_fp(Xsqlite3_db_name)
	*(*uintptr)(unsafe.Add(p, 1060)) = __ccgo_fp(Xsqlite3_value_encoding)
	*(*uintptr)(unsafe.Add(p, 1064)) = __ccgo_fp(Xsqlite3_is_interrupted)
	*(*uintptr)(unsafe.Add(p, 1068)) = __ccgo_fp(Xsqlite3_stmt_explain)
	*(*uintptr)(unsafe.Add(p, 1072)) = __ccgo_fp(Xsqlite3_get_clientdata)
	*(*uintptr)(unsafe.Add(p, 1076)) = __ccgo_fp(Xsqlite3_set_clientdata)
}

/* True if x is the directory separator character
 */

// C documentation
//
//	/*
//	** Attempt to load an SQLite extension library contained in the file
//	** zFile.  The entry point is zProc.  zProc may be 0 in which case a
//	** default entry point name (sqlite3_extension_init) is used.  Use
//	** of the default name is recommended.
//	**
//	** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
//	**
//	** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
//	** error message text.  The calling function should free this memory
//	** by calling sqlite3DbFree(db, ).
//	*/
func _sqlite3LoadExtension(tls *libc.TLS, db uintptr, zFile uintptr, zProc uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aHandle, handle, pVfs, zAltEntry, zAltFile, zEntry, v1, v10, v7, v9 uintptr
	var c, iEntry, iFile, ii, ncFile, rc, v5, v6, v8 int32
	var nMsg Tu64
	var xInit Tsqlite3_loadext_entry
	var _ /* zErrmsg at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aHandle, c, handle, iEntry, iFile, ii, nMsg, ncFile, pVfs, rc, xInit, zAltEntry, zAltFile, zEntry, v1, v10, v5, v6, v7, v8, v9
	pVfs = (*Tsqlite3)(unsafe.Pointer(db)).FpVfs
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	zAltEntry = uintptr(0)
	nMsg = uint64(libc.Xstrlen(tls, zFile))
	if pzErrMsg != 0 {
		*(*uintptr)(unsafe.Pointer(pzErrMsg)) = uintptr(0)
	}
	/* Ticket #1863.  To avoid a creating security problems for older
	 ** applications that relink against newer versions of SQLite, the
	 ** ability to run load_extension is turned off by default.  One
	 ** must call either sqlite3_enable_load_extension(db) or
	 ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
	 ** to turn on extension loading.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LoadExtension) == uint64(0) {
		if pzErrMsg != 0 {
			*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+13854, 0)
		}
		return int32(SQLITE_ERROR)
	}
	if zProc != 0 {
		v1 = zProc
	} else {
		v1 = __ccgo_ts + 17720
	}
	zEntry = v1
	/* tag-20210611-1.  Some dlopen() implementations will segfault if given
	 ** an oversize filename.  Most filesystems have a pathname limit of 4K,
	 ** so limit the extension filename length to about twice that.
	 ** https://sqlite.org/forum/forumpost/08a0d6d9bf
	 **
	 ** Later (2023-03-25): Save an extra 6 bytes for the filename suffix.
	 ** See https://sqlite.org/forum/forumpost/24083b579d.
	 */
	if nMsg > uint64(FILENAME_MAX) {
		goto extension_not_found
	}
	/* Do not allow sqlite3_load_extension() to link to a copy of the
	 ** running application, by passing in an empty filename. */
	if nMsg == uint64(0) {
		goto extension_not_found
	}
	handle = _sqlite3OsDlOpen(tls, pVfs, zFile)
	ii = 0
	for {
		if !(ii < int32(libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)) && handle == uintptr(0)) {
			break
		}
		zAltFile = Xsqlite3_mprintf(tls, __ccgo_ts+13815, libc.VaList(bp+16, zFile, _azEndings[ii]))
		if zAltFile == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		if nMsg+uint64(libc.Xstrlen(tls, _azEndings[ii]))+uint64(1) <= uint64(FILENAME_MAX) {
			handle = _sqlite3OsDlOpen(tls, pVfs, zAltFile)
		}
		Xsqlite3_free(tls, zAltFile)
		goto _2
	_2:
		;
		ii++
	}
	if handle == uintptr(0) {
		goto extension_not_found
	}
	xInit = _sqlite3OsDlSym(tls, pVfs, handle, zEntry)
	/* If no entry point was specified and the default legacy
	 ** entry point name "sqlite3_extension_init" was not found, then
	 ** construct an entry point name "sqlite3_X_init" where the X is
	 ** replaced by the lowercase value of every ASCII alphabetic
	 ** character in the filename after the last "/" upto the first ".",
	 ** and eliding the first three characters if they are "lib".
	 ** Examples:
	 **
	 **    /usr/local/lib/libExample5.4.3.so ==>  sqlite3_example_init
	 **    C:/lib/mathfuncs.dll              ==>  sqlite3_mathfuncs_init
	 */
	if xInit == uintptr(0) && zProc == uintptr(0) {
		ncFile = _sqlite3Strlen30(tls, zFile)
		zAltEntry = Xsqlite3_malloc64(tls, uint64(ncFile+int32(30)))
		if zAltEntry == uintptr(0) {
			_sqlite3OsDlClose(tls, pVfs, handle)
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemcpy(tls, zAltEntry, __ccgo_ts+17743, uint32(8))
		iFile = ncFile - int32(1)
		for {
			if !(iFile >= 0 && !(int32(*(*int8)(unsafe.Pointer(zFile + uintptr(iFile)))) == int32('/') || int32(*(*int8)(unsafe.Pointer(zFile + uintptr(iFile)))) == int32('\\'))) {
				break
			}
			goto _3
		_3:
			;
			iFile--
		}
		iFile++
		if Xsqlite3_strnicmp(tls, zFile+uintptr(iFile), __ccgo_ts+17752, int32(3)) == 0 {
			iFile += int32(3)
		}
		iEntry = int32(8)
		for {
			v5 = int32(*(*int8)(unsafe.Pointer(zFile + uintptr(iFile))))
			c = v5
			if !(v5 != 0 && c != int32('.')) {
				break
			}
			if int32(_sqlite3CtypeMap[uint8(c)])&int32(0x02) != 0 {
				v6 = iEntry
				iEntry++
				*(*int8)(unsafe.Pointer(zAltEntry + uintptr(v6))) = int8(_sqlite3UpperToLower[uint32(uint32(c))])
			}
			goto _4
		_4:
			;
			iFile++
		}
		libc.Xmemcpy(tls, zAltEntry+uintptr(iEntry), __ccgo_ts+17756, uint32(6))
		zEntry = zAltEntry
		xInit = _sqlite3OsDlSym(tls, pVfs, handle, zEntry)
	}
	if xInit == uintptr(0) {
		if pzErrMsg != 0 {
			nMsg += uint64(libc.Xstrlen(tls, zEntry) + uint32(300))
			v7 = Xsqlite3_malloc64(tls, nMsg)
			*(*uintptr)(unsafe.Pointer(bp)) = v7
			*(*uintptr)(unsafe.Pointer(pzErrMsg)) = v7
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				/* zErrmsg would be NULL if not so */
				Xsqlite3_snprintf(tls, int32(int32(nMsg)), *(*uintptr)(unsafe.Pointer(bp)), __ccgo_ts+17762, libc.VaList(bp+16, zEntry, zFile))
				_sqlite3OsDlError(tls, pVfs, int32(nMsg-uint64(1)), *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		_sqlite3OsDlClose(tls, pVfs, handle)
		Xsqlite3_free(tls, zAltEntry)
		return int32(SQLITE_ERROR)
	}
	Xsqlite3_free(tls, zAltEntry)
	rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xInit})))(tls, db, bp, uintptr(unsafe.Pointer(&_sqlite3Apis)))
	if rc != 0 {
		if rc == libc.Int32FromInt32(SQLITE_OK)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8) {
			return SQLITE_OK
		}
		if pzErrMsg != 0 {
			*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+17805, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp))))
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
		_sqlite3OsDlClose(tls, pVfs, handle)
		return int32(SQLITE_ERROR)
	}
	/* Append the new shared library handle to the db->aExtension array. */
	aHandle = _sqlite3DbMallocZero(tls, db, uint64(uint32(4)*uint32((*Tsqlite3)(unsafe.Pointer(db)).FnExtension+libc.Int32FromInt32(1))))
	if aHandle == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FnExtension > 0 {
		libc.Xmemcpy(tls, aHandle, (*Tsqlite3)(unsafe.Pointer(db)).FaExtension, uint32(4)*uint32((*Tsqlite3)(unsafe.Pointer(db)).FnExtension))
	}
	_sqlite3DbFree(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaExtension)
	(*Tsqlite3)(unsafe.Pointer(db)).FaExtension = aHandle
	v9 = db + 208
	v8 = *(*int32)(unsafe.Pointer(v9))
	*(*int32)(unsafe.Pointer(v9))++
	*(*uintptr)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaExtension + uintptr(v8)*4)) = handle
	return SQLITE_OK
	goto extension_not_found
extension_not_found:
	;
	if pzErrMsg != 0 {
		nMsg += uint64(300)
		v10 = Xsqlite3_malloc64(tls, nMsg)
		*(*uintptr)(unsafe.Pointer(bp)) = v10
		*(*uintptr)(unsafe.Pointer(pzErrMsg)) = v10
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			/* zErrmsg would be NULL if not so */
			Xsqlite3_snprintf(tls, int32(int32(nMsg)), *(*uintptr)(unsafe.Pointer(bp)), __ccgo_ts+17837, libc.VaList(bp+16, int32(FILENAME_MAX), zFile))
			_sqlite3OsDlError(tls, pVfs, int32(nMsg-uint64(1)), *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	return int32(SQLITE_ERROR)
}

/* Shared library endings to try if zFile cannot be loaded as written */
var _azEndings = [1]uintptr{
	0: __ccgo_ts + 17716,
}

func Xsqlite3_load_extension(tls *libc.TLS, db uintptr, zFile uintptr, zProc uintptr, pzErrMsg uintptr) (r int32) {
	var rc int32
	_ = rc
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	rc = _sqlite3LoadExtension(tls, db, zFile, zProc, pzErrMsg)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Call this routine when the database connection is closing in order
//	** to clean up loaded extensions
//	*/
func _sqlite3CloseExtensions(tls *libc.TLS, db uintptr) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnExtension) {
			break
		}
		_sqlite3OsDlClose(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, *(*uintptr)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaExtension + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
	_sqlite3DbFree(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaExtension)
}

// C documentation
//
//	/*
//	** Enable or disable extension loading.  Extension loading is disabled by
//	** default so as not to open security holes in older applications.
//	*/
func Xsqlite3_enable_load_extension(tls *libc.TLS, db uintptr, onoff int32) (r int32) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if onoff != 0 {
		*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(libc.Int32FromInt32(SQLITE_LoadExtension) | libc.Int32FromInt32(SQLITE_LoadExtFunc))
	} else {
		*(*Tu64)(unsafe.Pointer(db + 32)) &= ^uint64(libc.Int32FromInt32(SQLITE_LoadExtension) | libc.Int32FromInt32(SQLITE_LoadExtFunc))
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The following object holds the list of automatically loaded
//	** extensions.
//	**
//	** This list is shared across threads.  The SQLITE_MUTEX_STATIC_MAIN
//	** mutex must be held while accessing this list.
//	*/
type Tsqlite3AutoExtList = struct {
	FnExt Tu32
	FaExt uintptr
}

type sqlite3AutoExtList = Tsqlite3AutoExtList

type Tsqlite3AutoExtList1 = struct {
	FnExt Tu32
	FaExt uintptr
}

type sqlite3AutoExtList1 = Tsqlite3AutoExtList1

var _sqlite3Autoext = Tsqlite3AutoExtList1{}

/* The "wsdAutoext" macro will resolve to the autoextension
** state vector.  If writable static data is unsupported on the target,
** we have to locate the state vector at run-time.  In the more common
** case where writable static data is supported, wsdStat can refer directly
** to the "sqlite3Autoext" state vector declared above.
 */

// C documentation
//
//	/*
//	** Register a statically linked extension that is automatically
//	** loaded by every new database connection.
//	*/
func Xsqlite3_auto_extension(tls *libc.TLS, xInit uintptr) (r int32) {
	var aNew, mutex uintptr
	var i Tu32
	var nByte Tu64
	var rc int32
	_, _, _, _, _ = aNew, i, mutex, nByte, rc
	rc = SQLITE_OK
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	} else {
		mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
		Xsqlite3_mutex_enter(tls, mutex)
		i = uint32(0)
		for {
			if !(i < _sqlite3Autoext.FnExt) {
				break
			}
			if *(*uintptr)(unsafe.Pointer(_sqlite3Autoext.FaExt + uintptr(i)*4)) == xInit {
				break
			}
			goto _1
		_1:
			;
			i++
		}
		if i == _sqlite3Autoext.FnExt {
			nByte = uint64((_sqlite3Autoext.FnExt + uint32(1)) * uint32(4))
			aNew = Xsqlite3_realloc64(tls, _sqlite3Autoext.FaExt, nByte)
			if aNew == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				_sqlite3Autoext.FaExt = aNew
				*(*uintptr)(unsafe.Pointer(_sqlite3Autoext.FaExt + uintptr(_sqlite3Autoext.FnExt)*4)) = xInit
				_sqlite3Autoext.FnExt++
			}
		}
		Xsqlite3_mutex_leave(tls, mutex)
		return rc
	}
	return r
}

// C documentation
//
//	/*
//	** Cancel a prior call to sqlite3_auto_extension.  Remove xInit from the
//	** set of routines that is invoked for each new database connection, if it
//	** is currently on the list.  If xInit is not on the list, then this
//	** routine is a no-op.
//	**
//	** Return 1 if xInit was found on the list and removed.  Return 0 if xInit
//	** was not on the list.
//	*/
func Xsqlite3_cancel_auto_extension(tls *libc.TLS, xInit uintptr) (r int32) {
	var i, n int32
	var mutex uintptr
	_, _, _ = i, mutex, n
	mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
	n = 0
	Xsqlite3_mutex_enter(tls, mutex)
	i = int32(_sqlite3Autoext.FnExt) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		if *(*uintptr)(unsafe.Pointer(_sqlite3Autoext.FaExt + uintptr(i)*4)) == xInit {
			_sqlite3Autoext.FnExt--
			*(*uintptr)(unsafe.Pointer(_sqlite3Autoext.FaExt + uintptr(i)*4)) = *(*uintptr)(unsafe.Pointer(_sqlite3Autoext.FaExt + uintptr(_sqlite3Autoext.FnExt)*4))
			n++
			break
		}
		goto _1
	_1:
		;
		i--
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return n
}

// C documentation
//
//	/*
//	** Reset the automatic extension loading mechanism.
//	*/
func Xsqlite3_reset_auto_extension(tls *libc.TLS) {
	var mutex uintptr
	_ = mutex
	if Xsqlite3_initialize(tls) == SQLITE_OK {
		mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
		Xsqlite3_mutex_enter(tls, mutex)
		Xsqlite3_free(tls, _sqlite3Autoext.FaExt)
		_sqlite3Autoext.FaExt = uintptr(0)
		_sqlite3Autoext.FnExt = uint32(0)
		Xsqlite3_mutex_leave(tls, mutex)
	}
}

// C documentation
//
//	/*
//	** Load all automatic extensions.
//	**
//	** If anything goes wrong, set an error in the database connection.
//	*/
func _sqlite3AutoLoadExtensions(tls *libc.TLS, db uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var go1, rc, v2 int32
	var i Tu32
	var mutex, pThunk uintptr
	var xInit Tsqlite3_loadext_entry
	var v3 bool
	var _ /* zErrmsg at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = go1, i, mutex, pThunk, rc, xInit, v2, v3
	go1 = int32(1)
	if _sqlite3Autoext.FnExt == uint32(0) {
		/* Common case: early out without every having to acquire a mutex */
		return
	}
	i = uint32(0)
	for {
		if !(go1 != 0) {
			break
		}
		mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
		pThunk = uintptr(unsafe.Pointer(&_sqlite3Apis))
		Xsqlite3_mutex_enter(tls, mutex)
		if i >= _sqlite3Autoext.FnExt {
			xInit = uintptr(0)
			go1 = 0
		} else {
			xInit = *(*uintptr)(unsafe.Pointer(_sqlite3Autoext.FaExt + uintptr(i)*4))
		}
		Xsqlite3_mutex_leave(tls, mutex)
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		if v3 = xInit != 0; v3 {
			v2 = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xInit})))(tls, db, bp, pThunk)
			rc = v2
		}
		if v3 && v2 != 0 {
			_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+17874, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp))))
			go1 = 0
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
		goto _1
	_1:
		;
		i++
	}
}

/************** End of loadext.c *********************************************/
/************** Begin file pragma.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 PRAGMA command.
 */
/* #include "sqliteInt.h" */

/***************************************************************************
** The "pragma.h" include file is an automatically generated file that
** that includes the PragType_XXXX macro definitions and the aPragmaName[]
** object.  This ensures that the aPragmaName[] table is arranged in
** lexicographical order to facility a binary search of the pragma name.
** Do not edit pragma.h directly.  Edit and rerun the script in at
** ../tool/mkpragmatab.tcl. */
/************** Include pragma.h in the middle of pragma.c *******************/
/************** Begin file pragma.h ******************************************/
/* DO NOT EDIT!
** This file is automatically generated by the script at
** ../tool/mkpragmatab.tcl.  To update the set of pragmas, edit
** that script and rerun it.
 */

/* The various pragma types */

/* Property flags associated with various pragma. */

// C documentation
//
//	/* Names of columns for pragmas that return multi-column result
//	** or that return single-column results where the name of the
//	** result column is different from the name of the pragma
//	*/
var _pragCName = [57]uintptr{
	0:  __ccgo_ts + 6854,
	1:  __ccgo_ts + 17913,
	2:  __ccgo_ts + 10492,
	3:  __ccgo_ts + 17917,
	4:  __ccgo_ts + 17922,
	5:  __ccgo_ts + 17925,
	6:  __ccgo_ts + 17935,
	7:  __ccgo_ts + 17945,
	8:  __ccgo_ts + 17951,
	9:  __ccgo_ts + 17955,
	10: __ccgo_ts + 17960,
	11: __ccgo_ts + 17965,
	12: __ccgo_ts + 17973,
	13: __ccgo_ts + 17984,
	14: __ccgo_ts + 17987,
	15: __ccgo_ts + 17994,
	16: __ccgo_ts + 17955,
	17: __ccgo_ts + 17960,
	18: __ccgo_ts + 18001,
	19: __ccgo_ts + 18006,
	20: __ccgo_ts + 18009,
	21: __ccgo_ts + 18016,
	22: __ccgo_ts + 17951,
	23: __ccgo_ts + 17955,
	24: __ccgo_ts + 18022,
	25: __ccgo_ts + 18027,
	26: __ccgo_ts + 18032,
	27: __ccgo_ts + 17955,
	28: __ccgo_ts + 18036,
	29: __ccgo_ts + 17960,
	30: __ccgo_ts + 18044,
	31: __ccgo_ts + 18048,
	32: __ccgo_ts + 18053,
	33: __ccgo_ts + 13231,
	34: __ccgo_ts + 13227,
	35: __ccgo_ts + 18059,
	36: __ccgo_ts + 18064,
	37: __ccgo_ts + 18069,
	38: __ccgo_ts + 17913,
	39: __ccgo_ts + 17955,
	40: __ccgo_ts + 18074,
	41: __ccgo_ts + 18081,
	42: __ccgo_ts + 18088,
	43: __ccgo_ts + 10492,
	44: __ccgo_ts + 18096,
	45: __ccgo_ts + 6857,
	46: __ccgo_ts + 18102,
	47: __ccgo_ts + 17913,
	48: __ccgo_ts + 17955,
	49: __ccgo_ts + 18107,
	50: __ccgo_ts + 18112,
	51: __ccgo_ts + 17300,
	52: __ccgo_ts + 18117,
	53: __ccgo_ts + 18130,
	54: __ccgo_ts + 18139,
	55: __ccgo_ts + 18146,
	56: __ccgo_ts + 18157,
}

// C documentation
//
//	/* Definitions of all built-in pragmas */
type TPragmaName = struct {
	F__ccgo_align [0]uint32
	FzName        uintptr
	FePragTyp     Tu8
	FmPragFlg     Tu8
	FiPragCName   Tu8
	FnPragCName   Tu8
	FiArg         Tu64
}

type PragmaName = TPragmaName

var _aPragmaName = [67]TPragmaName{
	0: {
		FzName:    __ccgo_ts + 18165,
		FePragTyp: uint8(PragTyp_ANALYSIS_LIMIT),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	1: {
		FzName:    __ccgo_ts + 18180,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_APPLICATION_ID),
	},
	2: {
		FzName:    __ccgo_ts + 18195,
		FePragTyp: uint8(PragTyp_AUTO_VACUUM),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	3: {
		FzName:    __ccgo_ts + 18207,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_AutoIndex),
	},
	4: {
		FzName:      __ccgo_ts + 18223,
		FePragTyp:   uint8(PragTyp_BUSY_TIMEOUT),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(56),
		FnPragCName: uint8(1),
	},
	5: {
		FzName:    __ccgo_ts + 18146,
		FePragTyp: uint8(PragTyp_CACHE_SIZE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	6: {
		FzName:    __ccgo_ts + 18236,
		FePragTyp: uint8(PragTyp_CACHE_SPILL),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	7: {
		FzName:    __ccgo_ts + 18248,
		FePragTyp: uint8(PragTyp_CASE_SENSITIVE_LIKE),
		FmPragFlg: uint8(PragFlg_NoColumns),
	},
	8: {
		FzName:    __ccgo_ts + 18268,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_CellSizeCk),
	},
	9: {
		FzName:    __ccgo_ts + 18284,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_CkptFullFSync),
	},
	10: {
		FzName:      __ccgo_ts + 18305,
		FePragTyp:   uint8(PragTyp_COLLATION_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(38),
		FnPragCName: uint8(2),
	},
	11: {
		FzName:    __ccgo_ts + 18320,
		FePragTyp: uint8(PragTyp_COMPILE_OPTIONS),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	12: {
		FzName:    __ccgo_ts + 18336,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(libc.Int32FromInt32(0x00001)) << libc.Int32FromInt32(32),
	},
	13: {
		FzName:    __ccgo_ts + 18350,
		FePragTyp: uint8(PragTyp_DATA_STORE_DIRECTORY),
		FmPragFlg: uint8(PragFlg_NoColumns1),
	},
	14: {
		FzName:    __ccgo_ts + 18371,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_ReadOnly) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_DATA_VERSION),
	},
	15: {
		FzName:      __ccgo_ts + 18384,
		FePragTyp:   uint8(PragTyp_DATABASE_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(47),
		FnPragCName: uint8(3),
	},
	16: {
		FzName:      __ccgo_ts + 18398,
		FePragTyp:   uint8(PragTyp_DEFAULT_CACHE_SIZE),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiPragCName: uint8(55),
		FnPragCName: uint8(1),
	},
	17: {
		FzName:    __ccgo_ts + 18417,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_DeferFKs),
	},
	18: {
		FzName:    __ccgo_ts + 18436,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_NullCallback),
	},
	19: {
		FzName:    __ccgo_ts + 18459,
		FePragTyp: uint8(PragTyp_ENCODING),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	20: {
		FzName:      __ccgo_ts + 18468,
		FePragTyp:   uint8(PragTyp_FOREIGN_KEY_CHECK),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(43),
		FnPragCName: uint8(4),
	},
	21: {
		FzName:      __ccgo_ts + 18486,
		FePragTyp:   uint8(PragTyp_FOREIGN_KEY_LIST),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FnPragCName: uint8(8),
	},
	22: {
		FzName:    __ccgo_ts + 18503,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_ForeignKeys),
	},
	23: {
		FzName:    __ccgo_ts + 18516,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_ReadOnly) | libc.Int32FromInt32(PragFlg_Result0)),
	},
	24: {
		FzName:    __ccgo_ts + 18531,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_FullColNames),
	},
	25: {
		FzName:    __ccgo_ts + 18549,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_FullFSync),
	},
	26: {
		FzName:      __ccgo_ts + 18559,
		FePragTyp:   uint8(PragTyp_FUNCTION_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(27),
		FnPragCName: uint8(6),
	},
	27: {
		FzName:    __ccgo_ts + 18573,
		FePragTyp: uint8(PragTyp_HARD_HEAP_LIMIT),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	28: {
		FzName:    __ccgo_ts + 18589,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_IgnoreChecks),
	},
	29: {
		FzName:    __ccgo_ts + 18614,
		FePragTyp: uint8(PragTyp_INCREMENTAL_VACUUM),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_NoColumns)),
	},
	30: {
		FzName:      __ccgo_ts + 18633,
		FePragTyp:   uint8(PragTyp_INDEX_INFO),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(21),
		FnPragCName: uint8(3),
	},
	31: {
		FzName:      __ccgo_ts + 18644,
		FePragTyp:   uint8(PragTyp_INDEX_LIST),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(38),
		FnPragCName: uint8(5),
	},
	32: {
		FzName:      __ccgo_ts + 18655,
		FePragTyp:   uint8(PragTyp_INDEX_INFO),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(21),
		FnPragCName: uint8(6),
		FiArg:       uint64(1),
	},
	33: {
		FzName:    __ccgo_ts + 18667,
		FePragTyp: uint8(PragTyp_INTEGRITY_CHECK),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
	},
	34: {
		FzName:    __ccgo_ts + 18683,
		FePragTyp: uint8(PragTyp_JOURNAL_MODE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	35: {
		FzName:    __ccgo_ts + 18696,
		FePragTyp: uint8(PragTyp_JOURNAL_SIZE_LIMIT),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	36: {
		FzName:    __ccgo_ts + 18715,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_LegacyAlter),
	},
	37: {
		FzName:    __ccgo_ts + 18734,
		FePragTyp: uint8(PragTyp_LOCKING_MODE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	38: {
		FzName:    __ccgo_ts + 18747,
		FePragTyp: uint8(PragTyp_PAGE_COUNT),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	39: {
		FzName:    __ccgo_ts + 18762,
		FePragTyp: uint8(PragTyp_MMAP_SIZE),
	},
	40: {
		FzName:      __ccgo_ts + 18772,
		FePragTyp:   uint8(PragTyp_MODULE_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(9),
		FnPragCName: uint8(1),
	},
	41: {
		FzName:    __ccgo_ts + 18784,
		FePragTyp: uint8(PragTyp_OPTIMIZE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_NeedSchema)),
	},
	42: {
		FzName:    __ccgo_ts + 18793,
		FePragTyp: uint8(PragTyp_PAGE_COUNT),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	43: {
		FzName:    __ccgo_ts + 18804,
		FePragTyp: uint8(PragTyp_PAGE_SIZE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	44: {
		FzName:      __ccgo_ts + 18814,
		FePragTyp:   uint8(PragTyp_PRAGMA_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(9),
		FnPragCName: uint8(1),
	},
	45: {
		FzName:    __ccgo_ts + 18826,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_QueryOnly),
	},
	46: {
		FzName:    __ccgo_ts + 18837,
		FePragTyp: uint8(PragTyp_INTEGRITY_CHECK),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
	},
	47: {
		FzName:    __ccgo_ts + 18849,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(libc.Int32FromInt32(0x00004)) << libc.Int32FromInt32(32),
	},
	48: {
		FzName:    __ccgo_ts + 18866,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_RecTriggers),
	},
	49: {
		FzName:    __ccgo_ts + 18885,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_ReverseOrder),
	},
	50: {
		FzName:    __ccgo_ts + 18911,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_SCHEMA_VERSION),
	},
	51: {
		FzName:    __ccgo_ts + 18926,
		FePragTyp: uint8(PragTyp_SECURE_DELETE),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	52: {
		FzName:    __ccgo_ts + 18940,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_ShortColNames),
	},
	53: {
		FzName:    __ccgo_ts + 18959,
		FePragTyp: uint8(PragTyp_SHRINK_MEMORY),
		FmPragFlg: uint8(PragFlg_NoColumns),
	},
	54: {
		FzName:    __ccgo_ts + 18973,
		FePragTyp: uint8(PragTyp_SOFT_HEAP_LIMIT),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	55: {
		FzName:    __ccgo_ts + 18989,
		FePragTyp: uint8(PragTyp_SYNCHRONOUS),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	56: {
		FzName:      __ccgo_ts + 19001,
		FePragTyp:   uint8(PragTyp_TABLE_INFO),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(8),
		FnPragCName: uint8(6),
	},
	57: {
		FzName:      __ccgo_ts + 19012,
		FePragTyp:   uint8(PragTyp_TABLE_LIST),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1)),
		FiPragCName: uint8(15),
		FnPragCName: uint8(6),
	},
	58: {
		FzName:      __ccgo_ts + 19023,
		FePragTyp:   uint8(PragTyp_TABLE_INFO),
		FmPragFlg:   uint8(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(8),
		FnPragCName: uint8(7),
		FiArg:       uint64(1),
	},
	59: {
		FzName:    __ccgo_ts + 19035,
		FePragTyp: uint8(PragTyp_TEMP_STORE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	60: {
		FzName:    __ccgo_ts + 19046,
		FePragTyp: uint8(PragTyp_TEMP_STORE_DIRECTORY),
		FmPragFlg: uint8(PragFlg_NoColumns1),
	},
	61: {
		FzName:    __ccgo_ts + 19067,
		FePragTyp: uint8(PragTyp_THREADS),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	62: {
		FzName:    __ccgo_ts + 19075,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_TrustedSchema),
	},
	63: {
		FzName:    __ccgo_ts + 19090,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_USER_VERSION),
	},
	64: {
		FzName:    __ccgo_ts + 19103,
		FePragTyp: uint8(PragTyp_WAL_AUTOCHECKPOINT),
	},
	65: {
		FzName:      __ccgo_ts + 19122,
		FePragTyp:   uint8(PragTyp_WAL_CHECKPOINT),
		FmPragFlg:   uint8(PragFlg_NeedSchema),
		FiPragCName: uint8(50),
		FnPragCName: uint8(3),
	},
	66: {
		FzName:    __ccgo_ts + 19137,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: uint8(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(libc.Int32FromInt32(SQLITE_WriteSchema) | libc.Int32FromInt32(SQLITE_NoSchemaError)),
	},
}

/* Number of pragmas: 68 on by default, 78 total. */

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

/*
** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
** will be run with an analysis_limit set to the lessor of the value of
** the following macro or to the actual analysis_limit if it is non-zero,
** in order to prevent PRAGMA optimize from running for too long.
**
** The value of 2000 is chosen emperically so that the worst-case run-time
** for PRAGMA optimize does not exceed 100 milliseconds against a variety
** of test databases on a RaspberryPI-4 compiled using -Os and without
** -DSQLITE_DEBUG.  Of course, your mileage may vary.  For the purpose of
** this paragraph, "worst-case" means that ANALYZE ends up being
** run on every table in the database.  The worst case typically only
** happens if PRAGMA optimize is run on a database file for which ANALYZE
** has not been previously run and the 0x10000 flag is included so that
** all tables are analyzed.  The usual case for PRAGMA optimize is that
** no ANALYZE commands will be run at all, or if any ANALYZE happens it
** will be against a single table, so that expected timing for PRAGMA
** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
** flag or less than 100 microseconds without the 0x10000 flag.
**
** An analysis limit of 2000 is almost always sufficient for the query
** planner to fully characterize an index.  The additional accuracy from
** a larger analysis is not usually helpful.
 */

// C documentation
//
//	/*
//	** Interpret the given string as a safety level.  Return 0 for OFF,
//	** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA.  Return 1 for an empty or
//	** unrecognized string argument.  The FULL and EXTRA option is disallowed
//	** if the omitFull parameter it 1.
//	**
//	** Note that the values returned are one less that the values that
//	** should be passed into sqlite3BtreeSetSafetyLevel().  The is done
//	** to support legacy SQL code.  The safety level used to be boolean
//	** and older scripts may have used numbers 0 for OFF and 1 for ON.
//	*/
func _getSafetyLevel(tls *libc.TLS, z uintptr, omitFull int32, dflt Tu8) (r Tu8) {
	var i, n int32
	_, _ = i, n
	if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x04) != 0 {
		return uint8(_sqlite3Atoi(tls, z))
	}
	n = _sqlite3Strlen30(tls, z)
	i = 0
	for {
		if !(i < int32(libc.Uint32FromInt64(8)/libc.Uint32FromInt64(1))) {
			break
		}
		if int32(_iLength[i]) == n && Xsqlite3_strnicmp(tls, uintptr(unsafe.Pointer(&_zText))+uintptr(_iOffset[i]), z, n) == 0 && (!(omitFull != 0) || int32(_iValue[i]) <= int32(1)) {
			return _iValue[i]
		}
		goto _1
	_1:
		;
		i++
	}
	return dflt
}

/* 123456789 123456789 123 */
var _zText = [25]int8{'o', 'n', 'o', 'f', 'f', 'a', 'l', 's', 'e', 'y', 'e', 's', 't', 'r', 'u', 'e', 'x', 't', 'r', 'a', 'f', 'u', 'l', 'l'}

var _iOffset = [8]Tu8{
	1: uint8(1),
	2: uint8(2),
	3: uint8(4),
	4: uint8(9),
	5: uint8(12),
	6: uint8(15),
	7: uint8(20),
}

var _iLength = [8]Tu8{
	0: uint8(2),
	1: uint8(2),
	2: uint8(3),
	3: uint8(5),
	4: uint8(3),
	5: uint8(4),
	6: uint8(5),
	7: uint8(4),
}

var _iValue = [8]Tu8{
	0: uint8(1),
	4: uint8(1),
	5: uint8(1),
	6: uint8(3),
	7: uint8(2),
}

// C documentation
//
//	/*
//	** Interpret the given string as a boolean value.
//	*/
func _sqlite3GetBoolean(tls *libc.TLS, z uintptr, dflt Tu8) (r Tu8) {
	return libc.BoolUint8(int32(_getSafetyLevel(tls, z, int32(1), dflt)) != 0)
}

/* The sqlite3GetBoolean() function is used by other modules but the
** remainder of this file is specific to PRAGMA processing.  So omit
** the rest of the file if PRAGMAs are omitted from the build.
 */

// C documentation
//
//	/*
//	** Interpret the given string as a locking mode value.
//	*/
func _getLockingMode(tls *libc.TLS, z uintptr) (r int32) {
	if z != 0 {
		if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+5170) {
			return int32(PAGER_LOCKINGMODE_EXCLUSIVE)
		}
		if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19153) {
			return PAGER_LOCKINGMODE_NORMAL
		}
	}
	return -int32(1)
}

// C documentation
//
//	/*
//	** Interpret the given string as an auto-vacuum mode value.
//	**
//	** The following strings, "none", "full" and "incremental" are
//	** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
//	*/
func _getAutoVacuum(tls *libc.TLS, z uintptr) (r int32) {
	var i, v1 int32
	_, _ = i, v1
	if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+9652) {
		return BTREE_AUTOVACUUM_NONE
	}
	if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19160) {
		return int32(BTREE_AUTOVACUUM_FULL)
	}
	if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19165) {
		return int32(BTREE_AUTOVACUUM_INCR)
	}
	i = _sqlite3Atoi(tls, z)
	if i >= 0 && i <= int32(2) {
		v1 = i
	} else {
		v1 = 0
	}
	return int32(uint8(v1))
}

// C documentation
//
//	/*
//	** Interpret the given string as a temp db location. Return 1 for file
//	** backed temporary databases, 2 for the Red-Black tree in memory database
//	** and 0 to use the compile-time default.
//	*/
func _getTempStore(tls *libc.TLS, z uintptr) (r int32) {
	if int32(*(*int8)(unsafe.Pointer(z))) >= int32('0') && int32(*(*int8)(unsafe.Pointer(z))) <= int32('2') {
		return int32(*(*int8)(unsafe.Pointer(z))) - int32('0')
	} else {
		if _sqlite3StrICmp(tls, z, __ccgo_ts+18107) == 0 {
			return int32(1)
		} else {
			if _sqlite3StrICmp(tls, z, __ccgo_ts+19177) == 0 {
				return int32(2)
			} else {
				return 0
			}
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Invalidate temp storage, either when the temp storage is changed
//	** from default, or when 'file' and the temp_store_directory has changed
//	*/
func _invalidateTempStorage(tls *libc.TLS, pParse uintptr) (r int32) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpBt != uintptr(0) {
		if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) || _sqlite3BtreeTxnState(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpBt) != SQLITE_TXN_NONE {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19184, 0)
			return int32(SQLITE_ERROR)
		}
		_sqlite3BtreeClose(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpBt)
		(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpBt = uintptr(0)
		_sqlite3ResetAllSchemasOfConnection(tls, db)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If the TEMP database is open, close it and mark the database schema
//	** as needing reloading.  This must be done when using the SQLITE_TEMP_STORE
//	** or DEFAULT_TEMP_STORE pragmas.
//	*/
func _changeTempStorage(tls *libc.TLS, pParse uintptr, zStorageType uintptr) (r int32) {
	var db uintptr
	var ts int32
	_, _ = db, ts
	ts = _getTempStore(tls, zStorageType)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if int32((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) == ts {
		return SQLITE_OK
	}
	if _invalidateTempStorage(tls, pParse) != SQLITE_OK {
		return int32(SQLITE_ERROR)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store = uint8(uint8(ts))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Set result column names for a pragma.
//	*/
func _setPragmaResultColumnNames(tls *libc.TLS, v uintptr, pPragma uintptr) {
	var i, j, v1 int32
	var n Tu8
	_, _, _, _ = i, j, n, v1
	n = (*TPragmaName)(unsafe.Pointer(pPragma)).FnPragCName
	if int32(int32(n)) == 0 {
		v1 = int32(1)
	} else {
		v1 = int32(int32(n))
	}
	_sqlite3VdbeSetNumCols(tls, v, v1)
	if int32(int32(n)) == 0 {
		_sqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, (*TPragmaName)(unsafe.Pointer(pPragma)).FzName, libc.UintptrFromInt32(0))
	} else {
		i = 0
		j = int32((*TPragmaName)(unsafe.Pointer(pPragma)).FiPragCName)
		for {
			if !(i < int32(int32(n))) {
				break
			}
			_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, _pragCName[j], libc.UintptrFromInt32(0))
			goto _2
		_2:
			;
			i++
			j++
		}
	}
}

// C documentation
//
//	/*
//	** Generate code to return a single integer value.
//	*/
func _returnSingleInt(tls *libc.TLS, v uintptr, _value Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*Ti64)(unsafe.Pointer(bp)) = _value
	_sqlite3VdbeAddOp4Dup8(tls, v, int32(OP_Int64), 0, int32(1), 0, bp, -int32(13))
	_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(1))
}

// C documentation
//
//	/*
//	** Generate code to return a single text value.
//	*/
func _returnSingleText(tls *libc.TLS, v uintptr, zValue uintptr) {
	if zValue != 0 {
		_sqlite3VdbeLoadString(tls, v, int32(1), zValue)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(1))
	}
}

// C documentation
//
//	/*
//	** Set the safety_level and pager flags for pager iDb.  Or if iDb<0
//	** set these values for all pagers.
//	*/
func _setAllPagerFlags(tls *libc.TLS, db uintptr) {
	var n, v1 int32
	var pDb uintptr
	_, _, _ = n, pDb, v1
	if (*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
		n = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
		for {
			v1 = n
			n--
			if !(v1 > 0) {
				break
			}
			if (*TDb)(unsafe.Pointer(pDb)).FpBt != 0 {
				_sqlite3BtreeSetPagerFlags(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, uint32(uint64((*TDb)(unsafe.Pointer(pDb)).Fsafety_level)|(*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK)))
			}
			pDb += 16
		}
	}
}

// C documentation
//
//	/*
//	** Return a human-readable name for a constraint resolution action.
//	*/
func _actionName(tls *libc.TLS, action Tu8) (r uintptr) {
	var zName uintptr
	_ = zName
	switch int32(int32(action)) {
	case int32(OE_SetNull):
		zName = __ccgo_ts + 19246
	case int32(OE_SetDflt):
		zName = __ccgo_ts + 19255
	case int32(OE_Cascade):
		zName = __ccgo_ts + 19267
	case int32(OE_Restrict):
		zName = __ccgo_ts + 19275
	default:
		zName = __ccgo_ts + 19284
		break
	}
	return zName
}

// C documentation
//
//	/*
//	** Parameter eMode must be one of the PAGER_JOURNALMODE_XXX constants
//	** defined in pager.h. This function returns the associated lowercase
//	** journal-mode name.
//	*/
func _sqlite3JournalModename(tls *libc.TLS, eMode int32) (r uintptr) {
	if eMode == int32(libc.Uint32FromInt64(24)/libc.Uint32FromInt64(4)) {
		return uintptr(0)
	}
	return _azModeName[eMode]
}

var _azModeName = [6]uintptr{
	0: __ccgo_ts + 19294,
	1: __ccgo_ts + 19301,
	2: __ccgo_ts + 19309,
	3: __ccgo_ts + 19313,
	4: __ccgo_ts + 19177,
	5: __ccgo_ts + 19322,
}

// C documentation
//
//	/*
//	** Locate a pragma in the aPragmaName[] array.
//	*/
func _pragmaLocate(tls *libc.TLS, zName uintptr) (r uintptr) {
	var lwr, mid, rc, upr int32
	var v1 uintptr
	_, _, _, _, _ = lwr, mid, rc, upr, v1
	mid = 0
	lwr = 0
	upr = int32(libc.Uint32FromInt64(1072)/libc.Uint32FromInt64(16)) - libc.Int32FromInt32(1)
	for lwr <= upr {
		mid = (lwr + upr) / int32(2)
		rc = Xsqlite3_stricmp(tls, zName, _aPragmaName[mid].FzName)
		if rc == 0 {
			break
		}
		if rc < 0 {
			upr = mid - int32(1)
		} else {
			lwr = mid + int32(1)
		}
	}
	if lwr > upr {
		v1 = uintptr(0)
	} else {
		v1 = uintptr(unsafe.Pointer(&_aPragmaName)) + uintptr(mid)*16
	}
	return v1
}

// C documentation
//
//	/*
//	** Create zero or more entries in the output for the SQL functions
//	** defined by FuncDef p.
//	*/
func _pragmaFunclistLine(tls *libc.TLS, v uintptr, p uintptr, isBuiltin int32, showInternFuncs int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var mask Tu32
	var zType uintptr
	_, _ = mask, zType
	mask = uint32(libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_INNOCUOUS) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL))
	if showInternFuncs != 0 {
		mask = uint32(0xffffffff)
	}
	for {
		if !(p != 0) {
			break
		}
		if (*TFuncDef)(unsafe.Pointer(p)).FxSFunc == uintptr(0) {
			goto _1
		}
		if (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_INTERNAL) != uint32(0) && showInternFuncs == 0 {
			goto _1
		}
		if (*TFuncDef)(unsafe.Pointer(p)).FxValue != uintptr(0) {
			zType = __ccgo_ts + 19347
		} else {
			if (*TFuncDef)(unsafe.Pointer(p)).FxFinalize != uintptr(0) {
				zType = __ccgo_ts + 19349
			} else {
				zType = __ccgo_ts + 9051
			}
		}
		_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19351, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer(p)).FzName, isBuiltin, zType, _azEnc[(*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK)], int32((*TFuncDef)(unsafe.Pointer(p)).FnArg), (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&mask^uint32(SQLITE_INNOCUOUS)))
		goto _1
	_1:
		;
		p = (*TFuncDef)(unsafe.Pointer(p)).FpNext
	}
}

var _azEnc = [4]uintptr{
	1: __ccgo_ts + 19326,
	2: __ccgo_ts + 19331,
	3: __ccgo_ts + 19339,
}

// C documentation
//
//	/*
//	** Helper subroutine for PRAGMA integrity_check:
//	**
//	** Generate code to output a single-column result row with a value of the
//	** string held in register 3.  Decrement the result count in register 1
//	** and halt if the maximum number of result rows have been issued.
//	*/
func _integrityCheckResultRow(tls *libc.TLS, v uintptr) (r int32) {
	var addr int32
	_ = addr
	_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(3), int32(1))
	addr = _sqlite3VdbeAddOp3(tls, v, int32(OP_IfPos), int32(1), _sqlite3VdbeCurrentAddr(tls, v)+int32(2), int32(1))
	_sqlite3VdbeAddOp0(tls, v, int32(OP_Halt))
	return addr
}

// 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(208)
	defer tls.Free(208)
	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, v10, v15, v18, v2, v26, v33, v38, v4, v43, v45, v47, v48, v50, v64, v66, v67, v68, v69, v72, v75, v76 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, v14, v16, v22, v34, v39, v5, v65, v70, v8 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+104 */ Tsqlite3_int64
	var _ /* N at bp+112 */ Tsqlite3_int64
	var _ /* N at bp+120 */ Tsqlite3_int64
	var _ /* N at bp+96 */ Tsqlite3_int64
	var _ /* aFcntl at bp+4 */ [4]uintptr
	var _ /* aiCols at bp+72 */ uintptr
	var _ /* iDataCur at bp+80 */ int32
	var _ /* iIdxCur at bp+84 */ int32
	var _ /* iLimit at bp+32 */ Ti64
	var _ /* iLimit at bp+40 */ int32
	var _ /* jmp3 at bp+92 */ int32
	var _ /* mxErr at bp+76 */ int32
	var _ /* pDfltValue at bp+88 */ uintptr
	var _ /* pDummy at bp+64 */ uintptr
	var _ /* pId at bp+0 */ uintptr
	var _ /* pIdx at bp+68 */ uintptr
	var _ /* res at bp+56 */ int32
	var _ /* res at bp+60 */ int32
	var _ /* size at bp+44 */ int32
	var _ /* sz at bp+48 */ Tsqlite3_int64
	var _ /* x at bp+24 */ 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, v10, v14, v15, v16, v18, v2, v22, v26, v33, v34, v38, v39, v4, v43, v45, v47, v48, v5, v50, v64, v65, v66, v67, v68, v69, v70, v72, v75, v76, v8
	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)*16
	/* 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)(unsafe.Pointer(bp)))
	if !(zLeft != 0) {
		return
	}
	if minusFlag != 0 {
		zRight = _sqlite3MPrintf(tls, db, __ccgo_ts+19358, libc.VaList(bp+136, 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)(unsafe.Pointer(bp + 4)))[0] = uintptr(0)
	(*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[int32(1)] = zLeft
	(*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[int32(2)] = zRight
	(*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[int32(3)] = uintptr(0)
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	rc = Xsqlite3_file_control(tls, db, zDb, int32(SQLITE_FCNTL_PRAGMA), bp+4)
	if rc == SQLITE_OK {
		_sqlite3VdbeSetNumCols(tls, v, int32(1))
		_sqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, (*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[0], uintptr(-libc.Int32FromInt32(1)))
		_returnSingleText(tls, v, (*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[0])
		Xsqlite3_free(tls, (*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[0])
		goto pragma_out
	}
	if rc != int32(SQLITE_NOTFOUND) {
		if (*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[0] != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+4709, libc.VaList(bp+136, (*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[0]))
			Xsqlite3_free(tls, (*(*[4]uintptr)(unsafe.Pointer(bp + 4)))[0])
		}
		(*TParse)(unsafe.Pointer(pParse)).FnErr++
		(*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 int32((*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 int32((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns) == 0 && (int32((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns1) == 0 || zRight == uintptr(0)) {
		_setPragmaResultColumnNames(tls, v, pPragma)
	}
	/* Jump to the appropriate pragma handler */
	switch int32((*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)(unsafe.Pointer(pParse + 44)) += int32(2)
			aOp = _sqlite3VdbeAddOpList(tls, v, int32(libc.Uint32FromInt64(36)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_getCacheSize)), _iLn3)
			if 0 != 0 {
				break
			}
			(*(*TVdbeOp)(unsafe.Pointer(aOp))).Fp1 = iDb
			(*(*TVdbeOp)(unsafe.Pointer(aOp + 1*20))).Fp1 = iDb
			(*(*TVdbeOp)(unsafe.Pointer(aOp + 6*20))).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(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+19362) == 0 {
				b = int32(2)
			} else {
				b = int32(_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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*16))).FpBt, b)
				goto _3
			_3:
				;
				ii++
			}
		}
		b = _sqlite3BtreeSecureDelete(tls, pBt1, b)
		_returnSingleInt(tls, v, int64(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)(unsafe.Pointer(bp + 24)) = 0
		_sqlite3CodeVerifySchema(tls, pParse, iDb)
		v5 = pParse + 44
		*(*int32)(unsafe.Pointer(v5))++
		v4 = *(*int32)(unsafe.Pointer(v5))
		iReg = v4
		if int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(zLeft)))]) == int32('p') {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Pagecount), iDb, iReg)
		} else {
			if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+24) == 0 {
				if *(*Ti64)(unsafe.Pointer(bp + 24)) < 0 {
					*(*Ti64)(unsafe.Pointer(bp + 24)) = 0
				} else {
					if *(*Ti64)(unsafe.Pointer(bp + 24)) > libc.Int64FromUint32(0xfffffffe) {
						*(*Ti64)(unsafe.Pointer(bp + 24)) = libc.Int64FromUint32(0xfffffffe)
					}
				}
			} else {
				*(*Ti64)(unsafe.Pointer(bp + 24)) = 0
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MaxPgcnt), iDb, iReg, int32(*(*Ti64)(unsafe.Pointer(bp + 24))))
		}
		_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 + 19153
		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 = int32((*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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii1)*16))).FpBt)
					_sqlite3PagerLockingMode(tls, pPager, eMode)
					goto _6
				_6:
					;
					ii1++
				}
				(*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode = uint8(uint8(eMode))
			}
			pPager = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
			eMode = _sqlite3PagerLockingMode(tls, pPager, eMode)
		}
		if eMode == int32(PAGER_LOCKINGMODE_EXCLUSIVE) {
			zRet = __ccgo_ts + 5170
		}
		_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 {
				v8 = _sqlite3JournalModename(tls, eMode1)
				zMode = v8
				if !(v8 != uintptr(0)) {
					break
				}
				if Xsqlite3_strnicmp(tls, zRight, zMode, n) == 0 {
					break
				}
				goto _7
			_7:
				;
				eMode1++
			}
			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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii2)*16))).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--
		}
		_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)(unsafe.Pointer(bp + 32)) = int64(-int32(2))
		if zRight != 0 {
			_sqlite3DecOrHexToI64(tls, zRight, bp+32)
			if *(*Ti64)(unsafe.Pointer(bp + 32)) < int64(-int32(1)) {
				*(*Ti64)(unsafe.Pointer(bp + 32)) = int64(-int32(1))
			}
		}
		*(*Ti64)(unsafe.Pointer(bp + 32)) = _sqlite3PagerJournalSizeLimit(tls, pPager1, *(*Ti64)(unsafe.Pointer(bp + 32)))
		_returnSingleInt(tls, v, *(*Ti64)(unsafe.Pointer(bp + 32)))
		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 = int8(uint8(uint8(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, int32(libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_setMeta6)), _iLn11)
				if 0 != 0 {
					break
				}
				(*(*TVdbeOp)(unsafe.Pointer(aOp1))).Fp1 = iDb
				(*(*TVdbeOp)(unsafe.Pointer(aOp1 + 1*20))).Fp1 = iDb
				(*(*TVdbeOp)(unsafe.Pointer(aOp1 + 2*20))).Fp2 = iAddr + int32(4)
				(*(*TVdbeOp)(unsafe.Pointer(aOp1 + 4*20))).Fp1 = iDb
				(*(*TVdbeOp)(unsafe.Pointer(aOp1 + 4*20))).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)(unsafe.Pointer(bp + 40)) = 0
		if zRight == uintptr(0) || !(_sqlite3GetInt32(tls, zRight, bp+40) != 0) || *(*int32)(unsafe.Pointer(bp + 40)) <= 0 {
			*(*int32)(unsafe.Pointer(bp + 40)) = int32(0x7fffffff)
		}
		_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), *(*int32)(unsafe.Pointer(bp + 40)), 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) {
				v10 = 0
			} else {
				v10 = _sqlite3BtreeSetSpillSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, 0)
			}
			_returnSingleInt(tls, v, int64(v10))
		} else {
			*(*int32)(unsafe.Pointer(bp + 44)) = int32(1)
			if _sqlite3GetInt32(tls, zRight, bp+44) != 0 {
				_sqlite3BtreeSetSpillSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, *(*int32)(unsafe.Pointer(bp + 44)))
			}
			if _sqlite3GetBoolean(tls, zRight, libc.BoolUint8(*(*int32)(unsafe.Pointer(bp + 44)) != 0)) != 0 {
				*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(SQLITE_CacheSpill)
			} else {
				*(*Tu64)(unsafe.Pointer(db + 32)) &= ^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+48)
			if *(*Tsqlite3_int64)(unsafe.Pointer(bp + 48)) < 0 {
				*(*Tsqlite3_int64)(unsafe.Pointer(bp + 48)) = _sqlite3Config.FszMmap
			}
			if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) {
				(*Tsqlite3)(unsafe.Pointer(db)).FszMmap = *(*Tsqlite3_int64)(unsafe.Pointer(bp + 48))
			}
			ii3 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
			for {
				if !(ii3 >= 0) {
					break
				}
				if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii3)*16))).FpBt != 0 && (ii3 == iDb || (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
					_sqlite3BtreeSetMmapLimit(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii3)*16))).FpBt, *(*Tsqlite3_int64)(unsafe.Pointer(bp + 48)))
				}
				goto _11
			_11:
				;
				ii3--
			}
		}
		*(*Tsqlite3_int64)(unsafe.Pointer(bp + 48)) = int64(-int32(1))
		rc = Xsqlite3_file_control(tls, db, zDb, int32(SQLITE_FCNTL_MMAP_SIZE), bp+48)
		if rc == SQLITE_OK {
			_returnSingleInt(tls, v, *(*Tsqlite3_int64)(unsafe.Pointer(bp + 48)))
		} else {
			if rc != int32(SQLITE_NOTFOUND) {
				(*TParse)(unsafe.Pointer(pParse)).FnErr++
				(*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, int64((*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 *(*int8)(unsafe.Pointer(zRight)) != 0 {
				rc = _sqlite3OsAccess(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, zRight, int32(SQLITE_ACCESS_READWRITE), bp+56)
				if rc != SQLITE_OK || *(*int32)(unsafe.Pointer(bp + 56)) == 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19367, 0)
					Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
					goto pragma_out
				}
			}
			if libc.Bool(false) || libc.Bool(true) && int32((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) <= int32(1) || libc.Bool(libc.Bool(false) && int32((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) == int32(1)) {
				_invalidateTempStorage(tls, pParse)
			}
			Xsqlite3_free(tls, Xsqlite3_temp_directory)
			if *(*int8)(unsafe.Pointer(zRight)) != 0 {
				Xsqlite3_temp_directory = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+136, zRight))
			} else {
				Xsqlite3_temp_directory = uintptr(0)
			}
		}
		Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
		break
		/*
		 **   PRAGMA data_store_directory
		 **   PRAGMA data_store_directory = ""|"directory_name"
		 **
		 ** Return or set the local value of the data_store_directory flag.  Changing
		 ** the value sets a specific directory to be used for database files that
		 ** were specified with a relative pathname.  Setting to a null string reverts
		 ** to the default database directory, which for database files specified with
		 ** a relative path will probably be based on the current directory for the
		 ** process.  Database file specified with an absolute path are not impacted
		 ** by this setting, regardless of its value.
		 **
		 */
		fallthrough
	case int32(PragTyp_DATA_STORE_DIRECTORY):
		Xsqlite3_mutex_enter(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
		if !(zRight != 0) {
			_returnSingleText(tls, v, Xsqlite3_data_directory)
		} else {
			if *(*int8)(unsafe.Pointer(zRight)) != 0 {
				rc = _sqlite3OsAccess(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, zRight, int32(SQLITE_ACCESS_READWRITE), bp+60)
				if rc != SQLITE_OK || *(*int32)(unsafe.Pointer(bp + 60)) == 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19367, 0)
					Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
					goto pragma_out
				}
			}
			Xsqlite3_free(tls, Xsqlite3_data_directory)
			if *(*int8)(unsafe.Pointer(zRight)) != 0 {
				Xsqlite3_data_directory = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+136, zRight))
			} else {
				Xsqlite3_data_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(int32((*TDb)(unsafe.Pointer(pDb)).Fsafety_level)-int32(1)))
		} else {
			if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19392, 0)
			} else {
				if iDb != int32(1) {
					iLevel = (int32(_getSafetyLevel(tls, zRight, 0, uint8(1))) + int32(1)) & int32(PAGER_SYNCHRONOUS_MASK)
					if iLevel == 0 {
						iLevel = int32(1)
					}
					(*TDb)(unsafe.Pointer(pDb)).Fsafety_level = uint8(uint8(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 int32((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
				/* Foreign key support may not be enabled or disabled while not
				 ** in auto-commit mode.  */
				mask &= uint64(^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)(unsafe.Pointer(db + 32)) |= mask
				}
			} else {
				*(*Tu64)(unsafe.Pointer(db + 32)) &= ^mask
				if mask == uint64(SQLITE_DeferFKs) {
					(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = 0
				}
				if mask&uint64(SQLITE_WriteSchema) != uint64(0) && Xsqlite3_stricmp(tls, zRight, __ccgo_ts+19445) == 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 int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_NOINSERT) != 0 {
						if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg == uint64(0) {
							nHidden++
							goto _12
						}
						if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
							isHidden = int32(2) /* GENERATED ALWAYS AS ... VIRTUAL */
						} else {
							if int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_STORED) != 0 {
								isHidden = int32(3) /* GENERATED ALWAYS AS ... STORED */
							} else {
								isHidden = int32(1) /* HIDDEN */
							}
						}
					}
					if int32((*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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(k-int32(1))*2))) != i) {
									break
								}
								goto _13
							_13:
								;
								k++
							}
						}
					}
					pColExpr = _sqlite3ColumnExpr(tls, pTab, pCol)
					if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
						v14 = __ccgo_ts + 19451
					} else {
						v14 = __ccgo_ts + 19459
					}
					if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf>>0)) != 0 {
						v15 = int32(1)
					} else {
						v15 = 0
					}
					if isHidden >= int32(2) || pColExpr == uintptr(0) {
						v16 = uintptr(0)
					} else {
						v16 = *(*uintptr)(unsafe.Pointer(pColExpr + 8))
					}
					_sqlite3VdbeMultiLoad(tls, v, int32(1), v14, libc.VaList(bp+136, i-nHidden, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, _sqlite3ColumnType(tls, pCol, __ccgo_ts+1672), v15, v16, k, isHidden))
					goto _12
				_12:
					;
					i++
					pCol += 12
				}
			}
		}
		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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).FpSchema + 8
			initNCol = int32((*THash)(unsafe.Pointer(pHash)).Fcount)
			for {
				v18 = initNCol
				initNCol--
				if !(v18 != 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+19466, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab1)).FzName))
						if zSql != 0 {
							*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)
							Xsqlite3_prepare(tls, db, zSql, -int32(1), bp+64, uintptr(0))
							Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
							_sqlite3DbFree(tls, db, zSql)
						}
						if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
							_sqlite3ErrorMsg(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpParse, __ccgo_ts+1642, 0)
							(*TParse)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpParse)).Frc = int32(SQLITE_NOMEM)
						}
						pHash = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).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 int32((*TTable)(unsafe.Pointer(pTab2)).FeTabType) == int32(TABTYP_VIEW) {
					zType = __ccgo_ts + 12230
				} else {
					if int32((*TTable)(unsafe.Pointer(pTab2)).FeTabType) == int32(TABTYP_VTAB) {
						zType = __ccgo_ts + 14478
					} else {
						if (*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_Shadow) != 0 {
							zType = __ccgo_ts + 19482
						} else {
							zType = __ccgo_ts + 10492
						}
					}
				}
				_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19489, libc.VaList(bp+136, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).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++
		}
	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 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
					(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
				} else {
					/* PRAGMA index_info (legacy version) */
					mx = int32((*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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2))
					if int32(int32(cnum)) < 0 {
						v22 = uintptr(0)
					} else {
						v22 = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab3)).FaCol + uintptr(cnum)*12))).FzCnName
					}
					_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19496, libc.VaList(bp+136, i1, int32(int32(cnum)), v22))
					if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
						_sqlite3VdbeMultiLoad(tls, v, int32(4), __ccgo_ts+19501, libc.VaList(bp+136, int32(*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i1)))), *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*4)), libc.BoolInt32(i1 < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol))))
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), (*TParse)(unsafe.Pointer(pParse)).FnMem)
					goto _21
				_21:
					;
					i1++
				}
			}
		}
	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 + 19506,
						1: __ccgo_ts + 19508,
						2: __ccgo_ts + 17984,
					}
					_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19510, libc.VaList(bp+136, i2, (*TIndex)(unsafe.Pointer(pIdx1)).FzName, libc.BoolInt32(int32((*TIndex)(unsafe.Pointer(pIdx1)).FonError) != OE_None), azOrigin[int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 56))&0x3>>0))], libc.BoolInt32((*TIndex)(unsafe.Pointer(pIdx1)).FpPartIdxWhere != uintptr(0))))
					goto _23
				_23:
					;
					pIdx1 = (*TIndex)(unsafe.Pointer(pIdx1)).FpNext
					i2++
				}
			}
		}
	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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*16))).FpBt == uintptr(0) {
				goto _24
			}
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19516, libc.VaList(bp+136, i3, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*16))).FzDbSName, _sqlite3BtreeGetFilename(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*16))).FpBt)))
			goto _24
		_24:
			;
			i3++
		}
	case int32(PragTyp_COLLATION_LIST):
		i4 = 0
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(2)
		p = (*THash)(unsafe.Pointer(db + 448)).Ffirst
		for {
			if !(p != 0) {
				break
			}
			pColl = (*THashElem)(unsafe.Pointer(p)).Fdata
			v26 = i4
			i4++
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19520, libc.VaList(bp+136, v26, (*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)(unsafe.Pointer(uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)) + uintptr(i5)*4))
			for {
				if !(p1 != 0) {
					break
				}
				_pragmaFunclistLine(tls, v, p1, int32(1), showInternFunc)
				goto _28
			_28:
				;
				p1 = *(*uintptr)(unsafe.Pointer(p1 + 36))
			}
			goto _27
		_27:
			;
			i5++
		}
		j = (*THash)(unsafe.Pointer(db + 432)).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 + 404)).Ffirst
		for {
			if !(j1 != 0) {
				break
			}
			pMod = (*THashElem)(unsafe.Pointer(j1)).Fdata
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+9051, libc.VaList(bp+136, (*TModule)(unsafe.Pointer(pMod)).FzName))
			goto _30
		_30:
			;
			j1 = (*THashElem)(unsafe.Pointer(j1)).Fnext
		}
	case int32(PragTyp_PRAGMA_LIST):
		i6 = 0
		for {
			if !(i6 < int32(libc.Uint32FromInt64(1072)/libc.Uint32FromInt64(16))) {
				break
			}
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+9051, libc.VaList(bp+136, _aPragmaName[i6].FzName))
			goto _31
		_31:
			;
			i6++
		}
	case int32(PragTyp_FOREIGN_KEY_LIST):
		if zRight != 0 {
			pTab5 = _sqlite3FindTable(tls, db, zRight, zDb)
			if pTab5 != 0 && int32((*TTable)(unsafe.Pointer(pTab5)).FeTabType) == TABTYP_NORM {
				pFK = (*(*struct {
					FaddColOffset int32
					FpFKey        uintptr
					FpDfltList    uintptr
				})(unsafe.Pointer(pTab5 + 44))).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+19523, libc.VaList(bp+136, i7, j2, (*TFKey)(unsafe.Pointer(pFK)).FzTo, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab5)).FaCol + uintptr((*(*TsColMap)(unsafe.Pointer(pFK + 36 + uintptr(j2)*8))).FiFrom)*12))).FzCnName, (*(*TsColMap)(unsafe.Pointer(pFK + 36 + uintptr(j2)*8))).FzCol, _actionName(tls, *(*Tu8)(unsafe.Pointer(pFK + 25 + 1))), _actionName(tls, *(*Tu8)(unsafe.Pointer(pFK + 25))), __ccgo_ts+19532))
							goto _32
						_32:
							;
							j2++
						}
						i7++
						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)(unsafe.Pointer(pParse + 44)) += int32(4)
		v34 = pParse + 44
		*(*int32)(unsafe.Pointer(v34))++
		v33 = *(*int32)(unsafe.Pointer(v34))
		regRow = v33
		k2 = (*THash)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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) || !(int32((*TTable)(unsafe.Pointer(pTab6)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) || (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTab6 + 44))).FpFKey == uintptr(0) {
				continue
			}
			iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab6)).FpSchema)
			zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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 + 44))).FpFKey
			for {
				if !(pFK1 != 0) {
					break
				}
				pParent = _sqlite3FindTable(tls, db, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
				if pParent == uintptr(0) {
					goto _35
				}
				*(*uintptr)(unsafe.Pointer(bp + 68)) = 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+68, uintptr(0))
				if x1 == 0 {
					if *(*uintptr)(unsafe.Pointer(bp + 68)) == uintptr(0) {
						_sqlite3OpenTable(tls, pParse, i8, iDb, pParent, int32(OP_OpenRead))
					} else {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), i8, int32((*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 68)))).Ftnum), iDb)
						_sqlite3VdbeSetP4KeyInfo(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 68)))
					}
				} else {
					k2 = uintptr(0)
					break
				}
				goto _35
			_35:
				;
				i8++
				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 + 44))).FpFKey
			for {
				if !(pFK1 != 0) {
					break
				}
				pParent = _sqlite3FindTable(tls, db, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
				*(*uintptr)(unsafe.Pointer(bp + 68)) = uintptr(0)
				*(*uintptr)(unsafe.Pointer(bp + 72)) = uintptr(0)
				if pParent != 0 {
					x1 = _sqlite3FkLocateIndex(tls, pParse, pParent, pFK1, bp+68, bp+72)
				}
				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)(unsafe.Pointer(bp + 72)) != 0 {
						v38 = *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 72)) + uintptr(j3)*4))
					} else {
						v38 = (*(*TsColMap)(unsafe.Pointer(pFK1 + 36 + uintptr(j3)*8))).FiFrom
					}
					iCol = v38
					_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab6, 0, iCol, regRow+j3)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regRow+j3, addrOk)
					goto _37
				_37:
					;
					j3++
				}
				/* Generate code to query the parent index for a matching parent
				 ** key. If a match is found, jump to addrOk. */
				if *(*uintptr)(unsafe.Pointer(bp + 68)) != 0 {
					_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), regRow, (*TFKey)(unsafe.Pointer(pFK1)).FnCol, 0, _sqlite3IndexAffinityStr(tls, db, *(*uintptr)(unsafe.Pointer(bp + 68))), (*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+19537, libc.VaList(bp+136, (*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)(unsafe.Pointer(bp + 72)))
				goto _36
			_36:
				;
				i8++
				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, int32(_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(int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(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)(unsafe.Pointer(bp + 76)) = int32(SQLITE_INTEGRITY_CHECK_ERROR_MAX)
		if zRight != 0 {
			if _sqlite3GetInt32(tls, (*TToken)(unsafe.Pointer(pValue)).Fz, bp+76) != 0 {
				if *(*int32)(unsafe.Pointer(bp + 76)) <= 0 {
					*(*int32)(unsafe.Pointer(bp + 76)) = int32(SQLITE_INTEGRITY_CHECK_ERROR_MAX)
				}
			} else {
				if iDb >= 0 {
					v39 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
				} else {
					v39 = uintptr(0)
				}
				pObjTab = _sqlite3LocateTable(tls, pParse, uint32(0), zRight, v39)
			}
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), *(*int32)(unsafe.Pointer(bp + 76))-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)
			(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = uint8(0) /* 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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i9)*16))).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 pObjTab != 0 && pObjTab != pTab7 {
					goto _41
				}
				if (*TTable)(unsafe.Pointer(pTab7)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					cnt++
				}
				nIdx = 0
				pIdx3 = (*TTable)(unsafe.Pointer(pTab7)).FpIndex
				for {
					if !(pIdx3 != 0) {
						break
					}
					cnt++
					goto _42
				_42:
					;
					pIdx3 = (*TIndex)(unsafe.Pointer(pIdx3)).FpNext
					nIdx++
				}
				goto _41
			_41:
				;
				x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
			}
			if cnt == 0 {
				goto _40
			}
			if pObjTab != 0 {
				cnt++
			}
			aRoot = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(4)*uint32(cnt+libc.Int32FromInt32(1))))
			if aRoot == uintptr(0) {
				break
			}
			cnt = 0
			if pObjTab != 0 {
				cnt++
				v43 = cnt
				*(*int32)(unsafe.Pointer(aRoot + uintptr(v43)*4)) = 0
			}
			x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
			for {
				if !(x2 != 0) {
					break
				}
				pTab8 = (*THashElem)(unsafe.Pointer(x2)).Fdata
				if pObjTab != 0 && pObjTab != pTab8 {
					goto _44
				}
				if (*TTable)(unsafe.Pointer(pTab8)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					cnt++
					v45 = cnt
					*(*int32)(unsafe.Pointer(aRoot + uintptr(v45)*4)) = int32((*TTable)(unsafe.Pointer(pTab8)).Ftnum)
				}
				pIdx4 = (*TTable)(unsafe.Pointer(pTab8)).FpIndex
				for {
					if !(pIdx4 != 0) {
						break
					}
					cnt++
					v47 = cnt
					*(*int32)(unsafe.Pointer(aRoot + uintptr(v47)*4)) = int32((*TIndex)(unsafe.Pointer(pIdx4)).Ftnum)
					goto _46
				_46:
					;
					pIdx4 = (*TIndex)(unsafe.Pointer(pIdx4)).FpNext
				}
				goto _44
			_44:
				;
				x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
			}
			*(*int32)(unsafe.Pointer(aRoot)) = cnt
			/* Make sure sufficient number of registers have been allocated */
			_sqlite3TouchRegister(tls, pParse, 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(14))
			_sqlite3VdbeChangeP5(tls, v, uint16(uint8(uint8(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+19541, libc.VaList(bp+136, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i9)*16))).FzDbSName)), -int32(6))
			_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 {
				v48 = int32(1)
			} else {
				v48 = 0
			}
			cnt = v48
			_sqlite3VdbeLoadString(tls, v, int32(2), __ccgo_ts+19565)
			x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
			for {
				if !(x2 != 0) {
					break
				}
				iTab = 0
				pTab9 = (*THashElem)(unsafe.Pointer(x2)).Fdata
				if pObjTab != 0 && pObjTab != pTab9 {
					goto _49
				}
				if (*TTable)(unsafe.Pointer(pTab9)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					v50 = cnt
					cnt++
					iTab = v50
				} else {
					iTab = cnt
					pIdx5 = (*TTable)(unsafe.Pointer(pTab9)).FpIndex
					for {
						if !(pIdx5 != 0) {
							break
						}
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx5 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
							break
						}
						iTab++
						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++
					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 pObjTab != 0 && pObjTab != pTab10 {
					goto _53
				}
				if !(int32((*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, int32((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), int32(1), r2, r2+int32((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol)-int32(1))
				}
				_sqlite3OpenTableAndIndices(tls, pParse, pTab10, int32(OP_OpenRead), uint8(0), int32(1), uintptr(0), bp+80, bp+84)
				/* 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++
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), *(*int32)(unsafe.Pointer(bp + 80)), 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 int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
							mxCol++
						}
						goto _55
					_55:
						;
						j4++
					}
					if mxCol == int32((*TTable)(unsafe.Pointer(pTab10)).FiPKey) {
						mxCol--
					}
				} 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 = int32((*TIndex)(unsafe.Pointer(_sqlite3PrimaryKeyIndex(tls, pTab10))).FnColumn) - int32(1)
				}
				if mxCol >= 0 {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), *(*int32)(unsafe.Pointer(bp + 80)), mxCol, int32(3))
					_sqlite3VdbeTypeofColumn(tls, v, int32(3))
				}
				if !(isQuick != 0) {
					if pPk1 != 0 {
						a1 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxGT), *(*int32)(unsafe.Pointer(bp + 80)), 0, r2, int32((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
						_sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), r2)
						zErr = _sqlite3MPrintf(tls, db, __ccgo_ts+19594, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr, -int32(6))
						_integrityCheckResultRow(tls, v)
						_sqlite3VdbeJumpHere(tls, v, a1)
						_sqlite3VdbeJumpHere(tls, v, a1+int32(1))
						j4 = 0
						for {
							if !(j4 < int32((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol)) {
								break
							}
							_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pPk1, *(*int32)(unsafe.Pointer(bp + 80)), j4, r2+j4)
							goto _56
						_56:
							;
							j4++
						}
					}
				}
				/* 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)*12 /* 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 + 4))&0xf0>>4)) > int32(COLTYPE_ANY))
					} else {
						doTypeCheck = libc.BoolInt32(int32((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) > int32(SQLITE_AFF_BLOB))
					}
					if int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf>>0)) == 0 && !(doTypeCheck != 0) {
						goto _57
					}
					/* Compute the operands that will be needed for OP_IsType */
					p4 = int32(SQLITE_NULL)
					if int32((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
						_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab10, *(*int32)(unsafe.Pointer(bp + 80)), j4, int32(3))
						p11 = -int32(1)
						p3 = int32(3)
					} else {
						if (*TColumn)(unsafe.Pointer(pCol1)).FiDflt != 0 {
							*(*uintptr)(unsafe.Pointer(bp + 88)) = uintptr(0)
							_sqlite3ValueFromExpr(tls, db, _sqlite3ColumnExpr(tls, pTab10, pCol1), (*Tsqlite3)(unsafe.Pointer(db)).Fenc, uint8((*TColumn)(unsafe.Pointer(pCol1)).Faffinity), bp+88)
							if *(*uintptr)(unsafe.Pointer(bp + 88)) != 0 {
								p4 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 88)))
								_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 88)))
							}
						}
						p11 = *(*int32)(unsafe.Pointer(bp + 80))
						if !((*TTable)(unsafe.Pointer(pTab10)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
							p3 = int32(_sqlite3TableColumnToIndex(tls, _sqlite3PrimaryKeyIndex(tls, pTab10), int16(int16(j4))))
						} else {
							p3 = int32(_sqlite3TableColumnToStorage(tls, pTab10, int16(int16(j4))))
						}
					}
					labelError = _sqlite3VdbeMakeLabel(tls, pParse)
					labelOk = _sqlite3VdbeMakeLabel(tls, pParse)
					if int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf>>0)) != 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+19630, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName, (*TColumn)(unsafe.Pointer(pCol1)).FzCnName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(6))
						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 + 4))&0xf0>>4))-int32(1)]))
						zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19650, libc.VaList(bp+136, _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf0>>4))-int32(1)], (*TTable)(unsafe.Pointer(pTab10)).FzName, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FzCnName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(6))
					} else {
						if !(bStrict != 0) && int32((*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+19672, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FzCnName))
							_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(6))
						} else {
							if !(bStrict != 0) && int32((*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)(unsafe.Pointer(bp + 80)), j4, int32(3))
								}
								_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), int32(3), int32(1), 0, __ccgo_ts+19695, -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+19697, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FzCnName))
								_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(6))
							}
						}
					}
					_sqlite3VdbeResolveLabel(tls, v, labelError)
					_integrityCheckResultRow(tls, v)
					_sqlite3VdbeResolveLabel(tls, v, labelOk)
					goto _57
				_57:
					;
					j4++
				}
				/* 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 int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
						addrCkFault = _sqlite3VdbeMakeLabel(tls, pParse)
						addrCkOk = _sqlite3VdbeMakeLabel(tls, pParse)
						(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = *(*int32)(unsafe.Pointer(bp + 80)) + 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)*20))).FpExpr, addrCkFault, 0)
							goto _58
						_58:
							;
							k3--
						}
						_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+19717, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr2, -int32(6))
						_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)(unsafe.Pointer(bp + 80)), 0, 0, bp+92, 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 */
						jmp21 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), *(*int32)(unsafe.Pointer(bp + 84))+j4, ckUniq, r1, int32((*TIndex)(unsafe.Pointer(pIdx6)).FnColumn))
						_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19747)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
						_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19752)
						_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)
						_sqlite3VdbeJumpHere(tls, v, jmp21)
						/* 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)(unsafe.Pointer(bp + 84))+j4, int32(3))
							jmp7 = _sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), int32(3), 0, r1+int32((*TIndex)(unsafe.Pointer(pIdx6)).FnColumn)-int32(1))
							_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19773)
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
							_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19809)
							_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 < int32((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol)) {
								break
							}
							if *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx6)).FazColl + uintptr(kk)*4)) == uintptr(unsafe.Pointer(&_sqlite3StrBINARY)) {
								goto _60
							}
							if label6 == 0 {
								label6 = _sqlite3VdbeMakeLabel(tls, pParse)
							}
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), *(*int32)(unsafe.Pointer(bp + 84))+j4, kk, int32(3))
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Ne), int32(3), label6, r1+kk)
							goto _60
						_60:
							;
							kk++
						}
						if label6 != 0 {
							jmp6 = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
							_sqlite3VdbeResolveLabel(tls, v, label6)
							_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19747)
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
							_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19820)
							_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 int32((*TIndex)(unsafe.Pointer(pIdx6)).FonError) != OE_None {
							uniqOk = _sqlite3VdbeMakeLabel(tls, pParse)
							kk = 0
							for {
								if !(kk < int32((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol)) {
									break
								}
								iCol1 = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx6)).FaiColumn + uintptr(kk)*2)))
								if iCol1 >= 0 && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(iCol1)*12 + 4))&0xf>>0)) != 0 {
									goto _61
								}
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), r1+kk, uniqOk)
								goto _61
							_61:
								;
								kk++
							}
							jmp61 = _sqlite3VdbeAddOp1(tls, v, int32(OP_Next), *(*int32)(unsafe.Pointer(bp + 84))+j4)
							_sqlite3VdbeGoto(tls, v, uniqOk)
							_sqlite3VdbeJumpHere(tls, v, jmp61)
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxGT), *(*int32)(unsafe.Pointer(bp + 84))+j4, uniqOk, r1, int32((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol))
							_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19847)
							_sqlite3VdbeGoto(tls, v, jmp5)
							_sqlite3VdbeResolveLabel(tls, v, uniqOk)
						}
						_sqlite3VdbeJumpHere(tls, v, jmp4)
						_sqlite3ResolvePartIdxLabel(tls, pParse, *(*int32)(unsafe.Pointer(bp + 92)))
						goto _59
					_59:
						;
						pIdx6 = (*TIndex)(unsafe.Pointer(pIdx6)).FpNext
						j4++
					}
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), *(*int32)(unsafe.Pointer(bp + 80)), loopTop)
				_sqlite3VdbeJumpHere(tls, v, loopTop-int32(1))
				if pPk1 != 0 {
					_sqlite3ReleaseTempRange(tls, pParse, r2, int32((*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 pObjTab != 0 && pObjTab != pTab11 {
					goto _62
				}
				if int32((*TTable)(unsafe.Pointer(pTab11)).FeTabType) == TABTYP_NORM {
					goto _62
				}
				if !(int32((*TTable)(unsafe.Pointer(pTab11)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
					goto _62
				}
				if int32((*TTable)(unsafe.Pointer(pTab11)).FnCol) <= 0 {
					zMod = *(*uintptr)(unsafe.Pointer((*(*struct {
						FnArg  int32
						FazArg uintptr
						Fp     uintptr
					})(unsafe.Pointer(pTab11 + 44))).FazArg))
					if _sqlite3HashFind(tls, db+404, zMod) == uintptr(0) {
						goto _62
					}
				}
				_sqlite3ViewGetColumnNames(tls, pParse, pTab11)
				if (*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(pTab11 + 44))).Fp == uintptr(0) {
					goto _62
				}
				pVTab = (*TVTable)(unsafe.Pointer((*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(pTab11 + 44))).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++
				_sqlite3VdbeAppendP4(tls, v, pTab11, -int32(16))
				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++
		}
		aOp2 = _sqlite3VdbeAddOpList(tls, v, int32(libc.Uint32FromInt64(28)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_endCode)), _iLn21)
		if aOp2 != 0 {
			(*(*TVdbeOp)(unsafe.Pointer(aOp2))).Fp2 = int32(1) - *(*int32)(unsafe.Pointer(bp + 76))
			(*(*TVdbeOp)(unsafe.Pointer(aOp2 + 2*20))).Fp4type = int8(-libc.Int32FromInt32(1))
			*(*uintptr)(unsafe.Pointer(aOp2 + 2*20 + 16)) = __ccgo_ts + 19874
			(*(*TVdbeOp)(unsafe.Pointer(aOp2 + 5*20))).Fp4type = int8(-libc.Int32FromInt32(1))
			*(*uintptr)(unsafe.Pointer(aOp2 + 5*20 + 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 {
							v64 = int32((*struct {
								FzName uintptr
								Fenc   Tu8
							})(unsafe.Pointer(pEnc)).Fenc)
						} else {
							v64 = int32(SQLITE_UTF16LE)
						}
						enc = uint8(v64)
						(*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fenc = enc
						_sqlite3SetTextEncoding(tls, db, enc)
						break
					}
					goto _63
				_63:
					;
					pEnc += 8
				}
				if !((*struct {
					FzName uintptr
					Fenc   Tu8
				})(unsafe.Pointer(pEnc)).FzName != 0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19935, libc.VaList(bp+136, 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 = int32((*TPragmaName)(unsafe.Pointer(pPragma)).FiArg) /* Which cookie to read or write */
		_sqlite3VdbeUsesBtree(tls, v, iDb)
		if zRight != 0 && int32((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_ReadOnly) == 0 {
			aOp3 = _sqlite3VdbeAddOpList(tls, v, int32(libc.Uint32FromInt64(8)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_setCookie)), 0)
			if 0 != 0 {
				break
			}
			(*(*TVdbeOp)(unsafe.Pointer(aOp3))).Fp1 = iDb
			(*(*TVdbeOp)(unsafe.Pointer(aOp3 + 1*20))).Fp1 = iDb
			(*(*TVdbeOp)(unsafe.Pointer(aOp3 + 1*20))).Fp2 = iCookie
			(*(*TVdbeOp)(unsafe.Pointer(aOp3 + 1*20))).Fp3 = _sqlite3Atoi(tls, zRight)
			(*(*TVdbeOp)(unsafe.Pointer(aOp3 + 1*20))).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)(unsafe.Pointer(aOp3 + 1*20))).Fopcode = uint8(OP_Noop)
			}
		} else {
			aOp4 = _sqlite3VdbeAddOpList(tls, v, int32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_readCookie)), 0)
			if 0 != 0 {
				break
			}
			(*(*TVdbeOp)(unsafe.Pointer(aOp4))).Fp1 = iDb
			(*(*TVdbeOp)(unsafe.Pointer(aOp4 + 1*20))).Fp1 = iDb
			(*(*TVdbeOp)(unsafe.Pointer(aOp4 + 1*20))).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 {
			v66 = i10
			i10++
			v65 = Xsqlite3_compileoption_get(tls, v66)
			zOpt = v65
			if !(v65 != 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 {
			v67 = iDb
		} else {
			v67 = libc.Int32FromInt32(SQLITE_MAX_ATTACHED) + libc.Int32FromInt32(2)
		}
		iBt = v67
		eMode2 = SQLITE_CHECKPOINT_PASSIVE
		if zRight != 0 {
			if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19160) == 0 {
				eMode2 = int32(SQLITE_CHECKPOINT_FULL)
			} else {
				if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19960) == 0 {
					eMode2 = int32(SQLITE_CHECKPOINT_RESTART)
				} else {
					if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19313) == 0 {
						eMode2 = int32(SQLITE_CHECKPOINT_TRUNCATE)
					}
				}
			}
		}
		(*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) {
			v68 = int32((*Tsqlite3)(unsafe.Pointer(db)).FpWalArg)
		} else {
			v68 = 0
		}
		_returnSingleInt(tls, v, int64(v68))
		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 = uint32(_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)
			}
		}
		v70 = pParse + 40
		v69 = *(*int32)(unsafe.Pointer(v70))
		*(*int32)(unsafe.Pointer(v70))++
		iTabCur = v69
		if zDb != 0 {
			v72 = iDb
		} else {
			v72 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
		}
		iDbLast = v72
		for {
			if !(iDb <= iDbLast) {
				break
			}
			if iDb == int32(1) {
				goto _71
			}
			_sqlite3CodeVerifySchema(tls, pParse, iDb)
			pSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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 !(int32((*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+7898, 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++
					if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx7 + 56))&0x80>>7)) != 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(int32(szThreshold)) < 0 {
							/* Do analysis if unanalyzed indexes exists */
						} else {
							/* Otherwise, we can skip this table */
							goto _73
						}
					}
				}
				nCheck++
				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 += 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(int32(szThreshold)) >= 0 {
					iRange = int16(33) /* 10x size change */
					if int32(int32(szThreshold)) >= int32(int32(iRange)) {
						v75 = int32(int32(szThreshold)) - int32(int32(iRange))
					} else {
						v75 = -int32(1)
					}
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IfSizeBetween), iTabCur, int32(uint32(_sqlite3VdbeCurrentAddr(tls, v)+int32(2))+opMask&uint32(1)), v75, int32(int32(szThreshold))+int32(int32(iRange)))
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iTabCur, int32(uint32(_sqlite3VdbeCurrentAddr(tls, v)+int32(2))+opMask&uint32(1)))
				}
				zSubSql = _sqlite3MPrintf(tls, db, __ccgo_ts+19968, libc.VaList(bp+136, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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(6))
					_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), r11, int32(1))
				} else {
					if nLimit != 0 {
						v76 = int32(0x02)
					} else {
						v76 = 00
					}
					_sqlite3VdbeAddOp4(tls, v, int32(OP_SqlExec), v76, nLimit, 0, zSubSql, -int32(6))
				}
				goto _73
			_73:
				;
				k4 = (*THashElem)(unsafe.Pointer(k4)).Fnext
			}
			goto _71
		_71:
			;
			iDb++
		}
		_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 int32((*(*TVdbeOp)(unsafe.Pointer(aOp5 + uintptr(iAddr1)*20))).Fopcode) == int32(OP_SqlExec) {
					(*(*TVdbeOp)(unsafe.Pointer(aOp5 + uintptr(iAddr1)*20))).Fp2 = nLimit
				}
				goto _77
			_77:
				;
				iAddr1++
			}
		}
		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+96) == SQLITE_OK {
			Xsqlite3_soft_heap_limit64(tls, *(*Tsqlite3_int64)(unsafe.Pointer(bp + 96)))
		}
		_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+104) == SQLITE_OK {
			iPrior = Xsqlite3_hard_heap_limit64(tls, int64(-int32(1)))
			if *(*Tsqlite3_int64)(unsafe.Pointer(bp + 104)) > 0 && (iPrior == 0 || iPrior > *(*Tsqlite3_int64)(unsafe.Pointer(bp + 104))) {
				Xsqlite3_hard_heap_limit64(tls, *(*Tsqlite3_int64)(unsafe.Pointer(bp + 104)))
			}
		}
		_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+112) == SQLITE_OK && *(*Tsqlite3_int64)(unsafe.Pointer(bp + 112)) >= 0 {
			Xsqlite3_limit(tls, db, int32(SQLITE_LIMIT_WORKER_THREADS), int32(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 112))&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+120) == SQLITE_OK && *(*Tsqlite3_int64)(unsafe.Pointer(bp + 120)) >= 0 {
			(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = int32(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 120)) & 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 int32((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns1) != 0 && zRight != 0 {
	}
	goto pragma_out
pragma_out:
	;
	_sqlite3DbFree(tls, db, zLeft)
	_sqlite3DbFree(tls, db, zRight)
}

var _iLn3 int32

var _getCacheSize = [9]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_Transaction),
	},
	1: {
		Fopcode: uint8(OP_ReadCookie),
		Fp2:     int8(1),
		Fp3:     int8(BTREE_DEFAULT_CACHE_SIZE),
	},
	2: {
		Fopcode: uint8(OP_IfPos),
		Fp1:     int8(1),
		Fp2:     int8(8),
	},
	3: {
		Fopcode: uint8(OP_Integer),
		Fp2:     int8(2),
	},
	4: {
		Fopcode: uint8(OP_Subtract),
		Fp1:     int8(1),
		Fp2:     int8(2),
		Fp3:     int8(1),
	},
	5: {
		Fopcode: uint8(OP_IfPos),
		Fp1:     int8(1),
		Fp2:     int8(8),
	},
	6: {
		Fopcode: uint8(OP_Integer),
		Fp2:     int8(1),
	},
	7: {
		Fopcode: uint8(OP_Noop),
	},
	8: {
		Fopcode: uint8(OP_ResultRow),
		Fp1:     int8(1),
		Fp2:     int8(1),
	},
}

/* When setting the auto_vacuum mode to either "full" or
 ** "incremental", write the value of meta[6] in the database
 ** file. Before writing to meta[6], check that meta[3] indicates
 ** that this really is an auto-vacuum capable database.
 */
var _iLn11 int32

var _setMeta6 = [5]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_Transaction),
		Fp2:     int8(1),
	},
	1: {
		Fopcode: uint8(OP_ReadCookie),
		Fp2:     int8(1),
		Fp3:     int8(BTREE_LARGEST_ROOT_PAGE),
	},
	2: {
		Fopcode: uint8(OP_If),
		Fp1:     int8(1),
	},
	3: {
		Fopcode: uint8(OP_Halt),
		Fp2:     int8(OE_Abort),
	},
	4: {
		Fopcode: uint8(OP_SetCookie),
		Fp2:     int8(BTREE_INCR_VACUUM),
	},
}

/* (2) Datatype must be exact for non-ANY columns in STRICT tables*/
var _aStdTypeMask = [6]uint8{
	0: uint8(0x1f),
	1: uint8(0x18),
	2: uint8(0x11),
	3: uint8(0x11),
	4: uint8(0x13),
	5: uint8(0x14),
}

var _iLn21 int32

var _endCode = [7]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_AddImm),
		Fp1:     int8(1),
	},
	1: {
		Fopcode: uint8(OP_IfNotZero),
		Fp1:     int8(1),
		Fp2:     int8(4),
	},
	2: {
		Fopcode: uint8(OP_String8),
		Fp2:     int8(3),
	},
	3: {
		Fopcode: uint8(OP_ResultRow),
		Fp1:     int8(3),
		Fp2:     int8(1),
	},
	4: {
		Fopcode: uint8(OP_Halt),
	},
	5: {
		Fopcode: uint8(OP_String8),
		Fp2:     int8(3),
	},
	6: {
		Fopcode: uint8(OP_Goto),
		Fp2:     int8(3),
	},
}

var _encnames1 = [9]struct {
	FzName uintptr
	Fenc   Tu8
}{
	0: {
		FzName: __ccgo_ts + 19877,
		Fenc:   uint8(SQLITE_UTF8),
	},
	1: {
		FzName: __ccgo_ts + 19882,
		Fenc:   uint8(SQLITE_UTF8),
	},
	2: {
		FzName: __ccgo_ts + 19888,
		Fenc:   uint8(SQLITE_UTF16LE),
	},
	3: {
		FzName: __ccgo_ts + 19897,
		Fenc:   uint8(SQLITE_UTF16BE),
	},
	4: {
		FzName: __ccgo_ts + 19906,
		Fenc:   uint8(SQLITE_UTF16LE),
	},
	5: {
		FzName: __ccgo_ts + 19914,
		Fenc:   uint8(SQLITE_UTF16BE),
	},
	6: {
		FzName: __ccgo_ts + 19922,
	},
	7: {
		FzName: __ccgo_ts + 19929,
	},
	8: {},
}

/* Write the specified cookie value */
var _setCookie = [2]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_Transaction),
		Fp2:     int8(1),
	},
	1: {
		Fopcode: uint8(OP_SetCookie),
	},
}

/* Read the specified cookie value */
var _readCookie = [3]TVdbeOpList{
	0: {
		Fopcode: uint8(OP_Transaction),
	},
	1: {
		Fopcode: uint8(OP_ReadCookie),
		Fp2:     int8(1),
	},
	2: {
		Fopcode: uint8(OP_ResultRow),
		Fp1:     int8(1),
		Fp2:     int8(1),
	},
}

// C documentation
//
//	/*****************************************************************************
//	** Implementation of an eponymous virtual table that runs a pragma.
//	**
//	*/
type TPragmaVtab = struct {
	Fbase    Tsqlite3_vtab
	Fdb      uintptr
	FpName   uintptr
	FnHidden Tu8
	FiHidden Tu8
}

type PragmaVtab = TPragmaVtab

type TPragmaVtabCursor = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FpPragma      uintptr
	FiRowid       Tsqlite_int64
	FazArg        [2]uintptr
}

type PragmaVtabCursor = TPragmaVtabCursor

type TPragmaVtab1 = struct {
	Fbase    Tsqlite3_vtab
	Fdb      uintptr
	FpName   uintptr
	FnHidden Tu8
	FiHidden Tu8
}

type PragmaVtab1 = TPragmaVtab1

type TPragmaVtabCursor1 = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FpPragma      uintptr
	FiRowid       Tsqlite_int64
	FazArg        [2]uintptr
}

type PragmaVtabCursor1 = TPragmaVtabCursor1

// C documentation
//
//	/*
//	** Pragma virtual table module xConnect method.
//	*/
func _pragmaVtabConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(256)
	defer tls.Free(256)
	var cSep int8
	var i, j, rc int32
	var pPragma, pTab uintptr
	var _ /* acc at bp+0 */ TStrAccum
	var _ /* zBuf at bp+24 */ [200]int8
	_, _, _, _, _, _ = cSep, i, j, pPragma, pTab, rc
	pPragma = pAux
	pTab = uintptr(0)
	cSep = int8('(')
	_ = argc
	_ = argv
	_sqlite3StrAccumInit(tls, bp, uintptr(0), bp+24, int32(200), 0)
	Xsqlite3_str_appendall(tls, bp, __ccgo_ts+19986)
	i = 0
	j = int32((*TPragmaName)(unsafe.Pointer(pPragma)).FiPragCName)
	for {
		if !(i < int32((*TPragmaName)(unsafe.Pointer(pPragma)).FnPragCName)) {
			break
		}
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+20001, libc.VaList(bp+232, int32(int32(cSep)), _pragCName[j]))
		cSep = int8(',')
		goto _1
	_1:
		;
		i++
		j++
	}
	if i == 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+20008, libc.VaList(bp+232, (*TPragmaName)(unsafe.Pointer(pPragma)).FzName))
		i++
	}
	j = 0
	if int32((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_Result1) != 0 {
		Xsqlite3_str_appendall(tls, bp, __ccgo_ts+20014)
		j++
	}
	if int32((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&(libc.Int32FromInt32(PragFlg_SchemaOpt)|libc.Int32FromInt32(PragFlg_SchemaReq)) != 0 {
		Xsqlite3_str_appendall(tls, bp, __ccgo_ts+20026)
		j++
	}
	Xsqlite3_str_append(tls, bp, __ccgo_ts+6479, int32(1))
	_sqlite3StrAccumFinish(tls, bp)
	rc = Xsqlite3_declare_vtab(tls, db, bp+24)
	if rc == SQLITE_OK {
		pTab = Xsqlite3_malloc(tls, int32(24))
		if pTab == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, pTab, 0, uint32(24))
			(*TPragmaVtab)(unsafe.Pointer(pTab)).FpName = pPragma
			(*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb = db
			(*TPragmaVtab)(unsafe.Pointer(pTab)).FiHidden = uint8(uint8(i))
			(*TPragmaVtab)(unsafe.Pointer(pTab)).FnHidden = uint8(uint8(j))
		}
	} else {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+232, Xsqlite3_errmsg(tls, db)))
	}
	*(*uintptr)(unsafe.Pointer(ppVtab)) = pTab
	return rc
}

// C documentation
//
//	/*
//	** Pragma virtual table module xDisconnect method.
//	*/
func _pragmaVtabDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pTab uintptr
	_ = pTab
	pTab = pVtab
	Xsqlite3_free(tls, pTab)
	return SQLITE_OK
}

// C documentation
//
//	/* Figure out the best index to use to search a pragma virtual table.
//	**
//	** There are not really any index choices.  But we want to encourage the
//	** query planner to give == constraints on as many hidden parameters as
//	** possible, and especially on the first hidden parameter.  So return a
//	** high cost if hidden parameters are unconstrained.
//	*/
func _pragmaVtabBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
	var i, j int32
	var pConstraint, pTab uintptr
	var seen [2]int32
	_, _, _, _, _ = i, j, pConstraint, pTab, seen
	pTab = tab
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(1)
	if int32((*TPragmaVtab)(unsafe.Pointer(pTab)).FnHidden) == 0 {
		return SQLITE_OK
	}
	pConstraint = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint
	seen[0] = 0
	seen[int32(1)] = 0
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn < int32((*TPragmaVtab)(unsafe.Pointer(pTab)).FiHidden) {
			goto _1
		}
		if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fop) != int32(SQLITE_INDEX_CONSTRAINT_EQ) {
			goto _1
		}
		if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fusable) == 0 {
			return int32(SQLITE_CONSTRAINT)
		}
		j = (*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn - int32((*TPragmaVtab)(unsafe.Pointer(pTab)).FiHidden)
		seen[j] = i + int32(1)
		goto _1
	_1:
		;
		i++
		pConstraint += 12
	}
	if seen[0] == 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(2147483647)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(2147483647)
		return SQLITE_OK
	}
	j = seen[0] - int32(1)
	(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8))).FargvIndex = int32(1)
	(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8))).Fomit = uint8(1)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(20)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(20)
	if seen[int32(1)] != 0 {
		j = seen[int32(1)] - int32(1)
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8))).FargvIndex = int32(2)
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8))).Fomit = uint8(1)
	}
	return SQLITE_OK
}

// C documentation
//
//	/* Create a new cursor for the pragma virtual table */
func _pragmaVtabOpen(tls *libc.TLS, pVtab uintptr, ppCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = Xsqlite3_malloc(tls, int32(24))
	if pCsr == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCsr, 0, uint32(24))
	(*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVtab
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCsr
	return SQLITE_OK
}

// C documentation
//
//	/* Clear all content from pragma virtual table cursor. */
func _pragmaVtabCursorClear(tls *libc.TLS, pCsr uintptr) {
	var i int32
	_ = i
	Xsqlite3_finalize(tls, (*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma)
	(*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma = uintptr(0)
	(*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FiRowid = 0
	i = 0
	for {
		if !(i < int32(libc.Uint32FromInt64(8)/libc.Uint32FromInt64(4))) {
			break
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(pCsr + 16 + uintptr(i)*4)))
		*(*uintptr)(unsafe.Pointer(pCsr + 16 + uintptr(i)*4)) = uintptr(0)
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/* Close a pragma virtual table cursor */
func _pragmaVtabClose(tls *libc.TLS, cur uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = cur
	_pragmaVtabCursorClear(tls, pCsr)
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

// C documentation
//
//	/* Advance the pragma virtual table cursor to the next row */
func _pragmaVtabNext(tls *libc.TLS, pVtabCursor uintptr) (r int32) {
	var pCsr uintptr
	var rc int32
	_, _ = pCsr, rc
	pCsr = pVtabCursor
	rc = SQLITE_OK
	/* Increment the xRowid value */
	(*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FiRowid++
	if int32(SQLITE_ROW) != Xsqlite3_step(tls, (*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma) {
		rc = Xsqlite3_finalize(tls, (*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma)
		(*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma = uintptr(0)
		_pragmaVtabCursorClear(tls, pCsr)
	}
	return rc
}

// C documentation
//
//	/*
//	** Pragma virtual table module xFilter method.
//	*/
func _pragmaVtabFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, j, rc, v1 int32
	var pCsr, pTab, zSql, zText uintptr
	var _ /* acc at bp+0 */ TStrAccum
	_, _, _, _, _, _, _, _ = i, j, pCsr, pTab, rc, zSql, zText, v1
	pCsr = pVtabCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	_ = idxNum
	_ = idxStr
	_pragmaVtabCursorClear(tls, pCsr)
	if int32((*TPragmaName)(unsafe.Pointer((*TPragmaVtab)(unsafe.Pointer(pTab)).FpName)).FmPragFlg)&int32(PragFlg_Result1) != 0 {
		v1 = 0
	} else {
		v1 = int32(1)
	}
	j = v1
	i = 0
	for {
		if !(i < argc) {
			break
		}
		zText = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		if zText != 0 {
			*(*uintptr)(unsafe.Pointer(pCsr + 16 + uintptr(j)*4)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+32, zText))
			if *(*uintptr)(unsafe.Pointer(pCsr + 16 + uintptr(j)*4)) == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
		}
		goto _2
	_2:
		;
		i++
		j++
	}
	_sqlite3StrAccumInit(tls, bp, uintptr(0), uintptr(0), 0, *(*int32)(unsafe.Pointer((*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb + 120 + 1*4)))
	Xsqlite3_str_appendall(tls, bp, __ccgo_ts+20041)
	if *(*uintptr)(unsafe.Pointer(pCsr + 16 + 1*4)) != 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+20049, libc.VaList(bp+32, *(*uintptr)(unsafe.Pointer(pCsr + 16 + 1*4))))
	}
	Xsqlite3_str_appendall(tls, bp, (*TPragmaName)(unsafe.Pointer((*TPragmaVtab)(unsafe.Pointer(pTab)).FpName)).FzName)
	if *(*uintptr)(unsafe.Pointer(pCsr + 16)) != 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+20053, libc.VaList(bp+32, *(*uintptr)(unsafe.Pointer(pCsr + 16))))
	}
	zSql = _sqlite3StrAccumFinish(tls, bp)
	if zSql == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	rc = Xsqlite3_prepare_v2(tls, (*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb, zSql, -int32(1), pCsr+4, uintptr(0))
	Xsqlite3_free(tls, zSql)
	if rc != SQLITE_OK {
		(*TPragmaVtab)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+32, Xsqlite3_errmsg(tls, (*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb)))
		return rc
	}
	return _pragmaVtabNext(tls, pVtabCursor)
}

// C documentation
//
//	/*
//	** Pragma virtual table module xEof method.
//	*/
func _pragmaVtabEof(tls *libc.TLS, pVtabCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pVtabCursor
	return libc.BoolInt32((*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma == uintptr(0))
}

// C documentation
//
//	/* The xColumn method simply returns the corresponding column from
//	** the PRAGMA.
//	*/
func _pragmaVtabColumn(tls *libc.TLS, pVtabCursor uintptr, ctx uintptr, i int32) (r int32) {
	var pCsr, pTab uintptr
	_, _ = pCsr, pTab
	pCsr = pVtabCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	if i < int32((*TPragmaVtab)(unsafe.Pointer(pTab)).FiHidden) {
		Xsqlite3_result_value(tls, ctx, Xsqlite3_column_value(tls, (*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma, i))
	} else {
		Xsqlite3_result_text(tls, ctx, *(*uintptr)(unsafe.Pointer(pCsr + 16 + uintptr(i-int32((*TPragmaVtab)(unsafe.Pointer(pTab)).FiHidden))*4)), -int32(1), uintptr(-libc.Int32FromInt32(1)))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Pragma virtual table module xRowid method.
//	*/
func _pragmaVtabRowid(tls *libc.TLS, pVtabCursor uintptr, p uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pVtabCursor
	*(*Tsqlite_int64)(unsafe.Pointer(p)) = (*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).FiRowid
	return SQLITE_OK
}

// C documentation
//
//	/* The pragma virtual table object */
var _pragmaVtabModule = Tsqlite3_module{}

func init() {
	p := unsafe.Pointer(&_pragmaVtabModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_pragmaVtabConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_pragmaVtabBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_pragmaVtabDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_pragmaVtabOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_pragmaVtabClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_pragmaVtabFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_pragmaVtabNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_pragmaVtabEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_pragmaVtabColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_pragmaVtabRowid)
}

// C documentation
//
//	/*
//	** Check to see if zTabName is really the name of a pragma.  If it is,
//	** then register an eponymous virtual table for that pragma and return
//	** a pointer to the Module object for the new virtual table.
//	*/
func _sqlite3PragmaVtabRegister(tls *libc.TLS, db uintptr, zName uintptr) (r uintptr) {
	var pName uintptr
	_ = pName
	pName = _pragmaLocate(tls, zName+uintptr(7))
	if pName == uintptr(0) {
		return uintptr(0)
	}
	if int32((*TPragmaName)(unsafe.Pointer(pName)).FmPragFlg)&(libc.Int32FromInt32(PragFlg_Result0)|libc.Int32FromInt32(PragFlg_Result1)) == 0 {
		return uintptr(0)
	}
	return _sqlite3VtabCreateModule(tls, db, zName, uintptr(unsafe.Pointer(&_pragmaVtabModule)), pName, uintptr(0))
}

/************** End of pragma.c **********************************************/
/************** Begin file prepare.c *****************************************/
/*
** 2005 May 25
**
** 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 implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Fill the InitData structure with an error message that indicates
//	** that the database is corrupt.
//	*/
func _corruptSchema(tls *libc.TLS, pData uintptr, azObj uintptr, zExtra uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, z, zObj, v1 uintptr
	_, _, _, _ = db, z, zObj, v1
	db = (*TInitData)(unsafe.Pointer(pData)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*TInitData)(unsafe.Pointer(pData)).Frc = int32(SQLITE_NOMEM)
	} else {
		if *(*uintptr)(unsafe.Pointer((*TInitData)(unsafe.Pointer(pData)).FpzErrMsg)) != uintptr(0) {
			/* A error message has already been generated.  Do not overwrite it */
		} else {
			if (*TInitData)(unsafe.Pointer(pData)).FmInitFlags&uint32(libc.Int32FromInt32(INITFLAG_AlterMask)) != 0 {
				*(*uintptr)(unsafe.Pointer((*TInitData)(unsafe.Pointer(pData)).FpzErrMsg)) = _sqlite3MPrintf(tls, db, __ccgo_ts+20087, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(azObj)), *(*uintptr)(unsafe.Pointer(azObj + 1*4)), _azAlterType[(*TInitData)(unsafe.Pointer(pData)).FmInitFlags&uint32(INITFLAG_AlterMask)-uint32(1)], zExtra))
				(*TInitData)(unsafe.Pointer(pData)).Frc = int32(SQLITE_ERROR)
			} else {
				if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_WriteSchema) != 0 {
					(*TInitData)(unsafe.Pointer(pData)).Frc = _sqlite3CorruptError(tls, int32(141840))
				} else {
					if *(*uintptr)(unsafe.Pointer(azObj + 1*4)) != 0 {
						v1 = *(*uintptr)(unsafe.Pointer(azObj + 1*4))
					} else {
						v1 = __ccgo_ts + 6481
					}
					zObj = v1
					z = _sqlite3MPrintf(tls, db, __ccgo_ts+20115, libc.VaList(bp+8, zObj))
					if zExtra != 0 && *(*int8)(unsafe.Pointer(zExtra)) != 0 {
						z = _sqlite3MPrintf(tls, db, __ccgo_ts+20146, libc.VaList(bp+8, z, zExtra))
					}
					*(*uintptr)(unsafe.Pointer((*TInitData)(unsafe.Pointer(pData)).FpzErrMsg)) = z
					(*TInitData)(unsafe.Pointer(pData)).Frc = _sqlite3CorruptError(tls, int32(141847))
				}
			}
		}
	}
}

var _azAlterType = [3]uintptr{
	0: __ccgo_ts + 20057,
	1: __ccgo_ts + 20064,
	2: __ccgo_ts + 20076,
}

// C documentation
//
//	/*
//	** Check to see if any sibling index (another index on the same table)
//	** of pIndex has the same root page number, and if it does, return true.
//	** This would indicate a corrupt schema.
//	*/
func _sqlite3IndexHasDuplicateRootPage(tls *libc.TLS, pIndex uintptr) (r int32) {
	var p uintptr
	_ = p
	p = (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpIndex
	for {
		if !(p != 0) {
			break
		}
		if (*TIndex)(unsafe.Pointer(p)).Ftnum == (*TIndex)(unsafe.Pointer(pIndex)).Ftnum && p != pIndex {
			return int32(1)
		}
		goto _1
	_1:
		;
		p = (*TIndex)(unsafe.Pointer(p)).FpNext
	}
	return 0
}

// 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)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_EncodingFixed)
	if argv == uintptr(0) {
		return 0
	} /* Might happen if EMPTY_RESULT_CALLBACKS are on */
	(*TInitData)(unsafe.Pointer(pData)).FnInitRow++
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_corruptSchema(tls, pData, argv, uintptr(0))
		return int32(1)
	}
	if *(*uintptr)(unsafe.Pointer(argv + 3*4)) == uintptr(0) {
		_corruptSchema(tls, pData, argv, uintptr(0))
	} else {
		if *(*uintptr)(unsafe.Pointer(argv + 4*4)) != 0 && int32('c') == int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(argv + 4*4)))))]) && int32('r') == int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(argv + 4*4)) + 1)))]) {
			saved_iDb = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb
			/* Return code from sqlite3_prepare() */
			(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(uint8(iDb))
			if _sqlite3GetUInt32(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4)), db+172) == 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+15923)
				}
			}
			libc.SetBitFieldPtr8Uint32(db+172+8, libc.Uint32FromInt32(0), 0, 0x1)
			(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = argv
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			_sqlite3Prepare(tls, db, *(*uintptr)(unsafe.Pointer(argv + 4*4)), -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 + 172 + 8))&0x1>>0)) != 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)(unsafe.Pointer(bp)))
		} else {
			if *(*uintptr)(unsafe.Pointer(argv + 1*4)) == uintptr(0) || *(*uintptr)(unsafe.Pointer(argv + 4*4)) != uintptr(0) && int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(argv + 4*4))))) != 0 {
				_corruptSchema(tls, pData, argv, uintptr(0))
			} else {
				pIndex = _sqlite3FindIndex(tls, db, *(*uintptr)(unsafe.Pointer(argv + 1*4)), (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
				if pIndex == uintptr(0) {
					_corruptSchema(tls, pData, argv, __ccgo_ts+20154)
				} else {
					if _sqlite3GetUInt32(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4)), pIndex+44) == 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+15923)
						}
					}
				}
			}
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Attempt to read the database schema and initialize internal
//	** data structures for a single database file.  The index of the
//	** database file is given by iDb.  iDb==0 is used for the main
//	** database.  iDb==1 should never be used.  iDb>=2 is used for
//	** auxiliary databases.  Return one of the SQLITE_ error codes to
//	** indicate success or failure.
//	*/
func _sqlite3InitOne(tls *libc.TLS, db uintptr, iDb int32, pzErrMsg uintptr, mFlags Tu32) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var encoding Tu8
	var i, mask, openedTransaction, rc, size int32
	var pDb, zSchemaTabName, zSql, v1, v2, p3, p5 uintptr
	var xAuth Tsqlite3_xauth
	var _ /* azArg at bp+0 */ [6]uintptr
	var _ /* initData at bp+44 */ TInitData
	var _ /* meta at bp+24 */ [5]int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = encoding, i, mask, openedTransaction, pDb, rc, size, xAuth, zSchemaTabName, zSql, v1, v2, p3, p5
	openedTransaction = 0
	mask = int32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&libc.Uint32FromInt32(DBFLAG_EncodingFixed) | uint32(^libc.Int32FromInt32(DBFLAG_EncodingFixed)))
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(1)
	/* Construct the in-memory representation schema tables (sqlite_schema or
	 ** sqlite_temp_schema) by invoking the parser directly.  The appropriate
	 ** table name will be inserted automatically by the parser so we can just
	 ** use the abbreviation "x" here.  The parser will also automatically tag
	 ** the schema table as read-only. */
	(*(*[6]uintptr)(unsafe.Pointer(bp)))[0] = __ccgo_ts + 10492
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		v2 = __ccgo_ts + 7906
	} else {
		v2 = __ccgo_ts + 7439
	}
	v1 = v2
	zSchemaTabName = v1
	(*(*[6]uintptr)(unsafe.Pointer(bp)))[int32(1)] = v1
	(*(*[6]uintptr)(unsafe.Pointer(bp)))[int32(2)] = (*(*[6]uintptr)(unsafe.Pointer(bp)))[int32(1)]
	(*(*[6]uintptr)(unsafe.Pointer(bp)))[int32(3)] = __ccgo_ts + 9564
	(*(*[6]uintptr)(unsafe.Pointer(bp)))[int32(4)] = __ccgo_ts + 20167
	(*(*[6]uintptr)(unsafe.Pointer(bp)))[int32(5)] = uintptr(0)
	(*(*TInitData)(unsafe.Pointer(bp + 44))).Fdb = db
	(*(*TInitData)(unsafe.Pointer(bp + 44))).FiDb = iDb
	(*(*TInitData)(unsafe.Pointer(bp + 44))).Frc = SQLITE_OK
	(*(*TInitData)(unsafe.Pointer(bp + 44))).FpzErrMsg = pzErrMsg
	(*(*TInitData)(unsafe.Pointer(bp + 44))).FmInitFlags = mFlags
	(*(*TInitData)(unsafe.Pointer(bp + 44))).FnInitRow = uint32(0)
	(*(*TInitData)(unsafe.Pointer(bp + 44))).FmxPage = uint32(0)
	_sqlite3InitCallback(tls, bp+44, int32(5), bp, uintptr(0))
	*(*Tu32)(unsafe.Pointer(db + 24)) &= uint32(uint32(mask))
	if (*(*TInitData)(unsafe.Pointer(bp + 44))).Frc != 0 {
		rc = (*(*TInitData)(unsafe.Pointer(bp + 44))).Frc
		goto error_out
	}
	/* Create a cursor to hold the database open
	 */
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	if (*TDb)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
		p3 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 78
		*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(DB_SchemaLoaded))
		rc = SQLITE_OK
		goto error_out
	}
	/* If there is not already a read-only (or read-write) transaction opened
	 ** on the b-tree database, open one now. If a transaction is opened, it
	 ** will be closed before this function returns.  */
	_sqlite3BtreeEnter(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt) == SQLITE_TXN_NONE {
		rc = _sqlite3BtreeBeginTrans(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, 0, uintptr(0))
		if rc != SQLITE_OK {
			_sqlite3SetString(tls, pzErrMsg, db, _sqlite3ErrStr(tls, rc))
			goto initone_error_out
		}
		openedTransaction = int32(1)
	}
	/* Get the database meta information.
	 **
	 ** Meta values are as follows:
	 **    meta[0]   Schema cookie.  Changes with each schema change.
	 **    meta[1]   File format of schema layer.
	 **    meta[2]   Size of the page cache.
	 **    meta[3]   Largest rootpage (auto/incr_vacuum mode)
	 **    meta[4]   Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
	 **    meta[5]   User version
	 **    meta[6]   Incremental vacuum mode
	 **    meta[7]   unused
	 **    meta[8]   unused
	 **    meta[9]   unused
	 **
	 ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
	 ** the possible values of meta[4].
	 */
	i = 0
	for {
		if !(i < int32(libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4))) {
			break
		}
		_sqlite3BtreeGetMeta(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, i+int32(1), bp+24+uintptr(i)*4)
		goto _4
	_4:
		;
		i++
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0) {
		libc.Xmemset(tls, bp+24, 0, uint32(20))
	}
	(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fschema_cookie = (*(*[5]int32)(unsafe.Pointer(bp + 24)))[libc.Int32FromInt32(BTREE_SCHEMA_VERSION)-libc.Int32FromInt32(1)]
	/* If opening a non-empty database, check the text encoding. For the
	 ** main database, set sqlite3.enc to the encoding of the main database.
	 ** For an attached db, it is an error if the encoding is not the same
	 ** as sqlite3.enc.
	 */
	if (*(*[5]int32)(unsafe.Pointer(bp + 24)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)] != 0 { /* text encoding */
		if iDb == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_EncodingFixed) == uint32(0) {
			/* If opening the main database, set ENC(db). */
			encoding = uint8(int32(uint8((*(*[5]int32)(unsafe.Pointer(bp + 24)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)])) & int32(3))
			if int32(int32(encoding)) == 0 {
				encoding = uint8(SQLITE_UTF8)
			}
			if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive > 0 && int32(int32(encoding)) != int32((*Tsqlite3)(unsafe.Pointer(db)).Fenc) && (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) {
				rc = int32(SQLITE_LOCKED)
				goto initone_error_out
			} else {
				_sqlite3SetTextEncoding(tls, db, encoding)
			}
		} else {
			/* If opening an attached database, the encoding much match ENC(db) */
			if (*(*[5]int32)(unsafe.Pointer(bp + 24)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)]&int32(3) != int32((*Tsqlite3)(unsafe.Pointer(db)).Fenc) {
				_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+13529)
				rc = int32(SQLITE_ERROR)
				goto initone_error_out
			}
		}
	}
	(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
	if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size == 0 {
		size = _sqlite3AbsInt32(tls, (*(*[5]int32)(unsafe.Pointer(bp + 24)))[libc.Int32FromInt32(BTREE_DEFAULT_CACHE_SIZE)-libc.Int32FromInt32(1)])
		if size == 0 {
			size = -int32(2000)
		}
		(*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)
	}
	/*
	 ** file_format==1    Version 3.0.0.
	 ** file_format==2    Version 3.1.3.  // ALTER TABLE ADD COLUMN
	 ** file_format==3    Version 3.1.4.  // ditto but with non-NULL defaults
	 ** file_format==4    Version 3.3.0.  // DESC indices.  Boolean constants
	 */
	(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = uint8((*(*[5]int32)(unsafe.Pointer(bp + 24)))[libc.Int32FromInt32(BTREE_FILE_FORMAT)-libc.Int32FromInt32(1)])
	if int32((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) == 0 {
		(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = uint8(1)
	}
	if int32((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) > int32(SQLITE_MAX_FILE_FORMAT) {
		_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+20239)
		rc = int32(SQLITE_ERROR)
		goto initone_error_out
	}
	/* Ticket #2804:  When we open a database in the newer file format,
	 ** clear the legacy_file_format pragma flag so that a VACUUM will
	 ** not downgrade the database and thus invalidate any descending
	 ** indices that the user might have created.
	 */
	if iDb == 0 && (*(*[5]int32)(unsafe.Pointer(bp + 24)))[libc.Int32FromInt32(BTREE_FILE_FORMAT)-libc.Int32FromInt32(1)] >= int32(4) {
		*(*Tu64)(unsafe.Pointer(db + 32)) &= ^libc.Uint64FromInt32(SQLITE_LegacyFileFmt)
	}
	/* Read the schema information out of the schema tables
	 */
	(*(*TInitData)(unsafe.Pointer(bp + 44))).FmxPage = _sqlite3BtreeLastPage(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+20263, libc.VaList(bp+80, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, zSchemaTabName))
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3InitCallback), bp+44, uintptr(0))
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	if rc == SQLITE_OK {
		rc = (*(*TInitData)(unsafe.Pointer(bp + 44))).Frc
	}
	_sqlite3DbFree(tls, db, zSql)
	if rc == SQLITE_OK {
		_sqlite3AnalysisLoad(tls, db, iDb)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = int32(SQLITE_NOMEM)
		_sqlite3ResetAllSchemasOfConnection(tls, db)
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	} else {
		if rc == SQLITE_OK || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NoSchemaError) != 0 && rc != int32(SQLITE_NOMEM) {
			/* Hack: If the SQLITE_NoSchemaError flag is set, then consider
			 ** the schema loaded, even if errors (other than OOM) occurred. In
			 ** this situation the current sqlite3_prepare() operation will fail,
			 ** but the following one will attempt to compile the supplied statement
			 ** against whatever subset of the schema was loaded before the error
			 ** occurred.
			 **
			 ** The primary purpose of this is to allow access to the sqlite_schema
			 ** table even when its contents have been corrupted.
			 */
			p5 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 78
			*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(DB_SchemaLoaded))
			rc = SQLITE_OK
		}
	}
	/* Jump here for an error that occurs after successfully allocating
	 ** curMain and calling sqlite3BtreeEnter(). For an error that occurs
	 ** before that point, jump to error_out.
	 */
	goto initone_error_out
initone_error_out:
	;
	if openedTransaction != 0 {
		_sqlite3BtreeCommit(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	}
	_sqlite3BtreeLeave(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	goto error_out
error_out:
	;
	if rc != 0 {
		if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			_sqlite3OomFault(tls, db)
		}
		_sqlite3ResetOneSchema(tls, db, iDb)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
	return rc
}

// C documentation
//
//	/*
//	** Initialize all database files - the main database file, the file
//	** used to store temporary tables, and any additional database files
//	** created using ATTACH statements.  Return a success code.  If an
//	** error occurs, write an error message into *pzErrMsg.
//	**
//	** After a database is initialized, the DB_SchemaLoaded bit is set
//	** bit is set in the flags field of the Db structure.
//	*/
func _sqlite3Init(tls *libc.TLS, db uintptr, pzErrMsg uintptr) (r int32) {
	var commit_internal, i, rc int32
	_, _, _ = commit_internal, i, rc
	commit_internal = libc.BoolInt32(!((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&libc.Uint32FromInt32(DBFLAG_SchemaChange) != 0))
	(*Tsqlite3)(unsafe.Pointer(db)).Fenc = (*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fenc
	/* Do the main schema first */
	if !(int32((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_SchemaLoaded) == libc.Int32FromInt32(DB_SchemaLoaded)) {
		rc = _sqlite3InitOne(tls, db, 0, pzErrMsg, uint32(0))
		if rc != 0 {
			return rc
		}
	}
	/* All other schemas after the main schema. The "temp" schema must be last */
	i = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
	for {
		if !(i > 0) {
			break
		}
		if !(int32((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_SchemaLoaded) == libc.Int32FromInt32(DB_SchemaLoaded)) {
			rc = _sqlite3InitOne(tls, db, i, pzErrMsg, uint32(0))
			if rc != 0 {
				return rc
			}
		}
		goto _1
	_1:
		;
		i--
	}
	if commit_internal != 0 {
		_sqlite3CommitInternalChanges(tls, db)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This routine is a no-op if the database schema is already initialized.
//	** Otherwise, the schema is loaded. An error code is returned.
//	*/
func _sqlite3ReadSchema(tls *libc.TLS, pParse uintptr) (r int32) {
	var db uintptr
	var rc int32
	_, _ = db, rc
	rc = SQLITE_OK
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
		rc = _sqlite3Init(tls, db, pParse+4)
		if rc != SQLITE_OK {
			(*TParse)(unsafe.Pointer(pParse)).Frc = rc
			(*TParse)(unsafe.Pointer(pParse)).FnErr++
		} else {
			if (*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache != 0 {
				*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_SchemaKnownOk)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Check schema cookies in all databases.  If any cookie is out
//	** of date set pParse->rc to SQLITE_SCHEMA.  If all schema cookies
//	** make no changes to pParse->rc.
//	*/
func _schemaIsValid(tls *libc.TLS, pParse uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pBt uintptr
	var iDb, openedTransaction, rc int32
	var _ /* cookie at bp+0 */ int32
	_, _, _, _, _ = db, iDb, openedTransaction, pBt, rc
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	iDb = 0
	for {
		if !(iDb < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		openedTransaction = 0                                                                        /* True if a transaction is opened */
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt /* Btree database to read cookie from */
		if pBt == uintptr(0) {
			goto _1
		}
		/* If there is not already a read-only (or read-write) transaction opened
		 ** on the b-tree database, open one now. If a transaction is opened, it
		 ** will be closed immediately after reading the meta-value. */
		if _sqlite3BtreeTxnState(tls, pBt) == SQLITE_TXN_NONE {
			rc = _sqlite3BtreeBeginTrans(tls, pBt, 0, uintptr(0))
			if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
				_sqlite3OomFault(tls, db)
				(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
			}
			if rc != SQLITE_OK {
				return
			}
			openedTransaction = int32(1)
		}
		/* Read the schema cookie from the database. If it does not match the
		 ** value stored as part of the in-memory schema representation,
		 ** set Parse.rc to SQLITE_SCHEMA. */
		_sqlite3BtreeGetMeta(tls, pBt, int32(BTREE_SCHEMA_VERSION), bp)
		if *(*int32)(unsafe.Pointer(bp)) != (*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema)).Fschema_cookie {
			if int32((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema)).FschemaFlags)&int32(DB_SchemaLoaded) == int32(DB_SchemaLoaded) {
				(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_SCHEMA)
			}
			_sqlite3ResetOneSchema(tls, db, iDb)
		}
		/* Close the transaction, if one was opened. */
		if openedTransaction != 0 {
			_sqlite3BtreeCommit(tls, pBt)
		}
		goto _1
	_1:
		;
		iDb++
	}
}

// C documentation
//
//	/*
//	** Convert a schema pointer into the iDb index that indicates
//	** which database file in db->aDb[] the schema refers to.
//	**
//	** If the same database is attached more than once, the first
//	** attached database is returned.
//	*/
func _sqlite3SchemaToIndex(tls *libc.TLS, db uintptr, pSchema uintptr) (r int32) {
	var i int32
	_ = i
	i = -int32(32768)
	/* If pSchema is NULL, then return -32768. This happens when code in
	 ** expr.c is trying to resolve a reference to a transient table (i.e. one
	 ** created by a sub-select). In this case the return value of this
	 ** function should never be used.
	 **
	 ** We return -32768 instead of the more usual -1 simply because using
	 ** -32768 as the incorrect index into db->aDb[] is much
	 ** more likely to cause a segfault than -1 (of course there are assert()
	 ** statements too, but it never hurts to play the odds) and
	 ** -32768 will still fit into a 16-bit signed integer.
	 */
	if pSchema != 0 {
		i = 0
		for {
			if !(int32(1) != 0) {
				break
			}
			if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema == pSchema {
				break
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return i
}

// C documentation
//
//	/*
//	** Free all memory allocations in the pParse object
//	*/
func _sqlite3ParseObjectReset(tls *libc.TLS, pParse uintptr) {
	var db, pCleanup uintptr
	var v1 int32
	_, _, _ = db, pCleanup, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FaTableLock != 0 {
		_sqlite3DbNNFreeNN(tls, db, (*TParse)(unsafe.Pointer(pParse)).FaTableLock)
	}
	for (*TParse)(unsafe.Pointer(pParse)).FpCleanup != 0 {
		pCleanup = (*TParse)(unsafe.Pointer(pParse)).FpCleanup
		(*TParse)(unsafe.Pointer(pParse)).FpCleanup = (*TParseCleanup)(unsafe.Pointer(pCleanup)).FpNext
		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TParseCleanup)(unsafe.Pointer(pCleanup)).FxCleanup})))(tls, db, (*TParseCleanup)(unsafe.Pointer(pCleanup)).FpPtr)
		_sqlite3DbNNFreeNN(tls, db, pCleanup)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FaLabel != 0 {
		_sqlite3DbNNFreeNN(tls, db, (*TParse)(unsafe.Pointer(pParse)).FaLabel)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FpConstExpr != 0 {
		_sqlite3ExprListDelete(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpConstExpr)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable -= uint32((*TParse)(unsafe.Pointer(pParse)).FdisableLookaside)
	if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
		v1 = 0
	} else {
		v1 = int32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(v1)
	(*Tsqlite3)(unsafe.Pointer(db)).FpParse = (*TParse)(unsafe.Pointer(pParse)).FpOuterParse
}

// C documentation
//
//	/*
//	** Add a new cleanup operation to a Parser.  The cleanup should happen when
//	** the parser object is destroyed.  But, beware: the cleanup might happen
//	** immediately.
//	**
//	** Use this mechanism for uncommon cleanups.  There is a higher setup
//	** cost for this mechanism (an extra malloc), so it should not be used
//	** for common cleanups that happen on most calls.  But for less
//	** common cleanups, we save a single NULL-pointer comparison in
//	** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
//	**
//	** If a memory allocation error occurs, then the cleanup happens immediately.
//	** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
//	** pParse->earlyCleanup flag is set in that case.  Calling code show verify
//	** that test cases exist for which this happens, to guard against possible
//	** use-after-free errors following an OOM.  The preferred way to do this is
//	** to immediately follow the call to this routine with:
//	**
//	**       testcase( pParse->earlyCleanup );
//	**
//	** This routine returns a copy of its pPtr input (the third parameter)
//	** except if an early cleanup occurs, in which case it returns NULL.  So
//	** another way to check for early cleanup is to check the return value.
//	** Or, stop using the pPtr parameter with this call and use only its
//	** return value thereafter.  Something like this:
//	**
//	**       pObj = sqlite3ParserAddCleanup(pParse, destructor, pObj);
//	*/
func _sqlite3ParserAddCleanup(tls *libc.TLS, pParse uintptr, xCleanup uintptr, pPtr uintptr) (r uintptr) {
	var pCleanup uintptr
	_ = pCleanup
	if _sqlite3FaultSim(tls, int32(300)) != 0 {
		pCleanup = uintptr(0)
		_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb)
	} else {
		pCleanup = _sqlite3DbMallocRaw(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(12))
	}
	if pCleanup != 0 {
		(*TParseCleanup)(unsafe.Pointer(pCleanup)).FpNext = (*TParse)(unsafe.Pointer(pParse)).FpCleanup
		(*TParse)(unsafe.Pointer(pParse)).FpCleanup = pCleanup
		(*TParseCleanup)(unsafe.Pointer(pCleanup)).FpPtr = pPtr
		(*TParseCleanup)(unsafe.Pointer(pCleanup)).FxCleanup = xCleanup
	} else {
		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{xCleanup})))(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPtr)
		pPtr = uintptr(0)
	}
	return pPtr
}

// C documentation
//
//	/*
//	** Turn bulk memory into a valid Parse object and link that Parse object
//	** into database connection db.
//	**
//	** Call sqlite3ParseObjectReset() to undo this operation.
//	**
//	** Caution:  Do not confuse this routine with sqlite3ParseObjectInit() which
//	** is generated by Lemon.
//	*/
func _sqlite3ParseObjectInit(tls *libc.TLS, pParse uintptr, db uintptr) {
	libc.Xmemset(tls, pParse+uintptr(uint32(libc.UintptrFromInt32(0)+4)), 0, uint32(libc.UintptrFromInt32(0)+164)-uint32(libc.UintptrFromInt32(0)+4))
	libc.Xmemset(tls, pParse+uintptr(uint32(libc.UintptrFromInt32(0)+208)), 0, libc.Uint32FromInt64(284)-uint32(libc.UintptrFromInt32(0)+208))
	(*TParse)(unsafe.Pointer(pParse)).FpOuterParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
	(*Tsqlite3)(unsafe.Pointer(db)).FpParse = pParse
	(*TParse)(unsafe.Pointer(pParse)).Fdb = db
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1642, 0)
	}
}

/*
** Maximum number of times that we will try again to prepare a statement
** that returns SQLITE_ERROR_RETRY.
 */

// 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(304)
	defer tls.Free(304)
	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(uint32(libc.UintptrFromInt32(0)+4)), 0, uint32(libc.UintptrFromInt32(0)+164)-uint32(libc.UintptrFromInt32(0)+4))
	libc.Xmemset(tls, bp+uintptr(uint32(libc.UintptrFromInt32(0)+208)), 0, libc.Uint32FromInt64(284)-uint32(libc.UintptrFromInt32(0)+208))
	(*(*TParse)(unsafe.Pointer(bp))).FpOuterParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
	(*Tsqlite3)(unsafe.Pointer(db)).FpParse = bp
	(*(*TParse)(unsafe.Pointer(bp))).Fdb = db
	if pReprepare != 0 {
		(*(*TParse)(unsafe.Pointer(bp))).FpReprepare = pReprepare
		(*(*TParse)(unsafe.Pointer(bp))).Fexplain = uint8(Xsqlite3_stmt_isexplain(tls, pReprepare))
	} else {
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3ErrorMsg(tls, bp, __ccgo_ts+1642, 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)(unsafe.Pointer(bp))).FdisableLookaside++
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
	}
	(*(*TParse)(unsafe.Pointer(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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
			if pBt != 0 {
				rc = _sqlite3BtreeSchemaLocked(tls, pBt)
				if rc != 0 {
					zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FzDbSName
					_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+20297, libc.VaList(bp+296, zDb))
					goto end_prepare
				}
			}
			goto _2
		_2:
			;
			i++
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FpDisconnect != 0 {
		_sqlite3VtabUnlockList(tls, db)
	}
	if nBytes >= 0 && (nBytes == 0 || int32(*(*int8)(unsafe.Pointer(zSql + uintptr(nBytes-int32(1))))) != 0) {
		mxLen = *(*int32)(unsafe.Pointer(db + 120 + 1*4))
		if nBytes > mxLen {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_TOOBIG), __ccgo_ts+20327, 0)
			rc = _sqlite3ApiExit(tls, db, int32(SQLITE_TOOBIG))
			goto end_prepare
		}
		zSqlCopy = _sqlite3DbStrNDup(tls, db, zSql, uint64(uint64(nBytes)))
		if zSqlCopy != 0 {
			_sqlite3RunParser(tls, bp, zSqlCopy)
			(*(*TParse)(unsafe.Pointer(bp))).FzTail = zSql + uintptr(int32((*(*TParse)(unsafe.Pointer(bp))).FzTail)-int32(int32(zSqlCopy)))
			_sqlite3DbFree(tls, db, zSqlCopy)
		} else {
			(*(*TParse)(unsafe.Pointer(bp))).FzTail = zSql + uintptr(nBytes)
		}
	} else {
		_sqlite3RunParser(tls, bp, zSql)
	}
	if pzTail != 0 {
		*(*uintptr)(unsafe.Pointer(pzTail)) = (*(*TParse)(unsafe.Pointer(bp))).FzTail
	}
	if int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
		_sqlite3VdbeSetSql(tls, (*(*TParse)(unsafe.Pointer(bp))).FpVdbe, zSql, int32((*(*TParse)(unsafe.Pointer(bp))).FzTail)-int32(int32(zSql)), uint8(uint8(prepFlags)))
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*(*TParse)(unsafe.Pointer(bp))).Frc = int32(SQLITE_NOMEM)
		(*(*TParse)(unsafe.Pointer(bp))).FcheckSchema = uint8(0)
	}
	if (*(*TParse)(unsafe.Pointer(bp))).Frc != SQLITE_OK && (*(*TParse)(unsafe.Pointer(bp))).Frc != int32(SQLITE_DONE) {
		if (*(*TParse)(unsafe.Pointer(bp))).FcheckSchema != 0 && int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
			_schemaIsValid(tls, bp)
		}
		if (*(*TParse)(unsafe.Pointer(bp))).FpVdbe != 0 {
			_sqlite3VdbeFinalize(tls, (*(*TParse)(unsafe.Pointer(bp))).FpVdbe)
		}
		rc = (*(*TParse)(unsafe.Pointer(bp))).Frc
		if (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg != 0 {
			_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+4709, libc.VaList(bp+296, (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg))
			_sqlite3DbFree(tls, db, (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg)
		} else {
			_sqlite3Error(tls, db, rc)
		}
	} else {
		*(*uintptr)(unsafe.Pointer(ppStmt)) = (*(*TParse)(unsafe.Pointer(bp))).FpVdbe
		rc = SQLITE_OK
		_sqlite3ErrorClear(tls, db)
	}
	/* Delete any TriggerPrg structures allocated while parsing this statement. */
	for (*(*TParse)(unsafe.Pointer(bp))).FpTriggerPrg != 0 {
		pT = (*(*TParse)(unsafe.Pointer(bp))).FpTriggerPrg
		(*(*TParse)(unsafe.Pointer(bp))).FpTriggerPrg = (*TTriggerPrg)(unsafe.Pointer(pT)).FpNext
		_sqlite3DbFree(tls, db, pT)
	}
	goto end_prepare
end_prepare:
	;
	_sqlite3ParseObjectReset(tls, bp)
	return rc
}

func _sqlite3LockAndPrepare(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags Tu32, pOld uintptr, ppStmt uintptr, pzTail uintptr) (r int32) {
	var cnt, rc, v1, v3 int32
	var v2, v4, v5 bool
	_, _, _, _, _, _, _ = cnt, rc, v1, v2, v3, v4, v5
	cnt = 0
	*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	if !(_sqlite3SafetyCheckOk(tls, db) != 0) || zSql == uintptr(0) {
		return _sqlite3MisuseError(tls, int32(142654))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3BtreeEnterAll(tls, db)
	for {
		/* Make multiple attempts to compile the SQL, until it either succeeds
		 ** or encounters a permanent error.  A schema problem after one schema
		 ** reset is considered a permanent error. */
		rc = _sqlite3Prepare(tls, db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail)
		if rc == SQLITE_OK || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			break
		}
		goto _6
	_6:
		;
		if v2 = rc == libc.Int32FromInt32(SQLITE_ERROR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8); v2 {
			v1 = cnt
			cnt++
		}
		if v5 = v2 && v1 < int32(SQLITE_MAX_PREPARE_RETRY); !v5 {
			if v4 = rc == int32(SQLITE_SCHEMA); v4 {
				_sqlite3ResetOneSchema(tls, db, -int32(1))
				v3 = cnt
				cnt++
			}
		}
		if !(v5 || v4 && v3 == 0) {
			break
		}
	}
	_sqlite3BtreeLeaveAll(tls, db)
	rc = _sqlite3ApiExit(tls, db, rc)
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Rerun the compilation of a statement after a schema change.
//	**
//	** If the statement is successfully recompiled, return SQLITE_OK. Otherwise,
//	** if the statement cannot be recompiled because another connection has
//	** locked the sqlite3_schema table, return SQLITE_LOCKED. If any other error
//	** occurs, return SQLITE_SCHEMA.
//	*/
func _sqlite3Reprepare(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, zSql uintptr
	var prepFlags Tu8
	var rc int32
	var _ /* pNew at bp+0 */ uintptr
	_, _, _, _ = db, prepFlags, rc, zSql
	zSql = Xsqlite3_sql(tls, p)
	/* Reprepare only called for prepare_v2() statements */
	db = _sqlite3VdbeDb(tls, p)
	prepFlags = _sqlite3VdbePrepareFlags(tls, p)
	rc = _sqlite3LockAndPrepare(tls, db, zSql, -int32(1), uint32(uint32(prepFlags)), p, bp, uintptr(0))
	if rc != 0 {
		if rc == int32(SQLITE_NOMEM) {
			_sqlite3OomFault(tls, db)
		}
		return rc
	} else {
	}
	_sqlite3VdbeSwap(tls, *(*uintptr)(unsafe.Pointer(bp)), p)
	_sqlite3TransferBindings(tls, *(*uintptr)(unsafe.Pointer(bp)), p)
	_sqlite3VdbeResetStepResult(tls, *(*uintptr)(unsafe.Pointer(bp)))
	_sqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Two versions of the official API.  Legacy and new use.  In the legacy
//	** version, the original SQL text is not saved in the prepared statement
//	** and so if a schema change occurs, SQLITE_SCHEMA is returned by
//	** sqlite3_step().  In the new version, the original SQL text is retained
//	** and the statement is automatically recompiled if an schema change
//	** occurs.
//	*/
func Xsqlite3_prepare(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _sqlite3LockAndPrepare(tls, db, zSql, nBytes, uint32(0), uintptr(0), ppStmt, pzTail)
	/* VERIFY: F13021 */
	return rc
}

func Xsqlite3_prepare_v2(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) (r int32) {
	var rc int32
	_ = rc
	/* EVIDENCE-OF: R-37923-12173 The sqlite3_prepare_v2() interface works
	 ** exactly the same as sqlite3_prepare_v3() with a zero prepFlags
	 ** parameter.
	 **
	 ** Proof in that the 5th parameter to sqlite3LockAndPrepare is 0 */
	rc = _sqlite3LockAndPrepare(tls, db, zSql, nBytes, uint32(SQLITE_PREPARE_SAVESQL), uintptr(0), ppStmt, pzTail)
	return rc
}

func Xsqlite3_prepare_v3(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags uint32, ppStmt uintptr, pzTail uintptr) (r int32) {
	var rc int32
	_ = rc
	/* EVIDENCE-OF: R-56861-42673 sqlite3_prepare_v3() differs from
	 ** sqlite3_prepare_v2() only in having the extra prepFlags parameter,
	 ** which is a bit array consisting of zero or more of the
	 ** SQLITE_PREPARE_* flags.
	 **
	 ** Proof by comparison to the implementation of sqlite3_prepare_v2()
	 ** directly above. */
	rc = _sqlite3LockAndPrepare(tls, db, zSql, nBytes, uint32(SQLITE_PREPARE_SAVESQL)|prepFlags&uint32(SQLITE_PREPARE_MASK), uintptr(0), ppStmt, pzTail)
	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 int32
	var z, zSql8 uintptr
	var _ /* zTail8 at bp+0 */ uintptr
	_, _, _, _, _ = chars_parsed, rc, sz, z, zSql8
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	if !(_sqlite3SafetyCheckOk(tls, db) != 0) || zSql == uintptr(0) {
		return _sqlite3MisuseError(tls, int32(142803))
	}
	if nBytes >= 0 {
		z = zSql
		sz = 0
		for {
			if !(sz < nBytes && (int32(*(*int8)(unsafe.Pointer(z + uintptr(sz)))) != 0 || int32(*(*int8)(unsafe.Pointer(z + uintptr(sz+int32(1))))) != 0)) {
				break
			}
			goto _1
		_1:
			;
			sz += int32(2)
		}
		nBytes = sz
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	zSql8 = _sqlite3Utf16to8(tls, db, zSql, nBytes, uint8(SQLITE_UTF16LE))
	if zSql8 != 0 {
		rc = _sqlite3LockAndPrepare(tls, db, zSql8, -int32(1), prepFlags, uintptr(0), ppStmt, bp)
	}
	if *(*uintptr)(unsafe.Pointer(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(*(*uintptr)(unsafe.Pointer(bp)))-int32(int32(zSql8)))
		*(*uintptr)(unsafe.Pointer(pzTail)) = zSql + uintptr(_sqlite3Utf16ByteLen(tls, zSql, chars_parsed))
	}
	_sqlite3DbFree(tls, db, zSql8)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Two versions of the official API.  Legacy and new use.  In the legacy
//	** version, the original SQL text is not saved in the prepared statement
//	** and so if a schema change occurs, SQLITE_SCHEMA is returned by
//	** sqlite3_step().  In the new version, the original SQL text is retained
//	** and the statement is automatically recompiled if an schema change
//	** occurs.
//	*/
func Xsqlite3_prepare16(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _sqlite3Prepare16(tls, db, zSql, nBytes, uint32(0), ppStmt, pzTail)
	/* VERIFY: F13021 */
	return rc
}

func Xsqlite3_prepare16_v2(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _sqlite3Prepare16(tls, db, zSql, nBytes, uint32(SQLITE_PREPARE_SAVESQL), ppStmt, pzTail)
	/* VERIFY: F13021 */
	return rc
}

func Xsqlite3_prepare16_v3(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags uint32, ppStmt uintptr, pzTail uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _sqlite3Prepare16(tls, db, zSql, nBytes, uint32(SQLITE_PREPARE_SAVESQL)|prepFlags&uint32(SQLITE_PREPARE_MASK), ppStmt, pzTail)
	/* VERIFY: F13021 */
	return rc
}

/************** End of prepare.c *********************************************/
/************** Begin file select.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 C code routines that are called by the parser
** to handle SELECT statements in SQLite.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** An instance of the following object is used to record information about
//	** how to process the DISTINCT keyword, to simplify passing that information
//	** into the selectInnerLoop() routine.
//	*/
type TDistinctCtx = struct {
	FisTnct    Tu8
	FeTnctType Tu8
	FtabTnct   int32
	FaddrTnct  int32
}

type DistinctCtx = TDistinctCtx

type TDistinctCtx1 = struct {
	FisTnct    Tu8
	FeTnctType Tu8
	FtabTnct   int32
	FaddrTnct  int32
}

type DistinctCtx1 = TDistinctCtx1

// C documentation
//
//	/*
//	** An instance of the following object is used to record information about
//	** the ORDER BY (or GROUP BY) clause of query is being coded.
//	**
//	** The aDefer[] array is used by the sorter-references optimization. For
//	** example, assuming there is no index that can be used for the ORDER BY,
//	** for the query:
//	**
//	**     SELECT a, bigblob FROM t1 ORDER BY a LIMIT 10;
//	**
//	** it may be more efficient to add just the "a" values to the sorter, and
//	** retrieve the associated "bigblob" values directly from table t1 as the
//	** 10 smallest "a" values are extracted from the sorter.
//	**
//	** When the sorter-reference optimization is used, there is one entry in the
//	** aDefer[] array for each database table that may be read as values are
//	** extracted from the sorter.
//	*/
type TSortCtx = struct {
	FpOrderBy         uintptr
	FnOBSat           int32
	FiECursor         int32
	FregReturn        int32
	FlabelBkOut       int32
	FaddrSortIndex    int32
	FlabelDone        int32
	FlabelOBLopt      int32
	FsortFlags        Tu8
	FpDeferredRowLoad uintptr
}

type SortCtx = TSortCtx

type TSortCtx1 = struct {
	FpOrderBy         uintptr
	FnOBSat           int32
	FiECursor         int32
	FregReturn        int32
	FlabelBkOut       int32
	FaddrSortIndex    int32
	FlabelDone        int32
	FlabelOBLopt      int32
	FsortFlags        Tu8
	FpDeferredRowLoad uintptr
}

type SortCtx1 = TSortCtx1

// C documentation
//
//	/*
//	** Delete all the content of a Select structure.  Deallocate the structure
//	** itself depending on the value of bFree
//	**
//	** If bFree==1, call sqlite3DbFree() on the p object.
//	** If bFree==0, Leave the first Select object unfreed
//	*/
func _clearSelect(tls *libc.TLS, db uintptr, p uintptr, bFree int32) {
	var pPrior uintptr
	_ = pPrior
	for p != 0 {
		pPrior = (*TSelect)(unsafe.Pointer(p)).FpPrior
		_sqlite3ExprListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpEList)
		_sqlite3SrcListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpSrc)
		_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpWhere)
		_sqlite3ExprListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpGroupBy)
		_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpHaving)
		_sqlite3ExprListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
		_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit)
		if (*TSelect)(unsafe.Pointer(p)).FpWith != 0 {
			_sqlite3WithDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpWith)
		}
		if (*TSelect)(unsafe.Pointer(p)).FpWinDefn != 0 {
			_sqlite3WindowListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpWinDefn)
		}
		for (*TSelect)(unsafe.Pointer(p)).FpWin != 0 {
			_sqlite3WindowUnlinkFromSelect(tls, (*TSelect)(unsafe.Pointer(p)).FpWin)
		}
		if bFree != 0 {
			_sqlite3DbNNFreeNN(tls, db, p)
		}
		p = pPrior
		bFree = int32(1)
	}
}

// C documentation
//
//	/*
//	** Initialize a SelectDest structure.
//	*/
func _sqlite3SelectDestInit(tls *libc.TLS, pDest uintptr, eDest int32, iParm int32) {
	(*TSelectDest)(unsafe.Pointer(pDest)).FeDest = uint8(uint8(eDest))
	(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm = iParm
	(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 = 0
	(*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst = uintptr(0)
	(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = 0
	(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = 0
}

// C documentation
//
//	/*
//	** Allocate a new Select structure and return a pointer to that
//	** structure.
//	*/
func _sqlite3SelectNew(tls *libc.TLS, pParse uintptr, pEList uintptr, pSrc uintptr, pWhere uintptr, pGroupBy uintptr, pHaving uintptr, pOrderBy uintptr, selFlags Tu32, pLimit uintptr) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var pAllocated, pNew, v1, v3 uintptr
	var v2 int32
	var _ /* standin at bp+0 */ TSelect
	_, _, _, _, _ = pAllocated, pNew, v1, v2, v3
	v1 = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(76))
	pNew = v1
	pAllocated = v1
	if pNew == uintptr(0) {
		pNew = bp
	}
	if pEList == uintptr(0) {
		pEList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_ASTERISK), uintptr(0)))
	}
	(*TSelect)(unsafe.Pointer(pNew)).FpEList = pEList
	(*TSelect)(unsafe.Pointer(pNew)).Fop = uint8(TK_SELECT)
	(*TSelect)(unsafe.Pointer(pNew)).FselFlags = selFlags
	(*TSelect)(unsafe.Pointer(pNew)).FiLimit = 0
	(*TSelect)(unsafe.Pointer(pNew)).FiOffset = 0
	v3 = pParse + 108
	*(*int32)(unsafe.Pointer(v3))++
	v2 = *(*int32)(unsafe.Pointer(v3))
	(*TSelect)(unsafe.Pointer(pNew)).FselId = uint32(v2)
	*(*int32)(unsafe.Pointer(pNew + 20)) = -int32(1)
	*(*int32)(unsafe.Pointer(pNew + 20 + 1*4)) = -int32(1)
	(*TSelect)(unsafe.Pointer(pNew)).FnSelectRow = 0
	if pSrc == uintptr(0) {
		pSrc = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(80))
	}
	(*TSelect)(unsafe.Pointer(pNew)).FpSrc = pSrc
	(*TSelect)(unsafe.Pointer(pNew)).FpWhere = pWhere
	(*TSelect)(unsafe.Pointer(pNew)).FpGroupBy = pGroupBy
	(*TSelect)(unsafe.Pointer(pNew)).FpHaving = pHaving
	(*TSelect)(unsafe.Pointer(pNew)).FpOrderBy = pOrderBy
	(*TSelect)(unsafe.Pointer(pNew)).FpPrior = uintptr(0)
	(*TSelect)(unsafe.Pointer(pNew)).FpNext = uintptr(0)
	(*TSelect)(unsafe.Pointer(pNew)).FpLimit = pLimit
	(*TSelect)(unsafe.Pointer(pNew)).FpWith = uintptr(0)
	(*TSelect)(unsafe.Pointer(pNew)).FpWin = uintptr(0)
	(*TSelect)(unsafe.Pointer(pNew)).FpWinDefn = uintptr(0)
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		_clearSelect(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pNew, libc.BoolInt32(pNew != bp))
		pAllocated = uintptr(0)
	} else {
	}
	return pAllocated
}

// C documentation
//
//	/*
//	** Delete the given Select structure and all of its substructures.
//	*/
func _sqlite3SelectDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		_clearSelect(tls, db, p, int32(1))
	}
}

func _sqlite3SelectDeleteGeneric(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		_clearSelect(tls, db, p, int32(1))
	}
}

// C documentation
//
//	/*
//	** Return a pointer to the right-most SELECT statement in a compound.
//	*/
func _findRightmost(tls *libc.TLS, p uintptr) (r uintptr) {
	for (*TSelect)(unsafe.Pointer(p)).FpNext != 0 {
		p = (*TSelect)(unsafe.Pointer(p)).FpNext
	}
	return p
}

// C documentation
//
//	/*
//	** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
//	** type of join.  Return an integer constant that expresses that type
//	** in terms of the following bit values:
//	**
//	**     JT_INNER
//	**     JT_CROSS
//	**     JT_OUTER
//	**     JT_NATURAL
//	**     JT_LEFT
//	**     JT_RIGHT
//	**
//	** A full outer join is the combination of JT_LEFT and JT_RIGHT.
//	**
//	** If an illegal or unsupported join type is seen, then still return
//	** a join type, but put an error in the pParse structure.
//	**
//	** These are the valid join types:
//	**
//	**
//	**      pA       pB       pC               Return Value
//	**     -------  -----    -----             ------------
//	**     CROSS      -        -                 JT_CROSS
//	**     INNER      -        -                 JT_INNER
//	**     LEFT       -        -                 JT_LEFT|JT_OUTER
//	**     LEFT     OUTER      -                 JT_LEFT|JT_OUTER
//	**     RIGHT      -        -                 JT_RIGHT|JT_OUTER
//	**     RIGHT    OUTER      -                 JT_RIGHT|JT_OUTER
//	**     FULL       -        -                 JT_LEFT|JT_RIGHT|JT_OUTER
//	**     FULL     OUTER      -                 JT_LEFT|JT_RIGHT|JT_OUTER
//	**     NATURAL  INNER      -                 JT_NATURAL|JT_INNER
//	**     NATURAL  LEFT       -                 JT_NATURAL|JT_LEFT|JT_OUTER
//	**     NATURAL  LEFT     OUTER               JT_NATURAL|JT_LEFT|JT_OUTER
//	**     NATURAL  RIGHT      -                 JT_NATURAL|JT_RIGHT|JT_OUTER
//	**     NATURAL  RIGHT    OUTER               JT_NATURAL|JT_RIGHT|JT_OUTER
//	**     NATURAL  FULL       -                 JT_NATURAL|JT_LEFT|JT_RIGHT
//	**     NATURAL  FULL     OUTER               JT_NATRUAL|JT_LEFT|JT_RIGHT
//	**
//	** To preserve historical compatibly, SQLite also accepts a variety
//	** of other non-standard and in many cases nonsensical join types.
//	** This routine makes as much sense at it can from the nonsense join
//	** type and returns a result.  Examples of accepted nonsense join types
//	** include but are not limited to:
//	**
//	**          INNER CROSS JOIN        ->   same as JOIN
//	**          NATURAL CROSS JOIN      ->   same as NATURAL JOIN
//	**          OUTER LEFT JOIN         ->   same as LEFT JOIN
//	**          LEFT NATURAL JOIN       ->   same as NATURAL LEFT JOIN
//	**          LEFT RIGHT JOIN         ->   same as FULL JOIN
//	**          RIGHT OUTER FULL JOIN   ->   same as FULL JOIN
//	**          CROSS CROSS CROSS JOIN  ->   same as JOIN
//	**
//	** The only restrictions on the join type name are:
//	**
//	**    *   "INNER" cannot appear together with "OUTER", "LEFT", "RIGHT",
//	**        or "FULL".
//	**
//	**    *   "CROSS" cannot appear together with "OUTER", "LEFT", "RIGHT,
//	**        or "FULL".
//	**
//	**    *   If "OUTER" is present then there must also be one of
//	**        "LEFT", "RIGHT", or "FULL"
//	*/
func _sqlite3JoinType(tls *libc.TLS, pParse uintptr, pA uintptr, pB uintptr, pC uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var apAll [3]uintptr
	var i, j, jointype int32
	var p, zSp1, zSp2 uintptr
	_, _, _, _, _, _, _ = apAll, i, j, jointype, p, zSp1, zSp2
	jointype = 0
	apAll[0] = pA
	apAll[int32(1)] = pB
	apAll[int32(2)] = pC
	i = 0
	for {
		if !(i < int32(3) && apAll[i] != 0) {
			break
		}
		p = apAll[i]
		j = 0
		for {
			if !(j < int32(libc.Uint32FromInt64(21)/libc.Uint32FromInt64(3))) {
				break
			}
			if (*TToken)(unsafe.Pointer(p)).Fn == uint32(_aKeyword[j].FnChar) && Xsqlite3_strnicmp(tls, (*TToken)(unsafe.Pointer(p)).Fz, uintptr(unsafe.Pointer(&_zKeyText))+uintptr(_aKeyword[j].Fi), int32((*TToken)(unsafe.Pointer(p)).Fn)) == 0 {
				jointype |= int32(_aKeyword[j].Fcode)
				break
			}
			goto _2
		_2:
			;
			j++
		}
		if j >= int32(libc.Uint32FromInt64(21)/libc.Uint32FromInt64(3)) {
			jointype |= int32(JT_ERROR)
			break
		}
		goto _1
	_1:
		;
		i++
	}
	if jointype&(libc.Int32FromInt32(JT_INNER)|libc.Int32FromInt32(JT_OUTER)) == libc.Int32FromInt32(JT_INNER)|libc.Int32FromInt32(JT_OUTER) || jointype&int32(JT_ERROR) != 0 || jointype&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_RIGHT)) == int32(JT_OUTER) {
		zSp1 = __ccgo_ts + 12636
		zSp2 = __ccgo_ts + 12636
		if pB == uintptr(0) {
			zSp1++
		}
		if pC == uintptr(0) {
			zSp2++
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20346, libc.VaList(bp+8, pA, zSp1, pB, zSp2, pC))
		jointype = int32(JT_INNER)
	}
	return jointype
}

/*   0123456789 123456789 123456789 123 */
var _zKeyText = [34]int8{'n', 'a', 't', 'u', 'r', 'a', 'l', 'e', 'f', 't', 'o', 'u', 't', 'e', 'r', 'i', 'g', 'h', 't', 'f', 'u', 'l', 'l', 'i', 'n', 'n', 'e', 'r', 'c', 'r', 'o', 's', 's'}

var _aKeyword = [7]struct {
	Fi     Tu8
	FnChar Tu8
	Fcode  Tu8
}{
	0: {
		FnChar: uint8(7),
		Fcode:  uint8(JT_NATURAL),
	},
	1: {
		Fi:     uint8(6),
		FnChar: uint8(4),
		Fcode:  uint8(libc.Int32FromInt32(JT_LEFT) | libc.Int32FromInt32(JT_OUTER)),
	},
	2: {
		Fi:     uint8(10),
		FnChar: uint8(5),
		Fcode:  uint8(JT_OUTER),
	},
	3: {
		Fi:     uint8(14),
		FnChar: uint8(5),
		Fcode:  uint8(libc.Int32FromInt32(JT_RIGHT) | libc.Int32FromInt32(JT_OUTER)),
	},
	4: {
		Fi:     uint8(19),
		FnChar: uint8(4),
		Fcode:  uint8(libc.Int32FromInt32(JT_LEFT) | libc.Int32FromInt32(JT_RIGHT) | libc.Int32FromInt32(JT_OUTER)),
	},
	5: {
		Fi:     uint8(23),
		FnChar: uint8(5),
		Fcode:  uint8(JT_INNER),
	},
	6: {
		Fi:     uint8(28),
		FnChar: uint8(5),
		Fcode:  uint8(libc.Int32FromInt32(JT_INNER) | libc.Int32FromInt32(JT_CROSS)),
	},
}

// C documentation
//
//	/*
//	** Return the index of a column in a table.  Return -1 if the column
//	** is not contained in the table.
//	*/
func _sqlite3ColumnIndex(tls *libc.TLS, pTab uintptr, zCol uintptr) (r int32) {
	var h Tu8
	var i int32
	var pCol uintptr
	_, _, _ = h, i, pCol
	h = _sqlite3StrIHash(tls, zCol)
	pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
	i = libc.Int32FromInt32(0)
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if int32((*TColumn)(unsafe.Pointer(pCol)).FhName) == int32(int32(h)) && _sqlite3StrICmp(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, zCol) == 0 {
			return i
		}
		goto _1
	_1:
		;
		pCol += 12
		i++
	}
	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(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x2000>>13)) != 0 {
		pResults = (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpEList
		libc.SetBitFieldPtr16Uint32(pResults+8+uintptr(iCol)*20+8+4, libc.Uint32FromInt32(1), 6, 0x40)
	}
}

// C documentation
//
//	/*
//	** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
//	** table that has a column named zCol.  The search is left-to-right.
//	** The first match found is returned.
//	**
//	** When found, set *piTab and *piCol to the table index and column index
//	** of the matching column and return TRUE.
//	**
//	** If not found, return FALSE.
//	*/
func _tableAndColumnIndex(tls *libc.TLS, pSrc uintptr, iStart int32, iEnd int32, zCol uintptr, piTab uintptr, piCol uintptr, bIgnoreHidden int32) (r int32) {
	var i, iCol int32
	_, _ = i, iCol /* Index of column matching zCol */
	/* Both or neither are NULL */
	i = iStart
	for {
		if !(i <= iEnd) {
			break
		}
		iCol = _sqlite3ColumnIndex(tls, (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FpTab, zCol)
		if iCol >= 0 && (bIgnoreHidden == 0 || libc.BoolInt32(int32((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FpTab)).FaCol+uintptr(iCol)*12)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0) == 0) {
			if piTab != 0 {
				_sqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(i)*72, iCol)
				*(*int32)(unsafe.Pointer(piTab)) = i
				*(*int32)(unsafe.Pointer(piCol)) = iCol
			}
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Set the EP_OuterON property on all terms of the given expression.
//	** And set the Expr.w.iJoin to iTable for every term in the
//	** expression.
//	**
//	** The EP_OuterON property is used on terms of an expression to tell
//	** the OUTER JOIN processing logic that this term is part of the
//	** join restriction specified in the ON or USING clause and not a part
//	** of the more general WHERE clause.  These terms are moved over to the
//	** WHERE clause during join processing but we need to remember that they
//	** originated in the ON or USING clause.
//	**
//	** The Expr.w.iJoin tells the WHERE clause processing that the
//	** expression depends on table w.iJoin even if that table is not
//	** explicitly mentioned in the expression.  That information is needed
//	** for cases like this:
//	**
//	**    SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5
//	**
//	** The where clause needs to defer the handling of the t1.x=5
//	** term until after the t2 loop of the join.  In that way, a
//	** NULL t2 row will be inserted whenever t1.x!=5.  If we do not
//	** defer the handling of t1.x=5, it will be processed immediately
//	** after the t1 loop and rows with t1.x!=5 will never appear in
//	** the output, which is incorrect.
//	*/
func _sqlite3SetJoinExpr(tls *libc.TLS, p uintptr, iTable int32, joinFlag Tu32) {
	var i int32
	_ = i
	for p != 0 {
		*(*Tu32)(unsafe.Pointer(p + 4)) |= joinFlag
		*(*int32)(unsafe.Pointer(p + 36)) = iTable
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_FUNCTION) {
			if *(*uintptr)(unsafe.Pointer(p + 20)) != 0 {
				i = 0
				for {
					if !(i < (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)))).FnExpr) {
						break
					}
					_sqlite3SetJoinExpr(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)) + 8 + uintptr(i)*20))).FpExpr, iTable, joinFlag)
					goto _1
				_1:
					;
					i++
				}
			}
		}
		_sqlite3SetJoinExpr(tls, (*TExpr)(unsafe.Pointer(p)).FpLeft, iTable, joinFlag)
		p = (*TExpr)(unsafe.Pointer(p)).FpRight
	}
}

// C documentation
//
//	/* Undo the work of sqlite3SetJoinExpr().  This is used when a LEFT JOIN
//	** is simplified into an ordinary JOIN, and when an ON expression is
//	** "pushed down" into the WHERE clause of a subquery.
//	**
//	** Convert every term that is marked with EP_OuterON and w.iJoin==iTable into
//	** an ordinary term that omits the EP_OuterON mark.  Or if iTable<0, then
//	** just clear every EP_OuterON and EP_InnerON mark from the expression tree.
//	**
//	** If nullable is true, that means that Expr p might evaluate to NULL even
//	** if it is a reference to a NOT NULL column.  This can happen, for example,
//	** if the table that p references is on the left side of a RIGHT JOIN.
//	** If nullable is true, then take care to not remove the EP_CanBeNull bit.
//	** See forum thread https://sqlite.org/forum/forumpost/b40696f50145d21c
//	*/
func _unsetJoinExpr(tls *libc.TLS, p uintptr, iTable int32, nullable int32) {
	var i int32
	_ = i
	for p != 0 {
		if iTable < 0 || (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) && *(*int32)(unsafe.Pointer(p + 36)) == iTable {
			*(*Tu32)(unsafe.Pointer(p + 4)) &= uint32(^(libc.Int32FromInt32(EP_OuterON) | libc.Int32FromInt32(EP_InnerON)))
			if iTable >= 0 {
				*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(libc.Int32FromInt32(EP_InnerON))
			}
		}
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(p)).FiTable == iTable && !(nullable != 0) {
			*(*Tu32)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(EP_CanBeNull))
		}
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_FUNCTION) {
			if *(*uintptr)(unsafe.Pointer(p + 20)) != 0 {
				i = 0
				for {
					if !(i < (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)))).FnExpr) {
						break
					}
					_unsetJoinExpr(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)) + 8 + uintptr(i)*20))).FpExpr, iTable, nullable)
					goto _1
				_1:
					;
					i++
				}
			}
		}
		_unsetJoinExpr(tls, (*TExpr)(unsafe.Pointer(p)).FpLeft, iTable, nullable)
		p = (*TExpr)(unsafe.Pointer(p)).FpRight
	}
}

// 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*72
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc-int32(1)) {
			break
		}
		pRightTab = (*TSrcItem)(unsafe.Pointer(pRight)).FpTab
		if (*TSrcItem)(unsafe.Pointer(pLeft)).FpTab == uintptr(0) || pRightTab == uintptr(0) {
			goto _1
		}
		if int32((*TSrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&int32(JT_OUTER) != 0 {
			v2 = int32(EP_OuterON)
		} else {
			v2 = int32(EP_InnerON)
		}
		joinType = uint32(v2)
		/* If this is a NATURAL join, synthesize an appropriate USING clause
		 ** to specify which columns should be joined.
		 */
		if int32((*TSrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&int32(JT_NATURAL) != 0 {
			pUsing = uintptr(0)
			if int32(uint32(*(*uint16)(unsafe.Pointer(pRight + 36 + 4))&0x400>>10)) != 0 || *(*uintptr)(unsafe.Pointer(pRight + 48)) != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20376, 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 int32((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pRightTab)).FaCol+uintptr(j)*12)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
					goto _3
				}
				zName = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pRightTab)).FaCol + uintptr(j)*12))).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++
			}
			if pUsing != 0 {
				libc.SetBitFieldPtr16Uint32(pRight+36+4, libc.Uint32FromInt32(1), 10, 0x400)
				libc.SetBitFieldPtr16Uint32(pRight+36+4, libc.Uint32FromInt32(1), 12, 0x1000)
				*(*uintptr)(unsafe.Pointer(pRight + 48)) = 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(*(*uint16)(unsafe.Pointer(pRight + 36 + 4))&0x400>>10)) != 0 {
			pList = *(*uintptr)(unsafe.Pointer(pRight + 48))
			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(*(*uint16)(unsafe.Pointer(pRight + 36 + 4))&0x1000>>12))) == 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20426, libc.VaList(bp+16, zName1))
					return int32(1)
				}
				pE1 = _sqlite3CreateColumnExpr(tls, db, pSrc, *(*int32)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)))
				_sqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(*(*int32)(unsafe.Pointer(bp)))*72, *(*int32)(unsafe.Pointer(bp + 4)))
				if int32((*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 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() */
					for _tableAndColumnIndex(tls, pSrc, *(*int32)(unsafe.Pointer(bp))+int32(1), i, zName1, bp, bp+4, int32(uint32(*(*uint16)(unsafe.Pointer(pRight + 36 + 4))&0x1000>>12))) != 0 {
						if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(*(*int32)(unsafe.Pointer(bp)))*72 + 36 + 4))&0x400>>10)) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(*(*int32)(unsafe.Pointer(bp)))*72 + 48)), zName1) < 0 {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20490, libc.VaList(bp+16, zName1))
							break
						}
						pFuncArgs = _sqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
						pE1 = _sqlite3CreateColumnExpr(tls, db, pSrc, *(*int32)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)))
						_sqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(*(*int32)(unsafe.Pointer(bp)))*72, *(*int32)(unsafe.Pointer(bp + 4)))
					}
					if pFuncArgs != 0 {
						pFuncArgs = _sqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
						pE1 = _sqlite3ExprFunction(tls, pParse, pFuncArgs, uintptr(unsafe.Pointer(&_tkCoalesce)), 0)
					}
				}
				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)(unsafe.Pointer(pEq + 4)) |= joinType
					*(*int32)(unsafe.Pointer(pEq + 36)) = (*TExpr)(unsafe.Pointer(pE2)).FiTable
				}
				(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWhere, pEq)
				goto _4
			_4:
				;
				j++
			}
		} else {
			if *(*uintptr)(unsafe.Pointer(pRight + 48)) != 0 {
				_sqlite3SetJoinExpr(tls, *(*uintptr)(unsafe.Pointer(pRight + 48)), (*TSrcItem)(unsafe.Pointer(pRight)).FiCursor, joinType)
				(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWhere, *(*uintptr)(unsafe.Pointer(pRight + 48)))
				*(*uintptr)(unsafe.Pointer(pRight + 48)) = uintptr(0)
				libc.SetBitFieldPtr16Uint32(pRight+36+4, libc.Uint32FromInt32(1), 11, 0x800)
			}
		}
		goto _1
	_1:
		;
		i++
		pRight += 72
		pLeft += 72
	}
	return 0
}

var _tkCoalesce = TToken{
	Fz: __ccgo_ts + 8103,
	Fn: uint32(8),
}

// C documentation
//
//	/*
//	** An instance of this object holds information (beyond pParse and pSelect)
//	** needed to load the next result row that is to be added to the sorter.
//	*/
type TRowLoadInfo = struct {
	FregResult int32
	FecelFlags Tu8
}

type RowLoadInfo = TRowLoadInfo

type TRowLoadInfo1 = struct {
	FregResult int32
	FecelFlags Tu8
}

type RowLoadInfo1 = TRowLoadInfo1

// C documentation
//
//	/*
//	** This routine does the work of loading query data into an array of
//	** registers so that it can be added to the sorter.
//	*/
func _innerLoopLoadRow(tls *libc.TLS, pParse uintptr, pSelect uintptr, pInfo uintptr) {
	_sqlite3ExprCodeExprList(tls, pParse, (*TSelect)(unsafe.Pointer(pSelect)).FpEList, (*TRowLoadInfo)(unsafe.Pointer(pInfo)).FregResult, 0, (*TRowLoadInfo)(unsafe.Pointer(pInfo)).FecelFlags)
}

// C documentation
//
//	/*
//	** Code the OP_MakeRecord instruction that generates the entry to be
//	** added into the sorter.
//	**
//	** Return the register in which the result is stored.
//	*/
func _makeSorterRecord(tls *libc.TLS, pParse uintptr, pSort uintptr, pSelect uintptr, regBase int32, nBase int32) (r int32) {
	var nOBSat, regOut, v1 int32
	var v, v2 uintptr
	_, _, _, _, _ = nOBSat, regOut, v, v1, v2
	nOBSat = (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	v2 = pParse + 44
	*(*int32)(unsafe.Pointer(v2))++
	v1 = *(*int32)(unsafe.Pointer(v2))
	regOut = v1
	if (*TSortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad != 0 {
		_innerLoopLoadRow(tls, pParse, pSelect, (*TSortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad)
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regBase+nOBSat, nBase-nOBSat, regOut)
	return regOut
}

// C documentation
//
//	/*
//	** Generate code that will push the record in registers regData
//	** through regData+nData-1 onto the sorter.
//	*/
func _pushOntoSorter(tls *libc.TLS, pParse uintptr, pSort uintptr, pSelect uintptr, regData int32, regOrigData int32, nData int32, nPrefixReg int32) {
	var addrFirst, addrJmp, bSeq, iCsr, iLimit, iSkip, nBase, nExpr, nKey, nOBSat, op, regBase, regPrevKey, regRecord, v1, v2, v3, v5 int32
	var pKI, pOp, v, v4 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrFirst, addrJmp, bSeq, iCsr, iLimit, iSkip, nBase, nExpr, nKey, nOBSat, op, pKI, pOp, regBase, regPrevKey, regRecord, v, v1, v2, v3, v4, v5
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* Stmt under construction */
	bSeq = libc.BoolInt32(int32((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) == 0)
	nExpr = (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr /* No. of ORDER BY terms */
	nBase = nExpr + bSeq + nData                                                              /* Regs for sorter record */
	regRecord = 0                                                                             /* Assembled sorter record */
	nOBSat = (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat                                       /* LIMIT counter */
	iSkip = 0                                                                                 /* End of the sorter insert loop */
	/* Three cases:
	 **   (1) The data to be sorted has already been packed into a Record
	 **       by a prior OP_MakeRecord.  In this case nData==1 and regData
	 **       will be completely unrelated to regOrigData.
	 **   (2) All output columns are included in the sort record.  In that
	 **       case regData==regOrigData.
	 **   (3) Some output columns are omitted from the sort record due to
	 **       the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the
	 **       SQLITE_ECEL_OMITREF optimization, or due to the
	 **       SortCtx.pDeferredRowLoad optimization.  In any of these cases
	 **       regOrigData is 0 to prevent this routine from trying to copy
	 **       values that might not yet exist.
	 */
	if nPrefixReg != 0 {
		regBase = regData - nPrefixReg
	} else {
		regBase = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nBase
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FiOffset != 0 {
		v1 = (*TSelect)(unsafe.Pointer(pSelect)).FiOffset + int32(1)
	} else {
		v1 = (*TSelect)(unsafe.Pointer(pSelect)).FiLimit
	}
	iLimit = v1
	(*TSortCtx)(unsafe.Pointer(pSort)).FlabelDone = _sqlite3VdbeMakeLabel(tls, pParse)
	if regOrigData != 0 {
		v2 = int32(SQLITE_ECEL_REF)
	} else {
		v2 = 0
	}
	_sqlite3ExprCodeExprList(tls, pParse, (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy, regBase, regOrigData, uint8(int32(SQLITE_ECEL_DUP)|v2))
	if bSeq != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor, regBase+nExpr)
	}
	if nPrefixReg == 0 && nData > 0 {
		_sqlite3ExprCodeMove(tls, pParse, regData, regBase+nExpr+bSeq, nData)
	}
	if nOBSat > 0 { /* Original KeyInfo on the sorter table */
		regRecord = _makeSorterRecord(tls, pParse, pSort, pSelect, regBase, nBase)
		regPrevKey = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
		nKey = nExpr - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat + bSeq
		if bSeq != 0 {
			addrFirst = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regBase+nExpr)
		} else {
			addrFirst = _sqlite3VdbeAddOp1(tls, v, int32(OP_SequenceTest), (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Compare), regPrevKey, regBase, (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat)
		pOp = _sqlite3VdbeGetOp(tls, v, (*TSortCtx)(unsafe.Pointer(pSort)).FaddrSortIndex)
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
			return
		}
		(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = nKey + nData
		pKI = *(*uintptr)(unsafe.Pointer(pOp + 16))
		libc.Xmemset(tls, (*TKeyInfo)(unsafe.Pointer(pKI)).FaSortFlags, 0, uint32((*TKeyInfo)(unsafe.Pointer(pKI)).FnKeyField)) /* Makes OP_Jump testable */
		_sqlite3VdbeChangeP4(tls, v, -int32(1), pKI, -int32(8))
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = _sqlite3KeyInfoFromExprList(tls, pParse, (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy, nOBSat, int32((*TKeyInfo)(unsafe.Pointer(pKI)).FnAllField)-int32((*TKeyInfo)(unsafe.Pointer(pKI)).FnKeyField)-int32(1))
		pOp = uintptr(0) /* Ensure pOp not used after sqlite3VdbeAddOp3() */
		addrJmp = _sqlite3VdbeCurrentAddr(tls, v)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addrJmp+int32(1), 0, addrJmp+int32(1))
		(*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut = _sqlite3VdbeMakeLabel(tls, pParse)
		v4 = pParse + 44
		*(*int32)(unsafe.Pointer(v4))++
		v3 = *(*int32)(unsafe.Pointer(v4))
		(*TSortCtx)(unsafe.Pointer(pSort)).FregReturn = v3
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_ResetSorter), (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor)
		if iLimit != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), iLimit, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelDone)
		}
		_sqlite3VdbeJumpHere(tls, v, addrFirst)
		_sqlite3ExprCodeMove(tls, pParse, regBase, regPrevKey, (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat)
		_sqlite3VdbeJumpHere(tls, v, addrJmp)
	}
	if iLimit != 0 {
		/* At this point the values for the new sorter entry are stored
		 ** in an array of registers. They need to be composed into a record
		 ** and inserted into the sorter if either (a) there are currently
		 ** less than LIMIT+OFFSET items or (b) the new record is smaller than
		 ** the largest record currently in the sorter. If (b) is true and there
		 ** are already LIMIT+OFFSET items in the sorter, delete the largest
		 ** entry before inserting the new one. This way there are never more
		 ** than LIMIT+OFFSET items in the sorter.
		 **
		 ** If the new record does not need to be inserted into the sorter,
		 ** jump to the next iteration of the loop. If the pSort->labelOBLopt
		 ** value is not zero, then it is a label of where to jump.  Otherwise,
		 ** just bypass the row insert logic.  See the header comment on the
		 ** sqlite3WhereOrderByLimitOptLabel() function for additional info.
		 */
		iCsr = (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNotZero), iLimit, _sqlite3VdbeCurrentAddr(tls, v)+int32(4))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Last), iCsr, 0)
		iSkip = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxLE), iCsr, 0, regBase+nOBSat, nExpr-nOBSat)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iCsr)
	}
	if regRecord == 0 {
		regRecord = _makeSorterRecord(tls, pParse, pSort, pSelect, regBase, nBase)
	}
	if int32((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
		op = int32(OP_SorterInsert)
	} else {
		op = int32(OP_IdxInsert)
	}
	_sqlite3VdbeAddOp4Int(tls, v, op, (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor, regRecord, regBase+nOBSat, nBase-nOBSat)
	if iSkip != 0 {
		if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelOBLopt != 0 {
			v5 = (*TSortCtx)(unsafe.Pointer(pSort)).FlabelOBLopt
		} else {
			v5 = _sqlite3VdbeCurrentAddr(tls, v)
		}
		_sqlite3VdbeChangeP2(tls, v, iSkip, v5)
	}
}

// C documentation
//
//	/*
//	** Add code to implement the OFFSET
//	*/
func _codeOffset(tls *libc.TLS, v uintptr, iOffset int32, iContinue int32) {
	if iOffset > 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_IfPos), iOffset, iContinue, int32(1))
	}
}

// C documentation
//
//	/*
//	** Add code that will check to make sure the array of registers starting at
//	** iMem form a distinct entry. This is used by both "SELECT DISTINCT ..." and
//	** distinct aggregates ("SELECT count(DISTINCT <expr>) ..."). Three strategies
//	** are available. Which is used depends on the value of parameter eTnctType,
//	** as follows:
//	**
//	**   WHERE_DISTINCT_UNORDERED/WHERE_DISTINCT_NOOP:
//	**     Build an ephemeral table that contains all entries seen before and
//	**     skip entries which have been seen before.
//	**
//	**     Parameter iTab is the cursor number of an ephemeral table that must
//	**     be opened before the VM code generated by this routine is executed.
//	**     The ephemeral cursor table is queried for a record identical to the
//	**     record formed by the current array of registers. If one is found,
//	**     jump to VM address addrRepeat. Otherwise, insert a new record into
//	**     the ephemeral cursor and proceed.
//	**
//	**     The returned value in this case is a copy of parameter iTab.
//	**
//	**   WHERE_DISTINCT_ORDERED:
//	**     In this case rows are being delivered sorted order. The ephemeral
//	**     table is not required. Instead, the current set of values
//	**     is compared against previous row. If they match, the new row
//	**     is not distinct and control jumps to VM address addrRepeat. Otherwise,
//	**     the VM program proceeds with processing the new row.
//	**
//	**     The returned value in this case is the register number of the first
//	**     in an array of registers used to store the previous result row so that
//	**     it can be compared to the next. The caller must ensure that this
//	**     register is initialized to NULL.  (The fixDistinctOpenEph() routine
//	**     will take care of this initialization.)
//	**
//	**   WHERE_DISTINCT_UNIQUE:
//	**     In this case it has already been determined that the rows are distinct.
//	**     No special action is required. The return value is zero.
//	**
//	** Parameter pEList is the list of expressions used to generated the
//	** contents of each row. It is used by this routine to determine (a)
//	** how many elements there are in the array of registers and (b) the
//	** collation sequences that should be used for the comparisons if
//	** eTnctType is WHERE_DISTINCT_ORDERED.
//	*/
func _codeDistinct(tls *libc.TLS, pParse uintptr, eTnctType int32, iTab int32, addrRepeat int32, pEList uintptr, regElem int32) (r int32) {
	var i, iJump, iRet, nResultCol, r1, regPrev, v1 int32
	var pColl, v uintptr
	_, _, _, _, _, _, _, _, _ = i, iJump, iRet, nResultCol, pColl, r1, regPrev, v, v1
	iRet = 0
	nResultCol = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	switch eTnctType {
	case int32(WHERE_DISTINCT_ORDERED): /* Previous row content */
		/* Allocate space for the previous row */
		v1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + libc.Int32FromInt32(1)
		regPrev = v1
		iRet = v1
		*(*int32)(unsafe.Pointer(pParse + 44)) += nResultCol
		iJump = _sqlite3VdbeCurrentAddr(tls, v) + nResultCol
		i = 0
		for {
			if !(i < nResultCol) {
				break
			}
			pColl = _sqlite3ExprCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr)
			if i < nResultCol-int32(1) {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Ne), regElem+i, iJump, regPrev+i)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regElem+i, addrRepeat, regPrev+i)
			}
			_sqlite3VdbeChangeP4(tls, v, -int32(1), pColl, -int32(2))
			_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
			goto _2
		_2:
			;
			i++
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regElem, regPrev, nResultCol-int32(1))
	case int32(WHERE_DISTINCT_UNIQUE):
		/* nothing to do */
	default:
		r1 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iTab, addrRepeat, regElem, nResultCol)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regElem, nResultCol, r1)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iTab, r1, regElem, nResultCol)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
		_sqlite3ReleaseTempReg(tls, pParse, r1)
		iRet = iTab
		break
	}
	return iRet
}

// C documentation
//
//	/*
//	** This routine runs after codeDistinct().  It makes necessary
//	** adjustments to the OP_OpenEphemeral opcode that the codeDistinct()
//	** routine made use of.  This processing must be done separately since
//	** sometimes codeDistinct is called before the OP_OpenEphemeral is actually
//	** laid down.
//	**
//	** WHERE_DISTINCT_NOOP:
//	** WHERE_DISTINCT_UNORDERED:
//	**
//	**     No adjustments necessary.  This function is a no-op.
//	**
//	** WHERE_DISTINCT_UNIQUE:
//	**
//	**     The ephemeral table is not needed.  So change the
//	**     OP_OpenEphemeral opcode into an OP_Noop.
//	**
//	** WHERE_DISTINCT_ORDERED:
//	**
//	**     The ephemeral table is not needed.  But we do need register
//	**     iVal to be initialized to NULL.  So change the OP_OpenEphemeral
//	**     into an OP_Null on the iVal register.
//	*/
func _fixDistinctOpenEph(tls *libc.TLS, pParse uintptr, eTnctType int32, iVal int32, iOpenEphAddr int32) {
	var pOp, v uintptr
	_, _ = pOp, v
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 && (eTnctType == int32(WHERE_DISTINCT_UNIQUE) || eTnctType == int32(WHERE_DISTINCT_ORDERED)) {
		v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
		_sqlite3VdbeChangeToNoop(tls, v, iOpenEphAddr)
		if int32((*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, v, iOpenEphAddr+int32(1)))).Fopcode) == int32(OP_Explain) {
			_sqlite3VdbeChangeToNoop(tls, v, iOpenEphAddr+int32(1))
		}
		if eTnctType == int32(WHERE_DISTINCT_ORDERED) {
			/* Change the OP_OpenEphemeral to an OP_Null that sets the MEM_Cleared
			 ** bit on the first register of the previous value.  This will cause the
			 ** OP_Ne added in codeDistinct() to always fail on the first iteration of
			 ** the loop even if the first row is all NULLs.  */
			pOp = _sqlite3VdbeGetOp(tls, v, iOpenEphAddr)
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_Null)
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = int32(1)
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = iVal
		}
	}
}

// C documentation
//
//	/*
//	** This routine generates the code for the inside of the inner loop
//	** of a SELECT.
//	**
//	** If srcTab is negative, then the p->pEList expressions
//	** are evaluated in order to get the data for this row.  If srcTab is
//	** zero or more, then data is pulled from srcTab and p->pEList is used only
//	** to get the number of columns and the collation sequence for each column.
//	*/
func _selectInnerLoop(tls *libc.TLS, pParse uintptr, p uintptr, srcTab int32, pSort uintptr, pDistinct uintptr, pDest uintptr, iContinue int32, iBreak int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var addr, addrTest, eDest, eType, hasDistinct, i, i2, iParm, iTab, j, nKey, nPrefixReg, nResultCol, r1, r11, r12, r13, r14, r2, r21, r3, regOrig, regResult, v1, v2, v5 int32
	var ecelFlags Tu8
	var pEList, pSO, v uintptr
	var _ /* sRowLoadInfo at bp+0 */ TRowLoadInfo
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrTest, eDest, eType, ecelFlags, hasDistinct, i, i2, iParm, iTab, j, nKey, nPrefixReg, nResultCol, pEList, pSO, r1, r11, r12, r13, r14, r2, r21, r3, regOrig, regResult, v, v1, v2, v5
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                /* True if the DISTINCT keyword is present */
	eDest = int32((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) /* How to dispose of results */
	iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm      /* Number of result columns */
	nPrefixReg = 0                                              /* Start of memory holding full result (or 0) */
	if pDistinct != 0 {
		v1 = int32((*TDistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
	} else {
		v1 = WHERE_DISTINCT_NOOP
	}
	hasDistinct = v1
	if pSort != 0 && (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy == uintptr(0) {
		pSort = uintptr(0)
	}
	if pSort == uintptr(0) && !(hasDistinct != 0) {
		_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
	}
	/* Pull the requested columns.
	 */
	nResultCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
	if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
		if pSort != 0 {
			nPrefixReg = (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr
			if !(int32((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&libc.Int32FromInt32(SORTFLAG_UseSorter) != 0) {
				nPrefixReg++
			}
			*(*int32)(unsafe.Pointer(pParse + 44)) += nPrefixReg
		}
		(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nResultCol
	} else {
		if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst+nResultCol > (*TParse)(unsafe.Pointer(pParse)).FnMem {
			/* This is an error condition that can result, for example, when a SELECT
			 ** on the right-hand side of an INSERT contains more result columns than
			 ** there are columns in the table on the left.  The error will be caught
			 ** and reported later.  But we need to make sure enough memory is allocated
			 ** to avoid other spurious errors in the meantime. */
			*(*int32)(unsafe.Pointer(pParse + 44)) += nResultCol
		}
	}
	(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = nResultCol
	v2 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst
	regResult = v2
	regOrig = v2
	if srcTab >= 0 {
		i = 0
		for {
			if !(i < nResultCol) {
				break
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, i, regResult+i)
			goto _3
		_3:
			;
			i++
		}
	} else {
		if eDest != int32(SRT_Exists) {
			if eDest == int32(SRT_Mem) || eDest == int32(SRT_Output) || eDest == int32(SRT_Coroutine) {
				ecelFlags = uint8(SQLITE_ECEL_DUP)
			} else {
				ecelFlags = uint8(0)
			}
			if pSort != 0 && hasDistinct == 0 && eDest != int32(SRT_EphemTab) && eDest != int32(SRT_Table) {
				/* For each expression in p->pEList that is a copy of an expression in
				 ** the ORDER BY clause (pSort->pOrderBy), set the associated
				 ** iOrderByCol value to one more than the index of the ORDER BY
				 ** expression within the sort-key that pushOntoSorter() will generate.
				 ** This allows the p->pEList field to be omitted from the sorted record,
				 ** saving space and CPU cycles.  */
				ecelFlags = Tu8(int32(ecelFlags) | (libc.Int32FromInt32(SQLITE_ECEL_OMITREF) | libc.Int32FromInt32(SQLITE_ECEL_REF)))
				i = (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
				for {
					if !(i < (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr) {
						break
					}
					v5 = int32(*(*Tu16)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy + 8 + uintptr(i)*20 + 16)))
					j = v5
					if v5 > 0 {
						*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8 + uintptr(j-int32(1))*20 + 16)) = uint16(i + int32(1) - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat)
					}
					goto _4
				_4:
					;
					i++
				}
				/* Adjust nResultCol to account for columns that are omitted
				 ** from the sorter by the optimizations in this branch */
				pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
				i = 0
				for {
					if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
						break
					}
					if int32(*(*Tu16)(unsafe.Pointer(pEList + 8 + uintptr(i)*20 + 16))) > 0 {
						nResultCol--
						regOrig = 0
					}
					goto _6
				_6:
					;
					i++
				}
			}
			(*(*TRowLoadInfo)(unsafe.Pointer(bp))).FregResult = regResult
			(*(*TRowLoadInfo)(unsafe.Pointer(bp))).FecelFlags = ecelFlags
			if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 && int32(int32(ecelFlags))&int32(SQLITE_ECEL_OMITREF) != 0 && nPrefixReg > 0 {
				(*TSortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad = bp
				regOrig = 0
			} else {
				_innerLoopLoadRow(tls, pParse, p, bp)
			}
		}
	}
	/* If the DISTINCT keyword was present on the SELECT statement
	 ** and this row has been seen before, then do not make this row
	 ** part of the result.
	 */
	if hasDistinct != 0 {
		eType = int32((*TDistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
		iTab = (*TDistinctCtx)(unsafe.Pointer(pDistinct)).FtabTnct
		iTab = _codeDistinct(tls, pParse, eType, iTab, iContinue, (*TSelect)(unsafe.Pointer(p)).FpEList, regResult)
		_fixDistinctOpenEph(tls, pParse, eType, iTab, (*TDistinctCtx)(unsafe.Pointer(pDistinct)).FaddrTnct)
		if pSort == uintptr(0) {
			_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
		}
	}
	switch eDest {
	/* In this mode, write each query result to the key of the temporary
	 ** table iParm.
	 */
	case int32(SRT_Union):
		r1 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r1)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r1, regResult, nResultCol)
		_sqlite3ReleaseTempReg(tls, pParse, r1)
		break
		/* Construct a record from the query result, but instead of
		 ** saving that record, use it as a key to delete elements from
		 ** the temporary table iParm.
		 */
		fallthrough
	case int32(SRT_Except):
		_sqlite3VdbeAddOp3(tls, v, int32(OP_IdxDelete), iParm, regResult, nResultCol)
		break
		/* Store the result as data using a unique key.
		 */
		fallthrough
	case int32(SRT_Fifo):
		fallthrough
	case int32(SRT_DistFifo):
		fallthrough
	case int32(SRT_Table):
		fallthrough
	case int32(SRT_EphemTab):
		r11 = _sqlite3GetTempRange(tls, pParse, nPrefixReg+int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r11+nPrefixReg)
		if eDest == int32(SRT_DistFifo) {
			/* If the destination is DistFifo, then cursor (iParm+1) is open
			 ** on an ephemeral index. If the current row is already present
			 ** in the index, do not write it to the output. If not, add the
			 ** current row to the index and proceed with writing it to the
			 ** output table as well.  */
			addr = _sqlite3VdbeCurrentAddr(tls, v) + int32(4)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iParm+int32(1), addr, r11, 0)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm+int32(1), r11, regResult, nResultCol)
		}
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, r11+nPrefixReg, regOrig, int32(1), nPrefixReg)
		} else {
			r2 = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, r2)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r11, r2)
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
			_sqlite3ReleaseTempReg(tls, pParse, r2)
		}
		_sqlite3ReleaseTempRange(tls, pParse, r11, nPrefixReg+int32(1))
	case int32(SRT_Upfrom):
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
		} else {
			i2 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2
			r12 = _sqlite3GetTempReg(tls, pParse)
			/* If the UPDATE FROM join is an aggregate that matches no rows, it
			 ** might still be trying to return one row, because that is what
			 ** aggregates do.  Don't record that empty row in the output table. */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regResult, iBreak)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult+libc.BoolInt32(i2 < 0), nResultCol-libc.BoolInt32(i2 < 0), r12)
			if i2 < 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r12, regResult)
			} else {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r12, regResult, i2)
			}
		}
		break
		/* If we are creating a set for an "expr IN (SELECT ...)" construct,
		 ** then there should be a single item on the stack.  Write this
		 ** item into the set table with bogus data.
		 */
		fallthrough
	case int32(SRT_Set):
		if pSort != 0 {
			/* At first glance you would think we could optimize out the
			 ** ORDER BY in this case since the order of entries in the set
			 ** does not matter.  But there might be a LIMIT clause, in which
			 ** case the order does matter */
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
		} else {
			r13 = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r13, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nResultCol)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r13, regResult, nResultCol)
			_sqlite3ReleaseTempReg(tls, pParse, r13)
		}
		break
		/* If any row exist in the result set, record that fact and abort.
		 */
		fallthrough
	case int32(SRT_Exists):
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), iParm)
		/* The LIMIT clause will terminate the loop for us */
		break
		/* If this is a scalar select that is part of an expression, then
		 ** store the results in the appropriate memory cell or array of
		 ** memory cells and break out of the scan loop.
		 */
		fallthrough
	case int32(SRT_Mem):
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
		} else {
			/* The LIMIT clause will jump out of the loop for us */
		}
	case int32(SRT_Coroutine): /* Send data to a co-routine */
		fallthrough
	case int32(SRT_Output): /* Return the results */
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
		} else {
			if eDest == int32(SRT_Coroutine) {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), regResult, nResultCol)
			}
		}
		break
		/* Write the results into a priority queue that is order according to
		 ** pDest->pOrderBy (in pSO).  pDest->iSDParm (in iParm) is the cursor for an
		 ** index with pSO->nExpr+2 columns.  Build a key using pSO for the first
		 ** pSO->nExpr columns, then make sure all keys are unique by adding a
		 ** final OP_Sequence column.  The last column is the record as a blob.
		 */
		fallthrough
	case int32(SRT_DistQueue):
		fallthrough
	case int32(SRT_Queue):
		addrTest = 0
		pSO = (*TSelectDest)(unsafe.Pointer(pDest)).FpOrderBy
		nKey = (*TExprList)(unsafe.Pointer(pSO)).FnExpr
		r14 = _sqlite3GetTempReg(tls, pParse)
		r21 = _sqlite3GetTempRange(tls, pParse, nKey+int32(2))
		r3 = r21 + nKey + int32(1)
		if eDest == int32(SRT_DistQueue) {
			/* If the destination is DistQueue, then cursor (iParm+1) is open
			 ** on a second ephemeral index that holds all values every previously
			 ** added to the queue. */
			addrTest = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iParm+int32(1), 0, regResult, nResultCol)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r3)
		if eDest == int32(SRT_DistQueue) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iParm+int32(1), r3)
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
		}
		i = 0
		for {
			if !(i < nKey) {
				break
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), regResult+int32(*(*Tu16)(unsafe.Pointer(pSO + 8 + uintptr(i)*20 + 16)))-int32(1), r21+i)
			goto _7
		_7:
			;
			i++
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), iParm, r21+nKey)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r21, nKey+int32(2), r14)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r14, r21, nKey+int32(2))
		if addrTest != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrTest)
		}
		_sqlite3ReleaseTempReg(tls, pParse, r14)
		_sqlite3ReleaseTempRange(tls, pParse, r21, nKey+int32(2))
		break
		/* Discard the results.  This is used for SELECT statements inside
		 ** the body of a TRIGGER.  The purpose of such selects is to call
		 ** user-defined functions that have side effects.  We do not care
		 ** about the actual results of the select.
		 */
		fallthrough
	default:
		break
	}
	/* Jump to the end of the loop if the LIMIT is reached.  Except, if
	 ** there is a sorter, in which case the sorter has already limited
	 ** the output for us.
	 */
	if pSort == uintptr(0) && (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TSelect)(unsafe.Pointer(p)).FiLimit, iBreak)
	}
}

// C documentation
//
//	/*
//	** Allocate a KeyInfo object sufficient for an index of N key columns and
//	** X extra columns.
//	*/
func _sqlite3KeyInfoAlloc(tls *libc.TLS, db uintptr, N int32, X int32) (r uintptr) {
	var nExtra int32
	var p uintptr
	_, _ = nExtra, p
	nExtra = int32(uint32(N+X)*(libc.Uint32FromInt64(4)+libc.Uint32FromInt32(1)) - uint32(4))
	p = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(24)+uint32(uint32(nExtra))))
	if p != 0 {
		(*TKeyInfo)(unsafe.Pointer(p)).FaSortFlags = p + 20 + uintptr(N+X)*4
		(*TKeyInfo)(unsafe.Pointer(p)).FnKeyField = uint16(uint16(N))
		(*TKeyInfo)(unsafe.Pointer(p)).FnAllField = uint16(N + X)
		(*TKeyInfo)(unsafe.Pointer(p)).Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
		(*TKeyInfo)(unsafe.Pointer(p)).Fdb = db
		(*TKeyInfo)(unsafe.Pointer(p)).FnRef = uint32(1)
		libc.Xmemset(tls, p+1*24, 0, uint32(uint32(nExtra)))
	} else {
		return _sqlite3OomFault(tls, db)
	}
	return p
}

// C documentation
//
//	/*
//	** Deallocate a KeyInfo object
//	*/
func _sqlite3KeyInfoUnref(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*TKeyInfo)(unsafe.Pointer(p)).FnRef--
		if (*TKeyInfo)(unsafe.Pointer(p)).FnRef == uint32(0) {
			_sqlite3DbNNFreeNN(tls, (*TKeyInfo)(unsafe.Pointer(p)).Fdb, p)
		}
	}
}

// C documentation
//
//	/*
//	** Make a new pointer to a KeyInfo object
//	*/
func _sqlite3KeyInfoRef(tls *libc.TLS, p uintptr) (r uintptr) {
	if p != 0 {
		(*TKeyInfo)(unsafe.Pointer(p)).FnRef++
	}
	return p
}

// C documentation
//
//	/*
//	** Given an expression list, generate a KeyInfo structure that records
//	** the collating sequence for each expression in that expression list.
//	**
//	** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
//	** KeyInfo structure is appropriate for initializing a virtual index to
//	** implement that clause.  If the ExprList is the result set of a SELECT
//	** then the KeyInfo structure is appropriate for initializing a virtual
//	** index to implement a DISTINCT test.
//	**
//	** Space to hold the KeyInfo structure is obtained from malloc.  The calling
//	** function is responsible for seeing that this structure is eventually
//	** freed.
//	*/
func _sqlite3KeyInfoFromExprList(tls *libc.TLS, pParse uintptr, pList uintptr, iStart int32, nExtra int32) (r uintptr) {
	var db, pInfo, pItem uintptr
	var i, nExpr int32
	_, _, _, _, _ = db, i, nExpr, pInfo, pItem
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	nExpr = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	pInfo = _sqlite3KeyInfoAlloc(tls, db, nExpr-iStart, nExtra+int32(1))
	if pInfo != 0 {
		i = iStart
		pItem = pList + 8 + uintptr(iStart)*20
		for {
			if !(i < nExpr) {
				break
			}
			*(*uintptr)(unsafe.Pointer(pInfo + 20 + uintptr(i-iStart)*4)) = _sqlite3ExprNNCollSeq(tls, pParse, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pInfo)).FaSortFlags + uintptr(i-iStart))) = (*TExprList_item)(unsafe.Pointer(pItem)).Ffg.FsortFlags
			goto _1
		_1:
			;
			i++
			pItem += 20
		}
	}
	return pInfo
}

// C documentation
//
//	/*
//	** Name of the connection operator, used for error messages.
//	*/
func _sqlite3SelectOpName(tls *libc.TLS, id int32) (r uintptr) {
	var z uintptr
	_ = z
	switch id {
	case int32(TK_ALL):
		z = __ccgo_ts + 20527
	case int32(TK_INTERSECT):
		z = __ccgo_ts + 20537
	case int32(TK_EXCEPT):
		z = __ccgo_ts + 20547
	default:
		z = __ccgo_ts + 20554
		break
	}
	return z
}

// C documentation
//
//	/*
//	** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
//	** is a no-op. Otherwise, it adds a single row of output to the EQP result,
//	** where the caption is of the form:
//	**
//	**   "USE TEMP B-TREE FOR xxx"
//	**
//	** where xxx is one of "DISTINCT", "ORDER BY" or "GROUP BY". Exactly which
//	** is determined by the zUsage argument.
//	*/
func _explainTempTable(tls *libc.TLS, pParse uintptr, zUsage uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20560, libc.VaList(bp+8, zUsage))
}

/*
** Assign expression b to lvalue a. A second, no-op, version of this macro
** is provided when SQLITE_OMIT_EXPLAIN is defined. This allows the code
** in sqlite3Select() to assign values to structure member variables that
** only exist if SQLITE_OMIT_EXPLAIN is not defined without polluting the
** code with #ifndef directives.
 */

// C documentation
//
//	/*
//	** If the inner loop was generated using a non-null pOrderBy argument,
//	** then the results were placed in a sorter.  After the loop is terminated
//	** we need to run the sorter and output the results.  The following
//	** routine generates the code needed to do that.
//	*/
func _generateSortTail(tls *libc.TLS, pParse uintptr, p uintptr, pSort uintptr, nColumn int32, pDest uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aOutEx, pOrderBy, v, v1, v3, v5 uintptr
	var addr, addrBreak, addrContinue, addrOnce, bSeq, eDest, i, i2, iCol, iParm, iRead, iSortTab, iTab, nKey, nRefKey, r1, regRow, regRowid, regSortOut, v2, v4, v8 int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aOutEx, addr, addrBreak, addrContinue, addrOnce, bSeq, eDest, i, i2, iCol, iParm, iRead, iSortTab, iTab, nKey, nRefKey, pOrderBy, r1, regRow, regRowid, regSortOut, v, v1, v2, v3, v4, v5, v8
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe              /* The prepared statement */
	addrBreak = (*TSortCtx)(unsafe.Pointer(pSort)).FlabelDone /* Jump here to exit loop */
	addrContinue = _sqlite3VdbeMakeLabel(tls, pParse)         /* Top of output loop. Jump for Next. */
	addrOnce = 0
	pOrderBy = (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy
	eDest = int32((*TSelectDest)(unsafe.Pointer(pDest)).FeDest)
	iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm /* True if sorter record includes seq. no. */
	nRefKey = 0
	aOutEx = (*TSelect)(unsafe.Pointer(p)).FpEList + 8
	nKey = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
	if (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat == 0 || nKey == int32(1) {
		if (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat != 0 {
			v1 = __ccgo_ts + 20583
		} else {
			v1 = __ccgo_ts + 1672
		}
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20597, libc.VaList(bp+8, v1))
	} else {
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20628, libc.VaList(bp+8, nKey))
	}
	if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
		_sqlite3VdbeGoto(tls, v, addrBreak)
		_sqlite3VdbeResolveLabel(tls, v, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
	}
	iTab = (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor
	if eDest == int32(SRT_Output) || eDest == int32(SRT_Coroutine) || eDest == int32(SRT_Mem) {
		if eDest == int32(SRT_Mem) && (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst)
		}
		regRowid = 0
		regRow = (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst
	} else {
		regRowid = _sqlite3GetTempReg(tls, pParse)
		if eDest == int32(SRT_EphemTab) || eDest == int32(SRT_Table) {
			regRow = _sqlite3GetTempReg(tls, pParse)
			nColumn = 0
		} else {
			regRow = _sqlite3GetTempRange(tls, pParse, nColumn)
		}
	}
	if int32((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
		v3 = pParse + 44
		*(*int32)(unsafe.Pointer(v3))++
		v2 = *(*int32)(unsafe.Pointer(v3))
		regSortOut = v2
		v5 = pParse + 40
		v4 = *(*int32)(unsafe.Pointer(v5))
		*(*int32)(unsafe.Pointer(v5))++
		iSortTab = v4
		if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
			addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), iSortTab, regSortOut, nKey+int32(1)+nColumn+nRefKey)
		if addrOnce != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrOnce)
		}
		addr = int32(1) + _sqlite3VdbeAddOp2(tls, v, int32(OP_SorterSort), iTab, addrBreak)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SorterData), iTab, regSortOut, iSortTab)
		bSeq = 0
	} else {
		addr = int32(1) + _sqlite3VdbeAddOp2(tls, v, int32(OP_Sort), iTab, addrBreak)
		_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, addrContinue)
		iSortTab = iTab
		bSeq = int32(1)
		if (*TSelect)(unsafe.Pointer(p)).FiOffset > 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), (*TSelect)(unsafe.Pointer(p)).FiLimit, -int32(1))
		}
	}
	i = 0
	iCol = nKey + bSeq - libc.Int32FromInt32(1)
	for {
		if !(i < nColumn) {
			break
		}
		if int32(*(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*20 + 16))) == 0 {
			iCol++
		}
		goto _6
	_6:
		;
		i++
	}
	i = nColumn - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		if *(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*20 + 16)) != 0 {
			iRead = int32(*(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*20 + 16))) - int32(1)
		} else {
			v8 = iCol
			iCol--
			iRead = v8
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iSortTab, iRead, regRow+i)
		goto _7
	_7:
		;
		i--
	}
	switch eDest {
	case int32(SRT_Table):
		fallthrough
	case int32(SRT_EphemTab):
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iSortTab, nKey+bSeq, regRow)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, regRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, regRow, regRowid)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
	case int32(SRT_Set):
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regRow, nColumn, regRowid, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nColumn)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, regRowid, regRow, nColumn)
	case int32(SRT_Mem):
		/* The LIMIT clause will terminate the loop for us */
	case int32(SRT_Upfrom):
		i2 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2
		r1 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regRow+libc.BoolInt32(i2 < 0), nColumn-libc.BoolInt32(i2 < 0), r1)
		if i2 < 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r1, regRow)
		} else {
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r1, regRow, i2)
		}
	default:
		if eDest == int32(SRT_Output) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst, nColumn)
		} else {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
		}
		break
	}
	if regRowid != 0 {
		if eDest == int32(SRT_Set) {
			_sqlite3ReleaseTempRange(tls, pParse, regRow, nColumn)
		} else {
			_sqlite3ReleaseTempReg(tls, pParse, regRow)
		}
		_sqlite3ReleaseTempReg(tls, pParse, regRowid)
	}
	/* The bottom of the loop
	 */
	_sqlite3VdbeResolveLabel(tls, v, addrContinue)
	if int32((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterNext), iTab, addr)
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iTab, addr)
	}
	if (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn != 0 {
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn)
	}
	_sqlite3VdbeResolveLabel(tls, v, addrBreak)
}

// 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(96)
	defer tls.Free(96)
	var iCol, iDb, j int32
	var p, p1, pS, pS1, pTab, pTabList, zType uintptr
	var _ /* sNC at bp+12 */ TNameContext
	var _ /* sNC at bp+48 */ TNameContext
	var _ /* zOrigCol at bp+8 */ uintptr
	var _ /* zOrigDb at bp+0 */ uintptr
	var _ /* zOrigTab at bp+4 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = iCol, iDb, j, p, p1, pS, pS1, pTab, pTabList, zType
	zType = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	switch int32((*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)*72))).FiCursor != (*TExpr)(unsafe.Pointer(pExpr)).FiTable) {
					break
				}
				goto _1
			_1:
				;
				j++
			}
			if j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc {
				pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*72))).FpTab
				pS = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*72))).FpSelect
			} 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)*20))).FpExpr
				(*(*TNameContext)(unsafe.Pointer(bp + 12))).FpSrcList = (*TSelect)(unsafe.Pointer(pS)).FpSrc
				(*(*TNameContext)(unsafe.Pointer(bp + 12))).FpNext = pNC
				(*(*TNameContext)(unsafe.Pointer(bp + 12))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
				zType = _columnTypeImpl(tls, bp+12, p, bp, bp+4, bp+8)
			}
		} else {
			/* A real table or a CTE table */
			if iCol < 0 {
				iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
			}
			if iCol < 0 {
				zType = __ccgo_ts + 1146
				*(*uintptr)(unsafe.Pointer(bp + 8)) = __ccgo_ts + 18096
			} else {
				*(*uintptr)(unsafe.Pointer(bp + 8)) = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName
				zType = _sqlite3ColumnType(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*12, uintptr(0))
			}
			*(*uintptr)(unsafe.Pointer(bp + 4)) = (*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)(unsafe.Pointer(bp)) = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TNameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb)).FaDb + uintptr(iDb)*16))).FzDbSName
			}
		}
	case int32(TK_SELECT):
		pS1 = *(*uintptr)(unsafe.Pointer(pExpr + 20))
		p1 = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS1)).FpEList + 8))).FpExpr
		(*(*TNameContext)(unsafe.Pointer(bp + 48))).FpSrcList = (*TSelect)(unsafe.Pointer(pS1)).FpSrc
		(*(*TNameContext)(unsafe.Pointer(bp + 48))).FpNext = pNC
		(*(*TNameContext)(unsafe.Pointer(bp + 48))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
		zType = _columnTypeImpl(tls, bp+48, p1, bp, bp+4, bp+8)
		break
	}
	if pzOrigDb != 0 {
		*(*uintptr)(unsafe.Pointer(pzOrigDb)) = *(*uintptr)(unsafe.Pointer(bp))
		*(*uintptr)(unsafe.Pointer(pzOrigTab)) = *(*uintptr)(unsafe.Pointer(bp + 4))
		*(*uintptr)(unsafe.Pointer(pzOrigCol)) = *(*uintptr)(unsafe.Pointer(bp + 8))
	}
	return zType
}

// C documentation
//
//	/*
//	** Generate code that will tell the VDBE the declaration types of columns
//	** in the result set.
//	*/
func _generateColumnTypes(tls *libc.TLS, pParse uintptr, pTabList uintptr, pEList uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var p, v, zType uintptr
	var _ /* sNC at bp+0 */ TNameContext
	var _ /* zOrigCol at bp+44 */ uintptr
	var _ /* zOrigDb at bp+36 */ uintptr
	var _ /* zOrigTab at bp+40 */ uintptr
	_, _, _, _ = i, p, v, zType
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	(*(*TNameContext)(unsafe.Pointer(bp))).FpSrcList = pTabList
	(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TNameContext)(unsafe.Pointer(bp))).FpNext = uintptr(0)
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		p = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr
		*(*uintptr)(unsafe.Pointer(bp + 36)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 40)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 44)) = uintptr(0)
		zType = _columnTypeImpl(tls, bp, p, bp+36, bp+40, bp+44)
		/* The vdbe must make its own copy of the column-type and other
		 ** column specific strings, in case the schema is reset before this
		 ** virtual machine is deleted.
		 */
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_DATABASE), *(*uintptr)(unsafe.Pointer(bp + 36)), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_TABLE), *(*uintptr)(unsafe.Pointer(bp + 40)), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_COLUMN), *(*uintptr)(unsafe.Pointer(bp + 44)), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_DECLTYPE), zType, uintptr(-libc.Int32FromInt32(1)))
		goto _1
	_1:
		;
		i++
	}
}

// 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 (*TParse)(unsafe.Pointer(pParse)).FcolNamesSet != 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
	(*TParse)(unsafe.Pointer(pParse)).FcolNamesSet = uint8(1)
	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)*20))).FpExpr
		/* Agg processing has not run yet */
		/* Covering idx not yet coded */
		if (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FzEName != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME {
			/* An AS clause always takes first priority */
			zName = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FzEName
			_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName, uintptr(-libc.Int32FromInt32(1)))
		} else {
			if srcName != 0 && int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) {
				iCol = int32((*TExpr)(unsafe.Pointer(p)).FiColumn)
				pTab = (*TExpr)(unsafe.Pointer(p)).Fy.FpTab
				if iCol < 0 {
					iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
				}
				if iCol < 0 {
					zCol = __ccgo_ts + 18096
				} else {
					zCol = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName
				}
				if fullName != 0 {
					zName1 = uintptr(0)
					zName1 = _sqlite3MPrintf(tls, db, __ccgo_ts+13815, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol))
					_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName1, __ccgo_fp(_sqlite3OomClear))
				} else {
					_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zCol, uintptr(-libc.Int32FromInt32(1)))
				}
			} else {
				z = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FzEName
				if z == uintptr(0) {
					v2 = _sqlite3MPrintf(tls, db, __ccgo_ts+20674, libc.VaList(bp+8, i+int32(1)))
				} else {
					v2 = _sqlite3DbStrDup(tls, db, z)
				}
				z = v2
				_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, z, __ccgo_fp(_sqlite3OomClear))
			}
		}
		goto _1
	_1:
		;
		i++
	}
	_generateColumnTypes(tls, pParse, pTabList, pEList)
}

// 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, v4, p6, p9 uintptr
	var i, iCol, j, nCol, nName int32
	var v5 bool
	var v8 Tu32
	var _ /* cnt at bp+0 */ Tu32
	var _ /* ht at bp+4 */ THash
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCol, db, i, iCol, j, nCol, nName, pCol, pColExpr, pCollide, pTab, pX, zName, v2, v3, v4, v5, v8, p6, p9
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	_sqlite3HashInit(tls, bp+4)
	if pEList != 0 {
		nCol = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
		aCol = _sqlite3DbMallocZero(tls, db, uint64(uint32(12)*uint32(uint32(nCol))))
		if nCol > int32(32767) {
			nCol = int32(32767)
		}
	} else {
		nCol = 0
		aCol = uintptr(0)
	}
	*(*Ti16)(unsafe.Pointer(pnCol)) = int16(int16(nCol))
	*(*uintptr)(unsafe.Pointer(paCol)) = aCol
	i = 0
	pCol = aCol
	for {
		if !(i < nCol && !((*TParse)(unsafe.Pointer(pParse)).FnErr != 0)) {
			break
		}
		pX = pEList + 8 + uintptr(i)*20
		/* 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 + 8 + 4))&0x3>>0)) == 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) && int32((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_DOT) {
				pColExpr = (*TExpr)(unsafe.Pointer(pColExpr)).FpRight
			}
			if int32((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pColExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == uint32(0) && (*TExpr)(unsafe.Pointer(pColExpr)).Fy.FpTab != uintptr(0) {
				/* For columns use the column name name */
				iCol = int32((*TExpr)(unsafe.Pointer(pColExpr)).FiColumn)
				pTab = (*TExpr)(unsafe.Pointer(pColExpr)).Fy.FpTab
				if iCol < 0 {
					iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
				}
				if iCol >= 0 {
					v3 = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName
				} else {
					v3 = __ccgo_ts + 18096
				}
				zName = v3
			} else {
				if int32((*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+20674, libc.VaList(bp+32, 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)(unsafe.Pointer(bp)) = uint32(0)
		for {
			if v5 = zName != 0; v5 {
				v4 = _sqlite3HashFind(tls, bp+4, zName)
				pCollide = v4
			}
			if !(v5 && v4 != uintptr(0)) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pCollide + 8 + 4))&0x80>>7)) != 0 {
				p6 = pCol + 10
				*(*Tu16)(unsafe.Pointer(p6)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p6))) | libc.Int32FromInt32(COLFLAG_NOEXPAND))
			}
			nName = _sqlite3Strlen30(tls, zName)
			if nName > 0 {
				j = nName - int32(1)
				for {
					if !(j > 0 && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zName + uintptr(j))))])&int32(0x04) != 0) {
						break
					}
					goto _7
				_7:
					;
					j--
				}
				if int32(*(*int8)(unsafe.Pointer(zName + uintptr(j)))) == int32(':') {
					nName = j
				}
			}
			*(*Tu32)(unsafe.Pointer(bp))++
			v8 = *(*Tu32)(unsafe.Pointer(bp))
			zName = _sqlite3MPrintf(tls, db, __ccgo_ts+20683, libc.VaList(bp+32, nName, zName, v8))
			_sqlite3ProgressCheck(tls, pParse)
			if *(*Tu32)(unsafe.Pointer(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 + 8 + 4))&0x100>>8)) != 0 {
			p9 = pCol + 10
			*(*Tu16)(unsafe.Pointer(p9)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p9))) | libc.Int32FromInt32(COLFLAG_NOEXPAND))
		}
		if zName != 0 && _sqlite3HashInsert(tls, bp+4, zName, pX) == pX {
			_sqlite3OomFault(tls, db)
		}
		goto _1
	_1:
		;
		i++
		pCol += 12
	}
	_sqlite3HashClear(tls, bp+4)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		j = 0
		for {
			if !(j < i) {
				break
			}
			_sqlite3DbFree(tls, db, (*(*TColumn)(unsafe.Pointer(aCol + uintptr(j)*12))).FzCnName)
			goto _10
		_10:
			;
			j++
		}
		_sqlite3DbFree(tls, db, aCol)
		*(*uintptr)(unsafe.Pointer(paCol)) = uintptr(0)
		*(*Ti16)(unsafe.Pointer(pnCol)) = 0
		return (*TParse)(unsafe.Pointer(pParse)).Frc
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** pTab is a transient Table object that represents a subquery of some
//	** kind (maybe a parenthesized subquery in the FROM clause of a larger
//	** query, or a VIEW, or a CTE).  This routine computes type information
//	** for that Table object based on the Select object that implements the
//	** subquery.  For the purposes of this routine, "type information" means:
//	**
//	**    *   The datatype name, as it might appear in a CREATE TABLE statement
//	**    *   Which collating sequence to use for the column
//	**    *   The affinity of the column
//	*/
func _sqlite3SubqueryColumnTypes(tls *libc.TLS, pParse uintptr, pTab uintptr, pSelect uintptr, aff int8) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var a, db, p, pCol, pColl, pS2, zType, p4, p5 uintptr
	var i, j, m int32
	var k, n Ti64
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, db, i, j, k, m, n, p, pCol, pColl, pS2, zType, p4, p5
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 || int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		return
	}
	for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
	}
	a = (*TSelect)(unsafe.Pointer(pSelect)).FpEList + 8
	libc.Xmemset(tls, bp, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	i = 0
	pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		m = 0
		pS2 = pSelect
		*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(int32((*TColumn)(unsafe.Pointer(pCol)).FcolFlags) & libc.Int32FromInt32(COLFLAG_NOINSERT))
		p = (*(*TExprList_item)(unsafe.Pointer(a + uintptr(i)*20))).FpExpr
		/* pCol->szEst = ... // Column size est for SELECT tables never used */
		(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3ExprAffinity(tls, p)
		for int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) <= int32(SQLITE_AFF_NONE) && (*TSelect)(unsafe.Pointer(pS2)).FpNext != uintptr(0) {
			m |= _sqlite3ExprDataType(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS2)).FpEList + 8 + uintptr(i)*20))).FpExpr)
			pS2 = (*TSelect)(unsafe.Pointer(pS2)).FpNext
			(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS2)).FpEList + 8 + uintptr(i)*20))).FpExpr)
		}
		if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) <= int32(SQLITE_AFF_NONE) {
			(*TColumn)(unsafe.Pointer(pCol)).Faffinity = aff
		}
		if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) >= int32(SQLITE_AFF_TEXT) && ((*TSelect)(unsafe.Pointer(pS2)).FpNext != 0 || pS2 != pSelect) {
			pS2 = (*TSelect)(unsafe.Pointer(pS2)).FpNext
			for {
				if !(pS2 != 0) {
					break
				}
				m |= _sqlite3ExprDataType(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS2)).FpEList + 8 + uintptr(i)*20))).FpExpr)
				goto _2
			_2:
				;
				pS2 = (*TSelect)(unsafe.Pointer(pS2)).FpNext
			}
			if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) == int32(SQLITE_AFF_TEXT) && m&int32(0x01) != 0 {
				(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_BLOB)
			} else {
				if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) >= int32(SQLITE_AFF_NUMERIC) && m&int32(0x02) != 0 {
					(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_BLOB)
				}
			}
			if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) >= int32(SQLITE_AFF_NUMERIC) && int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_CAST) {
				(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_FLEXNUM)
			}
		}
		zType = _columnTypeImpl(tls, bp, p, uintptr(0), uintptr(0), uintptr(0))
		if zType == uintptr(0) || int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) != int32(_sqlite3AffinityType(tls, zType, uintptr(0))) {
			if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) == int32(SQLITE_AFF_NUMERIC) || int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) == int32(SQLITE_AFF_FLEXNUM) {
				zType = __ccgo_ts + 20691
			} else {
				zType = uintptr(0)
				j = int32(1)
				for {
					if !(j < int32(SQLITE_N_STDTYPE)) {
						break
					}
					if int32(_sqlite3StdTypeAffinity[j]) == int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) {
						zType = _sqlite3StdType[j]
						break
					}
					goto _3
				_3:
					;
					j++
				}
			}
		}
		if zType != 0 {
			k = int64(_sqlite3Strlen30(tls, zType))
			n = int64(_sqlite3Strlen30(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
			(*TColumn)(unsafe.Pointer(pCol)).FzCnName = _sqlite3DbReallocOrFree(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, uint64(n+k+int64(2)))
			p4 = pCol + 10
			*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) & ^(libc.Int32FromInt32(COLFLAG_HASTYPE) | libc.Int32FromInt32(COLFLAG_HASCOLL)))
			if (*TColumn)(unsafe.Pointer(pCol)).FzCnName != 0 {
				libc.Xmemcpy(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName+uintptr(n+int64(1)), zType, uint32(k+int64(1)))
				p5 = pCol + 10
				*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(COLFLAG_HASTYPE))
			}
		}
		pColl = _sqlite3ExprCollSeq(tls, pParse, p)
		if pColl != 0 {
			_sqlite3ColumnSetColl(tls, db, pCol, (*TCollSeq)(unsafe.Pointer(pColl)).FzName)
		}
		goto _1
	_1:
		;
		i++
		pCol += 12
	}
	(*TTable)(unsafe.Pointer(pTab)).FszTabRow = int16(1) /* Any non-zero value works */
}

// C documentation
//
//	/*
//	** Given a SELECT statement, generate a Table structure that describes
//	** the result set of that SELECT.
//	*/
func _sqlite3ResultSetOfSelect(tls *libc.TLS, pParse uintptr, pSelect uintptr, aff int8) (r uintptr) {
	var db, pTab uintptr
	var savedFlags Tu64
	_, _, _ = db, pTab, savedFlags
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	savedFlags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
	*(*Tu64)(unsafe.Pointer(db + 32)) &= ^libc.Uint64FromInt32(SQLITE_FullColNames)
	*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(SQLITE_ShortColNames)
	_sqlite3SelectPrep(tls, pParse, pSelect, uintptr(0))
	(*Tsqlite3)(unsafe.Pointer(db)).Fflags = savedFlags
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return uintptr(0)
	}
	for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
	}
	pTab = _sqlite3DbMallocZero(tls, db, uint64(64))
	if pTab == uintptr(0) {
		return uintptr(0)
	}
	(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
	(*TTable)(unsafe.Pointer(pTab)).FzName = uintptr(0)
	(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
	_sqlite3ColumnsFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(pSelect)).FpEList, pTab+34, pTab+4)
	_sqlite3SubqueryColumnTypes(tls, pParse, pTab, pSelect, aff)
	(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3DeleteTable(tls, db, pTab)
		return uintptr(0)
	}
	return pTab
}

// 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&uint32(libc.Int32FromInt32(SQLITE_FactorOutConst)) == uint32(0) {
		(*TParse)(unsafe.Pointer(pParse)).FokConstFactor = uint8(1)
	}
	return _sqlite3VdbeCreate(tls, pParse)
}

// C documentation
//
//	/*
//	** Compute the iLimit and iOffset fields of the SELECT based on the
//	** pLimit expressions.  pLimit->pLeft and pLimit->pRight hold the expressions
//	** that appear in the original SQL statement after the LIMIT and OFFSET
//	** keywords.  Or NULL if those keywords are omitted. iLimit and iOffset
//	** are the integer memory register numbers for counters used to compute
//	** the limit and offset.  If there is no limit and/or offset, then
//	** iLimit and iOffset are negative.
//	**
//	** This routine changes the values of iLimit and iOffset only if
//	** a limit or offset is defined by pLimit->pLeft and pLimit->pRight.  iLimit
//	** and iOffset should have been preset to appropriate default values (zero)
//	** prior to calling this routine.
//	**
//	** The iOffset register (if it exists) is initialized to the value
//	** of the OFFSET.  The iLimit register is initialized to LIMIT.  Register
//	** iOffset+1 is initialized to LIMIT+OFFSET.
//	**
//	** Only if pLimit->pLeft!=0 do the limit registers get
//	** redefined.  The UNION ALL operator uses this property to force
//	** the reuse of the same limit and offset registers across multiple
//	** SELECT statements.
//	*/
func _computeLimitRegisters(tls *libc.TLS, pParse uintptr, p uintptr, iBreak int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iLimit, iOffset, v1, v2, v4, v5 int32
	var pLimit, v, v3, v6 uintptr
	var _ /* n at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = iLimit, iOffset, pLimit, v, v1, v2, v3, v4, v5, v6
	v = uintptr(0)
	iLimit = 0
	pLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
	if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
		return
	}
	/*
	 ** "LIMIT -1" always shows all rows.  There is some
	 ** controversy about what the correct behavior should be.
	 ** The current implementation interprets "LIMIT 0" to mean
	 ** no rows.
	 */
	if pLimit != 0 {
		v3 = pParse + 44
		*(*int32)(unsafe.Pointer(v3))++
		v2 = *(*int32)(unsafe.Pointer(v3))
		v1 = v2
		iLimit = v1
		(*TSelect)(unsafe.Pointer(p)).FiLimit = v1
		v = _sqlite3GetVdbe(tls, pParse)
		if _sqlite3ExprIsInteger(tls, (*TExpr)(unsafe.Pointer(pLimit)).FpLeft, bp) != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), *(*int32)(unsafe.Pointer(bp)), iLimit)
			if *(*int32)(unsafe.Pointer(bp)) == 0 {
				_sqlite3VdbeGoto(tls, v, iBreak)
			} else {
				if *(*int32)(unsafe.Pointer(bp)) >= 0 && int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32(_sqlite3LogEst(tls, uint64(*(*int32)(unsafe.Pointer(bp))))) {
					(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEst(tls, uint64(*(*int32)(unsafe.Pointer(bp))))
					*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(SF_FixedLimit)
				}
			}
		} else {
			_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pLimit)).FpLeft, iLimit)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), iLimit)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), iLimit, iBreak)
		}
		if (*TExpr)(unsafe.Pointer(pLimit)).FpRight != 0 {
			v6 = pParse + 44
			*(*int32)(unsafe.Pointer(v6))++
			v5 = *(*int32)(unsafe.Pointer(v6))
			v4 = v5
			iOffset = v4
			(*TSelect)(unsafe.Pointer(p)).FiOffset = v4
			(*TParse)(unsafe.Pointer(pParse)).FnMem++ /* Allocate an extra register for limit+offset */
			_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pLimit)).FpRight, iOffset)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), iOffset)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_OffsetLimit), iLimit, iOffset+int32(1), iOffset)
		}
	}
}

// C documentation
//
//	/*
//	** Return the appropriate collating sequence for the iCol-th column of
//	** the result set for the compound-select statement "p".  Return NULL if
//	** the column has no default collating sequence.
//	**
//	** The collating sequence for the compound select is taken from the
//	** left-most term of the select that has a collating sequence.
//	*/
func _multiSelectCollSeq(tls *libc.TLS, pParse uintptr, p uintptr, iCol int32) (r uintptr) {
	var pRet uintptr
	_ = pRet
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		pRet = _multiSelectCollSeq(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpPrior, iCol)
	} else {
		pRet = uintptr(0)
	}
	/* iCol must be less than p->pEList->nExpr.  Otherwise an error would
	 ** have been thrown during name resolution and we would not have gotten
	 ** this far */
	if pRet == uintptr(0) && iCol < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr {
		pRet = _sqlite3ExprCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8 + uintptr(iCol)*20))).FpExpr)
	}
	return pRet
}

// C documentation
//
//	/*
//	** The select statement passed as the second parameter is a compound SELECT
//	** with an ORDER BY clause. This function allocates and returns a KeyInfo
//	** structure suitable for implementing the ORDER BY.
//	**
//	** Space to hold the KeyInfo structure is obtained from malloc. The calling
//	** function is responsible for ensuring that this structure is eventually
//	** freed.
//	*/
func _multiSelectOrderByKeyInfo(tls *libc.TLS, pParse uintptr, p uintptr, nExtra int32) (r uintptr) {
	var db, pColl, pItem, pOrderBy, pRet, pTerm uintptr
	var i, nOrderBy, v1 int32
	_, _, _, _, _, _, _, _, _ = db, i, nOrderBy, pColl, pItem, pOrderBy, pRet, pTerm, v1
	pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
	if pOrderBy != uintptr(0) {
		v1 = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
	} else {
		v1 = 0
	}
	nOrderBy = v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pRet = _sqlite3KeyInfoAlloc(tls, db, nOrderBy+nExtra, int32(1))
	if pRet != 0 {
		i = 0
		for {
			if !(i < nOrderBy) {
				break
			}
			pItem = pOrderBy + 8 + uintptr(i)*20
			pTerm = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
			if (*TExpr)(unsafe.Pointer(pTerm)).Fflags&uint32(EP_Collate) != 0 {
				pColl = _sqlite3ExprCollSeq(tls, pParse, pTerm)
			} else {
				pColl = _multiSelectCollSeq(tls, pParse, p, int32((*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem + 16))).FiOrderByCol)-int32(1))
				if pColl == uintptr(0) {
					pColl = (*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl
				}
				(*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).FpExpr = _sqlite3ExprAddCollateString(tls, pParse, pTerm, (*TCollSeq)(unsafe.Pointer(pColl)).FzName)
			}
			*(*uintptr)(unsafe.Pointer(pRet + 20 + uintptr(i)*4)) = pColl
			*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pRet)).FaSortFlags + uintptr(i))) = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).Ffg.FsortFlags
			goto _2
		_2:
			;
			i++
		}
	}
	return pRet
}

// 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(32)
	defer tls.Free(32)
	var addrBreak, addrCont, addrTop, eDest, i, iCurrent, iDistinct, iQueue, nCol, rc, regCurrent, regLimit, regOffset, v1, v3, v5, v6, v8, v9 int32
	var pFirstRec, pKeyInfo, pLimit, pOrderBy, pSetup, pSrc, v, v10, v4, v7 uintptr
	var _ /* destQueue at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrBreak, addrCont, addrTop, eDest, i, iCurrent, iDistinct, iQueue, nCol, pFirstRec, pKeyInfo, pLimit, pOrderBy, pSetup, pSrc, rc, regCurrent, regLimit, regOffset, v, v1, v10, v3, v4, v5, v6, v7, v8, v9
	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+20695, 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(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 36 + 4))&0x40>>6)) != 0 {
			iCurrent = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FiCursor
			break
		}
		goto _2
	_2:
		;
		i++
	}
	/* 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 + 40
	v3 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4))++
	iQueue = v3
	if int32((*TSelect)(unsafe.Pointer(p)).Fop) == int32(TK_UNION) {
		if pOrderBy != 0 {
			v5 = int32(SRT_DistQueue)
		} else {
			v5 = int32(SRT_DistFifo)
		}
		eDest = v5
		v7 = pParse + 40
		v6 = *(*int32)(unsafe.Pointer(v7))
		*(*int32)(unsafe.Pointer(v7))++
		iDistinct = v6
	} else {
		if pOrderBy != 0 {
			v8 = int32(SRT_Queue)
		} else {
			v8 = int32(SRT_Fifo)
		}
		eDest = v8
	}
	_sqlite3SelectDestInit(tls, bp, eDest, iQueue)
	/* Allocate cursors for Current, Queue, and Distinct. */
	v10 = pParse + 44
	*(*int32)(unsafe.Pointer(v10))++
	v9 = *(*int32)(unsafe.Pointer(v10))
	regCurrent = v9
	_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), iCurrent, regCurrent, nCol)
	if pOrderBy != 0 {
		pKeyInfo = _multiSelectOrderByKeyInfo(tls, pParse, p, int32(1))
		_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), iQueue, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr+int32(2), 0, pKeyInfo, -int32(8))
		(*(*TSelectDest)(unsafe.Pointer(bp))).FpOrderBy = pOrderBy
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iQueue, nCol)
	}
	if iDistinct != 0 {
		*(*int32)(unsafe.Pointer(p + 20)) = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iDistinct, 0)
		*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(SF_UsesEphemeral)
	}
	/* 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+20744, 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 _11
	_11:
		;
		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+20786, 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+20792, 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
//
//	/*
//	** Handle the special case of a compound-select that originates from a
//	** VALUES clause.  By handling this as a special case, we avoid deep
//	** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
//	** on a VALUES clause.
//	**
//	** Because the Select object originates from a VALUES clause:
//	**   (1) There is no LIMIT or OFFSET or else there is a LIMIT of exactly 1
//	**   (2) All terms are UNION ALL
//	**   (3) There is no ORDER BY clause
//	**
//	** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES
//	** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))").
//	** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
//	** Since the limit is exactly 1, we only need to evaluate the left-most VALUES.
//	*/
func _multiSelectValues(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bShowAll, nRow, rc int32
	var v1 uintptr
	_, _, _, _ = bShowAll, nRow, rc, v1
	nRow = int32(1)
	rc = 0
	bShowAll = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FpLimit == uintptr(0))
	for cond := true; cond; cond = int32(1) != 0 {
		if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 {
			return -int32(1)
		}
		if (*TSelect)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
			break
		}
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
		nRow += bShowAll
	}
	if nRow == int32(1) {
		v1 = __ccgo_ts + 1672
	} else {
		v1 = __ccgo_ts + 20807
	}
	_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20809, libc.VaList(bp+8, nRow, v1))
	for p != 0 {
		_selectInnerLoop(tls, pParse, p, -int32(1), uintptr(0), uintptr(0), pDest, int32(1), int32(1))
		if !(bShowAll != 0) {
			break
		}
		(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(int16(nRow))
		p = (*TSelect)(unsafe.Pointer(p)).FpNext
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if the SELECT statement which is known to be the recursive
//	** part of a recursive CTE still has its anchor terms attached.  If the
//	** anchor terms have already been removed, then return false.
//	*/
func _hasAnchor(tls *libc.TLS, p uintptr) (r int32) {
	for p != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Recursive) != uint32(0) {
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
	}
	return libc.BoolInt32(p != uintptr(0))
}

// C documentation
//
//	/*
//	** This routine is called to process a compound query form from
//	** two or more separate queries using UNION, UNION ALL, EXCEPT, or
//	** INTERSECT
//	**
//	** "p" points to the right-most of the two queries.  the query on the
//	** left is p->pPrior.  The left query could also be a compound query
//	** in which case this routine will be called recursively.
//	**
//	** The results of the total query are to be written into a destination
//	** of type eDest with parameter iParm.
//	**
//	** Example 1:  Consider a three-way compound SQL statement.
//	**
//	**     SELECT a FROM t1 UNION SELECT b FROM t2 UNION SELECT c FROM t3
//	**
//	** This statement is parsed up as follows:
//	**
//	**     SELECT c FROM t3
//	**      |
//	**      `----->  SELECT b FROM t2
//	**                |
//	**                `------>  SELECT a FROM t1
//	**
//	** The arrows in the diagram above represent the Select.pPrior pointer.
//	** So if this routine is called with p equal to the t3 query, then
//	** pPrior will be the t2 query.  p->op will be TK_UNION in this case.
//	**
//	** Notice that because of the way SQLite parses compound SELECTs, the
//	** individual selects always group from left to right.
//	*/
func _multiSelect(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var addr, addr1, addr2, addr3, i, iBreak, iBreak1, iCont, iCont1, iStart, iStart1, nCol, priorOp, r1, rc, tab1, tab2, unionTab, v1, v3, v5 int32
	var apColl, db, pDelete, pKeyInfo, pLimit, pLimit1, pLoop, pPrior, v, v2, v4, v6 uintptr
	var op Tu8
	var _ /* dest at bp+0 */ TSelectDest
	var _ /* intersectdest at bp+60 */ TSelectDest
	var _ /* nLimit at bp+28 */ int32
	var _ /* uniondest at bp+32 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addr1, addr2, addr3, apColl, db, i, iBreak, iBreak1, iCont, iCont1, iStart, iStart1, nCol, op, pDelete, pKeyInfo, pLimit, pLimit1, pLoop, pPrior, priorOp, r1, rc, tab1, tab2, unionTab, v, v1, v2, v3, v4, v5, v6
	rc = SQLITE_OK       /* Alternative data destination */
	pDelete = uintptr(0) /* Database connection */
	/* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs.  Only
	 ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
	 */
	/* Calling function guarantees this much */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pPrior = (*TSelect)(unsafe.Pointer(p)).FpPrior
	*(*TSelectDest)(unsafe.Pointer(bp)) = *(*TSelectDest)(unsafe.Pointer(pDest))
	v = _sqlite3GetVdbe(tls, pParse)
	/* The VDBE already created by calling function */
	/* Create the destination temporary table if necessary
	 */
	if int32((*(*TSelectDest)(unsafe.Pointer(bp))).FeDest) == int32(SRT_EphemTab) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr)
		(*(*TSelectDest)(unsafe.Pointer(bp))).FeDest = uint8(SRT_Table)
	}
	/* Special handling for a compound-select that originates as a VALUES clause.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_MultiValue) != 0 {
		rc = _multiSelectValues(tls, pParse, p, bp)
		if rc >= 0 {
			goto multi_select_end
		}
		rc = SQLITE_OK
	}
	/* Make sure all SELECTs in the statement have the same number of elements
	 ** in their result sets.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Recursive) != uint32(0) && _hasAnchor(tls, p) != 0 {
		_generateWithRecursiveQuery(tls, pParse, p, bp)
	} else {
		/* Compound SELECTs that have an ORDER BY clause are handled separately.
		 */
		if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
			return _multiSelectOrderBy(tls, pParse, p, pDest)
		} else {
			if (*TSelect)(unsafe.Pointer(pPrior)).FpPrior == uintptr(0) {
				_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20832, 0)
				_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20847, 0)
			}
			/* Generate code for the left and right SELECT statements.
			 */
			switch int32((*TSelect)(unsafe.Pointer(p)).Fop) {
			case int32(TK_ALL):
				addr = 0
				*(*int32)(unsafe.Pointer(bp + 28)) = 0 /* Initialize to suppress harmless compiler warning */
				(*TSelect)(unsafe.Pointer(pPrior)).FiLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
				(*TSelect)(unsafe.Pointer(pPrior)).FiOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
				(*TSelect)(unsafe.Pointer(pPrior)).FpLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
				rc = _sqlite3Select(tls, pParse, pPrior, bp)
				(*TSelect)(unsafe.Pointer(pPrior)).FpLimit = uintptr(0)
				if rc != 0 {
					goto multi_select_end
				}
				(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
				(*TSelect)(unsafe.Pointer(p)).FiLimit = (*TSelect)(unsafe.Pointer(pPrior)).FiLimit
				(*TSelect)(unsafe.Pointer(p)).FiOffset = (*TSelect)(unsafe.Pointer(pPrior)).FiOffset
				if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
					addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), (*TSelect)(unsafe.Pointer(p)).FiLimit)
					if (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_OffsetLimit), (*TSelect)(unsafe.Pointer(p)).FiLimit, (*TSelect)(unsafe.Pointer(p)).FiOffset+int32(1), (*TSelect)(unsafe.Pointer(p)).FiOffset)
					}
				}
				_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20527, 0)
				rc = _sqlite3Select(tls, pParse, p, bp)
				pDelete = (*TSelect)(unsafe.Pointer(p)).FpPrior
				(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
				(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEstAdd(tls, (*TSelect)(unsafe.Pointer(p)).FnSelectRow, (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow)
				if (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 && _sqlite3ExprIsInteger(tls, (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpLimit)).FpLeft, bp+28) != 0 && *(*int32)(unsafe.Pointer(bp + 28)) > 0 && int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32(_sqlite3LogEst(tls, uint64(*(*int32)(unsafe.Pointer(bp + 28))))) {
					(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEst(tls, uint64(*(*int32)(unsafe.Pointer(bp + 28))))
				}
				if addr != 0 {
					_sqlite3VdbeJumpHere(tls, v, addr)
				}
			case int32(TK_EXCEPT):
				fallthrough
			case int32(TK_UNION): /* Cursor number of the temp table holding result */
				op = uint8(0)
				priorOp = int32(SRT_Union)
				if int32((*(*TSelectDest)(unsafe.Pointer(bp))).FeDest) == priorOp {
					/* We can reuse a temporary table generated by a SELECT to our
					 ** right.
					 */
					/* Not allowed on leftward elements */
					unionTab = (*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm
				} else {
					/* We will need to create our own temporary table to hold the
					 ** intermediate results.
					 */
					v2 = pParse + 40
					v1 = *(*int32)(unsafe.Pointer(v2))
					*(*int32)(unsafe.Pointer(v2))++
					unionTab = v1
					addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), unionTab, 0)
					*(*int32)(unsafe.Pointer(p + 20)) = addr1
					*(*Tu32)(unsafe.Pointer(_findRightmost(tls, p) + 4)) |= uint32(SF_UsesEphemeral)
				}
				/* Code the SELECT statements to our left
				 */
				_sqlite3SelectDestInit(tls, bp+32, priorOp, unionTab)
				rc = _sqlite3Select(tls, pParse, pPrior, bp+32)
				if rc != 0 {
					goto multi_select_end
				}
				/* Code the current SELECT statement
				 */
				if int32((*TSelect)(unsafe.Pointer(p)).Fop) == int32(TK_EXCEPT) {
					op = uint8(SRT_Except)
				} else {
					op = uint8(SRT_Union)
				}
				(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
				pLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
				(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
				(*(*TSelectDest)(unsafe.Pointer(bp + 32))).FeDest = op
				_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20866, libc.VaList(bp+96, _sqlite3SelectOpName(tls, int32((*TSelect)(unsafe.Pointer(p)).Fop))))
				rc = _sqlite3Select(tls, pParse, p, bp+32)
				pDelete = (*TSelect)(unsafe.Pointer(p)).FpPrior
				(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
				(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
				if int32((*TSelect)(unsafe.Pointer(p)).Fop) == int32(TK_UNION) {
					(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEstAdd(tls, (*TSelect)(unsafe.Pointer(p)).FnSelectRow, (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow)
				}
				_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit)
				(*TSelect)(unsafe.Pointer(p)).FpLimit = pLimit
				(*TSelect)(unsafe.Pointer(p)).FiLimit = 0
				(*TSelect)(unsafe.Pointer(p)).FiOffset = 0
				/* Convert the data in the temporary table into whatever form
				 ** it is that we currently need.
				 */
				if int32((*(*TSelectDest)(unsafe.Pointer(bp))).FeDest) != priorOp && int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
					iBreak = _sqlite3VdbeMakeLabel(tls, pParse)
					iCont = _sqlite3VdbeMakeLabel(tls, pParse)
					_computeLimitRegisters(tls, pParse, p, iBreak)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), unionTab, iBreak)
					iStart = _sqlite3VdbeCurrentAddr(tls, v)
					_selectInnerLoop(tls, pParse, p, unionTab, uintptr(0), uintptr(0), bp, iCont, iBreak)
					_sqlite3VdbeResolveLabel(tls, v, iCont)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), unionTab, iStart)
					_sqlite3VdbeResolveLabel(tls, v, iBreak)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), unionTab, 0)
				}
			default:
				/* INTERSECT is different from the others since it requires
				 ** two temporary tables.  Hence it has its own case.  Begin
				 ** by allocating the tables we will need.
				 */
				v4 = pParse + 40
				v3 = *(*int32)(unsafe.Pointer(v4))
				*(*int32)(unsafe.Pointer(v4))++
				tab1 = v3
				v6 = pParse + 40
				v5 = *(*int32)(unsafe.Pointer(v6))
				*(*int32)(unsafe.Pointer(v6))++
				tab2 = v5
				addr2 = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), tab1, 0)
				*(*int32)(unsafe.Pointer(p + 20)) = addr2
				*(*Tu32)(unsafe.Pointer(_findRightmost(tls, p) + 4)) |= uint32(SF_UsesEphemeral)
				/* Code the SELECTs to our left into temporary table "tab1".
				 */
				_sqlite3SelectDestInit(tls, bp+60, int32(SRT_Union), tab1)
				rc = _sqlite3Select(tls, pParse, pPrior, bp+60)
				if rc != 0 {
					goto multi_select_end
				}
				/* Code the current SELECT into temporary table "tab2"
				 */
				addr2 = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), tab2, 0)
				*(*int32)(unsafe.Pointer(p + 20 + 1*4)) = addr2
				(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
				pLimit1 = (*TSelect)(unsafe.Pointer(p)).FpLimit
				(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
				(*(*TSelectDest)(unsafe.Pointer(bp + 60))).FiSDParm = tab2
				_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20866, libc.VaList(bp+96, _sqlite3SelectOpName(tls, int32((*TSelect)(unsafe.Pointer(p)).Fop))))
				rc = _sqlite3Select(tls, pParse, p, bp+60)
				pDelete = (*TSelect)(unsafe.Pointer(p)).FpPrior
				(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
				if int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32((*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow) {
					(*TSelect)(unsafe.Pointer(p)).FnSelectRow = (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow
				}
				_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit)
				(*TSelect)(unsafe.Pointer(p)).FpLimit = pLimit1
				/* Generate code to take the intersection of the two temporary
				 ** tables.
				 */
				if rc != 0 {
					break
				}
				iBreak1 = _sqlite3VdbeMakeLabel(tls, pParse)
				iCont1 = _sqlite3VdbeMakeLabel(tls, pParse)
				_computeLimitRegisters(tls, pParse, p, iBreak1)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), tab1, iBreak1)
				r1 = _sqlite3GetTempReg(tls, pParse)
				iStart1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), tab1, r1)
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), tab2, iCont1, r1, 0)
				_sqlite3ReleaseTempReg(tls, pParse, r1)
				_selectInnerLoop(tls, pParse, p, tab1, uintptr(0), uintptr(0), bp, iCont1, iBreak1)
				_sqlite3VdbeResolveLabel(tls, v, iCont1)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), tab1, iStart1)
				_sqlite3VdbeResolveLabel(tls, v, iBreak1)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), tab2, 0)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), tab1, 0)
				break
			}
			if (*TSelect)(unsafe.Pointer(p)).FpNext == uintptr(0) {
				_sqlite3VdbeExplainPop(tls, pParse)
			}
		}
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto multi_select_end
	}
	/* Compute collating sequences used by
	 ** temporary tables needed to implement the compound select.
	 ** Attach the KeyInfo structure to all temporary tables.
	 **
	 ** This section is run by the right-most SELECT statement only.
	 ** SELECT statements to the left always skip this part.  The right-most
	 ** SELECT might also skip this part if it has no ORDER BY clause and
	 ** no temp tables are required.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_UsesEphemeral) != 0 { /* Number of columns in result set */
		nCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
		pKeyInfo = _sqlite3KeyInfoAlloc(tls, db, nCol, int32(1))
		if !(pKeyInfo != 0) {
			rc = int32(SQLITE_NOMEM)
			goto multi_select_end
		}
		i = 0
		apColl = pKeyInfo + 20
		for {
			if !(i < nCol) {
				break
			}
			*(*uintptr)(unsafe.Pointer(apColl)) = _multiSelectCollSeq(tls, pParse, p, i)
			if uintptr(0) == *(*uintptr)(unsafe.Pointer(apColl)) {
				*(*uintptr)(unsafe.Pointer(apColl)) = (*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl
			}
			goto _7
		_7:
			;
			i++
			apColl += 4
		}
		pLoop = p
		for {
			if !(pLoop != 0) {
				break
			}
			i = 0
			for {
				if !(i < int32(2)) {
					break
				}
				addr3 = *(*int32)(unsafe.Pointer(pLoop + 20 + uintptr(i)*4))
				if addr3 < 0 {
					/* If [0] is unused then [1] is also unused.  So we can
					 ** always safely abort as soon as the first unused slot is found */
					break
				}
				_sqlite3VdbeChangeP2(tls, v, addr3, nCol)
				_sqlite3VdbeChangeP4(tls, v, addr3, _sqlite3KeyInfoRef(tls, pKeyInfo), -int32(8))
				*(*int32)(unsafe.Pointer(pLoop + 20 + uintptr(i)*4)) = -int32(1)
				goto _9
			_9:
				;
				i++
			}
			goto _8
		_8:
			;
			pLoop = (*TSelect)(unsafe.Pointer(pLoop)).FpPrior
		}
		_sqlite3KeyInfoUnref(tls, pKeyInfo)
	}
	goto multi_select_end
multi_select_end:
	;
	(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = (*(*TSelectDest)(unsafe.Pointer(bp))).FiSdst
	(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = (*(*TSelectDest)(unsafe.Pointer(bp))).FnSdst
	if pDelete != 0 {
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), pDelete)
	}
	return rc
}

// C documentation
//
//	/*
//	** Error message for when two or more terms of a compound select have different
//	** size result sets.
//	*/
func _sqlite3SelectWrongNumTermsError(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Values) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20887, 0)
	} else {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20933, libc.VaList(bp+8, _sqlite3SelectOpName(tls, int32((*TSelect)(unsafe.Pointer(p)).Fop))))
	}
}

// C documentation
//
//	/*
//	** Code an output subroutine for a coroutine implementation of a
//	** SELECT statement.
//	**
//	** The data to be output is contained in pIn->iSdst.  There are
//	** pIn->nSdst columns to be output.  pDest is where the output should
//	** be sent.
//	**
//	** regReturn is the number of the register holding the subroutine
//	** return address.
//	**
//	** If regPrev>0 then it is the first register in a vector that
//	** records the previous output.  mem[regPrev] is a flag that is false
//	** if there has been no previous output.  If regPrev>0 then code is
//	** generated to suppress duplicates.  pKeyInfo is used for comparing
//	** keys.
//	**
//	** If the LIMIT found in p->iLimit is reached, jump immediately to
//	** iBreak.
//	*/
func _generateOutputSubroutine(tls *libc.TLS, pParse uintptr, p uintptr, pIn uintptr, pDest uintptr, regReturn int32, regPrev int32, pKeyInfo uintptr, iBreak int32) (r int32) {
	var addr, addr1, addr2, iContinue, r1, r11, r2 int32
	var v uintptr
	_, _, _, _, _, _, _, _ = addr, addr1, addr2, iContinue, r1, r11, r2, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	addr = _sqlite3VdbeCurrentAddr(tls, v)
	iContinue = _sqlite3VdbeMakeLabel(tls, pParse)
	/* Suppress duplicates for UNION, EXCEPT, and INTERSECT
	 */
	if regPrev != 0 {
		addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regPrev)
		addr2 = _sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+int32(1), (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, _sqlite3KeyInfoRef(tls, pKeyInfo), -int32(8))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addr2+int32(2), iContinue, addr2+int32(2))
		_sqlite3VdbeJumpHere(tls, v, addr1)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+int32(1), (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst-int32(1))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), regPrev)
	}
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		return 0
	}
	/* Suppress the first OFFSET entries if there is an OFFSET clause
	 */
	_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
	switch int32((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) {
	/* Store the result as data using a unique key.
	 */
	case int32(SRT_EphemTab):
		r1 = _sqlite3GetTempReg(tls, pParse)
		r2 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, r2)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, r1, r2)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		_sqlite3ReleaseTempReg(tls, pParse, r2)
		_sqlite3ReleaseTempReg(tls, pParse, r1)
		break
		/* If we are creating a set for an "expr IN (SELECT ...)".
		 */
		fallthrough
	case int32(SRT_Set):
		r11 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r11, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, r11, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		_sqlite3ReleaseTempReg(tls, pParse, r11)
		break
		/* If this is a scalar select that is part of an expression, then
		 ** store the results in the appropriate memory cell and break out
		 ** of the scan loop.  Note that the select might return multiple columns
		 ** if it is the RHS of a row-value IN operator.
		 */
		fallthrough
	case int32(SRT_Mem):
		_sqlite3ExprCodeMove(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		/* The LIMIT clause will jump out of the loop for us */
		break
		/* The results are stored in a sequence of registers
		 ** starting at pDest->iSdst.  Then the co-routine yields.
		 */
		fallthrough
	case int32(SRT_Coroutine):
		if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
			(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = _sqlite3GetTempRange(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
			(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst
		}
		_sqlite3ExprCodeMove(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
		break
		/* If none of the above, then the result destination must be
		 ** SRT_Output.  This routine is never called with any other
		 ** destination other than the ones handled above or SRT_Output.
		 **
		 ** For SRT_Output, results are stored in a sequence of registers.
		 ** Then the OP_ResultRow opcode is used to cause sqlite3_step() to
		 ** return the next row of result.
		 */
		fallthrough
	default:
		_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		break
	}
	/* Jump to the end of the loop if the LIMIT is reached.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TSelect)(unsafe.Pointer(p)).FiLimit, iBreak)
	}
	/* Generate the subroutine return
	 */
	_sqlite3VdbeResolveLabel(tls, v, iContinue)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regReturn)
	return addr
}

// C documentation
//
//	/*
//	** Alternative compound select code generator for cases when there
//	** is an ORDER BY clause.
//	**
//	** We assume a query of the following form:
//	**
//	**      <selectA>  <operator>  <selectB>  ORDER BY <orderbylist>
//	**
//	** <operator> is one of UNION ALL, UNION, EXCEPT, or INTERSECT.  The idea
//	** is to code both <selectA> and <selectB> with the ORDER BY clause as
//	** co-routines.  Then run the co-routines in parallel and merge the results
//	** into the output.  In addition to the two coroutines (called selectA and
//	** selectB) there are 7 subroutines:
//	**
//	**    outA:    Move the output of the selectA coroutine into the output
//	**             of the compound query.
//	**
//	**    outB:    Move the output of the selectB coroutine into the output
//	**             of the compound query.  (Only generated for UNION and
//	**             UNION ALL.  EXCEPT and INSERTSECT never output a row that
//	**             appears only in B.)
//	**
//	**    AltB:    Called when there is data from both coroutines and A<B.
//	**
//	**    AeqB:    Called when there is data from both coroutines and A==B.
//	**
//	**    AgtB:    Called when there is data from both coroutines and A>B.
//	**
//	**    EofA:    Called when data is exhausted from selectA.
//	**
//	**    EofB:    Called when data is exhausted from selectB.
//	**
//	** The implementation of the latter five subroutines depend on which
//	** <operator> is used:
//	**
//	**
//	**             UNION ALL         UNION            EXCEPT          INTERSECT
//	**          -------------  -----------------  --------------  -----------------
//	**   AltB:   outA, nextA      outA, nextA       outA, nextA         nextA
//	**
//	**   AeqB:   outA, nextA         nextA             nextA         outA, nextA
//	**
//	**   AgtB:   outB, nextB      outB, nextB          nextB            nextB
//	**
//	**   EofA:   outB, nextB      outB, nextB          halt             halt
//	**
//	**   EofB:   outA, nextA      outA, nextA       outA, nextA         halt
//	**
//	** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA
//	** causes an immediate jump to EofA and an EOF on B following nextB causes
//	** an immediate jump to EofB.  Within EofA and EofB, and EOF on entry or
//	** following nextX causes a jump to the end of the select processing.
//	**
//	** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled
//	** within the output subroutine.  The regPrev register set holds the previously
//	** output value.  A comparison is made against this value and the output
//	** is skipped if the next results would be the same as the previous.
//	**
//	** The implementation plan is to implement the two coroutines and seven
//	** subroutines first, then put the control logic at the bottom.  Like this:
//	**
//	**          goto Init
//	**     coA: coroutine for left query (A)
//	**     coB: coroutine for right query (B)
//	**    outA: output one row of A
//	**    outB: output one row of B (UNION and UNION ALL only)
//	**    EofA: ...
//	**    EofB: ...
//	**    AltB: ...
//	**    AeqB: ...
//	**    AgtB: ...
//	**    Init: initialize coroutine registers
//	**          yield coA
//	**          if eof(A) goto EofA
//	**          yield coB
//	**          if eof(B) goto EofB
//	**    Cmpr: Compare A, B
//	**          Jump AltB, AeqB, AgtB
//	**     End: ...
//	**
//	** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
//	** actually called using Gosub and they do not Return.  EofA and EofB loop
//	** until all data is exhausted then jump to the "end" label.  AltB, AeqB,
//	** and AgtB jump to either L2 or to one of EofA or EofB.
//	*/
func _multiSelectOrderBy(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var aPermute, db, pItem, pItem1, pKeyDup, pKeyMerge, pNew, pOrderBy, pPrior, pSplit, v, v10, v12, v16, v18, v20, v22, v3 uintptr
	var addr1, addrAeqB, addrAgtB, addrAltB, addrEofA, addrEofA_noB, addrEofB, addrOutA, addrOutB, addrSelectA, addrSelectB, i, j, labelCmpr, labelEnd, nExpr, nOrderBy, nSelect, op, regAddrA, regAddrB, regLimitA, regLimitB, regOutA, regOutB, regPrev, savedLimit, savedOffset, v11, v13, v14, v15, v17, v19, v21, v23, v4, v9 int32
	var _ /* destA at bp+0 */ TSelectDest
	var _ /* destB at bp+28 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aPermute, addr1, addrAeqB, addrAgtB, addrAltB, addrEofA, addrEofA_noB, addrEofB, addrOutA, addrOutB, addrSelectA, addrSelectB, db, i, j, labelCmpr, labelEnd, nExpr, nOrderBy, nSelect, op, pItem, pItem1, pKeyDup, pKeyMerge, pNew, pOrderBy, pPrior, pSplit, regAddrA, regAddrB, regLimitA, regLimitB, regOutA, regOutB, regPrev, savedLimit, savedOffset, v, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v3, v4, v9 /* Address of the output-A subroutine */
	addrOutB = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
	pKeyDup = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* Mapping from ORDER BY terms to result set columns */
	/* "Managed" code needs this.  Ticket #3382. */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* Already thrown the error if VDBE alloc failed */
	labelEnd = _sqlite3VdbeMakeLabel(tls, pParse)
	labelCmpr = _sqlite3VdbeMakeLabel(tls, pParse)
	/* Patch up the ORDER BY clause
	 */
	op = int32((*TSelect)(unsafe.Pointer(p)).Fop)
	pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
	nOrderBy = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
	/* For operators other than UNION ALL we have to make sure that
	 ** the ORDER BY clause covers every term of the result set.  Add
	 ** terms to the ORDER BY clause as necessary.
	 */
	if op != int32(TK_ALL) {
		i = int32(1)
		for {
			if !(int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && i <= (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr) {
				break
			}
			j = 0
			pItem = pOrderBy + 8
			for {
				if !(j < nOrderBy) {
					break
				}
				if int32((*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem + 16))).FiOrderByCol) == i {
					break
				}
				goto _2
			_2:
				;
				j++
				pItem += 20
			}
			if j == nOrderBy {
				pNew = _sqlite3Expr(tls, db, int32(TK_INTEGER), uintptr(0))
				if pNew == uintptr(0) {
					return int32(SQLITE_NOMEM)
				}
				*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(EP_IntValue)
				*(*int32)(unsafe.Pointer(pNew + 8)) = i
				v3 = _sqlite3ExprListAppend(tls, pParse, pOrderBy, pNew)
				pOrderBy = v3
				(*TSelect)(unsafe.Pointer(p)).FpOrderBy = v3
				if pOrderBy != 0 {
					v4 = nOrderBy
					nOrderBy++
					*(*Tu16)(unsafe.Pointer(pOrderBy + 8 + uintptr(v4)*20 + 16)) = uint16(uint16(i))
				}
			}
			goto _1
		_1:
			;
			i++
		}
	}
	/* Compute the comparison permutation and keyinfo that is used with
	 ** the permutation used to determine if the next
	 ** row of results comes from selectA or selectB.  Also add explicit
	 ** collations to the ORDER BY clause terms so that when the subqueries
	 ** to the right and the left are evaluated, they use the correct
	 ** collation.
	 */
	aPermute = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(4)*uint32(nOrderBy+libc.Int32FromInt32(1))))
	if aPermute != 0 {
		*(*Tu32)(unsafe.Pointer(aPermute)) = uint32(uint32(nOrderBy))
		i = int32(1)
		pItem1 = pOrderBy + 8
		for {
			if !(i <= nOrderBy) {
				break
			}
			*(*Tu32)(unsafe.Pointer(aPermute + uintptr(i)*4)) = uint32(int32((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem1 + 16))).FiOrderByCol) - int32(1))
			goto _5
		_5:
			;
			i++
			pItem1 += 20
		}
		pKeyMerge = _multiSelectOrderByKeyInfo(tls, pParse, p, int32(1))
	} else {
		pKeyMerge = uintptr(0)
	}
	/* Allocate a range of temporary registers and the KeyInfo needed
	 ** for the logic that removes duplicate result rows when the
	 ** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
	 */
	if op == int32(TK_ALL) {
		regPrev = 0
	} else {
		nExpr = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
		regPrev = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nExpr + int32(1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regPrev)
		pKeyDup = _sqlite3KeyInfoAlloc(tls, db, nExpr, int32(1))
		if pKeyDup != 0 {
			i = 0
			for {
				if !(i < nExpr) {
					break
				}
				*(*uintptr)(unsafe.Pointer(pKeyDup + 20 + uintptr(i)*4)) = _multiSelectCollSeq(tls, pParse, p, i)
				*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKeyDup)).FaSortFlags + uintptr(i))) = uint8(0)
				goto _6
			_6:
				;
				i++
			}
		}
	}
	/* Separate the left and the right query from one another
	 */
	nSelect = int32(1)
	if (op == int32(TK_ALL) || op == int32(TK_UNION)) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_BalancedMerge)) == uint32(0) {
		pSplit = p
		for {
			if !((*TSelect)(unsafe.Pointer(pSplit)).FpPrior != uintptr(0) && int32((*TSelect)(unsafe.Pointer(pSplit)).Fop) == op) {
				break
			}
			nSelect++
			goto _7
		_7:
			;
			pSplit = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
		}
	}
	if nSelect <= int32(3) {
		pSplit = p
	} else {
		pSplit = p
		i = int32(2)
		for {
			if !(i < nSelect) {
				break
			}
			pSplit = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
			goto _8
		_8:
			;
			i += int32(2)
		}
	}
	pPrior = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
	(*TSelect)(unsafe.Pointer(pSplit)).FpPrior = uintptr(0)
	(*TSelect)(unsafe.Pointer(pPrior)).FpNext = uintptr(0)
	(*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy = _sqlite3ExprListDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pOrderBy, 0)
	_sqlite3ResolveOrderGroupBy(tls, pParse, p, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, __ccgo_ts+8801)
	_sqlite3ResolveOrderGroupBy(tls, pParse, pPrior, (*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy, __ccgo_ts+8801)
	/* Compute the limit registers */
	_computeLimitRegisters(tls, pParse, p, labelEnd)
	if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 && op == int32(TK_ALL) {
		v10 = pParse + 44
		*(*int32)(unsafe.Pointer(v10))++
		v9 = *(*int32)(unsafe.Pointer(v10))
		regLimitA = v9
		v12 = pParse + 44
		*(*int32)(unsafe.Pointer(v12))++
		v11 = *(*int32)(unsafe.Pointer(v12))
		regLimitB = v11
		if (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
			v13 = (*TSelect)(unsafe.Pointer(p)).FiOffset + int32(1)
		} else {
			v13 = (*TSelect)(unsafe.Pointer(p)).FiLimit
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), v13, regLimitA)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regLimitA, regLimitB)
	} else {
		v14 = libc.Int32FromInt32(0)
		regLimitB = v14
		regLimitA = v14
	}
	_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit)
	(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
	v16 = pParse + 44
	*(*int32)(unsafe.Pointer(v16))++
	v15 = *(*int32)(unsafe.Pointer(v16))
	regAddrA = v15
	v18 = pParse + 44
	*(*int32)(unsafe.Pointer(v18))++
	v17 = *(*int32)(unsafe.Pointer(v18))
	regAddrB = v17
	v20 = pParse + 44
	*(*int32)(unsafe.Pointer(v20))++
	v19 = *(*int32)(unsafe.Pointer(v20))
	regOutA = v19
	v22 = pParse + 44
	*(*int32)(unsafe.Pointer(v22))++
	v21 = *(*int32)(unsafe.Pointer(v22))
	regOutB = v21
	_sqlite3SelectDestInit(tls, bp, int32(SRT_Coroutine), regAddrA)
	_sqlite3SelectDestInit(tls, bp+28, int32(SRT_Coroutine), regAddrB)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21015, libc.VaList(bp+64, _sqlite3SelectOpName(tls, int32((*TSelect)(unsafe.Pointer(p)).Fop))))
	/* Generate a coroutine to evaluate the SELECT statement to the
	 ** left of the compound operator - the "A" select.
	 */
	addrSelectA = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
	addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regAddrA, 0, addrSelectA)
	(*TSelect)(unsafe.Pointer(pPrior)).FiLimit = regLimitA
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21026, 0)
	_sqlite3Select(tls, pParse, pPrior, bp)
	_sqlite3VdbeEndCoroutine(tls, v, regAddrA)
	_sqlite3VdbeJumpHere(tls, v, addr1)
	/* Generate a coroutine to evaluate the SELECT statement on
	 ** the right - the "B" select
	 */
	addrSelectB = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
	addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regAddrB, 0, addrSelectB)
	savedLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
	savedOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
	(*TSelect)(unsafe.Pointer(p)).FiLimit = regLimitB
	(*TSelect)(unsafe.Pointer(p)).FiOffset = 0
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21031, 0)
	_sqlite3Select(tls, pParse, p, bp+28)
	(*TSelect)(unsafe.Pointer(p)).FiLimit = savedLimit
	(*TSelect)(unsafe.Pointer(p)).FiOffset = savedOffset
	_sqlite3VdbeEndCoroutine(tls, v, regAddrB)
	/* Generate a subroutine that outputs the current row of the A
	 ** select as the next output row of the compound select.
	 */
	addrOutA = _generateOutputSubroutine(tls, pParse, p, bp, pDest, regOutA, regPrev, pKeyDup, labelEnd)
	/* Generate a subroutine that outputs the current row of the B
	 ** select as the next output row of the compound select.
	 */
	if op == int32(TK_ALL) || op == int32(TK_UNION) {
		addrOutB = _generateOutputSubroutine(tls, pParse, p, bp+28, pDest, regOutB, regPrev, pKeyDup, labelEnd)
	}
	_sqlite3KeyInfoUnref(tls, pKeyDup)
	/* Generate a subroutine to run when the results from select A
	 ** are exhausted and only data in select B remains.
	 */
	if op == int32(TK_EXCEPT) || op == int32(TK_INTERSECT) {
		v23 = labelEnd
		addrEofA = v23
		addrEofA_noB = v23
	} else {
		addrEofA = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutB, addrOutB)
		addrEofA_noB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, labelEnd)
		_sqlite3VdbeGoto(tls, v, addrEofA)
		(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEstAdd(tls, (*TSelect)(unsafe.Pointer(p)).FnSelectRow, (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow)
	}
	/* Generate a subroutine to run when the results from select B
	 ** are exhausted and only data in select A remains.
	 */
	if op == int32(TK_INTERSECT) {
		addrEofB = addrEofA
		if int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32((*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow) {
			(*TSelect)(unsafe.Pointer(p)).FnSelectRow = (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow
		}
	} else {
		addrEofB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutA, addrOutA)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, labelEnd)
		_sqlite3VdbeGoto(tls, v, addrEofB)
	}
	/* Generate code to handle the case of A<B
	 */
	addrAltB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutA, addrOutA)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, addrEofA)
	_sqlite3VdbeGoto(tls, v, labelCmpr)
	/* Generate code to handle the case of A==B
	 */
	if op == int32(TK_ALL) {
		addrAeqB = addrAltB
	} else {
		if op == int32(TK_INTERSECT) {
			addrAeqB = addrAltB
			addrAltB++
		} else {
			addrAeqB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, addrEofA)
			_sqlite3VdbeGoto(tls, v, labelCmpr)
		}
	}
	/* Generate code to handle the case of A>B
	 */
	addrAgtB = _sqlite3VdbeCurrentAddr(tls, v)
	if op == int32(TK_ALL) || op == int32(TK_UNION) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutB, addrOutB)
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, addrEofB)
	_sqlite3VdbeGoto(tls, v, labelCmpr)
	/* This code runs once to initialize everything.
	 */
	_sqlite3VdbeJumpHere(tls, v, addr1)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, addrEofA_noB)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, addrEofB)
	/* Implement the main merge loop
	 */
	_sqlite3VdbeResolveLabel(tls, v, labelCmpr)
	_sqlite3VdbeAddOp4(tls, v, int32(OP_Permutation), 0, 0, 0, aPermute, -int32(14))
	_sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), (*(*TSelectDest)(unsafe.Pointer(bp))).FiSdst, (*(*TSelectDest)(unsafe.Pointer(bp + 28))).FiSdst, nOrderBy, pKeyMerge, -int32(8))
	_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_PERMUTE))
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addrAltB, addrAeqB, addrAgtB)
	/* Jump to the this point in order to terminate the query.
	 */
	_sqlite3VdbeResolveLabel(tls, v, labelEnd)
	/* Make arrangements to free the 2nd and subsequent arms of the compound
	 ** after the parse has finished */
	if (*TSelect)(unsafe.Pointer(pSplit)).FpPrior != 0 {
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), (*TSelect)(unsafe.Pointer(pSplit)).FpPrior)
	}
	(*TSelect)(unsafe.Pointer(pSplit)).FpPrior = pPrior
	(*TSelect)(unsafe.Pointer(pPrior)).FpNext = pSplit
	_sqlite3ExprListDelete(tls, db, (*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy)
	(*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy = uintptr(0)
	/*** TBD:  Insert subroutine calls to close cursors on incomplete
	 **** subqueries ****/
	_sqlite3VdbeExplainPop(tls, pParse)
	return libc.BoolInt32((*TParse)(unsafe.Pointer(pParse)).FnErr != 0)
}

// C documentation
//
//	/* An instance of the SubstContext object describes an substitution edit
//	** to be performed on a parse tree.
//	**
//	** All references to columns in table iTable are to be replaced by corresponding
//	** expressions in pEList.
//	**
//	** ## About "isOuterJoin":
//	**
//	** The isOuterJoin column indicates that the replacement will occur into a
//	** position in the parent that NULL-able due to an OUTER JOIN.  Either the
//	** target slot in the parent is the right operand of a LEFT JOIN, or one of
//	** the left operands of a RIGHT JOIN.  In either case, we need to potentially
//	** bypass the substituted expression with OP_IfNullRow.
//	**
//	** Suppose the original expression is an integer constant. Even though the table
//	** has the nullRow flag set, because the expression is an integer constant,
//	** it will not be NULLed out.  So instead, we insert an OP_IfNullRow opcode
//	** that checks to see if the nullRow flag is set on the table.  If the nullRow
//	** flag is set, then the value in the register is set to NULL and the original
//	** expression is bypassed.  If the nullRow flag is not set, then the original
//	** expression runs to populate the register.
//	**
//	** Example where this is needed:
//	**
//	**      CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT);
//	**      CREATE TABLE t2(x INT UNIQUE);
//	**
//	**      SELECT a,b,m,x FROM t1 LEFT JOIN (SELECT 59 AS m,x FROM t2) ON b=x;
//	**
//	** When the subquery on the right side of the LEFT JOIN is flattened, we
//	** have to add OP_IfNullRow in front of the OP_Integer that implements the
//	** "m" value of the subquery so that a NULL will be loaded instead of 59
//	** when processing a non-matched row of the left.
//	*/
type TSubstContext = struct {
	FpParse      uintptr
	FiTable      int32
	FiNewTable   int32
	FisOuterJoin int32
	FpEList      uintptr
	FpCList      uintptr
}

type SubstContext = TSubstContext

// C documentation
//
//	/*
//	** Scan through the expression pExpr.  Replace every reference to
//	** a column in table number iTable with a copy of the iColumn-th
//	** entry in pEList.  (But leave references to the ROWID column
//	** unchanged.)
//	**
//	** This routine is part of the flattening procedure.  A subquery
//	** whose result set is defined by pEList appears as entry in the
//	** FROM clause of a SELECT such that the VDBE cursor assigned to that
//	** FORM clause entry is iTable.  This routine makes the necessary
//	** changes to pExpr so that it refers directly to the source table
//	** of the subquery rather the result set of the subquery.
//	*/
func _substExpr(tls *libc.TLS, pSubst uintptr, pExpr uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pColl, pCopy, pNat, pNew, pWin, v1 uintptr
	var iColumn int32
	var _ /* ifNullRow at bp+0 */ TExpr
	_, _, _, _, _, _, _, _ = db, iColumn, pColl, pCopy, pNat, pNew, pWin, v1
	if pExpr == uintptr(0) {
		return uintptr(0)
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) && *(*int32)(unsafe.Pointer(pExpr + 36)) == (*TSubstContext)(unsafe.Pointer(pSubst)).FiTable {
		*(*int32)(unsafe.Pointer(pExpr + 36)) = (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSubstContext)(unsafe.Pointer(pSubst)).FiTable && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_FixedCol)) != libc.Uint32FromInt32(0)) {
		iColumn = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
		pCopy = (*(*TExprList_item)(unsafe.Pointer((*TSubstContext)(unsafe.Pointer(pSubst)).FpEList + 8 + uintptr(iColumn)*20))).FpExpr
		if _sqlite3ExprIsVector(tls, pCopy) != 0 {
			_sqlite3VectorErrorMsg(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, pCopy)
		} else {
			db = (*TParse)(unsafe.Pointer((*TSubstContext)(unsafe.Pointer(pSubst)).FpParse)).Fdb
			if (*TSubstContext)(unsafe.Pointer(pSubst)).FisOuterJoin != 0 && (int32((*TExpr)(unsafe.Pointer(pCopy)).Fop) != int32(TK_COLUMN) || (*TExpr)(unsafe.Pointer(pCopy)).FiTable != (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable) {
				libc.Xmemset(tls, bp, 0, uint32(52))
				(*(*TExpr)(unsafe.Pointer(bp))).Fop = uint8(TK_IF_NULL_ROW)
				(*(*TExpr)(unsafe.Pointer(bp))).FpLeft = pCopy
				(*(*TExpr)(unsafe.Pointer(bp))).FiTable = (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable
				(*(*TExpr)(unsafe.Pointer(bp))).FiColumn = int16(-int32(99))
				(*(*TExpr)(unsafe.Pointer(bp))).Fflags = uint32(EP_IfNullRow)
				pCopy = bp
			}
			pNew = _sqlite3ExprDup(tls, db, pCopy, 0)
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				_sqlite3ExprDelete(tls, db, pNew)
				return pExpr
			}
			if (*TSubstContext)(unsafe.Pointer(pSubst)).FisOuterJoin != 0 {
				*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(libc.Int32FromInt32(EP_CanBeNull))
			}
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
				_sqlite3SetJoinExpr(tls, pNew, *(*int32)(unsafe.Pointer(pExpr + 36)), (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)))
			}
			_sqlite3ExprDelete(tls, db, pExpr)
			pExpr = pNew
			if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_TRUEFALSE) {
				*(*int32)(unsafe.Pointer(pExpr + 8)) = _sqlite3ExprTruthValue(tls, pExpr)
				(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_INTEGER)
				*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_IntValue))
			}
			/* Ensure that the expression now has an implicit collation sequence,
			 ** just as it did when it was a column of a view or sub-query. */
			pNat = _sqlite3ExprCollSeq(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, pExpr)
			pColl = _sqlite3ExprCollSeq(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, (*(*TExprList_item)(unsafe.Pointer((*TSubstContext)(unsafe.Pointer(pSubst)).FpCList + 8 + uintptr(iColumn)*20))).FpExpr)
			if pNat != pColl || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLLATE) {
				if pColl != 0 {
					v1 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
				} else {
					v1 = __ccgo_ts + 6459
				}
				pExpr = _sqlite3ExprAddCollateString(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, pExpr, v1)
			}
			*(*Tu32)(unsafe.Pointer(pExpr + 4)) &= uint32(^libc.Int32FromInt32(EP_Collate))
		}
	} else {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IF_NULL_ROW) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSubstContext)(unsafe.Pointer(pSubst)).FiTable {
			(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable
		}
		(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = _substExpr(tls, pSubst, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		(*TExpr)(unsafe.Pointer(pExpr)).FpRight = _substExpr(tls, pSubst, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			_substSelect(tls, pSubst, *(*uintptr)(unsafe.Pointer(pExpr + 20)), int32(1))
		} else {
			_substExprList(tls, pSubst, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
			pWin = *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy))
			(*TWindow)(unsafe.Pointer(pWin)).FpFilter = _substExpr(tls, pSubst, (*TWindow)(unsafe.Pointer(pWin)).FpFilter)
			_substExprList(tls, pSubst, (*TWindow)(unsafe.Pointer(pWin)).FpPartition)
			_substExprList(tls, pSubst, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy)
		}
	}
	return pExpr
}

func _substExprList(tls *libc.TLS, pSubst uintptr, pList uintptr) {
	var i int32
	_ = i
	if pList == uintptr(0) {
		return
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		(*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr = _substExpr(tls, pSubst, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr)
		goto _1
	_1:
		;
		i++
	}
}

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
	}
	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
			}
			_substSelect(tls, pSubst, (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect, int32(1))
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x4>>2)) != 0 {
				_substExprList(tls, pSubst, *(*uintptr)(unsafe.Pointer(pItem + 64)))
			}
			goto _4
		_4:
			;
			i--
			pItem += 72
		}
		goto _3
	_3:
		;
		if v2 = doPrior != 0; v2 {
			v1 = (*TSelect)(unsafe.Pointer(p)).FpPrior
			p = v1
		}
		if !(v2 && v1 != uintptr(0)) {
			break
		}
	}
}

// C documentation
//
//	/*
//	** pSelect is a SELECT statement and pSrcItem is one item in the FROM
//	** clause of that SELECT.
//	**
//	** This routine scans the entire SELECT statement and recomputes the
//	** pSrcItem->colUsed mask.
//	*/
func _recomputeColumnsUsedExpr(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var pItem uintptr
	_ = pItem
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLUMN) {
		return WRC_Continue
	}
	pItem = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	if (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor != (*TExpr)(unsafe.Pointer(pExpr)).FiTable {
		return WRC_Continue
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) < 0 {
		return WRC_Continue
	}
	*(*TBitmask)(unsafe.Pointer(pItem + 56)) |= _sqlite3ExprColUsed(tls, pExpr)
	return WRC_Continue
}

func _recomputeColumnsUsed(tls *libc.TLS, pSelect uintptr, pSrcItem uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	if (*TSrcItem)(unsafe.Pointer(pSrcItem)).FpTab == uintptr(0) {
		return
	}
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_recomputeColumnsUsedExpr)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pSrcItem
	(*TSrcItem)(unsafe.Pointer(pSrcItem)).FcolUsed = uint64(0)
	_sqlite3WalkSelect(tls, bp, pSelect)
}

// 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(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x40>>6)) != 0) || *(*int32)(unsafe.Pointer(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4)) == 0 {
				v3 = pParse + 40
				v2 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3))++
				*(*int32)(unsafe.Pointer(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4)) = v2
			}
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = *(*int32)(unsafe.Pointer(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4))
			p = (*TSrcItem)(unsafe.Pointer(pItem)).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++
		pItem += 72
	}
}

// C documentation
//
//	/*
//	** *piCursor is a cursor number.  Change it if it needs to be mapped.
//	*/
func _renumberCursorDoMapping(tls *libc.TLS, pWalker uintptr, piCursor uintptr) {
	var aCsrMap uintptr
	var iCsr int32
	_, _ = aCsrMap, iCsr
	aCsrMap = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	iCsr = *(*int32)(unsafe.Pointer(piCursor))
	if iCsr < *(*int32)(unsafe.Pointer(aCsrMap)) && *(*int32)(unsafe.Pointer(aCsrMap + uintptr(iCsr+int32(1))*4)) > 0 {
		*(*int32)(unsafe.Pointer(piCursor)) = *(*int32)(unsafe.Pointer(aCsrMap + uintptr(iCsr+int32(1))*4))
	}
}

// C documentation
//
//	/*
//	** Expression walker callback used by renumberCursors() to update
//	** Expr objects to match newly assigned cursor numbers.
//	*/
func _renumberCursorsCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var op int32
	_ = op
	op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop)
	if op == int32(TK_COLUMN) || op == int32(TK_IF_NULL_ROW) {
		_renumberCursorDoMapping(tls, pWalker, pExpr+28)
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
		_renumberCursorDoMapping(tls, pWalker, pExpr+36)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Assign a new cursor number to each cursor in the FROM clause (Select.pSrc)
//	** of the SELECT statement passed as the second argument, and to each
//	** cursor in the FROM clause of any FROM clause sub-selects, recursively.
//	** Except, do not assign a new cursor number to the iExcept'th element in
//	** the FROM clause of (*p). Update all expressions and other references
//	** to refer to the new cursor numbers.
//	**
//	** Argument aCsrMap is an array that may be used for temporary working
//	** space. Two guarantees are made by the caller:
//	**
//	**   * the array is larger than the largest cursor number used within the
//	**     select statement passed as an argument, and
//	**
//	**   * the array entries for all cursor numbers that do *not* appear in
//	**     FROM clauses of the select statement as described above are
//	**     initialized to zero.
//	*/
func _renumberCursors(tls *libc.TLS, pParse uintptr, p uintptr, iExcept int32, aCsrMap uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	_srclistRenumberCursors(tls, pParse, aCsrMap, (*TSelect)(unsafe.Pointer(p)).FpSrc, iExcept)
	libc.Xmemset(tls, bp, 0, uint32(28))
	*(*uintptr)(unsafe.Pointer(bp + 24)) = aCsrMap
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_renumberCursorsCb)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	_sqlite3WalkSelect(tls, bp, p)
}

// C documentation
//
//	/*
//	** If pSel is not part of a compound SELECT, return a pointer to its
//	** expression list. Otherwise, return a pointer to the expression list
//	** of the leftmost SELECT in the compound.
//	*/
func _findLeftmostExprlist(tls *libc.TLS, pSel uintptr) (r uintptr) {
	for (*TSelect)(unsafe.Pointer(pSel)).FpPrior != 0 {
		pSel = (*TSelect)(unsafe.Pointer(pSel)).FpPrior
	}
	return (*TSelect)(unsafe.Pointer(pSel)).FpEList
}

// C documentation
//
//	/*
//	** Return true if any of the result-set columns in the compound query
//	** have incompatible affinities on one or more arms of the compound.
//	*/
func _compoundHasDifferentAffinities(tls *libc.TLS, p uintptr) (r int32) {
	var aff int8
	var ii int32
	var pList, pSub1 uintptr
	_, _, _, _ = aff, ii, pList, pSub1
	pList = (*TSelect)(unsafe.Pointer(p)).FpEList
	ii = 0
	for {
		if !(ii < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		aff = _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ii)*20))).FpExpr)
		pSub1 = (*TSelect)(unsafe.Pointer(p)).FpPrior
		for {
			if !(pSub1 != 0) {
				break
			}
			if int32(_sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub1)).FpEList + 8 + uintptr(ii)*20))).FpExpr)) != int32(int32(aff)) {
				return int32(1)
			}
			goto _2
		_2:
			;
			pSub1 = (*TSelect)(unsafe.Pointer(pSub1)).FpPrior
		}
		goto _1
	_1:
		;
		ii++
	}
	return 0
}

// 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 and
//	**        (3b) the FROM clause of the subquery may not contain a virtual
//	**             table and
//	**        (**) 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(64)
	defer tls.Free(64)
	var aCsrMap, db, pItem, pItemTab, pLimit, pNew, pOrderBy, pOrderBy1, pParent, pPrior, pSrc, pSub, pSub1, pSubSrc, pSubitem, pTabToDel, pToplevel, pWhere, zSavedAuthContext, v5, v6, p10, p11, p9 uintptr
	var i, iNewParent, iParent, ii, isOuterJoin, nSubSrc, v4 int32
	var jointype, ltorj Tu8
	var _ /* w at bp+0 */ TWalker
	var _ /* x at bp+28 */ TSubstContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCsrMap, db, i, iNewParent, iParent, ii, isOuterJoin, jointype, ltorj, nSubSrc, pItem, pItemTab, pLimit, pNew, pOrderBy, pOrderBy1, pParent, pPrior, pSrc, pSub, pSub1, pSubSrc, pSubitem, pTabToDel, pToplevel, pWhere, zSavedAuthContext, v4, v5, v6, p10, p11, p9
	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&uint32(libc.Int32FromInt32(SQLITE_QueryFlattener)) != uint32(0) {
		return 0
	}
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
	pSubitem = pSrc + 8 + uintptr(iFrom)*72
	iParent = (*TSrcItem)(unsafe.Pointer(pSubitem)).FiCursor
	pSub = (*TSrcItem)(unsafe.Pointer(pSubitem)).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&uint32(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 int32((*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
		if (*TSrcList)(unsafe.Pointer(pSubSrc)).FnSrc > int32(1) || int32((*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pSubSrc + 8))).FpTab)).FeTabType) == int32(TABTYP_VTAB) || (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0) || int32((*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
			return 0
		}
		isOuterJoin = int32(1)
	}
	/* True by restriction (7) */
	if iFrom > 0 && int32((*(*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&uint32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) != uint32(0) || (*TSelect)(unsafe.Pointer(pSub1)).FpPrior != 0 && int32((*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 && int32((*(*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 int32(*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy + 8 + uintptr(ii)*20 + 16))) == 0 {
					return 0
				}
				goto _2
			_2:
				;
				ii++
			}
		}
		/* 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&uint32(libc.Int32FromInt32(SQLITE_FlttnUnionAll)) != uint32(0) {
				return 0
			}
			aCsrMap = _sqlite3DbMallocZero(tls, db, uint64((int64((*TParse)(unsafe.Pointer(pParse)).FnTab)+int64(1))*int64(4)))
			if aCsrMap != 0 {
				*(*int32)(unsafe.Pointer(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 */
	pSub1 = (*TSrcItem)(unsafe.Pointer(pSubitem)).FpSelect
	_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pSubitem)).FzDatabase)
	_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pSubitem)).FzName)
	_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pSubitem)).FzAlias)
	(*TSrcItem)(unsafe.Pointer(pSubitem)).FzDatabase = uintptr(0)
	(*TSrcItem)(unsafe.Pointer(pSubitem)).FzName = uintptr(0)
	(*TSrcItem)(unsafe.Pointer(pSubitem)).FzAlias = uintptr(0)
	(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSelect = 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)).FpTab
		(*TSrcItem)(unsafe.Pointer(pSubitem)).FpTab = 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)).FpTab = pItemTab
		if pNew == uintptr(0) {
			(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
		} else {
			v5 = pParse + 108
			*(*int32)(unsafe.Pointer(v5))++
			v4 = *(*int32)(unsafe.Pointer(v5))
			(*TSelect)(unsafe.Pointer(pNew)).FselId = uint32(v4)
			if aCsrMap != 0 && int32((*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 {
		(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSelect = pSub1
		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->pTab is always non-NULL by test restrictions and tests above.
	 */
	if (*TSrcItem)(unsafe.Pointer(pSubitem)).FpTab != uintptr(0) {
		pTabToDel = (*TSrcItem)(unsafe.Pointer(pSubitem)).FpTab
		if (*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef == uint32(1) {
			if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
				v6 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
			} else {
				v6 = pParse
			}
			pToplevel = v6
			_sqlite3ParserAddCleanup(tls, pToplevel, __ccgo_fp(_sqlite3DeleteTableGeneric), pTabToDel)
		} else {
			(*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef--
		}
		(*TSrcItem)(unsafe.Pointer(pSubitem)).FpTab = 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 = uint8(0)
		ltorj = uint8(int32((*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(iFrom)*72))).Ffg.Fjointype) & int32(JT_LTORJ))
		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 */
		if pParent == p {
			jointype = (*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype /* First time through the loop */
		}
		/* 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
		}
		/* Transfer the FROM clause terms from the subquery into the
		 ** outer query.
		 */
		i = 0
		for {
			if !(i < nSubSrc) {
				break
			}
			pItem = pSrc + 8 + uintptr(i+iFrom)*72
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x400>>10)) != 0 {
				_sqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 48)))
			}
			*(*TSrcItem)(unsafe.Pointer(pItem)) = *(*TSrcItem)(unsafe.Pointer(pSubSrc + 8 + uintptr(i)*72))
			p9 = pItem + 36
			*(*Tu8)(unsafe.Pointer(p9)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p9))) | int32(int32(ltorj)))
			iNewParent = (*(*TSrcItem)(unsafe.Pointer(pSubSrc + 8 + uintptr(i)*72))).FiCursor
			libc.Xmemset(tls, pSubSrc+8+uintptr(i)*72, 0, uint32(72))
			goto _8
		_8:
			;
			i++
		}
		p10 = pSrc + 8 + uintptr(iFrom)*72 + 36
		*(*Tu8)(unsafe.Pointer(p10)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p10))) & libc.Int32FromInt32(JT_LTORJ))
		p11 = pSrc + 8 + uintptr(iFrom)*72 + 36
		*(*Tu8)(unsafe.Pointer(p11)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p11))) | (int32(int32(jointype)) | int32(int32(ltorj))))
		/* Now 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 && (*TSelect)(unsafe.Pointer(pParent)).FselFlags&uint32(SF_NoopOrderBy) == uint32(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
			 ** (the only way this can happen is if the compound sub-query is
			 ** currently part of pSub->pSrc). 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)*20 + 16)) = uint16(0)
				goto _12
			_12:
				;
				i++
			}
			(*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 int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
			(*(*TSubstContext)(unsafe.Pointer(bp + 28))).FpParse = pParse
			(*(*TSubstContext)(unsafe.Pointer(bp + 28))).FiTable = iParent
			(*(*TSubstContext)(unsafe.Pointer(bp + 28))).FiNewTable = iNewParent
			(*(*TSubstContext)(unsafe.Pointer(bp + 28))).FisOuterJoin = isOuterJoin
			(*(*TSubstContext)(unsafe.Pointer(bp + 28))).FpEList = (*TSelect)(unsafe.Pointer(pSub)).FpEList
			(*(*TSubstContext)(unsafe.Pointer(bp + 28))).FpCList = _findLeftmostExprlist(tls, pSub)
			_substSelect(tls, bp+28, pParent, 0)
		}
		/* The flattened query is a compound if either the inner or the
		 ** outer query is a compound. */
		*(*Tu32)(unsafe.Pointer(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)*72)
			goto _13
		_13:
			;
			i++
		}
		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)
}

// C documentation
//
//	/*
//	** A structure to keep track of all of the column values that are fixed to
//	** a known value due to WHERE clause constraints of the form COLUMN=VALUE.
//	*/
type TWhereConst = struct {
	FpParse      uintptr
	FpOomFault   uintptr
	FnConst      int32
	FnChng       int32
	FbHasAffBlob int32
	FmExcludeOn  Tu32
	FapExpr      uintptr
}

type WhereConst = TWhereConst

type TWhereConst1 = struct {
	FpParse      uintptr
	FpOomFault   uintptr
	FnConst      int32
	FnChng       int32
	FbHasAffBlob int32
	FmExcludeOn  Tu32
	FapExpr      uintptr
}

type WhereConst1 = TWhereConst1

// C documentation
//
//	/*
//	** Add a new entry to the pConst object.  Except, do not add duplicate
//	** pColumn entries.  Also, do not add if doing so would not be appropriate.
//	**
//	** The caller guarantees the pColumn is a column and pValue is a constant.
//	** This routine has to do some additional checks before completing the
//	** insert.
//	*/
func _constInsert(tls *libc.TLS, pConst uintptr, pColumn uintptr, pValue uintptr, pExpr uintptr) {
	var i int32
	var pE2 uintptr
	_, _ = i, pE2
	if (*TExpr)(unsafe.Pointer(pColumn)).Fflags&uint32(libc.Int32FromInt32(EP_FixedCol)) != uint32(0) {
		return
	}
	if int32(_sqlite3ExprAffinity(tls, pValue)) != 0 {
		return
	}
	if !(_sqlite3IsBinary(tls, _sqlite3ExprCompareCollSeq(tls, (*TWhereConst)(unsafe.Pointer(pConst)).FpParse, pExpr)) != 0) {
		return
	}
	/* 2018-10-25 ticket [cf5ed20f]
	 ** Make sure the same pColumn is not inserted more than once */
	i = 0
	for {
		if !(i < (*TWhereConst)(unsafe.Pointer(pConst)).FnConst) {
			break
		}
		pE2 = *(*uintptr)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr(i*int32(2))*4))
		if (*TExpr)(unsafe.Pointer(pE2)).FiTable == (*TExpr)(unsafe.Pointer(pColumn)).FiTable && int32((*TExpr)(unsafe.Pointer(pE2)).FiColumn) == int32((*TExpr)(unsafe.Pointer(pColumn)).FiColumn) {
			return /* Already present.  Return without doing anything. */
		}
		goto _1
	_1:
		;
		i++
	}
	if int32(_sqlite3ExprAffinity(tls, pColumn)) == int32(SQLITE_AFF_BLOB) {
		(*TWhereConst)(unsafe.Pointer(pConst)).FbHasAffBlob = int32(1)
	}
	(*TWhereConst)(unsafe.Pointer(pConst)).FnConst++
	(*TWhereConst)(unsafe.Pointer(pConst)).FapExpr = _sqlite3DbReallocOrFree(tls, (*TParse)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FpParse)).Fdb, (*TWhereConst)(unsafe.Pointer(pConst)).FapExpr, uint64(uint32((*TWhereConst)(unsafe.Pointer(pConst)).FnConst*int32(2))*uint32(4)))
	if (*TWhereConst)(unsafe.Pointer(pConst)).FapExpr == uintptr(0) {
		(*TWhereConst)(unsafe.Pointer(pConst)).FnConst = 0
	} else {
		*(*uintptr)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr((*TWhereConst)(unsafe.Pointer(pConst)).FnConst*int32(2)-int32(2))*4)) = pColumn
		*(*uintptr)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr((*TWhereConst)(unsafe.Pointer(pConst)).FnConst*int32(2)-int32(1))*4)) = pValue
	}
}

// C documentation
//
//	/*
//	** Find all terms of COLUMN=VALUE or VALUE=COLUMN in pExpr where VALUE
//	** is a constant expression and where the term must be true because it
//	** is part of the AND-connected terms of the expression.  For each term
//	** found, add it to the pConst structure.
//	*/
func _findConstInWhere(tls *libc.TLS, pConst uintptr, pExpr uintptr) {
	var pLeft, pRight uintptr
	_, _ = pLeft, pRight
	if pExpr == uintptr(0) {
		return
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&(*TWhereConst)(unsafe.Pointer(pConst)).FmExcludeOn != uint32(0) {
		return
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AND) {
		_findConstInWhere(tls, pConst, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		_findConstInWhere(tls, pConst, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		return
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_EQ) {
		return
	}
	pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
	pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	if int32((*TExpr)(unsafe.Pointer(pRight)).Fop) == int32(TK_COLUMN) && _sqlite3ExprIsConstant(tls, (*TWhereConst)(unsafe.Pointer(pConst)).FpParse, pLeft) != 0 {
		_constInsert(tls, pConst, pRight, pLeft, pExpr)
	}
	if int32((*TExpr)(unsafe.Pointer(pLeft)).Fop) == int32(TK_COLUMN) && _sqlite3ExprIsConstant(tls, (*TWhereConst)(unsafe.Pointer(pConst)).FpParse, pRight) != 0 {
		_constInsert(tls, pConst, pLeft, pRight, pExpr)
	}
}

// C documentation
//
//	/*
//	** This is a helper function for Walker callback propagateConstantExprRewrite().
//	**
//	** Argument pExpr is a candidate expression to be replaced by a value. If
//	** pExpr is equivalent to one of the columns named in pWalker->u.pConst,
//	** then overwrite it with the corresponding value. Except, do not do so
//	** if argument bIgnoreAffBlob is non-zero and the affinity of pExpr
//	** is SQLITE_AFF_BLOB.
//	*/
func _propagateConstantExprRewriteOne(tls *libc.TLS, pConst uintptr, pExpr uintptr, bIgnoreAffBlob int32) (r int32) {
	var i int32
	var pColumn uintptr
	_, _ = i, pColumn
	if *(*Tu8)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FpOomFault)) != 0 {
		return int32(WRC_Prune)
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLUMN) {
		return WRC_Continue
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&(uint32(EP_FixedCol)|(*TWhereConst)(unsafe.Pointer(pConst)).FmExcludeOn) != uint32(0) {
		return WRC_Continue
	}
	i = 0
	for {
		if !(i < (*TWhereConst)(unsafe.Pointer(pConst)).FnConst) {
			break
		}
		pColumn = *(*uintptr)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr(i*int32(2))*4))
		if pColumn == pExpr {
			goto _1
		}
		if (*TExpr)(unsafe.Pointer(pColumn)).FiTable != (*TExpr)(unsafe.Pointer(pExpr)).FiTable {
			goto _1
		}
		if int32((*TExpr)(unsafe.Pointer(pColumn)).FiColumn) != int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) {
			goto _1
		}
		if bIgnoreAffBlob != 0 && int32(_sqlite3ExprAffinity(tls, pColumn)) == int32(SQLITE_AFF_BLOB) {
			break
		}
		/* A match is found.  Add the EP_FixedCol property */
		(*TWhereConst)(unsafe.Pointer(pConst)).FnChng++
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) &= uint32(^libc.Int32FromInt32(EP_Leaf))
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_FixedCol))
		(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FpParse)).Fdb, *(*uintptr)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr(i*int32(2)+int32(1))*4)), 0)
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FpParse)).Fdb)).FmallocFailed != 0 {
			return int32(WRC_Prune)
		}
		break
		goto _1
	_1:
		;
		i++
	}
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** This is a Walker expression callback. pExpr is a node from the WHERE
//	** clause of a SELECT statement. This function examines pExpr to see if
//	** any substitutions based on the contents of pWalker->u.pConst should
//	** be made to pExpr or its immediate children.
//	**
//	** A substitution is made if:
//	**
//	**   + pExpr is a column with an affinity other than BLOB that matches
//	**     one of the columns in pWalker->u.pConst, or
//	**
//	**   + pExpr is a binary comparison operator (=, <=, >=, <, >) that
//	**     uses an affinity other than TEXT and one of its immediate
//	**     children is a column that matches one of the columns in
//	**     pWalker->u.pConst.
//	*/
func _propagateConstantExprRewrite(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var pConst uintptr
	_ = pConst
	pConst = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	if (*TWhereConst)(unsafe.Pointer(pConst)).FbHasAffBlob != 0 {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) >= int32(TK_EQ) && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) <= int32(TK_GE) || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IS) {
			_propagateConstantExprRewriteOne(tls, pConst, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, 0)
			if *(*Tu8)(unsafe.Pointer((*TWhereConst)(unsafe.Pointer(pConst)).FpOomFault)) != 0 {
				return int32(WRC_Prune)
			}
			if int32(_sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)) != int32(SQLITE_AFF_TEXT) {
				_propagateConstantExprRewriteOne(tls, pConst, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, 0)
			}
		}
	}
	return _propagateConstantExprRewriteOne(tls, pConst, pExpr, (*TWhereConst)(unsafe.Pointer(pConst)).FbHasAffBlob)
}

// C documentation
//
//	/*
//	** The WHERE-clause constant propagation optimization.
//	**
//	** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
//	** CONSTANT=COLUMN that are top-level AND-connected terms that are not
//	** part of a ON clause from a LEFT JOIN, then throughout the query
//	** replace all other occurrences of COLUMN with CONSTANT.
//	**
//	** For example, the query:
//	**
//	**      SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
//	**
//	** Is transformed into
//	**
//	**      SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=39 AND t3.c=39
//	**
//	** Return true if any transformations where made and false if not.
//	**
//	** Implementation note:  Constant propagation is tricky due to affinity
//	** and collating sequence interactions.  Consider this example:
//	**
//	**    CREATE TABLE t1(a INT,b TEXT);
//	**    INSERT INTO t1 VALUES(123,'0123');
//	**    SELECT * FROM t1 WHERE a=123 AND b=a;
//	**    SELECT * FROM t1 WHERE a=123 AND b=123;
//	**
//	** The two SELECT statements above should return different answers.  b=a
//	** is always true because the comparison uses numeric affinity, but b=123
//	** is false because it uses text affinity and '0123' is not the same as '123'.
//	** To work around this, the expression tree is not actually changed from
//	** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol
//	** and the "123" value is hung off of the pLeft pointer.  Code generator
//	** routines know to generate the constant "123" instead of looking up the
//	** column value.  Also, to avoid collation problems, this optimization is
//	** only attempted if the "a=123" term uses the default BINARY collation.
//	**
//	** 2021-05-25 forum post 6a06202608: Another troublesome case is...
//	**
//	**    CREATE TABLE t1(x);
//	**    INSERT INTO t1 VALUES(10.0);
//	**    SELECT 1 FROM t1 WHERE x=10 AND x LIKE 10;
//	**
//	** The query should return no rows, because the t1.x value is '10.0' not '10'
//	** and '10.0' is not LIKE '10'.  But if we are not careful, the first WHERE
//	** term "x=10" will cause the second WHERE term to become "10 LIKE 10",
//	** resulting in a false positive.  To avoid this, constant propagation for
//	** columns with BLOB affinity is only allowed if the constant is used with
//	** operators ==, <=, <, >=, >, or IS in a way that will cause the correct
//	** type conversions to occur.  See logic associated with the bHasAffBlob flag
//	** for details.
//	*/
func _propagateConstants(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var nChng int32
	var _ /* w at bp+28 */ TWalker
	var _ /* x at bp+0 */ TWhereConst
	_ = nChng
	nChng = 0
	(*(*TWhereConst)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TWhereConst)(unsafe.Pointer(bp))).FpOomFault = (*TParse)(unsafe.Pointer(pParse)).Fdb + 87
	for cond := true; cond; cond = (*(*TWhereConst)(unsafe.Pointer(bp))).FnChng != 0 {
		(*(*TWhereConst)(unsafe.Pointer(bp))).FnConst = 0
		(*(*TWhereConst)(unsafe.Pointer(bp))).FnChng = 0
		(*(*TWhereConst)(unsafe.Pointer(bp))).FapExpr = uintptr(0)
		(*(*TWhereConst)(unsafe.Pointer(bp))).FbHasAffBlob = 0
		if (*TSelect)(unsafe.Pointer(p)).FpSrc != uintptr(0) && (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc > 0 && int32((*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
			/* Do not propagate constants on any ON clause if there is a
			 ** RIGHT JOIN anywhere in the query */
			(*(*TWhereConst)(unsafe.Pointer(bp))).FmExcludeOn = uint32(libc.Int32FromInt32(EP_InnerON) | libc.Int32FromInt32(EP_OuterON))
		} else {
			/* Do not propagate constants through the ON clause of a LEFT JOIN */
			(*(*TWhereConst)(unsafe.Pointer(bp))).FmExcludeOn = uint32(EP_OuterON)
		}
		_findConstInWhere(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpWhere)
		if (*(*TWhereConst)(unsafe.Pointer(bp))).FnConst != 0 {
			libc.Xmemset(tls, bp+28, 0, uint32(28))
			(*(*TWalker)(unsafe.Pointer(bp + 28))).FpParse = pParse
			(*(*TWalker)(unsafe.Pointer(bp + 28))).FxExprCallback = __ccgo_fp(_propagateConstantExprRewrite)
			(*(*TWalker)(unsafe.Pointer(bp + 28))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
			(*(*TWalker)(unsafe.Pointer(bp + 28))).FxSelectCallback2 = uintptr(0)
			(*(*TWalker)(unsafe.Pointer(bp + 28))).FwalkerDepth = 0
			*(*uintptr)(unsafe.Pointer(bp + 28 + 24)) = bp
			_sqlite3WalkExpr(tls, bp+28, (*TSelect)(unsafe.Pointer(p)).FpWhere)
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer((*(*TWhereConst)(unsafe.Pointer(bp))).FpParse)).Fdb, (*(*TWhereConst)(unsafe.Pointer(bp))).FapExpr)
			nChng += (*(*TWhereConst)(unsafe.Pointer(bp))).FnChng
		}
	}
	return nChng
}

// C documentation
//
//	/*
//	** This function is called to determine whether or not it is safe to
//	** push WHERE clause expression pExpr down to FROM clause sub-query
//	** pSubq, which contains at least one window function. Return 1
//	** if it is safe and the expression should be pushed down, or 0
//	** otherwise.
//	**
//	** It is only safe to push the expression down if it consists only
//	** of constants and copies of expressions that appear in the PARTITION
//	** BY clause of all window function used by the sub-query. It is safe
//	** to filter out entire partitions, but not rows within partitions, as
//	** this may change the results of the window functions.
//	**
//	** At the time this function is called it is guaranteed that
//	**
//	**   * the sub-query uses only one distinct window frame, and
//	**   * that the window frame has a PARTITION BY clause.
//	*/
func _pushDownWindowCheck(tls *libc.TLS, pParse uintptr, pSubq uintptr, pExpr uintptr) (r int32) {
	return _sqlite3ExprIsConstantOrGroupBy(tls, pParse, pExpr, (*TWindow)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSubq)).FpWin)).FpPartition)
}

// C documentation
//
//	/*
//	** Make copies of relevant WHERE clause terms of the outer query into
//	** the WHERE clause of subquery.  Example:
//	**
//	**    SELECT * FROM (SELECT a AS x, c-d AS y FROM t1) WHERE x=5 AND y=10;
//	**
//	** Transformed into:
//	**
//	**    SELECT * FROM (SELECT a AS x, c-d AS y FROM t1 WHERE a=5 AND c-d=10)
//	**     WHERE x=5 AND y=10;
//	**
//	** The hope is that the terms added to the inner query will make it more
//	** efficient.
//	**
//	** NAME AMBIGUITY
//	**
//	** This optimization is called the "WHERE-clause push-down optimization".
//	**
//	** Do not confuse this optimization with another unrelated optimization
//	** with a similar name:  The "MySQL push-down optimization" causes WHERE
//	** clause terms that can be evaluated using only the index and without
//	** reference to the table are run first, so that if they are false,
//	** unnecessary table seeks are avoided.
//	**
//	** RULES
//	**
//	** Do not attempt this optimization if:
//	**
//	**   (1) (** This restriction was removed on 2017-09-29.  We used to
//	**           disallow this optimization for aggregate subqueries, but now
//	**           it is allowed by putting the extra terms on the HAVING clause.
//	**           The added HAVING clause is pointless if the subquery lacks
//	**           a GROUP BY clause.  But such a HAVING clause is also harmless
//	**           so there does not appear to be any reason to add extra logic
//	**           to suppress it. **)
//	**
//	**   (2) The inner query is the recursive part of a common table expression.
//	**
//	**   (3) The inner query has a LIMIT clause (since the changes to the WHERE
//	**       clause would change the meaning of the LIMIT).
//	**
//	**   (4) The inner query is the right operand of a LEFT JOIN and the
//	**       expression to be pushed down does not come from the ON clause
//	**       on that LEFT JOIN.
//	**
//	**   (5) The WHERE clause expression originates in the ON or USING clause
//	**       of a LEFT JOIN where iCursor is not the right-hand table of that
//	**       left join.  An example:
//	**
//	**           SELECT *
//	**           FROM (SELECT 1 AS a1 UNION ALL SELECT 2) AS aa
//	**           JOIN (SELECT 1 AS b2 UNION ALL SELECT 2) AS bb ON (a1=b2)
//	**           LEFT JOIN (SELECT 8 AS c3 UNION ALL SELECT 9) AS cc ON (b2=2);
//	**
//	**       The correct answer is three rows:  (1,1,NULL),(2,2,8),(2,2,9).
//	**       But if the (b2=2) term were to be pushed down into the bb subquery,
//	**       then the (1,1,NULL) row would be suppressed.
//	**
//	**   (6) Window functions make things tricky as changes to the WHERE clause
//	**       of the inner query could change the window over which window
//	**       functions are calculated. Therefore, do not attempt the optimization
//	**       if:
//	**
//	**     (6a) The inner query uses multiple incompatible window partitions.
//	**
//	**     (6b) The inner query is a compound and uses window-functions.
//	**
//	**     (6c) The WHERE clause does not consist entirely of constants and
//	**          copies of expressions found in the PARTITION BY clause of
//	**          all window-functions used by the sub-query. It is safe to
//	**          filter out entire partitions, as this does not change the
//	**          window over which any window-function is calculated.
//	**
//	**   (7) The inner query is a Common Table Expression (CTE) that should
//	**       be materialized.  (This restriction is implemented in the calling
//	**       routine.)
//	**
//	**   (8) If the subquery is a compound that uses UNION, INTERSECT,
//	**       or EXCEPT, then all of the result set columns for all arms of
//	**       the compound must use the BINARY collating sequence.
//	**
//	**   (9) All three of the following are true:
//	**
//	**       (9a) The WHERE clause expression originates in the ON or USING clause
//	**            of a join (either an INNER or an OUTER join), and
//	**
//	**       (9b) The subquery is to the right of the ON/USING clause
//	**
//	**       (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING
//	**            clause and the subquery.
//	**
//	**       Without this restriction, the WHERE-clause push-down optimization
//	**       might move the ON/USING filter expression from the left side of a
//	**       RIGHT JOIN over to the right side, which leads to incorrect answers.
//	**       See also restriction (6) in sqlite3ExprIsSingleTableConstraint().
//	**
//	**  (10) The inner query is not the right-hand table of a RIGHT JOIN.
//	**
//	**  (11) The subquery is not a VALUES clause
//	**
//	**  (12) The WHERE clause is not "rowid ISNULL" or the equivalent.  This
//	**       case only comes up if SQLite is compiled using
//	**       SQLITE_ALLOW_ROWID_IN_VIEW.
//	**
//	** Return 0 if no changes are made and non-zero if one or more WHERE clause
//	** terms are duplicated into the subquery.
//	*/
func _pushDownWhereTerms(tls *libc.TLS, pParse uintptr, pSubq uintptr, pWhere uintptr, pSrcList uintptr, iSrc int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ii, nChng, notUnionAll int32
	var op Tu8
	var pColl, pList, pNew, pSel, pSrc uintptr
	var _ /* x at bp+0 */ TSubstContext
	_, _, _, _, _, _, _, _, _ = ii, nChng, notUnionAll, op, pColl, pList, pNew, pSel, pSrc /* The subquery FROM term into which WHERE is pushed */
	nChng = 0
	pSrc = pSrcList + 8 + uintptr(iSrc)*72
	if pWhere == uintptr(0) {
		return 0
	}
	if (*TSelect)(unsafe.Pointer(pSubq)).FselFlags&uint32(libc.Int32FromInt32(SF_Recursive)|libc.Int32FromInt32(SF_MultiPart)) != 0 {
		return 0 /* restrictions (2) and (11) */
	}
	if int32((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
		return 0 /* restrictions (10) */
	}
	if (*TSelect)(unsafe.Pointer(pSubq)).FpPrior != 0 {
		notUnionAll = 0
		pSel = pSubq
		for {
			if !(pSel != 0) {
				break
			}
			op = (*TSelect)(unsafe.Pointer(pSel)).Fop
			if int32(int32(op)) != int32(TK_ALL) && int32(int32(op)) != int32(TK_SELECT) {
				notUnionAll = int32(1)
			}
			if (*TSelect)(unsafe.Pointer(pSel)).FpWin != 0 {
				return 0
			} /* restriction (6b) */
			goto _1
		_1:
			;
			pSel = (*TSelect)(unsafe.Pointer(pSel)).FpPrior
		}
		if notUnionAll != 0 {
			/* If any of the compound arms are connected using UNION, INTERSECT,
			 ** or EXCEPT, then we must ensure that none of the columns use a
			 ** non-BINARY collating sequence. */
			pSel = pSubq
			for {
				if !(pSel != 0) {
					break
				}
				pList = (*TSelect)(unsafe.Pointer(pSel)).FpEList
				ii = 0
				for {
					if !(ii < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
						break
					}
					pColl = _sqlite3ExprCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ii)*20))).FpExpr)
					if !(_sqlite3IsBinary(tls, pColl) != 0) {
						return 0 /* Restriction (8) */
					}
					goto _3
				_3:
					;
					ii++
				}
				goto _2
			_2:
				;
				pSel = (*TSelect)(unsafe.Pointer(pSel)).FpPrior
			}
		}
	} else {
		if (*TSelect)(unsafe.Pointer(pSubq)).FpWin != 0 && (*TWindow)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSubq)).FpWin)).FpPartition == uintptr(0) {
			return 0
		}
	}
	if (*TSelect)(unsafe.Pointer(pSubq)).FpLimit != uintptr(0) {
		return 0 /* restriction (3) */
	}
	for int32((*TExpr)(unsafe.Pointer(pWhere)).Fop) == int32(TK_AND) {
		nChng += _pushDownWhereTerms(tls, pParse, pSubq, (*TExpr)(unsafe.Pointer(pWhere)).FpRight, pSrcList, iSrc)
		pWhere = (*TExpr)(unsafe.Pointer(pWhere)).FpLeft
	}
	if _sqlite3ExprIsSingleTableConstraint(tls, pWhere, pSrcList, iSrc, int32(1)) != 0 {
		nChng++
		*(*Tu32)(unsafe.Pointer(pSubq + 4)) |= uint32(SF_PushDown)
		for pSubq != 0 {
			pNew = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pWhere, 0)
			_unsetJoinExpr(tls, pNew, -int32(1), int32(1))
			(*(*TSubstContext)(unsafe.Pointer(bp))).FpParse = pParse
			(*(*TSubstContext)(unsafe.Pointer(bp))).FiTable = (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor
			(*(*TSubstContext)(unsafe.Pointer(bp))).FiNewTable = (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor
			(*(*TSubstContext)(unsafe.Pointer(bp))).FisOuterJoin = 0
			(*(*TSubstContext)(unsafe.Pointer(bp))).FpEList = (*TSelect)(unsafe.Pointer(pSubq)).FpEList
			(*(*TSubstContext)(unsafe.Pointer(bp))).FpCList = _findLeftmostExprlist(tls, pSubq)
			pNew = _substExpr(tls, bp, pNew)
			if (*TSelect)(unsafe.Pointer(pSubq)).FpWin != 0 && 0 == _pushDownWindowCheck(tls, pParse, pSubq, pNew) {
				/* Restriction 6c has prevented push-down in this case */
				_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pNew)
				nChng--
				break
			}
			if (*TSelect)(unsafe.Pointer(pSubq)).FselFlags&uint32(SF_Aggregate) != 0 {
				(*TSelect)(unsafe.Pointer(pSubq)).FpHaving = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(pSubq)).FpHaving, pNew)
			} else {
				(*TSelect)(unsafe.Pointer(pSubq)).FpWhere = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(pSubq)).FpWhere, pNew)
			}
			pSubq = (*TSelect)(unsafe.Pointer(pSubq)).FpPrior
		}
	}
	return nChng
}

// 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(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x8>>3)) != 0 || int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x100>>8)) != 0 {
		return 0
	}
	pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
	pSub = (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect
	pX = pSub
	for {
		if !(pX != 0) {
			break
		}
		if (*TSelect)(unsafe.Pointer(pX)).FselFlags&uint32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) != uint32(0) {
			return 0
		}
		if (*TSelect)(unsafe.Pointer(pX)).FpPrior != 0 && int32((*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)*20 + 16))
			if int32(int32(iCol)) > 0 {
				iCol--
				if int32(int32(iCol)) >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
					v3 = int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
				} else {
					v3 = int32(int32(iCol))
				}
				colUsed |= libc.Uint64FromInt32(1) << v3
			}
			goto _2
		_2:
			;
			j++
		}
	}
	nCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	j = 0
	for {
		if !(j < nCol) {
			break
		}
		if j < int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
			v5 = libc.Uint64FromInt32(1) << j
		} else {
			v5 = libc.Uint64FromInt32(1) << (int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(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)*20))).FpExpr
			if int32((*TExpr)(unsafe.Pointer(pY)).Fop) == int32(TK_NULL) {
				goto _6
			}
			(*TExpr)(unsafe.Pointer(pY)).Fop = uint8(TK_NULL)
			*(*Tu32)(unsafe.Pointer(pY + 4)) &= uint32(^(libc.Int32FromInt32(EP_Skip) | libc.Int32FromInt32(EP_Unlikely)))
			*(*Tu32)(unsafe.Pointer(pX + 4)) |= uint32(SF_PushDown)
			nChng++
			goto _6
		_6:
			;
			pX = (*TSelect)(unsafe.Pointer(pX)).FpPrior
		}
		goto _4
	_4:
		;
		j++
	}
	return nChng
}

// C documentation
//
//	/*
//	** The pFunc is the only aggregate function in the query.  Check to see
//	** if the query is a candidate for the min/max optimization.
//	**
//	** If the query is a candidate for the min/max optimization, then set
//	** *ppMinMax to be an ORDER BY clause to be used for the optimization
//	** and return either WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX depending on
//	** whether pFunc is a min() or max() function.
//	**
//	** If the query is not a candidate for the min/max optimization, return
//	** WHERE_ORDERBY_NORMAL (which must be zero).
//	**
//	** This routine must be called after aggregate functions have been
//	** located but before their arguments have been subjected to aggregate
//	** analysis.
//	*/
func _minMaxQuery(tls *libc.TLS, db uintptr, pFunc uintptr, ppMinMax uintptr) (r Tu8) {
	var eRet int32
	var pEList, pOrderBy, zFunc, v1 uintptr
	var sortFlags Tu8
	_, _, _, _, _, _ = eRet, pEList, pOrderBy, sortFlags, zFunc, v1
	eRet = WHERE_ORDERBY_NORMAL
	sortFlags = uint8(0)
	pEList = *(*uintptr)(unsafe.Pointer(pFunc + 20))
	if pEList == uintptr(0) || (*TExprList)(unsafe.Pointer(pEList)).FnExpr != int32(1) || (*TExpr)(unsafe.Pointer(pFunc)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) || (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_MinMaxOpt)) != uint32(0) {
		return uint8(uint8(eRet))
	}
	zFunc = *(*uintptr)(unsafe.Pointer(pFunc + 8))
	if _sqlite3StrICmp(tls, zFunc, __ccgo_ts+16957) == 0 {
		eRet = int32(WHERE_ORDERBY_MIN)
		if _sqlite3ExprCanBeNull(tls, (*(*TExprList_item)(unsafe.Pointer(pEList + 8))).FpExpr) != 0 {
			sortFlags = uint8(KEYINFO_ORDER_BIGNULL)
		}
	} else {
		if _sqlite3StrICmp(tls, zFunc, __ccgo_ts+16961) == 0 {
			eRet = int32(WHERE_ORDERBY_MAX)
			sortFlags = uint8(KEYINFO_ORDER_DESC)
		} else {
			return uint8(uint8(eRet))
		}
	}
	v1 = _sqlite3ExprListDup(tls, db, pEList, 0)
	pOrderBy = v1
	*(*uintptr)(unsafe.Pointer(ppMinMax)) = v1
	if pOrderBy != 0 {
		(*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).Ffg.FsortFlags = sortFlags
	}
	return uint8(uint8(eRet))
}

// 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) || (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSelect != 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))).FpTab
	if !(int32((*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 int32((*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)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_COUNT) == uint32(0) {
		return uintptr(0)
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Distinct)|libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		return uintptr(0)
	}
	return pTab
}

// 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)).FpTab
	zIndexedBy = *(*uintptr)(unsafe.Pointer(pFrom + 64))
	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+21037, libc.VaList(bp+8, zIndexedBy, 0))
		(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
		return int32(SQLITE_ERROR)
	}
	*(*uintptr)(unsafe.Pointer(pFrom + 68)) = pIdx
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Detect compound SELECT statements that use an ORDER BY clause with
//	** an alternative collating sequence.
//	**
//	**    SELECT ... FROM t1 EXCEPT SELECT ... FROM t2 ORDER BY .. COLLATE ...
//	**
//	** These are rewritten as a subquery:
//	**
//	**    SELECT * FROM (SELECT ... FROM t1 EXCEPT SELECT ... FROM t2)
//	**     ORDER BY ... COLLATE ...
//	**
//	** This transformation is necessary because the multiSelectOrderBy() routine
//	** above that generates the code for a compound SELECT with an ORDER BY clause
//	** uses a merge algorithm that requires the same collating sequence on the
//	** result columns as on the ORDER BY clause.  See ticket
//	** http://www.sqlite.org/src/info/6709574d2a
//	**
//	** This transformation is only needed for EXCEPT, INTERSECT, and UNION.
//	** The UNION ALL operator works fine with multiSelectOrderBy() even when
//	** there are COLLATE terms in the ORDER BY.
//	*/
func _convertCompoundSelectToSubquery(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, db, pNew, pNewSrc, pParse, pX uintptr
	var i int32
	var _ /* dummy at bp+0 */ TToken
	_, _, _, _, _, _, _ = a, db, i, pNew, pNewSrc, pParse, pX
	if (*TSelect)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
		return WRC_Continue
	}
	if (*TSelect)(unsafe.Pointer(p)).FpOrderBy == uintptr(0) {
		return WRC_Continue
	}
	pX = p
	for {
		if !(pX != 0 && (int32((*TSelect)(unsafe.Pointer(pX)).Fop) == int32(TK_ALL) || int32((*TSelect)(unsafe.Pointer(pX)).Fop) == int32(TK_SELECT))) {
			break
		}
		goto _1
	_1:
		;
		pX = (*TSelect)(unsafe.Pointer(pX)).FpPrior
	}
	if pX == uintptr(0) {
		return WRC_Continue
	}
	a = (*TSelect)(unsafe.Pointer(p)).FpOrderBy + 8
	/* If iOrderByCol is already non-zero, then it has already been matched
	 ** to a result column of the SELECT statement. This occurs when the
	 ** SELECT is rewritten for window-functions processing and then passed
	 ** to sqlite3SelectPrep() and similar a second time. The rewriting done
	 ** by this function is not required in this case. */
	if *(*Tu16)(unsafe.Pointer(a + 16)) != 0 {
		return WRC_Continue
	}
	i = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy)).FnExpr - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		if (*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(a + uintptr(i)*20))).FpExpr)).Fflags&uint32(EP_Collate) != 0 {
			break
		}
		goto _2
	_2:
		;
		i--
	}
	if i < 0 {
		return WRC_Continue
	}
	/* If we reach this point, that means the transformation is required. */
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = _sqlite3DbMallocZero(tls, db, uint64(76))
	if pNew == uintptr(0) {
		return int32(WRC_Abort)
	}
	libc.Xmemset(tls, bp, 0, uint32(8))
	pNewSrc = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp, pNew, uintptr(0))
	if pNewSrc == uintptr(0) {
		return int32(WRC_Abort)
	}
	*(*TSelect)(unsafe.Pointer(pNew)) = *(*TSelect)(unsafe.Pointer(p))
	(*TSelect)(unsafe.Pointer(p)).FpSrc = pNewSrc
	(*TSelect)(unsafe.Pointer(p)).FpEList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3Expr(tls, db, int32(TK_ASTERISK), uintptr(0)))
	(*TSelect)(unsafe.Pointer(p)).Fop = uint8(TK_SELECT)
	(*TSelect)(unsafe.Pointer(p)).FpWhere = uintptr(0)
	(*TSelect)(unsafe.Pointer(pNew)).FpGroupBy = uintptr(0)
	(*TSelect)(unsafe.Pointer(pNew)).FpHaving = uintptr(0)
	(*TSelect)(unsafe.Pointer(pNew)).FpOrderBy = uintptr(0)
	(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
	(*TSelect)(unsafe.Pointer(p)).FpNext = uintptr(0)
	(*TSelect)(unsafe.Pointer(p)).FpWith = uintptr(0)
	(*TSelect)(unsafe.Pointer(p)).FpWinDefn = uintptr(0)
	*(*Tu32)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(SF_Compound))
	*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(SF_Converted)
	(*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pNew)).FpPrior)).FpNext = pNew
	(*TSelect)(unsafe.Pointer(pNew)).FpLimit = uintptr(0)
	return WRC_Continue
}

// 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(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x4>>2)) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21055, libc.VaList(bp+8, (*TSrcItem)(unsafe.Pointer(pFrom)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Argument pWith (which may be NULL) points to a linked list of nested
//	** WITH contexts, from inner to outermost. If the table identified by
//	** FROM clause element pItem is really a common-table-expression (CTE)
//	** then return a pointer to the CTE definition for that table. Otherwise
//	** return NULL.
//	**
//	** If a non-NULL value is returned, set *ppContext to point to the With
//	** object that the returned CTE belongs to.
//	*/
func _searchWith(tls *libc.TLS, pWith uintptr, pItem uintptr, ppContext uintptr) (r uintptr) {
	var i int32
	var p, zName uintptr
	_, _, _ = i, p, zName
	zName = (*TSrcItem)(unsafe.Pointer(pItem)).FzName
	p = pWith
	for {
		if !(p != 0) {
			break
		}
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(p)).FnCte) {
				break
			}
			if _sqlite3StrICmp(tls, zName, (*(*TCte)(unsafe.Pointer(p + 12 + uintptr(i)*24))).FzName) == 0 {
				*(*uintptr)(unsafe.Pointer(ppContext)) = p
				return p + 12 + uintptr(i)*24
			}
			goto _2
		_2:
			;
			i++
		}
		if (*TWith)(unsafe.Pointer(p)).FbView != 0 {
			break
		}
		goto _1
	_1:
		;
		p = (*TWith)(unsafe.Pointer(p)).FpOuter
	}
	return uintptr(0)
}

// C documentation
//
//	/* The code generator maintains a stack of active WITH clauses
//	** with the inner-most WITH clause being at the top of the stack.
//	**
//	** This routine pushes the WITH clause passed as the second argument
//	** onto the top of the stack. If argument bFree is true, then this
//	** WITH clause will never be popped from the stack but should instead
//	** be freed along with the Parse object. In other cases, when
//	** bFree==0, the With object will be freed along with the SELECT
//	** statement with which it is associated.
//	**
//	** This routine returns a copy of pWith.  Or, if bFree is true and
//	** the pWith object is destroyed immediately due to an OOM condition,
//	** then this routine return NULL.
//	**
//	** If bFree is true, do not continue to use the pWith pointer after
//	** calling this routine,  Instead, use only the return value.
//	*/
func _sqlite3WithPush(tls *libc.TLS, pParse uintptr, pWith uintptr, bFree Tu8) (r uintptr) {
	if pWith != 0 {
		if bFree != 0 {
			pWith = _sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3WithDeleteGeneric), pWith)
			if pWith == uintptr(0) {
				return uintptr(0)
			}
		}
		if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
			(*TWith)(unsafe.Pointer(pWith)).FpOuter = (*TParse)(unsafe.Pointer(pParse)).FpWith
			(*TParse)(unsafe.Pointer(pParse)).FpWith = pWith
		}
	}
	return pWith
}

// 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->pTab
//	** 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, v4 int32
	var db, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, v1, v2, v5 uintptr
	var _ /* pWith at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bMayRecursive, db, i, iRecTab, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, rc, v1, v2, v4, v5 /* 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 (*TSrcItem)(unsafe.Pointer(pFrom)).FzDatabase != 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(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x200>>9)) != 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(64))
		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)).FpTab = 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)(unsafe.Pointer(pTab + 28)) |= uint32(libc.Int32FromInt32(TF_Ephemeral) | libc.Int32FromInt32(TF_NoVisibleRowid))
		(*TSrcItem)(unsafe.Pointer(pFrom)).FpSelect = _sqlite3SelectDup(tls, db, (*TCte)(unsafe.Pointer(pCte)).FpSelect, 0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return int32(2)
		}
		*(*Tu32)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pFrom)).FpSelect + 4)) |= uint32(SF_CopyCte)
		if int32(uint32(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x2>>1)) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21078, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(pFrom + 64))))
			return int32(2)
		}
		libc.SetBitFieldPtr16Uint32(pFrom+36+4, libc.Uint32FromInt32(1), 8, 0x100)
		*(*uintptr)(unsafe.Pointer(pFrom + 68)) = pCteUse
		(*TCteUse)(unsafe.Pointer(pCteUse)).FnUse++
		/* Check if this is a recursive CTE. */
		v2 = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSelect
		pSel = v2
		pRecTerm = v2
		bMayRecursive = libc.BoolInt32(int32((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_ALL) || int32((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_UNION))
		for bMayRecursive != 0 && int32((*TSelect)(unsafe.Pointer(pRecTerm)).Fop) == int32((*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)*72
				if (*TSrcItem)(unsafe.Pointer(pItem)).FzDatabase == uintptr(0) && (*TSrcItem)(unsafe.Pointer(pItem)).FzName != uintptr(0) && 0 == _sqlite3StrICmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, (*TCte)(unsafe.Pointer(pCte)).FzName) {
					(*TSrcItem)(unsafe.Pointer(pItem)).FpTab = pTab
					(*TTable)(unsafe.Pointer(pTab)).FnTabRef++
					libc.SetBitFieldPtr16Uint32(pItem+36+4, libc.Uint32FromInt32(1), 6, 0x40)
					if (*TSelect)(unsafe.Pointer(pRecTerm)).FselFlags&uint32(SF_Recursive) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21098, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName))
						return int32(2)
					}
					*(*Tu32)(unsafe.Pointer(pRecTerm + 4)) |= uint32(SF_Recursive)
					if iRecTab < 0 {
						v5 = pParse + 40
						v4 = *(*int32)(unsafe.Pointer(v5))
						*(*int32)(unsafe.Pointer(v5))++
						iRecTab = v4
					}
					(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = iRecTab
				}
				goto _3
			_3:
				;
				i++
			}
			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 + 21141
		pSavedWith = (*TParse)(unsafe.Pointer(pParse)).FpWith
		(*TParse)(unsafe.Pointer(pParse)).FpWith = *(*uintptr)(unsafe.Pointer(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)(unsafe.Pointer(bp))
		pLeft = pSel
		for {
			if !((*TSelect)(unsafe.Pointer(pLeft)).FpPrior != 0) {
				break
			}
			goto _6
		_6:
			;
			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+21164, 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+34, pTab+4)
		if bMayRecursive != 0 {
			if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Recursive) != 0 {
				(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21202
			} else {
				(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21236
			}
			_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
//
//	/*
//	** If the SELECT passed as the second argument has an associated WITH
//	** clause, pop it from the stack stored as part of the Parse object.
//	**
//	** This function is used as the xSelectCallback2() callback by
//	** sqlite3SelectExpand() when walking a SELECT tree to resolve table
//	** names and other FROM clause elements.
//	*/
func _sqlite3SelectPopWith(tls *libc.TLS, pWalker uintptr, p uintptr) {
	var pParse, pWith uintptr
	_, _ = pParse, pWith
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	if (*TParse)(unsafe.Pointer(pParse)).FpWith != 0 && (*TSelect)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
		pWith = (*TSelect)(unsafe.Pointer(_findRightmost(tls, p))).FpWith
		if pWith != uintptr(0) {
			(*TParse)(unsafe.Pointer(pParse)).FpWith = (*TWith)(unsafe.Pointer(pWith)).FpOuter
		}
	}
}

// C documentation
//
//	/*
//	** The SrcItem structure passed as the second argument represents a
//	** sub-query in the FROM clause of a SELECT statement. This function
//	** allocates and populates the SrcItem.pTab object. If successful,
//	** SQLITE_OK is returned. Otherwise, if an OOM error is encountered,
//	** SQLITE_NOMEM.
//	*/
func _sqlite3ExpandSubquery(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pSel, pTab, v1 uintptr
	var v2 int32
	_, _, _, _ = pSel, pTab, v1, v2
	pSel = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSelect
	v1 = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(64))
	pTab = v1
	(*TSrcItem)(unsafe.Pointer(pFrom)).FpTab = v1
	if pTab == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
	if (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias != 0 {
		(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias)
	} else {
		(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+21274, libc.VaList(bp+8, pFrom))
	}
	for (*TSelect)(unsafe.Pointer(pSel)).FpPrior != 0 {
		pSel = (*TSelect)(unsafe.Pointer(pSel)).FpPrior
	}
	_sqlite3ColumnsFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(pSel)).FpEList, pTab+34, pTab+4)
	(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
	(*TTable)(unsafe.Pointer(pTab)).FeTabType = uint8(TABTYP_VIEW)
	(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
	/* The usual case - do not allow ROWID on a subquery */
	*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(libc.Int32FromInt32(TF_Ephemeral) | libc.Int32FromInt32(TF_NoVisibleRowid))
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		v2 = int32(SQLITE_ERROR)
	} else {
		v2 = SQLITE_OK
	}
	return v2
}

// 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--
		pBase += 72
		if int32(uint32(*(*uint16)(unsafe.Pointer(pBase + 36 + 4))&0x400>>10)) == 0 {
			continue
		}
		if *(*uintptr)(unsafe.Pointer(pBase + 48)) == uintptr(0) {
			continue
		}
		if _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pBase + 48)), zName) >= 0 {
			return int32(1)
		}
	}
	return 0
}

// 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, v10, v2, v5, v9 uintptr
	var eCodeOrig Tu8
	var elistFlags Tu32
	var flags, i, iDb, iErrOfst, ii, j, k, longNames, nAdd, rc, tableSeen, v1, v13, v4 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, v10, v13, v2, v4, v5, v9
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	selFlags = uint16((*TSelect)(unsafe.Pointer(p)).FselFlags)
	elistFlags = uint32(0)
	*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(SF_Expanded)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return int32(WRC_Abort)
	}
	if int32(int32(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 + 108
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		(*TSelect)(unsafe.Pointer(p)).FselId = uint32(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(36))
			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)).FpTab != 0 {
			goto _3
		}
		if (*TSrcItem)(unsafe.Pointer(pFrom)).FzName == uintptr(0) {
			pSel = (*TSrcItem)(unsafe.Pointer(pFrom)).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 {
			v4 = _resolveFromTermToCte(tls, pParse, pWalker, pFrom)
			rc = v4
			if v4 != 0 {
				if rc > int32(1) {
					return int32(WRC_Abort)
				}
				pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpTab
			} else {
				/* An ordinary table or view name in the FROM clause */
				v5 = _sqlite3LocateTableItem(tls, pParse, uint32(0), pFrom)
				pTab = v5
				(*TSrcItem)(unsafe.Pointer(pFrom)).FpTab = v5
				if pTab == uintptr(0) {
					return int32(WRC_Abort)
				}
				if (*TTable)(unsafe.Pointer(pTab)).FnTabRef >= uint32(0xffff) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21278, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
					(*TSrcItem)(unsafe.Pointer(pFrom)).FpTab = uintptr(0)
					return int32(WRC_Abort)
				}
				(*TTable)(unsafe.Pointer(pTab)).FnTabRef++
				if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && _cannotBeFunction(tls, pParse, pFrom) != 0 {
					return int32(WRC_Abort)
				}
				if !(int32((*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 int32((*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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21317, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
						}
						(*TSrcItem)(unsafe.Pointer(pFrom)).FpSelect = _sqlite3SelectDup(tls, db, (*(*struct {
							FpSelect uintptr
						})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect, 0)
					} else {
						if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && int32(uint32(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x80>>7)) != 0 && (*(*struct {
							FnArg  int32
							FazArg uintptr
							Fp     uintptr
						})(unsafe.Pointer(pTab + 44))).Fp != uintptr(0) && int32((*TVTable)(unsafe.Pointer((*(*struct {
							FnArg  int32
							FazArg uintptr
							Fp     uintptr
						})(unsafe.Pointer(pTab + 44))).Fp)).FeVtabRisk) > libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16516, 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 */
					_sqlite3WalkSelect(tls, pWalker, (*TSrcItem)(unsafe.Pointer(pFrom)).FpSelect)
					(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(uint16(eCodeOrig))
					(*TTable)(unsafe.Pointer(pTab)).FnCol = nCol
				}
			}
		}
		/* Locate the index named by the INDEXED BY clause, if any. */
		if int32(uint32(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x2>>1)) != 0 && _sqlite3IndexedByLookup(tls, pParse, pFrom) != 0 {
			return int32(WRC_Abort)
		}
		goto _3
	_3:
		;
		i++
		pFrom += 72
	}
	/* 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)*20))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_ASTERISK) {
			break
		}
		if int32((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_DOT) && int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpRight)).Fop) == int32(TK_ASTERISK) {
			break
		}
		elistFlags |= (*TExpr)(unsafe.Pointer(pE)).Fflags
		goto _6
	_6:
		;
		k++
	}
	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 = int32((*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)(unsafe.Pointer(a + uintptr(k)*20))).FpExpr
			elistFlags |= (*TExpr)(unsafe.Pointer(pE)).Fflags
			pRight = (*TExpr)(unsafe.Pointer(pE)).FpRight
			if int32((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_ASTERISK) && (int32((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_DOT) || int32((*TExpr)(unsafe.Pointer(pRight)).Fop) != int32(TK_ASTERISK)) {
				/* This particular expression does not need to be expanded.
				 */
				pNew = _sqlite3ExprListAppend(tls, pParse, pNew, (*(*TExprList_item)(unsafe.Pointer(a + uintptr(k)*20))).FpExpr)
				if pNew != 0 {
					(*(*TExprList_item)(unsafe.Pointer(pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*20))).FzEName = (*(*TExprList_item)(unsafe.Pointer(a + uintptr(k)*20))).FzEName
					libc.SetBitFieldPtr16Uint32(pNew+8+uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*20+8+4, uint32(int32(uint32(*(*uint16)(unsafe.Pointer(a + uintptr(k)*20 + 8 + 4))&0x3>>0))), 0, 0x3)
					(*(*TExprList_item)(unsafe.Pointer(a + uintptr(k)*20))).FzEName = uintptr(0)
				}
				(*(*TExprList_item)(unsafe.Pointer(a + uintptr(k)*20))).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 int32((*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 + 36))
				} else {
					iErrOfst = *(*int32)(unsafe.Pointer(pE + 36))
				}
				i = 0
				pFrom = pTabList + 8
				for {
					if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
						break
					} /* Number of cols including rowid */
					pTab1 = (*TSrcItem)(unsafe.Pointer(pFrom)).FpTab /* AS name for this data source */
					zSchemaName = uintptr(0)                         /* USING clause for pFrom[1] */
					v9 = (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias
					zTabName = v9
					if v9 == uintptr(0) {
						zTabName = (*TTable)(unsafe.Pointer(pTab1)).FzName
					}
					if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
						break
					}
					if int32(uint32(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x2000>>13)) != 0 {
						pNestedFrom = (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pFrom)).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 {
							v10 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
						} else {
							v10 = __ccgo_ts + 7963
						}
						zSchemaName = v10
					}
					if i+int32(1) < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && int32(uint32(*(*uint16)(unsafe.Pointer(pFrom + 1*72 + 36 + 4))&0x400>>10)) != 0 && int32(int32(selFlags))&int32(SF_NestedFrom) != 0 {
						pUsing = *(*uintptr)(unsafe.Pointer(pFrom + 1*72 + 48))
						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))*20
								(*TExprList_item)(unsafe.Pointer(pX)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21348, libc.VaList(bp+8, zUName))
								libc.SetBitFieldPtr16Uint32(pX+8+4, libc.Uint32FromInt32(ENAME_TAB), 0, 0x3)
								libc.SetBitFieldPtr16Uint32(pX+8+4, libc.Uint32FromInt32(1), 7, 0x80)
							}
							goto _11
						_11:
							;
							ii++
						}
					} else {
						pUsing = uintptr(0)
					}
					nAdd = int32((*TTable)(unsafe.Pointer(pTab1)).FnCol)
					if (*TTable)(unsafe.Pointer(pTab1)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) && int32(int32(selFlags))&int32(SF_NestedFrom) != 0 {
						nAdd++
					}
					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)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*12))).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)*20 + 8 + 4))&0x3>>0)) == int32(ENAME_ROWID) {
								goto _12
							}
							if zTName != 0 && pNestedFrom != 0 && _sqlite3MatchEName(tls, pNestedFrom+8+uintptr(j)*20, 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) && int32((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab1)).FaCol+uintptr(j)*12)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
								goto _12
							}
							if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*12))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 && zTName == uintptr(0) && int32(int32(selFlags))&int32(SF_NestedFrom) == 0 {
								goto _12
							}
						}
						tableSeen = int32(1)
						if i > 0 && zTName == uintptr(0) && int32(int32(selFlags))&int32(SF_NestedFrom) == 0 {
							if int32(uint32(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x400>>10)) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 48)), 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) && (int32((*TSrcItem)(unsafe.Pointer(pFrom)).Ffg.Fjointype)&int32(JT_LTORJ) == 0 || int32(int32(selFlags))&int32(SF_NestedFrom) != 0 || !(_inAnyUsingClause(tls, zName, pFrom, (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc-i-int32(1)) != 0)) || int32((*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 int32((*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))*20
						if int32(int32(selFlags))&int32(SF_NestedFrom) != 0 && !(int32((*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)*20))).FzEName)
							} else {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21353, libc.VaList(bp+8, zSchemaName, zTabName, zName))
							}
							if j == int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) {
								v13 = int32(ENAME_ROWID)
							} else {
								v13 = int32(ENAME_TAB)
							}
							libc.SetBitFieldPtr16Uint32(pX1+8+4, uint32(v13), 0, 0x3)
							if int32(uint32(*(*uint16)(unsafe.Pointer(pFrom + 36 + 4))&0x400>>10)) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 48)), zName) >= 0 || pUsing != 0 && _sqlite3IdListIndex(tls, pUsing, zName) >= 0 || j < int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*12))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 {
								libc.SetBitFieldPtr16Uint32(pX1+8+4, libc.Uint32FromInt32(1), 8, 0x100)
							}
						} else {
							if longNames != 0 {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+13815, libc.VaList(bp+8, zTabName, zName))
								libc.SetBitFieldPtr16Uint32(pX1+8+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
							} else {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, zName)
								libc.SetBitFieldPtr16Uint32(pX1+8+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
							}
						}
						goto _12
					_12:
						;
						j++
					}
					goto _8
				_8:
					;
					i++
					pFrom += 72
				}
				if !(tableSeen != 0) {
					if zTName != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21362, libc.VaList(bp+8, zTName))
					} else {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21380, 0)
					}
				}
			}
			goto _7
		_7:
			;
			k++
		}
		_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)(unsafe.Pointer(db + 120 + 2*4)) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21400, 0)
			return int32(WRC_Abort)
		}
		if elistFlags&uint32(libc.Int32FromInt32(EP_HasFunc)|libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
			*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(SF_ComplexResult)
		}
	}
	return WRC_Continue
}

// 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(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_sqlite3ExprWalkNoop)
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	if (*TParse)(unsafe.Pointer(pParse)).FhasCompound != 0 {
		(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_convertCompoundSelectToSubquery)
		(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = uintptr(0)
		_sqlite3WalkSelect(tls, bp, pSelect)
	}
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_selectExpander)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = __ccgo_fp(_sqlite3SelectPopWith)
	(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(0)
	_sqlite3WalkSelect(tls, bp, pSelect)
}

// 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)(unsafe.Pointer(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)).FpTab
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Ephemeral) != uint32(0) {
			/* A sub-query in the FROM clause of a SELECT */
			pSel = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSelect
			if pSel != 0 {
				_sqlite3SubqueryColumnTypes(tls, pParse, pTab, pSel, int8(SQLITE_AFF_NONE))
			}
		}
		goto _1
	_1:
		;
		i++
		pFrom += 72
	}
}

// C documentation
//
//	/*
//	** This routine adds datatype and collating sequence information to
//	** the Table structures of all FROM-clause subqueries in a
//	** SELECT statement.
//	**
//	** Use this routine after name resolution.
//	*/
func _sqlite3SelectAddTypeInfo(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback2 = __ccgo_fp(_selectAddSubqueryTypeInfo)
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_sqlite3ExprWalkNoop)
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	_sqlite3WalkSelect(tls, bp, pSelect)
}

// C documentation
//
//	/*
//	** This routine sets up a SELECT statement for processing.  The
//	** following is accomplished:
//	**
//	**     *  VDBE Cursor numbers are assigned to all FROM-clause terms.
//	**     *  Ephemeral Table objects are created for all FROM-clause subqueries.
//	**     *  ON and USING clauses are shifted into WHERE statements
//	**     *  Wildcards "*" and "TABLE.*" in result sets are expanded.
//	**     *  Identifiers in expression are matched to tables.
//	**
//	** This routine acts recursively on all subqueries within the SELECT.
//	*/
func _sqlite3SelectPrep(tls *libc.TLS, pParse uintptr, p uintptr, pOuterNC uintptr) {
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		return
	}
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_HasTypeInfo) != 0 {
		return
	}
	_sqlite3SelectExpand(tls, pParse, p)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	_sqlite3ResolveSelectNames(tls, pParse, p, pOuterNC)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	_sqlite3SelectAddTypeInfo(tls, pParse, p)
}

// C documentation
//
//	/*
//	** Analyze the arguments to aggregate functions.  Create new pAggInfo->aCol[]
//	** entries for columns that are arguments to aggregate functions but which
//	** are not otherwise used.
//	**
//	** The aCol[] entries in AggInfo prior to nAccumulator are columns that
//	** are referenced outside of aggregate functions.  These might be columns
//	** that are part of the GROUP by clause, for example.  Other database engines
//	** would throw an error if there is a column reference that is not in the
//	** GROUP BY clause and that is not part of an aggregate function argument.
//	** But SQLite allows this.
//	**
//	** The aCol[] entries beginning with the aCol[nAccumulator] and following
//	** are column references that are used exclusively as arguments to
//	** aggregate functions.  This routine is responsible for computing
//	** (or recomputing) those aCol[] entries.
//	*/
func _analyzeAggFuncArgs(tls *libc.TLS, pAggInfo uintptr, pNC uintptr) {
	var i int32
	var pExpr uintptr
	_, _ = i, pExpr
	*(*int32)(unsafe.Pointer(pNC + 24)) |= int32(NC_InAggFunc)
	i = 0
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
			break
		}
		pExpr = (*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24))).FpFExpr
		_sqlite3ExprAnalyzeAggList(tls, pNC, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
		if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
			_sqlite3ExprAnalyzeAggList(tls, pNC, *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 20)))
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
			_sqlite3ExprAnalyzeAggregates(tls, pNC, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FpFilter)
		}
		goto _1
	_1:
		;
		i++
	}
	*(*int32)(unsafe.Pointer(pNC + 24)) &= ^libc.Int32FromInt32(NC_InAggFunc)
}

// C documentation
//
//	/*
//	** An index on expressions is being used in the inner loop of an
//	** aggregate query with a GROUP BY clause.  This routine attempts
//	** to adjust the AggInfo object to take advantage of index and to
//	** perhaps use the index as a covering index.
//	**
//	*/
func _optimizeAggregateUseOfIndexedExpr(tls *libc.TLS, pParse uintptr, pSelect uintptr, pAggInfo uintptr, pNC uintptr) {
	var j, k, mx int32
	_, _, _ = j, k, mx
	(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator
	if int32((*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn) > 0 {
		mx = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpGroupBy)).FnExpr - int32(1)
		j = 0
		for {
			if !(j < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
				break
			}
			k = int32((*(*TAggInfo_col)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(j)*16))).FiSorterColumn)
			if k > mx {
				mx = k
			}
			goto _1
		_1:
			;
			j++
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn = uint16(mx + int32(1))
	}
	_analyzeAggFuncArgs(tls, pAggInfo, pNC)
	_ = pSelect
	_ = pParse
}

// C documentation
//
//	/*
//	** Walker callback for aggregateConvertIndexedExprRefToColumn().
//	*/
func _aggregateIdxEprRefToColCallback(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var pAggInfo, pCol uintptr
	_, _ = pAggInfo, pCol
	_ = pWalker
	if (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
		return WRC_Continue
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_COLUMN) {
		return WRC_Continue
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_FUNCTION) {
		return WRC_Continue
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IF_NULL_ROW) {
		return WRC_Continue
	}
	pAggInfo = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
	if int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg) >= (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn {
		return WRC_Continue
	}
	pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)*16
	(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_AGG_COLUMN)
	(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TAggInfo_col)(unsafe.Pointer(pCol)).FiTable
	(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = (*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn
	*(*Tu32)(unsafe.Pointer(pExpr + 4)) &= uint32(^(libc.Int32FromInt32(EP_Skip) | libc.Int32FromInt32(EP_Collate) | libc.Int32FromInt32(EP_Unlikely)))
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** Convert every pAggInfo->aFunc[].pExpr such that any node within
//	** those expressions that has pAppInfo set is changed into a TK_AGG_COLUMN
//	** opcode.
//	*/
func _aggregateConvertIndexedExprRefToColumn(tls *libc.TLS, pAggInfo uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var _ /* w at bp+0 */ TWalker
	_ = i
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_aggregateIdxEprRefToColCallback)
	i = 0
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
			break
		}
		_sqlite3WalkExpr(tls, bp, (*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24))).FpFExpr)
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Allocate a block of registers so that there is one register for each
//	** pAggInfo->aCol[] and pAggInfo->aFunc[] entry in pAggInfo.  The first
//	** register in this block is stored in pAggInfo->iFirstReg.
//	**
//	** This routine may only be called once for each AggInfo object.  Prior
//	** to calling this routine:
//	**
//	**     *  The aCol[] and aFunc[] arrays may be modified
//	**     *  The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used
//	**
//	** After calling this routine:
//	**
//	**     *  The aCol[] and aFunc[] arrays are fixed
//	**     *  The AggInfoColumnReg() and AggInfoFuncReg() macros may be used
//	**
//	*/
func _assignAggregateRegisters(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	(*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	*(*int32)(unsafe.Pointer(pParse + 44)) += (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn + (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc
}

// C documentation
//
//	/*
//	** Reset the aggregate accumulator.
//	**
//	** The aggregate accumulator is a set of memory cells that hold
//	** intermediate results while calculating an aggregate.  This
//	** routine generates code that stores NULLs in all of those memory
//	** cells.
//	*/
func _resetAccumulator(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, nExtra, nReg int32
	var pE, pFunc, pKeyInfo, pKeyInfo1, pOBList, v uintptr
	_, _, _, _, _, _, _, _, _ = i, nExtra, nReg, pE, pFunc, pKeyInfo, pKeyInfo1, pOBList, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	nReg = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc + (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn
	if nReg == 0 {
		return
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+nReg-int32(1))
	pFunc = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
	i = libc.Int32FromInt32(0)
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
			break
		}
		if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct >= 0 {
			pE = (*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr
			if *(*uintptr)(unsafe.Pointer(pE + 20)) == uintptr(0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pE + 20)))).FnExpr != int32(1) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21431, 0)
				(*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct = -int32(1)
			} else {
				pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, *(*uintptr)(unsafe.Pointer(pE + 20)), 0, 0)
				(*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistAddr = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct, 0, 0, pKeyInfo, -int32(8))
				_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21482, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFunc)).FzName))
			}
		}
		if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiOBTab >= 0 {
			nExtra = 0
			pOBList = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr)).FpLeft + 20))
			if !((*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBUnique != 0) {
				nExtra++ /* One extra column for the OP_Sequence */
			}
			if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBPayload != 0 {
				/* extra columns for the function arguments */
				nExtra += (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr + 20)))).FnExpr
			}
			if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FbUseSubtype != 0 {
				nExtra += (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr + 20)))).FnExpr
			}
			pKeyInfo1 = _sqlite3KeyInfoFromExprList(tls, pParse, pOBList, 0, nExtra)
			if !((*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBUnique != 0) && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
				(*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnKeyField++
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiOBTab, (*TExprList)(unsafe.Pointer(pOBList)).FnExpr+nExtra, 0, pKeyInfo1, -int32(8))
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21515, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFunc)).FzName))
		}
		goto _1
	_1:
		;
		i++
		pFunc += 24
	}
}

// C documentation
//
//	/*
//	** Invoke the OP_AggFinalize opcode for every aggregate function
//	** in the AggInfo structure.
//	*/
func _finalizeAggFunctions(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	var i, iBaseCol, iTop, j, nArg, nKey, regAgg, regSubtype, v4 int32
	var pF, pList, v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = i, iBaseCol, iTop, j, nArg, nKey, pF, pList, regAgg, regSubtype, v, v4
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	i = 0
	pF = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
			break
		}
		pList = *(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFExpr + 20))
		if (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab >= 0 { /* Loop counter */
			nArg = (*TExprList)(unsafe.Pointer(pList)).FnExpr
			regAgg = _sqlite3GetTempRange(tls, pParse, nArg)
			if int32((*TAggInfo_func)(unsafe.Pointer(pF)).FbOBPayload) == 0 {
				nKey = 0
			} else {
				nKey = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFExpr)).FpLeft + 20)))).FnExpr
				if !((*TAggInfo_func)(unsafe.Pointer(pF)).FbOBUnique != 0) {
					nKey++
				}
			}
			iTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab)
			j = nArg - int32(1)
			for {
				if !(j >= 0) {
					break
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab, nKey+j, regAgg+j)
				goto _2
			_2:
				;
				j--
			}
			if (*TAggInfo_func)(unsafe.Pointer(pF)).FbUseSubtype != 0 {
				regSubtype = _sqlite3GetTempReg(tls, pParse)
				iBaseCol = nKey + nArg + libc.BoolInt32(int32((*TAggInfo_func)(unsafe.Pointer(pF)).FbOBPayload) == 0 && int32((*TAggInfo_func)(unsafe.Pointer(pF)).FbOBUnique) == 0)
				j = nArg - int32(1)
				for {
					if !(j >= 0) {
						break
					}
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab, iBaseCol+j, regSubtype)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_SetSubtype), regSubtype, regAgg+j)
					goto _3
				_3:
					;
					j--
				}
				_sqlite3ReleaseTempReg(tls, pParse, regSubtype)
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_AggStep), 0, regAgg, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn+i)
			_sqlite3VdbeAppendP4(tls, v, (*TAggInfo_func)(unsafe.Pointer(pF)).FpFunc, -int32(7))
			_sqlite3VdbeChangeP5(tls, v, uint16(uint8(uint8(nArg))))
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab, iTop+int32(1))
			_sqlite3VdbeJumpHere(tls, v, iTop)
			_sqlite3ReleaseTempRange(tls, pParse, regAgg, nArg)
		}
		if pList != 0 {
			v4 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
		} else {
			v4 = 0
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AggFinal), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn+i, v4)
		_sqlite3VdbeAppendP4(tls, v, (*TAggInfo_func)(unsafe.Pointer(pF)).FpFunc, -int32(7))
		goto _1
	_1:
		;
		i++
		pF += 24
	}
}

// C documentation
//
//	/*
//	** Generate code that will update the accumulator memory cells for an
//	** aggregate based on the current cursor position.
//	**
//	** If regAcc is non-zero and there are no min() or max() aggregates
//	** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
//	** registers if register regAcc contains 0. The caller will take care
//	** of setting and clearing regAcc.
//	**
//	** For an ORDER BY aggregate, the actual accumulator memory cell update
//	** is deferred until after all input rows have been received, so that they
//	** can be run in the requested order.  In that case, instead of invoking
//	** OP_AggStep to update the accumulator, just add the arguments that would
//	** have been passed into OP_AggStep into the sorting ephemeral table
//	** (along with the appropriate sort key).
//	*/
func _updateAccumulator(tls *libc.TLS, pParse uintptr, regAcc int32, pAggInfo uintptr, eDistinctType int32) {
	var addrHitTest, addrNext, i, j, jj, kk, nArg, regAgg, regAggSz, regBase, regDistinct, regHit, v2, v4, v7 int32
	var pC, pColl, pF, pFilter, pItem, pList, pOBList, v, v3, v8 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrHitTest, addrNext, i, j, jj, kk, nArg, pC, pColl, pF, pFilter, pItem, pList, pOBList, regAgg, regAggSz, regBase, regDistinct, regHit, v, v2, v3, v4, v7, v8
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	regHit = 0
	addrHitTest = 0
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(1)
	i = 0
	pF = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
			break
		}
		addrNext = 0
		regAggSz = 0
		regDistinct = 0
		pList = *(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFExpr + 20))
		if (*TExpr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
			pFilter = (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFExpr)).Fy)))).FpFilter
			if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 && (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 && regAcc != 0 {
				/* If regAcc==0, there there exists some min() or max() function
				 ** without a FILTER clause that will ensure the magnet registers
				 ** are populated. */
				if regHit == 0 {
					v3 = pParse + 44
					*(*int32)(unsafe.Pointer(v3))++
					v2 = *(*int32)(unsafe.Pointer(v3))
					regHit = v2
				}
				/* If this is the first row of the group (regAcc contains 0), clear the
				 ** "magnet" register regHit so that the accumulator registers
				 ** are populated if the FILTER clause jumps over the the
				 ** invocation of min() or max() altogether. Or, if this is not
				 ** the first row (regAcc contains 1), set the magnet register so that
				 ** the accumulators are not populated unless the min()/max() is invoked
				 ** and indicates that they should be.  */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regAcc, regHit)
			}
			addrNext = _sqlite3VdbeMakeLabel(tls, pParse)
			_sqlite3ExprIfFalse(tls, pParse, pFilter, addrNext, int32(SQLITE_JUMPIFNULL))
		}
		if (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab >= 0 { /* The ORDER BY clause */
			nArg = (*TExprList)(unsafe.Pointer(pList)).FnExpr
			pOBList = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFExpr)).FpLeft + 20))
			regAggSz = (*TExprList)(unsafe.Pointer(pOBList)).FnExpr
			if !((*TAggInfo_func)(unsafe.Pointer(pF)).FbOBUnique != 0) {
				regAggSz++ /* One register for OP_Sequence */
			}
			if (*TAggInfo_func)(unsafe.Pointer(pF)).FbOBPayload != 0 {
				regAggSz += nArg
			}
			if (*TAggInfo_func)(unsafe.Pointer(pF)).FbUseSubtype != 0 {
				regAggSz += nArg
			}
			regAggSz++ /* One extra register to hold result of MakeRecord */
			regAgg = _sqlite3GetTempRange(tls, pParse, regAggSz)
			regDistinct = regAgg
			_sqlite3ExprCodeExprList(tls, pParse, pOBList, regAgg, 0, uint8(SQLITE_ECEL_DUP))
			jj = (*TExprList)(unsafe.Pointer(pOBList)).FnExpr
			if !((*TAggInfo_func)(unsafe.Pointer(pF)).FbOBUnique != 0) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab, regAgg+jj)
				jj++
			}
			if (*TAggInfo_func)(unsafe.Pointer(pF)).FbOBPayload != 0 {
				regDistinct = regAgg + jj
				_sqlite3ExprCodeExprList(tls, pParse, pList, regDistinct, 0, uint8(SQLITE_ECEL_DUP))
				jj += nArg
			}
			if (*TAggInfo_func)(unsafe.Pointer(pF)).FbUseSubtype != 0 {
				if (*TAggInfo_func)(unsafe.Pointer(pF)).FbOBPayload != 0 {
					v4 = regDistinct
				} else {
					v4 = regAgg
				}
				regBase = v4
				kk = 0
				for {
					if !(kk < nArg) {
						break
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_GetSubtype), regBase+kk, regAgg+jj)
					goto _5
				_5:
					;
					kk++
					jj++
				}
			}
		} else {
			if pList != 0 {
				nArg = (*TExprList)(unsafe.Pointer(pList)).FnExpr
				regAgg = _sqlite3GetTempRange(tls, pParse, nArg)
				regDistinct = regAgg
				_sqlite3ExprCodeExprList(tls, pParse, pList, regAgg, 0, uint8(SQLITE_ECEL_DUP))
			} else {
				nArg = 0
				regAgg = 0
			}
		}
		if (*TAggInfo_func)(unsafe.Pointer(pF)).FiDistinct >= 0 && pList != 0 {
			if addrNext == 0 {
				addrNext = _sqlite3VdbeMakeLabel(tls, pParse)
			}
			(*TAggInfo_func)(unsafe.Pointer(pF)).FiDistinct = _codeDistinct(tls, pParse, eDistinctType, (*TAggInfo_func)(unsafe.Pointer(pF)).FiDistinct, addrNext, pList, regDistinct)
		}
		if (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab >= 0 {
			/* Insert a new record into the ORDER BY table */
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regAgg, regAggSz-int32(1), regAgg+regAggSz-int32(1))
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), (*TAggInfo_func)(unsafe.Pointer(pF)).FiOBTab, regAgg+regAggSz-int32(1), regAgg, regAggSz-int32(1))
			_sqlite3ReleaseTempRange(tls, pParse, regAgg, regAggSz)
		} else {
			/* Invoke the AggStep function */
			if (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pF)).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 {
				pColl = uintptr(0)
				/* pList!=0 if pF->pFunc has NEEDCOLL */
				j = 0
				pItem = pList + 8
				for {
					if !(!(pColl != 0) && j < nArg) {
						break
					}
					pColl = _sqlite3ExprCollSeq(tls, pParse, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
					goto _6
				_6:
					;
					j++
					pItem += 20
				}
				if !(pColl != 0) {
					pColl = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
				}
				if regHit == 0 && (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 {
					v8 = pParse + 44
					*(*int32)(unsafe.Pointer(v8))++
					v7 = *(*int32)(unsafe.Pointer(v8))
					regHit = v7
				}
				_sqlite3VdbeAddOp4(tls, v, int32(OP_CollSeq), regHit, 0, 0, pColl, -int32(2))
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_AggStep), 0, regAgg, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn+i)
			_sqlite3VdbeAppendP4(tls, v, (*TAggInfo_func)(unsafe.Pointer(pF)).FpFunc, -int32(7))
			_sqlite3VdbeChangeP5(tls, v, uint16(uint8(uint8(nArg))))
			_sqlite3ReleaseTempRange(tls, pParse, regAgg, nArg)
		}
		if addrNext != 0 {
			_sqlite3VdbeResolveLabel(tls, v, addrNext)
		}
		goto _1
	_1:
		;
		i++
		pF += 24
	}
	if regHit == 0 && (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 {
		regHit = regAcc
	}
	if regHit != 0 {
		addrHitTest = _sqlite3VdbeAddOp1(tls, v, int32(OP_If), regHit)
	}
	i = 0
	pC = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator) {
			break
		}
		_sqlite3ExprCode(tls, pParse, (*TAggInfo_col)(unsafe.Pointer(pC)).FpCExpr, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+i)
		goto _9
	_9:
		;
		i++
		pC += 16
	}
	(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(0)
	if addrHitTest != 0 {
		_sqlite3VdbeJumpHereOrPopInst(tls, v, addrHitTest)
	}
}

// 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 int32((*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 + 56))&0x3>>0)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))))
		if bCover != 0 {
			v1 = __ccgo_ts + 21548
		} else {
			v1 = __ccgo_ts + 1672
		}
		if bCover != 0 {
			v2 = (*TIndex)(unsafe.Pointer(pIdx)).FzName
		} else {
			v2 = __ccgo_ts + 1672
		}
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21571, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, v1, v2))
	}
}

// C documentation
//
//	/*
//	** sqlite3WalkExpr() callback used by havingToWhere().
//	**
//	** If the node passed to the callback is a TK_AND node, return
//	** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
//	**
//	** Otherwise, return WRC_Prune. In this case, also check if the
//	** sub-expression matches the criteria for being moved to the WHERE
//	** clause. If so, add it to the WHERE clause and replace the sub-expression
//	** within the HAVING expression with a constant "1".
//	*/
func _havingToWhereExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var db, pNew, pS, pWhere uintptr
	var t TExpr
	_, _, _, _, _ = db, pNew, pS, pWhere, t
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_AND) {
		pS = *(*uintptr)(unsafe.Pointer(pWalker + 24))
		/* This routine is called before the HAVING clause of the current
		 ** SELECT is analyzed for aggregates. So if pExpr->pAggInfo is set
		 ** here, it indicates that the expression is a correlated reference to a
		 ** column from an outer aggregate query, or an aggregate function that
		 ** belongs to an outer query. Do not move the expression to the WHERE
		 ** clause in this obscure case, as doing so may corrupt the outer Select
		 ** statements AggInfo structure.  */
		if _sqlite3ExprIsConstantOrGroupBy(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, pExpr, (*TSelect)(unsafe.Pointer(pS)).FpGroupBy) != 0 && libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_IsFalse)) == uint32(EP_IsFalse)) == 0 && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
			db = (*TParse)(unsafe.Pointer((*TWalker)(unsafe.Pointer(pWalker)).FpParse)).Fdb
			pNew = _sqlite3Expr(tls, db, int32(TK_INTEGER), __ccgo_ts+9564)
			if pNew != 0 {
				pWhere = (*TSelect)(unsafe.Pointer(pS)).FpWhere
				t = *(*TExpr)(unsafe.Pointer(pNew))
				*(*TExpr)(unsafe.Pointer(pNew)) = *(*TExpr)(unsafe.Pointer(pExpr))
				*(*TExpr)(unsafe.Pointer(pExpr)) = t
				pNew = _sqlite3ExprAnd(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, pWhere, pNew)
				(*TSelect)(unsafe.Pointer(pS)).FpWhere = pNew
				(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1)
			}
		}
		return int32(WRC_Prune)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Transfer eligible terms from the HAVING clause of a query, which is
//	** processed after grouping, to the WHERE clause, which is processed before
//	** grouping. For example, the query:
//	**
//	**   SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
//	**
//	** can be rewritten as:
//	**
//	**   SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
//	**
//	** A term of the HAVING expression is eligible for transfer if it consists
//	** entirely of constants and expressions that are also GROUP BY terms that
//	** use the "BINARY" collation sequence.
//	*/
func _havingToWhere(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* sWalker at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_havingToWhereExprCb)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = p
	_sqlite3WalkExpr(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpHaving)
}

// 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 uintptr
	var v1 int32
	_, _, _ = pItem, pS1, v1
	if (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pThis)).FpSelect)).FselFlags&uint32(SF_PushDown) != 0 {
		return uintptr(0)
	}
	for iFirst < iEnd {
		v1 = iFirst
		iFirst++
		pItem = pTabList + 8 + uintptr(v1)*72
		if (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect == uintptr(0) {
			continue
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x20>>5)) != 0 {
			continue
		}
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzName == uintptr(0) {
			continue
		}
		if (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpTab)).FpSchema != (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pThis)).FpTab)).FpSchema {
			continue
		}
		if Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, (*TSrcItem)(unsafe.Pointer(pThis)).FzName) != 0 {
			continue
		}
		pS1 = (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect
		if (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpTab)).FpSchema == uintptr(0) && (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pThis)).FpSelect)).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((*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)).FselFlags&uint32(SF_PushDown) != 0 {
			/* The view was modified by some other optimization such as
			 ** pushDownWhereTerms() */
			continue
		}
		return pItem
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Deallocate a single AggInfo object
//	*/
func _agginfoFree(tls *libc.TLS, db uintptr, pArg uintptr) {
	var p uintptr
	_ = p
	p = pArg
	_sqlite3DbFree(tls, db, (*TAggInfo)(unsafe.Pointer(p)).FaCol)
	_sqlite3DbFree(tls, db, (*TAggInfo)(unsafe.Pointer(p)).FaFunc)
	_sqlite3DbFreeNN(tls, db, p)
}

// 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.
//	**
//	** Return TRUE if the optimization is undertaken.
//	*/
func _countOfViewOptimization(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	var db, pCount, pExpr, pPrior, pSub, pTerm, v1 uintptr
	_, _, _, _, _, _, _ = db, pCount, pExpr, 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 int32((*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+17251) != 0 {
		return 0
	} /* Is count() */
	if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != 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&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		return 0
	} /* Not a window function */
	pSub = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSelect
	if pSub == uintptr(0) {
		return 0
	} /* The FROM is a subquery */
	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 int32((*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&uint32(SF_Aggregate) != 0 {
			return 0
		} /* Not an aggregate */
		/* 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 = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSelect
	(*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSelect = uintptr(0)
	_sqlite3SrcListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpSrc)
	(*TSelect)(unsafe.Pointer(p)).FpSrc = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(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)(unsafe.Pointer(pSub + 4)) |= uint32(SF_Aggregate)
		*(*Tu32)(unsafe.Pointer(pSub + 4)) &= uint32(^libc.Int32FromInt32(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)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(SF_Aggregate))
	return int32(1)
}

// 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)*72
		if p1 == p0 {
			goto _1
		}
		if (*TSrcItem)(unsafe.Pointer(p0)).FpTab == (*TSrcItem)(unsafe.Pointer(p1)).FpTab && 0 == Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(p0)).FzAlias, (*TSrcItem)(unsafe.Pointer(p1)).FzAlias) {
			return int32(1)
		}
		if (*TSrcItem)(unsafe.Pointer(p1)).FpSelect != 0 && (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(p1)).FpSelect)).FselFlags&uint32(SF_NestedFrom) != uint32(0) && _sameSrcAlias(tls, p0, (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(p1)).FpSelect)).FpSrc) != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// 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)*72
	if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x100>>8)) != 0 {
		pCteUse = *(*uintptr)(unsafe.Pointer(pItem + 68))
		if int32((*TCteUse)(unsafe.Pointer(pCteUse)).FeM10d) == M10d_Yes {
			return 0
		} /* (2a) */
		if (*TCteUse)(unsafe.Pointer(pCteUse)).FnUse >= int32(2) && int32((*TCteUse)(unsafe.Pointer(pCteUse)).FeM10d) != int32(M10d_No) {
			return 0
		} /* (2b) */
	}
	if int32((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
		return 0
	} /* (3)  */
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&uint32(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 int32((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + 1*72))).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 int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0 {
			return 0
		} /* (1c-ii) */
		if i == 0 {
			break
		}
		i--
		pItem -= 72
		if (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect != uintptr(0) {
			return 0
		} /* (1c-i) */
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Generate 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.
//	*/
func _sqlite3Select(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var addr1, addrEnd, addrGosub, addrOutputRow, addrReset, addrSetAbort, addrSortingIdx, addrTop, addrTopOfLoop, eDist, eDist1, groupBySort, i, iAMem, iAbortFlag, iBMem, iBreak, iCont, iCsr, iDb, iEnd, iUseFlag, ii, ii1, isAgg, j, k, nCol, nGroupBy, onceAddr, orderByGrp, rc, regAcc, regBase, regGosub, regOutputRow, regRecord, regReset, sortOut, sortPTab, topAddr, v11, v14, v17, v22, v24, v25, v30, v31, v32, v34, v36, v38, v40, v42, v43, v47, v48, v52, v56, v58 int32
	var db, p0, pAggInfo, pBest, pCol, pCteUse, pCteUse1, pDistinct, pDistinct1, pEList, pExpr, pF, pF1, pGroupBy, pHaving, pI2, pIdx, pItem, pItem1, pItem2, pKeyInfo, pKeyInfo1, pKeyInfo2, pPrior, pSub, pSub1, pTab, pTab1, pTabList, pWInfo, pWhere, pWin, v, zSavedAuthContext, v1, v12, v13, v15, v16, v18, v23, v26, v33, v35, v37, v39, v41, v44, v49, v51, v53, v57, p21, p3, p4, p6, p7, p9 uintptr
	var distFlag, distFlag1, wctrlFlags Tu16
	var iRoot TPgno
	var minMaxFlag, sortFlags Tu8
	var _ /* dest at bp+56 */ TSelectDest
	var _ /* pMinMaxOrderBy at bp+52 */ uintptr
	var _ /* sDistinct at bp+0 */ TDistinctCtx
	var _ /* sNC at bp+84 */ TNameContext
	var _ /* sSort at bp+12 */ TSortCtx
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addrEnd, addrGosub, addrOutputRow, addrReset, addrSetAbort, addrSortingIdx, addrTop, addrTopOfLoop, db, distFlag, distFlag1, eDist, eDist1, groupBySort, i, iAMem, iAbortFlag, iBMem, iBreak, iCont, iCsr, iDb, iEnd, iRoot, iUseFlag, ii, ii1, isAgg, j, k, minMaxFlag, nCol, nGroupBy, onceAddr, orderByGrp, p0, pAggInfo, pBest, pCol, pCteUse, pCteUse1, pDistinct, pDistinct1, pEList, pExpr, pF, pF1, pGroupBy, pHaving, pI2, pIdx, pItem, pItem1, pItem2, pKeyInfo, pKeyInfo1, pKeyInfo2, pPrior, pSub, pSub1, pTab, pTab1, pTabList, pWInfo, pWhere, pWin, rc, regAcc, regBase, regGosub, regOutputRow, regRecord, regReset, sortFlags, sortOut, sortPTab, topAddr, v, wctrlFlags, zSavedAuthContext, v1, v11, v12, v13, v14, v15, v16, v17, v18, v22, v23, v24, v25, v26, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v47, v48, v49, v51, v52, v53, v56, v57, v58, p21, p3, p4, p6, p7, p9 /* 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)(unsafe.Pointer(bp + 52)) = 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)
	}
	if int32((*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)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(SF_Distinct))
		*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(SF_NoopOrderBy)
	}
	_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)).FpTab)).FzName
			}
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21583, libc.VaList(bp+128, 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)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(SF_UFSrcCheck))
	}
	if int32((*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+12, 0, uint32(40))
	(*(*TSortCtx)(unsafe.Pointer(bp + 12))).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
	 */
	i = 0
	for {
		if !(!((*TSelect)(unsafe.Pointer(p)).FpPrior != 0) && i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		pItem = pTabList + 8 + uintptr(i)*72
		pSub = (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect
		pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
		/* 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.
		 */
		if int32((*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, int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LTORJ)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_SimplifyJoin)) == uint32(0) {
			if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
				if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
					p3 = pItem + 36
					*(*Tu8)(unsafe.Pointer(p3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(JT_LEFT))
				} else {
					p4 = pItem + 36
					*(*Tu8)(unsafe.Pointer(p4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p4))) & ^(libc.Int32FromInt32(JT_LEFT) | libc.Int32FromInt32(JT_OUTER)))
					_unsetJoinExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor, 0)
				}
			}
			if int32((*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)*72
					if int32((*TSrcItem)(unsafe.Pointer(pI2)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
						if int32((*TSrcItem)(unsafe.Pointer(pI2)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
							p6 = pI2 + 36
							*(*Tu8)(unsafe.Pointer(p6)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p6))) & ^libc.Int32FromInt32(JT_RIGHT))
						} else {
							p7 = pI2 + 36
							*(*Tu8)(unsafe.Pointer(p7)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p7))) & ^(libc.Int32FromInt32(JT_RIGHT) | libc.Int32FromInt32(JT_OUTER)))
							_unsetJoinExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pI2)).FiCursor, int32(1))
						}
					}
					goto _5
				_5:
					;
					j++
				}
				j = (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc - int32(1)
				for {
					if !(j >= 0) {
						break
					}
					p9 = pTabList + 8 + uintptr(j)*72 + 36
					*(*Tu8)(unsafe.Pointer(p9)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p9))) & ^libc.Int32FromInt32(JT_LTORJ))
					if int32((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*72))).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
						break
					}
					goto _8
				_8:
					;
					j--
				}
			}
		}
		/* 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+21637, libc.VaList(bp+128, 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(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x100>>8)) != 0 && int32((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 68)))).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
		}
		/* 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
		 **
		 ** 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&uint32(SF_OrderByReqd) == uint32(0) && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_OrderByReqd) == uint32(0) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(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) || int32((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + 1*72))).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0) {
			goto _2
		}
		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 !(int32((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) <= libc.Int32FromInt32(SRT_Fifo)) {
			(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
		}
		goto _2
	_2:
		;
		i++
	}
	/* Handle compound SELECT statements using the separate multiSelect()
	 ** procedure.
	 */
	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
	}
	/* Do the WHERE-clause constant propagation optimization if this is
	 ** a join.  No need to speed time on this operation for non-join queries
	 ** as the equivalent optimization will be handled by query planner in
	 ** sqlite3WhereBegin().
	 */
	if (*TSelect)(unsafe.Pointer(p)).FpWhere != uintptr(0) && int32((*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpWhere)).Fop) == int32(TK_AND) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_PropagateConst)) == uint32(0) && _propagateConstants(tls, pParse, p) != 0 {
	} else {
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(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
	}
	/* For each term in the FROM clause, do two things:
	 ** (1) Authorized unreferenced tables
	 ** (2) Generate code for all sub-queries
	 */
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		pItem1 = pTabList + 8 + uintptr(i)*72
		/* 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) {
			_sqlite3AuthCheck(tls, pParse, int32(SQLITE_READ), (*TSrcItem)(unsafe.Pointer(pItem1)).FzName, __ccgo_ts+1672, (*TSrcItem)(unsafe.Pointer(pItem1)).FzDatabase)
		}
		/* Generate code for all sub-queries in the FROM clause
		 */
		pSub1 = (*TSrcItem)(unsafe.Pointer(pItem1)).FpSelect
		if pSub1 == uintptr(0) || (*TSrcItem)(unsafe.Pointer(pItem1)).FaddrFillSub != 0 {
			goto _10
		}
		/* The code for a subquery should only be generated once. */
		/* 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)(unsafe.Pointer(pParse + 228)) += _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.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_PushDown)) == uint32(0) && (int32(uint32(*(*uint16)(unsafe.Pointer(pItem1 + 36 + 4))&0x100>>8)) == 0 || int32((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 68)))).FeM10d) != M10d_Yes && (*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 68)))).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.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(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 code to implement the subquery
		 */
		if _fromClauseTermCanBeCoroutine(tls, pParse, pTabList, i, int32((*TSelect)(unsafe.Pointer(p)).FselFlags)) != 0 {
			/* Implement a co-routine that will return a single row of the result
			 ** set on each invocation.
			 */
			addrTop = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
			v12 = pParse + 44
			*(*int32)(unsafe.Pointer(v12))++
			v11 = *(*int32)(unsafe.Pointer(v12))
			(*TSrcItem)(unsafe.Pointer(pItem1)).FregReturn = v11
			_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), (*TSrcItem)(unsafe.Pointer(pItem1)).FregReturn, 0, addrTop)
			(*TSrcItem)(unsafe.Pointer(pItem1)).FaddrFillSub = addrTop
			_sqlite3SelectDestInit(tls, bp+56, int32(SRT_Coroutine), (*TSrcItem)(unsafe.Pointer(pItem1)).FregReturn)
			_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21677, libc.VaList(bp+128, pItem1))
			_sqlite3Select(tls, pParse, pSub1, bp+56)
			(*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem1)).FpTab)).FnRowLogEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
			libc.SetBitFieldPtr16Uint32(pItem1+36+4, libc.Uint32FromInt32(1), 5, 0x20)
			(*TSrcItem)(unsafe.Pointer(pItem1)).FregResult = (*(*TSelectDest)(unsafe.Pointer(bp + 56))).FiSdst
			_sqlite3VdbeEndCoroutine(tls, v, (*TSrcItem)(unsafe.Pointer(pItem1)).FregReturn)
			_sqlite3VdbeJumpHere(tls, v, addrTop-int32(1))
			_sqlite3ClearTempRegCache(tls, pParse)
		} else {
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem1 + 36 + 4))&0x100>>8)) != 0 && (*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 68)))).FaddrM9e > 0 {
				/* This is a CTE for which materialization code has already been
				 ** generated.  Invoke the subroutine to compute the materialization,
				 ** the make the pItem->iCursor be a copy of the ephemeral table that
				 ** holds the result of the materialization. */
				pCteUse = *(*uintptr)(unsafe.Pointer(pItem1 + 68))
				_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 {
				v13 = _isSelfJoinView(tls, pTabList, pItem1, 0, i)
				pPrior = v13
				if v13 != uintptr(0) {
					/* This view has already been materialized by a prior entry in
					 ** this same FROM clause.  Reuse it. */
					if (*TSrcItem)(unsafe.Pointer(pPrior)).FaddrFillSub != 0 {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSrcItem)(unsafe.Pointer(pPrior)).FregReturn, (*TSrcItem)(unsafe.Pointer(pPrior)).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((*TSrcItem)(unsafe.Pointer(pPrior)).FpSelect)).FnSelectRow
				} else {
					onceAddr = 0
					v15 = pParse + 44
					*(*int32)(unsafe.Pointer(v15))++
					v14 = *(*int32)(unsafe.Pointer(v15))
					(*TSrcItem)(unsafe.Pointer(pItem1)).FregReturn = v14
					topAddr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
					(*TSrcItem)(unsafe.Pointer(pItem1)).FaddrFillSub = topAddr + int32(1)
					libc.SetBitFieldPtr16Uint32(pItem1+36+4, libc.Uint32FromInt32(1), 4, 0x10)
					if int32(uint32(*(*uint16)(unsafe.Pointer(pItem1 + 36 + 4))&0x8>>3)) == 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+56, int32(SRT_EphemTab), (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor)
					_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21692, libc.VaList(bp+128, pItem1))
					_sqlite3Select(tls, pParse, pSub1, bp+56)
					(*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem1)).FpTab)).FnRowLogEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
					if onceAddr != 0 {
						_sqlite3VdbeJumpHere(tls, v, onceAddr)
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Return), (*TSrcItem)(unsafe.Pointer(pItem1)).FregReturn, topAddr+int32(1))
					_sqlite3VdbeJumpHere(tls, v, topAddr)
					_sqlite3ClearTempRegCache(tls, pParse)
					if int32(uint32(*(*uint16)(unsafe.Pointer(pItem1 + 36 + 4))&0x100>>8)) != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pItem1 + 36 + 4))&0x8>>3)) == 0 {
						pCteUse1 = *(*uintptr)(unsafe.Pointer(pItem1 + 68))
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FaddrM9e = (*TSrcItem)(unsafe.Pointer(pItem1)).FaddrFillSub
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FregRtn = (*TSrcItem)(unsafe.Pointer(pItem1)).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)(unsafe.Pointer(pParse + 228)) -= _sqlite3SelectExprHeight(tls, p)
		(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedAuthContext
		goto _10
	_10:
		;
		i++
	}
	/* 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)(unsafe.Pointer(bp))).FisTnct = libc.BoolUint8((*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0))
	/* 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&uint32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) == uint32(SF_Distinct) && _sqlite3ExprListCompare(tls, (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy, pEList, -int32(1)) == 0 && (*TSelect)(unsafe.Pointer(p)).FpWin == uintptr(0) {
		*(*Tu32)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(SF_Distinct))
		v16 = _sqlite3ExprListDup(tls, db, pEList, 0)
		(*TSelect)(unsafe.Pointer(p)).FpGroupBy = v16
		pGroupBy = v16
		*(*Tu32)(unsafe.Pointer(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)(unsafe.Pointer(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.
	 */
	if (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy != 0 {
		pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy, 0, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
		v18 = pParse + 40
		v17 = *(*int32)(unsafe.Pointer(v18))
		*(*int32)(unsafe.Pointer(v18))++
		(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FiECursor = v17
		(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FaddrSortIndex = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FiECursor, (*TExprList)(unsafe.Pointer((*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy)).FnExpr+int32(1)+(*TExprList)(unsafe.Pointer(pEList)).FnExpr, 0, pKeyInfo, -int32(8))
	} else {
		(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FaddrSortIndex = -int32(1)
	}
	/* If the output is destined for a temporary table, open that table.
	 */
	if int32((*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)*20 + 8 + 4))&0x40>>6)) == 0) {
					break
				}
				_sqlite3ExprDelete(tls, db, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*20))).FpExpr)
				_sqlite3DbFree(tls, db, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*20))).FzEName)
				(*TExprList)(unsafe.Pointer(pEList)).FnExpr--
				goto _19
			_19:
				;
				ii--
			}
			ii = 0
			for {
				if !(ii < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
					break
				}
				if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(ii)*20 + 8 + 4))&0x40>>6)) == 0 {
					(*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*20))).FpExpr)).Fop = uint8(TK_NULL)
				}
				goto _20
			_20:
				;
				ii++
			}
		}
	}
	/* Set the limiter.
	 */
	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)(unsafe.Pointer(bp + 12))).FaddrSortIndex >= 0 {
		_sqlite3VdbeChangeOpcode(tls, v, (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FaddrSortIndex, uint8(OP_SorterOpen))
		p21 = bp + 12 + 32
		*(*Tu8)(unsafe.Pointer(p21)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p21))) | libc.Int32FromInt32(SORTFLAG_UseSorter))
	}
	/* Open an ephemeral index to use for the distinct set.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != 0 {
		v23 = pParse + 40
		v22 = *(*int32)(unsafe.Pointer(v23))
		*(*int32)(unsafe.Pointer(v23))++
		(*(*TDistinctCtx)(unsafe.Pointer(bp))).FtabTnct = v22
		(*(*TDistinctCtx)(unsafe.Pointer(bp))).FaddrTnct = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*(*TDistinctCtx)(unsafe.Pointer(bp))).FtabTnct, 0, 0, _sqlite3KeyInfoFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpEList, 0, 0), -int32(8))
		_sqlite3VdbeChangeP5(tls, v, uint16(BTREE_UNORDERED))
		(*(*TDistinctCtx)(unsafe.Pointer(bp))).FeTnctType = uint8(WHERE_DISTINCT_UNORDERED)
	} else {
		(*(*TDistinctCtx)(unsafe.Pointer(bp))).FeTnctType = uint8(WHERE_DISTINCT_NOOP)
	}
	if !(isAgg != 0) && pGroupBy == uintptr(0) {
		if (*(*TDistinctCtx)(unsafe.Pointer(bp))).FisTnct != 0 {
			v24 = int32(WHERE_WANT_DISTINCT)
		} else {
			v24 = 0
		}
		/* No aggregate functions and no GROUP BY clause */
		wctrlFlags = uint16(uint32(v24) | (*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)(unsafe.Pointer(bp + 12))).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 (*(*TDistinctCtx)(unsafe.Pointer(bp))).FisTnct != 0 && _sqlite3WhereIsDistinct(tls, pWInfo) != 0 {
			(*(*TDistinctCtx)(unsafe.Pointer(bp))).FeTnctType = uint8(_sqlite3WhereIsDistinct(tls, pWInfo))
		}
		if (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy != 0 {
			(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FnOBSat = _sqlite3WhereIsOrdered(tls, pWInfo)
			(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FlabelOBLopt = _sqlite3WhereOrderByLimitOptLabel(tls, pWInfo)
			if (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FnOBSat == (*TExprList)(unsafe.Pointer((*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy)).FnExpr {
				(*(*TSortCtx)(unsafe.Pointer(bp + 12))).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)(unsafe.Pointer(bp + 12))).FaddrSortIndex >= 0 && (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy == uintptr(0) {
			_sqlite3VdbeChangeToNoop(tls, v, (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FaddrSortIndex)
		}
		if pWin != 0 {
			addrGosub = _sqlite3VdbeMakeLabel(tls, pParse)
			iCont = _sqlite3VdbeMakeLabel(tls, pParse)
			iBreak = _sqlite3VdbeMakeLabel(tls, pParse)
			v26 = pParse + 44
			*(*int32)(unsafe.Pointer(v26))++
			v25 = *(*int32)(unsafe.Pointer(v26))
			regGosub = v25
			_sqlite3WindowCodeStep(tls, pParse, p, pWInfo, regGosub, addrGosub)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, iBreak)
			_sqlite3VdbeResolveLabel(tls, v, addrGosub)
			(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FlabelOBLopt = 0
			_selectInnerLoop(tls, pParse, p, -int32(1), bp+12, 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+12, 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 + 16))).FiAlias = uint16(0)
				goto _27
			_27:
				;
				k--
				pItem2 += 20
			}
			k = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			pItem2 = pGroupBy + 8
			for {
				if !(k > 0) {
					break
				}
				(*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem2 + 16))).FiAlias = uint16(0)
				goto _28
			_28:
				;
				k--
				pItem2 += 20
			}
			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 (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy != 0 && (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr == (*TExprList)(unsafe.Pointer((*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy)).FnExpr {
				/* The GROUP BY processing doesn't care whether rows are delivered in
				 ** ASC or DESC order - only that each group is returned contiguously.
				 ** So set the ASC/DESC flags in the GROUP BY to match those in the
				 ** ORDER BY to maximize the chances of rows being delivered in an
				 ** order that makes the ORDER BY redundant.  */
				ii1 = 0
				for {
					if !(ii1 < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
						break
					}
					sortFlags = uint8(int32((*(*TExprList_item)(unsafe.Pointer((*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy + 8 + uintptr(ii1)*20))).Ffg.FsortFlags) & int32(KEYINFO_ORDER_DESC))
					(*(*TExprList_item)(unsafe.Pointer(pGroupBy + 8 + uintptr(ii1)*20))).Ffg.FsortFlags = sortFlags
					goto _29
				_29:
					;
					ii1++
				}
				if _sqlite3ExprListCompare(tls, pGroupBy, (*(*TSortCtx)(unsafe.Pointer(bp + 12))).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(44))
		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+84, 0, uint32(36))
		(*(*TNameContext)(unsafe.Pointer(bp + 84))).FpParse = pParse
		(*(*TNameContext)(unsafe.Pointer(bp + 84))).FpSrcList = pTabList
		*(*uintptr)(unsafe.Pointer(bp + 84 + 8)) = pAggInfo
		if pGroupBy != 0 {
			v30 = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
		} else {
			v30 = 0
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn = uint16(v30)
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy = pGroupBy
		_sqlite3ExprAnalyzeAggList(tls, bp+84, pEList)
		_sqlite3ExprAnalyzeAggList(tls, bp+84, (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy)
		if pHaving != 0 {
			if pGroupBy != 0 {
				_havingToWhere(tls, pParse, p)
				pWhere = (*TSelect)(unsafe.Pointer(p)).FpWhere
			}
			_sqlite3ExprAnalyzeAggregates(tls, bp+84, 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)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr, bp+52)
		} else {
			minMaxFlag = uint8(WHERE_ORDERBY_NORMAL)
		}
		_analyzeAggFuncArgs(tls, pAggInfo, bp+84)
		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.
		 */
		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)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FiDistinct >= 0 && (*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr != uintptr(0) && (*TExpr)(unsafe.Pointer((*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr)).Fflags&uint32(EP_xIsSelect) == uint32(0) && *(*uintptr)(unsafe.Pointer((*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 20)) != uintptr(0) {
				pExpr = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 20)) + 8))).FpExpr
				pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
				pDistinct = _sqlite3ExprListDup(tls, db, pGroupBy, 0)
				pDistinct = _sqlite3ExprListAppend(tls, pParse, pDistinct, pExpr)
				if pDistinct != 0 {
					v31 = libc.Int32FromInt32(WHERE_WANT_DISTINCT) | libc.Int32FromInt32(WHERE_AGG_DISTINCT)
				} else {
					v31 = 0
				}
				distFlag = uint16(v31)
			}
			/* 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.
			 */
			v33 = pParse + 40
			v32 = *(*int32)(unsafe.Pointer(v33))
			*(*int32)(unsafe.Pointer(v33))++
			(*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx = v32
			pKeyInfo1 = _sqlite3KeyInfoFromExprList(tls, pParse, pGroupBy, 0, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn)
			addrSortingIdx = _sqlite3VdbeAddOp4(tls, v, int32(OP_SorterOpen), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, int32((*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn), 0, pKeyInfo1, -int32(8))
			/* Initialize memory locations used by GROUP BY aggregate processing
			 */
			v35 = pParse + 44
			*(*int32)(unsafe.Pointer(v35))++
			v34 = *(*int32)(unsafe.Pointer(v35))
			iUseFlag = v34
			v37 = pParse + 44
			*(*int32)(unsafe.Pointer(v37))++
			v36 = *(*int32)(unsafe.Pointer(v37))
			iAbortFlag = v36
			v39 = pParse + 44
			*(*int32)(unsafe.Pointer(v39))++
			v38 = *(*int32)(unsafe.Pointer(v39))
			regOutputRow = v38
			addrOutputRow = _sqlite3VdbeMakeLabel(tls, pParse)
			v41 = pParse + 44
			*(*int32)(unsafe.Pointer(v41))++
			v40 = *(*int32)(unsafe.Pointer(v41))
			regReset = v40
			addrReset = _sqlite3VdbeMakeLabel(tls, pParse)
			iAMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			*(*int32)(unsafe.Pointer(pParse + 44)) += (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			iBMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			*(*int32)(unsafe.Pointer(pParse + 44)) += (*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))
			/* 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 int32((*(*TDistinctCtx)(unsafe.Pointer(bp))).FisTnct) == int32(2) {
				v42 = int32(WHERE_DISTINCTBY)
			} else {
				v42 = int32(WHERE_GROUPBY)
			}
			if orderByGrp != 0 {
				v43 = int32(WHERE_SORTBYGROUP)
			} else {
				v43 = 0
			}
			pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, pGroupBy, pDistinct, p, uint16(v42|v43|int32(int32(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+84)
			}
			_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)(unsafe.Pointer(bp))).FisTnct != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) == uint32(0) {
					v44 = __ccgo_ts + 21708
				} else {
					v44 = __ccgo_ts + 21717
				}
				_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20560, libc.VaList(bp+128, v44))
				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 int32((*(*TAggInfo_col)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(i)*16))).FiSorterColumn) >= j {
						nCol++
						j++
					}
					goto _45
				_45:
					;
					i++
				}
				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)*16
					if int32((*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn) >= j {
						_sqlite3ExprCode(tls, pParse, (*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr, j+regBase)
						j++
					}
					goto _46
				_46:
					;
					i++
				}
				(*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)
				v49 = pParse + 40
				v48 = *(*int32)(unsafe.Pointer(v49))
				*(*int32)(unsafe.Pointer(v49))++
				v47 = v48
				sortPTab = v47
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdxPTab = v47
				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&uint32(libc.Int32FromInt32(SQLITE_GroupByOrder)) == uint32(0) && (groupBySort != 0 || _sqlite3WhereIsSorted(tls, pWInfo) != 0) {
				(*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy = uintptr(0)
				_sqlite3VdbeChangeToNoop(tls, v, (*(*TSortCtx)(unsafe.Pointer(bp + 12))).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
				}
				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)*20))).FpExpr, iBMem+j)
				}
				goto _50
			_50:
				;
				j++
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), iAMem, iBMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr, _sqlite3KeyInfoRef(tls, pKeyInfo1), -int32(8))
			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.
			 */
			_sqlite3ExprCodeMove(tls, pParse, iBMem, iAMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutputRow, addrOutputRow)
			_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+12, 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 int32(int32(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 {
			v51 = _isSimpleCount(tls, p, pAggInfo)
			pTab1 = v51
			if v51 != uintptr(0) {
				/* 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.
				 */
				iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab1)).FpSchema)
				v53 = pParse + 40
				v52 = *(*int32)(unsafe.Pointer(v53))
				*(*int32)(unsafe.Pointer(v53))++
				iCsr = v52                                     /* 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, iDb)
				_sqlite3TableLock(tls, pParse, iDb, (*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(*(*uint16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 36 + 4))&0x1>>0)) != 0) {
					pIdx = (*TTable)(unsafe.Pointer(pTab1)).FpIndex
					for {
						if !(pIdx != 0) {
							break
						}
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x4>>2)) == 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 _54
					_54:
						;
						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, int32(int32(iRoot)), iDb, int32(1))
				if pKeyInfo2 != 0 {
					_sqlite3VdbeChangeP4(tls, v, -int32(1), pKeyInfo2, -int32(8))
				}
				_assignAggregateRegisters(tls, pParse, pAggInfo)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Count), iCsr, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn+libc.Int32FromInt32(0))
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iCsr)
				_explainSimpleCount(tls, pParse, pTab1, pBest)
			} else {
				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)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24))).FpFExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
							goto _55
						}
						if (*TFuncDef)(unsafe.Pointer((*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24))).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 {
							break
						}
						goto _55
					_55:
						;
						i++
					}
					if i == (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc {
						v57 = pParse + 44
						*(*int32)(unsafe.Pointer(v57))++
						v56 = *(*int32)(unsafe.Pointer(v57))
						regAcc = v56
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regAcc)
					}
				} else {
					if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == int32(1) && (*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FiDistinct >= 0 {
						pDistinct1 = *(*uintptr)(unsafe.Pointer((*(*TAggInfo_func)(unsafe.Pointer((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 20))
						if pDistinct1 != 0 {
							v58 = libc.Int32FromInt32(WHERE_WANT_DISTINCT) | libc.Int32FromInt32(WHERE_AGG_DISTINCT)
						} else {
							v58 = 0
						}
						distFlag1 = uint16(v58)
					}
				}
				_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)(unsafe.Pointer(bp + 52)), pDistinct1, p, uint16(int32(int32(minMaxFlag))|int32(int32(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)(unsafe.Pointer(bp + 12))).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 int32((*(*TDistinctCtx)(unsafe.Pointer(bp))).FeTnctType) == int32(WHERE_DISTINCT_UNORDERED) {
		_explainTempTable(tls, pParse, __ccgo_ts+21708)
	}
	/* If there is an ORDER BY clause, then we need to sort the results
	 ** and send them to the callback one by one.
	 */
	if (*(*TSortCtx)(unsafe.Pointer(bp + 12))).FpOrderBy != 0 {
		_generateSortTail(tls, pParse, p, bp+12, (*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)(unsafe.Pointer(bp + 52)))
	_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
//
//	/*
//	** This structure is used to pass data from sqlite3_get_table() through
//	** to the callback function is uses to build the result.
//	*/
type TTabResult = struct {
	FazResult uintptr
	FzErrMsg  uintptr
	FnAlloc   Tu32
	FnRow     Tu32
	FnColumn  Tu32
	FnData    Tu32
	Frc       int32
}

type TabResult = TTabResult

// C documentation
//
//	/*
//	** This routine is called once for each row in the result table.  Its job
//	** is to fill in the TabResult structure appropriately, allocating new
//	** memory as necessary.
//	*/
func _sqlite3_get_table_cb(tls *libc.TLS, pArg uintptr, nCol int32, argv uintptr, colv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azNew, p, z, v3, v6 uintptr
	var i, n, need int32
	var v2, v5 Tu32
	_, _, _, _, _, _, _, _, _, _ = azNew, i, n, need, p, z, v2, v3, v5, v6
	p = pArg /* A single column of result */
	/* Make sure there is enough space in p->azResult to hold everything
	 ** we need to remember from this invocation of the callback.
	 */
	if (*TTabResult)(unsafe.Pointer(p)).FnRow == uint32(0) && argv != uintptr(0) {
		need = nCol * int32(2)
	} else {
		need = nCol
	}
	if (*TTabResult)(unsafe.Pointer(p)).FnData+uint32(uint32(need)) > (*TTabResult)(unsafe.Pointer(p)).FnAlloc {
		(*TTabResult)(unsafe.Pointer(p)).FnAlloc = (*TTabResult)(unsafe.Pointer(p)).FnAlloc*uint32(2) + uint32(uint32(need))
		azNew = _sqlite3Realloc(tls, (*TTabResult)(unsafe.Pointer(p)).FazResult, uint64(uint32(4)*(*TTabResult)(unsafe.Pointer(p)).FnAlloc))
		if azNew == uintptr(0) {
			goto malloc_failed
		}
		(*TTabResult)(unsafe.Pointer(p)).FazResult = azNew
	}
	/* If this is the first row, then generate an extra row containing
	 ** the names of all columns.
	 */
	if (*TTabResult)(unsafe.Pointer(p)).FnRow == uint32(0) {
		(*TTabResult)(unsafe.Pointer(p)).FnColumn = uint32(uint32(nCol))
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			z = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(colv + uintptr(i)*4))))
			if z == uintptr(0) {
				goto malloc_failed
			}
			v3 = p + 20
			v2 = *(*Tu32)(unsafe.Pointer(v3))
			*(*Tu32)(unsafe.Pointer(v3))++
			*(*uintptr)(unsafe.Pointer((*TTabResult)(unsafe.Pointer(p)).FazResult + uintptr(v2)*4)) = z
			goto _1
		_1:
			;
			i++
		}
	} else {
		if int32((*TTabResult)(unsafe.Pointer(p)).FnColumn) != nCol {
			Xsqlite3_free(tls, (*TTabResult)(unsafe.Pointer(p)).FzErrMsg)
			(*TTabResult)(unsafe.Pointer(p)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+21726, 0)
			(*TTabResult)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
			return int32(1)
		}
	}
	/* Copy over the row data
	 */
	if argv != uintptr(0) {
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			if *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)) == uintptr(0) {
				z = uintptr(0)
			} else {
				n = _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))) + int32(1)
				z = Xsqlite3_malloc64(tls, uint64(uint64(n)))
				if z == uintptr(0) {
					goto malloc_failed
				}
				libc.Xmemcpy(tls, z, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)), uint32(uint32(n)))
			}
			v6 = p + 20
			v5 = *(*Tu32)(unsafe.Pointer(v6))
			*(*Tu32)(unsafe.Pointer(v6))++
			*(*uintptr)(unsafe.Pointer((*TTabResult)(unsafe.Pointer(p)).FazResult + uintptr(v5)*4)) = z
			goto _4
		_4:
			;
			i++
		}
		(*TTabResult)(unsafe.Pointer(p)).FnRow++
	}
	return 0
	goto malloc_failed
malloc_failed:
	;
	(*TTabResult)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
	return int32(1)
}

// C documentation
//
//	/*
//	** Query the database.  But instead of invoking a callback for each row,
//	** malloc() for space to hold the result and return the entire results
//	** at the conclusion of the call.
//	**
//	** The result that is written to ***pazResult is held in memory obtained
//	** from malloc().  But the caller cannot free this memory directly.
//	** Instead, the entire table should be passed to sqlite3_free_table() when
//	** the calling procedure is finished using it.
//	*/
func Xsqlite3_get_table(tls *libc.TLS, db uintptr, zSql uintptr, pazResult uintptr, pnRow uintptr, pnColumn uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var azNew uintptr
	var rc int32
	var _ /* res at bp+0 */ TTabResult
	_, _ = azNew, rc
	*(*uintptr)(unsafe.Pointer(pazResult)) = uintptr(0)
	if pnColumn != 0 {
		*(*int32)(unsafe.Pointer(pnColumn)) = 0
	}
	if pnRow != 0 {
		*(*int32)(unsafe.Pointer(pnRow)) = 0
	}
	if pzErrMsg != 0 {
		*(*uintptr)(unsafe.Pointer(pzErrMsg)) = uintptr(0)
	}
	(*(*TTabResult)(unsafe.Pointer(bp))).FzErrMsg = uintptr(0)
	(*(*TTabResult)(unsafe.Pointer(bp))).FnRow = uint32(0)
	(*(*TTabResult)(unsafe.Pointer(bp))).FnColumn = uint32(0)
	(*(*TTabResult)(unsafe.Pointer(bp))).FnData = uint32(1)
	(*(*TTabResult)(unsafe.Pointer(bp))).FnAlloc = uint32(20)
	(*(*TTabResult)(unsafe.Pointer(bp))).Frc = SQLITE_OK
	(*(*TTabResult)(unsafe.Pointer(bp))).FazResult = Xsqlite3_malloc64(tls, uint64(uint32(4)*(*(*TTabResult)(unsafe.Pointer(bp))).FnAlloc))
	if (*(*TTabResult)(unsafe.Pointer(bp))).FazResult == uintptr(0) {
		(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = int32(SQLITE_NOMEM)
		return int32(SQLITE_NOMEM)
	}
	*(*uintptr)(unsafe.Pointer((*(*TTabResult)(unsafe.Pointer(bp))).FazResult)) = uintptr(0)
	rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3_get_table_cb), bp, pzErrMsg)
	*(*uintptr)(unsafe.Pointer((*(*TTabResult)(unsafe.Pointer(bp))).FazResult)) = uintptr(int32((*(*TTabResult)(unsafe.Pointer(bp))).FnData))
	if rc&int32(0xff) == int32(SQLITE_ABORT) {
		Xsqlite3_free_table(tls, (*(*TTabResult)(unsafe.Pointer(bp))).FazResult+1*4)
		if (*(*TTabResult)(unsafe.Pointer(bp))).FzErrMsg != 0 {
			if pzErrMsg != 0 {
				Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(pzErrMsg)))
				*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+40, (*(*TTabResult)(unsafe.Pointer(bp))).FzErrMsg))
			}
			Xsqlite3_free(tls, (*(*TTabResult)(unsafe.Pointer(bp))).FzErrMsg)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = (*(*TTabResult)(unsafe.Pointer(bp))).Frc /* Assume 32-bit assignment is atomic */
		return (*(*TTabResult)(unsafe.Pointer(bp))).Frc
	}
	Xsqlite3_free(tls, (*(*TTabResult)(unsafe.Pointer(bp))).FzErrMsg)
	if rc != SQLITE_OK {
		Xsqlite3_free_table(tls, (*(*TTabResult)(unsafe.Pointer(bp))).FazResult+1*4)
		return rc
	}
	if (*(*TTabResult)(unsafe.Pointer(bp))).FnAlloc > (*(*TTabResult)(unsafe.Pointer(bp))).FnData {
		azNew = _sqlite3Realloc(tls, (*(*TTabResult)(unsafe.Pointer(bp))).FazResult, uint64(uint32(4)*(*(*TTabResult)(unsafe.Pointer(bp))).FnData))
		if azNew == uintptr(0) {
			Xsqlite3_free_table(tls, (*(*TTabResult)(unsafe.Pointer(bp))).FazResult+1*4)
			(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = int32(SQLITE_NOMEM)
			return int32(SQLITE_NOMEM)
		}
		(*(*TTabResult)(unsafe.Pointer(bp))).FazResult = azNew
	}
	*(*uintptr)(unsafe.Pointer(pazResult)) = (*(*TTabResult)(unsafe.Pointer(bp))).FazResult + 1*4
	if pnColumn != 0 {
		*(*int32)(unsafe.Pointer(pnColumn)) = int32((*(*TTabResult)(unsafe.Pointer(bp))).FnColumn)
	}
	if pnRow != 0 {
		*(*int32)(unsafe.Pointer(pnRow)) = int32((*(*TTabResult)(unsafe.Pointer(bp))).FnRow)
	}
	return rc
}

// C documentation
//
//	/*
//	** This routine frees the space the sqlite3_get_table() malloced.
//	*/
func Xsqlite3_free_table(tls *libc.TLS, azResult uintptr) {
	var i, n int32
	_, _ = i, n
	if azResult != 0 {
		azResult -= 4
		n = int32(*(*uintptr)(unsafe.Pointer(azResult)))
		i = int32(1)
		for {
			if !(i < n) {
				break
			}
			if *(*uintptr)(unsafe.Pointer(azResult + uintptr(i)*4)) != 0 {
				Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(azResult + uintptr(i)*4)))
			}
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, azResult)
	}
}

/************** End of table.c ***********************************************/
/************** Begin file trigger.c *****************************************/
/*
**
** 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 implementation for TRIGGERs
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Delete a linked list of TriggerStep structures.
//	*/
func _sqlite3DeleteTriggerStep(tls *libc.TLS, db uintptr, pTriggerStep uintptr) {
	var pTmp uintptr
	_ = pTmp
	for pTriggerStep != 0 {
		pTmp = pTriggerStep
		pTriggerStep = (*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpNext
		_sqlite3ExprDelete(tls, db, (*TTriggerStep)(unsafe.Pointer(pTmp)).FpWhere)
		_sqlite3ExprListDelete(tls, db, (*TTriggerStep)(unsafe.Pointer(pTmp)).FpExprList)
		_sqlite3SelectDelete(tls, db, (*TTriggerStep)(unsafe.Pointer(pTmp)).FpSelect)
		_sqlite3IdListDelete(tls, db, (*TTriggerStep)(unsafe.Pointer(pTmp)).FpIdList)
		_sqlite3UpsertDelete(tls, db, (*TTriggerStep)(unsafe.Pointer(pTmp)).FpUpsert)
		_sqlite3SrcListDelete(tls, db, (*TTriggerStep)(unsafe.Pointer(pTmp)).FpFrom)
		_sqlite3DbFree(tls, db, (*TTriggerStep)(unsafe.Pointer(pTmp)).FzSpan)
		_sqlite3DbFree(tls, db, pTmp)
	}
}

// C documentation
//
//	/*
//	** Given table pTab, return a list of all the triggers attached to
//	** the table. The list is connected by Trigger.pNext pointers.
//	**
//	** All of the triggers on pTab that are in the same database as pTab
//	** are already attached to pTab->pTrigger.  But there might be additional
//	** triggers on pTab in the TEMP schema.  This routine prepends all
//	** TEMP triggers on pTab to the beginning of the pTab->pTrigger list
//	** and returns the combined list.
//	**
//	** To state it another way:  This routine returns a list of all triggers
//	** that fire off of pTab.  The list will include any TEMP triggers on
//	** pTab as well as the triggers lised in pTab->pTrigger.
//	*/
func _sqlite3TriggerList(tls *libc.TLS, pParse uintptr, pTab uintptr) (r uintptr) {
	var p, pList, pTmpSchema, pTrig uintptr
	_, _, _, _ = p, pList, pTmpSchema, pTrig /* Loop variable for TEMP triggers */
	pTmpSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + 1*16))).FpSchema
	p = (*THash)(unsafe.Pointer(pTmpSchema + 40)).Ffirst
	pList = (*TTable)(unsafe.Pointer(pTab)).FpTrigger
	for p != 0 {
		pTrig = (*THashElem)(unsafe.Pointer(p)).Fdata
		if (*TTrigger)(unsafe.Pointer(pTrig)).FpTabSchema == (*TTable)(unsafe.Pointer(pTab)).FpSchema && (*TTrigger)(unsafe.Pointer(pTrig)).Ftable != 0 && 0 == _sqlite3StrICmp(tls, (*TTrigger)(unsafe.Pointer(pTrig)).Ftable, (*TTable)(unsafe.Pointer(pTab)).FzName) && ((*TTrigger)(unsafe.Pointer(pTrig)).FpTabSchema != pTmpSchema || (*TTrigger)(unsafe.Pointer(pTrig)).FbReturning != 0) {
			(*TTrigger)(unsafe.Pointer(pTrig)).FpNext = pList
			pList = pTrig
		} else {
			if int32((*TTrigger)(unsafe.Pointer(pTrig)).Fop) == int32(TK_RETURNING) {
				(*TTrigger)(unsafe.Pointer(pTrig)).Ftable = (*TTable)(unsafe.Pointer(pTab)).FzName
				(*TTrigger)(unsafe.Pointer(pTrig)).FpTabSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
				(*TTrigger)(unsafe.Pointer(pTrig)).FpNext = pList
				pList = pTrig
			}
		}
		p = (*THashElem)(unsafe.Pointer(p)).Fnext
	}
	return pList
}

// 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(80)
	defer tls.Free(80)
	var code, iDb, iTabDb, v4 int32
	var db, pTab, pTrigger, zDb, zDbTrig, zName, v1, v2, v3 uintptr
	var _ /* pName at bp+0 */ uintptr
	var _ /* sFix at bp+4 */ TDbFixer
	_, _, _, _, _, _, _, _, _, _, _, _, _ = code, db, iDb, iTabDb, pTab, pTrigger, zDb, zDbTrig, zName, v1, v2, v3, 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+21791, 0)
			goto trigger_cleanup
		}
		iDb = int32(1)
		*(*uintptr)(unsafe.Pointer(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, (*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzDatabase)
		(*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzDatabase = 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 int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && (*TToken)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema == (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).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+4, pParse, iDb, __ccgo_ts+21837, *(*uintptr)(unsafe.Pointer(bp)))
	if _sqlite3FixSrcList(tls, bp+4, pTableName) != 0 {
		goto trigger_cleanup
	}
	pTab = _sqlite3SrcListLookup(tls, pParse, pTableName)
	if !(pTab != 0) {
		/* The table does not exist. */
		goto trigger_orphan_error
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21845, 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+21886, 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)(unsafe.Pointer(bp)))
	if zName == uintptr(0) {
		goto trigger_cleanup
	}
	if _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+21837, (*TTable)(unsafe.Pointer(pTab)).FzName) != 0 {
		goto trigger_cleanup
	}
	if !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		if _sqlite3HashFind(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema+40, zName) != 0 {
			if !(noErr != 0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21926, libc.VaList(bp+64, *(*uintptr)(unsafe.Pointer(bp))))
			} else {
				_sqlite3CodeVerifySchema(tls, pParse, iDb)
			}
			goto trigger_cleanup
		}
	}
	/* Do not create a trigger on a system table */
	if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+7898, int32(7)) == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21952, 0)
		goto trigger_cleanup
	}
	/* INSTEAD of triggers are only for views and views only support INSTEAD
	 ** of triggers.
	 */
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) && tr_tm != int32(TK_INSTEAD) {
		if tr_tm == int32(TK_BEFORE) {
			v1 = __ccgo_ts + 21990
		} else {
			v1 = __ccgo_ts + 21997
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22003, libc.VaList(bp+64, v1, pTableName+8))
		goto trigger_orphan_error
	}
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) && tr_tm == int32(TK_INSTEAD) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22040, libc.VaList(bp+64, pTableName+8))
		goto trigger_orphan_error
	}
	if !(int32((*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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iTabDb)*16))).FzDbSName
		if isTemp != 0 {
			v2 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FzDbSName
		} else {
			v2 = zDb
		}
		zDbTrig = v2
		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) {
			v3 = __ccgo_ts + 7906
		} else {
			v3 = __ccgo_ts + 7439
		}
		if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v3, 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(36))
	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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	(*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
	(*TTrigger)(unsafe.Pointer(pTrigger)).Fop = uint8(uint8(op))
	if tr_tm == int32(TK_BEFORE) {
		v4 = int32(TRIGGER_BEFORE)
	} else {
		v4 = int32(TRIGGER_AFTER)
	}
	(*TTrigger)(unsafe.Pointer(pTrigger)).Ftr_tm = uint8(v4)
	if int32((*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 int32((*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+172+8, libc.Uint32FromInt32(1), 0, 0x1)
	}
	goto trigger_cleanup
}

// C documentation
//
//	/*
//	** This routine is called after all of the trigger actions have been parsed
//	** in order to complete the process of building the trigger.
//	*/
func _sqlite3FinishTrigger(tls *libc.TLS, pParse uintptr, pStepList uintptr, pAll uintptr) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var db, pHash, pLink, pStep, pTab, pTrig, v, z, zName uintptr
	var iDb int32
	var _ /* nameToken at bp+56 */ TToken
	var _ /* sFix at bp+0 */ TDbFixer
	_, _, _, _, _, _, _, _, _, _ = db, iDb, pHash, pLink, pStep, pTab, pTrig, v, z, zName
	pTrig = (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger /* Name of trigger */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb             /* Trigger name for error reporting */
	(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = uintptr(0)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 || !(pTrig != 0) {
		goto triggerfinish_cleanup
	}
	zName = (*TTrigger)(unsafe.Pointer(pTrig)).FzName
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTrigger)(unsafe.Pointer(pTrig)).FpSchema)
	(*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list = pStepList
	for pStepList != 0 {
		(*TTriggerStep)(unsafe.Pointer(pStepList)).FpTrig = pTrig
		pStepList = (*TTriggerStep)(unsafe.Pointer(pStepList)).FpNext
	}
	_sqlite3TokenInit(tls, bp+56, (*TTrigger)(unsafe.Pointer(pTrig)).FzName)
	_sqlite3FixInit(tls, bp, pParse, iDb, __ccgo_ts+21837, bp+56)
	if _sqlite3FixTriggerStep(tls, bp, (*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list) != 0 || _sqlite3FixExpr(tls, bp, (*TTrigger)(unsafe.Pointer(pTrig)).FpWhen) != 0 {
		goto triggerfinish_cleanup
	}
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrig
		pTrig = uintptr(0)
	} else {
		/* if we are not initializing,
		 ** build the sqlite_schema entry
		 */
		if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
			/* If this is a new CREATE TABLE statement, and if shadow tables
			 ** are read-only, and the trigger makes a change to a shadow table,
			 ** then raise an error - do not allow the trigger to be created. */
			if _sqlite3ReadOnlyShadowTables(tls, db) != 0 {
				pStep = (*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list
				for {
					if !(pStep != 0) {
						break
					}
					if (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget != uintptr(0) && _sqlite3ShadowTableName(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22086, libc.VaList(bp+72, (*TTrigger)(unsafe.Pointer(pTrig)).FzName, (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget))
						goto triggerfinish_cleanup
					}
					goto _1
				_1:
					;
					pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
				}
			}
			/* Make an entry in the sqlite_schema table */
			v = _sqlite3GetVdbe(tls, pParse)
			if v == uintptr(0) {
				goto triggerfinish_cleanup
			}
			_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
			z = _sqlite3DbStrNDup(tls, db, (*TToken)(unsafe.Pointer(pAll)).Fz, uint64((*TToken)(unsafe.Pointer(pAll)).Fn))
			_sqlite3NestedParse(tls, pParse, __ccgo_ts+22134, libc.VaList(bp+72, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, zName, (*TTrigger)(unsafe.Pointer(pTrig)).Ftable, z))
			_sqlite3DbFree(tls, db, z)
			_sqlite3ChangeCookie(tls, pParse, iDb)
			_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+22209, libc.VaList(bp+72, zName)), uint16(0))
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		pLink = pTrig
		pHash = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 40
		pTrig = _sqlite3HashInsert(tls, pHash, zName, pTrig)
		if pTrig != 0 {
			_sqlite3OomFault(tls, db)
		} else {
			if (*TTrigger)(unsafe.Pointer(pLink)).FpSchema == (*TTrigger)(unsafe.Pointer(pLink)).FpTabSchema {
				pTab = _sqlite3HashFind(tls, (*TTrigger)(unsafe.Pointer(pLink)).FpTabSchema+8, (*TTrigger)(unsafe.Pointer(pLink)).Ftable)
				(*TTrigger)(unsafe.Pointer(pLink)).FpNext = (*TTable)(unsafe.Pointer(pTab)).FpTrigger
				(*TTable)(unsafe.Pointer(pTab)).FpTrigger = pLink
			}
		}
	}
	goto triggerfinish_cleanup
triggerfinish_cleanup:
	;
	_sqlite3DeleteTrigger(tls, db, pTrig)
	_sqlite3DeleteTriggerStep(tls, db, pStepList)
}

// C documentation
//
//	/*
//	** Duplicate a range of text from an SQL statement, then convert all
//	** whitespace characters into ordinary space characters.
//	*/
func _triggerSpanDup(tls *libc.TLS, db uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var i int32
	var z uintptr
	_, _ = i, z
	z = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
	if z != 0 {
		i = 0
		for {
			if !(*(*int8)(unsafe.Pointer(z + uintptr(i))) != 0) {
				break
			}
			if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i))))])&int32(0x01) != 0 {
				*(*int8)(unsafe.Pointer(z + uintptr(i))) = int8(' ')
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return z
}

// C documentation
//
//	/*
//	** Turn a SELECT statement (that the pSelect parameter points to) into
//	** a trigger step.  Return a pointer to a TriggerStep structure.
//	**
//	** The parser calls this routine when it finds a SELECT statement in
//	** body of a TRIGGER.
//	*/
func _sqlite3TriggerSelectStep(tls *libc.TLS, db uintptr, pSelect uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var pTriggerStep uintptr
	_ = pTriggerStep
	pTriggerStep = _sqlite3DbMallocZero(tls, db, uint64(48))
	if pTriggerStep == uintptr(0) {
		_sqlite3SelectDelete(tls, db, pSelect)
		return uintptr(0)
	}
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Fop = uint8(TK_SELECT)
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpSelect = pSelect
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = uint8(OE_Default)
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FzSpan = _triggerSpanDup(tls, db, zStart, zEnd)
	return pTriggerStep
}

// C documentation
//
//	/*
//	** Allocate space to hold a new trigger step.  The allocated space
//	** holds both the TriggerStep object and the TriggerStep.target.z string.
//	**
//	** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
//	*/
func _triggerStepAllocate(tls *libc.TLS, pParse uintptr, op Tu8, pName uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var db, pTriggerStep, z uintptr
	_, _, _ = db, pTriggerStep, z
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return uintptr(0)
	}
	pTriggerStep = _sqlite3DbMallocZero(tls, db, uint64(uint32(48)+(*TToken)(unsafe.Pointer(pName)).Fn+uint32(1)))
	if pTriggerStep != 0 {
		z = pTriggerStep + 1*48
		libc.Xmemcpy(tls, z, (*TToken)(unsafe.Pointer(pName)).Fz, (*TToken)(unsafe.Pointer(pName)).Fn)
		_sqlite3Dequote(tls, z)
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FzTarget = z
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Fop = op
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FzSpan = _triggerSpanDup(tls, db, zStart, zEnd)
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenMap(tls, pParse, (*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FzTarget, pName)
		}
	}
	return pTriggerStep
}

// C documentation
//
//	/*
//	** Build a trigger step out of an INSERT statement.  Return a pointer
//	** to the new trigger step.
//	**
//	** The parser calls this routine when it sees an INSERT inside the
//	** body of a trigger.
//	*/
func _sqlite3TriggerInsertStep(tls *libc.TLS, pParse uintptr, pTableName uintptr, pColumn uintptr, pSelect uintptr, orconf Tu8, pUpsert uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var db, pTriggerStep uintptr
	_, _ = db, pTriggerStep
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTriggerStep = _triggerStepAllocate(tls, pParse, uint8(TK_INSERT), pTableName, zStart, zEnd)
	if pTriggerStep != 0 {
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpSelect = pSelect
			pSelect = uintptr(0)
		} else {
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpSelect = _sqlite3SelectDup(tls, db, pSelect, int32(EXPRDUP_REDUCE))
		}
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpIdList = pColumn
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpUpsert = pUpsert
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = orconf
		if pUpsert != 0 {
			_sqlite3HasExplicitNulls(tls, pParse, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
		}
	} else {
		_sqlite3IdListDelete(tls, db, pColumn)
		_sqlite3UpsertDelete(tls, db, pUpsert)
	}
	_sqlite3SelectDelete(tls, db, pSelect)
	return pTriggerStep
}

// C documentation
//
//	/*
//	** Construct a trigger step that implements an UPDATE statement and return
//	** a pointer to that trigger step.  The parser calls this routine when it
//	** sees an UPDATE statement inside the body of a CREATE TRIGGER.
//	*/
func _sqlite3TriggerUpdateStep(tls *libc.TLS, pParse uintptr, pTableName uintptr, pFrom uintptr, pEList uintptr, pWhere uintptr, orconf Tu8, zStart uintptr, zEnd uintptr) (r uintptr) {
	var db, pTriggerStep uintptr
	_, _ = db, pTriggerStep
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTriggerStep = _triggerStepAllocate(tls, pParse, uint8(TK_UPDATE), pTableName, zStart, zEnd)
	if pTriggerStep != 0 {
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpExprList = pEList
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = pWhere
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpFrom = pFrom
			pEList = uintptr(0)
			pWhere = uintptr(0)
			pFrom = uintptr(0)
		} else {
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpExprList = _sqlite3ExprListDup(tls, db, pEList, int32(EXPRDUP_REDUCE))
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = _sqlite3ExprDup(tls, db, pWhere, int32(EXPRDUP_REDUCE))
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpFrom = _sqlite3SrcListDup(tls, db, pFrom, int32(EXPRDUP_REDUCE))
		}
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = orconf
	}
	_sqlite3ExprListDelete(tls, db, pEList)
	_sqlite3ExprDelete(tls, db, pWhere)
	_sqlite3SrcListDelete(tls, db, pFrom)
	return pTriggerStep
}

// C documentation
//
//	/*
//	** Construct a trigger step that implements a DELETE statement and return
//	** a pointer to that trigger step.  The parser calls this routine when it
//	** sees a DELETE statement inside the body of a CREATE TRIGGER.
//	*/
func _sqlite3TriggerDeleteStep(tls *libc.TLS, pParse uintptr, pTableName uintptr, pWhere uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var db, pTriggerStep uintptr
	_, _ = db, pTriggerStep
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTriggerStep = _triggerStepAllocate(tls, pParse, uint8(TK_DELETE), pTableName, zStart, zEnd)
	if pTriggerStep != 0 {
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = pWhere
			pWhere = uintptr(0)
		} else {
			(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = _sqlite3ExprDup(tls, db, pWhere, int32(EXPRDUP_REDUCE))
		}
		(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = uint8(OE_Default)
	}
	_sqlite3ExprDelete(tls, db, pWhere)
	return pTriggerStep
}

// C documentation
//
//	/*
//	** Recursively delete a Trigger structure
//	*/
func _sqlite3DeleteTrigger(tls *libc.TLS, db uintptr, pTrigger uintptr) {
	if pTrigger == uintptr(0) || (*TTrigger)(unsafe.Pointer(pTrigger)).FbReturning != 0 {
		return
	}
	_sqlite3DeleteTriggerStep(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list)
	_sqlite3DbFree(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName)
	_sqlite3DbFree(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).Ftable)
	_sqlite3ExprDelete(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen)
	_sqlite3IdListDelete(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).FpColumns)
	_sqlite3DbFree(tls, db, pTrigger)
}

// 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 = (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzDatabase
	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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*16))).FpSchema+40, zName)
		if pTrigger != 0 {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	if !(pTrigger != 0) {
		if !(noErr != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22238, libc.VaList(bp+8, pName+8))
		} else {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
		}
		(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
		goto drop_trigger_cleanup
	}
	_sqlite3DropTriggerPtr(tls, pParse, pTrigger)
	goto drop_trigger_cleanup
drop_trigger_cleanup:
	;
	_sqlite3SrcListDelete(tls, db, pName)
}

// C documentation
//
//	/*
//	** Return a pointer to the Table structure for the table that a trigger
//	** is set on.
//	*/
func _tableOfTrigger(tls *libc.TLS, pTrigger uintptr) (r uintptr) {
	return _sqlite3HashFind(tls, (*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema+8, (*TTrigger)(unsafe.Pointer(pTrigger)).Ftable)
}

// C documentation
//
//	/*
//	** Drop a trigger given a pointer to that trigger.
//	*/
func _sqlite3DropTriggerPtr(tls *libc.TLS, pParse uintptr, pTrigger uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var code, iDb int32
	var db, pTable, v, zDb, zTab, v1, v2 uintptr
	_, _, _, _, _, _, _, _, _ = code, db, iDb, pTable, v, zDb, zTab, v1, v2
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema)
	pTable = _tableOfTrigger(tls, pTrigger)
	if pTable != 0 {
		code = int32(SQLITE_DROP_TRIGGER)
		zDb = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			v1 = __ccgo_ts + 7906
		} else {
			v1 = __ccgo_ts + 7439
		}
		zTab = v1
		if iDb == int32(1) {
			code = int32(SQLITE_DROP_TEMP_TRIGGER)
		}
		if _sqlite3AuthCheck(tls, pParse, code, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName, (*TTable)(unsafe.Pointer(pTable)).FzName, zDb) != 0 || _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
			return
		}
	}
	/* Generate code to destroy the database record of the trigger.
	 */
	v2 = _sqlite3GetVdbe(tls, pParse)
	v = v2
	if v2 != uintptr(0) {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+22258, libc.VaList(bp+8, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName))
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_DropTrigger), iDb, 0, 0, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName, 0)
	}
}

// C documentation
//
//	/*
//	** Remove a trigger from the hash tables of the sqlite* pointer.
//	*/
func _sqlite3UnlinkAndDeleteTrigger(tls *libc.TLS, db uintptr, iDb int32, zName uintptr) {
	var pHash, pTab, pTrigger, pp uintptr
	_, _, _, _ = pHash, pTab, pTrigger, pp
	pHash = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 40
	pTrigger = _sqlite3HashInsert(tls, pHash, zName, uintptr(0))
	if pTrigger != 0 {
		if (*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema == (*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema {
			pTab = _tableOfTrigger(tls, pTrigger)
			if pTab != 0 {
				pp = pTab + 56
				for {
					if !(*(*uintptr)(unsafe.Pointer(pp)) != 0) {
						break
					}
					if *(*uintptr)(unsafe.Pointer(pp)) == pTrigger {
						*(*uintptr)(unsafe.Pointer(pp)) = (*TTrigger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext
						break
					}
					goto _1
				_1:
					;
					pp = *(*uintptr)(unsafe.Pointer(pp)) + 32
				}
			}
		}
		_sqlite3DeleteTrigger(tls, db, pTrigger)
		*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_SchemaChange)
	}
}

// C documentation
//
//	/*
//	** pEList is the SET clause of an UPDATE statement.  Each entry
//	** in pEList is of the format <id>=<expr>.  If any of the entries
//	** in pEList have an <id> which matches an identifier in pIdList,
//	** then return TRUE.  If pIdList==NULL, then it is considered a
//	** wildcard that matches anything.  Likewise if pEList==NULL then
//	** it matches anything so always return true.  Return false only
//	** if there is no match.
//	*/
func _checkColumnOverlap(tls *libc.TLS, pIdList uintptr, pEList uintptr) (r int32) {
	var e int32
	_ = e
	if pIdList == uintptr(0) || pEList == uintptr(0) {
		return int32(1)
	}
	e = 0
	for {
		if !(e < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		if _sqlite3IdListIndex(tls, pIdList, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(e)*20))).FzEName) >= 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		e++
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if any TEMP triggers exist
//	*/
func _tempTriggersExist(tls *libc.TLS, db uintptr) (r int32) {
	if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema == uintptr(0) {
		return 0
	}
	if (*THash)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema+40)).Ffirst == uintptr(0) {
		return 0
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Return a list of all triggers on table pTab if there exists at least
//	** one trigger that must be fired when an operation of type 'op' is
//	** performed on the table, and, if that operation is an UPDATE, if at
//	** least one of the columns in pChanges is being modified.
//	*/
func _triggersReallyExist(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, pChanges uintptr, pMask uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var mask int32
	var p, pList, v1, v2 uintptr
	_, _, _, _, _ = mask, p, pList, v1, v2
	mask = 0
	pList = uintptr(0)
	pList = _sqlite3TriggerList(tls, pParse, pTab)
	if pList != uintptr(0) {
		p = pList
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_EnableTrigger) == uint64(0) && (*TTable)(unsafe.Pointer(pTab)).FpTrigger != uintptr(0) {
			/* The SQLITE_DBCONFIG_ENABLE_TRIGGER setting is off.  That means that
			 ** only TEMP triggers are allowed.  Truncate the pList so that it
			 ** includes only TEMP triggers */
			if pList == (*TTable)(unsafe.Pointer(pTab)).FpTrigger {
				pList = uintptr(0)
				goto exit_triggers_exist
			}
			for (*TTrigger)(unsafe.Pointer(p)).FpNext != 0 && (*TTrigger)(unsafe.Pointer(p)).FpNext != (*TTable)(unsafe.Pointer(pTab)).FpTrigger {
				p = (*TTrigger)(unsafe.Pointer(p)).FpNext
			}
			(*TTrigger)(unsafe.Pointer(p)).FpNext = uintptr(0)
			p = pList
		}
		for cond := true; cond; cond = p != 0 {
			if int32((*TTrigger)(unsafe.Pointer(p)).Fop) == op && _checkColumnOverlap(tls, (*TTrigger)(unsafe.Pointer(p)).FpColumns, pChanges) != 0 {
				mask |= int32((*TTrigger)(unsafe.Pointer(p)).Ftr_tm)
			} else {
				if int32((*TTrigger)(unsafe.Pointer(p)).Fop) == int32(TK_RETURNING) {
					/* The first time a RETURNING trigger is seen, the "op" value tells
					 ** us what time of trigger it should be. */
					(*TTrigger)(unsafe.Pointer(p)).Fop = uint8(uint8(op))
					if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
						if op != int32(TK_INSERT) {
							if op == int32(TK_DELETE) {
								v1 = __ccgo_ts + 22320
							} else {
								v1 = __ccgo_ts + 22327
							}
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22334, libc.VaList(bp+8, v1))
						}
						(*TTrigger)(unsafe.Pointer(p)).Ftr_tm = uint8(TRIGGER_BEFORE)
					} else {
						(*TTrigger)(unsafe.Pointer(p)).Ftr_tm = uint8(TRIGGER_AFTER)
					}
					mask |= int32((*TTrigger)(unsafe.Pointer(p)).Ftr_tm)
				} else {
					if (*TTrigger)(unsafe.Pointer(p)).FbReturning != 0 && int32((*TTrigger)(unsafe.Pointer(p)).Fop) == int32(TK_INSERT) && op == int32(TK_UPDATE) && (*TParse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) {
						/* Also fire a RETURNING trigger for an UPSERT */
						mask |= int32((*TTrigger)(unsafe.Pointer(p)).Ftr_tm)
					}
				}
			}
			p = (*TTrigger)(unsafe.Pointer(p)).FpNext
		}
	}
	goto exit_triggers_exist
exit_triggers_exist:
	;
	if pMask != 0 {
		*(*int32)(unsafe.Pointer(pMask)) = mask
	}
	if mask != 0 {
		v2 = pList
	} else {
		v2 = uintptr(0)
	}
	return v2
}

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) || (*TParse)(unsafe.Pointer(pParse)).FdisableTriggers != 0 {
		if pMask != 0 {
			*(*int32)(unsafe.Pointer(pMask)) = 0
		}
		return uintptr(0)
	}
	return _triggersReallyExist(tls, pParse, pTab, op, pChanges, pMask)
}

// C documentation
//
//	/*
//	** Convert the pStep->zTarget string into a SrcList and return a pointer
//	** to that SrcList.
//	**
//	** This routine adds a specific database name, if needed, to the target when
//	** forming the SrcList.  This prevents a trigger in one database from
//	** referring to a target in another database.  An exception is when the
//	** trigger is in TEMP in which case it can refer to any other database it
//	** wants.
//	*/
func _sqlite3TriggerStepSrc(tls *libc.TLS, pParse uintptr, pStep uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pDup, pSchema, pSrc, pSubquery, zName uintptr
	var _ /* as at bp+0 */ TToken
	_, _, _, _, _, _ = db, pDup, pSchema, pSrc, pSubquery, zName
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* SrcList to be returned */
	zName = _sqlite3DbStrDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FzTarget)
	pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
	if pSrc != 0 {
		pSchema = (*TTrigger)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpTrig)).FpSchema
		(*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FzName = zName
		if pSchema != (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema {
			(*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FpSchema = pSchema
		}
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom != 0 {
			pDup = _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpFrom, 0)
			if pDup != 0 && (*TSrcList)(unsafe.Pointer(pDup)).FnSrc > int32(1) && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
				pSubquery = _sqlite3SelectNew(tls, pParse, uintptr(0), pDup, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
				(*(*TToken)(unsafe.Pointer(bp))).Fn = uint32(0)
				(*(*TToken)(unsafe.Pointer(bp))).Fz = uintptr(0)
				pDup = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp, pSubquery, uintptr(0))
			}
			pSrc = _sqlite3SrcListAppendList(tls, pParse, pSrc, pDup)
		}
	} else {
		_sqlite3DbFree(tls, db, zName)
	}
	return pSrc
}

// C documentation
//
//	/*
//	** Return true if the pExpr term from the RETURNING clause argument
//	** list is of the form "*".  Raise an error if the terms if of the
//	** form "table.*".
//	*/
func _isAsteriskTerm(tls *libc.TLS, pParse uintptr, pTerm uintptr) (r int32) {
	if int32((*TExpr)(unsafe.Pointer(pTerm)).Fop) == int32(TK_ASTERISK) {
		return int32(1)
	}
	if int32((*TExpr)(unsafe.Pointer(pTerm)).Fop) != int32(TK_DOT) {
		return 0
	}
	if int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pTerm)).FpRight)).Fop) != int32(TK_ASTERISK) {
		return 0
	}
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22382, 0)
	return int32(1)
}

// 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)*20))).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 int32((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(jj)*12)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
					goto _2
				}
				pNewExpr = _sqlite3Expr(tls, db, int32(TK_ID), (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(jj)*12))).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))*20
					(*TExprList_item)(unsafe.Pointer(pItem)).FzEName = _sqlite3DbStrDup(tls, db, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(jj)*12))).FzCnName)
					libc.SetBitFieldPtr16Uint32(pItem+8+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
				}
				goto _2
			_2:
				;
				jj++
			}
		} 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)*20))).FzEName != uintptr(0) {
				pItem1 = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*20
				(*TExprList_item)(unsafe.Pointer(pItem1)).FzEName = _sqlite3DbStrDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FzEName)
				libc.SetBitFieldPtr16Uint32(pItem1+8+4, uint32(int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*20 + 8 + 4))&0x3>>0))), 0, 0x3)
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return pNew
}

// C documentation
//
//	/* If the Expr node is a subquery or an EXISTS operator or an IN operator that
//	** uses a subquery, and if the subquery is SF_Correlated, then mark the
//	** expression as EP_VarSelect.
//	*/
func _sqlite3ReturningSubqueryVarSelect(tls *libc.TLS, NotUsed uintptr, pExpr uintptr) (r int32) {
	_ = NotUsed
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) && (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FselFlags&uint32(SF_Correlated) != uint32(0) {
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_VarSelect))
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** If the SELECT references the table pWalker->u.pTab, then do two things:
//	**
//	**    (1) Mark the SELECT as as SF_Correlated.
//	**    (2) Set pWalker->eCode to non-zero so that the caller will know
//	**        that (1) has happened.
//	*/
func _sqlite3ReturningSubqueryCorrelated(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	var i int32
	var pSrc uintptr
	_, _ = i, pSrc
	pSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		if (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FpTab == *(*uintptr)(unsafe.Pointer(pWalker + 24)) {
			*(*Tu32)(unsafe.Pointer(pSelect + 4)) |= uint32(SF_Correlated)
			(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1)
			break
		}
		goto _1
	_1:
		;
		i++
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Scan the expression list that is the argument to RETURNING looking
//	** for subqueries that depend on the table which is being modified in the
//	** statement that is hosting the RETURNING clause (pTab).  Mark all such
//	** subqueries as SF_Correlated.  If the subqueries are part of an
//	** expression, mark the expression as EP_VarSelect.
//	**
//	** https://sqlite.org/forum/forumpost/2c83569ce8945d39
//	*/
func _sqlite3ProcessReturningSubqueries(tls *libc.TLS, pEList uintptr, pTab uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_sqlite3ExprWalkNoop)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3ReturningSubqueryCorrelated)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pTab
	_sqlite3WalkExprList(tls, bp, pEList)
	if (*(*TWalker)(unsafe.Pointer(bp))).FeCode != 0 {
		(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_sqlite3ReturningSubqueryVarSelect)
		(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
		_sqlite3WalkExprList(tls, bp, pEList)
	}
}

// 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(208)
	defer tls.Free(208)
	var db, pCol, pNew, pReturning, v, v2 uintptr
	var i, nCol, reg, v1 int32
	var _ /* sFrom at bp+80 */ TSrcList
	var _ /* sNC at bp+160 */ TNameContext
	var _ /* sSelect at bp+0 */ TSelect
	_, _, _, _, _, _, _, _, _, _ = db, i, nCol, pCol, pNew, pReturning, reg, v, v1, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if !((*TParse)(unsafe.Pointer(pParse)).FbReturning != 0) {
		/* This RETURNING trigger must be for a different statement as
		 ** this statement lacks a RETURNING clause. */
		return
	}
	pReturning = *(*uintptr)(unsafe.Pointer(pParse + 144))
	if pTrigger != pReturning+8 {
		/* This RETURNING trigger is for a different statement */
		return
	}
	libc.Xmemset(tls, bp, 0, uint32(76))
	libc.Xmemset(tls, bp+80, 0, uint32(80))
	(*(*TSelect)(unsafe.Pointer(bp))).FpEList = _sqlite3ExprListDup(tls, db, (*TReturning)(unsafe.Pointer(pReturning)).FpReturnEL, 0)
	(*(*TSelect)(unsafe.Pointer(bp))).FpSrc = bp + 80
	(*(*TSrcList)(unsafe.Pointer(bp + 80))).FnSrc = int32(1)
	(*(*TSrcItem)(unsafe.Pointer(bp + 80 + 8))).FpTab = pTab
	(*(*TSrcItem)(unsafe.Pointer(bp + 80 + 8))).FzName = (*TTable)(unsafe.Pointer(pTab)).FzName /* tag-20240424-1 */
	(*(*TSrcItem)(unsafe.Pointer(bp + 80 + 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)(unsafe.Pointer(bp))).FpEList)
	pNew = _sqlite3ExpandReturning(tls, pParse, (*TReturning)(unsafe.Pointer(pReturning)).FpReturnEL, pTab)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		libc.Xmemset(tls, bp+160, 0, uint32(36))
		if (*TReturning)(unsafe.Pointer(pReturning)).FnRetCol == 0 {
			(*TReturning)(unsafe.Pointer(pReturning)).FnRetCol = (*TExprList)(unsafe.Pointer(pNew)).FnExpr
			v2 = pParse + 40
			v1 = *(*int32)(unsafe.Pointer(v2))
			*(*int32)(unsafe.Pointer(v2))++
			(*TReturning)(unsafe.Pointer(pReturning)).FiRetCur = v1
		}
		(*(*TNameContext)(unsafe.Pointer(bp + 160))).FpParse = pParse
		*(*int32)(unsafe.Pointer(bp + 160 + 8)) = regIn
		(*(*TNameContext)(unsafe.Pointer(bp + 160))).FncFlags = int32(NC_UBaseReg)
		(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pTrigger)).Fop
		(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = pTab
		if _sqlite3ResolveExprListNames(tls, bp+160, 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)(unsafe.Pointer(pParse + 44)) += 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)*20))).FpExpr
				/* Due to !db->mallocFailed ~9 lines above */
				_sqlite3ExprCodeFactorable(tls, pParse, pCol, reg+i)
				if int32(_sqlite3ExprAffinity(tls, pCol)) == int32(SQLITE_AFF_REAL) {
					_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), reg+i)
				}
				goto _3
			_3:
				;
				i++
			}
			_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
//
//	/*
//	** Generate VDBE code for the statements inside the body of a single
//	** trigger.
//	*/
func _codeTriggerProgram(tls *libc.TLS, pParse uintptr, pStepList uintptr, orconf int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, pSelect, pStep, v uintptr
	var v2 int32
	var _ /* sDest at bp+0 */ TSelectDest
	_, _, _, _, _ = db, pSelect, pStep, v, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pStep = pStepList
	for {
		if !(pStep != 0) {
			break
		}
		/* Figure out the ON CONFLICT policy that will be used for this step
		 ** of the trigger program. If the statement that caused this trigger
		 ** to fire had an explicit ON CONFLICT, then use it. Otherwise, use
		 ** the ON CONFLICT policy that was specified as part of the trigger
		 ** step statement. Example:
		 **
		 **   CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
		 **     INSERT OR REPLACE INTO t2 VALUES(new.a, new.b);
		 **   END;
		 **
		 **   INSERT INTO t1 ... ;            -- insert into t2 uses REPLACE policy
		 **   INSERT OR IGNORE INTO t1 ... ;  -- insert into t2 uses IGNORE policy
		 */
		if orconf == int32(OE_Default) {
			v2 = int32((*TTriggerStep)(unsafe.Pointer(pStep)).Forconf)
		} else {
			v2 = int32(uint8(uint8(orconf)))
		}
		(*TParse)(unsafe.Pointer(pParse)).FeOrconf = uint8(v2)
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FzSpan != 0 {
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Trace), int32(0x7fffffff), int32(1), 0, _sqlite3MPrintf(tls, db, __ccgo_ts+7636, libc.VaList(bp+40, (*TTriggerStep)(unsafe.Pointer(pStep)).FzSpan)), -int32(6))
		}
		switch int32((*TTriggerStep)(unsafe.Pointer(pStep)).Fop) {
		case int32(TK_UPDATE):
			_sqlite3Update(tls, pParse, _sqlite3TriggerStepSrc(tls, pParse, pStep), _sqlite3ExprListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, 0), _sqlite3ExprDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0), int32((*TParse)(unsafe.Pointer(pParse)).FeOrconf), uintptr(0), uintptr(0), uintptr(0))
			_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
		case int32(TK_INSERT):
			_sqlite3Insert(tls, pParse, _sqlite3TriggerStepSrc(tls, pParse, pStep), _sqlite3SelectDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0), _sqlite3IdListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpIdList), int32((*TParse)(unsafe.Pointer(pParse)).FeOrconf), _sqlite3UpsertDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert))
			_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
		case int32(TK_DELETE):
			_sqlite3DeleteFrom(tls, pParse, _sqlite3TriggerStepSrc(tls, pParse, pStep), _sqlite3ExprDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0), uintptr(0), uintptr(0))
			_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
		default:
			pSelect = _sqlite3SelectDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0)
			_sqlite3SelectDestInit(tls, bp, int32(SRT_Discard), 0)
			_sqlite3Select(tls, pParse, pSelect, bp)
			_sqlite3SelectDelete(tls, db, pSelect)
			break
		}
		goto _1
	_1:
		;
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
	return 0
}

// C documentation
//
//	/*
//	** Parse context structure pFrom has just been used to create a sub-vdbe
//	** (trigger program). If an error has occurred, transfer error information
//	** from pFrom to pTo.
//	*/
func _transferParseError(tls *libc.TLS, pTo uintptr, pFrom uintptr) {
	if (*TParse)(unsafe.Pointer(pTo)).FnErr == 0 {
		(*TParse)(unsafe.Pointer(pTo)).FzErrMsg = (*TParse)(unsafe.Pointer(pFrom)).FzErrMsg
		(*TParse)(unsafe.Pointer(pTo)).FnErr = (*TParse)(unsafe.Pointer(pFrom)).FnErr
		(*TParse)(unsafe.Pointer(pTo)).Frc = (*TParse)(unsafe.Pointer(pFrom)).Frc
	} else {
		_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pFrom)).Fdb, (*TParse)(unsafe.Pointer(pFrom)).FzErrMsg)
	}
}

// C documentation
//
//	/*
//	** Create and populate a new TriggerPrg object with a sub-program
//	** implementing trigger pTrigger with ON CONFLICT policy orconf.
//	*/
func _codeRowTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, orconf int32) (r uintptr) {
	bp := tls.Alloc(336)
	defer tls.Free(336)
	var db, pPrg, pProgram, pTop, pWhen, v, v1, v2 uintptr
	var iEndTrigger int32
	var _ /* sNC at bp+0 */ TNameContext
	var _ /* sSubParse at bp+36 */ TParse
	_, _, _, _, _, _, _, _, _ = db, iEndTrigger, pPrg, pProgram, pTop, pWhen, v, v1, v2
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pTop = v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Value to return */
	pWhen = uintptr(0)                         /* Name context for sub-vdbe */
	pProgram = uintptr(0)                      /* Sub-vdbe for trigger program */
	iEndTrigger = 0                            /* Parse context for sub-vdbe */
	/* Allocate the TriggerPrg and SubProgram objects. To ensure that they
	 ** are freed if an error occurs, link them into the Parse.pTriggerPrg
	 ** list of the top-level Parse object sooner rather than later.  */
	pPrg = _sqlite3DbMallocZero(tls, db, uint64(24))
	if !(pPrg != 0) {
		return uintptr(0)
	}
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpNext = (*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg
	(*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg = pPrg
	v2 = _sqlite3DbMallocZero(tls, db, uint64(28))
	pProgram = v2
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpProgram = v2
	if !(pProgram != 0) {
		return uintptr(0)
	}
	_sqlite3VdbeLinkSubProgram(tls, (*TParse)(unsafe.Pointer(pTop)).FpVdbe, pProgram)
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpTrigger = pTrigger
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).Forconf = orconf
	*(*Tu32)(unsafe.Pointer(pPrg + 16)) = uint32(0xffffffff)
	*(*Tu32)(unsafe.Pointer(pPrg + 16 + 1*4)) = uint32(0xffffffff)
	/* Allocate and populate a new Parse context to use for coding the
	 ** trigger sub-program.  */
	_sqlite3ParseObjectInit(tls, bp+36, db)
	libc.Xmemset(tls, bp, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = bp + 36
	(*(*TParse)(unsafe.Pointer(bp + 36))).FpTriggerTab = pTab
	(*(*TParse)(unsafe.Pointer(bp + 36))).FpToplevel = pTop
	(*(*TParse)(unsafe.Pointer(bp + 36))).FzAuthContext = (*TTrigger)(unsafe.Pointer(pTrigger)).FzName
	(*(*TParse)(unsafe.Pointer(bp + 36))).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pTrigger)).Fop
	(*(*TParse)(unsafe.Pointer(bp + 36))).FnQueryLoop = (*TParse)(unsafe.Pointer(pParse)).FnQueryLoop
	(*(*TParse)(unsafe.Pointer(bp + 36))).FprepFlags = (*TParse)(unsafe.Pointer(pParse)).FprepFlags
	v = _sqlite3GetVdbe(tls, bp+36)
	if v != 0 {
		if (*TTrigger)(unsafe.Pointer(pTrigger)).FzName != 0 {
			_sqlite3VdbeChangeP4(tls, v, -int32(1), _sqlite3MPrintf(tls, db, __ccgo_ts+22424, libc.VaList(bp+328, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName)), -int32(6))
		}
		/* If one was specified, code the WHEN clause. If it evaluates to false
		 ** (or NULL) the sub-vdbe is immediately halted by jumping to the
		 ** OP_Halt inserted at the end of the program.  */
		if (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen != 0 {
			pWhen = _sqlite3ExprDup(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen, 0)
			if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && SQLITE_OK == _sqlite3ResolveExprNames(tls, bp, pWhen) {
				iEndTrigger = _sqlite3VdbeMakeLabel(tls, bp+36)
				_sqlite3ExprIfFalse(tls, bp+36, pWhen, iEndTrigger, int32(SQLITE_JUMPIFNULL))
			}
			_sqlite3ExprDelete(tls, db, pWhen)
		}
		/* Code the trigger program into the sub-vdbe. */
		_codeTriggerProgram(tls, bp+36, (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list, orconf)
		/* Insert an OP_Halt at the end of the sub-program. */
		if iEndTrigger != 0 {
			_sqlite3VdbeResolveLabel(tls, v, iEndTrigger)
		}
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Halt))
		_transferParseError(tls, pParse, bp+36)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
			(*TSubProgram)(unsafe.Pointer(pProgram)).FaOp = _sqlite3VdbeTakeOpArray(tls, v, pProgram+4, pTop+104)
		}
		(*TSubProgram)(unsafe.Pointer(pProgram)).FnMem = (*(*TParse)(unsafe.Pointer(bp + 36))).FnMem
		(*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr = (*(*TParse)(unsafe.Pointer(bp + 36))).FnTab
		(*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken = pTrigger
		*(*Tu32)(unsafe.Pointer(pPrg + 16)) = (*(*TParse)(unsafe.Pointer(bp + 36))).Foldmask
		*(*Tu32)(unsafe.Pointer(pPrg + 16 + 1*4)) = (*(*TParse)(unsafe.Pointer(bp + 36))).Fnewmask
		_sqlite3VdbeDelete(tls, v)
	} else {
		_transferParseError(tls, pParse, bp+36)
	}
	_sqlite3ParseObjectReset(tls, bp+36)
	return pPrg
}

// C documentation
//
//	/*
//	** Return a pointer to a TriggerPrg object containing the sub-program for
//	** trigger pTrigger with default ON CONFLICT algorithm orconf. If no such
//	** TriggerPrg object exists, a new object is allocated and populated before
//	** being returned.
//	*/
func _getRowTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, orconf int32) (r uintptr) {
	var pPrg, pRoot, v1 uintptr
	_, _, _ = pPrg, pRoot, v1
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pRoot = v1
	/* It may be that this trigger has already been coded (or is in the
	 ** process of being coded). If this is the case, then an entry with
	 ** a matching TriggerPrg.pTrigger field will be present somewhere
	 ** in the Parse.pTriggerPrg list. Search for such an entry.  */
	pPrg = (*TParse)(unsafe.Pointer(pRoot)).FpTriggerPrg
	for {
		if !(pPrg != 0 && ((*TTriggerPrg)(unsafe.Pointer(pPrg)).FpTrigger != pTrigger || (*TTriggerPrg)(unsafe.Pointer(pPrg)).Forconf != orconf)) {
			break
		}
		goto _2
	_2:
		;
		pPrg = (*TTriggerPrg)(unsafe.Pointer(pPrg)).FpNext
	}
	/* If an existing TriggerPrg could not be located, create a new one. */
	if !(pPrg != 0) {
		pPrg = _codeRowTrigger(tls, pParse, pTrigger, pTab, orconf)
		(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FerrByteOffset = -int32(1)
	}
	return pPrg
}

// C documentation
//
//	/*
//	** Generate code for the trigger program associated with trigger p on
//	** table pTab. The reg, orconf and ignoreJump parameters passed to this
//	** function are the same as those described in the header function for
//	** sqlite3CodeRowTrigger()
//	*/
func _sqlite3CodeRowTriggerDirect(tls *libc.TLS, pParse uintptr, p uintptr, pTab uintptr, reg int32, orconf int32, ignoreJump int32) {
	var bRecursive, v1 int32
	var pPrg, v, v2 uintptr
	_, _, _, _, _ = bRecursive, pPrg, v, v1, v2
	v = _sqlite3GetVdbe(tls, pParse)
	pPrg = _getRowTrigger(tls, pParse, p, pTab, orconf)
	/* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
	 ** is a pointer to the sub-vdbe containing the trigger program.  */
	if pPrg != 0 {
		bRecursive = libc.BoolInt32((*TTrigger)(unsafe.Pointer(p)).FzName != 0 && uint64(0) == (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_RecTriggers))
		v2 = pParse + 44
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Program), reg, ignoreJump, v1, (*TTriggerPrg)(unsafe.Pointer(pPrg)).FpProgram, -int32(4))
		/* Set the P5 operand of the OP_Program instruction to non-zero if
		 ** recursive invocation of this trigger program is disallowed. Recursive
		 ** invocation is disallowed if (a) the sub-program is really a trigger,
		 ** not a foreign key action, and (b) the flag to enable recursive triggers
		 ** is clear.  */
		_sqlite3VdbeChangeP5(tls, v, uint16(uint8(uint8(bRecursive))))
	}
}

// C documentation
//
//	/*
//	** This is called to code the required FOR EACH ROW triggers for an operation
//	** on table pTab. The operation to code triggers for (INSERT, UPDATE or DELETE)
//	** is given by the op parameter. The tr_tm parameter determines whether the
//	** BEFORE or AFTER triggers are coded. If the operation is an UPDATE, then
//	** parameter pChanges is passed the list of columns being modified.
//	**
//	** If there are no triggers that fire at the specified time for the specified
//	** operation on pTab, this function is a no-op.
//	**
//	** The reg argument is the address of the first in an array of registers
//	** that contain the values substituted for the new.* and old.* references
//	** in the trigger program. If N is the number of columns in table pTab
//	** (a copy of pTab->nCol), then registers are populated as follows:
//	**
//	**   Register       Contains
//	**   ------------------------------------------------------
//	**   reg+0          OLD.rowid
//	**   reg+1          OLD.* value of left-most column of pTab
//	**   ...            ...
//	**   reg+N          OLD.* value of right-most column of pTab
//	**   reg+N+1        NEW.rowid
//	**   reg+N+2        NEW.* value of left-most column of pTab
//	**   ...            ...
//	**   reg+N+N+1      NEW.* value of right-most column of pTab
//	**
//	** For ON DELETE triggers, the registers containing the NEW.* values will
//	** never be accessed by the trigger program, so they are not allocated or
//	** populated by the caller (there is no data to populate them with anyway).
//	** Similarly, for ON INSERT triggers the values stored in the OLD.* registers
//	** are never accessed, and so are not allocated by the caller. So, for an
//	** ON INSERT trigger, the value passed to this function as parameter reg
//	** is not a readable register, although registers (reg+N) through
//	** (reg+N+N+1) are.
//	**
//	** Parameter orconf is the default conflict resolution algorithm for the
//	** trigger program to use (REPLACE, IGNORE etc.). Parameter ignoreJump
//	** is the instruction that control should jump to if a trigger program
//	** raises an IGNORE exception.
//	*/
func _sqlite3CodeRowTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, op int32, pChanges uintptr, tr_tm int32, pTab uintptr, reg int32, orconf int32, ignoreJump int32) {
	var p uintptr
	_ = p /* Used to iterate through pTrigger list */
	p = pTrigger
	for {
		if !(p != 0) {
			break
		}
		/* Sanity checking:  The schema for the trigger and for the table are
		 ** always defined.  The trigger must be in the same schema as the table
		 ** or else it must be a TEMP trigger. */
		/* Determine whether we should code this trigger.  One of two choices:
		 **   1. The trigger is an exact match to the current DML statement
		 **   2. This is a RETURNING trigger for INSERT but we are currently
		 **      doing the UPDATE part of an UPSERT.
		 */
		if (int32((*TTrigger)(unsafe.Pointer(p)).Fop) == op || (*TTrigger)(unsafe.Pointer(p)).FbReturning != 0 && int32((*TTrigger)(unsafe.Pointer(p)).Fop) == int32(TK_INSERT) && op == int32(TK_UPDATE)) && int32((*TTrigger)(unsafe.Pointer(p)).Ftr_tm) == tr_tm && _checkColumnOverlap(tls, (*TTrigger)(unsafe.Pointer(p)).FpColumns, pChanges) != 0 {
			if !((*TTrigger)(unsafe.Pointer(p)).FbReturning != 0) {
				_sqlite3CodeRowTriggerDirect(tls, pParse, p, pTab, reg, orconf, ignoreJump)
			} else {
				if (*TParse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) {
					_codeReturningTrigger(tls, pParse, p, pTab, reg)
				}
			}
		}
		goto _1
	_1:
		;
		p = (*TTrigger)(unsafe.Pointer(p)).FpNext
	}
}

// C documentation
//
//	/*
//	** Triggers may access values stored in the old.* or new.* pseudo-table.
//	** This function returns a 32-bit bitmask indicating which columns of the
//	** old.* or new.* tables actually are used by triggers. This information
//	** may be used by the caller, for example, to avoid having to load the entire
//	** old.* record into memory when executing an UPDATE or DELETE command.
//	**
//	** Bit 0 of the returned mask is set if the left-most column of the
//	** table may be accessed using an [old|new].<col> reference. Bit 1 is set if
//	** the second leftmost column value is required, and so on. If there
//	** are more than 32 columns in the table, and at least one of the columns
//	** with an index greater than 32 may be accessed, 0xffffffff is returned.
//	**
//	** It is not possible to determine if the old.rowid or new.rowid column is
//	** accessed by triggers. The caller must always assume that it is.
//	**
//	** Parameter isNew must be either 1 or 0. If it is 0, then the mask returned
//	** applies to the old.* table. If 1, the new.* table.
//	**
//	** Parameter tr_tm must be a mask with one or both of the TRIGGER_BEFORE
//	** and TRIGGER_AFTER bits set. Values accessed by BEFORE triggers are only
//	** included in the returned mask if the TRIGGER_BEFORE bit is set in the
//	** tr_tm parameter. Similarly, values accessed by AFTER triggers are only
//	** included in the returned mask if the TRIGGER_AFTER bit is set in tr_tm.
//	*/
func _sqlite3TriggerColmask(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pChanges uintptr, isNew int32, tr_tm int32, pTab uintptr, orconf int32) (r Tu32) {
	var mask Tu32
	var op, v1 int32
	var p, pPrg uintptr
	_, _, _, _, _ = mask, op, p, pPrg, v1
	if pChanges != 0 {
		v1 = int32(TK_UPDATE)
	} else {
		v1 = int32(TK_DELETE)
	}
	op = v1
	mask = uint32(0)
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		return uint32(0xffffffff)
	}
	p = pTrigger
	for {
		if !(p != 0) {
			break
		}
		if int32((*TTrigger)(unsafe.Pointer(p)).Fop) == op && tr_tm&int32((*TTrigger)(unsafe.Pointer(p)).Ftr_tm) != 0 && _checkColumnOverlap(tls, (*TTrigger)(unsafe.Pointer(p)).FpColumns, pChanges) != 0 {
			if (*TTrigger)(unsafe.Pointer(p)).FbReturning != 0 {
				mask = uint32(0xffffffff)
			} else {
				pPrg = _getRowTrigger(tls, pParse, p, pTab, orconf)
				if pPrg != 0 {
					mask |= *(*Tu32)(unsafe.Pointer(pPrg + 16 + uintptr(isNew)*4))
				}
			}
		}
		goto _2
	_2:
		;
		p = (*TTrigger)(unsafe.Pointer(p)).FpNext
	}
	return mask
}

// C documentation
//
//	/*
//	** The most recently coded instruction was an OP_Column to retrieve the
//	** i-th column of table pTab. This routine sets the P4 parameter of the
//	** OP_Column to the default value, if any.
//	**
//	** The default value of a column is specified by a DEFAULT clause in the
//	** column definition. This was either supplied by the user when the table
//	** was created, or added later to the table definition by an ALTER TABLE
//	** command. If the latter, then the row-records in the table btree on disk
//	** may not contain a value for the column and the default value, taken
//	** from the P4 parameter of the OP_Column instruction, is returned instead.
//	** If the former, then all row-records are guaranteed to include a value
//	** for the column and the P4 value is not required.
//	**
//	** Column definitions created by an ALTER TABLE command may only have
//	** literal default values specified: a number, null or a string. (If a more
//	** complicated default expression value was provided, it is evaluated
//	** when the ALTER TABLE is executed and one of the literal values written
//	** into the sqlite_schema table.)
//	**
//	** Therefore, the P4 parameter is only required if the default value for
//	** the column is a literal number, string or null. The sqlite3ValueFromExpr()
//	** function is capable of transforming these types of expressions into
//	** sqlite3_value objects.
//	**
//	** If column as REAL affinity and the table is an ordinary b-tree table
//	** (not a virtual table) then the value might have been stored as an
//	** integer.  In that case, add an OP_RealAffinity opcode to make sure
//	** it has been converted into REAL.
//	*/
func _sqlite3ColumnDefault(tls *libc.TLS, v uintptr, pTab uintptr, i int32, iReg int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var enc Tu8
	var pCol uintptr
	var _ /* pValue at bp+0 */ uintptr
	_, _ = enc, pCol
	pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12
	if (*TColumn)(unsafe.Pointer(pCol)).FiDflt != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		enc = (*Tsqlite3)(unsafe.Pointer(_sqlite3VdbeDb(tls, v))).Fenc
		_sqlite3ValueFromExpr(tls, _sqlite3VdbeDb(tls, v), _sqlite3ColumnExpr(tls, pTab, pCol), enc, uint8((*TColumn)(unsafe.Pointer(pCol)).Faffinity), bp)
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			_sqlite3VdbeAppendP4(tls, v, *(*uintptr)(unsafe.Pointer(bp)), -int32(10))
		}
	}
	if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) == int32(SQLITE_AFF_REAL) && !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), iReg)
	}
}

// C documentation
//
//	/*
//	** Check to see if column iCol of index pIdx references any of the
//	** columns defined by aXRef and chngRowid.  Return true if it does
//	** and false if not.  This is an optimization.  False-positives are a
//	** performance degradation, but false-negatives can result in a corrupt
//	** index and incorrect answers.
//	**
//	** aXRef[j] will be non-negative if column j of the original table is
//	** being updated.  chngRowid will be true if the rowid of the table is
//	** being updated.
//	*/
func _indexColumnIsBeingUpdated(tls *libc.TLS, pIdx uintptr, iCol int32, aXRef uintptr, chngRowid int32) (r int32) {
	var iIdxCol Ti16
	_ = iIdxCol
	iIdxCol = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2))
	/* Cannot index rowid */
	if int32(int32(iIdxCol)) >= 0 {
		return libc.BoolInt32(*(*int32)(unsafe.Pointer(aXRef + uintptr(iIdxCol)*4)) >= 0)
	}
	return _sqlite3ExprReferencesUpdatedColumn(tls, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(iCol)*20))).FpExpr, aXRef, chngRowid)
}

// C documentation
//
//	/*
//	** Check to see if index pIdx is a partial index whose conditional
//	** expression might change values due to an UPDATE.  Return true if
//	** the index is subject to change and false if the index is guaranteed
//	** to be unchanged.  This is an optimization.  False-positives are a
//	** performance degradation, but false-negatives can result in a corrupt
//	** index and incorrect answers.
//	**
//	** aXRef[j] will be non-negative if column j of the original table is
//	** being updated.  chngRowid will be true if the rowid of the table is
//	** being updated.
//	*/
func _indexWhereClauseMightChange(tls *libc.TLS, pIdx uintptr, aXRef uintptr, chngRowid int32) (r int32) {
	if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
		return 0
	}
	return _sqlite3ExprReferencesUpdatedColumn(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, aXRef, chngRowid)
}

// C documentation
//
//	/*
//	** Allocate and return a pointer to an expression of type TK_ROW with
//	** Expr.iColumn set to value (iCol+1). The resolver will modify the
//	** expression to be a TK_COLUMN reading column iCol of the first
//	** table in the source-list (pSrc->a[0]).
//	*/
func _exprRowColumn(tls *libc.TLS, pParse uintptr, iCol int32) (r uintptr) {
	var pRet uintptr
	_ = pRet
	pRet = _sqlite3PExpr(tls, pParse, int32(TK_ROW), uintptr(0), uintptr(0))
	if pRet != 0 {
		(*TExpr)(unsafe.Pointer(pRet)).FiColumn = int16(iCol + int32(1))
	}
	return pRet
}

// C documentation
//
//	/*
//	** Assuming both the pLimit and pOrderBy parameters are NULL, this function
//	** generates VM code to run the query:
//	**
//	**   SELECT <other-columns>, pChanges FROM pTabList WHERE pWhere
//	**
//	** and write the results to the ephemeral table already opened as cursor
//	** iEph. None of pChanges, pTabList or pWhere are modified or consumed by
//	** this function, they must be deleted by the caller.
//	**
//	** Or, if pLimit and pOrderBy are not NULL, and pTab is not a view:
//	**
//	**   SELECT <other-columns>, pChanges FROM pTabList
//	**   WHERE pWhere
//	**   GROUP BY <other-columns>
//	**   ORDER BY pOrderBy LIMIT pLimit
//	**
//	** If pTab is a view, the GROUP BY clause is omitted.
//	**
//	** Exactly how results are written to table iEph, and exactly what
//	** the <other-columns> in the query above are is determined by the type
//	** of table pTabList->a[0].pTab.
//	**
//	** If the table is a WITHOUT ROWID table, then argument pPk must be its
//	** PRIMARY KEY. In this case <other-columns> are the primary key columns
//	** of the table, in order. The results of the query are written to ephemeral
//	** table iEph as index keys, using OP_IdxInsert.
//	**
//	** If the table is actually a view, then <other-columns> are all columns of
//	** the view. The results are written to the ephemeral table iEph as records
//	** with automatically assigned integer keys.
//	**
//	** If the table is a virtual or ordinary intkey table, then <other-columns>
//	** is its rowid. For a virtual table, the results are written to iEph as
//	** records with automatically assigned integer keys For intkey tables, the
//	** rowid value in <other-columns> is used as the integer key, and the
//	** remaining fields make up the table record.
//	*/
func _updateFromSelect(tls *libc.TLS, pParse uintptr, iEph int32, pPk uintptr, pChanges uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pGrp, pLimit2, pList, pNew, pOrderBy2, pSelect, pSrc, pTab, pWhere2 uintptr
	var eDest, i, v2, v4, v6 int32
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, eDest, i, pGrp, pLimit2, pList, pNew, pOrderBy2, pSelect, pSrc, pTab, pWhere2, v2, v4, v6
	pSelect = uintptr(0)
	pList = uintptr(0)
	pGrp = uintptr(0)
	pLimit2 = uintptr(0)
	pOrderBy2 = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpTab
	_ = pOrderBy
	_ = pLimit
	pSrc = _sqlite3SrcListDup(tls, db, pTabList, 0)
	pWhere2 = _sqlite3ExprDup(tls, db, pWhere, 0)
	if pSrc != 0 {
		(*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FiCursor = -int32(1)
		(*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FpTab)).FnTabRef--
		(*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FpTab = uintptr(0)
	}
	if pPk != 0 {
		i = 0
		for {
			if !(i < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
				break
			}
			pNew = _exprRowColumn(tls, pParse, int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
			pList = _sqlite3ExprListAppend(tls, pParse, pList, pNew)
			goto _1
		_1:
			;
			i++
		}
		if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			v2 = int32(SRT_Table)
		} else {
			v2 = int32(SRT_Upfrom)
		}
		eDest = v2
	} else {
		if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			i = 0
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				pList = _sqlite3ExprListAppend(tls, pParse, pList, _exprRowColumn(tls, pParse, i))
				goto _3
			_3:
				;
				i++
			}
			eDest = int32(SRT_Table)
		} else {
			if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
				v4 = int32(SRT_Table)
			} else {
				v4 = int32(SRT_Upfrom)
			}
			eDest = v4
			pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3PExpr(tls, pParse, int32(TK_ROW), uintptr(0), uintptr(0)))
		}
	}
	if pChanges != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pChanges)).FnExpr) {
				break
			}
			pList = _sqlite3ExprListAppend(tls, pParse, pList, _sqlite3ExprDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FpExpr, 0))
			goto _5
		_5:
			;
			i++
		}
	}
	pSelect = _sqlite3SelectNew(tls, pParse, pList, pSrc, pWhere2, pGrp, uintptr(0), pOrderBy2, uint32(libc.Int32FromInt32(SF_UFSrcCheck)|libc.Int32FromInt32(SF_IncludeHidden)|libc.Int32FromInt32(SF_UpdateFrom)), pLimit2)
	if pSelect != 0 {
		*(*Tu32)(unsafe.Pointer(pSelect + 4)) |= uint32(SF_OrderByReqd)
	}
	_sqlite3SelectDestInit(tls, bp, eDest, iEph)
	if pPk != 0 {
		v6 = int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
	} else {
		v6 = -int32(1)
	}
	(*(*TSelectDest)(unsafe.Pointer(bp))).FiSDParm2 = v6
	_sqlite3Select(tls, pParse, pSelect, bp)
	_sqlite3SelectDelete(tls, db, pSelect)
}

// 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(96)
	defer tls.Free(96)
	var aRegIdx, aToOpen, aXRef, db, pIdx, pKeyInfo, pPk, pRowidExpr, pTab, pTrigger, pWInfo, v, v11, v16, v19, v21, v24, v26, v29, v31, v34, v37, v39, v4, v5 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, v15, v18, v2, v20, v22, v23, v25, v27, v28, v3, v30, v32, v33, v35, v36, v38, v41, v46, v48, v49 int32
	var chngKey, chngPk, chngRowid, hCol, v8 Tu8
	var colFlags, oldmask Tu32
	var nPk Ti16
	var v13 uint64
	var v43 uint32
	var _ /* aiCurOnePass at bp+48 */ [2]int32
	var _ /* bReplace at bp+56 */ int32
	var _ /* iNotUsed1 at bp+60 */ int32
	var _ /* iNotUsed2 at bp+64 */ int32
	var _ /* sContext at bp+0 */ TAuthContext
	var _ /* sNC at bp+8 */ TNameContext
	var _ /* tmask at bp+44 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aRegIdx, aToOpen, aXRef, addrOnce, addrOpen, addrTop, bFinishSeek, bProgress, chngKey, chngPk, chngRowid, colFlags, db, eOnePass, flags, hCol, 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, v11, v13, v15, v16, v18, v19, v2, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v3, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v4, v41, v43, v46, v48, v49, v5, 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)(unsafe.Pointer(bp + 56)) = 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, uint32(8))
	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+44)
	isView = libc.BoolInt32(int32((*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 + 40
	v3 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4))++
	v2 = v3
	iDataCur = v2
	iBaseCur = v2
	iIdxCur = iDataCur + int32(1)
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		v5 = uintptr(0)
	} else {
		v5 = _sqlite3PrimaryKeyIndex(tls, pTab)
	}
	pPk = v5
	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++
		goto _6
	_6:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nIdx++
	}
	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(uint32(4)*uint32(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+nIdx+libc.Int32FromInt32(1))+uint32(uint32(nIdx))+uint32(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), uint32(nIdx+int32(1)))
	*(*Tu8)(unsafe.Pointer(aToOpen + uintptr(nIdx+int32(1)))) = uint8(0)
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) = -int32(1)
		goto _7
	_7:
		;
		i++
	}
	/* Initialize the name-context */
	libc.Xmemset(tls, bp+8, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp + 8))).FpParse = pParse
	(*(*TNameContext)(unsafe.Pointer(bp + 8))).FpSrcList = pTabList
	*(*uintptr)(unsafe.Pointer(bp + 8 + 8)) = pUpsert
	(*(*TNameContext)(unsafe.Pointer(bp + 8))).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
		}
		hCol = _sqlite3StrIHash(tls, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FzEName)
		/* 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+8, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FpExpr) != 0 {
			goto update_cleanup
		}
		j = 0
		for {
			if !(j < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FhName) == int32(int32(hCol)) && _sqlite3StrICmp(tls, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FzCnName, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FzEName) == 0 {
				if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					chngRowid = uint8(1)
					pRowidExpr = (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FpExpr
					iRowidExpr = i
				} else {
					if pPk != 0 && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
						chngPk = uint8(1)
					} else {
						if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22438, libc.VaList(bp+80, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FzCnName))
							goto update_cleanup
						}
					}
				}
				*(*int32)(unsafe.Pointer(aXRef + uintptr(j)*4)) = i
				break
			}
			goto _10
		_10:
			;
			j++
		}
		if j >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
			if pPk == uintptr(0) && _sqlite3IsRowid(tls, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FzEName) != 0 {
				j = -int32(1)
				chngRowid = uint8(1)
				pRowidExpr = (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FpExpr
				iRowidExpr = i
			} else {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22474, libc.VaList(bp+80, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*20))).FzEName))
				(*TParse)(unsafe.Pointer(pParse)).FcheckSchema = uint8(1)
				goto update_cleanup
			}
		}
		if j < 0 {
			v11 = __ccgo_ts + 9339
		} else {
			v11 = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FzCnName
		}
		rc = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_UPDATE), (*TTable)(unsafe.Pointer(pTab)).FzName, v11, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
		if rc == int32(SQLITE_DENY) {
			goto update_cleanup
		} else {
			if rc == int32(SQLITE_IGNORE) {
				*(*int32)(unsafe.Pointer(aXRef + uintptr(j)*4)) = -int32(1)
			}
		}
		goto _9
	_9:
		;
		i++
	}
	chngKey = uint8(int32(int32(chngRowid)) + int32(int32(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)(unsafe.Pointer(aXRef + uintptr(i)*4)) >= 0 {
					goto _12
				}
				if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_GENERATED) == 0 {
					goto _12
				}
				if _sqlite3ExprReferencesUpdatedColumn(tls, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*12), aXRef, int32(int32(chngRowid))) != 0 {
					*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) = int32(99999)
					bProgress = int32(1)
				}
				goto _12
			_12:
				;
				i++
			}
		}
	}
	/* 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 int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		v13 = uint64(-libc.Int32FromInt32(1))
	} else {
		v13 = uint64(0)
	}
	(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FcolUsed = v13
	hasFK = _sqlite3FkRequired(tls, pParse, pTab, aXRef, int32(int32(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)(unsafe.Pointer(bp + 56)) = 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, int32(int32(chngRowid))) != 0 {
			v16 = pParse + 44
			*(*int32)(unsafe.Pointer(v16))++
			v15 = *(*int32)(unsafe.Pointer(v16))
			reg = v15
			*(*int32)(unsafe.Pointer(pParse + 44)) += int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		} else {
			reg = 0
			i = 0
			for {
				if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				if _indexColumnIsBeingUpdated(tls, pIdx, i, aXRef, int32(int32(chngRowid))) != 0 {
					v19 = pParse + 44
					*(*int32)(unsafe.Pointer(v19))++
					v18 = *(*int32)(unsafe.Pointer(v19))
					reg = v18
					*(*int32)(unsafe.Pointer(pParse + 44)) += int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
					if onError == int32(OE_Default) && int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Replace) {
						*(*int32)(unsafe.Pointer(bp + 56)) = int32(1)
					}
					break
				}
				goto _17
			_17:
				;
				i++
			}
		}
		if reg == 0 {
			*(*Tu8)(unsafe.Pointer(aToOpen + uintptr(nAllIdx+int32(1)))) = uint8(0)
		}
		*(*int32)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4)) = reg
		goto _14
	_14:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nAllIdx++
	}
	v21 = pParse + 44
	*(*int32)(unsafe.Pointer(v21))++
	v20 = *(*int32)(unsafe.Pointer(v21))
	*(*int32)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4)) = v20 /* Register storing the table record */
	if *(*int32)(unsafe.Pointer(bp + 56)) != 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), uint32(nIdx+int32(1)))
	}
	if int32((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
		_sqlite3VdbeCountChanges(tls, v)
	}
	_sqlite3BeginWriteOperation(tls, pParse, libc.BoolInt32(pTrigger != 0 || hasFK != 0), iDb)
	/* Allocate required registers. */
	if !(int32((*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)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4))
		v24 = pParse + 44
		*(*int32)(unsafe.Pointer(v24))++
		v23 = *(*int32)(unsafe.Pointer(v24))
		v22 = v23
		regNewRowid = v22
		regOldRowid = v22
		if chngPk != 0 || pTrigger != 0 || hasFK != 0 {
			regOld = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			*(*int32)(unsafe.Pointer(pParse + 44)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
		}
		if chngKey != 0 || pTrigger != 0 || hasFK != 0 {
			v26 = pParse + 44
			*(*int32)(unsafe.Pointer(v26))++
			v25 = *(*int32)(unsafe.Pointer(v26))
			regNewRowid = v25
		}
		regNew = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += 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+8, pWhere) != 0 {
		goto update_cleanup
	}
	/* Virtual tables must be handled separately */
	if int32((*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 */
	v27 = _sqlite3VdbeMakeLabel(tls, pParse)
	labelBreak = v27
	labelContinue = v27
	/* Not an UPSERT.  Normal processing.  Begin by
	 ** initialize the count of updated rows */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(uint64(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !((*TParse)(unsafe.Pointer(pParse)).FbReturning != 0) && pUpsert == uintptr(0) {
		v29 = pParse + 44
		*(*int32)(unsafe.Pointer(v29))++
		v28 = *(*int32)(unsafe.Pointer(v29))
		regRowCount = v28
		_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)
		v31 = pParse + 40
		v30 = *(*int32)(unsafe.Pointer(v31))
		*(*int32)(unsafe.Pointer(v31))++
		iEph = v30
		addrOpen = _sqlite3VdbeAddOp3(tls, v, int32(OP_OpenEphemeral), iEph, 0, regRowSet)
	} else {
		if pPk != 0 {
			v32 = int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
		} else {
			v32 = 0
		}
		nPk = int16(v32)
		iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += int32(int32(nPk))
		*(*int32)(unsafe.Pointer(pParse + 44)) += nChangeFrom
		v34 = pParse + 44
		*(*int32)(unsafe.Pointer(v34))++
		v33 = *(*int32)(unsafe.Pointer(v34))
		regKey = v33
		if pUpsert == uintptr(0) {
			if isView != 0 {
				v35 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
			} else {
				v35 = 0
			}
			nEphCol = int32(int32(nPk)) + nChangeFrom + v35
			v37 = pParse + 40
			v36 = *(*int32)(unsafe.Pointer(v37))
			*(*int32)(unsafe.Pointer(v37))++
			iEph = v36
			if pPk != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, iPk, iPk+int32(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 = uint16(uint16(nEphCol))
					_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(8))
				}
			}
			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(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)(unsafe.Pointer(bp + 56)) != 0) && (pWhere == uintptr(0) || !((*TExpr)(unsafe.Pointer(pWhere)).Fflags&uint32(libc.Int32FromInt32(EP_Subquery)) != libc.Uint32FromInt32(0))) {
				flags |= int32(WHERE_ONEPASS_MULTIROW)
			}
			pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), uint16(uint16(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+48)
			bFinishSeek = _sqlite3WhereUsesDeferredSeek(tls, pWInfo)
			if eOnePass != int32(ONEPASS_SINGLE) {
				_sqlite3MultiWrite(tls, pParse)
				if eOnePass == int32(ONEPASS_MULTI) {
					iCur = (*(*[2]int32)(unsafe.Pointer(bp + 48)))[int32(1)]
					if iCur >= 0 && iCur != iDataCur && *(*Tu8)(unsafe.Pointer(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 {
				v39 = pParse + 44
				*(*int32)(unsafe.Pointer(v39))++
				v38 = *(*int32)(unsafe.Pointer(v39))
				*(*int32)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4)) = v38
				_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(int32(nPk))) {
					break
				}
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
				goto _40
			_40:
				;
				i++
			}
			if eOnePass != 0 {
				if addrOpen != 0 {
					_sqlite3VdbeChangeToNoop(tls, v, addrOpen)
				}
				nKey = int32(int32(nPk))
				regKey = iPk
			} else {
				_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), iPk, int32(int32(nPk)), regKey, _sqlite3IndexAffinityStr(tls, db, pPk), int32(int32(nPk)))
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iEph, regKey, iPk, int32(int32(nPk)))
			}
		}
	}
	if pUpsert == uintptr(0) {
		if nChangeFrom == 0 && eOnePass != int32(ONEPASS_MULTI) {
			_sqlite3WhereEnd(tls, pWInfo)
		}
		if !(isView != 0) {
			addrOnce = 0
			*(*int32)(unsafe.Pointer(bp + 60)) = 0
			*(*int32)(unsafe.Pointer(bp + 64)) = 0
			/* Open every index that needs updating. */
			if eOnePass != ONEPASS_OFF {
				if (*(*[2]int32)(unsafe.Pointer(bp + 48)))[0] >= 0 {
					*(*Tu8)(unsafe.Pointer(aToOpen + uintptr((*(*[2]int32)(unsafe.Pointer(bp + 48)))[0]-iBaseCur))) = uint8(0)
				}
				if (*(*[2]int32)(unsafe.Pointer(bp + 48)))[int32(1)] >= 0 {
					*(*Tu8)(unsafe.Pointer(aToOpen + uintptr((*(*[2]int32)(unsafe.Pointer(bp + 48)))[int32(1)]-iBaseCur))) = uint8(0)
				}
			}
			if eOnePass == int32(ONEPASS_MULTI) && nIdx-libc.BoolInt32((*(*[2]int32)(unsafe.Pointer(bp + 48)))[int32(1)] >= 0) > 0 {
				addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			}
			_sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(0), iBaseCur, aToOpen, bp+60, bp+64)
			if addrOnce != 0 {
				_sqlite3VdbeJumpHereOrPopInst(tls, v, addrOnce)
			}
		}
		/* Top of the update loop */
		if eOnePass != ONEPASS_OFF {
			if (*(*[2]int32)(unsafe.Pointer(bp + 48)))[0] != iDataCur && (*(*[2]int32)(unsafe.Pointer(bp + 48)))[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 {
				v41 = regKey
			} else {
				v41 = regOldRowid
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), v41, 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(int32(nPk))) {
									break
								}
								_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, i, iPk+i)
								goto _42
							_42:
								;
								i++
							}
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, iPk, int32(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 {
			v43 = _sqlite3FkOldmask(tls, pParse, pTab)
		} else {
			v43 = uint32(0)
		}
		oldmask = v43
		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)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)
			k = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(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 _44
		_44:
			;
			i++
		}
		if int32(int32(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 = int32(_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 int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
				if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					k--
				}
			} else {
				j = *(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4))
				if j >= 0 {
					if nChangeFrom != 0 {
						if isView != 0 {
							v46 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
						} else {
							v46 = int32(int32(nPk))
						}
						nOff = v46
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, nOff+j, k)
					} else {
						_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(j)*20))).FpExpr, k)
					}
				} else {
					if 0 == *(*int32)(unsafe.Pointer(bp + 44))&int32(TRIGGER_BEFORE) || i > int32(31) || uint32(uint32(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 _45
	_45:
		;
		i++
		k++
	}
	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)(unsafe.Pointer(bp + 44))&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 int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
						k--
					}
				} else {
					if *(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) < 0 && i != int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
						_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
					}
				}
				goto _47
			_47:
				;
				i++
				k++
			}
			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, uint8(uint8(onError)), labelContinue, bp+56, 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)(unsafe.Pointer(bp + 56)) != 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, int32(int32(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 {
			v48 = 0
		} else {
			v48 = int32(OPFLAG_ISNOOP)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Delete), iDataCur, int32(OPFLAG_ISUPDATE)|v48, 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, int32(int32(chngKey)))
		}
		/* Insert the new index entries and the new record. */
		if eOnePass == int32(ONEPASS_MULTI) {
			v49 = int32(OPFLAG_SAVEPOSITION)
		} else {
			v49 = 0
		}
		_sqlite3CompleteInsertion(tls, pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx, int32(OPFLAG_ISUPDATE)|v49, 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, int32(int32(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 int32((*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+22493)
	}
	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
//
//	/*
//	** Generate code for an UPDATE of a virtual table.
//	**
//	** There are two possible strategies - the default and the special
//	** "onepass" strategy. Onepass is only used if the virtual table
//	** implementation indicates that pWhere may match at most one row.
//	**
//	** The default strategy is to create an ephemeral table that contains
//	** for each row to be changed:
//	**
//	**   (A)  The original rowid of that row.
//	**   (B)  The revised rowid for the row.
//	**   (C)  The content of every column in the row.
//	**
//	** Then loop through the contents of this ephemeral table executing a
//	** VUpdate for each row. When finished, drop the ephemeral table.
//	**
//	** The "onepass" strategy does not use an ephemeral table. Instead, it
//	** stores the same values (A, B and C above) in a register array and
//	** makes a single invocation of VUpdate.
//	*/
func _updateVirtualTable(tls *libc.TLS, pParse uintptr, pSrc uintptr, pTab uintptr, pChanges uintptr, pRowid uintptr, aXRef uintptr, pWhere uintptr, onError int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var addr, eOnePass, ephemTab, i, iCsr, nArg, regArg, regRec, regRowid, v1, v10, v4, v6 int32
	var db, pList, pPk, pPk1, pRow, pRowExpr, pVTab, pWInfo, v, v2, v5, v7 uintptr
	var iPk, iPk1 Ti16
	var _ /* aDummy at bp+0 */ [2]int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, db, eOnePass, ephemTab, i, iCsr, iPk, iPk1, nArg, pList, pPk, pPk1, pRow, pRowExpr, pVTab, pWInfo, regArg, regRec, regRowid, v, v1, v10, v2, v4, v5, v6, v7
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* Loop counter */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb   /* Database connection */
	pVTab = _sqlite3GetVTable(tls, db, pTab)
	pWInfo = uintptr(0)
	nArg = int32(2) + int32((*TTable)(unsafe.Pointer(pTab)).FnCol) /* Register for ephemeral table rowid */
	iCsr = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FiCursor       /* Address of OP_OpenEphemeral */
	/* Allocate nArg registers in which to gather the arguments for VUpdate. Then
	 ** create and open the ephemeral table in which the records created from
	 ** these arguments will be temporarily stored. */
	v2 = pParse + 40
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	ephemTab = v1
	addr = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), ephemTab, nArg)
	regArg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	*(*int32)(unsafe.Pointer(pParse + 44)) += nArg
	if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc > int32(1) {
		pPk = uintptr(0)
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			if pRowid != 0 {
				pRow = _sqlite3ExprDup(tls, db, pRowid, 0)
			} else {
				pRow = _sqlite3PExpr(tls, pParse, int32(TK_ROW), uintptr(0), uintptr(0))
			}
		} else { /* PRIMARY KEY column */
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
			iPk = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn))
			if *(*int32)(unsafe.Pointer(aXRef + uintptr(iPk)*4)) >= 0 {
				pRow = _sqlite3ExprDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(*(*int32)(unsafe.Pointer(aXRef + uintptr(iPk)*4)))*20))).FpExpr, 0)
			} else {
				pRow = _exprRowColumn(tls, pParse, int32(int32(iPk)))
			}
		}
		pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), pRow)
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if *(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) >= 0 {
				pList = _sqlite3ExprListAppend(tls, pParse, pList, _sqlite3ExprDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)))*20))).FpExpr, 0))
			} else {
				pRowExpr = _exprRowColumn(tls, pParse, i)
				if pRowExpr != 0 {
					(*TExpr)(unsafe.Pointer(pRowExpr)).Fop2 = uint8(OPFLAG_NOCHNG)
				}
				pList = _sqlite3ExprListAppend(tls, pParse, pList, pRowExpr)
			}
			goto _3
		_3:
			;
			i++
		}
		_updateFromSelect(tls, pParse, ephemTab, pPk, pList, pSrc, pWhere, uintptr(0), uintptr(0))
		_sqlite3ExprListDelete(tls, db, pList)
		eOnePass = ONEPASS_OFF
	} else {
		v5 = pParse + 44
		*(*int32)(unsafe.Pointer(v5))++
		v4 = *(*int32)(unsafe.Pointer(v5))
		regRec = v4
		v7 = pParse + 44
		*(*int32)(unsafe.Pointer(v7))++
		v6 = *(*int32)(unsafe.Pointer(v7))
		regRowid = v6
		/* Start scanning the virtual table */
		pWInfo = _sqlite3WhereBegin(tls, pParse, pSrc, pWhere, uintptr(0), uintptr(0), uintptr(0), uint16(WHERE_ONEPASS_DESIRED), 0)
		if pWInfo == uintptr(0) {
			return
		}
		/* Populate the argument registers. */
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if *(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) >= 0 {
				_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)))*20))).FpExpr, regArg+int32(2)+i)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_VColumn), iCsr, i, regArg+int32(2)+i)
				_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_NOCHNG)) /* For sqlite3_vtab_nochange() */
			}
			goto _8
		_8:
			;
			i++
		}
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCsr, regArg)
			if pRowid != 0 {
				_sqlite3ExprCode(tls, pParse, pRowid, regArg+int32(1))
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCsr, regArg+int32(1))
			}
		} else { /* PRIMARY KEY column */
			pPk1 = _sqlite3PrimaryKeyIndex(tls, pTab)
			iPk1 = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk1)).FaiColumn))
			_sqlite3VdbeAddOp3(tls, v, int32(OP_VColumn), iCsr, int32(int32(iPk1)), regArg)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), regArg+int32(2)+int32(int32(iPk1)), regArg+int32(1))
		}
		eOnePass = _sqlite3WhereOkOnePass(tls, pWInfo, bp)
		/* There is no ONEPASS_MULTI on virtual tables */
		if eOnePass != 0 {
			/* If using the onepass strategy, no-op out the OP_OpenEphemeral coded
			 ** above. */
			_sqlite3VdbeChangeToNoop(tls, v, addr)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iCsr)
		} else {
			/* Create a record from the argument register contents and insert it into
			 ** the ephemeral table. */
			_sqlite3MultiWrite(tls, pParse)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regArg, nArg, regRec)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), ephemTab, regRowid)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), ephemTab, regRec, regRowid)
		}
	}
	if eOnePass == ONEPASS_OFF {
		/* End the virtual table scan */
		if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc == int32(1) {
			_sqlite3WhereEnd(tls, pWInfo)
		}
		/* Begin scanning through the ephemeral table. */
		addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), ephemTab)
		/* Extract arguments from the current row of the ephemeral table and
		 ** invoke the VUpdate method.  */
		i = 0
		for {
			if !(i < nArg) {
				break
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), ephemTab, i, regArg+i)
			goto _9
		_9:
			;
			i++
		}
	}
	_sqlite3VtabMakeWritable(tls, pParse, pTab)
	_sqlite3VdbeAddOp4(tls, v, int32(OP_VUpdate), 0, nArg, regArg, pVTab, -int32(11))
	if onError == int32(OE_Default) {
		v10 = int32(OE_Abort)
	} else {
		v10 = onError
	}
	_sqlite3VdbeChangeP5(tls, v, uint16(v10))
	_sqlite3MayAbort(tls, pParse)
	/* End of the ephemeral table scan. Or, if using the onepass strategy,
	 ** jump to here if the scan visited zero rows. */
	if eOnePass == ONEPASS_OFF {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), ephemTab, addr+int32(1))
		_sqlite3VdbeJumpHere(tls, v, addr)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), ephemTab, 0)
	} else {
		_sqlite3WhereEnd(tls, pWInfo)
	}
}

/************** End of update.c **********************************************/
/************** Begin file upsert.c ******************************************/
/*
** 2018-04-12
**
** 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 to implement various aspects of UPSERT
** processing and handling of the Upsert object.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Free a list of Upsert objects
//	*/
func _upsertDelete(tls *libc.TLS, db uintptr, p uintptr) {
	var pNext uintptr
	_ = pNext
	for cond := true; cond; cond = p != 0 {
		pNext = (*TUpsert)(unsafe.Pointer(p)).FpNextUpsert
		_sqlite3ExprListDelete(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertTarget)
		_sqlite3ExprDelete(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertTargetWhere)
		_sqlite3ExprListDelete(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertSet)
		_sqlite3ExprDelete(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertWhere)
		_sqlite3DbFree(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpToFree)
		_sqlite3DbFree(tls, db, p)
		p = pNext
	}
}

func _sqlite3UpsertDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		_upsertDelete(tls, db, p)
	}
}

// C documentation
//
//	/*
//	** Duplicate an Upsert object.
//	*/
func _sqlite3UpsertDup(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	if p == uintptr(0) {
		return uintptr(0)
	}
	return _sqlite3UpsertNew(tls, db, _sqlite3ExprListDup(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertTarget, 0), _sqlite3ExprDup(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertTargetWhere, 0), _sqlite3ExprListDup(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertSet, 0), _sqlite3ExprDup(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpUpsertWhere, 0), _sqlite3UpsertDup(tls, db, (*TUpsert)(unsafe.Pointer(p)).FpNextUpsert))
}

// C documentation
//
//	/*
//	** Create a new Upsert object.
//	*/
func _sqlite3UpsertNew(tls *libc.TLS, db uintptr, pTarget uintptr, pTargetWhere uintptr, pSet uintptr, pWhere uintptr, pNext uintptr) (r uintptr) {
	var pNew uintptr
	_ = pNew
	pNew = _sqlite3DbMallocZero(tls, db, uint64(48))
	if pNew == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pTarget)
		_sqlite3ExprDelete(tls, db, pTargetWhere)
		_sqlite3ExprListDelete(tls, db, pSet)
		_sqlite3ExprDelete(tls, db, pWhere)
		_sqlite3UpsertDelete(tls, db, pNext)
		return uintptr(0)
	} else {
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertTarget = pTarget
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertTargetWhere = pTargetWhere
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertSet = pSet
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertWhere = pWhere
		(*TUpsert)(unsafe.Pointer(pNew)).FisDoUpdate = libc.BoolUint8(pSet != uintptr(0))
		(*TUpsert)(unsafe.Pointer(pNew)).FpNextUpsert = pNext
	}
	return pNew
}

// C documentation
//
//	/*
//	** Analyze the ON CONFLICT clause described by pUpsert.  Resolve all
//	** symbols in the conflict-target.
//	**
//	** Return SQLITE_OK if everything works, or an error code is something
//	** is wrong.
//	*/
func _sqlite3UpsertAnalyzeTarget(tls *libc.TLS, pParse uintptr, pTabList uintptr, pUpsert uintptr, pAll uintptr) (r int32) {
	bp := tls.Alloc(176)
	defer tls.Free(176)
	var iCursor, ii, jj, nClause, nn, rc int32
	var pExpr, pIdx, pTab, pTarget, pTerm, v2 uintptr
	var v3 bool
	var _ /* sCol at bp+36 */ [2]TExpr
	var _ /* sNC at bp+0 */ TNameContext
	var _ /* zWhich at bp+140 */ [16]int8
	_, _, _, _, _, _, _, _, _, _, _, _, _ = iCursor, ii, jj, nClause, nn, pExpr, pIdx, pTab, pTarget, pTerm, rc, v2, v3 /* Index column converted into an Expr */
	nClause = 0                                                                                                         /* Counter of ON CONFLICT clauses */
	/* Resolve all symbolic names in the conflict-target clause, which
	 ** includes both the list of columns and the optional partial-index
	 ** WHERE clause.
	 */
	libc.Xmemset(tls, bp, 0, uint32(36))
	(*(*TNameContext)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TNameContext)(unsafe.Pointer(bp))).FpSrcList = pTabList
	for {
		if !(pUpsert != 0 && (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget != 0) {
			break
		}
		rc = _sqlite3ResolveExprListNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
		if rc != 0 {
			return rc
		}
		rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
		if rc != 0 {
			return rc
		}
		/* Check to see if the conflict target matches the rowid. */
		pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpTab
		pTarget = (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget
		iCursor = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor
		if v3 = (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && (*TExprList)(unsafe.Pointer(pTarget)).FnExpr == int32(1); v3 {
			v2 = (*(*TExprList_item)(unsafe.Pointer(pTarget + 8))).FpExpr
			pTerm = v2
		}
		if v3 && int32((*TExpr)(unsafe.Pointer(v2)).Fop) == int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(pTerm)).FiColumn) == -int32(1) {
			/* The conflict-target is the rowid of the primary table */
			goto _1
		}
		/* Initialize sCol[0..1] to be an expression parse tree for a
		 ** single column of an index.  The sCol[0] node will be the TK_COLLATE
		 ** operator and sCol[1] will be the TK_COLUMN operator.  Code below
		 ** will populate the specific collation and column number values
		 ** prior to comparing against the conflict-target expression.
		 */
		libc.Xmemset(tls, bp+36, 0, uint32(104))
		(*(*[2]TExpr)(unsafe.Pointer(bp + 36)))[0].Fop = uint8(TK_COLLATE)
		(*(*[2]TExpr)(unsafe.Pointer(bp + 36)))[0].FpLeft = bp + 36 + 1*52
		(*(*[2]TExpr)(unsafe.Pointer(bp + 36)))[int32(1)].Fop = uint8(TK_COLUMN)
		(*(*[2]TExpr)(unsafe.Pointer(bp + 36)))[int32(1)].FiTable = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor
		/* Check for matches against other indexes */
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if !(int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromInt32(OE_None)) {
				goto _4
			}
			if (*TExprList)(unsafe.Pointer(pTarget)).FnExpr != int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
				goto _4
			}
			if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
				if (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere == uintptr(0) {
					goto _4
				}
				if _sqlite3ExprCompare(tls, pParse, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, iCursor) != 0 {
					goto _4
				}
			}
			nn = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
			ii = 0
			for {
				if !(ii < nn) {
					break
				}
				*(*uintptr)(unsafe.Pointer(bp + 36 + 8)) = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(ii)*4))
				if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(ii)*2))) == -int32(2) {
					pExpr = (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(ii)*20))).FpExpr
					if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLLATE) {
						(*(*[2]TExpr)(unsafe.Pointer(bp + 36)))[0].FpLeft = pExpr
						pExpr = bp + 36
					}
				} else {
					(*(*[2]TExpr)(unsafe.Pointer(bp + 36)))[0].FpLeft = bp + 36 + 1*52
					(*(*[2]TExpr)(unsafe.Pointer(bp + 36)))[int32(1)].FiColumn = *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(ii)*2))
					pExpr = bp + 36
				}
				jj = 0
				for {
					if !(jj < nn) {
						break
					}
					if _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pTarget + 8 + uintptr(jj)*20))).FpExpr, pExpr, iCursor) < int32(2) {
						break /* Column ii of the index matches column jj of target */
					}
					goto _6
				_6:
					;
					jj++
				}
				if jj >= nn {
					/* The target contains no match for column jj of the index */
					break
				}
				goto _5
			_5:
				;
				ii++
			}
			if ii < nn {
				/* Column ii of the index did not match any term of the conflict target.
				 ** Continue the search with the next index. */
				goto _4
			}
			(*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx = pIdx
			if _sqlite3UpsertOfIndex(tls, pAll, pIdx) != pUpsert {
				/* Really this should be an error.  The isDup ON CONFLICT clause will
				 ** never fire.  But this problem was not discovered until three years
				 ** after multi-CONFLICT upsert was added, and so we silently ignore
				 ** the problem to prevent breaking applications that might actually
				 ** have redundant ON CONFLICT clauses. */
				(*TUpsert)(unsafe.Pointer(pUpsert)).FisDup = uint8(1)
			}
			break
			goto _4
		_4:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
		if (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx == uintptr(0) {
			if nClause == 0 && (*TUpsert)(unsafe.Pointer(pUpsert)).FpNextUpsert == uintptr(0) {
				(*(*[16]int8)(unsafe.Pointer(bp + 140)))[0] = 0
			} else {
				Xsqlite3_snprintf(tls, int32(16), bp+140, __ccgo_ts+22506, libc.VaList(bp+168, nClause+int32(1)))
			}
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22510, libc.VaList(bp+168, bp+140))
			return int32(SQLITE_ERROR)
		}
		goto _1
	_1:
		;
		pUpsert = (*TUpsert)(unsafe.Pointer(pUpsert)).FpNextUpsert
		nClause++
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return true if pUpsert is the last ON CONFLICT clause with a
//	** conflict target, or if pUpsert is followed by another ON CONFLICT
//	** clause that targets the INTEGER PRIMARY KEY.
//	*/
func _sqlite3UpsertNextIsIPK(tls *libc.TLS, pUpsert uintptr) (r int32) {
	var pNext uintptr
	_ = pNext
	if pUpsert == uintptr(0) {
		return 0
	}
	pNext = (*TUpsert)(unsafe.Pointer(pUpsert)).FpNextUpsert
	for int32(1) != 0 {
		if pNext == uintptr(0) {
			return int32(1)
		}
		if (*TUpsert)(unsafe.Pointer(pNext)).FpUpsertTarget == uintptr(0) {
			return int32(1)
		}
		if (*TUpsert)(unsafe.Pointer(pNext)).FpUpsertIdx == uintptr(0) {
			return int32(1)
		}
		if !((*TUpsert)(unsafe.Pointer(pNext)).FisDup != 0) {
			return 0
		}
		pNext = (*TUpsert)(unsafe.Pointer(pNext)).FpNextUpsert
	}
	return 0
}

// C documentation
//
//	/*
//	** Given the list of ON CONFLICT clauses described by pUpsert, and
//	** a particular index pIdx, return a pointer to the particular ON CONFLICT
//	** clause that applies to the index.  Or, if the index is not subject to
//	** any ON CONFLICT clause, return NULL.
//	*/
func _sqlite3UpsertOfIndex(tls *libc.TLS, pUpsert uintptr, pIdx uintptr) (r uintptr) {
	for pUpsert != 0 && (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget != uintptr(0) && (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx != pIdx {
		pUpsert = (*TUpsert)(unsafe.Pointer(pUpsert)).FpNextUpsert
	}
	return pUpsert
}

// C documentation
//
//	/*
//	** Generate bytecode that does an UPDATE as part of an upsert.
//	**
//	** If pIdx is NULL, then the UNIQUE constraint that failed was the IPK.
//	** In this case parameter iCur is a cursor open on the table b-tree that
//	** currently points to the conflicting table row. Otherwise, if pIdx
//	** is not NULL, then pIdx is the constraint that failed and iCur is a
//	** cursor points to the conflicting row.
//	*/
func _sqlite3UpsertDoUpdate(tls *libc.TLS, pParse uintptr, pUpsert uintptr, pTab uintptr, pIdx uintptr, iCur int32) {
	var db, pPk, pSrc, pTop, v uintptr
	var i, iDataCur, iPk, k, nPk, regRowid int32
	_, _, _, _, _, _, _, _, _, _, _ = db, i, iDataCur, iPk, k, nPk, pPk, pSrc, pTop, regRowid, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTop = pUpsert
	iDataCur = (*TUpsert)(unsafe.Pointer(pUpsert)).FiDataCur
	pUpsert = _sqlite3UpsertOfIndex(tls, pTop, pIdx)
	if pIdx != 0 && iCur != iDataCur {
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			regRowid = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), iCur, regRowid)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), iDataCur, 0, regRowid)
			_sqlite3ReleaseTempReg(tls, pParse, regRowid)
		} else {
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
			nPk = int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
			iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			*(*int32)(unsafe.Pointer(pParse + 44)) += nPk
			i = 0
			for {
				if !(i < nPk) {
					break
				}
				k = int32(_sqlite3TableColumnToIndex(tls, pIdx, *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iCur, k, iPk+i)
				goto _1
			_1:
				;
				i++
			}
			i = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iDataCur, 0, iPk, nPk)
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Halt), int32(SQLITE_CORRUPT), int32(OE_Abort), 0, __ccgo_ts+13904, -int32(1))
			_sqlite3MayAbort(tls, pParse)
			_sqlite3VdbeJumpHere(tls, v, i)
		}
	}
	/* pUpsert does not own pTop->pUpsertSrc - the outer INSERT statement does.
	 ** So we have to make a copy before passing it down into sqlite3Update() */
	pSrc = _sqlite3SrcListDup(tls, db, (*TUpsert)(unsafe.Pointer(pTop)).FpUpsertSrc, 0)
	/* excluded.* columns of type REAL need to be converted to a hard real */
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity) == int32(SQLITE_AFF_REAL) {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), (*TUpsert)(unsafe.Pointer(pTop)).FregData+i)
		}
		goto _2
	_2:
		;
		i++
	}
	_sqlite3Update(tls, pParse, pSrc, _sqlite3ExprListDup(tls, db, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSet, 0), _sqlite3ExprDup(tls, db, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere, 0), int32(OE_Abort), uintptr(0), uintptr(0), pUpsert)
}

/************** End of upsert.c **********************************************/
/************** Begin file vacuum.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 VACUUM command.
**
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
 */
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */

// C documentation
//
//	/*
//	** Execute zSql on database db.
//	**
//	** If zSql returns rows, then each row will have exactly one
//	** column.  (This will only happen if zSql begins with "SELECT".)
//	** Take each row of result and call execSql() again recursively.
//	**
//	** The execSqlF() routine does the same thing, except it accepts
//	** a format string as its third argument
//	*/
func _execSql(tls *libc.TLS, db uintptr, pzErrMsg uintptr, zSql uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc, v1 int32
	var zSubSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _ = rc, zSubSql, v1
	/* printf("SQL: [%s]\n", zSql); fflush(stdout); */
	rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
	if rc != SQLITE_OK {
		return rc
	}
	for {
		v1 = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
		rc = v1
		if !(int32(SQLITE_ROW) == v1) {
			break
		}
		zSubSql = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
		/* The secondary SQL must be one of CREATE TABLE, CREATE INDEX,
		 ** or INSERT.  Historically there have been attacks that first
		 ** corrupt the sqlite_schema.sql field with other kinds of statements
		 ** then run VACUUM to get those statements to execute at inappropriate
		 ** times. */
		if zSubSql != 0 && (libc.Xstrncmp(tls, zSubSql, __ccgo_ts+22583, uint32(3)) == 0 || libc.Xstrncmp(tls, zSubSql, __ccgo_ts+22587, uint32(3)) == 0) {
			rc = _execSql(tls, db, pzErrMsg, zSubSql)
			if rc != SQLITE_OK {
				break
			}
		}
	}
	if rc == int32(SQLITE_DONE) {
		rc = SQLITE_OK
	}
	if rc != 0 {
		_sqlite3SetString(tls, pzErrMsg, db, Xsqlite3_errmsg(tls, db))
	}
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func _execSqlF(tls *libc.TLS, db uintptr, pzErrMsg uintptr, zSql uintptr, va uintptr) (r int32) {
	var ap Tva_list
	var rc int32
	var z uintptr
	_, _, _ = ap, rc, z
	ap = va
	z = _sqlite3VMPrintf(tls, db, zSql, ap)
	_ = ap
	if z == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	rc = _execSql(tls, db, pzErrMsg, z)
	_sqlite3DbFree(tls, db, z)
	return rc
}

// C documentation
//
//	/*
//	** The VACUUM command is used to clean up the database,
//	** collapse free space, etc.  It is modelled after the VACUUM command
//	** in PostgreSQL.  The VACUUM command works as follows:
//	**
//	**   (1)  Create a new transient database file
//	**   (2)  Copy all content from the database being vacuumed into
//	**        the new transient database file
//	**   (3)  Copy content from the transient database back into the
//	**        original database.
//	**
//	** The transient database requires temporary disk space approximately
//	** equal to the size of the original database.  The copy operation of
//	** step (3) requires additional temporary disk space approximately equal
//	** to the size of the original database for the rollback journal.
//	** Hence, temporary disk space that is approximately 2x the size of the
//	** original database is required.  Every page of the database is written
//	** approximately 3 times:  Once for step (2) and twice for step (3).
//	** Two writes per page are required in step (3) because the original
//	** database content must be written into the rollback journal prior to
//	** overwriting the database with the vacuumed content.
//	**
//	** Only 1x temporary space and only 1x writes would be required if
//	** the copy of step (3) were replaced by deleting the original database
//	** and renaming the transient database as the original.  But that will
//	** not work if other processes are attached to the original database.
//	** And a power loss in between deleting the original and renaming the
//	** transient would cause the database file to appear to be deleted
//	** following reboot.
//	*/
func _sqlite3Vacuum(tls *libc.TLS, pParse uintptr, _pNm uintptr, pInto uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _pNm
	var iDb, iIntoReg, v1 int32
	var v, v2 uintptr
	_, _, _, _, _ = iDb, iIntoReg, v, v1, v2
	v = _sqlite3GetVdbe(tls, pParse)
	iDb = 0
	if v == uintptr(0) {
		goto build_vacuum_end
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto build_vacuum_end
	}
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		/* Default behavior:  Report an error if the argument to VACUUM is
		 ** not recognized */
		iDb = _sqlite3TwoPartName(tls, pParse, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp)), bp)
		if iDb < 0 {
			goto build_vacuum_end
		}
	}
	if iDb != int32(1) {
		iIntoReg = 0
		if pInto != 0 && _sqlite3ResolveSelfReference(tls, pParse, uintptr(0), 0, pInto, uintptr(0)) == 0 {
			v2 = pParse + 44
			*(*int32)(unsafe.Pointer(v2))++
			v1 = *(*int32)(unsafe.Pointer(v2))
			iIntoReg = v1
			_sqlite3ExprCode(tls, pParse, pInto, iIntoReg)
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Vacuum), iDb, iIntoReg)
		_sqlite3VdbeUsesBtree(tls, v, iDb)
	}
	goto build_vacuum_end
build_vacuum_end:
	;
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pInto)
	return
}

// C documentation
//
//	/*
//	** This routine implements the OP_Vacuum opcode of the VDBE.
//	*/
func _sqlite3RunVacuum(tls *libc.TLS, pzErrMsg uintptr, db uintptr, iDb int32, pOut uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, isMemDb, nDb, nRes, rc, v1, v2 int32
	var id, pDb, pMain, pTemp, zDbMain, zOut uintptr
	var pgflags, saved_mDbFlags, saved_openFlags Tu32
	var saved_flags Tu64
	var saved_mTrace Tu8
	var saved_nChange, saved_nTotalChange Ti64
	var _ /* meta at bp+8 */ Tu32
	var _ /* sz at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, id, isMemDb, nDb, nRes, pDb, pMain, pTemp, pgflags, rc, saved_flags, saved_mDbFlags, saved_mTrace, saved_nChange, saved_nTotalChange, saved_openFlags, zDbMain, zOut, v1, v2
	rc = SQLITE_OK                          /* Saved trace settings */
	pDb = uintptr(0)                        /* Name of output file */
	pgflags = uint32(PAGER_SYNCHRONOUS_OFF) /* sync flags for output db */
	if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) {
		_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22591)
		return int32(SQLITE_ERROR) /* IMP: R-12218-18073 */
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive > int32(1) {
		_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22631)
		return int32(SQLITE_ERROR) /* IMP: R-15610-35227 */
	}
	saved_openFlags = (*Tsqlite3)(unsafe.Pointer(db)).FopenFlags
	if pOut != 0 {
		if Xsqlite3_value_type(tls, pOut) != int32(SQLITE_TEXT) {
			_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22674)
			return int32(SQLITE_ERROR)
		}
		zOut = Xsqlite3_value_text(tls, pOut)
		*(*uint32)(unsafe.Pointer(db + 60)) &= uint32(^libc.Int32FromInt32(SQLITE_OPEN_READONLY))
		*(*uint32)(unsafe.Pointer(db + 60)) |= uint32(libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE))
	} else {
		zOut = __ccgo_ts + 1672
	}
	/* Save the current value of the database flags so that it can be
	 ** restored before returning. Then set the writable-schema flag, and
	 ** disable CHECK and foreign key constraints.  */
	saved_flags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
	saved_mDbFlags = (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags
	saved_nChange = (*Tsqlite3)(unsafe.Pointer(db)).FnChange
	saved_nTotalChange = (*Tsqlite3)(unsafe.Pointer(db)).FnTotalChange
	saved_mTrace = (*Tsqlite3)(unsafe.Pointer(db)).FmTrace
	*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(libc.Int32FromInt32(SQLITE_WriteSchema) | libc.Int32FromInt32(SQLITE_IgnoreChecks))
	*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(libc.Int32FromInt32(DBFLAG_PreferBuiltin) | libc.Int32FromInt32(DBFLAG_Vacuum))
	*(*Tu64)(unsafe.Pointer(db + 32)) &= ^(uint64(libc.Int32FromInt32(SQLITE_ForeignKeys)|libc.Int32FromInt32(SQLITE_ReverseOrder)|libc.Int32FromInt32(SQLITE_Defensive)) | uint64(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32))
	(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = uint8(0)
	zDbMain = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	pMain = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
	isMemDb = _sqlite3PagerIsMemdb(tls, _sqlite3BtreePager(tls, pMain))
	/* Attach the temporary database as 'vacuum_db'. The synchronous pragma
	 ** can be set to 'off' for this file, as it is not recovered if a crash
	 ** occurs anyway. The integrity of the database is maintained by a
	 ** (possibly synchronous) transaction opened on the main database before
	 ** sqlite3BtreeCopyFile() is called.
	 **
	 ** An optimization would be to use a non-journaled pager.
	 ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but
	 ** that actually made the VACUUM run slower.  Very little journalling
	 ** actually occurs when doing a vacuum since the vacuum_db is initially
	 ** empty.  Only the journal header is written.  Apparently it takes more
	 ** time to parse and run the PRAGMA to turn journalling off than it does
	 ** to write the journal header file.
	 */
	nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
	rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+22692, libc.VaList(bp+24, zOut))
	(*Tsqlite3)(unsafe.Pointer(db)).FopenFlags = saved_openFlags
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(nDb)*16
	pTemp = (*TDb)(unsafe.Pointer(pDb)).FpBt
	if pOut != 0 {
		id = _sqlite3PagerFile(tls, _sqlite3BtreePager(tls, pTemp))
		*(*Ti64)(unsafe.Pointer(bp)) = 0
		if (*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods != uintptr(0) && (_sqlite3OsFileSize(tls, id, bp) != SQLITE_OK || *(*Ti64)(unsafe.Pointer(bp)) > 0) {
			rc = int32(SQLITE_ERROR)
			_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22715)
			goto end_of_vacuum
		}
		*(*Tu32)(unsafe.Pointer(db + 24)) |= uint32(DBFLAG_VacuumInto)
		/* For a VACUUM INTO, the pager-flags are set to the same values as
		 ** they are for the database being vacuumed, except that PAGER_CACHESPILL
		 ** is always set. */
		pgflags = uint32(uint64((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).Fsafety_level) | (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK))
	}
	nRes = _sqlite3BtreeGetRequestedReserve(tls, pMain)
	_sqlite3BtreeSetCacheSize(tls, pTemp, (*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema)).Fcache_size)
	_sqlite3BtreeSetSpillSize(tls, pTemp, _sqlite3BtreeSetSpillSize(tls, pMain, 0))
	_sqlite3BtreeSetPagerFlags(tls, pTemp, pgflags|uint32(PAGER_CACHESPILL))
	/* Begin a transaction and take an exclusive lock on the main database
	 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
	 ** to ensure that we do not try to change the page-size on a WAL database.
	 */
	rc = _execSql(tls, db, pzErrMsg, __ccgo_ts+16286)
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	if pOut == uintptr(0) {
		v1 = int32(2)
	} else {
		v1 = 0
	}
	rc = _sqlite3BtreeBeginTrans(tls, pMain, v1, uintptr(0))
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	/* Do not attempt to change the page size for a WAL database */
	if _sqlite3PagerGetJournalMode(tls, _sqlite3BtreePager(tls, pMain)) == int32(PAGER_JOURNALMODE_WAL) && pOut == uintptr(0) {
		(*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize = 0
	}
	if _sqlite3BtreeSetPageSize(tls, pTemp, _sqlite3BtreeGetPageSize(tls, pMain), nRes, 0) != 0 || !(isMemDb != 0) && _sqlite3BtreeSetPageSize(tls, pTemp, (*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize, nRes, 0) != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = int32(SQLITE_NOMEM)
		goto end_of_vacuum
	}
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac) >= 0 {
		v2 = int32((*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac)
	} else {
		v2 = _sqlite3BtreeGetAutoVacuum(tls, pMain)
	}
	_sqlite3BtreeSetAutoVacuum(tls, pTemp, v2)
	/* Query the schema of the main database. Create a mirror schema
	 ** in the temporary database.
	 */
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(uint8(nDb)) /* force new CREATE statements into vacuum_db */
	rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+22742, libc.VaList(bp+24, zDbMain))
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+22850, libc.VaList(bp+24, zDbMain))
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
	/* Loop through the tables in the main database. For each, do
	 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
	 ** the contents to the temporary database.
	 */
	rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+22904, libc.VaList(bp+24, zDbMain))
	*(*Tu32)(unsafe.Pointer(db + 24)) &= uint32(^libc.Int32FromInt32(DBFLAG_Vacuum))
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	/* Copy the triggers, views, and virtual tables from the main database
	 ** over to the temporary database.  None of these objects has any
	 ** associated storage, so all we have to do is copy their entries
	 ** from the schema table.
	 */
	rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+23055, libc.VaList(bp+24, zDbMain))
	if rc != 0 {
		goto end_of_vacuum
	}
	/* Copy Btree meta values */
	i = 0
	for {
		if !(i < int32(libc.Uint32FromInt64(10)/libc.Uint32FromInt64(1))) {
			break
		}
		/* GetMeta() and UpdateMeta() cannot fail in this context because
		 ** we already have page 1 loaded into cache and marked dirty. */
		_sqlite3BtreeGetMeta(tls, pMain, int32(_aCopy[i]), bp+8)
		rc = _sqlite3BtreeUpdateMeta(tls, pTemp, int32(_aCopy[i]), *(*Tu32)(unsafe.Pointer(bp + 8))+uint32(_aCopy[i+int32(1)]))
		if rc != SQLITE_OK {
			goto end_of_vacuum
		}
		goto _3
	_3:
		;
		i += int32(2)
	}
	if pOut == uintptr(0) {
		rc = _sqlite3BtreeCopyFile(tls, pMain, pTemp)
	}
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	rc = _sqlite3BtreeCommit(tls, pTemp)
	if rc != SQLITE_OK {
		goto end_of_vacuum
	}
	if pOut == uintptr(0) {
		_sqlite3BtreeSetAutoVacuum(tls, pMain, _sqlite3BtreeGetAutoVacuum(tls, pTemp))
	}
	if pOut == uintptr(0) {
		nRes = _sqlite3BtreeGetRequestedReserve(tls, pTemp)
		rc = _sqlite3BtreeSetPageSize(tls, pMain, _sqlite3BtreeGetPageSize(tls, pTemp), nRes, int32(1))
	}
	goto end_of_vacuum
end_of_vacuum:
	;
	/* Restore the original value of db->flags */
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
	(*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags = saved_mDbFlags
	(*Tsqlite3)(unsafe.Pointer(db)).Fflags = saved_flags
	(*Tsqlite3)(unsafe.Pointer(db)).FnChange = saved_nChange
	(*Tsqlite3)(unsafe.Pointer(db)).FnTotalChange = saved_nTotalChange
	(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = saved_mTrace
	_sqlite3BtreeSetPageSize(tls, pMain, -int32(1), 0, int32(1))
	/* Currently there is an SQL level transaction open on the vacuum
	 ** database. No locks are held on any other files (since the main file
	 ** was committed at the btree level). So it safe to end the transaction
	 ** by manually setting the autoCommit flag to true and detaching the
	 ** vacuum database. The vacuum_db journal file is deleted when the pager
	 ** is closed by the DETACH.
	 */
	(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
	if pDb != 0 {
		_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
		(*TDb)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
		(*TDb)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
	}
	/* This both clears the schemas and reduces the size of the db->aDb[]
	 ** array. */
	_sqlite3ResetAllSchemasOfConnection(tls, db)
	return rc
}

/* At this point, there is a write transaction open on both the
 ** vacuum database and the main database. Assuming no error occurs,
 ** both transactions are closed by this block - the main database
 ** transaction by sqlite3BtreeCopyFile() and the other by an explicit
 ** call to sqlite3BtreeCommit().
 */

/* This array determines which meta meta values are preserved in the
 ** vacuum.  Even entries are the meta value number and odd entries
 ** are an increment to apply to the meta value after the vacuum.
 ** The increment is used to increase the schema cookie so that other
 ** connections to the same database will know to reread the schema.
 */
var _aCopy = [10]uint8{
	0: uint8(BTREE_SCHEMA_VERSION),
	1: uint8(1),
	2: uint8(BTREE_DEFAULT_CACHE_SIZE),
	4: uint8(BTREE_TEXT_ENCODING),
	6: uint8(BTREE_USER_VERSION),
	8: uint8(BTREE_APPLICATION_ID),
}

/************** End of vacuum.c **********************************************/
/************** Begin file vtab.c ********************************************/
/*
** 2006 June 10
**
** 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 help implement virtual tables.
 */
/* #include "sqliteInt.h" */

/*
** Before a virtual table xCreate() or xConnect() method is invoked, the
** sqlite3.pVtabCtx member variable is set to point to an instance of
** this struct allocated on the stack. It is used by the implementation of
** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which
** are invoked only from within xCreate and xConnect methods.
 */
type TVtabCtx1 = struct {
	FpVTable   uintptr
	FpTab      uintptr
	FpPrior    uintptr
	FbDeclared int32
}

type VtabCtx1 = TVtabCtx1

// C documentation
//
//	/*
//	** Construct and install a Module object for a virtual table.  When this
//	** routine is called, it is guaranteed that all appropriate locks are held
//	** and the module is not already part of the connection.
//	**
//	** If there already exists a module with zName, replace it with the new one.
//	** If pModule==0, then delete the module zName if it exists.
//	*/
func _sqlite3VtabCreateModule(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr, xDestroy uintptr) (r uintptr) {
	var nName int32
	var pDel, pMod, zCopy uintptr
	_, _, _, _ = nName, pDel, pMod, zCopy
	if pModule == uintptr(0) {
		zCopy = zName
		pMod = uintptr(0)
	} else {
		nName = _sqlite3Strlen30(tls, zName)
		pMod = _sqlite3Malloc(tls, uint64(uint32(24)+uint32(uint32(nName))+uint32(1)))
		if pMod == uintptr(0) {
			_sqlite3OomFault(tls, db)
			return uintptr(0)
		}
		zCopy = pMod + 1*24
		libc.Xmemcpy(tls, zCopy, zName, uint32(nName+int32(1)))
		(*TModule)(unsafe.Pointer(pMod)).FzName = zCopy
		(*TModule)(unsafe.Pointer(pMod)).FpModule = pModule
		(*TModule)(unsafe.Pointer(pMod)).FpAux = pAux
		(*TModule)(unsafe.Pointer(pMod)).FxDestroy = xDestroy
		(*TModule)(unsafe.Pointer(pMod)).FpEpoTab = uintptr(0)
		(*TModule)(unsafe.Pointer(pMod)).FnRefModule = int32(1)
	}
	pDel = _sqlite3HashInsert(tls, db+404, zCopy, pMod)
	if pDel != 0 {
		if pDel == pMod {
			_sqlite3OomFault(tls, db)
			_sqlite3DbFree(tls, db, pDel)
			pMod = uintptr(0)
		} else {
			_sqlite3VtabEponymousTableClear(tls, db, pDel)
			_sqlite3VtabModuleUnref(tls, db, pDel)
		}
	}
	return pMod
}

// C documentation
//
//	/*
//	** The actual function that does the work of creating a new module.
//	** This function implements the sqlite3_create_module() and
//	** sqlite3_create_module_v2() interfaces.
//	*/
func _createModule(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr, xDestroy uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3VtabCreateModule(tls, db, zName, pModule, pAux, xDestroy)
	rc = _sqlite3ApiExit(tls, db, rc)
	if rc != SQLITE_OK && xDestroy != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDestroy})))(tls, pAux)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** External API function used to create a new virtual-table module.
//	*/
func Xsqlite3_create_module(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr) (r int32) {
	return _createModule(tls, db, zName, pModule, pAux, uintptr(0))
}

// C documentation
//
//	/*
//	** External API function used to create a new virtual-table module.
//	*/
func Xsqlite3_create_module_v2(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr, xDestroy uintptr) (r int32) {
	return _createModule(tls, db, zName, pModule, pAux, xDestroy)
}

// C documentation
//
//	/*
//	** External API to drop all virtual-table modules, except those named
//	** on the azNames list.
//	*/
func Xsqlite3_drop_modules(tls *libc.TLS, db uintptr, azNames uintptr) (r int32) {
	var ii int32
	var pMod, pNext, pThis uintptr
	_, _, _, _ = ii, pMod, pNext, pThis
	pThis = (*THash)(unsafe.Pointer(db + 404)).Ffirst
	for {
		if !(pThis != 0) {
			break
		}
		pMod = (*THashElem)(unsafe.Pointer(pThis)).Fdata
		pNext = (*THashElem)(unsafe.Pointer(pThis)).Fnext
		if azNames != 0 {
			ii = 0
			for {
				if !(*(*uintptr)(unsafe.Pointer(azNames + uintptr(ii)*4)) != uintptr(0) && libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(azNames + uintptr(ii)*4)), (*TModule)(unsafe.Pointer(pMod)).FzName) != 0) {
					break
				}
				goto _2
			_2:
				;
				ii++
			}
			if *(*uintptr)(unsafe.Pointer(azNames + uintptr(ii)*4)) != uintptr(0) {
				goto _1
			}
		}
		_createModule(tls, db, (*TModule)(unsafe.Pointer(pMod)).FzName, uintptr(0), uintptr(0), uintptr(0))
		goto _1
	_1:
		;
		pThis = pNext
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Decrement the reference count on a Module object.  Destroy the
//	** module when the reference count reaches zero.
//	*/
func _sqlite3VtabModuleUnref(tls *libc.TLS, db uintptr, pMod uintptr) {
	(*TModule)(unsafe.Pointer(pMod)).FnRefModule--
	if (*TModule)(unsafe.Pointer(pMod)).FnRefModule == 0 {
		if (*TModule)(unsafe.Pointer(pMod)).FxDestroy != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TModule)(unsafe.Pointer(pMod)).FxDestroy})))(tls, (*TModule)(unsafe.Pointer(pMod)).FpAux)
		}
		_sqlite3DbFree(tls, db, pMod)
	}
}

// C documentation
//
//	/*
//	** Lock the virtual table so that it cannot be disconnected.
//	** Locks nest.  Every lock should have a corresponding unlock.
//	** If an unlock is omitted, resources leaks will occur.
//	**
//	** If a disconnect is attempted while a virtual table is locked,
//	** the disconnect is deferred until all locks have been removed.
//	*/
func _sqlite3VtabLock(tls *libc.TLS, pVTab uintptr) {
	(*TVTable)(unsafe.Pointer(pVTab)).FnRef++
}

// C documentation
//
//	/*
//	** pTab is a pointer to a Table structure representing a virtual-table.
//	** Return a pointer to the VTable object used by connection db to access
//	** this virtual-table, if one has been created, or NULL otherwise.
//	*/
func _sqlite3GetVTable(tls *libc.TLS, db uintptr, pTab uintptr) (r uintptr) {
	var pVtab uintptr
	_ = pVtab
	pVtab = (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).Fp
	for {
		if !(pVtab != 0 && (*TVTable)(unsafe.Pointer(pVtab)).Fdb != db) {
			break
		}
		goto _1
	_1:
		;
		pVtab = (*TVTable)(unsafe.Pointer(pVtab)).FpNext
	}
	return pVtab
}

// C documentation
//
//	/*
//	** Decrement the ref-count on a virtual table object. When the ref-count
//	** reaches zero, call the xDisconnect() method to delete the object.
//	*/
func _sqlite3VtabUnlock(tls *libc.TLS, pVTab uintptr) {
	var db, p uintptr
	_, _ = db, p
	db = (*TVTable)(unsafe.Pointer(pVTab)).Fdb
	(*TVTable)(unsafe.Pointer(pVTab)).FnRef--
	if (*TVTable)(unsafe.Pointer(pVTab)).FnRef == 0 {
		p = (*TVTable)(unsafe.Pointer(pVTab)).FpVtab
		if p != 0 {
			(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(p)).FpModule)).FxDisconnect})))(tls, p)
		}
		_sqlite3VtabModuleUnref(tls, (*TVTable)(unsafe.Pointer(pVTab)).Fdb, (*TVTable)(unsafe.Pointer(pVTab)).FpMod)
		_sqlite3DbFree(tls, db, pVTab)
	}
}

// C documentation
//
//	/*
//	** Table p is a virtual table. This function moves all elements in the
//	** p->u.vtab.p list to the sqlite3.pDisconnect lists of their associated
//	** database connections to be disconnected at the next opportunity.
//	** Except, if argument db is not NULL, then the entry associated with
//	** connection db is left in the p->u.vtab.p list.
//	*/
func _vtabDisconnectAll(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	var db2, pNext, pRet, pVTable uintptr
	_, _, _, _ = db2, pNext, pRet, pVTable
	pRet = uintptr(0)
	pVTable = (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(p + 44))).Fp
	(*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(p + 44))).Fp = uintptr(0)
	/* Assert that the mutex (if any) associated with the BtShared database
	 ** that contains table p is held by the caller. See header comments
	 ** above function sqlite3VtabUnlockList() for an explanation of why
	 ** this makes it safe to access the sqlite3.pDisconnect list of any
	 ** database connection that may have an entry in the p->u.vtab.p list.
	 */
	for pVTable != 0 {
		db2 = (*TVTable)(unsafe.Pointer(pVTable)).Fdb
		pNext = (*TVTable)(unsafe.Pointer(pVTable)).FpNext
		if db2 == db {
			pRet = pVTable
			(*(*struct {
				FnArg  int32
				FazArg uintptr
				Fp     uintptr
			})(unsafe.Pointer(p + 44))).Fp = pRet
			(*TVTable)(unsafe.Pointer(pRet)).FpNext = uintptr(0)
		} else {
			(*TVTable)(unsafe.Pointer(pVTable)).FpNext = (*Tsqlite3)(unsafe.Pointer(db2)).FpDisconnect
			(*Tsqlite3)(unsafe.Pointer(db2)).FpDisconnect = pVTable
		}
		pVTable = pNext
	}
	return pRet
}

// C documentation
//
//	/*
//	** Table *p is a virtual table. This function removes the VTable object
//	** for table *p associated with database connection db from the linked
//	** list in p->pVTab. It also decrements the VTable ref count. This is
//	** used when closing database connection db to free all of its VTable
//	** objects without disturbing the rest of the Schema object (which may
//	** be being used by other shared-cache connections).
//	*/
func _sqlite3VtabDisconnect(tls *libc.TLS, db uintptr, p uintptr) {
	var pVTab, ppVTab uintptr
	_, _ = pVTab, ppVTab
	ppVTab = p + 44 + 8
	for {
		if !(*(*uintptr)(unsafe.Pointer(ppVTab)) != 0) {
			break
		}
		if (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppVTab)))).Fdb == db {
			pVTab = *(*uintptr)(unsafe.Pointer(ppVTab))
			*(*uintptr)(unsafe.Pointer(ppVTab)) = (*TVTable)(unsafe.Pointer(pVTab)).FpNext
			_sqlite3VtabUnlock(tls, pVTab)
			break
		}
		goto _1
	_1:
		;
		ppVTab = *(*uintptr)(unsafe.Pointer(ppVTab)) + 24
	}
}

// C documentation
//
//	/*
//	** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
//	**
//	** This function may only be called when the mutexes associated with all
//	** shared b-tree databases opened using connection db are held by the
//	** caller. This is done to protect the sqlite3.pDisconnect list. The
//	** sqlite3.pDisconnect list is accessed only as follows:
//	**
//	**   1) By this function. In this case, all BtShared mutexes and the mutex
//	**      associated with the database handle itself must be held.
//	**
//	**   2) By function vtabDisconnectAll(), when it adds a VTable entry to
//	**      the sqlite3.pDisconnect list. In this case either the BtShared mutex
//	**      associated with the database the virtual table is stored in is held
//	**      or, if the virtual table is stored in a non-sharable database, then
//	**      the database handle mutex is held.
//	**
//	** As a result, a sqlite3.pDisconnect cannot be accessed simultaneously
//	** by multiple threads. It is thread-safe.
//	*/
func _sqlite3VtabUnlockList(tls *libc.TLS, db uintptr) {
	var p, pNext uintptr
	_, _ = p, pNext
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpDisconnect
	if p != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FpDisconnect = uintptr(0)
		for cond := true; cond; cond = p != 0 {
			pNext = (*TVTable)(unsafe.Pointer(p)).FpNext
			_sqlite3VtabUnlock(tls, p)
			p = pNext
		}
	}
}

// C documentation
//
//	/*
//	** Clear any and all virtual-table information from the Table record.
//	** This routine is called, for example, just before deleting the Table
//	** record.
//	**
//	** Since it is a virtual-table, the Table structure contains a pointer
//	** to the head of a linked list of VTable structures. Each VTable
//	** structure is associated with a single sqlite3* user of the schema.
//	** The reference count of the VTable structure associated with database
//	** connection db is decremented immediately (which may lead to the
//	** structure being xDisconnected and free). Any other VTable structures
//	** in the list are moved to the sqlite3.pDisconnect list of the associated
//	** database connection.
//	*/
func _sqlite3VtabClear(tls *libc.TLS, db uintptr, p uintptr) {
	var i int32
	_ = i
	if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		_vtabDisconnectAll(tls, uintptr(0), p)
	}
	if (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(p + 44))).FazArg != 0 {
		i = 0
		for {
			if !(i < (*(*struct {
				FnArg  int32
				FazArg uintptr
				Fp     uintptr
			})(unsafe.Pointer(p + 44))).FnArg) {
				break
			}
			if i != int32(1) {
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer((*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(p + 44))).FazArg + uintptr(i)*4)))
			}
			goto _1
		_1:
			;
			i++
		}
		_sqlite3DbFree(tls, db, (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(p + 44))).FazArg)
	}
}

// C documentation
//
//	/*
//	** Add a new module argument to pTable->u.vtab.azArg[].
//	** The string is not copied - the pointer is stored.  The
//	** string will be freed automatically when the table is
//	** deleted.
//	*/
func _addModuleArgument(tls *libc.TLS, pParse uintptr, pTable uintptr, zArg uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azModuleArg, db, v2 uintptr
	var i, v1 int32
	var nBytes Tsqlite3_int64
	_, _, _, _, _, _ = azModuleArg, db, i, nBytes, v1, v2
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	nBytes = int64(uint32(4) * uint32(libc.Int32FromInt32(2)+(*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTable + 44))).FnArg))
	if (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTable + 44))).FnArg+int32(3) >= *(*int32)(unsafe.Pointer(db + 120 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14134, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTable)).FzName))
	}
	azModuleArg = _sqlite3DbRealloc(tls, db, (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTable + 44))).FazArg, uint64(uint64(nBytes)))
	if azModuleArg == uintptr(0) {
		_sqlite3DbFree(tls, db, zArg)
	} else {
		v2 = pTable + 44
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2))++
		i = v1
		*(*uintptr)(unsafe.Pointer(azModuleArg + uintptr(i)*4)) = zArg
		*(*uintptr)(unsafe.Pointer(azModuleArg + uintptr(i+int32(1))*4)) = uintptr(0)
		(*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTable + 44))).FazArg = azModuleArg
	}
}

// C documentation
//
//	/*
//	** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
//	** statement.  The module name has been parsed, but the optional list
//	** of parameters that follow the module name are still pending.
//	*/
func _sqlite3VtabBeginParse(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pModuleName uintptr, ifNotExists int32) {
	var db, pTable uintptr
	var iDb int32
	_, _, _ = db, iDb, pTable /* Database connection */
	_sqlite3StartTable(tls, pParse, pName1, pName2, 0, 0, int32(1), ifNotExists)
	pTable = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if pTable == uintptr(0) {
		return
	}
	(*TTable)(unsafe.Pointer(pTable)).FeTabType = uint8(TABTYP_VTAB)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	_addModuleArgument(tls, pParse, pTable, _sqlite3NameFromToken(tls, db, pModuleName))
	_addModuleArgument(tls, pParse, pTable, uintptr(0))
	_addModuleArgument(tls, pParse, pTable, _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pTable)).FzName))
	(*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fn = uint32(t__predefined_ptrdiff_t((*TToken)(unsafe.Pointer(pModuleName)).Fz+uintptr((*TToken)(unsafe.Pointer(pModuleName)).Fn)) - int32((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
	/* Creating a virtual table invokes the authorization callback twice.
	 ** The first invocation, to obtain permission to INSERT a row into the
	 ** sqlite_schema table, has already been made by sqlite3StartTable().
	 ** The second call, to obtain permission to create the table, is made now.
	 */
	if (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTable + 44))).FazArg != 0 {
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTable)).FpSchema)
		/* The database the table is being created in */
		_sqlite3AuthCheck(tls, pParse, int32(SQLITE_CREATE_VTABLE), (*TTable)(unsafe.Pointer(pTable)).FzName, *(*uintptr)(unsafe.Pointer((*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTable + 44))).FazArg)), (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FzDbSName)
	}
}

// C documentation
//
//	/*
//	** This routine takes the module argument that has been accumulating
//	** in pParse->zArg[] and appends it to the list of arguments on the
//	** virtual table currently under construction in pParse->pTable.
//	*/
func _addArgumentToVtab(tls *libc.TLS, pParse uintptr) {
	var db, z uintptr
	var n int32
	_, _, _ = db, n, z
	if (*TParse)(unsafe.Pointer(pParse)).FsArg.Fz != 0 && (*TParse)(unsafe.Pointer(pParse)).FpNewTable != 0 {
		z = (*TParse)(unsafe.Pointer(pParse)).FsArg.Fz
		n = int32((*TParse)(unsafe.Pointer(pParse)).FsArg.Fn)
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		_addModuleArgument(tls, pParse, (*TParse)(unsafe.Pointer(pParse)).FpNewTable, _sqlite3DbStrNDup(tls, db, z, uint64(uint64(n))))
	}
}

// C documentation
//
//	/*
//	** The parser calls this routine after the CREATE VIRTUAL TABLE statement
//	** has been completely parsed.
//	*/
func _sqlite3VtabFinishParse(tls *libc.TLS, pParse uintptr, pEnd uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, pOld, pSchema, pTab, v, zName, zStmt, zWhere, v2 uintptr
	var iDb, iReg, v1 int32
	_, _, _, _, _, _, _, _, _, _, _, _ = db, iDb, iReg, pOld, pSchema, pTab, v, zName, zStmt, zWhere, v1, v2
	pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable /* The table being constructed */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb          /* The database connection */
	if pTab == uintptr(0) {
		return
	}
	_addArgumentToVtab(tls, pParse)
	(*TParse)(unsafe.Pointer(pParse)).FsArg.Fz = uintptr(0)
	if (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FnArg < int32(1) {
		return
	}
	/* If the CREATE VIRTUAL TABLE statement is being entered for the
	 ** first time (in other words if the virtual table is actually being
	 ** created now instead of just being read out of sqlite_schema) then
	 ** do additional initialization work and store the statement text
	 ** in the sqlite_schema table.
	 */
	if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
		_sqlite3MayAbort(tls, pParse)
		/* Compute the complete text of the CREATE VIRTUAL TABLE statement */
		if pEnd != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fn = uint32(int32((*TToken)(unsafe.Pointer(pEnd)).Fz)-int32((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz)) + (*TToken)(unsafe.Pointer(pEnd)).Fn
		}
		zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+23185, libc.VaList(bp+8, pParse+200))
		/* 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.
		 **
		 ** The VM register number pParse->regRowid holds the rowid of an
		 ** entry in the sqlite_schema table that was created for this vtab
		 ** by sqlite3StartTable().
		 */
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+23209, libc.VaList(bp+8, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, zStmt, (*TParse)(unsafe.Pointer(pParse)).FregRowid))
		v = _sqlite3GetVdbe(tls, pParse)
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Expire))
		zWhere = _sqlite3MPrintf(tls, db, __ccgo_ts+23308, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, zStmt))
		_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, zWhere, uint16(0))
		_sqlite3DbFree(tls, db, zStmt)
		v2 = pParse + 44
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		iReg = v1
		_sqlite3VdbeLoadString(tls, v, iReg, (*TTable)(unsafe.Pointer(pTab)).FzName)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_VCreate), iDb, iReg)
	} else {
		pSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
		zName = (*TTable)(unsafe.Pointer(pTab)).FzName
		_sqlite3MarkAllShadowTablesOf(tls, db, pTab)
		pOld = _sqlite3HashInsert(tls, pSchema+8, zName, pTab)
		if pOld != 0 {
			_sqlite3OomFault(tls, db)
			/* Malloc must have failed inside HashInsert() */
			return
		}
		(*TParse)(unsafe.Pointer(pParse)).FpNewTable = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** The parser calls this routine when it sees the first token
//	** of an argument to the module name in a CREATE VIRTUAL TABLE statement.
//	*/
func _sqlite3VtabArgInit(tls *libc.TLS, pParse uintptr) {
	_addArgumentToVtab(tls, pParse)
	(*TParse)(unsafe.Pointer(pParse)).FsArg.Fz = uintptr(0)
	(*TParse)(unsafe.Pointer(pParse)).FsArg.Fn = uint32(0)
}

// C documentation
//
//	/*
//	** The parser calls this routine for each token after the first token
//	** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
//	*/
func _sqlite3VtabArgExtend(tls *libc.TLS, pParse uintptr, p uintptr) {
	var pArg uintptr
	_ = pArg
	pArg = pParse + 264
	if (*TToken)(unsafe.Pointer(pArg)).Fz == uintptr(0) {
		(*TToken)(unsafe.Pointer(pArg)).Fz = (*TToken)(unsafe.Pointer(p)).Fz
		(*TToken)(unsafe.Pointer(pArg)).Fn = (*TToken)(unsafe.Pointer(p)).Fn
	} else {
		(*TToken)(unsafe.Pointer(pArg)).Fn = uint32(t__predefined_ptrdiff_t((*TToken)(unsafe.Pointer(p)).Fz+uintptr((*TToken)(unsafe.Pointer(p)).Fn)) - int32((*TToken)(unsafe.Pointer(pArg)).Fz))
	}
}

// C documentation
//
//	/*
//	** Invoke a virtual table constructor (either xCreate or xConnect). The
//	** pointer to the function to invoke is passed as the fourth parameter
//	** to this procedure.
//	*/
func _vtabCallConstructor(tls *libc.TLS, db uintptr, pTab uintptr, pMod uintptr, xConstruct uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var azArg, pCtx, pVTable, zFormat, zModuleName, zType, p6 uintptr
	var i, iCol, iDb, j, nArg, nDel, nType, rc, v4 int32
	var oooHidden Tu16
	var _ /* sCtx at bp+0 */ TVtabCtx
	var _ /* zErr at bp+16 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = azArg, i, iCol, iDb, j, nArg, nDel, nType, oooHidden, pCtx, pVTable, rc, zFormat, zModuleName, zType, v4, p6
	nArg = (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FnArg
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	azArg = (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FazArg
	/* Check that the virtual-table is not already being initialized */
	pCtx = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
	for {
		if !(pCtx != 0) {
			break
		}
		if (*TVtabCtx)(unsafe.Pointer(pCtx)).FpTab == pTab {
			*(*uintptr)(unsafe.Pointer(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+23327, libc.VaList(bp+32, (*TTable)(unsafe.Pointer(pTab)).FzName))
			return int32(SQLITE_LOCKED)
		}
		goto _1
	_1:
		;
		pCtx = (*TVtabCtx)(unsafe.Pointer(pCtx)).FpPrior
	}
	zModuleName = _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pTab)).FzName)
	if !(zModuleName != 0) {
		return int32(SQLITE_NOMEM)
	}
	pVTable = _sqlite3MallocZero(tls, uint64(28))
	if !(pVTable != 0) {
		_sqlite3OomFault(tls, db)
		_sqlite3DbFree(tls, db, zModuleName)
		return int32(SQLITE_NOMEM)
	}
	(*TVTable)(unsafe.Pointer(pVTable)).Fdb = db
	(*TVTable)(unsafe.Pointer(pVTable)).FpMod = pMod
	(*TVTable)(unsafe.Pointer(pVTable)).FeVtabRisk = uint8(SQLITE_VTABRISK_Normal)
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	*(*uintptr)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FazArg + 1*4)) = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	/* Invoke the virtual table constructor */
	(*(*TVtabCtx)(unsafe.Pointer(bp))).FpTab = pTab
	(*(*TVtabCtx)(unsafe.Pointer(bp))).FpVTable = pVTable
	(*(*TVtabCtx)(unsafe.Pointer(bp))).FpPrior = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
	(*(*TVtabCtx)(unsafe.Pointer(bp))).FbDeclared = 0
	(*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx = bp
	(*TTable)(unsafe.Pointer(pTab)).FnTabRef++
	rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xConstruct})))(tls, db, (*TModule)(unsafe.Pointer(pMod)).FpAux, nArg, azArg, pVTable+8, bp+16)
	_sqlite3DeleteTable(tls, db, pTab)
	(*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx = (*(*TVtabCtx)(unsafe.Pointer(bp))).FpPrior
	if rc == int32(SQLITE_NOMEM) {
		_sqlite3OomFault(tls, db)
	}
	if SQLITE_OK != rc {
		if *(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+23369, libc.VaList(bp+32, zModuleName))
		} else {
			*(*uintptr)(unsafe.Pointer(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+4709, libc.VaList(bp+32, *(*uintptr)(unsafe.Pointer(bp + 16))))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
		}
		_sqlite3DbFree(tls, db, pVTable)
	} else {
		if (*TVTable)(unsafe.Pointer(pVTable)).FpVtab != 0 {
			/* Justification of ALWAYS():  A correct vtab constructor must allocate
			 ** the sqlite3_vtab object if successful.  */
			libc.Xmemset(tls, (*TVTable)(unsafe.Pointer(pVTable)).FpVtab, 0, uint32(12))
			(*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTable)).FpVtab)).FpModule = (*TModule)(unsafe.Pointer(pMod)).FpModule
			(*TModule)(unsafe.Pointer(pMod)).FnRefModule++
			(*TVTable)(unsafe.Pointer(pVTable)).FnRef = int32(1)
			if (*(*TVtabCtx)(unsafe.Pointer(bp))).FbDeclared == 0 {
				zFormat = __ccgo_ts + 23399
				*(*uintptr)(unsafe.Pointer(pzErr)) = _sqlite3MPrintf(tls, db, zFormat, libc.VaList(bp+32, zModuleName))
				_sqlite3VtabUnlock(tls, pVTable)
				rc = int32(SQLITE_ERROR)
			} else {
				oooHidden = uint16(0)
				/* If everything went according to plan, link the new VTable structure
				 ** into the linked list headed by pTab->u.vtab.p. Then loop through the
				 ** columns of the table to see if any of them contain the token "hidden".
				 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
				 ** the type string.  */
				(*TVTable)(unsafe.Pointer(pVTable)).FpNext = (*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(pTab + 44))).Fp
				(*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(pTab + 44))).Fp = pVTable
				iCol = 0
				for {
					if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
						break
					}
					zType = _sqlite3ColumnType(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*12, __ccgo_ts+1672)
					i = 0
					nType = _sqlite3Strlen30(tls, zType)
					i = 0
					for {
						if !(i < nType) {
							break
						}
						if 0 == Xsqlite3_strnicmp(tls, __ccgo_ts+17987, zType+uintptr(i), int32(6)) && (i == 0 || int32(*(*int8)(unsafe.Pointer(zType + uintptr(i-int32(1))))) == int32(' ')) && (int32(*(*int8)(unsafe.Pointer(zType + uintptr(i+int32(6))))) == int32('\000') || int32(*(*int8)(unsafe.Pointer(zType + uintptr(i+int32(6))))) == int32(' ')) {
							break
						}
						goto _3
					_3:
						;
						i++
					}
					if i < nType {
						if *(*int8)(unsafe.Pointer(zType + uintptr(i+int32(6)))) != 0 {
							v4 = int32(1)
						} else {
							v4 = 0
						}
						nDel = int32(6) + v4
						j = i
						for {
							if !(j+nDel <= nType) {
								break
							}
							*(*int8)(unsafe.Pointer(zType + uintptr(j))) = *(*int8)(unsafe.Pointer(zType + uintptr(j+nDel)))
							goto _5
						_5:
							;
							j++
						}
						if int32(*(*int8)(unsafe.Pointer(zType + uintptr(i)))) == int32('\000') && i > 0 {
							*(*int8)(unsafe.Pointer(zType + uintptr(i-int32(1)))) = int8('\000')
						}
						p6 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12 + 10
						*(*Tu16)(unsafe.Pointer(p6)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p6))) | libc.Int32FromInt32(COLFLAG_HIDDEN))
						*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(TF_HasHidden)
						oooHidden = uint16(TF_OOOHidden)
					} else {
						*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(uint32(oooHidden))
					}
					goto _2
				_2:
					;
					iCol++
				}
			}
		}
	}
	_sqlite3DbFree(tls, db, zModuleName)
	return rc
}

// C documentation
//
//	/*
//	** This function is invoked by the parser to call the xConnect() method
//	** of the virtual table pTab. If an error occurs, an error code is returned
//	** and an error left in pParse.
//	**
//	** This call is a no-op if table pTab is not a virtual table.
//	*/
func _sqlite3VtabCallConnect(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pMod, zMod, zModule uintptr
	var rc int32
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _, _ = db, pMod, rc, zMod, zModule
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if _sqlite3GetVTable(tls, db, pTab) != 0 {
		return SQLITE_OK
	}
	/* Locate the required virtual table module */
	zMod = *(*uintptr)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FazArg))
	pMod = _sqlite3HashFind(tls, db+404, zMod)
	if !(pMod != 0) {
		zModule = *(*uintptr)(unsafe.Pointer((*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab + 44))).FazArg))
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23445, libc.VaList(bp+16, zModule))
		rc = int32(SQLITE_ERROR)
	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = _vtabCallConstructor(tls, db, pTab, pMod, (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxConnect, bp)
		if rc != SQLITE_OK {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+4709, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp))))
			(*TParse)(unsafe.Pointer(pParse)).Frc = rc
		}
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Grow the db->aVTrans[] array so that there is room for at least one
//	** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
//	*/
func _growVTrans(tls *libc.TLS, db uintptr) (r int32) {
	var ARRAY_INCR int32
	var aVTrans uintptr
	var nBytes Tsqlite3_int64
	_, _, _ = ARRAY_INCR, aVTrans, nBytes
	ARRAY_INCR = int32(5)
	/* Grow the sqlite3.aVTrans array if required */
	if (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans%ARRAY_INCR == 0 {
		nBytes = int64(4) * (int64((*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) + int64(int64(ARRAY_INCR)))
		aVTrans = _sqlite3DbRealloc(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans, uint64(uint64(nBytes)))
		if !(aVTrans != 0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, aVTrans+uintptr((*Tsqlite3)(unsafe.Pointer(db)).FnVTrans)*4, 0, uint32(4)*uint32(uint32(ARRAY_INCR)))
		(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = aVTrans
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should
//	** have already been reserved using growVTrans().
//	*/
func _addToVTrans(tls *libc.TLS, db uintptr, pVTab uintptr) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	/* Add pVtab to the end of sqlite3.aVTrans */
	v2 = db + 400
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	*(*uintptr)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaVTrans + uintptr(v1)*4)) = pVTab
	_sqlite3VtabLock(tls, pVTab)
}

// C documentation
//
//	/*
//	** This function is invoked by the vdbe to call the xCreate method
//	** of the virtual table named zTab in database iDb.
//	**
//	** If an error occurs, *pzErr is set to point to an English language
//	** description of the error and an SQLITE_XXX error code is returned.
//	** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
//	*/
func _sqlite3VtabCallCreate(tls *libc.TLS, db uintptr, iDb int32, zTab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pMod, pTab, zMod uintptr
	var rc int32
	_, _, _, _ = pMod, pTab, rc, zMod
	rc = SQLITE_OK
	pTab = _sqlite3FindTable(tls, db, zTab, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
	/* Locate the required virtual table module */
	zMod = *(*uintptr)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).FazArg))
	pMod = _sqlite3HashFind(tls, db+404, zMod)
	/* If the module has been registered and includes a Create method,
	 ** invoke it now. If the module has not been registered, return an
	 ** error. Otherwise, do nothing.
	 */
	if pMod == uintptr(0) || (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxCreate == uintptr(0) || (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxDestroy == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+23445, libc.VaList(bp+8, zMod))
		rc = int32(SQLITE_ERROR)
	} else {
		rc = _vtabCallConstructor(tls, db, pTab, pMod, (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxCreate, pzErr)
	}
	/* Justification of ALWAYS():  The xConstructor method is required to
	 ** create a valid sqlite3_vtab if it returns SQLITE_OK. */
	if rc == SQLITE_OK && _sqlite3GetVTable(tls, db, pTab) != 0 {
		rc = _growVTrans(tls, db)
		if rc == SQLITE_OK {
			_addToVTrans(tls, db, _sqlite3GetVTable(tls, db, pTab))
		}
	}
	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(304)
	defer tls.Free(304)
	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+284 */ 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)(unsafe.Pointer(bp + 284)) = 0
		for cond := true; cond; cond = *(*int32)(unsafe.Pointer(bp + 284)) == int32(TK_SPACE) {
			z += uintptr(_sqlite3GetToken(tls, z, bp+284))
		}
		if *(*int32)(unsafe.Pointer(bp + 284)) != int32(_aKeyword1[i]) {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+23464, 0)
			return int32(SQLITE_ERROR)
		}
		goto _1
	_1:
		;
		i++
	}
	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(156227)))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		return _sqlite3MisuseError(tls, int32(156229))
	}
	pTab = (*TVtabCtx)(unsafe.Pointer(pCtx)).FpTab
	_sqlite3ParseObjectInit(tls, bp, db)
	(*(*TParse)(unsafe.Pointer(bp))).FeParseMode = uint8(PARSE_MODE_DECLARE_VTAB)
	(*(*TParse)(unsafe.Pointer(bp))).FdisableTriggers = uint8(1)
	/* 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 = int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy)
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
	(*(*TParse)(unsafe.Pointer(bp))).FnQueryLoop = int16(1)
	if SQLITE_OK == _sqlite3RunParser(tls, bp, zCreateTable) {
		if !((*TTable)(unsafe.Pointer(pTab)).FaCol != 0) {
			pNew = (*(*TParse)(unsafe.Pointer(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 + 44))).FpDfltList)
			v2 = (*TTable)(unsafe.Pointer(pNew)).FnCol
			(*TTable)(unsafe.Pointer(pTab)).FnCol = v2
			(*TTable)(unsafe.Pointer(pTab)).FnNVCol = v2
			*(*Tu32)(unsafe.Pointer(pTab + 28)) |= (*TTable)(unsafe.Pointer(pNew)).FtabFlags & uint32(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) && int32((*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)(unsafe.Pointer(bp))).FzErrMsg != 0 {
			v3 = __ccgo_ts + 4709
		} else {
			v3 = uintptr(0)
		}
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), v3, libc.VaList(bp+296, (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg))
		_sqlite3DbFree(tls, db, (*(*TParse)(unsafe.Pointer(bp))).FzErrMsg)
		rc = int32(SQLITE_ERROR)
	}
	(*(*TParse)(unsafe.Pointer(bp))).FeParseMode = uint8(PARSE_MODE_NORMAL)
	if (*(*TParse)(unsafe.Pointer(bp))).FpVdbe != 0 {
		_sqlite3VdbeFinalize(tls, (*(*TParse)(unsafe.Pointer(bp))).FpVdbe)
	}
	_sqlite3DeleteTable(tls, db, (*(*TParse)(unsafe.Pointer(bp))).FpNewTable)
	_sqlite3ParseObjectReset(tls, bp)
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(uint8(initBusy))
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

var _aKeyword1 = [3]Tu8{
	0: uint8(TK_CREATE),
	1: uint8(TK_TABLE),
}

// C documentation
//
//	/*
//	** This function is invoked by the vdbe to call the xDestroy method
//	** of the virtual table named zTab in database iDb. This occurs
//	** when a DROP TABLE is mentioned.
//	**
//	** This call is a no-op if zTab is not a virtual table.
//	*/
func _sqlite3VtabCallDestroy(tls *libc.TLS, db uintptr, iDb int32, zTab uintptr) (r int32) {
	var p, pTab, xDestroy uintptr
	var rc int32
	_, _, _, _ = p, pTab, rc, xDestroy
	rc = SQLITE_OK
	pTab = _sqlite3FindTable(tls, db, zTab, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
	if pTab != uintptr(0) && int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).Fp != uintptr(0) {
		p = (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab + 44))).Fp
		for {
			if !(p != 0) {
				break
			}
			if (*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(p)).FpVtab)).FnRef > 0 {
				return int32(SQLITE_LOCKED)
			}
			goto _1
		_1:
			;
			p = (*TVTable)(unsafe.Pointer(p)).FpNext
		}
		p = _vtabDisconnectAll(tls, db, pTab)
		xDestroy = (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(p)).FpMod)).FpModule)).FxDestroy
		if xDestroy == uintptr(0) {
			xDestroy = (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(p)).FpMod)).FpModule)).FxDisconnect
		}
		(*TTable)(unsafe.Pointer(pTab)).FnTabRef++
		rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xDestroy})))(tls, (*TVTable)(unsafe.Pointer(p)).FpVtab)
		/* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
		if rc == SQLITE_OK {
			(*TVTable)(unsafe.Pointer(p)).FpVtab = uintptr(0)
			(*(*struct {
				FnArg  int32
				FazArg uintptr
				Fp     uintptr
			})(unsafe.Pointer(pTab + 44))).Fp = uintptr(0)
			_sqlite3VtabUnlock(tls, p)
		}
		_sqlite3DeleteTable(tls, db, pTab)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function invokes either the xRollback or xCommit method
//	** of each of the virtual tables in the sqlite3.aVTrans array. The method
//	** called is identified by the second argument, "offset", which is
//	** the offset of the method to call in the sqlite3_module structure.
//	**
//	** The array is cleared after invoking the callbacks.
//	*/
func _callFinaliser(tls *libc.TLS, db uintptr, offset int32) {
	var aVTrans, p, pVTab, x uintptr
	var i int32
	_, _, _, _, _ = aVTrans, i, p, pVTab, x
	if (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans != 0 {
		aVTrans = (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans
		(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = uintptr(0)
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) {
				break
			}
			pVTab = *(*uintptr)(unsafe.Pointer(aVTrans + uintptr(i)*4))
			p = (*TVTable)(unsafe.Pointer(pVTab)).FpVtab
			if p != 0 {
				x = *(*uintptr)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(p)).FpModule + uintptr(offset)))
				if x != 0 {
					(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, p)
				}
			}
			(*TVTable)(unsafe.Pointer(pVTab)).FiSavepoint = 0
			_sqlite3VtabUnlock(tls, pVTab)
			goto _1
		_1:
			;
			i++
		}
		_sqlite3DbFree(tls, db, aVTrans)
		(*Tsqlite3)(unsafe.Pointer(db)).FnVTrans = 0
	}
}

// C documentation
//
//	/*
//	** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
//	** array. Return the error code for the first error that occurs, or
//	** SQLITE_OK if all xSync operations are successful.
//	**
//	** If an error message is available, leave it in p->zErrMsg.
//	*/
func _sqlite3VtabSync(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	var aVTrans, pVtab, x, v2 uintptr
	var i, rc int32
	var v3 bool
	_, _, _, _, _, _, _ = aVTrans, i, pVtab, rc, x, v2, v3
	rc = SQLITE_OK
	aVTrans = (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans
	(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = uintptr(0)
	i = 0
	for {
		if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) {
			break
		}
		pVtab = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aVTrans + uintptr(i)*4)))).FpVtab
		if v3 = pVtab != 0; v3 {
			v2 = (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule)).FxSync
			x = v2
		}
		if v3 && v2 != uintptr(0) {
			rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, pVtab)
			_sqlite3VtabImportErrmsg(tls, p, pVtab)
		}
		goto _1
	_1:
		;
		i++
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = aVTrans
	return rc
}

// C documentation
//
//	/*
//	** Invoke the xRollback method of all virtual tables in the
//	** sqlite3.aVTrans array. Then clear the array itself.
//	*/
func _sqlite3VtabRollback(tls *libc.TLS, db uintptr) (r int32) {
	_callFinaliser(tls, db, int32(uint32(libc.UintptrFromInt32(0)+68)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Invoke the xCommit method of all virtual tables in the
//	** sqlite3.aVTrans array. Then clear the array itself.
//	*/
func _sqlite3VtabCommit(tls *libc.TLS, db uintptr) (r int32) {
	_callFinaliser(tls, db, int32(uint32(libc.UintptrFromInt32(0)+64)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If the virtual table pVtab supports the transaction interface
//	** (xBegin/xRollback/xCommit and optionally xSync) and a transaction is
//	** not currently open, invoke the xBegin method now.
//	**
//	** If the xBegin call is successful, place the sqlite3_vtab pointer
//	** in the sqlite3.aVTrans array.
//	*/
func _sqlite3VtabBegin(tls *libc.TLS, db uintptr, pVTab uintptr) (r int32) {
	var i, iSvpt, rc int32
	var pModule uintptr
	_, _, _, _ = i, iSvpt, pModule, rc
	rc = SQLITE_OK
	/* Special case: If db->aVTrans is NULL and db->nVTrans is greater
	 ** than zero, then this function is being called from within a
	 ** virtual module xSync() callback. It is illegal to write to
	 ** virtual module tables in this case, so return SQLITE_LOCKED.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans == uintptr(0) {
		return int32(SQLITE_LOCKED)
	}
	if !(pVTab != 0) {
		return SQLITE_OK
	}
	pModule = (*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTab)).FpVtab)).FpModule
	if (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxBegin != 0 {
		/* If pVtab is already in the aVTrans array, return early */
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) {
				break
			}
			if *(*uintptr)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaVTrans + uintptr(i)*4)) == pVTab {
				return SQLITE_OK
			}
			goto _1
		_1:
			;
			i++
		}
		/* Invoke the xBegin method. If successful, add the vtab to the
		 ** sqlite3.aVTrans[] array. */
		rc = _growVTrans(tls, db)
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxBegin})))(tls, (*TVTable)(unsafe.Pointer(pVTab)).FpVtab)
			if rc == SQLITE_OK {
				iSvpt = (*Tsqlite3)(unsafe.Pointer(db)).FnStatement + (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint
				_addToVTrans(tls, db, pVTab)
				if iSvpt != 0 && (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxSavepoint != 0 {
					(*TVTable)(unsafe.Pointer(pVTab)).FiSavepoint = iSvpt
					rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxSavepoint})))(tls, (*TVTable)(unsafe.Pointer(pVTab)).FpVtab, iSvpt-int32(1))
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Invoke either the xSavepoint, xRollbackTo or xRelease method of all
//	** virtual tables that currently have an open transaction. Pass iSavepoint
//	** as the second argument to the virtual table method invoked.
//	**
//	** If op is SAVEPOINT_BEGIN, the xSavepoint method is invoked. If it is
//	** SAVEPOINT_ROLLBACK, the xRollbackTo method. Otherwise, if op is
//	** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with
//	** an open transaction is invoked.
//	**
//	** If any virtual table method returns an error code other than SQLITE_OK,
//	** processing is abandoned and the error returned to the caller of this
//	** function immediately. If all calls to virtual table methods are successful,
//	** SQLITE_OK is returned.
//	*/
func _sqlite3VtabSavepoint(tls *libc.TLS, db uintptr, op int32, iSavepoint int32) (r int32) {
	var i, rc int32
	var pMod, pVTab, xMethod uintptr
	var savedFlags Tu64
	_, _, _, _, _, _ = i, pMod, pVTab, rc, savedFlags, xMethod
	rc = SQLITE_OK
	if (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans != 0 {
		i = 0
		for {
			if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) {
				break
			}
			pVTab = *(*uintptr)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaVTrans + uintptr(i)*4))
			pMod = (*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTab)).FpMod)).FpModule
			if (*TVTable)(unsafe.Pointer(pVTab)).FpVtab != 0 && (*Tsqlite3_module)(unsafe.Pointer(pMod)).FiVersion >= int32(2) {
				_sqlite3VtabLock(tls, pVTab)
				switch op {
				case SAVEPOINT_BEGIN:
					xMethod = (*Tsqlite3_module)(unsafe.Pointer(pMod)).FxSavepoint
					(*TVTable)(unsafe.Pointer(pVTab)).FiSavepoint = iSavepoint + int32(1)
				case int32(SAVEPOINT_ROLLBACK):
					xMethod = (*Tsqlite3_module)(unsafe.Pointer(pMod)).FxRollbackTo
				default:
					xMethod = (*Tsqlite3_module)(unsafe.Pointer(pMod)).FxRelease
					break
				}
				if xMethod != 0 && (*TVTable)(unsafe.Pointer(pVTab)).FiSavepoint > iSavepoint {
					savedFlags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_Defensive)
					*(*Tu64)(unsafe.Pointer(db + 32)) &= ^libc.Uint64FromInt32(SQLITE_Defensive)
					rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xMethod})))(tls, (*TVTable)(unsafe.Pointer(pVTab)).FpVtab, iSavepoint)
					*(*Tu64)(unsafe.Pointer(db + 32)) |= savedFlags
				}
				_sqlite3VtabUnlock(tls, pVTab)
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** The first parameter (pDef) is a function implementation.  The
//	** second parameter (pExpr) is the first argument to this function.
//	** If pExpr is a column in a virtual table, then let the virtual
//	** table implementation have an opportunity to overload the function.
//	**
//	** This routine is used to allow virtual table implementations to
//	** overload MATCH, LIKE, GLOB, and REGEXP operators.
//	**
//	** Return either the pDef argument (indicating no change) or a
//	** new FuncDef structure that is marked as ephemeral using the
//	** SQLITE_FUNC_EPHEM flag.
//	*/
func _sqlite3VtabOverloadFunction(tls *libc.TLS, db uintptr, pDef uintptr, nArg int32, pExpr uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pMod, pNew, pTab, pVtab uintptr
	var rc int32
	var _ /* pArg at bp+4 */ uintptr
	var _ /* xSFunc at bp+0 */ uintptr
	_, _, _, _, _ = pMod, pNew, pTab, pVtab, rc
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	rc = 0
	/* Check to see the left operand is a column in a virtual table */
	if pExpr == uintptr(0) {
		return pDef
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLUMN) {
		return pDef
	}
	pTab = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
	if pTab == uintptr(0) {
		return pDef
	}
	if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		return pDef
	}
	pVtab = (*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, db, pTab))).FpVtab
	pMod = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule
	if (*Tsqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction == uintptr(0) {
		return pDef
	}
	/* Call the xFindFunction method on the virtual table implementation
	 ** to see if the implementation wants to overload this function.
	 **
	 ** Though undocumented, we have historically always invoked xFindFunction
	 ** with an all lower-case function name.  Continue in this tradition to
	 ** avoid any chance of an incompatibility.
	 */
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction})))(tls, pVtab, nArg, (*TFuncDef)(unsafe.Pointer(pDef)).FzName, bp, bp+4)
	if rc == 0 {
		return pDef
	}
	/* Create a new ephemeral function definition for the overloaded
	 ** function */
	pNew = _sqlite3DbMallocZero(tls, db, uint64(uint32(40)+uint32(_sqlite3Strlen30(tls, (*TFuncDef)(unsafe.Pointer(pDef)).FzName))+uint32(1)))
	if pNew == uintptr(0) {
		return pDef
	}
	*(*TFuncDef)(unsafe.Pointer(pNew)) = *(*TFuncDef)(unsafe.Pointer(pDef))
	(*TFuncDef)(unsafe.Pointer(pNew)).FzName = pNew + 1*40
	libc.Xmemcpy(tls, pNew+1*40, (*TFuncDef)(unsafe.Pointer(pDef)).FzName, uint32(_sqlite3Strlen30(tls, (*TFuncDef)(unsafe.Pointer(pDef)).FzName)+int32(1)))
	(*TFuncDef)(unsafe.Pointer(pNew)).FxSFunc = *(*uintptr)(unsafe.Pointer(bp))
	(*TFuncDef)(unsafe.Pointer(pNew)).FpUserData = *(*uintptr)(unsafe.Pointer(bp + 4))
	*(*Tu32)(unsafe.Pointer(pNew + 4)) |= uint32(SQLITE_FUNC_EPHEM)
	return pNew
}

// C documentation
//
//	/*
//	** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
//	** array so that an OP_VBegin will get generated for it.  Add pTab to the
//	** array if it is missing.  If pTab is already in the array, this routine
//	** is a no-op.
//	*/
func _sqlite3VtabMakeWritable(tls *libc.TLS, pParse uintptr, pTab uintptr) {
	var apVtabLock, pToplevel, v1, v4 uintptr
	var i, n, v3 int32
	_, _, _, _, _, _, _ = apVtabLock, i, n, pToplevel, v1, v3, v4
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pToplevel = v1
	i = 0
	for {
		if !(i < (*TParse)(unsafe.Pointer(pToplevel)).FnVtabLock) {
			break
		}
		if pTab == *(*uintptr)(unsafe.Pointer((*TParse)(unsafe.Pointer(pToplevel)).FapVtabLock + uintptr(i)*4)) {
			return
		}
		goto _2
	_2:
		;
		i++
	}
	n = int32(uint32((*TParse)(unsafe.Pointer(pToplevel)).FnVtabLock+libc.Int32FromInt32(1)) * uint32(4))
	apVtabLock = _sqlite3Realloc(tls, (*TParse)(unsafe.Pointer(pToplevel)).FapVtabLock, uint64(uint64(n)))
	if apVtabLock != 0 {
		(*TParse)(unsafe.Pointer(pToplevel)).FapVtabLock = apVtabLock
		v4 = pToplevel + 224
		v3 = *(*int32)(unsafe.Pointer(v4))
		*(*int32)(unsafe.Pointer(v4))++
		*(*uintptr)(unsafe.Pointer((*TParse)(unsafe.Pointer(pToplevel)).FapVtabLock + uintptr(v3)*4)) = pTab
	} else {
		_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(pToplevel)).Fdb)
	}
}

// C documentation
//
//	/*
//	** Check to see if virtual table module pMod can be have an eponymous
//	** virtual table instance.  If it can, create one if one does not already
//	** exist. Return non-zero if either the eponymous virtual table instance
//	** exists when this routine returns or if an attempt to create it failed
//	** and an error message was left in pParse.
//	**
//	** An eponymous virtual table instance is one that is named after its
//	** module, and more importantly, does not require a CREATE VIRTUAL TABLE
//	** statement in order to come into existence.  Eponymous virtual table
//	** instances always exist.  They cannot be DROP-ed.
//	**
//	** Any virtual table module for which xConnect and xCreate are the same
//	** method can have an eponymous virtual table instance.
//	*/
func _sqlite3VtabEponymousTableInit(tls *libc.TLS, pParse uintptr, pMod uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pModule, pTab uintptr
	var rc int32
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _ = db, pModule, pTab, rc
	pModule = (*TModule)(unsafe.Pointer(pMod)).FpModule
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TModule)(unsafe.Pointer(pMod)).FpEpoTab != 0 {
		return int32(1)
	}
	if (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxCreate != uintptr(0) && (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxCreate != (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxConnect {
		return 0
	}
	pTab = _sqlite3DbMallocZero(tls, db, uint64(64))
	if pTab == uintptr(0) {
		return 0
	}
	(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, db, (*TModule)(unsafe.Pointer(pMod)).FzName)
	if (*TTable)(unsafe.Pointer(pTab)).FzName == uintptr(0) {
		_sqlite3DbFree(tls, db, pTab)
		return 0
	}
	(*TModule)(unsafe.Pointer(pMod)).FpEpoTab = pTab
	(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
	(*TTable)(unsafe.Pointer(pTab)).FeTabType = uint8(TABTYP_VTAB)
	(*TTable)(unsafe.Pointer(pTab)).FpSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema
	(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
	*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(TF_Eponymous)
	_addModuleArgument(tls, pParse, pTab, _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pTab)).FzName))
	_addModuleArgument(tls, pParse, pTab, uintptr(0))
	_addModuleArgument(tls, pParse, pTab, _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pTab)).FzName))
	rc = _vtabCallConstructor(tls, db, pTab, pMod, (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxConnect, bp)
	if rc != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+4709, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp))))
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
		_sqlite3VtabEponymousTableClear(tls, db, pMod)
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Erase the eponymous virtual table instance associated with
//	** virtual table module pMod, if it exists.
//	*/
func _sqlite3VtabEponymousTableClear(tls *libc.TLS, db uintptr, pMod uintptr) {
	var pTab uintptr
	_ = pTab
	pTab = (*TModule)(unsafe.Pointer(pMod)).FpEpoTab
	if pTab != uintptr(0) {
		/* Mark the table as Ephemeral prior to deleting it, so that the
		 ** sqlite3DeleteTable() routine will know that it is not stored in
		 ** the schema. */
		*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(TF_Ephemeral)
		_sqlite3DeleteTable(tls, db, pTab)
		(*TModule)(unsafe.Pointer(pMod)).FpEpoTab = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Return the ON CONFLICT resolution mode in effect for the virtual
//	** table update operation currently in progress.
//	**
//	** The results of this routine are undefined unless it is called from
//	** within an xUpdate method.
//	*/
func Xsqlite3_vtab_on_conflict(tls *libc.TLS, db uintptr) (r int32) {
	return int32(_aMap[int32((*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict)-int32(1)])
}

var _aMap = [5]uint8{
	0: uint8(SQLITE_ROLLBACK),
	1: uint8(SQLITE_ABORT),
	2: uint8(SQLITE_FAIL),
	3: uint8(SQLITE_IGNORE),
	4: uint8(SQLITE_REPLACE),
}

// C documentation
//
//	/*
//	** Call from within the xCreate() or xConnect() methods to provide
//	** the SQLite core with additional information about the behavior
//	** of the virtual table being implemented.
//	*/
func Xsqlite3_vtab_config(tls *libc.TLS, db uintptr, op int32, va uintptr) (r int32) {
	var ap Tva_list
	var p uintptr
	var rc int32
	_, _, _ = ap, p, rc
	rc = SQLITE_OK
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
	if !(p != 0) {
		rc = _sqlite3MisuseError(tls, int32(156723))
	} else {
		ap = va
		switch op {
		case int32(SQLITE_VTAB_CONSTRAINT_SUPPORT):
			(*TVTable)(unsafe.Pointer((*TVtabCtx)(unsafe.Pointer(p)).FpVTable)).FbConstraint = uint8(libc.VaInt32(&ap))
		case int32(SQLITE_VTAB_INNOCUOUS):
			(*TVTable)(unsafe.Pointer((*TVtabCtx)(unsafe.Pointer(p)).FpVTable)).FeVtabRisk = uint8(SQLITE_VTABRISK_Low)
		case int32(SQLITE_VTAB_DIRECTONLY):
			(*TVTable)(unsafe.Pointer((*TVtabCtx)(unsafe.Pointer(p)).FpVTable)).FeVtabRisk = uint8(SQLITE_VTABRISK_High)
		case int32(SQLITE_VTAB_USES_ALL_SCHEMAS):
			(*TVTable)(unsafe.Pointer((*TVtabCtx)(unsafe.Pointer(p)).FpVTable)).FbAllSchemas = uint8(1)
		default:
			rc = _sqlite3MisuseError(tls, int32(156745))
			break
		}
		_ = ap
	}
	if rc != SQLITE_OK {
		_sqlite3Error(tls, db, rc)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

/************** End of vtab.c ************************************************/
/************** Begin file wherecode.c ***************************************/
/*
** 2015-06-06
**
** 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 file was split off from where.c on 2015-06-06 in order to reduce the
** size of where.c and make it easier to edit.  This file contains the routines
** that actually generate the bulk of the WHERE loop code.  The original where.c
** file retains the code that does query planning and analysis.
 */
/* #include "sqliteInt.h" */
/************** Include whereInt.h in the middle of wherecode.c **************/
/************** Begin file whereInt.h ****************************************/
/*
** 2013-11-12
**
** 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 structure and macro definitions for the query
** planner logic in "where.c".  These definitions are broken out into
** a separate source file for easier editing.
 */

// C documentation
//
//	/* Forward references
//	*/
type TWhereClause = struct {
	F__ccgo_align  [0]uint32
	FpWInfo        uintptr
	FpOuter        uintptr
	Fop            Tu8
	FhasOr         Tu8
	FnTerm         int32
	FnSlot         int32
	FnBase         int32
	Fa             uintptr
	F__ccgo_align8 [4]byte
	FaStatic       [8]TWhereTerm
}

type WhereClause = TWhereClause

type TWhereMaskSet = struct {
	FbVarSelect int32
	Fn          int32
	Fix         [64]int32
}

type WhereMaskSet = TWhereMaskSet

type TWhereOrInfo = struct {
	F__ccgo_align [0]uint32
	Fwc           TWhereClause
	Findexable    TBitmask
}

type WhereOrInfo = TWhereOrInfo

type TWhereAndInfo = struct {
	F__ccgo_align [0]uint32
	Fwc           TWhereClause
}

type WhereAndInfo = TWhereAndInfo

type TWhereLevel = struct {
	F__ccgo_align [0]uint32
	FiLeftJoin    int32
	FiTabCur      int32
	FiIdxCur      int32
	FaddrBrk      int32
	FaddrNxt      int32
	FaddrSkip     int32
	FaddrCont     int32
	FaddrFirst    int32
	FaddrBody     int32
	FregBignull   int32
	FaddrBignull  int32
	FregFilter    int32
	FpRJ          uintptr
	FiFrom        Tu8
	Fop           Tu8
	Fp3           Tu8
	Fp5           Tu8
	Fp1           int32
	Fp2           int32
	Fu            struct {
		FpCoveringIdx [0]uintptr
		Fin           struct {
			FnIn     int32
			FaInLoop uintptr
		}
	}
	FpWLoop         uintptr
	F__ccgo_align21 [4]byte
	FnotReady       TBitmask
}

type WhereLevel = TWhereLevel

type TWhereLoop = struct {
	F__ccgo_align [0]uint32
	Fprereq       TBitmask
	FmaskSelf     TBitmask
	FiTab         Tu8
	FiSortIdx     Tu8
	FrSetup       TLogEst
	FrRun         TLogEst
	FnOut         TLogEst
	Fu            struct {
		Fvtab [0]struct {
			FidxNum    int32
			F__ccgo4   uint8
			FisOrdered Ti8
			FomitMask  Tu16
			FidxStr    uintptr
			FmHandleIn Tu32
		}
		Fbtree struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
		}
		F__ccgo_pad2 [4]byte
	}
	FwsFlags     Tu32
	FnLTerm      Tu16
	FnSkip       Tu16
	FnLSlot      Tu16
	FaLTerm      uintptr
	FpNextLoop   uintptr
	FaLTermSpace [3]uintptr
}

type WhereLoop = TWhereLoop

type TWherePath = struct {
	F__ccgo_align [0]uint32
	FmaskLoop     TBitmask
	FrevLoop      TBitmask
	FnRow         TLogEst
	FrCost        TLogEst
	FrUnsorted    TLogEst
	FisOrdered    Ti8
	FaLoop        uintptr
	F__ccgo_pad7  [4]byte
}

type WherePath = TWherePath

type TWhereTerm = struct {
	F__ccgo_align [0]uint32
	FpExpr        uintptr
	FpWC          uintptr
	FtruthProb    TLogEst
	FwtFlags      Tu16
	FeOperator    Tu16
	FnChild       Tu8
	FeMatchOp     Tu8
	FiParent      int32
	FleftCursor   int32
	Fu            struct {
		FpOrInfo  [0]uintptr
		FpAndInfo [0]uintptr
		Fx        struct {
			FleftColumn int32
			FiField     int32
		}
	}
	FprereqRight TBitmask
	FprereqAll   TBitmask
}

type WhereTerm = TWhereTerm

type TWhereLoopBuilder = struct {
	FpWInfo     uintptr
	FpWC        uintptr
	FpNew       uintptr
	FpOrSet     uintptr
	FpRec       uintptr
	FnRecValid  int32
	FbldFlags1  uint8
	FbldFlags2  uint8
	FiPlanLimit uint32
}

type WhereLoopBuilder = TWhereLoopBuilder

type TWhereScan = struct {
	FpOrigWC   uintptr
	FpWC       uintptr
	FzCollName uintptr
	FpIdxExpr  uintptr
	Fk         int32
	FopMask    Tu32
	Fidxaff    int8
	FiEquiv    uint8
	FnEquiv    uint8
	FaiCur     [11]int32
	FaiColumn  [11]Ti16
}

type WhereScan = TWhereScan

type TWhereOrCost = struct {
	F__ccgo_align [0]uint32
	Fprereq       TBitmask
	FrRun         TLogEst
	FnOut         TLogEst
	F__ccgo_pad3  [4]byte
}

type WhereOrCost = TWhereOrCost

type TWhereOrSet = struct {
	F__ccgo_align  [0]uint32
	Fn             Tu16
	F__ccgo_align1 [6]byte
	Fa             [3]TWhereOrCost
}

type WhereOrSet = TWhereOrSet

type TWhereMemBlock = struct {
	F__ccgo_align  [0]uint32
	FpNext         uintptr
	F__ccgo_align1 [4]byte
	Fsz            Tu64
}

type WhereMemBlock = TWhereMemBlock

type TWhereRightJoin = struct {
	FiMatch     int32
	FregBloom   int32
	FregReturn  int32
	FaddrSubrtn int32
	FendSubrtn  int32
}

type WhereRightJoin = TWhereRightJoin

/*
** This object is a header on a block of allocated memory that will be
** automatically freed when its WInfo object is destructed.
 */
type TWhereMemBlock1 = struct {
	F__ccgo_align  [0]uint32
	FpNext         uintptr
	F__ccgo_align1 [4]byte
	Fsz            Tu64
}

type WhereMemBlock1 = TWhereMemBlock1

/*
** Extra information attached to a WhereLevel that is a RIGHT JOIN.
 */
type TWhereRightJoin1 = struct {
	FiMatch     int32
	FregBloom   int32
	FregReturn  int32
	FaddrSubrtn int32
	FendSubrtn  int32
}

type WhereRightJoin1 = TWhereRightJoin1

/*
** This object contains information needed to implement a single nested
** loop in WHERE clause.
**
** Contrast this object with WhereLoop.  This object describes the
** implementation of the loop.  WhereLoop describes the algorithm.
** This object contains a pointer to the WhereLoop algorithm as one of
** its elements.
**
** The WhereInfo object contains a single instance of this object for
** each term in the FROM clause (which is to say, for each of the
** nested loops as implemented).  The order of WhereLevel objects determines
** the loop nested order, with WhereInfo.a[0] being the outer loop and
** WhereInfo.a[WhereInfo.nLevel-1] being the inner loop.
 */
type TWhereLevel1 = struct {
	F__ccgo_align [0]uint32
	FiLeftJoin    int32
	FiTabCur      int32
	FiIdxCur      int32
	FaddrBrk      int32
	FaddrNxt      int32
	FaddrSkip     int32
	FaddrCont     int32
	FaddrFirst    int32
	FaddrBody     int32
	FregBignull   int32
	FaddrBignull  int32
	FregFilter    int32
	FpRJ          uintptr
	FiFrom        Tu8
	Fop           Tu8
	Fp3           Tu8
	Fp5           Tu8
	Fp1           int32
	Fp2           int32
	Fu            struct {
		FpCoveringIdx [0]uintptr
		Fin           struct {
			FnIn     int32
			FaInLoop uintptr
		}
	}
	FpWLoop         uintptr
	F__ccgo_align21 [4]byte
	FnotReady       TBitmask
}

type WhereLevel1 = TWhereLevel1

/*
** Each instance of this object represents an algorithm for evaluating one
** term of a join.  Every term of the FROM clause will have at least
** one corresponding WhereLoop object (unless INDEXED BY constraints
** prevent a query solution - which is an error) and many terms of the
** FROM clause will have multiple WhereLoop objects, each describing a
** potential way of implementing that FROM-clause term, together with
** dependencies and cost estimates for using the chosen algorithm.
**
** Query planning consists of building up a collection of these WhereLoop
** objects, then computing a particular sequence of WhereLoop objects, with
** one WhereLoop object per FROM clause term, that satisfy all dependencies
** and that minimize the overall cost.
 */
type TWhereLoop1 = struct {
	F__ccgo_align [0]uint32
	Fprereq       TBitmask
	FmaskSelf     TBitmask
	FiTab         Tu8
	FiSortIdx     Tu8
	FrSetup       TLogEst
	FrRun         TLogEst
	FnOut         TLogEst
	Fu            struct {
		Fvtab [0]struct {
			FidxNum    int32
			F__ccgo4   uint8
			FisOrdered Ti8
			FomitMask  Tu16
			FidxStr    uintptr
			FmHandleIn Tu32
		}
		Fbtree struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
		}
		F__ccgo_pad2 [4]byte
	}
	FwsFlags     Tu32
	FnLTerm      Tu16
	FnSkip       Tu16
	FnLSlot      Tu16
	FaLTerm      uintptr
	FpNextLoop   uintptr
	FaLTermSpace [3]uintptr
}

type WhereLoop1 = TWhereLoop1

/* This object holds the prerequisites and the cost of running a
** subquery on one operand of an OR operator in the WHERE clause.
** See WhereOrSet for additional information
 */
type TWhereOrCost1 = struct {
	F__ccgo_align [0]uint32
	Fprereq       TBitmask
	FrRun         TLogEst
	FnOut         TLogEst
	F__ccgo_pad3  [4]byte
}

type WhereOrCost1 = TWhereOrCost1

/* The WhereOrSet object holds a set of possible WhereOrCosts that
** correspond to the subquery(s) of OR-clause processing.  Only the
** best N_OR_COST elements are retained.
 */
type TWhereOrSet1 = struct {
	F__ccgo_align  [0]uint32
	Fn             Tu16
	F__ccgo_align1 [6]byte
	Fa             [3]TWhereOrCost
}

type WhereOrSet1 = TWhereOrSet1

/*
** Each instance of this object holds a sequence of WhereLoop objects
** that implement some or all of a query plan.
**
** Think of each WhereLoop object as a node in a graph with arcs
** showing dependencies and costs for travelling between nodes.  (That is
** not a completely accurate description because WhereLoop costs are a
** vector, not a scalar, and because dependencies are many-to-one, not
** one-to-one as are graph nodes.  But it is a useful visualization aid.)
** Then a WherePath object is a path through the graph that visits some
** or all of the WhereLoop objects once.
**
** The "solver" works by creating the N best WherePath objects of length
** 1.  Then using those as a basis to compute the N best WherePath objects
** of length 2.  And so forth until the length of WherePaths equals the
** number of nodes in the FROM clause.  The best (lowest cost) WherePath
** at the end is the chosen query plan.
 */
type TWherePath1 = struct {
	F__ccgo_align [0]uint32
	FmaskLoop     TBitmask
	FrevLoop      TBitmask
	FnRow         TLogEst
	FrCost        TLogEst
	FrUnsorted    TLogEst
	FisOrdered    Ti8
	FaLoop        uintptr
	F__ccgo_pad7  [4]byte
}

type WherePath1 = TWherePath1

/*
** The query generator uses an array of instances of this structure to
** help it analyze the subexpressions of the WHERE clause.  Each WHERE
** clause subexpression is separated from the others by AND operators,
** usually, or sometimes subexpressions separated by OR.
**
** All WhereTerms are collected into a single WhereClause structure.
** The following identity holds:
**
**        WhereTerm.pWC->a[WhereTerm.idx] == WhereTerm
**
** When a term is of the form:
**
**              X <op> <expr>
**
** where X is a column name and <op> is one of certain operators,
** then WhereTerm.leftCursor and WhereTerm.u.leftColumn record the
** cursor number and column number for X.  WhereTerm.eOperator records
** the <op> using a bitmask encoding defined by WO_xxx below.  The
** use of a bitmask encoding for the operator allows us to search
** quickly for terms that match any of several different operators.
**
** A WhereTerm might also be two or more subterms connected by OR:
**
**         (t1.X <op> <expr>) OR (t1.Y <op> <expr>) OR ....
**
** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR
** and the WhereTerm.u.pOrInfo field points to auxiliary information that
** is collected about the OR clause.
**
** If a term in the WHERE clause does not match either of the two previous
** categories, then eOperator==0.  The WhereTerm.pExpr field is still set
** to the original subexpression content and wtFlags is set up appropriately
** but no other fields in the WhereTerm object are meaningful.
**
** When eOperator!=0, prereqRight and prereqAll record sets of cursor numbers,
** but they do so indirectly.  A single WhereMaskSet structure translates
** cursor number into bits and the translated bit is stored in the prereq
** fields.  The translation is used in order to maximize the number of
** bits that will fit in a Bitmask.  The VDBE cursor numbers might be
** spread out over the non-negative integers.  For example, the cursor
** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45.  The WhereMaskSet
** translates these sparse cursor numbers into consecutive integers
** beginning with 0 in order to make the best possible use of the available
** bits in the Bitmask.  So, in the example above, the cursor numbers
** would be mapped into integers 0 through 7.
**
** The number of terms in a join is limited by the number of bits
** in prereqRight and prereqAll.  The default is 64 bits, hence SQLite
** is only able to process joins with 64 or fewer tables.
 */
type TWhereTerm1 = struct {
	F__ccgo_align [0]uint32
	FpExpr        uintptr
	FpWC          uintptr
	FtruthProb    TLogEst
	FwtFlags      Tu16
	FeOperator    Tu16
	FnChild       Tu8
	FeMatchOp     Tu8
	FiParent      int32
	FleftCursor   int32
	Fu            struct {
		FpOrInfo  [0]uintptr
		FpAndInfo [0]uintptr
		Fx        struct {
			FleftColumn int32
			FiField     int32
		}
	}
	FprereqRight TBitmask
	FprereqAll   TBitmask
}

type WhereTerm1 = TWhereTerm1

/*
** Allowed values of WhereTerm.wtFlags
 */

/*
** An instance of the WhereScan object is used as an iterator for locating
** terms in the WHERE clause that are useful to the query planner.
 */
type TWhereScan1 = struct {
	FpOrigWC   uintptr
	FpWC       uintptr
	FzCollName uintptr
	FpIdxExpr  uintptr
	Fk         int32
	FopMask    Tu32
	Fidxaff    int8
	FiEquiv    uint8
	FnEquiv    uint8
	FaiCur     [11]int32
	FaiColumn  [11]Ti16
}

type WhereScan1 = TWhereScan1

/*
** An instance of the following structure holds all information about a
** WHERE clause.  Mostly this is a container for one or more WhereTerms.
**
** Explanation of pOuter:  For a WHERE clause of the form
**
**           a AND ((b AND c) OR (d AND e)) AND f
**
** There are separate WhereClause objects for the whole clause and for
** the subclauses "(b AND c)" and "(d AND e)".  The pOuter field of the
** subclauses points to the WhereClause object for the whole clause.
 */
type TWhereClause1 = struct {
	F__ccgo_align  [0]uint32
	FpWInfo        uintptr
	FpOuter        uintptr
	Fop            Tu8
	FhasOr         Tu8
	FnTerm         int32
	FnSlot         int32
	FnBase         int32
	Fa             uintptr
	F__ccgo_align8 [4]byte
	FaStatic       [8]TWhereTerm
}

type WhereClause1 = TWhereClause1

/*
** A WhereTerm with eOperator==WO_OR has its u.pOrInfo pointer set to
** a dynamically allocated instance of the following structure.
 */
type TWhereOrInfo1 = struct {
	F__ccgo_align [0]uint32
	Fwc           TWhereClause
	Findexable    TBitmask
}

type WhereOrInfo1 = TWhereOrInfo1

/*
** A WhereTerm with eOperator==WO_AND has its u.pAndInfo pointer set to
** a dynamically allocated instance of the following structure.
 */
type TWhereAndInfo1 = struct {
	F__ccgo_align [0]uint32
	Fwc           TWhereClause
}

type WhereAndInfo1 = TWhereAndInfo1

/*
** An instance of the following structure keeps track of a mapping
** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
**
** The VDBE cursor numbers are small integers contained in
** SrcItem.iCursor and Expr.iTable fields.  For any given WHERE
** clause, the cursor numbers might not begin with 0 and they might
** contain gaps in the numbering sequence.  But we want to make maximum
** use of the bits in our bitmasks.  This structure provides a mapping
** from the sparse cursor numbers into consecutive integers beginning
** with 0.
**
** If WhereMaskSet.ix[A]==B it means that The A-th bit of a Bitmask
** corresponds VDBE cursor number B.  The A-th bit of a bitmask is 1<<A.
**
** For example, if the WHERE clause expression used these VDBE
** cursors:  4, 5, 8, 29, 57, 73.  Then the  WhereMaskSet structure
** would map those cursor numbers into bits 0 through 5.
**
** Note that the mapping is not necessarily ordered.  In the example
** above, the mapping might go like this:  4->3, 5->1, 8->2, 29->0,
** 57->5, 73->4.  Or one of 719 other combinations might be used. It
** does not really matter.  What is important is that sparse cursor
** numbers all get mapped into bit numbers that begin with 0 and contain
** no gaps.
 */
type TWhereMaskSet1 = struct {
	FbVarSelect int32
	Fn          int32
	Fix         [64]int32
}

type WhereMaskSet1 = TWhereMaskSet1

/*
** This object is a convenience wrapper holding all information needed
** to construct WhereLoop objects for a particular query.
 */
type TWhereLoopBuilder1 = struct {
	FpWInfo     uintptr
	FpWC        uintptr
	FpNew       uintptr
	FpOrSet     uintptr
	FpRec       uintptr
	FnRecValid  int32
	FbldFlags1  uint8
	FbldFlags2  uint8
	FiPlanLimit uint32
}

type WhereLoopBuilder1 = TWhereLoopBuilder1

/* Allowed values for WhereLoopBuider.bldFlags */

/* The WhereLoopBuilder.iPlanLimit is used to limit the number of
** index+constraint combinations the query planner will consider for a
** particular query.  If this parameter is unlimited, then certain
** pathological queries can spend excess time in the sqlite3WhereBegin()
** routine.  The limit is high enough that is should not impact real-world
** queries.
**
** SQLITE_QUERY_PLANNER_LIMIT is the baseline limit.  The limit is
** increased by SQLITE_QUERY_PLANNER_LIMIT_INCR before each term of the FROM
** clause is processed, so that every table in a join is guaranteed to be
** able to propose a some index+constraint combinations even if the initial
** baseline limit was exhausted by prior tables of the join.
 */

/*
** The WHERE clause processing routine has two halves.  The
** first part does the start of the WHERE loop and the second
** half does the tail of the WHERE loop.  An instance of
** this structure is returned by the first half and passed
** into the second half to give some continuity.
**
** An instance of this object holds the complete state of the query
** planner.
 */
type TWhereInfo1 = struct {
	F__ccgo_align    [0]uint32
	FpParse          uintptr
	FpTabList        uintptr
	FpOrderBy        uintptr
	FpResultSet      uintptr
	FpSelect         uintptr
	FaiCurOnePass    [2]int32
	FiContinue       int32
	FiBreak          int32
	FsavedNQueryLoop int32
	FwctrlFlags      Tu16
	FiLimit          TLogEst
	FnLevel          Tu8
	FnOBSat          Ti8
	FeOnePass        Tu8
	FeDistinct       Tu8
	F__ccgo48        uint8
	FnRowOut         TLogEst
	FiTop            int32
	FiEndWhere       int32
	FpLoops          uintptr
	FpMemToFree      uintptr
	F__ccgo_align24  [4]byte
	FrevMask         TBitmask
	FsWC             TWhereClause
	FsMaskSet        TWhereMaskSet
	Fa               [1]TWhereLevel
}

type WhereInfo1 = TWhereInfo1

/*
** Bitmasks for the operators on WhereTerm objects.  These are all
** operators that are of interest to the query planner.  An
** OR-ed combination of these values can be used when searching for
** particular WhereTerms within a WhereClause.
**
** Value constraints:
**     WO_EQ    == SQLITE_INDEX_CONSTRAINT_EQ
**     WO_LT    == SQLITE_INDEX_CONSTRAINT_LT
**     WO_LE    == SQLITE_INDEX_CONSTRAINT_LE
**     WO_GT    == SQLITE_INDEX_CONSTRAINT_GT
**     WO_GE    == SQLITE_INDEX_CONSTRAINT_GE
 */

/*
** These are definitions of bits in the WhereLoop.wsFlags field.
** The particular combination of bits in each WhereLoop help to
** determine the algorithm that WhereLoop represents.
 */
/*   0x02000000  -- available for reuse */

/************** End of whereInt.h ********************************************/
/************** Continuing where we left off in wherecode.c ******************/

// C documentation
//
//	/*
//	** Return the name of the i-th column of the pIdx index.
//	*/
func _explainIndexColumnName(tls *libc.TLS, pIdx uintptr, i int32) (r uintptr) {
	i = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
	if i == -int32(2) {
		return __ccgo_ts + 23477
	}
	if i == -int32(1) {
		return __ccgo_ts + 18096
	}
	return (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(i)*12))).FzCnName
}

// C documentation
//
//	/*
//	** This routine is a helper for explainIndexRange() below
//	**
//	** pStr holds the text of an expression that we are building up one term
//	** at a time.  This routine adds a new term to the end of the expression.
//	** Terms are separated by AND so add the "AND" text for second and subsequent
//	** terms only.
//	*/
func _explainAppendTerm(tls *libc.TLS, pStr uintptr, pIdx uintptr, nTerm int32, iTerm int32, bAnd int32, zOp uintptr) {
	var i int32
	_ = i
	if bAnd != 0 {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+23484, int32(5))
	}
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+23490, int32(1))
	}
	i = 0
	for {
		if !(i < nTerm) {
			break
		}
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, __ccgo_ts+14524, int32(1))
		}
		Xsqlite3_str_appendall(tls, pStr, _explainIndexColumnName(tls, pIdx, iTerm+i))
		goto _1
	_1:
		;
		i++
	}
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+6479, int32(1))
	}
	Xsqlite3_str_append(tls, pStr, zOp, int32(1))
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+23490, int32(1))
	}
	i = 0
	for {
		if !(i < nTerm) {
			break
		}
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, __ccgo_ts+14524, int32(1))
		}
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+6481, int32(1))
		goto _2
	_2:
		;
		i++
	}
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+6479, int32(1))
	}
}

// C documentation
//
//	/*
//	** Argument pLevel describes a strategy for scanning table pTab. This
//	** function appends text to pStr that describes the subset of table
//	** rows scanned by the strategy in the form of an SQL expression.
//	**
//	** For example, if the query:
//	**
//	**   SELECT * FROM t1 WHERE a=1 AND b>2;
//	**
//	** is run and there is an index on (a, b), then this function returns a
//	** string similar to:
//	**
//	**   "a=? AND b>?"
//	*/
func _explainIndexRange(tls *libc.TLS, pStr uintptr, pLoop uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, j int32
	var nEq, nSkip Tu16
	var pIndex, z, v2 uintptr
	_, _, _, _, _, _, _ = i, j, nEq, nSkip, pIndex, z, v2
	pIndex = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
	nEq = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq
	nSkip = (*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip
	if int32(int32(nEq)) == 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(libc.Int32FromInt32(WHERE_BTM_LIMIT)|libc.Int32FromInt32(WHERE_TOP_LIMIT)) == uint32(0) {
		return
	}
	Xsqlite3_str_append(tls, pStr, __ccgo_ts+23492, int32(2))
	i = 0
	for {
		if !(i < int32(int32(nEq))) {
			break
		}
		z = _explainIndexColumnName(tls, pIndex, i)
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, __ccgo_ts+23484, int32(5))
		}
		if i >= int32(int32(nSkip)) {
			v2 = __ccgo_ts + 23495
		} else {
			v2 = __ccgo_ts + 23500
		}
		Xsqlite3_str_appendf(tls, pStr, v2, libc.VaList(bp+8, z))
		goto _1
	_1:
		;
		i++
	}
	j = i
	if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
		_explainAppendTerm(tls, pStr, pIndex, int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnBtm), j, i, __ccgo_ts+23508)
		i = int32(1)
	}
	if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
		_explainAppendTerm(tls, pStr, pIndex, int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnTop), j, i, __ccgo_ts+23510)
	}
	Xsqlite3_str_append(tls, pStr, __ccgo_ts+6479, int32(1))
}

// C documentation
//
//	/*
//	** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
//	** command, or if stmt_scanstatus_v2() stats are enabled, or if SQLITE_DEBUG
//	** was defined at compile-time. If it is not a no-op, a single OP_Explain
//	** opcode is added to the output to describe the table scan strategy in pLevel.
//	**
//	** If an OP_Explain opcode is added to the VM, its address is returned.
//	** Otherwise, if no OP_Explain is coded, zero is returned.
//	*/
func _sqlite3WhereExplainOneScan(tls *libc.TLS, pParse uintptr, pTabList uintptr, pLevel uintptr, wctrlFlags Tu16) (r int32) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var cRangeOp int8
	var db, pIdx, pItem, pLoop, v, zFmt, zMsg, zRowid, v1, v2 uintptr
	var flags Tu32
	var isSearch, ret int32
	var _ /* str at bp+0 */ TStrAccum
	var _ /* zBuf at bp+24 */ [100]int8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = cRangeOp, db, flags, isSearch, pIdx, pItem, pLoop, ret, v, zFmt, zMsg, zRowid, v1, v2
	ret = 0
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	if int32((*TParse)(unsafe.Pointer(v1)).Fexplain) == int32(2) || libc.Bool(0 != 0) {
		pItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*72
		v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* VM being constructed */
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb   /* Initial space for EQP output string */
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		flags = (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags
		if flags&uint32(WHERE_MULTI_OR) != 0 || int32(int32(wctrlFlags))&int32(WHERE_OR_SUBCLAUSE) != 0 {
			return 0
		}
		isSearch = libc.BoolInt32(flags&uint32(libc.Int32FromInt32(WHERE_BTM_LIMIT)|libc.Int32FromInt32(WHERE_TOP_LIMIT)) != uint32(0) || flags&uint32(WHERE_VIRTUALTABLE) == uint32(0) && int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq) > 0 || int32(int32(wctrlFlags))&(libc.Int32FromInt32(WHERE_ORDERBY_MIN)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)) != 0)
		_sqlite3StrAccumInit(tls, bp, db, bp+24, int32(100), int32(SQLITE_MAX_LENGTH))
		(*(*TStrAccum)(unsafe.Pointer(bp))).FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
		if isSearch != 0 {
			v2 = __ccgo_ts + 23512
		} else {
			v2 = __ccgo_ts + 23519
		}
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23524, libc.VaList(bp+136, v2, pItem))
		if flags&uint32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_VIRTUALTABLE)) == uint32(0) {
			zFmt = uintptr(0)
			pIdx = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
			if !((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
				if isSearch != 0 {
					zFmt = __ccgo_ts + 12687
				}
			} else {
				if flags&uint32(WHERE_PARTIALIDX) != 0 {
					zFmt = __ccgo_ts + 23530
				} else {
					if flags&uint32(WHERE_AUTO_INDEX) != 0 {
						zFmt = __ccgo_ts + 23563
					} else {
						if flags&uint32(WHERE_IDX_ONLY) != 0 {
							zFmt = __ccgo_ts + 23588
						} else {
							zFmt = __ccgo_ts + 23606
						}
					}
				}
			}
			if zFmt != 0 {
				Xsqlite3_str_append(tls, bp, __ccgo_ts+23615, int32(7))
				Xsqlite3_str_appendf(tls, bp, zFmt, libc.VaList(bp+136, (*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 + 18096
				Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23623, libc.VaList(bp+136, zRowid))
				if flags&uint32(libc.Int32FromInt32(WHERE_COLUMN_EQ)|libc.Int32FromInt32(WHERE_COLUMN_IN)) != 0 {
					cRangeOp = int8('=')
				} else {
					if flags&uint32(WHERE_BOTH_LIMIT) == uint32(WHERE_BOTH_LIMIT) {
						Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23654, libc.VaList(bp+136, zRowid))
						cRangeOp = int8('<')
					} else {
						if flags&uint32(WHERE_BTM_LIMIT) != 0 {
							cRangeOp = int8('>')
						} else {
							cRangeOp = int8('<')
						}
					}
				}
				Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23664, libc.VaList(bp+136, int32(int32(cRangeOp))))
			} else {
				if flags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
					Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23669, libc.VaList(bp+136, (*(*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 int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23696, 0)
		}
		zMsg = _sqlite3StrAccumFinish(tls, bp)
		ret = _sqlite3VdbeAddOp4(tls, v, int32(OP_Explain), _sqlite3VdbeCurrentAddr(tls, v), (*TParse)(unsafe.Pointer(pParse)).FaddrExplain, 0, zMsg, -int32(6))
	}
	return ret
}

// C documentation
//
//	/*
//	** Add a single OP_Explain opcode that describes a Bloom filter.
//	**
//	** Or if not processing EXPLAIN QUERY PLAN and not in a SQLITE_DEBUG and/or
//	** SQLITE_ENABLE_STMT_SCANSTATUS build, then OP_Explain opcodes are not
//	** required and this routine is a no-op.
//	**
//	** If an OP_Explain opcode is added to the VM, its address is returned.
//	** Otherwise, if no OP_Explain is coded, zero is returned.
//	*/
func _sqlite3WhereExplainBloomFilter(tls *libc.TLS, pParse uintptr, pWInfo uintptr, pLevel uintptr) (r int32) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var db, pItem, pLoop, pTab, v, z, zMsg uintptr
	var i, ret int32
	var _ /* str at bp+0 */ TStrAccum
	var _ /* zBuf at bp+24 */ [100]int8
	_, _, _, _, _, _, _, _, _ = db, i, pItem, pLoop, pTab, ret, v, z, zMsg
	ret = 0
	pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*72
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* VM being constructed */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb   /* Initial space for EQP output string */
	_sqlite3StrAccumInit(tls, bp, db, bp+24, int32(100), int32(SQLITE_MAX_LENGTH))
	(*(*TStrAccum)(unsafe.Pointer(bp))).FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
	Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23707, libc.VaList(bp+136, pItem))
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != 0 {
		pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
		if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23495, libc.VaList(bp+136, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*12))).FzCnName))
		} else {
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23728, 0)
		}
	} else {
		i = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip)
		for {
			if !(i < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq)) {
				break
			}
			z = _explainIndexColumnName(tls, (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex, i)
			if i > int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
				Xsqlite3_str_append(tls, bp, __ccgo_ts+23484, int32(5))
			}
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23495, libc.VaList(bp+136, z))
			goto _1
		_1:
			;
			i++
		}
	}
	Xsqlite3_str_append(tls, bp, __ccgo_ts+6479, int32(1))
	zMsg = _sqlite3StrAccumFinish(tls, bp)
	ret = _sqlite3VdbeAddOp4(tls, v, int32(OP_Explain), _sqlite3VdbeCurrentAddr(tls, v), (*TParse)(unsafe.Pointer(pParse)).FaddrExplain, 0, zMsg, -int32(6))
	return ret
}

// C documentation
//
//	/*
//	** Disable a term in the WHERE clause.  Except, do not disable the term
//	** if it controls a LEFT OUTER JOIN and it did not originate in the ON
//	** or USING clause of that join.
//	**
//	** Consider the term t2.z='ok' in the following queries:
//	**
//	**   (1)  SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.x WHERE t2.z='ok'
//	**   (2)  SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.x AND t2.z='ok'
//	**   (3)  SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok'
//	**
//	** The t2.z='ok' is disabled in the in (2) because it originates
//	** in the ON clause.  The term is disabled in (3) because it is not part
//	** of a LEFT OUTER JOIN.  In (1), the term is not disabled.
//	**
//	** Disabling a term causes that term to not be tested in the inner loop
//	** of the join.  Disabling is an optimization.  When terms are satisfied
//	** by indices, we disable them to prevent redundant tests in the inner
//	** loop.  We would get the correct results if nothing were ever disabled,
//	** but joins might run a little slower.  The trick is to disable as much
//	** as we can without disabling too much.  If we disabled in (1), we'd get
//	** the wrong answer.  See ticket #813.
//	**
//	** If all the children of a term are disabled, then that term is also
//	** automatically disabled.  In this way, terms get disabled if derived
//	** virtual terms are tested first.  For example:
//	**
//	**      x GLOB 'abc*' AND x>='abc' AND x<'acd'
//	**      \___________/     \______/     \_____/
//	**         parent          child1       child2
//	**
//	** Only the parent term was in the original WHERE clause.  The child1
//	** and child2 terms were added by the LIKE optimization.  If both of
//	** the virtual child terms are valid, then testing of the parent can be
//	** skipped.
//	**
//	** Usually the parent term is marked as TERM_CODED.  But if the parent
//	** term was originally TERM_LIKE, then the parent gets TERM_LIKECOND instead.
//	** The TERM_LIKECOND marking indicates that the term should be coded inside
//	** a conditional such that is only evaluated on the second pass of a
//	** LIKE-optimization loop, when scanning BLOBs instead of strings.
//	*/
func _disableTerm(tls *libc.TLS, pLevel uintptr, pTerm uintptr) {
	var nLoop int32
	var p1, p2 uintptr
	_, _, _ = nLoop, p1, p2
	nLoop = 0
	for int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_CODED) == 0 && ((*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin == 0 || (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0)) && (*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady&(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll == uint64(0) {
		if nLoop != 0 && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_LIKE) != 0 {
			p1 = pTerm + 10
			*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(TERM_LIKECOND))
		} else {
			p2 = pTerm + 10
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(TERM_CODED))
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FiParent < 0 {
			break
		}
		pTerm = (*TWhereClause)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpWC)).Fa + uintptr((*TWhereTerm)(unsafe.Pointer(pTerm)).FiParent)*48
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FnChild--
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FnChild) != 0 {
			break
		}
		nLoop++
	}
}

// C documentation
//
//	/*
//	** Code an OP_Affinity opcode to apply the column affinity string zAff
//	** to the n registers starting at base.
//	**
//	** As an optimization, SQLITE_AFF_BLOB and SQLITE_AFF_NONE entries (which
//	** are no-ops) at the beginning and end of zAff are ignored.  If all entries
//	** in zAff are SQLITE_AFF_BLOB or SQLITE_AFF_NONE, then no code gets generated.
//	**
//	** This routine makes its own copy of zAff so that the caller is free
//	** to modify zAff after this routine returns.
//	*/
func _codeApplyAffinity(tls *libc.TLS, pParse uintptr, base int32, n int32, zAff uintptr) {
	var v uintptr
	_ = v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if zAff == uintptr(0) {
		return
	}
	/* Adjust base and n to skip over SQLITE_AFF_BLOB and SQLITE_AFF_NONE
	 ** entries at the beginning and end of the affinity string.
	 */
	for n > 0 && int32(*(*int8)(unsafe.Pointer(zAff))) <= int32(SQLITE_AFF_BLOB) {
		n--
		base++
		zAff++
	}
	for n > int32(1) && int32(*(*int8)(unsafe.Pointer(zAff + uintptr(n-int32(1))))) <= int32(SQLITE_AFF_BLOB) {
		n--
	}
	/* Code the OP_Affinity opcode if there is anything left to do. */
	if n > 0 {
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), base, n, 0, zAff, n)
	}
}

// C documentation
//
//	/*
//	** Expression pRight, which is the RHS of a comparison operation, is
//	** either a vector of n elements or, if n==1, a scalar expression.
//	** Before the comparison operation, affinity zAff is to be applied
//	** to the pRight values. This function modifies characters within the
//	** affinity string to SQLITE_AFF_BLOB if either:
//	**
//	**   * the comparison will be performed with no affinity, or
//	**   * the affinity change in zAff is guaranteed not to change the value.
//	*/
func _updateRangeAffinityStr(tls *libc.TLS, pRight uintptr, n int32, zAff uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	i = 0
	for {
		if !(i < n) {
			break
		}
		p = _sqlite3VectorFieldSubexpr(tls, pRight, i)
		if int32(_sqlite3CompareAffinity(tls, p, *(*int8)(unsafe.Pointer(zAff + uintptr(i))))) == int32(SQLITE_AFF_BLOB) || _sqlite3ExprNeedsNoAffinityChange(tls, p, *(*int8)(unsafe.Pointer(zAff + uintptr(i)))) != 0 {
			*(*int8)(unsafe.Pointer(zAff + uintptr(i))) = int8(SQLITE_AFF_BLOB)
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** pX is an expression of the form:  (vector) IN (SELECT ...)
//	** In other words, it is a vector IN operator with a SELECT clause on the
//	** LHS.  But not all terms in the vector are indexable and the terms might
//	** not be in the correct order for indexing.
//	**
//	** This routine makes a copy of the input pX expression and then adjusts
//	** the vector on the LHS with corresponding changes to the SELECT so that
//	** the vector contains only index terms and those terms are in the correct
//	** order.  The modified IN expression is returned.  The caller is responsible
//	** for deleting the returned expression.
//	**
//	** Example:
//	**
//	**    CREATE TABLE t1(a,b,c,d,e,f);
//	**    CREATE INDEX t1x1 ON t1(e,c);
//	**    SELECT * FROM t1 WHERE (a,b,c,d,e) IN (SELECT v,w,x,y,z FROM t2)
//	**                           \_______________________________________/
//	**                                     The pX expression
//	**
//	** Since only columns e and c can be used with the index, in that order,
//	** the modified IN expression that is returned will be:
//	**
//	**        (e,c) IN (SELECT z,x FROM t2)
//	**
//	** The reduced pX is different from the original (obviously) and thus is
//	** only used for indexing, to improve performance.  The original unaltered
//	** IN expression must also be run on each output row for correctness.
//	*/
func _removeUnindexableInClauseTerms(tls *libc.TLS, pParse uintptr, iEq int32, pLoop uintptr, pX uintptr) (r uintptr) {
	var db, p, pLhs, pNew, pOrderBy, pOrigLhs, pOrigRhs, pRhs, pSelect uintptr
	var i, iField int32
	_, _, _, _, _, _, _, _, _, _, _ = db, i, iField, p, pLhs, pNew, pOrderBy, pOrigLhs, pOrigRhs, pRhs, pSelect
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = _sqlite3ExprDup(tls, db, pX, 0)
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		pSelect = *(*uintptr)(unsafe.Pointer(pNew + 20))
		for {
			if !(pSelect != 0) {
				break
			} /* Original unmodified RHS */
			pOrigLhs = uintptr(0) /* Original unmodified LHS */
			pRhs = uintptr(0)     /* New RHS after modifications */
			pLhs = uintptr(0)     /* Loop counter */
			pOrigRhs = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
			if pSelect == *(*uintptr)(unsafe.Pointer(pNew + 20)) {
				pOrigLhs = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pNew)).FpLeft + 20))
			}
			i = iEq
			for {
				if !(i < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm)) {
					break
				}
				if (*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*4)))).FpExpr == pX {
					iField = (*(*struct {
						FleftColumn int32
						FiField     int32
					})(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*4)) + 24))).FiField - int32(1)
					if (*(*TExprList_item)(unsafe.Pointer(pOrigRhs + 8 + uintptr(iField)*20))).FpExpr == uintptr(0) {
						goto _2
					} /* Duplicate PK column */
					pRhs = _sqlite3ExprListAppend(tls, pParse, pRhs, (*(*TExprList_item)(unsafe.Pointer(pOrigRhs + 8 + uintptr(iField)*20))).FpExpr)
					(*(*TExprList_item)(unsafe.Pointer(pOrigRhs + 8 + uintptr(iField)*20))).FpExpr = uintptr(0)
					if pOrigLhs != 0 {
						pLhs = _sqlite3ExprListAppend(tls, pParse, pLhs, (*(*TExprList_item)(unsafe.Pointer(pOrigLhs + 8 + uintptr(iField)*20))).FpExpr)
						(*(*TExprList_item)(unsafe.Pointer(pOrigLhs + 8 + uintptr(iField)*20))).FpExpr = uintptr(0)
					}
				}
				goto _2
			_2:
				;
				i++
			}
			_sqlite3ExprListDelete(tls, db, pOrigRhs)
			if pOrigLhs != 0 {
				_sqlite3ExprListDelete(tls, db, pOrigLhs)
				*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pNew)).FpLeft + 20)) = pLhs
			}
			(*TSelect)(unsafe.Pointer(pSelect)).FpEList = pRhs
			if pLhs != 0 && (*TExprList)(unsafe.Pointer(pLhs)).FnExpr == int32(1) {
				/* Take care here not to generate a TK_VECTOR containing only a
				 ** single value. Since the parser never creates such a vector, some
				 ** of the subroutines do not handle this case.  */
				p = (*(*TExprList_item)(unsafe.Pointer(pLhs + 8))).FpExpr
				(*(*TExprList_item)(unsafe.Pointer(pLhs + 8))).FpExpr = uintptr(0)
				_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pNew)).FpLeft)
				(*TExpr)(unsafe.Pointer(pNew)).FpLeft = p
			}
			if (*TSelect)(unsafe.Pointer(pSelect)).FpOrderBy != 0 {
				/* If the SELECT statement has an ORDER BY clause, zero the
				 ** iOrderByCol variables. These are set to non-zero when an
				 ** ORDER BY term exactly matches one of the terms of the
				 ** result-set. Since the result-set of the SELECT statement may
				 ** have been modified or reordered, these variables are no longer
				 ** set correctly.  Since setting them is just an optimization,
				 ** it's easiest just to zero them here.  */
				pOrderBy = (*TSelect)(unsafe.Pointer(pSelect)).FpOrderBy
				i = 0
				for {
					if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
						break
					}
					*(*Tu16)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20 + 16)) = uint16(0)
					goto _3
				_3:
					;
					i++
				}
			}
			goto _1
		_1:
			;
			pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
		}
	}
	return pNew
}

// C documentation
//
//	/*
//	** Generate code for a single equality term of the WHERE clause.  An equality
//	** term can be either X=expr or X IN (...).   pTerm is the term to be
//	** coded.
//	**
//	** The current value for the constraint is left in a register, the index
//	** of which is returned.  An attempt is made store the result in iTarget but
//	** this is only guaranteed for TK_ISNULL and TK_IN constraints.  If the
//	** constraint is a TK_EQ or TK_IS, then the current value might be left in
//	** some other register and it is the caller's responsibility to compensate.
//	**
//	** For a constraint of the form X=expr, the expression is evaluated in
//	** straight-line code.  For constraints of the form X IN (...)
//	** this routine sets up a loop that will iterate over all values of X.
//	*/
func _codeEqualityTerm(tls *libc.TLS, pParse uintptr, pTerm uintptr, pLevel uintptr, iEq int32, bRev int32, iTarget int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aiMap, db, pExpr, pIn, pLoop, pX, v uintptr
	var eType, i, iCol, iMap, iOut, iReg, n, nEq, v3, v4, v6, v7, v8 int32
	var _ /* iTab at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aiMap, db, eType, i, iCol, iMap, iOut, iReg, n, nEq, pExpr, pIn, pLoop, pX, v, v3, v4, v6, v7, v8
	pX = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* Register holding results */
	if int32((*TExpr)(unsafe.Pointer(pX)).Fop) == int32(TK_EQ) || int32((*TExpr)(unsafe.Pointer(pX)).Fop) == int32(TK_IS) {
		iReg = _sqlite3ExprCodeTarget(tls, pParse, (*TExpr)(unsafe.Pointer(pX)).FpRight, iTarget)
	} else {
		if int32((*TExpr)(unsafe.Pointer(pX)).Fop) == int32(TK_ISNULL) {
			iReg = iTarget
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, iReg)
		} else {
			eType = int32(IN_INDEX_NOOP)
			pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
			nEq = 0
			aiMap = uintptr(0)
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex != uintptr(0) && *(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex)).FaSortOrder + uintptr(iEq))) != 0 {
				bRev = libc.BoolInt32(!(bRev != 0))
			}
			iReg = iTarget
			i = 0
			for {
				if !(i < iEq) {
					break
				}
				if *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*4)) != 0 && (*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*4)))).FpExpr == pX {
					_disableTerm(tls, pLevel, pTerm)
					return iTarget
				}
				goto _1
			_1:
				;
				i++
			}
			i = iEq
			for {
				if !(i < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm)) {
					break
				}
				if (*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*4)))).FpExpr == pX {
					nEq++
				}
				goto _2
			_2:
				;
				i++
			}
			*(*int32)(unsafe.Pointer(bp)) = 0
			if !((*TExpr)(unsafe.Pointer(pX)).Fflags&libc.Uint32FromInt32(EP_xIsSelect) != libc.Uint32FromInt32(0)) || (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 20)))).FpEList)).FnExpr == int32(1) {
				eType = _sqlite3FindInIndex(tls, pParse, pX, uint32(IN_INDEX_LOOP), uintptr(0), uintptr(0), bp)
			} else {
				pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
				if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == 0 || !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Subrtn)) != libc.Uint32FromInt32(0)) {
					db = (*TParse)(unsafe.Pointer(pParse)).Fdb
					pX = _removeUnindexableInClauseTerms(tls, pParse, iEq, pLoop, pX)
					if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
						aiMap = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint32(4)*uint32(uint32(nEq))))
						eType = _sqlite3FindInIndex(tls, pParse, pX, uint32(IN_INDEX_LOOP), uintptr(0), aiMap, bp)
						(*TExpr)(unsafe.Pointer(pExpr)).FiTable = *(*int32)(unsafe.Pointer(bp))
					}
					_sqlite3ExprDelete(tls, db, pX)
				} else {
					n = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft)
					if nEq > n {
						v3 = nEq
					} else {
						v3 = n
					}
					aiMap = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint32(4)*uint32(v3)))
					eType = _sqlite3FindInIndex(tls, pParse, pX, uint32(IN_INDEX_LOOP), uintptr(0), aiMap, bp)
				}
				pX = pExpr
			}
			if eType == int32(IN_INDEX_INDEX_DESC) {
				bRev = libc.BoolInt32(!(bRev != 0))
			}
			if bRev != 0 {
				v4 = int32(OP_Last)
			} else {
				v4 = int32(OP_Rewind)
			}
			_sqlite3VdbeAddOp2(tls, v, v4, *(*int32)(unsafe.Pointer(bp)), 0)
			*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= uint32(WHERE_IN_ABLE)
			if (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FnIn == 0 {
				(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt = _sqlite3VdbeMakeLabel(tls, pParse)
			}
			if iEq > 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_SEEKSCAN) == uint32(0) {
				*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= uint32(WHERE_IN_EARLYOUT)
			}
			i = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FnIn
			(*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FnIn += nEq
			(*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FaInLoop = _sqlite3WhereRealloc(tls, (*TWhereClause)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpWC)).FpWInfo, (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FaInLoop, uint64(uint32(20)*uint32((*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FnIn)))
			pIn = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FaInLoop
			if pIn != 0 {
				iMap = 0 /* Index in aiMap[] */
				pIn += uintptr(i) * 20
				i = iEq
				for {
					if !(i < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm)) {
						break
					}
					if (*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*4)))).FpExpr == pX {
						iOut = iReg + i - iEq
						if eType == int32(IN_INDEX_ROWID) {
							(*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), *(*int32)(unsafe.Pointer(bp)), iOut)
						} else {
							if aiMap != 0 {
								v7 = iMap
								iMap++
								v6 = *(*int32)(unsafe.Pointer(aiMap + uintptr(v7)*4))
							} else {
								v6 = 0
							}
							iCol = v6
							(*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop = _sqlite3VdbeAddOp3(tls, v, int32(OP_Column), *(*int32)(unsafe.Pointer(bp)), iCol, iOut)
						}
						_sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), iOut)
						if i == iEq {
							(*TInLoop)(unsafe.Pointer(pIn)).FiCur = *(*int32)(unsafe.Pointer(bp))
							if bRev != 0 {
								v8 = int32(OP_Prev)
							} else {
								v8 = int32(OP_Next)
							}
							(*TInLoop)(unsafe.Pointer(pIn)).FeEndLoopOp = uint8(v8)
							if iEq > 0 {
								(*TInLoop)(unsafe.Pointer(pIn)).FiBase = iReg - i
								(*TInLoop)(unsafe.Pointer(pIn)).FnPrefix = i
							} else {
								(*TInLoop)(unsafe.Pointer(pIn)).FnPrefix = 0
							}
						} else {
							(*TInLoop)(unsafe.Pointer(pIn)).FeEndLoopOp = uint8(OP_Noop)
						}
						pIn += 20
					}
					goto _5
				_5:
					;
					i++
				}
				if iEq > 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(libc.Int32FromInt32(WHERE_IN_SEEKSCAN)|libc.Int32FromInt32(WHERE_VIRTUALTABLE)) == uint32(0) {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekHit), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, 0, iEq)
				}
			} else {
				(*(*struct {
					FnIn     int32
					FaInLoop uintptr
				})(unsafe.Pointer(pLevel + 64))).FnIn = 0
			}
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, aiMap)
		}
	}
	/* As an optimization, try to disable the WHERE clause term that is
	 ** driving the index as it will always be true.  The correct answer is
	 ** obtained regardless, but we might get the answer with fewer CPU cycles
	 ** by omitting the term.
	 **
	 ** But do not disable the term unless we are certain that the term is
	 ** not a transitive constraint.  For an example of where that does not
	 ** work, see https://sqlite.org/forum/forumpost/eb8613976a (2021-05-04)
	 */
	if (*TWhereLoop1)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FwsFlags&uint32(WHERE_TRANSCONS) == uint32(0) || int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_EQUIV) == 0 {
		_disableTerm(tls, pLevel, pTerm)
	}
	return iReg
}

// C documentation
//
//	/*
//	** Generate code that will evaluate all == and IN constraints for an
//	** index scan.
//	**
//	** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
//	** Suppose the WHERE clause is this:  a==5 AND b IN (1,2,3) AND c>5 AND c<10
//	** The index has as many as three equality constraints, but in this
//	** example, the third "c" value is an inequality.  So only two
//	** constraints are coded.  This routine will generate code to evaluate
//	** a==5 and b IN (1,2,3).  The current values for a and b will be stored
//	** in consecutive registers and the index of the first register is returned.
//	**
//	** In the example above nEq==2.  But this subroutine works for any value
//	** of nEq including 0.  If nEq==0, this routine is nearly a no-op.
//	** The only thing it does is allocate the pLevel->iMem memory cell and
//	** compute the affinity string.
//	**
//	** The nExtraReg parameter is 0 or 1.  It is 0 if all WHERE clause constraints
//	** are == or IN and are covered by the nEq.  nExtraReg is 1 if there is
//	** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
//	** occurs after the nEq quality constraints.
//	**
//	** This routine allocates a range of nEq+nExtraReg memory cells and returns
//	** the index of the first memory cell in that range. The code that
//	** calls this routine will use that memory range to store keys for
//	** start and termination conditions of the loop.
//	** key value of the loop.  If one or more IN operators appear, then
//	** this routine allocates an additional nEq memory cells for internal
//	** use.
//	**
//	** Before returning, *pzAff is set to point to a buffer containing a
//	** copy of the column affinity string of the index allocated using
//	** sqlite3DbMalloc(). Except, entries in the copy of the string associated
//	** with equality constraints that use BLOB or NONE affinity are set to
//	** SQLITE_AFF_BLOB. This is to deal with SQL such as the following:
//	**
//	**   CREATE TABLE t1(a TEXT PRIMARY KEY, b);
//	**   SELECT ... FROM t1 AS t2, t1 WHERE t1.a = t2.b;
//	**
//	** In the example above, the index on t1(a) has TEXT affinity. But since
//	** the right hand side of the equality constraint (t2.b) has BLOB/NONE affinity,
//	** no conversion should be attempted before using a t2.b value as part of
//	** a key to search the index. Hence the first byte in the returned affinity
//	** string in this example would be set to SQLITE_AFF_BLOB.
//	*/
func _codeAllEqualityTerms(tls *libc.TLS, pParse uintptr, pLevel uintptr, bRev int32, nExtraReg int32, pzAff uintptr) (r int32) {
	var iIdxCur, j, nReg, r1, regBase, v1, v2 int32
	var nEq, nSkip Tu16
	var pIdx, pLoop, pRight, pTerm, v, zAff uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = iIdxCur, j, nEq, nReg, nSkip, pIdx, pLoop, pRight, pTerm, r1, regBase, v, zAff, v1, v2 /* Number of left-most columns to skip */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                                                                                         /* Affinity string to return */
	/* This module is only called on query plans that use an index. */
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	nEq = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq
	nSkip = (*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip
	pIdx = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
	/* Figure out how many memory cells we will need then allocate them.
	 */
	regBase = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	nReg = int32(int32(nEq)) + nExtraReg
	*(*int32)(unsafe.Pointer(pParse + 44)) += nReg
	zAff = _sqlite3DbStrDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, _sqlite3IndexAffinityStr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pIdx))
	if nSkip != 0 {
		iIdxCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, regBase, regBase+int32(int32(nSkip))-int32(1))
		if bRev != 0 {
			v1 = int32(OP_Last)
		} else {
			v1 = int32(OP_Rewind)
		}
		_sqlite3VdbeAddOp1(tls, v, v1, iIdxCur)
		j = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
		if bRev != 0 {
			v2 = int32(OP_SeekLT)
		} else {
			v2 = int32(OP_SeekGT)
		}
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip = _sqlite3VdbeAddOp4Int(tls, v, v2, iIdxCur, 0, regBase, int32(int32(nSkip)))
		_sqlite3VdbeJumpHere(tls, v, j)
		j = 0
		for {
			if !(j < int32(int32(nSkip))) {
				break
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, j, regBase+j)
			goto _3
		_3:
			;
			j++
		}
	}
	/* Evaluate the equality constraints
	 */
	j = int32(int32(nSkip))
	for {
		if !(j < int32(int32(nEq))) {
			break
		}
		pTerm = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4))
		/* The following testcase is true for indices with redundant columns.
		 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
		r1 = _codeEqualityTerm(tls, pParse, pTerm, pLevel, j, bRev, regBase+j)
		if r1 != regBase+j {
			if nReg == int32(1) {
				_sqlite3ReleaseTempReg(tls, pParse, regBase)
				regBase = r1
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), r1, regBase+j)
			}
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0 {
			if (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(EP_xIsSelect) != 0 {
				/* No affinity ever needs to be (or should be) applied to a value
				 ** from the RHS of an "? IN (SELECT ...)" expression. The
				 ** sqlite3FindInIndex() routine has already ensured that the
				 ** affinity of the comparison has been applied to the value.  */
				if zAff != 0 {
					*(*int8)(unsafe.Pointer(zAff + uintptr(j))) = int8(SQLITE_AFF_BLOB)
				}
			}
		} else {
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_ISNULL) == 0 {
				pRight = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
				if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_IS) == 0 && _sqlite3ExprCanBeNull(tls, pRight) != 0 {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regBase+j, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
				}
				if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
					if int32(_sqlite3CompareAffinity(tls, pRight, *(*int8)(unsafe.Pointer(zAff + uintptr(j))))) == int32(SQLITE_AFF_BLOB) {
						*(*int8)(unsafe.Pointer(zAff + uintptr(j))) = int8(SQLITE_AFF_BLOB)
					}
					if _sqlite3ExprNeedsNoAffinityChange(tls, pRight, *(*int8)(unsafe.Pointer(zAff + uintptr(j)))) != 0 {
						*(*int8)(unsafe.Pointer(zAff + uintptr(j))) = int8(SQLITE_AFF_BLOB)
					}
				}
			}
		}
		goto _4
	_4:
		;
		j++
	}
	*(*uintptr)(unsafe.Pointer(pzAff)) = zAff
	return regBase
}

// 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+48, libc.Uint32FromInt32(1), 0, 0x1)
	_sqlite3VdbeAddOp3(tls, v, int32(OP_DeferredSeek), iIdxCur, 0, iCur)
	if v2 = int32((*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(uint32(4)*uint32(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+libc.Int32FromInt32(1))))
		if ai != 0 {
			*(*Tu32)(unsafe.Pointer(ai)) = uint32((*TTable)(unsafe.Pointer(pTab)).FnCol)
			i = 0
			for {
				if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)-int32(1)) {
					break
				}
				x1 = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
				x2 = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(int16(x1))))
				if x1 >= 0 {
					*(*Tu32)(unsafe.Pointer(ai + uintptr(x2+int32(1))*4)) = uint32(i + int32(1))
				}
				goto _3
			_3:
				;
				i++
			}
			_sqlite3VdbeChangeP4(tls, v, -int32(1), ai, -int32(14))
		}
	}
}

// C documentation
//
//	/*
//	** If the expression passed as the second argument is a vector, generate
//	** code to write the first nReg elements of the vector into an array
//	** of registers starting with iReg.
//	**
//	** If the expression is not a vector, then nReg must be passed 1. In
//	** this case, generate code to evaluate the expression and leave the
//	** result in register iReg.
//	*/
func _codeExprOrVector(tls *libc.TLS, pParse uintptr, p uintptr, iReg int32, nReg int32) {
	var i, iSelect int32
	var pList, v uintptr
	_, _, _, _ = i, iSelect, pList, v
	if p != 0 && _sqlite3ExprIsVector(tls, p) != 0 {
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
			iSelect = _sqlite3CodeSubselect(tls, pParse, p)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), iSelect, iReg, nReg-int32(1))
		} else {
			pList = *(*uintptr)(unsafe.Pointer(p + 20))
			i = 0
			for {
				if !(i < nReg) {
					break
				}
				_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr, iReg+i)
				goto _1
			_1:
				;
				i++
			}
		}
	} else {
		_sqlite3ExprCode(tls, pParse, p, iReg)
	}
}

// C documentation
//
//	/*
//	** The pTruth expression is always true because it is the WHERE clause
//	** a partial index that is driving a query loop.  Look through all of the
//	** WHERE clause terms on the query, and if any of those terms must be
//	** true because pTruth is true, then mark those WHERE clause terms as
//	** coded.
//	*/
func _whereApplyPartialIndexConstraints(tls *libc.TLS, pTruth uintptr, iTabCur int32, pWC uintptr) {
	var i int32
	var pExpr, pTerm, p2 uintptr
	_, _, _, _ = i, pExpr, pTerm, p2
	for int32((*TExpr)(unsafe.Pointer(pTruth)).Fop) == int32(TK_AND) {
		_whereApplyPartialIndexConstraints(tls, (*TExpr)(unsafe.Pointer(pTruth)).FpLeft, iTabCur, pWC)
		pTruth = (*TExpr)(unsafe.Pointer(pTruth)).FpRight
	}
	i = 0
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(i < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
			break
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_CODED) != 0 {
			goto _1
		}
		pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		if _sqlite3ExprCompare(tls, uintptr(0), pExpr, pTruth, iTabCur) == 0 {
			p2 = pTerm + 10
			*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(TERM_CODED))
		}
		goto _1
	_1:
		;
		i++
		pTerm += 48
	}
}

// C documentation
//
//	/*
//	** This routine is called right after An OP_Filter has been generated and
//	** before the corresponding index search has been performed.  This routine
//	** checks to see if there are additional Bloom filters in inner loops that
//	** can be checked prior to doing the index lookup.  If there are available
//	** inner-loop Bloom filters, then evaluate those filters now, before the
//	** index lookup.  The idea is that a Bloom filter check is way faster than
//	** an index lookup, and the Bloom filter might return false, meaning that
//	** the index lookup can be skipped.
//	**
//	** We know that an inner loop uses a Bloom filter because it has the
//	** WhereLevel.regFilter set.  If an inner-loop Bloom filter is checked,
//	** then clear the WhereLevel.regFilter value to prevent the Bloom filter
//	** from being checked a second time when the inner loop is evaluated.
//	*/
func _filterPullDown(tls *libc.TLS, pParse uintptr, pWInfo uintptr, iLevel int32, addrNxt int32, notReady TBitmask) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nEq Tu16
	var pLevel, pLoop, pTerm uintptr
	var r1, regRowid, v1 int32
	var _ /* zStartAff at bp+0 */ uintptr
	_, _, _, _, _, _, _ = nEq, pLevel, pLoop, pTerm, r1, regRowid, v1
	for {
		iLevel++
		v1 = iLevel
		if !(v1 < int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
			break
		}
		pLevel = pWInfo + 760 + uintptr(iLevel)*88
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter == 0 {
			continue
		}
		if (*TWhereLoop1)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FnSkip != 0 {
			continue
		}
		/*         ,--- Because sqlite3ConstructBloomFilter() has will not have set
		 **  vvvvv--'    pLevel->regFilter if this were true. */
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).Fprereq&notReady != 0 {
			continue
		}
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk = addrNxt
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != 0 {
			pTerm = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
			regRowid = _sqlite3GetTempReg(tls, pParse)
			regRowid = _codeEqualityTerm(tls, pParse, pTerm, pLevel, 0, 0, regRowid)
			_sqlite3VdbeAddOp2(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_MustBeInt), regRowid, addrNxt)
			_sqlite3VdbeAddOp4Int(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Filter), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt, regRowid, int32(1))
		} else {
			nEq = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq
			r1 = _codeAllEqualityTerms(tls, pParse, pLevel, 0, 0, bp)
			_codeApplyAffinity(tls, pParse, r1, int32(int32(nEq)), *(*uintptr)(unsafe.Pointer(bp)))
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(bp)))
			_sqlite3VdbeAddOp4Int(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Filter), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt, r1, int32(int32(nEq)))
		}
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter = 0
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk = 0
	}
}

// C documentation
//
//	/*
//	** Loop pLoop is a WHERE_INDEXED level that uses at least one IN(...)
//	** operator. Return true if level pLoop is guaranteed to visit only one
//	** row for each key generated for the index.
//	*/
func _whereLoopIsOneRow(tls *libc.TLS, pLoop uintptr) (r int32) {
	var ii int32
	_ = ii
	if (*TIndex)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex)).FonError != 0 && int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) == 0 && int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq) == int32((*TIndex)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex)).FnKeyCol) {
		ii = 0
		for {
			if !(ii < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq)) {
				break
			}
			if int32((*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(ii)*4)))).FeOperator)&(libc.Int32FromInt32(WO_IS)|libc.Int32FromInt32(WO_ISNULL)) != 0 {
				return 0
			}
			goto _1
		_1:
			;
			ii++
		}
		return int32(1)
	}
	return 0
}

// 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(80)
	defer tls.Free(80)
	var aMoveOp [4]Tu8
	var addrBrk, addrCont, addrExplain, addrHalt, 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, v11, v13, v14, v2, v20, v23, v24, v25, v26, v27, v29, v3, v30, v31, v32, v34, v35, v36, v37, v38, v39, v4, v41, v43, v44, v46, v49, v51, v53, v58, v60, v9 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, pTab, pTab1, pTabItem, pTerm, pWC, pX, pX1, t, zEndAff, v10, v12, v19, v21, v22, v28, v33, v40, v45, v47, v5, v50, v52, v54, v57, p62, p64, p68 uintptr
	var m TBitmask
	var nBtm, nEq, nTop Tu16
	var v16, v8 uint32
	var v17 bool
	var _ /* rTemp at bp+0 */ int32
	var _ /* sEAlt at bp+8 */ TExpr
	var _ /* zStartAff at bp+4 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aMoveOp, addrBrk, addrCont, addrExplain, addrHalt, 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, 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, v10, v11, v12, v13, v14, v16, v17, v19, v2, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v3, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v4, v40, v41, v43, v44, v45, v46, v47, v49, v5, v50, v51, v52, v53, v54, v57, v58, v60, v8, v9, p62, p64, p68 /* 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 + 80
	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)*72
	iCur = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady = notReady & ^_sqlite3WhereGetMask(tls, pWInfo+496, iCur)
	bRev = int32((*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".
	 */
	v2 = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt = v2
	v1 = v2
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk = v1
	addrBrk = v1
	v3 = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont = v3
	addrCont = v3
	/* 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 int32((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom) > 0 && int32((*(*TSrcItem)(unsafe.Pointer(pTabItem))).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
		v5 = pParse + 44
		*(*int32)(unsafe.Pointer(v5))++
		v4 = *(*int32)(unsafe.Pointer(v5))
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin = v4
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
	}
	/* Compute a safe address to jump to if we discover that the table for
	 ** this loop is empty and can never contribute content. */
	j = iLevel
	for {
		if !(j > 0) {
			break
		}
		if (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(j)*88))).FiLeftJoin != 0 {
			break
		}
		if (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(j)*88))).FpRJ != 0 {
			break
		}
		goto _6
	_6:
		;
		j--
	}
	addrHalt = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(j)*88))).FaddrBrk
	/* Special case of a FROM clause subquery implemented as a co-routine */
	if int32(uint32(*(*uint16)(unsafe.Pointer(pTabItem + 36 + 4))&0x20>>5)) != 0 {
		regYield = (*TSrcItem)(unsafe.Pointer(pTabItem)).FregReturn
		_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, (*TSrcItem)(unsafe.Pointer(pTabItem)).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 = int32((*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)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4))
				if pTerm == uintptr(0) {
					goto _7
				}
				if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0 {
					if j <= int32(31) {
						v8 = libc.Uint32FromInt32(1) << j
					} else {
						v8 = uint32(0)
					}
					if v8&(*(*struct {
						FidxNum    int32
						F__ccgo4   uint8
						FisOrdered Ti8
						FomitMask  Tu16
						FidxStr    uintptr
						FmHandleIn Tu32
					})(unsafe.Pointer(pLoop + 24))).FmHandleIn != 0 {
						v10 = pParse + 40
						v9 = *(*int32)(unsafe.Pointer(v10))
						*(*int32)(unsafe.Pointer(v10))++
						iTab = v9
						v12 = pParse + 44
						*(*int32)(unsafe.Pointer(v12))++
						v11 = *(*int32)(unsafe.Pointer(v12))
						iCache = v11
						_sqlite3CodeRhsOfIN(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, iTab)
						_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 int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) == int32(SQLITE_INDEX_CONSTRAINT_OFFSET) && int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x2>>1)) != 0 {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TSelect)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FiOffset)
					}
				}
				goto _7
			_7:
				;
				j++
			}
			_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))
			if int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x1>>0)) != 0 {
				v13 = -int32(6)
			} else {
				v13 = -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, v13)
			libc.SetBitFieldPtr8Uint32(pLoop+24+4, libc.Uint32FromInt32(0), 0, 0x1)
			/* 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 {
				v14 = int32(OP_Noop)
			} else {
				v14 = int32(OP_VNext)
			}
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(v14)
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeCurrentAddr(tls, v)
			j = 0
			for {
				if !(j < nConstraint) {
					break
				}
				pTerm = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4))
				if j < int32(16) && int32((*(*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 _15
				}
				if v17 = int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0; v17 {
					if j <= int32(31) {
						v16 = libc.Uint32FromInt32(1) << j
					} else {
						v16 = uint32(0)
					}
				}
				if v17 && v16&(*(*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 + 64))).FnIn) {
							break
						}
						pOp = _sqlite3VdbeGetOp(tls, v, (*(*TInLoop)(unsafe.Pointer((*(*struct {
							FnIn     int32
							FaInLoop uintptr
						})(unsafe.Pointer(pLevel + 64))).FaInLoop + uintptr(iIn)*20))).FaddrInTop)
						if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 == iReg+j+int32(2) || int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Rowid) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 == iReg+j+int32(2) {
							_sqlite3VdbeAddOp3(tls, v, int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode), (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1, (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2, (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3)
							break
						}
						goto _18
					_18:
						;
						iIn++
					}
					/* 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 + 24))).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 + 20)) + 8 + uintptr(iFld-int32(1))*20))).FpExpr
						} else {
							(*TExpr)(unsafe.Pointer(pCompare)).FpLeft = pLeft
						}
						v19 = _sqlite3Expr(tls, db, int32(TK_REGISTER), uintptr(0))
						pRight1 = v19
						(*TExpr)(unsafe.Pointer(pCompare)).FpRight = v19
						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 _15
			_15:
				;
				j++
			}
			/* 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&uint32(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)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
				v21 = pParse + 44
				*(*int32)(unsafe.Pointer(v21))++
				v20 = *(*int32)(unsafe.Pointer(v21))
				iReleaseReg = v20
				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
					v22 = libc.UintptrFromInt32(0)
					pEnd = v22
					pStart = v22
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
						v23 = j
						j++
						pStart = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v23)*4))
					}
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
						v24 = j
						j++
						pEnd = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v24)*4))
					}
					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 {
							v25 = _sqlite3GetTempReg(tls, pParse)
							*(*int32)(unsafe.Pointer(bp)) = v25
							r11 = v25
							_codeExprOrVector(tls, pParse, (*TExpr)(unsafe.Pointer(pX)).FpRight, r11, int32(1))
							op = int32(aMoveOp[(int32((*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 = int32(aMoveOp[int32((*TExpr)(unsafe.Pointer(pX)).Fop)-int32(TK_GT)])
						}
						_sqlite3VdbeAddOp3(tls, v, op, iCur, addrBrk, r11)
						_sqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
					} else {
						if bRev != 0 {
							v26 = int32(OP_Last)
						} else {
							v26 = int32(OP_Rewind)
						}
						_sqlite3VdbeAddOp2(tls, v, v26, iCur, addrHalt)
					}
					if pEnd != 0 {
						pX1 = (*TWhereTerm)(unsafe.Pointer(pEnd)).FpExpr
						/* Transitive constraints */
						v28 = pParse + 44
						*(*int32)(unsafe.Pointer(v28))++
						v27 = *(*int32)(unsafe.Pointer(v28))
						memEndValue = v27
						_codeExprOrVector(tls, pParse, (*TExpr)(unsafe.Pointer(pX1)).FpRight, memEndValue, int32(1))
						if 0 == _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX1)).FpRight) && (int32((*TExpr)(unsafe.Pointer(pX1)).Fop) == int32(TK_LT) || int32((*TExpr)(unsafe.Pointer(pX1)).Fop) == int32(TK_GT)) {
							if bRev != 0 {
								v29 = int32(OP_Le)
							} else {
								v29 = int32(OP_Ge)
							}
							testOp = v29
						} else {
							if bRev != 0 {
								v30 = int32(OP_Lt)
							} else {
								v30 = int32(OP_Gt)
							}
							testOp = v30
						}
						if 0 == _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX1)).FpRight) {
							_disableTerm(tls, pLevel, pEnd)
						}
					}
					start = _sqlite3VdbeCurrentAddr(tls, v)
					if bRev != 0 {
						v31 = int32(OP_Prev)
					} else {
						v31 = int32(OP_Next)
					}
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(v31)
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = start
					if testOp != int32(OP_Noop) {
						v33 = pParse + 44
						*(*int32)(unsafe.Pointer(v33))++
						v32 = *(*int32)(unsafe.Pointer(v33))
						iRowidReg = v32
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCur, iRowidReg)
						_sqlite3VdbeAddOp3(tls, v, testOp, memEndValue, addrBrk, iRowidReg)
						_sqlite3VdbeChangeP5(tls, v, uint16(libc.Int32FromInt32(SQLITE_AFF_NUMERIC)|libc.Int32FromInt32(SQLITE_JUMPIFNULL)))
					}
				} else {
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != 0 {
						nEq = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq   /* Number of == or IN terms */
						nBtm = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnBtm /* Length of BTM vector */
						nTop = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.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 = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
						iIdxCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
						/* Find any inequality constraint terms for the start and end
						 ** of the range.
						 */
						j = int32(int32(nEq))
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
							v34 = j
							j++
							pRangeStart = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v34)*4))
							if nExtraReg > int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnBtm) {
								v35 = nExtraReg
							} else {
								v35 = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnBtm)
							}
							nExtraReg = v35
							/* Like optimization range constraints always occur in pairs */
						}
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
							v36 = j
							j++
							pRangeEnd = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v36)*4))
							if nExtraReg > int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnTop) {
								v37 = nExtraReg
							} else {
								v37 = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnTop)
							}
							nExtraReg = v37
							if pRangeStart == uintptr(0) {
								j = int32(*(*Ti16)(unsafe.Pointer((*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)*12 + 4))&0xf>>0)) == 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&uint32(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)
							v40 = pParse + 44
							*(*int32)(unsafe.Pointer(v40))++
							v39 = *(*int32)(unsafe.Pointer(v40))
							v38 = v39
							regBignull = v38
							(*TWhereLevel)(unsafe.Pointer(pLevel)).FregBignull = v38
							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 int32(int32(nEq)) < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) && bRev == libc.BoolInt32(int32(*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(nEq)))) == SQLITE_SO_ASC) {
							t = pRangeEnd
							pRangeEnd = pRangeStart
							pRangeStart = t
							t1 = bSeekPastNull
							bSeekPastNull = bStopAtNull
							bStopAtNull = t1
							t2 = uint8(uint8(nBtm))
							nBtm = nTop
							nTop = uint16(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+4)
						if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 && nTop != 0 {
							zEndAff = _sqlite3DbStrDup(tls, db, *(*uintptr)(unsafe.Pointer(bp + 4))+uintptr(nEq))
						}
						if regBignull != 0 {
							v41 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull
						} else {
							v41 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
						}
						addrNxt = v41
						startEq = libc.BoolInt32(!(pRangeStart != 0) || int32((*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) || int32((*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 || int32(int32(nEq)) > 0)
						/* Seek the index cursor to the start of the range. */
						nConstraint1 = int32(int32(nEq))
						if pRangeStart != 0 {
							pRight2 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FpExpr)).FpRight
							_codeExprOrVector(tls, pParse, pRight2, regBase+int32(int32(nEq)), int32(int32(nBtm)))
							if int32((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FwtFlags)&int32(TERM_VNULL) == 0 && _sqlite3ExprCanBeNull(tls, pRight2) != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regBase+int32(int32(nEq)), addrNxt)
							}
							if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
								_updateRangeAffinityStr(tls, pRight2, int32(int32(nBtm)), *(*uintptr)(unsafe.Pointer(bp + 4))+uintptr(nEq))
							}
							nConstraint1 += int32(int32(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+int32(int32(nEq)))
								start_constraints = int32(1)
								nConstraint1++
							} else {
								if regBignull != 0 {
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regBase+int32(int32(nEq)))
									start_constraints = int32(1)
									nConstraint1++
								}
							}
						}
						_codeApplyAffinity(tls, pParse, regBase, nConstraint1-int32(int32(bSeekPastNull)), *(*uintptr)(unsafe.Pointer(bp + 4)))
						if int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) > 0 && nConstraint1 == int32((*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, int32(int32(nEq)))
								_filterPullDown(tls, pParse, pWInfo, iLevel, addrNxt, notReady)
							}
							op1 = int32(_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)(unsafe.Pointer((*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 = int32(_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 = int32(int32(nEq))
						if pRangeEnd != 0 {
							pRight3 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FpExpr)).FpRight
							_codeExprOrVector(tls, pParse, pRight3, regBase+int32(int32(nEq)), int32(int32(nTop)))
							if int32((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FwtFlags)&int32(TERM_VNULL) == 0 && _sqlite3ExprCanBeNull(tls, pRight3) != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regBase+int32(int32(nEq)), addrNxt)
							}
							if zEndAff != 0 {
								_updateRangeAffinityStr(tls, pRight3, int32(int32(nTop)), zEndAff)
								_codeApplyAffinity(tls, pParse, regBase+int32(int32(nEq)), int32(int32(nTop)), zEndAff)
							} else {
							}
							nConstraint1 += int32(int32(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+int32(int32(nEq)))
									endEq = 0
								}
								nConstraint1++
							}
						}
						if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
							_sqlite3DbNNFreeNN(tls, db, *(*uintptr)(unsafe.Pointer(bp + 4)))
						}
						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 = int32(_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 = int32(_aEndOp[bRev*int32(2)+int32(int32(bSeekPastNull))])
							_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1+int32(int32(bSeekPastNull)))
						}
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_EARLYOUT) != uint32(0) {
							_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekHit), iIdxCur, int32(int32(nEq)), int32(int32(nEq)))
						}
						/* Seek the table cursor, if required */
						omitTable = libc.BoolInt32((*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) != uint32(0) && int32((*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, int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
									j = 0
									for {
										if !(j < int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
											break
										}
										k = int32(_sqlite3TableColumnToIndex(tls, pIdx, *(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
										_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, k, iRowidReg+j)
										goto _42
									_42:
										;
										j++
									}
									_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iCur, addrCont, iRowidReg, int32((*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.
							 **
							 ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work
							 ** for a LEFT JOIN.
							 */
							if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 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 + 64))).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) {
							v43 = int32(1)
						} else {
							v43 = 0
						}
						(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp3 = uint8(v43)
						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)
							v45 = pParse + 40
							v44 = *(*int32)(unsafe.Pointer(v45))
							*(*int32)(unsafe.Pointer(v45))++ /* Potential covering index (or NULL) */
							iCovCur = v44
							v47 = pParse + 44
							*(*int32)(unsafe.Pointer(v47))++
							v46 = *(*int32)(unsafe.Pointer(v47))           /* Cursor used for index scans (if any) */
							regReturn = v46                                /* 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)).FpTab
							pTerm = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
							pOrWc = *(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pTerm)).Fu))
							(*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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) > int32(1) { /* Original list of tables */
								nNotReady = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - iLevel - int32(1)
								pOrTab = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(80)+uint32(uint32(nNotReady))*uint32(72)))
								if pOrTab == uintptr(0) {
									return notReady
								}
								(*TSrcList)(unsafe.Pointer(pOrTab)).FnAlloc = uint32(uint8(nNotReady + libc.Int32FromInt32(1)))
								(*TSrcList)(unsafe.Pointer(pOrTab)).FnSrc = int32((*TSrcList)(unsafe.Pointer(pOrTab)).FnAlloc)
								libc.Xmemcpy(tls, pOrTab+8, pTabItem, uint32(72))
								origSrc = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
								k = int32(1)
								for {
									if !(k <= nNotReady) {
										break
									}
									libc.Xmemcpy(tls, pOrTab+8+uintptr(k)*72, origSrc+uintptr((*(*TWhereLevel)(unsafe.Pointer(pLevel + uintptr(k)*88))).FiFrom)*72, uint32(72))
									goto _48
								_48:
									;
									k++
								}
							} 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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DUPLICATES_OK) == 0 {
								if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
									v50 = pParse + 44
									*(*int32)(unsafe.Pointer(v50))++
									v49 = *(*int32)(unsafe.Pointer(v50))
									regRowset = v49
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regRowset)
								} else {
									pPk1 = _sqlite3PrimaryKeyIndex(tls, pTab)
									v52 = pParse + 40
									v51 = *(*int32)(unsafe.Pointer(v52))
									*(*int32)(unsafe.Pointer(v52))++
									regRowset = v51
									_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), regRowset, int32((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
									_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk1)
								}
								v54 = pParse + 44
								*(*int32)(unsafe.Pointer(v54))++
								v53 = *(*int32)(unsafe.Pointer(v54))
								regRowid = v53
							}
							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://www.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)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*48))).FpExpr
									if (*TWhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iTerm)*48 == pTerm {
										goto _55
									}
									if int32((*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*48))).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)|libc.Int32FromInt32(TERM_SLICE)) != 0 {
										goto _55
									}
									if int32((*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*48))).FeOperator)&int32(WO_ALL) == 0 {
										goto _55
									}
									if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
										goto _55
									} /* tag-20220303a */
									pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
									pAndExpr = _sqlite3ExprAnd(tls, pParse, pAndExpr, pExpr)
									goto _55
								_55:
									;
									iTerm++
								}
								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+23736, 0)
							ii = 0
							for {
								if !(ii < (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm) {
									break
								}
								pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr(ii)*48
								if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCur || int32((*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 */
									v57 = _sqlite3ExprDup(tls, db, pOrExpr, 0)
									pOrExpr = v57
									pDelete = v57
									if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
										_sqlite3ExprDelete(tls, db, pDelete)
										goto _56
									}
									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+23751, libc.VaList(bp+72, 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+760, 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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DUPLICATES_OK) == 0 {
											if ii == (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm-int32(1) {
												v58 = -int32(1)
											} else {
												v58 = ii
											}
											iSet = v58
											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 = int32((*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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk2)).FaiColumn + uintptr(iPk)*2)))
													_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
													goto _59
												_59:
													;
													iPk++
												}
												/* 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 + 48))&0x2>>1)) != 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 + 760))).FpWLoop
										if (*TWhereLoop)(unsafe.Pointer(pSubLoop)).FwsFlags&uint32(WHERE_INDEXED) != uint32(0) && (ii == 0 || (*TWhereLoop)(unsafe.Pointer(pSubLoop)).Fu.Fbtree.FpIndex == pCov) && ((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || !(int32(uint32(*(*uint16)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pSubLoop)).Fu.Fbtree.FpIndex + 56))&0x3>>0)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))) {
											pCov = (*TWhereLoop)(unsafe.Pointer(pSubLoop)).Fu.Fbtree.FpIndex
										} else {
											pCov = uintptr(0)
										}
										if _sqlite3WhereUsesDeferredSeek(tls, pSubWInfo) != 0 {
											libc.SetBitFieldPtr8Uint32(pWInfo+48, libc.Uint32FromInt32(1), 0, 0x1)
										}
										/* Finish the loop through table entries that match term pOrTerm. */
										_sqlite3WhereEnd(tls, pSubWInfo)
										_sqlite3VdbeExplainPop(tls, pParse)
									}
									_sqlite3ExprDelete(tls, db, pDelete)
								}
								goto _56
							_56:
								;
								ii++
							}
							_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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) > int32(1) {
								_sqlite3DbFreeNN(tls, db, pOrTab)
							}
							if !(untestedTerms != 0) {
								_disableTerm(tls, pLevel, pTerm)
							}
						} else {
							if int32(uint32(*(*uint16)(unsafe.Pointer(pTabItem + 36 + 4))&0x40>>6)) != 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, int32(_aStart[bRev]), iCur, addrHalt)
								(*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 {
		v60 = int32(1)
	} else {
		v60 = int32(2)
	}
	iLoop = v60
	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 int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
				goto _61
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0) {
				libc.SetBitFieldPtr8Uint32(pWInfo+48, libc.Uint32FromInt32(1), 1, 0x2)
				goto _61
			}
			pE = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if int32((*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&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != libc.Uint32FromInt32(0)) {
					/* Defer processing WHERE clause constraints until after outer
					 ** join processing.  tag-20220513a */
					goto _61
				} else {
					if int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LEFT) == int32(JT_LEFT) && !((*TExpr)(unsafe.Pointer(pE)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) {
						goto _61
					} else {
						m = _sqlite3WhereGetMask(tls, pWInfo+496, *(*int32)(unsafe.Pointer(pE + 36)))
						if m&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != 0 {
							/* An ON clause that is not ripe */
							goto _61
						}
					}
				}
			}
			if iLoop == int32(1) && !(_sqlite3ExprCoveredByIndex(tls, pE, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, pIdx) != 0) {
				iNext = int32(2)
				goto _61
			}
			if iLoop < int32(3) && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VARSELECT) != 0 {
				if iNext == 0 {
					iNext = int32(3)
				}
				goto _61
			}
			if int32((*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 _61
			}
			_sqlite3ExprIfFalse(tls, pParse, pE, addrCont, int32(SQLITE_JUMPIFNULL))
			if skipLikeAddr != 0 {
				_sqlite3VdbeJumpHere(tls, v, skipLikeAddr)
			}
			p62 = pTerm + 10
			*(*Tu16)(unsafe.Pointer(p62)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p62))) | libc.Int32FromInt32(TERM_CODED))
			goto _61
		_61:
			;
			j--
			pTerm += 48
		}
		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 int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
			goto _63
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) == 0 {
			goto _63
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_EQUIV) == 0 {
			goto _63
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != iCur {
			goto _63
		}
		if int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
			goto _63
		}
		pE1 = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		pAlt = _sqlite3WhereFindTerm(tls, pWC, iCur, (*(*struct {
			FleftColumn int32
			FiField     int32
		})(unsafe.Pointer(pTerm + 24))).FleftColumn, notReady, uint32(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IN)|libc.Int32FromInt32(WO_IS)), uintptr(0))
		if pAlt == uintptr(0) {
			goto _63
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pAlt)).FwtFlags)&int32(TERM_CODED) != 0 {
			goto _63
		}
		if int32((*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 + 20)))).FpEList)).FnExpr > int32(1) {
			goto _63
		}
		*(*TExpr)(unsafe.Pointer(bp + 8)) = *(*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr))
		(*(*TExpr)(unsafe.Pointer(bp + 8))).FpLeft = (*TExpr)(unsafe.Pointer(pE1)).FpLeft
		_sqlite3ExprIfFalse(tls, pParse, bp+8, addrCont, int32(SQLITE_JUMPIFNULL))
		p64 = pAlt + 10
		*(*Tu16)(unsafe.Pointer(p64)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p64))) | libc.Int32FromInt32(TERM_CODED))
		goto _63
	_63:
		;
		j--
		pTerm += 48
	}
	/* 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)*72))).FpTab
		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 = int32((*TIndex)(unsafe.Pointer(pPk3)).FnKeyCol)
			r1 = _sqlite3GetTempRange(tls, pParse, nPk1+int32(1))
			iPk1 = 0
			for {
				if !(iPk1 < nPk1) {
					break
				}
				iCol1 = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk3)).FaiColumn + uintptr(iPk1)*2)))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab1, iCur, iCol1, r1+int32(1)+iPk1)
				goto _65
			_65:
				;
				iPk1++
			}
		}
		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 _66
	}
	/* 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++
	/* 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 int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
			goto _67
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0) {
			goto _67
		}
		if int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
			goto _67
		}
		_sqlite3ExprIfFalse(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, addrCont, int32(SQLITE_JUMPIFNULL))
		p68 = pTerm + 10
		*(*Tu16)(unsafe.Pointer(p68)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p68))) | libc.Int32FromInt32(TERM_CODED))
		goto _67
	_67:
		;
		j++
		pTerm += 48
	}
_66:
	;
	return (*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady
}

/* Case 4: A scan using an index.
 **
 **         The WHERE clause may contain zero or more equality
 **         terms ("==" or "IN" operators) that refer to the N
 **         left-most columns of the index. It may also contain
 **         inequality constraints (>, <, >= or <=) on the indexed
 **         column that immediately follows the N equalities. Only
 **         the right-most column can be an inequality - the rest must
 **         use the "==" and "IN" operators. For example, if the
 **         index is on (x,y,z), then the following clauses are all
 **         optimized:
 **
 **            x=5
 **            x=5 AND y=10
 **            x=5 AND y<10
 **            x=5 AND y>5 AND y<10
 **            x=5 AND y=5 AND z<=10
 **
 **         The z<10 term of the following cannot be used, only
 **         the x=5 term:
 **
 **            x=5 AND z<10
 **
 **         N may be zero if there are inequality constraints.
 **         If there are no inequality constraints, then N is at
 **         least one.
 **
 **         This case is also used when there are no WHERE clause
 **         constraints but an index is selected anyway, in order
 **         to force the output order to conform to an ORDER BY.
 */
var _aStartOp = [8]Tu8{
	2: uint8(OP_Rewind),
	3: uint8(OP_Last),
	4: uint8(OP_SeekGT),
	5: uint8(OP_SeekLT),
	6: uint8(OP_SeekGE),
	7: uint8(OP_SeekLE),
}

var _aEndOp = [4]Tu8{
	0: uint8(OP_IdxGE),
	1: uint8(OP_IdxGT),
	2: uint8(OP_IdxLE),
	3: uint8(OP_IdxLT),
}

/* Case 6:  There is no usable index.  We must do a complete
 **          scan of the entire table.
 */
var _aStep = [2]Tu8{
	0: uint8(OP_Next),
	1: uint8(OP_Prev),
}

var _aStart = [2]Tu8{
	0: uint8(OP_Rewind),
	1: uint8(OP_Last),
}

// 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(96)
	defer tls.Free(96)
	var addrCont, iCol, iCur, iIdxCur, iPk, jmp, k, nPk, r, v3 int32
	var mAll TBitmask
	var pLoop, pParse, pPk, pRJ, pRight, pSubWInfo, pSubWhere, pTab, pTabItem, pTerm, pWC, v, v4 uintptr
	var _ /* sFrom at bp+0 */ TSrcList
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrCont, iCol, iCur, iIdxCur, iPk, jmp, k, mAll, nPk, pLoop, pParse, pPk, pRJ, pRight, pSubWInfo, pSubWhere, 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 + 80
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	pTabItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*72
	mAll = uint64(0)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23760, libc.VaList(bp+88, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pTabItem)).FpTab)).FzName))
	k = 0
	for {
		if !(k < iLevel) {
			break
		}
		pRight = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(k)*88))).FiFrom)*72
		mAll |= (*TWhereLoop1)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(k)*88))).FpWLoop)).FmaskSelf
		if int32(uint32(*(*uint16)(unsafe.Pointer(pRight + 36 + 4))&0x20>>5)) != 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*TSrcItem)(unsafe.Pointer(pRight)).FregResult, (*TSrcItem)(unsafe.Pointer(pRight)).FregResult+(*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pRight)).FpSelect)).FpEList)).FnExpr-int32(1))
		}
		_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(k)*88))).FiTabCur)
		iIdxCur = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(k)*88))).FiIdxCur
		if iIdxCur != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iIdxCur)
		}
		goto _1
	_1:
		;
		k++
	}
	if int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LTORJ) == 0 {
		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)*48
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_SLICE)) != 0 && int32((*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&uint32(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++
		}
	}
	(*(*TSrcList)(unsafe.Pointer(bp))).FnSrc = int32(1)
	(*(*TSrcList)(unsafe.Pointer(bp))).FnAlloc = uint32(1)
	libc.Xmemcpy(tls, bp+8, pTabItem, uint32(72))
	(*(*TSrcItem)(unsafe.Pointer(bp + 8))).Ffg.Fjointype = uint8(0)
	(*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn++
	pSubWInfo = _sqlite3WhereBegin(tls, pParse, bp, pSubWhere, uintptr(0), uintptr(0), uintptr(0), uint16(WHERE_RIGHT_JOIN), 0)
	if pSubWInfo != 0 {
		iCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
		v4 = pParse + 44
		*(*int32)(unsafe.Pointer(v4))++
		v3 = *(*int32)(unsafe.Pointer(v4))
		r = v3
		addrCont = _sqlite3WhereContinueLabel(tls, pSubWInfo)
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpTab
		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 = int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
			*(*int32)(unsafe.Pointer(pParse + 44)) += nPk - int32(1)
			iPk = 0
			for {
				if !(iPk < nPk) {
					break
				}
				iCol = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(iPk)*2)))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
				goto _5
			_5:
				;
				iPk++
			}
		}
		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--
}

// C documentation
//
//	/*
//	** Deallocate all memory associated with a WhereOrInfo object.
//	*/
func _whereOrInfoDelete(tls *libc.TLS, db uintptr, p uintptr) {
	_sqlite3WhereClauseClear(tls, p)
	_sqlite3DbFree(tls, db, p)
}

// C documentation
//
//	/*
//	** Deallocate all memory associated with a WhereAndInfo object.
//	*/
func _whereAndInfoDelete(tls *libc.TLS, db uintptr, p uintptr) {
	_sqlite3WhereClauseClear(tls, p)
	_sqlite3DbFree(tls, db, p)
}

// C documentation
//
//	/*
//	** Add a single new WhereTerm entry to the WhereClause object pWC.
//	** The new WhereTerm object is constructed from Expr p and with wtFlags.
//	** The index in pWC->a[] of the new WhereTerm is returned on success.
//	** 0 is returned if the new WhereTerm could not be added due to a memory
//	** allocation error.  The memory allocation failure will be recorded in
//	** the db->mallocFailed flag so that higher-level functions can detect it.
//	**
//	** This routine will increase the size of the pWC->a[] array as necessary.
//	**
//	** If the wtFlags argument includes TERM_DYNAMIC, then responsibility
//	** for freeing the expression p is assumed by the WhereClause object pWC.
//	** This is true even if this routine fails to allocate a new WhereTerm.
//	**
//	** WARNING:  This routine might reallocate the space used to store
//	** WhereTerms.  All pointers to WhereTerms should be invalidated after
//	** calling this routine.  Such pointers may be reinitialized by referencing
//	** the pWC->a[] array.
//	*/
func _whereClauseInsert(tls *libc.TLS, pWC uintptr, p uintptr, wtFlags Tu16) (r int32) {
	var db, pOld, pTerm, v3 uintptr
	var idx, v1, v2 int32
	_, _, _, _, _, _, _ = db, idx, pOld, pTerm, v1, v2, v3
	if (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm >= (*TWhereClause)(unsafe.Pointer(pWC)).FnSlot {
		pOld = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
		db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)).Fdb
		(*TWhereClause)(unsafe.Pointer(pWC)).Fa = _sqlite3WhereMalloc(tls, (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo, uint64(uint32(48)*uint32((*TWhereClause)(unsafe.Pointer(pWC)).FnSlot)*uint32(2)))
		if (*TWhereClause)(unsafe.Pointer(pWC)).Fa == uintptr(0) {
			if int32(int32(wtFlags))&int32(TERM_DYNAMIC) != 0 {
				_sqlite3ExprDelete(tls, db, p)
			}
			(*TWhereClause)(unsafe.Pointer(pWC)).Fa = pOld
			return 0
		}
		libc.Xmemcpy(tls, (*TWhereClause)(unsafe.Pointer(pWC)).Fa, pOld, uint32(48)*uint32((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm))
		(*TWhereClause)(unsafe.Pointer(pWC)).FnSlot = (*TWhereClause)(unsafe.Pointer(pWC)).FnSlot * int32(2)
	}
	v3 = pWC + 12
	v2 = *(*int32)(unsafe.Pointer(v3))
	*(*int32)(unsafe.Pointer(v3))++
	v1 = v2
	idx = v1
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(v1)*48
	if int32(int32(wtFlags))&int32(TERM_VIRTUAL) == 0 {
		(*TWhereClause)(unsafe.Pointer(pWC)).FnBase = (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm
	}
	if p != 0 && (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_Unlikely)) != uint32(0) {
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb = int16(int32(_sqlite3LogEst(tls, uint64((*TExpr)(unsafe.Pointer(p)).FiTable))) - int32(270))
	} else {
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb = int16(1)
	}
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr = _sqlite3ExprSkipCollateAndLikely(tls, p)
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags = wtFlags
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FpWC = pWC
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FiParent = -int32(1)
	libc.Xmemset(tls, pTerm+12, 0, libc.Uint32FromInt64(48)-uint32(libc.UintptrFromInt32(0)+12))
	return idx
}

// C documentation
//
//	/*
//	** Return TRUE if the given operator is one of the operators that is
//	** allowed for an indexable WHERE clause term.  The allowed operators are
//	** "=", "<", ">", "<=", ">=", "IN", "IS", and "IS NULL"
//	*/
func _allowedOp(tls *libc.TLS, op int32) (r int32) {
	return libc.BoolInt32(op == int32(TK_IN) || op >= int32(TK_EQ) && op <= int32(TK_GE) || op == int32(TK_ISNULL) || op == int32(TK_IS))
}

// C documentation
//
//	/*
//	** Commute a comparison operator.  Expressions of the form "X op Y"
//	** are converted into "Y op X".
//	*/
func _exprCommute(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r Tu16) {
	var t uintptr
	_ = t
	if int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == int32(TK_VECTOR) || int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpRight)).Fop) == int32(TK_VECTOR) || _sqlite3BinaryCompareCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight) != _sqlite3BinaryCompareCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft) {
		*(*Tu32)(unsafe.Pointer(pExpr + 4)) ^= uint32(EP_Commuted)
	}
	t = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
	(*TExpr)(unsafe.Pointer(pExpr)).FpRight = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = t
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) >= int32(TK_GT) {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) - int32(TK_GT) ^ int32(2) + int32(TK_GT))
	}
	return uint16(0)
}

// C documentation
//
//	/*
//	** Translate from TK_xx operator to WO_xx bitmask.
//	*/
func _operatorMask(tls *libc.TLS, op int32) (r Tu16) {
	var c Tu16
	_ = c
	if op == int32(TK_IN) {
		c = uint16(WO_IN)
	} else {
		if op == int32(TK_ISNULL) {
			c = uint16(WO_ISNULL)
		} else {
			if op == int32(TK_IS) {
				c = uint16(WO_IS)
			} else {
				c = uint16(libc.Int32FromInt32(WO_EQ) << (op - libc.Int32FromInt32(TK_EQ)))
			}
		}
	}
	return c
}

// C documentation
//
//	/*
//	** Check to see if the given expression is a LIKE or GLOB operator that
//	** can be optimized using inequality constraints.  Return TRUE if it is
//	** so and false if not.
//	**
//	** In order for the operator to be optimizible, the RHS must be a string
//	** literal that does not begin with a wildcard.  The LHS must be a column
//	** that may only be NULL, a string, or a BLOB, never a number. (This means
//	** that virtual tables cannot participate in the LIKE optimization.)  The
//	** collating sequence for the column on the LHS must be appropriate for
//	** the operator.
//	*/
func _isLikeOrGlob(tls *libc.TLS, pParse uintptr, pExpr uintptr, ppPrefix uintptr, pisComplete uintptr, pnoCase uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c, v1 Tu8
	var cnt, iCol, iFrom, iTo, isNum, op, r1, rc, v3, v4 int32
	var db, pLeft, pList, pPrefix, pReprepare, pRight, pVal, v, z, zNew uintptr
	var _ /* rDummy at bp+8 */ float64
	var _ /* wc at bp+0 */ [4]Tu8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, cnt, db, iCol, iFrom, iTo, isNum, op, pLeft, pList, pPrefix, pReprepare, pRight, pVal, r1, rc, v, z, zNew, v1, v3, v4
	z = uintptr(0)                             /* Wildcard characters */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database connection */
	pVal = uintptr(0)                          /* Result code to return */
	if !(_sqlite3IsLikeFunction(tls, db, pExpr, pnoCase, bp) != 0) {
		return 0
	}
	pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
	pLeft = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + 1*20))).FpExpr
	pRight = _sqlite3ExprSkipCollate(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr)
	op = int32((*TExpr)(unsafe.Pointer(pRight)).Fop)
	if op == int32(TK_VARIABLE) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableQPSG) == uint64(0) {
		pReprepare = (*TParse)(unsafe.Pointer(pParse)).FpReprepare
		iCol = int32((*TExpr)(unsafe.Pointer(pRight)).FiColumn)
		pVal = _sqlite3VdbeGetBoundValue(tls, pReprepare, iCol, uint8(SQLITE_AFF_BLOB))
		if pVal != 0 && Xsqlite3_value_type(tls, pVal) == int32(SQLITE_TEXT) {
			z = Xsqlite3_value_text(tls, pVal)
		}
		_sqlite3VdbeSetVarmask(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, iCol)
	} else {
		if op == int32(TK_STRING) {
			z = *(*uintptr)(unsafe.Pointer(pRight + 8))
		}
	}
	if z != 0 {
		/* Count the number of prefix characters prior to the first wildcard */
		cnt = 0
		for {
			v1 = *(*Tu8)(unsafe.Pointer(z + uintptr(cnt)))
			c = v1
			if !(int32(v1) != 0 && int32(int32(c)) != int32((*(*[4]Tu8)(unsafe.Pointer(bp)))[0]) && int32(int32(c)) != int32((*(*[4]Tu8)(unsafe.Pointer(bp)))[int32(1)]) && int32(int32(c)) != int32((*(*[4]Tu8)(unsafe.Pointer(bp)))[int32(2)])) {
				break
			}
			cnt++
			if int32(int32(c)) == int32((*(*[4]Tu8)(unsafe.Pointer(bp)))[int32(3)]) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(cnt)))) != 0 {
				cnt++
			}
		}
		/* The optimization is possible only if (1) the pattern does not begin
		 ** with a wildcard and if (2) the non-wildcard prefix does not end with
		 ** an (illegal 0xff) character, or (3) the pattern does not consist of
		 ** a single escape character. The second condition is necessary so
		 ** that we can increment the prefix key to find an upper bound for the
		 ** range search. The third is because the caller assumes that the pattern
		 ** consists of at least one character after all escapes have been
		 ** removed.  */
		if (cnt > int32(1) || cnt > 0 && int32(*(*Tu8)(unsafe.Pointer(z))) != int32((*(*[4]Tu8)(unsafe.Pointer(bp)))[int32(3)])) && int32(255) != int32(*(*Tu8)(unsafe.Pointer(z + uintptr(cnt-int32(1))))) {
			/* A "complete" match if the pattern ends with "*" or "%" */
			*(*int32)(unsafe.Pointer(pisComplete)) = libc.BoolInt32(int32(int32(c)) == int32((*(*[4]Tu8)(unsafe.Pointer(bp)))[0]) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(cnt+int32(1))))) == 0)
			/* Get the pattern prefix.  Remove all escapes from the prefix. */
			pPrefix = _sqlite3Expr(tls, db, int32(TK_STRING), z)
			if pPrefix != 0 {
				zNew = *(*uintptr)(unsafe.Pointer(pPrefix + 8))
				*(*int8)(unsafe.Pointer(zNew + uintptr(cnt))) = 0
				v3 = libc.Int32FromInt32(0)
				iTo = v3
				iFrom = v3
				for {
					if !(iFrom < cnt) {
						break
					}
					if int32(*(*int8)(unsafe.Pointer(zNew + uintptr(iFrom)))) == int32((*(*[4]Tu8)(unsafe.Pointer(bp)))[int32(3)]) {
						iFrom++
					}
					v4 = iTo
					iTo++
					*(*int8)(unsafe.Pointer(zNew + uintptr(v4))) = *(*int8)(unsafe.Pointer(zNew + uintptr(iFrom)))
					goto _2
				_2:
					;
					iFrom++
				}
				*(*int8)(unsafe.Pointer(zNew + uintptr(iTo))) = 0
				/* If the LHS is not an ordinary column with TEXT affinity, then the
				 ** pattern prefix boundaries (both the start and end boundaries) must
				 ** not look like a number.  Otherwise the pattern might be treated as
				 ** a number, which will invalidate the LIKE optimization.
				 **
				 ** Getting this right has been a persistent source of bugs in the
				 ** LIKE optimization.  See, for example:
				 **    2018-09-10 https://sqlite.org/src/info/c94369cae9b561b1
				 **    2019-05-02 https://sqlite.org/src/info/b043a54c3de54b28
				 **    2019-06-10 https://sqlite.org/src/info/fd76310a5e843e07
				 **    2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
				 **    2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
				 */
				if int32((*TExpr)(unsafe.Pointer(pLeft)).Fop) != int32(TK_COLUMN) || int32(_sqlite3ExprAffinity(tls, pLeft)) != int32(SQLITE_AFF_TEXT) || (*TExpr)(unsafe.Pointer(pLeft)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == uint32(0) && (*TExpr)(unsafe.Pointer(pLeft)).Fy.FpTab != 0 && int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pLeft)).Fy.FpTab)).FeTabType) == int32(TABTYP_VTAB) {
					isNum = _sqlite3AtoF(tls, zNew, bp+8, iTo, uint8(SQLITE_UTF8))
					if isNum <= 0 {
						if iTo == int32(1) && int32(*(*int8)(unsafe.Pointer(zNew))) == int32('-') {
							isNum = +libc.Int32FromInt32(1)
						} else {
							*(*int8)(unsafe.Pointer(zNew + uintptr(iTo-int32(1))))++
							isNum = _sqlite3AtoF(tls, zNew, bp+8, iTo, uint8(SQLITE_UTF8))
							*(*int8)(unsafe.Pointer(zNew + uintptr(iTo-int32(1))))--
						}
					}
					if isNum > 0 {
						_sqlite3ExprDelete(tls, db, pPrefix)
						_sqlite3ValueFree(tls, pVal)
						return 0
					}
				}
			}
			*(*uintptr)(unsafe.Pointer(ppPrefix)) = pPrefix
			/* If the RHS pattern is a bound parameter, make arrangements to
			 ** reprepare the statement when that parameter is rebound */
			if op == int32(TK_VARIABLE) {
				v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
				_sqlite3VdbeSetVarmask(tls, v, int32((*TExpr)(unsafe.Pointer(pRight)).FiColumn))
				if *(*int32)(unsafe.Pointer(pisComplete)) != 0 && *(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRight + 8)) + 1)) != 0 {
					/* If the rhs of the LIKE expression is a variable, and the current
					 ** value of the variable means there is no need to invoke the LIKE
					 ** function, then no OP_Variable will be added to the program.
					 ** This causes problems for the sqlite3_bind_parameter_name()
					 ** API. To work around them, add a dummy OP_Variable here.
					 */
					r1 = _sqlite3GetTempReg(tls, pParse)
					_sqlite3ExprCodeTarget(tls, pParse, pRight, r1)
					_sqlite3VdbeChangeP3(tls, v, _sqlite3VdbeCurrentAddr(tls, v)-int32(1), 0)
					_sqlite3ReleaseTempReg(tls, pParse, r1)
				}
			}
		} else {
			z = uintptr(0)
		}
	}
	rc = libc.BoolInt32(z != uintptr(0))
	_sqlite3ValueFree(tls, pVal)
	return rc
}

// C documentation
//
//	/*
//	** Check to see if the pExpr expression is a form that needs to be passed
//	** to the xBestIndex method of virtual tables.  Forms of interest include:
//	**
//	**          Expression                   Virtual Table Operator
//	**          -----------------------      ---------------------------------
//	**      1.  column MATCH expr            SQLITE_INDEX_CONSTRAINT_MATCH
//	**      2.  column GLOB expr             SQLITE_INDEX_CONSTRAINT_GLOB
//	**      3.  column LIKE expr             SQLITE_INDEX_CONSTRAINT_LIKE
//	**      4.  column REGEXP expr           SQLITE_INDEX_CONSTRAINT_REGEXP
//	**      5.  column != expr               SQLITE_INDEX_CONSTRAINT_NE
//	**      6.  expr != column               SQLITE_INDEX_CONSTRAINT_NE
//	**      7.  column IS NOT expr           SQLITE_INDEX_CONSTRAINT_ISNOT
//	**      8.  expr IS NOT column           SQLITE_INDEX_CONSTRAINT_ISNOT
//	**      9.  column IS NOT NULL           SQLITE_INDEX_CONSTRAINT_ISNOTNULL
//	**
//	** In every case, "column" must be a column of a virtual table.  If there
//	** is a match, set *ppLeft to the "column" expression, set *ppRight to the
//	** "expr" expression (even though in forms (6) and (8) the column is on the
//	** right and the expression is on the left).  Also set *peOp2 to the
//	** appropriate virtual table operator.  The return value is 1 or 2 if there
//	** is a match.  The usual return is 1, but if the RHS is also a column
//	** of virtual table in forms (5) or (7) then return 2.
//	**
//	** If the expression matches none of the patterns above, return 0.
//	*/
func _isAuxiliaryVtabOperator(tls *libc.TLS, db uintptr, pExpr uintptr, peOp2 uintptr, ppLeft uintptr, ppRight uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, res int32
	var pCol, pLeft, pList, pMod, pRight, pVtab, t uintptr
	var _ /* pNotUsed at bp+4 */ uintptr
	var _ /* xNotUsed at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _ = i, pCol, pLeft, pList, pMod, pRight, pVtab, res, t
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_FUNCTION) {
		pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
		if pList == uintptr(0) || (*TExprList)(unsafe.Pointer(pList)).FnExpr != int32(2) {
			return 0
		}
		/* Built-in operators MATCH, GLOB, LIKE, and REGEXP attach to a
		 ** virtual table on their second argument, which is the same as
		 ** the left-hand side operand in their in-fix form.
		 **
		 **       vtab_column MATCH expression
		 **       MATCH(expression,vtab_column)
		 */
		pCol = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + 1*20))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pCol)).Fop) == int32(TK_COLUMN) && int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pCol)).Fy.FpTab)).FeTabType) == int32(TABTYP_VTAB) {
			i = 0
			for {
				if !(i < int32(libc.Uint32FromInt64(32)/libc.Uint32FromInt64(8))) {
					break
				}
				if _sqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), _aOp[i].FzOp) == 0 {
					*(*uint8)(unsafe.Pointer(peOp2)) = _aOp[i].FeOp2
					*(*uintptr)(unsafe.Pointer(ppRight)) = (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr
					*(*uintptr)(unsafe.Pointer(ppLeft)) = pCol
					return int32(1)
				}
				goto _1
			_1:
				;
				i++
			}
		}
		/* We can also match against the first column of overloaded
		 ** functions where xFindFunction returns a value of at least
		 ** SQLITE_INDEX_CONSTRAINT_FUNCTION.
		 **
		 **      OVERLOADED(vtab_column,expression)
		 **
		 ** Historically, xFindFunction expected to see lower-case function
		 ** names.  But for this use case, xFindFunction is expected to deal
		 ** with function names in an arbitrary case.
		 */
		pCol = (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr
		if int32((*TExpr)(unsafe.Pointer(pCol)).Fop) == int32(TK_COLUMN) && int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pCol)).Fy.FpTab)).FeTabType) == int32(TABTYP_VTAB) {
			pVtab = (*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, db, (*TExpr)(unsafe.Pointer(pCol)).Fy.FpTab))).FpVtab
			pMod = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule
			if (*Tsqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction != uintptr(0) {
				i = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction})))(tls, pVtab, int32(2), *(*uintptr)(unsafe.Pointer(pExpr + 8)), bp, bp+4)
				if i >= int32(SQLITE_INDEX_CONSTRAINT_FUNCTION) {
					*(*uint8)(unsafe.Pointer(peOp2)) = uint8(uint8(i))
					*(*uintptr)(unsafe.Pointer(ppRight)) = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + 1*20))).FpExpr
					*(*uintptr)(unsafe.Pointer(ppLeft)) = pCol
					return int32(1)
				}
			}
		}
	} else {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NE) || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_ISNOT) || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NOTNULL) {
			res = 0
			pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
			pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
			if int32((*TExpr)(unsafe.Pointer(pLeft)).Fop) == int32(TK_COLUMN) && int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pLeft)).Fy.FpTab)).FeTabType) == int32(TABTYP_VTAB) {
				res++
			}
			if pRight != 0 && (int32((*TExpr)(unsafe.Pointer(pRight)).Fop) == int32(TK_COLUMN) && int32((*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pRight)).Fy.FpTab)).FeTabType) == int32(TABTYP_VTAB)) {
				res++
				t = pLeft
				pLeft = pRight
				pRight = t
			}
			*(*uintptr)(unsafe.Pointer(ppLeft)) = pLeft
			*(*uintptr)(unsafe.Pointer(ppRight)) = pRight
			if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NE) {
				*(*uint8)(unsafe.Pointer(peOp2)) = uint8(SQLITE_INDEX_CONSTRAINT_NE)
			}
			if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_ISNOT) {
				*(*uint8)(unsafe.Pointer(peOp2)) = uint8(SQLITE_INDEX_CONSTRAINT_ISNOT)
			}
			if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NOTNULL) {
				*(*uint8)(unsafe.Pointer(peOp2)) = uint8(SQLITE_INDEX_CONSTRAINT_ISNOTNULL)
			}
			return res
		}
	}
	return 0
}

var _aOp = [4]struct {
	FzOp  uintptr
	FeOp2 uint8
}{
	0: {
		FzOp:  __ccgo_ts + 17945,
		FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_MATCH),
	},
	1: {
		FzOp:  __ccgo_ts + 17281,
		FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_GLOB),
	},
	2: {
		FzOp:  __ccgo_ts + 16760,
		FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_LIKE),
	},
	3: {
		FzOp:  __ccgo_ts + 23774,
		FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_REGEXP),
	},
}

// C documentation
//
//	/*
//	** If the pBase expression originated in the ON or USING clause of
//	** a join, then transfer the appropriate markings over to derived.
//	*/
func _transferJoinMarkings(tls *libc.TLS, pDerived uintptr, pBase uintptr) {
	if pDerived != 0 && (*TExpr)(unsafe.Pointer(pBase)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
		*(*Tu32)(unsafe.Pointer(pDerived + 4)) |= (*TExpr)(unsafe.Pointer(pBase)).Fflags & uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON))
		*(*int32)(unsafe.Pointer(pDerived + 36)) = *(*int32)(unsafe.Pointer(pBase + 36))
	}
}

// C documentation
//
//	/*
//	** Mark term iChild as being a child of term iParent
//	*/
func _markTermAsChild(tls *libc.TLS, pWC uintptr, iChild int32, iParent int32) {
	(*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iChild)*48))).FiParent = iParent
	(*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iChild)*48))).FtruthProb = (*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iParent)*48))).FtruthProb
	(*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iParent)*48))).FnChild++
}

// C documentation
//
//	/*
//	** Return the N-th AND-connected subterm of pTerm.  Or if pTerm is not
//	** a conjunction, then return just pTerm when N==0.  If N is exceeds
//	** the number of available subterms, return NULL.
//	*/
func _whereNthSubterm(tls *libc.TLS, pTerm uintptr, N int32) (r uintptr) {
	var v1 uintptr
	_ = v1
	if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) != int32(WO_AND) {
		if N == 0 {
			v1 = pTerm
		} else {
			v1 = uintptr(0)
		}
		return v1
	}
	if N < (*TWhereAndInfo)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pTerm)).Fu)))).Fwc.FnTerm {
		return (*TWhereAndInfo)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pTerm)).Fu)))).Fwc.Fa + uintptr(N)*48
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Subterms pOne and pTwo are contained within WHERE clause pWC.  The
//	** two subterms are in disjunction - they are OR-ed together.
//	**
//	** If these two terms are both of the form:  "A op B" with the same
//	** A and B values but different operators and if the operators are
//	** compatible (if one is = and the other is <, for example) then
//	** add a new virtual AND term to pWC that is the combination of the
//	** two.
//	**
//	** Some examples:
//	**
//	**    x<y OR x=y    -->     x<=y
//	**    x=y OR x=y    -->     x=y
//	**    x<=y OR x<y   -->     x<=y
//	**
//	** The following is NOT generated:
//	**
//	**    x<y OR x>y    -->     x!=y
//	*/
func _whereCombineDisjuncts(tls *libc.TLS, pSrc uintptr, pWC uintptr, pOne uintptr, pTwo uintptr) {
	var db, pNew uintptr
	var eOp Tu16
	var idxNew, op int32
	_, _, _, _, _ = db, eOp, idxNew, op, pNew
	eOp = uint16(int32((*TWhereTerm)(unsafe.Pointer(pOne)).FeOperator) | int32((*TWhereTerm)(unsafe.Pointer(pTwo)).FeOperator)) /* Index in pWC of the next virtual term */
	if (int32((*TWhereTerm)(unsafe.Pointer(pOne)).FwtFlags)|int32((*TWhereTerm)(unsafe.Pointer(pTwo)).FwtFlags))&int32(TERM_VNULL) != 0 {
		return
	}
	if int32((*TWhereTerm)(unsafe.Pointer(pOne)).FeOperator)&(libc.Int32FromInt32(WO_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_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) == 0 {
		return
	}
	if int32((*TWhereTerm)(unsafe.Pointer(pTwo)).FeOperator)&(libc.Int32FromInt32(WO_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_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) == 0 {
		return
	}
	if int32(int32(eOp))&(libc.Int32FromInt32(WO_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))) != int32(int32(eOp)) && int32(int32(eOp))&(libc.Int32FromInt32(WO_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))) != int32(int32(eOp)) {
		return
	}
	if _sqlite3ExprCompare(tls, uintptr(0), (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOne)).FpExpr)).FpLeft, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTwo)).FpExpr)).FpLeft, -int32(1)) != 0 {
		return
	}
	if _sqlite3ExprCompare(tls, uintptr(0), (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOne)).FpExpr)).FpRight, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTwo)).FpExpr)).FpRight, -int32(1)) != 0 {
		return
	}
	/* If we reach this point, it means the two subterms can be combined */
	if int32(int32(eOp))&(int32(int32(eOp))-int32(1)) != 0 {
		if int32(int32(eOp))&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))) != 0 {
			eOp = uint16(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_LE) - libc.Int32FromInt32(TK_EQ)))
		} else {
			eOp = uint16(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_GE) - libc.Int32FromInt32(TK_EQ)))
		}
	}
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)).Fdb
	pNew = _sqlite3ExprDup(tls, db, (*TWhereTerm)(unsafe.Pointer(pOne)).FpExpr, 0)
	if pNew == uintptr(0) {
		return
	}
	op = int32(TK_EQ)
	for {
		if !(int32(int32(eOp)) != int32(WO_EQ)<<(op-int32(TK_EQ))) {
			break
		}
		goto _1
	_1:
		;
		op++
	}
	(*TExpr)(unsafe.Pointer(pNew)).Fop = uint8(uint8(op))
	idxNew = _whereClauseInsert(tls, pWC, pNew, uint16(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
	_exprAnalyze(tls, pSrc, pWC, idxNew)
}

// C documentation
//
//	/*
//	** Analyze a term that consists of two or more OR-connected
//	** subterms.  So in:
//	**
//	**     ... WHERE  (a=5) AND (b=7 OR c=9 OR d=13) AND (d=13)
//	**                          ^^^^^^^^^^^^^^^^^^^^
//	**
//	** This routine analyzes terms such as the middle term in the above example.
//	** A WhereOrTerm object is computed and attached to the term under
//	** analysis, regardless of the outcome of the analysis.  Hence:
//	**
//	**     WhereTerm.wtFlags   |=  TERM_ORINFO
//	**     WhereTerm.u.pOrInfo  =  a dynamically allocated WhereOrTerm object
//	**
//	** The term being analyzed must have two or more of OR-connected subterms.
//	** A single subterm might be a set of AND-connected sub-subterms.
//	** Examples of terms under analysis:
//	**
//	**     (A)     t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
//	**     (B)     x=expr1 OR expr2=x OR x=expr3
//	**     (C)     t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
//	**     (D)     x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
//	**     (E)     (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
//	**     (F)     x>A OR (x=A AND y>=B)
//	**
//	** CASE 1:
//	**
//	** If all subterms are of the form T.C=expr for some single column of C and
//	** a single table T (as shown in example B above) then create a new virtual
//	** term that is an equivalent IN expression.  In other words, if the term
//	** being analyzed is:
//	**
//	**      x = expr1  OR  expr2 = x  OR  x = expr3
//	**
//	** then create a new virtual term like this:
//	**
//	**      x IN (expr1,expr2,expr3)
//	**
//	** CASE 2:
//	**
//	** If there are exactly two disjuncts and one side has x>A and the other side
//	** has x=A (for the same x and A) then add a new virtual conjunct term to the
//	** WHERE clause of the form "x>=A".  Example:
//	**
//	**      x>A OR (x=A AND y>B)    adds:    x>=A
//	**
//	** The added conjunct can sometimes be helpful in query planning.
//	**
//	** CASE 3:
//	**
//	** If all subterms are indexable by a single table T, then set
//	**
//	**     WhereTerm.eOperator              =  WO_OR
//	**     WhereTerm.u.pOrInfo->indexable  |=  the cursor number for table T
//	**
//	** A subterm is "indexable" if it is of the form
//	** "T.C <op> <expr>" where C is any column of table T and
//	** <op> is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
//	** A subterm is also indexable if it is an AND of two or more
//	** subsubterms at least one of which is indexable.  Indexable AND
//	** subterms have their eOperator set to WO_AND and they have
//	** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
//	**
//	** From another point of view, "indexable" means that the subterm could
//	** potentially be used with an index if an appropriate index exists.
//	** This analysis does not consider whether or not the index exists; that
//	** is decided elsewhere.  This analysis only looks at whether subterms
//	** appropriate for indexing exist.
//	**
//	** All examples A through E above satisfy case 3.  But if a term
//	** also satisfies case 1 (such as B) we know that the optimizer will
//	** always prefer case 1, so in that case we pretend that case 3 is not
//	** satisfied.
//	**
//	** It might be the case that multiple tables are indexable.  For example,
//	** (E) above is indexable on tables P, Q, and R.
//	**
//	** Terms that satisfy case 3 are candidates for lookup by using
//	** separate indices to find rowids for each subterm and composing
//	** the union of all rowids using a RowSet object.  This is similar
//	** to "bitmap indices" in other database engines.
//	**
//	** OTHERWISE:
//	**
//	** If none of cases 1, 2, or 3 apply, then leave the eOperator set to
//	** zero.  This term is not useful for search.
//	*/
func _exprAnalyzeOrTerm(tls *libc.TLS, pSrc uintptr, pWC uintptr, idxTerm int32) {
	var affLeft, affRight, i, iColumn, iCursor, iOne, iTwo, idxNew, j, j1, okToChngToIN, v7, v9 int32
	var b, b1, chngToIN, indexable TBitmask
	var db, pAndInfo, pAndTerm, pAndWC, pDup, pExpr, pLeft, pLeft1, pList, pNew, pOne, pOrInfo, pOrTerm, pOrWc, pOther, pParse, pTerm, pTwo, pWInfo, v1, v6, v8, p12, p14, p15, p2, p4 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = affLeft, affRight, b, b1, chngToIN, db, i, iColumn, iCursor, iOne, iTwo, idxNew, indexable, j, j1, okToChngToIN, pAndInfo, pAndTerm, pAndWC, pDup, pExpr, pLeft, pLeft1, pList, pNew, pOne, pOrInfo, pOrTerm, pOrWc, pOther, pParse, pTerm, pTwo, pWInfo, v1, v6, v7, v8, v9, p12, p14, p15, p2, p4
	pWInfo = (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo                 /* WHERE clause processing context */
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse                /* Parser context */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                            /* Database connection */
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48 /* The term to be analyzed */
	pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr                   /* Tables that are indexable, satisfying case 2 */
	/*
	 ** Break the OR clause into its separate subterms.  The subterms are
	 ** stored in a WhereClause structure containing within the WhereOrInfo
	 ** object that is attached to the original OR clause term.
	 */
	v1 = _sqlite3DbMallocZero(tls, db, uint64(424))
	pOrInfo = v1
	*(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pTerm)).Fu)) = v1
	if pOrInfo == uintptr(0) {
		return
	}
	p2 = pTerm + 10
	*(*Tu16)(unsafe.Pointer(p2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p2))) | libc.Int32FromInt32(TERM_ORINFO))
	pOrWc = pOrInfo
	libc.Xmemset(tls, pOrWc+32, 0, uint32(384))
	_sqlite3WhereClauseInit(tls, pOrWc, pWInfo)
	_sqlite3WhereSplit(tls, pOrWc, pExpr, uint8(TK_OR))
	_sqlite3WhereExprAnalyze(tls, pSrc, pOrWc)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}
	/*
	 ** Compute the set of tables that might satisfy cases 1 or 3.
	 */
	indexable = ^libc.Uint64FromInt32(0)
	chngToIN = ^libc.Uint64FromInt32(0)
	i = (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm - int32(1)
	pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa
	for {
		if !(i >= 0 && indexable != 0) {
			break
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&int32(WO_SINGLE) == 0 {
			chngToIN = uint64(0)
			pAndInfo = _sqlite3DbMallocRawNN(tls, db, uint64(416))
			if pAndInfo != 0 {
				b = uint64(0)
				*(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pOrTerm)).Fu)) = pAndInfo
				p4 = pOrTerm + 10
				*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(TERM_ANDINFO))
				(*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator = uint16(WO_AND)
				(*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor = -int32(1)
				pAndWC = pAndInfo
				libc.Xmemset(tls, pAndWC+32, 0, uint32(384))
				_sqlite3WhereClauseInit(tls, pAndWC, (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)
				_sqlite3WhereSplit(tls, pAndWC, (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr, uint8(TK_AND))
				_sqlite3WhereExprAnalyze(tls, pSrc, pAndWC)
				(*TWhereClause)(unsafe.Pointer(pAndWC)).FpOuter = pWC
				if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
					j = 0
					pAndTerm = (*TWhereClause)(unsafe.Pointer(pAndWC)).Fa
					for {
						if !(j < (*TWhereClause)(unsafe.Pointer(pAndWC)).FnTerm) {
							break
						}
						if _allowedOp(tls, int32((*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAndTerm)).FpExpr)).Fop)) != 0 || int32((*TWhereTerm)(unsafe.Pointer(pAndTerm)).FeOperator) == int32(WO_AUX) {
							b |= _sqlite3WhereGetMask(tls, pWInfo+496, (*TWhereTerm)(unsafe.Pointer(pAndTerm)).FleftCursor)
						}
						goto _5
					_5:
						;
						j++
						pAndTerm += 48
					}
				}
				indexable &= b
			}
		} else {
			if int32((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&int32(TERM_COPIED) != 0 {
				/* Skip this term for now.  We revisit it when we process the
				 ** corresponding TERM_VIRTUAL term */
			} else {
				b1 = _sqlite3WhereGetMask(tls, pWInfo+496, (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor)
				if int32((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&int32(TERM_VIRTUAL) != 0 {
					pOther = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FiParent)*48
					b1 |= _sqlite3WhereGetMask(tls, pWInfo+496, (*TWhereTerm)(unsafe.Pointer(pOther)).FleftCursor)
				}
				indexable &= b1
				if int32((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&int32(WO_EQ) == 0 {
					chngToIN = uint64(0)
				} else {
					chngToIN &= b1
				}
			}
		}
		goto _3
	_3:
		;
		i--
		pOrTerm += 48
	}
	/*
	 ** Record the set of tables that satisfy case 3.  The set might be
	 ** empty.
	 */
	(*TWhereOrInfo)(unsafe.Pointer(pOrInfo)).Findexable = indexable
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(WO_OR)
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = -int32(1)
	if indexable != 0 {
		(*TWhereClause)(unsafe.Pointer(pWC)).FhasOr = uint8(1)
	}
	/* For a two-way OR, attempt to implementation case 2.
	 */
	if indexable != 0 && (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm == int32(2) {
		iOne = 0
		for {
			v7 = iOne
			iOne++
			v6 = _whereNthSubterm(tls, (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa, v7)
			pOne = v6
			if !(v6 != uintptr(0)) {
				break
			}
			iTwo = 0
			for {
				v9 = iTwo
				iTwo++
				v8 = _whereNthSubterm(tls, (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa+1*48, v9)
				pTwo = v8
				if !(v8 != uintptr(0)) {
					break
				}
				_whereCombineDisjuncts(tls, pSrc, pWC, pOne, pTwo)
			}
		}
	}
	/*
	 ** chngToIN holds a set of tables that *might* satisfy case 1.  But
	 ** we have to do some additional checking to see if case 1 really
	 ** is satisfied.
	 **
	 ** chngToIN will hold either 0, 1, or 2 bits.  The 0-bit case means
	 ** that there is no possibility of transforming the OR clause into an
	 ** IN operator because one or more terms in the OR clause contain
	 ** something other than == on a column in the single table.  The 1-bit
	 ** case means that every term of the OR clause is of the form
	 ** "table.column=expr" for some single table.  The one bit that is set
	 ** will correspond to the common table.  We still need to check to make
	 ** sure the same column is used on all terms.  The 2-bit case is when
	 ** the all terms are of the form "table1.column=table2.column".  It
	 ** might be possible to form an IN operator with either table1.column
	 ** or table2.column as the LHS if either is common to every term of
	 ** the OR clause.
	 **
	 ** Note that terms of the form "table.column1=table.column2" (the
	 ** same table on both sizes of the ==) cannot be optimized.
	 */
	if chngToIN != 0 {
		okToChngToIN = 0    /* True if the conversion to IN is valid */
		iColumn = -int32(1) /* Column index on lhs of IN operator */
		iCursor = -int32(1) /* Table cursor common to all terms */
		j1 = 0              /* Loop counter */
		/* Search for a table and column that appears on one side or the
		 ** other of the == operator in every subterm.  That table and column
		 ** will be recorded in iCursor and iColumn.  There might not be any
		 ** such table and column.  Set okToChngToIN if an appropriate table
		 ** and column is found but leave okToChngToIN false if not found.
		 */
		j1 = 0
		for {
			if !(j1 < int32(2) && !(okToChngToIN != 0)) {
				break
			}
			pLeft = uintptr(0)
			pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa
			i = (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm - int32(1)
			for {
				if !(i >= 0) {
					break
				}
				p12 = pOrTerm + 10
				*(*Tu16)(unsafe.Pointer(p12)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p12))) & ^libc.Int32FromInt32(TERM_OK))
				if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCursor {
					/* This is the 2-bit case and we are on the second iteration and
					 ** current term is from the first iteration.  So skip this term. */
					goto _11
				}
				if chngToIN&_sqlite3WhereGetMask(tls, pWInfo+496, (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor) == uint64(0) {
					/* This term must be of the form t1.a==t2.b where t2 is in the
					 ** chngToIN set but t1 is not.  This term will be either preceded
					 ** or followed by an inverted copy (t2.b==t1.a).  Skip this term
					 ** and use its inversion. */
					goto _11
				}
				iColumn = (*(*struct {
					FleftColumn int32
					FiField     int32
				})(unsafe.Pointer(pOrTerm + 24))).FleftColumn
				iCursor = (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor
				pLeft = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft
				break
				goto _11
			_11:
				;
				i--
				pOrTerm += 48
			}
			if i < 0 {
				/* No candidate table+column was found.  This can only occur
				 ** on the second iteration */
				break
			}
			/* We have found a candidate table and column.  Check to see if that
			 ** table and column is common to every term in the OR clause */
			okToChngToIN = int32(1)
			for {
				if !(i >= 0 && okToChngToIN != 0) {
					break
				}
				if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor != iCursor {
					p14 = pOrTerm + 10
					*(*Tu16)(unsafe.Pointer(p14)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p14))) & ^libc.Int32FromInt32(TERM_OK))
				} else {
					if (*(*struct {
						FleftColumn int32
						FiField     int32
					})(unsafe.Pointer(pOrTerm + 24))).FleftColumn != iColumn || iColumn == -int32(2) && _sqlite3ExprCompare(tls, pParse, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft, pLeft, -int32(1)) != 0 {
						okToChngToIN = 0
					} else {
						/* If the right-hand side is also a column, then the affinities
						 ** of both right and left sides must be such that no type
						 ** conversions are required on the right.  (Ticket #2249)
						 */
						affRight = int32(_sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpRight))
						affLeft = int32(_sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft))
						if affRight != 0 && affRight != affLeft {
							okToChngToIN = 0
						} else {
							p15 = pOrTerm + 10
							*(*Tu16)(unsafe.Pointer(p15)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p15))) | libc.Int32FromInt32(TERM_OK))
						}
					}
				}
				goto _13
			_13:
				;
				i--
				pOrTerm += 48
			}
			goto _10
		_10:
			;
			j1++
		}
		/* At this point, okToChngToIN is true if original pTerm satisfies
		 ** case 1.  In that case, construct a new virtual term that is
		 ** pTerm converted into an IN operator.
		 */
		if okToChngToIN != 0 { /* A transient duplicate expression */
			pList = uintptr(0)  /* The RHS of the IN operator */
			pLeft1 = uintptr(0) /* The complete IN operator */
			i = (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm - int32(1)
			pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa
			for {
				if !(i >= 0) {
					break
				}
				if int32((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&int32(TERM_OK) == 0 {
					goto _16
				}
				pDup = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpRight, 0)
				pList = _sqlite3ExprListAppend(tls, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse, pList, pDup)
				pLeft1 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft
				goto _16
			_16:
				;
				i--
				pOrTerm += 48
			}
			pDup = _sqlite3ExprDup(tls, db, pLeft1, 0)
			pNew = _sqlite3PExpr(tls, pParse, int32(TK_IN), pDup, uintptr(0))
			if pNew != 0 {
				_transferJoinMarkings(tls, pNew, pExpr)
				*(*uintptr)(unsafe.Pointer(pNew + 20)) = pList
				idxNew = _whereClauseInsert(tls, pWC, pNew, uint16(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
				_exprAnalyze(tls, pSrc, pWC, idxNew)
				/* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
				_markTermAsChild(tls, pWC, idxNew, idxTerm)
			} else {
				_sqlite3ExprListDelete(tls, db, pList)
			}
		}
	}
}

// C documentation
//
//	/*
//	** We already know that pExpr is a binary operator where both operands are
//	** column references.  This routine checks to see if pExpr is an equivalence
//	** relation:
//	**   1.  The SQLITE_Transitive optimization must be enabled
//	**   2.  Must be either an == or an IS operator
//	**   3.  Not originating in the ON clause of an OUTER JOIN
//	**   4.  The affinities of A and B must be compatible
//	**   5a. Both operands use the same collating sequence OR
//	**   5b. The overall collating sequence is BINARY
//	** If this routine returns TRUE, that means that the RHS can be substituted
//	** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
//	** This is an optimization.  No harm comes from returning 0.  But if 1 is
//	** returned when it should not be, then incorrect answers might result.
//	*/
func _termIsEquivalence(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
	var aff1, aff2 int8
	var pColl uintptr
	_, _, _ = aff1, aff2, pColl
	if !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_Transitive)) == libc.Uint32FromInt32(0)) {
		return 0
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_EQ) && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IS) {
		return 0
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
		return 0
	}
	aff1 = _sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
	aff2 = _sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
	if int32(int32(aff1)) != int32(int32(aff2)) && (!(int32(aff1) >= libc.Int32FromInt32(SQLITE_AFF_NUMERIC)) || !(int32(aff2) >= libc.Int32FromInt32(SQLITE_AFF_NUMERIC))) {
		return 0
	}
	pColl = _sqlite3ExprCompareCollSeq(tls, pParse, pExpr)
	if _sqlite3IsBinary(tls, pColl) != 0 {
		return int32(1)
	}
	return _sqlite3ExprCollSeqMatch(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
}

// 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 |= _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpEList)
		mask |= _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpGroupBy)
		mask |= _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpOrderBy)
		mask |= _sqlite3WhereExprUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpWhere)
		mask |= _sqlite3WhereExprUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpHaving)
		if pSrc != uintptr(0) {
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
					break
				}
				mask |= _exprSelectUsage(tls, pMaskSet, (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72))).FpSelect)
				if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 36 + 4))&0x400>>10)) == 0 {
					mask |= _sqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 48)))
				}
				if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 36 + 4))&0x4>>2)) != 0 {
					mask |= _sqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*72 + 64)))
				}
				goto _1
			_1:
				;
				i++
			}
		}
		pS = (*TSelect)(unsafe.Pointer(pS)).FpPrior
	}
	return mask
}

// C documentation
//
//	/*
//	** Expression pExpr is one operand of a comparison operator that might
//	** be useful for indexing.  This routine checks to see if pExpr appears
//	** in any index.  Return TRUE (1) if pExpr is an indexed term and return
//	** FALSE (0) if not.  If TRUE is returned, also set aiCurCol[0] to the cursor
//	** number of the table that is indexed and aiCurCol[1] to the column number
//	** of the column that is indexed, or XN_EXPR (-2) if an expression is being
//	** indexed.
//	**
//	** If pExpr is a TK_COLUMN column reference, then this routine always returns
//	** true even if that particular column is not indexed, because the column
//	** might be added to an automatic index later.
//	*/
func _exprMightBeIndexed2(tls *libc.TLS, pFrom uintptr, aiCurCol uintptr, pExpr uintptr, j int32) (r int32) {
	var i, iCur, v1 int32
	var pIdx uintptr
	_, _, _, _ = i, iCur, pIdx, v1
	for {
		iCur = (*(*TSrcItem)(unsafe.Pointer(pFrom + 8 + uintptr(j)*72))).FiCursor
		pIdx = (*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pFrom + 8 + uintptr(j)*72))).FpTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr == uintptr(0) {
				goto _3
			}
			i = 0
			for {
				if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) != -int32(2) {
					goto _4
				}
				if _sqlite3ExprCompareSkip(tls, pExpr, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(i)*20))).FpExpr, iCur) == 0 && !(_sqlite3ExprIsConstant(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(i)*20))).FpExpr) != 0) {
					*(*int32)(unsafe.Pointer(aiCurCol)) = iCur
					*(*int32)(unsafe.Pointer(aiCurCol + 1*4)) = -int32(2)
					return int32(1)
				}
				goto _4
			_4:
				;
				i++
			}
			goto _3
		_3:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
		goto _2
	_2:
		;
		j++
		v1 = j
		if !(v1 < (*TSrcList)(unsafe.Pointer(pFrom)).FnSrc) {
			break
		}
	}
	return 0
}

func _exprMightBeIndexed(tls *libc.TLS, pFrom uintptr, aiCurCol uintptr, pExpr uintptr, op int32) (r int32) {
	var i int32
	var pIdx uintptr
	_, _ = i, pIdx
	/* If this expression is a vector to the left or right of a
	 ** inequality constraint (>, <, >= or <=), perform the processing
	 ** on the first element of the vector.  */
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VECTOR) && (op >= int32(TK_GT) && op <= int32(TK_GE)) {
		pExpr = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr
	}
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) {
		*(*int32)(unsafe.Pointer(aiCurCol)) = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
		*(*int32)(unsafe.Pointer(aiCurCol + 1*4)) = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
		return int32(1)
	}
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pFrom)).FnSrc) {
			break
		}
		pIdx = (*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pFrom + 8 + uintptr(i)*72))).FpTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr != 0 {
				return _exprMightBeIndexed2(tls, pFrom, aiCurCol, pExpr, i)
			}
			goto _2
		_2:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** The input to this routine is an WhereTerm structure with only the
//	** "pExpr" field filled in.  The job of this routine is to analyze the
//	** subexpression and populate all the other fields of the WhereTerm
//	** structure.
//	**
//	** If the expression is of the form "<expr> <op> X" it gets commuted
//	** to the standard form of "X <op> <expr>".
//	**
//	** If the expression is of the form "X <op> Y" where both X and Y are
//	** columns, then the original expression is unchanged and a new virtual
//	** term of the form "Y <op> X" is added to the WHERE clause and
//	** analyzed separately.  The original term is marked with TERM_COPIED
//	** and the new term is marked with TERM_DYNAMIC (because it's pExpr
//	** needs to be freed with the WhereClause) and TERM_VIRTUAL (because it
//	** is a commuted copy of a prior term.)  The original term has nChild=1
//	** and the copy has idxParent set to the index of the original term.
//	*/
func _exprAnalyze(tls *libc.TLS, pSrc uintptr, pWC uintptr, idxTerm int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var c, v12 int8
	var c1 Tu8
	var db, pC, pDup, pExpr, pLeft, pLeft1, pLeft2, pLeft3, pList, pMaskSet, pNew, pNew1, pNewExpr, pNewExpr1, pNewExpr11, pNewExpr2, pNewExpr21, pNewTerm, pNewTerm1, pParse, pRight, pRight1, pStr2, pTerm, pWInfo, t, zCollSeqName, v13, p1, p10, p17, p20, p3, p4, p5, p6, p7, p9 uintptr
	var eExtraOp, opMask, wtFlags Tu16
	var extraRight, prereqAll, prereqColumn, prereqExpr, prereqLeft, x TBitmask
	var i, i1, i2, i3, idxNew, idxNew1, idxNew11, idxNew2, idxNew21, idxNew3, idxNew4, idxNew5, nLeft, op, res, v14, v19, v2 int32
	var v15 bool
	var _ /* aiCurCol at bp+16 */ [2]int32
	var _ /* eOp2 at bp+12 */ uint8
	var _ /* isComplete at bp+4 */ int32
	var _ /* noCase at bp+8 */ int32
	var _ /* pLeft at bp+28 */ uintptr
	var _ /* pRight at bp+24 */ uintptr
	var _ /* pStr1 at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, c1, db, eExtraOp, extraRight, i, i1, i2, i3, idxNew, idxNew1, idxNew11, idxNew2, idxNew21, idxNew3, idxNew4, idxNew5, nLeft, op, opMask, pC, pDup, pExpr, pLeft, pLeft1, pLeft2, pLeft3, pList, pMaskSet, pNew, pNew1, pNewExpr, pNewExpr1, pNewExpr11, pNewExpr2, pNewExpr21, pNewTerm, pNewTerm1, pParse, pRight, pRight1, pStr2, pTerm, pWInfo, prereqAll, prereqColumn, prereqExpr, prereqLeft, res, t, wtFlags, x, zCollSeqName, v12, v13, v14, v15, v19, v2, p1, p10, p17, p20, p3, p4, p5, p6, p7, p9
	pWInfo = (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo  /* Prerequisites of pExpr */
	extraRight = uint64(0)                                 /* Extra dependencies on LEFT JOIN */
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)           /* RHS of LIKE/GLOB operator */
	*(*int32)(unsafe.Pointer(bp + 4)) = 0                  /* RHS of LIKE/GLOB ends with wildcard */
	*(*int32)(unsafe.Pointer(bp + 8)) = 0                  /* Top-level operator.  pExpr->op */
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse /* Parsing context */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb             /* Database connection */
	*(*uint8)(unsafe.Pointer(bp + 12)) = uint8(0)          /* Number of elements on left side vector */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
	pMaskSet = pWInfo + 496
	pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
	/* Because malloc() has not failed */
	(*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect = 0
	prereqLeft = _sqlite3WhereExprUsage(tls, pMaskSet, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
	op = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop)
	if op == int32(TK_IN) {
		if _sqlite3ExprCheckIN(tls, pParse, pExpr) != 0 {
			return
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = _exprSelectUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
		} else {
			(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = _sqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
		}
		prereqAll = prereqLeft | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
	} else {
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = _sqlite3WhereExprUsage(tls, pMaskSet, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft == uintptr(0) || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_xIsSelect)|libc.Int32FromInt32(EP_IfNullRow)) != uint32(0) || *(*uintptr)(unsafe.Pointer(pExpr + 20)) != uintptr(0) {
			prereqAll = _sqlite3WhereExprUsageNN(tls, pMaskSet, pExpr)
		} else {
			prereqAll = prereqLeft | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
		}
	}
	if (*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect != 0 {
		p1 = pTerm + 10
		*(*Tu16)(unsafe.Pointer(p1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p1))) | libc.Int32FromInt32(TERM_VARSELECT))
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
		x = _sqlite3WhereGetMask(tls, pMaskSet, *(*int32)(unsafe.Pointer(pExpr + 36)))
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
			prereqAll |= x
			extraRight = x - uint64(1) /* ON clause terms may not be used with an index
			 ** on left table of a LEFT JOIN.  Ticket #3015 */
			if prereqAll>>libc.Int32FromInt32(1) >= x {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23781, 0)
				return
			}
		} else {
			if prereqAll>>libc.Int32FromInt32(1) >= x {
				/* The ON clause of an INNER JOIN references a table to its right.
				 ** Most other SQL database engines raise an error.  But SQLite versions
				 ** 3.0 through 3.38 just put the ON clause constraint into the WHERE
				 ** clause and carried on.   Beginning with 3.39, raise an error only
				 ** if there is a RIGHT or FULL JOIN in the query.  This makes SQLite
				 ** more like other systems, and also preserves legacy. */
				if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc > 0 && int32((*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23781, 0)
					return
				}
				*(*Tu32)(unsafe.Pointer(pExpr + 4)) &= uint32(^libc.Int32FromInt32(EP_InnerON))
			}
		}
	}
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll = prereqAll
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = -int32(1)
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FiParent = -int32(1)
	(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(0)
	if _allowedOp(tls, op) != 0 {
		pLeft = _sqlite3ExprSkipCollate(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		pRight = _sqlite3ExprSkipCollate(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&prereqLeft == uint64(0) {
			v2 = int32(WO_ALL)
		} else {
			v2 = int32(WO_EQUIV)
		}
		opMask = uint16(v2)
		if (*(*struct {
			FleftColumn int32
			FiField     int32
		})(unsafe.Pointer(pTerm + 24))).FiField > 0 {
			pLeft = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 20)) + 8 + uintptr((*(*struct {
				FleftColumn int32
				FiField     int32
			})(unsafe.Pointer(pTerm + 24))).FiField-int32(1))*20))).FpExpr
		}
		if _exprMightBeIndexed(tls, pSrc, bp+16, pLeft, op) != 0 {
			(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = (*(*[2]int32)(unsafe.Pointer(bp + 16)))[0]
			(*(*struct {
				FleftColumn int32
				FiField     int32
			})(unsafe.Pointer(pTerm + 24))).FleftColumn = (*(*[2]int32)(unsafe.Pointer(bp + 16)))[int32(1)]
			(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(int32(_operatorMask(tls, op)) & int32(int32(opMask)))
		}
		if op == int32(TK_IS) {
			p3 = pTerm + 10
			*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) | libc.Int32FromInt32(TERM_IS))
		}
		if pRight != 0 && _exprMightBeIndexed(tls, pSrc, bp+16, pRight, op) != 0 && !((*TExpr)(unsafe.Pointer(pRight)).Fflags&uint32(libc.Int32FromInt32(EP_FixedCol)) != libc.Uint32FromInt32(0)) {
			eExtraOp = uint16(0) /* Extra bits for pNew->eOperator */
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor >= 0 {
				pDup = _sqlite3ExprDup(tls, db, pExpr, 0)
				if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
					_sqlite3ExprDelete(tls, db, pDup)
					return
				}
				idxNew = _whereClauseInsert(tls, pWC, pDup, uint16(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
				if idxNew == 0 {
					return
				}
				pNew = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew)*48
				_markTermAsChild(tls, pWC, idxNew, idxTerm)
				if op == int32(TK_IS) {
					p4 = pNew + 10
					*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(TERM_IS))
				}
				pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
				p5 = pTerm + 10
				*(*Tu16)(unsafe.Pointer(p5)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p5))) | libc.Int32FromInt32(TERM_COPIED))
				if _termIsEquivalence(tls, pParse, pDup) != 0 {
					p6 = pTerm + 12
					*(*Tu16)(unsafe.Pointer(p6)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p6))) | libc.Int32FromInt32(WO_EQUIV))
					eExtraOp = uint16(WO_EQUIV)
				}
			} else {
				pDup = pExpr
				pNew = pTerm
			}
			p7 = pNew + 10
			*(*Tu16)(unsafe.Pointer(p7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p7))) | int32(_exprCommute(tls, pParse, pDup)))
			(*TWhereTerm)(unsafe.Pointer(pNew)).FleftCursor = (*(*[2]int32)(unsafe.Pointer(bp + 16)))[0]
			(*(*struct {
				FleftColumn int32
				FiField     int32
			})(unsafe.Pointer(pNew + 24))).FleftColumn = (*(*[2]int32)(unsafe.Pointer(bp + 16)))[int32(1)]
			(*TWhereTerm)(unsafe.Pointer(pNew)).FprereqRight = prereqLeft | extraRight
			(*TWhereTerm)(unsafe.Pointer(pNew)).FprereqAll = prereqAll
			(*TWhereTerm)(unsafe.Pointer(pNew)).FeOperator = uint16((int32(_operatorMask(tls, int32((*TExpr)(unsafe.Pointer(pDup)).Fop))) + int32(int32(eExtraOp))) & int32(int32(opMask)))
		} else {
			if op == int32(TK_ISNULL) && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) && 0 == _sqlite3ExprCanBeNull(tls, pLeft) {
				(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_TRUEFALSE) /* See tag-20230504-1 */
				*(*uintptr)(unsafe.Pointer(pExpr + 8)) = __ccgo_ts + 9325
				*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_IsFalse))
				(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll = uint64(0)
				(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(0)
			}
		}
	} else {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_BETWEEN) && int32((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) {
			pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
			i = 0
			for {
				if !(i < int32(2)) {
					break
				}
				pNewExpr = _sqlite3PExpr(tls, pParse, int32(_ops[i]), _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, 0), _sqlite3ExprDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr, 0))
				_transferJoinMarkings(tls, pNewExpr, pExpr)
				idxNew1 = _whereClauseInsert(tls, pWC, pNewExpr, uint16(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
				_exprAnalyze(tls, pSrc, pWC, idxNew1)
				pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
				_markTermAsChild(tls, pWC, idxNew1, idxTerm)
				goto _8
			_8:
				;
				i++
			}
		} else {
			if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_OR) {
				_exprAnalyzeOrTerm(tls, pSrc, pWC, idxTerm)
				pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
			} else {
				if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NOTNULL) {
					if int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).FiColumn) >= 0 && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) {
						pLeft1 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
						pNewExpr1 = _sqlite3PExpr(tls, pParse, int32(TK_GT), _sqlite3ExprDup(tls, db, pLeft1, 0), _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0))
						idxNew2 = _whereClauseInsert(tls, pWC, pNewExpr1, uint16(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)|libc.Int32FromInt32(TERM_VNULL)))
						if idxNew2 != 0 {
							pNewTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew2)*48
							(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FprereqRight = uint64(0)
							(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FleftCursor = (*TExpr)(unsafe.Pointer(pLeft1)).FiTable
							(*(*struct {
								FleftColumn int32
								FiField     int32
							})(unsafe.Pointer(pNewTerm + 24))).FleftColumn = int32((*TExpr)(unsafe.Pointer(pLeft1)).FiColumn)
							(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FeOperator = uint16(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_GT) - libc.Int32FromInt32(TK_EQ)))
							_markTermAsChild(tls, pWC, idxNew2, idxTerm)
							pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
							p9 = pTerm + 10
							*(*Tu16)(unsafe.Pointer(p9)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p9))) | libc.Int32FromInt32(TERM_COPIED))
							(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FprereqAll = (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll
						}
					}
				} else {
					if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_FUNCTION) && int32((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) && _isLikeOrGlob(tls, pParse, pExpr, bp, bp+4, bp+8) != 0 { /* Name of collating sequence */
						wtFlags = uint16(libc.Int32FromInt32(TERM_LIKEOPT) | libc.Int32FromInt32(TERM_VIRTUAL) | libc.Int32FromInt32(TERM_DYNAMIC))
						pLeft2 = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8 + 1*20))).FpExpr
						pStr2 = _sqlite3ExprDup(tls, db, *(*uintptr)(unsafe.Pointer(bp)), 0)
						/* Convert the lower bound to upper-case and the upper bound to
						 ** lower-case (upper-case is less than lower-case in ASCII) so that
						 ** the range constraints also work for BLOBs
						 */
						if *(*int32)(unsafe.Pointer(bp + 8)) != 0 && !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
							p10 = pTerm + 10
							*(*Tu16)(unsafe.Pointer(p10)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p10))) | libc.Int32FromInt32(TERM_LIKE))
							i1 = 0
							for {
								v12 = *(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 8)) + uintptr(i1)))
								c = v12
								if !(int32(v12) != 0) {
									break
								}
								*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 8)) + uintptr(i1))) = int8(int32(c) & ^(int32(_sqlite3CtypeMap[uint8(c)]) & libc.Int32FromInt32(0x20)))
								*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pStr2 + 8)) + uintptr(i1))) = int8(_sqlite3UpperToLower[uint8(c)])
								goto _11
							_11:
								;
								i1++
							}
						}
						if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) { /* Last character before the first wildcard */
							pC = *(*uintptr)(unsafe.Pointer(pStr2 + 8)) + uintptr(_sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pStr2 + 8)))-int32(1))
							c1 = *(*Tu8)(unsafe.Pointer(pC))
							if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
								/* The point is to increment the last character before the first
								 ** wildcard.  But if we increment '@', that will push it into the
								 ** alphabetic range where case conversions will mess up the
								 ** inequality.  To avoid this, make sure to also run the full
								 ** LIKE on all candidate expressions by clearing the isComplete flag
								 */
								if int32(int32(c1)) == libc.Int32FromUint8('A')-libc.Int32FromInt32(1) {
									*(*int32)(unsafe.Pointer(bp + 4)) = 0
								}
								c1 = _sqlite3UpperToLower[c1]
							}
							*(*Tu8)(unsafe.Pointer(pC)) = uint8(int32(int32(c1)) + int32(1))
						}
						if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
							v13 = __ccgo_ts + 23822
						} else {
							v13 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
						}
						zCollSeqName = v13
						pNewExpr11 = _sqlite3ExprDup(tls, db, pLeft2, 0)
						pNewExpr11 = _sqlite3PExpr(tls, pParse, int32(TK_GE), _sqlite3ExprAddCollateString(tls, pParse, pNewExpr11, zCollSeqName), *(*uintptr)(unsafe.Pointer(bp)))
						_transferJoinMarkings(tls, pNewExpr11, pExpr)
						idxNew11 = _whereClauseInsert(tls, pWC, pNewExpr11, wtFlags)
						pNewExpr21 = _sqlite3ExprDup(tls, db, pLeft2, 0)
						pNewExpr21 = _sqlite3PExpr(tls, pParse, int32(TK_LT), _sqlite3ExprAddCollateString(tls, pParse, pNewExpr21, zCollSeqName), pStr2)
						_transferJoinMarkings(tls, pNewExpr21, pExpr)
						idxNew21 = _whereClauseInsert(tls, pWC, pNewExpr21, wtFlags)
						_exprAnalyze(tls, pSrc, pWC, idxNew11)
						_exprAnalyze(tls, pSrc, pWC, idxNew21)
						pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
						if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
							_markTermAsChild(tls, pWC, idxNew11, idxTerm)
							_markTermAsChild(tls, pWC, idxNew21, idxTerm)
						}
					}
				}
			}
		}
	}
	/* If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create
	 ** new terms for each component comparison - "a = ?" and "b = ?".  The
	 ** new terms completely replace the original vector comparison, which is
	 ** no longer used.
	 **
	 ** This is only required if at least one side of the comparison operation
	 ** is not a sub-select.
	 **
	 ** tag-20220128a
	 */
	if v15 = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_EQ) || int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IS); v15 {
		v14 = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		nLeft = v14
	}
	if v15 && v14 > int32(1) && _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight) == nLeft && ((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).Fflags&uint32(EP_xIsSelect) == uint32(0) || (*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpRight)).Fflags&uint32(EP_xIsSelect) == uint32(0)) && int32((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) {
		i2 = 0
		for {
			if !(i2 < nLeft) {
				break
			}
			pLeft3 = _sqlite3ExprForVectorField(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, i2, nLeft)
			pRight1 = _sqlite3ExprForVectorField(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, i2, nLeft)
			pNew1 = _sqlite3PExpr(tls, pParse, int32((*TExpr)(unsafe.Pointer(pExpr)).Fop), pLeft3, pRight1)
			_transferJoinMarkings(tls, pNew1, pExpr)
			idxNew3 = _whereClauseInsert(tls, pWC, pNew1, uint16(libc.Int32FromInt32(TERM_DYNAMIC)|libc.Int32FromInt32(TERM_SLICE)))
			_exprAnalyze(tls, pSrc, pWC, idxNew3)
			goto _16
		_16:
			;
			i2++
		}
		pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
		p17 = pTerm + 10
		*(*Tu16)(unsafe.Pointer(p17)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p17))) | (libc.Int32FromInt32(TERM_CODED) | libc.Int32FromInt32(TERM_VIRTUAL))) /* Disable the original */
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(WO_ROWVAL)
	} else {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IN) && (*(*struct {
			FleftColumn int32
			FiField     int32
		})(unsafe.Pointer(pTerm + 24))).FiField == 0 && int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == int32(TK_VECTOR) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) && ((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpPrior == uintptr(0) || (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FselFlags&uint32(SF_Values) != 0) && (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpWin == uintptr(0) && int32((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) {
			i3 = 0
			for {
				if !(i3 < _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)) {
					break
				}
				idxNew4 = _whereClauseInsert(tls, pWC, pExpr, uint16(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_SLICE)))
				*(*int32)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew4)*48 + 24 + 4)) = i3 + int32(1)
				_exprAnalyze(tls, pSrc, pWC, idxNew4)
				_markTermAsChild(tls, pWC, idxNew4, idxTerm)
				goto _18
			_18:
				;
				i3++
			}
		} else {
			if int32((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) {
				*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
				*(*uintptr)(unsafe.Pointer(bp + 28)) = uintptr(0)
				res = _isAuxiliaryVtabOperator(tls, db, pExpr, bp+12, bp+28, bp+24)
				for {
					v19 = res
					res--
					if !(v19 > 0) {
						break
					}
					prereqExpr = _sqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(bp + 24)))
					prereqColumn = _sqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(bp + 28)))
					if prereqExpr&prereqColumn == uint64(0) {
						pNewExpr2 = _sqlite3PExpr(tls, pParse, int32(TK_MATCH), uintptr(0), _sqlite3ExprDup(tls, db, *(*uintptr)(unsafe.Pointer(bp + 24)), 0))
						if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) && pNewExpr2 != 0 {
							*(*Tu32)(unsafe.Pointer(pNewExpr2 + 4)) |= uint32(libc.Int32FromInt32(EP_OuterON))
							*(*int32)(unsafe.Pointer(pNewExpr2 + 36)) = *(*int32)(unsafe.Pointer(pExpr + 36))
						}
						idxNew5 = _whereClauseInsert(tls, pWC, pNewExpr2, uint16(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
						pNewTerm1 = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew5)*48
						(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FprereqRight = prereqExpr
						(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FleftCursor = (*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 28)))).FiTable
						(*(*struct {
							FleftColumn int32
							FiField     int32
						})(unsafe.Pointer(pNewTerm1 + 24))).FleftColumn = int32((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 28)))).FiColumn)
						(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FeOperator = uint16(WO_AUX)
						(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FeMatchOp = *(*uint8)(unsafe.Pointer(bp + 12))
						_markTermAsChild(tls, pWC, idxNew5, idxTerm)
						pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
						p20 = pTerm + 10
						*(*Tu16)(unsafe.Pointer(p20)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p20))) | libc.Int32FromInt32(TERM_COPIED))
						(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FprereqAll = (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll
					}
					t = *(*uintptr)(unsafe.Pointer(bp + 28))
					*(*uintptr)(unsafe.Pointer(bp + 28)) = *(*uintptr)(unsafe.Pointer(bp + 24))
					*(*uintptr)(unsafe.Pointer(bp + 24)) = t
				}
			}
		}
	}
	/* Prevent ON clause terms of a LEFT JOIN from being used to drive
	 ** an index for tables to the left of the join.
	 */
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
	*(*TBitmask)(unsafe.Pointer(pTerm + 32)) |= extraRight
}

var _ops = [2]Tu8{
	0: uint8(TK_GE),
	1: uint8(TK_LE),
}

/***************************************************************************
** Routines with file scope above.  Interface to the rest of the where.c
** subsystem follows.
***************************************************************************/

// C documentation
//
//	/*
//	** This routine identifies subexpressions in the WHERE clause where
//	** each subexpression is separated by the AND operator or some other
//	** operator specified in the op parameter.  The WhereClause structure
//	** is filled with pointers to subexpressions.  For example:
//	**
//	**    WHERE  a=='hello' AND coalesce(b,11)<10 AND (c+12!=d OR c==22)
//	**           \________/     \_______________/     \________________/
//	**            slot[0]            slot[1]               slot[2]
//	**
//	** The original WHERE clause in pExpr is unaltered.  All this routine
//	** does is make slot[] entries point to substructure within pExpr.
//	**
//	** In the previous sentence and in the diagram, "slot[]" refers to
//	** the WhereClause.a[] array.  The slot[] array grows as needed to contain
//	** all terms of the WHERE clause.
//	*/
func _sqlite3WhereSplit(tls *libc.TLS, pWC uintptr, pExpr uintptr, op Tu8) {
	var pE2 uintptr
	_ = pE2
	pE2 = _sqlite3ExprSkipCollateAndLikely(tls, pExpr)
	(*TWhereClause)(unsafe.Pointer(pWC)).Fop = op
	if pE2 == uintptr(0) {
		return
	}
	if int32((*TExpr)(unsafe.Pointer(pE2)).Fop) != int32(int32(op)) {
		_whereClauseInsert(tls, pWC, pExpr, uint16(0))
	} else {
		_sqlite3WhereSplit(tls, pWC, (*TExpr)(unsafe.Pointer(pE2)).FpLeft, op)
		_sqlite3WhereSplit(tls, pWC, (*TExpr)(unsafe.Pointer(pE2)).FpRight, op)
	}
}

// C documentation
//
//	/*
//	** Add either a LIMIT (if eMatchOp==SQLITE_INDEX_CONSTRAINT_LIMIT) or
//	** OFFSET (if eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET) term to the
//	** where-clause passed as the first argument. The value for the term
//	** is found in register iReg.
//	**
//	** In the common case where the value is a simple integer
//	** (example: "LIMIT 5 OFFSET 10") then the expression codes as a
//	** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value().
//	** If not, then it codes as a TK_REGISTER expression.
//	*/
func _whereAddLimitExpr(tls *libc.TLS, pWC uintptr, iReg int32, pExpr uintptr, iCsr int32, eMatchOp int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pNew, pParse, pTerm, pVal, pVal1 uintptr
	var idx int32
	var _ /* iVal at bp+0 */ int32
	_, _, _, _, _, _, _ = db, idx, pNew, pParse, pTerm, pVal, pVal1
	pParse = (*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	*(*int32)(unsafe.Pointer(bp)) = 0
	if _sqlite3ExprIsInteger(tls, pExpr, bp) != 0 && *(*int32)(unsafe.Pointer(bp)) >= 0 {
		pVal = _sqlite3Expr(tls, db, int32(TK_INTEGER), uintptr(0))
		if pVal == uintptr(0) {
			return
		}
		*(*Tu32)(unsafe.Pointer(pVal + 4)) |= uint32(libc.Int32FromInt32(EP_IntValue))
		*(*int32)(unsafe.Pointer(pVal + 8)) = *(*int32)(unsafe.Pointer(bp))
		pNew = _sqlite3PExpr(tls, pParse, int32(TK_MATCH), uintptr(0), pVal)
	} else {
		pVal1 = _sqlite3Expr(tls, db, int32(TK_REGISTER), uintptr(0))
		if pVal1 == uintptr(0) {
			return
		}
		(*TExpr)(unsafe.Pointer(pVal1)).FiTable = iReg
		pNew = _sqlite3PExpr(tls, pParse, int32(TK_MATCH), uintptr(0), pVal1)
	}
	if pNew != 0 {
		idx = _whereClauseInsert(tls, pWC, pNew, uint16(libc.Int32FromInt32(TERM_DYNAMIC)|libc.Int32FromInt32(TERM_VIRTUAL)))
		pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idx)*48
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = iCsr
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(WO_AUX)
		(*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp = uint8(uint8(eMatchOp))
	}
}

// C documentation
//
//	/*
//	** Possibly add terms corresponding to the LIMIT and OFFSET clauses of the
//	** SELECT statement passed as the second argument. These terms are only
//	** added if:
//	**
//	**   1. The SELECT statement has a LIMIT clause, and
//	**   2. The SELECT statement is not an aggregate or DISTINCT query, and
//	**   3. The SELECT statement has exactly one object in its from clause, and
//	**      that object is a virtual table, and
//	**   4. There are no terms in the WHERE clause that will not be passed
//	**      to the virtual table xBestIndex method.
//	**   5. The ORDER BY clause, if any, will be made available to the xBestIndex
//	**      method.
//	**
//	** LIMIT and OFFSET terms are ignored by most of the planner code. They
//	** exist only so that they may be passed to the xBestIndex method of the
//	** single virtual table in the FROM clause of the SELECT.
//	*/
func _sqlite3WhereAddLimit(tls *libc.TLS, pWC uintptr, p uintptr) {
	var iCsr, ii int32
	var pExpr, pOrderBy uintptr
	_, _, _, _ = iCsr, ii, pExpr, pOrderBy
	/* 1 -- checked by caller */
	if (*TSelect)(unsafe.Pointer(p)).FpGroupBy == uintptr(0) && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) == uint32(0) && ((*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc == int32(1) && int32((*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpTab)).FeTabType) == int32(TABTYP_VTAB)) {
		pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
		iCsr = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FiCursor
		/* Check condition (4). Return early if it is not met. */
		ii = 0
		for {
			if !(ii < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
				break
			}
			if int32((*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(ii)*48))).FwtFlags)&int32(TERM_CODED) != 0 {
				/* This term is a vector operation that has been decomposed into
				 ** other, subsequent terms.  It can be ignored. See tag-20220128a */
				goto _1
			}
			if (*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(ii)*48))).FnChild != 0 {
				/* If this term has child terms, then they are also part of the
				 ** pWC->a[] array. So this term can be ignored, as a LIMIT clause
				 ** will only be added if each of the child terms passes the
				 ** (leftCursor==iCsr) test below.  */
				goto _1
			}
			if (*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(ii)*48))).FleftCursor != iCsr {
				return
			}
			if (*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(ii)*48))).FprereqRight != uint64(0) {
				return
			}
			goto _1
		_1:
			;
			ii++
		}
		/* Check condition (5). Return early if it is not met. */
		if pOrderBy != 0 {
			ii = 0
			for {
				if !(ii < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
					break
				}
				pExpr = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(ii)*20))).FpExpr
				if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLUMN) {
					return
				}
				if (*TExpr)(unsafe.Pointer(pExpr)).FiTable != iCsr {
					return
				}
				if int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(ii)*20))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
					return
				}
				goto _2
			_2:
				;
				ii++
			}
		}
		/* All conditions are met. Add the terms to the where-clause object. */
		if (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Compound) == uint32(0) {
			_whereAddLimitExpr(tls, pWC, (*TSelect)(unsafe.Pointer(p)).FiOffset, (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpLimit)).FpRight, iCsr, int32(SQLITE_INDEX_CONSTRAINT_OFFSET))
		}
		if (*TSelect)(unsafe.Pointer(p)).FiOffset == 0 || (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Compound) == uint32(0) {
			_whereAddLimitExpr(tls, pWC, (*TSelect)(unsafe.Pointer(p)).FiLimit, (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpLimit)).FpLeft, iCsr, int32(SQLITE_INDEX_CONSTRAINT_LIMIT))
		}
	}
}

// C documentation
//
//	/*
//	** Initialize a preallocated WhereClause structure.
//	*/
func _sqlite3WhereClauseInit(tls *libc.TLS, pWC uintptr, pWInfo uintptr) {
	(*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo = pWInfo
	(*TWhereClause)(unsafe.Pointer(pWC)).FhasOr = uint8(0)
	(*TWhereClause)(unsafe.Pointer(pWC)).FpOuter = uintptr(0)
	(*TWhereClause)(unsafe.Pointer(pWC)).FnTerm = 0
	(*TWhereClause)(unsafe.Pointer(pWC)).FnBase = 0
	(*TWhereClause)(unsafe.Pointer(pWC)).FnSlot = int32(libc.Uint32FromInt64(384) / libc.Uint32FromInt64(48))
	(*TWhereClause)(unsafe.Pointer(pWC)).Fa = pWC + 32
}

// C documentation
//
//	/*
//	** Deallocate a WhereClause structure.  The WhereClause structure
//	** itself is not freed.  This routine is the inverse of
//	** sqlite3WhereClauseInit().
//	*/
func _sqlite3WhereClauseClear(tls *libc.TLS, pWC uintptr) {
	var a, aLast, db uintptr
	_, _, _ = a, aLast, db
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)).Fdb
	if (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm > 0 {
		a = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
		aLast = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm-int32(1))*48
		for int32(1) != 0 {
			if int32((*TWhereTerm)(unsafe.Pointer(a)).FwtFlags)&int32(TERM_DYNAMIC) != 0 {
				_sqlite3ExprDelete(tls, db, (*TWhereTerm)(unsafe.Pointer(a)).FpExpr)
			}
			if int32((*TWhereTerm)(unsafe.Pointer(a)).FwtFlags)&(libc.Int32FromInt32(TERM_ORINFO)|libc.Int32FromInt32(TERM_ANDINFO)) != 0 {
				if int32((*TWhereTerm)(unsafe.Pointer(a)).FwtFlags)&int32(TERM_ORINFO) != 0 {
					_whereOrInfoDelete(tls, db, *(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(a)).Fu)))
				} else {
					_whereAndInfoDelete(tls, db, *(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(a)).Fu)))
				}
			}
			if a == aLast {
				break
			}
			a += 48
		}
	}
}

// C documentation
//
//	/*
//	** These routines walk (recursively) an expression tree and generate
//	** a bitmask indicating which tables are used in that expression
//	** tree.
//	**
//	** sqlite3WhereExprUsage(MaskSet, Expr) ->
//	**
//	**       Return a Bitmask of all tables referenced by Expr.  Expr can be
//	**       be NULL, in which case 0 is returned.
//	**
//	** sqlite3WhereExprUsageNN(MaskSet, Expr) ->
//	**
//	**       Same as sqlite3WhereExprUsage() except that Expr must not be
//	**       NULL.  The "NN" suffix on the name stands for "Not Null".
//	**
//	** sqlite3WhereExprListUsage(MaskSet, ExprList) ->
//	**
//	**       Return a Bitmask of all tables referenced by every expression
//	**       in the expression list ExprList.  ExprList can be NULL, in which
//	**       case 0 is returned.
//	**
//	** sqlite3WhereExprUsageFull(MaskSet, ExprList) ->
//	**
//	**       Internal use only.  Called only by sqlite3WhereExprUsageNN() for
//	**       complex expressions that require pushing register values onto
//	**       the stack.  Many calls to sqlite3WhereExprUsageNN() do not need
//	**       the more complex analysis done by this routine.  Hence, the
//	**       computations done by this routine are broken out into a separate
//	**       "no-inline" function to avoid the stack push overhead in the
//	**       common case where it is not needed.
//	*/
func _sqlite3WhereExprUsageFull(tls *libc.TLS, pMaskSet uintptr, p uintptr) (r TBitmask) {
	var mask TBitmask
	var v1 uint64
	_, _ = mask, v1
	if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_IF_NULL_ROW) {
		v1 = _sqlite3WhereGetMask(tls, pMaskSet, (*TExpr)(unsafe.Pointer(p)).FiTable)
	} else {
		v1 = uint64(0)
	}
	mask = v1
	if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 {
		mask |= _sqlite3WhereExprUsageNN(tls, pMaskSet, (*TExpr)(unsafe.Pointer(p)).FpLeft)
	}
	if (*TExpr)(unsafe.Pointer(p)).FpRight != 0 {
		mask |= _sqlite3WhereExprUsageNN(tls, pMaskSet, (*TExpr)(unsafe.Pointer(p)).FpRight)
	} else {
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_VarSelect)) != uint32(0) {
				(*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect = int32(1)
			}
			mask |= _exprSelectUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(p + 20)))
		} else {
			if *(*uintptr)(unsafe.Pointer(p + 20)) != 0 {
				mask |= _sqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(p + 20)))
			}
		}
	}
	if (int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_FUNCTION) || int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_AGG_FUNCTION)) && (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_WinFunc) != uint32(0) {
		mask |= _sqlite3WhereExprListUsage(tls, pMaskSet, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(p)).Fy)))).FpPartition)
		mask |= _sqlite3WhereExprListUsage(tls, pMaskSet, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(p)).Fy)))).FpOrderBy)
		mask |= _sqlite3WhereExprUsage(tls, pMaskSet, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(p)).Fy)))).FpFilter)
	}
	return mask
}

func _sqlite3WhereExprUsageNN(tls *libc.TLS, pMaskSet uintptr, p uintptr) (r TBitmask) {
	if int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) && !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_FixedCol)) != libc.Uint32FromInt32(0)) {
		return _sqlite3WhereGetMask(tls, pMaskSet, (*TExpr)(unsafe.Pointer(p)).FiTable)
	} else {
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Leaf)) != uint32(0) {
			return uint64(0)
		}
	}
	return _sqlite3WhereExprUsageFull(tls, pMaskSet, p)
}

func _sqlite3WhereExprUsage(tls *libc.TLS, pMaskSet uintptr, p uintptr) (r TBitmask) {
	var v1 uint64
	_ = v1
	if p != 0 {
		v1 = _sqlite3WhereExprUsageNN(tls, pMaskSet, p)
	} else {
		v1 = uint64(0)
	}
	return v1
}

func _sqlite3WhereExprListUsage(tls *libc.TLS, pMaskSet uintptr, pList uintptr) (r TBitmask) {
	var i int32
	var mask TBitmask
	_, _ = i, mask
	mask = uint64(0)
	if pList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			mask |= _sqlite3WhereExprUsage(tls, pMaskSet, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr)
			goto _1
		_1:
			;
			i++
		}
	}
	return mask
}

// C documentation
//
//	/*
//	** Call exprAnalyze on all terms in a WHERE clause.
//	**
//	** Note that exprAnalyze() might add new virtual terms onto the
//	** end of the WHERE clause.  We do not want to analyze these new
//	** virtual terms, so start analyzing at the end and work forward
//	** so that the added virtual terms are never processed.
//	*/
func _sqlite3WhereExprAnalyze(tls *libc.TLS, pTabList uintptr, pWC uintptr) {
	var i int32
	_ = i
	i = (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		_exprAnalyze(tls, pTabList, pWC, i)
		goto _1
	_1:
		;
		i--
	}
}

// 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, v3 int32
	var joinType Tu32
	var pArgs, pColRef, pRhs, pTab, pTerm uintptr
	_, _, _, _, _, _, _, _, _, _ = j, joinType, k, pArgs, pColRef, pRhs, pTab, pTerm, v2, v3
	if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x4>>2)) == 0 {
		return
	}
	pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
	pArgs = *(*uintptr)(unsafe.Pointer(pItem + 64))
	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) && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(k)*12))).FcolFlags)&int32(COLFLAG_HIDDEN) == 0 {
			k++
		}
		if k >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23829, 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
		v3 = k
		k++
		(*TExpr)(unsafe.Pointer(pColRef)).FiColumn = int16(v3)
		(*TExpr)(unsafe.Pointer(pColRef)).Fy.FpTab = pTab
		*(*TBitmask)(unsafe.Pointer(pItem + 56)) |= _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)*20))).FpExpr, 0), uintptr(0))
		pTerm = _sqlite3PExpr(tls, pParse, int32(TK_EQ), pColRef, pRhs)
		if int32((*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++
	}
}

/************** 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
//
//	/*
//	** Extra information appended to the end of sqlite3_index_info but not
//	** visible to the xBestIndex function, at least not directly.  The
//	** sqlite3_vtab_collation() interface knows how to reach it, however.
//	**
//	** This object is not an API and can be changed from one release to the
//	** next.  As long as allocateIndexInfo() and sqlite3_vtab_collation()
//	** agree on the structure, all will be well.
//	*/
type THiddenIndexInfo = struct {
	FpWC       uintptr
	FpParse    uintptr
	FeDistinct int32
	FmIn       Tu32
	FmHandleIn Tu32
	FaRhs      [1]uintptr
}

type HiddenIndexInfo = THiddenIndexInfo

type THiddenIndexInfo1 = struct {
	FpWC       uintptr
	FpParse    uintptr
	FeDistinct int32
	FmIn       Tu32
	FmHandleIn Tu32
	FaRhs      [1]uintptr
}

type HiddenIndexInfo1 = THiddenIndexInfo1

// C documentation
//
//	/*
//	** Return the estimated number of output rows from a WHERE clause
//	*/
func _sqlite3WhereOutputRowCount(tls *libc.TLS, pWInfo uintptr) (r TLogEst) {
	return (*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut
}

// C documentation
//
//	/*
//	** Return one of the WHERE_DISTINCT_xxxxx values to indicate how this
//	** WHERE clause returns outputs for DISTINCT processing.
//	*/
func _sqlite3WhereIsDistinct(tls *libc.TLS, pWInfo uintptr) (r int32) {
	return int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct)
}

// C documentation
//
//	/*
//	** Return the number of ORDER BY terms that are satisfied by the
//	** WHERE clause.  A return of 0 means that the output must be
//	** completely sorted.  A return equal to the number of ORDER BY
//	** terms means that no sorting is needed at all.  A return that
//	** is positive but less than the number of ORDER BY terms means that
//	** block sorting is required.
//	*/
func _sqlite3WhereIsOrdered(tls *libc.TLS, pWInfo uintptr) (r int32) {
	var v1 int32
	_ = v1
	if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) < 0 {
		v1 = 0
	} else {
		v1 = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat)
	}
	return v1
}

// 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 + 48))&0x4>>2)) != 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 + 760 + uintptr(int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-int32(1))*88
	if (*TWhereLevel)(unsafe.Pointer(pInner)).FpRJ != 0 {
		v1 = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue
	} else {
		v1 = (*TWhereLevel)(unsafe.Pointer(pInner)).FaddrNxt
	}
	return v1
}

// 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 + 48))&0x4>>2)) != 0) {
		return
	}
	if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == 0 {
		return
	}
	i = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		pInner = pWInfo + 760 + uintptr(i)*88
		if (*TWhereLoop1)(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--
	}
	_sqlite3VdbeGoto(tls, v, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)
}

// C documentation
//
//	/*
//	** Return the VDBE address or label to jump to in order to continue
//	** immediately with the next row of a WHERE clause.
//	*/
func _sqlite3WhereContinueLabel(tls *libc.TLS, pWInfo uintptr) (r int32) {
	return (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue
}

// C documentation
//
//	/*
//	** Return the VDBE address or label to jump to in order to break
//	** out of a WHERE loop.
//	*/
func _sqlite3WhereBreakLabel(tls *libc.TLS, pWInfo uintptr) (r int32) {
	return (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak
}

// C documentation
//
//	/*
//	** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
//	** operate directly on the rowids returned by a WHERE clause.  Return
//	** ONEPASS_SINGLE (1) if the statement can operation directly because only
//	** a single row is to be changed.  Return ONEPASS_MULTI (2) if the one-pass
//	** optimization can be used on multiple
//	**
//	** If the ONEPASS optimization is used (if this routine returns true)
//	** then also write the indices of open cursors used by ONEPASS
//	** into aiCur[0] and aiCur[1].  iaCur[0] gets the cursor of the data
//	** table and iaCur[1] gets the cursor used by an auxiliary index.
//	** Either value may be -1, indicating that cursor is not used.
//	** Any cursors returned will have been opened for writing.
//	**
//	** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
//	** unable to use the ONEPASS optimization.
//	*/
func _sqlite3WhereOkOnePass(tls *libc.TLS, pWInfo uintptr, aiCur uintptr) (r int32) {
	libc.Xmemcpy(tls, aiCur, pWInfo+20, libc.Uint32FromInt64(4)*libc.Uint32FromInt32(2))
	return int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass)
}

// 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 + 48)) & 0x1 >> 0))
}

// C documentation
//
//	/*
//	** Move the content of pSrc into pDest
//	*/
func _whereOrMove(tls *libc.TLS, pDest uintptr, pSrc uintptr) {
	(*TWhereOrSet)(unsafe.Pointer(pDest)).Fn = (*TWhereOrSet)(unsafe.Pointer(pSrc)).Fn
	libc.Xmemcpy(tls, pDest+8, pSrc+8, uint32((*TWhereOrSet)(unsafe.Pointer(pDest)).Fn)*uint32(16))
}

// C documentation
//
//	/*
//	** Try to insert a new prerequisite/cost entry into the WhereOrSet pSet.
//	**
//	** The new entry might overwrite an existing entry, or it might be
//	** appended, or it might be discarded.  Do whatever is the right thing
//	** so that pSet keeps the N_OR_COST best entries seen so far.
//	*/
func _whereOrInsert(tls *libc.TLS, pSet uintptr, prereq TBitmask, rRun TLogEst, nOut TLogEst) (r int32) {
	var i, v2 Tu16
	var p, v3 uintptr
	_, _, _, _ = i, p, v2, v3
	i = (*TWhereOrSet)(unsafe.Pointer(pSet)).Fn
	p = pSet + 8
	for {
		if !(int32(int32(i)) > 0) {
			break
		}
		if int32(int32(rRun)) <= int32((*TWhereOrCost)(unsafe.Pointer(p)).FrRun) && prereq&(*TWhereOrCost)(unsafe.Pointer(p)).Fprereq == prereq {
			goto whereOrInsert_done
		}
		if int32((*TWhereOrCost)(unsafe.Pointer(p)).FrRun) <= int32(int32(rRun)) && (*TWhereOrCost)(unsafe.Pointer(p)).Fprereq&prereq == (*TWhereOrCost)(unsafe.Pointer(p)).Fprereq {
			return 0
		}
		goto _1
	_1:
		;
		i--
		p += 16
	}
	if int32((*TWhereOrSet)(unsafe.Pointer(pSet)).Fn) < int32(N_OR_COST) {
		v3 = pSet
		v2 = *(*Tu16)(unsafe.Pointer(v3))
		*(*Tu16)(unsafe.Pointer(v3))++
		p = pSet + 8 + uintptr(v2)*16
		(*TWhereOrCost)(unsafe.Pointer(p)).FnOut = nOut
	} else {
		p = pSet + 8
		i = uint16(1)
		for {
			if !(int32(int32(i)) < int32((*TWhereOrSet)(unsafe.Pointer(pSet)).Fn)) {
				break
			}
			if int32((*TWhereOrCost)(unsafe.Pointer(p)).FrRun) > int32((*(*TWhereOrCost)(unsafe.Pointer(pSet + 8 + uintptr(i)*16))).FrRun) {
				p = pSet + 8 + uintptr(i)*16
			}
			goto _4
		_4:
			;
			i++
		}
		if int32((*TWhereOrCost)(unsafe.Pointer(p)).FrRun) <= int32(int32(rRun)) {
			return 0
		}
	}
	goto whereOrInsert_done
whereOrInsert_done:
	;
	(*TWhereOrCost)(unsafe.Pointer(p)).Fprereq = prereq
	(*TWhereOrCost)(unsafe.Pointer(p)).FrRun = rRun
	if int32((*TWhereOrCost)(unsafe.Pointer(p)).FnOut) > int32(int32(nOut)) {
		(*TWhereOrCost)(unsafe.Pointer(p)).FnOut = nOut
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Return the bitmask for the given cursor number.  Return 0 if
//	** iCursor is not in the set.
//	*/
func _sqlite3WhereGetMask(tls *libc.TLS, pMaskSet uintptr, iCursor int32) (r TBitmask) {
	var i int32
	_ = i
	if *(*int32)(unsafe.Pointer(pMaskSet + 8)) == iCursor {
		return uint64(1)
	}
	i = int32(1)
	for {
		if !(i < (*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).Fn) {
			break
		}
		if *(*int32)(unsafe.Pointer(pMaskSet + 8 + uintptr(i)*4)) == iCursor {
			return libc.Uint64FromInt32(1) << i
		}
		goto _1
	_1:
		;
		i++
	}
	return uint64(0)
}

// C documentation
//
//	/* Allocate memory that is automatically freed when pWInfo is freed.
//	*/
func _sqlite3WhereMalloc(tls *libc.TLS, pWInfo uintptr, nByte Tu64) (r uintptr) {
	var pBlock uintptr
	_ = pBlock
	pBlock = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb, nByte+uint64(16))
	if pBlock != 0 {
		(*TWhereMemBlock)(unsafe.Pointer(pBlock)).FpNext = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree
		(*TWhereMemBlock)(unsafe.Pointer(pBlock)).Fsz = nByte
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree = pBlock
		pBlock += 16
	}
	return pBlock
}

func _sqlite3WhereRealloc(tls *libc.TLS, pWInfo uintptr, pOld uintptr, nByte Tu64) (r uintptr) {
	var pNew, pOldBlk uintptr
	_, _ = pNew, pOldBlk
	pNew = _sqlite3WhereMalloc(tls, pWInfo, nByte)
	if pNew != 0 && pOld != 0 {
		pOldBlk = pOld
		pOldBlk -= 16
		libc.Xmemcpy(tls, pNew, pOld, uint32((*TWhereMemBlock)(unsafe.Pointer(pOldBlk)).Fsz))
	}
	return pNew
}

// C documentation
//
//	/*
//	** Create a new mask for cursor iCursor.
//	**
//	** There is one cursor per table in the FROM clause.  The number of
//	** tables in the FROM clause is limited by a test early in the
//	** sqlite3WhereBegin() routine.  So we know that the pMaskSet->ix[]
//	** array will never overflow.
//	*/
func _createMask(tls *libc.TLS, pMaskSet uintptr, iCursor int32) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	v2 = pMaskSet + 4
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	*(*int32)(unsafe.Pointer(pMaskSet + 8 + uintptr(v1)*4)) = iCursor
}

// C documentation
//
//	/*
//	** If the right-hand branch of the expression is a TK_COLUMN, then return
//	** a pointer to the right-hand branch.  Otherwise, return NULL.
//	*/
func _whereRightSubexprIsColumn(tls *libc.TLS, p uintptr) (r uintptr) {
	p = _sqlite3ExprSkipCollateAndLikely(tls, (*TExpr)(unsafe.Pointer(p)).FpRight)
	if p != uintptr(0) && int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) && !((*TExpr)(unsafe.Pointer(p)).Fflags&uint32(libc.Int32FromInt32(EP_FixedCol)) != libc.Uint32FromInt32(0)) {
		return p
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Term pTerm is guaranteed to be a WO_IN term. It may be a component term
//	** of a vector IN expression of the form "(x, y, ...) IN (SELECT ...)".
//	** This function checks to see if the term is compatible with an index
//	** column with affinity idxaff (one of the SQLITE_AFF_XYZ values). If so,
//	** it returns a pointer to the name of the collation sequence (e.g. "BINARY"
//	** or "NOCASE") used by the comparison in pTerm. If it is not compatible
//	** with affinity idxaff, NULL is returned.
//	*/
func _indexInAffinityOk(tls *libc.TLS, pParse uintptr, pTerm uintptr, idxaff Tu8) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var iField int32
	var pRet, pX, v1 uintptr
	var _ /* inexpr at bp+0 */ TExpr
	_, _, _, _ = iField, pRet, pX, v1
	pX = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
	if _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft) != 0 {
		iField = (*(*struct {
			FleftColumn int32
			FiField     int32
		})(unsafe.Pointer(pTerm + 24))).FiField - int32(1)
		(*(*TExpr)(unsafe.Pointer(bp))).Fflags = uint32(0)
		(*(*TExpr)(unsafe.Pointer(bp))).Fop = uint8(TK_EQ)
		(*(*TExpr)(unsafe.Pointer(bp))).FpLeft = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pX)).FpLeft + 20)) + 8 + uintptr(iField)*20))).FpExpr
		(*(*TExpr)(unsafe.Pointer(bp))).FpRight = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 20)))).FpEList + 8 + uintptr(iField)*20))).FpExpr
		pX = bp
	}
	if _sqlite3IndexAffinityOk(tls, pX, int8(int8(idxaff))) != 0 {
		pRet = _sqlite3ExprCompareCollSeq(tls, pParse, pX)
		if pRet != 0 {
			v1 = (*TCollSeq)(unsafe.Pointer(pRet)).FzName
		} else {
			v1 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
		}
		return v1
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Advance to the next WhereTerm that matches according to the criteria
//	** established when the pScan object was initialized by whereScanInit().
//	** Return NULL if there are no more matching WhereTerms.
//	*/
func _whereScanNext(tls *libc.TLS, pScan uintptr) (r uintptr) {
	var iColumn Ti16
	var iCur, j, k int32
	var pColl, pParse, pTerm, pWC, pX, zCollName, v2, v5 uintptr
	var v3, v6 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = iColumn, iCur, j, k, pColl, pParse, pTerm, pWC, pX, zCollName, v2, v3, v5, v6 /* The term being tested */
	k = (*TWhereScan)(unsafe.Pointer(pScan)).Fk                                                                              /* Where to start scanning */
	pWC = (*TWhereScan)(unsafe.Pointer(pScan)).FpWC
	for int32(1) != 0 {
		iColumn = *(*Ti16)(unsafe.Pointer(pScan + 72 + uintptr(int32((*TWhereScan)(unsafe.Pointer(pScan)).FiEquiv)-int32(1))*2))
		iCur = *(*int32)(unsafe.Pointer(pScan + 28 + uintptr(int32((*TWhereScan)(unsafe.Pointer(pScan)).FiEquiv)-int32(1))*4))
		for cond := true; cond; cond = pWC != uintptr(0) {
			pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(k)*48
			for {
				if !(k < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
					break
				}
				if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor == iCur && (*(*struct {
					FleftColumn int32
					FiField     int32
				})(unsafe.Pointer(pTerm + 24))).FleftColumn == int32(int32(iColumn)) && (int32(int32(iColumn)) != -int32(2) || _sqlite3ExprCompareSkip(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft, (*TWhereScan)(unsafe.Pointer(pScan)).FpIdxExpr, iCur) == 0) && (int32((*TWhereScan)(unsafe.Pointer(pScan)).FiEquiv) <= int32(1) || !((*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0))) {
					if v3 = int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_EQUIV) != 0 && int32((*TWhereScan)(unsafe.Pointer(pScan)).FnEquiv) < int32(libc.Uint32FromInt64(44)/libc.Uint32FromInt64(4)); v3 {
						v2 = _whereRightSubexprIsColumn(tls, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)
						pX = v2
					}
					if v3 && v2 != uintptr(0) {
						j = 0
						for {
							if !(j < int32((*TWhereScan)(unsafe.Pointer(pScan)).FnEquiv)) {
								break
							}
							if *(*int32)(unsafe.Pointer(pScan + 28 + uintptr(j)*4)) == (*TExpr)(unsafe.Pointer(pX)).FiTable && int32(*(*Ti16)(unsafe.Pointer(pScan + 72 + uintptr(j)*2))) == int32((*TExpr)(unsafe.Pointer(pX)).FiColumn) {
								break
							}
							goto _4
						_4:
							;
							j++
						}
						if j == int32((*TWhereScan)(unsafe.Pointer(pScan)).FnEquiv) {
							*(*int32)(unsafe.Pointer(pScan + 28 + uintptr(j)*4)) = (*TExpr)(unsafe.Pointer(pX)).FiTable
							*(*Ti16)(unsafe.Pointer(pScan + 72 + uintptr(j)*2)) = (*TExpr)(unsafe.Pointer(pX)).FiColumn
							(*TWhereScan)(unsafe.Pointer(pScan)).FnEquiv++
						}
					}
					if uint32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(*TWhereScan)(unsafe.Pointer(pScan)).FopMask != uint32(0) {
						/* Verify the affinity and collating sequence match */
						if (*TWhereScan)(unsafe.Pointer(pScan)).FzCollName != 0 && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_ISNULL) == 0 {
							pParse = (*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse
							pX = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
							if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0 {
								zCollName = _indexInAffinityOk(tls, pParse, pTerm, uint8((*TWhereScan)(unsafe.Pointer(pScan)).Fidxaff))
								if !(zCollName != 0) {
									goto _1
								}
							} else {
								if !(_sqlite3IndexAffinityOk(tls, pX, (*TWhereScan)(unsafe.Pointer(pScan)).Fidxaff) != 0) {
									goto _1
								}
								pColl = _sqlite3ExprCompareCollSeq(tls, pParse, pX)
								if pColl != 0 {
									v5 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
								} else {
									v5 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
								}
								zCollName = v5
							}
							if _sqlite3StrICmp(tls, zCollName, (*TWhereScan)(unsafe.Pointer(pScan)).FzCollName) != 0 {
								goto _1
							}
						}
						if v6 = int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) != 0; v6 {
							pX = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
						}
						if v6 && pX != libc.UintptrFromInt32(0) && int32((*TExpr)(unsafe.Pointer(pX)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pX)).FiTable == *(*int32)(unsafe.Pointer(pScan + 28)) && int32((*TExpr)(unsafe.Pointer(pX)).FiColumn) == int32(*(*Ti16)(unsafe.Pointer(pScan + 72))) {
							goto _1
						}
						(*TWhereScan)(unsafe.Pointer(pScan)).FpWC = pWC
						(*TWhereScan)(unsafe.Pointer(pScan)).Fk = k + int32(1)
						return pTerm
					}
				}
				goto _1
			_1:
				;
				k++
				pTerm += 48
			}
			pWC = (*TWhereClause)(unsafe.Pointer(pWC)).FpOuter
			k = 0
		}
		if int32((*TWhereScan)(unsafe.Pointer(pScan)).FiEquiv) >= int32((*TWhereScan)(unsafe.Pointer(pScan)).FnEquiv) {
			break
		}
		pWC = (*TWhereScan)(unsafe.Pointer(pScan)).FpOrigWC
		k = 0
		(*TWhereScan)(unsafe.Pointer(pScan)).FiEquiv++
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** This is whereScanInit() for the case of an index on an expression.
//	** It is factored out into a separate tail-recursion subroutine so that
//	** the normal whereScanInit() routine, which is a high-runner, does not
//	** need to push registers onto the stack as part of its prologue.
//	*/
func _whereScanInitIndexExpr(tls *libc.TLS, pScan uintptr) (r uintptr) {
	(*TWhereScan)(unsafe.Pointer(pScan)).Fidxaff = _sqlite3ExprAffinity(tls, (*TWhereScan)(unsafe.Pointer(pScan)).FpIdxExpr)
	return _whereScanNext(tls, pScan)
}

// C documentation
//
//	/*
//	** Initialize a WHERE clause scanner object.  Return a pointer to the
//	** first match.  Return NULL if there are no matches.
//	**
//	** The scanner will be searching the WHERE clause pWC.  It will look
//	** for terms of the form "X <op> <expr>" where X is column iColumn of table
//	** iCur.   Or if pIdx!=0 then X is column iColumn of index pIdx.  pIdx
//	** must be one of the indexes of table iCur.
//	**
//	** The <op> must be one of the operators described by opMask.
//	**
//	** If the search is for X and the WHERE clause contains terms of the
//	** form X=Y then this routine might also return terms of the form
//	** "Y <op> <expr>".  The number of levels of transitivity is limited,
//	** but is enough to handle most commonly occurring SQL statements.
//	**
//	** If X is not the INTEGER PRIMARY KEY then X must be compatible with
//	** index pIdx.
//	*/
func _whereScanInit(tls *libc.TLS, pScan uintptr, pWC uintptr, iCur int32, iColumn int32, opMask Tu32, pIdx uintptr) (r uintptr) {
	var j int32
	_ = j
	(*TWhereScan)(unsafe.Pointer(pScan)).FpOrigWC = pWC
	(*TWhereScan)(unsafe.Pointer(pScan)).FpWC = pWC
	(*TWhereScan)(unsafe.Pointer(pScan)).FpIdxExpr = uintptr(0)
	(*TWhereScan)(unsafe.Pointer(pScan)).Fidxaff = 0
	(*TWhereScan)(unsafe.Pointer(pScan)).FzCollName = uintptr(0)
	(*TWhereScan)(unsafe.Pointer(pScan)).FopMask = opMask
	(*TWhereScan)(unsafe.Pointer(pScan)).Fk = 0
	*(*int32)(unsafe.Pointer(pScan + 28)) = iCur
	(*TWhereScan)(unsafe.Pointer(pScan)).FnEquiv = uint8(1)
	(*TWhereScan)(unsafe.Pointer(pScan)).FiEquiv = uint8(1)
	if pIdx != 0 {
		j = iColumn
		iColumn = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))
		if iColumn == int32((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FiPKey) {
			iColumn = -int32(1)
		} else {
			if iColumn >= 0 {
				(*TWhereScan)(unsafe.Pointer(pScan)).Fidxaff = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(iColumn)*12))).Faffinity
				(*TWhereScan)(unsafe.Pointer(pScan)).FzCollName = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*4))
			} else {
				if iColumn == -int32(2) {
					(*TWhereScan)(unsafe.Pointer(pScan)).FpIdxExpr = (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(j)*20))).FpExpr
					(*TWhereScan)(unsafe.Pointer(pScan)).FzCollName = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*4))
					*(*Ti16)(unsafe.Pointer(pScan + 72)) = int16(-libc.Int32FromInt32(2))
					return _whereScanInitIndexExpr(tls, pScan)
				}
			}
		}
	} else {
		if iColumn == -int32(2) {
			return uintptr(0)
		}
	}
	*(*Ti16)(unsafe.Pointer(pScan + 72)) = int16(int16(iColumn))
	return _whereScanNext(tls, pScan)
}

// C documentation
//
//	/*
//	** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
//	** where X is a reference to the iColumn of table iCur or of index pIdx
//	** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
//	** the op parameter.  Return a pointer to the term.  Return 0 if not found.
//	**
//	** If pIdx!=0 then it must be one of the indexes of table iCur.
//	** Search for terms matching the iColumn-th column of pIdx
//	** rather than the iColumn-th column of table iCur.
//	**
//	** The term returned might by Y=<expr> if there is another constraint in
//	** the WHERE clause that specifies that X=Y.  Any such constraints will be
//	** identified by the WO_EQUIV bit in the pTerm->eOperator field.  The
//	** aiCur[]/iaColumn[] arrays hold X and all its equivalents. There are 11
//	** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10
//	** other equivalent values.  Hence a search for X will return <expr> if X=A1
//	** and A1=A2 and A2=A3 and ... and A9=A10 and A10=<expr>.
//	**
//	** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
//	** then try for the one with no dependencies on <expr> - in other words where
//	** <expr> is a constant expression of some kind.  Only return entries of
//	** the form "X <op> Y" where Y is a column in another table if no terms of
//	** the form "X <op> <const-expr>" exist.   If no terms with a constant RHS
//	** exist, try to return a term that does not use WO_EQUIV.
//	*/
func _sqlite3WhereFindTerm(tls *libc.TLS, pWC uintptr, iCur int32, iColumn int32, notReady TBitmask, op Tu32, pIdx uintptr) (r uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var p, pResult uintptr
	var _ /* scan at bp+0 */ TWhereScan
	_, _ = p, pResult
	pResult = uintptr(0)
	p = _whereScanInit(tls, bp, pWC, iCur, iColumn, op, pIdx)
	op &= uint32(libc.Int32FromInt32(WO_EQ) | libc.Int32FromInt32(WO_IS))
	for p != 0 {
		if (*TWhereTerm)(unsafe.Pointer(p)).FprereqRight&notReady == uint64(0) {
			if (*TWhereTerm)(unsafe.Pointer(p)).FprereqRight == uint64(0) && uint32((*TWhereTerm)(unsafe.Pointer(p)).FeOperator)&op != uint32(0) {
				return p
			}
			if pResult == uintptr(0) {
				pResult = p
			}
		}
		p = _whereScanNext(tls, bp)
	}
	return pResult
}

// C documentation
//
//	/*
//	** This function searches pList for an entry that matches the iCol-th column
//	** of index pIdx.
//	**
//	** If such an expression is found, its index in pList->a[] is returned. If
//	** no expression is found, -1 is returned.
//	*/
func _findIndexCol(tls *libc.TLS, pParse uintptr, pList uintptr, iBase int32, pIdx uintptr, iCol int32) (r int32) {
	var i int32
	var p, pColl, zColl uintptr
	_, _, _, _ = i, p, pColl, zColl
	zColl = *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(iCol)*4))
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		p = _sqlite3ExprSkipCollateAndLikely(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr)
		if p != uintptr(0) && (int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) || int32((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_AGG_COLUMN)) && int32((*TExpr)(unsafe.Pointer(p)).FiColumn) == int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2))) && (*TExpr)(unsafe.Pointer(p)).FiTable == iBase {
			pColl = _sqlite3ExprNNCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr)
			if 0 == _sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pColl)).FzName, zColl) {
				return i
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return -int32(1)
}

// 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)(unsafe.Pointer((*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)*12 + 4)) & 0xf >> 0))
	} 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 the DISTINCT expression-list passed as the third argument
//	** is redundant.
//	**
//	** A DISTINCT list is redundant if any subset of the columns in the
//	** DISTINCT list are collectively unique and individually non-null.
//	*/
func _isDistinctRedundant(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWC uintptr, pDistinct uintptr) (r int32) {
	var i, iBase int32
	var p, pIdx, pTab uintptr
	_, _, _, _, _ = i, iBase, p, pIdx, pTab
	/* If there is more than one table or sub-select in the FROM clause of
	 ** this query, then it will not be possible to show that the DISTINCT
	 ** clause is redundant. */
	if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc != int32(1) {
		return 0
	}
	iBase = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor
	pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpTab
	/* If any of the expressions is an IPK column on table iBase, then return
	 ** true. Note: The (p->iTable==iBase) part of this test may be false if the
	 ** current SELECT is a correlated sub-query.
	 */
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pDistinct)).FnExpr) {
			break
		}
		p = _sqlite3ExprSkipCollateAndLikely(tls, (*(*TExprList_item)(unsafe.Pointer(pDistinct + 8 + uintptr(i)*20))).FpExpr)
		if p == uintptr(0) {
			goto _1
		}
		if int32((*TExpr)(unsafe.Pointer(p)).Fop) != int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(p)).Fop) != int32(TK_AGG_COLUMN) {
			goto _1
		}
		if (*TExpr)(unsafe.Pointer(p)).FiTable == iBase && int32((*TExpr)(unsafe.Pointer(p)).FiColumn) < 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	/* Loop through all indices on the table, checking each to see if it makes
	 ** the DISTINCT qualifier redundant. It does so if:
	 **
	 **   1. The index is itself UNIQUE, and
	 **
	 **   2. All of the columns in the index are either part of the pDistinct
	 **      list, or else the WHERE clause contains a term of the form "col=X",
	 **      where X is a constant value. The collation sequences of the
	 **      comparison and select-list expressions must match those of the index.
	 **
	 **   3. All of those index columns for which the WHERE clause does not
	 **      contain a "col=X" term are subject to a NOT NULL constraint.
	 */
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if !(int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromInt32(OE_None)) {
			goto _2
		}
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			goto _2
		}
		i = 0
		for {
			if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
				break
			}
			if uintptr(0) == _sqlite3WhereFindTerm(tls, pWC, iBase, i, ^libc.Uint64FromInt32(0), uint32(WO_EQ), pIdx) {
				if _findIndexCol(tls, pParse, pDistinct, iBase, pIdx, i) < 0 {
					break
				}
				if _indexColumnNotNull(tls, pIdx, i) == 0 {
					break
				}
			}
			goto _3
		_3:
			;
			i++
		}
		if i == int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
			/* This index implies that the DISTINCT qualifier is redundant. */
			return int32(1)
		}
		goto _2
	_2:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	return 0
}

// C documentation
//
//	/*
//	** Estimate the logarithm of the input value to base 2.
//	*/
func _estLog(tls *libc.TLS, N TLogEst) (r TLogEst) {
	var v1 int32
	_ = v1
	if int32(int32(N)) <= int32(10) {
		v1 = 0
	} else {
		v1 = int32(_sqlite3LogEst(tls, uint64(uint64(N)))) - int32(33)
	}
	return int16(v1)
}

// C documentation
//
//	/*
//	** Convert OP_Column opcodes to OP_Copy in previously generated code.
//	**
//	** This routine runs over generated VDBE code and translates OP_Column
//	** opcodes into OP_Copy when the table is being accessed via co-routine
//	** instead of via table lookup.
//	**
//	** If the iAutoidxCur is not zero, then any OP_Rowid instructions on
//	** cursor iTabCur are transformed into OP_Sequence opcode for the
//	** iAutoidxCur cursor, in order to generate unique rowids for the
//	** automatic index being generated.
//	*/
func _translateColumnToCopy(tls *libc.TLS, pParse uintptr, iStart int32, iTabCur int32, iRegister int32, iAutoidxCur int32) {
	var iEnd int32
	var pOp, v uintptr
	_, _, _ = iEnd, pOp, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pOp = _sqlite3VdbeGetOp(tls, v, iStart)
	iEnd = _sqlite3VdbeCurrentAddr(tls, v)
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		return
	}
	for {
		if !(iStart < iEnd) {
			break
		}
		if (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 != iTabCur {
			goto _1
		}
		if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) {
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_Copy)
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 + iRegister
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 = 0
			(*TVdbeOp)(unsafe.Pointer(pOp)).Fp5 = uint16(2) /* Cause the MEM_Subtype flag to be cleared */
		} else {
			if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Rowid) {
				(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_Sequence)
				(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = iAutoidxCur
			}
		}
		goto _1
	_1:
		;
		iStart++
		pOp += 20
	}
}

/*
** Two routines for printing the content of an sqlite3_index_info
** structure.  Used for testing and debugging only.  If neither
** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
** are no-ops.
 */

// C documentation
//
//	/*
//	** We know that pSrc is an operand of an outer join.  Return true if
//	** pTerm is a constraint that is compatible with that join.
//	**
//	** pTerm must be EP_OuterON if pSrc is the right operand of an
//	** outer join.  pTerm can be either EP_OuterON or EP_InnerON if pSrc
//	** is the left operand of a RIGHT join.
//	**
//	** See https://sqlite.org/forum/forumpost/206d99a16dd9212f
//	** for an example of a WHERE clause constraints that may not be used on
//	** the right table of a RIGHT JOIN because the constraint implies a
//	** not-NULL condition on the left table of the RIGHT JOIN.
//	*/
func _constraintCompatibleWithOuterJoin(tls *libc.TLS, pTerm uintptr, pSrc uintptr) (r int32) {
	/* By caller */
	if !((*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != libc.Uint32FromInt32(0)) || *(*int32)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr + 36)) != (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
		return 0
	}
	if int32((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_RIGHT)) != 0 && (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
		return 0
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Return TRUE if the WHERE clause term pTerm is of a form where it
//	** could be used with an index to access pSrc, assuming an appropriate
//	** index existed.
//	*/
func _termCanDriveIndex(tls *libc.TLS, pTerm uintptr, pSrc uintptr, notReady TBitmask) (r int32) {
	var aff int8
	_ = aff
	if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
		return 0
	}
	if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) == 0 {
		return 0
	}
	if int32((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 && !(_constraintCompatibleWithOuterJoin(tls, pTerm, pSrc) != 0) {
		return 0 /* See https://sqlite.org/forum/forumpost/51e6959f61 */
	}
	if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&notReady != uint64(0) {
		return 0
	}
	if (*(*struct {
		FleftColumn int32
		FiField     int32
	})(unsafe.Pointer(pTerm + 24))).FleftColumn < 0 {
		return 0
	}
	aff = (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpTab)).FaCol + uintptr((*(*struct {
		FleftColumn int32
		FiField     int32
	})(unsafe.Pointer(pTerm + 24))).FleftColumn)*12))).Faffinity
	if !(_sqlite3IndexAffinityOk(tls, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, aff) != 0) {
		return 0
	}
	return int32(1)
}

// 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, v12, v14, v3, v5 int32
	var cMask, cMask1, extraCols, idxCols TBitmask
	var pColl, pExpr, pIdx, pLoop, pPartial, pSrc, pTabList, pTable, pTerm, pWCEnd, pX, v, v13, v15, v9 uintptr
	var sentWarning, useBloomFilter Tu8
	var v2, v8 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, pTabList, pTable, pTerm, pWCEnd, pX, regBase, regRecord, regYield, sentWarning, useBloomFilter, v, v12, v13, v14, v15, v2, v3, v4, v5, v8, v9 /* 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)*72
	pTable = (*TSrcItem)(unsafe.Pointer(pSrc)).FpTab
	pWCEnd = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm)*48
	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 int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VIRTUAL) == 0 && _sqlite3ExprIsSingleTableConstraint(tls, pExpr, pTabList, int32((*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 + 24))).FleftColumn
			if iCol >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
				v2 = libc.Uint64FromInt32(1) << (int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(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+23865, libc.VaList(bp+16, (*TTable)(unsafe.Pointer(pTable)).FzName, (*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTable)).FaCol + uintptr(iCol)*12))).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++
				*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v3)*4)) = pTerm
				idxCols |= cMask
			}
		}
		goto _1
	_1:
		;
		pTerm += 48
	}
	v4 = uint16(uint16(nKeyCol))
	(*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = v4
	(*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq = v4
	(*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = uint32(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 int32((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VIEW) {
		extraCols = uint64(-libc.Int32FromInt32(1)) & ^idxCols
	} else {
		extraCols = (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed & (^idxCols | libc.Uint64FromInt32(1)<<(int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1)))
	}
	if int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) < int32((*TTable)(unsafe.Pointer(pTable)).FnCol) {
		v5 = int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
	} else {
		v5 = int32((*TTable)(unsafe.Pointer(pTable)).FnCol)
	}
	mxBitCol = v5
	i = 0
	for {
		if !(i < mxBitCol) {
			break
		}
		if extraCols&(libc.Uint64FromInt32(1)<<i) != 0 {
			nKeyCol++
		}
		goto _6
	_6:
		;
		i++
	}
	if (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(libc.Uint64FromInt32(1)<<(int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1))) != 0 {
		nKeyCol += int32((*TTable)(unsafe.Pointer(pTable)).FnCol) - int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) + int32(1)
	}
	/* Construct the Index object to describe this index */
	pIdx = _sqlite3AllocateIndexObject(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int16(nKeyCol+int32(1)), 0, bp)
	if pIdx == uintptr(0) {
		goto end_auto_index_create
	}
	(*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex = pIdx
	(*TIndex)(unsafe.Pointer(pIdx)).FzName = __ccgo_ts + 23891
	(*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 + 24))).FleftColumn
			if iCol1 >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
				v8 = libc.Uint64FromInt32(1) << (int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1))
			} else {
				v8 = libc.Uint64FromInt32(1) << iCol1
			}
			cMask1 = v8
			if idxCols&cMask1 == uint64(0) {
				pX = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
				idxCols |= cMask1
				*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16((*(*struct {
					FleftColumn int32
					FiField     int32
				})(unsafe.Pointer(pTerm + 24))).FleftColumn)
				pColl = _sqlite3ExprCompareCollSeq(tls, pParse, pX)
				/* TH3 collate01.800 */
				if pColl != 0 {
					v9 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
				} else {
					v9 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
				}
				*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = v9
				n++
				if (*TExpr)(unsafe.Pointer(pX)).FpLeft != uintptr(0) && int32(_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 _7
	_7:
		;
		pTerm += 48
	}
	/* 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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(int16(i))
			*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
			n++
		}
		goto _10
	_10:
		;
		i++
	}
	if (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(libc.Uint64FromInt32(1)<<(int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1))) != 0 {
		i = int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTable)).FnCol)) {
				break
			}
			*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(int16(i))
			*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
			n++
			goto _11
		_11:
			;
			i++
		}
	}
	*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(-libc.Int32FromInt32(1))
	*(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
	/* Create the automatic index */
	v13 = pParse + 40
	v12 = *(*int32)(unsafe.Pointer(v13))
	*(*int32)(unsafe.Pointer(v13))++
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = v12
	_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&uint32(libc.Int32FromInt32(SQLITE_BloomFilter)) == uint32(0) && useBloomFilter != 0 {
		_sqlite3WhereExplainBloomFilter(tls, pParse, (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo, pLevel)
		v15 = pParse + 44
		*(*int32)(unsafe.Pointer(v15))++
		v14 = *(*int32)(unsafe.Pointer(v15))
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter = v14
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(10000), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter)
	}
	/* Fill the automatic index with content */
	if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x20>>5)) != 0 {
		regYield = (*TSrcItem)(unsafe.Pointer(pSrc)).FregReturn
		addrCounter = _sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, 0)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, (*TSrcItem)(unsafe.Pointer(pSrc)).FaddrFillSub)
		addrTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), regYield)
	} else {
		addrTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur)
	}
	if pPartial != 0 {
		iContinue = _sqlite3VdbeMakeLabel(tls, pParse)
		_sqlite3ExprIfFalse(tls, pParse, pPartial, iContinue, int32(SQLITE_JUMPIFNULL))
		*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= 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, int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.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(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x20>>5)) != 0 {
		_sqlite3VdbeChangeP2(tls, v, addrCounter, regBase+n)
		_translateColumnToCopy(tls, pParse, addrTop, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TSrcItem)(unsafe.Pointer(pSrc)).FregResult, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
		_sqlite3VdbeGoto(tls, v, addrTop)
		libc.SetBitFieldPtr16Uint32(pSrc+36+4, libc.Uint32FromInt32(0), 5, 0x20)
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, addrTop+int32(1))
		_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_STMTSTATUS_AUTOINDEX))
	}
	_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
//
//	/*
//	** Generate bytecode that will initialize a Bloom filter that is appropriate
//	** for pLevel.
//	**
//	** If there are inner loops within pLevel that have the WHERE_BLOOMFILTER
//	** flag set, initialize a Bloomfilter for them as well.  Except don't do
//	** this recursive initialization if the SQLITE_BloomPulldown optimization has
//	** been turned off.
//	**
//	** When the Bloom filter is initialized, the WHERE_BLOOMFILTER flag is cleared
//	** from the loop, but the regFilter value is set to a register that implements
//	** the Bloom filter.  When regFilter is positive, the
//	** sqlite3WhereCodeOneLoopStart() will generate code to test the Bloom filter
//	** and skip the subsequence B-Tree seek if the Bloom filter indicates that
//	** no matching rows exist.
//	**
//	** This routine may only be called if it has previously been determined that
//	** the loop would benefit from a Bloom filter, and the WHERE_BLOOMFILTER bit
//	** is set.
//	*/
func _sqlite3ConstructBloomFilter(tls *libc.TLS, pWInfo uintptr, iLevel int32, pLevel uintptr, notReady TBitmask) {
	var addrCont, addrOnce, addrTop, iCur, iSrc, jj, n, r1, r11, v1, v5 int32
	var pExpr, pIdx, pItem, pLoop, pParse, pTab, pTabItem, pTabList, pTerm, pWCEnd, saved_pIdxEpr, saved_pIdxPartExpr, v, v2 uintptr
	var sz Tu64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrCont, addrOnce, addrTop, iCur, iSrc, jj, n, pExpr, pIdx, pItem, pLoop, pParse, pTab, pTabItem, pTabList, pTerm, pWCEnd, r1, r11, saved_pIdxEpr, saved_pIdxPartExpr, sz, v, v1, v2, v5 /* Last WHERE clause term */
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse                                                                                                                                                                                                                   /* Parsing context */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                                                                                                                                                                                                                             /* VDBE under construction */
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop                                                                                                                                                                                                                   /* saved copy of Parse.pIdxPartExpr */
	saved_pIdxEpr = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
	saved_pIdxPartExpr = (*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr
	(*TParse)(unsafe.Pointer(pParse)).FpIdxEpr = uintptr(0)
	(*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr = uintptr(0)
	addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
	for cond := true; cond; cond = iLevel < int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) {
		_sqlite3WhereExplainBloomFilter(tls, pParse, pWInfo, pLevel)
		addrCont = _sqlite3VdbeMakeLabel(tls, pParse)
		iCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
		v2 = pParse + 44
		*(*int32)(unsafe.Pointer(v2))++
		v1 = *(*int32)(unsafe.Pointer(v2))
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter = v1
		/* The Bloom filter is a Blob held in a register.  Initialize it
		 ** to zero-filled blob of at least 80K bits, but maybe more if the
		 ** estimated size of the table is larger.  We could actually
		 ** measure the size of the table at run-time using OP_Count with
		 ** P3==1 and use that value to initialize the blob.  But that makes
		 ** testing complicated.  By basing the blob size on the value in the
		 ** sqlite_stat1 table, testing is much easier.
		 */
		pTabList = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
		iSrc = int32((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)
		pItem = pTabList + 8 + uintptr(iSrc)*72
		pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
		sz = _sqlite3LogEstToInt(tls, (*TTable)(unsafe.Pointer(pTab)).FnRowLogEst)
		if sz < uint64(10000) {
			sz = uint64(10000)
		} else {
			if sz > uint64(10000000) {
				sz = uint64(10000000)
			}
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(int32(sz)), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter)
		addrTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iCur)
		pWCEnd = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa + uintptr((*TWhereInfo)(unsafe.Pointer(pWInfo)).FsWC.FnTerm)*48
		pTerm = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa
		for {
			if !(pTerm < pWCEnd) {
				break
			}
			pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VIRTUAL) == 0 && _sqlite3ExprIsSingleTableConstraint(tls, pExpr, pTabList, iSrc, 0) != 0 {
				_sqlite3ExprIfFalse(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, addrCont, int32(SQLITE_JUMPIFNULL))
			}
			goto _3
		_3:
			;
			pTerm += 48
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != 0 {
			r1 = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCur, r1)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, 0, r1, int32(1))
			_sqlite3ReleaseTempReg(tls, pParse, r1)
		} else {
			pIdx = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
			n = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq)
			r11 = _sqlite3GetTempRange(tls, pParse, n)
			jj = 0
			for {
				if !(jj < n) {
					break
				}
				_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iCur, jj, r11+jj)
				goto _4
			_4:
				;
				jj++
			}
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, 0, r11, n)
			_sqlite3ReleaseTempRange(tls, pParse, r11, n)
		}
		_sqlite3VdbeResolveLabel(tls, v, addrCont)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, addrTop+int32(1))
		_sqlite3VdbeJumpHere(tls, v, addrTop)
		*(*Tu32)(unsafe.Pointer(pLoop + 40)) &= uint32(^libc.Int32FromInt32(WHERE_BLOOMFILTER))
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_BloomPulldown)) != uint32(0) {
			break
		}
		for {
			iLevel++
			v5 = iLevel
			if !(v5 < int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
				break
			}
			pLevel = pWInfo + 760 + uintptr(iLevel)*88
			pTabItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*72
			if int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
				continue
			}
			pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
			if pLoop == uintptr(0) {
				continue
			}
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).Fprereq&notReady != 0 {
				continue
			}
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(libc.Int32FromInt32(WHERE_BLOOMFILTER)|libc.Int32FromInt32(WHERE_COLUMN_IN)) == uint32(WHERE_BLOOMFILTER) {
				/* This is a candidate for bloom-filter pull-down (early evaluation).
				 ** The test that WHERE_COLUMN_IN is omitted is important, as we are
				 ** not able to do early evaluation of bloom filters that make use of
				 ** the IN operator */
				break
			}
		}
	}
	_sqlite3VdbeJumpHere(tls, v, addrOnce)
	(*TParse)(unsafe.Pointer(pParse)).FpIdxEpr = saved_pIdxEpr
	(*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr = saved_pIdxPartExpr
}

// 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 eDistinct, i, j, n, nOrderBy, nTerm, v12, v2, v9 int32
	var mNoOmit, op Tu16
	var pE2, pExpr, pExpr1, pHidden, pIdxCons, pIdxInfo, pIdxOrderBy, pOrderBy, pParse, pTab, pTerm, pUsage, zColl, v6, p3, p4 uintptr
	var v10 uint32
	var v7 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = eDistinct, i, j, mNoOmit, n, nOrderBy, nTerm, op, pE2, pExpr, pExpr1, pHidden, pIdxCons, pIdxInfo, pIdxOrderBy, pOrderBy, pParse, pTab, pTerm, pUsage, zColl, v10, v12, v2, v6, v7, v9, p3, p4
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	mNoOmit = uint16(0)
	eDistinct = 0
	pOrderBy = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy
	pTab = (*TSrcItem)(unsafe.Pointer(pSrc)).FpTab
	/* 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.
	 */
	v2 = libc.Int32FromInt32(0)
	nTerm = v2
	i = v2
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(i < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
			break
		}
		p3 = pTerm + 10
		*(*Tu16)(unsafe.Pointer(p3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p3))) & ^libc.Int32FromInt32(TERM_OK))
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
			goto _1
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUnusable != 0 {
			goto _1
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) & ^libc.Int32FromInt32(WO_EQUIV) == 0 {
			goto _1
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VNULL) != 0 {
			goto _1
		}
		if int32((*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
		}
		nTerm++
		p4 = pTerm + 10
		*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(TERM_OK))
		goto _1
	_1:
		;
		i++
		pTerm += 48
	}
	/* 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)*20))).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 int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
				break
			}
			/* First case - a direct column references without a COLLATE operator */
			if int32((*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 = int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE); v7 {
				v6 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
				pE2 = v6
			}
			if v7 && int32((*TExpr)(unsafe.Pointer(v6)).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)*12)
				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++
		}
		if i == n {
			nOrderBy = n
			if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) != 0 && !(int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x4000>>14)) != 0) {
				eDistinct = int32(2) + libc.BoolInt32(int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_SORTBYGROUP) != 0)
			} else {
				if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_GROUPBY) != 0 {
					eDistinct = int32(1)
				}
			}
		}
	}
	/* Allocate the sqlite3_index_info structure
	 */
	pIdxInfo = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint32(72)+(libc.Uint32FromInt64(12)+libc.Uint32FromInt64(8))*uint32(uint32(nTerm))+uint32(8)*uint32(uint32(nOrderBy))+uint32(24)+uint32(4)*uint32(uint32(nTerm))))
	if pIdxInfo == uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1642, 0)
		return uintptr(0)
	}
	pHidden = pIdxInfo + 1*72
	pIdxCons = pHidden + 20 + uintptr(nTerm)*4
	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
	(*THiddenIndexInfo1)(unsafe.Pointer(pHidden)).FpWC = pWC
	(*THiddenIndexInfo1)(unsafe.Pointer(pHidden)).FpParse = pParse
	(*THiddenIndexInfo1)(unsafe.Pointer(pHidden)).FeDistinct = eDistinct
	(*THiddenIndexInfo1)(unsafe.Pointer(pHidden)).FmIn = uint32(0)
	v9 = libc.Int32FromInt32(0)
	j = v9
	i = v9
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(i < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
			break
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_OK) == 0 {
			goto _8
		}
		(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).FiColumn = (*(*struct {
			FleftColumn int32
			FiField     int32
		})(unsafe.Pointer(pTerm + 24))).FleftColumn
		(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).FiTermOffset = i
		op = uint16(int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) & int32(WO_ALL))
		if int32(int32(op)) == int32(WO_IN) {
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_SLICE) == 0 {
				if j <= int32(31) {
					v10 = libc.Uint32FromInt32(1) << j
				} else {
					v10 = uint32(0)
				}
				*(*Tu32)(unsafe.Pointer(pHidden + 12)) |= v10
			}
			op = uint16(WO_EQ)
		}
		if int32(int32(op)) == int32(WO_AUX) {
			(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).Fop = (*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp
		} else {
			if int32(int32(op))&(libc.Int32FromInt32(WO_ISNULL)|libc.Int32FromInt32(WO_IS)) != 0 {
				if int32(int32(op)) == int32(WO_ISNULL) {
					(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).Fop = uint8(SQLITE_INDEX_CONSTRAINT_ISNULL)
				} else {
					(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).Fop = uint8(SQLITE_INDEX_CONSTRAINT_IS)
				}
			} else {
				(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).Fop = uint8(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 int32(int32(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 = Tu16(int32(mNoOmit) | libc.Int32FromInt32(1)<<j)
					}
					if int32(int32(op)) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) {
						(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).Fop = uint8(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_LE) - libc.Int32FromInt32(TK_EQ)))
					}
					if int32(int32(op)) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ)) {
						(*(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12))).Fop = uint8(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_GE) - libc.Int32FromInt32(TK_EQ)))
					}
				}
			}
		}
		j++
		goto _8
	_8:
		;
		i++
		pTerm += 48
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint = j
	v12 = libc.Int32FromInt32(0)
	j = v12
	i = v12
	for {
		if !(i < nOrderBy) {
			break
		}
		pExpr1 = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).FpExpr
		if _sqlite3ExprIsConstant(tls, uintptr(0), pExpr1) != 0 {
			goto _11
		}
		(*(*Tsqlite3_index_orderby)(unsafe.Pointer(pIdxOrderBy + uintptr(j)*8))).FiColumn = int32((*TExpr)(unsafe.Pointer(pExpr1)).FiColumn)
		(*(*Tsqlite3_index_orderby)(unsafe.Pointer(pIdxOrderBy + uintptr(j)*8))).Fdesc = uint8(int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).Ffg.FsortFlags) & int32(KEYINFO_ORDER_DESC))
		j++
		goto _11
	_11:
		;
		i++
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy = j
	*(*Tu16)(unsafe.Pointer(pmNoOmit)) = mNoOmit
	return pIdxInfo
}

// C documentation
//
//	/*
//	** Free an sqlite3_index_info structure allocated by allocateIndexInfo()
//	** and possibly modified by xBestIndex methods.
//	*/
func _freeIndexInfo(tls *libc.TLS, db uintptr, pIdxInfo uintptr) {
	var i int32
	var pHidden uintptr
	_, _ = i, pHidden
	pHidden = pIdxInfo + 1*72
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(pHidden + 20 + uintptr(i)*4))) /* IMP: R-14553-25174 */
		*(*uintptr)(unsafe.Pointer(pHidden + 20 + uintptr(i)*4)) = uintptr(0)
		goto _1
	_1:
		;
		i++
	}
	_sqlite3DbFree(tls, db, pIdxInfo)
}

// C documentation
//
//	/*
//	** The table object reference passed as the second argument to this function
//	** must represent a virtual table. This function invokes the xBestIndex()
//	** method of the virtual table with the sqlite3_index_info object that
//	** comes in as the 3rd argument to this function.
//	**
//	** If an error occurs, pParse is populated with an error message and an
//	** appropriate error code is returned.  A return of SQLITE_CONSTRAINT from
//	** xBestIndex is not considered an error.  SQLITE_CONSTRAINT indicates that
//	** the current configuration of "unusable" flags in sqlite3_index_info can
//	** not result in a valid plan.
//	**
//	** Whether or not an error is returned, it is the responsibility of the
//	** caller to eventually free p->idxStr if p->needToFreeIdxStr indicates
//	** that this is required.
//	*/
func _vtabBestIndex(tls *libc.TLS, pParse uintptr, pTab uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pVtab uintptr
	var rc int32
	_, _ = pVtab, rc
	pVtab = (*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pTab))).FpVtab
	(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock++
	rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule)).FxBestIndex})))(tls, pVtab, p)
	(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock--
	if rc != SQLITE_OK && rc != int32(SQLITE_CONSTRAINT) {
		if rc == int32(SQLITE_NOMEM) {
			_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb)
		} else {
			if !((*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg != 0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+4709, libc.VaList(bp+8, _sqlite3ErrStr(tls, rc)))
			} else {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+4709, libc.VaList(bp+8, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg))
			}
		}
	}
	if (*TVTable)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).Fp)).FbAllSchemas != 0 {
		_sqlite3VtabUsesAllSchemas(tls, pParse)
	}
	Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
	(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = uintptr(0)
	return rc
}

// 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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
		nField = int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
	} else {
		nField = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
	}
	if int32((*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField) < nField {
		v1 = int32((*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)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(iSamp-int32(1))*20))).FanLt + uintptr(n-int32(1))*8)) != *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(iSamp)*20))).FanLt + uintptr(n-int32(1))*8)) {
					break
				}
				goto _2
			_2:
				;
				n++
			}
		} else {
			n = iTest + int32(1)
		}
		(*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField = uint16(uint16(n))
		res = _sqlite3VdbeRecordCompare(tls, (*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(iSamp)*20))).Fn, (*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(iSamp)*20))).Fp, pRec)
		if res < 0 {
			iLower = *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(iSamp)*20))).FanLt + uintptr(n-int32(1))*8)) + *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(iSamp)*20))).FanEq + uintptr(n-int32(1))*8))
			iMin = iTest + int32(1)
		} else {
			if res == 0 && n < nField {
				iLower = *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(iSamp)*20))).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)(unsafe.Pointer(aStat)) = *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(i)*20))).FanLt + uintptr(iCol)*8))
		*(*TtRowcnt)(unsafe.Pointer(aStat + 1*8)) = *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(i)*20))).FanEq + uintptr(iCol)*8))
	} else {
		if i >= (*TIndex)(unsafe.Pointer(pIdx)).FnSample {
			iUpper = (*TIndex)(unsafe.Pointer(pIdx)).FnRowEst0
		} else {
			iUpper = *(*TtRowcnt)(unsafe.Pointer((*(*TIndexSample)(unsafe.Pointer(aSample + uintptr(i)*20))).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)(unsafe.Pointer(aStat)) = iLower + iGap
		*(*TtRowcnt)(unsafe.Pointer(aStat + 1*8)) = *(*TtRowcnt)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaAvgEq + uintptr(nField-int32(1))*8))
	}
	/* Restore the pRec->nField value before returning.  */
	(*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField = uint16(uint16(nField))
	return i
}

// C documentation
//
//	/*
//	** If it is not NULL, pTerm is a term that provides an upper or lower
//	** bound on a range scan. Without considering pTerm, it is estimated
//	** that the scan will visit nNew rows. This function returns the number
//	** estimated to be visited after taking pTerm into account.
//	**
//	** If the user explicitly specified a likelihood() value for this term,
//	** then the return value is the likelihood multiplied by the number of
//	** input rows. Otherwise, this function assumes that an "IS NOT NULL" term
//	** has a likelihood of 0.50, and any other term a likelihood of 0.25.
//	*/
func _whereRangeAdjust(tls *libc.TLS, pTerm uintptr, nNew TLogEst) (r TLogEst) {
	var nRet TLogEst
	_ = nRet
	nRet = nNew
	if pTerm != 0 {
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 {
			nRet = TLogEst(int32(nRet) + int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
		} else {
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VNULL) == 0 {
				nRet = TLogEst(int32(nRet) - libc.Int32FromInt32(20))
			}
		}
	}
	return nRet
}

// C documentation
//
//	/*
//	** Return the affinity for a single column of an index.
//	*/
func _sqlite3IndexColumnAffinity(tls *libc.TLS, db uintptr, pIdx uintptr, iCol int32) (r int8) {
	if !((*TIndex)(unsafe.Pointer(pIdx)).FzColAff != 0) {
		if _sqlite3IndexAffinityStr(tls, db, pIdx) == uintptr(0) {
			return int8(SQLITE_AFF_BLOB)
		}
	}
	return *(*int8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FzColAff + uintptr(iCol)))
}

// C documentation
//
//	/*
//	** This function is called to estimate the number of rows visited by a
//	** range-scan on a skip-scan index. For example:
//	**
//	**   CREATE INDEX i1 ON t1(a, b, c);
//	**   SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?;
//	**
//	** Value pLoop->nOut is currently set to the estimated number of rows
//	** visited for scanning (a=? AND b=?). This function reduces that estimate
//	** by some factor to account for the (c BETWEEN ? AND ?) expression based
//	** on the stat4 data for the index. this scan will be performed multiple
//	** times (once for each (a,b) combination that matches a=?) is dealt with
//	** by the caller.
//	**
//	** It does this by scanning through all stat4 samples, comparing values
//	** extracted from pLower and pUpper with the corresponding column in each
//	** sample. If L and U are the number of samples found to be less than or
//	** equal to the values extracted from pLower and pUpper respectively, and
//	** N is the total number of samples, the pLoop->nOut value is adjusted
//	** as follows:
//	**
//	**   nOut = nOut * ( min(U - L, 1) / N )
//	**
//	** If pLower is NULL, or a value cannot be extracted from the term, L is
//	** set to zero. If pUpper is NULL, or a value cannot be extracted from it,
//	** U is set to N.
//	**
//	** Normally, this function sets *pbDone to 1 before returning. However,
//	** if no value can be extracted from either pLower or pUpper (and so the
//	** estimate of the number of rows delivered remains unchanged), *pbDone
//	** is left as is.
//	**
//	** If an error occurs, an SQLite error code is returned. Otherwise,
//	** SQLITE_OK.
//	*/
func _whereRangeSkipScanEst(tls *libc.TLS, pParse uintptr, pLower uintptr, pUpper uintptr, pLoop uintptr, pbDone uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aff Tu8
	var db, p, pColl, p3 uintptr
	var i, nAdjust, nDiff, nEq, nLower, nUpper, rc, res, res1, v1 int32
	var _ /* p1 at bp+0 */ uintptr
	var _ /* p2 at bp+4 */ uintptr
	var _ /* pVal at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aff, db, i, nAdjust, nDiff, nEq, nLower, nUpper, p, pColl, rc, res, res1, v1, p3
	p = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
	nEq = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	nLower = -int32(1)
	nUpper = (*TIndex)(unsafe.Pointer(p)).FnSample + int32(1)
	rc = SQLITE_OK
	aff = uint8(_sqlite3IndexColumnAffinity(tls, db, p, nEq))
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)     /* Value extracted from pLower */
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* Value extracted from pUpper */
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0) /* Value extracted from record */
	pColl = _sqlite3LocateCollSeq(tls, pParse, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(p)).FazColl + uintptr(nEq)*4)))
	if pLower != 0 {
		rc = _sqlite3Stat4ValueFromExpr(tls, pParse, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pLower)).FpExpr)).FpRight, aff, bp)
		nLower = 0
	}
	if pUpper != 0 && rc == SQLITE_OK {
		rc = _sqlite3Stat4ValueFromExpr(tls, pParse, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pUpper)).FpExpr)).FpRight, aff, bp+4)
		if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
			v1 = 0
		} else {
			v1 = (*TIndex)(unsafe.Pointer(p)).FnSample
		}
		nUpper = v1
	}
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 || *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
		i = 0
		for {
			if !(rc == SQLITE_OK && i < (*TIndex)(unsafe.Pointer(p)).FnSample) {
				break
			}
			rc = _sqlite3Stat4Column(tls, db, (*(*TIndexSample)(unsafe.Pointer((*TIndex)(unsafe.Pointer(p)).FaSample + uintptr(i)*20))).Fp, (*(*TIndexSample)(unsafe.Pointer((*TIndex)(unsafe.Pointer(p)).FaSample + uintptr(i)*20))).Fn, nEq, bp+8)
			if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				res = _sqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), pColl)
				if res >= 0 {
					nLower++
				}
			}
			if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
				res1 = _sqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*uintptr)(unsafe.Pointer(bp + 8)), pColl)
				if res1 >= 0 {
					nUpper++
				}
			}
			goto _2
		_2:
			;
			i++
		}
		nDiff = nUpper - nLower
		if nDiff <= 0 {
			nDiff = int32(1)
		}
		/* If there is both an upper and lower bound specified, and the
		 ** comparisons indicate that they are close together, use the fallback
		 ** method (assume that the scan visits 1/64 of the rows) for estimating
		 ** the number of rows visited. Otherwise, estimate the number of rows
		 ** using the method described in the header comment for this function. */
		if nDiff != int32(1) || pUpper == uintptr(0) || pLower == uintptr(0) {
			nAdjust = int32(_sqlite3LogEst(tls, uint64((*TIndex)(unsafe.Pointer(p)).FnSample))) - int32(_sqlite3LogEst(tls, uint64(uint64(nDiff))))
			p3 = pLoop + 22
			*(*TLogEst)(unsafe.Pointer(p3)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p3))) - nAdjust)
			*(*int32)(unsafe.Pointer(pbDone)) = int32(1)
		}
	} else {
	}
	_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return rc
}

// C documentation
//
//	/*
//	** This function is used to estimate the number of rows that will be visited
//	** by scanning an index for a range of values. The range may have an upper
//	** bound, a lower bound, or both. The WHERE clause terms that set the upper
//	** and lower bounds are represented by pLower and pUpper respectively. For
//	** example, assuming that index p is on t1(a):
//	**
//	**   ... FROM t1 WHERE a > ? AND a < ? ...
//	**                    |_____|   |_____|
//	**                       |         |
//	**                     pLower    pUpper
//	**
//	** If either of the upper or lower bound is not present, then NULL is passed in
//	** place of the corresponding WhereTerm.
//	**
//	** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index
//	** column subject to the range constraint. Or, equivalently, the number of
//	** equality constraints optimized by the proposed index scan. For example,
//	** assuming index p is on t1(a, b), and the SQL query is:
//	**
//	**   ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
//	**
//	** then nEq is set to 1 (as the range restricted column, b, is the second
//	** left-most column of the index). Or, if the query is:
//	**
//	**   ... FROM t1 WHERE a > ? AND a < ? ...
//	**
//	** then nEq is set to 0.
//	**
//	** When this function is called, *pnOut is set to the sqlite3LogEst() of the
//	** number of rows that the index scan is expected to visit without
//	** considering the range constraints. If nEq is 0, then *pnOut is the number of
//	** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
//	** to account for the range constraints pLower and pUpper.
//	**
//	** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
//	** used, a single range inequality reduces the search space by a factor of 4.
//	** and a pair of constraints (x>? AND x<?) reduces the expected number of
//	** rows visited by a factor of 64.
//	*/
func _whereRangeScanEst(tls *libc.TLS, pParse uintptr, pBuilder uintptr, pLower uintptr, pUpper uintptr, pLoop uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iLower, iNew, iNew1, iUpper TtRowcnt
	var iLwrIdx, iUprIdx, nBtm, nEq, nOut, nTop, rc, t1 int32
	var mask, mask1 Tu16
	var nNew TLogEst
	var p, pExpr, pExpr1, t uintptr
	var v1, v2 uint64
	var _ /* a at bp+8 */ [2]TtRowcnt
	var _ /* bDone at bp+32 */ int32
	var _ /* n at bp+24 */ int32
	var _ /* n at bp+28 */ int32
	var _ /* pRec at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = iLower, iLwrIdx, iNew, iNew1, iUpper, iUprIdx, mask, mask1, nBtm, nEq, nNew, nOut, nTop, p, pExpr, pExpr1, rc, t, t1, v1, v2
	rc = SQLITE_OK
	nOut = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnOut)
	p = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
	nEq = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq)
	if (*TIndex)(unsafe.Pointer(p)).FnSample > 0 && nEq < (*TIndex)(unsafe.Pointer(p)).FnSampleCol && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
		if nEq == (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid {
			*(*uintptr)(unsafe.Pointer(bp)) = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec
			nBtm = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnBtm)
			nTop = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnTop) /* Rows less than the upper bound */
			iLwrIdx = -int32(2)                                                /* aSample[] for the lower bound */
			iUprIdx = -int32(1)                                                /* aSample[] for the upper bound */
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				(*TUnpackedRecord)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnField = uint16((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid)
			}
			/* Determine iLower and iUpper using ($P) only. */
			if nEq == 0 {
				iLower = uint64(0)
				iUpper = (*TIndex)(unsafe.Pointer(p)).FnRowEst0
			} else {
				/* Note: this call could be optimized away - since the same values must
				 ** have been requested when testing key $P in whereEqualScanEst().  */
				_whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp)), 0, bp+8)
				iLower = (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[0]
				iUpper = (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[0] + (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[int32(1)]
			}
			if *(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(p)).FaSortOrder + uintptr(nEq))) != 0 {
				/* The roles of pLower and pUpper are swapped for a DESC index */
				t = pLower
				pLower = pUpper
				pUpper = t
				t1 = nBtm
				nBtm = nTop
				nTop = t1
			}
			/* If possible, improve on the iLower estimate using ($P:$L). */
			if pLower != 0 { /* Values extracted from pExpr */
				pExpr = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pLower)).FpExpr)).FpRight
				rc = _sqlite3Stat4ProbeSetValue(tls, pParse, p, bp, pExpr, nBtm, nEq, bp+24)
				if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
					mask = uint16(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ)))
					if _sqlite3ExprVectorSize(tls, pExpr) > *(*int32)(unsafe.Pointer(bp + 24)) {
						mask = uint16(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)))
					}
					iLwrIdx = _whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp)), 0, bp+8)
					if int32((*TWhereTerm)(unsafe.Pointer(pLower)).FeOperator)&int32(int32(mask)) != 0 {
						v1 = (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[int32(1)]
					} else {
						v1 = uint64(0)
					}
					iNew = (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[0] + v1
					if iNew > iLower {
						iLower = iNew
					}
					nOut--
					pLower = uintptr(0)
				}
			}
			/* If possible, improve on the iUpper estimate using ($P:$U). */
			if pUpper != 0 { /* Values extracted from pExpr */
				pExpr1 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pUpper)).FpExpr)).FpRight
				rc = _sqlite3Stat4ProbeSetValue(tls, pParse, p, bp, pExpr1, nTop, nEq, bp+28)
				if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 28)) != 0 {
					mask1 = uint16(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ)))
					if _sqlite3ExprVectorSize(tls, pExpr1) > *(*int32)(unsafe.Pointer(bp + 28)) {
						mask1 = uint16(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)))
					}
					iUprIdx = _whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp)), int32(1), bp+8)
					if int32((*TWhereTerm)(unsafe.Pointer(pUpper)).FeOperator)&int32(int32(mask1)) != 0 {
						v2 = (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[int32(1)]
					} else {
						v2 = uint64(0)
					}
					iNew1 = (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[0] + v2
					if iNew1 < iUpper {
						iUpper = iNew1
					}
					nOut--
					pUpper = uintptr(0)
				}
			}
			(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec = *(*uintptr)(unsafe.Pointer(bp))
			if rc == SQLITE_OK {
				if iUpper > iLower {
					nNew = _sqlite3LogEst(tls, iUpper-iLower)
					/* TUNING:  If both iUpper and iLower are derived from the same
					 ** sample, then assume they are 4x more selective.  This brings
					 ** the estimated selectivity more in line with what it would be
					 ** if estimated without the use of STAT4 tables. */
					if iLwrIdx == iUprIdx {
						nNew = TLogEst(int32(nNew) - libc.Int32FromInt32(20))
					}
				} else {
					nNew = int16(10)
				}
				if int32(int32(nNew)) < nOut {
					nOut = int32(int32(nNew))
				}
			}
		} else {
			*(*int32)(unsafe.Pointer(bp + 32)) = 0
			rc = _whereRangeSkipScanEst(tls, pParse, pLower, pUpper, pLoop, bp+32)
			if *(*int32)(unsafe.Pointer(bp + 32)) != 0 {
				return rc
			}
		}
	}
	nNew = _whereRangeAdjust(tls, pLower, int16(int16(nOut)))
	nNew = _whereRangeAdjust(tls, pUpper, nNew)
	/* TUNING: If there is both an upper and lower limit and neither limit
	 ** has an application-defined likelihood(), assume the range is
	 ** reduced by an additional 75%. This means that, by default, an open-ended
	 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
	 ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
	 ** match 1/64 of the index. */
	if pLower != 0 && int32((*TWhereTerm)(unsafe.Pointer(pLower)).FtruthProb) > 0 && pUpper != 0 && int32((*TWhereTerm)(unsafe.Pointer(pUpper)).FtruthProb) > 0 {
		nNew = TLogEst(int32(nNew) - libc.Int32FromInt32(20))
	}
	nOut -= libc.BoolInt32(pLower != uintptr(0)) + libc.BoolInt32(pUpper != uintptr(0))
	if int32(int32(nNew)) < int32(10) {
		nNew = int16(10)
	}
	if int32(int32(nNew)) < nOut {
		nOut = int32(int32(nNew))
	}
	(*TWhereLoop)(unsafe.Pointer(pLoop)).FnOut = int16(int16(nOut))
	return rc
}

// C documentation
//
//	/*
//	** Estimate the number of rows that will be returned based on
//	** an equality constraint x=VALUE and where that VALUE occurs in
//	** the histogram data.  This only works when x is the left-most
//	** column of an index and sqlite_stat4 histogram data is available
//	** for that index.  When pExpr==NULL that means the constraint is
//	** "x IS NULL" instead of "x=VALUE".
//	**
//	** Write the estimated row count into *pnRow and return SQLITE_OK.
//	** If unable to make an estimate, leave *pnRow unchanged and return
//	** non-zero.
//	**
//	** This routine can fail if it is unable to load a collating sequence
//	** required for string comparison, or if unable to allocate memory
//	** for a UTF conversion required for comparison.  The error is stored
//	** in the pParse structure.
//	*/
func _whereEqualScanEst(tls *libc.TLS, pParse uintptr, pBuilder uintptr, pExpr uintptr, pnRow uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nEq, rc int32
	var p uintptr
	var _ /* a at bp+8 */ [2]TtRowcnt
	var _ /* bOk at bp+24 */ int32
	var _ /* pRec at bp+0 */ uintptr
	_, _, _ = nEq, p, rc
	p = (*TWhereLoop)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew)).Fu.Fbtree.FpIndex
	nEq = int32((*TWhereLoop)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew)).Fu.Fbtree.FnEq)
	*(*uintptr)(unsafe.Pointer(bp)) = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec
	/* If values are not available for all fields of the index to the left
	 ** of this one, no estimate can be made. Return SQLITE_NOTFOUND. */
	if (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid < nEq-int32(1) {
		return int32(SQLITE_NOTFOUND)
	}
	/* This is an optimization only. The call to sqlite3Stat4ProbeSetValue()
	 ** below would return the same value.  */
	if nEq >= int32((*TIndex)(unsafe.Pointer(p)).FnColumn) {
		*(*TtRowcnt)(unsafe.Pointer(pnRow)) = uint64(1)
		return SQLITE_OK
	}
	rc = _sqlite3Stat4ProbeSetValue(tls, pParse, p, bp, pExpr, int32(1), nEq-int32(1), bp+24)
	(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec = *(*uintptr)(unsafe.Pointer(bp))
	if rc != SQLITE_OK {
		return rc
	}
	if *(*int32)(unsafe.Pointer(bp + 24)) == 0 {
		return int32(SQLITE_NOTFOUND)
	}
	(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = nEq
	_whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp)), 0, bp+8)
	*(*TtRowcnt)(unsafe.Pointer(pnRow)) = (*(*[2]TtRowcnt)(unsafe.Pointer(bp + 8)))[int32(1)]
	return rc
}

// C documentation
//
//	/*
//	** Estimate the number of rows that will be returned based on
//	** an IN constraint where the right-hand side of the IN operator
//	** is a list of values.  Example:
//	**
//	**        WHERE x IN (1,2,3,4)
//	**
//	** Write the estimated row count into *pnRow and return SQLITE_OK.
//	** If unable to make an estimate, leave *pnRow unchanged and return
//	** non-zero.
//	**
//	** This routine can fail if it is unable to load a collating sequence
//	** required for string comparison, or if unable to allocate memory
//	** for a UTF conversion required for comparison.  The error is stored
//	** in the pParse structure.
//	*/
func _whereInScanEst(tls *libc.TLS, pParse uintptr, pBuilder uintptr, pList uintptr, pnRow uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, nRecValid, rc int32
	var nRow0 Ti64
	var nRowEst TtRowcnt
	var p uintptr
	var _ /* nEst at bp+0 */ TtRowcnt
	_, _, _, _, _, _ = i, nRecValid, nRow0, nRowEst, p, rc
	p = (*TWhereLoop)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew)).Fu.Fbtree.FpIndex
	nRow0 = int64(_sqlite3LogEstToInt(tls, *(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(p)).FaiRowLogEst))))
	nRecValid = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid
	rc = SQLITE_OK      /* Number of rows for a single term */
	nRowEst = uint64(0) /* Loop counter */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		*(*TtRowcnt)(unsafe.Pointer(bp)) = uint64(uint64(nRow0))
		rc = _whereEqualScanEst(tls, pParse, pBuilder, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr, bp)
		nRowEst += *(*TtRowcnt)(unsafe.Pointer(bp))
		(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = nRecValid
		goto _1
	_1:
		;
		i++
	}
	if rc == SQLITE_OK {
		if nRowEst > uint64(uint64(nRow0)) {
			nRowEst = uint64(uint64(nRow0))
		}
		*(*TtRowcnt)(unsafe.Pointer(pnRow)) = nRowEst
	}
	return rc
}

// C documentation
//
//	/*
//	** Convert bulk memory into a valid WhereLoop that can be passed
//	** to whereLoopClear harmlessly.
//	*/
func _whereLoopInit(tls *libc.TLS, p uintptr) {
	(*TWhereLoop)(unsafe.Pointer(p)).FaLTerm = p + 60
	(*TWhereLoop)(unsafe.Pointer(p)).FnLTerm = uint16(0)
	(*TWhereLoop)(unsafe.Pointer(p)).FnLSlot = uint16(int32(libc.Uint32FromInt64(12) / libc.Uint32FromInt64(4)))
	(*TWhereLoop)(unsafe.Pointer(p)).FwsFlags = uint32(0)
}

// 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&uint32(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))&0x1>>0)) != 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), 0, 0x1)
			(*(*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) && (*TWhereLoop)(unsafe.Pointer(p)).Fu.Fbtree.FpIndex != uintptr(0) {
				_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(p)).Fu.Fbtree.FpIndex)).FzColAff)
				_sqlite3DbFreeNN(tls, db, (*TWhereLoop)(unsafe.Pointer(p)).Fu.Fbtree.FpIndex)
				(*TWhereLoop)(unsafe.Pointer(p)).Fu.Fbtree.FpIndex = uintptr(0)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Deallocate internal memory used by a WhereLoop object.  Leave the
//	** object in an initialized state, as if it had been newly allocated.
//	*/
func _whereLoopClear(tls *libc.TLS, db uintptr, p uintptr) {
	if (*TWhereLoop)(unsafe.Pointer(p)).FaLTerm != p+60 {
		_sqlite3DbFreeNN(tls, db, (*TWhereLoop)(unsafe.Pointer(p)).FaLTerm)
		(*TWhereLoop)(unsafe.Pointer(p)).FaLTerm = p + 60
		(*TWhereLoop)(unsafe.Pointer(p)).FnLSlot = uint16(int32(libc.Uint32FromInt64(12) / libc.Uint32FromInt64(4)))
	}
	_whereLoopClearUnion(tls, db, p)
	(*TWhereLoop)(unsafe.Pointer(p)).FnLTerm = uint16(0)
	(*TWhereLoop)(unsafe.Pointer(p)).FwsFlags = uint32(0)
}

// C documentation
//
//	/*
//	** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
//	*/
func _whereLoopResize(tls *libc.TLS, db uintptr, p uintptr, n int32) (r int32) {
	var paNew uintptr
	_ = paNew
	if int32((*TWhereLoop)(unsafe.Pointer(p)).FnLSlot) >= n {
		return SQLITE_OK
	}
	n = (n + int32(7)) & ^libc.Int32FromInt32(7)
	paNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(4)*uint32(uint32(n))))
	if paNew == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemcpy(tls, paNew, (*TWhereLoop)(unsafe.Pointer(p)).FaLTerm, uint32(4)*uint32((*TWhereLoop)(unsafe.Pointer(p)).FnLSlot))
	if (*TWhereLoop)(unsafe.Pointer(p)).FaLTerm != p+60 {
		_sqlite3DbFreeNN(tls, db, (*TWhereLoop)(unsafe.Pointer(p)).FaLTerm)
	}
	(*TWhereLoop)(unsafe.Pointer(p)).FaLTerm = paNew
	(*TWhereLoop)(unsafe.Pointer(p)).FnLSlot = uint16(uint16(n))
	return SQLITE_OK
}

// 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 int32((*TWhereLoop)(unsafe.Pointer(pFrom)).FnLTerm) > int32((*TWhereLoop)(unsafe.Pointer(pTo)).FnLSlot) && _whereLoopResize(tls, db, pTo, int32((*TWhereLoop)(unsafe.Pointer(pFrom)).FnLTerm)) != 0 {
		libc.Xmemset(tls, pTo, 0, uint32(libc.UintptrFromInt32(0)+48))
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemcpy(tls, pTo, pFrom, uint32(libc.UintptrFromInt32(0)+48))
	libc.Xmemcpy(tls, (*TWhereLoop)(unsafe.Pointer(pTo)).FaLTerm, (*TWhereLoop)(unsafe.Pointer(pFrom)).FaLTerm, uint32((*TWhereLoop)(unsafe.Pointer(pTo)).FnLTerm)*uint32(4))
	if (*TWhereLoop)(unsafe.Pointer(pFrom)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != 0 {
		libc.SetBitFieldPtr8Uint32(pFrom+24+4, libc.Uint32FromInt32(0), 0, 0x1)
	} else {
		if (*TWhereLoop)(unsafe.Pointer(pFrom)).FwsFlags&uint32(WHERE_AUTO_INDEX) != uint32(0) {
			(*TWhereLoop)(unsafe.Pointer(pFrom)).Fu.Fbtree.FpIndex = uintptr(0)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Delete a WhereLoop object
//	*/
func _whereLoopDelete(tls *libc.TLS, db uintptr, p uintptr) {
	_whereLoopClear(tls, db, p)
	_sqlite3DbNNFreeNN(tls, db, p)
}

// C documentation
//
//	/*
//	** Free a WhereInfo structure
//	*/
func _whereInfoFree(tls *libc.TLS, db uintptr, pWInfo uintptr) {
	var p, pNext uintptr
	_, _ = p, pNext
	_sqlite3WhereClauseClear(tls, pWInfo+80)
	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)
	}
	for (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree != 0 {
		pNext = (*TWhereMemBlock)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree)).FpNext
		_sqlite3DbNNFreeNN(tls, db, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree)
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree = pNext
	}
	_sqlite3DbNNFreeNN(tls, db, pWInfo)
}

// C documentation
//
//	/*
//	** Return TRUE if X is a proper subset of Y but is of equal or less cost.
//	** In other words, return true if all constraints of X are also part of Y
//	** and Y has additional constraints that might speed the search that X lacks
//	** but the cost of running X is not more than the cost of running Y.
//	**
//	** In other words, return true if the cost relationwship between X and Y
//	** is inverted and needs to be adjusted.
//	**
//	** Case 1:
//	**
//	**   (1a)  X and Y use the same index.
//	**   (1b)  X has fewer == terms than Y
//	**   (1c)  Neither X nor Y use skip-scan
//	**   (1d)  X does not have a a greater cost than Y
//	**
//	** Case 2:
//	**
//	**   (2a)  X has the same or lower cost, or returns the same or fewer rows,
//	**         than Y.
//	**   (2b)  X uses fewer WHERE clause terms than Y
//	**   (2c)  Every WHERE clause term used by X is also used by Y
//	**   (2d)  X skips at least as many columns as Y
//	**   (2e)  If X is a covering index, than Y is too
//	*/
func _whereLoopCheaperProperSubset(tls *libc.TLS, pX uintptr, pY uintptr) (r int32) {
	var i, j int32
	_, _ = i, j
	if int32((*TWhereLoop)(unsafe.Pointer(pX)).FrRun) > int32((*TWhereLoop)(unsafe.Pointer(pY)).FrRun) && int32((*TWhereLoop)(unsafe.Pointer(pX)).FnOut) > int32((*TWhereLoop)(unsafe.Pointer(pY)).FnOut) {
		return 0
	} /* (1d) and (2a) */
	if int32((*TWhereLoop)(unsafe.Pointer(pX)).Fu.Fbtree.FnEq) < int32((*TWhereLoop)(unsafe.Pointer(pY)).Fu.Fbtree.FnEq) && (*TWhereLoop)(unsafe.Pointer(pX)).Fu.Fbtree.FpIndex == (*TWhereLoop)(unsafe.Pointer(pY)).Fu.Fbtree.FpIndex && int32((*TWhereLoop)(unsafe.Pointer(pX)).FnSkip) == 0 && int32((*TWhereLoop)(unsafe.Pointer(pY)).FnSkip) == 0 {
		return int32(1) /* Case 1 is true */
	}
	if int32((*TWhereLoop)(unsafe.Pointer(pX)).FnLTerm)-int32((*TWhereLoop)(unsafe.Pointer(pX)).FnSkip) >= int32((*TWhereLoop)(unsafe.Pointer(pY)).FnLTerm)-int32((*TWhereLoop)(unsafe.Pointer(pY)).FnSkip) {
		return 0 /* (2b) */
	}
	if int32((*TWhereLoop)(unsafe.Pointer(pY)).FnSkip) > int32((*TWhereLoop)(unsafe.Pointer(pX)).FnSkip) {
		return 0
	} /* (2d) */
	i = int32((*TWhereLoop)(unsafe.Pointer(pX)).FnLTerm) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		if *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pX)).FaLTerm + uintptr(i)*4)) == uintptr(0) {
			goto _1
		}
		j = int32((*TWhereLoop)(unsafe.Pointer(pY)).FnLTerm) - int32(1)
		for {
			if !(j >= 0) {
				break
			}
			if *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pY)).FaLTerm + uintptr(j)*4)) == *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pX)).FaLTerm + uintptr(i)*4)) {
				break
			}
			goto _2
		_2:
			;
			j--
		}
		if j < 0 {
			return 0
		} /* (2c) */
		goto _1
	_1:
		;
		i--
	}
	if (*TWhereLoop)(unsafe.Pointer(pX)).FwsFlags&uint32(WHERE_IDX_ONLY) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pY)).FwsFlags&uint32(WHERE_IDX_ONLY) == uint32(0) {
		return 0 /* (2e) */
	}
	return int32(1) /* Case 2 is true */
}

// C documentation
//
//	/*
//	** Try to adjust the cost and number of output rows of WhereLoop pTemplate
//	** upwards or downwards so that:
//	**
//	**   (1) pTemplate costs less than any other WhereLoops that are a proper
//	**       subset of pTemplate
//	**
//	**   (2) pTemplate costs more than any other WhereLoops for which pTemplate
//	**       is a proper subset.
//	**
//	** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
//	** WHERE clause terms than Y and that every WHERE clause term used by X is
//	** also used by Y.
//	*/
func _whereLoopAdjustCost(tls *libc.TLS, p uintptr, pTemplate uintptr) {
	var v2, v3, v4, v5 int32
	_, _, _, _ = v2, v3, v4, v5
	if (*TWhereLoop)(unsafe.Pointer(pTemplate)).FwsFlags&uint32(WHERE_INDEXED) == uint32(0) {
		return
	}
	for {
		if !(p != 0) {
			break
		}
		if int32((*TWhereLoop)(unsafe.Pointer(p)).FiTab) != int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FiTab) {
			goto _1
		}
		if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(WHERE_INDEXED) == uint32(0) {
			goto _1
		}
		if _whereLoopCheaperProperSubset(tls, p, pTemplate) != 0 {
			/* Adjust pTemplate cost downward so that it is cheaper than its
			 ** subset p. */
			if int32((*TWhereLoop)(unsafe.Pointer(p)).FrRun) < int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun) {
				v2 = int32((*TWhereLoop)(unsafe.Pointer(p)).FrRun)
			} else {
				v2 = int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun)
			}
			(*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun = int16(v2)
			if int32((*TWhereLoop)(unsafe.Pointer(p)).FnOut)-int32(1) < int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
				v3 = int32((*TWhereLoop)(unsafe.Pointer(p)).FnOut) - int32(1)
			} else {
				v3 = int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut)
			}
			(*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut = int16(v3)
		} else {
			if _whereLoopCheaperProperSubset(tls, pTemplate, p) != 0 {
				/* Adjust pTemplate cost upward so that it is costlier than p since
				 ** pTemplate is a proper subset of p */
				if int32((*TWhereLoop)(unsafe.Pointer(p)).FrRun) > int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun) {
					v4 = int32((*TWhereLoop)(unsafe.Pointer(p)).FrRun)
				} else {
					v4 = int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun)
				}
				(*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun = int16(v4)
				if int32((*TWhereLoop)(unsafe.Pointer(p)).FnOut)+int32(1) > int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
					v5 = int32((*TWhereLoop)(unsafe.Pointer(p)).FnOut) + int32(1)
				} else {
					v5 = int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut)
				}
				(*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut = int16(v5)
			}
		}
		goto _1
	_1:
		;
		p = (*TWhereLoop)(unsafe.Pointer(p)).FpNextLoop
	}
}

// C documentation
//
//	/*
//	** Search the list of WhereLoops in *ppPrev looking for one that can be
//	** replaced by pTemplate.
//	**
//	** Return NULL if pTemplate does not belong on the WhereLoop list.
//	** In other words if pTemplate ought to be dropped from further consideration.
//	**
//	** If pX is a WhereLoop that pTemplate can replace, then return the
//	** link that points to pX.
//	**
//	** If pTemplate cannot replace any existing element of the list but needs
//	** to be added to the list as a new entry, then return a pointer to the
//	** tail of the list.
//	*/
func _whereLoopFindLesser(tls *libc.TLS, ppPrev uintptr, pTemplate uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = *(*uintptr)(unsafe.Pointer(ppPrev))
	for {
		if !(p != 0) {
			break
		}
		if int32((*TWhereLoop)(unsafe.Pointer(p)).FiTab) != int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FiTab) || int32((*TWhereLoop)(unsafe.Pointer(p)).FiSortIdx) != int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FiSortIdx) {
			/* If either the iTab or iSortIdx values for two WhereLoop are different
			 ** then those WhereLoops need to be considered separately.  Neither is
			 ** a candidate to replace the other. */
			goto _1
		}
		/* In the current implementation, the rSetup value is either zero
		 ** or the cost of building an automatic index (NlogN) and the NlogN
		 ** is the same for compatible WhereLoops. */
		/* whereLoopAddBtree() always generates and inserts the automatic index
		 ** case first.  Hence compatible candidate WhereLoops never have a larger
		 ** rSetup. Call this SETUP-INVARIANT */
		/* Any loop using an application-defined index (or PRIMARY KEY or
		 ** UNIQUE constraint) with one or more == constraints is better
		 ** than an automatic index. Unless it is a skip-scan. */
		if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(WHERE_AUTO_INDEX) != uint32(0) && int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FnSkip) == 0 && (*TWhereLoop)(unsafe.Pointer(pTemplate)).FwsFlags&uint32(WHERE_INDEXED) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pTemplate)).FwsFlags&uint32(WHERE_COLUMN_EQ) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(p)).Fprereq&(*TWhereLoop)(unsafe.Pointer(pTemplate)).Fprereq == (*TWhereLoop)(unsafe.Pointer(pTemplate)).Fprereq {
			break
		}
		/* If existing WhereLoop p is better than pTemplate, pTemplate can be
		 ** discarded.  WhereLoop p is better if:
		 **   (1)  p has no more dependencies than pTemplate, and
		 **   (2)  p has an equal or lower cost than pTemplate
		 */
		if (*TWhereLoop)(unsafe.Pointer(p)).Fprereq&(*TWhereLoop)(unsafe.Pointer(pTemplate)).Fprereq == (*TWhereLoop)(unsafe.Pointer(p)).Fprereq && int32((*TWhereLoop)(unsafe.Pointer(p)).FrSetup) <= int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FrSetup) && int32((*TWhereLoop)(unsafe.Pointer(p)).FrRun) <= int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun) && int32((*TWhereLoop)(unsafe.Pointer(p)).FnOut) <= int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
			return uintptr(0) /* Discard pTemplate */
		}
		/* If pTemplate is always better than p, then cause p to be overwritten
		 ** with pTemplate.  pTemplate is better than p if:
		 **   (1)  pTemplate has no more dependencies than p, and
		 **   (2)  pTemplate has an equal or lower cost than p.
		 */
		if (*TWhereLoop)(unsafe.Pointer(p)).Fprereq&(*TWhereLoop)(unsafe.Pointer(pTemplate)).Fprereq == (*TWhereLoop)(unsafe.Pointer(pTemplate)).Fprereq && int32((*TWhereLoop)(unsafe.Pointer(p)).FrRun) >= int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun) && int32((*TWhereLoop)(unsafe.Pointer(p)).FnOut) >= int32((*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
			/* SETUP-INVARIANT above */
			break /* Cause p to be overwritten by pTemplate */
		}
		goto _1
	_1:
		;
		ppPrev = p + 56
		p = *(*uintptr)(unsafe.Pointer(ppPrev))
	}
	return ppPrev
}

// 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--
	_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+60, 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)(unsafe.Pointer(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(72))
		p = v1
		*(*uintptr)(unsafe.Pointer(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 + 56
		for *(*uintptr)(unsafe.Pointer(ppTail)) != 0 {
			ppTail = _whereLoopFindLesser(tls, ppTail, pTemplate)
			if ppTail == uintptr(0) {
				break
			}
			pToDel = *(*uintptr)(unsafe.Pointer(ppTail))
			if pToDel == uintptr(0) {
				break
			}
			*(*uintptr)(unsafe.Pointer(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 = (*TWhereLoop)(unsafe.Pointer(p)).Fu.Fbtree.FpIndex
		if pIndex != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_IPK) {
			(*TWhereLoop)(unsafe.Pointer(p)).Fu.Fbtree.FpIndex = uintptr(0)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Adjust the WhereLoop.nOut value downward to account for terms of the
//	** WHERE clause that reference the loop but which are not used by an
//	** index.
//	*
//	** For every WHERE clause term that is not used by the index
//	** and which has a truth probability assigned by one of the likelihood(),
//	** likely(), or unlikely() SQL functions, reduce the estimated number
//	** of output rows by the probability specified.
//	**
//	** TUNING:  For every WHERE clause term that is not used by the index
//	** and which does not have an assigned truth probability, heuristics
//	** described below are used to try to estimate the truth probability.
//	** TODO --> Perhaps this is something that could be improved by better
//	** table statistics.
//	**
//	** Heuristic 1:  Estimate the truth probability as 93.75%.  The 93.75%
//	** value corresponds to -1 in LogEst notation, so this means decrement
//	** the WhereLoop.nOut field for every such WHERE clause term.
//	**
//	** Heuristic 2:  If there exists one or more WHERE clause terms of the
//	** form "x==EXPR" and EXPR is not a constant 0 or 1, then make sure the
//	** final output row estimate is no greater than 1/4 of the total number
//	** of rows in the table.  In other words, assume that x==EXPR will filter
//	** out at least 3 out of 4 rows.  If EXPR is -1 or 0 or 1, then maybe the
//	** "x" column is boolean or else -1 or 0 or 1 is a common default value
//	** on the "x" column and so in that case only cap the output row estimate
//	** at 1/2 instead of 1/4.
//	*/
func _whereLoopOutputAdjust(tls *libc.TLS, pWC uintptr, pLoop uintptr, nRow TLogEst) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, j int32
	var iReduce TLogEst
	var notAllowed TBitmask
	var pRight, pTerm, pX, p3, p4 uintptr
	var _ /* k at bp+0 */ int32
	_, _, _, _, _, _, _, _, _ = i, iReduce, j, notAllowed, pRight, pTerm, pX, p3, p4
	notAllowed = ^((*TWhereLoop)(unsafe.Pointer(pLoop)).Fprereq | (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf)
	iReduce = 0 /* pLoop->nOut should not exceed nRow-iReduce */
	i = (*TWhereClause)(unsafe.Pointer(pWC)).FnBase
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(i > 0) {
			break
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&notAllowed != uint64(0) {
			goto _1
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf == uint64(0) {
			goto _1
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VIRTUAL) != 0 {
			goto _1
		}
		j = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) - int32(1)
		for {
			if !(j >= 0) {
				break
			}
			pX = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4))
			if pX == uintptr(0) {
				goto _2
			}
			if pX == pTerm {
				break
			}
			if (*TWhereTerm)(unsafe.Pointer(pX)).FiParent >= 0 && (*TWhereClause)(unsafe.Pointer(pWC)).Fa+uintptr((*TWhereTerm)(unsafe.Pointer(pX)).FiParent)*48 == pTerm {
				break
			}
			goto _2
		_2:
			;
			j--
		}
		if j < 0 {
			_sqlite3ProgressCheck(tls, (*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf == (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll {
				/* If there are extra terms in the WHERE clause not used by an index
				 ** that depend only on the table being scanned, and that will tend to
				 ** cause many rows to be omitted, then mark that table as
				 ** "self-culling".
				 **
				 ** 2022-03-24:  Self-culling only applies if either the extra terms
				 ** are straight comparison operators that are non-true with NULL
				 ** operand, or if the loop is not an OUTER JOIN.
				 */
				if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(0x3f) != 0 || int32((*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pLoop)).FiTab)*72))).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) == 0 {
					*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= uint32(WHERE_SELFCULL)
				}
			}
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 {
				/* If a truth probability is specified using the likelihood() hints,
				 ** then use the probability provided by the application. */
				p3 = pLoop + 22
				*(*TLogEst)(unsafe.Pointer(p3)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p3))) + int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
			} else {
				/* In the absence of explicit truth probabilities, use heuristics to
				 ** guess a reasonable truth probability. */
				(*TWhereLoop)(unsafe.Pointer(pLoop)).FnOut--
				if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) != 0 && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_HIGHTRUTH) == 0 {
					pRight = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
					*(*int32)(unsafe.Pointer(bp)) = 0
					if _sqlite3ExprIsInteger(tls, pRight, bp) != 0 && *(*int32)(unsafe.Pointer(bp)) >= -int32(1) && *(*int32)(unsafe.Pointer(bp)) <= int32(1) {
						*(*int32)(unsafe.Pointer(bp)) = int32(10)
					} else {
						*(*int32)(unsafe.Pointer(bp)) = int32(20)
					}
					if int32(int32(iReduce)) < *(*int32)(unsafe.Pointer(bp)) {
						p4 = pTerm + 10
						*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(TERM_HEURTRUTH))
						iReduce = int16(*(*int32)(unsafe.Pointer(bp)))
					}
				}
			}
		}
		goto _1
	_1:
		;
		i--
		pTerm += 48
	}
	if int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnOut) > int32(int32(nRow))-int32(int32(iReduce)) {
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FnOut = int16(int32(int32(nRow)) - int32(int32(iReduce)))
	}
}

// C documentation
//
//	/*
//	** Term pTerm is a vector range comparison operation. The first comparison
//	** in the vector can be optimized using column nEq of the index. This
//	** function returns the total number of vector elements that can be used
//	** as part of the range comparison.
//	**
//	** For example, if the query is:
//	**
//	**   WHERE a = ? AND (b, c, d) > (?, ?, ?)
//	**
//	** and the index:
//	**
//	**   CREATE INDEX ... ON (a, b, c, d, e)
//	**
//	** then this function would be invoked with nEq=1. The value returned in
//	** this case is 3.
//	*/
func _whereRangeVectorLen(tls *libc.TLS, pParse uintptr, iCur int32, pIdx uintptr, nEq int32, pTerm uintptr) (r int32) {
	var aff, idxaff int8
	var i, nCmp, v1 int32
	var pColl, pLhs, pRhs uintptr
	_, _, _, _, _, _, _, _ = aff, i, idxaff, nCmp, pColl, pLhs, pRhs, v1
	nCmp = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft)
	if nCmp < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)-nEq {
		v1 = nCmp
	} else {
		v1 = int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) - nEq
	}
	nCmp = v1
	i = int32(1)
	for {
		if !(i < nCmp) {
			break
		} /* Comparison affinity */
		idxaff = 0
		pLhs = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft + 20)) + 8 + uintptr(i)*20))).FpExpr
		pRhs = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
		if (*TExpr)(unsafe.Pointer(pRhs)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			pRhs = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRhs + 20)))).FpEList + 8 + uintptr(i)*20))).FpExpr
		} else {
			pRhs = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRhs + 20)) + 8 + uintptr(i)*20))).FpExpr
		}
		/* Check that the LHS of the comparison is a column reference to
		 ** the right column of the right source table. And that the sort
		 ** order of the index column is the same as the sort order of the
		 ** leftmost index column.  */
		if int32((*TExpr)(unsafe.Pointer(pLhs)).Fop) != int32(TK_COLUMN) || (*TExpr)(unsafe.Pointer(pLhs)).FiTable != iCur || int32((*TExpr)(unsafe.Pointer(pLhs)).FiColumn) != int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i+nEq)*2))) || int32(*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i+nEq)))) != int32(*(*Tu8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(nEq)))) {
			break
		}
		aff = _sqlite3CompareAffinity(tls, pRhs, _sqlite3ExprAffinity(tls, pLhs))
		idxaff = _sqlite3TableColumnAffinity(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpTable, int32((*TExpr)(unsafe.Pointer(pLhs)).FiColumn))
		if int32(int32(aff)) != int32(int32(idxaff)) {
			break
		}
		pColl = _sqlite3BinaryCompareCollSeq(tls, pParse, pLhs, pRhs)
		if pColl == uintptr(0) {
			break
		}
		if _sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pColl)).FzName, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i+nEq)*4))) != 0 {
			break
		}
		goto _2
	_2:
		;
		i++
	}
	return i
}

/*
** Adjust the cost C by the costMult factor T.  This only occurs if
** compiled with -DSQLITE_ENABLE_COSTMULT
 */

// 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(112)
	defer tls.Free(112)
	var M, logK, nIter, nOutUnadjusted, rCostIdx, rLogSize, rSize, saved_nOut, x TLogEst
	var db, pBtm, pExpr, pExpr1, pNew, pParse, pTerm, pTop, pWInfo, v11, v24, v5, v8, v9, p12, p13, p14, p15, p16, p17, p18, p19, p2, p20, p25, p3 uintptr
	var eOp, saved_nBtm, saved_nEq, saved_nLTerm, saved_nSkip, saved_nTop, v10, v23, v4, v7 Tu16
	var i, iCol, nEq, nIn, nRecValid, nVecLen, opMask, rc, v21 int32
	var saved_prereq TBitmask
	var saved_wsFlags Tu32
	var v22 bool
	var _ /* nOut at bp+96 */ TtRowcnt
	var _ /* scan at bp+0 */ TWhereScan
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = M, 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, v10, v11, v21, v22, v23, v24, v4, v5, v7, v8, v9, p12, p13, p14, p15, p16, p17, p18, p19, p2, p20, p25, p3
	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 + 56))&0x4>>2)) != 0 || int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x100>>8)) != 0 {
		if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x4>>2)) != 0 {
			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)))
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x100>>8)) != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x2>>1)) == 0 {
			opMask &= ^(libc.Int32FromInt32(WO_EQ) | libc.Int32FromInt32(WO_IN) | libc.Int32FromInt32(WO_IS))
		}
	}
	saved_nEq = (*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq
	saved_nBtm = (*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnBtm
	saved_nTop = (*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.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, int32(int32(saved_nEq)), uint32(uint32(opMask)), pProbe)
	(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
	rSize = *(*TLogEst)(unsafe.Pointer((*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 (int32(int32(eOp)) == int32(WO_ISNULL) || int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VNULL) != 0) && _indexColumnNotNull(tls, pProbe, int32(int32(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 int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_LIKEOPT) != 0 && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) {
			goto _1
		}
		if int32((*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 int32((*TIndex)(unsafe.Pointer(pProbe)).FonError) != OE_None && int32(int32(saved_nEq)) == int32((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol)-int32(1) {
			p2 = pBuilder + 24
			*(*uint8)(unsafe.Pointer(p2)) = uint8(int32(*(*uint8)(unsafe.Pointer(p2))) | libc.Int32FromInt32(SQLITE_BLDF1_UNIQUE))
		} else {
			p3 = pBuilder + 24
			*(*uint8)(unsafe.Pointer(p3)) = uint8(int32(*(*uint8)(unsafe.Pointer(p3))) | libc.Int32FromInt32(SQLITE_BLDF1_INDEXED))
		}
		(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq = saved_nEq
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnBtm = saved_nBtm
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnTop = saved_nTop
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = saved_nLTerm
		if int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm) >= int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLSlot) && _whereLoopResize(tls, db, pNew, int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+int32(1)) != 0 {
			break /* OOM while trying to enlarge the pNew->aLTerm array */
		}
		v5 = pNew + 44
		v4 = *(*Tu16)(unsafe.Pointer(v5))
		*(*Tu16)(unsafe.Pointer(v5))++
		*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(v4)*4)) = pTerm
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = (saved_prereq | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight) & ^(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf
		if int32(int32(eOp))&int32(WO_IN) != 0 {
			pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(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 < int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)-int32(1)) {
						break
					}
					if *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*4)) != 0 && (*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*4)))).FpExpr == pExpr {
						nIn = 0
					}
					goto _6
				_6:
					;
					i++
				}
			} else {
				if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != 0 && (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr != 0 {
					/* "x IN (value, value, ...)" */
					nIn = int32(_sqlite3LogEst(tls, uint64((*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr)))
				}
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x80>>7)) != 0 && int32(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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(saved_nEq)*2))
				logK = _estLog(tls, int16(int16(nIn)))
				/* TUNING      v-----  10 to bias toward indexed IN */
				x = int16(int32(int32(M)) + int32(int32(logK)) + int32(10) - (nIn + int32(int32(rLogSize))))
				if int32(int32(x)) >= 0 {
				} else {
					if int32(int32(nInMul)) < int32(2) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_SeekScan)) == uint32(0) {
						*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_IN_SEEKSCAN)
					} else {
						goto _1
					}
				}
			}
			*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_COLUMN_IN)
		} else {
			if int32(int32(eOp))&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) != 0 {
				iCol = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiColumn + uintptr(saved_nEq)*2)))
				*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_COLUMN_EQ)
				if iCol == -int32(1) || iCol >= 0 && int32(int32(nInMul)) == 0 && int32(int32(saved_nEq)) == int32((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol)-int32(1) {
					if iCol == -int32(1) || int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x8>>3)) != 0 || int32((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol) == int32(1) && (*TIndex)(unsafe.Pointer(pProbe)).FonError != 0 && int32(int32(eOp)) == int32(WO_EQ) {
						*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_ONEROW)
					} else {
						*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_UNQ_WANTED)
					}
				}
				if int32((*(*TWhereScan)(unsafe.Pointer(bp))).FiEquiv) > int32(1) {
					*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_TRANSCONS)
				}
			} else {
				if int32(int32(eOp))&int32(WO_ISNULL) != 0 {
					*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_COLUMN_NULL)
				} else {
					nVecLen = _whereRangeVectorLen(tls, pParse, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor, pProbe, int32(int32(saved_nEq)), pTerm)
					if int32(int32(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)(unsafe.Pointer(pNew + 40)) |= uint32(libc.Int32FromInt32(WHERE_COLUMN_RANGE) | libc.Int32FromInt32(WHERE_BTM_LIMIT))
						(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnBtm = uint16(uint16(nVecLen))
						pBtm = pTerm
						pTop = uintptr(0)
						if int32((*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*48
							if _whereLoopResize(tls, db, pNew, int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+int32(1)) != 0 {
								break
							} /* OOM */
							v8 = pNew + 44
							v7 = *(*Tu16)(unsafe.Pointer(v8))
							*(*Tu16)(unsafe.Pointer(v8))++
							*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(v7)*4)) = pTop
							*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_TOP_LIMIT)
							(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnTop = uint16(1)
						}
					} else {
						*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(libc.Int32FromInt32(WHERE_COLUMN_RANGE) | libc.Int32FromInt32(WHERE_TOP_LIMIT))
						(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnTop = uint16(uint16(nVecLen))
						pTop = pTerm
						if (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags&uint32(WHERE_BTM_LIMIT) != uint32(0) {
							v9 = *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)-int32(2))*4))
						} else {
							v9 = uintptr(0)
						}
						pBtm = v9
					}
				}
			}
		}
		/* 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 {
			v11 = pNew + 24
			*(*Tu16)(unsafe.Pointer(v11))++
			v10 = *(*Tu16)(unsafe.Pointer(v11))
			nEq = int32(v10)
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 && int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiColumn + uintptr(saved_nEq)*2))) >= 0 {
				p12 = pNew + 22
				*(*TLogEst)(unsafe.Pointer(p12)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p12))) + int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
				p13 = pNew + 22
				*(*TLogEst)(unsafe.Pointer(p13)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p13))) - nIn)
			} else {
				*(*TtRowcnt)(unsafe.Pointer(bp + 96)) = uint64(0)
				if int32(int32(nInMul)) == 0 && (*TIndex)(unsafe.Pointer(pProbe)).FnSample != 0 && int32((*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq) <= (*TIndex)(unsafe.Pointer(pProbe)).FnSampleCol && (int32(int32(eOp))&int32(WO_IN) == 0 || (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(EP_xIsSelect) == uint32(0)) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
					pExpr1 = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
					if int32(int32(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+96)
					} else {
						rc = _whereInScanEst(tls, pParse, pBuilder, *(*uintptr)(unsafe.Pointer(pExpr1 + 20)), bp+96)
					}
					if rc == int32(SQLITE_NOTFOUND) {
						rc = SQLITE_OK
					}
					if rc != SQLITE_OK {
						break
					} /* Jump out of the pTerm loop */
					if *(*TtRowcnt)(unsafe.Pointer(bp + 96)) != 0 {
						(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = _sqlite3LogEst(tls, *(*TtRowcnt)(unsafe.Pointer(bp + 96)))
						if nEq == int32(1) && int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnOut)+int32(10) > int32(*(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst))) {
							p14 = pTerm + 10
							*(*Tu16)(unsafe.Pointer(p14)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p14))) | libc.Int32FromInt32(TERM_HIGHTRUTH))
							if int32((*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. */
								p15 = pBuilder + 25
								*(*uint8)(unsafe.Pointer(p15)) = uint8(int32(*(*uint8)(unsafe.Pointer(p15))) | libc.Int32FromInt32(SQLITE_BLDF2_2NDPASS))
							}
						}
						if int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnOut) > int32(int32(saved_nOut)) {
							(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
						}
						p16 = pNew + 22
						*(*TLogEst)(unsafe.Pointer(p16)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p16))) - nIn)
					}
				}
				if *(*TtRowcnt)(unsafe.Pointer(bp + 96)) == uint64(0) {
					p17 = pNew + 22
					*(*TLogEst)(unsafe.Pointer(p17)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p17))) + (int32(*(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(nEq)*2))) - int32(*(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(nEq-int32(1))*2)))))
					if int32(int32(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=?). */
						p18 = pNew + 22
						*(*TLogEst)(unsafe.Pointer(p18)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p18))) + 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 + 56))&0x3>>0)) == 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)).FpTab)).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&uint32(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
		p19 = pNew + 20
		*(*TLogEst)(unsafe.Pointer(p19)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p19))) + (int32(int32(nInMul)) + nIn))
		p20 = pNew + 22
		*(*TLogEst)(unsafe.Pointer(p20)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p20))) + (int32(int32(nInMul)) + nIn))
		_whereLoopOutputAdjust(tls, (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC, pNew, rSize)
		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) && int32((*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq) < int32((*TIndex)(unsafe.Pointer(pProbe)).FnColumn) && (int32((*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq) < int32((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol) || int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x3>>0)) != int32(SQLITE_IDXTYPE_PRIMARYKEY)) {
			if int32((*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq) > int32(3) {
				_sqlite3ProgressCheck(tls, pParse)
			}
			_whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, int16(int32(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
	(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq = saved_nEq
	(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnBtm = saved_nBtm
	(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.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 = int32(int32(saved_nEq)) == int32(int32(saved_nSkip)) && int32(int32(saved_nEq))+int32(1) < int32((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol) && int32(int32(saved_nEq)) == int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm) && int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x40>>6)) == 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x80>>7)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_SkipScan)) == uint32(0) && int32(*(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(int32(int32(saved_nEq))+int32(1))*2))) >= int32(42); v22 {
		v21 = _whereLoopResize(tls, db, pNew, int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+int32(1))
		rc = v21
	}
	if v22 && v21 == SQLITE_OK {
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq++
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip++
		v24 = pNew + 44
		v23 = *(*Tu16)(unsafe.Pointer(v24))
		*(*Tu16)(unsafe.Pointer(v24))++
		*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(v23)*4)) = uintptr(0)
		*(*Tu32)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_SKIPSCAN)
		nIter = int16(int32(*(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(saved_nEq)*2))) - int32(*(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(int32(int32(saved_nEq))+int32(1))*2))))
		p25 = pNew + 22
		*(*TLogEst)(unsafe.Pointer(p25)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p25))) - int32(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 = TLogEst(int32(nIter) + libc.Int32FromInt32(5))
		_whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, int16(int32(int32(nIter))+int32(int32(nInMul))))
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq = saved_nEq
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip = saved_nSkip
		(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
	}
	return rc
}

// 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, v4 uintptr
	var ii, jj int32
	_, _, _, _, _, _, _ = aColExpr, ii, jj, pExpr, pOB, v1, v4
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 56))&0x4>>2)) != 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)*20))).FpExpr)
		if pExpr == uintptr(0) {
			goto _2
		}
		if (int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || int32((*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 < int32((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol)) {
					break
				}
				if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) == int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(jj)*2))) {
					return int32(1)
				}
				goto _3
			_3:
				;
				jj++
			}
		} else {
			v4 = (*TIndex)(unsafe.Pointer(pIndex)).FaColExpr
			aColExpr = v4
			if v4 != uintptr(0) {
				jj = 0
				for {
					if !(jj < int32((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol)) {
						break
					}
					if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(jj)*2))) != -int32(2) {
						goto _5
					}
					if _sqlite3ExprCompareSkip(tls, pExpr, (*(*TExprList_item)(unsafe.Pointer(aColExpr + 8 + uintptr(jj)*20))).FpExpr, iCursor) == 0 {
						return int32(1)
					}
					goto _5
				_5:
					;
					jj++
				}
			}
		}
		goto _2
	_2:
		;
		ii++
	}
	return 0
}

// C documentation
//
//	/* Check to see if a partial index with pPartIndexWhere can be used
//	** in the current query.  Return true if it can be and false if not.
//	*/
func _whereUsablePartialIndex(tls *libc.TLS, iTab int32, jointype Tu8, pWC uintptr, pWhere uintptr) (r int32) {
	var i int32
	var pExpr, pParse, pTerm uintptr
	_, _, _, _ = i, pExpr, pParse, pTerm
	if int32(int32(jointype))&int32(JT_LTORJ) != 0 {
		return 0
	}
	pParse = (*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse
	for int32((*TExpr)(unsafe.Pointer(pWhere)).Fop) == int32(TK_AND) {
		if !(_whereUsablePartialIndex(tls, iTab, jointype, pWC, (*TExpr)(unsafe.Pointer(pWhere)).FpLeft) != 0) {
			return 0
		}
		pWhere = (*TExpr)(unsafe.Pointer(pWhere)).FpRight
	}
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_EnableQPSG) != 0 {
		pParse = uintptr(0)
	}
	i = 0
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(i < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
			break
		}
		pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		if (!((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) || *(*int32)(unsafe.Pointer(pExpr + 36)) == iTab) && (int32(int32(jointype))&int32(JT_OUTER) == 0 || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != uint32(0)) && _sqlite3ExprImpliesExpr(tls, pParse, pExpr, pWhere, iTab) != 0 && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VNULL) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
		pTerm += 48
	}
	return 0
}

// C documentation
//
//	/*
//	** pIdx is an index containing expressions.  Check it see if any of the
//	** expressions in the index match the pExpr expression.
//	*/
func _exprIsCoveredByIndex(tls *libc.TLS, pExpr uintptr, pIdx uintptr, iTabCur int32) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
			break
		}
		if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) == -int32(2) && _sqlite3ExprCompare(tls, uintptr(0), pExpr, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(i)*20))).FpExpr, iTabCur) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Structure passed to the whereIsCoveringIndex Walker callback.
//	*/
type TCoveringIndexCheck = struct {
	FpIdx    uintptr
	FiTabCur int32
	FbExpr   Tu8
	FbUnidx  Tu8
}

type CoveringIndexCheck = TCoveringIndexCheck

type TCoveringIndexCheck1 = struct {
	FpIdx    uintptr
	FiTabCur int32
	FbExpr   Tu8
	FbUnidx  Tu8
}

type CoveringIndexCheck1 = TCoveringIndexCheck1

// 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 + 24))
	pIdx = (*TCoveringIndexCheck)(unsafe.Pointer(pCk)).FpIdx
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || int32((*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 = (*TCoveringIndexCheck1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalk + 24)))).FpIdx
		aiColumn = (*TIndex)(unsafe.Pointer(pIdx)).FaiColumn
		nColumn = (*TIndex)(unsafe.Pointer(pIdx)).FnColumn
		i = 0
		for {
			if !(i < int32(int32(nColumn))) {
				break
			}
			if int32(*(*Ti16)(unsafe.Pointer(aiColumn + uintptr(i)*2))) == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) {
				return WRC_Continue
			}
			goto _1
		_1:
			;
			i++
		}
		(*TCoveringIndexCheck)(unsafe.Pointer(pCk)).FbUnidx = uint8(1)
		return int32(WRC_Abort)
	} else {
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x1000>>12)) != 0 && _exprIsCoveredByIndex(tls, pExpr, pIdx, (*TCoveringIndexCheck1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalk + 24)))).FiTabCur) != 0 {
			(*TCoveringIndexCheck)(unsafe.Pointer(pCk)).FbExpr = uint8(1)
			return int32(WRC_Prune)
		}
	}
	return WRC_Continue
}

// 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(48)
	defer tls.Free(48)
	var i, rc int32
	var _ /* ck at bp+0 */ TCoveringIndexCheck1
	var _ /* w at bp+12 */ 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 + 56))&0x1000>>12)) == 0 {
		i = 0
		for {
			if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
				break
			}
			if int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
				break
			}
			goto _1
		_1:
			;
			i++
		}
		if i >= int32((*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)
		}
	}
	(*(*TCoveringIndexCheck1)(unsafe.Pointer(bp))).FpIdx = pIdx
	(*(*TCoveringIndexCheck1)(unsafe.Pointer(bp))).FiTabCur = iTabCur
	(*(*TCoveringIndexCheck1)(unsafe.Pointer(bp))).FbExpr = uint8(0)
	(*(*TCoveringIndexCheck1)(unsafe.Pointer(bp))).FbUnidx = uint8(0)
	libc.Xmemset(tls, bp+12, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp + 12))).FxExprCallback = __ccgo_fp(_whereIsCoveringIndexWalkCallback)
	(*(*TWalker)(unsafe.Pointer(bp + 12))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	*(*uintptr)(unsafe.Pointer(bp + 12 + 24)) = bp
	_sqlite3WalkSelect(tls, bp+12, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)
	if (*(*TCoveringIndexCheck1)(unsafe.Pointer(bp))).FbUnidx != 0 {
		rc = 0
	} else {
		if (*(*TCoveringIndexCheck1)(unsafe.Pointer(bp))).FbExpr != 0 {
			rc = int32(WHERE_EXPRIDX)
		} else {
			rc = int32(WHERE_IDX_ONLY)
		}
	}
	return uint32(uint32(rc))
}

// C documentation
//
//	/*
//	** This is an sqlite3ParserAddCleanup() callback that is invoked to
//	** free the Parse->pIdxEpr list when the Parse object is destroyed.
//	*/
func _whereIndexedExprCleanup(tls *libc.TLS, db uintptr, pObject uintptr) {
	var p, pp uintptr
	_, _ = p, pp
	pp = pObject
	for *(*uintptr)(unsafe.Pointer(pp)) != uintptr(0) {
		p = *(*uintptr)(unsafe.Pointer(pp))
		*(*uintptr)(unsafe.Pointer(pp)) = (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext
		_sqlite3ExprDelete(tls, db, (*TIndexedExpr)(unsafe.Pointer(p)).FpExpr)
		_sqlite3DbFreeNN(tls, db, p)
	}
}

// C documentation
//
//	/*
//	** This function is called for a partial index - one with a WHERE clause - in
//	** two scenarios. In both cases, it determines whether or not the WHERE
//	** clause on the index implies that a column of the table may be safely
//	** replaced by a constant expression. For example, in the following
//	** SELECT:
//	**
//	**   CREATE INDEX i1 ON t1(b, c) WHERE a=<expr>;
//	**   SELECT a, b, c FROM t1 WHERE a=<expr> AND b=?;
//	**
//	** The "a" in the select-list may be replaced by <expr>, iff:
//	**
//	**    (a) <expr> is a constant expression, and
//	**    (b) The (a=<expr>) comparison uses the BINARY collation sequence, and
//	**    (c) Column "a" has an affinity other than NONE or BLOB.
//	**
//	** If argument pItem is NULL, then pMask must not be NULL. In this case this
//	** function is being called as part of determining whether or not pIdx
//	** is a covering index. This function clears any bits in (*pMask)
//	** corresponding to columns that may be replaced by constants as described
//	** above.
//	**
//	** Otherwise, if pItem is not NULL, then this function is being called
//	** as part of coding a loop that uses index pIdx. In this case, add entries
//	** to the Parse.pIdxPartExpr list for each column that can be replaced
//	** by a constant.
//	*/
func _wherePartIdxExpr(tls *libc.TLS, pParse uintptr, pIdx uintptr, pPart uintptr, pMask uintptr, iIdxCur int32, pItem uintptr) {
	var aff Tu8
	var bNullRow int32
	var db, p, pArg, pLeft, pRight uintptr
	_, _, _, _, _, _, _ = aff, bNullRow, db, p, pArg, pLeft, pRight
	if int32((*TExpr)(unsafe.Pointer(pPart)).Fop) == int32(TK_AND) {
		_wherePartIdxExpr(tls, pParse, pIdx, (*TExpr)(unsafe.Pointer(pPart)).FpRight, pMask, iIdxCur, pItem)
		pPart = (*TExpr)(unsafe.Pointer(pPart)).FpLeft
	}
	if int32((*TExpr)(unsafe.Pointer(pPart)).Fop) == int32(TK_EQ) || int32((*TExpr)(unsafe.Pointer(pPart)).Fop) == int32(TK_IS) {
		pLeft = (*TExpr)(unsafe.Pointer(pPart)).FpLeft
		pRight = (*TExpr)(unsafe.Pointer(pPart)).FpRight
		if int32((*TExpr)(unsafe.Pointer(pLeft)).Fop) != int32(TK_COLUMN) {
			return
		}
		if !(_sqlite3ExprIsConstant(tls, uintptr(0), pRight) != 0) {
			return
		}
		if !(_sqlite3IsBinary(tls, _sqlite3ExprCompareCollSeq(tls, pParse, pPart)) != 0) {
			return
		}
		if int32((*TExpr)(unsafe.Pointer(pLeft)).FiColumn) < 0 {
			return
		}
		aff = uint8((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr((*TExpr)(unsafe.Pointer(pLeft)).FiColumn)*12))).Faffinity)
		if int32(int32(aff)) >= int32(SQLITE_AFF_TEXT) {
			if pItem != 0 {
				db = (*TParse)(unsafe.Pointer(pParse)).Fdb
				p = _sqlite3DbMallocRaw(tls, db, uint64(24))
				if p != 0 {
					bNullRow = libc.BoolInt32(int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) != 0)
					(*TIndexedExpr)(unsafe.Pointer(p)).FpExpr = _sqlite3ExprDup(tls, db, pRight, 0)
					(*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
					(*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur = iIdxCur
					(*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol = int32((*TExpr)(unsafe.Pointer(pLeft)).FiColumn)
					(*TIndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow = uint8(uint8(bNullRow))
					(*TIndexedExpr)(unsafe.Pointer(p)).FpIENext = (*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr
					(*TIndexedExpr)(unsafe.Pointer(p)).Faff = aff
					(*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr = p
					if (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext == uintptr(0) {
						pArg = pParse + 76
						_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_whereIndexedExprCleanup), pArg)
					}
				}
			} else {
				if int32((*TExpr)(unsafe.Pointer(pLeft)).FiColumn) < int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
					*(*TBitmask)(unsafe.Pointer(pMask)) &= ^(libc.Uint64FromInt32(1) << (*TExpr)(unsafe.Pointer(pLeft)).FiColumn)
				}
			}
		}
	}
}

// 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(128)
	defer tls.Free(128)
	var b, iCur, iSortIdx, ii, rc, v5, v6 int32
	var isCov Tu32
	var nLookup, rLogSize, rSize TLogEst
	var pFirst, pNew, pProbe, pSrc, pTab, pTabList, pTerm, pTerm1, pWC, pWC2, pWCEnd, pWInfo, v8, p2, p3 uintptr
	var _ /* aiColumnPk at bp+108 */ Ti16
	var _ /* aiRowEstPk at bp+104 */ [2]TLogEst
	var _ /* m at bp+112 */ 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, v5, v6, v8, p2, p3 /* The aiRowLogEst[] value for the sPk index */
	*(*Ti16)(unsafe.Pointer(bp + 108)) = 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)*72
	pTab = (*TSrcItem)(unsafe.Pointer(pSrc)).FpTab
	pWC = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x2>>1)) != 0 {
		/* An INDEXED BY clause specifies a particular index to use */
		pProbe = *(*uintptr)(unsafe.Pointer(pSrc + 68))
	} 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, uint32(104))
			(*(*TIndex)(unsafe.Pointer(bp))).FnKeyCol = uint16(1)
			(*(*TIndex)(unsafe.Pointer(bp))).FnColumn = uint16(1)
			(*(*TIndex)(unsafe.Pointer(bp))).FaiColumn = bp + 108
			(*(*TIndex)(unsafe.Pointer(bp))).FaiRowLogEst = bp + 104
			(*(*TIndex)(unsafe.Pointer(bp))).FonError = uint8(OE_Replace)
			(*(*TIndex)(unsafe.Pointer(bp))).FpTable = pTab
			(*(*TIndex)(unsafe.Pointer(bp))).FszIdxRow = int16(3) /* TUNING: Interior rows of IPK table are very small */
			libc.SetBitFieldPtr16Uint32(bp+56, libc.Uint32FromInt32(SQLITE_IDXTYPE_IPK), 0, 0x3)
			(*(*[2]TLogEst)(unsafe.Pointer(bp + 104)))[0] = (*TTable)(unsafe.Pointer(pTab)).FnRowLogEst
			(*(*[2]TLogEst)(unsafe.Pointer(bp + 104)))[int32(1)] = 0
			pFirst = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpTab)).FpIndex
			if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x1>>0)) == 0 {
				/* The real indices of the table are only considered if the
				 ** NOT INDEXED qualifier is omitted from the FROM clause */
				(*(*TIndex)(unsafe.Pointer(bp))).FpNext = pFirst
			}
			pProbe = bp
		}
	}
	rSize = (*TTable)(unsafe.Pointer(pTab)).FnRowLogEst
	/* Automatic indexes */
	if !((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != 0) && int32((*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(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x2>>1)) != 0) && !(int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x1>>0)) != 0) && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && !(int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x8>>3)) != 0) && !(int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x40>>6)) != 0) && int32((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
		pWCEnd = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm)*48
		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 {
				(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq = uint16(1)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip = uint16(0)
				(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FpIndex = uintptr(0)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = uint16(1)
				*(*uintptr)(unsafe.Pointer((*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(int32(rLogSize)) + int32(int32(rSize)))
				if !(int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Ephemeral) == uint32(0) {
					p2 = pNew + 18
					*(*TLogEst)(unsafe.Pointer(p2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p2))) + libc.Int32FromInt32(28))
				} else {
					p3 = pNew + 18
					*(*TLogEst)(unsafe.Pointer(p3)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p3))) - 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 += 48
		}
	}
	/* 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 + 56))&0x200>>9)) != 0 {
			goto _4
		}
		rSize = *(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst))
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnEq = uint16(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnBtm = uint16(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FnTop = 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
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fu.Fbtree.FpIndex = pProbe
		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 + 56))&0x3>>0)) == 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 = uint8(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(int32(rSize)) + int32(16) - int32(2)*libc.BoolInt32((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasStat4) != uint32(0)))
			_whereLoopOutputAdjust(tls, pWC, pNew, rSize)
			rc = _whereLoopInsert(tls, pBuilder, pNew)
			(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = rSize
			if rc != 0 {
				break
			}
		} else {
			if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x20>>5)) != 0 {
				*(*TBitmask)(unsafe.Pointer(bp + 112)) = uint64(0)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(libc.Int32FromInt32(WHERE_IDX_ONLY) | libc.Int32FromInt32(WHERE_INDEXED))
			} else {
				*(*TBitmask)(unsafe.Pointer(bp + 112)) = (*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+112, 0, uintptr(0))
				}
				(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(WHERE_INDEXED)
				if *(*TBitmask)(unsafe.Pointer(bp + 112)) == libc.Uint64FromInt32(1)<<(int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1)) || int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x1000>>12)) != 0 && !(int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x800>>11)) != 0) && *(*TBitmask)(unsafe.Pointer(bp + 112)) != uint64(0) {
					isCov = _whereIsCoveringIndex(tls, pWInfo, pProbe, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor)
					if isCov == uint32(0) {
					} else {
						*(*TBitmask)(unsafe.Pointer(bp + 112)) = uint64(0)
						*(*Tu32)(unsafe.Pointer(pNew + 40)) |= isCov
						if isCov&uint32(WHERE_IDX_ONLY) != 0 {
						} else {
						}
					}
				} else {
					if *(*TBitmask)(unsafe.Pointer(bp + 112)) == uint64(0) {
						(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(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(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x2>>1)) != 0 || *(*TBitmask)(unsafe.Pointer(bp + 112)) == uint64(0) && int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 56))&0x4>>2)) == 0 && int32((*TIndex)(unsafe.Pointer(pProbe)).FszIdxRow) < int32((*TTable)(unsafe.Pointer(pTab)).FszTabRow) && int32((*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&uint32(libc.Int32FromInt32(SQLITE_CoverIdxScan)) == uint32(0) {
				if b != 0 {
					v6 = iSortIdx
				} else {
					v6 = 0
				}
				(*TWhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = uint8(v6)
				/* 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(int32(rSize)) + int32(1) + int32(15)*int32((*TIndex)(unsafe.Pointer(pProbe)).FszIdxRow)/int32((*TTable)(unsafe.Pointer(pTab)).FszTabRow))
				if *(*TBitmask)(unsafe.Pointer(bp + 112)) != 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(int32(rSize)) + int32(16))
					iCur = (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor
					pWC2 = pWInfo + 80
					ii = 0
					for {
						if !(ii < (*TWhereClause)(unsafe.Pointer(pWC2)).FnTerm) {
							break
						}
						pTerm1 = (*TWhereClause)(unsafe.Pointer(pWC2)).Fa + uintptr(ii)*48
						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 = TLogEst(int32(nLookup) + int32((*TWhereTerm)(unsafe.Pointer(pTerm1)).FtruthProb))
						} else {
							nLookup--
							if int32((*TWhereTerm)(unsafe.Pointer(pTerm1)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) != 0 {
								nLookup = TLogEst(int32(nLookup) - libc.Int32FromInt32(19))
							}
						}
						goto _7
					_7:
						;
						ii++
					}
					(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = _sqlite3LogEstAdd(tls, (*TWhereLoop)(unsafe.Pointer(pNew)).FrRun, nLookup)
				}
				_whereLoopOutputAdjust(tls, pWC, pNew, rSize)
				if int32((*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 {
					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 int32((*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)(unsafe.Pointer(pTab + 28)) |= 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(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x2>>1)) != 0 {
			v8 = uintptr(0)
		} else {
			v8 = (*TIndex)(unsafe.Pointer(pProbe)).FpNext
		}
		pProbe = v8
		iSortIdx++
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if pTerm is a virtual table LIMIT or OFFSET term.
//	*/
func _isLimitTerm(tls *libc.TLS, pTerm uintptr) (r int32) {
	return libc.BoolInt32(int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) >= int32(SQLITE_INDEX_CONSTRAINT_LIMIT) && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) <= int32(SQLITE_INDEX_CONSTRAINT_OFFSET))
}

// C documentation
//
//	/*
//	** Return true if the first nCons constraints in the pUsage array are
//	** marked as in-use (have argvIndex>0). False otherwise.
//	*/
func _allConstraintsUsed(tls *libc.TLS, aUsage uintptr, nCons int32) (r int32) {
	var ii int32
	_ = ii
	ii = 0
	for {
		if !(ii < nCons) {
			break
		}
		if (*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer(aUsage + uintptr(ii)*8))).FargvIndex <= 0 {
			return 0
		}
		goto _1
	_1:
		;
		ii++
	}
	return int32(1)
}

// 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, v7 int32
	var pHidden, pIdxCons, pNew, pParse, pSrc, pTerm, pTerm1, pUsage, pWC, p4 uintptr
	var v5 uint32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iTerm, j, mxTerm, nConstraint, pHidden, pIdxCons, pNew, pParse, pSrc, pTerm, pTerm1, pUsage, pWC, rc, v3, v5, v7, p4
	pWC = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	pHidden = pIdxInfo + 1*72
	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)*72
	nConstraint = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint
	*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(pIdxInfo + 4))
	i = 0
	for {
		if !(i < nConstraint) {
			break
		}
		pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset)*48
		(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(0)
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUsable == (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight && int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(int32(mExclude)) == 0 && (pbRetryLimit != 0 || !(_isLimitTerm(tls, pTerm) != 0)) {
			(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(1)
		}
		goto _1
	_1:
		;
		i++
		pIdxCons += 12
	}
	/* Initialize the output fields of the sqlite3_index_info structure */
	libc.Xmemset(tls, pUsage, 0, uint32(8)*uint32(uint32(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
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FcolUsed = uint64(int64((*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed))
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmHandleIn = uint32(0)
	/* Invoke the virtual table xBestIndex() method */
	rc = _vtabBestIndex(tls, pParse, (*TSrcItem)(unsafe.Pointer(pSrc)).FpTab, 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.
			 */
			return SQLITE_OK
		}
		return rc
	}
	mxTerm = -int32(1)
	libc.Xmemset(tls, (*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm, 0, uint32(4)*uint32(uint32(nConstraint)))
	libc.Xmemset(tls, pNew+24, 0, uint32(16))
	pIdxCons = *(*uintptr)(unsafe.Pointer(pIdxInfo + 4))
	i = 0
	for {
		if !(i < nConstraint) {
			break
		}
		v3 = (*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer(pUsage + uintptr(i)*8))).FargvIndex - libc.Int32FromInt32(1)
		iTerm = v3
		if v3 >= 0 {
			j = (*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset
			if iTerm >= nConstraint || j < 0 || j >= (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm || *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*4)) != uintptr(0) || int32((*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable) == 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23902, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpTab)).FzName))
				return int32(SQLITE_ERROR)
			}
			pTerm1 = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(j)*48
			*(*TBitmask)(unsafe.Pointer(pNew)) |= (*TWhereTerm)(unsafe.Pointer(pTerm1)).FprereqRight
			*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*4)) = pTerm1
			if iTerm > mxTerm {
				mxTerm = iTerm
			}
			if (*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer(pUsage + uintptr(i)*8))).Fomit != 0 {
				if i < int32(16) && int32(1)<<i&int32(int32(mNoOmit)) == 0 {
					p4 = pNew + 24 + 6
					*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(1)<<iTerm)
				} else {
				}
				if int32((*TWhereTerm)(unsafe.Pointer(pTerm1)).FeMatchOp) == int32(SQLITE_INDEX_CONSTRAINT_OFFSET) {
					libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32(1), 1, 0x2)
				}
			}
			if i <= int32(31) {
				v5 = libc.Uint32FromInt32(1) << i
			} else {
				v5 = uint32(0)
			}
			if v5&(*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 int32((*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)(unsafe.Pointer(pIdxInfo + 56)) &= ^libc.Int32FromInt32(SQLITE_INDEX_SCAN_UNIQUE)
					*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(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. */
				if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr != 0 {
					Xsqlite3_free(tls, (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr)
					(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = uintptr(0)
					(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = 0
				}
				*(*int32)(unsafe.Pointer(pbRetryLimit)) = int32(1)
				return SQLITE_OK
			}
		}
		goto _2
	_2:
		;
		i++
		pIdxCons += 12
	}
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = uint16(mxTerm + int32(1))
	i = 0
	for {
		if !(i <= mxTerm) {
			break
		}
		if *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*4)) == uintptr(0) {
			/* The non-zero argvIdx values must be contiguous.  Raise an
			 ** error if they are not */
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23902, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpTab)).FzName))
			return int32(SQLITE_ERROR)
		}
		goto _6
	_6:
		;
		i++
	}
	(*(*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, uint32((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr), 0, 0x1)
	(*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 {
		v7 = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy
	} else {
		v7 = 0
	}
	(*(*struct {
		FidxNum    int32
		F__ccgo4   uint8
		FisOrdered Ti8
		FomitMask  Tu16
		FidxStr    uintptr
		FmHandleIn Tu32
	})(unsafe.Pointer(pNew + 24))).FisOrdered = int8(v7)
	(*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, uint64((*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)(unsafe.Pointer(pNew + 40)) |= uint32(WHERE_ONEROW)
	} else {
		*(*Tu32)(unsafe.Pointer(pNew + 40)) &= uint32(^libc.Int32FromInt32(WHERE_ONEROW))
	}
	rc = _whereLoopInsert(tls, pBuilder, pNew)
	if int32(Tu32(*(*uint8)(unsafe.Pointer(pNew + 24 + 4))&0x1>>0)) != 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), 0, 0x1)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the collating sequence for a constraint passed into xBestIndex.
//	**
//	** pIdxInfo must be an sqlite3_index_info structure passed into xBestIndex.
//	** This routine depends on there being a HiddenIndexInfo structure immediately
//	** following the sqlite3_index_info structure.
//	**
//	** Return a pointer to the collation name:
//	**
//	**    1. If there is an explicit COLLATE operator on the constraint, return it.
//	**
//	**    2. Else, if the column has an alternative collation, return that.
//	**
//	**    3. Otherwise, return "BINARY".
//	*/
func Xsqlite3_vtab_collation(tls *libc.TLS, pIdxInfo uintptr, iCons int32) (r uintptr) {
	var iTerm int32
	var pC, pHidden, pX, zRet, v1 uintptr
	_, _, _, _, _, _ = iTerm, pC, pHidden, pX, zRet, v1
	pHidden = pIdxInfo + 1*72
	zRet = uintptr(0)
	if iCons >= 0 && iCons < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint {
		pC = uintptr(0)
		iTerm = (*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(iCons)*12))).FiTermOffset
		pX = (*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer((*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FpWC)).Fa + uintptr(iTerm)*48))).FpExpr
		if (*TExpr)(unsafe.Pointer(pX)).FpLeft != 0 {
			pC = _sqlite3ExprCompareCollSeq(tls, (*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FpParse, pX)
		}
		if pC != 0 {
			v1 = (*TCollSeq)(unsafe.Pointer(pC)).FzName
		} else {
			v1 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
		}
		zRet = v1
	}
	return zRet
}

// C documentation
//
//	/*
//	** Return true if constraint iCons is really an IN(...) constraint, or
//	** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
//	** or clear (if bHandle==0) the flag to handle it using an iterator.
//	*/
func Xsqlite3_vtab_in(tls *libc.TLS, pIdxInfo uintptr, iCons int32, bHandle int32) (r int32) {
	var m Tu32
	var pHidden uintptr
	var v1 uint32
	_, _, _ = m, pHidden, v1
	pHidden = pIdxInfo + 1*72
	if iCons <= int32(31) {
		v1 = libc.Uint32FromInt32(1) << iCons
	} else {
		v1 = uint32(0)
	}
	m = v1
	if m&(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmIn != 0 {
		if bHandle == 0 {
			*(*Tu32)(unsafe.Pointer(pHidden + 16)) &= ^m
		} else {
			if bHandle > 0 {
				*(*Tu32)(unsafe.Pointer(pHidden + 16)) |= m
			}
		}
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** This interface is callable from within the xBestIndex callback only.
//	**
//	** If possible, set (*ppVal) to point to an object containing the value
//	** on the right-hand-side of constraint iCons.
//	*/
func Xsqlite3_vtab_rhs_value(tls *libc.TLS, pIdxInfo uintptr, iCons int32, ppVal uintptr) (r int32) {
	var pH, pTerm, pVal uintptr
	var rc int32
	_, _, _, _ = pH, pTerm, pVal, rc
	pH = pIdxInfo + 1*72
	pVal = uintptr(0)
	rc = SQLITE_OK
	if iCons < 0 || iCons >= (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint {
		rc = _sqlite3MisuseError(tls, int32(166453)) /* EV: R-30545-25046 */
	} else {
		if *(*uintptr)(unsafe.Pointer(pH + 20 + uintptr(iCons)*4)) == uintptr(0) {
			pTerm = (*TWhereClause)(unsafe.Pointer((*THiddenIndexInfo)(unsafe.Pointer(pH)).FpWC)).Fa + uintptr((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(iCons)*12))).FiTermOffset)*48
			rc = _sqlite3ValueFromExpr(tls, (*TParse)(unsafe.Pointer((*THiddenIndexInfo)(unsafe.Pointer(pH)).FpParse)).Fdb, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight, (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*THiddenIndexInfo)(unsafe.Pointer(pH)).FpParse)).Fdb)).Fenc, uint8(SQLITE_AFF_BLOB), pH+20+uintptr(iCons)*4)
		}
		pVal = *(*uintptr)(unsafe.Pointer(pH + 20 + uintptr(iCons)*4))
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = pVal
	if rc == SQLITE_OK && pVal == uintptr(0) { /* IMP: R-19933-32160 */
		rc = int32(SQLITE_NOTFOUND) /* IMP: R-36424-56542 */
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if ORDER BY clause may be handled as DISTINCT.
//	*/
func Xsqlite3_vtab_distinct(tls *libc.TLS, pIdxInfo uintptr) (r int32) {
	var pHidden uintptr
	_ = pHidden
	pHidden = pIdxInfo + 1*72
	return (*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FeDistinct
}

// C documentation
//
//	/*
//	** Cause the prepared statement that is associated with a call to
//	** xBestIndex to potentially use all schemas.  If the statement being
//	** prepared is read-only, then just start read transactions on all
//	** schemas.  But if this is a write operation, start writes on all
//	** schemas.
//	**
//	** This is used by the (built-in) sqlite_dbpage virtual table.
//	*/
func _sqlite3VtabUsesAllSchemas(tls *libc.TLS, pParse uintptr) {
	var i, nDb int32
	_, _ = i, nDb
	nDb = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnDb
	i = 0
	for {
		if !(i < nDb) {
			break
		}
		_sqlite3CodeVerifySchema(tls, pParse, i)
		goto _1
	_1:
		;
		i++
	}
	if (*TParse)(unsafe.Pointer(pParse)).FwriteMask != uint32(0) {
		i = 0
		for {
			if !(i < nDb) {
				break
			}
			_sqlite3BeginWriteOperation(tls, pParse, 0, i)
			goto _2
		_2:
			;
			i++
		}
	}
}

// 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, 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, mBest, mBestNoIn, mNext, mPrev, mThis, nConstraint, p, pNew, pParse, pSrc, pWC, pWInfo, rc, seenZero, seenZeroNoIN, v1, v2
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(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)*72
	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), 0, 0x1)
	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, uint64(-libc.Int32FromInt32(1)), uint16(0), p, *(*Tu16)(unsafe.Pointer(bp + 4)), bp, bp+8)
	if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
		rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, uint64(-libc.Int32FromInt32(1)), uint16(0), p, *(*Tu16)(unsafe.Pointer(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)(unsafe.Pointer(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)(unsafe.Pointer(bp)) != 0 {
			rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, uint64(-libc.Int32FromInt32(1)), uint16(WO_IN), p, *(*Tu16)(unsafe.Pointer(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 = uint64(-libc.Int32FromInt32(1))
			i = 0
			for {
				if !(i < nConstraint) {
					break
				}
				mThis = (*(*TWhereTerm)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(p)).FaConstraint + uintptr(i)*12))).FiTermOffset)*48))).FprereqRight & ^mPrereq
				if mThis > mPrev && mThis < mNext {
					mNext = mThis
				}
				goto _3
			_3:
				;
				i++
			}
			mPrev = mNext
			if mNext == uint64(-libc.Int32FromInt32(1)) {
				break
			}
			if mNext == mBest || mNext == mBestNoIn {
				continue
			}
			rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, mNext|mPrereq, uint16(0), p, *(*Tu16)(unsafe.Pointer(bp + 4)), bp, uintptr(0))
			if (*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq == mPrereq {
				seenZero = int32(1)
				if *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp + 4)), bp, uintptr(0))
			if *(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp + 4)), bp, uintptr(0))
		}
	}
	if (*Tsqlite3_index_info)(unsafe.Pointer(p)).FneedToFreeIdxStr != 0 {
		Xsqlite3_free(tls, (*Tsqlite3_index_info)(unsafe.Pointer(p)).FidxStr)
	}
	_freeIndexInfo(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, p)
	return rc
}

// C documentation
//
//	/*
//	** Add WhereLoop entries to handle OR terms.  This works for either
//	** btrees or virtual tables.
//	*/
func _whereLoopAddOr(tls *libc.TLS, pBuilder uintptr, mPrereq TBitmask, mUnusable TBitmask) (r int32) {
	bp := tls.Alloc(624)
	defer tls.Free(624)
	var i, iCur, j, once, rc int32
	var pItem, pNew, pOrTerm, pOrWC, pOrWCEnd, pTerm, pWC, pWCEnd, pWInfo uintptr
	var _ /* sCur at bp+504 */ TWhereOrSet
	var _ /* sPrev at bp+560 */ TWhereOrSet
	var _ /* sSubBuild at bp+416 */ TWhereLoopBuilder
	var _ /* sSum at bp+448 */ TWhereOrSet
	var _ /* tempWC at bp+0 */ TWhereClause
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iCur, j, once, pItem, pNew, pOrTerm, pOrWC, pOrWCEnd, pTerm, pWC, pWCEnd, pWInfo, rc
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	rc = SQLITE_OK
	pWC = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	pWCEnd = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm)*48
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	libc.Xmemset(tls, bp+448, 0, uint32(56))
	pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pNew)).FiTab)*72
	iCur = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
	/* The multi-index OR optimization does not work for RIGHT and FULL JOIN */
	if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
		return SQLITE_OK
	}
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(pTerm < pWCEnd && rc == SQLITE_OK) {
			break
		}
		if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_OR) != 0 && (*TWhereOrInfo)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pTerm)).Fu)))).Findexable&(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf != uint64(0) {
			pOrWC = *(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pTerm)).Fu))
			pOrWCEnd = (*TWhereClause)(unsafe.Pointer(pOrWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pOrWC)).FnTerm)*48
			once = int32(1)
			*(*TWhereLoopBuilder)(unsafe.Pointer(bp + 416)) = *(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder))
			(*(*TWhereLoopBuilder)(unsafe.Pointer(bp + 416))).FpOrSet = bp + 504
			pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWC)).Fa
			for {
				if !(pOrTerm < pOrWCEnd) {
					break
				}
				if int32((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&int32(WO_AND) != 0 {
					(*(*TWhereLoopBuilder)(unsafe.Pointer(bp + 416))).FpWC = *(*uintptr)(unsafe.Pointer(&(*TWhereTerm)(unsafe.Pointer(pOrTerm)).Fu))
				} else {
					if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCur {
						(*(*TWhereClause)(unsafe.Pointer(bp))).FpWInfo = (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo
						(*(*TWhereClause)(unsafe.Pointer(bp))).FpOuter = pWC
						(*(*TWhereClause)(unsafe.Pointer(bp))).Fop = uint8(TK_AND)
						(*(*TWhereClause)(unsafe.Pointer(bp))).FnTerm = int32(1)
						(*(*TWhereClause)(unsafe.Pointer(bp))).FnBase = int32(1)
						(*(*TWhereClause)(unsafe.Pointer(bp))).Fa = pOrTerm
						(*(*TWhereLoopBuilder)(unsafe.Pointer(bp + 416))).FpWC = bp
					} else {
						goto _2
					}
				}
				(*(*TWhereOrSet)(unsafe.Pointer(bp + 504))).Fn = uint16(0)
				if int32((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpTab)).FeTabType) == int32(TABTYP_VTAB) {
					rc = _whereLoopAddVirtual(tls, bp+416, mPrereq, mUnusable)
				} else {
					rc = _whereLoopAddBtree(tls, bp+416, mPrereq)
				}
				if rc == SQLITE_OK {
					rc = _whereLoopAddOr(tls, bp+416, mPrereq, mUnusable)
				}
				if int32((*(*TWhereOrSet)(unsafe.Pointer(bp + 504))).Fn) == 0 {
					(*(*TWhereOrSet)(unsafe.Pointer(bp + 448))).Fn = uint16(0)
					break
				} else {
					if once != 0 {
						_whereOrMove(tls, bp+448, bp+504)
						once = 0
					} else {
						_whereOrMove(tls, bp+560, bp+448)
						(*(*TWhereOrSet)(unsafe.Pointer(bp + 448))).Fn = uint16(0)
						i = 0
						for {
							if !(i < int32((*(*TWhereOrSet)(unsafe.Pointer(bp + 560))).Fn)) {
								break
							}
							j = 0
							for {
								if !(j < int32((*(*TWhereOrSet)(unsafe.Pointer(bp + 504))).Fn)) {
									break
								}
								_whereOrInsert(tls, bp+448, (*(*TWhereOrCost)(unsafe.Pointer(bp + 560 + 8 + uintptr(i)*16))).Fprereq|(*(*TWhereOrCost)(unsafe.Pointer(bp + 504 + 8 + uintptr(j)*16))).Fprereq, _sqlite3LogEstAdd(tls, (*(*TWhereOrCost)(unsafe.Pointer(bp + 560 + 8 + uintptr(i)*16))).FrRun, (*(*TWhereOrCost)(unsafe.Pointer(bp + 504 + 8 + uintptr(j)*16))).FrRun), _sqlite3LogEstAdd(tls, (*(*TWhereOrCost)(unsafe.Pointer(bp + 560 + 8 + uintptr(i)*16))).FnOut, (*(*TWhereOrCost)(unsafe.Pointer(bp + 504 + 8 + uintptr(j)*16))).FnOut))
								goto _4
							_4:
								;
								j++
							}
							goto _3
						_3:
							;
							i++
						}
					}
				}
				goto _2
			_2:
				;
				pOrTerm += 48
			}
			(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = uint16(1)
			*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm)) = pTerm
			(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(WHERE_MULTI_OR)
			(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
			(*TWhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = uint8(0)
			libc.Xmemset(tls, pNew+24, 0, uint32(16))
			i = 0
			for {
				if !(rc == SQLITE_OK && i < int32((*(*TWhereOrSet)(unsafe.Pointer(bp + 448))).Fn)) {
					break
				}
				/* TUNING: Currently sSum.a[i].rRun is set to the sum of the costs
				 ** of all sub-scans required by the OR-scan. However, due to rounding
				 ** errors, it may be that the cost of the OR-scan is equal to its
				 ** most expensive sub-scan. Add the smallest possible penalty
				 ** (equivalent to multiplying the cost by 1.07) to ensure that
				 ** this does not happen. Otherwise, for WHERE clauses such as the
				 ** following where there is an index on "y":
				 **
				 **     WHERE likelihood(x=?, 0.99) OR y=?
				 **
				 ** the planner may elect to "OR" together a full-table scan and an
				 ** index lookup. And other similarly odd results.  */
				(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = int16(int32((*(*TWhereOrCost)(unsafe.Pointer(bp + 448 + 8 + uintptr(i)*16))).FrRun) + int32(1))
				(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = (*(*TWhereOrCost)(unsafe.Pointer(bp + 448 + 8 + uintptr(i)*16))).FnOut
				(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = (*(*TWhereOrCost)(unsafe.Pointer(bp + 448 + 8 + uintptr(i)*16))).Fprereq
				rc = _whereLoopInsert(tls, pBuilder, pNew)
				goto _5
			_5:
				;
				i++
			}
		}
		goto _1
	_1:
		;
		pTerm += 48
	}
	return rc
}

// C documentation
//
//	/*
//	** Add all WhereLoop objects for all tables
//	*/
func _whereLoopAddAll(tls *libc.TLS, pBuilder uintptr) (r int32) {
	var bFirstPastRJ, hasRightJoin, iTab, rc int32
	var db, p, pEnd, pItem, pNew, pTabList, pWInfo uintptr
	var mPrereq, mPrior, mUnusable TBitmask
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bFirstPastRJ, db, hasRightJoin, iTab, mPrereq, mPrior, mUnusable, p, pEnd, pItem, pNew, pTabList, 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)*72
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	rc = SQLITE_OK
	bFirstPastRJ = 0
	hasRightJoin = 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 = uint8(uint8(iTab))
		*(*uint32)(unsafe.Pointer(pBuilder + 28)) += uint32(SQLITE_QUERY_PLANNER_LIMIT_INCR)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf = _sqlite3WhereGetMask(tls, pWInfo+496, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor)
		if bFirstPastRJ != 0 || int32((*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 JT_LTORJ case and the hasRightJoin flag work together to
			 ** prevent FROM-clause terms from moving from the right side of
			 ** a LEFT JOIN over to the left side of that join if the LEFT JOIN
			 ** is itself on the left side of a RIGHT JOIN.
			 */
			if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
				hasRightJoin = int32(1)
			}
			mPrereq |= mPrior
			bFirstPastRJ = libc.BoolInt32(int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0)
		} else {
			if !(hasRightJoin != 0) {
				mPrereq = uint64(0)
			}
		}
		if int32((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpTab)).FeTabType) == int32(TABTYP_VTAB) {
			p = pItem + 1*72
			for {
				if !(p < pEnd) {
					break
				}
				if mUnusable != 0 || int32((*TSrcItem)(unsafe.Pointer(p)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0 {
					mUnusable |= _sqlite3WhereGetMask(tls, pWInfo+496, (*TSrcItem)(unsafe.Pointer(p)).FiCursor)
				}
				goto _2
			_2:
				;
				p += 72
			}
			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 |= (*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+23928, 0)
				rc = SQLITE_OK
			} else {
				break
			}
		}
		goto _1
	_1:
		;
		iTab++
		pItem += 72
	}
	_whereLoopClear(tls, db, pNew)
	return rc
}

// 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) {
	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, obSat, orderDistinctMask, ready TBitmask
	var v11 uint64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bOnce, db, distinctColumns, eOp, eqOpMask, i, iColumn, iCur, iLoop, isMatch, isOrderDistinct, j, m, mTerm, nColumn, nKeyCol, nOrderBy, obDone, obSat, 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 */
	obSat = 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&uint32(libc.Int32FromInt32(SQLITE_OrderByIdxJoin)) != uint32(0) {
		return 0
	}
	nOrderBy = uint16((*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr)
	if int32(int32(nOrderBy)) > int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(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 = uint16(libc.Int32FromInt32(WO_EQ) | libc.Int32FromInt32(WO_IS) | libc.Int32FromInt32(WO_ISNULL))
	if int32(int32(wctrlFlags))&(libc.Int32FromInt32(WHERE_ORDERBY_LIMIT)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)|libc.Int32FromInt32(WHERE_ORDERBY_MIN)) != 0 {
		eqOpMask = Tu16(int32(eqOpMask) | libc.Int32FromInt32(WO_IN))
	}
	iLoop = 0
	for {
		if !(isOrderDistinct != 0 && obSat < obDone && iLoop <= int32(int32(nLoop))) {
			break
		}
		if iLoop > 0 {
			ready |= (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		}
		if iLoop < int32(int32(nLoop)) {
			pLoop = *(*uintptr)(unsafe.Pointer((*TWherePath)(unsafe.Pointer(pPath)).FaLoop + uintptr(iLoop)*4))
			if int32(int32(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 && int32(int32(wctrlFlags))&(libc.Int32FromInt32(WHERE_DISTINCTBY)|libc.Int32FromInt32(WHERE_SORTBYGROUP)) != int32(WHERE_DISTINCTBY) {
				obSat = obDone
			}
			break
		} else {
			if int32(int32(wctrlFlags))&int32(WHERE_DISTINCTBY) != 0 {
				(*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnDistinctCol = uint16(0)
			}
		}
		iCur = (*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pLoop)).FiTab)*72))).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 < int32(int32(nOrderBy))) {
				break
			}
			if libc.Uint64FromInt32(1)<<i&obSat != 0 {
				goto _2
			}
			pOBExpr = _sqlite3ExprSkipCollateAndLikely(tls, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).FpExpr)
			if pOBExpr == uintptr(0) {
				goto _2
			}
			if int32((*TExpr)(unsafe.Pointer(pOBExpr)).Fop) != int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(pOBExpr)).Fop) != int32(TK_AGG_COLUMN) {
				goto _2
			}
			if (*TExpr)(unsafe.Pointer(pOBExpr)).FiTable != iCur {
				goto _2
			}
			pTerm = _sqlite3WhereFindTerm(tls, pWInfo+80, iCur, int32((*TExpr)(unsafe.Pointer(pOBExpr)).FiColumn), ^ready, uint32(uint32(eqOpMask)), uintptr(0))
			if pTerm == uintptr(0) {
				goto _2
			}
			if int32((*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 < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) && pTerm != *(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4))) {
						break
					}
					goto _3
				_3:
					;
					j++
				}
				if j >= int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) {
					goto _2
				}
			}
			if int32((*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)*20))).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
				}
			}
			obSat |= libc.Uint64FromInt32(1) << i
			goto _2
		_2:
			;
			i++
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_ONEROW) == uint32(0) {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != 0 {
				pIndex = uintptr(0)
				nKeyCol = uint16(0)
				nColumn = uint16(1)
			} else {
				v4 = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
				pIndex = v4
				if v4 == uintptr(0) || int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 56))&0x4>>2)) != 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 isOrderDistint value
					 ** computed here might be a false positive.  Corrections will be
					 ** made at tag-20210426-1 below */
					isOrderDistinct = libc.BoolUint8(int32((*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 < int32(int32(nColumn))) {
					break
				}
				bOnce = uint8(1) /* True to run the ORDER BY search loop */
				if j < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq) && j >= int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
					eOp = (*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4)))).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 int32(int32(eOp))&int32(int32(eqOpMask)) != 0 {
						if int32(int32(eOp))&(libc.Int32FromInt32(WO_ISNULL)|libc.Int32FromInt32(WO_IS)) != 0 {
							isOrderDistinct = uint8(0)
						}
						goto _6
					} else {
						if int32(int32(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)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4)))).FpExpr
							i = j + int32(1)
							for {
								if !(i < int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq)) {
									break
								}
								if (*TWhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*4)))).FpExpr == pX {
									bOnce = uint8(0)
									break
								}
								goto _7
							_7:
								;
								i++
							}
						}
					}
				}
				/* 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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(j)*2)))
					revIdx = uint8(int32(*(*Tu8)(unsafe.Pointer((*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 >= int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq) && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FaCol + uintptr(iColumn)*12 + 4))&0xf>>0)) == 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 off
				 */
				isMatch = uint8(0)
				i = 0
				for {
					if !(bOnce != 0 && i < int32(int32(nOrderBy))) {
						break
					}
					if libc.Uint64FromInt32(1)<<i&obSat != 0 {
						goto _8
					}
					pOBExpr = _sqlite3ExprSkipCollateAndLikely(tls, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).FpExpr)
					if pOBExpr == uintptr(0) {
						goto _8
					}
					if int32(int32(wctrlFlags))&(libc.Int32FromInt32(WHERE_GROUPBY)|libc.Int32FromInt32(WHERE_DISTINCTBY)) == 0 {
						bOnce = uint8(0)
					}
					if iColumn >= -int32(1) {
						if int32((*TExpr)(unsafe.Pointer(pOBExpr)).Fop) != int32(TK_COLUMN) && int32((*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)*20))).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)*20))).FpExpr)
						if _sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pColl)).FzName, *(*uintptr)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(j)*4))) != 0 {
							goto _8
						}
					}
					if int32(int32(wctrlFlags))&int32(WHERE_DISTINCTBY) != 0 {
						(*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnDistinctCol = uint16(j + int32(1))
					}
					isMatch = uint8(1)
					break
					goto _8
				_8:
					;
					i++
				}
				if isMatch != 0 && int32(int32(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 int32(int32(rev))^int32(int32(revIdx)) != int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_DESC) {
							isMatch = uint8(0)
						}
					} else {
						rev = uint8(int32(int32(revIdx)) ^ int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_DESC))
						if rev != 0 {
							*(*TBitmask)(unsafe.Pointer(pRevMask)) |= libc.Uint64FromInt32(1) << iLoop
						}
						revSet = uint8(1)
					}
				}
				if isMatch != 0 && int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
					if j == int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq) {
						*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= uint32(WHERE_BIGNULL_SORT)
					} else {
						isMatch = uint8(0)
					}
				}
				if isMatch != 0 {
					if iColumn == -int32(1) {
						distinctColumns = uint8(1)
					}
					obSat |= libc.Uint64FromInt32(1) << i
				} else {
					/* No match found */
					if j == 0 || j < int32(int32(nKeyCol)) {
						isOrderDistinct = uint8(0)
					}
					break
				}
				goto _6
			_6:
				;
				j++
			} /* 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 |= (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
			i = 0
			for {
				if !(i < int32(int32(nOrderBy))) {
					break
				}
				if libc.Uint64FromInt32(1)<<i&obSat != 0 {
					goto _9
				}
				p = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*20))).FpExpr
				mTerm = _sqlite3WhereExprUsage(tls, pWInfo+496, p)
				if mTerm == uint64(0) && !(_sqlite3ExprIsConstant(tls, uintptr(0), p) != 0) {
					goto _9
				}
				if mTerm & ^orderDistinctMask == uint64(0) {
					obSat |= libc.Uint64FromInt32(1) << i
				}
				goto _9
			_9:
				;
				i++
			}
		}
		goto _1
	_1:
		;
		iLoop++
	} /* End the loop over all WhereLoops from outer-most down to inner-most */
	if obSat == obDone {
		return int8(int8(nOrderBy))
	}
	if !(isOrderDistinct != 0) {
		i = int32(int32(nOrderBy)) - int32(1)
		for {
			if !(i > 0) {
				break
			}
			if i < int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
				v11 = libc.Uint64FromInt32(1)<<i - uint64(1)
			} else {
				v11 = uint64(0)
			}
			m = v11
			if obSat&m == m {
				return int8(int8(i))
			}
			goto _10
		_10:
			;
			i--
		}
		return 0
	}
	return int8(-int32(1))
}

// 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 + 48)) & 0x8 >> 3))
}

// C documentation
//
//	/*
//	** Return the cost of sorting nRow rows, assuming that the keys have
//	** nOrderby columns and that the first nSorted columns are already in
//	** order.
//	*/
func _whereSortingCost(tls *libc.TLS, pWInfo uintptr, nRow TLogEst, nOrderBy int32, nSorted int32) (r TLogEst) {
	var nCol, rSortCost TLogEst
	_, _ = nCol, rSortCost
	/* TUNING: sorting cost proportional to the number of output columns: */
	nCol = _sqlite3LogEst(tls, uint64(((*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FpEList)).FnExpr+int32(59))/int32(30)))
	rSortCost = int16(int32(int32(nRow)) + int32(int32(nCol)))
	if nSorted > 0 {
		/* Scale the result by (Y/X) */
		rSortCost = TLogEst(int32(rSortCost) + (int32(_sqlite3LogEst(tls, uint64((nOrderBy-nSorted)*int32(100)/nOrderBy))) - libc.Int32FromInt32(66)))
	}
	/* Multiple by log(M) where M is the number of output rows.
	 ** Use the LIMIT for M if it is smaller.  Or if this sort is for
	 ** a DISTINCT operator, M will be the number of distinct output
	 ** rows, so fudge it downwards a bit.
	 */
	if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_USE_LIMIT) != 0 {
		rSortCost = TLogEst(int32(rSortCost) + libc.Int32FromInt32(10)) /* TUNING: Extra 2.0x if using LIMIT */
		if nSorted != 0 {
			rSortCost = TLogEst(int32(rSortCost) + libc.Int32FromInt32(6)) /* TUNING: Extra 1.5x if also using partial sort */
		}
		if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FiLimit) < int32(int32(nRow)) {
			nRow = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiLimit
		}
	} else {
		if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
			/* TUNING: In the sort for a DISTINCT operator, assume that the DISTINCT
			 ** reduces the number of output rows by a factor of 2 */
			if int32(int32(nRow)) > int32(10) {
				nRow = TLogEst(int32(nRow) - libc.Int32FromInt32(10))
			}
		}
	}
	rSortCost = TLogEst(int32(rSortCost) + int32(_estLog(tls, nRow)))
	return rSortCost
}

// 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, v14 uintptr
	var iLoop, ii, jj, mxChoice, mxI, nFrom, nLoop, nOrder, nOrderBy, nSpace, nTo, rc, rc1, v1, v10, v2, v4, v5 int32
	var isOrdered Ti8
	var maskNew TBitmask
	var mxCost, mxUnsorted, nOut, rCost, rUnsorted 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, mxUnsorted, nFrom, nLoop, nOrder, nOrderBy, nOut, nSpace, nTo, pFrom, pLevel, pParse, pSpace, pTo, pWLoop, pX, rCost, rUnsorted, rc, rc1, wsFlags, v1, v10, v14, v2, v4, v5 /* Loop counters */
	mxI = 0                                                                                                                                                                                                                                                                                                                                                                      /* Number of ORDER BY clause terms */
	mxCost = 0                                                                                                                                                                                                                                                                                                                                                                   /* Maximum cost of a set of paths */
	mxUnsorted = 0                                                                                                                                                                                                                                                                                                                                                               /* Used to divy up the pSpace memory */
	aSortCost = uintptr(0)                                                                                                                                                                                                                                                                                                                                                       /* Bytes of space allocated at pSpace */
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	nLoop = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)
	/* TUNING: For simple queries, only the best path is tracked.
	 ** For 2-way joins, the 5 best paths are followed.
	 ** For joins of 3 or more tables, track the 10 best paths */
	if nLoop <= int32(1) {
		v1 = int32(1)
	} else {
		if nLoop == int32(2) {
			v2 = int32(5)
		} else {
			v2 = int32(10)
		}
		v1 = v2
	}
	mxChoice = v1
	/* 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(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 = int32((uint32(32) + uint32(4)*uint32(uint32(nLoop))) * uint32(uint32(mxChoice)) * uint32(2))
	nSpace = int32(uint32(nSpace) + libc.Uint32FromInt64(2)*uint32(uint32(nOrderBy)))
	pSpace = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(nSpace)))
	if pSpace == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	aTo = pSpace
	aFrom = aTo + uintptr(mxChoice)*32
	libc.Xmemset(tls, aFrom, 0, uint32(32))
	pX = aFrom + uintptr(mxChoice)*32
	ii = mxChoice * int32(2)
	pFrom = aTo
	for {
		if !(ii > 0) {
			break
		}
		(*TWherePath)(unsafe.Pointer(pFrom)).FaLoop = pX
		goto _3
	_3:
		;
		ii--
		pFrom += 32
		pX += uintptr(nLoop) * 4
	}
	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, uint32(2)*uint32(uint32(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) {
		v4 = int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
	} else {
		v4 = int32(48)
	}
	(*(*TWherePath)(unsafe.Pointer(aFrom))).FnRow = int16(v4)
	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 {
			v5 = -int32(1)
		} else {
			v5 = nOrderBy
		}
		(*(*TWherePath)(unsafe.Pointer(aFrom))).FisOrdered = int8(v5)
	}
	/* 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 _8
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf&(*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop != uint64(0) {
					goto _8
				}
				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 _8
				}
				/* At this point, pWLoop is a candidate to be the next loop.
				 ** Compute its cost */
				rUnsorted = _sqlite3LogEstAdd(tls, (*TWhereLoop)(unsafe.Pointer(pWLoop)).FrSetup, int16(int32((*TWhereLoop)(unsafe.Pointer(pWLoop)).FrRun)+int32((*TWherePath)(unsafe.Pointer(pFrom)).FnRow)))
				rUnsorted = _sqlite3LogEstAdd(tls, rUnsorted, (*TWherePath)(unsafe.Pointer(pFrom)).FrUnsorted)
				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(int32(isOrdered)) < 0 {
					*(*TBitmask)(unsafe.Pointer(bp)) = uint64(0)
					isOrdered = _wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags, uint16(uint16(iLoop)), pWLoop, bp)
				} else {
					*(*TBitmask)(unsafe.Pointer(bp)) = (*TWherePath)(unsafe.Pointer(pFrom)).FrevLoop
				}
				if int32(int32(isOrdered)) >= 0 && int32(int32(isOrdered)) < nOrderBy {
					if int32(*(*TLogEst)(unsafe.Pointer(aSortCost + uintptr(isOrdered)*2))) == 0 {
						*(*TLogEst)(unsafe.Pointer(aSortCost + uintptr(isOrdered)*2)) = _whereSortingCost(tls, pWInfo, nRowEst, nOrderBy, int32(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, rUnsorted, *(*TLogEst)(unsafe.Pointer(aSortCost + uintptr(isOrdered)*2)))) + int32(3))
				} else {
					rCost = rUnsorted
					rUnsorted = TLogEst(int32(rUnsorted) - 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 covers the same set of loops and has the same isOrdered
				 ** setting as the current path candidate.
				 **
				 ** 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(int32(isOrdered)))&int32(0x80) == 0 {
						break
					}
					goto _9
				_9:
					;
					jj++
					pTo += 32
				}
				if jj >= nTo {
					/* None of the existing best-so-far paths match the candidate. */
					if nTo >= mxChoice && (int32(int32(rCost)) > int32(int32(mxCost)) || int32(int32(rCost)) == int32(int32(mxCost)) && int32(int32(rUnsorted)) >= int32(int32(mxUnsorted))) {
						/* 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 _8
					}
					/* 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 */
						v10 = nTo
						nTo++
						jj = v10
					} 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->rUnsorted) <= (rCost,nOut,rUnsorted)
					 */
					if int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) < int32(int32(rCost)) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(int32(rCost)) && (int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) < int32(int32(nOut)) || int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) == int32(int32(nOut)) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsorted) <= int32(int32(rUnsorted))) {
						/* Discard the candidate path from further consideration */
						goto _8
					}
					/* 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)(unsafe.Pointer(bp))
				(*TWherePath)(unsafe.Pointer(pTo)).FnRow = nOut
				(*TWherePath)(unsafe.Pointer(pTo)).FrCost = rCost
				(*TWherePath)(unsafe.Pointer(pTo)).FrUnsorted = rUnsorted
				(*TWherePath)(unsafe.Pointer(pTo)).FisOrdered = isOrdered
				libc.Xmemcpy(tls, (*TWherePath)(unsafe.Pointer(pTo)).FaLoop, (*TWherePath)(unsafe.Pointer(pFrom)).FaLoop, uint32(4)*uint32(uint32(iLoop)))
				*(*uintptr)(unsafe.Pointer((*TWherePath)(unsafe.Pointer(pTo)).FaLoop + uintptr(iLoop)*4)) = pWLoop
				if nTo >= mxChoice {
					mxI = 0
					mxCost = (*(*TWherePath)(unsafe.Pointer(aTo))).FrCost
					mxUnsorted = (*(*TWherePath)(unsafe.Pointer(aTo))).FnRow
					jj = int32(1)
					pTo = aTo + 1*32
					for {
						if !(jj < mxChoice) {
							break
						}
						if int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) > int32(int32(mxCost)) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(int32(mxCost)) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsorted) > int32(int32(mxUnsorted)) {
							mxCost = (*TWherePath)(unsafe.Pointer(pTo)).FrCost
							mxUnsorted = (*TWherePath)(unsafe.Pointer(pTo)).FrUnsorted
							mxI = jj
						}
						goto _11
					_11:
						;
						jj++
						pTo += 32
					}
				}
				goto _8
			_8:
				;
				pWLoop = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop
			}
			goto _7
		_7:
			;
			ii++
			pFrom += 32
		}
		/* Swap the roles of aFrom and aTo for the next generation */
		pFrom = aTo
		aTo = aFrom
		aFrom = pFrom
		nFrom = nTo
		goto _6
	_6:
		;
		iLoop++
	}
	if nFrom == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23963, 0)
		_sqlite3DbFreeNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSpace)
		return int32(SQLITE_ERROR)
	}
	/* Find the lowest cost path.  pFrom will be left pointing to that path */
	pFrom = aFrom
	ii = int32(1)
	for {
		if !(ii < nFrom) {
			break
		}
		if int32((*TWherePath)(unsafe.Pointer(pFrom)).FrCost) > int32((*(*TWherePath)(unsafe.Pointer(aFrom + uintptr(ii)*32))).FrCost) {
			pFrom = aFrom + uintptr(ii)*32
		}
		goto _12
	_12:
		;
		ii++
	}
	/* Load the lowest cost path into pWInfo */
	iLoop = 0
	for {
		if !(iLoop < nLoop) {
			break
		}
		pLevel = pWInfo + 760 + uintptr(iLoop)*88
		v14 = *(*uintptr)(unsafe.Pointer((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(iLoop)*4))
		pWLoop = v14
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop = v14
		(*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)*72))).FiCursor
		goto _13
	_13:
		;
		iLoop++
	}
	if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) == 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == WHERE_DISTINCT_NOOP && nRowEst != 0 {
		rc = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet, pFrom, uint16(WHERE_DISTINCTBY), uint16(nLoop-int32(1)), *(*uintptr)(unsafe.Pointer((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*4)), 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+48, libc.Uint32FromInt32(0), 2, 0x4)
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = (*TWherePath)(unsafe.Pointer(pFrom)).FisOrdered
		if int32((*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)(unsafe.Pointer((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*4)))).FwsFlags
					if wsFlags&uint32(WHERE_ONEROW) == uint32(0) && wsFlags&uint32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_COLUMN_IN)) != uint32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_COLUMN_IN)) {
						*(*TBitmask)(unsafe.Pointer(bp + 16)) = uint64(0)
						rc1 = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, uint16(WHERE_ORDERBY_LIMIT), uint16(nLoop-int32(1)), *(*uintptr)(unsafe.Pointer((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*4)), bp+16))
						if rc1 == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
							libc.SetBitFieldPtr8Uint32(pWInfo+48, libc.Uint32FromInt32(1), 2, 0x4)
							(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = *(*TBitmask)(unsafe.Pointer(bp + 16))
						}
					}
				}
			} else {
				if nLoop != 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == int32(1) && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(libc.Int32FromInt32(WHERE_ORDERBY_MIN)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)) != 0 {
					libc.SetBitFieldPtr8Uint32(pWInfo+48, libc.Uint32FromInt32(1), 2, 0x4)
				}
			}
		}
		if int32((*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)(unsafe.Pointer(bp + 24)) = uint64(0)
			nOrder = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, uint16(0), uint16(nLoop-int32(1)), *(*uintptr)(unsafe.Pointer((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*4)), bp+24))
			if nOrder == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
				libc.SetBitFieldPtr8Uint32(pWInfo+48, libc.Uint32FromInt32(1), 3, 0x8)
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = *(*TBitmask)(unsafe.Pointer(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
//
//	/*
//	** This routine implements a heuristic designed to improve query planning.
//	** This routine is called in between the first and second call to
//	** wherePathSolver().  Hence the name "Interstage" "Heuristic".
//	**
//	** The first call to wherePathSolver() (hereafter just "solver()") computes
//	** the best path without regard to the order of the outputs.  The second call
//	** to the solver() builds upon the first call to try to find an alternative
//	** path that satisfies the ORDER BY clause.
//	**
//	** This routine looks at the results of the first solver() run, and for
//	** every FROM clause term in the resulting query plan that uses an equality
//	** constraint against an index, disable other WhereLoops for that same
//	** FROM clause term that would try to do a full-table scan.  This prevents
//	** an index search from being converted into a full-table scan in order to
//	** satisfy an ORDER BY clause, since even though we might get slightly better
//	** performance using the full-scan without sorting if the output size
//	** estimates are very precise, we might also get severe performance
//	** degradation using the full-scan if the output size estimate is too large.
//	** It is better to err on the side of caution.
//	**
//	** Except, if the first solver() call generated a full-table scan in an outer
//	** loop then stop this analysis at the first full-scan, since the second
//	** solver() run might try to swap that full-scan for another in order to
//	** get the output into the correct order.  In other words, we allow a
//	** rewrite like this:
//	**
//	**     First Solver()                      Second Solver()
//	**       |-- SCAN t1                         |-- SCAN t2
//	**       |-- SEARCH t2                       `-- SEARCH t1
//	**       `-- SORT USING B-TREE
//	**
//	** The purpose of this routine is to disallow rewrites such as:
//	**
//	**     First Solver()                      Second Solver()
//	**       |-- SEARCH t1                       |-- SCAN t2     <--- bad!
//	**       |-- SEARCH t2                       `-- SEARCH t1
//	**       `-- SORT USING B-TREE
//	**
//	** See test cases in test/whereN.test for the real-world query that
//	** originally provoked this heuristic.
//	*/
func _whereInterstageHeuristic(tls *libc.TLS, pWInfo uintptr) {
	var i int32
	var iTab Tu8
	var p, pLoop uintptr
	_, _, _, _ = i, iTab, p, pLoop
	i = 0
	for {
		if !(i < int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
			break
		}
		p = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(i)*88))).FpWLoop
		if p == uintptr(0) {
			break
		}
		if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
			goto _1
		}
		if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(libc.Int32FromInt32(WHERE_COLUMN_EQ)|libc.Int32FromInt32(WHERE_COLUMN_NULL)|libc.Int32FromInt32(WHERE_COLUMN_IN)) != uint32(0) {
			iTab = (*TWhereLoop)(unsafe.Pointer(p)).FiTab
			pLoop = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
			for {
				if !(pLoop != 0) {
					break
				}
				if int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FiTab) != int32(int32(iTab)) {
					goto _2
				}
				if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(libc.Int32FromInt32(WHERE_CONSTRAINT)|libc.Int32FromInt32(WHERE_AUTO_INDEX)) != uint32(0) {
					/* Auto-index and index-constrained loops allowed to remain */
					goto _2
				}
				(*TWhereLoop)(unsafe.Pointer(pLoop)).Fprereq = uint64(-libc.Int32FromInt32(1)) /* Prevent 2nd solver() from using this one */
				goto _2
			_2:
				;
				pLoop = (*TWhereLoop)(unsafe.Pointer(pLoop)).FpNextLoop
			}
		} else {
			break
		}
		goto _1
	_1:
		;
		i++
	}
}

// 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(96)
	defer tls.Free(96)
	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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
		return 0
	}
	pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
	pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
	if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		return 0
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x2>>1)) != 0 || int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x1>>0)) != 0 {
		return 0
	}
	iCur = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
	pWC = pWInfo + 80
	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), uint32(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 = uint32(libc.Int32FromInt32(WHERE_COLUMN_EQ) | libc.Int32FromInt32(WHERE_IPK) | libc.Int32FromInt32(WHERE_ONEROW))
		*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm)) = pTerm
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = uint16(1)
		(*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.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 !(int32((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromInt32(OE_None)) || (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) || int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) > int32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(4)) {
				goto _1
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x8>>3)) != 0 {
				v2 = libc.Int32FromInt32(WO_EQ) | libc.Int32FromInt32(WO_IS)
			} else {
				v2 = int32(WO_EQ)
			}
			opMask = v2
			j = 0
			for {
				if !(j < int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				pTerm = _whereScanInit(tls, bp, pWC, iCur, j, uint32(uint32(opMask)), pIdx)
				for pTerm != 0 && (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight != 0 {
					pTerm = _whereScanNext(tls, bp)
				}
				if pTerm == uintptr(0) {
					break
				}
				*(*uintptr)(unsafe.Pointer((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*4)) = pTerm
				goto _3
			_3:
				;
				j++
			}
			if j != int32((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
				goto _1
			}
			(*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = uint32(libc.Int32FromInt32(WHERE_COLUMN_EQ) | libc.Int32FromInt32(WHERE_ONEROW) | libc.Int32FromInt32(WHERE_INDEXED))
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x20>>5)) != 0 || (*TSrcItem)(unsafe.Pointer(pItem)).FcolUsed&(*TIndex)(unsafe.Pointer(pIdx)).FcolNotIdxed == uint64(0) {
				*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= uint32(WHERE_IDX_ONLY)
			}
			(*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = uint16(uint16(j))
			(*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnEq = uint16(uint16(j))
			(*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.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 + 760))).FpWLoop = pLoop
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf = uint64(1) /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
		(*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760))).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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNIQUE)
		}
		if int32((*(*TWhereScan)(unsafe.Pointer(bp))).FiEquiv) > int32(1) {
			*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= uint32(WHERE_TRANSCONS)
		}
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Helper function for exprIsDeterministic().
//	*/
func _exprNodeIsDeterministic(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_FUNCTION) && libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_ConstFunc)) != uint32(0)) == 0 {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
		return int32(WRC_Abort)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Return true if the expression contains no non-deterministic SQL
//	** functions. Do not consider non-deterministic SQL functions that are
//	** part of sub-select statements.
//	*/
func _exprIsDeterministic(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FeCode = uint16(1)
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprNodeIsDeterministic)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkFail)
	_sqlite3WalkExpr(tls, bp, p)
	return int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)
}

// C documentation
//
//	/* Attempt to omit tables from a join that do not affect the result.
//	** For a table to not affect the result, the following must be true:
//	**
//	**   1) The query must not be an aggregate.
//	**   2) The table must be the RHS of a LEFT JOIN.
//	**   3) Either the query must be DISTINCT, or else the ON or USING clause
//	**      must contain a constraint that limits the scan of the table to
//	**      at most a single row.
//	**   4) The table must not be referenced by any part of the query apart
//	**      from its own USING or ON clause.
//	**   5) The table must not have an inner-join ON or USING clause if there is
//	**      a RIGHT JOIN anywhere in the query.  Otherwise the ON/USING clause
//	**      might move from the right side to the left side of the RIGHT JOIN.
//	**      Note: Due to (2), this condition can only arise if the table is
//	**      the right-most table of a subquery that was flattened into the
//	**      main query and that subquery was the right-hand operand of an
//	**      inner join that held an ON or USING clause.
//	**
//	** For example, given:
//	**
//	**     CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1);
//	**     CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2);
//	**     CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3);
//	**
//	** then table t2 can be omitted from the following:
//	**
//	**     SELECT v1, v3 FROM t1
//	**       LEFT JOIN t2 ON (t1.ipk=t2.ipk)
//	**       LEFT JOIN t3 ON (t1.ipk=t3.ipk)
//	**
//	** or from:
//	**
//	**     SELECT DISTINCT v1, v3 FROM t1
//	**       LEFT JOIN t2
//	**       LEFT JOIN t3 ON (t1.ipk=t3.ipk)
//	*/
func _whereOmitNoopJoin(tls *libc.TLS, pWInfo uintptr, notReady TBitmask) (r TBitmask) {
	var hasRightJoin, i, nByte int32
	var pEnd, pItem, pLoop, pTerm, p4 uintptr
	var tabUsed TBitmask
	_, _, _, _, _, _, _, _, _ = hasRightJoin, i, nByte, pEnd, pItem, pLoop, pTerm, tabUsed, p4
	/* Preconditions checked by the caller */
	/* These two preconditions checked by the caller combine to guarantee
	 ** condition (1) of the header comment */
	tabUsed = _sqlite3WhereExprListUsage(tls, pWInfo+496, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet)
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
		tabUsed |= _sqlite3WhereExprListUsage(tls, pWInfo+496, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)
	}
	hasRightJoin = libc.BoolInt32(int32((*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0)
	i = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - int32(1)
	for {
		if !(i >= int32(1)) {
			break
		}
		pLoop = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(i)*88))).FpWLoop
		pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pLoop)).FiTab)*72
		if int32((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_RIGHT)) != int32(JT_LEFT) {
			goto _1
		}
		if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) == 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_ONEROW) == uint32(0) {
			goto _1
		}
		if tabUsed&(*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf != uint64(0) {
			goto _1
		}
		pEnd = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa + uintptr((*TWhereInfo)(unsafe.Pointer(pWInfo)).FsWC.FnTerm)*48
		pTerm = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa
		for {
			if !(pTerm < pEnd) {
				break
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf != uint64(0) {
				if !((*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) || *(*int32)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr + 36)) != (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor {
					break
				}
			}
			if hasRightJoin != 0 && (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) && *(*int32)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr + 36)) == (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor {
				break /* restriction (5) */
			}
			goto _2
		_2:
			;
			pTerm += 48
		}
		if pTerm < pEnd {
			goto _1
		}
		notReady &= ^(*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		pTerm = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa
		for {
			if !(pTerm < pEnd) {
				break
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf != uint64(0) {
				p4 = pTerm + 10
				*(*Tu16)(unsafe.Pointer(p4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p4))) | libc.Int32FromInt32(TERM_CODED))
			}
			goto _3
		_3:
			;
			pTerm += 48
		}
		if i != int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-int32(1) {
			nByte = int32(uint32(int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-libc.Int32FromInt32(1)-i) * uint32(88))
			libc.Xmemmove(tls, pWInfo+760+uintptr(i)*88, pWInfo+760+uintptr(i+int32(1))*88, uint32(uint32(nByte)))
		}
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel--
		goto _1
	_1:
		;
		i--
	}
	return notReady
}

// C documentation
//
//	/*
//	** Check to see if there are any SEARCH loops that might benefit from
//	** using a Bloom filter.  Consider a Bloom filter if:
//	**
//	**   (1)  The SEARCH happens more than N times where N is the number
//	**        of rows in the table that is being considered for the Bloom
//	**        filter.
//	**   (2)  Some searches are expected to find zero rows.  (This is determined
//	**        by the WHERE_SELFCULL flag on the term.)
//	**   (3)  Bloom-filter processing is not disabled.  (Checked by the
//	**        caller.)
//	**   (4)  The size of the table being searched is known by ANALYZE.
//	**
//	** This block of code merely checks to see if a Bloom filter would be
//	** appropriate, and if so sets the WHERE_BLOOMFILTER flag on the
//	** WhereLoop.  The implementation of the Bloom filter comes further
//	** down where the code for each WhereLoop is generated.
//	*/
func _whereCheckIfBloomFilterIsUseful(tls *libc.TLS, pWInfo uintptr) {
	var i int32
	var nSearch TLogEst
	var pItem, pLoop, pTab uintptr
	var reqFlags uint32
	_, _, _, _, _, _ = i, nSearch, pItem, pLoop, pTab, reqFlags
	nSearch = 0
	i = 0
	for {
		if !(i < int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
			break
		}
		pLoop = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760 + uintptr(i)*88))).FpWLoop
		reqFlags = uint32(libc.Int32FromInt32(WHERE_SELFCULL) | libc.Int32FromInt32(WHERE_COLUMN_EQ))
		pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pLoop)).FiTab)*72
		pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpTab
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasStat1) == uint32(0) {
			break
		}
		*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(TF_MaybeReanalyze)
		if i >= int32(1) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&reqFlags == reqFlags && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_INDEXED)) != uint32(0) {
			if int32(int32(nSearch)) > int32((*TTable)(unsafe.Pointer(pTab)).FnRowLogEst) {
				*(*Tu32)(unsafe.Pointer(pLoop + 40)) |= uint32(WHERE_BLOOMFILTER)
				*(*Tu32)(unsafe.Pointer(pLoop + 40)) &= uint32(^libc.Int32FromInt32(WHERE_IDX_ONLY))
			}
		}
		nSearch = TLogEst(int32(nSearch) + int32((*TWhereLoop)(unsafe.Pointer(pLoop)).FnOut))
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Expression Node callback for sqlite3ExprCanReturnSubtype().
//	**
//	** Only a function call is able to return a subtype.  So if the node
//	** is not a function call, return WRC_Prune immediately.
//	**
//	** A function call is able to return a subtype if it has the
//	** SQLITE_RESULT_SUBTYPE property.
//	**
//	** Assume that every function is able to pass-through a subtype from
//	** one of its argument (using sqlite3_result_value()).  Most functions
//	** are not this way, but we don't have a mechanism to distinguish those
//	** that are from those that are not, so assume they all work this way.
//	** That means that if one of its arguments is another function and that
//	** other function is able to return a subtype, then this function is
//	** able to return a subtype.
//	*/
func _exprNodeCanReturnSubtype(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var db, pDef uintptr
	var n, v1 int32
	_, _, _, _ = db, n, pDef, v1
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_FUNCTION) {
		return int32(WRC_Prune)
	}
	db = (*TParse)(unsafe.Pointer((*TWalker)(unsafe.Pointer(pWalker)).FpParse)).Fdb
	if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != 0 {
		v1 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FnExpr
	} else {
		v1 = 0
	}
	n = v1
	pDef = _sqlite3FindFunction(tls, db, *(*uintptr)(unsafe.Pointer(pExpr + 8)), n, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, uint8(0))
	if pDef == uintptr(0) || (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_RESULT_SUBTYPE) != uint32(0) {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1)
		return int32(WRC_Prune)
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Return TRUE if expression pExpr is able to return a subtype.
//	**
//	** A TRUE return does not guarantee that a subtype will be returned.
//	** It only indicates that a subtype return is possible.  False positives
//	** are acceptable as they only disable an optimization.  False negatives,
//	** on the other hand, can lead to incorrect answers.
//	*/
func _sqlite3ExprCanReturnSubtype(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_exprNodeCanReturnSubtype)
	_sqlite3WalkExpr(tls, bp, pExpr)
	return int32((*(*TWalker)(unsafe.Pointer(bp))).FeCode)
}

// C documentation
//
//	/*
//	** The index pIdx is used by a query and contains one or more expressions.
//	** In other words pIdx is an index on an expression.  iIdxCur is the cursor
//	** number for the index and iDataCur is the cursor number for the corresponding
//	** table.
//	**
//	** This routine adds IndexedExpr entries to the Parse->pIdxEpr field for
//	** each of the expressions in the index so that the expression code generator
//	** will know to replace occurrences of the indexed expression with
//	** references to the corresponding column of the index.
//	*/
func _whereAddIndexedExpr(tls *libc.TLS, pParse uintptr, pIdx uintptr, iIdxCur int32, pTabItem uintptr) {
	var i, j int32
	var p, pArg, pExpr, pTab uintptr
	_, _, _, _, _, _ = i, j, p, pArg, pExpr, pTab
	pTab = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
	i = 0
	for {
		if !(i < int32((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
			break
		}
		j = int32(*(*Ti16)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
		if j == -int32(2) {
			pExpr = (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(i)*20))).FpExpr
		} else {
			if j >= 0 && int32((*(*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
				pExpr = _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*12)
			} else {
				goto _1
			}
		}
		if _sqlite3ExprIsConstant(tls, uintptr(0), pExpr) != 0 {
			goto _1
		}
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_FUNCTION) && _sqlite3ExprCanReturnSubtype(tls, pParse, pExpr) != 0 {
			/* Functions that might set a subtype should not be replaced by the
			 ** value taken from an expression index since the index omits the
			 ** subtype.  https://sqlite.org/forum/forumpost/68d284c86b082c3e */
			goto _1
		}
		p = _sqlite3DbMallocRaw(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(24))
		if p == uintptr(0) {
			break
		}
		(*TIndexedExpr)(unsafe.Pointer(p)).FpIENext = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
		(*TIndexedExpr)(unsafe.Pointer(p)).FpExpr = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
		(*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
		(*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur = iIdxCur
		(*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol = i
		(*TIndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow = libc.BoolUint8(int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0)
		if _sqlite3IndexAffinityStr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pIdx) != 0 {
			(*TIndexedExpr)(unsafe.Pointer(p)).Faff = uint8(*(*int8)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FzColAff + uintptr(i))))
		}
		(*TParse)(unsafe.Pointer(pParse)).FpIdxEpr = p
		if (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext == uintptr(0) {
			pArg = pParse + 72
			_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_whereIndexedExprCleanup), pArg)
		}
		goto _1
	_1:
		;
		i++
	}
}

// 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)*72
		if !(int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 36 + 4))&0x100>>8)) != 0) || int32((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 68)))).FeM10d) != M10d_Yes || (*TSrcItem)(unsafe.Pointer(pItem)).FpSelect == uintptr(0) || (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpOrderBy == uintptr(0) {
			*(*TBitmask)(unsafe.Pointer(pWInfo + 72)) |= libc.Uint64FromInt32(1) << ii
		}
		goto _1
	_1:
		;
		ii++
	}
}

// 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(48)
	defer tls.Free(48)
	var addrExplain, bOnerow, iCur, iDb, iIndexCur, iOnce, ii, n, nByteWInfo, nTabList, op, op1, rc, wsFlags, wsFlags1, v1, v12, v15, v19, v2, v21, v23, v3, v4 int32
	var b, notReady TBitmask
	var bFordelete Tu8
	var db, p, pInfo, pIx, pJ, pLevel, pLoop, pMaskSet, pPk, pRJ, pSrc, pT, pTab, pTabItem, pVTab, pWInfo, pX, v, v16, v17, v20, v22, v24, p10, p11, p7, p8, p9 uintptr
	var v18 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, pT, pTab, pTabItem, pVTab, pWInfo, pX, rc, v, wsFlags, wsFlags1, v1, v12, v15, v16, v17, v18, v19, v2, v20, v21, v22, v23, v24, v3, v4, p10, p11, p7, p8, p9 /* 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, uint32(32))
	/* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
	if pOrderBy != 0 && (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr >= int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
		pOrderBy = uintptr(0)
		wctrlFlags = Tu16(int32(wctrlFlags) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
	}
	/* The number of tables in the FROM clause is limited by the number of
	 ** bits in a Bitmask
	 */
	if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23981, libc.VaList(bp+40, int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(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 int32(int32(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 = int32((libc.Uint32FromInt64(848) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
	if nTabList > int32(1) {
		nByteWInfo = int32((uint32(uint32(nByteWInfo)) + uint32(nTabList-libc.Int32FromInt32(1))*libc.Uint32FromInt64(88) + libc.Uint32FromInt32(7)) & uint32(^libc.Int32FromInt32(7)))
	}
	pWInfo = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(uint32(nByteWInfo))+uint32(72)))
	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
	v2 = -libc.Int32FromInt32(1)
	*(*int32)(unsafe.Pointer(pWInfo + 20 + 1*4)) = v2
	*(*int32)(unsafe.Pointer(pWInfo + 20)) = v2
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel = uint8(uint8(nTabList))
	v3 = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue = v3
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak = v3
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags = wctrlFlags
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiLimit = int16(int16(iAuxArg))
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop = int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect = pSelect
	libc.Xmemset(tls, pWInfo+45, 0, uint32(libc.UintptrFromInt32(0)+80)-uint32(libc.UintptrFromInt32(0)+45))
	libc.Xmemset(tls, pWInfo+760, 0, uint32(72)+uint32(uint32(nTabList))*uint32(88))
	/* ONEPASS defaults to OFF */
	pMaskSet = pWInfo + 496
	(*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).Fn = 0
	*(*int32)(unsafe.Pointer(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)(unsafe.Pointer(bp))).FpWInfo = pWInfo
	(*(*TWhereLoopBuilder)(unsafe.Pointer(bp))).FpWC = pWInfo + 80
	(*(*TWhereLoopBuilder)(unsafe.Pointer(bp))).FpNew = pWInfo + uintptr(nByteWInfo)
	_whereLoopInit(tls, (*(*TWhereLoopBuilder)(unsafe.Pointer(bp))).FpNew)
	/* Split the WHERE clause into separate subexpressions where each
	 ** subexpression is separated by an AND operator.
	 */
	_sqlite3WhereClauseInit(tls, pWInfo+80, pWInfo)
	_sqlite3WhereSplit(tls, pWInfo+80, 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 int32(int32(wctrlFlags))&int32(WHERE_WANT_DISTINCT) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(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+24009, 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)*72))).FiCursor)
			_sqlite3WhereTabFuncArgs(tls, pParse, pTabList+8+uintptr(ii)*72, pWInfo+80)
			goto _5
		_5:
			;
			ii++
			v4 = ii
			if !(v4 < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
				break
			}
		}
	}
	/* Analyze all of the subexpressions. */
	_sqlite3WhereExprAnalyze(tls, pTabList, pWInfo+80)
	if pSelect != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FpLimit != 0 {
		_sqlite3WhereAddLimit(tls, pWInfo+80, 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)(unsafe.Pointer(bp))).FpWC)).FnBase) {
			break
		}
		pT = (*TWhereClause)(unsafe.Pointer((*(*TWhereLoopBuilder)(unsafe.Pointer(bp))).FpWC)).Fa + uintptr(ii)*48 /* The expression of pT */
		if int32((*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&uint32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) && int32((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0) {
			_sqlite3ExprIfFalse(tls, pParse, pX, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak, int32(SQLITE_JUMPIFNULL))
			p7 = pT + 10
			*(*Tu16)(unsafe.Pointer(p7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p7))) | libc.Int32FromInt32(TERM_CODED))
		}
		goto _6
	_6:
		;
		ii++
	}
	if int32(int32(wctrlFlags))&int32(WHERE_WANT_DISTINCT) != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_DistinctOpt)) != uint32(0) {
			/* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
			 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
			wctrlFlags = Tu16(int32(wctrlFlags) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
			p8 = pWInfo + 40
			*(*Tu16)(unsafe.Pointer(p8)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p8))) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
		} else {
			if _isDistinctRedundant(tls, pParse, pTabList, pWInfo+80, 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 */
					p9 = pWInfo + 40
					*(*Tu16)(unsafe.Pointer(p9)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(p9))) | 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 int32((*(*TWhereLoopBuilder)(unsafe.Pointer(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)
			_wherePathSolver(tls, pWInfo, int16(int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut)+int32(1)))
			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).
		 */
		if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
			p10 = pWInfo + 50
			*(*TLogEst)(unsafe.Pointer(p10)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p10))) - 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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= int32(2) && pResultSet != uintptr(0) && 0 == int32(int32(wctrlFlags))&int32(WHERE_AGG_DISTINCT) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_OmitNoopJoin)) == uint32(0) {
		notReady = _whereOmitNoopJoin(tls, pWInfo, notReady)
		nTabList = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)
	}
	/* Check to see if there are any SEARCH loops that might benefit from
	 ** using a Bloom filter.
	 */
	if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= int32(2) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_BloomFilter)) == uint32(0) {
		_whereCheckIfBloomFilterIsUseful(tls, pWInfo)
	}
	p11 = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse + 156
	*(*TLogEst)(unsafe.Pointer(p11)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(p11))) + 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 int32(int32(wctrlFlags))&int32(WHERE_ONEPASS_DESIRED) != 0 {
		wsFlags = int32((*TWhereLoop1)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760))).FpWLoop)).FwsFlags)
		bOnerow = libc.BoolInt32(wsFlags&int32(WHERE_ONEROW) != 0)
		if bOnerow != 0 || 0 != int32(int32(wctrlFlags))&int32(WHERE_ONEPASS_MULTIROW) && !(int32((*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && (0 == wsFlags&int32(WHERE_MULTI_OR) || int32(int32(wctrlFlags))&int32(WHERE_DUPLICATES_OK) != 0) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_OnePass)) == uint32(0) {
			if bOnerow != 0 {
				v12 = int32(ONEPASS_SINGLE)
			} else {
				v12 = int32(ONEPASS_MULTI)
			}
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass = uint8(v12)
			if (*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && wsFlags&int32(WHERE_IDX_ONLY) != 0 {
				if int32(int32(wctrlFlags))&int32(WHERE_ONEPASS_MULTIROW) != 0 {
					bFordelete = uint8(OPFLAG_FORDELETE)
				}
				(*TWhereLoop1)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 760))).FpWLoop)).FwsFlags = uint32(wsFlags & ^libc.Int32FromInt32(WHERE_IDX_ONLY))
			}
		}
	}
	/* Open all tables in the pTabList and any indices selected for
	 ** searching those tables.
	 */
	ii = 0
	pLevel = pWInfo + 760
	for {
		if !(ii < nTabList) {
			break
		}
		pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*72
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpTab
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Ephemeral) != uint32(0) || int32((*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(11))
			} else {
				if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					/* noop */
				} else {
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) == uint32(0) && int32(int32(wctrlFlags))&int32(WHERE_OR_SUBCLAUSE) == 0 || int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
						op = int32(OP_OpenRead)
						if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF {
							op = int32(OP_OpenWrite)
							*(*int32)(unsafe.Pointer(pWInfo + 20)) = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
						}
						_sqlite3OpenTable(tls, pParse, (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor, iDb, pTab, op)
						if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) == ONEPASS_OFF && int32((*TTable)(unsafe.Pointer(pTab)).FnCol) < int32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(libc.Int32FromInt32(TF_HasGenerated)|libc.Int32FromInt32(TF_WithoutRowid)) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(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 _14
							_14:
								;
								b = b >> int32(1)
								n++
							}
							_sqlite3VdbeChangeP4(tls, v, -int32(1), uintptr(n), -int32(3))
						}
						_sqlite3VdbeChangeP5(tls, v, uint16(uint16(bFordelete)))
					} 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 = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.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 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && int32(int32(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 int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF {
					pJ = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pTabItem)).FpTab)).FpIndex
					iIndexCur = iAuxArg
					for pJ != 0 && pJ != pIx {
						iIndexCur++
						pJ = (*TIndex)(unsafe.Pointer(pJ)).FpNext
					}
					op1 = int32(OP_OpenWrite)
					*(*int32)(unsafe.Pointer(pWInfo + 20 + 1*4)) = iIndexCur
				} else {
					if iAuxArg != 0 && int32(int32(wctrlFlags))&int32(WHERE_OR_SUBCLAUSE) != 0 {
						iIndexCur = iAuxArg
						op1 = int32(OP_ReopenIdx)
					} else {
						v16 = pParse + 40
						v15 = *(*int32)(unsafe.Pointer(v16))
						*(*int32)(unsafe.Pointer(v16))++
						iIndexCur = v15
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIx + 56))&0x1000>>12)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_IndexedExpr)) == uint32(0) {
							_whereAddIndexedExpr(tls, pParse, pIx, iIndexCur, pTabItem)
						}
						if (*TIndex)(unsafe.Pointer(pIx)).FpPartIdxWhere != 0 && int32((*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, int32((*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&uint32(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) && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_ORDERBY_MIN) == 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) != int32(WHERE_DISTINCT_ORDERED) {
					_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SEEKEQ))
				}
			}
		}
		if iDb >= 0 {
			_sqlite3CodeVerifySchema(tls, pParse, iDb)
		}
		if v18 = int32((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0; v18 {
			v17 = _sqlite3WhereMalloc(tls, pWInfo, uint64(20))
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ = v17
		}
		if v18 && v17 != uintptr(0) {
			pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
			v20 = pParse + 40
			v19 = *(*int32)(unsafe.Pointer(v20))
			*(*int32)(unsafe.Pointer(v20))++
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch = v19
			v22 = pParse + 44
			*(*int32)(unsafe.Pointer(v22))++
			v21 = *(*int32)(unsafe.Pointer(v22))
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom = v21
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(65536), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom)
			v24 = pParse + 44
			*(*int32)(unsafe.Pointer(v24))++
			v23 = *(*int32)(unsafe.Pointer(v24))
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn = v23
			_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 + 20)) = uintptr(0)
					*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pInfo)).FaSortFlags)) = uint8(0)
					_sqlite3VdbeAppendP4(tls, v, pInfo, -int32(8))
				}
			} else {
				pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, int32((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
				_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
			}
			*(*Tu32)(unsafe.Pointer(pLoop + 40)) &= uint32(^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 _13
	_13:
		;
		ii++
		pLevel += 88
	}
	(*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 + 760 + uintptr(ii)*88
		wsFlags1 = int32((*TWhereLoop1)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FwsFlags)
		pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*72
		if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x10>>4)) != 0 {
			if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x8>>3)) != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSrcItem)(unsafe.Pointer(pSrc)).FregReturn, (*TSrcItem)(unsafe.Pointer(pSrc)).FaddrFillSub)
			} else {
				iOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSrcItem)(unsafe.Pointer(pSrc)).FregReturn, (*TSrcItem)(unsafe.Pointer(pSrc)).FaddrFillSub)
				_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+80, 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 && int32(int32(wctrlFlags))&int32(WHERE_OR_SUBCLAUSE) == 0 {
			_ = addrExplain
		}
		goto _25
	_25:
		;
		ii++
	}
	/* 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 the end of the WHERE loop.  See comments on
//	** sqlite3WhereBegin() for additional information.
//	*/
func _sqlite3WhereEnd(tls *libc.TLS, pWInfo uintptr) {
	var addr, addrSeek, bEarlyOut, i, iDb, iEnd, j, j1, k, last, m, n, n1, nRJ, op, r1, ws, x, v4, v7 int32
	var db, p, pIdx, pIdx1, pIn, pIx, pLastOp, pLevel, pLoop, pOp, pParse, pPk, pRJ, pSrc, pTab, pTabItem, pTabList, v, v10, v2, p12 uintptr
	var v3, v5 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, 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, v10, v2, v3, v4, v5, v7, p12
	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
	/* Generate loop termination code.
	 */
	i = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		pLevel = pWInfo + 760 + uintptr(i)*88
		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)
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont = 0
			(*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++
		}
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		if int32((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) != int32(OP_Noop) {
			addrSeek = 0
			if v3 = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == int32(WHERE_DISTINCT_ORDERED) && i == int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-int32(1) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != uint32(0); v3 {
				v2 = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FpIndex
				pIdx = v2
			}
			if v5 = v3 && int32(uint32(*(*uint16)(unsafe.Pointer(v2 + 56))&0x80>>7)) != 0; v5 {
				v4 = int32((*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.FnDistinctCol)
				n = v4
			}
			if v5 && v4 > 0 && int32(*(*TLogEst)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst + uintptr(n)*2))) >= int32(36) {
				r1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
				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++
				}
				*(*int32)(unsafe.Pointer(pParse + 44)) += n + int32(1)
				if int32((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) == int32(OP_Prev) {
					v7 = int32(OP_SeekLT)
				} else {
					v7 = int32(OP_SeekGT)
				}
				op = v7
				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)
			}
			/* The common case: Advance to the next row */
			if (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont != 0 {
				_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
			}
			_sqlite3VdbeAddOp3(tls, v, int32((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop), (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1, (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2, int32((*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)
			}
		} else {
			if (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont != 0 {
				_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
			}
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_ABLE) != uint32(0) && (*(*struct {
			FnIn     int32
			FaInLoop uintptr
		})(unsafe.Pointer(pLevel + 64))).FnIn > 0 {
			_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt)
			j1 = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FnIn
			pIn = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 64))).FaInLoop + uintptr(j1-int32(1))*20
			for {
				if !(j1 > 0) {
					break
				}
				_sqlite3VdbeJumpHere(tls, v, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop+int32(1))
				if int32((*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, int32((*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--
				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 = int32((*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)*72
				if int32(uint32(*(*uint16)(unsafe.Pointer(pSrc + 36 + 4))&0x20>>5)) != 0 {
					n1 = (*TSrcItem)(unsafe.Pointer(pSrc)).FregResult
					m = int32((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpTab)).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, int32((*TIndex)(unsafe.Pointer(pIx)).Ftnum), iDb)
					_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIx)
				}
				_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
			}
			if int32((*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 = 0
	pLevel = pWInfo + 760
	for {
		if !(i < int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
			break
		}
		pIdx1 = uintptr(0)
		pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*72
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpTab
		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(*(*uint16)(unsafe.Pointer(pTabItem + 36 + 4))&0x20>>5)) != 0 {
			_translateColumnToCopy(tls, pParse, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TSrcItem)(unsafe.Pointer(pTabItem)).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&uint32(libc.Int32FromInt32(WHERE_INDEXED)|libc.Int32FromInt32(WHERE_IDX_ONLY)) != 0 {
			pIdx1 = (*TWhereLoop)(unsafe.Pointer(pLoop)).Fu.Fbtree.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 int32((*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 + 56))&0x1000>>12)) != 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)*20
			for {
				if (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 != (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur {
					/* no-op */
				} else {
					if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) || int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Offset) {
						x = (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2
						if int32((*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)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(x)*2)))
							} else {
								x = int32(_sqlite3StorageColumnToTable(tls, pTab, int16(int16(x))))
							}
						}
						x = int32(_sqlite3TableColumnToIndex(tls, pIdx1, int16(int16(x))))
						if x >= 0 {
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = x
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
						} else {
							/* Unable to translate the table reference into an index
							 ** reference.  Verify that this is harmless - that the
							 ** table being referenced really is open.
							 */
						}
					} else {
						if int32((*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 int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_IfNullRow) {
								(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
							}
						}
					}
				}
				goto _11
			_11:
				;
				pOp += 20
				v10 = pOp
				if !(v10 < pLastOp) {
					break
				}
			}
		}
		goto _9
	_9:
		;
		i++
		pLevel += 88
	}
	/* 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)
	p12 = pParse + 26
	*(*Tu8)(unsafe.Pointer(p12)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p12))) - 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
//
//	/*
//	** Implementation of built-in window function row_number(). Assumes that the
//	** window frame has been coerced to:
//	**
//	**   ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
//	*/
func _row_numberStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 {
		*(*Ti64)(unsafe.Pointer(p))++
	}
	_ = nArg
	_ = apArg
}

func _row_numberValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	var v1 int64
	_, _ = p, v1
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 {
		v1 = *(*Ti64)(unsafe.Pointer(p))
	} else {
		v1 = 0
	}
	Xsqlite3_result_int64(tls, pCtx, v1)
}

/*
** Context object type used by rank(), dense_rank(), percent_rank() and
** cume_dist().
 */
type TCallCount = struct {
	F__ccgo_align [0]uint32
	FnValue       Ti64
	FnStep        Ti64
	FnTotal       Ti64
}

type CallCount = TCallCount

// C documentation
//
//	/*
//	** Implementation of built-in window function dense_rank(). Assumes that
//	** the window frame has been set to:
//	**
//	**   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
//	*/
func _dense_rankStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		(*TCallCount)(unsafe.Pointer(p)).FnStep = int64(1)
	}
	_ = nArg
	_ = apArg
}

func _dense_rankValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		if (*TCallCount)(unsafe.Pointer(p)).FnStep != 0 {
			(*TCallCount)(unsafe.Pointer(p)).FnValue++
			(*TCallCount)(unsafe.Pointer(p)).FnStep = 0
		}
		Xsqlite3_result_int64(tls, pCtx, (*TCallCount)(unsafe.Pointer(p)).FnValue)
	}
}

/*
** Implementation of built-in window function nth_value(). This
** implementation is used in "slow mode" only - when the EXCLUDE clause
** is not set to the default value "NO OTHERS".
 */
type TNthValueCtx = struct {
	F__ccgo_align [0]uint32
	FnStep        Ti64
	FpValue       uintptr
	F__ccgo_pad2  [4]byte
}

type NthValueCtx = TNthValueCtx

func _nth_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var fVal float64
	var iVal Ti64
	var p uintptr
	_, _, _ = fVal, iVal, p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(16))
	if p != 0 {
		switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*4))) {
		case int32(SQLITE_INTEGER):
			iVal = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*4)))
		case int32(SQLITE_FLOAT):
			fVal = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*4)))
			if float64(int64(int64(fVal))) != fVal {
				goto error_out
			}
			iVal = int64(int64(fVal))
		default:
			goto error_out
		}
		if iVal <= 0 {
			goto error_out
		}
		(*TNthValueCtx)(unsafe.Pointer(p)).FnStep++
		if iVal == (*TNthValueCtx)(unsafe.Pointer(p)).FnStep {
			(*TNthValueCtx)(unsafe.Pointer(p)).FpValue = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(apArg)))
			if !((*TNthValueCtx)(unsafe.Pointer(p)).FpValue != 0) {
				Xsqlite3_result_error_nomem(tls, pCtx)
			}
		}
	}
	_ = nArg
	_ = apArg
	return
	goto error_out
error_out:
	;
	Xsqlite3_result_error(tls, pCtx, __ccgo_ts+24027, -int32(1))
}

func _nth_valueFinalizeFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, 0)
	if p != 0 && (*TNthValueCtx)(unsafe.Pointer(p)).FpValue != 0 {
		Xsqlite3_result_value(tls, pCtx, (*TNthValueCtx)(unsafe.Pointer(p)).FpValue)
		Xsqlite3_value_free(tls, (*TNthValueCtx)(unsafe.Pointer(p)).FpValue)
		(*TNthValueCtx)(unsafe.Pointer(p)).FpValue = uintptr(0)
	}
}

func _first_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(16))
	if p != 0 && (*TNthValueCtx)(unsafe.Pointer(p)).FpValue == uintptr(0) {
		(*TNthValueCtx)(unsafe.Pointer(p)).FpValue = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(apArg)))
		if !((*TNthValueCtx)(unsafe.Pointer(p)).FpValue != 0) {
			Xsqlite3_result_error_nomem(tls, pCtx)
		}
	}
	_ = nArg
	_ = apArg
}

func _first_valueFinalizeFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(16))
	if p != 0 && (*TNthValueCtx)(unsafe.Pointer(p)).FpValue != 0 {
		Xsqlite3_result_value(tls, pCtx, (*TNthValueCtx)(unsafe.Pointer(p)).FpValue)
		Xsqlite3_value_free(tls, (*TNthValueCtx)(unsafe.Pointer(p)).FpValue)
		(*TNthValueCtx)(unsafe.Pointer(p)).FpValue = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Implementation of built-in window function rank(). Assumes that
//	** the window frame has been set to:
//	**
//	**   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
//	*/
func _rankStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		(*TCallCount)(unsafe.Pointer(p)).FnStep++
		if (*TCallCount)(unsafe.Pointer(p)).FnValue == 0 {
			(*TCallCount)(unsafe.Pointer(p)).FnValue = (*TCallCount)(unsafe.Pointer(p)).FnStep
		}
	}
	_ = nArg
	_ = apArg
}

func _rankValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		Xsqlite3_result_int64(tls, pCtx, (*TCallCount)(unsafe.Pointer(p)).FnValue)
		(*TCallCount)(unsafe.Pointer(p)).FnValue = 0
	}
}

// C documentation
//
//	/*
//	** Implementation of built-in window function percent_rank(). Assumes that
//	** the window frame has been set to:
//	**
//	**   GROUPS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
//	*/
func _percent_rankStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		(*TCallCount)(unsafe.Pointer(p)).FnTotal++
	}
}

func _percent_rankInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	(*TCallCount)(unsafe.Pointer(p)).FnStep++
}

func _percent_rankValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	var r float64
	_, _ = p, r
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		(*TCallCount)(unsafe.Pointer(p)).FnValue = (*TCallCount)(unsafe.Pointer(p)).FnStep
		if (*TCallCount)(unsafe.Pointer(p)).FnTotal > int64(1) {
			r = float64((*TCallCount)(unsafe.Pointer(p)).FnValue) / float64((*TCallCount)(unsafe.Pointer(p)).FnTotal-libc.Int64FromInt32(1))
			Xsqlite3_result_double(tls, pCtx, r)
		} else {
			Xsqlite3_result_double(tls, pCtx, float64(0))
		}
	}
}

// C documentation
//
//	/*
//	** Implementation of built-in window function cume_dist(). Assumes that
//	** the window frame has been set to:
//	**
//	**   GROUPS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
//	*/
func _cume_distStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		(*TCallCount)(unsafe.Pointer(p)).FnTotal++
	}
}

func _cume_distInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	(*TCallCount)(unsafe.Pointer(p)).FnStep++
}

func _cume_distValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	var r float64
	_, _ = p, r
	p = Xsqlite3_aggregate_context(tls, pCtx, 0)
	if p != 0 {
		r = float64((*TCallCount)(unsafe.Pointer(p)).FnStep) / float64((*TCallCount)(unsafe.Pointer(p)).FnTotal)
		Xsqlite3_result_double(tls, pCtx, r)
	}
}

/*
** Context object for ntile() window function.
 */
type TNtileCtx = struct {
	F__ccgo_align [0]uint32
	FnTotal       Ti64
	FnParam       Ti64
	FiRow         Ti64
}

type NtileCtx = TNtileCtx

// C documentation
//
//	/*
//	** Implementation of ntile(). This assumes that the window frame has
//	** been coerced to:
//	**
//	**   ROWS CURRENT ROW AND UNBOUNDED FOLLOWING
//	*/
func _ntileStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		if (*TNtileCtx)(unsafe.Pointer(p)).FnTotal == 0 {
			(*TNtileCtx)(unsafe.Pointer(p)).FnParam = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apArg)))
			if (*TNtileCtx)(unsafe.Pointer(p)).FnParam <= 0 {
				Xsqlite3_result_error(tls, pCtx, __ccgo_ts+24083, -int32(1))
			}
		}
		(*TNtileCtx)(unsafe.Pointer(p)).FnTotal++
	}
}

func _ntileInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	(*TNtileCtx)(unsafe.Pointer(p)).FiRow++
}

func _ntileValueFunc(tls *libc.TLS, pCtx uintptr) {
	var iRow, iSmall, nLarge Ti64
	var nSize int32
	var p uintptr
	_, _, _, _, _ = iRow, iSmall, nLarge, nSize, p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 && (*TNtileCtx)(unsafe.Pointer(p)).FnParam > 0 {
		nSize = int32((*TNtileCtx)(unsafe.Pointer(p)).FnTotal / (*TNtileCtx)(unsafe.Pointer(p)).FnParam)
		if nSize == 0 {
			Xsqlite3_result_int64(tls, pCtx, (*TNtileCtx)(unsafe.Pointer(p)).FiRow+int64(1))
		} else {
			nLarge = (*TNtileCtx)(unsafe.Pointer(p)).FnTotal - (*TNtileCtx)(unsafe.Pointer(p)).FnParam*int64(int64(nSize))
			iSmall = nLarge * int64(nSize+libc.Int32FromInt32(1))
			iRow = (*TNtileCtx)(unsafe.Pointer(p)).FiRow
			if iRow < iSmall {
				Xsqlite3_result_int64(tls, pCtx, int64(1)+iRow/int64(nSize+libc.Int32FromInt32(1)))
			} else {
				Xsqlite3_result_int64(tls, pCtx, int64(1)+nLarge+(iRow-iSmall)/int64(int64(nSize)))
			}
		}
	}
}

/*
** Context object for last_value() window function.
 */
type TLastValueCtx = struct {
	FpVal uintptr
	FnVal int32
}

type LastValueCtx = TLastValueCtx

// C documentation
//
//	/*
//	** Implementation of last_value().
//	*/
func _last_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 {
		Xsqlite3_value_free(tls, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
		(*TLastValueCtx)(unsafe.Pointer(p)).FpVal = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(apArg)))
		if (*TLastValueCtx)(unsafe.Pointer(p)).FpVal == uintptr(0) {
			Xsqlite3_result_error_nomem(tls, pCtx)
		} else {
			(*TLastValueCtx)(unsafe.Pointer(p)).FnVal++
		}
	}
}

func _last_valueInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 {
		(*TLastValueCtx)(unsafe.Pointer(p)).FnVal--
		if (*TLastValueCtx)(unsafe.Pointer(p)).FnVal == 0 {
			Xsqlite3_value_free(tls, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
			(*TLastValueCtx)(unsafe.Pointer(p)).FpVal = uintptr(0)
		}
	}
}

func _last_valueValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, 0)
	if p != 0 && (*TLastValueCtx)(unsafe.Pointer(p)).FpVal != 0 {
		Xsqlite3_result_value(tls, pCtx, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
	}
}

func _last_valueFinalizeFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 && (*TLastValueCtx)(unsafe.Pointer(p)).FpVal != 0 {
		Xsqlite3_result_value(tls, pCtx, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
		Xsqlite3_value_free(tls, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
		(*TLastValueCtx)(unsafe.Pointer(p)).FpVal = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Static names for the built-in window function names.  These static
//	** names are used, rather than string literals, so that FuncDef objects
//	** can be associated with a particular window function by direct
//	** comparison of the zName pointer.  Example:
//	**
//	**       if( pFuncDef->zName==row_valueName ){ ... }
//	*/
var _row_numberName = [11]int8{'r', 'o', 'w', '_', 'n', 'u', 'm', 'b', 'e', 'r'}
var _dense_rankName = [11]int8{'d', 'e', 'n', 's', 'e', '_', 'r', 'a', 'n', 'k'}
var _rankName = [5]int8{'r', 'a', 'n', 'k'}
var _percent_rankName = [13]int8{'p', 'e', 'r', 'c', 'e', 'n', 't', '_', 'r', 'a', 'n', 'k'}
var _cume_distName = [10]int8{'c', 'u', 'm', 'e', '_', 'd', 'i', 's', 't'}
var _ntileName = [6]int8{'n', 't', 'i', 'l', 'e'}
var _last_valueName = [11]int8{'l', 'a', 's', 't', '_', 'v', 'a', 'l', 'u', 'e'}
var _nth_valueName = [10]int8{'n', 't', 'h', '_', 'v', 'a', 'l', 'u', 'e'}
var _first_valueName = [12]int8{'f', 'i', 'r', 's', 't', '_', 'v', 'a', 'l', 'u', 'e'}
var _leadName = [5]int8{'l', 'e', 'a', 'd'}
var _lagName = [4]int8{'l', 'a', 'g'}

// C documentation
//
//	/*
//	** No-op implementations of xStep() and xFinalize().  Used as place-holders
//	** for built-in window functions that never call those interfaces.
//	**
//	** The noopValueFunc() is called but is expected to do nothing.  The
//	** noopStepFunc() is never called, and so it is marked with NO_TEST to
//	** let the test coverage routine know not to expect this function to be
//	** invoked.
//	*/
func _noopStepFunc(tls *libc.TLS, p uintptr, n int32, a uintptr) {
	/*NO_TEST*/
	_ = p /*NO_TEST*/
	_ = n /*NO_TEST*/
	_ = a /*NO_TEST*/
	/*NO_TEST*/
}

/*NO_TEST*/
func _noopValueFunc(tls *libc.TLS, p uintptr) {
	_ = p /*no-op*/
}

/* Window functions that use all window interfaces: xStep, xFinal,
** xValue, and xInverse */

/* Window functions that are implemented using bytecode and thus have
** no-op routines for their methods */

/* Window functions that use all window interfaces: xStep, the
** same routine for xFinalize and xValue and which never call
** xInverse. */

// C documentation
//
//	/*
//	** Register those built-in window functions that are not also aggregates.
//	*/
func _sqlite3WindowFunctions(tls *libc.TLS) {
	_sqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&_aWindowFuncs)), int32(libc.Uint32FromInt64(600)/libc.Uint32FromInt64(40)))
}

var _aWindowFuncs = [15]TFuncDef{
	0: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_row_numberName)),
	},
	1: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_dense_rankName)),
	},
	2: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_rankName)),
	},
	3: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_percent_rankName)),
	},
	4: {
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_cume_distName)),
	},
	5: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_ntileName)),
	},
	6: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_last_valueName)),
	},
	7: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_nth_valueName)),
	},
	8: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_first_valueName)),
	},
	9: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_leadName)),
	},
	10: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_leadName)),
	},
	11: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_leadName)),
	},
	12: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_lagName)),
	},
	13: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_lagName)),
	},
	14: {
		FnArg:      int8(3),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_WINDOW) | libc.Int32FromInt32(0)),
		FzName:     uintptr(unsafe.Pointer(&_lagName)),
	},
}

func init() {
	p := unsafe.Pointer(&_aWindowFuncs)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_row_numberStepFunc)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_row_numberValueFunc)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_row_numberValueFunc)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_dense_rankStepFunc)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_dense_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_dense_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_rankStepFunc)
	*(*uintptr)(unsafe.Add(p, 100)) = __ccgo_fp(_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 108)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_percent_rankStepFunc)
	*(*uintptr)(unsafe.Add(p, 140)) = __ccgo_fp(_percent_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 144)) = __ccgo_fp(_percent_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 148)) = __ccgo_fp(_percent_rankInvFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_cume_distStepFunc)
	*(*uintptr)(unsafe.Add(p, 180)) = __ccgo_fp(_cume_distValueFunc)
	*(*uintptr)(unsafe.Add(p, 184)) = __ccgo_fp(_cume_distValueFunc)
	*(*uintptr)(unsafe.Add(p, 188)) = __ccgo_fp(_cume_distInvFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_ntileStepFunc)
	*(*uintptr)(unsafe.Add(p, 220)) = __ccgo_fp(_ntileValueFunc)
	*(*uintptr)(unsafe.Add(p, 224)) = __ccgo_fp(_ntileValueFunc)
	*(*uintptr)(unsafe.Add(p, 228)) = __ccgo_fp(_ntileInvFunc)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_last_valueStepFunc)
	*(*uintptr)(unsafe.Add(p, 260)) = __ccgo_fp(_last_valueFinalizeFunc)
	*(*uintptr)(unsafe.Add(p, 264)) = __ccgo_fp(_last_valueValueFunc)
	*(*uintptr)(unsafe.Add(p, 268)) = __ccgo_fp(_last_valueInvFunc)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_nth_valueStepFunc)
	*(*uintptr)(unsafe.Add(p, 300)) = __ccgo_fp(_nth_valueFinalizeFunc)
	*(*uintptr)(unsafe.Add(p, 304)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 308)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_first_valueStepFunc)
	*(*uintptr)(unsafe.Add(p, 340)) = __ccgo_fp(_first_valueFinalizeFunc)
	*(*uintptr)(unsafe.Add(p, 344)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 348)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 380)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 384)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 388)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 420)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 424)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 428)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 460)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 464)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 468)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 500)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 504)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 508)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 540)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 544)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 548)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 580)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 584)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 588)) = __ccgo_fp(_noopStepFunc)
}

func _windowFind(tls *libc.TLS, pParse uintptr, pList uintptr, zName uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	_ = p
	p = pList
	for {
		if !(p != 0) {
			break
		}
		if _sqlite3StrICmp(tls, (*TWindow)(unsafe.Pointer(p)).FzName, zName) == 0 {
			break
		}
		goto _1
	_1:
		;
		p = (*TWindow)(unsafe.Pointer(p)).FpNextWin
	}
	if p == uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24128, libc.VaList(bp+8, zName))
	}
	return p
}

// C documentation
//
//	/*
//	** This function is called immediately after resolving the function name
//	** for a window function within a SELECT statement. Argument pList is a
//	** linked list of WINDOW definitions for the current SELECT statement.
//	** Argument pFunc is the function definition just resolved and pWin
//	** is the Window object representing the associated OVER clause. This
//	** function updates the contents of pWin as follows:
//	**
//	**   * If the OVER clause referred to a named window (as in "max(x) OVER win"),
//	**     search list pList for a matching WINDOW definition, and update pWin
//	**     accordingly. If no such WINDOW clause can be found, leave an error
//	**     in pParse.
//	**
//	**   * If the function is a built-in window function that requires the
//	**     window to be coerced (see "BUILT-IN WINDOW FUNCTIONS" at the top
//	**     of this file), pWin is updated here.
//	*/
func _sqlite3WindowUpdate(tls *libc.TLS, pParse uintptr, pList uintptr, pWin uintptr, pFunc uintptr) {
	var aUp [8]struct {
		FzFunc    uintptr
		FeFrmType int32
		FeStart   int32
		FeEnd     int32
	}
	var db, p, v2 uintptr
	var i int32
	_, _, _, _, _ = aUp, db, i, p, v2
	if (*TWindow)(unsafe.Pointer(pWin)).FzName != 0 && int32((*TWindow)(unsafe.Pointer(pWin)).FeFrmType) == 0 {
		p = _windowFind(tls, pParse, pList, (*TWindow)(unsafe.Pointer(pWin)).FzName)
		if p == uintptr(0) {
			return
		}
		(*TWindow)(unsafe.Pointer(pWin)).FpPartition = _sqlite3ExprListDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpPartition, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FpOrderBy = _sqlite3ExprListDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpOrderBy, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FpStart = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpStart, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FpEnd = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpEnd, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FeStart = (*TWindow)(unsafe.Pointer(p)).FeStart
		(*TWindow)(unsafe.Pointer(pWin)).FeEnd = (*TWindow)(unsafe.Pointer(p)).FeEnd
		(*TWindow)(unsafe.Pointer(pWin)).FeFrmType = (*TWindow)(unsafe.Pointer(p)).FeFrmType
		(*TWindow)(unsafe.Pointer(pWin)).FeExclude = (*TWindow)(unsafe.Pointer(p)).FeExclude
	} else {
		_sqlite3WindowChain(tls, pParse, pWin, pList)
	}
	if int32((*TWindow)(unsafe.Pointer(pWin)).FeFrmType) == int32(TK_RANGE) && ((*TWindow)(unsafe.Pointer(pWin)).FpStart != 0 || (*TWindow)(unsafe.Pointer(pWin)).FpEnd != 0) && ((*TWindow)(unsafe.Pointer(pWin)).FpOrderBy == uintptr(0) || (*TExprList)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOrderBy)).FnExpr != int32(1)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24147, 0)
	} else {
		if (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(SQLITE_FUNC_WINDOW) != 0 {
			db = (*TParse)(unsafe.Pointer(pParse)).Fdb
			if (*TWindow)(unsafe.Pointer(pWin)).FpFilter != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24218, 0)
			} else {
				aUp = [8]struct {
					FzFunc    uintptr
					FeFrmType int32
					FeStart   int32
					FeEnd     int32
				}{
					0: {
						FzFunc:    uintptr(unsafe.Pointer(&_row_numberName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
					1: {
						FzFunc:    uintptr(unsafe.Pointer(&_dense_rankName)),
						FeFrmType: int32(TK_RANGE),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
					2: {
						FzFunc:    uintptr(unsafe.Pointer(&_rankName)),
						FeFrmType: int32(TK_RANGE),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
					3: {
						FzFunc:    uintptr(unsafe.Pointer(&_percent_rankName)),
						FeFrmType: int32(TK_GROUPS),
						FeStart:   int32(TK_CURRENT),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					4: {
						FzFunc:    uintptr(unsafe.Pointer(&_cume_distName)),
						FeFrmType: int32(TK_GROUPS),
						FeStart:   int32(TK_FOLLOWING),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					5: {
						FzFunc:    uintptr(unsafe.Pointer(&_ntileName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_CURRENT),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					6: {
						FzFunc:    uintptr(unsafe.Pointer(&_leadName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					7: {
						FzFunc:    uintptr(unsafe.Pointer(&_lagName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
				}
				i = 0
				for {
					if !(i < int32(libc.Uint32FromInt64(128)/libc.Uint32FromInt64(16))) {
						break
					}
					if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == aUp[i].FzFunc {
						_sqlite3ExprDelete(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FpStart)
						_sqlite3ExprDelete(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FpEnd)
						v2 = libc.UintptrFromInt32(0)
						(*TWindow)(unsafe.Pointer(pWin)).FpStart = v2
						(*TWindow)(unsafe.Pointer(pWin)).FpEnd = v2
						(*TWindow)(unsafe.Pointer(pWin)).FeFrmType = uint8(aUp[i].FeFrmType)
						(*TWindow)(unsafe.Pointer(pWin)).FeStart = uint8(aUp[i].FeStart)
						(*TWindow)(unsafe.Pointer(pWin)).FeEnd = uint8(aUp[i].FeEnd)
						(*TWindow)(unsafe.Pointer(pWin)).FeExclude = uint8(0)
						if int32((*TWindow)(unsafe.Pointer(pWin)).FeStart) == int32(TK_FOLLOWING) {
							(*TWindow)(unsafe.Pointer(pWin)).FpStart = _sqlite3Expr(tls, db, int32(TK_INTEGER), __ccgo_ts+9564)
						}
						break
					}
					goto _1
				_1:
					;
					i++
				}
			}
		}
	}
	(*TWindow)(unsafe.Pointer(pWin)).FpWFunc = pFunc
}

// C documentation
//
//	/*
//	** Context object passed through sqlite3WalkExprList() to
//	** selectWindowRewriteExprCb() by selectWindowRewriteEList().
//	*/
type TWindowRewrite = struct {
	FpWin       uintptr
	FpSrc       uintptr
	FpSub       uintptr
	FpTab       uintptr
	FpSubSelect uintptr
}

type WindowRewrite = TWindowRewrite

type TWindowRewrite1 = struct {
	FpWin       uintptr
	FpSrc       uintptr
	FpSub       uintptr
	FpTab       uintptr
	FpSubSelect uintptr
}

type WindowRewrite1 = TWindowRewrite1

// C documentation
//
//	/*
//	** Callback function used by selectWindowRewriteEList(). If necessary,
//	** this function appends to the output expression-list and updates
//	** expression (*ppExpr) in place.
//	*/
func _selectWindowRewriteExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var f, i, i1, iCol, nSrc, v4 int32
	var p, pDup, pParse, pWin uintptr
	_, _, _, _, _, _, _, _, _, _ = f, i, i1, iCol, nSrc, p, pDup, pParse, pWin, v4
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	/* If this function is being called from within a scalar sub-select
	 ** that used by the SELECT statement being processed, only process
	 ** TK_COLUMN expressions that refer to it (the outer SELECT). Do
	 ** not process aggregates or window functions at all, as they belong
	 ** to the scalar sub-select.  */
	if (*TWindowRewrite1)(unsafe.Pointer(p)).FpSubSelect != 0 {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLUMN) {
			return WRC_Continue
		} else {
			nSrc = (*TSrcList)(unsafe.Pointer((*TWindowRewrite1)(unsafe.Pointer(p)).FpSrc)).FnSrc
			i = 0
			for {
				if !(i < nSrc) {
					break
				}
				if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*(*TSrcItem)(unsafe.Pointer((*TWindowRewrite1)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*72))).FiCursor {
					break
				}
				goto _1
			_1:
				;
				i++
			}
			if i == nSrc {
				return WRC_Continue
			}
		}
	}
	switch int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	case int32(TK_FUNCTION):
		if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(libc.Int32FromInt32(EP_WinFunc)) != libc.Uint32FromInt32(0)) {
			break
		} else {
			pWin = (*TWindowRewrite1)(unsafe.Pointer(p)).FpWin
			for {
				if !(pWin != 0) {
					break
				}
				if *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)) == pWin {
					return int32(WRC_Prune)
				}
				goto _2
			_2:
				;
				pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
			}
		}
		fallthrough
	case int32(TK_IF_NULL_ROW):
		fallthrough
	case int32(TK_AGG_FUNCTION):
		fallthrough
	case int32(TK_COLUMN):
		iCol = -int32(1)
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
			return int32(WRC_Abort)
		}
		if (*TWindowRewrite1)(unsafe.Pointer(p)).FpSub != 0 {
			i1 = 0
			for {
				if !(i1 < (*TExprList)(unsafe.Pointer((*TWindowRewrite1)(unsafe.Pointer(p)).FpSub)).FnExpr) {
					break
				}
				if 0 == _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer((*TWindowRewrite1)(unsafe.Pointer(p)).FpSub + 8 + uintptr(i1)*20))).FpExpr, pExpr, -int32(1)) {
					iCol = i1
					break
				}
				goto _3
			_3:
				;
				i1++
			}
		}
		if iCol < 0 {
			pDup = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
			if pDup != 0 && int32((*TExpr)(unsafe.Pointer(pDup)).Fop) == int32(TK_AGG_FUNCTION) {
				(*TExpr)(unsafe.Pointer(pDup)).Fop = uint8(TK_FUNCTION)
			}
			(*TWindowRewrite1)(unsafe.Pointer(p)).FpSub = _sqlite3ExprListAppend(tls, pParse, (*TWindowRewrite1)(unsafe.Pointer(p)).FpSub, pDup)
		}
		if (*TWindowRewrite1)(unsafe.Pointer(p)).FpSub != 0 {
			f = int32((*TExpr)(unsafe.Pointer(pExpr)).Fflags & uint32(EP_Collate))
			*(*Tu32)(unsafe.Pointer(pExpr + 4)) |= uint32(libc.Int32FromInt32(EP_Static))
			_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
			*(*Tu32)(unsafe.Pointer(pExpr + 4)) &= uint32(^libc.Int32FromInt32(EP_Static))
			libc.Xmemset(tls, pExpr, 0, uint32(52))
			(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_COLUMN)
			if iCol < 0 {
				v4 = (*TExprList)(unsafe.Pointer((*TWindowRewrite1)(unsafe.Pointer(p)).FpSub)).FnExpr - int32(1)
			} else {
				v4 = iCol
			}
			(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(v4)
			(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TWindow)(unsafe.Pointer((*TWindowRewrite1)(unsafe.Pointer(p)).FpWin)).FiEphCsr
			(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = (*TWindowRewrite1)(unsafe.Pointer(p)).FpTab
			(*TExpr)(unsafe.Pointer(pExpr)).Fflags = uint32(uint32(f))
		}
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
			return int32(WRC_Abort)
		}
	default: /* no-op */
		break
	}
	return WRC_Continue
}

func _selectWindowRewriteSelectCb(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	var p, pSave uintptr
	_, _ = p, pSave
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pSave = (*TWindowRewrite1)(unsafe.Pointer(p)).FpSubSelect
	if pSave == pSelect {
		return WRC_Continue
	} else {
		(*TWindowRewrite1)(unsafe.Pointer(p)).FpSubSelect = pSelect
		_sqlite3WalkSelect(tls, pWalker, pSelect)
		(*TWindowRewrite1)(unsafe.Pointer(p)).FpSubSelect = pSave
	}
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** Iterate through each expression in expression-list pEList. For each:
//	**
//	**   * TK_COLUMN,
//	**   * aggregate function, or
//	**   * window function with a Window object that is not a member of the
//	**     Window list passed as the second argument (pWin).
//	**
//	** Append the node to output expression-list (*ppSub). And replace it
//	** with a TK_COLUMN that reads the (N-1)th element of table
//	** pWin->iEphCsr, where N is the number of elements in (*ppSub) after
//	** appending the new one.
//	*/
func _selectWindowRewriteEList(tls *libc.TLS, pParse uintptr, pWin uintptr, pSrc uintptr, pEList uintptr, pTab uintptr, ppSub uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* sRewrite at bp+28 */ TWindowRewrite
	var _ /* sWalker at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	libc.Xmemset(tls, bp+28, 0, uint32(20))
	(*(*TWindowRewrite)(unsafe.Pointer(bp + 28))).FpSub = *(*uintptr)(unsafe.Pointer(ppSub))
	(*(*TWindowRewrite)(unsafe.Pointer(bp + 28))).FpWin = pWin
	(*(*TWindowRewrite)(unsafe.Pointer(bp + 28))).FpSrc = pSrc
	(*(*TWindowRewrite)(unsafe.Pointer(bp + 28))).FpTab = pTab
	(*(*TWalker)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TWalker)(unsafe.Pointer(bp))).FxExprCallback = __ccgo_fp(_selectWindowRewriteExprCb)
	(*(*TWalker)(unsafe.Pointer(bp))).FxSelectCallback = __ccgo_fp(_selectWindowRewriteSelectCb)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = bp + 28
	_sqlite3WalkExprList(tls, bp, pEList)
	*(*uintptr)(unsafe.Pointer(ppSub)) = (*(*TWindowRewrite)(unsafe.Pointer(bp + 28))).FpSub
}

// C documentation
//
//	/*
//	** Append a copy of each expression in expression-list pAppend to
//	** expression list pList. Return a pointer to the result list.
//	*/
func _exprListAppendList(tls *libc.TLS, pParse uintptr, pList uintptr, pAppend uintptr, bIntToNull int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pDup, pSub uintptr
	var i, nInit, v1 int32
	var _ /* iDummy at bp+0 */ int32
	_, _, _, _, _, _ = db, i, nInit, pDup, pSub, v1
	if pAppend != 0 {
		if pList != 0 {
			v1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
		} else {
			v1 = 0
		}
		nInit = v1
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pAppend)).FnExpr) {
				break
			}
			db = (*TParse)(unsafe.Pointer(pParse)).Fdb
			pDup = _sqlite3ExprDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pAppend + 8 + uintptr(i)*20))).FpExpr, 0)
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				_sqlite3ExprDelete(tls, db, pDup)
				break
			}
			if bIntToNull != 0 {
				pSub = _sqlite3ExprSkipCollateAndLikely(tls, pDup)
				if _sqlite3ExprIsInteger(tls, pSub, bp) != 0 {
					(*TExpr)(unsafe.Pointer(pSub)).Fop = uint8(TK_NULL)
					*(*Tu32)(unsafe.Pointer(pSub + 4)) &= uint32(^(libc.Int32FromInt32(EP_IntValue) | libc.Int32FromInt32(EP_IsTrue) | libc.Int32FromInt32(EP_IsFalse)))
					*(*uintptr)(unsafe.Pointer(pSub + 8)) = uintptr(0)
				}
			}
			pList = _sqlite3ExprListAppend(tls, pParse, pList, pDup)
			if pList != 0 {
				(*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(nInit+i)*20))).Ffg.FsortFlags = (*(*TExprList_item)(unsafe.Pointer(pAppend + 8 + uintptr(i)*20))).Ffg.FsortFlags
			}
			goto _2
		_2:
			;
			i++
		}
	}
	return pList
}

// C documentation
//
//	/*
//	** When rewriting a query, if the new subquery in the FROM clause
//	** contains TK_AGG_FUNCTION nodes that refer to an outer query,
//	** then we have to increase the Expr->op2 values of those nodes
//	** due to the extra subquery layer that was added.
//	**
//	** See also the incrAggDepth() routine in resolve.c
//	*/
func _sqlite3WindowExtraAggFuncDepth(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_FUNCTION) && int32((*TExpr)(unsafe.Pointer(pExpr)).Fop2) >= (*TWalker)(unsafe.Pointer(pWalker)).FwalkerDepth {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop2++
	}
	return WRC_Continue
}

func _disallowAggregatesInOrderByCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if int32((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_FUNCTION) && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
		_sqlite3ErrorMsg(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, __ccgo_ts+24281, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
	}
	return WRC_Continue
}

// 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(32)
	defer tls.Free(32)
	var db, pArgs, pFilter, pGroupBy, pHaving, pMWin, pSort, pSrc, pSub, pTab, pTab2, pWhere, pWin, v, v10, v2, v8 uintptr
	var nSave, rc, v1, v3, v5, v6, v7, v9 int32
	var selFlags Tu32
	var _ /* pSublist at bp+0 */ uintptr
	var _ /* w at bp+4 */ TWalker
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, nSave, pArgs, pFilter, pGroupBy, pHaving, pMWin, pSort, pSrc, pSub, pTab, pTab2, pWhere, pWin, rc, selFlags, v, v1, v10, v2, v3, v5, v6, v7, v8, v9
	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) && !(int32((*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)(unsafe.Pointer(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(64))
		if pTab == uintptr(0) {
			return _sqlite3ErrorToParser(tls, db, int32(SQLITE_NOMEM))
		}
		_sqlite3AggInfoPersistWalkerInit(tls, bp+4, pParse)
		_sqlite3WalkSelect(tls, bp+4, p)
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) == uint32(0) {
			(*(*TWalker)(unsafe.Pointer(bp + 4))).FxExprCallback = __ccgo_fp(_disallowAggregatesInOrderByCb)
			(*(*TWalker)(unsafe.Pointer(bp + 4))).FxSelectCallback = uintptr(0)
			_sqlite3WalkExprList(tls, bp+4, (*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)(unsafe.Pointer(p + 4)) &= uint32(^libc.Int32FromInt32(SF_Aggregate))
		*(*Tu32)(unsafe.Pointer(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 + 40
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2))++
		(*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr = v1
		*(*int32)(unsafe.Pointer(pParse + 40)) += 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)(unsafe.Pointer(bp)) != 0 {
			v3 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnExpr
		} else {
			v3 = 0
		}
		(*TWindow)(unsafe.Pointer(pMWin)).FnBufferCol = v3
		/* 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)(unsafe.Pointer(bp)) = _exprListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(bp)), (*TWindow)(unsafe.Pointer(pMWin)).FpPartition, 0)
		*(*uintptr)(unsafe.Pointer(bp)) = _exprListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(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 + 20))
			if (*TFuncDef)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpWFunc)).FfuncFlags&uint32(SQLITE_SUBTYPE) != 0 {
				_selectWindowRewriteEList(tls, pParse, pMWin, pSrc, pArgs, pTab, bp)
				if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
					v5 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnExpr
				} else {
					v5 = 0
				}
				(*TWindow)(unsafe.Pointer(pWin)).FiArgCol = v5
				(*TWindow)(unsafe.Pointer(pWin)).FbExprArgs = uint8(1)
			} else {
				if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
					v6 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnExpr
				} else {
					v6 = 0
				}
				(*TWindow)(unsafe.Pointer(pWin)).FiArgCol = v6
				*(*uintptr)(unsafe.Pointer(bp)) = _exprListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(bp)), pArgs, 0)
			}
			if (*TWindow)(unsafe.Pointer(pWin)).FpFilter != 0 {
				pFilter = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FpFilter, 0)
				*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(bp)), pFilter)
			}
			v8 = pParse + 44
			*(*int32)(unsafe.Pointer(v8))++
			v7 = *(*int32)(unsafe.Pointer(v8))
			(*TWindow)(unsafe.Pointer(pWin)).FregAccum = v7
			v10 = pParse + 44
			*(*int32)(unsafe.Pointer(v10))++
			v9 = *(*int32)(unsafe.Pointer(v10))
			(*TWindow)(unsafe.Pointer(pWin)).FregResult = v9
			_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)(unsafe.Pointer(bp)) == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3Expr(tls, db, int32(TK_INTEGER), __ccgo_ts+1792))
		}
		pSub = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(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 != 0 {
			(*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSelect = pSub
			libc.SetBitFieldPtr16Uint32((*TSelect)(unsafe.Pointer(p)).FpSrc+8+36+4, libc.Uint32FromInt32(1), 3, 0x8)
			_sqlite3SrcListAssignCursors(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpSrc)
			*(*Tu32)(unsafe.Pointer(pSub + 4)) |= uint32(libc.Int32FromInt32(SF_Expanded) | libc.Int32FromInt32(SF_OrderByReqd))
			pTab2 = _sqlite3ResultSetOfSelect(tls, pParse, pSub, int8(SQLITE_AFF_NONE))
			*(*Tu32)(unsafe.Pointer(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, uint32(64))
				*(*Tu32)(unsafe.Pointer(pTab + 28)) |= uint32(TF_Ephemeral)
				(*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpTab = pTab
				pTab = pTab2
				libc.Xmemset(tls, bp+4, 0, uint32(28))
				(*(*TWalker)(unsafe.Pointer(bp + 4))).FxExprCallback = __ccgo_fp(_sqlite3WindowExtraAggFuncDepth)
				(*(*TWalker)(unsafe.Pointer(bp + 4))).FxSelectCallback = __ccgo_fp(_sqlite3WalkerDepthIncrease)
				(*(*TWalker)(unsafe.Pointer(bp + 4))).FxSelectCallback2 = __ccgo_fp(_sqlite3WalkerDepthDecrease)
				_sqlite3WalkSelect(tls, bp+4, pSub)
			}
		} else {
			_sqlite3SelectDelete(tls, db, 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
//
//	/*
//	** Unlink the Window object from the Select to which it is attached,
//	** if it is attached.
//	*/
func _sqlite3WindowUnlinkFromSelect(tls *libc.TLS, p uintptr) {
	if (*TWindow)(unsafe.Pointer(p)).FppThis != 0 {
		*(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(p)).FppThis)) = (*TWindow)(unsafe.Pointer(p)).FpNextWin
		if (*TWindow)(unsafe.Pointer(p)).FpNextWin != 0 {
			(*TWindow)(unsafe.Pointer((*TWindow)(unsafe.Pointer(p)).FpNextWin)).FppThis = (*TWindow)(unsafe.Pointer(p)).FppThis
		}
		(*TWindow)(unsafe.Pointer(p)).FppThis = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Free the Window object passed as the second argument.
//	*/
func _sqlite3WindowDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		_sqlite3WindowUnlinkFromSelect(tls, p)
		_sqlite3ExprDelete(tls, db, (*TWindow)(unsafe.Pointer(p)).FpFilter)
		_sqlite3ExprListDelete(tls, db, (*TWindow)(unsafe.Pointer(p)).FpPartition)
		_sqlite3ExprListDelete(tls, db, (*TWindow)(unsafe.Pointer(p)).FpOrderBy)
		_sqlite3ExprDelete(tls, db, (*TWindow)(unsafe.Pointer(p)).FpEnd)
		_sqlite3ExprDelete(tls, db, (*TWindow)(unsafe.Pointer(p)).FpStart)
		_sqlite3DbFree(tls, db, (*TWindow)(unsafe.Pointer(p)).FzName)
		_sqlite3DbFree(tls, db, (*TWindow)(unsafe.Pointer(p)).FzBase)
		_sqlite3DbFree(tls, db, p)
	}
}

// C documentation
//
//	/*
//	** Free the linked list of Window objects starting at the second argument.
//	*/
func _sqlite3WindowListDelete(tls *libc.TLS, db uintptr, p uintptr) {
	var pNext uintptr
	_ = pNext
	for p != 0 {
		pNext = (*TWindow)(unsafe.Pointer(p)).FpNextWin
		_sqlite3WindowDelete(tls, db, p)
		p = pNext
	}
}

// C documentation
//
//	/*
//	** The argument expression is an PRECEDING or FOLLOWING offset.  The
//	** value should be a non-negative integer.  If the value is not a
//	** constant, change it to NULL.  The fact that it is then a non-negative
//	** integer will be caught later.  But it is important not to leave
//	** variable values in the expression tree.
//	*/
func _sqlite3WindowOffsetExpr(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r uintptr) {
	if 0 == _sqlite3ExprIsConstant(tls, uintptr(0), pExpr) {
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameExprUnmap(tls, pParse, pExpr)
		}
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		pExpr = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_NULL), uintptr(0), 0)
	}
	return pExpr
}

// C documentation
//
//	/*
//	** Allocate and return a new Window object describing a Window Definition.
//	*/
func _sqlite3WindowAlloc(tls *libc.TLS, pParse uintptr, eType int32, eStart int32, pStart uintptr, eEnd int32, pEnd uintptr, eExclude Tu8) (r uintptr) {
	var bImplicitFrame int32
	var pWin uintptr
	_, _ = bImplicitFrame, pWin
	pWin = uintptr(0)
	bImplicitFrame = 0
	/* Parser assures the following: */
	if eType == 0 {
		bImplicitFrame = int32(1)
		eType = int32(TK_RANGE)
	}
	/* Additionally, the
	 ** starting boundary type may not occur earlier in the following list than
	 ** the ending boundary type:
	 **
	 **   UNBOUNDED PRECEDING
	 **   <expr> PRECEDING
	 **   CURRENT ROW
	 **   <expr> FOLLOWING
	 **   UNBOUNDED FOLLOWING
	 **
	 ** The parser ensures that "UNBOUNDED PRECEDING" cannot be used as an ending
	 ** boundary, and than "UNBOUNDED FOLLOWING" cannot be used as a starting
	 ** frame boundary.
	 */
	if eStart == int32(TK_CURRENT) && eEnd == int32(TK_PRECEDING) || eStart == int32(TK_FOLLOWING) && (eEnd == int32(TK_PRECEDING) || eEnd == int32(TK_CURRENT)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24307, 0)
		goto windowAllocErr
	}
	pWin = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(100))
	if pWin == uintptr(0) {
		goto windowAllocErr
	}
	(*TWindow)(unsafe.Pointer(pWin)).FeFrmType = uint8(uint8(eType))
	(*TWindow)(unsafe.Pointer(pWin)).FeStart = uint8(uint8(eStart))
	(*TWindow)(unsafe.Pointer(pWin)).FeEnd = uint8(uint8(eEnd))
	if int32(int32(eExclude)) == 0 && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&uint32(libc.Int32FromInt32(SQLITE_WindowFunc)) != uint32(0) {
		eExclude = uint8(TK_NO)
	}
	(*TWindow)(unsafe.Pointer(pWin)).FeExclude = eExclude
	(*TWindow)(unsafe.Pointer(pWin)).FbImplicitFrame = uint8(uint8(bImplicitFrame))
	(*TWindow)(unsafe.Pointer(pWin)).FpEnd = _sqlite3WindowOffsetExpr(tls, pParse, pEnd)
	(*TWindow)(unsafe.Pointer(pWin)).FpStart = _sqlite3WindowOffsetExpr(tls, pParse, pStart)
	return pWin
	goto windowAllocErr
windowAllocErr:
	;
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pEnd)
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pStart)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Attach PARTITION and ORDER BY clauses pPartition and pOrderBy to window
//	** pWin. Also, if parameter pBase is not NULL, set pWin->zBase to the
//	** equivalent nul-terminated string.
//	*/
func _sqlite3WindowAssemble(tls *libc.TLS, pParse uintptr, pWin uintptr, pPartition uintptr, pOrderBy uintptr, pBase uintptr) (r uintptr) {
	if pWin != 0 {
		(*TWindow)(unsafe.Pointer(pWin)).FpPartition = pPartition
		(*TWindow)(unsafe.Pointer(pWin)).FpOrderBy = pOrderBy
		if pBase != 0 {
			(*TWindow)(unsafe.Pointer(pWin)).FzBase = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TToken)(unsafe.Pointer(pBase)).Fz, uint64((*TToken)(unsafe.Pointer(pBase)).Fn))
		}
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPartition)
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pOrderBy)
	}
	return pWin
}

// C documentation
//
//	/*
//	** Window *pWin has just been created from a WINDOW clause. Token pBase
//	** is the base window. Earlier windows from the same WINDOW clause are
//	** stored in the linked list starting at pWin->pNextWin. This function
//	** either updates *pWin according to the base specification, or else
//	** leaves an error in pParse.
//	*/
func _sqlite3WindowChain(tls *libc.TLS, pParse uintptr, pWin uintptr, pList uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pExist, zErr uintptr
	_, _, _ = db, pExist, zErr
	if (*TWindow)(unsafe.Pointer(pWin)).FzBase != 0 {
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		pExist = _windowFind(tls, pParse, pList, (*TWindow)(unsafe.Pointer(pWin)).FzBase)
		if pExist != 0 {
			zErr = uintptr(0)
			/* Check for errors */
			if (*TWindow)(unsafe.Pointer(pWin)).FpPartition != 0 {
				zErr = __ccgo_ts + 24339
			} else {
				if (*TWindow)(unsafe.Pointer(pExist)).FpOrderBy != 0 && (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy != 0 {
					zErr = __ccgo_ts + 24356
				} else {
					if int32((*TWindow)(unsafe.Pointer(pExist)).FbImplicitFrame) == 0 {
						zErr = __ccgo_ts + 24372
					}
				}
			}
			if zErr != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24392, libc.VaList(bp+8, zErr, (*TWindow)(unsafe.Pointer(pWin)).FzBase))
			} else {
				(*TWindow)(unsafe.Pointer(pWin)).FpPartition = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(pExist)).FpPartition, 0)
				if (*TWindow)(unsafe.Pointer(pExist)).FpOrderBy != 0 {
					(*TWindow)(unsafe.Pointer(pWin)).FpOrderBy = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(pExist)).FpOrderBy, 0)
				}
				_sqlite3DbFree(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FzBase)
				(*TWindow)(unsafe.Pointer(pWin)).FzBase = uintptr(0)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Attach window object pWin to expression p.
//	*/
func _sqlite3WindowAttach(tls *libc.TLS, pParse uintptr, p uintptr, pWin uintptr) {
	if p != 0 {
		*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(p)).Fy)) = pWin
		*(*Tu32)(unsafe.Pointer(p + 4)) |= uint32(libc.Int32FromInt32(EP_WinFunc) | libc.Int32FromInt32(EP_FullSize))
		(*TWindow)(unsafe.Pointer(pWin)).FpOwner = p
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_Distinct) != 0 && int32((*TWindow)(unsafe.Pointer(pWin)).FeFrmType) != int32(TK_FILTER) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24425, 0)
		}
	} else {
		_sqlite3WindowDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pWin)
	}
}

// C documentation
//
//	/*
//	** Possibly link window pWin into the list at pSel->pWin (window functions
//	** to be processed as part of SELECT statement pSel). The window is linked
//	** in if either (a) there are no other windows already linked to this
//	** SELECT, or (b) the windows already linked use a compatible window frame.
//	*/
func _sqlite3WindowLink(tls *libc.TLS, pSel uintptr, pWin uintptr) {
	if pSel != 0 {
		if uintptr(0) == (*TSelect)(unsafe.Pointer(pSel)).FpWin || 0 == _sqlite3WindowCompare(tls, uintptr(0), (*TSelect)(unsafe.Pointer(pSel)).FpWin, pWin, 0) {
			(*TWindow)(unsafe.Pointer(pWin)).FpNextWin = (*TSelect)(unsafe.Pointer(pSel)).FpWin
			if (*TSelect)(unsafe.Pointer(pSel)).FpWin != 0 {
				(*TWindow)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpWin)).FppThis = pWin + 36
			}
			(*TSelect)(unsafe.Pointer(pSel)).FpWin = pWin
			(*TWindow)(unsafe.Pointer(pWin)).FppThis = pSel + 68
		} else {
			if _sqlite3ExprListCompare(tls, (*TWindow)(unsafe.Pointer(pWin)).FpPartition, (*TWindow)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpWin)).FpPartition, -int32(1)) != 0 {
				*(*Tu32)(unsafe.Pointer(pSel + 4)) |= uint32(SF_MultiPart)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Return 0 if the two window objects are identical, 1 if they are
//	** different, or 2 if it cannot be determined if the objects are identical
//	** or not. Identical window objects can be processed in a single scan.
//	*/
func _sqlite3WindowCompare(tls *libc.TLS, pParse uintptr, p1 uintptr, p2 uintptr, bFilter int32) (r int32) {
	var res, v1, v2, v3 int32
	_, _, _, _ = res, v1, v2, v3
	if p1 == uintptr(0) || p2 == uintptr(0) {
		return int32(1)
	}
	if int32((*TWindow)(unsafe.Pointer(p1)).FeFrmType) != int32((*TWindow)(unsafe.Pointer(p2)).FeFrmType) {
		return int32(1)
	}
	if int32((*TWindow)(unsafe.Pointer(p1)).FeStart) != int32((*TWindow)(unsafe.Pointer(p2)).FeStart) {
		return int32(1)
	}
	if int32((*TWindow)(unsafe.Pointer(p1)).FeEnd) != int32((*TWindow)(unsafe.Pointer(p2)).FeEnd) {
		return int32(1)
	}
	if int32((*TWindow)(unsafe.Pointer(p1)).FeExclude) != int32((*TWindow)(unsafe.Pointer(p2)).FeExclude) {
		return int32(1)
	}
	if _sqlite3ExprCompare(tls, pParse, (*TWindow)(unsafe.Pointer(p1)).FpStart, (*TWindow)(unsafe.Pointer(p2)).FpStart, -int32(1)) != 0 {
		return int32(1)
	}
	if _sqlite3ExprCompare(tls, pParse, (*TWindow)(unsafe.Pointer(p1)).FpEnd, (*TWindow)(unsafe.Pointer(p2)).FpEnd, -int32(1)) != 0 {
		return int32(1)
	}
	v1 = _sqlite3ExprListCompare(tls, (*TWindow)(unsafe.Pointer(p1)).FpPartition, (*TWindow)(unsafe.Pointer(p2)).FpPartition, -int32(1))
	res = v1
	if v1 != 0 {
		return res
	}
	v2 = _sqlite3ExprListCompare(tls, (*TWindow)(unsafe.Pointer(p1)).FpOrderBy, (*TWindow)(unsafe.Pointer(p2)).FpOrderBy, -int32(1))
	res = v2
	if v2 != 0 {
		return res
	}
	if bFilter != 0 {
		v3 = _sqlite3ExprCompare(tls, pParse, (*TWindow)(unsafe.Pointer(p1)).FpFilter, (*TWindow)(unsafe.Pointer(p2)).FpFilter, -int32(1))
		res = v3
		if v3 != 0 {
			return res
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** This is called by code in select.c before it calls sqlite3WhereBegin()
//	** to begin iterating through the sub-query results. It is used to allocate
//	** and initialize registers and cursors used by sqlite3WindowCodeStep().
//	*/
func _sqlite3WindowCodeInit(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	var nEphExpr, nExpr, v1, v10, v12, v14, v3, v5, v7 int32
	var p, pKeyInfo, pList, pMWin, pWin, v, v11, v13, v15, v2, v4, v6, v8 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = nEphExpr, nExpr, p, pKeyInfo, pList, pMWin, pWin, v, v1, v10, v11, v12, v13, v14, v15, v2, v3, v4, v5, v6, v7, v8
	nEphExpr = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8))).FpSelect)).FpEList)).FnExpr
	pMWin = (*TSelect)(unsafe.Pointer(pSelect)).FpWin
	v = _sqlite3GetVdbe(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr, nEphExpr)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr+int32(1), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr+int32(2), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr+int32(3), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr)
	/* Allocate registers to use for PARTITION BY values, if any. Initialize
	 ** said registers to NULL.  */
	if (*TWindow)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		nExpr = (*TExprList)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pMWin)).FpPartition)).FnExpr
		(*TWindow)(unsafe.Pointer(pMWin)).FregPart = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nExpr
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pMWin)).FregPart, (*TWindow)(unsafe.Pointer(pMWin)).FregPart+nExpr-int32(1))
	}
	v2 = pParse + 44
	*(*int32)(unsafe.Pointer(v2))++
	v1 = *(*int32)(unsafe.Pointer(v2))
	(*TWindow)(unsafe.Pointer(pMWin)).FregOne = v1
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), (*TWindow)(unsafe.Pointer(pMWin)).FregOne)
	if (*TWindow)(unsafe.Pointer(pMWin)).FeExclude != 0 {
		v4 = pParse + 44
		*(*int32)(unsafe.Pointer(v4))++
		v3 = *(*int32)(unsafe.Pointer(v4))
		(*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid = v3
		v6 = pParse + 44
		*(*int32)(unsafe.Pointer(v6))++
		v5 = *(*int32)(unsafe.Pointer(v6))
		(*TWindow)(unsafe.Pointer(pMWin)).FregEndRowid = v5
		v8 = pParse + 40
		v7 = *(*int32)(unsafe.Pointer(v8))
		*(*int32)(unsafe.Pointer(v8))++
		(*TWindow)(unsafe.Pointer(pMWin)).FcsrApp = v7
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pMWin)).FregEndRowid)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TWindow)(unsafe.Pointer(pMWin)).FcsrApp, (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr)
		return
	}
	pWin = pMWin
	for {
		if !(pWin != 0) {
			break
		}
		p = (*TWindow)(unsafe.Pointer(pWin)).FpWFunc
		if (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_MINMAX) != 0 && int32((*TWindow)(unsafe.Pointer(pWin)).FeStart) != int32(TK_UNBOUNDED) {
			pList = *(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20))
			pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, pList, 0, 0)
			v11 = pParse + 40
			v10 = *(*int32)(unsafe.Pointer(v11))
			*(*int32)(unsafe.Pointer(v11))++
			(*TWindow)(unsafe.Pointer(pWin)).FcsrApp = v10
			(*TWindow)(unsafe.Pointer(pWin)).FregApp = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			*(*int32)(unsafe.Pointer(pParse + 44)) += int32(3)
			if pKeyInfo != 0 && int32(*(*int8)(unsafe.Pointer((*TFuncDef)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpWFunc)).FzName + 1))) == int32('i') {
				*(*Tu8)(unsafe.Pointer((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags)) = uint8(KEYINFO_ORDER_DESC)
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp, int32(2))
			_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(8))
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1))
		} else {
			if (*TFuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) || (*TFuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&_first_valueName)) {
				/* Allocate two registers at pWin->regApp. These will be used to
				 ** store the start and end index of the current frame.  */
				(*TWindow)(unsafe.Pointer(pWin)).FregApp = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
				v13 = pParse + 40
				v12 = *(*int32)(unsafe.Pointer(v13))
				*(*int32)(unsafe.Pointer(v13))++
				(*TWindow)(unsafe.Pointer(pWin)).FcsrApp = v12
				*(*int32)(unsafe.Pointer(pParse + 44)) += int32(2)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp, (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr)
			} else {
				if (*TFuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&_leadName)) || (*TFuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&_lagName)) {
					v15 = pParse + 40
					v14 = *(*int32)(unsafe.Pointer(v15))
					*(*int32)(unsafe.Pointer(v15))++
					(*TWindow)(unsafe.Pointer(pWin)).FcsrApp = v14
					_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp, (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr)
				}
			}
		}
		goto _9
	_9:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
}

// C documentation
//
//	/*
//	** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
//	** value of the second argument to nth_value() (eCond==2) has just been
//	** evaluated and the result left in register reg. This function generates VM
//	** code to check that the value is a non-negative integer and throws an
//	** exception if it is not.
//	*/
func _windowCheckValue(tls *libc.TLS, pParse uintptr, reg int32, eCond int32) {
	var regString, regZero int32
	var v uintptr
	_, _, _ = regString, regZero, v
	v = _sqlite3GetVdbe(tls, pParse)
	regZero = _sqlite3GetTempReg(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regZero)
	if eCond >= int32(WINDOW_STARTING_NUM) {
		regString = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, regString, 0, __ccgo_ts+1672, -int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Ge), regString, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), reg)
		_sqlite3VdbeChangeP5(tls, v, uint16(libc.Int32FromInt32(SQLITE_AFF_NUMERIC)|libc.Int32FromInt32(SQLITE_JUMPIFNULL)))
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_MustBeInt), reg, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
	}
	_sqlite3VdbeAddOp3(tls, v, _aOp1[eCond], regZero, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), reg)
	_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_AFF_NUMERIC))
	/* NULL case captured by */
	/*   the OP_MustBeInt */
	/* NULL case caught by */
	/*   the OP_Ge */
	_sqlite3MayAbort(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Halt), int32(SQLITE_ERROR), int32(OE_Abort))
	_sqlite3VdbeAppendP4(tls, v, _azErr[eCond], -int32(1))
	_sqlite3ReleaseTempReg(tls, pParse, regZero)
}

var _azErr = [5]uintptr{
	0: __ccgo_ts + 24472,
	1: __ccgo_ts + 24525,
	2: __ccgo_ts + 24027,
	3: __ccgo_ts + 24576,
	4: __ccgo_ts + 24628,
}

var _aOp1 = [5]int32{
	0: int32(OP_Ge),
	1: int32(OP_Ge),
	2: int32(OP_Gt),
	3: int32(OP_Ge),
	4: int32(OP_Ge),
}

// C documentation
//
//	/*
//	** Return the number of arguments passed to the window-function associated
//	** with the object passed as the only argument to this function.
//	*/
func _windowArgCount(tls *libc.TLS, pWin uintptr) (r int32) {
	var pList uintptr
	var v1 int32
	_, _ = pList, v1
	pList = *(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20))
	if pList != 0 {
		v1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	} else {
		v1 = 0
	}
	return v1
}

type TWindowCodeArg = struct {
	FpParse    uintptr
	FpMWin     uintptr
	FpVdbe     uintptr
	FaddrGosub int32
	FregGosub  int32
	FregArg    int32
	FeDelete   int32
	FregRowid  int32
	Fstart     TWindowCsrAndReg
	Fcurrent   TWindowCsrAndReg
	Fend       TWindowCsrAndReg
}

type WindowCodeArg = TWindowCodeArg

type TWindowCsrAndReg = struct {
	Fcsr int32
	Freg int32
}

type WindowCsrAndReg = TWindowCsrAndReg

/*
** See comments above struct WindowCodeArg.
 */
type TWindowCsrAndReg1 = struct {
	Fcsr int32
	Freg int32
}

type WindowCsrAndReg1 = TWindowCsrAndReg1

/*
** A single instance of this structure is allocated on the stack by
** sqlite3WindowCodeStep() and a pointer to it passed to the various helper
** routines. This is to reduce the number of arguments required by each
** helper function.
**
** regArg:
**   Each window function requires an accumulator register (just as an
**   ordinary aggregate function does). This variable is set to the first
**   in an array of accumulator registers - one for each window function
**   in the WindowCodeArg.pMWin list.
**
** eDelete:
**   The window functions implementation sometimes caches the input rows
**   that it processes in a temporary table. If it is not zero, this
**   variable indicates when rows may be removed from the temp table (in
**   order to reduce memory requirements - it would always be safe just
**   to leave them there). Possible values for eDelete are:
**
**      WINDOW_RETURN_ROW:
**        An input row can be discarded after it is returned to the caller.
**
**      WINDOW_AGGINVERSE:
**        An input row can be discarded after the window functions xInverse()
**        callbacks have been invoked in it.
**
**      WINDOW_AGGSTEP:
**        An input row can be discarded after the window functions xStep()
**        callbacks have been invoked in it.
**
** start,current,end
**   Consider a window-frame similar to the following:
**
**     (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
**
**   The windows functions implementation caches the input rows in a temp
**   table, sorted by "a, b" (it actually populates the cache lazily, and
**   aggressively removes rows once they are no longer required, but that's
**   a mere detail). It keeps three cursors open on the temp table. One
**   (current) that points to the next row to return to the query engine
**   once its window function values have been calculated. Another (end)
**   points to the next row to call the xStep() method of each window function
**   on (so that it is 2 groups ahead of current). And a third (start) that
**   points to the next row to call the xInverse() method of each window
**   function on.
**
**   Each cursor (start, current and end) consists of a VDBE cursor
**   (WindowCsrAndReg.csr) and an array of registers (starting at
**   WindowCodeArg.reg) that always contains a copy of the peer values
**   read from the corresponding cursor.
**
**   Depending on the window-frame in question, all three cursors may not
**   be required. In this case both WindowCodeArg.csr and reg are set to
**   0.
 */
type TWindowCodeArg1 = struct {
	FpParse    uintptr
	FpMWin     uintptr
	FpVdbe     uintptr
	FaddrGosub int32
	FregGosub  int32
	FregArg    int32
	FeDelete   int32
	FregRowid  int32
	Fstart     TWindowCsrAndReg
	Fcurrent   TWindowCsrAndReg
	Fend       TWindowCsrAndReg
}

type WindowCodeArg1 = TWindowCodeArg1

// C documentation
//
//	/*
//	** Generate VM code to read the window frames peer values from cursor csr into
//	** an array of registers starting at reg.
//	*/
func _windowReadPeerValues(tls *libc.TLS, p uintptr, csr int32, reg int32) {
	var i, iColOff, v1 int32
	var pMWin, pOrderBy, pPart, v uintptr
	_, _, _, _, _, _, _ = i, iColOff, pMWin, pOrderBy, pPart, v, v1
	pMWin = (*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin
	pOrderBy = (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy
	if pOrderBy != 0 {
		v = _sqlite3GetVdbe(tls, (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse)
		pPart = (*TWindow)(unsafe.Pointer(pMWin)).FpPartition
		if pPart != 0 {
			v1 = (*TExprList)(unsafe.Pointer(pPart)).FnExpr
		} else {
			v1 = 0
		}
		iColOff = (*TWindow)(unsafe.Pointer(pMWin)).FnBufferCol + v1
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
				break
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csr, iColOff+i, reg+i)
			goto _2
		_2:
			;
			i++
		}
	}
}

// C documentation
//
//	/*
//	** Generate VM code to invoke either xStep() (if bInverse is 0) or
//	** xInverse (if bInverse is non-zero) for each window function in the
//	** linked list starting at pMWin. Or, for built-in window functions
//	** that do not use the standard function API, generate the required
//	** inline VM code.
//	**
//	** If argument csr is greater than or equal to 0, then argument reg is
//	** the first register in an array of registers guaranteed to be large
//	** enough to hold the array of arguments for each function. In this case
//	** the arguments are extracted from the current row of csr into the
//	** array of registers before invoking OP_AggStep or OP_AggInverse
//	**
//	** Or, if csr is less than zero, then the array of registers at reg is
//	** already populated with all columns from the current row of the sub-query.
//	**
//	** If argument regPartSize is non-zero, then it is a register containing the
//	** number of rows in the current partition.
//	*/
func _windowAggStep(tls *libc.TLS, p uintptr, pMWin uintptr, csr int32, bInverse int32, reg int32) {
	var addrIf, addrIsNull, i, iEnd, iOp, nArg, regArg, regTmp, v2, v5 int32
	var pColl, pFunc, pOp, pParse, pWin, v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrIf, addrIsNull, i, iEnd, iOp, nArg, pColl, pFunc, pOp, pParse, pWin, regArg, regTmp, v, v2, v5
	pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
	v = _sqlite3GetVdbe(tls, pParse)
	pWin = pMWin
	for {
		if !(pWin != 0) {
			break
		}
		pFunc = (*TWindow)(unsafe.Pointer(pWin)).FpWFunc
		if (*TWindow)(unsafe.Pointer(pWin)).FbExprArgs != 0 {
			v2 = 0
		} else {
			v2 = _windowArgCount(tls, pWin)
		}
		nArg = v2
		/* All OVER clauses in the same window function aggregate step must
		 ** be the same. */
		i = 0
		for {
			if !(i < nArg) {
				break
			}
			if i != int32(1) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName != uintptr(unsafe.Pointer(&_nth_valueName)) {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csr, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+i, reg+i)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+i, reg+i)
			}
			goto _3
		_3:
			;
			i++
		}
		regArg = reg
		if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid == 0 && (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(SQLITE_FUNC_MINMAX) != 0 && int32((*TWindow)(unsafe.Pointer(pWin)).FeStart) != int32(TK_UNBOUNDED) {
			addrIsNull = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), regArg)
			if bInverse == 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1), int32(1))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), regArg, (*TWindow)(unsafe.Pointer(pWin)).FregApp)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*TWindow)(unsafe.Pointer(pWin)).FregApp, int32(2), (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(2))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp, (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(2))
			} else {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_SeekGE), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp, 0, regArg, int32(1))
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp)
				_sqlite3VdbeJumpHere(tls, v, _sqlite3VdbeCurrentAddr(tls, v)-int32(2))
			}
			_sqlite3VdbeJumpHere(tls, v, addrIsNull)
		} else {
			if (*TWindow)(unsafe.Pointer(pWin)).FregApp != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1)-bInverse, int32(1))
			} else {
				if (*TFuncDef)(unsafe.Pointer(pFunc)).FxSFunc != __ccgo_fp(_noopStepFunc) {
					addrIf = 0
					if (*TWindow)(unsafe.Pointer(pWin)).FpFilter != 0 {
						regTmp = _sqlite3GetTempReg(tls, pParse)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csr, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+nArg, regTmp)
						addrIf = _sqlite3VdbeAddOp3(tls, v, int32(OP_IfNot), regTmp, 0, int32(1))
						_sqlite3ReleaseTempReg(tls, pParse, regTmp)
					}
					if (*TWindow)(unsafe.Pointer(pWin)).FbExprArgs != 0 {
						iOp = _sqlite3VdbeCurrentAddr(tls, v)
						nArg = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20)))).FnExpr
						regArg = _sqlite3GetTempRange(tls, pParse, nArg)
						_sqlite3ExprCodeExprList(tls, pParse, *(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20)), regArg, 0, uint8(0))
						iEnd = _sqlite3VdbeCurrentAddr(tls, v)
						for {
							if !(iOp < iEnd) {
								break
							}
							pOp = _sqlite3VdbeGetOp(tls, v, iOp)
							if int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 == (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr {
								(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = csr
							}
							goto _4
						_4:
							;
							iOp++
						}
					}
					if (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 {
						pColl = _sqlite3ExprNNCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20)) + 8))).FpExpr)
						_sqlite3VdbeAddOp4(tls, v, int32(OP_CollSeq), 0, 0, 0, pColl, -int32(2))
					}
					if bInverse != 0 {
						v5 = int32(OP_AggInverse)
					} else {
						v5 = int32(OP_AggStep)
					}
					_sqlite3VdbeAddOp3(tls, v, v5, bInverse, regArg, (*TWindow)(unsafe.Pointer(pWin)).FregAccum)
					_sqlite3VdbeAppendP4(tls, v, pFunc, -int32(7))
					_sqlite3VdbeChangeP5(tls, v, uint16(uint8(uint8(nArg))))
					if (*TWindow)(unsafe.Pointer(pWin)).FbExprArgs != 0 {
						_sqlite3ReleaseTempRange(tls, pParse, regArg, nArg)
					}
					if addrIf != 0 {
						_sqlite3VdbeJumpHere(tls, v, addrIf)
					}
				}
			}
		}
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
}

/*
** Values that may be passed as the second argument to windowCodeOp().
 */

// C documentation
//
//	/*
//	** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
//	** (bFin==1) for each window function in the linked list starting at
//	** pMWin. Or, for built-in window-functions that do not use the standard
//	** API, generate the equivalent VM code.
//	*/
func _windowAggFinal(tls *libc.TLS, p uintptr, bFin int32) {
	var nArg int32
	var pMWin, pParse, pWin, v uintptr
	_, _, _, _, _ = nArg, pMWin, pParse, pWin, v
	pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
	pMWin = (*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin
	v = _sqlite3GetVdbe(tls, pParse)
	pWin = pMWin
	for {
		if !(pWin != 0) {
			break
		}
		if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid == 0 && (*TFuncDef)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpWFunc)).FfuncFlags&uint32(SQLITE_FUNC_MINMAX) != 0 && int32((*TWindow)(unsafe.Pointer(pWin)).FeStart) != int32(TK_UNBOUNDED) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Last), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp, 0, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
			_sqlite3VdbeJumpHere(tls, v, _sqlite3VdbeCurrentAddr(tls, v)-int32(2))
		} else {
			if (*TWindow)(unsafe.Pointer(pWin)).FregApp != 0 {
			} else {
				nArg = _windowArgCount(tls, pWin)
				if bFin != 0 {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_AggFinal), (*TWindow)(unsafe.Pointer(pWin)).FregAccum, nArg)
					_sqlite3VdbeAppendP4(tls, v, (*TWindow)(unsafe.Pointer(pWin)).FpWFunc, -int32(7))
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), (*TWindow)(unsafe.Pointer(pWin)).FregAccum, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregAccum)
				} else {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_AggValue), (*TWindow)(unsafe.Pointer(pWin)).FregAccum, nArg, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					_sqlite3VdbeAppendP4(tls, v, (*TWindow)(unsafe.Pointer(pWin)).FpWFunc, -int32(7))
				}
			}
		}
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
}

// C documentation
//
//	/*
//	** Generate code to calculate the current values of all window functions in the
//	** p->pMWin list by doing a full scan of the current window frame. Store the
//	** results in the Window.regResult registers, ready to return the upper
//	** layer.
//	*/
func _windowFullScan(tls *libc.TLS, p uintptr) {
	var addr, addrEq, addrNext, csr, lblBrk, lblNext, nPeer, regCPeer, regCRowid, regPeer, regRowid, v1 int32
	var pKeyInfo, pMWin, pParse, pWin, v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrEq, addrNext, csr, lblBrk, lblNext, nPeer, pKeyInfo, pMWin, pParse, pWin, regCPeer, regCRowid, regPeer, regRowid, v, v1
	pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
	pMWin = (*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin
	v = (*TWindowCodeArg)(unsafe.Pointer(p)).FpVdbe
	regCRowid = 0 /* Current rowid value */
	regCPeer = 0  /* Current peer values */
	regRowid = 0  /* AggStep rowid value */
	regPeer = 0
	csr = (*TWindow)(unsafe.Pointer(pMWin)).FcsrApp
	if (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy != 0 {
		v1 = (*TExprList)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy)).FnExpr
	} else {
		v1 = 0
	}
	nPeer = v1
	lblNext = _sqlite3VdbeMakeLabel(tls, pParse)
	lblBrk = _sqlite3VdbeMakeLabel(tls, pParse)
	regCRowid = _sqlite3GetTempReg(tls, pParse)
	regRowid = _sqlite3GetTempReg(tls, pParse)
	if nPeer != 0 {
		regCPeer = _sqlite3GetTempRange(tls, pParse, nPeer)
		regPeer = _sqlite3GetTempRange(tls, pParse, nPeer)
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr, regCRowid)
	_windowReadPeerValues(tls, p, (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr, regCPeer)
	pWin = pMWin
	for {
		if !(pWin != 0) {
			break
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregAccum)
		goto _2
	_2:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekGE), csr, lblBrk, (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid)
	addrNext = _sqlite3VdbeCurrentAddr(tls, v)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), csr, regRowid)
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Gt), (*TWindow)(unsafe.Pointer(pMWin)).FregEndRowid, lblBrk, regRowid)
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeExclude) == int32(TK_CURRENT) {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regCRowid, lblNext, regRowid)
	} else {
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeExclude) != int32(TK_NO) {
			addrEq = 0
			pKeyInfo = uintptr(0)
			if (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy != 0 {
				pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy, 0, 0)
			}
			if int32((*TWindow)(unsafe.Pointer(pMWin)).FeExclude) == int32(TK_TIES) {
				addrEq = _sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regCRowid, 0, regRowid)
			}
			if pKeyInfo != 0 {
				_windowReadPeerValues(tls, p, csr, regPeer)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Compare), regPeer, regCPeer, nPeer)
				_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(8))
				addr = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addr, lblNext, addr)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, lblNext)
			}
			if addrEq != 0 {
				_sqlite3VdbeJumpHere(tls, v, addrEq)
			}
		}
	}
	_windowAggStep(tls, p, pMWin, csr, 0, (*TWindowCodeArg)(unsafe.Pointer(p)).FregArg)
	_sqlite3VdbeResolveLabel(tls, v, lblNext)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), csr, addrNext)
	_sqlite3VdbeJumpHere(tls, v, addrNext-int32(1))
	_sqlite3VdbeJumpHere(tls, v, addrNext+int32(1))
	_sqlite3ReleaseTempReg(tls, pParse, regRowid)
	_sqlite3ReleaseTempReg(tls, pParse, regCRowid)
	if nPeer != 0 {
		_sqlite3ReleaseTempRange(tls, pParse, regPeer, nPeer)
		_sqlite3ReleaseTempRange(tls, pParse, regCPeer, nPeer)
	}
	_windowAggFinal(tls, p, int32(1))
}

// C documentation
//
//	/*
//	** Invoke the sub-routine at regGosub (generated by code in select.c) to
//	** return the current row of Window.iEphCsr. If all window functions are
//	** aggregate window functions that use the standard API, a single
//	** OP_Gosub instruction is all that this routine generates. Extra VM code
//	** for per-row processing is only generated for the following built-in window
//	** functions:
//	**
//	**   nth_value()
//	**   first_value()
//	**   lag()
//	**   lead()
//	*/
func _windowReturnOneRow(tls *libc.TLS, p uintptr) {
	var csr, csr1, iEph, lbl, lbl1, nArg, op, tmpReg, tmpReg1, tmpReg2, val, v2, v3 int32
	var pFunc, pMWin, pParse, pWin, v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = csr, csr1, iEph, lbl, lbl1, nArg, op, pFunc, pMWin, pParse, pWin, tmpReg, tmpReg1, tmpReg2, v, val, v2, v3
	pMWin = (*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin
	v = (*TWindowCodeArg)(unsafe.Pointer(p)).FpVdbe
	if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
		_windowFullScan(tls, p)
	} else {
		pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
		pWin = pMWin
		for {
			if !(pWin != 0) {
				break
			}
			pFunc = (*TWindow)(unsafe.Pointer(pWin)).FpWFunc
			if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_first_valueName)) {
				csr = (*TWindow)(unsafe.Pointer(pWin)).FcsrApp
				lbl = _sqlite3VdbeMakeLabel(tls, pParse)
				tmpReg = _sqlite3GetTempReg(tls, pParse)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
				if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+int32(1), tmpReg)
					_windowCheckValue(tls, pParse, tmpReg, int32(2))
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), tmpReg)
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Add), tmpReg, (*TWindow)(unsafe.Pointer(pWin)).FregApp, tmpReg)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Gt), (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1), lbl, tmpReg)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), csr, 0, tmpReg)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csr, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
				_sqlite3VdbeResolveLabel(tls, v, lbl)
				_sqlite3ReleaseTempReg(tls, pParse, tmpReg)
			} else {
				if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_leadName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_lagName)) {
					nArg = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20)))).FnExpr
					csr1 = (*TWindow)(unsafe.Pointer(pWin)).FcsrApp
					lbl1 = _sqlite3VdbeMakeLabel(tls, pParse)
					tmpReg1 = _sqlite3GetTempReg(tls, pParse)
					iEph = (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr
					if nArg < int32(3) {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					} else {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+int32(2), (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iEph, tmpReg1)
					if nArg < int32(2) {
						if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_leadName)) {
							v2 = int32(1)
						} else {
							v2 = -int32(1)
						}
						val = v2
						_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), tmpReg1, val)
					} else {
						if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_leadName)) {
							v3 = int32(OP_Add)
						} else {
							v3 = int32(OP_Subtract)
						}
						op = v3
						tmpReg2 = _sqlite3GetTempReg(tls, pParse)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+int32(1), tmpReg2)
						_sqlite3VdbeAddOp3(tls, v, op, tmpReg2, tmpReg1, tmpReg1)
						_sqlite3ReleaseTempReg(tls, pParse, tmpReg2)
					}
					_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), csr1, lbl1, tmpReg1)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csr1, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					_sqlite3VdbeResolveLabel(tls, v, lbl1)
					_sqlite3ReleaseTempReg(tls, pParse, tmpReg1)
				}
			}
			goto _1
		_1:
			;
			pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
		}
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TWindowCodeArg)(unsafe.Pointer(p)).FregGosub, (*TWindowCodeArg)(unsafe.Pointer(p)).FaddrGosub)
}

// C documentation
//
//	/*
//	** Generate code to set the accumulator register for each window function
//	** in the linked list passed as the second argument to NULL. And perform
//	** any equivalent initialization required by any built-in window functions
//	** in the list.
//	*/
func _windowInitAccum(tls *libc.TLS, pParse uintptr, pMWin uintptr) (r int32) {
	var nArg, regArg, v2 int32
	var pFunc, pWin, v uintptr
	_, _, _, _, _, _ = nArg, pFunc, pWin, regArg, v, v2
	v = _sqlite3GetVdbe(tls, pParse)
	nArg = 0
	pWin = pMWin
	for {
		if !(pWin != 0) {
			break
		}
		pFunc = (*TWindow)(unsafe.Pointer(pWin)).FpWFunc
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregAccum)
		if nArg > _windowArgCount(tls, pWin) {
			v2 = nArg
		} else {
			v2 = _windowArgCount(tls, pWin)
		}
		nArg = v2
		if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid == 0 {
			if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_first_valueName)) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pWin)).FregApp)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1))
			}
			if (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(SQLITE_FUNC_MINMAX) != 0 && (*TWindow)(unsafe.Pointer(pWin)).FcsrApp != 0 {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_ResetSorter), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1))
			}
		}
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
	regArg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	*(*int32)(unsafe.Pointer(pParse + 44)) += nArg
	return regArg
}

// C documentation
//
//	/*
//	** Return true if the current frame should be cached in the ephemeral table,
//	** even if there are no xInverse() calls required.
//	*/
func _windowCacheFrame(tls *libc.TLS, pMWin uintptr) (r int32) {
	var pFunc, pWin uintptr
	_, _ = pFunc, pWin
	if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
		return int32(1)
	}
	pWin = pMWin
	for {
		if !(pWin != 0) {
			break
		}
		pFunc = (*TWindow)(unsafe.Pointer(pWin)).FpWFunc
		if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_first_valueName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_leadName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_lagName)) {
			return int32(1)
		}
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
	return 0
}

// C documentation
//
//	/*
//	** regOld and regNew are each the first register in an array of size
//	** pOrderBy->nExpr. This function generates code to compare the two
//	** arrays of registers using the collation sequences and other comparison
//	** parameters specified by pOrderBy.
//	**
//	** If the two arrays are not equal, the contents of regNew is copied to
//	** regOld and control falls through. Otherwise, if the contents of the arrays
//	** are equal, an OP_Goto is executed. The address of the OP_Goto is returned.
//	*/
func _windowIfNewPeer(tls *libc.TLS, pParse uintptr, pOrderBy uintptr, regNew int32, regOld int32, addr int32) {
	var nVal int32
	var pKeyInfo, v uintptr
	_, _, _ = nVal, pKeyInfo, v
	v = _sqlite3GetVdbe(tls, pParse)
	if pOrderBy != 0 {
		nVal = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
		pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, pOrderBy, 0, 0)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Compare), regOld, regNew, nVal)
		_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(8))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), _sqlite3VdbeCurrentAddr(tls, v)+int32(1), addr, _sqlite3VdbeCurrentAddr(tls, v)+int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regNew, regOld, nVal-int32(1))
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addr)
	}
}

// C documentation
//
//	/*
//	** This function is called as part of generating VM programs for RANGE
//	** offset PRECEDING/FOLLOWING frame boundaries. Assuming "ASC" order for
//	** the ORDER BY term in the window, and that argument op is OP_Ge, it generates
//	** code equivalent to:
//	**
//	**   if( csr1.peerVal + regVal >= csr2.peerVal ) goto lbl;
//	**
//	** The value of parameter op may also be OP_Gt or OP_Le. In these cases the
//	** operator in the above pseudo-code is replaced with ">" or "<=", respectively.
//	**
//	** If the sort-order for the ORDER BY term in the window is DESC, then the
//	** comparison is reversed. Instead of adding regVal to csr1.peerVal, it is
//	** subtracted. And the comparison operator is inverted to - ">=" becomes "<=",
//	** ">" becomes "<", and so on. So, with DESC sort order, if the argument op
//	** is OP_Ge, the generated code is equivalent to:
//	**
//	**   if( csr1.peerVal - regVal <= csr2.peerVal ) goto lbl;
//	**
//	** A special type of arithmetic is used such that if csr1.peerVal is not
//	** a numeric type (real or integer), then the result of the addition
//	** or subtraction is a a copy of csr1.peerVal.
//	*/
func _windowCodeRangeTest(tls *libc.TLS, p uintptr, op int32, csr1 int32, regVal int32, csr2 int32, lbl int32) {
	var addr, addrDone, addrGe, arith, reg1, reg2, regString, v1, v3 int32
	var pColl, pOrderBy, pParse, v, v2 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrDone, addrGe, arith, pColl, pOrderBy, pParse, reg1, reg2, regString, v, v1, v2, v3
	pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
	v = _sqlite3GetVdbe(tls, pParse)
	pOrderBy = (*TWindow)(unsafe.Pointer((*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin)).FpOrderBy /* ORDER BY clause for window */
	reg1 = _sqlite3GetTempReg(tls, pParse)                                                       /* Reg. for csr1.peerVal+regVal */
	reg2 = _sqlite3GetTempReg(tls, pParse)
	v2 = pParse + 44
	*(*int32)(unsafe.Pointer(v2))++
	v1 = *(*int32)(unsafe.Pointer(v2)) /* Reg. for csr2.peerVal */
	regString = v1                     /* Reg. for constant value '' */
	arith = int32(OP_Add)              /* Jump destination */
	addrDone = _sqlite3VdbeMakeLabel(tls, pParse)
	/* Read the peer-value from each cursor into a register */
	_windowReadPeerValues(tls, p, csr1, reg1)
	_windowReadPeerValues(tls, p, csr2, reg2)
	if int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_DESC) != 0 {
		switch op {
		case int32(OP_Ge):
			op = int32(OP_Le)
		case int32(OP_Gt):
			op = int32(OP_Lt)
		default:
			op = int32(OP_Ge)
			break
		}
		arith = int32(OP_Subtract)
	}
	/* If the BIGNULL flag is set for the ORDER BY, then it is required to
	 ** consider NULL values to be larger than all other values, instead of
	 ** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this
	 ** (and adding that capability causes a performance regression), so
	 ** instead if the BIGNULL flag is set then cases where either reg1 or
	 ** reg2 are NULL are handled separately in the following block. The code
	 ** generated is equivalent to:
	 **
	 **   if( reg1 IS NULL ){
	 **     if( op==OP_Ge ) goto lbl;
	 **     if( op==OP_Gt && reg2 IS NOT NULL ) goto lbl;
	 **     if( op==OP_Le && reg2 IS NULL ) goto lbl;
	 **   }else if( reg2 IS NULL ){
	 **     if( op==OP_Le ) goto lbl;
	 **   }
	 **
	 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
	 ** not taken, control jumps over the comparison operator coded below this
	 ** block.  */
	if int32((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
		/* This block runs if reg1 contains a NULL. */
		addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), reg1)
		switch op {
		case int32(OP_Ge):
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, lbl)
		case int32(OP_Gt):
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), reg2, lbl)
		case int32(OP_Le):
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), reg2, lbl)
		default: /* no-op */
			break
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrDone)
		/* This block runs if reg1 is not NULL, but reg2 is. */
		_sqlite3VdbeJumpHere(tls, v, addr)
		if op == int32(OP_Gt) || op == int32(OP_Ge) {
			v3 = addrDone
		} else {
			v3 = lbl
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), reg2, v3)
	}
	/* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
	 ** This block adds (or subtracts for DESC) the numeric value in regVal
	 ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
	 ** then leave reg1 as it is. In pseudo-code, this is implemented as:
	 **
	 **   if( reg1>='' ) goto addrGe;
	 **   reg1 = reg1 +/- regVal
	 **   addrGe:
	 **
	 ** Since all strings and blobs are greater-than-or-equal-to an empty string,
	 ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
	 ** then the arithmetic is performed, but since adding or subtracting from
	 ** NULL is always NULL anyway, this case is handled as required too.  */
	_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, regString, 0, __ccgo_ts+1672, -int32(1))
	addrGe = _sqlite3VdbeAddOp3(tls, v, int32(OP_Ge), regString, 0, reg1)
	if op == int32(OP_Ge) && arith == int32(OP_Add) || op == int32(OP_Le) && arith == int32(OP_Subtract) {
		_sqlite3VdbeAddOp3(tls, v, op, reg2, lbl, reg1)
	}
	_sqlite3VdbeAddOp3(tls, v, arith, regVal, reg1, reg1)
	_sqlite3VdbeJumpHere(tls, v, addrGe)
	/* Compare registers reg2 and reg1, taking the jump if required. Note that
	 ** control skips over this test if the BIGNULL flag is set and either
	 ** reg1 or reg2 contain a NULL value.  */
	_sqlite3VdbeAddOp3(tls, v, op, reg2, lbl, reg1)
	pColl = _sqlite3ExprNNCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).FpExpr)
	_sqlite3VdbeAppendP4(tls, v, pColl, -int32(2))
	_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
	_sqlite3VdbeResolveLabel(tls, v, addrDone)
	_sqlite3ReleaseTempReg(tls, pParse, reg1)
	_sqlite3ReleaseTempReg(tls, pParse, reg2)
}

// C documentation
//
//	/*
//	** Helper function for sqlite3WindowCodeStep(). Each call to this function
//	** generates VM code for a single RETURN_ROW, AGGSTEP or AGGINVERSE
//	** operation. Refer to the header comment for sqlite3WindowCodeStep() for
//	** details.
//	*/
func _windowCodeOp(tls *libc.TLS, p uintptr, op int32, regCountdown int32, jumpOnEof int32) (r int32) {
	var addrContinue, addrNextRange, bPeer, csr, lblDone, nReg, reg, regRowid1, regRowid2, regTmp, ret, v1, v2 int32
	var pMWin, pParse, v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrContinue, addrNextRange, bPeer, csr, lblDone, nReg, pMWin, pParse, reg, regRowid1, regRowid2, regTmp, ret, v, v1, v2
	pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
	pMWin = (*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin
	ret = 0
	v = (*TWindowCodeArg)(unsafe.Pointer(p)).FpVdbe
	addrContinue = 0
	bPeer = libc.BoolInt32(int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) != int32(TK_ROWS))
	lblDone = _sqlite3VdbeMakeLabel(tls, pParse)
	addrNextRange = 0
	/* Special case - WINDOW_AGGINVERSE is always a no-op if the frame
	 ** starts with UNBOUNDED PRECEDING. */
	if op == int32(WINDOW_AGGINVERSE) && int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_UNBOUNDED) {
		return 0
	}
	if regCountdown > 0 {
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE) {
			addrNextRange = _sqlite3VdbeCurrentAddr(tls, v)
			if op == int32(WINDOW_AGGINVERSE) {
				if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_FOLLOWING) {
					_windowCodeRangeTest(tls, p, int32(OP_Le), (*TWindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr, regCountdown, (*TWindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr, lblDone)
				} else {
					_windowCodeRangeTest(tls, p, int32(OP_Ge), (*TWindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr, regCountdown, (*TWindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr, lblDone)
				}
			} else {
				_windowCodeRangeTest(tls, p, int32(OP_Gt), (*TWindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr, regCountdown, (*TWindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr, lblDone)
			}
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_IfPos), regCountdown, lblDone, int32(1))
		}
	}
	if op == int32(WINDOW_RETURN_ROW) && (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid == 0 {
		_windowAggFinal(tls, p, 0)
	}
	addrContinue = _sqlite3VdbeCurrentAddr(tls, v)
	/* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
	 ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
	 ** start cursor does not advance past the end cursor within the
	 ** temporary table. It otherwise might, if (a>b). Also ensure that,
	 ** if the input cursor is still finding new rows, that the end
	 ** cursor does not go past it to EOF. */
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) && regCountdown != 0 && int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE) {
		regRowid1 = _sqlite3GetTempReg(tls, pParse)
		regRowid2 = _sqlite3GetTempReg(tls, pParse)
		if op == int32(WINDOW_AGGINVERSE) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), (*TWindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr, regRowid1)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), (*TWindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr, regRowid2)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Ge), regRowid2, lblDone, regRowid1)
		} else {
			if (*TWindowCodeArg)(unsafe.Pointer(p)).FregRowid != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), (*TWindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr, regRowid1)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Ge), (*TWindowCodeArg)(unsafe.Pointer(p)).FregRowid, lblDone, regRowid1)
			}
		}
		_sqlite3ReleaseTempReg(tls, pParse, regRowid1)
		_sqlite3ReleaseTempReg(tls, pParse, regRowid2)
	}
	switch op {
	case int32(WINDOW_RETURN_ROW):
		csr = (*TWindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr
		reg = (*TWindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Freg
		_windowReturnOneRow(tls, p)
	case int32(WINDOW_AGGINVERSE):
		csr = (*TWindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr
		reg = (*TWindowCodeArg)(unsafe.Pointer(p)).Fstart.Freg
		if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid, int32(1))
		} else {
			_windowAggStep(tls, p, pMWin, csr, int32(1), (*TWindowCodeArg)(unsafe.Pointer(p)).FregArg)
		}
	default:
		csr = (*TWindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr
		reg = (*TWindowCodeArg)(unsafe.Pointer(p)).Fend.Freg
		if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), (*TWindow)(unsafe.Pointer(pMWin)).FregEndRowid, int32(1))
		} else {
			_windowAggStep(tls, p, pMWin, csr, 0, (*TWindowCodeArg)(unsafe.Pointer(p)).FregArg)
		}
		break
	}
	if op == (*TWindowCodeArg)(unsafe.Pointer(p)).FeDelete {
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), csr)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))
	}
	if jumpOnEof != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), csr, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
		ret = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), csr, _sqlite3VdbeCurrentAddr(tls, v)+int32(1)+bPeer)
		if bPeer != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, lblDone)
		}
	}
	if bPeer != 0 {
		if (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy != 0 {
			v1 = (*TExprList)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy)).FnExpr
		} else {
			v1 = 0
		}
		nReg = v1
		if nReg != 0 {
			v2 = _sqlite3GetTempRange(tls, pParse, nReg)
		} else {
			v2 = 0
		}
		regTmp = v2
		_windowReadPeerValues(tls, p, csr, regTmp)
		_windowIfNewPeer(tls, pParse, (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy, regTmp, reg, addrContinue)
		_sqlite3ReleaseTempRange(tls, pParse, regTmp, nReg)
	}
	if addrNextRange != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrNextRange)
	}
	_sqlite3VdbeResolveLabel(tls, v, lblDone)
	return ret
}

// C documentation
//
//	/*
//	** Allocate and return a duplicate of the Window object indicated by the
//	** third argument. Set the Window.pOwner field of the new object to
//	** pOwner.
//	*/
func _sqlite3WindowDup(tls *libc.TLS, db uintptr, pOwner uintptr, p uintptr) (r uintptr) {
	var pNew uintptr
	_ = pNew
	pNew = uintptr(0)
	if p != 0 {
		pNew = _sqlite3DbMallocZero(tls, db, uint64(100))
		if pNew != 0 {
			(*TWindow)(unsafe.Pointer(pNew)).FzName = _sqlite3DbStrDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FzName)
			(*TWindow)(unsafe.Pointer(pNew)).FzBase = _sqlite3DbStrDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FzBase)
			(*TWindow)(unsafe.Pointer(pNew)).FpFilter = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpFilter, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpWFunc = (*TWindow)(unsafe.Pointer(p)).FpWFunc
			(*TWindow)(unsafe.Pointer(pNew)).FpPartition = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpPartition, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpOrderBy = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpOrderBy, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FeFrmType = (*TWindow)(unsafe.Pointer(p)).FeFrmType
			(*TWindow)(unsafe.Pointer(pNew)).FeEnd = (*TWindow)(unsafe.Pointer(p)).FeEnd
			(*TWindow)(unsafe.Pointer(pNew)).FeStart = (*TWindow)(unsafe.Pointer(p)).FeStart
			(*TWindow)(unsafe.Pointer(pNew)).FeExclude = (*TWindow)(unsafe.Pointer(p)).FeExclude
			(*TWindow)(unsafe.Pointer(pNew)).FregResult = (*TWindow)(unsafe.Pointer(p)).FregResult
			(*TWindow)(unsafe.Pointer(pNew)).FregAccum = (*TWindow)(unsafe.Pointer(p)).FregAccum
			(*TWindow)(unsafe.Pointer(pNew)).FiArgCol = (*TWindow)(unsafe.Pointer(p)).FiArgCol
			(*TWindow)(unsafe.Pointer(pNew)).FiEphCsr = (*TWindow)(unsafe.Pointer(p)).FiEphCsr
			(*TWindow)(unsafe.Pointer(pNew)).FbExprArgs = (*TWindow)(unsafe.Pointer(p)).FbExprArgs
			(*TWindow)(unsafe.Pointer(pNew)).FpStart = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpStart, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpEnd = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpEnd, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpOwner = pOwner
			(*TWindow)(unsafe.Pointer(pNew)).FbImplicitFrame = (*TWindow)(unsafe.Pointer(p)).FbImplicitFrame
		}
	}
	return pNew
}

// C documentation
//
//	/*
//	** Return a copy of the linked list of Window objects passed as the
//	** second argument.
//	*/
func _sqlite3WindowListDup(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pWin, pp uintptr
	var _ /* pRet at bp+0 */ uintptr
	_, _ = pWin, pp
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pp = bp
	pWin = p
	for {
		if !(pWin != 0) {
			break
		}
		*(*uintptr)(unsafe.Pointer(pp)) = _sqlite3WindowDup(tls, db, uintptr(0), pWin)
		if *(*uintptr)(unsafe.Pointer(pp)) == uintptr(0) {
			break
		}
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 36
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Return true if it can be determined at compile time that expression
//	** pExpr evaluates to a value that, when cast to an integer, is greater
//	** than zero. False otherwise.
//	**
//	** If an OOM error occurs, this function sets the Parse.db.mallocFailed
//	** flag and returns zero.
//	*/
func _windowExprGtZero(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	var ret int32
	var _ /* pVal at bp+0 */ uintptr
	_, _ = db, ret
	ret = 0
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	_sqlite3ValueFromExpr(tls, db, pExpr, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, uint8(SQLITE_AFF_NUMERIC), bp)
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 && Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(bp))) > 0 {
		ret = int32(1)
	}
	_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return ret
}

// C documentation
//
//	/*
//	** sqlite3WhereBegin() has already been called for the SELECT statement
//	** passed as the second argument when this function is invoked. It generates
//	** code to populate the Window.regResult register for each window function
//	** and invoke the sub-routine at instruction addrGosub once for each row.
//	** sqlite3WhereEnd() is always called before returning.
//	**
//	** This function handles several different types of window frames, which
//	** require slightly different processing. The following pseudo code is
//	** used to implement window frames of the form:
//	**
//	**   ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
//	**
//	** Other window frame types use variants of the following:
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**       if( new partition ){
//	**         Gosub flush
//	**       }
//	**       Insert new row into eph table.
//	**
//	**       if( first row of partition ){
//	**         // Rewind three cursors, all open on the eph table.
//	**         Rewind(csrEnd);
//	**         Rewind(csrStart);
//	**         Rewind(csrCurrent);
//	**
//	**         regEnd = <expr2>          // FOLLOWING expression
//	**         regStart = <expr1>        // PRECEDING expression
//	**       }else{
//	**         // First time this branch is taken, the eph table contains two
//	**         // rows. The first row in the partition, which all three cursors
//	**         // currently point to, and the following row.
//	**         AGGSTEP
//	**         if( (regEnd--)<=0 ){
//	**           RETURN_ROW
//	**           if( (regStart--)<=0 ){
//	**             AGGINVERSE
//	**           }
//	**         }
//	**       }
//	**     }
//	**     flush:
//	**       AGGSTEP
//	**       while( 1 ){
//	**         RETURN ROW
//	**         if( csrCurrent is EOF ) break;
//	**         if( (regStart--)<=0 ){
//	**           AggInverse(csrStart)
//	**           Next(csrStart)
//	**         }
//	**       }
//	**
//	** The pseudo-code above uses the following shorthand:
//	**
//	**   AGGSTEP:    invoke the aggregate xStep() function for each window function
//	**               with arguments read from the current row of cursor csrEnd, then
//	**               step cursor csrEnd forward one row (i.e. sqlite3BtreeNext()).
//	**
//	**   RETURN_ROW: return a row to the caller based on the contents of the
//	**               current row of csrCurrent and the current state of all
//	**               aggregates. Then step cursor csrCurrent forward one row.
//	**
//	**   AGGINVERSE: invoke the aggregate xInverse() function for each window
//	**               functions with arguments read from the current row of cursor
//	**               csrStart. Then step csrStart forward one row.
//	**
//	** There are two other ROWS window frames that are handled significantly
//	** differently from the above - "BETWEEN <expr> PRECEDING AND <expr> PRECEDING"
//	** and "BETWEEN <expr> FOLLOWING AND <expr> FOLLOWING". These are special
//	** cases because they change the order in which the three cursors (csrStart,
//	** csrCurrent and csrEnd) iterate through the ephemeral table. Cases that
//	** use UNBOUNDED or CURRENT ROW are much simpler variations on one of these
//	** three.
//	**
//	**   ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**       if( new partition ){
//	**         Gosub flush
//	**       }
//	**       Insert new row into eph table.
//	**       if( first row of partition ){
//	**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**         regEnd = <expr2>
//	**         regStart = <expr1>
//	**       }else{
//	**         if( (regEnd--)<=0 ){
//	**           AGGSTEP
//	**         }
//	**         RETURN_ROW
//	**         if( (regStart--)<=0 ){
//	**           AGGINVERSE
//	**         }
//	**       }
//	**     }
//	**     flush:
//	**       if( (regEnd--)<=0 ){
//	**         AGGSTEP
//	**       }
//	**       RETURN_ROW
//	**
//	**
//	**   ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**     if( new partition ){
//	**       Gosub flush
//	**     }
//	**     Insert new row into eph table.
//	**     if( first row of partition ){
//	**       Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**       regEnd = <expr2>
//	**       regStart = regEnd - <expr1>
//	**     }else{
//	**       AGGSTEP
//	**       if( (regEnd--)<=0 ){
//	**         RETURN_ROW
//	**       }
//	**       if( (regStart--)<=0 ){
//	**         AGGINVERSE
//	**       }
//	**     }
//	**   }
//	**   flush:
//	**     AGGSTEP
//	**     while( 1 ){
//	**       if( (regEnd--)<=0 ){
//	**         RETURN_ROW
//	**         if( eof ) break;
//	**       }
//	**       if( (regStart--)<=0 ){
//	**         AGGINVERSE
//	**         if( eof ) break
//	**       }
//	**     }
//	**     while( !eof csrCurrent ){
//	**       RETURN_ROW
//	**     }
//	**
//	** For the most part, the patterns above are adapted to support UNBOUNDED by
//	** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and
//	** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING".
//	** This is optimized of course - branches that will never be taken and
//	** conditions that are always true are omitted from the VM code. The only
//	** exceptional case is:
//	**
//	**   ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**     if( new partition ){
//	**       Gosub flush
//	**     }
//	**     Insert new row into eph table.
//	**     if( first row of partition ){
//	**       Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**       regStart = <expr1>
//	**     }else{
//	**       AGGSTEP
//	**     }
//	**   }
//	**   flush:
//	**     AGGSTEP
//	**     while( 1 ){
//	**       if( (regStart--)<=0 ){
//	**         AGGINVERSE
//	**         if( eof ) break
//	**       }
//	**       RETURN_ROW
//	**     }
//	**     while( !eof csrCurrent ){
//	**       RETURN_ROW
//	**     }
//	**
//	** Also requiring special handling are the cases:
//	**
//	**   ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
//	**   ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
//	**
//	** when (expr1 < expr2). This is detected at runtime, not by this function.
//	** To handle this case, the pseudo-code programs depicted above are modified
//	** slightly to be:
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**     if( new partition ){
//	**       Gosub flush
//	**     }
//	**     Insert new row into eph table.
//	**     if( first row of partition ){
//	**       Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**       regEnd = <expr2>
//	**       regStart = <expr1>
//	**       if( regEnd < regStart ){
//	**         RETURN_ROW
//	**         delete eph table contents
//	**         continue
//	**       }
//	**     ...
//	**
//	** The new "continue" statement in the above jumps to the next iteration
//	** of the outer loop - the one started by sqlite3WhereBegin().
//	**
//	** The various GROUPS cases are implemented using the same patterns as
//	** ROWS. The VM code is modified slightly so that:
//	**
//	**   1. The else branch in the main loop is only taken if the row just
//	**      added to the ephemeral table is the start of a new group. In
//	**      other words, it becomes:
//	**
//	**         ... loop started by sqlite3WhereBegin() ...
//	**         if( new partition ){
//	**           Gosub flush
//	**         }
//	**         Insert new row into eph table.
//	**         if( first row of partition ){
//	**           Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**           regEnd = <expr2>
//	**           regStart = <expr1>
//	**         }else if( new group ){
//	**           ...
//	**         }
//	**       }
//	**
//	**   2. Instead of processing a single row, each RETURN_ROW, AGGSTEP or
//	**      AGGINVERSE step processes the current row of the relevant cursor and
//	**      all subsequent rows belonging to the same group.
//	**
//	** RANGE window frames are a little different again. As for GROUPS, the
//	** main loop runs once per group only. And RETURN_ROW, AGGSTEP and AGGINVERSE
//	** deal in groups instead of rows. As for ROWS and GROUPS, there are three
//	** basic cases:
//	**
//	**   RANGE BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**       if( new partition ){
//	**         Gosub flush
//	**       }
//	**       Insert new row into eph table.
//	**       if( first row of partition ){
//	**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**         regEnd = <expr2>
//	**         regStart = <expr1>
//	**       }else{
//	**         AGGSTEP
//	**         while( (csrCurrent.key + regEnd) < csrEnd.key ){
//	**           RETURN_ROW
//	**           while( csrStart.key + regStart) < csrCurrent.key ){
//	**             AGGINVERSE
//	**           }
//	**         }
//	**       }
//	**     }
//	**     flush:
//	**       AGGSTEP
//	**       while( 1 ){
//	**         RETURN ROW
//	**         if( csrCurrent is EOF ) break;
//	**           while( csrStart.key + regStart) < csrCurrent.key ){
//	**             AGGINVERSE
//	**           }
//	**         }
//	**       }
//	**
//	** In the above notation, "csr.key" means the current value of the ORDER BY
//	** expression (there is only ever 1 for a RANGE that uses an <expr> FOLLOWING
//	** or <expr PRECEDING) read from cursor csr.
//	**
//	**   RANGE BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**       if( new partition ){
//	**         Gosub flush
//	**       }
//	**       Insert new row into eph table.
//	**       if( first row of partition ){
//	**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**         regEnd = <expr2>
//	**         regStart = <expr1>
//	**       }else{
//	**         while( (csrEnd.key + regEnd) <= csrCurrent.key ){
//	**           AGGSTEP
//	**         }
//	**         while( (csrStart.key + regStart) < csrCurrent.key ){
//	**           AGGINVERSE
//	**         }
//	**         RETURN_ROW
//	**       }
//	**     }
//	**     flush:
//	**       while( (csrEnd.key + regEnd) <= csrCurrent.key ){
//	**         AGGSTEP
//	**       }
//	**       while( (csrStart.key + regStart) < csrCurrent.key ){
//	**         AGGINVERSE
//	**       }
//	**       RETURN_ROW
//	**
//	**   RANGE BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
//	**
//	**     ... loop started by sqlite3WhereBegin() ...
//	**       if( new partition ){
//	**         Gosub flush
//	**       }
//	**       Insert new row into eph table.
//	**       if( first row of partition ){
//	**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
//	**         regEnd = <expr2>
//	**         regStart = <expr1>
//	**       }else{
//	**         AGGSTEP
//	**         while( (csrCurrent.key + regEnd) < csrEnd.key ){
//	**           while( (csrCurrent.key + regStart) > csrStart.key ){
//	**             AGGINVERSE
//	**           }
//	**           RETURN_ROW
//	**         }
//	**       }
//	**     }
//	**     flush:
//	**       AGGSTEP
//	**       while( 1 ){
//	**         while( (csrCurrent.key + regStart) > csrStart.key ){
//	**           AGGINVERSE
//	**           if( eof ) break "while( 1 )" loop.
//	**         }
//	**         RETURN_ROW
//	**       }
//	**       while( !eof csrCurrent ){
//	**         RETURN_ROW
//	**       }
//	**
//	** The text above leaves out many details. Refer to the code and comments
//	** below for a more complete picture.
//	*/
func _sqlite3WindowCodeStep(tls *libc.TLS, pParse uintptr, p uintptr, pWInfo uintptr, regGosub int32, addrGosub int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var addr, addr1, addrBreak, addrBreak1, addrBreak2, addrBreak3, addrEmpty, addrGe, addrGosubFlush, addrInteger, addrNe, addrNext, addrStart, addrStart1, bRPS, bRPS1, csrInput, csrWrite, iInput, lbl, lbl1, lblWhereEnd, nInput, nPart, nPeer, op, regEnd, regFlushPart, regNew, regNewPart, regNewPeer, regPeer, regRecord, regStart, v1, v11, v13, v14, v15, v3, v5, v7, v9 int32
	var pKeyInfo, pMWin, pOrderBy, pPart, v, v12, v2, v4, v6, v8 uintptr
	var _ /* s at bp+0 */ TWindowCodeArg
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addr1, addrBreak, addrBreak1, addrBreak2, addrBreak3, addrEmpty, addrGe, addrGosubFlush, addrInteger, addrNe, addrNext, addrStart, addrStart1, bRPS, bRPS1, csrInput, csrWrite, iInput, lbl, lbl1, lblWhereEnd, nInput, nPart, nPeer, op, pKeyInfo, pMWin, pOrderBy, pPart, regEnd, regFlushPart, regNew, regNewPart, regNewPeer, regPeer, regRecord, regStart, v, v1, v11, v12, v13, v14, v15, v2, v3, v4, v5, v6, v7, v8, v9
	pMWin = (*TSelect)(unsafe.Pointer(p)).FpWin
	pOrderBy = (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy
	v = _sqlite3GetVdbe(tls, pParse)                                                                                               /* Cursor used to write to eph. table */
	csrInput = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FiCursor                                    /* Cursor of sub-select */
	nInput = int32((*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpTab)).FnCol) /* Address of OP_Ne */
	addrGosubFlush = 0                                                                                                             /* Address of OP_Gosub to flush: */
	addrInteger = 0                                                                                                                /* regNew array in record form */
	regNewPeer = 0                                                                                                                 /* Peer values for new row (part of regNew) */
	regPeer = 0                                                                                                                    /* Peer values for current row */
	regFlushPart = 0                                                                                                               /* Label just before sqlite3WhereEnd() code */
	regStart = 0                                                                                                                   /* Value of <expr> PRECEDING */
	regEnd = 0                                                                                                                     /* Value of <expr> FOLLOWING */
	lblWhereEnd = _sqlite3VdbeMakeLabel(tls, pParse)
	/* Fill in the context object */
	libc.Xmemset(tls, bp, 0, uint32(56))
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FpParse = pParse
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FpMWin = pMWin
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FpVdbe = v
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FregGosub = regGosub
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FaddrGosub = addrGosub
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr = (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr
	csrWrite = (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr + int32(1)
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fstart.Fcsr = (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr + int32(2)
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fend.Fcsr = (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr + int32(3)
	/* Figure out when rows may be deleted from the ephemeral table. There
	 ** are four options - they may never be deleted (eDelete==0), they may
	 ** be deleted as soon as they are no longer part of the window frame
	 ** (eDelete==WINDOW_AGGINVERSE), they may be deleted as after the row
	 ** has been returned to the caller (WINDOW_RETURN_ROW), or they may
	 ** be deleted after they enter the frame (WINDOW_AGGSTEP). */
	switch int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) {
	case int32(TK_FOLLOWING):
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) != int32(TK_RANGE) && _windowExprGtZero(tls, pParse, (*TWindow)(unsafe.Pointer(pMWin)).FpStart) != 0 {
			(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FeDelete = int32(WINDOW_RETURN_ROW)
		}
	case int32(TK_UNBOUNDED):
		if _windowCacheFrame(tls, pMWin) == 0 {
			if int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) == int32(TK_PRECEDING) {
				if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) != int32(TK_RANGE) && _windowExprGtZero(tls, pParse, (*TWindow)(unsafe.Pointer(pMWin)).FpEnd) != 0 {
					(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FeDelete = int32(WINDOW_AGGSTEP)
				}
			} else {
				(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FeDelete = int32(WINDOW_RETURN_ROW)
			}
		}
	default:
		(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FeDelete = int32(WINDOW_AGGINVERSE)
		break
	}
	/* Allocate registers for the array of values from the sub-query, the
	 ** same values in record form, and the rowid used to insert said record
	 ** into the ephemeral table.  */
	regNew = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	*(*int32)(unsafe.Pointer(pParse + 44)) += nInput
	v2 = pParse + 44
	*(*int32)(unsafe.Pointer(v2))++
	v1 = *(*int32)(unsafe.Pointer(v2))
	regRecord = v1
	v4 = pParse + 44
	*(*int32)(unsafe.Pointer(v4))++
	v3 = *(*int32)(unsafe.Pointer(v4))
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FregRowid = v3
	/* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
	 ** clause, allocate registers to store the results of evaluating each
	 ** <expr>.  */
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_PRECEDING) || int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_FOLLOWING) {
		v6 = pParse + 44
		*(*int32)(unsafe.Pointer(v6))++
		v5 = *(*int32)(unsafe.Pointer(v6))
		regStart = v5
	}
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) == int32(TK_PRECEDING) || int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) == int32(TK_FOLLOWING) {
		v8 = pParse + 44
		*(*int32)(unsafe.Pointer(v8))++
		v7 = *(*int32)(unsafe.Pointer(v8))
		regEnd = v7
	}
	/* If this is not a "ROWS BETWEEN ..." frame, then allocate arrays of
	 ** registers to store copies of the ORDER BY expressions (peer values)
	 ** for the main loop, and for each cursor (start, current and end). */
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) != int32(TK_ROWS) {
		if pOrderBy != 0 {
			v9 = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
		} else {
			v9 = 0
		}
		nPeer = v9
		regNewPeer = regNew + (*TWindow)(unsafe.Pointer(pMWin)).FnBufferCol
		if (*TWindow)(unsafe.Pointer(pMWin)).FpPartition != 0 {
			regNewPeer += (*TExprList)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pMWin)).FpPartition)).FnExpr
		}
		regPeer = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nPeer
		(*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fstart.Freg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nPeer
		(*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Freg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nPeer
		(*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fend.Freg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		*(*int32)(unsafe.Pointer(pParse + 44)) += nPeer
	}
	/* Load the column values for the row returned by the sub-select
	 ** into an array of registers starting at regNew. Assemble them into
	 ** a record in register regRecord. */
	iInput = 0
	for {
		if !(iInput < nInput) {
			break
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csrInput, iInput, regNew+iInput)
		goto _10
	_10:
		;
		iInput++
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regNew, nInput, regRecord)
	/* An input row has just been read into an array of registers starting
	 ** at regNew. If the window has a PARTITION clause, this block generates
	 ** VM code to check if the input row is the start of a new partition.
	 ** If so, it does an OP_Gosub to an address to be filled in later. The
	 ** address of the OP_Gosub is stored in local variable addrGosubFlush. */
	if (*TWindow)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		pPart = (*TWindow)(unsafe.Pointer(pMWin)).FpPartition
		nPart = (*TExprList)(unsafe.Pointer(pPart)).FnExpr
		regNewPart = regNew + (*TWindow)(unsafe.Pointer(pMWin)).FnBufferCol
		pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, pPart, 0, 0)
		v12 = pParse + 44
		*(*int32)(unsafe.Pointer(v12))++
		v11 = *(*int32)(unsafe.Pointer(v12))
		regFlushPart = v11
		addr = _sqlite3VdbeAddOp3(tls, v, int32(OP_Compare), regNewPart, (*TWindow)(unsafe.Pointer(pMWin)).FregPart, nPart)
		_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(8))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addr+int32(2), addr+int32(4), addr+int32(2))
		addrGosubFlush = _sqlite3VdbeAddOp1(tls, v, int32(OP_Gosub), regFlushPart)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regNewPart, (*TWindow)(unsafe.Pointer(pMWin)).FregPart, nPart-int32(1))
	}
	/* Insert the new row into the ephemeral table */
	_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), csrWrite, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).FregRowid)
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), csrWrite, regRecord, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).FregRowid)
	addrNe = _sqlite3VdbeAddOp3(tls, v, int32(OP_Ne), (*TWindow)(unsafe.Pointer(pMWin)).FregOne, 0, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).FregRowid)
	/* This block is run for the first row of each partition */
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FregArg = _windowInitAccum(tls, pParse, pMWin)
	if regStart != 0 {
		_sqlite3ExprCode(tls, pParse, (*TWindow)(unsafe.Pointer(pMWin)).FpStart, regStart)
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE) {
			v13 = int32(3)
		} else {
			v13 = 0
		}
		_windowCheckValue(tls, pParse, regStart, 0+v13)
	}
	if regEnd != 0 {
		_sqlite3ExprCode(tls, pParse, (*TWindow)(unsafe.Pointer(pMWin)).FpEnd, regEnd)
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE) {
			v14 = int32(3)
		} else {
			v14 = 0
		}
		_windowCheckValue(tls, pParse, regEnd, int32(1)+v14)
	}
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) != int32(TK_RANGE) && int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) && regStart != 0 {
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_FOLLOWING) {
			v15 = int32(OP_Ge)
		} else {
			v15 = int32(OP_Le)
		}
		op = v15
		addrGe = _sqlite3VdbeAddOp3(tls, v, op, regStart, 0, regEnd)
		/* NeverNull because bound <expr> */
		/*   values previously checked */
		_windowAggFinal(tls, bp, 0)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr)
		_windowReturnOneRow(tls, bp)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_ResetSorter), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, lblWhereEnd)
		_sqlite3VdbeJumpHere(tls, v, addrGe)
	}
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_FOLLOWING) && int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) != int32(TK_RANGE) && regEnd != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Subtract), regStart, regEnd, regStart)
	}
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) != int32(TK_UNBOUNDED) {
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fstart.Fcsr)
	}
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fend.Fcsr)
	if regPeer != 0 && pOrderBy != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regNewPeer, regPeer, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr-int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regPeer, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fstart.Freg, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr-int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regPeer, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Freg, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr-int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regPeer, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fend.Freg, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr-int32(1))
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, lblWhereEnd)
	_sqlite3VdbeJumpHere(tls, v, addrNe)
	/* Beginning of the block executed for the second and subsequent rows. */
	if regPeer != 0 {
		_windowIfNewPeer(tls, pParse, pOrderBy, regNewPeer, regPeer, lblWhereEnd)
	}
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_FOLLOWING) {
		_windowCodeOp(tls, bp, int32(WINDOW_AGGSTEP), 0, 0)
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) != int32(TK_UNBOUNDED) {
			if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE) {
				lbl = _sqlite3VdbeMakeLabel(tls, pParse)
				addrNext = _sqlite3VdbeCurrentAddr(tls, v)
				_windowCodeRangeTest(tls, bp, int32(OP_Ge), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr, regEnd, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fend.Fcsr, lbl)
				_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
				_windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, 0)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrNext)
				_sqlite3VdbeResolveLabel(tls, v, lbl)
			} else {
				_windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), regEnd, 0)
				_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
			}
		}
	} else {
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) == int32(TK_PRECEDING) {
			bRPS = libc.BoolInt32(int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_PRECEDING) && int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE))
			_windowCodeOp(tls, bp, int32(WINDOW_AGGSTEP), regEnd, 0)
			if bRPS != 0 {
				_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
			}
			_windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, 0)
			if !(bRPS != 0) {
				_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
			}
		} else {
			addr1 = 0
			_windowCodeOp(tls, bp, int32(WINDOW_AGGSTEP), 0, 0)
			if int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) != int32(TK_UNBOUNDED) {
				if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE) {
					lbl1 = 0
					addr1 = _sqlite3VdbeCurrentAddr(tls, v)
					if regEnd != 0 {
						lbl1 = _sqlite3VdbeMakeLabel(tls, pParse)
						_windowCodeRangeTest(tls, bp, int32(OP_Ge), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr, regEnd, (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fend.Fcsr, lbl1)
					}
					_windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, 0)
					_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
					if regEnd != 0 {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addr1)
						_sqlite3VdbeResolveLabel(tls, v, lbl1)
					}
				} else {
					if regEnd != 0 {
						addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_IfPos), regEnd, 0, int32(1))
					}
					_windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, 0)
					_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
					if regEnd != 0 {
						_sqlite3VdbeJumpHere(tls, v, addr1)
					}
				}
			}
		}
	}
	/* End of the main input loop */
	_sqlite3VdbeResolveLabel(tls, v, lblWhereEnd)
	_sqlite3WhereEnd(tls, pWInfo)
	/* Fall through */
	if (*TWindow)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		addrInteger = _sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regFlushPart)
		_sqlite3VdbeJumpHere(tls, v, addrGosubFlush)
	}
	(*(*TWindowCodeArg)(unsafe.Pointer(bp))).FregRowid = 0
	addrEmpty = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), csrWrite)
	if int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) == int32(TK_PRECEDING) {
		bRPS1 = libc.BoolInt32(int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_PRECEDING) && int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE))
		_windowCodeOp(tls, bp, int32(WINDOW_AGGSTEP), regEnd, 0)
		if bRPS1 != 0 {
			_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
		}
		_windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, 0)
	} else {
		if int32((*TWindow)(unsafe.Pointer(pMWin)).FeStart) == int32(TK_FOLLOWING) {
			_windowCodeOp(tls, bp, int32(WINDOW_AGGSTEP), 0, 0)
			if int32((*TWindow)(unsafe.Pointer(pMWin)).FeFrmType) == int32(TK_RANGE) {
				addrStart = _sqlite3VdbeCurrentAddr(tls, v)
				addrBreak2 = _windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, int32(1))
				addrBreak1 = _windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, int32(1))
			} else {
				if int32((*TWindow)(unsafe.Pointer(pMWin)).FeEnd) == int32(TK_UNBOUNDED) {
					addrStart = _sqlite3VdbeCurrentAddr(tls, v)
					addrBreak1 = _windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), regStart, int32(1))
					addrBreak2 = _windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), 0, int32(1))
				} else {
					addrStart = _sqlite3VdbeCurrentAddr(tls, v)
					addrBreak1 = _windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), regEnd, int32(1))
					addrBreak2 = _windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, int32(1))
				}
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrStart)
			_sqlite3VdbeJumpHere(tls, v, addrBreak2)
			addrStart = _sqlite3VdbeCurrentAddr(tls, v)
			addrBreak3 = _windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, int32(1))
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrStart)
			_sqlite3VdbeJumpHere(tls, v, addrBreak1)
			_sqlite3VdbeJumpHere(tls, v, addrBreak3)
		} else {
			_windowCodeOp(tls, bp, int32(WINDOW_AGGSTEP), 0, 0)
			addrStart1 = _sqlite3VdbeCurrentAddr(tls, v)
			addrBreak = _windowCodeOp(tls, bp, int32(WINDOW_RETURN_ROW), 0, int32(1))
			_windowCodeOp(tls, bp, int32(WINDOW_AGGINVERSE), regStart, 0)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrStart1)
			_sqlite3VdbeJumpHere(tls, v, addrBreak)
		}
	}
	_sqlite3VdbeJumpHere(tls, v, addrEmpty)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_ResetSorter), (*(*TWindowCodeArg)(unsafe.Pointer(bp))).Fcurrent.Fcsr)
	if (*TWindow)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pMWin)).FregEndRowid)
		}
		_sqlite3VdbeChangeP1(tls, v, addrInteger, _sqlite3VdbeCurrentAddr(tls, v))
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regFlushPart)
	}
}

/************** End of window.c **********************************************/
/************** Begin file parse.c *******************************************/
/* This file is automatically generated by Lemon from input grammar
** source file "parse.y".
 */
/*
** 2001-09-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 SQLite's SQL parser.
**
** The canonical source code to this file ("parse.y") is a Lemon grammar
** file that specifies the input grammar and actions to take while parsing.
** That input file is processed by Lemon to generate a C-language
** implementation of a parser for the given grammar.  You might be reading
** this comment as part of the translated C-code.  Edits should be made
** to the original parse.y sources.
 */

/* #include "sqliteInt.h" */

/*
** Disable all error recovery processing in the parser push-down
** automaton.
 */

/*
** Make yytestcase() the same as testcase()
 */

/*
** Indicate that sqlite3ParserFree() will never be called with a null
** pointer.
 */

/*
** In the amalgamation, the parse.c file generated by lemon and the
** tokenize.c file are concatenated.  In that case, sqlite3RunParser()
** has access to the the size of the yyParser object and so the parser
** engine can be allocated from stack.  In that case, only the
** sqlite3ParserInit() and sqlite3ParserFinalize() routines are invoked
** and the sqlite3ParserAlloc() and sqlite3ParserFree() routines can be
** omitted.
 */

/*
** Alternative datatype for the argument to the malloc() routine passed
** into sqlite3ParserAlloc().  The default is size_t.
 */

/*
** An instance of the following structure describes the event of a
** TRIGGER.  "a" is the event type, one of TK_UPDATE, TK_INSERT,
** TK_DELETE, or TK_INSTEAD.  If the event is of the form
**
**      UPDATE ON (a,b,c)
**
** Then the "b" IdList records the list "a,b,c".
 */
type TTrigEvent = struct {
	Fa int32
	Fb uintptr
}

type TrigEvent = TTrigEvent

type TFrameBound = struct {
	FeType int32
	FpExpr uintptr
}

type FrameBound = TFrameBound

// C documentation
//
//	/*
//	** Disable lookaside memory allocation for objects that might be
//	** shared across database connections.
//	*/
func _disableLookaside(tls *libc.TLS, pParse uintptr) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	(*TParse)(unsafe.Pointer(pParse)).FdisableLookaside++
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
}

// C documentation
//
//	/*
//	  ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
//	  ** all elements in the list.  And make sure list length does not exceed
//	  ** SQLITE_LIMIT_COMPOUND_SELECT.
//	  */
func _parserDoubleLinkSelect(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var cnt, mxSelect, v2 int32
	var pLoop, pNext, v1 uintptr
	var v3 bool
	_, _, _, _, _, _, _ = cnt, mxSelect, pLoop, pNext, v1, v2, v3
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		pNext = uintptr(0)
		pLoop = p
		cnt = int32(1)
		for int32(1) != 0 {
			(*TSelect)(unsafe.Pointer(pLoop)).FpNext = pNext
			*(*Tu32)(unsafe.Pointer(pLoop + 4)) |= uint32(SF_Compound)
			pNext = pLoop
			pLoop = (*TSelect)(unsafe.Pointer(pLoop)).FpPrior
			if pLoop == uintptr(0) {
				break
			}
			cnt++
			if (*TSelect)(unsafe.Pointer(pLoop)).FpOrderBy != 0 || (*TSelect)(unsafe.Pointer(pLoop)).FpLimit != 0 {
				if (*TSelect)(unsafe.Pointer(pLoop)).FpOrderBy != uintptr(0) {
					v1 = __ccgo_ts + 24678
				} else {
					v1 = __ccgo_ts + 24687
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24693, libc.VaList(bp+8, v1, _sqlite3SelectOpName(tls, int32((*TSelect)(unsafe.Pointer(pNext)).Fop))))
				break
			}
		}
		if v3 = (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_MultiValue) == uint32(0); v3 {
			v2 = *(*int32)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb + 120 + 4*4))
			mxSelect = v2
		}
		if v3 && v2 > 0 && cnt > mxSelect {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24735, 0)
		}
	}
}

// C documentation
//
//	/* Attach a With object describing the WITH clause to a Select
//	  ** object describing the query for which the WITH clause is a prefix.
//	  */
func _attachWithToSelect(tls *libc.TLS, pParse uintptr, pSelect uintptr, pWith uintptr) (r uintptr) {
	if pSelect != 0 {
		(*TSelect)(unsafe.Pointer(pSelect)).FpWith = pWith
		_parserDoubleLinkSelect(tls, pParse, pSelect)
	} else {
		_sqlite3WithDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pWith)
	}
	return pSelect
}

// C documentation
//
//	/* Memory allocator for parser stack resizing.  This is a thin wrapper around
//	  ** sqlite3_realloc() that includes a call to sqlite3FaultSim() to facilitate
//	  ** testing.
//	  */
func _parserStackRealloc(tls *libc.TLS, pOld uintptr, newSize Tsqlite3_uint64) (r uintptr) {
	var v1 uintptr
	_ = v1
	if _sqlite3FaultSim(tls, int32(700)) != 0 {
		v1 = uintptr(0)
	} else {
		v1 = Xsqlite3_realloc(tls, pOld, int32(int32(newSize)))
	}
	return v1
}

// C documentation
//
//	/* Construct a new Expr object from a single token */
func _tokenExpr(tls *libc.TLS, pParse uintptr, op int32, _t TToken) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*TToken)(unsafe.Pointer(bp)) = _t
	var p, v1 uintptr
	_, _ = p, v1
	p = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint32(52)+(*(*TToken)(unsafe.Pointer(bp))).Fn+uint32(1)))
	if p != 0 {
		/* memset(p, 0, sizeof(Expr)); */
		(*TExpr)(unsafe.Pointer(p)).Fop = uint8(uint8(op))
		(*TExpr)(unsafe.Pointer(p)).FaffExpr = 0
		(*TExpr)(unsafe.Pointer(p)).Fflags = uint32(EP_Leaf)
		/* p->iAgg = -1; // Not required */
		v1 = libc.UintptrFromInt32(0)
		(*TExpr)(unsafe.Pointer(p)).FpRight = v1
		(*TExpr)(unsafe.Pointer(p)).FpLeft = v1
		(*TExpr)(unsafe.Pointer(p)).FpAggInfo = uintptr(0)
		libc.Xmemset(tls, p+20, 0, uint32(4))
		libc.Xmemset(tls, p+44, 0, uint32(8))
		(*TExpr)(unsafe.Pointer(p)).Fop2 = uint8(0)
		(*TExpr)(unsafe.Pointer(p)).FiTable = 0
		(*TExpr)(unsafe.Pointer(p)).FiColumn = 0
		*(*uintptr)(unsafe.Pointer(p + 8)) = p + 1*52
		libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(p + 8)), (*(*TToken)(unsafe.Pointer(bp))).Fz, (*(*TToken)(unsafe.Pointer(bp))).Fn)
		*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8)) + uintptr((*(*TToken)(unsafe.Pointer(bp))).Fn))) = 0
		*(*int32)(unsafe.Pointer(p + 36)) = int32((*(*TToken)(unsafe.Pointer(bp))).Fz) - int32((*TParse)(unsafe.Pointer(pParse)).FzTail)
		if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8)))))])&int32(0x80) != 0 {
			_sqlite3DequoteExpr(tls, p)
		}
		(*TExpr)(unsafe.Pointer(p)).FnHeight = int32(1)
		if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			return _sqlite3RenameTokenMap(tls, pParse, p, bp)
		}
	}
	return p
}

// C documentation
//
//	/* A routine to convert a binary TK_IS or TK_ISNOT expression into a
//	  ** unary TK_ISNULL or TK_NOTNULL expression. */
func _binaryToUnaryIfNull(tls *libc.TLS, pParse uintptr, pY uintptr, pA uintptr, op int32) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pA != 0 && pY != 0 && int32((*TExpr)(unsafe.Pointer(pY)).Fop) == int32(TK_NULL) && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		(*TExpr)(unsafe.Pointer(pA)).Fop = uint8(uint8(op))
		_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pA)).FpRight)
		(*TExpr)(unsafe.Pointer(pA)).FpRight = uintptr(0)
	}
}

// C documentation
//
//	/* Add a single new term to an ExprList that is used to store a
//	  ** list of identifiers.  Report an error if the ID list contains
//	  ** a COLLATE clause or an ASC or DESC keyword, except ignore the
//	  ** error while parsing a legacy schema.
//	  */
func _parserAddExprIdListTerm(tls *libc.TLS, pParse uintptr, pPrior uintptr, pIdToken uintptr, hasCollate int32, sortOrder int32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p uintptr
	_ = p
	p = _sqlite3ExprListAppend(tls, pParse, pPrior, uintptr(0))
	if (hasCollate != 0 || sortOrder != -int32(1)) && int32((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24769, libc.VaList(bp+8, (*TToken)(unsafe.Pointer(pIdToken)).Fn, (*TToken)(unsafe.Pointer(pIdToken)).Fz))
	}
	_sqlite3ExprListSetName(tls, pParse, p, pIdToken, int32(1))
	return p
}

/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols.
***************** Begin token definitions *************************************/
/**************** End token definitions ***************************************/

// C documentation
//
//	/* The next sections is a series of control #defines.
//	** various aspects of the generated parser.
//	**    YYCODETYPE         is the data type used to store the integer codes
//	**                       that represent terminal and non-terminal symbols.
//	**                       "unsigned char" is used if there are fewer than
//	**                       256 symbols.  Larger types otherwise.
//	**    YYNOCODE           is a number of type YYCODETYPE that is not used for
//	**                       any terminal or nonterminal symbol.
//	**    YYFALLBACK         If defined, this indicates that one or more tokens
//	**                       (also known as: "terminal symbols") have fall-back
//	**                       values which should be used if the original symbol
//	**                       would not parse.  This permits keywords to sometimes
//	**                       be used as identifiers, for example.
//	**    YYACTIONTYPE       is the data type used for "action codes" - numbers
//	**                       that indicate what to do in response to the next
//	**                       token.
//	**    sqlite3ParserTOKENTYPE     is the data type used for minor type for terminal
//	**                       symbols.  Background: A "minor type" is a semantic
//	**                       value associated with a terminal or non-terminal
//	**                       symbols.  For example, for an "ID" terminal symbol,
//	**                       the minor type might be the name of the identifier.
//	**                       Each non-terminal can have a different minor type.
//	**                       Terminal symbols all have the same minor type, though.
//	**                       This macros defines the minor type for terminal
//	**                       symbols.
//	**    YYMINORTYPE        is the data type used for all minor types.
//	**                       This is typically a union of many types, one of
//	**                       which is sqlite3ParserTOKENTYPE.  The entry in the union
//	**                       for terminal symbols is called "yy0".
//	**    YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
//	**                       zero the stack is dynamically sized using realloc()
//	**    sqlite3ParserARG_SDECL     A static variable declaration for the %extra_argument
//	**    sqlite3ParserARG_PDECL     A parameter declaration for the %extra_argument
//	**    sqlite3ParserARG_PARAM     Code to pass %extra_argument as a subroutine parameter
//	**    sqlite3ParserARG_STORE     Code to store %extra_argument into yypParser
//	**    sqlite3ParserARG_FETCH     Code to extract %extra_argument from yypParser
//	**    sqlite3ParserCTX_*         As sqlite3ParserARG_ except for %extra_context
//	**    YYREALLOC          Name of the realloc() function to use
//	**    YYFREE             Name of the free() function to use
//	**    YYDYNSTACK         True if stack space should be extended on heap
//	**    YYERRORSYMBOL      is the code number of the error symbol.  If not
//	**                       defined, then do no error processing.
//	**    YYNSTATE           the combined number of states.
//	**    YYNRULE            the number of rules in the grammar
//	**    YYNTOKEN           Number of terminal symbols
//	**    YY_MAX_SHIFT       Maximum value for shift actions
//	**    YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
//	**    YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
//	**    YY_ERROR_ACTION    The yy_action[] code for syntax error
//	**    YY_ACCEPT_ACTION   The yy_action[] code for accept
//	**    YY_NO_ACTION       The yy_action[] code for no-op
//	**    YY_MIN_REDUCE      Minimum value for reduce actions
//	**    YY_MAX_REDUCE      Maximum value for reduce actions
//	**    YY_MIN_DSTRCTR     Minimum symbol value that has a destructor
//	**    YY_MAX_DSTRCTR     Maximum symbol value that has a destructor
//	*/
//	/************* Begin control #defines *****************************************/
type TYYMINORTYPE = struct {
	Fyy0   [0]TToken
	Fyy14  [0]uintptr
	Fyy59  [0]uintptr
	Fyy67  [0]uintptr
	Fyy122 [0]uintptr
	Fyy132 [0]uintptr
	Fyy144 [0]int32
	Fyy168 [0]uintptr
	Fyy203 [0]uintptr
	Fyy211 [0]uintptr
	Fyy269 [0]TOnOrUsing
	Fyy286 [0]TTrigEvent
	Fyy383 [0]struct {
		Fvalue int32
		Fmask  int32
	}
	Fyy391        [0]Tu32
	Fyy427        [0]uintptr
	Fyy454        [0]uintptr
	Fyy462        [0]Tu8
	Fyy509        [0]TFrameBound
	Fyy555        [0]uintptr
	Fyyinit       int32
	F__ccgo_pad20 [4]byte
}

type YYMINORTYPE = TYYMINORTYPE

/************* End control #defines *******************************************/

/* Define the yytestcase() macro to be a no-op if is not already defined
** otherwise.
**
** Applications can choose to define yytestcase() in the %include section
** to a macro that can assist in verifying code coverage.  For production
** code the yytestcase() macro should be turned off.  But it is useful
** for testing.
 */

/* Macro to determine if stack space has the ability to grow using
** heap memory.
 */

/* Guarantee a minimum number of initial stack slots.
 */

// C documentation
//
//	/* Next are the tables used to determine what action to take based on the
//	** current state and lookahead token.  These tables are used to implement
//	** functions that take a state number and lookahead value and return an
//	** action integer.
//	**
//	** Suppose the action integer is N.  Then the action is determined as
//	** follows
//	**
//	**   0 <= N <= YY_MAX_SHIFT             Shift N.  That is, push the lookahead
//	**                                      token onto the stack and goto state N.
//	**
//	**   N between YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
//	**     and YY_MAX_SHIFTREDUCE           reduce by rule N-YY_MIN_SHIFTREDUCE.
//	**
//	**   N == YY_ERROR_ACTION               A syntax error has occurred.
//	**
//	**   N == YY_ACCEPT_ACTION              The parser accepts its input.
//	**
//	**   N == YY_NO_ACTION                  No such action.  Denotes unused
//	**                                      slots in the yy_action[] table.
//	**
//	**   N between YY_MIN_REDUCE            Reduce by rule N-YY_MIN_REDUCE
//	**     and YY_MAX_REDUCE
//	**
//	** The action table is constructed as a single large table named yy_action[].
//	** Given state S and lookahead X, the action is computed as either:
//	**
//	**    (A)   N = yy_action[ yy_shift_ofst[S] + X ]
//	**    (B)   N = yy_default[S]
//	**
//	** The (A) formula is preferred.  The B formula is used instead if
//	** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
//	**
//	** The formulas above are for computing the action when the lookahead is
//	** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
//	** a reduce action) then the yy_reduce_ofst[] array is used in place of
//	** the yy_shift_ofst[] array.
//	**
//	** The following are the tables generated in this section:
//	**
//	**  yy_action[]        A single table containing all actions.
//	**  yy_lookahead[]     A table containing the lookahead for each entry in
//	**                     yy_action.  Used to detect hash collisions.
//	**  yy_shift_ofst[]    For each state, the offset into yy_action for
//	**                     shifting terminals.
//	**  yy_reduce_ofst[]   For each state, the offset into yy_action for
//	**                     shifting non-terminals after a reduce.
//	**  yy_default[]       Default action for each state.
//	**
//	*********** Begin parsing tables **********************************************/
var _yy_action = [2142]uint16{
	0:    uint16(576),
	1:    uint16(128),
	2:    uint16(125),
	3:    uint16(232),
	4:    uint16(1622),
	5:    uint16(549),
	6:    uint16(576),
	7:    uint16(1290),
	8:    uint16(1281),
	9:    uint16(576),
	10:   uint16(328),
	11:   uint16(576),
	12:   uint16(1300),
	13:   uint16(212),
	14:   uint16(576),
	15:   uint16(128),
	16:   uint16(125),
	17:   uint16(232),
	18:   uint16(578),
	19:   uint16(412),
	20:   uint16(578),
	21:   uint16(391),
	22:   uint16(1542),
	23:   uint16(51),
	24:   uint16(51),
	25:   uint16(523),
	26:   uint16(405),
	27:   uint16(1293),
	28:   uint16(529),
	29:   uint16(51),
	30:   uint16(51),
	31:   uint16(983),
	32:   uint16(51),
	33:   uint16(51),
	34:   uint16(81),
	35:   uint16(81),
	36:   uint16(1107),
	37:   uint16(61),
	38:   uint16(61),
	39:   uint16(984),
	40:   uint16(1107),
	41:   uint16(1292),
	42:   uint16(380),
	43:   uint16(135),
	44:   uint16(136),
	45:   uint16(90),
	46:   uint16(1228),
	47:   uint16(1228),
	48:   uint16(1063),
	49:   uint16(1066),
	50:   uint16(1053),
	51:   uint16(1053),
	52:   uint16(133),
	53:   uint16(133),
	54:   uint16(134),
	55:   uint16(134),
	56:   uint16(134),
	57:   uint16(134),
	58:   uint16(1577),
	59:   uint16(412),
	60:   uint16(287),
	61:   uint16(287),
	62:   uint16(7),
	63:   uint16(287),
	64:   uint16(287),
	65:   uint16(422),
	66:   uint16(1050),
	67:   uint16(1050),
	68:   uint16(1064),
	69:   uint16(1067),
	70:   uint16(289),
	71:   uint16(556),
	72:   uint16(492),
	73:   uint16(573),
	74:   uint16(524),
	75:   uint16(561),
	76:   uint16(573),
	77:   uint16(497),
	78:   uint16(561),
	79:   uint16(482),
	80:   uint16(530),
	81:   uint16(262),
	82:   uint16(229),
	83:   uint16(135),
	84:   uint16(136),
	85:   uint16(90),
	86:   uint16(1228),
	87:   uint16(1228),
	88:   uint16(1063),
	89:   uint16(1066),
	90:   uint16(1053),
	91:   uint16(1053),
	92:   uint16(133),
	93:   uint16(133),
	94:   uint16(134),
	95:   uint16(134),
	96:   uint16(134),
	97:   uint16(134),
	98:   uint16(128),
	99:   uint16(125),
	100:  uint16(232),
	101:  uint16(1506),
	102:  uint16(132),
	103:  uint16(132),
	104:  uint16(132),
	105:  uint16(132),
	106:  uint16(131),
	107:  uint16(131),
	108:  uint16(130),
	109:  uint16(130),
	110:  uint16(130),
	111:  uint16(129),
	112:  uint16(126),
	113:  uint16(450),
	114:  uint16(1204),
	115:  uint16(1255),
	116:  uint16(1),
	117:  uint16(1),
	118:  uint16(582),
	119:  uint16(2),
	120:  uint16(1259),
	121:  uint16(1571),
	122:  uint16(420),
	123:  uint16(1582),
	124:  uint16(379),
	125:  uint16(320),
	126:  uint16(1174),
	127:  uint16(153),
	128:  uint16(1174),
	129:  uint16(1584),
	130:  uint16(412),
	131:  uint16(378),
	132:  uint16(1582),
	133:  uint16(543),
	134:  uint16(1341),
	135:  uint16(330),
	136:  uint16(111),
	137:  uint16(570),
	138:  uint16(570),
	139:  uint16(570),
	140:  uint16(293),
	141:  uint16(1054),
	142:  uint16(132),
	143:  uint16(132),
	144:  uint16(132),
	145:  uint16(132),
	146:  uint16(131),
	147:  uint16(131),
	148:  uint16(130),
	149:  uint16(130),
	150:  uint16(130),
	151:  uint16(129),
	152:  uint16(126),
	153:  uint16(450),
	154:  uint16(135),
	155:  uint16(136),
	156:  uint16(90),
	157:  uint16(1228),
	158:  uint16(1228),
	159:  uint16(1063),
	160:  uint16(1066),
	161:  uint16(1053),
	162:  uint16(1053),
	163:  uint16(133),
	164:  uint16(133),
	165:  uint16(134),
	166:  uint16(134),
	167:  uint16(134),
	168:  uint16(134),
	169:  uint16(287),
	170:  uint16(287),
	171:  uint16(1204),
	172:  uint16(1205),
	173:  uint16(1204),
	174:  uint16(255),
	175:  uint16(287),
	176:  uint16(287),
	177:  uint16(510),
	178:  uint16(507),
	179:  uint16(506),
	180:  uint16(137),
	181:  uint16(455),
	182:  uint16(573),
	183:  uint16(212),
	184:  uint16(561),
	185:  uint16(447),
	186:  uint16(446),
	187:  uint16(505),
	188:  uint16(573),
	189:  uint16(1616),
	190:  uint16(561),
	191:  uint16(134),
	192:  uint16(134),
	193:  uint16(134),
	194:  uint16(134),
	195:  uint16(127),
	196:  uint16(400),
	197:  uint16(243),
	198:  uint16(132),
	199:  uint16(132),
	200:  uint16(132),
	201:  uint16(132),
	202:  uint16(131),
	203:  uint16(131),
	204:  uint16(130),
	205:  uint16(130),
	206:  uint16(130),
	207:  uint16(129),
	208:  uint16(126),
	209:  uint16(450),
	210:  uint16(282),
	211:  uint16(471),
	212:  uint16(345),
	213:  uint16(132),
	214:  uint16(132),
	215:  uint16(132),
	216:  uint16(132),
	217:  uint16(131),
	218:  uint16(131),
	219:  uint16(130),
	220:  uint16(130),
	221:  uint16(130),
	222:  uint16(129),
	223:  uint16(126),
	224:  uint16(450),
	225:  uint16(574),
	226:  uint16(155),
	227:  uint16(936),
	228:  uint16(936),
	229:  uint16(454),
	230:  uint16(227),
	231:  uint16(521),
	232:  uint16(1236),
	233:  uint16(412),
	234:  uint16(1236),
	235:  uint16(134),
	236:  uint16(134),
	237:  uint16(134),
	238:  uint16(134),
	239:  uint16(132),
	240:  uint16(132),
	241:  uint16(132),
	242:  uint16(132),
	243:  uint16(131),
	244:  uint16(131),
	245:  uint16(130),
	246:  uint16(130),
	247:  uint16(130),
	248:  uint16(129),
	249:  uint16(126),
	250:  uint16(450),
	251:  uint16(130),
	252:  uint16(130),
	253:  uint16(130),
	254:  uint16(129),
	255:  uint16(126),
	256:  uint16(450),
	257:  uint16(135),
	258:  uint16(136),
	259:  uint16(90),
	260:  uint16(1228),
	261:  uint16(1228),
	262:  uint16(1063),
	263:  uint16(1066),
	264:  uint16(1053),
	265:  uint16(1053),
	266:  uint16(133),
	267:  uint16(133),
	268:  uint16(134),
	269:  uint16(134),
	270:  uint16(134),
	271:  uint16(134),
	272:  uint16(128),
	273:  uint16(125),
	274:  uint16(232),
	275:  uint16(450),
	276:  uint16(576),
	277:  uint16(412),
	278:  uint16(397),
	279:  uint16(1249),
	280:  uint16(180),
	281:  uint16(92),
	282:  uint16(93),
	283:  uint16(132),
	284:  uint16(132),
	285:  uint16(132),
	286:  uint16(132),
	287:  uint16(131),
	288:  uint16(131),
	289:  uint16(130),
	290:  uint16(130),
	291:  uint16(130),
	292:  uint16(129),
	293:  uint16(126),
	294:  uint16(450),
	295:  uint16(381),
	296:  uint16(387),
	297:  uint16(1204),
	298:  uint16(383),
	299:  uint16(81),
	300:  uint16(81),
	301:  uint16(135),
	302:  uint16(136),
	303:  uint16(90),
	304:  uint16(1228),
	305:  uint16(1228),
	306:  uint16(1063),
	307:  uint16(1066),
	308:  uint16(1053),
	309:  uint16(1053),
	310:  uint16(133),
	311:  uint16(133),
	312:  uint16(134),
	313:  uint16(134),
	314:  uint16(134),
	315:  uint16(134),
	316:  uint16(132),
	317:  uint16(132),
	318:  uint16(132),
	319:  uint16(132),
	320:  uint16(131),
	321:  uint16(131),
	322:  uint16(130),
	323:  uint16(130),
	324:  uint16(130),
	325:  uint16(129),
	326:  uint16(126),
	327:  uint16(450),
	328:  uint16(131),
	329:  uint16(131),
	330:  uint16(130),
	331:  uint16(130),
	332:  uint16(130),
	333:  uint16(129),
	334:  uint16(126),
	335:  uint16(450),
	336:  uint16(556),
	337:  uint16(1204),
	338:  uint16(302),
	339:  uint16(319),
	340:  uint16(567),
	341:  uint16(121),
	342:  uint16(568),
	343:  uint16(480),
	344:  uint16(4),
	345:  uint16(555),
	346:  uint16(1149),
	347:  uint16(1657),
	348:  uint16(1628),
	349:  uint16(1657),
	350:  uint16(45),
	351:  uint16(128),
	352:  uint16(125),
	353:  uint16(232),
	354:  uint16(1204),
	355:  uint16(1205),
	356:  uint16(1204),
	357:  uint16(1250),
	358:  uint16(571),
	359:  uint16(1169),
	360:  uint16(132),
	361:  uint16(132),
	362:  uint16(132),
	363:  uint16(132),
	364:  uint16(131),
	365:  uint16(131),
	366:  uint16(130),
	367:  uint16(130),
	368:  uint16(130),
	369:  uint16(129),
	370:  uint16(126),
	371:  uint16(450),
	372:  uint16(1169),
	373:  uint16(287),
	374:  uint16(287),
	375:  uint16(1169),
	376:  uint16(1019),
	377:  uint16(576),
	378:  uint16(422),
	379:  uint16(1019),
	380:  uint16(412),
	381:  uint16(451),
	382:  uint16(1602),
	383:  uint16(582),
	384:  uint16(2),
	385:  uint16(1259),
	386:  uint16(573),
	387:  uint16(44),
	388:  uint16(561),
	389:  uint16(95),
	390:  uint16(320),
	391:  uint16(110),
	392:  uint16(153),
	393:  uint16(565),
	394:  uint16(1204),
	395:  uint16(1205),
	396:  uint16(1204),
	397:  uint16(522),
	398:  uint16(522),
	399:  uint16(1341),
	400:  uint16(81),
	401:  uint16(81),
	402:  uint16(7),
	403:  uint16(44),
	404:  uint16(135),
	405:  uint16(136),
	406:  uint16(90),
	407:  uint16(1228),
	408:  uint16(1228),
	409:  uint16(1063),
	410:  uint16(1066),
	411:  uint16(1053),
	412:  uint16(1053),
	413:  uint16(133),
	414:  uint16(133),
	415:  uint16(134),
	416:  uint16(134),
	417:  uint16(134),
	418:  uint16(134),
	419:  uint16(295),
	420:  uint16(1149),
	421:  uint16(1658),
	422:  uint16(1040),
	423:  uint16(1658),
	424:  uint16(1204),
	425:  uint16(1147),
	426:  uint16(319),
	427:  uint16(567),
	428:  uint16(119),
	429:  uint16(119),
	430:  uint16(343),
	431:  uint16(466),
	432:  uint16(331),
	433:  uint16(343),
	434:  uint16(287),
	435:  uint16(287),
	436:  uint16(120),
	437:  uint16(556),
	438:  uint16(451),
	439:  uint16(577),
	440:  uint16(451),
	441:  uint16(1169),
	442:  uint16(1169),
	443:  uint16(1028),
	444:  uint16(319),
	445:  uint16(567),
	446:  uint16(438),
	447:  uint16(573),
	448:  uint16(210),
	449:  uint16(561),
	450:  uint16(1339),
	451:  uint16(1451),
	452:  uint16(546),
	453:  uint16(531),
	454:  uint16(1169),
	455:  uint16(1169),
	456:  uint16(1598),
	457:  uint16(1169),
	458:  uint16(1169),
	459:  uint16(416),
	460:  uint16(319),
	461:  uint16(567),
	462:  uint16(243),
	463:  uint16(132),
	464:  uint16(132),
	465:  uint16(132),
	466:  uint16(132),
	467:  uint16(131),
	468:  uint16(131),
	469:  uint16(130),
	470:  uint16(130),
	471:  uint16(130),
	472:  uint16(129),
	473:  uint16(126),
	474:  uint16(450),
	475:  uint16(1028),
	476:  uint16(1028),
	477:  uint16(1030),
	478:  uint16(1031),
	479:  uint16(35),
	480:  uint16(44),
	481:  uint16(1204),
	482:  uint16(1205),
	483:  uint16(1204),
	484:  uint16(472),
	485:  uint16(287),
	486:  uint16(287),
	487:  uint16(1328),
	488:  uint16(412),
	489:  uint16(1307),
	490:  uint16(372),
	491:  uint16(1595),
	492:  uint16(359),
	493:  uint16(225),
	494:  uint16(454),
	495:  uint16(1204),
	496:  uint16(195),
	497:  uint16(1328),
	498:  uint16(573),
	499:  uint16(1147),
	500:  uint16(561),
	501:  uint16(1333),
	502:  uint16(1333),
	503:  uint16(274),
	504:  uint16(576),
	505:  uint16(1188),
	506:  uint16(576),
	507:  uint16(340),
	508:  uint16(46),
	509:  uint16(196),
	510:  uint16(537),
	511:  uint16(217),
	512:  uint16(135),
	513:  uint16(136),
	514:  uint16(90),
	515:  uint16(1228),
	516:  uint16(1228),
	517:  uint16(1063),
	518:  uint16(1066),
	519:  uint16(1053),
	520:  uint16(1053),
	521:  uint16(133),
	522:  uint16(133),
	523:  uint16(134),
	524:  uint16(134),
	525:  uint16(134),
	526:  uint16(134),
	527:  uint16(19),
	528:  uint16(19),
	529:  uint16(19),
	530:  uint16(19),
	531:  uint16(412),
	532:  uint16(581),
	533:  uint16(1204),
	534:  uint16(1259),
	535:  uint16(511),
	536:  uint16(1204),
	537:  uint16(319),
	538:  uint16(567),
	539:  uint16(320),
	540:  uint16(944),
	541:  uint16(153),
	542:  uint16(425),
	543:  uint16(491),
	544:  uint16(430),
	545:  uint16(943),
	546:  uint16(1204),
	547:  uint16(488),
	548:  uint16(1341),
	549:  uint16(1450),
	550:  uint16(532),
	551:  uint16(1277),
	552:  uint16(1204),
	553:  uint16(1205),
	554:  uint16(1204),
	555:  uint16(135),
	556:  uint16(136),
	557:  uint16(90),
	558:  uint16(1228),
	559:  uint16(1228),
	560:  uint16(1063),
	561:  uint16(1066),
	562:  uint16(1053),
	563:  uint16(1053),
	564:  uint16(133),
	565:  uint16(133),
	566:  uint16(134),
	567:  uint16(134),
	568:  uint16(134),
	569:  uint16(134),
	570:  uint16(575),
	571:  uint16(132),
	572:  uint16(132),
	573:  uint16(132),
	574:  uint16(132),
	575:  uint16(131),
	576:  uint16(131),
	577:  uint16(130),
	578:  uint16(130),
	579:  uint16(130),
	580:  uint16(129),
	581:  uint16(126),
	582:  uint16(450),
	583:  uint16(287),
	584:  uint16(287),
	585:  uint16(528),
	586:  uint16(287),
	587:  uint16(287),
	588:  uint16(372),
	589:  uint16(1595),
	590:  uint16(1204),
	591:  uint16(1205),
	592:  uint16(1204),
	593:  uint16(1204),
	594:  uint16(1205),
	595:  uint16(1204),
	596:  uint16(573),
	597:  uint16(486),
	598:  uint16(561),
	599:  uint16(573),
	600:  uint16(889),
	601:  uint16(561),
	602:  uint16(412),
	603:  uint16(1204),
	604:  uint16(1205),
	605:  uint16(1204),
	606:  uint16(886),
	607:  uint16(40),
	608:  uint16(22),
	609:  uint16(22),
	610:  uint16(220),
	611:  uint16(243),
	612:  uint16(525),
	613:  uint16(1449),
	614:  uint16(132),
	615:  uint16(132),
	616:  uint16(132),
	617:  uint16(132),
	618:  uint16(131),
	619:  uint16(131),
	620:  uint16(130),
	621:  uint16(130),
	622:  uint16(130),
	623:  uint16(129),
	624:  uint16(126),
	625:  uint16(450),
	626:  uint16(135),
	627:  uint16(136),
	628:  uint16(90),
	629:  uint16(1228),
	630:  uint16(1228),
	631:  uint16(1063),
	632:  uint16(1066),
	633:  uint16(1053),
	634:  uint16(1053),
	635:  uint16(133),
	636:  uint16(133),
	637:  uint16(134),
	638:  uint16(134),
	639:  uint16(134),
	640:  uint16(134),
	641:  uint16(412),
	642:  uint16(180),
	643:  uint16(454),
	644:  uint16(1204),
	645:  uint16(879),
	646:  uint16(255),
	647:  uint16(287),
	648:  uint16(287),
	649:  uint16(510),
	650:  uint16(507),
	651:  uint16(506),
	652:  uint16(372),
	653:  uint16(1595),
	654:  uint16(1568),
	655:  uint16(1331),
	656:  uint16(1331),
	657:  uint16(576),
	658:  uint16(889),
	659:  uint16(505),
	660:  uint16(573),
	661:  uint16(44),
	662:  uint16(561),
	663:  uint16(559),
	664:  uint16(1207),
	665:  uint16(135),
	666:  uint16(136),
	667:  uint16(90),
	668:  uint16(1228),
	669:  uint16(1228),
	670:  uint16(1063),
	671:  uint16(1066),
	672:  uint16(1053),
	673:  uint16(1053),
	674:  uint16(133),
	675:  uint16(133),
	676:  uint16(134),
	677:  uint16(134),
	678:  uint16(134),
	679:  uint16(134),
	680:  uint16(81),
	681:  uint16(81),
	682:  uint16(422),
	683:  uint16(576),
	684:  uint16(377),
	685:  uint16(132),
	686:  uint16(132),
	687:  uint16(132),
	688:  uint16(132),
	689:  uint16(131),
	690:  uint16(131),
	691:  uint16(130),
	692:  uint16(130),
	693:  uint16(130),
	694:  uint16(129),
	695:  uint16(126),
	696:  uint16(450),
	697:  uint16(297),
	698:  uint16(287),
	699:  uint16(287),
	700:  uint16(460),
	701:  uint16(1204),
	702:  uint16(1205),
	703:  uint16(1204),
	704:  uint16(1204),
	705:  uint16(534),
	706:  uint16(19),
	707:  uint16(19),
	708:  uint16(448),
	709:  uint16(448),
	710:  uint16(448),
	711:  uint16(573),
	712:  uint16(412),
	713:  uint16(561),
	714:  uint16(230),
	715:  uint16(436),
	716:  uint16(1187),
	717:  uint16(535),
	718:  uint16(319),
	719:  uint16(567),
	720:  uint16(363),
	721:  uint16(432),
	722:  uint16(1207),
	723:  uint16(1435),
	724:  uint16(132),
	725:  uint16(132),
	726:  uint16(132),
	727:  uint16(132),
	728:  uint16(131),
	729:  uint16(131),
	730:  uint16(130),
	731:  uint16(130),
	732:  uint16(130),
	733:  uint16(129),
	734:  uint16(126),
	735:  uint16(450),
	736:  uint16(135),
	737:  uint16(136),
	738:  uint16(90),
	739:  uint16(1228),
	740:  uint16(1228),
	741:  uint16(1063),
	742:  uint16(1066),
	743:  uint16(1053),
	744:  uint16(1053),
	745:  uint16(133),
	746:  uint16(133),
	747:  uint16(134),
	748:  uint16(134),
	749:  uint16(134),
	750:  uint16(134),
	751:  uint16(412),
	752:  uint16(211),
	753:  uint16(949),
	754:  uint16(1169),
	755:  uint16(1041),
	756:  uint16(1110),
	757:  uint16(1110),
	758:  uint16(494),
	759:  uint16(547),
	760:  uint16(547),
	761:  uint16(1204),
	762:  uint16(1205),
	763:  uint16(1204),
	764:  uint16(7),
	765:  uint16(539),
	766:  uint16(1570),
	767:  uint16(1169),
	768:  uint16(376),
	769:  uint16(576),
	770:  uint16(1169),
	771:  uint16(5),
	772:  uint16(1204),
	773:  uint16(486),
	774:  uint16(3),
	775:  uint16(135),
	776:  uint16(136),
	777:  uint16(90),
	778:  uint16(1228),
	779:  uint16(1228),
	780:  uint16(1063),
	781:  uint16(1066),
	782:  uint16(1053),
	783:  uint16(1053),
	784:  uint16(133),
	785:  uint16(133),
	786:  uint16(134),
	787:  uint16(134),
	788:  uint16(134),
	789:  uint16(134),
	790:  uint16(576),
	791:  uint16(513),
	792:  uint16(19),
	793:  uint16(19),
	794:  uint16(427),
	795:  uint16(132),
	796:  uint16(132),
	797:  uint16(132),
	798:  uint16(132),
	799:  uint16(131),
	800:  uint16(131),
	801:  uint16(130),
	802:  uint16(130),
	803:  uint16(130),
	804:  uint16(129),
	805:  uint16(126),
	806:  uint16(450),
	807:  uint16(305),
	808:  uint16(1204),
	809:  uint16(433),
	810:  uint16(225),
	811:  uint16(1204),
	812:  uint16(385),
	813:  uint16(19),
	814:  uint16(19),
	815:  uint16(273),
	816:  uint16(290),
	817:  uint16(371),
	818:  uint16(516),
	819:  uint16(366),
	820:  uint16(515),
	821:  uint16(260),
	822:  uint16(412),
	823:  uint16(538),
	824:  uint16(1568),
	825:  uint16(549),
	826:  uint16(1024),
	827:  uint16(362),
	828:  uint16(437),
	829:  uint16(1204),
	830:  uint16(1205),
	831:  uint16(1204),
	832:  uint16(902),
	833:  uint16(1552),
	834:  uint16(132),
	835:  uint16(132),
	836:  uint16(132),
	837:  uint16(132),
	838:  uint16(131),
	839:  uint16(131),
	840:  uint16(130),
	841:  uint16(130),
	842:  uint16(130),
	843:  uint16(129),
	844:  uint16(126),
	845:  uint16(450),
	846:  uint16(135),
	847:  uint16(136),
	848:  uint16(90),
	849:  uint16(1228),
	850:  uint16(1228),
	851:  uint16(1063),
	852:  uint16(1066),
	853:  uint16(1053),
	854:  uint16(1053),
	855:  uint16(133),
	856:  uint16(133),
	857:  uint16(134),
	858:  uint16(134),
	859:  uint16(134),
	860:  uint16(134),
	861:  uint16(412),
	862:  uint16(1435),
	863:  uint16(514),
	864:  uint16(1281),
	865:  uint16(1204),
	866:  uint16(1205),
	867:  uint16(1204),
	868:  uint16(1204),
	869:  uint16(1205),
	870:  uint16(1204),
	871:  uint16(903),
	872:  uint16(48),
	873:  uint16(342),
	874:  uint16(1568),
	875:  uint16(1568),
	876:  uint16(1279),
	877:  uint16(1627),
	878:  uint16(1568),
	879:  uint16(911),
	880:  uint16(576),
	881:  uint16(129),
	882:  uint16(126),
	883:  uint16(450),
	884:  uint16(110),
	885:  uint16(135),
	886:  uint16(136),
	887:  uint16(90),
	888:  uint16(1228),
	889:  uint16(1228),
	890:  uint16(1063),
	891:  uint16(1066),
	892:  uint16(1053),
	893:  uint16(1053),
	894:  uint16(133),
	895:  uint16(133),
	896:  uint16(134),
	897:  uint16(134),
	898:  uint16(134),
	899:  uint16(134),
	900:  uint16(265),
	901:  uint16(576),
	902:  uint16(459),
	903:  uint16(19),
	904:  uint16(19),
	905:  uint16(132),
	906:  uint16(132),
	907:  uint16(132),
	908:  uint16(132),
	909:  uint16(131),
	910:  uint16(131),
	911:  uint16(130),
	912:  uint16(130),
	913:  uint16(130),
	914:  uint16(129),
	915:  uint16(126),
	916:  uint16(450),
	917:  uint16(1345),
	918:  uint16(204),
	919:  uint16(576),
	920:  uint16(459),
	921:  uint16(458),
	922:  uint16(50),
	923:  uint16(47),
	924:  uint16(19),
	925:  uint16(19),
	926:  uint16(49),
	927:  uint16(434),
	928:  uint16(1105),
	929:  uint16(573),
	930:  uint16(497),
	931:  uint16(561),
	932:  uint16(412),
	933:  uint16(428),
	934:  uint16(108),
	935:  uint16(1224),
	936:  uint16(1569),
	937:  uint16(1554),
	938:  uint16(376),
	939:  uint16(205),
	940:  uint16(550),
	941:  uint16(550),
	942:  uint16(81),
	943:  uint16(81),
	944:  uint16(132),
	945:  uint16(132),
	946:  uint16(132),
	947:  uint16(132),
	948:  uint16(131),
	949:  uint16(131),
	950:  uint16(130),
	951:  uint16(130),
	952:  uint16(130),
	953:  uint16(129),
	954:  uint16(126),
	955:  uint16(450),
	956:  uint16(135),
	957:  uint16(136),
	958:  uint16(90),
	959:  uint16(1228),
	960:  uint16(1228),
	961:  uint16(1063),
	962:  uint16(1066),
	963:  uint16(1053),
	964:  uint16(1053),
	965:  uint16(133),
	966:  uint16(133),
	967:  uint16(134),
	968:  uint16(134),
	969:  uint16(134),
	970:  uint16(134),
	971:  uint16(480),
	972:  uint16(576),
	973:  uint16(1204),
	974:  uint16(576),
	975:  uint16(1541),
	976:  uint16(412),
	977:  uint16(1435),
	978:  uint16(969),
	979:  uint16(315),
	980:  uint16(1659),
	981:  uint16(398),
	982:  uint16(284),
	983:  uint16(497),
	984:  uint16(969),
	985:  uint16(893),
	986:  uint16(1569),
	987:  uint16(1569),
	988:  uint16(376),
	989:  uint16(376),
	990:  uint16(1569),
	991:  uint16(461),
	992:  uint16(376),
	993:  uint16(1224),
	994:  uint16(459),
	995:  uint16(80),
	996:  uint16(80),
	997:  uint16(81),
	998:  uint16(81),
	999:  uint16(497),
	1000: uint16(374),
	1001: uint16(114),
	1002: uint16(90),
	1003: uint16(1228),
	1004: uint16(1228),
	1005: uint16(1063),
	1006: uint16(1066),
	1007: uint16(1053),
	1008: uint16(1053),
	1009: uint16(133),
	1010: uint16(133),
	1011: uint16(134),
	1012: uint16(134),
	1013: uint16(134),
	1014: uint16(134),
	1015: uint16(132),
	1016: uint16(132),
	1017: uint16(132),
	1018: uint16(132),
	1019: uint16(131),
	1020: uint16(131),
	1021: uint16(130),
	1022: uint16(130),
	1023: uint16(130),
	1024: uint16(129),
	1025: uint16(126),
	1026: uint16(450),
	1027: uint16(1204),
	1028: uint16(1505),
	1029: uint16(576),
	1030: uint16(1204),
	1031: uint16(1205),
	1032: uint16(1204),
	1033: uint16(1366),
	1034: uint16(316),
	1035: uint16(486),
	1036: uint16(281),
	1037: uint16(281),
	1038: uint16(497),
	1039: uint16(431),
	1040: uint16(557),
	1041: uint16(288),
	1042: uint16(288),
	1043: uint16(402),
	1044: uint16(1340),
	1045: uint16(471),
	1046: uint16(345),
	1047: uint16(298),
	1048: uint16(429),
	1049: uint16(573),
	1050: uint16(576),
	1051: uint16(561),
	1052: uint16(81),
	1053: uint16(81),
	1054: uint16(573),
	1055: uint16(374),
	1056: uint16(561),
	1057: uint16(971),
	1058: uint16(386),
	1059: uint16(132),
	1060: uint16(132),
	1061: uint16(132),
	1062: uint16(132),
	1063: uint16(131),
	1064: uint16(131),
	1065: uint16(130),
	1066: uint16(130),
	1067: uint16(130),
	1068: uint16(129),
	1069: uint16(126),
	1070: uint16(450),
	1071: uint16(231),
	1072: uint16(117),
	1073: uint16(81),
	1074: uint16(81),
	1075: uint16(287),
	1076: uint16(287),
	1077: uint16(231),
	1078: uint16(287),
	1079: uint16(287),
	1080: uint16(576),
	1081: uint16(1511),
	1082: uint16(576),
	1083: uint16(1336),
	1084: uint16(1204),
	1085: uint16(1205),
	1086: uint16(1204),
	1087: uint16(139),
	1088: uint16(573),
	1089: uint16(556),
	1090: uint16(561),
	1091: uint16(573),
	1092: uint16(412),
	1093: uint16(561),
	1094: uint16(441),
	1095: uint16(456),
	1096: uint16(969),
	1097: uint16(213),
	1098: uint16(558),
	1099: uint16(1511),
	1100: uint16(1513),
	1101: uint16(1550),
	1102: uint16(969),
	1103: uint16(143),
	1104: uint16(143),
	1105: uint16(145),
	1106: uint16(145),
	1107: uint16(1368),
	1108: uint16(314),
	1109: uint16(478),
	1110: uint16(444),
	1111: uint16(970),
	1112: uint16(412),
	1113: uint16(850),
	1114: uint16(851),
	1115: uint16(852),
	1116: uint16(135),
	1117: uint16(136),
	1118: uint16(90),
	1119: uint16(1228),
	1120: uint16(1228),
	1121: uint16(1063),
	1122: uint16(1066),
	1123: uint16(1053),
	1124: uint16(1053),
	1125: uint16(133),
	1126: uint16(133),
	1127: uint16(134),
	1128: uint16(134),
	1129: uint16(134),
	1130: uint16(134),
	1131: uint16(357),
	1132: uint16(412),
	1133: uint16(397),
	1134: uint16(1148),
	1135: uint16(304),
	1136: uint16(135),
	1137: uint16(136),
	1138: uint16(90),
	1139: uint16(1228),
	1140: uint16(1228),
	1141: uint16(1063),
	1142: uint16(1066),
	1143: uint16(1053),
	1144: uint16(1053),
	1145: uint16(133),
	1146: uint16(133),
	1147: uint16(134),
	1148: uint16(134),
	1149: uint16(134),
	1150: uint16(134),
	1151: uint16(1575),
	1152: uint16(323),
	1153: uint16(6),
	1154: uint16(862),
	1155: uint16(7),
	1156: uint16(135),
	1157: uint16(124),
	1158: uint16(90),
	1159: uint16(1228),
	1160: uint16(1228),
	1161: uint16(1063),
	1162: uint16(1066),
	1163: uint16(1053),
	1164: uint16(1053),
	1165: uint16(133),
	1166: uint16(133),
	1167: uint16(134),
	1168: uint16(134),
	1169: uint16(134),
	1170: uint16(134),
	1171: uint16(409),
	1172: uint16(408),
	1173: uint16(1511),
	1174: uint16(212),
	1175: uint16(132),
	1176: uint16(132),
	1177: uint16(132),
	1178: uint16(132),
	1179: uint16(131),
	1180: uint16(131),
	1181: uint16(130),
	1182: uint16(130),
	1183: uint16(130),
	1184: uint16(129),
	1185: uint16(126),
	1186: uint16(450),
	1187: uint16(411),
	1188: uint16(118),
	1189: uint16(1204),
	1190: uint16(116),
	1191: uint16(10),
	1192: uint16(352),
	1193: uint16(265),
	1194: uint16(355),
	1195: uint16(132),
	1196: uint16(132),
	1197: uint16(132),
	1198: uint16(132),
	1199: uint16(131),
	1200: uint16(131),
	1201: uint16(130),
	1202: uint16(130),
	1203: uint16(130),
	1204: uint16(129),
	1205: uint16(126),
	1206: uint16(450),
	1207: uint16(576),
	1208: uint16(324),
	1209: uint16(306),
	1210: uint16(576),
	1211: uint16(306),
	1212: uint16(1250),
	1213: uint16(469),
	1214: uint16(158),
	1215: uint16(132),
	1216: uint16(132),
	1217: uint16(132),
	1218: uint16(132),
	1219: uint16(131),
	1220: uint16(131),
	1221: uint16(130),
	1222: uint16(130),
	1223: uint16(130),
	1224: uint16(129),
	1225: uint16(126),
	1226: uint16(450),
	1227: uint16(207),
	1228: uint16(1224),
	1229: uint16(1126),
	1230: uint16(65),
	1231: uint16(65),
	1232: uint16(470),
	1233: uint16(66),
	1234: uint16(66),
	1235: uint16(412),
	1236: uint16(447),
	1237: uint16(446),
	1238: uint16(882),
	1239: uint16(531),
	1240: uint16(335),
	1241: uint16(258),
	1242: uint16(257),
	1243: uint16(256),
	1244: uint16(1127),
	1245: uint16(1233),
	1246: uint16(1204),
	1247: uint16(1205),
	1248: uint16(1204),
	1249: uint16(327),
	1250: uint16(1235),
	1251: uint16(874),
	1252: uint16(159),
	1253: uint16(576),
	1254: uint16(16),
	1255: uint16(480),
	1256: uint16(1085),
	1257: uint16(1040),
	1258: uint16(1234),
	1259: uint16(1128),
	1260: uint16(136),
	1261: uint16(90),
	1262: uint16(1228),
	1263: uint16(1228),
	1264: uint16(1063),
	1265: uint16(1066),
	1266: uint16(1053),
	1267: uint16(1053),
	1268: uint16(133),
	1269: uint16(133),
	1270: uint16(134),
	1271: uint16(134),
	1272: uint16(134),
	1273: uint16(134),
	1274: uint16(1029),
	1275: uint16(576),
	1276: uint16(81),
	1277: uint16(81),
	1278: uint16(1028),
	1279: uint16(1040),
	1280: uint16(922),
	1281: uint16(576),
	1282: uint16(463),
	1283: uint16(1236),
	1284: uint16(576),
	1285: uint16(1236),
	1286: uint16(1224),
	1287: uint16(502),
	1288: uint16(107),
	1289: uint16(1435),
	1290: uint16(923),
	1291: uint16(6),
	1292: uint16(576),
	1293: uint16(410),
	1294: uint16(1498),
	1295: uint16(882),
	1296: uint16(1029),
	1297: uint16(480),
	1298: uint16(21),
	1299: uint16(21),
	1300: uint16(1028),
	1301: uint16(332),
	1302: uint16(1380),
	1303: uint16(334),
	1304: uint16(53),
	1305: uint16(53),
	1306: uint16(497),
	1307: uint16(81),
	1308: uint16(81),
	1309: uint16(874),
	1310: uint16(1028),
	1311: uint16(1028),
	1312: uint16(1030),
	1313: uint16(445),
	1314: uint16(259),
	1315: uint16(19),
	1316: uint16(19),
	1317: uint16(533),
	1318: uint16(132),
	1319: uint16(132),
	1320: uint16(132),
	1321: uint16(132),
	1322: uint16(131),
	1323: uint16(131),
	1324: uint16(130),
	1325: uint16(130),
	1326: uint16(130),
	1327: uint16(129),
	1328: uint16(126),
	1329: uint16(450),
	1330: uint16(551),
	1331: uint16(301),
	1332: uint16(1028),
	1333: uint16(1028),
	1334: uint16(1030),
	1335: uint16(107),
	1336: uint16(532),
	1337: uint16(545),
	1338: uint16(121),
	1339: uint16(568),
	1340: uint16(1188),
	1341: uint16(4),
	1342: uint16(1126),
	1343: uint16(1576),
	1344: uint16(449),
	1345: uint16(576),
	1346: uint16(462),
	1347: uint16(7),
	1348: uint16(1282),
	1349: uint16(418),
	1350: uint16(462),
	1351: uint16(350),
	1352: uint16(1435),
	1353: uint16(576),
	1354: uint16(518),
	1355: uint16(571),
	1356: uint16(544),
	1357: uint16(1127),
	1358: uint16(121),
	1359: uint16(568),
	1360: uint16(442),
	1361: uint16(4),
	1362: uint16(1188),
	1363: uint16(464),
	1364: uint16(533),
	1365: uint16(1180),
	1366: uint16(1223),
	1367: uint16(9),
	1368: uint16(67),
	1369: uint16(67),
	1370: uint16(487),
	1371: uint16(576),
	1372: uint16(1128),
	1373: uint16(303),
	1374: uint16(410),
	1375: uint16(571),
	1376: uint16(54),
	1377: uint16(54),
	1378: uint16(451),
	1379: uint16(576),
	1380: uint16(123),
	1381: uint16(944),
	1382: uint16(576),
	1383: uint16(417),
	1384: uint16(576),
	1385: uint16(333),
	1386: uint16(943),
	1387: uint16(1379),
	1388: uint16(576),
	1389: uint16(236),
	1390: uint16(565),
	1391: uint16(576),
	1392: uint16(1574),
	1393: uint16(564),
	1394: uint16(68),
	1395: uint16(68),
	1396: uint16(7),
	1397: uint16(576),
	1398: uint16(451),
	1399: uint16(362),
	1400: uint16(419),
	1401: uint16(182),
	1402: uint16(69),
	1403: uint16(69),
	1404: uint16(541),
	1405: uint16(70),
	1406: uint16(70),
	1407: uint16(71),
	1408: uint16(71),
	1409: uint16(540),
	1410: uint16(565),
	1411: uint16(72),
	1412: uint16(72),
	1413: uint16(484),
	1414: uint16(55),
	1415: uint16(55),
	1416: uint16(473),
	1417: uint16(1180),
	1418: uint16(296),
	1419: uint16(1040),
	1420: uint16(56),
	1421: uint16(56),
	1422: uint16(296),
	1423: uint16(493),
	1424: uint16(541),
	1425: uint16(119),
	1426: uint16(119),
	1427: uint16(410),
	1428: uint16(1573),
	1429: uint16(542),
	1430: uint16(569),
	1431: uint16(418),
	1432: uint16(7),
	1433: uint16(120),
	1434: uint16(1244),
	1435: uint16(451),
	1436: uint16(577),
	1437: uint16(451),
	1438: uint16(465),
	1439: uint16(1040),
	1440: uint16(1028),
	1441: uint16(576),
	1442: uint16(1557),
	1443: uint16(552),
	1444: uint16(476),
	1445: uint16(119),
	1446: uint16(119),
	1447: uint16(527),
	1448: uint16(259),
	1449: uint16(121),
	1450: uint16(568),
	1451: uint16(240),
	1452: uint16(4),
	1453: uint16(120),
	1454: uint16(576),
	1455: uint16(451),
	1456: uint16(577),
	1457: uint16(451),
	1458: uint16(576),
	1459: uint16(477),
	1460: uint16(1028),
	1461: uint16(576),
	1462: uint16(156),
	1463: uint16(576),
	1464: uint16(57),
	1465: uint16(57),
	1466: uint16(571),
	1467: uint16(576),
	1468: uint16(286),
	1469: uint16(229),
	1470: uint16(410),
	1471: uint16(336),
	1472: uint16(1028),
	1473: uint16(1028),
	1474: uint16(1030),
	1475: uint16(1031),
	1476: uint16(35),
	1477: uint16(59),
	1478: uint16(59),
	1479: uint16(219),
	1480: uint16(983),
	1481: uint16(60),
	1482: uint16(60),
	1483: uint16(220),
	1484: uint16(73),
	1485: uint16(73),
	1486: uint16(74),
	1487: uint16(74),
	1488: uint16(984),
	1489: uint16(451),
	1490: uint16(75),
	1491: uint16(75),
	1492: uint16(1028),
	1493: uint16(1028),
	1494: uint16(1030),
	1495: uint16(1031),
	1496: uint16(35),
	1497: uint16(96),
	1498: uint16(216),
	1499: uint16(291),
	1500: uint16(552),
	1501: uint16(565),
	1502: uint16(1188),
	1503: uint16(318),
	1504: uint16(395),
	1505: uint16(395),
	1506: uint16(394),
	1507: uint16(276),
	1508: uint16(392),
	1509: uint16(576),
	1510: uint16(485),
	1511: uint16(859),
	1512: uint16(474),
	1513: uint16(1311),
	1514: uint16(410),
	1515: uint16(541),
	1516: uint16(576),
	1517: uint16(417),
	1518: uint16(1530),
	1519: uint16(1144),
	1520: uint16(540),
	1521: uint16(399),
	1522: uint16(1188),
	1523: uint16(292),
	1524: uint16(237),
	1525: uint16(1153),
	1526: uint16(326),
	1527: uint16(38),
	1528: uint16(23),
	1529: uint16(576),
	1530: uint16(1040),
	1531: uint16(576),
	1532: uint16(20),
	1533: uint16(20),
	1534: uint16(325),
	1535: uint16(299),
	1536: uint16(119),
	1537: uint16(119),
	1538: uint16(164),
	1539: uint16(76),
	1540: uint16(76),
	1541: uint16(1529),
	1542: uint16(121),
	1543: uint16(568),
	1544: uint16(120),
	1545: uint16(4),
	1546: uint16(451),
	1547: uint16(577),
	1548: uint16(451),
	1549: uint16(203),
	1550: uint16(576),
	1551: uint16(1028),
	1552: uint16(141),
	1553: uint16(141),
	1554: uint16(142),
	1555: uint16(142),
	1556: uint16(576),
	1557: uint16(322),
	1558: uint16(39),
	1559: uint16(571),
	1560: uint16(341),
	1561: uint16(1021),
	1562: uint16(110),
	1563: uint16(264),
	1564: uint16(239),
	1565: uint16(901),
	1566: uint16(900),
	1567: uint16(423),
	1568: uint16(242),
	1569: uint16(908),
	1570: uint16(909),
	1571: uint16(370),
	1572: uint16(173),
	1573: uint16(77),
	1574: uint16(77),
	1575: uint16(43),
	1576: uint16(479),
	1577: uint16(1310),
	1578: uint16(264),
	1579: uint16(62),
	1580: uint16(62),
	1581: uint16(369),
	1582: uint16(451),
	1583: uint16(1028),
	1584: uint16(1028),
	1585: uint16(1030),
	1586: uint16(1031),
	1587: uint16(35),
	1588: uint16(1601),
	1589: uint16(1192),
	1590: uint16(453),
	1591: uint16(1092),
	1592: uint16(238),
	1593: uint16(291),
	1594: uint16(565),
	1595: uint16(163),
	1596: uint16(1309),
	1597: uint16(110),
	1598: uint16(395),
	1599: uint16(395),
	1600: uint16(394),
	1601: uint16(276),
	1602: uint16(392),
	1603: uint16(986),
	1604: uint16(987),
	1605: uint16(859),
	1606: uint16(481),
	1607: uint16(346),
	1608: uint16(264),
	1609: uint16(110),
	1610: uint16(1032),
	1611: uint16(489),
	1612: uint16(576),
	1613: uint16(1188),
	1614: uint16(503),
	1615: uint16(1088),
	1616: uint16(261),
	1617: uint16(261),
	1618: uint16(237),
	1619: uint16(576),
	1620: uint16(326),
	1621: uint16(121),
	1622: uint16(568),
	1623: uint16(1040),
	1624: uint16(4),
	1625: uint16(347),
	1626: uint16(1376),
	1627: uint16(413),
	1628: uint16(325),
	1629: uint16(119),
	1630: uint16(119),
	1631: uint16(948),
	1632: uint16(319),
	1633: uint16(567),
	1634: uint16(351),
	1635: uint16(78),
	1636: uint16(78),
	1637: uint16(120),
	1638: uint16(571),
	1639: uint16(451),
	1640: uint16(577),
	1641: uint16(451),
	1642: uint16(79),
	1643: uint16(79),
	1644: uint16(1028),
	1645: uint16(354),
	1646: uint16(356),
	1647: uint16(576),
	1648: uint16(360),
	1649: uint16(1092),
	1650: uint16(110),
	1651: uint16(576),
	1652: uint16(974),
	1653: uint16(942),
	1654: uint16(264),
	1655: uint16(123),
	1656: uint16(457),
	1657: uint16(358),
	1658: uint16(239),
	1659: uint16(576),
	1660: uint16(519),
	1661: uint16(451),
	1662: uint16(939),
	1663: uint16(1104),
	1664: uint16(123),
	1665: uint16(1104),
	1666: uint16(173),
	1667: uint16(576),
	1668: uint16(1032),
	1669: uint16(43),
	1670: uint16(63),
	1671: uint16(63),
	1672: uint16(1324),
	1673: uint16(565),
	1674: uint16(168),
	1675: uint16(168),
	1676: uint16(1028),
	1677: uint16(1028),
	1678: uint16(1030),
	1679: uint16(1031),
	1680: uint16(35),
	1681: uint16(576),
	1682: uint16(169),
	1683: uint16(169),
	1684: uint16(1308),
	1685: uint16(872),
	1686: uint16(238),
	1687: uint16(157),
	1688: uint16(1589),
	1689: uint16(576),
	1690: uint16(86),
	1691: uint16(86),
	1692: uint16(365),
	1693: uint16(89),
	1694: uint16(568),
	1695: uint16(375),
	1696: uint16(4),
	1697: uint16(1103),
	1698: uint16(941),
	1699: uint16(1103),
	1700: uint16(123),
	1701: uint16(576),
	1702: uint16(1040),
	1703: uint16(1389),
	1704: uint16(64),
	1705: uint16(64),
	1706: uint16(1188),
	1707: uint16(1434),
	1708: uint16(119),
	1709: uint16(119),
	1710: uint16(571),
	1711: uint16(576),
	1712: uint16(82),
	1713: uint16(82),
	1714: uint16(563),
	1715: uint16(576),
	1716: uint16(120),
	1717: uint16(165),
	1718: uint16(451),
	1719: uint16(577),
	1720: uint16(451),
	1721: uint16(413),
	1722: uint16(1362),
	1723: uint16(1028),
	1724: uint16(144),
	1725: uint16(144),
	1726: uint16(319),
	1727: uint16(567),
	1728: uint16(576),
	1729: uint16(1374),
	1730: uint16(562),
	1731: uint16(498),
	1732: uint16(279),
	1733: uint16(451),
	1734: uint16(83),
	1735: uint16(83),
	1736: uint16(1439),
	1737: uint16(576),
	1738: uint16(166),
	1739: uint16(166),
	1740: uint16(576),
	1741: uint16(1289),
	1742: uint16(554),
	1743: uint16(576),
	1744: uint16(1280),
	1745: uint16(565),
	1746: uint16(576),
	1747: uint16(12),
	1748: uint16(576),
	1749: uint16(1268),
	1750: uint16(457),
	1751: uint16(146),
	1752: uint16(146),
	1753: uint16(1267),
	1754: uint16(576),
	1755: uint16(1028),
	1756: uint16(1028),
	1757: uint16(1030),
	1758: uint16(1031),
	1759: uint16(35),
	1760: uint16(140),
	1761: uint16(140),
	1762: uint16(1269),
	1763: uint16(167),
	1764: uint16(167),
	1765: uint16(1609),
	1766: uint16(160),
	1767: uint16(160),
	1768: uint16(1359),
	1769: uint16(150),
	1770: uint16(150),
	1771: uint16(149),
	1772: uint16(149),
	1773: uint16(311),
	1774: uint16(1040),
	1775: uint16(576),
	1776: uint16(312),
	1777: uint16(147),
	1778: uint16(147),
	1779: uint16(313),
	1780: uint16(119),
	1781: uint16(119),
	1782: uint16(222),
	1783: uint16(235),
	1784: uint16(576),
	1785: uint16(1188),
	1786: uint16(396),
	1787: uint16(576),
	1788: uint16(120),
	1789: uint16(576),
	1790: uint16(451),
	1791: uint16(577),
	1792: uint16(451),
	1793: uint16(1192),
	1794: uint16(453),
	1795: uint16(1028),
	1796: uint16(508),
	1797: uint16(291),
	1798: uint16(148),
	1799: uint16(148),
	1800: uint16(1421),
	1801: uint16(1612),
	1802: uint16(395),
	1803: uint16(395),
	1804: uint16(394),
	1805: uint16(276),
	1806: uint16(392),
	1807: uint16(85),
	1808: uint16(85),
	1809: uint16(859),
	1810: uint16(87),
	1811: uint16(87),
	1812: uint16(84),
	1813: uint16(84),
	1814: uint16(553),
	1815: uint16(576),
	1816: uint16(294),
	1817: uint16(576),
	1818: uint16(1426),
	1819: uint16(338),
	1820: uint16(339),
	1821: uint16(1425),
	1822: uint16(237),
	1823: uint16(300),
	1824: uint16(326),
	1825: uint16(1416),
	1826: uint16(1409),
	1827: uint16(1028),
	1828: uint16(1028),
	1829: uint16(1030),
	1830: uint16(1031),
	1831: uint16(35),
	1832: uint16(325),
	1833: uint16(344),
	1834: uint16(403),
	1835: uint16(483),
	1836: uint16(226),
	1837: uint16(1307),
	1838: uint16(52),
	1839: uint16(52),
	1840: uint16(58),
	1841: uint16(58),
	1842: uint16(368),
	1843: uint16(1371),
	1844: uint16(1502),
	1845: uint16(566),
	1846: uint16(1501),
	1847: uint16(121),
	1848: uint16(568),
	1849: uint16(221),
	1850: uint16(4),
	1851: uint16(208),
	1852: uint16(268),
	1853: uint16(209),
	1854: uint16(390),
	1855: uint16(1244),
	1856: uint16(1549),
	1857: uint16(1188),
	1858: uint16(1372),
	1859: uint16(1370),
	1860: uint16(1369),
	1861: uint16(1547),
	1862: uint16(239),
	1863: uint16(184),
	1864: uint16(571),
	1865: uint16(233),
	1866: uint16(421),
	1867: uint16(1241),
	1868: uint16(95),
	1869: uint16(218),
	1870: uint16(173),
	1871: uint16(1507),
	1872: uint16(193),
	1873: uint16(43),
	1874: uint16(91),
	1875: uint16(94),
	1876: uint16(178),
	1877: uint16(186),
	1878: uint16(467),
	1879: uint16(188),
	1880: uint16(468),
	1881: uint16(1422),
	1882: uint16(13),
	1883: uint16(189),
	1884: uint16(190),
	1885: uint16(191),
	1886: uint16(501),
	1887: uint16(451),
	1888: uint16(245),
	1889: uint16(108),
	1890: uint16(238),
	1891: uint16(401),
	1892: uint16(1428),
	1893: uint16(1427),
	1894: uint16(1430),
	1895: uint16(475),
	1896: uint16(404),
	1897: uint16(1496),
	1898: uint16(197),
	1899: uint16(565),
	1900: uint16(14),
	1901: uint16(490),
	1902: uint16(249),
	1903: uint16(101),
	1904: uint16(1518),
	1905: uint16(496),
	1906: uint16(349),
	1907: uint16(280),
	1908: uint16(251),
	1909: uint16(201),
	1910: uint16(353),
	1911: uint16(499),
	1912: uint16(252),
	1913: uint16(406),
	1914: uint16(1270),
	1915: uint16(253),
	1916: uint16(517),
	1917: uint16(1327),
	1918: uint16(1326),
	1919: uint16(435),
	1920: uint16(1325),
	1921: uint16(1318),
	1922: uint16(103),
	1923: uint16(893),
	1924: uint16(1296),
	1925: uint16(413),
	1926: uint16(227),
	1927: uint16(407),
	1928: uint16(1040),
	1929: uint16(1626),
	1930: uint16(319),
	1931: uint16(567),
	1932: uint16(1625),
	1933: uint16(1297),
	1934: uint16(119),
	1935: uint16(119),
	1936: uint16(439),
	1937: uint16(367),
	1938: uint16(1317),
	1939: uint16(1295),
	1940: uint16(1624),
	1941: uint16(526),
	1942: uint16(120),
	1943: uint16(440),
	1944: uint16(451),
	1945: uint16(577),
	1946: uint16(451),
	1947: uint16(1594),
	1948: uint16(309),
	1949: uint16(1028),
	1950: uint16(310),
	1951: uint16(373),
	1952: uint16(266),
	1953: uint16(267),
	1954: uint16(457),
	1955: uint16(1580),
	1956: uint16(1579),
	1957: uint16(443),
	1958: uint16(138),
	1959: uint16(1394),
	1960: uint16(552),
	1961: uint16(1393),
	1962: uint16(11),
	1963: uint16(1483),
	1964: uint16(384),
	1965: uint16(115),
	1966: uint16(317),
	1967: uint16(1350),
	1968: uint16(109),
	1969: uint16(536),
	1970: uint16(42),
	1971: uint16(579),
	1972: uint16(382),
	1973: uint16(214),
	1974: uint16(1349),
	1975: uint16(388),
	1976: uint16(1198),
	1977: uint16(389),
	1978: uint16(275),
	1979: uint16(277),
	1980: uint16(278),
	1981: uint16(1028),
	1982: uint16(1028),
	1983: uint16(1030),
	1984: uint16(1031),
	1985: uint16(35),
	1986: uint16(580),
	1987: uint16(1265),
	1988: uint16(414),
	1989: uint16(1260),
	1990: uint16(170),
	1991: uint16(415),
	1992: uint16(183),
	1993: uint16(1534),
	1994: uint16(1535),
	1995: uint16(1533),
	1996: uint16(171),
	1997: uint16(154),
	1998: uint16(307),
	1999: uint16(1532),
	2000: uint16(846),
	2001: uint16(223),
	2002: uint16(224),
	2003: uint16(88),
	2004: uint16(452),
	2005: uint16(215),
	2006: uint16(172),
	2007: uint16(321),
	2008: uint16(234),
	2009: uint16(1102),
	2010: uint16(152),
	2011: uint16(1188),
	2012: uint16(1100),
	2013: uint16(329),
	2014: uint16(185),
	2015: uint16(174),
	2016: uint16(1223),
	2017: uint16(925),
	2018: uint16(187),
	2019: uint16(241),
	2020: uint16(337),
	2021: uint16(244),
	2022: uint16(1116),
	2023: uint16(192),
	2024: uint16(175),
	2025: uint16(176),
	2026: uint16(424),
	2027: uint16(426),
	2028: uint16(97),
	2029: uint16(194),
	2030: uint16(98),
	2031: uint16(99),
	2032: uint16(100),
	2033: uint16(177),
	2034: uint16(1119),
	2035: uint16(1115),
	2036: uint16(246),
	2037: uint16(247),
	2038: uint16(161),
	2039: uint16(24),
	2040: uint16(248),
	2041: uint16(348),
	2042: uint16(1238),
	2043: uint16(264),
	2044: uint16(1108),
	2045: uint16(250),
	2046: uint16(495),
	2047: uint16(199),
	2048: uint16(198),
	2049: uint16(15),
	2050: uint16(861),
	2051: uint16(500),
	2052: uint16(369),
	2053: uint16(254),
	2054: uint16(504),
	2055: uint16(509),
	2056: uint16(512),
	2057: uint16(200),
	2058: uint16(102),
	2059: uint16(25),
	2060: uint16(179),
	2061: uint16(361),
	2062: uint16(26),
	2063: uint16(364),
	2064: uint16(104),
	2065: uint16(891),
	2066: uint16(308),
	2067: uint16(162),
	2068: uint16(105),
	2069: uint16(904),
	2070: uint16(520),
	2071: uint16(106),
	2072: uint16(1185),
	2073: uint16(1069),
	2074: uint16(1155),
	2075: uint16(17),
	2076: uint16(228),
	2077: uint16(27),
	2078: uint16(1154),
	2079: uint16(283),
	2080: uint16(285),
	2081: uint16(263),
	2082: uint16(978),
	2083: uint16(202),
	2084: uint16(972),
	2085: uint16(123),
	2086: uint16(28),
	2087: uint16(1175),
	2088: uint16(29),
	2089: uint16(30),
	2090: uint16(1179),
	2091: uint16(1171),
	2092: uint16(31),
	2093: uint16(1173),
	2094: uint16(1160),
	2095: uint16(41),
	2096: uint16(32),
	2097: uint16(206),
	2098: uint16(548),
	2099: uint16(33),
	2100: uint16(110),
	2101: uint16(1178),
	2102: uint16(1083),
	2103: uint16(8),
	2104: uint16(112),
	2105: uint16(1070),
	2106: uint16(113),
	2107: uint16(1068),
	2108: uint16(1072),
	2109: uint16(34),
	2110: uint16(1073),
	2111: uint16(560),
	2112: uint16(1125),
	2113: uint16(269),
	2114: uint16(1124),
	2115: uint16(270),
	2116: uint16(36),
	2117: uint16(18),
	2118: uint16(1194),
	2119: uint16(1033),
	2120: uint16(873),
	2121: uint16(151),
	2122: uint16(122),
	2123: uint16(37),
	2124: uint16(393),
	2125: uint16(271),
	2126: uint16(272),
	2127: uint16(572),
	2128: uint16(181),
	2129: uint16(1193),
	2130: uint16(1256),
	2131: uint16(1256),
	2132: uint16(1256),
	2133: uint16(935),
	2134: uint16(1256),
	2135: uint16(1256),
	2136: uint16(1256),
	2137: uint16(1256),
	2138: uint16(1256),
	2139: uint16(1256),
	2140: uint16(1256),
	2141: uint16(1617),
}
var _yy_lookahead = [2328]uint16{
	0:    uint16(194),
	1:    uint16(276),
	2:    uint16(277),
	3:    uint16(278),
	4:    uint16(216),
	5:    uint16(194),
	6:    uint16(194),
	7:    uint16(217),
	8:    uint16(194),
	9:    uint16(194),
	10:   uint16(194),
	11:   uint16(194),
	12:   uint16(224),
	13:   uint16(194),
	14:   uint16(194),
	15:   uint16(276),
	16:   uint16(277),
	17:   uint16(278),
	18:   uint16(204),
	19:   uint16(19),
	20:   uint16(206),
	21:   uint16(202),
	22:   uint16(297),
	23:   uint16(217),
	24:   uint16(218),
	25:   uint16(205),
	26:   uint16(207),
	27:   uint16(217),
	28:   uint16(205),
	29:   uint16(217),
	30:   uint16(218),
	31:   uint16(31),
	32:   uint16(217),
	33:   uint16(218),
	34:   uint16(217),
	35:   uint16(218),
	36:   uint16(29),
	37:   uint16(217),
	38:   uint16(218),
	39:   uint16(39),
	40:   uint16(33),
	41:   uint16(217),
	42:   uint16(220),
	43:   uint16(43),
	44:   uint16(44),
	45:   uint16(45),
	46:   uint16(46),
	47:   uint16(47),
	48:   uint16(48),
	49:   uint16(49),
	50:   uint16(50),
	51:   uint16(51),
	52:   uint16(52),
	53:   uint16(53),
	54:   uint16(54),
	55:   uint16(55),
	56:   uint16(56),
	57:   uint16(57),
	58:   uint16(312),
	59:   uint16(19),
	60:   uint16(240),
	61:   uint16(241),
	62:   uint16(316),
	63:   uint16(240),
	64:   uint16(241),
	65:   uint16(194),
	66:   uint16(46),
	67:   uint16(47),
	68:   uint16(48),
	69:   uint16(49),
	70:   uint16(22),
	71:   uint16(254),
	72:   uint16(65),
	73:   uint16(253),
	74:   uint16(254),
	75:   uint16(255),
	76:   uint16(253),
	77:   uint16(194),
	78:   uint16(255),
	79:   uint16(194),
	80:   uint16(263),
	81:   uint16(258),
	82:   uint16(259),
	83:   uint16(43),
	84:   uint16(44),
	85:   uint16(45),
	86:   uint16(46),
	87:   uint16(47),
	88:   uint16(48),
	89:   uint16(49),
	90:   uint16(50),
	91:   uint16(51),
	92:   uint16(52),
	93:   uint16(53),
	94:   uint16(54),
	95:   uint16(55),
	96:   uint16(56),
	97:   uint16(57),
	98:   uint16(276),
	99:   uint16(277),
	100:  uint16(278),
	101:  uint16(285),
	102:  uint16(102),
	103:  uint16(103),
	104:  uint16(104),
	105:  uint16(105),
	106:  uint16(106),
	107:  uint16(107),
	108:  uint16(108),
	109:  uint16(109),
	110:  uint16(110),
	111:  uint16(111),
	112:  uint16(112),
	113:  uint16(113),
	114:  uint16(59),
	115:  uint16(186),
	116:  uint16(187),
	117:  uint16(188),
	118:  uint16(189),
	119:  uint16(190),
	120:  uint16(191),
	121:  uint16(310),
	122:  uint16(239),
	123:  uint16(317),
	124:  uint16(318),
	125:  uint16(196),
	126:  uint16(86),
	127:  uint16(198),
	128:  uint16(88),
	129:  uint16(317),
	130:  uint16(19),
	131:  uint16(319),
	132:  uint16(317),
	133:  uint16(318),
	134:  uint16(205),
	135:  uint16(264),
	136:  uint16(25),
	137:  uint16(211),
	138:  uint16(212),
	139:  uint16(213),
	140:  uint16(205),
	141:  uint16(121),
	142:  uint16(102),
	143:  uint16(103),
	144:  uint16(104),
	145:  uint16(105),
	146:  uint16(106),
	147:  uint16(107),
	148:  uint16(108),
	149:  uint16(109),
	150:  uint16(110),
	151:  uint16(111),
	152:  uint16(112),
	153:  uint16(113),
	154:  uint16(43),
	155:  uint16(44),
	156:  uint16(45),
	157:  uint16(46),
	158:  uint16(47),
	159:  uint16(48),
	160:  uint16(49),
	161:  uint16(50),
	162:  uint16(51),
	163:  uint16(52),
	164:  uint16(53),
	165:  uint16(54),
	166:  uint16(55),
	167:  uint16(56),
	168:  uint16(57),
	169:  uint16(240),
	170:  uint16(241),
	171:  uint16(116),
	172:  uint16(117),
	173:  uint16(118),
	174:  uint16(119),
	175:  uint16(240),
	176:  uint16(241),
	177:  uint16(122),
	178:  uint16(123),
	179:  uint16(124),
	180:  uint16(69),
	181:  uint16(298),
	182:  uint16(253),
	183:  uint16(194),
	184:  uint16(255),
	185:  uint16(106),
	186:  uint16(107),
	187:  uint16(132),
	188:  uint16(253),
	189:  uint16(141),
	190:  uint16(255),
	191:  uint16(54),
	192:  uint16(55),
	193:  uint16(56),
	194:  uint16(57),
	195:  uint16(58),
	196:  uint16(207),
	197:  uint16(268),
	198:  uint16(102),
	199:  uint16(103),
	200:  uint16(104),
	201:  uint16(105),
	202:  uint16(106),
	203:  uint16(107),
	204:  uint16(108),
	205:  uint16(109),
	206:  uint16(110),
	207:  uint16(111),
	208:  uint16(112),
	209:  uint16(113),
	210:  uint16(214),
	211:  uint16(128),
	212:  uint16(129),
	213:  uint16(102),
	214:  uint16(103),
	215:  uint16(104),
	216:  uint16(105),
	217:  uint16(106),
	218:  uint16(107),
	219:  uint16(108),
	220:  uint16(109),
	221:  uint16(110),
	222:  uint16(111),
	223:  uint16(112),
	224:  uint16(113),
	225:  uint16(134),
	226:  uint16(25),
	227:  uint16(136),
	228:  uint16(137),
	229:  uint16(300),
	230:  uint16(165),
	231:  uint16(166),
	232:  uint16(153),
	233:  uint16(19),
	234:  uint16(155),
	235:  uint16(54),
	236:  uint16(55),
	237:  uint16(56),
	238:  uint16(57),
	239:  uint16(102),
	240:  uint16(103),
	241:  uint16(104),
	242:  uint16(105),
	243:  uint16(106),
	244:  uint16(107),
	245:  uint16(108),
	246:  uint16(109),
	247:  uint16(110),
	248:  uint16(111),
	249:  uint16(112),
	250:  uint16(113),
	251:  uint16(108),
	252:  uint16(109),
	253:  uint16(110),
	254:  uint16(111),
	255:  uint16(112),
	256:  uint16(113),
	257:  uint16(43),
	258:  uint16(44),
	259:  uint16(45),
	260:  uint16(46),
	261:  uint16(47),
	262:  uint16(48),
	263:  uint16(49),
	264:  uint16(50),
	265:  uint16(51),
	266:  uint16(52),
	267:  uint16(53),
	268:  uint16(54),
	269:  uint16(55),
	270:  uint16(56),
	271:  uint16(57),
	272:  uint16(276),
	273:  uint16(277),
	274:  uint16(278),
	275:  uint16(113),
	276:  uint16(194),
	277:  uint16(19),
	278:  uint16(22),
	279:  uint16(23),
	280:  uint16(194),
	281:  uint16(67),
	282:  uint16(24),
	283:  uint16(102),
	284:  uint16(103),
	285:  uint16(104),
	286:  uint16(105),
	287:  uint16(106),
	288:  uint16(107),
	289:  uint16(108),
	290:  uint16(109),
	291:  uint16(110),
	292:  uint16(111),
	293:  uint16(112),
	294:  uint16(113),
	295:  uint16(220),
	296:  uint16(250),
	297:  uint16(59),
	298:  uint16(252),
	299:  uint16(217),
	300:  uint16(218),
	301:  uint16(43),
	302:  uint16(44),
	303:  uint16(45),
	304:  uint16(46),
	305:  uint16(47),
	306:  uint16(48),
	307:  uint16(49),
	308:  uint16(50),
	309:  uint16(51),
	310:  uint16(52),
	311:  uint16(53),
	312:  uint16(54),
	313:  uint16(55),
	314:  uint16(56),
	315:  uint16(57),
	316:  uint16(102),
	317:  uint16(103),
	318:  uint16(104),
	319:  uint16(105),
	320:  uint16(106),
	321:  uint16(107),
	322:  uint16(108),
	323:  uint16(109),
	324:  uint16(110),
	325:  uint16(111),
	326:  uint16(112),
	327:  uint16(113),
	328:  uint16(106),
	329:  uint16(107),
	330:  uint16(108),
	331:  uint16(109),
	332:  uint16(110),
	333:  uint16(111),
	334:  uint16(112),
	335:  uint16(113),
	336:  uint16(254),
	337:  uint16(59),
	338:  uint16(205),
	339:  uint16(138),
	340:  uint16(139),
	341:  uint16(19),
	342:  uint16(20),
	343:  uint16(194),
	344:  uint16(22),
	345:  uint16(263),
	346:  uint16(22),
	347:  uint16(23),
	348:  uint16(231),
	349:  uint16(25),
	350:  uint16(72),
	351:  uint16(276),
	352:  uint16(277),
	353:  uint16(278),
	354:  uint16(116),
	355:  uint16(117),
	356:  uint16(118),
	357:  uint16(101),
	358:  uint16(36),
	359:  uint16(76),
	360:  uint16(102),
	361:  uint16(103),
	362:  uint16(104),
	363:  uint16(105),
	364:  uint16(106),
	365:  uint16(107),
	366:  uint16(108),
	367:  uint16(109),
	368:  uint16(110),
	369:  uint16(111),
	370:  uint16(112),
	371:  uint16(113),
	372:  uint16(89),
	373:  uint16(240),
	374:  uint16(241),
	375:  uint16(92),
	376:  uint16(73),
	377:  uint16(194),
	378:  uint16(194),
	379:  uint16(73),
	380:  uint16(19),
	381:  uint16(59),
	382:  uint16(188),
	383:  uint16(189),
	384:  uint16(190),
	385:  uint16(191),
	386:  uint16(253),
	387:  uint16(81),
	388:  uint16(255),
	389:  uint16(151),
	390:  uint16(196),
	391:  uint16(25),
	392:  uint16(198),
	393:  uint16(71),
	394:  uint16(116),
	395:  uint16(117),
	396:  uint16(118),
	397:  uint16(311),
	398:  uint16(312),
	399:  uint16(205),
	400:  uint16(217),
	401:  uint16(218),
	402:  uint16(316),
	403:  uint16(81),
	404:  uint16(43),
	405:  uint16(44),
	406:  uint16(45),
	407:  uint16(46),
	408:  uint16(47),
	409:  uint16(48),
	410:  uint16(49),
	411:  uint16(50),
	412:  uint16(51),
	413:  uint16(52),
	414:  uint16(53),
	415:  uint16(54),
	416:  uint16(55),
	417:  uint16(56),
	418:  uint16(57),
	419:  uint16(270),
	420:  uint16(22),
	421:  uint16(23),
	422:  uint16(100),
	423:  uint16(25),
	424:  uint16(59),
	425:  uint16(101),
	426:  uint16(138),
	427:  uint16(139),
	428:  uint16(106),
	429:  uint16(107),
	430:  uint16(127),
	431:  uint16(128),
	432:  uint16(129),
	433:  uint16(127),
	434:  uint16(240),
	435:  uint16(241),
	436:  uint16(114),
	437:  uint16(254),
	438:  uint16(116),
	439:  uint16(117),
	440:  uint16(118),
	441:  uint16(76),
	442:  uint16(76),
	443:  uint16(121),
	444:  uint16(138),
	445:  uint16(139),
	446:  uint16(263),
	447:  uint16(253),
	448:  uint16(264),
	449:  uint16(255),
	450:  uint16(205),
	451:  uint16(275),
	452:  uint16(87),
	453:  uint16(19),
	454:  uint16(89),
	455:  uint16(89),
	456:  uint16(194),
	457:  uint16(92),
	458:  uint16(92),
	459:  uint16(199),
	460:  uint16(138),
	461:  uint16(139),
	462:  uint16(268),
	463:  uint16(102),
	464:  uint16(103),
	465:  uint16(104),
	466:  uint16(105),
	467:  uint16(106),
	468:  uint16(107),
	469:  uint16(108),
	470:  uint16(109),
	471:  uint16(110),
	472:  uint16(111),
	473:  uint16(112),
	474:  uint16(113),
	475:  uint16(153),
	476:  uint16(154),
	477:  uint16(155),
	478:  uint16(156),
	479:  uint16(157),
	480:  uint16(81),
	481:  uint16(116),
	482:  uint16(117),
	483:  uint16(118),
	484:  uint16(129),
	485:  uint16(240),
	486:  uint16(241),
	487:  uint16(224),
	488:  uint16(19),
	489:  uint16(226),
	490:  uint16(314),
	491:  uint16(315),
	492:  uint16(23),
	493:  uint16(25),
	494:  uint16(300),
	495:  uint16(59),
	496:  uint16(22),
	497:  uint16(234),
	498:  uint16(253),
	499:  uint16(101),
	500:  uint16(255),
	501:  uint16(236),
	502:  uint16(237),
	503:  uint16(26),
	504:  uint16(194),
	505:  uint16(183),
	506:  uint16(194),
	507:  uint16(152),
	508:  uint16(72),
	509:  uint16(22),
	510:  uint16(145),
	511:  uint16(150),
	512:  uint16(43),
	513:  uint16(44),
	514:  uint16(45),
	515:  uint16(46),
	516:  uint16(47),
	517:  uint16(48),
	518:  uint16(49),
	519:  uint16(50),
	520:  uint16(51),
	521:  uint16(52),
	522:  uint16(53),
	523:  uint16(54),
	524:  uint16(55),
	525:  uint16(56),
	526:  uint16(57),
	527:  uint16(217),
	528:  uint16(218),
	529:  uint16(217),
	530:  uint16(218),
	531:  uint16(19),
	532:  uint16(189),
	533:  uint16(59),
	534:  uint16(191),
	535:  uint16(23),
	536:  uint16(59),
	537:  uint16(138),
	538:  uint16(139),
	539:  uint16(196),
	540:  uint16(135),
	541:  uint16(198),
	542:  uint16(232),
	543:  uint16(283),
	544:  uint16(232),
	545:  uint16(140),
	546:  uint16(59),
	547:  uint16(287),
	548:  uint16(205),
	549:  uint16(275),
	550:  uint16(116),
	551:  uint16(205),
	552:  uint16(116),
	553:  uint16(117),
	554:  uint16(118),
	555:  uint16(43),
	556:  uint16(44),
	557:  uint16(45),
	558:  uint16(46),
	559:  uint16(47),
	560:  uint16(48),
	561:  uint16(49),
	562:  uint16(50),
	563:  uint16(51),
	564:  uint16(52),
	565:  uint16(53),
	566:  uint16(54),
	567:  uint16(55),
	568:  uint16(56),
	569:  uint16(57),
	570:  uint16(194),
	571:  uint16(102),
	572:  uint16(103),
	573:  uint16(104),
	574:  uint16(105),
	575:  uint16(106),
	576:  uint16(107),
	577:  uint16(108),
	578:  uint16(109),
	579:  uint16(110),
	580:  uint16(111),
	581:  uint16(112),
	582:  uint16(113),
	583:  uint16(240),
	584:  uint16(241),
	585:  uint16(194),
	586:  uint16(240),
	587:  uint16(241),
	588:  uint16(314),
	589:  uint16(315),
	590:  uint16(116),
	591:  uint16(117),
	592:  uint16(118),
	593:  uint16(116),
	594:  uint16(117),
	595:  uint16(118),
	596:  uint16(253),
	597:  uint16(194),
	598:  uint16(255),
	599:  uint16(253),
	600:  uint16(59),
	601:  uint16(255),
	602:  uint16(19),
	603:  uint16(116),
	604:  uint16(117),
	605:  uint16(118),
	606:  uint16(23),
	607:  uint16(22),
	608:  uint16(217),
	609:  uint16(218),
	610:  uint16(142),
	611:  uint16(268),
	612:  uint16(205),
	613:  uint16(275),
	614:  uint16(102),
	615:  uint16(103),
	616:  uint16(104),
	617:  uint16(105),
	618:  uint16(106),
	619:  uint16(107),
	620:  uint16(108),
	621:  uint16(109),
	622:  uint16(110),
	623:  uint16(111),
	624:  uint16(112),
	625:  uint16(113),
	626:  uint16(43),
	627:  uint16(44),
	628:  uint16(45),
	629:  uint16(46),
	630:  uint16(47),
	631:  uint16(48),
	632:  uint16(49),
	633:  uint16(50),
	634:  uint16(51),
	635:  uint16(52),
	636:  uint16(53),
	637:  uint16(54),
	638:  uint16(55),
	639:  uint16(56),
	640:  uint16(57),
	641:  uint16(19),
	642:  uint16(194),
	643:  uint16(300),
	644:  uint16(59),
	645:  uint16(23),
	646:  uint16(119),
	647:  uint16(240),
	648:  uint16(241),
	649:  uint16(122),
	650:  uint16(123),
	651:  uint16(124),
	652:  uint16(314),
	653:  uint16(315),
	654:  uint16(194),
	655:  uint16(236),
	656:  uint16(237),
	657:  uint16(194),
	658:  uint16(117),
	659:  uint16(132),
	660:  uint16(253),
	661:  uint16(81),
	662:  uint16(255),
	663:  uint16(205),
	664:  uint16(59),
	665:  uint16(43),
	666:  uint16(44),
	667:  uint16(45),
	668:  uint16(46),
	669:  uint16(47),
	670:  uint16(48),
	671:  uint16(49),
	672:  uint16(50),
	673:  uint16(51),
	674:  uint16(52),
	675:  uint16(53),
	676:  uint16(54),
	677:  uint16(55),
	678:  uint16(56),
	679:  uint16(57),
	680:  uint16(217),
	681:  uint16(218),
	682:  uint16(194),
	683:  uint16(194),
	684:  uint16(194),
	685:  uint16(102),
	686:  uint16(103),
	687:  uint16(104),
	688:  uint16(105),
	689:  uint16(106),
	690:  uint16(107),
	691:  uint16(108),
	692:  uint16(109),
	693:  uint16(110),
	694:  uint16(111),
	695:  uint16(112),
	696:  uint16(113),
	697:  uint16(294),
	698:  uint16(240),
	699:  uint16(241),
	700:  uint16(120),
	701:  uint16(116),
	702:  uint16(117),
	703:  uint16(118),
	704:  uint16(59),
	705:  uint16(194),
	706:  uint16(217),
	707:  uint16(218),
	708:  uint16(211),
	709:  uint16(212),
	710:  uint16(213),
	711:  uint16(253),
	712:  uint16(19),
	713:  uint16(255),
	714:  uint16(194),
	715:  uint16(19),
	716:  uint16(23),
	717:  uint16(254),
	718:  uint16(138),
	719:  uint16(139),
	720:  uint16(24),
	721:  uint16(232),
	722:  uint16(117),
	723:  uint16(194),
	724:  uint16(102),
	725:  uint16(103),
	726:  uint16(104),
	727:  uint16(105),
	728:  uint16(106),
	729:  uint16(107),
	730:  uint16(108),
	731:  uint16(109),
	732:  uint16(110),
	733:  uint16(111),
	734:  uint16(112),
	735:  uint16(113),
	736:  uint16(43),
	737:  uint16(44),
	738:  uint16(45),
	739:  uint16(46),
	740:  uint16(47),
	741:  uint16(48),
	742:  uint16(49),
	743:  uint16(50),
	744:  uint16(51),
	745:  uint16(52),
	746:  uint16(53),
	747:  uint16(54),
	748:  uint16(55),
	749:  uint16(56),
	750:  uint16(57),
	751:  uint16(19),
	752:  uint16(264),
	753:  uint16(108),
	754:  uint16(76),
	755:  uint16(23),
	756:  uint16(127),
	757:  uint16(128),
	758:  uint16(129),
	759:  uint16(311),
	760:  uint16(312),
	761:  uint16(116),
	762:  uint16(117),
	763:  uint16(118),
	764:  uint16(316),
	765:  uint16(87),
	766:  uint16(306),
	767:  uint16(89),
	768:  uint16(308),
	769:  uint16(194),
	770:  uint16(92),
	771:  uint16(22),
	772:  uint16(59),
	773:  uint16(194),
	774:  uint16(22),
	775:  uint16(43),
	776:  uint16(44),
	777:  uint16(45),
	778:  uint16(46),
	779:  uint16(47),
	780:  uint16(48),
	781:  uint16(49),
	782:  uint16(50),
	783:  uint16(51),
	784:  uint16(52),
	785:  uint16(53),
	786:  uint16(54),
	787:  uint16(55),
	788:  uint16(56),
	789:  uint16(57),
	790:  uint16(194),
	791:  uint16(95),
	792:  uint16(217),
	793:  uint16(218),
	794:  uint16(265),
	795:  uint16(102),
	796:  uint16(103),
	797:  uint16(104),
	798:  uint16(105),
	799:  uint16(106),
	800:  uint16(107),
	801:  uint16(108),
	802:  uint16(109),
	803:  uint16(110),
	804:  uint16(111),
	805:  uint16(112),
	806:  uint16(113),
	807:  uint16(232),
	808:  uint16(59),
	809:  uint16(113),
	810:  uint16(25),
	811:  uint16(59),
	812:  uint16(194),
	813:  uint16(217),
	814:  uint16(218),
	815:  uint16(119),
	816:  uint16(120),
	817:  uint16(121),
	818:  uint16(122),
	819:  uint16(123),
	820:  uint16(124),
	821:  uint16(125),
	822:  uint16(19),
	823:  uint16(145),
	824:  uint16(194),
	825:  uint16(194),
	826:  uint16(23),
	827:  uint16(131),
	828:  uint16(232),
	829:  uint16(116),
	830:  uint16(117),
	831:  uint16(118),
	832:  uint16(35),
	833:  uint16(194),
	834:  uint16(102),
	835:  uint16(103),
	836:  uint16(104),
	837:  uint16(105),
	838:  uint16(106),
	839:  uint16(107),
	840:  uint16(108),
	841:  uint16(109),
	842:  uint16(110),
	843:  uint16(111),
	844:  uint16(112),
	845:  uint16(113),
	846:  uint16(43),
	847:  uint16(44),
	848:  uint16(45),
	849:  uint16(46),
	850:  uint16(47),
	851:  uint16(48),
	852:  uint16(49),
	853:  uint16(50),
	854:  uint16(51),
	855:  uint16(52),
	856:  uint16(53),
	857:  uint16(54),
	858:  uint16(55),
	859:  uint16(56),
	860:  uint16(57),
	861:  uint16(19),
	862:  uint16(194),
	863:  uint16(66),
	864:  uint16(194),
	865:  uint16(116),
	866:  uint16(117),
	867:  uint16(118),
	868:  uint16(116),
	869:  uint16(117),
	870:  uint16(118),
	871:  uint16(74),
	872:  uint16(242),
	873:  uint16(294),
	874:  uint16(194),
	875:  uint16(194),
	876:  uint16(206),
	877:  uint16(23),
	878:  uint16(194),
	879:  uint16(25),
	880:  uint16(194),
	881:  uint16(111),
	882:  uint16(112),
	883:  uint16(113),
	884:  uint16(25),
	885:  uint16(43),
	886:  uint16(44),
	887:  uint16(45),
	888:  uint16(46),
	889:  uint16(47),
	890:  uint16(48),
	891:  uint16(49),
	892:  uint16(50),
	893:  uint16(51),
	894:  uint16(52),
	895:  uint16(53),
	896:  uint16(54),
	897:  uint16(55),
	898:  uint16(56),
	899:  uint16(57),
	900:  uint16(24),
	901:  uint16(194),
	902:  uint16(194),
	903:  uint16(217),
	904:  uint16(218),
	905:  uint16(102),
	906:  uint16(103),
	907:  uint16(104),
	908:  uint16(105),
	909:  uint16(106),
	910:  uint16(107),
	911:  uint16(108),
	912:  uint16(109),
	913:  uint16(110),
	914:  uint16(111),
	915:  uint16(112),
	916:  uint16(113),
	917:  uint16(241),
	918:  uint16(232),
	919:  uint16(194),
	920:  uint16(212),
	921:  uint16(213),
	922:  uint16(242),
	923:  uint16(242),
	924:  uint16(217),
	925:  uint16(218),
	926:  uint16(242),
	927:  uint16(130),
	928:  uint16(11),
	929:  uint16(253),
	930:  uint16(194),
	931:  uint16(255),
	932:  uint16(19),
	933:  uint16(265),
	934:  uint16(149),
	935:  uint16(59),
	936:  uint16(306),
	937:  uint16(194),
	938:  uint16(308),
	939:  uint16(232),
	940:  uint16(309),
	941:  uint16(310),
	942:  uint16(217),
	943:  uint16(218),
	944:  uint16(102),
	945:  uint16(103),
	946:  uint16(104),
	947:  uint16(105),
	948:  uint16(106),
	949:  uint16(107),
	950:  uint16(108),
	951:  uint16(109),
	952:  uint16(110),
	953:  uint16(111),
	954:  uint16(112),
	955:  uint16(113),
	956:  uint16(43),
	957:  uint16(44),
	958:  uint16(45),
	959:  uint16(46),
	960:  uint16(47),
	961:  uint16(48),
	962:  uint16(49),
	963:  uint16(50),
	964:  uint16(51),
	965:  uint16(52),
	966:  uint16(53),
	967:  uint16(54),
	968:  uint16(55),
	969:  uint16(56),
	970:  uint16(57),
	971:  uint16(194),
	972:  uint16(194),
	973:  uint16(59),
	974:  uint16(194),
	975:  uint16(239),
	976:  uint16(19),
	977:  uint16(194),
	978:  uint16(25),
	979:  uint16(254),
	980:  uint16(303),
	981:  uint16(304),
	982:  uint16(23),
	983:  uint16(194),
	984:  uint16(25),
	985:  uint16(126),
	986:  uint16(306),
	987:  uint16(306),
	988:  uint16(308),
	989:  uint16(308),
	990:  uint16(306),
	991:  uint16(271),
	992:  uint16(308),
	993:  uint16(117),
	994:  uint16(286),
	995:  uint16(217),
	996:  uint16(218),
	997:  uint16(217),
	998:  uint16(218),
	999:  uint16(194),
	1000: uint16(194),
	1001: uint16(159),
	1002: uint16(45),
	1003: uint16(46),
	1004: uint16(47),
	1005: uint16(48),
	1006: uint16(49),
	1007: uint16(50),
	1008: uint16(51),
	1009: uint16(52),
	1010: uint16(53),
	1011: uint16(54),
	1012: uint16(55),
	1013: uint16(56),
	1014: uint16(57),
	1015: uint16(102),
	1016: uint16(103),
	1017: uint16(104),
	1018: uint16(105),
	1019: uint16(106),
	1020: uint16(107),
	1021: uint16(108),
	1022: uint16(109),
	1023: uint16(110),
	1024: uint16(111),
	1025: uint16(112),
	1026: uint16(113),
	1027: uint16(59),
	1028: uint16(239),
	1029: uint16(194),
	1030: uint16(116),
	1031: uint16(117),
	1032: uint16(118),
	1033: uint16(260),
	1034: uint16(254),
	1035: uint16(194),
	1036: uint16(240),
	1037: uint16(241),
	1038: uint16(194),
	1039: uint16(233),
	1040: uint16(205),
	1041: uint16(240),
	1042: uint16(241),
	1043: uint16(205),
	1044: uint16(239),
	1045: uint16(128),
	1046: uint16(129),
	1047: uint16(270),
	1048: uint16(265),
	1049: uint16(253),
	1050: uint16(194),
	1051: uint16(255),
	1052: uint16(217),
	1053: uint16(218),
	1054: uint16(253),
	1055: uint16(194),
	1056: uint16(255),
	1057: uint16(143),
	1058: uint16(280),
	1059: uint16(102),
	1060: uint16(103),
	1061: uint16(104),
	1062: uint16(105),
	1063: uint16(106),
	1064: uint16(107),
	1065: uint16(108),
	1066: uint16(109),
	1067: uint16(110),
	1068: uint16(111),
	1069: uint16(112),
	1070: uint16(113),
	1071: uint16(118),
	1072: uint16(159),
	1073: uint16(217),
	1074: uint16(218),
	1075: uint16(240),
	1076: uint16(241),
	1077: uint16(118),
	1078: uint16(240),
	1079: uint16(241),
	1080: uint16(194),
	1081: uint16(194),
	1082: uint16(194),
	1083: uint16(239),
	1084: uint16(116),
	1085: uint16(117),
	1086: uint16(118),
	1087: uint16(22),
	1088: uint16(253),
	1089: uint16(254),
	1090: uint16(255),
	1091: uint16(253),
	1092: uint16(19),
	1093: uint16(255),
	1094: uint16(233),
	1095: uint16(194),
	1096: uint16(143),
	1097: uint16(24),
	1098: uint16(263),
	1099: uint16(212),
	1100: uint16(213),
	1101: uint16(194),
	1102: uint16(143),
	1103: uint16(217),
	1104: uint16(218),
	1105: uint16(217),
	1106: uint16(218),
	1107: uint16(261),
	1108: uint16(262),
	1109: uint16(271),
	1110: uint16(254),
	1111: uint16(143),
	1112: uint16(19),
	1113: uint16(7),
	1114: uint16(8),
	1115: uint16(9),
	1116: uint16(43),
	1117: uint16(44),
	1118: uint16(45),
	1119: uint16(46),
	1120: uint16(47),
	1121: uint16(48),
	1122: uint16(49),
	1123: uint16(50),
	1124: uint16(51),
	1125: uint16(52),
	1126: uint16(53),
	1127: uint16(54),
	1128: uint16(55),
	1129: uint16(56),
	1130: uint16(57),
	1131: uint16(16),
	1132: uint16(19),
	1133: uint16(22),
	1134: uint16(23),
	1135: uint16(294),
	1136: uint16(43),
	1137: uint16(44),
	1138: uint16(45),
	1139: uint16(46),
	1140: uint16(47),
	1141: uint16(48),
	1142: uint16(49),
	1143: uint16(50),
	1144: uint16(51),
	1145: uint16(52),
	1146: uint16(53),
	1147: uint16(54),
	1148: uint16(55),
	1149: uint16(56),
	1150: uint16(57),
	1151: uint16(312),
	1152: uint16(194),
	1153: uint16(214),
	1154: uint16(21),
	1155: uint16(316),
	1156: uint16(43),
	1157: uint16(44),
	1158: uint16(45),
	1159: uint16(46),
	1160: uint16(47),
	1161: uint16(48),
	1162: uint16(49),
	1163: uint16(50),
	1164: uint16(51),
	1165: uint16(52),
	1166: uint16(53),
	1167: uint16(54),
	1168: uint16(55),
	1169: uint16(56),
	1170: uint16(57),
	1171: uint16(106),
	1172: uint16(107),
	1173: uint16(286),
	1174: uint16(194),
	1175: uint16(102),
	1176: uint16(103),
	1177: uint16(104),
	1178: uint16(105),
	1179: uint16(106),
	1180: uint16(107),
	1181: uint16(108),
	1182: uint16(109),
	1183: uint16(110),
	1184: uint16(111),
	1185: uint16(112),
	1186: uint16(113),
	1187: uint16(207),
	1188: uint16(158),
	1189: uint16(59),
	1190: uint16(160),
	1191: uint16(22),
	1192: uint16(77),
	1193: uint16(24),
	1194: uint16(79),
	1195: uint16(102),
	1196: uint16(103),
	1197: uint16(104),
	1198: uint16(105),
	1199: uint16(106),
	1200: uint16(107),
	1201: uint16(108),
	1202: uint16(109),
	1203: uint16(110),
	1204: uint16(111),
	1205: uint16(112),
	1206: uint16(113),
	1207: uint16(194),
	1208: uint16(194),
	1209: uint16(229),
	1210: uint16(194),
	1211: uint16(231),
	1212: uint16(101),
	1213: uint16(80),
	1214: uint16(22),
	1215: uint16(102),
	1216: uint16(103),
	1217: uint16(104),
	1218: uint16(105),
	1219: uint16(106),
	1220: uint16(107),
	1221: uint16(108),
	1222: uint16(109),
	1223: uint16(110),
	1224: uint16(111),
	1225: uint16(112),
	1226: uint16(113),
	1227: uint16(288),
	1228: uint16(59),
	1229: uint16(12),
	1230: uint16(217),
	1231: uint16(218),
	1232: uint16(293),
	1233: uint16(217),
	1234: uint16(218),
	1235: uint16(19),
	1236: uint16(106),
	1237: uint16(107),
	1238: uint16(59),
	1239: uint16(19),
	1240: uint16(16),
	1241: uint16(127),
	1242: uint16(128),
	1243: uint16(129),
	1244: uint16(27),
	1245: uint16(115),
	1246: uint16(116),
	1247: uint16(117),
	1248: uint16(118),
	1249: uint16(194),
	1250: uint16(120),
	1251: uint16(59),
	1252: uint16(22),
	1253: uint16(194),
	1254: uint16(24),
	1255: uint16(194),
	1256: uint16(123),
	1257: uint16(100),
	1258: uint16(128),
	1259: uint16(42),
	1260: uint16(44),
	1261: uint16(45),
	1262: uint16(46),
	1263: uint16(47),
	1264: uint16(48),
	1265: uint16(49),
	1266: uint16(50),
	1267: uint16(51),
	1268: uint16(52),
	1269: uint16(53),
	1270: uint16(54),
	1271: uint16(55),
	1272: uint16(56),
	1273: uint16(57),
	1274: uint16(117),
	1275: uint16(194),
	1276: uint16(217),
	1277: uint16(218),
	1278: uint16(121),
	1279: uint16(100),
	1280: uint16(63),
	1281: uint16(194),
	1282: uint16(245),
	1283: uint16(153),
	1284: uint16(194),
	1285: uint16(155),
	1286: uint16(117),
	1287: uint16(19),
	1288: uint16(115),
	1289: uint16(194),
	1290: uint16(73),
	1291: uint16(214),
	1292: uint16(194),
	1293: uint16(256),
	1294: uint16(161),
	1295: uint16(116),
	1296: uint16(117),
	1297: uint16(194),
	1298: uint16(217),
	1299: uint16(218),
	1300: uint16(121),
	1301: uint16(77),
	1302: uint16(194),
	1303: uint16(79),
	1304: uint16(217),
	1305: uint16(218),
	1306: uint16(194),
	1307: uint16(217),
	1308: uint16(218),
	1309: uint16(117),
	1310: uint16(153),
	1311: uint16(154),
	1312: uint16(155),
	1313: uint16(254),
	1314: uint16(46),
	1315: uint16(217),
	1316: uint16(218),
	1317: uint16(144),
	1318: uint16(102),
	1319: uint16(103),
	1320: uint16(104),
	1321: uint16(105),
	1322: uint16(106),
	1323: uint16(107),
	1324: uint16(108),
	1325: uint16(109),
	1326: uint16(110),
	1327: uint16(111),
	1328: uint16(112),
	1329: uint16(113),
	1330: uint16(232),
	1331: uint16(270),
	1332: uint16(153),
	1333: uint16(154),
	1334: uint16(155),
	1335: uint16(115),
	1336: uint16(116),
	1337: uint16(66),
	1338: uint16(19),
	1339: uint16(20),
	1340: uint16(183),
	1341: uint16(22),
	1342: uint16(12),
	1343: uint16(312),
	1344: uint16(254),
	1345: uint16(194),
	1346: uint16(262),
	1347: uint16(316),
	1348: uint16(209),
	1349: uint16(210),
	1350: uint16(266),
	1351: uint16(239),
	1352: uint16(194),
	1353: uint16(194),
	1354: uint16(108),
	1355: uint16(36),
	1356: uint16(85),
	1357: uint16(27),
	1358: uint16(19),
	1359: uint16(20),
	1360: uint16(265),
	1361: uint16(22),
	1362: uint16(183),
	1363: uint16(245),
	1364: uint16(144),
	1365: uint16(94),
	1366: uint16(25),
	1367: uint16(48),
	1368: uint16(217),
	1369: uint16(218),
	1370: uint16(293),
	1371: uint16(194),
	1372: uint16(42),
	1373: uint16(270),
	1374: uint16(256),
	1375: uint16(36),
	1376: uint16(217),
	1377: uint16(218),
	1378: uint16(59),
	1379: uint16(194),
	1380: uint16(25),
	1381: uint16(135),
	1382: uint16(194),
	1383: uint16(115),
	1384: uint16(194),
	1385: uint16(161),
	1386: uint16(140),
	1387: uint16(194),
	1388: uint16(194),
	1389: uint16(15),
	1390: uint16(71),
	1391: uint16(194),
	1392: uint16(312),
	1393: uint16(63),
	1394: uint16(217),
	1395: uint16(218),
	1396: uint16(316),
	1397: uint16(194),
	1398: uint16(59),
	1399: uint16(131),
	1400: uint16(301),
	1401: uint16(302),
	1402: uint16(217),
	1403: uint16(218),
	1404: uint16(85),
	1405: uint16(217),
	1406: uint16(218),
	1407: uint16(217),
	1408: uint16(218),
	1409: uint16(90),
	1410: uint16(71),
	1411: uint16(217),
	1412: uint16(218),
	1413: uint16(19),
	1414: uint16(217),
	1415: uint16(218),
	1416: uint16(245),
	1417: uint16(146),
	1418: uint16(262),
	1419: uint16(100),
	1420: uint16(217),
	1421: uint16(218),
	1422: uint16(266),
	1423: uint16(265),
	1424: uint16(85),
	1425: uint16(106),
	1426: uint16(107),
	1427: uint16(256),
	1428: uint16(312),
	1429: uint16(90),
	1430: uint16(209),
	1431: uint16(210),
	1432: uint16(316),
	1433: uint16(114),
	1434: uint16(60),
	1435: uint16(116),
	1436: uint16(117),
	1437: uint16(118),
	1438: uint16(194),
	1439: uint16(100),
	1440: uint16(121),
	1441: uint16(194),
	1442: uint16(194),
	1443: uint16(145),
	1444: uint16(115),
	1445: uint16(106),
	1446: uint16(107),
	1447: uint16(19),
	1448: uint16(46),
	1449: uint16(19),
	1450: uint16(20),
	1451: uint16(24),
	1452: uint16(22),
	1453: uint16(114),
	1454: uint16(194),
	1455: uint16(116),
	1456: uint16(117),
	1457: uint16(118),
	1458: uint16(194),
	1459: uint16(245),
	1460: uint16(121),
	1461: uint16(194),
	1462: uint16(164),
	1463: uint16(194),
	1464: uint16(217),
	1465: uint16(218),
	1466: uint16(36),
	1467: uint16(194),
	1468: uint16(258),
	1469: uint16(259),
	1470: uint16(256),
	1471: uint16(194),
	1472: uint16(153),
	1473: uint16(154),
	1474: uint16(155),
	1475: uint16(156),
	1476: uint16(157),
	1477: uint16(217),
	1478: uint16(218),
	1479: uint16(150),
	1480: uint16(31),
	1481: uint16(217),
	1482: uint16(218),
	1483: uint16(142),
	1484: uint16(217),
	1485: uint16(218),
	1486: uint16(217),
	1487: uint16(218),
	1488: uint16(39),
	1489: uint16(59),
	1490: uint16(217),
	1491: uint16(218),
	1492: uint16(153),
	1493: uint16(154),
	1494: uint16(155),
	1495: uint16(156),
	1496: uint16(157),
	1497: uint16(149),
	1498: uint16(150),
	1499: uint16(5),
	1500: uint16(145),
	1501: uint16(71),
	1502: uint16(183),
	1503: uint16(245),
	1504: uint16(10),
	1505: uint16(11),
	1506: uint16(12),
	1507: uint16(13),
	1508: uint16(14),
	1509: uint16(194),
	1510: uint16(116),
	1511: uint16(17),
	1512: uint16(129),
	1513: uint16(227),
	1514: uint16(256),
	1515: uint16(85),
	1516: uint16(194),
	1517: uint16(115),
	1518: uint16(194),
	1519: uint16(23),
	1520: uint16(90),
	1521: uint16(25),
	1522: uint16(183),
	1523: uint16(99),
	1524: uint16(30),
	1525: uint16(97),
	1526: uint16(32),
	1527: uint16(22),
	1528: uint16(22),
	1529: uint16(194),
	1530: uint16(100),
	1531: uint16(194),
	1532: uint16(217),
	1533: uint16(218),
	1534: uint16(40),
	1535: uint16(152),
	1536: uint16(106),
	1537: uint16(107),
	1538: uint16(23),
	1539: uint16(217),
	1540: uint16(218),
	1541: uint16(194),
	1542: uint16(19),
	1543: uint16(20),
	1544: uint16(114),
	1545: uint16(22),
	1546: uint16(116),
	1547: uint16(117),
	1548: uint16(118),
	1549: uint16(257),
	1550: uint16(194),
	1551: uint16(121),
	1552: uint16(217),
	1553: uint16(218),
	1554: uint16(217),
	1555: uint16(218),
	1556: uint16(194),
	1557: uint16(133),
	1558: uint16(53),
	1559: uint16(36),
	1560: uint16(23),
	1561: uint16(23),
	1562: uint16(25),
	1563: uint16(25),
	1564: uint16(70),
	1565: uint16(120),
	1566: uint16(121),
	1567: uint16(61),
	1568: uint16(141),
	1569: uint16(7),
	1570: uint16(8),
	1571: uint16(121),
	1572: uint16(78),
	1573: uint16(217),
	1574: uint16(218),
	1575: uint16(81),
	1576: uint16(23),
	1577: uint16(227),
	1578: uint16(25),
	1579: uint16(217),
	1580: uint16(218),
	1581: uint16(131),
	1582: uint16(59),
	1583: uint16(153),
	1584: uint16(154),
	1585: uint16(155),
	1586: uint16(156),
	1587: uint16(157),
	1589: uint16(1),
	1590: uint16(2),
	1591: uint16(59),
	1592: uint16(98),
	1593: uint16(5),
	1594: uint16(71),
	1595: uint16(23),
	1596: uint16(227),
	1597: uint16(25),
	1598: uint16(10),
	1599: uint16(11),
	1600: uint16(12),
	1601: uint16(13),
	1602: uint16(14),
	1603: uint16(83),
	1604: uint16(84),
	1605: uint16(17),
	1606: uint16(23),
	1607: uint16(23),
	1608: uint16(25),
	1609: uint16(25),
	1610: uint16(59),
	1611: uint16(194),
	1612: uint16(194),
	1613: uint16(183),
	1614: uint16(23),
	1615: uint16(23),
	1616: uint16(25),
	1617: uint16(25),
	1618: uint16(30),
	1619: uint16(194),
	1620: uint16(32),
	1621: uint16(19),
	1622: uint16(20),
	1623: uint16(100),
	1624: uint16(22),
	1625: uint16(194),
	1626: uint16(194),
	1627: uint16(133),
	1628: uint16(40),
	1629: uint16(106),
	1630: uint16(107),
	1631: uint16(108),
	1632: uint16(138),
	1633: uint16(139),
	1634: uint16(194),
	1635: uint16(217),
	1636: uint16(218),
	1637: uint16(114),
	1638: uint16(36),
	1639: uint16(116),
	1640: uint16(117),
	1641: uint16(118),
	1642: uint16(217),
	1643: uint16(218),
	1644: uint16(121),
	1645: uint16(194),
	1646: uint16(194),
	1647: uint16(194),
	1648: uint16(23),
	1649: uint16(117),
	1650: uint16(25),
	1651: uint16(194),
	1652: uint16(23),
	1653: uint16(23),
	1654: uint16(25),
	1655: uint16(25),
	1656: uint16(162),
	1657: uint16(194),
	1658: uint16(70),
	1659: uint16(194),
	1660: uint16(145),
	1661: uint16(59),
	1662: uint16(23),
	1663: uint16(153),
	1664: uint16(25),
	1665: uint16(155),
	1666: uint16(78),
	1667: uint16(194),
	1668: uint16(117),
	1669: uint16(81),
	1670: uint16(217),
	1671: uint16(218),
	1672: uint16(194),
	1673: uint16(71),
	1674: uint16(217),
	1675: uint16(218),
	1676: uint16(153),
	1677: uint16(154),
	1678: uint16(155),
	1679: uint16(156),
	1680: uint16(157),
	1681: uint16(194),
	1682: uint16(217),
	1683: uint16(218),
	1684: uint16(194),
	1685: uint16(23),
	1686: uint16(98),
	1687: uint16(25),
	1688: uint16(321),
	1689: uint16(194),
	1690: uint16(217),
	1691: uint16(218),
	1692: uint16(194),
	1693: uint16(19),
	1694: uint16(20),
	1695: uint16(194),
	1696: uint16(22),
	1697: uint16(153),
	1698: uint16(23),
	1699: uint16(155),
	1700: uint16(25),
	1701: uint16(194),
	1702: uint16(100),
	1703: uint16(194),
	1704: uint16(217),
	1705: uint16(218),
	1706: uint16(183),
	1707: uint16(194),
	1708: uint16(106),
	1709: uint16(107),
	1710: uint16(36),
	1711: uint16(194),
	1712: uint16(217),
	1713: uint16(218),
	1714: uint16(237),
	1715: uint16(194),
	1716: uint16(114),
	1717: uint16(243),
	1718: uint16(116),
	1719: uint16(117),
	1720: uint16(118),
	1721: uint16(133),
	1722: uint16(194),
	1723: uint16(121),
	1724: uint16(217),
	1725: uint16(218),
	1726: uint16(138),
	1727: uint16(139),
	1728: uint16(194),
	1729: uint16(194),
	1730: uint16(194),
	1731: uint16(290),
	1732: uint16(289),
	1733: uint16(59),
	1734: uint16(217),
	1735: uint16(218),
	1736: uint16(194),
	1737: uint16(194),
	1738: uint16(217),
	1739: uint16(218),
	1740: uint16(194),
	1741: uint16(194),
	1742: uint16(140),
	1743: uint16(194),
	1744: uint16(194),
	1745: uint16(71),
	1746: uint16(194),
	1747: uint16(244),
	1748: uint16(194),
	1749: uint16(194),
	1750: uint16(162),
	1751: uint16(217),
	1752: uint16(218),
	1753: uint16(194),
	1754: uint16(194),
	1755: uint16(153),
	1756: uint16(154),
	1757: uint16(155),
	1758: uint16(156),
	1759: uint16(157),
	1760: uint16(217),
	1761: uint16(218),
	1762: uint16(194),
	1763: uint16(217),
	1764: uint16(218),
	1765: uint16(194),
	1766: uint16(217),
	1767: uint16(218),
	1768: uint16(257),
	1769: uint16(217),
	1770: uint16(218),
	1771: uint16(217),
	1772: uint16(218),
	1773: uint16(257),
	1774: uint16(100),
	1775: uint16(194),
	1776: uint16(257),
	1777: uint16(217),
	1778: uint16(218),
	1779: uint16(257),
	1780: uint16(106),
	1781: uint16(107),
	1782: uint16(215),
	1783: uint16(299),
	1784: uint16(194),
	1785: uint16(183),
	1786: uint16(192),
	1787: uint16(194),
	1788: uint16(114),
	1789: uint16(194),
	1790: uint16(116),
	1791: uint16(117),
	1792: uint16(118),
	1793: uint16(1),
	1794: uint16(2),
	1795: uint16(121),
	1796: uint16(221),
	1797: uint16(5),
	1798: uint16(217),
	1799: uint16(218),
	1800: uint16(273),
	1801: uint16(197),
	1802: uint16(10),
	1803: uint16(11),
	1804: uint16(12),
	1805: uint16(13),
	1806: uint16(14),
	1807: uint16(217),
	1808: uint16(218),
	1809: uint16(17),
	1810: uint16(217),
	1811: uint16(218),
	1812: uint16(217),
	1813: uint16(218),
	1814: uint16(140),
	1815: uint16(194),
	1816: uint16(246),
	1817: uint16(194),
	1818: uint16(273),
	1819: uint16(295),
	1820: uint16(247),
	1821: uint16(273),
	1822: uint16(30),
	1823: uint16(247),
	1824: uint16(32),
	1825: uint16(269),
	1826: uint16(269),
	1827: uint16(153),
	1828: uint16(154),
	1829: uint16(155),
	1830: uint16(156),
	1831: uint16(157),
	1832: uint16(40),
	1833: uint16(246),
	1834: uint16(273),
	1835: uint16(295),
	1836: uint16(230),
	1837: uint16(226),
	1838: uint16(217),
	1839: uint16(218),
	1840: uint16(217),
	1841: uint16(218),
	1842: uint16(220),
	1843: uint16(261),
	1844: uint16(220),
	1845: uint16(282),
	1846: uint16(220),
	1847: uint16(19),
	1848: uint16(20),
	1849: uint16(244),
	1850: uint16(22),
	1851: uint16(250),
	1852: uint16(141),
	1853: uint16(250),
	1854: uint16(246),
	1855: uint16(60),
	1856: uint16(201),
	1857: uint16(183),
	1858: uint16(261),
	1859: uint16(261),
	1860: uint16(261),
	1861: uint16(201),
	1862: uint16(70),
	1863: uint16(299),
	1864: uint16(36),
	1865: uint16(299),
	1866: uint16(201),
	1867: uint16(38),
	1868: uint16(151),
	1869: uint16(150),
	1870: uint16(78),
	1871: uint16(285),
	1872: uint16(22),
	1873: uint16(81),
	1874: uint16(296),
	1875: uint16(296),
	1876: uint16(43),
	1877: uint16(235),
	1878: uint16(18),
	1879: uint16(238),
	1880: uint16(201),
	1881: uint16(274),
	1882: uint16(272),
	1883: uint16(238),
	1884: uint16(238),
	1885: uint16(238),
	1886: uint16(18),
	1887: uint16(59),
	1888: uint16(200),
	1889: uint16(149),
	1890: uint16(98),
	1891: uint16(247),
	1892: uint16(274),
	1893: uint16(274),
	1894: uint16(235),
	1895: uint16(247),
	1896: uint16(247),
	1897: uint16(247),
	1898: uint16(235),
	1899: uint16(71),
	1900: uint16(272),
	1901: uint16(201),
	1902: uint16(200),
	1903: uint16(158),
	1904: uint16(292),
	1905: uint16(62),
	1906: uint16(291),
	1907: uint16(201),
	1908: uint16(200),
	1909: uint16(22),
	1910: uint16(201),
	1911: uint16(222),
	1912: uint16(200),
	1913: uint16(222),
	1914: uint16(201),
	1915: uint16(200),
	1916: uint16(115),
	1917: uint16(219),
	1918: uint16(219),
	1919: uint16(64),
	1920: uint16(219),
	1921: uint16(228),
	1922: uint16(22),
	1923: uint16(126),
	1924: uint16(221),
	1925: uint16(133),
	1926: uint16(165),
	1927: uint16(222),
	1928: uint16(100),
	1929: uint16(225),
	1930: uint16(138),
	1931: uint16(139),
	1932: uint16(225),
	1933: uint16(219),
	1934: uint16(106),
	1935: uint16(107),
	1936: uint16(24),
	1937: uint16(219),
	1938: uint16(228),
	1939: uint16(219),
	1940: uint16(219),
	1941: uint16(307),
	1942: uint16(114),
	1943: uint16(113),
	1944: uint16(116),
	1945: uint16(117),
	1946: uint16(118),
	1947: uint16(315),
	1948: uint16(284),
	1949: uint16(121),
	1950: uint16(284),
	1951: uint16(222),
	1952: uint16(201),
	1953: uint16(91),
	1954: uint16(162),
	1955: uint16(320),
	1956: uint16(320),
	1957: uint16(82),
	1958: uint16(148),
	1959: uint16(267),
	1960: uint16(145),
	1961: uint16(267),
	1962: uint16(22),
	1963: uint16(279),
	1964: uint16(201),
	1965: uint16(158),
	1966: uint16(281),
	1967: uint16(251),
	1968: uint16(147),
	1969: uint16(146),
	1970: uint16(25),
	1971: uint16(203),
	1972: uint16(250),
	1973: uint16(249),
	1974: uint16(251),
	1975: uint16(248),
	1976: uint16(13),
	1977: uint16(247),
	1978: uint16(195),
	1979: uint16(195),
	1980: uint16(6),
	1981: uint16(153),
	1982: uint16(154),
	1983: uint16(155),
	1984: uint16(156),
	1985: uint16(157),
	1986: uint16(193),
	1987: uint16(193),
	1988: uint16(305),
	1989: uint16(193),
	1990: uint16(208),
	1991: uint16(305),
	1992: uint16(302),
	1993: uint16(214),
	1994: uint16(214),
	1995: uint16(214),
	1996: uint16(208),
	1997: uint16(223),
	1998: uint16(223),
	1999: uint16(214),
	2000: uint16(4),
	2001: uint16(215),
	2002: uint16(215),
	2003: uint16(214),
	2004: uint16(3),
	2005: uint16(22),
	2006: uint16(208),
	2007: uint16(163),
	2008: uint16(15),
	2009: uint16(23),
	2010: uint16(16),
	2011: uint16(183),
	2012: uint16(23),
	2013: uint16(139),
	2014: uint16(151),
	2015: uint16(130),
	2016: uint16(25),
	2017: uint16(20),
	2018: uint16(142),
	2019: uint16(24),
	2020: uint16(16),
	2021: uint16(144),
	2022: uint16(1),
	2023: uint16(142),
	2024: uint16(130),
	2025: uint16(130),
	2026: uint16(61),
	2027: uint16(37),
	2028: uint16(53),
	2029: uint16(151),
	2030: uint16(53),
	2031: uint16(53),
	2032: uint16(53),
	2033: uint16(130),
	2034: uint16(116),
	2035: uint16(1),
	2036: uint16(34),
	2037: uint16(141),
	2038: uint16(5),
	2039: uint16(22),
	2040: uint16(115),
	2041: uint16(161),
	2042: uint16(75),
	2043: uint16(25),
	2044: uint16(68),
	2045: uint16(141),
	2046: uint16(41),
	2047: uint16(115),
	2048: uint16(68),
	2049: uint16(24),
	2050: uint16(20),
	2051: uint16(19),
	2052: uint16(131),
	2053: uint16(125),
	2054: uint16(67),
	2055: uint16(67),
	2056: uint16(96),
	2057: uint16(22),
	2058: uint16(22),
	2059: uint16(22),
	2060: uint16(37),
	2061: uint16(23),
	2062: uint16(22),
	2063: uint16(24),
	2064: uint16(22),
	2065: uint16(59),
	2066: uint16(67),
	2067: uint16(23),
	2068: uint16(149),
	2069: uint16(28),
	2070: uint16(22),
	2071: uint16(25),
	2072: uint16(23),
	2073: uint16(23),
	2074: uint16(23),
	2075: uint16(22),
	2076: uint16(141),
	2077: uint16(34),
	2078: uint16(97),
	2079: uint16(23),
	2080: uint16(23),
	2081: uint16(34),
	2082: uint16(116),
	2083: uint16(22),
	2084: uint16(143),
	2085: uint16(25),
	2086: uint16(34),
	2087: uint16(75),
	2088: uint16(34),
	2089: uint16(34),
	2090: uint16(75),
	2091: uint16(88),
	2092: uint16(34),
	2093: uint16(86),
	2094: uint16(23),
	2095: uint16(22),
	2096: uint16(34),
	2097: uint16(25),
	2098: uint16(24),
	2099: uint16(34),
	2100: uint16(25),
	2101: uint16(93),
	2102: uint16(23),
	2103: uint16(44),
	2104: uint16(142),
	2105: uint16(23),
	2106: uint16(142),
	2107: uint16(23),
	2108: uint16(23),
	2109: uint16(22),
	2110: uint16(11),
	2111: uint16(25),
	2112: uint16(23),
	2113: uint16(25),
	2114: uint16(23),
	2115: uint16(22),
	2116: uint16(22),
	2117: uint16(22),
	2118: uint16(1),
	2119: uint16(23),
	2120: uint16(23),
	2121: uint16(23),
	2122: uint16(22),
	2123: uint16(22),
	2124: uint16(15),
	2125: uint16(141),
	2126: uint16(141),
	2127: uint16(25),
	2128: uint16(25),
	2129: uint16(1),
	2130: uint16(322),
	2131: uint16(322),
	2132: uint16(322),
	2133: uint16(135),
	2134: uint16(322),
	2135: uint16(322),
	2136: uint16(322),
	2137: uint16(322),
	2138: uint16(322),
	2139: uint16(322),
	2140: uint16(322),
	2141: uint16(141),
	2142: uint16(322),
	2143: uint16(322),
	2144: uint16(322),
	2145: uint16(322),
	2146: uint16(322),
	2147: uint16(322),
	2148: uint16(322),
	2149: uint16(322),
	2150: uint16(322),
	2151: uint16(322),
	2152: uint16(322),
	2153: uint16(322),
	2154: uint16(322),
	2155: uint16(322),
	2156: uint16(322),
	2157: uint16(322),
	2158: uint16(322),
	2159: uint16(322),
	2160: uint16(322),
	2161: uint16(322),
	2162: uint16(322),
	2163: uint16(322),
	2164: uint16(322),
	2165: uint16(322),
	2166: uint16(322),
	2167: uint16(322),
	2168: uint16(322),
	2169: uint16(322),
	2170: uint16(322),
	2171: uint16(322),
	2172: uint16(322),
	2173: uint16(322),
	2174: uint16(322),
	2175: uint16(322),
	2176: uint16(322),
	2177: uint16(322),
	2178: uint16(322),
	2179: uint16(322),
	2180: uint16(322),
	2181: uint16(322),
	2182: uint16(322),
	2183: uint16(322),
	2184: uint16(322),
	2185: uint16(322),
	2186: uint16(322),
	2187: uint16(322),
	2188: uint16(322),
	2189: uint16(322),
	2190: uint16(322),
	2191: uint16(322),
	2192: uint16(322),
	2193: uint16(322),
	2194: uint16(322),
	2195: uint16(322),
	2196: uint16(322),
	2197: uint16(322),
	2198: uint16(322),
	2199: uint16(322),
	2200: uint16(322),
	2201: uint16(322),
	2202: uint16(322),
	2203: uint16(322),
	2204: uint16(322),
	2205: uint16(322),
	2206: uint16(322),
	2207: uint16(322),
	2208: uint16(322),
	2209: uint16(322),
	2210: uint16(322),
	2211: uint16(322),
	2212: uint16(322),
	2213: uint16(322),
	2214: uint16(322),
	2215: uint16(322),
	2216: uint16(322),
	2217: uint16(322),
	2218: uint16(322),
	2219: uint16(322),
	2220: uint16(322),
	2221: uint16(322),
	2222: uint16(322),
	2223: uint16(322),
	2224: uint16(322),
	2225: uint16(322),
	2226: uint16(322),
	2227: uint16(322),
	2228: uint16(322),
	2229: uint16(322),
	2230: uint16(322),
	2231: uint16(322),
	2232: uint16(322),
	2233: uint16(322),
	2234: uint16(322),
	2235: uint16(322),
	2236: uint16(322),
	2237: uint16(322),
	2238: uint16(322),
	2239: uint16(322),
	2240: uint16(322),
	2241: uint16(322),
	2242: uint16(322),
	2243: uint16(322),
	2244: uint16(322),
	2245: uint16(322),
	2246: uint16(322),
	2247: uint16(322),
	2248: uint16(322),
	2249: uint16(322),
	2250: uint16(322),
	2251: uint16(322),
	2252: uint16(322),
	2253: uint16(322),
	2254: uint16(322),
	2255: uint16(322),
	2256: uint16(322),
	2257: uint16(322),
	2258: uint16(322),
	2259: uint16(322),
	2260: uint16(322),
	2261: uint16(322),
	2262: uint16(322),
	2263: uint16(322),
	2264: uint16(322),
	2265: uint16(322),
	2266: uint16(322),
	2267: uint16(322),
	2268: uint16(322),
	2269: uint16(322),
	2270: uint16(322),
	2271: uint16(322),
	2272: uint16(322),
	2273: uint16(322),
	2274: uint16(322),
	2275: uint16(322),
	2276: uint16(322),
	2277: uint16(322),
	2278: uint16(322),
	2279: uint16(322),
	2280: uint16(322),
	2281: uint16(322),
	2282: uint16(322),
	2283: uint16(322),
	2284: uint16(322),
	2285: uint16(322),
	2286: uint16(322),
	2287: uint16(322),
	2288: uint16(322),
	2289: uint16(322),
	2290: uint16(322),
	2291: uint16(322),
	2292: uint16(322),
	2293: uint16(322),
	2294: uint16(322),
	2295: uint16(322),
	2296: uint16(322),
	2297: uint16(322),
	2298: uint16(322),
	2299: uint16(322),
	2300: uint16(322),
	2301: uint16(322),
	2302: uint16(322),
	2303: uint16(322),
	2304: uint16(322),
	2305: uint16(322),
	2306: uint16(322),
	2307: uint16(322),
	2308: uint16(322),
	2309: uint16(322),
	2310: uint16(322),
	2311: uint16(322),
	2312: uint16(322),
	2313: uint16(322),
	2314: uint16(322),
	2315: uint16(322),
	2316: uint16(322),
	2317: uint16(322),
	2318: uint16(322),
	2319: uint16(322),
	2320: uint16(322),
	2321: uint16(322),
	2322: uint16(322),
	2323: uint16(322),
	2324: uint16(322),
	2325: uint16(322),
	2326: uint16(322),
	2327: uint16(322),
}
var _yy_shift_ofst = [583]uint16{
	0:   uint16(1792),
	1:   uint16(1588),
	2:   uint16(1494),
	3:   uint16(322),
	4:   uint16(322),
	5:   uint16(399),
	6:   uint16(306),
	7:   uint16(1319),
	8:   uint16(1339),
	9:   uint16(1430),
	10:  uint16(1828),
	11:  uint16(1828),
	12:  uint16(1828),
	13:  uint16(580),
	14:  uint16(399),
	15:  uint16(399),
	16:  uint16(399),
	17:  uint16(399),
	18:  uint16(399),
	21:  uint16(214),
	22:  uint16(1093),
	23:  uint16(1828),
	24:  uint16(1828),
	25:  uint16(1828),
	26:  uint16(1828),
	27:  uint16(1828),
	28:  uint16(1828),
	29:  uint16(1828),
	30:  uint16(1828),
	31:  uint16(1828),
	32:  uint16(1828),
	33:  uint16(1828),
	34:  uint16(1828),
	35:  uint16(1828),
	36:  uint16(1828),
	37:  uint16(1828),
	38:  uint16(1130),
	39:  uint16(1130),
	40:  uint16(365),
	41:  uint16(365),
	42:  uint16(55),
	43:  uint16(278),
	44:  uint16(436),
	45:  uint16(713),
	46:  uint16(713),
	47:  uint16(201),
	48:  uint16(201),
	49:  uint16(201),
	50:  uint16(201),
	51:  uint16(40),
	52:  uint16(111),
	53:  uint16(258),
	54:  uint16(361),
	55:  uint16(469),
	56:  uint16(512),
	57:  uint16(583),
	58:  uint16(622),
	59:  uint16(693),
	60:  uint16(732),
	61:  uint16(803),
	62:  uint16(842),
	63:  uint16(913),
	64:  uint16(1073),
	65:  uint16(1093),
	66:  uint16(1093),
	67:  uint16(1093),
	68:  uint16(1093),
	69:  uint16(1093),
	70:  uint16(1093),
	71:  uint16(1093),
	72:  uint16(1093),
	73:  uint16(1093),
	74:  uint16(1093),
	75:  uint16(1093),
	76:  uint16(1093),
	77:  uint16(1093),
	78:  uint16(1093),
	79:  uint16(1093),
	80:  uint16(1093),
	81:  uint16(1093),
	82:  uint16(1093),
	83:  uint16(1113),
	84:  uint16(1093),
	85:  uint16(1216),
	86:  uint16(957),
	87:  uint16(957),
	88:  uint16(1523),
	89:  uint16(1602),
	90:  uint16(1674),
	91:  uint16(1828),
	92:  uint16(1828),
	93:  uint16(1828),
	94:  uint16(1828),
	95:  uint16(1828),
	96:  uint16(1828),
	97:  uint16(1828),
	98:  uint16(1828),
	99:  uint16(1828),
	100: uint16(1828),
	101: uint16(1828),
	102: uint16(1828),
	103: uint16(1828),
	104: uint16(1828),
	105: uint16(1828),
	106: uint16(1828),
	107: uint16(1828),
	108: uint16(1828),
	109: uint16(1828),
	110: uint16(1828),
	111: uint16(1828),
	112: uint16(1828),
	113: uint16(1828),
	114: uint16(1828),
	115: uint16(1828),
	116: uint16(1828),
	117: uint16(1828),
	118: uint16(1828),
	119: uint16(1828),
	120: uint16(1828),
	121: uint16(1828),
	122: uint16(1828),
	123: uint16(1828),
	124: uint16(1828),
	125: uint16(1828),
	126: uint16(1828),
	127: uint16(1828),
	128: uint16(1828),
	129: uint16(1828),
	130: uint16(1828),
	131: uint16(1828),
	132: uint16(1828),
	133: uint16(1828),
	134: uint16(1828),
	135: uint16(1828),
	136: uint16(1828),
	137: uint16(1828),
	138: uint16(1828),
	139: uint16(1828),
	140: uint16(137),
	141: uint16(181),
	142: uint16(181),
	143: uint16(181),
	144: uint16(181),
	145: uint16(181),
	146: uint16(181),
	147: uint16(181),
	148: uint16(96),
	149: uint16(222),
	150: uint16(143),
	151: uint16(477),
	152: uint16(713),
	153: uint16(1133),
	154: uint16(1268),
	155: uint16(713),
	156: uint16(713),
	157: uint16(79),
	158: uint16(79),
	159: uint16(713),
	160: uint16(770),
	161: uint16(83),
	162: uint16(65),
	163: uint16(65),
	164: uint16(65),
	165: uint16(288),
	166: uint16(162),
	167: uint16(162),
	168: uint16(2142),
	169: uint16(2142),
	170: uint16(696),
	171: uint16(696),
	172: uint16(696),
	173: uint16(238),
	174: uint16(474),
	175: uint16(474),
	176: uint16(474),
	177: uint16(474),
	178: uint16(1217),
	179: uint16(1217),
	180: uint16(678),
	181: uint16(477),
	182: uint16(324),
	183: uint16(398),
	184: uint16(713),
	185: uint16(713),
	186: uint16(713),
	187: uint16(713),
	188: uint16(713),
	189: uint16(713),
	190: uint16(713),
	191: uint16(713),
	192: uint16(713),
	193: uint16(713),
	194: uint16(713),
	195: uint16(713),
	196: uint16(713),
	197: uint16(713),
	198: uint16(713),
	199: uint16(713),
	200: uint16(713),
	201: uint16(713),
	202: uint16(713),
	203: uint16(1220),
	204: uint16(366),
	205: uint16(366),
	206: uint16(713),
	207: uint16(917),
	208: uint16(283),
	209: uint16(283),
	210: uint16(434),
	211: uint16(434),
	212: uint16(605),
	213: uint16(605),
	214: uint16(1298),
	215: uint16(2142),
	216: uint16(2142),
	217: uint16(2142),
	218: uint16(2142),
	219: uint16(2142),
	220: uint16(2142),
	221: uint16(2142),
	222: uint16(1179),
	223: uint16(1157),
	224: uint16(1157),
	225: uint16(487),
	226: uint16(527),
	227: uint16(585),
	228: uint16(645),
	229: uint16(749),
	230: uint16(914),
	231: uint16(968),
	232: uint16(752),
	233: uint16(713),
	234: uint16(713),
	235: uint16(713),
	236: uint16(713),
	237: uint16(713),
	238: uint16(713),
	239: uint16(713),
	240: uint16(713),
	241: uint16(713),
	242: uint16(713),
	243: uint16(303),
	244: uint16(713),
	245: uint16(713),
	246: uint16(713),
	247: uint16(713),
	248: uint16(713),
	249: uint16(713),
	250: uint16(713),
	251: uint16(713),
	252: uint16(713),
	253: uint16(713),
	254: uint16(713),
	255: uint16(713),
	256: uint16(797),
	257: uint16(797),
	258: uint16(797),
	259: uint16(713),
	260: uint16(713),
	261: uint16(713),
	262: uint16(959),
	263: uint16(713),
	264: uint16(713),
	265: uint16(713),
	266: uint16(1169),
	267: uint16(1271),
	268: uint16(713),
	269: uint16(713),
	270: uint16(1330),
	271: uint16(713),
	272: uint16(713),
	273: uint16(713),
	274: uint16(713),
	275: uint16(713),
	276: uint16(713),
	277: uint16(713),
	278: uint16(713),
	279: uint16(629),
	280: uint16(7),
	281: uint16(91),
	282: uint16(876),
	283: uint16(876),
	284: uint16(876),
	285: uint16(876),
	286: uint16(953),
	287: uint16(91),
	288: uint16(91),
	289: uint16(1246),
	290: uint16(1065),
	291: uint16(1106),
	292: uint16(1374),
	293: uint16(1329),
	294: uint16(1348),
	295: uint16(468),
	296: uint16(1348),
	297: uint16(1394),
	298: uint16(785),
	299: uint16(1329),
	300: uint16(1329),
	301: uint16(785),
	302: uint16(1329),
	303: uint16(468),
	304: uint16(1394),
	305: uint16(859),
	306: uint16(854),
	307: uint16(1402),
	308: uint16(1449),
	309: uint16(1449),
	310: uint16(1449),
	311: uint16(1173),
	312: uint16(1173),
	313: uint16(1173),
	314: uint16(1173),
	315: uint16(1355),
	316: uint16(1355),
	317: uint16(1030),
	318: uint16(1341),
	319: uint16(405),
	320: uint16(1230),
	321: uint16(1795),
	322: uint16(1795),
	323: uint16(1711),
	324: uint16(1711),
	325: uint16(1829),
	326: uint16(1829),
	327: uint16(1711),
	328: uint16(1717),
	329: uint16(1719),
	330: uint16(1850),
	331: uint16(1833),
	332: uint16(1860),
	333: uint16(1860),
	334: uint16(1860),
	335: uint16(1860),
	336: uint16(1711),
	337: uint16(1868),
	338: uint16(1740),
	339: uint16(1719),
	340: uint16(1719),
	341: uint16(1740),
	342: uint16(1850),
	343: uint16(1833),
	344: uint16(1740),
	345: uint16(1833),
	346: uint16(1740),
	347: uint16(1711),
	348: uint16(1868),
	349: uint16(1745),
	350: uint16(1843),
	351: uint16(1711),
	352: uint16(1868),
	353: uint16(1887),
	354: uint16(1711),
	355: uint16(1868),
	356: uint16(1711),
	357: uint16(1868),
	358: uint16(1887),
	359: uint16(1801),
	360: uint16(1801),
	361: uint16(1801),
	362: uint16(1855),
	363: uint16(1900),
	364: uint16(1900),
	365: uint16(1887),
	366: uint16(1801),
	367: uint16(1797),
	368: uint16(1801),
	369: uint16(1855),
	370: uint16(1801),
	371: uint16(1801),
	372: uint16(1761),
	373: uint16(1912),
	374: uint16(1830),
	375: uint16(1830),
	376: uint16(1887),
	377: uint16(1711),
	378: uint16(1862),
	379: uint16(1862),
	380: uint16(1875),
	381: uint16(1875),
	382: uint16(1810),
	383: uint16(1815),
	384: uint16(1940),
	385: uint16(1711),
	386: uint16(1807),
	387: uint16(1810),
	388: uint16(1821),
	389: uint16(1823),
	390: uint16(1740),
	391: uint16(1945),
	392: uint16(1963),
	393: uint16(1963),
	394: uint16(1974),
	395: uint16(1974),
	396: uint16(1974),
	397: uint16(2142),
	398: uint16(2142),
	399: uint16(2142),
	400: uint16(2142),
	401: uint16(2142),
	402: uint16(2142),
	403: uint16(2142),
	404: uint16(2142),
	405: uint16(2142),
	406: uint16(2142),
	407: uint16(2142),
	408: uint16(2142),
	409: uint16(2142),
	410: uint16(2142),
	411: uint16(2142),
	412: uint16(20),
	413: uint16(1224),
	414: uint16(256),
	415: uint16(1111),
	416: uint16(1115),
	417: uint16(1114),
	418: uint16(1192),
	419: uint16(1496),
	420: uint16(1424),
	421: uint16(1505),
	422: uint16(1427),
	423: uint16(355),
	424: uint16(1383),
	425: uint16(1537),
	426: uint16(1506),
	427: uint16(1538),
	428: uint16(1553),
	429: uint16(1583),
	430: uint16(1584),
	431: uint16(1591),
	432: uint16(1625),
	433: uint16(541),
	434: uint16(1445),
	435: uint16(1562),
	436: uint16(1450),
	437: uint16(1572),
	438: uint16(1515),
	439: uint16(1428),
	440: uint16(1532),
	441: uint16(1592),
	442: uint16(1629),
	443: uint16(1520),
	444: uint16(1630),
	445: uint16(1639),
	446: uint16(1510),
	447: uint16(1544),
	448: uint16(1662),
	449: uint16(1675),
	450: uint16(1551),
	451: uint16(48),
	452: uint16(1996),
	453: uint16(2001),
	454: uint16(1983),
	455: uint16(1844),
	456: uint16(1993),
	457: uint16(1994),
	458: uint16(1986),
	459: uint16(1989),
	460: uint16(1874),
	461: uint16(1863),
	462: uint16(1885),
	463: uint16(1991),
	464: uint16(1991),
	465: uint16(1995),
	466: uint16(1876),
	467: uint16(1997),
	468: uint16(1877),
	469: uint16(2004),
	470: uint16(2021),
	471: uint16(1881),
	472: uint16(1894),
	473: uint16(1991),
	474: uint16(1895),
	475: uint16(1965),
	476: uint16(1990),
	477: uint16(1991),
	478: uint16(1878),
	479: uint16(1975),
	480: uint16(1977),
	481: uint16(1978),
	482: uint16(1979),
	483: uint16(1903),
	484: uint16(1918),
	485: uint16(2002),
	486: uint16(1896),
	487: uint16(2034),
	488: uint16(2033),
	489: uint16(2017),
	490: uint16(1925),
	491: uint16(1880),
	492: uint16(1976),
	493: uint16(2018),
	494: uint16(1980),
	495: uint16(1967),
	496: uint16(2005),
	497: uint16(1904),
	498: uint16(1932),
	499: uint16(2025),
	500: uint16(2030),
	501: uint16(2032),
	502: uint16(1921),
	503: uint16(1928),
	504: uint16(2035),
	505: uint16(1987),
	506: uint16(2036),
	507: uint16(2037),
	508: uint16(2038),
	509: uint16(2040),
	510: uint16(1988),
	511: uint16(2006),
	512: uint16(2039),
	513: uint16(1960),
	514: uint16(2041),
	515: uint16(2042),
	516: uint16(1999),
	517: uint16(2023),
	518: uint16(2044),
	519: uint16(2043),
	520: uint16(1919),
	521: uint16(2048),
	522: uint16(2049),
	523: uint16(2050),
	524: uint16(2046),
	525: uint16(2051),
	526: uint16(2053),
	527: uint16(1981),
	528: uint16(1935),
	529: uint16(2056),
	530: uint16(2057),
	531: uint16(1966),
	532: uint16(2047),
	533: uint16(2061),
	534: uint16(1941),
	535: uint16(2060),
	536: uint16(2052),
	537: uint16(2054),
	538: uint16(2055),
	539: uint16(2058),
	540: uint16(2003),
	541: uint16(2012),
	542: uint16(2007),
	543: uint16(2059),
	544: uint16(2015),
	545: uint16(2008),
	546: uint16(2062),
	547: uint16(2071),
	548: uint16(2073),
	549: uint16(2074),
	550: uint16(2072),
	551: uint16(2075),
	552: uint16(2065),
	553: uint16(1962),
	554: uint16(1964),
	555: uint16(2079),
	556: uint16(2060),
	557: uint16(2082),
	558: uint16(2084),
	559: uint16(2085),
	560: uint16(2087),
	561: uint16(2086),
	562: uint16(2089),
	563: uint16(2088),
	564: uint16(2091),
	565: uint16(2093),
	566: uint16(2099),
	567: uint16(2094),
	568: uint16(2095),
	569: uint16(2096),
	570: uint16(2097),
	571: uint16(2100),
	572: uint16(2101),
	573: uint16(2102),
	574: uint16(1998),
	575: uint16(1984),
	576: uint16(1985),
	577: uint16(2000),
	578: uint16(2103),
	579: uint16(2098),
	580: uint16(2109),
	581: uint16(2117),
	582: uint16(2128),
}
var _yy_reduce_ofst = [412]int16{
	0:   int16(-int32(71)),
	1:   int16(194),
	2:   int16(343),
	3:   int16(835),
	4:   int16(-int32(180)),
	5:   int16(-int32(177)),
	6:   int16(838),
	7:   int16(-int32(194)),
	8:   int16(-int32(188)),
	9:   int16(-int32(185)),
	10:  int16(-int32(183)),
	11:  int16(82),
	12:  int16(183),
	13:  int16(-int32(65)),
	14:  int16(133),
	15:  int16(245),
	16:  int16(346),
	17:  int16(407),
	18:  int16(458),
	19:  int16(-int32(178)),
	20:  int16(75),
	21:  int16(-int32(275)),
	22:  int16(-int32(4)),
	23:  int16(310),
	24:  int16(312),
	25:  int16(489),
	26:  int16(575),
	27:  int16(596),
	28:  int16(463),
	29:  int16(686),
	30:  int16(707),
	31:  int16(725),
	32:  int16(780),
	33:  int16(1098),
	34:  int16(856),
	35:  int16(778),
	36:  int16(1059),
	37:  int16(1090),
	38:  int16(708),
	39:  int16(887),
	40:  int16(86),
	41:  int16(448),
	42:  int16(980),
	43:  int16(630),
	44:  int16(680),
	45:  int16(681),
	46:  int16(684),
	47:  int16(796),
	48:  int16(801),
	49:  int16(796),
	50:  int16(801),
	51:  int16(-int32(261)),
	52:  int16(-int32(261)),
	53:  int16(-int32(261)),
	54:  int16(-int32(261)),
	55:  int16(-int32(261)),
	56:  int16(-int32(261)),
	57:  int16(-int32(261)),
	58:  int16(-int32(261)),
	59:  int16(-int32(261)),
	60:  int16(-int32(261)),
	61:  int16(-int32(261)),
	62:  int16(-int32(261)),
	63:  int16(-int32(261)),
	64:  int16(-int32(261)),
	65:  int16(-int32(261)),
	66:  int16(-int32(261)),
	67:  int16(-int32(261)),
	68:  int16(-int32(261)),
	69:  int16(-int32(261)),
	70:  int16(-int32(261)),
	71:  int16(-int32(261)),
	72:  int16(-int32(261)),
	73:  int16(-int32(261)),
	74:  int16(-int32(261)),
	75:  int16(-int32(261)),
	76:  int16(-int32(261)),
	77:  int16(-int32(261)),
	78:  int16(-int32(261)),
	79:  int16(-int32(261)),
	80:  int16(-int32(261)),
	81:  int16(-int32(261)),
	82:  int16(-int32(261)),
	83:  int16(-int32(261)),
	84:  int16(-int32(261)),
	85:  int16(-int32(261)),
	86:  int16(-int32(261)),
	87:  int16(-int32(261)),
	88:  int16(391),
	89:  int16(886),
	90:  int16(888),
	91:  int16(1013),
	92:  int16(1016),
	93:  int16(1081),
	94:  int16(1087),
	95:  int16(1151),
	96:  int16(1159),
	97:  int16(1177),
	98:  int16(1185),
	99:  int16(1188),
	100: int16(1190),
	101: int16(1194),
	102: int16(1197),
	103: int16(1203),
	104: int16(1247),
	105: int16(1260),
	106: int16(1264),
	107: int16(1267),
	108: int16(1269),
	109: int16(1273),
	110: int16(1315),
	111: int16(1322),
	112: int16(1335),
	113: int16(1337),
	114: int16(1356),
	115: int16(1362),
	116: int16(1418),
	117: int16(1425),
	118: int16(1453),
	119: int16(1457),
	120: int16(1465),
	121: int16(1473),
	122: int16(1487),
	123: int16(1495),
	124: int16(1507),
	125: int16(1517),
	126: int16(1521),
	127: int16(1534),
	128: int16(1543),
	129: int16(1546),
	130: int16(1549),
	131: int16(1552),
	132: int16(1554),
	133: int16(1560),
	134: int16(1581),
	135: int16(1590),
	136: int16(1593),
	137: int16(1595),
	138: int16(1621),
	139: int16(1623),
	140: int16(-int32(261)),
	141: int16(-int32(261)),
	142: int16(-int32(261)),
	143: int16(-int32(261)),
	144: int16(-int32(261)),
	145: int16(-int32(261)),
	146: int16(-int32(261)),
	147: int16(-int32(261)),
	148: int16(-int32(261)),
	149: int16(-int32(261)),
	150: int16(-int32(261)),
	151: int16(-int32(186)),
	152: int16(-int32(117)),
	153: int16(260),
	154: int16(263),
	155: int16(460),
	156: int16(631),
	157: int16(-int32(74)),
	158: int16(497),
	159: int16(-int32(181)),
	160: int16(-int32(261)),
	161: int16(939),
	162: int16(176),
	163: int16(274),
	164: int16(338),
	165: int16(676),
	166: int16(-int32(261)),
	167: int16(-int32(261)),
	168: int16(-int32(261)),
	169: int16(-int32(261)),
	170: int16(-int32(212)),
	171: int16(-int32(212)),
	172: int16(-int32(212)),
	173: int16(-int32(184)),
	174: int16(149),
	175: int16(777),
	176: int16(1061),
	177: int16(1103),
	178: int16(265),
	179: int16(419),
	180: int16(-int32(254)),
	181: int16(670),
	182: int16(677),
	183: int16(677),
	184: int16(-int32(11)),
	185: int16(-int32(129)),
	186: int16(184),
	187: int16(488),
	188: int16(736),
	189: int16(789),
	190: int16(805),
	191: int16(844),
	192: int16(403),
	193: int16(529),
	194: int16(579),
	195: int16(668),
	196: int16(783),
	197: int16(841),
	198: int16(1158),
	199: int16(1112),
	200: int16(806),
	201: int16(861),
	202: int16(1095),
	203: int16(846),
	204: int16(839),
	205: int16(1031),
	206: int16(-int32(189)),
	207: int16(1077),
	208: int16(1080),
	209: int16(1116),
	210: int16(1084),
	211: int16(1156),
	212: int16(1139),
	213: int16(1221),
	214: int16(46),
	215: int16(1099),
	216: int16(1037),
	217: int16(1118),
	218: int16(1171),
	219: int16(1214),
	220: int16(1210),
	221: int16(1258),
	222: int16(-int32(210)),
	223: int16(-int32(190)),
	224: int16(-int32(176)),
	225: int16(-int32(115)),
	226: int16(117),
	227: int16(262),
	228: int16(376),
	229: int16(490),
	230: int16(511),
	231: int16(520),
	232: int16(618),
	233: int16(639),
	234: int16(743),
	235: int16(901),
	236: int16(907),
	237: int16(958),
	238: int16(1014),
	239: int16(1055),
	240: int16(1108),
	241: int16(1193),
	242: int16(1244),
	243: int16(720),
	244: int16(1248),
	245: int16(1277),
	246: int16(1324),
	247: int16(1347),
	248: int16(1417),
	249: int16(1431),
	250: int16(1432),
	251: int16(1440),
	252: int16(1451),
	253: int16(1452),
	254: int16(1463),
	255: int16(1478),
	256: int16(1286),
	257: int16(1350),
	258: int16(1369),
	259: int16(1490),
	260: int16(1498),
	261: int16(1501),
	262: int16(773),
	263: int16(1509),
	264: int16(1513),
	265: int16(1528),
	266: int16(1292),
	267: int16(1367),
	268: int16(1535),
	269: int16(1536),
	270: int16(1477),
	271: int16(1542),
	272: int16(376),
	273: int16(1547),
	274: int16(1550),
	275: int16(1555),
	276: int16(1559),
	277: int16(1568),
	278: int16(1571),
	279: int16(1441),
	280: int16(1443),
	281: int16(1474),
	282: int16(1511),
	283: int16(1516),
	284: int16(1519),
	285: int16(1522),
	286: int16(773),
	287: int16(1474),
	288: int16(1474),
	289: int16(1503),
	290: int16(1567),
	291: int16(1594),
	292: int16(1484),
	293: int16(1527),
	294: int16(1556),
	295: int16(1570),
	296: int16(1557),
	297: int16(1524),
	298: int16(1573),
	299: int16(1545),
	300: int16(1548),
	301: int16(1576),
	302: int16(1561),
	303: int16(1587),
	304: int16(1540),
	305: int16(1575),
	306: int16(1606),
	307: int16(1611),
	308: int16(1622),
	309: int16(1624),
	310: int16(1626),
	311: int16(1582),
	312: int16(1597),
	313: int16(1598),
	314: int16(1599),
	315: int16(1601),
	316: int16(1603),
	317: int16(1563),
	318: int16(1608),
	319: int16(1605),
	320: int16(1604),
	321: int16(1564),
	322: int16(1566),
	323: int16(1655),
	324: int16(1660),
	325: int16(1578),
	326: int16(1579),
	327: int16(1665),
	328: int16(1586),
	329: int16(1607),
	330: int16(1610),
	331: int16(1642),
	332: int16(1641),
	333: int16(1645),
	334: int16(1646),
	335: int16(1647),
	336: int16(1679),
	337: int16(1688),
	338: int16(1644),
	339: int16(1618),
	340: int16(1619),
	341: int16(1648),
	342: int16(1628),
	343: int16(1659),
	344: int16(1649),
	345: int16(1663),
	346: int16(1650),
	347: int16(1700),
	348: int16(1702),
	349: int16(1612),
	350: int16(1615),
	351: int16(1706),
	352: int16(1708),
	353: int16(1689),
	354: int16(1709),
	355: int16(1712),
	356: int16(1713),
	357: int16(1715),
	358: int16(1691),
	359: int16(1698),
	360: int16(1699),
	361: int16(1701),
	362: int16(1693),
	363: int16(1704),
	364: int16(1707),
	365: int16(1705),
	366: int16(1714),
	367: int16(1703),
	368: int16(1718),
	369: int16(1710),
	370: int16(1720),
	371: int16(1721),
	372: int16(1632),
	373: int16(1634),
	374: int16(1664),
	375: int16(1666),
	376: int16(1729),
	377: int16(1751),
	378: int16(1635),
	379: int16(1636),
	380: int16(1692),
	381: int16(1694),
	382: int16(1716),
	383: int16(1722),
	384: int16(1684),
	385: int16(1763),
	386: int16(1685),
	387: int16(1723),
	388: int16(1724),
	389: int16(1727),
	390: int16(1730),
	391: int16(1768),
	392: int16(1783),
	393: int16(1784),
	394: int16(1793),
	395: int16(1794),
	396: int16(1796),
	397: int16(1683),
	398: int16(1686),
	399: int16(1690),
	400: int16(1782),
	401: int16(1779),
	402: int16(1780),
	403: int16(1781),
	404: int16(1785),
	405: int16(1788),
	406: int16(1774),
	407: int16(1775),
	408: int16(1786),
	409: int16(1787),
	410: int16(1789),
	411: int16(1798),
}
var _yy_default = [583]uint16{
	0:   uint16(1663),
	1:   uint16(1663),
	2:   uint16(1663),
	3:   uint16(1491),
	4:   uint16(1254),
	5:   uint16(1367),
	6:   uint16(1254),
	7:   uint16(1254),
	8:   uint16(1254),
	9:   uint16(1254),
	10:  uint16(1491),
	11:  uint16(1491),
	12:  uint16(1491),
	13:  uint16(1254),
	14:  uint16(1254),
	15:  uint16(1254),
	16:  uint16(1254),
	17:  uint16(1254),
	18:  uint16(1254),
	19:  uint16(1397),
	20:  uint16(1397),
	21:  uint16(1544),
	22:  uint16(1287),
	23:  uint16(1254),
	24:  uint16(1254),
	25:  uint16(1254),
	26:  uint16(1254),
	27:  uint16(1254),
	28:  uint16(1254),
	29:  uint16(1254),
	30:  uint16(1254),
	31:  uint16(1254),
	32:  uint16(1254),
	33:  uint16(1254),
	34:  uint16(1254),
	35:  uint16(1490),
	36:  uint16(1254),
	37:  uint16(1254),
	38:  uint16(1254),
	39:  uint16(1254),
	40:  uint16(1578),
	41:  uint16(1578),
	42:  uint16(1254),
	43:  uint16(1254),
	44:  uint16(1254),
	45:  uint16(1254),
	46:  uint16(1254),
	47:  uint16(1563),
	48:  uint16(1562),
	49:  uint16(1254),
	50:  uint16(1254),
	51:  uint16(1254),
	52:  uint16(1406),
	53:  uint16(1254),
	54:  uint16(1413),
	55:  uint16(1254),
	56:  uint16(1254),
	57:  uint16(1254),
	58:  uint16(1254),
	59:  uint16(1254),
	60:  uint16(1492),
	61:  uint16(1493),
	62:  uint16(1254),
	63:  uint16(1254),
	64:  uint16(1254),
	65:  uint16(1543),
	66:  uint16(1545),
	67:  uint16(1508),
	68:  uint16(1420),
	69:  uint16(1419),
	70:  uint16(1418),
	71:  uint16(1417),
	72:  uint16(1526),
	73:  uint16(1385),
	74:  uint16(1411),
	75:  uint16(1404),
	76:  uint16(1408),
	77:  uint16(1487),
	78:  uint16(1488),
	79:  uint16(1486),
	80:  uint16(1641),
	81:  uint16(1493),
	82:  uint16(1492),
	83:  uint16(1254),
	84:  uint16(1407),
	85:  uint16(1455),
	86:  uint16(1471),
	87:  uint16(1454),
	88:  uint16(1254),
	89:  uint16(1254),
	90:  uint16(1254),
	91:  uint16(1254),
	92:  uint16(1254),
	93:  uint16(1254),
	94:  uint16(1254),
	95:  uint16(1254),
	96:  uint16(1254),
	97:  uint16(1254),
	98:  uint16(1254),
	99:  uint16(1254),
	100: uint16(1254),
	101: uint16(1254),
	102: uint16(1254),
	103: uint16(1254),
	104: uint16(1254),
	105: uint16(1254),
	106: uint16(1254),
	107: uint16(1254),
	108: uint16(1254),
	109: uint16(1254),
	110: uint16(1254),
	111: uint16(1254),
	112: uint16(1254),
	113: uint16(1254),
	114: uint16(1254),
	115: uint16(1254),
	116: uint16(1254),
	117: uint16(1254),
	118: uint16(1254),
	119: uint16(1254),
	120: uint16(1254),
	121: uint16(1254),
	122: uint16(1254),
	123: uint16(1254),
	124: uint16(1254),
	125: uint16(1254),
	126: uint16(1254),
	127: uint16(1254),
	128: uint16(1254),
	129: uint16(1254),
	130: uint16(1254),
	131: uint16(1254),
	132: uint16(1254),
	133: uint16(1254),
	134: uint16(1254),
	135: uint16(1254),
	136: uint16(1254),
	137: uint16(1254),
	138: uint16(1254),
	139: uint16(1254),
	140: uint16(1463),
	141: uint16(1470),
	142: uint16(1469),
	143: uint16(1468),
	144: uint16(1477),
	145: uint16(1467),
	146: uint16(1464),
	147: uint16(1457),
	148: uint16(1456),
	149: uint16(1458),
	150: uint16(1459),
	151: uint16(1278),
	152: uint16(1254),
	153: uint16(1275),
	154: uint16(1329),
	155: uint16(1254),
	156: uint16(1254),
	157: uint16(1254),
	158: uint16(1254),
	159: uint16(1254),
	160: uint16(1460),
	161: uint16(1287),
	162: uint16(1448),
	163: uint16(1447),
	164: uint16(1446),
	165: uint16(1254),
	166: uint16(1474),
	167: uint16(1461),
	168: uint16(1473),
	169: uint16(1472),
	170: uint16(1551),
	171: uint16(1615),
	172: uint16(1614),
	173: uint16(1509),
	174: uint16(1254),
	175: uint16(1254),
	176: uint16(1254),
	177: uint16(1254),
	178: uint16(1254),
	179: uint16(1254),
	180: uint16(1578),
	181: uint16(1254),
	182: uint16(1254),
	183: uint16(1254),
	184: uint16(1254),
	185: uint16(1254),
	186: uint16(1254),
	187: uint16(1254),
	188: uint16(1254),
	189: uint16(1254),
	190: uint16(1254),
	191: uint16(1254),
	192: uint16(1254),
	193: uint16(1254),
	194: uint16(1254),
	195: uint16(1254),
	196: uint16(1254),
	197: uint16(1254),
	198: uint16(1254),
	199: uint16(1254),
	200: uint16(1254),
	201: uint16(1254),
	202: uint16(1254),
	203: uint16(1387),
	204: uint16(1578),
	205: uint16(1578),
	206: uint16(1254),
	207: uint16(1287),
	208: uint16(1578),
	209: uint16(1578),
	210: uint16(1388),
	211: uint16(1388),
	212: uint16(1283),
	213: uint16(1283),
	214: uint16(1391),
	215: uint16(1558),
	216: uint16(1358),
	217: uint16(1358),
	218: uint16(1358),
	219: uint16(1358),
	220: uint16(1367),
	221: uint16(1358),
	222: uint16(1254),
	223: uint16(1254),
	224: uint16(1254),
	225: uint16(1254),
	226: uint16(1254),
	227: uint16(1254),
	228: uint16(1254),
	229: uint16(1254),
	230: uint16(1254),
	231: uint16(1254),
	232: uint16(1254),
	233: uint16(1254),
	234: uint16(1254),
	235: uint16(1254),
	236: uint16(1254),
	237: uint16(1548),
	238: uint16(1546),
	239: uint16(1254),
	240: uint16(1254),
	241: uint16(1254),
	242: uint16(1254),
	243: uint16(1254),
	244: uint16(1254),
	245: uint16(1254),
	246: uint16(1254),
	247: uint16(1254),
	248: uint16(1254),
	249: uint16(1254),
	250: uint16(1254),
	251: uint16(1254),
	252: uint16(1254),
	253: uint16(1254),
	254: uint16(1254),
	255: uint16(1254),
	256: uint16(1254),
	257: uint16(1254),
	258: uint16(1254),
	259: uint16(1254),
	260: uint16(1254),
	261: uint16(1254),
	262: uint16(1254),
	263: uint16(1254),
	264: uint16(1254),
	265: uint16(1254),
	266: uint16(1363),
	267: uint16(1254),
	268: uint16(1254),
	269: uint16(1254),
	270: uint16(1254),
	271: uint16(1254),
	272: uint16(1254),
	273: uint16(1254),
	274: uint16(1254),
	275: uint16(1254),
	276: uint16(1254),
	277: uint16(1254),
	278: uint16(1608),
	279: uint16(1254),
	280: uint16(1521),
	281: uint16(1343),
	282: uint16(1363),
	283: uint16(1363),
	284: uint16(1363),
	285: uint16(1363),
	286: uint16(1365),
	287: uint16(1344),
	288: uint16(1342),
	289: uint16(1357),
	290: uint16(1288),
	291: uint16(1261),
	292: uint16(1655),
	293: uint16(1423),
	294: uint16(1412),
	295: uint16(1364),
	296: uint16(1412),
	297: uint16(1652),
	298: uint16(1410),
	299: uint16(1423),
	300: uint16(1423),
	301: uint16(1410),
	302: uint16(1423),
	303: uint16(1364),
	304: uint16(1652),
	305: uint16(1304),
	306: uint16(1630),
	307: uint16(1299),
	308: uint16(1397),
	309: uint16(1397),
	310: uint16(1397),
	311: uint16(1387),
	312: uint16(1387),
	313: uint16(1387),
	314: uint16(1387),
	315: uint16(1391),
	316: uint16(1391),
	317: uint16(1489),
	318: uint16(1364),
	319: uint16(1357),
	320: uint16(1254),
	321: uint16(1655),
	322: uint16(1655),
	323: uint16(1373),
	324: uint16(1373),
	325: uint16(1654),
	326: uint16(1654),
	327: uint16(1373),
	328: uint16(1509),
	329: uint16(1638),
	330: uint16(1432),
	331: uint16(1332),
	332: uint16(1338),
	333: uint16(1338),
	334: uint16(1338),
	335: uint16(1338),
	336: uint16(1373),
	337: uint16(1272),
	338: uint16(1410),
	339: uint16(1638),
	340: uint16(1638),
	341: uint16(1410),
	342: uint16(1432),
	343: uint16(1332),
	344: uint16(1410),
	345: uint16(1332),
	346: uint16(1410),
	347: uint16(1373),
	348: uint16(1272),
	349: uint16(1525),
	350: uint16(1649),
	351: uint16(1373),
	352: uint16(1272),
	353: uint16(1499),
	354: uint16(1373),
	355: uint16(1272),
	356: uint16(1373),
	357: uint16(1272),
	358: uint16(1499),
	359: uint16(1330),
	360: uint16(1330),
	361: uint16(1330),
	362: uint16(1319),
	363: uint16(1254),
	364: uint16(1254),
	365: uint16(1499),
	366: uint16(1330),
	367: uint16(1304),
	368: uint16(1330),
	369: uint16(1319),
	370: uint16(1330),
	371: uint16(1330),
	372: uint16(1596),
	373: uint16(1254),
	374: uint16(1503),
	375: uint16(1503),
	376: uint16(1499),
	377: uint16(1373),
	378: uint16(1588),
	379: uint16(1588),
	380: uint16(1400),
	381: uint16(1400),
	382: uint16(1405),
	383: uint16(1391),
	384: uint16(1494),
	385: uint16(1373),
	386: uint16(1254),
	387: uint16(1405),
	388: uint16(1403),
	389: uint16(1401),
	390: uint16(1410),
	391: uint16(1322),
	392: uint16(1611),
	393: uint16(1611),
	394: uint16(1607),
	395: uint16(1607),
	396: uint16(1607),
	397: uint16(1660),
	398: uint16(1660),
	399: uint16(1558),
	400: uint16(1623),
	401: uint16(1287),
	402: uint16(1287),
	403: uint16(1287),
	404: uint16(1287),
	405: uint16(1623),
	406: uint16(1306),
	407: uint16(1306),
	408: uint16(1288),
	409: uint16(1288),
	410: uint16(1287),
	411: uint16(1623),
	412: uint16(1254),
	413: uint16(1254),
	414: uint16(1254),
	415: uint16(1254),
	416: uint16(1254),
	417: uint16(1254),
	418: uint16(1618),
	419: uint16(1254),
	420: uint16(1553),
	421: uint16(1510),
	422: uint16(1377),
	423: uint16(1254),
	424: uint16(1254),
	425: uint16(1254),
	426: uint16(1254),
	427: uint16(1254),
	428: uint16(1254),
	429: uint16(1254),
	430: uint16(1254),
	431: uint16(1254),
	432: uint16(1254),
	433: uint16(1254),
	434: uint16(1254),
	435: uint16(1254),
	436: uint16(1254),
	437: uint16(1254),
	438: uint16(1254),
	439: uint16(1564),
	440: uint16(1254),
	441: uint16(1254),
	442: uint16(1254),
	443: uint16(1254),
	444: uint16(1254),
	445: uint16(1254),
	446: uint16(1254),
	447: uint16(1254),
	448: uint16(1254),
	449: uint16(1254),
	450: uint16(1254),
	451: uint16(1437),
	452: uint16(1254),
	453: uint16(1257),
	454: uint16(1555),
	455: uint16(1254),
	456: uint16(1254),
	457: uint16(1254),
	458: uint16(1254),
	459: uint16(1254),
	460: uint16(1254),
	461: uint16(1254),
	462: uint16(1254),
	463: uint16(1414),
	464: uint16(1415),
	465: uint16(1378),
	466: uint16(1254),
	467: uint16(1254),
	468: uint16(1254),
	469: uint16(1254),
	470: uint16(1254),
	471: uint16(1254),
	472: uint16(1254),
	473: uint16(1429),
	474: uint16(1254),
	475: uint16(1254),
	476: uint16(1254),
	477: uint16(1424),
	478: uint16(1254),
	479: uint16(1254),
	480: uint16(1254),
	481: uint16(1254),
	482: uint16(1254),
	483: uint16(1254),
	484: uint16(1254),
	485: uint16(1254),
	486: uint16(1651),
	487: uint16(1254),
	488: uint16(1254),
	489: uint16(1254),
	490: uint16(1254),
	491: uint16(1254),
	492: uint16(1254),
	493: uint16(1524),
	494: uint16(1523),
	495: uint16(1254),
	496: uint16(1254),
	497: uint16(1375),
	498: uint16(1254),
	499: uint16(1254),
	500: uint16(1254),
	501: uint16(1254),
	502: uint16(1254),
	503: uint16(1254),
	504: uint16(1254),
	505: uint16(1254),
	506: uint16(1254),
	507: uint16(1254),
	508: uint16(1254),
	509: uint16(1254),
	510: uint16(1254),
	511: uint16(1302),
	512: uint16(1254),
	513: uint16(1254),
	514: uint16(1254),
	515: uint16(1254),
	516: uint16(1254),
	517: uint16(1254),
	518: uint16(1254),
	519: uint16(1254),
	520: uint16(1254),
	521: uint16(1254),
	522: uint16(1254),
	523: uint16(1254),
	524: uint16(1254),
	525: uint16(1254),
	526: uint16(1254),
	527: uint16(1254),
	528: uint16(1254),
	529: uint16(1254),
	530: uint16(1254),
	531: uint16(1254),
	532: uint16(1254),
	533: uint16(1254),
	534: uint16(1254),
	535: uint16(1402),
	536: uint16(1254),
	537: uint16(1254),
	538: uint16(1254),
	539: uint16(1254),
	540: uint16(1254),
	541: uint16(1254),
	542: uint16(1254),
	543: uint16(1254),
	544: uint16(1254),
	545: uint16(1254),
	546: uint16(1254),
	547: uint16(1254),
	548: uint16(1254),
	549: uint16(1254),
	550: uint16(1593),
	551: uint16(1392),
	552: uint16(1254),
	553: uint16(1254),
	554: uint16(1254),
	555: uint16(1254),
	556: uint16(1642),
	557: uint16(1254),
	558: uint16(1254),
	559: uint16(1254),
	560: uint16(1254),
	561: uint16(1352),
	562: uint16(1254),
	563: uint16(1254),
	564: uint16(1254),
	565: uint16(1254),
	566: uint16(1254),
	567: uint16(1254),
	568: uint16(1254),
	569: uint16(1254),
	570: uint16(1254),
	571: uint16(1254),
	572: uint16(1254),
	573: uint16(1634),
	574: uint16(1346),
	575: uint16(1438),
	576: uint16(1254),
	577: uint16(1441),
	578: uint16(1276),
	579: uint16(1254),
	580: uint16(1266),
	581: uint16(1254),
	582: uint16(1254),
}

/********** End of lemon-generated parsing tables *****************************/

// C documentation
//
//	/* The next table maps tokens (terminal symbols) into fallback tokens.
//	** If a construct like the following:
//	**
//	**      %fallback ID X Y Z.
//	**
//	** appears in the grammar, then ID becomes a fallback token for X, Y,
//	** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
//	** but it does not parse, the type of the token is changed to ID and
//	** the parse is retried before an error is thrown.
//	**
//	** This feature can be used, for example, to cause some keywords in a language
//	** to revert to identifiers if they keyword does not apply in the context where
//	** it appears.
//	*/
var _yyFallback = [186]uint16{
	2:   uint16(59),
	3:   uint16(59),
	4:   uint16(59),
	5:   uint16(59),
	7:   uint16(59),
	8:   uint16(59),
	9:   uint16(59),
	11:  uint16(59),
	12:  uint16(59),
	13:  uint16(59),
	14:  uint16(59),
	18:  uint16(59),
	21:  uint16(59),
	26:  uint16(59),
	27:  uint16(59),
	28:  uint16(59),
	29:  uint16(59),
	30:  uint16(59),
	31:  uint16(59),
	32:  uint16(59),
	33:  uint16(59),
	34:  uint16(59),
	35:  uint16(59),
	36:  uint16(59),
	37:  uint16(59),
	38:  uint16(59),
	39:  uint16(59),
	40:  uint16(59),
	41:  uint16(59),
	42:  uint16(59),
	46:  uint16(59),
	47:  uint16(59),
	60:  uint16(59),
	61:  uint16(59),
	62:  uint16(59),
	63:  uint16(59),
	64:  uint16(59),
	65:  uint16(59),
	66:  uint16(59),
	67:  uint16(59),
	68:  uint16(59),
	69:  uint16(59),
	70:  uint16(59),
	71:  uint16(59),
	72:  uint16(59),
	73:  uint16(59),
	74:  uint16(59),
	75:  uint16(59),
	76:  uint16(59),
	77:  uint16(59),
	78:  uint16(59),
	79:  uint16(59),
	80:  uint16(59),
	81:  uint16(59),
	82:  uint16(59),
	83:  uint16(59),
	84:  uint16(59),
	85:  uint16(59),
	86:  uint16(59),
	87:  uint16(59),
	88:  uint16(59),
	89:  uint16(59),
	90:  uint16(59),
	91:  uint16(59),
	92:  uint16(59),
	93:  uint16(59),
	94:  uint16(59),
	95:  uint16(59),
	96:  uint16(59),
	97:  uint16(59),
	98:  uint16(59),
	99:  uint16(59),
	100: uint16(59),
}

/* The following structure represents a single element of the
** parser's stack.  Information stored includes:
**
**   +  The state number for the parser at this level of the stack.
**
**   +  The value of the token stored at this level of the stack.
**      (In other words, the "major" token.)
**
**   +  The semantic value stored at this level of the stack.  This is
**      the information used by the action routines in the grammar.
**      It is sometimes called the "minor" token.
**
** After the "shift" half of a SHIFTREDUCE action, the stateno field
** actually contains the reduce action for the second half of the
** SHIFTREDUCE.
 */
type TyyStackEntry1 = struct {
	Fstateno uint16
	Fmajor   uint16
	Fminor   TYYMINORTYPE
}

type yyStackEntry1 = TyyStackEntry1

type TyyStackEntry = struct {
	Fstateno uint16
	Fmajor   uint16
	Fminor   TYYMINORTYPE
}

type yyStackEntry = TyyStackEntry

/* The state of the parser is completely contained in an instance of
** the following structure */
type TyyParser1 = struct {
	Fyytos      uintptr
	FpParse     uintptr
	FyystackEnd uintptr
	Fyystack    uintptr
	Fyystk0     [100]TyyStackEntry
}

type yyParser1 = TyyParser1

type TyyParser = struct {
	Fyytos      uintptr
	FpParse     uintptr
	FyystackEnd uintptr
	Fyystack    uintptr
	Fyystk0     [100]TyyStackEntry
}

type yyParser = TyyParser

/* #include <assert.h> */

// C documentation
//
//	/*
//	** Try to increase the size of the parser stack.  Return the number
//	** of errors.  Return 0 on success.
//	*/
func _yyGrowStack(tls *libc.TLS, p uintptr) (r int32) {
	var idx, newSize, oldSize int32
	var pNew uintptr
	_, _, _, _ = idx, newSize, oldSize, pNew
	oldSize = int32(1) + (int32((*TyyParser)(unsafe.Pointer(p)).FyystackEnd)-int32((*TyyParser)(unsafe.Pointer(p)).Fyystack))/12
	newSize = oldSize*int32(2) + int32(100)
	idx = (int32((*TyyParser)(unsafe.Pointer(p)).Fyytos) - int32((*TyyParser)(unsafe.Pointer(p)).Fyystack)) / 12
	if (*TyyParser)(unsafe.Pointer(p)).Fyystack == p+16 {
		pNew = _parserStackRealloc(tls, uintptr(0), uint64(uint32(uint32(newSize))*uint32(12)))
		if pNew == uintptr(0) {
			return int32(1)
		}
		libc.Xmemcpy(tls, pNew, (*TyyParser)(unsafe.Pointer(p)).Fyystack, uint32(uint32(oldSize))*uint32(12))
	} else {
		pNew = _parserStackRealloc(tls, (*TyyParser)(unsafe.Pointer(p)).Fyystack, uint64(uint32(uint32(newSize))*uint32(12)))
		if pNew == uintptr(0) {
			return int32(1)
		}
	}
	(*TyyParser)(unsafe.Pointer(p)).Fyystack = pNew
	(*TyyParser)(unsafe.Pointer(p)).Fyytos = (*TyyParser)(unsafe.Pointer(p)).Fyystack + uintptr(idx)*12
	(*TyyParser)(unsafe.Pointer(p)).FyystackEnd = (*TyyParser)(unsafe.Pointer(p)).Fyystack + uintptr(newSize-int32(1))*12
	return 0
}

/* Datatype of the argument to the memory allocated passed as the
** second argument to sqlite3ParserAlloc() below.  This can be changed by
** putting an appropriate #define in the %include section of the input
** grammar.
 */

// C documentation
//
//	/* Initialize a new parser that has already been allocated.
//	*/
func _sqlite3ParserInit(tls *libc.TLS, yypRawParser uintptr, pParse uintptr) {
	var yypParser uintptr
	_ = yypParser
	yypParser = yypRawParser
	(*TyyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
	(*TyyParser)(unsafe.Pointer(yypParser)).Fyystack = yypParser + 16
	(*TyyParser)(unsafe.Pointer(yypParser)).FyystackEnd = (*TyyParser)(unsafe.Pointer(yypParser)).Fyystack + uintptr(libc.Int32FromInt32(YYSTACKDEPTH)-libc.Int32FromInt32(1))*12
	(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos = (*TyyParser)(unsafe.Pointer(yypParser)).Fyystack
	(*(*TyyStackEntry)(unsafe.Pointer((*TyyParser)(unsafe.Pointer(yypParser)).Fyystack))).Fstateno = uint16(0)
	(*(*TyyStackEntry)(unsafe.Pointer((*TyyParser)(unsafe.Pointer(yypParser)).Fyystack))).Fmajor = uint16(0)
}

// C documentation
//
//	/* The following function deletes the "minor type" or semantic value
//	** associated with a symbol.  The symbol can be either a terminal
//	** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
//	** a pointer to the value to be deleted.  The code used to do the
//	** deletions is derived from the %destructor and/or %token_destructor
//	** directives of the input grammar.
//	*/
func _yy_destructor(tls *libc.TLS, yypParser uintptr, yymajor uint16, yypminor uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*TyyParser)(unsafe.Pointer(yypParser)).FpParse
	switch int32(int32(yymajor)) {
	/* Here is inserted the actions which take place when a
	 ** terminal or non-terminal is destroyed.  This can happen
	 ** when the symbol is popped from the stack during a
	 ** reduce or during error processing or when a parser is
	 ** being destroyed before it is finished parsing.
	 **
	 ** Note: during a reduce, the only symbols destroyed are those
	 ** which appear on the RHS of the rule, but which are *not* used
	 ** inside the C code.
	 */
	/********* Begin destructor definitions ***************************************/
	case int32(205): /* select */
		fallthrough
	case int32(240): /* selectnowith */
		fallthrough
	case int32(241): /* oneselect */
		fallthrough
	case int32(253): /* values */
		fallthrough
	case int32(255): /* mvalues */
		_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(217): /* term */
		fallthrough
	case int32(218): /* expr */
		fallthrough
	case int32(247): /* where_opt */
		fallthrough
	case int32(249): /* having_opt */
		fallthrough
	case int32(269): /* where_opt_ret */
		fallthrough
	case int32(280): /* case_operand */
		fallthrough
	case int32(282): /* case_else */
		fallthrough
	case int32(285): /* vinto */
		fallthrough
	case int32(292): /* when_clause */
		fallthrough
	case int32(297): /* key_opt */
		fallthrough
	case int32(314): /* filter_clause */
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(222): /* eidlist_opt */
		fallthrough
	case int32(232): /* sortlist */
		fallthrough
	case int32(233): /* eidlist */
		fallthrough
	case int32(245): /* selcollist */
		fallthrough
	case int32(248): /* groupby_opt */
		fallthrough
	case int32(250): /* orderby_opt */
		fallthrough
	case int32(254): /* nexprlist */
		fallthrough
	case int32(256): /* sclp */
		fallthrough
	case int32(263): /* exprlist */
		fallthrough
	case int32(270): /* setlist */
		fallthrough
	case int32(279): /* paren_exprlist */
		fallthrough
	case int32(281): /* case_exprlist */
		fallthrough
	case int32(313): /* part_opt */
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(239): /* fullname */
		fallthrough
	case int32(246): /* from */
		fallthrough
	case int32(258): /* seltablist */
		fallthrough
	case int32(259): /* stl_prefix */
		fallthrough
	case int32(264): /* xfullname */
		_sqlite3SrcListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(242): /* wqlist */
		_sqlite3WithDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(252): /* window_clause */
		fallthrough
	case int32(309): /* windowdefn_list */
		_sqlite3WindowListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(265): /* idlist */
		fallthrough
	case int32(272): /* idlist_opt */
		_sqlite3IdListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(275): /* filter_over */
		fallthrough
	case int32(310): /* windowdefn */
		fallthrough
	case int32(311): /* window */
		fallthrough
	case int32(312): /* frame_opt */
		fallthrough
	case int32(315): /* over_clause */
		_sqlite3WindowDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(288): /* trigger_cmd_list */
		fallthrough
	case int32(293): /* trigger_cmd */
		_sqlite3DeleteTriggerStep(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
	case int32(290): /* trigger_event */
		_sqlite3IdListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*(*TTrigEvent)(unsafe.Pointer(yypminor))).Fb)
	case int32(317): /* frame_bound */
		fallthrough
	case int32(318): /* frame_bound_s */
		fallthrough
	case int32(319): /* frame_bound_e */
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*(*TFrameBound)(unsafe.Pointer(yypminor))).FpExpr)
		break
		/********* End destructor definitions *****************************************/
		fallthrough
	default:
		break /* If no destructor action specified: do nothing */
	}
}

// C documentation
//
//	/*
//	** Pop the parser's stack once.
//	**
//	** If there is a destructor routine associated with the token which
//	** is popped from the stack, then call it.
//	*/
func _yy_pop_parser_stack(tls *libc.TLS, pParser uintptr) {
	var yytos, v1, v2 uintptr
	_, _, _ = yytos, v1, v2
	v2 = pParser
	v1 = *(*uintptr)(unsafe.Pointer(v2))
	*(*uintptr)(unsafe.Pointer(v2)) -= 12
	yytos = v1
	_yy_destructor(tls, pParser, (*TyyStackEntry)(unsafe.Pointer(yytos)).Fmajor, yytos+4)
}

// C documentation
//
//	/*
//	** Clear all secondary memory allocations from the parser
//	*/
func _sqlite3ParserFinalize(tls *libc.TLS, p uintptr) {
	var pParser, yytos uintptr
	_, _ = pParser, yytos
	pParser = p
	/* In-lined version of calling yy_pop_parser_stack() for each
	 ** element left in the stack */
	yytos = (*TyyParser)(unsafe.Pointer(pParser)).Fyytos
	for yytos > (*TyyParser)(unsafe.Pointer(pParser)).Fyystack {
		if int32((*TyyStackEntry)(unsafe.Pointer(yytos)).Fmajor) >= int32(YY_MIN_DSTRCTR) {
			_yy_destructor(tls, pParser, (*TyyStackEntry)(unsafe.Pointer(yytos)).Fmajor, yytos+4)
		}
		yytos -= 12
	}
	if (*TyyParser)(unsafe.Pointer(pParser)).Fyystack != pParser+16 {
		Xsqlite3_free(tls, (*TyyParser)(unsafe.Pointer(pParser)).Fyystack)
	}
}

/*
** Return the peak depth of the stack for a parser.
 */

/* This array of booleans keeps track of the parser statement
** coverage.  The element yycoverage[X][Y] is set when the parser
** is in state X and has a lookahead token Y.  In a well-tested
** systems, every element of this matrix should end up being set.
 */

/*
** Write into out a description of every state/lookahead combination that
**
**   (1)  has not been used by the parser, and
**   (2)  is not a syntax error.
**
** Return the number of missed state/lookahead combinations.
 */

// C documentation
//
//	/*
//	** Find the appropriate action for a parser given the terminal
//	** look-ahead token iLookAhead.
//	*/
func _yy_find_shift_action(tls *libc.TLS, iLookAhead uint16, stateno uint16) (r uint16) {
	var i, j int32
	var iFallback uint16
	_, _, _ = i, iFallback, j
	if int32(int32(stateno)) > int32(YY_MAX_SHIFT) {
		return stateno
	}
	for cond := true; cond; cond = int32(1) != 0 {
		i = int32(_yy_shift_ofst[stateno])
		i += int32(int32(iLookAhead))
		if int32(_yy_lookahead[i]) != int32(int32(iLookAhead)) { /* Fallback token */
			iFallback = _yyFallback[iLookAhead]
			if int32(int32(iFallback)) != 0 {
				/* Fallback loop must terminate */
				iLookAhead = iFallback
				continue
			}
			j = i - int32(int32(iLookAhead)) + int32(YYWILDCARD)
			if int32(_yy_lookahead[j]) == int32(YYWILDCARD) && int32(int32(iLookAhead)) > 0 {
				return _yy_action[j]
			}
			return _yy_default[stateno]
		} else {
			return _yy_action[i]
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Find the appropriate action for a parser given the non-terminal
//	** look-ahead token iLookAhead.
//	*/
func _yy_find_reduce_action(tls *libc.TLS, stateno uint16, iLookAhead uint16) (r uint16) {
	var i int32
	_ = i
	i = int32(_yy_reduce_ofst[stateno])
	i += int32(int32(iLookAhead))
	return _yy_action[i]
}

// C documentation
//
//	/*
//	** The following routine is called if the stack overflows.
//	*/
func _yyStackOverflow(tls *libc.TLS, yypParser uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*TyyParser)(unsafe.Pointer(yypParser)).FpParse
	for (*TyyParser)(unsafe.Pointer(yypParser)).Fyytos > (*TyyParser)(unsafe.Pointer(yypParser)).Fyystack {
		_yy_pop_parser_stack(tls, yypParser)
	}
	/* Here code is inserted which will execute if the parser
	 ** stack every overflows */
	/******** Begin %stack_overflow code ******************************************/
	_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb)
	/******** End %stack_overflow code ********************************************/
	/* Suppress warning about unused %extra_argument var */
	(*TyyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
}

/*
** Print tracing information for a SHIFT action
 */

// C documentation
//
//	/*
//	** Perform a shift action.
//	*/
func _yy_shift(tls *libc.TLS, yypParser uintptr, yyNewState uint16, yyMajor uint16, yyMinor TToken) {
	var yytos uintptr
	_ = yytos
	(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos += 12
	yytos = (*TyyParser)(unsafe.Pointer(yypParser)).Fyytos
	if yytos > (*TyyParser)(unsafe.Pointer(yypParser)).FyystackEnd {
		if _yyGrowStack(tls, yypParser) != 0 {
			(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos -= 12
			_yyStackOverflow(tls, yypParser)
			return
		}
		yytos = (*TyyParser)(unsafe.Pointer(yypParser)).Fyytos
	}
	if int32(int32(yyNewState)) > int32(YY_MAX_SHIFT) {
		yyNewState = uint16(int32(yyNewState) + (libc.Int32FromInt32(YY_MIN_REDUCE) - libc.Int32FromInt32(YY_MIN_SHIFTREDUCE)))
	}
	(*TyyStackEntry)(unsafe.Pointer(yytos)).Fstateno = yyNewState
	(*TyyStackEntry)(unsafe.Pointer(yytos)).Fmajor = yyMajor
	*(*TToken)(unsafe.Pointer(yytos + 4)) = yyMinor
}

// C documentation
//
//	/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
//	** of that rule */
var _yyRuleInfoLhs = [409]uint16{
	0:   uint16(190),
	1:   uint16(190),
	2:   uint16(189),
	3:   uint16(191),
	4:   uint16(192),
	5:   uint16(192),
	6:   uint16(192),
	7:   uint16(192),
	8:   uint16(191),
	9:   uint16(191),
	10:  uint16(191),
	11:  uint16(191),
	12:  uint16(191),
	13:  uint16(196),
	14:  uint16(198),
	15:  uint16(200),
	16:  uint16(200),
	17:  uint16(199),
	18:  uint16(199),
	19:  uint16(197),
	20:  uint16(197),
	21:  uint16(204),
	22:  uint16(204),
	23:  uint16(206),
	24:  uint16(206),
	25:  uint16(207),
	26:  uint16(209),
	27:  uint16(209),
	28:  uint16(209),
	29:  uint16(210),
	30:  uint16(214),
	31:  uint16(215),
	32:  uint16(216),
	33:  uint16(216),
	34:  uint16(216),
	35:  uint16(216),
	36:  uint16(216),
	37:  uint16(216),
	38:  uint16(216),
	39:  uint16(216),
	40:  uint16(216),
	41:  uint16(216),
	42:  uint16(216),
	43:  uint16(216),
	44:  uint16(216),
	45:  uint16(225),
	46:  uint16(225),
	47:  uint16(221),
	48:  uint16(221),
	49:  uint16(223),
	50:  uint16(223),
	51:  uint16(226),
	52:  uint16(226),
	53:  uint16(226),
	54:  uint16(226),
	55:  uint16(227),
	56:  uint16(227),
	57:  uint16(227),
	58:  uint16(227),
	59:  uint16(227),
	60:  uint16(224),
	61:  uint16(224),
	62:  uint16(228),
	63:  uint16(228),
	64:  uint16(228),
	65:  uint16(203),
	66:  uint16(230),
	67:  uint16(231),
	68:  uint16(231),
	69:  uint16(231),
	70:  uint16(231),
	71:  uint16(231),
	72:  uint16(234),
	73:  uint16(219),
	74:  uint16(219),
	75:  uint16(235),
	76:  uint16(235),
	77:  uint16(236),
	78:  uint16(236),
	79:  uint16(191),
	80:  uint16(238),
	81:  uint16(238),
	82:  uint16(191),
	83:  uint16(191),
	84:  uint16(191),
	85:  uint16(205),
	86:  uint16(205),
	87:  uint16(205),
	88:  uint16(240),
	89:  uint16(243),
	90:  uint16(243),
	91:  uint16(243),
	92:  uint16(241),
	93:  uint16(241),
	94:  uint16(253),
	95:  uint16(241),
	96:  uint16(255),
	97:  uint16(255),
	98:  uint16(244),
	99:  uint16(244),
	100: uint16(244),
	101: uint16(256),
	102: uint16(245),
	103: uint16(245),
	104: uint16(245),
	105: uint16(257),
	106: uint16(257),
	107: uint16(246),
	108: uint16(246),
	109: uint16(259),
	110: uint16(259),
	111: uint16(258),
	112: uint16(258),
	113: uint16(258),
	114: uint16(258),
	115: uint16(258),
	116: uint16(201),
	117: uint16(201),
	118: uint16(239),
	119: uint16(239),
	120: uint16(264),
	121: uint16(264),
	122: uint16(264),
	123: uint16(264),
	124: uint16(260),
	125: uint16(260),
	126: uint16(260),
	127: uint16(260),
	128: uint16(261),
	129: uint16(261),
	130: uint16(261),
	131: uint16(266),
	132: uint16(262),
	133: uint16(262),
	134: uint16(250),
	135: uint16(250),
	136: uint16(232),
	137: uint16(232),
	138: uint16(220),
	139: uint16(220),
	140: uint16(220),
	141: uint16(267),
	142: uint16(267),
	143: uint16(267),
	144: uint16(248),
	145: uint16(248),
	146: uint16(249),
	147: uint16(249),
	148: uint16(251),
	149: uint16(251),
	150: uint16(251),
	151: uint16(251),
	152: uint16(191),
	153: uint16(247),
	154: uint16(247),
	155: uint16(269),
	156: uint16(269),
	157: uint16(269),
	158: uint16(269),
	159: uint16(191),
	160: uint16(270),
	161: uint16(270),
	162: uint16(270),
	163: uint16(270),
	164: uint16(191),
	165: uint16(191),
	166: uint16(273),
	167: uint16(273),
	168: uint16(273),
	169: uint16(273),
	170: uint16(273),
	171: uint16(273),
	172: uint16(274),
	173: uint16(271),
	174: uint16(271),
	175: uint16(272),
	176: uint16(272),
	177: uint16(265),
	178: uint16(265),
	179: uint16(218),
	180: uint16(218),
	181: uint16(218),
	182: uint16(218),
	183: uint16(217),
	184: uint16(217),
	185: uint16(217),
	186: uint16(218),
	187: uint16(218),
	188: uint16(218),
	189: uint16(218),
	190: uint16(218),
	191: uint16(218),
	192: uint16(218),
	193: uint16(218),
	194: uint16(218),
	195: uint16(217),
	196: uint16(218),
	197: uint16(218),
	198: uint16(218),
	199: uint16(218),
	200: uint16(218),
	201: uint16(218),
	202: uint16(218),
	203: uint16(218),
	204: uint16(218),
	205: uint16(276),
	206: uint16(218),
	207: uint16(218),
	208: uint16(218),
	209: uint16(218),
	210: uint16(218),
	211: uint16(218),
	212: uint16(218),
	213: uint16(218),
	214: uint16(218),
	215: uint16(218),
	216: uint16(218),
	217: uint16(218),
	218: uint16(277),
	219: uint16(277),
	220: uint16(218),
	221: uint16(278),
	222: uint16(278),
	223: uint16(218),
	224: uint16(218),
	225: uint16(218),
	226: uint16(218),
	227: uint16(218),
	228: uint16(218),
	229: uint16(281),
	230: uint16(281),
	231: uint16(282),
	232: uint16(282),
	233: uint16(280),
	234: uint16(263),
	235: uint16(254),
	236: uint16(254),
	237: uint16(279),
	238: uint16(279),
	239: uint16(191),
	240: uint16(283),
	241: uint16(283),
	242: uint16(222),
	243: uint16(222),
	244: uint16(233),
	245: uint16(233),
	246: uint16(284),
	247: uint16(284),
	248: uint16(191),
	249: uint16(191),
	250: uint16(191),
	251: uint16(285),
	252: uint16(285),
	253: uint16(191),
	254: uint16(191),
	255: uint16(191),
	256: uint16(191),
	257: uint16(191),
	258: uint16(212),
	259: uint16(213),
	260: uint16(191),
	261: uint16(287),
	262: uint16(289),
	263: uint16(289),
	264: uint16(289),
	265: uint16(290),
	266: uint16(290),
	267: uint16(290),
	268: uint16(292),
	269: uint16(292),
	270: uint16(288),
	271: uint16(288),
	272: uint16(294),
	273: uint16(295),
	274: uint16(295),
	275: uint16(293),
	276: uint16(293),
	277: uint16(293),
	278: uint16(293),
	279: uint16(218),
	280: uint16(218),
	281: uint16(237),
	282: uint16(237),
	283: uint16(237),
	284: uint16(191),
	285: uint16(191),
	286: uint16(191),
	287: uint16(297),
	288: uint16(297),
	289: uint16(191),
	290: uint16(191),
	291: uint16(191),
	292: uint16(191),
	293: uint16(191),
	294: uint16(191),
	295: uint16(191),
	296: uint16(298),
	297: uint16(191),
	298: uint16(191),
	299: uint16(191),
	300: uint16(300),
	301: uint16(302),
	302: uint16(303),
	303: uint16(303),
	304: uint16(304),
	305: uint16(268),
	306: uint16(268),
	307: uint16(307),
	308: uint16(307),
	309: uint16(307),
	310: uint16(306),
	311: uint16(308),
	312: uint16(242),
	313: uint16(242),
	314: uint16(309),
	315: uint16(310),
	316: uint16(311),
	317: uint16(311),
	318: uint16(311),
	319: uint16(311),
	320: uint16(311),
	321: uint16(312),
	322: uint16(312),
	323: uint16(312),
	324: uint16(316),
	325: uint16(318),
	326: uint16(318),
	327: uint16(319),
	328: uint16(319),
	329: uint16(317),
	330: uint16(317),
	331: uint16(320),
	332: uint16(320),
	333: uint16(321),
	334: uint16(321),
	335: uint16(321),
	336: uint16(252),
	337: uint16(275),
	338: uint16(275),
	339: uint16(275),
	340: uint16(315),
	341: uint16(315),
	342: uint16(314),
	343: uint16(217),
	344: uint16(186),
	345: uint16(187),
	346: uint16(187),
	347: uint16(188),
	348: uint16(188),
	349: uint16(188),
	350: uint16(193),
	351: uint16(193),
	352: uint16(193),
	353: uint16(195),
	354: uint16(195),
	355: uint16(191),
	356: uint16(204),
	357: uint16(202),
	358: uint16(202),
	359: uint16(194),
	360: uint16(194),
	361: uint16(209),
	362: uint16(210),
	363: uint16(211),
	364: uint16(211),
	365: uint16(208),
	366: uint16(208),
	367: uint16(216),
	368: uint16(216),
	369: uint16(216),
	370: uint16(203),
	371: uint16(229),
	372: uint16(229),
	373: uint16(230),
	374: uint16(234),
	375: uint16(236),
	376: uint16(240),
	377: uint16(241),
	378: uint16(256),
	379: uint16(257),
	380: uint16(266),
	381: uint16(274),
	382: uint16(218),
	383: uint16(276),
	384: uint16(280),
	385: uint16(263),
	386: uint16(286),
	387: uint16(286),
	388: uint16(286),
	389: uint16(286),
	390: uint16(286),
	391: uint16(212),
	392: uint16(291),
	393: uint16(291),
	394: uint16(294),
	395: uint16(295),
	396: uint16(296),
	397: uint16(296),
	398: uint16(299),
	399: uint16(299),
	400: uint16(301),
	401: uint16(301),
	402: uint16(302),
	403: uint16(305),
	404: uint16(305),
	405: uint16(305),
	406: uint16(268),
	407: uint16(309),
	408: uint16(311),
}

// C documentation
//
//	/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
//	** of symbols on the right-hand side of that rule. */
var _yyRuleInfoNRhs = [409]int8{
	0:   int8(-int32(1)),
	1:   int8(-int32(3)),
	2:   int8(-int32(1)),
	3:   int8(-int32(3)),
	5:   int8(-int32(1)),
	6:   int8(-int32(1)),
	7:   int8(-int32(1)),
	8:   int8(-int32(2)),
	9:   int8(-int32(2)),
	10:  int8(-int32(2)),
	11:  int8(-int32(3)),
	12:  int8(-int32(5)),
	13:  int8(-int32(6)),
	14:  int8(-int32(1)),
	16:  int8(-int32(3)),
	17:  int8(-int32(1)),
	19:  int8(-int32(5)),
	20:  int8(-int32(2)),
	22:  int8(-int32(3)),
	23:  int8(-int32(2)),
	24:  int8(-int32(1)),
	25:  int8(-int32(2)),
	27:  int8(-int32(4)),
	28:  int8(-int32(6)),
	29:  int8(-int32(2)),
	32:  int8(-int32(2)),
	33:  int8(-int32(3)),
	34:  int8(-int32(4)),
	35:  int8(-int32(4)),
	36:  int8(-int32(4)),
	37:  int8(-int32(3)),
	38:  int8(-int32(3)),
	39:  int8(-int32(5)),
	40:  int8(-int32(2)),
	41:  int8(-int32(4)),
	42:  int8(-int32(4)),
	43:  int8(-int32(1)),
	44:  int8(-int32(2)),
	45:  int8(-int32(3)),
	46:  int8(-int32(4)),
	48:  int8(-int32(1)),
	50:  int8(-int32(2)),
	51:  int8(-int32(2)),
	52:  int8(-int32(3)),
	53:  int8(-int32(3)),
	54:  int8(-int32(3)),
	55:  int8(-int32(2)),
	56:  int8(-int32(2)),
	57:  int8(-int32(1)),
	58:  int8(-int32(1)),
	59:  int8(-int32(2)),
	60:  int8(-int32(3)),
	61:  int8(-int32(2)),
	63:  int8(-int32(2)),
	64:  int8(-int32(2)),
	66:  int8(-int32(1)),
	67:  int8(-int32(2)),
	68:  int8(-int32(7)),
	69:  int8(-int32(5)),
	70:  int8(-int32(5)),
	71:  int8(-int32(10)),
	74:  int8(-int32(3)),
	76:  int8(-int32(2)),
	77:  int8(-int32(1)),
	78:  int8(-int32(1)),
	79:  int8(-int32(4)),
	80:  int8(-int32(2)),
	82:  int8(-int32(9)),
	83:  int8(-int32(4)),
	84:  int8(-int32(1)),
	85:  int8(-int32(3)),
	86:  int8(-int32(4)),
	87:  int8(-int32(1)),
	88:  int8(-int32(3)),
	89:  int8(-int32(1)),
	90:  int8(-int32(2)),
	91:  int8(-int32(1)),
	92:  int8(-int32(9)),
	93:  int8(-int32(10)),
	94:  int8(-int32(4)),
	95:  int8(-int32(1)),
	96:  int8(-int32(5)),
	97:  int8(-int32(5)),
	98:  int8(-int32(1)),
	99:  int8(-int32(1)),
	102: int8(-int32(5)),
	103: int8(-int32(3)),
	104: int8(-int32(5)),
	105: int8(-int32(2)),
	108: int8(-int32(2)),
	109: int8(-int32(2)),
	111: int8(-int32(5)),
	112: int8(-int32(6)),
	113: int8(-int32(8)),
	114: int8(-int32(6)),
	115: int8(-int32(6)),
	117: int8(-int32(2)),
	118: int8(-int32(1)),
	119: int8(-int32(3)),
	120: int8(-int32(1)),
	121: int8(-int32(3)),
	122: int8(-int32(5)),
	123: int8(-int32(3)),
	124: int8(-int32(1)),
	125: int8(-int32(2)),
	126: int8(-int32(3)),
	127: int8(-int32(4)),
	128: int8(-int32(2)),
	129: int8(-int32(4)),
	132: int8(-int32(3)),
	133: int8(-int32(2)),
	135: int8(-int32(3)),
	136: int8(-int32(5)),
	137: int8(-int32(3)),
	138: int8(-int32(1)),
	139: int8(-int32(1)),
	141: int8(-int32(2)),
	142: int8(-int32(2)),
	145: int8(-int32(3)),
	147: int8(-int32(2)),
	149: int8(-int32(2)),
	150: int8(-int32(4)),
	151: int8(-int32(4)),
	152: int8(-int32(6)),
	154: int8(-int32(2)),
	156: int8(-int32(2)),
	157: int8(-int32(2)),
	158: int8(-int32(4)),
	159: int8(-int32(9)),
	160: int8(-int32(5)),
	161: int8(-int32(7)),
	162: int8(-int32(3)),
	163: int8(-int32(5)),
	164: int8(-int32(7)),
	165: int8(-int32(8)),
	167: int8(-int32(2)),
	168: int8(-int32(12)),
	169: int8(-int32(9)),
	170: int8(-int32(5)),
	171: int8(-int32(8)),
	172: int8(-int32(2)),
	173: int8(-int32(2)),
	174: int8(-int32(1)),
	176: int8(-int32(3)),
	177: int8(-int32(3)),
	178: int8(-int32(1)),
	179: int8(-int32(3)),
	180: int8(-int32(1)),
	181: int8(-int32(3)),
	182: int8(-int32(5)),
	183: int8(-int32(1)),
	184: int8(-int32(1)),
	185: int8(-int32(1)),
	186: int8(-int32(1)),
	187: int8(-int32(3)),
	188: int8(-int32(6)),
	189: int8(-int32(5)),
	190: int8(-int32(8)),
	191: int8(-int32(4)),
	192: int8(-int32(6)),
	193: int8(-int32(9)),
	194: int8(-int32(5)),
	195: int8(-int32(1)),
	196: int8(-int32(5)),
	197: int8(-int32(3)),
	198: int8(-int32(3)),
	199: int8(-int32(3)),
	200: int8(-int32(3)),
	201: int8(-int32(3)),
	202: int8(-int32(3)),
	203: int8(-int32(3)),
	204: int8(-int32(3)),
	205: int8(-int32(2)),
	206: int8(-int32(3)),
	207: int8(-int32(5)),
	208: int8(-int32(2)),
	209: int8(-int32(3)),
	210: int8(-int32(3)),
	211: int8(-int32(4)),
	212: int8(-int32(6)),
	213: int8(-int32(5)),
	214: int8(-int32(2)),
	215: int8(-int32(2)),
	216: int8(-int32(2)),
	217: int8(-int32(3)),
	218: int8(-int32(1)),
	219: int8(-int32(2)),
	220: int8(-int32(5)),
	221: int8(-int32(1)),
	222: int8(-int32(2)),
	223: int8(-int32(5)),
	224: int8(-int32(3)),
	225: int8(-int32(5)),
	226: int8(-int32(5)),
	227: int8(-int32(4)),
	228: int8(-int32(5)),
	229: int8(-int32(5)),
	230: int8(-int32(4)),
	231: int8(-int32(2)),
	235: int8(-int32(3)),
	236: int8(-int32(1)),
	238: int8(-int32(3)),
	239: int8(-int32(12)),
	240: int8(-int32(1)),
	243: int8(-int32(3)),
	244: int8(-int32(5)),
	245: int8(-int32(3)),
	247: int8(-int32(2)),
	248: int8(-int32(4)),
	249: int8(-int32(2)),
	250: int8(-int32(3)),
	251: int8(-int32(2)),
	253: int8(-int32(3)),
	254: int8(-int32(5)),
	255: int8(-int32(6)),
	256: int8(-int32(5)),
	257: int8(-int32(6)),
	258: int8(-int32(2)),
	259: int8(-int32(2)),
	260: int8(-int32(5)),
	261: int8(-int32(11)),
	262: int8(-int32(1)),
	263: int8(-int32(2)),
	265: int8(-int32(1)),
	266: int8(-int32(1)),
	267: int8(-int32(3)),
	269: int8(-int32(2)),
	270: int8(-int32(3)),
	271: int8(-int32(2)),
	272: int8(-int32(3)),
	273: int8(-int32(3)),
	274: int8(-int32(2)),
	275: int8(-int32(9)),
	276: int8(-int32(8)),
	277: int8(-int32(6)),
	278: int8(-int32(3)),
	279: int8(-int32(4)),
	280: int8(-int32(6)),
	281: int8(-int32(1)),
	282: int8(-int32(1)),
	283: int8(-int32(1)),
	284: int8(-int32(4)),
	285: int8(-int32(6)),
	286: int8(-int32(3)),
	288: int8(-int32(2)),
	289: int8(-int32(1)),
	290: int8(-int32(3)),
	291: int8(-int32(1)),
	292: int8(-int32(3)),
	293: int8(-int32(6)),
	294: int8(-int32(7)),
	295: int8(-int32(6)),
	296: int8(-int32(1)),
	297: int8(-int32(8)),
	298: int8(-int32(1)),
	299: int8(-int32(4)),
	300: int8(-int32(8)),
	302: int8(-int32(1)),
	303: int8(-int32(3)),
	304: int8(-int32(1)),
	305: int8(-int32(2)),
	306: int8(-int32(3)),
	307: int8(-int32(1)),
	308: int8(-int32(2)),
	309: int8(-int32(3)),
	310: int8(-int32(6)),
	311: int8(-int32(1)),
	312: int8(-int32(1)),
	313: int8(-int32(3)),
	314: int8(-int32(3)),
	315: int8(-int32(5)),
	316: int8(-int32(5)),
	317: int8(-int32(6)),
	318: int8(-int32(4)),
	319: int8(-int32(5)),
	320: int8(-int32(2)),
	322: int8(-int32(3)),
	323: int8(-int32(6)),
	324: int8(-int32(1)),
	325: int8(-int32(1)),
	326: int8(-int32(2)),
	327: int8(-int32(1)),
	328: int8(-int32(2)),
	329: int8(-int32(2)),
	330: int8(-int32(2)),
	332: int8(-int32(2)),
	333: int8(-int32(2)),
	334: int8(-int32(2)),
	335: int8(-int32(1)),
	336: int8(-int32(2)),
	337: int8(-int32(2)),
	338: int8(-int32(1)),
	339: int8(-int32(1)),
	340: int8(-int32(4)),
	341: int8(-int32(2)),
	342: int8(-int32(5)),
	343: int8(-int32(1)),
	344: int8(-int32(1)),
	345: int8(-int32(2)),
	346: int8(-int32(1)),
	347: int8(-int32(1)),
	348: int8(-int32(2)),
	349: int8(-int32(3)),
	351: int8(-int32(1)),
	352: int8(-int32(2)),
	353: int8(-int32(1)),
	355: int8(-int32(2)),
	356: int8(-int32(1)),
	357: int8(-int32(4)),
	358: int8(-int32(2)),
	359: int8(-int32(1)),
	360: int8(-int32(1)),
	361: int8(-int32(1)),
	362: int8(-int32(1)),
	363: int8(-int32(1)),
	364: int8(-int32(1)),
	365: int8(-int32(2)),
	367: int8(-int32(2)),
	368: int8(-int32(4)),
	369: int8(-int32(2)),
	370: int8(-int32(2)),
	371: int8(-int32(3)),
	372: int8(-int32(1)),
	374: int8(-int32(1)),
	375: int8(-int32(1)),
	376: int8(-int32(1)),
	377: int8(-int32(1)),
	378: int8(-int32(2)),
	379: int8(-int32(1)),
	380: int8(-int32(1)),
	382: int8(-int32(1)),
	383: int8(-int32(1)),
	384: int8(-int32(1)),
	385: int8(-int32(1)),
	386: int8(-int32(1)),
	387: int8(-int32(1)),
	388: int8(-int32(1)),
	389: int8(-int32(1)),
	390: int8(-int32(1)),
	391: int8(-int32(1)),
	393: int8(-int32(3)),
	394: int8(-int32(1)),
	396: int8(-int32(1)),
	399: int8(-int32(1)),
	400: int8(-int32(1)),
	401: int8(-int32(3)),
	402: int8(-int32(2)),
	404: int8(-int32(4)),
	405: int8(-int32(2)),
	407: int8(-int32(1)),
	408: int8(-int32(1)),
}

// 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(96)
	defer tls.Free(96)
	var bNot, bNot1, nExpr, yygoto, yysize int32
	var n Tu32
	var op Tu8
	var p, p1, p2, p3, p4, p5, 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, v347, v348, v349, v350, v351 uintptr
	var yyact uint16
	var v352 TToken
	var _ /* all at bp+64 */ TToken
	var _ /* as at bp+48 */ TToken
	var _ /* dest at bp+8 */ TSelectDest
	var _ /* t at bp+56 */ TToken
	var _ /* x at bp+40 */ TToken
	var _ /* yylhsminor at bp+0 */ TYYMINORTYPE
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNot, bNot1, n, nExpr, op, p, p1, p2, p3, p4, p5, 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, v347, v348, v349, v350, v351, v352 /* 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(324):
		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(118):
		goto _134
	case uint32(119):
		goto _135
	case uint32(120):
		goto _136
	case uint32(121):
		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(282):
		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(287):
		goto _271
	case uint32(268):
		goto _272
	case uint32(288):
		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(281):
		goto _286
	case uint32(283):
		goto _287
	case uint32(284):
		goto _288
	case uint32(285):
		goto _289
	case uint32(286):
		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(303):
		goto _304
	case uint32(302):
		goto _305
	case uint32(304):
		goto _306
	case uint32(306):
		goto _307
	case uint32(305):
		goto _308
	case uint32(307):
		goto _309
	case uint32(308):
		goto _310
	case uint32(309):
		goto _311
	case uint32(310):
		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(327):
		goto _326
	case uint32(325):
		goto _327
	case uint32(328):
		goto _328
	case uint32(326):
		goto _329
	case uint32(330):
		goto _330
	case uint32(329):
		goto _331
	case uint32(331):
		goto _332
	case uint32(332):
		goto _333
	case uint32(334):
		goto _334
	case uint32(333):
		goto _335
	case uint32(335):
		goto _336
	case uint32(336):
		goto _337
	case uint32(337):
		goto _338
	case uint32(338):
		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
	default:
		goto _345
	}
	goto _346
_1:
	; /* explain ::= EXPLAIN */
	if (*TParse)(unsafe.Pointer(pParse)).FpReprepare == uintptr(0) {
		(*TParse)(unsafe.Pointer(pParse)).Fexplain = uint8(1)
	}
	goto _346
_2:
	; /* explain ::= EXPLAIN QUERY PLAN */
	if (*TParse)(unsafe.Pointer(pParse)).FpReprepare == uintptr(0) {
		(*TParse)(unsafe.Pointer(pParse)).Fexplain = uint8(2)
	}
	goto _346
_3:
	; /* cmdx ::= cmd */
	_sqlite3FinishCoding(tls, pParse)
	goto _346
_4:
	; /* cmd ::= BEGIN transtype trans_opt */
	_sqlite3BeginTransaction(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_5:
	; /* transtype ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = int32(TK_DEFERRED)
	goto _346
_7:
	; /* transtype ::= DEFERRED */
_6:
	;
_8:
	;
_9:
	;
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor) /*A-overwrites-X*/
	goto _346
_11:
	; /* cmd ::= COMMIT|END trans_opt */
_10:
	;
	_sqlite3EndTransaction(tls, pParse, int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor))
	goto _346
_12:
	; /* cmd ::= SAVEPOINT nm */
	_sqlite3Savepoint(tls, pParse, SAVEPOINT_BEGIN, yymsp+4)
	goto _346
_13:
	; /* cmd ::= RELEASE savepoint_opt nm */
	_sqlite3Savepoint(tls, pParse, int32(SAVEPOINT_RELEASE), yymsp+4)
	goto _346
_14:
	; /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
	_sqlite3Savepoint(tls, pParse, int32(SAVEPOINT_ROLLBACK), yymsp+4)
	goto _346
_15:
	; /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
	_sqlite3StartTable(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), 0, 0, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	goto _346
_16:
	; /* createkw ::= CREATE */
	_disableLookaside(tls, pParse)
	goto _346
_18:
	; /* ifnotexists ::= */
_17:
	;
_19:
	;
_20:
	;
_21:
	;
_22:
	;
_23:
	;
_24:
	;
	*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = 0
	goto _346
_25:
	; /* ifnotexists ::= IF NOT EXISTS */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = int32(1)
	goto _346
_26:
	; /* temp ::= TEMP */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = libc.BoolInt32(int32((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0)
	goto _346
_27:
	; /* create_table_args ::= LP columnlist conslist_opt RP table_option_set */
	_sqlite3EndTable(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*Tu32)(unsafe.Pointer(yymsp + 4)), uintptr(0))
	goto _346
_28:
	; /* create_table_args ::= AS select */
	_sqlite3EndTable(tls, pParse, uintptr(0), uintptr(0), uint32(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_29:
	; /* table_option_set ::= */
	*(*Tu32)(unsafe.Pointer(yymsp + 1*12 + 4)) = uint32(0)
	goto _346
_30:
	; /* table_option_set ::= table_option_set COMMA table_option */
	*(*Tu32)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = *(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) | *(*Tu32)(unsafe.Pointer(yymsp + 4))
	*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*Tu32)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_31:
	; /* table_option ::= WITHOUT nm */
	if *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) == uint32(5) && Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(yymsp + 4)), __ccgo_ts+18096, int32(5)) == 0 {
		*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uint32(libc.Int32FromInt32(TF_WithoutRowid) | libc.Int32FromInt32(TF_NoVisibleRowid))
	} else {
		*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uint32(0)
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24807, libc.VaList(bp+80, *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))))
	}
	goto _346
_32:
	; /* table_option ::= nm */
	if *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) == uint32(6) && Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(yymsp + 4)), __ccgo_ts+18009, int32(6)) == 0 {
		*(*Tu32)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = uint32(TF_Strict)
	} else {
		*(*Tu32)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = uint32(0)
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24807, libc.VaList(bp+80, *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))))
	}
	*(*Tu32)(unsafe.Pointer(yymsp + 4)) = *(*Tu32)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_33:
	; /* columnname ::= nm typetoken */
	_sqlite3AddColumn(tls, pParse, *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*TToken)(unsafe.Pointer(yymsp + 4)))
	goto _346
_35:
	; /* typetoken ::= */
_34:
	;
_36:
	;
	*(*uint32)(unsafe.Pointer(yymsp + 1*12 + 4 + 4)) = uint32(0)
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	goto _346
_37:
	; /* typetoken ::= typename LP signed RP */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) = uint32(t__predefined_ptrdiff_t(*(*uintptr)(unsafe.Pointer(yymsp + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4)))) - int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))))
	goto _346
_38:
	; /* typetoken ::= typename LP signed COMMA signed RP */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4 + 4)) = uint32(t__predefined_ptrdiff_t(*(*uintptr)(unsafe.Pointer(yymsp + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4)))) - int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4))))
	goto _346
_39:
	; /* typename ::= typename ID|STRING */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) + uint32(int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))))
	goto _346
_40:
	; /* scanpt ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = yyLookaheadToken.Fz
	goto _346
_41:
	; /* scantok ::= */
	*(*TToken)(unsafe.Pointer(yymsp + 1*12 + 4)) = yyLookaheadToken
	goto _346
_43:
	; /* ccons ::= CONSTRAINT nm */
_42:
	;
	(*TParse)(unsafe.Pointer(pParse)).FconstraintName = *(*TToken)(unsafe.Pointer(yymsp + 4))
	goto _346
_44:
	; /* ccons ::= DEFAULT scantok term */
	_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4))))
	goto _346
_45:
	; /* ccons ::= DEFAULT LP expr RP */
	_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))+uintptr(1), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_46:
	; /* ccons ::= DEFAULT PLUS scantok term */
	_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4))))
	goto _346
_47:
	; /* ccons ::= DEFAULT MINUS scantok term */
	p = _sqlite3PExpr(tls, pParse, int32(TK_UMINUS), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0))
	_sqlite3AddDefaultValue(tls, pParse, p, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4))))
	goto _346
_48:
	; /* ccons ::= DEFAULT scantok ID|INDEXED */
	p1 = _tokenExpr(tls, pParse, int32(TK_STRING), *(*TToken)(unsafe.Pointer(yymsp + 4)))
	if p1 != 0 {
		_sqlite3ExprIdToTrueFalse(tls, p1)
	}
	_sqlite3AddDefaultValue(tls, pParse, p1, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4))))
	goto _346
_49:
	; /* ccons ::= NOT NULL onconf */
	_sqlite3AddNotNull(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 4)))
	goto _346
_50:
	; /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
	_sqlite3AddPrimaryKey(tls, pParse, uintptr(0), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	goto _346
_51:
	; /* ccons ::= UNIQUE onconf */
	_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), uintptr(0), *(*int32)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_UNIQUE))
	goto _346
_52:
	; /* ccons ::= CHECK LP expr RP */
	_sqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_53:
	; /* ccons ::= REFERENCES nm eidlist_opt refargs */
	_sqlite3CreateForeignKey(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
	goto _346
_54:
	; /* ccons ::= defer_subclause */
	_sqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 4)))
	goto _346
_55:
	; /* ccons ::= COLLATE ID|STRING */
	_sqlite3AddCollateType(tls, pParse, yymsp+4)
	goto _346
_56:
	; /* generated ::= LP expr RP */
	_sqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
	goto _346
_57:
	; /* generated ::= LP expr RP ID */
	_sqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+4)
	goto _346
_58:
	; /* autoinc ::= AUTOINCR */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(1)
	goto _346
_59:
	;                                                                                                        /* refargs ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = libc.Int32FromInt32(OE_None) * libc.Int32FromInt32(0x0101) /* EV: R-19803-45884 */
	goto _346
_60:
	; /* refargs ::= refargs refarg */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) & ^*(*int32)(unsafe.Pointer(yymsp + 4 + 4)) | *(*int32)(unsafe.Pointer(yymsp + 4))
	goto _346
_61:
	; /* refarg ::= MATCH nm */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = 0
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = 0x000000
	goto _346
_62:
	; /* refarg ::= ON INSERT refact */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = 0
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = 0x000000
	goto _346
_63:
	; /* refarg ::= ON DELETE refact */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4))
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = int32(0x0000ff)
	goto _346
_64:
	; /* refarg ::= ON UPDATE refact */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4)) << int32(8)
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = int32(0x00ff00)
	goto _346
_65:
	;                                                                                              /* refact ::= SET NULL */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(OE_SetNull) /* EV: R-33326-45252 */
	goto _346
_66:
	;                                                                                              /* refact ::= SET DEFAULT */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(OE_SetDflt) /* EV: R-33326-45252 */
	goto _346
_67:
	;                                                        /* refact ::= CASCADE */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Cascade) /* EV: R-33326-45252 */
	goto _346
_68:
	;                                                         /* refact ::= RESTRICT */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Restrict) /* EV: R-33326-45252 */
	goto _346
_69:
	;                                                                                    /* refact ::= NO ACTION */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = OE_None /* EV: R-33326-45252 */
	goto _346
_70:
	; /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = 0
	goto _346
_72:
	; /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
_71:
	;
_73:
	;
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4))
	goto _346
_75:
	; /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
_74:
	;
_76:
	;
_77:
	;
_78:
	;
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(1)
	goto _346
_79:
	; /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = 0
	goto _346
_80:
	; /* tconscomma ::= COMMA */
	(*TParse)(unsafe.Pointer(pParse)).FconstraintName.Fn = uint32(0)
	goto _346
_81:
	; /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
	_sqlite3AddPrimaryKey(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), 0)
	goto _346
_82:
	; /* tcons ::= UNIQUE LP sortlist RP onconf */
	_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_UNIQUE))
	goto _346
_83:
	; /* tcons ::= CHECK LP expr RP onconf */
	_sqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_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))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	_sqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 4)))
	goto _346
_86:
	; /* onconf ::= */
_85:
	;
	*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = int32(OE_Default)
	goto _346
_87:
	; /* onconf ::= ON CONFLICT resolvetype */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4))
	goto _346
_88:
	; /* resolvetype ::= IGNORE */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Ignore)
	goto _346
_90:
	; /* resolvetype ::= REPLACE */
_89:
	;
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Replace)
	goto _346
_91:
	; /* cmd ::= DROP TABLE ifexists fullname */
	_sqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), 0, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_92:
	; /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
	_sqlite3CreateView(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(8))*12+4, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))
	goto _346
_93:
	; /* cmd ::= DROP VIEW ifexists fullname */
	_sqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), int32(1), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_94:
	; /* cmd ::= select */
	*(*TSelectDest)(unsafe.Pointer(bp + 8)) = TSelectDest{
		FeDest: uint8(SRT_Output),
	}
	_sqlite3Select(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), bp+8)
	_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_95:
	; /* select ::= WITH wqlist selectnowith */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_96:
	; /* select ::= WITH RECURSIVE wqlist selectnowith */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_97:
	; /* select ::= selectnowith */
	p2 = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	if p2 != 0 {
		_parserDoubleLinkSelect(tls, pParse, p2)
	}
	goto _346
_98:
	; /* selectnowith ::= selectnowith multiselect_op oneselect */
	pRhs = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	pLhs = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
	if pRhs != 0 && (*TSelect)(unsafe.Pointer(pRhs)).FpPrior != 0 {
		(*(*TToken)(unsafe.Pointer(bp + 40))).Fn = uint32(0)
		_parserDoubleLinkSelect(tls, pParse, pRhs)
		pFrom = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+40, 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 = uint8(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
		(*TSelect)(unsafe.Pointer(pRhs)).FpPrior = pLhs
		if pLhs != 0 {
			*(*Tu32)(unsafe.Pointer(pLhs + 4)) &= uint32(^libc.Int32FromInt32(SF_MultiValue))
		}
		*(*Tu32)(unsafe.Pointer(pRhs + 4)) &= uint32(^libc.Int32FromInt32(SF_MultiValue))
		if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != int32(TK_ALL) {
			(*TParse)(unsafe.Pointer(pParse)).FhasCompound = uint8(1)
		}
	} else {
		_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pLhs)
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = pRhs
	goto _346
_100:
	; /* multiselect_op ::= UNION */
_99:
	;
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor) /*A-overwrites-OP*/
	goto _346
_101:
	; /* multiselect_op ::= UNION ALL */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(TK_ALL)
	goto _346
_102:
	; /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uint32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_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))*12 + 4)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uint32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*12 + 4)) != 0 {
		(*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*12 + 4)))).FpWinDefn = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
	} else {
		_sqlite3WindowListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	}
	goto _346
_104:
	; /* values ::= VALUES LP nexprlist RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
	goto _346
_105:
	; /* oneselect ::= mvalues */
	_sqlite3MultiValuesEnd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_107:
	; /* mvalues ::= values COMMA LP nexprlist RP */
_106:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3MultiValues(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_108:
	; /* distinct ::= DISTINCT */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(SF_Distinct)
	goto _346
_109:
	; /* distinct ::= ALL */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(SF_All)
	goto _346
_111:
	; /* sclp ::= */
_110:
	;
_112:
	;
_113:
	;
_114:
	;
_115:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	goto _346
_116:
	; /* selcollist ::= sclp scanpt expr scanpt as */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	if *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) > uint32(0) {
		_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+4, int32(1))
	}
	_sqlite3ExprListSetSpan(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_117:
	; /* selcollist ::= sclp scanpt STAR */
	p3 = _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_ASTERISK), uintptr(0))
	_sqlite3ExprSetErrorOffset(tls, p3, int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32((*TParse)(unsafe.Pointer(pParse)).FzTail))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), p3)
	goto _346
_118:
	; /* selcollist ::= sclp scanpt nm DOT STAR */
	pRight = _sqlite3PExpr(tls, pParse, int32(TK_ASTERISK), uintptr(0), uintptr(0))
	_sqlite3ExprSetErrorOffset(tls, pRight, int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32((*TParse)(unsafe.Pointer(pParse)).FzTail))
	pLeft = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	pDot = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pRight)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pDot)
	goto _346
_120:
	; /* as ::= AS nm */
_119:
	;
_121:
	;
_122:
	;
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + 4))
	goto _346
_124:
	; /* from ::= */
_123:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	goto _346
_125:
	; /* from ::= FROM seltablist */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	_sqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_126:
	; /* stl_prefix ::= seltablist joinop */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 && (*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnSrc > 0 {
		(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) + 8 + uintptr((*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnSrc-int32(1))*72))).Ffg.Fjointype = uint8(*(*int32)(unsafe.Pointer(yymsp + 4)))
	}
	goto _346
_127:
	; /* seltablist ::= stl_prefix nm dbnm as on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), yymsp+4)
	goto _346
_128:
	; /* seltablist ::= stl_prefix nm dbnm as indexed_by on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, uintptr(0), yymsp+4)
	_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
	goto _346
_129:
	; /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, yymsp+uintptr(-libc.Int32FromInt32(5))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), yymsp+4)
	_sqlite3SrcListFuncArgs(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
	goto _346
_130:
	; /* seltablist ::= stl_prefix LP select RP as on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), yymsp+4)
	goto _346
_131:
	; /* seltablist ::= stl_prefix LP seltablist RP as on_using */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) == uintptr(0) && *(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) == uint32(0) && *(*uintptr)(unsafe.Pointer(yymsp + 4)) == uintptr(0) && *(*uintptr)(unsafe.Pointer(yymsp + 4 + 4)) == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))
	} else {
		if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != uintptr(0) && (*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))).FnSrc == int32(1) {
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), yymsp+4)
			if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) != 0 {
				pNew = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) + 8 + uintptr((*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))).FnSrc-int32(1))*72
				pOld = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) + 8
				(*TSrcItem)(unsafe.Pointer(pNew)).FzName = (*TSrcItem)(unsafe.Pointer(pOld)).FzName
				(*TSrcItem)(unsafe.Pointer(pNew)).FzDatabase = (*TSrcItem)(unsafe.Pointer(pOld)).FzDatabase
				(*TSrcItem)(unsafe.Pointer(pNew)).FpSelect = (*TSrcItem)(unsafe.Pointer(pOld)).FpSelect
				if (*TSrcItem)(unsafe.Pointer(pNew)).FpSelect != 0 && (*TSelect)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pNew)).FpSelect)).FselFlags&uint32(SF_NestedFrom) != uint32(0) {
					libc.SetBitFieldPtr16Uint32(pNew+36+4, libc.Uint32FromInt32(1), 13, 0x2000)
				}
				if int32(uint32(*(*uint16)(unsafe.Pointer(pOld + 36 + 4))&0x4>>2)) != 0 {
					*(*uintptr)(unsafe.Pointer(pNew + 64)) = *(*uintptr)(unsafe.Pointer(pOld + 64))
					*(*uintptr)(unsafe.Pointer(pOld + 64)) = uintptr(0)
					libc.SetBitFieldPtr16Uint32(pOld+36+4, libc.Uint32FromInt32(0), 2, 0x4)
					libc.SetBitFieldPtr16Uint32(pNew+36+4, libc.Uint32FromInt32(1), 2, 0x4)
				}
				v347 = libc.UintptrFromInt32(0)
				(*TSrcItem)(unsafe.Pointer(pOld)).FzDatabase = v347
				(*TSrcItem)(unsafe.Pointer(pOld)).FzName = v347
				(*TSrcItem)(unsafe.Pointer(pOld)).FpSelect = uintptr(0)
			}
			_sqlite3SrcListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
		} else {
			_sqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
			pSubquery = _sqlite3SelectNew(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, pSubquery, yymsp+4)
		}
	}
	goto _346
_133:
	; /* dbnm ::= */
_132:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	*(*uint32)(unsafe.Pointer(yymsp + 1*12 + 4 + 4)) = uint32(0)
	goto _346
_134:
	; /* fullname ::= nm */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+4, uintptr(0))
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) != 0 {
		_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) + 8))).FzName, yymsp+4)
	}
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_135:
	; /* fullname ::= nm DOT nm */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4)
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) != 0 {
		_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) + 8))).FzName, yymsp+4)
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_136:
	;                                                                                                            /* xfullname ::= nm */
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+4, uintptr(0)) /*A-overwrites-X*/
	goto _346
_137:
	;                                                                                                                                                                                   /* xfullname ::= nm DOT nm */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4) /*A-overwrites-X*/
	goto _346
_138:
	;                                                                                                                                                                                                                       /* xfullname ::= nm DOT nm AS nm */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4) /*A-overwrites-X*/
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
		(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 8))).FzAlias = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, yymsp+4)
	}
	goto _346
_139:
	;                                                                                                                                                                                      /* xfullname ::= nm AS nm */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, uintptr(0)) /*A-overwrites-X*/
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) != 0 {
		(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) + 8))).FzAlias = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, yymsp+4)
	}
	goto _346
_140:
	; /* joinop ::= COMMA|JOIN */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(JT_INNER)
	goto _346
_141:
	;                                                                                                                                                                               /* joinop ::= JOIN_KW JOIN */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), uintptr(0)) /*X-overwrites-A*/
	goto _346
_142:
	;                                                                                                                                                                                                                /* joinop ::= JOIN_KW nm JOIN */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0)) /*X-overwrites-A*/
	goto _346
_143:
	;                                                                                                                                                                                                                                                 /* joinop ::= JOIN_KW nm nm JOIN */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4) /*X-overwrites-A*/
	goto _346
_144:
	; /* on_using ::= ON expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = uintptr(0)
	goto _346
_145:
	; /* on_using ::= USING LP idlist RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_146:
	; /* on_using ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4 + 4)) = uintptr(0)
	goto _346
_147:
	; /* indexed_by ::= INDEXED BY nm */
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + 4))
	goto _346
_148:
	; /* indexed_by ::= NOT INDEXED */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uintptr(0)
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = uint32(1)
	goto _346
_150:
	; /* orderby_opt ::= ORDER BY sortlist */
_149:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	goto _346
_151:
	; /* sortlist ::= sortlist COMMA expr sortorder nulls */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	_sqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
	goto _346
_152:
	;                                                                                                                                                                                                            /* sortlist ::= expr sortorder nulls */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))) /*A-overwrites-Y*/
	_sqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
	goto _346
_153:
	; /* sortorder ::= ASC */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = SQLITE_SO_ASC
	goto _346
_154:
	; /* sortorder ::= DESC */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(SQLITE_SO_DESC)
	goto _346
_156:
	; /* sortorder ::= */
_155:
	;
	*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = -int32(1)
	goto _346
_157:
	; /* nulls ::= NULLS FIRST */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = SQLITE_SO_ASC
	goto _346
_158:
	; /* nulls ::= NULLS LAST */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(SQLITE_SO_DESC)
	goto _346
_160:
	; /* having_opt ::= */
_159:
	;
_161:
	;
_162:
	;
_163:
	;
_164:
	;
_165:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	goto _346
_167:
	; /* having_opt ::= HAVING expr */
_166:
	;
_168:
	;
_169:
	;
_170:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	goto _346
_171:
	; /* limit_opt ::= LIMIT expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0))
	goto _346
_172:
	; /* limit_opt ::= LIMIT expr OFFSET expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_173:
	; /* limit_opt ::= LIMIT expr COMMA expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	goto _346
_174:
	; /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt_ret */
	_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
	_sqlite3DeleteFrom(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0))
	goto _346
_175:
	; /* where_opt_ret ::= RETURNING selcollist */
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uintptr(0)
	goto _346
_176:
	; /* where_opt_ret ::= WHERE expr RETURNING selcollist */
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
	goto _346
_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))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4)
	_sqlite3ExprListCheckLength(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), __ccgo_ts+24834)
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
		pFromClause = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
		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)(unsafe.Pointer(bp + 48))).Fn = uint32(0)
			(*(*TToken)(unsafe.Pointer(bp + 48))).Fz = uintptr(0)
			pFromClause = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+48, pSubquery1, uintptr(0))
		}
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), pFromClause)
	}
	_sqlite3Update(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), uintptr(0), uintptr(0), uintptr(0))
	goto _346
_178:
	; /* setlist ::= setlist COMMA nm EQ expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, int32(1))
	goto _346
_179:
	; /* setlist ::= setlist COMMA LP idlist RP EQ expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)) = _sqlite3ExprListAppendVector(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_180:
	; /* setlist ::= nm EQ expr */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, int32(1))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_181:
	; /* setlist ::= LP idlist RP EQ expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppendVector(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_182:
	; /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
	_sqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_183:
	; /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES returning */
	_sqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), uintptr(0))
	goto _346
_184:
	; /* upsert ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	goto _346
_185:
	; /* upsert ::= RETURNING selcollist */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uintptr(0)
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_186:
	; /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt upsert */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(11))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_187:
	; /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING upsert */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_188:
	; /* upsert ::= ON CONFLICT DO NOTHING returning */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
	goto _346
_189:
	; /* upsert ::= ON CONFLICT DO UPDATE SET setlist where_opt returning */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
	goto _346
_190:
	; /* returning ::= RETURNING selcollist */
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_191:
	; /* idlist_opt ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	goto _346
_192:
	; /* idlist_opt ::= LP idlist RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_193:
	; /* idlist ::= idlist COMMA nm */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3IdListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+4)
	goto _346
_194:
	;                                                                                               /* idlist ::= nm */
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3IdListAppend(tls, pParse, uintptr(0), yymsp+4) /*A-overwrites-Y*/
	goto _346
_195:
	; /* expr ::= LP expr RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_196:
	;                                                                                                                     /* expr ::= ID|INDEXED|JOIN_KW */
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-X*/
	goto _346
_197:
	; /* expr ::= nm DOT nm */
	temp1 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	temp2 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp1, temp2)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_198:
	; /* expr ::= nm DOT nm DOT nm */
	temp11 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
	temp21 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	temp3 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 4)))
	temp4 = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp21, temp3)
	if int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), temp11)
	}
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp11, temp4)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_200:
	; /* term ::= NULL|FLOAT|BLOB */
_199:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _tokenExpr(tls, pParse, int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor), *(*TToken)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-X*/
	goto _346
_201:
	; /* term ::= INTEGER */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_INTEGER), yymsp+4, int32(1))
	if *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) != 0 {
		*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) + 36)) = int32(*(*uintptr)(unsafe.Pointer(yymsp + 4))) - int32((*TParse)(unsafe.Pointer(pParse)).FzTail)
	}
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_202:
	; /* expr ::= VARIABLE */
	if !(int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 4))))) == int32('#') && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 4)) + 1)))])&int32(0x04) != 0) {
		n = *(*uint32)(unsafe.Pointer(yymsp + 4 + 4))
		*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _tokenExpr(tls, pParse, int32(TK_VARIABLE), *(*TToken)(unsafe.Pointer(yymsp + 4)))
		_sqlite3ExprAssignVarNumber(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), 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)(unsafe.Pointer(bp + 56)) = *(*TToken)(unsafe.Pointer(yymsp + 4)) /*A-overwrites-X*/
		if int32((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24843, libc.VaList(bp+80, bp+56))
			*(*uintptr)(unsafe.Pointer(yymsp + 4)) = uintptr(0)
		} else {
			*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_REGISTER), uintptr(0), uintptr(0))
			if *(*uintptr)(unsafe.Pointer(yymsp + 4)) != 0 {
				_sqlite3GetInt32(tls, (*(*TToken)(unsafe.Pointer(bp + 56))).Fz+1, *(*uintptr)(unsafe.Pointer(yymsp + 4))+28)
			}
		}
	}
	goto _346
_203:
	; /* expr ::= expr COLLATE ID|STRING */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprAddCollateToken(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+4, int32(1))
	goto _346
_204:
	; /* expr ::= CAST LP expr AS typetoken RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_CAST), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, int32(1))
	_sqlite3ExprAttachSubtrees(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0))
	goto _346
_205:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist RP */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_206:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist ORDER BY sortlist RP */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(7))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))
	_sqlite3ExprAddFunctionOrderBy(tls, pParse, *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_207:
	; /* expr ::= ID|INDEXED|JOIN_KW LP STAR RP */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, 0)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_208:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist RP filter_over */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(5))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
	_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_209:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist ORDER BY sortlist RP filter_over */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(8))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)))
	_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_sqlite3ExprAddFunctionOrderBy(tls, pParse, *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_210:
	; /* expr ::= ID|INDEXED|JOIN_KW LP STAR RP filter_over */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, 0)
	_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_211:
	; /* term ::= CTIME_KW */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+4, 0)
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_212:
	; /* expr ::= LP nexprlist COMMA expr RP */
	pList = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_VECTOR), uintptr(0), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
		*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = pList
		if (*TExprList)(unsafe.Pointer(pList)).FnExpr != 0 {
			*(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 4)) |= (*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr)).Fflags & uint32(libc.Int32FromInt32(EP_Collate)|libc.Int32FromInt32(EP_Subquery)|libc.Int32FromInt32(EP_HasFunc))
		}
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
	}
	goto _346
_213:
	; /* expr ::= expr AND expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprAnd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_215:
	; /* expr ::= expr OR expr */
_214:
	;
_216:
	;
_217:
	;
_218:
	;
_219:
	;
_220:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_221:
	; /* likeop ::= NOT LIKE_KW|MATCH */
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + 4))
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) |= uint32(0x80000000) /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/
	goto _346
_222:
	; /* expr ::= expr likeop expr */
	bNot = int32(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) & uint32(0x80000000))
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) &= uint32(0x7fffffff)
	pList1 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	pList1 = _sqlite3ExprListAppend(tls, pParse, pList1, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprFunction(tls, pParse, pList1, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, 0)
	if bNot != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), uintptr(0))
	}
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) != 0 {
		*(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) + 4)) |= uint32(EP_InfixFunc)
	}
	goto _346
_223:
	; /* expr ::= expr likeop expr ESCAPE expr */
	bNot1 = int32(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) & uint32(0x80000000))
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) &= uint32(0x7fffffff)
	pList2 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	pList2 = _sqlite3ExprListAppend(tls, pParse, pList2, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
	pList2 = _sqlite3ExprListAppend(tls, pParse, pList2, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprFunction(tls, pParse, pList2, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, 0)
	if bNot1 != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
	}
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
		*(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 4)) |= uint32(EP_InfixFunc)
	}
	goto _346
_224:
	; /* expr ::= expr ISNULL|NOTNULL */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
	goto _346
_225:
	; /* expr ::= expr NOT NULL */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOTNULL), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), uintptr(0))
	goto _346
_226:
	; /* expr ::= expr IS expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IS), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), int32(TK_ISNULL))
	goto _346
_227:
	; /* expr ::= expr IS NOT expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_ISNOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), int32(TK_NOTNULL))
	goto _346
_228:
	; /* expr ::= expr IS NOT DISTINCT FROM expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IS), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), int32(TK_ISNULL))
	goto _346
_229:
	; /* expr ::= expr IS DISTINCT FROM expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_ISNOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	_binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), int32(TK_NOTNULL))
	goto _346
_231:
	; /* expr ::= NOT expr */
_230:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0)) /*A-overwrites-B*/
	goto _346
_232:
	; /* expr ::= PLUS|MINUS expr */
	p4 = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	op = uint8(int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor) + (libc.Int32FromInt32(TK_UPLUS) - libc.Int32FromInt32(TK_PLUS)))
	if p4 != 0 && int32((*TExpr)(unsafe.Pointer(p4)).Fop) == int32(TK_UPLUS) {
		(*TExpr)(unsafe.Pointer(p4)).Fop = op
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = p4
	} else {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(int32(op)), p4, uintptr(0))
		/*A-overwrites-B*/
	}
	goto _346
_233:
	; /* expr ::= expr PTR expr */
	pList3 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	pList3 = _sqlite3ExprListAppend(tls, pParse, pList3, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3ExprFunction(tls, pParse, pList3, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, 0)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_235:
	; /* between_op ::= BETWEEN */
_234:
	;
	*(*int32)(unsafe.Pointer(yymsp + 4)) = 0
	goto _346
_236:
	; /* expr ::= expr between_op expr AND expr */
	pList4 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	pList4 = _sqlite3ExprListAppend(tls, pParse, pList4, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_BETWEEN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
		*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = pList4
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList4)
	}
	if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
	}
	goto _346
_237:
	; /* expr ::= expr in_op LP exprlist RP */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) == uintptr(0) {
		/* Expressions of the form
		 **
		 **      expr1 IN ()
		 **      expr1 NOT IN ()
		 **
		 ** simplify to constants 0 (false) and 1 (true), respectively,
		 ** regardless of the value of expr1.
		 */
		_sqlite3ExprUnmapAndDelete(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
		if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
			v348 = __ccgo_ts + 9320
		} else {
			v348 = __ccgo_ts + 9325
		}
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_STRING), v348)
		if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
			_sqlite3ExprIdToTrueFalse(tls, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
		}
	} else {
		pRHS = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) + 8))).FpExpr
		if (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnExpr == int32(1) && _sqlite3ExprIsConstant(tls, pParse, pRHS) != 0 && int32((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))).Fop) != int32(TK_VECTOR) {
			(*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) + 8))).FpExpr = uintptr(0)
			_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
			pRHS = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), pRHS, uintptr(0))
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_EQ), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pRHS)
		} else {
			if (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnExpr == int32(1) && int32((*TExpr)(unsafe.Pointer(pRHS)).Fop) == int32(TK_SELECT) {
				*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
				_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(pRHS + 20)))
				*(*uintptr)(unsafe.Pointer(pRHS + 20)) = uintptr(0)
				_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
			} else {
				*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) == uintptr(0) {
					_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
				} else {
					if int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))).FpLeft)).Fop) == int32(TK_VECTOR) {
						nExpr = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))).FpLeft + 20)))).FnExpr
						pSelectRHS = _sqlite3ExprListToValues(tls, pParse, nExpr, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
						if pSelectRHS != 0 {
							_parserDoubleLinkSelect(tls, pParse, pSelectRHS)
							_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pSelectRHS)
						}
					} else {
						*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
						_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
					}
				}
			}
		}
		if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
		}
	}
	goto _346
_238:
	; /* expr ::= LP select RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_SELECT), uintptr(0), uintptr(0))
	_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_239:
	; /* expr ::= expr in_op LP select RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
	_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
	}
	goto _346
_240:
	; /* expr ::= expr in_op nm dbnm paren_exprlist */
	pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
	pSelect = _sqlite3SelectNew(tls, pParse, uintptr(0), pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + 4)) != 0 {
		if pSelect != 0 {
			v349 = pSrc
		} else {
			v349 = uintptr(0)
		}
		_sqlite3SrcListFuncArgs(tls, pParse, v349, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
	_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pSelect)
	if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
	}
	goto _346
_241:
	; /* expr ::= EXISTS LP select RP */
	v350 = _sqlite3PExpr(tls, pParse, int32(TK_EXISTS), uintptr(0), uintptr(0))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = v350
	p5 = v350
	_sqlite3PExprAddSelect(tls, pParse, p5, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_242:
	; /* expr ::= CASE case_operand case_exprlist case_else END */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_CASE), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
		if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
			v351 = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
		} else {
			v351 = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
		}
		*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = v351
		_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	}
	goto _346
_243:
	; /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_244:
	; /* case_exprlist ::= WHEN expr THEN expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_245:
	; /* nexprlist ::= nexprlist COMMA expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_246:
	;                                                                                                                                /* nexprlist ::= expr */
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-Y*/
	goto _346
_248:
	; /* paren_exprlist ::= LP exprlist RP */
_247:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_249:
	; /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
	_sqlite3CreateIndex(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(7))*12+4, yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, uintptr(0)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(11))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + 4)), SQLITE_SO_ASC, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)), uint8(SQLITE_IDXTYPE_APPDEF))
	if int32((*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))*12+4)
	}
	goto _346
_251:
	; /* uniqueflag ::= UNIQUE */
_250:
	;
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Abort)
	goto _346
_252:
	; /* uniqueflag ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = OE_None
	goto _346
_253:
	; /* eidlist ::= eidlist COMMA nm collate sortorder */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _parserAddExprIdListTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
	goto _346
_254:
	;                                                                                                                                                                                                                                                                                               /* eidlist ::= nm collate sortorder */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _parserAddExprIdListTerm(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-Y*/
	goto _346
_255:
	; /* cmd ::= DROP INDEX ifexists fullname */
	_sqlite3DropIndex(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_256:
	; /* cmd ::= VACUUM vinto */
	_sqlite3Vacuum(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_257:
	; /* cmd ::= VACUUM nm vinto */
	_sqlite3Vacuum(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_258:
	; /* cmd ::= PRAGMA nm dbnm */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4, uintptr(0), 0)
	goto _346
_259:
	; /* cmd ::= PRAGMA nm dbnm EQ nmnum */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4, 0)
	goto _346
_260:
	; /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, 0)
	goto _346
_261:
	; /* cmd ::= PRAGMA nm dbnm EQ minus_num */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4, int32(1))
	goto _346
_262:
	; /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, int32(1))
	goto _346
_263:
	; /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
	(*(*TToken)(unsafe.Pointer(bp + 64))).Fz = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))
	(*(*TToken)(unsafe.Pointer(bp + 64))).Fn = uint32(int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))) + *(*uint32)(unsafe.Pointer(yymsp + 4 + 4))
	_sqlite3FinishTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), bp+64)
	goto _346
_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))*12+4, yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)))
	if *(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4 + 4)) == uint32(0) {
		v352 = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4))
	} else {
		v352 = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4))
	}
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*12 + 4)) = v352 /*A-overwrites-T*/
	goto _346
_265:
	;                                                                                               /* trigger_time ::= BEFORE|AFTER */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor) /*A-overwrites-X*/
	goto _346
_266:
	; /* trigger_time ::= INSTEAD OF */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(TK_INSTEAD)
	goto _346
_267:
	; /* trigger_time ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = int32(TK_BEFORE)
	goto _346
_269:
	; /* trigger_event ::= DELETE|INSERT */
_268:
	;
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor) /*A-overwrites-X*/
	*(*uintptr)(unsafe.Pointer(yymsp + 4 + 4)) = uintptr(0)
	goto _346
_270:
	; /* trigger_event ::= UPDATE OF idlist */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = int32(TK_UPDATE)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	goto _346
_272:
	; /* when_clause ::= */
_271:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
	goto _346
_274:
	; /* when_clause ::= WHEN expr */
_273:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	goto _346
_275:
	; /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
	(*TTriggerStep)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))).FpLast)).FpNext = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	(*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_276:
	; /* trigger_cmd_list ::= trigger_cmd SEMI */
	(*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_277:
	; /* trnm ::= nm DOT nm */
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + 4))
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24867, 0)
	goto _346
_278:
	; /* tridxby ::= INDEXED BY nm */
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24962, 0)
	goto _346
_279:
	; /* tridxby ::= NOT INDEXED */
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25046, 0)
	goto _346
_280:
	; /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3TriggerUpdateStep(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uint8(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_281:
	;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3TriggerInsertStep(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), uint8(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*yylhsminor.yy427-overwrites-yymsp[-6].minor.yy144*/
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_282:
	; /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3TriggerDeleteStep(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_283:
	;                                                                                                                                                                                                                                                                                                                                              /* trigger_cmd ::= scanpt select scanpt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3TriggerSelectStep(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*yylhsminor.yy427-overwrites-yymsp[-1].minor.yy555*/
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_284:
	; /* expr ::= RAISE LP IGNORE RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_RAISE), uintptr(0), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
		(*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))).FaffExpr = int8(OE_Ignore)
	}
	goto _346
_285:
	; /* expr ::= RAISE LP raisetype COMMA nm RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_RAISE), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, int32(1))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) != 0 {
		(*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))).FaffExpr = int8(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
	}
	goto _346
_286:
	; /* raisetype ::= ROLLBACK */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Rollback)
	goto _346
_287:
	; /* raisetype ::= FAIL */
	*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Fail)
	goto _346
_288:
	; /* cmd ::= DROP TRIGGER ifexists fullname */
	_sqlite3DropTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _346
_289:
	; /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
	_sqlite3Attach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_290:
	; /* cmd ::= DETACH database_kw_opt expr */
	_sqlite3Detach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_291:
	; /* cmd ::= REINDEX */
	_sqlite3Reindex(tls, pParse, uintptr(0), uintptr(0))
	goto _346
_292:
	; /* cmd ::= REINDEX nm dbnm */
	_sqlite3Reindex(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4)
	goto _346
_293:
	; /* cmd ::= ANALYZE */
	_sqlite3Analyze(tls, pParse, uintptr(0), uintptr(0))
	goto _346
_294:
	; /* cmd ::= ANALYZE nm dbnm */
	_sqlite3Analyze(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4)
	goto _346
_295:
	; /* cmd ::= ALTER TABLE fullname RENAME TO nm */
	_sqlite3AlterRenameTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), yymsp+4)
	goto _346
_296:
	; /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = uint32(int32((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))) + (*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn
	_sqlite3AlterFinishAddColumn(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
	goto _346
_297:
	; /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
	_sqlite3AlterDropColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), yymsp+4)
	goto _346
_298:
	; /* add_column_fullname ::= fullname */
	_disableLookaside(tls, pParse)
	_sqlite3AlterBeginAddColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_299:
	; /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
	_sqlite3AlterRenameColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4)
	goto _346
_300:
	; /* cmd ::= create_vtab */
	_sqlite3VtabFinishParse(tls, pParse, uintptr(0))
	goto _346
_301:
	; /* cmd ::= create_vtab LP vtabarglist RP */
	_sqlite3VtabFinishParse(tls, pParse, yymsp+4)
	goto _346
_302:
	; /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
	_sqlite3VtabBeginParse(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
	goto _346
_303:
	; /* vtabarg ::= */
	_sqlite3VtabArgInit(tls, pParse)
	goto _346
_305:
	; /* vtabargtoken ::= ANY */
_304:
	;
_306:
	;
	_sqlite3VtabArgExtend(tls, pParse, yymsp+4)
	goto _346
_308:
	; /* with ::= WITH wqlist */
_307:
	;
	_sqlite3WithPush(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uint8(1))
	goto _346
_309:
	; /* wqas ::= AS */
	*(*Tu8)(unsafe.Pointer(yymsp + 4)) = uint8(M10d_Any)
	goto _346
_310:
	; /* wqas ::= AS MATERIALIZED */
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uint8(M10d_Yes)
	goto _346
_311:
	; /* wqas ::= AS NOT MATERIALIZED */
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = uint8(M10d_No)
	goto _346
_312:
	;                                                                                                                                                                                                                                                                                                                                                                                             /* wqitem ::= withnm eidlist_opt wqas LP select RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3CteNew(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(5))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))) /*A-overwrites-X*/
	goto _346
_313:
	; /* withnm ::= nm */
	(*TParse)(unsafe.Pointer(pParse)).FbHasWith = uint8(1)
	goto _346
_314:
	;                                                                                                                         /* wqlist ::= wqitem */
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3WithAdd(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-X*/
	goto _346
_315:
	; /* wqlist ::= wqlist COMMA wqitem */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3WithAdd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	goto _346
_316:
	; /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
	_sqlite3WindowChain(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 4)))).FpNextWin = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_317:
	; /* windowdefn ::= nm AS LP window RP */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FzName = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uint64(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4 + 4))))
	}
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_318:
	; /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
	goto _346
_319:
	; /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(5))*12+4)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_320:
	; /* window ::= ORDER BY sortlist frame_opt */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
	goto _346
_321:
	; /* window ::= nm ORDER BY sortlist frame_opt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_322:
	; /* window ::= nm frame_opt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_323:
	; /* frame_opt ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = _sqlite3WindowAlloc(tls, pParse, 0, int32(TK_UNBOUNDED), uintptr(0), int32(TK_CURRENT), uintptr(0), uint8(0))
	goto _346
_324:
	; /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)), int32(TK_CURRENT), uintptr(0), *(*Tu8)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_325:
	; /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)), *(*Tu8)(unsafe.Pointer(yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_327:
	; /* frame_bound_s ::= frame_bound */
_326:
	;
	*(*TFrameBound)(unsafe.Pointer(bp)) = *(*TFrameBound)(unsafe.Pointer(yymsp + 4))
	*(*TFrameBound)(unsafe.Pointer(yymsp + 4)) = *(*TFrameBound)(unsafe.Pointer(bp))
	goto _346
_329:
	; /* frame_bound_s ::= UNBOUNDED PRECEDING */
_328:
	;
_330:
	;
	(*(*TFrameBound)(unsafe.Pointer(bp))).FeType = int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor)
	(*(*TFrameBound)(unsafe.Pointer(bp))).FpExpr = uintptr(0)
	*(*TFrameBound)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TFrameBound)(unsafe.Pointer(bp))
	goto _346
_331:
	; /* frame_bound ::= expr PRECEDING|FOLLOWING */
	(*(*TFrameBound)(unsafe.Pointer(bp))).FeType = int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor)
	(*(*TFrameBound)(unsafe.Pointer(bp))).FpExpr = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	*(*TFrameBound)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TFrameBound)(unsafe.Pointer(bp))
	goto _346
_332:
	; /* frame_exclude_opt ::= */
	*(*Tu8)(unsafe.Pointer(yymsp + 1*12 + 4)) = uint8(0)
	goto _346
_333:
	; /* frame_exclude_opt ::= EXCLUDE frame_exclude */
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*Tu8)(unsafe.Pointer(yymsp + 4))
	goto _346
_335:
	; /* frame_exclude ::= NO OTHERS */
_334:
	;
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uint8((*(*TyyStackEntry)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor) /*A-overwrites-X*/
	goto _346
_336:
	;                                                                                             /* frame_exclude ::= GROUP|TIES */
	*(*Tu8)(unsafe.Pointer(yymsp + 4)) = uint8((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor) /*A-overwrites-X*/
	goto _346
_337:
	; /* window_clause ::= WINDOW windowdefn_list */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	goto _346
_338:
	; /* filter_over ::= filter_clause over_clause */
	if *(*uintptr)(unsafe.Pointer(yymsp + 4)) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 4)))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	} else {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	}
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_339:
	; /* filter_over ::= over_clause */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_340:
	; /* filter_over ::= filter_clause */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(100))
	if *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))))).FeFrmType = uint8(TK_FILTER)
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + 4))
	} else {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
	}
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_341:
	; /* over_clause ::= OVER LP window RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_342:
	; /* over_clause ::= OVER nm */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(100))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FzName = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uint64(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4))))
	}
	goto _346
_343:
	; /* filter_clause ::= FILTER LP WHERE expr RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _346
_344:
	; /* term ::= QNUMBER */
	*(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))) = _tokenExpr(tls, pParse, int32((*(*TyyStackEntry)(unsafe.Pointer(yymsp))).Fmajor), *(*TToken)(unsafe.Pointer(yymsp + 4)))
	_sqlite3DequoteNumber(tls, pParse, *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp)))))
	*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&*(*TYYMINORTYPE)(unsafe.Pointer(bp))))
	goto _346
_345:
	;
	goto _346
	/********** End reduce actions ************************************************/
_346:
	;
	yygoto = int32(_yyRuleInfoLhs[yyruleno])
	yysize = int32(_yyRuleInfoNRhs[yyruleno])
	yyact = _yy_find_reduce_action(tls, (*(*TyyStackEntry)(unsafe.Pointer(yymsp + uintptr(yysize)*12))).Fstateno, uint16(uint16(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 += uintptr(yysize+int32(1)) * 12
	(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos = yymsp
	(*TyyStackEntry)(unsafe.Pointer(yymsp)).Fstateno = yyact
	(*TyyStackEntry)(unsafe.Pointer(yymsp)).Fmajor = uint16(uint16(yygoto))
	return yyact
}

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

// C documentation
//
//	/*
//	** The following code executes when a syntax error first occurs.
//	*/
func _yy_syntax_error(tls *libc.TLS, yypParser uintptr, yymajor int32, _yyminor TToken) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	*(*TToken)(unsafe.Pointer(bp)) = _yyminor
	var pParse uintptr
	_ = pParse
	pParse = (*TyyParser)(unsafe.Pointer(yypParser)).FpParse
	/************ Begin %syntax_error code ****************************************/
	_ = yymajor /* Silence some compiler warnings */
	if *(*int8)(unsafe.Pointer((*(*TToken)(unsafe.Pointer(bp))).Fz)) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24843, libc.VaList(bp+16, bp))
	} else {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25131, 0)
	}
	/************ End %syntax_error code ******************************************/
	/* Suppress warning about unused %extra_argument variable */
	(*TyyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
}

// C documentation
//
//	/*
//	** The following is executed when the parser accepts
//	*/
func _yy_accept(tls *libc.TLS, yypParser uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*TyyParser)(unsafe.Pointer(yypParser)).FpParse
	/* Here code is inserted which will be executed whenever the
	 ** parser accepts */
	/*********** Begin %parse_accept code *****************************************/
	/*********** End %parse_accept code *******************************************/
	/* Suppress warning about unused %extra_argument variable */
	(*TyyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
}

// C documentation
//
//	/* The main parser program.
//	** The first argument is a pointer to a structure obtained from
//	** "sqlite3ParserAlloc" which describes the current state of the parser.
//	** The second argument is the major token number.  The third is
//	** the minor token.  The fourth optional argument is whatever the
//	** user wants (and specified in the grammar) and is available for
//	** use by the action routines.
//	**
//	** Inputs:
//	** <ul>
//	** <li> A pointer to the parser (an opaque structure.)
//	** <li> The major token number.
//	** <li> The minor token number.
//	** <li> An option argument of a grammar-specified type.
//	** </ul>
//	**
//	** Outputs:
//	** None.
//	*/
func _sqlite3Parser(tls *libc.TLS, yyp uintptr, yymajor int32, yyminor TToken) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pParse, yypParser uintptr
	var yyact uint16
	var yyruleno uint32
	var _ /* yyminorunion at bp+0 */ TYYMINORTYPE
	_, _, _, _ = pParse, yyact, yypParser, yyruleno /* The parser action. */
	yypParser = yyp                                 /* The parser */
	pParse = (*TyyParser)(unsafe.Pointer(yypParser)).FpParse
	yyact = (*TyyStackEntry)(unsafe.Pointer((*TyyParser)(unsafe.Pointer(yypParser)).Fyytos)).Fstateno
	for int32(1) != 0 { /* Exit by "break" */
		yyact = _yy_find_shift_action(tls, uint16(uint16(yymajor)), yyact)
		if int32(int32(yyact)) >= int32(YY_MIN_REDUCE) {
			yyruleno = uint32(int32(int32(yyact)) - int32(YY_MIN_REDUCE)) /* Reduce by this rule */
			/* Check that the stack is large enough to grow by a single entry
			 ** if the RHS of the rule is empty.  This ensures that there is room
			 ** enough on the stack to push the LHS value */
			if int32(_yyRuleInfoNRhs[yyruleno]) == 0 {
				if (*TyyParser)(unsafe.Pointer(yypParser)).Fyytos >= (*TyyParser)(unsafe.Pointer(yypParser)).FyystackEnd {
					if _yyGrowStack(tls, yypParser) != 0 {
						_yyStackOverflow(tls, yypParser)
						break
					}
				}
			}
			yyact = _yy_reduce(tls, yypParser, yyruleno, yymajor, yyminor, pParse)
		} else {
			if int32(int32(yyact)) <= int32(YY_MAX_SHIFTREDUCE) {
				_yy_shift(tls, yypParser, yyact, uint16(uint16(yymajor)), yyminor)
				break
			} else {
				if int32(int32(yyact)) == int32(YY_ACCEPT_ACTION) {
					(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos -= 12
					_yy_accept(tls, yypParser)
					return
				} else {
					*(*TToken)(unsafe.Pointer(bp)) = yyminor
					/* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
					 ** do any kind of error recovery.  Instead, simply invoke the syntax
					 ** error routine and continue going as if nothing had happened.
					 **
					 ** Applications can set this macro (for example inside %include) if
					 ** they intend to abandon the parse upon the first syntax error seen.
					 */
					_yy_syntax_error(tls, yypParser, yymajor, yyminor)
					_yy_destructor(tls, yypParser, uint16(uint16(yymajor)), bp)
					break
				}
			}
		}
	}
	return
}

// C documentation
//
//	/*
//	** Return the fallback token corresponding to canonical token iToken, or
//	** 0 if iToken has no fallback.
//	*/
func _sqlite3ParserFallback(tls *libc.TLS, iToken int32) (r int32) {
	return int32(_yyFallback[iToken])
}

/************** End of parse.c ***********************************************/
/************** Begin file tokenize.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.
**
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that splits an SQL input string up into
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
 */
/* #include "sqliteInt.h" */
/* #include <stdlib.h> */

/* Character classes for tokenizing
**
** In the sqlite3GetToken() function, a switch() on aiClass[c] is implemented
** using a lookup table, whereas a switch() directly on c uses a binary search.
** The lookup table is much faster.  To maximize speed, and to ensure that
** a lookup table is used, all of the classes need to be small integers and
** all of them need to be used within the switch.
 */

var _aiClass = [256]uint8{
	0:   uint8(29),
	1:   uint8(28),
	2:   uint8(28),
	3:   uint8(28),
	4:   uint8(28),
	5:   uint8(28),
	6:   uint8(28),
	7:   uint8(28),
	8:   uint8(28),
	9:   uint8(7),
	10:  uint8(7),
	11:  uint8(28),
	12:  uint8(7),
	13:  uint8(7),
	14:  uint8(28),
	15:  uint8(28),
	16:  uint8(28),
	17:  uint8(28),
	18:  uint8(28),
	19:  uint8(28),
	20:  uint8(28),
	21:  uint8(28),
	22:  uint8(28),
	23:  uint8(28),
	24:  uint8(28),
	25:  uint8(28),
	26:  uint8(28),
	27:  uint8(28),
	28:  uint8(28),
	29:  uint8(28),
	30:  uint8(28),
	31:  uint8(28),
	32:  uint8(7),
	33:  uint8(15),
	34:  uint8(8),
	35:  uint8(5),
	36:  uint8(4),
	37:  uint8(22),
	38:  uint8(24),
	39:  uint8(8),
	40:  uint8(17),
	41:  uint8(18),
	42:  uint8(21),
	43:  uint8(20),
	44:  uint8(23),
	45:  uint8(11),
	46:  uint8(26),
	47:  uint8(16),
	48:  uint8(3),
	49:  uint8(3),
	50:  uint8(3),
	51:  uint8(3),
	52:  uint8(3),
	53:  uint8(3),
	54:  uint8(3),
	55:  uint8(3),
	56:  uint8(3),
	57:  uint8(3),
	58:  uint8(5),
	59:  uint8(19),
	60:  uint8(12),
	61:  uint8(14),
	62:  uint8(13),
	63:  uint8(6),
	64:  uint8(5),
	65:  uint8(1),
	66:  uint8(1),
	67:  uint8(1),
	68:  uint8(1),
	69:  uint8(1),
	70:  uint8(1),
	71:  uint8(1),
	72:  uint8(1),
	73:  uint8(1),
	74:  uint8(1),
	75:  uint8(1),
	76:  uint8(1),
	77:  uint8(1),
	78:  uint8(1),
	79:  uint8(1),
	80:  uint8(1),
	81:  uint8(1),
	82:  uint8(1),
	83:  uint8(1),
	84:  uint8(1),
	85:  uint8(1),
	86:  uint8(1),
	87:  uint8(1),
	89:  uint8(2),
	90:  uint8(2),
	91:  uint8(9),
	92:  uint8(28),
	93:  uint8(28),
	94:  uint8(28),
	95:  uint8(2),
	96:  uint8(8),
	97:  uint8(1),
	98:  uint8(1),
	99:  uint8(1),
	100: uint8(1),
	101: uint8(1),
	102: uint8(1),
	103: uint8(1),
	104: uint8(1),
	105: uint8(1),
	106: uint8(1),
	107: uint8(1),
	108: uint8(1),
	109: uint8(1),
	110: uint8(1),
	111: uint8(1),
	112: uint8(1),
	113: uint8(1),
	114: uint8(1),
	115: uint8(1),
	116: uint8(1),
	117: uint8(1),
	118: uint8(1),
	119: uint8(1),
	121: uint8(2),
	122: uint8(2),
	123: uint8(28),
	124: uint8(10),
	125: uint8(28),
	126: uint8(25),
	127: uint8(28),
	128: uint8(27),
	129: uint8(27),
	130: uint8(27),
	131: uint8(27),
	132: uint8(27),
	133: uint8(27),
	134: uint8(27),
	135: uint8(27),
	136: uint8(27),
	137: uint8(27),
	138: uint8(27),
	139: uint8(27),
	140: uint8(27),
	141: uint8(27),
	142: uint8(27),
	143: uint8(27),
	144: uint8(27),
	145: uint8(27),
	146: uint8(27),
	147: uint8(27),
	148: uint8(27),
	149: uint8(27),
	150: uint8(27),
	151: uint8(27),
	152: uint8(27),
	153: uint8(27),
	154: uint8(27),
	155: uint8(27),
	156: uint8(27),
	157: uint8(27),
	158: uint8(27),
	159: uint8(27),
	160: uint8(27),
	161: uint8(27),
	162: uint8(27),
	163: uint8(27),
	164: uint8(27),
	165: uint8(27),
	166: uint8(27),
	167: uint8(27),
	168: uint8(27),
	169: uint8(27),
	170: uint8(27),
	171: uint8(27),
	172: uint8(27),
	173: uint8(27),
	174: uint8(27),
	175: uint8(27),
	176: uint8(27),
	177: uint8(27),
	178: uint8(27),
	179: uint8(27),
	180: uint8(27),
	181: uint8(27),
	182: uint8(27),
	183: uint8(27),
	184: uint8(27),
	185: uint8(27),
	186: uint8(27),
	187: uint8(27),
	188: uint8(27),
	189: uint8(27),
	190: uint8(27),
	191: uint8(27),
	192: uint8(27),
	193: uint8(27),
	194: uint8(27),
	195: uint8(27),
	196: uint8(27),
	197: uint8(27),
	198: uint8(27),
	199: uint8(27),
	200: uint8(27),
	201: uint8(27),
	202: uint8(27),
	203: uint8(27),
	204: uint8(27),
	205: uint8(27),
	206: uint8(27),
	207: uint8(27),
	208: uint8(27),
	209: uint8(27),
	210: uint8(27),
	211: uint8(27),
	212: uint8(27),
	213: uint8(27),
	214: uint8(27),
	215: uint8(27),
	216: uint8(27),
	217: uint8(27),
	218: uint8(27),
	219: uint8(27),
	220: uint8(27),
	221: uint8(27),
	222: uint8(27),
	223: uint8(27),
	224: uint8(27),
	225: uint8(27),
	226: uint8(27),
	227: uint8(27),
	228: uint8(27),
	229: uint8(27),
	230: uint8(27),
	231: uint8(27),
	232: uint8(27),
	233: uint8(27),
	234: uint8(27),
	235: uint8(27),
	236: uint8(27),
	237: uint8(27),
	238: uint8(27),
	239: uint8(30),
	240: uint8(27),
	241: uint8(27),
	242: uint8(27),
	243: uint8(27),
	244: uint8(27),
	245: uint8(27),
	246: uint8(27),
	247: uint8(27),
	248: uint8(27),
	249: uint8(27),
	250: uint8(27),
	251: uint8(27),
	252: uint8(27),
	253: uint8(27),
	254: uint8(27),
	255: uint8(27),
}

/*
** The charMap() macro maps alphabetic characters (only) into their
** lower-case ASCII equivalent.  On ASCII machines, this is just
** an upper-to-lower case map.  On EBCDIC machines we also need
** to adjust the encoding.  The mapping is only valid for alphabetics
** which are the only characters for which this feature is used.
**
** Used by keywordhash.h
 */

// C documentation
//
//	/*
//	** The sqlite3KeywordCode function looks up an identifier to determine if
//	** it is a keyword.  If it is a keyword, the token code of that keyword is
//	** returned.  If the input is not a keyword, TK_ID is returned.
//	**
//	** The implementation of this routine was generated by a program,
//	** mkkeywordhash.c, located in the tool subdirectory of the distribution.
//	** The output of the mkkeywordhash.c program is written into a file
//	** named keywordhash.h and then included into this source file by
//	** the #include below.
//	*/
//	/************** Include keywordhash.h in the middle of tokenize.c ************/
//	/************** Begin file keywordhash.h *************************************/
//	/***** This file contains automatically generated code ******
//	**
//	** The code in this file has been automatically generated by
//	**
//	**   sqlite/tool/mkkeywordhash.c
//	**
//	** The code in this file implements a function that determines whether
//	** or not a given identifier is really an SQL keyword.  The same thing
//	** might be implemented more directly using a hand-written hash table.
//	** But by using this automatically generated code, the size of the code
//	** is substantially reduced.  This is important for embedded applications
//	** on platforms with limited memory.
//	*/
//	/* Hash score: 231 */
//	/* zKWText[] encodes 1007 bytes of keyword text in 667 bytes */
//	/*   REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT       */
//	/*   ABLEFTHENDEFERRABLELSEXCLUDELETEMPORARYISNULLSAVEPOINTERSECT       */
//	/*   IESNOTNULLIKEXCEPTRANSACTIONATURALTERAISEXCLUSIVEXISTS             */
//	/*   CONSTRAINTOFFSETRIGGERANGENERATEDETACHAVINGLOBEGINNEREFERENCES     */
//	/*   UNIQUERYWITHOUTERELEASEATTACHBETWEENOTHINGROUPSCASCADEFAULT        */
//	/*   CASECOLLATECREATECURRENT_DATEIMMEDIATEJOINSERTMATCHPLANALYZE       */
//	/*   PRAGMATERIALIZEDEFERREDISTINCTUPDATEVALUESVIRTUALWAYSWHENWHERE     */
//	/*   CURSIVEABORTAFTERENAMEANDROPARTITIONAUTOINCREMENTCASTCOLUMN        */
//	/*   COMMITCONFLICTCROSSCURRENT_TIMESTAMPRECEDINGFAILASTFILTER          */
//	/*   EPLACEFIRSTFOLLOWINGFROMFULLIMITIFORDERESTRICTOTHERSOVER           */
//	/*   ETURNINGRIGHTROLLBACKROWSUNBOUNDEDUNIONUSINGVACUUMVIEWINDOWBY      */
//	/*   INITIALLYPRIMARY                                                   */
var _zKWText = [666]int8{
	0:   int8('R'),
	1:   int8('E'),
	2:   int8('I'),
	3:   int8('N'),
	4:   int8('D'),
	5:   int8('E'),
	6:   int8('X'),
	7:   int8('E'),
	8:   int8('D'),
	9:   int8('E'),
	10:  int8('S'),
	11:  int8('C'),
	12:  int8('A'),
	13:  int8('P'),
	14:  int8('E'),
	15:  int8('A'),
	16:  int8('C'),
	17:  int8('H'),
	18:  int8('E'),
	19:  int8('C'),
	20:  int8('K'),
	21:  int8('E'),
	22:  int8('Y'),
	23:  int8('B'),
	24:  int8('E'),
	25:  int8('F'),
	26:  int8('O'),
	27:  int8('R'),
	28:  int8('E'),
	29:  int8('I'),
	30:  int8('G'),
	31:  int8('N'),
	32:  int8('O'),
	33:  int8('R'),
	34:  int8('E'),
	35:  int8('G'),
	36:  int8('E'),
	37:  int8('X'),
	38:  int8('P'),
	39:  int8('L'),
	40:  int8('A'),
	41:  int8('I'),
	42:  int8('N'),
	43:  int8('S'),
	44:  int8('T'),
	45:  int8('E'),
	46:  int8('A'),
	47:  int8('D'),
	48:  int8('D'),
	49:  int8('A'),
	50:  int8('T'),
	51:  int8('A'),
	52:  int8('B'),
	53:  int8('A'),
	54:  int8('S'),
	55:  int8('E'),
	56:  int8('L'),
	57:  int8('E'),
	58:  int8('C'),
	59:  int8('T'),
	60:  int8('A'),
	61:  int8('B'),
	62:  int8('L'),
	63:  int8('E'),
	64:  int8('F'),
	65:  int8('T'),
	66:  int8('H'),
	67:  int8('E'),
	68:  int8('N'),
	69:  int8('D'),
	70:  int8('E'),
	71:  int8('F'),
	72:  int8('E'),
	73:  int8('R'),
	74:  int8('R'),
	75:  int8('A'),
	76:  int8('B'),
	77:  int8('L'),
	78:  int8('E'),
	79:  int8('L'),
	80:  int8('S'),
	81:  int8('E'),
	82:  int8('X'),
	83:  int8('C'),
	84:  int8('L'),
	85:  int8('U'),
	86:  int8('D'),
	87:  int8('E'),
	88:  int8('L'),
	89:  int8('E'),
	90:  int8('T'),
	91:  int8('E'),
	92:  int8('M'),
	93:  int8('P'),
	94:  int8('O'),
	95:  int8('R'),
	96:  int8('A'),
	97:  int8('R'),
	98:  int8('Y'),
	99:  int8('I'),
	100: int8('S'),
	101: int8('N'),
	102: int8('U'),
	103: int8('L'),
	104: int8('L'),
	105: int8('S'),
	106: int8('A'),
	107: int8('V'),
	108: int8('E'),
	109: int8('P'),
	110: int8('O'),
	111: int8('I'),
	112: int8('N'),
	113: int8('T'),
	114: int8('E'),
	115: int8('R'),
	116: int8('S'),
	117: int8('E'),
	118: int8('C'),
	119: int8('T'),
	120: int8('I'),
	121: int8('E'),
	122: int8('S'),
	123: int8('N'),
	124: int8('O'),
	125: int8('T'),
	126: int8('N'),
	127: int8('U'),
	128: int8('L'),
	129: int8('L'),
	130: int8('I'),
	131: int8('K'),
	132: int8('E'),
	133: int8('X'),
	134: int8('C'),
	135: int8('E'),
	136: int8('P'),
	137: int8('T'),
	138: int8('R'),
	139: int8('A'),
	140: int8('N'),
	141: int8('S'),
	142: int8('A'),
	143: int8('C'),
	144: int8('T'),
	145: int8('I'),
	146: int8('O'),
	147: int8('N'),
	148: int8('A'),
	149: int8('T'),
	150: int8('U'),
	151: int8('R'),
	152: int8('A'),
	153: int8('L'),
	154: int8('T'),
	155: int8('E'),
	156: int8('R'),
	157: int8('A'),
	158: int8('I'),
	159: int8('S'),
	160: int8('E'),
	161: int8('X'),
	162: int8('C'),
	163: int8('L'),
	164: int8('U'),
	165: int8('S'),
	166: int8('I'),
	167: int8('V'),
	168: int8('E'),
	169: int8('X'),
	170: int8('I'),
	171: int8('S'),
	172: int8('T'),
	173: int8('S'),
	174: int8('C'),
	175: int8('O'),
	176: int8('N'),
	177: int8('S'),
	178: int8('T'),
	179: int8('R'),
	180: int8('A'),
	181: int8('I'),
	182: int8('N'),
	183: int8('T'),
	184: int8('O'),
	185: int8('F'),
	186: int8('F'),
	187: int8('S'),
	188: int8('E'),
	189: int8('T'),
	190: int8('R'),
	191: int8('I'),
	192: int8('G'),
	193: int8('G'),
	194: int8('E'),
	195: int8('R'),
	196: int8('A'),
	197: int8('N'),
	198: int8('G'),
	199: int8('E'),
	200: int8('N'),
	201: int8('E'),
	202: int8('R'),
	203: int8('A'),
	204: int8('T'),
	205: int8('E'),
	206: int8('D'),
	207: int8('E'),
	208: int8('T'),
	209: int8('A'),
	210: int8('C'),
	211: int8('H'),
	212: int8('A'),
	213: int8('V'),
	214: int8('I'),
	215: int8('N'),
	216: int8('G'),
	217: int8('L'),
	218: int8('O'),
	219: int8('B'),
	220: int8('E'),
	221: int8('G'),
	222: int8('I'),
	223: int8('N'),
	224: int8('N'),
	225: int8('E'),
	226: int8('R'),
	227: int8('E'),
	228: int8('F'),
	229: int8('E'),
	230: int8('R'),
	231: int8('E'),
	232: int8('N'),
	233: int8('C'),
	234: int8('E'),
	235: int8('S'),
	236: int8('U'),
	237: int8('N'),
	238: int8('I'),
	239: int8('Q'),
	240: int8('U'),
	241: int8('E'),
	242: int8('R'),
	243: int8('Y'),
	244: int8('W'),
	245: int8('I'),
	246: int8('T'),
	247: int8('H'),
	248: int8('O'),
	249: int8('U'),
	250: int8('T'),
	251: int8('E'),
	252: int8('R'),
	253: int8('E'),
	254: int8('L'),
	255: int8('E'),
	256: int8('A'),
	257: int8('S'),
	258: int8('E'),
	259: int8('A'),
	260: int8('T'),
	261: int8('T'),
	262: int8('A'),
	263: int8('C'),
	264: int8('H'),
	265: int8('B'),
	266: int8('E'),
	267: int8('T'),
	268: int8('W'),
	269: int8('E'),
	270: int8('E'),
	271: int8('N'),
	272: int8('O'),
	273: int8('T'),
	274: int8('H'),
	275: int8('I'),
	276: int8('N'),
	277: int8('G'),
	278: int8('R'),
	279: int8('O'),
	280: int8('U'),
	281: int8('P'),
	282: int8('S'),
	283: int8('C'),
	284: int8('A'),
	285: int8('S'),
	286: int8('C'),
	287: int8('A'),
	288: int8('D'),
	289: int8('E'),
	290: int8('F'),
	291: int8('A'),
	292: int8('U'),
	293: int8('L'),
	294: int8('T'),
	295: int8('C'),
	296: int8('A'),
	297: int8('S'),
	298: int8('E'),
	299: int8('C'),
	300: int8('O'),
	301: int8('L'),
	302: int8('L'),
	303: int8('A'),
	304: int8('T'),
	305: int8('E'),
	306: int8('C'),
	307: int8('R'),
	308: int8('E'),
	309: int8('A'),
	310: int8('T'),
	311: int8('E'),
	312: int8('C'),
	313: int8('U'),
	314: int8('R'),
	315: int8('R'),
	316: int8('E'),
	317: int8('N'),
	318: int8('T'),
	319: int8('_'),
	320: int8('D'),
	321: int8('A'),
	322: int8('T'),
	323: int8('E'),
	324: int8('I'),
	325: int8('M'),
	326: int8('M'),
	327: int8('E'),
	328: int8('D'),
	329: int8('I'),
	330: int8('A'),
	331: int8('T'),
	332: int8('E'),
	333: int8('J'),
	334: int8('O'),
	335: int8('I'),
	336: int8('N'),
	337: int8('S'),
	338: int8('E'),
	339: int8('R'),
	340: int8('T'),
	341: int8('M'),
	342: int8('A'),
	343: int8('T'),
	344: int8('C'),
	345: int8('H'),
	346: int8('P'),
	347: int8('L'),
	348: int8('A'),
	349: int8('N'),
	350: int8('A'),
	351: int8('L'),
	352: int8('Y'),
	353: int8('Z'),
	354: int8('E'),
	355: int8('P'),
	356: int8('R'),
	357: int8('A'),
	358: int8('G'),
	359: int8('M'),
	360: int8('A'),
	361: int8('T'),
	362: int8('E'),
	363: int8('R'),
	364: int8('I'),
	365: int8('A'),
	366: int8('L'),
	367: int8('I'),
	368: int8('Z'),
	369: int8('E'),
	370: int8('D'),
	371: int8('E'),
	372: int8('F'),
	373: int8('E'),
	374: int8('R'),
	375: int8('R'),
	376: int8('E'),
	377: int8('D'),
	378: int8('I'),
	379: int8('S'),
	380: int8('T'),
	381: int8('I'),
	382: int8('N'),
	383: int8('C'),
	384: int8('T'),
	385: int8('U'),
	386: int8('P'),
	387: int8('D'),
	388: int8('A'),
	389: int8('T'),
	390: int8('E'),
	391: int8('V'),
	392: int8('A'),
	393: int8('L'),
	394: int8('U'),
	395: int8('E'),
	396: int8('S'),
	397: int8('V'),
	398: int8('I'),
	399: int8('R'),
	400: int8('T'),
	401: int8('U'),
	402: int8('A'),
	403: int8('L'),
	404: int8('W'),
	405: int8('A'),
	406: int8('Y'),
	407: int8('S'),
	408: int8('W'),
	409: int8('H'),
	410: int8('E'),
	411: int8('N'),
	412: int8('W'),
	413: int8('H'),
	414: int8('E'),
	415: int8('R'),
	416: int8('E'),
	417: int8('C'),
	418: int8('U'),
	419: int8('R'),
	420: int8('S'),
	421: int8('I'),
	422: int8('V'),
	423: int8('E'),
	424: int8('A'),
	425: int8('B'),
	426: int8('O'),
	427: int8('R'),
	428: int8('T'),
	429: int8('A'),
	430: int8('F'),
	431: int8('T'),
	432: int8('E'),
	433: int8('R'),
	434: int8('E'),
	435: int8('N'),
	436: int8('A'),
	437: int8('M'),
	438: int8('E'),
	439: int8('A'),
	440: int8('N'),
	441: int8('D'),
	442: int8('R'),
	443: int8('O'),
	444: int8('P'),
	445: int8('A'),
	446: int8('R'),
	447: int8('T'),
	448: int8('I'),
	449: int8('T'),
	450: int8('I'),
	451: int8('O'),
	452: int8('N'),
	453: int8('A'),
	454: int8('U'),
	455: int8('T'),
	456: int8('O'),
	457: int8('I'),
	458: int8('N'),
	459: int8('C'),
	460: int8('R'),
	461: int8('E'),
	462: int8('M'),
	463: int8('E'),
	464: int8('N'),
	465: int8('T'),
	466: int8('C'),
	467: int8('A'),
	468: int8('S'),
	469: int8('T'),
	470: int8('C'),
	471: int8('O'),
	472: int8('L'),
	473: int8('U'),
	474: int8('M'),
	475: int8('N'),
	476: int8('C'),
	477: int8('O'),
	478: int8('M'),
	479: int8('M'),
	480: int8('I'),
	481: int8('T'),
	482: int8('C'),
	483: int8('O'),
	484: int8('N'),
	485: int8('F'),
	486: int8('L'),
	487: int8('I'),
	488: int8('C'),
	489: int8('T'),
	490: int8('C'),
	491: int8('R'),
	492: int8('O'),
	493: int8('S'),
	494: int8('S'),
	495: int8('C'),
	496: int8('U'),
	497: int8('R'),
	498: int8('R'),
	499: int8('E'),
	500: int8('N'),
	501: int8('T'),
	502: int8('_'),
	503: int8('T'),
	504: int8('I'),
	505: int8('M'),
	506: int8('E'),
	507: int8('S'),
	508: int8('T'),
	509: int8('A'),
	510: int8('M'),
	511: int8('P'),
	512: int8('R'),
	513: int8('E'),
	514: int8('C'),
	515: int8('E'),
	516: int8('D'),
	517: int8('I'),
	518: int8('N'),
	519: int8('G'),
	520: int8('F'),
	521: int8('A'),
	522: int8('I'),
	523: int8('L'),
	524: int8('A'),
	525: int8('S'),
	526: int8('T'),
	527: int8('F'),
	528: int8('I'),
	529: int8('L'),
	530: int8('T'),
	531: int8('E'),
	532: int8('R'),
	533: int8('E'),
	534: int8('P'),
	535: int8('L'),
	536: int8('A'),
	537: int8('C'),
	538: int8('E'),
	539: int8('F'),
	540: int8('I'),
	541: int8('R'),
	542: int8('S'),
	543: int8('T'),
	544: int8('F'),
	545: int8('O'),
	546: int8('L'),
	547: int8('L'),
	548: int8('O'),
	549: int8('W'),
	550: int8('I'),
	551: int8('N'),
	552: int8('G'),
	553: int8('F'),
	554: int8('R'),
	555: int8('O'),
	556: int8('M'),
	557: int8('F'),
	558: int8('U'),
	559: int8('L'),
	560: int8('L'),
	561: int8('I'),
	562: int8('M'),
	563: int8('I'),
	564: int8('T'),
	565: int8('I'),
	566: int8('F'),
	567: int8('O'),
	568: int8('R'),
	569: int8('D'),
	570: int8('E'),
	571: int8('R'),
	572: int8('E'),
	573: int8('S'),
	574: int8('T'),
	575: int8('R'),
	576: int8('I'),
	577: int8('C'),
	578: int8('T'),
	579: int8('O'),
	580: int8('T'),
	581: int8('H'),
	582: int8('E'),
	583: int8('R'),
	584: int8('S'),
	585: int8('O'),
	586: int8('V'),
	587: int8('E'),
	588: int8('R'),
	589: int8('E'),
	590: int8('T'),
	591: int8('U'),
	592: int8('R'),
	593: int8('N'),
	594: int8('I'),
	595: int8('N'),
	596: int8('G'),
	597: int8('R'),
	598: int8('I'),
	599: int8('G'),
	600: int8('H'),
	601: int8('T'),
	602: int8('R'),
	603: int8('O'),
	604: int8('L'),
	605: int8('L'),
	606: int8('B'),
	607: int8('A'),
	608: int8('C'),
	609: int8('K'),
	610: int8('R'),
	611: int8('O'),
	612: int8('W'),
	613: int8('S'),
	614: int8('U'),
	615: int8('N'),
	616: int8('B'),
	617: int8('O'),
	618: int8('U'),
	619: int8('N'),
	620: int8('D'),
	621: int8('E'),
	622: int8('D'),
	623: int8('U'),
	624: int8('N'),
	625: int8('I'),
	626: int8('O'),
	627: int8('N'),
	628: int8('U'),
	629: int8('S'),
	630: int8('I'),
	631: int8('N'),
	632: int8('G'),
	633: int8('V'),
	634: int8('A'),
	635: int8('C'),
	636: int8('U'),
	637: int8('U'),
	638: int8('M'),
	639: int8('V'),
	640: int8('I'),
	641: int8('E'),
	642: int8('W'),
	643: int8('I'),
	644: int8('N'),
	645: int8('D'),
	646: int8('O'),
	647: int8('W'),
	648: int8('B'),
	649: int8('Y'),
	650: int8('I'),
	651: int8('N'),
	652: int8('I'),
	653: int8('T'),
	654: int8('I'),
	655: int8('A'),
	656: int8('L'),
	657: int8('L'),
	658: int8('Y'),
	659: int8('P'),
	660: int8('R'),
	661: int8('I'),
	662: int8('M'),
	663: int8('A'),
	664: int8('R'),
	665: int8('Y'),
}

// C documentation
//
//	/* aKWHash[i] is the hash value for the i-th keyword */
var _aKWHash = [127]uint8{
	0:   uint8(84),
	1:   uint8(92),
	2:   uint8(134),
	3:   uint8(82),
	4:   uint8(105),
	5:   uint8(29),
	8:   uint8(94),
	10:  uint8(85),
	11:  uint8(72),
	13:  uint8(53),
	14:  uint8(35),
	15:  uint8(86),
	16:  uint8(15),
	18:  uint8(42),
	19:  uint8(97),
	20:  uint8(54),
	21:  uint8(89),
	22:  uint8(135),
	23:  uint8(19),
	26:  uint8(140),
	28:  uint8(40),
	29:  uint8(129),
	31:  uint8(22),
	32:  uint8(107),
	34:  uint8(9),
	37:  uint8(123),
	38:  uint8(80),
	40:  uint8(78),
	41:  uint8(6),
	43:  uint8(65),
	44:  uint8(103),
	45:  uint8(147),
	47:  uint8(136),
	48:  uint8(115),
	51:  uint8(48),
	53:  uint8(90),
	54:  uint8(24),
	56:  uint8(17),
	58:  uint8(27),
	59:  uint8(70),
	60:  uint8(23),
	61:  uint8(26),
	62:  uint8(5),
	63:  uint8(60),
	64:  uint8(142),
	65:  uint8(110),
	66:  uint8(122),
	68:  uint8(73),
	69:  uint8(91),
	70:  uint8(71),
	71:  uint8(145),
	72:  uint8(61),
	73:  uint8(120),
	74:  uint8(74),
	76:  uint8(49),
	78:  uint8(11),
	79:  uint8(41),
	81:  uint8(113),
	85:  uint8(109),
	86:  uint8(10),
	87:  uint8(111),
	88:  uint8(116),
	89:  uint8(125),
	90:  uint8(14),
	91:  uint8(50),
	92:  uint8(124),
	94:  uint8(100),
	96:  uint8(18),
	97:  uint8(121),
	98:  uint8(144),
	99:  uint8(56),
	100: uint8(130),
	101: uint8(139),
	102: uint8(88),
	103: uint8(83),
	104: uint8(37),
	105: uint8(30),
	106: uint8(126),
	109: uint8(108),
	110: uint8(51),
	111: uint8(131),
	112: uint8(128),
	114: uint8(34),
	117: uint8(132),
	119: uint8(98),
	120: uint8(38),
	121: uint8(39),
	123: uint8(20),
	124: uint8(45),
	125: uint8(117),
	126: uint8(93),
}

// C documentation
//
//	/* aKWNext[] forms the hash collision chain.  If aKWHash[i]==0
//	** then the i-th keyword has no more hash collisions.  Otherwise,
//	** the next keyword with the same hash is aKWHash[i]-1. */
var _aKWNext = [148]uint8{
	5:   uint8(4),
	7:   uint8(43),
	10:  uint8(106),
	11:  uint8(114),
	15:  uint8(2),
	18:  uint8(143),
	22:  uint8(13),
	27:  uint8(141),
	30:  uint8(119),
	31:  uint8(52),
	34:  uint8(137),
	35:  uint8(12),
	38:  uint8(62),
	40:  uint8(138),
	42:  uint8(133),
	45:  uint8(36),
	48:  uint8(28),
	49:  uint8(77),
	54:  uint8(59),
	56:  uint8(47),
	67:  uint8(69),
	73:  uint8(146),
	74:  uint8(3),
	76:  uint8(58),
	78:  uint8(1),
	79:  uint8(75),
	83:  uint8(31),
	89:  uint8(127),
	91:  uint8(104),
	93:  uint8(64),
	94:  uint8(66),
	95:  uint8(63),
	101: uint8(46),
	103: uint8(16),
	104: uint8(8),
	115: uint8(81),
	116: uint8(101),
	118: uint8(112),
	119: uint8(21),
	120: uint8(7),
	121: uint8(67),
	123: uint8(79),
	124: uint8(96),
	125: uint8(118),
	128: uint8(68),
	131: uint8(99),
	132: uint8(44),
	134: uint8(55),
	136: uint8(76),
	138: uint8(95),
	139: uint8(32),
	140: uint8(33),
	141: uint8(57),
	142: uint8(25),
	144: uint8(102),
	147: uint8(87),
}

// C documentation
//
//	/* aKWLen[i] is the length (in bytes) of the i-th keyword */
var _aKWLen = [148]uint8{
	1:   uint8(7),
	2:   uint8(7),
	3:   uint8(5),
	4:   uint8(4),
	5:   uint8(6),
	6:   uint8(4),
	7:   uint8(5),
	8:   uint8(3),
	9:   uint8(6),
	10:  uint8(7),
	11:  uint8(3),
	12:  uint8(6),
	13:  uint8(6),
	14:  uint8(7),
	15:  uint8(7),
	16:  uint8(3),
	17:  uint8(8),
	18:  uint8(2),
	19:  uint8(6),
	20:  uint8(5),
	21:  uint8(4),
	22:  uint8(4),
	23:  uint8(3),
	24:  uint8(10),
	25:  uint8(4),
	26:  uint8(7),
	27:  uint8(6),
	28:  uint8(9),
	29:  uint8(4),
	30:  uint8(2),
	31:  uint8(6),
	32:  uint8(5),
	33:  uint8(9),
	34:  uint8(9),
	35:  uint8(4),
	36:  uint8(7),
	37:  uint8(3),
	38:  uint8(2),
	39:  uint8(4),
	40:  uint8(4),
	41:  uint8(6),
	42:  uint8(11),
	43:  uint8(6),
	44:  uint8(2),
	45:  uint8(7),
	46:  uint8(5),
	47:  uint8(5),
	48:  uint8(9),
	49:  uint8(6),
	50:  uint8(10),
	51:  uint8(4),
	52:  uint8(6),
	53:  uint8(2),
	54:  uint8(3),
	55:  uint8(7),
	56:  uint8(5),
	57:  uint8(9),
	58:  uint8(6),
	59:  uint8(6),
	60:  uint8(4),
	61:  uint8(5),
	62:  uint8(5),
	63:  uint8(10),
	64:  uint8(6),
	65:  uint8(5),
	66:  uint8(7),
	67:  uint8(4),
	68:  uint8(5),
	69:  uint8(7),
	70:  uint8(6),
	71:  uint8(7),
	72:  uint8(7),
	73:  uint8(6),
	74:  uint8(5),
	75:  uint8(7),
	76:  uint8(3),
	77:  uint8(7),
	78:  uint8(4),
	79:  uint8(7),
	80:  uint8(6),
	81:  uint8(12),
	82:  uint8(9),
	83:  uint8(4),
	84:  uint8(6),
	85:  uint8(5),
	86:  uint8(4),
	87:  uint8(7),
	88:  uint8(6),
	89:  uint8(12),
	90:  uint8(8),
	91:  uint8(8),
	92:  uint8(2),
	93:  uint8(6),
	94:  uint8(6),
	95:  uint8(7),
	96:  uint8(6),
	97:  uint8(4),
	98:  uint8(5),
	99:  uint8(9),
	100: uint8(5),
	101: uint8(5),
	102: uint8(6),
	103: uint8(3),
	104: uint8(4),
	105: uint8(9),
	106: uint8(13),
	107: uint8(2),
	108: uint8(2),
	109: uint8(4),
	110: uint8(6),
	111: uint8(6),
	112: uint8(8),
	113: uint8(5),
	114: uint8(17),
	115: uint8(12),
	116: uint8(7),
	117: uint8(9),
	118: uint8(4),
	119: uint8(4),
	120: uint8(6),
	121: uint8(7),
	122: uint8(5),
	123: uint8(9),
	124: uint8(4),
	125: uint8(4),
	126: uint8(5),
	127: uint8(2),
	128: uint8(5),
	129: uint8(8),
	130: uint8(6),
	131: uint8(4),
	132: uint8(9),
	133: uint8(5),
	134: uint8(8),
	135: uint8(4),
	136: uint8(3),
	137: uint8(9),
	138: uint8(5),
	139: uint8(5),
	140: uint8(6),
	141: uint8(4),
	142: uint8(6),
	143: uint8(2),
	144: uint8(2),
	145: uint8(9),
	146: uint8(3),
	147: uint8(7),
}

// C documentation
//
//	/* aKWOffset[i] is the index into zKWText[] of the start of
//	** the text for the i-th keyword. */
var _aKWOffset = [148]uint16{
	2:   uint16(2),
	3:   uint16(2),
	4:   uint16(8),
	5:   uint16(9),
	6:   uint16(14),
	7:   uint16(16),
	8:   uint16(20),
	9:   uint16(23),
	10:  uint16(25),
	11:  uint16(25),
	12:  uint16(29),
	13:  uint16(33),
	14:  uint16(36),
	15:  uint16(41),
	16:  uint16(46),
	17:  uint16(48),
	18:  uint16(53),
	19:  uint16(54),
	20:  uint16(59),
	21:  uint16(62),
	22:  uint16(65),
	23:  uint16(67),
	24:  uint16(69),
	25:  uint16(78),
	26:  uint16(81),
	27:  uint16(86),
	28:  uint16(90),
	29:  uint16(90),
	30:  uint16(94),
	31:  uint16(99),
	32:  uint16(101),
	33:  uint16(105),
	34:  uint16(111),
	35:  uint16(119),
	36:  uint16(123),
	37:  uint16(123),
	38:  uint16(123),
	39:  uint16(126),
	40:  uint16(129),
	41:  uint16(132),
	42:  uint16(137),
	43:  uint16(142),
	44:  uint16(146),
	45:  uint16(147),
	46:  uint16(152),
	47:  uint16(156),
	48:  uint16(160),
	49:  uint16(168),
	50:  uint16(174),
	51:  uint16(181),
	52:  uint16(184),
	53:  uint16(184),
	54:  uint16(187),
	55:  uint16(189),
	56:  uint16(195),
	57:  uint16(198),
	58:  uint16(206),
	59:  uint16(211),
	60:  uint16(216),
	61:  uint16(219),
	62:  uint16(222),
	63:  uint16(226),
	64:  uint16(236),
	65:  uint16(239),
	66:  uint16(244),
	67:  uint16(244),
	68:  uint16(248),
	69:  uint16(252),
	70:  uint16(259),
	71:  uint16(265),
	72:  uint16(271),
	73:  uint16(277),
	74:  uint16(277),
	75:  uint16(283),
	76:  uint16(284),
	77:  uint16(288),
	78:  uint16(295),
	79:  uint16(299),
	80:  uint16(306),
	81:  uint16(312),
	82:  uint16(324),
	83:  uint16(333),
	84:  uint16(335),
	85:  uint16(341),
	86:  uint16(346),
	87:  uint16(348),
	88:  uint16(355),
	89:  uint16(359),
	90:  uint16(370),
	91:  uint16(377),
	92:  uint16(378),
	93:  uint16(385),
	94:  uint16(391),
	95:  uint16(397),
	96:  uint16(402),
	97:  uint16(408),
	98:  uint16(412),
	99:  uint16(415),
	100: uint16(424),
	101: uint16(429),
	102: uint16(433),
	103: uint16(439),
	104: uint16(441),
	105: uint16(444),
	106: uint16(453),
	107: uint16(455),
	108: uint16(457),
	109: uint16(466),
	110: uint16(470),
	111: uint16(476),
	112: uint16(482),
	113: uint16(490),
	114: uint16(495),
	115: uint16(495),
	116: uint16(495),
	117: uint16(511),
	118: uint16(520),
	119: uint16(523),
	120: uint16(527),
	121: uint16(532),
	122: uint16(539),
	123: uint16(544),
	124: uint16(553),
	125: uint16(557),
	126: uint16(560),
	127: uint16(565),
	128: uint16(567),
	129: uint16(571),
	130: uint16(579),
	131: uint16(585),
	132: uint16(588),
	133: uint16(597),
	134: uint16(602),
	135: uint16(610),
	136: uint16(610),
	137: uint16(614),
	138: uint16(623),
	139: uint16(628),
	140: uint16(633),
	141: uint16(639),
	142: uint16(642),
	143: uint16(645),
	144: uint16(648),
	145: uint16(650),
	146: uint16(655),
	147: uint16(659),
}

// C documentation
//
//	/* aKWCode[i] is the parser symbol code for the i-th keyword */
var _aKWCode = [148]uint8{
	1:   uint8(TK_REINDEX),
	2:   uint8(TK_INDEXED),
	3:   uint8(TK_INDEX),
	4:   uint8(TK_DESC),
	5:   uint8(TK_ESCAPE),
	6:   uint8(TK_EACH),
	7:   uint8(TK_CHECK),
	8:   uint8(TK_KEY),
	9:   uint8(TK_BEFORE),
	10:  uint8(TK_FOREIGN),
	11:  uint8(TK_FOR),
	12:  uint8(TK_IGNORE),
	13:  uint8(TK_LIKE_KW),
	14:  uint8(TK_EXPLAIN),
	15:  uint8(TK_INSTEAD),
	16:  uint8(TK_ADD),
	17:  uint8(TK_DATABASE),
	18:  uint8(TK_AS),
	19:  uint8(TK_SELECT),
	20:  uint8(TK_TABLE),
	21:  uint8(TK_JOIN_KW),
	22:  uint8(TK_THEN),
	23:  uint8(TK_END),
	24:  uint8(TK_DEFERRABLE),
	25:  uint8(TK_ELSE),
	26:  uint8(TK_EXCLUDE),
	27:  uint8(TK_DELETE),
	28:  uint8(TK_TEMP),
	29:  uint8(TK_TEMP),
	30:  uint8(TK_OR),
	31:  uint8(TK_ISNULL),
	32:  uint8(TK_NULLS),
	33:  uint8(TK_SAVEPOINT),
	34:  uint8(TK_INTERSECT),
	35:  uint8(TK_TIES),
	36:  uint8(TK_NOTNULL),
	37:  uint8(TK_NOT),
	38:  uint8(TK_NO),
	39:  uint8(TK_NULL),
	40:  uint8(TK_LIKE_KW),
	41:  uint8(TK_EXCEPT),
	42:  uint8(TK_TRANSACTION),
	43:  uint8(TK_ACTION),
	44:  uint8(TK_ON),
	45:  uint8(TK_JOIN_KW),
	46:  uint8(TK_ALTER),
	47:  uint8(TK_RAISE),
	48:  uint8(TK_EXCLUSIVE),
	49:  uint8(TK_EXISTS),
	50:  uint8(TK_CONSTRAINT),
	51:  uint8(TK_INTO),
	52:  uint8(TK_OFFSET),
	53:  uint8(TK_OF),
	54:  uint8(TK_SET),
	55:  uint8(TK_TRIGGER),
	56:  uint8(TK_RANGE),
	57:  uint8(TK_GENERATED),
	58:  uint8(TK_DETACH),
	59:  uint8(TK_HAVING),
	60:  uint8(TK_LIKE_KW),
	61:  uint8(TK_BEGIN),
	62:  uint8(TK_JOIN_KW),
	63:  uint8(TK_REFERENCES),
	64:  uint8(TK_UNIQUE),
	65:  uint8(TK_QUERY),
	66:  uint8(TK_WITHOUT),
	67:  uint8(TK_WITH),
	68:  uint8(TK_JOIN_KW),
	69:  uint8(TK_RELEASE),
	70:  uint8(TK_ATTACH),
	71:  uint8(TK_BETWEEN),
	72:  uint8(TK_NOTHING),
	73:  uint8(TK_GROUPS),
	74:  uint8(TK_GROUP),
	75:  uint8(TK_CASCADE),
	76:  uint8(TK_ASC),
	77:  uint8(TK_DEFAULT),
	78:  uint8(TK_CASE),
	79:  uint8(TK_COLLATE),
	80:  uint8(TK_CREATE),
	81:  uint8(TK_CTIME_KW),
	82:  uint8(TK_IMMEDIATE),
	83:  uint8(TK_JOIN),
	84:  uint8(TK_INSERT),
	85:  uint8(TK_MATCH),
	86:  uint8(TK_PLAN),
	87:  uint8(TK_ANALYZE),
	88:  uint8(TK_PRAGMA),
	89:  uint8(TK_MATERIALIZED),
	90:  uint8(TK_DEFERRED),
	91:  uint8(TK_DISTINCT),
	92:  uint8(TK_IS),
	93:  uint8(TK_UPDATE),
	94:  uint8(TK_VALUES),
	95:  uint8(TK_VIRTUAL),
	96:  uint8(TK_ALWAYS),
	97:  uint8(TK_WHEN),
	98:  uint8(TK_WHERE),
	99:  uint8(TK_RECURSIVE),
	100: uint8(TK_ABORT),
	101: uint8(TK_AFTER),
	102: uint8(TK_RENAME),
	103: uint8(TK_AND),
	104: uint8(TK_DROP),
	105: uint8(TK_PARTITION),
	106: uint8(TK_AUTOINCR),
	107: uint8(TK_TO),
	108: uint8(TK_IN),
	109: uint8(TK_CAST),
	110: uint8(TK_COLUMNKW),
	111: uint8(TK_COMMIT),
	112: uint8(TK_CONFLICT),
	113: uint8(TK_JOIN_KW),
	114: uint8(TK_CTIME_KW),
	115: uint8(TK_CTIME_KW),
	116: uint8(TK_CURRENT),
	117: uint8(TK_PRECEDING),
	118: uint8(TK_FAIL),
	119: uint8(TK_LAST),
	120: uint8(TK_FILTER),
	121: uint8(TK_REPLACE),
	122: uint8(TK_FIRST),
	123: uint8(TK_FOLLOWING),
	124: uint8(TK_FROM),
	125: uint8(TK_JOIN_KW),
	126: uint8(TK_LIMIT),
	127: uint8(TK_IF),
	128: uint8(TK_ORDER),
	129: uint8(TK_RESTRICT),
	130: uint8(TK_OTHERS),
	131: uint8(TK_OVER),
	132: uint8(TK_RETURNING),
	133: uint8(TK_JOIN_KW),
	134: uint8(TK_ROLLBACK),
	135: uint8(TK_ROWS),
	136: uint8(TK_ROW),
	137: uint8(TK_UNBOUNDED),
	138: uint8(TK_UNION),
	139: uint8(TK_USING),
	140: uint8(TK_VACUUM),
	141: uint8(TK_VIEW),
	142: uint8(TK_WINDOW),
	143: uint8(TK_DO),
	144: uint8(TK_BY),
	145: uint8(TK_INITIALLY),
	146: uint8(TK_ALL),
	147: uint8(TK_PRIMARY),
}

// C documentation
//
//	/* Hash table decoded:
//	**   0: INSERT
//	**   1: IS
//	**   2: ROLLBACK TRIGGER
//	**   3: IMMEDIATE
//	**   4: PARTITION
//	**   5: TEMP
//	**   6:
//	**   7:
//	**   8: VALUES WITHOUT
//	**   9:
//	**  10: MATCH
//	**  11: NOTHING
//	**  12:
//	**  13: OF
//	**  14: TIES IGNORE
//	**  15: PLAN
//	**  16: INSTEAD INDEXED
//	**  17:
//	**  18: TRANSACTION RIGHT
//	**  19: WHEN
//	**  20: SET HAVING
//	**  21: MATERIALIZED IF
//	**  22: ROWS
//	**  23: SELECT
//	**  24:
//	**  25:
//	**  26: VACUUM SAVEPOINT
//	**  27:
//	**  28: LIKE UNION VIRTUAL REFERENCES
//	**  29: RESTRICT
//	**  30:
//	**  31: THEN REGEXP
//	**  32: TO
//	**  33:
//	**  34: BEFORE
//	**  35:
//	**  36:
//	**  37: FOLLOWING COLLATE CASCADE
//	**  38: CREATE
//	**  39:
//	**  40: CASE REINDEX
//	**  41: EACH
//	**  42:
//	**  43: QUERY
//	**  44: AND ADD
//	**  45: PRIMARY ANALYZE
//	**  46:
//	**  47: ROW ASC DETACH
//	**  48: CURRENT_TIME CURRENT_DATE
//	**  49:
//	**  50:
//	**  51: EXCLUSIVE TEMPORARY
//	**  52:
//	**  53: DEFERRED
//	**  54: DEFERRABLE
//	**  55:
//	**  56: DATABASE
//	**  57:
//	**  58: DELETE VIEW GENERATED
//	**  59: ATTACH
//	**  60: END
//	**  61: EXCLUDE
//	**  62: ESCAPE DESC
//	**  63: GLOB
//	**  64: WINDOW ELSE
//	**  65: COLUMN
//	**  66: FIRST
//	**  67:
//	**  68: GROUPS ALL
//	**  69: DISTINCT DROP KEY
//	**  70: BETWEEN
//	**  71: INITIALLY
//	**  72: BEGIN
//	**  73: FILTER CHECK ACTION
//	**  74: GROUP INDEX
//	**  75:
//	**  76: EXISTS DEFAULT
//	**  77:
//	**  78: FOR CURRENT_TIMESTAMP
//	**  79: EXCEPT
//	**  80:
//	**  81: CROSS
//	**  82:
//	**  83:
//	**  84:
//	**  85: CAST
//	**  86: FOREIGN AUTOINCREMENT
//	**  87: COMMIT
//	**  88: CURRENT AFTER ALTER
//	**  89: FULL FAIL CONFLICT
//	**  90: EXPLAIN
//	**  91: CONSTRAINT
//	**  92: FROM ALWAYS
//	**  93:
//	**  94: ABORT
//	**  95:
//	**  96: AS DO
//	**  97: REPLACE WITH RELEASE
//	**  98: BY RENAME
//	**  99: RANGE RAISE
//	** 100: OTHERS
//	** 101: USING NULLS
//	** 102: PRAGMA
//	** 103: JOIN ISNULL OFFSET
//	** 104: NOT
//	** 105: OR LAST LEFT
//	** 106: LIMIT
//	** 107:
//	** 108:
//	** 109: IN
//	** 110: INTO
//	** 111: OVER RECURSIVE
//	** 112: ORDER OUTER
//	** 113:
//	** 114: INTERSECT UNBOUNDED
//	** 115:
//	** 116:
//	** 117: RETURNING ON
//	** 118:
//	** 119: WHERE
//	** 120: NO INNER
//	** 121: NULL
//	** 122:
//	** 123: TABLE
//	** 124: NATURAL NOTNULL
//	** 125: PRECEDING
//	** 126: UPDATE UNIQUE
//	*/
//	/* Check to see if z[0..n-1] is a keyword. If it is, write the
//	** parser symbol code for that keyword into *pType.  Always
//	** return the integer n (the length of the token). */
func _keywordCode(tls *libc.TLS, z uintptr, n int32, pType uintptr) (r int32) {
	var i, j int32
	var zKW uintptr
	_, _, _ = i, j, zKW
	i = (int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(z)))])*int32(4) ^ int32(_sqlite3UpperToLower[uint8(*(*int8)(unsafe.Pointer(z + uintptr(n-int32(1)))))])*int32(3) ^ n*int32(1)) % int32(127)
	i = int32(_aKWHash[i])
	for {
		if !(i > 0) {
			break
		}
		if int32(_aKWLen[i]) != n {
			goto _1
		}
		zKW = uintptr(unsafe.Pointer(&_zKWText)) + uintptr(_aKWOffset[i])
		if int32(*(*int8)(unsafe.Pointer(z))) & ^libc.Int32FromInt32(0x20) != int32(*(*int8)(unsafe.Pointer(zKW))) {
			goto _1
		}
		if int32(*(*int8)(unsafe.Pointer(z + 1))) & ^libc.Int32FromInt32(0x20) != int32(*(*int8)(unsafe.Pointer(zKW + 1))) {
			goto _1
		}
		j = int32(2)
		for j < n && int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) & ^libc.Int32FromInt32(0x20) == int32(*(*int8)(unsafe.Pointer(zKW + uintptr(j)))) {
			j++
		}
		if j < n {
			goto _1
		}
		/* REINDEX */
		/* INDEXED */
		/* INDEX */
		/* DESC */
		/* ESCAPE */
		/* EACH */
		/* CHECK */
		/* KEY */
		/* BEFORE */
		/* FOREIGN */
		/* FOR */
		/* IGNORE */
		/* REGEXP */
		/* EXPLAIN */
		/* INSTEAD */
		/* ADD */
		/* DATABASE */
		/* AS */
		/* SELECT */
		/* TABLE */
		/* LEFT */
		/* THEN */
		/* END */
		/* DEFERRABLE */
		/* ELSE */
		/* EXCLUDE */
		/* DELETE */
		/* TEMPORARY */
		/* TEMP */
		/* OR */
		/* ISNULL */
		/* NULLS */
		/* SAVEPOINT */
		/* INTERSECT */
		/* TIES */
		/* NOTNULL */
		/* NOT */
		/* NO */
		/* NULL */
		/* LIKE */
		/* EXCEPT */
		/* TRANSACTION */
		/* ACTION */
		/* ON */
		/* NATURAL */
		/* ALTER */
		/* RAISE */
		/* EXCLUSIVE */
		/* EXISTS */
		/* CONSTRAINT */
		/* INTO */
		/* OFFSET */
		/* OF */
		/* SET */
		/* TRIGGER */
		/* RANGE */
		/* GENERATED */
		/* DETACH */
		/* HAVING */
		/* GLOB */
		/* BEGIN */
		/* INNER */
		/* REFERENCES */
		/* UNIQUE */
		/* QUERY */
		/* WITHOUT */
		/* WITH */
		/* OUTER */
		/* RELEASE */
		/* ATTACH */
		/* BETWEEN */
		/* NOTHING */
		/* GROUPS */
		/* GROUP */
		/* CASCADE */
		/* ASC */
		/* DEFAULT */
		/* CASE */
		/* COLLATE */
		/* CREATE */
		/* CURRENT_DATE */
		/* IMMEDIATE */
		/* JOIN */
		/* INSERT */
		/* MATCH */
		/* PLAN */
		/* ANALYZE */
		/* PRAGMA */
		/* MATERIALIZED */
		/* DEFERRED */
		/* DISTINCT */
		/* IS */
		/* UPDATE */
		/* VALUES */
		/* VIRTUAL */
		/* ALWAYS */
		/* WHEN */
		/* WHERE */
		/* RECURSIVE */
		/* ABORT */
		/* AFTER */
		/* RENAME */
		/* AND */
		/* DROP */
		/* PARTITION */
		/* AUTOINCREMENT */
		/* TO */
		/* IN */
		/* CAST */
		/* COLUMN */
		/* COMMIT */
		/* CONFLICT */
		/* CROSS */
		/* CURRENT_TIMESTAMP */
		/* CURRENT_TIME */
		/* CURRENT */
		/* PRECEDING */
		/* FAIL */
		/* LAST */
		/* FILTER */
		/* REPLACE */
		/* FIRST */
		/* FOLLOWING */
		/* FROM */
		/* FULL */
		/* LIMIT */
		/* IF */
		/* ORDER */
		/* RESTRICT */
		/* OTHERS */
		/* OVER */
		/* RETURNING */
		/* RIGHT */
		/* ROLLBACK */
		/* ROWS */
		/* ROW */
		/* UNBOUNDED */
		/* UNION */
		/* USING */
		/* VACUUM */
		/* VIEW */
		/* WINDOW */
		/* DO */
		/* BY */
		/* INITIALLY */
		/* ALL */
		/* PRIMARY */
		*(*int32)(unsafe.Pointer(pType)) = int32(_aKWCode[i])
		break
		goto _1
	_1:
		;
		i = int32(_aKWNext[i])
	}
	return n
}

func _sqlite3KeywordCode(tls *libc.TLS, z uintptr, n int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* id at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = int32(TK_ID)
	if n >= int32(2) {
		_keywordCode(tls, z, n, bp)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func Xsqlite3_keyword_name(tls *libc.TLS, i int32, pzName uintptr, pnName uintptr) (r int32) {
	if i < 0 || i >= int32(SQLITE_N_KEYWORD) {
		return int32(SQLITE_ERROR)
	}
	i++
	*(*uintptr)(unsafe.Pointer(pzName)) = uintptr(unsafe.Pointer(&_zKWText)) + uintptr(_aKWOffset[i])
	*(*int32)(unsafe.Pointer(pnName)) = int32(_aKWLen[i])
	return SQLITE_OK
}

func Xsqlite3_keyword_count(tls *libc.TLS) (r int32) {
	return int32(SQLITE_N_KEYWORD)
}

func Xsqlite3_keyword_check(tls *libc.TLS, zName uintptr, nName int32) (r int32) {
	return libc.BoolInt32(int32(TK_ID) != _sqlite3KeywordCode(tls, zName, nName))
}

/************** End of keywordhash.h *****************************************/
/************** Continuing where we left off in tokenize.c *******************/

/*
** If X is a character that can be used in an identifier then
** IdChar(X) will be true.  Otherwise it is false.
**
** For ASCII, any character with the high-order bit set is
** allowed in an identifier.  For 7-bit characters,
** sqlite3IsIdChar[X] must be 1.
**
** For EBCDIC, the rules are more complex but have the same
** end result.
**
** Ticket #1066.  the SQL standard does not allow '$' in the
** middle of identifiers.  But many SQL implementations do.
** SQLite will allow '$' in identifiers for compatibility.
** But the feature is undocumented.
 */

// C documentation
//
//	/* Make the IdChar function accessible from ctime.c and alter.c */
func _sqlite3IsIdChar(tls *libc.TLS, c Tu8) (r int32) {
	return libc.BoolInt32(int32(_sqlite3CtypeMap[c])&int32(0x46) != 0)
}

// C documentation
//
//	/*
//	** Return the id of the next token in string (*pz). Before returning, set
//	** (*pz) to point to the byte following the parsed token.
//	*/
func _getToken(tls *libc.TLS, pz uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var z uintptr
	var _ /* t at bp+0 */ int32
	_ = z
	z = *(*uintptr)(unsafe.Pointer(pz)) /* Token type to return */
	for cond := true; cond; cond = *(*int32)(unsafe.Pointer(bp)) == int32(TK_SPACE) {
		z += uintptr(_sqlite3GetToken(tls, z, bp))
	}
	if *(*int32)(unsafe.Pointer(bp)) == int32(TK_ID) || *(*int32)(unsafe.Pointer(bp)) == int32(TK_STRING) || *(*int32)(unsafe.Pointer(bp)) == int32(TK_JOIN_KW) || *(*int32)(unsafe.Pointer(bp)) == int32(TK_WINDOW) || *(*int32)(unsafe.Pointer(bp)) == int32(TK_OVER) || _sqlite3ParserFallback(tls, *(*int32)(unsafe.Pointer(bp))) == int32(TK_ID) {
		*(*int32)(unsafe.Pointer(bp)) = int32(TK_ID)
	}
	*(*uintptr)(unsafe.Pointer(pz)) = z
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** The following three functions are called immediately after the tokenizer
//	** reads the keywords WINDOW, OVER and FILTER, respectively, to determine
//	** whether the token should be treated as a keyword or an SQL identifier.
//	** This cannot be handled by the usual lemon %fallback method, due to
//	** the ambiguity in some constructions. e.g.
//	**
//	**   SELECT sum(x) OVER ...
//	**
//	** In the above, "OVER" might be a keyword, or it might be an alias for the
//	** sum(x) expression. If a "%fallback ID OVER" directive were added to
//	** grammar, then SQLite would always treat "OVER" as an alias, making it
//	** impossible to call a window-function without a FILTER clause.
//	**
//	** WINDOW is treated as a keyword if:
//	**
//	**   * the following token is an identifier, or a keyword that can fallback
//	**     to being an identifier, and
//	**   * the token after than one is TK_AS.
//	**
//	** OVER is a keyword if:
//	**
//	**   * the previous token was TK_RP, and
//	**   * the next token is either TK_LP or an identifier.
//	**
//	** FILTER is a keyword if:
//	**
//	**   * the previous token was TK_RP, and
//	**   * the next token is TK_LP.
//	*/
func _analyzeWindowKeyword(tls *libc.TLS, _z uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _z
	var t int32
	_ = t
	t = _getToken(tls, bp)
	if t != int32(TK_ID) {
		return int32(TK_ID)
	}
	t = _getToken(tls, bp)
	if t != int32(TK_AS) {
		return int32(TK_ID)
	}
	return int32(TK_WINDOW)
}

func _analyzeOverKeyword(tls *libc.TLS, _z uintptr, lastToken int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _z
	var t int32
	_ = t
	if lastToken == int32(TK_RP) {
		t = _getToken(tls, bp)
		if t == int32(TK_LP) || t == int32(TK_ID) {
			return int32(TK_OVER)
		}
	}
	return int32(TK_ID)
}

func _analyzeFilterKeyword(tls *libc.TLS, _z uintptr, lastToken int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _z
	if lastToken == int32(TK_RP) && _getToken(tls, bp) == int32(TK_LP) {
		return int32(TK_FILTER)
	}
	return int32(TK_ID)
}

// C documentation
//
//	/*
//	** Return the length (in bytes) of the token that begins at z[0].
//	** Store the token type in *tokenType before returning.
//	*/
func _sqlite3GetToken(tls *libc.TLS, z uintptr, tokenType uintptr) (r int32) {
	var c, delim, i, n, v10, v16, v18, v21, v22, v3, v5, v7, v8 int32
	var v17, v6 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, delim, i, n, v10, v16, v17, v18, v21, v22, v3, v5, v6, v7, v8
	switch int32(_aiClass[*(*uint8)(unsafe.Pointer(z))]) { /* Switch on the character-class of the first byte
	 ** of the token. See the comment on the CC_ defines
	 ** above. */
	case int32(CC_SPACE):
		i = int32(1)
		for {
			if !(int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x01) != 0) {
				break
			}
			goto _1
		_1:
			;
			i++
		}
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_SPACE)
		return i
	case int32(CC_MINUS):
		if int32(*(*uint8)(unsafe.Pointer(z + 1))) == int32('-') {
			i = int32(2)
			for {
				v3 = int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))
				c = v3
				if !(v3 != 0 && c != int32('\n')) {
					break
				}
				goto _2
			_2:
				;
				i++
			}
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_SPACE) /* IMP: R-22934-25134 */
			return i
		} else {
			if int32(*(*uint8)(unsafe.Pointer(z + 1))) == int32('>') {
				*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_PTR)
				return int32(2) + libc.BoolInt32(int32(*(*uint8)(unsafe.Pointer(z + 2))) == int32('>'))
			}
		}
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_MINUS)
		return int32(1)
	case int32(CC_LP):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_LP)
		return int32(1)
	case int32(CC_RP):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_RP)
		return int32(1)
	case int32(CC_SEMI):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_SEMI)
		return int32(1)
	case int32(CC_PLUS):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_PLUS)
		return int32(1)
	case int32(CC_STAR):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_STAR)
		return int32(1)
	case int32(CC_SLASH):
		if int32(*(*uint8)(unsafe.Pointer(z + 1))) != int32('*') || int32(*(*uint8)(unsafe.Pointer(z + 2))) == 0 {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_SLASH)
			return int32(1)
		}
		i = int32(3)
		c = int32(*(*uint8)(unsafe.Pointer(z + 2)))
		for {
			if v6 = c != int32('*') || int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) != int32('/'); v6 {
				v5 = int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))
				c = v5
			}
			if !(v6 && v5 != 0) {
				break
			}
			goto _4
		_4:
			;
			i++
		}
		if c != 0 {
			i++
		}
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_SPACE) /* IMP: R-22934-25134 */
		return i
	case int32(CC_PERCENT):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_REM)
		return int32(1)
	case int32(CC_EQ):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_EQ)
		return int32(1) + libc.BoolInt32(int32(*(*uint8)(unsafe.Pointer(z + 1))) == int32('='))
	case int32(CC_LT):
		v7 = int32(*(*uint8)(unsafe.Pointer(z + 1)))
		c = v7
		if v7 == int32('=') {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_LE)
			return int32(2)
		} else {
			if c == int32('>') {
				*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_NE)
				return int32(2)
			} else {
				if c == int32('<') {
					*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_LSHIFT)
					return int32(2)
				} else {
					*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_LT)
					return int32(1)
				}
			}
		}
		fallthrough
	case int32(CC_GT):
		v8 = int32(*(*uint8)(unsafe.Pointer(z + 1)))
		c = v8
		if v8 == int32('=') {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_GE)
			return int32(2)
		} else {
			if c == int32('>') {
				*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_RSHIFT)
				return int32(2)
			} else {
				*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_GT)
				return int32(1)
			}
		}
		fallthrough
	case int32(CC_BANG):
		if int32(*(*uint8)(unsafe.Pointer(z + 1))) != int32('=') {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
			return int32(1)
		} else {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_NE)
			return int32(2)
		}
		fallthrough
	case int32(CC_PIPE):
		if int32(*(*uint8)(unsafe.Pointer(z + 1))) != int32('|') {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_BITOR)
			return int32(1)
		} else {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_CONCAT)
			return int32(2)
		}
		fallthrough
	case int32(CC_COMMA):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_COMMA)
		return int32(1)
	case int32(CC_AND):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_BITAND)
		return int32(1)
	case int32(CC_TILDA):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_BITNOT)
		return int32(1)
	case int32(CC_QUOTE):
		delim = int32(*(*uint8)(unsafe.Pointer(z)))
		i = int32(1)
		for {
			v10 = int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))
			c = v10
			if !(v10 != 0) {
				break
			}
			if c == delim {
				if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+int32(1))))) == delim {
					i++
				} else {
					break
				}
			}
			goto _9
		_9:
			;
			i++
		}
		if c == int32('\'') {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_STRING)
			return i + int32(1)
		} else {
			if c != 0 {
				*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ID)
				return i + int32(1)
			} else {
				*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
				return i
			}
		}
		fallthrough
	case int32(CC_DOT):
		if !(int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + 1))])&libc.Int32FromInt32(0x04) != 0) {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_DOT)
			return int32(1)
		}
		fallthrough
	case int32(CC_DIGIT):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_INTEGER)
		if int32(*(*uint8)(unsafe.Pointer(z))) == int32('0') && (int32(*(*uint8)(unsafe.Pointer(z + 1))) == int32('x') || int32(*(*uint8)(unsafe.Pointer(z + 1))) == int32('X')) && int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + 2))])&int32(0x08) != 0 {
			i = int32(3)
			for {
				if !(int32(1) != 0) {
					break
				}
				if int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x08) == 0 {
					if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32('_') {
						*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_QNUMBER)
					} else {
						break
					}
				}
				goto _11
			_11:
				;
				i++
			}
		} else {
			i = 0
			for {
				if !(int32(1) != 0) {
					break
				}
				if int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x04) == 0 {
					if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32('_') {
						*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_QNUMBER)
					} else {
						break
					}
				}
				goto _12
			_12:
				;
				i++
			}
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32('.') {
				if *(*int32)(unsafe.Pointer(tokenType)) == int32(TK_INTEGER) {
					*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_FLOAT)
				}
				i++
				for {
					if !(int32(1) != 0) {
						break
					}
					if int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x04) == 0 {
						if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32('_') {
							*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_QNUMBER)
						} else {
							break
						}
					}
					goto _13
				_13:
					;
					i++
				}
			}
			if (int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32('e') || int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32('E')) && (int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i+int32(1))))])&int32(0x04) != 0 || (int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+int32(1))))) == int32('+') || int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+int32(1))))) == int32('-')) && int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i+int32(2))))])&int32(0x04) != 0) {
				if *(*int32)(unsafe.Pointer(tokenType)) == int32(TK_INTEGER) {
					*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_FLOAT)
				}
				i += int32(2)
				for {
					if !(int32(1) != 0) {
						break
					}
					if int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x04) == 0 {
						if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32('_') {
							*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_QNUMBER)
						} else {
							break
						}
					}
					goto _14
				_14:
					;
					i++
				}
			}
		}
		for int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x46) != 0 {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
			i++
		}
		return i
	case int32(CC_QUOTE2):
		i = int32(1)
		c = int32(*(*uint8)(unsafe.Pointer(z)))
		for {
			if v17 = c != int32(']'); v17 {
				v16 = int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))
				c = v16
			}
			if !(v17 && v16 != 0) {
				break
			}
			goto _15
		_15:
			;
			i++
		}
		if c == int32(']') {
			v18 = int32(TK_ID)
		} else {
			v18 = int32(TK_ILLEGAL)
		}
		*(*int32)(unsafe.Pointer(tokenType)) = v18
		return i
	case int32(CC_VARNUM):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_VARIABLE)
		i = int32(1)
		for {
			if !(int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x04) != 0) {
				break
			}
			goto _19
		_19:
			;
			i++
		}
		return i
	case int32(CC_DOLLAR):
		fallthrough
	case int32(CC_VARALPHA):
		n = 0
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_VARIABLE)
		i = int32(1)
		for {
			v21 = int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))
			c = v21
			if !(v21 != 0) {
				break
			}
			if int32(_sqlite3CtypeMap[uint8(uint8(c))])&int32(0x46) != 0 {
				n++
			} else {
				if c == int32('(') && n > 0 {
					for {
						i++
						goto _23
					_23:
						;
						v22 = int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))
						c = v22
						if !(v22 != 0 && !(int32(_sqlite3CtypeMap[uint8(c)])&libc.Int32FromInt32(0x01) != 0) && c != int32(')')) {
							break
						}
					}
					if c == int32(')') {
						i++
					} else {
						*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
					}
					break
				} else {
					if c == int32(':') && int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+int32(1))))) == int32(':') {
						i++
					} else {
						break
					}
				}
			}
			goto _20
		_20:
			;
			i++
		}
		if n == 0 {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
		}
		return i
	case int32(CC_KYWD0):
		if int32(_aiClass[*(*uint8)(unsafe.Pointer(z + 1))]) > int32(CC_KYWD) {
			i = int32(1)
			break
		}
		i = int32(2)
		for {
			if !(int32(_aiClass[*(*uint8)(unsafe.Pointer(z + uintptr(i)))]) <= int32(CC_KYWD)) {
				break
			}
			goto _24
		_24:
			;
			i++
		}
		if int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x46) != 0 {
			/* This token started out using characters that can appear in keywords,
			 ** but z[i] is a character not allowed within keywords, so this must
			 ** be an identifier instead */
			i++
			break
		}
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ID)
		return _keywordCode(tls, z, i, tokenType)
	case CC_X:
		if int32(*(*uint8)(unsafe.Pointer(z + 1))) == int32('\'') {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_BLOB)
			i = int32(2)
			for {
				if !(int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x08) != 0) {
					break
				}
				goto _25
			_25:
				;
				i++
			}
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) != int32('\'') || i%int32(2) != 0 {
				*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
				for *(*uint8)(unsafe.Pointer(z + uintptr(i))) != 0 && int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) != int32('\'') {
					i++
				}
			}
			if *(*uint8)(unsafe.Pointer(z + uintptr(i))) != 0 {
				i++
			}
			return i
		}
		fallthrough
	case int32(CC_KYWD):
		fallthrough
	case int32(CC_ID):
		i = int32(1)
	case int32(CC_BOM):
		if int32(*(*uint8)(unsafe.Pointer(z + 1))) == int32(0xbb) && int32(*(*uint8)(unsafe.Pointer(z + 2))) == int32(0xbf) {
			*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_SPACE)
			return int32(3)
		}
		i = int32(1)
	case int32(CC_NUL):
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
		return 0
	default:
		*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ILLEGAL)
		return int32(1)
	}
	for int32(_sqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&int32(0x46) != 0 {
		i++
	}
	*(*int32)(unsafe.Pointer(tokenType)) = int32(TK_ID)
	return i
}

// C documentation
//
//	/*
//	** Run the parser on the given SQL string.
//	*/
func _sqlite3RunParser(tls *libc.TLS, pParse uintptr, zSql uintptr) (r int32) {
	bp := tls.Alloc(1264)
	defer tls.Free(1264)
	var db, pEngine, pParentParse uintptr
	var lastTokenParsed, mxSqlLen, n, nErr int32
	var _ /* sEngine at bp+4 */ TyyParser
	var _ /* tokenType at bp+0 */ int32
	var _ /* x at bp+1224 */ TToken
	_, _, _, _, _, _, _ = db, lastTokenParsed, mxSqlLen, n, nErr, pEngine, pParentParse
	nErr = 0                                   /* The LEMON-generated LALR(1) parser */
	n = 0                                      /* type of the next token */
	lastTokenParsed = -int32(1)                /* type of the previous token */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Max length of an SQL string */
	pParentParse = uintptr(0)                  /* Space to hold the Lemon-generated Parser object */
	mxSqlLen = *(*int32)(unsafe.Pointer(db + 120 + 1*4))
	if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
		libc.AtomicStoreNInt32(db+312, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
	}
	(*TParse)(unsafe.Pointer(pParse)).Frc = SQLITE_OK
	(*TParse)(unsafe.Pointer(pParse)).FzTail = zSql
	pEngine = bp + 4
	_sqlite3ParserInit(tls, pEngine, pParse)
	pParentParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
	(*Tsqlite3)(unsafe.Pointer(db)).FpParse = pParse
	for int32(1) != 0 {
		n = _sqlite3GetToken(tls, zSql, bp)
		mxSqlLen -= n
		if mxSqlLen < 0 {
			(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_TOOBIG)
			(*TParse)(unsafe.Pointer(pParse)).FnErr++
			break
		}
		if *(*int32)(unsafe.Pointer(bp)) >= int32(TK_WINDOW) {
			if libc.AtomicLoadNInt32(db+312, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
				(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_INTERRUPT)
				(*TParse)(unsafe.Pointer(pParse)).FnErr++
				break
			}
			if *(*int32)(unsafe.Pointer(bp)) == int32(TK_SPACE) {
				zSql += uintptr(n)
				continue
			}
			if int32(*(*int8)(unsafe.Pointer(zSql))) == 0 {
				/* Upon reaching the end of input, call the parser two more times
				 ** with tokens TK_SEMI and 0, in that order. */
				if lastTokenParsed == int32(TK_SEMI) {
					*(*int32)(unsafe.Pointer(bp)) = 0
				} else {
					if lastTokenParsed == 0 {
						break
					} else {
						*(*int32)(unsafe.Pointer(bp)) = int32(TK_SEMI)
					}
				}
				n = 0
			} else {
				if *(*int32)(unsafe.Pointer(bp)) == int32(TK_WINDOW) {
					*(*int32)(unsafe.Pointer(bp)) = _analyzeWindowKeyword(tls, zSql+6)
				} else {
					if *(*int32)(unsafe.Pointer(bp)) == int32(TK_OVER) {
						*(*int32)(unsafe.Pointer(bp)) = _analyzeOverKeyword(tls, zSql+4, lastTokenParsed)
					} else {
						if *(*int32)(unsafe.Pointer(bp)) == int32(TK_FILTER) {
							*(*int32)(unsafe.Pointer(bp)) = _analyzeFilterKeyword(tls, zSql+6, lastTokenParsed)
						} else {
							if *(*int32)(unsafe.Pointer(bp)) != int32(TK_QNUMBER) {
								(*(*TToken)(unsafe.Pointer(bp + 1224))).Fz = zSql
								(*(*TToken)(unsafe.Pointer(bp + 1224))).Fn = uint32(uint32(n))
								_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25148, libc.VaList(bp+1240, bp+1224))
								break
							}
						}
					}
				}
			}
		}
		(*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz = zSql
		(*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn = uint32(uint32(n))
		_sqlite3Parser(tls, pEngine, *(*int32)(unsafe.Pointer(bp)), (*TParse)(unsafe.Pointer(pParse)).FsLastToken)
		lastTokenParsed = *(*int32)(unsafe.Pointer(bp))
		zSql += uintptr(n)
		if (*TParse)(unsafe.Pointer(pParse)).Frc != SQLITE_OK {
			break
		}
	}
	_sqlite3ParserFinalize(tls, pEngine)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FzErrMsg != 0 || (*TParse)(unsafe.Pointer(pParse)).Frc != SQLITE_OK && (*TParse)(unsafe.Pointer(pParse)).Frc != int32(SQLITE_DONE) {
		if (*TParse)(unsafe.Pointer(pParse)).FzErrMsg == uintptr(0) {
			(*TParse)(unsafe.Pointer(pParse)).FzErrMsg = _sqlite3MPrintf(tls, db, __ccgo_ts+4709, libc.VaList(bp+1240, _sqlite3ErrStr(tls, (*TParse)(unsafe.Pointer(pParse)).Frc)))
		}
		Xsqlite3_log(tls, (*TParse)(unsafe.Pointer(pParse)).Frc, __ccgo_ts+25173, libc.VaList(bp+1240, (*TParse)(unsafe.Pointer(pParse)).FzErrMsg, (*TParse)(unsafe.Pointer(pParse)).FzTail))
		nErr++
	}
	(*TParse)(unsafe.Pointer(pParse)).FzTail = zSql
	Xsqlite3_free(tls, (*TParse)(unsafe.Pointer(pParse)).FapVtabLock)
	if (*TParse)(unsafe.Pointer(pParse)).FpNewTable != 0 && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
		/* If the pParse->declareVtab flag is set, do not delete any table
		 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
		 ** will take responsibility for freeing the Table structure.
		 */
		_sqlite3DeleteTable(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpNewTable)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0 && !(int32((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		_sqlite3DeleteTrigger(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FpVList != 0 {
		_sqlite3DbNNFreeNN(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpVList)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FpParse = pParentParse
	return nErr
}

/************** End of tokenize.c ********************************************/
/************** Begin file complete.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.
**
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that implements the sqlite3_complete() API.
** This code used to be part of the tokenizer.c source file.  But by
** separating it out, the code will be automatically omitted from
** static links that do not use it.
 */
/* #include "sqliteInt.h" */

/*
** This is defined in tokenize.c.  We just have to import the definition.
 */

/*
** Token types used by the sqlite3_complete() routine.  See the header
** comments on that procedure for additional information.
 */

// C documentation
//
//	/*
//	** Return TRUE if the given SQL string ends in a semicolon.
//	**
//	** Special handling is require for CREATE TRIGGER statements.
//	** Whenever the CREATE TRIGGER keywords are seen, the statement
//	** must end with ";END;".
//	**
//	** This implementation uses a state machine with 8 states:
//	**
//	**   (0) INVALID   We have not yet seen a non-whitespace character.
//	**
//	**   (1) START     At the beginning or end of an SQL statement.  This routine
//	**                 returns 1 if it ends in the START state and 0 if it ends
//	**                 in any other state.
//	**
//	**   (2) NORMAL    We are in the middle of statement which ends with a single
//	**                 semicolon.
//	**
//	**   (3) EXPLAIN   The keyword EXPLAIN has been seen at the beginning of
//	**                 a statement.
//	**
//	**   (4) CREATE    The keyword CREATE has been seen at the beginning of a
//	**                 statement, possibly preceded by EXPLAIN and/or followed by
//	**                 TEMP or TEMPORARY
//	**
//	**   (5) TRIGGER   We are in the middle of a trigger definition that must be
//	**                 ended by a semicolon, the keyword END, and another semicolon.
//	**
//	**   (6) SEMI      We've seen the first semicolon in the ";END;" that occurs at
//	**                 the end of a trigger definition.
//	**
//	**   (7) END       We've seen the ";END" of the ";END;" that occurs at the end
//	**                 of a trigger definition.
//	**
//	** Transitions between states above are determined by tokens extracted
//	** from the input.  The following tokens are significant:
//	**
//	**   (0) tkSEMI      A semicolon.
//	**   (1) tkWS        Whitespace.
//	**   (2) tkOTHER     Any other SQL token.
//	**   (3) tkEXPLAIN   The "explain" keyword.
//	**   (4) tkCREATE    The "create" keyword.
//	**   (5) tkTEMP      The "temp" or "temporary" keyword.
//	**   (6) tkTRIGGER   The "trigger" keyword.
//	**   (7) tkEND       The "end" keyword.
//	**
//	** Whitespace never causes a state transition and is always ignored.
//	** This means that a SQL string of all whitespace is invalid.
//	**
//	** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
//	** to recognize the end of a trigger can be omitted.  All we have to do
//	** is look for a semicolon that is not part of an string or comment.
//	*/
func Xsqlite3_complete(tls *libc.TLS, zSql uintptr) (r int32) {
	var c, nId int32
	var state, token Tu8
	_, _, _, _ = c, nId, state, token
	state = uint8(0) /* Value of the next token */
	for *(*int8)(unsafe.Pointer(zSql)) != 0 {
		switch int32(*(*int8)(unsafe.Pointer(zSql))) {
		case int32(';'): /* A semicolon */
			token = uint8(tkSEMI)
		case int32(' '):
			fallthrough
		case int32('\r'):
			fallthrough
		case int32('\t'):
			fallthrough
		case int32('\n'):
			fallthrough
		case int32('\f'): /* White space is ignored */
			token = uint8(tkWS)
		case int32('/'): /* C-style comments */
			if int32(*(*int8)(unsafe.Pointer(zSql + 1))) != int32('*') {
				token = uint8(tkOTHER)
				break
			}
			zSql += uintptr(2)
			for *(*int8)(unsafe.Pointer(zSql)) != 0 && (int32(*(*int8)(unsafe.Pointer(zSql))) != int32('*') || int32(*(*int8)(unsafe.Pointer(zSql + 1))) != int32('/')) {
				zSql++
			}
			if int32(*(*int8)(unsafe.Pointer(zSql))) == 0 {
				return 0
			}
			zSql++
			token = uint8(tkWS)
		case int32('-'): /* SQL-style comments from "--" to end of line */
			if int32(*(*int8)(unsafe.Pointer(zSql + 1))) != int32('-') {
				token = uint8(tkOTHER)
				break
			}
			for *(*int8)(unsafe.Pointer(zSql)) != 0 && int32(*(*int8)(unsafe.Pointer(zSql))) != int32('\n') {
				zSql++
			}
			if int32(*(*int8)(unsafe.Pointer(zSql))) == 0 {
				return libc.BoolInt32(int32(int32(state)) == int32(1))
			}
			token = uint8(tkWS)
		case int32('['): /* Microsoft-style identifiers in [...] */
			zSql++
			for *(*int8)(unsafe.Pointer(zSql)) != 0 && int32(*(*int8)(unsafe.Pointer(zSql))) != int32(']') {
				zSql++
			}
			if int32(*(*int8)(unsafe.Pointer(zSql))) == 0 {
				return 0
			}
			token = uint8(tkOTHER)
		case int32('`'): /* Grave-accent quoted symbols used by MySQL */
			fallthrough
		case int32('"'): /* single- and double-quoted strings */
			fallthrough
		case int32('\''):
			c = int32(*(*int8)(unsafe.Pointer(zSql)))
			zSql++
			for *(*int8)(unsafe.Pointer(zSql)) != 0 && int32(*(*int8)(unsafe.Pointer(zSql))) != c {
				zSql++
			}
			if int32(*(*int8)(unsafe.Pointer(zSql))) == 0 {
				return 0
			}
			token = uint8(tkOTHER)
		default:
			if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zSql)))])&int32(0x46) != 0 {
				nId = int32(1)
				for {
					if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zSql + uintptr(nId))))])&int32(0x46) != 0) {
						break
					}
					goto _1
				_1:
					;
					nId++
				}
				switch int32(*(*int8)(unsafe.Pointer(zSql))) {
				case int32('c'):
					fallthrough
				case int32('C'):
					if nId == int32(6) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25184, int32(6)) == 0 {
						token = uint8(tkCREATE)
					} else {
						token = uint8(tkOTHER)
					}
				case int32('t'):
					fallthrough
				case int32('T'):
					if nId == int32(7) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+21837, int32(7)) == 0 {
						token = uint8(tkTRIGGER)
					} else {
						if nId == int32(4) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25191, int32(4)) == 0 {
							token = uint8(tkTEMP)
						} else {
							if nId == int32(9) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25196, int32(9)) == 0 {
								token = uint8(tkTEMP)
							} else {
								token = uint8(tkOTHER)
							}
						}
					}
				case int32('e'):
					fallthrough
				case int32('E'):
					if nId == int32(3) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25206, int32(3)) == 0 {
						token = uint8(tkEND)
					} else {
						if nId == int32(7) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25210, int32(7)) == 0 {
							token = uint8(tkEXPLAIN)
						} else {
							token = uint8(tkOTHER)
						}
					}
				default:
					token = uint8(tkOTHER)
					break
				}
				zSql += uintptr(nId - int32(1))
			} else {
				/* Operators and special symbols */
				token = uint8(tkOTHER)
			}
			break
		}
		state = *(*Tu8)(unsafe.Pointer(uintptr(unsafe.Pointer(&_trans)) + uintptr(state)*8 + uintptr(token)))
		zSql++
	}
	return libc.BoolInt32(int32(int32(state)) == int32(1))
}

/* A complex statement machine used to detect the end of a CREATE TRIGGER
 ** statement.  This is the normal case.
 */
var _trans = [8][8]Tu8{
	0: {
		0: uint8(1),
		2: uint8(2),
		3: uint8(3),
		4: uint8(4),
		5: uint8(2),
		6: uint8(2),
		7: uint8(2),
	},
	1: {
		0: uint8(1),
		1: uint8(1),
		2: uint8(2),
		3: uint8(3),
		4: uint8(4),
		5: uint8(2),
		6: uint8(2),
		7: uint8(2),
	},
	2: {
		0: uint8(1),
		1: uint8(2),
		2: uint8(2),
		3: uint8(2),
		4: uint8(2),
		5: uint8(2),
		6: uint8(2),
		7: uint8(2),
	},
	3: {
		0: uint8(1),
		1: uint8(3),
		2: uint8(3),
		3: uint8(2),
		4: uint8(4),
		5: uint8(2),
		6: uint8(2),
		7: uint8(2),
	},
	4: {
		0: uint8(1),
		1: uint8(4),
		2: uint8(2),
		3: uint8(2),
		4: uint8(2),
		5: uint8(4),
		6: uint8(5),
		7: uint8(2),
	},
	5: {
		0: uint8(6),
		1: uint8(5),
		2: uint8(5),
		3: uint8(5),
		4: uint8(5),
		5: uint8(5),
		6: uint8(5),
		7: uint8(5),
	},
	6: {
		0: uint8(6),
		1: uint8(6),
		2: uint8(5),
		3: uint8(5),
		4: uint8(5),
		5: uint8(5),
		6: uint8(5),
		7: uint8(7),
	},
	7: {
		0: uint8(1),
		1: uint8(7),
		2: uint8(5),
		3: uint8(5),
		4: uint8(5),
		5: uint8(5),
		6: uint8(5),
		7: uint8(5),
	},
}

// 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_UTF16LE), 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
//
//	/*
//	** This is an extension initializer that is a no-op and always
//	** succeeds, except that it fails if the fault-simulation is set
//	** to 500.
//	*/
func _sqlite3TestExtInit(tls *libc.TLS, db uintptr) (r int32) {
	_ = db
	return _sqlite3FaultSim(tls, int32(500))
}

// C documentation
//
//	/*
//	** An array of pointers to extension initializer functions for
//	** built-in extensions.
//	*/
var _sqlite3BuiltinExtensions = [5]uintptr{}

func init() {
	p := unsafe.Pointer(&_sqlite3BuiltinExtensions)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_sqlite3Fts5Init)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_sqlite3RtreeInit)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_sqlite3DbstatRegister)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_sqlite3TestExtInit)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_sqlite3JsonTableFunctions)
}

// C documentation
//
//	/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
//	** a pointer to the to the sqlite3_version[] string constant.
//	*/
func Xsqlite3_libversion(tls *libc.TLS) (r uintptr) {
	return uintptr(unsafe.Pointer(&Xsqlite3_version))
}

/* IMPLEMENTATION-OF: R-25063-23286 The sqlite3_sourceid() function returns a
** pointer to a string constant whose value is the same as the
** SQLITE_SOURCE_ID C preprocessor macro. Except if SQLite is built using
** an edited copy of the amalgamation, then the last four characters of
** the hash might be different from SQLITE_SOURCE_ID.
 */
/* SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } */

// C documentation
//
//	/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
//	** returns an integer equal to SQLITE_VERSION_NUMBER.
//	*/
func Xsqlite3_libversion_number(tls *libc.TLS) (r int32) {
	return int32(SQLITE_VERSION_NUMBER)
}

// C documentation
//
//	/* IMPLEMENTATION-OF: R-20790-14025 The sqlite3_threadsafe() function returns
//	** zero if and only if SQLite was compiled with mutexing code omitted due to
//	** the SQLITE_THREADSAFE compile-time option being set to 0.
//	*/
func Xsqlite3_threadsafe(tls *libc.TLS) (r int32) {
	return int32(SQLITE_THREADSAFE)
}

// C documentation
//
//	/*
//	** Determine whether or not high-precision (long double) floating point
//	** math works correctly on CPU currently running.
//	*/
func _hasHighPrecisionDouble(tls *libc.TLS, rc int32) (r int32) {
	var a, b, c float64
	_, _, _ = a, b, c
	if uint32(8) <= uint32(8) {
		/* If the size of "long double" is not more than 8, then
		 ** high-precision math is not possible. */
		return 0
	} else {
		rc++
		a = float64(1) + float64(float64(rc))*float64(0.1)
		b = float64(1e+18) + float64(float64(rc))*float64(25)
		c = a + b
		return libc.BoolInt32(b != c)
	}
	return r
}

// C documentation
//
//	/*
//	** Initialize SQLite.
//	**
//	** This routine must be called to initialize the memory allocation,
//	** VFS, and mutex subsystems prior to doing any serious work with
//	** SQLite.  But as long as you do not compile with SQLITE_OMIT_AUTOINIT
//	** this routine will be called automatically by key routines such as
//	** sqlite3_open().
//	**
//	** This routine is a no-op except on its very first call for the process,
//	** or for the first call after a call to sqlite3_shutdown.
//	**
//	** The first thread to call this routine runs the initialization to
//	** completion.  If subsequent threads call this routine before the first
//	** thread has finished the initialization process, then the subsequent
//	** threads must block until the first thread finishes with the initialization.
//	**
//	** The first thread might call this routine recursively.  Recursive
//	** calls to this routine should not block, of course.  Otherwise the
//	** initialization process would never complete.
//	**
//	** Let X be the first thread to enter this routine.  Let Y be some other
//	** thread.  Then while the initial invocation of this routine by X is
//	** incomplete, it is required that:
//	**
//	**    *  Calls to this routine from Y must block until the outer-most
//	**       call by X completes.
//	**
//	**    *  Recursive calls to this routine from thread X return immediately
//	**       without blocking.
//	*/
func Xsqlite3_initialize(tls *libc.TLS) (r int32) {
	var pMainMtx uintptr
	var rc int32
	_, _ = pMainMtx, rc /* Result code */
	/* If the following assert() fails on some obscure processor/compiler
	 ** combination, the work-around is to set the correct pointer
	 ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
	/* If SQLite is already completely initialized, then this call
	 ** to sqlite3_initialize() should be a no-op.  But the initialization
	 ** must be complete.  So isInit must not be set until the very end
	 ** of this routine.
	 */
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208) != 0 {
		_sqlite3MemoryBarrier(tls)
		return SQLITE_OK
	}
	/* Make sure the mutex subsystem is initialized.  If unable to
	 ** initialize the mutex subsystem, return early with the error.
	 ** If the system is so sick that we are unable to allocate a mutex,
	 ** there is not much SQLite is going to be able to do.
	 **
	 ** The mutex subsystem must take care of serializing its own
	 ** initialization.
	 */
	rc = _sqlite3MutexInit(tls)
	if rc != 0 {
		return rc
	}
	/* Initialize the malloc() system and the recursive pInitMutex mutex.
	 ** This operation is protected by the STATIC_MAIN mutex.  Note that
	 ** MutexAlloc() is called for a static mutex prior to initializing the
	 ** malloc subsystem - this implies that the allocation of a static
	 ** mutex must not require support from the malloc subsystem.
	 */
	pMainMtx = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
	Xsqlite3_mutex_enter(tls, pMainMtx)
	_sqlite3Config.FisMutexInit = int32(1)
	if !(_sqlite3Config.FisMallocInit != 0) {
		rc = _sqlite3MallocInit(tls)
	}
	if rc == SQLITE_OK {
		_sqlite3Config.FisMallocInit = int32(1)
		if !(_sqlite3Config.FpInitMutex != 0) {
			_sqlite3Config.FpInitMutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_RECURSIVE))
			if _sqlite3Config.FbCoreMutex != 0 && !(_sqlite3Config.FpInitMutex != 0) {
				rc = int32(SQLITE_NOMEM)
			}
		}
	}
	if rc == SQLITE_OK {
		_sqlite3Config.FnRefInitMutex++
	}
	Xsqlite3_mutex_leave(tls, pMainMtx)
	/* If rc is not SQLITE_OK at this point, then either the malloc
	 ** subsystem could not be initialized or the system failed to allocate
	 ** the pInitMutex mutex. Return an error in either case.  */
	if rc != SQLITE_OK {
		return rc
	}
	/* Do the rest of the initialization under the recursive mutex so
	 ** that we will be able to handle recursive calls into
	 ** sqlite3_initialize().  The recursive calls normally come through
	 ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
	 ** recursive calls might also be possible.
	 **
	 ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
	 ** to the xInit method, so the xInit method need not be threadsafe.
	 **
	 ** The following mutex is what serializes access to the appdef pcache xInit
	 ** methods.  The sqlite3_pcache_methods.xInit() all is embedded in the
	 ** call to sqlite3PcacheInitialize().
	 */
	Xsqlite3_mutex_enter(tls, _sqlite3Config.FpInitMutex)
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208) == 0 && _sqlite3Config.FinProgress == 0 {
		_sqlite3Config.FinProgress = int32(1)
		libc.Xmemset(tls, uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)), 0, uint32(92))
		_sqlite3RegisterBuiltinFunctions(tls)
		if _sqlite3Config.FisPCacheInit == 0 {
			rc = _sqlite3PcacheInitialize(tls)
		}
		if rc == SQLITE_OK {
			_sqlite3Config.FisPCacheInit = int32(1)
			rc = _sqlite3OsInit(tls)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3MemdbInit(tls)
		}
		if rc == SQLITE_OK {
			_sqlite3PCacheBufferSetup(tls, _sqlite3Config.FpPage, _sqlite3Config.FszPage, _sqlite3Config.FnPage)
			_sqlite3MemoryBarrier(tls)
			libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208, int32(1))
		}
		_sqlite3Config.FinProgress = 0
	}
	Xsqlite3_mutex_leave(tls, _sqlite3Config.FpInitMutex)
	/* Go back under the static mutex and clean up the recursive
	 ** mutex to prevent a resource leak.
	 */
	Xsqlite3_mutex_enter(tls, pMainMtx)
	_sqlite3Config.FnRefInitMutex--
	if _sqlite3Config.FnRefInitMutex <= 0 {
		Xsqlite3_mutex_free(tls, _sqlite3Config.FpInitMutex)
		_sqlite3Config.FpInitMutex = uintptr(0)
	}
	Xsqlite3_mutex_leave(tls, pMainMtx)
	/* The following is just a sanity check to make sure SQLite has
	 ** been compiled correctly.  It is important to run this code, but
	 ** we don't want to run it too often and soak up CPU cycles for no
	 ** reason.  So we run it once during initialization.
	 */
	/* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
	 ** compile-time option.
	 */
	/* Experimentally determine if high-precision floating point is
	 ** available. */
	// disabled
	return rc
}

// C documentation
//
//	/*
//	** Undo the effects of sqlite3_initialize().  Must not be called while
//	** there are outstanding database connections or memory allocations or
//	** while any part of SQLite is otherwise in use in any thread.  This
//	** routine is not threadsafe.  But it is safe to invoke this routine
//	** on when SQLite is already shut down.  If SQLite is already shut down
//	** when this routine is invoked, then this routine is a harmless no-op.
//	*/
func Xsqlite3_shutdown(tls *libc.TLS) (r int32) {
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208) != 0 {
		Xsqlite3_os_end(tls)
		Xsqlite3_reset_auto_extension(tls)
		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208, 0)
	}
	if _sqlite3Config.FisPCacheInit != 0 {
		_sqlite3PcacheShutdown(tls)
		_sqlite3Config.FisPCacheInit = 0
	}
	if _sqlite3Config.FisMallocInit != 0 {
		_sqlite3MallocEnd(tls)
		_sqlite3Config.FisMallocInit = 0
		/* The heap subsystem has now been shutdown and these values are supposed
		 ** to be NULL or point to memory that was obtained from sqlite3_malloc(),
		 ** which would rely on that heap subsystem; therefore, make sure these
		 ** values cannot refer to heap memory that was just invalidated when the
		 ** heap subsystem was shutdown.  This is only done if the current call to
		 ** this function resulted in the heap subsystem actually being shutdown.
		 */
		Xsqlite3_data_directory = uintptr(0)
		Xsqlite3_temp_directory = uintptr(0)
	}
	if _sqlite3Config.FisMutexInit != 0 {
		_sqlite3MutexEnd(tls)
		_sqlite3Config.FisMutexInit = 0
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This API allows applications to modify the global configuration of
//	** the SQLite library at run-time.
//	**
//	** This routine should only be called when there are no outstanding
//	** database connections or memory allocations.  This routine is not
//	** threadsafe.  Failure to heed these warnings can lead to unpredictable
//	** behavior.
//	*/
func Xsqlite3_config(tls *libc.TLS, op int32, va uintptr) (r int32) {
	var ap Tva_list
	var bOpenUri, rc int32
	var mxMmap, szMmap Tsqlite3_int64
	var pLogArg, pVal, xLog uintptr
	_, _, _, _, _, _, _, _ = ap, bOpenUri, mxMmap, pLogArg, pVal, rc, szMmap, xLog
	rc = SQLITE_OK
	/* sqlite3_config() normally returns SQLITE_MISUSE if it is invoked while
	 ** the SQLite library is in use.  Except, a few selected opcodes
	 ** are allowed.
	 */
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208) != 0 {
		if op < 0 || op > int32(63) || libc.Uint64FromInt32(1)<<op&_mAnytimeConfigOption == uint64(0) {
			return _sqlite3MisuseError(tls, int32(180234))
		}
	}
	ap = va
	switch op {
	/* Mutex configuration options are only available in a threadsafe
	 ** compile.
	 */
	case int32(SQLITE_CONFIG_SINGLETHREAD):
		/* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
		 ** Single-thread. */
		_sqlite3Config.FbCoreMutex = uint8(0) /* Disable mutex on core */
		_sqlite3Config.FbFullMutex = uint8(0) /* Disable mutex on connections */
	case int32(SQLITE_CONFIG_MULTITHREAD):
		/* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
		 ** Multi-thread. */
		_sqlite3Config.FbCoreMutex = uint8(1) /* Enable mutex on core */
		_sqlite3Config.FbFullMutex = uint8(0) /* Disable mutex on connections */
	case int32(SQLITE_CONFIG_SERIALIZED):
		/* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
		 ** Serialized. */
		_sqlite3Config.FbCoreMutex = uint8(1) /* Enable mutex on core */
		_sqlite3Config.FbFullMutex = uint8(1) /* Enable mutex on connections */
	case int32(SQLITE_CONFIG_MUTEX):
		/* Specify an alternative mutex implementation */
		_sqlite3Config.Fmutex = *(*Tsqlite3_mutex_methods)(unsafe.Pointer(libc.VaUintptr(&ap)))
	case int32(SQLITE_CONFIG_GETMUTEX):
		/* Retrieve the current mutex implementation */
		*(*Tsqlite3_mutex_methods)(unsafe.Pointer(libc.VaUintptr(&ap))) = _sqlite3Config.Fmutex
	case int32(SQLITE_CONFIG_MALLOC):
		/* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
		 ** single argument which is a pointer to an instance of the
		 ** sqlite3_mem_methods structure. The argument specifies alternative
		 ** low-level memory allocation routines to be used in place of the memory
		 ** allocation routines built into SQLite. */
		_sqlite3Config.Fm = *(*Tsqlite3_mem_methods)(unsafe.Pointer(libc.VaUintptr(&ap)))
	case int32(SQLITE_CONFIG_GETMALLOC):
		/* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
		 ** single argument which is a pointer to an instance of the
		 ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
		 ** filled with the currently defined memory allocation routines. */
		if _sqlite3Config.Fm.FxMalloc == uintptr(0) {
			_sqlite3MemSetDefault(tls)
		}
		*(*Tsqlite3_mem_methods)(unsafe.Pointer(libc.VaUintptr(&ap))) = _sqlite3Config.Fm
	case int32(SQLITE_CONFIG_MEMSTATUS):
		/* Cannot change at runtime */
		/* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
		 ** single argument of type int, interpreted as a boolean, which enables
		 ** or disables the collection of memory allocation statistics. */
		_sqlite3Config.FbMemstat = libc.VaInt32(&ap)
	case int32(SQLITE_CONFIG_SMALL_MALLOC):
		_sqlite3Config.FbSmallMalloc = uint8(libc.VaInt32(&ap))
	case int32(SQLITE_CONFIG_PAGECACHE):
		/* EVIDENCE-OF: R-18761-36601 There are three arguments to
		 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
		 ** the size of each page cache line (sz), and the number of cache lines
		 ** (N). */
		_sqlite3Config.FpPage = libc.VaUintptr(&ap)
		_sqlite3Config.FszPage = libc.VaInt32(&ap)
		_sqlite3Config.FnPage = libc.VaInt32(&ap)
	case int32(SQLITE_CONFIG_PCACHE_HDRSZ):
		/* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
		 ** a single parameter which is a pointer to an integer and writes into
		 ** that integer the number of extra bytes per page required for each page
		 ** in SQLITE_CONFIG_PAGECACHE. */
		*(*int32)(unsafe.Pointer(libc.VaUintptr(&ap))) = _sqlite3HeaderSizeBtree(tls) + _sqlite3HeaderSizePcache(tls) + _sqlite3HeaderSizePcache1(tls)
	case int32(SQLITE_CONFIG_PCACHE):
		/* no-op */
	case int32(SQLITE_CONFIG_GETPCACHE):
		/* now an error */
		rc = int32(SQLITE_ERROR)
	case int32(SQLITE_CONFIG_PCACHE2):
		/* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
		 ** single argument which is a pointer to an sqlite3_pcache_methods2
		 ** object. This object specifies the interface to a custom page cache
		 ** implementation. */
		_sqlite3Config.Fpcache2 = *(*Tsqlite3_pcache_methods2)(unsafe.Pointer(libc.VaUintptr(&ap)))
	case int32(SQLITE_CONFIG_GETPCACHE2):
		/* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
		 ** single argument which is a pointer to an sqlite3_pcache_methods2
		 ** object. SQLite copies of the current page cache implementation into
		 ** that object. */
		if _sqlite3Config.Fpcache2.FxInit == uintptr(0) {
			_sqlite3PCacheSetDefault(tls)
		}
		*(*Tsqlite3_pcache_methods2)(unsafe.Pointer(libc.VaUintptr(&ap))) = _sqlite3Config.Fpcache2
		break
		/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
		 ** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
		 ** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
		fallthrough
	case int32(SQLITE_CONFIG_LOOKASIDE):
		_sqlite3Config.FszLookaside = libc.VaInt32(&ap)
		_sqlite3Config.FnLookaside = libc.VaInt32(&ap)
		break
		/* Record a pointer to the logger function and its first argument.
		 ** The default is NULL.  Logging is disabled if the function pointer is
		 ** NULL.
		 */
		fallthrough
	case int32(SQLITE_CONFIG_LOG):
		xLog = libc.VaUintptr(&ap)
		pLogArg = libc.VaUintptr(&ap)
		libc.AtomicStoreNUintptr(uintptr(unsafe.Pointer(&_sqlite3Config))+236, xLog, libc.Int32FromInt32(__ATOMIC_RELAXED))
		libc.AtomicStoreNUintptr(uintptr(unsafe.Pointer(&_sqlite3Config))+240, pLogArg, libc.Int32FromInt32(__ATOMIC_RELAXED))
		break
		/* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
		 ** can be changed at start-time using the
		 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
		 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
		 */
		fallthrough
	case int32(SQLITE_CONFIG_URI):
		/* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
		 ** argument of type int. If non-zero, then URI handling is globally
		 ** enabled. If the parameter is zero, then URI handling is globally
		 ** disabled. */
		bOpenUri = libc.VaInt32(&ap)
		libc.AtomicStoreNUint8(uintptr(unsafe.Pointer(&_sqlite3Config))+6, uint8(bOpenUri), libc.Int32FromInt32(__ATOMIC_RELAXED))
	case int32(SQLITE_CONFIG_COVERING_INDEX_SCAN):
		/* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
		 ** option takes a single integer argument which is interpreted as a
		 ** boolean in order to enable or disable the use of covering indices for
		 ** full table scans in the query optimizer. */
		_sqlite3Config.FbUseCis = uint8(libc.VaInt32(&ap))
	case int32(SQLITE_CONFIG_MMAP_SIZE):
		/* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
		 ** integer (sqlite3_int64) values that are the default mmap size limit
		 ** (the default setting for PRAGMA mmap_size) and the maximum allowed
		 ** mmap size limit. */
		szMmap = libc.VaInt64(&ap)
		mxMmap = libc.VaInt64(&ap)
		/* EVIDENCE-OF: R-53367-43190 If either argument to this option is
		 ** negative, then that argument is changed to its compile-time default.
		 **
		 ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
		 ** silently truncated if necessary so that it does not exceed the
		 ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
		 ** compile-time option.
		 */
		if mxMmap < 0 || mxMmap > int64(SQLITE_MAX_MMAP_SIZE) {
			mxMmap = int64(SQLITE_MAX_MMAP_SIZE)
		}
		if szMmap < 0 {
			szMmap = SQLITE_DEFAULT_MMAP_SIZE
		}
		if szMmap > mxMmap {
			szMmap = mxMmap
		}
		_sqlite3Config.FmxMmap = mxMmap
		_sqlite3Config.FszMmap = szMmap
	case int32(SQLITE_CONFIG_PMASZ):
		_sqlite3Config.FszPma = libc.VaUint32(&ap)
	case int32(SQLITE_CONFIG_STMTJRNL_SPILL):
		_sqlite3Config.FnStmtSpill = libc.VaInt32(&ap)
	case int32(SQLITE_CONFIG_MEMDB_MAXSIZE):
		_sqlite3Config.FmxMemdbSize = libc.VaInt64(&ap)
	case int32(SQLITE_CONFIG_ROWID_IN_VIEW):
		pVal = libc.VaUintptr(&ap)
		*(*int32)(unsafe.Pointer(pVal)) = 0
	default:
		rc = int32(SQLITE_ERROR)
		break
	}
	_ = ap
	return rc
}

var _mAnytimeConfigOption = libc.Uint64FromInt32(0) | libc.Uint64FromInt32(1)<<libc.Int32FromInt32(SQLITE_CONFIG_LOG) | libc.Uint64FromInt32(1)<<libc.Int32FromInt32(SQLITE_CONFIG_PCACHE_HDRSZ)

// C documentation
//
//	/*
//	** Set up the lookaside buffers for a database connection.
//	** Return SQLITE_OK on success.
//	** If lookaside is already active, return SQLITE_BUSY.
//	**
//	** The sz parameter is the number of bytes in each lookaside slot.
//	** The cnt parameter is the number of slots.  If pStart is NULL the
//	** space for the lookaside memory is obtained from sqlite3_malloc().
//	** If pStart is not NULL then it is sz*cnt bytes of memory to use for
//	** the lookaside memory.
//	*/
func _setupLookaside(tls *libc.TLS, db uintptr, pBuf uintptr, sz int32, cnt int32) (r int32) {
	var i, nBig, nSm, v1, v4 int32
	var p, pStart uintptr
	var szAlloc Tsqlite3_int64
	_, _, _, _, _, _, _, _ = i, nBig, nSm, p, pStart, szAlloc, v1, v4
	szAlloc = int64(int64(sz)) * int64(int64(cnt)) /* Number smaller LOOKASIDE_SMALL-byte slots */
	if _sqlite3LookasideUsed(tls, db, uintptr(0)) > 0 {
		return int32(SQLITE_BUSY)
	}
	/* Free any existing lookaside buffer for this handle before
	 ** allocating a new one so we don't have to have space for
	 ** both at the same time.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced != 0 {
		Xsqlite3_free(tls, (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart)
	}
	/* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
	 ** than a pointer to be useful.
	 */
	sz = sz & ^libc.Int32FromInt32(7) /* IMP: R-33038-09382 */
	if sz <= libc.Int32FromInt64(4) {
		sz = 0
	}
	if cnt < 0 {
		cnt = 0
	}
	if sz == 0 || cnt == 0 {
		sz = 0
		pStart = uintptr(0)
	} else {
		if pBuf == uintptr(0) {
			_sqlite3BeginBenignMalloc(tls)
			pStart = _sqlite3Malloc(tls, uint64(uint64(szAlloc))) /* IMP: R-61949-35727 */
			_sqlite3EndBenignMalloc(tls)
			if pStart != 0 {
				szAlloc = int64(_sqlite3MallocSize(tls, pStart))
			}
		} else {
			pStart = pBuf
		}
	}
	if sz >= libc.Int32FromInt32(LOOKASIDE_SMALL)*libc.Int32FromInt32(3) {
		nBig = int32(szAlloc / int64(libc.Int32FromInt32(3)*libc.Int32FromInt32(LOOKASIDE_SMALL)+sz))
		nSm = int32((szAlloc - int64(sz*nBig)) / int64(LOOKASIDE_SMALL))
	} else {
		if sz >= libc.Int32FromInt32(LOOKASIDE_SMALL)*libc.Int32FromInt32(2) {
			nBig = int32(szAlloc / int64(libc.Int32FromInt32(LOOKASIDE_SMALL)+sz))
			nSm = int32((szAlloc - int64(sz*nBig)) / int64(LOOKASIDE_SMALL))
		} else {
			if sz > 0 {
				nBig = int32(szAlloc / int64(int64(sz)))
				nSm = 0
			} else {
				v1 = libc.Int32FromInt32(0)
				nSm = v1
				nBig = v1
			}
		}
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart = pStart
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = uintptr(0)
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = uintptr(0)
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(uint16(sz))
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue = uint16(uint16(sz))
	if pStart != 0 {
		p = pStart
		i = 0
		for {
			if !(i < nBig) {
				break
			}
			(*TLookasideSlot)(unsafe.Pointer(p)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = p
			p = p + uintptr(sz)
			goto _2
		_2:
			;
			i++
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle = p
		i = 0
		for {
			if !(i < nSm) {
				break
			}
			(*TLookasideSlot)(unsafe.Pointer(p)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = p
			p = p + 128
			goto _3
		_3:
			;
			i++
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = p
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = uint32(0)
		if pBuf == uintptr(0) {
			v4 = int32(1)
		} else {
			v4 = 0
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced = uint8(v4)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot = uint32(nBig + nSm)
	} else {
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = uint32(1)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced = uint8(0)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot = uint32(0)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the mutex associated with a database connection.
//	*/
func Xsqlite3_db_mutex(tls *libc.TLS, db uintptr) (r uintptr) {
	return (*Tsqlite3)(unsafe.Pointer(db)).Fmutex
}

// C documentation
//
//	/*
//	** Free up as much memory as we can from the given database
//	** connection.
//	*/
func Xsqlite3_db_release_memory(tls *libc.TLS, db uintptr) (r int32) {
	var i int32
	var pBt, pPager uintptr
	_, _, _ = i, pBt, pPager
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3BtreeEnterAll(tls, db)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 {
			pPager = _sqlite3BtreePager(tls, pBt)
			_sqlite3PagerShrink(tls, pPager)
		}
		goto _1
	_1:
		;
		i++
	}
	_sqlite3BtreeLeaveAll(tls, db)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Flush any dirty pages in the pager-cache for any attached database
//	** to disk.
//	*/
func Xsqlite3_db_cacheflush(tls *libc.TLS, db uintptr) (r int32) {
	var bSeenBusy, i, rc, v2 int32
	var pBt, pPager uintptr
	_, _, _, _, _, _ = bSeenBusy, i, pBt, pPager, rc, v2
	rc = SQLITE_OK
	bSeenBusy = 0
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3BtreeEnterAll(tls, db)
	i = 0
	for {
		if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 && _sqlite3BtreeTxnState(tls, pBt) == int32(SQLITE_TXN_WRITE) {
			pPager = _sqlite3BtreePager(tls, pBt)
			rc = _sqlite3PagerFlush(tls, pPager)
			if rc == int32(SQLITE_BUSY) {
				bSeenBusy = int32(1)
				rc = SQLITE_OK
			}
		}
		goto _1
	_1:
		;
		i++
	}
	_sqlite3BtreeLeaveAll(tls, db)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if rc == SQLITE_OK && bSeenBusy != 0 {
		v2 = int32(SQLITE_BUSY)
	} else {
		v2 = rc
	}
	return v2
}

// C documentation
//
//	/*
//	** Configuration settings for an individual database connection
//	*/
func Xsqlite3_db_config(tls *libc.TLS, db uintptr, op int32, va uintptr) (r int32) {
	var ap Tva_list
	var cnt, onoff, rc, sz int32
	var i uint32
	var oldFlags Tu64
	var pBuf, pRes uintptr
	_, _, _, _, _, _, _, _, _ = ap, cnt, i, oldFlags, onoff, pBuf, pRes, rc, sz
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	ap = va
	switch op {
	case int32(SQLITE_DBCONFIG_MAINDBNAME):
		/* IMP: R-06824-28531 */
		/* IMP: R-36257-52125 */
		(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName = libc.VaUintptr(&ap)
		rc = SQLITE_OK
	case int32(SQLITE_DBCONFIG_LOOKASIDE):
		pBuf = libc.VaUintptr(&ap) /* IMP: R-26835-10964 */
		sz = libc.VaInt32(&ap)     /* IMP: R-47871-25994 */
		cnt = libc.VaInt32(&ap)    /* IMP: R-04460-53386 */
		rc = _setupLookaside(tls, db, pBuf, sz, cnt)
	default:
		rc = int32(SQLITE_ERROR) /* IMP: R-42790-23372 */
		i = uint32(0)
		for {
			if !(i < uint32(int32(libc.Uint32FromInt64(144)/libc.Uint32FromInt64(8)))) {
				break
			}
			if _aFlagOp[i].Fop == op {
				onoff = libc.VaInt32(&ap)
				pRes = libc.VaUintptr(&ap)
				oldFlags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
				if onoff > 0 {
					*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(_aFlagOp[i].Fmask)
				} else {
					if onoff == 0 {
						*(*Tu64)(unsafe.Pointer(db + 32)) &= ^uint64(_aFlagOp[i].Fmask)
					}
				}
				if oldFlags != (*Tsqlite3)(unsafe.Pointer(db)).Fflags {
					_sqlite3ExpirePreparedStatements(tls, db, 0)
				}
				if pRes != 0 {
					*(*int32)(unsafe.Pointer(pRes)) = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(_aFlagOp[i].Fmask) != uint64(0))
				}
				rc = SQLITE_OK
				break
			}
			goto _1
		_1:
			;
			i++
		}
		break
	}
	_ = ap
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

var _aFlagOp = [18]struct {
	Fop   int32
	Fmask Tu32
}{
	0: {
		Fop:   int32(SQLITE_DBCONFIG_ENABLE_FKEY),
		Fmask: uint32(SQLITE_ForeignKeys),
	},
	1: {
		Fop:   int32(SQLITE_DBCONFIG_ENABLE_TRIGGER),
		Fmask: uint32(SQLITE_EnableTrigger),
	},
	2: {
		Fop:   int32(SQLITE_DBCONFIG_ENABLE_VIEW),
		Fmask: uint32(SQLITE_EnableView),
	},
	3: {
		Fop:   int32(SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER),
		Fmask: uint32(SQLITE_Fts3Tokenizer),
	},
	4: {
		Fop:   int32(SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION),
		Fmask: uint32(SQLITE_LoadExtension),
	},
	5: {
		Fop:   int32(SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE),
		Fmask: uint32(SQLITE_NoCkptOnClose),
	},
	6: {
		Fop:   int32(SQLITE_DBCONFIG_ENABLE_QPSG),
		Fmask: uint32(SQLITE_EnableQPSG),
	},
	7: {
		Fop:   int32(SQLITE_DBCONFIG_TRIGGER_EQP),
		Fmask: uint32(SQLITE_TriggerEQP),
	},
	8: {
		Fop:   int32(SQLITE_DBCONFIG_RESET_DATABASE),
		Fmask: uint32(SQLITE_ResetDatabase),
	},
	9: {
		Fop:   int32(SQLITE_DBCONFIG_DEFENSIVE),
		Fmask: uint32(SQLITE_Defensive),
	},
	10: {
		Fop:   int32(SQLITE_DBCONFIG_WRITABLE_SCHEMA),
		Fmask: uint32(libc.Int32FromInt32(SQLITE_WriteSchema) | libc.Int32FromInt32(SQLITE_NoSchemaError)),
	},
	11: {
		Fop:   int32(SQLITE_DBCONFIG_LEGACY_ALTER_TABLE),
		Fmask: uint32(SQLITE_LegacyAlter),
	},
	12: {
		Fop:   int32(SQLITE_DBCONFIG_DQS_DDL),
		Fmask: uint32(SQLITE_DqsDDL),
	},
	13: {
		Fop:   int32(SQLITE_DBCONFIG_DQS_DML),
		Fmask: uint32(SQLITE_DqsDML),
	},
	14: {
		Fop:   int32(SQLITE_DBCONFIG_LEGACY_FILE_FORMAT),
		Fmask: uint32(SQLITE_LegacyFileFmt),
	},
	15: {
		Fop:   int32(SQLITE_DBCONFIG_TRUSTED_SCHEMA),
		Fmask: uint32(SQLITE_TrustedSchema),
	},
	16: {
		Fop:   int32(SQLITE_DBCONFIG_STMT_SCANSTATUS),
		Fmask: uint32(SQLITE_StmtScanStatus),
	},
	17: {
		Fop:   int32(SQLITE_DBCONFIG_REVERSE_SCANORDER),
		Fmask: uint32(SQLITE_ReverseOrder),
	},
}

// C documentation
//
//	/*
//	** This is the default collating function named "BINARY" which is always
//	** available.
//	*/
func _binCollFunc(tls *libc.TLS, NotUsed uintptr, nKey1 int32, pKey1 uintptr, nKey2 int32, pKey2 uintptr) (r int32) {
	var n, rc, v1 int32
	_, _, _ = n, rc, v1
	_ = NotUsed
	if nKey1 < nKey2 {
		v1 = nKey1
	} else {
		v1 = nKey2
	}
	n = v1
	/* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
	 ** strings byte by byte using the memcmp() function from the standard C
	 ** library. */
	rc = libc.Xmemcmp(tls, pKey1, pKey2, uint32(uint32(n)))
	if rc == 0 {
		rc = nKey1 - nKey2
	}
	return rc
}

// C documentation
//
//	/*
//	** This is the collating function named "RTRIM" which is always
//	** available.  Ignore trailing spaces.
//	*/
func _rtrimCollFunc(tls *libc.TLS, pUser uintptr, nKey1 int32, pKey1 uintptr, nKey2 int32, pKey2 uintptr) (r int32) {
	var pK1, pK2 uintptr
	_, _ = pK1, pK2
	pK1 = pKey1
	pK2 = pKey2
	for nKey1 != 0 && int32(*(*Tu8)(unsafe.Pointer(pK1 + uintptr(nKey1-int32(1))))) == int32(' ') {
		nKey1--
	}
	for nKey2 != 0 && int32(*(*Tu8)(unsafe.Pointer(pK2 + uintptr(nKey2-int32(1))))) == int32(' ') {
		nKey2--
	}
	return _binCollFunc(tls, pUser, nKey1, pKey1, nKey2, pKey2)
}

// C documentation
//
//	/*
//	** Return true if CollSeq is the default built-in BINARY.
//	*/
func _sqlite3IsBinary(tls *libc.TLS, p uintptr) (r int32) {
	return libc.BoolInt32(p == uintptr(0) || (*TCollSeq)(unsafe.Pointer(p)).FxCmp == __ccgo_fp(_binCollFunc))
}

// C documentation
//
//	/*
//	** Another built-in collating sequence: NOCASE.
//	**
//	** This collating sequence is intended to be used for "case independent
//	** comparison". SQLite's knowledge of upper and lower case equivalents
//	** extends only to the 26 characters used in the English language.
//	**
//	** At the moment there is only a UTF-8 implementation.
//	*/
func _nocaseCollatingFunc(tls *libc.TLS, NotUsed uintptr, nKey1 int32, pKey1 uintptr, nKey2 int32, pKey2 uintptr) (r1 int32) {
	var r, v1 int32
	_, _ = r, v1
	if nKey1 < nKey2 {
		v1 = nKey1
	} else {
		v1 = nKey2
	}
	r = Xsqlite3_strnicmp(tls, pKey1, pKey2, v1)
	_ = NotUsed
	if 0 == r {
		r = nKey1 - nKey2
	}
	return r
}

// C documentation
//
//	/*
//	** Return the ROWID of the most recent insert
//	*/
func Xsqlite3_last_insert_rowid(tls *libc.TLS, db uintptr) (r Tsqlite_int64) {
	return (*Tsqlite3)(unsafe.Pointer(db)).FlastRowid
}

// C documentation
//
//	/*
//	** Set the value returned by the sqlite3_last_insert_rowid() API function.
//	*/
func Xsqlite3_set_last_insert_rowid(tls *libc.TLS, db uintptr, iRowid Tsqlite3_int64) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Tsqlite3)(unsafe.Pointer(db)).FlastRowid = iRowid
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
}

// C documentation
//
//	/*
//	** Return the number of changes in the most recent call to sqlite3_exec().
//	*/
func Xsqlite3_changes64(tls *libc.TLS, db uintptr) (r Tsqlite3_int64) {
	return (*Tsqlite3)(unsafe.Pointer(db)).FnChange
}

func Xsqlite3_changes(tls *libc.TLS, db uintptr) (r int32) {
	return int32(Xsqlite3_changes64(tls, db))
}

// C documentation
//
//	/*
//	** Return the number of changes since the database handle was opened.
//	*/
func Xsqlite3_total_changes64(tls *libc.TLS, db uintptr) (r Tsqlite3_int64) {
	return (*Tsqlite3)(unsafe.Pointer(db)).FnTotalChange
}

func Xsqlite3_total_changes(tls *libc.TLS, db uintptr) (r int32) {
	return int32(Xsqlite3_total_changes64(tls, db))
}

// C documentation
//
//	/*
//	** Close all open savepoints. This function only manipulates fields of the
//	** database handle object, it does not close any savepoints that may be open
//	** at the b-tree/pager level.
//	*/
func _sqlite3CloseSavepoints(tls *libc.TLS, db uintptr) {
	var pTmp uintptr
	_ = pTmp
	for (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint != 0 {
		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 = 0
	(*Tsqlite3)(unsafe.Pointer(db)).FnStatement = 0
	(*Tsqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = uint8(0)
}

// C documentation
//
//	/*
//	** Invoke the destructor function associated with FuncDef p, if any. Except,
//	** if this is not the last copy of the function, do not invoke it. Multiple
//	** copies of a single function are created when create_function() is called
//	** with SQLITE_ANY as the encoding.
//	*/
func _functionDestroy(tls *libc.TLS, db uintptr, p uintptr) {
	var pDestructor uintptr
	_ = pDestructor
	pDestructor = *(*uintptr)(unsafe.Pointer(p + 36))
	if pDestructor != 0 {
		(*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef--
		if (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef == 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDestructor)(unsafe.Pointer(pDestructor)).FxDestroy})))(tls, (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FpUserData)
			_sqlite3DbFree(tls, db, pDestructor)
		}
	}
}

// C documentation
//
//	/*
//	** Disconnect all sqlite3_vtab objects that belong to database connection
//	** db. This is called when db is being closed.
//	*/
func _disconnectAllVtab(tls *libc.TLS, db uintptr) {
	var i int32
	var p, pMod, pSchema, pTab uintptr
	_, _, _, _, _ = i, p, pMod, pSchema, pTab
	_sqlite3BtreeEnterAll(tls, db)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pSchema = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema
		if pSchema != 0 {
			p = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
			for {
				if !(p != 0) {
					break
				}
				pTab = (*THashElem)(unsafe.Pointer(p)).Fdata
				if int32((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					_sqlite3VtabDisconnect(tls, db, pTab)
				}
				goto _2
			_2:
				;
				p = (*THashElem)(unsafe.Pointer(p)).Fnext
			}
		}
		goto _1
	_1:
		;
		i++
	}
	p = (*THash)(unsafe.Pointer(db + 404)).Ffirst
	for {
		if !(p != 0) {
			break
		}
		pMod = (*THashElem)(unsafe.Pointer(p)).Fdata
		if (*TModule)(unsafe.Pointer(pMod)).FpEpoTab != 0 {
			_sqlite3VtabDisconnect(tls, db, (*TModule)(unsafe.Pointer(pMod)).FpEpoTab)
		}
		goto _3
	_3:
		;
		p = (*THashElem)(unsafe.Pointer(p)).Fnext
	}
	_sqlite3VtabUnlockList(tls, db)
	_sqlite3BtreeLeaveAll(tls, db)
}

// C documentation
//
//	/*
//	** Return TRUE if database connection db has unfinalized prepared
//	** statements or unfinished sqlite3_backup objects.
//	*/
func _connectionIsBusy(tls *libc.TLS, db uintptr) (r int32) {
	var j int32
	var pBt uintptr
	_, _ = j, pBt
	if (*Tsqlite3)(unsafe.Pointer(db)).FpVdbe != 0 {
		return int32(1)
	}
	j = 0
	for {
		if !(j < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*16))).FpBt
		if pBt != 0 && _sqlite3BtreeIsInBackup(tls, pBt) != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		j++
	}
	return 0
}

// C documentation
//
//	/*
//	** Close an existing SQLite database
//	*/
func _sqlite3Close(tls *libc.TLS, db uintptr, forceZombie int32) (r int32) {
	var p uintptr
	_ = p
	if !(db != 0) {
		/* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
		 ** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */
		return SQLITE_OK
	}
	if !(_sqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return _sqlite3MisuseError(tls, int32(181034))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_CLOSE) != 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_CLOSE), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, db, uintptr(0))
	}
	/* Force xDisconnect calls on all virtual tables */
	_disconnectAllVtab(tls, db)
	/* If a transaction is open, the disconnectAllVtab() call above
	 ** will not have called the xDisconnect() method on any virtual
	 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
	 ** call will do so. We need to do this before the check for active
	 ** SQL statements below, as the v-table implementation may be storing
	 ** some prepared statements internally.
	 */
	_sqlite3VtabRollback(tls, db)
	/* Legacy behavior (sqlite3_close() behavior) is to return
	 ** SQLITE_BUSY if the connection can not be closed immediately.
	 */
	if !(forceZombie != 0) && _connectionIsBusy(tls, db) != 0 {
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+25218, 0)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		return int32(SQLITE_BUSY)
	}
	for (*Tsqlite3)(unsafe.Pointer(db)).FpDbData != 0 {
		p = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
		(*Tsqlite3)(unsafe.Pointer(db)).FpDbData = (*TDbClientData)(unsafe.Pointer(p)).FpNext
		if (*TDbClientData)(unsafe.Pointer(p)).FxDestructor != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TDbClientData)(unsafe.Pointer(p)).FxDestructor})))(tls, (*TDbClientData)(unsafe.Pointer(p)).FpData)
		}
		Xsqlite3_free(tls, p)
	}
	/* Convert the connection into a zombie and then close it.
	 */
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_ZOMBIE)
	_sqlite3LeaveMutexAndCloseZombie(tls, db)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the transaction state for a single databse, or the maximum
//	** transaction state over all attached databases if zSchema is null.
//	*/
func Xsqlite3_txn_state(tls *libc.TLS, db uintptr, zSchema uintptr) (r int32) {
	var iDb, iTxn, nDb, x, v1, v3 int32
	var pBt uintptr
	_, _, _, _, _, _, _ = iDb, iTxn, nDb, pBt, x, v1, v3
	iTxn = -int32(1)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zSchema != 0 {
		v1 = _sqlite3FindDbName(tls, db, zSchema)
		iDb = v1
		nDb = v1
		if iDb < 0 {
			nDb--
		}
	} else {
		iDb = 0
		nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
	}
	for {
		if !(iDb <= nDb) {
			break
		}
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
		if pBt != uintptr(0) {
			v3 = _sqlite3BtreeTxnState(tls, pBt)
		} else {
			v3 = SQLITE_TXN_NONE
		}
		x = v3
		if x > iTxn {
			iTxn = x
		}
		goto _2
	_2:
		;
		iDb++
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return iTxn
}

// C documentation
//
//	/*
//	** Two variations on the public interface for closing a database
//	** connection. The sqlite3_close() version returns SQLITE_BUSY and
//	** leaves the connection open if there are unfinalized prepared
//	** statements or unfinished sqlite3_backups.  The sqlite3_close_v2()
//	** version forces the connection to become a zombie if there are
//	** unclosed resources, and arranges for deallocation when the last
//	** prepare statement or sqlite3_backup closes.
//	*/
func Xsqlite3_close(tls *libc.TLS, db uintptr) (r int32) {
	return _sqlite3Close(tls, db, 0)
}

func Xsqlite3_close_v2(tls *libc.TLS, db uintptr) (r int32) {
	return _sqlite3Close(tls, db, int32(1))
}

// C documentation
//
//	/*
//	** Close the mutex on database connection db.
//	**
//	** Furthermore, if database connection db is a zombie (meaning that there
//	** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
//	** every sqlite3_stmt has now been finalized and every sqlite3_backup has
//	** finished, then free all resources.
//	*/
func _sqlite3LeaveMutexAndCloseZombie(tls *libc.TLS, db uintptr) {
	var i, p, pColl, pDb, pMod, pNext uintptr
	var j int32
	_, _, _, _, _, _, _ = i, j, p, pColl, pDb, pMod, pNext
	/* If there are outstanding sqlite3_stmt or sqlite3_backup objects
	 ** or if the connection has not yet been closed by sqlite3_close_v2(),
	 ** then just leave the mutex and return.
	 */
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FeOpenState) != int32(SQLITE_STATE_ZOMBIE) || _connectionIsBusy(tls, db) != 0 {
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		return
	}
	/* If we reach this point, it means that the database connection has
	 ** closed all sqlite3_stmt and sqlite3_backup objects and has been
	 ** passed to sqlite3_close (meaning that it is a zombie).  Therefore,
	 ** go ahead and free all resources.
	 */
	/* If a transaction is open, roll it back. This also ensures that if
	 ** any database schemas have been modified by an uncommitted transaction
	 ** they are reset. And that the required b-tree mutex is held to make
	 ** the pager rollback and schema reset an atomic operation. */
	_sqlite3RollbackAll(tls, db, SQLITE_OK)
	/* Free any outstanding Savepoint structures. */
	_sqlite3CloseSavepoints(tls, db)
	/* Close all database connections */
	j = 0
	for {
		if !(j < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*16
		if (*TDb1)(unsafe.Pointer(pDb)).FpBt != 0 {
			_sqlite3BtreeClose(tls, (*TDb1)(unsafe.Pointer(pDb)).FpBt)
			(*TDb1)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
			if j != int32(1) {
				(*TDb1)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
			}
		}
		goto _1
	_1:
		;
		j++
	}
	/* Clear the TEMP schema separately and last */
	if (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema != 0 {
		_sqlite3SchemaClear(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema)
	}
	_sqlite3VtabUnlockList(tls, db)
	/* Free up the array of auxiliary databases */
	_sqlite3CollapseDatabaseArray(tls, db)
	/* Tell the code in notify.c that the connection no longer holds any
	 ** locks and does not require any further unlock-notify callbacks.
	 */
	_sqlite3ConnectionClosed(tls, db)
	i = (*THash)(unsafe.Pointer(db + 432)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		p = (*THashElem)(unsafe.Pointer(i)).Fdata
		for cond := true; cond; cond = p != 0 {
			_functionDestroy(tls, db, p)
			pNext = (*TFuncDef)(unsafe.Pointer(p)).FpNext
			_sqlite3DbFree(tls, db, p)
			p = pNext
		}
		goto _2
	_2:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	_sqlite3HashClear(tls, db+432)
	i = (*THash)(unsafe.Pointer(db + 448)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pColl = (*THashElem)(unsafe.Pointer(i)).Fdata
		/* Invoke any destructors registered for collation sequence user data. */
		j = 0
		for {
			if !(j < int32(3)) {
				break
			}
			if (*(*TCollSeq)(unsafe.Pointer(pColl + uintptr(j)*20))).FxDel != 0 {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*(*TCollSeq)(unsafe.Pointer(pColl + uintptr(j)*20))).FxDel})))(tls, (*(*TCollSeq)(unsafe.Pointer(pColl + uintptr(j)*20))).FpUser)
			}
			goto _4
		_4:
			;
			j++
		}
		_sqlite3DbFree(tls, db, pColl)
		goto _3
	_3:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	_sqlite3HashClear(tls, db+448)
	i = (*THash)(unsafe.Pointer(db + 404)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pMod = (*THashElem)(unsafe.Pointer(i)).Fdata
		_sqlite3VtabEponymousTableClear(tls, db, pMod)
		_sqlite3VtabModuleUnref(tls, db, pMod)
		goto _5
	_5:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	_sqlite3HashClear(tls, db+404)
	_sqlite3Error(tls, db, SQLITE_OK) /* Deallocates any cached error strings. */
	_sqlite3ValueFree(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
	_sqlite3CloseExtensions(tls, db)
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_ERROR)
	/* The temp-database schema is allocated differently from the other schema
	 ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
	 ** So it needs to be freed here. Todo: Why not roll the temp schema into
	 ** the same sqliteMalloc() as the one that allocates the database
	 ** structure?
	 */
	_sqlite3DbFree(tls, db, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema)
	if (*Tsqlite3)(unsafe.Pointer(db)).FxAutovacDestr != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAutovacDestr})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_CLOSED)
	Xsqlite3_mutex_free(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced != 0 {
		Xsqlite3_free(tls, (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart)
	}
	Xsqlite3_free(tls, db)
}

// C documentation
//
//	/*
//	** Rollback all database files.  If tripCode is not SQLITE_OK, then
//	** any write cursors are invalidated ("tripped" - as in "tripping a circuit
//	** breaker") and made to return tripCode if there are any further
//	** attempts to use that cursor.  Read cursors remain open and valid
//	** but are "saved" in case the table pages are moved around.
//	*/
func _sqlite3RollbackAll(tls *libc.TLS, db uintptr, tripCode int32) {
	var i, inTrans, schemaChange int32
	var p uintptr
	_, _, _, _ = i, inTrans, p, schemaChange
	inTrans = 0
	_sqlite3BeginBenignMalloc(tls)
	/* Obtain all b-tree mutexes before making any calls to BtreeRollback().
	 ** This is important in case the transaction being rolled back has
	 ** modified the database schema. If the b-tree mutexes are not taken
	 ** here, then another shared-cache connection might sneak in between
	 ** the database rollback and schema reset, which can cause false
	 ** corruption reports in some cases.  */
	_sqlite3BtreeEnterAll(tls, db)
	schemaChange = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_SchemaChange) != uint32(0) && int32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		p = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if p != 0 {
			if _sqlite3BtreeTxnState(tls, p) == int32(SQLITE_TXN_WRITE) {
				inTrans = int32(1)
			}
			_sqlite3BtreeRollback(tls, p, tripCode, libc.BoolInt32(!(schemaChange != 0)))
		}
		goto _1
	_1:
		;
		i++
	}
	_sqlite3VtabRollback(tls, db)
	_sqlite3EndBenignMalloc(tls)
	if schemaChange != 0 {
		_sqlite3ExpirePreparedStatements(tls, db, 0)
		_sqlite3ResetAllSchemasOfConnection(tls, db)
	}
	_sqlite3BtreeLeaveAll(tls, db)
	/* Any deferred constraint violations have now been resolved. */
	(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = 0
	(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = 0
	*(*Tu64)(unsafe.Pointer(db + 32)) &= ^(libc.Uint64FromInt32(SQLITE_DeferFKs) | uint64(libc.Int32FromInt32(0x00002))<<libc.Int32FromInt32(32))
	/* If one has been configured, invoke the rollback-hook callback */
	if (*Tsqlite3)(unsafe.Pointer(db)).FxRollbackCallback != 0 && (inTrans != 0 || !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0)) {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxRollbackCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpRollbackArg)
	}
}

/*
** Return a static string containing the name corresponding to the error code
** specified in the argument.
 */

// C documentation
//
//	/*
//	** Return a static string that describes the kind of error specified in the
//	** argument.
//	*/
func _sqlite3ErrStr(tls *libc.TLS, rc int32) (r uintptr) {
	var zErr uintptr
	_ = zErr
	zErr = __ccgo_ts + 25761
	switch rc {
	case libc.Int32FromInt32(SQLITE_ABORT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8):
		zErr = __ccgo_ts + 25775
	case int32(SQLITE_ROW):
		zErr = __ccgo_ts + 25797
	case int32(SQLITE_DONE):
		zErr = __ccgo_ts + 25819
	default:
		rc &= int32(0xff)
		if rc >= 0 && rc < int32(libc.Uint32FromInt64(116)/libc.Uint32FromInt64(4)) && _aMsg[rc] != uintptr(0) {
			zErr = _aMsg[rc]
		}
		break
	}
	return zErr
}

var _aMsg = [29]uintptr{
	0:  __ccgo_ts + 25286,
	1:  __ccgo_ts + 25299,
	3:  __ccgo_ts + 25315,
	4:  __ccgo_ts + 25340,
	5:  __ccgo_ts + 25354,
	6:  __ccgo_ts + 25373,
	7:  __ccgo_ts + 1642,
	8:  __ccgo_ts + 25398,
	9:  __ccgo_ts + 25435,
	10: __ccgo_ts + 25447,
	11: __ccgo_ts + 25462,
	12: __ccgo_ts + 25495,
	13: __ccgo_ts + 25513,
	14: __ccgo_ts + 25538,
	15: __ccgo_ts + 25567,
	17: __ccgo_ts + 7394,
	18: __ccgo_ts + 6796,
	19: __ccgo_ts + 25584,
	20: __ccgo_ts + 25602,
	21: __ccgo_ts + 25620,
	23: __ccgo_ts + 25654,
	25: __ccgo_ts + 25675,
	26: __ccgo_ts + 25701,
	27: __ccgo_ts + 25724,
	28: __ccgo_ts + 25745,
}

// C documentation
//
//	/*
//	** This routine implements a busy callback that sleeps and tries
//	** again until a timeout value is reached.  The timeout value is
//	** an integer number of milliseconds passed in as the first
//	** argument.
//	**
//	** Return non-zero to retry the lock.  Return zero to stop trying
//	** and cause SQLite to return SQLITE_BUSY.
//	*/
func _sqliteDefaultBusyCallback(tls *libc.TLS, ptr uintptr, count int32) (r int32) {
	var db uintptr
	var delay, prior, tmout int32
	_, _, _, _ = db, delay, prior, tmout
	db = ptr
	tmout = (*Tsqlite3)(unsafe.Pointer(db)).FbusyTimeout
	if count < int32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(1)) {
		delay = int32(_delays[count])
		prior = int32(_totals[count])
	} else {
		delay = int32(_delays[int32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(1))-libc.Int32FromInt32(1)])
		prior = int32(_totals[int32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(1))-libc.Int32FromInt32(1)]) + delay*(count-(int32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(1))-libc.Int32FromInt32(1)))
	}
	if prior+delay > tmout {
		delay = tmout - prior
		if delay <= 0 {
			return 0
		}
	}
	_sqlite3OsSleep(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, delay*int32(1000))
	return int32(1)
}

/* This case is for systems that have support for sleeping for fractions of
 ** a second.  Examples:  All windows systems, unix systems with nanosleep() */
var _delays = [12]Tu8{
	0:  uint8(1),
	1:  uint8(2),
	2:  uint8(5),
	3:  uint8(10),
	4:  uint8(15),
	5:  uint8(20),
	6:  uint8(25),
	7:  uint8(25),
	8:  uint8(25),
	9:  uint8(50),
	10: uint8(50),
	11: uint8(100),
}

var _totals = [12]Tu8{
	1:  uint8(1),
	2:  uint8(3),
	3:  uint8(8),
	4:  uint8(18),
	5:  uint8(33),
	6:  uint8(53),
	7:  uint8(78),
	8:  uint8(103),
	9:  uint8(128),
	10: uint8(178),
	11: uint8(228),
}

// C documentation
//
//	/*
//	** Invoke the given busy handler.
//	**
//	** This routine is called when an operation failed to acquire a
//	** lock on VFS file pFile.
//	**
//	** If this routine returns non-zero, the lock is retried.  If it
//	** returns 0, the operation aborts with an SQLITE_BUSY error.
//	*/
func _sqlite3InvokeBusyHandler(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	if (*TBusyHandler)(unsafe.Pointer(p)).FxBusyHandler == uintptr(0) || (*TBusyHandler)(unsafe.Pointer(p)).FnBusy < 0 {
		return 0
	}
	rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TBusyHandler)(unsafe.Pointer(p)).FxBusyHandler})))(tls, (*TBusyHandler)(unsafe.Pointer(p)).FpBusyArg, (*TBusyHandler)(unsafe.Pointer(p)).FnBusy)
	if rc == 0 {
		(*TBusyHandler)(unsafe.Pointer(p)).FnBusy = -int32(1)
	} else {
		(*TBusyHandler)(unsafe.Pointer(p)).FnBusy++
	}
	return rc
}

// C documentation
//
//	/*
//	** This routine sets the busy callback for an Sqlite database to the
//	** given callback function with the given argument.
//	*/
func Xsqlite3_busy_handler(tls *libc.TLS, db uintptr, xBusy uintptr, pArg uintptr) (r int32) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FxBusyHandler = xBusy
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FpBusyArg = pArg
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyTimeout = 0
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This routine sets the progress callback for an Sqlite database to the
//	** given callback function with the given argument. The progress callback will
//	** be invoked every nOps opcodes.
//	*/
func Xsqlite3_progress_handler(tls *libc.TLS, db uintptr, nOps int32, xProgress uintptr, pArg uintptr) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if nOps > 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FxProgress = xProgress
		(*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps = uint32(uint32(nOps))
		(*Tsqlite3)(unsafe.Pointer(db)).FpProgressArg = pArg
	} else {
		(*Tsqlite3)(unsafe.Pointer(db)).FxProgress = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps = uint32(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FpProgressArg = uintptr(0)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
}

// C documentation
//
//	/*
//	** This routine installs a default busy handler that waits for the
//	** specified number of milliseconds before returning 0.
//	*/
func Xsqlite3_busy_timeout(tls *libc.TLS, db uintptr, ms int32) (r int32) {
	if ms > 0 {
		Xsqlite3_busy_handler(tls, db, __ccgo_fp(_sqliteDefaultBusyCallback), db)
		(*Tsqlite3)(unsafe.Pointer(db)).FbusyTimeout = ms
	} else {
		Xsqlite3_busy_handler(tls, db, uintptr(0), uintptr(0))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Cause any pending operation to stop at its earliest opportunity.
//	*/
func Xsqlite3_interrupt(tls *libc.TLS, db uintptr) {
	libc.AtomicStoreNInt32(db+312, libc.Int32FromInt32(1), libc.Int32FromInt32(__ATOMIC_RELAXED))
}

// C documentation
//
//	/*
//	** Return true or false depending on whether or not an interrupt is
//	** pending on connection db.
//	*/
func Xsqlite3_is_interrupted(tls *libc.TLS, db uintptr) (r int32) {
	return libc.BoolInt32(libc.AtomicLoadNInt32(db+312, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0)
}

// 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, xSFunc uintptr, xStep uintptr, xFinal uintptr, xValue uintptr, xInverse uintptr, pDestructor uintptr) (r int32) {
	var extraFlags, rc int32
	var p, v1 uintptr
	_, _, _, _ = extraFlags, p, rc, v1
	if zFunctionName == uintptr(0) || xSFunc != uintptr(0) && xFinal != uintptr(0) || libc.BoolInt32(xFinal == uintptr(0)) != libc.BoolInt32(xStep == uintptr(0)) || libc.BoolInt32(xValue == uintptr(0)) != libc.BoolInt32(xInverse == uintptr(0)) || (nArg < -int32(1) || nArg > int32(SQLITE_MAX_FUNCTION_ARG)) || int32(255) < _sqlite3Strlen30(tls, zFunctionName) {
		return _sqlite3MisuseError(tls, int32(181689))
	}
	extraFlags = enc & (libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_INNOCUOUS) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE))
	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 ^= 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_UTF16LE)
	case int32(SQLITE_ANY):
		rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF8)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor)
		if rc == SQLITE_OK {
			rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF16LE)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, xSFunc, xStep, xFinal, xValue, 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, uint8(uint8(enc)), uint8(0))
	if p != 0 && (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) == uint32(uint32(enc)) && int32((*TFuncDef)(unsafe.Pointer(p)).FnArg) == nArg {
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+25842, 0)
			return int32(SQLITE_BUSY)
		} else {
			_sqlite3ExpirePreparedStatements(tls, db, 0)
		}
	} else {
		if xSFunc == uintptr(0) && 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, uint8(uint8(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++
	}
	*(*uintptr)(unsafe.Pointer(p + 36)) = pDestructor
	(*TFuncDef)(unsafe.Pointer(p)).FfuncFlags = (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) | uint32(uint32(extraFlags))
	if xSFunc != 0 {
		v1 = xSFunc
	} else {
		v1 = xStep
	}
	(*TFuncDef)(unsafe.Pointer(p)).FxSFunc = v1
	(*TFuncDef)(unsafe.Pointer(p)).FxFinalize = xFinal
	(*TFuncDef)(unsafe.Pointer(p)).FxValue = xValue
	(*TFuncDef)(unsafe.Pointer(p)).FxInverse = xInverse
	(*TFuncDef)(unsafe.Pointer(p)).FpUserData = pUserData
	(*TFuncDef)(unsafe.Pointer(p)).FnArg = int8(uint16(uint16(nArg)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Worker function used by utf-8 APIs that create new functions:
//	**
//	**    sqlite3_create_function()
//	**    sqlite3_create_function_v2()
//	**    sqlite3_create_window_function()
//	*/
func _createFunctionApi(tls *libc.TLS, db uintptr, zFunc uintptr, nArg int32, enc int32, p uintptr, xSFunc uintptr, xStep uintptr, xFinal uintptr, xValue uintptr, xInverse uintptr, xDestroy uintptr) (r int32) {
	var pArg uintptr
	var rc int32
	_, _ = pArg, rc
	rc = int32(SQLITE_ERROR)
	pArg = uintptr(0)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if xDestroy != 0 {
		pArg = _sqlite3Malloc(tls, uint64(12))
		if !(pArg != 0) {
			_sqlite3OomFault(tls, db)
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDestroy})))(tls, p)
			goto out
		}
		(*TFuncDestructor)(unsafe.Pointer(pArg)).FnRef = 0
		(*TFuncDestructor)(unsafe.Pointer(pArg)).FxDestroy = xDestroy
		(*TFuncDestructor)(unsafe.Pointer(pArg)).FpUserData = p
	}
	rc = _sqlite3CreateFunc(tls, db, zFunc, nArg, enc, p, xSFunc, xStep, xFinal, xValue, xInverse, pArg)
	if pArg != 0 && (*TFuncDestructor)(unsafe.Pointer(pArg)).FnRef == 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDestroy})))(tls, p)
		Xsqlite3_free(tls, pArg)
	}
	goto out
out:
	;
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Create new user functions.
//	*/
func Xsqlite3_create_function(tls *libc.TLS, db uintptr, zFunc uintptr, nArg int32, enc int32, p uintptr, xSFunc uintptr, xStep uintptr, xFinal uintptr) (r int32) {
	return _createFunctionApi(tls, db, zFunc, nArg, enc, p, xSFunc, xStep, xFinal, uintptr(0), uintptr(0), uintptr(0))
}

func Xsqlite3_create_function_v2(tls *libc.TLS, db uintptr, zFunc uintptr, nArg int32, enc int32, p uintptr, xSFunc uintptr, xStep uintptr, xFinal uintptr, xDestroy uintptr) (r int32) {
	return _createFunctionApi(tls, db, zFunc, nArg, enc, p, xSFunc, xStep, xFinal, uintptr(0), uintptr(0), xDestroy)
}

func Xsqlite3_create_window_function(tls *libc.TLS, db uintptr, zFunc uintptr, nArg int32, enc int32, p uintptr, xStep uintptr, xFinal uintptr, xValue uintptr, xInverse uintptr, xDestroy uintptr) (r int32) {
	return _createFunctionApi(tls, db, zFunc, nArg, enc, p, uintptr(0), xStep, xFinal, xValue, xInverse, xDestroy)
}

func Xsqlite3_create_function16(tls *libc.TLS, db uintptr, zFunctionName uintptr, nArg int32, eTextRep int32, p uintptr, xSFunc uintptr, xStep uintptr, 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_UTF16LE))
	rc = _sqlite3CreateFunc(tls, db, zFunc8, nArg, eTextRep, p, xSFunc, xStep, 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
//
//	/*
//	** The following is the implementation of an SQL function that always
//	** fails with an error message stating that the function is used in the
//	** wrong context.  The sqlite3_overload_function() API might construct
//	** SQL function that use this routine so that the functions will exist
//	** for name resolution but are actually overloaded by the xFindFunction
//	** method of virtual tables.
//	*/
func _sqlite3InvalidFunction(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var zErr, zName uintptr
	_, _ = zErr, zName
	zName = Xsqlite3_user_data(tls, context)
	_ = NotUsed
	_ = NotUsed2
	zErr = Xsqlite3_mprintf(tls, __ccgo_ts+25905, libc.VaList(bp+8, zName))
	Xsqlite3_result_error(tls, context, zErr, -int32(1))
	Xsqlite3_free(tls, zErr)
}

// C documentation
//
//	/*
//	** Declare that a function has been overloaded by a virtual table.
//	**
//	** If the function already exists as a regular global function, then
//	** this routine is a no-op.  If the function does not exist, then create
//	** a new one that always throws a run-time error.
//	**
//	** When virtual tables intend to provide an overloaded function, they
//	** should call this routine to make sure the global function exists.
//	** A global function must exist in order for name resolution to work
//	** properly.
//	*/
func Xsqlite3_overload_function(tls *libc.TLS, db uintptr, zName uintptr, nArg int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var zCopy uintptr
	_, _ = rc, zCopy
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	rc = libc.BoolInt32(_sqlite3FindFunction(tls, db, zName, nArg, uint8(SQLITE_UTF8), uint8(0)) != uintptr(0))
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if rc != 0 {
		return SQLITE_OK
	}
	zCopy = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, zName))
	if zCopy == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	return Xsqlite3_create_function_v2(tls, db, zName, nArg, int32(SQLITE_UTF8), zCopy, __ccgo_fp(_sqlite3InvalidFunction), uintptr(0), uintptr(0), __ccgo_fp(Xsqlite3_free))
}

// C documentation
//
//	/*
//	** Register a trace function.  The pArg from the previously registered trace
//	** is returned.
//	**
//	** A NULL trace function means that no tracing is executes.  A non-NULL
//	** trace is a pointer to a function that is invoked at the start of each
//	** SQL statement.
//	*/
func Xsqlite3_trace(tls *libc.TLS, db uintptr, xTrace uintptr, pArg uintptr) (r uintptr) {
	var pOld uintptr
	var v1 int32
	_, _ = pOld, v1
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pOld = (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg
	if xTrace != 0 {
		v1 = int32(SQLITE_TRACE_LEGACY)
	} else {
		v1 = 0
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = uint8(v1)
	*(*uintptr)(unsafe.Pointer(db + 216)) = xTrace
	(*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg = pArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pOld
}

// C documentation
//
//	/* Register a trace callback using the version-2 interface.
//	*/
func Xsqlite3_trace_v2(tls *libc.TLS, db uintptr, mTrace uint32, xTrace uintptr, pArg uintptr) (r int32) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if mTrace == uint32(0) {
		xTrace = uintptr(0)
	}
	if xTrace == uintptr(0) {
		mTrace = uint32(0)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = uint8(uint8(mTrace))
	*(*uintptr)(unsafe.Pointer(db + 216)) = xTrace
	(*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg = pArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Register a profile function.  The pArg from the previously registered
//	** profile function is returned.
//	**
//	** A NULL profile function means that no profiling is executes.  A non-NULL
//	** profile is a pointer to a function that is invoked at the conclusion of
//	** each SQL statement that is run.
//	*/
func Xsqlite3_profile(tls *libc.TLS, db uintptr, xProfile uintptr, pArg uintptr) (r uintptr) {
	var pOld, p1, p2 uintptr
	_, _, _ = pOld, p1, p2
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pOld = (*Tsqlite3)(unsafe.Pointer(db)).FpProfileArg
	(*Tsqlite3)(unsafe.Pointer(db)).FxProfile = xProfile
	(*Tsqlite3)(unsafe.Pointer(db)).FpProfileArg = pArg
	p1 = db + 94
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) & libc.Int32FromInt32(SQLITE_TRACE_NONLEGACY_MASK))
	if (*Tsqlite3)(unsafe.Pointer(db)).FxProfile != 0 {
		p2 = db + 94
		*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | libc.Int32FromInt32(SQLITE_TRACE_XPROFILE))
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pOld
}

// C documentation
//
//	/*
//	** Register a function to be invoked when a transaction commits.
//	** If the invoked function returns non-zero, then the commit becomes a
//	** rollback.
//	*/
func Xsqlite3_commit_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) (r uintptr) {
	var pOld uintptr
	_ = pOld
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pOld = (*Tsqlite3)(unsafe.Pointer(db)).FpCommitArg
	(*Tsqlite3)(unsafe.Pointer(db)).FxCommitCallback = xCallback
	(*Tsqlite3)(unsafe.Pointer(db)).FpCommitArg = pArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pOld
}

// C documentation
//
//	/*
//	** Register a callback to be invoked each time a row is updated,
//	** inserted or deleted using this database connection.
//	*/
func Xsqlite3_update_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) (r uintptr) {
	var pRet uintptr
	_ = pRet
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Tsqlite3)(unsafe.Pointer(db)).FpUpdateArg
	(*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback = xCallback
	(*Tsqlite3)(unsafe.Pointer(db)).FpUpdateArg = pArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

// C documentation
//
//	/*
//	** Register a callback to be invoked each time a transaction is rolled
//	** back by this database connection.
//	*/
func Xsqlite3_rollback_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) (r uintptr) {
	var pRet uintptr
	_ = pRet
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Tsqlite3)(unsafe.Pointer(db)).FpRollbackArg
	(*Tsqlite3)(unsafe.Pointer(db)).FxRollbackCallback = xCallback
	(*Tsqlite3)(unsafe.Pointer(db)).FpRollbackArg = pArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

// C documentation
//
//	/*
//	** Register a callback to be invoked each time a row is updated,
//	** inserted or deleted using this database connection.
//	*/
func Xsqlite3_preupdate_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) (r uintptr) {
	var pRet uintptr
	_ = pRet
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdateArg
	(*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback = xCallback
	(*Tsqlite3)(unsafe.Pointer(db)).FpPreUpdateArg = pArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

// C documentation
//
//	/*
//	** Register a function to be invoked prior to each autovacuum that
//	** determines the number of pages to vacuum.
//	*/
func Xsqlite3_autovacuum_pages(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr, xDestructor uintptr) (r int32) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*Tsqlite3)(unsafe.Pointer(db)).FxAutovacDestr != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAutovacDestr})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FxAutovacPages = xCallback
	(*Tsqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg = pArg
	(*Tsqlite3)(unsafe.Pointer(db)).FxAutovacDestr = xDestructor
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
//	** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
//	** is greater than sqlite3.pWalArg cast to an integer (the value configured by
//	** wal_autocheckpoint()).
//	*/
func _sqlite3WalDefaultHook(tls *libc.TLS, pClientData uintptr, db uintptr, zDb uintptr, nFrame int32) (r int32) {
	if nFrame >= int32(pClientData) {
		_sqlite3BeginBenignMalloc(tls)
		Xsqlite3_wal_checkpoint(tls, db, zDb)
		_sqlite3EndBenignMalloc(tls)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Configure an sqlite3_wal_hook() callback to automatically checkpoint
//	** a database after committing a transaction if there are nFrame or
//	** more frames in the log file. Passing zero or a negative value as the
//	** nFrame parameter disables automatic checkpoints entirely.
//	**
//	** The callback registered by this function replaces any existing callback
//	** registered using sqlite3_wal_hook(). Likewise, registering a callback
//	** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
//	** configured by this function.
//	*/
func Xsqlite3_wal_autocheckpoint(tls *libc.TLS, db uintptr, nFrame int32) (r int32) {
	if nFrame > 0 {
		Xsqlite3_wal_hook(tls, db, __ccgo_fp(_sqlite3WalDefaultHook), uintptr(nFrame))
	} else {
		Xsqlite3_wal_hook(tls, db, uintptr(0), uintptr(0))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Register a callback to be invoked each time a transaction is written
//	** into the write-ahead-log by this database connection.
//	*/
func Xsqlite3_wal_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) (r uintptr) {
	var pRet uintptr
	_ = pRet
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Tsqlite3)(unsafe.Pointer(db)).FpWalArg
	(*Tsqlite3)(unsafe.Pointer(db)).FxWalCallback = xCallback
	(*Tsqlite3)(unsafe.Pointer(db)).FpWalArg = pArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

// C documentation
//
//	/*
//	** Checkpoint database zDb.
//	*/
func Xsqlite3_wal_checkpoint_v2(tls *libc.TLS, db uintptr, zDb uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iDb, rc int32
	_, _ = iDb, rc /* Schema to checkpoint */
	/* Initialize the output variables to -1 in case an error occurs. */
	if pnLog != 0 {
		*(*int32)(unsafe.Pointer(pnLog)) = -int32(1)
	}
	if pnCkpt != 0 {
		*(*int32)(unsafe.Pointer(pnCkpt)) = -int32(1)
	}
	if eMode < SQLITE_CHECKPOINT_PASSIVE || eMode > int32(SQLITE_CHECKPOINT_TRUNCATE) {
		/* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
		 ** mode: */
		return _sqlite3MisuseError(tls, int32(182304))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zDb != 0 && *(*int8)(unsafe.Pointer(zDb)) != 0 {
		iDb = _sqlite3FindDbName(tls, db, zDb)
	} else {
		iDb = libc.Int32FromInt32(SQLITE_MAX_ATTACHED) + libc.Int32FromInt32(2) /* This means process all schemas */
	}
	if iDb < 0 {
		rc = int32(SQLITE_ERROR)
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+25956, libc.VaList(bp+8, zDb))
	} else {
		(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
		rc = _sqlite3Checkpoint(tls, db, iDb, eMode, pnLog, pnCkpt)
		_sqlite3Error(tls, db, rc)
	}
	rc = _sqlite3ApiExit(tls, db, rc)
	/* If there are no active statements, clear the interrupt flag at this
	 ** point.  */
	if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
		libc.AtomicStoreNInt32(db+312, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
//	** to contains a zero-length string, all attached databases are
//	** checkpointed.
//	*/
func Xsqlite3_wal_checkpoint(tls *libc.TLS, db uintptr, zDb uintptr) (r int32) {
	/* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to
	 ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
	return Xsqlite3_wal_checkpoint_v2(tls, db, zDb, SQLITE_CHECKPOINT_PASSIVE, uintptr(0), uintptr(0))
}

// C documentation
//
//	/*
//	** Run a checkpoint on database iDb. This is a no-op if database iDb is
//	** not currently open in WAL mode.
//	**
//	** If a transaction is open on the database being checkpointed, this
//	** function returns SQLITE_LOCKED and a checkpoint is not attempted. If
//	** an error occurs while running the checkpoint, an SQLite error code is
//	** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
//	**
//	** The mutex on database handle db should be held by the caller. The mutex
//	** associated with the specific b-tree being checkpointed is taken by
//	** this function while the checkpoint is running.
//	**
//	** If iDb is passed SQLITE_MAX_DB then all attached databases are
//	** checkpointed. If an error is encountered it is returned immediately -
//	** no attempt is made to checkpoint any remaining databases.
//	**
//	** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL, RESTART
//	** or TRUNCATE.
//	*/
func _sqlite3Checkpoint(tls *libc.TLS, db uintptr, iDb int32, eMode int32, pnLog uintptr, pnCkpt uintptr) (r int32) {
	var bBusy, i, rc, v2 int32
	_, _, _, _ = bBusy, i, rc, v2
	rc = SQLITE_OK /* Used to iterate through attached dbs */
	bBusy = 0      /* True if SQLITE_BUSY has been encountered */
	/* See forum post a006d86f72 */
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb && rc == SQLITE_OK) {
			break
		}
		if i == iDb || iDb == libc.Int32FromInt32(SQLITE_MAX_ATTACHED)+libc.Int32FromInt32(2) {
			rc = _sqlite3BtreeCheckpoint(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt, eMode, pnLog, pnCkpt)
			pnLog = uintptr(0)
			pnCkpt = uintptr(0)
			if rc == int32(SQLITE_BUSY) {
				bBusy = int32(1)
				rc = SQLITE_OK
			}
		}
		goto _1
	_1:
		;
		i++
	}
	if rc == SQLITE_OK && bBusy != 0 {
		v2 = int32(SQLITE_BUSY)
	} else {
		v2 = rc
	}
	return v2
}

// C documentation
//
//	/*
//	** This function returns true if main-memory should be used instead of
//	** a temporary file for transient pager files and statement journals.
//	** The value returned depends on the value of db->temp_store (runtime
//	** parameter) and the compile time value of SQLITE_TEMP_STORE. The
//	** following table describes the relationship between these two values
//	** and this functions return value.
//	**
//	**   SQLITE_TEMP_STORE     db->temp_store     Location of temporary database
//	**   -----------------     --------------     ------------------------------
//	**   0                     any                file      (return 0)
//	**   1                     1                  file      (return 0)
//	**   1                     2                  memory    (return 1)
//	**   1                     0                  file      (return 0)
//	**   2                     1                  file      (return 0)
//	**   2                     2                  memory    (return 1)
//	**   2                     0                  memory    (return 1)
//	**   3                     any                memory    (return 1)
//	*/
func _sqlite3TempInMemory(tls *libc.TLS, db uintptr) (r int32) {
	return libc.BoolInt32(int32((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) == int32(2))
}

// C documentation
//
//	/*
//	** Return UTF-8 encoded English language explanation of the most recent
//	** error.
//	*/
func Xsqlite3_errmsg(tls *libc.TLS, db uintptr) (r uintptr) {
	var z, v1 uintptr
	_, _ = z, v1
	if !(db != 0) {
		return _sqlite3ErrStr(tls, int32(SQLITE_NOMEM))
	}
	if !(_sqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return _sqlite3ErrStr(tls, _sqlite3MisuseError(tls, int32(182440)))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		z = _sqlite3ErrStr(tls, int32(SQLITE_NOMEM))
	} else {
		if (*Tsqlite3)(unsafe.Pointer(db)).FerrCode != 0 {
			v1 = Xsqlite3_value_text(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
		} else {
			v1 = uintptr(0)
		}
		z = v1
		if z == uintptr(0) {
			z = _sqlite3ErrStr(tls, (*Tsqlite3)(unsafe.Pointer(db)).FerrCode)
		}
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return z
}

// C documentation
//
//	/*
//	** Return the byte offset of the most recent error
//	*/
func Xsqlite3_error_offset(tls *libc.TLS, db uintptr) (r int32) {
	var iOffset int32
	_ = iOffset
	iOffset = -int32(1)
	if db != 0 && _sqlite3SafetyCheckSickOrOk(tls, db) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FerrCode != 0 {
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		iOffset = (*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	}
	return iOffset
}

// C documentation
//
//	/*
//	** Return UTF-16 encoded English language explanation of the most recent
//	** error.
//	*/
func Xsqlite3_errmsg16(tls *libc.TLS, db uintptr) (r uintptr) {
	var z uintptr
	_ = z
	if !(db != 0) {
		return uintptr(unsafe.Pointer(&_outOfMem))
	}
	if !(_sqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return uintptr(unsafe.Pointer(&_misuse))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		z = uintptr(unsafe.Pointer(&_outOfMem))
	} else {
		z = Xsqlite3_value_text16(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
		if z == uintptr(0) {
			_sqlite3ErrorWithMsg(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FerrCode, _sqlite3ErrStr(tls, (*Tsqlite3)(unsafe.Pointer(db)).FerrCode), 0)
			z = Xsqlite3_value_text16(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpErr)
		}
		/* A malloc() may have failed within the call to sqlite3_value_text16()
		 ** above. If this is the case, then the db->mallocFailed flag needs to
		 ** be cleared before returning. Do this directly, instead of via
		 ** sqlite3ApiExit(), to avoid setting the database handle error message.
		 */
		_sqlite3OomClear(tls, db)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return z
}

var _outOfMem = [14]Tu16{
	0:  uint16('o'),
	1:  uint16('u'),
	2:  uint16('t'),
	3:  uint16(' '),
	4:  uint16('o'),
	5:  uint16('f'),
	6:  uint16(' '),
	7:  uint16('m'),
	8:  uint16('e'),
	9:  uint16('m'),
	10: uint16('o'),
	11: uint16('r'),
	12: uint16('y'),
}

var _misuse = [34]Tu16{
	0:  uint16('b'),
	1:  uint16('a'),
	2:  uint16('d'),
	3:  uint16(' '),
	4:  uint16('p'),
	5:  uint16('a'),
	6:  uint16('r'),
	7:  uint16('a'),
	8:  uint16('m'),
	9:  uint16('e'),
	10: uint16('t'),
	11: uint16('e'),
	12: uint16('r'),
	13: uint16(' '),
	14: uint16('o'),
	15: uint16('r'),
	16: uint16(' '),
	17: uint16('o'),
	18: uint16('t'),
	19: uint16('h'),
	20: uint16('e'),
	21: uint16('r'),
	22: uint16(' '),
	23: uint16('A'),
	24: uint16('P'),
	25: uint16('I'),
	26: uint16(' '),
	27: uint16('m'),
	28: uint16('i'),
	29: uint16('s'),
	30: uint16('u'),
	31: uint16('s'),
	32: uint16('e'),
}

// C documentation
//
//	/*
//	** Return the most recent error code generated by an SQLite routine. If NULL is
//	** passed to this function, we assume a malloc() failed during sqlite3_open().
//	*/
func Xsqlite3_errcode(tls *libc.TLS, db uintptr) (r int32) {
	if db != 0 && !(_sqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return _sqlite3MisuseError(tls, int32(182519))
	}
	if !(db != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return int32(SQLITE_NOMEM)
	}
	return (*Tsqlite3)(unsafe.Pointer(db)).FerrCode & (*Tsqlite3)(unsafe.Pointer(db)).FerrMask
}

func Xsqlite3_extended_errcode(tls *libc.TLS, db uintptr) (r int32) {
	if db != 0 && !(_sqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return _sqlite3MisuseError(tls, int32(182528))
	}
	if !(db != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return int32(SQLITE_NOMEM)
	}
	return (*Tsqlite3)(unsafe.Pointer(db)).FerrCode
}

func Xsqlite3_system_errno(tls *libc.TLS, db uintptr) (r int32) {
	var v1 int32
	_ = v1
	if db != 0 {
		v1 = (*Tsqlite3)(unsafe.Pointer(db)).FiSysErrno
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Return a string that describes the kind of error specified in the
//	** argument.  For now, this simply calls the internal sqlite3ErrStr()
//	** function.
//	*/
func Xsqlite3_errstr(tls *libc.TLS, rc int32) (r uintptr) {
	return _sqlite3ErrStr(tls, rc)
}

// 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, xCompare uintptr, 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 = int32(int32(enc))
	if enc2 == int32(SQLITE_UTF16) || enc2 == int32(SQLITE_UTF16_ALIGNED) {
		enc2 = int32(SQLITE_UTF16LE)
	}
	if enc2 < int32(SQLITE_UTF8) || enc2 > int32(SQLITE_UTF16BE) {
		return _sqlite3MisuseError(tls, int32(182576))
	}
	/* 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, uint8(uint8(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+25977, 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 int32((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) & ^libc.Int32FromInt32(SQLITE_UTF16_ALIGNED) == enc2 {
			aColl = _sqlite3HashFind(tls, db+448, zName)
			j = 0
			for {
				if !(j < int32(3)) {
					break
				}
				p = aColl + uintptr(j)*20
				if int32((*TCollSeq)(unsafe.Pointer(p)).Fenc) == int32((*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++
			}
		}
	}
	pColl = _sqlite3FindCollSeq(tls, db, uint8(uint8(enc2)), zName, int32(1))
	if pColl == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TCollSeq)(unsafe.Pointer(pColl)).FxCmp = xCompare
	(*TCollSeq)(unsafe.Pointer(pColl)).FpUser = pCtx
	(*TCollSeq)(unsafe.Pointer(pColl)).FxDel = xDel
	(*TCollSeq)(unsafe.Pointer(pColl)).Fenc = uint8(enc2 | int32(int32(enc))&libc.Int32FromInt32(SQLITE_UTF16_ALIGNED))
	_sqlite3Error(tls, db, SQLITE_OK)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This array defines hard upper bounds on limit values.  The
//	** initializer must be kept in sync with the SQLITE_LIMIT_*
//	** #defines in sqlite3.h.
//	*/
var _aHardLimit = [12]int32{
	0:  int32(SQLITE_MAX_LENGTH),
	1:  int32(SQLITE_MAX_SQL_LENGTH),
	2:  int32(SQLITE_MAX_COLUMN),
	3:  int32(SQLITE_MAX_EXPR_DEPTH),
	4:  int32(SQLITE_MAX_COMPOUND_SELECT),
	5:  int32(SQLITE_MAX_VDBE_OP),
	6:  int32(SQLITE_MAX_FUNCTION_ARG),
	7:  int32(SQLITE_MAX_ATTACHED),
	8:  int32(SQLITE_MAX_LIKE_PATTERN_LENGTH),
	9:  int32(SQLITE_MAX_VARIABLE_NUMBER),
	10: int32(SQLITE_MAX_TRIGGER_DEPTH),
	11: int32(SQLITE_MAX_WORKER_THREADS),
}

/*
** Make sure the hard limits are set to reasonable values
 */

// C documentation
//
//	/*
//	** Change the value of a limit.  Report the old value.
//	** If an invalid limit index is supplied, report -1.
//	** Make no changes but still report the old value if the
//	** new limit is negative.
//	**
//	** A new lower limit does not shrink existing constructs.
//	** It merely prevents new constructs that exceed the limit
//	** from forming.
//	*/
func Xsqlite3_limit(tls *libc.TLS, db uintptr, limitId int32, newLimit int32) (r int32) {
	var oldLimit int32
	_ = oldLimit
	/* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
	 ** there is a hard upper bound set at compile-time by a C preprocessor
	 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
	 ** "_MAX_".)
	 */
	if limitId < 0 || limitId >= libc.Int32FromInt32(SQLITE_LIMIT_WORKER_THREADS)+libc.Int32FromInt32(1) {
		return -int32(1)
	}
	oldLimit = *(*int32)(unsafe.Pointer(db + 120 + uintptr(limitId)*4))
	if newLimit >= 0 { /* IMP: R-52476-28732 */
		if newLimit > _aHardLimit[limitId] {
			newLimit = _aHardLimit[limitId] /* IMP: R-51463-25634 */
		} else {
			if newLimit < int32(1) && limitId == SQLITE_LIMIT_LENGTH {
				newLimit = int32(1)
			}
		}
		*(*int32)(unsafe.Pointer(db + 120 + uintptr(limitId)*4)) = newLimit
	}
	return oldLimit /* IMP: R-53341-35419 */
}

// C documentation
//
//	/*
//	** This function is used to parse both URIs and non-URI filenames passed by the
//	** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
//	** URIs specified as part of ATTACH statements.
//	**
//	** The first argument to this function is the name of the VFS to use (or
//	** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
//	** query parameter. The second argument contains the URI (or non-URI filename)
//	** itself. When this function is called the *pFlags variable should contain
//	** the default flags to open the database handle with. The value stored in
//	** *pFlags may be updated before returning if the URI filename contains
//	** "cache=xxx" or "mode=xxx" query parameters.
//	**
//	** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
//	** the VFS that should be used to open the database file. *pzFile is set to
//	** point to a buffer containing the name of the file to open.  The value
//	** stored in *pzFile is a database name acceptable to sqlite3_uri_parameter()
//	** and is in the same format as names created using sqlite3_create_filename().
//	** The caller must invoke sqlite3_free_filename() (not sqlite3_free()!) on
//	** the value returned in *pzFile to avoid a memory leak.
//	**
//	** If an error occurs, then an SQLite error code is returned and *pzErrMsg
//	** may be set to point to a buffer containing an English language error
//	** message. It is the responsibility of the caller to eventually release
//	** this buffer by calling sqlite3_free().
//	*/
func _sqlite3ParseUri(tls *libc.TLS, zDefaultVfs uintptr, zUri uintptr, pFlags uintptr, ppVfs uintptr, pzFile uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aMode, z, zFile, zModeType, zOpt, zVal, zVfs uintptr
	var c, v2, v5 int8
	var eState, i, iIn, iOut, limit, mask, mode, nOpt, nUri, nVal, octet, rc, v3, v4, v6, v7, v8 int32
	var flags uint32
	var nByte Tu64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aMode, c, eState, flags, i, iIn, iOut, limit, mask, mode, nByte, nOpt, nUri, nVal, octet, rc, z, zFile, zModeType, zOpt, zVal, zVfs, v2, v3, v4, v5, v6, v7, v8
	rc = SQLITE_OK
	flags = *(*uint32)(unsafe.Pointer(pFlags))
	zVfs = zDefaultVfs
	nUri = _sqlite3Strlen30(tls, zUri)
	if (flags&uint32(SQLITE_OPEN_URI) != 0 || libc.AtomicLoadNUint8(uintptr(unsafe.Pointer(&_sqlite3Config))+6, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0) && nUri >= int32(5) && libc.Xmemcmp(tls, zUri, __ccgo_ts+26045, uint32(5)) == 0 { /* Input character index */
		iOut = 0                        /* Output character index */
		nByte = uint64(nUri + int32(8)) /* Bytes of space to allocate */
		/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
		 ** method that there may be extra parameters following the file-name.  */
		flags |= uint32(SQLITE_OPEN_URI)
		iIn = 0
		for {
			if !(iIn < nUri) {
				break
			}
			nByte += libc.BoolUint64(int32(*(*int8)(unsafe.Pointer(zUri + uintptr(iIn)))) == libc.Int32FromUint8('&'))
			goto _1
		_1:
			;
			iIn++
		}
		zFile = Xsqlite3_malloc64(tls, nByte)
		if !(zFile != 0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, zFile, 0, uint32(4)) /* 4-byte of 0x00 is the start of DB name marker */
		zFile += uintptr(4)
		iIn = int32(5)
		/* Discard the scheme and authority segments of the URI. */
		if int32(*(*int8)(unsafe.Pointer(zUri + 5))) == int32('/') && int32(*(*int8)(unsafe.Pointer(zUri + 6))) == int32('/') {
			iIn = int32(7)
			for *(*int8)(unsafe.Pointer(zUri + uintptr(iIn))) != 0 && int32(*(*int8)(unsafe.Pointer(zUri + uintptr(iIn)))) != int32('/') {
				iIn++
			}
			if iIn != int32(7) && (iIn != int32(16) || libc.Xmemcmp(tls, __ccgo_ts+26051, zUri+7, uint32(9)) != 0) {
				*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26061, libc.VaList(bp+8, iIn-int32(7), zUri+7))
				rc = int32(SQLITE_ERROR)
				goto parse_uri_out
			}
		}
		/* Copy the filename and any query parameters into the zFile buffer.
		 ** Decode %HH escape codes along the way.
		 **
		 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
		 ** on the parsing context. As follows:
		 **
		 **   0: Parsing file-name.
		 **   1: Parsing name section of a name=value query parameter.
		 **   2: Parsing value section of a name=value query parameter.
		 */
		eState = 0
		for {
			v2 = *(*int8)(unsafe.Pointer(zUri + uintptr(iIn)))
			c = v2
			if !(int32(v2) != 0 && int32(int32(c)) != int32('#')) {
				break
			}
			iIn++
			if int32(int32(c)) == int32('%') && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zUri + uintptr(iIn))))])&int32(0x08) != 0 && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zUri + uintptr(iIn+int32(1)))))])&int32(0x08) != 0 {
				v3 = iIn
				iIn++
				octet = int32(_sqlite3HexToInt(tls, int32(*(*int8)(unsafe.Pointer(zUri + uintptr(v3)))))) << int32(4)
				v4 = iIn
				iIn++
				octet += int32(_sqlite3HexToInt(tls, int32(*(*int8)(unsafe.Pointer(zUri + uintptr(v4))))))
				if octet == 0 {
					/* This branch is taken when "%00" appears within the URI. In this
					 ** case we ignore all text in the remainder of the path, name or
					 ** value currently being parsed. So ignore the current character
					 ** and skip to the next "?", "=" or "&", as appropriate. */
					for {
						v5 = *(*int8)(unsafe.Pointer(zUri + uintptr(iIn)))
						c = v5
						if !(int32(v5) != 0 && int32(int32(c)) != int32('#') && (eState != 0 || int32(int32(c)) != int32('?')) && (eState != int32(1) || int32(int32(c)) != int32('=') && int32(int32(c)) != int32('&')) && (eState != int32(2) || int32(int32(c)) != int32('&'))) {
							break
						}
						iIn++
					}
					continue
				}
				c = int8(int8(octet))
			} else {
				if eState == int32(1) && (int32(int32(c)) == int32('&') || int32(int32(c)) == int32('=')) {
					if int32(*(*int8)(unsafe.Pointer(zFile + uintptr(iOut-int32(1))))) == 0 {
						/* An empty option name. Ignore this option altogether. */
						for *(*int8)(unsafe.Pointer(zUri + uintptr(iIn))) != 0 && int32(*(*int8)(unsafe.Pointer(zUri + uintptr(iIn)))) != int32('#') && int32(*(*int8)(unsafe.Pointer(zUri + uintptr(iIn-int32(1))))) != int32('&') {
							iIn++
						}
						continue
					}
					if int32(int32(c)) == int32('&') {
						v6 = iOut
						iOut++
						*(*int8)(unsafe.Pointer(zFile + uintptr(v6))) = int8('\000')
					} else {
						eState = int32(2)
					}
					c = 0
				} else {
					if eState == 0 && int32(int32(c)) == int32('?') || eState == int32(2) && int32(int32(c)) == int32('&') {
						c = 0
						eState = int32(1)
					}
				}
			}
			v7 = iOut
			iOut++
			*(*int8)(unsafe.Pointer(zFile + uintptr(v7))) = c
		}
		if eState == int32(1) {
			v8 = iOut
			iOut++
			*(*int8)(unsafe.Pointer(zFile + uintptr(v8))) = int8('\000')
		}
		libc.Xmemset(tls, zFile+uintptr(iOut), 0, uint32(4)) /* end-of-options + empty journal filenames */
		/* Check if there were any options specified that should be interpreted
		 ** here. Options that are interpreted here include "vfs" and those that
		 ** correspond to flags that may be passed to the sqlite3_open_v2()
		 ** method. */
		zOpt = zFile + uintptr(_sqlite3Strlen30(tls, zFile)+int32(1))
		for *(*int8)(unsafe.Pointer(zOpt)) != 0 {
			nOpt = _sqlite3Strlen30(tls, zOpt)
			zVal = zOpt + uintptr(nOpt+int32(1))
			nVal = _sqlite3Strlen30(tls, zVal)
			if nOpt == int32(3) && libc.Xmemcmp(tls, __ccgo_ts+26089, zOpt, uint32(3)) == 0 {
				zVfs = zVal
			} else {
				aMode = uintptr(0)
				zModeType = uintptr(0)
				mask = 0
				limit = 0
				if nOpt == int32(5) && libc.Xmemcmp(tls, __ccgo_ts+26093, zOpt, uint32(5)) == 0 {
					mask = libc.Int32FromInt32(SQLITE_OPEN_SHAREDCACHE) | libc.Int32FromInt32(SQLITE_OPEN_PRIVATECACHE)
					aMode = uintptr(unsafe.Pointer(&_aCacheMode))
					limit = mask
					zModeType = __ccgo_ts + 26093
				}
				if nOpt == int32(4) && libc.Xmemcmp(tls, __ccgo_ts+26114, zOpt, uint32(4)) == 0 {
					mask = libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_MEMORY)
					aMode = uintptr(unsafe.Pointer(&_aOpenMode))
					limit = int32(uint32(uint32(mask)) & flags)
					zModeType = __ccgo_ts + 26129
				}
				if aMode != 0 {
					mode = 0
					i = 0
					for {
						if !((*(*struct {
							Fz    uintptr
							Fmode int32
						})(unsafe.Pointer(aMode + uintptr(i)*8))).Fz != 0) {
							break
						}
						z = (*(*struct {
							Fz    uintptr
							Fmode int32
						})(unsafe.Pointer(aMode + uintptr(i)*8))).Fz
						if nVal == _sqlite3Strlen30(tls, z) && 0 == libc.Xmemcmp(tls, zVal, z, uint32(uint32(nVal))) {
							mode = (*(*struct {
								Fz    uintptr
								Fmode int32
							})(unsafe.Pointer(aMode + uintptr(i)*8))).Fmode
							break
						}
						goto _9
					_9:
						;
						i++
					}
					if mode == 0 {
						*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26136, libc.VaList(bp+8, zModeType, zVal))
						rc = int32(SQLITE_ERROR)
						goto parse_uri_out
					}
					if mode & ^libc.Int32FromInt32(SQLITE_OPEN_MEMORY) > limit {
						*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26156, libc.VaList(bp+8, zModeType, zVal))
						rc = int32(SQLITE_PERM)
						goto parse_uri_out
					}
					flags = flags&uint32(^mask) | uint32(uint32(mode))
				}
			}
			zOpt = zVal + uintptr(nVal+int32(1))
		}
	} else {
		zFile = Xsqlite3_malloc64(tls, uint64(nUri+int32(8)))
		if !(zFile != 0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, zFile, 0, uint32(4))
		zFile += uintptr(4)
		if nUri != 0 {
			libc.Xmemcpy(tls, zFile, zUri, uint32(uint32(nUri)))
		}
		libc.Xmemset(tls, zFile+uintptr(nUri), 0, uint32(4))
		flags &= uint32(^libc.Int32FromInt32(SQLITE_OPEN_URI))
	}
	*(*uintptr)(unsafe.Pointer(ppVfs)) = Xsqlite3_vfs_find(tls, zVfs)
	if *(*uintptr)(unsafe.Pointer(ppVfs)) == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26180, libc.VaList(bp+8, zVfs))
		rc = int32(SQLITE_ERROR)
	}
	goto parse_uri_out
parse_uri_out:
	;
	if rc != SQLITE_OK {
		Xsqlite3_free_filename(tls, zFile)
		zFile = uintptr(0)
	}
	*(*uint32)(unsafe.Pointer(pFlags)) = flags
	*(*uintptr)(unsafe.Pointer(pzFile)) = zFile
	return rc
}

var _aCacheMode = [3]struct {
	Fz    uintptr
	Fmode int32
}{
	0: {
		Fz:    __ccgo_ts + 26099,
		Fmode: int32(SQLITE_OPEN_SHAREDCACHE),
	},
	1: {
		Fz:    __ccgo_ts + 26106,
		Fmode: int32(SQLITE_OPEN_PRIVATECACHE),
	},
	2: {},
}

var _aOpenMode = [5]struct {
	Fz    uintptr
	Fmode int32
}{
	0: {
		Fz:    __ccgo_ts + 26119,
		Fmode: int32(SQLITE_OPEN_READONLY),
	},
	1: {
		Fz:    __ccgo_ts + 26122,
		Fmode: int32(SQLITE_OPEN_READWRITE),
	},
	2: {
		Fz:    __ccgo_ts + 26125,
		Fmode: libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE),
	},
	3: {
		Fz:    __ccgo_ts + 19177,
		Fmode: int32(SQLITE_OPEN_MEMORY),
	},
	4: {},
}

// C documentation
//
//	/*
//	** This routine does the core work of extracting URI parameters from a
//	** database filename for the sqlite3_uri_parameter() interface.
//	*/
func _uriParameter(tls *libc.TLS, zFilename uintptr, zParam uintptr) (r uintptr) {
	var x int32
	_ = x
	zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
	for zFilename != uintptr(0) && *(*int8)(unsafe.Pointer(zFilename)) != 0 {
		x = libc.Xstrcmp(tls, zFilename, zParam)
		zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
		if x == 0 {
			return zFilename
		}
		zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** This routine does the work of opening a database on behalf of
//	** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
//	** is UTF-8 encoded.
//	*/
func _openDatabase(tls *libc.TLS, zFilename uintptr, ppDb uintptr, _flags uint32, zVfs uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	*(*uint32)(unsafe.Pointer(bp)) = _flags
	var db, v2 uintptr
	var i, isThreadsafe, rc int32
	var v1 uint32
	var _ /* zErrMsg at bp+8 */ uintptr
	var _ /* zOpen at bp+4 */ uintptr
	_, _, _, _, _, _ = db, i, isThreadsafe, rc, v1, v2 /* True for threadsafe connections */
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)   /* Filename argument to pass to BtreeOpen() */
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)   /* Loop counter */
	*(*uintptr)(unsafe.Pointer(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	if int32(_sqlite3Config.FbCoreMutex) == 0 {
		isThreadsafe = 0
	} else {
		if *(*uint32)(unsafe.Pointer(bp))&uint32(SQLITE_OPEN_NOMUTEX) != 0 {
			isThreadsafe = 0
		} else {
			if *(*uint32)(unsafe.Pointer(bp))&uint32(SQLITE_OPEN_FULLMUTEX) != 0 {
				isThreadsafe = int32(1)
			} else {
				isThreadsafe = int32(_sqlite3Config.FbFullMutex)
			}
		}
	}
	if *(*uint32)(unsafe.Pointer(bp))&uint32(SQLITE_OPEN_PRIVATECACHE) != 0 {
		*(*uint32)(unsafe.Pointer(bp)) &= uint32(^libc.Int32FromInt32(SQLITE_OPEN_SHAREDCACHE))
	} else {
		if _sqlite3Config.FsharedCacheEnabled != 0 {
			*(*uint32)(unsafe.Pointer(bp)) |= uint32(SQLITE_OPEN_SHAREDCACHE)
		}
	}
	/* Remove harmful bits from the flags parameter
	 **
	 ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
	 ** dealt with in the previous code block.  Besides these, the only
	 ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
	 ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
	 ** SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_EXRESCODE, and some reserved
	 ** bits.  Silently mask off all other flags.
	 */
	*(*uint32)(unsafe.Pointer(bp)) &= uint32(^(libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_DB) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_DB) | libc.Int32FromInt32(SQLITE_OPEN_TRANSIENT_DB) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_SUBJOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_SUPER_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_NOMUTEX) | libc.Int32FromInt32(SQLITE_OPEN_FULLMUTEX) | libc.Int32FromInt32(SQLITE_OPEN_WAL)))
	/* Allocate the sqlite data structure */
	db = _sqlite3MallocZero(tls, uint64(576))
	if db == uintptr(0) {
		goto opendb_out
	}
	if isThreadsafe != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_RECURSIVE))
		if (*Tsqlite3)(unsafe.Pointer(db)).Fmutex == uintptr(0) {
			Xsqlite3_free(tls, db)
			db = uintptr(0)
			goto opendb_out
		}
		if isThreadsafe == 0 {
		}
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if *(*uint32)(unsafe.Pointer(bp))&uint32(SQLITE_OPEN_EXRESCODE) != uint32(0) {
		v1 = uint32(0xffffffff)
	} else {
		v1 = uint32(0xff)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FerrMask = int32(v1)
	(*Tsqlite3)(unsafe.Pointer(db)).FnDb = int32(2)
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_BUSY)
	(*Tsqlite3)(unsafe.Pointer(db)).FaDb = db + 476
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = uint32(1)
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
	libc.Xmemcpy(tls, db+120, uintptr(unsafe.Pointer(&_aHardLimit)), uint32(48))
	*(*int32)(unsafe.Pointer(db + 120 + 11*4)) = SQLITE_DEFAULT_WORKER_THREADS
	(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
	(*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac = int8(-int32(1))
	(*Tsqlite3)(unsafe.Pointer(db)).FszMmap = _sqlite3Config.FszMmap
	(*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize = 0
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = uintptr(unsafe.Pointer(&_sqlite3StdType)) /* Any array of string ptrs will do */
	*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(uint32(libc.Int32FromInt32(SQLITE_ShortColNames)|libc.Int32FromInt32(SQLITE_EnableTrigger)) | libc.Uint32FromUint32(SQLITE_EnableView) | libc.Uint32FromInt32(SQLITE_CacheSpill) | libc.Uint32FromInt32(SQLITE_TrustedSchema) | libc.Uint32FromInt32(SQLITE_DqsDML) | libc.Uint32FromInt32(SQLITE_DqsDDL) | libc.Uint32FromInt32(SQLITE_AutoIndex))
	_sqlite3HashInit(tls, db+448)
	_sqlite3HashInit(tls, db+404)
	/* Add the default collation sequence BINARY. BINARY works for both UTF-8
	 ** and UTF-16, so add a version for each to avoid any unnecessary
	 ** conversions. The only error that can occur here is a malloc() failure.
	 **
	 ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
	 ** functions:
	 */
	_createCollation(tls, db, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), uint8(SQLITE_UTF8), uintptr(0), __ccgo_fp(_binCollFunc), uintptr(0))
	_createCollation(tls, db, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), uint8(SQLITE_UTF16BE), uintptr(0), __ccgo_fp(_binCollFunc), uintptr(0))
	_createCollation(tls, db, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), uint8(SQLITE_UTF16LE), uintptr(0), __ccgo_fp(_binCollFunc), uintptr(0))
	_createCollation(tls, db, __ccgo_ts+23822, uint8(SQLITE_UTF8), uintptr(0), __ccgo_fp(_nocaseCollatingFunc), uintptr(0))
	_createCollation(tls, db, __ccgo_ts+26196, uint8(SQLITE_UTF8), uintptr(0), __ccgo_fp(_rtrimCollFunc), uintptr(0))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto opendb_out
	}
	/* Parse the filename/URI argument
	 **
	 ** Only allow sensible combinations of bits in the flags argument.
	 ** Throw an error if any non-sense combination is used.  If we
	 ** do not block illegal combinations here, it could trigger
	 ** assert() statements in deeper layers.  Sensible combinations
	 ** are:
	 **
	 **  1:  SQLITE_OPEN_READONLY
	 **  2:  SQLITE_OPEN_READWRITE
	 **  6:  SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
	 */
	(*Tsqlite3)(unsafe.Pointer(db)).FopenFlags = *(*uint32)(unsafe.Pointer(bp))
	/* READONLY */
	/* READWRITE */
	/* READWRITE | CREATE */
	if int32(1)<<(*(*uint32)(unsafe.Pointer(bp))&uint32(7))&int32(0x46) == 0 {
		rc = _sqlite3MisuseError(tls, int32(183248)) /* IMP: R-18321-05872 */
	} else {
		rc = _sqlite3ParseUri(tls, zVfs, zFilename, bp, db, bp+4, bp+8)
	}
	if rc != SQLITE_OK {
		if rc == int32(SQLITE_NOMEM) {
			_sqlite3OomFault(tls, db)
		}
		if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
			v2 = __ccgo_ts + 4709
		} else {
			v2 = uintptr(0)
		}
		_sqlite3ErrorWithMsg(tls, db, rc, v2, libc.VaList(bp+24, *(*uintptr)(unsafe.Pointer(bp + 8))))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		goto opendb_out
	}
	/* Open the backend database driver */
	rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, *(*uintptr)(unsafe.Pointer(bp + 4)), db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb+4, 0, int32(*(*uint32)(unsafe.Pointer(bp))|uint32(SQLITE_OPEN_MAIN_DB)))
	if rc != SQLITE_OK {
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			rc = int32(SQLITE_NOMEM)
		}
		_sqlite3Error(tls, db, rc)
		goto opendb_out
	}
	_sqlite3BtreeEnter(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
	(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema = _sqlite3SchemaGet(tls, db, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
	if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		_sqlite3SetTextEncoding(tls, db, (*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fenc)
	}
	_sqlite3BtreeLeave(tls, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
	(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema = _sqlite3SchemaGet(tls, db, uintptr(0))
	/* The default safety_level for the main database is FULL; for the temp
	 ** database it is OFF. This matches the pager layer defaults.
	 */
	(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName = __ccgo_ts + 7958
	(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).Fsafety_level = uint8(libc.Int32FromInt32(SQLITE_DEFAULT_SYNCHRONOUS) + libc.Int32FromInt32(1))
	(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FzDbSName = __ccgo_ts + 25191
	(*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).Fsafety_level = uint8(PAGER_SYNCHRONOUS_OFF)
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_OPEN)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto opendb_out
	}
	/* Register all built-in functions, but do not attempt to read the
	 ** database schema yet. This is delayed until the first time the database
	 ** is accessed.
	 */
	_sqlite3Error(tls, db, SQLITE_OK)
	_sqlite3RegisterPerConnectionBuiltinFunctions(tls, db)
	rc = Xsqlite3_errcode(tls, db)
	/* Load compiled-in extensions */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < int32(libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4))) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3BuiltinExtensions[i]})))(tls, db)
		goto _3
	_3:
		;
		i++
	}
	/* Load automatic extensions - extensions that have been registered
	 ** using the sqlite3_automatic_extension() API.
	 */
	if rc == SQLITE_OK {
		_sqlite3AutoLoadExtensions(tls, db)
		rc = Xsqlite3_errcode(tls, db)
		if rc != SQLITE_OK {
			goto opendb_out
		}
	}
	/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
	 ** mode.  -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
	 ** mode.  Doing nothing at all also makes NORMAL the default.
	 */
	if rc != 0 {
		_sqlite3Error(tls, db, rc)
	}
	/* Enable the lookaside-malloc subsystem */
	_setupLookaside(tls, db, uintptr(0), _sqlite3Config.FszLookaside, _sqlite3Config.FnLookaside)
	Xsqlite3_wal_autocheckpoint(tls, db, int32(SQLITE_DEFAULT_WAL_AUTOCHECKPOINT))
	goto opendb_out
opendb_out:
	;
	if db != 0 {
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	}
	rc = Xsqlite3_errcode(tls, db)
	if rc&int32(0xff) == int32(SQLITE_NOMEM) {
		Xsqlite3_close(tls, db)
		db = uintptr(0)
	} else {
		if rc != SQLITE_OK {
			(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_SICK)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppDb)) = db
	Xsqlite3_free_filename(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	return rc
}

// C documentation
//
//	/*
//	** Open a new database handle.
//	*/
func Xsqlite3_open(tls *libc.TLS, zFilename uintptr, ppDb uintptr) (r int32) {
	return _openDatabase(tls, zFilename, ppDb, uint32(libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)), uintptr(0))
}

func Xsqlite3_open_v2(tls *libc.TLS, filename uintptr, ppDb uintptr, flags int32, zVfs uintptr) (r int32) {
	return _openDatabase(tls, filename, ppDb, uint32(uint32(flags)), zVfs)
}

// 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)(unsafe.Pointer(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	if zFilename == uintptr(0) {
		zFilename = __ccgo_ts + 26202
	}
	pVal = _sqlite3ValueNew(tls, uintptr(0))
	_sqlite3ValueSetStr(tls, pVal, -int32(1), zFilename, uint8(SQLITE_UTF16LE), libc.UintptrFromInt32(0))
	zFilename8 = _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zFilename8 != 0 {
		rc = _openDatabase(tls, zFilename8, ppDb, uint32(libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)), uintptr(0))
		if rc == SQLITE_OK && !(int32((*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppDb)))).FaDb))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_SchemaLoaded) == libc.Int32FromInt32(DB_SchemaLoaded)) {
			v1 = libc.Uint8FromInt32(SQLITE_UTF16LE)
			(*Tsqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppDb)))).Fenc = v1
			(*TSchema)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppDb)))).FaDb))).FpSchema)).Fenc = v1
		}
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	_sqlite3ValueFree(tls, pVal)
	return rc & int32(0xff)
}

// C documentation
//
//	/*
//	** Register a new collation sequence with the database handle db.
//	*/
func Xsqlite3_create_collation(tls *libc.TLS, db uintptr, zName uintptr, enc int32, pCtx uintptr, xCompare uintptr) (r int32) {
	return Xsqlite3_create_collation_v2(tls, db, zName, enc, pCtx, xCompare, uintptr(0))
}

// C documentation
//
//	/*
//	** Register a new collation sequence with the database handle db.
//	*/
func Xsqlite3_create_collation_v2(tls *libc.TLS, db uintptr, zName uintptr, enc int32, pCtx uintptr, xCompare uintptr, xDel uintptr) (r int32) {
	var rc int32
	_ = rc
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	rc = _createCollation(tls, db, zName, uint8(uint8(enc)), pCtx, xCompare, xDel)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// 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, 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_UTF16LE))
	if zName8 != 0 {
		rc = _createCollation(tls, db, zName8, uint8(uint8(enc)), pCtx, xCompare, uintptr(0))
		_sqlite3DbFree(tls, db, zName8)
	}
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Register a collation sequence factory callback with the database handle
//	** db. Replace any previously installed collation sequence factory.
//	*/
func Xsqlite3_collation_needed(tls *libc.TLS, db uintptr, pCollNeededArg uintptr, xCollNeeded uintptr) (r int32) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded = xCollNeeded
	(*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded16 = uintptr(0)
	(*Tsqlite3)(unsafe.Pointer(db)).FpCollNeededArg = pCollNeededArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Register a collation sequence factory callback with the database handle
//	** db. Replace any previously installed collation sequence factory.
//	*/
func Xsqlite3_collation_needed16(tls *libc.TLS, db uintptr, pCollNeededArg uintptr, xCollNeeded16 uintptr) (r int32) {
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded = uintptr(0)
	(*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded16 = xCollNeeded16
	(*Tsqlite3)(unsafe.Pointer(db)).FpCollNeededArg = pCollNeededArg
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Find existing client data.
//	*/
func Xsqlite3_get_clientdata(tls *libc.TLS, db uintptr, zName uintptr) (r uintptr) {
	var p, pResult uintptr
	_, _ = p, pResult
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
	for {
		if !(p != 0) {
			break
		}
		if libc.Xstrcmp(tls, p+12, zName) == 0 {
			pResult = (*TDbClientData)(unsafe.Pointer(p)).FpData
			Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
			return pResult
		}
		goto _1
	_1:
		;
		p = (*TDbClientData)(unsafe.Pointer(p)).FpNext
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Add new client data to a database connection.
//	*/
func Xsqlite3_set_clientdata(tls *libc.TLS, db uintptr, zName uintptr, pData uintptr, xDestructor uintptr) (r int32) {
	var n Tsize_t
	var p, pp uintptr
	_, _, _ = n, p, pp
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pp = db + 548
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
	for {
		if !(p != 0 && libc.Xstrcmp(tls, p+12, zName) != 0) {
			break
		}
		pp = p
		goto _1
	_1:
		;
		p = (*TDbClientData)(unsafe.Pointer(p)).FpNext
	}
	if p != 0 {
		if (*TDbClientData)(unsafe.Pointer(p)).FxDestructor != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TDbClientData)(unsafe.Pointer(p)).FxDestructor})))(tls, (*TDbClientData)(unsafe.Pointer(p)).FpData)
		}
		if pData == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(pp)) = (*TDbClientData)(unsafe.Pointer(p)).FpNext
			Xsqlite3_free(tls, p)
			Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
			return SQLITE_OK
		}
	} else {
		if pData == uintptr(0) {
			Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
			return SQLITE_OK
		} else {
			n = libc.Xstrlen(tls, zName)
			p = Xsqlite3_malloc64(tls, uint64(uint32(16)+n+uint32(1)))
			if p == uintptr(0) {
				if xDestructor != 0 {
					(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDestructor})))(tls, pData)
				}
				Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
				return int32(SQLITE_NOMEM)
			}
			libc.Xmemcpy(tls, p+12, zName, n+uint32(1))
			(*TDbClientData)(unsafe.Pointer(p)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
			(*Tsqlite3)(unsafe.Pointer(db)).FpDbData = p
		}
	}
	(*TDbClientData)(unsafe.Pointer(p)).FpData = pData
	(*TDbClientData)(unsafe.Pointer(p)).FxDestructor = xDestructor
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function is now an anachronism. It used to be used to recover from a
//	** malloc() failure, but SQLite now does this automatically.
//	*/
func Xsqlite3_global_recover(tls *libc.TLS) (r int32) {
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Test to see whether or not the database connection is in autocommit
//	** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
//	** by default.  Autocommit is disabled by a BEGIN statement and reenabled
//	** by the next COMMIT or ROLLBACK.
//	*/
func Xsqlite3_get_autocommit(tls *libc.TLS, db uintptr) (r int32) {
	return int32((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit)
}

// C documentation
//
//	/*
//	** The following routines are substitutes for constants SQLITE_CORRUPT,
//	** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error
//	** constants.  They serve two purposes:
//	**
//	**   1.  Serve as a convenient place to set a breakpoint in a debugger
//	**       to detect when version error conditions occurs.
//	**
//	**   2.  Invoke sqlite3_log() to provide the source code location where
//	**       a low-level error is first detected.
//	*/
func _sqlite3ReportError(tls *libc.TLS, iErr int32, lineno int32, zType uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	Xsqlite3_log(tls, iErr, __ccgo_ts+26205, libc.VaList(bp+8, zType, lineno, uintptr(20)+Xsqlite3_sourceid(tls)))
	return iErr
}

func _sqlite3CorruptError(tls *libc.TLS, lineno int32) (r int32) {
	return _sqlite3ReportError(tls, int32(SQLITE_CORRUPT), lineno, __ccgo_ts+26230)
}

func _sqlite3MisuseError(tls *libc.TLS, lineno int32) (r int32) {
	return _sqlite3ReportError(tls, int32(SQLITE_MISUSE), lineno, __ccgo_ts+26250)
}

func _sqlite3CantopenError(tls *libc.TLS, lineno int32) (r int32) {
	return _sqlite3ReportError(tls, int32(SQLITE_CANTOPEN), lineno, __ccgo_ts+26257)
}

// C documentation
//
//	/*
//	** This is a convenience routine that makes sure that all thread-specific
//	** data for this thread has been deallocated.
//	**
//	** SQLite no longer uses thread-specific data so this routine is now a
//	** no-op.  It is retained for historical compatibility.
//	*/
func Xsqlite3_thread_cleanup(tls *libc.TLS) {
}

// 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, v2, v3 uintptr
	var _ /* zErrMsg at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = autoinc, iCol, notnull, pCol, pTab, primarykey, rc, zCollSeq, zDataType, v2, v3
	*(*uintptr)(unsafe.Pointer(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) || int32((*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 = 0
		for {
			if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12
			if 0 == _sqlite3StrICmp(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, zColumnName) {
				break
			}
			goto _1
		_1:
			;
			iCol++
		}
		if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
			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 {
					v2 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12
				} else {
					v2 = uintptr(0)
				}
				pCol = v2
			} 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 + 4))&0xf>>0)) != 0)
		primarykey = libc.BoolInt32(int32((*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 + 1146
		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)(unsafe.Pointer(pzDataType)) = zDataType
	}
	if pzCollSeq != 0 {
		*(*uintptr)(unsafe.Pointer(pzCollSeq)) = zCollSeq
	}
	if pNotNull != 0 {
		*(*int32)(unsafe.Pointer(pNotNull)) = notnull
	}
	if pPrimaryKey != 0 {
		*(*int32)(unsafe.Pointer(pPrimaryKey)) = primarykey
	}
	if pAutoinc != 0 {
		*(*int32)(unsafe.Pointer(pAutoinc)) = autoinc
	}
	if SQLITE_OK == rc && !(pTab != 0) {
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
		*(*uintptr)(unsafe.Pointer(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+26274, libc.VaList(bp+16, zTableName, zColumnName))
		rc = int32(SQLITE_ERROR)
	}
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		v3 = __ccgo_ts + 4709
	} else {
		v3 = uintptr(0)
	}
	_sqlite3ErrorWithMsg(tls, db, rc, v3, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp))))
	_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Sleep for a little while.  Return the amount of time slept.
//	*/
func Xsqlite3_sleep(tls *libc.TLS, ms int32) (r int32) {
	var pVfs uintptr
	var rc, v1 int32
	_, _, _ = pVfs, rc, v1
	pVfs = Xsqlite3_vfs_find(tls, uintptr(0))
	if pVfs == uintptr(0) {
		return 0
	}
	/* This function works in milliseconds, but the underlying OsSleep()
	 ** API uses microseconds. Hence the 1000's.
	 */
	if ms < 0 {
		v1 = 0
	} else {
		v1 = int32(1000) * ms
	}
	rc = _sqlite3OsSleep(tls, pVfs, v1) / int32(1000)
	return rc
}

// C documentation
//
//	/*
//	** Enable or disable the extended result codes.
//	*/
func Xsqlite3_extended_result_codes(tls *libc.TLS, db uintptr, onoff int32) (r int32) {
	var v1 uint32
	_ = v1
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if onoff != 0 {
		v1 = uint32(0xffffffff)
	} else {
		v1 = uint32(0xff)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FerrMask = int32(v1)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Invoke the xFileControl method on a particular database.
//	*/
func Xsqlite3_file_control(tls *libc.TLS, db uintptr, zDbName uintptr, op int32, pArg uintptr) (r int32) {
	var fd, pBtree, pPager uintptr
	var iNew, nSave, rc int32
	_, _, _, _, _, _ = fd, iNew, nSave, pBtree, pPager, rc
	rc = int32(SQLITE_ERROR)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pBtree = _sqlite3DbNameToBtree(tls, db, zDbName)
	if pBtree != 0 {
		_sqlite3BtreeEnter(tls, pBtree)
		pPager = _sqlite3BtreePager(tls, pBtree)
		fd = _sqlite3PagerFile(tls, pPager)
		if op == int32(SQLITE_FCNTL_FILE_POINTER) {
			*(*uintptr)(unsafe.Pointer(pArg)) = fd
			rc = SQLITE_OK
		} else {
			if op == int32(SQLITE_FCNTL_VFS_POINTER) {
				*(*uintptr)(unsafe.Pointer(pArg)) = _sqlite3PagerVfs(tls, pPager)
				rc = SQLITE_OK
			} else {
				if op == int32(SQLITE_FCNTL_JOURNAL_POINTER) {
					*(*uintptr)(unsafe.Pointer(pArg)) = _sqlite3PagerJrnlFile(tls, pPager)
					rc = SQLITE_OK
				} else {
					if op == int32(SQLITE_FCNTL_DATA_VERSION) {
						*(*uint32)(unsafe.Pointer(pArg)) = _sqlite3PagerDataVersion(tls, pPager)
						rc = SQLITE_OK
					} else {
						if op == int32(SQLITE_FCNTL_RESERVE_BYTES) {
							iNew = *(*int32)(unsafe.Pointer(pArg))
							*(*int32)(unsafe.Pointer(pArg)) = _sqlite3BtreeGetRequestedReserve(tls, pBtree)
							if iNew >= 0 && iNew <= int32(255) {
								_sqlite3BtreeSetPageSize(tls, pBtree, 0, iNew, 0)
							}
							rc = SQLITE_OK
						} else {
							if op == int32(SQLITE_FCNTL_RESET_CACHE) {
								_sqlite3BtreeClearCache(tls, pBtree)
								rc = SQLITE_OK
							} else {
								nSave = (*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy
								rc = _sqlite3OsFileControl(tls, fd, op, pArg)
								(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = nSave
							}
						}
					}
				}
			}
		}
		_sqlite3BtreeLeave(tls, pBtree)
	}
	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, pCtx, pI1, pI2, pU64, pn, ptr, xBenignBegin, xBenignEnd uintptr
	var ap Tva_list
	var b, b1, iDb, opTrace, rc, sz, x, x1, x2, y, v1, v3 int32
	var newVal uint32
	var rIn float64
	var rLogEst TLogEst
	var v2 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aProg, ap, b, b1, db, db1, db2, db3, db4, db5, db6, iDb, newVal, opTrace, pCtx, pI1, pI2, pU64, pn, ptr, rIn, rLogEst, rc, sz, x, x1, x2, xBenignBegin, xBenignEnd, y, v1, v2, v3
	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)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fschema_cookie
			y = v1
		}
		if v2 && v1 != 0 {
			x = y
		}
		_sqlite3Config.FiPrngSeed = uint32(uint32(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 clearn that setting.  If the SQLITE_FkNoAction setting is
		 ** abled, 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)(unsafe.Pointer(db1 + 32)) |= uint64(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32)
		} else {
			*(*Tu64)(unsafe.Pointer(db1 + 32)) &= ^(uint64(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 = int32(int32(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 {
			v3 = x2
		} else {
			v3 = 0
		}
		rc = v3
		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_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):
		db3 = libc.VaUintptr(&ap)
		*(*Tu32)(unsafe.Pointer(db3 + 24)) ^= 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 = uint8(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):
		db4 = libc.VaUintptr(&ap)
		(*Tsqlite3)(unsafe.Pointer(db4)).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))+208) == 0 {
			rc = int32(SQLITE_ERROR)
		}
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, 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.  "onOff" turns imposter mode on
		 ** or off.  "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):
		db5 = libc.VaUintptr(&ap)
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db5)).Fmutex)
		iDb = _sqlite3FindDbName(tls, db5, libc.VaUintptr(&ap))
		if iDb >= 0 {
			(*Tsqlite3)(unsafe.Pointer(db5)).Finit1.FiDb = uint8(uint8(iDb))
			(*Tsqlite3)(unsafe.Pointer(db5)).Finit1.Fbusy = uint8(libc.AssignBitFieldPtr8Uint32(db5+172+8, uint32(libc.VaInt32(&ap)), 1, 1, 0x2))
			(*Tsqlite3)(unsafe.Pointer(db5)).Finit1.FnewTnum = uint32(libc.VaInt32(&ap))
			if int32((*Tsqlite3)(unsafe.Pointer(db5)).Finit1.Fbusy) == 0 && (*Tsqlite3)(unsafe.Pointer(db5)).Finit1.FnewTnum > uint32(0) {
				_sqlite3ResetAllSchemasOfConnection(tls, db5)
			}
		}
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db5)).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):
		db6 = libc.VaUintptr(&ap)
		pn = libc.VaUintptr(&ap)
		*(*Tu64)(unsafe.Pointer(pn)) = uint64(0)
		_ = db6 /* 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)(unsafe.Pointer(ptr)) = _sqlite3TreeTrace
		case int32(1):
			_sqlite3TreeTrace = *(*Tu32)(unsafe.Pointer(ptr))
		case int32(2):
			*(*Tu32)(unsafe.Pointer(ptr)) = _sqlite3WhereTrace
		case int32(3):
			_sqlite3WhereTrace = *(*Tu32)(unsafe.Pointer(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)(unsafe.Pointer(pI1)) = int32(int32(rLogEst))
		*(*Tu64)(unsafe.Pointer(pU64)) = _sqlite3LogEstToInt(tls, rLogEst)
		*(*int32)(unsafe.Pointer(pI2)) = int32(_sqlite3LogEst(tls, *(*Tu64)(unsafe.Pointer(pU64))))
		break
		/* sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, int X);
		 **
		 **   X<0     Make no changes to the bUseLongDouble.  Just report value.
		 **   X==0    Disable bUseLongDouble
		 **   X==1    Enable bUseLongDouble
		 **   X>=2    Set bUseLongDouble to its default value for this platform
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_USELONGDOUBLE):
		b1 = libc.VaInt32(&ap)
		if b1 >= int32(2) {
			b1 = _hasHighPrecisionDouble(tls, b1)
		}
		if b1 >= 0 {
			_sqlite3Config.FbUseLongDouble = libc.BoolUint8(b1 > 0)
		}
		rc = libc.BoolInt32(int32(_sqlite3Config.FbUseLongDouble) != 0)
		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
//
//	/*
//	** The Pager stores the Database filename, Journal filename, and WAL filename
//	** consecutively in memory, in that order.  The database filename is prefixed
//	** by four zero bytes.  Locate the start of the database filename by searching
//	** backwards for the first byte following four consecutive zero bytes.
//	**
//	** This only works if the filename passed in was obtained from the Pager.
//	*/
func _databaseName(tls *libc.TLS, zName uintptr) (r uintptr) {
	for int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(1))))) != 0 || int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(2))))) != 0 || int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(3))))) != 0 || int32(*(*int8)(unsafe.Pointer(zName + uintptr(-libc.Int32FromInt32(4))))) != 0 {
		zName--
	}
	return zName
}

// C documentation
//
//	/*
//	** Append text z[] to the end of p[].  Return a pointer to the first
//	** character after then zero terminator on the new text in p[].
//	*/
func _appendText(tls *libc.TLS, p uintptr, z uintptr) (r uintptr) {
	var n Tsize_t
	_ = n
	n = libc.Xstrlen(tls, z)
	libc.Xmemcpy(tls, p, z, n+uint32(1))
	return p + uintptr(n) + uintptr(1)
}

// C documentation
//
//	/*
//	** Allocate memory to hold names for a database, journal file, WAL file,
//	** and query parameters.  The pointer returned is valid for use by
//	** sqlite3_filename_database() and sqlite3_uri_parameter() and related
//	** functions.
//	**
//	** Memory layout must be compatible with that generated by the pager
//	** and expected by sqlite3_uri_parameter() and databaseName().
//	*/
func Xsqlite3_create_filename(tls *libc.TLS, zDatabase uintptr, zJournal uintptr, zWal uintptr, nParam int32, azParam uintptr) (r uintptr) {
	var i int32
	var nByte Tsqlite3_int64
	var p, pResult, v2, v4, v5, v6 uintptr
	_, _, _, _, _, _, _, _ = i, nByte, p, pResult, v2, v4, v5, v6
	nByte = int64(libc.Xstrlen(tls, zDatabase) + libc.Xstrlen(tls, zJournal) + libc.Xstrlen(tls, zWal) + uint32(10))
	i = 0
	for {
		if !(i < nParam*int32(2)) {
			break
		}
		nByte += int64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(azParam + uintptr(i)*4))) + uint32(1))
		goto _1
	_1:
		;
		i++
	}
	v2 = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	p = v2
	pResult = v2
	if p == uintptr(0) {
		return uintptr(0)
	}
	libc.Xmemset(tls, p, 0, uint32(4))
	p += uintptr(4)
	p = _appendText(tls, p, zDatabase)
	i = 0
	for {
		if !(i < nParam*int32(2)) {
			break
		}
		p = _appendText(tls, p, *(*uintptr)(unsafe.Pointer(azParam + uintptr(i)*4)))
		goto _3
	_3:
		;
		i++
	}
	v4 = p
	p++
	*(*int8)(unsafe.Pointer(v4)) = 0
	p = _appendText(tls, p, zJournal)
	p = _appendText(tls, p, zWal)
	v5 = p
	p++
	*(*int8)(unsafe.Pointer(v5)) = 0
	v6 = p
	p++
	*(*int8)(unsafe.Pointer(v6)) = 0
	return pResult + uintptr(4)
}

// C documentation
//
//	/*
//	** Free memory obtained from sqlite3_create_filename().  It is a severe
//	** error to call this routine with any parameter other than a pointer
//	** previously obtained from sqlite3_create_filename() or a NULL pointer.
//	*/
func Xsqlite3_free_filename(tls *libc.TLS, p uintptr) {
	if p == uintptr(0) {
		return
	}
	p = _databaseName(tls, p)
	Xsqlite3_free(tls, p-uintptr(4))
}

// C documentation
//
//	/*
//	** This is a utility routine, useful to VFS implementations, that checks
//	** to see if a database file was a URI that contained a specific query
//	** parameter, and if so obtains the value of the query parameter.
//	**
//	** The zFilename argument is the filename pointer passed into the xOpen()
//	** method of a VFS implementation.  The zParam argument is the name of the
//	** query parameter we seek.  This routine returns the value of the zParam
//	** parameter if it exists.  If the parameter does not exist, this routine
//	** returns a NULL pointer.
//	*/
func Xsqlite3_uri_parameter(tls *libc.TLS, zFilename uintptr, zParam uintptr) (r uintptr) {
	if zFilename == uintptr(0) || zParam == uintptr(0) {
		return uintptr(0)
	}
	zFilename = _databaseName(tls, zFilename)
	return _uriParameter(tls, zFilename, zParam)
}

// C documentation
//
//	/*
//	** Return a pointer to the name of Nth query parameter of the filename.
//	*/
func Xsqlite3_uri_key(tls *libc.TLS, zFilename uintptr, N int32) (r uintptr) {
	var v1 int32
	var v2 bool
	var v3 uintptr
	_, _, _ = v1, v2, v3
	if zFilename == uintptr(0) || N < 0 {
		return uintptr(0)
	}
	zFilename = _databaseName(tls, zFilename)
	zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
	for {
		if v2 = zFilename != 0 && *(*int8)(unsafe.Pointer(zFilename)) != 0; v2 {
			v1 = N
			N--
		}
		if !(v2 && v1 > 0) {
			break
		}
		zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
		zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
	}
	if *(*int8)(unsafe.Pointer(zFilename)) != 0 {
		v3 = zFilename
	} else {
		v3 = uintptr(0)
	}
	return v3
}

// C documentation
//
//	/*
//	** Return a boolean value for a query parameter.
//	*/
func Xsqlite3_uri_boolean(tls *libc.TLS, zFilename uintptr, zParam uintptr, bDflt int32) (r int32) {
	var z uintptr
	var v1 int32
	_, _ = z, v1
	z = Xsqlite3_uri_parameter(tls, zFilename, zParam)
	bDflt = libc.BoolInt32(bDflt != 0)
	if z != 0 {
		v1 = int32(_sqlite3GetBoolean(tls, z, uint8(uint8(bDflt))))
	} else {
		v1 = bDflt
	}
	return v1
}

// C documentation
//
//	/*
//	** Return a 64-bit integer value for a query parameter.
//	*/
func Xsqlite3_uri_int64(tls *libc.TLS, zFilename uintptr, zParam uintptr, bDflt Tsqlite3_int64) (r Tsqlite3_int64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var z uintptr
	var _ /* v at bp+0 */ Tsqlite3_int64
	_ = z
	z = Xsqlite3_uri_parameter(tls, zFilename, zParam)
	if z != 0 && _sqlite3DecOrHexToI64(tls, z, bp) == 0 {
		bDflt = *(*Tsqlite3_int64)(unsafe.Pointer(bp))
	}
	return bDflt
}

// C documentation
//
//	/*
//	** Translate a filename that was handed to a VFS routine into the corresponding
//	** database, journal, or WAL file.
//	**
//	** It is an error to pass this routine a filename string that was not
//	** passed into the VFS from the SQLite core.  Doing so is similar to
//	** passing free() a pointer that was not obtained from malloc() - it is
//	** an error that we cannot easily detect but that will likely cause memory
//	** corruption.
//	*/
func Xsqlite3_filename_database(tls *libc.TLS, zFilename uintptr) (r uintptr) {
	if zFilename == uintptr(0) {
		return uintptr(0)
	}
	return _databaseName(tls, zFilename)
}

func Xsqlite3_filename_journal(tls *libc.TLS, zFilename uintptr) (r uintptr) {
	if zFilename == uintptr(0) {
		return uintptr(0)
	}
	zFilename = _databaseName(tls, zFilename)
	zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
	for zFilename != 0 && *(*int8)(unsafe.Pointer(zFilename)) != 0 {
		zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
		zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
	}
	return zFilename + uintptr(1)
}

func Xsqlite3_filename_wal(tls *libc.TLS, zFilename uintptr) (r uintptr) {
	zFilename = Xsqlite3_filename_journal(tls, zFilename)
	if zFilename != 0 {
		zFilename += uintptr(_sqlite3Strlen30(tls, zFilename) + int32(1))
	}
	return zFilename
}

// C documentation
//
//	/*
//	** Return the Btree pointer identified by zDbName.  Return NULL if not found.
//	*/
func _sqlite3DbNameToBtree(tls *libc.TLS, db uintptr, zDbName uintptr) (r uintptr) {
	var iDb, v1 int32
	var v2 uintptr
	_, _, _ = iDb, v1, v2
	if zDbName != 0 {
		v1 = _sqlite3FindDbName(tls, db, zDbName)
	} else {
		v1 = 0
	}
	iDb = v1
	if iDb < 0 {
		v2 = uintptr(0)
	} else {
		v2 = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
	}
	return v2
}

// C documentation
//
//	/*
//	** Return the name of the N-th database schema.  Return NULL if N is out
//	** of range.
//	*/
func Xsqlite3_db_name(tls *libc.TLS, db uintptr, N int32) (r uintptr) {
	if N < 0 || N >= (*Tsqlite3)(unsafe.Pointer(db)).FnDb {
		return uintptr(0)
	} else {
		return (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(N)*16))).FzDbSName
	}
	return r
}

// C documentation
//
//	/*
//	** Return the filename of the database associated with a database
//	** connection.
//	*/
func Xsqlite3_db_filename(tls *libc.TLS, db uintptr, zDbName uintptr) (r uintptr) {
	var pBt, v1 uintptr
	_, _ = pBt, v1
	pBt = _sqlite3DbNameToBtree(tls, db, zDbName)
	if pBt != 0 {
		v1 = _sqlite3BtreeGetFilename(tls, pBt)
	} else {
		v1 = uintptr(0)
	}
	return v1
}

// C documentation
//
//	/*
//	** Return 1 if database is read-only or 0 if read/write.  Return -1 if
//	** no such database exists.
//	*/
func Xsqlite3_db_readonly(tls *libc.TLS, db uintptr, zDbName uintptr) (r int32) {
	var pBt uintptr
	var v1 int32
	_, _ = pBt, v1
	pBt = _sqlite3DbNameToBtree(tls, db, zDbName)
	if pBt != 0 {
		v1 = _sqlite3BtreeIsReadonly(tls, pBt)
	} else {
		v1 = -int32(1)
	}
	return v1
}

// C documentation
//
//	/*
//	** Obtain a snapshot handle for the snapshot of database zDb currently
//	** being read by handle db.
//	*/
func Xsqlite3_snapshot_get(tls *libc.TLS, db uintptr, zDb uintptr, ppSnapshot uintptr) (r int32) {
	var iDb, rc int32
	var pBt uintptr
	_, _, _ = iDb, pBt, rc
	rc = int32(SQLITE_ERROR)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
		iDb = _sqlite3FindDbName(tls, db, zDb)
		if iDb == 0 || iDb > int32(1) {
			pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
			if int32(SQLITE_TXN_WRITE) != _sqlite3BtreeTxnState(tls, pBt) {
				rc = _sqlite3BtreeBeginTrans(tls, pBt, 0, uintptr(0))
				if rc == SQLITE_OK {
					rc = _sqlite3PagerSnapshotGet(tls, _sqlite3BtreePager(tls, pBt), ppSnapshot)
				}
			}
		}
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Open a read-transaction on the snapshot identified by pSnapshot.
//	*/
func Xsqlite3_snapshot_open(tls *libc.TLS, db uintptr, zDb uintptr, pSnapshot uintptr) (r int32) {
	var bUnlock, iDb, rc int32
	var pBt, pPager uintptr
	_, _, _, _, _ = bUnlock, iDb, pBt, pPager, rc
	rc = int32(SQLITE_ERROR)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if int32((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
		iDb = _sqlite3FindDbName(tls, db, zDb)
		if iDb == 0 || iDb > int32(1) {
			pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
			if _sqlite3BtreeTxnState(tls, pBt) != int32(SQLITE_TXN_WRITE) {
				pPager = _sqlite3BtreePager(tls, pBt)
				bUnlock = 0
				if _sqlite3BtreeTxnState(tls, pBt) != SQLITE_TXN_NONE {
					if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
						rc = _sqlite3PagerSnapshotCheck(tls, pPager, pSnapshot)
						if rc == SQLITE_OK {
							bUnlock = int32(1)
							rc = _sqlite3BtreeCommit(tls, pBt)
						}
					}
				} else {
					rc = SQLITE_OK
				}
				if rc == SQLITE_OK {
					rc = _sqlite3PagerSnapshotOpen(tls, pPager, pSnapshot)
				}
				if rc == SQLITE_OK {
					rc = _sqlite3BtreeBeginTrans(tls, pBt, 0, uintptr(0))
					_sqlite3PagerSnapshotOpen(tls, pPager, uintptr(0))
				}
				if bUnlock != 0 {
					_sqlite3PagerSnapshotUnlock(tls, pPager)
				}
			}
		}
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Recover as many snapshots as possible from the wal file associated with
//	** schema zDb of database db.
//	*/
func Xsqlite3_snapshot_recover(tls *libc.TLS, db uintptr, zDb uintptr) (r int32) {
	var iDb, rc int32
	var pBt uintptr
	_, _, _ = iDb, pBt, rc
	rc = int32(SQLITE_ERROR)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	iDb = _sqlite3FindDbName(tls, db, zDb)
	if iDb == 0 || iDb > int32(1) {
		pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
		if SQLITE_TXN_NONE == _sqlite3BtreeTxnState(tls, pBt) {
			rc = _sqlite3BtreeBeginTrans(tls, pBt, 0, uintptr(0))
			if rc == SQLITE_OK {
				rc = _sqlite3PagerSnapshotRecover(tls, _sqlite3BtreePager(tls, pBt))
				_sqlite3BtreeCommit(tls, pBt)
			}
		}
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Free a snapshot handle obtained from sqlite3_snapshot_get().
//	*/
func Xsqlite3_snapshot_free(tls *libc.TLS, pSnapshot uintptr) {
	Xsqlite3_free(tls, pSnapshot)
}

// C documentation
//
//	/*
//	** Given the name of a compile-time option, return true if that option
//	** was used and false if not.
//	**
//	** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
//	** is not required for a match.
//	*/
func Xsqlite3_compileoption_used(tls *libc.TLS, zOptName uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azCompileOpt uintptr
	var i, n int32
	var _ /* nOpt at bp+0 */ int32
	_, _, _ = azCompileOpt, i, n
	azCompileOpt = _sqlite3CompileOptions(tls, bp)
	if Xsqlite3_strnicmp(tls, zOptName, __ccgo_ts+26302, int32(7)) == 0 {
		zOptName += uintptr(7)
	}
	n = _sqlite3Strlen30(tls, zOptName)
	/* Since nOpt is normally in single digits, a linear search is
	 ** adequate. No need for a binary search. */
	i = 0
	for {
		if !(i < *(*int32)(unsafe.Pointer(bp))) {
			break
		}
		if Xsqlite3_strnicmp(tls, zOptName, *(*uintptr)(unsafe.Pointer(azCompileOpt + uintptr(i)*4)), n) == 0 && _sqlite3IsIdChar(tls, uint8(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(azCompileOpt + uintptr(i)*4)) + uintptr(n))))) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** Return the N-th compile-time option string.  If N is out of range,
//	** return a NULL pointer.
//	*/
func Xsqlite3_compileoption_get(tls *libc.TLS, N int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azCompileOpt uintptr
	var _ /* nOpt at bp+0 */ int32
	_ = azCompileOpt
	azCompileOpt = _sqlite3CompileOptions(tls, bp)
	if N >= 0 && N < *(*int32)(unsafe.Pointer(bp)) {
		return *(*uintptr)(unsafe.Pointer(azCompileOpt + uintptr(N)*4))
	}
	return uintptr(0)
}

/************** End of main.c ************************************************/
/************** Begin file notify.c ******************************************/
/*
** 2009 March 3
**
** 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 implementation of the sqlite3_unlock_notify()
** API method and its associated functionality.
 */
/* #include "sqliteInt.h" */
/* #include "btreeInt.h" */

/* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */

/*
** Public interfaces:
**
**   sqlite3ConnectionBlocked()
**   sqlite3ConnectionUnlocked()
**   sqlite3ConnectionClosed()
**   sqlite3_unlock_notify()
 */

// C documentation
//
//	/*
//	** Head of a linked list of all sqlite3 objects created by this process
//	** for which either sqlite3.pBlockingConnection or sqlite3.pUnlockConnection
//	** is not NULL. This variable may only accessed while the STATIC_MAIN
//	** mutex is held.
//	*/
var _sqlite3BlockedList = uintptr(0)

// C documentation
//
//	/*
//	** Remove connection db from the blocked connections list. If connection
//	** db is not currently a part of the list, this function is a no-op.
//	*/
func _removeFromBlockedList(tls *libc.TLS, db uintptr) {
	var pp uintptr
	_ = pp
	pp = uintptr(unsafe.Pointer(&_sqlite3BlockedList))
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != 0) {
			break
		}
		if *(*uintptr)(unsafe.Pointer(pp)) == db {
			*(*uintptr)(unsafe.Pointer(pp)) = (*Tsqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNextBlocked
			break
		}
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 568
	}
}

// C documentation
//
//	/*
//	** Add connection db to the blocked connections list. It is assumed
//	** that it is not already a part of the list.
//	*/
func _addToBlockedList(tls *libc.TLS, db uintptr) {
	var pp uintptr
	_ = pp
	pp = uintptr(unsafe.Pointer(&_sqlite3BlockedList))
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != 0 && (*Tsqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FxUnlockNotify != (*Tsqlite3)(unsafe.Pointer(db)).FxUnlockNotify) {
			break
		}
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 568
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FpNextBlocked = *(*uintptr)(unsafe.Pointer(pp))
	*(*uintptr)(unsafe.Pointer(pp)) = db
}

// C documentation
//
//	/*
//	** Obtain the STATIC_MAIN mutex.
//	*/
func _enterMutex(tls *libc.TLS) {
	Xsqlite3_mutex_enter(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN)))
}

// C documentation
//
//	/*
//	** Release the STATIC_MAIN mutex.
//	*/
func _leaveMutex(tls *libc.TLS) {
	Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN)))
}

// C documentation
//
//	/*
//	** Register an unlock-notify callback.
//	**
//	** This is called after connection "db" has attempted some operation
//	** but has received an SQLITE_LOCKED error because another connection
//	** (call it pOther) in the same process was busy using the same shared
//	** cache.  pOther is found by looking at db->pBlockingConnection.
//	**
//	** If there is no blocking connection, the callback is invoked immediately,
//	** before this routine returns.
//	**
//	** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
//	** a deadlock.
//	**
//	** Otherwise, make arrangements to invoke xNotify when pOther drops
//	** its locks.
//	**
//	** Each call to this routine overrides any prior callbacks registered
//	** on the same "db".  If xNotify==0 then any prior callbacks are immediately
//	** cancelled.
//	*/
func Xsqlite3_unlock_notify(tls *libc.TLS, db uintptr, xNotify uintptr, _pArg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _pArg
	var p, v2 uintptr
	var rc int32
	_, _, _ = p, rc, v2
	rc = SQLITE_OK
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_enterMutex(tls)
	if xNotify == uintptr(0) {
		_removeFromBlockedList(tls, db)
		(*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockConnection = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FxUnlockNotify = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockArg = uintptr(0)
	} else {
		if uintptr(0) == (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection {
			/* The blocking transaction has been concluded. Or there never was a
			 ** blocking transaction. In either case, invoke the notify callback
			 ** immediately.
			 */
			(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xNotify})))(tls, bp, int32(1))
		} else {
			p = (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection
			for {
				if !(p != 0 && p != db) {
					break
				}
				goto _1
			_1:
				;
				p = (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection
			}
			if p != 0 {
				rc = int32(SQLITE_LOCKED) /* Deadlock detected. */
			} else {
				(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockConnection = (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection
				(*Tsqlite3)(unsafe.Pointer(db)).FxUnlockNotify = xNotify
				(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockArg = *(*uintptr)(unsafe.Pointer(bp))
				_removeFromBlockedList(tls, db)
				_addToBlockedList(tls, db)
			}
		}
	}
	_leaveMutex(tls)
	if rc != 0 {
		v2 = __ccgo_ts + 26310
	} else {
		v2 = uintptr(0)
	}
	_sqlite3ErrorWithMsg(tls, db, rc, v2, 0)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** This function is called while stepping or preparing a statement
//	** associated with connection db. The operation will return SQLITE_LOCKED
//	** to the user because it requires a lock that will not be available
//	** until connection pBlocker concludes its current transaction.
//	*/
func _sqlite3ConnectionBlocked(tls *libc.TLS, db uintptr, pBlocker uintptr) {
	_enterMutex(tls)
	if (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(db)).FpUnlockConnection == uintptr(0) {
		_addToBlockedList(tls, db)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection = pBlocker
	_leaveMutex(tls)
}

// C documentation
//
//	/*
//	** This function is called when
//	** the transaction opened by database db has just finished. Locks held
//	** by database connection db have been released.
//	**
//	** This function loops through each entry in the blocked connections
//	** list and does the following:
//	**
//	**   1) If the sqlite3.pBlockingConnection member of a list entry is
//	**      set to db, then set pBlockingConnection=0.
//	**
//	**   2) If the sqlite3.pUnlockConnection member of a list entry is
//	**      set to db, then invoke the configured unlock-notify callback and
//	**      set pUnlockConnection=0.
//	**
//	**   3) If the two steps above mean that pBlockingConnection==0 and
//	**      pUnlockConnection==0, remove the entry from the blocked connections
//	**      list.
//	*/
func _sqlite3ConnectionUnlocked(tls *libc.TLS, db uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aArg, aDyn, p, pNew, pp, xUnlockNotify, v2 uintptr
	var nArg, v3 int32
	var _ /* aStatic at bp+0 */ [16]uintptr
	_, _, _, _, _, _, _, _, _ = aArg, aDyn, nArg, p, pNew, pp, xUnlockNotify, v2, v3
	xUnlockNotify = uintptr(0) /* Unlock-notify cb to invoke */
	nArg = 0                   /* Arguments to the unlock callback */
	aDyn = uintptr(0)          /* Starter space for aArg[].  No malloc required */
	aArg = bp
	_enterMutex(tls) /* Enter STATIC_MAIN mutex */
	/* This loop runs once for each entry in the blocked-connections list. */
	pp = uintptr(unsafe.Pointer(&_sqlite3BlockedList))
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != 0) {
			break
		}
		p = *(*uintptr)(unsafe.Pointer(pp))
		/* Step 1. */
		if (*Tsqlite3)(unsafe.Pointer(p)).FpBlockingConnection == db {
			(*Tsqlite3)(unsafe.Pointer(p)).FpBlockingConnection = uintptr(0)
		}
		/* Step 2. */
		if (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection == db {
			if (*Tsqlite3)(unsafe.Pointer(p)).FxUnlockNotify != xUnlockNotify && nArg != 0 {
				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})))(tls, aArg, nArg)
				nArg = 0
			}
			_sqlite3BeginBenignMalloc(tls)
			if !(aDyn != 0) && nArg == int32(libc.Uint32FromInt64(64)/libc.Uint32FromInt64(4)) || aDyn != 0 && nArg == int32(uint32(_sqlite3MallocSize(tls, aDyn))/libc.Uint32FromInt64(4)) {
				/* The aArg[] array needs to grow. */
				pNew = _sqlite3Malloc(tls, uint64(uint32(uint32(nArg))*uint32(4)*uint32(2)))
				if pNew != 0 {
					libc.Xmemcpy(tls, pNew, aArg, uint32(uint32(nArg))*uint32(4))
					Xsqlite3_free(tls, aDyn)
					v2 = pNew
					aArg = v2
					aDyn = v2
				} else {
					/* This occurs when the array of context pointers that need to
					 ** be passed to the unlock-notify callback is larger than the
					 ** aStatic[] array allocated on the stack and the attempt to
					 ** allocate a larger array from the heap has failed.
					 **
					 ** This is a difficult situation to handle. Returning an error
					 ** code to the caller is insufficient, as even if an error code
					 ** is returned the transaction on connection db will still be
					 ** closed and the unlock-notify callbacks on blocked connections
					 ** will go unissued. This might cause the application to wait
					 ** indefinitely for an unlock-notify callback that will never
					 ** arrive.
					 **
					 ** Instead, invoke the unlock-notify callback with the context
					 ** array already accumulated. We can then clear the array and
					 ** begin accumulating any further context pointers without
					 ** requiring any dynamic allocation. This is sub-optimal because
					 ** it means that instead of one callback with a large array of
					 ** context pointers the application will receive two or more
					 ** callbacks with smaller arrays of context pointers, which will
					 ** reduce the applications ability to prioritize multiple
					 ** connections. But it is the best that can be done under the
					 ** circumstances.
					 */
					(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})))(tls, aArg, nArg)
					nArg = 0
				}
			}
			_sqlite3EndBenignMalloc(tls)
			v3 = nArg
			nArg++
			*(*uintptr)(unsafe.Pointer(aArg + uintptr(v3)*4)) = (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockArg
			xUnlockNotify = (*Tsqlite3)(unsafe.Pointer(p)).FxUnlockNotify
			(*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection = uintptr(0)
			(*Tsqlite3)(unsafe.Pointer(p)).FxUnlockNotify = uintptr(0)
			(*Tsqlite3)(unsafe.Pointer(p)).FpUnlockArg = uintptr(0)
		}
		/* Step 3. */
		if (*Tsqlite3)(unsafe.Pointer(p)).FpBlockingConnection == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection == uintptr(0) {
			/* Remove connection p from the blocked connections list. */
			*(*uintptr)(unsafe.Pointer(pp)) = (*Tsqlite3)(unsafe.Pointer(p)).FpNextBlocked
			(*Tsqlite3)(unsafe.Pointer(p)).FpNextBlocked = uintptr(0)
		} else {
			pp = p + 568
		}
		goto _1
	_1:
	}
	if nArg != 0 {
		(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})))(tls, aArg, nArg)
	}
	Xsqlite3_free(tls, aDyn)
	_leaveMutex(tls) /* Leave STATIC_MAIN mutex */
}

// C documentation
//
//	/*
//	** This is called when the database connection passed as an argument is
//	** being closed. The connection is removed from the blocked list.
//	*/
func _sqlite3ConnectionClosed(tls *libc.TLS, db uintptr) {
	_sqlite3ConnectionUnlocked(tls, db)
	_enterMutex(tls)
	_removeFromBlockedList(tls, db)
	_leaveMutex(tls)
}

/************** End of notify.c **********************************************/
/************** Begin file fts3.c ********************************************/
/*
** 2006 Oct 10
**
** 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 is an SQLite module implementing full-text search.
 */

/*
** The code in this file is only compiled if:
**
**     * The FTS3 module is being built as an extension
**       (in which case SQLITE_CORE is not defined), or
**
**     * The FTS3 module is being built into the core of
**       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
 */

/* The full-text index is stored in a series of b+tree (-like)
** structures called segments which map terms to doclists.  The
** structures are like b+trees in layout, but are constructed from the
** bottom up in optimal fashion and are not updatable.  Since trees
** are built from the bottom up, things will be described from the
** bottom up.
**
**
**** Varints ****
** The basic unit of encoding is a variable-length integer called a
** varint.  We encode variable-length integers in little-endian order
** using seven bits * per byte as follows:
**
** KEY:
**         A = 0xxxxxxx    7 bits of data and one flag bit
**         B = 1xxxxxxx    7 bits of data and one flag bit
**
**  7 bits - A
** 14 bits - BA
** 21 bits - BBA
** and so on.
**
** This is similar in concept to how sqlite encodes "varints" but
** the encoding is not the same.  SQLite varints are big-endian
** are are limited to 9 bytes in length whereas FTS3 varints are
** little-endian and can be up to 10 bytes in length (in theory).
**
** Example encodings:
**
**     1:    0x01
**   127:    0x7f
**   128:    0x81 0x00
**
**
**** Document lists ****
** A doclist (document list) holds a docid-sorted list of hits for a
** given term.  Doclists hold docids and associated token positions.
** A docid is the unique integer identifier for a single document.
** A position is the index of a word within the document.  The first
** word of the document has a position of 0.
**
** FTS3 used to optionally store character offsets using a compile-time
** option.  But that functionality is no longer supported.
**
** A doclist is stored like this:
**
** array {
**   varint docid;          (delta from previous doclist)
**   array {                (position list for column 0)
**     varint position;     (2 more than the delta from previous position)
**   }
**   array {
**     varint POS_COLUMN;   (marks start of position list for new column)
**     varint column;       (index of new column)
**     array {
**       varint position;   (2 more than the delta from previous position)
**     }
**   }
**   varint POS_END;        (marks end of positions for this document.
** }
**
** Here, array { X } means zero or more occurrences of X, adjacent in
** memory.  A "position" is an index of a token in the token stream
** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
** in the same logical place as the position element, and act as sentinals
** ending a position list array.  POS_END is 0.  POS_COLUMN is 1.
** The positions numbers are not stored literally but rather as two more
** than the difference from the prior position, or the just the position plus
** 2 for the first position.  Example:
**
**   label:       A B C D E  F  G H   I  J K
**   value:     123 5 9 1 1 14 35 0 234 72 0
**
** The 123 value is the first docid.  For column zero in this document
** there are two matches at positions 3 and 10 (5-2 and 9-2+3).  The 1
** at D signals the start of a new column; the 1 at E indicates that the
** new column is column number 1.  There are two positions at 12 and 45
** (14-2 and 35-2+12).  The 0 at H indicate the end-of-document.  The
** 234 at I is the delta to next docid (357).  It has one position 70
** (72-2) and then terminates with the 0 at K.
**
** A "position-list" is the list of positions for multiple columns for
** a single docid.  A "column-list" is the set of positions for a single
** column.  Hence, a position-list consists of one or more column-lists,
** a document record consists of a docid followed by a position-list and
** a doclist consists of one or more document records.
**
** A bare doclist omits the position information, becoming an
** array of varint-encoded docids.
**
**** Segment leaf nodes ****
** Segment leaf nodes store terms and doclists, ordered by term.  Leaf
** nodes are written using LeafWriter, and read using LeafReader (to
** iterate through a single leaf node's data) and LeavesReader (to
** iterate through a segment's entire leaf layer).  Leaf nodes have
** the format:
**
** varint iHeight;             (height from leaf level, always 0)
** varint nTerm;               (length of first term)
** char pTerm[nTerm];          (content of first term)
** varint nDoclist;            (length of term's associated doclist)
** char pDoclist[nDoclist];    (content of doclist)
** array {
**                             (further terms are delta-encoded)
**   varint nPrefix;           (length of prefix shared with previous term)
**   varint nSuffix;           (length of unshared suffix)
**   char pTermSuffix[nSuffix];(unshared suffix of next term)
**   varint nDoclist;          (length of term's associated doclist)
**   char pDoclist[nDoclist];  (content of doclist)
** }
**
** Here, array { X } means zero or more occurrences of X, adjacent in
** memory.
**
** Leaf nodes are broken into blocks which are stored contiguously in
** the %_segments table in sorted order.  This means that when the end
** of a node is reached, the next term is in the node with the next
** greater node id.
**
** New data is spilled to a new leaf node when the current node
** exceeds LEAF_MAX bytes (default 2048).  New data which itself is
** larger than STANDALONE_MIN (default 1024) is placed in a standalone
** node (a leaf node with a single term and doclist).  The goal of
** these settings is to pack together groups of small doclists while
** making it efficient to directly access large doclists.  The
** assumption is that large doclists represent terms which are more
** likely to be query targets.
**
** TODO(shess) It may be useful for blocking decisions to be more
** dynamic.  For instance, it may make more sense to have a 2.5k leaf
** node rather than splitting into 2k and .5k nodes.  My intuition is
** that this might extend through 2x or 4x the pagesize.
**
**
**** Segment interior nodes ****
** Segment interior nodes store blockids for subtree nodes and terms
** to describe what data is stored by the each subtree.  Interior
** nodes are written using InteriorWriter, and read using
** InteriorReader.  InteriorWriters are created as needed when
** SegmentWriter creates new leaf nodes, or when an interior node
** itself grows too big and must be split.  The format of interior
** nodes:
**
** varint iHeight;           (height from leaf level, always >0)
** varint iBlockid;          (block id of node's leftmost subtree)
** optional {
**   varint nTerm;           (length of first term)
**   char pTerm[nTerm];      (content of first term)
**   array {
**                                (further terms are delta-encoded)
**     varint nPrefix;            (length of shared prefix with previous term)
**     varint nSuffix;            (length of unshared suffix)
**     char pTermSuffix[nSuffix]; (unshared suffix of next term)
**   }
** }
**
** Here, optional { X } means an optional element, while array { X }
** means zero or more occurrences of X, adjacent in memory.
**
** An interior node encodes n terms separating n+1 subtrees.  The
** subtree blocks are contiguous, so only the first subtree's blockid
** is encoded.  The subtree at iBlockid will contain all terms less
** than the first term encoded (or all terms if no term is encoded).
** Otherwise, for terms greater than or equal to pTerm[i] but less
** than pTerm[i+1], the subtree for that term will be rooted at
** iBlockid+i.  Interior nodes only store enough term data to
** distinguish adjacent children (if the rightmost term of the left
** child is "something", and the leftmost term of the right child is
** "wicked", only "w" is stored).
**
** New data is spilled to a new interior node at the same height when
** the current node exceeds INTERIOR_MAX bytes (default 2048).
** INTERIOR_MIN_TERMS (default 7) keeps large terms from monopolizing
** interior nodes and making the tree too skinny.  The interior nodes
** at a given height are naturally tracked by interior nodes at
** height+1, and so on.
**
**
**** Segment directory ****
** The segment directory in table %_segdir stores meta-information for
** merging and deleting segments, and also the root node of the
** segment's tree.
**
** The root node is the top node of the segment's tree after encoding
** the entire segment, restricted to ROOT_MAX bytes (default 1024).
** This could be either a leaf node or an interior node.  If the top
** node requires more than ROOT_MAX bytes, it is flushed to %_segments
** and a new root interior node is generated (which should always fit
** within ROOT_MAX because it only needs space for 2 varints, the
** height and the blockid of the previous root).
**
** The meta-information in the segment directory is:
**   level               - segment level (see below)
**   idx                 - index within level
**                       - (level,idx uniquely identify a segment)
**   start_block         - first leaf node
**   leaves_end_block    - last leaf node
**   end_block           - last block (including interior nodes)
**   root                - contents of root node
**
** If the root node is a leaf node, then start_block,
** leaves_end_block, and end_block are all 0.
**
**
**** Segment merging ****
** To amortize update costs, segments are grouped into levels and
** merged in batches.  Each increase in level represents exponentially
** more documents.
**
** New documents (actually, document updates) are tokenized and
** written individually (using LeafWriter) to a level 0 segment, with
** incrementing idx.  When idx reaches MERGE_COUNT (default 16), all
** level 0 segments are merged into a single level 1 segment.  Level 1
** is populated like level 0, and eventually MERGE_COUNT level 1
** segments are merged to a single level 2 segment (representing
** MERGE_COUNT^2 updates), and so on.
**
** A segment merge traverses all segments at a given level in
** parallel, performing a straightforward sorted merge.  Since segment
** leaf nodes are written in to the %_segments table in order, this
** merge traverses the underlying sqlite disk structures efficiently.
** After the merge, all segment blocks from the merged level are
** deleted.
**
** MERGE_COUNT controls how often we merge segments.  16 seems to be
** somewhat of a sweet spot for insertion performance.  32 and 64 show
** very similar performance numbers to 16 on insertion, though they're
** a tiny bit slower (perhaps due to more overhead in merge-time
** sorting).  8 is about 20% slower than 16, 4 about 50% slower than
** 16, 2 about 66% slower than 16.
**
** At query time, high MERGE_COUNT increases the number of segments
** which need to be scanned and merged.  For instance, with 100k docs
** inserted:
**
**    MERGE_COUNT   segments
**       16           25
**        8           12
**        4           10
**        2            6
**
** This appears to have only a moderate impact on queries for very
** frequent terms (which are somewhat dominated by segment merge
** costs), and infrequent and non-existent terms still seem to be fast
** even with many segments.
**
** TODO(shess) That said, it would be nice to have a better query-side
** argument for MERGE_COUNT of 16.  Also, it is possible/likely that
** optimizations to things like doclist merging will swing the sweet
** spot around.
**
**
**
**** Handling of deletions and updates ****
** Since we're using a segmented structure, with no docid-oriented
** index into the term index, we clearly cannot simply update the term
** index when a document is deleted or updated.  For deletions, we
** write an empty doclist (varint(docid) varint(POS_END)), for updates
** we simply write the new doclist.  Segment merges overwrite older
** data for a particular docid with newer data, so deletes or updates
** will eventually overtake the earlier data and knock it out.  The
** query logic likewise merges doclists so that newer data knocks out
** older data.
 */

/************** Include fts3Int.h in the middle of fts3.c ********************/
/************** Begin file fts3Int.h *****************************************/
/*
** 2009 Nov 12
**
** 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.
**
******************************************************************************
**
 */

/* FTS3/FTS4 require virtual tables */

/*
** FTS4 is really an extension for FTS3.  It is enabled using the
** SQLITE_ENABLE_FTS3 macro.  But to avoid confusion we also all
** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
 */

/************** End of fts3Int.h *********************************************/
/************** Continuing where we left off in fts3.c ***********************/

/************** End of fts3.c ************************************************/
/************** Begin file fts3_aux.c ****************************************/
/*
** 2011 Jan 27
**
** 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 "fts3Int.h" */

/************** End of fts3_aux.c ********************************************/
/************** Begin file fts3_expr.c ***************************************/
/*
** 2008 Nov 28
**
** 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 code that implements a parser for fts3 query strings
** (the right-hand argument to the MATCH operator). Because the supported
** syntax is relatively simple, the whole tokenizer/parser system is
** hand-coded.
 */
/* #include "fts3Int.h" */

/************** End of fts3_expr.c *******************************************/
/************** Begin file fts3_hash.c ***************************************/
/*
** 2001 September 22
**
** 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 is the implementation of generic hash-tables used in SQLite.
** We've modified it slightly to serve as a standalone hash table
** implementation for the full-text indexing module.
 */

/*
** The code in this file is only compiled if:
**
**     * The FTS3 module is being built as an extension
**       (in which case SQLITE_CORE is not defined), or
**
**     * The FTS3 module is being built into the core of
**       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
 */
/* #include "fts3Int.h" */

/************** End of fts3_hash.c *******************************************/
/************** Begin file fts3_porter.c *************************************/
/*
** 2006 September 30
**
** 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.
**
*************************************************************************
** Implementation of the full-text-search tokenizer that implements
** a Porter stemmer.
 */

/*
** The code in this file is only compiled if:
**
**     * The FTS3 module is being built as an extension
**       (in which case SQLITE_CORE is not defined), or
**
**     * The FTS3 module is being built into the core of
**       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
 */
/* #include "fts3Int.h" */

/************** End of fts3_porter.c *****************************************/
/************** Begin file fts3_tokenizer.c **********************************/
/*
** 2007 June 22
**
** 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 is part of an SQLite module implementing full-text search.
** This particular file implements the generic tokenizer interface.
 */

/*
** The code in this file is only compiled if:
**
**     * The FTS3 module is being built as an extension
**       (in which case SQLITE_CORE is not defined), or
**
**     * The FTS3 module is being built into the core of
**       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
 */
/* #include "fts3Int.h" */

/************** End of fts3_tokenizer.c **************************************/
/************** Begin file fts3_tokenizer1.c *********************************/
/*
** 2006 Oct 10
**
** 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.
**
******************************************************************************
**
** Implementation of the "simple" full-text-search tokenizer.
 */

/*
** The code in this file is only compiled if:
**
**     * The FTS3 module is being built as an extension
**       (in which case SQLITE_CORE is not defined), or
**
**     * The FTS3 module is being built into the core of
**       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
 */
/* #include "fts3Int.h" */

/************** End of fts3_tokenizer1.c *************************************/
/************** Begin file fts3_tokenize_vtab.c ******************************/
/*
** 2013 Apr 22
**
** 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 for the "fts3tokenize" virtual table module.
** An fts3tokenize virtual table is created as follows:
**
**   CREATE VIRTUAL TABLE <tbl> USING fts3tokenize(
**       <tokenizer-name>, <arg-1>, ...
**   );
**
** The table created has the following schema:
**
**   CREATE TABLE <tbl>(input, token, start, end, position)
**
** When queried, the query must include a WHERE clause of type:
**
**   input = <string>
**
** The virtual table module tokenizes this <string>, using the FTS3
** tokenizer specified by the arguments to the CREATE VIRTUAL TABLE
** statement and returns one row for each token in the result. With
** fields set as follows:
**
**   input:   Always set to a copy of <string>
**   token:   A token from the input.
**   start:   Byte offset of the token within the input <string>.
**   end:     Byte offset of the byte immediately following the end of the
**            token within the input string.
**   pos:     Token offset of token within input.
**
 */
/* #include "fts3Int.h" */

/************** End of fts3_tokenize_vtab.c **********************************/
/************** Begin file fts3_write.c **************************************/
/*
** 2009 Oct 23
**
** 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 is part of the SQLite FTS3 extension module. Specifically,
** this file contains code to insert, update and delete rows from FTS3
** tables. It also contains code to merge FTS3 b-tree segments. Some
** of the sub-routines used to merge segments are also used by the query
** code in fts3.c.
 */

/* #include "fts3Int.h" */

/************** End of fts3_write.c ******************************************/
/************** Begin file fts3_snippet.c ************************************/
/*
** 2009 Oct 23
**
** 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 "fts3Int.h" */

/************** End of fts3_snippet.c ****************************************/
/************** Begin file fts3_unicode.c ************************************/
/*
** 2012 May 24
**
** 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.
**
******************************************************************************
**
** Implementation of the "unicode" full-text-search tokenizer.
 */

/* #include "fts3Int.h" */

/************** End of fts3_unicode.c ****************************************/
/************** Begin file fts3_unicode2.c ***********************************/
/*
** 2012-05-25
**
** 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.
**
******************************************************************************
 */

/*
** DO NOT EDIT THIS MACHINE GENERATED FILE.
 */

/************** End of fts3_unicode2.c ***************************************/
/************** Begin file json.c ********************************************/
/*
** 2015-08-12
**
** 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.
**
******************************************************************************
**
** SQLite JSON functions.
**
** This file began as an extension in ext/misc/json1.c in 2015.  That
** extension proved so useful that it has now been moved into the core.
**
** The original design stored all JSON as pure text, canonical RFC-8259.
** Support for JSON-5 extensions was added with version 3.42.0 (2023-05-16).
** All generated JSON text still conforms strictly to RFC-8259, but text
** with JSON-5 extensions is accepted as input.
**
** Beginning with version 3.45.0 (circa 2024-01-01), these routines also
** accept BLOB values that have JSON encoded using a binary representation
** called "JSONB".  The name JSONB comes from PostgreSQL, however the on-disk
** format SQLite JSONB is completely different and incompatible with
** PostgreSQL JSONB.
**
** Decoding and interpreting JSONB is still O(N) where N is the size of
** the input, the same as text JSON.  However, the constant of proportionality
** for JSONB is much smaller due to faster parsing.  The size of each
** element in JSONB is encoded in its header, so there is no need to search
** for delimiters using persnickety syntax rules.  JSONB seems to be about
** 3x faster than text JSON as a result.  JSONB is also tends to be slightly
** smaller than text JSON, by 5% or 10%, but there are corner cases where
** JSONB can be slightly larger.  So you are not far mistaken to say that
** a JSONB blob is the same size as the equivalent RFC-8259 text.
**
**
** THE JSONB ENCODING:
**
** Every JSON element is encoded in JSONB as a header and a payload.
** The header is between 1 and 9 bytes in size.  The payload is zero
** or more bytes.
**
** The lower 4 bits of the first byte of the header determines the
** element type:
**
**    0:   NULL
**    1:   TRUE
**    2:   FALSE
**    3:   INT        -- RFC-8259 integer literal
**    4:   INT5       -- JSON5 integer literal
**    5:   FLOAT      -- RFC-8259 floating point literal
**    6:   FLOAT5     -- JSON5 floating point literal
**    7:   TEXT       -- Text literal acceptable to both SQL and JSON
**    8:   TEXTJ      -- Text containing RFC-8259 escapes
**    9:   TEXT5      -- Text containing JSON5 and/or RFC-8259 escapes
**   10:   TEXTRAW    -- Text containing unescaped syntax characters
**   11:   ARRAY
**   12:   OBJECT
**
** The other three possible values (13-15) are reserved for future
** enhancements.
**
** The upper 4 bits of the first byte determine the size of the header
** and sometimes also the size of the payload.  If X is the first byte
** of the element and if X>>4 is between 0 and 11, then the payload
** will be that many bytes in size and the header is exactly one byte
** in size.  Other four values for X>>4 (12-15) indicate that the header
** is more than one byte in size and that the payload size is determined
** by the remainder of the header, interpreted as a unsigned big-endian
** integer.
**
**   Value of X>>4         Size integer        Total header size
**   -------------     --------------------    -----------------
**        12           1 byte (0-255)                2
**        13           2 byte (0-65535)              3
**        14           4 byte (0-4294967295)         5
**        15           8 byte (0-1.8e19)             9
**
** The payload size need not be expressed in its minimal form.  For example,
** if the payload size is 10, the size can be expressed in any of 5 different
** ways: (1) (X>>4)==10, (2) (X>>4)==12 following by on 0x0a byte,
** (3) (X>>4)==13 followed by 0x00 and 0x0a, (4) (X>>4)==14 followed by
** 0x00 0x00 0x00 0x0a, or (5) (X>>4)==15 followed by 7 bytes of 0x00 and
** a single byte of 0x0a.  The shorter forms are preferred, of course, but
** sometimes when generating JSONB, the payload size is not known in advance
** and it is convenient to reserve sufficient header space to cover the
** largest possible payload size and then come back later and patch up
** the size when it becomes known, resulting in a non-minimal encoding.
**
** The value (X>>4)==15 is not actually used in the current implementation
** (as SQLite is currently unable handle BLOBs larger than about 2GB)
** but is included in the design to allow for future enhancements.
**
** The payload follows the header.  NULL, TRUE, and FALSE have no payload and
** their payload size must always be zero.  The payload for INT, INT5,
** FLOAT, FLOAT5, TEXT, TEXTJ, TEXT5, and TEXTROW is text.  Note that the
** "..." or '...' delimiters are omitted from the various text encodings.
** The payload for ARRAY and OBJECT is a list of additional elements that
** are the content for the array or object.  The payload for an OBJECT
** must be an even number of elements.  The first element of each pair is
** the label and must be of type TEXT, TEXTJ, TEXT5, or TEXTRAW.
**
** A valid JSONB blob consists of a single element, as described above.
** Usually this will be an ARRAY or OBJECT element which has many more
** elements as its content.  But the overall blob is just a single element.
**
** Input validation for JSONB blobs simply checks that the element type
** code is between 0 and 12 and that the total size of the element
** (header plus payload) is the same as the size of the BLOB.  If those
** checks are true, the BLOB is assumed to be JSONB and processing continues.
** Errors are only raised if some other miscoding is discovered during
** processing.
**
** Additional information can be found in the doc/jsonb.md file of the
** canonical SQLite source tree.
 */
/* #include "sqliteInt.h" */

/* JSONB element types
 */

// C documentation
//
//	/* Human-readable names for the JSONB values.  The index for each
//	** string must correspond to the JSONB_* integer above.
//	*/
var _jsonbType = [17]uintptr{
	0:  __ccgo_ts + 1658,
	1:  __ccgo_ts + 9320,
	2:  __ccgo_ts + 9325,
	3:  __ccgo_ts + 7679,
	4:  __ccgo_ts + 7679,
	5:  __ccgo_ts + 7674,
	6:  __ccgo_ts + 7674,
	7:  __ccgo_ts + 9631,
	8:  __ccgo_ts + 9631,
	9:  __ccgo_ts + 9631,
	10: __ccgo_ts + 9631,
	11: __ccgo_ts + 26333,
	12: __ccgo_ts + 26339,
	13: __ccgo_ts + 1672,
	14: __ccgo_ts + 1672,
	15: __ccgo_ts + 1672,
	16: __ccgo_ts + 1672,
}

// C documentation
//
//	/*
//	** Growing our own isspace() routine this way is twice as fast as
//	** the library isspace() function, resulting in a 7% overall performance
//	** increase for the text-JSON parser.  (Ubuntu14.10 gcc 4.8.4 x64 with -Os).
//	*/
var _jsonIsSpace = [256]int8{
	9:  int8(1),
	10: int8(1),
	13: int8(1),
	32: int8(1),
}

// C documentation
//
//	/*
//	** The set of all space characters recognized by jsonIsspace().
//	** Useful as the second argument to strspn().
//	*/
var _jsonSpaces = [5]int8{9, 10, 13, ' '}

// C documentation
//
//	/*
//	** Characters that are special to JSON.  Control characters,
//	** '"' and '\\' and '\''.  Actually, '\'' is not special to
//	** canonical JSON, but it is special in JSON-5, so we include
//	** it in the set of special characters.
//	*/
var _jsonIsOk = [256]int8{
	32:  int8(1),
	33:  int8(1),
	35:  int8(1),
	36:  int8(1),
	37:  int8(1),
	38:  int8(1),
	40:  int8(1),
	41:  int8(1),
	42:  int8(1),
	43:  int8(1),
	44:  int8(1),
	45:  int8(1),
	46:  int8(1),
	47:  int8(1),
	48:  int8(1),
	49:  int8(1),
	50:  int8(1),
	51:  int8(1),
	52:  int8(1),
	53:  int8(1),
	54:  int8(1),
	55:  int8(1),
	56:  int8(1),
	57:  int8(1),
	58:  int8(1),
	59:  int8(1),
	60:  int8(1),
	61:  int8(1),
	62:  int8(1),
	63:  int8(1),
	64:  int8(1),
	65:  int8(1),
	66:  int8(1),
	67:  int8(1),
	68:  int8(1),
	69:  int8(1),
	70:  int8(1),
	71:  int8(1),
	72:  int8(1),
	73:  int8(1),
	74:  int8(1),
	75:  int8(1),
	76:  int8(1),
	77:  int8(1),
	78:  int8(1),
	79:  int8(1),
	80:  int8(1),
	81:  int8(1),
	82:  int8(1),
	83:  int8(1),
	84:  int8(1),
	85:  int8(1),
	86:  int8(1),
	87:  int8(1),
	88:  int8(1),
	89:  int8(1),
	90:  int8(1),
	91:  int8(1),
	93:  int8(1),
	94:  int8(1),
	95:  int8(1),
	96:  int8(1),
	97:  int8(1),
	98:  int8(1),
	99:  int8(1),
	100: int8(1),
	101: int8(1),
	102: int8(1),
	103: int8(1),
	104: int8(1),
	105: int8(1),
	106: int8(1),
	107: int8(1),
	108: int8(1),
	109: int8(1),
	110: int8(1),
	111: int8(1),
	112: int8(1),
	113: int8(1),
	114: int8(1),
	115: int8(1),
	116: int8(1),
	117: int8(1),
	118: int8(1),
	119: int8(1),
	120: int8(1),
	121: int8(1),
	122: int8(1),
	123: int8(1),
	124: int8(1),
	125: int8(1),
	126: int8(1),
	127: int8(1),
	128: int8(1),
	129: int8(1),
	130: int8(1),
	131: int8(1),
	132: int8(1),
	133: int8(1),
	134: int8(1),
	135: int8(1),
	136: int8(1),
	137: int8(1),
	138: int8(1),
	139: int8(1),
	140: int8(1),
	141: int8(1),
	142: int8(1),
	143: int8(1),
	144: int8(1),
	145: int8(1),
	146: int8(1),
	147: int8(1),
	148: int8(1),
	149: int8(1),
	150: int8(1),
	151: int8(1),
	152: int8(1),
	153: int8(1),
	154: int8(1),
	155: int8(1),
	156: int8(1),
	157: int8(1),
	158: int8(1),
	159: int8(1),
	160: int8(1),
	161: int8(1),
	162: int8(1),
	163: int8(1),
	164: int8(1),
	165: int8(1),
	166: int8(1),
	167: int8(1),
	168: int8(1),
	169: int8(1),
	170: int8(1),
	171: int8(1),
	172: int8(1),
	173: int8(1),
	174: int8(1),
	175: int8(1),
	176: int8(1),
	177: int8(1),
	178: int8(1),
	179: int8(1),
	180: int8(1),
	181: int8(1),
	182: int8(1),
	183: int8(1),
	184: int8(1),
	185: int8(1),
	186: int8(1),
	187: int8(1),
	188: int8(1),
	189: int8(1),
	190: int8(1),
	191: int8(1),
	192: int8(1),
	193: int8(1),
	194: int8(1),
	195: int8(1),
	196: int8(1),
	197: int8(1),
	198: int8(1),
	199: int8(1),
	200: int8(1),
	201: int8(1),
	202: int8(1),
	203: int8(1),
	204: int8(1),
	205: int8(1),
	206: int8(1),
	207: int8(1),
	208: int8(1),
	209: int8(1),
	210: int8(1),
	211: int8(1),
	212: int8(1),
	213: int8(1),
	214: int8(1),
	215: int8(1),
	216: int8(1),
	217: int8(1),
	218: int8(1),
	219: int8(1),
	220: int8(1),
	221: int8(1),
	222: int8(1),
	223: int8(1),
	224: int8(1),
	225: int8(1),
	226: int8(1),
	227: int8(1),
	228: int8(1),
	229: int8(1),
	230: int8(1),
	231: int8(1),
	232: int8(1),
	233: int8(1),
	234: int8(1),
	235: int8(1),
	236: int8(1),
	237: int8(1),
	238: int8(1),
	239: int8(1),
	240: int8(1),
	241: int8(1),
	242: int8(1),
	243: int8(1),
	244: int8(1),
	245: int8(1),
	246: int8(1),
	247: int8(1),
	248: int8(1),
	249: int8(1),
	250: int8(1),
	251: int8(1),
	252: int8(1),
	253: int8(1),
	254: int8(1),
	255: int8(1),
}

// C documentation
//
//	/* Objects */
type TJsonCache = struct {
	Fdb    uintptr
	FnUsed int32
	Fa     [4]uintptr
}

type JsonCache = TJsonCache

type TJsonString = struct {
	F__ccgo_align [0]uint32
	FpCtx         uintptr
	FzBuf         uintptr
	FnAlloc       Tu64
	FnUsed        Tu64
	FbStatic      Tu8
	FeErr         Tu8
	FzSpace       [100]int8
	F__ccgo_pad7  [2]byte
}

type JsonString = TJsonString

type TJsonParse = struct {
	FaBlob        uintptr
	FnBlob        Tu32
	FnBlobAlloc   Tu32
	FzJson        uintptr
	Fdb           uintptr
	FnJson        int32
	FnJPRef       Tu32
	FiErr         Tu32
	FiDepth       Tu16
	FnErr         Tu8
	Foom          Tu8
	FbJsonIsRCStr Tu8
	FhasNonstd    Tu8
	FbReadOnly    Tu8
	FeEdit        Tu8
	Fdelta        int32
	FnIns         Tu32
	FiLabel       Tu32
	FaIns         uintptr
}

type JsonParse = TJsonParse

/*
** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
 */

/*
** jsonUnescapeOneChar() returns this invalid code point if it encounters
** a syntax error.
 */

/* A cache mapping JSON text into JSONB blobs.
**
** Each cache entry is a JsonParse object with the following restrictions:
**
**    *   The bReadOnly flag must be set
**
**    *   The aBlob[] array must be owned by the JsonParse object.  In other
**        words, nBlobAlloc must be non-zero.
**
**    *   eEdit and delta must be zero.
**
**    *   zJson must be an RCStr.  In other words bJsonIsRCStr must be true.
 */
type TJsonCache1 = struct {
	Fdb    uintptr
	FnUsed int32
	Fa     [4]uintptr
}

type JsonCache1 = TJsonCache1

/* An instance of this object represents a JSON string
** under construction.  Really, this is a generic string accumulator
** that can be and is used to create strings other than JSON.
**
** If the generated string is longer than will fit into the zSpace[] buffer,
** then it will be an RCStr string.  This aids with caching of large
** JSON strings.
 */
type TJsonString1 = struct {
	F__ccgo_align [0]uint32
	FpCtx         uintptr
	FzBuf         uintptr
	FnAlloc       Tu64
	FnUsed        Tu64
	FbStatic      Tu8
	FeErr         Tu8
	FzSpace       [100]int8
	F__ccgo_pad7  [2]byte
}

type JsonString1 = TJsonString1

/* Allowed values for JsonString.eErr */

/* The "subtype" set for text JSON values passed through using
** sqlite3_result_subtype() and sqlite3_value_subtype().
 */

/*
** Bit values for the flags passed into various SQL function implementations
** via the sqlite3_user_data() value.
 */

/* A parsed JSON value.  Lifecycle:
**
**   1.  JSON comes in and is parsed into a JSONB value in aBlob.  The
**       original text is stored in zJson.  This step is skipped if the
**       input is JSONB instead of text JSON.
**
**   2.  The aBlob[] array is searched using the JSON path notation, if needed.
**
**   3.  Zero or more changes are made to aBlob[] (via json_remove() or
**       json_replace() or json_patch() or similar).
**
**   4.  New JSON text is generated from the aBlob[] for output.  This step
**       is skipped if the function is one of the jsonb_* functions that
**       returns JSONB instead of text JSON.
 */
type TJsonParse1 = struct {
	FaBlob        uintptr
	FnBlob        Tu32
	FnBlobAlloc   Tu32
	FzJson        uintptr
	Fdb           uintptr
	FnJson        int32
	FnJPRef       Tu32
	FiErr         Tu32
	FiDepth       Tu16
	FnErr         Tu8
	Foom          Tu8
	FbJsonIsRCStr Tu8
	FhasNonstd    Tu8
	FbReadOnly    Tu8
	FeEdit        Tu8
	Fdelta        int32
	FnIns         Tu32
	FiLabel       Tu32
	FaIns         uintptr
}

type JsonParse1 = TJsonParse1

/**************************************************************************
** Utility routines for dealing with JsonCache objects
**************************************************************************/

// C documentation
//
//	/*
//	** Free a JsonCache object.
//	*/
func _jsonCacheDelete(tls *libc.TLS, p uintptr) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed) {
			break
		}
		_jsonParseFree(tls, *(*uintptr)(unsafe.Pointer(p + 8 + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
	_sqlite3DbFree(tls, (*TJsonCache)(unsafe.Pointer(p)).Fdb, p)
}

func _jsonCacheDeleteGeneric(tls *libc.TLS, p uintptr) {
	_jsonCacheDelete(tls, p)
}

// C documentation
//
//	/*
//	** Insert a new entry into the cache.  If the cache is full, expel
//	** the least recently used entry.  Return SQLITE_OK on success or a
//	** result code otherwise.
//	**
//	** Cache entries are stored in age order, oldest first.
//	*/
func _jsonCacheInsert(tls *libc.TLS, ctx uintptr, pParse uintptr) (r int32) {
	var db, p uintptr
	_, _ = db, p
	p = Xsqlite3_get_auxdata(tls, ctx, -int32(429938))
	if p == uintptr(0) {
		db = Xsqlite3_context_db_handle(tls, ctx)
		p = _sqlite3DbMallocZero(tls, db, uint64(24))
		if p == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		(*TJsonCache)(unsafe.Pointer(p)).Fdb = db
		Xsqlite3_set_auxdata(tls, ctx, -int32(429938), p, __ccgo_fp(_jsonCacheDeleteGeneric))
		p = Xsqlite3_get_auxdata(tls, ctx, -int32(429938))
		if p == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
	}
	if (*TJsonCache)(unsafe.Pointer(p)).FnUsed >= int32(JSON_CACHE_SIZE) {
		_jsonParseFree(tls, *(*uintptr)(unsafe.Pointer(p + 8)))
		libc.Xmemmove(tls, p+8, p+8+1*4, uint32(libc.Int32FromInt32(JSON_CACHE_SIZE)-libc.Int32FromInt32(1))*libc.Uint32FromInt64(4))
		(*TJsonCache)(unsafe.Pointer(p)).FnUsed = libc.Int32FromInt32(JSON_CACHE_SIZE) - libc.Int32FromInt32(1)
	}
	(*TJsonParse)(unsafe.Pointer(pParse)).FeEdit = uint8(0)
	(*TJsonParse)(unsafe.Pointer(pParse)).FnJPRef++
	(*TJsonParse)(unsafe.Pointer(pParse)).FbReadOnly = uint8(1)
	*(*uintptr)(unsafe.Pointer(p + 8 + uintptr((*TJsonCache)(unsafe.Pointer(p)).FnUsed)*4)) = pParse
	(*TJsonCache)(unsafe.Pointer(p)).FnUsed++
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Search for a cached translation the json text supplied by pArg.  Return
//	** the JsonParse object if found.  Return NULL if not found.
//	**
//	** When a match if found, the matching entry is moved to become the
//	** most-recently used entry if it isn't so already.
//	**
//	** The JsonParse object returned still belongs to the Cache and might
//	** be deleted at any moment.  If the caller whants the JsonParse to
//	** linger, it needs to increment the nPJRef reference counter.
//	*/
func _jsonCacheSearch(tls *libc.TLS, ctx uintptr, pArg uintptr) (r uintptr) {
	var i, nJson int32
	var p, tmp, zJson uintptr
	_, _, _, _, _ = i, nJson, p, tmp, zJson
	if Xsqlite3_value_type(tls, pArg) != int32(SQLITE_TEXT) {
		return uintptr(0)
	}
	zJson = Xsqlite3_value_text(tls, pArg)
	if zJson == uintptr(0) {
		return uintptr(0)
	}
	nJson = Xsqlite3_value_bytes(tls, pArg)
	p = Xsqlite3_get_auxdata(tls, ctx, -int32(429938))
	if p == uintptr(0) {
		return uintptr(0)
	}
	i = 0
	for {
		if !(i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed) {
			break
		}
		if (*TJsonParse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8 + uintptr(i)*4)))).FzJson == zJson {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	if i >= (*TJsonCache)(unsafe.Pointer(p)).FnUsed {
		i = 0
		for {
			if !(i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed) {
				break
			}
			if (*TJsonParse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8 + uintptr(i)*4)))).FnJson != nJson {
				goto _2
			}
			if libc.Xmemcmp(tls, (*TJsonParse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8 + uintptr(i)*4)))).FzJson, zJson, uint32(uint32(nJson))) == 0 {
				break
			}
			goto _2
		_2:
			;
			i++
		}
	}
	if i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed {
		if i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed-int32(1) {
			/* Make the matching entry the most recently used entry */
			tmp = *(*uintptr)(unsafe.Pointer(p + 8 + uintptr(i)*4))
			libc.Xmemmove(tls, p+8+uintptr(i)*4, p+8+uintptr(i+int32(1))*4, uint32((*TJsonCache)(unsafe.Pointer(p)).FnUsed-i-libc.Int32FromInt32(1))*uint32(4))
			*(*uintptr)(unsafe.Pointer(p + 8 + uintptr((*TJsonCache)(unsafe.Pointer(p)).FnUsed-int32(1))*4)) = tmp
			i = (*TJsonCache)(unsafe.Pointer(p)).FnUsed - int32(1)
		}
		return *(*uintptr)(unsafe.Pointer(p + 8 + uintptr(i)*4))
	} else {
		return uintptr(0)
	}
	return r
}

/**************************************************************************
** Utility routines for dealing with JsonString objects
**************************************************************************/

// C documentation
//
//	/* Turn uninitialized bulk memory into a valid JsonString object
//	** holding a zero-length string.
//	*/
func _jsonStringZero(tls *libc.TLS, p uintptr) {
	(*TJsonString)(unsafe.Pointer(p)).FzBuf = p + 26
	(*TJsonString)(unsafe.Pointer(p)).FnAlloc = uint64(100)
	(*TJsonString)(unsafe.Pointer(p)).FnUsed = uint64(0)
	(*TJsonString)(unsafe.Pointer(p)).FbStatic = uint8(1)
}

// C documentation
//
//	/* Initialize the JsonString object
//	*/
func _jsonStringInit(tls *libc.TLS, p uintptr, pCtx uintptr) {
	(*TJsonString)(unsafe.Pointer(p)).FpCtx = pCtx
	(*TJsonString)(unsafe.Pointer(p)).FeErr = uint8(0)
	_jsonStringZero(tls, p)
}

// C documentation
//
//	/* Free all allocated memory and reset the JsonString object back to its
//	** initial state.
//	*/
func _jsonStringReset(tls *libc.TLS, p uintptr) {
	if !((*TJsonString)(unsafe.Pointer(p)).FbStatic != 0) {
		_sqlite3RCStrUnref(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf)
	}
	_jsonStringZero(tls, p)
}

// C documentation
//
//	/* Report an out-of-memory (OOM) condition
//	*/
func _jsonStringOom(tls *libc.TLS, p uintptr) {
	var p1 uintptr
	_ = p1
	p1 = p + 25
	*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(JSTRING_OOM))
	if (*TJsonString)(unsafe.Pointer(p)).FpCtx != 0 {
		Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)
	}
	_jsonStringReset(tls, p)
}

// C documentation
//
//	/* Enlarge pJson->zBuf so that it can hold at least N more bytes.
//	** Return zero on success.  Return non-zero on an OOM error
//	*/
func _jsonStringGrow(tls *libc.TLS, p uintptr, N Tu32) (r int32) {
	var nTotal Tu64
	var zNew, p2 uintptr
	var v1 uint64
	_, _, _, _ = nTotal, zNew, v1, p2
	if uint64(uint64(N)) < (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
		v1 = (*TJsonString)(unsafe.Pointer(p)).FnAlloc * uint64(2)
	} else {
		v1 = (*TJsonString)(unsafe.Pointer(p)).FnAlloc + uint64(uint64(N)) + uint64(10)
	}
	nTotal = v1
	if (*TJsonString)(unsafe.Pointer(p)).FbStatic != 0 {
		if (*TJsonString)(unsafe.Pointer(p)).FeErr != 0 {
			return int32(1)
		}
		zNew = _sqlite3RCStrNew(tls, nTotal)
		if zNew == uintptr(0) {
			_jsonStringOom(tls, p)
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemcpy(tls, zNew, (*TJsonString)(unsafe.Pointer(p)).FzBuf, uint32((*TJsonString)(unsafe.Pointer(p)).FnUsed))
		(*TJsonString)(unsafe.Pointer(p)).FzBuf = zNew
		(*TJsonString)(unsafe.Pointer(p)).FbStatic = uint8(0)
	} else {
		(*TJsonString)(unsafe.Pointer(p)).FzBuf = _sqlite3RCStrResize(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf, nTotal)
		if (*TJsonString)(unsafe.Pointer(p)).FzBuf == uintptr(0) {
			p2 = p + 25
			*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | libc.Int32FromInt32(JSTRING_OOM))
			_jsonStringZero(tls, p)
			return int32(SQLITE_NOMEM)
		}
	}
	(*TJsonString)(unsafe.Pointer(p)).FnAlloc = nTotal
	return SQLITE_OK
}

// C documentation
//
//	/* Append N bytes from zIn onto the end of the JsonString string.
//	*/
func _jsonStringExpandAndAppend(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
	if _jsonStringGrow(tls, p, N) != 0 {
		return
	}
	libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, N)
	*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(uint64(N))
}

func _jsonAppendRaw(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
	if N == uint32(0) {
		return
	}
	if uint64(uint64(N))+(*TJsonString)(unsafe.Pointer(p)).FnUsed >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
		_jsonStringExpandAndAppend(tls, p, zIn, N)
	} else {
		libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, N)
		*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(uint64(N))
	}
}

func _jsonAppendRawNZ(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
	if uint64(uint64(N))+(*TJsonString)(unsafe.Pointer(p)).FnUsed >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
		_jsonStringExpandAndAppend(tls, p, zIn, N)
	} else {
		libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, N)
		*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(uint64(N))
	}
}

// C documentation
//
//	/* Append formatted text (not to exceed N bytes) to the JsonString.
//	*/
func _jsonPrintf(tls *libc.TLS, N int32, p uintptr, zFormat uintptr, va uintptr) {
	var ap Tva_list
	_ = ap
	if (*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(uint64(N)) >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc && _jsonStringGrow(tls, p, uint32(uint32(N))) != 0 {
		return
	}
	ap = va
	Xsqlite3_vsnprintf(tls, N, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zFormat, ap)
	_ = ap
	*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(int32(libc.Xstrlen(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed))))
}

// C documentation
//
//	/* Append a single character
//	*/
func _jsonAppendCharExpand(tls *libc.TLS, p uintptr, c int8) {
	var v1 Tu64
	var v2 uintptr
	_, _ = v1, v2
	if _jsonStringGrow(tls, p, uint32(1)) != 0 {
		return
	}
	v2 = p + 16
	v1 = *(*Tu64)(unsafe.Pointer(v2))
	*(*Tu64)(unsafe.Pointer(v2))++
	*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = c
}

func _jsonAppendChar(tls *libc.TLS, p uintptr, c int8) {
	var v1 Tu64
	var v2 uintptr
	_, _ = v1, v2
	if (*TJsonString)(unsafe.Pointer(p)).FnUsed >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
		_jsonAppendCharExpand(tls, p, c)
	} else {
		v2 = p + 16
		v1 = *(*Tu64)(unsafe.Pointer(v2))
		*(*Tu64)(unsafe.Pointer(v2))++
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = c
	}
}

// C documentation
//
//	/* Remove a single character from the end of the string
//	*/
func _jsonStringTrimOneChar(tls *libc.TLS, p uintptr) {
	if int32((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0 {
		(*TJsonString)(unsafe.Pointer(p)).FnUsed--
	}
}

// C documentation
//
//	/* Make sure there is a zero terminator on p->zBuf[]
//	**
//	** Return true on success.  Return false if an OOM prevents this
//	** from happening.
//	*/
func _jsonStringTerminate(tls *libc.TLS, p uintptr) (r int32) {
	_jsonAppendChar(tls, p, 0)
	_jsonStringTrimOneChar(tls, p)
	return libc.BoolInt32(int32((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0)
}

// C documentation
//
//	/* Append a comma separator to the output buffer, if the previous
//	** character is not '[' or '{'.
//	*/
func _jsonAppendSeparator(tls *libc.TLS, p uintptr) {
	var c int8
	_ = c
	if (*TJsonString)(unsafe.Pointer(p)).FnUsed == uint64(0) {
		return
	}
	c = *(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed-uint64(1))))
	if int32(int32(c)) == int32('[') || int32(int32(c)) == int32('{') {
		return
	}
	_jsonAppendChar(tls, p, int8(','))
}

// C documentation
//
//	/* c is a control character.  Append the canonical JSON representation
//	** of that control character to p.
//	**
//	** This routine assumes that the output buffer has already been enlarged
//	** sufficiently to hold the worst-case encoding plus a nul terminator.
//	*/
func _jsonAppendControlChar(tls *libc.TLS, p uintptr, c Tu8) {
	if _aSpecial[c] != 0 {
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed))) = int8('\\')
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(1)))) = _aSpecial[c]
		*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(2)
	} else {
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed))) = int8('\\')
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(1)))) = int8('u')
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(2)))) = int8('0')
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(3)))) = int8('0')
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(4)))) = *(*int8)(unsafe.Pointer(__ccgo_ts + 26346 + uintptr(int32(int32(c))>>int32(4))))
		*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(5)))) = *(*int8)(unsafe.Pointer(__ccgo_ts + 26346 + uintptr(int32(int32(c))&int32(0xf))))
		*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(6)
	}
}

var _aSpecial = [32]int8{
	8:  int8('b'),
	9:  int8('t'),
	10: int8('n'),
	12: int8('f'),
	13: int8('r'),
}

// C documentation
//
//	/* Append the N-byte string in zIn to the end of the JsonString string
//	** under construction.  Enclose the string in double-quotes ("...") and
//	** escape any double-quotes or backslash characters contained within the
//	** string.
//	**
//	** This routine is a high-runner.  There is a measurable performance
//	** increase associated with unwinding the jsonIsOk[] loop.
//	*/
func _jsonAppendString(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
	var c Tu8
	var k Tu32
	var z, v10, v2, v4, v6, v8 uintptr
	var v1, v3, v5, v7, v9 Tu64
	_, _, _, _, _, _, _, _, _, _, _, _, _ = c, k, z, v1, v10, v2, v3, v4, v5, v6, v7, v8, v9
	z = zIn
	if z == uintptr(0) {
		return
	}
	if uint64(uint64(N))+(*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(2) >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc && _jsonStringGrow(tls, p, N+uint32(2)) != 0 {
		return
	}
	v2 = p + 16
	v1 = *(*Tu64)(unsafe.Pointer(v2))
	*(*Tu64)(unsafe.Pointer(v2))++
	*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = int8('"')
	for int32(1) != 0 {
		k = uint32(0)
		/* The following while() is the 4-way unwound equivalent of
		 **
		 **     while( k<N && jsonIsOk[z[k]] ){ k++; }
		 */
		for int32(1) != 0 {
			if k+uint32(3) >= N {
				for k < N && _jsonIsOk[*(*Tu8)(unsafe.Pointer(z + uintptr(k)))] != 0 {
					k++
				}
				break
			}
			if !(_jsonIsOk[*(*Tu8)(unsafe.Pointer(z + uintptr(k)))] != 0) {
				break
			}
			if !(_jsonIsOk[*(*Tu8)(unsafe.Pointer(z + uintptr(k+uint32(1))))] != 0) {
				k += uint32(1)
				break
			}
			if !(_jsonIsOk[*(*Tu8)(unsafe.Pointer(z + uintptr(k+uint32(2))))] != 0) {
				k += uint32(2)
				break
			}
			if !(_jsonIsOk[*(*Tu8)(unsafe.Pointer(z + uintptr(k+uint32(3))))] != 0) {
				k += uint32(3)
				break
			} else {
				k += uint32(4)
			}
		}
		if k >= N {
			if k > uint32(0) {
				libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), z, k)
				*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(uint64(k))
			}
			break
		}
		if k > uint32(0) {
			libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), z, k)
			*(*Tu64)(unsafe.Pointer(p + 16)) += uint64(uint64(k))
			z += uintptr(k)
			N -= k
		}
		c = *(*Tu8)(unsafe.Pointer(z))
		if int32(int32(c)) == int32('"') || int32(int32(c)) == int32('\\') {
			if (*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(uint64(N))+uint64(3) > (*TJsonString)(unsafe.Pointer(p)).FnAlloc && _jsonStringGrow(tls, p, N+uint32(3)) != 0 {
				return
			}
			v4 = p + 16
			v3 = *(*Tu64)(unsafe.Pointer(v4))
			*(*Tu64)(unsafe.Pointer(v4))++
			*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v3))) = int8('\\')
			v6 = p + 16
			v5 = *(*Tu64)(unsafe.Pointer(v6))
			*(*Tu64)(unsafe.Pointer(v6))++
			*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v5))) = int8(int8(c))
		} else {
			if int32(int32(c)) == int32('\'') {
				v8 = p + 16
				v7 = *(*Tu64)(unsafe.Pointer(v8))
				*(*Tu64)(unsafe.Pointer(v8))++
				*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v7))) = int8(int8(c))
			} else {
				if (*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(uint64(N))+uint64(7) > (*TJsonString)(unsafe.Pointer(p)).FnAlloc && _jsonStringGrow(tls, p, N+uint32(7)) != 0 {
					return
				}
				_jsonAppendControlChar(tls, p, c)
			}
		}
		z++
		N--
	}
	v10 = p + 16
	v9 = *(*Tu64)(unsafe.Pointer(v10))
	*(*Tu64)(unsafe.Pointer(v10))++
	*(*int8)(unsafe.Pointer((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v9))) = int8('"')
}

// C documentation
//
//	/*
//	** Append an sqlite3_value (such as a function parameter) to the JSON
//	** string under construction in p.
//	*/
func _jsonAppendSqlValue(tls *libc.TLS, p uintptr, pValue uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var n, n1 Tu32
	var z, z1 uintptr
	var _ /* px at bp+0 */ TJsonParse
	_, _, _, _ = n, n1, z, z1
	switch Xsqlite3_value_type(tls, pValue) {
	case int32(SQLITE_NULL):
		_jsonAppendRawNZ(tls, p, __ccgo_ts+1658, uint32(4))
	case int32(SQLITE_FLOAT):
		_jsonPrintf(tls, int32(100), p, __ccgo_ts+16730, libc.VaList(bp+64, Xsqlite3_value_double(tls, pValue)))
	case int32(SQLITE_INTEGER):
		z = Xsqlite3_value_text(tls, pValue)
		n = uint32(Xsqlite3_value_bytes(tls, pValue))
		_jsonAppendRaw(tls, p, z, n)
	case int32(SQLITE_TEXT):
		z1 = Xsqlite3_value_text(tls, pValue)
		n1 = uint32(Xsqlite3_value_bytes(tls, pValue))
		if Xsqlite3_value_subtype(tls, pValue) == uint32(JSON_SUBTYPE) {
			_jsonAppendRaw(tls, p, z1, n1)
		} else {
			_jsonAppendString(tls, p, z1, n1)
		}
	default:
		if _jsonFuncArgMightBeBinary(tls, pValue) != 0 {
			libc.Xmemset(tls, bp, 0, uint32(56))
			(*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob = Xsqlite3_value_blob(tls, pValue)
			(*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob = uint32(Xsqlite3_value_bytes(tls, pValue))
			_jsonTranslateBlobToText(tls, bp, uint32(0), p)
		} else {
			if int32((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0 {
				Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26363, -int32(1))
				(*TJsonString)(unsafe.Pointer(p)).FeErr = uint8(JSTRING_ERR)
				_jsonStringReset(tls, p)
			}
		}
		break
	}
}

// C documentation
//
//	/* Make the text in p (which is probably a generated JSON text string)
//	** the result of the SQL function.
//	**
//	** The JsonString is reset.
//	**
//	** If pParse and ctx are both non-NULL, then the SQL string in p is
//	** loaded into the zJson field of the pParse object as a RCStr and the
//	** pParse is added to the cache.
//	*/
func _jsonReturnString(tls *libc.TLS, p uintptr, pParse uintptr, ctx uintptr) {
	var flags, rc int32
	_, _ = flags, rc
	if int32((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0 {
		flags = int32(Xsqlite3_user_data(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx))
		if flags&int32(JSON_BLOB) != 0 {
			_jsonReturnStringAsBlob(tls, p)
		} else {
			if (*TJsonString)(unsafe.Pointer(p)).FbStatic != 0 {
				Xsqlite3_result_text64(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, (*TJsonString)(unsafe.Pointer(p)).FzBuf, (*TJsonString)(unsafe.Pointer(p)).FnUsed, uintptr(-libc.Int32FromInt32(1)), uint8(SQLITE_UTF8))
			} else {
				if _jsonStringTerminate(tls, p) != 0 {
					if pParse != 0 && int32((*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr) == 0 && (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc > uint32(0) {
						(*TJsonParse)(unsafe.Pointer(pParse)).FzJson = _sqlite3RCStrRef(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf)
						(*TJsonParse)(unsafe.Pointer(pParse)).FnJson = int32((*TJsonString)(unsafe.Pointer(p)).FnUsed)
						(*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr = uint8(1)
						rc = _jsonCacheInsert(tls, ctx, pParse)
						if rc == int32(SQLITE_NOMEM) {
							Xsqlite3_result_error_nomem(tls, ctx)
							_jsonStringReset(tls, p)
							return
						}
					}
					Xsqlite3_result_text64(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, _sqlite3RCStrRef(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf), (*TJsonString)(unsafe.Pointer(p)).FnUsed, __ccgo_fp(_sqlite3RCStrUnref), uint8(SQLITE_UTF8))
				} else {
					Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)
				}
			}
		}
	} else {
		if int32((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_OOM) != 0 {
			Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)
		} else {
			if int32((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_MALFORMED) != 0 {
				Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26392, -int32(1))
			}
		}
	}
	_jsonStringReset(tls, p)
}

/**************************************************************************
** Utility routines for dealing with JsonParse objects
**************************************************************************/

// C documentation
//
//	/*
//	** Reclaim all memory allocated by a JsonParse object.  But do not
//	** delete the JsonParse object itself.
//	*/
func _jsonParseReset(tls *libc.TLS, pParse uintptr) {
	if (*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr != 0 {
		_sqlite3RCStrUnref(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FzJson)
		(*TJsonParse)(unsafe.Pointer(pParse)).FzJson = uintptr(0)
		(*TJsonParse)(unsafe.Pointer(pParse)).FnJson = 0
		(*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr = uint8(0)
	}
	if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc != 0 {
		_sqlite3DbFree(tls, (*TJsonParse)(unsafe.Pointer(pParse)).Fdb, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob)
		(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = uintptr(0)
		(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = uint32(0)
		(*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc = uint32(0)
	}
}

// C documentation
//
//	/*
//	** Decrement the reference count on the JsonParse object.  When the
//	** count reaches zero, free the object.
//	*/
func _jsonParseFree(tls *libc.TLS, pParse uintptr) {
	if pParse != 0 {
		if (*TJsonParse)(unsafe.Pointer(pParse)).FnJPRef > uint32(1) {
			(*TJsonParse)(unsafe.Pointer(pParse)).FnJPRef--
		} else {
			_jsonParseReset(tls, pParse)
			_sqlite3DbFree(tls, (*TJsonParse)(unsafe.Pointer(pParse)).Fdb, pParse)
		}
	}
}

/**************************************************************************
** Utility routines for the JSON text parser
**************************************************************************/

// C documentation
//
//	/*
//	** Translate a single byte of Hex into an integer.
//	** This routine only gives a correct answer if h really is a valid hexadecimal
//	** character:  0..9a..fA..F.  But unlike sqlite3HexToInt(), it does not
//	** assert() if the digit is not hex.
//	*/
func _jsonHexToInt(tls *libc.TLS, h int32) (r Tu8) {
	h += int32(9) * (int32(1) & (h >> int32(6)))
	return uint8(h & libc.Int32FromInt32(0xf))
}

// C documentation
//
//	/*
//	** Convert a 4-byte hex string into an integer
//	*/
func _jsonHexToInt4(tls *libc.TLS, z uintptr) (r Tu32) {
	var v Tu32
	_ = v
	v = uint32(int32(_jsonHexToInt(tls, int32(*(*int8)(unsafe.Pointer(z)))))<<int32(12) + int32(_jsonHexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + 1)))))<<int32(8) + int32(_jsonHexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + 2)))))<<int32(4) + int32(_jsonHexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + 3))))))
	return v
}

// C documentation
//
//	/*
//	** Return true if z[] begins with 2 (or more) hexadecimal digits
//	*/
func _jsonIs2Hex(tls *libc.TLS, z uintptr) (r int32) {
	return libc.BoolInt32(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&int32(0x08) != 0 && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + 1)))])&int32(0x08) != 0)
}

// C documentation
//
//	/*
//	** Return true if z[] begins with 4 (or more) hexadecimal digits
//	*/
func _jsonIs4Hex(tls *libc.TLS, z uintptr) (r int32) {
	return libc.BoolInt32(_jsonIs2Hex(tls, z) != 0 && _jsonIs2Hex(tls, z+2) != 0)
}

// C documentation
//
//	/*
//	** Return the number of bytes of JSON5 whitespace at the beginning of
//	** the input string z[].
//	**
//	** JSON5 whitespace consists of any of the following characters:
//	**
//	**    Unicode  UTF-8         Name
//	**    U+0009   09            horizontal tab
//	**    U+000a   0a            line feed
//	**    U+000b   0b            vertical tab
//	**    U+000c   0c            form feed
//	**    U+000d   0d            carriage return
//	**    U+0020   20            space
//	**    U+00a0   c2 a0         non-breaking space
//	**    U+1680   e1 9a 80      ogham space mark
//	**    U+2000   e2 80 80      en quad
//	**    U+2001   e2 80 81      em quad
//	**    U+2002   e2 80 82      en space
//	**    U+2003   e2 80 83      em space
//	**    U+2004   e2 80 84      three-per-em space
//	**    U+2005   e2 80 85      four-per-em space
//	**    U+2006   e2 80 86      six-per-em space
//	**    U+2007   e2 80 87      figure space
//	**    U+2008   e2 80 88      punctuation space
//	**    U+2009   e2 80 89      thin space
//	**    U+200a   e2 80 8a      hair space
//	**    U+2028   e2 80 a8      line separator
//	**    U+2029   e2 80 a9      paragraph separator
//	**    U+202f   e2 80 af      narrow no-break space (NNBSP)
//	**    U+205f   e2 81 9f      medium mathematical space (MMSP)
//	**    U+3000   e3 80 80      ideographical space
//	**    U+FEFF   ef bb bf      byte order mark
//	**
//	** In addition, comments between '/', '*' and '*', '/' and
//	** from '/', '/' to end-of-line are also considered to be whitespace.
//	*/
func _json5Whitespace(tls *libc.TLS, zIn uintptr) (r int32) {
	var c, v3 int8
	var c1 Tu8
	var j, j1, n int32
	var z uintptr
	_, _, _, _, _, _, _ = c, c1, j, j1, n, z, v3
	n = 0
	z = zIn
	for int32(1) != 0 {
		switch int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n)))) {
		case int32(0x09):
			fallthrough
		case int32(0x0a):
			fallthrough
		case int32(0x0b):
			fallthrough
		case int32(0x0c):
			fallthrough
		case int32(0x0d):
			fallthrough
		case int32(0x20):
			n++
		case int32('/'):
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32('*') && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(2))))) != 0 {
				j = n + int32(3)
				for {
					if !(int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) != int32('/') || int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j-int32(1))))) != int32('*')) {
						break
					}
					if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == 0 {
						goto whitespace_done
					}
					goto _1
				_1:
					;
					j++
				}
				n = j + int32(1)
				break
			} else {
				if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32('/') {
					j1 = n + int32(2)
					for {
						v3 = int8(*(*Tu8)(unsafe.Pointer(z + uintptr(j1))))
						c = v3
						if !(int32(v3) != 0) {
							break
						}
						if int32(int32(c)) == int32('\n') || int32(int32(c)) == int32('\r') {
							break
						}
						if int32(0xe2) == int32(uint8(uint8(c))) && int32(0x80) == int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j1+int32(1))))) && (int32(0xa8) == int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j1+int32(2))))) || int32(0xa9) == int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j1+int32(2)))))) {
							j1 += int32(2)
							break
						}
						goto _2
					_2:
						;
						j1++
					}
					n = j1
					if *(*Tu8)(unsafe.Pointer(z + uintptr(n))) != 0 {
						n++
					}
					break
				}
			}
			goto whitespace_done
		case int32(0xc2):
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32(0xa0) {
				n += int32(2)
				break
			}
			goto whitespace_done
		case int32(0xe1):
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32(0x9a) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(2))))) == int32(0x80) {
				n += int32(3)
				break
			}
			goto whitespace_done
		case int32(0xe2):
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32(0x80) {
				c1 = *(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(2))))
				if int32(int32(c1)) < int32(0x80) {
					goto whitespace_done
				}
				if int32(int32(c1)) <= int32(0x8a) || int32(int32(c1)) == int32(0xa8) || int32(int32(c1)) == int32(0xa9) || int32(int32(c1)) == int32(0xaf) {
					n += int32(3)
					break
				}
			} else {
				if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32(0x81) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(2))))) == int32(0x9f) {
					n += int32(3)
					break
				}
			}
			goto whitespace_done
		case int32(0xe3):
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32(0x80) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(2))))) == int32(0x80) {
				n += int32(3)
				break
			}
			goto whitespace_done
		case int32(0xef):
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(1))))) == int32(0xbb) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(n+int32(2))))) == int32(0xbf) {
				n += int32(3)
				break
			}
			goto whitespace_done
		default:
			goto whitespace_done
		}
	}
	goto whitespace_done
whitespace_done:
	;
	return n
	return r
}

// C documentation
//
//	/*
//	** Extra floating-point literals to allow in JSON.
//	*/
type TNanInfName = struct {
	Fc1     int8
	Fc2     int8
	Fn      int8
	FeType  int8
	FnRepl  int8
	FzMatch uintptr
	FzRepl  uintptr
}

type NanInfName = TNanInfName

// C documentation
//
//	/*
//	** Extra floating-point literals to allow in JSON.
//	*/
var _aNanInfName = [5]TNanInfName{
	0: {
		Fc1:     int8('i'),
		Fc2:     int8('I'),
		Fn:      int8(3),
		FeType:  int8(JSONB_FLOAT),
		FnRepl:  int8(7),
		FzMatch: __ccgo_ts + 26407,
		FzRepl:  __ccgo_ts + 26411,
	},
	1: {
		Fc1:     int8('i'),
		Fc2:     int8('I'),
		Fn:      int8(8),
		FeType:  int8(JSONB_FLOAT),
		FnRepl:  int8(7),
		FzMatch: __ccgo_ts + 26419,
		FzRepl:  __ccgo_ts + 26411,
	},
	2: {
		Fc1:     int8('n'),
		Fc2:     int8('N'),
		Fn:      int8(3),
		FnRepl:  int8(4),
		FzMatch: __ccgo_ts + 1663,
		FzRepl:  __ccgo_ts + 1658,
	},
	3: {
		Fc1:     int8('q'),
		Fc2:     int8('Q'),
		Fn:      int8(4),
		FnRepl:  int8(4),
		FzMatch: __ccgo_ts + 26428,
		FzRepl:  __ccgo_ts + 1658,
	},
	4: {
		Fc1:     int8('s'),
		Fc2:     int8('S'),
		Fn:      int8(4),
		FnRepl:  int8(4),
		FzMatch: __ccgo_ts + 26433,
		FzRepl:  __ccgo_ts + 1658,
	},
}

// C documentation
//
//	/*
//	** Report the wrong number of arguments for json_insert(), json_replace()
//	** or json_set().
//	*/
func _jsonWrongNumArgs(tls *libc.TLS, pCtx uintptr, zFuncName uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var zMsg uintptr
	_ = zMsg
	zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26438, libc.VaList(bp+8, zFuncName))
	Xsqlite3_result_error(tls, pCtx, zMsg, -int32(1))
	Xsqlite3_free(tls, zMsg)
}

/****************************************************************************
** Utility routines for dealing with the binary BLOB representation of JSON
****************************************************************************/

// C documentation
//
//	/*
//	** Expand pParse->aBlob so that it holds at least N bytes.
//	**
//	** Return the number of errors.
//	*/
func _jsonBlobExpand(tls *libc.TLS, pParse uintptr, N Tu32) (r int32) {
	var aNew uintptr
	var t Tu32
	_, _ = aNew, t
	if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc == uint32(0) {
		t = uint32(100)
	} else {
		t = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc * uint32(2)
	}
	if t < N {
		t = N + uint32(100)
	}
	aNew = _sqlite3DbRealloc(tls, (*TJsonParse)(unsafe.Pointer(pParse)).Fdb, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob, uint64(uint64(t)))
	if aNew == uintptr(0) {
		(*TJsonParse)(unsafe.Pointer(pParse)).Foom = uint8(1)
		return int32(1)
	}
	(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = aNew
	(*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc = t
	return 0
}

// C documentation
//
//	/*
//	** If pParse->aBlob is not previously editable (because it is taken
//	** from sqlite3_value_blob(), as indicated by the fact that
//	** pParse->nBlobAlloc==0 and pParse->nBlob>0) then make it editable
//	** by making a copy into space obtained from malloc.
//	**
//	** Return true on success.  Return false on OOM.
//	*/
func _jsonBlobMakeEditable(tls *libc.TLS, pParse uintptr, nExtra Tu32) (r int32) {
	var aOld uintptr
	var nSize Tu32
	_, _ = aOld, nSize
	if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		return 0
	}
	if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc > uint32(0) {
		return int32(1)
	}
	aOld = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob
	nSize = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + nExtra
	(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = uintptr(0)
	if _jsonBlobExpand(tls, pParse, nSize) != 0 {
		return 0
	}
	libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob, aOld, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)
	return int32(1)
}

// C documentation
//
//	/* Expand pParse->aBlob and append one bytes.
//	*/
func _jsonBlobExpandAndAppendOneByte(tls *libc.TLS, pParse uintptr, c Tu8) {
	var v1 Tu32
	var v2 uintptr
	_, _ = v1, v2
	_jsonBlobExpand(tls, pParse, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob+uint32(1))
	if int32((*TJsonParse)(unsafe.Pointer(pParse)).Foom) == 0 {
		v2 = pParse + 4
		v1 = *(*Tu32)(unsafe.Pointer(v2))
		*(*Tu32)(unsafe.Pointer(v2))++
		*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(v1))) = c
	}
}

// C documentation
//
//	/* Append a single character.
//	*/
func _jsonBlobAppendOneByte(tls *libc.TLS, pParse uintptr, c Tu8) {
	var v1 Tu32
	var v2 uintptr
	_, _ = v1, v2
	if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob >= (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc {
		_jsonBlobExpandAndAppendOneByte(tls, pParse, c)
	} else {
		v2 = pParse + 4
		v1 = *(*Tu32)(unsafe.Pointer(v2))
		*(*Tu32)(unsafe.Pointer(v2))++
		*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(v1))) = c
	}
}

func _jsonBlobExpandAndAppendNode(tls *libc.TLS, pParse uintptr, eType Tu8, szPayload Tu32, aPayload uintptr) {
	if _jsonBlobExpand(tls, pParse, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob+szPayload+uint32(9)) != 0 {
		return
	}
	_jsonBlobAppendNode(tls, pParse, eType, szPayload, aPayload)
}

// C documentation
//
//	/* Append an node type byte together with the payload size and
//	** possibly also the payload.
//	**
//	** If aPayload is not NULL, then it is a pointer to the payload which
//	** is also appended.  If aPayload is NULL, the pParse->aBlob[] array
//	** is resized (if necessary) so that it is big enough to hold the
//	** payload, but the payload is not appended and pParse->nBlob is left
//	** pointing to where the first byte of payload will eventually be.
//	*/
func _jsonBlobAppendNode(tls *libc.TLS, pParse uintptr, eType Tu8, szPayload Tu32, aPayload uintptr) {
	var a uintptr
	_ = a
	if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob+szPayload+uint32(9) > (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc {
		_jsonBlobExpandAndAppendNode(tls, pParse, eType, szPayload, aPayload)
		return
	}
	a = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)
	if szPayload <= uint32(11) {
		*(*Tu8)(unsafe.Pointer(a)) = uint8(uint32(uint32(eType)) | szPayload<<libc.Int32FromInt32(4))
		*(*Tu32)(unsafe.Pointer(pParse + 4)) += uint32(1)
	} else {
		if szPayload <= uint32(0xff) {
			*(*Tu8)(unsafe.Pointer(a)) = uint8(int32(int32(eType)) | int32(0xc0))
			*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(szPayload & uint32(0xff))
			*(*Tu32)(unsafe.Pointer(pParse + 4)) += uint32(2)
		} else {
			if szPayload <= uint32(0xffff) {
				*(*Tu8)(unsafe.Pointer(a)) = uint8(int32(int32(eType)) | int32(0xd0))
				*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(szPayload >> libc.Int32FromInt32(8) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 2)) = uint8(szPayload & uint32(0xff))
				*(*Tu32)(unsafe.Pointer(pParse + 4)) += uint32(3)
			} else {
				*(*Tu8)(unsafe.Pointer(a)) = uint8(int32(int32(eType)) | int32(0xe0))
				*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(szPayload >> libc.Int32FromInt32(24) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 2)) = uint8(szPayload >> libc.Int32FromInt32(16) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 3)) = uint8(szPayload >> libc.Int32FromInt32(8) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 4)) = uint8(szPayload & uint32(0xff))
				*(*Tu32)(unsafe.Pointer(pParse + 4)) += uint32(5)
			}
		}
	}
	if aPayload != 0 {
		*(*Tu32)(unsafe.Pointer(pParse + 4)) += szPayload
		libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-szPayload), aPayload, szPayload)
	}
}

// C documentation
//
//	/* Change the payload size for the node at index i to be szPayload.
//	*/
func _jsonBlobChangePayloadSize(tls *libc.TLS, pParse uintptr, i Tu32, szPayload Tu32) (r int32) {
	var a uintptr
	var delta int32
	var nExtra, nNeeded, szType Tu8
	var newSize Tu32
	_, _, _, _, _, _ = a, delta, nExtra, nNeeded, newSize, szType
	if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		return 0
	}
	a = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)
	szType = uint8(int32(*(*Tu8)(unsafe.Pointer(a))) >> int32(4))
	if int32(int32(szType)) <= int32(11) {
		nExtra = uint8(0)
	} else {
		if int32(int32(szType)) == int32(12) {
			nExtra = uint8(1)
		} else {
			if int32(int32(szType)) == int32(13) {
				nExtra = uint8(2)
			} else {
				nExtra = uint8(4)
			}
		}
	}
	if szPayload <= uint32(11) {
		nNeeded = uint8(0)
	} else {
		if szPayload <= uint32(0xff) {
			nNeeded = uint8(1)
		} else {
			if szPayload <= uint32(0xffff) {
				nNeeded = uint8(2)
			} else {
				nNeeded = uint8(4)
			}
		}
	}
	delta = int32(int32(nNeeded)) - int32(int32(nExtra))
	if delta != 0 {
		newSize = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + uint32(uint32(delta))
		if delta > 0 {
			if newSize > (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc && _jsonBlobExpand(tls, pParse, newSize) != 0 {
				return 0 /* OOM error.  Error state recorded in pParse->oom. */
			}
			a = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)
			libc.Xmemmove(tls, a+uintptr(int32(1)+delta), a+1, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-(i+uint32(1)))
		} else {
			libc.Xmemmove(tls, a+1, a+uintptr(int32(1)-delta), (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-(i+uint32(1)-uint32(uint32(delta))))
		}
		(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = newSize
	}
	if int32(int32(nNeeded)) == 0 {
		*(*Tu8)(unsafe.Pointer(a)) = uint8(uint32(int32(*(*Tu8)(unsafe.Pointer(a)))&libc.Int32FromInt32(0x0f)) | szPayload<<libc.Int32FromInt32(4))
	} else {
		if int32(int32(nNeeded)) == int32(1) {
			*(*Tu8)(unsafe.Pointer(a)) = uint8(int32(*(*Tu8)(unsafe.Pointer(a)))&int32(0x0f) | int32(0xc0))
			*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(szPayload & uint32(0xff))
		} else {
			if int32(int32(nNeeded)) == int32(2) {
				*(*Tu8)(unsafe.Pointer(a)) = uint8(int32(*(*Tu8)(unsafe.Pointer(a)))&int32(0x0f) | int32(0xd0))
				*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(szPayload >> libc.Int32FromInt32(8) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 2)) = uint8(szPayload & uint32(0xff))
			} else {
				*(*Tu8)(unsafe.Pointer(a)) = uint8(int32(*(*Tu8)(unsafe.Pointer(a)))&int32(0x0f) | int32(0xe0))
				*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(szPayload >> libc.Int32FromInt32(24) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 2)) = uint8(szPayload >> libc.Int32FromInt32(16) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 3)) = uint8(szPayload >> libc.Int32FromInt32(8) & uint32(0xff))
				*(*Tu8)(unsafe.Pointer(a + 4)) = uint8(szPayload & uint32(0xff))
			}
		}
	}
	return delta
}

// C documentation
//
//	/*
//	** If z[0] is 'u' and is followed by exactly 4 hexadecimal character,
//	** then set *pOp to JSONB_TEXTJ and return true.  If not, do not make
//	** any changes to *pOp and return false.
//	*/
func _jsonIs4HexB(tls *libc.TLS, z uintptr, pOp uintptr) (r int32) {
	if int32(*(*int8)(unsafe.Pointer(z))) != int32('u') {
		return 0
	}
	if !(_jsonIs4Hex(tls, z+1) != 0) {
		return 0
	}
	*(*int32)(unsafe.Pointer(pOp)) = int32(JSONB_TEXTJ)
	return int32(1)
}

// C documentation
//
//	/*
//	** Check a single element of the JSONB in pParse for validity.
//	**
//	** The element to be checked starts at offset i and must end at on the
//	** last byte before iEnd.
//	**
//	** Return 0 if everything is correct.  Return the 1-based byte offset of the
//	** error if a problem is detected.  (In other words, if the error is at offset
//	** 0, return 1).
//	*/
func _jsonbValidityCheck(tls *libc.TLS, pParse uintptr, i Tu32, iEnd Tu32, iDepth Tu32) (r Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var cnt, j, k, n, sub, sub1, szC Tu32
	var seen, x Tu8
	var z uintptr
	var v1 uint32
	var _ /* c at bp+4 */ Tu32
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _ = cnt, j, k, n, seen, sub, sub1, szC, x, z, v1
	if iDepth > uint32(JSON_MAX_DEPTH) {
		return i + uint32(1)
	}
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
	n = _jsonbPayloadSize(tls, pParse, i, bp)
	if n == uint32(0) {
		return i + uint32(1)
	} /* Checked by caller */
	if i+n+*(*Tu32)(unsafe.Pointer(bp)) != iEnd {
		return i + uint32(1)
	} /* Checked by caller */
	z = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob
	x = uint8(int32(*(*Tu8)(unsafe.Pointer(z + uintptr(i)))) & int32(0x0f))
	switch int32(int32(x)) {
	case JSONB_NULL:
		fallthrough
	case int32(JSONB_TRUE):
		fallthrough
	case int32(JSONB_FALSE):
		if n+*(*Tu32)(unsafe.Pointer(bp)) == uint32(1) {
			v1 = uint32(0)
		} else {
			v1 = i + uint32(1)
		}
		return v1
	case int32(JSONB_INT):
		if *(*Tu32)(unsafe.Pointer(bp)) < uint32(1) {
			return i + uint32(1)
		}
		j = i + n
		if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('-') {
			j++
			if *(*Tu32)(unsafe.Pointer(bp)) < uint32(2) {
				return i + uint32(1)
			}
		}
		k = i + n + *(*Tu32)(unsafe.Pointer(bp))
		for j < k {
			if int32(_sqlite3CtypeMap[*(*Tu8)(unsafe.Pointer(z + uintptr(j)))])&int32(0x04) != 0 {
				j++
			} else {
				return j + uint32(1)
			}
		}
		return uint32(0)
	case int32(JSONB_INT5):
		if *(*Tu32)(unsafe.Pointer(bp)) < uint32(3) {
			return i + uint32(1)
		}
		j = i + n
		if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('-') {
			if *(*Tu32)(unsafe.Pointer(bp)) < uint32(4) {
				return i + uint32(1)
			}
			j++
		}
		if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) != int32('0') {
			return i + uint32(1)
		}
		if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) != int32('x') && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) != int32('X') {
			return j + uint32(2)
		}
		j += uint32(2)
		k = i + n + *(*Tu32)(unsafe.Pointer(bp))
		for j < k {
			if int32(_sqlite3CtypeMap[*(*Tu8)(unsafe.Pointer(z + uintptr(j)))])&int32(0x08) != 0 {
				j++
			} else {
				return j + uint32(1)
			}
		}
		return uint32(0)
	case int32(JSONB_FLOAT):
		fallthrough
	case int32(JSONB_FLOAT5):
		seen = uint8(0) /* 0: initial.  1: '.' seen  2: 'e' seen */
		if *(*Tu32)(unsafe.Pointer(bp)) < uint32(2) {
			return i + uint32(1)
		}
		j = i + n
		k = j + *(*Tu32)(unsafe.Pointer(bp))
		if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('-') {
			j++
			if *(*Tu32)(unsafe.Pointer(bp)) < uint32(3) {
				return i + uint32(1)
			}
		}
		if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('.') {
			if int32(int32(x)) == int32(JSONB_FLOAT) {
				return j + uint32(1)
			}
			if !(int32(_sqlite3CtypeMap[*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))])&libc.Int32FromInt32(0x04) != 0) {
				return j + uint32(1)
			}
			j += uint32(2)
			seen = uint8(1)
		} else {
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('0') && int32(int32(x)) == int32(JSONB_FLOAT) {
				if j+uint32(3) > k {
					return j + uint32(1)
				}
				if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) != int32('.') && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) != int32('e') && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) != int32('E') {
					return j + uint32(1)
				}
				j++
			}
		}
		for {
			if !(j < k) {
				break
			}
			if int32(_sqlite3CtypeMap[*(*Tu8)(unsafe.Pointer(z + uintptr(j)))])&int32(0x04) != 0 {
				goto _2
			}
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('.') {
				if int32(int32(seen)) > 0 {
					return j + uint32(1)
				}
				if int32(int32(x)) == int32(JSONB_FLOAT) && (j == k-uint32(1) || !(int32(_sqlite3CtypeMap[*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))])&libc.Int32FromInt32(0x04) != 0)) {
					return j + uint32(1)
				}
				seen = uint8(1)
				goto _2
			}
			if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('e') || int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('E') {
				if int32(int32(seen)) == int32(2) {
					return j + uint32(1)
				}
				if j == k-uint32(1) {
					return j + uint32(1)
				}
				if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) == int32('+') || int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) == int32('-') {
					j++
					if j == k-uint32(1) {
						return j + uint32(1)
					}
				}
				seen = uint8(2)
				goto _2
			}
			return j + uint32(1)
			goto _2
		_2:
			;
			j++
		}
		if int32(int32(seen)) == 0 {
			return i + uint32(1)
		}
		return uint32(0)
	case int32(JSONB_TEXT):
		j = i + n
		k = j + *(*Tu32)(unsafe.Pointer(bp))
		for j < k {
			if !(_jsonIsOk[*(*Tu8)(unsafe.Pointer(z + uintptr(j)))] != 0) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) != int32('\'') {
				return j + uint32(1)
			}
			j++
		}
		return uint32(0)
	case int32(JSONB_TEXTJ):
		fallthrough
	case int32(JSONB_TEXT5):
		j = i + n
		k = j + *(*Tu32)(unsafe.Pointer(bp))
		for j < k {
			if !(_jsonIsOk[*(*Tu8)(unsafe.Pointer(z + uintptr(j)))] != 0) && int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) != int32('\'') {
				if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) == int32('"') {
					if int32(int32(x)) == int32(JSONB_TEXTJ) {
						return j + uint32(1)
					}
				} else {
					if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) <= int32(0x1f) {
						/* Control characters in JSON5 string literals are ok */
						if int32(int32(x)) == int32(JSONB_TEXTJ) {
							return j + uint32(1)
						}
					} else {
						if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) != int32('\\') || j+uint32(1) >= k {
							return j + uint32(1)
						} else {
							if libc.Xstrchr(tls, __ccgo_ts+26481, int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1)))))) != uintptr(0) {
								j++
							} else {
								if int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) == int32('u') {
									if j+uint32(5) >= k {
										return j + uint32(1)
									}
									if !(_jsonIs4Hex(tls, z+uintptr(j+uint32(2))) != 0) {
										return j + uint32(1)
									}
									j++
								} else {
									if int32(int32(x)) != int32(JSONB_TEXT5) {
										return j + uint32(1)
									} else {
										*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0)
										szC = _jsonUnescapeOneChar(tls, z+uintptr(j), k-j, bp+4)
										if *(*Tu32)(unsafe.Pointer(bp + 4)) == uint32(JSON_INVALID_CHAR) {
											return j + uint32(1)
										}
										j += szC - uint32(1)
									}
								}
							}
						}
					}
				}
			}
			j++
		}
		return uint32(0)
	case int32(JSONB_TEXTRAW):
		return uint32(0)
	case int32(JSONB_ARRAY):
		j = i + n
		k = j + *(*Tu32)(unsafe.Pointer(bp))
		for j < k {
			*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
			n = _jsonbPayloadSize(tls, pParse, j, bp)
			if n == uint32(0) {
				return j + uint32(1)
			}
			if j+n+*(*Tu32)(unsafe.Pointer(bp)) > k {
				return j + uint32(1)
			}
			sub = _jsonbValidityCheck(tls, pParse, j, j+n+*(*Tu32)(unsafe.Pointer(bp)), iDepth+uint32(1))
			if sub != 0 {
				return sub
			}
			j += n + *(*Tu32)(unsafe.Pointer(bp))
		}
		return uint32(0)
	case int32(JSONB_OBJECT):
		cnt = uint32(0)
		j = i + n
		k = j + *(*Tu32)(unsafe.Pointer(bp))
		for j < k {
			*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
			n = _jsonbPayloadSize(tls, pParse, j, bp)
			if n == uint32(0) {
				return j + uint32(1)
			}
			if j+n+*(*Tu32)(unsafe.Pointer(bp)) > k {
				return j + uint32(1)
			}
			if cnt&uint32(1) == uint32(0) {
				x = uint8(int32(*(*Tu8)(unsafe.Pointer(z + uintptr(j)))) & int32(0x0f))
				if int32(int32(x)) < int32(JSONB_TEXT) || int32(int32(x)) > int32(JSONB_TEXTRAW) {
					return j + uint32(1)
				}
			}
			sub1 = _jsonbValidityCheck(tls, pParse, j, j+n+*(*Tu32)(unsafe.Pointer(bp)), iDepth+uint32(1))
			if sub1 != 0 {
				return sub1
			}
			cnt++
			j += n + *(*Tu32)(unsafe.Pointer(bp))
		}
		if cnt&uint32(1) != uint32(0) {
			return j + uint32(1)
		}
		return uint32(0)
	default:
		return i + uint32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Translate a single element of JSON text at pParse->zJson[i] into
//	** its equivalent binary JSONB representation.  Append the translation into
//	** pParse->aBlob[] beginning at pParse->nBlob.  The size of
//	** pParse->aBlob[] is increased as necessary.
//	**
//	** Return the index of the first character past the end of the element parsed,
//	** or one of the following special result codes:
//	**
//	**      0    End of input
//	**     -1    Syntax error or OOM
//	**     -2    '}' seen   **     -3    ']' seen    \___  For these returns, pParse->iErr is set to
//	**     -4    ',' seen    /     the index in zJson[] of the seen character
//	**     -5    ':' seen   /
//	*/
func _jsonTranslateTextToBlob(tls *libc.TLS, pParse uintptr, i Tu32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c, cDelim int8
	var iBlob, iStart, iThis, j, k1, v46 Tu32
	var k, nn, x, v48 int32
	var opcode, seenE, t Tu8
	var z, v41, v44 uintptr
	var v40, v43 Tu16
	var _ /* op at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, cDelim, iBlob, iStart, iThis, j, k, k1, nn, opcode, seenE, t, x, z, v40, v41, v43, v44, v46, v48
	z = (*TJsonParse)(unsafe.Pointer(pParse)).FzJson
	goto json_parse_restart
json_parse_restart:
	;
	switch int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(i))))) {
	case int32('{'):
		goto _1
	case int32('['):
		goto _2
	case int32('"'):
		goto _3
	case int32('\''):
		goto _4
	case int32('t'):
		goto _5
	case int32('f'):
		goto _6
	case int32('.'):
		goto _7
	case int32('9'):
		goto _8
	case int32('8'):
		goto _9
	case int32('7'):
		goto _10
	case int32('6'):
		goto _11
	case int32('5'):
		goto _12
	case int32('4'):
		goto _13
	case int32('3'):
		goto _14
	case int32('2'):
		goto _15
	case int32('1'):
		goto _16
	case int32('0'):
		goto _17
	case int32('-'):
		goto _18
	case int32('+'):
		goto _19
	case int32('}'):
		goto _20
	case int32(']'):
		goto _21
	case int32(','):
		goto _22
	case int32(':'):
		goto _23
	case 0:
		goto _24
	case int32(0x20):
		goto _25
	case int32(0x0d):
		goto _26
	case int32(0x0a):
		goto _27
	case int32(0x09):
		goto _28
	case int32(0xef):
		goto _29
	case int32(0xe3):
		goto _30
	case int32(0xe2):
		goto _31
	case int32(0xe1):
		goto _32
	case int32(0xc2):
		goto _33
	case int32('/'):
		goto _34
	case int32(0x0c):
		goto _35
	case int32(0x0b):
		goto _36
	case int32('n'):
		goto _37
	default:
		goto _38
	}
	goto _39
_1:
	;
	/* Parse object */
	iThis = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
	_jsonBlobAppendNode(tls, pParse, uint8(JSONB_OBJECT), uint32((*TJsonParse)(unsafe.Pointer(pParse)).FnJson)-i, uintptr(0))
	v41 = pParse + 32
	*(*Tu16)(unsafe.Pointer(v41))++
	v40 = *(*Tu16)(unsafe.Pointer(v41))
	if int32(v40) > int32(JSON_MAX_DEPTH) {
		(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
		return -int32(1)
	}
	iStart = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
	j = i + uint32(1)
	for {
		iBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
		x = _jsonTranslateTextToBlob(tls, pParse, j)
		if x <= 0 {
			if x == -int32(2) {
				j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
				if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob != iStart {
					(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
				}
				break
			}
			j += uint32(_json5Whitespace(tls, z+uintptr(j)))
			*(*int32)(unsafe.Pointer(bp)) = int32(JSONB_TEXT)
			if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))])&int32(0x42) != 0 || int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32('\\') && _jsonIs4HexB(tls, z+uintptr(j+uint32(1)), bp) != 0 {
				k = int32(j + uint32(1))
				for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(k))))])&int32(0x46) != 0 && _json5Whitespace(tls, z+uintptr(k)) == 0 || int32(*(*int8)(unsafe.Pointer(z + uintptr(k)))) == int32('\\') && _jsonIs4HexB(tls, z+uintptr(k+int32(1)), bp) != 0 {
					k++
				}
				_jsonBlobAppendNode(tls, pParse, uint8(*(*int32)(unsafe.Pointer(bp))), uint32(uint32(k))-j, z+uintptr(j))
				(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
				x = k
			} else {
				if x != -int32(1) {
					(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
				}
				return -int32(1)
			}
		}
		if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
			return -int32(1)
		}
		t = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(iBlob)))) & int32(0x0f))
		if int32(int32(t)) < int32(JSONB_TEXT) || int32(int32(t)) > int32(JSONB_TEXTRAW) {
			(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
			return -int32(1)
		}
		j = uint32(uint32(x))
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(':') {
			j++
		} else {
			if _jsonIsSpace[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))] != 0 {
				/* strspn() is not helpful here */
				for cond := true; cond; cond = _jsonIsSpace[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))] != 0 {
					j++
				}
				if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(':') {
					j++
					goto parse_object_value
				}
			}
			x = _jsonTranslateTextToBlob(tls, pParse, j)
			if x != -int32(5) {
				if x != -int32(1) {
					(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
				}
				return -int32(1)
			}
			j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr + uint32(1)
		}
		goto parse_object_value
	parse_object_value:
		;
		x = _jsonTranslateTextToBlob(tls, pParse, j)
		if x <= 0 {
			if x != -int32(1) {
				(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
			}
			return -int32(1)
		}
		j = uint32(uint32(x))
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(',') {
			goto _42
		} else {
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32('}') {
				break
			} else {
				if _jsonIsSpace[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))] != 0 {
					j += uint32(1) + libc.Xstrspn(tls, z+uintptr(j+uint32(1)), uintptr(unsafe.Pointer(&_jsonSpaces)))
					if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(',') {
						goto _42
					} else {
						if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32('}') {
							break
						}
					}
				}
				x = _jsonTranslateTextToBlob(tls, pParse, j)
				if x == -int32(4) {
					j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
					goto _42
				}
				if x == -int32(2) {
					j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
					break
				}
			}
		}
		(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
		return -int32(1)
		goto _42
	_42:
		;
		j++
	}
	_jsonBlobChangePayloadSize(tls, pParse, iThis, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-iStart)
	(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth--
	return int32(j + uint32(1))
_2:
	;
	/* Parse array */
	iThis = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
	_jsonBlobAppendNode(tls, pParse, uint8(JSONB_ARRAY), uint32((*TJsonParse)(unsafe.Pointer(pParse)).FnJson)-i, uintptr(0))
	iStart = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
	if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		return -int32(1)
	}
	v44 = pParse + 32
	*(*Tu16)(unsafe.Pointer(v44))++
	v43 = *(*Tu16)(unsafe.Pointer(v44))
	if int32(v43) > int32(JSON_MAX_DEPTH) {
		(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
		return -int32(1)
	}
	j = i + uint32(1)
	for {
		x = _jsonTranslateTextToBlob(tls, pParse, j)
		if x <= 0 {
			if x == -int32(3) {
				j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
				if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob != iStart {
					(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
				}
				break
			}
			if x != -int32(1) {
				(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
			}
			return -int32(1)
		}
		j = uint32(uint32(x))
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(',') {
			goto _45
		} else {
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(']') {
				break
			} else {
				if _jsonIsSpace[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))] != 0 {
					j += uint32(1) + libc.Xstrspn(tls, z+uintptr(j+uint32(1)), uintptr(unsafe.Pointer(&_jsonSpaces)))
					if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(',') {
						goto _45
					} else {
						if int32(*(*int8)(unsafe.Pointer(z + uintptr(j)))) == int32(']') {
							break
						}
					}
				}
				x = _jsonTranslateTextToBlob(tls, pParse, j)
				if x == -int32(4) {
					j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
					goto _45
				}
				if x == -int32(3) {
					j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
					break
				}
			}
		}
		(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
		return -int32(1)
		goto _45
	_45:
		;
		j++
	}
	_jsonBlobChangePayloadSize(tls, pParse, iThis, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-iStart)
	(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth--
	return int32(j + uint32(1))
_4:
	;
	(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
	opcode = uint8(JSONB_TEXT)
	goto parse_string
_3:
	;
	/* Parse string */
	opcode = uint8(JSONB_TEXT)
	goto parse_string
parse_string:
	;
	cDelim = *(*int8)(unsafe.Pointer(z + uintptr(i)))
	j = i + uint32(1)
	for int32(1) != 0 {
		if _jsonIsOk[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))] != 0 {
			if !(_jsonIsOk[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j+uint32(1)))))] != 0) {
				j += uint32(1)
			} else {
				if !(_jsonIsOk[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j+uint32(2)))))] != 0) {
					j += uint32(2)
				} else {
					j += uint32(3)
					continue
				}
			}
		}
		c = *(*int8)(unsafe.Pointer(z + uintptr(j)))
		if int32(int32(c)) == int32(int32(cDelim)) {
			break
		} else {
			if int32(int32(c)) == int32('\\') {
				j++
				v46 = j
				c = *(*int8)(unsafe.Pointer(z + uintptr(v46)))
				if int32(int32(c)) == int32('"') || int32(int32(c)) == int32('\\') || int32(int32(c)) == int32('/') || int32(int32(c)) == int32('b') || int32(int32(c)) == int32('f') || int32(int32(c)) == int32('n') || int32(int32(c)) == int32('r') || int32(int32(c)) == int32('t') || int32(int32(c)) == int32('u') && _jsonIs4Hex(tls, z+uintptr(j+uint32(1))) != 0 {
					if int32(int32(opcode)) == int32(JSONB_TEXT) {
						opcode = uint8(JSONB_TEXTJ)
					}
				} else {
					if int32(int32(c)) == int32('\'') || int32(int32(c)) == int32('0') || int32(int32(c)) == int32('v') || int32(int32(c)) == int32('\n') || int32(0xe2) == int32(uint8(uint8(c))) && int32(0x80) == int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(j+uint32(1)))))) && (int32(0xa8) == int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(j+uint32(2)))))) || int32(0xa9) == int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(j+uint32(2))))))) || int32(int32(c)) == int32('x') && _jsonIs2Hex(tls, z+uintptr(j+uint32(1))) != 0 {
						opcode = uint8(JSONB_TEXT5)
						(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
					} else {
						if int32(int32(c)) == int32('\r') {
							if int32(*(*int8)(unsafe.Pointer(z + uintptr(j+uint32(1))))) == int32('\n') {
								j++
							}
							opcode = uint8(JSONB_TEXT5)
							(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
						} else {
							(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
							return -int32(1)
						}
					}
				}
			} else {
				if int32(int32(c)) <= int32(0x1f) {
					if int32(int32(c)) == 0 {
						(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
						return -int32(1)
					}
					/* Control characters are not allowed in canonical JSON string
					 ** literals, but are allowed in JSON5 string literals. */
					opcode = uint8(JSONB_TEXT5)
					(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
				} else {
					if int32(int32(c)) == int32('"') {
						opcode = uint8(JSONB_TEXT5)
					}
				}
			}
		}
		j++
	}
	_jsonBlobAppendNode(tls, pParse, opcode, j-uint32(1)-i, z+uintptr(i+uint32(1)))
	return int32(j + uint32(1))
_5:
	;
	if libc.Xstrncmp(tls, z+uintptr(i), __ccgo_ts+9320, uint32(4)) == 0 && !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(4)))))])&libc.Int32FromInt32(0x06) != 0) {
		_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_TRUE))
		return int32(i + uint32(4))
	}
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(1)
_6:
	;
	if libc.Xstrncmp(tls, z+uintptr(i), __ccgo_ts+9325, uint32(5)) == 0 && !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(5)))))])&libc.Int32FromInt32(0x06) != 0) {
		_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_FALSE))
		return int32(i + uint32(5))
	}
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(1)
_19:
	;
	(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
	t = uint8(0x00) /* Bit 0x01:  JSON5.   Bit 0x02:  FLOAT */
	goto parse_number
_7:
	;
	if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1)))))])&int32(0x04) != 0 {
		(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
		t = uint8(0x03) /* Bit 0x01:  JSON5.   Bit 0x02:  FLOAT */
		seenE = uint8(0)
		goto parse_number_2
	}
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(1)
_18:
	;
_17:
	;
_16:
	;
_15:
	;
_14:
	;
_13:
	;
_12:
	;
_11:
	;
_10:
	;
_9:
	;
_8:
	;
	/* Parse number */
	t = uint8(0x00) /* Bit 0x01:  JSON5.   Bit 0x02:  FLOAT */
	goto parse_number
parse_number:
	;
	seenE = uint8(0)
	c = *(*int8)(unsafe.Pointer(z + uintptr(i)))
	if int32(int32(c)) <= int32('0') {
		if int32(int32(c)) == int32('0') {
			if (int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('x') || int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('X')) && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(2)))))])&int32(0x08) != 0 {
				(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
				t = uint8(0x01)
				j = i + uint32(3)
				for {
					if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))])&int32(0x08) != 0) {
						break
					}
					goto _47
				_47:
					;
					j++
				}
				goto parse_number_finish
			} else {
				if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1)))))])&int32(0x04) != 0 {
					(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i + uint32(1)
					return -int32(1)
				}
			}
		} else {
			if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1)))))])&libc.Int32FromInt32(0x04) != 0) {
				/* JSON5 allows for "+Infinity" and "-Infinity" using exactly
				 ** that case.  SQLite also allows these in any case and it allows
				 ** "+inf" and "-inf". */
				if (int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('I') || int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('i')) && Xsqlite3_strnicmp(tls, z+uintptr(i+uint32(1)), __ccgo_ts+26407, int32(3)) == 0 {
					(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
					if int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) == int32('-') {
						_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint32(6), __ccgo_ts+26490)
					} else {
						_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint32(5), __ccgo_ts+26497)
					}
					if Xsqlite3_strnicmp(tls, z+uintptr(i+uint32(4)), __ccgo_ts+26503, int32(5)) == 0 {
						v48 = int32(9)
					} else {
						v48 = int32(4)
					}
					return int32(i + uint32(v48))
				}
				if int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('.') {
					(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
					t = Tu8(int32(t) | libc.Int32FromInt32(0x01))
					goto parse_number_2
				}
				(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
				return -int32(1)
			}
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('0') {
				if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(2)))))])&int32(0x04) != 0 {
					(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i + uint32(1)
					return -int32(1)
				} else {
					if (int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(2))))) == int32('x') || int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(2))))) == int32('X')) && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(3)))))])&int32(0x08) != 0 {
						(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
						t = Tu8(int32(t) | libc.Int32FromInt32(0x01))
						j = i + uint32(4)
						for {
							if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j))))])&int32(0x08) != 0) {
								break
							}
							goto _49
						_49:
							;
							j++
						}
						goto parse_number_finish
					}
				}
			}
		}
	}
	goto parse_number_2
parse_number_2:
	;
	j = i + uint32(1)
	for {
		c = *(*int8)(unsafe.Pointer(z + uintptr(j)))
		if int32(_sqlite3CtypeMap[uint8(c)])&int32(0x04) != 0 {
			goto _50
		}
		if int32(int32(c)) == int32('.') {
			if int32(int32(t))&int32(0x02) != 0 {
				(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
				return -int32(1)
			}
			t = Tu8(int32(t) | libc.Int32FromInt32(0x02))
			goto _50
		}
		if int32(int32(c)) == int32('e') || int32(int32(c)) == int32('E') {
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(j-uint32(1))))) < int32('0') {
				if int32(*(*int8)(unsafe.Pointer(z + uintptr(j-uint32(1))))) == int32('.') && j-uint32(2) >= i && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j-uint32(2)))))])&int32(0x04) != 0 {
					(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
					t = Tu8(int32(t) | libc.Int32FromInt32(0x01))
				} else {
					(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
					return -int32(1)
				}
			}
			if seenE != 0 {
				(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
				return -int32(1)
			}
			t = Tu8(int32(t) | libc.Int32FromInt32(0x02))
			seenE = uint8(1)
			c = *(*int8)(unsafe.Pointer(z + uintptr(j+uint32(1))))
			if int32(int32(c)) == int32('+') || int32(int32(c)) == int32('-') {
				j++
				c = *(*int8)(unsafe.Pointer(z + uintptr(j+uint32(1))))
			}
			if int32(int32(c)) < int32('0') || int32(int32(c)) > int32('9') {
				(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
				return -int32(1)
			}
			goto _50
		}
		break
		goto _50
	_50:
		;
		j++
	}
	if int32(*(*int8)(unsafe.Pointer(z + uintptr(j-uint32(1))))) < int32('0') {
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(j-uint32(1))))) == int32('.') && j-uint32(2) >= i && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(j-uint32(2)))))])&int32(0x04) != 0 {
			(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
			t = Tu8(int32(t) | libc.Int32FromInt32(0x01))
		} else {
			(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
			return -int32(1)
		}
	}
	goto parse_number_finish
parse_number_finish:
	;
	if int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) == int32('+') {
		i++
	}
	_jsonBlobAppendNode(tls, pParse, uint8(int32(JSONB_INT)+int32(int32(t))), j-i, z+uintptr(i))
	return int32(int32(j))
_20:
	;
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(2) /* End of {...} */
_21:
	;
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(3) /* End of [...] */
_22:
	;
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(4) /* List separator */
_23:
	;
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(5) /* Object label/value separator */
_24:
	;
	return 0 /* End of file */
_28:
	;
_27:
	;
_26:
	;
_25:
	;
	i += uint32(1) + libc.Xstrspn(tls, z+uintptr(i+uint32(1)), uintptr(unsafe.Pointer(&_jsonSpaces)))
	goto json_parse_restart
_36:
	;
_35:
	;
_34:
	;
_33:
	;
_32:
	;
_31:
	;
_30:
	;
_29:
	;
	j = uint32(_json5Whitespace(tls, z+uintptr(i)))
	if j > uint32(0) {
		i += j
		(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
		goto json_parse_restart
	}
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(1)
_37:
	;
	if libc.Xstrncmp(tls, z+uintptr(i), __ccgo_ts+1658, uint32(4)) == 0 && !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(4)))))])&libc.Int32FromInt32(0x06) != 0) {
		_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_NULL))
		return int32(i + uint32(4))
	}
_38:
	;
	c = *(*int8)(unsafe.Pointer(z + uintptr(i)))
	k1 = uint32(0)
	for {
		if !(k1 < libc.Uint32FromInt64(80)/libc.Uint32FromInt64(16)) {
			break
		}
		if int32(int32(c)) != int32(_aNanInfName[k1].Fc1) && int32(int32(c)) != int32(_aNanInfName[k1].Fc2) {
			goto _51
		}
		nn = int32(_aNanInfName[k1].Fn)
		if Xsqlite3_strnicmp(tls, z+uintptr(i), _aNanInfName[k1].FzMatch, nn) != 0 {
			goto _51
		}
		if int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(uint32(nn))))))])&int32(0x06) != 0 {
			goto _51
		}
		if int32(_aNanInfName[k1].FeType) == int32(JSONB_FLOAT) {
			_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint32(5), __ccgo_ts+26497)
		} else {
			_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_NULL))
		}
		(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
		return int32(i + uint32(uint32(nn)))
		goto _51
	_51:
		;
		k1++
	}
	(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
	return -int32(1) /* Syntax error */
_39:
	; /* End switch(z[i]) */
	return r
}

// C documentation
//
//	/*
//	** Parse a complete JSON string.  Return 0 on success or non-zero if there
//	** are any errors.  If an error occurs, free all memory held by pParse,
//	** but not pParse itself.
//	**
//	** pParse must be initialized to an empty parse object prior to calling
//	** this routine.
//	*/
func _jsonConvertTextToBlob(tls *libc.TLS, pParse uintptr, pCtx uintptr) (r int32) {
	var i int32
	var zJson uintptr
	_, _ = i, zJson
	zJson = (*TJsonParse)(unsafe.Pointer(pParse)).FzJson
	i = _jsonTranslateTextToBlob(tls, pParse, uint32(0))
	if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		i = -int32(1)
	}
	if i > 0 {
		for _jsonIsSpace[uint8(*(*int8)(unsafe.Pointer(zJson + uintptr(i))))] != 0 {
			i++
		}
		if *(*int8)(unsafe.Pointer(zJson + uintptr(i))) != 0 {
			i += _json5Whitespace(tls, zJson+uintptr(i))
			if *(*int8)(unsafe.Pointer(zJson + uintptr(i))) != 0 {
				if pCtx != 0 {
					Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26392, -int32(1))
				}
				_jsonParseReset(tls, pParse)
				return int32(1)
			}
			(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
		}
	}
	if i <= 0 {
		if pCtx != uintptr(0) {
			if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
				Xsqlite3_result_error_nomem(tls, pCtx)
			} else {
				Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26392, -int32(1))
			}
		}
		_jsonParseReset(tls, pParse)
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** The input string pStr is a well-formed JSON text string.  Convert
//	** this into the JSONB format and make it the return value of the
//	** SQL function.
//	*/
func _jsonReturnStringAsBlob(tls *libc.TLS, pStr uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var _ /* px at bp+0 */ TJsonParse
	libc.Xmemset(tls, bp, 0, uint32(56))
	_jsonStringTerminate(tls, pStr)
	if (*TJsonString)(unsafe.Pointer(pStr)).FeErr != 0 {
		Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(pStr)).FpCtx)
		return
	}
	(*(*TJsonParse)(unsafe.Pointer(bp))).FzJson = (*TJsonString)(unsafe.Pointer(pStr)).FzBuf
	(*(*TJsonParse)(unsafe.Pointer(bp))).FnJson = int32((*TJsonString)(unsafe.Pointer(pStr)).FnUsed)
	(*(*TJsonParse)(unsafe.Pointer(bp))).Fdb = Xsqlite3_context_db_handle(tls, (*TJsonString)(unsafe.Pointer(pStr)).FpCtx)
	_jsonTranslateTextToBlob(tls, bp, uint32(0))
	if (*(*TJsonParse)(unsafe.Pointer(bp))).Foom != 0 {
		_sqlite3DbFree(tls, (*(*TJsonParse)(unsafe.Pointer(bp))).Fdb, (*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob)
		Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(pStr)).FpCtx)
	} else {
		Xsqlite3_result_blob(tls, (*TJsonString)(unsafe.Pointer(pStr)).FpCtx, (*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob, int32((*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob), __ccgo_fp(_sqlite3OomClear))
	}
}

// C documentation
//
//	/* The byte at index i is a node type-code.  This routine
//	** determines the payload size for that node and writes that
//	** payload size in to *pSz.  It returns the offset from i to the
//	** beginning of the payload.  Return 0 on error.
//	*/
func _jsonbPayloadSize(tls *libc.TLS, pParse uintptr, i Tu32, pSz uintptr) (r Tu32) {
	var n, sz Tu32
	var x Tu8
	_, _, _ = n, sz, x
	if i > (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob {
		*(*Tu32)(unsafe.Pointer(pSz)) = uint32(0)
		return uint32(0)
	}
	x = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)))) >> int32(4))
	if int32(int32(x)) <= int32(11) {
		sz = uint32(uint32(x))
		n = uint32(1)
	} else {
		if int32(int32(x)) == int32(12) {
			if i+uint32(1) >= (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob {
				*(*Tu32)(unsafe.Pointer(pSz)) = uint32(0)
				return uint32(0)
			}
			sz = uint32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(1)))))
			n = uint32(2)
		} else {
			if int32(int32(x)) == int32(13) {
				if i+uint32(2) >= (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob {
					*(*Tu32)(unsafe.Pointer(pSz)) = uint32(0)
					return uint32(0)
				}
				sz = uint32(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(1)))))<<int32(8) + int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(2))))))
				n = uint32(3)
			} else {
				if int32(int32(x)) == int32(14) {
					if i+uint32(4) >= (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob {
						*(*Tu32)(unsafe.Pointer(pSz)) = uint32(0)
						return uint32(0)
					}
					sz = uint32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(1)))))<<libc.Int32FromInt32(24) + uint32(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(2)))))<<libc.Int32FromInt32(16)) + uint32(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(3)))))<<libc.Int32FromInt32(8)) + uint32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(4)))))
					n = uint32(5)
				} else {
					if i+uint32(8) >= (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob || int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(1))))) != 0 || int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(2))))) != 0 || int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(3))))) != 0 || int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(4))))) != 0 {
						*(*Tu32)(unsafe.Pointer(pSz)) = uint32(0)
						return uint32(0)
					}
					sz = uint32(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(5)))))<<int32(24) + int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(6)))))<<int32(16) + int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(7)))))<<int32(8) + int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+uint32(8))))))
					n = uint32(9)
				}
			}
		}
	}
	if int64(int64(i))+int64(int64(sz))+int64(int64(n)) > int64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob) && int64(int64(i))+int64(int64(sz))+int64(int64(n)) > int64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-uint32((*TJsonParse)(unsafe.Pointer(pParse)).Fdelta)) {
		sz = uint32(0)
		n = uint32(0)
	}
	*(*Tu32)(unsafe.Pointer(pSz)) = sz
	return n
}

// C documentation
//
//	/*
//	** Translate the binary JSONB representation of JSON beginning at
//	** pParse->aBlob[i] into a JSON text string.  Append the JSON
//	** text onto the end of pOut.  Return the index in pParse->aBlob[]
//	** of the first byte past the end of the element that is translated.
//	**
//	** If an error is detected in the BLOB input, the pOut->eErr flag
//	** might get set to JSTRING_MALFORMED.  But not all BLOB input errors
//	** are detected.  So a malformed JSONB input might either result
//	** in an error, or in incorrect JSON.
//	**
//	** The pOut->eErr JSTRING_OOM flag is set on a OOM.
//	*/
func _jsonTranslateBlobToText(tls *libc.TLS, pParse uintptr, i Tu32, pOut uintptr) (r Tu32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bOverflow, x, v26, v27 int32
	var iEnd, j, k, k1, k2, n, sz2 Tu32
	var u Tsqlite3_uint64
	var zIn, zIn1, zIn2, v19, p1, p18, p22, p23, p24, p25, p28, p29 uintptr
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bOverflow, iEnd, j, k, k1, k2, n, sz2, u, x, zIn, zIn1, zIn2, v19, v26, v27, p1, p18, p22, p23, p24, p25, p28, p29
	n = _jsonbPayloadSize(tls, pParse, i, bp)
	if n == uint32(0) {
		p1 = pOut + 25
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
		return (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + uint32(1)
	}
	switch int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)))) & libc.Int32FromInt32(0x0f) {
	case JSONB_NULL:
		goto _2
	case int32(JSONB_TRUE):
		goto _3
	case int32(JSONB_FALSE):
		goto _4
	case int32(JSONB_FLOAT):
		goto _5
	case int32(JSONB_INT):
		goto _6
	case int32(JSONB_INT5):
		goto _7
	case int32(JSONB_FLOAT5):
		goto _8
	case int32(JSONB_TEXTJ):
		goto _9
	case int32(JSONB_TEXT):
		goto _10
	case int32(JSONB_TEXT5):
		goto _11
	case int32(JSONB_TEXTRAW):
		goto _12
	case int32(JSONB_ARRAY):
		goto _13
	case int32(JSONB_OBJECT):
		goto _14
	default:
		goto _15
	}
	goto _16
_2:
	;
	_jsonAppendRawNZ(tls, pOut, __ccgo_ts+1658, uint32(4))
	return i + uint32(1)
_3:
	;
	_jsonAppendRawNZ(tls, pOut, __ccgo_ts+9320, uint32(4))
	return i + uint32(1)
_4:
	;
	_jsonAppendRawNZ(tls, pOut, __ccgo_ts+9325, uint32(5))
	return i + uint32(1)
_6:
	;
_5:
	;
	if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) {
		goto malformed_jsonb
	}
	_jsonAppendRaw(tls, pOut, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), *(*Tu32)(unsafe.Pointer(bp)))
	goto _16
_7:
	; /* Integer literal in hexadecimal notation */
	k = uint32(2)
	u = uint64(0)
	zIn = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
	bOverflow = 0
	if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) {
		goto malformed_jsonb
	}
	if int32(*(*int8)(unsafe.Pointer(zIn))) == int32('-') {
		_jsonAppendChar(tls, pOut, int8('-'))
		k++
	} else {
		if int32(*(*int8)(unsafe.Pointer(zIn))) == int32('+') {
			k++
		}
	}
	for {
		if !(k < *(*Tu32)(unsafe.Pointer(bp))) {
			break
		}
		if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zIn + uintptr(k))))])&libc.Int32FromInt32(0x08) != 0) {
			p18 = pOut + 25
			*(*Tu8)(unsafe.Pointer(p18)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p18))) | libc.Int32FromInt32(JSTRING_MALFORMED))
			break
		} else {
			if u>>libc.Int32FromInt32(60) != uint64(0) {
				bOverflow = int32(1)
			} else {
				u = u*uint64(16) + uint64(_sqlite3HexToInt(tls, int32(*(*int8)(unsafe.Pointer(zIn + uintptr(k))))))
			}
		}
		goto _17
	_17:
		;
		k++
	}
	if bOverflow != 0 {
		v19 = __ccgo_ts + 26411
	} else {
		v19 = __ccgo_ts + 13187
	}
	_jsonPrintf(tls, int32(100), pOut, v19, libc.VaList(bp+16, u))
	goto _16
_8:
	; /* Float literal missing digits beside "." */
	k1 = uint32(0)
	zIn1 = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
	if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) {
		goto malformed_jsonb
	}
	if int32(*(*int8)(unsafe.Pointer(zIn1))) == int32('-') {
		_jsonAppendChar(tls, pOut, int8('-'))
		k1++
	}
	if int32(*(*int8)(unsafe.Pointer(zIn1 + uintptr(k1)))) == int32('.') {
		_jsonAppendChar(tls, pOut, int8('0'))
	}
	for {
		if !(k1 < *(*Tu32)(unsafe.Pointer(bp))) {
			break
		}
		_jsonAppendChar(tls, pOut, *(*int8)(unsafe.Pointer(zIn1 + uintptr(k1))))
		if int32(*(*int8)(unsafe.Pointer(zIn1 + uintptr(k1)))) == int32('.') && (k1+uint32(1) == *(*Tu32)(unsafe.Pointer(bp)) || !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zIn1 + uintptr(k1+uint32(1)))))])&libc.Int32FromInt32(0x04) != 0)) {
			_jsonAppendChar(tls, pOut, int8('0'))
		}
		goto _20
	_20:
		;
		k1++
	}
	goto _16
_10:
	;
_9:
	;
	_jsonAppendChar(tls, pOut, int8('"'))
	_jsonAppendRaw(tls, pOut, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), *(*Tu32)(unsafe.Pointer(bp)))
	_jsonAppendChar(tls, pOut, int8('"'))
	goto _16
_11:
	;
	sz2 = *(*Tu32)(unsafe.Pointer(bp))
	zIn2 = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
	_jsonAppendChar(tls, pOut, int8('"'))
	for sz2 > uint32(0) {
		k2 = uint32(0)
		for {
			if !(k2 < sz2 && (_jsonIsOk[uint8(*(*int8)(unsafe.Pointer(zIn2 + uintptr(k2))))] != 0 || int32(*(*int8)(unsafe.Pointer(zIn2 + uintptr(k2)))) == int32('\''))) {
				break
			}
			goto _21
		_21:
			;
			k2++
		}
		if k2 > uint32(0) {
			_jsonAppendRawNZ(tls, pOut, zIn2, k2)
			if k2 >= sz2 {
				break
			}
			zIn2 += uintptr(k2)
			sz2 -= k2
		}
		if int32(*(*int8)(unsafe.Pointer(zIn2))) == int32('"') {
			_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26509, uint32(2))
			zIn2++
			sz2--
			continue
		}
		if int32(*(*int8)(unsafe.Pointer(zIn2))) <= int32(0x1f) {
			if (*TJsonString)(unsafe.Pointer(pOut)).FnUsed+uint64(7) > (*TJsonString)(unsafe.Pointer(pOut)).FnAlloc && _jsonStringGrow(tls, pOut, uint32(7)) != 0 {
				break
			}
			_jsonAppendControlChar(tls, pOut, uint8(*(*int8)(unsafe.Pointer(zIn2))))
			zIn2++
			sz2--
			continue
		}
		if sz2 < uint32(2) {
			p22 = pOut + 25
			*(*Tu8)(unsafe.Pointer(p22)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p22))) | libc.Int32FromInt32(JSTRING_MALFORMED))
			break
		}
		switch int32(uint8(*(*int8)(unsafe.Pointer(zIn2 + 1)))) {
		case int32('\''):
			_jsonAppendChar(tls, pOut, int8('\''))
		case int32('v'):
			_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26512, uint32(6))
		case int32('x'):
			if sz2 < uint32(4) {
				p23 = pOut + 25
				*(*Tu8)(unsafe.Pointer(p23)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p23))) | libc.Int32FromInt32(JSTRING_MALFORMED))
				sz2 = uint32(2)
				break
			}
			_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26519, uint32(4))
			_jsonAppendRawNZ(tls, pOut, zIn2+2, uint32(2))
			zIn2 += uintptr(2)
			sz2 -= uint32(2)
		case int32('0'):
			_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26524, uint32(6))
		case int32('\r'):
			if sz2 > uint32(2) && int32(*(*int8)(unsafe.Pointer(zIn2 + 2))) == int32('\n') {
				zIn2++
				sz2--
			}
		case int32('\n'):
		case int32(0xe2):
			/* '\' followed by either U+2028 or U+2029 is ignored as
			 ** whitespace.  Not that in UTF8, U+2028 is 0xe2 0x80 0x29.
			 ** U+2029 is the same except for the last byte */
			if sz2 < uint32(4) || int32(0x80) != int32(uint8(*(*int8)(unsafe.Pointer(zIn2 + 2)))) || int32(0xa8) != int32(uint8(*(*int8)(unsafe.Pointer(zIn2 + 3)))) && int32(0xa9) != int32(uint8(*(*int8)(unsafe.Pointer(zIn2 + 3)))) {
				p24 = pOut + 25
				*(*Tu8)(unsafe.Pointer(p24)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p24))) | libc.Int32FromInt32(JSTRING_MALFORMED))
				sz2 = uint32(2)
				break
			}
			zIn2 += uintptr(2)
			sz2 -= uint32(2)
		default:
			_jsonAppendRawNZ(tls, pOut, zIn2, uint32(2))
			break
		}
		zIn2 += uintptr(2)
		sz2 -= uint32(2)
	}
	_jsonAppendChar(tls, pOut, int8('"'))
	goto _16
_12:
	;
	_jsonAppendString(tls, pOut, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), *(*Tu32)(unsafe.Pointer(bp)))
	goto _16
_13:
	;
	_jsonAppendChar(tls, pOut, int8('['))
	j = i + n
	iEnd = j + *(*Tu32)(unsafe.Pointer(bp))
	for j < iEnd && int32((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
		j = _jsonTranslateBlobToText(tls, pParse, j, pOut)
		_jsonAppendChar(tls, pOut, int8(','))
	}
	if j > iEnd {
		p25 = pOut + 25
		*(*Tu8)(unsafe.Pointer(p25)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p25))) | libc.Int32FromInt32(JSTRING_MALFORMED))
	}
	if *(*Tu32)(unsafe.Pointer(bp)) > uint32(0) {
		_jsonStringTrimOneChar(tls, pOut)
	}
	_jsonAppendChar(tls, pOut, int8(']'))
	goto _16
_14:
	;
	x = 0
	_jsonAppendChar(tls, pOut, int8('{'))
	j = i + n
	iEnd = j + *(*Tu32)(unsafe.Pointer(bp))
	for j < iEnd && int32((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
		j = _jsonTranslateBlobToText(tls, pParse, j, pOut)
		v27 = x
		x++
		if v27&int32(1) != 0 {
			v26 = int32(',')
		} else {
			v26 = int32(':')
		}
		_jsonAppendChar(tls, pOut, int8(v26))
	}
	if x&int32(1) != 0 || j > iEnd {
		p28 = pOut + 25
		*(*Tu8)(unsafe.Pointer(p28)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p28))) | libc.Int32FromInt32(JSTRING_MALFORMED))
	}
	if *(*Tu32)(unsafe.Pointer(bp)) > uint32(0) {
		_jsonStringTrimOneChar(tls, pOut)
	}
	_jsonAppendChar(tls, pOut, int8('}'))
	goto _16
_15:
	;
	goto malformed_jsonb
malformed_jsonb:
	;
	p29 = pOut + 25
	*(*Tu8)(unsafe.Pointer(p29)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p29))) | libc.Int32FromInt32(JSTRING_MALFORMED))
	goto _16
_16:
	;
	return i + n + *(*Tu32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/* Context for recursion of json_pretty()
//	*/
type TJsonPretty = struct {
	FpParse   uintptr
	FpOut     uintptr
	FzIndent  uintptr
	FszIndent Tu32
	FnIndent  Tu32
}

type JsonPretty = TJsonPretty

type TJsonPretty1 = struct {
	FpParse   uintptr
	FpOut     uintptr
	FzIndent  uintptr
	FszIndent Tu32
	FnIndent  Tu32
}

type JsonPretty1 = TJsonPretty1

// C documentation
//
//	/* Append indentation to the pretty JSON under construction */
func _jsonPrettyIndent(tls *libc.TLS, pPretty uintptr) {
	var jj Tu32
	_ = jj
	jj = uint32(0)
	for {
		if !(jj < (*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent) {
			break
		}
		_jsonAppendRaw(tls, (*TJsonPretty)(unsafe.Pointer(pPretty)).FpOut, (*TJsonPretty)(unsafe.Pointer(pPretty)).FzIndent, (*TJsonPretty)(unsafe.Pointer(pPretty)).FszIndent)
		goto _1
	_1:
		;
		jj++
	}
}

// C documentation
//
//	/*
//	** Translate the binary JSONB representation of JSON beginning at
//	** pParse->aBlob[i] into a JSON text string.  Append the JSON
//	** text onto the end of pOut.  Return the index in pParse->aBlob[]
//	** of the first byte past the end of the element that is translated.
//	**
//	** This is a variant of jsonTranslateBlobToText() that "pretty-prints"
//	** the output.  Extra whitespace is inserted to make the JSON easier
//	** for humans to read.
//	**
//	** If an error is detected in the BLOB input, the pOut->eErr flag
//	** might get set to JSTRING_MALFORMED.  But not all BLOB input errors
//	** are detected.  So a malformed JSONB input might either result
//	** in an error, or in incorrect JSON.
//	**
//	** The pOut->eErr JSTRING_OOM flag is set on a OOM.
//	*/
func _jsonTranslateBlobToPrettyText(tls *libc.TLS, pPretty uintptr, i Tu32) (r Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iEnd, j, n Tu32
	var pOut, pParse, p1, p2 uintptr
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _, _, _, _ = iEnd, j, n, pOut, pParse, p1, p2
	pParse = (*TJsonPretty)(unsafe.Pointer(pPretty)).FpParse
	pOut = (*TJsonPretty)(unsafe.Pointer(pPretty)).FpOut
	n = _jsonbPayloadSize(tls, pParse, i, bp)
	if n == uint32(0) {
		p1 = pOut + 25
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
		return (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + uint32(1)
	}
	switch int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)))) & libc.Int32FromInt32(0x0f) {
	case int32(JSONB_ARRAY):
		j = i + n
		iEnd = j + *(*Tu32)(unsafe.Pointer(bp))
		_jsonAppendChar(tls, pOut, int8('['))
		if j < iEnd {
			_jsonAppendChar(tls, pOut, int8('\n'))
			(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent++
			for int32((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
				_jsonPrettyIndent(tls, pPretty)
				j = _jsonTranslateBlobToPrettyText(tls, pPretty, j)
				if j >= iEnd {
					break
				}
				_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26531, uint32(2))
			}
			_jsonAppendChar(tls, pOut, int8('\n'))
			(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent--
			_jsonPrettyIndent(tls, pPretty)
		}
		_jsonAppendChar(tls, pOut, int8(']'))
		i = iEnd
	case int32(JSONB_OBJECT):
		j = i + n
		iEnd = j + *(*Tu32)(unsafe.Pointer(bp))
		_jsonAppendChar(tls, pOut, int8('{'))
		if j < iEnd {
			_jsonAppendChar(tls, pOut, int8('\n'))
			(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent++
			for int32((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
				_jsonPrettyIndent(tls, pPretty)
				j = _jsonTranslateBlobToText(tls, pParse, j, pOut)
				if j > iEnd {
					p2 = pOut + 25
					*(*Tu8)(unsafe.Pointer(p2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p2))) | libc.Int32FromInt32(JSTRING_MALFORMED))
					break
				}
				_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26534, uint32(2))
				j = _jsonTranslateBlobToPrettyText(tls, pPretty, j)
				if j >= iEnd {
					break
				}
				_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26531, uint32(2))
			}
			_jsonAppendChar(tls, pOut, int8('\n'))
			(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent--
			_jsonPrettyIndent(tls, pPretty)
		}
		_jsonAppendChar(tls, pOut, int8('}'))
		i = iEnd
	default:
		i = _jsonTranslateBlobToText(tls, pParse, i, pOut)
		break
	}
	return i
}

// C documentation
//
//	/* Return true if the input pJson
//	**
//	** For performance reasons, this routine does not do a detailed check of the
//	** input BLOB to ensure that it is well-formed.  Hence, false positives are
//	** possible.  False negatives should never occur, however.
//	*/
func _jsonFuncArgMightBeBinary(tls *libc.TLS, pJson uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aBlob uintptr
	var n Tu32
	var nBlob int32
	var _ /* s at bp+4 */ TJsonParse
	var _ /* sz at bp+0 */ Tu32
	_, _, _ = aBlob, n, nBlob
	if Xsqlite3_value_type(tls, pJson) != int32(SQLITE_BLOB) {
		return 0
	}
	aBlob = Xsqlite3_value_blob(tls, pJson)
	nBlob = Xsqlite3_value_bytes(tls, pJson)
	if nBlob < int32(1) {
		return 0
	}
	if aBlob == uintptr(0) || int32(*(*Tu8)(unsafe.Pointer(aBlob)))&int32(0x0f) > int32(JSONB_OBJECT) {
		return 0
	}
	libc.Xmemset(tls, bp+4, 0, uint32(56))
	(*(*TJsonParse)(unsafe.Pointer(bp + 4))).FaBlob = aBlob
	(*(*TJsonParse)(unsafe.Pointer(bp + 4))).FnBlob = uint32(uint32(nBlob))
	n = _jsonbPayloadSize(tls, bp+4, uint32(0), bp)
	if n == uint32(0) {
		return 0
	}
	if *(*Tu32)(unsafe.Pointer(bp))+n != uint32(uint32(nBlob)) {
		return 0
	}
	if int32(*(*Tu8)(unsafe.Pointer(aBlob)))&int32(0x0f) <= int32(JSONB_FALSE) && *(*Tu32)(unsafe.Pointer(bp)) > uint32(0) {
		return 0
	}
	return libc.BoolInt32(*(*Tu32)(unsafe.Pointer(bp))+n == uint32(uint32(nBlob)))
}

// C documentation
//
//	/*
//	** Given that a JSONB_ARRAY object starts at offset i, return
//	** the number of entries in that array.
//	*/
func _jsonbArrayCount(tls *libc.TLS, pParse uintptr, iRoot Tu32) (r Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iEnd, k, n Tu32
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _ = i, iEnd, k, n
	k = uint32(0)
	n = _jsonbPayloadSize(tls, pParse, iRoot, bp)
	iEnd = iRoot + n + *(*Tu32)(unsafe.Pointer(bp))
	i = iRoot + n
	for {
		if !(n > uint32(0) && i < iEnd) {
			break
		}
		n = _jsonbPayloadSize(tls, pParse, i, bp)
		goto _1
	_1:
		;
		i += *(*Tu32)(unsafe.Pointer(bp)) + n
		k++
	}
	return k
}

// C documentation
//
//	/*
//	** Edit the payload size of the element at iRoot by the amount in
//	** pParse->delta.
//	*/
func _jsonAfterEditSizeAdjust(tls *libc.TLS, pParse uintptr, iRoot Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nBlob Tu32
	var _ /* sz at bp+0 */ Tu32
	_ = nBlob
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
	nBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
	(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc
	_jsonbPayloadSize(tls, pParse, iRoot, bp)
	(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = nBlob
	*(*Tu32)(unsafe.Pointer(bp)) += uint32((*TJsonParse)(unsafe.Pointer(pParse)).Fdelta)
	*(*int32)(unsafe.Pointer(pParse + 40)) += _jsonBlobChangePayloadSize(tls, pParse, iRoot, *(*Tu32)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Modify the JSONB blob at pParse->aBlob by removing nDel bytes of
//	** content beginning at iDel, and replacing them with nIns bytes of
//	** content given by aIns.
//	**
//	** nDel may be zero, in which case no bytes are removed.  But iDel is
//	** still important as new bytes will be insert beginning at iDel.
//	**
//	** aIns may be zero, in which case space is created to hold nIns bytes
//	** beginning at iDel, but that space is uninitialized.
//	**
//	** Set pParse->oom if an OOM occurs.
//	*/
func _jsonBlobEdit(tls *libc.TLS, pParse uintptr, iDel Tu32, nDel Tu32, aIns uintptr, nIns Tu32) {
	var d Ti64
	var p1, p2 uintptr
	_, _, _ = d, p1, p2
	d = int64(int64(nIns)) - int64(int64(nDel))
	if d != 0 {
		if int64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)+d > int64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc) {
			_jsonBlobExpand(tls, pParse, uint32(int64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)+d))
			if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
				return
			}
		}
		libc.Xmemmove(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(iDel+nIns), (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(iDel+nDel), (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-(iDel+nDel))
		p1 = pParse + 4
		*(*Tu32)(unsafe.Pointer(p1)) = Tu32(int64(*(*Tu32)(unsafe.Pointer(p1))) + d)
		p2 = pParse + 40
		*(*int32)(unsafe.Pointer(p2)) = int32(int64(*(*int32)(unsafe.Pointer(p2))) + d)
	}
	if nIns != 0 && aIns != 0 {
		libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(iDel), aIns, nIns)
	}
}

// C documentation
//
//	/*
//	** Return the number of escaped newlines to be ignored.
//	** An escaped newline is a one of the following byte sequences:
//	**
//	**    0x5c 0x0a
//	**    0x5c 0x0d
//	**    0x5c 0x0d 0x0a
//	**    0x5c 0xe2 0x80 0xa8
//	**    0x5c 0xe2 0x80 0xa9
//	*/
func _jsonBytesToBypass(tls *libc.TLS, z uintptr, n Tu32) (r Tu32) {
	var i Tu32
	_ = i
	i = uint32(0)
	for i+uint32(1) < n {
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) != int32('\\') {
			return i
		}
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('\n') {
			i += uint32(2)
			continue
		}
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1))))) == int32('\r') {
			if i+uint32(2) < n && int32(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(2))))) == int32('\n') {
				i += uint32(3)
			} else {
				i += uint32(2)
			}
			continue
		}
		if int32(0xe2) == int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(1)))))) && i+uint32(3) < n && int32(0x80) == int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(2)))))) && (int32(0xa8) == int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(3)))))) || int32(0xa9) == int32(uint8(*(*int8)(unsafe.Pointer(z + uintptr(i+uint32(3))))))) {
			i += uint32(4)
			continue
		}
		break
	}
	return i
}

// C documentation
//
//	/*
//	** Input z[0..n] defines JSON escape sequence including the leading '\\'.
//	** Decode that escape sequence into a single character.  Write that
//	** character into *piOut.  Return the number of bytes in the escape sequence.
//	**
//	** If there is a syntax error of some kind (for example too few characters
//	** after the '\\' to complete the encoding) then *piOut is set to
//	** JSON_INVALID_CHAR.
//	*/
func _jsonUnescapeOneChar(tls *libc.TLS, z uintptr, n Tu32, piOut uintptr) (r Tu32) {
	var nSkip, v, vlo, v1 Tu32
	var sz int32
	var v2 bool
	_, _, _, _, _, _ = nSkip, sz, v, vlo, v1, v2
	if n < uint32(2) {
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32(JSON_INVALID_CHAR)
		return n
	}
	switch int32(uint8(*(*int8)(unsafe.Pointer(z + 1)))) {
	case int32('u'):
		if n < uint32(6) {
			*(*Tu32)(unsafe.Pointer(piOut)) = uint32(JSON_INVALID_CHAR)
			return n
		}
		v = _jsonHexToInt4(tls, z+2)
		if v2 = v&uint32(0xfc00) == uint32(0xd800) && n >= uint32(12) && int32(*(*int8)(unsafe.Pointer(z + 6))) == int32('\\') && int32(*(*int8)(unsafe.Pointer(z + 7))) == int32('u'); v2 {
			v1 = _jsonHexToInt4(tls, z+8)
			vlo = v1
		}
		if v2 && v1&uint32(0xfc00) == uint32(0xdc00) {
			*(*Tu32)(unsafe.Pointer(piOut)) = v&uint32(0x3ff)<<int32(10) + vlo&uint32(0x3ff) + uint32(0x10000)
			return uint32(12)
		} else {
			*(*Tu32)(unsafe.Pointer(piOut)) = v
			return uint32(6)
		}
		fallthrough
	case int32('b'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32('\b')
		return uint32(2)
	case int32('f'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32('\f')
		return uint32(2)
	case int32('n'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32('\n')
		return uint32(2)
	case int32('r'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32('\r')
		return uint32(2)
	case int32('t'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32('\t')
		return uint32(2)
	case int32('v'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32('\v')
		return uint32(2)
	case int32('0'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32(0)
		return uint32(2)
	case int32('\''):
		fallthrough
	case int32('"'):
		fallthrough
	case int32('/'):
		fallthrough
	case int32('\\'):
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32(*(*int8)(unsafe.Pointer(z + 1)))
		return uint32(2)
	case int32('x'):
		if n < uint32(4) {
			*(*Tu32)(unsafe.Pointer(piOut)) = uint32(JSON_INVALID_CHAR)
			return n
		}
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32(int32(_jsonHexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + 2)))))<<int32(4) | int32(_jsonHexToInt(tls, int32(*(*int8)(unsafe.Pointer(z + 3))))))
		return uint32(4)
	case int32(0xe2):
		fallthrough
	case int32('\r'):
		fallthrough
	case int32('\n'):
		nSkip = _jsonBytesToBypass(tls, z, n)
		if nSkip == uint32(0) {
			*(*Tu32)(unsafe.Pointer(piOut)) = uint32(JSON_INVALID_CHAR)
			return n
		} else {
			if nSkip == n {
				*(*Tu32)(unsafe.Pointer(piOut)) = uint32(0)
				return n
			} else {
				if int32(*(*int8)(unsafe.Pointer(z + uintptr(nSkip)))) == int32('\\') {
					return nSkip + _jsonUnescapeOneChar(tls, z+uintptr(nSkip), n-nSkip, piOut)
				} else {
					sz = _sqlite3Utf8ReadLimited(tls, z+uintptr(nSkip), int32(n-nSkip), piOut)
					return nSkip + uint32(uint32(sz))
				}
			}
		}
		fallthrough
	default:
		*(*Tu32)(unsafe.Pointer(piOut)) = uint32(JSON_INVALID_CHAR)
		return uint32(2)
	}
	return r
}

// C documentation
//
//	/*
//	** Compare two object labels.  Return 1 if they are equal and
//	** 0 if they differ.
//	**
//	** In this version, we know that one or the other or both of the
//	** two comparands contains an escape sequence.
//	*/
func _jsonLabelCompareEscaped(tls *libc.TLS, zLeft uintptr, nLeft Tu32, rawLeft int32, zRight uintptr, nRight Tu32, rawRight int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var n, n1 Tu32
	var sz, sz1 int32
	var _ /* cLeft at bp+0 */ Tu32
	var _ /* cRight at bp+4 */ Tu32
	_, _, _, _ = n, n1, sz, sz1
	for int32(1) != 0 {
		if nLeft == uint32(0) {
			*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		} else {
			if rawLeft != 0 || int32(*(*int8)(unsafe.Pointer(zLeft))) != int32('\\') {
				*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(zLeft)))
				if *(*Tu32)(unsafe.Pointer(bp)) >= uint32(0xc0) {
					sz = _sqlite3Utf8ReadLimited(tls, zLeft, int32(int32(nLeft)), bp)
					zLeft += uintptr(sz)
					nLeft -= uint32(uint32(sz))
				} else {
					zLeft++
					nLeft--
				}
			} else {
				n = _jsonUnescapeOneChar(tls, zLeft, nLeft, bp)
				zLeft += uintptr(n)
				nLeft -= n
			}
		}
		if nRight == uint32(0) {
			*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0)
		} else {
			if rawRight != 0 || int32(*(*int8)(unsafe.Pointer(zRight))) != int32('\\') {
				*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(*(*Tu8)(unsafe.Pointer(zRight)))
				if *(*Tu32)(unsafe.Pointer(bp + 4)) >= uint32(0xc0) {
					sz1 = _sqlite3Utf8ReadLimited(tls, zRight, int32(int32(nRight)), bp+4)
					zRight += uintptr(sz1)
					nRight -= uint32(uint32(sz1))
				} else {
					zRight++
					nRight--
				}
			} else {
				n1 = _jsonUnescapeOneChar(tls, zRight, nRight, bp+4)
				zRight += uintptr(n1)
				nRight -= n1
			}
		}
		if *(*Tu32)(unsafe.Pointer(bp)) != *(*Tu32)(unsafe.Pointer(bp + 4)) {
			return 0
		}
		if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) {
			return int32(1)
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Compare two object labels.  Return 1 if they are equal and
//	** 0 if they differ.  Return -1 if an OOM occurs.
//	*/
func _jsonLabelCompare(tls *libc.TLS, zLeft uintptr, nLeft Tu32, rawLeft int32, zRight uintptr, nRight Tu32, rawRight int32) (r int32) {
	if rawLeft != 0 && rawRight != 0 {
		/* Simpliest case:  Neither label contains escapes.  A simple
		 ** memcmp() is sufficient. */
		if nLeft != nRight {
			return 0
		}
		return libc.BoolInt32(libc.Xmemcmp(tls, zLeft, zRight, nLeft) == 0)
	} else {
		return _jsonLabelCompareEscaped(tls, zLeft, nLeft, rawLeft, zRight, nRight, rawRight)
	}
	return r
}

// C documentation
//
//	/* This helper routine for jsonLookupStep() populates pIns with
//	** binary data that is to be inserted into pParse.
//	**
//	** In the common case, pIns just points to pParse->aIns and pParse->nIns.
//	** But if the zPath of the original edit operation includes path elements
//	** that go deeper, additional substructure must be created.
//	**
//	** For example:
//	**
//	**     json_insert('{}', '$.a.b.c', 123);
//	**
//	** The search stops at '$.a'  But additional substructure must be
//	** created for the ".b.c" part of the patch so that the final result
//	** is:  {"a":{"b":{"c"::123}}}.  This routine populates pIns with
//	** the binary equivalent of {"b":{"c":123}} so that it can be inserted.
//	**
//	** The caller is responsible for resetting pIns when it has finished
//	** using the substructure.
//	*/
func _jsonCreateEditSubstructure(tls *libc.TLS, pParse uintptr, pIns uintptr, zTail uintptr) (r Tu32) {
	var rc int32
	var p1 uintptr
	_, _ = rc, p1
	libc.Xmemset(tls, pIns, 0, uint32(56))
	(*TJsonParse)(unsafe.Pointer(pIns)).Fdb = (*TJsonParse)(unsafe.Pointer(pParse)).Fdb
	if int32(*(*int8)(unsafe.Pointer(zTail))) == 0 {
		/* No substructure.  Just insert what is given in pParse. */
		(*TJsonParse)(unsafe.Pointer(pIns)).FaBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FaIns
		(*TJsonParse)(unsafe.Pointer(pIns)).FnBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FnIns
		rc = 0
	} else {
		/* Construct the binary substructure */
		(*TJsonParse)(unsafe.Pointer(pIns)).FnBlob = uint32(1)
		(*TJsonParse)(unsafe.Pointer(pIns)).FaBlob = uintptr(unsafe.Pointer(&_emptyObject)) + libc.BoolUintptr(int32(*(*int8)(unsafe.Pointer(zTail))) == int32('.'))
		(*TJsonParse)(unsafe.Pointer(pIns)).FeEdit = (*TJsonParse)(unsafe.Pointer(pParse)).FeEdit
		(*TJsonParse)(unsafe.Pointer(pIns)).FnIns = (*TJsonParse)(unsafe.Pointer(pParse)).FnIns
		(*TJsonParse)(unsafe.Pointer(pIns)).FaIns = (*TJsonParse)(unsafe.Pointer(pParse)).FaIns
		rc = int32(_jsonLookupStep(tls, pIns, uint32(0), zTail, uint32(0)))
		p1 = pParse + 35
		*(*Tu8)(unsafe.Pointer(p1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p1))) | int32((*TJsonParse)(unsafe.Pointer(pIns)).Foom))
	}
	return uint32(uint32(rc)) /* Error code only */
}

var _emptyObject = [2]Tu8{
	0: uint8(JSONB_ARRAY),
	1: uint8(JSONB_OBJECT),
}

// C documentation
//
//	/*
//	** Search along zPath to find the Json element specified.  Return an
//	** index into pParse->aBlob[] for the start of that element's value.
//	**
//	** If the value found by this routine is the value half of label/value pair
//	** within an object, then set pPath->iLabel to the start of the corresponding
//	** label, before returning.
//	**
//	** Return one of the JSON_LOOKUP error codes if problems are seen.
//	**
//	** This routine will also modify the blob.  If pParse->eEdit is one of
//	** JEDIT_DEL, JEDIT_REPL, JEDIT_INS, or JEDIT_SET, then changes might be
//	** made to the selected value.  If an edit is performed, then the return
//	** value does not necessarily point to the select element.  If an edit
//	** is performed, the return value is only useful for detecting error
//	** conditions.
//	*/
func _jsonLookupStep(tls *libc.TLS, pParse uintptr, iRoot Tu32, zPath uintptr, iLabel Tu32) (r Tu32) {
	bp := tls.Alloc(176)
	defer tls.Free(176)
	var i, iEnd, j, k, n, nIns, nKey, rc, v Tu32
	var nn uint32
	var rawKey, rawLabel, v3 int32
	var x Tu8
	var zKey, zLabel, p4 uintptr
	var _ /* ix at bp+60 */ TJsonParse
	var _ /* sz at bp+0 */ Tu32
	var _ /* v at bp+116 */ TJsonParse
	var _ /* v at bp+4 */ TJsonParse
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iEnd, j, k, n, nIns, nKey, nn, rawKey, rawLabel, rc, v, x, zKey, zLabel, v3, p4
	if int32(*(*int8)(unsafe.Pointer(zPath))) == 0 {
		if (*TJsonParse)(unsafe.Pointer(pParse)).FeEdit != 0 && _jsonBlobMakeEditable(tls, pParse, (*TJsonParse)(unsafe.Pointer(pParse)).FnIns) != 0 {
			n = _jsonbPayloadSize(tls, pParse, iRoot, bp)
			*(*Tu32)(unsafe.Pointer(bp)) += n
			if int32((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) == int32(JEDIT_DEL) {
				if iLabel > uint32(0) {
					*(*Tu32)(unsafe.Pointer(bp)) += iRoot - iLabel
					iRoot = iLabel
				}
				_jsonBlobEdit(tls, pParse, iRoot, *(*Tu32)(unsafe.Pointer(bp)), uintptr(0), uint32(0))
			} else {
				if int32((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) == int32(JEDIT_INS) {
					/* Already exists, so json_insert() is a no-op */
				} else {
					/* json_set() or json_replace() */
					_jsonBlobEdit(tls, pParse, iRoot, *(*Tu32)(unsafe.Pointer(bp)), (*TJsonParse)(unsafe.Pointer(pParse)).FaIns, (*TJsonParse)(unsafe.Pointer(pParse)).FnIns)
				}
			}
		}
		(*TJsonParse)(unsafe.Pointer(pParse)).FiLabel = iLabel
		return iRoot
	}
	if int32(*(*int8)(unsafe.Pointer(zPath))) == int32('.') {
		rawKey = int32(1)
		x = *(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(iRoot)))
		zPath++
		if int32(*(*int8)(unsafe.Pointer(zPath))) == int32('"') {
			zKey = zPath + uintptr(1)
			i = uint32(1)
			for {
				if !(*(*int8)(unsafe.Pointer(zPath + uintptr(i))) != 0 && int32(*(*int8)(unsafe.Pointer(zPath + uintptr(i)))) != int32('"')) {
					break
				}
				goto _1
			_1:
				;
				i++
			}
			nKey = i - uint32(1)
			if *(*int8)(unsafe.Pointer(zPath + uintptr(i))) != 0 {
				i++
			} else {
				return uint32(JSON_LOOKUP_PATHERROR)
			}
			rawKey = libc.BoolInt32(libc.Xmemchr(tls, zKey, int32('\\'), nKey) == uintptr(0))
		} else {
			zKey = zPath
			i = uint32(0)
			for {
				if !(*(*int8)(unsafe.Pointer(zPath + uintptr(i))) != 0 && int32(*(*int8)(unsafe.Pointer(zPath + uintptr(i)))) != int32('.') && int32(*(*int8)(unsafe.Pointer(zPath + uintptr(i)))) != int32('[')) {
					break
				}
				goto _2
			_2:
				;
				i++
			}
			nKey = i
			if nKey == uint32(0) {
				return uint32(JSON_LOOKUP_PATHERROR)
			}
		}
		if int32(int32(x))&int32(0x0f) != int32(JSONB_OBJECT) {
			return uint32(JSON_LOOKUP_NOTFOUND)
		}
		n = _jsonbPayloadSize(tls, pParse, iRoot, bp)
		j = iRoot + n /* j is the index of a label */
		iEnd = j + *(*Tu32)(unsafe.Pointer(bp))
		for j < iEnd {
			x = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(j)))) & int32(0x0f))
			if int32(int32(x)) < int32(JSONB_TEXT) || int32(int32(x)) > int32(JSONB_TEXTRAW) {
				return uint32(JSON_LOOKUP_ERROR)
			}
			n = _jsonbPayloadSize(tls, pParse, j, bp)
			if n == uint32(0) {
				return uint32(JSON_LOOKUP_ERROR)
			}
			k = j + n /* k is the index of the label text */
			if k+*(*Tu32)(unsafe.Pointer(bp)) >= iEnd {
				return uint32(JSON_LOOKUP_ERROR)
			}
			zLabel = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(k)
			rawLabel = libc.BoolInt32(int32(int32(x)) == int32(JSONB_TEXT) || int32(int32(x)) == int32(JSONB_TEXTRAW))
			if _jsonLabelCompare(tls, zKey, nKey, rawKey, zLabel, *(*Tu32)(unsafe.Pointer(bp)), rawLabel) != 0 {
				v = k + *(*Tu32)(unsafe.Pointer(bp)) /* v is the index of the value */
				if int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(v))))&int32(0x0f) > int32(JSONB_OBJECT) {
					return uint32(JSON_LOOKUP_ERROR)
				}
				n = _jsonbPayloadSize(tls, pParse, v, bp)
				if n == uint32(0) || v+n+*(*Tu32)(unsafe.Pointer(bp)) > iEnd {
					return uint32(JSON_LOOKUP_ERROR)
				}
				rc = _jsonLookupStep(tls, pParse, v, zPath+uintptr(i), j)
				if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
					_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
				}
				return rc
			}
			j = k + *(*Tu32)(unsafe.Pointer(bp))
			if int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(j))))&int32(0x0f) > int32(JSONB_OBJECT) {
				return uint32(JSON_LOOKUP_ERROR)
			}
			n = _jsonbPayloadSize(tls, pParse, j, bp)
			if n == uint32(0) {
				return uint32(JSON_LOOKUP_ERROR)
			}
			j += n + *(*Tu32)(unsafe.Pointer(bp))
		}
		if j > iEnd {
			return uint32(JSON_LOOKUP_ERROR)
		}
		if int32((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) >= int32(JEDIT_INS) { /* Header of the label to be inserted */
			libc.Xmemset(tls, bp+60, 0, uint32(56))
			(*(*TJsonParse)(unsafe.Pointer(bp + 60))).Fdb = (*TJsonParse)(unsafe.Pointer(pParse)).Fdb
			if rawKey != 0 {
				v3 = int32(JSONB_TEXTRAW)
			} else {
				v3 = int32(JSONB_TEXT5)
			}
			_jsonBlobAppendNode(tls, bp+60, uint8(v3), nKey, uintptr(0))
			p4 = pParse + 35
			*(*Tu8)(unsafe.Pointer(p4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p4))) | int32((*(*TJsonParse)(unsafe.Pointer(bp + 60))).Foom))
			rc = _jsonCreateEditSubstructure(tls, pParse, bp+4, zPath+uintptr(i))
			if !(rc >= libc.Uint32FromUint32(JSON_LOOKUP_PATHERROR)) && _jsonBlobMakeEditable(tls, pParse, (*(*TJsonParse)(unsafe.Pointer(bp + 60))).FnBlob+nKey+(*(*TJsonParse)(unsafe.Pointer(bp + 4))).FnBlob) != 0 {
				nIns = (*(*TJsonParse)(unsafe.Pointer(bp + 60))).FnBlob + nKey + (*(*TJsonParse)(unsafe.Pointer(bp + 4))).FnBlob
				_jsonBlobEdit(tls, pParse, j, uint32(0), uintptr(0), nIns)
				if !((*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0) {
					/* Because pParse->oom!=0 */
					/* Because pPasre->oom!=0 */
					libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(j), (*(*TJsonParse)(unsafe.Pointer(bp + 60))).FaBlob, (*(*TJsonParse)(unsafe.Pointer(bp + 60))).FnBlob)
					k = j + (*(*TJsonParse)(unsafe.Pointer(bp + 60))).FnBlob
					libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(k), zKey, nKey)
					k += nKey
					libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(k), (*(*TJsonParse)(unsafe.Pointer(bp + 4))).FaBlob, (*(*TJsonParse)(unsafe.Pointer(bp + 4))).FnBlob)
					if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
						_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
					}
				}
			}
			_jsonParseReset(tls, bp+4)
			_jsonParseReset(tls, bp+60)
			return rc
		}
	} else {
		if int32(*(*int8)(unsafe.Pointer(zPath))) == int32('[') {
			x = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(iRoot)))) & int32(0x0f))
			if int32(int32(x)) != int32(JSONB_ARRAY) {
				return uint32(JSON_LOOKUP_NOTFOUND)
			}
			n = _jsonbPayloadSize(tls, pParse, iRoot, bp)
			k = uint32(0)
			i = uint32(1)
			for int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zPath + uintptr(i))))])&int32(0x04) != 0 {
				k = k*uint32(10) + uint32(*(*int8)(unsafe.Pointer(zPath + uintptr(i)))) - uint32('0')
				i++
			}
			if i < uint32(2) || int32(*(*int8)(unsafe.Pointer(zPath + uintptr(i)))) != int32(']') {
				if int32(*(*int8)(unsafe.Pointer(zPath + 1))) == int32('#') {
					k = _jsonbArrayCount(tls, pParse, iRoot)
					i = uint32(2)
					if int32(*(*int8)(unsafe.Pointer(zPath + 2))) == int32('-') && int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zPath + 3)))])&int32(0x04) != 0 {
						nn = uint32(0)
						i = uint32(3)
						for cond := true; cond; cond = int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(zPath + uintptr(i))))])&int32(0x04) != 0 {
							nn = nn*uint32(10) + uint32(*(*int8)(unsafe.Pointer(zPath + uintptr(i)))) - uint32('0')
							i++
						}
						if nn > k {
							return uint32(JSON_LOOKUP_NOTFOUND)
						}
						k -= nn
					}
					if int32(*(*int8)(unsafe.Pointer(zPath + uintptr(i)))) != int32(']') {
						return uint32(JSON_LOOKUP_PATHERROR)
					}
				} else {
					return uint32(JSON_LOOKUP_PATHERROR)
				}
			}
			j = iRoot + n
			iEnd = j + *(*Tu32)(unsafe.Pointer(bp))
			for j < iEnd {
				if k == uint32(0) {
					rc = _jsonLookupStep(tls, pParse, j, zPath+uintptr(i+uint32(1)), uint32(0))
					if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
						_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
					}
					return rc
				}
				k--
				n = _jsonbPayloadSize(tls, pParse, j, bp)
				if n == uint32(0) {
					return uint32(JSON_LOOKUP_ERROR)
				}
				j += n + *(*Tu32)(unsafe.Pointer(bp))
			}
			if j > iEnd {
				return uint32(JSON_LOOKUP_ERROR)
			}
			if k > uint32(0) {
				return uint32(JSON_LOOKUP_NOTFOUND)
			}
			if int32((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) >= int32(JEDIT_INS) {
				rc = _jsonCreateEditSubstructure(tls, pParse, bp+116, zPath+uintptr(i+uint32(1)))
				if !(rc >= libc.Uint32FromUint32(JSON_LOOKUP_PATHERROR)) && _jsonBlobMakeEditable(tls, pParse, (*(*TJsonParse)(unsafe.Pointer(bp + 116))).FnBlob) != 0 {
					_jsonBlobEdit(tls, pParse, j, uint32(0), (*(*TJsonParse)(unsafe.Pointer(bp + 116))).FaBlob, (*(*TJsonParse)(unsafe.Pointer(bp + 116))).FnBlob)
				}
				_jsonParseReset(tls, bp+116)
				if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
					_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
				}
				return rc
			}
		} else {
			return uint32(JSON_LOOKUP_PATHERROR)
		}
	}
	return uint32(JSON_LOOKUP_NOTFOUND)
}

// C documentation
//
//	/*
//	** Convert a JSON BLOB into text and make that text the return value
//	** of an SQL function.
//	*/
func _jsonReturnTextJsonFromBlob(tls *libc.TLS, ctx uintptr, aBlob uintptr, nBlob Tu32) {
	bp := tls.Alloc(192)
	defer tls.Free(192)
	var _ /* s at bp+56 */ TJsonString
	var _ /* x at bp+0 */ TJsonParse
	if aBlob == uintptr(0) {
		return
	}
	libc.Xmemset(tls, bp, 0, uint32(56))
	(*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob = aBlob
	(*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob = nBlob
	_jsonStringInit(tls, bp+56, ctx)
	_jsonTranslateBlobToText(tls, bp, uint32(0), bp+56)
	_jsonReturnString(tls, bp+56, uintptr(0), uintptr(0))
}

// C documentation
//
//	/*
//	** Return the value of the BLOB node at index i.
//	**
//	** If the value is a primitive, return it as an SQL value.
//	** If the value is an array or object, return it as either
//	** JSON text or the BLOB encoding, depending on the JSON_B flag
//	** on the userdata.
//	*/
func _jsonReturnFromBlob(tls *libc.TLS, pParse uintptr, i Tu32, pCtx uintptr, textOnly int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bNeg, flags, rc, v30 int32
	var c, x int8
	var db, z, z1, z2, zOut uintptr
	var iIn, iOut, n, nOut, szEscape, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29 Tu32
	var v16 int64
	var _ /* iRes at bp+8 */ Tsqlite3_int64
	var _ /* r at bp+16 */ float64
	var _ /* sz at bp+0 */ Tu32
	var _ /* v at bp+24 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNeg, c, db, flags, iIn, iOut, n, nOut, rc, szEscape, x, z, z1, z2, zOut, v16, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30
	db = Xsqlite3_context_db_handle(tls, pCtx)
	n = _jsonbPayloadSize(tls, pParse, i, bp)
	if n == uint32(0) {
		Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26392, -int32(1))
		return
	}
	switch int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)))) & libc.Int32FromInt32(0x0f) {
	case JSONB_NULL:
		goto _1
	case int32(JSONB_TRUE):
		goto _2
	case int32(JSONB_FALSE):
		goto _3
	case int32(JSONB_INT):
		goto _4
	case int32(JSONB_INT5):
		goto _5
	case int32(JSONB_FLOAT):
		goto _6
	case int32(JSONB_FLOAT5):
		goto _7
	case int32(JSONB_TEXT):
		goto _8
	case int32(JSONB_TEXTRAW):
		goto _9
	case int32(JSONB_TEXTJ):
		goto _10
	case int32(JSONB_TEXT5):
		goto _11
	case int32(JSONB_OBJECT):
		goto _12
	case int32(JSONB_ARRAY):
		goto _13
	default:
		goto _14
	}
	goto _15
_1:
	;
	if *(*Tu32)(unsafe.Pointer(bp)) != 0 {
		goto returnfromblob_malformed
	}
	Xsqlite3_result_null(tls, pCtx)
	goto _15
_2:
	;
	if *(*Tu32)(unsafe.Pointer(bp)) != 0 {
		goto returnfromblob_malformed
	}
	Xsqlite3_result_int(tls, pCtx, int32(1))
	goto _15
_3:
	;
	if *(*Tu32)(unsafe.Pointer(bp)) != 0 {
		goto returnfromblob_malformed
	}
	Xsqlite3_result_int(tls, pCtx, 0)
	goto _15
_5:
	;
_4:
	;
	*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)) = 0
	bNeg = 0
	if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) {
		goto returnfromblob_malformed
	}
	x = int8(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n))))
	if int32(int32(x)) == int32('-') {
		if *(*Tu32)(unsafe.Pointer(bp)) < uint32(2) {
			goto returnfromblob_malformed
		}
		n++
		*(*Tu32)(unsafe.Pointer(bp))--
		bNeg = int32(1)
	}
	z = _sqlite3DbStrNDup(tls, db, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), uint64(int32(*(*Tu32)(unsafe.Pointer(bp)))))
	if z == uintptr(0) {
		goto returnfromblob_oom
	}
	rc = _sqlite3DecOrHexToI64(tls, z, bp+8)
	_sqlite3DbFree(tls, db, z)
	if rc == 0 {
		if bNeg != 0 {
			v16 = -*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8))
		} else {
			v16 = *(*Tsqlite3_int64)(unsafe.Pointer(bp + 8))
		}
		Xsqlite3_result_int64(tls, pCtx, v16)
	} else {
		if rc == int32(3) && bNeg != 0 {
			Xsqlite3_result_int64(tls, pCtx, int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
		} else {
			if rc == int32(1) {
				goto returnfromblob_malformed
			} else {
				if bNeg != 0 {
					n--
					*(*Tu32)(unsafe.Pointer(bp))++
				}
				goto to_double
			}
		}
	}
	goto _15
_7:
	;
_6:
	;
	if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) {
		goto returnfromblob_malformed
	}
	goto to_double
to_double:
	;
	z1 = _sqlite3DbStrNDup(tls, db, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), uint64(int32(*(*Tu32)(unsafe.Pointer(bp)))))
	if z1 == uintptr(0) {
		goto returnfromblob_oom
	}
	rc = _sqlite3AtoF(tls, z1, bp+16, _sqlite3Strlen30(tls, z1), uint8(SQLITE_UTF8))
	_sqlite3DbFree(tls, db, z1)
	if rc <= 0 {
		goto returnfromblob_malformed
	}
	Xsqlite3_result_double(tls, pCtx, *(*float64)(unsafe.Pointer(bp + 16)))
	goto _15
_9:
	;
_8:
	;
	Xsqlite3_result_text(tls, pCtx, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), int32(*(*Tu32)(unsafe.Pointer(bp))), uintptr(-libc.Int32FromInt32(1)))
	goto _15
_11:
	;
_10:
	;
	nOut = *(*Tu32)(unsafe.Pointer(bp))
	z2 = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
	zOut = _sqlite3DbMallocRaw(tls, db, uint64(nOut+uint32(1)))
	if zOut == uintptr(0) {
		goto returnfromblob_oom
	}
	v18 = libc.Uint32FromInt32(0)
	iOut = v18
	iIn = v18
	for {
		if !(iIn < *(*Tu32)(unsafe.Pointer(bp))) {
			break
		}
		c = *(*int8)(unsafe.Pointer(z2 + uintptr(iIn)))
		if int32(int32(c)) == int32('\\') {
			szEscape = _jsonUnescapeOneChar(tls, z2+uintptr(iIn), *(*Tu32)(unsafe.Pointer(bp))-iIn, bp+24)
			if *(*Tu32)(unsafe.Pointer(bp + 24)) <= uint32(0x7f) {
				v19 = iOut
				iOut++
				*(*int8)(unsafe.Pointer(zOut + uintptr(v19))) = int8(*(*Tu32)(unsafe.Pointer(bp + 24)))
			} else {
				if *(*Tu32)(unsafe.Pointer(bp + 24)) <= uint32(0x7ff) {
					v20 = iOut
					iOut++
					*(*int8)(unsafe.Pointer(zOut + uintptr(v20))) = int8(libc.Uint32FromInt32(0xc0) | *(*Tu32)(unsafe.Pointer(bp + 24))>>libc.Int32FromInt32(6))
					v21 = iOut
					iOut++
					*(*int8)(unsafe.Pointer(zOut + uintptr(v21))) = int8(uint32(0x80) | *(*Tu32)(unsafe.Pointer(bp + 24))&uint32(0x3f))
				} else {
					if *(*Tu32)(unsafe.Pointer(bp + 24)) < uint32(0x10000) {
						v22 = iOut
						iOut++
						*(*int8)(unsafe.Pointer(zOut + uintptr(v22))) = int8(uint32(0xe0) | *(*Tu32)(unsafe.Pointer(bp + 24))>>libc.Int32FromInt32(12))
						v23 = iOut
						iOut++
						*(*int8)(unsafe.Pointer(zOut + uintptr(v23))) = int8(uint32(0x80) | *(*Tu32)(unsafe.Pointer(bp + 24))>>libc.Int32FromInt32(6)&uint32(0x3f))
						v24 = iOut
						iOut++
						*(*int8)(unsafe.Pointer(zOut + uintptr(v24))) = int8(uint32(0x80) | *(*Tu32)(unsafe.Pointer(bp + 24))&uint32(0x3f))
					} else {
						if *(*Tu32)(unsafe.Pointer(bp + 24)) == uint32(JSON_INVALID_CHAR) {
							/* Silently ignore illegal unicode */
						} else {
							v25 = iOut
							iOut++
							*(*int8)(unsafe.Pointer(zOut + uintptr(v25))) = int8(uint32(0xf0) | *(*Tu32)(unsafe.Pointer(bp + 24))>>libc.Int32FromInt32(18))
							v26 = iOut
							iOut++
							*(*int8)(unsafe.Pointer(zOut + uintptr(v26))) = int8(uint32(0x80) | *(*Tu32)(unsafe.Pointer(bp + 24))>>libc.Int32FromInt32(12)&uint32(0x3f))
							v27 = iOut
							iOut++
							*(*int8)(unsafe.Pointer(zOut + uintptr(v27))) = int8(uint32(0x80) | *(*Tu32)(unsafe.Pointer(bp + 24))>>libc.Int32FromInt32(6)&uint32(0x3f))
							v28 = iOut
							iOut++
							*(*int8)(unsafe.Pointer(zOut + uintptr(v28))) = int8(uint32(0x80) | *(*Tu32)(unsafe.Pointer(bp + 24))&uint32(0x3f))
						}
					}
				}
			}
			iIn += szEscape - uint32(1)
		} else {
			v29 = iOut
			iOut++
			*(*int8)(unsafe.Pointer(zOut + uintptr(v29))) = c
		}
		goto _17
	_17:
		;
		iIn++
	} /* end for() */
	*(*int8)(unsafe.Pointer(zOut + uintptr(iOut))) = 0
	Xsqlite3_result_text(tls, pCtx, zOut, int32(int32(iOut)), __ccgo_fp(_sqlite3OomClear))
	goto _15
_13:
	;
_12:
	;
	if textOnly != 0 {
		v30 = 0
	} else {
		v30 = int32(Xsqlite3_user_data(tls, pCtx))
	}
	flags = v30
	if flags&int32(JSON_BLOB) != 0 {
		Xsqlite3_result_blob(tls, pCtx, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i), int32(*(*Tu32)(unsafe.Pointer(bp))+n), uintptr(-libc.Int32FromInt32(1)))
	} else {
		_jsonReturnTextJsonFromBlob(tls, pCtx, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i), *(*Tu32)(unsafe.Pointer(bp))+n)
	}
	goto _15
_14:
	;
	goto returnfromblob_malformed
_15:
	;
	return
	goto returnfromblob_oom
returnfromblob_oom:
	;
	Xsqlite3_result_error_nomem(tls, pCtx)
	return
	goto returnfromblob_malformed
returnfromblob_malformed:
	;
	Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26392, -int32(1))
	return
}

// C documentation
//
//	/*
//	** pArg is a function argument that might be an SQL value or a JSON
//	** value.  Figure out what it is and encode it as a JSONB blob.
//	** Return the results in pParse.
//	**
//	** pParse is uninitialized upon entry.  This routine will handle the
//	** initialization of pParse.  The result will be contained in
//	** pParse->aBlob and pParse->nBlob.  pParse->aBlob might be dynamically
//	** allocated (if pParse->nBlobAlloc is greater than zero) in which case
//	** the caller is responsible for freeing the space allocated to pParse->aBlob
//	** when it has finished with it.  Or pParse->aBlob might be a static string
//	** or a value obtained from sqlite3_value_blob(pArg).
//	**
//	** If the argument is a BLOB that is clearly not a JSONB, then this
//	** function might set an error message in ctx and return non-zero.
//	** It might also set an error message and return non-zero on an OOM error.
//	*/
func _jsonFunctionArgToBlob(tls *libc.TLS, ctx uintptr, pArg uintptr, pParse uintptr) (r1 int32) {
	var eType, n, n1, nJson int32
	var r float64
	var z, z1, zJson uintptr
	_, _, _, _, _, _, _, _ = eType, n, n1, nJson, r, z, z1, zJson
	eType = Xsqlite3_value_type(tls, pArg)
	libc.Xmemset(tls, pParse, 0, uint32(56))
	(*TJsonParse)(unsafe.Pointer(pParse)).Fdb = Xsqlite3_context_db_handle(tls, ctx)
	switch eType {
	default:
		(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = uintptr(unsafe.Pointer(&_aNull))
		(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = uint32(1)
		return 0
	case int32(SQLITE_BLOB):
		if _jsonFuncArgMightBeBinary(tls, pArg) != 0 {
			(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = Xsqlite3_value_blob(tls, pArg)
			(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = uint32(Xsqlite3_value_bytes(tls, pArg))
		} else {
			Xsqlite3_result_error(tls, ctx, __ccgo_ts+26363, -int32(1))
			return int32(1)
		}
	case int32(SQLITE_TEXT):
		zJson = Xsqlite3_value_text(tls, pArg)
		nJson = Xsqlite3_value_bytes(tls, pArg)
		if zJson == uintptr(0) {
			return int32(1)
		}
		if Xsqlite3_value_subtype(tls, pArg) == uint32(JSON_SUBTYPE) {
			(*TJsonParse)(unsafe.Pointer(pParse)).FzJson = zJson
			(*TJsonParse)(unsafe.Pointer(pParse)).FnJson = nJson
			if _jsonConvertTextToBlob(tls, pParse, ctx) != 0 {
				Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
				_sqlite3DbFree(tls, (*TJsonParse)(unsafe.Pointer(pParse)).Fdb, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob)
				libc.Xmemset(tls, pParse, 0, uint32(56))
				return int32(1)
			}
		} else {
			_jsonBlobAppendNode(tls, pParse, uint8(JSONB_TEXTRAW), uint32(uint32(nJson)), zJson)
		}
	case int32(SQLITE_FLOAT):
		r = Xsqlite3_value_double(tls, pArg)
		if _sqlite3IsNaN(tls, r) != 0 {
			_jsonBlobAppendNode(tls, pParse, uint8(JSONB_NULL), uint32(0), uintptr(0))
		} else {
			n = Xsqlite3_value_bytes(tls, pArg)
			z = Xsqlite3_value_text(tls, pArg)
			if z == uintptr(0) {
				return int32(1)
			}
			if int32(*(*int8)(unsafe.Pointer(z))) == int32('I') {
				_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint32(5), __ccgo_ts+26497)
			} else {
				if int32(*(*int8)(unsafe.Pointer(z))) == int32('-') && int32(*(*int8)(unsafe.Pointer(z + 1))) == int32('I') {
					_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint32(6), __ccgo_ts+26490)
				} else {
					_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint32(uint32(n)), z)
				}
			}
		}
	case int32(SQLITE_INTEGER):
		n1 = Xsqlite3_value_bytes(tls, pArg)
		z1 = Xsqlite3_value_text(tls, pArg)
		if z1 == uintptr(0) {
			return int32(1)
		}
		_jsonBlobAppendNode(tls, pParse, uint8(JSONB_INT), uint32(uint32(n1)), z1)
		break
	}
	if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		Xsqlite3_result_error_nomem(tls, ctx)
		return int32(1)
	} else {
		return 0
	}
	return r1
}

var _aNull = [1]Tu8{}

// C documentation
//
//	/*
//	** Generate a bad path error.
//	**
//	** If ctx is not NULL then push the error message into ctx and return NULL.
//	** If ctx is NULL, then return the text of the error message.
//	*/
func _jsonBadPathError(tls *libc.TLS, ctx uintptr, zPath uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var zMsg uintptr
	_ = zMsg
	zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26537, libc.VaList(bp+8, zPath))
	if ctx == uintptr(0) {
		return zMsg
	}
	if zMsg != 0 {
		Xsqlite3_result_error(tls, ctx, zMsg, -int32(1))
		Xsqlite3_free(tls, zMsg)
	} else {
		Xsqlite3_result_error_nomem(tls, ctx)
	}
	return uintptr(0)
}

// C documentation
//
//	/* argv[0] is a BLOB that seems likely to be a JSONB.  Subsequent
//	** arguments come in parse where each pair contains a JSON path and
//	** content to insert or set at that patch.  Do the updates
//	** and return the result.
//	**
//	** The specific operation is determined by eEdit, which can be one
//	** of JEDIT_INS, JEDIT_REPL, or JEDIT_SET.
//	*/
func _jsonInsertIntoBlob(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr, eEdit int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var flgs, i, v1 int32
	var p, zPath uintptr
	var rc Tu32
	var _ /* ax at bp+0 */ TJsonParse
	_, _, _, _, _, _ = flgs, i, p, rc, zPath, v1
	rc = uint32(0)
	zPath = uintptr(0)
	if argc == int32(1) {
		v1 = 0
	} else {
		v1 = int32(JSON_EDITABLE)
	}
	flgs = v1
	p = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(uint32(flgs)))
	if p == uintptr(0) {
		return
	}
	i = int32(1)
	for {
		if !(i < argc-int32(1)) {
			break
		}
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))) == int32(SQLITE_NULL) {
			goto _2
		}
		zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		if zPath == uintptr(0) {
			Xsqlite3_result_error_nomem(tls, ctx)
			_jsonParseFree(tls, p)
			return
		}
		if int32(*(*int8)(unsafe.Pointer(zPath))) != int32('$') {
			goto jsonInsertIntoBlob_patherror
		}
		if _jsonFunctionArgToBlob(tls, ctx, *(*uintptr)(unsafe.Pointer(argv + uintptr(i+int32(1))*4)), bp) != 0 {
			_jsonParseReset(tls, bp)
			_jsonParseFree(tls, p)
			return
		}
		if int32(*(*int8)(unsafe.Pointer(zPath + 1))) == 0 {
			if eEdit == int32(JEDIT_REPL) || eEdit == int32(JEDIT_SET) {
				_jsonBlobEdit(tls, p, uint32(0), (*TJsonParse)(unsafe.Pointer(p)).FnBlob, (*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob, (*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob)
			}
			rc = uint32(0)
		} else {
			(*TJsonParse)(unsafe.Pointer(p)).FeEdit = uint8(uint8(eEdit))
			(*TJsonParse)(unsafe.Pointer(p)).FnIns = (*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob
			(*TJsonParse)(unsafe.Pointer(p)).FaIns = (*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob
			(*TJsonParse)(unsafe.Pointer(p)).Fdelta = 0
			rc = _jsonLookupStep(tls, p, uint32(0), zPath+uintptr(1), uint32(0))
		}
		_jsonParseReset(tls, bp)
		if rc == uint32(JSON_LOOKUP_NOTFOUND) {
			goto _2
		}
		if rc >= uint32(JSON_LOOKUP_PATHERROR) {
			goto jsonInsertIntoBlob_patherror
		}
		goto _2
	_2:
		;
		i += int32(2)
	}
	_jsonReturnParse(tls, ctx, p)
	_jsonParseFree(tls, p)
	return
	goto jsonInsertIntoBlob_patherror
jsonInsertIntoBlob_patherror:
	;
	_jsonParseFree(tls, p)
	if rc == uint32(JSON_LOOKUP_ERROR) {
		Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
	} else {
		_jsonBadPathError(tls, ctx, zPath)
	}
	return
}

// C documentation
//
//	/*
//	** If pArg is a blob that seems like a JSONB blob, then initialize
//	** p to point to that JSONB and return TRUE.  If pArg does not seem like
//	** a JSONB blob, then return FALSE;
//	**
//	** This routine is only called if it is already known that pArg is a
//	** blob.  The only open question is whether or not the blob appears
//	** to be a JSONB blob.
//	*/
func _jsonArgIsJsonb(tls *libc.TLS, pArg uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var n, v1 Tu32
	var v2 bool
	var _ /* sz at bp+0 */ Tu32
	_, _, _ = n, v1, v2
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
	(*TJsonParse)(unsafe.Pointer(p)).FaBlob = Xsqlite3_value_blob(tls, pArg)
	(*TJsonParse)(unsafe.Pointer(p)).FnBlob = uint32(Xsqlite3_value_bytes(tls, pArg))
	if (*TJsonParse)(unsafe.Pointer(p)).FnBlob == uint32(0) {
		(*TJsonParse)(unsafe.Pointer(p)).FaBlob = uintptr(0)
		return 0
	}
	if (*TJsonParse)(unsafe.Pointer(p)).FaBlob == uintptr(0) {
		return 0
	}
	if v2 = int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(p)).FaBlob)))&int32(0x0f) <= int32(JSONB_OBJECT); v2 {
		v1 = _jsonbPayloadSize(tls, p, uint32(0), bp)
		n = v1
	}
	if v2 && v1 > uint32(0) && *(*Tu32)(unsafe.Pointer(bp))+n == (*TJsonParse)(unsafe.Pointer(p)).FnBlob && (int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(p)).FaBlob)))&int32(0x0f) > int32(JSONB_FALSE) || *(*Tu32)(unsafe.Pointer(bp)) == uint32(0)) {
		return int32(1)
	}
	(*TJsonParse)(unsafe.Pointer(p)).FaBlob = uintptr(0)
	(*TJsonParse)(unsafe.Pointer(p)).FnBlob = uint32(0)
	return 0
}

// C documentation
//
//	/*
//	** Generate a JsonParse object, containing valid JSONB in aBlob and nBlob,
//	** from the SQL function argument pArg.  Return a pointer to the new
//	** JsonParse object.
//	**
//	** Ownership of the new JsonParse object is passed to the caller.  The
//	** caller should invoke jsonParseFree() on the return value when it
//	** has finished using it.
//	**
//	** If any errors are detected, an appropriate error messages is set
//	** using sqlite3_result_error() or the equivalent and this routine
//	** returns NULL.  This routine also returns NULL if the pArg argument
//	** is an SQL NULL value, but no error message is set in that case.  This
//	** is so that SQL functions that are given NULL arguments will return
//	** a NULL value.
//	*/
func _jsonParseFuncArg(tls *libc.TLS, ctx uintptr, pArg uintptr, flgs Tu32) (r uintptr) {
	var db, p, pFromCache, zNew, v2 uintptr
	var eType, isRCStr, rc int32
	var nBlob, v1 Tu32
	_, _, _, _, _, _, _, _, _, _ = db, eType, isRCStr, nBlob, p, pFromCache, rc, zNew, v1, v2 /* Datatype of pArg */
	p = uintptr(0)                                                                            /* Value to be returned */
	pFromCache = uintptr(0)                                                                   /* The database connection */
	eType = Xsqlite3_value_type(tls, pArg)
	if eType == int32(SQLITE_NULL) {
		return uintptr(0)
	}
	pFromCache = _jsonCacheSearch(tls, ctx, pArg)
	if pFromCache != 0 {
		(*TJsonParse)(unsafe.Pointer(pFromCache)).FnJPRef++
		if flgs&uint32(JSON_EDITABLE) == uint32(0) {
			return pFromCache
		}
	}
	db = Xsqlite3_context_db_handle(tls, ctx)
	goto rebuild_from_cache
rebuild_from_cache:
	;
	p = _sqlite3DbMallocZero(tls, db, uint64(56))
	if p == uintptr(0) {
		goto json_pfa_oom
	}
	libc.Xmemset(tls, p, 0, uint32(56))
	(*TJsonParse)(unsafe.Pointer(p)).Fdb = db
	(*TJsonParse)(unsafe.Pointer(p)).FnJPRef = uint32(1)
	if pFromCache != uintptr(0) {
		nBlob = (*TJsonParse)(unsafe.Pointer(pFromCache)).FnBlob
		(*TJsonParse)(unsafe.Pointer(p)).FaBlob = _sqlite3DbMallocRaw(tls, db, uint64(uint64(nBlob)))
		if (*TJsonParse)(unsafe.Pointer(p)).FaBlob == uintptr(0) {
			goto json_pfa_oom
		}
		libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(p)).FaBlob, (*TJsonParse)(unsafe.Pointer(pFromCache)).FaBlob, nBlob)
		v1 = nBlob
		(*TJsonParse)(unsafe.Pointer(p)).FnBlob = v1
		(*TJsonParse)(unsafe.Pointer(p)).FnBlobAlloc = v1
		(*TJsonParse)(unsafe.Pointer(p)).FhasNonstd = (*TJsonParse)(unsafe.Pointer(pFromCache)).FhasNonstd
		_jsonParseFree(tls, pFromCache)
		return p
	}
	if eType == int32(SQLITE_BLOB) {
		if _jsonArgIsJsonb(tls, pArg, p) != 0 {
			if flgs&uint32(JSON_EDITABLE) != uint32(0) && _jsonBlobMakeEditable(tls, p, uint32(0)) == 0 {
				goto json_pfa_oom
			}
			return p
		}
		/* If the blob is not valid JSONB, fall through into trying to cast
		 ** the blob into text which is then interpreted as JSON.  (tag-20240123-a)
		 **
		 ** This goes against all historical documentation about how the SQLite
		 ** JSON functions were suppose to work.  From the beginning, blob was
		 ** reserved for expansion and a blob value should have raised an error.
		 ** But it did not, due to a bug.  And many applications came to depend
		 ** upon this buggy behavior, espeically when using the CLI and reading
		 ** JSON text using readfile(), which returns a blob.  For this reason
		 ** we will continue to support the bug moving forward.
		 ** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d
		 */
	}
	(*TJsonParse)(unsafe.Pointer(p)).FzJson = Xsqlite3_value_text(tls, pArg)
	(*TJsonParse)(unsafe.Pointer(p)).FnJson = Xsqlite3_value_bytes(tls, pArg)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto json_pfa_oom
	}
	if (*TJsonParse)(unsafe.Pointer(p)).FnJson == 0 {
		goto json_pfa_malformed
	}
	if flgs&uint32(JSON_KEEPERROR) != 0 {
		v2 = uintptr(0)
	} else {
		v2 = ctx
	}
	if _jsonConvertTextToBlob(tls, p, v2) != 0 {
		if flgs&uint32(JSON_KEEPERROR) != 0 {
			(*TJsonParse)(unsafe.Pointer(p)).FnErr = uint8(1)
			return p
		} else {
			_jsonParseFree(tls, p)
			return uintptr(0)
		}
	} else {
		isRCStr = _sqlite3ValueIsOfClass(tls, pArg, __ccgo_fp(_sqlite3RCStrUnref))
		if !(isRCStr != 0) {
			zNew = _sqlite3RCStrNew(tls, uint64((*TJsonParse)(unsafe.Pointer(p)).FnJson))
			if zNew == uintptr(0) {
				goto json_pfa_oom
			}
			libc.Xmemcpy(tls, zNew, (*TJsonParse)(unsafe.Pointer(p)).FzJson, uint32((*TJsonParse)(unsafe.Pointer(p)).FnJson))
			(*TJsonParse)(unsafe.Pointer(p)).FzJson = zNew
			*(*int8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(p)).FzJson + uintptr((*TJsonParse)(unsafe.Pointer(p)).FnJson))) = 0
		} else {
			_sqlite3RCStrRef(tls, (*TJsonParse)(unsafe.Pointer(p)).FzJson)
		}
		(*TJsonParse)(unsafe.Pointer(p)).FbJsonIsRCStr = uint8(1)
		rc = _jsonCacheInsert(tls, ctx, p)
		if rc == int32(SQLITE_NOMEM) {
			goto json_pfa_oom
		}
		if flgs&uint32(JSON_EDITABLE) != 0 {
			pFromCache = p
			p = uintptr(0)
			goto rebuild_from_cache
		}
	}
	return p
	goto json_pfa_malformed
json_pfa_malformed:
	;
	if flgs&uint32(JSON_KEEPERROR) != 0 {
		(*TJsonParse)(unsafe.Pointer(p)).FnErr = uint8(1)
		return p
	} else {
		_jsonParseFree(tls, p)
		Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
		return uintptr(0)
	}
	goto json_pfa_oom
json_pfa_oom:
	;
	_jsonParseFree(tls, pFromCache)
	_jsonParseFree(tls, p)
	Xsqlite3_result_error_nomem(tls, ctx)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Make the return value of a JSON function either the raw JSONB blob
//	** or make it JSON text, depending on whether the JSON_BLOB flag is
//	** set on the function.
//	*/
func _jsonReturnParse(tls *libc.TLS, ctx uintptr, p uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var flgs int32
	var _ /* s at bp+0 */ TJsonString
	_ = flgs
	if (*TJsonParse)(unsafe.Pointer(p)).Foom != 0 {
		Xsqlite3_result_error_nomem(tls, ctx)
		return
	}
	flgs = int32(Xsqlite3_user_data(tls, ctx))
	if flgs&int32(JSON_BLOB) != 0 {
		if (*TJsonParse)(unsafe.Pointer(p)).FnBlobAlloc > uint32(0) && !((*TJsonParse)(unsafe.Pointer(p)).FbReadOnly != 0) {
			Xsqlite3_result_blob(tls, ctx, (*TJsonParse)(unsafe.Pointer(p)).FaBlob, int32((*TJsonParse)(unsafe.Pointer(p)).FnBlob), __ccgo_fp(_sqlite3OomClear))
			(*TJsonParse)(unsafe.Pointer(p)).FnBlobAlloc = uint32(0)
		} else {
			Xsqlite3_result_blob(tls, ctx, (*TJsonParse)(unsafe.Pointer(p)).FaBlob, int32((*TJsonParse)(unsafe.Pointer(p)).FnBlob), uintptr(-libc.Int32FromInt32(1)))
		}
	} else {
		_jsonStringInit(tls, bp, ctx)
		(*TJsonParse)(unsafe.Pointer(p)).Fdelta = 0
		_jsonTranslateBlobToText(tls, p, uint32(0), bp)
		_jsonReturnString(tls, bp, p, ctx)
		Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
	}
}

/****************************************************************************
** SQL functions used for testing and debugging
****************************************************************************/

/****************************************************************************
** Scalar SQL function implementations
****************************************************************************/

// C documentation
//
//	/*
//	** Implementation of the json_quote(VALUE) function.  Return a JSON value
//	** corresponding to the SQL value input.  Mostly this means putting
//	** double-quotes around strings and returning the unquoted string "null"
//	** when given a NULL input.
//	*/
func _jsonQuoteFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var _ /* jx at bp+0 */ TJsonString
	_ = argc
	_jsonStringInit(tls, bp, ctx)
	_jsonAppendSqlValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv)))
	_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

// C documentation
//
//	/*
//	** Implementation of the json_array(VALUE,...) function.  Return a JSON
//	** array that contains all values given in arguments.  Or if any argument
//	** is a BLOB, throw an error.
//	*/
func _jsonArrayFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var i int32
	var _ /* jx at bp+0 */ TJsonString
	_ = i
	_jsonStringInit(tls, bp, ctx)
	_jsonAppendChar(tls, bp, int8('['))
	i = 0
	for {
		if !(i < argc) {
			break
		}
		_jsonAppendSeparator(tls, bp)
		_jsonAppendSqlValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
	_jsonAppendChar(tls, bp, int8(']'))
	_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

// C documentation
//
//	/*
//	** json_array_length(JSON)
//	** json_array_length(JSON, PATH)
//	**
//	** Return the number of elements in the top-level JSON array.
//	** Return 0 if the input is not a well-formed JSON array.
//	*/
func _jsonArrayLengthFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var cnt Tsqlite3_int64
	var eErr Tu8
	var i Tu32
	var p, zPath, v1 uintptr
	_, _, _, _, _, _ = cnt, eErr, i, p, zPath, v1 /* The parse */
	cnt = 0
	eErr = uint8(0)
	p = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(0))
	if p == uintptr(0) {
		return
	}
	if argc == int32(2) {
		zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		if zPath == uintptr(0) {
			_jsonParseFree(tls, p)
			return
		}
		if int32(*(*int8)(unsafe.Pointer(zPath))) == int32('$') {
			v1 = zPath + uintptr(1)
		} else {
			v1 = __ccgo_ts + 26555
		}
		i = _jsonLookupStep(tls, p, uint32(0), v1, uint32(0))
		if i >= uint32(JSON_LOOKUP_PATHERROR) {
			if i == uint32(JSON_LOOKUP_NOTFOUND) {
				/* no-op */
			} else {
				if i == uint32(JSON_LOOKUP_PATHERROR) {
					_jsonBadPathError(tls, ctx, zPath)
				} else {
					Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
				}
			}
			eErr = uint8(1)
			i = uint32(0)
		}
	} else {
		i = uint32(0)
	}
	if int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(p)).FaBlob + uintptr(i))))&int32(0x0f) == int32(JSONB_ARRAY) {
		cnt = int64(_jsonbArrayCount(tls, p, i))
	}
	if !(eErr != 0) {
		Xsqlite3_result_int64(tls, ctx, cnt)
	}
	_jsonParseFree(tls, p)
}

// C documentation
//
//	/* True if the string is all alphanumerics and underscores */
func _jsonAllAlphanum(tls *libc.TLS, z uintptr, n int32) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < n && (int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i))))])&int32(0x06) != 0 || int32(*(*int8)(unsafe.Pointer(z + uintptr(i)))) == int32('_'))) {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	return libc.BoolInt32(i == n)
}

// C documentation
//
//	/*
//	** json_extract(JSON, PATH, ...)
//	** "->"(JSON,PATH)
//	** "->>"(JSON,PATH)
//	**
//	** Return the element described by PATH.  Return NULL if that PATH element
//	** is not found.
//	**
//	** If JSON_JSON is set or if more that one PATH argument is supplied then
//	** always return a JSON representation of the result.  If JSON_SQL is set,
//	** then always return an SQL representation of the result.  If neither flag
//	** is present and argc==2, then return JSON for objects and arrays and SQL
//	** for all other values.
//	**
//	** When multiple PATH arguments are supplied, the result is a JSON array
//	** containing the result of each PATH.
//	**
//	** Abbreviated JSON path expressions are allows if JSON_ABPATH, for
//	** compatibility with PG.
//	*/
func _jsonExtractFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var flags, i, nPath int32
	var j Tu32
	var p, zPath uintptr
	var _ /* jx at bp+0 */ TJsonString
	_, _, _, _, _, _ = flags, i, j, nPath, p, zPath
	p = uintptr(0) /* String for array result */
	if argc < int32(2) {
		return
	}
	p = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(0))
	if p == uintptr(0) {
		return
	}
	flags = int32(Xsqlite3_user_data(tls, ctx))
	_jsonStringInit(tls, bp, ctx)
	if argc > int32(2) {
		_jsonAppendChar(tls, bp, int8('['))
	}
	i = int32(1)
	for {
		if !(i < argc) {
			break
		}
		/* With a single PATH argument */
		zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		if zPath == uintptr(0) {
			goto json_extract_error
		}
		nPath = _sqlite3Strlen30(tls, zPath)
		if int32(*(*int8)(unsafe.Pointer(zPath))) == int32('$') {
			j = _jsonLookupStep(tls, p, uint32(0), zPath+uintptr(1), uint32(0))
		} else {
			if flags&int32(JSON_ABPATH) != 0 {
				/* The -> and ->> operators accept abbreviated PATH arguments.  This
				 ** is mostly for compatibility with PostgreSQL, but also for
				 ** convenience.
				 **
				 **     NUMBER   ==>  $[NUMBER]     // PG compatible
				 **     LABEL    ==>  $.LABEL       // PG compatible
				 **     [NUMBER] ==>  $[NUMBER]     // Not PG.  Purely for convenience
				 */
				_jsonStringInit(tls, bp, ctx)
				if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))) == int32(SQLITE_INTEGER) {
					_jsonAppendRawNZ(tls, bp, __ccgo_ts+26557, uint32(1))
					_jsonAppendRaw(tls, bp, zPath, uint32(uint32(nPath)))
					_jsonAppendRawNZ(tls, bp, __ccgo_ts+6534, uint32(2))
				} else {
					if _jsonAllAlphanum(tls, zPath, nPath) != 0 {
						_jsonAppendRawNZ(tls, bp, __ccgo_ts+1685, uint32(1))
						_jsonAppendRaw(tls, bp, zPath, uint32(uint32(nPath)))
					} else {
						if int32(*(*int8)(unsafe.Pointer(zPath))) == int32('[') && nPath >= int32(3) && int32(*(*int8)(unsafe.Pointer(zPath + uintptr(nPath-int32(1))))) == int32(']') {
							_jsonAppendRaw(tls, bp, zPath, uint32(uint32(nPath)))
						} else {
							_jsonAppendRawNZ(tls, bp, __ccgo_ts+26559, uint32(2))
							_jsonAppendRaw(tls, bp, zPath, uint32(uint32(nPath)))
							_jsonAppendRawNZ(tls, bp, __ccgo_ts+26562, uint32(1))
						}
					}
				}
				_jsonStringTerminate(tls, bp)
				j = _jsonLookupStep(tls, p, uint32(0), (*(*TJsonString)(unsafe.Pointer(bp))).FzBuf, uint32(0))
				_jsonStringReset(tls, bp)
			} else {
				_jsonBadPathError(tls, ctx, zPath)
				goto json_extract_error
			}
		}
		if j < (*TJsonParse)(unsafe.Pointer(p)).FnBlob {
			if argc == int32(2) {
				if flags&int32(JSON_JSON) != 0 {
					_jsonStringInit(tls, bp, ctx)
					_jsonTranslateBlobToText(tls, p, j, bp)
					_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
					_jsonStringReset(tls, bp)
					Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
				} else {
					_jsonReturnFromBlob(tls, p, j, ctx, 0)
					if flags&(libc.Int32FromInt32(JSON_SQL)|libc.Int32FromInt32(JSON_BLOB)) == 0 && int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(p)).FaBlob + uintptr(j))))&int32(0x0f) >= int32(JSONB_ARRAY) {
						Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
					}
				}
			} else {
				_jsonAppendSeparator(tls, bp)
				_jsonTranslateBlobToText(tls, p, j, bp)
			}
		} else {
			if j == uint32(JSON_LOOKUP_NOTFOUND) {
				if argc == int32(2) {
					goto json_extract_error /* Return NULL if not found */
				} else {
					_jsonAppendSeparator(tls, bp)
					_jsonAppendRawNZ(tls, bp, __ccgo_ts+1658, uint32(4))
				}
			} else {
				if j == uint32(JSON_LOOKUP_ERROR) {
					Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
					goto json_extract_error
				} else {
					_jsonBadPathError(tls, ctx, zPath)
					goto json_extract_error
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	if argc > int32(2) {
		_jsonAppendChar(tls, bp, int8(']'))
		_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
		if flags&int32(JSON_BLOB) == 0 {
			Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
		}
	}
	goto json_extract_error
json_extract_error:
	;
	_jsonStringReset(tls, bp)
	_jsonParseFree(tls, p)
	return
}

/*
** Return codes for jsonMergePatch()
 */

// C documentation
//
//	/*
//	** RFC-7396 MergePatch for two JSONB blobs.
//	**
//	** pTarget is the target. pPatch is the patch.  The target is updated
//	** in place.  The patch is read-only.
//	**
//	** The original RFC-7396 algorithm is this:
//	**
//	**   define MergePatch(Target, Patch):
//	**     if Patch is an Object:
//	**       if Target is not an Object:
//	**         Target = {} # Ignore the contents and set it to an empty Object
//	**     for each Name/Value pair in Patch:
//	**         if Value is null:
//	**           if Name exists in Target:
//	**             remove the Name/Value pair from Target
//	**         else:
//	**           Target[Name] = MergePatch(Target[Name], Value)
//	**       return Target
//	**     else:
//	**       return Patch
//	**
//	** Here is an equivalent algorithm restructured to show the actual
//	** implementation:
//	**
//	** 01   define MergePatch(Target, Patch):
//	** 02      if Patch is not an Object:
//	** 03         return Patch
//	** 04      else: // if Patch is an Object
//	** 05         if Target is not an Object:
//	** 06            Target = {}
//	** 07      for each Name/Value pair in Patch:
//	** 08         if Name exists in Target:
//	** 09            if Value is null:
//	** 10               remove the Name/Value pair from Target
//	** 11            else
//	** 12               Target[name] = MergePatch(Target[Name], Value)
//	** 13         else if Value is not NULL:
//	** 14            if Value is not an Object:
//	** 15               Target[name] = Value
//	** 16            else:
//	** 17               Target[name] = MergePatch('{}',value)
//	** 18      return Target
//	**  |
//	**  ^---- Line numbers referenced in comments in the implementation
//	*/
func _jsonMergePatch(tls *libc.TLS, pTarget uintptr, iTarget Tu32, pPatch uintptr, iPatch Tu32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ePLabel, eTLabel, x Tu8
	var iPCursor, iPEnd, iPLabel, iPValue, iTCursor, iTEnd, iTEndBE, iTLabel, iTStart, iTValue, n, nPLabel, nPValue, nTLabel, nTValue, szNew, szPatch, szTarget Tu32
	var isEqual, rc, rc1, savedDelta, savedDelta1, v1, v2 int32
	var _ /* sz at bp+0 */ Tu32
	var _ /* szPLabel at bp+12 */ Tu32
	var _ /* szPValue at bp+16 */ Tu32
	var _ /* szTLabel at bp+4 */ Tu32
	var _ /* szTValue at bp+8 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ePLabel, eTLabel, iPCursor, iPEnd, iPLabel, iPValue, iTCursor, iTEnd, iTEndBE, iTLabel, iTStart, iTValue, isEqual, n, nPLabel, nPValue, nTLabel, nTValue, rc, rc1, savedDelta, savedDelta1, szNew, szPatch, szTarget, x, v1, v2
	*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)     /* Node type of the target label */
	iTLabel = uint32(0)                          /* Index of the label */
	nTLabel = uint32(0)                          /* Header size in bytes for the target label */
	*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0) /* Size of the target label payload */
	iTValue = uint32(0)                          /* Index of the target value */
	nTValue = uint32(0)                          /* Header size of the target value */
	*(*Tu32)(unsafe.Pointer(bp + 8)) = uint32(0) /* Payload size of the patch value */
	x = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPatch)))) & int32(0x0f))
	if int32(int32(x)) != int32(JSONB_OBJECT) { /* Total size of the target, header+payload */
		n = _jsonbPayloadSize(tls, pPatch, iPatch, bp)
		szPatch = n + *(*Tu32)(unsafe.Pointer(bp))
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		n = _jsonbPayloadSize(tls, pTarget, iTarget, bp)
		szTarget = n + *(*Tu32)(unsafe.Pointer(bp))
		_jsonBlobEdit(tls, pTarget, iTarget, szTarget, (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPatch), szPatch)
		if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
			v1 = int32(JSON_MERGE_OOM)
		} else {
			v1 = JSON_MERGE_OK
		}
		return v1 /* Line 03 */
	}
	x = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTarget)))) & int32(0x0f))
	if int32(int32(x)) != int32(JSONB_OBJECT) { /* Algorithm line 05 */
		n = _jsonbPayloadSize(tls, pTarget, iTarget, bp)
		_jsonBlobEdit(tls, pTarget, iTarget+n, *(*Tu32)(unsafe.Pointer(bp)), uintptr(0), uint32(0))
		x = *(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTarget)))
		*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTarget))) = uint8(int32(int32(x))&int32(0xf0) | int32(JSONB_OBJECT))
	}
	n = _jsonbPayloadSize(tls, pPatch, iPatch, bp)
	if n == uint32(0) {
		return int32(JSON_MERGE_BADPATCH)
	}
	iPCursor = iPatch + n
	iPEnd = iPCursor + *(*Tu32)(unsafe.Pointer(bp))
	n = _jsonbPayloadSize(tls, pTarget, iTarget, bp)
	if n == uint32(0) {
		return int32(JSON_MERGE_BADTARGET)
	}
	iTStart = iTarget + n
	iTEndBE = iTStart + *(*Tu32)(unsafe.Pointer(bp))
	for iPCursor < iPEnd { /* Algorithm line 07 */
		iPLabel = iPCursor
		ePLabel = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPCursor)))) & int32(0x0f))
		if int32(int32(ePLabel)) < int32(JSONB_TEXT) || int32(int32(ePLabel)) > int32(JSONB_TEXTRAW) {
			return int32(JSON_MERGE_BADPATCH)
		}
		nPLabel = _jsonbPayloadSize(tls, pPatch, iPCursor, bp+12)
		if nPLabel == uint32(0) {
			return int32(JSON_MERGE_BADPATCH)
		}
		iPValue = iPCursor + nPLabel + *(*Tu32)(unsafe.Pointer(bp + 12))
		if iPValue >= iPEnd {
			return int32(JSON_MERGE_BADPATCH)
		}
		nPValue = _jsonbPayloadSize(tls, pPatch, iPValue, bp+16)
		if nPValue == uint32(0) {
			return int32(JSON_MERGE_BADPATCH)
		}
		iPCursor = iPValue + nPValue + *(*Tu32)(unsafe.Pointer(bp + 16))
		if iPCursor > iPEnd {
			return int32(JSON_MERGE_BADPATCH)
		}
		iTCursor = iTStart
		iTEnd = iTEndBE + uint32((*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta)
		for iTCursor < iTEnd { /* true if the patch and target labels match */
			iTLabel = iTCursor
			eTLabel = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTCursor)))) & int32(0x0f))
			if int32(int32(eTLabel)) < int32(JSONB_TEXT) || int32(int32(eTLabel)) > int32(JSONB_TEXTRAW) {
				return int32(JSON_MERGE_BADTARGET)
			}
			nTLabel = _jsonbPayloadSize(tls, pTarget, iTCursor, bp+4)
			if nTLabel == uint32(0) {
				return int32(JSON_MERGE_BADTARGET)
			}
			iTValue = iTLabel + nTLabel + *(*Tu32)(unsafe.Pointer(bp + 4))
			if iTValue >= iTEnd {
				return int32(JSON_MERGE_BADTARGET)
			}
			nTValue = _jsonbPayloadSize(tls, pTarget, iTValue, bp+8)
			if nTValue == uint32(0) {
				return int32(JSON_MERGE_BADTARGET)
			}
			if iTValue+nTValue+*(*Tu32)(unsafe.Pointer(bp + 8)) > iTEnd {
				return int32(JSON_MERGE_BADTARGET)
			}
			isEqual = _jsonLabelCompare(tls, (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPLabel+nPLabel), *(*Tu32)(unsafe.Pointer(bp + 12)), libc.BoolInt32(int32(int32(ePLabel)) == int32(JSONB_TEXT) || int32(int32(ePLabel)) == int32(JSONB_TEXTRAW)), (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTLabel+nTLabel), *(*Tu32)(unsafe.Pointer(bp + 4)), libc.BoolInt32(int32(int32(eTLabel)) == int32(JSONB_TEXT) || int32(int32(eTLabel)) == int32(JSONB_TEXTRAW)))
			if isEqual != 0 {
				break
			}
			iTCursor = iTValue + nTValue + *(*Tu32)(unsafe.Pointer(bp + 8))
		}
		x = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPValue)))) & int32(0x0f))
		if iTCursor < iTEnd {
			/* A match was found.  Algorithm line 08 */
			if int32(int32(x)) == 0 {
				/* Patch value is NULL.  Algorithm line 09 */
				_jsonBlobEdit(tls, pTarget, iTLabel, nTLabel+*(*Tu32)(unsafe.Pointer(bp + 4))+nTValue+*(*Tu32)(unsafe.Pointer(bp + 8)), uintptr(0), uint32(0))
				/*  vvvvvv----- No OOM on a delete-only edit */
				if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
					return int32(JSON_MERGE_OOM)
				}
			} else {
				savedDelta = (*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta
				(*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta = 0
				rc = _jsonMergePatch(tls, pTarget, iTValue, pPatch, iPValue)
				if rc != 0 {
					return rc
				}
				*(*int32)(unsafe.Pointer(pTarget + 40)) += savedDelta
			}
		} else {
			if int32(int32(x)) > 0 { /* Algorithm line 13 */
				/* No match and patch value is not NULL */
				szNew = *(*Tu32)(unsafe.Pointer(bp + 12)) + nPLabel
				if int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPValue))))&int32(0x0f) != int32(JSONB_OBJECT) { /* Line 14 */
					_jsonBlobEdit(tls, pTarget, iTEnd, uint32(0), uintptr(0), *(*Tu32)(unsafe.Pointer(bp + 16))+nPValue+szNew)
					if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
						return int32(JSON_MERGE_OOM)
					}
					libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTEnd), (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPLabel), szNew)
					libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTEnd+szNew), (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPValue), *(*Tu32)(unsafe.Pointer(bp + 16))+nPValue)
				} else {
					_jsonBlobEdit(tls, pTarget, iTEnd, uint32(0), uintptr(0), szNew+uint32(1))
					if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
						return int32(JSON_MERGE_OOM)
					}
					libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTEnd), (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPLabel), szNew)
					*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTEnd+szNew))) = uint8(0x00)
					savedDelta1 = (*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta
					(*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta = 0
					rc1 = _jsonMergePatch(tls, pTarget, iTEnd+szNew, pPatch, iPValue)
					if rc1 != 0 {
						return rc1
					}
					*(*int32)(unsafe.Pointer(pTarget + 40)) += savedDelta1
				}
			}
		}
	}
	if (*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta != 0 {
		_jsonAfterEditSizeAdjust(tls, pTarget, iTarget)
	}
	if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
		v2 = int32(JSON_MERGE_OOM)
	} else {
		v2 = JSON_MERGE_OK
	}
	return v2
}

// C documentation
//
//	/*
//	** Implementation of the json_mergepatch(JSON1,JSON2) function.  Return a JSON
//	** object that is the result of running the RFC 7396 MergePatch() algorithm
//	** on the two arguments.
//	*/
func _jsonPatchFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var pPatch, pTarget uintptr
	var rc int32
	_, _, _ = pPatch, pTarget, rc /* Result code */
	_ = argc
	pTarget = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(JSON_EDITABLE))
	if pTarget == uintptr(0) {
		return
	}
	pPatch = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv + 1*4)), uint32(0))
	if pPatch != 0 {
		rc = _jsonMergePatch(tls, pTarget, uint32(0), pPatch, uint32(0))
		if rc == JSON_MERGE_OK {
			_jsonReturnParse(tls, ctx, pTarget)
		} else {
			if rc == int32(JSON_MERGE_OOM) {
				Xsqlite3_result_error_nomem(tls, ctx)
			} else {
				Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
			}
		}
		_jsonParseFree(tls, pPatch)
	}
	_jsonParseFree(tls, pTarget)
}

// C documentation
//
//	/*
//	** Implementation of the json_object(NAME,VALUE,...) function.  Return a JSON
//	** object that contains all name/value given in arguments.  Or if any name
//	** is not a string or if any value is a BLOB, throw an error.
//	*/
func _jsonObjectFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var i int32
	var n Tu32
	var z uintptr
	var _ /* jx at bp+0 */ TJsonString
	_, _, _ = i, n, z
	if argc&int32(1) != 0 {
		Xsqlite3_result_error(tls, ctx, __ccgo_ts+26564, -int32(1))
		return
	}
	_jsonStringInit(tls, bp, ctx)
	_jsonAppendChar(tls, bp, int8('{'))
	i = 0
	for {
		if !(i < argc) {
			break
		}
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))) != int32(SQLITE_TEXT) {
			Xsqlite3_result_error(tls, ctx, __ccgo_ts+26615, -int32(1))
			_jsonStringReset(tls, bp)
			return
		}
		_jsonAppendSeparator(tls, bp)
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		n = uint32(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4))))
		_jsonAppendString(tls, bp, z, n)
		_jsonAppendChar(tls, bp, int8(':'))
		_jsonAppendSqlValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv + uintptr(i+int32(1))*4)))
		goto _1
	_1:
		;
		i += int32(2)
	}
	_jsonAppendChar(tls, bp, int8('}'))
	_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

// C documentation
//
//	/*
//	** json_remove(JSON, PATH, ...)
//	**
//	** Remove the named elements from JSON and return the result.  malformed
//	** JSON or PATH arguments result in an error.
//	*/
func _jsonRemoveFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var i, v1 int32
	var p, zPath uintptr
	var rc Tu32
	_, _, _, _, _ = i, p, rc, zPath, v1 /* The parse */
	zPath = uintptr(0)                  /* Subroutine return code */
	if argc < int32(1) {
		return
	}
	if argc > int32(1) {
		v1 = int32(JSON_EDITABLE)
	} else {
		v1 = 0
	}
	p = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(v1))
	if p == uintptr(0) {
		return
	}
	i = int32(1)
	for {
		if !(i < argc) {
			break
		}
		zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
		if zPath == uintptr(0) {
			goto json_remove_done
		}
		if int32(*(*int8)(unsafe.Pointer(zPath))) != int32('$') {
			goto json_remove_patherror
		}
		if int32(*(*int8)(unsafe.Pointer(zPath + 1))) == 0 {
			/* json_remove(j,'$') returns NULL */
			goto json_remove_done
		}
		(*TJsonParse)(unsafe.Pointer(p)).FeEdit = uint8(JEDIT_DEL)
		(*TJsonParse)(unsafe.Pointer(p)).Fdelta = 0
		rc = _jsonLookupStep(tls, p, uint32(0), zPath+uintptr(1), uint32(0))
		if rc >= uint32(JSON_LOOKUP_PATHERROR) {
			if rc == uint32(JSON_LOOKUP_NOTFOUND) {
				goto _2 /* No-op */
			} else {
				if rc == uint32(JSON_LOOKUP_PATHERROR) {
					_jsonBadPathError(tls, ctx, zPath)
				} else {
					Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
				}
			}
			goto json_remove_done
		}
		goto _2
	_2:
		;
		i++
	}
	_jsonReturnParse(tls, ctx, p)
	_jsonParseFree(tls, p)
	return
	goto json_remove_patherror
json_remove_patherror:
	;
	_jsonBadPathError(tls, ctx, zPath)
	goto json_remove_done
json_remove_done:
	;
	_jsonParseFree(tls, p)
	return
}

// C documentation
//
//	/*
//	** json_replace(JSON, PATH, VALUE, ...)
//	**
//	** Replace the value at PATH with VALUE.  If PATH does not already exist,
//	** this routine is a no-op.  If JSON or PATH is malformed, throw an error.
//	*/
func _jsonReplaceFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	if argc < int32(1) {
		return
	}
	if argc&int32(1) == 0 {
		_jsonWrongNumArgs(tls, ctx, __ccgo_ts+17203)
		return
	}
	_jsonInsertIntoBlob(tls, ctx, argc, argv, int32(JEDIT_REPL))
}

// C documentation
//
//	/*
//	** json_set(JSON, PATH, VALUE, ...)
//	**
//	** Set the value at PATH to VALUE.  Create the PATH if it does not already
//	** exist.  Overwrite existing values that do exist.
//	** If JSON or PATH is malformed, throw an error.
//	**
//	** json_insert(JSON, PATH, VALUE, ...)
//	**
//	** Create PATH and initialize it to VALUE.  If PATH already exists, this
//	** routine is a no-op.  If JSON or PATH is malformed, throw an error.
//	*/
func _jsonSetFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var bIsSet, flags, v2 int32
	var v1 uintptr
	_, _, _, _ = bIsSet, flags, v1, v2
	flags = int32(Xsqlite3_user_data(tls, ctx))
	bIsSet = libc.BoolInt32(flags&int32(JSON_ISSET) != 0)
	if argc < int32(1) {
		return
	}
	if argc&int32(1) == 0 {
		if bIsSet != 0 {
			v1 = __ccgo_ts + 26649
		} else {
			v1 = __ccgo_ts + 26653
		}
		_jsonWrongNumArgs(tls, ctx, v1)
		return
	}
	if bIsSet != 0 {
		v2 = int32(JEDIT_SET)
	} else {
		v2 = int32(JEDIT_INS)
	}
	_jsonInsertIntoBlob(tls, ctx, argc, argv, v2)
}

// C documentation
//
//	/*
//	** json_type(JSON)
//	** json_type(JSON, PATH)
//	**
//	** Return the top-level "type" of a JSON string.  json_type() raises an
//	** error if either the JSON or PATH inputs are not well-formed.
//	*/
func _jsonTypeFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var i Tu32
	var p, zPath uintptr
	_, _, _ = i, p, zPath /* The parse */
	zPath = uintptr(0)
	p = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(0))
	if p == uintptr(0) {
		return
	}
	if argc == int32(2) {
		zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		if zPath == uintptr(0) {
			goto json_type_done
		}
		if int32(*(*int8)(unsafe.Pointer(zPath))) != int32('$') {
			_jsonBadPathError(tls, ctx, zPath)
			goto json_type_done
		}
		i = _jsonLookupStep(tls, p, uint32(0), zPath+uintptr(1), uint32(0))
		if i >= uint32(JSON_LOOKUP_PATHERROR) {
			if i == uint32(JSON_LOOKUP_NOTFOUND) {
				/* no-op */
			} else {
				if i == uint32(JSON_LOOKUP_PATHERROR) {
					_jsonBadPathError(tls, ctx, zPath)
				} else {
					Xsqlite3_result_error(tls, ctx, __ccgo_ts+26392, -int32(1))
				}
			}
			goto json_type_done
		}
	} else {
		i = uint32(0)
	}
	Xsqlite3_result_text(tls, ctx, _jsonbType[int32(*(*Tu8)(unsafe.Pointer((*TJsonParse)(unsafe.Pointer(p)).FaBlob + uintptr(i))))&int32(0x0f)], -int32(1), libc.UintptrFromInt32(0))
	goto json_type_done
json_type_done:
	;
	_jsonParseFree(tls, p)
}

// C documentation
//
//	/*
//	** json_pretty(JSON)
//	** json_pretty(JSON, INDENT)
//	**
//	** Return text that is a pretty-printed rendering of the input JSON.
//	** If the argument is not valid JSON, return NULL.
//	**
//	** The INDENT argument is text that is used for indentation.  If omitted,
//	** it defaults to four spaces (the same as PostgreSQL).
//	*/
func _jsonPrettyFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var v1 uintptr
	var v2 bool
	var _ /* s at bp+0 */ TJsonString
	var _ /* x at bp+128 */ TJsonPretty
	_, _ = v1, v2 /* Pretty printing context */
	libc.Xmemset(tls, bp+128, 0, uint32(20))
	(*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FpParse = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(0))
	if (*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FpParse == uintptr(0) {
		return
	}
	(*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FpOut = bp
	_jsonStringInit(tls, bp, ctx)
	if v2 = argc == int32(1); !v2 {
		v1 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		(*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FzIndent = v1
	}
	if v2 || v1 == uintptr(0) {
		(*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FzIndent = __ccgo_ts + 26660
		(*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FszIndent = uint32(4)
	} else {
		(*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FszIndent = libc.Xstrlen(tls, (*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FzIndent)
	}
	_jsonTranslateBlobToPrettyText(tls, bp+128, uint32(0))
	_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
	_jsonParseFree(tls, (*(*TJsonPretty)(unsafe.Pointer(bp + 128))).FpParse)
}

// C documentation
//
//	/*
//	** json_valid(JSON)
//	** json_valid(JSON, FLAGS)
//	**
//	** Check the JSON argument to see if it is well-formed.  The FLAGS argument
//	** encodes the various constraints on what is meant by "well-formed":
//	**
//	**     0x01      Canonical RFC-8259 JSON text
//	**     0x02      JSON text with optional JSON-5 extensions
//	**     0x04      Superficially appears to be JSONB
//	**     0x08      Strictly well-formed JSONB
//	**
//	** If the FLAGS argument is omitted, it defaults to 1.  Useful values for
//	** FLAGS include:
//	**
//	**    1          Strict canonical JSON text
//	**    2          JSON text perhaps with JSON-5 extensions
//	**    4          Superficially appears to be JSONB
//	**    5          Canonical JSON text or superficial JSONB
//	**    6          JSON-5 text or superficial JSONB
//	**    8          Strict JSONB
//	**    9          Canonical JSON text or strict JSONB
//	**    10         JSON-5 text or strict JSONB
//	**
//	** Other flag combinations are redundant.  For example, every canonical
//	** JSON text is also well-formed JSON-5 text, so FLAG values 2 and 3
//	** are the same.  Similarly, any input that passes a strict JSONB validation
//	** will also pass the superficial validation so 12 through 15 are the same
//	** as 8 through 11 respectively.
//	**
//	** This routine runs in linear time to validate text and when doing strict
//	** JSONB validation.  Superficial JSONB validation is constant time,
//	** assuming the BLOB is already in memory.  The performance advantage
//	** of superficial JSONB validation is why that option is provided.
//	** Application developers can choose to do fast superficial validation or
//	** slower strict validation, according to their specific needs.
//	**
//	** Only the lower four bits of the FLAGS argument are currently used.
//	** Higher bits are reserved for future expansion.   To facilitate
//	** compatibility, the current implementation raises an error if any bit
//	** in FLAGS is set other than the lower four bits.
//	**
//	** The original circa 2015 implementation of the JSON routines in
//	** SQLite only supported canonical RFC-8259 JSON text and the json_valid()
//	** function only accepted one argument.  That is why the default value
//	** for the FLAGS argument is 1, since FLAGS=1 causes this routine to only
//	** recognize canonical RFC-8259 JSON text as valid.  The extra FLAGS
//	** argument was added when the JSON routines were extended to support
//	** JSON5-like extensions and binary JSONB stored in BLOBs.
//	**
//	** Return Values:
//	**
//	**   *   Raise an error if FLAGS is outside the range of 1 to 15.
//	**   *   Return NULL if the input is NULL
//	**   *   Return 1 if the input is well-formed.
//	**   *   Return 0 if the input is not well-formed.
//	*/
func _jsonValidFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var f Ti64
	var flags, res Tu8
	var iErr Tu32
	var p uintptr
	var _ /* px at bp+0 */ TJsonParse
	var _ /* px at bp+56 */ TJsonParse
	_, _, _, _, _ = f, flags, iErr, p, res /* The parse */
	flags = uint8(1)
	res = uint8(0)
	if argc == int32(2) {
		f = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		if f < int64(1) || f > int64(15) {
			Xsqlite3_result_error(tls, ctx, __ccgo_ts+26665, -int32(1))
			return
		}
		flags = uint8(f & int64(0x0f))
	}
	switch Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case int32(SQLITE_NULL):
		return
	case int32(SQLITE_BLOB):
		if _jsonFuncArgMightBeBinary(tls, *(*uintptr)(unsafe.Pointer(argv))) != 0 {
			if int32(int32(flags))&int32(0x04) != 0 {
				/* Superficial checking only - accomplished by the
				 ** jsonFuncArgMightBeBinary() call above. */
				res = uint8(1)
			} else {
				if int32(int32(flags))&int32(0x08) != 0 {
					libc.Xmemset(tls, bp, 0, uint32(56))
					(*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
					(*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob = uint32(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
					iErr = _jsonbValidityCheck(tls, bp, uint32(0), (*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob, uint32(1))
					res = libc.BoolUint8(iErr == uint32(0))
				}
			}
			break
		}
		fallthrough
	default:
		if int32(int32(flags))&int32(0x3) == 0 {
			break
		}
		libc.Xmemset(tls, bp+56, 0, uint32(56))
		p = _jsonParseFuncArg(tls, ctx, *(*uintptr)(unsafe.Pointer(argv)), uint32(JSON_KEEPERROR))
		if p != 0 {
			if (*TJsonParse)(unsafe.Pointer(p)).Foom != 0 {
				Xsqlite3_result_error_nomem(tls, ctx)
			} else {
				if (*TJsonParse)(unsafe.Pointer(p)).FnErr != 0 {
					/* no-op */
				} else {
					if int32(int32(flags))&int32(0x02) != 0 || int32((*TJsonParse)(unsafe.Pointer(p)).FhasNonstd) == 0 {
						res = uint8(1)
					}
				}
			}
			_jsonParseFree(tls, p)
		} else {
			Xsqlite3_result_error_nomem(tls, ctx)
		}
		break
	}
	Xsqlite3_result_int(tls, ctx, int32(int32(res)))
}

// C documentation
//
//	/*
//	** json_error_position(JSON)
//	**
//	** If the argument is NULL, return NULL
//	**
//	** If the argument is BLOB, do a full validity check and return non-zero
//	** if the check fails.  The return value is the approximate 1-based offset
//	** to the byte of the element that contains the first error.
//	**
//	** Otherwise interpret the argument is TEXT (even if it is numeric) and
//	** return the 1-based character position for where the parser first recognized
//	** that the input was not valid JSON, or return 0 if the input text looks
//	** ok.  JSON-5 extensions are accepted.
//	*/
func _jsonErrorFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var iErrPos Ti64
	var k Tu32
	var _ /* s at bp+0 */ TJsonParse
	_, _ = iErrPos, k
	iErrPos = 0
	_ = argc
	libc.Xmemset(tls, bp, 0, uint32(56))
	(*(*TJsonParse)(unsafe.Pointer(bp))).Fdb = Xsqlite3_context_db_handle(tls, ctx)
	if _jsonFuncArgMightBeBinary(tls, *(*uintptr)(unsafe.Pointer(argv))) != 0 {
		(*(*TJsonParse)(unsafe.Pointer(bp))).FaBlob = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
		(*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob = uint32(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
		iErrPos = int64(_jsonbValidityCheck(tls, bp, uint32(0), (*(*TJsonParse)(unsafe.Pointer(bp))).FnBlob, uint32(1)))
	} else {
		(*(*TJsonParse)(unsafe.Pointer(bp))).FzJson = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if (*(*TJsonParse)(unsafe.Pointer(bp))).FzJson == uintptr(0) {
			return
		} /* NULL input or OOM */
		(*(*TJsonParse)(unsafe.Pointer(bp))).FnJson = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if _jsonConvertTextToBlob(tls, bp, uintptr(0)) != 0 {
			if (*(*TJsonParse)(unsafe.Pointer(bp))).Foom != 0 {
				iErrPos = int64(-int32(1))
			} else {
				/* Because s.oom is false */
				k = uint32(0)
				for {
					if !(k < (*(*TJsonParse)(unsafe.Pointer(bp))).FiErr && *(*int8)(unsafe.Pointer((*(*TJsonParse)(unsafe.Pointer(bp))).FzJson + uintptr(k))) != 0) {
						break
					}
					if int32(*(*int8)(unsafe.Pointer((*(*TJsonParse)(unsafe.Pointer(bp))).FzJson + uintptr(k))))&int32(0xc0) != int32(0x80) {
						iErrPos++
					}
					goto _1
				_1:
					;
					k++
				}
				iErrPos++
			}
		}
	}
	_jsonParseReset(tls, bp)
	if iErrPos < 0 {
		Xsqlite3_result_error_nomem(tls, ctx)
	} else {
		Xsqlite3_result_int64(tls, ctx, iErrPos)
	}
}

// C documentation
//
//	/****************************************************************************
//	** Aggregate SQL function implementations
//	****************************************************************************/
//	/*
//	** json_group_array(VALUE)
//	**
//	** Return a JSON array composed of all values in the aggregate.
//	*/
func _jsonArrayStep(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var pStr uintptr
	_ = pStr
	_ = argc
	pStr = Xsqlite3_aggregate_context(tls, ctx, int32(128))
	if pStr != 0 {
		if (*TJsonString)(unsafe.Pointer(pStr)).FzBuf == uintptr(0) {
			_jsonStringInit(tls, pStr, ctx)
			_jsonAppendChar(tls, pStr, int8('['))
		} else {
			if (*TJsonString)(unsafe.Pointer(pStr)).FnUsed > uint64(1) {
				_jsonAppendChar(tls, pStr, int8(','))
			}
		}
		(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		_jsonAppendSqlValue(tls, pStr, *(*uintptr)(unsafe.Pointer(argv)))
	}
}

func _jsonArrayCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
	var flags int32
	var pStr uintptr
	var v1 Tsqlite3_destructor_type
	_, _, _ = flags, pStr, v1
	pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
	if pStr != 0 {
		(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		_jsonAppendChar(tls, pStr, int8(']'))
		flags = int32(Xsqlite3_user_data(tls, ctx))
		if (*TJsonString)(unsafe.Pointer(pStr)).FeErr != 0 {
			_jsonReturnString(tls, pStr, uintptr(0), uintptr(0))
			return
		} else {
			if flags&int32(JSON_BLOB) != 0 {
				_jsonReturnStringAsBlob(tls, pStr)
				if isFinal != 0 {
					if !((*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0) {
						_sqlite3RCStrUnref(tls, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf)
					}
				} else {
					_jsonStringTrimOneChar(tls, pStr)
				}
				return
			} else {
				if isFinal != 0 {
					if (*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0 {
						v1 = uintptr(-libc.Int32FromInt32(1))
					} else {
						v1 = __ccgo_fp(_sqlite3RCStrUnref)
					}
					Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), v1)
					(*TJsonString)(unsafe.Pointer(pStr)).FbStatic = uint8(1)
				} else {
					Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), uintptr(-libc.Int32FromInt32(1)))
					_jsonStringTrimOneChar(tls, pStr)
				}
			}
		}
	} else {
		Xsqlite3_result_text(tls, ctx, __ccgo_ts+26722, int32(2), libc.UintptrFromInt32(0))
	}
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

func _jsonArrayValue(tls *libc.TLS, ctx uintptr) {
	_jsonArrayCompute(tls, ctx, 0)
}

func _jsonArrayFinal(tls *libc.TLS, ctx uintptr) {
	_jsonArrayCompute(tls, ctx, int32(1))
}

// C documentation
//
//	/*
//	** This method works for both json_group_array() and json_group_object().
//	** It works by removing the first element of the group by searching forward
//	** to the first comma (",") that is not within a string and deleting all
//	** text through that comma.
//	*/
func _jsonGroupInverse(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var c, v2 int8
	var i uint32
	var inStr, nNest int32
	var pStr, z uintptr
	var v3 bool
	_, _, _, _, _, _, _, _ = c, i, inStr, nNest, pStr, z, v2, v3
	inStr = 0
	nNest = 0
	_ = argc
	_ = argv
	pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
	/* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
	 ** always have been called to initialize it */
	if !(pStr != 0) {
		return
	}
	z = (*TJsonString)(unsafe.Pointer(pStr)).FzBuf
	i = uint32(1)
	for {
		if v3 = uint64(uint64(i)) < (*TJsonString)(unsafe.Pointer(pStr)).FnUsed; v3 {
			v2 = *(*int8)(unsafe.Pointer(z + uintptr(i)))
			c = v2
		}
		if !(v3 && (int32(v2) != int32(',') || inStr != 0 || nNest != 0)) {
			break
		}
		if int32(int32(c)) == int32('"') {
			inStr = libc.BoolInt32(!(inStr != 0))
		} else {
			if int32(int32(c)) == int32('\\') {
				i++
			} else {
				if !(inStr != 0) {
					if int32(int32(c)) == int32('{') || int32(int32(c)) == int32('[') {
						nNest++
					}
					if int32(int32(c)) == int32('}') || int32(int32(c)) == int32(']') {
						nNest--
					}
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	if uint64(uint64(i)) < (*TJsonString)(unsafe.Pointer(pStr)).FnUsed {
		*(*Tu64)(unsafe.Pointer(pStr + 16)) -= uint64(uint64(i))
		libc.Xmemmove(tls, z+1, z+uintptr(i+uint32(1)), uint32((*TJsonString)(unsafe.Pointer(pStr)).FnUsed)-uint32(1))
		*(*int8)(unsafe.Pointer(z + uintptr((*TJsonString)(unsafe.Pointer(pStr)).FnUsed))) = 0
	} else {
		(*TJsonString)(unsafe.Pointer(pStr)).FnUsed = uint64(1)
	}
}

// C documentation
//
//	/*
//	** json_group_obj(NAME,VALUE)
//	**
//	** Return a JSON object composed of all names and values in the aggregate.
//	*/
func _jsonObjectStep(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var n Tu32
	var pStr, z uintptr
	_, _, _ = n, pStr, z
	_ = argc
	pStr = Xsqlite3_aggregate_context(tls, ctx, int32(128))
	if pStr != 0 {
		if (*TJsonString)(unsafe.Pointer(pStr)).FzBuf == uintptr(0) {
			_jsonStringInit(tls, pStr, ctx)
			_jsonAppendChar(tls, pStr, int8('{'))
		} else {
			if (*TJsonString)(unsafe.Pointer(pStr)).FnUsed > uint64(1) {
				_jsonAppendChar(tls, pStr, int8(','))
			}
		}
		(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		n = uint32(_sqlite3Strlen30(tls, z))
		_jsonAppendString(tls, pStr, z, n)
		_jsonAppendChar(tls, pStr, int8(':'))
		_jsonAppendSqlValue(tls, pStr, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	}
}

func _jsonObjectCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
	var flags int32
	var pStr uintptr
	var v1 Tsqlite3_destructor_type
	_, _, _ = flags, pStr, v1
	pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
	if pStr != 0 {
		_jsonAppendChar(tls, pStr, int8('}'))
		(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		flags = int32(Xsqlite3_user_data(tls, ctx))
		if (*TJsonString)(unsafe.Pointer(pStr)).FeErr != 0 {
			_jsonReturnString(tls, pStr, uintptr(0), uintptr(0))
			return
		} else {
			if flags&int32(JSON_BLOB) != 0 {
				_jsonReturnStringAsBlob(tls, pStr)
				if isFinal != 0 {
					if !((*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0) {
						_sqlite3RCStrUnref(tls, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf)
					}
				} else {
					_jsonStringTrimOneChar(tls, pStr)
				}
				return
			} else {
				if isFinal != 0 {
					if (*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0 {
						v1 = uintptr(-libc.Int32FromInt32(1))
					} else {
						v1 = __ccgo_fp(_sqlite3RCStrUnref)
					}
					Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), v1)
					(*TJsonString)(unsafe.Pointer(pStr)).FbStatic = uint8(1)
				} else {
					Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), uintptr(-libc.Int32FromInt32(1)))
					_jsonStringTrimOneChar(tls, pStr)
				}
			}
		}
	} else {
		Xsqlite3_result_text(tls, ctx, __ccgo_ts+26725, int32(2), libc.UintptrFromInt32(0))
	}
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

func _jsonObjectValue(tls *libc.TLS, ctx uintptr) {
	_jsonObjectCompute(tls, ctx, 0)
}

func _jsonObjectFinal(tls *libc.TLS, ctx uintptr) {
	_jsonObjectCompute(tls, ctx, int32(1))
}

// C documentation
//
//	/****************************************************************************
//	** The json_each virtual table
//	****************************************************************************/
type TJsonParent = struct {
	F__ccgo_align [0]uint32
	FiHead        Tu32
	FiValue       Tu32
	FiEnd         Tu32
	FnPath        Tu32
	FiKey         Ti64
}

type JsonParent = TJsonParent

type TJsonParent1 = struct {
	F__ccgo_align [0]uint32
	FiHead        Tu32
	FiValue       Tu32
	FiEnd         Tu32
	FnPath        Tu32
	FiKey         Ti64
}

type JsonParent1 = TJsonParent1

type TJsonEachCursor = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FiRowid       Tu32
	Fi            Tu32
	FiEnd         Tu32
	FnRoot        Tu32
	FeType        Tu8
	FbRecursive   Tu8
	FnParent      Tu32
	FnParentAlloc Tu32
	FaParent      uintptr
	Fdb           uintptr
	Fpath         TJsonString
	FsParse       TJsonParse
}

type JsonEachCursor = TJsonEachCursor

type TJsonEachCursor1 = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FiRowid       Tu32
	Fi            Tu32
	FiEnd         Tu32
	FnRoot        Tu32
	FeType        Tu8
	FbRecursive   Tu8
	FnParent      Tu32
	FnParentAlloc Tu32
	FaParent      uintptr
	Fdb           uintptr
	Fpath         TJsonString
	FsParse       TJsonParse
}

type JsonEachCursor1 = TJsonEachCursor1

type TJsonEachConnection = struct {
	Fbase Tsqlite3_vtab
	Fdb   uintptr
}

type JsonEachConnection = TJsonEachConnection

type TJsonEachConnection1 = struct {
	Fbase Tsqlite3_vtab
	Fdb   uintptr
}

type JsonEachConnection1 = TJsonEachConnection1

// C documentation
//
//	/* Constructor for the json_each virtual table */
func _jsonEachConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	/* Column numbers */
	/* The xBestIndex method assumes that the JSON and ROOT columns are
	 ** the last two columns in the table.  Should this ever changes, be
	 ** sure to update the xBestIndex method. */
	_ = pzErr
	_ = argv
	_ = argc
	_ = pAux
	rc = Xsqlite3_declare_vtab(tls, db, __ccgo_ts+26728)
	if rc == SQLITE_OK {
		pNew = _sqlite3DbMallocZero(tls, db, uint64(16))
		*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
		(*TJsonEachConnection)(unsafe.Pointer(pNew)).Fdb = db
	}
	return rc
}

// C documentation
//
//	/* destructor for json_each virtual table */
func _jsonEachDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pVtab
	_sqlite3DbFree(tls, (*TJsonEachConnection)(unsafe.Pointer(p)).Fdb, pVtab)
	return SQLITE_OK
}

// C documentation
//
//	/* constructor for a JsonEachCursor object for json_each(). */
func _jsonEachOpenEach(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur, pVtab uintptr
	_, _ = pCur, pVtab
	pVtab = p
	_ = p
	pCur = _sqlite3DbMallocZero(tls, (*TJsonEachConnection)(unsafe.Pointer(pVtab)).Fdb, uint64(224))
	if pCur == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TJsonEachCursor)(unsafe.Pointer(pCur)).Fdb = (*TJsonEachConnection)(unsafe.Pointer(pVtab)).Fdb
	_jsonStringZero(tls, pCur+40)
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return SQLITE_OK
}

// C documentation
//
//	/* constructor for a JsonEachCursor object for json_tree(). */
func _jsonEachOpenTree(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	var rc int32
	_, _ = pCur, rc
	rc = _jsonEachOpenEach(tls, p, ppCursor)
	if rc == SQLITE_OK {
		pCur = *(*uintptr)(unsafe.Pointer(ppCursor))
		(*TJsonEachCursor)(unsafe.Pointer(pCur)).FbRecursive = uint8(1)
	}
	return rc
}

// C documentation
//
//	/* Reset a JsonEachCursor back to its original state.  Free any memory
//	** held. */
func _jsonEachCursorReset(tls *libc.TLS, p uintptr) {
	_jsonParseReset(tls, p+168)
	_jsonStringReset(tls, p+40)
	_sqlite3DbFree(tls, (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb, (*TJsonEachCursor)(unsafe.Pointer(p)).FaParent)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FiRowid = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FaParent = uintptr(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FnParentAlloc = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
}

// C documentation
//
//	/* Destructor for a jsonEachCursor object */
func _jsonEachClose(tls *libc.TLS, cur uintptr) (r int32) {
	var p uintptr
	_ = p
	p = cur
	_jsonEachCursorReset(tls, p)
	_sqlite3DbFree(tls, (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb, cur)
	return SQLITE_OK
}

// C documentation
//
//	/* Return TRUE if the jsonEachCursor object has been advanced off the end
//	** of the JSON object */
func _jsonEachEof(tls *libc.TLS, cur uintptr) (r int32) {
	var p uintptr
	_ = p
	p = cur
	return libc.BoolInt32((*TJsonEachCursor)(unsafe.Pointer(p)).Fi >= (*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd)
}

// C documentation
//
//	/*
//	** If the cursor is currently pointing at the label of a object entry,
//	** then return the index of the value.  For all other cases, return the
//	** current pointer position, which is the value.
//	*/
func _jsonSkipLabel(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var n Tu32
	var _ /* sz at bp+0 */ Tu32
	_ = n
	if int32((*TJsonEachCursor)(unsafe.Pointer(p)).FeType) == int32(JSONB_OBJECT) {
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		n = _jsonbPayloadSize(tls, p+168, (*TJsonEachCursor)(unsafe.Pointer(p)).Fi, bp)
		return int32((*TJsonEachCursor)(unsafe.Pointer(p)).Fi + n + *(*Tu32)(unsafe.Pointer(bp)))
	} else {
		return int32((*TJsonEachCursor)(unsafe.Pointer(p)).Fi)
	}
	return r
}

// C documentation
//
//	/*
//	** Append the path name for the current element.
//	*/
func _jsonAppendPathName(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, k, n Tu32
	var needQuote int32
	var z uintptr
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _, _ = i, k, n, needQuote, z
	if int32((*TJsonEachCursor)(unsafe.Pointer(p)).FeType) == int32(JSONB_ARRAY) {
		_jsonPrintf(tls, int32(30), p+40, __ccgo_ts+26811, libc.VaList(bp+16, (*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent-uint32(1))*24))).FiKey))
	} else {
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		needQuote = 0
		n = _jsonbPayloadSize(tls, p+168, (*TJsonEachCursor)(unsafe.Pointer(p)).Fi, bp)
		k = (*TJsonEachCursor)(unsafe.Pointer(p)).Fi + n
		z = (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(k)
		if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) || !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z)))])&libc.Int32FromInt32(0x02) != 0) {
			needQuote = int32(1)
		} else {
			i = uint32(0)
			for {
				if !(i < *(*Tu32)(unsafe.Pointer(bp))) {
					break
				}
				if !(int32(_sqlite3CtypeMap[uint8(*(*int8)(unsafe.Pointer(z + uintptr(i))))])&libc.Int32FromInt32(0x06) != 0) {
					needQuote = int32(1)
					break
				}
				goto _1
			_1:
				;
				i++
			}
		}
		if needQuote != 0 {
			_jsonPrintf(tls, int32(*(*Tu32)(unsafe.Pointer(bp))+uint32(4)), p+40, __ccgo_ts+26818, libc.VaList(bp+16, *(*Tu32)(unsafe.Pointer(bp)), z))
		} else {
			_jsonPrintf(tls, int32(*(*Tu32)(unsafe.Pointer(bp))+uint32(2)), p+40, __ccgo_ts+26826, libc.VaList(bp+16, *(*Tu32)(unsafe.Pointer(bp)), z))
		}
	}
}

// C documentation
//
//	/* Advance the cursor to the next element for json_tree() */
func _jsonEachNext(tls *libc.TLS, cur uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, i1, iVal, n, n1 Tu32
	var levelChange, x Tu8
	var nNew Tu64
	var p, pNew, pParent, pParent1 uintptr
	var rc int32
	var _ /* sz at bp+0 */ Tu32
	var _ /* sz at bp+4 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = i, i1, iVal, levelChange, n, n1, nNew, p, pNew, pParent, pParent1, rc, x
	p = cur
	rc = SQLITE_OK
	if (*TJsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
		levelChange = uint8(0)
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
		i = uint32(_jsonSkipLabel(tls, p))
		x = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i)))) & int32(0x0f))
		n = _jsonbPayloadSize(tls, p+168, i, bp)
		if int32(int32(x)) == int32(JSONB_OBJECT) || int32(int32(x)) == int32(JSONB_ARRAY) {
			if (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent >= (*TJsonEachCursor)(unsafe.Pointer(p)).FnParentAlloc {
				nNew = uint64((*TJsonEachCursor)(unsafe.Pointer(p)).FnParentAlloc*uint32(2) + uint32(3))
				pNew = _sqlite3DbRealloc(tls, (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb, (*TJsonEachCursor)(unsafe.Pointer(p)).FaParent, uint64(24)*nNew)
				if pNew == uintptr(0) {
					return int32(SQLITE_NOMEM)
				}
				(*TJsonEachCursor)(unsafe.Pointer(p)).FnParentAlloc = uint32(uint32(nNew))
				(*TJsonEachCursor)(unsafe.Pointer(p)).FaParent = pNew
			}
			levelChange = uint8(1)
			pParent = (*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent)*24
			(*TJsonParent)(unsafe.Pointer(pParent)).FiHead = (*TJsonEachCursor)(unsafe.Pointer(p)).Fi
			(*TJsonParent)(unsafe.Pointer(pParent)).FiValue = i
			(*TJsonParent)(unsafe.Pointer(pParent)).FiEnd = i + n + *(*Tu32)(unsafe.Pointer(bp))
			(*TJsonParent)(unsafe.Pointer(pParent)).FiKey = int64(-int32(1))
			(*TJsonParent)(unsafe.Pointer(pParent)).FnPath = uint32((*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FnUsed)
			if (*TJsonEachCursor)(unsafe.Pointer(p)).FeType != 0 && (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent != 0 {
				_jsonAppendPathName(tls, p)
				if (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FeErr != 0 {
					rc = int32(SQLITE_NOMEM)
				}
			}
			(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent++
			(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = i + n
		} else {
			(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = i + n + *(*Tu32)(unsafe.Pointer(bp))
		}
		for (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent > uint32(0) && (*TJsonEachCursor)(unsafe.Pointer(p)).Fi >= (*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent-uint32(1))*24))).FiEnd {
			(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent--
			(*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FnUsed = uint64((*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent)*24))).FnPath)
			levelChange = uint8(1)
		}
		if levelChange != 0 {
			if (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent > uint32(0) {
				pParent1 = (*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent-uint32(1))*24
				iVal = (*TJsonParent)(unsafe.Pointer(pParent1)).FiValue
				(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(iVal)))) & int32(0x0f))
			} else {
				(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
			}
		}
	} else {
		*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0)
		i1 = uint32(_jsonSkipLabel(tls, p))
		n1 = _jsonbPayloadSize(tls, p+168, i1, bp+4)
		(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = i1 + n1 + *(*Tu32)(unsafe.Pointer(bp + 4))
	}
	if int32((*TJsonEachCursor)(unsafe.Pointer(p)).FeType) == int32(JSONB_ARRAY) && (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent != 0 {
		(*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent-uint32(1))*24))).FiKey++
	}
	(*TJsonEachCursor)(unsafe.Pointer(p)).FiRowid++
	return rc
}

// C documentation
//
//	/* Length of the path for rowid==0 in bRecursive mode.
//	*/
func _jsonEachPathLength(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var cSaved int8
	var n, x Tu32
	var z uintptr
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _ = cSaved, n, x, z
	n = uint32((*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FnUsed)
	z = (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf
	if (*TJsonEachCursor)(unsafe.Pointer(p)).FiRowid == uint32(0) && (*TJsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 && n >= uint32(2) {
		for n > uint32(1) {
			n--
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(n)))) == int32('[') || int32(*(*int8)(unsafe.Pointer(z + uintptr(n)))) == int32('.') {
				*(*Tu32)(unsafe.Pointer(bp)) = uint32(0)
				cSaved = *(*int8)(unsafe.Pointer(z + uintptr(n)))
				*(*int8)(unsafe.Pointer(z + uintptr(n))) = 0
				x = _jsonLookupStep(tls, p+168, uint32(0), z+uintptr(1), uint32(0))
				*(*int8)(unsafe.Pointer(z + uintptr(n))) = cSaved
				if x >= uint32(JSON_LOOKUP_PATHERROR) {
					continue
				}
				if x+_jsonbPayloadSize(tls, p+168, x, bp) == (*TJsonEachCursor)(unsafe.Pointer(p)).Fi {
					break
				}
			}
		}
	}
	return int32(int32(n))
}

// C documentation
//
//	/* Return the value of a column */
func _jsonEachColumn(tls *libc.TLS, cur uintptr, ctx uintptr, iColumn int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType Tu8
	var i, i1, i2, j, n, n1 Tu32
	var nBase Tu64
	var p uintptr
	var _ /* x at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _ = eType, i, i1, i2, j, n, n1, nBase, p
	p = cur
	switch iColumn {
	case JEACH_KEY:
		if (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent == uint32(0) {
			if (*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot == uint32(1) {
				break
			}
			j = uint32(_jsonEachPathLength(tls, p))
			n = (*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot - j
			if n == uint32(0) {
				break
			} else {
				if int32(*(*int8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf + uintptr(j)))) == int32('[') {
					_sqlite3Atoi64(tls, (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf+uintptr(j+uint32(1)), bp, int32(n-uint32(1)), uint8(SQLITE_UTF8))
					Xsqlite3_result_int64(tls, ctx, *(*Ti64)(unsafe.Pointer(bp)))
				} else {
					if int32(*(*int8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf + uintptr(j+uint32(1))))) == int32('"') {
						Xsqlite3_result_text(tls, ctx, (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf+uintptr(j+uint32(2)), int32(n-uint32(3)), uintptr(-libc.Int32FromInt32(1)))
					} else {
						Xsqlite3_result_text(tls, ctx, (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf+uintptr(j+uint32(1)), int32(n-uint32(1)), uintptr(-libc.Int32FromInt32(1)))
					}
				}
			}
			break
		}
		if int32((*TJsonEachCursor)(unsafe.Pointer(p)).FeType) == int32(JSONB_OBJECT) {
			_jsonReturnFromBlob(tls, p+168, (*TJsonEachCursor)(unsafe.Pointer(p)).Fi, ctx, int32(1))
		} else {
			Xsqlite3_result_int64(tls, ctx, (*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent-uint32(1))*24))).FiKey)
		}
	case int32(JEACH_VALUE):
		i = uint32(_jsonSkipLabel(tls, p))
		_jsonReturnFromBlob(tls, p+168, i, ctx, int32(1))
		if int32(*(*Tu8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i))))&int32(0x0f) >= int32(JSONB_ARRAY) {
			Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
		}
	case int32(JEACH_TYPE):
		i1 = uint32(_jsonSkipLabel(tls, p))
		eType = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i1)))) & int32(0x0f))
		Xsqlite3_result_text(tls, ctx, _jsonbType[eType], -int32(1), libc.UintptrFromInt32(0))
	case int32(JEACH_ATOM):
		i2 = uint32(_jsonSkipLabel(tls, p))
		if int32(*(*Tu8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i2))))&int32(0x0f) < int32(JSONB_ARRAY) {
			_jsonReturnFromBlob(tls, p+168, i2, ctx, int32(1))
		}
	case int32(JEACH_ID):
		Xsqlite3_result_int64(tls, ctx, int64((*TJsonEachCursor)(unsafe.Pointer(p)).Fi))
	case int32(JEACH_PARENT):
		if (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent > uint32(0) && (*TJsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
			Xsqlite3_result_int64(tls, ctx, int64((*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent-uint32(1))*24))).FiHead))
		}
	case int32(JEACH_FULLKEY):
		nBase = (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FnUsed
		if (*TJsonEachCursor)(unsafe.Pointer(p)).FnParent != 0 {
			_jsonAppendPathName(tls, p)
		}
		Xsqlite3_result_text64(tls, ctx, (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf, (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FnUsed, uintptr(-libc.Int32FromInt32(1)), uint8(SQLITE_UTF8))
		(*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FnUsed = nBase
	case int32(JEACH_PATH):
		n1 = uint32(_jsonEachPathLength(tls, p))
		Xsqlite3_result_text64(tls, ctx, (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf, uint64(uint64(n1)), uintptr(-libc.Int32FromInt32(1)), uint8(SQLITE_UTF8))
	default:
		Xsqlite3_result_text(tls, ctx, (*TJsonEachCursor)(unsafe.Pointer(p)).Fpath.FzBuf, int32((*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot), libc.UintptrFromInt32(0))
	case int32(JEACH_JSON):
		if (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FzJson == uintptr(0) {
			Xsqlite3_result_blob(tls, ctx, (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob, int32((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FnBlob), uintptr(-libc.Int32FromInt32(1)))
		} else {
			Xsqlite3_result_text(tls, ctx, (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FzJson, -int32(1), uintptr(-libc.Int32FromInt32(1)))
		}
		break
	}
	return SQLITE_OK
}

// C documentation
//
//	/* Return the current rowid value */
func _jsonEachRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) (r int32) {
	var p uintptr
	_ = p
	p = cur
	*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = int64((*TJsonEachCursor)(unsafe.Pointer(p)).FiRowid)
	return SQLITE_OK
}

// C documentation
//
//	/* The query strategy is to look for an equality constraint on the json
//	** column.  Without such a constraint, the table cannot operate.  idxNum is
//	** 1 if the constraint is found, 3 if the constraint and zRoot are found,
//	** and 0 otherwise.
//	*/
func _jsonEachBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
	var aIdx [2]int32
	var i, iCol, iMask, idxMask, unusableMask, v1 int32
	var pConstraint uintptr
	_, _, _, _, _, _, _, _ = aIdx, i, iCol, iMask, idxMask, pConstraint, unusableMask, v1 /* Index of constraints for JSON and ROOT */
	unusableMask = 0                                                                      /* Mask of unusable JSON and ROOT constraints */
	idxMask = 0
	/* This implementation assumes that JSON and ROOT are the last two
	 ** columns in the table */
	_ = tab
	v1 = -libc.Int32FromInt32(1)
	aIdx[int32(1)] = v1
	aIdx[0] = v1
	pConstraint = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn < int32(JEACH_JSON) {
			goto _2
		}
		iCol = (*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn - int32(JEACH_JSON)
		iMask = int32(1) << iCol
		if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fusable) == 0 {
			unusableMask |= iMask
		} else {
			if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) {
				aIdx[iCol] = i
				idxMask |= iMask
			}
		}
		goto _2
	_2:
		;
		i++
		pConstraint += 12
	}
	if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy > 0 && (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).FiColumn < 0 && int32((*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).Fdesc) == 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = int32(1)
	}
	if unusableMask & ^idxMask != 0 {
		/* If there are any unusable constraints on JSON or ROOT, then reject
		 ** this entire plan */
		return int32(SQLITE_CONSTRAINT)
	}
	if aIdx[0] < 0 {
		/* No JSON input.  Leave estimatedCost at the huge value that it was
		 ** initialized to to discourage the query planner from selecting this
		 ** plan. */
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 0
	} else {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(1)
		i = aIdx[0]
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = int32(1)
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).Fomit = uint8(1)
		if aIdx[int32(1)] < 0 {
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(1) /* Only JSON supplied.  Plan 1 */
		} else {
			i = aIdx[int32(1)]
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = int32(2)
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).Fomit = uint8(1)
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(3) /* Both JSON and ROOT are supplied.  Plan 3 */
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/* Start a search on a new JSON string */
func _jsonEachFilter(tls *libc.TLS, cur uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, n, v1, v3, v5 Tu32
	var p, zRoot uintptr
	var v2, v4, v6 int32
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _, _, _, _, _, _, _ = i, n, p, zRoot, v1, v2, v3, v4, v5, v6
	p = cur
	zRoot = uintptr(0)
	_ = idxStr
	_ = argc
	_jsonEachCursorReset(tls, p)
	if idxNum == 0 {
		return SQLITE_OK
	}
	libc.Xmemset(tls, p+168, 0, uint32(56))
	(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FnJPRef = uint32(1)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.Fdb = (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb
	if _jsonFuncArgMightBeBinary(tls, *(*uintptr)(unsafe.Pointer(argv))) != 0 {
		(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FnBlob = uint32(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
		(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	} else {
		(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FzJson = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FnJson = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FzJson == uintptr(0) {
			v1 = libc.Uint32FromInt32(0)
			(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = v1
			(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = v1
			return SQLITE_OK
		}
		if _jsonConvertTextToBlob(tls, p+168, uintptr(0)) != 0 {
			if (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.Foom != 0 {
				return int32(SQLITE_NOMEM)
			}
			goto json_each_malformed_input
		}
	}
	if idxNum == int32(3) {
		zRoot = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
		if zRoot == uintptr(0) {
			return SQLITE_OK
		}
		if int32(*(*int8)(unsafe.Pointer(zRoot))) != int32('$') {
			Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
			(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = _jsonBadPathError(tls, uintptr(0), zRoot)
			_jsonEachCursorReset(tls, p)
			if (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
				v2 = int32(SQLITE_ERROR)
			} else {
				v2 = int32(SQLITE_NOMEM)
			}
			return v2
		}
		(*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot = uint32(_sqlite3Strlen30(tls, zRoot))
		if int32(*(*int8)(unsafe.Pointer(zRoot + 1))) == 0 {
			v3 = libc.Uint32FromInt32(0)
			(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = v3
			i = v3
			(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
		} else {
			i = _jsonLookupStep(tls, p+168, uint32(0), zRoot+uintptr(1), uint32(0))
			if i >= uint32(JSON_LOOKUP_PATHERROR) {
				if i == uint32(JSON_LOOKUP_NOTFOUND) {
					(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = uint32(0)
					(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
					(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = uint32(0)
					return SQLITE_OK
				}
				Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
				(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = _jsonBadPathError(tls, uintptr(0), zRoot)
				_jsonEachCursorReset(tls, p)
				if (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
					v4 = int32(SQLITE_ERROR)
				} else {
					v4 = int32(SQLITE_NOMEM)
				}
				return v4
			}
			if (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FiLabel != 0 {
				(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FiLabel
				(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(JSONB_OBJECT)
			} else {
				(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = i
				(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(JSONB_ARRAY)
			}
		}
		_jsonAppendRaw(tls, p+40, zRoot, (*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot)
	} else {
		v5 = libc.Uint32FromInt32(0)
		(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = v5
		i = v5
		(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
		(*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot = uint32(1)
		_jsonAppendRaw(tls, p+40, __ccgo_ts+26832, uint32(1))
	}
	(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent = uint32(0)
	n = _jsonbPayloadSize(tls, p+168, i, bp)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = i + n + *(*Tu32)(unsafe.Pointer(bp))
	if int32(*(*Tu8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i))))&int32(0x0f) >= int32(JSONB_ARRAY) && !((*TJsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0) {
		(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = i + n
		(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(int32(*(*Tu8)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i)))) & int32(0x0f))
		(*TJsonEachCursor)(unsafe.Pointer(p)).FaParent = _sqlite3DbMallocZero(tls, (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb, uint64(24))
		if (*TJsonEachCursor)(unsafe.Pointer(p)).FaParent == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent = uint32(1)
		(*TJsonEachCursor)(unsafe.Pointer(p)).FnParentAlloc = uint32(1)
		(*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiKey = 0
		(*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiEnd = (*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd
		(*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiHead = (*TJsonEachCursor)(unsafe.Pointer(p)).Fi
		(*(*TJsonParent)(unsafe.Pointer((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiValue = i
	}
	return SQLITE_OK
	goto json_each_malformed_input
json_each_malformed_input:
	;
	Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
	(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26392, 0)
	_jsonEachCursorReset(tls, p)
	if (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
		v6 = int32(SQLITE_ERROR)
	} else {
		v6 = int32(SQLITE_NOMEM)
	}
	return v6
}

// C documentation
//
//	/* The methods of the json_each virtual table */
var _jsonEachModule = Tsqlite3_module{}

func init() {
	p := unsafe.Pointer(&_jsonEachModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_jsonEachConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_jsonEachBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_jsonEachDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_jsonEachOpenEach)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_jsonEachClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_jsonEachFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_jsonEachNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_jsonEachEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_jsonEachColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_jsonEachRowid)
}

// C documentation
//
//	/* The methods of the json_tree virtual table. */
var _jsonTreeModule = Tsqlite3_module{}

func init() {
	p := unsafe.Pointer(&_jsonTreeModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_jsonEachConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_jsonEachBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_jsonEachDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_jsonEachOpenTree)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_jsonEachClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_jsonEachFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_jsonEachNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_jsonEachEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_jsonEachColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_jsonEachRowid)
}

// C documentation
//
//	/*
//	** Register JSON functions.
//	*/
func _sqlite3RegisterJsonFunctions(tls *libc.TLS) {
	_sqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&_aJsonFunc)), int32(libc.Uint32FromInt64(1360)/libc.Uint32FromInt64(40)))
}

var _aJsonFunc = [34]TFuncDef{
	0: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26834,
	},
	1: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 26839,
	},
	2: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26845,
	},
	3: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 26856,
	},
	4: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26868,
	},
	5: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26868,
	},
	6: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26886,
	},
	7: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26906,
	},
	8: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 26919,
	},
	9: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(JSON_JSON) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 26933,
	},
	10: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(JSON_SQL) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 26936,
	},
	11: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26940,
	},
	12: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 26952,
	},
	13: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26965,
	},
	14: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 26977,
	},
	15: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26990,
	},
	16: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 27001,
	},
	17: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27013,
	},
	18: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27013,
	},
	19: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27025,
	},
	20: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27036,
	},
	21: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 27048,
	},
	22: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27061,
	},
	23: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 27074,
	},
	24: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(JSON_ISSET) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 27088,
	},
	25: {
		FnArg:      int8(-int32(1)),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(libc.Int32FromInt32(JSON_ISSET) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 27097,
	},
	26: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27107,
	},
	27: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27107,
	},
	28: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27117,
	},
	29: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27117,
	},
	30: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FzName:     __ccgo_ts + 27128,
	},
	31: {
		FnArg:      int8(1),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FpUserData: uintptr(libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 27145,
	},
	32: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FzName:     __ccgo_ts + 27163,
	},
	33: {
		FnArg:      int8(2),
		FfuncFlags: uint32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FpUserData: uintptr(libc.Int32FromInt32(JSON_BLOB)),
		FzName:     __ccgo_ts + 27181,
	},
}

func init() {
	p := unsafe.Pointer(&_aJsonFunc)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_jsonArrayFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_jsonArrayFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_jsonArrayLengthFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_jsonArrayLengthFunc)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_jsonErrorFunc)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(_jsonObjectFunc)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(_jsonObjectFunc)
	*(*uintptr)(unsafe.Add(p, 616)) = __ccgo_fp(_jsonPatchFunc)
	*(*uintptr)(unsafe.Add(p, 656)) = __ccgo_fp(_jsonPatchFunc)
	*(*uintptr)(unsafe.Add(p, 696)) = __ccgo_fp(_jsonPrettyFunc)
	*(*uintptr)(unsafe.Add(p, 736)) = __ccgo_fp(_jsonPrettyFunc)
	*(*uintptr)(unsafe.Add(p, 776)) = __ccgo_fp(_jsonQuoteFunc)
	*(*uintptr)(unsafe.Add(p, 816)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 856)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 896)) = __ccgo_fp(_jsonReplaceFunc)
	*(*uintptr)(unsafe.Add(p, 936)) = __ccgo_fp(_jsonReplaceFunc)
	*(*uintptr)(unsafe.Add(p, 976)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 1016)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 1056)) = __ccgo_fp(_jsonTypeFunc)
	*(*uintptr)(unsafe.Add(p, 1096)) = __ccgo_fp(_jsonTypeFunc)
	*(*uintptr)(unsafe.Add(p, 1136)) = __ccgo_fp(_jsonValidFunc)
	*(*uintptr)(unsafe.Add(p, 1176)) = __ccgo_fp(_jsonValidFunc)
	*(*uintptr)(unsafe.Add(p, 1216)) = __ccgo_fp(_jsonArrayStep)
	*(*uintptr)(unsafe.Add(p, 1220)) = __ccgo_fp(_jsonArrayFinal)
	*(*uintptr)(unsafe.Add(p, 1224)) = __ccgo_fp(_jsonArrayValue)
	*(*uintptr)(unsafe.Add(p, 1228)) = __ccgo_fp(_jsonGroupInverse)
	*(*uintptr)(unsafe.Add(p, 1256)) = __ccgo_fp(_jsonArrayStep)
	*(*uintptr)(unsafe.Add(p, 1260)) = __ccgo_fp(_jsonArrayFinal)
	*(*uintptr)(unsafe.Add(p, 1264)) = __ccgo_fp(_jsonArrayValue)
	*(*uintptr)(unsafe.Add(p, 1268)) = __ccgo_fp(_jsonGroupInverse)
	*(*uintptr)(unsafe.Add(p, 1296)) = __ccgo_fp(_jsonObjectStep)
	*(*uintptr)(unsafe.Add(p, 1300)) = __ccgo_fp(_jsonObjectFinal)
	*(*uintptr)(unsafe.Add(p, 1304)) = __ccgo_fp(_jsonObjectValue)
	*(*uintptr)(unsafe.Add(p, 1308)) = __ccgo_fp(_jsonGroupInverse)
	*(*uintptr)(unsafe.Add(p, 1336)) = __ccgo_fp(_jsonObjectStep)
	*(*uintptr)(unsafe.Add(p, 1340)) = __ccgo_fp(_jsonObjectFinal)
	*(*uintptr)(unsafe.Add(p, 1344)) = __ccgo_fp(_jsonObjectValue)
	*(*uintptr)(unsafe.Add(p, 1348)) = __ccgo_fp(_jsonGroupInverse)
}

// C documentation
//
//	/*
//	** Register the JSON table-valued functions
//	*/
func _sqlite3JsonTableFunctions(tls *libc.TLS, db uintptr) (r int32) {
	var i uint32
	var rc int32
	_, _ = i, rc
	rc = SQLITE_OK
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(16)/libc.Uint32FromInt64(8) && rc == SQLITE_OK) {
			break
		}
		rc = Xsqlite3_create_module(tls, db, _aMod[i].FzName, _aMod[i].FpModule, uintptr(0))
		goto _1
	_1:
		;
		i++
	}
	return rc
}

var _aMod = [2]struct {
	FzName   uintptr
	FpModule uintptr
}{
	0: {
		FzName:   __ccgo_ts + 27200,
		FpModule: uintptr(unsafe.Pointer(&_jsonEachModule)),
	},
	1: {
		FzName:   __ccgo_ts + 27210,
		FpModule: uintptr(unsafe.Pointer(&_jsonTreeModule)),
	},
}

/* In the SQLite core */

/*
** If building separately, we will need some setup that is normally
** found in sqliteInt.h
 */

/* Macro to check for 4-byte alignment.  Only used inside of assert() */

/* #include <string.h> */
/* #include <stdio.h> */
/* #include <assert.h> */
/* #include <stdlib.h> */

/*  The following macro is used to suppress compiler warnings.
 */

type TRtree = struct {
	F__ccgo_align  [0]uint32
	Fbase          Tsqlite3_vtab
	Fdb            uintptr
	FiNodeSize     int32
	FnDim          Tu8
	FnDim2         Tu8
	FeCoordType    Tu8
	FnBytesPerCell Tu8
	FinWrTrans     Tu8
	FnAux          Tu8
	FnAuxNotNull   Tu8
	FiDepth        int32
	FzDb           uintptr
	FzName         uintptr
	FzNodeName     uintptr
	FnBusy         Tu32
	FnRowEst       Ti64
	FnCursor       Tu32
	FnNodeRef      Tu32
	FzReadAuxSql   uintptr
	FpDeleted      uintptr
	FpNodeBlob     uintptr
	FpWriteNode    uintptr
	FpDeleteNode   uintptr
	FpReadRowid    uintptr
	FpWriteRowid   uintptr
	FpDeleteRowid  uintptr
	FpReadParent   uintptr
	FpWriteParent  uintptr
	FpDeleteParent uintptr
	FpWriteAux     uintptr
	FaHash         [97]uintptr
	F__ccgo_pad31  [4]byte
}

type Rtree = TRtree

type TRtreeCursor = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FatEOF        Tu8
	FbPoint       Tu8
	FbAuxValid    Tu8
	FiStrategy    int32
	FnConstraint  int32
	FaConstraint  uintptr
	FnPointAlloc  int32
	FnPoint       int32
	FmxLevel      int32
	FaPoint       uintptr
	FpReadAux     uintptr
	FsPoint       TRtreeSearchPoint
	FaNode        [5]uintptr
	FanQueue      [41]Tu32
}

type RtreeCursor = TRtreeCursor

type TRtreeNode = struct {
	F__ccgo_align  [0]uint32
	FpParent       uintptr
	F__ccgo_align1 [4]byte
	FiNode         Ti64
	FnRef          int32
	FisDirty       int32
	FzData         uintptr
	FpNext         uintptr
}

type RtreeNode = TRtreeNode

type TRtreeCell = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FaCoord       [10]TRtreeCoord
}

type RtreeCell = TRtreeCell

type TRtreeConstraint = struct {
	F__ccgo_align [0]uint32
	FiCoord       int32
	Fop           int32
	Fu            struct {
		F__ccgo_align [0]uint32
		FxGeom        [0]uintptr
		FxQueryFunc   [0]uintptr
		FrValue       TRtreeDValue
	}
	FpInfo       uintptr
	F__ccgo_pad4 [4]byte
}

type RtreeConstraint = TRtreeConstraint

type TRtreeMatchArg = struct {
	F__ccgo_align  [0]uint32
	FiSize         Tu32
	Fcb            TRtreeGeomCallback
	FnParam        int32
	FapSqlParam    uintptr
	F__ccgo_align4 [4]byte
	FaParam        [1]TRtreeDValue
}

type RtreeMatchArg = TRtreeMatchArg

type TRtreeGeomCallback = struct {
	FxGeom       uintptr
	FxQueryFunc  uintptr
	FxDestructor uintptr
	FpContext    uintptr
}

type RtreeGeomCallback = TRtreeGeomCallback

type TRtreeCoord = struct {
	Fi [0]int32
	Fu [0]Tu32
	Ff TRtreeValue
}

type RtreeCoord = TRtreeCoord

type TRtreeSearchPoint = struct {
	F__ccgo_align [0]uint32
	FrScore       TRtreeDValue
	Fid           Tsqlite3_int64
	FiLevel       Tu8
	FeWithin      Tu8
	FiCell        Tu8
	F__ccgo_pad5  [5]byte
}

type RtreeSearchPoint = TRtreeSearchPoint

/* The rtree may have between 1 and RTREE_MAX_DIMENSIONS dimensions. */

/* Maximum number of auxiliary columns */

/* Size of hash table Rtree.aHash. This hash table is not expected to
** ever contain very many entries, so a fixed number of buckets is
** used.
 */

/* The xBestIndex method of this virtual table requires an estimate of
** the number of rows in the virtual table to calculate the costs of
** various strategies. If possible, this estimate is loaded from the
** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
** Otherwise, if no sqlite_stat1 entry is available, use
** RTREE_DEFAULT_ROWEST.
 */

/*
** An rtree virtual-table object.
 */
type TRtree1 = struct {
	F__ccgo_align  [0]uint32
	Fbase          Tsqlite3_vtab
	Fdb            uintptr
	FiNodeSize     int32
	FnDim          Tu8
	FnDim2         Tu8
	FeCoordType    Tu8
	FnBytesPerCell Tu8
	FinWrTrans     Tu8
	FnAux          Tu8
	FnAuxNotNull   Tu8
	FiDepth        int32
	FzDb           uintptr
	FzName         uintptr
	FzNodeName     uintptr
	FnBusy         Tu32
	FnRowEst       Ti64
	FnCursor       Tu32
	FnNodeRef      Tu32
	FzReadAuxSql   uintptr
	FpDeleted      uintptr
	FpNodeBlob     uintptr
	FpWriteNode    uintptr
	FpDeleteNode   uintptr
	FpReadRowid    uintptr
	FpWriteRowid   uintptr
	FpDeleteRowid  uintptr
	FpReadParent   uintptr
	FpWriteParent  uintptr
	FpDeleteParent uintptr
	FpWriteAux     uintptr
	FaHash         [97]uintptr
	F__ccgo_pad31  [4]byte
}

type Rtree1 = TRtree1

/* Possible values for Rtree.eCoordType: */

// C documentation
//
//	/*
//	** If SQLITE_RTREE_INT_ONLY is defined, then this virtual table will
//	** only deal with integer coordinates.  No floating point operations
//	** will be done.
//	*/
type TRtreeDValue = float64

type RtreeDValue = TRtreeDValue

/* High accuracy coordinate */

type TRtreeValue = float32

type RtreeValue = TRtreeValue

/* Low accuracy coordinate */

/*
** Set the Rtree.bCorrupt flag
 */

/*
** When doing a search of an r-tree, instances of the following structure
** record intermediate results from the tree walk.
**
** The id is always a node-id.  For iLevel>=1 the id is the node-id of
** the node that the RtreeSearchPoint represents.  When iLevel==0, however,
** the id is of the parent node and the cell that RtreeSearchPoint
** represents is the iCell-th entry in the parent node.
 */
type TRtreeSearchPoint1 = struct {
	F__ccgo_align [0]uint32
	FrScore       TRtreeDValue
	Fid           Tsqlite3_int64
	FiLevel       Tu8
	FeWithin      Tu8
	FiCell        Tu8
	F__ccgo_pad5  [5]byte
}

type RtreeSearchPoint1 = TRtreeSearchPoint1

/*
** The minimum number of cells allowed for a node is a third of the
** maximum. In Gutman's notation:
**
**     m = M/3
**
** If an R*-tree "Reinsert" operation is required, the same number of
** cells are removed from the overfull node and reinserted into the tree.
 */

/*
** The smallest possible node-size is (512-64)==448 bytes. And the largest
** supported cell size is 48 bytes (8 byte rowid + ten 4 byte coordinates).
** Therefore all non-root nodes must contain at least 3 entries. Since
** 3^40 is greater than 2^64, an r-tree structure always has a depth of
** 40 or less.
 */

/*
** Number of entries in the cursor RtreeNode cache.  The first entry is
** used to cache the RtreeNode for RtreeCursor.sPoint.  The remaining
** entries cache the RtreeNode for the first elements of the priority queue.
 */

/*
** An rtree cursor object.
 */
type TRtreeCursor1 = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FatEOF        Tu8
	FbPoint       Tu8
	FbAuxValid    Tu8
	FiStrategy    int32
	FnConstraint  int32
	FaConstraint  uintptr
	FnPointAlloc  int32
	FnPoint       int32
	FmxLevel      int32
	FaPoint       uintptr
	FpReadAux     uintptr
	FsPoint       TRtreeSearchPoint
	FaNode        [5]uintptr
	FanQueue      [41]Tu32
}

type RtreeCursor1 = TRtreeCursor1

/* Return the Rtree of a RtreeCursor */

/*
** A coordinate can be either a floating point number or a integer.  All
** coordinates within a single R-Tree are always of the same time.
 */
type TRtreeCoord1 = struct {
	Fi [0]int32
	Fu [0]Tu32
	Ff TRtreeValue
}

type RtreeCoord1 = TRtreeCoord1

/*
** The argument is an RtreeCoord. Return the value stored within the RtreeCoord
** formatted as a RtreeDValue (double or int64). This macro assumes that local
** variable pRtree points to the Rtree structure associated with the
** RtreeCoord.
 */

/*
** A search constraint.
 */
type TRtreeConstraint1 = struct {
	F__ccgo_align [0]uint32
	FiCoord       int32
	Fop           int32
	Fu            struct {
		F__ccgo_align [0]uint32
		FxGeom        [0]uintptr
		FxQueryFunc   [0]uintptr
		FrValue       TRtreeDValue
	}
	FpInfo       uintptr
	F__ccgo_pad4 [4]byte
}

type RtreeConstraint1 = TRtreeConstraint1

/* Possible values for RtreeConstraint.op */

/* Special operators available only on cursors.  Needs to be consecutive
** with the normal values above, but must be less than RTREE_MATCH.  These
** are used in the cursor for contraints such as x=NULL (RTREE_FALSE) or
** x<'xyz' (RTREE_TRUE) */

/*
** An rtree structure node.
 */
type TRtreeNode1 = struct {
	F__ccgo_align  [0]uint32
	FpParent       uintptr
	F__ccgo_align1 [4]byte
	FiNode         Ti64
	FnRef          int32
	FisDirty       int32
	FzData         uintptr
	FpNext         uintptr
}

type RtreeNode1 = TRtreeNode1

/* Return the number of cells in a node  */

/*
** A single cell from a node, deserialized
 */
type TRtreeCell1 = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FaCoord       [10]TRtreeCoord
}

type RtreeCell1 = TRtreeCell1

/*
** This object becomes the sqlite3_user_data() for the SQL functions
** that are created by sqlite3_rtree_geometry_callback() and
** sqlite3_rtree_query_callback() and which appear on the right of MATCH
** operators in order to constrain a search.
**
** xGeom and xQueryFunc are the callback functions.  Exactly one of
** xGeom and xQueryFunc fields is non-NULL, depending on whether the
** SQL function was created using sqlite3_rtree_geometry_callback() or
** sqlite3_rtree_query_callback().
**
** This object is deleted automatically by the destructor mechanism in
** sqlite3_create_function_v2().
 */
type TRtreeGeomCallback1 = struct {
	FxGeom       uintptr
	FxQueryFunc  uintptr
	FxDestructor uintptr
	FpContext    uintptr
}

type RtreeGeomCallback1 = TRtreeGeomCallback1

/*
** An instance of this structure (in the form of a BLOB) is returned by
** the SQL functions that sqlite3_rtree_geometry_callback() and
** sqlite3_rtree_query_callback() create, and is read as the right-hand
** operand to the MATCH operator of an R-Tree.
 */
type TRtreeMatchArg1 = struct {
	F__ccgo_align  [0]uint32
	FiSize         Tu32
	Fcb            TRtreeGeomCallback
	FnParam        int32
	FapSqlParam    uintptr
	F__ccgo_align4 [4]byte
	FaParam        [1]TRtreeDValue
}

type RtreeMatchArg1 = TRtreeMatchArg1

/* What version of GCC is being used.  0 means GCC is not being used .
** Note that the GCC_VERSION macro will also be set correctly when using
** clang, since clang works hard to be gcc compatible.  So the gcc
** optimizations will also work when compiling with clang.
 */

/* The testcase() macro should already be defined in the amalgamation.  If
** it is not, make it a no-op.
 */

/*
** Make sure that the compiler intrinsics we desire are enabled when
** compiling with an appropriate version of MSVC unless prevented by
** the SQLITE_DISABLE_INTRINSIC define.
 */

/*
** Macros to determine whether the machine is big or little endian,
** and whether or not that determination is run-time or compile-time.
**
** For best performance, an attempt is made to guess at the byte-order
** using C-preprocessor macros.  If that is unsuccessful, or if
** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
** at run-time.
 */

/* What version of MSVC is being used.  0 means MSVC is not being used */

// C documentation
//
//	/*
//	** Functions to deserialize a 16 bit integer, 32 bit real number and
//	** 64 bit integer. The deserialized value is returned.
//	*/
func _readInt16(tls *libc.TLS, p uintptr) (r int32) {
	return int32(*(*Tu8)(unsafe.Pointer(p)))<<int32(8) + int32(*(*Tu8)(unsafe.Pointer(p + 1)))
}

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

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

// C documentation
//
//	/*
//	** Functions to serialize a 16 bit integer, 32 bit real number and
//	** 64 bit integer. The value returned is the number of bytes written
//	** to the argument buffer (always 2, 4 and 8 respectively).
//	*/
func _writeInt16(tls *libc.TLS, p uintptr, i int32) {
	*(*Tu8)(unsafe.Pointer(p)) = uint8(i >> int32(8) & int32(0xFF))
	*(*Tu8)(unsafe.Pointer(p + 1)) = uint8(i >> 0 & int32(0xFF))
}

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)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, *(*Tu32)(unsafe.Pointer(pCoord)))
	libc.Xmemcpy(tls, p, bp, uint32(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
	*(*Ti64)(unsafe.Pointer(bp)) = int64(libc.X__builtin_bswap64(tls, uint64(*(*Ti64)(unsafe.Pointer(bp)))))
	libc.Xmemcpy(tls, p, bp, uint32(8))
	return int32(8)
}

// C documentation
//
//	/*
//	** Increment the reference count of node p.
//	*/
func _nodeReference(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*TRtreeNode)(unsafe.Pointer(p)).FnRef++
	}
}

// C documentation
//
//	/*
//	** Clear the content of node p (set all bytes to 0x00).
//	*/
func _nodeZero(tls *libc.TLS, pRtree uintptr, p uintptr) {
	libc.Xmemset(tls, (*TRtreeNode)(unsafe.Pointer(p)).FzData+2, 0, uint32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(2)))
	(*TRtreeNode)(unsafe.Pointer(p)).FisDirty = int32(1)
}

// C documentation
//
//	/*
//	** Given a node number iNode, return the corresponding key to use
//	** in the Rtree.aHash table.
//	*/
func _nodeHash(tls *libc.TLS, iNode Ti64) (r uint32) {
	return uint32(uint32(iNode)) % uint32(HASHSIZE)
}

// C documentation
//
//	/*
//	** Search the node hash table for node iNode. If found, return a pointer
//	** to it. Otherwise, return 0.
//	*/
func _nodeHashLookup(tls *libc.TLS, pRtree uintptr, iNode Ti64) (r uintptr) {
	var p uintptr
	_ = p
	p = *(*uintptr)(unsafe.Pointer(pRtree + 112 + uintptr(_nodeHash(tls, iNode))*4))
	for {
		if !(p != 0 && (*TRtreeNode)(unsafe.Pointer(p)).FiNode != iNode) {
			break
		}
		goto _1
	_1:
		;
		p = (*TRtreeNode)(unsafe.Pointer(p)).FpNext
	}
	return p
}

// C documentation
//
//	/*
//	** Add node pNode to the node hash table.
//	*/
func _nodeHashInsert(tls *libc.TLS, pRtree uintptr, pNode uintptr) {
	var iHash int32
	_ = iHash
	iHash = int32(_nodeHash(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode))
	(*TRtreeNode)(unsafe.Pointer(pNode)).FpNext = *(*uintptr)(unsafe.Pointer(pRtree + 112 + uintptr(iHash)*4))
	*(*uintptr)(unsafe.Pointer(pRtree + 112 + uintptr(iHash)*4)) = pNode
}

// C documentation
//
//	/*
//	** Remove node pNode from the node hash table.
//	*/
func _nodeHashDelete(tls *libc.TLS, pRtree uintptr, pNode uintptr) {
	var pp uintptr
	_ = pp
	if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode != 0 {
		pp = pRtree + 112 + uintptr(_nodeHash(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode))*4
		for {
			if !(*(*uintptr)(unsafe.Pointer(pp)) != pNode) {
				break
			}
			goto _1
		_1:
			;
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 28
		}
		*(*uintptr)(unsafe.Pointer(pp)) = (*TRtreeNode)(unsafe.Pointer(pNode)).FpNext
		(*TRtreeNode)(unsafe.Pointer(pNode)).FpNext = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
//	** indicating that node has not yet been assigned a node number. It is
//	** assigned a node number when nodeWrite() is called to write the
//	** node contents out to the database.
//	*/
func _nodeNew(tls *libc.TLS, pRtree uintptr, pParent uintptr) (r uintptr) {
	var pNode uintptr
	_ = pNode
	pNode = Xsqlite3_malloc64(tls, uint64(uint32(32)+uint32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize)))
	if pNode != 0 {
		libc.Xmemset(tls, pNode, 0, uint32(32)+uint32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize))
		(*TRtreeNode)(unsafe.Pointer(pNode)).FzData = pNode + 1*32
		(*TRtreeNode)(unsafe.Pointer(pNode)).FnRef = int32(1)
		(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef++
		(*TRtreeNode)(unsafe.Pointer(pNode)).FpParent = pParent
		(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = int32(1)
		_nodeReference(tls, pParent)
	}
	return pNode
}

// C documentation
//
//	/*
//	** Clear the Rtree.pNodeBlob object
//	*/
func _nodeBlobReset(tls *libc.TLS, pRtree uintptr) {
	var pBlob uintptr
	_ = pBlob
	pBlob = (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob
	(*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob = uintptr(0)
	Xsqlite3_blob_close(tls, pBlob)
}

// C documentation
//
//	/*
//	** Obtain a reference to an r-tree node.
//	*/
func _nodeAcquire(tls *libc.TLS, pRtree uintptr, iNode Ti64, pParent uintptr, ppNode uintptr) (r int32) {
	var pBlob, pNode, v1 uintptr
	var rc int32
	_, _, _, _ = pBlob, pNode, rc, v1
	rc = SQLITE_OK
	pNode = uintptr(0)
	/* Check if the requested node is already in the hash table. If so,
	 ** increase its reference count and return it.
	 */
	v1 = _nodeHashLookup(tls, pRtree, iNode)
	pNode = v1
	if v1 != uintptr(0) {
		if pParent != 0 && pParent != (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent {
			return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		(*TRtreeNode)(unsafe.Pointer(pNode)).FnRef++
		*(*uintptr)(unsafe.Pointer(ppNode)) = pNode
		return SQLITE_OK
	}
	if (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob != 0 {
		pBlob = (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob
		(*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob = uintptr(0)
		rc = Xsqlite3_blob_reopen(tls, pBlob, iNode)
		(*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob = pBlob
		if rc != 0 {
			_nodeBlobReset(tls, pRtree)
			if rc == int32(SQLITE_NOMEM) {
				return int32(SQLITE_NOMEM)
			}
		}
	}
	if (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob == uintptr(0) {
		rc = Xsqlite3_blob_open(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, __ccgo_ts+27220, iNode, 0, pRtree+72)
	}
	if rc != 0 {
		*(*uintptr)(unsafe.Pointer(ppNode)) = uintptr(0)
		/* If unable to open an sqlite3_blob on the desired row, that can only
		 ** be because the shadow tables hold erroneous data. */
		if rc == int32(SQLITE_ERROR) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	} else {
		if (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize == Xsqlite3_blob_bytes(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob) {
			pNode = Xsqlite3_malloc64(tls, uint64(uint32(32)+uint32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize)))
			if !(pNode != 0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				(*TRtreeNode)(unsafe.Pointer(pNode)).FpParent = pParent
				(*TRtreeNode)(unsafe.Pointer(pNode)).FzData = pNode + 1*32
				(*TRtreeNode)(unsafe.Pointer(pNode)).FnRef = int32(1)
				(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef++
				(*TRtreeNode)(unsafe.Pointer(pNode)).FiNode = iNode
				(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = 0
				(*TRtreeNode)(unsafe.Pointer(pNode)).FpNext = uintptr(0)
				rc = Xsqlite3_blob_read(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData, (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize, 0)
			}
		}
	}
	/* If the root node was just loaded, set pRtree->iDepth to the height
	 ** of the r-tree structure. A height of zero means all data is stored on
	 ** the root node. A height of one means the children of the root node
	 ** are the leaves, and so on. If the depth as specified on the root node
	 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
	 */
	if rc == SQLITE_OK && pNode != 0 && iNode == int64(1) {
		(*TRtree)(unsafe.Pointer(pRtree)).FiDepth = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData)
		if (*TRtree)(unsafe.Pointer(pRtree)).FiDepth > int32(RTREE_MAX_DEPTH) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	}
	/* If no error has occurred so far, check if the "number of entries"
	 ** field on the node is too large. If so, set the return code to
	 ** SQLITE_CORRUPT_VTAB.
	 */
	if pNode != 0 && rc == SQLITE_OK {
		if _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2) > ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	}
	if rc == SQLITE_OK {
		if pNode != uintptr(0) {
			_nodeReference(tls, pParent)
			_nodeHashInsert(tls, pRtree, pNode)
		} else {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		*(*uintptr)(unsafe.Pointer(ppNode)) = pNode
	} else {
		_nodeBlobReset(tls, pRtree)
		if pNode != 0 {
			(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef--
			Xsqlite3_free(tls, pNode)
		}
		*(*uintptr)(unsafe.Pointer(ppNode)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Overwrite cell iCell of node pNode with the contents of pCell.
//	*/
func _nodeOverwriteCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iCell int32) {
	var ii int32
	var p uintptr
	_, _ = ii, p
	p = (*TRtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(int32(4)+int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell)
	p += uintptr(_writeInt64(tls, p, (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid))
	ii = 0
	for {
		if !(ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)) {
			break
		}
		p += uintptr(_writeCoord(tls, p, pCell+8+uintptr(ii)*4))
		goto _1
	_1:
		;
		ii++
	}
	(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = int32(1)
}

// C documentation
//
//	/*
//	** Remove the cell with index iCell from node pNode.
//	*/
func _nodeDeleteCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32) {
	var nByte int32
	var pDst, pSrc uintptr
	_, _, _ = nByte, pDst, pSrc
	pDst = (*TRtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(int32(4)+int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell)
	pSrc = pDst + uintptr((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
	nByte = (_readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2) - iCell - int32(1)) * int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
	libc.Xmemmove(tls, pDst, pSrc, uint32(uint32(nByte)))
	_writeInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2, _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2)-int32(1))
	(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = int32(1)
}

// C documentation
//
//	/*
//	** Insert the contents of cell pCell into node pNode. If the insert
//	** is successful, return SQLITE_OK.
//	**
//	** If there is not enough free space in pNode, return SQLITE_FULL.
//	*/
func _nodeInsertCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr) (r int32) {
	var nCell, nMaxCell int32
	_, _ = nCell, nMaxCell /* Maximum number of cells for pNode */
	nMaxCell = ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize - int32(4)) / int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
	nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2)
	if nCell < nMaxCell {
		_nodeOverwriteCell(tls, pRtree, pNode, pCell, nCell)
		_writeInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2, nCell+int32(1))
		(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = int32(1)
	}
	return libc.BoolInt32(nCell == nMaxCell)
}

// C documentation
//
//	/*
//	** If the node is dirty, write it out to the database.
//	*/
func _nodeWrite(tls *libc.TLS, pRtree uintptr, pNode uintptr) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	rc = SQLITE_OK
	if (*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty != 0 {
		p = (*TRtree)(unsafe.Pointer(pRtree)).FpWriteNode
		if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode != 0 {
			Xsqlite3_bind_int64(tls, p, int32(1), (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode)
		} else {
			Xsqlite3_bind_null(tls, p, int32(1))
		}
		Xsqlite3_bind_blob(tls, p, int32(2), (*TRtreeNode)(unsafe.Pointer(pNode)).FzData, (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize, libc.UintptrFromInt32(0))
		Xsqlite3_step(tls, p)
		(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = 0
		rc = Xsqlite3_reset(tls, p)
		Xsqlite3_bind_null(tls, p, int32(2))
		if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == 0 && rc == SQLITE_OK {
			(*TRtreeNode)(unsafe.Pointer(pNode)).FiNode = Xsqlite3_last_insert_rowid(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb)
			_nodeHashInsert(tls, pRtree, pNode)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Release a reference to a node. If the node is dirty and the reference
//	** count drops to zero, the node data is written to the database.
//	*/
func _nodeRelease(tls *libc.TLS, pRtree uintptr, pNode uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if pNode != 0 {
		(*TRtreeNode)(unsafe.Pointer(pNode)).FnRef--
		if (*TRtreeNode)(unsafe.Pointer(pNode)).FnRef == 0 {
			(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef--
			if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
				(*TRtree)(unsafe.Pointer(pRtree)).FiDepth = -int32(1)
			}
			if (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent != 0 {
				rc = _nodeRelease(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent)
			}
			if rc == SQLITE_OK {
				rc = _nodeWrite(tls, pRtree, pNode)
			}
			_nodeHashDelete(tls, pRtree, pNode)
			Xsqlite3_free(tls, pNode)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the 64-bit integer value associated with cell iCell of
//	** node pNode. If pNode is a leaf node, this is a rowid. If it is
//	** an internal node, then the 64-bit integer is a child page number.
//	*/
func _nodeGetRowid(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32) (r Ti64) {
	return _readInt64(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+uintptr(int32(4)+int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell))
}

// C documentation
//
//	/*
//	** Return coordinate iCoord from cell iCell in node pNode.
//	*/
func _nodeGetCoord(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32, iCoord int32, pCoord uintptr) {
	_readCoord(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+uintptr(int32(12)+int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell+int32(4)*iCoord), pCoord)
}

// C documentation
//
//	/*
//	** Deserialize cell iCell of node pNode. Populate the structure pointed
//	** to by pCell with the results.
//	*/
func _nodeGetCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32, pCell uintptr) {
	var ii int32
	var pCoord, pData uintptr
	_, _, _ = ii, pCoord, pData
	ii = 0
	(*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid = _nodeGetRowid(tls, pRtree, pNode, iCell)
	pData = (*TRtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(libc.Int32FromInt32(12)+int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell)
	pCoord = pCell + 8
	for cond := true; cond; cond = ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) {
		_readCoord(tls, pData, pCoord+uintptr(ii)*4)
		_readCoord(tls, pData+uintptr(4), pCoord+uintptr(ii+int32(1))*4)
		pData += uintptr(8)
		ii += int32(2)
	}
}

// C documentation
//
//	/*
//	** Rtree virtual table module xCreate method.
//	*/
func _rtreeCreate(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _rtreeInit(tls, db, pAux, argc, argv, ppVtab, pzErr, int32(1))
}

// C documentation
//
//	/*
//	** Rtree virtual table module xConnect method.
//	*/
func _rtreeConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _rtreeInit(tls, db, pAux, argc, argv, ppVtab, pzErr, 0)
}

// C documentation
//
//	/*
//	** Increment the r-tree reference count.
//	*/
func _rtreeReference(tls *libc.TLS, pRtree uintptr) {
	(*TRtree)(unsafe.Pointer(pRtree)).FnBusy++
}

// C documentation
//
//	/*
//	** Decrement the r-tree reference count. When the reference count reaches
//	** zero the structure is deleted.
//	*/
func _rtreeRelease(tls *libc.TLS, pRtree uintptr) {
	(*TRtree)(unsafe.Pointer(pRtree)).FnBusy--
	if (*TRtree)(unsafe.Pointer(pRtree)).FnBusy == uint32(0) {
		(*TRtree)(unsafe.Pointer(pRtree)).FinWrTrans = uint8(0)
		_nodeBlobReset(tls, pRtree)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteNode)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteNode)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadParent)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteParent)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteParent)
		Xsqlite3_finalize(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteAux)
		Xsqlite3_free(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzReadAuxSql)
		Xsqlite3_free(tls, pRtree)
	}
}

// C documentation
//
//	/*
//	** Rtree virtual table module xDisconnect method.
//	*/
func _rtreeDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	_rtreeRelease(tls, pVtab)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Rtree virtual table module xDestroy method.
//	*/
func _rtreeDestroy(tls *libc.TLS, pVtab uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var pRtree, zCreate uintptr
	var rc int32
	_, _, _ = pRtree, rc, zCreate
	pRtree = pVtab
	zCreate = Xsqlite3_mprintf(tls, __ccgo_ts+27225, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
	if !(zCreate != 0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		_nodeBlobReset(tls, pRtree)
		rc = Xsqlite3_exec(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zCreate, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zCreate)
	}
	if rc == SQLITE_OK {
		_rtreeRelease(tls, pRtree)
	}
	return rc
}

// C documentation
//
//	/*
//	** Rtree virtual table module xOpen method.
//	*/
func _rtreeOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) (r int32) {
	var pCsr, pRtree uintptr
	var rc int32
	_, _, _ = pCsr, pRtree, rc
	rc = int32(SQLITE_NOMEM)
	pRtree = pVTab
	pCsr = Xsqlite3_malloc64(tls, uint64(248))
	if pCsr != 0 {
		libc.Xmemset(tls, pCsr, 0, uint32(248))
		(*TRtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
		rc = SQLITE_OK
		(*TRtree)(unsafe.Pointer(pRtree)).FnCursor++
	}
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCsr
	return rc
}

// C documentation
//
//	/*
//	** Reset a cursor back to its initial state.
//	*/
func _resetCursor(tls *libc.TLS, pCsr uintptr) {
	var i, ii int32
	var pInfo, pRtree, pStmt uintptr
	_, _, _, _, _ = i, ii, pInfo, pRtree, pStmt
	pRtree = (*TRtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	if (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint != 0 { /* Used to iterate through constraint array */
		i = 0
		for {
			if !(i < (*TRtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint) {
				break
			}
			pInfo = (*(*TRtreeConstraint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint + uintptr(i)*24))).FpInfo
			if pInfo != 0 {
				if (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FxDelUser != 0 {
					(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FxDelUser})))(tls, (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FpUser)
				}
				Xsqlite3_free(tls, pInfo)
			}
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint)
		(*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = uintptr(0)
	}
	ii = 0
	for {
		if !(ii < int32(RTREE_CACHE_SZ)) {
			break
		}
		_nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(pCsr + 64 + uintptr(ii)*4)))
		goto _2
	_2:
		;
		ii++
	}
	Xsqlite3_free(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaPoint)
	pStmt = (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux
	libc.Xmemset(tls, pCsr, 0, uint32(248))
	(*TRtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pRtree
	(*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux = pStmt
}

// C documentation
//
//	/*
//	** Rtree virtual table module xClose method.
//	*/
func _rtreeClose(tls *libc.TLS, cur uintptr) (r int32) {
	var pCsr, pRtree uintptr
	_, _ = pCsr, pRtree
	pRtree = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	pCsr = cur
	_resetCursor(tls, pCsr)
	Xsqlite3_finalize(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
	Xsqlite3_free(tls, pCsr)
	(*TRtree)(unsafe.Pointer(pRtree)).FnCursor--
	if (*TRtree)(unsafe.Pointer(pRtree)).FnCursor == uint32(0) && int32((*TRtree)(unsafe.Pointer(pRtree)).FinWrTrans) == 0 {
		_nodeBlobReset(tls, pRtree)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Rtree virtual table module xEof method.
//	**
//	** Return non-zero if the cursor does not currently point to a valid
//	** record (i.e if the scan has finished), or zero otherwise.
//	*/
func _rtreeEof(tls *libc.TLS, cur uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = cur
	return int32((*TRtreeCursor)(unsafe.Pointer(pCsr)).FatEOF)
}

/*
** Convert raw bits from the on-disk RTree record into a coordinate value.
** The on-disk format is big-endian and needs to be converted for little-
** endian platforms.  The on-disk record stores integer coordinates if
** eInt is true and it stores 32-bit floating point records if eInt is
** false.  a[] is the four bytes of the on-disk record to be decoded.
** Store the results in "r".
**
** There are five versions of this macro.  The last one is generic.  The
** other four are various architectures-specific optimizations.
 */

// C documentation
//
//	/*
//	** Check the RTree node or entry given by pCellData and p against the MATCH
//	** constraint pConstraint.
//	*/
func _rtreeCallbackConstraint(tls *libc.TLS, pConstraint uintptr, eInt int32, pCellData uintptr, pSearch uintptr, prScore uintptr, peWithin uintptr) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var nCoord, rc, v2 int32
	var pInfo uintptr
	var v1 Tsqlite3_rtree_dbl
	var _ /* aCoord at bp+8 */ [10]Tsqlite3_rtree_dbl
	var _ /* c at bp+0 */ TRtreeCoord
	var _ /* eWithin at bp+88 */ int32
	_, _, _, _, _ = nCoord, pInfo, rc, v1, v2
	pInfo = (*TRtreeConstraint)(unsafe.Pointer(pConstraint)).FpInfo      /* Callback info */
	nCoord = (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FnCoord /* Decoded coordinates */
	if (*TRtreeConstraint)(unsafe.Pointer(pConstraint)).Fop == int32(RTREE_QUERY) && int32((*TRtreeSearchPoint)(unsafe.Pointer(pSearch)).FiLevel) == int32(1) {
		(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FiRowid = _readInt64(tls, pCellData)
	}
	pCellData += uintptr(8)
	if eInt == 0 {
		switch nCoord {
		case int32(10):
			_readCoord(tls, pCellData+uintptr(36), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(9)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(32), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(8)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		case int32(8):
			_readCoord(tls, pCellData+uintptr(28), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(7)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(24), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(6)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		case int32(6):
			_readCoord(tls, pCellData+uintptr(20), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(5)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(16), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(4)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		case int32(4):
			_readCoord(tls, pCellData+uintptr(12), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(3)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(8), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(2)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		default:
			_readCoord(tls, pCellData+uintptr(4), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(1)] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData, bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[0] = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
		}
	} else {
		switch nCoord {
		case int32(10):
			_readCoord(tls, pCellData+uintptr(36), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(9)] = float64(*(*int32)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(32), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(8)] = float64(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		case int32(8):
			_readCoord(tls, pCellData+uintptr(28), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(7)] = float64(*(*int32)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(24), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(6)] = float64(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		case int32(6):
			_readCoord(tls, pCellData+uintptr(20), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(5)] = float64(*(*int32)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(16), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(4)] = float64(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		case int32(4):
			_readCoord(tls, pCellData+uintptr(12), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(3)] = float64(*(*int32)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData+uintptr(8), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(2)] = float64(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		default:
			_readCoord(tls, pCellData+uintptr(4), bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[int32(1)] = float64(*(*int32)(unsafe.Pointer(bp)))
			_readCoord(tls, pCellData, bp)
			(*(*[10]Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)))[0] = float64(*(*int32)(unsafe.Pointer(bp)))
		}
	}
	if (*TRtreeConstraint)(unsafe.Pointer(pConstraint)).Fop == int32(RTREE_MATCH) {
		*(*int32)(unsafe.Pointer(bp + 88)) = 0
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*TRtreeConstraint)(unsafe.Pointer(pConstraint)).Fu))})))(tls, pInfo, nCoord, bp+8, bp+88)
		if *(*int32)(unsafe.Pointer(bp + 88)) == 0 {
			*(*int32)(unsafe.Pointer(peWithin)) = NOT_WITHIN
		}
		*(*Tsqlite3_rtree_dbl)(unsafe.Pointer(prScore)) = float64(0)
	} else {
		(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FaCoord = bp + 8
		(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FiLevel = int32((*TRtreeSearchPoint)(unsafe.Pointer(pSearch)).FiLevel) - int32(1)
		v1 = (*TRtreeSearchPoint)(unsafe.Pointer(pSearch)).FrScore
		(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FrParentScore = v1
		(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FrScore = v1
		v2 = int32((*TRtreeSearchPoint)(unsafe.Pointer(pSearch)).FeWithin)
		(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FeParentWithin = v2
		(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FeWithin = v2
		rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*TRtreeConstraint)(unsafe.Pointer(pConstraint)).Fu))})))(tls, pInfo)
		if (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FeWithin < *(*int32)(unsafe.Pointer(peWithin)) {
			*(*int32)(unsafe.Pointer(peWithin)) = (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FeWithin
		}
		if (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FrScore < *(*Tsqlite3_rtree_dbl)(unsafe.Pointer(prScore)) || *(*Tsqlite3_rtree_dbl)(unsafe.Pointer(prScore)) < float64(0) {
			*(*Tsqlite3_rtree_dbl)(unsafe.Pointer(prScore)) = (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FrScore
		}
	}
	return rc
}

// 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, v2, v3, v4 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, v2, v3, v4 /* 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 += 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 */ *(*Tu32)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, *(*Tu32)(unsafe.Pointer(pCellData)))
		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 += uintptr(4)
			/* Coordinate decoded */ *(*Tu32)(unsafe.Pointer(bp + 4)) = libc.X__builtin_bswap32(tls, *(*Tu32)(unsafe.Pointer(pCellData)))
			if eInt != 0 {
				v2 = float64(*(*int32)(unsafe.Pointer(bp + 4)))
			} else {
				v2 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 4)))
			}
			val = v2
			/* 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 */ *(*Tu32)(unsafe.Pointer(bp + 8)) = libc.X__builtin_bswap32(tls, *(*Tu32)(unsafe.Pointer(pCellData)))
		if eInt != 0 {
			v3 = float64(*(*int32)(unsafe.Pointer(bp + 8)))
		} else {
			v3 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 8)))
		}
		val = v3
		/* val now holds the lower bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) >= val {
			return
		}
	default:
		pCellData += uintptr(4)
		/* Coordinate decoded */ *(*Tu32)(unsafe.Pointer(bp + 12)) = libc.X__builtin_bswap32(tls, *(*Tu32)(unsafe.Pointer(pCellData)))
		if eInt != 0 {
			v4 = float64(*(*int32)(unsafe.Pointer(bp + 12)))
		} else {
			v4 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 12)))
		}
		val = v4
		/* val now holds the upper bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) <= val {
			return
		}
		break
	}
	*(*int32)(unsafe.Pointer(peWithin)) = NOT_WITHIN
}

// 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 += uintptr(int32(8) + (*TRtreeConstraint)(unsafe.Pointer(p)).FiCoord*int32(4))
	/* Coordinate decoded */
	*(*Tu32)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, *(*Tu32)(unsafe.Pointer(pCellData)))
	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)(unsafe.Pointer(peWithin)) = NOT_WITHIN
}

// C documentation
//
//	/*
//	** One of the cells in node pNode is guaranteed to have a 64-bit
//	** integer value equal to iRowid. Return the index of this cell.
//	*/
func _nodeRowidIndex(tls *libc.TLS, pRtree uintptr, pNode uintptr, iRowid Ti64, piIndex uintptr) (r int32) {
	var ii, nCell int32
	_, _ = ii, nCell
	nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2)
	ii = 0
	for {
		if !(ii < nCell) {
			break
		}
		if _nodeGetRowid(tls, pRtree, pNode, ii) == iRowid {
			*(*int32)(unsafe.Pointer(piIndex)) = ii
			return SQLITE_OK
		}
		goto _1
	_1:
		;
		ii++
	}
	return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
}

// C documentation
//
//	/*
//	** Return the index of the cell containing a pointer to node pNode
//	** in its parent. If pNode is the root node, return -1.
//	*/
func _nodeParentIndex(tls *libc.TLS, pRtree uintptr, pNode uintptr, piIndex uintptr) (r int32) {
	var pParent uintptr
	_ = pParent
	pParent = (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent
	if pParent != 0 {
		return _nodeRowidIndex(tls, pRtree, pParent, (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode, piIndex)
	} else {
		*(*int32)(unsafe.Pointer(piIndex)) = -int32(1)
		return SQLITE_OK
	}
	return r
}

// C documentation
//
//	/*
//	** Compare two search points.  Return negative, zero, or positive if the first
//	** is less than, equal to, or greater than the second.
//	**
//	** The rScore is the primary key.  Smaller rScore values come first.
//	** If the rScore is a tie, then use iLevel as the tie breaker with smaller
//	** iLevel values coming first.  In this way, if rScore is the same for all
//	** SearchPoints, then iLevel becomes the deciding factor and the result
//	** is a depth-first search, which is the desired default behavior.
//	*/
func _rtreeSearchPointCompare(tls *libc.TLS, pA uintptr, pB uintptr) (r int32) {
	if (*TRtreeSearchPoint)(unsafe.Pointer(pA)).FrScore < (*TRtreeSearchPoint)(unsafe.Pointer(pB)).FrScore {
		return -int32(1)
	}
	if (*TRtreeSearchPoint)(unsafe.Pointer(pA)).FrScore > (*TRtreeSearchPoint)(unsafe.Pointer(pB)).FrScore {
		return +libc.Int32FromInt32(1)
	}
	if int32((*TRtreeSearchPoint)(unsafe.Pointer(pA)).FiLevel) < int32((*TRtreeSearchPoint)(unsafe.Pointer(pB)).FiLevel) {
		return -int32(1)
	}
	if int32((*TRtreeSearchPoint)(unsafe.Pointer(pA)).FiLevel) > int32((*TRtreeSearchPoint)(unsafe.Pointer(pB)).FiLevel) {
		return +libc.Int32FromInt32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Interchange two search points in a cursor.
//	*/
func _rtreeSearchPointSwap(tls *libc.TLS, p uintptr, i int32, j int32) {
	var pTemp uintptr
	var t TRtreeSearchPoint
	_, _ = pTemp, t
	t = *(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(i)*24))
	*(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(i)*24)) = *(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(j)*24))
	*(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(j)*24)) = t
	i++
	j++
	if i < int32(RTREE_CACHE_SZ) {
		if j >= int32(RTREE_CACHE_SZ) {
			_nodeRelease(tls, (*TRtreeCursor)(unsafe.Pointer(p)).Fbase.FpVtab, *(*uintptr)(unsafe.Pointer(p + 64 + uintptr(i)*4)))
			*(*uintptr)(unsafe.Pointer(p + 64 + uintptr(i)*4)) = uintptr(0)
		} else {
			pTemp = *(*uintptr)(unsafe.Pointer(p + 64 + uintptr(i)*4))
			*(*uintptr)(unsafe.Pointer(p + 64 + uintptr(i)*4)) = *(*uintptr)(unsafe.Pointer(p + 64 + uintptr(j)*4))
			*(*uintptr)(unsafe.Pointer(p + 64 + uintptr(j)*4)) = pTemp
		}
	}
}

// C documentation
//
//	/*
//	** Return the search point with the lowest current score.
//	*/
func _rtreeSearchPointFirst(tls *libc.TLS, pCur uintptr) (r uintptr) {
	var v1, v2 uintptr
	_, _ = v1, v2
	if (*TRtreeCursor)(unsafe.Pointer(pCur)).FbPoint != 0 {
		v1 = pCur + 40
	} else {
		if (*TRtreeCursor)(unsafe.Pointer(pCur)).FnPoint != 0 {
			v2 = (*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint
		} else {
			v2 = uintptr(0)
		}
		v1 = v2
	}
	return v1
}

// C documentation
//
//	/*
//	** Get the RtreeNode for the search point with the lowest score.
//	*/
func _rtreeNodeOfFirstSearchPoint(tls *libc.TLS, pCur uintptr, pRC uintptr) (r uintptr) {
	var id Tsqlite3_int64
	var ii int32
	var v1 int64
	_, _, _ = id, ii, v1
	ii = int32(1) - int32((*TRtreeCursor)(unsafe.Pointer(pCur)).FbPoint)
	if *(*uintptr)(unsafe.Pointer(pCur + 64 + uintptr(ii)*4)) == uintptr(0) {
		if ii != 0 {
			v1 = (*(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint))).Fid
		} else {
			v1 = (*TRtreeCursor)(unsafe.Pointer(pCur)).FsPoint.Fid
		}
		id = v1
		*(*int32)(unsafe.Pointer(pRC)) = _nodeAcquire(tls, (*TRtreeCursor)(unsafe.Pointer(pCur)).Fbase.FpVtab, id, uintptr(0), pCur+64+uintptr(ii)*4)
	}
	return *(*uintptr)(unsafe.Pointer(pCur + 64 + uintptr(ii)*4))
}

// C documentation
//
//	/*
//	** Push a new element onto the priority queue
//	*/
func _rtreeEnqueue(tls *libc.TLS, pCur uintptr, rScore TRtreeDValue, iLevel Tu8) (r uintptr) {
	var i, j, nNew, v1 int32
	var pNew, pParent, v2 uintptr
	_, _, _, _, _, _, _ = i, j, nNew, pNew, pParent, v1, v2
	if (*TRtreeCursor)(unsafe.Pointer(pCur)).FnPoint >= (*TRtreeCursor)(unsafe.Pointer(pCur)).FnPointAlloc {
		nNew = (*TRtreeCursor)(unsafe.Pointer(pCur)).FnPointAlloc*int32(2) + int32(8)
		pNew = Xsqlite3_realloc64(tls, (*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint, uint64(uint32(uint32(nNew))*uint32(24)))
		if pNew == uintptr(0) {
			return uintptr(0)
		}
		(*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint = pNew
		(*TRtreeCursor)(unsafe.Pointer(pCur)).FnPointAlloc = nNew
	}
	v2 = pCur + 24
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	i = v1
	pNew = (*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint + uintptr(i)*24
	(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FrScore = rScore
	(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FiLevel = iLevel
	for i > 0 {
		j = (i - int32(1)) / int32(2)
		pParent = (*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint + uintptr(j)*24
		if _rtreeSearchPointCompare(tls, pNew, pParent) >= 0 {
			break
		}
		_rtreeSearchPointSwap(tls, pCur, j, i)
		i = j
		pNew = pParent
	}
	return pNew
}

// C documentation
//
//	/*
//	** Allocate a new RtreeSearchPoint and return a pointer to it.  Return
//	** NULL if malloc fails.
//	*/
func _rtreeSearchPointNew(tls *libc.TLS, pCur uintptr, rScore TRtreeDValue, iLevel Tu8) (r uintptr) {
	var ii int32
	var pFirst, pNew uintptr
	_, _, _ = ii, pFirst, pNew
	pFirst = _rtreeSearchPointFirst(tls, pCur)
	*(*Tu32)(unsafe.Pointer(pCur + 84 + uintptr(iLevel)*4))++
	if pFirst == uintptr(0) || (*TRtreeSearchPoint)(unsafe.Pointer(pFirst)).FrScore > rScore || (*TRtreeSearchPoint)(unsafe.Pointer(pFirst)).FrScore == rScore && int32((*TRtreeSearchPoint)(unsafe.Pointer(pFirst)).FiLevel) > int32(int32(iLevel)) {
		if (*TRtreeCursor)(unsafe.Pointer(pCur)).FbPoint != 0 {
			pNew = _rtreeEnqueue(tls, pCur, rScore, iLevel)
			if pNew == uintptr(0) {
				return uintptr(0)
			}
			ii = (int32(int32(pNew))-int32((*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint))/24 + int32(1)
			if ii < int32(RTREE_CACHE_SZ) {
				*(*uintptr)(unsafe.Pointer(pCur + 64 + uintptr(ii)*4)) = *(*uintptr)(unsafe.Pointer(pCur + 64))
			} else {
				_nodeRelease(tls, (*TRtreeCursor)(unsafe.Pointer(pCur)).Fbase.FpVtab, *(*uintptr)(unsafe.Pointer(pCur + 64)))
			}
			*(*uintptr)(unsafe.Pointer(pCur + 64)) = uintptr(0)
			*(*TRtreeSearchPoint)(unsafe.Pointer(pNew)) = (*TRtreeCursor)(unsafe.Pointer(pCur)).FsPoint
		}
		(*TRtreeCursor)(unsafe.Pointer(pCur)).FsPoint.FrScore = rScore
		(*TRtreeCursor)(unsafe.Pointer(pCur)).FsPoint.FiLevel = iLevel
		(*TRtreeCursor)(unsafe.Pointer(pCur)).FbPoint = uint8(1)
		return pCur + 40
	} else {
		return _rtreeEnqueue(tls, pCur, rScore, iLevel)
	}
	return r
}

// C documentation
//
//	/* Remove the search point with the lowest current score.
//	*/
func _rtreeSearchPointPop(tls *libc.TLS, p uintptr) {
	var i, j, k, n, v1, v3 int32
	var v2 uintptr
	_, _, _, _, _, _, _ = i, j, k, n, v1, v2, v3
	i = int32(1) - int32((*TRtreeCursor)(unsafe.Pointer(p)).FbPoint)
	if *(*uintptr)(unsafe.Pointer(p + 64 + uintptr(i)*4)) != 0 {
		_nodeRelease(tls, (*TRtreeCursor)(unsafe.Pointer(p)).Fbase.FpVtab, *(*uintptr)(unsafe.Pointer(p + 64 + uintptr(i)*4)))
		*(*uintptr)(unsafe.Pointer(p + 64 + uintptr(i)*4)) = uintptr(0)
	}
	if (*TRtreeCursor)(unsafe.Pointer(p)).FbPoint != 0 {
		*(*Tu32)(unsafe.Pointer(p + 84 + uintptr((*TRtreeCursor)(unsafe.Pointer(p)).FsPoint.FiLevel)*4))--
		(*TRtreeCursor)(unsafe.Pointer(p)).FbPoint = uint8(0)
	} else {
		if (*TRtreeCursor)(unsafe.Pointer(p)).FnPoint != 0 {
			*(*Tu32)(unsafe.Pointer(p + 84 + uintptr((*(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(p)).FaPoint))).FiLevel)*4))--
			v2 = p + 24
			*(*int32)(unsafe.Pointer(v2))--
			v1 = *(*int32)(unsafe.Pointer(v2))
			n = v1
			*(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(p)).FaPoint)) = *(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(n)*24))
			if n < libc.Int32FromInt32(RTREE_CACHE_SZ)-libc.Int32FromInt32(1) {
				*(*uintptr)(unsafe.Pointer(p + 64 + 1*4)) = *(*uintptr)(unsafe.Pointer(p + 64 + uintptr(n+int32(1))*4))
				*(*uintptr)(unsafe.Pointer(p + 64 + uintptr(n+int32(1))*4)) = uintptr(0)
			}
			i = 0
			for {
				v3 = i*libc.Int32FromInt32(2) + libc.Int32FromInt32(1)
				j = v3
				if !(v3 < n) {
					break
				}
				k = j + int32(1)
				if k < n && _rtreeSearchPointCompare(tls, (*TRtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(k)*24, (*TRtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(j)*24) < 0 {
					if _rtreeSearchPointCompare(tls, (*TRtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(k)*24, (*TRtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(i)*24) < 0 {
						_rtreeSearchPointSwap(tls, p, i, k)
						i = k
					} else {
						break
					}
				} else {
					if _rtreeSearchPointCompare(tls, (*TRtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(j)*24, (*TRtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(i)*24) < 0 {
						_rtreeSearchPointSwap(tls, p, i, j)
						i = j
					} else {
						break
					}
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Continue the search on cursor pCur until the front of the queue
//	** contains an entry suitable for returning as a result-set row,
//	** or until the RtreeSearchPoint queue is empty, indicating that the
//	** query has completed.
//	*/
func _rtreeStepToLeaf(tls *libc.TLS, pCur uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eInt, ii, nCell, nConstraint int32
	var p, pCellData, pConstraint, pNode, pRtree, v1 uintptr
	var x TRtreeSearchPoint
	var _ /* eWithin at bp+0 */ int32
	var _ /* rScore at bp+8 */ Tsqlite3_rtree_dbl
	var _ /* rc at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _ = eInt, ii, nCell, nConstraint, p, pCellData, pConstraint, pNode, pRtree, x, v1
	pRtree = (*TRtreeCursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
	nConstraint = (*TRtreeCursor)(unsafe.Pointer(pCur)).FnConstraint
	eInt = libc.BoolInt32(int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == int32(RTREE_COORD_INT32))
	for {
		v1 = _rtreeSearchPointFirst(tls, pCur)
		p = v1
		if !(v1 != uintptr(0) && int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiLevel) > 0) {
			break
		}
		pNode = _rtreeNodeOfFirstSearchPoint(tls, pCur, bp+4)
		if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
			return *(*int32)(unsafe.Pointer(bp + 4))
		}
		nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2)
		pCellData = (*TRtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(libc.Int32FromInt32(4)+int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell))
		for int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell) < nCell {
			*(*Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) = float64(-libc.Int32FromInt32(1))
			*(*int32)(unsafe.Pointer(bp)) = int32(FULLY_WITHIN)
			ii = 0
			for {
				if !(ii < nConstraint) {
					break
				}
				pConstraint = (*TRtreeCursor)(unsafe.Pointer(pCur)).FaConstraint + uintptr(ii)*24
				if (*TRtreeConstraint)(unsafe.Pointer(pConstraint)).Fop >= int32(RTREE_MATCH) {
					*(*int32)(unsafe.Pointer(bp + 4)) = _rtreeCallbackConstraint(tls, pConstraint, eInt, pCellData, p, bp+8, bp)
					if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
						return *(*int32)(unsafe.Pointer(bp + 4))
					}
				} else {
					if int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiLevel) == int32(1) {
						_rtreeLeafConstraint(tls, pConstraint, eInt, pCellData, bp)
					} else {
						_rtreeNonleafConstraint(tls, pConstraint, eInt, pCellData, bp)
					}
				}
				if *(*int32)(unsafe.Pointer(bp)) == NOT_WITHIN {
					(*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell++
					pCellData += uintptr((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
					break
				}
				goto _2
			_2:
				;
				ii++
			}
			if *(*int32)(unsafe.Pointer(bp)) == NOT_WITHIN {
				continue
			}
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell++
			x.FiLevel = uint8(int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiLevel) - int32(1))
			if x.FiLevel != 0 {
				x.Fid = _readInt64(tls, pCellData)
				ii = 0
				for {
					if !(ii < (*TRtreeCursor)(unsafe.Pointer(pCur)).FnPoint) {
						break
					}
					if (*(*TRtreeSearchPoint)(unsafe.Pointer((*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint + uintptr(ii)*24))).Fid == x.Fid {
						return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					}
					goto _3
				_3:
					;
					ii++
				}
				x.FiCell = uint8(0)
			} else {
				x.Fid = (*TRtreeSearchPoint)(unsafe.Pointer(p)).Fid
				x.FiCell = uint8(int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell) - int32(1))
			}
			if int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell) >= nCell {
				_rtreeSearchPointPop(tls, pCur)
			}
			if *(*Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) < float64(0) {
				*(*Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) = float64(0)
			}
			p = _rtreeSearchPointNew(tls, pCur, *(*Tsqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)), x.FiLevel)
			if p == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = uint8(*(*int32)(unsafe.Pointer(bp)))
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).Fid = x.Fid
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell = x.FiCell
			break
		}
		if int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell) >= nCell {
			_rtreeSearchPointPop(tls, pCur)
		}
	}
	(*TRtreeCursor)(unsafe.Pointer(pCur)).FatEOF = libc.BoolUint8(p == uintptr(0))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Rtree virtual table module xNext method.
//	*/
func _rtreeNext(tls *libc.TLS, pVtabCursor uintptr) (r int32) {
	var pCsr uintptr
	var rc int32
	_, _ = pCsr, rc
	pCsr = pVtabCursor
	rc = SQLITE_OK
	/* Move to the next entry that matches the configured constraints. */
	if (*TRtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid != 0 {
		(*TRtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid = uint8(0)
		Xsqlite3_reset(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
	}
	_rtreeSearchPointPop(tls, pCsr)
	rc = _rtreeStepToLeaf(tls, pCsr)
	return rc
}

// C documentation
//
//	/*
//	** Rtree virtual table module xRowid method.
//	*/
func _rtreeRowid(tls *libc.TLS, pVtabCursor uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p, pCsr, pNode uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _ = p, pCsr, pNode
	pCsr = pVtabCursor
	p = _rtreeSearchPointFirst(tls, pCsr)
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	pNode = _rtreeNodeOfFirstSearchPoint(tls, pCsr, bp)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && p != 0 {
		if int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell) >= _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2) {
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ABORT)
		} else {
			*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = _nodeGetRowid(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab, pNode, int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell))
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Rtree virtual table module xColumn method.
//	*/
func _rtreeColumn(tls *libc.TLS, cur uintptr, ctx uintptr, i int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p, pCsr, pNode, pRtree uintptr
	var _ /* c at bp+0 */ TRtreeCoord
	var _ /* rc at bp+4 */ int32
	_, _, _, _ = p, pCsr, pNode, pRtree
	pRtree = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	pCsr = cur
	p = _rtreeSearchPointFirst(tls, pCsr)
	*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
	pNode = _rtreeNodeOfFirstSearchPoint(tls, pCsr, bp+4)
	if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
		return *(*int32)(unsafe.Pointer(bp + 4))
	}
	if p == uintptr(0) {
		return SQLITE_OK
	}
	if int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell) >= _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2) {
		return int32(SQLITE_ABORT)
	}
	if i == 0 {
		Xsqlite3_result_int64(tls, ctx, _nodeGetRowid(tls, pRtree, pNode, int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell)))
	} else {
		if i <= int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) {
			_nodeGetCoord(tls, pRtree, pNode, int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell), i-int32(1), bp)
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				Xsqlite3_result_double(tls, ctx, float64(*(*TRtreeValue)(unsafe.Pointer(bp))))
			} else {
				Xsqlite3_result_int(tls, ctx, *(*int32)(unsafe.Pointer(bp)))
			}
		} else {
			if !((*TRtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid != 0) {
				if (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux == uintptr(0) {
					*(*int32)(unsafe.Pointer(bp + 4)) = Xsqlite3_prepare_v3(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, (*TRtree)(unsafe.Pointer(pRtree)).FzReadAuxSql, -int32(1), uint32(0), pCsr+36, uintptr(0))
					if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
						return *(*int32)(unsafe.Pointer(bp + 4))
					}
				}
				Xsqlite3_bind_int64(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, int32(1), _nodeGetRowid(tls, pRtree, pNode, int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell)))
				*(*int32)(unsafe.Pointer(bp + 4)) = Xsqlite3_step(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
				if *(*int32)(unsafe.Pointer(bp + 4)) == int32(SQLITE_ROW) {
					(*TRtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid = uint8(1)
				} else {
					Xsqlite3_reset(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
					if *(*int32)(unsafe.Pointer(bp + 4)) == int32(SQLITE_DONE) {
						*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
					}
					return *(*int32)(unsafe.Pointer(bp + 4))
				}
			}
			Xsqlite3_result_value(tls, ctx, Xsqlite3_column_value(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, i-int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)+int32(1)))
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Use nodeAcquire() to obtain the leaf node containing the record with
//	** rowid iRowid. If successful, set *ppLeaf to point to the node and
//	** return SQLITE_OK. If there is no such record in the table, set
//	** *ppLeaf to 0 and return SQLITE_OK. If an error occurs, set *ppLeaf
//	** to zero and return an SQLite error code.
//	*/
func _findLeafNode(tls *libc.TLS, pRtree uintptr, iRowid Ti64, ppLeaf uintptr, piNode uintptr) (r int32) {
	var iNode Ti64
	var rc int32
	_, _ = iNode, rc
	*(*uintptr)(unsafe.Pointer(ppLeaf)) = uintptr(0)
	Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid, int32(1), iRowid)
	if Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid) == int32(SQLITE_ROW) {
		iNode = Xsqlite3_column_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid, 0)
		if piNode != 0 {
			*(*Tsqlite3_int64)(unsafe.Pointer(piNode)) = iNode
		}
		rc = _nodeAcquire(tls, pRtree, iNode, uintptr(0), ppLeaf)
		Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	} else {
		rc = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called to configure the RtreeConstraint object passed
//	** as the second argument for a MATCH constraint. The value passed as the
//	** first argument to this function is the right-hand operand to the MATCH
//	** operator.
//	*/
func _deserializeGeometry(tls *libc.TLS, pValue uintptr, pCons uintptr) (r int32) {
	var pBlob, pInfo, pSrc uintptr
	_, _, _ = pBlob, pInfo, pSrc /* Callback information */
	pSrc = Xsqlite3_value_pointer(tls, pValue, __ccgo_ts+27307)
	if pSrc == uintptr(0) {
		return int32(SQLITE_ERROR)
	}
	pInfo = Xsqlite3_malloc64(tls, uint64(uint32(80)+(*TRtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize))
	if !(pInfo != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pInfo, 0, uint32(80))
	pBlob = pInfo + 1*80
	libc.Xmemcpy(tls, pBlob, pSrc, (*TRtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize)
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FpContext = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FpContext
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FnParam = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FaParam = pBlob + 32
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FapSqlParam = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam
	if (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom != 0 {
		*(*uintptr)(unsafe.Pointer(&(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fu)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom
	} else {
		(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fop = int32(RTREE_QUERY)
		*(*uintptr)(unsafe.Pointer(&(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fu)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxQueryFunc
	}
	(*TRtreeConstraint)(unsafe.Pointer(pCons)).FpInfo = pInfo
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Rtree virtual table module xFilter method.
//	*/
func _rtreeFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eType, eType1, ii, rc int32
	var iRowid Ti64
	var iVal Tsqlite3_int64
	var p, p1, pCsr, pNew, pRtree uintptr
	var _ /* iCell at bp+4 */ int32
	var _ /* iNode at bp+16 */ Ti64
	var _ /* pLeaf at bp+8 */ uintptr
	var _ /* pRoot at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = eType, eType1, iRowid, iVal, ii, p, p1, pCsr, pNew, pRtree, rc
	pRtree = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	pCsr = pVtabCursor
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	_rtreeReference(tls, pRtree)
	/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
	_resetCursor(tls, pCsr)
	(*TRtreeCursor)(unsafe.Pointer(pCsr)).FiStrategy = idxNum
	if idxNum == int32(1) { /* Search point for the leaf */
		iRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
		*(*Ti64)(unsafe.Pointer(bp + 16)) = 0
		eType = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) && 0 == _sqlite3IntFloatCompare(tls, iRowid, Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))) {
			rc = _findLeafNode(tls, pRtree, iRowid, bp+8, bp+16)
		} else {
			rc = SQLITE_OK
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		}
		if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 8)) != uintptr(0) {
			p = _rtreeSearchPointNew(tls, pCsr, float64(0), uint8(0))
			/* Always returns pCsr->sPoint */
			*(*uintptr)(unsafe.Pointer(pCsr + 64)) = *(*uintptr)(unsafe.Pointer(bp + 8))
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).Fid = *(*Ti64)(unsafe.Pointer(bp + 16))
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = uint8(PARTLY_WITHIN)
			rc = _nodeRowidIndex(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)), iRowid, bp+4)
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell = uint8(*(*int32)(unsafe.Pointer(bp + 4)))
		} else {
			(*TRtreeCursor)(unsafe.Pointer(pCsr)).FatEOF = uint8(1)
		}
	} else {
		/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
		 ** with the configured constraints.
		 */
		rc = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)
		if rc == SQLITE_OK && argc > 0 {
			(*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = Xsqlite3_malloc64(tls, uint64(uint32(24)*uint32(uint32(argc))))
			(*TRtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint = argc
			if !((*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint != 0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemset(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint, 0, uint32(24)*uint32(uint32(argc)))
				libc.Xmemset(tls, pCsr+84, 0, uint32(4)*uint32((*TRtree)(unsafe.Pointer(pRtree)).FiDepth+libc.Int32FromInt32(1)))
				ii = 0
				for {
					if !(ii < argc) {
						break
					}
					p1 = (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint + uintptr(ii)*24
					eType1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*4)))
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(ii*int32(2)))))
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(ii*int32(2)+int32(1))))) - int32('0')
					if (*TRtreeConstraint)(unsafe.Pointer(p1)).Fop >= int32(RTREE_MATCH) {
						/* A MATCH operator. The right-hand-side must be a blob that
						 ** can be cast into an RtreeMatchArg object. One created using
						 ** an sqlite3_rtree_geometry_callback() SQL user function.
						 */
						rc = _deserializeGeometry(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*4)), p1)
						if rc != SQLITE_OK {
							break
						}
						(*Tsqlite3_rtree_query_info)(unsafe.Pointer((*TRtreeConstraint)(unsafe.Pointer(p1)).FpInfo)).FnCoord = int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)
						(*Tsqlite3_rtree_query_info)(unsafe.Pointer((*TRtreeConstraint)(unsafe.Pointer(p1)).FpInfo)).FanQueue = pCsr + 84
						(*Tsqlite3_rtree_query_info)(unsafe.Pointer((*TRtreeConstraint)(unsafe.Pointer(p1)).FpInfo)).FmxLevel = (*TRtree)(unsafe.Pointer(pRtree)).FiDepth + int32(1)
					} else {
						if eType1 == int32(SQLITE_INTEGER) {
							iVal = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*4)))
							*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(float64(iVal))
							if iVal >= libc.Int64FromInt32(1)<<libc.Int32FromInt32(48) || iVal <= -(libc.Int64FromInt32(1)<<libc.Int32FromInt32(48)) {
								if (*TRtreeConstraint)(unsafe.Pointer(p1)).Fop == int32(RTREE_LT) {
									(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32(RTREE_LE)
								}
								if (*TRtreeConstraint)(unsafe.Pointer(p1)).Fop == int32(RTREE_GT) {
									(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32(RTREE_GE)
								}
							}
						} else {
							if eType1 == int32(SQLITE_FLOAT) {
								*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*4)))
							} else {
								*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(0)
								if eType1 == int32(SQLITE_NULL) {
									(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32(RTREE_FALSE)
								} else {
									if (*TRtreeConstraint)(unsafe.Pointer(p1)).Fop == int32(RTREE_LT) || (*TRtreeConstraint)(unsafe.Pointer(p1)).Fop == int32(RTREE_LE) {
										(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32(RTREE_TRUE)
									} else {
										(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32(RTREE_FALSE)
									}
								}
							}
						}
					}
					goto _1
				_1:
					;
					ii++
				}
			}
		}
		if rc == SQLITE_OK {
			/* Due to the resetCursor() call above */
			pNew = _rtreeSearchPointNew(tls, pCsr, float64(0), uint8((*TRtree)(unsafe.Pointer(pRtree)).FiDepth+libc.Int32FromInt32(1)))
			if pNew == uintptr(0) { /* Because pCsr->bPoint was FALSE */
				return int32(SQLITE_NOMEM)
			}
			(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).Fid = int64(1)
			(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FiCell = uint8(0)
			(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FeWithin = uint8(PARTLY_WITHIN)
			*(*uintptr)(unsafe.Pointer(pCsr + 64)) = *(*uintptr)(unsafe.Pointer(bp))
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			rc = _rtreeStepToLeaf(tls, pCsr)
		}
	}
	_nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
	_rtreeRelease(tls, pRtree)
	return rc
}

// C documentation
//
//	/*
//	** Rtree virtual table module xBestIndex method. There are three
//	** table scan strategies to choose from (in order from most to
//	** least desirable):
//	**
//	**   idxNum     idxStr        Strategy
//	**   ------------------------------------------------
//	**     1        Unused        Direct lookup by rowid.
//	**     2        See below     R-tree query or full-table scan.
//	**   ------------------------------------------------
//	**
//	** If strategy 1 is used, then idxStr is not meaningful. If strategy
//	** 2 is used, idxStr is formatted to contain 2 bytes for each
//	** constraint used. The first two bytes of idxStr correspond to
//	** the constraint in sqlite3_index_info.aConstraintUsage[] with
//	** (argvIndex==1) etc.
//	**
//	** The first of each pair of bytes in idxStr identifies the constraint
//	** operator as follows:
//	**
//	**   Operator    Byte Value
//	**   ----------------------
//	**      =        0x41 ('A')
//	**     <=        0x42 ('B')
//	**      <        0x43 ('C')
//	**     >=        0x44 ('D')
//	**      >        0x45 ('E')
//	**   MATCH       0x46 ('F')
//	**   ----------------------
//	**
//	** The second of each pair of bytes identifies the coordinate column
//	** to which the constraint applies. The leftmost coordinate column
//	** is 'a', the second from the left 'b' etc.
//	*/
func _rtreeBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bMatch, iIdx, ii, jj, rc, v4, v5 int32
	var doOmit, op Tu8
	var nRow Ti64
	var p, pRtree uintptr
	var _ /* zIdxStr at bp+0 */ [41]int8
	_, _, _, _, _, _, _, _, _, _, _, _ = bMatch, doOmit, iIdx, ii, jj, nRow, op, p, pRtree, rc, v4, v5
	pRtree = tab
	rc = SQLITE_OK
	bMatch = 0 /* Estimated rows returned by this scan */
	iIdx = 0
	libc.Xmemset(tls, bp, 0, uint32(41))
	/* Check if there exists a MATCH constraint - even an unusable one. If there
	 ** is, do not consider the lookup-by-rowid plan as using such a plan would
	 ** require the VDBE to evaluate the MATCH constraint, which is not currently
	 ** possible. */
	ii = 0
	for {
		if !(ii < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		if int32((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12))).Fop) == int32(SQLITE_INDEX_CONSTRAINT_MATCH) {
			bMatch = int32(1)
		}
		goto _1
	_1:
		;
		ii++
	}
	ii = 0
	for {
		if !(ii < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint && iIdx < int32(libc.Uint32FromInt64(41)-libc.Uint32FromInt32(1))) {
			break
		}
		p = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12
		if bMatch == 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn <= 0 && int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) {
			jj = 0
			for {
				if !(jj < ii) {
					break
				}
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8))).FargvIndex = 0
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8))).Fomit = uint8(0)
				goto _3
			_3:
				;
				jj++
			}
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(1)
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8))).FargvIndex = int32(1)
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8))).Fomit = uint8(1)
			/* This strategy involves a two rowid lookups on an B-Tree structures
			 ** and then a linear search of an R-Tree node. This should be
			 ** considered almost as quick as a direct rowid lookup (for which
			 ** sqlite uses an internal cost of 0.0). It is expected to return
			 ** a single row.
			 */
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(30)
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = int32(SQLITE_INDEX_SCAN_UNIQUE)
			return SQLITE_OK
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 && ((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn > 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn <= int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) || int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_MATCH)) {
			doOmit = uint8(1)
			switch int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) {
			case int32(SQLITE_INDEX_CONSTRAINT_EQ):
				op = uint8(RTREE_EQ)
				doOmit = uint8(0)
			case int32(SQLITE_INDEX_CONSTRAINT_GT):
				op = uint8(RTREE_GT)
				doOmit = uint8(0)
			case int32(SQLITE_INDEX_CONSTRAINT_LE):
				op = uint8(RTREE_LE)
			case int32(SQLITE_INDEX_CONSTRAINT_LT):
				op = uint8(RTREE_LT)
				doOmit = uint8(0)
			case int32(SQLITE_INDEX_CONSTRAINT_GE):
				op = uint8(RTREE_GE)
			case int32(SQLITE_INDEX_CONSTRAINT_MATCH):
				op = uint8(RTREE_MATCH)
			default:
				op = uint8(0)
				break
			}
			if op != 0 {
				v4 = iIdx
				iIdx++
				(*(*[41]int8)(unsafe.Pointer(bp)))[v4] = int8(int8(op))
				v5 = iIdx
				iIdx++
				(*(*[41]int8)(unsafe.Pointer(bp)))[v5] = int8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn - libc.Int32FromInt32(1) + libc.Int32FromUint8('0'))
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8))).FargvIndex = iIdx / int32(2)
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8))).Fomit = doOmit
			}
		}
		goto _2
	_2:
		;
		ii++
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(2)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = int32(1)
	if iIdx > 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = Xsqlite3_malloc(tls, iIdx+int32(1))
		if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemcpy(tls, (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr, bp, uint32(iIdx+int32(1)))
	}
	nRow = (*TRtree)(unsafe.Pointer(pRtree)).FnRowEst >> (iIdx / int32(2))
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromFloat64(6) * float64(float64(nRow))
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = nRow
	return rc
}

// C documentation
//
//	/*
//	** Return the N-dimensional volumn of the cell stored in *p.
//	*/
func _cellArea(tls *libc.TLS, pRtree uintptr, p uintptr) (r TRtreeDValue) {
	var area TRtreeDValue
	_ = area
	area = libc.Float64FromInt32(1)
	if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
		switch int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim) {
		case int32(5):
			area = float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + 9*4)) - *(*TRtreeValue)(unsafe.Pointer(p + 8 + 8*4)))
			fallthrough
		case int32(4):
			area *= float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + 7*4)) - *(*TRtreeValue)(unsafe.Pointer(p + 8 + 6*4)))
			fallthrough
		case int32(3):
			area *= float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + 5*4)) - *(*TRtreeValue)(unsafe.Pointer(p + 8 + 4*4)))
			fallthrough
		case int32(2):
			area *= float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + 3*4)) - *(*TRtreeValue)(unsafe.Pointer(p + 8 + 2*4)))
			fallthrough
		default:
			area *= float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + 1*4)) - *(*TRtreeValue)(unsafe.Pointer(p + 8)))
		}
	} else {
		switch int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim) {
		case int32(5):
			area = float64(int64(*(*int32)(unsafe.Pointer(p + 8 + 9*4))) - int64(*(*int32)(unsafe.Pointer(p + 8 + 8*4))))
			fallthrough
		case int32(4):
			area *= float64(int64(*(*int32)(unsafe.Pointer(p + 8 + 7*4))) - int64(*(*int32)(unsafe.Pointer(p + 8 + 6*4))))
			fallthrough
		case int32(3):
			area *= float64(int64(*(*int32)(unsafe.Pointer(p + 8 + 5*4))) - int64(*(*int32)(unsafe.Pointer(p + 8 + 4*4))))
			fallthrough
		case int32(2):
			area *= float64(int64(*(*int32)(unsafe.Pointer(p + 8 + 3*4))) - int64(*(*int32)(unsafe.Pointer(p + 8 + 2*4))))
			fallthrough
		default:
			area *= float64(int64(*(*int32)(unsafe.Pointer(p + 8 + 1*4))) - int64(*(*int32)(unsafe.Pointer(p + 8))))
		}
	}
	return area
}

// C documentation
//
//	/*
//	** Return the margin length of cell p. The margin length is the sum
//	** of the objects size in each dimension.
//	*/
func _cellMargin(tls *libc.TLS, pRtree uintptr, p uintptr) (r TRtreeDValue) {
	var ii int32
	var margin TRtreeDValue
	var v1, v2 float64
	_, _, _, _ = ii, margin, v1, v2
	margin = libc.Float64FromInt32(0)
	ii = int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) - int32(2)
	for cond := true; cond; cond = ii >= 0 {
		if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
			v1 = float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + uintptr(ii+int32(1))*4)))
		} else {
			v1 = float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(ii+int32(1))*4)))
		}
		if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
			v2 = float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + uintptr(ii)*4)))
		} else {
			v2 = float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(ii)*4)))
		}
		margin += v1 - v2
		ii -= int32(2)
	}
	return margin
}

// C documentation
//
//	/*
//	** Store the union of cells p1 and p2 in p1.
//	*/
func _cellUnion(tls *libc.TLS, pRtree uintptr, p1 uintptr, p2 uintptr) {
	var ii, v3, v4 int32
	var v1, v2 TRtreeValue
	_, _, _, _, _ = ii, v1, v2, v3, v4
	ii = 0
	if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
		for cond := true; cond; cond = ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) {
			if *(*TRtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) < *(*TRtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4)) {
				v1 = *(*TRtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4))
			} else {
				v1 = *(*TRtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4))
			}
			*(*TRtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) = v1
			if *(*TRtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii+int32(1))*4)) > *(*TRtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii+int32(1))*4)) {
				v2 = *(*TRtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii+int32(1))*4))
			} else {
				v2 = *(*TRtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii+int32(1))*4))
			}
			*(*TRtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii+int32(1))*4)) = v2
			ii += int32(2)
		}
	} else {
		for cond := true; cond; cond = ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) {
			if *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) < *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4)) {
				v3 = *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4))
			} else {
				v3 = *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4))
			}
			*(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) = v3
			if *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii+int32(1))*4)) > *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii+int32(1))*4)) {
				v4 = *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii+int32(1))*4))
			} else {
				v4 = *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii+int32(1))*4))
			}
			*(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii+int32(1))*4)) = v4
			ii += int32(2)
		}
	}
}

// C documentation
//
//	/*
//	** Return true if the area covered by p2 is a subset of the area covered
//	** by p1. False otherwise.
//	*/
func _cellContains(tls *libc.TLS, pRtree uintptr, p1 uintptr, p2 uintptr) (r int32) {
	var a1, a11, a2, a21 uintptr
	var ii int32
	_, _, _, _, _ = a1, a11, a2, a21, ii
	if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == int32(RTREE_COORD_INT32) {
		ii = 0
		for {
			if !(ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)) {
				break
			}
			a1 = p1 + 8 + uintptr(ii)*4
			a2 = p2 + 8 + uintptr(ii)*4
			if *(*int32)(unsafe.Pointer(a2)) < *(*int32)(unsafe.Pointer(a1)) || *(*int32)(unsafe.Pointer(a2 + 1*4)) > *(*int32)(unsafe.Pointer(a1 + 1*4)) {
				return 0
			}
			goto _1
		_1:
			;
			ii += int32(2)
		}
	} else {
		ii = 0
		for {
			if !(ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)) {
				break
			}
			a11 = p1 + 8 + uintptr(ii)*4
			a21 = p2 + 8 + uintptr(ii)*4
			if *(*TRtreeValue)(unsafe.Pointer(a21)) < *(*TRtreeValue)(unsafe.Pointer(a11)) || *(*TRtreeValue)(unsafe.Pointer(a21 + 1*4)) > *(*TRtreeValue)(unsafe.Pointer(a11 + 1*4)) {
				return 0
			}
			goto _2
		_2:
			;
			ii += int32(2)
		}
	}
	return int32(1)
}

func _cellOverlap(tls *libc.TLS, pRtree uintptr, p uintptr, aCell uintptr, nCell int32) (r TRtreeDValue) {
	var ii, jj int32
	var o, overlap, x1, x2 TRtreeDValue
	var v10, v11, v12, v3, v4, v5, v6, v7, v8, v9 float64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ii, jj, o, overlap, x1, x2, v10, v11, v12, v3, v4, v5, v6, v7, v8, v9
	overlap = float64(0)
	ii = 0
	for {
		if !(ii < nCell) {
			break
		}
		o = libc.Float64FromInt32(1)
		jj = 0
		for {
			if !(jj < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)) {
				break
			}
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v4 = float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
			} else {
				v4 = float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
			}
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v5 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
			} else {
				v5 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
			}
			if v4 > v5 {
				if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					v6 = float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
				} else {
					v6 = float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
				}
				v3 = v6
			} else {
				if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					v7 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
				} else {
					v7 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
				}
				v3 = v7
			}
			x1 = v3
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v9 = float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj+int32(1))*4)))
			} else {
				v9 = float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj+int32(1))*4)))
			}
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v10 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+int32(1))*4)))
			} else {
				v10 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+int32(1))*4)))
			}
			if v9 < v10 {
				if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					v11 = float64(*(*TRtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj+int32(1))*4)))
				} else {
					v11 = float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj+int32(1))*4)))
				}
				v8 = v11
			} else {
				if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					v12 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+int32(1))*4)))
				} else {
					v12 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+int32(1))*4)))
				}
				v8 = v12
			}
			x2 = v8
			if x2 < x1 {
				o = libc.Float64FromInt32(0)
				break
			} else {
				o = o * (x2 - x1)
			}
			goto _2
		_2:
			;
			jj += int32(2)
		}
		overlap += o
		goto _1
	_1:
		;
		ii++
	}
	return overlap
}

// C documentation
//
//	/*
//	** This function implements the ChooseLeaf algorithm from Gutman[84].
//	** ChooseSubTree in r*tree terminology.
//	*/
func _ChooseLeaf(tls *libc.TLS, pRtree uintptr, pCell uintptr, iHeight int32, ppLeaf uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var area, area1, fMinArea, fMinGrowth, growth TRtreeDValue
	var bFound, iCell, ii, nCell, rc int32
	var iBest Tsqlite3_int64
	var _ /* cell at bp+56 */ TRtreeCell
	var _ /* cell at bp+8 */ TRtreeCell
	var _ /* pChild at bp+4 */ uintptr
	var _ /* pNode at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = area, area1, bFound, fMinArea, fMinGrowth, growth, iBest, iCell, ii, nCell, rc
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)
	ii = 0
	for {
		if !(rc == SQLITE_OK && ii < (*TRtree)(unsafe.Pointer(pRtree)).FiDepth-iHeight) {
			break
		}
		iBest = 0
		bFound = 0
		fMinGrowth = float64(0)
		fMinArea = float64(0)
		nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzData+2)
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		/* First check to see if there is are any cells in pNode that completely
		 ** contains pCell.  If two or more cells in pNode completely contain pCell
		 ** then pick the smallest.
		 */
		iCell = 0
		for {
			if !(iCell < nCell) {
				break
			}
			_nodeGetCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), iCell, bp+8)
			if _cellContains(tls, pRtree, bp+8, pCell) != 0 {
				area = _cellArea(tls, pRtree, bp+8)
				if bFound == 0 || area < fMinArea {
					iBest = (*(*TRtreeCell)(unsafe.Pointer(bp + 8))).FiRowid
					fMinArea = area
					bFound = int32(1)
				}
			}
			goto _2
		_2:
			;
			iCell++
		}
		if !(bFound != 0) {
			/* No cells of pNode will completely contain pCell.  So pick the
			 ** cell of pNode that grows by the least amount when pCell is added.
			 ** Break ties by selecting the smaller cell.
			 */
			iCell = 0
			for {
				if !(iCell < nCell) {
					break
				}
				_nodeGetCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), iCell, bp+56)
				area1 = _cellArea(tls, pRtree, bp+56)
				_cellUnion(tls, pRtree, bp+56, pCell)
				growth = _cellArea(tls, pRtree, bp+56) - area1
				if iCell == 0 || growth < fMinGrowth || growth == fMinGrowth && area1 < fMinArea {
					fMinGrowth = growth
					fMinArea = area1
					iBest = (*(*TRtreeCell)(unsafe.Pointer(bp + 56))).FiRowid
				}
				goto _3
			_3:
				;
				iCell++
			}
		}
		rc = _nodeAcquire(tls, pRtree, iBest, *(*uintptr)(unsafe.Pointer(bp)), bp+4)
		_nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
		*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(bp + 4))
		goto _1
	_1:
		;
		ii++
	}
	*(*uintptr)(unsafe.Pointer(ppLeaf)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

// C documentation
//
//	/*
//	** A cell with the same content as pCell has just been inserted into
//	** the node pNode. This function updates the bounding box cells in
//	** all ancestor elements.
//	*/
func _AdjustTree(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var cnt, rc int32
	var p, pParent uintptr
	var _ /* cell at bp+0 */ TRtreeCell
	var _ /* iCell at bp+48 */ int32
	_, _, _, _ = cnt, p, pParent, rc
	p = pNode
	cnt = 0
	for (*TRtreeNode)(unsafe.Pointer(p)).FpParent != 0 {
		pParent = (*TRtreeNode)(unsafe.Pointer(p)).FpParent
		cnt++
		if cnt > int32(100) {
			return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		rc = _nodeParentIndex(tls, pRtree, p, bp+48)
		if rc != SQLITE_OK {
			return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		_nodeGetCell(tls, pRtree, pParent, *(*int32)(unsafe.Pointer(bp + 48)), bp)
		if !(_cellContains(tls, pRtree, bp, pCell) != 0) {
			_cellUnion(tls, pRtree, bp, pCell)
			_nodeOverwriteCell(tls, pRtree, pParent, bp, *(*int32)(unsafe.Pointer(bp + 48)))
		}
		p = pParent
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
//	*/
func _rowidWrite(tls *libc.TLS, pRtree uintptr, iRowid Tsqlite3_int64, iNode Tsqlite3_int64) (r int32) {
	Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid, int32(1), iRowid)
	Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid, int32(2), iNode)
	Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
	return Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
}

// C documentation
//
//	/*
//	** Write mapping (iNode->iPar) to the <rtree>_parent table.
//	*/
func _parentWrite(tls *libc.TLS, pRtree uintptr, iNode Tsqlite3_int64, iPar Tsqlite3_int64) (r int32) {
	Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteParent, int32(1), iNode)
	Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteParent, int32(2), iPar)
	Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteParent)
	return Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteParent)
}

// C documentation
//
//	/*
//	** Arguments aIdx, aCell and aSpare all point to arrays of size
//	** nIdx. The aIdx array contains the set of integers from 0 to
//	** (nIdx-1) in no particular order. This function sorts the values
//	** in aIdx according to dimension iDim of the cells in aCell. The
//	** minimum value of dimension iDim is considered first, the
//	** maximum used to break ties.
//	**
//	** The aSpare array is used as temporary working space by the
//	** sorting algorithm.
//	*/
func _SortByDimension(tls *libc.TLS, pRtree uintptr, aIdx uintptr, nIdx int32, iDim int32, aCell uintptr, aSpare uintptr) {
	var aLeft, aRight uintptr
	var iLeft, iRight, nLeft, nRight int32
	var xleft1, xleft2, xright1, xright2 TRtreeDValue
	var v1, v2, v3, v4 float64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aLeft, aRight, iLeft, iRight, nLeft, nRight, xleft1, xleft2, xright1, xright2, v1, v2, v3, v4
	if nIdx > int32(1) {
		iLeft = 0
		iRight = 0
		nLeft = nIdx / int32(2)
		nRight = nIdx - nLeft
		aLeft = aIdx
		aRight = aIdx + uintptr(nLeft)*4
		_SortByDimension(tls, pRtree, aLeft, nLeft, iDim, aCell, aSpare)
		_SortByDimension(tls, pRtree, aRight, nRight, iDim, aCell, aSpare)
		libc.Xmemcpy(tls, aSpare, aLeft, uint32(4)*uint32(uint32(nLeft)))
		aLeft = aSpare
		for iLeft < nLeft || iRight < nRight {
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v1 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
			} else {
				v1 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
			}
			xleft1 = v1
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v2 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
			} else {
				v2 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
			}
			xleft2 = v2
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v3 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
			} else {
				v3 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
			}
			xright1 = v3
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				v4 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
			} else {
				v4 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
			}
			xright2 = v4
			if iLeft != nLeft && (iRight == nRight || xleft1 < xright1 || xleft1 == xright1 && xleft2 < xright2) {
				*(*int32)(unsafe.Pointer(aIdx + uintptr(iLeft+iRight)*4)) = *(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4))
				iLeft++
			} else {
				*(*int32)(unsafe.Pointer(aIdx + uintptr(iLeft+iRight)*4)) = *(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4))
				iRight++
			}
		}
	}
}

// C documentation
//
//	/*
//	** Implementation of the R*-tree variant of SplitNode from Beckman[1990].
//	*/
func _splitNodeStartree(tls *libc.TLS, pRtree uintptr, aCell uintptr, nCell int32, pLeft uintptr, pRight uintptr, pBboxLeft uintptr, pBboxRight uintptr) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var aSpare, aaSorted, pBbox, pCell, pTarget, v7, v8 uintptr
	var area, fBestArea, fBestMargin, fBestOverlap, margin, overlap TRtreeDValue
	var iBestDim, iBestLeft, iBestSplit, ii, jj, kk, nLeft int32
	var nByte Tsqlite3_int64
	var _ /* left at bp+0 */ TRtreeCell
	var _ /* right at bp+48 */ TRtreeCell
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aSpare, aaSorted, area, fBestArea, fBestMargin, fBestOverlap, iBestDim, iBestLeft, iBestSplit, ii, jj, kk, margin, nByte, nLeft, overlap, pBbox, pCell, pTarget, v7, v8
	iBestDim = 0
	iBestSplit = 0
	fBestMargin = float64(0)
	nByte = int64(uint32(int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim)+libc.Int32FromInt32(1)) * (uint32(4) + uint32(uint32(nCell))*uint32(4)))
	aaSorted = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	if !(aaSorted != 0) {
		return int32(SQLITE_NOMEM)
	}
	aSpare = aaSorted + uintptr((*TRtree)(unsafe.Pointer(pRtree)).FnDim)*4 + uintptr(int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim)*nCell)*4
	libc.Xmemset(tls, aaSorted, 0, uint32(uint32(nByte)))
	ii = 0
	for {
		if !(ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim)) {
			break
		}
		*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*4)) = aaSorted + uintptr((*TRtree)(unsafe.Pointer(pRtree)).FnDim)*4 + uintptr(ii*nCell)*4
		jj = 0
		for {
			if !(jj < nCell) {
				break
			}
			*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*4)) + uintptr(jj)*4)) = jj
			goto _2
		_2:
			;
			jj++
		}
		_SortByDimension(tls, pRtree, *(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*4)), nCell, ii, aCell, aSpare)
		goto _1
	_1:
		;
		ii++
	}
	ii = 0
	for {
		if !(ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim)) {
			break
		}
		margin = float64(0)
		fBestOverlap = float64(0)
		fBestArea = float64(0)
		iBestLeft = 0
		nLeft = ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize - int32(4)) / int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell) / int32(3)
		for {
			if !(nLeft <= nCell-((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/int32(3)) {
				break
			}
			libc.Xmemcpy(tls, bp, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*4)))))*48, uint32(48))
			libc.Xmemcpy(tls, bp+48, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*4)) + uintptr(nCell-int32(1))*4)))*48, uint32(48))
			kk = int32(1)
			for {
				if !(kk < nCell-int32(1)) {
					break
				}
				if kk < nLeft {
					_cellUnion(tls, pRtree, bp, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*4)) + uintptr(kk)*4)))*48)
				} else {
					_cellUnion(tls, pRtree, bp+48, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*4)) + uintptr(kk)*4)))*48)
				}
				goto _5
			_5:
				;
				kk++
			}
			margin += _cellMargin(tls, pRtree, bp)
			margin += _cellMargin(tls, pRtree, bp+48)
			overlap = _cellOverlap(tls, pRtree, bp, bp+48, int32(1))
			area = _cellArea(tls, pRtree, bp) + _cellArea(tls, pRtree, bp+48)
			if nLeft == ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/int32(3) || overlap < fBestOverlap || overlap == fBestOverlap && area < fBestArea {
				iBestLeft = nLeft
				fBestOverlap = overlap
				fBestArea = area
			}
			goto _4
		_4:
			;
			nLeft++
		}
		if ii == 0 || margin < fBestMargin {
			iBestDim = ii
			fBestMargin = margin
			iBestSplit = iBestLeft
		}
		goto _3
	_3:
		;
		ii++
	}
	libc.Xmemcpy(tls, pBboxLeft, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(iBestDim)*4)))))*48, uint32(48))
	libc.Xmemcpy(tls, pBboxRight, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(iBestDim)*4)) + uintptr(iBestSplit)*4)))*48, uint32(48))
	ii = 0
	for {
		if !(ii < nCell) {
			break
		}
		if ii < iBestSplit {
			v7 = pLeft
		} else {
			v7 = pRight
		}
		pTarget = v7
		if ii < iBestSplit {
			v8 = pBboxLeft
		} else {
			v8 = pBboxRight
		}
		pBbox = v8
		pCell = aCell + uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(iBestDim)*4)) + uintptr(ii)*4)))*48
		_nodeInsertCell(tls, pRtree, pTarget, pCell)
		_cellUnion(tls, pRtree, pBbox, pCell)
		goto _6
	_6:
		;
		ii++
	}
	Xsqlite3_free(tls, aaSorted)
	return SQLITE_OK
}

func _updateMapping(tls *libc.TLS, pRtree uintptr, iRowid Ti64, pNode uintptr, iHeight int32) (r int32) {
	var p, pChild, xSetMapping, v1 uintptr
	_, _, _, _ = p, pChild, xSetMapping, v1
	if iHeight == 0 {
		v1 = __ccgo_fp(_rowidWrite)
	} else {
		v1 = __ccgo_fp(_parentWrite)
	}
	xSetMapping = v1
	if iHeight > 0 {
		pChild = _nodeHashLookup(tls, pRtree, iRowid)
		p = pNode
		for {
			if !(p != 0) {
				break
			}
			if p == pChild {
				return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
			goto _2
		_2:
			;
			p = (*TRtreeNode)(unsafe.Pointer(p)).FpParent
		}
		if pChild != 0 {
			_nodeRelease(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pChild)).FpParent)
			_nodeReference(tls, pNode)
			(*TRtreeNode)(unsafe.Pointer(pChild)).FpParent = pNode
		}
	}
	if pNode == uintptr(0) {
		return int32(SQLITE_ERROR)
	}
	return (*(*func(*libc.TLS, uintptr, Tsqlite3_int64, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{xSetMapping})))(tls, pRtree, iRowid, (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode)
}

func _SplitNode(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iHeight int32) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var aCell, aiUsed, pLeft, pParent, pRight uintptr
	var i, nCell, newCellIsRight, rc, v2, v3, v6 int32
	var iRowid, iRowid1 Ti64
	var v4, v5 bool
	var _ /* iCell at bp+96 */ int32
	var _ /* leftbbox at bp+0 */ TRtreeCell
	var _ /* rightbbox at bp+48 */ TRtreeCell
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCell, aiUsed, i, iRowid, iRowid1, nCell, newCellIsRight, pLeft, pParent, pRight, rc, v2, v3, v4, v5, v6
	newCellIsRight = 0
	rc = SQLITE_OK
	nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2)
	pLeft = uintptr(0)
	pRight = uintptr(0)
	/* Allocate an array and populate it with a copy of pCell and
	 ** all cells from node pLeft. Then zero the original node.
	 */
	aCell = Xsqlite3_malloc64(tls, uint64((libc.Uint32FromInt64(48)+libc.Uint32FromInt64(4))*uint32(nCell+libc.Int32FromInt32(1))))
	if !(aCell != 0) {
		rc = int32(SQLITE_NOMEM)
		goto splitnode_out
	}
	aiUsed = aCell + uintptr(nCell+int32(1))*48
	libc.Xmemset(tls, aiUsed, 0, uint32(4)*uint32(nCell+libc.Int32FromInt32(1)))
	i = 0
	for {
		if !(i < nCell) {
			break
		}
		_nodeGetCell(tls, pRtree, pNode, i, aCell+uintptr(i)*48)
		goto _1
	_1:
		;
		i++
	}
	_nodeZero(tls, pRtree, pNode)
	libc.Xmemcpy(tls, aCell+uintptr(nCell)*48, pCell, uint32(48))
	nCell++
	if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
		pRight = _nodeNew(tls, pRtree, pNode)
		pLeft = _nodeNew(tls, pRtree, pNode)
		(*TRtree)(unsafe.Pointer(pRtree)).FiDepth++
		(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = int32(1)
		_writeInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData, (*TRtree)(unsafe.Pointer(pRtree)).FiDepth)
	} else {
		pLeft = pNode
		pRight = _nodeNew(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pLeft)).FpParent)
		(*TRtreeNode)(unsafe.Pointer(pLeft)).FnRef++
	}
	if !(pLeft != 0) || !(pRight != 0) {
		rc = int32(SQLITE_NOMEM)
		goto splitnode_out
	}
	libc.Xmemset(tls, (*TRtreeNode)(unsafe.Pointer(pLeft)).FzData, 0, uint32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize))
	libc.Xmemset(tls, (*TRtreeNode)(unsafe.Pointer(pRight)).FzData, 0, uint32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize))
	rc = _splitNodeStartree(tls, pRtree, aCell, nCell, pLeft, pRight, bp, bp+48)
	if rc != SQLITE_OK {
		goto splitnode_out
	}
	/* Ensure both child nodes have node numbers assigned to them by calling
	 ** nodeWrite(). Node pRight always needs a node number, as it was created
	 ** by nodeNew() above. But node pLeft sometimes already has a node number.
	 ** In this case avoid the all to nodeWrite().
	 */
	v2 = _nodeWrite(tls, pRtree, pRight)
	rc = v2
	if v5 = SQLITE_OK != v2; !v5 {
		if v4 = 0 == (*TRtreeNode)(unsafe.Pointer(pLeft)).FiNode; v4 {
			v3 = _nodeWrite(tls, pRtree, pLeft)
			rc = v3
		}
	}
	if v5 || v4 && SQLITE_OK != v3 {
		goto splitnode_out
	}
	(*(*TRtreeCell)(unsafe.Pointer(bp + 48))).FiRowid = (*TRtreeNode)(unsafe.Pointer(pRight)).FiNode
	(*(*TRtreeCell)(unsafe.Pointer(bp))).FiRowid = (*TRtreeNode)(unsafe.Pointer(pLeft)).FiNode
	if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
		rc = _rtreeInsertCell(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pLeft)).FpParent, bp, iHeight+int32(1))
		if rc != SQLITE_OK {
			goto splitnode_out
		}
	} else {
		pParent = (*TRtreeNode)(unsafe.Pointer(pLeft)).FpParent
		rc = _nodeParentIndex(tls, pRtree, pLeft, bp+96)
		if rc == SQLITE_OK {
			_nodeOverwriteCell(tls, pRtree, pParent, bp, *(*int32)(unsafe.Pointer(bp + 96)))
			rc = _AdjustTree(tls, pRtree, pParent, bp)
		}
		if rc != SQLITE_OK {
			goto splitnode_out
		}
	}
	v6 = _rtreeInsertCell(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pRight)).FpParent, bp+48, iHeight+int32(1))
	rc = v6
	if v6 != 0 {
		goto splitnode_out
	}
	i = 0
	for {
		if !(i < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pRight)).FzData+2)) {
			break
		}
		iRowid = _nodeGetRowid(tls, pRtree, pRight, i)
		rc = _updateMapping(tls, pRtree, iRowid, pRight, iHeight)
		if iRowid == (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid {
			newCellIsRight = int32(1)
		}
		if rc != SQLITE_OK {
			goto splitnode_out
		}
		goto _7
	_7:
		;
		i++
	}
	if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
		i = 0
		for {
			if !(i < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pLeft)).FzData+2)) {
				break
			}
			iRowid1 = _nodeGetRowid(tls, pRtree, pLeft, i)
			rc = _updateMapping(tls, pRtree, iRowid1, pLeft, iHeight)
			if rc != SQLITE_OK {
				goto splitnode_out
			}
			goto _8
		_8:
			;
			i++
		}
	} else {
		if newCellIsRight == 0 {
			rc = _updateMapping(tls, pRtree, (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid, pLeft, iHeight)
		}
	}
	if rc == SQLITE_OK {
		rc = _nodeRelease(tls, pRtree, pRight)
		pRight = uintptr(0)
	}
	if rc == SQLITE_OK {
		rc = _nodeRelease(tls, pRtree, pLeft)
		pLeft = uintptr(0)
	}
	goto splitnode_out
splitnode_out:
	;
	_nodeRelease(tls, pRtree, pRight)
	_nodeRelease(tls, pRtree, pLeft)
	Xsqlite3_free(tls, aCell)
	return rc
}

// C documentation
//
//	/*
//	** If node pLeaf is not the root of the r-tree and its pParent pointer is
//	** still NULL, load all ancestor nodes of pLeaf into memory and populate
//	** the pLeaf->pParent chain all the way up to the root node.
//	**
//	** This operation is required when a row is deleted (or updated - an update
//	** is implemented as a delete followed by an insert). SQLite provides the
//	** rowid of the row to delete, which can be used to find the leaf on which
//	** the entry resides (argument pLeaf). Once the leaf is located, this
//	** function is called to determine its ancestry.
//	*/
func _fixLeafParent(tls *libc.TLS, pRtree uintptr, pLeaf uintptr) (r int32) {
	var iNode Ti64
	var pChild, pTest uintptr
	var rc, rc2 int32
	_, _, _, _, _ = iNode, pChild, pTest, rc, rc2
	rc = SQLITE_OK
	pChild = pLeaf
	for rc == SQLITE_OK && (*TRtreeNode)(unsafe.Pointer(pChild)).FiNode != int64(1) && (*TRtreeNode)(unsafe.Pointer(pChild)).FpParent == uintptr(0) {
		rc2 = SQLITE_OK /* sqlite3_reset() return code */
		Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadParent, int32(1), (*TRtreeNode)(unsafe.Pointer(pChild)).FiNode)
		rc = Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadParent)
		if rc == int32(SQLITE_ROW) { /* Node number of parent node */
			/* Before setting pChild->pParent, test that we are not creating a
			 ** loop of references (as we would if, say, pChild==pParent). We don't
			 ** want to do this as it leads to a memory leak when trying to delete
			 ** the referenced counted node structures.
			 */
			iNode = Xsqlite3_column_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadParent, 0)
			pTest = pLeaf
			for {
				if !(pTest != 0 && (*TRtreeNode)(unsafe.Pointer(pTest)).FiNode != iNode) {
					break
				}
				goto _1
			_1:
				;
				pTest = (*TRtreeNode)(unsafe.Pointer(pTest)).FpParent
			}
			if pTest == uintptr(0) {
				rc2 = _nodeAcquire(tls, pRtree, iNode, uintptr(0), pChild)
			}
		}
		rc = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadParent)
		if rc == SQLITE_OK {
			rc = rc2
		}
		if rc == SQLITE_OK && !((*TRtreeNode)(unsafe.Pointer(pChild)).FpParent != 0) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		pChild = (*TRtreeNode)(unsafe.Pointer(pChild)).FpParent
	}
	return rc
}

func _removeNode(tls *libc.TLS, pRtree uintptr, pNode uintptr, iHeight int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pParent uintptr
	var rc, rc2, v1, v2 int32
	var _ /* iCell at bp+0 */ int32
	_, _, _, _, _ = pParent, rc, rc2, v1, v2
	pParent = uintptr(0)
	/* Remove the entry in the parent cell. */
	rc = _nodeParentIndex(tls, pRtree, pNode, bp)
	if rc == SQLITE_OK {
		pParent = (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent
		(*TRtreeNode)(unsafe.Pointer(pNode)).FpParent = uintptr(0)
		rc = _deleteCell(tls, pRtree, pParent, *(*int32)(unsafe.Pointer(bp)), iHeight+int32(1))
	}
	rc2 = _nodeRelease(tls, pRtree, pParent)
	if rc == SQLITE_OK {
		rc = rc2
	}
	if rc != SQLITE_OK {
		return rc
	}
	/* Remove the xxx_node entry. */
	Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteNode, int32(1), (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode)
	Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteNode)
	v1 = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteNode)
	rc = v1
	if SQLITE_OK != v1 {
		return rc
	}
	/* Remove the xxx_parent entry. */
	Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteParent, int32(1), (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode)
	Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteParent)
	v2 = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteParent)
	rc = v2
	if SQLITE_OK != v2 {
		return rc
	}
	/* Remove the node from the in-memory hash table and link it into
	 ** the Rtree.pDeleted list. Its contents will be re-inserted later on.
	 */
	_nodeHashDelete(tls, pRtree, pNode)
	(*TRtreeNode)(unsafe.Pointer(pNode)).FiNode = int64(int64(iHeight))
	(*TRtreeNode)(unsafe.Pointer(pNode)).FpNext = (*TRtree)(unsafe.Pointer(pRtree)).FpDeleted
	(*TRtreeNode)(unsafe.Pointer(pNode)).FnRef++
	(*TRtree)(unsafe.Pointer(pRtree)).FpDeleted = pNode
	return SQLITE_OK
}

func _fixBoundingBox(tls *libc.TLS, pRtree uintptr, pNode uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var nCell, rc int32
	var pParent uintptr
	var _ /* box at bp+8 */ TRtreeCell
	var _ /* cell at bp+56 */ TRtreeCell
	var _ /* ii at bp+0 */ int32
	_, _, _ = nCell, pParent, rc
	pParent = (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent
	rc = SQLITE_OK
	if pParent != 0 {
		nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2) /* Bounding box for pNode */
		_nodeGetCell(tls, pRtree, pNode, 0, bp+8)
		*(*int32)(unsafe.Pointer(bp)) = int32(1)
		for {
			if !(*(*int32)(unsafe.Pointer(bp)) < nCell) {
				break
			}
			_nodeGetCell(tls, pRtree, pNode, *(*int32)(unsafe.Pointer(bp)), bp+56)
			_cellUnion(tls, pRtree, bp+8, bp+56)
			goto _1
		_1:
			;
			*(*int32)(unsafe.Pointer(bp))++
		}
		(*(*TRtreeCell)(unsafe.Pointer(bp + 8))).FiRowid = (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode
		rc = _nodeParentIndex(tls, pRtree, pNode, bp)
		if rc == SQLITE_OK {
			_nodeOverwriteCell(tls, pRtree, pParent, bp+8, *(*int32)(unsafe.Pointer(bp)))
			rc = _fixBoundingBox(tls, pRtree, pParent)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Delete the cell at index iCell of node pNode. After removing the
//	** cell, adjust the r-tree data structure if required.
//	*/
func _deleteCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32, iHeight int32) (r int32) {
	var pParent uintptr
	var rc, v1 int32
	_, _, _ = pParent, rc, v1
	v1 = _fixLeafParent(tls, pRtree, pNode)
	rc = v1
	if SQLITE_OK != v1 {
		return rc
	}
	/* Remove the cell from the node. This call just moves bytes around
	 ** the in-memory node image, so it cannot fail.
	 */
	_nodeDeleteCell(tls, pRtree, pNode, iCell)
	/* If the node is not the tree root and now has less than the minimum
	 ** number of cells, remove it from the tree. Otherwise, update the
	 ** cell in the parent node so that it tightly contains the updated
	 ** node.
	 */
	pParent = (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent
	if pParent != 0 {
		if _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2) < ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/int32(3) {
			rc = _removeNode(tls, pRtree, pNode, iHeight)
		} else {
			rc = _fixBoundingBox(tls, pRtree, pNode)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Insert cell pCell into node pNode. Node pNode is the head of a
//	** subtree iHeight high (leaf nodes have iHeight==0).
//	*/
func _rtreeInsertCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iHeight int32) (r int32) {
	var pChild uintptr
	var rc int32
	_, _ = pChild, rc
	rc = SQLITE_OK
	if iHeight > 0 {
		pChild = _nodeHashLookup(tls, pRtree, (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid)
		if pChild != 0 {
			_nodeRelease(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pChild)).FpParent)
			_nodeReference(tls, pNode)
			(*TRtreeNode)(unsafe.Pointer(pChild)).FpParent = pNode
		}
	}
	if _nodeInsertCell(tls, pRtree, pNode, pCell) != 0 {
		rc = _SplitNode(tls, pRtree, pNode, pCell, iHeight)
	} else {
		rc = _AdjustTree(tls, pRtree, pNode, pCell)
		if rc == SQLITE_OK {
			if iHeight == 0 {
				rc = _rowidWrite(tls, pRtree, (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid, (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode)
			} else {
				rc = _parentWrite(tls, pRtree, (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid, (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode)
			}
		}
	}
	return rc
}

func _reinsertNodeContent(tls *libc.TLS, pRtree uintptr, pNode uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var ii, nCell, rc, rc2 int32
	var _ /* cell at bp+8 */ TRtreeCell
	var _ /* pInsert at bp+0 */ uintptr
	_, _, _, _ = ii, nCell, rc, rc2
	rc = SQLITE_OK
	nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2)
	ii = 0
	for {
		if !(rc == SQLITE_OK && ii < nCell) {
			break
		}
		_nodeGetCell(tls, pRtree, pNode, ii, bp+8)
		/* Find a node to store this cell in. pNode->iNode currently contains
		 ** the height of the sub-tree headed by the cell.
		 */
		rc = _ChooseLeaf(tls, pRtree, bp+8, int32((*TRtreeNode)(unsafe.Pointer(pNode)).FiNode), bp)
		if rc == SQLITE_OK {
			rc = _rtreeInsertCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), bp+8, int32((*TRtreeNode)(unsafe.Pointer(pNode)).FiNode))
			rc2 = _nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
		goto _1
	_1:
		;
		ii++
	}
	return rc
}

// C documentation
//
//	/*
//	** Select a currently unused rowid for a new r-tree record.
//	*/
func _rtreeNewRowid(tls *libc.TLS, pRtree uintptr, piRowid uintptr) (r int32) {
	var rc int32
	_ = rc
	Xsqlite3_bind_null(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid, int32(1))
	Xsqlite3_bind_null(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid, int32(2))
	Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
	rc = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
	*(*Ti64)(unsafe.Pointer(piRowid)) = Xsqlite3_last_insert_rowid(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb)
	return rc
}

// C documentation
//
//	/*
//	** Remove the entry with rowid=iDelete from the r-tree structure.
//	*/
func _rtreeDeleteRowid(tls *libc.TLS, pRtree uintptr, iDelete Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iChild Ti64
	var rc, rc2, rc21 int32
	var _ /* iCell at bp+4 */ int32
	var _ /* pChild at bp+12 */ uintptr
	var _ /* pLeaf at bp+0 */ uintptr
	var _ /* pRoot at bp+8 */ uintptr
	_, _, _, _ = iChild, rc, rc2, rc21               /* Return code */
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)     /* Index of iDelete cell in pLeaf */
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0) /* Root node of rtree structure */
	/* Obtain a reference to the root node to initialize Rtree.iDepth */
	rc = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp+8)
	/* Obtain a reference to the leaf node that contains the entry
	 ** about to be deleted.
	 */
	if rc == SQLITE_OK {
		rc = _findLeafNode(tls, pRtree, iDelete, bp, uintptr(0))
	}
	/* Delete the cell in question from the leaf node. */
	if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		rc = _nodeRowidIndex(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), iDelete, bp+4)
		if rc == SQLITE_OK {
			rc = _deleteCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)), 0)
		}
		rc2 = _nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
		if rc == SQLITE_OK {
			rc = rc2
		}
	}
	/* Delete the corresponding entry in the <rtree>_rowid table. */
	if rc == SQLITE_OK {
		Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteRowid, int32(1), iDelete)
		Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
		rc = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
	}
	/* Check if the root node now has exactly one child. If so, remove
	 ** it, schedule the contents of the child for reinsertion and
	 ** reduce the tree height by one.
	 **
	 ** This is equivalent to copying the contents of the child into
	 ** the root node (the operation that Gutman's paper says to perform
	 ** in this scenario).
	 */
	if rc == SQLITE_OK && (*TRtree)(unsafe.Pointer(pRtree)).FiDepth > 0 && _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FzData+2) == int32(1) {
		*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
		iChild = _nodeGetRowid(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)), 0)
		rc = _nodeAcquire(tls, pRtree, iChild, *(*uintptr)(unsafe.Pointer(bp + 8)), bp+12) /* tag-20210916a */
		if rc == SQLITE_OK {
			rc = _removeNode(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 12)), (*TRtree)(unsafe.Pointer(pRtree)).FiDepth-int32(1))
		}
		rc21 = _nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 12)))
		if rc == SQLITE_OK {
			rc = rc21
		}
		if rc == SQLITE_OK {
			(*TRtree)(unsafe.Pointer(pRtree)).FiDepth--
			_writeInt16(tls, (*TRtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FzData, (*TRtree)(unsafe.Pointer(pRtree)).FiDepth)
			(*TRtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FisDirty = int32(1)
		}
	}
	/* Re-insert the contents of any underfull nodes removed from the tree. */
	*(*uintptr)(unsafe.Pointer(bp)) = (*TRtree)(unsafe.Pointer(pRtree)).FpDeleted
	for {
		if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
			break
		}
		if rc == SQLITE_OK {
			rc = _reinsertNodeContent(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
		}
		(*TRtree)(unsafe.Pointer(pRtree)).FpDeleted = (*TRtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpNext
		(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef--
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
		goto _1
	_1:
		;
		*(*uintptr)(unsafe.Pointer(bp)) = (*TRtree)(unsafe.Pointer(pRtree)).FpDeleted
	}
	/* Release the reference to the root node. */
	if rc == SQLITE_OK {
		rc = _nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)))
	} else {
		_nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}
	return rc
}

/*
** Rounding constants for float->double conversion.
 */

// C documentation
//
//	/*
//	** Convert an sqlite3_value into an RtreeValue (presumably a float)
//	** while taking care to round toward negative or positive, respectively.
//	*/
func _rtreeValueDown(tls *libc.TLS, v uintptr) (r TRtreeValue) {
	var d, v1 float64
	var f float32
	_, _, _ = d, f, v1
	d = Xsqlite3_value_double(tls, v)
	f = float32(float32(d))
	if float64(float64(f)) > d {
		if d < libc.Float64FromInt32(0) {
			v1 = float64(1) + libc.Float64FromFloat64(1)/libc.Float64FromFloat64(8.388608e+06)
		} else {
			v1 = float64(1) - libc.Float64FromFloat64(1)/libc.Float64FromFloat64(8.388608e+06)
		}
		f = float32(d * v1)
	}
	return f
}

func _rtreeValueUp(tls *libc.TLS, v uintptr) (r TRtreeValue) {
	var d, v1 float64
	var f float32
	_, _, _ = d, f, v1
	d = Xsqlite3_value_double(tls, v)
	f = float32(float32(d))
	if float64(float64(f)) < d {
		if d < libc.Float64FromInt32(0) {
			v1 = float64(1) - libc.Float64FromFloat64(1)/libc.Float64FromFloat64(8.388608e+06)
		} else {
			v1 = float64(1) + libc.Float64FromFloat64(1)/libc.Float64FromFloat64(8.388608e+06)
		}
		f = float32(d * v1)
	}
	return f
}

// C documentation
//
//	/*
//	** A constraint has failed while inserting a row into an rtree table.
//	** Assuming no OOM error occurs, this function sets the error message
//	** (at pRtree->base.zErrMsg) to an appropriate value and returns
//	** SQLITE_CONSTRAINT.
//	**
//	** Parameter iCol is the index of the leftmost column involved in the
//	** constraint failure. If it is 0, then the constraint that failed is
//	** the unique constraint on the id column. Otherwise, it is the rtree
//	** (c1<=c2) constraint on columns iCol and iCol+1 that has failed.
//	**
//	** If an OOM occurs, SQLITE_NOMEM is returned instead of SQLITE_CONSTRAINT.
//	*/
func _rtreeConstraintError(tls *libc.TLS, pRtree uintptr, iCol int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc, v1 int32
	var zCol, zCol1, zCol2, zSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _ = rc, zCol, zCol1, zCol2, zSql, v1
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+27321, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
	if zSql != 0 {
		rc = Xsqlite3_prepare_v2(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zSql, -int32(1), bp, uintptr(0))
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	Xsqlite3_free(tls, zSql)
	if rc == SQLITE_OK {
		if iCol == 0 {
			zCol = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27341, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zCol))
		} else {
			zCol1 = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp)), iCol)
			zCol2 = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp)), iCol+int32(1))
			(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27373, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zCol1, zCol2))
		}
	}
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == SQLITE_OK {
		v1 = int32(SQLITE_CONSTRAINT)
	} else {
		v1 = rc
	}
	return v1
}

// C documentation
//
//	/*
//	** The xUpdate method for rtree module virtual tables.
//	*/
func _rtreeUpdate(tls *libc.TLS, pVtab uintptr, nData int32, aData uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bHaveRowid, ii, jj, nn, rc, rc2, steprc int32
	var pRtree, pUp uintptr
	var _ /* cell at bp+0 */ TRtreeCell
	var _ /* pLeaf at bp+48 */ uintptr
	_, _, _, _, _, _, _, _, _ = bHaveRowid, ii, jj, nn, pRtree, pUp, rc, rc2, steprc
	pRtree = pVtab
	rc = SQLITE_OK /* New cell to insert if nData>1 */
	bHaveRowid = 0 /* Set to 1 after new rowid is determined */
	if (*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef != 0 {
		/* Unable to write to the btree while another cursor is reading from it,
		 ** since the write might do a rebalance which would disrupt the read
		 ** cursor. */
		return libc.Int32FromInt32(SQLITE_LOCKED) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	_rtreeReference(tls, pRtree)
	libc.Xmemset(tls, bp, 0, uint32(48))
	/* Constraint handling. A write operation on an r-tree table may return
	 ** SQLITE_CONSTRAINT for two reasons:
	 **
	 **   1. A duplicate rowid value, or
	 **   2. The supplied data violates the "x2>=x1" constraint.
	 **
	 ** In the first case, if the conflict-handling mode is REPLACE, then
	 ** the conflicting row can be removed before proceeding. In the second
	 ** case, SQLITE_CONSTRAINT must be returned regardless of the
	 ** conflict-handling mode specified by the user.
	 */
	if nData > int32(1) {
		nn = nData - int32(4)
		if nn > int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) {
			nn = int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)
		}
		/* Populate the cell.aCoord[] array. The first coordinate is aData[3].
		 **
		 ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
		 ** with "column" that are interpreted as table constraints.
		 ** Example:  CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
		 ** This problem was discovered after years of use, so we silently ignore
		 ** these kinds of misdeclared tables to avoid breaking any legacy.
		 */
		if int32((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
			ii = 0
			for {
				if !(ii < nn) {
					break
				}
				*(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) = _rtreeValueDown(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+int32(3))*4)))
				*(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) = _rtreeValueUp(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+int32(4))*4)))
				if *(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) > *(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) {
					rc = _rtreeConstraintError(tls, pRtree, ii+int32(1))
					goto constraint
				}
				goto _1
			_1:
				;
				ii += int32(2)
			}
		} else {
			ii = 0
			for {
				if !(ii < nn) {
					break
				}
				*(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+int32(3))*4)))
				*(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+int32(4))*4)))
				if *(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) > *(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) {
					rc = _rtreeConstraintError(tls, pRtree, ii+int32(1))
					goto constraint
				}
				goto _2
			_2:
				;
				ii += int32(2)
			}
		}
		/* If a rowid value was supplied, check if it is already present in
		 ** the table. If so, the constraint has failed. */
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData + 2*4))) != int32(SQLITE_NULL) {
			(*(*TRtreeCell)(unsafe.Pointer(bp))).FiRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData + 2*4)))
			if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData))) == int32(SQLITE_NULL) || Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData))) != (*(*TRtreeCell)(unsafe.Pointer(bp))).FiRowid {
				Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid, int32(1), (*(*TRtreeCell)(unsafe.Pointer(bp))).FiRowid)
				steprc = Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
				rc = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
				if int32(SQLITE_ROW) == steprc {
					if Xsqlite3_vtab_on_conflict(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb) == int32(SQLITE_REPLACE) {
						rc = _rtreeDeleteRowid(tls, pRtree, (*(*TRtreeCell)(unsafe.Pointer(bp))).FiRowid)
					} else {
						rc = _rtreeConstraintError(tls, pRtree, 0)
						goto constraint
					}
				}
			}
			bHaveRowid = int32(1)
		}
	}
	/* If aData[0] is not an SQL NULL value, it is the rowid of a
	 ** record to delete from the r-tree table. The following block does
	 ** just that.
	 */
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData))) != int32(SQLITE_NULL) {
		rc = _rtreeDeleteRowid(tls, pRtree, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData))))
	}
	/* If the aData[] array contains more than one element, elements
	 ** (aData[2]..aData[argc-1]) contain a new record to insert into
	 ** the r-tree structure.
	 */
	if rc == SQLITE_OK && nData > int32(1) {
		/* Insert the new record into the r-tree */
		*(*uintptr)(unsafe.Pointer(bp + 48)) = uintptr(0)
		/* Figure out the rowid of the new row. */
		if bHaveRowid == 0 {
			rc = _rtreeNewRowid(tls, pRtree, bp)
		}
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*(*TRtreeCell)(unsafe.Pointer(bp))).FiRowid
		if rc == SQLITE_OK {
			rc = _ChooseLeaf(tls, pRtree, bp, 0, bp+48)
		}
		if rc == SQLITE_OK {
			rc = _rtreeInsertCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 48)), bp, 0)
			rc2 = _nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 48)))
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
		if rc == SQLITE_OK && (*TRtree)(unsafe.Pointer(pRtree)).FnAux != 0 {
			pUp = (*TRtree)(unsafe.Pointer(pRtree)).FpWriteAux
			Xsqlite3_bind_int64(tls, pUp, int32(1), *(*Tsqlite_int64)(unsafe.Pointer(pRowid)))
			jj = 0
			for {
				if !(jj < int32((*TRtree)(unsafe.Pointer(pRtree)).FnAux)) {
					break
				}
				Xsqlite3_bind_value(tls, pUp, jj+int32(2), *(*uintptr)(unsafe.Pointer(aData + uintptr(int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)+int32(3)+jj)*4)))
				goto _3
			_3:
				;
				jj++
			}
			Xsqlite3_step(tls, pUp)
			rc = Xsqlite3_reset(tls, pUp)
		}
	}
	goto constraint
constraint:
	;
	_rtreeRelease(tls, pRtree)
	return rc
}

// C documentation
//
//	/*
//	** Called when a transaction starts.
//	*/
func _rtreeBeginTransaction(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pRtree uintptr
	_ = pRtree
	pRtree = pVtab
	(*TRtree)(unsafe.Pointer(pRtree)).FinWrTrans = uint8(1)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Called when a transaction completes (either by COMMIT or ROLLBACK).
//	** The sqlite3_blob object should be released at this point.
//	*/
func _rtreeEndTransaction(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pRtree uintptr
	_ = pRtree
	pRtree = pVtab
	(*TRtree)(unsafe.Pointer(pRtree)).FinWrTrans = uint8(0)
	_nodeBlobReset(tls, pRtree)
	return SQLITE_OK
}

func _rtreeRollback(tls *libc.TLS, pVtab uintptr) (r int32) {
	return _rtreeEndTransaction(tls, pVtab)
}

// C documentation
//
//	/*
//	** The xRename method for rtree module virtual tables.
//	*/
func _rtreeRename(tls *libc.TLS, pVtab uintptr, zNewName uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var pRtree, zSql uintptr
	var rc int32
	_, _, _ = pRtree, rc, zSql
	pRtree = pVtab
	rc = int32(SQLITE_NOMEM)
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+27410, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName))
	if zSql != 0 {
		_nodeBlobReset(tls, pRtree)
		rc = Xsqlite3_exec(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zSql, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	return rc
}

// C documentation
//
//	/*
//	** The xSavepoint method.
//	**
//	** This module does not need to do anything to support savepoints. However,
//	** it uses this hook to close any open blob handle. This is done because a
//	** DROP TABLE command - which fortunately always opens a savepoint - cannot
//	** succeed if there are any open blob handles. i.e. if the blob handle were
//	** not closed here, the following would fail:
//	**
//	**   BEGIN;
//	**     INSERT INTO rtree...
//	**     DROP TABLE <tablename>;    -- Would fail with SQLITE_LOCKED
//	**   COMMIT;
//	*/
func _rtreeSavepoint(tls *libc.TLS, pVtab uintptr, iSavepoint int32) (r int32) {
	var iwt Tu8
	var pRtree uintptr
	_, _ = iwt, pRtree
	pRtree = pVtab
	iwt = (*TRtree)(unsafe.Pointer(pRtree)).FinWrTrans
	_ = iSavepoint
	(*TRtree)(unsafe.Pointer(pRtree)).FinWrTrans = uint8(0)
	_nodeBlobReset(tls, pRtree)
	(*TRtree)(unsafe.Pointer(pRtree)).FinWrTrans = iwt
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function populates the pRtree->nRowEst variable with an estimate
//	** of the number of rows in the virtual table. If possible, this is based
//	** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
//	*/
func _rtreeQueryStat1(tls *libc.TLS, db uintptr, pRtree uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nRow Ti64
	var rc, v1 int32
	var zFmt, zSql uintptr
	var v2 int64
	var _ /* p at bp+0 */ uintptr
	_, _, _, _, _, _ = nRow, rc, zFmt, zSql, v1, v2
	zFmt = __ccgo_ts + 27555
	nRow = int64(RTREE_MIN_ROWEST)
	rc = Xsqlite3_table_column_metadata(tls, db, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, __ccgo_ts+13016, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
	if rc != SQLITE_OK {
		(*TRtree)(unsafe.Pointer(pRtree)).FnRowEst = int64(RTREE_DEFAULT_ROWEST)
		if rc == int32(SQLITE_ERROR) {
			v1 = SQLITE_OK
		} else {
			v1 = rc
		}
		return v1
	}
	zSql = Xsqlite3_mprintf(tls, zFmt, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
		if rc == SQLITE_OK {
			if Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) == int32(SQLITE_ROW) {
				nRow = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			}
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		Xsqlite3_free(tls, zSql)
	}
	if nRow > int64(libc.Int32FromInt32(RTREE_MIN_ROWEST)) {
		v2 = nRow
	} else {
		v2 = int64(libc.Int32FromInt32(RTREE_MIN_ROWEST))
	}
	(*TRtree)(unsafe.Pointer(pRtree)).FnRowEst = v2
	return rc
}

// C documentation
//
//	/*
//	** Return true if zName is the extension on one of the shadow tables used
//	** by this module.
//	*/
func _rtreeShadowName(tls *libc.TLS, zName uintptr) (r int32) {
	var i uint32
	_ = i
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(12)/libc.Uint32FromInt64(4)) {
			break
		}
		if Xsqlite3_stricmp(tls, zName, _azName1[i]) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

var _azName1 = [3]uintptr{
	0: __ccgo_ts + 27611,
	1: __ccgo_ts + 6857,
	2: __ccgo_ts + 18096,
}

var _rtreeModule = Tsqlite3_module{
	FiVersion: int32(4),
}

func init() {
	p := unsafe.Pointer(&_rtreeModule)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_rtreeCreate)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_rtreeConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_rtreeBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rtreeDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rtreeDestroy)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rtreeOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rtreeClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rtreeFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rtreeNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rtreeEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rtreeColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rtreeRowid)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_rtreeUpdate)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rtreeBeginTransaction)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_rtreeRollback)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_rtreeRename)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_rtreeSavepoint)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_rtreeShadowName)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_rtreeIntegrity)
}

func _rtreeSqlInit(tls *libc.TLS, pRtree uintptr, db uintptr, zDb uintptr, zPrefix uintptr, isCreate int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var appStmt [8]uintptr
	var f, i, ii, ii1, rc int32
	var p, p1, zCreate, zFormat, zSql, zSql1 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = appStmt, f, i, ii, ii1, p, p1, rc, zCreate, zFormat, zSql, zSql1
	rc = SQLITE_OK
	f = libc.Int32FromInt32(SQLITE_PREPARE_PERSISTENT) | libc.Int32FromInt32(SQLITE_PREPARE_NO_VTAB)
	(*TRtree)(unsafe.Pointer(pRtree)).Fdb = db
	if isCreate != 0 {
		p = Xsqlite3_str_new(tls, db)
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28025, libc.VaList(bp+8, zDb, zPrefix))
		ii = 0
		for {
			if !(ii < int32((*TRtree)(unsafe.Pointer(pRtree)).FnAux)) {
				break
			}
			Xsqlite3_str_appendf(tls, p, __ccgo_ts+28087, libc.VaList(bp+8, ii))
			goto _1
		_1:
			;
			ii++
		}
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28092, libc.VaList(bp+8, zDb, zPrefix))
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28156, libc.VaList(bp+8, zDb, zPrefix))
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28226, libc.VaList(bp+8, zDb, zPrefix, (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize))
		zCreate = Xsqlite3_str_finish(tls, p)
		if !(zCreate != 0) {
			return int32(SQLITE_NOMEM)
		}
		rc = Xsqlite3_exec(tls, db, zCreate, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zCreate)
		if rc != SQLITE_OK {
			return rc
		}
	}
	appStmt[0] = pRtree + 76
	appStmt[int32(1)] = pRtree + 80
	appStmt[int32(2)] = pRtree + 84
	appStmt[int32(3)] = pRtree + 88
	appStmt[int32(4)] = pRtree + 92
	appStmt[int32(5)] = pRtree + 96
	appStmt[int32(6)] = pRtree + 100
	appStmt[int32(7)] = pRtree + 104
	rc = _rtreeQueryStat1(tls, db, pRtree)
	i = 0
	for {
		if !(i < int32(N_STATEMENT) && rc == SQLITE_OK) {
			break
		}
		if i != int32(3) || int32((*TRtree)(unsafe.Pointer(pRtree)).FnAux) == 0 {
			zFormat = _azSql[i]
		} else {
			/* An UPSERT is very slightly slower than REPLACE, but it is needed
			 ** if there are auxiliary columns */
			zFormat = __ccgo_ts + 28275
		}
		zSql = Xsqlite3_mprintf(tls, zFormat, libc.VaList(bp+8, zDb, zPrefix))
		if zSql != 0 {
			rc = Xsqlite3_prepare_v3(tls, db, zSql, -int32(1), uint32(uint32(f)), appStmt[i], uintptr(0))
		} else {
			rc = int32(SQLITE_NOMEM)
		}
		Xsqlite3_free(tls, zSql)
		goto _2
	_2:
		;
		i++
	}
	if (*TRtree)(unsafe.Pointer(pRtree)).FnAux != 0 && rc != int32(SQLITE_NOMEM) {
		(*TRtree)(unsafe.Pointer(pRtree)).FzReadAuxSql = Xsqlite3_mprintf(tls, __ccgo_ts+28383, libc.VaList(bp+8, zDb, zPrefix))
		if (*TRtree)(unsafe.Pointer(pRtree)).FzReadAuxSql == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			p1 = Xsqlite3_str_new(tls, db)
			Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28428, libc.VaList(bp+8, zDb, zPrefix))
			ii1 = 0
			for {
				if !(ii1 < int32((*TRtree)(unsafe.Pointer(pRtree)).FnAux)) {
					break
				}
				if ii1 != 0 {
					Xsqlite3_str_append(tls, p1, __ccgo_ts+14524, int32(1))
				}
				if ii1 < int32((*TRtree)(unsafe.Pointer(pRtree)).FnAuxNotNull) {
					Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28455, libc.VaList(bp+8, ii1, ii1+int32(2), ii1))
				} else {
					Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28477, libc.VaList(bp+8, ii1, ii1+int32(2)))
				}
				goto _3
			_3:
				;
				ii1++
			}
			Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28485, 0)
			zSql1 = Xsqlite3_str_finish(tls, p1)
			if zSql1 == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				rc = Xsqlite3_prepare_v3(tls, db, zSql1, -int32(1), uint32(uint32(f)), pRtree+108, uintptr(0))
				Xsqlite3_free(tls, zSql1)
			}
		}
	}
	return rc
}

var _azSql = [8]uintptr{
	0: __ccgo_ts + 27616,
	1: __ccgo_ts + 27669,
	2: __ccgo_ts + 27714,
	3: __ccgo_ts + 27766,
	4: __ccgo_ts + 27820,
	5: __ccgo_ts + 27865,
	6: __ccgo_ts + 27923,
	7: __ccgo_ts + 27978,
}

// C documentation
//
//	/*
//	** The second argument to this function contains the text of an SQL statement
//	** that returns a single integer value. The statement is compiled and executed
//	** using database connection db. If successful, the integer value returned
//	** is written to *piVal and SQLITE_OK returned. Otherwise, an SQLite error
//	** code is returned and the value of *piVal after returning is not defined.
//	*/
func _getIntFromStmt(tls *libc.TLS, db uintptr, zSql uintptr, piVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pStmt at bp+0 */ uintptr
	_ = rc
	rc = int32(SQLITE_NOMEM)
	if zSql != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
		if rc == SQLITE_OK {
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				*(*int32)(unsafe.Pointer(piVal)) = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			}
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called from within the xConnect() or xCreate() method to
//	** determine the node-size used by the rtree table being created or connected
//	** to. If successful, pRtree->iNodeSize is populated and SQLITE_OK returned.
//	** Otherwise, an SQLite error code is returned.
//	**
//	** If this function is being called as part of an xConnect(), then the rtree
//	** table already exists. In this case the node-size is determined by inspecting
//	** the root node of the tree.
//	**
//	** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
//	** This ensures that each node is stored on a single database page. If the
//	** database page-size is so large that more than RTREE_MAXCELLS entries
//	** would fit in a single node, use a smaller node-size.
//	*/
func _getNodeSize(tls *libc.TLS, db uintptr, pRtree uintptr, isCreate int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	var _ /* iPageSize at bp+0 */ int32
	_, _ = rc, zSql
	if isCreate != 0 {
		*(*int32)(unsafe.Pointer(bp)) = 0
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+28501, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb))
		rc = _getIntFromStmt(tls, db, zSql, bp)
		if rc == SQLITE_OK {
			(*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize = *(*int32)(unsafe.Pointer(bp)) - int32(64)
			if int32(4)+int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32(RTREE_MAXCELLS) < (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize {
				(*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize = int32(4) + int32((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32(RTREE_MAXCELLS)
			}
		} else {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+16, Xsqlite3_errmsg(tls, db)))
		}
	} else {
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+28521, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
		rc = _getIntFromStmt(tls, db, zSql, pRtree+16)
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+16, Xsqlite3_errmsg(tls, db)))
		} else {
			if (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize < libc.Int32FromInt32(512)-libc.Int32FromInt32(64) {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+28578, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
			}
		}
	}
	Xsqlite3_free(tls, zSql)
	return rc
}

// C documentation
//
//	/*
//	** Return the length of a token
//	*/
func _rtreeTokenLength(tls *libc.TLS, z uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* dummy at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = 0
	return _sqlite3GetToken(tls, z, bp)
}

// C documentation
//
//	/*
//	** This function is the implementation of both the xConnect and xCreate
//	** methods of the r-tree virtual table.
//	**
//	**   argv[0]   -> module name
//	**   argv[1]   -> database name
//	**   argv[2]   -> table name
//	**   argv[...] -> column names...
//	*/
func _rtreeInit(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aErrMsg [5]uintptr
	var eCoordType, iErr, ii, nDb, nName, rc, v1, v3 int32
	var pRtree, pSql, zArg, zSql uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = aErrMsg, eCoordType, iErr, ii, nDb, nName, pRtree, pSql, rc, zArg, zSql, v1, v3
	rc = SQLITE_OK
	if pAux != 0 {
		v1 = int32(RTREE_COORD_INT32)
	} else {
		v1 = RTREE_COORD_REAL32
	} /* Length of string argv[2] */
	eCoordType = v1
	ii = int32(4)
	aErrMsg = [5]uintptr{
		1: __ccgo_ts + 28613,
		2: __ccgo_ts + 28656,
		3: __ccgo_ts + 28691,
		4: __ccgo_ts + 28727,
	}
	/* Aux columns counted by a u8 */
	if argc < int32(6) || argc > libc.Int32FromInt32(RTREE_MAX_AUX_COLUMN)+libc.Int32FromInt32(3) {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, aErrMsg[int32(2)+libc.BoolInt32(argc >= int32(6))]))
		return int32(SQLITE_ERROR)
	}
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_CONSTRAINT_SUPPORT), libc.VaList(bp+8, int32(1)))
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
	/* Allocate the sqlite3_vtab structure */
	nDb = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))))
	nName = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))))
	pRtree = Xsqlite3_malloc64(tls, uint64(uint32(504)+uint32(uint32(nDb))+uint32(nName*int32(2))+uint32(8)))
	if !(pRtree != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pRtree, 0, uint32(504)+uint32(uint32(nDb))+uint32(nName*int32(2))+uint32(8))
	(*TRtree)(unsafe.Pointer(pRtree)).FnBusy = uint32(1)
	(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FpModule = uintptr(unsafe.Pointer(&_rtreeModule))
	(*TRtree)(unsafe.Pointer(pRtree)).FzDb = pRtree + 1*504
	(*TRtree)(unsafe.Pointer(pRtree)).FzName = (*TRtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+int32(1))
	(*TRtree)(unsafe.Pointer(pRtree)).FzNodeName = (*TRtree)(unsafe.Pointer(pRtree)).FzName + uintptr(nName+int32(1))
	(*TRtree)(unsafe.Pointer(pRtree)).FeCoordType = uint8(uint8(eCoordType))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, *(*uintptr)(unsafe.Pointer(argv + 1*4)), uint32(uint32(nDb)))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzName, *(*uintptr)(unsafe.Pointer(argv + 2*4)), uint32(uint32(nName)))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, *(*uintptr)(unsafe.Pointer(argv + 2*4)), uint32(uint32(nName)))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName+uintptr(nName), __ccgo_ts+28764, uint32(6))
	/* Create/Connect to the underlying relational database schema. If
	 ** that is successful, call sqlite3_declare_vtab() to configure
	 ** the r-tree table schema.
	 */
	pSql = Xsqlite3_str_new(tls, db)
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+28770, libc.VaList(bp+8, _rtreeTokenLength(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4))), *(*uintptr)(unsafe.Pointer(argv + 3*4))))
	ii = int32(4)
	for {
		if !(ii < argc) {
			break
		}
		zArg = *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*4))
		if int32(*(*int8)(unsafe.Pointer(zArg))) == int32('+') {
			(*TRtree)(unsafe.Pointer(pRtree)).FnAux++
			Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+28794, libc.VaList(bp+8, _rtreeTokenLength(tls, zArg+uintptr(1)), zArg+uintptr(1)))
		} else {
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FnAux) > 0 {
				break
			} else {
				(*TRtree)(unsafe.Pointer(pRtree)).FnDim2++
				Xsqlite3_str_appendf(tls, pSql, _azFormat[eCoordType], libc.VaList(bp+8, _rtreeTokenLength(tls, zArg), zArg))
			}
		}
		goto _2
	_2:
		;
		ii++
	}
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+28821, 0)
	zSql = Xsqlite3_str_finish(tls, pSql)
	if !(zSql != 0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		if ii < argc {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, aErrMsg[int32(4)]))
			rc = int32(SQLITE_ERROR)
		} else {
			v3 = Xsqlite3_declare_vtab(tls, db, zSql)
			rc = v3
			if SQLITE_OK != v3 {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
			}
		}
	}
	Xsqlite3_free(tls, zSql)
	if rc != 0 {
		goto rtreeInit_fail
	}
	(*TRtree)(unsafe.Pointer(pRtree)).FnDim = uint8(int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) / int32(2))
	if int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim) < int32(1) {
		iErr = int32(2)
	} else {
		if int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) > libc.Int32FromInt32(RTREE_MAX_DIMENSIONS)*libc.Int32FromInt32(2) {
			iErr = int32(3)
		} else {
			if int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)%int32(2) != 0 {
				iErr = int32(1)
			} else {
				iErr = 0
			}
		}
	}
	if iErr != 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, aErrMsg[iErr]))
		goto rtreeInit_fail
	}
	(*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell = uint8(int32(8) + int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)*int32(4))
	/* Figure out the node size to use. */
	rc = _getNodeSize(tls, db, pRtree, isCreate, pzErr)
	if rc != 0 {
		goto rtreeInit_fail
	}
	rc = _rtreeSqlInit(tls, pRtree, db, *(*uintptr)(unsafe.Pointer(argv + 1*4)), *(*uintptr)(unsafe.Pointer(argv + 2*4)), isCreate)
	if rc != 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		goto rtreeInit_fail
	}
	*(*uintptr)(unsafe.Pointer(ppVtab)) = pRtree
	return SQLITE_OK
	goto rtreeInit_fail
rtreeInit_fail:
	;
	if rc == SQLITE_OK {
		rc = int32(SQLITE_ERROR)
	}
	_rtreeRelease(tls, pRtree)
	return rc
}

var _azFormat = [2]uintptr{
	0: __ccgo_ts + 28800,
	1: __ccgo_ts + 28811,
}

// C documentation
//
//	/*
//	** Implementation of a scalar function that decodes r-tree nodes to
//	** human readable strings. This can be used for debugging and analysis.
//	**
//	** The scalar function takes two arguments: (1) the number of dimensions
//	** to the rtree (between 1 and 5, inclusive) and (2) a blob of data containing
//	** an r-tree node.  For a two-dimensional r-tree structure called "rt", to
//	** deserialize all nodes, a statement like:
//	**
//	**   SELECT rtreenode(2, data) FROM rt_node;
//	**
//	** The human readable string takes the form of a Tcl list with one
//	** entry for each cell in the r-tree node. Each entry is itself a
//	** list, containing the 8-byte rowid/pageno followed by the
//	** <num-dimension>*2 coordinates.
//	*/
func _rtreenode(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	bp := tls.Alloc(608)
	defer tls.Free(608)
	var errCode, ii, jj, nData int32
	var pOut uintptr
	var _ /* cell at bp+536 */ TRtreeCell
	var _ /* node at bp+0 */ TRtreeNode
	var _ /* tree at bp+32 */ TRtree
	_, _, _, _, _ = errCode, ii, jj, nData, pOut
	_ = nArg
	libc.Xmemset(tls, bp, 0, uint32(32))
	libc.Xmemset(tls, bp+32, 0, uint32(504))
	(*(*TRtree)(unsafe.Pointer(bp + 32))).FnDim = uint8(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apArg))))
	if int32((*(*TRtree)(unsafe.Pointer(bp + 32))).FnDim) < int32(1) || int32((*(*TRtree)(unsafe.Pointer(bp + 32))).FnDim) > int32(5) {
		return
	}
	(*(*TRtree)(unsafe.Pointer(bp + 32))).FnDim2 = uint8(int32((*(*TRtree)(unsafe.Pointer(bp + 32))).FnDim) * int32(2))
	(*(*TRtree)(unsafe.Pointer(bp + 32))).FnBytesPerCell = uint8(int32(8) + int32(8)*int32((*(*TRtree)(unsafe.Pointer(bp + 32))).FnDim))
	(*(*TRtreeNode)(unsafe.Pointer(bp))).FzData = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*4)))
	if (*(*TRtreeNode)(unsafe.Pointer(bp))).FzData == uintptr(0) {
		return
	}
	nData = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*4)))
	if nData < int32(4) {
		return
	}
	if nData < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(bp)).FzData+2)*int32((*(*TRtree)(unsafe.Pointer(bp + 32))).FnBytesPerCell) {
		return
	}
	pOut = Xsqlite3_str_new(tls, uintptr(0))
	ii = 0
	for {
		if !(ii < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(bp)).FzData+2)) {
			break
		}
		_nodeGetCell(tls, bp+32, bp, ii, bp+536)
		if ii > 0 {
			Xsqlite3_str_append(tls, pOut, __ccgo_ts+12636, int32(1))
		}
		Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+28824, libc.VaList(bp+592, (*(*TRtreeCell)(unsafe.Pointer(bp + 536))).FiRowid))
		jj = 0
		for {
			if !(jj < int32((*(*TRtree)(unsafe.Pointer(bp + 32))).FnDim2)) {
				break
			}
			Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+28830, libc.VaList(bp+592, float64(*(*TRtreeValue)(unsafe.Pointer(bp + 536 + 8 + uintptr(jj)*4)))))
			goto _2
		_2:
			;
			jj++
		}
		Xsqlite3_str_append(tls, pOut, __ccgo_ts+28834, int32(1))
		goto _1
	_1:
		;
		ii++
	}
	errCode = Xsqlite3_str_errcode(tls, pOut)
	Xsqlite3_result_text(tls, ctx, Xsqlite3_str_finish(tls, pOut), -int32(1), __ccgo_fp(Xsqlite3_free))
	Xsqlite3_result_error_code(tls, ctx, errCode)
}

// C documentation
//
//	/* This routine implements an SQL function that returns the "depth" parameter
//	** from the front of a blob that is an r-tree node.  For example:
//	**
//	**     SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
//	**
//	** The depth value is 0 for all nodes other than the root node, and the root
//	** node always has nodeno=1, so the example above is the primary use for this
//	** routine.  This routine is intended for testing and analysis only.
//	*/
func _rtreedepth(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	var zBlob uintptr
	_ = zBlob
	_ = nArg
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apArg))) != int32(SQLITE_BLOB) || Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apArg))) < int32(2) {
		Xsqlite3_result_error(tls, ctx, __ccgo_ts+28836, -int32(1))
	} else {
		zBlob = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(apArg)))
		if zBlob != 0 {
			Xsqlite3_result_int(tls, ctx, _readInt16(tls, zBlob))
		} else {
			Xsqlite3_result_error_nomem(tls, ctx)
		}
	}
}

// C documentation
//
//	/*
//	** Context object passed between the various routines that make up the
//	** implementation of integrity-check function rtreecheck().
//	*/
type TRtreeCheck = struct {
	Fdb            uintptr
	FzDb           uintptr
	FzTab          uintptr
	FbInt          int32
	FnDim          int32
	FpGetNode      uintptr
	FaCheckMapping [2]uintptr
	FnLeaf         int32
	FnNonLeaf      int32
	Frc            int32
	FzReport       uintptr
	FnErr          int32
}

type RtreeCheck = TRtreeCheck

type TRtreeCheck1 = struct {
	Fdb            uintptr
	FzDb           uintptr
	FzTab          uintptr
	FbInt          int32
	FnDim          int32
	FpGetNode      uintptr
	FaCheckMapping [2]uintptr
	FnLeaf         int32
	FnNonLeaf      int32
	Frc            int32
	FzReport       uintptr
	FnErr          int32
}

type RtreeCheck1 = TRtreeCheck1

// C documentation
//
//	/*
//	** Reset SQL statement pStmt. If the sqlite3_reset() call returns an error,
//	** and RtreeCheck.rc==SQLITE_OK, set RtreeCheck.rc to the error code.
//	*/
func _rtreeCheckReset(tls *libc.TLS, pCheck uintptr, pStmt uintptr) {
	var rc int32
	_ = rc
	rc = Xsqlite3_reset(tls, pStmt)
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = rc
	}
}

// C documentation
//
//	/*
//	** The second and subsequent arguments to this function are a format string
//	** and printf style arguments. This function formats the string and attempts
//	** to compile it as an SQL statement.
//	**
//	** If successful, a pointer to the new SQL statement is returned. Otherwise,
//	** NULL is returned and an error code left in RtreeCheck.rc.
//	*/
func _rtreeCheckPrepare(tls *libc.TLS, pCheck uintptr, zFmt uintptr, va uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var ap Tva_list
	var z uintptr
	var _ /* pRet at bp+0 */ uintptr
	_, _ = ap, z
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	ap = va
	z = Xsqlite3_vmprintf(tls, zFmt, ap)
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		if z == uintptr(0) {
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
		} else {
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = Xsqlite3_prepare_v2(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).Fdb, z, -int32(1), bp, uintptr(0))
		}
	}
	Xsqlite3_free(tls, z)
	_ = ap
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** The second and subsequent arguments to this function are a printf()
//	** style format string and arguments. This function formats the string and
//	** appends it to the report being accumuated in pCheck.
//	*/
func _rtreeCheckAppendMsg(tls *libc.TLS, pCheck uintptr, zFmt uintptr, va uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap Tva_list
	var z, v1 uintptr
	_, _, _ = ap, z, v1
	ap = va
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr < int32(RTREE_CHECK_MAX_ERROR) {
		z = Xsqlite3_vmprintf(tls, zFmt, ap)
		if z == uintptr(0) {
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
		} else {
			if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport != 0 {
				v1 = __ccgo_ts + 5576
			} else {
				v1 = __ccgo_ts + 1672
			}
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport = Xsqlite3_mprintf(tls, __ccgo_ts+28869, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport, v1, z))
			if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport == uintptr(0) {
				(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
			}
		}
		(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr++
	}
	_ = ap
}

// C documentation
//
//	/*
//	** This function is a no-op if there is already an error code stored
//	** in the RtreeCheck object indicated by the first argument. NULL is
//	** returned in this case.
//	**
//	** Otherwise, the contents of rtree table node iNode are loaded from
//	** the database and copied into a buffer obtained from sqlite3_malloc().
//	** If no error occurs, a pointer to the buffer is returned and (*pnNode)
//	** is set to the size of the buffer in bytes.
//	**
//	** Or, if an error does occur, NULL is returned and an error code left
//	** in the RtreeCheck object. The final value of *pnNode is undefined in
//	** this case.
//	*/
func _rtreeCheckGetNode(tls *libc.TLS, pCheck uintptr, iNode Ti64, pnNode uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nNode int32
	var pNode, pRet uintptr
	_, _, _ = nNode, pNode, pRet
	pRet = uintptr(0) /* Return value */
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode == uintptr(0) {
		(*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode = _rtreeCheckPrepare(tls, pCheck, __ccgo_ts+28876, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
	}
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		Xsqlite3_bind_int64(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, int32(1), iNode)
		if Xsqlite3_step(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode) == int32(SQLITE_ROW) {
			nNode = Xsqlite3_column_bytes(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
			pNode = Xsqlite3_column_blob(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
			pRet = Xsqlite3_malloc64(tls, uint64(uint64(nNode)))
			if pRet == uintptr(0) {
				(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemcpy(tls, pRet, pNode, uint32(uint32(nNode)))
				*(*int32)(unsafe.Pointer(pnNode)) = nNode
			}
		}
		_rtreeCheckReset(tls, pCheck, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode)
		if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && pRet == uintptr(0) {
			_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+28921, libc.VaList(bp+8, iNode))
		}
	}
	return pRet
}

// C documentation
//
//	/*
//	** This function is used to check that the %_parent (if bLeaf==0) or %_rowid
//	** (if bLeaf==1) table contains a specified entry. The schemas of the
//	** two tables are:
//	**
//	**   CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
//	**   CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER, ...)
//	**
//	** In both cases, this function checks that there exists an entry with
//	** IPK value iKey and the second column set to iVal.
//	**
//	*/
func _rtreeCheckMapping(tls *libc.TLS, pCheck uintptr, bLeaf int32, iKey Ti64, iVal Ti64) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var azSql [2]uintptr
	var ii Ti64
	var pStmt, v1, v2 uintptr
	var rc int32
	_, _, _, _, _, _ = azSql, ii, pStmt, rc, v1, v2
	azSql = [2]uintptr{
		0: __ccgo_ts + 28953,
		1: __ccgo_ts + 29007,
	}
	if *(*uintptr)(unsafe.Pointer(pCheck + 24 + uintptr(bLeaf)*4)) == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pCheck + 24 + uintptr(bLeaf)*4)) = _rtreeCheckPrepare(tls, pCheck, azSql[bLeaf], libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
	}
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc != SQLITE_OK {
		return
	}
	pStmt = *(*uintptr)(unsafe.Pointer(pCheck + 24 + uintptr(bLeaf)*4))
	Xsqlite3_bind_int64(tls, pStmt, int32(1), iKey)
	rc = Xsqlite3_step(tls, pStmt)
	if rc == int32(SQLITE_DONE) {
		if bLeaf != 0 {
			v1 = __ccgo_ts + 29055
		} else {
			v1 = __ccgo_ts + 29063
		}
		_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29072, libc.VaList(bp+8, iKey, iVal, v1))
	} else {
		if rc == int32(SQLITE_ROW) {
			ii = Xsqlite3_column_int64(tls, pStmt, 0)
			if ii != iVal {
				if bLeaf != 0 {
					v2 = __ccgo_ts + 29055
				} else {
					v2 = __ccgo_ts + 29063
				}
				_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29117, libc.VaList(bp+8, iKey, ii, v2, iKey, iVal))
			}
		}
	}
	_rtreeCheckReset(tls, pCheck, pStmt)
}

// C documentation
//
//	/*
//	** Argument pCell points to an array of coordinates stored on an rtree page.
//	** This function checks that the coordinates are internally consistent (no
//	** x1>x2 conditions) and adds an error message to the RtreeCheck object
//	** if they are not.
//	**
//	** Additionally, if pParent is not NULL, then it is assumed to point to
//	** the array of coordinates on the parent page that bound the page
//	** containing pCell. In this case it is also verified that the two
//	** sets of coordinates are mutually consistent and an error message added
//	** to the RtreeCheck object if they are not.
//	*/
func _rtreeCheckCellCoord(tls *libc.TLS, pCheck uintptr, iNode Ti64, iCell int32, pCell uintptr, pParent uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, v2, v3, v4 int32
	var v5 bool
	var _ /* c1 at bp+0 */ TRtreeCoord
	var _ /* c2 at bp+4 */ TRtreeCoord
	var _ /* p1 at bp+8 */ TRtreeCoord
	var _ /* p2 at bp+12 */ TRtreeCoord
	_, _, _, _, _ = i, v2, v3, v4, v5
	i = 0
	for {
		if !(i < (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim) {
			break
		}
		_readCoord(tls, pCell+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(2)*i), bp)
		_readCoord(tls, pCell+uintptr(int32(4)*(int32(2)*i+int32(1))), bp+4)
		/* printf("%e, %e\n", c1.u.f, c2.u.f); */
		if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
			v2 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp)) > *(*int32)(unsafe.Pointer(bp + 4)))
		} else {
			v2 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp)) > *(*TRtreeValue)(unsafe.Pointer(bp + 4)))
		}
		if v2 != 0 {
			_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29175, libc.VaList(bp+24, i, iCell, iNode))
		}
		if pParent != 0 {
			_readCoord(tls, pParent+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(2)*i), bp+8)
			_readCoord(tls, pParent+uintptr(int32(4)*(int32(2)*i+int32(1))), bp+12)
			if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
				v3 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp)) < *(*int32)(unsafe.Pointer(bp + 8)))
			} else {
				v3 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp)) < *(*TRtreeValue)(unsafe.Pointer(bp + 8)))
			}
			if v5 = v3 != 0; !v5 {
				if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
					v4 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp + 4)) > *(*int32)(unsafe.Pointer(bp + 12)))
				} else {
					v4 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp + 4)) > *(*TRtreeValue)(unsafe.Pointer(bp + 12)))
				}
			}
			if v5 || v4 != 0 {
				_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29223, libc.VaList(bp+24, i, iCell, iNode))
			}
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Run rtreecheck() checks on node iNode, which is at depth iDepth within
//	** the r-tree structure. Argument aParent points to the array of coordinates
//	** that bound node iNode on the parent node.
//	**
//	** If any problems are discovered, an error message is appended to the
//	** report accumulated in the RtreeCheck object.
//	*/
func _rtreeCheckNode(tls *libc.TLS, pCheck uintptr, iDepth int32, aParent uintptr, iNode Ti64) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aNode, pCell uintptr
	var i, nCell int32
	var iVal Ti64
	var _ /* nNode at bp+0 */ int32
	_, _, _, _, _ = aNode, i, iVal, nCell, pCell
	aNode = uintptr(0)
	*(*int32)(unsafe.Pointer(bp)) = 0
	aNode = _rtreeCheckGetNode(tls, pCheck, iNode, bp)
	if aNode != 0 {
		if *(*int32)(unsafe.Pointer(bp)) < int32(4) {
			_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29290, libc.VaList(bp+16, iNode, *(*int32)(unsafe.Pointer(bp))))
		} else { /* Used to iterate through cells */
			if aParent == uintptr(0) {
				iDepth = _readInt16(tls, aNode)
				if iDepth > int32(RTREE_MAX_DEPTH) {
					_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29324, libc.VaList(bp+16, iDepth))
					Xsqlite3_free(tls, aNode)
					return
				}
			}
			nCell = _readInt16(tls, aNode+2)
			if int32(4)+nCell*(int32(8)+(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim*int32(2)*int32(4)) > *(*int32)(unsafe.Pointer(bp)) {
				_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29354, libc.VaList(bp+16, iNode, nCell, *(*int32)(unsafe.Pointer(bp))))
			} else {
				i = 0
				for {
					if !(i < nCell) {
						break
					}
					pCell = aNode + uintptr(int32(4)+i*(int32(8)+(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim*int32(2)*int32(4)))
					iVal = _readInt64(tls, pCell)
					_rtreeCheckCellCoord(tls, pCheck, iNode, i, pCell+8, aParent)
					if iDepth > 0 {
						_rtreeCheckMapping(tls, pCheck, 0, iVal, iNode)
						_rtreeCheckNode(tls, pCheck, iDepth-int32(1), pCell+8, iVal)
						(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnNonLeaf++
					} else {
						_rtreeCheckMapping(tls, pCheck, int32(1), iVal, iNode)
						(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnLeaf++
					}
					goto _1
				_1:
					;
					i++
				}
			}
		}
		Xsqlite3_free(tls, aNode)
	}
}

// C documentation
//
//	/*
//	** The second argument to this function must be either "_rowid" or
//	** "_parent". This function checks that the number of entries in the
//	** %_rowid or %_parent table is exactly nExpect. If not, it adds
//	** an error message to the report in the RtreeCheck object indicated
//	** by the first argument.
//	*/
func _rtreeCheckCount(tls *libc.TLS, pCheck uintptr, zTbl uintptr, nExpect Ti64) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nActual Ti64
	var pCount uintptr
	_, _ = nActual, pCount
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		pCount = _rtreeCheckPrepare(tls, pCheck, __ccgo_ts+29409, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab, zTbl))
		if pCount != 0 {
			if Xsqlite3_step(tls, pCount) == int32(SQLITE_ROW) {
				nActual = Xsqlite3_column_int64(tls, pCount, 0)
				if nActual != nExpect {
					_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29440, libc.VaList(bp+8, zTbl, nExpect, nActual))
				}
			}
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = Xsqlite3_finalize(tls, pCount)
		}
	}
}

// C documentation
//
//	/*
//	** This function does the bulk of the work for the rtree integrity-check.
//	** It is called by rtreecheck(), which is the SQL function implementation.
//	*/
func _rtreeCheckTable(tls *libc.TLS, db uintptr, zDb uintptr, zTab uintptr, pzReport uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var nAux, rc int32
	var pStmt uintptr
	var _ /* check at bp+0 */ TRtreeCheck
	_, _, _ = nAux, pStmt, rc /* Common context for various routines */
	pStmt = uintptr(0)        /* Used to find column count of rtree table */
	nAux = 0                  /* Number of extra columns. */
	/* Initialize the context object */
	libc.Xmemset(tls, bp, 0, uint32(52))
	(*(*TRtreeCheck)(unsafe.Pointer(bp))).Fdb = db
	(*(*TRtreeCheck)(unsafe.Pointer(bp))).FzDb = zDb
	(*(*TRtreeCheck)(unsafe.Pointer(bp))).FzTab = zTab
	/* Find the number of auxiliary columns */
	pStmt = _rtreeCheckPrepare(tls, bp, __ccgo_ts+29507, libc.VaList(bp+64, zDb, zTab))
	if pStmt != 0 {
		nAux = Xsqlite3_column_count(tls, pStmt) - int32(2)
		Xsqlite3_finalize(tls, pStmt)
	} else {
		if (*(*TRtreeCheck)(unsafe.Pointer(bp))).Frc != int32(SQLITE_NOMEM) {
			(*(*TRtreeCheck)(unsafe.Pointer(bp))).Frc = SQLITE_OK
		}
	}
	/* Find number of dimensions in the rtree table. */
	pStmt = _rtreeCheckPrepare(tls, bp, __ccgo_ts+27321, libc.VaList(bp+64, zDb, zTab))
	if pStmt != 0 {
		(*(*TRtreeCheck)(unsafe.Pointer(bp))).FnDim = (Xsqlite3_column_count(tls, pStmt) - int32(1) - nAux) / int32(2)
		if (*(*TRtreeCheck)(unsafe.Pointer(bp))).FnDim < int32(1) {
			_rtreeCheckAppendMsg(tls, bp, __ccgo_ts+29535, 0)
		} else {
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, pStmt) {
				(*(*TRtreeCheck)(unsafe.Pointer(bp))).FbInt = libc.BoolInt32(Xsqlite3_column_type(tls, pStmt, int32(1)) == int32(SQLITE_INTEGER))
			}
		}
		rc = Xsqlite3_finalize(tls, pStmt)
		if rc != int32(SQLITE_CORRUPT) {
			(*(*TRtreeCheck)(unsafe.Pointer(bp))).Frc = rc
		}
	}
	/* Do the actual integrity-check */
	if (*(*TRtreeCheck)(unsafe.Pointer(bp))).FnDim >= int32(1) {
		if (*(*TRtreeCheck)(unsafe.Pointer(bp))).Frc == SQLITE_OK {
			_rtreeCheckNode(tls, bp, 0, uintptr(0), int64(1))
		}
		_rtreeCheckCount(tls, bp, __ccgo_ts+29566, int64((*(*TRtreeCheck)(unsafe.Pointer(bp))).FnLeaf))
		_rtreeCheckCount(tls, bp, __ccgo_ts+29573, int64((*(*TRtreeCheck)(unsafe.Pointer(bp))).FnNonLeaf))
	}
	/* Finalize SQL statements used by the integrity-check */
	Xsqlite3_finalize(tls, (*(*TRtreeCheck)(unsafe.Pointer(bp))).FpGetNode)
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 24 + 1*4)))
	*(*uintptr)(unsafe.Pointer(pzReport)) = (*(*TRtreeCheck)(unsafe.Pointer(bp))).FzReport
	return (*(*TRtreeCheck)(unsafe.Pointer(bp))).Frc
}

// C documentation
//
//	/*
//	** Implementation of the xIntegrity method for Rtree.
//	*/
func _rtreeIntegrity(tls *libc.TLS, pVtab uintptr, zSchema uintptr, zName uintptr, isQuick int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pRtree uintptr
	var rc int32
	_, _ = pRtree, rc
	pRtree = pVtab
	_ = zSchema
	_ = zName
	_ = isQuick
	rc = _rtreeCheckTable(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, pzErr)
	if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(pzErr)) != 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+29581, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, *(*uintptr)(unsafe.Pointer(pzErr))))
		if *(*uintptr)(unsafe.Pointer(pzErr)) == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Usage:
//	**
//	**   rtreecheck(<rtree-table>);
//	**   rtreecheck(<database>, <rtree-table>);
//	**
//	** Invoking this SQL function runs an integrity-check on the named rtree
//	** table. The integrity-check verifies the following:
//	**
//	**   1. For each cell in the r-tree structure (%_node table), that:
//	**
//	**       a) for each dimension, (coord1 <= coord2).
//	**
//	**       b) unless the cell is on the root node, that the cell is bounded
//	**          by the parent cell on the parent node.
//	**
//	**       c) for leaf nodes, that there is an entry in the %_rowid
//	**          table corresponding to the cell's rowid value that
//	**          points to the correct node.
//	**
//	**       d) for cells on non-leaf nodes, that there is an entry in the
//	**          %_parent table mapping from the cell's child node to the
//	**          node that it resides on.
//	**
//	**   2. That there are the same number of entries in the %_rowid table
//	**      as there are leaf cells in the r-tree structure, and that there
//	**      is a leaf cell that corresponds to each entry in the %_rowid table.
//	**
//	**   3. That there are the same number of entries in the %_parent table
//	**      as there are non-leaf cells in the r-tree structure, and that
//	**      there is a non-leaf cell that corresponds to each entry in the
//	**      %_parent table.
//	*/
func _rtreecheck(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var zDb, zTab, v1 uintptr
	var _ /* zReport at bp+0 */ uintptr
	_, _, _, _ = rc, zDb, zTab, v1
	if nArg != int32(1) && nArg != int32(2) {
		Xsqlite3_result_error(tls, ctx, __ccgo_ts+29600, -int32(1))
	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		zDb = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apArg)))
		if nArg == int32(1) {
			zTab = zDb
			zDb = __ccgo_ts + 7958
		} else {
			zTab = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*4)))
		}
		rc = _rtreeCheckTable(tls, Xsqlite3_context_db_handle(tls, ctx), zDb, zTab, bp)
		if rc == SQLITE_OK {
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				v1 = *(*uintptr)(unsafe.Pointer(bp))
			} else {
				v1 = __ccgo_ts + 19874
			}
			Xsqlite3_result_text(tls, ctx, v1, -int32(1), uintptr(-libc.Int32FromInt32(1)))
		} else {
			Xsqlite3_result_error_code(tls, ctx, rc)
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
}

/* Conditionally include the geopoly code */
/************** Include geopoly.c in the middle of rtree.c *******************/
/************** Begin file geopoly.c *****************************************/
/*
** 2018-05-25
**
** 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 implements an alternative R-Tree virtual table that
** uses polygons to express the boundaries of 2-dimensional objects.
**
** This file is #include-ed onto the end of "rtree.c" so that it has
** access to all of the R-Tree internals.
 */
/* #include <stdlib.h> */

/* Enable -DGEOPOLY_ENABLE_DEBUG for debugging facilities */

/* Character class routines */
/* Use the SQLite core versions if this routine is part of the
 ** SQLite amalgamation */

// C documentation
//
//	/*
//	** Growing our own isspace() routine this way is twice as fast as
//	** the library isspace() function.
//	*/
var _geopolyIsSpace = [256]int8{
	9:  int8(1),
	10: int8(1),
	13: int8(1),
	32: int8(1),
}

/* Compiler and version */

// C documentation
//
//	/* Datatype for coordinates
//	*/
type TGeoCoord = float32

type GeoCoord = TGeoCoord

// C documentation
//
//	/*
//	** Internal representation of a polygon.
//	**
//	** The polygon consists of a sequence of vertexes.  There is a line
//	** segment between each pair of vertexes, and one final segment from
//	** the last vertex back to the first.  (This differs from the GeoJSON
//	** standard in which the final vertex is a repeat of the first.)
//	**
//	** The polygon follows the right-hand rule.  The area to the right of
//	** each segment is "outside" and the area to the left is "inside".
//	**
//	** The on-disk representation consists of a 4-byte header followed by
//	** the values.  The 4-byte header is:
//	**
//	**      encoding    (1 byte)   0=big-endian, 1=little-endian
//	**      nvertex     (3 bytes)  Number of vertexes as a big-endian integer
//	**
//	** Enough space is allocated for 4 coordinates, to work around over-zealous
//	** warnings coming from some compiler (notably, clang). In reality, the size
//	** of each GeoPoly memory allocate is adjusted as necessary so that the
//	** GeoPoly.a[] array at the end is the appropriate size.
//	*/
type TGeoPoly = struct {
	FnVertex int32
	Fhdr     [4]uint8
	Fa       [8]TGeoCoord
}

type GeoPoly = TGeoPoly

type TGeoPoly1 = struct {
	FnVertex int32
	Fhdr     [4]uint8
	Fa       [8]TGeoCoord
}

type GeoPoly1 = TGeoPoly1

/* The size of a memory allocation needed for a GeoPoly object sufficient
** to hold N coordinate pairs.
 */

/* Macros to access coordinates of a GeoPoly.
** We have to use these macros, rather than just say p->a[i] in order
** to silence (incorrect) UBSAN warnings if the array index is too large.
 */

// C documentation
//
//	/*
//	** State of a parse of a GeoJSON input.
//	*/
type TGeoParse = struct {
	Fz       uintptr
	FnVertex int32
	FnAlloc  int32
	FnErr    int32
	Fa       uintptr
}

type GeoParse = TGeoParse

type TGeoParse1 = struct {
	Fz       uintptr
	FnVertex int32
	FnAlloc  int32
	FnErr    int32
	Fa       uintptr
}

type GeoParse1 = TGeoParse1

// C documentation
//
//	/* Do a 4-byte byte swap */
func _geopolySwab32(tls *libc.TLS, a uintptr) {
	var t uint8
	_ = t
	t = *(*uint8)(unsafe.Pointer(a))
	*(*uint8)(unsafe.Pointer(a)) = *(*uint8)(unsafe.Pointer(a + 3))
	*(*uint8)(unsafe.Pointer(a + 3)) = t
	t = *(*uint8)(unsafe.Pointer(a + 1))
	*(*uint8)(unsafe.Pointer(a + 1)) = *(*uint8)(unsafe.Pointer(a + 2))
	*(*uint8)(unsafe.Pointer(a + 2)) = t
}

// C documentation
//
//	/* Skip whitespace.  Return the next non-whitespace character. */
func _geopolySkipSpace(tls *libc.TLS, p uintptr) (r int8) {
	for _geopolyIsSpace[*(*uint8)(unsafe.Pointer((*TGeoParse)(unsafe.Pointer(p)).Fz))] != 0 {
		(*TGeoParse)(unsafe.Pointer(p)).Fz++
	}
	return int8(*(*uint8)(unsafe.Pointer((*TGeoParse)(unsafe.Pointer(p)).Fz)))
}

// C documentation
//
//	/* Parse out a number.  Write the value into *pVal if pVal!=0.
//	** return non-zero on success and zero if the next token is not a number.
//	*/
func _geopolyParseNumber(tls *libc.TLS, p uintptr, pVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c int8
	var j, seenDP, seenE, v2 int32
	var z uintptr
	var _ /* r at bp+0 */ float64
	_, _, _, _, _, _ = c, j, seenDP, seenE, z, v2
	c = _geopolySkipSpace(tls, p)
	z = (*TGeoParse)(unsafe.Pointer(p)).Fz
	j = 0
	seenDP = 0
	seenE = 0
	if int32(int32(c)) == int32('-') {
		j = int32(1)
		c = int8(*(*uint8)(unsafe.Pointer(z + uintptr(j))))
	}
	if int32(int32(c)) == int32('0') && int32(*(*uint8)(unsafe.Pointer(z + uintptr(j+int32(1))))) >= int32('0') && int32(*(*uint8)(unsafe.Pointer(z + uintptr(j+int32(1))))) <= int32('9') {
		return 0
	}
	for {
		c = int8(*(*uint8)(unsafe.Pointer(z + uintptr(j))))
		if int32(_sqlite3CtypeMap[uint8(c)])&int32(0x04) != 0 {
			goto _1
		}
		if int32(int32(c)) == int32('.') {
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-int32(1))))) == int32('-') {
				return 0
			}
			if seenDP != 0 {
				return 0
			}
			seenDP = int32(1)
			goto _1
		}
		if int32(int32(c)) == int32('e') || int32(int32(c)) == int32('E') {
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-int32(1))))) < int32('0') {
				return 0
			}
			if seenE != 0 {
				return -int32(1)
			}
			v2 = libc.Int32FromInt32(1)
			seenE = v2
			seenDP = v2
			c = int8(*(*uint8)(unsafe.Pointer(z + uintptr(j+int32(1)))))
			if int32(int32(c)) == int32('+') || int32(int32(c)) == int32('-') {
				j++
				c = int8(*(*uint8)(unsafe.Pointer(z + uintptr(j+int32(1)))))
			}
			if int32(int32(c)) < int32('0') || int32(int32(c)) > int32('9') {
				return 0
			}
			goto _1
		}
		break
		goto _1
	_1:
		;
		j++
	}
	if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-int32(1))))) < int32('0') {
		return 0
	}
	if pVal != 0 {
		_sqlite3AtoF(tls, (*TGeoParse)(unsafe.Pointer(p)).Fz, bp, j, uint8(SQLITE_UTF8))
		*(*TGeoCoord)(unsafe.Pointer(pVal)) = float32(*(*float64)(unsafe.Pointer(bp)))
	}
	*(*uintptr)(unsafe.Pointer(p)) += uintptr(j)
	return int32(1)
}

// C documentation
//
//	/*
//	** If the input is a well-formed JSON array of coordinates with at least
//	** four coordinates and where each coordinate is itself a two-value array,
//	** then convert the JSON into a GeoPoly object and return a pointer to
//	** that object.
//	**
//	** If any error occurs, return NULL.
//	*/
func _geopolyParseJson(tls *libc.TLS, z uintptr, pRc uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aNew, pOut, v1 uintptr
	var c int8
	var ii, rc int32
	var v2 bool
	var _ /* s at bp+0 */ TGeoParse
	var _ /* x at bp+20 */ int32
	_, _, _, _, _, _, _ = aNew, c, ii, pOut, rc, v1, v2
	rc = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint32(20))
	(*(*TGeoParse)(unsafe.Pointer(bp))).Fz = z
	if int32(_geopolySkipSpace(tls, bp)) == int32('[') {
		(*(*TGeoParse)(unsafe.Pointer(bp))).Fz++
		for int32(_geopolySkipSpace(tls, bp)) == int32('[') {
			ii = 0
			(*(*TGeoParse)(unsafe.Pointer(bp))).Fz++
			if (*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex >= (*(*TGeoParse)(unsafe.Pointer(bp))).FnAlloc {
				(*(*TGeoParse)(unsafe.Pointer(bp))).FnAlloc = (*(*TGeoParse)(unsafe.Pointer(bp))).FnAlloc*int32(2) + int32(16)
				aNew = Xsqlite3_realloc64(tls, (*(*TGeoParse)(unsafe.Pointer(bp))).Fa, uint64(uint32((*(*TGeoParse)(unsafe.Pointer(bp))).FnAlloc)*uint32(4)*uint32(2)))
				if aNew == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
					(*(*TGeoParse)(unsafe.Pointer(bp))).FnErr++
					break
				}
				(*(*TGeoParse)(unsafe.Pointer(bp))).Fa = aNew
			}
			for {
				if ii <= int32(1) {
					v1 = (*(*TGeoParse)(unsafe.Pointer(bp))).Fa + uintptr((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex*int32(2)+ii)*4
				} else {
					v1 = uintptr(0)
				}
				if !(_geopolyParseNumber(tls, bp, v1) != 0) {
					break
				}
				ii++
				if ii == int32(2) {
					(*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex++
				}
				c = _geopolySkipSpace(tls, bp)
				(*(*TGeoParse)(unsafe.Pointer(bp))).Fz++
				if int32(int32(c)) == int32(',') {
					continue
				}
				if int32(int32(c)) == int32(']') && ii >= int32(2) {
					break
				}
				(*(*TGeoParse)(unsafe.Pointer(bp))).FnErr++
				rc = int32(SQLITE_ERROR)
				goto parse_json_err
			}
			if int32(_geopolySkipSpace(tls, bp)) == int32(',') {
				(*(*TGeoParse)(unsafe.Pointer(bp))).Fz++
				continue
			}
			break
		}
		if v2 = int32(_geopolySkipSpace(tls, bp)) == int32(']') && (*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex >= int32(4) && *(*TGeoCoord)(unsafe.Pointer((*(*TGeoParse)(unsafe.Pointer(bp))).Fa)) == *(*TGeoCoord)(unsafe.Pointer((*(*TGeoParse)(unsafe.Pointer(bp))).Fa + uintptr((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex*int32(2)-int32(2))*4)) && *(*TGeoCoord)(unsafe.Pointer((*(*TGeoParse)(unsafe.Pointer(bp))).Fa + 1*4)) == *(*TGeoCoord)(unsafe.Pointer((*(*TGeoParse)(unsafe.Pointer(bp))).Fa + uintptr((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex*int32(2)-int32(1))*4)); v2 {
			(*(*TGeoParse)(unsafe.Pointer(bp))).Fz++
		}
		if v2 && int32(_geopolySkipSpace(tls, bp)) == libc.Int32FromInt32(0) {
			*(*int32)(unsafe.Pointer(bp + 20)) = int32(1)
			(*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex-- /* Remove the redundant vertex at the end */
			pOut = Xsqlite3_malloc64(tls, uint64(libc.Int64FromInt64(40)+int64(libc.Uint32FromInt64(4)*libc.Uint32FromInt32(2))*(int64((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex)-libc.Int64FromInt32(4))))
			*(*int32)(unsafe.Pointer(bp + 20)) = int32(1)
			if pOut == uintptr(0) {
				goto parse_json_err
			}
			(*TGeoPoly)(unsafe.Pointer(pOut)).FnVertex = (*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex
			libc.Xmemcpy(tls, pOut+8, (*(*TGeoParse)(unsafe.Pointer(bp))).Fa, uint32((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex*int32(2))*uint32(4))
			*(*uint8)(unsafe.Pointer(pOut + 4)) = *(*uint8)(unsafe.Pointer(bp + 20))
			*(*uint8)(unsafe.Pointer(pOut + 4 + 1)) = uint8((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex >> int32(16) & int32(0xff))
			*(*uint8)(unsafe.Pointer(pOut + 4 + 2)) = uint8((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex >> int32(8) & int32(0xff))
			*(*uint8)(unsafe.Pointer(pOut + 4 + 3)) = uint8((*(*TGeoParse)(unsafe.Pointer(bp))).FnVertex & int32(0xff))
			Xsqlite3_free(tls, (*(*TGeoParse)(unsafe.Pointer(bp))).Fa)
			if pRc != 0 {
				*(*int32)(unsafe.Pointer(pRc)) = SQLITE_OK
			}
			return pOut
		} else {
			(*(*TGeoParse)(unsafe.Pointer(bp))).FnErr++
			rc = int32(SQLITE_ERROR)
		}
	}
	goto parse_json_err
parse_json_err:
	;
	if pRc != 0 {
		*(*int32)(unsafe.Pointer(pRc)) = rc
	}
	Xsqlite3_free(tls, (*(*TGeoParse)(unsafe.Pointer(bp))).Fa)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Given a function parameter, try to interpret it as a polygon, either
//	** in the binary format or JSON text.  Compute a GeoPoly object and
//	** return a pointer to that object.  Or if the input is not a well-formed
//	** polygon, put an error message in sqlite3_context and return NULL.
//	*/
func _geopolyFuncParam(tls *libc.TLS, pCtx uintptr, pVal uintptr, pRc uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, p, zJson, p4 uintptr
	var ii, nByte, nVertex, v1 int32
	var v2 bool
	var _ /* x at bp+0 */ int32
	_, _, _, _, _, _, _, _, _ = a, ii, nByte, nVertex, p, zJson, v1, v2, p4
	p = uintptr(0)
	if v2 = Xsqlite3_value_type(tls, pVal) == int32(SQLITE_BLOB); v2 {
		v1 = Xsqlite3_value_bytes(tls, pVal)
		nByte = v1
	}
	if v2 && v1 >= int32(libc.Uint32FromInt32(4)+libc.Uint32FromInt32(6)*libc.Uint32FromInt64(4)) {
		a = Xsqlite3_value_blob(tls, pVal)
		if a == uintptr(0) {
			if pCtx != 0 {
				Xsqlite3_result_error_nomem(tls, pCtx)
			}
			return uintptr(0)
		}
		nVertex = int32(*(*uint8)(unsafe.Pointer(a + 1)))<<int32(16) + int32(*(*uint8)(unsafe.Pointer(a + 2)))<<int32(8) + int32(*(*uint8)(unsafe.Pointer(a + 3)))
		if (int32(*(*uint8)(unsafe.Pointer(a))) == 0 || int32(*(*uint8)(unsafe.Pointer(a))) == int32(1)) && uint32(nVertex*int32(2))*uint32(4)+uint32(4) == uint32(uint32(nByte)) {
			p = Xsqlite3_malloc64(tls, uint64(uint32(40)+uint32((nVertex-int32(1))*int32(2))*uint32(4)))
			if p == uintptr(0) {
				if pRc != 0 {
					*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
				}
				if pCtx != 0 {
					Xsqlite3_result_error_nomem(tls, pCtx)
				}
			} else {
				*(*int32)(unsafe.Pointer(bp)) = int32(1)
				(*TGeoPoly)(unsafe.Pointer(p)).FnVertex = nVertex
				libc.Xmemcpy(tls, p+4, a, uint32(uint32(nByte)))
				if int32(*(*uint8)(unsafe.Pointer(a))) != int32(*(*uint8)(unsafe.Pointer(bp))) {
					ii = 0
					for {
						if !(ii < nVertex) {
							break
						}
						_geopolySwab32(tls, p+8+uintptr(ii*int32(2))*4)
						_geopolySwab32(tls, p+8+uintptr(ii*int32(2)+int32(1))*4)
						goto _3
					_3:
						;
						ii++
					}
					p4 = p + 4
					*(*uint8)(unsafe.Pointer(p4)) = uint8(int32(*(*uint8)(unsafe.Pointer(p4))) ^ libc.Int32FromInt32(1))
				}
			}
		}
		if pRc != 0 {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_OK
		}
		return p
	} else {
		if Xsqlite3_value_type(tls, pVal) == int32(SQLITE_TEXT) {
			zJson = Xsqlite3_value_text(tls, pVal)
			if zJson == uintptr(0) {
				if pRc != 0 {
					*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
				}
				return uintptr(0)
			}
			return _geopolyParseJson(tls, zJson, pRc)
		} else {
			if pRc != 0 {
				*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_ERROR)
			}
			return uintptr(0)
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Implementation of the geopoly_blob(X) function.
//	**
//	** If the input is a well-formed Geopoly BLOB or JSON string
//	** then return the BLOB representation of the polygon.  Otherwise
//	** return NULL.
//	*/
func _geopolyBlobFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = p
	p = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** SQL function:     geopoly_json(X)
//	**
//	** Interpret X as a polygon and render it as a JSON array
//	** of coordinates.  Or, if X is not a valid polygon, return NULL.
//	*/
func _geopolyJsonFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, x uintptr
	var i int32
	_, _, _, _ = db, i, p, x
	p = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		db = Xsqlite3_context_db_handle(tls, context)
		x = Xsqlite3_str_new(tls, db)
		Xsqlite3_str_append(tls, x, __ccgo_ts+26557, int32(1))
		i = 0
		for {
			if !(i < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
				break
			}
			Xsqlite3_str_appendf(tls, x, __ccgo_ts+29651, libc.VaList(bp+8, float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*int32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*int32(2)+int32(1))*4)))))
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_str_appendf(tls, x, __ccgo_ts+29662, libc.VaList(bp+8, float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)))))
		Xsqlite3_result_text(tls, context, Xsqlite3_str_finish(tls, x), -int32(1), __ccgo_fp(Xsqlite3_free))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** SQL function:     geopoly_svg(X, ....)
//	**
//	** Interpret X as a polygon and render it as a SVG <polyline>.
//	** Additional arguments are added as attributes to the <polyline>.
//	*/
func _geopolySvgFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var cSep int8
	var db, p, x, z uintptr
	var i int32
	_, _, _, _, _, _ = cSep, db, i, p, x, z
	if argc < int32(1) {
		return
	}
	p = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	if p != 0 {
		db = Xsqlite3_context_db_handle(tls, context)
		x = Xsqlite3_str_new(tls, db)
		cSep = int8('\'')
		Xsqlite3_str_appendf(tls, x, __ccgo_ts+29673, 0)
		i = 0
		for {
			if !(i < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
				break
			}
			Xsqlite3_str_appendf(tls, x, __ccgo_ts+29691, libc.VaList(bp+8, int32(int32(cSep)), float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*int32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*int32(2)+int32(1))*4)))))
			cSep = int8(' ')
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_str_appendf(tls, x, __ccgo_ts+29699, libc.VaList(bp+8, float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)))))
		i = int32(1)
		for {
			if !(i < argc) {
				break
			}
			z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*4)))
			if z != 0 && *(*int8)(unsafe.Pointer(z)) != 0 {
				Xsqlite3_str_appendf(tls, x, __ccgo_ts+29707, libc.VaList(bp+8, z))
			}
			goto _2
		_2:
			;
			i++
		}
		Xsqlite3_str_appendf(tls, x, __ccgo_ts+29711, 0)
		Xsqlite3_result_text(tls, context, Xsqlite3_str_finish(tls, x), -int32(1), __ccgo_fp(Xsqlite3_free))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** SQL Function:      geopoly_xform(poly, A, B, C, D, E, F)
//	**
//	** Transform and/or translate a polygon as follows:
//	**
//	**      x1 = A*x0 + B*y0 + E
//	**      y1 = C*x0 + D*y0 + F
//	**
//	** For a translation:
//	**
//	**      geopoly_xform(poly, 1, 0, 0, 1, x-offset, y-offset)
//	**
//	** Rotate by R around the point (0,0):
//	**
//	**      geopoly_xform(poly, cos(R), sin(R), -sin(R), cos(R), 0, 0)
//	*/
func _geopolyXformFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var A, B, C, D, E, F float64
	var ii int32
	var p uintptr
	var x0, x1, y0, y1 TGeoCoord
	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, ii, p, x0, x1, y0, y1
	p = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	A = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	B = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4)))
	C = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4)))
	D = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 4*4)))
	E = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 5*4)))
	F = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 6*4)))
	_ = argc
	if p != 0 {
		ii = 0
		for {
			if !(ii < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
				break
			}
			x0 = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2))*4))
			y0 = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2)+int32(1))*4))
			x1 = float32(A*float64(float64(x0)) + B*float64(float64(y0)) + E)
			y1 = float32(C*float64(float64(x0)) + D*float64(float64(y0)) + F)
			*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2))*4)) = x1
			*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2)+int32(1))*4)) = y1
			goto _1
		_1:
			;
			ii++
		}
		Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Compute the area enclosed by the polygon.
//	**
//	** This routine can also be used to detect polygons that rotate in
//	** the wrong direction.  Polygons are suppose to be counter-clockwise (CCW).
//	** This routine returns a negative value for clockwise (CW) polygons.
//	*/
func _geopolyArea(tls *libc.TLS, p uintptr) (r float64) {
	var ii int32
	var rArea float64
	_, _ = ii, rArea
	rArea = float64(0)
	ii = 0
	for {
		if !(ii < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex-int32(1)) {
			break
		}
		rArea += float64((*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2))*4))-*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr((ii+int32(1))*int32(2))*4)))*(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2)+int32(1))*4))+*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr((ii+int32(1))*int32(2)+int32(1))*4)))) * float64(0.5)
		goto _1
	_1:
		;
		ii++
	}
	rArea += float64((*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2))*4))-*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4)))*(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2)+int32(1))*4))+*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)))) * float64(0.5)
	return rArea
}

// C documentation
//
//	/*
//	** Implementation of the geopoly_area(X) function.
//	**
//	** If the input is a well-formed Geopoly BLOB then return the area
//	** enclosed by the polygon.  If the polygon circulates clockwise instead
//	** of counterclockwise (as it should) then return the negative of the
//	** enclosed area.  Otherwise return NULL.
//	*/
func _geopolyAreaFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = p
	p = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		Xsqlite3_result_double(tls, context, _geopolyArea(tls, p))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Implementation of the geopoly_ccw(X) function.
//	**
//	** If the rotation of polygon X is clockwise (incorrect) instead of
//	** counter-clockwise (the correct winding order according to RFC7946)
//	** then reverse the order of the vertexes in polygon X.
//	**
//	** In other words, this routine returns a CCW polygon regardless of the
//	** winding order of its input.
//	**
//	** Use this routine to sanitize historical inputs that that sometimes
//	** contain polygons that wind in the wrong direction.
//	*/
func _geopolyCcwFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var ii, jj int32
	var p uintptr
	var t TGeoCoord
	_, _, _, _ = ii, jj, p, t
	p = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		if _geopolyArea(tls, p) < float64(0) {
			ii = int32(1)
			jj = (*TGeoPoly)(unsafe.Pointer(p)).FnVertex - libc.Int32FromInt32(1)
			for {
				if !(ii < jj) {
					break
				}
				t = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2))*4))
				*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2))*4)) = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*int32(2))*4))
				*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*int32(2))*4)) = t
				t = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2)+int32(1))*4))
				*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*int32(2)+int32(1))*4)) = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*int32(2)+int32(1))*4))
				*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*int32(2)+int32(1))*4)) = t
				goto _1
			_1:
				;
				ii++
				jj--
			}
		}
		Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/* Fast approximation for sine(X) for X between -0.5*pi and 2*pi
//	*/
func _geopolySine(tls *libc.TLS, r float64) (r1 float64) {
	var r2, r3, r5 float64
	_, _, _ = r2, r3, r5
	if r >= libc.Float64FromFloat64(1.5)*libc.Float64FromFloat64(3.141592653589793) {
		r -= libc.Float64FromFloat64(2) * libc.Float64FromFloat64(3.141592653589793)
	}
	if r >= libc.Float64FromFloat64(0.5)*libc.Float64FromFloat64(3.141592653589793) {
		return -_geopolySine(tls, r-float64(3.141592653589793))
	} else {
		r2 = r * r
		r3 = r2 * r
		r5 = r3 * r2
		return float64(0.9996949)*r - float64(0.16567)*r3 + float64(0.0075134)*r5
	}
	return r1
}

// C documentation
//
//	/*
//	** Function:   geopoly_regular(X,Y,R,N)
//	**
//	** Construct a simple, convex, regular polygon centered at X, Y
//	** with circumradius R and with N sides.
//	*/
func _geopolyRegularFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var n int32
	var p uintptr
	var r, rAngle, x, y float64
	var _ /* i at bp+0 */ int32
	_, _, _, _, _, _ = n, p, r, rAngle, x, y
	x = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	y = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	r = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4)))
	n = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 3*4)))
	_ = argc
	if n < int32(3) || r <= float64(0) {
		return
	}
	if n > int32(1000) {
		n = int32(1000)
	}
	p = Xsqlite3_malloc64(tls, uint64(uint32(40)+uint32((n-int32(1))*int32(2))*uint32(4)))
	if p == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
		return
	}
	*(*int32)(unsafe.Pointer(bp)) = int32(1)
	*(*uint8)(unsafe.Pointer(p + 4)) = *(*uint8)(unsafe.Pointer(bp))
	*(*uint8)(unsafe.Pointer(p + 4 + 1)) = uint8(0)
	*(*uint8)(unsafe.Pointer(p + 4 + 2)) = uint8(n >> int32(8) & int32(0xff))
	*(*uint8)(unsafe.Pointer(p + 4 + 3)) = uint8(n & int32(0xff))
	*(*int32)(unsafe.Pointer(bp)) = 0
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) < n) {
			break
		}
		rAngle = libc.Float64FromFloat64(2) * libc.Float64FromFloat64(3.141592653589793) * float64(*(*int32)(unsafe.Pointer(bp))) / float64(float64(n))
		*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*int32(2))*4)) = float32(x - r*_geopolySine(tls, rAngle-libc.Float64FromFloat64(0.5)*libc.Float64FromFloat64(3.141592653589793)))
		*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*int32(2)+int32(1))*4)) = float32(y + r*_geopolySine(tls, rAngle))
		goto _1
	_1:
		;
		*(*int32)(unsafe.Pointer(bp))++
	}
	Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*n, uintptr(-libc.Int32FromInt32(1)))
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** If pPoly is a polygon, compute its bounding box. Then:
//	**
//	**    (1) if aCoord!=0 store the bounding box in aCoord, returning NULL
//	**    (2) otherwise, compute a GeoPoly for the bounding box and return the
//	**        new GeoPoly
//	**
//	** If pPoly is NULL but aCoord is not NULL, then compute a new GeoPoly from
//	** the bounding box in aCoord and return a pointer to that GeoPoly.
//	*/
func _geopolyBBox(tls *libc.TLS, context uintptr, pPoly uintptr, aCoord uintptr, pRc uintptr) (r1 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var mnX, mnY, mxX, mxY, v3, v4 float32
	var p, pOut uintptr
	var r float64
	var _ /* ii at bp+0 */ int32
	_, _, _, _, _, _, _, _, _ = mnX, mnY, mxX, mxY, p, pOut, r, v3, v4
	pOut = uintptr(0)
	if pPoly == uintptr(0) && aCoord != uintptr(0) {
		p = uintptr(0)
		mnX = *(*TRtreeValue)(unsafe.Pointer(aCoord))
		mxX = *(*TRtreeValue)(unsafe.Pointer(aCoord + 1*4))
		mnY = *(*TRtreeValue)(unsafe.Pointer(aCoord + 2*4))
		mxY = *(*TRtreeValue)(unsafe.Pointer(aCoord + 3*4))
		goto geopolyBboxFill
	} else {
		p = _geopolyFuncParam(tls, context, pPoly, pRc)
	}
	if !(p != 0) {
		goto _1
	}
	v3 = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))
	mxX = v3
	mnX = v3
	v4 = *(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4))
	mxY = v4
	mnY = v4
	*(*int32)(unsafe.Pointer(bp)) = int32(1)
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
			break
		}
		r = float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*int32(2))*4)))
		if r < float64(float64(mnX)) {
			mnX = float32(float32(r))
		} else {
			if r > float64(float64(mxX)) {
				mxX = float32(float32(r))
			}
		}
		r = float64(*(*TGeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*int32(2)+int32(1))*4)))
		if r < float64(float64(mnY)) {
			mnY = float32(float32(r))
		} else {
			if r > float64(float64(mxY)) {
				mxY = float32(float32(r))
			}
		}
		goto _5
	_5:
		;
		*(*int32)(unsafe.Pointer(bp))++
	}
	if pRc != 0 {
		*(*int32)(unsafe.Pointer(pRc)) = SQLITE_OK
	}
	if !(aCoord == uintptr(0)) {
		goto _6
	}
	goto geopolyBboxFill
geopolyBboxFill:
	;
	pOut = Xsqlite3_realloc64(tls, p, uint64(libc.Uint32FromInt64(40)+libc.Uint32FromInt64(4)*libc.Uint32FromInt32(2)*uint32(libc.Int32FromInt32(4)-libc.Int32FromInt32(4))))
	if pOut == uintptr(0) {
		Xsqlite3_free(tls, p)
		if context != 0 {
			Xsqlite3_result_error_nomem(tls, context)
		}
		if pRc != 0 {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		}
		return uintptr(0)
	}
	(*TGeoPoly)(unsafe.Pointer(pOut)).FnVertex = int32(4)
	*(*int32)(unsafe.Pointer(bp)) = int32(1)
	*(*uint8)(unsafe.Pointer(pOut + 4)) = *(*uint8)(unsafe.Pointer(bp))
	*(*uint8)(unsafe.Pointer(pOut + 4 + 1)) = uint8(0)
	*(*uint8)(unsafe.Pointer(pOut + 4 + 2)) = uint8(0)
	*(*uint8)(unsafe.Pointer(pOut + 4 + 3)) = uint8(4)
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4)) = mnX
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mnY
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(2))*4)) = mxX
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mnY
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))*4)) = mxX
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mxY
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(2))*4)) = mnX
	*(*TGeoCoord)(unsafe.Pointer(pOut + 8 + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mxY
	goto _7
_6:
	;
	Xsqlite3_free(tls, p)
	*(*TRtreeValue)(unsafe.Pointer(aCoord)) = mnX
	*(*TRtreeValue)(unsafe.Pointer(aCoord + 1*4)) = mxX
	*(*TRtreeValue)(unsafe.Pointer(aCoord + 2*4)) = mnY
	*(*TRtreeValue)(unsafe.Pointer(aCoord + 3*4)) = mxY
_7:
	;
	goto _2
_1:
	;
	if aCoord != 0 {
		libc.Xmemset(tls, aCoord, 0, libc.Uint32FromInt64(4)*libc.Uint32FromInt32(4))
	}
_2:
	;
	return pOut
}

// C documentation
//
//	/*
//	** Implementation of the geopoly_bbox(X) SQL function.
//	*/
func _geopolyBBoxFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = p
	p = _geopolyBBox(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0), uintptr(0))
	_ = argc
	if p != 0 {
		Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** State vector for the geopoly_group_bbox() aggregate function.
//	*/
type TGeoBBox = struct {
	FisInit int32
	Fa      [4]TRtreeCoord
}

type GeoBBox = TGeoBBox

type TGeoBBox1 = struct {
	FisInit int32
	Fa      [4]TRtreeCoord
}

type GeoBBox1 = TGeoBBox1

// C documentation
//
//	/*
//	** Implementation of the geopoly_group_bbox(X) aggregate SQL function.
//	*/
func _geopolyBBoxStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pBBox uintptr
	var _ /* a at bp+0 */ [4]TRtreeCoord
	var _ /* rc at bp+16 */ int32
	_ = pBBox
	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	_ = argc
	_geopolyBBox(tls, context, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+16)
	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		pBBox = Xsqlite3_aggregate_context(tls, context, int32(20))
		if pBBox == uintptr(0) {
			return
		}
		if libc.AtomicLoadPInt32(pBBox) == 0 {
			libc.AtomicStorePInt32(pBBox, int32(1))
			libc.Xmemcpy(tls, pBBox+4, bp, libc.Uint32FromInt64(4)*libc.Uint32FromInt32(4))
		} else {
			if *(*TRtreeValue)(unsafe.Pointer(bp)) < *(*TRtreeValue)(unsafe.Pointer(pBBox + 4)) {
				*(*TRtreeCoord)(unsafe.Pointer(pBBox + 4)) = (*(*[4]TRtreeCoord)(unsafe.Pointer(bp)))[0]
			}
			if *(*TRtreeValue)(unsafe.Pointer(bp + 1*4)) > *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 1*4)) {
				*(*TRtreeCoord)(unsafe.Pointer(pBBox + 4 + 1*4)) = (*(*[4]TRtreeCoord)(unsafe.Pointer(bp)))[int32(1)]
			}
			if *(*TRtreeValue)(unsafe.Pointer(bp + 2*4)) < *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 2*4)) {
				*(*TRtreeCoord)(unsafe.Pointer(pBBox + 4 + 2*4)) = (*(*[4]TRtreeCoord)(unsafe.Pointer(bp)))[int32(2)]
			}
			if *(*TRtreeValue)(unsafe.Pointer(bp + 3*4)) > *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 3*4)) {
				*(*TRtreeCoord)(unsafe.Pointer(pBBox + 4 + 3*4)) = (*(*[4]TRtreeCoord)(unsafe.Pointer(bp)))[int32(3)]
			}
		}
	}
}

func _geopolyBBoxFinal(tls *libc.TLS, context uintptr) {
	var p, pBBox uintptr
	_, _ = p, pBBox
	pBBox = Xsqlite3_aggregate_context(tls, context, 0)
	if pBBox == uintptr(0) {
		return
	}
	p = _geopolyBBox(tls, context, uintptr(0), pBBox+4, uintptr(0))
	if p != 0 {
		Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Determine if point (x0,y0) is beneath line segment (x1,y1)->(x2,y2).
//	** Returns:
//	**
//	**    +2  x0,y0 is on the line segement
//	**
//	**    +1  x0,y0 is beneath line segment
//	**
//	**    0   x0,y0 is not on or beneath the line segment or the line segment
//	**        is vertical and x0,y0 is not on the line segment
//	**
//	** The left-most coordinate min(x1,x2) is not considered to be part of
//	** the line segment for the purposes of this analysis.
//	*/
func _pointBeneathLine(tls *libc.TLS, x0 float64, y0 float64, x1 float64, y1 float64, x2 float64, y2 float64) (r int32) {
	var y float64
	_ = y
	if x0 == x1 && y0 == y1 {
		return int32(2)
	}
	if x1 < x2 {
		if x0 <= x1 || x0 > x2 {
			return 0
		}
	} else {
		if x1 > x2 {
			if x0 <= x2 || x0 > x1 {
				return 0
			}
		} else {
			/* Vertical line segment */
			if x0 != x1 {
				return 0
			}
			if y0 < y1 && y0 < y2 {
				return 0
			}
			if y0 > y1 && y0 > y2 {
				return 0
			}
			return int32(2)
		}
	}
	y = y1 + (y2-y1)*(x0-x1)/(x2-x1)
	if y0 == y {
		return int32(2)
	}
	if y0 < y {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** SQL function:    geopoly_contains_point(P,X,Y)
//	**
//	** Return +2 if point X,Y is within polygon P.
//	** Return +1 if point X,Y is on the polygon boundary.
//	** Return 0 if point X,Y is outside the polygon
//	*/
func _geopolyContainsPointFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var cnt, ii, v int32
	var p1 uintptr
	var x0, y0 float64
	_, _, _, _, _, _ = cnt, ii, p1, v, x0, y0
	p1 = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	x0 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	y0 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4)))
	v = 0
	cnt = 0
	_ = argc
	if p1 == uintptr(0) {
		return
	}
	ii = 0
	for {
		if !(ii < (*TGeoPoly)(unsafe.Pointer(p1)).FnVertex-int32(1)) {
			break
		}
		v = _pointBeneathLine(tls, x0, y0, float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*int32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*int32(2)+int32(1))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr((ii+int32(1))*int32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr((ii+int32(1))*int32(2)+int32(1))*4))))
		if v == int32(2) {
			break
		}
		cnt += v
		goto _1
	_1:
		;
		ii++
	}
	if v != int32(2) {
		v = _pointBeneathLine(tls, x0, y0, float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*int32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*int32(2)+int32(1))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))), float64(*(*TGeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4))))
	}
	if v == int32(2) {
		Xsqlite3_result_int(tls, context, int32(1))
	} else {
		if (v+cnt)&int32(1) == 0 {
			Xsqlite3_result_int(tls, context, 0)
		} else {
			Xsqlite3_result_int(tls, context, int32(2))
		}
	}
	Xsqlite3_free(tls, p1)
}

// C documentation
//
//	/*
//	** SQL function:    geopoly_within(P1,P2)
//	**
//	** Return +2 if P1 and P2 are the same polygon
//	** Return +1 if P2 is contained within P1
//	** Return 0 if any part of P2 is on the outside of P1
//	**
//	*/
func _geopolyWithinFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p1, p2 uintptr
	var x, v1, v2 int32
	_, _, _, _, _ = p1, p2, x, v1, v2
	p1 = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	p2 = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv + 1*4)), uintptr(0))
	_ = argc
	if p1 != 0 && p2 != 0 {
		x = _geopolyOverlap(tls, p1, p2)
		if x < 0 {
			Xsqlite3_result_error_nomem(tls, context)
		} else {
			if x == int32(2) {
				v1 = int32(1)
			} else {
				if x == int32(4) {
					v2 = int32(2)
				} else {
					v2 = 0
				}
				v1 = v2
			}
			Xsqlite3_result_int(tls, context, v1)
		}
	}
	Xsqlite3_free(tls, p1)
	Xsqlite3_free(tls, p2)
}

// C documentation
//
//	/* Objects used by the overlap algorihm. */
type TGeoEvent = struct {
	F__ccgo_align [0]uint32
	Fx            float64
	FeType        int32
	FpSeg         uintptr
	FpNext        uintptr
	F__ccgo_pad4  [4]byte
}

type GeoEvent = TGeoEvent

type TGeoSegment = struct {
	F__ccgo_align [0]uint32
	FC            float64
	FB            float64
	Fy            float64
	Fy0           float32
	Fside         uint8
	Fidx          uint32
	FpNext        uintptr
}

type GeoSegment = TGeoSegment

type TGeoOverlap = struct {
	FaEvent   uintptr
	FaSegment uintptr
	FnEvent   int32
	FnSegment int32
}

type GeoOverlap = TGeoOverlap

type TGeoEvent1 = struct {
	F__ccgo_align [0]uint32
	Fx            float64
	FeType        int32
	FpSeg         uintptr
	FpNext        uintptr
	F__ccgo_pad4  [4]byte
}

type GeoEvent1 = TGeoEvent1

type TGeoSegment1 = struct {
	F__ccgo_align [0]uint32
	FC            float64
	FB            float64
	Fy            float64
	Fy0           float32
	Fside         uint8
	Fidx          uint32
	FpNext        uintptr
}

type GeoSegment1 = TGeoSegment1

type TGeoOverlap1 = struct {
	FaEvent   uintptr
	FaSegment uintptr
	FnEvent   int32
	FnSegment int32
}

type GeoOverlap1 = TGeoOverlap1

// C documentation
//
//	/*
//	** Add a single segment and its associated events.
//	*/
func _geopolyAddOneSegment(tls *libc.TLS, p uintptr, x0 TGeoCoord, y0 TGeoCoord, x1 TGeoCoord, y1 TGeoCoord, side uint8, idx uint32) {
	var pEvent, pSeg uintptr
	var t TGeoCoord
	_, _, _ = pEvent, pSeg, t
	if x0 == x1 {
		return
	} /* Ignore vertical segments */
	if x0 > x1 {
		t = x0
		x0 = x1
		x1 = t
		t = y0
		y0 = y1
		y1 = t
	}
	pSeg = (*TGeoOverlap)(unsafe.Pointer(p)).FaSegment + uintptr((*TGeoOverlap)(unsafe.Pointer(p)).FnSegment)*40
	(*TGeoOverlap)(unsafe.Pointer(p)).FnSegment++
	(*TGeoSegment)(unsafe.Pointer(pSeg)).FC = float64((y1 - y0) / (x1 - x0))
	(*TGeoSegment)(unsafe.Pointer(pSeg)).FB = float64(float64(y1)) - float64(float64(x1))*(*TGeoSegment)(unsafe.Pointer(pSeg)).FC
	(*TGeoSegment)(unsafe.Pointer(pSeg)).Fy0 = y0
	(*TGeoSegment)(unsafe.Pointer(pSeg)).Fside = side
	(*TGeoSegment)(unsafe.Pointer(pSeg)).Fidx = idx
	pEvent = (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr((*TGeoOverlap)(unsafe.Pointer(p)).FnEvent)*24
	(*TGeoOverlap)(unsafe.Pointer(p)).FnEvent++
	(*TGeoEvent)(unsafe.Pointer(pEvent)).Fx = float64(float64(x0))
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FeType = 0
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FpSeg = pSeg
	pEvent = (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr((*TGeoOverlap)(unsafe.Pointer(p)).FnEvent)*24
	(*TGeoOverlap)(unsafe.Pointer(p)).FnEvent++
	(*TGeoEvent)(unsafe.Pointer(pEvent)).Fx = float64(float64(x1))
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FeType = int32(1)
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FpSeg = pSeg
}

// C documentation
//
//	/*
//	** Insert all segments and events for polygon pPoly.
//	*/
func _geopolyAddSegments(tls *libc.TLS, p uintptr, pPoly uintptr, side uint8) {
	var i uint32
	var x uintptr
	_, _ = i, x
	i = uint32(0)
	for {
		if !(i < uint32((*TGeoPoly)(unsafe.Pointer(pPoly)).FnVertex)-uint32(1)) {
			break
		}
		x = pPoly + 8 + uintptr(i*uint32(2))*4
		_geopolyAddOneSegment(tls, p, *(*TGeoCoord)(unsafe.Pointer(x)), *(*TGeoCoord)(unsafe.Pointer(x + 1*4)), *(*TGeoCoord)(unsafe.Pointer(x + 2*4)), *(*TGeoCoord)(unsafe.Pointer(x + 3*4)), side, i)
		goto _1
	_1:
		;
		i++
	}
	x = pPoly + 8 + uintptr(i*uint32(2))*4
	_geopolyAddOneSegment(tls, p, *(*TGeoCoord)(unsafe.Pointer(x)), *(*TGeoCoord)(unsafe.Pointer(x + 1*4)), *(*TGeoCoord)(unsafe.Pointer(pPoly + 8)), *(*TGeoCoord)(unsafe.Pointer(pPoly + 8 + 1*4)), side, i)
}

// C documentation
//
//	/*
//	** Merge two lists of sorted events by X coordinate
//	*/
func _geopolyEventMerge(tls *libc.TLS, pLeft uintptr, pRight uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pLast, v1 uintptr
	var _ /* head at bp+0 */ TGeoEvent
	_, _ = pLast, v1
	(*(*TGeoEvent)(unsafe.Pointer(bp))).FpNext = uintptr(0)
	pLast = bp
	for pRight != 0 && pLeft != 0 {
		if (*TGeoEvent)(unsafe.Pointer(pRight)).Fx <= (*TGeoEvent)(unsafe.Pointer(pLeft)).Fx {
			(*TGeoEvent)(unsafe.Pointer(pLast)).FpNext = pRight
			pLast = pRight
			pRight = (*TGeoEvent)(unsafe.Pointer(pRight)).FpNext
		} else {
			(*TGeoEvent)(unsafe.Pointer(pLast)).FpNext = pLeft
			pLast = pLeft
			pLeft = (*TGeoEvent)(unsafe.Pointer(pLeft)).FpNext
		}
	}
	if pRight != 0 {
		v1 = pRight
	} else {
		v1 = pLeft
	}
	(*TGeoEvent)(unsafe.Pointer(pLast)).FpNext = v1
	return (*(*TGeoEvent)(unsafe.Pointer(bp))).FpNext
}

// C documentation
//
//	/*
//	** Sort an array of nEvent event objects into a list.
//	*/
func _geopolySortEventsByX(tls *libc.TLS, aEvent uintptr, nEvent int32) (r uintptr) {
	var a [50]uintptr
	var i, j, mx int32
	var p uintptr
	_, _, _, _, _ = a, i, j, mx, p
	mx = 0
	i = 0
	for {
		if !(i < nEvent) {
			break
		}
		p = aEvent + uintptr(i)*24
		(*TGeoEvent)(unsafe.Pointer(p)).FpNext = uintptr(0)
		j = 0
		for {
			if !(j < mx && a[j] != 0) {
				break
			}
			p = _geopolyEventMerge(tls, a[j], p)
			a[j] = uintptr(0)
			goto _2
		_2:
			;
			j++
		}
		a[j] = p
		if j >= mx {
			mx = j + int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	p = uintptr(0)
	i = 0
	for {
		if !(i < mx) {
			break
		}
		p = _geopolyEventMerge(tls, a[i], p)
		goto _3
	_3:
		;
		i++
	}
	return p
}

// C documentation
//
//	/*
//	** Merge two lists of sorted segments by Y, and then by C.
//	*/
func _geopolySegmentMerge(tls *libc.TLS, pLeft uintptr, pRight uintptr) (r1 uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pLast, v1 uintptr
	var r float64
	var _ /* head at bp+0 */ TGeoSegment
	_, _, _ = pLast, r, v1
	(*(*TGeoSegment)(unsafe.Pointer(bp))).FpNext = uintptr(0)
	pLast = bp
	for pRight != 0 && pLeft != 0 {
		r = (*TGeoSegment)(unsafe.Pointer(pRight)).Fy - (*TGeoSegment)(unsafe.Pointer(pLeft)).Fy
		if r == float64(0) {
			r = (*TGeoSegment)(unsafe.Pointer(pRight)).FC - (*TGeoSegment)(unsafe.Pointer(pLeft)).FC
		}
		if r < float64(0) {
			(*TGeoSegment)(unsafe.Pointer(pLast)).FpNext = pRight
			pLast = pRight
			pRight = (*TGeoSegment)(unsafe.Pointer(pRight)).FpNext
		} else {
			(*TGeoSegment)(unsafe.Pointer(pLast)).FpNext = pLeft
			pLast = pLeft
			pLeft = (*TGeoSegment)(unsafe.Pointer(pLeft)).FpNext
		}
	}
	if pRight != 0 {
		v1 = pRight
	} else {
		v1 = pLeft
	}
	(*TGeoSegment)(unsafe.Pointer(pLast)).FpNext = v1
	return (*(*TGeoSegment)(unsafe.Pointer(bp))).FpNext
}

// C documentation
//
//	/*
//	** Sort a list of GeoSegments in order of increasing Y and in the event of
//	** a tie, increasing C (slope).
//	*/
func _geopolySortSegmentsByYAndC(tls *libc.TLS, pList uintptr) (r uintptr) {
	var a [50]uintptr
	var i, mx int32
	var p uintptr
	_, _, _, _ = a, i, mx, p
	mx = 0
	for pList != 0 {
		p = pList
		pList = (*TGeoSegment)(unsafe.Pointer(pList)).FpNext
		(*TGeoSegment)(unsafe.Pointer(p)).FpNext = uintptr(0)
		i = 0
		for {
			if !(i < mx && a[i] != 0) {
				break
			}
			p = _geopolySegmentMerge(tls, a[i], p)
			a[i] = uintptr(0)
			goto _1
		_1:
			;
			i++
		}
		a[i] = p
		if i >= mx {
			mx = i + int32(1)
		}
	}
	p = uintptr(0)
	i = 0
	for {
		if !(i < mx) {
			break
		}
		p = _geopolySegmentMerge(tls, a[i], p)
		goto _2
	_2:
		;
		i++
	}
	return p
}

// C documentation
//
//	/*
//	** Determine the overlap between two polygons
//	*/
func _geopolyOverlap(tls *libc.TLS, p1 uintptr, p2 uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iMask, needSort, rc, v1 int32
	var nByte, nVertex Tsqlite3_int64
	var p, pActive, pPrev, pSeg, pThisEvent, v5, v7 uintptr
	var rX, y, v2 float64
	var _ /* aOverlap at bp+0 */ [4]uint8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = iMask, nByte, nVertex, needSort, p, pActive, pPrev, pSeg, pThisEvent, rX, rc, y, v1, v2, v5, v7
	nVertex = int64((*TGeoPoly)(unsafe.Pointer(p1)).FnVertex + (*TGeoPoly)(unsafe.Pointer(p2)).FnVertex + int32(2))
	rc = 0
	needSort = 0
	pActive = uintptr(0)
	nByte = int64(24)*nVertex*int64(2) + int64(40)*nVertex + int64(16)
	p = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	if p == uintptr(0) {
		return -int32(1)
	}
	(*TGeoOverlap)(unsafe.Pointer(p)).FaEvent = p + 1*16
	(*TGeoOverlap)(unsafe.Pointer(p)).FaSegment = (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr(nVertex*int64(2))*24
	v1 = libc.Int32FromInt32(0)
	(*TGeoOverlap)(unsafe.Pointer(p)).FnSegment = v1
	(*TGeoOverlap)(unsafe.Pointer(p)).FnEvent = v1
	_geopolyAddSegments(tls, p, p1, uint8(1))
	_geopolyAddSegments(tls, p, p2, uint8(2))
	pThisEvent = _geopolySortEventsByX(tls, (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent, (*TGeoOverlap)(unsafe.Pointer(p)).FnEvent)
	if pThisEvent != 0 && (*TGeoEvent)(unsafe.Pointer(pThisEvent)).Fx == float64(0) {
		v2 = -libc.Float64FromFloat64(1)
	} else {
		v2 = float64(0)
	}
	rX = v2
	libc.Xmemset(tls, bp, 0, uint32(4))
	for pThisEvent != 0 {
		if (*TGeoEvent)(unsafe.Pointer(pThisEvent)).Fx != rX {
			pPrev = uintptr(0)
			iMask = 0
			rX = (*TGeoEvent)(unsafe.Pointer(pThisEvent)).Fx
			if needSort != 0 {
				pActive = _geopolySortSegmentsByYAndC(tls, pActive)
				needSort = 0
			}
			pSeg = pActive
			for {
				if !(pSeg != 0) {
					break
				}
				if pPrev != 0 {
					if (*TGeoSegment)(unsafe.Pointer(pPrev)).Fy != (*TGeoSegment)(unsafe.Pointer(pSeg)).Fy {
						(*(*[4]uint8)(unsafe.Pointer(bp)))[iMask] = uint8(1)
					}
				}
				iMask ^= int32((*TGeoSegment)(unsafe.Pointer(pSeg)).Fside)
				pPrev = pSeg
				goto _3
			_3:
				;
				pSeg = (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext
			}
			pPrev = uintptr(0)
			pSeg = pActive
			for {
				if !(pSeg != 0) {
					break
				}
				y = (*TGeoSegment)(unsafe.Pointer(pSeg)).FC*rX + (*TGeoSegment)(unsafe.Pointer(pSeg)).FB
				(*TGeoSegment)(unsafe.Pointer(pSeg)).Fy = y
				if pPrev != 0 {
					if (*TGeoSegment)(unsafe.Pointer(pPrev)).Fy > (*TGeoSegment)(unsafe.Pointer(pSeg)).Fy && int32((*TGeoSegment)(unsafe.Pointer(pPrev)).Fside) != int32((*TGeoSegment)(unsafe.Pointer(pSeg)).Fside) {
						rc = int32(1)
						goto geopolyOverlapDone
					} else {
						if (*TGeoSegment)(unsafe.Pointer(pPrev)).Fy != (*TGeoSegment)(unsafe.Pointer(pSeg)).Fy {
							(*(*[4]uint8)(unsafe.Pointer(bp)))[iMask] = uint8(1)
						}
					}
				}
				iMask ^= int32((*TGeoSegment)(unsafe.Pointer(pSeg)).Fside)
				pPrev = pSeg
				goto _4
			_4:
				;
				pSeg = (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext
			}
		}
		if (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FeType == 0 {
			/* Add a segment */
			pSeg = (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg
			(*TGeoSegment)(unsafe.Pointer(pSeg)).Fy = float64((*TGeoSegment)(unsafe.Pointer(pSeg)).Fy0)
			(*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext = pActive
			pActive = pSeg
			needSort = int32(1)
		} else {
			/* Remove a segment */
			if pActive == (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg {
				if pActive != 0 {
					v5 = (*TGeoSegment)(unsafe.Pointer(pActive)).FpNext
				} else {
					v5 = uintptr(0)
				}
				pActive = v5
			} else {
				pSeg = pActive
				for {
					if !(pSeg != 0) {
						break
					}
					if (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext == (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg {
						if (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext != 0 {
							v7 = (*TGeoSegment)(unsafe.Pointer((*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext)).FpNext
						} else {
							v7 = uintptr(0)
						}
						(*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext = v7
						break
					}
					goto _6
				_6:
					;
					pSeg = (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext
				}
			}
		}
		pThisEvent = (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpNext
	}
	if int32((*(*[4]uint8)(unsafe.Pointer(bp)))[int32(3)]) == 0 {
		rc = 0
	} else {
		if int32((*(*[4]uint8)(unsafe.Pointer(bp)))[int32(1)]) != 0 && int32((*(*[4]uint8)(unsafe.Pointer(bp)))[int32(2)]) == 0 {
			rc = int32(3)
		} else {
			if int32((*(*[4]uint8)(unsafe.Pointer(bp)))[int32(1)]) == 0 && int32((*(*[4]uint8)(unsafe.Pointer(bp)))[int32(2)]) != 0 {
				rc = int32(2)
			} else {
				if int32((*(*[4]uint8)(unsafe.Pointer(bp)))[int32(1)]) == 0 && int32((*(*[4]uint8)(unsafe.Pointer(bp)))[int32(2)]) == 0 {
					rc = int32(4)
				} else {
					rc = int32(1)
				}
			}
		}
	}
	goto geopolyOverlapDone
geopolyOverlapDone:
	;
	Xsqlite3_free(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** SQL function:    geopoly_overlap(P1,P2)
//	**
//	** Determine whether or not P1 and P2 overlap. Return value:
//	**
//	**   0     The two polygons are disjoint
//	**   1     They overlap
//	**   2     P1 is completely contained within P2
//	**   3     P2 is completely contained within P1
//	**   4     P1 and P2 are the same polygon
//	**   NULL  Either P1 or P2 or both are not valid polygons
//	*/
func _geopolyOverlapFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p1, p2 uintptr
	var x int32
	_, _, _ = p1, p2, x
	p1 = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	p2 = _geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv + 1*4)), uintptr(0))
	_ = argc
	if p1 != 0 && p2 != 0 {
		x = _geopolyOverlap(tls, p1, p2)
		if x < 0 {
			Xsqlite3_result_error_nomem(tls, context)
		} else {
			Xsqlite3_result_int(tls, context, x)
		}
	}
	Xsqlite3_free(tls, p1)
	Xsqlite3_free(tls, p2)
}

// C documentation
//
//	/*
//	** Enable or disable debugging output
//	*/
func _geopolyDebugFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = context
	_ = argc
	_ = argv
}

// C documentation
//
//	/*
//	** This function is the implementation of both the xConnect and xCreate
//	** methods of the geopoly virtual table.
//	**
//	**   argv[0]   -> module name
//	**   argv[1]   -> database name
//	**   argv[2]   -> table name
//	**   argv[...] -> column names...
//	*/
func _geopolyInit(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var ii, rc, v2 int32
	var nDb, nName Tsqlite3_int64
	var pRtree, pSql, zSql uintptr
	_, _, _, _, _, _, _, _ = ii, nDb, nName, pRtree, pSql, rc, zSql, v2
	rc = SQLITE_OK
	_ = pAux
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_CONSTRAINT_SUPPORT), libc.VaList(bp+8, int32(1)))
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
	/* Allocate the sqlite3_vtab structure */
	nDb = int64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))))
	nName = int64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 2*4))))
	pRtree = Xsqlite3_malloc64(tls, uint64(int64(504)+nDb+nName*int64(2)+int64(8)))
	if !(pRtree != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pRtree, 0, uint32(int64(504)+nDb+nName*int64(2)+int64(8)))
	(*TRtree)(unsafe.Pointer(pRtree)).FnBusy = uint32(1)
	(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FpModule = uintptr(unsafe.Pointer(&_rtreeModule))
	(*TRtree)(unsafe.Pointer(pRtree)).FzDb = pRtree + 1*504
	(*TRtree)(unsafe.Pointer(pRtree)).FzName = (*TRtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+int64(1))
	(*TRtree)(unsafe.Pointer(pRtree)).FzNodeName = (*TRtree)(unsafe.Pointer(pRtree)).FzName + uintptr(nName+int64(1))
	(*TRtree)(unsafe.Pointer(pRtree)).FeCoordType = uint8(RTREE_COORD_REAL32)
	(*TRtree)(unsafe.Pointer(pRtree)).FnDim = uint8(2)
	(*TRtree)(unsafe.Pointer(pRtree)).FnDim2 = uint8(4)
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, *(*uintptr)(unsafe.Pointer(argv + 1*4)), uint32(uint32(nDb)))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzName, *(*uintptr)(unsafe.Pointer(argv + 2*4)), uint32(uint32(nName)))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, *(*uintptr)(unsafe.Pointer(argv + 2*4)), uint32(uint32(nName)))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName+uintptr(nName), __ccgo_ts+28764, uint32(6))
	/* Create/Connect to the underlying relational database schema. If
	 ** that is successful, call sqlite3_declare_vtab() to configure
	 ** the r-tree table schema.
	 */
	pSql = Xsqlite3_str_new(tls, db)
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+29724, 0)
	(*TRtree)(unsafe.Pointer(pRtree)).FnAux = uint8(1)        /* Add one for _shape */
	(*TRtree)(unsafe.Pointer(pRtree)).FnAuxNotNull = uint8(1) /* The _shape column is always not-null */
	ii = int32(3)
	for {
		if !(ii < argc) {
			break
		}
		(*TRtree)(unsafe.Pointer(pRtree)).FnAux++
		Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+29746, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*4))))
		goto _1
	_1:
		;
		ii++
	}
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+28821, 0)
	zSql = Xsqlite3_str_finish(tls, pSql)
	if !(zSql != 0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		v2 = Xsqlite3_declare_vtab(tls, db, zSql)
		rc = v2
		if SQLITE_OK != v2 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		}
	}
	Xsqlite3_free(tls, zSql)
	if rc != 0 {
		goto geopolyInit_fail
	}
	(*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell = uint8(int32(8) + int32((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)*int32(4))
	/* Figure out the node size to use. */
	rc = _getNodeSize(tls, db, pRtree, isCreate, pzErr)
	if rc != 0 {
		goto geopolyInit_fail
	}
	rc = _rtreeSqlInit(tls, pRtree, db, *(*uintptr)(unsafe.Pointer(argv + 1*4)), *(*uintptr)(unsafe.Pointer(argv + 2*4)), isCreate)
	if rc != 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		goto geopolyInit_fail
	}
	*(*uintptr)(unsafe.Pointer(ppVtab)) = pRtree
	return SQLITE_OK
	goto geopolyInit_fail
geopolyInit_fail:
	;
	if rc == SQLITE_OK {
		rc = int32(SQLITE_ERROR)
	}
	_rtreeRelease(tls, pRtree)
	return rc
}

// C documentation
//
//	/*
//	** GEOPOLY virtual table module xCreate method.
//	*/
func _geopolyCreate(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _geopolyInit(tls, db, pAux, argc, argv, ppVtab, pzErr, int32(1))
}

// C documentation
//
//	/*
//	** GEOPOLY virtual table module xConnect method.
//	*/
func _geopolyConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _geopolyInit(tls, db, pAux, argc, argv, ppVtab, pzErr, 0)
}

// C documentation
//
//	/*
//	** GEOPOLY virtual table module xFilter method.
//	**
//	** Query plans:
//	**
//	**      1         rowid lookup
//	**      2         search for objects overlapping the same bounding box
//	**                that contains polygon argv[0]
//	**      3         search for objects overlapping the same bounding box
//	**                that contains polygon argv[0]
//	**      4         full table scan
//	*/
func _geopolyFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iRowid Ti64
	var p, p1, pCsr, pNew, pRtree, v1 uintptr
	var _ /* bbox at bp+24 */ [4]TRtreeCoord
	var _ /* iCell at bp+8 */ int32
	var _ /* iNode at bp+16 */ Ti64
	var _ /* pLeaf at bp+12 */ uintptr
	var _ /* pRoot at bp+0 */ uintptr
	var _ /* rc at bp+4 */ int32
	_, _, _, _, _, _, _ = iRowid, p, p1, pCsr, pNew, pRtree, v1
	pRtree = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	pCsr = pVtabCursor
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	_ = idxStr
	_rtreeReference(tls, pRtree)
	/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
	_resetCursor(tls, pCsr)
	(*TRtreeCursor)(unsafe.Pointer(pCsr)).FiStrategy = idxNum
	if idxNum == int32(1) { /* Search point for the leaf */
		iRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
		*(*Ti64)(unsafe.Pointer(bp + 16)) = 0
		*(*int32)(unsafe.Pointer(bp + 4)) = _findLeafNode(tls, pRtree, iRowid, bp+12, bp+16)
		if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 12)) != uintptr(0) {
			p = _rtreeSearchPointNew(tls, pCsr, float64(0), uint8(0))
			/* Always returns pCsr->sPoint */
			*(*uintptr)(unsafe.Pointer(pCsr + 64)) = *(*uintptr)(unsafe.Pointer(bp + 12))
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).Fid = *(*Ti64)(unsafe.Pointer(bp + 16))
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = uint8(PARTLY_WITHIN)
			*(*int32)(unsafe.Pointer(bp + 4)) = _nodeRowidIndex(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 12)), iRowid, bp+8)
			(*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell = uint8(*(*int32)(unsafe.Pointer(bp + 8)))
		} else {
			(*TRtreeCursor)(unsafe.Pointer(pCsr)).FatEOF = uint8(1)
		}
	} else {
		/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
		 ** with the configured constraints.
		 */
		*(*int32)(unsafe.Pointer(bp + 4)) = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)
		if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && idxNum <= int32(3) {
			_geopolyBBox(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(argv)), bp+24, bp+4)
			if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
				goto geopoly_filter_end
			}
			v1 = Xsqlite3_malloc(tls, int32(libc.Uint32FromInt64(24)*libc.Uint32FromInt32(4)))
			p1 = v1
			(*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = v1
			(*TRtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint = int32(4)
			if p1 == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp + 4)) = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemset(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint, 0, libc.Uint32FromInt64(24)*libc.Uint32FromInt32(4))
				libc.Xmemset(tls, pCsr+84, 0, uint32(4)*uint32((*TRtree)(unsafe.Pointer(pRtree)).FiDepth+libc.Int32FromInt32(1)))
				if idxNum == int32(2) {
					/* Overlap query */
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 0
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24 + 1*4)))
					p1 += 24
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(1)
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24)))
					p1 += 24
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(2)
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24 + 3*4)))
					p1 += 24
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(3)
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24 + 2*4)))
				} else {
					/* Within query */
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 0
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24)))
					p1 += 24
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(1)
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24 + 1*4)))
					p1 += 24
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(2)
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24 + 2*4)))
					p1 += 24
					(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
					(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(3)
					*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 24 + 3*4)))
				}
			}
		}
		if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
			pNew = _rtreeSearchPointNew(tls, pCsr, float64(0), uint8((*TRtree)(unsafe.Pointer(pRtree)).FiDepth+libc.Int32FromInt32(1)))
			if pNew == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp + 4)) = int32(SQLITE_NOMEM)
				goto geopoly_filter_end
			}
			(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).Fid = int64(1)
			(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FiCell = uint8(0)
			(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FeWithin = uint8(PARTLY_WITHIN)
			*(*uintptr)(unsafe.Pointer(pCsr + 64)) = *(*uintptr)(unsafe.Pointer(bp))
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			*(*int32)(unsafe.Pointer(bp + 4)) = _rtreeStepToLeaf(tls, pCsr)
		}
	}
	goto geopoly_filter_end
geopoly_filter_end:
	;
	_nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
	_rtreeRelease(tls, pRtree)
	return *(*int32)(unsafe.Pointer(bp + 4))
}

// C documentation
//
//	/*
//	** Rtree virtual table module xBestIndex method. There are three
//	** table scan strategies to choose from (in order from most to
//	** least desirable):
//	**
//	**   idxNum     idxStr        Strategy
//	**   ------------------------------------------------
//	**     1        "rowid"       Direct lookup by rowid.
//	**     2        "rtree"       R-tree overlap query using geopoly_overlap()
//	**     3        "rtree"       R-tree within query using geopoly_within()
//	**     4        "fullscan"    full-table scan.
//	**   ------------------------------------------------
//	*/
func _geopolyBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
	var iFuncTerm, iRowidTerm, idxNum, ii int32
	var p uintptr
	_, _, _, _, _ = iFuncTerm, iRowidTerm, idxNum, ii, p
	iRowidTerm = -int32(1)
	iFuncTerm = -int32(1)
	idxNum = 0
	_ = tab
	ii = 0
	for {
		if !(ii < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		p = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12
		if !((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0) {
			goto _1
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn < 0 && int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) {
			iRowidTerm = ii
			break
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == 0 && int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) >= int32(SQLITE_INDEX_CONSTRAINT_FUNCTION) {
			/* p->op==SQLITE_INDEX_CONSTRAINT_FUNCTION for geopoly_overlap()
			 ** p->op==(SQLITE_INDEX_CONTRAINT_FUNCTION+1) for geopoly_within().
			 ** See geopolyFindFunction() */
			iFuncTerm = ii
			idxNum = int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) - int32(SQLITE_INDEX_CONSTRAINT_FUNCTION) + int32(2)
		}
		goto _1
	_1:
		;
		ii++
	}
	if iRowidTerm >= 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(1)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 18096
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).FargvIndex = int32(1)
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).Fomit = uint8(1)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(30)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = int32(SQLITE_INDEX_SCAN_UNIQUE)
		return SQLITE_OK
	}
	if iFuncTerm >= 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = idxNum
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 29750
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8))).FargvIndex = int32(1)
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8))).Fomit = uint8(0)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(300)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
		return SQLITE_OK
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(4)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 29756
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(3e+06)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100000)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** GEOPOLY virtual table module xColumn method.
//	*/
func _geopolyColumn(tls *libc.TLS, cur uintptr, ctx uintptr, i int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p, pCsr, pNode, pRtree uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = p, pCsr, pNode, pRtree
	pRtree = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	pCsr = cur
	p = _rtreeSearchPointFirst(tls, pCsr)
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	pNode = _rtreeNodeOfFirstSearchPoint(tls, pCsr, bp)
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		return *(*int32)(unsafe.Pointer(bp))
	}
	if p == uintptr(0) {
		return SQLITE_OK
	}
	if i == 0 && Xsqlite3_vtab_nochange(tls, ctx) != 0 {
		return SQLITE_OK
	}
	if i <= int32((*TRtree)(unsafe.Pointer(pRtree)).FnAux) {
		if !((*TRtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid != 0) {
			if (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v3(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, (*TRtree)(unsafe.Pointer(pRtree)).FzReadAuxSql, -int32(1), uint32(0), pCsr+36, uintptr(0))
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					return *(*int32)(unsafe.Pointer(bp))
				}
			}
			Xsqlite3_bind_int64(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, int32(1), _nodeGetRowid(tls, pRtree, pNode, int32((*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell)))
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_step(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
			if *(*int32)(unsafe.Pointer(bp)) == int32(SQLITE_ROW) {
				(*TRtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid = uint8(1)
			} else {
				Xsqlite3_reset(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
				if *(*int32)(unsafe.Pointer(bp)) == int32(SQLITE_DONE) {
					*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
				}
				return *(*int32)(unsafe.Pointer(bp))
			}
		}
		Xsqlite3_result_value(tls, ctx, Xsqlite3_column_value(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, i+int32(2)))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The xUpdate method for GEOPOLY module virtual tables.
//	**
//	** For DELETE:
//	**
//	**     argv[0] = the rowid to be deleted
//	**
//	** For INSERT:
//	**
//	**     argv[0] = SQL NULL
//	**     argv[1] = rowid to insert, or an SQL NULL to select automatically
//	**     argv[2] = _shape column
//	**     argv[3] = first application-defined column....
//	**
//	** For UPDATE:
//	**
//	**     argv[0] = rowid to modify.  Never NULL
//	**     argv[1] = rowid after the change.  Never NULL
//	**     argv[2] = new value for _shape
//	**     argv[3] = new value for first application-defined column....
//	*/
func _geopolyUpdate(tls *libc.TLS, pVtab uintptr, nData int32, aData uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var coordChange, jj, nChange, newRowidValid, oldRowidValid, rc2, steprc int32
	var newRowid, oldRowid Ti64
	var p, pRtree, pUp, v3 uintptr
	var v1, v2 int64
	var v4 bool
	var _ /* cell at bp+8 */ TRtreeCell
	var _ /* pLeaf at bp+56 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = coordChange, jj, nChange, newRowid, newRowidValid, oldRowid, oldRowidValid, p, pRtree, pUp, rc2, steprc, v1, v2, v3, v4
	pRtree = pVtab
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK /* True if newRowid is valid */
	coordChange = 0                           /* Change in coordinates */
	if (*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef != 0 {
		/* Unable to write to the btree while another cursor is reading from it,
		 ** since the write might do a rebalance which would disrupt the read
		 ** cursor. */
		return libc.Int32FromInt32(SQLITE_LOCKED) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	_rtreeReference(tls, pRtree)
	oldRowidValid = libc.BoolInt32(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData))) != int32(SQLITE_NULL))
	if oldRowidValid != 0 {
		v1 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData)))
	} else {
		v1 = 0
	}
	oldRowid = v1
	newRowidValid = libc.BoolInt32(nData > int32(1) && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData + 1*4))) != int32(SQLITE_NULL))
	if newRowidValid != 0 {
		v2 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData + 1*4)))
	} else {
		v2 = 0
	}
	newRowid = v2
	(*(*TRtreeCell)(unsafe.Pointer(bp + 8))).FiRowid = newRowid
	if nData > int32(1) && (!(oldRowidValid != 0) || !(Xsqlite3_value_nochange(tls, *(*uintptr)(unsafe.Pointer(aData + 2*4))) != 0) || oldRowid != newRowid) {
		_geopolyBBox(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(aData + 2*4)), bp+8+8, bp)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			if *(*int32)(unsafe.Pointer(bp)) == int32(SQLITE_ERROR) {
				(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+29765, 0)
			}
			goto geopoly_update_end
		}
		coordChange = int32(1)
		/* If a rowid value was supplied, check if it is already present in
		 ** the table. If so, the constraint has failed. */
		if newRowidValid != 0 && (!(oldRowidValid != 0) || oldRowid != newRowid) {
			Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid, int32(1), (*(*TRtreeCell)(unsafe.Pointer(bp + 8))).FiRowid)
			steprc = Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
			if int32(SQLITE_ROW) == steprc {
				if Xsqlite3_vtab_on_conflict(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb) == int32(SQLITE_REPLACE) {
					*(*int32)(unsafe.Pointer(bp)) = _rtreeDeleteRowid(tls, pRtree, (*(*TRtreeCell)(unsafe.Pointer(bp + 8))).FiRowid)
				} else {
					*(*int32)(unsafe.Pointer(bp)) = _rtreeConstraintError(tls, pRtree, 0)
				}
			}
		}
	}
	/* If aData[0] is not an SQL NULL value, it is the rowid of a
	 ** record to delete from the r-tree table. The following block does
	 ** just that.
	 */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (nData == int32(1) || coordChange != 0 && oldRowidValid != 0) {
		*(*int32)(unsafe.Pointer(bp)) = _rtreeDeleteRowid(tls, pRtree, oldRowid)
	}
	/* If the aData[] array contains more than one element, elements
	 ** (aData[2]..aData[argc-1]) contain a new record to insert into
	 ** the r-tree structure.
	 */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && nData > int32(1) && coordChange != 0 {
		/* Insert the new record into the r-tree */
		*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
		if !(newRowidValid != 0) {
			*(*int32)(unsafe.Pointer(bp)) = _rtreeNewRowid(tls, pRtree, bp+8)
		}
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*(*TRtreeCell)(unsafe.Pointer(bp + 8))).FiRowid
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = _ChooseLeaf(tls, pRtree, bp+8, 0, bp+56)
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = _rtreeInsertCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 56)), bp+8, 0)
			rc2 = _nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 56)))
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp)) = rc2
			}
		}
	}
	/* Change the data */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && nData > int32(1) {
		pUp = (*TRtree)(unsafe.Pointer(pRtree)).FpWriteAux
		nChange = 0
		Xsqlite3_bind_int64(tls, pUp, int32(1), (*(*TRtreeCell)(unsafe.Pointer(bp + 8))).FiRowid)
		if Xsqlite3_value_nochange(tls, *(*uintptr)(unsafe.Pointer(aData + 2*4))) != 0 {
			Xsqlite3_bind_null(tls, pUp, int32(2))
		} else {
			p = uintptr(0)
			if v4 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData + 2*4))) == int32(SQLITE_TEXT); v4 {
				v3 = _geopolyFuncParam(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(aData + 2*4)), bp)
				p = v3
			}
			if v4 && v3 != uintptr(0) && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				Xsqlite3_bind_blob(tls, pUp, int32(2), p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
			} else {
				Xsqlite3_bind_value(tls, pUp, int32(2), *(*uintptr)(unsafe.Pointer(aData + 2*4)))
			}
			Xsqlite3_free(tls, p)
			nChange = int32(1)
		}
		jj = int32(1)
		for {
			if !(jj < nData-int32(2)) {
				break
			}
			nChange++
			Xsqlite3_bind_value(tls, pUp, jj+int32(2), *(*uintptr)(unsafe.Pointer(aData + uintptr(jj+int32(2))*4)))
			goto _5
		_5:
			;
			jj++
		}
		if nChange != 0 {
			Xsqlite3_step(tls, pUp)
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_reset(tls, pUp)
		}
	}
	goto geopoly_update_end
geopoly_update_end:
	;
	_rtreeRelease(tls, pRtree)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Report that geopoly_overlap() is an overloaded function suitable
//	** for use in xBestIndex.
//	*/
func _geopolyFindFunction(tls *libc.TLS, pVtab uintptr, nArg int32, zName uintptr, pxFunc uintptr, ppArg uintptr) (r int32) {
	_ = pVtab
	_ = nArg
	if Xsqlite3_stricmp(tls, zName, __ccgo_ts+29805) == 0 {
		*(*uintptr)(unsafe.Pointer(pxFunc)) = __ccgo_fp(_geopolyOverlapFunc)
		*(*uintptr)(unsafe.Pointer(ppArg)) = uintptr(0)
		return int32(SQLITE_INDEX_CONSTRAINT_FUNCTION)
	}
	if Xsqlite3_stricmp(tls, zName, __ccgo_ts+29821) == 0 {
		*(*uintptr)(unsafe.Pointer(pxFunc)) = __ccgo_fp(_geopolyWithinFunc)
		*(*uintptr)(unsafe.Pointer(ppArg)) = uintptr(0)
		return libc.Int32FromInt32(SQLITE_INDEX_CONSTRAINT_FUNCTION) + libc.Int32FromInt32(1)
	}
	return 0
}

var _geopolyModule = Tsqlite3_module{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_geopolyModule)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_geopolyCreate)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_geopolyConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_geopolyBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rtreeDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rtreeDestroy)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rtreeOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rtreeClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_geopolyFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rtreeNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rtreeEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_geopolyColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rtreeRowid)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_geopolyUpdate)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rtreeBeginTransaction)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_geopolyFindFunction)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_rtreeRename)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_rtreeSavepoint)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_rtreeShadowName)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_rtreeIntegrity)
}

func _sqlite3_geopoly_init(tls *libc.TLS, db uintptr) (r int32) {
	var enc, rc int32
	var i uint32
	_, _, _ = enc, i, rc
	rc = SQLITE_OK
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(144)/libc.Uint32FromInt64(12) && rc == SQLITE_OK) {
			break
		}
		if _aFunc[i].FbPure != 0 {
			enc = libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_INNOCUOUS)
		} else {
			enc = libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY)
		}
		rc = Xsqlite3_create_function(tls, db, _aFunc[i].FzName, int32(_aFunc[i].FnArg), enc, uintptr(0), _aFunc[i].FxFunc, uintptr(0), uintptr(0))
		goto _1
	_1:
		;
		i++
	}
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(12)/libc.Uint32FromInt64(12) && rc == SQLITE_OK) {
			break
		}
		rc = Xsqlite3_create_function(tls, db, _aAgg[i].FzName, int32(1), libc.Int32FromInt32(SQLITE_UTF8)|libc.Int32FromInt32(SQLITE_DETERMINISTIC)|libc.Int32FromInt32(SQLITE_INNOCUOUS), uintptr(0), uintptr(0), _aAgg[i].FxStep, _aAgg[i].FxFinal)
		goto _2
	_2:
		;
		i++
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+29998, uintptr(unsafe.Pointer(&_geopolyModule)), uintptr(0), uintptr(0))
	}
	return rc
}

var _aFunc = [12]struct {
	FxFunc uintptr
	FnArg  int8
	FbPure uint8
	FzName uintptr
}{
	0: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29836,
	},
	1: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29849,
	},
	2: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29862,
	},
	3: {
		FnArg:  int8(-int32(1)),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29875,
	},
	4: {
		FnArg:  int8(2),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29821,
	},
	5: {
		FnArg:  int8(3),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29887,
	},
	6: {
		FnArg:  int8(2),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29805,
	},
	7: {
		FnArg:  int8(1),
		FzName: __ccgo_ts + 29910,
	},
	8: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29924,
	},
	9: {
		FnArg:  int8(7),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29937,
	},
	10: {
		FnArg:  int8(4),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29951,
	},
	11: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 29967,
	},
}

func init() {
	p := unsafe.Pointer(&_aFunc)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_geopolyAreaFunc)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_geopolyBlobFunc)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_geopolyJsonFunc)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_geopolySvgFunc)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_geopolyWithinFunc)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_geopolyContainsPointFunc)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_geopolyOverlapFunc)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_geopolyDebugFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_geopolyBBoxFunc)
	*(*uintptr)(unsafe.Add(p, 108)) = __ccgo_fp(_geopolyXformFunc)
	*(*uintptr)(unsafe.Add(p, 120)) = __ccgo_fp(_geopolyRegularFunc)
	*(*uintptr)(unsafe.Add(p, 132)) = __ccgo_fp(_geopolyCcwFunc)
}

var _aAgg = [1]struct {
	FxStep  uintptr
	FxFinal uintptr
	FzName  uintptr
}{
	0: {
		FzName: __ccgo_ts + 29979,
	},
}

func init() {
	p := unsafe.Pointer(&_aAgg)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_geopolyBBoxStep)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_geopolyBBoxFinal)
}

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

// C documentation
//
//	/*
//	** Register the r-tree module with database handle db. This creates the
//	** virtual table module "rtree" and the debugging/analysis scalar
//	** function "rtreenode".
//	*/
func _sqlite3RtreeInit(tls *libc.TLS, db uintptr) (r int32) {
	var c, c1 uintptr
	var rc, utf8 int32
	_, _, _, _ = c, c1, rc, utf8
	utf8 = int32(SQLITE_UTF8)
	rc = Xsqlite3_create_function(tls, db, __ccgo_ts+30006, int32(2), utf8, uintptr(0), __ccgo_fp(_rtreenode), uintptr(0), uintptr(0))
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls, db, __ccgo_ts+30016, int32(1), utf8, uintptr(0), __ccgo_fp(_rtreedepth), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls, db, __ccgo_ts+30027, -int32(1), utf8, uintptr(0), __ccgo_fp(_rtreecheck), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		c = libc.UintptrFromInt32(RTREE_COORD_REAL32)
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+29750, uintptr(unsafe.Pointer(&_rtreeModule)), c, uintptr(0))
	}
	if rc == SQLITE_OK {
		c1 = libc.UintptrFromInt32(RTREE_COORD_INT32)
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+30038, uintptr(unsafe.Pointer(&_rtreeModule)), c1, uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = _sqlite3_geopoly_init(tls, db)
	}
	return rc
}

// C documentation
//
//	/*
//	** This routine deletes the RtreeGeomCallback object that was attached
//	** one of the SQL functions create by sqlite3_rtree_geometry_callback()
//	** or sqlite3_rtree_query_callback().  In other words, this routine is the
//	** destructor for an RtreeGeomCallback objecct.  This routine is called when
//	** the corresponding SQL function is deleted.
//	*/
func _rtreeFreeCallback(tls *libc.TLS, p uintptr) {
	var pInfo uintptr
	_ = pInfo
	pInfo = p
	if (*TRtreeGeomCallback)(unsafe.Pointer(pInfo)).FxDestructor != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TRtreeGeomCallback)(unsafe.Pointer(pInfo)).FxDestructor})))(tls, (*TRtreeGeomCallback)(unsafe.Pointer(pInfo)).FpContext)
	}
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** This routine frees the BLOB that is returned by geomCallback().
//	*/
func _rtreeMatchArgFree(tls *libc.TLS, pArg uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	p = pArg
	i = 0
	for {
		if !(i < (*TRtreeMatchArg)(unsafe.Pointer(p)).FnParam) {
			break
		}
		Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer((*TRtreeMatchArg)(unsafe.Pointer(p)).FapSqlParam + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Each call to sqlite3_rtree_geometry_callback() or
//	** sqlite3_rtree_query_callback() creates an ordinary SQLite
//	** scalar function that is implemented by this routine.
//	**
//	** All this function does is construct an RtreeMatchArg object that
//	** contains the geometry-checking callback routines and a list of
//	** parameters to this function, then return that RtreeMatchArg object
//	** as a BLOB.
//	**
//	** The R-Tree MATCH operator will read the returned BLOB, deserialize
//	** the RtreeMatchArg object, and use the RtreeMatchArg object to figure
//	** out which elements of the R-Tree should be returned by the query.
//	*/
func _geomCallback(tls *libc.TLS, ctx uintptr, nArg int32, aArg uintptr) {
	var i, memErr int32
	var nBlob Tsqlite3_int64
	var pBlob, pGeomCtx uintptr
	_, _, _, _, _ = i, memErr, nBlob, pBlob, pGeomCtx
	pGeomCtx = Xsqlite3_user_data(tls, ctx)
	memErr = 0
	nBlob = int64(uint32(40) + uint32(nArg-libc.Int32FromInt32(1))*uint32(8) + uint32(uint32(nArg))*uint32(4))
	pBlob = Xsqlite3_malloc64(tls, uint64(uint64(nBlob)))
	if !(pBlob != 0) {
		Xsqlite3_result_error_nomem(tls, ctx)
	} else {
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FiSize = uint32(uint32(nBlob))
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb = *(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx))
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam = pBlob + 32 + uintptr(nArg)*8
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam = nArg
		i = 0
		for {
			if !(i < nArg) {
				break
			}
			*(*uintptr)(unsafe.Pointer((*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*4)) = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(aArg + uintptr(i)*4)))
			if *(*uintptr)(unsafe.Pointer((*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*4)) == uintptr(0) {
				memErr = int32(1)
			}
			*(*TRtreeDValue)(unsafe.Pointer(pBlob + 32 + uintptr(i)*8)) = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(aArg + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		if memErr != 0 {
			Xsqlite3_result_error_nomem(tls, ctx)
			_rtreeMatchArgFree(tls, pBlob)
		} else {
			Xsqlite3_result_pointer(tls, ctx, pBlob, __ccgo_ts+27307, __ccgo_fp(_rtreeMatchArgFree))
		}
	}
}

// C documentation
//
//	/*
//	** Register a new geometry function for use with the r-tree MATCH operator.
//	*/
func Xsqlite3_rtree_geometry_callback(tls *libc.TLS, db uintptr, zGeom uintptr, xGeom uintptr, pContext uintptr) (r int32) {
	var pGeomCtx uintptr
	_ = pGeomCtx /* Context object for new user-function */
	/* Allocate and populate the context object. */
	pGeomCtx = Xsqlite3_malloc(tls, int32(16))
	if !(pGeomCtx != 0) {
		return int32(SQLITE_NOMEM)
	}
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxGeom = xGeom
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxQueryFunc = uintptr(0)
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxDestructor = uintptr(0)
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FpContext = pContext
	return Xsqlite3_create_function_v2(tls, db, zGeom, -int32(1), int32(SQLITE_ANY), pGeomCtx, __ccgo_fp(_geomCallback), uintptr(0), uintptr(0), __ccgo_fp(_rtreeFreeCallback))
}

// C documentation
//
//	/*
//	** Register a new 2nd-generation geometry function for use with the
//	** r-tree MATCH operator.
//	*/
func Xsqlite3_rtree_query_callback(tls *libc.TLS, db uintptr, zQueryFunc uintptr, xQueryFunc uintptr, pContext uintptr, xDestructor uintptr) (r int32) {
	var pGeomCtx uintptr
	_ = pGeomCtx /* Context object for new user-function */
	/* Allocate and populate the context object. */
	pGeomCtx = Xsqlite3_malloc(tls, int32(16))
	if !(pGeomCtx != 0) {
		if xDestructor != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDestructor})))(tls, pContext)
		}
		return int32(SQLITE_NOMEM)
	}
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxGeom = uintptr(0)
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxQueryFunc = xQueryFunc
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxDestructor = xDestructor
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FpContext = pContext
	return Xsqlite3_create_function_v2(tls, db, zQueryFunc, -int32(1), int32(SQLITE_ANY), pGeomCtx, __ccgo_fp(_geomCallback), uintptr(0), uintptr(0), __ccgo_fp(_rtreeFreeCallback))
}

/************** End of rtree.c ***********************************************/
/************** Begin file icu.c *********************************************/
/*
** 2007 May 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.
**
*************************************************************************
** $Id: icu.c,v 1.7 2007/12/13 21:54:11 drh Exp $
**
** This file implements an integration between the ICU library
** ("International Components for Unicode", an open-source library
** for handling unicode data) and SQLite. The integration uses
** ICU to provide the following to SQLite:
**
**   * An implementation of the SQL regexp() function (and hence REGEXP
**     operator) using the ICU uregex_XX() APIs.
**
**   * Implementations of the SQL scalar upper() and lower() functions
**     for case mapping.
**
**   * Integration of ICU and SQLite collation sequences.
**
**   * An implementation of the LIKE operator that uses ICU to
**     provide case-independent matching.
 */

/************** End of icu.c *************************************************/
/************** Begin file fts3_icu.c ****************************************/
/*
** 2007 June 22
**
** 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 implements a tokenizer for fts3 based on the ICU library.
 */
/* #include "fts3Int.h" */

/************** End of fts3_icu.c ********************************************/
/************** Begin file sqlite3rbu.c **************************************/
/*
** 2014 August 30
**
** 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.
**
*************************************************************************
**
**
** OVERVIEW
**
**  The RBU extension requires that the RBU update be packaged as an
**  SQLite database. The tables it expects to find are described in
**  sqlite3rbu.h.  Essentially, for each table xyz in the target database
**  that the user wishes to write to, a corresponding data_xyz table is
**  created in the RBU database and populated with one row for each row to
**  update, insert or delete from the target table.
**
**  The update proceeds in three stages:
**
**  1) The database is updated. The modified database pages are written
**     to a *-oal file. A *-oal file is just like a *-wal file, except
**     that it is named "<database>-oal" instead of "<database>-wal".
**     Because regular SQLite clients do not look for file named
**     "<database>-oal", they go on using the original database in
**     rollback mode while the *-oal file is being generated.
**
**     During this stage RBU does not update the database by writing
**     directly to the target tables. Instead it creates "imposter"
**     tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses
**     to update each b-tree individually. All updates required by each
**     b-tree are completed before moving on to the next, and all
**     updates are done in sorted key order.
**
**  2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
**     location using a call to rename(2). Before doing this the RBU
**     module takes an EXCLUSIVE lock on the database file, ensuring
**     that there are no other active readers.
**
**     Once the EXCLUSIVE lock is released, any other database readers
**     detect the new *-wal file and read the database in wal mode. At
**     this point they see the new version of the database - including
**     the updates made as part of the RBU update.
**
**  3) The new *-wal file is checkpointed. This proceeds in the same way
**     as a regular database checkpoint, except that a single frame is
**     checkpointed each time sqlite3rbu_step() is called. If the RBU
**     handle is closed before the entire *-wal file is checkpointed,
**     the checkpoint progress is saved in the RBU database and the
**     checkpoint can be resumed by another RBU client at some point in
**     the future.
**
** POTENTIAL PROBLEMS
**
**  The rename() call might not be portable. And RBU is not currently
**  syncing the directory after renaming the file.
**
**  When state is saved, any commit to the *-oal file and the commit to
**  the RBU update database are not atomic. So if the power fails at the
**  wrong moment they might get out of sync. As the main database will be
**  committed before the RBU update database this will likely either just
**  pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
**  constraint violations).
**
**  If some client does modify the target database mid RBU update, or some
**  other error occurs, the RBU extension will keep throwing errors. It's
**  not really clear how to get out of this state. The system could just
**  by delete the RBU update database and *-oal file and have the device
**  download the update again and start over.
**
**  At present, for an UPDATE, both the new.* and old.* records are
**  collected in the rbu_xyz table. And for both UPDATEs and DELETEs all
**  fields are collected.  This means we're probably writing a lot more
**  data to disk when saving the state of an ongoing update to the RBU
**  update database than is strictly necessary.
**
 */

/* #include <assert.h> */
/* #include <string.h> */
/* #include <stdio.h> */

/* #include "sqlite3.h" */

/************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
/************** Begin file sqlite3rbu.h **************************************/
/*
** 2014 August 30
**
** 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 public interface for the RBU extension.
 */

/*
** SUMMARY
**
** Writing a transaction containing a large number of operations on
** b-tree indexes that are collectively larger than the available cache
** memory can be very inefficient.
**
** The problem is that in order to update a b-tree, the leaf page (at least)
** containing the entry being inserted or deleted must be modified. If the
** working set of leaves is larger than the available cache memory, then a
** single leaf that is modified more than once as part of the transaction
** may be loaded from or written to the persistent media multiple times.
** Additionally, because the index updates are likely to be applied in
** random order, access to pages within the database is also likely to be in
** random order, which is itself quite inefficient.
**
** One way to improve the situation is to sort the operations on each index
** by index key before applying them to the b-tree. This leads to an IO
** pattern that resembles a single linear scan through the index b-tree,
** and all but guarantees each modified leaf page is loaded and stored
** exactly once. SQLite uses this trick to improve the performance of
** CREATE INDEX commands. This extension allows it to be used to improve
** the performance of large transactions on existing databases.
**
** Additionally, this extension allows the work involved in writing the
** large transaction to be broken down into sub-transactions performed
** sequentially by separate processes. This is useful if the system cannot
** guarantee that a single update process will run for long enough to apply
** the entire update, for example because the update is being applied on a
** mobile device that is frequently rebooted. Even after the writer process
** has committed one or more sub-transactions, other database clients continue
** to read from the original database snapshot. In other words, partially
** applied transactions are not visible to other clients.
**
** "RBU" stands for "Resumable Bulk Update". As in a large database update
** transmitted via a wireless network to a mobile device. A transaction
** applied using this extension is hence refered to as an "RBU update".
**
**
** LIMITATIONS
**
** An "RBU update" transaction is subject to the following limitations:
**
**   * The transaction must consist of INSERT, UPDATE and DELETE operations
**     only.
**
**   * INSERT statements may not use any default values.
**
**   * UPDATE and DELETE statements must identify their target rows by
**     non-NULL PRIMARY KEY values. Rows with NULL values stored in PRIMARY
**     KEY fields may not be updated or deleted. If the table being written
**     has no PRIMARY KEY, affected rows must be identified by rowid.
**
**   * UPDATE statements may not modify PRIMARY KEY columns.
**
**   * No triggers will be fired.
**
**   * No foreign key violations are detected or reported.
**
**   * CHECK constraints are not enforced.
**
**   * No constraint handling mode except for "OR ROLLBACK" is supported.
**
**
** PREPARATION
**
** An "RBU update" is stored as a separate SQLite database. A database
** containing an RBU update is an "RBU database". For each table in the
** target database to be updated, the RBU database should contain a table
** named "data_<target name>" containing the same set of columns as the
** target table, and one more - "rbu_control". The data_% table should
** have no PRIMARY KEY or UNIQUE constraints, but each column should have
** the same type as the corresponding column in the target database.
** The "rbu_control" column should have no type at all. For example, if
** the target database contains:
**
**   CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE);
**
** Then the RBU database should contain:
**
**   CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
**
** The order of the columns in the data_% table does not matter.
**
** Instead of a regular table, the RBU database may also contain virtual
** tables or views named using the data_<target> naming scheme.
**
** Instead of the plain data_<target> naming scheme, RBU database tables
** may also be named data<integer>_<target>, where <integer> is any sequence
** of zero or more numeric characters (0-9). This can be significant because
** tables within the RBU database are always processed in order sorted by
** name. By judicious selection of the <integer> portion of the names
** of the RBU tables the user can therefore control the order in which they
** are processed. This can be useful, for example, to ensure that "external
** content" FTS4 tables are updated before their underlying content tables.
**
** If the target database table is a virtual table or a table that has no
** PRIMARY KEY declaration, the data_% table must also contain a column
** named "rbu_rowid". This column is mapped to the table's implicit primary
** key column - "rowid". Virtual tables for which the "rowid" column does
** not function like a primary key value cannot be updated using RBU. For
** example, if the target db contains either of the following:
**
**   CREATE VIRTUAL TABLE x1 USING fts3(a, b);
**   CREATE TABLE x1(a, b)
**
** then the RBU database should contain:
**
**   CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control);
**
** All non-hidden columns (i.e. all columns matched by "SELECT *") of the
** target table must be present in the input table. For virtual tables,
** hidden columns are optional - they are updated by RBU if present in
** the input table, or not otherwise. For example, to write to an fts4
** table with a hidden languageid column such as:
**
**   CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid');
**
** Either of the following input table schemas may be used:
**
**   CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control);
**   CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control);
**
** For each row to INSERT into the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain integer value 0. The
** other columns should be set to the values that make up the new record
** to insert.
**
** If the target database table has an INTEGER PRIMARY KEY, it is not
** possible to insert a NULL value into the IPK column. Attempting to
** do so results in an SQLITE_MISMATCH error.
**
** For each row to DELETE from the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain integer value 1. The
** real primary key values of the row to delete should be stored in the
** corresponding columns of the data_% table. The values stored in the
** other columns are not used.
**
** For each row to UPDATE from the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain a value of type text.
** The real primary key values identifying the row to update should be
** stored in the corresponding columns of the data_% table row, as should
** the new values of all columns being update. The text value in the
** "rbu_control" column must contain the same number of characters as
** there are columns in the target database table, and must consist entirely
** of 'x' and '.' characters (or in some special cases 'd' - see below). For
** each column that is being updated, the corresponding character is set to
** 'x'. For those that remain as they are, the corresponding character of the
** rbu_control value should be set to '.'. For example, given the tables
** above, the update statement:
**
**   UPDATE t1 SET c = 'usa' WHERE a = 4;
**
** is represented by the data_t1 row created by:
**
**   INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..x');
**
** Instead of an 'x' character, characters of the rbu_control value specified
** for UPDATEs may also be set to 'd'. In this case, instead of updating the
** target table with the value stored in the corresponding data_% column, the
** user-defined SQL function "rbu_delta()" is invoked and the result stored in
** the target table column. rbu_delta() is invoked with two arguments - the
** original value currently stored in the target table column and the
** value specified in the data_xxx table.
**
** For example, this row:
**
**   INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
**
** is similar to an UPDATE statement such as:
**
**   UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
**
** Finally, if an 'f' character appears in place of a 'd' or 's' in an
** ota_control string, the contents of the data_xxx table column is assumed
** to be a "fossil delta" - a patch to be applied to a blob value in the
** format used by the fossil source-code management system. In this case
** the existing value within the target database table must be of type BLOB.
** It is replaced by the result of applying the specified fossil delta to
** itself.
**
** If the target database table is a virtual table or a table with no PRIMARY
** KEY, the rbu_control value should not include a character corresponding
** to the rbu_rowid value. For example, this:
**
**   INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control)
**       VALUES(NULL, 'usa', 12, '.x');
**
** causes a result similar to:
**
**   UPDATE ft1 SET b = 'usa' WHERE rowid = 12;
**
** The data_xxx tables themselves should have no PRIMARY KEY declarations.
** However, RBU is more efficient if reading the rows in from each data_xxx
** table in "rowid" order is roughly the same as reading them sorted by
** the PRIMARY KEY of the corresponding target database table. In other
** words, rows should be sorted using the destination table PRIMARY KEY
** fields before they are inserted into the data_xxx tables.
**
** USAGE
**
** The API declared below allows an application to apply an RBU update
** stored on disk to an existing target database. Essentially, the
** application:
**
**     1) Opens an RBU handle using the sqlite3rbu_open() function.
**
**     2) Registers any required virtual table modules with the database
**        handle returned by sqlite3rbu_db(). Also, if required, register
**        the rbu_delta() implementation.
**
**     3) Calls the sqlite3rbu_step() function one or more times on
**        the new handle. Each call to sqlite3rbu_step() performs a single
**        b-tree operation, so thousands of calls may be required to apply
**        a complete update.
**
**     4) Calls sqlite3rbu_close() to close the RBU update handle. If
**        sqlite3rbu_step() has been called enough times to completely
**        apply the update to the target database, then the RBU database
**        is marked as fully applied. Otherwise, the state of the RBU
**        update application is saved in the RBU database for later
**        resumption.
**
** See comments below for more detail on APIs.
**
** If an update is only partially applied to the target database by the
** time sqlite3rbu_close() is called, various state information is saved
** within the RBU database. This allows subsequent processes to automatically
** resume the RBU update from where it left off.
**
** To remove all RBU extension state information, returning an RBU database
** to its original contents, it is sufficient to drop all tables that begin
** with the prefix "rbu_"
**
** DATABASE LOCKING
**
** An RBU update may not be applied to a database in WAL mode. Attempting
** to do so is an error (SQLITE_ERROR).
**
** While an RBU handle is open, a SHARED lock may be held on the target
** database file. This means it is possible for other clients to read the
** database, but not to write it.
**
** If an RBU update is started and then suspended before it is completed,
** then an external client writes to the database, then attempting to resume
** the suspended RBU update is also an error (SQLITE_BUSY).
 */

/* #include "sqlite3.h"              ** Required for error code definitions ** */

type Tsqlite3rbu = struct {
	F__ccgo_align   [0]uint32
	FeStage         int32
	FdbMain         uintptr
	FdbRbu          uintptr
	FzTarget        uintptr
	FzRbu           uintptr
	FzState         uintptr
	FzStateDb       [5]int8
	Frc             int32
	FzErrmsg        uintptr
	FnStep          int32
	FnProgress      int32
	Fobjiter        TRbuObjIter
	FzVfsName       uintptr
	FpTargetFd      uintptr
	FnPagePerSector int32
	FiOalSz         Ti64
	FnPhaseOneStep  Ti64
	FpRenameArg     uintptr
	FxRename        uintptr
	FiMaxFrame      Tu32
	FmLock          Tu32
	FnFrame         int32
	FnFrameAlloc    int32
	FaFrame         uintptr
	Fpgsz           int32
	FaBuf           uintptr
	F__ccgo_align26 [4]byte
	FiWalCksum      Ti64
	FszTemp         Ti64
	FszTempLimit    Ti64
	FnRbu           int32
	FpRbuFd         uintptr
}

type sqlite3rbu = Tsqlite3rbu

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

/* Maximum number of prepared UPDATE statements held by this module */

/* Delta checksums disabled by default.  Compile with -DRBU_ENABLE_DELTA_CKSUM
** to enable checksum verification.
 */

/*
** Swap two objects of type TYPE.
 */

/*
** Name of the URI option that causes RBU to take an exclusive lock as
** part of the incremental checkpoint operation.
 */

/*
** The rbu_state table is used to save the state of a partially applied
** update so that it can be resumed later. The table consists of integer
** keys mapped to values as follows:
**
** RBU_STATE_STAGE:
**   May be set to integer values 1, 2, 4 or 5. As follows:
**       1: the *-rbu file is currently under construction.
**       2: the *-rbu file has been constructed, but not yet moved
**          to the *-wal path.
**       4: the checkpoint is underway.
**       5: the rbu update has been checkpointed.
**
** RBU_STATE_TBL:
**   Only valid if STAGE==1. The target database name of the table
**   currently being written.
**
** RBU_STATE_IDX:
**   Only valid if STAGE==1. The target database name of the index
**   currently being written, or NULL if the main table is currently being
**   updated.
**
** RBU_STATE_ROW:
**   Only valid if STAGE==1. Number of rows already processed for the current
**   table/index.
**
** RBU_STATE_PROGRESS:
**   Trbul number of sqlite3rbu_step() calls made so far as part of this
**   rbu update.
**
** RBU_STATE_CKPT:
**   Valid if STAGE==4. The 64-bit checksum associated with the wal-index
**   header created by recovering the *-wal file. This is used to detect
**   cases when another client appends frames to the *-wal file in the
**   middle of an incremental checkpoint (an incremental checkpoint cannot
**   be continued if this happens).
**
** RBU_STATE_COOKIE:
**   Valid if STAGE==1. The current change-counter cookie value in the
**   target db file.
**
** RBU_STATE_OALSZ:
**   Valid if STAGE==1. The size in bytes of the *-oal file.
**
** RBU_STATE_DATATBL:
**   Only valid if STAGE==1. The RBU database name of the table
**   currently being read.
 */

type TRbuFrame = struct {
	FiDbPage   Tu32
	FiWalFrame Tu32
}

type RbuFrame = TRbuFrame

type TRbuObjIter = struct {
	FpTblIter   uintptr
	FpIdxIter   uintptr
	FnTblCol    int32
	FazTblCol   uintptr
	FazTblType  uintptr
	FaiSrcOrder uintptr
	FabTblPk    uintptr
	FabNotNull  uintptr
	FabIndexed  uintptr
	FeType      int32
	FbCleanup   int32
	FzTbl       uintptr
	FzDataTbl   uintptr
	FzIdx       uintptr
	FiTnum      int32
	FiPkTnum    int32
	FbUnique    int32
	FnIndex     int32
	FnCol       int32
	FpSelect    uintptr
	FpInsert    uintptr
	FpDelete    uintptr
	FpTmpInsert uintptr
	FnIdxCol    int32
	FaIdxCol    uintptr
	FzIdxSql    uintptr
	FpRbuUpdate uintptr
}

type RbuObjIter = TRbuObjIter

type TRbuState = struct {
	F__ccgo_align  [0]uint32
	FeStage        int32
	FzTbl          uintptr
	FzDataTbl      uintptr
	FzIdx          uintptr
	FiWalCksum     Ti64
	FnRow          int32
	F__ccgo_align6 [4]byte
	FnProgress     Ti64
	FiCookie       Tu32
	F__ccgo_align8 [4]byte
	FiOalSz        Ti64
	FnPhaseOneStep Ti64
}

type RbuState = TRbuState

type TRbuSpan = struct {
	FzSpan uintptr
	FnSpan int32
}

type RbuSpan = TRbuSpan

type Trbu_vfs = struct {
	Fbase     Tsqlite3_vfs
	FpRealVfs uintptr
	Fmutex    uintptr
	FpRbu     uintptr
	FpMain    uintptr
	FpMainRbu uintptr
}

type rbu_vfs = Trbu_vfs

type Trbu_file = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_file
	FpReal        uintptr
	FpRbuVfs      uintptr
	FpRbu         uintptr
	Fsz           Ti64
	FopenFlags    int32
	FiCookie      Tu32
	FiWriteVer    Tu8
	FbNolock      Tu8
	FnShm         int32
	FapShm        uintptr
	FzDel         uintptr
	FzWal         uintptr
	FpWalFd       uintptr
	FpMainNext    uintptr
	FpMainRbuNext uintptr
}

type rbu_file = Trbu_file

type TRbuUpdateStmt = struct {
	FzMask   uintptr
	FpUpdate uintptr
	FpNext   uintptr
}

type RbuUpdateStmt = TRbuUpdateStmt

/*
** These values must match the values defined in wal.c for the equivalent
** locks. These are not magic numbers as they are part of the SQLite file
** format.
 */

/*
** A structure to store values read from the rbu_state table in memory.
 */
type TRbuState1 = struct {
	F__ccgo_align  [0]uint32
	FeStage        int32
	FzTbl          uintptr
	FzDataTbl      uintptr
	FzIdx          uintptr
	FiWalCksum     Ti64
	FnRow          int32
	F__ccgo_align6 [4]byte
	FnProgress     Ti64
	FiCookie       Tu32
	F__ccgo_align8 [4]byte
	FiOalSz        Ti64
	FnPhaseOneStep Ti64
}

type RbuState1 = TRbuState1

type TRbuUpdateStmt1 = struct {
	FzMask   uintptr
	FpUpdate uintptr
	FpNext   uintptr
}

type RbuUpdateStmt1 = TRbuUpdateStmt1

type TRbuSpan1 = struct {
	FzSpan uintptr
	FnSpan int32
}

type RbuSpan1 = TRbuSpan1

/*
** An iterator of this type is used to iterate through all objects in
** the target database that require updating. For each such table, the
** iterator visits, in order:
**
**     * the table itself,
**     * each index of the table (zero or more points to visit), and
**     * a special "cleanup table" state.
**
** abIndexed:
**   If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
**   it points to an array of flags nTblCol elements in size. The flag is
**   set for each column that is either a part of the PK or a part of an
**   index. Or clear otherwise.
**
**   If there are one or more partial indexes on the table, all fields of
**   this array set set to 1. This is because in that case, the module has
**   no way to tell which fields will be required to add and remove entries
**   from the partial indexes.
**
 */
type TRbuObjIter1 = struct {
	FpTblIter   uintptr
	FpIdxIter   uintptr
	FnTblCol    int32
	FazTblCol   uintptr
	FazTblType  uintptr
	FaiSrcOrder uintptr
	FabTblPk    uintptr
	FabNotNull  uintptr
	FabIndexed  uintptr
	FeType      int32
	FbCleanup   int32
	FzTbl       uintptr
	FzDataTbl   uintptr
	FzIdx       uintptr
	FiTnum      int32
	FiPkTnum    int32
	FbUnique    int32
	FnIndex     int32
	FnCol       int32
	FpSelect    uintptr
	FpInsert    uintptr
	FpDelete    uintptr
	FpTmpInsert uintptr
	FnIdxCol    int32
	FaIdxCol    uintptr
	FzIdxSql    uintptr
	FpRbuUpdate uintptr
}

type RbuObjIter1 = TRbuObjIter1

/*
** Values for RbuObjIter.eType
**
**     0: Table does not exist (error)
**     1: Table has an implicit rowid.
**     2: Table has an explicit IPK column.
**     3: Table has an external PK index.
**     4: Table is WITHOUT ROWID.
**     5: Table is a virtual table.
 */

/*
** Within the RBU_STAGE_OAL stage, each call to sqlite3rbu_step() performs
** one of the following operations.
 */

/*
** A single step of an incremental checkpoint - frame iWalFrame of the wal
** file should be copied to page iDbPage of the database file.
 */
type TRbuFrame1 = struct {
	FiDbPage   Tu32
	FiWalFrame Tu32
}

type RbuFrame1 = TRbuFrame1

/*
** RBU handle.
**
** nPhaseOneStep:
**   If the RBU database contains an rbu_count table, this value is set to
**   a running estimate of the number of b-tree operations required to
**   finish populating the *-oal file. This allows the sqlite3_bp_progress()
**   API to calculate the permyriadage progress of populating the *-oal file
**   using the formula:
**
**     permyriadage = (10000 * nProgress) / nPhaseOneStep
**
**   nPhaseOneStep is initialized to the sum of:
**
**     nRow * (nIndex + 1)
**
**   for all source tables in the RBU database, where nRow is the number
**   of rows in the source table and nIndex the number of indexes on the
**   corresponding target database table.
**
**   This estimate is accurate if the RBU update consists entirely of
**   INSERT operations. However, it is inaccurate if:
**
**     * the RBU update contains any UPDATE operations. If the PK specified
**       for an UPDATE operation does not exist in the target table, then
**       no b-tree operations are required on index b-trees. Or if the
**       specified PK does exist, then (nIndex*2) such operations are
**       required (one delete and one insert on each index b-tree).
**
**     * the RBU update contains any DELETE operations for which the specified
**       PK does not exist. In this case no operations are required on index
**       b-trees.
**
**     * the RBU update contains REPLACE operations. These are similar to
**       UPDATE operations.
**
**   nPhaseOneStep is updated to account for the conditions above during the
**   first pass of each source table. The updated nPhaseOneStep value is
**   stored in the rbu_state table if the RBU update is suspended.
 */
type Tsqlite3rbu1 = struct {
	F__ccgo_align   [0]uint32
	FeStage         int32
	FdbMain         uintptr
	FdbRbu          uintptr
	FzTarget        uintptr
	FzRbu           uintptr
	FzState         uintptr
	FzStateDb       [5]int8
	Frc             int32
	FzErrmsg        uintptr
	FnStep          int32
	FnProgress      int32
	Fobjiter        TRbuObjIter
	FzVfsName       uintptr
	FpTargetFd      uintptr
	FnPagePerSector int32
	FiOalSz         Ti64
	FnPhaseOneStep  Ti64
	FpRenameArg     uintptr
	FxRename        uintptr
	FiMaxFrame      Tu32
	FmLock          Tu32
	FnFrame         int32
	FnFrameAlloc    int32
	FaFrame         uintptr
	Fpgsz           int32
	FaBuf           uintptr
	F__ccgo_align26 [4]byte
	FiWalCksum      Ti64
	FszTemp         Ti64
	FszTempLimit    Ti64
	FnRbu           int32
	FpRbuFd         uintptr
}

type sqlite3rbu1 = Tsqlite3rbu1

/*
** An rbu VFS is implemented using an instance of this structure.
**
** Variable pRbu is only non-NULL for automatically created RBU VFS objects.
** It is NULL for RBU VFS objects created explicitly using
** sqlite3rbu_create_vfs(). It is used to track the total amount of temp
** space used by the RBU handle.
 */
type Trbu_vfs1 = struct {
	Fbase     Tsqlite3_vfs
	FpRealVfs uintptr
	Fmutex    uintptr
	FpRbu     uintptr
	FpMain    uintptr
	FpMainRbu uintptr
}

type rbu_vfs1 = Trbu_vfs1

/*
** Each file opened by an rbu VFS is represented by an instance of
** the following structure.
**
** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable
** "sz" is set to the current size of the database file.
 */
type Trbu_file1 = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_file
	FpReal        uintptr
	FpRbuVfs      uintptr
	FpRbu         uintptr
	Fsz           Ti64
	FopenFlags    int32
	FiCookie      Tu32
	FiWriteVer    Tu8
	FbNolock      Tu8
	FnShm         int32
	FapShm        uintptr
	FzDel         uintptr
	FzWal         uintptr
	FpWalFd       uintptr
	FpMainNext    uintptr
	FpMainRbuNext uintptr
}

type rbu_file1 = Trbu_file1

/*
** True for an RBU vacuum handle, or false otherwise.
 */

/*************************************************************************
** The following three functions, found below:
**
**   rbuDeltaGetInt()
**   rbuDeltaChecksum()
**   rbuDeltaApply()
**
** are lifted from the fossil source code (http://fossil-scm.org). They
** are used to implement the scalar SQL function rbu_fossil_delta().
 */

// C documentation
//
//	/*
//	** Read bytes from *pz and convert them into a positive integer.  When
//	** finished, leave *pz pointing to the first character past the end of
//	** the integer.  The *pLen parameter holds the length of the string
//	** in *pz and is decremented once for each character in the integer.
//	*/
func _rbuDeltaGetInt(tls *libc.TLS, pz uintptr, pLen uintptr) (r uint32) {
	var c, v1 int32
	var v uint32
	var z, zStart, v2 uintptr
	_, _, _, _, _, _ = c, v, z, zStart, v1, v2
	v = uint32(0)
	z = *(*uintptr)(unsafe.Pointer(pz))
	zStart = z
	for {
		v2 = z
		z++
		v1 = int32(_zValue[int32(0x7f)&int32(*(*uint8)(unsafe.Pointer(v2)))])
		c = v1
		if !(v1 >= 0) {
			break
		}
		v = v<<int32(6) + uint32(uint32(c))
	}
	z--
	*(*int32)(unsafe.Pointer(pLen)) -= int32(int32(z)) - int32(int32(zStart))
	*(*uintptr)(unsafe.Pointer(pz)) = z
	return v
}

var _zValue = [128]int8{
	0:   int8(-int32(1)),
	1:   int8(-int32(1)),
	2:   int8(-int32(1)),
	3:   int8(-int32(1)),
	4:   int8(-int32(1)),
	5:   int8(-int32(1)),
	6:   int8(-int32(1)),
	7:   int8(-int32(1)),
	8:   int8(-int32(1)),
	9:   int8(-int32(1)),
	10:  int8(-int32(1)),
	11:  int8(-int32(1)),
	12:  int8(-int32(1)),
	13:  int8(-int32(1)),
	14:  int8(-int32(1)),
	15:  int8(-int32(1)),
	16:  int8(-int32(1)),
	17:  int8(-int32(1)),
	18:  int8(-int32(1)),
	19:  int8(-int32(1)),
	20:  int8(-int32(1)),
	21:  int8(-int32(1)),
	22:  int8(-int32(1)),
	23:  int8(-int32(1)),
	24:  int8(-int32(1)),
	25:  int8(-int32(1)),
	26:  int8(-int32(1)),
	27:  int8(-int32(1)),
	28:  int8(-int32(1)),
	29:  int8(-int32(1)),
	30:  int8(-int32(1)),
	31:  int8(-int32(1)),
	32:  int8(-int32(1)),
	33:  int8(-int32(1)),
	34:  int8(-int32(1)),
	35:  int8(-int32(1)),
	36:  int8(-int32(1)),
	37:  int8(-int32(1)),
	38:  int8(-int32(1)),
	39:  int8(-int32(1)),
	40:  int8(-int32(1)),
	41:  int8(-int32(1)),
	42:  int8(-int32(1)),
	43:  int8(-int32(1)),
	44:  int8(-int32(1)),
	45:  int8(-int32(1)),
	46:  int8(-int32(1)),
	47:  int8(-int32(1)),
	49:  int8(1),
	50:  int8(2),
	51:  int8(3),
	52:  int8(4),
	53:  int8(5),
	54:  int8(6),
	55:  int8(7),
	56:  int8(8),
	57:  int8(9),
	58:  int8(-int32(1)),
	59:  int8(-int32(1)),
	60:  int8(-int32(1)),
	61:  int8(-int32(1)),
	62:  int8(-int32(1)),
	63:  int8(-int32(1)),
	64:  int8(-int32(1)),
	65:  int8(10),
	66:  int8(11),
	67:  int8(12),
	68:  int8(13),
	69:  int8(14),
	70:  int8(15),
	71:  int8(16),
	72:  int8(17),
	73:  int8(18),
	74:  int8(19),
	75:  int8(20),
	76:  int8(21),
	77:  int8(22),
	78:  int8(23),
	79:  int8(24),
	80:  int8(25),
	81:  int8(26),
	82:  int8(27),
	83:  int8(28),
	84:  int8(29),
	85:  int8(30),
	86:  int8(31),
	87:  int8(32),
	88:  int8(33),
	89:  int8(34),
	90:  int8(35),
	91:  int8(-int32(1)),
	92:  int8(-int32(1)),
	93:  int8(-int32(1)),
	94:  int8(-int32(1)),
	95:  int8(36),
	96:  int8(-int32(1)),
	97:  int8(37),
	98:  int8(38),
	99:  int8(39),
	100: int8(40),
	101: int8(41),
	102: int8(42),
	103: int8(43),
	104: int8(44),
	105: int8(45),
	106: int8(46),
	107: int8(47),
	108: int8(48),
	109: int8(49),
	110: int8(50),
	111: int8(51),
	112: int8(52),
	113: int8(53),
	114: int8(54),
	115: int8(55),
	116: int8(56),
	117: int8(57),
	118: int8(58),
	119: int8(59),
	120: int8(60),
	121: int8(61),
	122: int8(62),
	123: int8(-int32(1)),
	124: int8(-int32(1)),
	125: int8(-int32(1)),
	126: int8(63),
	127: int8(-int32(1)),
}

// C documentation
//
//	/*
//	** Apply a delta.
//	**
//	** The output buffer should be big enough to hold the whole output
//	** file and a NUL terminator at the end.  The delta_output_size()
//	** routine will determine this size for you.
//	**
//	** The delta string should be null-terminated.  But the delta string
//	** may contain embedded NUL characters (if the input and output are
//	** binary files) so we also have to pass in the length of the delta in
//	** the lenDelta parameter.
//	**
//	** This function returns the size of the output file in bytes (excluding
//	** the final NUL terminator character).  Except, if the delta string is
//	** malformed or intended for use with a source file other than zSrc,
//	** then this routine returns -1.
//	**
//	** Refer to the delta_create() documentation above for a description
//	** of the delta file format.
//	*/
func _rbuDeltaApply(tls *libc.TLS, zSrc uintptr, lenSrc int32, _zDelta uintptr, _lenDelta int32, zOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _zDelta
	*(*int32)(unsafe.Pointer(bp + 4)) = _lenDelta
	var cnt, limit, ofst, total uint32
	_, _, _, _ = cnt, limit, ofst, total
	total = uint32(0)
	limit = _rbuDeltaGetInt(tls, bp, bp+4)
	if int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != int32('\n') {
		/* ERROR: size integer not terminated by "\n" */
		return -int32(1)
	}
	*(*uintptr)(unsafe.Pointer(bp))++
	*(*int32)(unsafe.Pointer(bp + 4))--
	for *(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) != 0 && *(*int32)(unsafe.Pointer(bp + 4)) > 0 {
		cnt = _rbuDeltaGetInt(tls, bp, bp+4)
		switch int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) {
		case int32('@'):
			*(*uintptr)(unsafe.Pointer(bp))++
			*(*int32)(unsafe.Pointer(bp + 4))--
			ofst = _rbuDeltaGetInt(tls, bp, bp+4)
			if *(*int32)(unsafe.Pointer(bp + 4)) > 0 && int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != int32(',') {
				/* ERROR: copy command not terminated by ',' */
				return -int32(1)
			}
			*(*uintptr)(unsafe.Pointer(bp))++
			*(*int32)(unsafe.Pointer(bp + 4))--
			total += cnt
			if total > limit {
				/* ERROR: copy exceeds output file size */
				return -int32(1)
			}
			if int32(ofst+cnt) > lenSrc {
				/* ERROR: copy extends past end of input */
				return -int32(1)
			}
			libc.Xmemcpy(tls, zOut, zSrc+uintptr(ofst), cnt)
			zOut += uintptr(cnt)
		case int32(':'):
			*(*uintptr)(unsafe.Pointer(bp))++
			*(*int32)(unsafe.Pointer(bp + 4))--
			total += cnt
			if total > limit {
				/* ERROR:  insert command gives an output larger than predicted */
				return -int32(1)
			}
			if int32(int32(cnt)) > *(*int32)(unsafe.Pointer(bp + 4)) {
				/* ERROR: insert count exceeds size of delta */
				return -int32(1)
			}
			libc.Xmemcpy(tls, zOut, *(*uintptr)(unsafe.Pointer(bp)), cnt)
			zOut += uintptr(cnt)
			*(*uintptr)(unsafe.Pointer(bp)) += uintptr(cnt)
			*(*int32)(unsafe.Pointer(bp + 4)) = int32(uint32(*(*int32)(unsafe.Pointer(bp + 4))) - cnt)
		case int32(';'):
			*(*uintptr)(unsafe.Pointer(bp))++
			*(*int32)(unsafe.Pointer(bp + 4))--
			*(*int8)(unsafe.Pointer(zOut)) = 0
			if total != limit {
				/* ERROR: generated size does not match predicted size */
				return -int32(1)
			}
			return int32(int32(total))
		default:
			/* ERROR: unknown delta operator */
			return -int32(1)
		}
	}
	/* ERROR: unterminated delta */
	return -int32(1)
}

func _rbuDeltaOutputSize(tls *libc.TLS, _zDelta uintptr, _lenDelta int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _zDelta
	*(*int32)(unsafe.Pointer(bp + 4)) = _lenDelta
	var size int32
	_ = size
	size = int32(_rbuDeltaGetInt(tls, bp, bp+4))
	if int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != int32('\n') {
		/* ERROR: size integer not terminated by "\n" */
		return -int32(1)
	}
	return size
}

/*
** End of code taken from fossil.
*************************************************************************/

// C documentation
//
//	/*
//	** Implementation of SQL scalar function rbu_fossil_delta().
//	**
//	** This function applies a fossil delta patch to a blob. Exactly two
//	** arguments must be passed to this function. The first is the blob to
//	** patch and the second the patch to apply. If no error occurs, this
//	** function returns the patched blob.
//	*/
func _rbuFossilDeltaFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var aDelta, aOrig, aOut uintptr
	var nDelta, nOrig, nOut, nOut2 int32
	_, _, _, _, _, _, _ = aDelta, aOrig, aOut, nDelta, nOrig, nOut, nOut2
	nOrig = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	aOrig = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	nDelta = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	aDelta = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4)))
	/* Figure out the size of the output */
	nOut = _rbuDeltaOutputSize(tls, aDelta, nDelta)
	if nOut < 0 {
		Xsqlite3_result_error(tls, context, __ccgo_ts+30048, -int32(1))
		return
	}
	aOut = Xsqlite3_malloc(tls, nOut+int32(1))
	if aOut == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
	} else {
		nOut2 = _rbuDeltaApply(tls, aOrig, nOrig, aDelta, nDelta, aOut)
		if nOut2 != nOut {
			Xsqlite3_free(tls, aOut)
			Xsqlite3_result_error(tls, context, __ccgo_ts+30048, -int32(1))
		} else {
			Xsqlite3_result_blob(tls, context, aOut, nOut, __ccgo_fp(Xsqlite3_free))
		}
	}
}

// C documentation
//
//	/*
//	** Prepare the SQL statement in buffer zSql against database handle db.
//	** If successful, set *ppStmt to point to the new statement and return
//	** SQLITE_OK.
//	**
//	** Otherwise, if an error does occur, set *ppStmt to NULL and return
//	** an SQLite error code. Additionally, set output variable *pzErrmsg to
//	** point to a buffer containing an error message. It is the responsibility
//	** of the caller to (eventually) free this buffer using sqlite3_free().
//	*/
func _prepareAndCollectError(tls *libc.TLS, db uintptr, ppStmt uintptr, pzErrmsg uintptr, zSql uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), ppStmt, uintptr(0))
	if rc != SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(pzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Reset the SQL statement passed as the first argument. Return a copy
//	** of the value returned by sqlite3_reset().
//	**
//	** If an error has occurred, then set *pzErrmsg to point to a buffer
//	** containing an error message. It is the responsibility of the caller
//	** to eventually free this buffer using sqlite3_free().
//	*/
func _resetAndCollectError(tls *libc.TLS, pStmt uintptr, pzErrmsg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = Xsqlite3_reset(tls, pStmt)
	if rc != SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(pzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, Xsqlite3_db_handle(tls, pStmt))))
	}
	return rc
}

// C documentation
//
//	/*
//	** Unless it is NULL, argument zSql points to a buffer allocated using
//	** sqlite3_malloc containing an SQL statement. This function prepares the SQL
//	** statement against database db and frees the buffer. If statement
//	** compilation is successful, *ppStmt is set to point to the new statement
//	** handle and SQLITE_OK is returned.
//	**
//	** Otherwise, if an error occurs, *ppStmt is set to NULL and an error code
//	** returned. In this case, *pzErrmsg may also be set to point to an error
//	** message. It is the responsibility of the caller to free this error message
//	** buffer using sqlite3_free().
//	**
//	** If argument zSql is NULL, this function assumes that an OOM has occurred.
//	** In this case SQLITE_NOMEM is returned and *ppStmt set to NULL.
//	*/
func _prepareFreeAndCollectError(tls *libc.TLS, db uintptr, ppStmt uintptr, pzErrmsg uintptr, zSql uintptr) (r int32) {
	var rc int32
	_ = rc
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
		*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	} else {
		rc = _prepareAndCollectError(tls, db, ppStmt, pzErrmsg, zSql)
		Xsqlite3_free(tls, zSql)
	}
	return rc
}

// C documentation
//
//	/*
//	** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated
//	** by an earlier call to rbuObjIterCacheTableInfo().
//	*/
func _rbuObjIterFreeCols(tls *libc.TLS, pIter uintptr) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
			break
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
	Xsqlite3_free(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol = 0
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FeType = 0 /* Invalid value */
}

// C documentation
//
//	/*
//	** Finalize all statements and free all allocations that are specific to
//	** the current object (table/index pair).
//	*/
func _rbuObjIterClearStatements(tls *libc.TLS, pIter uintptr) {
	var pTmp, pUp uintptr
	_, _ = pTmp, pUp
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpInsert)
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpDelete)
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTmpInsert)
	pUp = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
	for pUp != 0 {
		pTmp = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext
		Xsqlite3_finalize(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate)
		Xsqlite3_free(tls, pUp)
		pUp = pTmp
	}
	Xsqlite3_free(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol)
	Xsqlite3_free(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdxSql)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FpInsert = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FpDelete = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FpTmpInsert = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol = 0
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIdxCol = 0
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdxSql = uintptr(0)
}

// C documentation
//
//	/*
//	** Clean up any resources allocated as part of the iterator object passed
//	** as the only argument.
//	*/
func _rbuObjIterFinalize(tls *libc.TLS, pIter uintptr) {
	_rbuObjIterClearStatements(tls, pIter)
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
	_rbuObjIterFreeCols(tls, pIter)
	libc.Xmemset(tls, pIter, 0, uint32(108))
}

// C documentation
//
//	/*
//	** Advance the iterator to the next position.
//	**
//	** If no error occurs, SQLITE_OK is returned and the iterator is left
//	** pointing to the next entry. Otherwise, an error code and message is
//	** left in the RBU handle passed as the first argument. A copy of the
//	** error code is returned.
//	*/
func _rbuObjIterNext(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	var pIdx uintptr
	var rc, v1, v2 int32
	_, _, _, _ = pIdx, rc, v1, v2
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	if rc == SQLITE_OK {
		/* Free any SQLite statements used while processing the previous object */
		_rbuObjIterClearStatements(tls, pIter)
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+30069, uintptr(0), uintptr(0), p+36)
		}
		if rc == SQLITE_OK {
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 {
				_rbuObjIterFreeCols(tls, pIter)
				(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = 0
				rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
				if rc != int32(SQLITE_ROW) {
					rc = _resetAndCollectError(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, p+36)
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl = uintptr(0)
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl = uintptr(0)
				} else {
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, 0)
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, int32(1))
					if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl != 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 {
						v1 = SQLITE_OK
					} else {
						v1 = int32(SQLITE_NOMEM)
					}
					rc = v1
				}
			} else {
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
					pIdx = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter
					rc = Xsqlite3_bind_text(tls, pIdx, int32(1), (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, -int32(1), libc.UintptrFromInt32(0))
				}
				if rc == SQLITE_OK {
					rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
					if rc != int32(SQLITE_ROW) {
						rc = _resetAndCollectError(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, p+36)
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = int32(1)
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx = uintptr(0)
					} else {
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, 0)
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum = Xsqlite3_column_int(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, int32(1))
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FbUnique = Xsqlite3_column_int(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, int32(2))
						if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx != 0 {
							v2 = SQLITE_OK
						} else {
							v2 = int32(SQLITE_NOMEM)
						}
						rc = v2
					}
				}
			}
		}
	}
	if rc != SQLITE_OK {
		_rbuObjIterFinalize(tls, pIter)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
	return rc
}

// C documentation
//
//	/*
//	** The implementation of the rbu_target_name() SQL function. This function
//	** accepts one or two arguments. The first argument is the name of a table -
//	** the name of a table in the RBU database.  The second, if it is present, is 1
//	** for a view or 0 for a table.
//	**
//	** For a non-vacuum RBU handle, if the table name matches the pattern:
//	**
//	**     data[0-9]_<name>
//	**
//	** where <name> is any sequence of 1 or more characters, <name> is returned.
//	** Otherwise, if the only argument does not match the above pattern, an SQL
//	** NULL is returned.
//	**
//	**     "data_t1"     -> "t1"
//	**     "data0123_t2" -> "t2"
//	**     "dataAB_t3"   -> NULL
//	**
//	** For an rbu vacuum handle, a copy of the first argument is returned if
//	** the second argument is either missing or 0 (not a view).
//	*/
func _rbuTargetNameFunc(tls *libc.TLS, pCtx uintptr, argc int32, argv uintptr) {
	var i int32
	var p, zIn uintptr
	_, _, _ = i, p, zIn
	p = Xsqlite3_user_data(tls, pCtx)
	zIn = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zIn != 0 {
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			if argc == int32(1) || 0 == Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))) {
				Xsqlite3_result_text(tls, pCtx, zIn, -int32(1), libc.UintptrFromInt32(0))
			}
		} else {
			if libc.Xstrlen(tls, zIn) > uint32(4) && libc.Xmemcmp(tls, __ccgo_ts+27220, zIn, uint32(4)) == 0 {
				i = int32(4)
				for {
					if !(int32(*(*int8)(unsafe.Pointer(zIn + uintptr(i)))) >= int32('0') && int32(*(*int8)(unsafe.Pointer(zIn + uintptr(i)))) <= int32('9')) {
						break
					}
					goto _1
				_1:
					;
					i++
				}
				if int32(*(*int8)(unsafe.Pointer(zIn + uintptr(i)))) == int32('_') && *(*int8)(unsafe.Pointer(zIn + uintptr(i+int32(1)))) != 0 {
					Xsqlite3_result_text(tls, pCtx, zIn+uintptr(i+int32(1)), -int32(1), libc.UintptrFromInt32(0))
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Initialize the iterator structure passed as the second argument.
//	**
//	** If no error occurs, SQLITE_OK is returned and the iterator is left
//	** pointing to the first entry. Otherwise, an error code and message is
//	** left in the RBU handle passed as the first argument. A copy of the
//	** error code is returned.
//	*/
func _rbuObjIterFirst(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var v1 uintptr
	_, _ = rc, v1
	libc.Xmemset(tls, pIter, 0, uint32(108))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		v1 = __ccgo_ts + 30240
	} else {
		v1 = __ccgo_ts + 1672
	}
	rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30281, libc.VaList(bp+8, v1)))
	if rc == SQLITE_OK {
		rc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+4, p+36, __ccgo_ts+30431)
	}
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = int32(1)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	return _rbuObjIterNext(tls, p, pIter)
}

// C documentation
//
//	/*
//	** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs,
//	** an error code is stored in the RBU handle passed as the first argument.
//	**
//	** If an error has already occurred (p->rc is already set to something other
//	** than SQLITE_OK), then this function returns NULL without modifying the
//	** stored error code. In this case it still calls sqlite3_free() on any
//	** printf() parameters associated with %z conversions.
//	*/
func _rbuMPrintf(tls *libc.TLS, p uintptr, zFmt uintptr, va uintptr) (r uintptr) {
	var ap Tva_list
	var zSql uintptr
	_, _ = ap, zSql
	zSql = uintptr(0)
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if zSql == uintptr(0) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		}
	} else {
		Xsqlite3_free(tls, zSql)
		zSql = uintptr(0)
	}
	_ = ap
	return zSql
}

// C documentation
//
//	/*
//	** Argument zFmt is a sqlite3_mprintf() style format string. The trailing
//	** arguments are the usual subsitution values. This function performs
//	** the printf() style substitutions and executes the result as an SQL
//	** statement on the RBU handles database.
//	**
//	** If an error occurs, an error code and error message is stored in the
//	** RBU handle. If an error has already occurred when this function is
//	** called, it is a no-op.
//	*/
func _rbuMPrintfExec(tls *libc.TLS, p uintptr, db uintptr, zFmt uintptr, va uintptr) (r int32) {
	var ap Tva_list
	var zSql uintptr
	_, _ = ap, zSql
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if zSql == uintptr(0) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		} else {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, zSql, uintptr(0), uintptr(0), p+36)
		}
	}
	Xsqlite3_free(tls, zSql)
	_ = ap
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Attempt to allocate and return a pointer to a zeroed block of nByte
//	** bytes.
//	**
//	** If an error (i.e. an OOM condition) occurs, return NULL and leave an
//	** error code in the rbu handle passed as the first argument. Or, if an
//	** error has already occurred when this function is called, return NULL
//	** immediately without attempting the allocation or modifying the stored
//	** error code.
//	*/
func _rbuMalloc(tls *libc.TLS, p uintptr, nByte Tsqlite3_int64) (r uintptr) {
	var pRet uintptr
	_ = pRet
	pRet = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pRet = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if pRet == uintptr(0) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, pRet, 0, uint32(uint32(nByte)))
		}
	}
	return pRet
}

// C documentation
//
//	/*
//	** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
//	** there is room for at least nCol elements. If an OOM occurs, store an
//	** error code in the RBU handle passed as the first argument.
//	*/
func _rbuAllocateIterArrays(tls *libc.TLS, p uintptr, pIter uintptr, nCol int32) {
	var azNew uintptr
	var nByte Tsqlite3_int64
	_, _ = azNew, nByte
	nByte = int64((libc.Uint32FromInt32(2)*libc.Uint32FromInt64(4) + libc.Uint32FromInt64(4) + libc.Uint32FromInt32(3)*libc.Uint32FromInt64(1)) * uint32(uint32(nCol)))
	azNew = _rbuMalloc(tls, p, nByte)
	if azNew != 0 {
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol = azNew
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType = azNew + uintptr(nCol)*4
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder = (*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(nCol)*4
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk = (*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(nCol)*4
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull = (*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(nCol)
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed = (*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(nCol)
	}
}

// C documentation
//
//	/*
//	** The first argument must be a nul-terminated string. This function
//	** returns a copy of the string in memory obtained from sqlite3_malloc().
//	** It is the responsibility of the caller to eventually free this memory
//	** using sqlite3_free().
//	**
//	** If an OOM condition is encountered when attempting to allocate memory,
//	** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
//	** if the allocation succeeds, (*pRc) is left unchanged.
//	*/
func _rbuStrndup(tls *libc.TLS, zStr uintptr, pRc uintptr) (r uintptr) {
	var nCopy Tsize_t
	var zRet uintptr
	_, _ = nCopy, zRet
	zRet = uintptr(0)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		if zStr != 0 {
			nCopy = libc.Xstrlen(tls, zStr) + uint32(1)
			zRet = Xsqlite3_malloc64(tls, uint64(uint64(nCopy)))
			if zRet != 0 {
				libc.Xmemcpy(tls, zRet, zStr, nCopy)
			} else {
				*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
			}
		}
	}
	return zRet
}

// C documentation
//
//	/*
//	** Finalize the statement passed as the second argument.
//	**
//	** If the sqlite3_finalize() call indicates that an error occurs, and the
//	** rbu handle error code is not already set, set the error code and error
//	** message accordingly.
//	*/
func _rbuFinalize(tls *libc.TLS, p uintptr, pStmt uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	var rc int32
	_, _ = db, rc
	db = Xsqlite3_db_handle(tls, pStmt)
	rc = Xsqlite3_finalize(tls, pStmt)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && rc != SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
	}
}

// C documentation
//
//	/* Determine the type of a table.
//	**
//	**   peType is of type (int*), a pointer to an output parameter of type
//	**   (int). This call sets the output parameter as follows, depending
//	**   on the type of the table specified by parameters dbName and zTbl.
//	**
//	**     RBU_PK_NOTABLE:       No such table.
//	**     RBU_PK_NONE:          Table has an implicit rowid.
//	**     RBU_PK_IPK:           Table has an explicit IPK column.
//	**     RBU_PK_EXTERNAL:      Table has an external PK index.
//	**     RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
//	**     RBU_PK_VTAB:          Table is a virtual table.
//	**
//	**   Argument *piPk is also of type (int*), and also points to an output
//	**   parameter. Unless the table has an external primary key index
//	**   (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
//	**   if the table does have an external primary key index, then *piPk
//	**   is set to the root page number of the primary key index before
//	**   returning.
//	**
//	** ALGORITHM:
//	**
//	**   if( no entry exists in sqlite_schema ){
//	**     return RBU_PK_NOTABLE
//	**   }else if( sql for the entry starts with "CREATE VIRTUAL" ){
//	**     return RBU_PK_VTAB
//	**   }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
//	**     if( the index that is the pk exists in sqlite_schema ){
//	**       *piPK = rootpage of that index.
//	**       return RBU_PK_EXTERNAL
//	**     }else{
//	**       return RBU_PK_WITHOUT_ROWID
//	**     }
//	**   }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
//	**     return RBU_PK_IPK
//	**   }else{
//	**     return RBU_PK_NONE
//	**   }
//	*/
func _rbuTableType(tls *libc.TLS, p uintptr, zTab uintptr, peType uintptr, piTnum uintptr, piPk uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i uint32
	var zIdx, zOrig uintptr
	var _ /* aStmt at bp+0 */ [4]uintptr
	_, _, _ = i, zIdx, zOrig
	/*
	 ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
	 ** 1) PRAGMA index_list = ?
	 ** 2) SELECT count(*) FROM sqlite_schema where name=%Q
	 ** 3) PRAGMA table_info = ?
	 */
	*(*[4]uintptr)(unsafe.Pointer(bp)) = [4]uintptr{}
	*(*int32)(unsafe.Pointer(peType)) = RBU_PK_NOTABLE
	*(*int32)(unsafe.Pointer(piPk)) = 0
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30556, libc.VaList(bp+24, zTab)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK || Xsqlite3_step(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[0]) != int32(SQLITE_ROW) {
		/* Either an error, or no such table. */
		goto rbuTableType_end
	}
	if Xsqlite3_column_int(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[0], 0) != 0 {
		*(*int32)(unsafe.Pointer(peType)) = int32(RBU_PK_VTAB) /* virtual table */
		goto rbuTableType_end
	}
	*(*int32)(unsafe.Pointer(piTnum)) = Xsqlite3_column_int(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[0], int32(1))
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+1*4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30675, libc.VaList(bp+24, zTab)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
		goto rbuTableType_end
	}
	for Xsqlite3_step(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[int32(1)]) == int32(SQLITE_ROW) {
		zOrig = Xsqlite3_column_text(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[int32(1)], int32(3))
		zIdx = Xsqlite3_column_text(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[int32(1)], int32(1))
		if zOrig != 0 && zIdx != 0 && int32(*(*Tu8)(unsafe.Pointer(zOrig))) == int32('p') {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+2*4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30696, libc.VaList(bp+24, zIdx)))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if Xsqlite3_step(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[int32(2)]) == int32(SQLITE_ROW) {
					*(*int32)(unsafe.Pointer(piPk)) = Xsqlite3_column_int(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[int32(2)], 0)
					*(*int32)(unsafe.Pointer(peType)) = int32(RBU_PK_EXTERNAL)
				} else {
					*(*int32)(unsafe.Pointer(peType)) = int32(RBU_PK_WITHOUT_ROWID)
				}
			}
			goto rbuTableType_end
		}
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+3*4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30747, libc.VaList(bp+24, zTab)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		for Xsqlite3_step(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[int32(3)]) == int32(SQLITE_ROW) {
			if Xsqlite3_column_int(tls, (*(*[4]uintptr)(unsafe.Pointer(bp)))[int32(3)], int32(5)) > 0 {
				*(*int32)(unsafe.Pointer(peType)) = int32(RBU_PK_IPK) /* explicit IPK column */
				goto rbuTableType_end
			}
		}
		*(*int32)(unsafe.Pointer(peType)) = int32(RBU_PK_NONE)
	}
	goto rbuTableType_end
rbuTableType_end:
	;
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(16)/libc.Uint32FromInt64(4)) {
			break
		}
		_rbuFinalize(tls, p, (*(*[4]uintptr)(unsafe.Pointer(bp)))[i])
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** This is a helper function for rbuObjIterCacheTableInfo(). It populates
//	** the pIter->abIndexed[] array.
//	*/
func _rbuObjIterCacheIndexedCols(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bIndex, bPartial, iCid int32
	var zIdx uintptr
	var _ /* pList at bp+0 */ uintptr
	var _ /* pXInfo at bp+4 */ uintptr
	_, _, _, _ = bIndex, bPartial, iCid, zIdx
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	bIndex = 0
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		libc.Xmemcpy(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk, uint32(1)*uint32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30768, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
	}
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex = 0
	for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
		zIdx = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		bPartial = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(4))
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		if zIdx == uintptr(0) {
			break
		}
		if bPartial != 0 {
			libc.Xmemset(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, int32(0x01), uint32(1)*uint32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30796, libc.VaList(bp+16, zIdx)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4))) {
			iCid = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(1))
			if iCid >= 0 {
				*(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(iCid))) = uint8(1)
			}
			if iCid == -int32(2) {
				libc.Xmemset(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, int32(0x01), uint32(1)*uint32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
			}
		}
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)))
		bIndex = int32(1)
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex++
	}
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
		/* "PRAGMA index_list" includes the main PK b-tree */
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex--
	}
	_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	if bIndex == 0 {
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** If they are not already populated, populate the pIter->azTblCol[],
//	** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
//	** the table (not index) that the iterator currently points to.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
//	** an error does occur, an error code and error message are also left in
//	** the RBU handle.
//	*/
func _rbuObjIterCacheTableInfo(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bNotNull, bRbuRowid, i, iOrder, iPk, nCol, t, v2 int32
	var t1, zCopy, zName, zName1, zType, v3, v4 uintptr
	var _ /* iTnum at bp+4 */ int32
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNotNull, bRbuRowid, i, iOrder, iPk, nCol, t, t1, zCopy, zName, zName1, zType, v2, v3, v4
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		nCol = 0      /* for() loop iterator variable */
		bRbuRowid = 0 /* If input table has column "rbu_rowid" */
		iOrder = 0
		*(*int32)(unsafe.Pointer(bp + 4)) = 0
		/* Figure out the type of table this step will deal with. */
		_rbuTableType(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, pIter+36, bp+4, pIter+60)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NOTABLE {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+21362, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl))
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
		}
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum = *(*int32)(unsafe.Pointer(bp + 4))
		}
		/* Populate the azTblCol[] and nTblCol variables based on the columns
		 ** of the input table. Ignore any input table columns that begin with
		 ** "rbu_".  */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30825, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl)))
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			nCol = Xsqlite3_column_count(tls, *(*uintptr)(unsafe.Pointer(bp)))
			_rbuAllocateIterArrays(tls, p, pIter, nCol)
		}
		i = 0
		for {
			if !((*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && i < nCol) {
				break
			}
			zName = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp)), i)
			if Xsqlite3_strnicmp(tls, __ccgo_ts+30844, zName, int32(4)) != 0 {
				zCopy = _rbuStrndup(tls, zName, p+32)
				*(*int32)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)*4)) = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol
				v3 = pIter + 8
				v2 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3))++
				*(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(v2)*4)) = zCopy
			} else {
				if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+30849, zName) {
					bRbuRowid = int32(1)
				}
			}
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && bRbuRowid != libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE)) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
			if bRbuRowid != 0 {
				v4 = __ccgo_ts + 30859
			} else {
				v4 = __ccgo_ts + 30872
			}
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+30881, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v4))
		}
		/* Check that all non-HIDDEN columns in the destination table are also
		 ** present in the input table. Populate the abTblPk[], azTblType[] and
		 ** aiTblOrder[] arrays at the same time.  */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30910, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		}
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			zName1 = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
			if zName1 == uintptr(0) {
				break
			} /* An OOM - finalize() below returns S_NOMEM */
			i = iOrder
			for {
				if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
					break
				}
				if 0 == libc.Xstrcmp(tls, zName1, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4))) {
					break
				}
				goto _5
			_5:
				;
				i++
			}
			if i == (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+30932, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zName1))
			} else {
				iPk = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(5))
				bNotNull = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(3))
				zType = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2))
				if i != iOrder {
					t = *(*int32)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4))
					*(*int32)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)) = *(*int32)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4))
					*(*int32)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4)) = t
					t1 = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4))
					*(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)) = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*4))
					*(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*4)) = t1
				}
				*(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iOrder)*4)) = _rbuStrndup(tls, zType, p+32)
				*(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iOrder))) = uint8(uint8(iPk))
				*(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iOrder))) = libc.BoolUint8(uint8(uint8(bNotNull)) != 0 || iPk != 0)
				iOrder++
			}
		}
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		_rbuObjIterCacheIndexedCols(tls, p, pIter)
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** This function constructs and returns a pointer to a nul-terminated
//	** string containing some SQL clause or list based on one or more of the
//	** column names currently stored in the pIter->azTblCol[] array.
//	*/
func _rbuObjIterGetCollist(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var z, zList, zSep uintptr
	_, _, _, _ = i, z, zList, zSep
	zList = uintptr(0)
	zSep = __ccgo_ts + 1672
	i = 0
	for {
		if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
			break
		}
		z = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4))
		zList = _rbuMPrintf(tls, p, __ccgo_ts+30959, libc.VaList(bp+8, zList, zSep, z))
		zSep = __ccgo_ts + 16397
		goto _1
	_1:
		;
		i++
	}
	return zList
}

// C documentation
//
//	/*
//	** Return a comma separated list of the quoted PRIMARY KEY column names,
//	** in order, for the current table. Before each column name, add the text
//	** zPre. After each column name, add the zPost text. Use zSeparator as
//	** the separator text (usually ", ").
//	*/
func _rbuObjIterGetPkList(tls *libc.TLS, p uintptr, pIter uintptr, zPre uintptr, zSeparator uintptr, zPost uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, iPk int32
	var zCol, zRet, zSep uintptr
	_, _, _, _, _ = i, iPk, zCol, zRet, zSep
	iPk = int32(1)
	zRet = uintptr(0)
	zSep = __ccgo_ts + 1672
	for int32(1) != 0 {
		i = 0
		for {
			if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
				break
			}
			if int32(*(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == iPk {
				zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4))
				zRet = _rbuMPrintf(tls, p, __ccgo_ts+30968, libc.VaList(bp+8, zRet, zSep, zPre, zCol, zPost))
				zSep = zSeparator
				break
			}
			goto _1
		_1:
			;
			i++
		}
		if i == (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
			break
		}
		iPk++
	}
	return zRet
}

// C documentation
//
//	/*
//	** This function is called as part of restarting an RBU vacuum within
//	** stage 1 of the process (while the *-oal file is being built) while
//	** updating a table (not an index). The table may be a rowid table or
//	** a WITHOUT ROWID table. It queries the target database to find the
//	** largest key that has already been written to the target table and
//	** constructs a WHERE clause that can be used to extract the remaining
//	** rows from the source table. For a rowid table, the WHERE clause
//	** is of the form:
//	**
//	**     "WHERE _rowid_ > ?"
//	**
//	** and for WITHOUT ROWID tables:
//	**
//	**     "WHERE (key1, key2) > (?, ?)"
//	**
//	** Instead of "?" placeholders, the actual WHERE clauses created by
//	** this function contain literal SQL values.
//	*/
func _rbuVacuumTableStart(tls *libc.TLS, p uintptr, pIter uintptr, bRowid int32, zWrite uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iMax Tsqlite3_int64
	var zList, zOrder, zRet, zSelect, zVal uintptr
	var _ /* pMax at bp+0 */ uintptr
	_, _, _, _, _, _ = iMax, zList, zOrder, zRet, zSelect, zVal
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	zRet = uintptr(0)
	if bRowid != 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30981, libc.VaList(bp+16, zWrite, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			iMax = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			zRet = _rbuMPrintf(tls, p, __ccgo_ts+31013, libc.VaList(bp+16, iMax))
		}
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	} else {
		zOrder = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1672, __ccgo_ts+16397, __ccgo_ts+31036)
		zSelect = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+31042, __ccgo_ts+31049, __ccgo_ts+6479)
		zList = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1672, __ccgo_ts+16397, __ccgo_ts+1672)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+31057, libc.VaList(bp+16, zSelect, zWrite, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zOrder)))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				zVal = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
				zRet = _rbuMPrintf(tls, p, __ccgo_ts+31099, libc.VaList(bp+16, zList, zVal))
			}
			_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		}
		Xsqlite3_free(tls, zOrder)
		Xsqlite3_free(tls, zSelect)
		Xsqlite3_free(tls, zList)
	}
	return zRet
}

// C documentation
//
//	/*
//	** This function is called as part of restating an RBU vacuum when the
//	** current operation is writing content to an index. If possible, it
//	** queries the target index b-tree for the largest key already written to
//	** it, then composes and returns an expression that can be used in a WHERE
//	** clause to select the remaining required rows from the source table.
//	** It is only possible to return such an expression if:
//	**
//	**   * The index contains no DESC columns, and
//	**   * The last key written to the index before the operation was
//	**     suspended does not contain any NULL values.
//	**
//	** The expression is of the form:
//	**
//	**   (index-field1, index-field2, ...) > (?, ?, ...)
//	**
//	** except that the "?" placeholders are replaced with literal values.
//	**
//	** If the expression cannot be created, NULL is returned. In this case,
//	** the caller has to use an OFFSET clause to extract only the required
//	** rows from the sourct table, just as it does for an RBU update operation.
//	*/
func _rbuVacuumIndexStart(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bFailed, i, iCid, iCol int32
	var zCol, zCollate, zLhs, zOrder, zQuoted, zRet, zSelect, zSep, zVector uintptr
	var _ /* pSel at bp+4 */ uintptr
	var _ /* pXInfo at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = bFailed, i, iCid, iCol, zCol, zCollate, zLhs, zOrder, zQuoted, zRet, zSelect, zSep, zVector
	zOrder = uintptr(0)
	zLhs = uintptr(0)
	zSelect = uintptr(0)
	zVector = uintptr(0)
	zRet = uintptr(0)
	bFailed = 0
	zSep = __ccgo_ts + 1672
	iCol = 0
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30796, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx)))
	for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
		iCid = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		zCollate = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(4))
		if Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(3)) != 0 {
			bFailed = int32(1)
			break
		}
		if iCid < 0 {
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) {
				i = 0
				for {
					if !(int32(*(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0) {
						break
					}
					goto _1
				_1:
					;
					i++
				}
				zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4))
			} else {
				zCol = __ccgo_ts + 31119
			}
		} else {
			zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*4))
		}
		zLhs = _rbuMPrintf(tls, p, __ccgo_ts+31127, libc.VaList(bp+16, zLhs, zSep, zCol, zCollate))
		zOrder = _rbuMPrintf(tls, p, __ccgo_ts+31148, libc.VaList(bp+16, zOrder, zSep, iCol, zCol, zCollate))
		zSelect = _rbuMPrintf(tls, p, __ccgo_ts+31184, libc.VaList(bp+16, zSelect, zSep, iCol, zCol))
		zSep = __ccgo_ts + 16397
		iCol++
	}
	_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	if bFailed != 0 {
		goto index_start_out
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+31211, libc.VaList(bp+16, zSelect, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zOrder)))
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4))) {
			zSep = __ccgo_ts + 1672
			iCol = 0
			for {
				if !(iCol < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
					break
				}
				zQuoted = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), iCol)
				if zQuoted == uintptr(0) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
				} else {
					if int32(*(*int8)(unsafe.Pointer(zQuoted))) == int32('N') {
						bFailed = int32(1)
						break
					}
				}
				zVector = _rbuMPrintf(tls, p, __ccgo_ts+31259, libc.VaList(bp+16, zVector, zSep, zQuoted))
				zSep = __ccgo_ts + 16397
				goto _2
			_2:
				;
				iCol++
			}
			if !(bFailed != 0) {
				zRet = _rbuMPrintf(tls, p, __ccgo_ts+31266, libc.VaList(bp+16, zLhs, zVector))
			}
		}
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	goto index_start_out
index_start_out:
	;
	Xsqlite3_free(tls, zOrder)
	Xsqlite3_free(tls, zSelect)
	Xsqlite3_free(tls, zVector)
	Xsqlite3_free(tls, zLhs)
	return zRet
}

// C documentation
//
//	/*
//	** This function is used to create a SELECT list (the list of SQL
//	** expressions that follows a SELECT keyword) for a SELECT statement
//	** used to read from an data_xxx or rbu_tmp_xxx table while updating the
//	** index object currently indicated by the iterator object passed as the
//	** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used
//	** to obtain the required information.
//	**
//	** If the index is of the following form:
//	**
//	**   CREATE INDEX i1 ON t1(c, b COLLATE nocase);
//	**
//	** and "t1" is a table with an explicit INTEGER PRIMARY KEY column
//	** "ipk", the returned string is:
//	**
//	**   "`c` COLLATE 'BINARY', `b` COLLATE 'NOCASE', `ipk` COLLATE 'BINARY'"
//	**
//	** As well as the returned string, three other malloc'd strings are
//	** returned via output parameters. As follows:
//	**
//	**   pzImposterCols: ...
//	**   pzImposterPk: ...
//	**   pzWhere: ...
//	*/
func _rbuObjIterGetIndexCols(tls *libc.TLS, p uintptr, pIter uintptr, pzImposterCols uintptr, pzImposterPk uintptr, pzWhere uintptr, pnBind uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bDesc, i, iCid, iSeq, nBind, rc, rc2 int32
	var zAnd, zCol, zCollate, zCom, zImpCols, zImpPK, zOrder, zRet, zType, zWhere, v2 uintptr
	var _ /* pXInfo at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDesc, i, iCid, iSeq, nBind, rc, rc2, zAnd, zCol, zCollate, zCom, zImpCols, zImpPK, zOrder, zRet, zType, zWhere, v2
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc   /* sqlite3_finalize() return code */
	zRet = uintptr(0)                            /* String to return */
	zImpCols = uintptr(0)                        /* String to return via *pzImposterCols */
	zImpPK = uintptr(0)                          /* String to return via *pzImposterPK */
	zWhere = uintptr(0)                          /* String to return via *pzWhere */
	nBind = 0                                    /* Value to return via *pnBind */
	zCom = __ccgo_ts + 1672                      /* Set to ", " later on */
	zAnd = __ccgo_ts + 1672                      /* Set to " AND " later on */
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* PRAGMA index_xinfo = ? */
	if rc == SQLITE_OK {
		rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30796, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx)))
	}
	for rc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
		iCid = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		bDesc = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(3))
		zCollate = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(4))
		zCol = uintptr(0)
		if iCid == -int32(2) {
			iSeq = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+31278, libc.VaList(bp+16, zRet, zCom, (*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iSeq)*8))).FnSpan, (*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iSeq)*8))).FzSpan, zCollate))
			zType = __ccgo_ts + 1672
		} else {
			if iCid < 0 {
				/* An integer primary key. If the table has an explicit IPK, use
				 ** its name. Otherwise, use "rbu_rowid".  */
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) {
					i = 0
					for {
						if !(int32(*(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0) {
							break
						}
						goto _1
					_1:
						;
						i++
					}
					zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4))
				} else {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						zCol = __ccgo_ts + 31119
					} else {
						zCol = __ccgo_ts + 30849
					}
				}
				zType = __ccgo_ts + 1146
			} else {
				zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*4))
				zType = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*4))
			}
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+31300, libc.VaList(bp+16, zRet, zCom, zCol, zCollate))
		}
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbUnique == 0 || Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(5)) != 0 {
			if bDesc != 0 {
				v2 = __ccgo_ts + 31036
			} else {
				v2 = __ccgo_ts + 1672
			}
			zOrder = v2
			zImpPK = Xsqlite3_mprintf(tls, __ccgo_ts+31320, libc.VaList(bp+16, zImpPK, zCom, nBind, zCol, zOrder))
		}
		zImpCols = Xsqlite3_mprintf(tls, __ccgo_ts+31341, libc.VaList(bp+16, zImpCols, zCom, nBind, zCol, zType, zCollate))
		zWhere = Xsqlite3_mprintf(tls, __ccgo_ts+31374, libc.VaList(bp+16, zWhere, zAnd, nBind, zCol))
		if zRet == uintptr(0) || zImpPK == uintptr(0) || zImpCols == uintptr(0) || zWhere == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
		zCom = __ccgo_ts + 16397
		zAnd = __ccgo_ts + 23484
		nBind++
	}
	rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == SQLITE_OK {
		rc = rc2
	}
	if rc != SQLITE_OK {
		Xsqlite3_free(tls, zRet)
		Xsqlite3_free(tls, zImpCols)
		Xsqlite3_free(tls, zImpPK)
		Xsqlite3_free(tls, zWhere)
		zRet = uintptr(0)
		zImpCols = uintptr(0)
		zImpPK = uintptr(0)
		zWhere = uintptr(0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
	*(*uintptr)(unsafe.Pointer(pzImposterCols)) = zImpCols
	*(*uintptr)(unsafe.Pointer(pzImposterPk)) = zImpPK
	*(*uintptr)(unsafe.Pointer(pzWhere)) = zWhere
	*(*int32)(unsafe.Pointer(pnBind)) = nBind
	return zRet
}

// C documentation
//
//	/*
//	** Assuming the current table columns are "a", "b" and "c", and the zObj
//	** paramter is passed "old", return a string of the form:
//	**
//	**     "old.a, old.b, old.b"
//	**
//	** With the column names escaped.
//	**
//	** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append
//	** the text ", old._rowid_" to the returned value.
//	*/
func _rbuObjIterGetOldlist(tls *libc.TLS, p uintptr, pIter uintptr, zObj uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var zCol, zList, zS uintptr
	_, _, _, _ = i, zCol, zList, zS
	zList = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
		zS = __ccgo_ts + 1672
		i = 0
		for {
			if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
				break
			}
			if *(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(i))) != 0 {
				zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4))
				zList = Xsqlite3_mprintf(tls, __ccgo_ts+31398, libc.VaList(bp+8, zList, zS, zObj, zCol))
			} else {
				zList = Xsqlite3_mprintf(tls, __ccgo_ts+31410, libc.VaList(bp+8, zList, zS))
			}
			zS = __ccgo_ts + 16397
			if zList == uintptr(0) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
				break
			}
			goto _1
		_1:
			;
			i++
		}
		/* For a table with implicit rowids, append "old._rowid_" to the list. */
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
			zList = _rbuMPrintf(tls, p, __ccgo_ts+31419, libc.VaList(bp+8, zList, zObj))
		}
	}
	return zList
}

// C documentation
//
//	/*
//	** Return an expression that can be used in a WHERE clause to match the
//	** primary key of the current table. For example, if the table is:
//	**
//	**   CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c));
//	**
//	** Return the string:
//	**
//	**   "b = ?1 AND c = ?2"
//	*/
func _rbuObjIterGetWhere(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, i1 int32
	var zCol, zList, zSep, zSep1 uintptr
	_, _, _, _, _, _ = i, i1, zCol, zList, zSep, zSep1
	zList = uintptr(0)
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
		zList = _rbuMPrintf(tls, p, __ccgo_ts+31434, libc.VaList(bp+8, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+int32(1)))
	} else {
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
			zSep = __ccgo_ts + 1672
			i = 0
			for {
				if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
					break
				}
				if *(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 {
					zList = _rbuMPrintf(tls, p, __ccgo_ts+31448, libc.VaList(bp+8, zList, zSep, i, i+int32(1)))
					zSep = __ccgo_ts + 23484
				}
				goto _1
			_1:
				;
				i++
			}
			zList = _rbuMPrintf(tls, p, __ccgo_ts+31460, libc.VaList(bp+8, zList))
		} else {
			zSep1 = __ccgo_ts + 1672
			i1 = 0
			for {
				if !(i1 < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
					break
				}
				if *(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i1))) != 0 {
					zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i1)*4))
					zList = _rbuMPrintf(tls, p, __ccgo_ts+31510, libc.VaList(bp+8, zList, zSep1, zCol, i1+int32(1)))
					zSep1 = __ccgo_ts + 23484
				}
				goto _2
			_2:
				;
				i1++
			}
		}
	}
	return zList
}

// C documentation
//
//	/*
//	** The SELECT statement iterating through the keys for the current object
//	** (p->objiter.pSelect) currently points to a valid row. However, there
//	** is something wrong with the rbu_control value in the rbu_control value
//	** stored in the (p->nCol+1)'th column. Set the error code and error message
//	** of the RBU handle to something reflecting this.
//	*/
func _rbuBadControlError(tls *libc.TLS, p uintptr) {
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+31523, 0)
}

// C documentation
//
//	/*
//	** Return a nul-terminated string containing the comma separated list of
//	** assignments that should be included following the "SET" keyword of
//	** an UPDATE statement used to update the table object that the iterator
//	** passed as the second argument currently points to if the rbu_control
//	** column of the data_xxx table entry is set to zMask.
//	**
//	** The memory for the returned string is obtained from sqlite3_malloc().
//	** It is the responsibility of the caller to eventually free it using
//	** sqlite3_free().
//	**
//	** If an OOM error is encountered when allocating space for the new
//	** string, an error code is left in the rbu handle passed as the first
//	** argument and NULL is returned. Or, if an error has already occurred
//	** when this function is called, NULL is returned immediately, without
//	** attempting the allocation or modifying the stored error code.
//	*/
func _rbuObjIterGetSetlist(tls *libc.TLS, p uintptr, pIter uintptr, zMask uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var c int8
	var i int32
	var zList, zSep uintptr
	_, _, _, _ = c, i, zList, zSep
	zList = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if int32(libc.Xstrlen(tls, zMask)) != (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
			_rbuBadControlError(tls, p)
		} else {
			zSep = __ccgo_ts + 1672
			i = 0
			for {
				if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
					break
				}
				c = *(*int8)(unsafe.Pointer(zMask + uintptr(*(*int32)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)))))
				if int32(int32(c)) == int32('x') {
					zList = _rbuMPrintf(tls, p, __ccgo_ts+31510, libc.VaList(bp+8, zList, zSep, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), i+int32(1)))
					zSep = __ccgo_ts + 16397
				} else {
					if int32(int32(c)) == int32('d') {
						zList = _rbuMPrintf(tls, p, __ccgo_ts+31549, libc.VaList(bp+8, zList, zSep, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), i+int32(1)))
						zSep = __ccgo_ts + 16397
					} else {
						if int32(int32(c)) == int32('f') {
							zList = _rbuMPrintf(tls, p, __ccgo_ts+31579, libc.VaList(bp+8, zList, zSep, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), i+int32(1)))
							zSep = __ccgo_ts + 16397
						}
					}
				}
				goto _1
			_1:
				;
				i++
			}
		}
	}
	return zList
}

// C documentation
//
//	/*
//	** Return a nul-terminated string consisting of nByte comma separated
//	** "?" expressions. For example, if nByte is 3, return a pointer to
//	** a buffer containing the string "?,?,?".
//	**
//	** The memory for the returned string is obtained from sqlite3_malloc().
//	** It is the responsibility of the caller to eventually free it using
//	** sqlite3_free().
//	**
//	** If an OOM error is encountered when allocating space for the new
//	** string, an error code is left in the rbu handle passed as the first
//	** argument and NULL is returned. Or, if an error has already occurred
//	** when this function is called, NULL is returned immediately, without
//	** attempting the allocation or modifying the stored error code.
//	*/
func _rbuObjIterGetBindlist(tls *libc.TLS, p uintptr, nBind int32) (r uintptr) {
	var i, v2 int32
	var nByte Tsqlite3_int64
	var zRet uintptr
	_, _, _, _ = i, nByte, zRet, v2
	zRet = uintptr(0)
	nByte = int64(2)*int64(int64(nBind)) + int64(1)
	zRet = _rbuMalloc(tls, p, nByte)
	if zRet != 0 {
		i = 0
		for {
			if !(i < nBind) {
				break
			}
			*(*int8)(unsafe.Pointer(zRet + uintptr(i*int32(2)))) = int8('?')
			if i+int32(1) == nBind {
				v2 = int32('\000')
			} else {
				v2 = int32(',')
			}
			*(*int8)(unsafe.Pointer(zRet + uintptr(i*int32(2)+int32(1)))) = int8(v2)
			goto _1
		_1:
			;
			i++
		}
	}
	return zRet
}

// C documentation
//
//	/*
//	** The iterator currently points to a table (not index) of type
//	** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
//	** declaration for the corresponding imposter table. For example,
//	** if the iterator points to a table created as:
//	**
//	**   CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
//	**
//	** this function returns:
//	**
//	**   PRIMARY KEY("b", "a" DESC)
//	*/
func _rbuWithoutRowidPK(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var z, zCol, zDesc, zIdx, zOrig, zSep, v1 uintptr
	var _ /* pXInfo at bp+4 */ uintptr
	var _ /* pXList at bp+0 */ uintptr
	_, _, _, _, _, _, _ = z, zCol, zDesc, zIdx, zOrig, zSep, v1
	z = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		zSep = __ccgo_ts + 31616
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)     /* PRAGMA index_list = (pIter->zTbl) */
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* PRAGMA index_xinfo = <pk-index> */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30768, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			zOrig = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(3))
			if zOrig != 0 && libc.Xstrcmp(tls, zOrig, __ccgo_ts+17984) == 0 {
				zIdx = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
				if zIdx != 0 {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30796, libc.VaList(bp+16, zIdx)))
				}
				break
			}
		}
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4))) {
			if Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(5)) != 0 {
				/* int iCid = sqlite3_column_int(pXInfo, 0); */
				zCol = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(2))
				if Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(3)) != 0 {
					v1 = __ccgo_ts + 31036
				} else {
					v1 = __ccgo_ts + 1672
				}
				zDesc = v1
				z = _rbuMPrintf(tls, p, __ccgo_ts+31629, libc.VaList(bp+16, z, zSep, zCol, zDesc))
				zSep = __ccgo_ts + 16397
			}
		}
		z = _rbuMPrintf(tls, p, __ccgo_ts+31640, libc.VaList(bp+16, z))
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	return z
}

// C documentation
//
//	/*
//	** This function creates the second imposter table used when writing to
//	** a table b-tree where the table has an external primary key. If the
//	** iterator passed as the second argument does not currently point to
//	** a table (not index) with an external primary key, this function is a
//	** no-op.
//	**
//	** Assuming the iterator does point to a table with an external PK, this
//	** function creates a WITHOUT ROWID imposter table named "rbu_imposter2"
//	** used to access that PK index. For example, if the target table is
//	** declared as follows:
//	**
//	**   CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
//	**
//	** then the imposter table schema is:
//	**
//	**   CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
//	**
//	*/
func _rbuCreateImposterTable2(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bDesc, bKey, iCid, tnum int32
	var zCollate, zCols, zComma, zIdx, zPk, v1 uintptr
	var _ /* pQuery at bp+0 */ uintptr
	var _ /* pXInfo at bp+4 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = bDesc, bKey, iCid, tnum, zCollate, zCols, zComma, zIdx, zPk, v1
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
		tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiPkTnum /* Root page of PK index */
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)          /* SELECT name ... WHERE rootpage = $tnum */
		zIdx = uintptr(0)                                     /* Name of PK index */
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)      /* PRAGMA main.index_xinfo = $zIdx */
		zComma = __ccgo_ts + 1672
		zCols = uintptr(0) /* Used to build up list of table cols */
		zPk = uintptr(0)   /* Used to build up table PK declaration */
		/* Figure out the name of the primary key index for the current table.
		 ** This is needed for the argument to "PRAGMA index_xinfo". Set
		 ** zIdx to point to a nul-terminated string containing this name. */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, __ccgo_ts+31644)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			Xsqlite3_bind_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), tnum)
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				zIdx = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			}
		}
		if zIdx != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+30796, libc.VaList(bp+16, zIdx)))
		}
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4))) {
			bKey = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(5))
			if bKey != 0 {
				iCid = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(1))
				bDesc = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(3))
				zCollate = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), int32(4))
				zCols = _rbuMPrintf(tls, p, __ccgo_ts+31694, libc.VaList(bp+16, zCols, zComma, iCid, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*4)), zCollate))
				if bDesc != 0 {
					v1 = __ccgo_ts + 31036
				} else {
					v1 = __ccgo_ts + 1672
				}
				zPk = _rbuMPrintf(tls, p, __ccgo_ts+31716, libc.VaList(bp+16, zPk, zComma, iCid, v1))
				zComma = __ccgo_ts + 16397
			}
		}
		zCols = _rbuMPrintf(tls, p, __ccgo_ts+31726, libc.VaList(bp+16, zCols))
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)))
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, int32(1), tnum))
		_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+31741, libc.VaList(bp+16, zCols, zPk))
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, 0, 0))
	}
}

// C documentation
//
//	/*
//	** If an error has already occurred when this function is called, it
//	** immediately returns zero (without doing any work). Or, if an error
//	** occurs during the execution of this function, it sets the error code
//	** in the sqlite3rbu object indicated by the first argument and returns
//	** zero.
//	**
//	** The iterator passed as the second argument is guaranteed to point to
//	** a table (not an index) when this function is called. This function
//	** attempts to create any imposter table required to write to the main
//	** table b-tree of the table before returning. Non-zero is returned if
//	** an imposter table are created, or zero otherwise.
//	**
//	** An imposter table is required in all cases except RBU_PK_VTAB. Only
//	** virtual tables are written to directly. The imposter table has the
//	** same schema as the actual target table (less any UNIQUE constraints).
//	** More precisely, the "same schema" means the same columns, types,
//	** collation sequences. For tables that do not have an external PRIMARY
//	** KEY, it also means the same PRIMARY KEY declaration.
//	*/
func _rbuCreateImposterTable(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var iCol, tnum int32
	var zCol, zComma, zPk, zPk1, zSql, v2, v3 uintptr
	var _ /* zColl at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _ = iCol, tnum, zCol, zComma, zPk, zPk1, zSql, v2, v3
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType != int32(RBU_PK_VTAB) {
		tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum
		zComma = __ccgo_ts + 1672
		zSql = uintptr(0)
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, 0, int32(1)))
		iCol = 0
		for {
			if !((*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && iCol < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
				break
			}
			zPk = __ccgo_ts + 1672
			zCol = *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCol)*4))
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_table_column_metadata(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zCol, uintptr(0), bp, uintptr(0), uintptr(0), uintptr(0))
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) && *(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iCol))) != 0 {
				/* If the target table column is an "INTEGER PRIMARY KEY", add
				 ** "PRIMARY KEY" to the imposter table column declaration. */
				zPk = __ccgo_ts + 31803
			}
			if *(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iCol))) != 0 {
				v2 = __ccgo_ts + 31816
			} else {
				v2 = __ccgo_ts + 1672
			}
			zSql = _rbuMPrintf(tls, p, __ccgo_ts+31826, libc.VaList(bp+16, zSql, zComma, zCol, *(*uintptr)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCol)*4)), zPk, *(*uintptr)(unsafe.Pointer(bp)), v2))
			zComma = __ccgo_ts + 16397
			goto _1
		_1:
			;
			iCol++
		}
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
			zPk1 = _rbuWithoutRowidPK(tls, p, pIter)
			if zPk1 != 0 {
				zSql = _rbuMPrintf(tls, p, __ccgo_ts+31853, libc.VaList(bp+16, zSql, zPk1))
			}
		}
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, int32(1), tnum))
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
			v3 = __ccgo_ts + 31860
		} else {
			v3 = __ccgo_ts + 1672
		}
		_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+31875, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSql, v3))
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, 0, 0))
	}
}

// C documentation
//
//	/*
//	** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table.
//	** Specifically a statement of the form:
//	**
//	**     INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...);
//	**
//	** The number of bound variables is equal to the number of columns in
//	** the target table, plus one (for the rbu_control column), plus one more
//	** (for the rbu_rowid column) if the target table is an implicit IPK or
//	** virtual table.
//	*/
func _rbuObjIterPrepareTmpInsert(tls *libc.TLS, p uintptr, pIter uintptr, zCollist uintptr, zRbuRowid uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bRbuRowid int32
	var zBind uintptr
	_, _ = bRbuRowid, zBind
	bRbuRowid = libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE))
	zBind = _rbuObjIterGetBindlist(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+int32(1)+bRbuRowid)
	if zBind != 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+88, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+31907, libc.VaList(bp+8, p+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zCollist, zRbuRowid, zBind)))
	}
}

func _rbuTmpInsertFunc(tls *libc.TLS, pCtx uintptr, nVal int32, apVal uintptr) {
	var i, rc int32
	var p uintptr
	_, _, _ = i, p, rc
	p = Xsqlite3_user_data(tls, pCtx)
	rc = SQLITE_OK
	if Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal))) != 0 {
		*(*Ti64)(unsafe.Pointer(p + 176)) += int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
	}
	i = 0
	for {
		if !(rc == SQLITE_OK && i < nVal) {
			break
		}
		rc = Xsqlite3_bind_value(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpTmpInsert, i+int32(1), *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
	if rc == SQLITE_OK {
		Xsqlite3_step(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpTmpInsert)
		rc = Xsqlite3_reset(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpTmpInsert)
	}
	if rc != SQLITE_OK {
		Xsqlite3_result_error_code(tls, pCtx, rc)
	}
}

func _rbuObjIterGetIndexWhere(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aIdxCol, zRet, zSql, v1 uintptr
	var c int8
	var i, iIdxCol, nIdxAlloc, nParen, nSpan, nSpan1, rc2, v3, v4 int32
	var _ /* pStmt at bp+0 */ uintptr
	var _ /* rc at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aIdxCol, c, i, iIdxCol, nIdxAlloc, nParen, nSpan, nSpan1, rc2, zRet, zSql, v1, v3, v4
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 4)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	zRet = uintptr(0)
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 4)) = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, __ccgo_ts+31964)
	}
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 4)) = Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx, -int32(1), libc.UintptrFromInt32(0))
		if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			zSql = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			if zSql != 0 {
				v1 = _rbuStrndup(tls, zSql, bp+4)
				zSql = v1
				(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdxSql = v1
			}
			if zSql != 0 {
				nParen = 0
				iIdxCol = 0
				nIdxAlloc = 0
				i = 0
				for {
					if !(*(*int8)(unsafe.Pointer(zSql + uintptr(i))) != 0) {
						break
					}
					c = *(*int8)(unsafe.Pointer(zSql + uintptr(i)))
					/* If necessary, grow the pIter->aIdxCol[] array */
					if iIdxCol == nIdxAlloc {
						aIdxCol = Xsqlite3_realloc(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol, int32(uint32(nIdxAlloc+libc.Int32FromInt32(16))*uint32(8)))
						if aIdxCol == uintptr(0) {
							*(*int32)(unsafe.Pointer(bp + 4)) = int32(SQLITE_NOMEM)
							break
						}
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol = aIdxCol
						nIdxAlloc += int32(16)
					}
					if int32(int32(c)) == int32('(') {
						if nParen == 0 {
							(*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol))).FzSpan = zSql + uintptr(i+int32(1))
						}
						nParen++
					} else {
						if int32(int32(c)) == int32(')') {
							nParen--
							if nParen == 0 {
								nSpan = t__predefined_ptrdiff_t(zSql+uintptr(i)) - int32((*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*8))).FzSpan)
								v3 = iIdxCol
								iIdxCol++
								(*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(v3)*8))).FnSpan = nSpan
								i++
								break
							}
						} else {
							if int32(int32(c)) == int32(',') && nParen == int32(1) {
								nSpan1 = t__predefined_ptrdiff_t(zSql+uintptr(i)) - int32((*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*8))).FzSpan)
								v4 = iIdxCol
								iIdxCol++
								(*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(v4)*8))).FnSpan = nSpan1
								(*(*TRbuSpan)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*8))).FzSpan = zSql + uintptr(i+int32(1))
							} else {
								if int32(int32(c)) == int32('"') || int32(int32(c)) == int32('\'') || int32(int32(c)) == int32('`') {
									i++
									for {
										if !(int32(1) != 0) {
											break
										}
										if int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i)))) == int32(int32(c)) {
											if int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i+int32(1))))) != int32(int32(c)) {
												break
											}
											i++
										}
										goto _5
									_5:
										;
										i++
									}
								} else {
									if int32(int32(c)) == int32('[') {
										i++
										for {
											if !(int32(1) != 0) {
												break
											}
											if int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i)))) == int32(']') {
												break
											}
											goto _6
										_6:
											;
											i++
										}
									} else {
										if int32(int32(c)) == int32('-') && int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i+int32(1))))) == int32('-') {
											i = i + int32(2)
											for {
												if !(*(*int8)(unsafe.Pointer(zSql + uintptr(i))) != 0 && int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i)))) != int32('\n')) {
													break
												}
												goto _7
											_7:
												;
												i++
											}
											if int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i)))) == int32('\000') {
												break
											}
										} else {
											if int32(int32(c)) == int32('/') && int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i+int32(1))))) == int32('*') {
												i = i + int32(2)
												for {
													if !(*(*int8)(unsafe.Pointer(zSql + uintptr(i))) != 0 && (int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i)))) != int32('*') || int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i+int32(1))))) != int32('/'))) {
														break
													}
													goto _8
												_8:
													;
													i++
												}
												if int32(*(*int8)(unsafe.Pointer(zSql + uintptr(i)))) == int32('\000') {
													break
												}
												i++
											}
										}
									}
								}
							}
						}
					}
					goto _2
				_2:
					;
					i++
				}
				if *(*int8)(unsafe.Pointer(zSql + uintptr(i))) != 0 {
					zRet = _rbuStrndup(tls, zSql+uintptr(i), bp+4)
				}
				(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIdxCol = iIdxCol
			}
		}
		rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 4)) = rc2
		}
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = *(*int32)(unsafe.Pointer(bp + 4))
	return zRet
}

// C documentation
//
//	/*
//	** Ensure that the SQLite statement handles required to update the
//	** target database object currently indicated by the iterator passed
//	** as the second argument are available.
//	*/
func _rbuObjIterPrepareAll(tls *libc.TLS, p uintptr, pIter uintptr, nOffset int32) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var bRbuRowid, tnum int32
	var pz, zBind, zBindings, zCollist, zIdx, zLimit, zNewlist, zOldlist, zOrder, zPart, zRbuRowid, zRbuRowid1, zSql, zStart, zStart1, zTbl, zTbl1, zWhere1, zWrite, v1, v10, v2, v3, v4, v5, v6, v7, v8, v9 uintptr
	var _ /* nBind at bp+12 */ int32
	var _ /* zImposterCols at bp+0 */ uintptr
	var _ /* zImposterPK at bp+4 */ uintptr
	var _ /* zWhere at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bRbuRowid, pz, tnum, zBind, zBindings, zCollist, zIdx, zLimit, zNewlist, zOldlist, zOrder, zPart, zRbuRowid, zRbuRowid1, zSql, zStart, zStart1, zTbl, zTbl1, zWhere1, zWrite, v1, v10, v2, v3, v4, v5, v6, v7, v8, v9
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect == uintptr(0) && _rbuObjIterCacheTableInfo(tls, p, pIter) == SQLITE_OK {
		tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum
		zCollist = uintptr(0) /* List of indexed columns */
		pz = p + 36
		zIdx = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx
		zLimit = uintptr(0)
		if nOffset != 0 {
			zLimit = Xsqlite3_mprintf(tls, __ccgo_ts+32030, libc.VaList(bp+24, nOffset))
			if !(zLimit != 0) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
			}
		}
		if zIdx != 0 {
			zTbl = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)     /* Columns for imposter table */
			*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* Primary key declaration for imposter */
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0) /* WHERE clause on PK columns */
			zBind = uintptr(0)
			zPart = uintptr(0)
			*(*int32)(unsafe.Pointer(bp + 12)) = 0
			zPart = _rbuObjIterGetIndexWhere(tls, p, pIter)
			zCollist = _rbuObjIterGetIndexCols(tls, p, pIter, bp, bp+4, bp+8, bp+12)
			zBind = _rbuObjIterGetBindlist(tls, p, *(*int32)(unsafe.Pointer(bp + 12)))
			/* Create the imposter table used to write to this index. */
			Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+24, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, 0, int32(1)))
			Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+24, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, int32(1), tnum))
			_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32050, libc.VaList(bp+24, zTbl, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 4))))
			Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+24, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, 0, 0))
			/* Create the statement to insert index entries */
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol = *(*int32)(unsafe.Pointer(bp + 12))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+80, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+32115, libc.VaList(bp+24, zTbl, zBind)))
			}
			/* And to delete index entries */
			if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+84, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+32151, libc.VaList(bp+24, zTbl, *(*uintptr)(unsafe.Pointer(bp + 8)))))
			}
			/* Create the SELECT statement to read keys in sorted order */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					zStart = uintptr(0)
					if nOffset != 0 {
						zStart = _rbuVacuumIndexStart(tls, p, pIter)
						if zStart != 0 {
							Xsqlite3_free(tls, zLimit)
							zLimit = uintptr(0)
						}
					}
					if zStart != 0 {
						if zPart != 0 {
							v2 = __ccgo_ts + 32185
						} else {
							v2 = __ccgo_ts + 32189
						}
						v1 = v2
					} else {
						v1 = __ccgo_ts + 1672
					}
					zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32195, libc.VaList(bp+24, zCollist, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, v1, zStart, zCollist, zLimit))
					Xsqlite3_free(tls, zStart)
				} else {
					if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
						zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32256, libc.VaList(bp+24, zCollist, p+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, zCollist, zLimit))
					} else {
						if zPart != 0 {
							v3 = __ccgo_ts + 32185
						} else {
							v3 = __ccgo_ts + 32189
						}
						zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32317, libc.VaList(bp+24, zCollist, p+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, zCollist, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, v3, zCollist, zLimit))
					}
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+76, pz, zSql)
				} else {
					Xsqlite3_free(tls, zSql)
				}
			}
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
			Xsqlite3_free(tls, zBind)
			Xsqlite3_free(tls, zPart)
		} else {
			bRbuRowid = libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0))
			zTbl1 = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl /* Imposter table name */
			zBindings = _rbuObjIterGetBindlist(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+bRbuRowid)
			zWhere1 = _rbuObjIterGetWhere(tls, p, pIter)
			zOldlist = _rbuObjIterGetOldlist(tls, p, pIter, __ccgo_ts+7969)
			zNewlist = _rbuObjIterGetOldlist(tls, p, pIter, __ccgo_ts+7965)
			zCollist = _rbuObjIterGetCollist(tls, p, pIter)
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol
			/* Create the imposter table or tables (if required). */
			_rbuCreateImposterTable(tls, p, pIter)
			_rbuCreateImposterTable2(tls, p, pIter)
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) {
				v4 = __ccgo_ts + 1672
			} else {
				v4 = __ccgo_ts + 32476
			}
			zWrite = v4
			/* Create the INSERT statement to write to the target PK b-tree */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if bRbuRowid != 0 {
					v5 = __ccgo_ts + 32485
				} else {
					v5 = __ccgo_ts + 1672
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+80, pz, Xsqlite3_mprintf(tls, __ccgo_ts+32495, libc.VaList(bp+24, zWrite, zTbl1, zCollist, v5, zBindings)))
			}
			/* Create the DELETE statement to write to the target PK b-tree.
			 ** Because it only performs INSERT operations, this is not required for
			 ** an rbu vacuum handle.  */
			if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+84, pz, Xsqlite3_mprintf(tls, __ccgo_ts+32531, libc.VaList(bp+24, zWrite, zTbl1, zWhere1)))
			}
			if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
				zRbuRowid = __ccgo_ts + 1672
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
					zRbuRowid = __ccgo_ts + 32559
				}
				/* Create the rbu_tmp_xxx table and the triggers to populate it. */
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
					v6 = __ccgo_ts + 32571
				} else {
					v6 = __ccgo_ts + 1672
				}
				_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+32588, libc.VaList(bp+24, p+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v6, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))
				_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32664, libc.VaList(bp+24, zWrite, zTbl1, zOldlist, zWrite, zTbl1, zOldlist, zWrite, zTbl1, zNewlist))
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
					_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32963, libc.VaList(bp+24, zWrite, zTbl1, zNewlist))
				}
				_rbuObjIterPrepareTmpInsert(tls, p, pIter, zCollist, zRbuRowid)
			}
			/* Create the SELECT statement to read keys from data_xxx */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				zRbuRowid1 = __ccgo_ts + 1672
				zStart1 = uintptr(0)
				zOrder = uintptr(0)
				if bRbuRowid != 0 {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						v7 = __ccgo_ts + 33062
					} else {
						v7 = __ccgo_ts + 33072
					}
					zRbuRowid1 = v7
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					if nOffset != 0 {
						zStart1 = _rbuVacuumTableStart(tls, p, pIter, bRbuRowid, zWrite)
						if zStart1 != 0 {
							Xsqlite3_free(tls, zLimit)
							zLimit = uintptr(0)
						}
					}
					if bRbuRowid != 0 {
						zOrder = _rbuMPrintf(tls, p, __ccgo_ts+31119, 0)
					} else {
						zOrder = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1672, __ccgo_ts+16397, __ccgo_ts+1672)
					}
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						v8 = __ccgo_ts + 33083
					} else {
						v8 = __ccgo_ts + 1672
					}
					if zStart1 != 0 {
						v9 = zStart1
					} else {
						v9 = __ccgo_ts + 1672
					}
					if zOrder != 0 {
						v10 = __ccgo_ts + 24678
					} else {
						v10 = __ccgo_ts + 1672
					}
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+76, pz, Xsqlite3_mprintf(tls, __ccgo_ts+33089, libc.VaList(bp+24, zCollist, v8, zRbuRowid1, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v9, v10, zOrder, zLimit)))
				}
				Xsqlite3_free(tls, zStart1)
				Xsqlite3_free(tls, zOrder)
			}
			Xsqlite3_free(tls, zWhere1)
			Xsqlite3_free(tls, zOldlist)
			Xsqlite3_free(tls, zNewlist)
			Xsqlite3_free(tls, zBindings)
		}
		Xsqlite3_free(tls, zCollist)
		Xsqlite3_free(tls, zLimit)
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Set output variable *ppStmt to point to an UPDATE statement that may
//	** be used to update the imposter table for the main table b-tree of the
//	** table object that pIter currently points to, assuming that the
//	** rbu_control column of the data_xyz table contains zMask.
//	**
//	** If the zMask string does not specify any columns to update, then this
//	** is not an error. Output variable *ppStmt is set to NULL in this case.
//	*/
func _rbuGetUpdateStmt(tls *libc.TLS, p uintptr, pIter uintptr, zMask uintptr, ppStmt uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var nUp int32
	var pUp, pp, zPrefix, zSet, zUpdate, zWhere uintptr
	_, _, _, _, _, _, _ = nUp, pUp, pp, zPrefix, zSet, zUpdate, zWhere
	pUp = uintptr(0)
	nUp = 0
	/* In case an error occurs */
	*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	/* Search for an existing statement. If one is found, shift it to the front
	 ** of the LRU queue and return immediately. Otherwise, leave nUp pointing
	 ** to the number of statements currently in the cache and pUp to the
	 ** last object in the list.  */
	pp = pIter + 104
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != 0) {
			break
		}
		pUp = *(*uintptr)(unsafe.Pointer(pp))
		if libc.Xstrcmp(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask) == 0 {
			*(*uintptr)(unsafe.Pointer(pp)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext
			(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp
			*(*uintptr)(unsafe.Pointer(ppStmt)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
			return SQLITE_OK
		}
		nUp++
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 8
	}
	if nUp >= int32(SQLITE_RBU_UPDATE_CACHESIZE) {
		pp = pIter + 104
		for {
			if !(*(*uintptr)(unsafe.Pointer(pp)) != pUp) {
				break
			}
			goto _2
		_2:
			;
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 8
		}
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
		Xsqlite3_finalize(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate)
		(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate = uintptr(0)
	} else {
		pUp = _rbuMalloc(tls, p, int64(uint32(12)+uint32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)+uint32(1)))
	}
	if pUp != 0 {
		zWhere = _rbuObjIterGetWhere(tls, p, pIter)
		zSet = _rbuObjIterGetSetlist(tls, p, pIter, zMask)
		zUpdate = uintptr(0)
		(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask = pUp + 1*12
		libc.Xmemcpy(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask, uint32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp
		if zSet != 0 {
			zPrefix = __ccgo_ts + 1672
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType != int32(RBU_PK_VTAB) {
				zPrefix = __ccgo_ts + 32476
			}
			zUpdate = Xsqlite3_mprintf(tls, __ccgo_ts+33137, libc.VaList(bp+8, zPrefix, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSet, zWhere))
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pUp+4, p+36, zUpdate)
			*(*uintptr)(unsafe.Pointer(ppStmt)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
		}
		Xsqlite3_free(tls, zWhere)
		Xsqlite3_free(tls, zSet)
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

func _rbuOpenDbhandle(tls *libc.TLS, p uintptr, zName uintptr, bUseVfs int32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var flags int32
	var v1 uintptr
	var _ /* db at bp+0 */ uintptr
	_, _ = flags, v1
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		flags = libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_URI)
		if bUseVfs != 0 {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FzVfsName
		} else {
			v1 = uintptr(0)
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_open_v2(tls, zName, bp, flags, v1)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+16, Xsqlite3_errmsg(tls, *(*uintptr)(unsafe.Pointer(bp)))))
			Xsqlite3_close(tls, *(*uintptr)(unsafe.Pointer(bp)))
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		}
	}
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Free an RbuState object allocated by rbuLoadState().
//	*/
func _rbuFreeState(tls *libc.TLS, p uintptr) {
	if p != 0 {
		Xsqlite3_free(tls, (*TRbuState)(unsafe.Pointer(p)).FzTbl)
		Xsqlite3_free(tls, (*TRbuState)(unsafe.Pointer(p)).FzDataTbl)
		Xsqlite3_free(tls, (*TRbuState)(unsafe.Pointer(p)).FzIdx)
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Allocate an RbuState object and load the contents of the rbu_state
//	** table into it. Return a pointer to the new object. It is the
//	** responsibility of the caller to eventually free the object using
//	** sqlite3_free().
//	**
//	** If an error occurs, leave an error code and message in the rbu handle
//	** and return NULL.
//	*/
func _rbuLoadState(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pRet uintptr
	var rc2 int32
	var _ /* pStmt at bp+0 */ uintptr
	var _ /* rc at bp+4 */ int32
	_, _ = pRet, rc2
	pRet = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pRet = _rbuMalloc(tls, p, int64(64))
	if pRet == uintptr(0) {
		return uintptr(0)
	}
	*(*int32)(unsafe.Pointer(bp + 4)) = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+33167, libc.VaList(bp+16, p+24)))
	for *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
		switch Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 0) {
		case int32(RBU_STATE_STAGE):
			(*TRbuState)(unsafe.Pointer(pRet)).FeStage = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
			if (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_OAL) && (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_MOVE) && (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_CKPT) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_CORRUPT)
			}
		case int32(RBU_STATE_TBL):
			(*TRbuState)(unsafe.Pointer(pRet)).FzTbl = _rbuStrndup(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1)), bp+4)
		case int32(RBU_STATE_IDX):
			(*TRbuState)(unsafe.Pointer(pRet)).FzIdx = _rbuStrndup(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1)), bp+4)
		case int32(RBU_STATE_ROW):
			(*TRbuState)(unsafe.Pointer(pRet)).FnRow = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		case int32(RBU_STATE_PROGRESS):
			(*TRbuState)(unsafe.Pointer(pRet)).FnProgress = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		case int32(RBU_STATE_CKPT):
			(*TRbuState)(unsafe.Pointer(pRet)).FiWalCksum = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		case int32(RBU_STATE_COOKIE):
			(*TRbuState)(unsafe.Pointer(pRet)).FiCookie = uint32(Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1)))
		case int32(RBU_STATE_OALSZ):
			(*TRbuState)(unsafe.Pointer(pRet)).FiOalSz = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		case int32(RBU_STATE_PHASEONESTEP):
			(*TRbuState)(unsafe.Pointer(pRet)).FnPhaseOneStep = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		case int32(RBU_STATE_DATATBL):
			(*TRbuState)(unsafe.Pointer(pRet)).FzDataTbl = _rbuStrndup(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1)), bp+4)
		default:
			*(*int32)(unsafe.Pointer(bp + 4)) = int32(SQLITE_CORRUPT)
			break
		}
	}
	rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 4)) = rc2
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = *(*int32)(unsafe.Pointer(bp + 4))
	return pRet
}

// C documentation
//
//	/*
//	** Open the database handle and attach the RBU database as "rbu". If an
//	** error occurs, leave an error code and message in the RBU handle.
//	**
//	** If argument dbMain is not NULL, then it is a database handle already
//	** open on the target database. Use this handle instead of opening a new
//	** one.
//	*/
func _rbuOpenDatabase(tls *libc.TLS, p uintptr, dbMain uintptr, pbRetry uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bOpen, rc int32
	var pState, zExtra, zFile, zTarget, v1, v2, v3 uintptr
	_, _, _, _, _, _, _, _, _ = bOpen, pState, rc, zExtra, zFile, zTarget, v1, v2, v3
	/* Open the RBU database */
	(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, int32(1))
	(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = dbMain
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+7958, int32(SQLITE_FCNTL_RBUCNT), p)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState == uintptr(0) {
			zFile = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+7958)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzState = _rbuMPrintf(tls, p, __ccgo_ts+33197, libc.VaList(bp+8, zFile, zFile))
		}
	}
	/* If using separate RBU and state databases, attach the state database to
	 ** the RBU db handle now.  */
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState != 0 {
		_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33225, libc.VaList(bp+8, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState))
		libc.Xmemcpy(tls, p+24, __ccgo_ts+15255, uint32(4))
	} else {
		libc.Xmemcpy(tls, p+24, __ccgo_ts+7958, uint32(4))
	}
	/* If it has not already been created, create the rbu_state table */
	_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33243, libc.VaList(bp+8, p+24))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		bOpen = 0
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FnRbu = 0
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd = uintptr(0)
		rc = Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+7958, int32(SQLITE_FCNTL_RBUCNT), p)
		if rc != int32(SQLITE_NOTFOUND) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage >= int32(RBU_STAGE_MOVE) {
			bOpen = int32(1)
		} else {
			pState = _rbuLoadState(tls, p)
			if pState != 0 {
				bOpen = libc.BoolInt32((*TRbuState)(unsafe.Pointer(pState)).FeStage >= int32(RBU_STAGE_MOVE))
				_rbuFreeState(tls, pState)
			}
		}
		if bOpen != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnRbu <= int32(1)))
		}
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = 0
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain == uintptr(0) {
		if !((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == libc.UintptrFromInt32(0)) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, int32(1))
		} else {
			if (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd)).FpWalFd != 0 {
				if pbRetry != 0 {
					(*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd)).FbNolock = uint8(0)
					Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
					Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = uintptr(0)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu = uintptr(0)
					*(*int32)(unsafe.Pointer(pbRetry)) = int32(1)
					return
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+33309, 0)
			} else {
				zExtra = uintptr(0)
				if libc.Xstrlen(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu) >= uint32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+26045, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, uint32(5)) {
					zExtra = (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu + 5
					for *(*int8)(unsafe.Pointer(zExtra)) != 0 {
						v1 = zExtra
						zExtra++
						if int32(*(*int8)(unsafe.Pointer(v1))) == int32('?') {
							break
						}
					}
					if int32(*(*int8)(unsafe.Pointer(zExtra))) == int32('\000') {
						zExtra = uintptr(0)
					}
				}
				if zExtra == uintptr(0) {
					v2 = __ccgo_ts + 1672
				} else {
					v2 = __ccgo_ts + 33341
				}
				if zExtra == uintptr(0) {
					v3 = __ccgo_ts + 1672
				} else {
					v3 = zExtra
				}
				zTarget = Xsqlite3_mprintf(tls, __ccgo_ts+33343, libc.VaList(bp+8, Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+7958), v2, v3))
				if zTarget == uintptr(0) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
					return
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = _rbuOpenDbhandle(tls, p, zTarget, libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnRbu <= int32(1)))
				Xsqlite3_free(tls, zTarget)
			}
		}
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33375, -int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_rbuTmpInsertFunc), uintptr(0), uintptr(0))
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33390, int32(2), int32(SQLITE_UTF8), uintptr(0), __ccgo_fp(_rbuFossilDeltaFunc), uintptr(0), uintptr(0))
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33407, -int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_rbuTargetNameFunc), uintptr(0), uintptr(0))
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, int32(SQLITE_FCNTL_RBU), p)
	}
	_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33423, 0)
	/* Mark the database file just opened as an RBU target database. If
	 ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
	 ** This is an error.  */
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, int32(SQLITE_FCNTL_RBU), p)
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_NOTFOUND) {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+33451, 0)
	}
}

// C documentation
//
//	/*
//	** This routine is a copy of the sqlite3FileSuffix3() routine from the core.
//	** It is a no-op unless SQLITE_ENABLE_8_3_NAMES is defined.
//	**
//	** If SQLITE_ENABLE_8_3_NAMES is set at compile-time and if the database
//	** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
//	** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
//	** three characters, then shorten the suffix on z[] to be the last three
//	** characters of the original suffix.
//	**
//	** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
//	** do the suffix shortening regardless of URI parameter.
//	**
//	** Examples:
//	**
//	**     test.db-journal    =>   test.nal
//	**     test.db-wal        =>   test.wal
//	**     test.db-shm        =>   test.shm
//	**     test.db-mj7f3319fa =>   test.9fa
//	*/
func _rbuFileSuffix3(tls *libc.TLS, zBase uintptr, z uintptr) {
}

// C documentation
//
//	/*
//	** Return the current wal-index header checksum for the target database
//	** as a 64-bit integer.
//	**
//	** The checksum is store in the first page of xShmMap memory as an 8-byte
//	** blob starting at byte offset 40.
//	*/
func _rbuShmChecksum(tls *libc.TLS, p uintptr) (r Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iRet Ti64
	var pDb uintptr
	var _ /* ptr at bp+0 */ uintptr
	_, _ = iRet, pDb
	iRet = 0
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxShmMap})))(tls, pDb, 0, libc.Int32FromInt32(32)*libc.Int32FromInt32(1024), 0, bp)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			iRet = int64(uint64(libc.AtomicLoadPUint32(*(*uintptr)(unsafe.Pointer(bp))+libc.UintptrFromInt32(10)*4))<<libc.Int32FromInt32(32) + uint64(libc.AtomicLoadPUint32(*(*uintptr)(unsafe.Pointer(bp))+11*4)))
		}
	}
	return iRet
}

// C documentation
//
//	/*
//	** This function is called as part of initializing or reinitializing an
//	** incremental checkpoint.
//	**
//	** It populates the sqlite3rbu.aFrame[] array with the set of
//	** (wal frame -> db page) copy operations required to checkpoint the
//	** current wal file, and obtains the set of shm locks required to safely
//	** perform the copy operations directly on the file-system.
//	**
//	** If argument pState is not NULL, then the incremental checkpoint is
//	** being resumed. In this case, if the checksum of the wal-index-header
//	** following recovery is not the same as the checksum saved in the RbuState
//	** object, then the rbu handle is set to DONE state. This occurs if some
//	** other client appends a transaction to the wal file in the middle of
//	** an incremental checkpoint.
//	*/
func _rbuSetupCheckpoint(tls *libc.TLS, p uintptr, pState uintptr) {
	var nSectorSize, rc2, v1 int32
	var pDb, pWal uintptr
	_, _, _, _, _ = nSectorSize, pDb, pWal, rc2, v1
	/* If pState is NULL, then the wal file may not have been opened and
	 ** recovered. Running a read-statement here to ensure that doing so
	 ** does not interfere with the "capture" process below.  */
	if pState == uintptr(0) {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = 0
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33423, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	/* Assuming no error has occurred, run a "restart" checkpoint with the
	 ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
	 ** special behaviour in the rbu VFS:
	 **
	 **   * If the exclusive shm WRITER or READ0 lock cannot be obtained,
	 **     the checkpoint fails with SQLITE_BUSY (normally SQLite would
	 **     proceed with running a passive checkpoint instead of failing).
	 **
	 **   * Attempts to read from the *-wal file or write to the database file
	 **     do not perform any IO. Instead, the frame/page combinations that
	 **     would be read/written are recorded in the sqlite3rbu.aFrame[]
	 **     array.
	 **
	 **   * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
	 **     READ0 and CHECKPOINT locks taken as part of the checkpoint are
	 **     no-ops. These locks will not be released until the connection
	 **     is closed.
	 **
	 **   * Attempting to xSync() the database file causes an SQLITE_NOTICE
	 **     error.
	 **
	 ** As a result, unless an error (i.e. OOM or SQLITE_BUSY) occurs, the
	 ** checkpoint below fails with SQLITE_NOTICE, and leaves the aFrame[]
	 ** array populated with a set of (frame -> page) mappings. Because the
	 ** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy
	 ** data from the wal file into the database file according to the
	 ** contents of aFrame[].
	 */
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CAPTURE)
		rc2 = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33469, uintptr(0), uintptr(0), uintptr(0))
		if rc2 != int32(SQLITE_NOTICE) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc2
		}
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame > 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
		if pState != 0 {
			v1 = (*TRbuState)(unsafe.Pointer(pState)).FnRow
		} else {
			v1 = 0
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = v1
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FaBuf = _rbuMalloc(tls, p, int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum = _rbuShmChecksum(tls, p)
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame == 0 || pState != 0 && (*TRbuState)(unsafe.Pointer(pState)).FiWalCksum != (*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
		} else {
			pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
			pWal = (*Trbu_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd)).FpReal
			nSectorSize = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSectorSize})))(tls, pDb)
			if nSectorSize > (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = nSectorSize / (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz
			} else {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = int32(1)
			}
			/* Call xSync() on the wal file. This causes SQLite to sync the
			 ** directory in which the target database and the wal file reside, in
			 ** case it has not been synced since the rename() call in
			 ** rbuMoveOalFile(). */
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pWal)).FpMethods)).FxSync})))(tls, pWal, int32(SQLITE_SYNC_NORMAL))
		}
	}
}

// C documentation
//
//	/*
//	** Called when iAmt bytes are read from offset iOff of the wal file while
//	** the rbu object is in capture mode. Record the frame number of the frame
//	** being read in the aFrame[] array.
//	*/
func _rbuCaptureWalRead(tls *libc.TLS, pRbu uintptr, iOff Ti64, iAmt int32) (r int32) {
	var aNew uintptr
	var iFrame, mReq Tu32
	var nNew, v1 int32
	_, _, _, _, _ = aNew, iFrame, mReq, nNew, v1
	mReq = uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(WAL_LOCK_WRITE) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(WAL_LOCK_CKPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(WAL_LOCK_READ0))
	if (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FmLock != mReq {
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).Frc = int32(SQLITE_BUSY)
		return libc.Int32FromInt32(SQLITE_NOTICE) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
	}
	(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).Fpgsz = iAmt
	if (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame == (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc {
		if (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc != 0 {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc
		} else {
			v1 = int32(64)
		}
		nNew = v1 * int32(2)
		aNew = Xsqlite3_realloc64(tls, (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame, uint64(uint32(uint32(nNew))*uint32(8)))
		if aNew == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame = aNew
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc = nNew
	}
	iFrame = uint32((iOff-libc.Int64FromInt32(32))/int64(iAmt+libc.Int32FromInt32(24))) + uint32(1)
	if (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FiMaxFrame < iFrame {
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FiMaxFrame = iFrame
	}
	(*(*TRbuFrame)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame)*8))).FiWalFrame = iFrame
	(*(*TRbuFrame)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame)*8))).FiDbPage = uint32(0)
	(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame++
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Called when a page of data is written to offset iOff of the database
//	** file while the rbu handle is in capture mode. Record the page number
//	** of the page being written in the aFrame[] array.
//	*/
func _rbuCaptureDbWrite(tls *libc.TLS, pRbu uintptr, iOff Ti64) (r int32) {
	(*(*TRbuFrame)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame-int32(1))*8))).FiDbPage = uint32(iOff/int64((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).Fpgsz)) + uint32(1)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This is called as part of an incremental checkpoint operation. Copy
//	** a single frame of data from the wal file into the database file, as
//	** indicated by the RbuFrame object.
//	*/
func _rbuCheckpointFrame(tls *libc.TLS, p uintptr, pFrame uintptr) {
	var iOff Ti64
	var pDb, pWal uintptr
	_, _, _ = iOff, pDb, pWal
	pWal = (*Trbu_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd)).FpReal
	pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
	iOff = int64((*TRbuFrame)(unsafe.Pointer(pFrame)).FiWalFrame-libc.Uint32FromInt32(1))*int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz+libc.Int32FromInt32(24)) + int64(32) + int64(24)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pWal)).FpMethods)).FxRead})))(tls, pWal, (*Tsqlite3rbu)(unsafe.Pointer(p)).FaBuf, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz, iOff)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
		return
	}
	iOff = int64((*TRbuFrame)(unsafe.Pointer(pFrame)).FiDbPage-libc.Uint32FromInt32(1)) * int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxWrite})))(tls, pDb, (*Tsqlite3rbu)(unsafe.Pointer(p)).FaBuf, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz, iOff)
}

/*
** This value is copied from the definition of ZIPVFS_CTRL_FILE_POINTER
** in zipvfs.h.
 */

// C documentation
//
//	/*
//	** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if
//	** successful, or an SQLite error code otherwise.
//	*/
func _rbuLockDatabase(tls *libc.TLS, db uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* fd at bp+0 */ uintptr
	_ = rc
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	Xsqlite3_file_control(tls, db, __ccgo_ts+7958, int32(RBU_ZIPVFS_CTRL_FILE_POINTER), bp)
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		Xsqlite3_file_control(tls, db, __ccgo_ts+7958, int32(SQLITE_FCNTL_FILE_POINTER), bp)
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods)).FxLock})))(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(SQLITE_LOCK_SHARED))
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods)).FxUnlock})))(tls, *(*uintptr)(unsafe.Pointer(bp)), SQLITE_LOCK_NONE)
		}
		Xsqlite3_file_control(tls, db, __ccgo_ts+7958, int32(RBU_ZIPVFS_CTRL_FILE_POINTER), bp)
	} else {
		Xsqlite3_file_control(tls, db, __ccgo_ts+7958, int32(SQLITE_FCNTL_FILE_POINTER), bp)
	}
	if rc == SQLITE_OK && (*Tsqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods != 0 {
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods)).FxLock})))(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(SQLITE_LOCK_SHARED))
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods)).FxLock})))(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(SQLITE_LOCK_EXCLUSIVE))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if the database handle passed as the only argument
//	** was opened with the rbu_exclusive_checkpoint=1 URI parameter
//	** specified. Or false otherwise.
//	*/
func _rbuExclusiveCheckpoint(tls *libc.TLS, db uintptr) (r int32) {
	var zUri uintptr
	_ = zUri
	zUri = Xsqlite3_db_filename(tls, db, uintptr(0))
	return Xsqlite3_uri_boolean(tls, zUri, __ccgo_ts+33504, 0)
}

// C documentation
//
//	/*
//	** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock
//	** on the database file. This proc moves the *-oal file to the *-wal path,
//	** then reopens the database file (this time in vanilla, non-oal, WAL mode).
//	** If an error occurs, leave an error code and error message in the rbu
//	** handle.
//	*/
func _rbuMoveOalFile(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var dbMain, zBase, zMove, zOal, zWal uintptr
	_, _, _, _, _ = dbMain, zBase, zMove, zOal, zWal
	zBase = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958)
	zMove = zBase
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		zMove = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+7958)
	}
	zOal = Xsqlite3_mprintf(tls, __ccgo_ts+33529, libc.VaList(bp+8, zMove))
	zWal = Xsqlite3_mprintf(tls, __ccgo_ts+33536, libc.VaList(bp+8, zMove))
	if zWal == uintptr(0) || zOal == uintptr(0) {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
	} else {
		/* Move the *-oal file to *-wal. At this point connection p->db is
		 ** holding a SHARED lock on the target database file (because it is
		 ** in WAL mode). So no other connection may be writing the db.
		 **
		 ** In order to ensure that there are no database readers, an EXCLUSIVE
		 ** lock is obtained here before the *-oal is moved to *-wal.
		 */
		dbMain = uintptr(0)
		_rbuFileSuffix3(tls, zBase, zWal)
		_rbuFileSuffix3(tls, zBase, zOal)
		/* Re-open the databases. */
		_rbuObjIterFinalize(tls, p+48)
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = uintptr(0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu = uintptr(0)
		dbMain = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, int32(1))
		if dbMain != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuLockDatabase(tls, dbMain)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3rbu)(unsafe.Pointer(p)).FxRename})))(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRenameArg, zOal, zWal)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK || (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) || _rbuExclusiveCheckpoint(tls, dbMain) == 0 {
			Xsqlite3_close(tls, dbMain)
			dbMain = uintptr(0)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			_rbuOpenDatabase(tls, p, dbMain, uintptr(0))
			_rbuSetupCheckpoint(tls, p, uintptr(0))
		}
	}
	Xsqlite3_free(tls, zWal)
	Xsqlite3_free(tls, zOal)
}

// C documentation
//
//	/*
//	** The SELECT statement iterating through the keys for the current object
//	** (p->objiter.pSelect) currently points to a valid row. This function
//	** determines the type of operation requested by this row and returns
//	** one of the following values to indicate the result:
//	**
//	**     * RBU_INSERT
//	**     * RBU_DELETE
//	**     * RBU_IDX_DELETE
//	**     * RBU_UPDATE
//	**
//	** If RBU_UPDATE is returned, then output variable *pzMask is set to
//	** point to the text value indicating the columns to update.
//	**
//	** If the rbu_control field contains an invalid value, an error code and
//	** message are left in the RBU handle and zero returned.
//	*/
func _rbuStepType(tls *libc.TLS, p uintptr, pzMask uintptr) (r int32) {
	var iCol, iVal, res int32
	var z uintptr
	_, _, _, _ = iCol, iVal, res, z
	iCol = (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnCol /* Index of rbu_control column */
	res = 0                                                 /* Return value */
	switch Xsqlite3_column_type(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpSelect, iCol) {
	case int32(SQLITE_INTEGER):
		iVal = Xsqlite3_column_int(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpSelect, iCol)
		switch iVal {
		case 0:
			res = int32(RBU_INSERT)
		case int32(1):
			res = int32(RBU_DELETE)
		case int32(2):
			res = int32(RBU_REPLACE)
		case int32(3):
			res = int32(RBU_IDX_DELETE)
		case int32(4):
			res = int32(RBU_IDX_INSERT)
			break
		}
	case int32(SQLITE_TEXT):
		z = Xsqlite3_column_text(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpSelect, iCol)
		if z == uintptr(0) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		} else {
			*(*uintptr)(unsafe.Pointer(pzMask)) = z
		}
		res = int32(RBU_UPDATE)
	default:
		break
	}
	if res == 0 {
		_rbuBadControlError(tls, p)
	}
	return res
}

// C documentation
//
//	/*
//	** Argument eType must be one of RBU_INSERT, RBU_DELETE, RBU_IDX_INSERT or
//	** RBU_IDX_DELETE. This function performs the work of a single
//	** sqlite3rbu_step() call for the type of operation specified by eType.
//	*/
func _rbuStepOneOp(tls *libc.TLS, p uintptr, eType int32) {
	var i int32
	var pIter, pVal, pWriter uintptr
	_, _, _, _ = i, pIter, pVal, pWriter
	pIter = p + 48
	/* If this is a delete, decrement nPhaseOneStep by nIndex. If the DELETE
	 ** statement below does actually delete a row, nPhaseOneStep will be
	 ** incremented by the same amount when SQL function rbu_tmp_insert()
	 ** is invoked by the trigger.  */
	if eType == int32(RBU_DELETE) {
		*(*Ti64)(unsafe.Pointer(p + 176)) -= int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
	}
	if eType == int32(RBU_IDX_DELETE) || eType == int32(RBU_DELETE) {
		pWriter = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpDelete
	} else {
		pWriter = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpInsert
	}
	i = 0
	for {
		if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
			break
		}
		/* If this is an INSERT into a table b-tree and the table has an
		 ** explicit INTEGER PRIMARY KEY, check that this is not an attempt
		 ** to write a NULL into the IPK column. That is not permitted.  */
		if eType == int32(RBU_INSERT) && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) && *(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 && Xsqlite3_column_type(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i) == int32(SQLITE_NULL) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_MISMATCH)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+25602, 0)
			return
		}
		if eType == int32(RBU_DELETE) && int32(*(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0 {
			goto _1
		}
		pVal = Xsqlite3_column_value(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, pWriter, i+int32(1), pVal)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
		goto _1
	_1:
		;
		i++
	}
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			/* For a virtual table, or a table with no primary key, the
			 ** SELECT statement is:
			 **
			 **   SELECT <cols>, rbu_control, rbu_rowid FROM ....
			 **
			 ** Hence column_value(pIter->nCol+1).
			 */
			pVal = Xsqlite3_column_value(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1))
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, pWriter, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1), pVal)
		}
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		Xsqlite3_step(tls, pWriter)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _resetAndCollectError(tls, pWriter, p+36)
	}
}

// C documentation
//
//	/*
//	** This function does the work for an sqlite3rbu_step() call.
//	**
//	** The object-iterator (p->objiter) currently points to a valid object,
//	** and the input cursor (p->objiter.pSelect) currently points to a valid
//	** input row. Perform whatever processing is required and return.
//	**
//	** If no  error occurs, SQLITE_OK is returned. Otherwise, an error code
//	** and message is left in the RBU handle and a copy of the error code
//	** returned.
//	*/
func _rbuStep(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c int8
	var eType, i int32
	var pIter, pVal uintptr
	var _ /* pUpdate at bp+4 */ uintptr
	var _ /* zMask at bp+0 */ uintptr
	_, _, _, _, _ = c, eType, i, pIter, pVal
	pIter = p + 48
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	eType = _rbuStepType(tls, p, bp)
	if eType != 0 {
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) && (eType == int32(RBU_IDX_DELETE) || eType == int32(RBU_IDX_INSERT)) {
			_rbuBadControlError(tls, p)
		} else {
			if eType == int32(RBU_REPLACE) {
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
					*(*Ti64)(unsafe.Pointer(p + 176)) += int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
					_rbuStepOneOp(tls, p, int32(RBU_DELETE))
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					_rbuStepOneOp(tls, p, int32(RBU_INSERT))
				}
			} else {
				if eType != int32(RBU_UPDATE) {
					_rbuStepOneOp(tls, p, eType)
				} else {
					*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
					*(*Ti64)(unsafe.Pointer(p + 176)) -= int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
					_rbuGetUpdateStmt(tls, p, pIter, *(*uintptr)(unsafe.Pointer(bp)), bp+4)
					if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
						i = 0
						for {
							if !((*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
								break
							}
							c = *(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(*(*int32)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)))))
							pVal = Xsqlite3_column_value(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i)
							if *(*Tu8)(unsafe.Pointer((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 || int32(int32(c)) != int32('.') {
								(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), i+int32(1), pVal)
							}
							goto _1
						_1:
							;
							i++
						}
						if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && ((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE)) {
							/* Bind the rbu_rowid value to column _rowid_ */
							pVal = Xsqlite3_column_value(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1))
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1), pVal)
						}
						if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _resetAndCollectError(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), p+36)
						}
					}
				}
			}
		}
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Increment the schema cookie of the main database opened by p->dbMain.
//	**
//	** Or, if this is an RBU vacuum, set the schema cookie of the main db
//	** opened by p->dbMain to one more than the schema cookie of the main
//	** db opened by p->dbRbu.
//	*/
func _rbuIncrSchemaCookie(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var dbread, v1 uintptr
	var iCookie int32
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _ = dbread, iCookie, v1
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu
		} else {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
		}
		dbread = v1
		iCookie = int32(1000000)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, dbread, bp, p+36, __ccgo_ts+33543)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			/* Coverage: it may be that this sqlite3_step() cannot fail. There
			 ** is already a transaction open, so the prepared statement cannot
			 ** throw an SQLITE_SCHEMA exception. The only database page the
			 ** statement reads is page 1, which is guaranteed to be in the cache.
			 ** And no memory allocations are required.  */
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				iCookie = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			}
			_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33565, libc.VaList(bp+16, iCookie+int32(1)))
		}
	}
}

// C documentation
//
//	/*
//	** Update the contents of the rbu_state table within the rbu database. The
//	** value stored in the RBU_STATE_STAGE column is eStage. All other values
//	** are determined by inspecting the rbu handle passed as the first argument.
//	*/
func _rbuSaveState(tls *libc.TLS, p uintptr, eStage int32) {
	bp := tls.Alloc(192)
	defer tls.Free(192)
	var pFd, v1 uintptr
	var rc int32
	var _ /* pInsert at bp+0 */ uintptr
	_, _, _ = pFd, rc, v1
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK || (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_DONE) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd
		} else {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd
		}
		pFd = v1
		rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+33592, libc.VaList(bp+16, p+24, int32(RBU_STATE_STAGE), eStage, int32(RBU_STATE_TBL), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl, int32(RBU_STATE_IDX), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzIdx, int32(RBU_STATE_ROW), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep, int32(RBU_STATE_PROGRESS), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress, int32(RBU_STATE_CKPT), (*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum, int32(RBU_STATE_COOKIE), int64((*Trbu_file)(unsafe.Pointer(pFd)).FiCookie), int32(RBU_STATE_OALSZ), (*Tsqlite3rbu)(unsafe.Pointer(p)).FiOalSz, int32(RBU_STATE_PHASEONESTEP), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep, int32(RBU_STATE_DATATBL), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzDataTbl)))
		if rc == SQLITE_OK {
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		if rc != SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		}
	}
}

// C documentation
//
//	/*
//	** The second argument passed to this function is the name of a PRAGMA
//	** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
//	** This function executes the following on sqlite3rbu.dbRbu:
//	**
//	**   "PRAGMA main.$zPragma"
//	**
//	** where $zPragma is the string passed as the second argument, then
//	** on sqlite3rbu.dbMain:
//	**
//	**   "PRAGMA main.$zPragma = $val"
//	**
//	** where $val is the value returned by the first PRAGMA invocation.
//	**
//	** In short, it copies the value  of the specified PRAGMA setting from
//	** dbRbu to dbMain.
//	*/
func _rbuCopyPragma(tls *libc.TLS, p uintptr, zPragma uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* pPragma at bp+0 */ uintptr
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+33750, libc.VaList(bp+16, zPragma)))
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33765, libc.VaList(bp+16, zPragma, Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)))
		}
		_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	}
}

// C documentation
//
//	/*
//	** The RBU handle passed as the only argument has just been opened and
//	** the state database is empty. If this RBU handle was opened for an
//	** RBU vacuum operation, create the schema in the target db.
//	*/
func _rbuCreateTargetSchema(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var zSql uintptr
	var _ /* pInsert at bp+4 */ uintptr
	var _ /* pSql at bp+0 */ uintptr
	_, _ = i, zSql
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33785, uintptr(0), uintptr(0), p+36)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, __ccgo_ts+33810)
	}
	for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) == int32(SQLITE_ROW) {
		zSql = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, zSql, uintptr(0), uintptr(0), p+36)
	}
	_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, __ccgo_ts+33918)
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+4, p+36, __ccgo_ts+33983)
	}
	for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) == int32(SQLITE_ROW) {
		i = 0
		for {
			if !(i < int32(5)) {
				break
			}
			Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), i+int32(1), Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp)), i))
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34027, uintptr(0), uintptr(0), p+36)
	}
	_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	_rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)))
}

// C documentation
//
//	/*
//	** Step the RBU object.
//	*/
func Xsqlite3rbu_step(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iSector Tu32
	var pDb, pFrame, pIter uintptr
	var rc int32
	var _ /* ptr at bp+0 */ uintptr
	_, _, _, _, _ = iSector, pDb, pFrame, pIter, rc
	if p != 0 {
		switch (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage {
		case int32(RBU_STAGE_OAL):
			pIter = p + 48
			/* If this is an RBU vacuum operation and the state table was empty
			 ** when this handle was opened, create the target database schema. */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				_rbuCreateTargetSchema(tls, p)
				_rbuCopyPragma(tls, p, __ccgo_ts+19090)
				_rbuCopyPragma(tls, p, __ccgo_ts+18180)
			}
			for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 {
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 {
					/* Clean up the rbu_tmp_xxx table for the previous table. It
					 ** cannot be dropped as there are currently active SQL statements.
					 ** But the contents can be deleted.  */
					if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
						_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+34052, libc.VaList(bp+16, p+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))
					}
				} else {
					_rbuObjIterPrepareAll(tls, p, pIter, 0)
					/* Advance to the next row to process. */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
						if rc == int32(SQLITE_ROW) {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress++
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep++
							return _rbuStep(tls, p)
						}
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
						(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = 0
					}
				}
				_rbuObjIterNext(tls, p, pIter)
			}
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				_rbuSaveState(tls, p, int32(RBU_STAGE_MOVE))
				_rbuIncrSchemaCookie(tls, p)
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16301, uintptr(0), uintptr(0), p+36)
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16301, uintptr(0), uintptr(0), p+36)
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_MOVE)
			}
		case int32(RBU_STAGE_MOVE):
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				_rbuMoveOalFile(tls, p)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress++
			}
		case int32(RBU_STAGE_CKPT):
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep >= (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame {
					pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
					/* Sync the db file */
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
					/* Update nBackfill */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxShmMap})))(tls, pDb, 0, libc.Int32FromInt32(32)*libc.Int32FromInt32(1024), 0, bp)
						if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							*(*Tu32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 24*4)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).FiMaxFrame
						}
					}
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
					}
				} else {
					for cond := true; cond; cond = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep < (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame && iSector == ((*(*TRbuFrame)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)*8))).FiDbPage-uint32(1))/uint32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector) && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						pFrame = (*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)*8
						iSector = ((*TRbuFrame)(unsafe.Pointer(pFrame)).FiDbPage - uint32(1)) / uint32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector)
						_rbuCheckpointFrame(tls, p, pFrame)
						(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep++
					}
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress++
			}
		default:
			break
		}
		return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	} else {
		return int32(SQLITE_NOMEM)
	}
	return r
}

// C documentation
//
//	/*
//	** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
//	** otherwise. Either or both argument may be NULL. Two NULL values are
//	** considered equal, and NULL is considered distinct from all other values.
//	*/
func _rbuStrCompare(tls *libc.TLS, z1 uintptr, z2 uintptr) (r int32) {
	if z1 == uintptr(0) && z2 == uintptr(0) {
		return 0
	}
	if z1 == uintptr(0) || z2 == uintptr(0) {
		return int32(1)
	}
	return libc.BoolInt32(Xsqlite3_stricmp(tls, z1, z2) != 0)
}

// C documentation
//
//	/*
//	** This function is called as part of sqlite3rbu_open() when initializing
//	** an rbu handle in OAL stage. If the rbu update has not started (i.e.
//	** the rbu_state table was empty) it is a no-op. Otherwise, it arranges
//	** things so that the next call to sqlite3rbu_step() continues on from
//	** where the previous rbu handle left off.
//	**
//	** If an error occurs, an error code and error message are left in the
//	** rbu handle passed as the first argument.
//	*/
func _rbuSetupOal(tls *libc.TLS, p uintptr, pState uintptr) {
	var pIter uintptr
	var rc int32
	_, _ = pIter, rc
	if (*TRbuState)(unsafe.Pointer(pState)).FzTbl != 0 {
		pIter = p + 48
		rc = SQLITE_OK
		for rc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 && ((*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 || _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx, (*TRbuState)(unsafe.Pointer(pState)).FzIdx) != 0 || (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl == uintptr(0) && _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, (*TRbuState)(unsafe.Pointer(pState)).FzTbl) != 0 || (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl != 0 && _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl) != 0) {
			rc = _rbuObjIterNext(tls, p, pIter)
		}
		if rc == SQLITE_OK && !((*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0) {
			rc = int32(SQLITE_ERROR)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34080, 0)
		}
		if rc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*TRbuState)(unsafe.Pointer(pState)).FnRow
			rc = _rbuObjIterPrepareAll(tls, p, p+48, (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
}

// C documentation
//
//	/*
//	** If there is a "*-oal" file in the file-system corresponding to the
//	** target database in the file-system, delete it. If an error occurs,
//	** leave an error code and error message in the rbu handle.
//	*/
func _rbuDeleteOalFile(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zOal uintptr
	var _ /* pVfs at bp+0 */ uintptr
	_ = zOal
	zOal = _rbuMPrintf(tls, p, __ccgo_ts+33529, libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget))
	if zOal != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7958, int32(SQLITE_FCNTL_VFS_POINTER), bp)
		(*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxDelete})))(tls, *(*uintptr)(unsafe.Pointer(bp)), zOal, 0)
		Xsqlite3_free(tls, zOal)
	}
}

// C documentation
//
//	/*
//	** Allocate a private rbu VFS for the rbu handle passed as the only
//	** argument. This VFS will be used unless the call to sqlite3rbu_open()
//	** specified a URI with a vfs=? option in place of a target database
//	** file name.
//	*/
func _rbuCreateVfs(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var pVfs uintptr
	var _ /* rnd at bp+0 */ int32
	var _ /* zRnd at bp+4 */ [64]int8
	_ = pVfs
	Xsqlite3_randomness(tls, int32(4), bp)
	Xsqlite3_snprintf(tls, int32(64), bp+4, __ccgo_ts+34105, libc.VaList(bp+80, *(*int32)(unsafe.Pointer(bp))))
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3rbu_create_vfs(tls, bp+4, uintptr(0))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pVfs = Xsqlite3_vfs_find(tls, bp+4)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FzVfsName = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FzName
		(*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRbu = p
	}
}

// C documentation
//
//	/*
//	** Destroy the private VFS created for the rbu handle passed as the only
//	** argument by an earlier call to rbuCreateVfs().
//	*/
func _rbuDeleteVfs(tls *libc.TLS, p uintptr) {
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzVfsName != 0 {
		Xsqlite3rbu_destroy_vfs(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzVfsName)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FzVfsName = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** This user-defined SQL function is invoked with a single argument - the
//	** name of a table expected to appear in the target database. It returns
//	** the number of auxilliary indexes on the table.
//	*/
func _rbuIndexCntFunc(tls *libc.TLS, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, v1 uintptr
	var nIndex, rc int32
	var _ /* pStmt at bp+0 */ uintptr
	var _ /* zErrmsg at bp+4 */ uintptr
	_, _, _, _, _ = db, nIndex, p, rc, v1
	p = Xsqlite3_user_data(tls, pCtx)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu
	} else {
		v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
	}
	db = v1
	rc = _prepareFreeAndCollectError(tls, db, bp, bp+4, Xsqlite3_mprintf(tls, __ccgo_ts+34116, libc.VaList(bp+16, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal))))))
	if rc != SQLITE_OK {
		Xsqlite3_result_error(tls, pCtx, *(*uintptr)(unsafe.Pointer(bp + 4)), -int32(1))
	} else {
		nIndex = 0
		if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			nIndex = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
		}
		rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if rc == SQLITE_OK {
			Xsqlite3_result_int(tls, pCtx, nIndex)
		} else {
			Xsqlite3_result_error(tls, pCtx, Xsqlite3_errmsg(tls, db), -int32(1))
		}
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
}

// C documentation
//
//	/*
//	** If the RBU database contains the rbu_count table, use it to initialize
//	** the sqlite3rbu.nPhaseOneStep variable. The schema of the rbu_count table
//	** is assumed to contain the same columns as:
//	**
//	**   CREATE TABLE rbu_count(tbl TEXT PRIMARY KEY, cnt INTEGER) WITHOUT ROWID;
//	**
//	** There should be one row in the table for each data_xxx table in the
//	** database. The 'tbl' column should contain the name of a data_xxx table,
//	** and the cnt column the number of rows it contains.
//	**
//	** sqlite3rbu.nPhaseOneStep is initialized to the sum of (1 + nIndex) * cnt
//	** for all rows in the rbu_count table, where nIndex is the number of
//	** indexes on the corresponding target database table.
//	*/
func _rbuInitPhaseOneSteps(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bExists int32
	var _ /* pStmt at bp+0 */ uintptr
	_ = bExists
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		bExists = 0 /* True if rbu_count exists */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = int64(-int32(1))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+34188, int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_rbuIndexCntFunc), uintptr(0), uintptr(0))
		/* Check for the rbu_count table. If it does not exist, or if an error
		 ** occurs, nPhaseOneStep will be left set to -1. */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, __ccgo_ts+34202)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				bExists = int32(1)
			}
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && bExists != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, __ccgo_ts+34259)
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
	}
}

func _openRbuHandle(tls *libc.TLS, zTarget uintptr, zRbu uintptr, zState uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pCsr, pFd, pState, v2, v3 uintptr
	var frc int32
	var nByte, nRbu, nTarget Tsize_t
	var v1 uint32
	var _ /* bRetry at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _ = db, frc, nByte, nRbu, nTarget, p, pCsr, pFd, pState, v1, v2, v3
	if zTarget != 0 {
		v1 = libc.Xstrlen(tls, zTarget)
	} else {
		v1 = uint32(0)
	}
	nTarget = v1
	nRbu = libc.Xstrlen(tls, zRbu)
	nByte = uint32(256) + nTarget + uint32(1) + nRbu + uint32(1)
	p = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	if p != 0 {
		pState = uintptr(0)
		/* Create the custom VFS. */
		libc.Xmemset(tls, p, 0, uint32(256))
		Xsqlite3rbu_rename_handler(tls, p, uintptr(0), uintptr(0))
		_rbuCreateVfs(tls, p)
		/* Open the target, RBU and state databases */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			pCsr = p + 1*256
			*(*int32)(unsafe.Pointer(bp)) = 0
			if zTarget != 0 {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget = pCsr
				libc.Xmemcpy(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, zTarget, nTarget+uint32(1))
				pCsr += uintptr(nTarget + uint32(1))
			}
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu = pCsr
			libc.Xmemcpy(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, zRbu, nRbu+uint32(1))
			pCsr += uintptr(nRbu + uint32(1))
			if zState != 0 {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzState = _rbuMPrintf(tls, p, __ccgo_ts+4709, libc.VaList(bp+16, zState))
			}
			/* If the first attempt to open the database file fails and the bRetry
			 ** flag it set, this means that the db was not opened because it seemed
			 ** to be a wal-mode db. But, this may have happened due to an earlier
			 ** RBU vacuum operation leaving an old wal file in the directory.
			 ** If this is the case, it will have been checkpointed and deleted
			 ** when the handle was closed and a second attempt to open the
			 ** database may succeed.  */
			_rbuOpenDatabase(tls, p, uintptr(0), bp)
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				_rbuOpenDatabase(tls, p, uintptr(0), uintptr(0))
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			pState = _rbuLoadState(tls, p)
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if (*TRbuState)(unsafe.Pointer(pState)).FeStage == 0 {
					_rbuDeleteOalFile(tls, p)
					_rbuInitPhaseOneSteps(tls, p)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_OAL)
				} else {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = (*TRbuState)(unsafe.Pointer(pState)).FeStage
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = (*TRbuState)(unsafe.Pointer(pState)).FnPhaseOneStep
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = int32((*TRbuState)(unsafe.Pointer(pState)).FnProgress)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FiOalSz = (*TRbuState)(unsafe.Pointer(pState)).FiOalSz
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd != 0 {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34333, 0)
			} else {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_MOVE) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = 0
				}
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && ((*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) || (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_MOVE)) && (*TRbuState)(unsafe.Pointer(pState)).FeStage != 0 {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
				v2 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd
			} else {
				v2 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd
			}
			pFd = v2
			if (*Trbu_file)(unsafe.Pointer(pFd)).FiCookie != (*TRbuState)(unsafe.Pointer(pState)).FiCookie {
				/* At this point (pTargetFd->iCookie) contains the value of the
				 ** change-counter cookie (the thing that gets incremented when a
				 ** transaction is committed in rollback mode) currently stored on
				 ** page 1 of the database file. */
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_BUSY)
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					v3 = __ccgo_ts + 34365
				} else {
					v3 = __ccgo_ts + 34372
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34379, libc.VaList(bp+16, v3))
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
				db = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16286, uintptr(0), uintptr(0), p+36)
				/* Point the object iterator at the first object */
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuObjIterFirst(tls, p, p+48)
				}
				/* If the RBU database contains no data_xxx tables, declare the RBU
				 ** update finished.  */
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl == uintptr(0) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
				} else {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuState)(unsafe.Pointer(pState)).FeStage == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						_rbuCopyPragma(tls, p, __ccgo_ts+18804)
						_rbuCopyPragma(tls, p, __ccgo_ts+18195)
					}
					/* Open transactions both databases. The *-oal file is opened or
					 ** created at this point. */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, __ccgo_ts+34411, uintptr(0), uintptr(0), p+36)
					}
					/* Check if the main database is a zipvfs db. If it is, set the upper
					 ** level pager to use "journal_mode=off". This prevents it from
					 ** generating a large journal using a temp file.  */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						frc = Xsqlite3_file_control(tls, db, __ccgo_ts+7958, int32(SQLITE_FCNTL_ZIPVFS), uintptr(0))
						if frc == SQLITE_OK {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, __ccgo_ts+34427, uintptr(0), uintptr(0), p+36)
						}
					}
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						_rbuSetupOal(tls, p, pState)
					}
				}
			} else {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_MOVE) {
					/* no-op */
				} else {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
						if !((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == libc.UintptrFromInt32(0)) && _rbuExclusiveCheckpoint(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain) != 0 {
							/* If the rbu_exclusive_checkpoint=1 URI parameter was specified
							 ** and an incremental checkpoint is being resumed, attempt an
							 ** exclusive lock on the db file. If this fails, so be it.  */
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
							_rbuLockDatabase(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
						}
						_rbuSetupCheckpoint(tls, p, pState)
					} else {
						if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_DONE) {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
						} else {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_CORRUPT)
						}
					}
				}
			}
		}
		_rbuFreeState(tls, pState)
	}
	return p
}

// C documentation
//
//	/*
//	** Allocate and return an RBU handle with all fields zeroed except for the
//	** error code, which is set to SQLITE_MISUSE.
//	*/
func _rbuMisuseError(tls *libc.TLS) (r uintptr) {
	var pRet uintptr
	_ = pRet
	pRet = Xsqlite3_malloc64(tls, uint64(256))
	if pRet != 0 {
		libc.Xmemset(tls, pRet, 0, uint32(256))
		(*Tsqlite3rbu)(unsafe.Pointer(pRet)).Frc = int32(SQLITE_MISUSE)
	}
	return pRet
}

// C documentation
//
//	/*
//	** Open and return a new RBU handle.
//	*/
func Xsqlite3rbu_open(tls *libc.TLS, zTarget uintptr, zRbu uintptr, zState uintptr) (r uintptr) {
	if zTarget == uintptr(0) || zRbu == uintptr(0) {
		return _rbuMisuseError(tls)
	}
	return _openRbuHandle(tls, zTarget, zRbu, zState)
}

// C documentation
//
//	/*
//	** Open a handle to begin or resume an RBU VACUUM operation.
//	*/
func Xsqlite3rbu_vacuum(tls *libc.TLS, zTarget uintptr, zState uintptr) (r uintptr) {
	var n int32
	_ = n
	if zTarget == uintptr(0) {
		return _rbuMisuseError(tls)
	}
	if zState != 0 {
		n = int32(libc.Xstrlen(tls, zState))
		if n >= int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+34451, zState+uintptr(n-int32(7)), uint32(7)) {
			return _rbuMisuseError(tls)
		}
	}
	/* TODO: Check that both arguments are non-NULL */
	return _openRbuHandle(tls, uintptr(0), zTarget, zState)
}

// C documentation
//
//	/*
//	** Return the database handle used by pRbu.
//	*/
func Xsqlite3rbu_db(tls *libc.TLS, pRbu uintptr, bRbu int32) (r uintptr) {
	var db, v1 uintptr
	_, _ = db, v1
	db = uintptr(0)
	if pRbu != 0 {
		if bRbu != 0 {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FdbRbu
		} else {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FdbMain
		}
		db = v1
	}
	return db
}

// C documentation
//
//	/*
//	** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT,
//	** then edit any error message string so as to remove all occurrences of
//	** the pattern "rbu_imp_[0-9]*".
//	*/
func _rbuEditErrmsg(tls *libc.TLS, p uintptr) {
	var i uint32
	var nDel int32
	var nErrmsg Tsize_t
	_, _, _ = i, nDel, nErrmsg
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_CONSTRAINT) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg != 0 {
		nErrmsg = libc.Xstrlen(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg)
		i = uint32(0)
		for {
			if !(i < nErrmsg-uint32(8)) {
				break
			}
			if libc.Xmemcmp(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), __ccgo_ts+32476, uint32(8)) == 0 {
				nDel = int32(8)
				for int32(*(*int8)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg + uintptr(i+uint32(uint32(nDel)))))) >= int32('0') && int32(*(*int8)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg + uintptr(i+uint32(uint32(nDel)))))) <= int32('9') {
					nDel++
				}
				libc.Xmemmove(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i+uint32(uint32(nDel))), nErrmsg+uint32(1)-i-uint32(uint32(nDel)))
				nErrmsg -= uint32(uint32(nDel))
			}
			goto _1
		_1:
			;
			i++
		}
	}
}

// C documentation
//
//	/*
//	** Close the RBU handle.
//	*/
func Xsqlite3rbu_close(tls *libc.TLS, p uintptr, pzErrmsg uintptr) (r int32) {
	var pDb uintptr
	var rc, rc2 int32
	_, _, _ = pDb, rc, rc2
	if p != 0 {
		/* Commit the transaction to the *-oal file. */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16301, uintptr(0), uintptr(0), p+36)
		}
		/* Sync the db file if currently doing an incremental checkpoint */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
			pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
		}
		_rbuSaveState(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16301, uintptr(0), uintptr(0), p+36)
		}
		/* Close any open statement handles. */
		_rbuObjIterFinalize(tls, p+48)
		/* If this is an RBU vacuum handle and the vacuum has either finished
		 ** successfully or encountered an error, delete the contents of the
		 ** state table. This causes the next call to sqlite3rbu_vacuum()
		 ** specifying the current target and state databases to start a new
		 ** vacuum from scratch.  */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu != 0 {
			rc2 = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+34459, uintptr(0), uintptr(0), uintptr(0))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_DONE) && rc2 != SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc2
			}
		}
		/* Close the open database handle and VFS object. */
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
		_rbuDeleteVfs(tls, p)
		Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FaBuf)
		Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame)
		_rbuEditErrmsg(tls, p)
		rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
		if pzErrmsg != 0 {
			*(*uintptr)(unsafe.Pointer(pzErrmsg)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg
		} else {
			Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg)
		}
		Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState)
		Xsqlite3_free(tls, p)
	} else {
		rc = int32(SQLITE_NOMEM)
		*(*uintptr)(unsafe.Pointer(pzErrmsg)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the total number of key-value operations (inserts, deletes or
//	** updates) that have been performed on the target database since the
//	** current RBU update was started.
//	*/
func Xsqlite3rbu_progress(tls *libc.TLS, pRbu uintptr) (r Tsqlite3_int64) {
	return int64((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FnProgress)
}

// C documentation
//
//	/*
//	** Return permyriadage progress indications for the two main stages of
//	** an RBU update.
//	*/
func Xsqlite3rbu_bp_progress(tls *libc.TLS, p uintptr, pnOne uintptr, pnTwo uintptr) {
	var MAX_PROGRESS int32
	_ = MAX_PROGRESS
	MAX_PROGRESS = int32(10000)
	switch (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage {
	case int32(RBU_STAGE_OAL):
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep > 0 {
			*(*int32)(unsafe.Pointer(pnOne)) = int32(int64(int64(MAX_PROGRESS)) * int64((*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress) / (*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep)
		} else {
			*(*int32)(unsafe.Pointer(pnOne)) = -int32(1)
		}
		*(*int32)(unsafe.Pointer(pnTwo)) = 0
	case int32(RBU_STAGE_MOVE):
		*(*int32)(unsafe.Pointer(pnOne)) = MAX_PROGRESS
		*(*int32)(unsafe.Pointer(pnTwo)) = 0
	case int32(RBU_STAGE_CKPT):
		*(*int32)(unsafe.Pointer(pnOne)) = MAX_PROGRESS
		*(*int32)(unsafe.Pointer(pnTwo)) = int32(int64(int64(MAX_PROGRESS)) * int64((*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep) / int64((*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame))
	case int32(RBU_STAGE_DONE):
		*(*int32)(unsafe.Pointer(pnOne)) = MAX_PROGRESS
		*(*int32)(unsafe.Pointer(pnTwo)) = MAX_PROGRESS
	default:
	}
}

// C documentation
//
//	/*
//	** Return the current state of the RBU vacuum or update operation.
//	*/
func Xsqlite3rbu_state(tls *libc.TLS, p uintptr) (r int32) {
	var aRes [6]int32
	_ = aRes
	aRes = [6]int32{
		1: int32(SQLITE_RBU_STATE_OAL),
		2: int32(SQLITE_RBU_STATE_MOVE),
		4: int32(SQLITE_RBU_STATE_CHECKPOINT),
		5: int32(SQLITE_RBU_STATE_DONE),
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != int32(SQLITE_DONE) {
		return int32(SQLITE_RBU_STATE_ERROR)
	} else {
		return aRes[(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage]
	}
	return r
}

func Xsqlite3rbu_savestate(tls *libc.TLS, p uintptr) (r int32) {
	var pDb, zBegin, v1 uintptr
	var rc int32
	_, _, _, _ = pDb, rc, zBegin, v1
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	if rc == int32(SQLITE_DONE) {
		return SQLITE_OK
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16301, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	/* Sync the db file */
	if rc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
		pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	_rbuSaveState(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage)
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16301, uintptr(0), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
				v1 = __ccgo_ts + 16286
			} else {
				v1 = __ccgo_ts + 34411
			}
			zBegin = v1
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, zBegin, uintptr(0), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34411, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	return rc
}

// C documentation
//
//	/*
//	** Default xRename callback for RBU.
//	*/
func _xDefaultRename(tls *libc.TLS, pArg uintptr, zOld uintptr, zNew uintptr) (r int32) {
	var rc, v1 int32
	_, _ = rc, v1
	rc = SQLITE_OK
	if libc.Xrename(tls, zOld, zNew) != 0 {
		v1 = int32(SQLITE_IOERR)
	} else {
		v1 = SQLITE_OK
	}
	rc = v1
	return rc
}

func Xsqlite3rbu_rename_handler(tls *libc.TLS, pRbu uintptr, pArg uintptr, xRename uintptr) {
	if xRename != 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FxRename = xRename
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FpRenameArg = pArg
	} else {
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FxRename = __ccgo_fp(_xDefaultRename)
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FpRenameArg = uintptr(0)
	}
}

/**************************************************************************
** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
** of a standard VFS in the following ways:
**
** 1. Whenever the first page of a main database file is read or
**    written, the value of the change-counter cookie is stored in
**    rbu_file.iCookie. Similarly, the value of the "write-version"
**    database header field is stored in rbu_file.iWriteVer. This ensures
**    that the values are always trustworthy within an open transaction.
**
** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (rbu_file.pWalFd)
**    member variable of the associated database file descriptor is set
**    to point to the new file. A mutex protected linked list of all main
**    db fds opened using a particular RBU VFS is maintained at
**    rbu_vfs.pMain to facilitate this.
**
** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file
**    object can be marked as the target database of an RBU update. This
**    turns on the following extra special behaviour:
**
** 3a. If xAccess() is called to check if there exists a *-wal file
**     associated with an RBU target database currently in RBU_STAGE_OAL
**     stage (preparing the *-oal file), the following special handling
**     applies:
**
**      * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU
**        target database may not be in wal mode already.
**
**      * if the *-wal file does not exist, set the output parameter to
**        non-zero (to tell SQLite that it does exist) anyway.
**
**     Then, when xOpen() is called to open the *-wal file associated with
**     the RBU target in RBU_STAGE_OAL stage, instead of opening the *-wal
**     file, the rbu vfs opens the corresponding *-oal file instead.
**
** 3b. The *-shm pages returned by xShmMap() for a target db file in
**     RBU_STAGE_OAL mode are actually stored in heap memory. This is to
**     avoid creating a *-shm file on disk. Additionally, xShmLock() calls
**     are no-ops on target database files in RBU_STAGE_OAL mode. This is
**     because assert() statements in some VFS implementations fail if
**     xShmLock() is called before xShmMap().
**
** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
**     mode except RBU_STAGE_DONE (all work completed and checkpointed), it
**     fails with an SQLITE_BUSY error. This is to stop RBU connections
**     from automatically checkpointing a *-wal (or *-oal) file from within
**     sqlite3_close().
**
** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
**     all xWrite() calls on the target database file perform no IO.
**     Instead the frame and page numbers that would be read and written
**     are recorded. Additionally, successful attempts to obtain exclusive
**     xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
**     database file are recorded. xShmLock() calls to unlock the same
**     locks are no-ops (so that once obtained, these locks are never
**     relinquished). Finally, calls to xSync() on the target database
**     file fail with SQLITE_NOTICE errors.
 */

func _rbuUnlockShm(tls *libc.TLS, p uintptr) {
	var i int32
	var xShmLock uintptr
	_, _ = i, xShmLock
	if (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
		xShmLock = (*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmLock
		i = 0
		for {
			if !(i < int32(SQLITE_SHM_NLOCK)) {
				break
			}
			if uint32(libc.Int32FromInt32(1)<<i)&(*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbu)).FmLock != 0 {
				(*(*func(*libc.TLS, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xShmLock})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, i, int32(1), libc.Int32FromInt32(SQLITE_SHM_UNLOCK)|libc.Int32FromInt32(SQLITE_SHM_EXCLUSIVE))
			}
			goto _1
		_1:
			;
			i++
		}
		(*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbu)).FmLock = uint32(0)
	}
}

// C documentation
//
//	/*
//	*/
func _rbuUpdateTempSize(tls *libc.TLS, pFd uintptr, nNew Tsqlite3_int64) (r int32) {
	var nDiff Ti64
	var pRbu uintptr
	_, _ = nDiff, pRbu
	pRbu = (*Trbu_file)(unsafe.Pointer(pFd)).FpRbu
	nDiff = nNew - (*Trbu_file)(unsafe.Pointer(pFd)).Fsz
	*(*Ti64)(unsafe.Pointer(pRbu + 232)) += nDiff
	(*Trbu_file)(unsafe.Pointer(pFd)).Fsz = nNew
	if (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FszTemp > (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit {
		return int32(SQLITE_FULL)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Add an item to the main-db lists, if it is not already present.
//	**
//	** There are two main-db lists. One for all file descriptors, and one
//	** for all file descriptors with rbu_file.pDb!=0. If the argument has
//	** rbu_file.pDb!=0, then it is assumed to already be present on the
//	** main list and is only added to the pDb!=0 list.
//	*/
func _rbuMainlistAdd(tls *libc.TLS, p uintptr) {
	var pIter, pRbuVfs uintptr
	_, _ = pIter, pRbuVfs
	pRbuVfs = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs
	Xsqlite3_mutex_enter(tls, (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
	if (*Trbu_file)(unsafe.Pointer(p)).FpRbu == uintptr(0) {
		pIter = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain
		for {
			if !(pIter != 0) {
				break
			}
			goto _1
		_1:
			;
			pIter = (*Trbu_file)(unsafe.Pointer(pIter)).FpMainNext
		}
		(*Trbu_file)(unsafe.Pointer(p)).FpMainNext = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain
		(*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain = p
	} else {
		pIter = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu
		for {
			if !(pIter != 0 && pIter != p) {
				break
			}
			goto _2
		_2:
			;
			pIter = (*Trbu_file)(unsafe.Pointer(pIter)).FpMainRbuNext
		}
		if pIter == uintptr(0) {
			(*Trbu_file)(unsafe.Pointer(p)).FpMainRbuNext = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu
			(*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu = p
		}
	}
	Xsqlite3_mutex_leave(tls, (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
}

// C documentation
//
//	/*
//	** Remove an item from the main-db lists.
//	*/
func _rbuMainlistRemove(tls *libc.TLS, p uintptr) {
	var pp uintptr
	_ = pp
	Xsqlite3_mutex_enter(tls, (*Trbu_vfs)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs)).Fmutex)
	pp = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs + 100
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != 0 && *(*uintptr)(unsafe.Pointer(pp)) != p) {
			break
		}
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 56
	}
	if *(*uintptr)(unsafe.Pointer(pp)) != 0 {
		*(*uintptr)(unsafe.Pointer(pp)) = (*Trbu_file)(unsafe.Pointer(p)).FpMainNext
	}
	(*Trbu_file)(unsafe.Pointer(p)).FpMainNext = uintptr(0)
	pp = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs + 104
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != 0 && *(*uintptr)(unsafe.Pointer(pp)) != p) {
			break
		}
		goto _2
	_2:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 60
	}
	if *(*uintptr)(unsafe.Pointer(pp)) != 0 {
		*(*uintptr)(unsafe.Pointer(pp)) = (*Trbu_file)(unsafe.Pointer(p)).FpMainRbuNext
	}
	(*Trbu_file)(unsafe.Pointer(p)).FpMainRbuNext = uintptr(0)
	Xsqlite3_mutex_leave(tls, (*Trbu_vfs)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs)).Fmutex)
}

// C documentation
//
//	/*
//	** Given that zWal points to a buffer containing a wal file name passed to
//	** either the xOpen() or xAccess() VFS method, search the main-db list for
//	** a file-handle opened by the same database connection on the corresponding
//	** database file.
//	**
//	** If parameter bRbu is true, only search for file-descriptors with
//	** rbu_file.pDb!=0.
//	*/
func _rbuFindMaindb(tls *libc.TLS, pRbuVfs uintptr, zWal uintptr, bRbu int32) (r uintptr) {
	var pDb uintptr
	_ = pDb
	Xsqlite3_mutex_enter(tls, (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
	if bRbu != 0 {
		pDb = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu
		for {
			if !(pDb != 0 && (*Trbu_file)(unsafe.Pointer(pDb)).FzWal != zWal) {
				break
			}
			goto _1
		_1:
			;
			pDb = (*Trbu_file)(unsafe.Pointer(pDb)).FpMainRbuNext
		}
	} else {
		pDb = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain
		for {
			if !(pDb != 0 && (*Trbu_file)(unsafe.Pointer(pDb)).FzWal != zWal) {
				break
			}
			goto _2
		_2:
			;
			pDb = (*Trbu_file)(unsafe.Pointer(pDb)).FpMainNext
		}
	}
	Xsqlite3_mutex_leave(tls, (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
	return pDb
}

// C documentation
//
//	/*
//	** Close an rbu file.
//	*/
func _rbuVfsClose(tls *libc.TLS, pFile uintptr) (r int32) {
	var i, rc int32
	var p, pMeth uintptr
	_, _, _, _ = i, p, pMeth, rc
	p = pFile
	/* Free the contents of the apShm[] array. And the array itself. */
	i = 0
	for {
		if !(i < (*Trbu_file)(unsafe.Pointer(p)).FnShm) {
			break
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FapShm + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
	Xsqlite3_free(tls, (*Trbu_file)(unsafe.Pointer(p)).FapShm)
	(*Trbu_file)(unsafe.Pointer(p)).FapShm = uintptr(0)
	Xsqlite3_free(tls, (*Trbu_file)(unsafe.Pointer(p)).FzDel)
	if (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
		pMeth = (*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods
		_rbuMainlistRemove(tls, p)
		_rbuUnlockShm(tls, p)
		if (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FiVersion > int32(1) && (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmUnmap != 0 {
			(*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmUnmap})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, 0)
		}
	} else {
		if (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_DELETEONCLOSE) != 0 && (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
			_rbuUpdateTempSize(tls, p, 0)
		}
	}
	/* Close the underlying file handle */
	rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxClose})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal)
	return rc
}

// C documentation
//
//	/*
//	** Read and return an unsigned 32-bit big-endian integer from the buffer
//	** passed as the only argument.
//	*/
func _rbuGetU32(tls *libc.TLS, aBuf uintptr) (r Tu32) {
	return uint32(*(*Tu8)(unsafe.Pointer(aBuf)))<<libc.Int32FromInt32(24) + uint32(*(*Tu8)(unsafe.Pointer(aBuf + 1)))<<libc.Int32FromInt32(16) + uint32(*(*Tu8)(unsafe.Pointer(aBuf + 2)))<<libc.Int32FromInt32(8) + uint32(*(*Tu8)(unsafe.Pointer(aBuf + 3)))
}

// C documentation
//
//	/*
//	** Write an unsigned 32-bit value in big-endian format to the supplied
//	** buffer.
//	*/
func _rbuPutU32(tls *libc.TLS, aBuf uintptr, iVal Tu32) {
	*(*Tu8)(unsafe.Pointer(aBuf)) = uint8(iVal >> libc.Int32FromInt32(24) & uint32(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 1)) = uint8(iVal >> libc.Int32FromInt32(16) & uint32(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 2)) = uint8(iVal >> libc.Int32FromInt32(8) & uint32(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 3)) = uint8(iVal >> libc.Int32FromInt32(0) & uint32(0xFF))
}

func _rbuPutU16(tls *libc.TLS, aBuf uintptr, iVal Tu16) {
	*(*Tu8)(unsafe.Pointer(aBuf)) = uint8(int32(int32(iVal)) >> int32(8) & int32(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 1)) = uint8(int32(int32(iVal)) >> 0 & int32(0xFF))
}

// C documentation
//
//	/*
//	** Read data from an rbuVfs-file.
//	*/
func _rbuVfsRead(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
	var aBuf, p, pBuf, pFd, pRbu uintptr
	var iRoot Tu32
	var rc, v1 int32
	_, _, _, _, _, _, _, _ = aBuf, iRoot, p, pBuf, pFd, pRbu, rc, v1
	p = pFile
	pRbu = (*Trbu_file)(unsafe.Pointer(p)).FpRbu
	if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_CAPTURE) {
		rc = _rbuCaptureWalRead(tls, (*Trbu_file)(unsafe.Pointer(p)).FpRbu, iOfst, iAmt)
	} else {
		if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_OAL) && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_WAL) != 0 && iOfst >= (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FiOalSz {
			rc = SQLITE_OK
			libc.Xmemset(tls, zBuf, 0, uint32(uint32(iAmt)))
		} else {
			rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxRead})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, zBuf, iAmt, iOfst)
			/* If this is being called to read the first page of the target
			 ** database as part of an rbu vacuum operation, synthesize the
			 ** contents of the first page if it does not yet exist. Otherwise,
			 ** SQLite will not check for a *-wal file.  */
			if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FzTarget == uintptr(0) && rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) && iOfst == 0 && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).Frc == SQLITE_OK {
				pFd = (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FpRbuFd
				rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods)).FxRead})))(tls, pFd, zBuf, iAmt, iOfst)
				if rc == SQLITE_OK {
					aBuf = zBuf
					if _rbuGetU32(tls, aBuf+52) != 0 {
						v1 = int32(1)
					} else {
						v1 = 0
					}
					iRoot = uint32(v1)
					_rbuPutU32(tls, aBuf+52, iRoot)                                                                                         /* largest root page number */
					_rbuPutU32(tls, aBuf+36, uint32(0))                                                                                     /* number of free pages */
					_rbuPutU32(tls, aBuf+32, uint32(0))                                                                                     /* first page on free list trunk */
					_rbuPutU32(tls, aBuf+28, uint32(1))                                                                                     /* size of db file in pages */
					_rbuPutU32(tls, aBuf+24, (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FpRbuFd)).FiCookie+uint32(1)) /* Change counter */
					if iAmt > int32(100) {
						libc.Xmemset(tls, aBuf+100, 0, uint32(iAmt-int32(100)))
						_rbuPutU16(tls, aBuf+105, uint16(iAmt&int32(0xFFFF)))
						*(*Tu8)(unsafe.Pointer(aBuf + 100)) = uint8(0x0D)
					}
				}
			}
		}
		if rc == SQLITE_OK && iOfst == 0 && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
			/* These look like magic numbers. But they are stable, as they are part
			 ** of the definition of the SQLite file format, which may not change. */
			pBuf = zBuf
			(*Trbu_file)(unsafe.Pointer(p)).FiCookie = _rbuGetU32(tls, pBuf+24)
			(*Trbu_file)(unsafe.Pointer(p)).FiWriteVer = *(*Tu8)(unsafe.Pointer(pBuf + 19))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Write data to an rbuVfs-file.
//	*/
func _rbuVfsWrite(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
	var p, pBuf, pRbu uintptr
	var rc int32
	var szNew Ti64
	_, _, _, _, _ = p, pBuf, pRbu, rc, szNew
	p = pFile
	pRbu = (*Trbu_file)(unsafe.Pointer(p)).FpRbu
	if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_CAPTURE) {
		rc = _rbuCaptureDbWrite(tls, (*Trbu_file)(unsafe.Pointer(p)).FpRbu, iOfst)
	} else {
		if pRbu != 0 {
			if (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_OAL) && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_WAL) != 0 && iOfst >= (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FiOalSz {
				(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FiOalSz = int64(int64(iAmt)) + iOfst
			} else {
				if (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_DELETEONCLOSE) != 0 {
					szNew = int64(int64(iAmt)) + iOfst
					if szNew > (*Trbu_file)(unsafe.Pointer(p)).Fsz {
						rc = _rbuUpdateTempSize(tls, p, szNew)
						if rc != SQLITE_OK {
							return rc
						}
					}
				}
			}
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxWrite})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, zBuf, iAmt, iOfst)
		if rc == SQLITE_OK && iOfst == 0 && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
			/* These look like magic numbers. But they are stable, as they are part
			 ** of the definition of the SQLite file format, which may not change. */
			pBuf = zBuf
			(*Trbu_file)(unsafe.Pointer(p)).FiCookie = _rbuGetU32(tls, pBuf+24)
			(*Trbu_file)(unsafe.Pointer(p)).FiWriteVer = *(*Tu8)(unsafe.Pointer(pBuf + 19))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Truncate an rbuVfs-file.
//	*/
func _rbuVfsTruncate(tls *libc.TLS, pFile uintptr, size Tsqlite_int64) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pFile
	if (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_DELETEONCLOSE) != 0 && (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
		rc = _rbuUpdateTempSize(tls, p, size)
		if rc != SQLITE_OK {
			return rc
		}
	}
	return (*(*func(*libc.TLS, uintptr, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxTruncate})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, size)
}

// C documentation
//
//	/*
//	** Sync an rbuVfs-file.
//	*/
func _rbuVfsSync(tls *libc.TLS, pFile uintptr, flags int32) (r int32) {
	var p uintptr
	_ = p
	p = pFile
	if (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbu)).FeStage == int32(RBU_STAGE_CAPTURE) {
		if (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
			return libc.Int32FromInt32(SQLITE_NOTICE) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
		}
		return SQLITE_OK
	}
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxSync})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, flags)
}

// C documentation
//
//	/*
//	** Return the current file-size of an rbuVfs-file.
//	*/
func _rbuVfsFileSize(tls *libc.TLS, pFile uintptr, pSize uintptr) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	p = pFile
	rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxFileSize})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, pSize)
	/* If this is an RBU vacuum operation and this is the target database,
	 ** pretend that it has at least one page. Otherwise, SQLite will not
	 ** check for the existance of a *-wal file. rbuVfsRead() contains
	 ** similar logic.  */
	if rc == SQLITE_OK && *(*Tsqlite_int64)(unsafe.Pointer(pSize)) == 0 && (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbu)).FzTarget == uintptr(0) && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
		*(*Tsqlite_int64)(unsafe.Pointer(pSize)) = int64(1024)
	}
	return rc
}

// C documentation
//
//	/*
//	** Lock an rbuVfs-file.
//	*/
func _rbuVfsLock(tls *libc.TLS, pFile uintptr, eLock int32) (r int32) {
	var p, pRbu uintptr
	var rc int32
	_, _, _ = p, pRbu, rc
	p = pFile
	pRbu = (*Trbu_file)(unsafe.Pointer(p)).FpRbu
	rc = SQLITE_OK
	if eLock == int32(SQLITE_LOCK_EXCLUSIVE) && ((*Trbu_file)(unsafe.Pointer(p)).FbNolock != 0 || pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage != int32(RBU_STAGE_DONE)) {
		/* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
		 ** prevents it from checkpointing the database from sqlite3_close(). */
		rc = int32(SQLITE_BUSY)
	} else {
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxLock})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, eLock)
	}
	return rc
}

// C documentation
//
//	/*
//	** Unlock an rbuVfs-file.
//	*/
func _rbuVfsUnlock(tls *libc.TLS, pFile uintptr, eLock int32) (r int32) {
	var p uintptr
	_ = p
	p = pFile
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxUnlock})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, eLock)
}

// C documentation
//
//	/*
//	** Check if another file-handle holds a RESERVED lock on an rbuVfs-file.
//	*/
func _rbuVfsCheckReservedLock(tls *libc.TLS, pFile uintptr, pResOut uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pFile
	return (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxCheckReservedLock})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, pResOut)
}

// C documentation
//
//	/*
//	** File control method. For custom operations on an rbuVfs-file.
//	*/
func _rbuVfsFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p, pRbu, pRbu1, pRbuVfs, xControl, zIn, zOut uintptr
	var rc int32
	var _ /* dummy at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = p, pRbu, pRbu1, pRbuVfs, rc, xControl, zIn, zOut
	p = pFile
	xControl = (*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxFileControl
	if op == int32(SQLITE_FCNTL_RBU) {
		pRbu = pArg
		/* First try to find another RBU vfs lower down in the vfs stack. If
		 ** one is found, this vfs will operate in pass-through mode. The lower
		 ** level vfs will do the special RBU handling.  */
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)
		if rc == int32(SQLITE_NOTFOUND) {
			/* Now search for a zipvfs instance lower down in the VFS stack. If
			 ** one is found, this is an error.  */
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, int32(SQLITE_FCNTL_ZIPVFS), bp)
			if rc == SQLITE_OK {
				rc = int32(SQLITE_ERROR)
				(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34486, 0)
			} else {
				if rc == int32(SQLITE_NOTFOUND) {
					(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FpTargetFd = p
					(*Trbu_file)(unsafe.Pointer(p)).FpRbu = pRbu
					_rbuMainlistAdd(tls, p)
					if (*Trbu_file)(unsafe.Pointer(p)).FpWalFd != 0 {
						(*Trbu_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpWalFd)).FpRbu = pRbu
					}
					rc = SQLITE_OK
				}
			}
		}
		return rc
	} else {
		if op == int32(SQLITE_FCNTL_RBUCNT) {
			pRbu1 = pArg
			(*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FnRbu++
			(*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FpRbuFd = p
			(*Trbu_file)(unsafe.Pointer(p)).FbNolock = uint8(1)
		}
	}
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)
	if rc == SQLITE_OK && op == int32(SQLITE_FCNTL_VFSNAME) {
		pRbuVfs = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs
		zIn = *(*uintptr)(unsafe.Pointer(pArg))
		zOut = Xsqlite3_mprintf(tls, __ccgo_ts+34509, libc.VaList(bp+16, (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).Fbase.FzName, zIn))
		*(*uintptr)(unsafe.Pointer(pArg)) = zOut
		if zOut == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the sector-size in bytes for an rbuVfs-file.
//	*/
func _rbuVfsSectorSize(tls *libc.TLS, pFile uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pFile
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxSectorSize})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal)
}

// C documentation
//
//	/*
//	** Return the device characteristic flags supported by an rbuVfs-file.
//	*/
func _rbuVfsDeviceCharacteristics(tls *libc.TLS, pFile uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pFile
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxDeviceCharacteristics})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal)
}

// C documentation
//
//	/*
//	** Take or release a shared-memory lock.
//	*/
func _rbuVfsShmLock(tls *libc.TLS, pFile uintptr, ofst int32, n int32, flags int32) (r int32) {
	var bCapture, rc int32
	var p, pRbu uintptr
	_, _, _, _ = bCapture, p, pRbu, rc
	p = pFile
	pRbu = (*Trbu_file)(unsafe.Pointer(p)).FpRbu
	rc = SQLITE_OK
	if pRbu != 0 && ((*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_OAL) || (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_MOVE) || (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_DONE)) {
		/* Prevent SQLite from taking a shm-lock on the target file when it
		 ** is supplying heap memory to the upper layer in place of *-shm
		 ** segments. */
		if ofst == int32(WAL_LOCK_CKPT) && n == int32(1) {
			rc = int32(SQLITE_BUSY)
		}
	} else {
		bCapture = 0
		if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_CAPTURE) {
			bCapture = int32(1)
		}
		if bCapture == 0 || 0 == flags&int32(SQLITE_SHM_UNLOCK) {
			rc = (*(*func(*libc.TLS, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmLock})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, ofst, n, flags)
			if bCapture != 0 && rc == SQLITE_OK {
				*(*Tu32)(unsafe.Pointer(pRbu + 196)) |= uint32((int32(1)<<n - int32(1)) << ofst)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
//	*/
func _rbuVfsShmMap(tls *libc.TLS, pFile uintptr, iRegion int32, szRegion int32, isWrite int32, pp uintptr) (r int32) {
	var apNew, p, pNew uintptr
	var eStage, rc, v1 int32
	var nByte Tsqlite3_int64
	_, _, _, _, _, _, _ = apNew, eStage, nByte, p, pNew, rc, v1
	p = pFile
	rc = SQLITE_OK
	if (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
		v1 = (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbu)).FeStage
	} else {
		v1 = 0
	}
	eStage = v1
	/* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this
	 ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
	 ** instead of a file on disk.  */
	if eStage == int32(RBU_STAGE_OAL) {
		nByte = int64(uint32(iRegion+libc.Int32FromInt32(1)) * uint32(4))
		apNew = Xsqlite3_realloc64(tls, (*Trbu_file)(unsafe.Pointer(p)).FapShm, uint64(uint64(nByte)))
		/* This is an RBU connection that uses its own heap memory for the
		 ** pages of the *-shm file. Since no other process can have run
		 ** recovery, the connection must request *-shm pages in order
		 ** from start to finish.  */
		if apNew == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, apNew+uintptr((*Trbu_file)(unsafe.Pointer(p)).FnShm)*4, 0, uint32(4)*uint32(libc.Int32FromInt32(1)+iRegion-(*Trbu_file)(unsafe.Pointer(p)).FnShm))
			(*Trbu_file)(unsafe.Pointer(p)).FapShm = apNew
			(*Trbu_file)(unsafe.Pointer(p)).FnShm = iRegion + int32(1)
		}
		if rc == SQLITE_OK {
			pNew = Xsqlite3_malloc64(tls, uint64(uint64(szRegion)))
			if pNew == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemset(tls, pNew, 0, uint32(uint32(szRegion)))
				*(*uintptr)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FapShm + uintptr(iRegion)*4)) = pNew
			}
		}
		if rc == SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pp)) = *(*uintptr)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FapShm + uintptr(iRegion)*4))
		} else {
			*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
		}
	} else {
		rc = (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmMap})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, iRegion, szRegion, isWrite, pp)
	}
	return rc
}

// C documentation
//
//	/*
//	** Memory barrier.
//	*/
func _rbuVfsShmBarrier(tls *libc.TLS, pFile uintptr) {
	var p uintptr
	_ = p
	p = pFile
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmBarrier})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal)
}

// C documentation
//
//	/*
//	** The xShmUnmap method.
//	*/
func _rbuVfsShmUnmap(tls *libc.TLS, pFile uintptr, delFlag int32) (r int32) {
	var eStage, rc, v1 int32
	var p uintptr
	_, _, _, _ = eStage, p, rc, v1
	p = pFile
	rc = SQLITE_OK
	if (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
		v1 = (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbu)).FeStage
	} else {
		v1 = 0
	}
	eStage = v1
	if eStage == int32(RBU_STAGE_OAL) || eStage == int32(RBU_STAGE_MOVE) {
		/* no-op */
	} else {
		/* Release the checkpointer and writer locks */
		_rbuUnlockShm(tls, p)
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods1)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmUnmap})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, delFlag)
	}
	return rc
}

// C documentation
//
//	/*
//	** Open an rbu file handle.
//	*/
func _rbuVfsOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pFile uintptr, flags int32, pOutFlags uintptr) (r int32) {
	var nOpen Tsize_t
	var oflags, rc int32
	var pDb, pFd, pMeth, pRbuVfs, pRealVfs, zOpen uintptr
	_, _, _, _, _, _, _, _, _ = nOpen, oflags, pDb, pFd, pMeth, pRbuVfs, pRealVfs, rc, zOpen
	pRbuVfs = pVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRealVfs
	pFd = pFile
	rc = SQLITE_OK
	zOpen = zName
	oflags = flags
	libc.Xmemset(tls, pFd, 0, uint32(64))
	(*Trbu_file)(unsafe.Pointer(pFd)).FpReal = pFd + 1*64
	(*Trbu_file)(unsafe.Pointer(pFd)).FpRbuVfs = pRbuVfs
	(*Trbu_file)(unsafe.Pointer(pFd)).FopenFlags = flags
	if zName != 0 {
		if flags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
			/* A main database has just been opened. The following block sets
			 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
			 ** the name of the *-wal file this db connection will use. SQLite
			 ** happens to pass a pointer to this buffer when using xAccess()
			 ** or xOpen() to operate on the *-wal file.  */
			(*Trbu_file)(unsafe.Pointer(pFd)).FzWal = Xsqlite3_filename_wal(tls, zName)
		} else {
			if flags&int32(SQLITE_OPEN_WAL) != 0 {
				pDb = _rbuFindMaindb(tls, pRbuVfs, zName, 0)
				if pDb != 0 {
					if (*Trbu_file)(unsafe.Pointer(pDb)).FpRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pDb)).FpRbu)).FeStage == int32(RBU_STAGE_OAL) {
						if (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pDb)).FpRbu)).FzTarget == uintptr(0) {
							zOpen = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pDb)).FpRbu)).FdbRbu, __ccgo_ts+7958)
							zOpen = Xsqlite3_filename_wal(tls, zOpen)
						}
						nOpen = libc.Xstrlen(tls, zOpen)
						*(*int8)(unsafe.Pointer(zOpen + uintptr(nOpen-uint32(3)))) = int8('o')
						(*Trbu_file)(unsafe.Pointer(pFd)).FpRbu = (*Trbu_file)(unsafe.Pointer(pDb)).FpRbu
					}
					(*Trbu_file)(unsafe.Pointer(pDb)).FpWalFd = pFd
				}
			}
		}
	} else {
		(*Trbu_file)(unsafe.Pointer(pFd)).FpRbu = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRbu
	}
	if oflags&int32(SQLITE_OPEN_MAIN_DB) != 0 && Xsqlite3_uri_boolean(tls, zName, __ccgo_ts+34520, 0) != 0 {
		oflags = libc.Int32FromInt32(SQLITE_OPEN_TEMP_DB) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE)
		zOpen = uintptr(0)
	}
	if rc == SQLITE_OK {
		rc = (*(*func(*libc.TLS, uintptr, Tsqlite3_filename, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxOpen})))(tls, pRealVfs, zOpen, (*Trbu_file)(unsafe.Pointer(pFd)).FpReal, oflags, pOutFlags)
	}
	if (*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pFd)).FpReal)).FpMethods != 0 {
		pMeth = (*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pFd)).FpReal)).FpMethods
		/* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
		 ** pointer and, if the file is a main database file, link it into the
		 ** mutex protected linked list of all such files.  */
		if (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FiVersion < int32(2) || (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmLock == uintptr(0) {
			(*Tsqlite3_file)(unsafe.Pointer(pFile)).FpMethods = uintptr(unsafe.Pointer(&_rbuvfs_io_methods1))
		} else {
			(*Tsqlite3_file)(unsafe.Pointer(pFile)).FpMethods = uintptr(unsafe.Pointer(&_rbuvfs_io_methods))
		}
		if flags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
			_rbuMainlistAdd(tls, pFd)
		}
	} else {
		Xsqlite3_free(tls, (*Trbu_file)(unsafe.Pointer(pFd)).FzDel)
	}
	return rc
}

var _rbuvfs_io_methods = Tsqlite3_io_methods{
	FiVersion: int32(2),
}

func init() {
	p := unsafe.Pointer(&_rbuvfs_io_methods)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_rbuVfsClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_rbuVfsRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_rbuVfsWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rbuVfsTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rbuVfsSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rbuVfsFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rbuVfsLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rbuVfsUnlock)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rbuVfsCheckReservedLock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rbuVfsFileControl)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rbuVfsSectorSize)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rbuVfsDeviceCharacteristics)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_rbuVfsShmMap)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rbuVfsShmLock)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rbuVfsShmBarrier)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rbuVfsShmUnmap)
}

var _rbuvfs_io_methods1 = Tsqlite3_io_methods{
	FiVersion: int32(1),
}

func init() {
	p := unsafe.Pointer(&_rbuvfs_io_methods1)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_rbuVfsClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_rbuVfsRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_rbuVfsWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rbuVfsTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rbuVfsSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rbuVfsFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rbuVfsLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rbuVfsUnlock)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rbuVfsCheckReservedLock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rbuVfsFileControl)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rbuVfsSectorSize)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rbuVfsDeviceCharacteristics)
}

// C documentation
//
//	/*
//	** Delete the file located at zPath.
//	*/
func _rbuVfsDelete(tls *libc.TLS, pVfs uintptr, zPath uintptr, dirSync int32) (r int32) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDelete})))(tls, pRealVfs, zPath, dirSync)
}

// C documentation
//
//	/*
//	** Test for access permissions. Return true if the requested permission
//	** is available, or false otherwise.
//	*/
func _rbuVfsAccess(tls *libc.TLS, pVfs uintptr, zPath uintptr, flags int32, pResOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pDb, pRbuVfs, pRealVfs uintptr
	var rc int32
	var _ /* sz at bp+0 */ Tsqlite3_int64
	_, _, _, _ = pDb, pRbuVfs, pRealVfs, rc
	pRbuVfs = pVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRealVfs
	rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxAccess})))(tls, pRealVfs, zPath, flags, pResOut)
	/* If this call is to check if a *-wal file associated with an RBU target
	 ** database connection exists, and the RBU update is in RBU_STAGE_OAL,
	 ** the following special handling is activated:
	 **
	 **   a) if the *-wal file does exist, return SQLITE_CANTOPEN. This
	 **      ensures that the RBU extension never tries to update a database
	 **      in wal mode, even if the first page of the database file has
	 **      been damaged.
	 **
	 **   b) if the *-wal file does not exist, claim that it does anyway,
	 **      causing SQLite to call xOpen() to open it. This call will also
	 **      be intercepted (see the rbuVfsOpen() function) and the *-oal
	 **      file opened instead.
	 */
	if rc == SQLITE_OK && flags == SQLITE_ACCESS_EXISTS {
		pDb = _rbuFindMaindb(tls, pRbuVfs, zPath, int32(1))
		if pDb != 0 && (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pDb)).FpRbu)).FeStage == int32(RBU_STAGE_OAL) {
			if *(*int32)(unsafe.Pointer(pResOut)) != 0 {
				rc = int32(SQLITE_CANTOPEN)
			} else {
				*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = 0
				rc = _rbuVfsFileSize(tls, pDb, bp)
				*(*int32)(unsafe.Pointer(pResOut)) = libc.BoolInt32(*(*Tsqlite3_int64)(unsafe.Pointer(bp)) > 0)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Populate buffer zOut with the full canonical pathname corresponding
//	** to the pathname in zPath. zOut is guaranteed to point to a buffer
//	** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
//	*/
func _rbuVfsFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nOut int32, zOut uintptr) (r int32) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxFullPathname})))(tls, pRealVfs, zPath, nOut, zOut)
}

// C documentation
//
//	/*
//	** Open the dynamic library located at zPath and return a handle.
//	*/
func _rbuVfsDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) (r uintptr) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlOpen})))(tls, pRealVfs, zPath)
}

// C documentation
//
//	/*
//	** Populate the buffer zErrMsg (size nByte bytes) with a human readable
//	** utf-8 string describing the most recent error encountered associated
//	** with dynamic libraries.
//	*/
func _rbuVfsDlError(tls *libc.TLS, pVfs uintptr, nByte int32, zErrMsg uintptr) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlError})))(tls, pRealVfs, nByte, zErrMsg)
}

// C documentation
//
//	/*
//	** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
//	*/
func _rbuVfsDlSym(tls *libc.TLS, pVfs uintptr, pArg uintptr, zSym uintptr) (r uintptr) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlSym})))(tls, pRealVfs, pArg, zSym)
}

// C documentation
//
//	/*
//	** Close the dynamic library handle pHandle.
//	*/
func _rbuVfsDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlClose})))(tls, pRealVfs, pHandle)
}

// C documentation
//
//	/*
//	** Populate the buffer pointed to by zBufOut with nByte bytes of
//	** random data.
//	*/
func _rbuVfsRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zBufOut uintptr) (r int32) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxRandomness})))(tls, pRealVfs, nByte, zBufOut)
}

// C documentation
//
//	/*
//	** Sleep for nMicro microseconds. Return the number of microseconds
//	** actually slept.
//	*/
func _rbuVfsSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) (r int32) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxSleep})))(tls, pRealVfs, nMicro)
}

// C documentation
//
//	/*
//	** Return the current time as a Julian Day number in *pTimeOut.
//	*/
func _rbuVfsCurrentTime(tls *libc.TLS, pVfs uintptr, pTimeOut uintptr) (r int32) {
	var pRealVfs uintptr
	_ = pRealVfs
	pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxCurrentTime})))(tls, pRealVfs, pTimeOut)
}

// C documentation
//
//	/*
//	** No-op.
//	*/
func _rbuVfsGetLastError(tls *libc.TLS, pVfs uintptr, a int32, b uintptr) (r int32) {
	return 0
}

// C documentation
//
//	/*
//	** Deregister and destroy an RBU vfs created by an earlier call to
//	** sqlite3rbu_create_vfs().
//	*/
func Xsqlite3rbu_destroy_vfs(tls *libc.TLS, zName uintptr) {
	var pVfs uintptr
	_ = pVfs
	pVfs = Xsqlite3_vfs_find(tls, zName)
	if pVfs != 0 && (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FxOpen == __ccgo_fp(_rbuVfsOpen) {
		Xsqlite3_mutex_free(tls, (*Trbu_vfs)(unsafe.Pointer(pVfs)).Fmutex)
		Xsqlite3_vfs_unregister(tls, pVfs)
		Xsqlite3_free(tls, pVfs)
	}
}

// C documentation
//
//	/*
//	** Create an RBU VFS named zName that accesses the underlying file-system
//	** via existing VFS zParent. The new object is registered as a non-default
//	** VFS with SQLite before returning.
//	*/
func Xsqlite3rbu_create_vfs(tls *libc.TLS, zName uintptr, zParent uintptr) (r int32) {
	var nByte, nName Tsize_t
	var pNew, pParent, zSpace, v1 uintptr
	var rc int32
	_, _, _, _, _, _, _ = nByte, nName, pNew, pParent, rc, zSpace, v1
	pNew = uintptr(0) /* Newly allocated VFS */
	rc = SQLITE_OK
	nName = libc.Xstrlen(tls, zName)
	nByte = uint32(108) + nName + uint32(1)
	pNew = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	if pNew == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else { /* Parent VFS */
		libc.Xmemset(tls, pNew, 0, nByte)
		pParent = Xsqlite3_vfs_find(tls, zParent)
		if pParent == uintptr(0) {
			rc = int32(SQLITE_NOTFOUND)
		} else {
			libc.Xmemcpy(tls, pNew, uintptr(unsafe.Pointer(&_vfs_template)), uint32(88))
			(*Trbu_vfs)(unsafe.Pointer(pNew)).Fbase.FmxPathname = (*Tsqlite3_vfs)(unsafe.Pointer(pParent)).FmxPathname
			(*Trbu_vfs)(unsafe.Pointer(pNew)).Fbase.FszOsFile = int32(uint32(64) + uint32((*Tsqlite3_vfs)(unsafe.Pointer(pParent)).FszOsFile))
			(*Trbu_vfs)(unsafe.Pointer(pNew)).FpRealVfs = pParent
			v1 = pNew + 1*108
			zSpace = v1
			(*Trbu_vfs)(unsafe.Pointer(pNew)).Fbase.FzName = v1
			libc.Xmemcpy(tls, zSpace, zName, nName)
			/* Allocate the mutex and register the new VFS (not as the default) */
			(*Trbu_vfs)(unsafe.Pointer(pNew)).Fmutex = Xsqlite3_mutex_alloc(tls, int32(SQLITE_MUTEX_RECURSIVE))
			if (*Trbu_vfs)(unsafe.Pointer(pNew)).Fmutex == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				rc = Xsqlite3_vfs_register(tls, pNew, 0)
			}
		}
		if rc != SQLITE_OK {
			Xsqlite3_mutex_free(tls, (*Trbu_vfs)(unsafe.Pointer(pNew)).Fmutex)
			Xsqlite3_free(tls, pNew)
		}
	}
	return rc
}

/* Template for VFS */
var _vfs_template = Tsqlite3_vfs{
	FiVersion: int32(1),
}

func init() {
	p := unsafe.Pointer(&_vfs_template)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rbuVfsOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rbuVfsDelete)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rbuVfsAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rbuVfsFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rbuVfsDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rbuVfsDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rbuVfsDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_rbuVfsDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rbuVfsRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rbuVfsSleep)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rbuVfsCurrentTime)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_rbuVfsGetLastError)
}

// C documentation
//
//	/*
//	** Configure the aggregate temp file size limit for this RBU handle.
//	*/
func Xsqlite3rbu_temp_size_limit(tls *libc.TLS, pRbu uintptr, n Tsqlite3_int64) (r Tsqlite3_int64) {
	if n >= 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit = n
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit
}

func Xsqlite3rbu_temp_size(tls *libc.TLS, pRbu uintptr) (r Tsqlite3_int64) {
	return (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FszTemp
}

/**************************************************************************/

/************** End of sqlite3rbu.c ******************************************/
/************** Begin file dbstat.c ******************************************/
/*
** 2010 July 12
**
** 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 an implementation of the "dbstat" virtual table.
**
** The dbstat virtual table is used to extract low-level storage
** information from an SQLite database in order to implement the
** "sqlite3_analyzer" utility.  See the ../tool/spaceanal.tcl script
** for an example implementation.
**
** Additional information is available on the "dbstat.html" page of the
** official SQLite documentation.
 */

/* #include "sqliteInt.h"   ** Requires access to internal data structures ** */

/*
** The pager and btree modules arrange objects in memory so that there are
** always approximately 200 bytes of addressable memory following each page
** buffer. This way small buffer overreads caused by corrupt database pages
** do not cause undefined behaviour. This module pads each page buffer
** by the following number of bytes for the same purpose.
 */

// C documentation
//
//	/*
//	** Page paths:
//	**
//	**   The value of the 'path' column describes the path taken from the
//	**   root-node of the b-tree structure to each page. The value of the
//	**   root-node path is '/'.
//	**
//	**   The value of the path for the left-most child page of the root of
//	**   a b-tree is '/000/'. (Btrees store content ordered from left to right
//	**   so the pages to the left have smaller keys than the pages to the right.)
//	**   The next to left-most child of the root page is
//	**   '/001', and so on, each sibling page identified by a 3-digit hex
//	**   value. The children of the 451st left-most sibling have paths such
//	**   as '/1c2/000/, '/1c2/001/' etc.
//	**
//	**   Overflow pages are specified by appending a '+' character and a
//	**   six-digit hexadecimal value to the path to the cell they are linked
//	**   from. For example, the three overflow pages in a chain linked from
//	**   the left-most cell of the 450th child of the root page are identified
//	**   by the paths:
//	**
//	**      '/1c2/000+000000'         // First page in overflow chain
//	**      '/1c2/000+000001'         // Second page in overflow chain
//	**      '/1c2/000+000002'         // Third page in overflow chain
//	**
//	**   If the paths are sorted using the BINARY collation sequence, then
//	**   the overflow pages associated with a cell will appear earlier in the
//	**   sort-order than its child page:
//	**
//	**      '/1c2/000/'               // Left-most child of 451st child of root
//	*/
var _zDbstatSchema = [258]int8{'C', 'R', 'E', 'A', 'T', 'E', ' ', 'T', 'A', 'B', 'L', 'E', ' ', 'x', '(', ' ', 'n', 'a', 'm', 'e', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'T', 'E', 'X', 'T', ',', ' ', 'p', 'a', 't', 'h', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'T', 'E', 'X', 'T', ',', ' ', 'p', 'a', 'g', 'e', 'n', 'o', ' ', ' ', ' ', ' ', ' ', 'I', 'N', 'T', 'E', 'G', 'E', 'R', ',', ' ', 'p', 'a', 'g', 'e', 't', 'y', 'p', 'e', ' ', ' ', ' ', 'T', 'E', 'X', 'T', ',', ' ', 'n', 'c', 'e', 'l', 'l', ' ', ' ', ' ', ' ', ' ', ' ', 'I', 'N', 'T', 'E', 'G', 'E', 'R', ',', ' ', 'p', 'a', 'y', 'l', 'o', 'a', 'd', ' ', ' ', ' ', ' ', 'I', 'N', 'T', 'E', 'G', 'E', 'R', ',', ' ', 'u', 'n', 'u', 's', 'e', 'd', ' ', ' ', ' ', ' ', ' ', 'I', 'N', 'T', 'E', 'G', 'E', 'R', ',', ' ', 'm', 'x', '_', 'p', 'a', 'y', 'l', 'o', 'a', 'd', ' ', 'I', 'N', 'T', 'E', 'G', 'E', 'R', ',', ' ', 'p', 'g', 'o', 'f', 'f', 's', 'e', 't', ' ', ' ', ' ', 'I', 'N', 'T', 'E', 'G', 'E', 'R', ',', ' ', 'p', 'g', 's', 'i', 'z', 'e', ' ', ' ', ' ', ' ', ' ', 'I', 'N', 'T', 'E', 'G', 'E', 'R', ',', ' ', 's', 'c', 'h', 'e', 'm', 'a', ' ', ' ', ' ', ' ', ' ', 'T', 'E', 'X', 'T', ' ', 'H', 'I', 'D', 'D', 'E', 'N', ',', ' ', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', 'e', ' ', ' ', 'B', 'O', 'O', 'L', 'E', 'A', 'N', ' ', 'H', 'I', 'D', 'D', 'E', 'N', ')'}

// C documentation
//
//	/* Forward reference to data structured used in this module */
type TStatTable = struct {
	Fbase Tsqlite3_vtab
	Fdb   uintptr
	FiDb  int32
}

type StatTable = TStatTable

type TStatCursor = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FpStmt        uintptr
	FisEof        Tu8
	FisAgg        Tu8
	FiDb          int32
	FaPage        [32]TStatPage
	FiPage        int32
	FiPageno      Tu32
	FzName        uintptr
	FzPath        uintptr
	FzPagetype    uintptr
	FnPage        int32
	FnCell        int32
	FnMxPayload   int32
	FnUnused      Ti64
	FnPayload     Ti64
	FiOffset      Ti64
	FszPage       Ti64
}

type StatCursor = TStatCursor

type TStatPage = struct {
	FiPgno         Tu32
	FaPg           uintptr
	FiCell         int32
	FzPath         uintptr
	Fflags         Tu8
	FnCell         int32
	FnUnused       int32
	FaCell         uintptr
	FiRightChildPg Tu32
	FnMxPayload    int32
}

type StatPage = TStatPage

type TStatCell = struct {
	FnLocal    int32
	FiChildPg  Tu32
	FnOvfl     int32
	FaOvfl     uintptr
	FnLastOvfl int32
	FiOvfl     int32
}

type StatCell = TStatCell

/* Size information for a single cell within a btree page */
type TStatCell1 = struct {
	FnLocal    int32
	FiChildPg  Tu32
	FnOvfl     int32
	FaOvfl     uintptr
	FnLastOvfl int32
	FiOvfl     int32
}

type StatCell1 = TStatCell1

/* Size information for a single btree page */
type TStatPage1 = struct {
	FiPgno         Tu32
	FaPg           uintptr
	FiCell         int32
	FzPath         uintptr
	Fflags         Tu8
	FnCell         int32
	FnUnused       int32
	FaCell         uintptr
	FiRightChildPg Tu32
	FnMxPayload    int32
}

type StatPage1 = TStatPage1

/* The cursor for scanning the dbstat virtual table */
type TStatCursor1 = struct {
	F__ccgo_align [0]uint32
	Fbase         Tsqlite3_vtab_cursor
	FpStmt        uintptr
	FisEof        Tu8
	FisAgg        Tu8
	FiDb          int32
	FaPage        [32]TStatPage
	FiPage        int32
	FiPageno      Tu32
	FzName        uintptr
	FzPath        uintptr
	FzPagetype    uintptr
	FnPage        int32
	FnCell        int32
	FnMxPayload   int32
	FnUnused      Ti64
	FnPayload     Ti64
	FiOffset      Ti64
	FszPage       Ti64
}

type StatCursor1 = TStatCursor1

/* An instance of the DBSTAT virtual table */
type TStatTable1 = struct {
	Fbase Tsqlite3_vtab
	Fdb   uintptr
	FiDb  int32
}

type StatTable1 = TStatTable1

// C documentation
//
//	/*
//	** Connect to or create a new DBSTAT virtual table.
//	*/
func _statConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iDb, rc int32
	var pTab uintptr
	var _ /* nm at bp+0 */ TToken
	_, _, _ = iDb, pTab, rc
	pTab = uintptr(0)
	rc = SQLITE_OK
	_ = pAux
	if argc >= int32(4) {
		_sqlite3TokenInit(tls, bp, *(*uintptr)(unsafe.Pointer(argv + 3*4)))
		iDb = _sqlite3FindDb(tls, db, bp)
		if iDb < 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+13625, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(argv + 3*4))))
			return int32(SQLITE_ERROR)
		}
	} else {
		iDb = 0
	}
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_DIRECTONLY), 0)
	rc = Xsqlite3_declare_vtab(tls, db, uintptr(unsafe.Pointer(&_zDbstatSchema)))
	if rc == SQLITE_OK {
		pTab = Xsqlite3_malloc64(tls, uint64(20))
		if pTab == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	if rc == SQLITE_OK {
		libc.Xmemset(tls, pTab, 0, uint32(20))
		(*TStatTable)(unsafe.Pointer(pTab)).Fdb = db
		(*TStatTable)(unsafe.Pointer(pTab)).FiDb = iDb
	}
	*(*uintptr)(unsafe.Pointer(ppVtab)) = pTab
	return rc
}

// C documentation
//
//	/*
//	** Disconnect from or destroy the DBSTAT virtual table.
//	*/
func _statDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	Xsqlite3_free(tls, pVtab)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Compute the best query strategy and return the result in idxNum.
//	**
//	**   idxNum-Bit        Meaning
//	**   ----------        ----------------------------------------------
//	**      0x01           There is a schema=? term in the WHERE clause
//	**      0x02           There is a name=? term in the WHERE clause
//	**      0x04           There is an aggregate=? term in the WHERE clause
//	**      0x08           Output should be ordered by name and path
//	*/
func _statBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
	var i, iAgg, iName, iSchema, v2, v3, v4 int32
	_, _, _, _, _, _, _ = i, iAgg, iName, iSchema, v2, v3, v4
	iSchema = -int32(1)
	iName = -int32(1)
	iAgg = -int32(1)
	_ = tab
	/* Look for a valid schema=? constraint.  If found, change the idxNum to
	 ** 1 and request the value of that constraint be sent to xFilter.  And
	 ** lower the cost estimate to encourage the constrained version to be
	 ** used.
	 */
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		if int32((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fop) != int32(SQLITE_INDEX_CONSTRAINT_EQ) {
			goto _1
		}
		if int32((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fusable) == 0 {
			/* Force DBSTAT table should always be the right-most table in a join */
			return int32(SQLITE_CONSTRAINT)
		}
		switch (*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).FiColumn {
		case 0: /* name */
			iName = i
		case int32(10): /* schema */
			iSchema = i
		case int32(11): /* aggregate */
			iAgg = i
			break
		}
		goto _1
	_1:
		;
		i++
	}
	i = 0
	if iSchema >= 0 {
		i++
		v2 = i
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iSchema)*8))).FargvIndex = v2
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iSchema)*8))).Fomit = uint8(1)
		*(*int32)(unsafe.Pointer(pIdxInfo + 20)) |= int32(0x01)
	}
	if iName >= 0 {
		i++
		v3 = i
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iName)*8))).FargvIndex = v3
		*(*int32)(unsafe.Pointer(pIdxInfo + 20)) |= int32(0x02)
	}
	if iAgg >= 0 {
		i++
		v4 = i
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iAgg)*8))).FargvIndex = v4
		*(*int32)(unsafe.Pointer(pIdxInfo + 20)) |= int32(0x04)
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(1)
	/* Records are always returned in ascending order of (name, path).
	 ** If this will satisfy the client, set the orderByConsumed flag so that
	 ** SQLite does not do an external sort.
	 */
	if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy == int32(1) && (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).FiColumn == 0 && int32((*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).Fdesc) == 0 || (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy == int32(2) && (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).FiColumn == 0 && int32((*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).Fdesc) == 0 && (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy + 1*8))).FiColumn == int32(1) && int32((*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy + 1*8))).Fdesc) == 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = int32(1)
		*(*int32)(unsafe.Pointer(pIdxInfo + 20)) |= int32(0x08)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Open a new DBSTAT cursor.
//	*/
func _statOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) (r int32) {
	var pCsr, pTab uintptr
	_, _ = pCsr, pTab
	pTab = pVTab
	pCsr = Xsqlite3_malloc64(tls, uint64(1360))
	if pCsr == uintptr(0) {
		return int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, pCsr, 0, uint32(1360))
		(*TStatCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = (*TStatTable)(unsafe.Pointer(pTab)).FiDb
	}
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCsr
	return SQLITE_OK
}

func _statClearCells(tls *libc.TLS, p uintptr) {
	var i int32
	_ = i
	if (*TStatPage)(unsafe.Pointer(p)).FaCell != 0 {
		i = 0
		for {
			if !(i < (*TStatPage)(unsafe.Pointer(p)).FnCell) {
				break
			}
			Xsqlite3_free(tls, (*(*TStatCell)(unsafe.Pointer((*TStatPage)(unsafe.Pointer(p)).FaCell + uintptr(i)*24))).FaOvfl)
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, (*TStatPage)(unsafe.Pointer(p)).FaCell)
	}
	(*TStatPage)(unsafe.Pointer(p)).FnCell = 0
	(*TStatPage)(unsafe.Pointer(p)).FaCell = uintptr(0)
}

func _statClearPage(tls *libc.TLS, p uintptr) {
	var aPg uintptr
	_ = aPg
	aPg = (*TStatPage)(unsafe.Pointer(p)).FaPg
	_statClearCells(tls, p)
	Xsqlite3_free(tls, (*TStatPage)(unsafe.Pointer(p)).FzPath)
	libc.Xmemset(tls, p, 0, uint32(40))
	(*TStatPage)(unsafe.Pointer(p)).FaPg = aPg
}

func _statResetCsr(tls *libc.TLS, pCsr uintptr) {
	var i int32
	_ = i
	/* In some circumstances, specifically if an OOM has occurred, the call
	 ** to sqlite3_reset() may cause the pager to be reset (emptied). It is
	 ** important that statClearPage() is called to free any page refs before
	 ** this happens. dbsqlfuzz 9ed3e4e3816219d3509d711636c38542bf3f40b1. */
	i = 0
	for {
		if !(i < int32(libc.Uint32FromInt64(1280)/libc.Uint32FromInt64(40))) {
			break
		}
		_statClearPage(tls, pCsr+16+uintptr(i)*40)
		Xsqlite3_free(tls, (*(*TStatPage)(unsafe.Pointer(pCsr + 16 + uintptr(i)*40))).FaPg)
		(*(*TStatPage)(unsafe.Pointer(pCsr + 16 + uintptr(i)*40))).FaPg = uintptr(0)
		goto _1
	_1:
		;
		i++
	}
	Xsqlite3_reset(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage = 0
	Xsqlite3_free(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FzPath)
	(*TStatCursor)(unsafe.Pointer(pCsr)).FzPath = uintptr(0)
	(*TStatCursor)(unsafe.Pointer(pCsr)).FisEof = uint8(0)
}

// C documentation
//
//	/* Resize the space-used counters inside of the cursor */
func _statResetCounts(tls *libc.TLS, pCsr uintptr) {
	(*TStatCursor)(unsafe.Pointer(pCsr)).FnCell = 0
	(*TStatCursor)(unsafe.Pointer(pCsr)).FnMxPayload = 0
	(*TStatCursor)(unsafe.Pointer(pCsr)).FnUnused = 0
	(*TStatCursor)(unsafe.Pointer(pCsr)).FnPayload = 0
	(*TStatCursor)(unsafe.Pointer(pCsr)).FszPage = 0
	(*TStatCursor)(unsafe.Pointer(pCsr)).FnPage = 0
}

// C documentation
//
//	/*
//	** Close a DBSTAT cursor.
//	*/
func _statClose(tls *libc.TLS, pCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCursor
	_statResetCsr(tls, pCsr)
	Xsqlite3_finalize(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** For a single cell on a btree page, compute the number of bytes of
//	** content (payload) stored on that page.  That is to say, compute the
//	** number of bytes of content not found on overflow pages.
//	*/
func _getLocalPayload(tls *libc.TLS, nUsable int32, flags Tu8, nTotal int32) (r int32) {
	var nLocal, nMaxLocal, nMinLocal int32
	_, _, _ = nLocal, nMaxLocal, nMinLocal
	if int32(int32(flags)) == int32(0x0D) { /* Table leaf node */
		nMinLocal = (nUsable-int32(12))*int32(32)/int32(255) - int32(23)
		nMaxLocal = nUsable - int32(35)
	} else { /* Index interior and leaf nodes */
		nMinLocal = (nUsable-int32(12))*int32(32)/int32(255) - int32(23)
		nMaxLocal = (nUsable-int32(12))*int32(64)/int32(255) - int32(23)
	}
	nLocal = nMinLocal + (nTotal-nMinLocal)%(nUsable-int32(4))
	if nLocal > nMaxLocal {
		nLocal = nMinLocal
	}
	return nLocal
}

// C documentation
//
//	/* Populate the StatPage object with information about the all
//	** cells found on the page currently under analysis.
//	*/
func _statDecodePage(tls *libc.TLS, pBt uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aData, aHdr, pCell uintptr
	var i, iNext, iOff, isLeaf, j, nHdr, nLocal, nOvfl, nUnused, nUsable, rc, szPage, v1, v4 int32
	var iPrev Tu32
	var v2 uint32
	var _ /* dummy at bp+8 */ Tu64
	var _ /* nPayload at bp+0 */ Tu32
	var _ /* pPg at bp+16 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aHdr, i, iNext, iOff, iPrev, isLeaf, j, nHdr, nLocal, nOvfl, nUnused, nUsable, pCell, rc, szPage, v1, v2, v4
	aData = (*TStatPage)(unsafe.Pointer(p)).FaPg
	if (*TStatPage)(unsafe.Pointer(p)).FiPgno == uint32(1) {
		v1 = int32(100)
	} else {
		v1 = 0
	}
	aHdr = aData + uintptr(v1)
	(*TStatPage)(unsafe.Pointer(p)).Fflags = *(*Tu8)(unsafe.Pointer(aHdr))
	if int32((*TStatPage)(unsafe.Pointer(p)).Fflags) == int32(0x0A) || int32((*TStatPage)(unsafe.Pointer(p)).Fflags) == int32(0x0D) {
		isLeaf = int32(1)
		nHdr = int32(8)
	} else {
		if int32((*TStatPage)(unsafe.Pointer(p)).Fflags) == int32(0x05) || int32((*TStatPage)(unsafe.Pointer(p)).Fflags) == int32(0x02) {
			isLeaf = 0
			nHdr = int32(12)
		} else {
			goto statPageIsCorrupt
		}
	}
	if (*TStatPage)(unsafe.Pointer(p)).FiPgno == uint32(1) {
		nHdr += int32(100)
	}
	(*TStatPage)(unsafe.Pointer(p)).FnCell = int32(*(*Tu8)(unsafe.Pointer(aHdr + 3)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(aHdr + 3 + 1)))
	(*TStatPage)(unsafe.Pointer(p)).FnMxPayload = 0
	szPage = _sqlite3BtreeGetPageSize(tls, pBt)
	nUnused = int32(*(*Tu8)(unsafe.Pointer(aHdr + 5)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(aHdr + 5 + 1))) - nHdr - int32(2)*(*TStatPage)(unsafe.Pointer(p)).FnCell
	nUnused += int32(*(*Tu8)(unsafe.Pointer(aHdr + 7)))
	iOff = int32(*(*Tu8)(unsafe.Pointer(aHdr + 1)))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(aHdr + 1 + 1)))
	for iOff != 0 {
		if iOff >= szPage {
			goto statPageIsCorrupt
		}
		nUnused += int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(iOff+int32(2)))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(iOff+int32(2)) + 1)))
		iNext = int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(iOff))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(iOff) + 1)))
		if iNext < iOff+int32(4) && iNext > 0 {
			goto statPageIsCorrupt
		}
		iOff = iNext
	}
	(*TStatPage)(unsafe.Pointer(p)).FnUnused = nUnused
	if isLeaf != 0 {
		v2 = uint32(0)
	} else {
		v2 = _sqlite3Get4byte(tls, aHdr+8)
	}
	(*TStatPage)(unsafe.Pointer(p)).FiRightChildPg = v2
	if (*TStatPage)(unsafe.Pointer(p)).FnCell != 0 { /* Usable bytes per page */
		_sqlite3BtreeEnter(tls, pBt)
		nUsable = szPage - _sqlite3BtreeGetReserveNoMutex(tls, pBt)
		_sqlite3BtreeLeave(tls, pBt)
		(*TStatPage)(unsafe.Pointer(p)).FaCell = Xsqlite3_malloc64(tls, uint64(uint32((*TStatPage)(unsafe.Pointer(p)).FnCell+libc.Int32FromInt32(1))*uint32(24)))
		if (*TStatPage)(unsafe.Pointer(p)).FaCell == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, (*TStatPage)(unsafe.Pointer(p)).FaCell, 0, uint32((*TStatPage)(unsafe.Pointer(p)).FnCell+libc.Int32FromInt32(1))*uint32(24))
		i = 0
		for {
			if !(i < (*TStatPage)(unsafe.Pointer(p)).FnCell) {
				break
			}
			pCell = (*TStatPage)(unsafe.Pointer(p)).FaCell + uintptr(i)*24
			iOff = int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(nHdr+i*int32(2)))))<<int32(8) | int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(nHdr+i*int32(2)) + 1)))
			if iOff < nHdr || iOff >= szPage {
				goto statPageIsCorrupt
			}
			if !(isLeaf != 0) {
				(*TStatCell)(unsafe.Pointer(pCell)).FiChildPg = _sqlite3Get4byte(tls, aData+uintptr(iOff))
				iOff += int32(4)
			}
			if int32((*TStatPage)(unsafe.Pointer(p)).Fflags) == int32(0x05) {
				/* A table interior node. nPayload==0. */
			} else { /* Bytes of payload stored locally */
				if int32(*(*Tu8)(unsafe.Pointer(aData + uintptr(iOff)))) < int32(libc.Uint8FromInt32(0x80)) {
					*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(aData + uintptr(iOff))))
					v4 = libc.Int32FromInt32(1)
				} else {
					v4 = int32(_sqlite3GetVarint32(tls, aData+uintptr(iOff), bp))
				}
				iOff += int32(uint8(v4))
				if int32((*TStatPage)(unsafe.Pointer(p)).Fflags) == int32(0x0D) {
					iOff += int32(_sqlite3GetVarint(tls, aData+uintptr(iOff), bp+8))
				}
				if *(*Tu32)(unsafe.Pointer(bp)) > uint32((*TStatPage)(unsafe.Pointer(p)).FnMxPayload) {
					(*TStatPage)(unsafe.Pointer(p)).FnMxPayload = int32(*(*Tu32)(unsafe.Pointer(bp)))
				}
				nLocal = _getLocalPayload(tls, nUsable, (*TStatPage)(unsafe.Pointer(p)).Fflags, int32(*(*Tu32)(unsafe.Pointer(bp))))
				if nLocal < 0 {
					goto statPageIsCorrupt
				}
				(*TStatCell)(unsafe.Pointer(pCell)).FnLocal = nLocal
				if *(*Tu32)(unsafe.Pointer(bp)) > uint32(uint32(nLocal)) {
					nOvfl = int32((*(*Tu32)(unsafe.Pointer(bp)) - uint32(uint32(nLocal)) + uint32(uint32(nUsable)) - uint32(4) - uint32(1)) / uint32(nUsable-libc.Int32FromInt32(4)))
					if iOff+nLocal+int32(4) > nUsable || *(*Tu32)(unsafe.Pointer(bp)) > uint32(0x7fffffff) {
						goto statPageIsCorrupt
					}
					(*TStatCell)(unsafe.Pointer(pCell)).FnLastOvfl = int32(*(*Tu32)(unsafe.Pointer(bp)) - uint32(uint32(nLocal)) - uint32((nOvfl-int32(1))*(nUsable-int32(4))))
					(*TStatCell)(unsafe.Pointer(pCell)).FnOvfl = nOvfl
					(*TStatCell)(unsafe.Pointer(pCell)).FaOvfl = Xsqlite3_malloc64(tls, uint64(uint32(4)*uint32(uint32(nOvfl))))
					if (*TStatCell)(unsafe.Pointer(pCell)).FaOvfl == uintptr(0) {
						return int32(SQLITE_NOMEM)
					}
					*(*Tu32)(unsafe.Pointer((*TStatCell)(unsafe.Pointer(pCell)).FaOvfl)) = _sqlite3Get4byte(tls, aData+uintptr(iOff+nLocal))
					j = int32(1)
					for {
						if !(j < nOvfl) {
							break
						}
						iPrev = *(*Tu32)(unsafe.Pointer((*TStatCell)(unsafe.Pointer(pCell)).FaOvfl + uintptr(j-int32(1))*4))
						*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
						rc = _sqlite3PagerGet(tls, _sqlite3BtreePager(tls, pBt), iPrev, bp+16, 0)
						if rc != SQLITE_OK {
							return rc
						}
						*(*Tu32)(unsafe.Pointer((*TStatCell)(unsafe.Pointer(pCell)).FaOvfl + uintptr(j)*4)) = _sqlite3Get4byte(tls, _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 16))))
						_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
						goto _5
					_5:
						;
						j++
					}
				}
			}
			goto _3
		_3:
			;
			i++
		}
	}
	return SQLITE_OK
	goto statPageIsCorrupt
statPageIsCorrupt:
	;
	(*TStatPage)(unsafe.Pointer(p)).Fflags = uint8(0)
	_statClearCells(tls, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
//	** the current value of pCsr->iPageno.
//	*/
func _statSizeAndOffset(tls *libc.TLS, pCsr uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var fd, pBt, pPager, pTab uintptr
	var _ /* x at bp+0 */ [2]Tsqlite3_int64
	_, _, _, _ = fd, pBt, pPager, pTab
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCsr)).FpVtab
	pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TStatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*TStatTable)(unsafe.Pointer(pTab)).FiDb)*16))).FpBt
	pPager = _sqlite3BtreePager(tls, pBt)
	/* If connected to a ZIPVFS backend, find the page size and
	 ** offset from ZIPVFS.
	 */
	fd = _sqlite3PagerFile(tls, pPager)
	(*(*[2]Tsqlite3_int64)(unsafe.Pointer(bp)))[0] = int64((*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno)
	if _sqlite3OsFileControl(tls, fd, int32(230440), bp) == SQLITE_OK {
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiOffset = (*(*[2]Tsqlite3_int64)(unsafe.Pointer(bp)))[0]
		*(*Ti64)(unsafe.Pointer(pCsr + 1352)) += (*(*[2]Tsqlite3_int64)(unsafe.Pointer(bp)))[int32(1)]
	} else {
		/* Not ZIPVFS: The default page size and offset */
		*(*Ti64)(unsafe.Pointer(pCsr + 1352)) += int64(_sqlite3BtreeGetPageSize(tls, pBt))
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiOffset = (*TStatCursor)(unsafe.Pointer(pCsr)).FszPage * int64((*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno-libc.Uint32FromInt32(1))
	}
}

// C documentation
//
//	/*
//	** Load a copy of the page data for page iPg into the buffer belonging
//	** to page object pPg. Allocate the buffer if necessary. Return SQLITE_OK
//	** if successful, or an SQLite error code otherwise.
//	*/
func _statGetPage(tls *libc.TLS, pBt uintptr, iPg Tu32, pPg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a uintptr
	var pgsz, rc int32
	var _ /* pDbPage at bp+0 */ uintptr
	_, _, _ = a, pgsz, rc
	pgsz = _sqlite3BtreeGetPageSize(tls, pBt)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	if (*TStatPage)(unsafe.Pointer(pPg)).FaPg == uintptr(0) {
		(*TStatPage)(unsafe.Pointer(pPg)).FaPg = Xsqlite3_malloc(tls, pgsz+int32(DBSTAT_PAGE_PADDING_BYTES))
		if (*TStatPage)(unsafe.Pointer(pPg)).FaPg == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, (*TStatPage)(unsafe.Pointer(pPg)).FaPg+uintptr(pgsz), 0, uint32(DBSTAT_PAGE_PADDING_BYTES))
	}
	rc = _sqlite3PagerGet(tls, _sqlite3BtreePager(tls, pBt), iPg, bp, 0)
	if rc == SQLITE_OK {
		a = _sqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
		libc.Xmemcpy(tls, (*TStatPage)(unsafe.Pointer(pPg)).FaPg, a, uint32(uint32(pgsz)))
		_sqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Move a DBSTAT cursor to the next entry.  Normally, the next
//	** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0),
//	** the next entry is the next btree.
//	*/
func _statNext(tls *libc.TLS, pCursor uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, iOvfl, nPayload, nUsable, rc, v3 int32
	var iRoot Tu32
	var p, p1, pBt, pCell, pCsr, pPager, pTab, z, v1, v2, v4, v5 uintptr
	var _ /* nPage at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iOvfl, iRoot, nPayload, nUsable, p, p1, pBt, pCell, pCsr, pPager, pTab, rc, z, v1, v2, v3, v4, v5
	pCsr = pCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pBt = (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TStatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiDb)*16))).FpBt
	pPager = _sqlite3BtreePager(tls, pBt)
	Xsqlite3_free(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FzPath)
	(*TStatCursor)(unsafe.Pointer(pCsr)).FzPath = uintptr(0)
	goto statNextRestart
statNextRestart:
	;
	if (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage < 0 {
		/* Start measuring space on the next btree */
		_statResetCounts(tls, pCsr)
		rc = Xsqlite3_step(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
		if rc == int32(SQLITE_ROW) {
			iRoot = uint32(Xsqlite3_column_int64(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1)))
			_sqlite3PagerPagecount(tls, pPager, bp)
			if *(*int32)(unsafe.Pointer(bp)) == 0 {
				(*TStatCursor)(unsafe.Pointer(pCsr)).FisEof = uint8(1)
				return Xsqlite3_reset(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
			}
			rc = _statGetPage(tls, pBt, iRoot, pCsr+16)
			(*(*TStatPage)(unsafe.Pointer(pCsr + 16))).FiPgno = iRoot
			(*(*TStatPage)(unsafe.Pointer(pCsr + 16))).FiCell = 0
			if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
				v1 = Xsqlite3_mprintf(tls, __ccgo_ts+34531, 0)
				z = v1
				(*(*TStatPage)(unsafe.Pointer(pCsr + 16))).FzPath = v1
				if z == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				}
			}
			(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage = 0
			(*TStatCursor)(unsafe.Pointer(pCsr)).FnPage = int32(1)
		} else {
			(*TStatCursor)(unsafe.Pointer(pCsr)).FisEof = uint8(1)
			return Xsqlite3_reset(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
		}
	} else {
		/* Continue analyzing the btree previously started */
		p = pCsr + 16 + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiPage)*40
		if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
			_statResetCounts(tls, pCsr)
		}
		for (*TStatPage)(unsafe.Pointer(p)).FiCell < (*TStatPage)(unsafe.Pointer(p)).FnCell {
			pCell = (*TStatPage)(unsafe.Pointer(p)).FaCell + uintptr((*TStatPage)(unsafe.Pointer(p)).FiCell)*24
			for (*TStatCell)(unsafe.Pointer(pCell)).FiOvfl < (*TStatCell)(unsafe.Pointer(pCell)).FnOvfl {
				_sqlite3BtreeEnter(tls, pBt)
				nUsable = _sqlite3BtreeGetPageSize(tls, pBt) - _sqlite3BtreeGetReserveNoMutex(tls, pBt)
				_sqlite3BtreeLeave(tls, pBt)
				(*TStatCursor)(unsafe.Pointer(pCsr)).FnPage++
				_statSizeAndOffset(tls, pCsr)
				if (*TStatCell)(unsafe.Pointer(pCell)).FiOvfl < (*TStatCell)(unsafe.Pointer(pCell)).FnOvfl-int32(1) {
					*(*Ti64)(unsafe.Pointer(pCsr + 1336)) += int64(nUsable - int32(4))
				} else {
					*(*Ti64)(unsafe.Pointer(pCsr + 1336)) += int64((*TStatCell)(unsafe.Pointer(pCell)).FnLastOvfl)
					*(*Ti64)(unsafe.Pointer(pCsr + 1328)) += int64(nUsable - int32(4) - (*TStatCell)(unsafe.Pointer(pCell)).FnLastOvfl)
				}
				iOvfl = (*TStatCell)(unsafe.Pointer(pCell)).FiOvfl
				(*TStatCell)(unsafe.Pointer(pCell)).FiOvfl++
				if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
					(*TStatCursor)(unsafe.Pointer(pCsr)).FzName = Xsqlite3_column_text(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
					(*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno = *(*Tu32)(unsafe.Pointer((*TStatCell)(unsafe.Pointer(pCell)).FaOvfl + uintptr(iOvfl)*4))
					(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34533
					v2 = Xsqlite3_mprintf(tls, __ccgo_ts+34542, libc.VaList(bp+16, (*TStatPage)(unsafe.Pointer(p)).FzPath, (*TStatPage)(unsafe.Pointer(p)).FiCell, iOvfl))
					z = v2
					(*TStatCursor)(unsafe.Pointer(pCsr)).FzPath = v2
					if z == uintptr(0) {
						v3 = int32(SQLITE_NOMEM)
					} else {
						v3 = SQLITE_OK
					}
					return v3
				}
			}
			if (*TStatPage)(unsafe.Pointer(p)).FiRightChildPg != 0 {
				break
			}
			(*TStatPage)(unsafe.Pointer(p)).FiCell++
		}
		if !((*TStatPage)(unsafe.Pointer(p)).FiRightChildPg != 0) || (*TStatPage)(unsafe.Pointer(p)).FiCell > (*TStatPage)(unsafe.Pointer(p)).FnCell {
			_statClearPage(tls, p)
			(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage--
			if (*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0 && (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage < 0 {
				/* label-statNext-done:  When computing aggregate space usage over
				 ** an entire btree, this is the exit point from this function */
				return SQLITE_OK
			}
			goto statNextRestart /* Tail recursion */
		}
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage++
		if (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage >= int32(libc.Uint32FromInt64(1280)/libc.Uint32FromInt64(40)) {
			_statResetCsr(tls, pCsr)
			return _sqlite3CorruptError(tls, int32(224206))
		}
		if (*TStatPage)(unsafe.Pointer(p)).FiCell == (*TStatPage)(unsafe.Pointer(p)).FnCell {
			(*(*TStatPage)(unsafe.Pointer(p + 1*40))).FiPgno = (*TStatPage)(unsafe.Pointer(p)).FiRightChildPg
		} else {
			(*(*TStatPage)(unsafe.Pointer(p + 1*40))).FiPgno = (*(*TStatCell)(unsafe.Pointer((*TStatPage)(unsafe.Pointer(p)).FaCell + uintptr((*TStatPage)(unsafe.Pointer(p)).FiCell)*24))).FiChildPg
		}
		rc = _statGetPage(tls, pBt, (*(*TStatPage)(unsafe.Pointer(p + 1*40))).FiPgno, p+1*40)
		(*TStatCursor)(unsafe.Pointer(pCsr)).FnPage++
		(*(*TStatPage)(unsafe.Pointer(p + 1*40))).FiCell = 0
		if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
			v4 = Xsqlite3_mprintf(tls, __ccgo_ts+34554, libc.VaList(bp+16, (*TStatPage)(unsafe.Pointer(p)).FzPath, (*TStatPage)(unsafe.Pointer(p)).FiCell))
			z = v4
			(*(*TStatPage)(unsafe.Pointer(p + 1*40))).FzPath = v4
			if z == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			}
		}
		(*TStatPage)(unsafe.Pointer(p)).FiCell++
	}
	/* Populate the StatCursor fields with the values to be returned
	 ** by the xColumn() and xRowid() methods.
	 */
	if rc == SQLITE_OK {
		p1 = pCsr + 16 + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiPage)*40
		(*TStatCursor)(unsafe.Pointer(pCsr)).FzName = Xsqlite3_column_text(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno = (*TStatPage)(unsafe.Pointer(p1)).FiPgno
		rc = _statDecodePage(tls, pBt, p1)
		if rc == SQLITE_OK {
			_statSizeAndOffset(tls, pCsr)
			switch int32((*TStatPage)(unsafe.Pointer(p1)).Fflags) {
			case int32(0x05): /* table internal */
				fallthrough
			case int32(0x02): /* index internal */
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34562
			case int32(0x0D): /* table leaf */
				fallthrough
			case int32(0x0A): /* index leaf */
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34571
			default:
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34576
				break
			}
			*(*int32)(unsafe.Pointer(pCsr + 1320)) += (*TStatPage)(unsafe.Pointer(p1)).FnCell
			*(*Ti64)(unsafe.Pointer(pCsr + 1328)) += int64((*TStatPage)(unsafe.Pointer(p1)).FnUnused)
			if (*TStatPage)(unsafe.Pointer(p1)).FnMxPayload > (*TStatCursor)(unsafe.Pointer(pCsr)).FnMxPayload {
				(*TStatCursor)(unsafe.Pointer(pCsr)).FnMxPayload = (*TStatPage)(unsafe.Pointer(p1)).FnMxPayload
			}
			if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
				v5 = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+16, (*TStatPage)(unsafe.Pointer(p1)).FzPath))
				z = v5
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPath = v5
				if z == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				}
			}
			nPayload = 0
			i = 0
			for {
				if !(i < (*TStatPage)(unsafe.Pointer(p1)).FnCell) {
					break
				}
				nPayload += (*(*TStatCell)(unsafe.Pointer((*TStatPage)(unsafe.Pointer(p1)).FaCell + uintptr(i)*24))).FnLocal
				goto _6
			_6:
				;
				i++
			}
			*(*Ti64)(unsafe.Pointer(pCsr + 1336)) += int64(int64(nPayload))
			/* If computing aggregate space usage by btree, continue with the
			 ** next page.  The loop will exit via the return at label-statNext-done
			 */
			if (*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0 {
				goto statNextRestart
			}
		}
	}
	return rc
}

func _statEof(tls *libc.TLS, pCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCursor
	return int32((*TStatCursor)(unsafe.Pointer(pCsr)).FisEof)
}

// C documentation
//
//	/* Initialize a cursor according to the query plan idxNum using the
//	** arguments in argv[0].  See statBestIndex() for a description of the
//	** meaning of the bits in idxNum.
//	*/
func _statFilter(tls *libc.TLS, pCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iArg, rc, v1, v2, v3 int32
	var pCsr, pSql, pTab, zDbase, zName, zSql uintptr
	_, _, _, _, _, _, _, _, _, _, _ = iArg, pCsr, pSql, pTab, rc, zDbase, zName, zSql, v1, v2, v3
	pCsr = pCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab /* String value of pSql */
	iArg = 0                                                       /* Count of argv[] parameters used so far */
	rc = SQLITE_OK                                                 /* Result of this operation */
	zName = uintptr(0)                                             /* Only provide analysis of this table */
	_ = argc
	_ = idxStr
	_statResetCsr(tls, pCsr)
	Xsqlite3_finalize(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	(*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt = uintptr(0)
	if idxNum&int32(0x01) != 0 {
		v1 = iArg
		iArg++
		/* schema=? constraint is present.  Get its value */
		zDbase = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(v1)*4)))
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = _sqlite3FindDbName(tls, (*TStatTable)(unsafe.Pointer(pTab)).Fdb, zDbase)
		if (*TStatCursor)(unsafe.Pointer(pCsr)).FiDb < 0 {
			(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = 0
			(*TStatCursor)(unsafe.Pointer(pCsr)).FisEof = uint8(1)
			return SQLITE_OK
		}
	} else {
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = (*TStatTable)(unsafe.Pointer(pTab)).FiDb
	}
	if idxNum&int32(0x02) != 0 {
		/* name=? constraint is present */
		v2 = iArg
		iArg++
		zName = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(v2)*4)))
	}
	if idxNum&int32(0x04) != 0 {
		/* aggregate=? constraint is present */
		v3 = iArg
		iArg++
		(*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg = libc.BoolUint8(Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(v3)*4))) != float64(0))
	} else {
		(*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg = uint8(0)
	}
	pSql = Xsqlite3_str_new(tls, (*TStatTable)(unsafe.Pointer(pTab)).Fdb)
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+34586, libc.VaList(bp+8, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer((*TStatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiDb)*16))).FzDbSName))
	if zName != 0 {
		Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+34741, libc.VaList(bp+8, zName))
	}
	if idxNum&int32(0x08) != 0 {
		Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+34755, 0)
	}
	zSql = Xsqlite3_str_finish(tls, pSql)
	if zSql == uintptr(0) {
		return int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v2(tls, (*TStatTable)(unsafe.Pointer(pTab)).Fdb, zSql, -int32(1), pCsr+4, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	if rc == SQLITE_OK {
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage = -int32(1)
		rc = _statNext(tls, pCursor)
	}
	return rc
}

func _statColumn(tls *libc.TLS, pCursor uintptr, ctx uintptr, i int32) (r int32) {
	var db, pCsr uintptr
	var iDb int32
	_, _, _ = db, iDb, pCsr
	pCsr = pCursor
	switch i {
	case 0: /* name */
		Xsqlite3_result_text(tls, ctx, (*TStatCursor)(unsafe.Pointer(pCsr)).FzName, -int32(1), uintptr(-libc.Int32FromInt32(1)))
	case int32(1): /* path */
		if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
			Xsqlite3_result_text(tls, ctx, (*TStatCursor)(unsafe.Pointer(pCsr)).FzPath, -int32(1), uintptr(-libc.Int32FromInt32(1)))
		}
	case int32(2): /* pageno */
		if (*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0 {
			Xsqlite3_result_int64(tls, ctx, int64((*TStatCursor)(unsafe.Pointer(pCsr)).FnPage))
		} else {
			Xsqlite3_result_int64(tls, ctx, int64((*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno))
		}
	case int32(3): /* pagetype */
		if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
			Xsqlite3_result_text(tls, ctx, (*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype, -int32(1), libc.UintptrFromInt32(0))
		}
	case int32(4): /* ncell */
		Xsqlite3_result_int64(tls, ctx, int64((*TStatCursor)(unsafe.Pointer(pCsr)).FnCell))
	case int32(5): /* payload */
		Xsqlite3_result_int64(tls, ctx, (*TStatCursor)(unsafe.Pointer(pCsr)).FnPayload)
	case int32(6): /* unused */
		Xsqlite3_result_int64(tls, ctx, (*TStatCursor)(unsafe.Pointer(pCsr)).FnUnused)
	case int32(7): /* mx_payload */
		Xsqlite3_result_int64(tls, ctx, int64((*TStatCursor)(unsafe.Pointer(pCsr)).FnMxPayload))
	case int32(8): /* pgoffset */
		if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
			Xsqlite3_result_int64(tls, ctx, (*TStatCursor)(unsafe.Pointer(pCsr)).FiOffset)
		}
	case int32(9): /* pgsize */
		Xsqlite3_result_int64(tls, ctx, (*TStatCursor)(unsafe.Pointer(pCsr)).FszPage)
	case int32(10): /* schema */
		db = Xsqlite3_context_db_handle(tls, ctx)
		iDb = (*TStatCursor)(unsafe.Pointer(pCsr)).FiDb
		Xsqlite3_result_text(tls, ctx, (*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, -int32(1), libc.UintptrFromInt32(0))
	default: /* aggregate */
		Xsqlite3_result_int(tls, ctx, int32((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg))
		break
	}
	return SQLITE_OK
}

func _statRowid(tls *libc.TLS, pCursor uintptr, pRowid uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCursor
	*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = int64((*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Invoke this routine to register the "dbstat" virtual table module
//	*/
func _sqlite3DbstatRegister(tls *libc.TLS, db uintptr) (r int32) {
	return Xsqlite3_create_module(tls, db, __ccgo_ts+34770, uintptr(unsafe.Pointer(&_dbstat_module)), uintptr(0))
}

var _dbstat_module = Tsqlite3_module{}

func init() {
	p := unsafe.Pointer(&_dbstat_module)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_statConnect)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_statConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_statBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_statDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_statOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_statClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_statFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_statNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_statEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_statColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_statRowid)
}

/************** End of dbstat.c **********************************************/
/************** Begin file dbpage.c ******************************************/
/*
** 2017-10-11
**
** 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 an implementation of the "sqlite_dbpage" virtual table.
**
** The sqlite_dbpage virtual table is used to read or write whole raw
** pages of the database file.  The pager interface is used so that
** uncommitted changes and changes recorded in the WAL file are correctly
** retrieved.
**
** Usage example:
**
**    SELECT data FROM sqlite_dbpage('aux1') WHERE pgno=123;
**
** This is an eponymous virtual table so it does not need to be created before
** use.  The optional argument to the sqlite_dbpage() table name is the
** schema for the database file that is to be read.  The default schema is
** "main".
**
** The data field of sqlite_dbpage table can be updated.  The new
** value must be a BLOB which is the correct page size, otherwise the
** update fails.  Rows may not be deleted or inserted.
 */

/* #include "sqliteInt.h"   ** Requires access to internal data structures ** */

/************** End of dbpage.c **********************************************/
/************** Begin file sqlite3session.c **********************************/

/* #include "sqlite3session.h" */
/* #include <assert.h> */
/* #include <string.h> */

type TSessionTable = struct {
	FpNext     uintptr
	FzName     uintptr
	FnCol      int32
	FbStat1    int32
	FbRowid    int32
	FazCol     uintptr
	FazDflt    uintptr
	FabPK      uintptr
	FnEntry    int32
	FnChange   int32
	FapChange  uintptr
	FpDfltStmt uintptr
}

type SessionTable = TSessionTable

type TSessionChange = struct {
	Fop           Tu8
	FbIndirect    Tu8
	FnRecordField Tu16
	FnMaxSize     int32
	FnRecord      int32
	FaRecord      uintptr
	FpNext        uintptr
}

type SessionChange = TSessionChange

type TSessionBuffer = struct {
	FaBuf   uintptr
	FnBuf   int32
	FnAlloc int32
}

type SessionBuffer = TSessionBuffer

type TSessionInput = struct {
	FbNoDiscard int32
	FiCurrent   int32
	FiNext      int32
	FaData      uintptr
	FnData      int32
	Fbuf        TSessionBuffer
	FxInput     uintptr
	FpIn        uintptr
	FbEof       int32
}

type SessionInput = TSessionInput

/*
** Minimum chunk size used by streaming versions of functions.
 */

var _sessions_strm_chunk_size = int32(SESSIONS_STRM_CHUNK_SIZE)

type TSessionHook = struct {
	FpCtx   uintptr
	FxOld   uintptr
	FxNew   uintptr
	FxCount uintptr
	FxDepth uintptr
}

type SessionHook = TSessionHook

type TSessionHook1 = struct {
	FpCtx   uintptr
	FxOld   uintptr
	FxNew   uintptr
	FxCount uintptr
	FxDepth uintptr
}

type SessionHook1 = TSessionHook1

/*
** Session handle structure.
 */
type Tsqlite3_session1 = struct {
	F__ccgo_align      [0]uint32
	Fdb                uintptr
	FzDb               uintptr
	FbEnableSize       int32
	FbEnable           int32
	FbIndirect         int32
	FbAutoAttach       int32
	FbImplicitPK       int32
	Frc                int32
	FpFilterCtx        uintptr
	FxTableFilter      uintptr
	FnMalloc           Ti64
	FnMaxChangesetSize Ti64
	FpZeroBlob         uintptr
	FpNext             uintptr
	FpTable            uintptr
	Fhook              TSessionHook
}

type sqlite3_session1 = Tsqlite3_session1

/*
** Instances of this structure are used to build strings or binary records.
 */
type TSessionBuffer1 = struct {
	FaBuf   uintptr
	FnBuf   int32
	FnAlloc int32
}

type SessionBuffer1 = TSessionBuffer1

/*
** An object of this type is used internally as an abstraction for
** input data. Input data may be supplied either as a single large buffer
** (e.g. sqlite3changeset_start()) or using a stream function (e.g.
**  sqlite3changeset_start_strm()).
 */
type TSessionInput1 = struct {
	FbNoDiscard int32
	FiCurrent   int32
	FiNext      int32
	FaData      uintptr
	FnData      int32
	Fbuf        TSessionBuffer
	FxInput     uintptr
	FpIn        uintptr
	FbEof       int32
}

type SessionInput1 = TSessionInput1

/*
** Structure for changeset iterators.
 */
type Tsqlite3_changeset_iter1 = struct {
	Fin         TSessionInput
	Ftblhdr     TSessionBuffer
	FbPatchset  int32
	FbInvert    int32
	FbSkipEmpty int32
	Frc         int32
	FpConflict  uintptr
	FzTab       uintptr
	FnCol       int32
	Fop         int32
	FbIndirect  int32
	FabPK       uintptr
	FapValue    uintptr
}

type sqlite3_changeset_iter1 = Tsqlite3_changeset_iter1

/*
** Each session object maintains a set of the following structures, one
** for each table the session object is monitoring. The structures are
** stored in a linked list starting at sqlite3_session.pTable.
**
** The keys of the SessionTable.aChange[] hash table are all rows that have
** been modified in any way since the session object was attached to the
** table.
**
** The data associated with each hash-table entry is a structure containing
** a subset of the initial values that the modified row contained at the
** start of the session. Or no initial values if the row was inserted.
**
** pDfltStmt:
**   This is only used by the sqlite3changegroup_xxx() APIs, not by
**   regular sqlite3_session objects. It is a SELECT statement that
**   selects the default value for each table column. For example,
**   if the table is
**
**      CREATE TABLE xx(a DEFAULT 1, b, c DEFAULT 'abc')
**
**   then this variable is the compiled version of:
**
**      SELECT 1, NULL, 'abc'
 */
type TSessionTable1 = struct {
	FpNext     uintptr
	FzName     uintptr
	FnCol      int32
	FbStat1    int32
	FbRowid    int32
	FazCol     uintptr
	FazDflt    uintptr
	FabPK      uintptr
	FnEntry    int32
	FnChange   int32
	FapChange  uintptr
	FpDfltStmt uintptr
}

type SessionTable1 = TSessionTable1

/*
** RECORD FORMAT:
**
** The following record format is similar to (but not compatible with) that
** used in SQLite database files. This format is used as part of the
** change-set binary format, and so must be architecture independent.
**
** Unlike the SQLite database record format, each field is self-contained -
** there is no separation of header and data. Each field begins with a
** single byte describing its type, as follows:
**
**       0x00: Undefined value.
**       0x01: Integer value.
**       0x02: Real value.
**       0x03: Text value.
**       0x04: Blob value.
**       0x05: SQL NULL value.
**
** Note that the above match the definitions of SQLITE_INTEGER, SQLITE_TEXT
** and so on in sqlite3.h. For undefined and NULL values, the field consists
** only of the single type byte. For other types of values, the type byte
** is followed by:
**
**   Text values:
**     A varint containing the number of bytes in the value (encoded using
**     UTF-8). Followed by a buffer containing the UTF-8 representation
**     of the text value. There is no nul terminator.
**
**   Blob values:
**     A varint containing the number of bytes in the value, followed by
**     a buffer containing the value itself.
**
**   Integer values:
**     An 8-byte big-endian integer value.
**
**   Real values:
**     An 8-byte big-endian IEEE 754-2008 real value.
**
** Varint values are encoded in the same way as varints in the SQLite
** record format.
**
** CHANGESET FORMAT:
**
** A changeset is a collection of DELETE, UPDATE and INSERT operations on
** one or more tables. Operations on a single table are grouped together,
** but may occur in any order (i.e. deletes, updates and inserts are all
** mixed together).
**
** Each group of changes begins with a table header:
**
**   1 byte: Constant 0x54 (capital 'T')
**   Varint: Number of columns in the table.
**   nCol bytes: 0x01 for PK columns, 0x00 otherwise.
**   N bytes: Unqualified table name (encoded using UTF-8). Nul-terminated.
**
** Followed by one or more changes to the table.
**
**   1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
**   1 byte: The "indirect-change" flag.
**   old.* record: (delete and update only)
**   new.* record: (insert and update only)
**
** The "old.*" and "new.*" records, if present, are N field records in the
** format described above under "RECORD FORMAT", where N is the number of
** columns in the table. The i'th field of each record is associated with
** the i'th column of the table, counting from left to right in the order
** in which columns were declared in the CREATE TABLE statement.
**
** The new.* record that is part of each INSERT change contains the values
** that make up the new row. Similarly, the old.* record that is part of each
** DELETE change contains the values that made up the row that was deleted
** from the database. In the changeset format, the records that are part
** of INSERT or DELETE changes never contain any undefined (type byte 0x00)
** fields.
**
** Within the old.* record associated with an UPDATE change, all fields
** associated with table columns that are not PRIMARY KEY columns and are
** not modified by the UPDATE change are set to "undefined". Other fields
** are set to the values that made up the row before the UPDATE that the
** change records took place. Within the new.* record, fields associated
** with table columns modified by the UPDATE change contain the new
** values. Fields associated with table columns that are not modified
** are set to "undefined".
**
** PATCHSET FORMAT:
**
** A patchset is also a collection of changes. It is similar to a changeset,
** but leaves undefined those fields that are not useful if no conflict
** resolution is required when applying the changeset.
**
** Each group of changes begins with a table header:
**
**   1 byte: Constant 0x50 (capital 'P')
**   Varint: Number of columns in the table.
**   nCol bytes: 0x01 for PK columns, 0x00 otherwise.
**   N bytes: Unqualified table name (encoded using UTF-8). Nul-terminated.
**
** Followed by one or more changes to the table.
**
**   1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
**   1 byte: The "indirect-change" flag.
**   single record: (PK fields for DELETE, PK and modified fields for UPDATE,
**                   full record for INSERT).
**
** As in the changeset format, each field of the single record that is part
** of a patchset change is associated with the correspondingly positioned
** table column, counting from left to right within the CREATE TABLE
** statement.
**
** For a DELETE change, all fields within the record except those associated
** with PRIMARY KEY columns are omitted. The PRIMARY KEY fields contain the
** values identifying the row to delete.
**
** For an UPDATE change, all fields except those associated with PRIMARY KEY
** columns and columns that are modified by the UPDATE are set to "undefined".
** PRIMARY KEY fields contain the values identifying the table row to update,
** and fields associated with modified columns contain the new column values.
**
** The records associated with INSERT changes are in the same format as for
** changesets. It is not possible for a record associated with an INSERT
** change to contain a field set to "undefined".
**
** REBASE BLOB FORMAT:
**
** A rebase blob may be output by sqlite3changeset_apply_v2() and its
** streaming equivalent for use with the sqlite3_rebaser APIs to rebase
** existing changesets. A rebase blob contains one entry for each conflict
** resolved using either the OMIT or REPLACE strategies within the apply_v2()
** call.
**
** The format used for a rebase blob is very similar to that used for
** changesets. All entries related to a single table are grouped together.
**
** Each group of entries begins with a table header in changeset format:
**
**   1 byte: Constant 0x54 (capital 'T')
**   Varint: Number of columns in the table.
**   nCol bytes: 0x01 for PK columns, 0x00 otherwise.
**   N bytes: Unqualified table name (encoded using UTF-8). Nul-terminated.
**
** Followed by one or more entries associated with the table.
**
**   1 byte: Either SQLITE_INSERT (0x12), DELETE (0x09).
**   1 byte: Flag. 0x01 for REPLACE, 0x00 for OMIT.
**   record: (in the record format defined above).
**
** In a rebase blob, the first field is set to SQLITE_INSERT if the change
** that caused the conflict was an INSERT or UPDATE, or to SQLITE_DELETE if
** it was a DELETE. The second field is set to 0x01 if the conflict
** resolution strategy was REPLACE, or 0x00 if it was OMIT.
**
** If the change that caused the conflict was a DELETE, then the single
** record is a copy of the old.* record from the original changeset. If it
** was an INSERT, then the single record is a copy of the new.* record. If
** the conflicting change was an UPDATE, then the single record is a copy
** of the new.* record with the PK fields filled in based on the original
** old.* record.
 */

/*
** For each row modified during a session, there exists a single instance of
** this structure stored in a SessionTable.aChange[] hash table.
 */
type TSessionChange1 = struct {
	Fop           Tu8
	FbIndirect    Tu8
	FnRecordField Tu16
	FnMaxSize     int32
	FnRecord      int32
	FaRecord      uintptr
	FpNext        uintptr
}

type SessionChange1 = TSessionChange1

// C documentation
//
//	/*
//	** Write a varint with value iVal into the buffer at aBuf. Return the
//	** number of bytes written.
//	*/
func _sessionVarintPut(tls *libc.TLS, aBuf uintptr, iVal int32) (r int32) {
	var v1 int32
	_ = v1
	if uint32(iVal) < libc.Uint32FromInt32(0x80) {
		*(*Tu8)(unsafe.Pointer(aBuf)) = uint8(iVal)
		v1 = libc.Int32FromInt32(1)
	} else {
		v1 = _sqlite3PutVarint(tls, aBuf, uint64(iVal))
	}
	return int32(uint8(v1))
}

// C documentation
//
//	/*
//	** Return the number of bytes required to store value iVal as a varint.
//	*/
func _sessionVarintLen(tls *libc.TLS, iVal int32) (r int32) {
	return _sqlite3VarintLen(tls, uint64(uint64(iVal)))
}

// C documentation
//
//	/*
//	** Read a varint value from aBuf[] into *piVal. Return the number of
//	** bytes read.
//	*/
func _sessionVarintGet(tls *libc.TLS, aBuf uintptr, piVal uintptr) (r int32) {
	var v1 int32
	_ = v1
	if int32(*(*Tu8)(unsafe.Pointer(aBuf))) < int32(libc.Uint8FromInt32(0x80)) {
		*(*int32)(unsafe.Pointer(piVal)) = int32(uint32(*(*Tu8)(unsafe.Pointer(aBuf))))
		v1 = libc.Int32FromInt32(1)
	} else {
		v1 = int32(_sqlite3GetVarint32(tls, aBuf, piVal))
	}
	return int32(uint8(v1))
}

/* Load an unaligned and unsigned 32-bit integer */

// C documentation
//
//	/*
//	** Read a 64-bit big-endian integer value from buffer aRec[]. Return
//	** the value read.
//	*/
func _sessionGetI64(tls *libc.TLS, aRec uintptr) (r Tsqlite3_int64) {
	var x Tu64
	var y Tu32
	_, _ = x, y
	x = uint64(uint32(*(*Tu8)(unsafe.Pointer(aRec)))<<libc.Int32FromInt32(24) | uint32(int32(*(*Tu8)(unsafe.Pointer(aRec + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*Tu8)(unsafe.Pointer(aRec + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*Tu8)(unsafe.Pointer(aRec + 3))))
	y = uint32(*(*Tu8)(unsafe.Pointer(aRec + libc.UintptrFromInt32(4))))<<libc.Int32FromInt32(24) | uint32(int32(*(*Tu8)(unsafe.Pointer(aRec + libc.UintptrFromInt32(4) + 1)))<<libc.Int32FromInt32(16)) | uint32(int32(*(*Tu8)(unsafe.Pointer(aRec + libc.UintptrFromInt32(4) + 2)))<<libc.Int32FromInt32(8)) | uint32(*(*Tu8)(unsafe.Pointer(aRec + libc.UintptrFromInt32(4) + 3)))
	x = x<<libc.Int32FromInt32(32) + uint64(uint64(y))
	return int64(int64(x))
}

// C documentation
//
//	/*
//	** Write a 64-bit big-endian integer value to the buffer aBuf[].
//	*/
func _sessionPutI64(tls *libc.TLS, aBuf uintptr, i Tsqlite3_int64) {
	*(*Tu8)(unsafe.Pointer(aBuf)) = uint8(i >> libc.Int32FromInt32(56) & int64(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 1)) = uint8(i >> libc.Int32FromInt32(48) & int64(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 2)) = uint8(i >> libc.Int32FromInt32(40) & int64(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 3)) = uint8(i >> libc.Int32FromInt32(32) & int64(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 4)) = uint8(i >> libc.Int32FromInt32(24) & int64(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 5)) = uint8(i >> libc.Int32FromInt32(16) & int64(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 6)) = uint8(i >> libc.Int32FromInt32(8) & int64(0xFF))
	*(*Tu8)(unsafe.Pointer(aBuf + 7)) = uint8(i >> libc.Int32FromInt32(0) & int64(0xFF))
}

// C documentation
//
//	/*
//	** This function is used to serialize the contents of value pValue (see
//	** comment titled "RECORD FORMAT" above).
//	**
//	** If it is non-NULL, the serialized form of the value is written to
//	** buffer aBuf. *pnWrite is set to the number of bytes written before
//	** returning. Or, if aBuf is NULL, the only thing this function does is
//	** set *pnWrite.
//	**
//	** If no error occurs, SQLITE_OK is returned. Or, if an OOM error occurs
//	** within a call to sqlite3_value_text() (may fail if the db is utf-16))
//	** SQLITE_NOMEM is returned.
//	*/
func _sessionSerializeValue(tls *libc.TLS, aBuf uintptr, pValue uintptr, pnWrite uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType, n, nByte, nVarint int32
	var z uintptr
	var _ /* i at bp+0 */ Tu64
	var _ /* r at bp+8 */ float64
	_, _, _, _, _ = eType, n, nByte, nVarint, z /* Size of serialized value in bytes */
	if pValue != 0 {                            /* Value type (SQLITE_NULL, TEXT etc.) */
		eType = Xsqlite3_value_type(tls, pValue)
		if aBuf != 0 {
			*(*Tu8)(unsafe.Pointer(aBuf)) = uint8(uint8(eType))
		}
		switch eType {
		case int32(SQLITE_NULL):
			nByte = int32(1)
		case int32(SQLITE_INTEGER):
			fallthrough
		case int32(SQLITE_FLOAT):
			if aBuf != 0 {
				if eType == int32(SQLITE_INTEGER) {
					*(*Tu64)(unsafe.Pointer(bp)) = uint64(Xsqlite3_value_int64(tls, pValue))
				} else {
					*(*float64)(unsafe.Pointer(bp + 8)) = Xsqlite3_value_double(tls, pValue)
					libc.Xmemcpy(tls, bp, bp+8, uint32(8))
				}
				_sessionPutI64(tls, aBuf+1, int64(*(*Tu64)(unsafe.Pointer(bp))))
			}
			nByte = int32(9)
		default:
			if eType == int32(SQLITE_TEXT) {
				z = Xsqlite3_value_text(tls, pValue)
			} else {
				z = Xsqlite3_value_blob(tls, pValue)
			}
			n = Xsqlite3_value_bytes(tls, pValue)
			if z == uintptr(0) && (eType != int32(SQLITE_BLOB) || n > 0) {
				return int32(SQLITE_NOMEM)
			}
			nVarint = _sessionVarintLen(tls, n)
			if aBuf != 0 {
				_sessionVarintPut(tls, aBuf+1, n)
				if n > 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nVarint+int32(1)), z, uint32(uint32(n)))
				}
			}
			nByte = int32(1) + nVarint + n
			break
		}
	} else {
		nByte = int32(1)
		if aBuf != 0 {
			*(*Tu8)(unsafe.Pointer(aBuf)) = uint8('\000')
		}
	}
	if pnWrite != 0 {
		*(*Tsqlite3_int64)(unsafe.Pointer(pnWrite)) += int64(int64(nByte))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Allocate and return a pointer to a buffer nByte bytes in size. If
//	** pSession is not NULL, increase the sqlite3_session.nMalloc variable
//	** by the number of bytes allocated.
//	*/
func _sessionMalloc64(tls *libc.TLS, pSession uintptr, nByte Ti64) (r uintptr) {
	var pRet, p1 uintptr
	_, _ = pRet, p1
	pRet = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	if pSession != 0 {
		p1 = pSession + 40
		*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) + Xsqlite3_msize(tls, pRet))
	}
	return pRet
}

// C documentation
//
//	/*
//	** Free buffer pFree, which must have been allocated by an earlier
//	** call to sessionMalloc64(). If pSession is not NULL, decrease the
//	** sqlite3_session.nMalloc counter by the number of bytes freed.
//	*/
func _sessionFree(tls *libc.TLS, pSession uintptr, pFree uintptr) {
	var p1 uintptr
	_ = p1
	if pSession != 0 {
		p1 = pSession + 40
		*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) - Xsqlite3_msize(tls, pFree))
	}
	Xsqlite3_free(tls, pFree)
}

/*
** This macro is used to calculate hash key values for data structures. In
** order to use this macro, the entire data structure must be represented
** as a series of unsigned integers. In order to calculate a hash-key value
** for a data structure represented as three such integers, the macro may
** then be used as follows:
**
**    int hash_key_value;
**    hash_key_value = HASH_APPEND(0, <value 1>);
**    hash_key_value = HASH_APPEND(hash_key_value, <value 2>);
**    hash_key_value = HASH_APPEND(hash_key_value, <value 3>);
**
** In practice, the data structures this macro is used for are the primary
** key values of modified rows.
 */

// C documentation
//
//	/*
//	** Append the hash of the 64-bit integer passed as the second argument to the
//	** hash-key value passed as the first. Return the new hash-key value.
//	*/
func _sessionHashAppendI64(tls *libc.TLS, h uint32, i Ti64) (r uint32) {
	h = h<<int32(3) ^ h ^ uint32(i&libc.Int64FromUint32(0xFFFFFFFF))
	return h<<int32(3) ^ h ^ uint32(i>>libc.Int32FromInt32(32)&libc.Int64FromUint32(0xFFFFFFFF))
}

// C documentation
//
//	/*
//	** Append the hash of the blob passed via the second and third arguments to
//	** the hash-key value passed as the first. Return the new hash-key value.
//	*/
func _sessionHashAppendBlob(tls *libc.TLS, h uint32, n int32, z uintptr) (r uint32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < n) {
			break
		}
		h = h<<int32(3) ^ h ^ uint32(*(*Tu8)(unsafe.Pointer(z + uintptr(i))))
		goto _1
	_1:
		;
		i++
	}
	return h
}

// C documentation
//
//	/*
//	** Append the hash of the data type passed as the second argument to the
//	** hash-key value passed as the first. Return the new hash-key value.
//	*/
func _sessionHashAppendType(tls *libc.TLS, h uint32, eType int32) (r uint32) {
	return h<<int32(3) ^ h ^ uint32(eType)
}

// C documentation
//
//	/*
//	** This function may only be called from within a pre-update callback.
//	** It calculates a hash based on the primary key values of the old.* or
//	** new.* row currently available and, assuming no error occurs, writes it to
//	** *piHash before returning. If the primary key contains one or more NULL
//	** values, *pbNullPK is set to true before returning.
//	**
//	** If an error occurs, an SQLite error code is returned and the final values
//	** of *piHash asn *pbNullPK are undefined. Otherwise, SQLITE_OK is returned
//	** and the output variables are set as described above.
//	*/
func _sessionPreupdateHash(tls *libc.TLS, pSession uintptr, iRowid Ti64, pTab uintptr, bNew int32, piHash uintptr, pbNullPK uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eType, i, n, rc int32
	var h uint32
	var z uintptr
	var _ /* iVal at bp+8 */ Ti64
	var _ /* pVal at bp+0 */ uintptr
	var _ /* rVal at bp+16 */ float64
	_, _, _, _, _, _ = eType, h, i, n, rc, z
	h = uint32(0) /* Used to iterate through columns */
	if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
		h = _sessionHashAppendI64(tls, h, iRowid)
	} else {
		i = 0
		for {
			if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
				break
			}
			if *(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
				if bNew != 0 {
					rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp)
				} else {
					rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp)
				}
				if rc != SQLITE_OK {
					return rc
				}
				eType = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp)))
				h = _sessionHashAppendType(tls, h, eType)
				if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
					if eType == int32(SQLITE_INTEGER) {
						*(*Ti64)(unsafe.Pointer(bp + 8)) = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(bp)))
					} else {
						*(*float64)(unsafe.Pointer(bp + 16)) = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(bp)))
						libc.Xmemcpy(tls, bp+8, bp+16, uint32(8))
					}
					h = _sessionHashAppendI64(tls, h, *(*Ti64)(unsafe.Pointer(bp + 8)))
				} else {
					if eType == int32(SQLITE_TEXT) || eType == int32(SQLITE_BLOB) {
						if eType == int32(SQLITE_TEXT) {
							z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(bp)))
						} else {
							z = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(bp)))
						}
						n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)))
						if !(z != 0) && (eType != int32(SQLITE_BLOB) || n > 0) {
							return int32(SQLITE_NOMEM)
						}
						h = _sessionHashAppendBlob(tls, h, n, z)
					} else {
						*(*int32)(unsafe.Pointer(pbNullPK)) = int32(1)
					}
				}
			}
			goto _1
		_1:
			;
			i++
		}
	}
	*(*int32)(unsafe.Pointer(piHash)) = int32(h % uint32((*TSessionTable)(unsafe.Pointer(pTab)).FnChange))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The buffer that the argument points to contains a serialized SQL value.
//	** Return the number of bytes of space occupied by the value (including
//	** the type byte).
//	*/
func _sessionSerialLen(tls *libc.TLS, a uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var e int32
	var _ /* n at bp+0 */ int32
	_ = e
	e = int32(*(*Tu8)(unsafe.Pointer(a)))
	if e == 0 || e == int32(0xFF) {
		return int32(1)
	}
	if e == int32(SQLITE_NULL) {
		return int32(1)
	}
	if e == int32(SQLITE_INTEGER) || e == int32(SQLITE_FLOAT) {
		return int32(9)
	}
	return _sessionVarintGet(tls, a+1, bp) + int32(1) + *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Based on the primary key values stored in change aRecord, calculate a
//	** hash key. Assume the has table has nBucket buckets. The hash keys
//	** calculated by this function are compatible with those calculated by
//	** sessionPreupdateHash().
//	**
//	** The bPkOnly argument is non-zero if the record at aRecord[] is from
//	** a patchset DELETE. In this case the non-PK fields are omitted entirely.
//	*/
func _sessionChangeHash(tls *libc.TLS, pTab uintptr, bPkOnly int32, aRecord uintptr, nBucket int32) (r uint32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a uintptr
	var eType, i, isPK int32
	var h uint32
	var _ /* n at bp+0 */ int32
	_, _, _, _, _ = a, eType, h, i, isPK
	h = uint32(0) /* Used to iterate through columns */
	a = aRecord   /* Used to iterate through change record */
	i = 0
	for {
		if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		eType = int32(*(*Tu8)(unsafe.Pointer(a)))
		isPK = int32(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))))
		if bPkOnly != 0 && isPK == 0 {
			goto _1
		}
		/* It is not possible for eType to be SQLITE_NULL here. The session
		 ** module does not record changes for rows with NULL values stored in
		 ** primary key columns. */
		if isPK != 0 {
			a++
			h = _sessionHashAppendType(tls, h, eType)
			if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
				h = _sessionHashAppendI64(tls, h, _sessionGetI64(tls, a))
				a += uintptr(8)
			} else {
				a += uintptr(_sessionVarintGet(tls, a, bp))
				h = _sessionHashAppendBlob(tls, h, *(*int32)(unsafe.Pointer(bp)), a)
				a += uintptr(*(*int32)(unsafe.Pointer(bp)))
			}
		} else {
			a += uintptr(_sessionSerialLen(tls, a))
		}
		goto _1
	_1:
		;
		i++
	}
	return h % uint32(uint32(nBucket))
}

// C documentation
//
//	/*
//	** Arguments aLeft and aRight are pointers to change records for table pTab.
//	** This function returns true if the two records apply to the same row (i.e.
//	** have the same values stored in the primary key columns), or false
//	** otherwise.
//	*/
func _sessionChangeEqual(tls *libc.TLS, pTab uintptr, bLeftPkOnly int32, aLeft uintptr, bRightPkOnly int32, aRight uintptr) (r int32) {
	var a1, a2 uintptr
	var iCol, n1, n2 int32
	_, _, _, _, _ = a1, a2, iCol, n1, n2
	a1 = aLeft  /* Cursor to iterate through aLeft */
	a2 = aRight /* Used to iterate through table columns */
	iCol = 0
	for {
		if !(iCol < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		if *(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(iCol))) != 0 {
			n1 = _sessionSerialLen(tls, a1)
			n2 = _sessionSerialLen(tls, a2)
			if n1 != n2 || libc.Xmemcmp(tls, a1, a2, uint32(uint32(n1))) != 0 {
				return 0
			}
			a1 += uintptr(n1)
			a2 += uintptr(n2)
		} else {
			if bLeftPkOnly == 0 {
				a1 += uintptr(_sessionSerialLen(tls, a1))
			}
			if bRightPkOnly == 0 {
				a2 += uintptr(_sessionSerialLen(tls, a2))
			}
		}
		goto _1
	_1:
		;
		iCol++
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Arguments aLeft and aRight both point to buffers containing change
//	** records with nCol columns. This function "merges" the two records into
//	** a single records which is written to the buffer at *paOut. *paOut is
//	** then set to point to one byte after the last byte written before
//	** returning.
//	**
//	** The merging of records is done as follows: For each column, if the
//	** aRight record contains a value for the column, copy the value from
//	** their. Otherwise, if aLeft contains a value, copy it. If neither
//	** record contains a value for a given column, then neither does the
//	** output record.
//	*/
func _sessionMergeRecord(tls *libc.TLS, paOut uintptr, nCol int32, aLeft uintptr, aRight uintptr) {
	var a1, a2, aOut uintptr
	var iCol, n1, n2 int32
	_, _, _, _, _, _ = a1, a2, aOut, iCol, n1, n2
	a1 = aLeft                                /* Cursor used to iterate through aLeft */
	a2 = aRight                               /* Cursor used to iterate through aRight */
	aOut = *(*uintptr)(unsafe.Pointer(paOut)) /* Used to iterate from 0 to nCol */
	iCol = 0
	for {
		if !(iCol < nCol) {
			break
		}
		n1 = _sessionSerialLen(tls, a1)
		n2 = _sessionSerialLen(tls, a2)
		if *(*Tu8)(unsafe.Pointer(a2)) != 0 {
			libc.Xmemcpy(tls, aOut, a2, uint32(uint32(n2)))
			aOut += uintptr(n2)
		} else {
			libc.Xmemcpy(tls, aOut, a1, uint32(uint32(n1)))
			aOut += uintptr(n1)
		}
		a1 += uintptr(n1)
		a2 += uintptr(n2)
		goto _1
	_1:
		;
		iCol++
	}
	*(*uintptr)(unsafe.Pointer(paOut)) = aOut
}

// C documentation
//
//	/*
//	** This is a helper function used by sessionMergeUpdate().
//	**
//	** When this function is called, both *paOne and *paTwo point to a value
//	** within a change record. Before it returns, both have been advanced so
//	** as to point to the next value in the record.
//	**
//	** If, when this function is called, *paTwo points to a valid value (i.e.
//	** *paTwo[0] is not 0x00 - the "no value" placeholder), a copy of the *paTwo
//	** pointer is returned and *pnVal is set to the number of bytes in the
//	** serialized value. Otherwise, a copy of *paOne is returned and *pnVal
//	** set to the number of bytes in the value at *paOne. If *paOne points
//	** to the "no value" placeholder, *pnVal is set to 1. In other words:
//	**
//	**   if( *paTwo is valid ) return *paTwo;
//	**   return *paOne;
//	**
//	*/
func _sessionMergeValue(tls *libc.TLS, paOne uintptr, paTwo uintptr, pnVal uintptr) (r uintptr) {
	var a1, a2, pRet uintptr
	var n1, n2 int32
	_, _, _, _, _ = a1, a2, n1, n2, pRet
	a1 = *(*uintptr)(unsafe.Pointer(paOne))
	a2 = *(*uintptr)(unsafe.Pointer(paTwo))
	pRet = uintptr(0)
	if a2 != 0 {
		n2 = _sessionSerialLen(tls, a2)
		if *(*Tu8)(unsafe.Pointer(a2)) != 0 {
			*(*int32)(unsafe.Pointer(pnVal)) = n2
			pRet = a2
		}
		*(*uintptr)(unsafe.Pointer(paTwo)) = a2 + uintptr(n2)
	}
	n1 = _sessionSerialLen(tls, a1)
	if pRet == uintptr(0) {
		*(*int32)(unsafe.Pointer(pnVal)) = n1
		pRet = a1
	}
	*(*uintptr)(unsafe.Pointer(paOne)) = a1 + uintptr(n1)
	return pRet
}

// C documentation
//
//	/*
//	** This function is used by changeset_concat() to merge two UPDATE changes
//	** on the same row.
//	*/
func _sessionMergeUpdate(tls *libc.TLS, paOut uintptr, pTab uintptr, bPatchset int32, aOldRecord1 uintptr, aOldRecord2 uintptr, aNewRecord1 uintptr, aNewRecord2 uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aNew, aNew1, aOld, aOld1, aOut, v2, v4 uintptr
	var bRequired, i int32
	var _ /* aNew1 at bp+8 */ uintptr
	var _ /* aNew2 at bp+12 */ uintptr
	var _ /* aOld1 at bp+0 */ uintptr
	var _ /* aOld2 at bp+4 */ uintptr
	var _ /* nNew at bp+20 */ int32
	var _ /* nNew at bp+28 */ int32
	var _ /* nOld at bp+16 */ int32
	var _ /* nOld at bp+24 */ int32
	_, _, _, _, _, _, _, _, _ = aNew, aNew1, aOld, aOld1, aOut, bRequired, i, v2, v4
	*(*uintptr)(unsafe.Pointer(bp)) = aOldRecord1
	*(*uintptr)(unsafe.Pointer(bp + 4)) = aOldRecord2
	*(*uintptr)(unsafe.Pointer(bp + 8)) = aNewRecord1
	*(*uintptr)(unsafe.Pointer(bp + 12)) = aNewRecord2
	aOut = *(*uintptr)(unsafe.Pointer(paOut))
	if bPatchset == 0 {
		bRequired = 0
		/* Write the old.* vector first. */
		i = 0
		for {
			if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
				break
			}
			aOld = _sessionMergeValue(tls, bp, bp+4, bp+16)
			aNew = _sessionMergeValue(tls, bp+8, bp+12, bp+20)
			if *(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 || *(*int32)(unsafe.Pointer(bp + 16)) != *(*int32)(unsafe.Pointer(bp + 20)) || libc.Xmemcmp(tls, aOld, aNew, uint32(*(*int32)(unsafe.Pointer(bp + 20)))) != 0 {
				if int32(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i)))) == 0 {
					bRequired = int32(1)
				}
				libc.Xmemcpy(tls, aOut, aOld, uint32(*(*int32)(unsafe.Pointer(bp + 16))))
				aOut += uintptr(*(*int32)(unsafe.Pointer(bp + 16)))
			} else {
				v2 = aOut
				aOut++
				*(*Tu8)(unsafe.Pointer(v2)) = uint8('\000')
			}
			goto _1
		_1:
			;
			i++
		}
		if !(bRequired != 0) {
			return 0
		}
	}
	/* Write the new.* vector */
	*(*uintptr)(unsafe.Pointer(bp)) = aOldRecord1
	*(*uintptr)(unsafe.Pointer(bp + 4)) = aOldRecord2
	*(*uintptr)(unsafe.Pointer(bp + 8)) = aNewRecord1
	*(*uintptr)(unsafe.Pointer(bp + 12)) = aNewRecord2
	i = 0
	for {
		if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		aOld1 = _sessionMergeValue(tls, bp, bp+4, bp+24)
		aNew1 = _sessionMergeValue(tls, bp+8, bp+12, bp+28)
		if bPatchset == 0 && (*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 || *(*int32)(unsafe.Pointer(bp + 24)) == *(*int32)(unsafe.Pointer(bp + 28)) && 0 == libc.Xmemcmp(tls, aOld1, aNew1, uint32(*(*int32)(unsafe.Pointer(bp + 28))))) {
			v4 = aOut
			aOut++
			*(*Tu8)(unsafe.Pointer(v4)) = uint8('\000')
		} else {
			libc.Xmemcpy(tls, aOut, aNew1, uint32(*(*int32)(unsafe.Pointer(bp + 28))))
			aOut += uintptr(*(*int32)(unsafe.Pointer(bp + 28)))
		}
		goto _3
	_3:
		;
		i++
	}
	*(*uintptr)(unsafe.Pointer(paOut)) = aOut
	return int32(1)
}

// C documentation
//
//	/*
//	** This function is only called from within a pre-update-hook callback.
//	** It determines if the current pre-update-hook change affects the same row
//	** as the change stored in argument pChange. If so, it returns true. Otherwise
//	** if the pre-update-hook does not affect the same row as pChange, it returns
//	** false.
//	*/
func _sessionPreupdateEqual(tls *libc.TLS, pSession uintptr, iRowid Ti64, pTab uintptr, pChange uintptr, op int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, z, v2 uintptr
	var eType, iCol, rc int32
	var _ /* iVal at bp+8 */ Ti64
	var _ /* n at bp+24 */ int32
	var _ /* pVal at bp+0 */ uintptr
	var _ /* rVal at bp+16 */ float64
	_, _, _, _, _, _ = a, eType, iCol, rc, z, v2            /* Used to iterate through columns */
	a = (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord /* Cursor used to scan change record */
	if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
		if int32(*(*Tu8)(unsafe.Pointer(a))) != int32(SQLITE_INTEGER) {
			return 0
		}
		return libc.BoolInt32(_sessionGetI64(tls, a+1) == iRowid)
	}
	iCol = 0
	for {
		if !(iCol < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		if !(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(iCol))) != 0) {
			a += uintptr(_sessionSerialLen(tls, a))
		} else {
			v2 = a
			a++                                        /* Error code from preupdate_new/old */
			eType = int32(*(*Tu8)(unsafe.Pointer(v2))) /* Type of value from change record */
			/* The following calls to preupdate_new() and preupdate_old() can not
			 ** fail. This is because they cache their return values, and by the
			 ** time control flows to here they have already been called once from
			 ** within sessionPreupdateHash(). The first two asserts below verify
			 ** this (that the method has already been called). */
			if op == int32(SQLITE_INSERT) {
				/* assert( db->pPreUpdate->pNewUnpacked || db->pPreUpdate->aNew ); */
				rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iCol, bp)
			} else {
				/* assert( db->pPreUpdate->pUnpacked ); */
				rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iCol, bp)
			}
			_ = rc /* Suppress warning about unused variable */
			if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp))) != eType {
				return 0
			}
			/* A SessionChange object never has a NULL value in a PK column */
			if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
				*(*Ti64)(unsafe.Pointer(bp + 8)) = _sessionGetI64(tls, a)
				a += uintptr(8)
				if eType == int32(SQLITE_INTEGER) {
					if Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(bp))) != *(*Ti64)(unsafe.Pointer(bp + 8)) {
						return 0
					}
				} else {
					libc.Xmemcpy(tls, bp+16, bp+8, uint32(8))
					if Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(bp))) != *(*float64)(unsafe.Pointer(bp + 16)) {
						return 0
					}
				}
			} else {
				a += uintptr(_sessionVarintGet(tls, a, bp+24))
				if Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(bp))) != *(*int32)(unsafe.Pointer(bp + 24)) {
					return 0
				}
				if eType == int32(SQLITE_TEXT) {
					z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(bp)))
				} else {
					z = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(bp)))
				}
				if *(*int32)(unsafe.Pointer(bp + 24)) > 0 && libc.Xmemcmp(tls, a, z, uint32(*(*int32)(unsafe.Pointer(bp + 24)))) != 0 {
					return 0
				}
				a += uintptr(*(*int32)(unsafe.Pointer(bp + 24)))
			}
		}
		goto _1
	_1:
		;
		iCol++
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** If required, grow the hash table used to store changes on table pTab
//	** (part of the session pSession). If a fatal OOM error occurs, set the
//	** session object to failed and return SQLITE_ERROR. Otherwise, return
//	** SQLITE_OK.
//	**
//	** It is possible that a non-fatal OOM error occurs in this function. In
//	** that case the hash-table does not grow, but SQLITE_OK is returned anyway.
//	** Growing the hash table in this case is a performance optimization only,
//	** it is not required for correct operation.
//	*/
func _sessionGrowHash(tls *libc.TLS, pSession uintptr, bPatchset int32, pTab uintptr) (r int32) {
	var apNew, p, pNext uintptr
	var bPkOnly, i, iHash, v1 int32
	var nNew Tsqlite3_int64
	_, _, _, _, _, _, _, _ = apNew, bPkOnly, i, iHash, nNew, p, pNext, v1
	if (*TSessionTable)(unsafe.Pointer(pTab)).FnChange == 0 || (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry >= (*TSessionTable)(unsafe.Pointer(pTab)).FnChange/int32(2) {
		if (*TSessionTable)(unsafe.Pointer(pTab)).FnChange != 0 {
			v1 = (*TSessionTable)(unsafe.Pointer(pTab)).FnChange
		} else {
			v1 = int32(128)
		}
		nNew = int64(2) * int64(v1)
		apNew = _sessionMalloc64(tls, pSession, int64(4)*nNew)
		if apNew == uintptr(0) {
			if (*TSessionTable)(unsafe.Pointer(pTab)).FnChange == 0 {
				return int32(SQLITE_ERROR)
			}
			return SQLITE_OK
		}
		libc.Xmemset(tls, apNew, 0, uint32(int64(4)*nNew))
		i = 0
		for {
			if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange) {
				break
			}
			p = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*4))
			for {
				if !(p != 0) {
					break
				}
				bPkOnly = libc.BoolInt32(int32((*TSessionChange)(unsafe.Pointer(p)).Fop) == int32(SQLITE_DELETE) && bPatchset != 0)
				iHash = int32(_sessionChangeHash(tls, pTab, bPkOnly, (*TSessionChange)(unsafe.Pointer(p)).FaRecord, int32(int32(nNew))))
				pNext = (*TSessionChange)(unsafe.Pointer(p)).FpNext
				(*TSessionChange)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*4))
				*(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*4)) = p
				goto _3
			_3:
				;
				p = pNext
			}
			goto _2
		_2:
			;
			i++
		}
		_sessionFree(tls, pSession, (*TSessionTable)(unsafe.Pointer(pTab)).FapChange)
		(*TSessionTable)(unsafe.Pointer(pTab)).FnChange = int32(int32(nNew))
		(*TSessionTable)(unsafe.Pointer(pTab)).FapChange = apNew
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function queries the database for the names of the columns of table
//	** zThis, in schema zDb.
//	**
//	** Otherwise, if they are not NULL, variable *pnCol is set to the number
//	** of columns in the database table and variable *pzTab is set to point to a
//	** nul-terminated copy of the table name. *pazCol (if not NULL) is set to
//	** point to an array of pointers to column names. And *pabPK (again, if not
//	** NULL) is set to point to an array of booleans - true if the corresponding
//	** column is part of the primary key.
//	**
//	** For example, if the table is declared as:
//	**
//	**     CREATE TABLE tbl1(w, x DEFAULT 'abc', y, z, PRIMARY KEY(w, z));
//	**
//	** Then the five output variables are populated as follows:
//	**
//	**     *pnCol  = 4
//	**     *pzTab  = "tbl1"
//	**     *pazCol = {"w", "x", "y", "z"}
//	**     *pazDflt = {NULL, 'abc', NULL, NULL}
//	**     *pabPK  = {1, 0, 0, 1}
//	**
//	** All returned buffers are part of the same single allocation, which must
//	** be freed using sqlite3_free() by the caller
//	*/
func _sessionTableInfo(tls *libc.TLS, pSession uintptr, db uintptr, zDb uintptr, zThis uintptr, pnCol uintptr, pzTab uintptr, pazCol uintptr, pazDflt uintptr, pabPK uintptr, pbRowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var abPK, azCol, azDflt, pAlloc, zDflt, zName, zPragma uintptr
	var bRowid, i, nDbCol, nDflt, nName1, nThis, rc int32
	var nByte Tsqlite3_int64
	var nName Tsize_t
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = abPK, azCol, azDflt, bRowid, i, nByte, nDbCol, nDflt, nName, nName1, nThis, pAlloc, rc, zDflt, zName, zPragma
	nDbCol = 0
	pAlloc = uintptr(0)
	azCol = uintptr(0)
	azDflt = uintptr(0)
	abPK = uintptr(0)
	bRowid = 0 /* Set to true to use rowid as PK */
	*(*uintptr)(unsafe.Pointer(pazCol)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(pabPK)) = uintptr(0)
	*(*int32)(unsafe.Pointer(pnCol)) = 0
	if pzTab != 0 {
		*(*uintptr)(unsafe.Pointer(pzTab)) = uintptr(0)
	}
	if pazDflt != 0 {
		*(*uintptr)(unsafe.Pointer(pazDflt)) = uintptr(0)
	}
	nThis = _sqlite3Strlen30(tls, zThis)
	if nThis == int32(12) && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+13016, zThis) {
		rc = Xsqlite3_table_column_metadata(tls, db, zDb, zThis, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
		if rc == SQLITE_OK {
			/* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
			zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+34777, 0)
		} else {
			if rc == int32(SQLITE_ERROR) {
				zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+1672, 0)
			} else {
				return rc
			}
		}
	} else {
		zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+34898, libc.VaList(bp+16, zDb, zThis))
	}
	if !(zPragma != 0) {
		return int32(SQLITE_NOMEM)
	}
	rc = Xsqlite3_prepare_v2(tls, db, zPragma, -int32(1), bp, uintptr(0))
	Xsqlite3_free(tls, zPragma)
	if rc != SQLITE_OK {
		return rc
	}
	nByte = int64(nThis + int32(1))
	bRowid = libc.BoolInt32(pbRowid != uintptr(0))
	for int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
		nByte += int64(Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))) /* name */
		nByte += int64(Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(4))) /* dflt_value */
		nDbCol++
		if Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(5)) != 0 {
			bRowid = 0
		} /* pk */
	}
	if nDbCol == 0 {
		bRowid = 0
	}
	nDbCol += bRowid
	nByte += int64(libc.Xstrlen(tls, __ccgo_ts+31119))
	rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == SQLITE_OK {
		nByte += int64(uint32(uint32(nDbCol)) * (libc.Uint32FromInt64(4)*libc.Uint32FromInt32(2) + libc.Uint32FromInt64(1) + libc.Uint32FromInt32(1) + libc.Uint32FromInt32(1)))
		pAlloc = _sessionMalloc64(tls, pSession, nByte)
		if pAlloc == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, pAlloc, 0, uint32(uint32(nByte)))
		}
	}
	if rc == SQLITE_OK {
		azCol = pAlloc
		azDflt = azCol + uintptr(nDbCol)*4
		pAlloc = azDflt + uintptr(nDbCol)*4
		abPK = pAlloc
		pAlloc = abPK + uintptr(nDbCol)
		if pzTab != 0 {
			libc.Xmemcpy(tls, pAlloc, zThis, uint32(nThis+int32(1)))
			*(*uintptr)(unsafe.Pointer(pzTab)) = pAlloc
			pAlloc += uintptr(nThis + int32(1))
		}
		i = 0
		if bRowid != 0 {
			nName = libc.Xstrlen(tls, __ccgo_ts+31119)
			libc.Xmemcpy(tls, pAlloc, __ccgo_ts+31119, nName+uint32(1))
			*(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4)) = pAlloc
			pAlloc += uintptr(nName + uint32(1))
			*(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) = uint8(1)
			i++
		}
		for int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			nName1 = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
			nDflt = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(4))
			zName = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
			zDflt = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(4))
			if zName == uintptr(0) {
				break
			}
			libc.Xmemcpy(tls, pAlloc, zName, uint32(nName1+int32(1)))
			*(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4)) = pAlloc
			pAlloc += uintptr(nName1 + int32(1))
			if zDflt != 0 {
				libc.Xmemcpy(tls, pAlloc, zDflt, uint32(nDflt+int32(1)))
				*(*uintptr)(unsafe.Pointer(azDflt + uintptr(i)*4)) = pAlloc
				pAlloc += uintptr(nDflt + int32(1))
			} else {
				*(*uintptr)(unsafe.Pointer(azDflt + uintptr(i)*4)) = uintptr(0)
			}
			*(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) = uint8(Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(5)))
			i++
		}
		rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	/* If successful, populate the output variables. Otherwise, zero them and
	 ** free any allocation made. An error code will be returned in this case.
	 */
	if rc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(pazCol)) = azCol
		if pazDflt != 0 {
			*(*uintptr)(unsafe.Pointer(pazDflt)) = azDflt
		}
		*(*uintptr)(unsafe.Pointer(pabPK)) = abPK
		*(*int32)(unsafe.Pointer(pnCol)) = nDbCol
	} else {
		_sessionFree(tls, pSession, azCol)
	}
	if pbRowid != 0 {
		*(*int32)(unsafe.Pointer(pbRowid)) = bRowid
	}
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

// C documentation
//
//	/*
//	** This function is called to initialize the SessionTable.nCol, azCol[]
//	** abPK[] and azDflt[] members of SessionTable object pTab. If these
//	** fields are already initilialized, this function is a no-op.
//	**
//	** If an error occurs, an error code is stored in sqlite3_session.rc and
//	** non-zero returned. Or, if no error occurs but the table has no primary
//	** key, sqlite3_session.rc is left set to SQLITE_OK and non-zero returned to
//	** indicate that updates on this table should be ignored. SessionTable.abPK
//	** is set to NULL in this case.
//	*/
func _sessionInitTable(tls *libc.TLS, pSession uintptr, pTab uintptr, db uintptr, zDb uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var v1 uintptr
	var _ /* abPK at bp+0 */ uintptr
	_, _, _ = i, rc, v1
	rc = SQLITE_OK
	if (*TSessionTable)(unsafe.Pointer(pTab)).FnCol == 0 {
		if pSession == uintptr(0) || (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK != 0 {
			v1 = pTab + 16
		} else {
			v1 = uintptr(0)
		}
		rc = _sessionTableInfo(tls, pSession, db, zDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, pTab+8, uintptr(0), pTab+20, pTab+24, bp, v1)
		if rc == SQLITE_OK {
			i = 0
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
					break
				}
				if *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i))) != 0 {
					(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = *(*uintptr)(unsafe.Pointer(bp))
					break
				}
				goto _2
			_2:
				;
				i++
			}
			if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+13016, (*TSessionTable)(unsafe.Pointer(pTab)).FzName) {
				(*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 = int32(1)
			}
			if pSession != 0 && (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
				*(*Ti64)(unsafe.Pointer(pSession + 48)) += int64(uint32(libc.Int32FromInt32(1)+_sessionVarintLen(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)+(*TSessionTable)(unsafe.Pointer(pTab)).FnCol) + libc.Xstrlen(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName) + libc.Uint32FromInt32(1))
			}
		}
	}
	if pSession != 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = rc
		return libc.BoolInt32(rc != 0 || (*TSessionTable)(unsafe.Pointer(pTab)).FabPK == uintptr(0))
	}
	return rc
}

// C documentation
//
//	/*
//	** Re-initialize table object pTab.
//	*/
func _sessionReinitTable(tls *libc.TLS, pSession uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, v1 uintptr
	var ii, nOldCol int32
	var _ /* abPK at bp+12 */ uintptr
	var _ /* azCol at bp+4 */ uintptr
	var _ /* azDflt at bp+8 */ uintptr
	var _ /* bRowid at bp+16 */ int32
	var _ /* nCol at bp+0 */ int32
	_, _, _, _ = a, ii, nOldCol, v1
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 16)) = 0
	if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK != 0 {
		v1 = bp + 16
	} else {
		v1 = uintptr(0)
	}
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = _sessionTableInfo(tls, pSession, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, bp, uintptr(0), bp+4, bp+8, bp+12, v1)
	if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc == SQLITE_OK {
		if (*TSessionTable)(unsafe.Pointer(pTab)).FnCol > *(*int32)(unsafe.Pointer(bp)) || (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != *(*int32)(unsafe.Pointer(bp + 16)) {
			(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_SCHEMA)
		} else {
			nOldCol = (*TSessionTable)(unsafe.Pointer(pTab)).FnCol
			ii = 0
			for {
				if !(ii < *(*int32)(unsafe.Pointer(bp))) {
					break
				}
				if ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol {
					if int32(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii)))) != int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)) + uintptr(ii)))) {
						(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_SCHEMA)
					}
				} else {
					if *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)) + uintptr(ii))) != 0 {
						(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_SCHEMA)
					}
				}
				goto _2
			_2:
				;
				ii++
			}
			if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc == SQLITE_OK {
				a = (*TSessionTable)(unsafe.Pointer(pTab)).FazCol
				(*TSessionTable)(unsafe.Pointer(pTab)).FazCol = *(*uintptr)(unsafe.Pointer(bp + 4))
				(*TSessionTable)(unsafe.Pointer(pTab)).FnCol = *(*int32)(unsafe.Pointer(bp))
				(*TSessionTable)(unsafe.Pointer(pTab)).FazDflt = *(*uintptr)(unsafe.Pointer(bp + 8))
				(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = *(*uintptr)(unsafe.Pointer(bp + 12))
				*(*uintptr)(unsafe.Pointer(bp + 4)) = a
			}
			if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
				*(*Ti64)(unsafe.Pointer(pSession + 48)) += int64(*(*int32)(unsafe.Pointer(bp)) - nOldCol)
				*(*Ti64)(unsafe.Pointer(pSession + 48)) += int64(_sessionVarintLen(tls, *(*int32)(unsafe.Pointer(bp))))
				*(*Ti64)(unsafe.Pointer(pSession + 48)) -= int64(_sessionVarintLen(tls, nOldCol))
			}
		}
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	return (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
}

// C documentation
//
//	/*
//	** Session-change object (*pp) contains an old.* record with fewer than
//	** nCol fields. This function updates it with the default values for
//	** the missing fields.
//	*/
func _sessionUpdateOneChange(tls *libc.TLS, pSession uintptr, pRc uintptr, pp uintptr, nCol int32, pDflt uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType, iField, n, n1, n2, nByte, nIncr, v1 int32
	var iVal Ti64
	var pNew, pOld, z, z1, v2, v3 uintptr
	var _ /* iVal at bp+8 */ Ti64
	var _ /* rVal at bp+0 */ float64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = eType, iField, iVal, n, n1, n2, nByte, nIncr, pNew, pOld, z, z1, v1, v2, v3
	pOld = *(*uintptr)(unsafe.Pointer(pp))
	for int32((*TSessionChange)(unsafe.Pointer(pOld)).FnRecordField) < nCol {
		pNew = uintptr(0)
		nByte = 0
		nIncr = 0
		iField = int32((*TSessionChange)(unsafe.Pointer(pOld)).FnRecordField)
		eType = Xsqlite3_column_type(tls, pDflt, iField)
		switch eType {
		case int32(SQLITE_NULL):
			nIncr = int32(1)
		case int32(SQLITE_INTEGER):
			fallthrough
		case int32(SQLITE_FLOAT):
			nIncr = int32(9)
		default:
			n = Xsqlite3_column_bytes(tls, pDflt, iField)
			nIncr = int32(1) + _sessionVarintLen(tls, n) + n
			break
		}
		nByte = int32(uint32(uint32(nIncr)) + (uint32(20) + uint32((*TSessionChange)(unsafe.Pointer(pOld)).FnRecord)))
		pNew = _sessionMalloc64(tls, pSession, int64(int64(nByte)))
		if pNew == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
			return
		} else {
			libc.Xmemcpy(tls, pNew, pOld, uint32(20))
			(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = pNew + 1*20
			libc.Xmemcpy(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord, (*TSessionChange)(unsafe.Pointer(pOld)).FaRecord, uint32((*TSessionChange)(unsafe.Pointer(pOld)).FnRecord))
			v2 = pNew + 8
			v1 = *(*int32)(unsafe.Pointer(v2))
			*(*int32)(unsafe.Pointer(v2))++
			*(*Tu8)(unsafe.Pointer((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord + uintptr(v1))) = uint8(uint8(eType))
			switch eType {
			case int32(SQLITE_INTEGER):
				iVal = Xsqlite3_column_int64(tls, pDflt, iField)
				_sessionPutI64(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), iVal)
				*(*int32)(unsafe.Pointer(pNew + 8)) += int32(8)
			case int32(SQLITE_FLOAT):
				*(*float64)(unsafe.Pointer(bp)) = Xsqlite3_column_double(tls, pDflt, iField)
				*(*Ti64)(unsafe.Pointer(bp + 8)) = 0
				libc.Xmemcpy(tls, bp+8, bp, uint32(8))
				_sessionPutI64(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), *(*Ti64)(unsafe.Pointer(bp + 8)))
				*(*int32)(unsafe.Pointer(pNew + 8)) += int32(8)
			case int32(SQLITE_TEXT):
				n1 = Xsqlite3_column_bytes(tls, pDflt, iField)
				z = Xsqlite3_column_text(tls, pDflt, iField)
				*(*int32)(unsafe.Pointer(pNew + 8)) += _sessionVarintPut(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), n1)
				libc.Xmemcpy(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), z, uint32(uint32(n1)))
				*(*int32)(unsafe.Pointer(pNew + 8)) += n1
			case int32(SQLITE_BLOB):
				n2 = Xsqlite3_column_bytes(tls, pDflt, iField)
				z1 = Xsqlite3_column_blob(tls, pDflt, iField)
				*(*int32)(unsafe.Pointer(pNew + 8)) += _sessionVarintPut(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), n2)
				libc.Xmemcpy(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), z1, uint32(uint32(n2)))
				*(*int32)(unsafe.Pointer(pNew + 8)) += n2
			default:
				break
			}
			_sessionFree(tls, pSession, pOld)
			v3 = pNew
			pOld = v3
			*(*uintptr)(unsafe.Pointer(pp)) = v3
			(*TSessionChange)(unsafe.Pointer(pNew)).FnRecordField++
			*(*int32)(unsafe.Pointer(pNew + 4)) += nIncr
			if pSession != 0 {
				*(*Ti64)(unsafe.Pointer(pSession + 48)) += int64(int64(nIncr))
			}
		}
	}
}

// C documentation
//
//	/*
//	** Ensure that there is room in the buffer to append nByte bytes of data.
//	** If not, use sqlite3_realloc() to grow the buffer so that there is.
//	**
//	** If successful, return zero. Otherwise, if an OOM condition is encountered,
//	** set *pRc to SQLITE_NOMEM and return non-zero.
//	*/
func _sessionBufferGrow(tls *libc.TLS, p uintptr, nByte Ti64, pRc uintptr) (r int32) {
	var aNew uintptr
	var nNew, nReq Ti64
	var v1 int32
	_, _, _, _ = aNew, nNew, nReq, v1
	nReq = int64((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf) + nByte
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK && nReq > int64((*TSessionBuffer)(unsafe.Pointer(p)).FnAlloc) {
		if (*TSessionBuffer)(unsafe.Pointer(p)).FnAlloc != 0 {
			v1 = (*TSessionBuffer)(unsafe.Pointer(p)).FnAlloc
		} else {
			v1 = int32(128)
		}
		nNew = int64(v1)
		for cond := true; cond; cond = nNew < nReq {
			nNew = nNew * int64(2)
		}
		/* The value of SESSION_MAX_BUFFER_SZ is copied from the implementation
		 ** of sqlite3_realloc64(). Allocations greater than this size in bytes
		 ** always fail. It is used here to ensure that this routine can always
		 ** allocate up to this limit - instead of up to the largest power of
		 ** two smaller than the limit.  */
		if nNew > int64(libc.Int32FromInt32(0x7FFFFF00)-libc.Int32FromInt32(1)) {
			nNew = int64(libc.Int32FromInt32(0x7FFFFF00) - libc.Int32FromInt32(1))
			if nNew < nReq {
				*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
				return int32(1)
			}
		}
		aNew = Xsqlite3_realloc64(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf, uint64(uint64(nNew)))
		if uintptr(0) == aNew {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		} else {
			(*TSessionBuffer)(unsafe.Pointer(p)).FaBuf = aNew
			(*TSessionBuffer)(unsafe.Pointer(p)).FnAlloc = int32(int32(nNew))
		}
	}
	return libc.BoolInt32(*(*int32)(unsafe.Pointer(pRc)) != SQLITE_OK)
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append a string to the buffer. All bytes in the string
//	** up to (but not including) the nul-terminator are written to the buffer.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendStr(tls *libc.TLS, p uintptr, zStr uintptr, pRc uintptr) {
	var nStr int32
	_ = nStr
	nStr = _sqlite3Strlen30(tls, zStr)
	if 0 == _sessionBufferGrow(tls, p, int64(nStr+int32(1)), pRc) {
		libc.Xmemcpy(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), zStr, uint32(uint32(nStr)))
		*(*int32)(unsafe.Pointer(p + 4)) += nStr
		*(*Tu8)(unsafe.Pointer((*TSessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf))) = uint8(0x00)
	}
}

// C documentation
//
//	/*
//	** Format a string using printf() style formatting and then append it to the
//	** buffer using sessionAppendString().
//	*/
func _sessionAppendPrintf(tls *libc.TLS, p uintptr, pRc uintptr, zFmt uintptr, va uintptr) {
	var ap Tva_list
	var zApp uintptr
	_, _ = ap, zApp
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		zApp = uintptr(0)
		ap = va
		zApp = Xsqlite3_vmprintf(tls, zFmt, ap)
		if zApp == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		} else {
			_sessionAppendStr(tls, p, zApp, pRc)
		}
		_ = ap
		Xsqlite3_free(tls, zApp)
	}
}

// C documentation
//
//	/*
//	** Prepare a statement against database handle db that SELECTs a single
//	** row containing the default values for each column in table pTab. For
//	** example, if pTab is declared as:
//	**
//	**   CREATE TABLE pTab(a PRIMARY KEY, b DEFAULT 123, c DEFAULT 'abcd');
//	**
//	** Then this function prepares and returns the SQL statement:
//	**
//	**   SELECT NULL, 123, 'abcd';
//	*/
func _sessionPrepareDfltStmt(tls *libc.TLS, db uintptr, pTab uintptr, ppStmt uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var ii int32
	var zDflt, zSep, v2 uintptr
	var _ /* rc at bp+12 */ int32
	var _ /* sql at bp+0 */ TSessionBuffer
	_, _, _, _ = ii, zDflt, zSep, v2
	*(*TSessionBuffer)(unsafe.Pointer(bp)) = TSessionBuffer{}
	*(*int32)(unsafe.Pointer(bp + 12)) = SQLITE_OK
	zSep = __ccgo_ts + 12636
	ii = 0
	*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	_sessionAppendPrintf(tls, bp, bp+12, __ccgo_ts+34927, 0)
	ii = 0
	for {
		if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		if *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FazDflt + uintptr(ii)*4)) != 0 {
			v2 = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FazDflt + uintptr(ii)*4))
		} else {
			v2 = __ccgo_ts + 1673
		}
		zDflt = v2
		_sessionAppendPrintf(tls, bp, bp+12, __ccgo_ts+6449, libc.VaList(bp+24, zSep, zDflt))
		zSep = __ccgo_ts + 16397
		goto _1
	_1:
		;
		ii++
	}
	if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 12)) = Xsqlite3_prepare_v2(tls, db, (*(*TSessionBuffer)(unsafe.Pointer(bp))).FaBuf, -int32(1), ppStmt, uintptr(0))
	}
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp + 12))
}

// C documentation
//
//	/*
//	** Table pTab has one or more existing change-records with old.* records
//	** with fewer than pTab->nCol columns. This function updates all such
//	** change-records with the default values for the missing columns.
//	*/
func _sessionUpdateChanges(tls *libc.TLS, pSession uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var ii int32
	var pp uintptr
	var _ /* pStmt at bp+0 */ uintptr
	var _ /* rc at bp+4 */ int32
	_, _ = ii, pp
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 4)) = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
	*(*int32)(unsafe.Pointer(bp + 4)) = _sessionPrepareDfltStmt(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, pTab, bp)
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
		ii = 0
		pp = uintptr(0)
		ii = 0
		for {
			if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange) {
				break
			}
			pp = (*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(ii)*4
			for {
				if !(*(*uintptr)(unsafe.Pointer(pp)) != 0) {
					break
				}
				if int32((*TSessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FnRecordField) != (*TSessionTable)(unsafe.Pointer(pTab)).FnCol {
					_sessionUpdateOneChange(tls, pSession, bp+4, pp, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, *(*uintptr)(unsafe.Pointer(bp)))
				}
				goto _2
			_2:
				;
				pp = *(*uintptr)(unsafe.Pointer(pp)) + 16
			}
			goto _1
		_1:
			;
			ii++
		}
	}
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = *(*int32)(unsafe.Pointer(bp + 4))
	*(*int32)(unsafe.Pointer(bp + 4)) = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc == SQLITE_OK {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = *(*int32)(unsafe.Pointer(bp + 4))
	}
	return (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
}

// C documentation
//
//	/*
//	** Versions of the four methods in object SessionHook for use with the
//	** sqlite_stat1 table. The purpose of this is to substitute a zero-length
//	** blob each time a NULL value is read from the "idx" column of the
//	** sqlite_stat1 table.
//	*/
type TSessionStat1Ctx = struct {
	Fhook     TSessionHook
	FpSession uintptr
}

type SessionStat1Ctx = TSessionStat1Ctx

type TSessionStat1Ctx1 = struct {
	Fhook     TSessionHook
	FpSession uintptr
}

type SessionStat1Ctx1 = TSessionStat1Ctx1

func _sessionStat1Old(tls *libc.TLS, pCtx uintptr, iCol int32, ppVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	var rc int32
	var _ /* pVal at bp+0 */ uintptr
	_, _ = p, rc
	p = pCtx
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxOld})))(tls, (*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx, iCol, bp)
	if rc == SQLITE_OK && iCol == int32(1) && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp))) == int32(SQLITE_NULL) {
		*(*uintptr)(unsafe.Pointer(bp)) = (*Tsqlite3_session)(unsafe.Pointer((*TSessionStat1Ctx)(unsafe.Pointer(p)).FpSession)).FpZeroBlob
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

func _sessionStat1New(tls *libc.TLS, pCtx uintptr, iCol int32, ppVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	var rc int32
	var _ /* pVal at bp+0 */ uintptr
	_, _ = p, rc
	p = pCtx
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxNew})))(tls, (*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx, iCol, bp)
	if rc == SQLITE_OK && iCol == int32(1) && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp))) == int32(SQLITE_NULL) {
		*(*uintptr)(unsafe.Pointer(bp)) = (*Tsqlite3_session)(unsafe.Pointer((*TSessionStat1Ctx)(unsafe.Pointer(p)).FpSession)).FpZeroBlob
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

func _sessionStat1Count(tls *libc.TLS, pCtx uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pCtx
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxCount})))(tls, (*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx)
}

func _sessionStat1Depth(tls *libc.TLS, pCtx uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pCtx
	return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxDepth})))(tls, (*TSessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx)
}

func _sessionUpdateMaxSize(tls *libc.TLS, op int32, pSession uintptr, pTab uintptr, pC uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bChanged, eType, ii, ii1, nIncr, nOld int32
	var pCsr, v3 uintptr
	var _ /* dVal at bp+24 */ float64
	var _ /* iVal at bp+16 */ Tsqlite3_int64
	var _ /* nByte at bp+32 */ int32
	var _ /* nNew at bp+0 */ Ti64
	var _ /* p at bp+12 */ uintptr
	var _ /* p at bp+8 */ uintptr
	_, _, _, _, _, _, _, _ = bChanged, eType, ii, ii1, nIncr, nOld, pCsr, v3
	*(*Ti64)(unsafe.Pointer(bp)) = int64(2)
	if int32((*TSessionChange)(unsafe.Pointer(pC)).Fop) == int32(SQLITE_INSERT) {
		if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
			*(*Ti64)(unsafe.Pointer(bp)) += int64(9)
		}
		if op != int32(SQLITE_DELETE) {
			ii = 0
			for {
				if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
					break
				}
				*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
				(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, ii, bp+8)
				_sessionSerializeValue(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(bp + 8)), bp)
				goto _1
			_1:
				;
				ii++
			}
		}
	} else {
		if op == int32(SQLITE_DELETE) {
			*(*Ti64)(unsafe.Pointer(bp)) += int64((*TSessionChange)(unsafe.Pointer(pC)).FnRecord)
			if Xsqlite3_preupdate_blobwrite(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb) >= 0 {
				*(*Ti64)(unsafe.Pointer(bp)) += int64((*TSessionChange)(unsafe.Pointer(pC)).FnRecord)
			}
		} else {
			pCsr = (*TSessionChange)(unsafe.Pointer(pC)).FaRecord
			if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
				*(*Ti64)(unsafe.Pointer(bp)) += int64(libc.Int32FromInt32(9) + libc.Int32FromInt32(1))
				pCsr += uintptr(9)
			}
			ii1 = (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid
			for {
				if !(ii1 < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
					break
				}
				bChanged = int32(1)
				nOld = 0
				*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
				(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, ii1-(*TSessionTable)(unsafe.Pointer(pTab)).FbRowid, bp+12)
				if *(*uintptr)(unsafe.Pointer(bp + 12)) == uintptr(0) {
					return int32(SQLITE_NOMEM)
				}
				v3 = pCsr
				pCsr++
				eType = int32(*(*Tu8)(unsafe.Pointer(v3)))
				switch eType {
				case int32(SQLITE_NULL):
					bChanged = libc.BoolInt32(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 12))) != int32(SQLITE_NULL))
				case int32(SQLITE_FLOAT):
					fallthrough
				case int32(SQLITE_INTEGER):
					if eType == Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 12))) {
						*(*Tsqlite3_int64)(unsafe.Pointer(bp + 16)) = _sessionGetI64(tls, pCsr)
						if eType == int32(SQLITE_INTEGER) {
							bChanged = libc.BoolInt32(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 16)) != Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 12))))
						} else {
							libc.Xmemcpy(tls, bp+24, bp+16, uint32(8))
							bChanged = libc.BoolInt32(*(*float64)(unsafe.Pointer(bp + 24)) != Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(bp + 12))))
						}
					}
					nOld = int32(8)
					pCsr += uintptr(8)
				default:
					nOld = _sessionVarintGet(tls, pCsr, bp+32)
					pCsr += uintptr(nOld)
					nOld += *(*int32)(unsafe.Pointer(bp + 32))
					if eType == Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 12))) && *(*int32)(unsafe.Pointer(bp + 32)) == Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 12))) && (*(*int32)(unsafe.Pointer(bp + 32)) == 0 || 0 == libc.Xmemcmp(tls, pCsr, Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(bp + 12))), uint32(*(*int32)(unsafe.Pointer(bp + 32))))) {
						bChanged = 0
					}
					pCsr += uintptr(*(*int32)(unsafe.Pointer(bp + 32)))
					break
				}
				if bChanged != 0 && *(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii1))) != 0 {
					*(*Ti64)(unsafe.Pointer(bp)) = int64((*TSessionChange)(unsafe.Pointer(pC)).FnRecord + int32(2))
					break
				}
				if bChanged != 0 {
					*(*Ti64)(unsafe.Pointer(bp)) += int64(int32(1) + nOld)
					_sessionSerializeValue(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(bp + 12)), bp)
				} else {
					if *(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii1))) != 0 {
						*(*Ti64)(unsafe.Pointer(bp)) += int64(int32(2) + nOld)
					} else {
						*(*Ti64)(unsafe.Pointer(bp)) += int64(2)
					}
				}
				goto _2
			_2:
				;
				ii1++
			}
		}
	}
	if *(*Ti64)(unsafe.Pointer(bp)) > int64((*TSessionChange)(unsafe.Pointer(pC)).FnMaxSize) {
		nIncr = int32(*(*Ti64)(unsafe.Pointer(bp)) - int64((*TSessionChange)(unsafe.Pointer(pC)).FnMaxSize))
		(*TSessionChange)(unsafe.Pointer(pC)).FnMaxSize = int32(*(*Ti64)(unsafe.Pointer(bp)))
		*(*Ti64)(unsafe.Pointer(pSession + 48)) += int64(int64(nIncr))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function is only called from with a pre-update-hook reporting a
//	** change on table pTab (attached to session pSession). The type of change
//	** (UPDATE, INSERT, DELETE) is specified by the first argument.
//	**
//	** Unless one is already present or an error occurs, an entry is added
//	** to the changed-rows hash table associated with table pTab.
//	*/
func _sessionPreupdateOneChange(tls *libc.TLS, op int32, iRowid Ti64, pSession uintptr, pTab uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, nExpect, rc int32
	var p, pC uintptr
	var _ /* bNull at bp+4 */ int32
	var _ /* iHash at bp+0 */ int32
	var _ /* nByte at bp+32 */ Tsqlite3_int64
	var _ /* p at bp+40 */ uintptr
	var _ /* p at bp+44 */ uintptr
	var _ /* stat1 at bp+8 */ TSessionStat1Ctx
	_, _, _, _, _ = i, nExpect, p, pC, rc
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	rc = SQLITE_OK
	nExpect = 0
	*(*TSessionStat1Ctx)(unsafe.Pointer(bp + 8)) = TSessionStat1Ctx{}
	if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
		return
	}
	/* Load table details if required */
	if _sessionInitTable(tls, pSession, pTab, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb) != 0 {
		return
	}
	/* Check the number of columns in this xPreUpdate call matches the
	 ** number of columns in the table.  */
	nExpect = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx)
	if (*TSessionTable)(unsafe.Pointer(pTab)).FnCol-(*TSessionTable)(unsafe.Pointer(pTab)).FbRowid < nExpect {
		if _sessionReinitTable(tls, pSession, pTab) != 0 {
			return
		}
		if _sessionUpdateChanges(tls, pSession, pTab) != 0 {
			return
		}
	}
	if (*TSessionTable)(unsafe.Pointer(pTab)).FnCol-(*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != nExpect {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_SCHEMA)
		return
	}
	/* Grow the hash table if required */
	if _sessionGrowHash(tls, pSession, 0, pTab) != 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_NOMEM)
		return
	}
	if (*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0 {
		(*(*TSessionStat1Ctx)(unsafe.Pointer(bp + 8))).Fhook = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook
		(*(*TSessionStat1Ctx)(unsafe.Pointer(bp + 8))).FpSession = pSession
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = bp + 8
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = __ccgo_fp(_sessionStat1New)
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = __ccgo_fp(_sessionStat1Old)
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = __ccgo_fp(_sessionStat1Count)
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = __ccgo_fp(_sessionStat1Depth)
		if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob == uintptr(0) {
			p = _sqlite3ValueNew(tls, uintptr(0))
			if p == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
				goto error_out
			}
			_sqlite3ValueSetStr(tls, p, 0, __ccgo_ts+1672, uint8(0), libc.UintptrFromInt32(0))
			(*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob = p
		}
	}
	/* Calculate the hash-key for this change. If the primary key of the row
	 ** includes a NULL value, exit early. Such changes are ignored by the
	 ** session module. */
	rc = _sessionPreupdateHash(tls, pSession, iRowid, pTab, libc.BoolInt32(op == int32(SQLITE_INSERT)), bp, bp+4)
	if rc != SQLITE_OK {
		goto error_out
	}
	if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
		pC = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(*(*int32)(unsafe.Pointer(bp)))*4))
		for {
			if !(pC != 0) {
				break
			}
			if _sessionPreupdateEqual(tls, pSession, iRowid, pTab, pC, op) != 0 {
				break
			}
			goto _1
		_1:
			;
			pC = (*TSessionChange)(unsafe.Pointer(pC)).FpNext
		}
		if pC == uintptr(0) { /* Used to iterate through columns */
			(*TSessionTable)(unsafe.Pointer(pTab)).FnEntry++
			/* Figure out how large an allocation is required */
			*(*Tsqlite3_int64)(unsafe.Pointer(bp + 32)) = int64(20)
			i = 0
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol-(*TSessionTable)(unsafe.Pointer(pTab)).FbRowid) {
					break
				}
				*(*uintptr)(unsafe.Pointer(bp + 40)) = uintptr(0)
				if op != int32(SQLITE_INSERT) {
					(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+40)
				} else {
					if *(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
						(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+40)
					}
				}
				/* This may fail if SQLite value p contains a utf-16 string that must
				 ** be converted to utf-8 and an OOM error occurs while doing so. */
				rc = _sessionSerializeValue(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(bp + 40)), bp+32)
				if rc != SQLITE_OK {
					goto error_out
				}
				goto _2
			_2:
				;
				i++
			}
			if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
				*(*Tsqlite3_int64)(unsafe.Pointer(bp + 32)) += int64(9) /* Size of rowid field - an integer */
			}
			/* Allocate the change object */
			pC = _sessionMalloc64(tls, pSession, *(*Tsqlite3_int64)(unsafe.Pointer(bp + 32)))
			if !(pC != 0) {
				rc = int32(SQLITE_NOMEM)
				goto error_out
			} else {
				libc.Xmemset(tls, pC, 0, uint32(20))
				(*TSessionChange)(unsafe.Pointer(pC)).FaRecord = pC + 1*20
			}
			/* Populate the change object. None of the preupdate_old(),
			 ** preupdate_new() or SerializeValue() calls below may fail as all
			 ** required values and encodings have already been cached in memory.
			 ** It is not possible for an OOM to occur in this block. */
			*(*Tsqlite3_int64)(unsafe.Pointer(bp + 32)) = 0
			if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
				*(*Tu8)(unsafe.Pointer((*TSessionChange)(unsafe.Pointer(pC)).FaRecord)) = uint8(SQLITE_INTEGER)
				_sessionPutI64(tls, (*TSessionChange)(unsafe.Pointer(pC)).FaRecord+1, iRowid)
				*(*Tsqlite3_int64)(unsafe.Pointer(bp + 32)) = int64(9)
			}
			i = 0
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol-(*TSessionTable)(unsafe.Pointer(pTab)).FbRowid) {
					break
				}
				*(*uintptr)(unsafe.Pointer(bp + 44)) = uintptr(0)
				if op != int32(SQLITE_INSERT) {
					(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+44)
				} else {
					if *(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
						(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+44)
					}
				}
				_sessionSerializeValue(tls, (*TSessionChange)(unsafe.Pointer(pC)).FaRecord+uintptr(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 32))), *(*uintptr)(unsafe.Pointer(bp + 44)), bp+32)
				goto _3
			_3:
				;
				i++
			}
			/* Add the change to the hash-table */
			if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect != 0 || (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) != 0 {
				(*TSessionChange)(unsafe.Pointer(pC)).FbIndirect = uint8(1)
			}
			(*TSessionChange)(unsafe.Pointer(pC)).FnRecordField = uint16((*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
			(*TSessionChange)(unsafe.Pointer(pC)).FnRecord = int32(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 32)))
			(*TSessionChange)(unsafe.Pointer(pC)).Fop = uint8(uint8(op))
			(*TSessionChange)(unsafe.Pointer(pC)).FpNext = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(*(*int32)(unsafe.Pointer(bp)))*4))
			*(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(*(*int32)(unsafe.Pointer(bp)))*4)) = pC
		} else {
			if (*TSessionChange)(unsafe.Pointer(pC)).FbIndirect != 0 {
				/* If the existing change is considered "indirect", but this current
				 ** change is "direct", mark the change object as direct. */
				if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) == 0 && (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect == 0 {
					(*TSessionChange)(unsafe.Pointer(pC)).FbIndirect = uint8(0)
				}
			}
		}
		if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
			rc = _sessionUpdateMaxSize(tls, op, pSession, pTab, pC)
		}
	}
	/* If an error has occurred, mark the session object as failed. */
	goto error_out
error_out:
	;
	if (*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook = (*(*TSessionStat1Ctx)(unsafe.Pointer(bp + 8))).Fhook
	}
	if rc != SQLITE_OK {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = rc
	}
}

func _sessionFindTable(tls *libc.TLS, pSession uintptr, zName uintptr, ppTab uintptr) (r int32) {
	var nName, rc int32
	var pRet uintptr
	_, _, _ = nName, pRet, rc
	rc = SQLITE_OK
	nName = _sqlite3Strlen30(tls, zName)
	/* Search for an existing table */
	pRet = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
	for {
		if !(pRet != 0) {
			break
		}
		if 0 == Xsqlite3_strnicmp(tls, (*TSessionTable)(unsafe.Pointer(pRet)).FzName, zName, nName+int32(1)) {
			break
		}
		goto _1
	_1:
		;
		pRet = (*TSessionTable)(unsafe.Pointer(pRet)).FpNext
	}
	if pRet == uintptr(0) && (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach != 0 {
		/* If there is a table-filter configured, invoke it. If it returns 0,
		 ** do not automatically add the new table. */
		if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FxTableFilter == uintptr(0) || (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).FxTableFilter})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpFilterCtx, zName) != 0 {
			rc = Xsqlite3session_attach(tls, pSession, zName)
			if rc == SQLITE_OK {
				pRet = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
				for pRet != 0 && (*TSessionTable)(unsafe.Pointer(pRet)).FpNext != 0 {
					pRet = (*TSessionTable)(unsafe.Pointer(pRet)).FpNext
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppTab)) = pRet
	return rc
}

// C documentation
//
//	/*
//	** The 'pre-update' hook registered by this module with SQLite databases.
//	*/
func _xPreUpdate(tls *libc.TLS, pCtx uintptr, db uintptr, op int32, zDb uintptr, zName uintptr, iKey1 Tsqlite3_int64, iKey2 Tsqlite3_int64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nDb int32
	var pSession uintptr
	var _ /* pTab at bp+0 */ uintptr
	_, _ = nDb, pSession
	nDb = _sqlite3Strlen30(tls, zDb)
	_ = iKey1
	_ = iKey2
	pSession = pCtx
	for {
		if !(pSession != 0) {
			break
		}
		/* If this session is attached to a different database ("main", "temp"
		 ** etc.), or if it is not currently enabled, there is nothing to do. Skip
		 ** to the next session object attached to this database. */
		if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnable == 0 {
			goto _1
		}
		if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
			goto _1
		}
		if Xsqlite3_strnicmp(tls, zDb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, nDb+int32(1)) != 0 {
			goto _1
		}
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = _sessionFindTable(tls, pSession, zName, bp)
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			_sessionPreupdateOneChange(tls, op, iKey1, pSession, *(*uintptr)(unsafe.Pointer(bp)))
			if op == int32(SQLITE_UPDATE) {
				_sessionPreupdateOneChange(tls, int32(SQLITE_INSERT), iKey2, pSession, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		goto _1
	_1:
		;
		pSession = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpNext
	}
}

// C documentation
//
//	/*
//	** The pre-update hook implementations.
//	*/
func _sessionPreupdateOld(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) (r int32) {
	return Xsqlite3_preupdate_old(tls, pCtx, iVal, ppVal)
}

func _sessionPreupdateNew(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) (r int32) {
	return Xsqlite3_preupdate_new(tls, pCtx, iVal, ppVal)
}

func _sessionPreupdateCount(tls *libc.TLS, pCtx uintptr) (r int32) {
	return Xsqlite3_preupdate_count(tls, pCtx)
}

func _sessionPreupdateDepth(tls *libc.TLS, pCtx uintptr) (r int32) {
	return Xsqlite3_preupdate_depth(tls, pCtx)
}

// C documentation
//
//	/*
//	** Install the pre-update hooks on the session object passed as the only
//	** argument.
//	*/
func _sessionPreupdateHooks(tls *libc.TLS, pSession uintptr) {
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = __ccgo_fp(_sessionPreupdateOld)
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = __ccgo_fp(_sessionPreupdateNew)
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = __ccgo_fp(_sessionPreupdateCount)
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = __ccgo_fp(_sessionPreupdateDepth)
}

type TSessionDiffCtx = struct {
	FpStmt   uintptr
	FbRowid  int32
	FnOldOff int32
}

type SessionDiffCtx = TSessionDiffCtx

type TSessionDiffCtx1 = struct {
	FpStmt   uintptr
	FbRowid  int32
	FnOldOff int32
}

type SessionDiffCtx1 = TSessionDiffCtx1

// C documentation
//
//	/*
//	** The diff hook implementations.
//	*/
func _sessionDiffOld(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pCtx
	*(*uintptr)(unsafe.Pointer(ppVal)) = Xsqlite3_column_value(tls, (*TSessionDiffCtx)(unsafe.Pointer(p)).FpStmt, iVal+(*TSessionDiffCtx)(unsafe.Pointer(p)).FnOldOff+(*TSessionDiffCtx)(unsafe.Pointer(p)).FbRowid)
	return SQLITE_OK
}

func _sessionDiffNew(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pCtx
	*(*uintptr)(unsafe.Pointer(ppVal)) = Xsqlite3_column_value(tls, (*TSessionDiffCtx)(unsafe.Pointer(p)).FpStmt, iVal+(*TSessionDiffCtx)(unsafe.Pointer(p)).FbRowid)
	return SQLITE_OK
}

func _sessionDiffCount(tls *libc.TLS, pCtx uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	p = pCtx
	if (*TSessionDiffCtx)(unsafe.Pointer(p)).FnOldOff != 0 {
		v1 = (*TSessionDiffCtx)(unsafe.Pointer(p)).FnOldOff
	} else {
		v1 = Xsqlite3_column_count(tls, (*TSessionDiffCtx)(unsafe.Pointer(p)).FpStmt)
	}
	return v1 - (*TSessionDiffCtx)(unsafe.Pointer(p)).FbRowid
}

func _sessionDiffDepth(tls *libc.TLS, pCtx uintptr) (r int32) {
	_ = pCtx
	return 0
}

// C documentation
//
//	/*
//	** Install the diff hooks on the session object passed as the only
//	** argument.
//	*/
func _sessionDiffHooks(tls *libc.TLS, pSession uintptr, pDiffCtx uintptr) {
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = pDiffCtx
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = __ccgo_fp(_sessionDiffOld)
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = __ccgo_fp(_sessionDiffNew)
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = __ccgo_fp(_sessionDiffCount)
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = __ccgo_fp(_sessionDiffDepth)
}

func _sessionExprComparePK(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var i int32
	var zRet, zSep uintptr
	_, _, _ = i, zRet, zSep
	zSep = __ccgo_ts + 1672
	zRet = uintptr(0)
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		if *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+34934, libc.VaList(bp+8, zRet, zSep, zDb1, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4)), zDb2, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4))))
			zSep = __ccgo_ts + 23484
			if zRet == uintptr(0) {
				break
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return zRet
}

func _sessionExprCompareOther(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var bHave, i int32
	var zRet, zSep uintptr
	_, _, _, _ = bHave, i, zRet, zSep
	zSep = __ccgo_ts + 1672
	zRet = uintptr(0)
	bHave = 0
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		if int32(*(*Tu8)(unsafe.Pointer(abPK + uintptr(i)))) == 0 {
			bHave = int32(1)
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+34968, libc.VaList(bp+8, zRet, zSep, zDb1, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4)), zDb2, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4))))
			zSep = __ccgo_ts + 35009
			if zRet == uintptr(0) {
				break
			}
		}
		goto _1
	_1:
		;
		i++
	}
	if bHave == 0 {
		zRet = Xsqlite3_mprintf(tls, __ccgo_ts+1792, 0)
	}
	return zRet
}

func _sessionSelectFindNew(tls *libc.TLS, zDb1 uintptr, zDb2 uintptr, bRowid int32, zTbl uintptr, zExpr uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var zRet, zSel, v1 uintptr
	_, _, _ = zRet, zSel, v1
	if bRowid != 0 {
		v1 = __ccgo_ts + 35014
	} else {
		v1 = __ccgo_ts + 7963
	}
	zSel = v1
	zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35025, libc.VaList(bp+8, zSel, zDb1, zTbl, zDb2, zTbl, zExpr))
	return zRet
}

func _sessionDiffFindNew(tls *libc.TLS, op int32, pSession uintptr, pTab uintptr, zDb1 uintptr, zDb2 uintptr, zExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iRowid Ti64
	var pDiffCtx, zStmt uintptr
	var rc int32
	var v1 int64
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _ = iRowid, pDiffCtx, rc, zStmt, v1
	rc = SQLITE_OK
	zStmt = _sessionSelectFindNew(tls, zDb1, zDb2, (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zExpr)
	if zStmt == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, zStmt, -int32(1), bp, uintptr(0))
		if rc == SQLITE_OK {
			pDiffCtx = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx
			(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FpStmt = *(*uintptr)(unsafe.Pointer(bp))
			(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FnOldOff = 0
			(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FbRowid = (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid
			for int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
					v1 = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
				} else {
					v1 = 0
				}
				iRowid = v1
				_sessionPreupdateOneChange(tls, op, iRowid, pSession, pTab)
			}
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		Xsqlite3_free(tls, zStmt)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return a comma-separated list of the fully-qualified (with both database
//	** and table name) column names from table pTab. e.g.
//	**
//	**    "main"."t1"."a", "main"."t1"."b", "main"."t1"."c"
//	*/
func _sessionAllCols(tls *libc.TLS, zDb uintptr, pTab uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var ii int32
	var zRet, v2 uintptr
	_, _, _ = ii, zRet, v2
	zRet = uintptr(0)
	ii = 0
	for {
		if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		if zRet != 0 {
			v2 = __ccgo_ts + 16397
		} else {
			v2 = __ccgo_ts + 1672
		}
		zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35104, libc.VaList(bp+8, zRet, v2, zDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FazCol + uintptr(ii)*4))))
		if !(zRet != 0) {
			break
		}
		goto _1
	_1:
		;
		ii++
	}
	return zRet
}

func _sessionDiffFindModified(tls *libc.TLS, pSession uintptr, pTab uintptr, zFrom uintptr, zExpr uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var iRowid Ti64
	var pDiffCtx, z1, z2, zExpr2, zStmt uintptr
	var rc int32
	var v1 int64
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = iRowid, pDiffCtx, rc, z1, z2, zExpr2, zStmt, v1
	rc = SQLITE_OK
	zExpr2 = _sessionExprCompareOther(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, zFrom, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
	if zExpr2 == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		z1 = _sessionAllCols(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, pTab)
		z2 = _sessionAllCols(tls, zFrom, pTab)
		zStmt = Xsqlite3_mprintf(tls, __ccgo_ts+35123, libc.VaList(bp+16, z1, z2, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zFrom, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zExpr, zExpr2))
		if zStmt == uintptr(0) || z1 == uintptr(0) || z2 == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			rc = Xsqlite3_prepare(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, zStmt, -int32(1), bp, uintptr(0))
			if rc == SQLITE_OK {
				pDiffCtx = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx
				(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FpStmt = *(*uintptr)(unsafe.Pointer(bp))
				(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FnOldOff = (*TSessionTable)(unsafe.Pointer(pTab)).FnCol
				for int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
					if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
						v1 = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
					} else {
						v1 = 0
					}
					iRowid = v1
					_sessionPreupdateOneChange(tls, int32(SQLITE_UPDATE), iRowid, pSession, pTab)
				}
				rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		Xsqlite3_free(tls, zStmt)
		Xsqlite3_free(tls, z1)
		Xsqlite3_free(tls, z2)
	}
	return rc
}

func Xsqlite3session_diff(tls *libc.TLS, pSession uintptr, zFrom uintptr, zTbl uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bHasPk, bMismatch, i, rc int32
	var db, zDb, zExpr, v1 uintptr
	var _ /* abPK at bp+24 */ uintptr
	var _ /* azCol at bp+28 */ uintptr
	var _ /* bRowid at bp+20 */ int32
	var _ /* d at bp+0 */ TSessionDiffCtx
	var _ /* nCol at bp+16 */ int32
	var _ /* pTo at bp+12 */ uintptr
	_, _, _, _, _, _, _, _ = bHasPk, bMismatch, db, i, rc, zDb, zExpr, v1
	zDb = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb
	rc = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
	libc.Xmemset(tls, bp, 0, uint32(12))
	_sessionDiffHooks(tls, pSession, bp)
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if pzErrMsg != 0 {
		*(*uintptr)(unsafe.Pointer(pzErrMsg)) = uintptr(0)
	}
	if rc == SQLITE_OK {
		zExpr = uintptr(0)
		db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb /* Table zTbl */
		/* Locate and if necessary initialize the target table object */
		rc = _sessionFindTable(tls, pSession, zTbl, bp+12)
		if *(*uintptr)(unsafe.Pointer(bp + 12)) == uintptr(0) {
			goto diff_out
		}
		if _sessionInitTable(tls, pSession, *(*uintptr)(unsafe.Pointer(bp + 12)), (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb) != 0 {
			rc = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
			goto diff_out
		}
		/* Check the table schemas match */
		if rc == SQLITE_OK {
			bHasPk = 0
			bMismatch = 0 /* Columns in zFrom.zTbl */
			*(*int32)(unsafe.Pointer(bp + 20)) = 0
			*(*uintptr)(unsafe.Pointer(bp + 28)) = uintptr(0)
			if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK != 0 {
				v1 = bp + 20
			} else {
				v1 = uintptr(0)
			}
			rc = _sessionTableInfo(tls, uintptr(0), db, zFrom, zTbl, bp+16, uintptr(0), bp+28, uintptr(0), bp+24, v1)
			if rc == SQLITE_OK {
				if (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FnCol != *(*int32)(unsafe.Pointer(bp + 16)) {
					bMismatch = int32(1)
				} else {
					i = 0
					for {
						if !(i < *(*int32)(unsafe.Pointer(bp + 16))) {
							break
						}
						if int32(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FabPK + uintptr(i)))) != int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)) + uintptr(i)))) {
							bMismatch = int32(1)
						}
						if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 28)) + uintptr(i)*4)), *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FazCol + uintptr(i)*4))) != 0 {
							bMismatch = int32(1)
						}
						if *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)) + uintptr(i))) != 0 {
							bHasPk = int32(1)
						}
						goto _2
					_2:
						;
						i++
					}
				}
			}
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 28)))
			if bMismatch != 0 {
				if pzErrMsg != 0 {
					*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+35180, 0)
				}
				rc = int32(SQLITE_SCHEMA)
			}
			if bHasPk == 0 {
				/* Ignore tables with no primary keys */
				goto diff_out
			}
		}
		if rc == SQLITE_OK {
			zExpr = _sessionExprComparePK(tls, (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FnCol, zDb, zFrom, (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FzName, (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FazCol, (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FabPK)
		}
		/* Find new rows */
		if rc == SQLITE_OK {
			rc = _sessionDiffFindNew(tls, int32(SQLITE_INSERT), pSession, *(*uintptr)(unsafe.Pointer(bp + 12)), zDb, zFrom, zExpr)
		}
		/* Find old rows */
		if rc == SQLITE_OK {
			rc = _sessionDiffFindNew(tls, int32(SQLITE_DELETE), pSession, *(*uintptr)(unsafe.Pointer(bp + 12)), zFrom, zDb, zExpr)
		}
		/* Find modified rows */
		if rc == SQLITE_OK {
			rc = _sessionDiffFindModified(tls, pSession, *(*uintptr)(unsafe.Pointer(bp + 12)), zFrom, zExpr)
		}
		Xsqlite3_free(tls, zExpr)
	}
	goto diff_out
diff_out:
	;
	_sessionPreupdateHooks(tls, pSession)
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return rc
}

// C documentation
//
//	/*
//	** Create a session object. This session object will record changes to
//	** database zDb attached to connection db.
//	*/
func Xsqlite3session_create(tls *libc.TLS, db uintptr, zDb uintptr, ppSession uintptr) (r int32) {
	var nDb int32
	var pNew, pOld uintptr
	_, _, _ = nDb, pNew, pOld        /* Session object already attached to db */
	nDb = _sqlite3Strlen30(tls, zDb) /* Length of zDb in bytes */
	/* Zero the output value in case an error occurs. */
	*(*uintptr)(unsafe.Pointer(ppSession)) = uintptr(0)
	/* Allocate and populate the new session object. */
	pNew = Xsqlite3_malloc64(tls, uint64(uint32(88)+uint32(uint32(nDb))+uint32(1)))
	if !(pNew != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pNew, 0, uint32(88))
	(*Tsqlite3_session)(unsafe.Pointer(pNew)).Fdb = db
	(*Tsqlite3_session)(unsafe.Pointer(pNew)).FzDb = pNew + 1*88
	(*Tsqlite3_session)(unsafe.Pointer(pNew)).FbEnable = int32(1)
	libc.Xmemcpy(tls, (*Tsqlite3_session)(unsafe.Pointer(pNew)).FzDb, zDb, uint32(nDb+int32(1)))
	_sessionPreupdateHooks(tls, pNew)
	/* Add the new session object to the linked list of session objects
	 ** attached to database handle $db. Do this under the cover of the db
	 ** handle mutex.  */
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	pOld = Xsqlite3_preupdate_hook(tls, db, __ccgo_fp(_xPreUpdate), pNew)
	(*Tsqlite3_session)(unsafe.Pointer(pNew)).FpNext = pOld
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	*(*uintptr)(unsafe.Pointer(ppSession)) = pNew
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Free the list of table objects passed as the first argument. The contents
//	** of the changed-rows hash tables are also deleted.
//	*/
func _sessionDeleteTable(tls *libc.TLS, pSession uintptr, pList uintptr) {
	var i int32
	var p, pNext, pNextChange, pTab uintptr
	_, _, _, _, _ = i, p, pNext, pNextChange, pTab
	pTab = pList
	for {
		if !(pTab != 0) {
			break
		}
		pNext = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
		i = 0
		for {
			if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange) {
				break
			}
			p = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*4))
			for {
				if !(p != 0) {
					break
				}
				pNextChange = (*TSessionChange)(unsafe.Pointer(p)).FpNext
				_sessionFree(tls, pSession, p)
				goto _3
			_3:
				;
				p = pNextChange
			}
			goto _2
		_2:
			;
			i++
		}
		Xsqlite3_finalize(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt)
		_sessionFree(tls, pSession, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol) /* cast works around VC++ bug */
		_sessionFree(tls, pSession, (*TSessionTable)(unsafe.Pointer(pTab)).FapChange)
		_sessionFree(tls, pSession, pTab)
		goto _1
	_1:
		;
		pTab = pNext
	}
}

// C documentation
//
//	/*
//	** Delete a session object previously allocated using sqlite3session_create().
//	*/
func Xsqlite3session_delete(tls *libc.TLS, pSession uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pp uintptr
	var _ /* pHead at bp+0 */ uintptr
	_, _ = db, pp
	db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb
	/* Unlink the session from the linked list of sessions attached to the
	 ** database handle. Hold the db mutex while doing so.  */
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3_preupdate_hook(tls, db, uintptr(0), uintptr(0))
	pp = bp
	for {
		if !(*(*uintptr)(unsafe.Pointer(pp)) != uintptr(0)) {
			break
		}
		if *(*uintptr)(unsafe.Pointer(pp)) == pSession {
			*(*uintptr)(unsafe.Pointer(pp)) = (*Tsqlite3_session)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				Xsqlite3_preupdate_hook(tls, db, __ccgo_fp(_xPreUpdate), *(*uintptr)(unsafe.Pointer(bp)))
			}
			break
		}
		goto _1
	_1:
		;
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 60
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	_sqlite3ValueFree(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob)
	/* Delete all attached table objects. And the contents of their
	 ** associated hash-tables. */
	_sessionDeleteTable(tls, pSession, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable)
	/* Free the session object. */
	Xsqlite3_free(tls, pSession)
}

// C documentation
//
//	/*
//	** Set a table filter on a Session Object.
//	*/
func Xsqlite3session_table_filter(tls *libc.TLS, pSession uintptr, xFilter uintptr, pCtx uintptr) {
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = int32(1)
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).FpFilterCtx = pCtx
	(*Tsqlite3_session)(unsafe.Pointer(pSession)).FxTableFilter = xFilter
}

// C documentation
//
//	/*
//	** Attach a table to a session. All subsequent changes made to the table
//	** while the session object is enabled will be recorded.
//	**
//	** Only tables that have a PRIMARY KEY defined may be attached. It does
//	** not matter if the PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias)
//	** or not.
//	*/
func Xsqlite3session_attach(tls *libc.TLS, pSession uintptr, zName uintptr) (r int32) {
	var nByte, nName, rc int32
	var pTab, ppTab uintptr
	_, _, _, _, _ = nByte, nName, pTab, ppTab, rc
	rc = SQLITE_OK
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if !(zName != 0) {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = int32(1)
	} else { /* Number of bytes in string zName */
		/* First search for an existing entry. If one is found, this call is
		 ** a no-op. Return early. */
		nName = _sqlite3Strlen30(tls, zName)
		pTab = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
		for {
			if !(pTab != 0) {
				break
			}
			if 0 == Xsqlite3_strnicmp(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zName, nName+int32(1)) {
				break
			}
			goto _1
		_1:
			;
			pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
		}
		if !(pTab != 0) {
			/* Allocate new SessionTable object. */
			nByte = int32(uint32(48) + uint32(uint32(nName)) + uint32(1))
			pTab = _sessionMalloc64(tls, pSession, int64(int64(nByte)))
			if !(pTab != 0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemset(tls, pTab, 0, uint32(48))
				(*TSessionTable)(unsafe.Pointer(pTab)).FzName = pTab + 1*48
				libc.Xmemcpy(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zName, uint32(nName+int32(1)))
				ppTab = pSession + 64
				for {
					if !(*(*uintptr)(unsafe.Pointer(ppTab)) != 0) {
						break
					}
					goto _2
				_2:
					;
					ppTab = *(*uintptr)(unsafe.Pointer(ppTab))
				}
				*(*uintptr)(unsafe.Pointer(ppTab)) = pTab
			}
		}
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return rc
}

// C documentation
//
//	/*
//	** Append the value passed as the second argument to the buffer passed
//	** as the first.
//	**
//	** This function is a no-op if *pRc is non-zero when it is called.
//	** Otherwise, if an error occurs, *pRc is set to an SQLite error code
//	** before returning.
//	*/
func _sessionAppendValue(tls *libc.TLS, p uintptr, pVal uintptr, pRc uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p1 uintptr
	var _ /* nByte at bp+8 */ Tsqlite3_int64
	var _ /* rc at bp+0 */ int32
	_ = p1
	*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(pRc))
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)) = 0
		*(*int32)(unsafe.Pointer(bp)) = _sessionSerializeValue(tls, uintptr(0), pVal, bp+8)
		_sessionBufferGrow(tls, p, *(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)), bp)
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = _sessionSerializeValue(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), pVal, uintptr(0))
			p1 = p + 4
			*(*int32)(unsafe.Pointer(p1)) = int32(int64(*(*int32)(unsafe.Pointer(p1))) + *(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)))
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp))
		}
	}
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append a single byte to the buffer.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendByte(tls *libc.TLS, p uintptr, v Tu8, pRc uintptr) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if 0 == _sessionBufferGrow(tls, p, int64(1), pRc) {
		v2 = p + 4
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2))++
		*(*Tu8)(unsafe.Pointer((*TSessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr(v1))) = v
	}
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append a single varint to the buffer.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendVarint(tls *libc.TLS, p uintptr, v int32, pRc uintptr) {
	if 0 == _sessionBufferGrow(tls, p, int64(9), pRc) {
		*(*int32)(unsafe.Pointer(p + 4)) += _sessionVarintPut(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), v)
	}
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append a blob of data to the buffer.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendBlob(tls *libc.TLS, p uintptr, aBlob uintptr, nBlob int32, pRc uintptr) {
	if nBlob > 0 && 0 == _sessionBufferGrow(tls, p, int64(int64(nBlob)), pRc) {
		libc.Xmemcpy(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), aBlob, uint32(uint32(nBlob)))
		*(*int32)(unsafe.Pointer(p + 4)) += nBlob
	}
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append the string representation of integer iVal
//	** to the buffer. No nul-terminator is written.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendInteger(tls *libc.TLS, p uintptr, iVal int32, pRc uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* aBuf at bp+0 */ [24]int8
	Xsqlite3_snprintf(tls, int32(libc.Uint32FromInt64(24)-libc.Uint32FromInt32(1)), bp, __ccgo_ts+6511, libc.VaList(bp+32, iVal))
	_sessionAppendStr(tls, p, bp, pRc)
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append the string zStr enclosed in quotes (") and
//	** with any embedded quote characters escaped to the buffer. No
//	** nul-terminator byte is written.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendIdent(tls *libc.TLS, p uintptr, zStr uintptr, pRc uintptr) {
	var nStr int32
	var zIn, zOut, v1, v2, v3, v4, v5 uintptr
	_, _, _, _, _, _, _, _ = nStr, zIn, zOut, v1, v2, v3, v4, v5
	nStr = _sqlite3Strlen30(tls, zStr)*int32(2) + int32(2) + int32(2)
	if 0 == _sessionBufferGrow(tls, p, int64(int64(nStr)), pRc) {
		zOut = (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf)
		zIn = zStr
		v1 = zOut
		zOut++
		*(*int8)(unsafe.Pointer(v1)) = int8('"')
		for *(*int8)(unsafe.Pointer(zIn)) != 0 {
			if int32(*(*int8)(unsafe.Pointer(zIn))) == int32('"') {
				v2 = zOut
				zOut++
				*(*int8)(unsafe.Pointer(v2)) = int8('"')
			}
			v3 = zOut
			zOut++
			v4 = zIn
			zIn++
			*(*int8)(unsafe.Pointer(v3)) = *(*int8)(unsafe.Pointer(v4))
		}
		v5 = zOut
		zOut++
		*(*int8)(unsafe.Pointer(v5)) = int8('"')
		(*TSessionBuffer)(unsafe.Pointer(p)).FnBuf = int32(zOut) - int32((*TSessionBuffer)(unsafe.Pointer(p)).FaBuf)
		*(*Tu8)(unsafe.Pointer((*TSessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf))) = uint8(0x00)
	}
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwse, it appends the serialized version of the value stored
//	** in column iCol of the row that SQL statement pStmt currently points
//	** to to the buffer.
//	*/
func _sessionAppendCol(tls *libc.TLS, p uintptr, pStmt uintptr, iCol int32, pRc uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eType, nByte int32
	var z uintptr
	var _ /* aBuf at bp+8 */ [8]Tu8
	var _ /* i at bp+0 */ Tsqlite3_int64
	var _ /* r at bp+16 */ float64
	_, _, _ = eType, nByte, z
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		eType = Xsqlite3_column_type(tls, pStmt, iCol)
		_sessionAppendByte(tls, p, uint8(uint8(eType)), pRc)
		if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
			if eType == int32(SQLITE_INTEGER) {
				*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = Xsqlite3_column_int64(tls, pStmt, iCol)
			} else {
				*(*float64)(unsafe.Pointer(bp + 16)) = Xsqlite3_column_double(tls, pStmt, iCol)
				libc.Xmemcpy(tls, bp, bp+16, uint32(8))
			}
			_sessionPutI64(tls, bp+8, *(*Tsqlite3_int64)(unsafe.Pointer(bp)))
			_sessionAppendBlob(tls, p, bp+8, int32(8), pRc)
		}
		if eType == int32(SQLITE_BLOB) || eType == int32(SQLITE_TEXT) {
			if eType == int32(SQLITE_BLOB) {
				z = Xsqlite3_column_blob(tls, pStmt, iCol)
			} else {
				z = Xsqlite3_column_text(tls, pStmt, iCol)
			}
			nByte = Xsqlite3_column_bytes(tls, pStmt, iCol)
			if z != 0 || eType == int32(SQLITE_BLOB) && nByte == 0 {
				_sessionAppendVarint(tls, p, nByte, pRc)
				_sessionAppendBlob(tls, p, z, nByte, pRc)
			} else {
				*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
			}
		}
	}
}

// C documentation
//
//	/*
//	**
//	** This function appends an update change to the buffer (see the comments
//	** under "CHANGESET FORMAT" at the top of the file). An update change
//	** consists of:
//	**
//	**   1 byte:  SQLITE_UPDATE (0x17)
//	**   n bytes: old.* record (see RECORD FORMAT)
//	**   m bytes: new.* record (see RECORD FORMAT)
//	**
//	** The SessionChange object passed as the third argument contains the
//	** values that were stored in the row when the session began (the old.*
//	** values). The statement handle passed as the second argument points
//	** at the current version of the row (the new.* values).
//	**
//	** If all of the old.* values are equal to their corresponding new.* value
//	** (i.e. nothing has changed), then no data at all is appended to the buffer.
//	**
//	** Otherwise, the old.* record contains all primary key values and the
//	** original values of any fields that have been modified. The new.* record
//	** contains the new values of only those fields that have been modified.
//	*/
func _sessionAppendUpdate(tls *libc.TLS, pBuf uintptr, bPatchset int32, pStmt uintptr, p uintptr, abPK uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bChanged, bNoop, eType, i, nAdvance, nHdr, nRewind int32
	var pCsr uintptr
	var _ /* buf2 at bp+4 */ TSessionBuffer
	var _ /* dVal at bp+24 */ float64
	var _ /* iVal at bp+16 */ Tsqlite3_int64
	var _ /* n at bp+32 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _ = bChanged, bNoop, eType, i, nAdvance, nHdr, nRewind, pCsr
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*TSessionBuffer)(unsafe.Pointer(bp + 4)) = TSessionBuffer{} /* Buffer to accumulate new.* record in */
	bNoop = int32(1)                                              /* Set to zero if any values are modified */
	nRewind = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf       /* Used to iterate through columns */
	pCsr = (*TSessionChange)(unsafe.Pointer(p)).FaRecord          /* Used to iterate through old.* values */
	_sessionAppendByte(tls, pBuf, uint8(SQLITE_UPDATE), bp)
	_sessionAppendByte(tls, pBuf, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp)
	i = 0
	for {
		if !(i < Xsqlite3_column_count(tls, pStmt)) {
			break
		}
		bChanged = 0
		eType = int32(*(*Tu8)(unsafe.Pointer(pCsr)))
		switch eType {
		case int32(SQLITE_NULL):
			nAdvance = int32(1)
			if Xsqlite3_column_type(tls, pStmt, i) != int32(SQLITE_NULL) {
				bChanged = int32(1)
			}
		case int32(SQLITE_FLOAT):
			fallthrough
		case int32(SQLITE_INTEGER):
			nAdvance = int32(9)
			if eType == Xsqlite3_column_type(tls, pStmt, i) {
				*(*Tsqlite3_int64)(unsafe.Pointer(bp + 16)) = _sessionGetI64(tls, pCsr+1)
				if eType == int32(SQLITE_INTEGER) {
					if *(*Tsqlite3_int64)(unsafe.Pointer(bp + 16)) == Xsqlite3_column_int64(tls, pStmt, i) {
						break
					}
				} else {
					libc.Xmemcpy(tls, bp+24, bp+16, uint32(8))
					if *(*float64)(unsafe.Pointer(bp + 24)) == Xsqlite3_column_double(tls, pStmt, i) {
						break
					}
				}
			}
			bChanged = int32(1)
		default:
			nHdr = int32(1) + _sessionVarintGet(tls, pCsr+1, bp+32)
			nAdvance = nHdr + *(*int32)(unsafe.Pointer(bp + 32))
			if eType == Xsqlite3_column_type(tls, pStmt, i) && *(*int32)(unsafe.Pointer(bp + 32)) == Xsqlite3_column_bytes(tls, pStmt, i) && (*(*int32)(unsafe.Pointer(bp + 32)) == 0 || 0 == libc.Xmemcmp(tls, pCsr+uintptr(nHdr), Xsqlite3_column_blob(tls, pStmt, i), uint32(*(*int32)(unsafe.Pointer(bp + 32))))) {
				break
			}
			bChanged = int32(1)
		}
		/* If at least one field has been modified, this is not a no-op. */
		if bChanged != 0 {
			bNoop = 0
		}
		/* Add a field to the old.* record. This is omitted if this module is
		 ** currently generating a patchset. */
		if bPatchset == 0 {
			if bChanged != 0 || *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				_sessionAppendBlob(tls, pBuf, pCsr, nAdvance, bp)
			} else {
				_sessionAppendByte(tls, pBuf, uint8(0), bp)
			}
		}
		/* Add a field to the new.* record. Or the only record if currently
		 ** generating a patchset.  */
		if bChanged != 0 || bPatchset != 0 && *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
			_sessionAppendCol(tls, bp+4, pStmt, i, bp)
		} else {
			_sessionAppendByte(tls, bp+4, uint8(0), bp)
		}
		pCsr += uintptr(nAdvance)
		goto _1
	_1:
		;
		i++
	}
	if bNoop != 0 {
		(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = nRewind
	} else {
		_sessionAppendBlob(tls, pBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf, bp)
	}
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Append a DELETE change to the buffer passed as the first argument. Use
//	** the changeset format if argument bPatchset is zero, or the patchset
//	** format otherwise.
//	*/
func _sessionAppendDelete(tls *libc.TLS, pBuf uintptr, bPatchset int32, p uintptr, nCol int32, abPK uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, pStart, v2 uintptr
	var eType, i int32
	var _ /* n at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _ = a, eType, i, pStart, v2
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	_sessionAppendByte(tls, pBuf, uint8(SQLITE_DELETE), bp)
	_sessionAppendByte(tls, pBuf, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp)
	if bPatchset == 0 {
		_sessionAppendBlob(tls, pBuf, (*TSessionChange)(unsafe.Pointer(p)).FaRecord, (*TSessionChange)(unsafe.Pointer(p)).FnRecord, bp)
	} else {
		a = (*TSessionChange)(unsafe.Pointer(p)).FaRecord
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			pStart = a
			v2 = a
			a++
			eType = int32(*(*Tu8)(unsafe.Pointer(v2)))
			switch eType {
			case 0:
				fallthrough
			case int32(SQLITE_NULL):
			case int32(SQLITE_FLOAT):
				fallthrough
			case int32(SQLITE_INTEGER):
				a += uintptr(8)
			default:
				a += uintptr(_sessionVarintGet(tls, a, bp+4))
				a += uintptr(*(*int32)(unsafe.Pointer(bp + 4)))
				break
			}
			if *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				_sessionAppendBlob(tls, pBuf, pStart, int32(int32(a))-int32(int32(pStart)), bp)
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Formulate and prepare a SELECT statement to retrieve a row from table
//	** zTab in database zDb based on its primary key. i.e.
//	**
//	**   SELECT *, <noop-test> FROM zDb.zTab WHERE (pk1, pk2,...) IS (?1, ?2,...)
//	**
//	** where <noop-test> is:
//	**
//	**   1 AND (?A OR ?1 IS <column>) AND ...
//	**
//	** for each non-pk <column>.
//	*/
func _sessionSelectStmt(tls *libc.TLS, db uintptr, bIgnoreNoop int32, zDb uintptr, zTab uintptr, bRowid int32, nCol int32, azCol uintptr, abPK uintptr, ppStmt uintptr) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var i, nSql int32
	var zCols, zSep, zSql, v1, v3 uintptr
	var _ /* nooptest at bp+4 */ TSessionBuffer
	var _ /* pkfield at bp+16 */ TSessionBuffer
	var _ /* pkvar at bp+28 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _ = i, nSql, zCols, zSep, zSql, v1, v3
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	zSql = uintptr(0)
	zSep = __ccgo_ts + 1672
	if bRowid != 0 {
		v1 = __ccgo_ts + 35014
	} else {
		v1 = __ccgo_ts + 7963
	}
	zCols = v1
	nSql = -int32(1)
	*(*TSessionBuffer)(unsafe.Pointer(bp + 4)) = TSessionBuffer{}
	*(*TSessionBuffer)(unsafe.Pointer(bp + 16)) = TSessionBuffer{}
	*(*TSessionBuffer)(unsafe.Pointer(bp + 28)) = TSessionBuffer{}
	_sessionAppendStr(tls, bp+4, __ccgo_ts+35207, bp)
	if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+13016, zTab) {
		_sessionAppendStr(tls, bp+4, __ccgo_ts+35211, bp)
		_sessionAppendStr(tls, bp+16, __ccgo_ts+35235, bp)
		_sessionAppendStr(tls, bp+28, __ccgo_ts+35244, bp)
		zCols = __ccgo_ts + 35289
	} else {
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			if *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				_sessionAppendStr(tls, bp+16, zSep, bp)
				_sessionAppendStr(tls, bp+28, zSep, bp)
				zSep = __ccgo_ts + 16397
				_sessionAppendIdent(tls, bp+16, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4)), bp)
				_sessionAppendPrintf(tls, bp+28, bp, __ccgo_ts+35303, libc.VaList(bp+48, i+int32(1)))
			} else {
				_sessionAppendPrintf(tls, bp+4, bp, __ccgo_ts+35307, libc.VaList(bp+48, i+int32(1)+nCol, i+int32(1), zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*4))))
			}
			goto _2
		_2:
			;
			i++
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		if bIgnoreNoop != 0 {
			v3 = (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf
		} else {
			v3 = __ccgo_ts + 1672
		}
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+35334, libc.VaList(bp+48, zCols, v3, zDb, zTab, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 28))).FaBuf))
		if zSql == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v2(tls, db, zSql, nSql, ppStmt, uintptr(0))
	}
	Xsqlite3_free(tls, zSql)
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf)
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf)
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 28))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Bind the PRIMARY KEY values from the change passed in argument pChange
//	** to the SELECT statement passed as the first argument. The SELECT statement
//	** is as prepared by function sessionSelectStmt().
//	**
//	** Return SQLITE_OK if all PK values are successfully bound, or an SQLite
//	** error code (e.g. SQLITE_NOMEM) otherwise.
//	*/
func _sessionSelectBind(tls *libc.TLS, pSelect uintptr, nCol int32, abPK uintptr, pChange uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, v2 uintptr
	var eType, i, rc int32
	var iVal Ti64
	var _ /* iVal at bp+8 */ Ti64
	var _ /* n at bp+16 */ int32
	var _ /* n at bp+20 */ int32
	var _ /* rVal at bp+0 */ float64
	_, _, _, _, _, _ = a, eType, i, iVal, rc, v2
	rc = SQLITE_OK
	a = (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord
	i = 0
	for {
		if !(i < nCol && rc == SQLITE_OK) {
			break
		}
		v2 = a
		a++
		eType = int32(*(*Tu8)(unsafe.Pointer(v2)))
		switch eType {
		case 0:
			fallthrough
		case int32(SQLITE_NULL):
		case int32(SQLITE_INTEGER):
			if *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				iVal = _sessionGetI64(tls, a)
				rc = Xsqlite3_bind_int64(tls, pSelect, i+int32(1), iVal)
			}
			a += uintptr(8)
		case int32(SQLITE_FLOAT):
			if *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				*(*Ti64)(unsafe.Pointer(bp + 8)) = _sessionGetI64(tls, a)
				libc.Xmemcpy(tls, bp, bp+8, uint32(8))
				rc = Xsqlite3_bind_double(tls, pSelect, i+int32(1), *(*float64)(unsafe.Pointer(bp)))
			}
			a += uintptr(8)
		case int32(SQLITE_TEXT):
			a += uintptr(_sessionVarintGet(tls, a, bp+16))
			if *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				rc = Xsqlite3_bind_text(tls, pSelect, i+int32(1), a, *(*int32)(unsafe.Pointer(bp + 16)), uintptr(-libc.Int32FromInt32(1)))
			}
			a += uintptr(*(*int32)(unsafe.Pointer(bp + 16)))
		default:
			a += uintptr(_sessionVarintGet(tls, a, bp+20))
			if *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				rc = Xsqlite3_bind_blob(tls, pSelect, i+int32(1), a, *(*int32)(unsafe.Pointer(bp + 20)), uintptr(-libc.Int32FromInt32(1)))
			}
			a += uintptr(*(*int32)(unsafe.Pointer(bp + 20)))
			break
		}
		goto _1
	_1:
		;
		i++
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is set to other than SQLITE_OK when it
//	** is called. Otherwise, append a serialized table header (part of the binary
//	** changeset format) to buffer *pBuf. If an error occurs, set *pRc to an
//	** SQLite error code before returning.
//	*/
func _sessionAppendTableHdr(tls *libc.TLS, pBuf uintptr, bPatchset int32, pTab uintptr, pRc uintptr) {
	var v1 int32
	_ = v1
	/* Write a table header */
	if bPatchset != 0 {
		v1 = int32('P')
	} else {
		v1 = int32('T')
	}
	_sessionAppendByte(tls, pBuf, uint8(v1), pRc)
	_sessionAppendVarint(tls, pBuf, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, pRc)
	_sessionAppendBlob(tls, pBuf, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, pRc)
	_sessionAppendBlob(tls, pBuf, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, int32(libc.Xstrlen(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName))+int32(1), pRc)
}

// C documentation
//
//	/*
//	** Generate either a changeset (if argument bPatchset is zero) or a patchset
//	** (if it is non-zero) based on the current contents of the session object
//	** passed as the first argument.
//	**
//	** If no error occurs, SQLITE_OK is returned and the new changeset/patchset
//	** stored in output variables *pnChangeset and *ppChangeset. Or, if an error
//	** occurs, an SQLite error code is returned and both output variables set
//	** to 0.
//	*/
func _sessionGenerateChangeset(tls *libc.TLS, pSession uintptr, bPatchset int32, xOutput uintptr, pOut uintptr, pnChangeset uintptr, ppChangeset uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pTab, zName uintptr
	var i, iCol, nNoop, nOldCol, nRewind int32
	var _ /* buf at bp+0 */ TSessionBuffer
	var _ /* pSel at bp+16 */ uintptr
	var _ /* rc at bp+12 */ int32
	_, _, _, _, _, _, _, _, _ = db, i, iCol, nNoop, nOldCol, nRewind, p, pTab, zName
	db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb    /* Used to iterate through attached tables */
	*(*TSessionBuffer)(unsafe.Pointer(bp)) = TSessionBuffer{} /* Return code */
	/* Zero the output variables in case an error occurs. If this session
	 ** object is already in the error state (sqlite3_session.rc != SQLITE_OK),
	 ** this call will be a no-op.  */
	if xOutput == uintptr(0) {
		*(*int32)(unsafe.Pointer(pnChangeset)) = 0
		*(*uintptr)(unsafe.Pointer(ppChangeset)) = uintptr(0)
	}
	if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
		return (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
	}
	*(*int32)(unsafe.Pointer(bp + 12)) = Xsqlite3_exec(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, __ccgo_ts+35376, uintptr(0), uintptr(0), uintptr(0))
	if *(*int32)(unsafe.Pointer(bp + 12)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp + 12))
	}
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	pTab = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
	for {
		if !(*(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK && pTab != 0) {
			break
		}
		if (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry != 0 {
			zName = (*TSessionTable)(unsafe.Pointer(pTab)).FzName    /* Used to iterate through hash buckets */
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)        /* SELECT statement to query table pTab */
			nRewind = (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf /* Size of buffer after writing tbl header */
			nOldCol = (*TSessionTable)(unsafe.Pointer(pTab)).FnCol
			/* Check the table schema is still Ok. */
			*(*int32)(unsafe.Pointer(bp + 12)) = _sessionReinitTable(tls, pSession, pTab)
			if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK && (*TSessionTable)(unsafe.Pointer(pTab)).FnCol != nOldCol {
				*(*int32)(unsafe.Pointer(bp + 12)) = _sessionUpdateChanges(tls, pSession, pTab)
			}
			/* Write a table header */
			_sessionAppendTableHdr(tls, bp, bPatchset, pTab, bp+12)
			/* Build and compile a statement to execute: */
			if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp + 12)) = _sessionSelectStmt(tls, db, 0, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, zName, (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, bp+16)
			}
			nNoop = (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf
			i = 0
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange && *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK) {
					break
				} /* Used to iterate through changes */
				p = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*4))
				for {
					if !(*(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK && p != 0) {
						break
					}
					*(*int32)(unsafe.Pointer(bp + 12)) = _sessionSelectBind(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, p)
					if *(*int32)(unsafe.Pointer(bp + 12)) != SQLITE_OK {
						goto _3
					}
					if Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) == int32(SQLITE_ROW) {
						if int32((*TSessionChange)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INSERT) {
							_sessionAppendByte(tls, bp, uint8(SQLITE_INSERT), bp+12)
							_sessionAppendByte(tls, bp, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp+12)
							iCol = 0
							for {
								if !(iCol < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
									break
								}
								_sessionAppendCol(tls, bp, *(*uintptr)(unsafe.Pointer(bp + 16)), iCol, bp+12)
								goto _4
							_4:
								;
								iCol++
							}
						} else {
							*(*int32)(unsafe.Pointer(bp + 12)) = _sessionAppendUpdate(tls, bp, bPatchset, *(*uintptr)(unsafe.Pointer(bp + 16)), p, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
						}
					} else {
						if int32((*TSessionChange)(unsafe.Pointer(p)).Fop) != int32(SQLITE_INSERT) {
							*(*int32)(unsafe.Pointer(bp + 12)) = _sessionAppendDelete(tls, bp, bPatchset, p, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
						}
					}
					if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK {
						*(*int32)(unsafe.Pointer(bp + 12)) = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
					}
					/* If the buffer is now larger than sessions_strm_chunk_size, pass
					 ** its contents to the xOutput() callback. */
					if xOutput != 0 && *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK && (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf > nNoop && (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf > _sessions_strm_chunk_size {
						*(*int32)(unsafe.Pointer(bp + 12)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf)
						nNoop = -int32(1)
						(*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf = 0
					}
					goto _3
				_3:
					;
					p = (*TSessionChange)(unsafe.Pointer(p)).FpNext
				}
				goto _2
			_2:
				;
				i++
			}
			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
			if (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf == nNoop {
				(*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf = nRewind
			}
		}
		goto _1
	_1:
		;
		pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
	}
	if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK {
		if xOutput == uintptr(0) {
			*(*int32)(unsafe.Pointer(pnChangeset)) = (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf
			*(*uintptr)(unsafe.Pointer(ppChangeset)) = (*(*TSessionBuffer)(unsafe.Pointer(bp))).FaBuf
			(*(*TSessionBuffer)(unsafe.Pointer(bp))).FaBuf = uintptr(0)
		} else {
			if (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf > 0 {
				*(*int32)(unsafe.Pointer(bp + 12)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp))).FnBuf)
			}
		}
	}
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp))).FaBuf)
	Xsqlite3_exec(tls, db, __ccgo_ts+35396, uintptr(0), uintptr(0), uintptr(0))
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	return *(*int32)(unsafe.Pointer(bp + 12))
}

// C documentation
//
//	/*
//	** Obtain a changeset object containing all changes recorded by the
//	** session object passed as the first argument.
//	**
//	** It is the responsibility of the caller to eventually free the buffer
//	** using sqlite3_free().
//	*/
func Xsqlite3session_changeset(tls *libc.TLS, pSession uintptr, pnChangeset uintptr, ppChangeset uintptr) (r int32) {
	var rc int32
	_ = rc
	if pnChangeset == uintptr(0) || ppChangeset == uintptr(0) {
		return int32(SQLITE_MISUSE)
	}
	rc = _sessionGenerateChangeset(tls, pSession, 0, uintptr(0), uintptr(0), pnChangeset, ppChangeset)
	return rc
}

// C documentation
//
//	/*
//	** Streaming version of sqlite3session_changeset().
//	*/
func Xsqlite3session_changeset_strm(tls *libc.TLS, pSession uintptr, xOutput uintptr, pOut uintptr) (r int32) {
	if xOutput == uintptr(0) {
		return int32(SQLITE_MISUSE)
	}
	return _sessionGenerateChangeset(tls, pSession, 0, xOutput, pOut, uintptr(0), uintptr(0))
}

// C documentation
//
//	/*
//	** Streaming version of sqlite3session_patchset().
//	*/
func Xsqlite3session_patchset_strm(tls *libc.TLS, pSession uintptr, xOutput uintptr, pOut uintptr) (r int32) {
	if xOutput == uintptr(0) {
		return int32(SQLITE_MISUSE)
	}
	return _sessionGenerateChangeset(tls, pSession, int32(1), xOutput, pOut, uintptr(0), uintptr(0))
}

// C documentation
//
//	/*
//	** Obtain a patchset object containing all changes recorded by the
//	** session object passed as the first argument.
//	**
//	** It is the responsibility of the caller to eventually free the buffer
//	** using sqlite3_free().
//	*/
func Xsqlite3session_patchset(tls *libc.TLS, pSession uintptr, pnPatchset uintptr, ppPatchset uintptr) (r int32) {
	if pnPatchset == uintptr(0) || ppPatchset == uintptr(0) {
		return int32(SQLITE_MISUSE)
	}
	return _sessionGenerateChangeset(tls, pSession, int32(1), uintptr(0), uintptr(0), pnPatchset, ppPatchset)
}

// C documentation
//
//	/*
//	** Enable or disable the session object passed as the first argument.
//	*/
func Xsqlite3session_enable(tls *libc.TLS, pSession uintptr, bEnable int32) (r int32) {
	var ret int32
	_ = ret
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if bEnable >= 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnable = bEnable
	}
	ret = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnable
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return ret
}

// C documentation
//
//	/*
//	** Enable or disable the session object passed as the first argument.
//	*/
func Xsqlite3session_indirect(tls *libc.TLS, pSession uintptr, bIndirect int32) (r int32) {
	var ret int32
	_ = ret
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if bIndirect >= 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect = bIndirect
	}
	ret = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return ret
}

// C documentation
//
//	/*
//	** Return true if there have been no changes to monitored tables recorded
//	** by the session object passed as the only argument.
//	*/
func Xsqlite3session_isempty(tls *libc.TLS, pSession uintptr) (r int32) {
	var pTab uintptr
	var ret int32
	_, _ = pTab, ret
	ret = 0
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	pTab = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
	for {
		if !(pTab != 0 && ret == 0) {
			break
		}
		ret = libc.BoolInt32((*TSessionTable)(unsafe.Pointer(pTab)).FnEntry > 0)
		goto _1
	_1:
		;
		pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return libc.BoolInt32(ret == 0)
}

// C documentation
//
//	/*
//	** Return the amount of heap memory in use.
//	*/
func Xsqlite3session_memory_used(tls *libc.TLS, pSession uintptr) (r Tsqlite3_int64) {
	return (*Tsqlite3_session)(unsafe.Pointer(pSession)).FnMalloc
}

// C documentation
//
//	/*
//	** Configure the session object passed as the first argument.
//	*/
func Xsqlite3session_object_config(tls *libc.TLS, pSession uintptr, op int32, pArg uintptr) (r int32) {
	var iArg, iArg1, rc int32
	_, _, _ = iArg, iArg1, rc
	rc = SQLITE_OK
	switch op {
	case int32(SQLITE_SESSION_OBJCONFIG_SIZE):
		iArg = *(*int32)(unsafe.Pointer(pArg))
		if iArg >= 0 {
			if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable != 0 {
				rc = int32(SQLITE_MISUSE)
			} else {
				(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize = libc.BoolInt32(iArg != 0)
			}
		}
		*(*int32)(unsafe.Pointer(pArg)) = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize
	case int32(SQLITE_SESSION_OBJCONFIG_ROWID):
		iArg1 = *(*int32)(unsafe.Pointer(pArg))
		if iArg1 >= 0 {
			if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable != 0 {
				rc = int32(SQLITE_MISUSE)
			} else {
				(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK = libc.BoolInt32(iArg1 != 0)
			}
		}
		*(*int32)(unsafe.Pointer(pArg)) = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK
	default:
		rc = int32(SQLITE_MISUSE)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the maximum size of sqlite3session_changeset() output.
//	*/
func Xsqlite3session_changeset_size(tls *libc.TLS, pSession uintptr) (r Tsqlite3_int64) {
	return (*Tsqlite3_session)(unsafe.Pointer(pSession)).FnMaxChangesetSize
}

// C documentation
//
//	/*
//	** Do the work for either sqlite3changeset_start() or start_strm().
//	*/
func _sessionChangesetStart(tls *libc.TLS, pp uintptr, xInput uintptr, pIn uintptr, nChangeset int32, pChangeset uintptr, bInvert int32, bSkipEmpty int32) (r int32) {
	var nByte, v1 int32
	var pRet uintptr
	_, _, _ = nByte, pRet, v1 /* Number of bytes to allocate for iterator */
	/* Zero the output variable in case an error occurs. */
	*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	/* Allocate and initialize the iterator structure. */
	nByte = int32(100)
	pRet = Xsqlite3_malloc(tls, nByte)
	if !(pRet != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pRet, 0, uint32(100))
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FaData = pChangeset
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FnData = nChangeset
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FxInput = xInput
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FpIn = pIn
	if xInput != 0 {
		v1 = 0
	} else {
		v1 = int32(1)
	}
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FbEof = v1
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbInvert = bInvert
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbSkipEmpty = bSkipEmpty
	/* Populate the output variable and return success. */
	*(*uintptr)(unsafe.Pointer(pp)) = pRet
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Create an iterator used to iterate through the contents of a changeset.
//	*/
func Xsqlite3changeset_start(tls *libc.TLS, pp uintptr, nChangeset int32, pChangeset uintptr) (r int32) {
	return _sessionChangesetStart(tls, pp, uintptr(0), uintptr(0), nChangeset, pChangeset, 0, 0)
}

func Xsqlite3changeset_start_v2(tls *libc.TLS, pp uintptr, nChangeset int32, pChangeset uintptr, flags int32) (r int32) {
	var bInvert int32
	_ = bInvert
	bInvert = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETSTART_INVERT) != 0))
	return _sessionChangesetStart(tls, pp, uintptr(0), uintptr(0), nChangeset, pChangeset, bInvert, 0)
}

// C documentation
//
//	/*
//	** Streaming version of sqlite3changeset_start().
//	*/
func Xsqlite3changeset_start_strm(tls *libc.TLS, pp uintptr, xInput uintptr, pIn uintptr) (r int32) {
	return _sessionChangesetStart(tls, pp, xInput, pIn, 0, uintptr(0), 0, 0)
}

func Xsqlite3changeset_start_v2_strm(tls *libc.TLS, pp uintptr, xInput uintptr, pIn uintptr, flags int32) (r int32) {
	var bInvert int32
	_ = bInvert
	bInvert = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETSTART_INVERT) != 0))
	return _sessionChangesetStart(tls, pp, xInput, pIn, 0, uintptr(0), bInvert, 0)
}

// C documentation
//
//	/*
//	** If the SessionInput object passed as the only argument is a streaming
//	** object and the buffer is full, discard some data to free up space.
//	*/
func _sessionDiscardData(tls *libc.TLS, pIn uintptr) {
	var nMove int32
	_ = nMove
	if (*TSessionInput)(unsafe.Pointer(pIn)).FxInput != 0 && (*TSessionInput)(unsafe.Pointer(pIn)).FiNext >= _sessions_strm_chunk_size {
		nMove = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf - (*TSessionInput)(unsafe.Pointer(pIn)).FiNext
		if nMove > 0 {
			libc.Xmemmove(tls, (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf, (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext), uint32(uint32(nMove)))
		}
		(*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf -= (*TSessionInput)(unsafe.Pointer(pIn)).FiNext
		(*TSessionInput)(unsafe.Pointer(pIn)).FiNext = 0
		(*TSessionInput)(unsafe.Pointer(pIn)).FnData = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf
	}
}

// C documentation
//
//	/*
//	** Ensure that there are at least nByte bytes available in the buffer. Or,
//	** if there are not nByte bytes remaining in the input, that all available
//	** data is in the buffer.
//	**
//	** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise.
//	*/
func _sessionInputBuffer(tls *libc.TLS, pIn uintptr, nByte int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* nNew at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	if (*TSessionInput)(unsafe.Pointer(pIn)).FxInput != 0 {
		for !((*TSessionInput)(unsafe.Pointer(pIn)).FbEof != 0) && (*TSessionInput)(unsafe.Pointer(pIn)).FiNext+nByte >= (*TSessionInput)(unsafe.Pointer(pIn)).FnData && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 4)) = _sessions_strm_chunk_size
			if (*TSessionInput)(unsafe.Pointer(pIn)).FbNoDiscard == 0 {
				_sessionDiscardData(tls, pIn)
			}
			if SQLITE_OK == _sessionBufferGrow(tls, pIn+20, int64(*(*int32)(unsafe.Pointer(bp + 4))), bp) {
				*(*int32)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSessionInput)(unsafe.Pointer(pIn)).FxInput})))(tls, (*TSessionInput)(unsafe.Pointer(pIn)).FpIn, (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf), bp+4)
				if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
					(*TSessionInput)(unsafe.Pointer(pIn)).FbEof = int32(1)
				} else {
					(*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf += *(*int32)(unsafe.Pointer(bp + 4))
				}
			}
			(*TSessionInput)(unsafe.Pointer(pIn)).FaData = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf
			(*TSessionInput)(unsafe.Pointer(pIn)).FnData = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** When this function is called, *ppRec points to the start of a record
//	** that contains nCol values. This function advances the pointer *ppRec
//	** until it points to the byte immediately following that record.
//	*/
func _sessionSkipRecord(tls *libc.TLS, ppRec uintptr, nCol int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aRec, v2 uintptr
	var eType, i int32
	var _ /* nByte at bp+0 */ int32
	_, _, _, _ = aRec, eType, i, v2
	aRec = *(*uintptr)(unsafe.Pointer(ppRec))
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		v2 = aRec
		aRec++
		eType = int32(*(*Tu8)(unsafe.Pointer(v2)))
		if eType == int32(SQLITE_TEXT) || eType == int32(SQLITE_BLOB) {
			aRec += uintptr(_sessionVarintGet(tls, aRec, bp))
			aRec += uintptr(*(*int32)(unsafe.Pointer(bp)))
		} else {
			if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
				aRec += uintptr(8)
			}
		}
		goto _1
	_1:
		;
		i++
	}
	*(*uintptr)(unsafe.Pointer(ppRec)) = aRec
}

// C documentation
//
//	/*
//	** This function sets the value of the sqlite3_value object passed as the
//	** first argument to a copy of the string or blob held in the aData[]
//	** buffer. SQLITE_OK is returned if successful, or SQLITE_NOMEM if an OOM
//	** error occurs.
//	*/
func _sessionValueSetStr(tls *libc.TLS, pVal uintptr, aData uintptr, nData int32, enc Tu8) (r int32) {
	var aCopy uintptr
	_ = aCopy
	/* In theory this code could just pass SQLITE_TRANSIENT as the final
	 ** argument to sqlite3ValueSetStr() and have the copy created
	 ** automatically. But doing so makes it difficult to detect any OOM
	 ** error. Hence the code to create the copy externally. */
	aCopy = Xsqlite3_malloc64(tls, uint64(int64(int64(nData))+int64(1)))
	if aCopy == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemcpy(tls, aCopy, aData, uint32(uint32(nData)))
	_sqlite3ValueSetStr(tls, pVal, nData, aCopy, enc, __ccgo_fp(Xsqlite3_free))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Deserialize a single record from a buffer in memory. See "RECORD FORMAT"
//	** for details.
//	**
//	** When this function is called, *paChange points to the start of the record
//	** to deserialize. Assuming no error occurs, *paChange is set to point to
//	** one byte after the end of the same record before this function returns.
//	** If the argument abPK is NULL, then the record contains nCol values. Or,
//	** if abPK is other than NULL, then the record contains only the PK fields
//	** (in other words, it is a patchset DELETE record).
//	**
//	** If successful, each element of the apOut[] array (allocated by the caller)
//	** is set to point to an sqlite3_value object containing the value read
//	** from the corresponding position in the record. If that value is not
//	** included in the record (i.e. because the record is part of an UPDATE change
//	** and the field was not modified), the corresponding element of apOut[] is
//	** set to NULL.
//	**
//	** It is the responsibility of the caller to free all sqlite_value structures
//	** using sqlite3_free().
//	**
//	** If an error occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
//	** The apOut[] array may have been partially populated in this case.
//	*/
func _sessionReadRecord(tls *libc.TLS, pIn uintptr, nCol int32, abPK uintptr, apOut uintptr, pbEmpty uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aVal, v3 uintptr
	var eType, i, rc, v2, v4 int32
	var enc Tu8
	var _ /* d at bp+16 */ float64
	var _ /* nByte at bp+0 */ int32
	var _ /* v at bp+8 */ Tsqlite3_int64
	_, _, _, _, _, _, _, _ = aVal, eType, enc, i, rc, v2, v3, v4 /* Used to iterate through columns */
	rc = SQLITE_OK
	if pbEmpty != 0 {
		*(*int32)(unsafe.Pointer(pbEmpty)) = int32(1)
	}
	i = 0
	for {
		if !(i < nCol && rc == SQLITE_OK) {
			break
		}
		eType = 0 /* Type of value (SQLITE_NULL, TEXT etc.) */
		if abPK != 0 && int32(*(*Tu8)(unsafe.Pointer(abPK + uintptr(i)))) == 0 {
			goto _1
		}
		rc = _sessionInputBuffer(tls, pIn, int32(9))
		if rc == SQLITE_OK {
			if (*TSessionInput)(unsafe.Pointer(pIn)).FiNext >= (*TSessionInput)(unsafe.Pointer(pIn)).FnData {
				rc = _sqlite3CorruptError(tls, int32(228355))
			} else {
				v3 = pIn + 8
				v2 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3))++
				eType = int32(*(*Tu8)(unsafe.Pointer((*TSessionInput)(unsafe.Pointer(pIn)).FaData + uintptr(v2))))
				if eType != 0 {
					if pbEmpty != 0 {
						*(*int32)(unsafe.Pointer(pbEmpty)) = 0
					}
					*(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*4)) = _sqlite3ValueNew(tls, uintptr(0))
					if !(*(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*4)) != 0) {
						rc = int32(SQLITE_NOMEM)
					}
				}
			}
		}
		if rc == SQLITE_OK {
			aVal = (*TSessionInput)(unsafe.Pointer(pIn)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext)
			if eType == int32(SQLITE_TEXT) || eType == int32(SQLITE_BLOB) {
				*(*int32)(unsafe.Pointer(pIn + 8)) += _sessionVarintGet(tls, aVal, bp)
				rc = _sessionInputBuffer(tls, pIn, *(*int32)(unsafe.Pointer(bp)))
				if rc == SQLITE_OK {
					if *(*int32)(unsafe.Pointer(bp)) < 0 || *(*int32)(unsafe.Pointer(bp)) > (*TSessionInput)(unsafe.Pointer(pIn)).FnData-(*TSessionInput)(unsafe.Pointer(pIn)).FiNext {
						rc = _sqlite3CorruptError(tls, int32(228375))
					} else {
						if eType == int32(SQLITE_TEXT) {
							v4 = int32(SQLITE_UTF8)
						} else {
							v4 = 0
						}
						enc = uint8(v4)
						rc = _sessionValueSetStr(tls, *(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*4)), (*TSessionInput)(unsafe.Pointer(pIn)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext), *(*int32)(unsafe.Pointer(bp)), enc)
						*(*int32)(unsafe.Pointer(pIn + 8)) += *(*int32)(unsafe.Pointer(bp))
					}
				}
			}
			if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
				if (*TSessionInput)(unsafe.Pointer(pIn)).FnData-(*TSessionInput)(unsafe.Pointer(pIn)).FiNext < int32(8) {
					rc = _sqlite3CorruptError(tls, int32(228385))
				} else {
					*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)) = _sessionGetI64(tls, aVal)
					if eType == int32(SQLITE_INTEGER) {
						_sqlite3VdbeMemSetInt64(tls, *(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*4)), *(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)))
					} else {
						libc.Xmemcpy(tls, bp+16, bp+8, uint32(8))
						_sqlite3VdbeMemSetDouble(tls, *(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*4)), *(*float64)(unsafe.Pointer(bp + 16)))
					}
					*(*int32)(unsafe.Pointer(pIn + 8)) += int32(8)
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return rc
}

// C documentation
//
//	/*
//	** The input pointer currently points to the second byte of a table-header.
//	** Specifically, to the following:
//	**
//	**   + number of columns in table (varint)
//	**   + array of PK flags (1 byte per column),
//	**   + table name (nul terminated).
//	**
//	** This function ensures that all of the above is present in the input
//	** buffer (i.e. that it can be accessed without any calls to xInput()).
//	** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code.
//	** The input pointer is not moved.
//	*/
func _sessionChangesetBufferTblhdr(tls *libc.TLS, pIn uintptr, pnByte uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nRead, rc int32
	var _ /* nCol at bp+0 */ int32
	_, _ = nRead, rc
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp)) = 0
	nRead = 0
	rc = _sessionInputBuffer(tls, pIn, int32(9))
	if rc == SQLITE_OK {
		nRead += _sessionVarintGet(tls, (*TSessionInput)(unsafe.Pointer(pIn)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext+nRead), bp)
		/* The hard upper limit for the number of columns in an SQLite
		 ** database table is, according to sqliteLimit.h, 32676. So
		 ** consider any table-header that purports to have more than 65536
		 ** columns to be corrupt. This is convenient because otherwise,
		 ** if the (nCol>65536) condition below were omitted, a sufficiently
		 ** large value for nCol may cause nRead to wrap around and become
		 ** negative. Leading to a crash. */
		if *(*int32)(unsafe.Pointer(bp)) < 0 || *(*int32)(unsafe.Pointer(bp)) > int32(65536) {
			rc = _sqlite3CorruptError(tls, int32(228433))
		} else {
			rc = _sessionInputBuffer(tls, pIn, nRead+*(*int32)(unsafe.Pointer(bp))+int32(100))
			nRead += *(*int32)(unsafe.Pointer(bp))
		}
	}
	for rc == SQLITE_OK {
		for (*TSessionInput)(unsafe.Pointer(pIn)).FiNext+nRead < (*TSessionInput)(unsafe.Pointer(pIn)).FnData && *(*Tu8)(unsafe.Pointer((*TSessionInput)(unsafe.Pointer(pIn)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext+nRead))) != 0 {
			nRead++
		}
		if (*TSessionInput)(unsafe.Pointer(pIn)).FiNext+nRead < (*TSessionInput)(unsafe.Pointer(pIn)).FnData {
			break
		}
		rc = _sessionInputBuffer(tls, pIn, nRead+int32(100))
	}
	*(*int32)(unsafe.Pointer(pnByte)) = nRead + int32(1)
	return rc
}

// C documentation
//
//	/*
//	** The input pointer currently points to the first byte of the first field
//	** of a record consisting of nCol columns. This function ensures the entire
//	** record is buffered. It does not move the input pointer.
//	**
//	** If successful, SQLITE_OK is returned and *pnByte is set to the size of
//	** the record in bytes. Otherwise, an SQLite error code is returned. The
//	** final value of *pnByte is undefined in this case.
//	*/
func _sessionChangesetBufferRecord(tls *libc.TLS, pIn uintptr, nCol int32, pnByte uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType, i, nByte, rc, v2 int32
	var _ /* n at bp+0 */ int32
	_, _, _, _, _ = eType, i, nByte, rc, v2
	rc = SQLITE_OK
	nByte = 0
	i = 0
	for {
		if !(rc == SQLITE_OK && i < nCol) {
			break
		}
		rc = _sessionInputBuffer(tls, pIn, nByte+int32(10))
		if rc == SQLITE_OK {
			v2 = nByte
			nByte++
			eType = int32(*(*Tu8)(unsafe.Pointer((*TSessionInput)(unsafe.Pointer(pIn)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext+v2))))
			if eType == int32(SQLITE_TEXT) || eType == int32(SQLITE_BLOB) {
				nByte += _sessionVarintGet(tls, (*TSessionInput)(unsafe.Pointer(pIn)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext+nByte), bp)
				nByte += *(*int32)(unsafe.Pointer(bp))
				rc = _sessionInputBuffer(tls, pIn, nByte)
			} else {
				if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
					nByte += int32(8)
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	*(*int32)(unsafe.Pointer(pnByte)) = nByte
	return rc
}

// C documentation
//
//	/*
//	** The input pointer currently points to the second byte of a table-header.
//	** Specifically, to the following:
//	**
//	**   + number of columns in table (varint)
//	**   + array of PK flags (1 byte per column),
//	**   + table name (nul terminated).
//	**
//	** This function decodes the table-header and populates the p->nCol,
//	** p->zTab and p->abPK[] variables accordingly. The p->apValue[] array is
//	** also allocated or resized according to the new value of p->nCol. The
//	** input pointer is left pointing to the byte following the table header.
//	**
//	** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code
//	** is returned and the final values of the various fields enumerated above
//	** are undefined.
//	*/
func _sessionChangesetReadTblhdr(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPK Tsize_t
	var nByte, nVarint, v2 int32
	var v1 uintptr
	var _ /* nCopy at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _ = iPK, nByte, nVarint, v1, v2
	*(*int32)(unsafe.Pointer(bp)) = _sessionChangesetBufferTblhdr(tls, p, bp+4)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		nVarint = _sessionVarintGet(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData+uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext), p+80)
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol > 0 {
			*(*int32)(unsafe.Pointer(bp + 4)) -= nVarint
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext += nVarint
			nByte = int32(uint32((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*uint32(4)*uint32(2) + uint32(*(*int32)(unsafe.Pointer(bp + 4))))
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FnBuf = 0
			_sessionBufferGrow(tls, p+44, int64(int64(nByte)), bp)
		} else {
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(228521))
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		iPK = uint32(4) * uint32((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) * uint32(2)
		libc.Xmemset(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf, 0, iPK)
		libc.Xmemcpy(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf+uintptr(iPK), (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData+uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext), uint32(*(*int32)(unsafe.Pointer(bp + 4))))
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext += *(*int32)(unsafe.Pointer(bp + 4))
	}
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue == uintptr(0) {
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK = uintptr(0)
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab = uintptr(0)
	} else {
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*int32(2))*4
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK != 0 {
			v1 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)
		} else {
			v1 = uintptr(0)
		}
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab = v1
	}
	v2 = *(*int32)(unsafe.Pointer(bp))
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v2
	return v2
}

// C documentation
//
//	/*
//	** Advance the changeset iterator to the next change. The differences between
//	** this function and sessionChangesetNext() are that
//	**
//	**   * If pbEmpty is not NULL and the change is a no-op UPDATE (an UPDATE
//	**     that modifies no columns), this function sets (*pbEmpty) to 1.
//	**
//	**   * If the iterator is configured to skip no-op UPDATEs,
//	**     sessionChangesetNext() does that. This function does not.
//	*/
func _sessionChangesetNextOne(tls *libc.TLS, p uintptr, paRec uintptr, pnRec uintptr, pbNew uintptr, pbEmpty uintptr) (r int32) {
	var abPK, apNew, apOld, v12, v13, v14, v3, v6, v9 uintptr
	var i, nVal, v10, v16, v2, v4, v5, v7, v8 int32
	var op Tu8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = abPK, apNew, apOld, i, nVal, op, v10, v12, v13, v14, v16, v2, v3, v4, v5, v6, v7, v8, v9
	/* If the iterator is in the error-state, return immediately. */
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
	}
	/* Free the current contents of p->apValue[], if any. */
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue != 0 {
		i = 0
		for {
			if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*int32(2)) {
				break
			}
			_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		libc.Xmemset(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue, 0, uint32(4)*uint32((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*uint32(2))
	}
	/* Make sure the buffer contains at least 10 bytes of input data, or all
	 ** remaining data if there are less than 10 bytes available. This is
	 ** sufficient either for the 'T' or 'P' byte and the varint that follows
	 ** it, or for the two single byte values otherwise. */
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionInputBuffer(tls, p, int32(2))
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
	}
	_sessionDiscardData(tls, p)
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiCurrent = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext
	/* If the iterator is already at the end of the changeset, return DONE. */
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FnData {
		return int32(SQLITE_DONE)
	}
	v3 = p + 8
	v2 = *(*int32)(unsafe.Pointer(v3))
	*(*int32)(unsafe.Pointer(v3))++
	op = *(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(v2)))
	for int32(int32(op)) == int32('T') || int32(int32(op)) == int32('P') {
		if pbNew != 0 {
			*(*int32)(unsafe.Pointer(pbNew)) = int32(1)
		}
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset = libc.BoolInt32(int32(int32(op)) == int32('P'))
		if _sessionChangesetReadTblhdr(tls, p) != 0 {
			return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		}
		v4 = _sessionInputBuffer(tls, p, int32(2))
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v4
		if v4 != 0 {
			return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		}
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiCurrent = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FnData {
			return int32(SQLITE_DONE)
		}
		v6 = p + 8
		v5 = *(*int32)(unsafe.Pointer(v6))
		*(*int32)(unsafe.Pointer(v6))++
		op = *(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(v5)))
	}
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab == uintptr(0) || (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
		/* The first record in the changeset is not a table header. Must be a
		 ** corrupt changeset. */
		v7 = _sqlite3CorruptError(tls, int32(228607))
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v7
		return v7
	}
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = int32(int32(op))
	v9 = p + 8
	v8 = *(*int32)(unsafe.Pointer(v9))
	*(*int32)(unsafe.Pointer(v9))++
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbIndirect = int32(*(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(v8))))
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != int32(SQLITE_UPDATE) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != int32(SQLITE_DELETE) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != int32(SQLITE_INSERT) {
		v10 = _sqlite3CorruptError(tls, int32(228613))
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v10
		return v10
	}
	if paRec != 0 { /* Number of values to buffer */
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 && int32(int32(op)) == int32(SQLITE_UPDATE) {
			nVal = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol * int32(2)
		} else {
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 && int32(int32(op)) == int32(SQLITE_DELETE) {
				nVal = 0
				i = 0
				for {
					if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) {
						break
					}
					if *(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
						nVal++
					}
					goto _11
				_11:
					;
					i++
				}
			} else {
				nVal = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol
			}
		}
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionChangesetBufferRecord(tls, p, nVal, pnRec)
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
			return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		}
		*(*uintptr)(unsafe.Pointer(paRec)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext)
		(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext += *(*int32)(unsafe.Pointer(pnRec))
	} else {
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
			v12 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*4
		} else {
			v12 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue
		}
		apOld = v12
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
			v13 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue
		} else {
			v13 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*4
		}
		apNew = v13
		/* If this is an UPDATE or DELETE, read the old.* record. */
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != int32(SQLITE_INSERT) && ((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 || (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_DELETE)) {
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 {
				v14 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK
			} else {
				v14 = uintptr(0)
			}
			abPK = v14
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionReadRecord(tls, p, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol, abPK, apOld, uintptr(0))
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
			}
		}
		/* If this is an INSERT or UPDATE, read the new.* record. */
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != int32(SQLITE_DELETE) {
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionReadRecord(tls, p, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol, uintptr(0), apNew, pbEmpty)
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
			}
		}
		if ((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 || (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_UPDATE) {
			/* If this is an UPDATE that is part of a patchset, then all PK and
			 ** modified fields are present in the new.* record. The old.* record
			 ** is currently completely empty. This block shifts the PK fields from
			 ** new.* to old.*, to accommodate the code that reads these arrays.  */
			i = 0
			for {
				if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) {
					break
				}
				if *(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
					*(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*4)) = *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*4))
					if *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*4)) == uintptr(0) {
						v16 = _sqlite3CorruptError(tls, int32(228657))
						(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v16
						return v16
					}
					*(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*4)) = uintptr(0)
				}
				goto _15
			_15:
				;
				i++
			}
		} else {
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
				if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_INSERT) {
					(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = int32(SQLITE_DELETE)
				} else {
					if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_DELETE) {
						(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = int32(SQLITE_INSERT)
					}
				}
			}
		}
		/* If this is an UPDATE that is part of a changeset, then check that
		 ** there are no fields in the old.* record that are not (a) PK fields,
		 ** or (b) also present in the new.* record.
		 **
		 ** Such records are technically corrupt, but the rebaser was at one
		 ** point generating them. Under most circumstances this is benign, but
		 ** can cause spurious SQLITE_RANGE errors when applying the changeset. */
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_UPDATE) {
			i = 0
			for {
				if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) {
					break
				}
				if int32(*(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i)))) == 0 && *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*4)) == uintptr(0) {
					_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*4)))
					*(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*4)) = uintptr(0)
				}
				goto _17
			_17:
				;
				i++
			}
		}
	}
	return int32(SQLITE_ROW)
}

// C documentation
//
//	/*
//	** Advance the changeset iterator to the next change.
//	**
//	** If both paRec and pnRec are NULL, then this function works like the public
//	** API sqlite3changeset_next(). If SQLITE_ROW is returned, then the
//	** sqlite3changeset_new() and old() APIs may be used to query for values.
//	**
//	** Otherwise, if paRec and pnRec are not NULL, then a pointer to the change
//	** record is written to *paRec before returning and the number of bytes in
//	** the record to *pnRec.
//	**
//	** Either way, this function returns SQLITE_ROW if the iterator is
//	** successfully advanced to the next change in the changeset, an SQLite
//	** error code if an error occurs, or SQLITE_DONE if there are no further
//	** changes in the changeset.
//	*/
func _sessionChangesetNext(tls *libc.TLS, p uintptr, paRec uintptr, pnRec uintptr, pbNew uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* bEmpty at bp+0 */ int32
	_ = rc
	for cond := true; cond; cond = rc == int32(SQLITE_ROW) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbSkipEmpty != 0 && *(*int32)(unsafe.Pointer(bp)) != 0 {
		*(*int32)(unsafe.Pointer(bp)) = 0
		rc = _sessionChangesetNextOne(tls, p, paRec, pnRec, pbNew, bp)
	}
	return rc
}

// C documentation
//
//	/*
//	** Advance an iterator created by sqlite3changeset_start() to the next
//	** change in the changeset. This function may return SQLITE_ROW, SQLITE_DONE
//	** or SQLITE_CORRUPT.
//	**
//	** This function may not be called on iterators passed to a conflict handler
//	** callback by changeset_apply().
//	*/
func Xsqlite3changeset_next(tls *libc.TLS, p uintptr) (r int32) {
	return _sessionChangesetNext(tls, p, uintptr(0), uintptr(0), uintptr(0))
}

// C documentation
//
//	/*
//	** The following function extracts information on the current change
//	** from a changeset iterator. It may only be called after changeset_next()
//	** has returned SQLITE_ROW.
//	*/
func Xsqlite3changeset_op(tls *libc.TLS, pIter uintptr, pzTab uintptr, pnCol uintptr, pOp uintptr, pbIndirect uintptr) (r int32) {
	*(*int32)(unsafe.Pointer(pOp)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop
	*(*int32)(unsafe.Pointer(pnCol)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	*(*uintptr)(unsafe.Pointer(pzTab)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab
	if pbIndirect != 0 {
		*(*int32)(unsafe.Pointer(pbIndirect)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return information regarding the PRIMARY KEY and number of columns in
//	** the database table affected by the change that pIter currently points
//	** to. This function may only be called after changeset_next() returns
//	** SQLITE_ROW.
//	*/
func Xsqlite3changeset_pk(tls *libc.TLS, pIter uintptr, pabPK uintptr, pnCol uintptr) (r int32) {
	*(*uintptr)(unsafe.Pointer(pabPK)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK
	if pnCol != 0 {
		*(*int32)(unsafe.Pointer(pnCol)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function may only be called while the iterator is pointing to an
//	** SQLITE_UPDATE or SQLITE_DELETE change (see sqlite3changeset_op()).
//	** Otherwise, SQLITE_MISUSE is returned.
//	**
//	** It sets *ppValue to point to an sqlite3_value structure containing the
//	** iVal'th value in the old.* record. Or, if that particular value is not
//	** included in the record (because the change is an UPDATE and the field
//	** was not modified and is not a PK column), set *ppValue to NULL.
//	**
//	** If value iVal is out-of-range, SQLITE_RANGE is returned and *ppValue is
//	** not modified. Otherwise, SQLITE_OK.
//	*/
func Xsqlite3changeset_old(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) (r int32) {
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_UPDATE) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_DELETE) {
		return int32(SQLITE_MISUSE)
	}
	if iVal < 0 || iVal >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return int32(SQLITE_RANGE)
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(iVal)*4))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function may only be called while the iterator is pointing to an
//	** SQLITE_UPDATE or SQLITE_INSERT change (see sqlite3changeset_op()).
//	** Otherwise, SQLITE_MISUSE is returned.
//	**
//	** It sets *ppValue to point to an sqlite3_value structure containing the
//	** iVal'th value in the new.* record. Or, if that particular value is not
//	** included in the record (because the change is an UPDATE and the field
//	** was not modified), set *ppValue to NULL.
//	**
//	** If value iVal is out-of-range, SQLITE_RANGE is returned and *ppValue is
//	** not modified. Otherwise, SQLITE_OK.
//	*/
func Xsqlite3changeset_new(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) (r int32) {
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_UPDATE) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_INSERT) {
		return int32(SQLITE_MISUSE)
	}
	if iVal < 0 || iVal >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return int32(SQLITE_RANGE)
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+iVal)*4))
	return SQLITE_OK
}

/*
** The following two macros are used internally. They are similar to the
** sqlite3changeset_new() and sqlite3changeset_old() functions, except that
** they omit all error checking and return a pointer to the requested value.
 */

// C documentation
//
//	/*
//	** This function may only be called with a changeset iterator that has been
//	** passed to an SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT
//	** conflict-handler function. Otherwise, SQLITE_MISUSE is returned.
//	**
//	** If successful, *ppValue is set to point to an sqlite3_value structure
//	** containing the iVal'th value of the conflicting record.
//	**
//	** If value iVal is out-of-range or some other error occurs, an SQLite error
//	** code is returned. Otherwise, SQLITE_OK.
//	*/
func Xsqlite3changeset_conflict(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) (r int32) {
	if !((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict != 0) {
		return int32(SQLITE_MISUSE)
	}
	if iVal < 0 || iVal >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return int32(SQLITE_RANGE)
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = Xsqlite3_column_value(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict, iVal)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function may only be called with an iterator passed to an
//	** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
//	** it sets the output variable to the total number of known foreign key
//	** violations in the destination database and returns SQLITE_OK.
//	**
//	** In all other cases this function returns SQLITE_MISUSE.
//	*/
func Xsqlite3changeset_fk_conflicts(tls *libc.TLS, pIter uintptr, pnOut uintptr) (r int32) {
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict != 0 || (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue != 0 {
		return int32(SQLITE_MISUSE)
	}
	*(*int32)(unsafe.Pointer(pnOut)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Finalize an iterator allocated with sqlite3changeset_start().
//	**
//	** This function may not be called on iterators passed to a conflict handler
//	** callback by changeset_apply().
//	*/
func Xsqlite3changeset_finalize(tls *libc.TLS, p uintptr) (r int32) {
	var i, rc int32
	_, _ = i, rc
	rc = SQLITE_OK
	if p != 0 { /* Used to iterate through p->apValue[] */
		rc = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue != 0 {
			i = 0
			for {
				if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*int32(2)) {
					break
				}
				_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*4)))
				goto _1
			_1:
				;
				i++
			}
		}
		Xsqlite3_free(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf)
		Xsqlite3_free(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.Fbuf.FaBuf)
		Xsqlite3_free(tls, p)
	}
	return rc
}

func _sessionChangesetInvert(tls *libc.TLS, pInput uintptr, xOutput uintptr, pOut uintptr, pnInverted uintptr, ppInverted uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var abPK, apVal, pVal, pVal1, v7 uintptr
	var bIndirect, eType2, iCol, nVar, v1, v2, v3, v5 int32
	var eType Tu8
	var _ /* nByte at bp+32 */ int32
	var _ /* nByte at bp+36 */ int32
	var _ /* nCol at bp+16 */ int32
	var _ /* rc at bp+0 */ int32
	var _ /* sOut at bp+4 */ TSessionBuffer
	var _ /* sPK at bp+20 */ TSessionBuffer
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = abPK, apVal, bIndirect, eType, eType2, iCol, nVar, pVal, pVal1, v1, v2, v3, v5, v7
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK                      /* Output buffer */
	*(*int32)(unsafe.Pointer(bp + 16)) = 0                         /* Number of cols in current table */
	abPK = uintptr(0)                                              /* PK array for current table */
	apVal = uintptr(0)                                             /* Space for values for UPDATE inversion */
	*(*TSessionBuffer)(unsafe.Pointer(bp + 20)) = TSessionBuffer{} /* PK array for current table */
	/* Initialize the output buffer */
	libc.Xmemset(tls, bp+4, 0, uint32(12))
	/* Zero the output variables in case an error occurs. */
	if ppInverted != 0 {
		*(*uintptr)(unsafe.Pointer(ppInverted)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pnInverted)) = 0
	}
	for int32(1) != 0 {
		/* Test for EOF. */
		v1 = _sessionInputBuffer(tls, pInput, int32(2))
		*(*int32)(unsafe.Pointer(bp)) = v1
		if v1 != 0 {
			goto finished_invert
		}
		if (*TSessionInput)(unsafe.Pointer(pInput)).FiNext >= (*TSessionInput)(unsafe.Pointer(pInput)).FnData {
			break
		}
		eType = *(*Tu8)(unsafe.Pointer((*TSessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext)))
		switch int32(int32(eType)) {
		case int32('T'):
			(*TSessionInput)(unsafe.Pointer(pInput)).FiNext++
			v2 = _sessionChangesetBufferTblhdr(tls, pInput, bp+32)
			*(*int32)(unsafe.Pointer(bp)) = v2
			if v2 != 0 {
				goto finished_invert
			}
			nVar = _sessionVarintGet(tls, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext), bp+16)
			(*(*TSessionBuffer)(unsafe.Pointer(bp + 20))).FnBuf = 0
			_sessionAppendBlob(tls, bp+20, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext+nVar), *(*int32)(unsafe.Pointer(bp + 16)), bp)
			_sessionAppendByte(tls, bp+4, eType, bp)
			_sessionAppendBlob(tls, bp+4, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext), *(*int32)(unsafe.Pointer(bp + 32)), bp)
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				goto finished_invert
			}
			*(*int32)(unsafe.Pointer(pInput + 8)) += *(*int32)(unsafe.Pointer(bp + 32))
			Xsqlite3_free(tls, apVal)
			apVal = uintptr(0)
			abPK = (*(*TSessionBuffer)(unsafe.Pointer(bp + 20))).FaBuf
		case int32(SQLITE_INSERT):
			fallthrough
		case int32(SQLITE_DELETE):
			bIndirect = int32(*(*Tu8)(unsafe.Pointer((*TSessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext+int32(1)))))
			if int32(int32(eType)) == int32(SQLITE_DELETE) {
				v3 = int32(SQLITE_INSERT)
			} else {
				v3 = int32(SQLITE_DELETE)
			}
			eType2 = v3
			*(*int32)(unsafe.Pointer(pInput + 8)) += int32(2)
			*(*int32)(unsafe.Pointer(bp)) = _sessionChangesetBufferRecord(tls, pInput, *(*int32)(unsafe.Pointer(bp + 16)), bp+36)
			_sessionAppendByte(tls, bp+4, uint8(uint8(eType2)), bp)
			_sessionAppendByte(tls, bp+4, uint8(uint8(bIndirect)), bp)
			_sessionAppendBlob(tls, bp+4, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext), *(*int32)(unsafe.Pointer(bp + 36)), bp)
			*(*int32)(unsafe.Pointer(pInput + 8)) += *(*int32)(unsafe.Pointer(bp + 36))
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				goto finished_invert
			}
		case int32(SQLITE_UPDATE):
			if uintptr(0) == apVal {
				apVal = Xsqlite3_malloc64(tls, uint64(uint32(4)*uint32(*(*int32)(unsafe.Pointer(bp + 16)))*uint32(2)))
				if uintptr(0) == apVal {
					*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
					goto finished_invert
				}
				libc.Xmemset(tls, apVal, 0, uint32(4)*uint32(*(*int32)(unsafe.Pointer(bp + 16)))*uint32(2))
			}
			/* Write the header for the new UPDATE change. Same as the original. */
			_sessionAppendByte(tls, bp+4, eType, bp)
			_sessionAppendByte(tls, bp+4, *(*Tu8)(unsafe.Pointer((*TSessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext+int32(1)))), bp)
			/* Read the old.* and new.* records for the update change. */
			*(*int32)(unsafe.Pointer(pInput + 8)) += int32(2)
			*(*int32)(unsafe.Pointer(bp)) = _sessionReadRecord(tls, pInput, *(*int32)(unsafe.Pointer(bp + 16)), uintptr(0), apVal, uintptr(0))
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp)) = _sessionReadRecord(tls, pInput, *(*int32)(unsafe.Pointer(bp + 16)), uintptr(0), apVal+uintptr(*(*int32)(unsafe.Pointer(bp + 16)))*4, uintptr(0))
			}
			/* Write the new old.* record. Consists of the PK columns from the
			 ** original old.* record, and the other values from the original
			 ** new.* record. */
			iCol = 0
			for {
				if !(iCol < *(*int32)(unsafe.Pointer(bp + 16))) {
					break
				}
				if *(*Tu8)(unsafe.Pointer(abPK + uintptr(iCol))) != 0 {
					v5 = 0
				} else {
					v5 = *(*int32)(unsafe.Pointer(bp + 16))
				}
				pVal = *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol+v5)*4))
				_sessionAppendValue(tls, bp+4, pVal, bp)
				goto _4
			_4:
				;
				iCol++
			}
			/* Write the new new.* record. Consists of a copy of all values
			 ** from the original old.* record, except for the PK columns, which
			 ** are set to "undefined". */
			iCol = 0
			for {
				if !(iCol < *(*int32)(unsafe.Pointer(bp + 16))) {
					break
				}
				if *(*Tu8)(unsafe.Pointer(abPK + uintptr(iCol))) != 0 {
					v7 = uintptr(0)
				} else {
					v7 = *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol)*4))
				}
				pVal1 = v7
				_sessionAppendValue(tls, bp+4, pVal1, bp)
				goto _6
			_6:
				;
				iCol++
			}
			iCol = 0
			for {
				if !(iCol < *(*int32)(unsafe.Pointer(bp + 16))*int32(2)) {
					break
				}
				_sqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol)*4)))
				goto _8
			_8:
				;
				iCol++
			}
			libc.Xmemset(tls, apVal, 0, uint32(4)*uint32(*(*int32)(unsafe.Pointer(bp + 16)))*uint32(2))
			if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
				goto finished_invert
			}
		default:
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3CorruptError(tls, int32(229022))
			goto finished_invert
		}
		if xOutput != 0 && (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf >= _sessions_strm_chunk_size {
			*(*int32)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf)
			(*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf = 0
			if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
				goto finished_invert
			}
		}
	}
	if pnInverted != 0 && ppInverted != 0 {
		*(*int32)(unsafe.Pointer(pnInverted)) = (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf
		*(*uintptr)(unsafe.Pointer(ppInverted)) = (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf
		(*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf = uintptr(0)
	} else {
		if (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf > 0 && xOutput != uintptr(0) {
			*(*int32)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf)
		}
	}
	goto finished_invert
finished_invert:
	;
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf)
	Xsqlite3_free(tls, apVal)
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 20))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Invert a changeset object.
//	*/
func Xsqlite3changeset_invert(tls *libc.TLS, nChangeset int32, pChangeset uintptr, pnInverted uintptr, ppInverted uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* sInput at bp+0 */ TSessionInput
	/* Set up the input stream */
	libc.Xmemset(tls, bp, 0, uint32(44))
	(*(*TSessionInput)(unsafe.Pointer(bp))).FnData = nChangeset
	(*(*TSessionInput)(unsafe.Pointer(bp))).FaData = pChangeset
	return _sessionChangesetInvert(tls, bp, uintptr(0), uintptr(0), pnInverted, ppInverted)
}

// C documentation
//
//	/*
//	** Streaming version of sqlite3changeset_invert().
//	*/
func Xsqlite3changeset_invert_strm(tls *libc.TLS, xInput uintptr, pIn uintptr, xOutput uintptr, pOut uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var _ /* sInput at bp+0 */ TSessionInput
	_ = rc
	/* Set up the input stream */
	libc.Xmemset(tls, bp, 0, uint32(44))
	(*(*TSessionInput)(unsafe.Pointer(bp))).FxInput = xInput
	(*(*TSessionInput)(unsafe.Pointer(bp))).FpIn = pIn
	rc = _sessionChangesetInvert(tls, bp, xOutput, pOut, uintptr(0), uintptr(0))
	Xsqlite3_free(tls, (*(*TSessionInput)(unsafe.Pointer(bp))).Fbuf.FaBuf)
	return rc
}

type TSessionUpdate = struct {
	FpStmt uintptr
	FaMask uintptr
	FpNext uintptr
}

type SessionUpdate = TSessionUpdate

type TSessionUpdate1 = struct {
	FpStmt uintptr
	FaMask uintptr
	FpNext uintptr
}

type SessionUpdate1 = TSessionUpdate1

type TSessionApplyCtx = struct {
	Fdb                 uintptr
	FpDelete            uintptr
	FpInsert            uintptr
	FpSelect            uintptr
	FnCol               int32
	FazCol              uintptr
	FabPK               uintptr
	FaUpdateMask        uintptr
	FpUp                uintptr
	FbStat1             int32
	FbDeferConstraints  int32
	FbInvertConstraints int32
	Fconstraints        TSessionBuffer
	Frebase             TSessionBuffer
	FbRebaseStarted     Tu8
	FbRebase            Tu8
	FbIgnoreNoop        Tu8
	FbRowid             int32
}

type SessionApplyCtx = TSessionApplyCtx

type TSessionApplyCtx1 = struct {
	Fdb                 uintptr
	FpDelete            uintptr
	FpInsert            uintptr
	FpSelect            uintptr
	FnCol               int32
	FazCol              uintptr
	FabPK               uintptr
	FaUpdateMask        uintptr
	FpUp                uintptr
	FbStat1             int32
	FbDeferConstraints  int32
	FbInvertConstraints int32
	Fconstraints        TSessionBuffer
	Frebase             TSessionBuffer
	FbRebaseStarted     Tu8
	FbRebase            Tu8
	FbIgnoreNoop        Tu8
	FbRowid             int32
}

type SessionApplyCtx1 = TSessionApplyCtx1

/* Number of prepared UPDATE statements to cache. */

// C documentation
//
//	/*
//	** Find a prepared UPDATE statement suitable for the UPDATE step currently
//	** being visited by the iterator. The UPDATE is of the form:
//	**
//	**   UPDATE tbl SET col = ?, col2 = ? WHERE pk1 IS ? AND pk2 IS ?
//	*/
func _sessionUpdateFind(tls *libc.TLS, pIter uintptr, p uintptr, bPatchset int32, ppStmt uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bStat1, ii, nByte, nCol, nU32, nUp int32
	var pUp, pp, zSep, zSql uintptr
	var _ /* buf at bp+4 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = bStat1, ii, nByte, nCol, nU32, nUp, pUp, pp, zSep, zSql
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	pUp = uintptr(0)
	nCol = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	nU32 = ((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol + int32(33)) / int32(32)
	if (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
		(*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask = Xsqlite3_malloc(tls, int32(uint32(uint32(nU32))*uint32(4)))
		if (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		libc.Xmemset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, 0, uint32(uint32(nU32))*uint32(4))
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_CORRUPT)
		ii = 0
		for {
			if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
				break
			}
			if *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*4)) != 0 {
				*(*Tu32)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(ii/int32(32))*4)) |= uint32(libc.Int32FromInt32(1) << (ii % libc.Int32FromInt32(32)))
				*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
			}
			goto _1
		_1:
			;
			ii++
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		if bPatchset != 0 {
			*(*Tu32)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(nCol/int32(32))*4)) |= uint32(libc.Int32FromInt32(1) << (nCol % libc.Int32FromInt32(32)))
		}
		if (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp != 0 {
			nUp = 0
			pp = p + 32
			for int32(1) != 0 {
				nUp++
				if 0 == libc.Xmemcmp(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, (*TSessionUpdate)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FaMask, uint32(uint32(nU32))*uint32(4)) {
					pUp = *(*uintptr)(unsafe.Pointer(pp))
					*(*uintptr)(unsafe.Pointer(pp)) = (*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext
					(*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp
					(*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
					break
				}
				if (*TSessionUpdate)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext != 0 {
					pp = *(*uintptr)(unsafe.Pointer(pp)) + 8
				} else {
					if nUp >= int32(SESSION_UPDATE_CACHE_SZ) {
						Xsqlite3_finalize(tls, (*TSessionUpdate)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpStmt)
						Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(pp)))
						*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
					}
					break
				}
			}
		}
		if pUp == uintptr(0) {
			nByte = int32(uint32(12) * uint32(uint32(nU32)) * uint32(4))
			bStat1 = libc.BoolInt32(Xsqlite3_stricmp(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, __ccgo_ts+13016) == 0)
			pUp = Xsqlite3_malloc(tls, nByte)
			if pUp == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
			} else {
				zSep = __ccgo_ts + 1672
				libc.Xmemset(tls, bp+4, 0, uint32(12))
				(*TSessionUpdate)(unsafe.Pointer(pUp)).FaMask = pUp + 1*12
				libc.Xmemcpy(tls, (*TSessionUpdate)(unsafe.Pointer(pUp)).FaMask, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, uint32(uint32(nU32))*uint32(4))
				_sessionAppendStr(tls, bp+4, __ccgo_ts+35414, bp)
				_sessionAppendIdent(tls, bp+4, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, bp)
				_sessionAppendStr(tls, bp+4, __ccgo_ts+35427, bp)
				/* Create the assignments part of the UPDATE */
				ii = 0
				for {
					if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
						break
					}
					if int32(*(*Tu8)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii)))) == 0 && *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*4)) != 0 {
						_sessionAppendStr(tls, bp+4, zSep, bp)
						_sessionAppendIdent(tls, bp+4, *(*uintptr)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*4)), bp)
						_sessionAppendStr(tls, bp+4, __ccgo_ts+35433, bp)
						_sessionAppendInteger(tls, bp+4, ii*int32(2)+int32(1), bp)
						zSep = __ccgo_ts + 16397
					}
					goto _2
				_2:
					;
					ii++
				}
				/* Create the WHERE clause part of the UPDATE */
				zSep = __ccgo_ts + 1672
				_sessionAppendStr(tls, bp+4, __ccgo_ts+35438, bp)
				ii = 0
				for {
					if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
						break
					}
					if *(*Tu8)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii))) != 0 || bPatchset == 0 && *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(ii)*4)) != 0 {
						_sessionAppendStr(tls, bp+4, zSep, bp)
						if bStat1 != 0 && ii == int32(1) {
							_sessionAppendStr(tls, bp+4, __ccgo_ts+35446, bp)
						} else {
							_sessionAppendIdent(tls, bp+4, *(*uintptr)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*4)), bp)
							_sessionAppendStr(tls, bp+4, __ccgo_ts+35521, bp)
							_sessionAppendInteger(tls, bp+4, ii*int32(2)+int32(2), bp)
						}
						zSep = __ccgo_ts + 23484
					}
					goto _3
				_3:
					;
					ii++
				}
				if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
					zSql = (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf
					*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v2(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).Fdb, zSql, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf, pUp, uintptr(0))
				}
				if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
					Xsqlite3_free(tls, pUp)
					pUp = uintptr(0)
				} else {
					(*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp
					(*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
				}
				Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf)
			}
		}
	}
	if pUp != 0 {
		*(*uintptr)(unsafe.Pointer(ppStmt)) = (*TSessionUpdate)(unsafe.Pointer(pUp)).FpStmt
	} else {
		*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Free all cached UPDATE statements.
//	*/
func _sessionUpdateFree(tls *libc.TLS, p uintptr) {
	var pNext, pUp uintptr
	_, _ = pNext, pUp
	pUp = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp
	for {
		if !(pUp != 0) {
			break
		}
		pNext = (*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext
		Xsqlite3_finalize(tls, (*TSessionUpdate)(unsafe.Pointer(pUp)).FpStmt)
		Xsqlite3_free(tls, pUp)
		goto _1
	_1:
		;
		pUp = pNext
	}
	(*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp = uintptr(0)
	Xsqlite3_free(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask)
	(*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask = uintptr(0)
}

// C documentation
//
//	/*
//	** Formulate a statement to DELETE a row from database db. Assuming a table
//	** structure like this:
//	**
//	**     CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
//	**
//	** The DELETE statement looks like this:
//	**
//	**     DELETE FROM x WHERE a = :1 AND c = :3 AND (:5 OR b IS :2 AND d IS :4)
//	**
//	** Variable :5 (nCol+1) is a boolean. It should be set to 0 if we require
//	** matching b and d values, or 1 otherwise. The second case comes up if the
//	** conflict handler is invoked with NOTFOUND and returns CHANGESET_REPLACE.
//	**
//	** If successful, SQLITE_OK is returned and SessionApplyCtx.pDelete is left
//	** pointing to the prepared version of the SQL statement.
//	*/
func _sessionDeleteRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, nPk int32
	var zSep uintptr
	var _ /* buf at bp+4 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _ = i, nPk, zSep
	zSep = __ccgo_ts + 1672
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*TSessionBuffer)(unsafe.Pointer(bp + 4)) = TSessionBuffer{}
	nPk = 0
	_sessionAppendStr(tls, bp+4, __ccgo_ts+35527, bp)
	_sessionAppendIdent(tls, bp+4, zTab, bp)
	_sessionAppendStr(tls, bp+4, __ccgo_ts+35438, bp)
	i = 0
	for {
		if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
			break
		}
		if *(*Tu8)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
			nPk++
			_sessionAppendStr(tls, bp+4, zSep, bp)
			_sessionAppendIdent(tls, bp+4, *(*uintptr)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*4)), bp)
			_sessionAppendStr(tls, bp+4, __ccgo_ts+35433, bp)
			_sessionAppendInteger(tls, bp+4, i+int32(1), bp)
			zSep = __ccgo_ts + 23484
		}
		goto _1
	_1:
		;
		i++
	}
	if nPk < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol {
		_sessionAppendStr(tls, bp+4, __ccgo_ts+35545, bp)
		_sessionAppendInteger(tls, bp+4, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol+int32(1), bp)
		_sessionAppendStr(tls, bp+4, __ccgo_ts+35009, bp)
		zSep = __ccgo_ts + 1672
		i = 0
		for {
			if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
				break
			}
			if !(*(*Tu8)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0) {
				_sessionAppendStr(tls, bp+4, zSep, bp)
				_sessionAppendIdent(tls, bp+4, *(*uintptr)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*4)), bp)
				_sessionAppendStr(tls, bp+4, __ccgo_ts+35521, bp)
				_sessionAppendInteger(tls, bp+4, i+int32(1), bp)
				zSep = __ccgo_ts + 35553
			}
			goto _2
		_2:
			;
			i++
		}
		_sessionAppendStr(tls, bp+4, __ccgo_ts+6479, bp)
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v2(tls, db, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf, p+4, uintptr(0))
	}
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Formulate and prepare an SQL statement to query table zTab by primary
//	** key. Assuming the following table structure:
//	**
//	**     CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
//	**
//	** The SELECT statement looks like this:
//	**
//	**     SELECT * FROM x WHERE a = ?1 AND c = ?3
//	**
//	** If successful, SQLITE_OK is returned and SessionApplyCtx.pSelect is left
//	** pointing to the prepared version of the SQL statement.
//	*/
func _sessionSelectRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
	/* TODO */
	return _sessionSelectStmt(tls, db, int32((*TSessionApplyCtx)(unsafe.Pointer(p)).FbIgnoreNoop), __ccgo_ts+7958, zTab, (*TSessionApplyCtx)(unsafe.Pointer(p)).FbRowid, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol, (*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK, p+12)
}

// C documentation
//
//	/*
//	** Formulate and prepare an INSERT statement to add a record to table zTab.
//	** For example:
//	**
//	**     INSERT INTO main."zTab" VALUES(?1, ?2, ?3 ...);
//	**
//	** If successful, SQLITE_OK is returned and SessionApplyCtx.pInsert is left
//	** pointing to the prepared version of the SQL statement.
//	*/
func _sessionInsertRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var _ /* buf at bp+4 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_ = i
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*TSessionBuffer)(unsafe.Pointer(bp + 4)) = TSessionBuffer{}
	_sessionAppendStr(tls, bp+4, __ccgo_ts+35558, bp)
	_sessionAppendIdent(tls, bp+4, zTab, bp)
	_sessionAppendStr(tls, bp+4, __ccgo_ts+23490, bp)
	i = 0
	for {
		if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
			break
		}
		if i != 0 {
			_sessionAppendStr(tls, bp+4, __ccgo_ts+16397, bp)
		}
		_sessionAppendIdent(tls, bp+4, *(*uintptr)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*4)), bp)
		goto _1
	_1:
		;
		i++
	}
	_sessionAppendStr(tls, bp+4, __ccgo_ts+35576, bp)
	i = int32(1)
	for {
		if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
			break
		}
		_sessionAppendStr(tls, bp+4, __ccgo_ts+35587, bp)
		goto _2
	_2:
		;
		i++
	}
	_sessionAppendStr(tls, bp+4, __ccgo_ts+6479, bp)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v2(tls, db, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf, p+8, uintptr(0))
	}
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp))
}

func _sessionPrepare(tls *libc.TLS, db uintptr, pp uintptr, zSql uintptr) (r int32) {
	return Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), pp, uintptr(0))
}

// C documentation
//
//	/*
//	** Prepare statements for applying changes to the sqlite_stat1 table.
//	** These are similar to those created by sessionSelectRow(),
//	** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
//	** other tables.
//	*/
func _sessionStat1Sql(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _sessionSelectRow(tls, db, __ccgo_ts+13016, p)
	if rc == SQLITE_OK {
		rc = _sessionPrepare(tls, db, p+8, __ccgo_ts+35591)
	}
	if rc == SQLITE_OK {
		rc = _sessionPrepare(tls, db, p+4, __ccgo_ts+35704)
	}
	return rc
}

// C documentation
//
//	/*
//	** A wrapper around sqlite3_bind_value() that detects an extra problem.
//	** See comments in the body of this function for details.
//	*/
func _sessionBindValue(tls *libc.TLS, pStmt uintptr, i int32, pVal uintptr) (r int32) {
	var eType int32
	_ = eType
	eType = Xsqlite3_value_type(tls, pVal)
	/* COVERAGE: The (pVal->z==0) branch is never true using current versions
	 ** of SQLite. If a malloc fails in an sqlite3_value_xxx() function, either
	 ** the (pVal->z) variable remains as it was or the type of the value is
	 ** set to SQLITE_NULL.  */
	if (eType == int32(SQLITE_TEXT) || eType == int32(SQLITE_BLOB)) && (*Tsqlite3_value)(unsafe.Pointer(pVal)).Fz == uintptr(0) {
		/* This condition occurs when an earlier OOM in a call to
		 ** sqlite3_value_text() or sqlite3_value_blob() (perhaps from within
		 ** a conflict-handler) has zeroed the pVal->z pointer. Return NOMEM. */
		return int32(SQLITE_NOMEM)
	}
	return Xsqlite3_bind_value(tls, pStmt, i, pVal)
}

// C documentation
//
//	/*
//	** Iterator pIter must point to an SQLITE_INSERT entry. This function
//	** transfers new.* values from the current iterator entry to statement
//	** pStmt. The table being inserted into has nCol columns.
//	**
//	** New.* value $i from the iterator is bound to variable ($i+1) of
//	** statement pStmt. If parameter abPK is NULL, all values from 0 to (nCol-1)
//	** are transfered to the statement. Otherwise, if abPK is not NULL, it points
//	** to an array nCol elements in size. In this case only those values for
//	** which abPK[$i] is true are read from the iterator and bound to the
//	** statement.
//	**
//	** An SQLite error code is returned if an error occurs. Otherwise, SQLITE_OK.
//	*/
func _sessionBindRow(tls *libc.TLS, pIter uintptr, xValue uintptr, nCol int32, abPK uintptr, pStmt uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var _ /* pVal at bp+0 */ uintptr
	_, _ = i, rc
	rc = SQLITE_OK
	/* Neither sqlite3changeset_old or sqlite3changeset_new can fail if the
	 ** argument iterator points to a suitable entry. Make sure that xValue
	 ** is one of these to guarantee that it is safe to ignore the return
	 ** in the code below. */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < nCol) {
			break
		}
		if !(abPK != 0) || *(*Tu8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xValue})))(tls, pIter, i, bp)
			if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
				/* The value in the changeset was "undefined". This indicates a
				 ** corrupt changeset blob.  */
				rc = _sqlite3CorruptError(tls, int32(229504))
			} else {
				rc = _sessionBindValue(tls, pStmt, i+int32(1), *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return rc
}

// C documentation
//
//	/*
//	** SQL statement pSelect is as generated by the sessionSelectRow() function.
//	** This function binds the primary key values from the change that changeset
//	** iterator pIter points to to the SELECT and attempts to seek to the table
//	** entry. If a row is found, the SELECT statement left pointing at the row
//	** and SQLITE_ROW is returned. Otherwise, if no row is found and no error
//	** has occured, the statement is reset and SQLITE_OK is returned. If an
//	** error occurs, the statement is reset and an SQLite error code is returned.
//	**
//	** If this function returns SQLITE_ROW, the caller must eventually reset()
//	** statement pSelect. If any other value is returned, the statement does
//	** not require a reset().
//	**
//	** If the iterator currently points to an INSERT record, bind values from the
//	** new.* record to the SELECT statement. Or, if it points to a DELETE or
//	** UPDATE, bind values from the old.* record.
//	*/
func _sessionSeekToRow(tls *libc.TLS, pIter uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var ii, rc int32
	var pSelect, v1 uintptr
	var _ /* nCol at bp+0 */ int32
	var _ /* op at bp+4 */ int32
	var _ /* pVal at bp+12 */ uintptr
	var _ /* zDummy at bp+8 */ uintptr
	_, _, _, _ = ii, pSelect, rc, v1
	pSelect = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpSelect /* Unused */
	Xsqlite3_clear_bindings(tls, pSelect)
	Xsqlite3changeset_op(tls, pIter, bp+8, bp, bp+4, uintptr(0))
	if *(*int32)(unsafe.Pointer(bp + 4)) == int32(SQLITE_INSERT) {
		v1 = __ccgo_fp(Xsqlite3changeset_new)
	} else {
		v1 = __ccgo_fp(Xsqlite3changeset_old)
	}
	rc = _sessionBindRow(tls, pIter, v1, *(*int32)(unsafe.Pointer(bp)), (*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK, pSelect)
	if *(*int32)(unsafe.Pointer(bp + 4)) != int32(SQLITE_DELETE) && (*TSessionApplyCtx)(unsafe.Pointer(p)).FbIgnoreNoop != 0 {
		ii = 0
		for {
			if !(rc == SQLITE_OK && ii < *(*int32)(unsafe.Pointer(bp))) {
				break
			}
			if int32(*(*Tu8)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii)))) == 0 {
				*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
				Xsqlite3changeset_new(tls, pIter, ii, bp+12)
				Xsqlite3_bind_int(tls, pSelect, ii+int32(1)+*(*int32)(unsafe.Pointer(bp)), libc.BoolInt32(*(*uintptr)(unsafe.Pointer(bp + 12)) == uintptr(0)))
				if *(*uintptr)(unsafe.Pointer(bp + 12)) != 0 {
					rc = _sessionBindValue(tls, pSelect, ii+int32(1), *(*uintptr)(unsafe.Pointer(bp + 12)))
				}
			}
			goto _2
		_2:
			;
			ii++
		}
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_step(tls, pSelect)
		if rc != int32(SQLITE_ROW) {
			rc = Xsqlite3_reset(tls, pSelect)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called from within sqlite3changeset_apply_v2() when
//	** a conflict is encountered and resolved using conflict resolution
//	** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE)..
//	** It adds a conflict resolution record to the buffer in
//	** SessionApplyCtx.rebase, which will eventually be returned to the caller
//	** of apply_v2() as the "rebase" buffer.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code otherwise.
//	*/
func _sessionRebaseAdd(tls *libc.TLS, p uintptr, eType int32, pIter uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eOp, i, v1 int32
	var zTab uintptr
	var _ /* pVal at bp+4 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = eOp, i, zTab, v1
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	if (*TSessionApplyCtx)(unsafe.Pointer(p)).FbRebase != 0 {
		eOp = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop
		if int32((*TSessionApplyCtx)(unsafe.Pointer(p)).FbRebaseStarted) == 0 {
			/* Append a table-header to the rebase buffer */
			zTab = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab
			_sessionAppendByte(tls, p+60, uint8('T'), bp)
			_sessionAppendVarint(tls, p+60, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol, bp)
			_sessionAppendBlob(tls, p+60, (*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol, bp)
			_sessionAppendBlob(tls, p+60, zTab, int32(libc.Xstrlen(tls, zTab))+int32(1), bp)
			(*TSessionApplyCtx)(unsafe.Pointer(p)).FbRebaseStarted = uint8(1)
		}
		if eOp == int32(SQLITE_DELETE) {
			v1 = int32(SQLITE_DELETE)
		} else {
			v1 = int32(SQLITE_INSERT)
		}
		_sessionAppendByte(tls, p+60, uint8(v1), bp)
		_sessionAppendByte(tls, p+60, libc.BoolUint8(eType == libc.Int32FromInt32(SQLITE_CHANGESET_REPLACE)), bp)
		i = 0
		for {
			if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
				break
			}
			*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
			if eOp == int32(SQLITE_DELETE) || eOp == int32(SQLITE_UPDATE) && *(*Tu8)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
				Xsqlite3changeset_old(tls, pIter, i, bp+4)
			} else {
				Xsqlite3changeset_new(tls, pIter, i, bp+4)
			}
			_sessionAppendValue(tls, p+60, *(*uintptr)(unsafe.Pointer(bp + 4)), bp)
			goto _2
		_2:
			;
			i++
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Invoke the conflict handler for the change that the changeset iterator
//	** currently points to.
//	**
//	** Argument eType must be either CHANGESET_DATA or CHANGESET_CONFLICT.
//	** If argument pbReplace is NULL, then the type of conflict handler invoked
//	** depends solely on eType, as follows:
//	**
//	**    eType value                 Value passed to xConflict
//	**    -------------------------------------------------
//	**    CHANGESET_DATA              CHANGESET_NOTFOUND
//	**    CHANGESET_CONFLICT          CHANGESET_CONSTRAINT
//	**
//	** Or, if pbReplace is not NULL, then an attempt is made to find an existing
//	** record with the same primary key as the record about to be deleted, updated
//	** or inserted. If such a record can be found, it is available to the conflict
//	** handler as the "conflicting" record. In this case the type of conflict
//	** handler invoked is as follows:
//	**
//	**    eType value         PK Record found?   Value passed to xConflict
//	**    ----------------------------------------------------------------
//	**    CHANGESET_DATA      Yes                CHANGESET_DATA
//	**    CHANGESET_DATA      No                 CHANGESET_NOTFOUND
//	**    CHANGESET_CONFLICT  Yes                CHANGESET_CONFLICT
//	**    CHANGESET_CONFLICT  No                 CHANGESET_CONSTRAINT
//	**
//	** If pbReplace is not NULL, and a record with a matching PK is found, and
//	** the conflict handler function returns SQLITE_CHANGESET_REPLACE, *pbReplace
//	** is set to non-zero before returning SQLITE_OK.
//	**
//	** If the conflict handler returns SQLITE_CHANGESET_ABORT, SQLITE_ABORT is
//	** returned. Or, if the conflict handler returns an invalid value,
//	** SQLITE_MISUSE. If the conflict handler returns SQLITE_CHANGESET_OMIT,
//	** this function returns SQLITE_OK.
//	*/
func _sessionConflictHandler(tls *libc.TLS, eType int32, p uintptr, pIter uintptr, xConflict uintptr, pCtx uintptr, pbReplace uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aBlob uintptr
	var nBlob, res int32
	var _ /* nCol at bp+4 */ int32
	var _ /* op at bp+8 */ int32
	var _ /* rc at bp+0 */ int32
	var _ /* zDummy at bp+12 */ uintptr
	_, _, _ = aBlob, nBlob, res
	res = 0
	Xsqlite3changeset_op(tls, pIter, bp+12, bp+4, bp+8, uintptr(0))
	/* Bind the new.* PRIMARY KEY values to the SELECT statement. */
	if pbReplace != 0 {
		*(*int32)(unsafe.Pointer(bp)) = _sessionSeekToRow(tls, pIter, p)
	} else {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	}
	if *(*int32)(unsafe.Pointer(bp)) == int32(SQLITE_ROW) {
		/* There exists another row with the new.* primary key. */
		if (*TSessionApplyCtx)(unsafe.Pointer(p)).FbIgnoreNoop != 0 && Xsqlite3_column_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpSelect, Xsqlite3_column_count(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpSelect)-int32(1)) != 0 {
			res = SQLITE_CHANGESET_OMIT
		} else {
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpSelect
			res = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xConflict})))(tls, pCtx, eType, pIter)
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict = uintptr(0)
		}
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpSelect)
	} else {
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			if (*TSessionApplyCtx)(unsafe.Pointer(p)).FbDeferConstraints != 0 && eType == int32(SQLITE_CHANGESET_CONFLICT) {
				/* Instead of invoking the conflict handler, append the change blob
				 ** to the SessionApplyCtx.constraints buffer. */
				aBlob = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FaData + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent)
				nBlob = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiNext - (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent
				_sessionAppendBlob(tls, p+48, aBlob, nBlob, bp)
				return SQLITE_OK
			} else {
				/* No other row with the new.* primary key. */
				res = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xConflict})))(tls, pCtx, eType+int32(1), pIter)
				if res == int32(SQLITE_CHANGESET_REPLACE) {
					*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_MISUSE)
				}
			}
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		switch res {
		case int32(SQLITE_CHANGESET_REPLACE):
			*(*int32)(unsafe.Pointer(pbReplace)) = int32(1)
		case SQLITE_CHANGESET_OMIT:
		case int32(SQLITE_CHANGESET_ABORT):
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ABORT)
		default:
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_MISUSE)
			break
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = _sessionRebaseAdd(tls, p, res, pIter)
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Attempt to apply the change that the iterator passed as the first argument
//	** currently points to to the database. If a conflict is encountered, invoke
//	** the conflict handler callback.
//	**
//	** If argument pbRetry is NULL, then ignore any CHANGESET_DATA conflict. If
//	** one is encountered, update or delete the row with the matching primary key
//	** instead. Or, if pbRetry is not NULL and a CHANGESET_DATA conflict occurs,
//	** invoke the conflict handler. If it returns CHANGESET_REPLACE, set *pbRetry
//	** to true before returning. In this case the caller will invoke this function
//	** again, this time with pbRetry set to NULL.
//	**
//	** If argument pbReplace is NULL and a CHANGESET_CONFLICT conflict is
//	** encountered invoke the conflict handler with CHANGESET_CONSTRAINT instead.
//	** Or, if pbReplace is not NULL, invoke it with CHANGESET_CONFLICT. If such
//	** an invocation returns SQLITE_CHANGESET_REPLACE, set *pbReplace to true
//	** before retrying. In this case the caller attempts to remove the conflicting
//	** row before invoking this function again, this time with pbReplace set
//	** to NULL.
//	**
//	** If any conflict handler returns SQLITE_CHANGESET_ABORT, this function
//	** returns SQLITE_ABORT. Otherwise, if no error occurs, SQLITE_OK is
//	** returned.
//	*/
func _sessionApplyOneOp(tls *libc.TLS, pIter uintptr, p uintptr, xConflict uintptr, pCtx uintptr, pbReplace uintptr, pbRetry uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var abPK, pNew, pOld, v1 uintptr
	var bPatchset, i, rc int32
	var _ /* nCol at bp+8 */ int32
	var _ /* op at bp+4 */ int32
	var _ /* pUp at bp+12 */ uintptr
	var _ /* zDummy at bp+0 */ uintptr
	_, _, _, _, _, _, _ = abPK, bPatchset, i, pNew, pOld, rc, v1
	rc = SQLITE_OK
	Xsqlite3changeset_op(tls, pIter, bp, bp+8, bp+4, uintptr(0))
	if *(*int32)(unsafe.Pointer(bp + 4)) == int32(SQLITE_DELETE) {
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
			v1 = (*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK
		} else {
			v1 = uintptr(0)
		}
		/* Bind values to the DELETE statement. If conflict handling is required,
		 ** bind values for all columns and set bound variable (nCol+1) to true.
		 ** Or, if conflict handling is not required, bind just the PK column
		 ** values and, if it exists, set (nCol+1) to false. Conflict handling
		 ** is not required if:
		 **
		 **   * this is a patchset, or
		 **   * (pbRetry==0), or
		 **   * all columns of the table are PK columns (in this case there is
		 **     no (nCol+1) variable to bind to).
		 */
		abPK = v1
		rc = _sessionBindRow(tls, pIter, __ccgo_fp(Xsqlite3changeset_old), *(*int32)(unsafe.Pointer(bp + 8)), abPK, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		if rc == SQLITE_OK && Xsqlite3_bind_parameter_count(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete) > *(*int32)(unsafe.Pointer(bp + 8)) {
			rc = Xsqlite3_bind_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete, *(*int32)(unsafe.Pointer(bp + 8))+int32(1), libc.BoolInt32(pbRetry == uintptr(0) || abPK != 0))
		}
		if rc != SQLITE_OK {
			return rc
		}
		Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		rc = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		if rc == SQLITE_OK && Xsqlite3_changes(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).Fdb) == 0 && int32((*TSessionApplyCtx)(unsafe.Pointer(p)).FbIgnoreNoop) == 0 {
			rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_DATA), p, pIter, xConflict, pCtx, pbRetry)
		} else {
			if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) {
				rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_CONFLICT), p, pIter, xConflict, pCtx, uintptr(0))
			}
		}
	} else {
		if *(*int32)(unsafe.Pointer(bp + 4)) == int32(SQLITE_UPDATE) {
			*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
			bPatchset = libc.BoolInt32(pbRetry == uintptr(0) || (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0)
			rc = _sessionUpdateFind(tls, pIter, p, bPatchset, bp+12)
			/* Bind values to the UPDATE statement. */
			i = 0
			for {
				if !(rc == SQLITE_OK && i < *(*int32)(unsafe.Pointer(bp + 8))) {
					break
				}
				pOld = *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(i)*4))
				pNew = *(*uintptr)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+i)*4))
				if *(*Tu8)(unsafe.Pointer((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 || bPatchset == 0 && pOld != 0 {
					rc = _sessionBindValue(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), i*int32(2)+int32(2), pOld)
				}
				if rc == SQLITE_OK && pNew != 0 {
					rc = _sessionBindValue(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), i*int32(2)+int32(1), pNew)
				}
				goto _2
			_2:
				;
				i++
			}
			if rc != SQLITE_OK {
				return rc
			}
			/* Attempt the UPDATE. In the case of a NOTFOUND or DATA conflict,
			 ** the result will be SQLITE_OK with 0 rows modified. */
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
			if rc == SQLITE_OK && Xsqlite3_changes(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).Fdb) == 0 {
				/* A NOTFOUND or DATA error. Search the table to see if it contains
				 ** a row with a matching primary key. If so, this is a DATA conflict.
				 ** Otherwise, if there is no primary key match, it is a NOTFOUND. */
				rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_DATA), p, pIter, xConflict, pCtx, pbRetry)
			} else {
				if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) {
					/* This is always a CONSTRAINT conflict. */
					rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_CONFLICT), p, pIter, xConflict, pCtx, uintptr(0))
				}
			}
		} else {
			if (*TSessionApplyCtx)(unsafe.Pointer(p)).FbStat1 != 0 {
				/* Check if there is a conflicting row. For sqlite_stat1, this needs
				 ** to be done using a SELECT, as there is no PRIMARY KEY in the
				 ** database schema to throw an exception if a duplicate is inserted.  */
				rc = _sessionSeekToRow(tls, pIter, p)
				if rc == int32(SQLITE_ROW) {
					rc = int32(SQLITE_CONSTRAINT)
					Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpSelect)
				}
			}
			if rc == SQLITE_OK {
				rc = _sessionBindRow(tls, pIter, __ccgo_fp(Xsqlite3changeset_new), *(*int32)(unsafe.Pointer(bp + 8)), uintptr(0), (*TSessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
				if rc != SQLITE_OK {
					return rc
				}
				Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
				rc = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
			}
			if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) {
				rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_CONFLICT), p, pIter, xConflict, pCtx, pbReplace)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Attempt to apply the change that the iterator passed as the first argument
//	** currently points to to the database. If a conflict is encountered, invoke
//	** the conflict handler callback.
//	**
//	** The difference between this function and sessionApplyOne() is that this
//	** function handles the case where the conflict-handler is invoked and
//	** returns SQLITE_CHANGESET_REPLACE - indicating that the change should be
//	** retried in some manner.
//	*/
func _sessionApplyOneWithRetry(tls *libc.TLS, db uintptr, pIter uintptr, pApply uintptr, xConflict uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* bReplace at bp+0 */ int32
	var _ /* bRetry at bp+4 */ int32
	_ = rc
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	rc = _sessionApplyOneOp(tls, pIter, pApply, xConflict, pCtx, bp, bp+4)
	if rc == SQLITE_OK {
		/* If the bRetry flag is set, the change has not been applied due to an
		 ** SQLITE_CHANGESET_DATA problem (i.e. this is an UPDATE or DELETE and
		 ** a row with the correct PK is present in the db, but one or more other
		 ** fields do not contain the expected values) and the conflict handler
		 ** returned SQLITE_CHANGESET_REPLACE. In this case retry the operation,
		 ** but pass NULL as the final argument so that sessionApplyOneOp() ignores
		 ** the SQLITE_CHANGESET_DATA problem.  */
		if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
			rc = _sessionApplyOneOp(tls, pIter, pApply, xConflict, pCtx, uintptr(0), uintptr(0))
		} else {
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				rc = Xsqlite3_exec(tls, db, __ccgo_ts+35848, uintptr(0), uintptr(0), uintptr(0))
				if rc == SQLITE_OK {
					rc = _sessionBindRow(tls, pIter, __ccgo_fp(Xsqlite3changeset_new), (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
					Xsqlite3_bind_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol+int32(1), int32(1))
				}
				if rc == SQLITE_OK {
					Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
					rc = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
				}
				if rc == SQLITE_OK {
					rc = _sessionApplyOneOp(tls, pIter, pApply, xConflict, pCtx, uintptr(0), uintptr(0))
				}
				if rc == SQLITE_OK {
					rc = Xsqlite3_exec(tls, db, __ccgo_ts+35869, uintptr(0), uintptr(0), uintptr(0))
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Retry the changes accumulated in the pApply->constraints buffer.
//	*/
func _sessionRetryConstraints(tls *libc.TLS, db uintptr, bPatchset int32, zTab uintptr, pApply uintptr, xConflict uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var cons TSessionBuffer
	var nByte Tsize_t
	var rc2 int32
	var _ /* pIter2 at bp+4 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _ = cons, nByte, rc2
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	for (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 {
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		cons = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
		libc.Xmemset(tls, pApply+48, 0, uint32(12))
		*(*int32)(unsafe.Pointer(bp)) = _sessionChangesetStart(tls, bp+4, uintptr(0), uintptr(0), cons.FnBuf, cons.FaBuf, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FbInvertConstraints, int32(1))
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			nByte = uint32(int32(2)*(*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol) * uint32(4)
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FbPatchset = bPatchset
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FzTab = zTab
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FnCol = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FabPK = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK
			_sessionBufferGrow(tls, *(*uintptr)(unsafe.Pointer(bp + 4))+44, int64(int64(nByte)), bp)
			(*Tsqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FapValue = (*Tsqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).Ftblhdr.FaBuf
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				libc.Xmemset(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FapValue, 0, nByte)
			}
			for *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3changeset_next(tls, *(*uintptr)(unsafe.Pointer(bp + 4))) {
				*(*int32)(unsafe.Pointer(bp)) = _sessionApplyOneWithRetry(tls, db, *(*uintptr)(unsafe.Pointer(bp + 4)), pApply, xConflict, pCtx)
			}
			rc2 = Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp)) = rc2
			}
		}
		Xsqlite3_free(tls, cons.FaBuf)
		if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
			break
		}
		if (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf >= cons.FnBuf {
			/* No progress was made on the last round. */
			(*TSessionApplyCtx)(unsafe.Pointer(pApply)).FbDeferConstraints = 0
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Argument pIter is a changeset iterator that has been initialized, but
//	** not yet passed to sqlite3changeset_next(). This function applies the
//	** changeset to the main database attached to handle "db". The supplied
//	** conflict handler callback is invoked to resolve any conflicts encountered
//	** while applying the change.
//	*/
func _sessionChangesetApply(tls *libc.TLS, db uintptr, pIter uintptr, xFilter uintptr, xConflict uintptr, pCtx uintptr, ppRebase uintptr, pnRebase uintptr, flags int32) (r int32) {
	bp := tls.Alloc(240)
	defer tls.Free(240)
	var bPatchset, i, nMinCol, nTab, rc, res, schemaMismatch, v2, v3, v4, v6 int32
	var v5, v7 bool
	var _ /* abPK at bp+96 */ uintptr
	var _ /* nCol at bp+84 */ int32
	var _ /* nFk at bp+100 */ int32
	var _ /* notUsed at bp+104 */ int32
	var _ /* op at bp+88 */ int32
	var _ /* sApply at bp+4 */ TSessionApplyCtx
	var _ /* sIter at bp+108 */ Tsqlite3_changeset_iter
	var _ /* zNew at bp+92 */ uintptr
	var _ /* zTab at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = bPatchset, i, nMinCol, nTab, rc, res, schemaMismatch, v2, v3, v4, v5, v6, v7
	schemaMismatch = 0
	rc = SQLITE_OK                               /* Return code */
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Name of current table */
	nTab = 0
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FbNoDiscard = int32(1)
	libc.Xmemset(tls, bp+4, 0, uint32(80))
	(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbRebase = libc.BoolUint8(ppRebase != 0 && pnRebase != 0)
	(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbInvertConstraints = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_INVERT) != 0))
	(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbIgnoreNoop = libc.BoolUint8(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_IGNORENOOP) != 0))
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	if flags&int32(SQLITE_CHANGESETAPPLY_NOSAVEPOINT) == 0 {
		rc = Xsqlite3_exec(tls, db, __ccgo_ts+35888, uintptr(0), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_exec(tls, db, __ccgo_ts+35914, uintptr(0), uintptr(0), uintptr(0))
	}
	for rc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3changeset_next(tls, pIter) {
		Xsqlite3changeset_op(tls, pIter, bp+92, bp+84, bp+88, uintptr(0))
		if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) || Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(bp + 92)), *(*uintptr)(unsafe.Pointer(bp)), nTab+int32(1)) != 0 {
			rc = _sessionRetryConstraints(tls, db, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, *(*uintptr)(unsafe.Pointer(bp)), bp+4, xConflict, pCtx)
			if rc != SQLITE_OK {
				break
			}
			_sessionUpdateFree(tls, bp+4)
			Xsqlite3_free(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FazCol) /* cast works around VC++ bug */
			Xsqlite3_finalize(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpDelete)
			Xsqlite3_finalize(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpInsert)
			Xsqlite3_finalize(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpSelect)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).Fdb = db
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpDelete = uintptr(0)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpInsert = uintptr(0)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpSelect = uintptr(0)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FnCol = 0
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FazCol = uintptr(0)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FabPK = uintptr(0)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbStat1 = 0
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbDeferConstraints = int32(1)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbRebaseStarted = uint8(0)
			(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbRowid = 0
			libc.Xmemset(tls, bp+4+48, 0, uint32(12))
			/* If an xFilter() callback was specified, invoke it now. If the
			 ** xFilter callback returns zero, skip this table. If it returns
			 ** non-zero, proceed. */
			schemaMismatch = libc.BoolInt32(xFilter != 0 && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xFilter})))(tls, pCtx, *(*uintptr)(unsafe.Pointer(bp + 92))))
			if schemaMismatch != 0 {
				*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+216, *(*uintptr)(unsafe.Pointer(bp + 92))))
				if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
					break
				}
				nTab = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp))))
				(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FazCol = *(*uintptr)(unsafe.Pointer(bp))
			} else {
				nMinCol = 0
				Xsqlite3changeset_pk(tls, pIter, bp+96, uintptr(0))
				rc = _sessionTableInfo(tls, uintptr(0), db, __ccgo_ts+7958, *(*uintptr)(unsafe.Pointer(bp + 92)), bp+4+16, bp, bp+4+20, uintptr(0), bp+4+24, bp+4+76)
				if rc != SQLITE_OK {
					break
				}
				i = 0
				for {
					if !(i < (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FnCol) {
						break
					}
					if *(*Tu8)(unsafe.Pointer((*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FabPK + uintptr(i))) != 0 {
						nMinCol = i + int32(1)
					}
					goto _1
				_1:
					;
					i++
				}
				if (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FnCol == 0 {
					schemaMismatch = int32(1)
					Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+35944, libc.VaList(bp+216, *(*uintptr)(unsafe.Pointer(bp))))
				} else {
					if (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FnCol < *(*int32)(unsafe.Pointer(bp + 84)) {
						schemaMismatch = int32(1)
						Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+35988, libc.VaList(bp+216, *(*uintptr)(unsafe.Pointer(bp)), (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FnCol, *(*int32)(unsafe.Pointer(bp + 84))))
					} else {
						if *(*int32)(unsafe.Pointer(bp + 84)) < nMinCol || libc.Xmemcmp(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FabPK, *(*uintptr)(unsafe.Pointer(bp + 96)), uint32(*(*int32)(unsafe.Pointer(bp + 84)))) != 0 {
							schemaMismatch = int32(1)
							Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36059, libc.VaList(bp+216, *(*uintptr)(unsafe.Pointer(bp))))
						} else {
							(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FnCol = *(*int32)(unsafe.Pointer(bp + 84))
							if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(bp)), __ccgo_ts+13016) {
								v2 = _sessionStat1Sql(tls, db, bp+4)
								rc = v2
								if v2 != 0 {
									break
								}
								(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbStat1 = int32(1)
							} else {
								v3 = _sessionSelectRow(tls, db, *(*uintptr)(unsafe.Pointer(bp)), bp+4)
								rc = v3
								if v5 = v3 != 0; !v5 {
									v4 = _sessionDeleteRow(tls, db, *(*uintptr)(unsafe.Pointer(bp)), bp+4)
									rc = v4
								}
								if v7 = v5 || v4 != 0; !v7 {
									v6 = _sessionInsertRow(tls, db, *(*uintptr)(unsafe.Pointer(bp)), bp+4)
									rc = v6
								}
								if v7 || v6 != 0 {
									break
								}
								(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbStat1 = 0
							}
						}
					}
				}
				nTab = _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		/* If there is a schema mismatch on the current table, proceed to the
		 ** next change. A log message has already been issued. */
		if schemaMismatch != 0 {
			continue
		}
		rc = _sessionApplyOneWithRetry(tls, db, pIter, bp+4, xConflict, pCtx)
	}
	bPatchset = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset
	if rc == SQLITE_OK {
		rc = Xsqlite3changeset_finalize(tls, pIter)
	} else {
		Xsqlite3changeset_finalize(tls, pIter)
	}
	if rc == SQLITE_OK {
		rc = _sessionRetryConstraints(tls, db, bPatchset, *(*uintptr)(unsafe.Pointer(bp)), bp+4, xConflict, pCtx)
	}
	if rc == SQLITE_OK {
		Xsqlite3_db_status(tls, db, int32(SQLITE_DBSTATUS_DEFERRED_FKS), bp+100, bp+104, 0)
		if *(*int32)(unsafe.Pointer(bp + 100)) != 0 {
			res = int32(SQLITE_CHANGESET_ABORT)
			libc.Xmemset(tls, bp+108, 0, uint32(100))
			(*(*Tsqlite3_changeset_iter)(unsafe.Pointer(bp + 108))).FnCol = *(*int32)(unsafe.Pointer(bp + 100))
			res = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xConflict})))(tls, pCtx, int32(SQLITE_CHANGESET_FOREIGN_KEY), bp+108)
			if res != SQLITE_CHANGESET_OMIT {
				rc = int32(SQLITE_CONSTRAINT)
			}
		}
	}
	Xsqlite3_exec(tls, db, __ccgo_ts+36119, uintptr(0), uintptr(0), uintptr(0))
	if flags&int32(SQLITE_CHANGESETAPPLY_NOSAVEPOINT) == 0 {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, db, __ccgo_ts+36149, uintptr(0), uintptr(0), uintptr(0))
		} else {
			Xsqlite3_exec(tls, db, __ccgo_ts+36173, uintptr(0), uintptr(0), uintptr(0))
			Xsqlite3_exec(tls, db, __ccgo_ts+36149, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	if rc == SQLITE_OK && bPatchset == 0 && (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FbRebase != 0 {
		*(*uintptr)(unsafe.Pointer(ppRebase)) = (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).Frebase.FaBuf
		*(*int32)(unsafe.Pointer(pnRebase)) = (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).Frebase.FnBuf
		(*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).Frebase.FaBuf = uintptr(0)
	}
	_sessionUpdateFree(tls, bp+4)
	Xsqlite3_finalize(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpInsert)
	Xsqlite3_finalize(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpDelete)
	Xsqlite3_finalize(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FpSelect)
	Xsqlite3_free(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).FazCol) /* cast works around VC++ bug */
	Xsqlite3_free(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).Fconstraints.FaBuf)
	Xsqlite3_free(tls, (*(*TSessionApplyCtx)(unsafe.Pointer(bp + 4))).Frebase.FaBuf)
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	return rc
}

// C documentation
//
//	/*
//	** Apply the changeset passed via pChangeset/nChangeset to the main
//	** database attached to handle "db".
//	*/
func Xsqlite3changeset_apply_v2(tls *libc.TLS, db uintptr, nChangeset int32, pChangeset uintptr, xFilter uintptr, xConflict uintptr, pCtx uintptr, ppRebase uintptr, pnRebase uintptr, flags int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bInv, rc int32
	var savedFlag Tu64
	var _ /* pIter at bp+0 */ uintptr
	_, _, _ = bInv, rc, savedFlag /* Iterator to skip through changeset */
	bInv = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_INVERT) != 0))
	rc = _sessionChangesetStart(tls, bp, uintptr(0), uintptr(0), nChangeset, pChangeset, bInv, int32(1))
	savedFlag = (*Tsqlite3)(unsafe.Pointer(db)).Fflags & (uint64(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32))
	if flags&int32(SQLITE_CHANGESETAPPLY_FKNOACTION) != 0 {
		*(*Tu64)(unsafe.Pointer(db + 32)) |= uint64(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32)
		*(*int32)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)) -= int32(32)
	}
	if rc == SQLITE_OK {
		rc = _sessionChangesetApply(tls, db, *(*uintptr)(unsafe.Pointer(bp)), xFilter, xConflict, pCtx, ppRebase, pnRebase, flags)
	}
	if flags&int32(SQLITE_CHANGESETAPPLY_FKNOACTION) != 0 && savedFlag == uint64(0) {
		*(*Tu64)(unsafe.Pointer(db + 32)) &= ^(uint64(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32))
		*(*int32)(unsafe.Pointer((*(*TDb)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)) -= int32(32)
	}
	return rc
}

// C documentation
//
//	/*
//	** Apply the changeset passed via pChangeset/nChangeset to the main database
//	** attached to handle "db". Invoke the supplied conflict handler callback
//	** to resolve any conflicts encountered while applying the change.
//	*/
func Xsqlite3changeset_apply(tls *libc.TLS, db uintptr, nChangeset int32, pChangeset uintptr, xFilter uintptr, xConflict uintptr, pCtx uintptr) (r int32) {
	return Xsqlite3changeset_apply_v2(tls, db, nChangeset, pChangeset, xFilter, xConflict, pCtx, uintptr(0), uintptr(0), 0)
}

// C documentation
//
//	/*
//	** Apply the changeset passed via xInput/pIn to the main database
//	** attached to handle "db". Invoke the supplied conflict handler callback
//	** to resolve any conflicts encountered while applying the change.
//	*/
func Xsqlite3changeset_apply_v2_strm(tls *libc.TLS, db uintptr, xInput uintptr, pIn uintptr, xFilter uintptr, xConflict uintptr, pCtx uintptr, ppRebase uintptr, pnRebase uintptr, flags int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bInverse, rc int32
	var _ /* pIter at bp+0 */ uintptr
	_, _ = bInverse, rc /* Iterator to skip through changeset */
	bInverse = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_INVERT) != 0))
	rc = _sessionChangesetStart(tls, bp, xInput, pIn, 0, uintptr(0), bInverse, int32(1))
	if rc == SQLITE_OK {
		rc = _sessionChangesetApply(tls, db, *(*uintptr)(unsafe.Pointer(bp)), xFilter, xConflict, pCtx, ppRebase, pnRebase, flags)
	}
	return rc
}

func Xsqlite3changeset_apply_strm(tls *libc.TLS, db uintptr, xInput uintptr, pIn uintptr, xFilter uintptr, xConflict uintptr, pCtx uintptr) (r int32) {
	return Xsqlite3changeset_apply_v2_strm(tls, db, xInput, pIn, xFilter, xConflict, pCtx, uintptr(0), uintptr(0), 0)
}

/*
** sqlite3_changegroup handle.
 */
type Tsqlite3_changegroup1 = struct {
	Frc     int32
	FbPatch int32
	FpList  uintptr
	Frec    TSessionBuffer
	Fdb     uintptr
	FzDb    uintptr
}

type sqlite3_changegroup1 = Tsqlite3_changegroup1

// C documentation
//
//	/*
//	** This function is called to merge two changes to the same row together as
//	** part of an sqlite3changeset_concat() operation. A new change object is
//	** allocated and a pointer to it stored in *ppNew.
//	*/
func _sessionChangeMerge(tls *libc.TLS, pTab uintptr, bRebase int32, bPatchset int32, pExist uintptr, op2 int32, bIndirect int32, aRec uintptr, nRec int32, ppNew uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a1, a2, aExist, pIn, pNew, pOut, pOut1, v2, v3, v4, v6, v7 uintptr
	var i, i1, n1, n2, nIn, op1, rc int32
	var nByte, nByte1 Tsqlite3_int64
	var _ /* a1 at bp+4 */ uintptr
	var _ /* a1 at bp+8 */ uintptr
	var _ /* a2 at bp+12 */ uintptr
	var _ /* aCsr at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a1, a2, aExist, i, i1, n1, n2, nByte, nByte1, nIn, op1, pIn, pNew, pOut, pOut1, rc, v2, v3, v4, v6, v7
	pNew = uintptr(0)
	rc = SQLITE_OK
	if !(pExist != 0) {
		pNew = Xsqlite3_malloc64(tls, uint64(uint32(20)+uint32(uint32(nRec))))
		if !(pNew != 0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint32(20))
		(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(uint8(op2))
		(*TSessionChange)(unsafe.Pointer(pNew)).FbIndirect = uint8(uint8(bIndirect))
		(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = pNew + 1*20
		if bIndirect == 0 || bRebase == 0 {
			(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = nRec
			libc.Xmemcpy(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord, aRec, uint32(uint32(nRec)))
		} else {
			pIn = aRec
			pOut = (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord
			i = 0
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
					break
				}
				nIn = _sessionSerialLen(tls, pIn)
				if int32(*(*Tu8)(unsafe.Pointer(pIn))) == 0 {
					v2 = pOut
					pOut++
					*(*Tu8)(unsafe.Pointer(v2)) = uint8(0)
				} else {
					if int32(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i)))) == 0 {
						v3 = pOut
						pOut++
						*(*Tu8)(unsafe.Pointer(v3)) = uint8(0xFF)
					} else {
						libc.Xmemcpy(tls, pOut, pIn, uint32(uint32(nIn)))
						pOut += uintptr(nIn)
					}
				}
				pIn += uintptr(nIn)
				goto _1
			_1:
				;
				i++
			}
			(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = int32(int32(pOut)) - int32((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord)
		}
	} else {
		if bRebase != 0 {
			if int32((*TSessionChange)(unsafe.Pointer(pExist)).Fop) == int32(SQLITE_DELETE) && (*TSessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0 {
				*(*uintptr)(unsafe.Pointer(ppNew)) = pExist
			} else {
				nByte = int64(uint32(nRec+(*TSessionChange)(unsafe.Pointer(pExist)).FnRecord) + uint32(20))
				pNew = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
				if pNew == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				} else {
					a1 = (*TSessionChange)(unsafe.Pointer(pExist)).FaRecord
					a2 = aRec
					libc.Xmemset(tls, pNew, 0, uint32(uint32(nByte)))
					(*TSessionChange)(unsafe.Pointer(pNew)).FbIndirect = libc.BoolUint8(bIndirect != 0 || (*TSessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0)
					(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(uint8(op2))
					v4 = pNew + 1*20
					(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = v4
					pOut1 = v4
					i1 = 0
					for {
						if !(i1 < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
							break
						}
						n1 = _sessionSerialLen(tls, a1)
						n2 = _sessionSerialLen(tls, a2)
						if int32(*(*Tu8)(unsafe.Pointer(a1))) == int32(0xFF) || int32(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i1)))) == 0 && bIndirect != 0 {
							v6 = pOut1
							pOut1++
							*(*Tu8)(unsafe.Pointer(v6)) = uint8(0xFF)
						} else {
							if int32(*(*Tu8)(unsafe.Pointer(a2))) == 0 {
								libc.Xmemcpy(tls, pOut1, a1, uint32(uint32(n1)))
								pOut1 += uintptr(n1)
							} else {
								libc.Xmemcpy(tls, pOut1, a2, uint32(uint32(n2)))
								pOut1 += uintptr(n2)
							}
						}
						a1 += uintptr(n1)
						a2 += uintptr(n2)
						goto _5
					_5:
						;
						i1++
					}
					(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = int32(int32(pOut1)) - int32((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord)
				}
				Xsqlite3_free(tls, pExist)
			}
		} else {
			op1 = int32((*TSessionChange)(unsafe.Pointer(pExist)).Fop)
			/*
			 **   op1=INSERT, op2=INSERT      ->      Unsupported. Discard op2.
			 **   op1=INSERT, op2=UPDATE      ->      INSERT.
			 **   op1=INSERT, op2=DELETE      ->      (none)
			 **
			 **   op1=UPDATE, op2=INSERT      ->      Unsupported. Discard op2.
			 **   op1=UPDATE, op2=UPDATE      ->      UPDATE.
			 **   op1=UPDATE, op2=DELETE      ->      DELETE.
			 **
			 **   op1=DELETE, op2=INSERT      ->      UPDATE.
			 **   op1=DELETE, op2=UPDATE      ->      Unsupported. Discard op2.
			 **   op1=DELETE, op2=DELETE      ->      Unsupported. Discard op2.
			 */
			if op1 == int32(SQLITE_INSERT) && op2 == int32(SQLITE_INSERT) || op1 == int32(SQLITE_UPDATE) && op2 == int32(SQLITE_INSERT) || op1 == int32(SQLITE_DELETE) && op2 == int32(SQLITE_UPDATE) || op1 == int32(SQLITE_DELETE) && op2 == int32(SQLITE_DELETE) {
				pNew = pExist
			} else {
				if op1 == int32(SQLITE_INSERT) && op2 == int32(SQLITE_DELETE) {
					Xsqlite3_free(tls, pExist)
				} else {
					aExist = (*TSessionChange)(unsafe.Pointer(pExist)).FaRecord
					/* Allocate a new SessionChange object. Ensure that the aRecord[]
					 ** buffer of the new object is large enough to hold any record that
					 ** may be generated by combining the input records.  */
					nByte1 = int64(uint32(20) + uint32((*TSessionChange)(unsafe.Pointer(pExist)).FnRecord) + uint32(uint32(nRec)))
					pNew = Xsqlite3_malloc64(tls, uint64(uint64(nByte1)))
					if !(pNew != 0) {
						Xsqlite3_free(tls, pExist)
						return int32(SQLITE_NOMEM)
					}
					libc.Xmemset(tls, pNew, 0, uint32(20))
					(*TSessionChange)(unsafe.Pointer(pNew)).FbIndirect = libc.BoolUint8(bIndirect != 0 && (*TSessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0)
					v7 = pNew + 1*20
					(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = v7
					*(*uintptr)(unsafe.Pointer(bp)) = v7
					if op1 == int32(SQLITE_INSERT) { /* INSERT + UPDATE */
						*(*uintptr)(unsafe.Pointer(bp + 4)) = aRec
						(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_INSERT)
						if bPatchset == 0 {
							_sessionSkipRecord(tls, bp+4, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
						}
						_sessionMergeRecord(tls, bp, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, aExist, *(*uintptr)(unsafe.Pointer(bp + 4)))
					} else {
						if op1 == int32(SQLITE_DELETE) { /* DELETE + INSERT */
							(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_UPDATE)
							if bPatchset != 0 {
								libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp)), aRec, uint32(uint32(nRec)))
								*(*uintptr)(unsafe.Pointer(bp)) += uintptr(nRec)
							} else {
								if 0 == _sessionMergeUpdate(tls, bp, pTab, bPatchset, aExist, uintptr(0), aRec, uintptr(0)) {
									Xsqlite3_free(tls, pNew)
									pNew = uintptr(0)
								}
							}
						} else {
							if op2 == int32(SQLITE_UPDATE) { /* UPDATE + UPDATE */
								*(*uintptr)(unsafe.Pointer(bp + 8)) = aExist
								*(*uintptr)(unsafe.Pointer(bp + 12)) = aRec
								if bPatchset == 0 {
									_sessionSkipRecord(tls, bp+8, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
									_sessionSkipRecord(tls, bp+12, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
								}
								(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_UPDATE)
								if 0 == _sessionMergeUpdate(tls, bp, pTab, bPatchset, aRec, aExist, *(*uintptr)(unsafe.Pointer(bp + 8)), *(*uintptr)(unsafe.Pointer(bp + 12))) {
									Xsqlite3_free(tls, pNew)
									pNew = uintptr(0)
								}
							} else { /* UPDATE + DELETE */
								(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_DELETE)
								if bPatchset != 0 {
									libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp)), aRec, uint32(uint32(nRec)))
									*(*uintptr)(unsafe.Pointer(bp)) += uintptr(nRec)
								} else {
									_sessionMergeRecord(tls, bp, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, aRec, aExist)
								}
							}
						}
					}
					if pNew != 0 {
						(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = int32(*(*uintptr)(unsafe.Pointer(bp))) - int32((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord)
					}
					Xsqlite3_free(tls, pExist)
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppNew)) = pNew
	return rc
}

// C documentation
//
//	/*
//	** Check if a changeset entry with nCol columns and the PK array passed
//	** as the final argument to this function is compatible with SessionTable
//	** pTab. If so, return 1. Otherwise, if they are incompatible in some way,
//	** return 0.
//	*/
func _sessionChangesetCheckCompat(tls *libc.TLS, pTab uintptr, nCol int32, abPK uintptr) (r int32) {
	var bPK Tu8
	var ii, v2 int32
	_, _, _ = bPK, ii, v2
	if (*TSessionTable)(unsafe.Pointer(pTab)).FazCol != 0 && nCol < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol {
		ii = 0
		for {
			if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
				break
			}
			if ii < nCol {
				v2 = int32(*(*Tu8)(unsafe.Pointer(abPK + uintptr(ii))))
			} else {
				v2 = 0
			}
			bPK = uint8(v2)
			if int32(*(*Tu8)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii)))) != int32(int32(bPK)) {
				return 0
			}
			goto _1
		_1:
			;
			ii++
		}
		return int32(1)
	}
	return libc.BoolInt32((*TSessionTable)(unsafe.Pointer(pTab)).FnCol == nCol && 0 == libc.Xmemcmp(tls, abPK, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, uint32(uint32(nCol))))
}

func _sessionChangesetExtendRecord(tls *libc.TLS, pGrp uintptr, pTab uintptr, nCol int32, op int32, aRec uintptr, nRec int32, pOut uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eType, iOff, ii, n int32
	var z, z1 uintptr
	var _ /* iVal at bp+8 */ Ti64
	var _ /* rVal at bp+16 */ float64
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _ = eType, iOff, ii, n, z, z1
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	ii = 0
	(*TSessionBuffer)(unsafe.Pointer(pOut)).FnBuf = 0
	if op == int32(SQLITE_INSERT) || op == int32(SQLITE_DELETE) && (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 {
		/* Append the missing default column values to the record. */
		_sessionAppendBlob(tls, pOut, aRec, nRec, bp)
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp)) = _sessionPrepareDfltStmt(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb, pTab, pTab+44)
		}
		ii = nCol
		for {
			if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
				break
			}
			eType = Xsqlite3_column_type(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt, ii)
			_sessionAppendByte(tls, pOut, uint8(uint8(eType)), bp)
			switch eType {
			case int32(SQLITE_FLOAT):
				fallthrough
			case int32(SQLITE_INTEGER):
				if eType == int32(SQLITE_INTEGER) {
					*(*Ti64)(unsafe.Pointer(bp + 8)) = Xsqlite3_column_int64(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt, ii)
				} else {
					*(*float64)(unsafe.Pointer(bp + 16)) = float64(Xsqlite3_column_int64(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt, ii))
					libc.Xmemcpy(tls, bp+8, bp+16, uint32(8))
				}
				if SQLITE_OK == _sessionBufferGrow(tls, pOut, int64(8), bp) {
					_sessionPutI64(tls, (*TSessionBuffer)(unsafe.Pointer(pOut)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(pOut)).FnBuf), *(*Ti64)(unsafe.Pointer(bp + 8)))
				}
			case int32(SQLITE_BLOB):
				fallthrough
			case int32(SQLITE_TEXT):
				n = Xsqlite3_column_bytes(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt, ii)
				_sessionAppendVarint(tls, pOut, n, bp)
				if eType == int32(SQLITE_TEXT) {
					z = Xsqlite3_column_text(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt, ii)
					_sessionAppendBlob(tls, pOut, z, n, bp)
				} else {
					z1 = Xsqlite3_column_blob(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt, ii)
					_sessionAppendBlob(tls, pOut, z1, n, bp)
				}
			default:
				break
			}
			goto _1
		_1:
			;
			ii++
		}
	} else {
		if op == int32(SQLITE_UPDATE) {
			/* Append missing "undefined" entries to the old.* record. And, if this
			 ** is an UPDATE, to the new.* record as well.  */
			iOff = 0
			if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 {
				ii = 0
				for {
					if !(ii < nCol) {
						break
					}
					iOff += _sessionSerialLen(tls, aRec+uintptr(iOff))
					goto _2
				_2:
					;
					ii++
				}
				_sessionAppendBlob(tls, pOut, aRec, iOff, bp)
				ii = 0
				for {
					if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol-nCol) {
						break
					}
					_sessionAppendByte(tls, pOut, uint8(0x00), bp)
					goto _3
				_3:
					;
					ii++
				}
			}
			_sessionAppendBlob(tls, pOut, aRec+uintptr(iOff), nRec-iOff, bp)
			ii = 0
			for {
				if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol-nCol) {
					break
				}
				_sessionAppendByte(tls, pOut, uint8(0x00), bp)
				goto _4
			_4:
				;
				ii++
			}
		} else {
			_sessionAppendBlob(tls, pOut, aRec, nRec, bp)
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Locate or create a SessionTable object that may be used to add the
//	** change currently pointed to by iterator pIter to changegroup pGrp.
//	** If successful, set output variable (*ppTab) to point to the table
//	** object and return SQLITE_OK. Otherwise, if some error occurs, return
//	** an SQLite error code and leave (*ppTab) set to NULL.
//	*/
func _sessionChangesetFindTable(tls *libc.TLS, pGrp uintptr, zTab uintptr, pIter uintptr, ppTab uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nTab, rc int32
	var pTab, ppNew uintptr
	var _ /* abPK at bp+0 */ uintptr
	var _ /* nCol at bp+4 */ int32
	_, _, _, _ = nTab, pTab, ppNew, rc
	rc = SQLITE_OK
	pTab = uintptr(0)
	nTab = int32(libc.Xstrlen(tls, zTab))
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	*(*uintptr)(unsafe.Pointer(ppTab)) = uintptr(0)
	Xsqlite3changeset_pk(tls, pIter, bp, bp+4)
	/* Search the list for an existing table */
	pTab = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList
	for {
		if !(pTab != 0) {
			break
		}
		if 0 == Xsqlite3_strnicmp(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zTab, nTab+int32(1)) {
			break
		}
		goto _1
	_1:
		;
		pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
	}
	/* If one was not found above, create a new table now */
	if !(pTab != 0) {
		pTab = Xsqlite3_malloc64(tls, uint64(uint32(48)+uint32(*(*int32)(unsafe.Pointer(bp + 4)))+uint32(uint32(nTab))+uint32(1)))
		if !(pTab != 0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pTab, 0, uint32(48))
		(*TSessionTable)(unsafe.Pointer(pTab)).FnCol = *(*int32)(unsafe.Pointer(bp + 4))
		(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = pTab + 1*48
		libc.Xmemcpy(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, *(*uintptr)(unsafe.Pointer(bp)), uint32(*(*int32)(unsafe.Pointer(bp + 4))))
		(*TSessionTable)(unsafe.Pointer(pTab)).FzName = (*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(*(*int32)(unsafe.Pointer(bp + 4)))
		libc.Xmemcpy(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zTab, uint32(nTab+int32(1)))
		if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb != 0 {
			(*TSessionTable)(unsafe.Pointer(pTab)).FnCol = 0
			rc = _sessionInitTable(tls, uintptr(0), pTab, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb)
			if rc != 0 {
				Xsqlite3_free(tls, pTab)
				return rc
			}
		}
		/* The new object must be linked on to the end of the list, not
		 ** simply added to the start of it. This is to ensure that the
		 ** tables within the output of sqlite3changegroup_output() are in
		 ** the right order.  */
		ppNew = pGrp + 8
		for {
			if !(*(*uintptr)(unsafe.Pointer(ppNew)) != 0) {
				break
			}
			goto _2
		_2:
			;
			ppNew = *(*uintptr)(unsafe.Pointer(ppNew))
		}
		*(*uintptr)(unsafe.Pointer(ppNew)) = pTab
	}
	/* Check that the table is compatible. */
	if !(_sessionChangesetCheckCompat(tls, pTab, *(*int32)(unsafe.Pointer(bp + 4)), *(*uintptr)(unsafe.Pointer(bp))) != 0) {
		rc = int32(SQLITE_SCHEMA)
	}
	*(*uintptr)(unsafe.Pointer(ppTab)) = pTab
	return rc
}

// C documentation
//
//	/*
//	** Add the change currently indicated by iterator pIter to the hash table
//	** belonging to changegroup pGrp.
//	*/
func _sessionOneChangeToHash(tls *libc.TLS, pGrp uintptr, pIter uintptr, bRebase int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aRec, pBuf, pExist, pp uintptr
	var bPkOnly1, bPkOnly2, iHash, nRec, rc int32
	var _ /* bIndirect at bp+8 */ int32
	var _ /* nCol at bp+0 */ int32
	var _ /* op at bp+4 */ int32
	var _ /* pChange at bp+12 */ uintptr
	var _ /* pTab at bp+16 */ uintptr
	var _ /* zTab at bp+20 */ uintptr
	_, _, _, _, _, _, _, _, _ = aRec, bPkOnly1, bPkOnly2, iHash, nRec, pBuf, pExist, pp, rc
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	iHash = 0
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
	pExist = uintptr(0)
	pp = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	aRec = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FaData + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent+int32(2))
	nRec = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiNext - (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent - int32(2)
	/* Ensure that only changesets, or only patchsets, but not a mixture
	 ** of both, are being combined. It is an error to try to combine a
	 ** changeset and a patchset.  */
	if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList == uintptr(0) {
		(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset
	} else {
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch {
			rc = int32(SQLITE_ERROR)
		}
	}
	if rc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(bp + 20)) = uintptr(0)
		Xsqlite3changeset_op(tls, pIter, bp+20, bp, bp+4, bp+8)
		rc = _sessionChangesetFindTable(tls, pGrp, *(*uintptr)(unsafe.Pointer(bp + 20)), pIter, bp+16)
	}
	if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) < (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FnCol {
		pBuf = pGrp + 12
		rc = _sessionChangesetExtendRecord(tls, pGrp, *(*uintptr)(unsafe.Pointer(bp + 16)), *(*int32)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)), aRec, nRec, pBuf)
		aRec = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf
		nRec = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf
	}
	if rc == SQLITE_OK && _sessionGrowHash(tls, uintptr(0), (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, *(*uintptr)(unsafe.Pointer(bp + 16))) != 0 {
		rc = int32(SQLITE_NOMEM)
	}
	if rc == SQLITE_OK {
		/* Search for existing entry. If found, remove it from the hash table.
		 ** Code below may link it back in.  */
		iHash = int32(_sessionChangeHash(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), libc.BoolInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 && *(*int32)(unsafe.Pointer(bp + 4)) == int32(SQLITE_DELETE)), aRec, (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FnChange))
		pp = (*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FapChange + uintptr(iHash)*4
		for {
			if !(*(*uintptr)(unsafe.Pointer(pp)) != 0) {
				break
			}
			bPkOnly1 = 0
			bPkOnly2 = 0
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
				bPkOnly1 = libc.BoolInt32(int32((*TSessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).Fop) == int32(SQLITE_DELETE))
				bPkOnly2 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp + 4)) == int32(SQLITE_DELETE))
			}
			if _sessionChangeEqual(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), bPkOnly1, (*TSessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FaRecord, bPkOnly2, aRec) != 0 {
				pExist = *(*uintptr)(unsafe.Pointer(pp))
				*(*uintptr)(unsafe.Pointer(pp)) = (*TSessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext
				(*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FnEntry--
				break
			}
			goto _1
		_1:
			;
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 16
		}
	}
	if rc == SQLITE_OK {
		rc = _sessionChangeMerge(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), bRebase, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, pExist, *(*int32)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp + 8)), aRec, nRec, bp+12)
	}
	if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 12)) != 0 {
		(*TSessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FpNext = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FapChange + uintptr(iHash)*4))
		*(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FapChange + uintptr(iHash)*4)) = *(*uintptr)(unsafe.Pointer(bp + 12))
		(*TSessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FnEntry++
	}
	if rc == SQLITE_OK {
		rc = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Frc
	}
	return rc
}

// C documentation
//
//	/*
//	** Add all changes in the changeset traversed by the iterator passed as
//	** the first argument to the changegroup hash tables.
//	*/
func _sessionChangesetToHash(tls *libc.TLS, pIter uintptr, pGrp uintptr, bRebase int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* aRec at bp+0 */ uintptr
	var _ /* nRec at bp+4 */ int32
	_ = rc
	rc = SQLITE_OK
	for int32(SQLITE_ROW) == _sessionChangesetNext(tls, pIter, bp, bp+4, uintptr(0)) {
		rc = _sessionOneChangeToHash(tls, pGrp, pIter, bRebase)
		if rc != SQLITE_OK {
			break
		}
	}
	if rc == SQLITE_OK {
		rc = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Frc
	}
	return rc
}

// C documentation
//
//	/*
//	** Serialize a changeset (or patchset) based on all changesets (or patchsets)
//	** added to the changegroup object passed as the first argument.
//	**
//	** If xOutput is not NULL, then the changeset/patchset is returned to the
//	** user via one or more calls to xOutput, as with the other streaming
//	** interfaces.
//	**
//	** Or, if xOutput is NULL, then (*ppOut) is populated with a pointer to a
//	** buffer containing the output changeset before this function returns. In
//	** this case (*pnOut) is set to the size of the output buffer in bytes. It
//	** is the responsibility of the caller to free the output buffer using
//	** sqlite3_free() when it is no longer required.
//	**
//	** If successful, SQLITE_OK is returned. Or, if an error occurs, an SQLite
//	** error code. If an error occurs and xOutput is NULL, (*ppOut) and (*pnOut)
//	** are both set to 0 before returning.
//	*/
func _sessionChangegroupOutput(tls *libc.TLS, pGrp uintptr, xOutput uintptr, pOut uintptr, pnOut uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var p, pTab uintptr
	var _ /* buf at bp+4 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _ = i, p, pTab
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*TSessionBuffer)(unsafe.Pointer(bp + 4)) = TSessionBuffer{}
	/* Create the serialized output changeset based on the contents of the
	 ** hash tables attached to the SessionTable objects in list p->pList.
	 */
	pTab = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && pTab != 0) {
			break
		}
		if (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry == 0 {
			goto _1
		}
		_sessionAppendTableHdr(tls, bp+4, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch, pTab, bp)
		i = 0
		for {
			if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange) {
				break
			}
			p = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*4))
			for {
				if !(p != 0) {
					break
				}
				_sessionAppendByte(tls, bp+4, (*TSessionChange)(unsafe.Pointer(p)).Fop, bp)
				_sessionAppendByte(tls, bp+4, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp)
				_sessionAppendBlob(tls, bp+4, (*TSessionChange)(unsafe.Pointer(p)).FaRecord, (*TSessionChange)(unsafe.Pointer(p)).FnRecord, bp)
				if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && xOutput != 0 && (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf >= _sessions_strm_chunk_size {
					*(*int32)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf)
					(*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf = 0
				}
				goto _3
			_3:
				;
				p = (*TSessionChange)(unsafe.Pointer(p)).FpNext
			}
			goto _2
		_2:
			;
			i++
		}
		goto _1
	_1:
		;
		pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		if xOutput != 0 {
			if (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf > 0 {
				*(*int32)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf)
			}
		} else {
			if ppOut != 0 {
				*(*uintptr)(unsafe.Pointer(ppOut)) = (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf
				if pnOut != 0 {
					*(*int32)(unsafe.Pointer(pnOut)) = (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FnBuf
				}
				(*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf = uintptr(0)
			}
		}
	}
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 4))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Allocate a new, empty, sqlite3_changegroup.
//	*/
func Xsqlite3changegroup_new(tls *libc.TLS, pp uintptr) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	rc = SQLITE_OK /* New object */
	p = Xsqlite3_malloc(tls, int32(32))
	if p == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, p, 0, uint32(32))
	}
	*(*uintptr)(unsafe.Pointer(pp)) = p
	return rc
}

// C documentation
//
//	/*
//	** Provide a database schema to the changegroup object.
//	*/
func Xsqlite3changegroup_schema(tls *libc.TLS, pGrp uintptr, db uintptr, zDb uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList != 0 || (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb != 0 {
		/* Cannot add a schema after one or more calls to sqlite3changegroup_add(),
		 ** or after sqlite3changegroup_schema() has already been called. */
		rc = int32(SQLITE_MISUSE)
	} else {
		(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, zDb))
		if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb = db
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Add the changeset currently stored in buffer pData, size nData bytes,
//	** to changeset-group p.
//	*/
func Xsqlite3changegroup_add(tls *libc.TLS, pGrp uintptr, nData int32, pData uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pIter at bp+0 */ uintptr
	_ = rc /* Return code */
	rc = Xsqlite3changeset_start(tls, bp, nData, pData)
	if rc == SQLITE_OK {
		rc = _sessionChangesetToHash(tls, *(*uintptr)(unsafe.Pointer(bp)), pGrp, 0)
	}
	Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

// C documentation
//
//	/*
//	** Add a single change to a changeset-group.
//	*/
func Xsqlite3changegroup_add_change(tls *libc.TLS, pGrp uintptr, pIter uintptr) (r int32) {
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent == (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiNext || (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Frc != SQLITE_OK || (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbInvert != 0 {
		/* Iterator does not point to any valid entry or is an INVERT iterator. */
		return int32(SQLITE_ERROR)
	}
	return _sessionOneChangeToHash(tls, pGrp, pIter, 0)
}

// C documentation
//
//	/*
//	** Obtain a buffer containing a changeset representing the concatenation
//	** of all changesets added to the group so far.
//	*/
func Xsqlite3changegroup_output(tls *libc.TLS, pGrp uintptr, pnData uintptr, ppData uintptr) (r int32) {
	return _sessionChangegroupOutput(tls, pGrp, uintptr(0), uintptr(0), pnData, ppData)
}

// C documentation
//
//	/*
//	** Streaming versions of changegroup_add().
//	*/
func Xsqlite3changegroup_add_strm(tls *libc.TLS, pGrp uintptr, xInput uintptr, pIn uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pIter at bp+0 */ uintptr
	_ = rc /* Return code */
	rc = Xsqlite3changeset_start_strm(tls, bp, xInput, pIn)
	if rc == SQLITE_OK {
		rc = _sessionChangesetToHash(tls, *(*uintptr)(unsafe.Pointer(bp)), pGrp, 0)
	}
	Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

// C documentation
//
//	/*
//	** Streaming versions of changegroup_output().
//	*/
func Xsqlite3changegroup_output_strm(tls *libc.TLS, pGrp uintptr, xOutput uintptr, pOut uintptr) (r int32) {
	return _sessionChangegroupOutput(tls, pGrp, xOutput, pOut, uintptr(0), uintptr(0))
}

// C documentation
//
//	/*
//	** Delete a changegroup object.
//	*/
func Xsqlite3changegroup_delete(tls *libc.TLS, pGrp uintptr) {
	if pGrp != 0 {
		Xsqlite3_free(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb)
		_sessionDeleteTable(tls, uintptr(0), (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList)
		Xsqlite3_free(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Frec.FaBuf)
		Xsqlite3_free(tls, pGrp)
	}
}

// C documentation
//
//	/*
//	** Combine two changesets together.
//	*/
func Xsqlite3changeset_concat(tls *libc.TLS, nLeft int32, pLeft uintptr, nRight int32, pRight uintptr, pnOut uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pGrp at bp+0 */ uintptr
	_ = rc
	rc = Xsqlite3changegroup_new(tls, bp)
	if rc == SQLITE_OK {
		rc = Xsqlite3changegroup_add(tls, *(*uintptr)(unsafe.Pointer(bp)), nLeft, pLeft)
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3changegroup_add(tls, *(*uintptr)(unsafe.Pointer(bp)), nRight, pRight)
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3changegroup_output(tls, *(*uintptr)(unsafe.Pointer(bp)), pnOut, ppOut)
	}
	Xsqlite3changegroup_delete(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

// C documentation
//
//	/*
//	** Streaming version of sqlite3changeset_concat().
//	*/
func Xsqlite3changeset_concat_strm(tls *libc.TLS, xInputA uintptr, pInA uintptr, xInputB uintptr, pInB uintptr, xOutput uintptr, pOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pGrp at bp+0 */ uintptr
	_ = rc
	rc = Xsqlite3changegroup_new(tls, bp)
	if rc == SQLITE_OK {
		rc = Xsqlite3changegroup_add_strm(tls, *(*uintptr)(unsafe.Pointer(bp)), xInputA, pInA)
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3changegroup_add_strm(tls, *(*uintptr)(unsafe.Pointer(bp)), xInputB, pInB)
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3changegroup_output_strm(tls, *(*uintptr)(unsafe.Pointer(bp)), xOutput, pOut)
	}
	Xsqlite3changegroup_delete(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

/*
** Changeset rebaser handle.
 */
type Tsqlite3_rebaser1 = struct {
	Fgrp Tsqlite3_changegroup
}

type sqlite3_rebaser1 = Tsqlite3_rebaser1

// C documentation
//
//	/*
//	** Buffers a1 and a2 must both contain a sessions module record nCol
//	** fields in size. This function appends an nCol sessions module
//	** record to buffer pBuf that is a copy of a1, except that for
//	** each field that is undefined in a1[], swap in the field from a2[].
//	*/
func _sessionAppendRecordMerge(tls *libc.TLS, pBuf uintptr, nCol int32, a1 uintptr, n1 int32, a2 uintptr, n2 int32, pRc uintptr) {
	var i, nn1, nn2 int32
	var pOut uintptr
	_, _, _, _ = i, nn1, nn2, pOut
	_sessionBufferGrow(tls, pBuf, int64(n1+n2), pRc)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		pOut = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf)
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			nn1 = _sessionSerialLen(tls, a1)
			nn2 = _sessionSerialLen(tls, a2)
			if int32(*(*Tu8)(unsafe.Pointer(a1))) == 0 || int32(*(*Tu8)(unsafe.Pointer(a1))) == int32(0xFF) {
				libc.Xmemcpy(tls, pOut, a2, uint32(uint32(nn2)))
				pOut += uintptr(nn2)
			} else {
				libc.Xmemcpy(tls, pOut, a1, uint32(uint32(nn1)))
				pOut += uintptr(nn1)
			}
			a1 += uintptr(nn1)
			a2 += uintptr(nn2)
			goto _1
		_1:
			;
			i++
		}
		(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = int32(int32(pOut)) - int32((*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf)
	}
}

// C documentation
//
//	/*
//	** This function is called when rebasing a local UPDATE change against one
//	** or more remote UPDATE changes. The aRec/nRec buffer contains the current
//	** old.* and new.* records for the change. The rebase buffer (a single
//	** record) is in aChange/nChange. The rebased change is appended to buffer
//	** pBuf.
//	**
//	** Rebasing the UPDATE involves:
//	**
//	**   * Removing any changes to fields for which the corresponding field
//	**     in the rebase buffer is set to "replaced" (type 0xFF). If this
//	**     means the UPDATE change updates no fields, nothing is appended
//	**     to the output buffer.
//	**
//	**   * For each field modified by the local change for which the
//	**     corresponding field in the rebase buffer is not "undefined" (0x00)
//	**     or "replaced" (0xFF), the old.* value is replaced by the value
//	**     in the rebase buffer.
//	*/
func _sessionAppendPartialUpdate(tls *libc.TLS, pBuf uintptr, pIter uintptr, aRec uintptr, nRec int32, aChange uintptr, nChange int32, pRc uintptr) {
	var a1, a2, pOut, v1, v2, v4, v6 uintptr
	var bData, i, n1, n11, n2, n21 int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = a1, a2, bData, i, n1, n11, n2, n21, pOut, v1, v2, v4, v6
	_sessionBufferGrow(tls, pBuf, int64(int32(2)+nRec+nChange), pRc)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		bData = 0
		pOut = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf)
		a1 = aRec
		a2 = aChange
		v1 = pOut
		pOut++
		*(*Tu8)(unsafe.Pointer(v1)) = uint8(SQLITE_UPDATE)
		v2 = pOut
		pOut++
		*(*Tu8)(unsafe.Pointer(v2)) = uint8((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect)
		i = 0
		for {
			if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
				break
			}
			n1 = _sessionSerialLen(tls, a1)
			n2 = _sessionSerialLen(tls, a2)
			if *(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0 || int32(*(*Tu8)(unsafe.Pointer(a2))) == 0 {
				if !(*(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0) && *(*Tu8)(unsafe.Pointer(a1)) != 0 {
					bData = int32(1)
				}
				libc.Xmemcpy(tls, pOut, a1, uint32(uint32(n1)))
				pOut += uintptr(n1)
			} else {
				if int32(*(*Tu8)(unsafe.Pointer(a2))) != int32(0xFF) && *(*Tu8)(unsafe.Pointer(a1)) != 0 {
					bData = int32(1)
					libc.Xmemcpy(tls, pOut, a2, uint32(uint32(n2)))
					pOut += uintptr(n2)
				} else {
					v4 = pOut
					pOut++
					*(*Tu8)(unsafe.Pointer(v4)) = uint8('\000')
				}
			}
			a1 += uintptr(n1)
			a2 += uintptr(n2)
			goto _3
		_3:
			;
			i++
		}
		if bData != 0 {
			a2 = aChange
			i = 0
			for {
				if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
					break
				}
				n11 = _sessionSerialLen(tls, a1)
				n21 = _sessionSerialLen(tls, a2)
				if *(*Tu8)(unsafe.Pointer((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0 || int32(*(*Tu8)(unsafe.Pointer(a2))) != int32(0xFF) {
					libc.Xmemcpy(tls, pOut, a1, uint32(uint32(n11)))
					pOut += uintptr(n11)
				} else {
					v6 = pOut
					pOut++
					*(*Tu8)(unsafe.Pointer(v6)) = uint8('\000')
				}
				a1 += uintptr(n11)
				a2 += uintptr(n21)
				goto _5
			_5:
				;
				i++
			}
			(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = int32(int32(pOut)) - int32((*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf)
		}
	}
}

// C documentation
//
//	/*
//	** pIter is configured to iterate through a changeset. This function rebases
//	** that changeset according to the current configuration of the rebaser
//	** object passed as the first argument. If no error occurs and argument xOutput
//	** is not NULL, then the changeset is returned to the caller by invoking
//	** xOutput zero or more times and SQLITE_OK returned. Or, if xOutput is NULL,
//	** then (*ppOut) is set to point to a buffer containing the rebased changeset
//	** before this function returns. In this case (*pnOut) is set to the size of
//	** the buffer in bytes.  It is the responsibility of the caller to eventually
//	** free the (*ppOut) buffer using sqlite3_free().
//	**
//	** If an error occurs, an SQLite error code is returned. If ppOut and
//	** pnOut are not NULL, then the two output parameters are set to 0 before
//	** returning.
//	*/
func _sessionRebase(tls *libc.TLS, p uintptr, pIter uintptr, xOutput uintptr, pOut uintptr, pnOut uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bDone, iHash, v2 int32
	var pChange, pTab, zTab uintptr
	var _ /* aRec at bp+4 */ uintptr
	var _ /* bNew at bp+12 */ int32
	var _ /* nRec at bp+8 */ int32
	var _ /* pCsr at bp+28 */ uintptr
	var _ /* rc at bp+0 */ int32
	var _ /* sOut at bp+16 */ TSessionBuffer
	_, _, _, _, _, _ = bDone, iHash, pChange, pTab, zTab, v2
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	*(*int32)(unsafe.Pointer(bp + 12)) = 0
	pTab = uintptr(0)
	*(*TSessionBuffer)(unsafe.Pointer(bp + 16)) = TSessionBuffer{}
	for int32(SQLITE_ROW) == _sessionChangesetNext(tls, pIter, bp+4, bp+8, bp+12) {
		pChange = uintptr(0)
		bDone = 0
		if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
			zTab = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab
			pTab = (*Tsqlite3_rebaser)(unsafe.Pointer(p)).Fgrp.FpList
			for {
				if !(pTab != 0) {
					break
				}
				if 0 == Xsqlite3_stricmp(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zTab) {
					break
				}
				goto _1
			_1:
				;
				pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
			}
			*(*int32)(unsafe.Pointer(bp + 12)) = 0
			/* A patchset may not be rebased */
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
			}
			/* Append a table header to the output for this new table */
			if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
				v2 = int32('P')
			} else {
				v2 = int32('T')
			}
			_sessionAppendByte(tls, bp+16, uint8(v2), bp)
			_sessionAppendVarint(tls, bp+16, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, bp)
			_sessionAppendBlob(tls, bp+16, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, bp)
			_sessionAppendBlob(tls, bp+16, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, int32(libc.Xstrlen(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab))+int32(1), bp)
		}
		if pTab != 0 && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			iHash = int32(_sessionChangeHash(tls, pTab, 0, *(*uintptr)(unsafe.Pointer(bp + 4)), (*TSessionTable)(unsafe.Pointer(pTab)).FnChange))
			pChange = *(*uintptr)(unsafe.Pointer((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(iHash)*4))
			for {
				if !(pChange != 0) {
					break
				}
				if _sessionChangeEqual(tls, pTab, 0, *(*uintptr)(unsafe.Pointer(bp + 4)), 0, (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord) != 0 {
					break
				}
				goto _3
			_3:
				;
				pChange = (*TSessionChange)(unsafe.Pointer(pChange)).FpNext
			}
		}
		if pChange != 0 {
			switch (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop {
			case int32(SQLITE_INSERT):
				if int32((*TSessionChange)(unsafe.Pointer(pChange)).Fop) == int32(SQLITE_INSERT) {
					bDone = int32(1)
					if int32((*TSessionChange)(unsafe.Pointer(pChange)).FbIndirect) == 0 {
						_sessionAppendByte(tls, bp+16, uint8(SQLITE_UPDATE), bp)
						_sessionAppendByte(tls, bp+16, uint8((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
						_sessionAppendBlob(tls, bp+16, (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, bp)
						_sessionAppendBlob(tls, bp+16, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp + 8)), bp)
					}
				}
			case int32(SQLITE_UPDATE):
				bDone = int32(1)
				if int32((*TSessionChange)(unsafe.Pointer(pChange)).Fop) == int32(SQLITE_DELETE) {
					if int32((*TSessionChange)(unsafe.Pointer(pChange)).FbIndirect) == 0 {
						*(*uintptr)(unsafe.Pointer(bp + 28)) = *(*uintptr)(unsafe.Pointer(bp + 4))
						_sessionSkipRecord(tls, bp+28, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol)
						_sessionAppendByte(tls, bp+16, uint8(SQLITE_INSERT), bp)
						_sessionAppendByte(tls, bp+16, uint8((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
						_sessionAppendRecordMerge(tls, bp+16, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, *(*uintptr)(unsafe.Pointer(bp + 28)), *(*int32)(unsafe.Pointer(bp + 8))-(int32(*(*uintptr)(unsafe.Pointer(bp + 28)))-int32(*(*uintptr)(unsafe.Pointer(bp + 4)))), (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, bp)
					}
				} else {
					_sessionAppendPartialUpdate(tls, bp+16, pIter, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp + 8)), (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, bp)
				}
			default:
				bDone = int32(1)
				if int32((*TSessionChange)(unsafe.Pointer(pChange)).Fop) == int32(SQLITE_INSERT) {
					_sessionAppendByte(tls, bp+16, uint8(SQLITE_DELETE), bp)
					_sessionAppendByte(tls, bp+16, uint8((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
					_sessionAppendRecordMerge(tls, bp+16, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp + 8)), bp)
				}
				break
			}
		}
		if bDone == 0 {
			_sessionAppendByte(tls, bp+16, uint8((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop), bp)
			_sessionAppendByte(tls, bp+16, uint8((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
			_sessionAppendBlob(tls, bp+16, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp + 8)), bp)
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && xOutput != 0 && (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FnBuf > _sessions_strm_chunk_size {
			*(*int32)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FnBuf)
			(*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FnBuf = 0
		}
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			break
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf)
		libc.Xmemset(tls, bp+16, 0, uint32(12))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		if xOutput != 0 {
			if (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FnBuf > 0 {
				*(*int32)(unsafe.Pointer(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xOutput})))(tls, pOut, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FnBuf)
			}
		} else {
			if ppOut != 0 {
				*(*uintptr)(unsafe.Pointer(ppOut)) = (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf
				*(*int32)(unsafe.Pointer(pnOut)) = (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FnBuf
				(*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf = uintptr(0)
			}
		}
	}
	Xsqlite3_free(tls, (*(*TSessionBuffer)(unsafe.Pointer(bp + 16))).FaBuf)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Create a new rebaser object.
//	*/
func Xsqlite3rebaser_create(tls *libc.TLS, ppNew uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	rc = SQLITE_OK
	pNew = Xsqlite3_malloc(tls, int32(32))
	if pNew == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, pNew, 0, uint32(32))
	}
	*(*uintptr)(unsafe.Pointer(ppNew)) = pNew
	return rc
}

// C documentation
//
//	/*
//	** Call this one or more times to configure a rebaser.
//	*/
func Xsqlite3rebaser_configure(tls *libc.TLS, p uintptr, nRebase int32, pRebase uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pIter at bp+0 */ uintptr
	_ = rc
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Return code */
	rc = Xsqlite3changeset_start(tls, bp, nRebase, pRebase)
	if rc == SQLITE_OK {
		rc = _sessionChangesetToHash(tls, *(*uintptr)(unsafe.Pointer(bp)), p, int32(1))
	}
	Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

// C documentation
//
//	/*
//	** Rebase a changeset according to current rebaser configuration
//	*/
func Xsqlite3rebaser_rebase(tls *libc.TLS, p uintptr, nIn int32, pIn uintptr, pnOut uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pIter at bp+0 */ uintptr
	_ = rc
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Iterator to skip through input */
	rc = Xsqlite3changeset_start(tls, bp, nIn, pIn)
	if rc == SQLITE_OK {
		rc = _sessionRebase(tls, p, *(*uintptr)(unsafe.Pointer(bp)), uintptr(0), uintptr(0), pnOut, ppOut)
		Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Rebase a changeset according to current rebaser configuration
//	*/
func Xsqlite3rebaser_rebase_strm(tls *libc.TLS, p uintptr, xInput uintptr, pIn uintptr, xOutput uintptr, pOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pIter at bp+0 */ uintptr
	_ = rc
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Iterator to skip through input */
	rc = Xsqlite3changeset_start_strm(tls, bp, xInput, pIn)
	if rc == SQLITE_OK {
		rc = _sessionRebase(tls, p, *(*uintptr)(unsafe.Pointer(bp)), xOutput, pOut, uintptr(0), uintptr(0))
		Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Destroy a rebaser object
//	*/
func Xsqlite3rebaser_delete(tls *libc.TLS, p uintptr) {
	if p != 0 {
		_sessionDeleteTable(tls, uintptr(0), (*Tsqlite3_rebaser)(unsafe.Pointer(p)).Fgrp.FpList)
		Xsqlite3_free(tls, (*Tsqlite3_rebaser)(unsafe.Pointer(p)).Fgrp.Frec.FaBuf)
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Global configuration
//	*/
func Xsqlite3session_config(tls *libc.TLS, op int32, pArg uintptr) (r int32) {
	var pInt uintptr
	var rc int32
	_, _ = pInt, rc
	rc = SQLITE_OK
	switch op {
	case int32(SQLITE_SESSION_CONFIG_STRMSIZE):
		pInt = pArg
		if *(*int32)(unsafe.Pointer(pInt)) > 0 {
			_sessions_strm_chunk_size = *(*int32)(unsafe.Pointer(pInt))
		}
		*(*int32)(unsafe.Pointer(pInt)) = _sessions_strm_chunk_size
	default:
		rc = int32(SQLITE_MISUSE)
		break
	}
	return rc
}

/************** End of sqlite3session.c **************************************/
/************** Begin file fts5.c ********************************************/

/*
** 2014 May 31
**
** 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.
**
******************************************************************************
**
** Interfaces to extend FTS5. Using the interfaces defined in this file,
** FTS5 may be extended with:
**
**     * custom tokenizers, and
**     * custom auxiliary functions.
 */

/*
** 2014 May 31
**
** 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 "fts5.h" */
/* #include "sqlite3ext.h" */

/* #include <string.h> */
/* #include <assert.h> */

/* Truncate very long tokens to this many bytes. Hard limit is
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
** field that occurs at the start of each leaf page (see fts5_index.c). */

/*
** Maximum number of prefix indexes on single FTS5 table. This must be
** less than 32. If it is set to anything large than that, an #error
** directive in fts5_index.c will cause the build to fail.
 */

/*
** Maximum segments permitted in a single index
 */

/* Name of rank and rowid columns */

/*
** The assert_nc() macro is similar to the assert() macro, except that it
** is used for assert() conditions that are true only if it can be
** guranteed that the database is not corrupt.
 */

/*
** A version of memcmp() that does not cause asan errors if one of the pointer
** parameters is NULL and the number of bytes to compare is zero.
 */

/* Mark a function parameter as unused, to suppress nuisance compiler
** warnings. */

type TFts5Global = struct {
	F__ccgo_align  [0]uint32
	Fapi           Tfts5_api
	Fdb            uintptr
	F__ccgo_align2 [4]byte
	FiNextId       Ti64
	FpAux          uintptr
	FpTok          uintptr
	FpDfltTok      uintptr
	FpCsr          uintptr
}

type Fts5Global = TFts5Global

type TFts5Colset = struct {
	FnCol  int32
	FaiCol [1]int32
}

type Fts5Colset = TFts5Colset

/* If a NEAR() clump or phrase may only match a specific set of columns,
** then an object of the following type is used to record the set of columns.
** Each entry in the aiCol[] array is a column that may be matched.
**
** This object is used by fts5_expr.c and fts5_index.c.
 */
type TFts5Colset1 = struct {
	FnCol  int32
	FaiCol [1]int32
}

type Fts5Colset1 = TFts5Colset1

/**************************************************************************
** Interface to code in fts5_config.c. fts5_config.c contains contains code
** to parse the arguments passed to the CREATE VIRTUAL TABLE statement.
 */

type TFts5Config = struct {
	Fdb                 uintptr
	FzDb                uintptr
	FzName              uintptr
	FnCol               int32
	FazCol              uintptr
	FabUnindexed        uintptr
	FnPrefix            int32
	FaPrefix            uintptr
	FeContent           int32
	FbContentlessDelete int32
	FzContent           uintptr
	FzContentRowid      uintptr
	FbColumnsize        int32
	FbTokendata         int32
	FeDetail            int32
	FzContentExprlist   uintptr
	FpTok               uintptr
	FpTokApi            uintptr
	FbLock              int32
	FePattern           int32
	FiVersion           int32
	FiCookie            int32
	Fpgsz               int32
	FnAutomerge         int32
	FnCrisisMerge       int32
	FnUsermerge         int32
	FnHashSize          int32
	FzRank              uintptr
	FzRankArgs          uintptr
	FbSecureDelete      int32
	FnDeleteMerge       int32
	FpzErrmsg           uintptr
}

type Fts5Config = TFts5Config

/*
** An instance of the following structure encodes all information that can
** be gleaned from the CREATE VIRTUAL TABLE statement.
**
** And all information loaded from the %_config table.
**
** nAutomerge:
**   The minimum number of segments that an auto-merge operation should
**   attempt to merge together. A value of 1 sets the object to use the
**   compile time default. Zero disables auto-merge altogether.
**
** bContentlessDelete:
**   True if the contentless_delete option was present in the CREATE
**   VIRTUAL TABLE statement.
**
** zContent:
**
** zContentRowid:
**   The value of the content_rowid= option, if one was specified. Or
**   the string "rowid" otherwise. This text is not quoted - if it is
**   used as part of an SQL statement it needs to be quoted appropriately.
**
** zContentExprlist:
**
** pzErrmsg:
**   This exists in order to allow the fts5_index.c module to return a
**   decent error message if it encounters a file-format version it does
**   not understand.
**
** bColumnsize:
**   True if the %_docsize table is created.
**
** bPrefixIndex:
**   This is only used for debugging. If set to false, any prefix indexes
**   are ignored. This value is configured using:
**
**       INSERT INTO tbl(tbl, rank) VALUES('prefix-index', $bPrefixIndex);
**
 */
type TFts5Config1 = struct {
	Fdb                 uintptr
	FzDb                uintptr
	FzName              uintptr
	FnCol               int32
	FazCol              uintptr
	FabUnindexed        uintptr
	FnPrefix            int32
	FaPrefix            uintptr
	FeContent           int32
	FbContentlessDelete int32
	FzContent           uintptr
	FzContentRowid      uintptr
	FbColumnsize        int32
	FbTokendata         int32
	FeDetail            int32
	FzContentExprlist   uintptr
	FpTok               uintptr
	FpTokApi            uintptr
	FbLock              int32
	FePattern           int32
	FiVersion           int32
	FiCookie            int32
	Fpgsz               int32
	FnAutomerge         int32
	FnCrisisMerge       int32
	FnUsermerge         int32
	FnHashSize          int32
	FzRank              uintptr
	FzRankArgs          uintptr
	FbSecureDelete      int32
	FnDeleteMerge       int32
	FpzErrmsg           uintptr
}

type Fts5Config1 = TFts5Config1

/*
** End of interface to code in fts5_config.c.
**************************************************************************/

/**************************************************************************
** Interface to code in fts5_buffer.c.
 */

// C documentation
//
//	/*
//	** Buffer object for the incremental building of string data.
//	*/
type TFts5Buffer = struct {
	Fp      uintptr
	Fn      int32
	FnSpace int32
}

type Fts5Buffer = TFts5Buffer

type TFts5Buffer1 = struct {
	Fp      uintptr
	Fn      int32
	FnSpace int32
}

type Fts5Buffer1 = TFts5Buffer1

type TFts5PoslistReader = struct {
	F__ccgo_align  [0]uint32
	Fa             uintptr
	Fn             int32
	Fi             int32
	FbFlag         Tu8
	FbEof          Tu8
	F__ccgo_align5 [2]byte
	FiPos          Ti64
}

type Fts5PoslistReader = TFts5PoslistReader

type TFts5PoslistReader1 = struct {
	F__ccgo_align  [0]uint32
	Fa             uintptr
	Fn             int32
	Fi             int32
	FbFlag         Tu8
	FbEof          Tu8
	F__ccgo_align5 [2]byte
	FiPos          Ti64
}

type Fts5PoslistReader1 = TFts5PoslistReader1

type TFts5PoslistWriter = struct {
	F__ccgo_align [0]uint32
	FiPrev        Ti64
}

type Fts5PoslistWriter = TFts5PoslistWriter

type TFts5PoslistWriter1 = struct {
	F__ccgo_align [0]uint32
	FiPrev        Ti64
}

type Fts5PoslistWriter1 = TFts5PoslistWriter1

// C documentation
//
//	/* Bucket of terms object used by the integrity-check in offsets=0 mode. */
type TFts5Termset = struct {
	FapHash [512]uintptr
}

type Fts5Termset = TFts5Termset

/*
** End of interface to code in fts5_buffer.c.
**************************************************************************/

/**************************************************************************
** Interface to code in fts5_index.c. fts5_index.c contains contains code
** to access the data stored in the %_data table.
 */

type TFts5Index = struct {
	F__ccgo_align       [0]uint32
	FpConfig            uintptr
	FzDataTbl           uintptr
	FnWorkUnit          int32
	FpHash              uintptr
	FnPendingData       int32
	F__ccgo_align5      [4]byte
	FiWriteRowid        Ti64
	FbDelete            int32
	FnContentlessDelete int32
	FnPendingRow        int32
	Frc                 int32
	FflushRc            int32
	FpReader            uintptr
	FpWriter            uintptr
	FpDeleter           uintptr
	FpIdxWriter         uintptr
	FpIdxDeleter        uintptr
	FpIdxSelect         uintptr
	FpIdxNextSelect     uintptr
	FnRead              int32
	FpDeleteFromIdx     uintptr
	FpDataVersion       uintptr
	F__ccgo_align21     [4]byte
	FiStructVersion     Ti64
	FpStruct            uintptr
	F__ccgo_pad23       [4]byte
}

type Fts5Index = TFts5Index

type TFts5IndexIter = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FpData        uintptr
	FnData        int32
	FbEof         Tu8
	F__ccgo_pad4  [7]byte
}

type Fts5IndexIter = TFts5IndexIter

type TFts5IndexIter1 = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FpData        uintptr
	FnData        int32
	FbEof         Tu8
	F__ccgo_pad4  [7]byte
}

type Fts5IndexIter1 = TFts5IndexIter1

/*
** End of interface to code in fts5_varint.c.
**************************************************************************/

/**************************************************************************
** Interface to code in fts5_main.c.
 */

// C documentation
//
//	/*
//	** Virtual-table object.
//	*/
type TFts5Table = struct {
	Fbase    Tsqlite3_vtab
	FpConfig uintptr
	FpIndex  uintptr
}

type Fts5Table = TFts5Table

type TFts5Table1 = struct {
	Fbase    Tsqlite3_vtab
	FpConfig uintptr
	FpIndex  uintptr
}

type Fts5Table1 = TFts5Table1

/*
** End of interface to code in fts5.c.
**************************************************************************/

// C documentation
//
//	/**************************************************************************
//	** Interface to code in fts5_hash.c.
//	*/
type TFts5Hash = struct {
	FeDetail int32
	FpnByte  uintptr
	FnEntry  int32
	FnSlot   int32
	FpScan   uintptr
	FaSlot   uintptr
}

type Fts5Hash = TFts5Hash

/*
** End of interface to code in fts5_hash.c.
**************************************************************************/

/**************************************************************************
** Interface to code in fts5_storage.c. fts5_storage.c contains contains
** code to access the data stored in the %_content and %_docsize tables.
 */

type TFts5Storage = struct {
	F__ccgo_align  [0]uint32
	FpConfig       uintptr
	FpIndex        uintptr
	FbTotalsValid  int32
	F__ccgo_align3 [4]byte
	FnTotalRow     Ti64
	FaTotalSize    uintptr
	FaStmt         [11]uintptr
}

type Fts5Storage = TFts5Storage

/*
** End of interface to code in fts5_storage.c.
**************************************************************************/

// C documentation
//
//	/**************************************************************************
//	** Interface to code in fts5_expr.c.
//	*/
type TFts5Expr = struct {
	FpIndex       uintptr
	FpConfig      uintptr
	FpRoot        uintptr
	FbDesc        int32
	FnPhrase      int32
	FapExprPhrase uintptr
}

type Fts5Expr = TFts5Expr

type TFts5ExprNode = struct {
	F__ccgo_align  [0]uint32
	FeType         int32
	FbEof          int32
	FbNomatch      int32
	FiHeight       int32
	FxNext         uintptr
	F__ccgo_align5 [4]byte
	FiRowid        Ti64
	FpNear         uintptr
	FnChild        int32
	FapChild       [1]uintptr
	F__ccgo_pad9   [4]byte
}

type Fts5ExprNode = TFts5ExprNode

type TFts5Parse = struct {
	FpConfig      uintptr
	FzErr         uintptr
	Frc           int32
	FnPhrase      int32
	FapPhrase     uintptr
	FpExpr        uintptr
	FbPhraseToAnd int32
}

type Fts5Parse = TFts5Parse

type TFts5Token = struct {
	Fp uintptr
	Fn int32
}

type Fts5Token = TFts5Token

type TFts5ExprPhrase = struct {
	FpNode   uintptr
	Fposlist TFts5Buffer
	FnTerm   int32
	FaTerm   [1]TFts5ExprTerm
}

type Fts5ExprPhrase = TFts5ExprPhrase

type TFts5ExprNearset = struct {
	FnNear    int32
	FpColset  uintptr
	FnPhrase  int32
	FapPhrase [1]uintptr
}

type Fts5ExprNearset = TFts5ExprNearset

type TFts5Token1 = struct {
	Fp uintptr
	Fn int32
}

type Fts5Token1 = TFts5Token1

type TFts5PoslistPopulator = struct {
	F__ccgo_align [0]uint32
	Fwriter       TFts5PoslistWriter
	FbOk          int32
	FbMiss        int32
}

type Fts5PoslistPopulator = TFts5PoslistPopulator

/*
** End of interface to code in fts5_unicode2.c.
**************************************************************************/

/* This file is automatically generated by Lemon from input grammar
** source file "fts5parse.y".
 */
/*
** 2000-05-29
**
** 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.
**
*************************************************************************
** Driver template for the LEMON parser generator.
**
** The "lemon" program processes an LALR(1) input grammar file, then uses
** this template to construct a parser.  The "lemon" program inserts text
** at each "%%" line.  Also, any "P-a-r-s-e" identifer prefix (without the
** interstitial "-" characters) contained in this template is changed into
** the value of the %name directive from the grammar.  Otherwise, the content
** of this template is copied straight through into the generate parser
** source file.
**
** The following is the concatenation of all %include directives from the
** input grammar file:
 */
/************ Begin %include sections from the grammar ************************/

/* #include "fts5Int.h" */
/* #include "fts5parse.h" */

/*
** Disable all error recovery processing in the parser push-down
** automaton.
 */

/*
** Make fts5yytestcase() the same as testcase()
 */

/*
** Indicate that sqlite3ParserFree() will never be called with a null
** pointer.
 */

/*
** Alternative datatype for the argument to the malloc() routine passed
** into sqlite3ParserAlloc().  The default is size_t.
 */

/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols.
***************** Begin token definitions *************************************/
/**************** End token definitions ***************************************/

// C documentation
//
//	/* The next sections is a series of control #defines.
//	** various aspects of the generated parser.
//	**    fts5YYCODETYPE         is the data type used to store the integer codes
//	**                       that represent terminal and non-terminal symbols.
//	**                       "unsigned char" is used if there are fewer than
//	**                       256 symbols.  Larger types otherwise.
//	**    fts5YYNOCODE           is a number of type fts5YYCODETYPE that is not used for
//	**                       any terminal or nonterminal symbol.
//	**    fts5YYFALLBACK         If defined, this indicates that one or more tokens
//	**                       (also known as: "terminal symbols") have fall-back
//	**                       values which should be used if the original symbol
//	**                       would not parse.  This permits keywords to sometimes
//	**                       be used as identifiers, for example.
//	**    fts5YYACTIONTYPE       is the data type used for "action codes" - numbers
//	**                       that indicate what to do in response to the next
//	**                       token.
//	**    sqlite3Fts5ParserFTS5TOKENTYPE     is the data type used for minor type for terminal
//	**                       symbols.  Background: A "minor type" is a semantic
//	**                       value associated with a terminal or non-terminal
//	**                       symbols.  For example, for an "ID" terminal symbol,
//	**                       the minor type might be the name of the identifier.
//	**                       Each non-terminal can have a different minor type.
//	**                       Terminal symbols all have the same minor type, though.
//	**                       This macros defines the minor type for terminal
//	**                       symbols.
//	**    fts5YYMINORTYPE        is the data type used for all minor types.
//	**                       This is typically a union of many types, one of
//	**                       which is sqlite3Fts5ParserFTS5TOKENTYPE.  The entry in the union
//	**                       for terminal symbols is called "fts5yy0".
//	**    fts5YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
//	**                       zero the stack is dynamically sized using realloc()
//	**    sqlite3Fts5ParserARG_SDECL     A static variable declaration for the %extra_argument
//	**    sqlite3Fts5ParserARG_PDECL     A parameter declaration for the %extra_argument
//	**    sqlite3Fts5ParserARG_PARAM     Code to pass %extra_argument as a subroutine parameter
//	**    sqlite3Fts5ParserARG_STORE     Code to store %extra_argument into fts5yypParser
//	**    sqlite3Fts5ParserARG_FETCH     Code to extract %extra_argument from fts5yypParser
//	**    sqlite3Fts5ParserCTX_*         As sqlite3Fts5ParserARG_ except for %extra_context
//	**    fts5YYREALLOC          Name of the realloc() function to use
//	**    fts5YYFREE             Name of the free() function to use
//	**    fts5YYDYNSTACK         True if stack space should be extended on heap
//	**    fts5YYERRORSYMBOL      is the code number of the error symbol.  If not
//	**                       defined, then do no error processing.
//	**    fts5YYNSTATE           the combined number of states.
//	**    fts5YYNRULE            the number of rules in the grammar
//	**    fts5YYNFTS5TOKEN           Number of terminal symbols
//	**    fts5YY_MAX_SHIFT       Maximum value for shift actions
//	**    fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
//	**    fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
//	**    fts5YY_ERROR_ACTION    The fts5yy_action[] code for syntax error
//	**    fts5YY_ACCEPT_ACTION   The fts5yy_action[] code for accept
//	**    fts5YY_NO_ACTION       The fts5yy_action[] code for no-op
//	**    fts5YY_MIN_REDUCE      Minimum value for reduce actions
//	**    fts5YY_MAX_REDUCE      Maximum value for reduce actions
//	**    fts5YY_MIN_DSTRCTR     Minimum symbol value that has a destructor
//	**    fts5YY_MAX_DSTRCTR     Maximum symbol value that has a destructor
//	*/
//	/************* Begin control #defines *****************************************/
type Tfts5YYMINORTYPE = struct {
	Ffts5yy0     [0]TFts5Token
	Ffts5yy4     [0]int32
	Ffts5yy11    [0]uintptr
	Ffts5yy24    [0]uintptr
	Ffts5yy46    [0]uintptr
	Ffts5yy53    [0]uintptr
	Ffts5yyinit  int32
	F__ccgo_pad7 [4]byte
}

type fts5YYMINORTYPE = Tfts5YYMINORTYPE

/************* End control #defines *******************************************/

/* Define the fts5yytestcase() macro to be a no-op if is not already defined
** otherwise.
**
** Applications can choose to define fts5yytestcase() in the %include section
** to a macro that can assist in verifying code coverage.  For production
** code the fts5yytestcase() macro should be turned off.  But it is useful
** for testing.
 */

/* Macro to determine if stack space has the ability to grow using
** heap memory.
 */

/* Guarantee a minimum number of initial stack slots.
 */

// C documentation
//
//	/* Next are the tables used to determine what action to take based on the
//	** current state and lookahead token.  These tables are used to implement
//	** functions that take a state number and lookahead value and return an
//	** action integer.
//	**
//	** Suppose the action integer is N.  Then the action is determined as
//	** follows
//	**
//	**   0 <= N <= fts5YY_MAX_SHIFT             Shift N.  That is, push the lookahead
//	**                                      token onto the stack and goto state N.
//	**
//	**   N between fts5YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
//	**     and fts5YY_MAX_SHIFTREDUCE           reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
//	**
//	**   N == fts5YY_ERROR_ACTION               A syntax error has occurred.
//	**
//	**   N == fts5YY_ACCEPT_ACTION              The parser accepts its input.
//	**
//	**   N == fts5YY_NO_ACTION                  No such action.  Denotes unused
//	**                                      slots in the fts5yy_action[] table.
//	**
//	**   N between fts5YY_MIN_REDUCE            Reduce by rule N-fts5YY_MIN_REDUCE
//	**     and fts5YY_MAX_REDUCE
//	**
//	** The action table is constructed as a single large table named fts5yy_action[].
//	** Given state S and lookahead X, the action is computed as either:
//	**
//	**    (A)   N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
//	**    (B)   N = fts5yy_default[S]
//	**
//	** The (A) formula is preferred.  The B formula is used instead if
//	** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X.
//	**
//	** The formulas above are for computing the action when the lookahead is
//	** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
//	** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
//	** the fts5yy_shift_ofst[] array.
//	**
//	** The following are the tables generated in this section:
//	**
//	**  fts5yy_action[]        A single table containing all actions.
//	**  fts5yy_lookahead[]     A table containing the lookahead for each entry in
//	**                     fts5yy_action.  Used to detect hash collisions.
//	**  fts5yy_shift_ofst[]    For each state, the offset into fts5yy_action for
//	**                     shifting terminals.
//	**  fts5yy_reduce_ofst[]   For each state, the offset into fts5yy_action for
//	**                     shifting non-terminals after a reduce.
//	**  fts5yy_default[]       Default action for each state.
//	**
//	*********** Begin parsing tables **********************************************/
var _fts5yy_action = [105]uint8{
	0:   uint8(81),
	1:   uint8(20),
	2:   uint8(96),
	3:   uint8(6),
	4:   uint8(28),
	5:   uint8(99),
	6:   uint8(98),
	7:   uint8(26),
	8:   uint8(26),
	9:   uint8(18),
	10:  uint8(96),
	11:  uint8(6),
	12:  uint8(28),
	13:  uint8(17),
	14:  uint8(98),
	15:  uint8(56),
	16:  uint8(26),
	17:  uint8(19),
	18:  uint8(96),
	19:  uint8(6),
	20:  uint8(28),
	21:  uint8(14),
	22:  uint8(98),
	23:  uint8(14),
	24:  uint8(26),
	25:  uint8(31),
	26:  uint8(92),
	27:  uint8(96),
	28:  uint8(6),
	29:  uint8(28),
	30:  uint8(108),
	31:  uint8(98),
	32:  uint8(25),
	33:  uint8(26),
	34:  uint8(21),
	35:  uint8(96),
	36:  uint8(6),
	37:  uint8(28),
	38:  uint8(78),
	39:  uint8(98),
	40:  uint8(58),
	41:  uint8(26),
	42:  uint8(29),
	43:  uint8(96),
	44:  uint8(6),
	45:  uint8(28),
	46:  uint8(107),
	47:  uint8(98),
	48:  uint8(22),
	49:  uint8(26),
	50:  uint8(24),
	51:  uint8(16),
	52:  uint8(12),
	53:  uint8(11),
	54:  uint8(1),
	55:  uint8(13),
	56:  uint8(13),
	57:  uint8(24),
	58:  uint8(16),
	59:  uint8(23),
	60:  uint8(11),
	61:  uint8(33),
	62:  uint8(34),
	63:  uint8(13),
	64:  uint8(97),
	65:  uint8(8),
	66:  uint8(27),
	67:  uint8(32),
	68:  uint8(98),
	69:  uint8(7),
	70:  uint8(26),
	71:  uint8(3),
	72:  uint8(4),
	73:  uint8(5),
	74:  uint8(3),
	75:  uint8(4),
	76:  uint8(5),
	77:  uint8(3),
	78:  uint8(83),
	79:  uint8(4),
	80:  uint8(5),
	81:  uint8(3),
	82:  uint8(63),
	83:  uint8(5),
	84:  uint8(3),
	85:  uint8(62),
	86:  uint8(12),
	87:  uint8(2),
	88:  uint8(86),
	89:  uint8(13),
	90:  uint8(9),
	91:  uint8(30),
	92:  uint8(10),
	93:  uint8(10),
	94:  uint8(54),
	95:  uint8(57),
	96:  uint8(75),
	97:  uint8(78),
	98:  uint8(78),
	99:  uint8(53),
	100: uint8(57),
	101: uint8(15),
	102: uint8(82),
	103: uint8(82),
	104: uint8(71),
}
var _fts5yy_lookahead = [121]uint8{
	0:   uint8(16),
	1:   uint8(17),
	2:   uint8(18),
	3:   uint8(19),
	4:   uint8(20),
	5:   uint8(22),
	6:   uint8(22),
	7:   uint8(24),
	8:   uint8(24),
	9:   uint8(17),
	10:  uint8(18),
	11:  uint8(19),
	12:  uint8(20),
	13:  uint8(7),
	14:  uint8(22),
	15:  uint8(9),
	16:  uint8(24),
	17:  uint8(17),
	18:  uint8(18),
	19:  uint8(19),
	20:  uint8(20),
	21:  uint8(9),
	22:  uint8(22),
	23:  uint8(9),
	24:  uint8(24),
	25:  uint8(13),
	26:  uint8(17),
	27:  uint8(18),
	28:  uint8(19),
	29:  uint8(20),
	30:  uint8(26),
	31:  uint8(22),
	32:  uint8(24),
	33:  uint8(24),
	34:  uint8(17),
	35:  uint8(18),
	36:  uint8(19),
	37:  uint8(20),
	38:  uint8(15),
	39:  uint8(22),
	40:  uint8(9),
	41:  uint8(24),
	42:  uint8(17),
	43:  uint8(18),
	44:  uint8(19),
	45:  uint8(20),
	46:  uint8(26),
	47:  uint8(22),
	48:  uint8(21),
	49:  uint8(24),
	50:  uint8(6),
	51:  uint8(7),
	52:  uint8(9),
	53:  uint8(9),
	54:  uint8(10),
	55:  uint8(12),
	56:  uint8(12),
	57:  uint8(6),
	58:  uint8(7),
	59:  uint8(21),
	60:  uint8(9),
	61:  uint8(24),
	62:  uint8(25),
	63:  uint8(12),
	64:  uint8(18),
	65:  uint8(5),
	66:  uint8(20),
	67:  uint8(14),
	68:  uint8(22),
	69:  uint8(5),
	70:  uint8(24),
	71:  uint8(3),
	72:  uint8(1),
	73:  uint8(2),
	74:  uint8(3),
	75:  uint8(1),
	76:  uint8(2),
	77:  uint8(3),
	79:  uint8(1),
	80:  uint8(2),
	81:  uint8(3),
	82:  uint8(11),
	83:  uint8(2),
	84:  uint8(3),
	85:  uint8(11),
	86:  uint8(9),
	87:  uint8(10),
	88:  uint8(5),
	89:  uint8(12),
	90:  uint8(23),
	91:  uint8(24),
	92:  uint8(10),
	93:  uint8(10),
	94:  uint8(8),
	95:  uint8(9),
	96:  uint8(9),
	97:  uint8(15),
	98:  uint8(15),
	99:  uint8(8),
	100: uint8(9),
	101: uint8(9),
	102: uint8(27),
	103: uint8(27),
	104: uint8(11),
	105: uint8(27),
	106: uint8(27),
	107: uint8(27),
	108: uint8(27),
	109: uint8(27),
	110: uint8(27),
	111: uint8(27),
	112: uint8(27),
	113: uint8(27),
	114: uint8(27),
	115: uint8(27),
	116: uint8(27),
	117: uint8(27),
	118: uint8(27),
	119: uint8(27),
	120: uint8(27),
}
var _fts5yy_shift_ofst = [35]uint8{
	0:  uint8(44),
	1:  uint8(44),
	2:  uint8(44),
	3:  uint8(44),
	4:  uint8(44),
	5:  uint8(44),
	6:  uint8(51),
	7:  uint8(77),
	8:  uint8(43),
	9:  uint8(12),
	10: uint8(14),
	11: uint8(83),
	12: uint8(82),
	13: uint8(14),
	14: uint8(23),
	15: uint8(23),
	16: uint8(31),
	17: uint8(31),
	18: uint8(71),
	19: uint8(74),
	20: uint8(78),
	21: uint8(81),
	22: uint8(86),
	23: uint8(91),
	24: uint8(6),
	25: uint8(53),
	26: uint8(53),
	27: uint8(60),
	28: uint8(64),
	29: uint8(68),
	30: uint8(53),
	31: uint8(87),
	32: uint8(92),
	33: uint8(53),
	34: uint8(93),
}
var _fts5yy_reduce_ofst = [18]int8{
	0:  int8(-int32(16)),
	1:  int8(-int32(8)),
	3:  int8(9),
	4:  int8(17),
	5:  int8(25),
	6:  int8(46),
	7:  int8(-int32(17)),
	8:  int8(-int32(17)),
	9:  int8(37),
	10: int8(67),
	11: int8(4),
	12: int8(4),
	13: int8(8),
	14: int8(4),
	15: int8(20),
	16: int8(27),
	17: int8(38),
}
var _fts5yy_default = [35]uint8{
	0:  uint8(80),
	1:  uint8(80),
	2:  uint8(80),
	3:  uint8(80),
	4:  uint8(80),
	5:  uint8(80),
	6:  uint8(95),
	7:  uint8(80),
	8:  uint8(80),
	9:  uint8(105),
	10: uint8(80),
	11: uint8(110),
	12: uint8(110),
	13: uint8(80),
	14: uint8(110),
	15: uint8(110),
	16: uint8(80),
	17: uint8(80),
	18: uint8(80),
	19: uint8(80),
	20: uint8(80),
	21: uint8(91),
	22: uint8(80),
	23: uint8(80),
	24: uint8(80),
	25: uint8(101),
	26: uint8(100),
	27: uint8(80),
	28: uint8(80),
	29: uint8(90),
	30: uint8(103),
	31: uint8(80),
	32: uint8(80),
	33: uint8(104),
	34: uint8(80),
}

/********** End of lemon-generated parsing tables *****************************/

/* The next table maps tokens (terminal symbols) into fallback tokens.
** If a construct like the following:
**
**      %fallback ID X Y Z.
**
** appears in the grammar, then ID becomes a fallback token for X, Y,
** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
** but it does not parse, the type of the token is changed to ID and
** the parse is retried before an error is thrown.
**
** This feature can be used, for example, to cause some keywords in a language
** to revert to identifiers if they keyword does not apply in the context where
** it appears.
 */

/* The following structure represents a single element of the
** parser's stack.  Information stored includes:
**
**   +  The state number for the parser at this level of the stack.
**
**   +  The value of the token stored at this level of the stack.
**      (In other words, the "major" token.)
**
**   +  The semantic value stored at this level of the stack.  This is
**      the information used by the action routines in the grammar.
**      It is sometimes called the "minor" token.
**
** After the "shift" half of a SHIFTREDUCE action, the stateno field
** actually contains the reduce action for the second half of the
** SHIFTREDUCE.
 */
type Tfts5yyStackEntry1 = struct {
	Fstateno uint8
	Fmajor   uint8
	Fminor   Tfts5YYMINORTYPE
}

type fts5yyStackEntry1 = Tfts5yyStackEntry1

type Tfts5yyStackEntry = struct {
	Fstateno uint8
	Fmajor   uint8
	Fminor   Tfts5YYMINORTYPE
}

type fts5yyStackEntry = Tfts5yyStackEntry

/* The state of the parser is completely contained in an instance of
** the following structure */
type Tfts5yyParser1 = struct {
	Ffts5yytos      uintptr
	FpParse         uintptr
	Ffts5yystackEnd uintptr
	Ffts5yystack    uintptr
	Ffts5yystk0     [100]Tfts5yyStackEntry
}

type fts5yyParser1 = Tfts5yyParser1

type Tfts5yyParser = struct {
	Ffts5yytos      uintptr
	FpParse         uintptr
	Ffts5yystackEnd uintptr
	Ffts5yystack    uintptr
	Ffts5yystk0     [100]Tfts5yyStackEntry
}

type fts5yyParser = Tfts5yyParser

/* #include <assert.h> */

/* For builds that do no have a growable stack, fts5yyGrowStack always
** returns an error.
 */

/* Datatype of the argument to the memory allocated passed as the
** second argument to sqlite3Fts5ParserAlloc() below.  This can be changed by
** putting an appropriate #define in the %include section of the input
** grammar.
 */

// C documentation
//
//	/* Initialize a new parser that has already been allocated.
//	*/
func _sqlite3Fts5ParserInit(tls *libc.TLS, fts5yypRawParser uintptr) {
	var fts5yypParser uintptr
	_ = fts5yypParser
	fts5yypParser = fts5yypRawParser
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack = fts5yypParser + 16
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystackEnd = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack + uintptr(libc.Int32FromInt32(fts5YYSTACKDEPTH)-libc.Int32FromInt32(1))*12
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack
	(*(*Tfts5yyStackEntry)(unsafe.Pointer((*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack))).Fstateno = uint8(0)
	(*(*Tfts5yyStackEntry)(unsafe.Pointer((*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack))).Fmajor = uint8(0)
}

// C documentation
//
//	/*
//	** This function allocates a new parser.
//	** The only argument is a pointer to a function which works like
//	** malloc.
//	**
//	** Inputs:
//	** A pointer to the function used to allocate memory.
//	**
//	** Outputs:
//	** A pointer to a parser.  This pointer is used in subsequent calls
//	** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
//	*/
func _sqlite3Fts5ParserAlloc(tls *libc.TLS, mallocProc uintptr) (r uintptr) {
	var fts5yypParser uintptr
	_ = fts5yypParser
	fts5yypParser = (*(*func(*libc.TLS, Tu64) uintptr)(unsafe.Pointer(&struct{ uintptr }{mallocProc})))(tls, libc.Uint64FromInt64(1216))
	if fts5yypParser != 0 {
		_sqlite3Fts5ParserInit(tls, fts5yypParser)
	}
	return fts5yypParser
}

// C documentation
//
//	/* The following function deletes the "minor type" or semantic value
//	** associated with a symbol.  The symbol can be either a terminal
//	** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is
//	** a pointer to the value to be deleted.  The code used to do the
//	** deletions is derived from the %destructor and/or %token_destructor
//	** directives of the input grammar.
//	*/
func _fts5yy_destructor(tls *libc.TLS, fts5yypParser uintptr, fts5yymajor uint8, fts5yypminor uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	switch int32(int32(fts5yymajor)) {
	/* Here is inserted the actions which take place when a
	 ** terminal or non-terminal is destroyed.  This can happen
	 ** when the symbol is popped from the stack during a
	 ** reduce or during error processing or when a parser is
	 ** being destroyed before it is finished parsing.
	 **
	 ** Note: during a reduce, the only symbols destroyed are those
	 ** which appear on the RHS of the rule, but which are *not* used
	 ** inside the C code.
	 */
	/********* Begin destructor definitions ***************************************/
	case int32(16): /* input */
		_ = pParse
	case int32(17): /* expr */
		fallthrough
	case int32(18): /* cnearset */
		fallthrough
	case int32(19): /* exprlist */
		_sqlite3Fts5ParseNodeFree(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
	case int32(20): /* colset */
		fallthrough
	case int32(21): /* colsetlist */
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
	case int32(22): /* nearset */
		fallthrough
	case int32(23): /* nearphrases */
		_sqlite3Fts5ParseNearsetFree(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
	case int32(24): /* phrase */
		_sqlite3Fts5ParsePhraseFree(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
		break
		/********* End destructor definitions *****************************************/
		fallthrough
	default:
		break /* If no destructor action specified: do nothing */
	}
}

// C documentation
//
//	/*
//	** Pop the parser's stack once.
//	**
//	** If there is a destructor routine associated with the token which
//	** is popped from the stack, then call it.
//	*/
func _fts5yy_pop_parser_stack(tls *libc.TLS, pParser uintptr) {
	var fts5yytos, v1, v2 uintptr
	_, _, _ = fts5yytos, v1, v2
	v2 = pParser
	v1 = *(*uintptr)(unsafe.Pointer(v2))
	*(*uintptr)(unsafe.Pointer(v2)) -= 12
	fts5yytos = v1
	_fts5yy_destructor(tls, pParser, (*Tfts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fmajor, fts5yytos+4)
}

// C documentation
//
//	/*
//	** Clear all secondary memory allocations from the parser
//	*/
func _sqlite3Fts5ParserFinalize(tls *libc.TLS, p uintptr) {
	var fts5yytos, pParser uintptr
	_, _ = fts5yytos, pParser
	pParser = p
	/* In-lined version of calling fts5yy_pop_parser_stack() for each
	 ** element left in the stack */
	fts5yytos = (*Tfts5yyParser)(unsafe.Pointer(pParser)).Ffts5yytos
	for fts5yytos > (*Tfts5yyParser)(unsafe.Pointer(pParser)).Ffts5yystack {
		if int32((*Tfts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fmajor) >= int32(fts5YY_MIN_DSTRCTR) {
			_fts5yy_destructor(tls, pParser, (*Tfts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fmajor, fts5yytos+4)
		}
		fts5yytos -= 12
	}
}

// C documentation
//
//	/*
//	** Deallocate and destroy a parser.  Destructors are called for
//	** all stack elements before shutting the parser down.
//	**
//	** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it
//	** is defined in a %include section of the input grammar) then it is
//	** assumed that the input pointer is never NULL.
//	*/
func _sqlite3Fts5ParserFree(tls *libc.TLS, p uintptr, freeProc uintptr) {
	if p == uintptr(0) {
		return
	}
	_sqlite3Fts5ParserFinalize(tls, p)
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{freeProc})))(tls, p)
}

/*
** Return the peak depth of the stack for a parser.
 */

/* This array of booleans keeps track of the parser statement
** coverage.  The element fts5yycoverage[X][Y] is set when the parser
** is in state X and has a lookahead token Y.  In a well-tested
** systems, every element of this matrix should end up being set.
 */

/*
** Write into out a description of every state/lookahead combination that
**
**   (1)  has not been used by the parser, and
**   (2)  is not a syntax error.
**
** Return the number of missed state/lookahead combinations.
 */

// C documentation
//
//	/*
//	** Find the appropriate action for a parser given the terminal
//	** look-ahead token iLookAhead.
//	*/
func _fts5yy_find_shift_action(tls *libc.TLS, iLookAhead uint8, stateno uint8) (r uint8) {
	var i int32
	_ = i
	if int32(int32(stateno)) > int32(fts5YY_MAX_SHIFT) {
		return stateno
	}
	for cond := true; cond; cond = int32(1) != 0 {
		i = int32(_fts5yy_shift_ofst[stateno])
		i += int32(int32(iLookAhead))
		if int32(_fts5yy_lookahead[i]) != int32(int32(iLookAhead)) {
			return _fts5yy_default[stateno]
		} else {
			return _fts5yy_action[i]
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Find the appropriate action for a parser given the non-terminal
//	** look-ahead token iLookAhead.
//	*/
func _fts5yy_find_reduce_action(tls *libc.TLS, stateno uint8, iLookAhead uint8) (r uint8) {
	var i int32
	_ = i
	i = int32(_fts5yy_reduce_ofst[stateno])
	i += int32(int32(iLookAhead))
	return _fts5yy_action[i]
}

// C documentation
//
//	/*
//	** The following routine is called if the stack overflows.
//	*/
func _fts5yyStackOverflow(tls *libc.TLS, fts5yypParser uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	for (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos > (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack {
		_fts5yy_pop_parser_stack(tls, fts5yypParser)
	}
	/* Here code is inserted which will execute if the parser
	 ** stack every overflows */
	/******** Begin %stack_overflow code ******************************************/
	_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+36201, 0)
	/******** End %stack_overflow code ********************************************/
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse /* Suppress warning about unused %extra_argument var */
}

/*
** Print tracing information for a SHIFT action
 */

// C documentation
//
//	/*
//	** Perform a shift action.
//	*/
func _fts5yy_shift(tls *libc.TLS, fts5yypParser uintptr, fts5yyNewState uint8, fts5yyMajor uint8, fts5yyMinor TFts5Token) {
	var fts5yytos uintptr
	_ = fts5yytos
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos += 12
	fts5yytos = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos
	if fts5yytos > (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystackEnd {
		if int32(1) != 0 {
			(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos -= 12
			_fts5yyStackOverflow(tls, fts5yypParser)
			return
		}
		fts5yytos = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos
	}
	if int32(int32(fts5yyNewState)) > int32(fts5YY_MAX_SHIFT) {
		fts5yyNewState = uint8(int32(fts5yyNewState) + (libc.Int32FromInt32(fts5YY_MIN_REDUCE) - libc.Int32FromInt32(fts5YY_MIN_SHIFTREDUCE)))
	}
	(*Tfts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fstateno = fts5yyNewState
	(*Tfts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fmajor = fts5yyMajor
	*(*TFts5Token)(unsafe.Pointer(fts5yytos + 4)) = fts5yyMinor
}

// C documentation
//
//	/* For rule J, fts5yyRuleInfoLhs[J] contains the symbol on the left-hand side
//	** of that rule */
var _fts5yyRuleInfoLhs = [28]uint8{
	0:  uint8(16),
	1:  uint8(20),
	2:  uint8(20),
	3:  uint8(20),
	4:  uint8(20),
	5:  uint8(21),
	6:  uint8(21),
	7:  uint8(17),
	8:  uint8(17),
	9:  uint8(17),
	10: uint8(17),
	11: uint8(17),
	12: uint8(17),
	13: uint8(19),
	14: uint8(19),
	15: uint8(18),
	16: uint8(18),
	17: uint8(22),
	18: uint8(22),
	19: uint8(22),
	20: uint8(23),
	21: uint8(23),
	22: uint8(25),
	23: uint8(25),
	24: uint8(24),
	25: uint8(24),
	26: uint8(26),
	27: uint8(26),
}

// C documentation
//
//	/* For rule J, fts5yyRuleInfoNRhs[J] contains the negative of the number
//	** of symbols on the right-hand side of that rule. */
var _fts5yyRuleInfoNRhs = [28]int8{
	0:  int8(-int32(1)),
	1:  int8(-int32(4)),
	2:  int8(-int32(3)),
	3:  int8(-int32(1)),
	4:  int8(-int32(2)),
	5:  int8(-int32(2)),
	6:  int8(-int32(1)),
	7:  int8(-int32(3)),
	8:  int8(-int32(3)),
	9:  int8(-int32(3)),
	10: int8(-int32(5)),
	11: int8(-int32(3)),
	12: int8(-int32(1)),
	13: int8(-int32(1)),
	14: int8(-int32(2)),
	15: int8(-int32(1)),
	16: int8(-int32(3)),
	17: int8(-int32(1)),
	18: int8(-int32(2)),
	19: int8(-int32(5)),
	20: int8(-int32(1)),
	21: int8(-int32(2)),
	23: int8(-int32(2)),
	24: int8(-int32(4)),
	25: int8(-int32(2)),
	26: int8(-int32(1)),
}

// C documentation
//
//	/*
//	** Perform a reduce action and the shift that must immediately
//	** follow the reduce.
//	**
//	** The fts5yyLookahead and fts5yyLookaheadToken parameters provide reduce actions
//	** access to the lookahead token (if any).  The fts5yyLookahead will be fts5YYNOCODE
//	** 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 _fts5yy_reduce(tls *libc.TLS, fts5yypParser uintptr, fts5yyruleno uint32, fts5yyLookahead int32, fts5yyLookaheadToken TFts5Token) (r uint8) {
	var fts5yyact uint8
	var fts5yygoto, fts5yysize int32
	var fts5yylhsminor Tfts5YYMINORTYPE
	var fts5yymsp, pParse uintptr
	_, _, _, _, _, _ = fts5yyact, fts5yygoto, fts5yylhsminor, fts5yymsp, fts5yysize, pParse /* Amount to pop the stack */
	pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	_ = fts5yyLookahead
	_ = fts5yyLookaheadToken
	fts5yymsp = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos
	switch fts5yyruleno {
	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(5):
		goto _6
	case uint32(6):
		goto _7
	case uint32(7):
		goto _8
	case uint32(8):
		goto _9
	case uint32(9):
		goto _10
	case uint32(10):
		goto _11
	case uint32(11):
		goto _12
	case uint32(13):
		goto _13
	case uint32(12):
		goto _14
	case uint32(14):
		goto _15
	case uint32(15):
		goto _16
	case uint32(16):
		goto _17
	case uint32(17):
		goto _18
	case uint32(18):
		goto _19
	case uint32(19):
		goto _20
	case uint32(20):
		goto _21
	case uint32(21):
		goto _22
	case uint32(22):
		goto _23
	case uint32(23):
		goto _24
	case uint32(24):
		goto _25
	case uint32(25):
		goto _26
	case uint32(26):
		goto _27
	case uint32(27):
		goto _28
	default:
		goto _29
	}
	goto _30
_1:
	; /* input ::= expr */
	_sqlite3Fts5ParseFinished(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	goto _30
_2:
	; /* colset ::= MINUS LCP colsetlist RCP */
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3Fts5ParseColsetInvert(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _30
_3:
	; /* colset ::= LCP colsetlist RCP */
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _30
_4:
	; /* colset ::= STRING */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseColset(tls, pParse, uintptr(0), fts5yymsp+4)
	*(*uintptr)(unsafe.Pointer(fts5yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_5:
	; /* colset ::= MINUS STRING */
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3Fts5ParseColset(tls, pParse, uintptr(0), fts5yymsp+4)
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3Fts5ParseColsetInvert(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
	goto _30
_6:
	; /* colsetlist ::= colsetlist STRING */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseColset(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), fts5yymsp+4)
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_7:
	; /* colsetlist ::= STRING */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseColset(tls, pParse, uintptr(0), fts5yymsp+4)
	*(*uintptr)(unsafe.Pointer(fts5yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_8:
	; /* expr ::= expr AND expr */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_AND), *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)), uintptr(0))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_9:
	; /* expr ::= expr OR expr */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_OR), *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)), uintptr(0))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_10:
	; /* expr ::= expr NOT expr */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_NOT), *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)), uintptr(0))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_11:
	; /* expr ::= colset COLON LP expr RP */
	_sqlite3Fts5ParseSetColset(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_12:
	; /* expr ::= LP expr RP */
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
	goto _30
_14:
	; /* expr ::= exprlist */
_13:
	;
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + 4))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_15:
	; /* exprlist ::= exprlist cnearset */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseImplicitAnd(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_16:
	; /* cnearset ::= nearset */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_STRING), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_17:
	; /* cnearset ::= colset COLON nearset */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_STRING), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	_sqlite3Fts5ParseSetColset(tls, pParse, *(*uintptr)(unsafe.Pointer(&fts5yylhsminor)), *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_18:
	; /* nearset ::= phrase */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_19:
	; /* nearset ::= CARET phrase */
	_sqlite3Fts5ParseSetCaret(tls, *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	goto _30
_20:
	; /* nearset ::= STRING LP nearphrases neardist_opt RP */
	_sqlite3Fts5ParseNear(tls, pParse, fts5yymsp+uintptr(-libc.Int32FromInt32(4))*12+4)
	_sqlite3Fts5ParseSetDistance(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), fts5yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_21:
	; /* nearphrases ::= phrase */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_22:
	; /* nearphrases ::= nearphrases phrase */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseNearset(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_23:
	; /* neardist_opt ::= */
	*(*uintptr)(unsafe.Pointer(fts5yymsp + 1*12 + 4)) = uintptr(0)
	*(*int32)(unsafe.Pointer(fts5yymsp + 1*12 + 4 + 4)) = 0
	goto _30
_24:
	; /* neardist_opt ::= COMMA STRING */
	*(*TFts5Token)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TFts5Token)(unsafe.Pointer(fts5yymsp + 4))
	goto _30
_25:
	; /* phrase ::= phrase PLUS STRING star_opt */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), fts5yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*int32)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_26:
	; /* phrase ::= STRING star_opt */
	*(*uintptr)(unsafe.Pointer(&fts5yylhsminor)) = _sqlite3Fts5ParseTerm(tls, pParse, uintptr(0), fts5yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*int32)(unsafe.Pointer(fts5yymsp + 4)))
	*(*uintptr)(unsafe.Pointer(fts5yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&fts5yylhsminor))
	goto _30
_27:
	; /* star_opt ::= STAR */
	*(*int32)(unsafe.Pointer(fts5yymsp + 4)) = int32(1)
	goto _30
_28:
	; /* star_opt ::= */
	*(*int32)(unsafe.Pointer(fts5yymsp + 1*12 + 4)) = 0
	goto _30
_29:
	;
	goto _30
	/********** End reduce actions ************************************************/
_30:
	;
	fts5yygoto = int32(_fts5yyRuleInfoLhs[fts5yyruleno])
	fts5yysize = int32(_fts5yyRuleInfoNRhs[fts5yyruleno])
	fts5yyact = _fts5yy_find_reduce_action(tls, (*(*Tfts5yyStackEntry)(unsafe.Pointer(fts5yymsp + uintptr(fts5yysize)*12))).Fstateno, uint8(uint8(fts5yygoto)))
	/* 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 */
	fts5yymsp += uintptr(fts5yysize+int32(1)) * 12
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos = fts5yymsp
	(*Tfts5yyStackEntry)(unsafe.Pointer(fts5yymsp)).Fstateno = fts5yyact
	(*Tfts5yyStackEntry)(unsafe.Pointer(fts5yymsp)).Fmajor = uint8(uint8(fts5yygoto))
	return fts5yyact
}

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

// C documentation
//
//	/*
//	** The following code executes when a syntax error first occurs.
//	*/
func _fts5yy_syntax_error(tls *libc.TLS, fts5yypParser uintptr, fts5yymajor int32, fts5yyminor TFts5Token) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pParse uintptr
	_ = pParse
	pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	/************ Begin %syntax_error code ****************************************/
	_ = fts5yymajor /* Silence a compiler warning */
	_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+36229, libc.VaList(bp+8, fts5yyminor.Fn, fts5yyminor.Fp))
	/************ End %syntax_error code ******************************************/
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse /* Suppress warning about unused %extra_argument variable */
}

// C documentation
//
//	/*
//	** The following is executed when the parser accepts
//	*/
func _fts5yy_accept(tls *libc.TLS, fts5yypParser uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	/* Here code is inserted which will be executed whenever the
	 ** parser accepts */
	/*********** Begin %parse_accept code *****************************************/
	/*********** End %parse_accept code *******************************************/
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse /* Suppress warning about unused %extra_argument variable */
}

// C documentation
//
//	/* The main parser program.
//	** The first argument is a pointer to a structure obtained from
//	** "sqlite3Fts5ParserAlloc" which describes the current state of the parser.
//	** The second argument is the major token number.  The third is
//	** the minor token.  The fourth optional argument is whatever the
//	** user wants (and specified in the grammar) and is available for
//	** use by the action routines.
//	**
//	** Inputs:
//	** <ul>
//	** <li> A pointer to the parser (an opaque structure.)
//	** <li> The major token number.
//	** <li> The minor token number.
//	** <li> An option argument of a grammar-specified type.
//	** </ul>
//	**
//	** Outputs:
//	** None.
//	*/
func _sqlite3Fts5Parser(tls *libc.TLS, fts5yyp uintptr, fts5yymajor int32, fts5yyminor TFts5Token, pParse uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var fts5yyact uint8
	var fts5yypParser uintptr
	var fts5yyruleno uint32
	var _ /* fts5yyminorunion at bp+0 */ Tfts5YYMINORTYPE
	_, _, _ = fts5yyact, fts5yypParser, fts5yyruleno /* The parser action. */
	fts5yypParser = fts5yyp                          /* The parser */
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse
	fts5yyact = (*Tfts5yyStackEntry)(unsafe.Pointer((*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos)).Fstateno
	for int32(1) != 0 { /* Exit by "break" */
		fts5yyact = _fts5yy_find_shift_action(tls, uint8(uint8(fts5yymajor)), fts5yyact)
		if int32(int32(fts5yyact)) >= int32(fts5YY_MIN_REDUCE) {
			fts5yyruleno = uint32(int32(int32(fts5yyact)) - int32(fts5YY_MIN_REDUCE)) /* Reduce by this rule */
			/* Check that the stack is large enough to grow by a single entry
			 ** if the RHS of the rule is empty.  This ensures that there is room
			 ** enough on the stack to push the LHS value */
			if int32(_fts5yyRuleInfoNRhs[fts5yyruleno]) == 0 {
				if (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos >= (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystackEnd {
					if int32(1) != 0 {
						_fts5yyStackOverflow(tls, fts5yypParser)
						break
					}
				}
			}
			fts5yyact = _fts5yy_reduce(tls, fts5yypParser, fts5yyruleno, fts5yymajor, fts5yyminor)
		} else {
			if int32(int32(fts5yyact)) <= int32(fts5YY_MAX_SHIFTREDUCE) {
				_fts5yy_shift(tls, fts5yypParser, fts5yyact, uint8(uint8(fts5yymajor)), fts5yyminor)
				break
			} else {
				if int32(int32(fts5yyact)) == int32(fts5YY_ACCEPT_ACTION) {
					(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos -= 12
					_fts5yy_accept(tls, fts5yypParser)
					return
				} else {
					*(*TFts5Token)(unsafe.Pointer(bp)) = fts5yyminor
					/* If the fts5YYNOERRORRECOVERY macro is defined, then do not attempt to
					 ** do any kind of error recovery.  Instead, simply invoke the syntax
					 ** error routine and continue going as if nothing had happened.
					 **
					 ** Applications can set this macro (for example inside %include) if
					 ** they intend to abandon the parse upon the first syntax error seen.
					 */
					_fts5yy_syntax_error(tls, fts5yypParser, fts5yymajor, fts5yyminor)
					_fts5yy_destructor(tls, fts5yypParser, uint8(uint8(fts5yymajor)), bp)
					break
				}
			}
		}
	}
	return
}

// C documentation
//
//	/*
//	** Return the fallback token corresponding to canonical token iToken, or
//	** 0 if iToken has no fallback.
//	*/
func _sqlite3Fts5ParserFallback(tls *libc.TLS, iToken int32) (r int32) {
	_ = iToken
	return 0
}

/*
** 2014 May 31
**
** 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 "fts5Int.h" */
/**
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is part of the mingw-w64 runtime package.
 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 */

// C documentation
//
//	/*
//	** Object used to iterate through all "coalesced phrase instances" in
//	** a single column of the current row. If the phrase instances in the
//	** column being considered do not overlap, this object simply iterates
//	** through them. Or, if they do overlap (share one or more tokens in
//	** common), each set of overlapping instances is treated as a single
//	** match. See documentation for the highlight() auxiliary function for
//	** details.
//	**
//	** Usage is:
//	**
//	**   for(rc = fts5CInstIterNext(pApi, pFts, iCol, &iter);
//	**      (rc==SQLITE_OK && 0==fts5CInstIterEof(&iter);
//	**      rc = fts5CInstIterNext(&iter)
//	**   ){
//	**     printf("instance starts at %d, ends at %d\n", iter.iStart, iter.iEnd);
//	**   }
//	**
//	*/
type TCInstIter = struct {
	FpApi   uintptr
	FpFts   uintptr
	FiCol   int32
	FiInst  int32
	FnInst  int32
	FiStart int32
	FiEnd   int32
}

type CInstIter = TCInstIter

type TCInstIter1 = struct {
	FpApi   uintptr
	FpFts   uintptr
	FiCol   int32
	FiInst  int32
	FnInst  int32
	FiStart int32
	FiEnd   int32
}

type CInstIter1 = TCInstIter1

// C documentation
//
//	/*
//	** Advance the iterator to the next coalesced phrase instance. Return
//	** an SQLite error code if an error occurs, or SQLITE_OK otherwise.
//	*/
func _fts5CInstIterNext(tls *libc.TLS, pIter uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iEnd, rc int32
	var _ /* ic at bp+4 */ int32
	var _ /* io at bp+8 */ int32
	var _ /* ip at bp+0 */ int32
	_, _ = iEnd, rc
	rc = SQLITE_OK
	(*TCInstIter)(unsafe.Pointer(pIter)).FiStart = -int32(1)
	(*TCInstIter)(unsafe.Pointer(pIter)).FiEnd = -int32(1)
	for rc == SQLITE_OK && (*TCInstIter)(unsafe.Pointer(pIter)).FiInst < (*TCInstIter)(unsafe.Pointer(pIter)).FnInst {
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer((*TCInstIter)(unsafe.Pointer(pIter)).FpApi)).FxInst})))(tls, (*TCInstIter)(unsafe.Pointer(pIter)).FpFts, (*TCInstIter)(unsafe.Pointer(pIter)).FiInst, bp, bp+4, bp+8)
		if rc == SQLITE_OK {
			if *(*int32)(unsafe.Pointer(bp + 4)) == (*TCInstIter)(unsafe.Pointer(pIter)).FiCol {
				iEnd = *(*int32)(unsafe.Pointer(bp + 8)) - int32(1) + (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer((*TCInstIter)(unsafe.Pointer(pIter)).FpApi)).FxPhraseSize})))(tls, (*TCInstIter)(unsafe.Pointer(pIter)).FpFts, *(*int32)(unsafe.Pointer(bp)))
				if (*TCInstIter)(unsafe.Pointer(pIter)).FiStart < 0 {
					(*TCInstIter)(unsafe.Pointer(pIter)).FiStart = *(*int32)(unsafe.Pointer(bp + 8))
					(*TCInstIter)(unsafe.Pointer(pIter)).FiEnd = iEnd
				} else {
					if *(*int32)(unsafe.Pointer(bp + 8)) <= (*TCInstIter)(unsafe.Pointer(pIter)).FiEnd {
						if iEnd > (*TCInstIter)(unsafe.Pointer(pIter)).FiEnd {
							(*TCInstIter)(unsafe.Pointer(pIter)).FiEnd = iEnd
						}
					} else {
						break
					}
				}
			}
			(*TCInstIter)(unsafe.Pointer(pIter)).FiInst++
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Initialize the iterator object indicated by the final parameter to
//	** iterate through coalesced phrase instances in column iCol.
//	*/
func _fts5CInstIterInit(tls *libc.TLS, pApi uintptr, pFts uintptr, iCol int32, pIter uintptr) (r int32) {
	var rc int32
	_ = rc
	libc.Xmemset(tls, pIter, 0, uint32(28))
	(*TCInstIter)(unsafe.Pointer(pIter)).FpApi = pApi
	(*TCInstIter)(unsafe.Pointer(pIter)).FpFts = pFts
	(*TCInstIter)(unsafe.Pointer(pIter)).FiCol = iCol
	rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, pIter+16)
	if rc == SQLITE_OK {
		rc = _fts5CInstIterNext(tls, pIter)
	}
	return rc
}

// C documentation
//
//	/*************************************************************************
//	** Start of highlight() implementation.
//	*/
type THighlightContext = struct {
	FiRangeStart int32
	FiRangeEnd   int32
	FzOpen       uintptr
	FzClose      uintptr
	FzIn         uintptr
	FnIn         int32
	Fiter        TCInstIter
	FiPos        int32
	FiOff        int32
	FbOpen       int32
	FzOut        uintptr
}

type HighlightContext = THighlightContext

type THighlightContext1 = struct {
	FiRangeStart int32
	FiRangeEnd   int32
	FzOpen       uintptr
	FzClose      uintptr
	FzIn         uintptr
	FnIn         int32
	Fiter        TCInstIter
	FiPos        int32
	FiOff        int32
	FbOpen       int32
	FzOut        uintptr
}

type HighlightContext1 = THighlightContext1

// C documentation
//
//	/*
//	** Append text to the HighlightContext output string - p->zOut. Argument
//	** z points to a buffer containing n bytes of text to append. If n is
//	** negative, everything up until the first '\0' is appended to the output.
//	**
//	** If *pRc is set to any value other than SQLITE_OK when this function is
//	** called, it is a no-op. If an error (i.e. an OOM condition) is encountered,
//	** *pRc is set to an error code before returning.
//	*/
func _fts5HighlightAppend(tls *libc.TLS, pRc uintptr, p uintptr, z uintptr, n int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK && z != 0 {
		if n < 0 {
			n = int32(libc.Xstrlen(tls, z))
		}
		(*THighlightContext)(unsafe.Pointer(p)).FzOut = Xsqlite3_mprintf(tls, __ccgo_ts+36260, libc.VaList(bp+8, (*THighlightContext)(unsafe.Pointer(p)).FzOut, n, z))
		if (*THighlightContext)(unsafe.Pointer(p)).FzOut == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		}
	}
}

// C documentation
//
//	/*
//	** Tokenizer callback used by implementation of highlight() function.
//	*/
func _fts5HighlightCb(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iStartOff int32, iEndOff int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPos, v1 int32
	var p, v2 uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = iPos, p, v1, v2
	p = pContext
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	_ = pToken
	_ = nToken
	if tflags&int32(FTS5_TOKEN_COLOCATED) != 0 {
		return SQLITE_OK
	}
	v2 = p + 52
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	iPos = v1
	if (*THighlightContext)(unsafe.Pointer(p)).FiRangeEnd >= 0 {
		if iPos < (*THighlightContext)(unsafe.Pointer(p)).FiRangeStart || iPos > (*THighlightContext)(unsafe.Pointer(p)).FiRangeEnd {
			return SQLITE_OK
		}
		if (*THighlightContext)(unsafe.Pointer(p)).FiRangeStart != 0 && iPos == (*THighlightContext)(unsafe.Pointer(p)).FiRangeStart {
			(*THighlightContext)(unsafe.Pointer(p)).FiOff = iStartOff
		}
	}
	/* If the parenthesis is open, and this token is not part of the current
	 ** phrase, and the starting byte offset of this token is past the point
	 ** that has currently been copied into the output buffer, close the
	 ** parenthesis. */
	if (*THighlightContext)(unsafe.Pointer(p)).FbOpen != 0 && (iPos <= (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart || (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart < 0) && iStartOff > (*THighlightContext)(unsafe.Pointer(p)).FiOff {
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzClose, -int32(1))
		(*THighlightContext)(unsafe.Pointer(p)).FbOpen = 0
	}
	/* If this is the start of a new phrase, and the highlight is not open:
	 **
	 **   * copy text from the input up to the start of the phrase, and
	 **   * open the highlight.
	 */
	if iPos == (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart && (*THighlightContext)(unsafe.Pointer(p)).FbOpen == 0 {
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iStartOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzOpen, -int32(1))
		(*THighlightContext)(unsafe.Pointer(p)).FiOff = iStartOff
		(*THighlightContext)(unsafe.Pointer(p)).FbOpen = int32(1)
	}
	if iPos == (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiEnd {
		if (*THighlightContext)(unsafe.Pointer(p)).FbOpen == 0 {
			_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzOpen, -int32(1))
			(*THighlightContext)(unsafe.Pointer(p)).FbOpen = int32(1)
		}
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
		(*THighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = _fts5CInstIterNext(tls, p+24)
		}
	}
	if iPos == (*THighlightContext)(unsafe.Pointer(p)).FiRangeEnd {
		if (*THighlightContext)(unsafe.Pointer(p)).FbOpen != 0 {
			if (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart >= 0 && iPos >= (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart {
				_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
				(*THighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
			}
			_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzClose, -int32(1))
			(*THighlightContext)(unsafe.Pointer(p)).FbOpen = 0
		}
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
		(*THighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Implementation of highlight() function.
//	*/
func _fts5HighlightFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var iCol int32
	var zErr uintptr
	var _ /* ctx at bp+0 */ THighlightContext
	var _ /* rc at bp+68 */ int32
	_, _ = iCol, zErr
	if nVal != int32(3) {
		zErr = __ccgo_ts + 36267
		Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
		return
	}
	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	libc.Xmemset(tls, bp, 0, uint32(68))
	(*(*THighlightContext)(unsafe.Pointer(bp))).FzOpen = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4)))
	(*(*THighlightContext)(unsafe.Pointer(bp))).FzClose = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + 2*4)))
	(*(*THighlightContext)(unsafe.Pointer(bp))).FiRangeEnd = -int32(1)
	*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, iCol, bp+16, bp+20)
	if *(*int32)(unsafe.Pointer(bp + 68)) == int32(SQLITE_RANGE) {
		Xsqlite3_result_text(tls, pCtx, __ccgo_ts+1672, -int32(1), libc.UintptrFromInt32(0))
		*(*int32)(unsafe.Pointer(bp + 68)) = SQLITE_OK
	} else {
		if (*(*THighlightContext)(unsafe.Pointer(bp))).FzIn != 0 {
			if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp + 68)) = _fts5CInstIterInit(tls, pApi, pFts, iCol, bp+24)
			}
			if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize})))(tls, pFts, (*(*THighlightContext)(unsafe.Pointer(bp))).FzIn, (*(*THighlightContext)(unsafe.Pointer(bp))).FnIn, bp, __ccgo_fp(_fts5HighlightCb))
			}
			if (*(*THighlightContext)(unsafe.Pointer(bp))).FbOpen != 0 {
				_fts5HighlightAppend(tls, bp+68, bp, (*(*THighlightContext)(unsafe.Pointer(bp))).FzClose, -int32(1))
			}
			_fts5HighlightAppend(tls, bp+68, bp, (*(*THighlightContext)(unsafe.Pointer(bp))).FzIn+uintptr((*(*THighlightContext)(unsafe.Pointer(bp))).FiOff), (*(*THighlightContext)(unsafe.Pointer(bp))).FnIn-(*(*THighlightContext)(unsafe.Pointer(bp))).FiOff)
			if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
				Xsqlite3_result_text(tls, pCtx, (*(*THighlightContext)(unsafe.Pointer(bp))).FzOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
			}
			Xsqlite3_free(tls, (*(*THighlightContext)(unsafe.Pointer(bp))).FzOut)
		}
	}
	if *(*int32)(unsafe.Pointer(bp + 68)) != SQLITE_OK {
		Xsqlite3_result_error_code(tls, pCtx, *(*int32)(unsafe.Pointer(bp + 68)))
	}
}

/*
** End of highlight() implementation.
**************************************************************************/

// C documentation
//
//	/*
//	** Context object passed to the fts5SentenceFinderCb() function.
//	*/
type TFts5SFinder = struct {
	FiPos        int32
	FnFirstAlloc int32
	FnFirst      int32
	FaFirst      uintptr
	FzDoc        uintptr
}

type Fts5SFinder = TFts5SFinder

type TFts5SFinder1 = struct {
	FiPos        int32
	FnFirstAlloc int32
	FnFirst      int32
	FaFirst      uintptr
	FzDoc        uintptr
}

type Fts5SFinder1 = TFts5SFinder1

// C documentation
//
//	/*
//	** Add an entry to the Fts5SFinder.aFirst[] array. Grow the array if
//	** necessary. Return SQLITE_OK if successful, or SQLITE_NOMEM if an
//	** error occurs.
//	*/
func _fts5SentenceFinderAdd(tls *libc.TLS, p uintptr, iAdd int32) (r int32) {
	var aNew, v3 uintptr
	var nNew, v1, v2 int32
	_, _, _, _, _ = aNew, nNew, v1, v2, v3
	if (*TFts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc == (*TFts5SFinder)(unsafe.Pointer(p)).FnFirst {
		if (*TFts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc != 0 {
			v1 = (*TFts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc * int32(2)
		} else {
			v1 = int32(64)
		}
		nNew = v1
		aNew = Xsqlite3_realloc64(tls, (*TFts5SFinder)(unsafe.Pointer(p)).FaFirst, uint64(uint32(uint32(nNew))*uint32(4)))
		if aNew == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		(*TFts5SFinder)(unsafe.Pointer(p)).FaFirst = aNew
		(*TFts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc = nNew
	}
	v3 = p + 8
	v2 = *(*int32)(unsafe.Pointer(v3))
	*(*int32)(unsafe.Pointer(v3))++
	*(*int32)(unsafe.Pointer((*TFts5SFinder)(unsafe.Pointer(p)).FaFirst + uintptr(v2)*4)) = iAdd
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function is an xTokenize() callback used by the auxiliary snippet()
//	** function. Its job is to identify tokens that are the first in a sentence.
//	** For each such token, an entry is added to the SFinder.aFirst[] array.
//	*/
func _fts5SentenceFinderCb(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iStartOff int32, iEndOff int32) (r int32) {
	var c int8
	var i, rc int32
	var p uintptr
	_, _, _, _ = c, i, p, rc
	rc = SQLITE_OK
	_ = pToken
	_ = nToken
	_ = iEndOff
	if tflags&int32(FTS5_TOKEN_COLOCATED) == 0 {
		p = pContext
		if (*TFts5SFinder)(unsafe.Pointer(p)).FiPos > 0 {
			c = 0
			i = iStartOff - int32(1)
			for {
				if !(i >= 0) {
					break
				}
				c = *(*int8)(unsafe.Pointer((*TFts5SFinder)(unsafe.Pointer(p)).FzDoc + uintptr(i)))
				if int32(int32(c)) != int32(' ') && int32(int32(c)) != int32('\t') && int32(int32(c)) != int32('\n') && int32(int32(c)) != int32('\r') {
					break
				}
				goto _1
			_1:
				;
				i--
			}
			if i != iStartOff-int32(1) && (int32(int32(c)) == int32('.') || int32(int32(c)) == int32(':')) {
				rc = _fts5SentenceFinderAdd(tls, p, (*TFts5SFinder)(unsafe.Pointer(p)).FiPos)
			}
		} else {
			rc = _fts5SentenceFinderAdd(tls, p, 0)
		}
		(*TFts5SFinder)(unsafe.Pointer(p)).FiPos++
	}
	return rc
}

func _fts5SnippetScore(tls *libc.TLS, pApi uintptr, pFts uintptr, nDocsize int32, aSeen uintptr, iCol int32, iPos int32, nToken int32, pnScore uintptr, piPos uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iFirst, iLast, nScore, rc, v2 int32
	var iAdj, iEnd Tsqlite3_int64
	var _ /* iOff at bp+8 */ int32
	var _ /* ic at bp+4 */ int32
	var _ /* ip at bp+0 */ int32
	var _ /* nInst at bp+12 */ int32
	_, _, _, _, _, _, _, _ = i, iAdj, iEnd, iFirst, iLast, nScore, rc, v2
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	iFirst = -int32(1)
	nScore = 0
	iLast = 0
	iEnd = int64(int64(iPos)) + int64(int64(nToken))
	rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, bp+12)
	i = 0
	for {
		if !(i < *(*int32)(unsafe.Pointer(bp + 12)) && rc == SQLITE_OK) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})))(tls, pFts, i, bp, bp+4, bp+8)
		if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 4)) == iCol && *(*int32)(unsafe.Pointer(bp + 8)) >= iPos && int64(*(*int32)(unsafe.Pointer(bp + 8))) < iEnd {
			if *(*uint8)(unsafe.Pointer(aSeen + uintptr(*(*int32)(unsafe.Pointer(bp))))) != 0 {
				v2 = int32(1)
			} else {
				v2 = int32(1000)
			}
			nScore += v2
			*(*uint8)(unsafe.Pointer(aSeen + uintptr(*(*int32)(unsafe.Pointer(bp))))) = uint8(1)
			if iFirst < 0 {
				iFirst = *(*int32)(unsafe.Pointer(bp + 8))
			}
			iLast = *(*int32)(unsafe.Pointer(bp + 8)) + (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseSize})))(tls, pFts, *(*int32)(unsafe.Pointer(bp)))
		}
		goto _1
	_1:
		;
		i++
	}
	*(*int32)(unsafe.Pointer(pnScore)) = nScore
	if piPos != 0 {
		iAdj = int64(iFirst - (nToken-(iLast-iFirst))/int32(2))
		if iAdj+int64(int64(nToken)) > int64(int64(nDocsize)) {
			iAdj = int64(nDocsize - nToken)
		}
		if iAdj < 0 {
			iAdj = 0
		}
		*(*int32)(unsafe.Pointer(piPos)) = int32(int32(iAdj))
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the value in pVal interpreted as utf-8 text. Except, if pVal
//	** contains a NULL value, return a pointer to a static string zero
//	** bytes in length instead of a NULL pointer.
//	*/
func _fts5ValueToText(tls *libc.TLS, pVal uintptr) (r uintptr) {
	var zRet, v1 uintptr
	_, _ = zRet, v1
	zRet = Xsqlite3_value_text(tls, pVal)
	if zRet != 0 {
		v1 = zRet
	} else {
		v1 = __ccgo_ts + 1672
	}
	return v1
}

// C documentation
//
//	/*
//	** Implementation of snippet() function.
//	*/
func _fts5SnippetFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var aSeen, zEllips, zErr uintptr
	var i, iBestCol, iBestStart, iCol, ii, jj, nBestScore, nCol, nPhrase, nToken, v1, v5 int32
	var _ /* ctx at bp+0 */ THighlightContext
	var _ /* iAdj at bp+120 */ int32
	var _ /* ic at bp+112 */ int32
	var _ /* io at bp+116 */ int32
	var _ /* ip at bp+108 */ int32
	var _ /* nColSize at bp+76 */ int32
	var _ /* nDoc at bp+100 */ int32
	var _ /* nDocsize at bp+104 */ int32
	var _ /* nInst at bp+72 */ int32
	var _ /* nScore at bp+124 */ int32
	var _ /* rc at bp+68 */ int32
	var _ /* sFinder at bp+80 */ TFts5SFinder
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aSeen, i, iBestCol, iBestStart, iCol, ii, jj, nBestScore, nCol, nPhrase, nToken, zEllips, zErr, v1, v5
	*(*int32)(unsafe.Pointer(bp + 68)) = SQLITE_OK /* 5th argument to snippet() */
	*(*int32)(unsafe.Pointer(bp + 72)) = 0         /* Column containing best snippet */
	iBestStart = 0                                 /* First token of best snippet */
	nBestScore = 0                                 /* Score of best snippet */
	*(*int32)(unsafe.Pointer(bp + 76)) = 0
	if nVal != int32(5) {
		zErr = __ccgo_ts + 36317
		Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
		return
	}
	nCol = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnCount})))(tls, pFts)
	libc.Xmemset(tls, bp, 0, uint32(68))
	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	(*(*THighlightContext)(unsafe.Pointer(bp))).FzOpen = _fts5ValueToText(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4)))
	(*(*THighlightContext)(unsafe.Pointer(bp))).FzClose = _fts5ValueToText(tls, *(*uintptr)(unsafe.Pointer(apVal + 2*4)))
	(*(*THighlightContext)(unsafe.Pointer(bp))).FiRangeEnd = -int32(1)
	zEllips = _fts5ValueToText(tls, *(*uintptr)(unsafe.Pointer(apVal + 3*4)))
	nToken = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal + 4*4)))
	if iCol >= 0 {
		v1 = iCol
	} else {
		v1 = 0
	}
	iBestCol = v1
	nPhrase = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseCount})))(tls, pFts)
	aSeen = Xsqlite3_malloc(tls, nPhrase)
	if aSeen == uintptr(0) {
		*(*int32)(unsafe.Pointer(bp + 68)) = int32(SQLITE_NOMEM)
	}
	if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, bp+72)
	}
	libc.Xmemset(tls, bp+80, 0, uint32(20))
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		if iCol < 0 || iCol == i {
			(*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FiPos = 0
			(*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FnFirst = 0
			*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, i, bp+80+16, bp+100)
			if *(*int32)(unsafe.Pointer(bp + 68)) != SQLITE_OK {
				break
			}
			*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize})))(tls, pFts, (*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FzDoc, *(*int32)(unsafe.Pointer(bp + 100)), bp+80, __ccgo_fp(_fts5SentenceFinderCb))
			if *(*int32)(unsafe.Pointer(bp + 68)) != SQLITE_OK {
				break
			}
			*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, i, bp+104)
			if *(*int32)(unsafe.Pointer(bp + 68)) != SQLITE_OK {
				break
			}
			ii = 0
			for {
				if !(*(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK && ii < *(*int32)(unsafe.Pointer(bp + 72))) {
					break
				}
				*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})))(tls, pFts, ii, bp+108, bp+112, bp+116)
				if *(*int32)(unsafe.Pointer(bp + 112)) != i {
					goto _3
				}
				if *(*int32)(unsafe.Pointer(bp + 116)) > *(*int32)(unsafe.Pointer(bp + 104)) {
					*(*int32)(unsafe.Pointer(bp + 68)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				if *(*int32)(unsafe.Pointer(bp + 68)) != SQLITE_OK {
					goto _3
				}
				libc.Xmemset(tls, aSeen, 0, uint32(uint32(nPhrase)))
				*(*int32)(unsafe.Pointer(bp + 68)) = _fts5SnippetScore(tls, pApi, pFts, *(*int32)(unsafe.Pointer(bp + 104)), aSeen, i, *(*int32)(unsafe.Pointer(bp + 116)), nToken, bp+124, bp+120)
				if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 124)) > nBestScore {
					nBestScore = *(*int32)(unsafe.Pointer(bp + 124))
					iBestCol = i
					iBestStart = *(*int32)(unsafe.Pointer(bp + 120))
					*(*int32)(unsafe.Pointer(bp + 76)) = *(*int32)(unsafe.Pointer(bp + 104))
				}
				if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK && (*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FnFirst != 0 && *(*int32)(unsafe.Pointer(bp + 104)) > nToken {
					jj = 0
					for {
						if !(jj < (*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FnFirst-int32(1)) {
							break
						}
						if *(*int32)(unsafe.Pointer((*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FaFirst + uintptr(jj+int32(1))*4)) > *(*int32)(unsafe.Pointer(bp + 116)) {
							break
						}
						goto _4
					_4:
						;
						jj++
					}
					if *(*int32)(unsafe.Pointer((*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FaFirst + uintptr(jj)*4)) < *(*int32)(unsafe.Pointer(bp + 116)) {
						libc.Xmemset(tls, aSeen, 0, uint32(uint32(nPhrase)))
						*(*int32)(unsafe.Pointer(bp + 68)) = _fts5SnippetScore(tls, pApi, pFts, *(*int32)(unsafe.Pointer(bp + 104)), aSeen, i, *(*int32)(unsafe.Pointer((*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FaFirst + uintptr(jj)*4)), nToken, bp+124, uintptr(0))
						if *(*int32)(unsafe.Pointer((*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FaFirst + uintptr(jj)*4)) == 0 {
							v5 = int32(120)
						} else {
							v5 = int32(100)
						}
						*(*int32)(unsafe.Pointer(bp + 124)) += v5
						if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 124)) > nBestScore {
							nBestScore = *(*int32)(unsafe.Pointer(bp + 124))
							iBestCol = i
							iBestStart = *(*int32)(unsafe.Pointer((*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FaFirst + uintptr(jj)*4))
							*(*int32)(unsafe.Pointer(bp + 76)) = *(*int32)(unsafe.Pointer(bp + 104))
						}
					}
				}
				goto _3
			_3:
				;
				ii++
			}
		}
		goto _2
	_2:
		;
		i++
	}
	if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, iBestCol, bp+16, bp+20)
	}
	if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 76)) == 0 {
		*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, iBestCol, bp+76)
	}
	if (*(*THighlightContext)(unsafe.Pointer(bp))).FzIn != 0 {
		if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 68)) = _fts5CInstIterInit(tls, pApi, pFts, iBestCol, bp+24)
		}
		(*(*THighlightContext)(unsafe.Pointer(bp))).FiRangeStart = iBestStart
		(*(*THighlightContext)(unsafe.Pointer(bp))).FiRangeEnd = iBestStart + nToken - int32(1)
		if iBestStart > 0 {
			_fts5HighlightAppend(tls, bp+68, bp, zEllips, -int32(1))
		}
		/* Advance iterator ctx.iter so that it points to the first coalesced
		 ** phrase instance at or following position iBestStart. */
		for (*(*THighlightContext)(unsafe.Pointer(bp))).Fiter.FiStart >= 0 && (*(*THighlightContext)(unsafe.Pointer(bp))).Fiter.FiStart < iBestStart && *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 68)) = _fts5CInstIterNext(tls, bp+24)
		}
		if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 68)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize})))(tls, pFts, (*(*THighlightContext)(unsafe.Pointer(bp))).FzIn, (*(*THighlightContext)(unsafe.Pointer(bp))).FnIn, bp, __ccgo_fp(_fts5HighlightCb))
		}
		if (*(*THighlightContext)(unsafe.Pointer(bp))).FbOpen != 0 {
			_fts5HighlightAppend(tls, bp+68, bp, (*(*THighlightContext)(unsafe.Pointer(bp))).FzClose, -int32(1))
		}
		if (*(*THighlightContext)(unsafe.Pointer(bp))).FiRangeEnd >= *(*int32)(unsafe.Pointer(bp + 76))-int32(1) {
			_fts5HighlightAppend(tls, bp+68, bp, (*(*THighlightContext)(unsafe.Pointer(bp))).FzIn+uintptr((*(*THighlightContext)(unsafe.Pointer(bp))).FiOff), (*(*THighlightContext)(unsafe.Pointer(bp))).FnIn-(*(*THighlightContext)(unsafe.Pointer(bp))).FiOff)
		} else {
			_fts5HighlightAppend(tls, bp+68, bp, zEllips, -int32(1))
		}
	}
	if *(*int32)(unsafe.Pointer(bp + 68)) == SQLITE_OK {
		Xsqlite3_result_text(tls, pCtx, (*(*THighlightContext)(unsafe.Pointer(bp))).FzOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
	} else {
		Xsqlite3_result_error_code(tls, pCtx, *(*int32)(unsafe.Pointer(bp + 68)))
	}
	Xsqlite3_free(tls, (*(*THighlightContext)(unsafe.Pointer(bp))).FzOut)
	Xsqlite3_free(tls, aSeen)
	Xsqlite3_free(tls, (*(*TFts5SFinder)(unsafe.Pointer(bp + 80))).FaFirst)
}

/************************************************************************/

// C documentation
//
//	/*
//	** The first time the bm25() function is called for a query, an instance
//	** of the following structure is allocated and populated.
//	*/
type TFts5Bm25Data = struct {
	F__ccgo_align  [0]uint32
	FnPhrase       int32
	F__ccgo_align1 [4]byte
	Favgdl         float64
	FaIDF          uintptr
	FaFreq         uintptr
}

type Fts5Bm25Data = TFts5Bm25Data

type TFts5Bm25Data1 = struct {
	F__ccgo_align  [0]uint32
	FnPhrase       int32
	F__ccgo_align1 [4]byte
	Favgdl         float64
	FaIDF          uintptr
	FaFreq         uintptr
}

type Fts5Bm25Data1 = TFts5Bm25Data1

// C documentation
//
//	/*
//	** Callback used by fts5Bm25GetData() to count the number of rows in the
//	** table matched by each individual phrase within the query.
//	*/
func _fts5CountCb(tls *libc.TLS, pApi uintptr, pFts uintptr, pUserData uintptr) (r int32) {
	var pn uintptr
	_ = pn
	pn = pUserData
	_ = pApi
	_ = pFts
	*(*Tsqlite3_int64)(unsafe.Pointer(pn))++
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Set *ppData to point to the Fts5Bm25Data object for the current query.
//	** If the object has not already been allocated, allocate and populate it
//	** now.
//	*/
func _fts5Bm25GetData(tls *libc.TLS, pApi uintptr, pFts uintptr, ppData uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, nPhrase, rc int32
	var idf float64
	var nByte Tsqlite3_int64
	var p uintptr
	var _ /* nHit at bp+16 */ Tsqlite3_int64
	var _ /* nRow at bp+0 */ Tsqlite3_int64
	var _ /* nToken at bp+8 */ Tsqlite3_int64
	_, _, _, _, _, _ = i, idf, nByte, nPhrase, p, rc
	rc = SQLITE_OK /* Object to return */
	p = (*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxGetAuxdata})))(tls, pFts, 0)
	if p == uintptr(0) { /* Number of phrases in query */
		*(*Tsqlite3_int64)(unsafe.Pointer(bp)) = 0 /* Number of rows in table */
		*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8)) = 0
		/* Allocate the Fts5Bm25Data object */
		nPhrase = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseCount})))(tls, pFts)
		nByte = int64(uint32(24) + uint32(nPhrase*int32(2))*uint32(8))
		p = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if p == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, p, 0, uint32(uint32(nByte)))
			(*TFts5Bm25Data)(unsafe.Pointer(p)).FnPhrase = nPhrase
			(*TFts5Bm25Data)(unsafe.Pointer(p)).FaIDF = p + 1*24
			(*TFts5Bm25Data)(unsafe.Pointer(p)).FaFreq = (*TFts5Bm25Data)(unsafe.Pointer(p)).FaIDF + uintptr(nPhrase)*8
		}
		/* Calculate the average document length for this FTS5 table */
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxRowCount})))(tls, pFts, bp)
		}
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnTotalSize})))(tls, pFts, -int32(1), bp+8)
		}
		if rc == SQLITE_OK {
			(*TFts5Bm25Data)(unsafe.Pointer(p)).Favgdl = float64(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 8))) / float64(*(*Tsqlite3_int64)(unsafe.Pointer(bp)))
		}
		/* Calculate an IDF for each phrase in the query */
		i = 0
		for {
			if !(rc == SQLITE_OK && i < nPhrase) {
				break
			}
			*(*Tsqlite3_int64)(unsafe.Pointer(bp + 16)) = 0
			rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxQueryPhrase})))(tls, pFts, i, bp+16, __ccgo_fp(_fts5CountCb))
			if rc == SQLITE_OK {
				/* Calculate the IDF (Inverse Document Frequency) for phrase i.
				 ** This is done using the standard BM25 formula as found on wikipedia:
				 **
				 **   IDF = log( (N - nHit + 0.5) / (nHit + 0.5) )
				 **
				 ** where "N" is the total number of documents in the set and nHit
				 ** is the number that contain at least one instance of the phrase
				 ** under consideration.
				 **
				 ** The problem with this is that if (N < 2*nHit), the IDF is
				 ** negative. Which is undesirable. So the mimimum allowable IDF is
				 ** (1e-6) - roughly the same as a term that appears in just over
				 ** half of set of 5,000,000 documents.  */
				idf = libc.Xlog(tls, (float64(*(*Tsqlite3_int64)(unsafe.Pointer(bp))-*(*Tsqlite3_int64)(unsafe.Pointer(bp + 16)))+float64(0.5))/(float64(*(*Tsqlite3_int64)(unsafe.Pointer(bp + 16)))+float64(0.5)))
				if idf <= float64(0) {
					idf = float64(1e-06)
				}
				*(*float64)(unsafe.Pointer((*TFts5Bm25Data)(unsafe.Pointer(p)).FaIDF + uintptr(i)*8)) = idf
			}
			goto _1
		_1:
			;
			i++
		}
		if rc != SQLITE_OK {
			Xsqlite3_free(tls, p)
		} else {
			rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxSetAuxdata})))(tls, pFts, p, __ccgo_fp(Xsqlite3_free))
		}
		if rc != SQLITE_OK {
			p = uintptr(0)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppData)) = p
	return rc
}

// C documentation
//
//	/*
//	** Implementation of bm25() function.
//	*/
func _fts5Bm25Function(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var D, b, k1, score, w, v2 float64
	var aFreq uintptr
	var i, rc int32
	var _ /* ic at bp+12 */ int32
	var _ /* io at bp+16 */ int32
	var _ /* ip at bp+8 */ int32
	var _ /* nInst at bp+4 */ int32
	var _ /* nTok at bp+20 */ int32
	var _ /* pData at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _ = D, aFreq, b, i, k1, rc, score, w, v2
	k1 = float64(1.2)                     /* Constant "k1" from BM25 formula */
	b = float64(0.75)                     /* Error code */
	score = float64(0)                    /* Iterator variable */
	*(*int32)(unsafe.Pointer(bp + 4)) = 0 /* Value returned by xInstCount() */
	D = float64(0)                        /* Total number of tokens in row */
	aFreq = uintptr(0)                    /* Array of phrase freq. for current row */
	/* Calculate the phrase frequency (symbol "f(qi,D)" in the documentation)
	 ** for each phrase in the query for the current row. */
	rc = _fts5Bm25GetData(tls, pApi, pFts, bp)
	if rc == SQLITE_OK {
		aFreq = (*TFts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFreq
		libc.Xmemset(tls, aFreq, 0, uint32(8)*uint32((*TFts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnPhrase))
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, bp+4)
	}
	i = 0
	for {
		if !(rc == SQLITE_OK && i < *(*int32)(unsafe.Pointer(bp + 4))) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})))(tls, pFts, i, bp+8, bp+12, bp+16)
		if rc == SQLITE_OK {
			if nVal > *(*int32)(unsafe.Pointer(bp + 12)) {
				v2 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(*(*int32)(unsafe.Pointer(bp + 12)))*4)))
			} else {
				v2 = float64(1)
			}
			w = v2
			*(*float64)(unsafe.Pointer(aFreq + uintptr(*(*int32)(unsafe.Pointer(bp + 8)))*8)) += w
		}
		goto _1
	_1:
		;
		i++
	}
	/* Figure out the total size of the current row in tokens. */
	if rc == SQLITE_OK {
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, -int32(1), bp+20)
		D = float64(*(*int32)(unsafe.Pointer(bp + 20)))
	}
	/* Determine and return the BM25 score for the current row. Or, if an
	 ** error has occurred, throw an exception. */
	if rc == SQLITE_OK {
		i = 0
		for {
			if !(i < (*TFts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnPhrase) {
				break
			}
			score += *(*float64)(unsafe.Pointer((*TFts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaIDF + uintptr(i)*8)) * (*(*float64)(unsafe.Pointer(aFreq + uintptr(i)*8)) * (k1 + libc.Float64FromFloat64(1)) / (*(*float64)(unsafe.Pointer(aFreq + uintptr(i)*8)) + k1*(libc.Float64FromInt32(1)-b+b*D/(*TFts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Favgdl)))
			goto _3
		_3:
			;
			i++
		}
		Xsqlite3_result_double(tls, pCtx, -libc.Float64FromFloat64(1)*score)
	} else {
		Xsqlite3_result_error_code(tls, pCtx, rc)
	}
}

func _sqlite3Fts5AuxInit(tls *libc.TLS, pApi uintptr) (r int32) {
	var aBuiltin [3]struct {
		FzFunc     uintptr
		FpUserData uintptr
		FxFunc     Tfts5_extension_function
		FxDestroy  uintptr
	}
	var i, rc int32
	_, _, _ = aBuiltin, i, rc
	aBuiltin = [3]struct {
		FzFunc     uintptr
		FpUserData uintptr
		FxFunc     Tfts5_extension_function
		FxDestroy  uintptr
	}{
		0: {
			FzFunc: __ccgo_ts + 36365,
			FxFunc: __ccgo_fp(_fts5SnippetFunction),
		},
		1: {
			FzFunc: __ccgo_ts + 36373,
			FxFunc: __ccgo_fp(_fts5HighlightFunction),
		},
		2: {
			FzFunc: __ccgo_ts + 36383,
			FxFunc: __ccgo_fp(_fts5Bm25Function),
		},
	}
	rc = SQLITE_OK /* To iterate through builtin functions */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < int32(libc.Uint32FromInt64(48)/libc.Uint32FromInt64(16))) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, Tfts5_extension_function, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxCreateFunction})))(tls, pApi, aBuiltin[i].FzFunc, aBuiltin[i].FpUserData, aBuiltin[i].FxFunc, aBuiltin[i].FxDestroy)
		goto _1
	_1:
		;
		i++
	}
	return rc
}

/*
** 2014 May 31
**
** 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 "fts5Int.h" */

func _sqlite3Fts5BufferSize(tls *libc.TLS, pRc uintptr, pBuf uintptr, nByte Tu32) (r int32) {
	var nNew Tu64
	var pNew uintptr
	var v1 int32
	_, _, _ = nNew, pNew, v1
	if uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) < nByte {
		if (*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace != 0 {
			v1 = (*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace
		} else {
			v1 = int32(64)
		}
		nNew = uint64(v1)
		for nNew < uint64(uint64(nByte)) {
			nNew = nNew * uint64(2)
		}
		pNew = Xsqlite3_realloc64(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp, nNew)
		if pNew == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
			return int32(1)
		} else {
			(*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace = int32(int32(nNew))
			(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp = pNew
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Encode value iVal as an SQLite varint and append it to the buffer object
//	** pBuf. If an OOM error occurs, set the error code in p.
//	*/
func _sqlite3Fts5BufferAppendVarint(tls *libc.TLS, pRc uintptr, pBuf uintptr, iVal Ti64) {
	var v1 int32
	_ = v1
	if uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)+uint32(libc.Int32FromInt32(9)) <= uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
		v1 = 0
	} else {
		v1 = _sqlite3Fts5BufferSize(tls, pRc, pBuf, uint32(int32(9)+(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn))
	}
	if v1 != 0 {
		return
	}
	*(*int32)(unsafe.Pointer(pBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(uint64(iVal)))
}

func _sqlite3Fts5Put32(tls *libc.TLS, aBuf uintptr, iVal int32) {
	*(*Tu8)(unsafe.Pointer(aBuf)) = uint8(iVal >> int32(24) & int32(0x00FF))
	*(*Tu8)(unsafe.Pointer(aBuf + 1)) = uint8(iVal >> int32(16) & int32(0x00FF))
	*(*Tu8)(unsafe.Pointer(aBuf + 2)) = uint8(iVal >> int32(8) & int32(0x00FF))
	*(*Tu8)(unsafe.Pointer(aBuf + 3)) = uint8(iVal >> 0 & int32(0x00FF))
}

func _sqlite3Fts5Get32(tls *libc.TLS, aBuf uintptr) (r int32) {
	return int32(uint32(*(*Tu8)(unsafe.Pointer(aBuf)))<<libc.Int32FromInt32(24) + uint32(int32(*(*Tu8)(unsafe.Pointer(aBuf + 1)))<<libc.Int32FromInt32(16)) + uint32(int32(*(*Tu8)(unsafe.Pointer(aBuf + 2)))<<libc.Int32FromInt32(8)) + uint32(*(*Tu8)(unsafe.Pointer(aBuf + 3))))
}

// C documentation
//
//	/*
//	** Append buffer nData/pData to buffer pBuf. If an OOM error occurs, set
//	** the error code in p. If an error has already occurred when this function
//	** is called, it is a no-op.
//	*/
func _sqlite3Fts5BufferAppendBlob(tls *libc.TLS, pRc uintptr, pBuf uintptr, nData Tu32, pData uintptr) {
	var v1 int32
	var p2 uintptr
	_, _ = v1, p2
	if nData != 0 {
		if uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)+nData <= uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
			v1 = 0
		} else {
			v1 = _sqlite3Fts5BufferSize(tls, pRc, pBuf, nData+uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn))
		}
		if v1 != 0 {
			return
		}
		libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), pData, nData)
		p2 = pBuf + 4
		*(*int32)(unsafe.Pointer(p2)) = int32(uint32(*(*int32)(unsafe.Pointer(p2))) + nData)
	}
}

// C documentation
//
//	/*
//	** Append the nul-terminated string zStr to the buffer pBuf. This function
//	** ensures that the byte following the buffer data is set to 0x00, even
//	** though this byte is not included in the pBuf->n count.
//	*/
func _sqlite3Fts5BufferAppendString(tls *libc.TLS, pRc uintptr, pBuf uintptr, zStr uintptr) {
	var nStr int32
	_ = nStr
	nStr = int32(libc.Xstrlen(tls, zStr))
	_sqlite3Fts5BufferAppendBlob(tls, pRc, pBuf, uint32(nStr+int32(1)), zStr)
	(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn--
}

// C documentation
//
//	/*
//	** Argument zFmt is a printf() style format string. This function performs
//	** the printf() style processing, then appends the results to buffer pBuf.
//	**
//	** Like sqlite3Fts5BufferAppendString(), this function ensures that the byte
//	** following the buffer data is set to 0x00, even though this byte is not
//	** included in the pBuf->n count.
//	*/
func _sqlite3Fts5BufferAppendPrintf(tls *libc.TLS, pRc uintptr, pBuf uintptr, zFmt uintptr, va uintptr) {
	var ap Tva_list
	var zTmp uintptr
	_, _ = ap, zTmp
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		ap = va
		zTmp = Xsqlite3_vmprintf(tls, zFmt, ap)
		_ = ap
		if zTmp == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		} else {
			_sqlite3Fts5BufferAppendString(tls, pRc, pBuf, zTmp)
			Xsqlite3_free(tls, zTmp)
		}
	}
}

func _sqlite3Fts5Mprintf(tls *libc.TLS, pRc uintptr, zFmt uintptr, va uintptr) (r uintptr) {
	var ap Tva_list
	var zRet uintptr
	_, _ = ap, zRet
	zRet = uintptr(0)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		ap = va
		zRet = Xsqlite3_vmprintf(tls, zFmt, ap)
		_ = ap
		if zRet == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		}
	}
	return zRet
}

// C documentation
//
//	/*
//	** Free any buffer allocated by pBuf. Zero the structure before returning.
//	*/
func _sqlite3Fts5BufferFree(tls *libc.TLS, pBuf uintptr) {
	Xsqlite3_free(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp)
	libc.Xmemset(tls, pBuf, 0, uint32(12))
}

// C documentation
//
//	/*
//	** Zero the contents of the buffer object. But do not free the associated
//	** memory allocation.
//	*/
func _sqlite3Fts5BufferZero(tls *libc.TLS, pBuf uintptr) {
	(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn = 0
}

// C documentation
//
//	/*
//	** Set the buffer to contain nData/pData. If an OOM error occurs, leave an
//	** the error code in p. If an error has already occurred when this function
//	** is called, it is a no-op.
//	*/
func _sqlite3Fts5BufferSet(tls *libc.TLS, pRc uintptr, pBuf uintptr, nData int32, pData uintptr) {
	(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn = 0
	_sqlite3Fts5BufferAppendBlob(tls, pRc, pBuf, uint32(uint32(nData)), pData)
}

func _sqlite3Fts5PoslistNext64(tls *libc.TLS, a uintptr, n int32, pi uintptr, piOff uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, v1, v2, v3 int32
	var iOff Ti64
	var _ /* iVal at bp+0 */ Tu32
	_, _, _, _, _ = i, iOff, v1, v2, v3
	i = *(*int32)(unsafe.Pointer(pi))
	if i >= n {
		/* EOF */
		*(*Ti64)(unsafe.Pointer(piOff)) = int64(-int32(1))
		return int32(1)
	} else {
		iOff = *(*Ti64)(unsafe.Pointer(piOff))
		v1 = i
		i++
		*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(a + uintptr(v1))))
		if *(*Tu32)(unsafe.Pointer(bp))&uint32(0x80) != 0 {
			i--
			i += _sqlite3Fts5GetVarint32(tls, a+uintptr(i), bp)
		}
		if *(*Tu32)(unsafe.Pointer(bp)) <= uint32(1) {
			if *(*Tu32)(unsafe.Pointer(bp)) == uint32(0) {
				*(*int32)(unsafe.Pointer(pi)) = i
				return 0
			}
			v2 = i
			i++
			*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(a + uintptr(v2))))
			if *(*Tu32)(unsafe.Pointer(bp))&uint32(0x80) != 0 {
				i--
				i += _sqlite3Fts5GetVarint32(tls, a+uintptr(i), bp)
			}
			iOff = int64(*(*Tu32)(unsafe.Pointer(bp))) << int32(32)
			v3 = i
			i++
			*(*Tu32)(unsafe.Pointer(bp)) = uint32(*(*Tu8)(unsafe.Pointer(a + uintptr(v3))))
			if *(*Tu32)(unsafe.Pointer(bp))&uint32(0x80) != 0 {
				i--
				i += _sqlite3Fts5GetVarint32(tls, a+uintptr(i), bp)
			}
			if *(*Tu32)(unsafe.Pointer(bp)) < uint32(2) {
				/* This is a corrupt record. So stop parsing it here. */
				*(*Ti64)(unsafe.Pointer(piOff)) = int64(-int32(1))
				return int32(1)
			}
			*(*Ti64)(unsafe.Pointer(piOff)) = iOff + int64((*(*Tu32)(unsafe.Pointer(bp))-libc.Uint32FromInt32(2))&libc.Uint32FromInt32(0x7FFFFFFF))
		} else {
			*(*Ti64)(unsafe.Pointer(piOff)) = iOff&(libc.Int64FromInt32(0x7FFFFFFF)<<libc.Int32FromInt32(32)) + (iOff+int64(*(*Tu32)(unsafe.Pointer(bp))-libc.Uint32FromInt32(2)))&int64(0x7FFFFFFF)
		}
		*(*int32)(unsafe.Pointer(pi)) = i
		return 0
	}
	return r
}

// C documentation
//
//	/*
//	** Advance the iterator object passed as the only argument. Return true
//	** if the iterator reaches EOF, or false otherwise.
//	*/
func _sqlite3Fts5PoslistReaderNext(tls *libc.TLS, pIter uintptr) (r int32) {
	if _sqlite3Fts5PoslistNext64(tls, (*TFts5PoslistReader)(unsafe.Pointer(pIter)).Fa, (*TFts5PoslistReader)(unsafe.Pointer(pIter)).Fn, pIter+8, pIter+16) != 0 {
		(*TFts5PoslistReader)(unsafe.Pointer(pIter)).FbEof = uint8(1)
	}
	return int32((*TFts5PoslistReader)(unsafe.Pointer(pIter)).FbEof)
}

func _sqlite3Fts5PoslistReaderInit(tls *libc.TLS, a uintptr, n int32, pIter uintptr) (r int32) {
	libc.Xmemset(tls, pIter, 0, uint32(24))
	(*TFts5PoslistReader)(unsafe.Pointer(pIter)).Fa = a
	(*TFts5PoslistReader)(unsafe.Pointer(pIter)).Fn = n
	_sqlite3Fts5PoslistReaderNext(tls, pIter)
	return int32((*TFts5PoslistReader)(unsafe.Pointer(pIter)).FbEof)
}

// C documentation
//
//	/*
//	** Append position iPos to the position list being accumulated in buffer
//	** pBuf, which must be already be large enough to hold the new data.
//	** The previous position written to this list is *piPrev. *piPrev is set
//	** to iPos before returning.
//	*/
func _sqlite3Fts5PoslistSafeAppend(tls *libc.TLS, pBuf uintptr, piPrev uintptr, iPos Ti64) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if iPos >= *(*Ti64)(unsafe.Pointer(piPrev)) {
		if iPos&_colmask != *(*Ti64)(unsafe.Pointer(piPrev))&_colmask {
			v2 = pBuf + 4
			v1 = *(*int32)(unsafe.Pointer(v2))
			*(*int32)(unsafe.Pointer(v2))++
			*(*Tu8)(unsafe.Pointer((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(v1))) = uint8(1)
			*(*int32)(unsafe.Pointer(pBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(iPos>>libc.Int32FromInt32(32)))
			*(*Ti64)(unsafe.Pointer(piPrev)) = iPos & _colmask
		}
		*(*int32)(unsafe.Pointer(pBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(iPos-*(*Ti64)(unsafe.Pointer(piPrev))+int64(2)))
		*(*Ti64)(unsafe.Pointer(piPrev)) = iPos
	}
}

var _colmask = int64(libc.Int32FromInt32(0x7FFFFFFF)) << libc.Int32FromInt32(32)

func _sqlite3Fts5PoslistWriterAppend(tls *libc.TLS, pBuf uintptr, pWriter uintptr, iPos Ti64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var v1 int32
	var _ /* rc at bp+0 */ int32
	_ = v1
	*(*int32)(unsafe.Pointer(bp)) = 0 /* Initialized only to suppress erroneous warning from Clang */
	if uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)+uint32(libc.Int32FromInt32(5)+libc.Int32FromInt32(5)+libc.Int32FromInt32(5)) <= uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
		v1 = 0
	} else {
		v1 = _sqlite3Fts5BufferSize(tls, bp, pBuf, uint32(libc.Int32FromInt32(5)+libc.Int32FromInt32(5)+libc.Int32FromInt32(5)+(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn))
	}
	if v1 != 0 {
		return *(*int32)(unsafe.Pointer(bp))
	}
	_sqlite3Fts5PoslistSafeAppend(tls, pBuf, pWriter, iPos)
	return SQLITE_OK
}

func _sqlite3Fts5MallocZero(tls *libc.TLS, pRc uintptr, nByte Tsqlite3_int64) (r uintptr) {
	var pRet uintptr
	_ = pRet
	pRet = uintptr(0)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		pRet = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if pRet == uintptr(0) {
			if nByte > 0 {
				*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
			}
		} else {
			libc.Xmemset(tls, pRet, 0, uint32(uint32(nByte)))
		}
	}
	return pRet
}

// C documentation
//
//	/*
//	** Return a nul-terminated copy of the string indicated by pIn. If nIn
//	** is non-negative, then it is the length of the string in bytes. Otherwise,
//	** the length of the string is determined using strlen().
//	**
//	** It is the responsibility of the caller to eventually free the returned
//	** buffer using sqlite3_free(). If an OOM error occurs, NULL is returned.
//	*/
func _sqlite3Fts5Strndup(tls *libc.TLS, pRc uintptr, pIn uintptr, nIn int32) (r uintptr) {
	var zRet uintptr
	_ = zRet
	zRet = uintptr(0)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		if nIn < 0 {
			nIn = int32(libc.Xstrlen(tls, pIn))
		}
		zRet = Xsqlite3_malloc(tls, nIn+int32(1))
		if zRet != 0 {
			libc.Xmemcpy(tls, zRet, pIn, uint32(uint32(nIn)))
			*(*int8)(unsafe.Pointer(zRet + uintptr(nIn))) = int8('\000')
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		}
	}
	return zRet
}

// C documentation
//
//	/*
//	** Return true if character 't' may be part of an FTS5 bareword, or false
//	** otherwise. Characters that may be part of barewords:
//	**
//	**   * All non-ASCII characters,
//	**   * The 52 upper and lower case ASCII characters, and
//	**   * The 10 integer ASCII characters.
//	**   * The underscore character "_" (0x5F).
//	**   * The unicode "subsitute" character (0x1A).
//	*/
func _sqlite3Fts5IsBareword(tls *libc.TLS, t int8) (r int32) {
	var aBareword [128]Tu8
	_ = aBareword
	aBareword = [128]Tu8{
		26:  uint8(1),
		48:  uint8(1),
		49:  uint8(1),
		50:  uint8(1),
		51:  uint8(1),
		52:  uint8(1),
		53:  uint8(1),
		54:  uint8(1),
		55:  uint8(1),
		56:  uint8(1),
		57:  uint8(1),
		65:  uint8(1),
		66:  uint8(1),
		67:  uint8(1),
		68:  uint8(1),
		69:  uint8(1),
		70:  uint8(1),
		71:  uint8(1),
		72:  uint8(1),
		73:  uint8(1),
		74:  uint8(1),
		75:  uint8(1),
		76:  uint8(1),
		77:  uint8(1),
		78:  uint8(1),
		79:  uint8(1),
		80:  uint8(1),
		81:  uint8(1),
		82:  uint8(1),
		83:  uint8(1),
		84:  uint8(1),
		85:  uint8(1),
		86:  uint8(1),
		87:  uint8(1),
		88:  uint8(1),
		89:  uint8(1),
		90:  uint8(1),
		95:  uint8(1),
		97:  uint8(1),
		98:  uint8(1),
		99:  uint8(1),
		100: uint8(1),
		101: uint8(1),
		102: uint8(1),
		103: uint8(1),
		104: uint8(1),
		105: uint8(1),
		106: uint8(1),
		107: uint8(1),
		108: uint8(1),
		109: uint8(1),
		110: uint8(1),
		111: uint8(1),
		112: uint8(1),
		113: uint8(1),
		114: uint8(1),
		115: uint8(1),
		116: uint8(1),
		117: uint8(1),
		118: uint8(1),
		119: uint8(1),
		120: uint8(1),
		121: uint8(1),
		122: uint8(1),
	}
	return libc.BoolInt32(int32(int32(t))&int32(0x80) != 0 || aBareword[int32(int32(t))] != 0)
}

// C documentation
//
//	/*************************************************************************
//	*/
type TFts5TermsetEntry = struct {
	FpTerm uintptr
	FnTerm int32
	FiIdx  int32
	FpNext uintptr
}

type Fts5TermsetEntry = TFts5TermsetEntry

type TFts5TermsetEntry1 = struct {
	FpTerm uintptr
	FnTerm int32
	FiIdx  int32
	FpNext uintptr
}

type Fts5TermsetEntry1 = TFts5TermsetEntry1

type TFts5Termset1 = struct {
	FapHash [512]uintptr
}

type Fts5Termset1 = TFts5Termset1

func _sqlite3Fts5TermsetNew(tls *libc.TLS, pp uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* rc at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(pp)) = _sqlite3Fts5MallocZero(tls, bp, int64(2048))
	return *(*int32)(unsafe.Pointer(bp))
}

func _sqlite3Fts5TermsetAdd(tls *libc.TLS, p uintptr, iIdx int32, pTerm uintptr, nTerm int32, pbPresent uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var hash Tu32
	var i int32
	var pEntry uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _ = hash, i, pEntry
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*int32)(unsafe.Pointer(pbPresent)) = 0
	if p != 0 {
		hash = uint32(13)
		/* Calculate a hash value for this term. This is the same hash checksum
		 ** used by the fts5_hash.c module. This is not important for correct
		 ** operation of the module, but is necessary to ensure that some tests
		 ** designed to produce hash table collisions really do work.  */
		i = nTerm - int32(1)
		for {
			if !(i >= 0) {
				break
			}
			hash = hash<<libc.Int32FromInt32(3) ^ hash ^ uint32(*(*int8)(unsafe.Pointer(pTerm + uintptr(i))))
			goto _1
		_1:
			;
			i--
		}
		hash = hash<<libc.Int32FromInt32(3) ^ hash ^ uint32(uint32(iIdx))
		hash = hash % uint32(int32(libc.Uint32FromInt64(2048)/libc.Uint32FromInt64(4)))
		pEntry = *(*uintptr)(unsafe.Pointer(p + uintptr(hash)*4))
		for {
			if !(pEntry != 0) {
				break
			}
			if (*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FiIdx == iIdx && (*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FnTerm == nTerm && libc.Xmemcmp(tls, (*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FpTerm, pTerm, uint32(uint32(nTerm))) == 0 {
				*(*int32)(unsafe.Pointer(pbPresent)) = int32(1)
				break
			}
			goto _2
		_2:
			;
			pEntry = (*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FpNext
		}
		if pEntry == uintptr(0) {
			pEntry = _sqlite3Fts5MallocZero(tls, bp, int64(uint32(16)+uint32(uint32(nTerm))))
			if pEntry != 0 {
				(*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FpTerm = pEntry + 1*16
				(*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FnTerm = nTerm
				(*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FiIdx = iIdx
				libc.Xmemcpy(tls, (*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FpTerm, pTerm, uint32(uint32(nTerm)))
				(*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FpNext = *(*uintptr)(unsafe.Pointer(p + uintptr(hash)*4))
				*(*uintptr)(unsafe.Pointer(p + uintptr(hash)*4)) = pEntry
			}
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func _sqlite3Fts5TermsetFree(tls *libc.TLS, p uintptr) {
	var i Tu32
	var pDel, pEntry uintptr
	_, _, _ = i, pDel, pEntry
	if p != 0 {
		i = uint32(0)
		for {
			if !(i < uint32(int32(libc.Uint32FromInt64(2048)/libc.Uint32FromInt64(4)))) {
				break
			}
			pEntry = *(*uintptr)(unsafe.Pointer(p + uintptr(i)*4))
			for pEntry != 0 {
				pDel = pEntry
				pEntry = (*TFts5TermsetEntry)(unsafe.Pointer(pEntry)).FpNext
				Xsqlite3_free(tls, pDel)
			}
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, p)
	}
}

/*
** 2014 Jun 09
**
** 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 is an SQLite module implementing full-text search.
 */

/* #include "fts5Int.h" */

/* Maximum allowed page size */

func _fts5_iswhitespace(tls *libc.TLS, x int8) (r int32) {
	return libc.BoolInt32(int32(int32(x)) == int32(' '))
}

func _fts5_isopenquote(tls *libc.TLS, x int8) (r int32) {
	return libc.BoolInt32(int32(int32(x)) == int32('"') || int32(int32(x)) == int32('\'') || int32(int32(x)) == int32('[') || int32(int32(x)) == int32('`'))
}

// C documentation
//
//	/*
//	** Argument pIn points to a character that is part of a nul-terminated
//	** string. Return a pointer to the first character following *pIn in
//	** the string that is not a white-space character.
//	*/
func _fts5ConfigSkipWhitespace(tls *libc.TLS, pIn uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = pIn
	if p != 0 {
		for _fts5_iswhitespace(tls, *(*int8)(unsafe.Pointer(p))) != 0 {
			p++
		}
	}
	return p
}

// C documentation
//
//	/*
//	** Argument pIn points to a character that is part of a nul-terminated
//	** string. Return a pointer to the first character following *pIn in
//	** the string that is not a "bareword" character.
//	*/
func _fts5ConfigSkipBareword(tls *libc.TLS, pIn uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = pIn
	for _sqlite3Fts5IsBareword(tls, *(*int8)(unsafe.Pointer(p))) != 0 {
		p++
	}
	if p == pIn {
		p = uintptr(0)
	}
	return p
}

func _fts5_isdigit(tls *libc.TLS, a int8) (r int32) {
	return libc.BoolInt32(int32(int32(a)) >= int32('0') && int32(int32(a)) <= int32('9'))
}

func _fts5ConfigSkipLiteral(tls *libc.TLS, pIn uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = pIn
	switch int32(*(*int8)(unsafe.Pointer(p))) {
	case int32('n'):
		fallthrough
	case int32('N'):
		if Xsqlite3_strnicmp(tls, __ccgo_ts+1658, p, int32(4)) == 0 {
			p = p + 4
		} else {
			p = uintptr(0)
		}
	case int32('x'):
		fallthrough
	case int32('X'):
		p++
		if int32(*(*int8)(unsafe.Pointer(p))) == int32('\'') {
			p++
			for int32(*(*int8)(unsafe.Pointer(p))) >= int32('a') && int32(*(*int8)(unsafe.Pointer(p))) <= int32('f') || int32(*(*int8)(unsafe.Pointer(p))) >= int32('A') && int32(*(*int8)(unsafe.Pointer(p))) <= int32('F') || int32(*(*int8)(unsafe.Pointer(p))) >= int32('0') && int32(*(*int8)(unsafe.Pointer(p))) <= int32('9') {
				p++
			}
			if int32(*(*int8)(unsafe.Pointer(p))) == int32('\'') && 0 == (int32(int32(p))-int32(int32(pIn)))%int32(2) {
				p++
			} else {
				p = uintptr(0)
			}
		} else {
			p = uintptr(0)
		}
	case int32('\''):
		p++
		for p != 0 {
			if int32(*(*int8)(unsafe.Pointer(p))) == int32('\'') {
				p++
				if int32(*(*int8)(unsafe.Pointer(p))) != int32('\'') {
					break
				}
			}
			p++
			if int32(*(*int8)(unsafe.Pointer(p))) == 0 {
				p = uintptr(0)
			}
		}
	default:
		/* maybe a number */
		if int32(*(*int8)(unsafe.Pointer(p))) == int32('+') || int32(*(*int8)(unsafe.Pointer(p))) == int32('-') {
			p++
		}
		for _fts5_isdigit(tls, *(*int8)(unsafe.Pointer(p))) != 0 {
			p++
		}
		/* At this point, if the literal was an integer, the parse is
		 ** finished. Or, if it is a floating point value, it may continue
		 ** with either a decimal point or an 'E' character. */
		if int32(*(*int8)(unsafe.Pointer(p))) == int32('.') && _fts5_isdigit(tls, *(*int8)(unsafe.Pointer(p + 1))) != 0 {
			p += uintptr(2)
			for _fts5_isdigit(tls, *(*int8)(unsafe.Pointer(p))) != 0 {
				p++
			}
		}
		if p == pIn {
			p = uintptr(0)
		}
		break
	}
	return p
}

// C documentation
//
//	/*
//	** The first character of the string pointed to by argument z is guaranteed
//	** to be an open-quote character (see function fts5_isopenquote()).
//	**
//	** This function searches for the corresponding close-quote character within
//	** the string and, if found, dequotes the string in place and adds a new
//	** nul-terminator byte.
//	**
//	** If the close-quote is found, the value returned is the byte offset of
//	** the character immediately following it. Or, if the close-quote is not
//	** found, -1 is returned. If -1 is returned, the buffer is left in an
//	** undefined state.
//	*/
func _fts5Dequote(tls *libc.TLS, z uintptr) (r int32) {
	var iIn, iOut, v1, v2, v3 int32
	var q int8
	_, _, _, _, _, _ = iIn, iOut, q, v1, v2, v3
	iIn = int32(1)
	iOut = 0
	q = *(*int8)(unsafe.Pointer(z))
	/* Set stack variable q to the close-quote character */
	if int32(int32(q)) == int32('[') {
		q = int8(']')
	}
	for *(*int8)(unsafe.Pointer(z + uintptr(iIn))) != 0 {
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(iIn)))) == int32(int32(q)) {
			if int32(*(*int8)(unsafe.Pointer(z + uintptr(iIn+int32(1))))) != int32(int32(q)) {
				/* Character iIn was the close quote. */
				iIn++
				break
			} else {
				/* Character iIn and iIn+1 form an escaped quote character. Skip
				 ** the input cursor past both and copy a single quote character
				 ** to the output buffer. */
				iIn += int32(2)
				v1 = iOut
				iOut++
				*(*int8)(unsafe.Pointer(z + uintptr(v1))) = q
			}
		} else {
			v2 = iOut
			iOut++
			v3 = iIn
			iIn++
			*(*int8)(unsafe.Pointer(z + uintptr(v2))) = *(*int8)(unsafe.Pointer(z + uintptr(v3)))
		}
	}
	*(*int8)(unsafe.Pointer(z + uintptr(iOut))) = int8('\000')
	return iIn
}

// C documentation
//
//	/*
//	** Convert an SQL-style quoted string into a normal string by removing
//	** the quote characters.  The conversion is done in-place.  If the
//	** input does not begin with a quote character, then this routine
//	** is a no-op.
//	**
//	** Examples:
//	**
//	**     "abc"   becomes   abc
//	**     'xyz'   becomes   xyz
//	**     [pqr]   becomes   pqr
//	**     `mno`   becomes   mno
//	*/
func _sqlite3Fts5Dequote(tls *libc.TLS, z uintptr) {
	var quote int8
	_ = quote /* Quote character (if any ) */
	quote = *(*int8)(unsafe.Pointer(z))
	if int32(int32(quote)) == int32('[') || int32(int32(quote)) == int32('\'') || int32(int32(quote)) == int32('"') || int32(int32(quote)) == int32('`') {
		_fts5Dequote(tls, z)
	}
}

type TFts5Enum1 = struct {
	FzName uintptr
	FeVal  int32
}

type Fts5Enum1 = TFts5Enum1

type TFts5Enum = struct {
	FzName uintptr
	FeVal  int32
}

type Fts5Enum = TFts5Enum

func _fts5ConfigSetEnum(tls *libc.TLS, aEnum uintptr, zEnum uintptr, peVal uintptr) (r int32) {
	var i, iVal, nEnum, v2 int32
	_, _, _, _ = i, iVal, nEnum, v2
	nEnum = int32(libc.Xstrlen(tls, zEnum))
	iVal = -int32(1)
	i = 0
	for {
		if !((*(*TFts5Enum)(unsafe.Pointer(aEnum + uintptr(i)*8))).FzName != 0) {
			break
		}
		if Xsqlite3_strnicmp(tls, (*(*TFts5Enum)(unsafe.Pointer(aEnum + uintptr(i)*8))).FzName, zEnum, nEnum) == 0 {
			if iVal >= 0 {
				return int32(SQLITE_ERROR)
			}
			iVal = (*(*TFts5Enum)(unsafe.Pointer(aEnum + uintptr(i)*8))).FeVal
		}
		goto _1
	_1:
		;
		i++
	}
	*(*int32)(unsafe.Pointer(peVal)) = iVal
	if iVal < 0 {
		v2 = int32(SQLITE_ERROR)
	} else {
		v2 = SQLITE_OK
	}
	return v2
}

// C documentation
//
//	/*
//	** Parse a "special" CREATE VIRTUAL TABLE directive and update
//	** configuration object pConfig as appropriate.
//	**
//	** If successful, object pConfig is updated and SQLITE_OK returned. If
//	** an error occurs, an SQLite error code is returned and an error message
//	** may be left in *pzErr. It is the responsibility of the caller to
//	** eventually free any such error message using sqlite3_free().
//	*/
func _fts5ConfigParseSpecial(tls *libc.TLS, pGlobal uintptr, pConfig uintptr, zCmd uintptr, zArg uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var azArg, p, p1, p2, pDel, pSpace uintptr
	var bFirst, nByte, nCmd, nPre, v2 int32
	var nArg Tsqlite3_int64
	var _ /* aDetail at bp+4 */ [4]TFts5Enum
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _ = azArg, bFirst, nArg, nByte, nCmd, nPre, p, p1, p2, pDel, pSpace, v2
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	nCmd = int32(libc.Xstrlen(tls, zCmd))
	if Xsqlite3_strnicmp(tls, __ccgo_ts+36388, zCmd, nCmd) == 0 {
		nByte = int32(libc.Uint32FromInt64(4) * libc.Uint32FromInt32(FTS5_MAX_PREFIX_INDEXES))
		bFirst = int32(1)
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix == uintptr(0) {
			(*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix = _sqlite3Fts5MallocZero(tls, bp, int64(int64(nByte)))
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				return *(*int32)(unsafe.Pointer(bp))
			}
		}
		p = zArg
		for int32(1) != 0 {
			nPre = 0
			for int32(*(*int8)(unsafe.Pointer(p))) == int32(' ') {
				p++
			}
			if bFirst == 0 && int32(*(*int8)(unsafe.Pointer(p))) == int32(',') {
				p++
				for int32(*(*int8)(unsafe.Pointer(p))) == int32(' ') {
					p++
				}
			} else {
				if int32(*(*int8)(unsafe.Pointer(p))) == int32('\000') {
					break
				}
			}
			if int32(*(*int8)(unsafe.Pointer(p))) < int32('0') || int32(*(*int8)(unsafe.Pointer(p))) > int32('9') {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36395, 0)
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
				break
			}
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix == int32(FTS5_MAX_PREFIX_INDEXES) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36426, libc.VaList(bp+48, int32(FTS5_MAX_PREFIX_INDEXES)))
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
				break
			}
			for int32(*(*int8)(unsafe.Pointer(p))) >= int32('0') && int32(*(*int8)(unsafe.Pointer(p))) <= int32('9') && nPre < int32(1000) {
				nPre = nPre*int32(10) + (int32(*(*int8)(unsafe.Pointer(p))) - int32('0'))
				p++
			}
			if nPre <= 0 || nPre >= int32(1000) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36459, 0)
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
				break
			}
			*(*int32)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr((*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix)*4)) = nPre
			(*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix++
			bFirst = 0
		}
		return *(*int32)(unsafe.Pointer(bp))
	}
	if Xsqlite3_strnicmp(tls, __ccgo_ts+36496, zCmd, nCmd) == 0 {
		p1 = zArg
		nArg = int64(libc.Xstrlen(tls, zArg) + uint32(1))
		azArg = _sqlite3Fts5MallocZero(tls, bp, int64(4)*nArg)
		pDel = _sqlite3Fts5MallocZero(tls, bp, nArg*int64(2))
		pSpace = pDel
		if azArg != 0 && pSpace != 0 {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FpTok != 0 {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36505, 0)
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
			} else {
				nArg = 0
				for {
					if !(p1 != 0 && *(*int8)(unsafe.Pointer(p1)) != 0) {
						break
					}
					p2 = _fts5ConfigSkipWhitespace(tls, p1)
					if int32(*(*int8)(unsafe.Pointer(p2))) == int32('\'') {
						p1 = _fts5ConfigSkipLiteral(tls, p2)
					} else {
						p1 = _fts5ConfigSkipBareword(tls, p2)
					}
					if p1 != 0 {
						libc.Xmemcpy(tls, pSpace, p2, uint32(int32(int32(p1))-int32(int32(p2))))
						*(*uintptr)(unsafe.Pointer(azArg + uintptr(nArg)*4)) = pSpace
						_sqlite3Fts5Dequote(tls, pSpace)
						pSpace += uintptr(int32(int32(p1)) - int32(int32(p2)) + int32(1))
						p1 = _fts5ConfigSkipWhitespace(tls, p1)
					}
					goto _1
				_1:
					;
					nArg++
				}
				if p1 == uintptr(0) {
					*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36538, 0)
					*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
				} else {
					*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5GetTokenizer(tls, pGlobal, azArg, int32(int32(nArg)), pConfig, pzErr)
				}
			}
		}
		Xsqlite3_free(tls, azArg)
		Xsqlite3_free(tls, pDel)
		return *(*int32)(unsafe.Pointer(bp))
	}
	if Xsqlite3_strnicmp(tls, __ccgo_ts+36572, zCmd, nCmd) == 0 {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36580, 0)
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		} else {
			if *(*int8)(unsafe.Pointer(zArg)) != 0 {
				(*TFts5Config)(unsafe.Pointer(pConfig)).FeContent = int32(FTS5_CONTENT_EXTERNAL)
				(*TFts5Config)(unsafe.Pointer(pConfig)).FzContent = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+36612, libc.VaList(bp+48, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, zArg))
			} else {
				(*TFts5Config)(unsafe.Pointer(pConfig)).FeContent = int32(FTS5_CONTENT_NONE)
			}
		}
		return *(*int32)(unsafe.Pointer(bp))
	}
	if Xsqlite3_strnicmp(tls, __ccgo_ts+36618, zCmd, nCmd) == 0 {
		if int32(*(*int8)(unsafe.Pointer(zArg))) != int32('0') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('1') || int32(*(*int8)(unsafe.Pointer(zArg + 1))) != int32('\000') {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36637, 0)
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete = libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zArg))) == int32('1'))
		}
		return *(*int32)(unsafe.Pointer(bp))
	}
	if Xsqlite3_strnicmp(tls, __ccgo_ts+36680, zCmd, nCmd) == 0 {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FzContentRowid != 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36694, 0)
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).FzContentRowid = _sqlite3Fts5Strndup(tls, bp, zArg, -int32(1))
		}
		return *(*int32)(unsafe.Pointer(bp))
	}
	if Xsqlite3_strnicmp(tls, __ccgo_ts+36732, zCmd, nCmd) == 0 {
		if int32(*(*int8)(unsafe.Pointer(zArg))) != int32('0') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('1') || int32(*(*int8)(unsafe.Pointer(zArg + 1))) != int32('\000') {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36743, 0)
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize = libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zArg))) == int32('1'))
		}
		return *(*int32)(unsafe.Pointer(bp))
	}
	if Xsqlite3_strnicmp(tls, __ccgo_ts+6872, zCmd, nCmd) == 0 {
		*(*[4]TFts5Enum)(unsafe.Pointer(bp + 4)) = [4]TFts5Enum{
			0: {
				FzName: __ccgo_ts + 9652,
				FeVal:  int32(FTS5_DETAIL_NONE),
			},
			1: {
				FzName: __ccgo_ts + 19160,
			},
			2: {
				FzName: __ccgo_ts + 36778,
				FeVal:  int32(FTS5_DETAIL_COLUMNS),
			},
			3: {},
		}
		v2 = _fts5ConfigSetEnum(tls, bp+4, zArg, pConfig+56)
		*(*int32)(unsafe.Pointer(bp)) = v2
		if v2 != 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36786, 0)
		}
		return *(*int32)(unsafe.Pointer(bp))
	}
	if Xsqlite3_strnicmp(tls, __ccgo_ts+36817, zCmd, nCmd) == 0 {
		if int32(*(*int8)(unsafe.Pointer(zArg))) != int32('0') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('1') || int32(*(*int8)(unsafe.Pointer(zArg + 1))) != int32('\000') {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36827, 0)
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).FbTokendata = libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zArg))) == int32('1'))
		}
		return *(*int32)(unsafe.Pointer(bp))
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36861, libc.VaList(bp+48, nCmd, zCmd))
	return int32(SQLITE_ERROR)
}

// C documentation
//
//	/*
//	** Allocate an instance of the default tokenizer ("simple") at
//	** Fts5Config.pTokenizer. Return SQLITE_OK if successful, or an SQLite error
//	** code if an error occurs.
//	*/
func _fts5ConfigDefaultTokenizer(tls *libc.TLS, pGlobal uintptr, pConfig uintptr) (r int32) {
	return _sqlite3Fts5GetTokenizer(tls, pGlobal, uintptr(0), 0, pConfig, uintptr(0))
}

// C documentation
//
//	/*
//	** Gobble up the first bareword or quoted word from the input buffer zIn.
//	** Return a pointer to the character immediately following the last in
//	** the gobbled word if successful, or a NULL pointer otherwise (failed
//	** to find close-quote character).
//	**
//	** Before returning, set pzOut to point to a new buffer containing a
//	** nul-terminated, dequoted copy of the gobbled word. If the word was
//	** quoted, *pbQuoted is also set to 1 before returning.
//	**
//	** If *pRc is other than SQLITE_OK when this function is called, it is
//	** a no-op (NULL is returned). Otherwise, if an OOM occurs within this
//	** function, *pRc is set to SQLITE_NOMEM before returning. *pRc is *not*
//	** set if a parse error (failed to find close quote) occurs.
//	*/
func _fts5ConfigGobbleWord(tls *libc.TLS, pRc uintptr, zIn uintptr, pzOut uintptr, pbQuoted uintptr) (r uintptr) {
	var ii int32
	var nIn Tsqlite3_int64
	var zOut, zRet uintptr
	_, _, _, _ = ii, nIn, zOut, zRet
	zRet = uintptr(0)
	nIn = int64(libc.Xstrlen(tls, zIn))
	zOut = Xsqlite3_malloc64(tls, uint64(nIn+int64(1)))
	*(*int32)(unsafe.Pointer(pbQuoted)) = 0
	*(*uintptr)(unsafe.Pointer(pzOut)) = uintptr(0)
	if zOut == uintptr(0) {
		*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemcpy(tls, zOut, zIn, uint32(nIn+libc.Int64FromInt32(1)))
		if _fts5_isopenquote(tls, *(*int8)(unsafe.Pointer(zOut))) != 0 {
			ii = _fts5Dequote(tls, zOut)
			zRet = zIn + uintptr(ii)
			*(*int32)(unsafe.Pointer(pbQuoted)) = int32(1)
		} else {
			zRet = _fts5ConfigSkipBareword(tls, zIn)
			if zRet != 0 {
				*(*int8)(unsafe.Pointer(zOut + uintptr(int32(int32(zRet))-int32(int32(zIn))))) = int8('\000')
			}
		}
	}
	if zRet == uintptr(0) {
		Xsqlite3_free(tls, zOut)
	} else {
		*(*uintptr)(unsafe.Pointer(pzOut)) = zOut
	}
	return zRet
}

func _fts5ConfigParseColumn(tls *libc.TLS, p uintptr, zCol uintptr, zArg uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc, v1 int32
	var v2 uintptr
	_, _, _ = rc, v1, v2
	rc = SQLITE_OK
	if 0 == Xsqlite3_stricmp(tls, zCol, __ccgo_ts+36889) || 0 == Xsqlite3_stricmp(tls, zCol, __ccgo_ts+18096) {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36894, libc.VaList(bp+8, zCol))
		rc = int32(SQLITE_ERROR)
	} else {
		if zArg != 0 {
			if 0 == Xsqlite3_stricmp(tls, zArg, __ccgo_ts+36924) {
				*(*Tu8)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr((*TFts5Config)(unsafe.Pointer(p)).FnCol))) = uint8(1)
			} else {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36934, libc.VaList(bp+8, zArg))
				rc = int32(SQLITE_ERROR)
			}
		}
	}
	v2 = p + 12
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2))++
	*(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(p)).FazCol + uintptr(v1)*4)) = zCol
	return rc
}

// C documentation
//
//	/*
//	** Populate the Fts5Config.zContentExprlist string.
//	*/
func _fts5ConfigMakeExprlist(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var _ /* buf at bp+4 */ TFts5Buffer
	var _ /* rc at bp+0 */ int32
	_ = i
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*TFts5Buffer)(unsafe.Pointer(bp + 4)) = TFts5Buffer{}
	_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+4, __ccgo_ts+36965, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(p)).FzContentRowid))
	if (*TFts5Config)(unsafe.Pointer(p)).FeContent != int32(FTS5_CONTENT_NONE) {
		i = 0
		for {
			if !(i < (*TFts5Config)(unsafe.Pointer(p)).FnCol) {
				break
			}
			if (*TFts5Config)(unsafe.Pointer(p)).FeContent == int32(FTS5_CONTENT_EXTERNAL) {
				_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+4, __ccgo_ts+36970, libc.VaList(bp+24, *(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(p)).FazCol + uintptr(i)*4))))
			} else {
				_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+4, __ccgo_ts+36977, libc.VaList(bp+24, i))
			}
			goto _1
		_1:
			;
			i++
		}
	}
	(*TFts5Config)(unsafe.Pointer(p)).FzContentExprlist = (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Arguments nArg/azArg contain the string arguments passed to the xCreate
//	** or xConnect method of the virtual table. This function attempts to
//	** allocate an instance of Fts5Config containing the results of parsing
//	** those arguments.
//	**
//	** If successful, SQLITE_OK is returned and *ppOut is set to point to the
//	** new Fts5Config object. If an error occurs, an SQLite error code is
//	** returned, *ppOut is set to NULL and an error message may be left in
//	** *pzErr. It is the responsibility of the caller to eventually free any
//	** such error message using sqlite3_free().
//	*/
func _sqlite3Fts5ConfigParse(tls *libc.TLS, pGlobal uintptr, db uintptr, nArg int32, azArg uintptr, ppOut uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bOption, i int32
	var nByte Tsqlite3_int64
	var pRet, z, zOrig, zTail, v1, v2, v4, v5 uintptr
	var _ /* bDummy at bp+16 */ int32
	var _ /* bMustBeCol at bp+12 */ int32
	var _ /* rc at bp+0 */ int32
	var _ /* zOne at bp+4 */ uintptr
	var _ /* zTwo at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = bOption, i, nByte, pRet, z, zOrig, zTail, v1, v2, v4, v5
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	v1 = Xsqlite3_malloc(tls, int32(128))
	pRet = v1
	*(*uintptr)(unsafe.Pointer(ppOut)) = v1
	if pRet == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pRet, 0, uint32(128))
	(*TFts5Config)(unsafe.Pointer(pRet)).Fdb = db
	(*TFts5Config)(unsafe.Pointer(pRet)).FiCookie = -int32(1)
	nByte = int64(uint32(uint32(nArg)) * (libc.Uint32FromInt64(4) + libc.Uint32FromInt64(1)))
	(*TFts5Config)(unsafe.Pointer(pRet)).FazCol = _sqlite3Fts5MallocZero(tls, bp, nByte)
	if (*TFts5Config)(unsafe.Pointer(pRet)).FazCol != 0 {
		v2 = (*TFts5Config)(unsafe.Pointer(pRet)).FazCol + uintptr(nArg)*4
	} else {
		v2 = uintptr(0)
	}
	(*TFts5Config)(unsafe.Pointer(pRet)).FabUnindexed = v2
	(*TFts5Config)(unsafe.Pointer(pRet)).FzDb = _sqlite3Fts5Strndup(tls, bp, *(*uintptr)(unsafe.Pointer(azArg + 1*4)), -int32(1))
	(*TFts5Config)(unsafe.Pointer(pRet)).FzName = _sqlite3Fts5Strndup(tls, bp, *(*uintptr)(unsafe.Pointer(azArg + 2*4)), -int32(1))
	(*TFts5Config)(unsafe.Pointer(pRet)).FbColumnsize = int32(1)
	(*TFts5Config)(unsafe.Pointer(pRet)).FeDetail = FTS5_DETAIL_FULL
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && Xsqlite3_stricmp(tls, (*TFts5Config)(unsafe.Pointer(pRet)).FzName, __ccgo_ts+36889) == 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36985, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(pRet)).FzName))
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
	}
	i = int32(3)
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && i < nArg) {
			break
		}
		zOrig = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4))
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		bOption = 0
		*(*int32)(unsafe.Pointer(bp + 12)) = 0
		z = _fts5ConfigGobbleWord(tls, bp, zOrig, bp+4, bp+12)
		z = _fts5ConfigSkipWhitespace(tls, z)
		if z != 0 && int32(*(*int8)(unsafe.Pointer(z))) == int32('=') {
			bOption = int32(1)
			z++
			if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
				z = uintptr(0)
			}
		}
		z = _fts5ConfigSkipWhitespace(tls, z)
		if z != 0 && *(*int8)(unsafe.Pointer(z)) != 0 {
			z = _fts5ConfigGobbleWord(tls, bp, z, bp+8, bp+16)
			if z != 0 && *(*int8)(unsafe.Pointer(z)) != 0 {
				z = uintptr(0)
			}
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			if z == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37014, libc.VaList(bp+32, zOrig))
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
			} else {
				if bOption != 0 {
					if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 {
						v4 = *(*uintptr)(unsafe.Pointer(bp + 4))
					} else {
						v4 = __ccgo_ts + 1672
					}
					if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
						v5 = *(*uintptr)(unsafe.Pointer(bp + 8))
					} else {
						v5 = __ccgo_ts + 1672
					}
					*(*int32)(unsafe.Pointer(bp)) = _fts5ConfigParseSpecial(tls, pGlobal, pRet, v4, v5, pzErr)
				} else {
					*(*int32)(unsafe.Pointer(bp)) = _fts5ConfigParseColumn(tls, pRet, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*uintptr)(unsafe.Pointer(bp + 8)), pzErr)
					*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
				}
			}
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		goto _3
	_3:
		;
		i++
	}
	/* We only allow contentless_delete=1 if the table is indeed contentless. */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FbContentlessDelete != 0 && (*TFts5Config)(unsafe.Pointer(pRet)).FeContent != int32(FTS5_CONTENT_NONE) {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37034, 0)
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
	}
	/* We only allow contentless_delete=1 if columnsize=0 is not present.
	 **
	 ** This restriction may be removed at some point.
	 */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FbContentlessDelete != 0 && (*TFts5Config)(unsafe.Pointer(pRet)).FbColumnsize == 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37084, 0)
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
	}
	/* If a tokenizer= option was successfully parsed, the tokenizer has
	 ** already been allocated. Otherwise, allocate an instance of the default
	 ** tokenizer (unicode61) now.  */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FpTok == uintptr(0) {
		*(*int32)(unsafe.Pointer(bp)) = _fts5ConfigDefaultTokenizer(tls, pGlobal, pRet)
	}
	/* If no zContent option was specified, fill in the default values. */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FzContent == uintptr(0) {
		zTail = uintptr(0)
		if (*TFts5Config)(unsafe.Pointer(pRet)).FeContent == FTS5_CONTENT_NORMAL {
			zTail = __ccgo_ts + 36572
		} else {
			if (*TFts5Config)(unsafe.Pointer(pRet)).FbColumnsize != 0 {
				zTail = __ccgo_ts + 37139
			}
		}
		if zTail != 0 {
			(*TFts5Config)(unsafe.Pointer(pRet)).FzContent = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+37147, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(pRet)).FzDb, (*TFts5Config)(unsafe.Pointer(pRet)).FzName, zTail))
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FzContentRowid == uintptr(0) {
		(*TFts5Config)(unsafe.Pointer(pRet)).FzContentRowid = _sqlite3Fts5Strndup(tls, bp, __ccgo_ts+18096, -int32(1))
	}
	/* Formulate the zContentExprlist text */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _fts5ConfigMakeExprlist(tls, pRet)
	}
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		_sqlite3Fts5ConfigFree(tls, pRet)
		*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Free the configuration object passed as the only argument.
//	*/
func _sqlite3Fts5ConfigFree(tls *libc.TLS, pConfig uintptr) {
	var i int32
	_ = i
	if pConfig != 0 {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FpTok != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_tokenizer)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FpTokApi)).FxDelete})))(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FpTok)
		}
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)
		i = 0
		for {
			if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
				break
			}
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FazCol)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzContent)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzContentRowid)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzContentExprlist)
		Xsqlite3_free(tls, pConfig)
	}
}

// C documentation
//
//	/*
//	** Call sqlite3_declare_vtab() based on the contents of the configuration
//	** object passed as the only argument. Return SQLITE_OK if successful, or
//	** an SQLite error code if an error occurs.
//	*/
func _sqlite3Fts5ConfigDeclareVtab(tls *libc.TLS, pConfig uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var zSep, zSql, v2 uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = i, zSep, zSql, v2
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+37158, 0)
	i = 0
	for {
		if !(zSql != 0 && i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
			break
		}
		if i == 0 {
			v2 = __ccgo_ts + 1672
		} else {
			v2 = __ccgo_ts + 16397
		}
		zSep = v2
		zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+37174, libc.VaList(bp+16, zSql, zSep, *(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(i)*4))))
		goto _1
	_1:
		;
		i++
	}
	zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+37181, libc.VaList(bp+16, zSql, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, __ccgo_ts+36889))
	if zSql != 0 {
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_declare_vtab(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql)
		Xsqlite3_free(tls, zSql)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Tokenize the text passed via the second and third arguments.
//	**
//	** The callback is invoked once for each token in the input text. The
//	** arguments passed to it are, in order:
//	**
//	**     void *pCtx          // Copy of 4th argument to sqlite3Fts5Tokenize()
//	**     const char *pToken  // Pointer to buffer containing token
//	**     int nToken          // Size of token in bytes
//	**     int iStart          // Byte offset of start of token within input text
//	**     int iEnd            // Byte offset of end of token within input text
//	**     int iPos            // Position of token in input (first token is 0)
//	**
//	** If the callback returns a non-zero value the tokenization is abandoned
//	** and no further callbacks are issued.
//	**
//	** This function returns SQLITE_OK if successful or an SQLite error code
//	** if an error occurs. If the tokenization was abandoned early because
//	** the callback returned SQLITE_DONE, this is not an error and this function
//	** still returns SQLITE_OK. Or, if the tokenization was abandoned early
//	** because the callback returned another non-zero value, it is assumed
//	** to be an SQLite error code and returned to the caller.
//	*/
func _sqlite3Fts5Tokenize(tls *libc.TLS, pConfig uintptr, flags int32, pText uintptr, nText int32, pCtx uintptr, xToken uintptr) (r int32) {
	if pText == uintptr(0) {
		return SQLITE_OK
	}
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_tokenizer)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FpTokApi)).FxTokenize})))(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FpTok, pCtx, flags, pText, nText, xToken)
}

// C documentation
//
//	/*
//	** Argument pIn points to the first character in what is expected to be
//	** a comma-separated list of SQL literals followed by a ')' character.
//	** If it actually is this, return a pointer to the ')'. Otherwise, return
//	** NULL to indicate a parse error.
//	*/
func _fts5ConfigSkipArgs(tls *libc.TLS, pIn uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = pIn
	for int32(1) != 0 {
		p = _fts5ConfigSkipWhitespace(tls, p)
		p = _fts5ConfigSkipLiteral(tls, p)
		p = _fts5ConfigSkipWhitespace(tls, p)
		if p == uintptr(0) || int32(*(*int8)(unsafe.Pointer(p))) == int32(')') {
			break
		}
		if int32(*(*int8)(unsafe.Pointer(p))) != int32(',') {
			p = uintptr(0)
			break
		}
		p++
	}
	return p
}

// C documentation
//
//	/*
//	** Parameter zIn contains a rank() function specification. The format of
//	** this is:
//	**
//	**   + Bareword (function name)
//	**   + Open parenthesis - "("
//	**   + Zero or more SQL literals in a comma separated list
//	**   + Close parenthesis - ")"
//	*/
func _sqlite3Fts5ConfigParseRank(tls *libc.TLS, zIn uintptr, pzRank uintptr, pzRankArgs uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p, pArgs, pRank, zRank, zRankArgs uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _ = p, pArgs, pRank, zRank, zRankArgs
	p = zIn
	zRank = uintptr(0)
	zRankArgs = uintptr(0)
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(pzRank)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(pzRankArgs)) = uintptr(0)
	if p == uintptr(0) {
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
	} else {
		p = _fts5ConfigSkipWhitespace(tls, p)
		pRank = p
		p = _fts5ConfigSkipBareword(tls, p)
		if p != 0 {
			zRank = _sqlite3Fts5MallocZero(tls, bp, int64(int32(uintptr(1)+p)-int32(int32(pRank))))
			if zRank != 0 {
				libc.Xmemcpy(tls, zRank, pRank, uint32(int32(int32(p))-int32(int32(pRank))))
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			p = _fts5ConfigSkipWhitespace(tls, p)
			if int32(*(*int8)(unsafe.Pointer(p))) != int32('(') {
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
			}
			p++
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			p = _fts5ConfigSkipWhitespace(tls, p)
			pArgs = p
			if int32(*(*int8)(unsafe.Pointer(p))) != int32(')') {
				p = _fts5ConfigSkipArgs(tls, p)
				if p == uintptr(0) {
					*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
				} else {
					zRankArgs = _sqlite3Fts5MallocZero(tls, bp, int64(int32(uintptr(1)+p)-int32(int32(pArgs))))
					if zRankArgs != 0 {
						libc.Xmemcpy(tls, zRankArgs, pArgs, uint32(int32(int32(p))-int32(int32(pArgs))))
					}
				}
			}
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		Xsqlite3_free(tls, zRank)
	} else {
		*(*uintptr)(unsafe.Pointer(pzRank)) = zRank
		*(*uintptr)(unsafe.Pointer(pzRankArgs)) = zRankArgs
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func _sqlite3Fts5ConfigSetValue(tls *libc.TLS, pConfig uintptr, zKey uintptr, pVal uintptr, pbBadkey uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bVal, nAutomerge, nCrisisMerge, nHashSize, nUsermerge, nVal, pgsz, rc, v1 int32
	var zIn uintptr
	var _ /* zRank at bp+0 */ uintptr
	var _ /* zRankArgs at bp+4 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = bVal, nAutomerge, nCrisisMerge, nHashSize, nUsermerge, nVal, pgsz, rc, zIn, v1
	rc = SQLITE_OK
	if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37207) {
		pgsz = 0
		if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
			pgsz = Xsqlite3_value_int(tls, pVal)
		}
		if pgsz < int32(32) || pgsz > libc.Int32FromInt32(64)*libc.Int32FromInt32(1024) {
			*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz = pgsz
		}
	} else {
		if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37212) {
			nHashSize = -int32(1)
			if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
				nHashSize = Xsqlite3_value_int(tls, pVal)
			}
			if nHashSize <= 0 {
				*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
			} else {
				(*TFts5Config)(unsafe.Pointer(pConfig)).FnHashSize = nHashSize
			}
		} else {
			if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37221) {
				nAutomerge = -int32(1)
				if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
					nAutomerge = Xsqlite3_value_int(tls, pVal)
				}
				if nAutomerge < 0 || nAutomerge > int32(64) {
					*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
				} else {
					if nAutomerge == int32(1) {
						nAutomerge = int32(FTS5_DEFAULT_AUTOMERGE)
					}
					(*TFts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = nAutomerge
				}
			} else {
				if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37231) {
					nUsermerge = -int32(1)
					if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
						nUsermerge = Xsqlite3_value_int(tls, pVal)
					}
					if nUsermerge < int32(2) || nUsermerge > int32(16) {
						*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
					} else {
						(*TFts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = nUsermerge
					}
				} else {
					if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37241) {
						nCrisisMerge = -int32(1)
						if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
							nCrisisMerge = Xsqlite3_value_int(tls, pVal)
						}
						if nCrisisMerge < 0 {
							*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
						} else {
							if nCrisisMerge <= int32(1) {
								nCrisisMerge = int32(FTS5_DEFAULT_CRISISMERGE)
							}
							if nCrisisMerge >= int32(FTS5_MAX_SEGMENT) {
								nCrisisMerge = libc.Int32FromInt32(FTS5_MAX_SEGMENT) - libc.Int32FromInt32(1)
							}
							(*TFts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = nCrisisMerge
						}
					} else {
						if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37253) {
							nVal = -int32(1)
							if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
								nVal = Xsqlite3_value_int(tls, pVal)
							} else {
								*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
							}
							if nVal < 0 {
								nVal = int32(FTS5_DEFAULT_DELETE_AUTOMERGE)
							}
							if nVal > int32(100) {
								nVal = 0
							}
							(*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge = nVal
						} else {
							if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+36889) {
								zIn = Xsqlite3_value_text(tls, pVal)
								rc = _sqlite3Fts5ConfigParseRank(tls, zIn, bp, bp+4)
								if rc == SQLITE_OK {
									Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank)
									Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs)
									(*TFts5Config)(unsafe.Pointer(pConfig)).FzRank = *(*uintptr)(unsafe.Pointer(bp))
									(*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs = *(*uintptr)(unsafe.Pointer(bp + 4))
								} else {
									if rc == int32(SQLITE_ERROR) {
										rc = SQLITE_OK
										*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
									}
								}
							} else {
								if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37265) {
									bVal = -int32(1)
									if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
										bVal = Xsqlite3_value_int(tls, pVal)
									}
									if bVal < 0 {
										*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
									} else {
										if bVal != 0 {
											v1 = int32(1)
										} else {
											v1 = 0
										}
										(*TFts5Config)(unsafe.Pointer(pConfig)).FbSecureDelete = v1
									}
								} else {
									*(*int32)(unsafe.Pointer(pbBadkey)) = int32(1)
								}
							}
						}
					}
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Load the contents of the %_config table into memory.
//	*/
func _sqlite3Fts5ConfigLoad(tls *libc.TLS, pConfig uintptr, iCookie int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iVersion int32
	var pVal, zK, zSelect, zSql uintptr
	var _ /* bDummy at bp+8 */ int32
	var _ /* p at bp+0 */ uintptr
	var _ /* rc at bp+4 */ int32
	_, _, _, _, _ = iVersion, pVal, zK, zSelect, zSql
	zSelect = __ccgo_ts + 37279
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK
	iVersion = 0
	/* Set default values */
	(*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz = int32(FTS5_DEFAULT_PAGE_SIZE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = int32(FTS5_DEFAULT_AUTOMERGE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = int32(FTS5_DEFAULT_USERMERGE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = int32(FTS5_DEFAULT_CRISISMERGE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnHashSize = libc.Int32FromInt32(1024) * libc.Int32FromInt32(1024)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge = int32(FTS5_DEFAULT_DELETE_AUTOMERGE)
	zSql = _sqlite3Fts5Mprintf(tls, bp+4, zSelect, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	if zSql != 0 {
		*(*int32)(unsafe.Pointer(bp + 4)) = Xsqlite3_prepare_v2(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), bp, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		for int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			zK = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			pVal = Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
			if 0 == Xsqlite3_stricmp(tls, zK, __ccgo_ts+37311) {
				iVersion = Xsqlite3_value_int(tls, pVal)
			} else {
				*(*int32)(unsafe.Pointer(bp + 8)) = 0
				_sqlite3Fts5ConfigSetValue(tls, pConfig, zK, pVal, bp+8)
			}
		}
		*(*int32)(unsafe.Pointer(bp + 4)) = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && iVersion != int32(FTS5_CURRENT_VERSION) && iVersion != int32(FTS5_CURRENT_VERSION_SECUREDELETE) {
		*(*int32)(unsafe.Pointer(bp + 4)) = int32(SQLITE_ERROR)
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg != 0 {
			*(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+37319, libc.VaList(bp+24, iVersion, int32(FTS5_CURRENT_VERSION), int32(FTS5_CURRENT_VERSION_SECUREDELETE)))
		}
	} else {
		(*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion = iVersion
	}
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		(*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie = iCookie
	}
	return *(*int32)(unsafe.Pointer(bp + 4))
}

/*
** 2014 May 31
**
** 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 "fts5Int.h" */
/* #include "fts5parse.h" */

/*
** All token types in the generated fts5parse.h file are greater than 0.
 */

type TFts5ExprTerm = struct {
	FbPrefix    Tu8
	FbFirst     Tu8
	FpTerm      uintptr
	FnQueryTerm int32
	FnFullTerm  int32
	FpIter      uintptr
	FpSynonym   uintptr
}

type Fts5ExprTerm = TFts5ExprTerm

type TFts5Expr1 = struct {
	FpIndex       uintptr
	FpConfig      uintptr
	FpRoot        uintptr
	FbDesc        int32
	FnPhrase      int32
	FapExprPhrase uintptr
}

type Fts5Expr1 = TFts5Expr1

/*
** eType:
**   Expression node type. Always one of:
**
**       FTS5_AND                 (nChild, apChild valid)
**       FTS5_OR                  (nChild, apChild valid)
**       FTS5_NOT                 (nChild, apChild valid)
**       FTS5_STRING              (pNear valid)
**       FTS5_TERM                (pNear valid)
**
** iHeight:
**   Distance from this node to furthest leaf. This is always 0 for nodes
**   of type FTS5_STRING and FTS5_TERM. For all other nodes it is one
**   greater than the largest child value.
 */
type TFts5ExprNode1 = struct {
	F__ccgo_align  [0]uint32
	FeType         int32
	FbEof          int32
	FbNomatch      int32
	FiHeight       int32
	FxNext         uintptr
	F__ccgo_align5 [4]byte
	FiRowid        Ti64
	FpNear         uintptr
	FnChild        int32
	FapChild       [1]uintptr
	F__ccgo_pad9   [4]byte
}

type Fts5ExprNode1 = TFts5ExprNode1

/*
** Invoke the xNext method of an Fts5ExprNode object. This macro should be
** used as if it has the same signature as the xNext() methods themselves.
 */

/*
** An instance of the following structure represents a single search term
** or term prefix.
 */
type TFts5ExprTerm1 = struct {
	FbPrefix    Tu8
	FbFirst     Tu8
	FpTerm      uintptr
	FnQueryTerm int32
	FnFullTerm  int32
	FpIter      uintptr
	FpSynonym   uintptr
}

type Fts5ExprTerm1 = TFts5ExprTerm1

/*
** A phrase. One or more terms that must appear in a contiguous sequence
** within a document for it to match.
 */
type TFts5ExprPhrase1 = struct {
	FpNode   uintptr
	Fposlist TFts5Buffer
	FnTerm   int32
	FaTerm   [1]TFts5ExprTerm
}

type Fts5ExprPhrase1 = TFts5ExprPhrase1

/*
** One or more phrases that must appear within a certain token distance of
** each other within each matching document.
 */
type TFts5ExprNearset1 = struct {
	FnNear    int32
	FpColset  uintptr
	FnPhrase  int32
	FapPhrase [1]uintptr
}

type Fts5ExprNearset1 = TFts5ExprNearset1

/*
** Parse context.
 */
type TFts5Parse1 = struct {
	FpConfig      uintptr
	FzErr         uintptr
	Frc           int32
	FnPhrase      int32
	FapPhrase     uintptr
	FpExpr        uintptr
	FbPhraseToAnd int32
}

type Fts5Parse1 = TFts5Parse1

/*
** Check that the Fts5ExprNode.iHeight variables are set correctly in
** the expression tree passed as the only argument.
 */

func _sqlite3Fts5ParseError(tls *libc.TLS, pParse uintptr, zFmt uintptr, va uintptr) {
	var ap Tva_list
	_ = ap
	ap = va
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		(*TFts5Parse)(unsafe.Pointer(pParse)).FzErr = Xsqlite3_vmprintf(tls, zFmt, ap)
		(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
	}
	_ = ap
}

func _fts5ExprIsspace(tls *libc.TLS, t int8) (r int32) {
	return libc.BoolInt32(int32(int32(t)) == int32(' ') || int32(int32(t)) == int32('\t') || int32(int32(t)) == int32('\n') || int32(int32(t)) == int32('\r'))
}

// C documentation
//
//	/*
//	** Read the first token from the nul-terminated string at *pz.
//	*/
func _fts5ExprGetToken(tls *libc.TLS, pParse uintptr, pz uintptr, pToken uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var tok int32
	var z, z2, z21 uintptr
	_, _, _, _ = tok, z, z2, z21
	z = *(*uintptr)(unsafe.Pointer(pz))
	/* Skip past any whitespace */
	for _fts5ExprIsspace(tls, *(*int8)(unsafe.Pointer(z))) != 0 {
		z++
	}
	(*TFts5Token)(unsafe.Pointer(pToken)).Fp = z
	(*TFts5Token)(unsafe.Pointer(pToken)).Fn = int32(1)
	switch int32(*(*int8)(unsafe.Pointer(z))) {
	case int32('('):
		tok = int32(FTS5_LP)
	case int32(')'):
		tok = int32(FTS5_RP)
	case int32('{'):
		tok = int32(FTS5_LCP)
	case int32('}'):
		tok = int32(FTS5_RCP)
	case int32(':'):
		tok = int32(FTS5_COLON)
	case int32(','):
		tok = int32(FTS5_COMMA)
	case int32('+'):
		tok = int32(FTS5_PLUS)
	case int32('*'):
		tok = int32(FTS5_STAR)
	case int32('-'):
		tok = int32(FTS5_MINUS)
	case int32('^'):
		tok = int32(FTS5_CARET)
	case int32('\000'):
		tok = FTS5_EOF
	case int32('"'):
		tok = int32(FTS5_STRING)
		z2 = z + 1
		for {
			if !(int32(1) != 0) {
				break
			}
			if int32(*(*int8)(unsafe.Pointer(z2))) == int32('"') {
				z2++
				if int32(*(*int8)(unsafe.Pointer(z2))) != int32('"') {
					break
				}
			}
			if int32(*(*int8)(unsafe.Pointer(z2))) == int32('\000') {
				_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37390, 0)
				return FTS5_EOF
			}
			goto _1
		_1:
			;
			z2++
		}
		(*TFts5Token)(unsafe.Pointer(pToken)).Fn = int32(int32(z2)) - int32(int32(z))
	default:
		if _sqlite3Fts5IsBareword(tls, *(*int8)(unsafe.Pointer(z))) == 0 {
			_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37410, libc.VaList(bp+8, z))
			return FTS5_EOF
		}
		tok = int32(FTS5_STRING)
		z21 = z + 1
		for {
			if !(_sqlite3Fts5IsBareword(tls, *(*int8)(unsafe.Pointer(z21))) != 0) {
				break
			}
			goto _2
		_2:
			;
			z21++
		}
		(*TFts5Token)(unsafe.Pointer(pToken)).Fn = int32(int32(z21)) - int32(int32(z))
		if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(2) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+37441, uint32(2)) == 0 {
			tok = int32(FTS5_OR)
		}
		if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(3) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+37444, uint32(3)) == 0 {
			tok = int32(FTS5_NOT)
		}
		if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(3) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+32185, uint32(3)) == 0 {
			tok = int32(FTS5_AND)
		}
		break
	}
	*(*uintptr)(unsafe.Pointer(pz)) = (*TFts5Token)(unsafe.Pointer(pToken)).Fp + uintptr((*TFts5Token)(unsafe.Pointer(pToken)).Fn)
	return tok
}

func _fts5ParseAlloc(tls *libc.TLS, t Tu64) (r uintptr) {
	return Xsqlite3_malloc64(tls, uint64(int64(int64(t))))
}

func _fts5ParseFree(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, p)
}

func _sqlite3Fts5ExprNew(tls *libc.TLS, pConfig uintptr, bPhraseToAnd int32, iCol int32, zExpr uintptr, ppNew uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var n, nByte, t int32
	var pColset, pEngine, pNew, v1 uintptr
	var _ /* sParse at bp+0 */ TFts5Parse
	var _ /* token at bp+32 */ TFts5Token
	var _ /* z at bp+40 */ uintptr
	_, _, _, _, _, _, _ = n, nByte, pColset, pEngine, pNew, t, v1
	*(*uintptr)(unsafe.Pointer(bp + 40)) = zExpr
	*(*uintptr)(unsafe.Pointer(ppNew)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(pzErr)) = uintptr(0)
	libc.Xmemset(tls, bp, 0, uint32(28))
	(*(*TFts5Parse)(unsafe.Pointer(bp))).FbPhraseToAnd = bPhraseToAnd
	pEngine = _sqlite3Fts5ParserAlloc(tls, __ccgo_fp(_fts5ParseAlloc))
	if pEngine == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*(*TFts5Parse)(unsafe.Pointer(bp))).FpConfig = pConfig
	for cond := true; cond; cond = (*(*TFts5Parse)(unsafe.Pointer(bp))).Frc == SQLITE_OK && t != FTS5_EOF {
		t = _fts5ExprGetToken(tls, bp, bp+40, bp+32)
		_sqlite3Fts5Parser(tls, pEngine, t, *(*TFts5Token)(unsafe.Pointer(bp + 32)), bp)
	}
	_sqlite3Fts5ParserFree(tls, pEngine, __ccgo_fp(_fts5ParseFree))
	/* If the LHS of the MATCH expression was a user column, apply the
	 ** implicit column-filter.  */
	if iCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol && (*(*TFts5Parse)(unsafe.Pointer(bp))).FpExpr != 0 && (*(*TFts5Parse)(unsafe.Pointer(bp))).Frc == SQLITE_OK {
		n = int32(8)
		pColset = _sqlite3Fts5MallocZero(tls, bp+8, int64(int64(n)))
		if pColset != 0 {
			(*TFts5Colset)(unsafe.Pointer(pColset)).FnCol = int32(1)
			*(*int32)(unsafe.Pointer(pColset + 4)) = iCol
			_sqlite3Fts5ParseSetColset(tls, bp, (*(*TFts5Parse)(unsafe.Pointer(bp))).FpExpr, pColset)
		}
	}
	if (*(*TFts5Parse)(unsafe.Pointer(bp))).Frc == SQLITE_OK {
		v1 = Xsqlite3_malloc(tls, int32(24))
		pNew = v1
		*(*uintptr)(unsafe.Pointer(ppNew)) = v1
		if pNew == uintptr(0) {
			(*(*TFts5Parse)(unsafe.Pointer(bp))).Frc = int32(SQLITE_NOMEM)
			_sqlite3Fts5ParseNodeFree(tls, (*(*TFts5Parse)(unsafe.Pointer(bp))).FpExpr)
		} else {
			if !((*(*TFts5Parse)(unsafe.Pointer(bp))).FpExpr != 0) {
				nByte = int32(48)
				(*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot = _sqlite3Fts5MallocZero(tls, bp+8, int64(int64(nByte)))
				if (*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot != 0 {
					(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FbEof = int32(1)
				}
			} else {
				(*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot = (*(*TFts5Parse)(unsafe.Pointer(bp))).FpExpr
			}
			(*TFts5Expr)(unsafe.Pointer(pNew)).FpIndex = uintptr(0)
			(*TFts5Expr)(unsafe.Pointer(pNew)).FpConfig = pConfig
			(*TFts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase = (*(*TFts5Parse)(unsafe.Pointer(bp))).FapPhrase
			(*TFts5Expr)(unsafe.Pointer(pNew)).FnPhrase = (*(*TFts5Parse)(unsafe.Pointer(bp))).FnPhrase
			(*TFts5Expr)(unsafe.Pointer(pNew)).FbDesc = 0
			(*(*TFts5Parse)(unsafe.Pointer(bp))).FapPhrase = uintptr(0)
		}
	} else {
		_sqlite3Fts5ParseNodeFree(tls, (*(*TFts5Parse)(unsafe.Pointer(bp))).FpExpr)
	}
	Xsqlite3_free(tls, (*(*TFts5Parse)(unsafe.Pointer(bp))).FapPhrase)
	*(*uintptr)(unsafe.Pointer(pzErr)) = (*(*TFts5Parse)(unsafe.Pointer(bp))).FzErr
	return (*(*TFts5Parse)(unsafe.Pointer(bp))).Frc
}

// C documentation
//
//	/*
//	** Assuming that buffer z is at least nByte bytes in size and contains a
//	** valid utf-8 string, return the number of characters in the string.
//	*/
func _fts5ExprCountChar(tls *libc.TLS, z uintptr, nByte int32) (r int32) {
	var ii, nRet int32
	_, _ = ii, nRet
	nRet = 0
	ii = 0
	for {
		if !(ii < nByte) {
			break
		}
		if int32(*(*int8)(unsafe.Pointer(z + uintptr(ii))))&int32(0xC0) != int32(0x80) {
			nRet++
		}
		goto _1
	_1:
		;
		ii++
	}
	return nRet
}

// C documentation
//
//	/*
//	** This function is only called when using the special 'trigram' tokenizer.
//	** Argument zText contains the text of a LIKE or GLOB pattern matched
//	** against column iCol. This function creates and compiles an FTS5 MATCH
//	** expression that will match a superset of the rows matched by the LIKE or
//	** GLOB. If successful, SQLITE_OK is returned. Otherwise, an SQLite error
//	** code.
//	*/
func _sqlite3Fts5ExprPattern(tls *libc.TLS, pConfig uintptr, bGlob int32, iCol int32, zText uintptr, pp uintptr) (r int32) {
	var aSpec [3]int8
	var bAnd, i, iFirst, iOut, jj, rc, v1, v3, v4, v5, v6 int32
	var nText Ti64
	var zExpr uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aSpec, bAnd, i, iFirst, iOut, jj, nText, rc, zExpr, v1, v3, v4, v5, v6
	nText = int64(libc.Xstrlen(tls, zText))
	zExpr = Xsqlite3_malloc64(tls, uint64(nText*int64(4)+int64(1)))
	rc = SQLITE_OK
	if zExpr == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		iOut = 0
		i = 0
		iFirst = 0
		if bGlob == 0 {
			aSpec[0] = int8('_')
			aSpec[int32(1)] = int8('%')
			aSpec[int32(2)] = 0
		} else {
			aSpec[0] = int8('*')
			aSpec[int32(1)] = int8('?')
			aSpec[int32(2)] = int8('[')
		}
		for int64(int64(i)) <= nText {
			if int64(int64(i)) == nText || int32(*(*int8)(unsafe.Pointer(zText + uintptr(i)))) == int32(aSpec[0]) || int32(*(*int8)(unsafe.Pointer(zText + uintptr(i)))) == int32(aSpec[int32(1)]) || int32(*(*int8)(unsafe.Pointer(zText + uintptr(i)))) == int32(aSpec[int32(2)]) {
				if _fts5ExprCountChar(tls, zText+uintptr(iFirst), i-iFirst) >= int32(3) {
					v1 = iOut
					iOut++
					*(*int8)(unsafe.Pointer(zExpr + uintptr(v1))) = int8('"')
					jj = iFirst
					for {
						if !(jj < i) {
							break
						}
						v3 = iOut
						iOut++
						*(*int8)(unsafe.Pointer(zExpr + uintptr(v3))) = *(*int8)(unsafe.Pointer(zText + uintptr(jj)))
						if int32(*(*int8)(unsafe.Pointer(zText + uintptr(jj)))) == int32('"') {
							v4 = iOut
							iOut++
							*(*int8)(unsafe.Pointer(zExpr + uintptr(v4))) = int8('"')
						}
						goto _2
					_2:
						;
						jj++
					}
					v5 = iOut
					iOut++
					*(*int8)(unsafe.Pointer(zExpr + uintptr(v5))) = int8('"')
					v6 = iOut
					iOut++
					*(*int8)(unsafe.Pointer(zExpr + uintptr(v6))) = int8(' ')
				}
				if int32(*(*int8)(unsafe.Pointer(zText + uintptr(i)))) == int32(aSpec[int32(2)]) {
					i += int32(2)
					if int32(*(*int8)(unsafe.Pointer(zText + uintptr(i-int32(1))))) == int32('^') {
						i++
					}
					for int64(int64(i)) < nText && int32(*(*int8)(unsafe.Pointer(zText + uintptr(i)))) != int32(']') {
						i++
					}
				}
				iFirst = i + int32(1)
			}
			i++
		}
		if iOut > 0 {
			bAnd = 0
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail != FTS5_DETAIL_FULL {
				bAnd = int32(1)
				if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
					iCol = (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol
				}
			}
			*(*int8)(unsafe.Pointer(zExpr + uintptr(iOut))) = int8('\000')
			rc = _sqlite3Fts5ExprNew(tls, pConfig, bAnd, iCol, zExpr, pp, (*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)
		} else {
			*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
		}
		Xsqlite3_free(tls, zExpr)
	}
	return rc
}

// C documentation
//
//	/*
//	** Free the expression node object passed as the only argument.
//	*/
func _sqlite3Fts5ParseNodeFree(tls *libc.TLS, p uintptr) {
	var i int32
	_ = i
	if p != 0 {
		i = 0
		for {
			if !(i < (*TFts5ExprNode)(unsafe.Pointer(p)).FnChild) {
				break
			}
			_sqlite3Fts5ParseNodeFree(tls, *(*uintptr)(unsafe.Pointer(p + 40 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		_sqlite3Fts5ParseNearsetFree(tls, (*TFts5ExprNode)(unsafe.Pointer(p)).FpNear)
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Free the expression object passed as the only argument.
//	*/
func _sqlite3Fts5ExprFree(tls *libc.TLS, p uintptr) {
	if p != 0 {
		_sqlite3Fts5ParseNodeFree(tls, (*TFts5Expr)(unsafe.Pointer(p)).FpRoot)
		Xsqlite3_free(tls, (*TFts5Expr)(unsafe.Pointer(p)).FapExprPhrase)
		Xsqlite3_free(tls, p)
	}
}

func _sqlite3Fts5ExprAnd(tls *libc.TLS, pp1 uintptr, p2 uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap, p1 uintptr
	var i, nPhrase int32
	var _ /* sParse at bp+0 */ TFts5Parse
	_, _, _, _ = ap, i, nPhrase, p1
	libc.Xmemset(tls, bp, 0, uint32(28))
	if *(*uintptr)(unsafe.Pointer(pp1)) != 0 && p2 != 0 {
		p1 = *(*uintptr)(unsafe.Pointer(pp1))
		nPhrase = (*TFts5Expr)(unsafe.Pointer(p1)).FnPhrase + (*TFts5Expr)(unsafe.Pointer(p2)).FnPhrase
		(*TFts5Expr)(unsafe.Pointer(p1)).FpRoot = _sqlite3Fts5ParseNode(tls, bp, int32(FTS5_AND), (*TFts5Expr)(unsafe.Pointer(p1)).FpRoot, (*TFts5Expr)(unsafe.Pointer(p2)).FpRoot, uintptr(0))
		(*TFts5Expr)(unsafe.Pointer(p2)).FpRoot = uintptr(0)
		if (*(*TFts5Parse)(unsafe.Pointer(bp))).Frc == SQLITE_OK {
			ap = Xsqlite3_realloc(tls, (*TFts5Expr)(unsafe.Pointer(p1)).FapExprPhrase, int32(uint32(uint32(nPhrase))*uint32(4)))
			if ap == uintptr(0) {
				(*(*TFts5Parse)(unsafe.Pointer(bp))).Frc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemmove(tls, ap+uintptr((*TFts5Expr)(unsafe.Pointer(p2)).FnPhrase)*4, ap, uint32((*TFts5Expr)(unsafe.Pointer(p1)).FnPhrase)*uint32(4))
				i = 0
				for {
					if !(i < (*TFts5Expr)(unsafe.Pointer(p2)).FnPhrase) {
						break
					}
					*(*uintptr)(unsafe.Pointer(ap + uintptr(i)*4)) = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(p2)).FapExprPhrase + uintptr(i)*4))
					goto _1
				_1:
					;
					i++
				}
				(*TFts5Expr)(unsafe.Pointer(p1)).FnPhrase = nPhrase
				(*TFts5Expr)(unsafe.Pointer(p1)).FapExprPhrase = ap
			}
		}
		Xsqlite3_free(tls, (*TFts5Expr)(unsafe.Pointer(p2)).FapExprPhrase)
		Xsqlite3_free(tls, p2)
	} else {
		if p2 != 0 {
			*(*uintptr)(unsafe.Pointer(pp1)) = p2
		}
	}
	return (*(*TFts5Parse)(unsafe.Pointer(bp))).Frc
}

// C documentation
//
//	/*
//	** Argument pTerm must be a synonym iterator. Return the current rowid
//	** that it points to.
//	*/
func _fts5ExprSynonymRowid(tls *libc.TLS, pTerm uintptr, bDesc int32, pbEof uintptr) (r Ti64) {
	var bRetValid int32
	var iRet, iRowid Ti64
	var p uintptr
	_, _, _, _ = bRetValid, iRet, iRowid, p
	iRet = 0
	bRetValid = 0
	p = pTerm
	for {
		if !(p != 0) {
			break
		}
		if 0 == int32((*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) {
			iRowid = (*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FiRowid
			if bRetValid == 0 || bDesc != libc.BoolInt32(iRowid < iRet) {
				iRet = iRowid
				bRetValid = int32(1)
			}
		}
		goto _1
	_1:
		;
		p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
	}
	if pbEof != 0 && bRetValid == 0 {
		*(*int32)(unsafe.Pointer(pbEof)) = int32(1)
	}
	return iRet
}

// C documentation
//
//	/*
//	** Argument pTerm must be a synonym iterator.
//	*/
func _fts5ExprSynonymList(tls *libc.TLS, pTerm uintptr, iRowid Ti64, pBuf uintptr, pa uintptr, pn uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var aIter, aNew, p, pIter uintptr
	var i, nAlloc, nIter, rc int32
	var iMin, iPrev Ti64
	var nByte Tsqlite3_int64
	var _ /* aStatic at bp+0 */ [4]TFts5PoslistReader
	var _ /* writer at bp+96 */ TFts5PoslistWriter
	_, _, _, _, _, _, _, _, _, _, _ = aIter, aNew, i, iMin, iPrev, nAlloc, nByte, nIter, p, pIter, rc
	aIter = bp
	nIter = 0
	nAlloc = int32(4)
	rc = SQLITE_OK
	p = pTerm
	for {
		if !(p != 0) {
			break
		}
		pIter = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter
		if int32((*TFts5IndexIter)(unsafe.Pointer(pIter)).FbEof) == 0 && (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == iRowid {
			if (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData == 0 {
				goto _1
			}
			if nIter == nAlloc {
				nByte = int64(uint32(24) * uint32(uint32(nAlloc)) * uint32(2))
				aNew = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
				if aNew == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
					goto synonym_poslist_out
				}
				libc.Xmemcpy(tls, aNew, aIter, uint32(24)*uint32(uint32(nIter)))
				nAlloc = nAlloc * int32(2)
				if aIter != bp {
					Xsqlite3_free(tls, aIter)
				}
				aIter = aNew
			}
			_sqlite3Fts5PoslistReaderInit(tls, (*TFts5IndexIter)(unsafe.Pointer(pIter)).FpData, (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData, aIter+uintptr(nIter)*24)
			nIter++
		}
		goto _1
	_1:
		;
		p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
	}
	if nIter == int32(1) {
		*(*uintptr)(unsafe.Pointer(pa)) = (*(*TFts5PoslistReader)(unsafe.Pointer(aIter))).Fa
		*(*int32)(unsafe.Pointer(pn)) = (*(*TFts5PoslistReader)(unsafe.Pointer(aIter))).Fn
	} else {
		*(*TFts5PoslistWriter)(unsafe.Pointer(bp + 96)) = TFts5PoslistWriter{}
		iPrev = int64(-int32(1))
		_sqlite3Fts5BufferZero(tls, pBuf)
		for int32(1) != 0 {
			iMin = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
			i = 0
			for {
				if !(i < nIter) {
					break
				}
				if int32((*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FbEof) == 0 {
					if (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FiPos == iPrev {
						if _sqlite3Fts5PoslistReaderNext(tls, aIter+uintptr(i)*24) != 0 {
							goto _2
						}
					}
					if (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FiPos < iMin {
						iMin = (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FiPos
					}
				}
				goto _2
			_2:
				;
				i++
			}
			if iMin == libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32) || rc != SQLITE_OK {
				break
			}
			rc = _sqlite3Fts5PoslistWriterAppend(tls, pBuf, bp+96, iMin)
			iPrev = iMin
		}
		if rc == SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pa)) = (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp
			*(*int32)(unsafe.Pointer(pn)) = (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn
		}
	}
	goto synonym_poslist_out
synonym_poslist_out:
	;
	if aIter != bp {
		Xsqlite3_free(tls, aIter)
	}
	return rc
}

// C documentation
//
//	/*
//	** All individual term iterators in pPhrase are guaranteed to be valid and
//	** pointing to the same rowid when this function is called. This function
//	** checks if the current rowid really is a match, and if so populates
//	** the pPhrase->poslist buffer accordingly. Output parameter *pbMatch
//	** is set to true if this is really a match, or false otherwise.
//	**
//	** SQLITE_OK is returned if an error occurs, or an SQLite error code
//	** otherwise. It is not considered an error code if the current rowid is
//	** not a match.
//	*/
func _fts5ExprPhraseIsMatch(tls *libc.TLS, pNode uintptr, pPhrase uintptr, pbMatch uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var aIter, pPos, pTerm uintptr
	var bFirst, bFlag, bMatch, i, rc int32
	var iAdj, iPos Ti64
	var nByte Tsqlite3_int64
	var _ /* a at bp+108 */ uintptr
	var _ /* aStatic at bp+8 */ [4]TFts5PoslistReader
	var _ /* buf at bp+112 */ TFts5Buffer
	var _ /* n at bp+104 */ int32
	var _ /* writer at bp+0 */ TFts5PoslistWriter
	_, _, _, _, _, _, _, _, _, _, _ = aIter, bFirst, bFlag, bMatch, i, iAdj, iPos, nByte, pPos, pTerm, rc
	*(*TFts5PoslistWriter)(unsafe.Pointer(bp)) = TFts5PoslistWriter{}
	aIter = bp + 8
	rc = SQLITE_OK
	bFirst = int32((*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FbFirst)
	_sqlite3Fts5BufferZero(tls, pPhrase+4)
	/* If the aStatic[] array is not large enough, allocate a large array
	 ** using sqlite3_malloc(). This approach could be improved upon. */
	if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > int32(libc.Uint32FromInt64(96)/libc.Uint32FromInt64(24)) {
		nByte = int64(uint32(24) * uint32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm))
		aIter = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if !(aIter != 0) {
			return int32(SQLITE_NOMEM)
		}
	}
	libc.Xmemset(tls, aIter, 0, uint32(24)*uint32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm))
	/* Initialize a term iterator for each term in the phrase */
	i = 0
	for {
		if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
			break
		}
		pTerm = pPhrase + 20 + uintptr(i)*24
		*(*int32)(unsafe.Pointer(bp + 104)) = 0
		bFlag = 0
		*(*uintptr)(unsafe.Pointer(bp + 108)) = uintptr(0)
		if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
			*(*TFts5Buffer)(unsafe.Pointer(bp + 112)) = TFts5Buffer{}
			rc = _fts5ExprSynonymList(tls, pTerm, (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid, bp+112, bp+108, bp+104)
			if rc != 0 {
				Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 108)))
				goto ismatch_out
			}
			if *(*uintptr)(unsafe.Pointer(bp + 108)) == (*(*TFts5Buffer)(unsafe.Pointer(bp + 112))).Fp {
				bFlag = int32(1)
			}
		} else {
			*(*uintptr)(unsafe.Pointer(bp + 108)) = (*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)).FpData
			*(*int32)(unsafe.Pointer(bp + 104)) = (*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)).FnData
		}
		_sqlite3Fts5PoslistReaderInit(tls, *(*uintptr)(unsafe.Pointer(bp + 108)), *(*int32)(unsafe.Pointer(bp + 104)), aIter+uintptr(i)*24)
		(*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FbFlag = uint8(uint8(bFlag))
		if (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FbEof != 0 {
			goto ismatch_out
		}
		goto _1
	_1:
		;
		i++
	}
	for int32(1) != 0 {
		iPos = (*(*TFts5PoslistReader)(unsafe.Pointer(aIter))).FiPos
		for cond := true; cond; cond = bMatch == 0 {
			bMatch = int32(1)
			i = 0
			for {
				if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
					break
				}
				pPos = aIter + uintptr(i)*24
				iAdj = iPos + int64(int64(i))
				if (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos != iAdj {
					bMatch = 0
					for (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos < iAdj {
						if _sqlite3Fts5PoslistReaderNext(tls, pPos) != 0 {
							goto ismatch_out
						}
					}
					if (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos > iAdj {
						iPos = (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos - int64(int64(i))
					}
				}
				goto _2
			_2:
				;
				i++
			}
		}
		/* Append position iPos to the output */
		if bFirst == 0 || int32(iPos&libc.Int64FromInt32(0x7FFFFFFF)) == 0 {
			rc = _sqlite3Fts5PoslistWriterAppend(tls, pPhrase+4, bp, iPos)
			if rc != SQLITE_OK {
				goto ismatch_out
			}
		}
		i = 0
		for {
			if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
				break
			}
			if _sqlite3Fts5PoslistReaderNext(tls, aIter+uintptr(i)*24) != 0 {
				goto ismatch_out
			}
			goto _3
		_3:
			;
			i++
		}
	}
	goto ismatch_out
ismatch_out:
	;
	*(*int32)(unsafe.Pointer(pbMatch)) = libc.BoolInt32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn > 0)
	i = 0
	for {
		if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
			break
		}
		if (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FbFlag != 0 {
			Xsqlite3_free(tls, (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).Fa)
		}
		goto _4
	_4:
		;
		i++
	}
	if aIter != bp+8 {
		Xsqlite3_free(tls, aIter)
	}
	return rc
}

type TFts5LookaheadReader = struct {
	F__ccgo_align  [0]uint32
	Fa             uintptr
	Fn             int32
	Fi             int32
	F__ccgo_align3 [4]byte
	FiPos          Ti64
	FiLookahead    Ti64
}

type Fts5LookaheadReader = TFts5LookaheadReader

type TFts5LookaheadReader1 = struct {
	F__ccgo_align  [0]uint32
	Fa             uintptr
	Fn             int32
	Fi             int32
	F__ccgo_align3 [4]byte
	FiPos          Ti64
	FiLookahead    Ti64
}

type Fts5LookaheadReader1 = TFts5LookaheadReader1

func _fts5LookaheadReaderNext(tls *libc.TLS, p uintptr) (r int32) {
	(*TFts5LookaheadReader)(unsafe.Pointer(p)).FiPos = (*TFts5LookaheadReader)(unsafe.Pointer(p)).FiLookahead
	if _sqlite3Fts5PoslistNext64(tls, (*TFts5LookaheadReader)(unsafe.Pointer(p)).Fa, (*TFts5LookaheadReader)(unsafe.Pointer(p)).Fn, p+8, p+24) != 0 {
		(*TFts5LookaheadReader)(unsafe.Pointer(p)).FiLookahead = libc.Int64FromInt32(1) << libc.Int32FromInt32(62)
	}
	return libc.BoolInt32((*TFts5LookaheadReader)(unsafe.Pointer(p)).FiPos == libc.Int64FromInt32(1)<<libc.Int32FromInt32(62))
}

func _fts5LookaheadReaderInit(tls *libc.TLS, a uintptr, n int32, p uintptr) (r int32) {
	libc.Xmemset(tls, p, 0, uint32(32))
	(*TFts5LookaheadReader)(unsafe.Pointer(p)).Fa = a
	(*TFts5LookaheadReader)(unsafe.Pointer(p)).Fn = n
	_fts5LookaheadReaderNext(tls, p)
	return _fts5LookaheadReaderNext(tls, p)
}

type TFts5NearTrimmer = struct {
	F__ccgo_align [0]uint32
	Freader       TFts5LookaheadReader
	Fwriter       TFts5PoslistWriter
	FpOut         uintptr
	F__ccgo_pad3  [4]byte
}

type Fts5NearTrimmer = TFts5NearTrimmer

type TFts5NearTrimmer1 = struct {
	F__ccgo_align [0]uint32
	Freader       TFts5LookaheadReader
	Fwriter       TFts5PoslistWriter
	FpOut         uintptr
	F__ccgo_pad3  [4]byte
}

type Fts5NearTrimmer1 = TFts5NearTrimmer1

// C documentation
//
//	/*
//	** The near-set object passed as the first argument contains more than
//	** one phrase. All phrases currently point to the same row. The
//	** Fts5ExprPhrase.poslist buffers are populated accordingly. This function
//	** tests if the current row contains instances of each phrase sufficiently
//	** close together to meet the NEAR constraint. Non-zero is returned if it
//	** does, or zero otherwise.
//	**
//	** If in/out parameter (*pRc) is set to other than SQLITE_OK when this
//	** function is called, it is a no-op. Or, if an error (e.g. SQLITE_NOMEM)
//	** occurs within this function (*pRc) is set accordingly before returning.
//	** The return value is undefined in both these cases.
//	**
//	** If no error occurs and non-zero (a match) is returned, the position-list
//	** of each phrase object is edited to contain only those entries that
//	** meet the constraint before returning.
//	*/
func _fts5ExprNearIsMatch(tls *libc.TLS, pRc uintptr, pNear uintptr) (r int32) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var a, apPhrase, pPos, pPoslist, pWriter uintptr
	var bMatch, bRet, i, iAdv int32
	var iMax, iMin, iPos Ti64
	var nByte Tsqlite3_int64
	var _ /* aStatic at bp+0 */ [4]TFts5NearTrimmer
	var _ /* rc at bp+192 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = a, apPhrase, bMatch, bRet, i, iAdv, iMax, iMin, iPos, nByte, pPos, pPoslist, pWriter
	a = bp
	apPhrase = pNear + 12
	*(*int32)(unsafe.Pointer(bp + 192)) = *(*int32)(unsafe.Pointer(pRc))
	/* If the aStatic[] array is not large enough, allocate a large array
	 ** using sqlite3_malloc(). This approach could be improved upon. */
	if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase > int32(libc.Uint32FromInt64(192)/libc.Uint32FromInt64(48)) {
		nByte = int64(uint32(48) * uint32((*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase))
		a = _sqlite3Fts5MallocZero(tls, bp+192, nByte)
	} else {
		libc.Xmemset(tls, bp, 0, uint32(192))
	}
	if *(*int32)(unsafe.Pointer(bp + 192)) != SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp + 192))
		return 0
	}
	/* Initialize a lookahead iterator for each phrase. After passing the
	 ** buffer and buffer size to the lookaside-reader init function, zero
	 ** the phrase poslist buffer. The new poslist for the phrase (containing
	 ** the same entries as the original with some entries removed on account
	 ** of the NEAR constraint) is written over the original even as it is
	 ** being read. This is safe as the entries for the new poslist are a
	 ** subset of the old, so it is not possible for data yet to be read to
	 ** be overwritten.  */
	i = 0
	for {
		if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
			break
		}
		pPoslist = *(*uintptr)(unsafe.Pointer(apPhrase + uintptr(i)*4)) + 4
		_fts5LookaheadReaderInit(tls, (*TFts5Buffer)(unsafe.Pointer(pPoslist)).Fp, (*TFts5Buffer)(unsafe.Pointer(pPoslist)).Fn, a+uintptr(i)*48)
		(*TFts5Buffer)(unsafe.Pointer(pPoslist)).Fn = 0
		(*(*TFts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48))).FpOut = pPoslist
		goto _1
	_1:
		;
		i++
	}
	for int32(1) != 0 {
		/* This block advances the phrase iterators until they point to a set of
		 ** entries that together comprise a match.  */
		iMax = (*(*TFts5NearTrimmer)(unsafe.Pointer(a))).Freader.FiPos
		for cond := true; cond; cond = bMatch == 0 {
			bMatch = int32(1)
			i = 0
			for {
				if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
					break
				}
				pPos = a + uintptr(i)*48
				iMin = iMax - int64((*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4)))).FnTerm) - int64((*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnNear)
				if (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos < iMin || (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos > iMax {
					bMatch = 0
					for (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos < iMin {
						if _fts5LookaheadReaderNext(tls, pPos) != 0 {
							goto ismatch_out
						}
					}
					if (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos > iMax {
						iMax = (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos
					}
				}
				goto _2
			_2:
				;
				i++
			}
		}
		/* Add an entry to each output position list */
		i = 0
		for {
			if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			iPos = (*(*TFts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48))).Freader.FiPos
			pWriter = a + uintptr(i)*48 + 32
			if (*TFts5Buffer)(unsafe.Pointer((*(*TFts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48))).FpOut)).Fn == 0 || iPos != (*TFts5PoslistWriter)(unsafe.Pointer(pWriter)).FiPrev {
				_sqlite3Fts5PoslistWriterAppend(tls, (*(*TFts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48))).FpOut, pWriter, iPos)
			}
			goto _3
		_3:
			;
			i++
		}
		iAdv = 0
		iMin = (*(*TFts5NearTrimmer)(unsafe.Pointer(a))).Freader.FiLookahead
		i = 0
		for {
			if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			if (*(*TFts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48))).Freader.FiLookahead < iMin {
				iMin = (*(*TFts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48))).Freader.FiLookahead
				iAdv = i
			}
			goto _4
		_4:
			;
			i++
		}
		if _fts5LookaheadReaderNext(tls, a+uintptr(iAdv)*48) != 0 {
			goto ismatch_out
		}
	}
	goto ismatch_out
ismatch_out:
	;
	bRet = libc.BoolInt32((*TFts5Buffer)(unsafe.Pointer((*(*TFts5NearTrimmer)(unsafe.Pointer(a))).FpOut)).Fn > 0)
	*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp + 192))
	if a != bp {
		Xsqlite3_free(tls, a)
	}
	return bRet
	return r
}

// C documentation
//
//	/*
//	** Advance iterator pIter until it points to a value equal to or laster
//	** than the initial value of *piLast. If this means the iterator points
//	** to a value laster than *piLast, update *piLast to the new lastest value.
//	**
//	** If the iterator reaches EOF, set *pbEof to true before returning. If
//	** an error occurs, set *pRc to an error code. If either *pbEof or *pRc
//	** are set, return a non-zero value. Otherwise, return zero.
//	*/
func _fts5ExprAdvanceto(tls *libc.TLS, pIter uintptr, bDesc int32, piLast uintptr, pRc uintptr, pbEof uintptr) (r int32) {
	var iLast, iRowid Ti64
	var rc int32
	_, _, _ = iLast, iRowid, rc
	iLast = *(*Ti64)(unsafe.Pointer(piLast))
	iRowid = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid
	if bDesc == 0 && iLast > iRowid || bDesc != 0 && iLast < iRowid {
		rc = _sqlite3Fts5IterNextFrom(tls, pIter, iLast)
		if rc != 0 || (*TFts5IndexIter)(unsafe.Pointer(pIter)).FbEof != 0 {
			*(*int32)(unsafe.Pointer(pRc)) = rc
			*(*int32)(unsafe.Pointer(pbEof)) = int32(1)
			return int32(1)
		}
		iRowid = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid
	}
	*(*Ti64)(unsafe.Pointer(piLast)) = iRowid
	return 0
}

func _fts5ExprSynonymAdvanceto(tls *libc.TLS, pTerm uintptr, bDesc int32, piLast uintptr, pRc uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iLast, iRowid Ti64
	var p uintptr
	var rc int32
	var _ /* bEof at bp+0 */ int32
	_, _, _, _ = iLast, iRowid, p, rc
	rc = SQLITE_OK
	iLast = *(*Ti64)(unsafe.Pointer(piLast))
	*(*int32)(unsafe.Pointer(bp)) = 0
	p = pTerm
	for {
		if !(rc == SQLITE_OK && p != 0) {
			break
		}
		if int32((*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) == 0 {
			iRowid = (*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FiRowid
			if bDesc == 0 && iLast > iRowid || bDesc != 0 && iLast < iRowid {
				rc = _sqlite3Fts5IterNextFrom(tls, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter, iLast)
			}
		}
		goto _1
	_1:
		;
		p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
	}
	if rc != SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRc)) = rc
		*(*int32)(unsafe.Pointer(bp)) = int32(1)
	} else {
		*(*Ti64)(unsafe.Pointer(piLast)) = _fts5ExprSynonymRowid(tls, pTerm, bDesc, bp)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func _fts5ExprNearTest(tls *libc.TLS, pRc uintptr, pExpr uintptr, pNode uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var pIter, pIter1, pNear, pPhrase, pPhrase1, pTerm uintptr
	var _ /* bMatch at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _ = i, pIter, pIter1, pNear, pPhrase, pPhrase1, pTerm
	pNear = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear
	*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(pRc))
	if (*TFts5Config)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FeDetail != FTS5_DETAIL_FULL {
		pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 12))
		(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = 0
		pTerm = pPhrase + 20
		for {
			if !(pTerm != 0) {
				break
			}
			pIter = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter
			if int32((*TFts5IndexIter)(unsafe.Pointer(pIter)).FbEof) == 0 {
				if (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid && (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData > 0 {
					(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = int32(1)
				}
			}
			goto _1
		_1:
			;
			pTerm = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym
		}
		return (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn
	} else {
		/* Check that each phrase in the nearset matches the current row.
		 ** Populate the pPhrase->poslist buffers at the same time. If any
		 ** phrase is not a match, break out of the loop early.  */
		i = 0
		for {
			if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			pPhrase1 = *(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4))
			if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase1)).FnTerm > int32(1) || (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase1 + 20))).FpSynonym != 0 || (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset != 0 || (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase1 + 20))).FbFirst != 0 {
				*(*int32)(unsafe.Pointer(bp + 4)) = 0
				*(*int32)(unsafe.Pointer(bp)) = _fts5ExprPhraseIsMatch(tls, pNode, pPhrase1, bp+4)
				if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
					break
				}
			} else {
				pIter1 = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase1 + 20))).FpIter
				_sqlite3Fts5BufferSet(tls, bp, pPhrase1+4, (*TFts5IndexIter)(unsafe.Pointer(pIter1)).FnData, (*TFts5IndexIter)(unsafe.Pointer(pIter1)).FpData)
			}
			goto _2
		_2:
			;
			i++
		}
		*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp))
		if i == (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase && (i == int32(1) || _fts5ExprNearIsMatch(tls, pRc, pNear) != 0) {
			return int32(1)
		}
		return 0
	}
	return r
}

// C documentation
//
//	/*
//	** Initialize all term iterators in the pNear object. If any term is found
//	** to match no documents at all, return immediately without initializing any
//	** further iterators.
//	**
//	** If an error occurs, return an SQLite error code. Otherwise, return
//	** SQLITE_OK. It is not considered an error if some term matches zero
//	** documents.
//	*/
func _fts5ExprNearInitAll(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	var bHit, i, j, rc, v4, v5 int32
	var p, pNear, pPhrase, pTerm uintptr
	_, _, _, _, _, _, _, _, _, _ = bHit, i, j, p, pNear, pPhrase, pTerm, rc, v4, v5
	pNear = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear
	i = 0
	for {
		if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
			break
		}
		pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4))
		if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm == 0 {
			(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = int32(1)
			return SQLITE_OK
		} else {
			j = 0
			for {
				if !(j < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
					break
				}
				pTerm = pPhrase + 20 + uintptr(j)*24
				bHit = 0
				p = pTerm
				for {
					if !(p != 0) {
						break
					}
					if (*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter != 0 {
						_sqlite3Fts5IterClose(tls, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)
						(*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter = uintptr(0)
					}
					if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FbPrefix != 0 {
						v4 = int32(FTS5INDEX_QUERY_PREFIX)
					} else {
						v4 = 0
					}
					if (*TFts5Expr)(unsafe.Pointer(pExpr)).FbDesc != 0 {
						v5 = int32(FTS5INDEX_QUERY_DESC)
					} else {
						v5 = 0
					}
					rc = _sqlite3Fts5IndexQuery(tls, (*TFts5Expr)(unsafe.Pointer(pExpr)).FpIndex, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpTerm, (*TFts5ExprTerm)(unsafe.Pointer(p)).FnQueryTerm, v4|v5, (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset, p+16)
					if rc != SQLITE_OK {
						return rc
					}
					if 0 == int32((*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) {
						bHit = int32(1)
					}
					goto _3
				_3:
					;
					p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
				}
				if bHit == 0 {
					(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = int32(1)
					return SQLITE_OK
				}
				goto _2
			_2:
				;
				j++
			}
		}
		goto _1
	_1:
		;
		i++
	}
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 0
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If pExpr is an ASC iterator, this function returns a value with the
//	** same sign as:
//	**
//	**   (iLhs - iRhs)
//	**
//	** Otherwise, if this is a DESC iterator, the opposite is returned:
//	**
//	**   (iRhs - iLhs)
//	*/
func _fts5RowidCmp(tls *libc.TLS, pExpr uintptr, iLhs Ti64, iRhs Ti64) (r int32) {
	if (*TFts5Expr)(unsafe.Pointer(pExpr)).FbDesc == 0 {
		if iLhs < iRhs {
			return -int32(1)
		}
		return libc.BoolInt32(iLhs > iRhs)
	} else {
		if iLhs > iRhs {
			return -int32(1)
		}
		return libc.BoolInt32(iLhs < iRhs)
	}
	return r
}

func _fts5ExprSetEof(tls *libc.TLS, pNode uintptr) {
	var i int32
	_ = i
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = int32(1)
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	i = 0
	for {
		if !(i < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
			break
		}
		_fts5ExprSetEof(tls, *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4)))
		goto _1
	_1:
		;
		i++
	}
}

func _fts5ExprNodeZeroPoslist(tls *libc.TLS, pNode uintptr) {
	var i, i1 int32
	var pNear, pPhrase uintptr
	_, _, _, _ = i, i1, pNear, pPhrase
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_STRING) || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_TERM) {
		pNear = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear
		i = 0
		for {
			if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4))
			(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = 0
			goto _1
		_1:
			;
			i++
		}
	} else {
		i1 = 0
		for {
			if !(i1 < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
				break
			}
			_fts5ExprNodeZeroPoslist(tls, *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i1)*4)))
			goto _2
		_2:
			;
			i1++
		}
	}
}

// C documentation
//
//	/*
//	** Compare the values currently indicated by the two nodes as follows:
//	**
//	**    res = (*p1) - (*p2)
//	**
//	** Nodes that point to values that come later in the iteration order are
//	** considered to be larger. Nodes at EOF are the largest of all.
//	**
//	** This means that if the iteration order is ASC, then numerically larger
//	** rowids are considered larger. Or if it is the default DESC, numerically
//	** smaller rowids are larger.
//	*/
func _fts5NodeCompare(tls *libc.TLS, pExpr uintptr, p1 uintptr, p2 uintptr) (r int32) {
	if (*TFts5ExprNode)(unsafe.Pointer(p2)).FbEof != 0 {
		return -int32(1)
	}
	if (*TFts5ExprNode)(unsafe.Pointer(p1)).FbEof != 0 {
		return +libc.Int32FromInt32(1)
	}
	return _fts5RowidCmp(tls, pExpr, (*TFts5ExprNode)(unsafe.Pointer(p1)).FiRowid, (*TFts5ExprNode)(unsafe.Pointer(p2)).FiRowid)
}

// C documentation
//
//	/*
//	** All individual term iterators in pNear are guaranteed to be valid when
//	** this function is called. This function checks if all term iterators
//	** point to the same rowid, and if not, advances them until they do.
//	** If an EOF is reached before this happens, *pbEof is set to true before
//	** returning.
//	**
//	** SQLITE_OK is returned if an error occurs, or an SQLite error code
//	** otherwise. It is not considered an error code if an iterator reaches
//	** EOF.
//	*/
func _fts5ExprNodeTest_STRING(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bDesc, bMatch, i, j int32
	var iRowid Ti64
	var pIter, pLeft, pNear, pPhrase, pTerm uintptr
	var _ /* iLast at bp+8 */ Ti64
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = bDesc, bMatch, i, iRowid, j, pIter, pLeft, pNear, pPhrase, pTerm
	pNear = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear
	pLeft = *(*uintptr)(unsafe.Pointer(pNear + 12))
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK /* True if all terms are at the same rowid */
	bDesc = (*TFts5Expr)(unsafe.Pointer(pExpr)).FbDesc
	/* Check that this node should not be FTS5_TERM */
	/* Initialize iLast, the "lastest" rowid any iterator points to. If the
	 ** iterator skips through rowids in the default ascending order, this means
	 ** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it
	 ** means the minimum rowid.  */
	if (*(*TFts5ExprTerm)(unsafe.Pointer(pLeft + 20))).FpSynonym != 0 {
		*(*Ti64)(unsafe.Pointer(bp + 8)) = _fts5ExprSynonymRowid(tls, pLeft+20, bDesc, uintptr(0))
	} else {
		*(*Ti64)(unsafe.Pointer(bp + 8)) = (*TFts5IndexIter)(unsafe.Pointer((*(*TFts5ExprTerm)(unsafe.Pointer(pLeft + 20))).FpIter)).FiRowid
	}
	for cond := true; cond; cond = bMatch == 0 {
		bMatch = int32(1)
		i = 0
		for {
			if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4))
			j = 0
			for {
				if !(j < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
					break
				}
				pTerm = pPhrase + 20 + uintptr(j)*24
				if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
					iRowid = _fts5ExprSynonymRowid(tls, pTerm, bDesc, uintptr(0))
					if iRowid == *(*Ti64)(unsafe.Pointer(bp + 8)) {
						goto _2
					}
					bMatch = 0
					if _fts5ExprSynonymAdvanceto(tls, pTerm, bDesc, bp+8, bp) != 0 {
						(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
						(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = int32(1)
						return *(*int32)(unsafe.Pointer(bp))
					}
				} else {
					pIter = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr(j)*24))).FpIter
					if (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == *(*Ti64)(unsafe.Pointer(bp + 8)) || (*TFts5IndexIter)(unsafe.Pointer(pIter)).FbEof != 0 {
						goto _2
					}
					bMatch = 0
					if _fts5ExprAdvanceto(tls, pIter, bDesc, bp+8, bp, pNode+4) != 0 {
						return *(*int32)(unsafe.Pointer(bp))
					}
				}
				goto _2
			_2:
				;
				j++
			}
			goto _1
		_1:
			;
			i++
		}
	}
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = *(*Ti64)(unsafe.Pointer(bp + 8))
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = libc.BoolInt32(0 == _fts5ExprNearTest(tls, bp, pExpr, pNode) && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Advance the first term iterator in the first phrase of pNear. Set output
//	** variable *pbEof to true if it reaches EOF or if an error occurs.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _fts5ExprNodeNext_STRING(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom Ti64) (r int32) {
	var bEof, rc int32
	var iRowid, ii Ti64
	var p, pIter, pTerm uintptr
	_, _, _, _, _, _, _ = bEof, iRowid, ii, p, pIter, pTerm, rc
	pTerm = *(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 12)) + 20
	rc = SQLITE_OK
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
		bEof = int32(1)
		/* Find the firstest rowid any synonym points to. */
		iRowid = _fts5ExprSynonymRowid(tls, pTerm, (*TFts5Expr)(unsafe.Pointer(pExpr)).FbDesc, uintptr(0))
		/* Advance each iterator that currently points to iRowid. Or, if iFrom
		 ** is valid - each iterator that points to a rowid before iFrom.  */
		p = pTerm
		for {
			if !(p != 0) {
				break
			}
			if int32((*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) == 0 {
				ii = (*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FiRowid
				if ii == iRowid || bFromValid != 0 && ii != iFrom && libc.BoolInt32(ii > iFrom) == (*TFts5Expr)(unsafe.Pointer(pExpr)).FbDesc {
					if bFromValid != 0 {
						rc = _sqlite3Fts5IterNextFrom(tls, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter, iFrom)
					} else {
						rc = _sqlite3Fts5IterNext(tls, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)
					}
					if rc != SQLITE_OK {
						break
					}
					if int32((*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) == 0 {
						bEof = 0
					}
				} else {
					bEof = 0
				}
			}
			goto _1
		_1:
			;
			p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
		}
		/* Set the EOF flag if either all synonym iterators are at EOF or an
		 ** error has occurred.  */
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = libc.BoolInt32(rc != 0 || bEof != 0)
	} else {
		pIter = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter
		if bFromValid != 0 {
			rc = _sqlite3Fts5IterNextFrom(tls, pIter, iFrom)
		} else {
			rc = _sqlite3Fts5IterNext(tls, pIter)
		}
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = libc.BoolInt32(rc != 0 || (*TFts5IndexIter)(unsafe.Pointer(pIter)).FbEof != 0)
	}
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 {
		rc = _fts5ExprNodeTest_STRING(tls, pExpr, pNode)
	}
	return rc
}

func _fts5ExprNodeTest_TERM(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	var pIter, pPhrase uintptr
	_, _ = pIter, pPhrase
	/* As this "NEAR" object is actually a single phrase that consists
	 ** of a single term only, grab pointers into the poslist managed by the
	 ** fts5_index.c iterator object. This is much faster than synthesizing
	 ** a new poslist the way we have to for more complicated phrase or NEAR
	 ** expressions.  */
	pPhrase = *(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 12))
	pIter = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FpIter
	(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData
	if (*TFts5Config)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FeDetail == FTS5_DETAIL_FULL {
		(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fp = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FpData
	}
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = libc.BoolInt32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn == 0)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** xNext() method for a node of type FTS5_TERM.
//	*/
func _fts5ExprNodeNext_TERM(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom Ti64) (r int32) {
	var pIter uintptr
	var rc int32
	_, _ = pIter, rc
	pIter = (*(*TFts5ExprTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 12)) + 20))).FpIter
	if bFromValid != 0 {
		rc = _sqlite3Fts5IterNextFrom(tls, pIter, iFrom)
	} else {
		rc = _sqlite3Fts5IterNext(tls, pIter)
	}
	if rc == SQLITE_OK && int32((*TFts5IndexIter)(unsafe.Pointer(pIter)).FbEof) == 0 {
		rc = _fts5ExprNodeTest_TERM(tls, pExpr, pNode)
	} else {
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = int32(1)
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	}
	return rc
}

func _fts5ExprNodeTest_OR(tls *libc.TLS, pExpr uintptr, pNode uintptr) {
	var cmp, i int32
	var pChild, pNext uintptr
	_, _, _, _ = cmp, i, pChild, pNext
	pNext = *(*uintptr)(unsafe.Pointer(pNode + 40))
	i = int32(1)
	for {
		if !(i < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
			break
		}
		pChild = *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4))
		cmp = _fts5NodeCompare(tls, pExpr, pNext, pChild)
		if cmp > 0 || cmp == 0 && (*TFts5ExprNode)(unsafe.Pointer(pChild)).FbNomatch == 0 {
			pNext = pChild
		}
		goto _1
	_1:
		;
		i++
	}
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*TFts5ExprNode)(unsafe.Pointer(pNext)).FiRowid
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = (*TFts5ExprNode)(unsafe.Pointer(pNext)).FbEof
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = (*TFts5ExprNode)(unsafe.Pointer(pNext)).FbNomatch
}

func _fts5ExprNodeNext_OR(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom Ti64) (r int32) {
	var i, rc int32
	var iLast Ti64
	var p1 uintptr
	_, _, _, _ = i, iLast, p1, rc
	iLast = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid
	i = 0
	for {
		if !(i < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
			break
		}
		p1 = *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4))
		if (*TFts5ExprNode)(unsafe.Pointer(p1)).FbEof == 0 {
			if (*TFts5ExprNode)(unsafe.Pointer(p1)).FiRowid == iLast || bFromValid != 0 && _fts5RowidCmp(tls, pExpr, (*TFts5ExprNode)(unsafe.Pointer(p1)).FiRowid, iFrom) < 0 {
				rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(p1)).FxNext})))(tls, pExpr, p1, bFromValid, iFrom)
				if rc != SQLITE_OK {
					(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
					return rc
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	_fts5ExprNodeTest_OR(tls, pExpr, pNode)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Argument pNode is an FTS5_AND node.
//	*/
func _fts5ExprNodeTest_AND(tls *libc.TLS, pExpr uintptr, pAnd uintptr) (r int32) {
	var bMatch, cmp, iChild, rc int32
	var iLast Ti64
	var pChild uintptr
	_, _, _, _, _, _ = bMatch, cmp, iChild, iLast, pChild, rc
	iLast = (*TFts5ExprNode)(unsafe.Pointer(pAnd)).FiRowid
	rc = SQLITE_OK
	for cond := true; cond; cond = bMatch == 0 {
		(*TFts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch = 0
		bMatch = int32(1)
		iChild = 0
		for {
			if !(iChild < (*TFts5ExprNode)(unsafe.Pointer(pAnd)).FnChild) {
				break
			}
			pChild = *(*uintptr)(unsafe.Pointer(pAnd + 40 + uintptr(iChild)*4))
			cmp = _fts5RowidCmp(tls, pExpr, iLast, (*TFts5ExprNode)(unsafe.Pointer(pChild)).FiRowid)
			if cmp > 0 {
				/* Advance pChild until it points to iLast or laster */
				rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(pChild)).FxNext})))(tls, pExpr, pChild, int32(1), iLast)
				if rc != SQLITE_OK {
					(*TFts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch = 0
					return rc
				}
			}
			/* If the child node is now at EOF, so is the parent AND node. Otherwise,
			 ** the child node is guaranteed to have advanced at least as far as
			 ** rowid iLast. So if it is not at exactly iLast, pChild->iRowid is the
			 ** new lastest rowid seen so far.  */
			if (*TFts5ExprNode)(unsafe.Pointer(pChild)).FbEof != 0 {
				_fts5ExprSetEof(tls, pAnd)
				bMatch = int32(1)
				break
			} else {
				if iLast != (*TFts5ExprNode)(unsafe.Pointer(pChild)).FiRowid {
					bMatch = 0
					iLast = (*TFts5ExprNode)(unsafe.Pointer(pChild)).FiRowid
				}
			}
			if (*TFts5ExprNode)(unsafe.Pointer(pChild)).FbNomatch != 0 {
				(*TFts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch = int32(1)
			}
			goto _1
		_1:
			;
			iChild++
		}
	}
	if (*TFts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch != 0 && pAnd != (*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot {
		_fts5ExprNodeZeroPoslist(tls, pAnd)
	}
	(*TFts5ExprNode)(unsafe.Pointer(pAnd)).FiRowid = iLast
	return SQLITE_OK
}

func _fts5ExprNodeNext_AND(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom Ti64) (r int32) {
	var rc int32
	_ = rc
	rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 40)))).FxNext})))(tls, pExpr, *(*uintptr)(unsafe.Pointer(pNode + 40)), bFromValid, iFrom)
	if rc == SQLITE_OK {
		rc = _fts5ExprNodeTest_AND(tls, pExpr, pNode)
	} else {
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	}
	return rc
}

func _fts5ExprNodeTest_NOT(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	var cmp, rc int32
	var p1, p2 uintptr
	_, _, _, _ = cmp, p1, p2, rc
	rc = SQLITE_OK
	p1 = *(*uintptr)(unsafe.Pointer(pNode + 40))
	p2 = *(*uintptr)(unsafe.Pointer(pNode + 40 + 1*4))
	for rc == SQLITE_OK && (*TFts5ExprNode)(unsafe.Pointer(p1)).FbEof == 0 {
		cmp = _fts5NodeCompare(tls, pExpr, p1, p2)
		if cmp > 0 {
			rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(p2)).FxNext})))(tls, pExpr, p2, int32(1), (*TFts5ExprNode)(unsafe.Pointer(p1)).FiRowid)
			cmp = _fts5NodeCompare(tls, pExpr, p1, p2)
		}
		if cmp != 0 || (*TFts5ExprNode)(unsafe.Pointer(p2)).FbNomatch != 0 {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(p1)).FxNext})))(tls, pExpr, p1, 0, int64(libc.Int32FromInt32(0)))
	}
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = (*TFts5ExprNode)(unsafe.Pointer(p1)).FbEof
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = (*TFts5ExprNode)(unsafe.Pointer(p1)).FbNomatch
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*TFts5ExprNode)(unsafe.Pointer(p1)).FiRowid
	if (*TFts5ExprNode)(unsafe.Pointer(p1)).FbEof != 0 {
		_fts5ExprNodeZeroPoslist(tls, p2)
	}
	return rc
}

func _fts5ExprNodeNext_NOT(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom Ti64) (r int32) {
	var rc int32
	_ = rc
	rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 40)))).FxNext})))(tls, pExpr, *(*uintptr)(unsafe.Pointer(pNode + 40)), bFromValid, iFrom)
	if rc == SQLITE_OK {
		rc = _fts5ExprNodeTest_NOT(tls, pExpr, pNode)
	}
	if rc != SQLITE_OK {
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	}
	return rc
}

// C documentation
//
//	/*
//	** If pNode currently points to a match, this function returns SQLITE_OK
//	** without modifying it. Otherwise, pNode is advanced until it does point
//	** to a match or EOF is reached.
//	*/
func _fts5ExprNodeTest(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 {
		switch (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType {
		case int32(FTS5_STRING):
			rc = _fts5ExprNodeTest_STRING(tls, pExpr, pNode)
		case int32(FTS5_TERM):
			rc = _fts5ExprNodeTest_TERM(tls, pExpr, pNode)
		case int32(FTS5_AND):
			rc = _fts5ExprNodeTest_AND(tls, pExpr, pNode)
		case int32(FTS5_OR):
			_fts5ExprNodeTest_OR(tls, pExpr, pNode)
		default:
			rc = _fts5ExprNodeTest_NOT(tls, pExpr, pNode)
			break
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Set node pNode, which is part of expression pExpr, to point to the first
//	** match. If there are no matches, set the Node.bEof flag to indicate EOF.
//	**
//	** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise.
//	** It is not an error if there are no matches.
//	*/
func _fts5ExprNodeFirst(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	var i, nEof, rc int32
	var pChild uintptr
	_, _, _, _ = i, nEof, pChild, rc
	rc = SQLITE_OK
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 0
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_TERM) || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_STRING) {
		/* Initialize all term iterators in the NEAR object. */
		rc = _fts5ExprNearInitAll(tls, pExpr, pNode)
	} else {
		if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FxNext == uintptr(0) {
			(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = int32(1)
		} else {
			nEof = 0
			i = 0
			for {
				if !(i < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild && rc == SQLITE_OK) {
					break
				}
				pChild = *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4))
				rc = _fts5ExprNodeFirst(tls, pExpr, *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4)))
				nEof += (*TFts5ExprNode)(unsafe.Pointer(pChild)).FbEof
				goto _1
			_1:
				;
				i++
			}
			(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 40)))).FiRowid
			switch (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType {
			case int32(FTS5_AND):
				if nEof > 0 {
					_fts5ExprSetEof(tls, pNode)
				}
			case int32(FTS5_OR):
				if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild == nEof {
					_fts5ExprSetEof(tls, pNode)
				}
			default:
				(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = (*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 40)))).FbEof
				break
			}
		}
	}
	if rc == SQLITE_OK {
		rc = _fts5ExprNodeTest(tls, pExpr, pNode)
	}
	return rc
}

// C documentation
//
//	/*
//	** Begin iterating through the set of documents in index pIdx matched by
//	** the MATCH expression passed as the first argument. If the "bDesc"
//	** parameter is passed a non-zero value, iteration is in descending rowid
//	** order. Or, if it is zero, in ascending order.
//	**
//	** If iterating in ascending rowid order (bDesc==0), the first document
//	** visited is that with the smallest rowid that is larger than or equal
//	** to parameter iFirst. Or, if iterating in ascending order (bDesc==1),
//	** then the first document visited must have a rowid smaller than or
//	** equal to iFirst.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
//	** is not considered an error if the query does not match any documents.
//	*/
func _sqlite3Fts5ExprFirst(tls *libc.TLS, p uintptr, pIdx uintptr, iFirst Ti64, bDesc int32) (r int32) {
	var pRoot uintptr
	var rc int32
	_, _ = pRoot, rc
	pRoot = (*TFts5Expr)(unsafe.Pointer(p)).FpRoot /* Return code */
	(*TFts5Expr)(unsafe.Pointer(p)).FpIndex = pIdx
	(*TFts5Expr)(unsafe.Pointer(p)).FbDesc = bDesc
	rc = _fts5ExprNodeFirst(tls, p, pRoot)
	/* If not at EOF but the current rowid occurs earlier than iFirst in
	 ** the iteration order, move to document iFirst or later. */
	if rc == SQLITE_OK && 0 == (*TFts5ExprNode)(unsafe.Pointer(pRoot)).FbEof && _fts5RowidCmp(tls, p, (*TFts5ExprNode)(unsafe.Pointer(pRoot)).FiRowid, iFirst) < 0 {
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(pRoot)).FxNext})))(tls, p, pRoot, int32(1), iFirst)
	}
	/* If the iterator is not at a real match, skip forward until it is. */
	for (*TFts5ExprNode)(unsafe.Pointer(pRoot)).FbNomatch != 0 && rc == SQLITE_OK {
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(pRoot)).FxNext})))(tls, p, pRoot, 0, int64(libc.Int32FromInt32(0)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Move to the next document
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
//	** is not considered an error if the query does not match any documents.
//	*/
func _sqlite3Fts5ExprNext(tls *libc.TLS, p uintptr, iLast Ti64) (r int32) {
	var pRoot uintptr
	var rc int32
	_, _ = pRoot, rc
	pRoot = (*TFts5Expr)(unsafe.Pointer(p)).FpRoot
	for cond := true; cond; cond = (*TFts5ExprNode)(unsafe.Pointer(pRoot)).FbNomatch != 0 {
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Ti64) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExprNode)(unsafe.Pointer(pRoot)).FxNext})))(tls, p, pRoot, 0, int64(libc.Int32FromInt32(0)))
	}
	if _fts5RowidCmp(tls, p, (*TFts5ExprNode)(unsafe.Pointer(pRoot)).FiRowid, iLast) > 0 {
		(*TFts5ExprNode)(unsafe.Pointer(pRoot)).FbEof = int32(1)
	}
	return rc
}

func _sqlite3Fts5ExprEof(tls *libc.TLS, p uintptr) (r int32) {
	return (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(p)).FpRoot)).FbEof
}

func _sqlite3Fts5ExprRowid(tls *libc.TLS, p uintptr) (r Ti64) {
	return (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(p)).FpRoot)).FiRowid
}

func _fts5ParseStringFromToken(tls *libc.TLS, pToken uintptr, pz uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* rc at bp+0 */ int32
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(pz)) = _sqlite3Fts5Strndup(tls, bp, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, (*TFts5Token)(unsafe.Pointer(pToken)).Fn)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Free the phrase object passed as the only argument.
//	*/
func _fts5ExprPhraseFree(tls *libc.TLS, pPhrase uintptr) {
	var i int32
	var pNext, pSyn, pTerm uintptr
	_, _, _, _ = i, pNext, pSyn, pTerm
	if pPhrase != 0 {
		i = 0
		for {
			if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
				break
			}
			pTerm = pPhrase + 20 + uintptr(i)*24
			Xsqlite3_free(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm)
			_sqlite3Fts5IterClose(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)
			pSyn = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym
			for {
				if !(pSyn != 0) {
					break
				}
				pNext = (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpSynonym
				_sqlite3Fts5IterClose(tls, (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpIter)
				_sqlite3Fts5BufferFree(tls, pSyn+1*24)
				Xsqlite3_free(tls, pSyn)
				goto _2
			_2:
				;
				pSyn = pNext
			}
			goto _1
		_1:
			;
			i++
		}
		if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.FnSpace > 0 {
			_sqlite3Fts5BufferFree(tls, pPhrase+4)
		}
		Xsqlite3_free(tls, pPhrase)
	}
}

// C documentation
//
//	/*
//	** Set the "bFirst" flag on the first token of the phrase passed as the
//	** only argument.
//	*/
func _sqlite3Fts5ParseSetCaret(tls *libc.TLS, pPhrase uintptr) {
	if pPhrase != 0 && (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm != 0 {
		(*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FbFirst = uint8(1)
	}
}

// C documentation
//
//	/*
//	** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated
//	** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is
//	** appended to it and the results returned.
//	**
//	** If an OOM error occurs, both the pNear and pPhrase objects are freed and
//	** NULL returned.
//	*/
func _sqlite3Fts5ParseNearset(tls *libc.TLS, pParse uintptr, pNear uintptr, pPhrase uintptr) (r uintptr) {
	var SZALLOC, nNew, v1 int32
	var nByte, nByte1 Tsqlite3_int64
	var pLast, pRet, v2 uintptr
	_, _, _, _, _, _, _, _ = SZALLOC, nByte, nByte1, nNew, pLast, pRet, v1, v2
	SZALLOC = int32(8)
	pRet = uintptr(0)
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		if pPhrase == uintptr(0) {
			return pNear
		}
		if pNear == uintptr(0) {
			nByte = int64(uint32(16) + uint32(uint32(SZALLOC))*uint32(4))
			pRet = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
			if pRet == uintptr(0) {
				(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemset(tls, pRet, 0, uint32(uint32(nByte)))
			}
		} else {
			if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase%SZALLOC == 0 {
				nNew = (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase + SZALLOC
				nByte1 = int64(uint32(16) + uint32(uint32(nNew))*uint32(4))
				pRet = Xsqlite3_realloc64(tls, pNear, uint64(uint64(nByte1)))
				if pRet == uintptr(0) {
					(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
				}
			} else {
				pRet = pNear
			}
		}
	}
	if pRet == uintptr(0) {
		_sqlite3Fts5ParseNearsetFree(tls, pNear)
		_sqlite3Fts5ParsePhraseFree(tls, pPhrase)
	} else {
		if (*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase > 0 {
			pLast = *(*uintptr)(unsafe.Pointer(pRet + 12 + uintptr((*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase-int32(1))*4))
			if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm == 0 {
				_fts5ExprPhraseFree(tls, pPhrase)
				(*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase--
				(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
				pPhrase = pLast
			} else {
				if (*TFts5ExprPhrase)(unsafe.Pointer(pLast)).FnTerm == 0 {
					_fts5ExprPhraseFree(tls, pLast)
					*(*uintptr)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase-int32(2))*4)) = pPhrase
					(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
					(*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase--
				}
			}
		}
		v2 = pRet + 8
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2))++
		*(*uintptr)(unsafe.Pointer(pRet + 12 + uintptr(v1)*4)) = pPhrase
	}
	return pRet
}

type TTokenCtx = struct {
	FpPhrase uintptr
	FpConfig uintptr
	Frc      int32
}

type TokenCtx = TTokenCtx

type TTokenCtx1 = struct {
	FpPhrase uintptr
	FpConfig uintptr
	Frc      int32
}

type TokenCtx1 = TTokenCtx1

// C documentation
//
//	/*
//	** Callback for tokenizing terms used by ParseTerm().
//	*/
func _fts5ParseTokenize(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var SZALLOC, nNew, v1, v2, v4, v6 int32
	var nByte Tsqlite3_int64
	var pCtx, pNew, pPhrase, pSyn, pTerm, v3, v5 uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = SZALLOC, nByte, nNew, pCtx, pNew, pPhrase, pSyn, pTerm, v1, v2, v3, v4, v5, v6
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	SZALLOC = int32(8)
	pCtx = pContext
	pPhrase = (*TTokenCtx)(unsafe.Pointer(pCtx)).FpPhrase
	_ = iUnused1
	_ = iUnused2
	/* If an error has already occurred, this is a no-op */
	if (*TTokenCtx)(unsafe.Pointer(pCtx)).Frc != SQLITE_OK {
		return (*TTokenCtx)(unsafe.Pointer(pCtx)).Frc
	}
	if nToken > int32(FTS5_MAX_TOKEN_SIZE) {
		nToken = int32(FTS5_MAX_TOKEN_SIZE)
	}
	if pPhrase != 0 && (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 0 && tflags&int32(FTS5_TOKEN_COLOCATED) != 0 {
		nByte = int64(libc.Uint32FromInt64(24) + libc.Uint32FromInt64(12) + uint32(uint32(nToken)) + uint32(1))
		pSyn = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if pSyn == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, pSyn, 0, uint32(uint32(nByte)))
			(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpTerm = pSyn + uintptr(24) + uintptr(12)
			v1 = nToken
			(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FnQueryTerm = v1
			(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FnFullTerm = v1
			if (*TFts5Config)(unsafe.Pointer((*TTokenCtx)(unsafe.Pointer(pCtx)).FpConfig)).FbTokendata != 0 {
				(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FnQueryTerm = int32(libc.Xstrlen(tls, (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpTerm))
			}
			libc.Xmemcpy(tls, (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpTerm, pToken, uint32(uint32(nToken)))
			(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpSynonym = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm-int32(1))*24))).FpSynonym
			(*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm-int32(1))*24))).FpSynonym = pSyn
		}
	} else {
		if pPhrase == uintptr(0) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm%SZALLOC == 0 {
			if pPhrase != 0 {
				v2 = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm
			} else {
				v2 = 0
			}
			nNew = SZALLOC + v2
			pNew = Xsqlite3_realloc64(tls, pPhrase, uint64(uint32(44)+uint32(24)*uint32(uint32(nNew))))
			if pNew == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
			} else {
				if pPhrase == uintptr(0) {
					libc.Xmemset(tls, pNew, 0, uint32(44))
				}
				v3 = pNew
				pPhrase = v3
				(*TTokenCtx)(unsafe.Pointer(pCtx)).FpPhrase = v3
				(*TFts5ExprPhrase)(unsafe.Pointer(pNew)).FnTerm = nNew - SZALLOC
			}
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			v5 = pPhrase + 16
			v4 = *(*int32)(unsafe.Pointer(v5))
			*(*int32)(unsafe.Pointer(v5))++
			pTerm = pPhrase + 20 + uintptr(v4)*24
			libc.Xmemset(tls, pTerm, 0, uint32(24))
			(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm = _sqlite3Fts5Strndup(tls, bp, pToken, nToken)
			v6 = nToken
			(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnQueryTerm = v6
			(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnFullTerm = v6
			if (*TFts5Config)(unsafe.Pointer((*TTokenCtx)(unsafe.Pointer(pCtx)).FpConfig)).FbTokendata != 0 && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnQueryTerm = int32(libc.Xstrlen(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm))
			}
		}
	}
	(*TTokenCtx)(unsafe.Pointer(pCtx)).Frc = *(*int32)(unsafe.Pointer(bp))
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Free the phrase object passed as the only argument.
//	*/
func _sqlite3Fts5ParsePhraseFree(tls *libc.TLS, pPhrase uintptr) {
	_fts5ExprPhraseFree(tls, pPhrase)
}

// C documentation
//
//	/*
//	** Free the phrase object passed as the second argument.
//	*/
func _sqlite3Fts5ParseNearsetFree(tls *libc.TLS, pNear uintptr) {
	var i int32
	_ = i
	if pNear != 0 {
		i = 0
		for {
			if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			_fts5ExprPhraseFree(tls, *(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset)
		Xsqlite3_free(tls, pNear)
	}
}

func _sqlite3Fts5ParseFinished(tls *libc.TLS, pParse uintptr, p uintptr) {
	(*TFts5Parse)(unsafe.Pointer(pParse)).FpExpr = p
}

func _parseGrowPhraseArray(tls *libc.TLS, pParse uintptr) (r int32) {
	var apNew uintptr
	var nByte Tsqlite3_int64
	_, _ = apNew, nByte
	if (*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase%int32(8) == 0 {
		nByte = int64(uint32(4) * uint32((*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase+libc.Int32FromInt32(8)))
		apNew = Xsqlite3_realloc64(tls, (*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase, uint64(uint64(nByte)))
		if apNew == uintptr(0) {
			(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
			return int32(SQLITE_NOMEM)
		}
		(*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase = apNew
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function is called by the parser to process a string token. The
//	** string may or may not be quoted. In any case it is tokenized and a
//	** phrase object consisting of all tokens returned.
//	*/
func _sqlite3Fts5ParseTerm(tls *libc.TLS, pParse uintptr, pAppend uintptr, pToken uintptr, bPrefix int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var flags, n, rc, v1, v2 int32
	var pConfig uintptr
	var v3 bool
	var _ /* sCtx at bp+0 */ TTokenCtx
	var _ /* z at bp+12 */ uintptr
	_, _, _, _, _, _, _ = flags, n, pConfig, rc, v1, v2, v3
	pConfig = (*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig /* Tokenize return code */
	*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
	libc.Xmemset(tls, bp, 0, uint32(12))
	(*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase = pAppend
	(*(*TTokenCtx)(unsafe.Pointer(bp))).FpConfig = pConfig
	rc = _fts5ParseStringFromToken(tls, pToken, bp+12)
	if rc == SQLITE_OK {
		if bPrefix != 0 {
			v1 = int32(FTS5_TOKENIZE_PREFIX)
		} else {
			v1 = 0
		}
		flags = int32(FTS5_TOKENIZE_QUERY) | v1
		_sqlite3Fts5Dequote(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
		n = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp + 12))))
		rc = _sqlite3Fts5Tokenize(tls, pConfig, flags, *(*uintptr)(unsafe.Pointer(bp + 12)), n, bp, __ccgo_fp(_fts5ParseTokenize))
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
	if v3 = rc != 0; !v3 {
		v2 = (*(*TTokenCtx)(unsafe.Pointer(bp))).Frc
		rc = v2
	}
	if v3 || v2 != 0 {
		(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = rc
		_fts5ExprPhraseFree(tls, (*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase)
		(*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase = uintptr(0)
	} else {
		if pAppend == uintptr(0) {
			if _parseGrowPhraseArray(tls, pParse) != 0 {
				_fts5ExprPhraseFree(tls, (*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase)
				return uintptr(0)
			}
			(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase++
		}
		if (*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase == uintptr(0) {
			/* This happens when parsing a token or quoted phrase that contains
			 ** no token characters at all. (e.g ... MATCH '""'). */
			(*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase = _sqlite3Fts5MallocZero(tls, pParse+8, int64(44))
		} else {
			if (*TFts5ExprPhrase)(unsafe.Pointer((*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase)).FnTerm != 0 {
				(*(*TFts5ExprTerm)(unsafe.Pointer((*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase + 20 + uintptr((*TFts5ExprPhrase)(unsafe.Pointer((*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase)).FnTerm-int32(1))*24))).FbPrefix = uint8(uint8(bPrefix))
			}
		}
		*(*uintptr)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase-int32(1))*4)) = (*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase
	}
	return (*(*TTokenCtx)(unsafe.Pointer(bp))).FpPhrase
}

// C documentation
//
//	/*
//	** Create a new FTS5 expression by cloning phrase iPhrase of the
//	** expression passed as the second argument.
//	*/
func _sqlite3Fts5ExprClonePhrase(tls *libc.TLS, pExpr uintptr, iPhrase int32, ppNew uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, tflags int32
	var nByte Tsqlite3_int64
	var p, pColset, pColsetOrig, pNew, pOrig uintptr
	var _ /* rc at bp+0 */ int32
	var _ /* sCtx at bp+4 */ TTokenCtx
	_, _, _, _, _, _, _, _ = i, nByte, p, pColset, pColsetOrig, pNew, pOrig, tflags
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK           /* Return code */
	pOrig = uintptr(0)                                  /* The phrase extracted from pExpr */
	pNew = uintptr(0)                                   /* Expression to return via *ppNew */
	*(*TTokenCtx)(unsafe.Pointer(bp + 4)) = TTokenCtx{} /* Context object for fts5ParseTokenize */
	if iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_RANGE)
	} else {
		pOrig = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
		pNew = _sqlite3Fts5MallocZero(tls, bp, int64(24))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*TFts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase = _sqlite3Fts5MallocZero(tls, bp, int64(4))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot = _sqlite3Fts5MallocZero(tls, bp, int64(48))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear = _sqlite3Fts5MallocZero(tls, bp, int64(libc.Uint32FromInt64(16)+libc.Uint32FromInt64(4)))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && pOrig != uintptr(0) {
		pColsetOrig = (*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FpNode)).FpNear)).FpColset
		if pColsetOrig != 0 {
			nByte = int64(uint32(8) + uint32((*TFts5Colset)(unsafe.Pointer(pColsetOrig)).FnCol-libc.Int32FromInt32(1))*uint32(4))
			pColset = _sqlite3Fts5MallocZero(tls, bp, nByte)
			if pColset != 0 {
				libc.Xmemcpy(tls, pColset, pColsetOrig, uint32(uint32(nByte)))
			}
			(*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear)).FpColset = pColset
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		if (*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm != 0 { /* Used to iterate through phrase terms */
			(*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpConfig = (*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig
			i = 0
			for {
				if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && i < (*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm) {
					break
				}
				tflags = 0
				p = pOrig + 20 + uintptr(i)*24
				for {
					if !(p != 0 && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK) {
						break
					}
					*(*int32)(unsafe.Pointer(bp)) = _fts5ParseTokenize(tls, bp+4, tflags, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpTerm, (*TFts5ExprTerm)(unsafe.Pointer(p)).FnFullTerm, 0, 0)
					tflags = int32(FTS5_TOKEN_COLOCATED)
					goto _2
				_2:
					;
					p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
				}
				if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
					(*(*TFts5ExprTerm)(unsafe.Pointer((*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase + 20 + uintptr(i)*24))).FbPrefix = (*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 20 + uintptr(i)*24))).FbPrefix
					(*(*TFts5ExprTerm)(unsafe.Pointer((*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase + 20 + uintptr(i)*24))).FbFirst = (*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 20 + uintptr(i)*24))).FbFirst
				}
				goto _1
			_1:
				;
				i++
			}
		} else {
			/* This happens when parsing a token or quoted phrase that contains
			 ** no token characters at all. (e.g ... MATCH '""'). */
			(*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase = _sqlite3Fts5MallocZero(tls, bp, int64(44))
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase != 0 {
		/* All the allocations succeeded. Put the expression object together. */
		(*TFts5Expr)(unsafe.Pointer(pNew)).FpIndex = (*TFts5Expr)(unsafe.Pointer(pExpr)).FpIndex
		(*TFts5Expr)(unsafe.Pointer(pNew)).FpConfig = (*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig
		(*TFts5Expr)(unsafe.Pointer(pNew)).FnPhrase = int32(1)
		*(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase)) = (*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase
		*(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear + 12)) = (*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase
		(*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear)).FnPhrase = int32(1)
		(*TFts5ExprPhrase)(unsafe.Pointer((*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase)).FpNode = (*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot
		if (*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm == int32(1) && (*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 20))).FpSynonym == uintptr(0) && int32((*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 20))).FbFirst) == 0 {
			(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FeType = int32(FTS5_TERM)
			(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FxNext = __ccgo_fp(_fts5ExprNodeNext_TERM)
		} else {
			(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FeType = int32(FTS5_STRING)
			(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FxNext = __ccgo_fp(_fts5ExprNodeNext_STRING)
		}
	} else {
		_sqlite3Fts5ExprFree(tls, pNew)
		_fts5ExprPhraseFree(tls, (*(*TTokenCtx)(unsafe.Pointer(bp + 4))).FpPhrase)
		pNew = uintptr(0)
	}
	*(*uintptr)(unsafe.Pointer(ppNew)) = pNew
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Token pTok has appeared in a MATCH expression where the NEAR operator
//	** is expected. If token pTok does not contain "NEAR", store an error
//	** in the pParse object.
//	*/
func _sqlite3Fts5ParseNear(tls *libc.TLS, pParse uintptr, pTok uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	if (*TFts5Token)(unsafe.Pointer(pTok)).Fn != int32(4) || libc.Xmemcmp(tls, __ccgo_ts+37448, (*TFts5Token)(unsafe.Pointer(pTok)).Fp, uint32(4)) != 0 {
		_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+36229, libc.VaList(bp+8, (*TFts5Token)(unsafe.Pointer(pTok)).Fn, (*TFts5Token)(unsafe.Pointer(pTok)).Fp))
	}
}

func _sqlite3Fts5ParseSetDistance(tls *libc.TLS, pParse uintptr, pNear uintptr, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var c int8
	var i, nNear int32
	_, _, _ = c, i, nNear
	if pNear != 0 {
		nNear = 0
		if (*TFts5Token)(unsafe.Pointer(p)).Fn != 0 {
			i = 0
			for {
				if !(i < (*TFts5Token)(unsafe.Pointer(p)).Fn) {
					break
				}
				c = *(*int8)(unsafe.Pointer((*TFts5Token)(unsafe.Pointer(p)).Fp + uintptr(i)))
				if int32(int32(c)) < int32('0') || int32(int32(c)) > int32('9') {
					_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37453, libc.VaList(bp+8, (*TFts5Token)(unsafe.Pointer(p)).Fn, (*TFts5Token)(unsafe.Pointer(p)).Fp))
					return
				}
				nNear = nNear*int32(10) + (int32(*(*int8)(unsafe.Pointer((*TFts5Token)(unsafe.Pointer(p)).Fp + uintptr(i)))) - int32('0'))
				goto _1
			_1:
				;
				i++
			}
		} else {
			nNear = int32(FTS5_DEFAULT_NEARDIST)
		}
		(*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnNear = nNear
	}
}

// C documentation
//
//	/*
//	** The second argument passed to this function may be NULL, or it may be
//	** an existing Fts5Colset object. This function returns a pointer to
//	** a new colset object containing the contents of (p) with new value column
//	** number iCol appended.
//	**
//	** If an OOM error occurs, store an error code in pParse and return NULL.
//	** The old colset object (if any) is not freed in this case.
//	*/
func _fts5ParseColset(tls *libc.TLS, pParse uintptr, p uintptr, iCol int32) (r uintptr) {
	var aiCol, pNew uintptr
	var i, j, nCol, v1 int32
	_, _, _, _, _, _ = aiCol, i, j, nCol, pNew, v1
	if p != 0 {
		v1 = (*TFts5Colset)(unsafe.Pointer(p)).FnCol
	} else {
		v1 = 0
	}
	nCol = v1 /* New colset object to return */
	pNew = Xsqlite3_realloc64(tls, p, uint64(uint32(8)+uint32(4)*uint32(uint32(nCol))))
	if pNew == uintptr(0) {
		(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
	} else {
		aiCol = pNew + 4
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			if *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) == iCol {
				return pNew
			}
			if *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) > iCol {
				break
			}
			goto _2
		_2:
			;
			i++
		}
		j = nCol
		for {
			if !(j > i) {
				break
			}
			*(*int32)(unsafe.Pointer(aiCol + uintptr(j)*4)) = *(*int32)(unsafe.Pointer(aiCol + uintptr(j-int32(1))*4))
			goto _3
		_3:
			;
			j--
		}
		*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) = iCol
		(*TFts5Colset)(unsafe.Pointer(pNew)).FnCol = nCol + int32(1)
	}
	return pNew
}

// C documentation
//
//	/*
//	** Allocate and return an Fts5Colset object specifying the inverse of
//	** the colset passed as the second argument. Free the colset passed
//	** as the second argument before returning.
//	*/
func _sqlite3Fts5ParseColsetInvert(tls *libc.TLS, pParse uintptr, p uintptr) (r uintptr) {
	var i, iOld, nCol, v2 int32
	var pRet, v3 uintptr
	_, _, _, _, _, _ = i, iOld, nCol, pRet, v2, v3
	nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FnCol
	pRet = _sqlite3Fts5MallocZero(tls, pParse+8, int64(uint32(8)+uint32(4)*uint32(uint32(nCol))))
	if pRet != 0 {
		iOld = 0
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			if iOld >= (*TFts5Colset)(unsafe.Pointer(p)).FnCol || *(*int32)(unsafe.Pointer(p + 4 + uintptr(iOld)*4)) != i {
				v3 = pRet
				v2 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3))++
				*(*int32)(unsafe.Pointer(pRet + 4 + uintptr(v2)*4)) = i
			} else {
				iOld++
			}
			goto _1
		_1:
			;
			i++
		}
	}
	Xsqlite3_free(tls, p)
	return pRet
}

func _sqlite3Fts5ParseColset(tls *libc.TLS, pParse uintptr, pColset uintptr, p uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCol int32
	var pConfig, pRet, z uintptr
	_, _, _, _ = iCol, pConfig, pRet, z
	pRet = uintptr(0) /* Dequoted copy of token p */
	z = _sqlite3Fts5Strndup(tls, pParse+8, (*TFts5Token)(unsafe.Pointer(p)).Fp, (*TFts5Token)(unsafe.Pointer(p)).Fn)
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		pConfig = (*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig
		_sqlite3Fts5Dequote(tls, z)
		iCol = 0
		for {
			if !(iCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
				break
			}
			if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(iCol)*4)), z) {
				break
			}
			goto _1
		_1:
			;
			iCol++
		}
		if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
			_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+22474, libc.VaList(bp+8, z))
		} else {
			pRet = _fts5ParseColset(tls, pParse, pColset, iCol)
		}
		Xsqlite3_free(tls, z)
	}
	if pRet == uintptr(0) {
		Xsqlite3_free(tls, pColset)
	}
	return pRet
}

// C documentation
//
//	/*
//	** If argument pOrig is NULL, or if (*pRc) is set to anything other than
//	** SQLITE_OK when this function is called, NULL is returned.
//	**
//	** Otherwise, a copy of (*pOrig) is made into memory obtained from
//	** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
//	** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
//	*/
func _fts5CloneColset(tls *libc.TLS, pRc uintptr, pOrig uintptr) (r uintptr) {
	var nByte Tsqlite3_int64
	var pRet uintptr
	_, _ = nByte, pRet
	if pOrig != 0 {
		nByte = int64(uint32(8) + uint32((*TFts5Colset)(unsafe.Pointer(pOrig)).FnCol-libc.Int32FromInt32(1))*uint32(4))
		pRet = _sqlite3Fts5MallocZero(tls, pRc, nByte)
		if pRet != 0 {
			libc.Xmemcpy(tls, pRet, pOrig, uint32(uint32(nByte)))
		}
	} else {
		pRet = uintptr(0)
	}
	return pRet
}

// C documentation
//
//	/*
//	** Remove from colset pColset any columns that are not also in colset pMerge.
//	*/
func _fts5MergeColset(tls *libc.TLS, pColset uintptr, pMerge uintptr) {
	var iDiff, iIn, iMerge, iOut, v1 int32
	_, _, _, _, _ = iDiff, iIn, iMerge, iOut, v1
	iIn = 0    /* Next input in pColset */
	iMerge = 0 /* Next input in pMerge */
	iOut = 0   /* Next output slot in pColset */
	for iIn < (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol && iMerge < (*TFts5Colset)(unsafe.Pointer(pMerge)).FnCol {
		iDiff = *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(iIn)*4)) - *(*int32)(unsafe.Pointer(pMerge + 4 + uintptr(iMerge)*4))
		if iDiff == 0 {
			v1 = iOut
			iOut++
			*(*int32)(unsafe.Pointer(pColset + 4 + uintptr(v1)*4)) = *(*int32)(unsafe.Pointer(pMerge + 4 + uintptr(iMerge)*4))
			iMerge++
			iIn++
		} else {
			if iDiff > 0 {
				iMerge++
			} else {
				iIn++
			}
		}
	}
	(*TFts5Colset)(unsafe.Pointer(pColset)).FnCol = iOut
}

// C documentation
//
//	/*
//	** Recursively apply colset pColset to expression node pNode and all of
//	** its decendents. If (*ppFree) is not NULL, it contains a spare copy
//	** of pColset. This function may use the spare copy and set (*ppFree) to
//	** zero, or it may create copies of pColset using fts5CloneColset().
//	*/
func _fts5ParseSetColset(tls *libc.TLS, pParse uintptr, pNode uintptr, pColset uintptr, ppFree uintptr) {
	var i int32
	var pNear uintptr
	_, _ = i, pNear
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_STRING) || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_TERM) {
			pNear = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear
			if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset != 0 {
				_fts5MergeColset(tls, (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset, pColset)
				if (*TFts5Colset)(unsafe.Pointer((*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset)).FnCol == 0 {
					(*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType = FTS5_EOF
					(*TFts5ExprNode)(unsafe.Pointer(pNode)).FxNext = uintptr(0)
				}
			} else {
				if *(*uintptr)(unsafe.Pointer(ppFree)) != 0 {
					(*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset = pColset
					*(*uintptr)(unsafe.Pointer(ppFree)) = uintptr(0)
				} else {
					(*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset = _fts5CloneColset(tls, pParse+8, pColset)
				}
			}
		} else {
			i = 0
			for {
				if !(i < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
					break
				}
				_fts5ParseSetColset(tls, pParse, *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4)), pColset, ppFree)
				goto _1
			_1:
				;
				i++
			}
		}
	}
}

// C documentation
//
//	/*
//	** Apply colset pColset to expression node pExpr and all of its descendents.
//	*/
func _sqlite3Fts5ParseSetColset(tls *libc.TLS, pParse uintptr, pExpr uintptr, pColset uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* pFree at bp+0 */ uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = pColset
	if (*TFts5Config)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
		_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37482, 0)
	} else {
		_fts5ParseSetColset(tls, pParse, pExpr, pColset, bp)
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _fts5ExprAssignXNext(tls *libc.TLS, pNode uintptr) {
	var pNear uintptr
	_ = pNear
	switch (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType {
	case int32(FTS5_STRING):
		pNear = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear
		if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase == int32(1) && (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12)))).FnTerm == int32(1) && (*(*TFts5ExprTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12)) + 20))).FpSynonym == uintptr(0) && int32((*(*TFts5ExprTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12)) + 20))).FbFirst) == 0 {
			(*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType = int32(FTS5_TERM)
			(*TFts5ExprNode)(unsafe.Pointer(pNode)).FxNext = __ccgo_fp(_fts5ExprNodeNext_TERM)
		} else {
			(*TFts5ExprNode)(unsafe.Pointer(pNode)).FxNext = __ccgo_fp(_fts5ExprNodeNext_STRING)
		}
	case int32(FTS5_OR):
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FxNext = __ccgo_fp(_fts5ExprNodeNext_OR)
	case int32(FTS5_AND):
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FxNext = __ccgo_fp(_fts5ExprNodeNext_AND)
	default:
		(*TFts5ExprNode)(unsafe.Pointer(pNode)).FxNext = __ccgo_fp(_fts5ExprNodeNext_NOT)
		break
	}
}

func _fts5ExprAddChildren(tls *libc.TLS, p uintptr, pSub uintptr) {
	var ii, nByte, v1, v4 int32
	var v2 uintptr
	_, _, _, _, _ = ii, nByte, v1, v2, v4
	ii = (*TFts5ExprNode)(unsafe.Pointer(p)).FnChild
	if (*TFts5ExprNode)(unsafe.Pointer(p)).FeType != int32(FTS5_NOT) && (*TFts5ExprNode)(unsafe.Pointer(pSub)).FeType == (*TFts5ExprNode)(unsafe.Pointer(p)).FeType {
		nByte = int32(uint32(4) * uint32((*TFts5ExprNode)(unsafe.Pointer(pSub)).FnChild))
		libc.Xmemcpy(tls, p+40+uintptr((*TFts5ExprNode)(unsafe.Pointer(p)).FnChild)*4, pSub+40, uint32(uint32(nByte)))
		*(*int32)(unsafe.Pointer(p + 36)) += (*TFts5ExprNode)(unsafe.Pointer(pSub)).FnChild
		Xsqlite3_free(tls, pSub)
	} else {
		v2 = p + 36
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2))++
		*(*uintptr)(unsafe.Pointer(p + 40 + uintptr(v1)*4)) = pSub
	}
	for {
		if !(ii < (*TFts5ExprNode)(unsafe.Pointer(p)).FnChild) {
			break
		}
		if (*TFts5ExprNode)(unsafe.Pointer(p)).FiHeight > (*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 40 + uintptr(ii)*4)))).FiHeight+int32(1) {
			v4 = (*TFts5ExprNode)(unsafe.Pointer(p)).FiHeight
		} else {
			v4 = (*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 40 + uintptr(ii)*4)))).FiHeight + int32(1)
		}
		(*TFts5ExprNode)(unsafe.Pointer(p)).FiHeight = v4
		goto _3
	_3:
		;
		ii++
	}
}

// C documentation
//
//	/*
//	** This function is used when parsing LIKE or GLOB patterns against
//	** trigram indexes that specify either detail=column or detail=none.
//	** It converts a phrase:
//	**
//	**     abc + def + ghi
//	**
//	** into an AND tree:
//	**
//	**     abc AND def AND ghi
//	*/
func _fts5ParsePhraseToAnd(tls *libc.TLS, pParse uintptr, pNear uintptr) (r uintptr) {
	var ii, nByte, nTerm, v2 int32
	var p, pPhrase, pRet, pTo, v3 uintptr
	_, _, _, _, _, _, _, _, _ = ii, nByte, nTerm, p, pPhrase, pRet, pTo, v2, v3
	nTerm = (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12)))).FnTerm
	nByte = int32(uint32(48) + uint32(uint32(nTerm))*uint32(4))
	pRet = _sqlite3Fts5MallocZero(tls, pParse+8, int64(int64(nByte)))
	if pRet != 0 {
		(*TFts5ExprNode)(unsafe.Pointer(pRet)).FeType = int32(FTS5_AND)
		(*TFts5ExprNode)(unsafe.Pointer(pRet)).FnChild = nTerm
		(*TFts5ExprNode)(unsafe.Pointer(pRet)).FiHeight = int32(1)
		_fts5ExprAssignXNext(tls, pRet)
		(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
		ii = 0
		for {
			if !(ii < nTerm) {
				break
			}
			pPhrase = _sqlite3Fts5MallocZero(tls, pParse+8, int64(44))
			if pPhrase != 0 {
				if _parseGrowPhraseArray(tls, pParse) != 0 {
					_fts5ExprPhraseFree(tls, pPhrase)
				} else {
					p = *(*uintptr)(unsafe.Pointer(pNear + 12)) + 20 + uintptr(ii)*24
					pTo = pPhrase + 20
					v3 = pParse + 12
					v2 = *(*int32)(unsafe.Pointer(v3))
					*(*int32)(unsafe.Pointer(v3))++
					*(*uintptr)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr(v2)*4)) = pPhrase
					(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm = int32(1)
					(*TFts5ExprTerm)(unsafe.Pointer(pTo)).FpTerm = _sqlite3Fts5Strndup(tls, pParse+8, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpTerm, (*TFts5ExprTerm)(unsafe.Pointer(p)).FnFullTerm)
					(*TFts5ExprTerm)(unsafe.Pointer(pTo)).FnQueryTerm = (*TFts5ExprTerm)(unsafe.Pointer(p)).FnQueryTerm
					(*TFts5ExprTerm)(unsafe.Pointer(pTo)).FnFullTerm = (*TFts5ExprTerm)(unsafe.Pointer(p)).FnFullTerm
					*(*uintptr)(unsafe.Pointer(pRet + 40 + uintptr(ii)*4)) = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_STRING), uintptr(0), uintptr(0), _sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), pPhrase))
				}
			}
			goto _1
		_1:
			;
			ii++
		}
		if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc != 0 {
			_sqlite3Fts5ParseNodeFree(tls, pRet)
			pRet = uintptr(0)
		} else {
			_sqlite3Fts5ParseNearsetFree(tls, pNear)
		}
	}
	return pRet
}

// C documentation
//
//	/*
//	** Allocate and return a new expression object. If anything goes wrong (i.e.
//	** OOM error), leave an error code in pParse and return NULL.
//	*/
func _sqlite3Fts5ParseNode(tls *libc.TLS, pParse uintptr, eType int32, pLeft uintptr, pRight uintptr, pNear uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPhrase, nChild int32
	var nByte Tsqlite3_int64
	var pPhrase, pRet, v2 uintptr
	_, _, _, _, _, _ = iPhrase, nByte, nChild, pPhrase, pRet, v2
	pRet = uintptr(0)
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		nChild = 0 /* Bytes of space to allocate for this node */
		if eType == int32(FTS5_STRING) && pNear == uintptr(0) {
			return uintptr(0)
		}
		if eType != int32(FTS5_STRING) && pLeft == uintptr(0) {
			return pRight
		}
		if eType != int32(FTS5_STRING) && pRight == uintptr(0) {
			return pLeft
		}
		if eType == int32(FTS5_STRING) && (*TFts5Parse)(unsafe.Pointer(pParse)).FbPhraseToAnd != 0 && (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12)))).FnTerm > int32(1) {
			pRet = _fts5ParsePhraseToAnd(tls, pParse, pNear)
		} else {
			if eType == int32(FTS5_NOT) {
				nChild = int32(2)
			} else {
				if eType == int32(FTS5_AND) || eType == int32(FTS5_OR) {
					nChild = int32(2)
					if (*TFts5ExprNode)(unsafe.Pointer(pLeft)).FeType == eType {
						nChild += (*TFts5ExprNode)(unsafe.Pointer(pLeft)).FnChild - int32(1)
					}
					if (*TFts5ExprNode)(unsafe.Pointer(pRight)).FeType == eType {
						nChild += (*TFts5ExprNode)(unsafe.Pointer(pRight)).FnChild - int32(1)
					}
				}
			}
			nByte = int64(uint32(48) + uint32(4)*uint32(nChild-libc.Int32FromInt32(1)))
			pRet = _sqlite3Fts5MallocZero(tls, pParse+8, nByte)
			if pRet != 0 {
				(*TFts5ExprNode)(unsafe.Pointer(pRet)).FeType = eType
				(*TFts5ExprNode)(unsafe.Pointer(pRet)).FpNear = pNear
				_fts5ExprAssignXNext(tls, pRet)
				if eType == int32(FTS5_STRING) {
					iPhrase = 0
					for {
						if !(iPhrase < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
							break
						}
						(*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(iPhrase)*4)))).FpNode = pRet
						if (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(iPhrase)*4)))).FnTerm == 0 {
							(*TFts5ExprNode)(unsafe.Pointer(pRet)).FxNext = uintptr(0)
							(*TFts5ExprNode)(unsafe.Pointer(pRet)).FeType = FTS5_EOF
						}
						goto _1
					_1:
						;
						iPhrase++
					}
					if (*TFts5Config)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail != FTS5_DETAIL_FULL {
						pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 12))
						if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase != int32(1) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > int32(1) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 0 && (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FbFirst != 0 {
							if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase == int32(1) {
								v2 = __ccgo_ts + 37535
							} else {
								v2 = __ccgo_ts + 37448
							}
							_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37542, libc.VaList(bp+8, v2))
							Xsqlite3_free(tls, pRet)
							pRet = uintptr(0)
						}
					}
				} else {
					_fts5ExprAddChildren(tls, pRet, pLeft)
					_fts5ExprAddChildren(tls, pRet, pRight)
					if (*TFts5ExprNode)(unsafe.Pointer(pRet)).FiHeight > int32(SQLITE_FTS5_MAX_EXPR_DEPTH) {
						_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37592, libc.VaList(bp+8, int32(SQLITE_FTS5_MAX_EXPR_DEPTH)))
						Xsqlite3_free(tls, pRet)
						pRet = uintptr(0)
					}
				}
			}
		}
	}
	if pRet == uintptr(0) {
		_sqlite3Fts5ParseNodeFree(tls, pLeft)
		_sqlite3Fts5ParseNodeFree(tls, pRight)
		_sqlite3Fts5ParseNearsetFree(tls, pNear)
	}
	return pRet
}

func _sqlite3Fts5ParseImplicitAnd(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr) (r uintptr) {
	var ap, pPrev, pRet uintptr
	_, _, _ = ap, pPrev, pRet
	pRet = uintptr(0)
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc != 0 {
		_sqlite3Fts5ParseNodeFree(tls, pLeft)
		_sqlite3Fts5ParseNodeFree(tls, pRight)
	} else {
		if (*TFts5ExprNode)(unsafe.Pointer(pLeft)).FeType == int32(FTS5_AND) {
			pPrev = *(*uintptr)(unsafe.Pointer(pLeft + 40 + uintptr((*TFts5ExprNode)(unsafe.Pointer(pLeft)).FnChild-int32(1))*4))
		} else {
			pPrev = pLeft
		}
		if (*TFts5ExprNode)(unsafe.Pointer(pRight)).FeType == FTS5_EOF {
			_sqlite3Fts5ParseNodeFree(tls, pRight)
			pRet = pLeft
			(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
		} else {
			if (*TFts5ExprNode)(unsafe.Pointer(pPrev)).FeType == FTS5_EOF {
				if pPrev == pLeft {
					pRet = pRight
				} else {
					*(*uintptr)(unsafe.Pointer(pLeft + 40 + uintptr((*TFts5ExprNode)(unsafe.Pointer(pLeft)).FnChild-int32(1))*4)) = pRight
					pRet = pLeft
				}
				ap = (*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase-int32(1)-(*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pRight)).FpNear)).FnPhrase)*4
				libc.Xmemmove(tls, ap, ap+1*4, uint32(4)*uint32((*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pRight)).FpNear)).FnPhrase))
				(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
				_sqlite3Fts5ParseNodeFree(tls, pPrev)
			} else {
				pRet = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_AND), pLeft, pRight, uintptr(0))
			}
		}
	}
	return pRet
}

// C documentation
//
//	/*
//	** This is called during initialization to register the fts5_expr() scalar
//	** UDF with the SQLite handle passed as the only argument.
//	*/
func _sqlite3Fts5ExprInit(tls *libc.TLS, pGlobal uintptr, db uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	_ = pGlobal
	_ = db
	/* Avoid warnings indicating that sqlite3Fts5ParserTrace() and
	 ** sqlite3Fts5ParserFallback() are unused */
	_ = __ccgo_fp(_sqlite3Fts5ParserFallback)
	return rc
}

// C documentation
//
//	/*
//	** Return the number of phrases in expression pExpr.
//	*/
func _sqlite3Fts5ExprPhraseCount(tls *libc.TLS, pExpr uintptr) (r int32) {
	var v1 int32
	_ = v1
	if pExpr != 0 {
		v1 = (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Return the number of terms in the iPhrase'th phrase in pExpr.
//	*/
func _sqlite3Fts5ExprPhraseSize(tls *libc.TLS, pExpr uintptr, iPhrase int32) (r int32) {
	if iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		return 0
	}
	return (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4)))).FnTerm
}

// C documentation
//
//	/*
//	** This function is used to access the current position list for phrase
//	** iPhrase.
//	*/
func _sqlite3Fts5ExprPoslist(tls *libc.TLS, pExpr uintptr, iPhrase int32, pa uintptr) (r int32) {
	var nRet int32
	var pNode, pPhrase uintptr
	_, _, _ = nRet, pNode, pPhrase
	pPhrase = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	pNode = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FpNode
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 && (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid == (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid {
		*(*uintptr)(unsafe.Pointer(pa)) = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fp
		nRet = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn
	} else {
		*(*uintptr)(unsafe.Pointer(pa)) = uintptr(0)
		nRet = 0
	}
	return nRet
}

type TFts5PoslistPopulator1 = struct {
	F__ccgo_align [0]uint32
	Fwriter       TFts5PoslistWriter
	FbOk          int32
	FbMiss        int32
}

type Fts5PoslistPopulator1 = TFts5PoslistPopulator1

// C documentation
//
//	/*
//	** Clear the position lists associated with all phrases in the expression
//	** passed as the first argument. Argument bLive is true if the expression
//	** might be pointing to a real entry, otherwise it has just been reset.
//	**
//	** At present this function is only used for detail=col and detail=none
//	** fts5 tables. This implies that all phrases must be at most 1 token
//	** in size, as phrase matches are not supported without detail=full.
//	*/
func _sqlite3Fts5ExprClearPoslists(tls *libc.TLS, pExpr uintptr, bLive int32) (r uintptr) {
	var i int32
	var pBuf, pNode, pRet uintptr
	_, _, _, _ = i, pBuf, pNode, pRet
	pRet = Xsqlite3_malloc64(tls, uint64(uint32(16)*uint32((*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase)))
	if pRet != 0 {
		libc.Xmemset(tls, pRet, 0, uint32(16)*uint32((*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase))
		i = 0
		for {
			if !(i < (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase) {
				break
			}
			pBuf = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*4)) + 4
			pNode = (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*4)))).FpNode
			if bLive != 0 && ((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn == 0 || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid != (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof != 0) {
				(*(*TFts5PoslistPopulator)(unsafe.Pointer(pRet + uintptr(i)*16))).FbMiss = int32(1)
			} else {
				(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn = 0
			}
			goto _1
		_1:
			;
			i++
		}
	}
	return pRet
}

type TFts5ExprCtx1 = struct {
	F__ccgo_align [0]uint32
	FpExpr        uintptr
	FaPopulator   uintptr
	FiOff         Ti64
}

type Fts5ExprCtx1 = TFts5ExprCtx1

type TFts5ExprCtx = struct {
	F__ccgo_align [0]uint32
	FpExpr        uintptr
	FaPopulator   uintptr
	FiOff         Ti64
}

type Fts5ExprCtx = TFts5ExprCtx

// C documentation
//
//	/*
//	** TODO: Make this more efficient!
//	*/
func _fts5ExprColsetTest(tls *libc.TLS, pColset uintptr, iCol int32) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol) {
			break
		}
		if *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) == iCol {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/*
//	** pToken is a buffer nToken bytes in size that may or may not contain
//	** an embedded 0x00 byte. If it does, return the number of bytes in
//	** the buffer before the 0x00. If it does not, return nToken.
//	*/
func _fts5QueryTerm(tls *libc.TLS, pToken uintptr, nToken int32) (r int32) {
	var ii int32
	_ = ii
	ii = 0
	for {
		if !(ii < nToken && *(*int8)(unsafe.Pointer(pToken + uintptr(ii))) != 0) {
			break
		}
		goto _1
	_1:
		;
		ii++
	}
	return ii
}

func _fts5ExprPopulatePoslistsCb(tls *libc.TLS, pCtx uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) (r int32) {
	var i, iCol, iTokOff, nQuery, rc int32
	var iRowid Ti64
	var p, pExpr, pT uintptr
	_, _, _, _, _, _, _, _, _ = i, iCol, iRowid, iTokOff, nQuery, p, pExpr, pT, rc
	p = pCtx
	pExpr = (*TFts5ExprCtx)(unsafe.Pointer(p)).FpExpr
	nQuery = nToken
	iRowid = (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid
	_ = iUnused1
	_ = iUnused2
	if nQuery > int32(FTS5_MAX_TOKEN_SIZE) {
		nQuery = int32(FTS5_MAX_TOKEN_SIZE)
	}
	if (*TFts5Config)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FbTokendata != 0 {
		nQuery = _fts5QueryTerm(tls, pToken, nQuery)
	}
	if tflags&int32(FTS5_TOKEN_COLOCATED) == 0 {
		(*TFts5ExprCtx)(unsafe.Pointer(p)).FiOff++
	}
	i = 0
	for {
		if !(i < (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase) {
			break
		}
		if (*(*TFts5PoslistPopulator)(unsafe.Pointer((*TFts5ExprCtx)(unsafe.Pointer(p)).FaPopulator + uintptr(i)*16))).FbOk == 0 {
			goto _1
		}
		pT = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*4)) + 20
		for {
			if !(pT != 0) {
				break
			}
			if ((*TFts5ExprTerm)(unsafe.Pointer(pT)).FnQueryTerm == nQuery || (*TFts5ExprTerm)(unsafe.Pointer(pT)).FnQueryTerm < nQuery && (*TFts5ExprTerm)(unsafe.Pointer(pT)).FbPrefix != 0) && libc.Xmemcmp(tls, (*TFts5ExprTerm)(unsafe.Pointer(pT)).FpTerm, pToken, uint32((*TFts5ExprTerm)(unsafe.Pointer(pT)).FnQueryTerm)) == 0 {
				rc = _sqlite3Fts5PoslistWriterAppend(tls, *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*4))+4, (*TFts5ExprCtx)(unsafe.Pointer(p)).FaPopulator+uintptr(i)*16, (*TFts5ExprCtx)(unsafe.Pointer(p)).FiOff)
				if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FbTokendata != 0 && !((*TFts5ExprTerm)(unsafe.Pointer(pT)).FbPrefix != 0) {
					iCol = int32((*TFts5ExprCtx)(unsafe.Pointer(p)).FiOff >> int32(32))
					iTokOff = int32((*TFts5ExprCtx)(unsafe.Pointer(p)).FiOff & int64(0x7FFFFFFF))
					rc = _sqlite3Fts5IndexIterWriteTokendata(tls, (*TFts5ExprTerm)(unsafe.Pointer(pT)).FpIter, pToken, nToken, iRowid, iCol, iTokOff)
				}
				if rc != 0 {
					return rc
				}
				break
			}
			goto _2
		_2:
			;
			pT = (*TFts5ExprTerm)(unsafe.Pointer(pT)).FpSynonym
		}
		goto _1
	_1:
		;
		i++
	}
	return SQLITE_OK
}

func _sqlite3Fts5ExprPopulatePoslists(tls *libc.TLS, pConfig uintptr, pExpr uintptr, aPopulator uintptr, iCol int32, z uintptr, n int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var pColset, pNode uintptr
	var _ /* sCtx at bp+0 */ TFts5ExprCtx
	_, _, _ = i, pColset, pNode
	(*(*TFts5ExprCtx)(unsafe.Pointer(bp))).FpExpr = pExpr
	(*(*TFts5ExprCtx)(unsafe.Pointer(bp))).FaPopulator = aPopulator
	(*(*TFts5ExprCtx)(unsafe.Pointer(bp))).FiOff = int64(int64(iCol))<<libc.Int32FromInt32(32) - int64(1)
	i = 0
	for {
		if !(i < (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase) {
			break
		}
		pNode = (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*4)))).FpNode
		pColset = (*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear)).FpColset
		if pColset != 0 && 0 == _fts5ExprColsetTest(tls, pColset, iCol) || (*(*TFts5PoslistPopulator)(unsafe.Pointer(aPopulator + uintptr(i)*16))).FbMiss != 0 {
			(*(*TFts5PoslistPopulator)(unsafe.Pointer(aPopulator + uintptr(i)*16))).FbOk = 0
		} else {
			(*(*TFts5PoslistPopulator)(unsafe.Pointer(aPopulator + uintptr(i)*16))).FbOk = int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), z, n, bp, __ccgo_fp(_fts5ExprPopulatePoslistsCb))
}

func _fts5ExprClearPoslists(tls *libc.TLS, pNode uintptr) {
	var i int32
	_ = i
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_TERM) || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType == int32(FTS5_STRING) {
		(*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 12)))).Fposlist.Fn = 0
	} else {
		i = 0
		for {
			if !(i < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
				break
			}
			_fts5ExprClearPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
	}
}

func _fts5ExprCheckPoslists(tls *libc.TLS, pNode uintptr, iRowid Ti64) (r int32) {
	var bRet, i, i1 int32
	_, _, _ = bRet, i, i1
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = iRowid
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 0
	switch (*TFts5ExprNode)(unsafe.Pointer(pNode)).FeType {
	case int32(FTS5_TERM):
		fallthrough
	case int32(FTS5_STRING):
		return libc.BoolInt32((*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 12)))).Fposlist.Fn > 0)
	case int32(FTS5_AND):
		i = 0
		for {
			if !(i < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
				break
			}
			if _fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i)*4)), iRowid) == 0 {
				_fts5ExprClearPoslists(tls, pNode)
				return 0
			}
			goto _1
		_1:
			;
			i++
		}
	case int32(FTS5_OR):
		bRet = 0
		i1 = 0
		for {
			if !(i1 < (*TFts5ExprNode)(unsafe.Pointer(pNode)).FnChild) {
				break
			}
			if _fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 40 + uintptr(i1)*4)), iRowid) != 0 {
				bRet = int32(1)
			}
			goto _2
		_2:
			;
			i1++
		}
		return bRet
	default:
		if 0 == _fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 40)), iRowid) || 0 != _fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 40 + 1*4)), iRowid) {
			_fts5ExprClearPoslists(tls, pNode)
			return 0
		}
		break
	}
	return int32(1)
}

func _sqlite3Fts5ExprCheckPoslists(tls *libc.TLS, pExpr uintptr, iRowid Ti64) {
	_fts5ExprCheckPoslists(tls, (*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot, iRowid)
}

// C documentation
//
//	/*
//	** This function is only called for detail=columns tables.
//	*/
func _sqlite3Fts5ExprPhraseCollist(tls *libc.TLS, pExpr uintptr, iPhrase int32, ppCollist uintptr, pnCollist uintptr) (r int32) {
	var pBuf, pNode, pPhrase, pTerm uintptr
	var rc int32
	_, _, _, _, _ = pBuf, pNode, pPhrase, pTerm, rc
	pPhrase = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	pNode = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FpNode
	rc = SQLITE_OK
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 && (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid == (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid && (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn > 0 {
		pTerm = pPhrase + 20
		if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
			pBuf = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym + 1*24
			rc = _fts5ExprSynonymList(tls, pTerm, (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid, pBuf, ppCollist, pnCollist)
		} else {
			*(*uintptr)(unsafe.Pointer(ppCollist)) = (*TFts5IndexIter)(unsafe.Pointer((*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FpIter)).FpData
			*(*int32)(unsafe.Pointer(pnCollist)) = (*TFts5IndexIter)(unsafe.Pointer((*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FpIter)).FnData
		}
	} else {
		*(*uintptr)(unsafe.Pointer(ppCollist)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pnCollist)) = 0
	}
	return rc
}

// C documentation
//
//	/*
//	** Does the work of the fts5_api.xQueryToken() API method.
//	*/
func _sqlite3Fts5ExprQueryToken(tls *libc.TLS, pExpr uintptr, iPhrase int32, iToken int32, ppOut uintptr, pnOut uintptr) (r int32) {
	var pPhrase uintptr
	_ = pPhrase
	pPhrase = uintptr(0)
	if iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		return int32(SQLITE_RANGE)
	}
	pPhrase = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	if iToken < 0 || iToken >= (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm {
		return int32(SQLITE_RANGE)
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr(iToken)*24))).FpTerm
	*(*int32)(unsafe.Pointer(pnOut)) = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr(iToken)*24))).FnFullTerm
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Does the work of the fts5_api.xInstToken() API method.
//	*/
func _sqlite3Fts5ExprInstToken(tls *libc.TLS, pExpr uintptr, iRowid Ti64, iPhrase int32, iCol int32, iOff int32, iToken int32, ppOut uintptr, pnOut uintptr) (r int32) {
	var pPhrase, pTerm uintptr
	var rc int32
	_, _, _ = pPhrase, pTerm, rc
	pPhrase = uintptr(0)
	pTerm = uintptr(0)
	rc = SQLITE_OK
	if iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		return int32(SQLITE_RANGE)
	}
	pPhrase = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	if iToken < 0 || iToken >= (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm {
		return int32(SQLITE_RANGE)
	}
	pTerm = pPhrase + 20 + uintptr(iToken)*24
	if int32((*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FbPrefix) == 0 {
		if (*TFts5Config)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FbTokendata != 0 {
			rc = _sqlite3Fts5IterToken(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter, iRowid, iCol, iOff+iToken, ppOut, pnOut)
		} else {
			*(*uintptr)(unsafe.Pointer(ppOut)) = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm
			*(*int32)(unsafe.Pointer(pnOut)) = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnFullTerm
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Clear the token mappings for all Fts5IndexIter objects mannaged by
//	** the expression passed as the only argument.
//	*/
func _sqlite3Fts5ExprClearTokens(tls *libc.TLS, pExpr uintptr) {
	var ii int32
	var pT uintptr
	_, _ = ii, pT
	ii = 0
	for {
		if !(ii < (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase) {
			break
		}
		pT = *(*uintptr)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(ii)*4)) + 20
		for {
			if !(pT != 0) {
				break
			}
			_sqlite3Fts5IndexIterClearTokendata(tls, (*TFts5ExprTerm)(unsafe.Pointer(pT)).FpIter)
			goto _2
		_2:
			;
			pT = (*TFts5ExprTerm)(unsafe.Pointer(pT)).FpSynonym
		}
		goto _1
	_1:
		;
		ii++
	}
}

/*
** 2014 August 11
**
** 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 "fts5Int.h" */

type TFts5HashEntry = struct {
	F__ccgo_align [0]uint32
	FpHashNext    uintptr
	FpScanNext    uintptr
	FnAlloc       int32
	FiSzPoslist   int32
	FnData        int32
	FnKey         int32
	FbDel         Tu8
	FbContent     Tu8
	FiCol         Ti16
	FiPos         int32
	FiRowid       Ti64
}

type Fts5HashEntry = TFts5HashEntry

/*
** This file contains the implementation of an in-memory hash table used
** to accumuluate "term -> doclist" content before it is flused to a level-0
** segment.
 */

type TFts5Hash1 = struct {
	FeDetail int32
	FpnByte  uintptr
	FnEntry  int32
	FnSlot   int32
	FpScan   uintptr
	FaSlot   uintptr
}

type Fts5Hash1 = TFts5Hash1

/*
** Each entry in the hash table is represented by an object of the
** following type. Each object, its key, and its current data are stored
** in a single memory allocation. The key immediately follows the object
** in memory. The position list data immediately follows the key data
** in memory.
**
** The key is Fts5HashEntry.nKey bytes in size. It consists of a single
** byte identifying the index (either the main term index or a prefix-index),
** followed by the term data. For example: "0token". There is no
** nul-terminator - in this case nKey=6.
**
** The data that follows the key is in a similar, but not identical format
** to the doclist data stored in the database. It is:
**
**   * Rowid, as a varint
**   * Position list, without 0x00 terminator.
**   * Size of previous position list and rowid, as a 4 byte
**     big-endian integer.
**
** iRowidOff:
**   Offset of last rowid written to data area. Relative to first byte of
**   structure.
**
** nData:
**   Bytes of data written since iRowidOff.
 */
type TFts5HashEntry1 = struct {
	F__ccgo_align [0]uint32
	FpHashNext    uintptr
	FpScanNext    uintptr
	FnAlloc       int32
	FiSzPoslist   int32
	FnData        int32
	FnKey         int32
	FbDel         Tu8
	FbContent     Tu8
	FiCol         Ti16
	FiPos         int32
	FiRowid       Ti64
}

type Fts5HashEntry1 = TFts5HashEntry1

/*
** Eqivalent to:
**
**   char *fts5EntryKey(Fts5HashEntry *pEntry){ return zKey; }
 */

// C documentation
//
//	/*
//	** Allocate a new hash table.
//	*/
func _sqlite3Fts5HashNew(tls *libc.TLS, pConfig uintptr, ppNew uintptr, pnByte uintptr) (r int32) {
	var nByte Tsqlite3_int64
	var pNew, v1 uintptr
	var rc int32
	_, _, _, _ = nByte, pNew, rc, v1
	rc = SQLITE_OK
	v1 = Xsqlite3_malloc(tls, int32(24))
	pNew = v1
	*(*uintptr)(unsafe.Pointer(ppNew)) = v1
	if pNew == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, pNew, 0, uint32(24))
		(*TFts5Hash)(unsafe.Pointer(pNew)).FpnByte = pnByte
		(*TFts5Hash)(unsafe.Pointer(pNew)).FeDetail = (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail
		(*TFts5Hash)(unsafe.Pointer(pNew)).FnSlot = int32(1024)
		nByte = int64(uint32(4) * uint32((*TFts5Hash)(unsafe.Pointer(pNew)).FnSlot))
		(*TFts5Hash)(unsafe.Pointer(pNew)).FaSlot = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if (*TFts5Hash)(unsafe.Pointer(pNew)).FaSlot == uintptr(0) {
			Xsqlite3_free(tls, pNew)
			*(*uintptr)(unsafe.Pointer(ppNew)) = uintptr(0)
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, (*TFts5Hash)(unsafe.Pointer(pNew)).FaSlot, 0, uint32(uint32(nByte)))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Free a hash table object.
//	*/
func _sqlite3Fts5HashFree(tls *libc.TLS, pHash uintptr) {
	if pHash != 0 {
		_sqlite3Fts5HashClear(tls, pHash)
		Xsqlite3_free(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot)
		Xsqlite3_free(tls, pHash)
	}
}

// C documentation
//
//	/*
//	** Empty (but do not delete) a hash table.
//	*/
func _sqlite3Fts5HashClear(tls *libc.TLS, pHash uintptr) {
	var i int32
	var pNext, pSlot uintptr
	_, _, _ = i, pNext, pSlot
	i = 0
	for {
		if !(i < (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot) {
			break
		}
		pSlot = *(*uintptr)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(i)*4))
		for {
			if !(pSlot != 0) {
				break
			}
			pNext = (*TFts5HashEntry)(unsafe.Pointer(pSlot)).FpHashNext
			Xsqlite3_free(tls, pSlot)
			goto _2
		_2:
			;
			pSlot = pNext
		}
		goto _1
	_1:
		;
		i++
	}
	libc.Xmemset(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot, 0, uint32((*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot)*uint32(4))
	(*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry = 0
}

func _fts5HashKey(tls *libc.TLS, nSlot int32, p uintptr, n int32) (r uint32) {
	var h uint32
	var i int32
	_, _ = h, i
	h = uint32(13)
	i = n - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		h = h<<int32(3) ^ h ^ uint32(*(*Tu8)(unsafe.Pointer(p + uintptr(i))))
		goto _1
	_1:
		;
		i--
	}
	return h % uint32(uint32(nSlot))
}

func _fts5HashKey2(tls *libc.TLS, nSlot int32, b Tu8, p uintptr, n int32) (r uint32) {
	var h uint32
	var i int32
	_, _ = h, i
	h = uint32(13)
	i = n - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		h = h<<int32(3) ^ h ^ uint32(*(*Tu8)(unsafe.Pointer(p + uintptr(i))))
		goto _1
	_1:
		;
		i--
	}
	h = h<<int32(3) ^ h ^ uint32(uint32(b))
	return h % uint32(uint32(nSlot))
}

// C documentation
//
//	/*
//	** Resize the hash table by doubling the number of slots.
//	*/
func _fts5HashResize(tls *libc.TLS, pHash uintptr) (r int32) {
	var apNew, apOld, p uintptr
	var i, nNew int32
	var iHash uint32
	_, _, _, _, _, _ = apNew, apOld, i, iHash, nNew, p
	nNew = (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot * int32(2)
	apOld = (*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot
	apNew = Xsqlite3_malloc64(tls, uint64(uint32(uint32(nNew))*uint32(4)))
	if !(apNew != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, apNew, 0, uint32(uint32(nNew))*uint32(4))
	i = 0
	for {
		if !(i < (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot) {
			break
		}
		for *(*uintptr)(unsafe.Pointer(apOld + uintptr(i)*4)) != 0 {
			p = *(*uintptr)(unsafe.Pointer(apOld + uintptr(i)*4))
			*(*uintptr)(unsafe.Pointer(apOld + uintptr(i)*4)) = (*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext
			iHash = _fts5HashKey(tls, nNew, p+1*40, (*TFts5HashEntry)(unsafe.Pointer(p)).FnKey)
			(*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext = *(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*4))
			*(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*4)) = p
		}
		goto _1
	_1:
		;
		i++
	}
	Xsqlite3_free(tls, apOld)
	(*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot = nNew
	(*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot = apNew
	return SQLITE_OK
}

func _fts5HashAddPoslistSize(tls *libc.TLS, pHash uintptr, p uintptr, p2 uintptr) (r int32) {
	var nByte, nData, nPos, nRet, nSz, v2, v3 int32
	var pPtr, v1 uintptr
	_, _, _, _, _, _, _, _, _ = nByte, nData, nPos, nRet, nSz, pPtr, v1, v2, v3
	nRet = 0
	if (*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist != 0 {
		if p2 != 0 {
			v1 = p2
		} else {
			v1 = p
		}
		pPtr = v1
		nData = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
		if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == int32(FTS5_DETAIL_NONE) {
			if (*TFts5HashEntry)(unsafe.Pointer(p)).FbDel != 0 {
				v2 = nData
				nData++
				*(*Tu8)(unsafe.Pointer(pPtr + uintptr(v2))) = uint8(0x00)
				if (*TFts5HashEntry)(unsafe.Pointer(p)).FbContent != 0 {
					v3 = nData
					nData++
					*(*Tu8)(unsafe.Pointer(pPtr + uintptr(v3))) = uint8(0x00)
				}
			}
		} else {
			nSz = nData - (*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist - int32(1) /* Size in bytes */
			nPos = nSz*int32(2) + int32((*TFts5HashEntry)(unsafe.Pointer(p)).FbDel)   /* Value of nPos field */
			if nPos <= int32(127) {
				*(*Tu8)(unsafe.Pointer(pPtr + uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist))) = uint8(uint8(nPos))
			} else {
				nByte = _sqlite3Fts5GetVarintLen(tls, uint32(uint32(nPos)))
				libc.Xmemmove(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist+nByte), pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist+int32(1)), uint32(uint32(nSz)))
				_sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist), uint64(uint64(nPos)))
				nData += nByte - int32(1)
			}
		}
		nRet = nData - (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
		if p2 == uintptr(0) {
			(*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = 0
			(*TFts5HashEntry)(unsafe.Pointer(p)).FbDel = uint8(0)
			(*TFts5HashEntry)(unsafe.Pointer(p)).FbContent = uint8(0)
			(*TFts5HashEntry)(unsafe.Pointer(p)).FnData = nData
		}
	}
	return nRet
}

// C documentation
//
//	/*
//	** Add an entry to the in-memory hash table. The key is the concatenation
//	** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
//	**
//	**     (bByte || pToken) -> (iRowid,iCol,iPos)
//	**
//	** Or, if iCol is negative, then the value is a delete marker.
//	*/
func _sqlite3Fts5HashWrite(tls *libc.TLS, pHash uintptr, iRowid Ti64, iCol int32, iPos int32, bByte int8, pToken uintptr, nToken int32) (r int32) {
	var bNew, nIncr, rc, v2, v4, v5, v7 int32
	var iDiff Tu64
	var iHash uint32
	var nByte, nNew Tsqlite3_int64
	var p, pNew, pPtr, pp, zKey, zKey1, v6 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNew, iDiff, iHash, nByte, nIncr, nNew, p, pNew, pPtr, pp, rc, zKey, zKey1, v2, v4, v5, v6, v7
	nIncr = 0 /* If non-delete entry should be written */
	bNew = libc.BoolInt32((*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL)
	/* Attempt to locate an existing hash entry */
	iHash = _fts5HashKey2(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot, uint8(uint8(bByte)), pToken, nToken)
	p = *(*uintptr)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*4))
	for {
		if !(p != 0) {
			break
		}
		zKey = p + 1*40
		if int32(*(*int8)(unsafe.Pointer(zKey))) == int32(int32(bByte)) && (*TFts5HashEntry)(unsafe.Pointer(p)).FnKey == nToken+int32(1) && libc.Xmemcmp(tls, zKey+1, pToken, uint32(uint32(nToken))) == 0 {
			break
		}
		goto _1
	_1:
		;
		p = (*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext
	}
	/* If an existing hash entry cannot be found, create a new one. */
	if p == uintptr(0) {
		nByte = int64(uint32(40) + uint32(nToken+libc.Int32FromInt32(1)) + uint32(1) + uint32(64))
		if nByte < int64(128) {
			nByte = int64(128)
		}
		/* Grow the Fts5Hash.aSlot[] array if necessary. */
		if (*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry*int32(2) >= (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot {
			rc = _fts5HashResize(tls, pHash)
			if rc != SQLITE_OK {
				return rc
			}
			iHash = _fts5HashKey2(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot, uint8(uint8(bByte)), pToken, nToken)
		}
		/* Allocate new Fts5HashEntry and add it to the hash table. */
		p = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if !(p != 0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, p, 0, uint32(40))
		(*TFts5HashEntry)(unsafe.Pointer(p)).FnAlloc = int32(int32(nByte))
		zKey1 = p + 1*40
		*(*int8)(unsafe.Pointer(zKey1)) = bByte
		libc.Xmemcpy(tls, zKey1+1, pToken, uint32(uint32(nToken)))
		(*TFts5HashEntry)(unsafe.Pointer(p)).FnKey = nToken + int32(1)
		*(*int8)(unsafe.Pointer(zKey1 + uintptr(nToken+int32(1)))) = int8('\000')
		(*TFts5HashEntry)(unsafe.Pointer(p)).FnData = int32(uint32(nToken+int32(1)) + uint32(40))
		(*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext = *(*uintptr)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*4))
		*(*uintptr)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*4)) = p
		(*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry++
		/* Add the first rowid field to the hash-entry */
		*(*int32)(unsafe.Pointer(p + 16)) += _sqlite3Fts5PutVarint(tls, p+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), uint64(uint64(iRowid)))
		(*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid = iRowid
		(*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
		if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail != int32(FTS5_DETAIL_NONE) {
			*(*int32)(unsafe.Pointer(p + 16)) += int32(1)
			if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
				v2 = 0
			} else {
				v2 = -int32(1)
			}
			(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(v2)
		}
	} else {
		/* Appending to an existing hash-entry. Check that there is enough
		 ** space to append the largest possible new entry. Worst case scenario
		 ** is:
		 **
		 **     + 9 bytes for a new rowid,
		 **     + 4 byte reserved for the "poslist size" varint.
		 **     + 1 byte for a "new column" byte,
		 **     + 3 bytes for a new column number (16-bit max) as a varint,
		 **     + 5 bytes for the new position offset (32-bit max).
		 */
		if (*TFts5HashEntry)(unsafe.Pointer(p)).FnAlloc-(*TFts5HashEntry)(unsafe.Pointer(p)).FnData < libc.Int32FromInt32(9)+libc.Int32FromInt32(4)+libc.Int32FromInt32(1)+libc.Int32FromInt32(3)+libc.Int32FromInt32(5) {
			nNew = int64((*TFts5HashEntry)(unsafe.Pointer(p)).FnAlloc * int32(2))
			pNew = Xsqlite3_realloc64(tls, p, uint64(uint64(nNew)))
			if pNew == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
			(*TFts5HashEntry)(unsafe.Pointer(pNew)).FnAlloc = int32(int32(nNew))
			pp = (*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*4
			for {
				if !(*(*uintptr)(unsafe.Pointer(pp)) != p) {
					break
				}
				goto _3
			_3:
				;
				pp = *(*uintptr)(unsafe.Pointer(pp))
			}
			*(*uintptr)(unsafe.Pointer(pp)) = pNew
			p = pNew
		}
		nIncr -= (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
	}
	pPtr = p
	/* If this is a new rowid, append the 4-byte size field for the previous
	 ** entry, and the new rowid for this entry.  */
	if iRowid != (*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid {
		iDiff = uint64(uint64(iRowid)) - uint64((*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid)
		_fts5HashAddPoslistSize(tls, pHash, p, uintptr(0))
		*(*int32)(unsafe.Pointer(p + 16)) += _sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), iDiff)
		(*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid = iRowid
		bNew = int32(1)
		(*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
		if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail != int32(FTS5_DETAIL_NONE) {
			*(*int32)(unsafe.Pointer(p + 16)) += int32(1)
			if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
				v4 = 0
			} else {
				v4 = -int32(1)
			}
			(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(v4)
			(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos = 0
		}
	}
	if iCol >= 0 {
		if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == int32(FTS5_DETAIL_NONE) {
			(*TFts5HashEntry)(unsafe.Pointer(p)).FbContent = uint8(1)
		} else {
			/* Append a new column value, if necessary */
			if iCol != int32((*TFts5HashEntry)(unsafe.Pointer(p)).FiCol) {
				if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
					v6 = p + 16
					v5 = *(*int32)(unsafe.Pointer(v6))
					*(*int32)(unsafe.Pointer(v6))++
					*(*Tu8)(unsafe.Pointer(pPtr + uintptr(v5))) = uint8(0x01)
					*(*int32)(unsafe.Pointer(p + 16)) += _sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), uint64(uint64(iCol)))
					(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(int16(iCol))
					(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos = 0
				} else {
					bNew = int32(1)
					v7 = iCol
					iPos = v7
					(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(v7)
				}
			}
			/* Append the new position offset, if necessary */
			if bNew != 0 {
				*(*int32)(unsafe.Pointer(p + 16)) += _sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), uint64(iPos-(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos+int32(2)))
				(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos = iPos
			}
		}
	} else {
		/* This is a delete. Set the delete flag. */
		(*TFts5HashEntry)(unsafe.Pointer(p)).FbDel = uint8(1)
	}
	nIncr += (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
	*(*int32)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(pHash)).FpnByte)) += nIncr
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Arguments pLeft and pRight point to linked-lists of hash-entry objects,
//	** each sorted in key order. This function merges the two lists into a
//	** single list and returns a pointer to its first element.
//	*/
func _fts5HashEntryMerge(tls *libc.TLS, pLeft uintptr, pRight uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var cmp, nMin, v1 int32
	var p1, p2, ppOut, zKey1, zKey2 uintptr
	var _ /* pRet at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = cmp, nMin, p1, p2, ppOut, zKey1, zKey2, v1
	p1 = pLeft
	p2 = pRight
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	ppOut = bp
	for p1 != 0 || p2 != 0 {
		if p1 == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(ppOut)) = p2
			p2 = uintptr(0)
		} else {
			if p2 == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(ppOut)) = p1
				p1 = uintptr(0)
			} else {
				zKey1 = p1 + 1*40
				zKey2 = p2 + 1*40
				if (*TFts5HashEntry)(unsafe.Pointer(p1)).FnKey < (*TFts5HashEntry)(unsafe.Pointer(p2)).FnKey {
					v1 = (*TFts5HashEntry)(unsafe.Pointer(p1)).FnKey
				} else {
					v1 = (*TFts5HashEntry)(unsafe.Pointer(p2)).FnKey
				}
				nMin = v1
				cmp = libc.Xmemcmp(tls, zKey1, zKey2, uint32(uint32(nMin)))
				if cmp == 0 {
					cmp = (*TFts5HashEntry)(unsafe.Pointer(p1)).FnKey - (*TFts5HashEntry)(unsafe.Pointer(p2)).FnKey
				}
				if cmp > 0 {
					/* p2 is smaller */
					*(*uintptr)(unsafe.Pointer(ppOut)) = p2
					ppOut = p2 + 4
					p2 = (*TFts5HashEntry)(unsafe.Pointer(p2)).FpScanNext
				} else {
					/* p1 is smaller */
					*(*uintptr)(unsafe.Pointer(ppOut)) = p1
					ppOut = p1 + 4
					p1 = (*TFts5HashEntry)(unsafe.Pointer(p1)).FpScanNext
				}
				*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
			}
		}
	}
	return *(*uintptr)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Link all tokens from hash table iHash into a list in sorted order. The
//	** tokens are not removed from the hash table.
//	*/
func _fts5HashEntrySort(tls *libc.TLS, pHash uintptr, pTerm uintptr, nTerm int32, ppSorted uintptr) (r int32) {
	var ap, pEntry, pIter, pList uintptr
	var i, iSlot, nMergeSlot int32
	_, _, _, _, _, _, _ = ap, i, iSlot, nMergeSlot, pEntry, pIter, pList
	nMergeSlot = int32(32)
	*(*uintptr)(unsafe.Pointer(ppSorted)) = uintptr(0)
	ap = Xsqlite3_malloc64(tls, uint64(uint32(4)*uint32(uint32(nMergeSlot))))
	if !(ap != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, ap, 0, uint32(4)*uint32(uint32(nMergeSlot)))
	iSlot = 0
	for {
		if !(iSlot < (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot) {
			break
		}
		pIter = *(*uintptr)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iSlot)*4))
		for {
			if !(pIter != 0) {
				break
			}
			if pTerm == uintptr(0) || (*TFts5HashEntry)(unsafe.Pointer(pIter)).FnKey >= nTerm && 0 == libc.Xmemcmp(tls, pIter+1*40, pTerm, uint32(uint32(nTerm))) {
				pEntry = pIter
				(*TFts5HashEntry)(unsafe.Pointer(pEntry)).FpScanNext = uintptr(0)
				i = 0
				for {
					if !(*(*uintptr)(unsafe.Pointer(ap + uintptr(i)*4)) != 0) {
						break
					}
					pEntry = _fts5HashEntryMerge(tls, pEntry, *(*uintptr)(unsafe.Pointer(ap + uintptr(i)*4)))
					*(*uintptr)(unsafe.Pointer(ap + uintptr(i)*4)) = uintptr(0)
					goto _3
				_3:
					;
					i++
				}
				*(*uintptr)(unsafe.Pointer(ap + uintptr(i)*4)) = pEntry
			}
			goto _2
		_2:
			;
			pIter = (*TFts5HashEntry)(unsafe.Pointer(pIter)).FpHashNext
		}
		goto _1
	_1:
		;
		iSlot++
	}
	pList = uintptr(0)
	i = 0
	for {
		if !(i < nMergeSlot) {
			break
		}
		pList = _fts5HashEntryMerge(tls, pList, *(*uintptr)(unsafe.Pointer(ap + uintptr(i)*4)))
		goto _4
	_4:
		;
		i++
	}
	Xsqlite3_free(tls, ap)
	*(*uintptr)(unsafe.Pointer(ppSorted)) = pList
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Query the hash table for a doclist associated with term pTerm/nTerm.
//	*/
func _sqlite3Fts5HashQuery(tls *libc.TLS, pHash uintptr, nPre int32, pTerm uintptr, nTerm int32, ppOut uintptr, pnDoclist uintptr) (r int32) {
	var iHash uint32
	var nHashPre, nList int32
	var p, pFaux, pRet, zKey, v2 uintptr
	_, _, _, _, _, _, _, _ = iHash, nHashPre, nList, p, pFaux, pRet, zKey, v2
	iHash = _fts5HashKey(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot, pTerm, nTerm)
	zKey = uintptr(0)
	p = *(*uintptr)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*4))
	for {
		if !(p != 0) {
			break
		}
		zKey = p + 1*40
		if nTerm == (*TFts5HashEntry)(unsafe.Pointer(p)).FnKey && libc.Xmemcmp(tls, zKey, pTerm, uint32(uint32(nTerm))) == 0 {
			break
		}
		goto _1
	_1:
		;
		p = (*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext
	}
	if p != 0 {
		nHashPre = int32(uint32(40) + uint32(uint32(nTerm)))
		nList = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData - nHashPre
		v2 = Xsqlite3_malloc64(tls, uint64(nPre+nList+int32(10)))
		*(*uintptr)(unsafe.Pointer(ppOut)) = v2
		pRet = v2
		if pRet != 0 {
			pFaux = pRet + uintptr(nPre-nHashPre)
			libc.Xmemcpy(tls, pRet+uintptr(nPre), p+uintptr(nHashPre), uint32(uint32(nList)))
			nList += _fts5HashAddPoslistSize(tls, pHash, p, pFaux)
			*(*int32)(unsafe.Pointer(pnDoclist)) = nList
		} else {
			*(*int32)(unsafe.Pointer(pnDoclist)) = 0
			return int32(SQLITE_NOMEM)
		}
	} else {
		*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pnDoclist)) = 0
	}
	return SQLITE_OK
}

func _sqlite3Fts5HashScanInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32) (r int32) {
	return _fts5HashEntrySort(tls, p, pTerm, nTerm, p+16)
}

// C documentation
//
//	/*
//	** Return true if the hash table is empty, false otherwise.
//	*/
func _sqlite3Fts5HashIsEmpty(tls *libc.TLS, pHash uintptr) (r int32) {
	return libc.BoolInt32((*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry == 0)
}

func _sqlite3Fts5HashScanNext(tls *libc.TLS, p uintptr) {
	(*TFts5Hash)(unsafe.Pointer(p)).FpScan = (*TFts5HashEntry)(unsafe.Pointer((*TFts5Hash)(unsafe.Pointer(p)).FpScan)).FpScanNext
}

func _sqlite3Fts5HashScanEof(tls *libc.TLS, p uintptr) (r int32) {
	return libc.BoolInt32((*TFts5Hash)(unsafe.Pointer(p)).FpScan == uintptr(0))
}

func _sqlite3Fts5HashScanEntry(tls *libc.TLS, pHash uintptr, pzTerm uintptr, pnTerm uintptr, ppDoclist uintptr, pnDoclist uintptr) {
	var nTerm int32
	var p, zKey, v1 uintptr
	_, _, _, _ = nTerm, p, zKey, v1
	v1 = (*TFts5Hash)(unsafe.Pointer(pHash)).FpScan
	p = v1
	if v1 != 0 {
		zKey = p + 1*40
		nTerm = (*TFts5HashEntry)(unsafe.Pointer(p)).FnKey
		_fts5HashAddPoslistSize(tls, pHash, p, uintptr(0))
		*(*uintptr)(unsafe.Pointer(pzTerm)) = zKey
		*(*int32)(unsafe.Pointer(pnTerm)) = nTerm
		*(*uintptr)(unsafe.Pointer(ppDoclist)) = zKey + uintptr(nTerm)
		*(*int32)(unsafe.Pointer(pnDoclist)) = int32(uint32((*TFts5HashEntry)(unsafe.Pointer(p)).FnData) - (uint32(40) + uint32(uint32(nTerm))))
	} else {
		*(*uintptr)(unsafe.Pointer(pzTerm)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pnTerm)) = 0
		*(*uintptr)(unsafe.Pointer(ppDoclist)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pnDoclist)) = 0
	}
}

/*
** 2014 May 31
**
** 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.
**
******************************************************************************
**
** Low level access to the FTS index stored in the database file. The
** routines in this file file implement all read and write access to the
** %_data table. Other parts of the system access this functionality via
** the interface defined in fts5Int.h.
 */

/* #include "fts5Int.h" */

/*
** Overview:
**
** The %_data table contains all the FTS indexes for an FTS5 virtual table.
** As well as the main term index, there may be up to 31 prefix indexes.
** The format is similar to FTS3/4, except that:
**
**   * all segment b-tree leaf data is stored in fixed size page records
**     (e.g. 1000 bytes). A single doclist may span multiple pages. Care is
**     taken to ensure it is possible to iterate in either direction through
**     the entries in a doclist, or to seek to a specific entry within a
**     doclist, without loading it into memory.
**
**   * large doclists that span many pages have associated "doclist index"
**     records that contain a copy of the first rowid on each page spanned by
**     the doclist. This is used to speed up seek operations, and merges of
**     large doclists with very small doclists.
**
**   * extra fields in the "structure record" record the state of ongoing
**     incremental merge operations.
**
 */

/*
** There are two versions of the format used for the structure record:
**
**   1. the legacy format, that may be read by all fts5 versions, and
**
**   2. the V2 format, which is used by contentless_delete=1 databases.
**
** Both begin with a 4-byte "configuration cookie" value. Then, a legacy
** format structure record contains a varint - the number of levels in
** the structure. Whereas a V2 structure record contains the constant
** 4 bytes [0xff 0x00 0x00 0x01]. This is unambiguous as the value of a
** varint has to be at least 16256 to begin with "0xFF". And the default
** maximum number of levels is 64.
**
** See below for more on structure record formats.
 */

/*
** Details:
**
** The %_data table managed by this module,
**
**     CREATE TABLE %_data(id INTEGER PRIMARY KEY, block BLOB);
**
** , contains the following 6 types of records. See the comments surrounding
** the FTS5_*_ROWID macros below for a description of how %_data rowids are
** assigned to each fo them.
**
** 1. Structure Records:
**
**   The set of segments that make up an index - the index structure - are
**   recorded in a single record within the %_data table. The record consists
**   of a single 32-bit configuration cookie value followed by a list of
**   SQLite varints.
**
**   If the structure record is a V2 record, the configuration cookie is
**   followed by the following 4 bytes: [0xFF 0x00 0x00 0x01].
**
**   Next, the record continues with three varints:
**
**     + number of levels,
**     + total number of segments on all levels,
**     + value of write counter.
**
**   Then, for each level from 0 to nMax:
**
**     + number of input segments in ongoing merge.
**     + total number of segments in level.
**     + for each segment from oldest to newest:
**         + segment id (always > 0)
**         + first leaf page number (often 1, always greater than 0)
**         + final leaf page number
**
**      Then, for V2 structures only:
**
**         + lower origin counter value,
**         + upper origin counter value,
**         + the number of tombstone hash pages.
**
** 2. The Averages Record:
**
**   A single record within the %_data table. The data is a list of varints.
**   The first value is the number of rows in the index. Then, for each column
**   from left to right, the total number of tokens in the column for all
**   rows of the table.
**
** 3. Segment leaves:
**
**   TERM/DOCLIST FORMAT:
**
**     Most of each segment leaf is taken up by term/doclist data. The
**     general format of term/doclist, starting with the first term
**     on the leaf page, is:
**
**         varint : size of first term
**         blob:    first term data
**         doclist: first doclist
**         zero-or-more {
**           varint:  number of bytes in common with previous term
**           varint:  number of bytes of new term data (nNew)
**           blob:    nNew bytes of new term data
**           doclist: next doclist
**         }
**
**     doclist format:
**
**         varint:  first rowid
**         poslist: first poslist
**         zero-or-more {
**           varint:  rowid delta (always > 0)
**           poslist: next poslist
**         }
**
**     poslist format:
**
**         varint: size of poslist in bytes multiplied by 2, not including
**                 this field. Plus 1 if this entry carries the "delete" flag.
**         collist: collist for column 0
**         zero-or-more {
**           0x01 byte
**           varint: column number (I)
**           collist: collist for column I
**         }
**
**     collist format:
**
**         varint: first offset + 2
**         zero-or-more {
**           varint: offset delta + 2
**         }
**
**   PAGE FORMAT
**
**     Each leaf page begins with a 4-byte header containing 2 16-bit
**     unsigned integer fields in big-endian format. They are:
**
**       * The byte offset of the first rowid on the page, if it exists
**         and occurs before the first term (otherwise 0).
**
**       * The byte offset of the start of the page footer. If the page
**         footer is 0 bytes in size, then this field is the same as the
**         size of the leaf page in bytes.
**
**     The page footer consists of a single varint for each term located
**     on the page. Each varint is the byte offset of the current term
**     within the page, delta-compressed against the previous value. In
**     other words, the first varint in the footer is the byte offset of
**     the first term, the second is the byte offset of the second less that
**     of the first, and so on.
**
**     The term/doclist format described above is accurate if the entire
**     term/doclist data fits on a single leaf page. If this is not the case,
**     the format is changed in two ways:
**
**       + if the first rowid on a page occurs before the first term, it
**         is stored as a literal value:
**
**             varint:  first rowid
**
**       + the first term on each page is stored in the same way as the
**         very first term of the segment:
**
**             varint : size of first term
**             blob:    first term data
**
** 5. Segment doclist indexes:
**
**   Doclist indexes are themselves b-trees, however they usually consist of
**   a single leaf record only. The format of each doclist index leaf page
**   is:
**
**     * Flags byte. Bits are:
**         0x01: Clear if leaf is also the root page, otherwise set.
**
**     * Page number of fts index leaf page. As a varint.
**
**     * First rowid on page indicated by previous field. As a varint.
**
**     * A list of varints, one for each subsequent termless page. A
**       positive delta if the termless page contains at least one rowid,
**       or an 0x00 byte otherwise.
**
**   Internal doclist index nodes are:
**
**     * Flags byte. Bits are:
**         0x01: Clear for root page, otherwise set.
**
**     * Page number of first child page. As a varint.
**
**     * Copy of first rowid on page indicated by previous field. As a varint.
**
**     * A list of delta-encoded varints - the first rowid on each subsequent
**       child page.
**
** 6. Tombstone Hash Page
**
**   These records are only ever present in contentless_delete=1 tables.
**   There are zero or more of these associated with each segment. They
**   are used to store the tombstone rowids for rows contained in the
**   associated segments.
**
**   The set of nHashPg tombstone hash pages associated with a single
**   segment together form a single hash table containing tombstone rowids.
**   To find the page of the hash on which a key might be stored:
**
**       iPg = (rowid % nHashPg)
**
**   Then, within page iPg, which has nSlot slots:
**
**       iSlot = (rowid / nHashPg) % nSlot
**
**   Each tombstone hash page begins with an 8 byte header:
**
**     1-byte:  Key-size (the size in bytes of each slot). Either 4 or 8.
**     1-byte:  rowid-0-tombstone flag. This flag is only valid on the
**              first tombstone hash page for each segment (iPg=0). If set,
**              the hash table contains rowid 0. If clear, it does not.
**              Rowid 0 is handled specially.
**     2-bytes: unused.
**     4-bytes: Big-endian integer containing number of entries on page.
**
**   Following this are nSlot 4 or 8 byte slots (depending on the key-size
**   in the first byte of the page header). The number of slots may be
**   determined based on the size of the page record and the key-size:
**
**     nSlot = (nByte - 8) / key-size
 */

/*
** Rowids for the averages and structure records in the %_data table.
 */

/*
** Macros determining the rowids used by segment leaves and dlidx leaves
** and nodes. All nodes and leaves are stored in the %_data table with large
** positive rowids.
**
** Each segment has a unique non-zero 16-bit id.
**
** The rowid for each segment leaf is found by passing the segment id and
** the leaf page number to the FTS5_SEGMENT_ROWID macro. Leaves are numbered
** sequentially starting from 1.
 */

/*
** Each time a blob is read from the %_data table, it is padded with this
** many zero bytes. This makes it easier to decode the various record formats
** without overreading if the records are corrupt.
 */

type TFts5Data = struct {
	Fp      uintptr
	Fnn     int32
	FszLeaf int32
}

type Fts5Data = TFts5Data

type TFts5DlidxIter = struct {
	F__ccgo_align [0]uint32
	FnLvl         int32
	FiSegid       int32
	FaLvl         [1]TFts5DlidxLvl
}

type Fts5DlidxIter = TFts5DlidxIter

type TFts5DlidxLvl = struct {
	F__ccgo_align  [0]uint32
	FpData         uintptr
	FiOff          int32
	FbEof          int32
	FiFirstOff     int32
	FiLeafPgno     int32
	F__ccgo_align5 [4]byte
	FiRowid        Ti64
}

type Fts5DlidxLvl = TFts5DlidxLvl

type TFts5DlidxWriter = struct {
	F__ccgo_align [0]uint32
	Fpgno         int32
	FbPrevValid   int32
	FiPrev        Ti64
	Fbuf          TFts5Buffer
	F__ccgo_pad4  [4]byte
}

type Fts5DlidxWriter = TFts5DlidxWriter

type TFts5Iter = struct {
	F__ccgo_align   [0]uint32
	Fbase           TFts5IndexIter
	FpTokenDataIter uintptr
	FpIndex         uintptr
	Fposlist        TFts5Buffer
	FpColset        uintptr
	FxSetOutputs    uintptr
	FnSeg           int32
	FbRev           int32
	FbSkipEmpty     Tu8
	F__ccgo_align9  [3]byte
	FiSwitchRowid   Ti64
	FaFirst         uintptr
	F__ccgo_align11 [4]byte
	FaSeg           [1]TFts5SegIter
}

type Fts5Iter = TFts5Iter

type TFts5PageWriter = struct {
	Fpgno       int32
	FiPrevPgidx int32
	Fbuf        TFts5Buffer
	Fpgidx      TFts5Buffer
	Fterm       TFts5Buffer
}

type Fts5PageWriter = TFts5PageWriter

type TFts5SegIter = struct {
	F__ccgo_align    [0]uint32
	FpSeg            uintptr
	Fflags           int32
	FiLeafPgno       int32
	FpLeaf           uintptr
	FpNextLeaf       uintptr
	F__ccgo_align5   [4]byte
	FiLeafOffset     Ti64
	FpTombArray      uintptr
	FxNext           uintptr
	FiTermLeafPgno   int32
	FiTermLeafOffset int32
	FiPgidxOff       int32
	FiEndofDoclist   int32
	FiRowidOffset    int32
	FnRowidOffset    int32
	FaRowidOffset    uintptr
	FpDlidx          uintptr
	Fterm            TFts5Buffer
	F__ccgo_align17  [4]byte
	FiRowid          Ti64
	FnPos            int32
	FbDel            Tu8
	F__ccgo_pad20    [3]byte
}

type Fts5SegIter = TFts5SegIter

type TFts5DoclistIter = struct {
	F__ccgo_align  [0]uint32
	FaEof          uintptr
	F__ccgo_align1 [4]byte
	FiRowid        Ti64
	FaPoslist      uintptr
	FnPoslist      int32
	FnSize         int32
	F__ccgo_pad5   [4]byte
}

type Fts5DoclistIter = TFts5DoclistIter

type TFts5SegWriter = struct {
	F__ccgo_align         [0]uint32
	FiSegid               int32
	Fwriter               TFts5PageWriter
	FiPrevRowid           Ti64
	FbFirstRowidInDoclist Tu8
	FbFirstRowidInPage    Tu8
	FbFirstTermInPage     Tu8
	FnLeafWritten         int32
	FnEmpty               int32
	FnDlidx               int32
	FaDlidx               uintptr
	Fbtterm               TFts5Buffer
	FiBtPage              int32
	F__ccgo_pad12         [4]byte
}

type Fts5SegWriter = TFts5SegWriter

type TFts5Structure = struct {
	F__ccgo_align  [0]uint32
	FnRef          int32
	F__ccgo_align1 [4]byte
	FnWriteCounter Tu64
	FnOriginCntr   Tu64
	FnSegment      int32
	FnLevel        int32
	FaLevel        [1]TFts5StructureLevel
	F__ccgo_pad6   [4]byte
}

type Fts5Structure = TFts5Structure

type TFts5StructureLevel = struct {
	FnMerge int32
	FnSeg   int32
	FaSeg   uintptr
}

type Fts5StructureLevel = TFts5StructureLevel

type TFts5StructureSegment = struct {
	F__ccgo_align    [0]uint32
	FiSegid          int32
	FpgnoFirst       int32
	FpgnoLast        int32
	F__ccgo_align3   [4]byte
	FiOrigin1        Tu64
	FiOrigin2        Tu64
	FnPgTombstone    int32
	F__ccgo_align6   [4]byte
	FnEntryTombstone Tu64
	FnEntry          Tu64
}

type Fts5StructureSegment = TFts5StructureSegment

type TFts5TokenDataIter = struct {
	FnIter          int32
	FnIterAlloc     int32
	FnMap           int32
	FnMapAlloc      int32
	FaMap           uintptr
	FaPoslistReader uintptr
	FaPoslistToIter uintptr
	FapIter         [1]uintptr
}

type Fts5TokenDataIter = TFts5TokenDataIter

type TFts5TokenDataMap = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FiPos         Ti64
	FiIter        int32
	F__ccgo_pad3  [4]byte
}

type Fts5TokenDataMap = TFts5TokenDataMap

type TFts5TombstoneArray = struct {
	FnRef        int32
	FnTombstone  int32
	FapTombstone [1]uintptr
}

type Fts5TombstoneArray = TFts5TombstoneArray

type TFts5Data1 = struct {
	Fp      uintptr
	Fnn     int32
	FszLeaf int32
}

type Fts5Data1 = TFts5Data1

/*
** One object per %_data table.
**
** nContentlessDelete:
**   The number of contentless delete operations since the most recent
**   call to fts5IndexFlush() or fts5IndexDiscardData(). This is tracked
**   so that extra auto-merge work can be done by fts5IndexFlush() to
**   account for the delete operations.
 */
type TFts5Index1 = struct {
	F__ccgo_align       [0]uint32
	FpConfig            uintptr
	FzDataTbl           uintptr
	FnWorkUnit          int32
	FpHash              uintptr
	FnPendingData       int32
	F__ccgo_align5      [4]byte
	FiWriteRowid        Ti64
	FbDelete            int32
	FnContentlessDelete int32
	FnPendingRow        int32
	Frc                 int32
	FflushRc            int32
	FpReader            uintptr
	FpWriter            uintptr
	FpDeleter           uintptr
	FpIdxWriter         uintptr
	FpIdxDeleter        uintptr
	FpIdxSelect         uintptr
	FpIdxNextSelect     uintptr
	FnRead              int32
	FpDeleteFromIdx     uintptr
	FpDataVersion       uintptr
	F__ccgo_align21     [4]byte
	FiStructVersion     Ti64
	FpStruct            uintptr
	F__ccgo_pad23       [4]byte
}

type Fts5Index1 = TFts5Index1

type TFts5DoclistIter1 = struct {
	F__ccgo_align  [0]uint32
	FaEof          uintptr
	F__ccgo_align1 [4]byte
	FiRowid        Ti64
	FaPoslist      uintptr
	FnPoslist      int32
	FnSize         int32
	F__ccgo_pad5   [4]byte
}

type Fts5DoclistIter1 = TFts5DoclistIter1

/*
** The contents of the "structure" record for each index are represented
** using an Fts5Structure record in memory. Which uses instances of the
** other Fts5StructureXXX types as components.
**
** nOriginCntr:
**   This value is set to non-zero for structure records created for
**   contentlessdelete=1 tables only. In that case it represents the
**   origin value to apply to the next top-level segment created.
 */
type TFts5StructureSegment1 = struct {
	F__ccgo_align    [0]uint32
	FiSegid          int32
	FpgnoFirst       int32
	FpgnoLast        int32
	F__ccgo_align3   [4]byte
	FiOrigin1        Tu64
	FiOrigin2        Tu64
	FnPgTombstone    int32
	F__ccgo_align6   [4]byte
	FnEntryTombstone Tu64
	FnEntry          Tu64
}

type Fts5StructureSegment1 = TFts5StructureSegment1

type TFts5StructureLevel1 = struct {
	FnMerge int32
	FnSeg   int32
	FaSeg   uintptr
}

type Fts5StructureLevel1 = TFts5StructureLevel1

type TFts5Structure1 = struct {
	F__ccgo_align  [0]uint32
	FnRef          int32
	F__ccgo_align1 [4]byte
	FnWriteCounter Tu64
	FnOriginCntr   Tu64
	FnSegment      int32
	FnLevel        int32
	FaLevel        [1]TFts5StructureLevel
	F__ccgo_pad6   [4]byte
}

type Fts5Structure1 = TFts5Structure1

/*
** An object of type Fts5SegWriter is used to write to segments.
 */
type TFts5PageWriter1 = struct {
	Fpgno       int32
	FiPrevPgidx int32
	Fbuf        TFts5Buffer
	Fpgidx      TFts5Buffer
	Fterm       TFts5Buffer
}

type Fts5PageWriter1 = TFts5PageWriter1

type TFts5DlidxWriter1 = struct {
	F__ccgo_align [0]uint32
	Fpgno         int32
	FbPrevValid   int32
	FiPrev        Ti64
	Fbuf          TFts5Buffer
	F__ccgo_pad4  [4]byte
}

type Fts5DlidxWriter1 = TFts5DlidxWriter1

type TFts5SegWriter1 = struct {
	F__ccgo_align         [0]uint32
	FiSegid               int32
	Fwriter               TFts5PageWriter
	FiPrevRowid           Ti64
	FbFirstRowidInDoclist Tu8
	FbFirstRowidInPage    Tu8
	FbFirstTermInPage     Tu8
	FnLeafWritten         int32
	FnEmpty               int32
	FnDlidx               int32
	FaDlidx               uintptr
	Fbtterm               TFts5Buffer
	FiBtPage              int32
	F__ccgo_pad12         [4]byte
}

type Fts5SegWriter1 = TFts5SegWriter1

type TFts5CResult = struct {
	FiFirst  Tu16
	FbTermEq Tu8
}

type Fts5CResult = TFts5CResult

type TFts5CResult1 = struct {
	FiFirst  Tu16
	FbTermEq Tu8
}

type Fts5CResult1 = TFts5CResult1

/*
** Object for iterating through a single segment, visiting each term/rowid
** pair in the segment.
**
** pSeg:
**   The segment to iterate through.
**
** iLeafPgno:
**   Current leaf page number within segment.
**
** iLeafOffset:
**   Byte offset within the current leaf that is the first byte of the
**   position list data (one byte passed the position-list size field).
**
** pLeaf:
**   Buffer containing current leaf page data. Set to NULL at EOF.
**
** iTermLeafPgno, iTermLeafOffset:
**   Leaf page number containing the last term read from the segment. And
**   the offset immediately following the term data.
**
** flags:
**   Mask of FTS5_SEGITER_XXX values. Interpreted as follows:
**
**   FTS5_SEGITER_ONETERM:
**     If set, set the iterator to point to EOF after the current doclist
**     has been exhausted. Do not proceed to the next term in the segment.
**
**   FTS5_SEGITER_REVERSE:
**     This flag is only ever set if FTS5_SEGITER_ONETERM is also set. If
**     it is set, iterate through rowid in descending order instead of the
**     default ascending order.
**
** iRowidOffset/nRowidOffset/aRowidOffset:
**     These are used if the FTS5_SEGITER_REVERSE flag is set.
**
**     For each rowid on the page corresponding to the current term, the
**     corresponding aRowidOffset[] entry is set to the byte offset of the
**     start of the "position-list-size" field within the page.
**
** iTermIdx:
**     Index of current term on iTermLeafPgno.
**
** apTombstone/nTombstone:
**     These are used for contentless_delete=1 tables only. When the cursor
**     is first allocated, the apTombstone[] array is allocated so that it
**     is large enough for all tombstones hash pages associated with the
**     segment. The pages themselves are loaded lazily from the database as
**     they are required.
 */
type TFts5SegIter1 = struct {
	F__ccgo_align    [0]uint32
	FpSeg            uintptr
	Fflags           int32
	FiLeafPgno       int32
	FpLeaf           uintptr
	FpNextLeaf       uintptr
	F__ccgo_align5   [4]byte
	FiLeafOffset     Ti64
	FpTombArray      uintptr
	FxNext           uintptr
	FiTermLeafPgno   int32
	FiTermLeafOffset int32
	FiPgidxOff       int32
	FiEndofDoclist   int32
	FiRowidOffset    int32
	FnRowidOffset    int32
	FaRowidOffset    uintptr
	FpDlidx          uintptr
	Fterm            TFts5Buffer
	F__ccgo_align17  [4]byte
	FiRowid          Ti64
	FnPos            int32
	FbDel            Tu8
	F__ccgo_pad20    [3]byte
}

type Fts5SegIter1 = TFts5SegIter1

/*
** Array of tombstone pages. Reference counted.
 */
type TFts5TombstoneArray1 = struct {
	FnRef        int32
	FnTombstone  int32
	FapTombstone [1]uintptr
}

type Fts5TombstoneArray1 = TFts5TombstoneArray1

/*
** Argument is a pointer to an Fts5Data structure that contains a
** leaf page.
 */

/*
** Argument is a pointer to an Fts5Data structure that contains a leaf
** page. This macro evaluates to true if the leaf contains no terms, or
** false if it contains at least one term.
 */

/*
** Object for iterating through the merged results of one or more segments,
** visiting each term/rowid pair in the merged data.
**
** nSeg is always a power of two greater than or equal to the number of
** segments that this object is merging data from. Both the aSeg[] and
** aFirst[] arrays are sized at nSeg entries. The aSeg[] array is padded
** with zeroed objects - these are handled as if they were iterators opened
** on empty segments.
**
** The results of comparing segments aSeg[N] and aSeg[N+1], where N is an
** even number, is stored in aFirst[(nSeg+N)/2]. The "result" of the
** comparison in this context is the index of the iterator that currently
** points to the smaller term/rowid combination. Iterators at EOF are
** considered to be greater than all other iterators.
**
** aFirst[1] contains the index in aSeg[] of the iterator that points to
** the smallest key overall. aFirst[0] is unused.
**
** poslist:
**   Used by sqlite3Fts5IterPoslist() when the poslist needs to be buffered.
**   There is no way to tell if this is populated or not.
**
** pColset:
**   If not NULL, points to an object containing a set of column indices.
**   Only matches that occur in one of these columns will be returned.
**   The Fts5Iter does not own the Fts5Colset object, and so it is not
**   freed when the iterator is closed - it is owned by the upper layer.
 */
type TFts5Iter1 = struct {
	F__ccgo_align   [0]uint32
	Fbase           TFts5IndexIter
	FpTokenDataIter uintptr
	FpIndex         uintptr
	Fposlist        TFts5Buffer
	FpColset        uintptr
	FxSetOutputs    uintptr
	FnSeg           int32
	FbRev           int32
	FbSkipEmpty     Tu8
	F__ccgo_align9  [3]byte
	FiSwitchRowid   Ti64
	FaFirst         uintptr
	F__ccgo_align11 [4]byte
	FaSeg           [1]TFts5SegIter
}

type Fts5Iter1 = TFts5Iter1

/*
** An instance of the following type is used to iterate through the contents
** of a doclist-index record.
**
** pData:
**   Record containing the doclist-index data.
**
** bEof:
**   Set to true once iterator has reached EOF.
**
** iOff:
**   Set to the current offset within record pData.
 */
type TFts5DlidxLvl1 = struct {
	F__ccgo_align  [0]uint32
	FpData         uintptr
	FiOff          int32
	FbEof          int32
	FiFirstOff     int32
	FiLeafPgno     int32
	F__ccgo_align5 [4]byte
	FiRowid        Ti64
}

type Fts5DlidxLvl1 = TFts5DlidxLvl1

type TFts5DlidxIter1 = struct {
	F__ccgo_align [0]uint32
	FnLvl         int32
	FiSegid       int32
	FaLvl         [1]TFts5DlidxLvl
}

type Fts5DlidxIter1 = TFts5DlidxIter1

func _fts5PutU16(tls *libc.TLS, aOut uintptr, iVal Tu16) {
	*(*Tu8)(unsafe.Pointer(aOut)) = uint8(int32(int32(iVal)) >> libc.Int32FromInt32(8))
	*(*Tu8)(unsafe.Pointer(aOut + 1)) = uint8(int32(int32(iVal)) & libc.Int32FromInt32(0xFF))
}

func _fts5GetU16(tls *libc.TLS, aIn uintptr) (r Tu16) {
	return uint16(int32(uint16(*(*Tu8)(unsafe.Pointer(aIn))))<<int32(8) + int32(*(*Tu8)(unsafe.Pointer(aIn + 1))))
}

// C documentation
//
//	/*
//	** The only argument points to a buffer at least 8 bytes in size. This
//	** function interprets the first 8 bytes of the buffer as a 64-bit big-endian
//	** unsigned integer and returns the result.
//	*/
func _fts5GetU64(tls *libc.TLS, a uintptr) (r Tu64) {
	return uint64(*(*Tu8)(unsafe.Pointer(a)))<<libc.Int32FromInt32(56) + uint64(*(*Tu8)(unsafe.Pointer(a + 1)))<<libc.Int32FromInt32(48) + uint64(*(*Tu8)(unsafe.Pointer(a + 2)))<<libc.Int32FromInt32(40) + uint64(*(*Tu8)(unsafe.Pointer(a + 3)))<<libc.Int32FromInt32(32) + uint64(*(*Tu8)(unsafe.Pointer(a + 4)))<<libc.Int32FromInt32(24) + uint64(*(*Tu8)(unsafe.Pointer(a + 5)))<<libc.Int32FromInt32(16) + uint64(*(*Tu8)(unsafe.Pointer(a + 6)))<<libc.Int32FromInt32(8) + uint64(*(*Tu8)(unsafe.Pointer(a + 7)))<<libc.Int32FromInt32(0)
}

// C documentation
//
//	/*
//	** The only argument points to a buffer at least 4 bytes in size. This
//	** function interprets the first 4 bytes of the buffer as a 32-bit big-endian
//	** unsigned integer and returns the result.
//	*/
func _fts5GetU32(tls *libc.TLS, a uintptr) (r Tu32) {
	return uint32(*(*Tu8)(unsafe.Pointer(a)))<<libc.Int32FromInt32(24) + uint32(*(*Tu8)(unsafe.Pointer(a + 1)))<<libc.Int32FromInt32(16) + uint32(*(*Tu8)(unsafe.Pointer(a + 2)))<<libc.Int32FromInt32(8) + uint32(*(*Tu8)(unsafe.Pointer(a + 3)))<<libc.Int32FromInt32(0)
}

// C documentation
//
//	/*
//	** Write iVal, formated as a 64-bit big-endian unsigned integer, to the
//	** buffer indicated by the first argument.
//	*/
func _fts5PutU64(tls *libc.TLS, a uintptr, iVal Tu64) {
	*(*Tu8)(unsafe.Pointer(a)) = uint8(iVal >> libc.Int32FromInt32(56) & libc.Uint64FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(iVal >> libc.Int32FromInt32(48) & libc.Uint64FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 2)) = uint8(iVal >> libc.Int32FromInt32(40) & libc.Uint64FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 3)) = uint8(iVal >> libc.Int32FromInt32(32) & libc.Uint64FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 4)) = uint8(iVal >> libc.Int32FromInt32(24) & libc.Uint64FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 5)) = uint8(iVal >> libc.Int32FromInt32(16) & libc.Uint64FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 6)) = uint8(iVal >> libc.Int32FromInt32(8) & libc.Uint64FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 7)) = uint8(iVal >> libc.Int32FromInt32(0) & libc.Uint64FromInt32(0xFF))
}

// C documentation
//
//	/*
//	** Write iVal, formated as a 32-bit big-endian unsigned integer, to the
//	** buffer indicated by the first argument.
//	*/
func _fts5PutU32(tls *libc.TLS, a uintptr, iVal Tu32) {
	*(*Tu8)(unsafe.Pointer(a)) = uint8(iVal >> libc.Int32FromInt32(24) & libc.Uint32FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 1)) = uint8(iVal >> libc.Int32FromInt32(16) & libc.Uint32FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 2)) = uint8(iVal >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0xFF))
	*(*Tu8)(unsafe.Pointer(a + 3)) = uint8(iVal >> libc.Int32FromInt32(0) & libc.Uint32FromInt32(0xFF))
}

// C documentation
//
//	/*
//	** Allocate and return a buffer at least nByte bytes in size.
//	**
//	** If an OOM error is encountered, return NULL and set the error code in
//	** the Fts5Index handle passed as the first argument.
//	*/
func _fts5IdxMalloc(tls *libc.TLS, p uintptr, nByte Tsqlite3_int64) (r uintptr) {
	return _sqlite3Fts5MallocZero(tls, p+44, nByte)
}

/*
** Compare the contents of the pLeft buffer with the pRight/nRight blob.
**
** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
** +ve if pRight is smaller than pLeft. In other words:
**
**     res = *pLeft - *pRight
 */

// C documentation
//
//	/*
//	** Compare the contents of the two buffers using memcmp(). If one buffer
//	** is a prefix of the other, it is considered the lesser.
//	**
//	** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
//	** +ve if pRight is smaller than pLeft. In other words:
//	**
//	**     res = *pLeft - *pRight
//	*/
func _fts5BufferCompare(tls *libc.TLS, pLeft uintptr, pRight uintptr) (r int32) {
	var nCmp, res, v1, v2, v3 int32
	_, _, _, _, _ = nCmp, res, v1, v2, v3
	if (*TFts5Buffer)(unsafe.Pointer(pLeft)).Fn < (*TFts5Buffer)(unsafe.Pointer(pRight)).Fn {
		v1 = (*TFts5Buffer)(unsafe.Pointer(pLeft)).Fn
	} else {
		v1 = (*TFts5Buffer)(unsafe.Pointer(pRight)).Fn
	}
	nCmp = v1
	if nCmp <= 0 {
		v2 = 0
	} else {
		v2 = libc.Xmemcmp(tls, (*TFts5Buffer)(unsafe.Pointer(pLeft)).Fp, (*TFts5Buffer)(unsafe.Pointer(pRight)).Fp, uint32(nCmp))
	}
	res = v2
	if res == 0 {
		v3 = (*TFts5Buffer)(unsafe.Pointer(pLeft)).Fn - (*TFts5Buffer)(unsafe.Pointer(pRight)).Fn
	} else {
		v3 = res
	}
	return v3
}

func _fts5LeafFirstTermOff(tls *libc.TLS, pLeaf uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* ret at bp+0 */ int32
	_sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf), bp)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Close the read-only blob handle, if it is open.
//	*/
func _sqlite3Fts5IndexCloseReader(tls *libc.TLS, p uintptr) {
	var pReader uintptr
	_ = pReader
	if (*TFts5Index)(unsafe.Pointer(p)).FpReader != 0 {
		pReader = (*TFts5Index)(unsafe.Pointer(p)).FpReader
		(*TFts5Index)(unsafe.Pointer(p)).FpReader = uintptr(0)
		Xsqlite3_blob_close(tls, pReader)
	}
}

// C documentation
//
//	/*
//	** Retrieve a record from the %_data table.
//	**
//	** If an error occurs, NULL is returned and an error left in the
//	** Fts5Index object.
//	*/
func _fts5DataRead(tls *libc.TLS, p uintptr, iRowid Ti64) (r uintptr) {
	var aOut, pBlob, pConfig, pRet, v1 uintptr
	var nAlloc Tsqlite3_int64
	var nByte, rc int32
	_, _, _, _, _, _, _, _ = aOut, nAlloc, nByte, pBlob, pConfig, pRet, rc, v1
	pRet = uintptr(0)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		rc = SQLITE_OK
		if (*TFts5Index)(unsafe.Pointer(p)).FpReader != 0 {
			/* This call may return SQLITE_ABORT if there has been a savepoint
			 ** rollback since it was last used. In this case a new blob handle
			 ** is required.  */
			pBlob = (*TFts5Index)(unsafe.Pointer(p)).FpReader
			(*TFts5Index)(unsafe.Pointer(p)).FpReader = uintptr(0)
			rc = Xsqlite3_blob_reopen(tls, pBlob, iRowid)
			(*TFts5Index)(unsafe.Pointer(p)).FpReader = pBlob
			if rc != SQLITE_OK {
				_sqlite3Fts5IndexCloseReader(tls, p)
			}
			if rc == int32(SQLITE_ABORT) {
				rc = SQLITE_OK
			}
		}
		/* If the blob handle is not open at this point, open it and seek
		 ** to the requested entry.  */
		if (*TFts5Index)(unsafe.Pointer(p)).FpReader == uintptr(0) && rc == SQLITE_OK {
			pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
			rc = Xsqlite3_blob_open(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl, __ccgo_ts+37645, iRowid, 0, p+52)
		}
		/* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
		 ** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
		 ** All the reasons those functions might return SQLITE_ERROR - missing
		 ** table, missing row, non-blob/text in block column - indicate
		 ** backing store corruption.  */
		if rc == int32(SQLITE_ERROR) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		if rc == SQLITE_OK {
			aOut = uintptr(0) /* Read blob data into this buffer */
			nByte = Xsqlite3_blob_bytes(tls, (*TFts5Index)(unsafe.Pointer(p)).FpReader)
			nAlloc = int64(uint32(12) + uint32(uint32(nByte)) + uint32(FTS5_DATA_PADDING))
			pRet = Xsqlite3_malloc64(tls, uint64(uint64(nAlloc)))
			if pRet != 0 {
				(*TFts5Data)(unsafe.Pointer(pRet)).Fnn = nByte
				v1 = pRet + 1*12
				(*TFts5Data)(unsafe.Pointer(pRet)).Fp = v1
				aOut = v1
			} else {
				rc = int32(SQLITE_NOMEM)
			}
			if rc == SQLITE_OK {
				rc = Xsqlite3_blob_read(tls, (*TFts5Index)(unsafe.Pointer(p)).FpReader, aOut, nByte, 0)
			}
			if rc != SQLITE_OK {
				Xsqlite3_free(tls, pRet)
				pRet = uintptr(0)
			} else {
				/* TODO1: Fix this */
				*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte))) = uint8(0x00)
				*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte+int32(1)))) = uint8(0x00)
				(*TFts5Data)(unsafe.Pointer(pRet)).FszLeaf = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pRet)).Fp+2))
			}
		}
		(*TFts5Index)(unsafe.Pointer(p)).Frc = rc
		(*TFts5Index)(unsafe.Pointer(p)).FnRead++
	}
	return pRet
}

// C documentation
//
//	/*
//	** Release a reference to data record returned by an earlier call to
//	** fts5DataRead().
//	*/
func _fts5DataRelease(tls *libc.TLS, pData uintptr) {
	Xsqlite3_free(tls, pData)
}

func _fts5LeafRead(tls *libc.TLS, p uintptr, iRowid Ti64) (r uintptr) {
	var pRet uintptr
	_ = pRet
	pRet = _fts5DataRead(tls, p, iRowid)
	if pRet != 0 {
		if (*TFts5Data)(unsafe.Pointer(pRet)).Fnn < int32(4) || (*TFts5Data)(unsafe.Pointer(pRet)).FszLeaf > (*TFts5Data)(unsafe.Pointer(pRet)).Fnn {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			_fts5DataRelease(tls, pRet)
			pRet = uintptr(0)
		}
	}
	return pRet
}

func _fts5IndexPrepareStmt(tls *libc.TLS, p uintptr, ppStmt uintptr, zSql uintptr) (r int32) {
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if zSql != 0 {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fdb, zSql, -int32(1), uint32(libc.Int32FromInt32(SQLITE_PREPARE_PERSISTENT)|libc.Int32FromInt32(SQLITE_PREPARE_NO_VTAB)), ppStmt, uintptr(0))
		} else {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		}
	}
	Xsqlite3_free(tls, zSql)
	return (*TFts5Index)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** INSERT OR REPLACE a record into the %_data table.
//	*/
func _fts5DataWrite(tls *libc.TLS, p uintptr, iRowid Ti64, pData uintptr, nData int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig uintptr
	_ = pConfig
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}
	if (*TFts5Index)(unsafe.Pointer(p)).FpWriter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+56, Xsqlite3_mprintf(tls, __ccgo_ts+37651, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
	}
	Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter, int32(1), iRowid)
	Xsqlite3_bind_blob(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter, int32(2), pData, nData, libc.UintptrFromInt32(0))
	Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter)
	(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter)
	Xsqlite3_bind_null(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter, int32(2))
}

// C documentation
//
//	/*
//	** Execute the following SQL:
//	**
//	**     DELETE FROM %_data WHERE id BETWEEN $iFirst AND $iLast
//	*/
func _fts5DataDelete(tls *libc.TLS, p uintptr, iFirst Ti64, iLast Ti64) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig, zSql uintptr
	_, _ = pConfig, zSql
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}
	if (*TFts5Index)(unsafe.Pointer(p)).FpDeleter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+37702, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
		if _fts5IndexPrepareStmt(tls, p, p+60, zSql) != 0 {
			return
		}
	}
	Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter, int32(1), iFirst)
	Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter, int32(2), iLast)
	Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter)
	(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter)
}

// C documentation
//
//	/*
//	** Remove all records associated with segment iSegid.
//	*/
func _fts5DataRemoveSegment(tls *libc.TLS, p uintptr, pSeg uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iFirst, iLast, iTomb1, iTomb2 Ti64
	var iSegid int32
	var pConfig uintptr
	_, _, _, _, _, _ = iFirst, iLast, iSegid, iTomb1, iTomb2, pConfig
	iSegid = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid
	iFirst = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(libc.Int32FromInt32(0))
	iLast = int64(iSegid+libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(libc.Int32FromInt32(0)) - int64(1)
	_fts5DataDelete(tls, p, iFirst, iLast)
	if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone != 0 {
		iTomb1 = int64(iSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(libc.Int32FromInt32(0))
		iTomb2 = int64(iSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone-libc.Int32FromInt32(1))
		_fts5DataDelete(tls, p, iTomb1, iTomb2)
	}
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+68, Xsqlite3_mprintf(tls, __ccgo_ts+37751, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter, int32(1), iSegid)
		Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
	}
}

// C documentation
//
//	/*
//	** Release a reference to an Fts5Structure object returned by an earlier
//	** call to fts5StructureRead() or fts5StructureDecode().
//	*/
func _fts5StructureRelease(tls *libc.TLS, pStruct uintptr) {
	var i, v1 int32
	var v2 uintptr
	var v3 bool
	_, _, _, _ = i, v1, v2, v3
	if v3 = pStruct != 0; v3 {
		v2 = pStruct
		*(*int32)(unsafe.Pointer(v2))--
		v1 = *(*int32)(unsafe.Pointer(v2))
	}
	if v3 && 0 >= v1 {
		i = 0
		for {
			if !(i < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
				break
			}
			Xsqlite3_free(tls, (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(i)*12))).FaSeg)
			goto _4
		_4:
			;
			i++
		}
		Xsqlite3_free(tls, pStruct)
	}
}

func _fts5StructureRef(tls *libc.TLS, pStruct uintptr) {
	(*TFts5Structure)(unsafe.Pointer(pStruct)).FnRef++
}

func _sqlite3Fts5StructureRef(tls *libc.TLS, p uintptr) (r uintptr) {
	_fts5StructureRef(tls, (*TFts5Index)(unsafe.Pointer(p)).FpStruct)
	return (*TFts5Index)(unsafe.Pointer(p)).FpStruct
}

func _sqlite3Fts5StructureRelease(tls *libc.TLS, p uintptr) {
	if p != 0 {
		_fts5StructureRelease(tls, p)
	}
}

func _sqlite3Fts5StructureTest(tls *libc.TLS, p uintptr, pStruct uintptr) (r int32) {
	if (*TFts5Index)(unsafe.Pointer(p)).FpStruct != pStruct {
		return int32(SQLITE_ABORT)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Ensure that structure object (*pp) is writable.
//	**
//	** This function is a no-op if (*pRc) is not SQLITE_OK when it is called. If
//	** an error occurs, (*pRc) is set to an SQLite error code before returning.
//	*/
func _fts5StructureMakeWritable(tls *libc.TLS, pRc uintptr, pp uintptr) {
	var i int32
	var nByte Ti64
	var p, pLvl, pNew uintptr
	_, _, _, _, _ = i, nByte, p, pLvl, pNew
	p = *(*uintptr)(unsafe.Pointer(pp))
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK && (*TFts5Structure)(unsafe.Pointer(p)).FnRef > int32(1) {
		nByte = int64(uint32(48) + uint32((*TFts5Structure)(unsafe.Pointer(p)).FnLevel-libc.Int32FromInt32(1))*uint32(12))
		pNew = _sqlite3Fts5MallocZero(tls, pRc, nByte)
		if pNew != 0 {
			libc.Xmemcpy(tls, pNew, p, uint32(uint32(nByte)))
			i = 0
			for {
				if !(i < (*TFts5Structure)(unsafe.Pointer(p)).FnLevel) {
					break
				}
				(*(*TFts5StructureLevel)(unsafe.Pointer(pNew + 32 + uintptr(i)*12))).FaSeg = uintptr(0)
				goto _1
			_1:
				;
				i++
			}
			i = 0
			for {
				if !(i < (*TFts5Structure)(unsafe.Pointer(p)).FnLevel) {
					break
				}
				pLvl = pNew + 32 + uintptr(i)*12
				nByte = int64(uint32(56) * uint32((*(*TFts5StructureLevel)(unsafe.Pointer(pNew + 32 + uintptr(i)*12))).FnSeg))
				(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = _sqlite3Fts5MallocZero(tls, pRc, nByte)
				if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg == uintptr(0) {
					i = 0
					for {
						if !(i < (*TFts5Structure)(unsafe.Pointer(p)).FnLevel) {
							break
						}
						Xsqlite3_free(tls, (*(*TFts5StructureLevel)(unsafe.Pointer(pNew + 32 + uintptr(i)*12))).FaSeg)
						goto _3
					_3:
						;
						i++
					}
					Xsqlite3_free(tls, pNew)
					return
				}
				libc.Xmemcpy(tls, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, (*(*TFts5StructureLevel)(unsafe.Pointer(p + 32 + uintptr(i)*12))).FaSeg, uint32(uint32(nByte)))
				goto _2
			_2:
				;
				i++
			}
			(*TFts5Structure)(unsafe.Pointer(p)).FnRef--
			(*TFts5Structure)(unsafe.Pointer(pNew)).FnRef = int32(1)
		}
		*(*uintptr)(unsafe.Pointer(pp)) = pNew
	}
}

// C documentation
//
//	/*
//	** Deserialize and return the structure record currently stored in serialized
//	** form within buffer pData/nData.
//	**
//	** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
//	** are over-allocated by one slot. This allows the structure contents
//	** to be more easily edited.
//	**
//	** If an error occurs, *ppOut is set to NULL and an SQLite error code
//	** returned. Otherwise, *ppOut is set to point to the new object and
//	** SQLITE_OK returned.
//	*/
func _fts5StructureDecode(tls *libc.TLS, pData uintptr, nData int32, piCookie uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bStructureV2, i, iLvl, iSeg int32
	var nByte Tsqlite3_int64
	var nOriginCntr Tu64
	var pLvl, pRet, pSeg uintptr
	var v3 uint64
	var _ /* nLevel at bp+4 */ int32
	var _ /* nSegment at bp+8 */ int32
	var _ /* nTotal at bp+12 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = bStructureV2, i, iLvl, iSeg, nByte, nOriginCntr, pLvl, pRet, pSeg, v3
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	i = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	*(*int32)(unsafe.Pointer(bp + 8)) = 0 /* Bytes of space to allocate at pRet */
	pRet = uintptr(0)                     /* Structure object to return */
	bStructureV2 = 0                      /* True for FTS5_STRUCTURE_V2 */
	nOriginCntr = uint64(0)               /* Largest origin value seen so far */
	/* Grab the cookie value */
	if piCookie != 0 {
		*(*int32)(unsafe.Pointer(piCookie)) = _sqlite3Fts5Get32(tls, pData)
	}
	i = int32(4)
	/* Check if this is a V2 structure record. Set bStructureV2 if it is. */
	if 0 == libc.Xmemcmp(tls, pData+uintptr(i), __ccgo_ts+37791, uint32(4)) {
		i += int32(4)
		bStructureV2 = int32(1)
	}
	/* Read the total number of levels and segments from the start of the
	 ** structure record.  */
	i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+4)
	i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+8)
	if *(*int32)(unsafe.Pointer(bp + 4)) > int32(FTS5_MAX_SEGMENT) || *(*int32)(unsafe.Pointer(bp + 4)) < 0 || *(*int32)(unsafe.Pointer(bp + 8)) > int32(FTS5_MAX_SEGMENT) || *(*int32)(unsafe.Pointer(bp + 8)) < 0 {
		return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	}
	nByte = int64(libc.Uint32FromInt64(48) + libc.Uint32FromInt64(12)*uint32(*(*int32)(unsafe.Pointer(bp + 4))-libc.Int32FromInt32(1)))
	pRet = _sqlite3Fts5MallocZero(tls, bp, nByte)
	if pRet != 0 {
		(*TFts5Structure)(unsafe.Pointer(pRet)).FnRef = int32(1)
		(*TFts5Structure)(unsafe.Pointer(pRet)).FnLevel = *(*int32)(unsafe.Pointer(bp + 4))
		(*TFts5Structure)(unsafe.Pointer(pRet)).FnSegment = *(*int32)(unsafe.Pointer(bp + 8))
		i += int32(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pRet+8))
		iLvl = 0
		for {
			if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && iLvl < *(*int32)(unsafe.Pointer(bp + 4))) {
				break
			}
			pLvl = pRet + 32 + uintptr(iLvl)*12
			*(*int32)(unsafe.Pointer(bp + 12)) = 0
			if i >= nData {
				*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			} else {
				i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pLvl)
				i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+12)
				if *(*int32)(unsafe.Pointer(bp + 12)) < (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge {
					*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = _sqlite3Fts5MallocZero(tls, bp, int64(uint32(*(*int32)(unsafe.Pointer(bp + 12)))*uint32(56)))
				*(*int32)(unsafe.Pointer(bp + 8)) -= *(*int32)(unsafe.Pointer(bp + 12))
			}
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg = *(*int32)(unsafe.Pointer(bp + 12))
				iSeg = 0
				for {
					if !(iSeg < *(*int32)(unsafe.Pointer(bp + 12))) {
						break
					}
					pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56
					if i >= nData {
						*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						break
					}
					i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg)
					i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+4)
					i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+8)
					if bStructureV2 != 0 {
						i += int32(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+16))
						i += int32(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+24))
						i += _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+32)
						i += int32(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+40))
						i += int32(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+48))
						if nOriginCntr > (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2 {
							v3 = nOriginCntr
						} else {
							v3 = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2
						}
						nOriginCntr = v3
					}
					if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
						*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						break
					}
					goto _2
				_2:
					;
					iSeg++
				}
				if iLvl > 0 && (*(*TFts5StructureLevel)(unsafe.Pointer(pLvl + uintptr(-libc.Int32FromInt32(1))*12))).FnMerge != 0 && *(*int32)(unsafe.Pointer(bp + 12)) == 0 {
					*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				if iLvl == *(*int32)(unsafe.Pointer(bp + 4))-int32(1) && (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
					*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
			}
			goto _1
		_1:
			;
			iLvl++
		}
		if *(*int32)(unsafe.Pointer(bp + 8)) != 0 && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		if bStructureV2 != 0 {
			(*TFts5Structure)(unsafe.Pointer(pRet)).FnOriginCntr = nOriginCntr + uint64(1)
		}
		if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
			_fts5StructureRelease(tls, pRet)
			pRet = uintptr(0)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = pRet
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Add a level to the Fts5Structure.aLevel[] array of structure object
//	** (*ppStruct).
//	*/
func _fts5StructureAddLevel(tls *libc.TLS, pRc uintptr, ppStruct uintptr) {
	var nByte Tsqlite3_int64
	var nLevel int32
	var pStruct uintptr
	_, _, _ = nByte, nLevel, pStruct
	_fts5StructureMakeWritable(tls, pRc, ppStruct)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		pStruct = *(*uintptr)(unsafe.Pointer(ppStruct))
		nLevel = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel
		nByte = int64(libc.Uint32FromInt64(48) + libc.Uint32FromInt64(12)*uint32(nLevel+libc.Int32FromInt32(1)))
		pStruct = Xsqlite3_realloc64(tls, pStruct, uint64(uint64(nByte)))
		if pStruct != 0 {
			libc.Xmemset(tls, pStruct+32+uintptr(nLevel)*12, 0, uint32(12))
			(*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel++
			*(*uintptr)(unsafe.Pointer(ppStruct)) = pStruct
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		}
	}
}

// C documentation
//
//	/*
//	** Extend level iLvl so that there is room for at least nExtra more
//	** segments.
//	*/
func _fts5StructureExtendLevel(tls *libc.TLS, pRc uintptr, pStruct uintptr, iLvl int32, nExtra int32, bInsert int32) {
	var aNew, pLvl uintptr
	var nByte Tsqlite3_int64
	var nMove int32
	_, _, _, _ = aNew, nByte, nMove, pLvl
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		pLvl = pStruct + 32 + uintptr(iLvl)*12
		nByte = int64(uint32((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg+nExtra) * uint32(56))
		aNew = Xsqlite3_realloc64(tls, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, uint64(uint64(nByte)))
		if aNew != 0 {
			if bInsert == 0 {
				libc.Xmemset(tls, aNew+uintptr((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg)*56, 0, uint32(56)*uint32(uint32(nExtra)))
			} else {
				nMove = int32(uint32((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg) * uint32(56))
				libc.Xmemmove(tls, aNew+uintptr(nExtra)*56, aNew, uint32(uint32(nMove)))
				libc.Xmemset(tls, aNew, 0, uint32(56)*uint32(uint32(nExtra)))
			}
			(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = aNew
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = int32(SQLITE_NOMEM)
		}
	}
}

func _fts5StructureReadUncached(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig, pData uintptr
	var _ /* iCookie at bp+4 */ int32
	var _ /* pRet at bp+0 */ uintptr
	_, _ = pConfig, pData
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
	pData = _fts5DataRead(tls, p, int64(FTS5_STRUCTURE_ROWID))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		/* TODO: Do we need this if the leaf-index is appended? Probably... */
		libc.Xmemset(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pData)).Fnn), 0, uint32(FTS5_DATA_PADDING))
		(*TFts5Index)(unsafe.Pointer(p)).Frc = _fts5StructureDecode(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp, (*TFts5Data)(unsafe.Pointer(pData)).Fnn, bp+4, bp)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && ((*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz == 0 || (*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie != *(*int32)(unsafe.Pointer(bp + 4))) {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5ConfigLoad(tls, pConfig, *(*int32)(unsafe.Pointer(bp + 4)))
		}
		_fts5DataRelease(tls, pData)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
			_fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		}
	}
	return *(*uintptr)(unsafe.Pointer(bp))
}

func _fts5IndexDataVersion(tls *libc.TLS, p uintptr) (r Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iVersion Ti64
	_ = iVersion
	iVersion = 0
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion == uintptr(0) {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = _fts5IndexPrepareStmt(tls, p, p+88, Xsqlite3_mprintf(tls, __ccgo_ts+37796, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzDb)))
			if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
				return 0
			}
		}
		if int32(SQLITE_ROW) == Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion) {
			iVersion = Xsqlite3_column_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion, 0)
		}
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion)
	}
	return iVersion
}

// C documentation
//
//	/*
//	** Read, deserialize and return the structure record.
//	**
//	** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
//	** are over-allocated as described for function fts5StructureDecode()
//	** above.
//	**
//	** If an error occurs, NULL is returned and an error code left in the
//	** Fts5Index handle. If an error has already occurred when this function
//	** is called, it is a no-op.
//	*/
func _fts5StructureRead(tls *libc.TLS, p uintptr) (r uintptr) {
	if (*TFts5Index)(unsafe.Pointer(p)).FpStruct == uintptr(0) {
		(*TFts5Index)(unsafe.Pointer(p)).FiStructVersion = _fts5IndexDataVersion(tls, p)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*TFts5Index)(unsafe.Pointer(p)).FpStruct = _fts5StructureReadUncached(tls, p)
		}
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return uintptr(0)
	}
	_fts5StructureRef(tls, (*TFts5Index)(unsafe.Pointer(p)).FpStruct)
	return (*TFts5Index)(unsafe.Pointer(p)).FpStruct
}

func _fts5StructureInvalidate(tls *libc.TLS, p uintptr) {
	if (*TFts5Index)(unsafe.Pointer(p)).FpStruct != 0 {
		_fts5StructureRelease(tls, (*TFts5Index)(unsafe.Pointer(p)).FpStruct)
		(*TFts5Index)(unsafe.Pointer(p)).FpStruct = uintptr(0)
	}
}

/*
** Return the total number of segments in index structure pStruct. This
** function is only ever used as part of assert() conditions.
 */

// C documentation
//
//	/*
//	** Serialize and store the "structure" record.
//	**
//	** If an error occurs, leave an error code in the Fts5Index object. If an
//	** error has already occurred, this function is a no-op.
//	*/
func _fts5StructureWrite(tls *libc.TLS, p uintptr, pStruct uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCookie, iLvl, iSeg, nHdr, v1 int32
	var pLvl, pSeg uintptr
	var _ /* buf at bp+0 */ TFts5Buffer
	_, _, _, _, _, _, _ = iCookie, iLvl, iSeg, nHdr, pLvl, pSeg, v1
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
			v1 = libc.Int32FromInt32(4) + libc.Int32FromInt32(4) + libc.Int32FromInt32(9) + libc.Int32FromInt32(9) + libc.Int32FromInt32(9)
		} else {
			v1 = libc.Int32FromInt32(4) + libc.Int32FromInt32(9) + libc.Int32FromInt32(9)
		} /* Cookie value to store */
		nHdr = v1
		libc.Xmemset(tls, bp, 0, uint32(12))
		/* Append the current configuration cookie */
		iCookie = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FiCookie
		if iCookie < 0 {
			iCookie = 0
		}
		if 0 == _sqlite3Fts5BufferSize(tls, p+44, bp, uint32(uint32(nHdr))) {
			_sqlite3Fts5Put32(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp, iCookie)
			(*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn = int32(4)
			if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
				libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), __ccgo_ts+37791, uint32(4))
				*(*int32)(unsafe.Pointer(bp + 4)) += int32(4)
			}
			*(*int32)(unsafe.Pointer(bp + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), uint64((*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel))
			*(*int32)(unsafe.Pointer(bp + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), uint64((*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment))
			*(*int32)(unsafe.Pointer(bp + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), uint64(int64((*TFts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter)))
		}
		iLvl = 0
		for {
			if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
				break
			} /* Used to iterate through segments */
			pLvl = pStruct + 32 + uintptr(iLvl)*12
			_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge))
			_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg))
			iSeg = 0
			for {
				if !(iSeg < (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg) {
					break
				}
				pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56
				_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid))
				_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst))
				_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast))
				if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
					_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1))
					_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2))
					_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone))
					_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntryTombstone))
					_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntry))
				}
				goto _3
			_3:
				;
				iSeg++
			}
			goto _2
		_2:
			;
			iLvl++
		}
		_fts5DataWrite(tls, p, int64(FTS5_STRUCTURE_ROWID), (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn)
		_sqlite3Fts5BufferFree(tls, bp)
	}
}

func _fts5SegmentSize(tls *libc.TLS, pSeg uintptr) (r int32) {
	return int32(1) + (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast - (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst
}

// C documentation
//
//	/*
//	** Return a copy of index structure pStruct. Except, promote as many
//	** segments as possible to level iPromote. If an OOM occurs, NULL is
//	** returned.
//	*/
func _fts5StructurePromoteTo(tls *libc.TLS, p uintptr, iPromote int32, szPromote int32, pStruct uintptr) {
	var il, is, sz int32
	var pLvl, pOut uintptr
	_, _, _, _, _ = il, is, pLvl, pOut, sz
	pOut = pStruct + 32 + uintptr(iPromote)*12
	if (*TFts5StructureLevel)(unsafe.Pointer(pOut)).FnMerge == 0 {
		il = iPromote + int32(1)
		for {
			if !(il < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
				break
			}
			pLvl = pStruct + 32 + uintptr(il)*12
			if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
				return
			}
			is = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg - int32(1)
			for {
				if !(is >= 0) {
					break
				}
				sz = _fts5SegmentSize(tls, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(is)*56)
				if sz > szPromote {
					return
				}
				_fts5StructureExtendLevel(tls, p+44, pStruct, iPromote, int32(1), int32(1))
				if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
					return
				}
				libc.Xmemcpy(tls, (*TFts5StructureLevel)(unsafe.Pointer(pOut)).FaSeg, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(is)*56, uint32(56))
				(*TFts5StructureLevel)(unsafe.Pointer(pOut)).FnSeg++
				(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg--
				goto _2
			_2:
				;
				is--
			}
			goto _1
		_1:
			;
			il++
		}
	}
}

// C documentation
//
//	/*
//	** A new segment has just been written to level iLvl of index structure
//	** pStruct. This function determines if any segments should be promoted
//	** as a result. Segments are promoted in two scenarios:
//	**
//	**   a) If the segment just written is smaller than one or more segments
//	**      within the previous populated level, it is promoted to the previous
//	**      populated level.
//	**
//	**   b) If the segment just written is larger than the newest segment on
//	**      the next populated level, then that segment, and any other adjacent
//	**      segments that are also smaller than the one just written, are
//	**      promoted.
//	**
//	** If one or more segments are promoted, the structure object is updated
//	** to reflect this.
//	*/
func _fts5StructurePromote(tls *libc.TLS, p uintptr, iLvl int32, pStruct uintptr) {
	var i, iPromote, iTst, nSeg, sz, szMax, szPromote, szSeg int32
	var pSeg, pTst uintptr
	_, _, _, _, _, _, _, _, _, _ = i, iPromote, iTst, nSeg, pSeg, pTst, sz, szMax, szPromote, szSeg
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		iPromote = -int32(1)
		szPromote = 0 /* Size of segment just written */
		nSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FnSeg
		if nSeg == 0 {
			return
		}
		pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FaSeg + uintptr((*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FnSeg-int32(1))*56
		szSeg = int32(1) + (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast - (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst
		/* Check for condition (a) */
		iTst = iLvl - int32(1)
		for {
			if !(iTst >= 0 && (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iTst)*12))).FnSeg == 0) {
				break
			}
			goto _1
		_1:
			;
			iTst--
		}
		if iTst >= 0 {
			szMax = 0
			pTst = pStruct + 32 + uintptr(iTst)*12
			i = 0
			for {
				if !(i < (*TFts5StructureLevel)(unsafe.Pointer(pTst)).FnSeg) {
					break
				}
				sz = (*(*TFts5StructureSegment)(unsafe.Pointer((*TFts5StructureLevel)(unsafe.Pointer(pTst)).FaSeg + uintptr(i)*56))).FpgnoLast - (*(*TFts5StructureSegment)(unsafe.Pointer((*TFts5StructureLevel)(unsafe.Pointer(pTst)).FaSeg + uintptr(i)*56))).FpgnoFirst + int32(1)
				if sz > szMax {
					szMax = sz
				}
				goto _2
			_2:
				;
				i++
			}
			if szMax >= szSeg {
				/* Condition (a) is true. Promote the newest segment on level
				 ** iLvl to level iTst.  */
				iPromote = iTst
				szPromote = szMax
			}
		}
		/* If condition (a) is not met, assume (b) is true. StructurePromoteTo()
		 ** is a no-op if it is not.  */
		if iPromote < 0 {
			iPromote = iLvl
			szPromote = szSeg
		}
		_fts5StructurePromoteTo(tls, p, iPromote, szPromote, pStruct)
	}
}

// C documentation
//
//	/*
//	** Advance the iterator passed as the only argument. If the end of the
//	** doclist-index page is reached, return non-zero.
//	*/
func _fts5DlidxLvlNext(tls *libc.TLS, pLvl uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iOff int32
	var pData, p2 uintptr
	var _ /* iVal at bp+0 */ Tu64
	_, _, _ = iOff, pData, p2
	pData = (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData
	if (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff == 0 {
		(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff = int32(1)
		*(*int32)(unsafe.Pointer(pLvl + 4)) += _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+1, pLvl+16)
		*(*int32)(unsafe.Pointer(pLvl + 4)) += int32(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff), pLvl+24))
		(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiFirstOff = (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff
	} else {
		iOff = (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff
		for {
			if !(iOff < (*TFts5Data)(unsafe.Pointer(pData)).Fnn) {
				break
			}
			if *(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pData)).Fp + uintptr(iOff))) != 0 {
				break
			}
			goto _1
		_1:
			;
			iOff++
		}
		if iOff < (*TFts5Data)(unsafe.Pointer(pData)).Fnn {
			*(*int32)(unsafe.Pointer(pLvl + 16)) += iOff - (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff + int32(1)
			iOff += int32(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr(iOff), bp))
			p2 = pLvl + 24
			*(*Ti64)(unsafe.Pointer(p2)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p2))) + *(*Tu64)(unsafe.Pointer(bp)))
			(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff = iOff
		} else {
			(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = int32(1)
		}
	}
	return (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof
}

// C documentation
//
//	/*
//	** Advance the iterator passed as the only argument.
//	*/
func _fts5DlidxIterNextR(tls *libc.TLS, p uintptr, pIter uintptr, iLvl int32) (r int32) {
	var pLvl uintptr
	_ = pLvl
	pLvl = pIter + 8 + uintptr(iLvl)*32
	if _fts5DlidxLvlNext(tls, pLvl) != 0 {
		if iLvl+int32(1) < (*TFts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl {
			_fts5DlidxIterNextR(tls, p, pIter, iLvl+int32(1))
			if (*(*TFts5DlidxLvl)(unsafe.Pointer(pLvl + 1*32))).FbEof == 0 {
				_fts5DataRelease(tls, (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)
				libc.Xmemset(tls, pLvl, 0, uint32(32))
				(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData = _fts5DataRead(tls, p, int64((*TFts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(iLvl)<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*(*TFts5DlidxLvl)(unsafe.Pointer(pLvl + 1*32))).FiLeafPgno))
				if (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData != 0 {
					_fts5DlidxLvlNext(tls, pLvl)
				}
			}
		}
	}
	return (*(*TFts5DlidxLvl)(unsafe.Pointer(pIter + 8))).FbEof
}

func _fts5DlidxIterNext(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	return _fts5DlidxIterNextR(tls, p, pIter, 0)
}

// C documentation
//
//	/*
//	** The iterator passed as the first argument has the following fields set
//	** as follows. This function sets up the rest of the iterator so that it
//	** points to the first rowid in the doclist-index.
//	**
//	**   pData:
//	**     pointer to doclist-index record,
//	**
//	** When this function is called pIter->iLeafPgno is the page number the
//	** doclist is associated with (the one featuring the term).
//	*/
func _fts5DlidxIterFirst(tls *libc.TLS, pIter uintptr) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TFts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl) {
			break
		}
		_fts5DlidxLvlNext(tls, pIter+8+uintptr(i)*32)
		goto _1
	_1:
		;
		i++
	}
	return (*(*TFts5DlidxLvl)(unsafe.Pointer(pIter + 8))).FbEof
}

func _fts5DlidxIterEof(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	return libc.BoolInt32((*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK || (*(*TFts5DlidxLvl)(unsafe.Pointer(pIter + 8))).FbEof != 0)
}

func _fts5DlidxIterLast(tls *libc.TLS, p uintptr, pIter uintptr) {
	var i int32
	var pChild, pLvl uintptr
	_, _, _ = i, pChild, pLvl
	/* Advance each level to the last entry on the last page */
	i = (*TFts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl - int32(1)
	for {
		if !((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && i >= 0) {
			break
		}
		pLvl = pIter + 8 + uintptr(i)*32
		for _fts5DlidxLvlNext(tls, pLvl) == 0 {
		}
		(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = 0
		if i > 0 {
			pChild = pLvl + uintptr(-libc.Int32FromInt32(1))*32
			_fts5DataRelease(tls, (*TFts5DlidxLvl)(unsafe.Pointer(pChild)).FpData)
			libc.Xmemset(tls, pChild, 0, uint32(32))
			(*TFts5DlidxLvl)(unsafe.Pointer(pChild)).FpData = _fts5DataRead(tls, p, int64((*TFts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(i-libc.Int32FromInt32(1))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiLeafPgno))
		}
		goto _1
	_1:
		;
		i--
	}
}

// C documentation
//
//	/*
//	** Move the iterator passed as the only argument to the previous entry.
//	*/
func _fts5DlidxLvlPrev(tls *libc.TLS, pLvl uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, p1 uintptr
	var iOff, ii, nZero int32
	var _ /* delta at bp+0 */ Tu64
	_, _, _, _, _ = a, iOff, ii, nZero, p1
	iOff = (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff
	if iOff <= (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiFirstOff {
		(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = int32(1)
	} else {
		a = (*TFts5Data)(unsafe.Pointer((*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)).Fp
		(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff = 0
		_fts5DlidxLvlNext(tls, pLvl)
		for int32(1) != 0 {
			nZero = 0
			ii = (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff
			*(*Tu64)(unsafe.Pointer(bp)) = uint64(0)
			for int32(*(*Tu8)(unsafe.Pointer(a + uintptr(ii)))) == 0 {
				nZero++
				ii++
			}
			ii += int32(_sqlite3Fts5GetVarint(tls, a+uintptr(ii), bp))
			if ii >= iOff {
				break
			}
			*(*int32)(unsafe.Pointer(pLvl + 16)) += nZero + int32(1)
			p1 = pLvl + 24
			*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) + *(*Tu64)(unsafe.Pointer(bp)))
			(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff = ii
		}
	}
	return (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof
}

func _fts5DlidxIterPrevR(tls *libc.TLS, p uintptr, pIter uintptr, iLvl int32) (r int32) {
	var pLvl uintptr
	_ = pLvl
	pLvl = pIter + 8 + uintptr(iLvl)*32
	if _fts5DlidxLvlPrev(tls, pLvl) != 0 {
		if iLvl+int32(1) < (*TFts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl {
			_fts5DlidxIterPrevR(tls, p, pIter, iLvl+int32(1))
			if (*(*TFts5DlidxLvl)(unsafe.Pointer(pLvl + 1*32))).FbEof == 0 {
				_fts5DataRelease(tls, (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)
				libc.Xmemset(tls, pLvl, 0, uint32(32))
				(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData = _fts5DataRead(tls, p, int64((*TFts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(iLvl)<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*(*TFts5DlidxLvl)(unsafe.Pointer(pLvl + 1*32))).FiLeafPgno))
				if (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData != 0 {
					for _fts5DlidxLvlNext(tls, pLvl) == 0 {
					}
					(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = 0
				}
			}
		}
	}
	return (*(*TFts5DlidxLvl)(unsafe.Pointer(pIter + 8))).FbEof
}

func _fts5DlidxIterPrev(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	return _fts5DlidxIterPrevR(tls, p, pIter, 0)
}

// C documentation
//
//	/*
//	** Free a doclist-index iterator object allocated by fts5DlidxIterInit().
//	*/
func _fts5DlidxIterFree(tls *libc.TLS, pIter uintptr) {
	var i int32
	_ = i
	if pIter != 0 {
		i = 0
		for {
			if !(i < (*TFts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl) {
				break
			}
			_fts5DataRelease(tls, (*(*TFts5DlidxLvl)(unsafe.Pointer(pIter + 8 + uintptr(i)*32))).FpData)
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, pIter)
	}
}

func _fts5DlidxIterInit(tls *libc.TLS, p uintptr, bRev int32, iSegid int32, iLeafPg int32) (r uintptr) {
	var bDone, i int32
	var iRowid Ti64
	var nByte Tsqlite3_int64
	var pIter, pLvl, pNew uintptr
	_, _, _, _, _, _, _ = bDone, i, iRowid, nByte, pIter, pLvl, pNew
	pIter = uintptr(0)
	bDone = 0
	i = 0
	for {
		if !((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bDone == 0) {
			break
		}
		nByte = int64(uint32(40) + uint32(uint32(i))*uint32(32))
		pNew = Xsqlite3_realloc64(tls, pIter, uint64(uint64(nByte)))
		if pNew == uintptr(0) {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		} else {
			iRowid = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(i)<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(iLeafPg)
			pLvl = pNew + 8 + uintptr(i)*32
			pIter = pNew
			libc.Xmemset(tls, pLvl, 0, uint32(32))
			(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData = _fts5DataRead(tls, p, iRowid)
			if (*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData != 0 && int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer((*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)).Fp)))&int32(0x0001) == 0 {
				bDone = int32(1)
			}
			(*TFts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl = i + int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*TFts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid = iSegid
		if bRev == 0 {
			_fts5DlidxIterFirst(tls, pIter)
		} else {
			_fts5DlidxIterLast(tls, p, pIter)
		}
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		_fts5DlidxIterFree(tls, pIter)
		pIter = uintptr(0)
	}
	return pIter
}

func _fts5DlidxIterRowid(tls *libc.TLS, pIter uintptr) (r Ti64) {
	return (*(*TFts5DlidxLvl)(unsafe.Pointer(pIter + 8))).FiRowid
}

func _fts5DlidxIterPgno(tls *libc.TLS, pIter uintptr) (r int32) {
	return (*(*TFts5DlidxLvl)(unsafe.Pointer(pIter + 8))).FiLeafPgno
}

// C documentation
//
//	/*
//	** Load the next leaf page into the segment iterator.
//	*/
func _fts5SegIterNextPage(tls *libc.TLS, p uintptr, pIter uintptr) {
	var pLeaf, pSeg uintptr
	_, _ = pLeaf, pSeg
	pSeg = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg
	_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno++
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf != 0 {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf = uintptr(0)
	} else {
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno <= (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = _fts5LeafRead(tls, p, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno))
		} else {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
		}
	}
	pLeaf = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf
	if pLeaf != 0 {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf
		if (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf >= (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn + int32(1)
		} else {
			*(*int32)(unsafe.Pointer(pIter + 48)) += _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff), pIter+52)
		}
	}
}

// C documentation
//
//	/*
//	** Argument p points to a buffer containing a varint to be interpreted as a
//	** position list size field. Read the varint and return the number of bytes
//	** read. Before returning, set *pnSz to the number of bytes in the position
//	** list, and *pbDel to true if the delete flag is set, or false otherwise.
//	*/
func _fts5GetPoslistSize(tls *libc.TLS, p uintptr, pnSz uintptr, pbDel uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var n, v1 int32
	var _ /* nSz at bp+0 */ int32
	_, _ = n, v1
	n = 0
	v1 = n
	n++
	*(*int32)(unsafe.Pointer(bp)) = int32(*(*Tu8)(unsafe.Pointer(p + uintptr(v1))))
	if *(*int32)(unsafe.Pointer(bp))&int32(0x80) != 0 {
		n--
		n += _sqlite3Fts5GetVarint32(tls, p+uintptr(n), bp)
	}
	*(*int32)(unsafe.Pointer(pnSz)) = *(*int32)(unsafe.Pointer(bp)) / int32(2)
	*(*int32)(unsafe.Pointer(pbDel)) = *(*int32)(unsafe.Pointer(bp)) & int32(0x0001)
	return n
}

// C documentation
//
//	/*
//	** Fts5SegIter.iLeafOffset currently points to the first byte of a
//	** position-list size field. Read the value of the field and store it
//	** in the following variables:
//	**
//	**   Fts5SegIter.nPos
//	**   Fts5SegIter.bDel
//	**
//	** Leave Fts5SegIter.iLeafOffset pointing to the first byte of the
//	** position list content (if any).
//	*/
func _fts5SegIterLoadNPos(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iEod, iOff, v1, v2 int32
	var _ /* nSz at bp+0 */ int32
	_, _, _, _ = iEod, iOff, v1, v2
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		iOff = int32((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset) /* Offset to read at */
		if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
			if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist < (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf {
				v1 = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist
			} else {
				v1 = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf
			}
			iEod = v1
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FbDel = uint8(0)
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FnPos = int32(1)
			if iOff < iEod && int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(iOff)))) == 0 {
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FbDel = uint8(1)
				iOff++
				if iOff < iEod && int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(iOff)))) == 0 {
					(*TFts5SegIter)(unsafe.Pointer(pIter)).FnPos = int32(1)
					iOff++
				} else {
					(*TFts5SegIter)(unsafe.Pointer(pIter)).FnPos = 0
				}
			}
		} else {
			v2 = iOff
			iOff++
			*(*int32)(unsafe.Pointer(bp)) = int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(v2))))
			if *(*int32)(unsafe.Pointer(bp))&int32(0x80) != 0 {
				iOff--
				iOff += _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iOff), bp)
			}
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FbDel = uint8(*(*int32)(unsafe.Pointer(bp)) & libc.Int32FromInt32(0x0001))
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FnPos = *(*int32)(unsafe.Pointer(bp)) >> int32(1)
		}
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(iOff))
	}
}

func _fts5SegIterLoadRowid(tls *libc.TLS, p uintptr, pIter uintptr) {
	var a uintptr
	var iOff Ti64
	_, _ = a, iOff
	a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp /* Buffer to read data from */
	iOff = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset
	for iOff >= int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf) {
		_fts5SegIterNextPage(tls, p, pIter)
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0) {
			if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
			return
		}
		iOff = int64(4)
		a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	}
	iOff += int64(_sqlite3Fts5GetVarint(tls, a+uintptr(iOff), pIter+88))
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = iOff
}

// C documentation
//
//	/*
//	** Fts5SegIter.iLeafOffset currently points to the first byte of the
//	** "nSuffix" field of a term. Function parameter nKeep contains the value
//	** of the "nPrefix" field (if there was one - it is passed 0 if this is
//	** the first term in the segment).
//	**
//	** This function populates:
//	**
//	**   Fts5SegIter.term
//	**   Fts5SegIter.rowid
//	**
//	** accordingly and leaves (Fts5SegIter.iLeafOffset) set to the content of
//	** the first position list. The position list belonging to document
//	** (Fts5SegIter.iRowid).
//	*/
func _fts5SegIterLoadTerm(tls *libc.TLS, p uintptr, pIter uintptr, nKeep int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a uintptr
	var iOff Ti64
	var _ /* nExtra at bp+4 */ int32
	var _ /* nNew at bp+0 */ int32
	_, _ = a, iOff
	a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp /* Buffer to read data from */
	iOff = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset                         /* Bytes of new data */
	iOff += int64(_sqlite3Fts5GetVarint32(tls, a+uintptr(iOff), bp))
	if iOff+int64(*(*int32)(unsafe.Pointer(bp))) > int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf) || nKeep > (*TFts5SegIter)(unsafe.Pointer(pIter)).Fterm.Fn || *(*int32)(unsafe.Pointer(bp)) == 0 {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		return
	}
	(*TFts5SegIter)(unsafe.Pointer(pIter)).Fterm.Fn = nKeep
	_sqlite3Fts5BufferAppendBlob(tls, p+44, pIter+72, uint32(*(*int32)(unsafe.Pointer(bp))), a+uintptr(iOff))
	iOff += int64(*(*int32)(unsafe.Pointer(bp)))
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset = int32(int32(iOff))
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = iOff
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff >= (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn + int32(1)
	} else {
		*(*int32)(unsafe.Pointer(pIter + 48)) += _sqlite3Fts5GetVarint32(tls, a+uintptr((*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff), bp+4)
		*(*int32)(unsafe.Pointer(pIter + 52)) += *(*int32)(unsafe.Pointer(bp + 4))
	}
	_fts5SegIterLoadRowid(tls, p, pIter)
}

func _fts5SegIterSetNext(tls *libc.TLS, p uintptr, pIter uintptr) {
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).Fflags&int32(FTS5_SEGITER_REVERSE) != 0 {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FxNext = __ccgo_fp(_fts5SegIterNext_Reverse)
	} else {
		if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FxNext = __ccgo_fp(_fts5SegIterNext_None)
		} else {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FxNext = __ccgo_fp(_fts5SegIterNext)
		}
	}
}

// C documentation
//
//	/*
//	** Allocate a tombstone hash page array object (pIter->pTombArray) for
//	** the iterator passed as the second argument. If an OOM error occurs,
//	** leave an error in the Fts5Index object.
//	*/
func _fts5SegIterAllocTombstone(tls *libc.TLS, p uintptr, pIter uintptr) {
	var nByte, nTomb int32
	var pNew uintptr
	_, _, _ = nByte, nTomb, pNew
	nTomb = (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FnPgTombstone
	if nTomb > 0 {
		nByte = int32(uint32(uint32(nTomb))*uint32(4) + uint32(12))
		pNew = _sqlite3Fts5MallocZero(tls, p+44, int64(int64(nByte)))
		if pNew != 0 {
			(*TFts5TombstoneArray)(unsafe.Pointer(pNew)).FnTombstone = nTomb
			(*TFts5TombstoneArray)(unsafe.Pointer(pNew)).FnRef = int32(1)
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FpTombArray = pNew
		}
	}
}

// C documentation
//
//	/*
//	** Initialize the iterator object pIter to iterate through the entries in
//	** segment pSeg. The iterator is left pointing to the first entry when
//	** this function returns.
//	**
//	** If an error occurs, Fts5Index.rc is set to an appropriate error code. If
//	** an error has already occurred when this function is called, it is a no-op.
//	*/
func _fts5SegIterInit(tls *libc.TLS, p uintptr, pSeg uintptr, pIter uintptr) {
	if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst == 0 {
		/* This happens if the segment is being used as an input to an incremental
		 ** merge and all data has already been "trimmed". See function
		 ** fts5TrimSegments() for details. In this case leave the iterator empty.
		 ** The caller will see the (pIter->pLeaf==0) and assume the iterator is
		 ** at EOF already. */
		return
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		libc.Xmemset(tls, pIter, 0, uint32(104))
		_fts5SegIterSetNext(tls, p, pIter)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst - int32(1)
		for cond := true; cond; cond = (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 && (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn == int32(4) {
			_fts5SegIterNextPage(tls, p, pIter)
		}
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(4)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf + int32(1)
		_fts5SegIterLoadTerm(tls, p, pIter, 0)
		_fts5SegIterLoadNPos(tls, p, pIter)
		_fts5SegIterAllocTombstone(tls, p, pIter)
	}
}

// C documentation
//
//	/*
//	** This function is only ever called on iterators created by calls to
//	** Fts5IndexQuery() with the FTS5INDEX_QUERY_DESC flag set.
//	**
//	** The iterator is in an unusual state when this function is called: the
//	** Fts5SegIter.iLeafOffset variable is set to the offset of the start of
//	** the position-list size field for the first relevant rowid on the page.
//	** Fts5SegIter.rowid is set, but nPos and bDel are not.
//	**
//	** This function advances the iterator so that it points to the last
//	** relevant rowid on the page and, if necessary, initializes the
//	** aRowidOffset[] and iRowidOffset variables. At this point the iterator
//	** is in its regular state - Fts5SegIter.iLeafOffset points to the first
//	** byte of the position list content associated with said rowid.
//	*/
func _fts5SegIterReverseInitPage(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, aNew, p1 uintptr
	var eDetail, i, iRowidOffset, n, nNew, v2 int32
	var _ /* bDummy at bp+12 */ int32
	var _ /* iDelta at bp+0 */ Tu64
	var _ /* nPos at bp+8 */ int32
	_, _, _, _, _, _, _, _, _ = a, aNew, eDetail, i, iRowidOffset, n, nNew, v2, p1
	eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
	n = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf
	i = int32((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
	a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	iRowidOffset = 0
	if n > (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist {
		n = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist
	}
	for int32(1) != 0 {
		*(*Tu64)(unsafe.Pointer(bp)) = uint64(0)
		if eDetail == int32(FTS5_DETAIL_NONE) {
			/* todo */
			if i < n && int32(*(*Tu8)(unsafe.Pointer(a + uintptr(i)))) == 0 {
				i++
				if i < n && int32(*(*Tu8)(unsafe.Pointer(a + uintptr(i)))) == 0 {
					i++
				}
			}
		} else {
			i += _fts5GetPoslistSize(tls, a+uintptr(i), bp+8, bp+12)
			i += *(*int32)(unsafe.Pointer(bp + 8))
		}
		if i >= n {
			break
		}
		i += int32(_sqlite3Fts5GetVarint(tls, a+uintptr(i), bp))
		p1 = pIter + 88
		*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) + *(*Tu64)(unsafe.Pointer(bp)))
		/* If necessary, grow the pIter->aRowidOffset[] array. */
		if iRowidOffset >= (*TFts5SegIter)(unsafe.Pointer(pIter)).FnRowidOffset {
			nNew = (*TFts5SegIter)(unsafe.Pointer(pIter)).FnRowidOffset + int32(8)
			aNew = Xsqlite3_realloc64(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset, uint64(uint32(uint32(nNew))*uint32(4)))
			if aNew == uintptr(0) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
				break
			}
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset = aNew
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FnRowidOffset = nNew
		}
		v2 = iRowidOffset
		iRowidOffset++
		*(*int32)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset + uintptr(v2)*4)) = int32((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(i))
	}
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset = iRowidOffset
	_fts5SegIterLoadNPos(tls, p, pIter)
}

// C documentation
//
//	/*
//	**
//	*/
func _fts5SegIterReverseNewPage(tls *libc.TLS, p uintptr, pIter uintptr) {
	var a, pNew uintptr
	var iRowidOff int32
	_, _, _ = a, iRowidOff, pNew
	_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
	for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno > (*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno--
		pNew = _fts5DataRead(tls, p, int64((*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno))
		if pNew != 0 {
			/* iTermLeafOffset may be equal to szLeaf if the term is the last
			 ** thing on the page - i.e. the first rowid is on the following page.
			 ** In this case leave pIter->pLeaf==0, this iterator is at EOF. */
			if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno {
				if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset < (*TFts5Data)(unsafe.Pointer(pNew)).FszLeaf {
					(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pNew
					(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64((*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset)
				}
			} else {
				iRowidOff = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pNew)).Fp))
				if iRowidOff != 0 {
					if iRowidOff >= (*TFts5Data)(unsafe.Pointer(pNew)).FszLeaf {
						(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					} else {
						(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pNew
						(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(iRowidOff))
					}
				}
			}
			if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
				a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
				*(*Ti64)(unsafe.Pointer(pIter + 24)) += int64(_sqlite3Fts5GetVarint(tls, a, pIter+88))
				break
			} else {
				_fts5DataRelease(tls, pNew)
			}
		}
	}
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn + int32(1)
		_fts5SegIterReverseInitPage(tls, p, pIter)
	}
}

// C documentation
//
//	/*
//	** Return true if the iterator passed as the second argument currently
//	** points to a delete marker. A delete marker is an entry with a 0 byte
//	** position-list.
//	*/
func _fts5MultiIterIsEmpty(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	var pSeg uintptr
	_ = pSeg
	pSeg = pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)*104
	return libc.BoolInt32((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos == 0)
}

// C documentation
//
//	/*
//	** Advance iterator pIter to the next entry.
//	**
//	** This version of fts5SegIterNext() is only used by reverse iterators.
//	*/
func _fts5SegIterNext_Reverse(tls *libc.TLS, p uintptr, pIter uintptr, pbUnused uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, p1 uintptr
	var iOff int32
	var _ /* iDelta at bp+0 */ Tu64
	_, _, _ = a, iOff, p1
	_ = pbUnused
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset > 0 {
		a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset--
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(*(*int32)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset + uintptr((*TFts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset)*4)))
		_fts5SegIterLoadNPos(tls, p, pIter)
		iOff = int32((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
		if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail != int32(FTS5_DETAIL_NONE) {
			iOff += (*TFts5SegIter)(unsafe.Pointer(pIter)).FnPos
		}
		_sqlite3Fts5GetVarint(tls, a+uintptr(iOff), bp)
		p1 = pIter + 88
		*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) - *(*Tu64)(unsafe.Pointer(bp)))
	} else {
		_fts5SegIterReverseNewPage(tls, p, pIter)
	}
}

// C documentation
//
//	/*
//	** Advance iterator pIter to the next entry.
//	**
//	** This version of fts5SegIterNext() is only used if detail=none and the
//	** iterator is not a reverse direction iterator.
//	*/
func _fts5SegIterNext_None(tls *libc.TLS, p uintptr, pIter uintptr, pbNewTerm uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iOff int32
	var _ /* iDelta at bp+0 */ Ti64
	var _ /* nKeep at bp+8 */ int32
	var _ /* nList at bp+24 */ int32
	var _ /* nTerm at bp+20 */ int32
	var _ /* pList at bp+12 */ uintptr
	var _ /* zTerm at bp+16 */ uintptr
	_ = iOff
	iOff = int32((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
	/* Next entry is on the next page */
	for (*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg != 0 && iOff >= (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf {
		_fts5SegIterNextPage(tls, p, pIter)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 || (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0) {
			return
		}
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiRowid = 0
		iOff = int32(4)
	}
	if iOff < (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist {
		iOff += int32(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iOff), bp))
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(iOff))
		*(*Ti64)(unsafe.Pointer(pIter + 88)) += *(*Ti64)(unsafe.Pointer(bp))
	} else {
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).Fflags&int32(FTS5_SEGITER_ONETERM) == 0 {
			if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg != 0 {
				*(*int32)(unsafe.Pointer(bp + 8)) = 0
				if iOff != _fts5LeafFirstTermOff(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf) {
					iOff += _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iOff), bp+8)
				}
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(iOff))
				_fts5SegIterLoadTerm(tls, p, pIter, *(*int32)(unsafe.Pointer(bp + 8)))
			} else {
				*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
				*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
				*(*int32)(unsafe.Pointer(bp + 20)) = 0
				_sqlite3Fts5HashScanNext(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash)
				_sqlite3Fts5HashScanEntry(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash, bp+16, bp+20, bp+12, bp+24)
				if *(*uintptr)(unsafe.Pointer(bp + 12)) == uintptr(0) {
					goto next_none_eof
				}
				(*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp = *(*uintptr)(unsafe.Pointer(bp + 12))
				(*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn = *(*int32)(unsafe.Pointer(bp + 24))
				(*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf = *(*int32)(unsafe.Pointer(bp + 24))
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = *(*int32)(unsafe.Pointer(bp + 24))
				_sqlite3Fts5BufferSet(tls, p+44, pIter+72, *(*int32)(unsafe.Pointer(bp + 20)), *(*uintptr)(unsafe.Pointer(bp + 16)))
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(_sqlite3Fts5GetVarint(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), pIter+88))
			}
			if pbNewTerm != 0 {
				*(*int32)(unsafe.Pointer(pbNewTerm)) = int32(1)
			}
		} else {
			goto next_none_eof
		}
	}
	_fts5SegIterLoadNPos(tls, p, pIter)
	return
	goto next_none_eof
next_none_eof:
	;
	_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
}

// C documentation
//
//	/*
//	** Advance iterator pIter to the next entry.
//	**
//	** If an error occurs, Fts5Index.rc is set to an appropriate error code. It
//	** is not considered an error if the iterator reaches EOF. If an error has
//	** already occurred when this function is called, it is a no-op.
//	*/
func _fts5SegIterNext(tls *libc.TLS, p uintptr, pIter uintptr, pbNewTerm uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var a, pLeaf, v4, p1 uintptr
	var bNewTerm, n, v2 int32
	var v3 Ti64
	var _ /* iDelta at bp+8 */ Tu64
	var _ /* iOff at bp+0 */ int32
	var _ /* nKeep at bp+4 */ int32
	var _ /* nList at bp+28 */ int32
	var _ /* nSz at bp+32 */ int32
	var _ /* nTerm at bp+24 */ int32
	var _ /* pList at bp+16 */ uintptr
	var _ /* zTerm at bp+20 */ uintptr
	_, _, _, _, _, _, _, _ = a, bNewTerm, n, pLeaf, v2, v3, v4, p1
	pLeaf = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf
	bNewTerm = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	/* Search for the end of the position list within the current page. */
	a = (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp
	n = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf
	*(*int32)(unsafe.Pointer(bp)) = int32((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset + int64((*TFts5SegIter)(unsafe.Pointer(pIter)).FnPos))
	if *(*int32)(unsafe.Pointer(bp)) < n {
		/* The next entry is on the current page. */
		if *(*int32)(unsafe.Pointer(bp)) >= (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist {
			bNewTerm = int32(1)
			if *(*int32)(unsafe.Pointer(bp)) != _fts5LeafFirstTermOff(tls, pLeaf) {
				*(*int32)(unsafe.Pointer(bp)) += _sqlite3Fts5GetVarint32(tls, a+uintptr(*(*int32)(unsafe.Pointer(bp))), bp+4)
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) += int32(_sqlite3Fts5GetVarint(tls, a+uintptr(*(*int32)(unsafe.Pointer(bp))), bp+8))
			p1 = pIter + 88
			*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) + *(*Tu64)(unsafe.Pointer(bp + 8)))
		}
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(*(*int32)(unsafe.Pointer(bp)))
	} else {
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
			*(*uintptr)(unsafe.Pointer(bp + 20)) = uintptr(0)
			*(*int32)(unsafe.Pointer(bp + 24)) = 0
			*(*int32)(unsafe.Pointer(bp + 28)) = 0
			if 0 == (*TFts5SegIter)(unsafe.Pointer(pIter)).Fflags&int32(FTS5_SEGITER_ONETERM) {
				_sqlite3Fts5HashScanNext(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash)
				_sqlite3Fts5HashScanEntry(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash, bp+20, bp+24, bp+16, bp+28)
			}
			if *(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0) {
				_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
			} else {
				(*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp = *(*uintptr)(unsafe.Pointer(bp + 16))
				(*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn = *(*int32)(unsafe.Pointer(bp + 28))
				(*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf = *(*int32)(unsafe.Pointer(bp + 28))
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = *(*int32)(unsafe.Pointer(bp + 28)) + int32(1)
				_sqlite3Fts5BufferSet(tls, p+44, pIter+72, *(*int32)(unsafe.Pointer(bp + 24)), *(*uintptr)(unsafe.Pointer(bp + 20)))
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(_sqlite3Fts5GetVarint(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), pIter+88))
				*(*int32)(unsafe.Pointer(pbNewTerm)) = int32(1)
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) = 0
			/* Next entry is not on the current page */
			for *(*int32)(unsafe.Pointer(bp)) == 0 {
				_fts5SegIterNextPage(tls, p, pIter)
				pLeaf = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf
				if pLeaf == uintptr(0) {
					break
				}
				v2 = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp))
				*(*int32)(unsafe.Pointer(bp)) = v2
				if v2 != 0 && *(*int32)(unsafe.Pointer(bp)) < (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
					*(*int32)(unsafe.Pointer(bp)) += int32(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(*(*int32)(unsafe.Pointer(bp))), pIter+88))
					(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(*(*int32)(unsafe.Pointer(bp)))
					if (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn > (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
						(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf + _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf), pIter+52)
					}
				} else {
					if (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn > (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
						(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf + _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf), bp)
						(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(*(*int32)(unsafe.Pointer(bp)))
						(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = *(*int32)(unsafe.Pointer(bp))
						bNewTerm = int32(1)
					}
				}
				if *(*int32)(unsafe.Pointer(bp)) > (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
					(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					return
				}
			}
		}
	}
	/* Check if the iterator is now at EOF. If so, return early. */
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		if bNewTerm != 0 {
			if (*TFts5SegIter)(unsafe.Pointer(pIter)).Fflags&int32(FTS5_SEGITER_ONETERM) != 0 {
				_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
			} else {
				_fts5SegIterLoadTerm(tls, p, pIter, *(*int32)(unsafe.Pointer(bp + 4)))
				_fts5SegIterLoadNPos(tls, p, pIter)
				if pbNewTerm != 0 {
					*(*int32)(unsafe.Pointer(pbNewTerm)) = int32(1)
				}
			}
		} else {
			v4 = pIter + 24
			v3 = *(*Ti64)(unsafe.Pointer(v4))
			*(*Ti64)(unsafe.Pointer(v4))++
			*(*int32)(unsafe.Pointer(bp + 32)) = int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(v3))))
			if *(*int32)(unsafe.Pointer(bp + 32))&int32(0x80) != 0 {
				(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset--
				*(*Ti64)(unsafe.Pointer(pIter + 24)) += int64(_sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset), bp+32))
			}
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FbDel = uint8(*(*int32)(unsafe.Pointer(bp + 32)) & libc.Int32FromInt32(0x0001))
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FnPos = *(*int32)(unsafe.Pointer(bp + 32)) >> int32(1)
		}
	}
}

// C documentation
//
//	/*
//	** Iterator pIter currently points to the first rowid in a doclist. This
//	** function sets the iterator up so that iterates in reverse order through
//	** the doclist.
//	*/
func _fts5SegIterReverse(tls *libc.TLS, p uintptr, pIter uintptr) {
	var bTermless, iEnd, iOff, iPoslist, iRowid, iSegid, pgno, pgnoLast, v1 int32
	var iAbs Ti64
	var pDlidx, pLast, pLeaf, pNew, pSeg, tmp uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bTermless, iAbs, iEnd, iOff, iPoslist, iRowid, iSegid, pDlidx, pLast, pLeaf, pNew, pSeg, pgno, pgnoLast, tmp, v1
	pDlidx = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpDlidx
	pLast = uintptr(0)
	pgnoLast = 0
	if pDlidx != 0 && (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FiVersion == int32(FTS5_CURRENT_VERSION) {
		iSegid = (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FiSegid
		pgnoLast = _fts5DlidxIterPgno(tls, pDlidx)
		pLast = _fts5LeafRead(tls, p, int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(pgnoLast))
	} else {
		pLeaf = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno {
			iPoslist = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset
		} else {
			iPoslist = int32(4)
		}
		iEnd = iPoslist + int32(9)
		for {
			v1 = iPoslist
			iPoslist++
			if !(int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pLeaf)).Fp + uintptr(v1))))&int32(0x80) != 0 && iPoslist < iEnd) {
				break
			}
		}
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(iPoslist))
		/* If this condition is true then the largest rowid for the current
		 ** term may not be stored on the current page. So search forward to
		 ** see where said rowid really is.  */
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist >= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
			pSeg = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg
			/* The last rowid in the doclist may not be on the current page. Search
			 ** forward to find the page containing the last rowid.  */
			pgno = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno + int32(1)
			for {
				if !(!((*TFts5Index)(unsafe.Pointer(p)).Frc != 0) && pgno <= (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast) {
					break
				}
				iAbs = int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(pgno)
				pNew = _fts5LeafRead(tls, p, iAbs)
				if pNew != 0 {
					iRowid = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pNew)).Fp))
					bTermless = libc.BoolInt32((*TFts5Data)(unsafe.Pointer(pNew)).FszLeaf >= (*TFts5Data)(unsafe.Pointer(pNew)).Fnn)
					if iRowid != 0 {
						tmp = pNew
						pNew = pLast
						pLast = tmp
						pgnoLast = pgno
					}
					_fts5DataRelease(tls, pNew)
					if bTermless == 0 {
						break
					}
				}
				goto _2
			_2:
				;
				pgno++
			}
		}
	}
	/* If pLast is NULL at this point, then the last rowid for this doclist
	 ** lies on the page currently indicated by the iterator. In this case
	 ** pIter->iLeafOffset is already set to point to the position-list size
	 ** field associated with the first relevant rowid on the page.
	 **
	 ** Or, if pLast is non-NULL, then it is the page that contains the last
	 ** rowid. In this case configure the iterator so that it points to the
	 ** first rowid on this page.
	 */
	if pLast != 0 {
		_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pLast
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = pgnoLast
		iOff = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLast)).Fp))
		if iOff > (*TFts5Data)(unsafe.Pointer(pLast)).FszLeaf {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			return
		}
		iOff += int32(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pLast)).Fp+uintptr(iOff), pIter+88))
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(iOff))
		if (*TFts5Data)(unsafe.Pointer(pLast)).FszLeaf >= (*TFts5Data)(unsafe.Pointer(pLast)).Fnn {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*TFts5Data)(unsafe.Pointer(pLast)).Fnn + int32(1)
		} else {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = _fts5LeafFirstTermOff(tls, pLast)
		}
	}
	_fts5SegIterReverseInitPage(tls, p, pIter)
}

// C documentation
//
//	/*
//	** Iterator pIter currently points to the first rowid of a doclist.
//	** There is a doclist-index associated with the final term on the current
//	** page. If the current term is the last term on the page, load the
//	** doclist-index from disk and initialize an iterator at (pIter->pDlidx).
//	*/
func _fts5SegIterLoadDlidx(tls *libc.TLS, p uintptr, pIter uintptr) {
	var bRev, iSeg int32
	var pLeaf uintptr
	_, _, _ = bRev, iSeg, pLeaf
	iSeg = (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FiSegid
	bRev = (*TFts5SegIter)(unsafe.Pointer(pIter)).Fflags & int32(FTS5_SEGITER_REVERSE)
	pLeaf = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf /* Current leaf data */
	/* Check if the current doclist ends on this page. If it does, return
	 ** early without loading the doclist-index (as it belongs to a different
	 ** term. */
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno && (*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist < (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
		return
	}
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FpDlidx = _fts5DlidxIterInit(tls, p, bRev, iSeg, (*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno)
}

// C documentation
//
//	/*
//	** The iterator object passed as the second argument currently contains
//	** no valid values except for the Fts5SegIter.pLeaf member variable. This
//	** function searches the leaf page for a term matching (pTerm/nTerm).
//	**
//	** If the specified term is found on the page, then the iterator is left
//	** pointing to it. If argument bGe is zero and the term is not found,
//	** the iterator is left pointing at EOF.
//	**
//	** If bGe is non-zero and the specified term is not found, then the
//	** iterator is left pointing to the smallest term in the segment that
//	** is larger than the specified term, even if this term is not on the
//	** current page.
//	*/
func _fts5LeafSeek(tls *libc.TLS, p uintptr, bGe int32, pIter uintptr, pTerm uintptr, nTerm int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a uintptr
	var bEndOfPage int32
	var i, iPgidx, n, nCmp, nMatch, v1, v4 Tu32
	var v2 uint32
	var _ /* iOff at bp+0 */ Tu32
	var _ /* iTermOff at bp+12 */ Tu32
	var _ /* nExtra at bp+16 */ int32
	var _ /* nKeep at bp+4 */ Tu32
	var _ /* nNew at bp+8 */ Tu32
	_, _, _, _, _, _, _, _, _, _ = a, bEndOfPage, i, iPgidx, n, nCmp, nMatch, v1, v2, v4
	a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	n = uint32((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn)
	nMatch = uint32(0)
	*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0)
	*(*Tu32)(unsafe.Pointer(bp + 8)) = uint32(0) /* Current offset in pgidx */
	bEndOfPage = 0
	iPgidx = uint32((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf)
	iPgidx += uint32(_sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidx), bp+12))
	*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(bp + 12))
	if *(*Tu32)(unsafe.Pointer(bp)) > n {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		return
	}
	for int32(1) != 0 {
		/* Figure out how many new bytes are in this term */
		v1 = *(*Tu32)(unsafe.Pointer(bp))
		*(*Tu32)(unsafe.Pointer(bp))++
		*(*Tu32)(unsafe.Pointer(bp + 8)) = uint32(*(*Tu8)(unsafe.Pointer(a + uintptr(v1))))
		if *(*Tu32)(unsafe.Pointer(bp + 8))&uint32(0x80) != 0 {
			*(*Tu32)(unsafe.Pointer(bp))--
			*(*Tu32)(unsafe.Pointer(bp)) += uint32(_sqlite3Fts5GetVarint32(tls, a+uintptr(*(*Tu32)(unsafe.Pointer(bp))), bp+8))
		}
		if *(*Tu32)(unsafe.Pointer(bp + 4)) < nMatch {
			goto search_failed
		}
		if *(*Tu32)(unsafe.Pointer(bp + 4)) == nMatch {
			if *(*Tu32)(unsafe.Pointer(bp + 8)) < uint32(uint32(nTerm))-nMatch {
				v2 = *(*Tu32)(unsafe.Pointer(bp + 8))
			} else {
				v2 = uint32(uint32(nTerm)) - nMatch
			}
			nCmp = v2
			i = uint32(0)
			for {
				if !(i < nCmp) {
					break
				}
				if int32(*(*Tu8)(unsafe.Pointer(a + uintptr(*(*Tu32)(unsafe.Pointer(bp))+i)))) != int32(*(*Tu8)(unsafe.Pointer(pTerm + uintptr(nMatch+i)))) {
					break
				}
				goto _3
			_3:
				;
				i++
			}
			nMatch += i
			if uint32(uint32(nTerm)) == nMatch {
				if i == *(*Tu32)(unsafe.Pointer(bp + 8)) {
					goto search_success
				} else {
					goto search_failed
				}
			} else {
				if i < *(*Tu32)(unsafe.Pointer(bp + 8)) && int32(*(*Tu8)(unsafe.Pointer(a + uintptr(*(*Tu32)(unsafe.Pointer(bp))+i)))) > int32(*(*Tu8)(unsafe.Pointer(pTerm + uintptr(nMatch)))) {
					goto search_failed
				}
			}
		}
		if iPgidx >= n {
			bEndOfPage = int32(1)
			break
		}
		iPgidx += uint32(_sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidx), bp+4))
		*(*Tu32)(unsafe.Pointer(bp + 12)) += *(*Tu32)(unsafe.Pointer(bp + 4))
		*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(bp + 12))
		if *(*Tu32)(unsafe.Pointer(bp)) >= n {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			return
		}
		/* Read the nKeep field of the next term. */
		v4 = *(*Tu32)(unsafe.Pointer(bp))
		*(*Tu32)(unsafe.Pointer(bp))++
		*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(*(*Tu8)(unsafe.Pointer(a + uintptr(v4))))
		if *(*Tu32)(unsafe.Pointer(bp + 4))&uint32(0x80) != 0 {
			*(*Tu32)(unsafe.Pointer(bp))--
			*(*Tu32)(unsafe.Pointer(bp)) += uint32(_sqlite3Fts5GetVarint32(tls, a+uintptr(*(*Tu32)(unsafe.Pointer(bp))), bp+4))
		}
	}
	goto search_failed
search_failed:
	;
	if bGe == 0 {
		_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
		return
	} else {
		if bEndOfPage != 0 {
			for cond := true; cond; cond = int32(1) != 0 {
				_fts5SegIterNextPage(tls, p, pIter)
				if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0) {
					return
				}
				a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
				if libc.BoolInt32((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf >= (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn) == 0 {
					iPgidx = uint32((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf)
					iPgidx += uint32(_sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iPgidx), bp))
					if *(*Tu32)(unsafe.Pointer(bp)) < uint32(4) || int64(*(*Tu32)(unsafe.Pointer(bp))) >= int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf) {
						(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						return
					} else {
						*(*Tu32)(unsafe.Pointer(bp + 4)) = uint32(0)
						*(*Tu32)(unsafe.Pointer(bp + 12)) = *(*Tu32)(unsafe.Pointer(bp))
						n = uint32((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn)
						*(*Tu32)(unsafe.Pointer(bp)) += uint32(_sqlite3Fts5GetVarint32(tls, a+uintptr(*(*Tu32)(unsafe.Pointer(bp))), bp+8))
						break
					}
				}
			}
		}
	}
	goto search_success
search_success:
	;
	if int64(*(*Tu32)(unsafe.Pointer(bp)))+int64(*(*Tu32)(unsafe.Pointer(bp + 8))) > int64(int64(n)) || *(*Tu32)(unsafe.Pointer(bp + 8)) < uint32(1) {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		return
	}
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(*(*Tu32)(unsafe.Pointer(bp)) + *(*Tu32)(unsafe.Pointer(bp + 8)))
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset = int32((*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno
	_sqlite3Fts5BufferSet(tls, p+44, pIter+72, int32(*(*Tu32)(unsafe.Pointer(bp + 4))), pTerm)
	_sqlite3Fts5BufferAppendBlob(tls, p+44, pIter+72, *(*Tu32)(unsafe.Pointer(bp + 8)), a+uintptr(*(*Tu32)(unsafe.Pointer(bp))))
	if iPgidx >= n {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn + int32(1)
	} else {
		iPgidx += uint32(_sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidx), bp+16))
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = int32(*(*Tu32)(unsafe.Pointer(bp + 12)) + uint32(*(*int32)(unsafe.Pointer(bp + 16))))
	}
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = int32(int32(iPgidx))
	_fts5SegIterLoadRowid(tls, p, pIter)
	_fts5SegIterLoadNPos(tls, p, pIter)
}

func _fts5IdxSelectStmt(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig uintptr
	_ = pConfig
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+72, Xsqlite3_mprintf(tls, __ccgo_ts+37819, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	return (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect
}

// C documentation
//
//	/*
//	** Initialize the object pIter to point to term pTerm/nTerm within segment
//	** pSeg. If there is no such term in the index, the iterator is set to EOF.
//	**
//	** If an error occurs, Fts5Index.rc is set to an appropriate error code. If
//	** an error has already occurred when this function is called, it is a no-op.
//	*/
func _fts5SegIterSeekInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32, flags int32, pSeg uintptr, pIter uintptr) {
	var bDlidx, bGe, iPg int32
	var pIdxSelect uintptr
	var val Ti64
	_, _, _, _, _ = bDlidx, bGe, iPg, pIdxSelect, val
	iPg = int32(1)
	bGe = flags & int32(FTS5INDEX_QUERY_SCAN)
	bDlidx = 0 /* True if there is a doclist-index */
	pIdxSelect = uintptr(0)
	libc.Xmemset(tls, pIter, 0, uint32(104))
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg
	/* This block sets stack variable iPg to the leaf page number that may
	 ** contain term (pTerm/nTerm), if it is present in the segment. */
	pIdxSelect = _fts5IdxSelectStmt(tls, p)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
		return
	}
	Xsqlite3_bind_int(tls, pIdxSelect, int32(1), (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
	Xsqlite3_bind_blob(tls, pIdxSelect, int32(2), pTerm, nTerm, libc.UintptrFromInt32(0))
	if int32(SQLITE_ROW) == Xsqlite3_step(tls, pIdxSelect) {
		val = int64(Xsqlite3_column_int(tls, pIdxSelect, 0))
		iPg = int32(val >> libc.Int32FromInt32(1))
		bDlidx = int32(val & libc.Int64FromInt32(0x0001))
	}
	(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, pIdxSelect)
	Xsqlite3_bind_null(tls, pIdxSelect, int32(2))
	if iPg < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
		iPg = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst
		bDlidx = 0
	}
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iPg - int32(1)
	_fts5SegIterNextPage(tls, p, pIter)
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		_fts5LeafSeek(tls, p, bGe, pIter, pTerm, nTerm)
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (bGe == 0 || flags&int32(FTS5INDEX_QUERY_SCANONETERM) != 0) {
		*(*int32)(unsafe.Pointer(pIter + 4)) |= int32(FTS5_SEGITER_ONETERM)
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
			if flags&int32(FTS5INDEX_QUERY_DESC) != 0 {
				*(*int32)(unsafe.Pointer(pIter + 4)) |= int32(FTS5_SEGITER_REVERSE)
			}
			if bDlidx != 0 {
				_fts5SegIterLoadDlidx(tls, p, pIter)
			}
			if flags&int32(FTS5INDEX_QUERY_DESC) != 0 {
				_fts5SegIterReverse(tls, p, pIter)
			}
		}
	}
	_fts5SegIterSetNext(tls, p, pIter)
	if 0 == flags&int32(FTS5INDEX_QUERY_SCANONETERM) {
		_fts5SegIterAllocTombstone(tls, p, pIter)
	}
	/* Either:
	 **
	 **   1) an error has occurred, or
	 **   2) the iterator points to EOF, or
	 **   3) the iterator points to an entry with term (pTerm/nTerm), or
	 **   4) the FTS5INDEX_QUERY_SCAN flag was set and the iterator points
	 **      to an entry with a term greater than or equal to (pTerm/nTerm).
	 */
}

// C documentation
//
//	/*
//	** SQL used by fts5SegIterNextInit() to find the page to open.
//	*/
func _fts5IdxNextStmt(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig uintptr
	_ = pConfig
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxNextSelect == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+76, Xsqlite3_mprintf(tls, __ccgo_ts+37903, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	return (*TFts5Index)(unsafe.Pointer(p)).FpIdxNextSelect
}

// C documentation
//
//	/*
//	** This is similar to fts5SegIterSeekInit(), except that it initializes
//	** the segment iterator to point to the first term following the page
//	** with pToken/nToken on it.
//	*/
func _fts5SegIterNextInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32, pSeg uintptr, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, pSel uintptr
	var bDlidx, iPg int32
	var val Ti64
	var _ /* iTermOff at bp+0 */ int32
	_, _, _, _, _ = a, bDlidx, iPg, pSel, val
	iPg = -int32(1) /* Page of segment to open */
	bDlidx = 0
	pSel = uintptr(0) /* SELECT to find iPg */
	pSel = _fts5IdxNextStmt(tls, p)
	if pSel != 0 {
		Xsqlite3_bind_int(tls, pSel, int32(1), (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
		Xsqlite3_bind_blob(tls, pSel, int32(2), pTerm, nTerm, libc.UintptrFromInt32(0))
		if Xsqlite3_step(tls, pSel) == int32(SQLITE_ROW) {
			val = Xsqlite3_column_int64(tls, pSel, 0)
			iPg = int32(val >> libc.Int32FromInt32(1))
			bDlidx = int32(val & libc.Int64FromInt32(0x0001))
		}
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, pSel)
		Xsqlite3_bind_null(tls, pSel, int32(2))
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
	}
	libc.Xmemset(tls, pIter, 0, uint32(104))
	(*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg
	*(*int32)(unsafe.Pointer(pIter + 4)) |= int32(FTS5_SEGITER_ONETERM)
	if iPg >= 0 {
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iPg - int32(1)
		_fts5SegIterNextPage(tls, p, pIter)
		_fts5SegIterSetNext(tls, p, pIter)
	}
	if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
		*(*int32)(unsafe.Pointer(bp)) = 0
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf
		*(*int32)(unsafe.Pointer(pIter + 48)) += _sqlite3Fts5GetVarint32(tls, a+uintptr((*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff), bp)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(*(*int32)(unsafe.Pointer(bp)))
		_fts5SegIterLoadTerm(tls, p, pIter, 0)
		_fts5SegIterLoadNPos(tls, p, pIter)
		if bDlidx != 0 {
			_fts5SegIterLoadDlidx(tls, p, pIter)
		}
	}
}

// C documentation
//
//	/*
//	** Initialize the object pIter to point to term pTerm/nTerm within the
//	** in-memory hash table. If there is no such term in the hash-table, the
//	** iterator is set to EOF.
//	**
//	** If an error occurs, Fts5Index.rc is set to an appropriate error code. If
//	** an error has already occurred when this function is called, it is a no-op.
//	*/
func _fts5SegIterHashInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32, flags int32, pIter uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var v1 int32
	var _ /* n at bp+8 */ int32
	var _ /* nList at bp+0 */ int32
	var _ /* pLeaf at bp+12 */ uintptr
	var _ /* pList at bp+16 */ uintptr
	var _ /* z at bp+4 */ uintptr
	_ = v1
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
	if pTerm == uintptr(0) || flags&int32(FTS5INDEX_QUERY_SCAN) != 0 {
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5HashScanInit(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash, pTerm, nTerm)
		_sqlite3Fts5HashScanEntry(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash, bp+4, bp+8, bp+16, bp)
		if *(*uintptr)(unsafe.Pointer(bp + 16)) != 0 {
			*(*uintptr)(unsafe.Pointer(bp + 12)) = _fts5IdxMalloc(tls, p, int64(12))
			if *(*uintptr)(unsafe.Pointer(bp + 12)) != 0 {
				(*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).Fp = *(*uintptr)(unsafe.Pointer(bp + 16))
			}
		}
		/* The call to sqlite3Fts5HashScanInit() causes the hash table to
		 ** fill the size field of all existing position lists. This means they
		 ** can no longer be appended to. Since the only scenario in which they
		 ** can be appended to is if the previous operation on this table was
		 ** a DELETE, by clearing the Fts5Index.bDelete flag we can avoid this
		 ** possibility altogether.  */
		(*TFts5Index)(unsafe.Pointer(p)).FbDelete = 0
	} else {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5HashQuery(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash, int32(12), pTerm, nTerm, bp+12, bp)
		if *(*uintptr)(unsafe.Pointer(bp + 12)) != 0 {
			(*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).Fp = *(*uintptr)(unsafe.Pointer(bp + 12)) + 1*12
		}
		*(*uintptr)(unsafe.Pointer(bp + 4)) = pTerm
		*(*int32)(unsafe.Pointer(bp + 8)) = nTerm
		*(*int32)(unsafe.Pointer(pIter + 4)) |= int32(FTS5_SEGITER_ONETERM)
	}
	if *(*uintptr)(unsafe.Pointer(bp + 12)) != 0 {
		_sqlite3Fts5BufferSet(tls, p+44, pIter+72, *(*int32)(unsafe.Pointer(bp + 8)), *(*uintptr)(unsafe.Pointer(bp + 4)))
		v1 = *(*int32)(unsafe.Pointer(bp))
		(*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FszLeaf = v1
		(*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).Fnn = v1
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = *(*uintptr)(unsafe.Pointer(bp + 12))
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).Fp, pIter+88))
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).Fnn
		if flags&int32(FTS5INDEX_QUERY_DESC) != 0 {
			*(*int32)(unsafe.Pointer(pIter + 4)) |= int32(FTS5_SEGITER_REVERSE)
			_fts5SegIterReverseInitPage(tls, p, pIter)
		} else {
			_fts5SegIterLoadNPos(tls, p, pIter)
		}
	}
	_fts5SegIterSetNext(tls, p, pIter)
}

// C documentation
//
//	/*
//	** Array ap[] contains n elements. Release each of these elements using
//	** fts5DataRelease(). Then free the array itself using sqlite3_free().
//	*/
func _fts5IndexFreeArray(tls *libc.TLS, ap uintptr, n int32) {
	var ii int32
	_ = ii
	if ap != 0 {
		ii = 0
		for {
			if !(ii < n) {
				break
			}
			_fts5DataRelease(tls, *(*uintptr)(unsafe.Pointer(ap + uintptr(ii)*4)))
			goto _1
		_1:
			;
			ii++
		}
		Xsqlite3_free(tls, ap)
	}
}

// C documentation
//
//	/*
//	** Decrement the ref-count of the object passed as the only argument. If it
//	** reaches 0, free it and its contents.
//	*/
func _fts5TombstoneArrayDelete(tls *libc.TLS, p uintptr) {
	var ii int32
	_ = ii
	if p != 0 {
		(*TFts5TombstoneArray)(unsafe.Pointer(p)).FnRef--
		if (*TFts5TombstoneArray)(unsafe.Pointer(p)).FnRef <= 0 {
			ii = 0
			for {
				if !(ii < (*TFts5TombstoneArray)(unsafe.Pointer(p)).FnTombstone) {
					break
				}
				_fts5DataRelease(tls, *(*uintptr)(unsafe.Pointer(p + 8 + uintptr(ii)*4)))
				goto _1
			_1:
				;
				ii++
			}
			Xsqlite3_free(tls, p)
		}
	}
}

// C documentation
//
//	/*
//	** Zero the iterator passed as the only argument.
//	*/
func _fts5SegIterClear(tls *libc.TLS, pIter uintptr) {
	_sqlite3Fts5BufferFree(tls, pIter+72)
	_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf)
	_fts5TombstoneArrayDelete(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpTombArray)
	_fts5DlidxIterFree(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpDlidx)
	Xsqlite3_free(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset)
	libc.Xmemset(tls, pIter, 0, uint32(104))
}

// C documentation
//
//	/*
//	** Do the comparison necessary to populate pIter->aFirst[iOut].
//	**
//	** If the returned value is non-zero, then it is the index of an entry
//	** in the pIter->aSeg[] array that is (a) not at EOF, and (b) pointing
//	** to a key that is a duplicate of another, higher priority,
//	** segment-iterator in the pSeg->aSeg[] array.
//	*/
func _fts5MultiIterDoCompare(tls *libc.TLS, pIter uintptr, iOut int32) (r int32) {
	var i1, i2, iRes, res, v1 int32
	var p1, p2, pRes uintptr
	_, _, _, _, _, _, _, _ = i1, i2, iRes, p1, p2, pRes, res, v1 /* Right-hand Fts5SegIter */
	pRes = (*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(iOut)*4
	if iOut >= (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg/int32(2) {
		i1 = (iOut - (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg/int32(2)) * int32(2)
		i2 = i1 + int32(1)
	} else {
		i1 = int32((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(iOut*int32(2))*4))).FiFirst)
		i2 = int32((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(iOut*int32(2)+int32(1))*4))).FiFirst)
	}
	p1 = pIter + 80 + uintptr(i1)*104
	p2 = pIter + 80 + uintptr(i2)*104
	(*TFts5CResult)(unsafe.Pointer(pRes)).FbTermEq = uint8(0)
	if (*TFts5SegIter)(unsafe.Pointer(p1)).FpLeaf == uintptr(0) { /* If p1 is at EOF */
		iRes = i2
	} else {
		if (*TFts5SegIter)(unsafe.Pointer(p2)).FpLeaf == uintptr(0) { /* If p2 is at EOF */
			iRes = i1
		} else {
			res = _fts5BufferCompare(tls, p1+72, p2+72)
			if res == 0 {
				(*TFts5CResult)(unsafe.Pointer(pRes)).FbTermEq = uint8(1)
				if (*TFts5SegIter)(unsafe.Pointer(p1)).FiRowid == (*TFts5SegIter)(unsafe.Pointer(p2)).FiRowid {
					return i2
				}
				if libc.BoolInt32((*TFts5SegIter)(unsafe.Pointer(p1)).FiRowid > (*TFts5SegIter)(unsafe.Pointer(p2)).FiRowid) == (*TFts5Iter)(unsafe.Pointer(pIter)).FbRev {
					v1 = -int32(1)
				} else {
					v1 = +libc.Int32FromInt32(1)
				}
				res = v1
			}
			if res < 0 {
				iRes = i1
			} else {
				iRes = i2
			}
		}
	}
	(*TFts5CResult)(unsafe.Pointer(pRes)).FiFirst = uint16(uint16(iRes))
	return 0
}

// C documentation
//
//	/*
//	** Move the seg-iter so that it points to the first rowid on page iLeafPgno.
//	** It is an error if leaf iLeafPgno does not exist. Unless the db is
//	** a 'secure-delete' db, if it contains no rowids then this is also an error.
//	*/
func _fts5SegIterGotoPage(tls *libc.TLS, p uintptr, pIter uintptr, iLeafPgno int32) {
	var a uintptr
	var iOff, n int32
	_, _, _ = a, iOff, n
	if iLeafPgno > (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FpgnoLast {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	} else {
		_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf = uintptr(0)
		(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iLeafPgno - int32(1)
		for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			_fts5SegIterNextPage(tls, p, pIter)
			if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0) {
				break
			}
			iOff = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp))
			if iOff > 0 {
				a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
				n = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf
				if iOff < int32(4) || iOff >= n {
					(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				} else {
					iOff += int32(_sqlite3Fts5GetVarint(tls, a+uintptr(iOff), pIter+88))
					(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(int64(iOff))
					_fts5SegIterLoadNPos(tls, p, pIter)
				}
				break
			}
		}
	}
}

// C documentation
//
//	/*
//	** Advance the iterator passed as the second argument until it is at or
//	** past rowid iFrom. Regardless of the value of iFrom, the iterator is
//	** always advanced at least once.
//	*/
func _fts5SegIterNextFrom(tls *libc.TLS, p uintptr, pIter uintptr, iMatch Ti64) {
	var bMove, bRev, iLeafPgno int32
	var pDlidx uintptr
	_, _, _, _ = bMove, bRev, iLeafPgno, pDlidx
	bRev = (*TFts5SegIter)(unsafe.Pointer(pIter)).Fflags & int32(FTS5_SEGITER_REVERSE)
	pDlidx = (*TFts5SegIter)(unsafe.Pointer(pIter)).FpDlidx
	iLeafPgno = (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno
	bMove = int32(1)
	if bRev == 0 {
		for !(_fts5DlidxIterEof(tls, p, pDlidx) != 0) && iMatch > _fts5DlidxIterRowid(tls, pDlidx) {
			iLeafPgno = _fts5DlidxIterPgno(tls, pDlidx)
			_fts5DlidxIterNext(tls, p, pDlidx)
		}
		if iLeafPgno > (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno {
			_fts5SegIterGotoPage(tls, p, pIter, iLeafPgno)
			bMove = 0
		}
	} else {
		for !(_fts5DlidxIterEof(tls, p, pDlidx) != 0) && iMatch < _fts5DlidxIterRowid(tls, pDlidx) {
			_fts5DlidxIterPrev(tls, p, pDlidx)
		}
		iLeafPgno = _fts5DlidxIterPgno(tls, pDlidx)
		if iLeafPgno < (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iLeafPgno + int32(1)
			_fts5SegIterReverseNewPage(tls, p, pIter)
			bMove = 0
		}
	}
	for cond := true; cond; cond = (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if bMove != 0 && (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5SegIter)(unsafe.Pointer(pIter)).FxNext})))(tls, p, pIter, uintptr(0))
		}
		if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0) {
			break
		}
		if bRev == 0 && (*TFts5SegIter)(unsafe.Pointer(pIter)).FiRowid >= iMatch {
			break
		}
		if bRev != 0 && (*TFts5SegIter)(unsafe.Pointer(pIter)).FiRowid <= iMatch {
			break
		}
		bMove = int32(1)
	}
}

// C documentation
//
//	/*
//	** Free the iterator object passed as the second argument.
//	*/
func _fts5MultiIterFree(tls *libc.TLS, pIter uintptr) {
	var i int32
	_ = i
	if pIter != 0 {
		i = 0
		for {
			if !(i < (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg) {
				break
			}
			_fts5SegIterClear(tls, pIter+80+uintptr(i)*104)
			goto _1
		_1:
			;
			i++
		}
		_sqlite3Fts5BufferFree(tls, pIter+32)
		Xsqlite3_free(tls, pIter)
	}
}

func _fts5MultiIterAdvanced(tls *libc.TLS, p uintptr, pIter uintptr, iChanged int32, iMinset int32) {
	var i, iEq, v2 int32
	var pSeg uintptr
	_, _, _, _ = i, iEq, pSeg, v2
	i = ((*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg + iChanged) / int32(2)
	for {
		if !(i >= iMinset && (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
			break
		}
		v2 = _fts5MultiIterDoCompare(tls, pIter, i)
		iEq = v2
		if v2 != 0 {
			pSeg = pIter + 80 + uintptr(iEq)*104
			(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5SegIter)(unsafe.Pointer(pSeg)).FxNext})))(tls, p, pSeg, uintptr(0))
			i = (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg + iEq
		}
		goto _1
	_1:
		;
		i = i / int32(2)
	}
}

// C documentation
//
//	/*
//	** Sub-iterator iChanged of iterator pIter has just been advanced. It still
//	** points to the same term though - just a different rowid. This function
//	** attempts to update the contents of the pIter->aFirst[] accordingly.
//	** If it does so successfully, 0 is returned. Otherwise 1.
//	**
//	** If non-zero is returned, the caller should call fts5MultiIterAdvanced()
//	** on the iterator instead. That function does the same as this one, except
//	** that it deals with more complicated cases as well.
//	*/
func _fts5MultiIterAdvanceRowid(tls *libc.TLS, pIter uintptr, iChanged int32, ppFirst uintptr) (r int32) {
	var i int32
	var pNew, pOther, pRes uintptr
	var v1 int64
	_, _, _, _, _ = i, pNew, pOther, pRes, v1
	pNew = pIter + 80 + uintptr(iChanged)*104
	if (*TFts5SegIter)(unsafe.Pointer(pNew)).FiRowid == (*TFts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid || libc.BoolInt32((*TFts5SegIter)(unsafe.Pointer(pNew)).FiRowid < (*TFts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid) == (*TFts5Iter)(unsafe.Pointer(pIter)).FbRev {
		pOther = pIter + 80 + uintptr(iChanged^int32(0x0001))*104
		if (*TFts5Iter)(unsafe.Pointer(pIter)).FbRev != 0 {
			v1 = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
		} else {
			v1 = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
		}
		(*TFts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = v1
		i = ((*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg + iChanged) / int32(2)
		for {
			if !(int32(1) != 0) {
				break
			}
			pRes = (*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(i)*4
			if (*TFts5CResult)(unsafe.Pointer(pRes)).FbTermEq != 0 {
				if (*TFts5SegIter)(unsafe.Pointer(pNew)).FiRowid == (*TFts5SegIter)(unsafe.Pointer(pOther)).FiRowid {
					return int32(1)
				} else {
					if libc.BoolInt32((*TFts5SegIter)(unsafe.Pointer(pOther)).FiRowid > (*TFts5SegIter)(unsafe.Pointer(pNew)).FiRowid) == (*TFts5Iter)(unsafe.Pointer(pIter)).FbRev {
						(*TFts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = (*TFts5SegIter)(unsafe.Pointer(pOther)).FiRowid
						pNew = pOther
					} else {
						if libc.BoolInt32((*TFts5SegIter)(unsafe.Pointer(pOther)).FiRowid > (*TFts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid) == (*TFts5Iter)(unsafe.Pointer(pIter)).FbRev {
							(*TFts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = (*TFts5SegIter)(unsafe.Pointer(pOther)).FiRowid
						}
					}
				}
			}
			(*TFts5CResult)(unsafe.Pointer(pRes)).FiFirst = uint16((int32(int32(pNew)) - t__predefined_ptrdiff_t(pIter+80)) / 104)
			if i == int32(1) {
				break
			}
			pOther = pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(i^int32(0x0001))*4))).FiFirst)*104
			goto _2
		_2:
			;
			i = i / int32(2)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppFirst)) = pNew
	return 0
}

// C documentation
//
//	/*
//	** Set the pIter->bEof variable based on the state of the sub-iterators.
//	*/
func _fts5MultiIterSetEof(tls *libc.TLS, pIter uintptr) {
	var pSeg uintptr
	_ = pSeg
	pSeg = pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)*104
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof = libc.BoolUint8((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf == uintptr(0))
	(*TFts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
}

/*
** The argument to this macro must be an Fts5Data structure containing a
** tombstone hash page. This macro returns the key-size of the hash-page.
 */

// C documentation
//
//	/*
//	** Query a single tombstone hash table for rowid iRowid. Return true if
//	** it is found or false otherwise. The tombstone hash table is one of
//	** nHashTable tables.
//	*/
func _fts5IndexTombstoneQuery(tls *libc.TLS, pHash uintptr, nHashTable int32, iRowid Tu64) (r int32) {
	var aSlot, aSlot1 uintptr
	var iSlot, nCollide, nSlot, szKey, v1, v2, v3, v4, v5 int32
	_, _, _, _, _, _, _, _, _, _, _ = aSlot, aSlot1, iSlot, nCollide, nSlot, szKey, v1, v2, v3, v4, v5
	if int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pHash)).Fp))) == int32(4) {
		v1 = int32(4)
	} else {
		v1 = int32(8)
	}
	szKey = v1
	if (*TFts5Data)(unsafe.Pointer(pHash)).Fnn > int32(16) {
		if int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pHash)).Fp))) == int32(4) {
			v3 = int32(4)
		} else {
			v3 = int32(8)
		}
		v2 = ((*TFts5Data)(unsafe.Pointer(pHash)).Fnn - int32(8)) / v3
	} else {
		v2 = int32(1)
	}
	nSlot = v2
	iSlot = int32(iRowid / uint64(uint64(nHashTable)) % uint64(uint64(nSlot)))
	nCollide = nSlot
	if iRowid == uint64(0) {
		return int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pHash)).Fp + 1)))
	} else {
		if szKey == int32(4) {
			aSlot = (*TFts5Data)(unsafe.Pointer(pHash)).Fp + 8
			for *(*Tu32)(unsafe.Pointer(aSlot + uintptr(iSlot)*4)) != 0 {
				if uint64(_fts5GetU32(tls, aSlot+uintptr(iSlot)*4)) == iRowid {
					return int32(1)
				}
				v4 = nCollide
				nCollide--
				if v4 == 0 {
					break
				}
				iSlot = (iSlot + int32(1)) % nSlot
			}
		} else {
			aSlot1 = (*TFts5Data)(unsafe.Pointer(pHash)).Fp + 8
			for *(*Tu64)(unsafe.Pointer(aSlot1 + uintptr(iSlot)*8)) != 0 {
				if _fts5GetU64(tls, aSlot1+uintptr(iSlot)*8) == iRowid {
					return int32(1)
				}
				v5 = nCollide
				nCollide--
				if v5 == 0 {
					break
				}
				iSlot = (iSlot + int32(1)) % nSlot
			}
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if the iterator passed as the only argument points
//	** to an segment entry for which there is a tombstone. Return false
//	** if there is no tombstone or if the iterator is already at EOF.
//	*/
func _fts5MultiIterIsDeleted(tls *libc.TLS, pIter uintptr) (r int32) {
	var iFirst, iPg int32
	var pArray, pSeg uintptr
	_, _, _, _ = iFirst, iPg, pArray, pSeg
	iFirst = int32((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)
	pSeg = pIter + 80 + uintptr(iFirst)*104
	pArray = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpTombArray
	if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 && pArray != 0 {
		/* Figure out which page the rowid might be present on. */
		iPg = int32(uint64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid) % uint64((*TFts5TombstoneArray)(unsafe.Pointer(pArray)).FnTombstone))
		/* If tombstone hash page iPg has not yet been loaded from the
		 ** database, load it now. */
		if *(*uintptr)(unsafe.Pointer(pArray + 8 + uintptr(iPg)*4)) == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(pArray + 8 + uintptr(iPg)*4)) = _fts5DataRead(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex, int64((*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FiSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(iPg))
			if *(*uintptr)(unsafe.Pointer(pArray + 8 + uintptr(iPg)*4)) == uintptr(0) {
				return 0
			}
		}
		return _fts5IndexTombstoneQuery(tls, *(*uintptr)(unsafe.Pointer(pArray + 8 + uintptr(iPg)*4)), (*TFts5TombstoneArray)(unsafe.Pointer(pArray)).FnTombstone, uint64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid))
	}
	return 0
}

// C documentation
//
//	/*
//	** Move the iterator to the next entry.
//	**
//	** If an error occurs, an error code is left in Fts5Index.rc. It is not
//	** considered an error if the iterator reaches EOF, or if it is already at
//	** EOF when this function is called.
//	*/
func _fts5MultiIterNext(tls *libc.TLS, p uintptr, pIter uintptr, bFrom int32, iFrom Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bUseFrom, iFirst int32
	var _ /* bNewTerm at bp+0 */ int32
	var _ /* pSeg at bp+4 */ uintptr
	_, _ = bUseFrom, iFirst
	bUseFrom = bFrom
	for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		iFirst = int32((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)
		*(*int32)(unsafe.Pointer(bp)) = 0
		*(*uintptr)(unsafe.Pointer(bp + 4)) = pIter + 80 + uintptr(iFirst)*104
		if bUseFrom != 0 && (*TFts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpDlidx != 0 {
			_fts5SegIterNextFrom(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)), iFrom)
		} else {
			(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FxNext})))(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)), bp)
		}
		if (*TFts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpLeaf == uintptr(0) || *(*int32)(unsafe.Pointer(bp)) != 0 || _fts5MultiIterAdvanceRowid(tls, pIter, iFirst, bp+4) != 0 {
			_fts5MultiIterAdvanced(tls, p, pIter, iFirst, int32(1))
			_fts5MultiIterSetEof(tls, pIter)
			*(*uintptr)(unsafe.Pointer(bp + 4)) = pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)*104
			if (*TFts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpLeaf == uintptr(0) {
				return
			}
		}
		if (int32((*TFts5Iter)(unsafe.Pointer(pIter)).FbSkipEmpty) == 0 || (*TFts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FnPos != 0) && 0 == _fts5MultiIterIsDeleted(tls, pIter) {
			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs})))(tls, pIter, *(*uintptr)(unsafe.Pointer(bp + 4)))
			return
		}
		bUseFrom = 0
	}
}

func _fts5MultiIterNext2(tls *libc.TLS, p uintptr, pIter uintptr, pbNewTerm uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iFirst int32
	var _ /* bNewTerm at bp+4 */ int32
	var _ /* pSeg at bp+0 */ uintptr
	_ = iFirst
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pbNewTerm)) = 0
		for cond := true; cond; cond = (_fts5MultiIterIsEmpty(tls, p, pIter) != 0 || _fts5MultiIterIsDeleted(tls, pIter) != 0) && (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			iFirst = int32((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)
			*(*uintptr)(unsafe.Pointer(bp)) = pIter + 80 + uintptr(iFirst)*104
			*(*int32)(unsafe.Pointer(bp + 4)) = 0
			(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxNext})))(tls, p, *(*uintptr)(unsafe.Pointer(bp)), bp+4)
			if (*TFts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpLeaf == uintptr(0) || *(*int32)(unsafe.Pointer(bp + 4)) != 0 || _fts5MultiIterAdvanceRowid(tls, pIter, iFirst, bp) != 0 {
				_fts5MultiIterAdvanced(tls, p, pIter, iFirst, int32(1))
				_fts5MultiIterSetEof(tls, pIter)
				*(*int32)(unsafe.Pointer(pbNewTerm)) = int32(1)
			}
		}
	}
}

func _fts5IterSetOutputs_Noop(tls *libc.TLS, pUnused1 uintptr, pUnused2 uintptr) {
	_ = pUnused1
	_ = pUnused2
}

func _fts5MultiIterAlloc(tls *libc.TLS, p uintptr, nSeg int32) (r uintptr) {
	var nSlot Ti64
	var pNew uintptr
	_, _ = nSlot, pNew /* Power of two >= nSeg */
	nSlot = int64(2)
	for {
		if !(nSlot < int64(int64(nSeg))) {
			break
		}
		goto _1
	_1:
		;
		nSlot = nSlot * int64(2)
	}
	pNew = _fts5IdxMalloc(tls, p, int64(184)+int64(104)*(nSlot-int64(1))+int64(4)*nSlot)
	if pNew != 0 {
		(*TFts5Iter)(unsafe.Pointer(pNew)).FnSeg = int32(int32(nSlot))
		(*TFts5Iter)(unsafe.Pointer(pNew)).FaFirst = pNew + 80 + uintptr(nSlot)*104
		(*TFts5Iter)(unsafe.Pointer(pNew)).FpIndex = p
		(*TFts5Iter)(unsafe.Pointer(pNew)).FxSetOutputs = __ccgo_fp(_fts5IterSetOutputs_Noop)
	}
	return pNew
}

func _fts5PoslistCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
	_ = pUnused
	if nChunk > 0 {
		libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(pContext)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pContext)).Fn), pChunk, uint32(uint32(nChunk)))
		*(*int32)(unsafe.Pointer(pContext + 4)) += nChunk
	}
}

type TPoslistCallbackCtx = struct {
	FpBuf    uintptr
	FpColset uintptr
	FeState  int32
}

type PoslistCallbackCtx = TPoslistCallbackCtx

type TPoslistCallbackCtx1 = struct {
	FpBuf    uintptr
	FpColset uintptr
	FeState  int32
}

type PoslistCallbackCtx1 = TPoslistCallbackCtx1

type TPoslistOffsetsCtx = struct {
	FpBuf    uintptr
	FpColset uintptr
	FiRead   int32
	FiWrite  int32
}

type PoslistOffsetsCtx = TPoslistOffsetsCtx

type TPoslistOffsetsCtx1 = struct {
	FpBuf    uintptr
	FpColset uintptr
	FiRead   int32
	FiWrite  int32
}

type PoslistOffsetsCtx1 = TPoslistOffsetsCtx1

// C documentation
//
//	/*
//	** TODO: Make this more efficient!
//	*/
func _fts5IndexColsetTest(tls *libc.TLS, pColset uintptr, iCol int32) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol) {
			break
		}
		if *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) == iCol {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

func _fts5PoslistOffsetsCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var pCtx uintptr
	var _ /* iVal at bp+0 */ int32
	_, _ = i, pCtx
	pCtx = pContext
	_ = pUnused
	if nChunk > 0 {
		i = 0
		for i < nChunk {
			i += _sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp)
			*(*int32)(unsafe.Pointer(bp)) += (*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiRead - int32(2)
			(*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiRead = *(*int32)(unsafe.Pointer(bp))
			if _fts5IndexColsetTest(tls, (*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpColset, *(*int32)(unsafe.Pointer(bp))) != 0 {
				*(*int32)(unsafe.Pointer((*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer((*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer((*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), uint64(*(*int32)(unsafe.Pointer(bp))+libc.Int32FromInt32(2)-(*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiWrite))
				(*TPoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiWrite = *(*int32)(unsafe.Pointer(bp))
			}
		}
	}
}

func _fts5PoslistFilterCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iStart, v1, v2 int32
	var pCtx uintptr
	var _ /* iCol at bp+0 */ int32
	var _ /* iCol at bp+4 */ int32
	_, _, _, _, _ = i, iStart, pCtx, v1, v2
	pCtx = pContext
	_ = pUnused
	if nChunk > 0 {
		/* Search through to find the first varint with value 1. This is the
		 ** start of the next columns hits. */
		i = 0
		iStart = 0
		if (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState == int32(2) {
			v1 = i
			i++
			*(*int32)(unsafe.Pointer(bp)) = int32(*(*Tu8)(unsafe.Pointer(pChunk + uintptr(v1))))
			if *(*int32)(unsafe.Pointer(bp))&int32(0x80) != 0 {
				i--
				i += _sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp)
			}
			if _fts5IndexColsetTest(tls, (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpColset, *(*int32)(unsafe.Pointer(bp))) != 0 {
				(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = int32(1)
				*(*int32)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), uint64(libc.Int32FromInt32(1)))
			} else {
				(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = 0
			}
		}
		for cond := true; cond; cond = i < nChunk {
			for i < nChunk && int32(*(*Tu8)(unsafe.Pointer(pChunk + uintptr(i)))) != int32(0x01) {
				for int32(*(*Tu8)(unsafe.Pointer(pChunk + uintptr(i))))&int32(0x80) != 0 {
					i++
				}
				i++
			}
			if (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState != 0 {
				libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), pChunk+uintptr(iStart), uint32(i-iStart))
				*(*int32)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 4)) += i - iStart
			}
			if i < nChunk {
				iStart = i
				i++
				if i >= nChunk {
					(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = int32(2)
				} else {
					v2 = i
					i++
					*(*int32)(unsafe.Pointer(bp + 4)) = int32(*(*Tu8)(unsafe.Pointer(pChunk + uintptr(v2))))
					if *(*int32)(unsafe.Pointer(bp + 4))&int32(0x80) != 0 {
						i--
						i += _sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp+4)
					}
					(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = _fts5IndexColsetTest(tls, (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpColset, *(*int32)(unsafe.Pointer(bp + 4)))
					if (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState != 0 {
						libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), pChunk+uintptr(iStart), uint32(i-iStart))
						*(*int32)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 4)) += i - iStart
						iStart = i
					}
				}
			}
		}
	}
}

func _fts5ChunkIterate(tls *libc.TLS, p uintptr, pSeg uintptr, pCtx uintptr, xChunk uintptr) {
	var nChunk, nRem, pgno, pgnoSave, v2 int32
	var pChunk, pData uintptr
	var v1 int64
	_, _, _, _, _, _, _, _ = nChunk, nRem, pChunk, pData, pgno, pgnoSave, v1, v2
	nRem = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos /* Number of bytes still to come */
	pData = uintptr(0)
	pChunk = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
	if int64(nRem) < int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf)-(*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset {
		v1 = int64(nRem)
	} else {
		v1 = int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf) - (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset
	}
	nChunk = int32(v1)
	pgno = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno
	pgnoSave = 0
	/* This function does not work with detail=none databases. */
	if (*TFts5SegIter)(unsafe.Pointer(pSeg)).Fflags&int32(FTS5_SEGITER_REVERSE) == 0 {
		pgnoSave = pgno + int32(1)
	}
	for int32(1) != 0 {
		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xChunk})))(tls, p, pCtx, pChunk, nChunk)
		nRem -= nChunk
		_fts5DataRelease(tls, pData)
		if nRem <= 0 {
			break
		} else {
			if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg == uintptr(0) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				return
			} else {
				pgno++
				pData = _fts5LeafRead(tls, p, int64((*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(pgno))
				if pData == uintptr(0) {
					break
				}
				pChunk = (*TFts5Data)(unsafe.Pointer(pData)).Fp + 4
				if nRem < (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf-int32(4) {
					v2 = nRem
				} else {
					v2 = (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf - int32(4)
				}
				nChunk = v2
				if pgno == pgnoSave {
					(*TFts5SegIter)(unsafe.Pointer(pSeg)).FpNextLeaf = pData
					pData = uintptr(0)
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Iterator pIter currently points to a valid entry (not EOF). This
//	** function appends the position list data for the current entry to
//	** buffer pBuf. It does not make a copy of the position-list size
//	** field.
//	*/
func _fts5SegiterPoslist(tls *libc.TLS, p uintptr, pSeg uintptr, pColset uintptr, pBuf uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var v1 int32
	var _ /* sCtx at bp+0 */ TPoslistCallbackCtx
	var _ /* sCtx at bp+12 */ TPoslistOffsetsCtx
	_ = v1
	if uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)+uint32((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos+libc.Int32FromInt32(FTS5_DATA_ZERO_PADDING)) <= uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
		v1 = 0
	} else {
		v1 = _sqlite3Fts5BufferSize(tls, p+44, pBuf, uint32((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos+int32(FTS5_DATA_ZERO_PADDING)+(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn))
	}
	if 0 == v1 {
		libc.Xmemset(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos), 0, uint32(FTS5_DATA_ZERO_PADDING))
		if pColset == uintptr(0) {
			_fts5ChunkIterate(tls, p, pSeg, pBuf, __ccgo_fp(_fts5PoslistCallback))
		} else {
			if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == FTS5_DETAIL_FULL {
				(*(*TPoslistCallbackCtx)(unsafe.Pointer(bp))).FpBuf = pBuf
				(*(*TPoslistCallbackCtx)(unsafe.Pointer(bp))).FpColset = pColset
				(*(*TPoslistCallbackCtx)(unsafe.Pointer(bp))).FeState = _fts5IndexColsetTest(tls, pColset, 0)
				_fts5ChunkIterate(tls, p, pSeg, bp, __ccgo_fp(_fts5PoslistFilterCallback))
			} else {
				libc.Xmemset(tls, bp+12, 0, uint32(16))
				(*(*TPoslistOffsetsCtx)(unsafe.Pointer(bp + 12))).FpBuf = pBuf
				(*(*TPoslistOffsetsCtx)(unsafe.Pointer(bp + 12))).FpColset = pColset
				_fts5ChunkIterate(tls, p, pSeg, bp+12, __ccgo_fp(_fts5PoslistOffsetsCallback))
			}
		}
	}
}

// C documentation
//
//	/*
//	** Parameter pPos points to a buffer containing a position list, size nPos.
//	** This function filters it according to pColset (which must be non-NULL)
//	** and sets pIter->base.pData/nData to point to the new position list.
//	** If memory is required for the new position list, use buffer pIter->poslist.
//	** Or, if the new position list is a contiguous subset of the input, set
//	** pIter->base.pData/nData to point directly to it.
//	**
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. If an OOM error is encountered, *pRc is set to SQLITE_NOMEM
//	** before returning.
//	*/
func _fts5IndexExtractColset(tls *libc.TLS, pRc uintptr, pColset uintptr, pPos uintptr, nPos int32, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aCopy, p, pEnd, v1, v2, v3 uintptr
	var i int32
	var _ /* iCurrent at bp+0 */ int32
	_, _, _, _, _, _, _ = aCopy, i, p, pEnd, v1, v2, v3
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		p = pPos
		aCopy = p
		pEnd = p + uintptr(nPos) /* One byte past end of position list */
		i = 0
		*(*int32)(unsafe.Pointer(bp)) = 0
		if (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol > int32(1) && _sqlite3Fts5BufferSize(tls, pRc, pIter+32, uint32(uint32(nPos))) != 0 {
			return
		}
		for int32(1) != 0 {
			for *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) < *(*int32)(unsafe.Pointer(bp)) {
				i++
				if i == (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol {
					(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
					(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
					return
				}
			}
			/* Advance pointer p until it points to pEnd or an 0x01 byte that is
			 ** not part of a varint */
			for p < pEnd && int32(*(*Tu8)(unsafe.Pointer(p))) != int32(0x01) {
				for {
					v1 = p
					p++
					if !(int32(*(*Tu8)(unsafe.Pointer(v1)))&int32(0x80) != 0) {
						break
					}
				}
			}
			if *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) == *(*int32)(unsafe.Pointer(bp)) {
				if (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol == int32(1) {
					(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = aCopy
					(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = int32(int32(p)) - int32(int32(aCopy))
					return
				}
				libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(pIter+32)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pIter+32)).Fn), aCopy, uint32(int32(int32(p))-int32(int32(aCopy))))
				*(*int32)(unsafe.Pointer(pIter + 32 + 4)) += int32(int32(p)) - int32(int32(aCopy))
			}
			if p >= pEnd {
				(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
				(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
				return
			}
			v2 = p
			p++
			aCopy = v2
			v3 = p
			p++
			*(*int32)(unsafe.Pointer(bp)) = int32(*(*Tu8)(unsafe.Pointer(v3)))
			if *(*int32)(unsafe.Pointer(bp))&int32(0x80) != 0 {
				p--
				p += uintptr(_sqlite3Fts5GetVarint32(tls, p, bp))
			}
		}
	}
}

// C documentation
//
//	/*
//	** xSetOutputs callback used by detail=none tables.
//	*/
func _fts5IterSetOutputs_None(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos
}

// C documentation
//
//	/*
//	** xSetOutputs callback used by detail=full and detail=col tables when no
//	** column filters are specified.
//	*/
func _fts5IterSetOutputs_Nocolset(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos
	if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset+int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos) <= int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf) {
		/* All data is stored on the current page. Populate the output
		 ** variables to point into the body of the page object. */
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
	} else {
		/* The data is distributed over two or more pages. Copy it into the
		 ** Fts5Iter.poslist buffer and then set the output pointer to point
		 ** to this buffer.  */
		_sqlite3Fts5BufferZero(tls, pIter+32)
		_fts5SegiterPoslist(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex, pSeg, uintptr(0), pIter+32)
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
	}
}

// C documentation
//
//	/*
//	** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
//	** against no columns at all).
//	*/
func _fts5IterSetOutputs_ZeroColset(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	_ = pSeg
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = 0
}

// C documentation
//
//	/*
//	** xSetOutputs callback used by detail=col when there is a column filter
//	** and there are 100 or more columns. Also called as a fallback from
//	** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
//	*/
func _fts5IterSetOutputs_Col(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	_sqlite3Fts5BufferZero(tls, pIter+32)
	_fts5SegiterPoslist(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex, pSeg, (*TFts5Iter)(unsafe.Pointer(pIter)).FpColset, pIter+32)
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
}

// C documentation
//
//	/*
//	** xSetOutputs callback used when:
//	**
//	**   * detail=col,
//	**   * there is a column filter, and
//	**   * the table contains 100 or fewer columns.
//	**
//	** The last point is to ensure all column numbers are stored as
//	** single-byte varints.
//	*/
func _fts5IterSetOutputs_Col100(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	var a, aOut, aiCol, aiColEnd, pEnd, v1, v2 uintptr
	var iPrev, iPrevOut int32
	_, _, _, _, _, _, _, _, _ = a, aOut, aiCol, aiColEnd, iPrev, iPrevOut, pEnd, v1, v2
	if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset+int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos) > int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf) {
		_fts5IterSetOutputs_Col(tls, pIter, pSeg)
	} else {
		a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
		pEnd = a + uintptr((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos)
		iPrev = 0
		aiCol = (*TFts5Iter)(unsafe.Pointer(pIter)).FpColset + 4
		aiColEnd = aiCol + uintptr((*TFts5Colset)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FpColset)).FnCol)*4
		aOut = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
		iPrevOut = 0
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
		for a < pEnd {
			v1 = a
			a++
			iPrev += int32(*(*Tu8)(unsafe.Pointer(v1))) - int32(2)
			for *(*int32)(unsafe.Pointer(aiCol)) < iPrev {
				aiCol += 4
				if aiCol == aiColEnd {
					goto setoutputs_col_out
				}
			}
			if *(*int32)(unsafe.Pointer(aiCol)) == iPrev {
				v2 = aOut
				aOut++
				*(*Tu8)(unsafe.Pointer(v2)) = uint8(iPrev - iPrevOut + libc.Int32FromInt32(2))
				iPrevOut = iPrev
			}
		}
		goto setoutputs_col_out
	setoutputs_col_out:
		;
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = int32(int32(aOut)) - int32((*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp)
	}
}

// C documentation
//
//	/*
//	** xSetOutputs callback used by detail=full when there is a column filter.
//	*/
func _fts5IterSetOutputs_Full(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	var a, pColset, pRc uintptr
	_, _, _ = a, pColset, pRc
	pColset = (*TFts5Iter)(unsafe.Pointer(pIter)).FpColset
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
	if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset+int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos) <= int64((*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf) {
		/* All data is stored on the current page. Populate the output
		 ** variables to point into the body of the page object. */
		a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
		pRc = (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex + 44
		_sqlite3Fts5BufferZero(tls, pIter+32)
		_fts5IndexExtractColset(tls, pRc, pColset, a, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos, pIter)
	} else {
		/* The data is distributed over two or more pages. Copy it into the
		 ** Fts5Iter.poslist buffer and then set the output pointer to point
		 ** to this buffer.  */
		_sqlite3Fts5BufferZero(tls, pIter+32)
		_fts5SegiterPoslist(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex, pSeg, pColset, pIter+32)
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
	}
}

func _fts5IterSetOutputCb(tls *libc.TLS, pRc uintptr, pIter uintptr) {
	var pConfig uintptr
	_ = pConfig
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		pConfig = (*TFts5Index)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex)).FpConfig
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
			(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = __ccgo_fp(_fts5IterSetOutputs_None)
		} else {
			if (*TFts5Iter)(unsafe.Pointer(pIter)).FpColset == uintptr(0) {
				(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = __ccgo_fp(_fts5IterSetOutputs_Nocolset)
			} else {
				if (*TFts5Colset)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FpColset)).FnCol == 0 {
					(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = __ccgo_fp(_fts5IterSetOutputs_ZeroColset)
				} else {
					if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_FULL {
						(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = __ccgo_fp(_fts5IterSetOutputs_Full)
					} else {
						if (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol <= int32(100) {
							(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = __ccgo_fp(_fts5IterSetOutputs_Col100)
							_sqlite3Fts5BufferSize(tls, pRc, pIter+32, uint32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol))
						} else {
							(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = __ccgo_fp(_fts5IterSetOutputs_Col)
						}
					}
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** All the component segment-iterators of pIter have been set up. This
//	** functions finishes setup for iterator pIter itself.
//	*/
func _fts5MultiIterFinishSetup(tls *libc.TLS, p uintptr, pIter uintptr) {
	var iEq, iIter, v2 int32
	var pSeg, pSeg1 uintptr
	_, _, _, _, _ = iEq, iIter, pSeg, pSeg1, v2
	iIter = (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg - int32(1)
	for {
		if !(iIter > 0) {
			break
		}
		v2 = _fts5MultiIterDoCompare(tls, pIter, iIter)
		iEq = v2
		if v2 != 0 {
			pSeg = pIter + 80 + uintptr(iEq)*104
			if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5SegIter)(unsafe.Pointer(pSeg)).FxNext})))(tls, p, pSeg, uintptr(0))
			}
			_fts5MultiIterAdvanced(tls, p, pIter, iEq, iIter)
		}
		goto _1
	_1:
		;
		iIter--
	}
	_fts5MultiIterSetEof(tls, pIter)
	if (*TFts5Iter)(unsafe.Pointer(pIter)).FbSkipEmpty != 0 && _fts5MultiIterIsEmpty(tls, p, pIter) != 0 || _fts5MultiIterIsDeleted(tls, pIter) != 0 {
		_fts5MultiIterNext(tls, p, pIter, 0, 0)
	} else {
		if int32((*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof) == 0 {
			pSeg1 = pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)*104
			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs})))(tls, pIter, pSeg1)
		}
	}
}

// C documentation
//
//	/*
//	** Allocate a new Fts5Iter object.
//	**
//	** The new object will be used to iterate through data in structure pStruct.
//	** If iLevel is -ve, then all data in all segments is merged. Or, if iLevel
//	** is zero or greater, data from the first nSegment segments on level iLevel
//	** is merged.
//	**
//	** The iterator initially points to the first term/rowid entry in the
//	** iterated data.
//	*/
func _fts5MultiIterNew(tls *libc.TLS, p uintptr, pStruct uintptr, flags int32, pColset uintptr, pTerm uintptr, nTerm int32, iLevel int32, nSegment int32, ppOut uintptr) {
	var iIter, iSeg, nSeg, v1, v3, v6, v8 int32
	var pEnd, pIter, pIter1, pLvl, pNew, pSeg, v2 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = iIter, iSeg, nSeg, pEnd, pIter, pIter1, pLvl, pNew, pSeg, v1, v2, v3, v6, v8
	nSeg = 0 /* Number of segment-iters in use */
	iIter = 0
	/* Allocate space for the new multi-seg-iterator. */
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if iLevel < 0 {
			nSeg = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment
			nSeg += libc.BoolInt32((*TFts5Index)(unsafe.Pointer(p)).FpHash != 0 && 0 == flags&int32(FTS5INDEX_QUERY_SKIPHASH))
		} else {
			if (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLevel)*12))).FnSeg < nSegment {
				v1 = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLevel)*12))).FnSeg
			} else {
				v1 = nSegment
			}
			nSeg = v1
		}
	}
	v2 = _fts5MultiIterAlloc(tls, p, nSeg)
	pNew = v2
	*(*uintptr)(unsafe.Pointer(ppOut)) = v2
	if pNew == uintptr(0) {
		goto fts5MultiIterNew_post_check
	}
	(*TFts5Iter)(unsafe.Pointer(pNew)).FbRev = libc.BoolInt32(0 != flags&int32(FTS5INDEX_QUERY_DESC))
	(*TFts5Iter)(unsafe.Pointer(pNew)).FbSkipEmpty = libc.BoolUint8(libc.Int32FromInt32(0) != flags&libc.Int32FromInt32(FTS5INDEX_QUERY_SKIPEMPTY))
	(*TFts5Iter)(unsafe.Pointer(pNew)).FpColset = pColset
	if flags&int32(FTS5INDEX_QUERY_NOOUTPUT) == 0 {
		_fts5IterSetOutputCb(tls, p+44, pNew)
	}
	/* Initialize each of the component segment iterators. */
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if iLevel < 0 {
			pEnd = pStruct + 32 + uintptr((*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel)*12
			if (*TFts5Index)(unsafe.Pointer(p)).FpHash != 0 && 0 == flags&int32(FTS5INDEX_QUERY_SKIPHASH) {
				v3 = iIter
				iIter++
				/* Add a segment iterator for the current contents of the hash table. */
				pIter = pNew + 80 + uintptr(v3)*104
				_fts5SegIterHashInit(tls, p, pTerm, nTerm, flags, pIter)
			}
			pLvl = pStruct + 32
			for {
				if !(pLvl < pEnd) {
					break
				}
				iSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg - int32(1)
				for {
					if !(iSeg >= 0) {
						break
					}
					pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56
					v6 = iIter
					iIter++
					pIter1 = pNew + 80 + uintptr(v6)*104
					if pTerm == uintptr(0) {
						_fts5SegIterInit(tls, p, pSeg, pIter1)
					} else {
						_fts5SegIterSeekInit(tls, p, pTerm, nTerm, flags, pSeg, pIter1)
					}
					goto _5
				_5:
					;
					iSeg--
				}
				goto _4
			_4:
				;
				pLvl += 12
			}
		} else {
			pLvl = pStruct + 32 + uintptr(iLevel)*12
			iSeg = nSeg - int32(1)
			for {
				if !(iSeg >= 0) {
					break
				}
				v8 = iIter
				iIter++
				_fts5SegIterInit(tls, p, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(iSeg)*56, pNew+80+uintptr(v8)*104)
				goto _7
			_7:
				;
				iSeg--
			}
		}
	}
	/* If the above was successful, each component iterator now points
	 ** to the first entry in its segment. In this case initialize the
	 ** aFirst[] array. Or, if an error has occurred, free the iterator
	 ** object and set the output variable to NULL.  */
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		_fts5MultiIterFinishSetup(tls, p, pNew)
	} else {
		_fts5MultiIterFree(tls, pNew)
		*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
	}
	goto fts5MultiIterNew_post_check
fts5MultiIterNew_post_check:
	;
	return
}

// C documentation
//
//	/*
//	** Create an Fts5Iter that iterates through the doclist provided
//	** as the second argument.
//	*/
func _fts5MultiIterNew2(tls *libc.TLS, p uintptr, pData uintptr, bDesc int32, ppOut uintptr) {
	var pIter, pNew uintptr
	_, _ = pIter, pNew
	pNew = _fts5MultiIterAlloc(tls, p, int32(2))
	if pNew != 0 {
		pIter = pNew + 80 + 1*104
		(*TFts5SegIter)(unsafe.Pointer(pIter)).Fflags = int32(FTS5_SEGITER_ONETERM)
		if (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf > 0 {
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pData
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp, pIter+88))
			(*TFts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*TFts5Data)(unsafe.Pointer(pData)).Fnn
			(*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pNew)).FaFirst + 1*4))).FiFirst = uint16(1)
			if bDesc != 0 {
				(*TFts5Iter)(unsafe.Pointer(pNew)).FbRev = int32(1)
				*(*int32)(unsafe.Pointer(pIter + 4)) |= int32(FTS5_SEGITER_REVERSE)
				_fts5SegIterReverseInitPage(tls, p, pIter)
			} else {
				_fts5SegIterLoadNPos(tls, p, pIter)
			}
			pData = uintptr(0)
		} else {
			(*TFts5Iter)(unsafe.Pointer(pNew)).Fbase.FbEof = uint8(1)
		}
		_fts5SegIterSetNext(tls, p, pIter)
		*(*uintptr)(unsafe.Pointer(ppOut)) = pNew
	}
	_fts5DataRelease(tls, pData)
}

// C documentation
//
//	/*
//	** Return true if the iterator is at EOF or if an error has occurred.
//	** False otherwise.
//	*/
func _fts5MultiIterEof(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	return libc.BoolInt32((*TFts5Index)(unsafe.Pointer(p)).Frc != 0 || (*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof != 0)
}

// C documentation
//
//	/*
//	** Return the rowid of the entry that the iterator currently points
//	** to. If the iterator points to EOF when this function is called the
//	** results are undefined.
//	*/
func _fts5MultiIterRowid(tls *libc.TLS, pIter uintptr) (r Ti64) {
	return (*(*TFts5SegIter)(unsafe.Pointer(pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)*104))).FiRowid
}

// C documentation
//
//	/*
//	** Move the iterator to the next entry at or following iMatch.
//	*/
func _fts5MultiIterNextFrom(tls *libc.TLS, p uintptr, pIter uintptr, iMatch Ti64) {
	var iRowid Ti64
	_ = iRowid
	for int32(1) != 0 {
		_fts5MultiIterNext(tls, p, pIter, int32(1), iMatch)
		if _fts5MultiIterEof(tls, p, pIter) != 0 {
			break
		}
		iRowid = _fts5MultiIterRowid(tls, pIter)
		if (*TFts5Iter)(unsafe.Pointer(pIter)).FbRev == 0 && iRowid >= iMatch {
			break
		}
		if (*TFts5Iter)(unsafe.Pointer(pIter)).FbRev != 0 && iRowid <= iMatch {
			break
		}
	}
}

// C documentation
//
//	/*
//	** Return a pointer to a buffer containing the term associated with the
//	** entry that the iterator currently points to.
//	*/
func _fts5MultiIterTerm(tls *libc.TLS, pIter uintptr, pn uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)*104
	*(*int32)(unsafe.Pointer(pn)) = (*TFts5SegIter)(unsafe.Pointer(p)).Fterm.Fn
	return (*TFts5SegIter)(unsafe.Pointer(p)).Fterm.Fp
}

// C documentation
//
//	/*
//	** Allocate a new segment-id for the structure pStruct. The new segment
//	** id must be between 1 and 65335 inclusive, and must not be used by
//	** any currently existing segment. If a free segment id cannot be found,
//	** SQLITE_FULL is returned.
//	**
//	** If an error has already occurred, this function is a no-op. 0 is
//	** returned in this case.
//	*/
func _fts5AllocateSegid(tls *libc.TLS, p uintptr, pStruct uintptr) (r int32) {
	bp := tls.Alloc(256)
	defer tls.Free(256)
	var i, iId, iLvl, iSeg, iSegid int32
	var mask Tu32
	var _ /* aUsed at bp+0 */ [63]Tu32
	_, _, _, _, _, _ = i, iId, iLvl, iSeg, iSegid, mask
	iSegid = 0
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment >= int32(FTS5_MAX_SEGMENT) {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_FULL)
		} else {
			libc.Xmemset(tls, bp, 0, uint32(252))
			iLvl = 0
			for {
				if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
					break
				}
				iSeg = 0
				for {
					if !(iSeg < (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FnSeg) {
						break
					}
					iId = (*(*TFts5StructureSegment)(unsafe.Pointer((*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FaSeg + uintptr(iSeg)*56))).FiSegid
					if iId <= int32(FTS5_MAX_SEGMENT) && iId > 0 {
						*(*Tu32)(unsafe.Pointer(bp + uintptr((iId-int32(1))/int32(32))*4)) |= libc.Uint32FromInt32(1) << ((iId - int32(1)) % int32(32))
					}
					goto _2
				_2:
					;
					iSeg++
				}
				goto _1
			_1:
				;
				iLvl++
			}
			i = 0
			for {
				if !((*(*[63]Tu32)(unsafe.Pointer(bp)))[i] == uint32(0xFFFFFFFF)) {
					break
				}
				goto _3
			_3:
				;
				i++
			}
			mask = (*(*[63]Tu32)(unsafe.Pointer(bp)))[i]
			iSegid = 0
			for {
				if !(mask&(libc.Uint32FromInt32(1)<<iSegid) != 0) {
					break
				}
				goto _4
			_4:
				;
				iSegid++
			}
			iSegid += int32(1) + i*int32(32)
		}
	}
	return iSegid
}

// C documentation
//
//	/*
//	** Discard all data currently cached in the hash-tables.
//	*/
func _fts5IndexDiscardData(tls *libc.TLS, p uintptr) {
	if (*TFts5Index)(unsafe.Pointer(p)).FpHash != 0 {
		_sqlite3Fts5HashClear(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash)
		(*TFts5Index)(unsafe.Pointer(p)).FnPendingData = 0
		(*TFts5Index)(unsafe.Pointer(p)).FnPendingRow = 0
		(*TFts5Index)(unsafe.Pointer(p)).FflushRc = SQLITE_OK
	}
	(*TFts5Index)(unsafe.Pointer(p)).FnContentlessDelete = 0
}

// C documentation
//
//	/*
//	** Return the size of the prefix, in bytes, that buffer
//	** (pNew/<length-unknown>) shares with buffer (pOld/nOld).
//	**
//	** Buffer (pNew/<length-unknown>) is guaranteed to be greater
//	** than buffer (pOld/nOld).
//	*/
func _fts5PrefixCompress(tls *libc.TLS, nOld int32, pOld uintptr, pNew uintptr) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < nOld) {
			break
		}
		if int32(*(*Tu8)(unsafe.Pointer(pOld + uintptr(i)))) != int32(*(*Tu8)(unsafe.Pointer(pNew + uintptr(i)))) {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	return i
}

func _fts5WriteDlidxClear(tls *libc.TLS, p uintptr, pWriter uintptr, bFlush int32) {
	var i int32
	var pDlidx uintptr
	_, _ = i, pDlidx
	i = 0
	for {
		if !(i < (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx) {
			break
		}
		pDlidx = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx + uintptr(i)*32
		if (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn == 0 {
			break
		}
		if bFlush != 0 {
			_fts5DataWrite(tls, p, int64((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(i)<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno), (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fp, (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn)
		}
		_sqlite3Fts5BufferZero(tls, pDlidx+16)
		(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid = 0
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Grow the pWriter->aDlidx[] array to at least nLvl elements in size.
//	** Any new array elements are zeroed before returning.
//	*/
func _fts5WriteDlidxGrow(tls *libc.TLS, p uintptr, pWriter uintptr, nLvl int32) (r int32) {
	var aDlidx uintptr
	var nByte Tsize_t
	_, _ = aDlidx, nByte
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && nLvl >= (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx {
		aDlidx = Xsqlite3_realloc64(tls, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx, uint64(uint32(32)*uint32(uint32(nLvl))))
		if aDlidx == uintptr(0) {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		} else {
			nByte = uint32(32) * uint32(nLvl-(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx)
			libc.Xmemset(tls, aDlidx+uintptr((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx)*32, 0, nByte)
			(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx = aDlidx
			(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx = nLvl
		}
	}
	return (*TFts5Index)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** If the current doclist-index accumulating in pWriter->aDlidx[] is large
//	** enough, flush it to disk and return 1. Otherwise discard it and return
//	** zero.
//	*/
func _fts5WriteFlushDlidx(tls *libc.TLS, p uintptr, pWriter uintptr) (r int32) {
	var bFlag int32
	_ = bFlag
	bFlag = 0
	/* If there were FTS5_MIN_DLIDX_SIZE or more empty leaf pages written
	 ** to the database, also write the doclist-index to disk.  */
	if (*(*TFts5DlidxWriter)(unsafe.Pointer((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx))).Fbuf.Fn > 0 && (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnEmpty >= int32(FTS5_MIN_DLIDX_SIZE) {
		bFlag = int32(1)
	}
	_fts5WriteDlidxClear(tls, p, pWriter, bFlag)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnEmpty = 0
	return bFlag
}

// C documentation
//
//	/*
//	** This function is called whenever processing of the doclist for the
//	** last term on leaf page (pWriter->iBtPage) is completed.
//	**
//	** The doclist-index for that term is currently stored in-memory within the
//	** Fts5SegWriter.aDlidx[] array. If it is large enough, this function
//	** writes it out to disk. Or, if it is too small to bother with, discards
//	** it.
//	**
//	** Fts5SegWriter.btterm currently contains the first term on page iBtPage.
//	*/
func _fts5WriteFlushBtree(tls *libc.TLS, p uintptr, pWriter uintptr) {
	var bFlag int32
	var z, v1 uintptr
	_, _, _ = bFlag, z, v1
	if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage == 0 {
		return
	}
	bFlag = _fts5WriteFlushDlidx(tls, p, pWriter)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn > 0 {
			v1 = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fp
		} else {
			v1 = __ccgo_ts + 1672
		}
		z = v1
		/* The following was already done in fts5WriteInit(): */
		/* sqlite3_bind_int(p->pIdxWriter, 1, pWriter->iSegid); */
		Xsqlite3_bind_blob(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(2), z, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn, libc.UintptrFromInt32(0))
		Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(3), int64(int64(bFlag))+int64((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage)<<libc.Int32FromInt32(1))
		Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		Xsqlite3_bind_null(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(2))
	}
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = 0
}

// C documentation
//
//	/*
//	** This is called once for each leaf page except the first that contains
//	** at least one term. Argument (nTerm/pTerm) is the split-key - a term that
//	** is larger than all terms written to earlier leaves, and equal to or
//	** smaller than the first term on the new leaf.
//	**
//	** If an error occurs, an error code is left in Fts5Index.rc. If an error
//	** has already occurred when this function is called, it is a no-op.
//	*/
func _fts5WriteBtreeTerm(tls *libc.TLS, p uintptr, pWriter uintptr, nTerm int32, pTerm uintptr) {
	_fts5WriteFlushBtree(tls, p, pWriter)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		_sqlite3Fts5BufferSet(tls, p+44, pWriter+76, nTerm, pTerm)
		(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno
	}
}

// C documentation
//
//	/*
//	** This function is called when flushing a leaf page that contains no
//	** terms at all to disk.
//	*/
func _fts5WriteBtreeNoTerm(tls *libc.TLS, p uintptr, pWriter uintptr) {
	var pDlidx uintptr
	_ = pDlidx
	/* If there were no rowids on the leaf page either and the doclist-index
	 ** has already been started, append an 0x00 byte to it.  */
	if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage != 0 && (*(*TFts5DlidxWriter)(unsafe.Pointer((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx))).Fbuf.Fn > 0 {
		pDlidx = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx
		_sqlite3Fts5BufferAppendVarint(tls, p+44, pDlidx+16, 0)
	}
	/* Increment the "number of sequential leaves without a term" counter. */
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnEmpty++
}

func _fts5DlidxExtractFirstRowid(tls *libc.TLS, pBuf uintptr) (r Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iOff int32
	var _ /* iRowid at bp+0 */ Ti64
	_ = iOff
	iOff = int32(1) + int32(_sqlite3Fts5GetVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+1, bp))
	_sqlite3Fts5GetVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr(iOff), bp)
	return *(*Ti64)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Rowid iRowid has just been appended to the current leaf page. It is the
//	** first on the page. This function appends an appropriate entry to the current
//	** doclist-index.
//	*/
func _fts5WriteDlidxAppend(tls *libc.TLS, p uintptr, pWriter uintptr, iRowid Ti64) {
	var bDone, i, v2 int32
	var iFirst, iPgno, iVal Ti64
	var pDlidx uintptr
	_, _, _, _, _, _, _ = bDone, i, iFirst, iPgno, iVal, pDlidx, v2
	bDone = 0
	i = 0
	for {
		if !((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bDone == 0) {
			break
		}
		pDlidx = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx + uintptr(i)*32
		if (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn >= (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
			/* The current doclist-index page is full. Write it to disk and push
			 ** a copy of iRowid (which will become the first rowid on the next
			 ** doclist-index leaf page) up into the next level of the b-tree
			 ** hierarchy. If the node being flushed is currently the root node,
			 ** also push its first rowid upwards. */
			*(*Tu8)(unsafe.Pointer((*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fp)) = uint8(0x01) /* Not the root node */
			_fts5DataWrite(tls, p, int64((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(i)<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno), (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fp, (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn)
			_fts5WriteDlidxGrow(tls, p, pWriter, i+int32(2))
			pDlidx = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx + uintptr(i)*32
			if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx + 1*32))).Fbuf.Fn == 0 {
				iFirst = _fts5DlidxExtractFirstRowid(tls, pDlidx+16)
				/* This was the root node. Push its first rowid up to the new root. */
				(*(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx + 1*32))).Fpgno = (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno
				_sqlite3Fts5BufferAppendVarint(tls, p+44, pDlidx+1*32+16, 0)
				_sqlite3Fts5BufferAppendVarint(tls, p+44, pDlidx+1*32+16, int64((*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno))
				_sqlite3Fts5BufferAppendVarint(tls, p+44, pDlidx+1*32+16, iFirst)
				(*(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx + 1*32))).FbPrevValid = int32(1)
				(*(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx + 1*32))).FiPrev = iFirst
			}
			_sqlite3Fts5BufferZero(tls, pDlidx+16)
			(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid = 0
			(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno++
		} else {
			bDone = int32(1)
		}
		if (*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid != 0 {
			iVal = int64(uint64(uint64(iRowid)) - uint64((*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).FiPrev))
		} else {
			if i == 0 {
				v2 = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno
			} else {
				v2 = (*(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx + uintptr(-libc.Int32FromInt32(1))*32))).Fpgno
			}
			iPgno = int64(v2)
			_sqlite3Fts5BufferAppendVarint(tls, p+44, pDlidx+16, libc.BoolInt64(!(bDone != 0)))
			_sqlite3Fts5BufferAppendVarint(tls, p+44, pDlidx+16, iPgno)
			iVal = iRowid
		}
		_sqlite3Fts5BufferAppendVarint(tls, p+44, pDlidx+16, iVal)
		(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid = int32(1)
		(*TFts5DlidxWriter)(unsafe.Pointer(pDlidx)).FiPrev = iRowid
		goto _1
	_1:
		;
		i++
	}
}

func _fts5WriteFlushLeaf(tls *libc.TLS, p uintptr, pWriter uintptr) {
	var iRowid Ti64
	var pPage uintptr
	_, _ = iRowid, pPage
	pPage = pWriter + 4
	/* Set the szLeaf header field. */
	_fts5PutU16(tls, (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fp+2, uint16((*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn))
	if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage != 0 {
		/* No term was written to this page. */
		_fts5WriteBtreeNoTerm(tls, p, pWriter)
	} else {
		/* Append the pgidx to the page buffer. Set the szLeaf header field. */
		_sqlite3Fts5BufferAppendBlob(tls, p+44, pPage+8, uint32((*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn), (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fp)
	}
	/* Write the page out to disk */
	iRowid = int64((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64((*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgno)
	_fts5DataWrite(tls, p, iRowid, (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fp, (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn)
	/* Initialize the next page. */
	_sqlite3Fts5BufferZero(tls, pPage+8)
	_sqlite3Fts5BufferZero(tls, pPage+20)
	_sqlite3Fts5BufferAppendBlob(tls, p+44, pPage+8, uint32(4), uintptr(unsafe.Pointer(&_zero)))
	(*TFts5PageWriter)(unsafe.Pointer(pPage)).FiPrevPgidx = 0
	(*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgno++
	/* Increase the leaves written counter */
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnLeafWritten++
	/* The new leaf holds no terms or rowids */
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = uint8(1)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage = uint8(1)
}

var _zero = [4]Tu8{}

// C documentation
//
//	/*
//	** Append term pTerm/nTerm to the segment being written by the writer passed
//	** as the second argument.
//	**
//	** If an error occurs, set the Fts5Index.rc error code. If an error has
//	** already occurred, this function is a no-op.
//	*/
func _fts5WriteAppendTerm(tls *libc.TLS, p uintptr, pWriter uintptr, nTerm int32, pTerm uintptr) {
	var n, nMin, nPrefix, v1 int32
	var pPage, pPgidx uintptr
	_, _, _, _, _, _ = n, nMin, nPrefix, pPage, pPgidx, v1 /* Bytes of prefix compression for term */
	pPage = pWriter + 4
	pPgidx = pWriter + 4 + 20
	if (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fn < nTerm {
		v1 = (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fn
	} else {
		v1 = nTerm
	}
	nMin = v1
	/* If the current leaf page is full, flush it to disk. */
	if (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn+nTerm+int32(2) >= (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
		if (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn > int32(4) {
			_fts5WriteFlushLeaf(tls, p, pWriter)
			if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return
			}
		}
		if !(uint32((*TFts5Buffer)(unsafe.Pointer(pPage+8)).Fn)+uint32(nTerm+libc.Int32FromInt32(FTS5_DATA_PADDING)) <= uint32((*TFts5Buffer)(unsafe.Pointer(pPage+8)).FnSpace)) {
			_sqlite3Fts5BufferSize(tls, p+44, pPage+8, uint32(nTerm+int32(FTS5_DATA_PADDING)+(*TFts5Buffer)(unsafe.Pointer(pPage+8)).Fn))
		}
	}
	/* TODO1: Updating pgidx here. */
	*(*int32)(unsafe.Pointer(pPgidx + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn), uint64((*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn-(*TFts5PageWriter)(unsafe.Pointer(pPage)).FiPrevPgidx))
	(*TFts5PageWriter)(unsafe.Pointer(pPage)).FiPrevPgidx = (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn
	if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage != 0 {
		nPrefix = 0
		if (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgno != int32(1) {
			/* This is the first term on a leaf that is not the leftmost leaf in
			 ** the segment b-tree. In this case it is necessary to add a term to
			 ** the b-tree hierarchy that is (a) larger than the largest term
			 ** already written to the segment and (b) smaller than or equal to
			 ** this term. In other words, a prefix of (pTerm/nTerm) that is one
			 ** byte longer than the longest prefix (pTerm/nTerm) shares with the
			 ** previous term.
			 **
			 ** Usually, the previous term is available in pPage->term. The exception
			 ** is if this is the first term written in an incremental-merge step.
			 ** In this case the previous term is not available, so just write a
			 ** copy of (pTerm/nTerm) into the parent node. This is slightly
			 ** inefficient, but still correct.  */
			n = nTerm
			if (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fn != 0 {
				n = int32(1) + _fts5PrefixCompress(tls, nMin, (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fp, pTerm)
			}
			_fts5WriteBtreeTerm(tls, p, pWriter, n, pTerm)
			if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return
			}
			pPage = pWriter + 4
		}
	} else {
		nPrefix = _fts5PrefixCompress(tls, nMin, (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fp, pTerm)
		_sqlite3Fts5BufferAppendVarint(tls, p+44, pPage+8, int64(int64(nPrefix)))
	}
	/* Append the number of bytes of new data, then the term data itself
	 ** to the page. */
	_sqlite3Fts5BufferAppendVarint(tls, p+44, pPage+8, int64(int64(nTerm))-int64(int64(nPrefix)))
	_sqlite3Fts5BufferAppendBlob(tls, p+44, pPage+8, uint32(nTerm-nPrefix), pTerm+uintptr(nPrefix))
	/* Update the Fts5PageWriter.term field. */
	_sqlite3Fts5BufferSet(tls, p+44, pPage+32, nTerm, pTerm)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = uint8(0)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage = uint8(0)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInDoclist = uint8(1)
	(*(*TFts5DlidxWriter)(unsafe.Pointer((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx))).Fpgno = (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgno
}

// C documentation
//
//	/*
//	** Append a rowid and position-list size field to the writers output.
//	*/
func _fts5WriteAppendRowid(tls *libc.TLS, p uintptr, pWriter uintptr, iRowid Ti64) {
	var pPage uintptr
	_ = pPage
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pPage = pWriter + 4
		if (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn+(*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn >= (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
			_fts5WriteFlushLeaf(tls, p, pWriter)
		}
		/* If this is to be the first rowid written to the page, set the
		 ** rowid-pointer in the page-header. Also append a value to the dlidx
		 ** buffer, in case a doclist-index is required.  */
		if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage != 0 {
			_fts5PutU16(tls, (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fp, uint16((*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn))
			_fts5WriteDlidxAppend(tls, p, pWriter, iRowid)
		}
		/* Write the rowid. */
		if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInDoclist != 0 || (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage != 0 {
			_sqlite3Fts5BufferAppendVarint(tls, p+44, pPage+8, iRowid)
		} else {
			_sqlite3Fts5BufferAppendVarint(tls, p+44, pPage+8, int64(uint64(int64(uint64(uint64(iRowid))))-uint64((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiPrevRowid)))
		}
		(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiPrevRowid = iRowid
		(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInDoclist = uint8(0)
		(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage = uint8(0)
	}
}

func _fts5WriteAppendPoslistData(tls *libc.TLS, p uintptr, pWriter uintptr, aData uintptr, nData int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, pPage uintptr
	var n, nCopy, nReq int32
	var _ /* dummy at bp+0 */ Ti64
	_, _, _, _, _ = a, n, nCopy, nReq, pPage
	pPage = pWriter + 4
	a = aData
	n = nData
	for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn+(*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn+n >= (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
		nReq = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz - (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn - (*TFts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn
		nCopy = 0
		for nCopy < nReq {
			nCopy += int32(_sqlite3Fts5GetVarint(tls, a+uintptr(nCopy), bp))
		}
		_sqlite3Fts5BufferAppendBlob(tls, p+44, pPage+8, uint32(uint32(nCopy)), a)
		a += uintptr(nCopy)
		n -= nCopy
		_fts5WriteFlushLeaf(tls, p, pWriter)
	}
	if n > 0 {
		_sqlite3Fts5BufferAppendBlob(tls, p+44, pPage+8, uint32(uint32(n)), a)
	}
}

// C documentation
//
//	/*
//	** Flush any data cached by the writer object to the database. Free any
//	** allocations associated with the writer.
//	*/
func _fts5WriteFinish(tls *libc.TLS, p uintptr, pWriter uintptr, pnLeaf uintptr) {
	var i int32
	var pLeaf uintptr
	_, _ = i, pLeaf
	pLeaf = pWriter + 4
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5PageWriter)(unsafe.Pointer(pLeaf)).Fbuf.Fn > int32(4) {
			_fts5WriteFlushLeaf(tls, p, pWriter)
		}
		*(*int32)(unsafe.Pointer(pnLeaf)) = (*TFts5PageWriter)(unsafe.Pointer(pLeaf)).Fpgno - int32(1)
		if (*TFts5PageWriter)(unsafe.Pointer(pLeaf)).Fpgno > int32(1) {
			_fts5WriteFlushBtree(tls, p, pWriter)
		}
	}
	_sqlite3Fts5BufferFree(tls, pLeaf+32)
	_sqlite3Fts5BufferFree(tls, pLeaf+8)
	_sqlite3Fts5BufferFree(tls, pLeaf+20)
	_sqlite3Fts5BufferFree(tls, pWriter+76)
	i = 0
	for {
		if !(i < (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx) {
			break
		}
		_sqlite3Fts5BufferFree(tls, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx+uintptr(i)*32+16)
		goto _1
	_1:
		;
		i++
	}
	Xsqlite3_free(tls, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx)
}

func _fts5WriteInit(tls *libc.TLS, p uintptr, pWriter uintptr, iSegid int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nBuffer int32
	var pConfig uintptr
	_, _ = nBuffer, pConfig
	nBuffer = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz + int32(FTS5_DATA_PADDING)
	libc.Xmemset(tls, pWriter, 0, uint32(96))
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid = iSegid
	_fts5WriteDlidxGrow(tls, p, pWriter, int32(1))
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno = int32(1)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = uint8(1)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = int32(1)
	/* Grow the two buffers to pgsz + padding bytes in size. */
	_sqlite3Fts5BufferSize(tls, p+44, pWriter+4+20, uint32(uint32(nBuffer)))
	_sqlite3Fts5BufferSize(tls, p+44, pWriter+4+8, uint32(uint32(nBuffer)))
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+37985, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		/* Initialize the 4-byte leaf-page header to 0x00. */
		libc.Xmemset(tls, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fp, 0, uint32(4))
		(*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fn = int32(4)
		/* Bind the current output segment id to the index-writer. This is an
		 ** optimization over binding the same value over and over as rows are
		 ** inserted into %_idx by the current writer.  */
		Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(1), (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)
	}
}

// C documentation
//
//	/*
//	** Iterator pIter was used to iterate through the input segments of on an
//	** incremental merge operation. This function is called if the incremental
//	** merge step has finished but the input has not been completely exhausted.
//	*/
func _fts5TrimSegments(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iId, iOff, nDiff int32
	var iLeafRowid Ti64
	var pData, pSeg uintptr
	var _ /* aHdr at bp+12 */ [4]Tu8
	var _ /* buf at bp+0 */ TFts5Buffer
	_, _, _, _, _, _, _ = i, iId, iLeafRowid, iOff, nDiff, pData, pSeg
	libc.Xmemset(tls, bp, 0, uint32(12))
	i = 0
	for {
		if !(i < (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg && (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
			break
		}
		pSeg = pIter + 80 + uintptr(i)*104
		if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg == uintptr(0) {
			/* no-op */
		} else {
			if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf == uintptr(0) {
				/* All keys from this input segment have been transfered to the output.
				 ** Set both the first and last page-numbers to 0 to indicate that the
				 ** segment is now empty. */
				(*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoLast = 0
				(*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoFirst = 0
			} else {
				iOff = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset
				iId = (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FiSegid
				*(*[4]Tu8)(unsafe.Pointer(bp + 12)) = [4]Tu8{}
				iLeafRowid = int64(iId)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno)
				pData = _fts5LeafRead(tls, p, iLeafRowid)
				if pData != 0 {
					if iOff > (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf {
						/* This can occur if the pages that the segments occupy overlap - if
						 ** a single page has been assigned to more than one segment. In
						 ** this case a prior iteration of this loop may have corrupted the
						 ** segment currently being trimmed.  */
						(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					} else {
						_sqlite3Fts5BufferZero(tls, bp)
						if !(uint32((*TFts5Buffer)(unsafe.Pointer(bp)).Fn)+uint32((*TFts5Data)(unsafe.Pointer(pData)).Fnn) <= uint32((*TFts5Buffer)(unsafe.Pointer(bp)).FnSpace)) {
							_sqlite3Fts5BufferSize(tls, p+44, bp, uint32((*TFts5Data)(unsafe.Pointer(pData)).Fnn+(*TFts5Buffer)(unsafe.Pointer(bp)).Fn))
						}
						_sqlite3Fts5BufferAppendBlob(tls, p+44, bp, uint32(4), bp+12)
						_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn))
						_sqlite3Fts5BufferAppendBlob(tls, p+44, bp, uint32((*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn), (*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp)
						_sqlite3Fts5BufferAppendBlob(tls, p+44, bp, uint32((*TFts5Data)(unsafe.Pointer(pData)).FszLeaf-iOff), (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr(iOff))
						if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							/* Set the szLeaf field */
							_fts5PutU16(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp+2, uint16((*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn))
						}
						/* Set up the new page-index array */
						_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, libc.Int64FromInt32(4))
						if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist < (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff <= (*TFts5Data)(unsafe.Pointer(pData)).Fnn {
							nDiff = (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf - (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist
							_sqlite3Fts5BufferAppendVarint(tls, p+44, bp, int64((*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn)-int64(1)-int64(int64(nDiff))-int64(4))
							_sqlite3Fts5BufferAppendBlob(tls, p+44, bp, uint32((*TFts5Data)(unsafe.Pointer(pData)).Fnn-(*TFts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff), (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff))
						}
						(*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoFirst = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno
						_fts5DataDelete(tls, p, int64(iId)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(libc.Int32FromInt32(1)), iLeafRowid)
						_fts5DataWrite(tls, p, iLeafRowid, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn)
					}
					_fts5DataRelease(tls, pData)
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	_sqlite3Fts5BufferFree(tls, bp)
}

func _fts5MergeChunkCallback(tls *libc.TLS, p uintptr, pCtx uintptr, pChunk uintptr, nChunk int32) {
	var pWriter uintptr
	_ = pWriter
	pWriter = pCtx
	_fts5WriteAppendPoslistData(tls, p, pWriter, pChunk, nChunk)
}

// C documentation
//
//	/*
//	**
//	*/
func _fts5IndexMergeLevel(tls *libc.TLS, p uintptr, ppStruct uintptr, iLvl int32, pnRem uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var bOldest, bTermWritten, eDetail, flags, i, iSegid, nInput, nMove, nPos, nRem, v1, v3 int32
	var pLvl, pLvlOut, pOld, pSeg, pSegIter, pStruct, pTerm uintptr
	var v4 bool
	var _ /* nTerm at bp+116 */ int32
	var _ /* pIter at bp+0 */ uintptr
	var _ /* term at bp+104 */ TFts5Buffer
	var _ /* writer at bp+8 */ TFts5SegWriter
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bOldest, bTermWritten, eDetail, flags, i, iSegid, nInput, nMove, nPos, nRem, pLvl, pLvlOut, pOld, pSeg, pSegIter, pStruct, pTerm, v1, v3, v4
	pStruct = *(*uintptr)(unsafe.Pointer(ppStruct))
	pLvl = pStruct + 32 + uintptr(iLvl)*12
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	if pnRem != 0 {
		v1 = *(*int32)(unsafe.Pointer(pnRem))
	} else {
		v1 = 0
	} /* Iterator to read input data */
	nRem = v1 /* True if the output segment is the oldest */
	eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
	flags = int32(FTS5INDEX_QUERY_NOOUTPUT)
	bTermWritten = 0 /* True if current term already output */
	libc.Xmemset(tls, bp+8, 0, uint32(96))
	libc.Xmemset(tls, bp+104, 0, uint32(12))
	if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
		pLvlOut = pStruct + 32 + uintptr(iLvl+int32(1))*12
		nInput = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge
		pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FaSeg + uintptr((*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg-int32(1))*56
		_fts5WriteInit(tls, p, bp+8, (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
		(*(*TFts5SegWriter)(unsafe.Pointer(bp + 8))).Fwriter.Fpgno = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast + int32(1)
		(*(*TFts5SegWriter)(unsafe.Pointer(bp + 8))).FiBtPage = 0
	} else {
		iSegid = _fts5AllocateSegid(tls, p, pStruct)
		/* Extend the Fts5Structure object as required to ensure the output
		 ** segment exists. */
		if iLvl == (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel-int32(1) {
			_fts5StructureAddLevel(tls, p+44, ppStruct)
			pStruct = *(*uintptr)(unsafe.Pointer(ppStruct))
		}
		_fts5StructureExtendLevel(tls, p+44, pStruct, iLvl+int32(1), int32(1), 0)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
		pLvl = pStruct + 32 + uintptr(iLvl)*12
		pLvlOut = pStruct + 32 + uintptr(iLvl+int32(1))*12
		_fts5WriteInit(tls, p, bp+8, iSegid)
		/* Add the new segment to the output level */
		pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FaSeg + uintptr((*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg)*56
		(*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg++
		(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst = int32(1)
		(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid = iSegid
		(*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment++
		/* Read input from all segments in the input level */
		nInput = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg
		/* Set the range of origins that will go into the output segment. */
		if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
			(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1 = (*(*TFts5StructureSegment)(unsafe.Pointer((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg))).FiOrigin1
			(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2 = (*(*TFts5StructureSegment)(unsafe.Pointer((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg-int32(1))*56))).FiOrigin2
		}
	}
	bOldest = libc.BoolInt32((*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg == int32(1) && (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel == iLvl+int32(2))
	_fts5MultiIterNew(tls, p, pStruct, flags, uintptr(0), uintptr(0), 0, iLvl, nInput, bp)
	for {
		if !(_fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp))) == 0) {
			break
		}
		pSegIter = *(*uintptr)(unsafe.Pointer(bp)) + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFirst + 1*4))).FiFirst)*104
		pTerm = _fts5MultiIterTerm(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+116)
		if v4 = *(*int32)(unsafe.Pointer(bp + 116)) != (*(*TFts5Buffer)(unsafe.Pointer(bp + 104))).Fn; !v4 {
			if *(*int32)(unsafe.Pointer(bp + 116)) <= 0 {
				v3 = 0
			} else {
				v3 = libc.Xmemcmp(tls, pTerm, (*(*TFts5Buffer)(unsafe.Pointer(bp + 104))).Fp, uint32(*(*int32)(unsafe.Pointer(bp + 116))))
			}
		}
		if v4 || v3 != 0 {
			if pnRem != 0 && (*(*TFts5SegWriter)(unsafe.Pointer(bp + 8))).FnLeafWritten > nRem {
				break
			}
			_sqlite3Fts5BufferSet(tls, p+44, bp+104, *(*int32)(unsafe.Pointer(bp + 116)), pTerm)
			bTermWritten = 0
		}
		/* Check for key annihilation. */
		if (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FnPos == 0 && (bOldest != 0 || int32((*TFts5SegIter)(unsafe.Pointer(pSegIter)).FbDel) == 0) {
			goto _2
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bTermWritten == 0 {
			/* This is a new term. Append a term to the output segment. */
			_fts5WriteAppendTerm(tls, p, bp+8, *(*int32)(unsafe.Pointer(bp + 116)), pTerm)
			bTermWritten = int32(1)
		}
		/* Append the rowid to the output */
		/* WRITEPOSLISTSIZE */
		_fts5WriteAppendRowid(tls, p, bp+8, _fts5MultiIterRowid(tls, *(*uintptr)(unsafe.Pointer(bp))))
		if eDetail == int32(FTS5_DETAIL_NONE) {
			if (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FbDel != 0 {
				_sqlite3Fts5BufferAppendVarint(tls, p+44, bp+8+4+8, libc.Int64FromInt32(0))
				if (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FnPos > 0 {
					_sqlite3Fts5BufferAppendVarint(tls, p+44, bp+8+4+8, libc.Int64FromInt32(0))
				}
			}
		} else {
			/* Append the position-list data to the output */
			nPos = (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FnPos*int32(2) + int32((*TFts5SegIter)(unsafe.Pointer(pSegIter)).FbDel)
			_sqlite3Fts5BufferAppendVarint(tls, p+44, bp+8+4+8, int64(int64(nPos)))
			_fts5ChunkIterate(tls, p, pSegIter, bp+8, __ccgo_fp(_fts5MergeChunkCallback))
		}
		goto _2
	_2:
		;
		_fts5MultiIterNext(tls, p, *(*uintptr)(unsafe.Pointer(bp)), 0, 0)
	}
	/* Flush the last leaf page to disk. Set the output segment b-tree height
	 ** and last leaf page number at the same time.  */
	_fts5WriteFinish(tls, p, bp+8, pSeg+8)
	if _fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp))) != 0 {
		/* Remove the redundant segments from the %_data table */
		i = 0
		for {
			if !(i < nInput) {
				break
			}
			pOld = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(i)*56
			*(*Tu64)(unsafe.Pointer(pSeg + 48)) += (*TFts5StructureSegment)(unsafe.Pointer(pOld)).FnEntry - (*TFts5StructureSegment)(unsafe.Pointer(pOld)).FnEntryTombstone
			_fts5DataRemoveSegment(tls, p, pOld)
			goto _5
		_5:
			;
			i++
		}
		/* Remove the redundant segments from the input level */
		if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg != nInput {
			nMove = int32(uint32((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg-nInput) * uint32(56))
			libc.Xmemmove(tls, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(nInput)*56, uint32(uint32(nMove)))
		}
		*(*int32)(unsafe.Pointer(pStruct + 24)) -= nInput
		*(*int32)(unsafe.Pointer(pLvl + 4)) -= nInput
		(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge = 0
		if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast == 0 {
			(*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg--
			(*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment--
		}
	} else {
		_fts5TrimSegments(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge = nInput
	}
	_fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	_sqlite3Fts5BufferFree(tls, bp+104)
	if pnRem != 0 {
		*(*int32)(unsafe.Pointer(pnRem)) -= (*(*TFts5SegWriter)(unsafe.Pointer(bp + 8))).FnLeafWritten
	}
}

// C documentation
//
//	/*
//	** If this is not a contentless_delete=1 table, or if the 'deletemerge'
//	** configuration option is set to 0, then this function always returns -1.
//	** Otherwise, it searches the structure object passed as the second argument
//	** for a level suitable for merging due to having a large number of
//	** tombstones in the tombstone hash. If one is found, its index is returned.
//	** Otherwise, if there is no suitable level, -1.
//	*/
func _fts5IndexFindDeleteMerge(tls *libc.TLS, p uintptr, pStruct uintptr) (r int32) {
	var iRet, iSeg, ii, nBest, nPercent int32
	var nEntry, nTomb Ti64
	var pConfig, pLvl uintptr
	_, _, _, _, _, _, _, _, _ = iRet, iSeg, ii, nBest, nEntry, nPercent, nTomb, pConfig, pLvl
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
	iRet = -int32(1)
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge > 0 {
		nBest = 0
		ii = 0
		for {
			if !(ii < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
				break
			}
			pLvl = pStruct + 32 + uintptr(ii)*12
			nEntry = 0
			nTomb = 0
			iSeg = 0
			for {
				if !(iSeg < (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg) {
					break
				}
				nEntry = Ti64(uint64(nEntry) + (*(*TFts5StructureSegment)(unsafe.Pointer((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56))).FnEntry)
				nTomb = Ti64(uint64(nTomb) + (*(*TFts5StructureSegment)(unsafe.Pointer((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56))).FnEntryTombstone)
				goto _2
			_2:
				;
				iSeg++
			}
			if nEntry > 0 {
				nPercent = int32(nTomb * int64(100) / nEntry)
				if nPercent >= (*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge && nPercent > nBest {
					iRet = ii
					nBest = nPercent
				}
			}
			goto _1
		_1:
			;
			ii++
		}
	}
	return iRet
}

// C documentation
//
//	/*
//	** Do up to nPg pages of automerge work on the index.
//	**
//	** Return true if any changes were actually made, or false otherwise.
//	*/
func _fts5IndexMerge(tls *libc.TLS, p uintptr, ppStruct uintptr, nPg int32, nMin int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bRet, iBestLvl, iLvl, nBest int32
	var pLvl uintptr
	var _ /* nRem at bp+0 */ int32
	var _ /* pStruct at bp+4 */ uintptr
	_, _, _, _, _ = bRet, iBestLvl, iLvl, nBest, pLvl
	*(*int32)(unsafe.Pointer(bp)) = nPg
	bRet = 0
	*(*uintptr)(unsafe.Pointer(bp + 4)) = *(*uintptr)(unsafe.Pointer(ppStruct))
	for *(*int32)(unsafe.Pointer(bp)) > 0 && (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK { /* To iterate through levels */
		iBestLvl = 0 /* Level offering the most input segments */
		nBest = 0    /* Number of input segments on best level */
		/* Set iBestLvl to the level to read input segments from. Or to -1 if
		 ** there is no level suitable to merge segments from.  */
		iLvl = 0
		for {
			if !(iLvl < (*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FnLevel) {
				break
			}
			pLvl = *(*uintptr)(unsafe.Pointer(bp + 4)) + 32 + uintptr(iLvl)*12
			if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
				if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge > nBest {
					iBestLvl = iLvl
					nBest = nMin
				}
				break
			}
			if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg > nBest {
				nBest = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg
				iBestLvl = iLvl
			}
			goto _1
		_1:
			;
			iLvl++
		}
		if nBest < nMin {
			iBestLvl = _fts5IndexFindDeleteMerge(tls, p, *(*uintptr)(unsafe.Pointer(bp + 4)))
		}
		if iBestLvl < 0 {
			break
		}
		bRet = int32(1)
		_fts5IndexMergeLevel(tls, p, bp+4, iBestLvl, bp)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*(*TFts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)) + 32 + uintptr(iBestLvl)*12))).FnMerge == 0 {
			_fts5StructurePromote(tls, p, iBestLvl+int32(1), *(*uintptr)(unsafe.Pointer(bp + 4)))
		}
		if nMin == int32(1) {
			nMin = int32(2)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppStruct)) = *(*uintptr)(unsafe.Pointer(bp + 4))
	return bRet
}

// C documentation
//
//	/*
//	** A total of nLeaf leaf pages of data has just been flushed to a level-0
//	** segment. This function updates the write-counter accordingly and, if
//	** necessary, performs incremental merge work.
//	**
//	** If an error occurs, set the Fts5Index.rc error code. If an error has
//	** already occurred, this function is a no-op.
//	*/
func _fts5IndexAutomerge(tls *libc.TLS, p uintptr, ppStruct uintptr, nLeaf int32) {
	var nRem, nWork int32
	var nWrite Tu64
	var pStruct uintptr
	_, _, _, _ = nRem, nWork, nWrite, pStruct
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnAutomerge > 0 && *(*uintptr)(unsafe.Pointer(ppStruct)) != uintptr(0) {
		pStruct = *(*uintptr)(unsafe.Pointer(ppStruct)) /* Number of leaf pages left to write */
		/* Update the write-counter. While doing so, set nWork. */
		nWrite = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter
		nWork = int32((nWrite+uint64(uint64(nLeaf)))/uint64((*TFts5Index)(unsafe.Pointer(p)).FnWorkUnit) - nWrite/uint64((*TFts5Index)(unsafe.Pointer(p)).FnWorkUnit))
		*(*Tu64)(unsafe.Pointer(pStruct + 8)) += uint64(uint64(nLeaf))
		nRem = (*TFts5Index)(unsafe.Pointer(p)).FnWorkUnit * nWork * (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel
		_fts5IndexMerge(tls, p, ppStruct, nRem, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnAutomerge)
	}
}

func _fts5IndexCrisismerge(tls *libc.TLS, p uintptr, ppStruct uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iLvl, nCrisis int32
	var _ /* pStruct at bp+0 */ uintptr
	_, _ = iLvl, nCrisis
	nCrisis = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnCrisisMerge
	*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(ppStruct))
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 && (*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnLevel > 0 {
		iLvl = 0
		for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*(*TFts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 32 + uintptr(iLvl)*12))).FnSeg >= nCrisis {
			_fts5IndexMergeLevel(tls, p, bp, iLvl, uintptr(0))
			_fts5StructurePromote(tls, p, iLvl+int32(1), *(*uintptr)(unsafe.Pointer(bp)))
			iLvl++
		}
		*(*uintptr)(unsafe.Pointer(ppStruct)) = *(*uintptr)(unsafe.Pointer(bp))
	}
}

func _fts5IndexReturn(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = (*TFts5Index)(unsafe.Pointer(p)).Frc
	(*TFts5Index)(unsafe.Pointer(p)).Frc = SQLITE_OK
	return rc
}

type TFts5FlushCtx = struct {
	F__ccgo_align  [0]uint32
	FpIdx          uintptr
	F__ccgo_align1 [4]byte
	Fwriter        TFts5SegWriter
}

type Fts5FlushCtx = TFts5FlushCtx

type TFts5FlushCtx1 = struct {
	F__ccgo_align  [0]uint32
	FpIdx          uintptr
	F__ccgo_align1 [4]byte
	Fwriter        TFts5SegWriter
}

type Fts5FlushCtx1 = TFts5FlushCtx1

// C documentation
//
//	/*
//	** Buffer aBuf[] contains a list of varints, all small enough to fit
//	** in a 32-bit integer. Return the size of the largest prefix of this
//	** list nMax bytes or less in size.
//	*/
func _fts5PoslistPrefix(tls *libc.TLS, aBuf uintptr, nMax int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, ret int32
	var _ /* dummy at bp+0 */ Tu32
	_, _ = i, ret
	ret = _sqlite3Fts5GetVarint32(tls, aBuf, bp)
	if ret < nMax {
		for int32(1) != 0 {
			i = _sqlite3Fts5GetVarint32(tls, aBuf+uintptr(ret), bp)
			if ret+i > nMax {
				break
			}
			ret += i
		}
	}
	return ret
}

// C documentation
//
//	/*
//	** Execute the SQL statement:
//	**
//	**    DELETE FROM %_idx WHERE (segid, (pgno/2)) = ($iSegid, $iPgno);
//	**
//	** This is used when a secure-delete operation removes the last term
//	** from a segment leaf page. In that case the %_idx entry is removed
//	** too. This is done to ensure that if all instances of a token are
//	** removed from an fts5 database in secure-delete mode, no trace of
//	** the token itself remains in the database.
//	*/
func _fts5SecureDeleteIdxEntry(tls *libc.TLS, p uintptr, iSegid int32, iPgno int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	if iPgno != int32(1) {
		if (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx == uintptr(0) {
			_fts5IndexPrepareStmt(tls, p, p+84, Xsqlite3_mprintf(tls, __ccgo_ts+38042, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzDb, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzName)))
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx, int32(1), iSegid)
			Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx, int32(2), iPgno)
			Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx)
			(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx)
		}
	}
}

// C documentation
//
//	/*
//	** This is called when a secure-delete operation removes a position-list
//	** that overflows onto segment page iPgno of segment pSeg. This function
//	** rewrites node iPgno, and possibly one or more of its right-hand peers,
//	** to remove this portion of the position list.
//	**
//	** Output variable (*pbLastInDoclist) is set to true if the position-list
//	** removed is followed by a new term or the end-of-segment, or false if
//	** it is followed by another rowid/position list.
//	*/
func _fts5SecureDeleteOverflow(tls *libc.TLS, p uintptr, pSeg uintptr, iPgno int32, pbLastInDoclist uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aIdx, aPg, pLeaf uintptr
	var bDetailNone, i1, i2, nIdx, nPg, nShift, pgno int32
	var iRowid Ti64
	var _ /* aEmpty at bp+4 */ [4]Tu8
	var _ /* iFirst at bp+8 */ int32
	var _ /* iNext at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _ = aIdx, aPg, bDetailNone, i1, i2, iRowid, nIdx, nPg, nShift, pLeaf, pgno
	bDetailNone = libc.BoolInt32((*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == libc.Int32FromInt32(FTS5_DETAIL_NONE))
	pLeaf = uintptr(0)
	*(*int32)(unsafe.Pointer(pbLastInDoclist)) = int32(1)
	pgno = iPgno
	for {
		if !((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && pgno <= (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast) {
			break
		}
		iRowid = int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(pgno)
		*(*int32)(unsafe.Pointer(bp)) = 0
		aPg = uintptr(0)
		pLeaf = _fts5DataRead(tls, p, iRowid)
		if pLeaf == uintptr(0) {
			break
		}
		aPg = (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp
		*(*int32)(unsafe.Pointer(bp)) = int32(_fts5GetU16(tls, aPg))
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			*(*int32)(unsafe.Pointer(pbLastInDoclist)) = 0
		}
		if *(*int32)(unsafe.Pointer(bp)) == 0 && (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf != (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn {
			_sqlite3Fts5GetVarint32(tls, aPg+uintptr((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf), bp)
		}
		if *(*int32)(unsafe.Pointer(bp)) == 0 {
			/* The page contains no terms or rowids. Replace it with an empty
			 ** page and move on to the right-hand peer.  */
			*(*[4]Tu8)(unsafe.Pointer(bp + 4)) = [4]Tu8{
				3: uint8(0x04),
			}
			if bDetailNone == 0 {
				_fts5DataWrite(tls, p, iRowid, bp+4, int32(4))
			}
			_fts5DataRelease(tls, pLeaf)
			pLeaf = uintptr(0)
		} else {
			if bDetailNone != 0 {
				break
			} else {
				if *(*int32)(unsafe.Pointer(bp)) >= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf || (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn < (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf || *(*int32)(unsafe.Pointer(bp)) < int32(4) {
					(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					break
				} else {
					nShift = *(*int32)(unsafe.Pointer(bp)) - int32(4)
					nIdx = 0
					aIdx = uintptr(0)
					/* Unless the current page footer is 0 bytes in size (in which case
					 ** the new page footer will be as well), allocate and populate a
					 ** buffer containing the new page footer. Set stack variables aIdx
					 ** and nIdx accordingly.  */
					if (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn > (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
						*(*int32)(unsafe.Pointer(bp + 8)) = 0
						i1 = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf
						i2 = 0
						i1 += _sqlite3Fts5GetVarint32(tls, aPg+uintptr(i1), bp+8)
						if *(*int32)(unsafe.Pointer(bp + 8)) < *(*int32)(unsafe.Pointer(bp)) {
							(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
							break
						}
						aIdx = _sqlite3Fts5MallocZero(tls, p+44, int64((*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn-(*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf+int32(2)))
						if aIdx == uintptr(0) {
							break
						}
						i2 = _sqlite3Fts5PutVarint(tls, aIdx, uint64(*(*int32)(unsafe.Pointer(bp + 8))-nShift))
						if i1 < (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn {
							libc.Xmemcpy(tls, aIdx+uintptr(i2), aPg+uintptr(i1), uint32((*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn-i1))
							i2 += (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn - i1
						}
						nIdx = i2
					}
					/* Modify the contents of buffer aPg[]. Set nPg to the new size
					 ** in bytes. The new page is always smaller than the old.  */
					nPg = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf - nShift
					libc.Xmemmove(tls, aPg+4, aPg+uintptr(int32(4)+nShift), uint32(nPg-int32(4)))
					_fts5PutU16(tls, aPg+2, uint16(uint16(nPg)))
					if _fts5GetU16(tls, aPg) != 0 {
						_fts5PutU16(tls, aPg, uint16(4))
					}
					if nIdx > 0 {
						libc.Xmemcpy(tls, aPg+uintptr(nPg), aIdx, uint32(uint32(nIdx)))
						nPg += nIdx
					}
					Xsqlite3_free(tls, aIdx)
					/* Write the new page to disk and exit the loop */
					_fts5DataWrite(tls, p, iRowid, aPg, nPg)
					break
				}
			}
		}
		goto _1
	_1:
		;
		pgno++
	}
	_fts5DataRelease(tls, pLeaf)
}

// C documentation
//
//	/*
//	** Completely remove the entry that pSeg currently points to from
//	** the database.
//	*/
func _fts5DoSecureDelete(tls *libc.TLS, p uintptr, pSeg uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aIdx, aPg, aTermIdx, pPg, pTerm uintptr
	var bDetailNone, bEmpty, iDelKeyOff, iIdx, iKey, iKeyIn, iKeyOff, iKeyOff1, iKeyOut, iNextOff, iOff, iPgIdx, iPgno, iPrevKeyOut, iSOP, iSegid, iStart, iTermIdx, iTermOff, nByte, nIdx, nMove, nPg, nShift, nTermIdx, pgno, v2, v4, v5, v8 int32
	var iId Ti64
	var _ /* bLastInDoclist at bp+8 */ int32
	var _ /* iDelta at bp+0 */ Tu64
	var _ /* iNextDelta at bp+24 */ Tu64
	var _ /* iVal at bp+16 */ Tu32
	var _ /* iVal at bp+32 */ Tu32
	var _ /* iVal at bp+52 */ Tu32
	var _ /* iVal at bp+56 */ Tu32
	var _ /* nPos at bp+12 */ int32
	var _ /* nPrefix at bp+36 */ int32
	var _ /* nPrefix2 at bp+44 */ int32
	var _ /* nSuffix at bp+40 */ int32
	var _ /* nSuffix2 at bp+48 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aIdx, aPg, aTermIdx, bDetailNone, bEmpty, iDelKeyOff, iId, iIdx, iKey, iKeyIn, iKeyOff, iKeyOff1, iKeyOut, iNextOff, iOff, iPgIdx, iPgno, iPrevKeyOut, iSOP, iSegid, iStart, iTermIdx, iTermOff, nByte, nIdx, nMove, nPg, nShift, nTermIdx, pPg, pTerm, pgno, v2, v4, v5, v8
	bDetailNone = libc.BoolInt32((*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == libc.Int32FromInt32(FTS5_DETAIL_NONE))
	iSegid = (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FiSegid
	aPg = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp
	nPg = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fnn
	iPgIdx = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf
	*(*Tu64)(unsafe.Pointer(bp)) = uint64(0)
	iNextOff = 0
	iOff = 0
	nIdx = 0
	aIdx = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	iIdx = 0
	iStart = 0
	iDelKeyOff = 0 /* Offset of deleted key, if any */
	nIdx = nPg - iPgIdx
	aIdx = _sqlite3Fts5MallocZero(tls, p+44, int64(nIdx+int32(16)))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
		return
	}
	libc.Xmemcpy(tls, aIdx, aPg+uintptr(iPgIdx), uint32(uint32(nIdx)))
	/* At this point segment iterator pSeg points to the entry
	 ** this function should remove from the b-tree segment.
	 **
	 ** In detail=full or detail=column mode, pSeg->iLeafOffset is the
	 ** offset of the first byte in the position-list for the entry to
	 ** remove. Immediately before this comes two varints that will also
	 ** need to be removed:
	 **
	 **     + the rowid or delta rowid value for the entry, and
	 **     + the size of the position list in bytes.
	 **
	 ** Or, in detail=none mode, there is a single varint prior to
	 ** pSeg->iLeafOffset - the rowid or delta rowid value.
	 **
	 ** This block sets the following variables:
	 **
	 **   iStart:
	 **     The offset of the first byte of the rowid or delta-rowid
	 **     value for the doclist entry being removed.
	 **
	 **   iDelta:
	 **     The value of the rowid or delta-rowid value for the doclist
	 **     entry being removed.
	 **
	 **   iNextOff:
	 **     The offset of the next entry following the position list
	 **     for the one being removed. If the position list for this
	 **     entry overflows onto the next leaf page, this value will be
	 **     greater than pLeaf->szLeaf.
	 */
	/* Start-Of-Position-list */
	if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno {
		iStart = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset
	} else {
		iStart = int32(_fts5GetU16(tls, aPg))
	}
	iSOP = iStart + int32(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iStart), bp))
	if bDetailNone != 0 {
		for int64(int64(iSOP)) < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset {
			if int32(*(*Tu8)(unsafe.Pointer(aPg + uintptr(iSOP)))) == 0x00 {
				iSOP++
			}
			if int32(*(*Tu8)(unsafe.Pointer(aPg + uintptr(iSOP)))) == 0x00 {
				iSOP++
			}
			iStart = iSOP
			iSOP = iStart + int32(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iStart), bp))
		}
		iNextOff = iSOP
		if iNextOff < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist && int32(*(*Tu8)(unsafe.Pointer(aPg + uintptr(iNextOff)))) == 0x00 {
			iNextOff++
		}
		if iNextOff < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist && int32(*(*Tu8)(unsafe.Pointer(aPg + uintptr(iNextOff)))) == 0x00 {
			iNextOff++
		}
	} else {
		*(*int32)(unsafe.Pointer(bp + 12)) = 0
		iSOP += _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iSOP), bp+12)
		for int64(int64(iSOP)) < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset {
			iStart = iSOP + *(*int32)(unsafe.Pointer(bp + 12))/int32(2)
			iSOP = iStart + int32(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iStart), bp))
			iSOP += _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iSOP), bp+12)
		}
		iNextOff = int32((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset + int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos))
	}
	iOff = iStart
	/* If the position-list for the entry being removed flows over past
	 ** the end of this page, delete the portion of the position-list on the
	 ** next page and beyond.
	 **
	 ** Set variable bLastInDoclist to true if this entry happens
	 ** to be the last rowid in the doclist for its term.  */
	if iNextOff >= iPgIdx {
		pgno = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno + int32(1)
		_fts5SecureDeleteOverflow(tls, p, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg, pgno, bp+8)
		iNextOff = iPgIdx
	}
	if int32((*TFts5SegIter)(unsafe.Pointer(pSeg)).FbDel) == 0 {
		if iNextOff != iPgIdx {
			/* Loop through the page-footer. If iNextOff (offset of the
			 ** entry following the one we are removing) is equal to the
			 ** offset of a key on this page, then the entry is the last
			 ** in its doclist. */
			iKeyOff = 0
			iIdx = 0
			for {
				if !(iIdx < nIdx) {
					break
				}
				*(*Tu32)(unsafe.Pointer(bp + 16)) = uint32(0)
				iIdx += _sqlite3Fts5GetVarint32(tls, aIdx+uintptr(iIdx), bp+16)
				iKeyOff = int32(uint32(iKeyOff) + *(*Tu32)(unsafe.Pointer(bp + 16)))
				if iKeyOff == iNextOff {
					*(*int32)(unsafe.Pointer(bp + 8)) = int32(1)
				}
				goto _1
			_1:
			}
		}
		/* If this is (a) the first rowid on a page and (b) is not followed by
		 ** another position list on the same page, set the "first-rowid" field
		 ** of the header to 0.  */
		if int32(_fts5GetU16(tls, aPg)) == iStart && (*(*int32)(unsafe.Pointer(bp + 8)) != 0 || iNextOff == iPgIdx) {
			_fts5PutU16(tls, aPg, uint16(0))
		}
	}
	if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FbDel != 0 {
		iOff += _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), *(*Tu64)(unsafe.Pointer(bp)))
		v2 = iOff
		iOff++
		*(*Tu8)(unsafe.Pointer(aPg + uintptr(v2))) = uint8(0x01)
	} else {
		if *(*int32)(unsafe.Pointer(bp + 8)) == 0 {
			if iNextOff != iPgIdx {
				*(*Tu64)(unsafe.Pointer(bp + 24)) = uint64(0)
				iNextOff += int32(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iNextOff), bp+24))
				iOff += _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), *(*Tu64)(unsafe.Pointer(bp))+*(*Tu64)(unsafe.Pointer(bp + 24)))
			}
		} else {
			if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno && iStart == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset {
				/* The entry being removed was the only position list in its
				 ** doclist. Therefore the term needs to be removed as well. */
				iKey = 0
				iKeyOff1 = 0
				/* Set iKeyOff to the offset of the term that will be removed - the
				 ** last offset in the footer that is not greater than iStart. */
				iIdx = 0
				for {
					if !(iIdx < nIdx) {
						break
					}
					*(*Tu32)(unsafe.Pointer(bp + 32)) = uint32(0)
					iIdx += _sqlite3Fts5GetVarint32(tls, aIdx+uintptr(iIdx), bp+32)
					if uint32(uint32(iKeyOff1))+*(*Tu32)(unsafe.Pointer(bp + 32)) > uint32(uint32(iStart)) {
						break
					}
					iKeyOff1 = int32(uint32(iKeyOff1) + *(*Tu32)(unsafe.Pointer(bp + 32)))
					goto _3
				_3:
					;
					iKey++
				}
				/* Set iDelKeyOff to the value of the footer entry to remove from
				 ** the page. */
				v4 = iKeyOff1
				iOff = v4
				iDelKeyOff = v4
				if iNextOff != iPgIdx {
					/* This is the only position-list associated with the term, and there
					 ** is another term following it on this page. So the subsequent term
					 ** needs to be moved to replace the term associated with the entry
					 ** being removed. */
					*(*int32)(unsafe.Pointer(bp + 36)) = 0
					*(*int32)(unsafe.Pointer(bp + 40)) = 0
					*(*int32)(unsafe.Pointer(bp + 44)) = 0
					*(*int32)(unsafe.Pointer(bp + 48)) = 0
					iDelKeyOff = iNextOff
					iNextOff += _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iNextOff), bp+44)
					iNextOff += _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iNextOff), bp+48)
					if iKey != int32(1) {
						iKeyOff1 += _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iKeyOff1), bp+36)
					}
					iKeyOff1 += _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iKeyOff1), bp+40)
					if *(*int32)(unsafe.Pointer(bp + 36)) < *(*int32)(unsafe.Pointer(bp + 44)) {
						v5 = *(*int32)(unsafe.Pointer(bp + 36))
					} else {
						v5 = *(*int32)(unsafe.Pointer(bp + 44))
					}
					*(*int32)(unsafe.Pointer(bp + 36)) = v5
					*(*int32)(unsafe.Pointer(bp + 40)) = *(*int32)(unsafe.Pointer(bp + 44)) + *(*int32)(unsafe.Pointer(bp + 48)) - *(*int32)(unsafe.Pointer(bp + 36))
					if iKeyOff1+*(*int32)(unsafe.Pointer(bp + 40)) > iPgIdx || iNextOff+*(*int32)(unsafe.Pointer(bp + 48)) > iPgIdx {
						(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					} else {
						if iKey != int32(1) {
							iOff += _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), uint64(*(*int32)(unsafe.Pointer(bp + 36))))
						}
						iOff += _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), uint64(*(*int32)(unsafe.Pointer(bp + 40))))
						if *(*int32)(unsafe.Pointer(bp + 44)) > (*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn {
							(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						} else {
							if *(*int32)(unsafe.Pointer(bp + 44)) > *(*int32)(unsafe.Pointer(bp + 36)) {
								libc.Xmemcpy(tls, aPg+uintptr(iOff), (*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp+uintptr(*(*int32)(unsafe.Pointer(bp + 36))), uint32(*(*int32)(unsafe.Pointer(bp + 44))-*(*int32)(unsafe.Pointer(bp + 36))))
								iOff += *(*int32)(unsafe.Pointer(bp + 44)) - *(*int32)(unsafe.Pointer(bp + 36))
							}
						}
						libc.Xmemmove(tls, aPg+uintptr(iOff), aPg+uintptr(iNextOff), uint32(*(*int32)(unsafe.Pointer(bp + 48))))
						iOff += *(*int32)(unsafe.Pointer(bp + 48))
						iNextOff += *(*int32)(unsafe.Pointer(bp + 48))
					}
				}
			} else {
				if iStart == int32(4) {
					/* The entry being removed may be the only position list in
					 ** its doclist. */
					iPgno = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno - int32(1)
					for {
						if !(iPgno > (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno) {
							break
						}
						pPg = _fts5DataRead(tls, p, int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(iPgno))
						bEmpty = libc.BoolInt32(pPg != 0 && (*TFts5Data)(unsafe.Pointer(pPg)).Fnn == int32(4))
						_fts5DataRelease(tls, pPg)
						if bEmpty == 0 {
							break
						}
						goto _6
					_6:
						;
						iPgno--
					}
					if iPgno == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno {
						iId = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno)
						pTerm = _fts5DataRead(tls, p, iId)
						if pTerm != 0 && (*TFts5Data)(unsafe.Pointer(pTerm)).FszLeaf == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset {
							aTermIdx = (*TFts5Data)(unsafe.Pointer(pTerm)).Fp + uintptr((*TFts5Data)(unsafe.Pointer(pTerm)).FszLeaf)
							nTermIdx = (*TFts5Data)(unsafe.Pointer(pTerm)).Fnn - (*TFts5Data)(unsafe.Pointer(pTerm)).FszLeaf
							iTermIdx = 0
							iTermOff = 0
							for int32(1) != 0 {
								*(*Tu32)(unsafe.Pointer(bp + 52)) = uint32(0)
								nByte = _sqlite3Fts5GetVarint32(tls, aTermIdx+uintptr(iTermIdx), bp+52)
								iTermOff = int32(uint32(iTermOff) + *(*Tu32)(unsafe.Pointer(bp + 52)))
								if iTermIdx+nByte >= nTermIdx {
									break
								}
								iTermIdx += nByte
							}
							nTermIdx = iTermIdx
							libc.Xmemmove(tls, (*TFts5Data)(unsafe.Pointer(pTerm)).Fp+uintptr(iTermOff), (*TFts5Data)(unsafe.Pointer(pTerm)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pTerm)).FszLeaf), uint32(uint32(nTermIdx)))
							_fts5PutU16(tls, (*TFts5Data)(unsafe.Pointer(pTerm)).Fp+2, uint16(uint16(iTermOff)))
							_fts5DataWrite(tls, p, iId, (*TFts5Data)(unsafe.Pointer(pTerm)).Fp, iTermOff+nTermIdx)
							if nTermIdx == 0 {
								_fts5SecureDeleteIdxEntry(tls, p, iSegid, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno)
							}
						}
						_fts5DataRelease(tls, pTerm)
					}
				}
			}
		}
	}
	/* Assuming no error has occurred, this block does final edits to the
	 ** leaf page before writing it back to disk. Input variables are:
	 **
	 **   nPg: Total initial size of leaf page.
	 **   iPgIdx: Initial offset of page footer.
	 **
	 **   iOff: Offset to move data to
	 **   iNextOff: Offset to move data from
	 */
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		nMove = nPg - iNextOff   /* Number of bytes to move */
		nShift = iNextOff - iOff /* Distance to move them */
		iPrevKeyOut = 0
		iKeyIn = 0
		libc.Xmemmove(tls, aPg+uintptr(iOff), aPg+uintptr(iNextOff), uint32(uint32(nMove)))
		iPgIdx -= nShift
		nPg = iPgIdx
		_fts5PutU16(tls, aPg+2, uint16(uint16(iPgIdx)))
		iIdx = 0
		for {
			if !(iIdx < nIdx) {
				break
			}
			*(*Tu32)(unsafe.Pointer(bp + 56)) = uint32(0)
			iIdx += _sqlite3Fts5GetVarint32(tls, aIdx+uintptr(iIdx), bp+56)
			iKeyIn = int32(uint32(iKeyIn) + *(*Tu32)(unsafe.Pointer(bp + 56)))
			if iKeyIn != iDelKeyOff {
				if iKeyIn > iOff {
					v8 = nShift
				} else {
					v8 = 0
				}
				iKeyOut = iKeyIn - v8
				nPg += _sqlite3Fts5PutVarint(tls, aPg+uintptr(nPg), uint64(iKeyOut-iPrevKeyOut))
				iPrevKeyOut = iKeyOut
			}
			goto _7
		_7:
		}
		if iPgIdx == nPg && nIdx > 0 && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno != int32(1) {
			_fts5SecureDeleteIdxEntry(tls, p, iSegid, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno)
		}
		_fts5DataWrite(tls, p, int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno), aPg, nPg)
	}
	Xsqlite3_free(tls, aIdx)
}

// C documentation
//
//	/*
//	** This is called as part of flushing a delete to disk in 'secure-delete'
//	** mode. It edits the segments within the database described by argument
//	** pStruct to remove the entries for term zTerm, rowid iRowid.
//	*/
func _fts5FlushSecureDelete(tls *libc.TLS, p uintptr, pStruct uintptr, zTerm uintptr, nTerm int32, iRowid Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var f int32
	var iThis Ti64
	var pSeg uintptr
	var _ /* pIter at bp+0 */ uintptr
	_, _, _ = f, iThis, pSeg
	f = int32(FTS5INDEX_QUERY_SKIPHASH)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Used to find term instance */
	_fts5MultiIterNew(tls, p, pStruct, f, uintptr(0), zTerm, nTerm, -int32(1), 0, bp)
	if _fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp))) == 0 {
		iThis = _fts5MultiIterRowid(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if iThis < iRowid {
			_fts5MultiIterNextFrom(tls, p, *(*uintptr)(unsafe.Pointer(bp)), iRowid)
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && _fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp))) == 0 && iRowid == _fts5MultiIterRowid(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			pSeg = *(*uintptr)(unsafe.Pointer(bp)) + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFirst + 1*4))).FiFirst)*104
			_fts5DoSecureDelete(tls, p, pSeg)
		}
	}
	_fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Flush the contents of in-memory hash table iHash to a new level-0
//	** segment on disk. Also update the corresponding structure record.
//	**
//	** If an error occurs, set the Fts5Index.rc error code. If an error has
//	** already occurred, this function is a no-op.
//	*/
func _fts5FlushOneHash(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var bSecureDelete, bTermWritten, eDetail, iOff, iPos, iSegid, n, nCopy, nSpace, pgsz, v1, v3, v5 int32
	var iPrev, iRowid Ti64
	var iRowidDelta Tu64
	var pBuf, pHash, pPgidx, pPoslist, pSeg, v2, v4, v6 uintptr
	var _ /* bDel at bp+128 */ int32
	var _ /* iDelta at bp+120 */ Tu64
	var _ /* nDoclist at bp+116 */ int32
	var _ /* nPos at bp+132 */ int32
	var _ /* nTerm at bp+108 */ int32
	var _ /* pDoclist at bp+112 */ uintptr
	var _ /* pStruct at bp+0 */ uintptr
	var _ /* pgnoLast at bp+4 */ int32
	var _ /* writer at bp+8 */ TFts5SegWriter
	var _ /* zTerm at bp+104 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bSecureDelete, bTermWritten, eDetail, iOff, iPos, iPrev, iRowid, iRowidDelta, iSegid, n, nCopy, nSpace, pBuf, pHash, pPgidx, pPoslist, pSeg, pgsz, v1, v2, v3, v4, v5, v6
	pHash = (*TFts5Index)(unsafe.Pointer(p)).FpHash
	*(*int32)(unsafe.Pointer(bp + 4)) = 0 /* Last leaf page number in segment */
	/* Obtain a reference to the index structure and allocate a new segment-id
	 ** for the new level-0 segment.  */
	*(*uintptr)(unsafe.Pointer(bp)) = _fts5StructureRead(tls, p)
	_fts5StructureInvalidate(tls, p)
	if _sqlite3Fts5HashIsEmpty(tls, pHash) == 0 {
		iSegid = _fts5AllocateSegid(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		if iSegid != 0 {
			pgsz = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz
			eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
			bSecureDelete = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FbSecureDelete
			_fts5WriteInit(tls, p, bp+8, iSegid)
			pBuf = bp + 8 + 4 + 8
			pPgidx = bp + 8 + 4 + 20
			/* fts5WriteInit() should have initialized the buffers to (most likely)
			 ** the maximum space required. */
			/* Begin scanning through hash table entries. This loop runs once for each
			 ** term/doclist currently stored within the hash table. */
			if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5HashScanInit(tls, pHash, uintptr(0), 0)
			}
			for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && 0 == _sqlite3Fts5HashScanEof(tls, pHash) { /* Size of doclist in bytes */
				/* Get the term and doclist for this entry. */
				_sqlite3Fts5HashScanEntry(tls, pHash, bp+104, bp+108, bp+112, bp+116)
				if bSecureDelete == 0 {
					_fts5WriteAppendTerm(tls, p, bp+8, *(*int32)(unsafe.Pointer(bp + 108)), *(*uintptr)(unsafe.Pointer(bp + 104)))
					if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
						break
					}
				}
				if !(bSecureDelete != 0) && pgsz >= (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn+*(*int32)(unsafe.Pointer(bp + 116))+int32(1) {
					/* The entire doclist will fit on the current leaf. */
					libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), *(*uintptr)(unsafe.Pointer(bp + 112)), uint32(*(*int32)(unsafe.Pointer(bp + 116))))
					*(*int32)(unsafe.Pointer(pBuf + 4)) += *(*int32)(unsafe.Pointer(bp + 116))
				} else {
					bTermWritten = libc.BoolInt32(!(bSecureDelete != 0))
					iRowid = 0
					iPrev = 0
					iOff = 0
					/* The entire doclist will not fit on this leaf. The following
					 ** loop iterates through the poslists that make up the current
					 ** doclist.  */
					for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && iOff < *(*int32)(unsafe.Pointer(bp + 116)) {
						*(*Tu64)(unsafe.Pointer(bp + 120)) = uint64(0)
						iOff += int32(_sqlite3Fts5GetVarint(tls, *(*uintptr)(unsafe.Pointer(bp + 112))+uintptr(iOff), bp+120))
						iRowid = Ti64(uint64(iRowid) + *(*Tu64)(unsafe.Pointer(bp + 120)))
						/* If in secure delete mode, and if this entry in the poslist is
						 ** in fact a delete, then edit the existing segments directly
						 ** using fts5FlushSecureDelete().  */
						if bSecureDelete != 0 {
							if eDetail == int32(FTS5_DETAIL_NONE) {
								if iOff < *(*int32)(unsafe.Pointer(bp + 116)) && int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)) + uintptr(iOff)))) == 0x00 {
									_fts5FlushSecureDelete(tls, p, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 104)), *(*int32)(unsafe.Pointer(bp + 108)), iRowid)
									iOff++
									if iOff < *(*int32)(unsafe.Pointer(bp + 116)) && int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)) + uintptr(iOff)))) == 0x00 {
										iOff++
										*(*int32)(unsafe.Pointer(bp + 116)) = 0
									} else {
										continue
									}
								}
							} else {
								if int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)) + uintptr(iOff))))&int32(0x01) != 0 {
									_fts5FlushSecureDelete(tls, p, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 104)), *(*int32)(unsafe.Pointer(bp + 108)), iRowid)
									if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK || int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)) + uintptr(iOff)))) == int32(0x01) {
										iOff++
										continue
									}
								}
							}
						}
						if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bTermWritten == 0 {
							_fts5WriteAppendTerm(tls, p, bp+8, *(*int32)(unsafe.Pointer(bp + 108)), *(*uintptr)(unsafe.Pointer(bp + 104)))
							bTermWritten = int32(1)
						}
						if (*(*TFts5SegWriter)(unsafe.Pointer(bp + 8))).FbFirstRowidInPage != 0 {
							_fts5PutU16(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp, uint16((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)) /* first rowid on page */
							*(*int32)(unsafe.Pointer(pBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(uint64(iRowid)))
							(*(*TFts5SegWriter)(unsafe.Pointer(bp + 8))).FbFirstRowidInPage = uint8(0)
							_fts5WriteDlidxAppend(tls, p, bp+8, iRowid)
						} else {
							iRowidDelta = uint64(uint64(iRowid)) - uint64(uint64(iPrev))
							*(*int32)(unsafe.Pointer(pBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), iRowidDelta)
						}
						if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
							break
						}
						iPrev = iRowid
						if eDetail == int32(FTS5_DETAIL_NONE) {
							if iOff < *(*int32)(unsafe.Pointer(bp + 116)) && int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)) + uintptr(iOff)))) == 0 {
								v2 = pBuf + 4
								v1 = *(*int32)(unsafe.Pointer(v2))
								*(*int32)(unsafe.Pointer(v2))++
								*(*Tu8)(unsafe.Pointer((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(v1))) = uint8(0)
								iOff++
								if iOff < *(*int32)(unsafe.Pointer(bp + 116)) && int32(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)) + uintptr(iOff)))) == 0 {
									v4 = pBuf + 4
									v3 = *(*int32)(unsafe.Pointer(v4))
									*(*int32)(unsafe.Pointer(v4))++
									*(*Tu8)(unsafe.Pointer((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(v3))) = uint8(0)
									iOff++
								}
							}
							if (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn >= pgsz {
								_fts5WriteFlushLeaf(tls, p, bp+8)
							}
						} else {
							*(*int32)(unsafe.Pointer(bp + 128)) = 0
							*(*int32)(unsafe.Pointer(bp + 132)) = 0
							nCopy = _fts5GetPoslistSize(tls, *(*uintptr)(unsafe.Pointer(bp + 112))+uintptr(iOff), bp+132, bp+128)
							if *(*int32)(unsafe.Pointer(bp + 128)) != 0 && bSecureDelete != 0 {
								_sqlite3Fts5BufferAppendVarint(tls, p+44, pBuf, int64(*(*int32)(unsafe.Pointer(bp + 132)))*int64(2))
								iOff += nCopy
								nCopy = *(*int32)(unsafe.Pointer(bp + 132))
							} else {
								nCopy += *(*int32)(unsafe.Pointer(bp + 132))
							}
							if (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn+nCopy <= pgsz {
								/* The entire poslist will fit on the current leaf. So copy
								 ** it in one go. */
								libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), *(*uintptr)(unsafe.Pointer(bp + 112))+uintptr(iOff), uint32(uint32(nCopy)))
								*(*int32)(unsafe.Pointer(pBuf + 4)) += nCopy
							} else {
								/* The entire poslist will not fit on this leaf. So it needs
								 ** to be broken into sections. The only qualification being
								 ** that each varint must be stored contiguously.  */
								pPoslist = *(*uintptr)(unsafe.Pointer(bp + 112)) + uintptr(iOff)
								iPos = 0
								for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
									nSpace = pgsz - (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn - (*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn
									n = 0
									if nCopy-iPos <= nSpace {
										n = nCopy - iPos
									} else {
										n = _fts5PoslistPrefix(tls, pPoslist+uintptr(iPos), nSpace)
									}
									libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), pPoslist+uintptr(iPos), uint32(uint32(n)))
									*(*int32)(unsafe.Pointer(pBuf + 4)) += n
									iPos += n
									if (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn >= pgsz {
										_fts5WriteFlushLeaf(tls, p, bp+8)
									}
									if iPos >= nCopy {
										break
									}
								}
							}
							iOff += nCopy
						}
					}
				}
				/* TODO2: Doclist terminator written here. */
				/* pBuf->p[pBuf->n++] = '\0'; */
				if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					_sqlite3Fts5HashScanNext(tls, pHash)
				}
			}
			_fts5WriteFinish(tls, p, bp+8, bp+4)
			if *(*int32)(unsafe.Pointer(bp + 4)) > 0 {
				/* Update the Fts5Structure. It is written back to the database by the
				 ** fts5StructureRelease() call below.  */
				if (*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnLevel == 0 {
					_fts5StructureAddLevel(tls, p+44, bp)
				}
				_fts5StructureExtendLevel(tls, p+44, *(*uintptr)(unsafe.Pointer(bp)), 0, int32(1), 0)
				if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					v6 = *(*uintptr)(unsafe.Pointer(bp)) + 32 + 4
					v5 = *(*int32)(unsafe.Pointer(v6))
					*(*int32)(unsafe.Pointer(v6))++
					pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 32))).FaSeg + uintptr(v5)*56
					(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid = iSegid
					(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst = int32(1)
					(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast = *(*int32)(unsafe.Pointer(bp + 4))
					if (*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnOriginCntr > uint64(0) {
						(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1 = (*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnOriginCntr
						(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2 = (*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnOriginCntr
						(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntry = uint64((*TFts5Index)(unsafe.Pointer(p)).FnPendingRow)
						(*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnOriginCntr++
					}
					(*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnSegment++
				}
				_fts5StructurePromote(tls, p, 0, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
	}
	_fts5IndexAutomerge(tls, p, bp, *(*int32)(unsafe.Pointer(bp + 4))+(*TFts5Index)(unsafe.Pointer(p)).FnContentlessDelete)
	_fts5IndexCrisismerge(tls, p, bp)
	_fts5StructureWrite(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	_fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Flush any data stored in the in-memory hash tables to the database.
//	*/
func _fts5IndexFlush(tls *libc.TLS, p uintptr) {
	/* Unless it is empty, flush the hash table to disk */
	if (*TFts5Index)(unsafe.Pointer(p)).FflushRc != 0 {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = (*TFts5Index)(unsafe.Pointer(p)).FflushRc
		return
	}
	if (*TFts5Index)(unsafe.Pointer(p)).FnPendingData != 0 || (*TFts5Index)(unsafe.Pointer(p)).FnContentlessDelete != 0 {
		_fts5FlushOneHash(tls, p)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			_sqlite3Fts5HashClear(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash)
			(*TFts5Index)(unsafe.Pointer(p)).FnPendingData = 0
			(*TFts5Index)(unsafe.Pointer(p)).FnPendingRow = 0
			(*TFts5Index)(unsafe.Pointer(p)).FnContentlessDelete = 0
		} else {
			if (*TFts5Index)(unsafe.Pointer(p)).FnPendingData != 0 || (*TFts5Index)(unsafe.Pointer(p)).FnContentlessDelete != 0 {
				(*TFts5Index)(unsafe.Pointer(p)).FflushRc = (*TFts5Index)(unsafe.Pointer(p)).Frc
			}
		}
	}
}

func _fts5IndexOptimizeStruct(tls *libc.TLS, p uintptr, pStruct uintptr) (r uintptr) {
	var i, iLvl, iSeg, iSegOut, nMerge, nSeg, nThis, v2, v5 int32
	var nByte Tsqlite3_int64
	var pLvl, pNew uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = i, iLvl, iSeg, iSegOut, nByte, nMerge, nSeg, nThis, pLvl, pNew, v2, v5
	pNew = uintptr(0)
	nByte = int64(48)
	nSeg = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment
	/* Figure out if this structure requires optimization. A structure does
	 ** not require optimization if either:
	 **
	 **  1. it consists of fewer than two segments, or
	 **  2. all segments are on the same level, or
	 **  3. all segments except one are currently inputs to a merge operation.
	 **
	 ** In the first case, if there are no tombstone hash pages, return NULL. In
	 ** the second, increment the ref-count on *pStruct and return a copy of the
	 ** pointer to it.
	 */
	if nSeg == 0 {
		return uintptr(0)
	}
	i = 0
	for {
		if !(i < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
			break
		}
		nThis = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(i)*12))).FnSeg
		nMerge = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(i)*12))).FnMerge
		if nThis > 0 && (nThis == nSeg || nThis == nSeg-int32(1) && nMerge == nThis) {
			if nSeg == int32(1) && nThis == int32(1) && (*(*TFts5StructureSegment)(unsafe.Pointer((*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(i)*12))).FaSeg))).FnPgTombstone == 0 {
				return uintptr(0)
			}
			_fts5StructureRef(tls, pStruct)
			return pStruct
		}
		goto _1
	_1:
		;
		i++
	}
	nByte += int64(uint32((*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel+libc.Int32FromInt32(1)) * uint32(12))
	pNew = _sqlite3Fts5MallocZero(tls, p+44, nByte)
	if pNew != 0 {
		nByte = int64(uint32(uint32(nSeg)) * uint32(56))
		if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel+int32(1) < int32(FTS5_MAX_LEVEL) {
			v2 = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel + int32(1)
		} else {
			v2 = int32(FTS5_MAX_LEVEL)
		}
		(*TFts5Structure)(unsafe.Pointer(pNew)).FnLevel = v2
		(*TFts5Structure)(unsafe.Pointer(pNew)).FnRef = int32(1)
		(*TFts5Structure)(unsafe.Pointer(pNew)).FnWriteCounter = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter
		(*TFts5Structure)(unsafe.Pointer(pNew)).FnOriginCntr = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr
		pLvl = pNew + 32 + uintptr((*TFts5Structure)(unsafe.Pointer(pNew)).FnLevel-int32(1))*12
		(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = _sqlite3Fts5MallocZero(tls, p+44, nByte)
		if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg != 0 {
			iSegOut = 0
			/* Iterate through all segments, from oldest to newest. Add them to
			 ** the new Fts5Level object so that pLvl->aSeg[0] is the oldest
			 ** segment in the data structure.  */
			iLvl = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel - int32(1)
			for {
				if !(iLvl >= 0) {
					break
				}
				iSeg = 0
				for {
					if !(iSeg < (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FnSeg) {
						break
					}
					*(*TFts5StructureSegment)(unsafe.Pointer((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSegOut)*56)) = *(*TFts5StructureSegment)(unsafe.Pointer((*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FaSeg + uintptr(iSeg)*56))
					iSegOut++
					goto _4
				_4:
					;
					iSeg++
				}
				goto _3
			_3:
				;
				iLvl--
			}
			v5 = nSeg
			(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg = v5
			(*TFts5Structure)(unsafe.Pointer(pNew)).FnSegment = v5
		} else {
			Xsqlite3_free(tls, pNew)
			pNew = uintptr(0)
		}
	}
	return pNew
}

func _sqlite3Fts5IndexOptimize(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iLvl int32
	var pStruct uintptr
	var _ /* nRem at bp+4 */ int32
	var _ /* pNew at bp+0 */ uintptr
	_, _ = iLvl, pStruct
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	_fts5IndexFlush(tls, p)
	pStruct = _fts5StructureRead(tls, p)
	_fts5StructureInvalidate(tls, p)
	if pStruct != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = _fts5IndexOptimizeStruct(tls, p, pStruct)
	}
	_fts5StructureRelease(tls, pStruct)
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		iLvl = 0
		for {
			if !((*(*TFts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 32 + uintptr(iLvl)*12))).FnSeg == 0) {
				break
			}
			goto _1
		_1:
			;
			iLvl++
		}
		for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*(*TFts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 32 + uintptr(iLvl)*12))).FnSeg > 0 {
			*(*int32)(unsafe.Pointer(bp + 4)) = int32(FTS5_OPT_WORK_UNIT)
			_fts5IndexMergeLevel(tls, p, bp, iLvl, bp+4)
		}
		_fts5StructureWrite(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		_fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** This is called to implement the special "VALUES('merge', $nMerge)"
//	** INSERT command.
//	*/
func _sqlite3Fts5IndexMerge(tls *libc.TLS, p uintptr, nMerge int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nMin int32
	var pNew uintptr
	var _ /* pStruct at bp+0 */ uintptr
	_, _ = nMin, pNew
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	_fts5IndexFlush(tls, p)
	*(*uintptr)(unsafe.Pointer(bp)) = _fts5StructureRead(tls, p)
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		nMin = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnUsermerge
		_fts5StructureInvalidate(tls, p)
		if nMerge < 0 {
			pNew = _fts5IndexOptimizeStruct(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
			_fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
			*(*uintptr)(unsafe.Pointer(bp)) = pNew
			nMin = int32(1)
			nMerge = nMerge * -int32(1)
		}
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 && (*TFts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnLevel != 0 {
			if _fts5IndexMerge(tls, p, bp, nMerge, nMin) != 0 {
				_fts5StructureWrite(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
		_fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return _fts5IndexReturn(tls, p)
}

func _fts5AppendRowid(tls *libc.TLS, p uintptr, iDelta Tu64, pUnused uintptr, pBuf uintptr) {
	_ = pUnused
	_sqlite3Fts5BufferAppendVarint(tls, p+44, pBuf, int64(int64(iDelta)))
}

func _fts5AppendPoslist(tls *libc.TLS, p uintptr, iDelta Tu64, pMulti uintptr, pBuf uintptr) {
	var nByte, nData, v1 int32
	var v2 bool
	_, _, _, _ = nByte, nData, v1, v2
	nData = (*TFts5Iter)(unsafe.Pointer(pMulti)).Fbase.FnData
	nByte = nData + int32(9) + int32(9) + int32(FTS5_DATA_ZERO_PADDING)
	if v2 = (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK; v2 {
		if uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)+uint32(nByte) <= uint32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
			v1 = 0
		} else {
			v1 = _sqlite3Fts5BufferSize(tls, p+44, pBuf, uint32(nByte+(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn))
		}
	}
	if v2 && 0 == v1 {
		*(*int32)(unsafe.Pointer(pBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), iDelta)
		*(*int32)(unsafe.Pointer(pBuf + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(nData*libc.Int32FromInt32(2)))
		libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), (*TFts5Iter)(unsafe.Pointer(pMulti)).Fbase.FpData, uint32(uint32(nData)))
		*(*int32)(unsafe.Pointer(pBuf + 4)) += nData
		libc.Xmemset(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), 0, uint32(FTS5_DATA_ZERO_PADDING))
	}
}

func _fts5DoclistIterNext(tls *libc.TLS, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	var _ /* iDelta at bp+0 */ Ti64
	var _ /* nPos at bp+8 */ int32
	_ = p
	p = (*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist + uintptr((*TFts5DoclistIter)(unsafe.Pointer(pIter)).FnSize) + uintptr((*TFts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist)
	if p >= (*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaEof {
		(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = uintptr(0)
	} else {
		p += uintptr(_sqlite3Fts5GetVarint(tls, p, bp))
		*(*Ti64)(unsafe.Pointer(pIter + 8)) += *(*Ti64)(unsafe.Pointer(bp))
		/* Read position list size */
		if int32(*(*Tu8)(unsafe.Pointer(p)))&int32(0x80) != 0 {
			(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FnSize = _sqlite3Fts5GetVarint32(tls, p, bp+8)
			(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist = *(*int32)(unsafe.Pointer(bp + 8)) >> int32(1)
		} else {
			(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist = int32(*(*Tu8)(unsafe.Pointer(p))) >> int32(1)
			(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FnSize = int32(1)
		}
		(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = p
		if (*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist+uintptr((*TFts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist) > (*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaEof {
			(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = uintptr(0)
		}
	}
}

func _fts5DoclistIterInit(tls *libc.TLS, pBuf uintptr, pIter uintptr) {
	libc.Xmemset(tls, pIter, 0, uint32(32))
	if (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn > 0 {
		(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp
		(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaEof = (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)
		_fts5DoclistIterNext(tls, pIter)
	}
}

// C documentation
//
//	/*
//	** Swap the contents of buffer *p1 with that of *p2.
//	*/
func _fts5BufferSwap(tls *libc.TLS, p1 uintptr, p2 uintptr) {
	var tmp TFts5Buffer
	_ = tmp
	tmp = *(*TFts5Buffer)(unsafe.Pointer(p1))
	*(*TFts5Buffer)(unsafe.Pointer(p1)) = *(*TFts5Buffer)(unsafe.Pointer(p2))
	*(*TFts5Buffer)(unsafe.Pointer(p2)) = tmp
}

func _fts5NextRowid(tls *libc.TLS, pBuf uintptr, piOff uintptr, piRowid uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var p1 uintptr
	var _ /* iVal at bp+0 */ Tu64
	_, _ = i, p1
	i = *(*int32)(unsafe.Pointer(piOff))
	if i >= (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn {
		*(*int32)(unsafe.Pointer(piOff)) = -int32(1)
	} else {
		*(*int32)(unsafe.Pointer(piOff)) = i + int32(_sqlite3Fts5GetVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr(i), bp))
		p1 = piRowid
		*(*Ti64)(unsafe.Pointer(p1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(p1))) + *(*Tu64)(unsafe.Pointer(bp)))
	}
}

// C documentation
//
//	/*
//	** This is the equivalent of fts5MergePrefixLists() for detail=none mode.
//	** In this case the buffers consist of a delta-encoded list of rowids only.
//	*/
func _fts5MergeRowidLists(tls *libc.TLS, p uintptr, p1 uintptr, nBuf int32, aBuf uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iOut Ti64
	var p2 uintptr
	var _ /* i1 at bp+0 */ int32
	var _ /* i2 at bp+4 */ int32
	var _ /* iRowid1 at bp+8 */ Ti64
	var _ /* iRowid2 at bp+16 */ Ti64
	var _ /* out at bp+24 */ TFts5Buffer
	_, _ = iOut, p2
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	*(*Ti64)(unsafe.Pointer(bp + 8)) = 0
	*(*Ti64)(unsafe.Pointer(bp + 16)) = 0
	iOut = 0
	p2 = aBuf
	_ = nBuf
	libc.Xmemset(tls, bp+24, 0, uint32(12))
	_sqlite3Fts5BufferSize(tls, p+44, bp+24, uint32((*TFts5Buffer)(unsafe.Pointer(p1)).Fn+(*TFts5Buffer)(unsafe.Pointer(p2)).Fn))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
		return
	}
	_fts5NextRowid(tls, p1, bp, bp+8)
	_fts5NextRowid(tls, p2, bp+4, bp+16)
	for *(*int32)(unsafe.Pointer(bp)) >= 0 || *(*int32)(unsafe.Pointer(bp + 4)) >= 0 {
		if *(*int32)(unsafe.Pointer(bp)) >= 0 && (*(*int32)(unsafe.Pointer(bp + 4)) < 0 || *(*Ti64)(unsafe.Pointer(bp + 8)) < *(*Ti64)(unsafe.Pointer(bp + 16))) {
			*(*int32)(unsafe.Pointer(bp + 24 + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+24)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+24)).Fn), uint64(*(*Ti64)(unsafe.Pointer(bp + 8))-iOut))
			iOut = *(*Ti64)(unsafe.Pointer(bp + 8))
			_fts5NextRowid(tls, p1, bp, bp+8)
		} else {
			*(*int32)(unsafe.Pointer(bp + 24 + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+24)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+24)).Fn), uint64(*(*Ti64)(unsafe.Pointer(bp + 16))-iOut))
			iOut = *(*Ti64)(unsafe.Pointer(bp + 16))
			if *(*int32)(unsafe.Pointer(bp)) >= 0 && *(*Ti64)(unsafe.Pointer(bp + 8)) == *(*Ti64)(unsafe.Pointer(bp + 16)) {
				_fts5NextRowid(tls, p1, bp, bp+8)
			}
			_fts5NextRowid(tls, p2, bp+4, bp+16)
		}
	}
	_fts5BufferSwap(tls, bp+24, p1)
	_sqlite3Fts5BufferFree(tls, bp+24)
}

type TPrefixMerger = struct {
	F__ccgo_align [0]uint32
	Fiter         TFts5DoclistIter
	FiPos         Ti64
	FiOff         int32
	FaPos         uintptr
	FpNext        uintptr
	F__ccgo_pad5  [4]byte
}

type PrefixMerger = TPrefixMerger

type TPrefixMerger1 = struct {
	F__ccgo_align [0]uint32
	Fiter         TFts5DoclistIter
	FiPos         Ti64
	FiOff         int32
	FaPos         uintptr
	FpNext        uintptr
	F__ccgo_pad5  [4]byte
}

type PrefixMerger1 = TPrefixMerger1

func _fts5PrefixMergerInsertByRowid(tls *libc.TLS, ppHead uintptr, p uintptr) {
	var pp uintptr
	_ = pp
	if (*TPrefixMerger)(unsafe.Pointer(p)).Fiter.FaPoslist != 0 {
		pp = ppHead
		for *(*uintptr)(unsafe.Pointer(pp)) != 0 && (*TPrefixMerger)(unsafe.Pointer(p)).Fiter.FiRowid > (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).Fiter.FiRowid {
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 48
		}
		(*TPrefixMerger)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(pp))
		*(*uintptr)(unsafe.Pointer(pp)) = p
	}
}

func _fts5PrefixMergerInsertByPosition(tls *libc.TLS, ppHead uintptr, p uintptr) {
	var pp uintptr
	_ = pp
	if (*TPrefixMerger)(unsafe.Pointer(p)).FiPos >= 0 {
		pp = ppHead
		for *(*uintptr)(unsafe.Pointer(pp)) != 0 && (*TPrefixMerger)(unsafe.Pointer(p)).FiPos > (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FiPos {
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 48
		}
		(*TPrefixMerger)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(pp))
		*(*uintptr)(unsafe.Pointer(pp)) = p
	}
}

// C documentation
//
//	/*
//	** Array aBuf[] contains nBuf doclists. These are all merged in with the
//	** doclist in buffer p1.
//	*/
func _fts5MergePrefixLists(tls *libc.TLS, p uintptr, p1 uintptr, nBuf int32, aBuf uintptr) {
	bp := tls.Alloc(944)
	defer tls.Free(944)
	var i, nMerge, nOut, nTail, nTmp int32
	var iLastRowid Ti64
	var pI, pNext, pSave, pThis, pThis1, pX uintptr
	var _ /* aMerger at bp+0 */ [16]TPrefixMerger
	var _ /* iPrev at bp+928 */ Ti64
	var _ /* out at bp+900 */ TFts5Buffer
	var _ /* pHead at bp+896 */ uintptr
	var _ /* tmp at bp+912 */ TFts5Buffer
	_, _, _, _, _, _, _, _, _, _, _, _ = i, iLastRowid, nMerge, nOut, nTail, nTmp, pI, pNext, pSave, pThis, pThis1, pX
	*(*uintptr)(unsafe.Pointer(bp + 896)) = uintptr(0)
	nOut = 0
	*(*TFts5Buffer)(unsafe.Pointer(bp + 900)) = TFts5Buffer{}
	*(*TFts5Buffer)(unsafe.Pointer(bp + 912)) = TFts5Buffer{}
	iLastRowid = 0
	/* Initialize a doclist-iterator for each input buffer. Arrange them in
	 ** a linked-list starting at pHead in ascending order of rowid. Avoid
	 ** linking any iterators already at EOF into the linked list at all. */
	libc.Xmemset(tls, bp, 0, uint32(56)*uint32(nBuf+libc.Int32FromInt32(1)))
	*(*uintptr)(unsafe.Pointer(bp + 896)) = bp + uintptr(nBuf)*56
	_fts5DoclistIterInit(tls, p1, *(*uintptr)(unsafe.Pointer(bp + 896)))
	i = 0
	for {
		if !(i < nBuf) {
			break
		}
		_fts5DoclistIterInit(tls, aBuf+uintptr(i)*12, bp+uintptr(i)*56)
		_fts5PrefixMergerInsertByRowid(tls, bp+896, bp+uintptr(i)*56)
		nOut += (*(*TFts5Buffer)(unsafe.Pointer(aBuf + uintptr(i)*12))).Fn
		goto _1
	_1:
		;
		i++
	}
	if nOut == 0 {
		return
	}
	nOut += (*TFts5Buffer)(unsafe.Pointer(p1)).Fn + int32(9) + int32(10)*nBuf
	/* The maximum size of the output is equal to the sum of the
	 ** input sizes + 1 varint (9 bytes). The extra varint is because if the
	 ** first rowid in one input is a large negative number, and the first in
	 ** the other a non-negative number, the delta for the non-negative
	 ** number will be larger on disk than the literal integer value
	 ** was.
	 **
	 ** Or, if the input position-lists are corrupt, then the output might
	 ** include up to (nBuf+1) extra 10-byte positions created by interpreting -1
	 ** (the value PoslistNext64() uses for EOF) as a position and appending
	 ** it to the output. This can happen at most once for each input
	 ** position-list, hence (nBuf+1) 10 byte paddings.  */
	if _sqlite3Fts5BufferSize(tls, p+44, bp+900, uint32(uint32(nOut))) != 0 {
		return
	}
	for *(*uintptr)(unsafe.Pointer(bp + 896)) != 0 {
		*(*int32)(unsafe.Pointer(bp + 900 + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+900)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+900)).Fn), uint64((*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).Fiter.FiRowid)-uint64(iLastRowid))
		iLastRowid = (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).Fiter.FiRowid
		if (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FpNext != 0 && iLastRowid == (*TPrefixMerger)(unsafe.Pointer((*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FpNext)).Fiter.FiRowid {
			/* Merge data from two or more poslists */
			*(*Ti64)(unsafe.Pointer(bp + 928)) = 0
			nTmp = int32(FTS5_DATA_ZERO_PADDING)
			nMerge = 0
			pSave = *(*uintptr)(unsafe.Pointer(bp + 896))
			pThis = uintptr(0)
			nTail = 0
			*(*uintptr)(unsafe.Pointer(bp + 896)) = uintptr(0)
			for pSave != 0 && (*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FiRowid == iLastRowid {
				pNext = (*TPrefixMerger)(unsafe.Pointer(pSave)).FpNext
				(*TPrefixMerger)(unsafe.Pointer(pSave)).FiOff = 0
				(*TPrefixMerger)(unsafe.Pointer(pSave)).FiPos = 0
				(*TPrefixMerger)(unsafe.Pointer(pSave)).FaPos = (*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FaPoslist + uintptr((*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnSize)
				_sqlite3Fts5PoslistNext64(tls, (*TPrefixMerger)(unsafe.Pointer(pSave)).FaPos, (*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnPoslist, pSave+40, pSave+32)
				nTmp += (*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnPoslist + int32(10)
				nMerge++
				_fts5PrefixMergerInsertByPosition(tls, bp+896, pSave)
				pSave = pNext
			}
			if *(*uintptr)(unsafe.Pointer(bp + 896)) == uintptr(0) || (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FpNext == uintptr(0) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				break
			}
			/* See the earlier comment in this function for an explanation of why
			 ** corrupt input position lists might cause the output to consume
			 ** at most nMerge*10 bytes of unexpected space. */
			if _sqlite3Fts5BufferSize(tls, p+44, bp+912, uint32(nTmp+nMerge*int32(10))) != 0 {
				break
			}
			_sqlite3Fts5BufferZero(tls, bp+912)
			pThis = *(*uintptr)(unsafe.Pointer(bp + 896))
			*(*uintptr)(unsafe.Pointer(bp + 896)) = (*TPrefixMerger)(unsafe.Pointer(pThis)).FpNext
			_sqlite3Fts5PoslistSafeAppend(tls, bp+912, bp+928, (*TPrefixMerger)(unsafe.Pointer(pThis)).FiPos)
			_sqlite3Fts5PoslistNext64(tls, (*TPrefixMerger)(unsafe.Pointer(pThis)).FaPos, (*TPrefixMerger)(unsafe.Pointer(pThis)).Fiter.FnPoslist, pThis+40, pThis+32)
			_fts5PrefixMergerInsertByPosition(tls, bp+896, pThis)
			for (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FpNext != 0 {
				pThis = *(*uintptr)(unsafe.Pointer(bp + 896))
				if (*TPrefixMerger)(unsafe.Pointer(pThis)).FiPos != *(*Ti64)(unsafe.Pointer(bp + 928)) {
					_sqlite3Fts5PoslistSafeAppend(tls, bp+912, bp+928, (*TPrefixMerger)(unsafe.Pointer(pThis)).FiPos)
				}
				_sqlite3Fts5PoslistNext64(tls, (*TPrefixMerger)(unsafe.Pointer(pThis)).FaPos, (*TPrefixMerger)(unsafe.Pointer(pThis)).Fiter.FnPoslist, pThis+40, pThis+32)
				*(*uintptr)(unsafe.Pointer(bp + 896)) = (*TPrefixMerger)(unsafe.Pointer(pThis)).FpNext
				_fts5PrefixMergerInsertByPosition(tls, bp+896, pThis)
			}
			if (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FiPos != *(*Ti64)(unsafe.Pointer(bp + 928)) {
				_sqlite3Fts5PoslistSafeAppend(tls, bp+912, bp+928, (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FiPos)
			}
			nTail = (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).Fiter.FnPoslist - (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FiOff
			/* WRITEPOSLISTSIZE */
			if (*(*TFts5Buffer)(unsafe.Pointer(bp + 912))).Fn+nTail > nTmp-int32(FTS5_DATA_ZERO_PADDING) {
				if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				break
			}
			*(*int32)(unsafe.Pointer(bp + 900 + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+900)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+900)).Fn), uint64(((*(*TFts5Buffer)(unsafe.Pointer(bp + 912))).Fn+nTail)*libc.Int32FromInt32(2)))
			libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(bp+900)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+900)).Fn), (*(*TFts5Buffer)(unsafe.Pointer(bp + 912))).Fp, uint32((*(*TFts5Buffer)(unsafe.Pointer(bp + 912))).Fn))
			*(*int32)(unsafe.Pointer(bp + 900 + 4)) += (*(*TFts5Buffer)(unsafe.Pointer(bp + 912))).Fn
			if nTail > 0 {
				libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(bp+900)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+900)).Fn), (*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FaPos+uintptr((*TPrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 896)))).FiOff), uint32(uint32(nTail)))
				*(*int32)(unsafe.Pointer(bp + 900 + 4)) += nTail
			}
			*(*uintptr)(unsafe.Pointer(bp + 896)) = pSave
			i = 0
			for {
				if !(i < nBuf+int32(1)) {
					break
				}
				pX = bp + uintptr(i)*56
				if (*TPrefixMerger)(unsafe.Pointer(pX)).Fiter.FaPoslist != 0 && (*TPrefixMerger)(unsafe.Pointer(pX)).Fiter.FiRowid == iLastRowid {
					_fts5DoclistIterNext(tls, pX)
					_fts5PrefixMergerInsertByRowid(tls, bp+896, pX)
				}
				goto _2
			_2:
				;
				i++
			}
		} else {
			/* Copy poslist from pHead to output */
			pThis1 = *(*uintptr)(unsafe.Pointer(bp + 896))
			pI = pThis1
			libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(bp+900)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+900)).Fn), (*TFts5DoclistIter)(unsafe.Pointer(pI)).FaPoslist, uint32((*TFts5DoclistIter)(unsafe.Pointer(pI)).FnPoslist+(*TFts5DoclistIter)(unsafe.Pointer(pI)).FnSize))
			*(*int32)(unsafe.Pointer(bp + 900 + 4)) += (*TFts5DoclistIter)(unsafe.Pointer(pI)).FnPoslist + (*TFts5DoclistIter)(unsafe.Pointer(pI)).FnSize
			_fts5DoclistIterNext(tls, pI)
			*(*uintptr)(unsafe.Pointer(bp + 896)) = (*TPrefixMerger)(unsafe.Pointer(pThis1)).FpNext
			_fts5PrefixMergerInsertByRowid(tls, bp+896, pThis1)
		}
	}
	_sqlite3Fts5BufferFree(tls, p1)
	_sqlite3Fts5BufferFree(tls, bp+912)
	libc.Xmemset(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp + 900))).Fp+uintptr((*(*TFts5Buffer)(unsafe.Pointer(bp + 900))).Fn), 0, uint32(FTS5_DATA_ZERO_PADDING))
	*(*TFts5Buffer)(unsafe.Pointer(p1)) = *(*TFts5Buffer)(unsafe.Pointer(bp + 900))
}

func _fts5SetupPrefixIter(tls *libc.TLS, p uintptr, bDesc int32, iIdx int32, pToken uintptr, nToken int32, pColset uintptr, ppIter uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aBuf, pData, pSeg, pSeg1, pStruct, pTerm, xAppend, xMerge uintptr
	var f2, flags, i, i1, iFree, iStore, nBuf, nMerge, nTerm, v8 int32
	var iLastRowid Ti64
	var _ /* bNewTerm at bp+16 */ int32
	var _ /* doclist at bp+4 */ TFts5Buffer
	var _ /* dummy at bp+20 */ int32
	var _ /* p1 at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aBuf, f2, flags, i, i1, iFree, iLastRowid, iStore, nBuf, nMerge, nTerm, pData, pSeg, pSeg1, pStruct, pTerm, xAppend, xMerge, v8
	nBuf = int32(32)
	nMerge = int32(1)
	if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
		xMerge = __ccgo_fp(_fts5MergeRowidLists)
		xAppend = __ccgo_fp(_fts5AppendRowid)
	} else {
		nMerge = libc.Int32FromInt32(FTS5_MERGE_NLIST) - libc.Int32FromInt32(1)
		nBuf = nMerge * int32(8) /* Sufficient to merge (16^8)==(2^32) lists */
		xMerge = __ccgo_fp(_fts5MergePrefixLists)
		xAppend = __ccgo_fp(_fts5AppendPoslist)
	}
	aBuf = _fts5IdxMalloc(tls, p, int64(uint32(12)*uint32(uint32(nBuf))))
	pStruct = _fts5StructureRead(tls, p)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		flags = libc.Int32FromInt32(FTS5INDEX_QUERY_SCAN) | libc.Int32FromInt32(FTS5INDEX_QUERY_SKIPEMPTY) | libc.Int32FromInt32(FTS5INDEX_QUERY_NOOUTPUT)
		iLastRowid = 0
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		*(*int32)(unsafe.Pointer(bp + 16)) = int32(1)
		libc.Xmemset(tls, bp+4, 0, uint32(12))
		/* If iIdx is non-zero, then it is the number of a prefix-index for
		 ** prefixes 1 character longer than the prefix being queried for. That
		 ** index contains all the doclists required, except for the one
		 ** corresponding to the prefix itself. That one is extracted from the
		 ** main term index here.  */
		if iIdx != 0 {
			*(*int32)(unsafe.Pointer(bp + 20)) = 0
			f2 = libc.Int32FromInt32(FTS5INDEX_QUERY_SKIPEMPTY) | libc.Int32FromInt32(FTS5INDEX_QUERY_NOOUTPUT)
			*(*Tu8)(unsafe.Pointer(pToken)) = uint8('0')
			_fts5MultiIterNew(tls, p, pStruct, f2, pColset, pToken, nToken, -int32(1), 0, bp)
			_fts5IterSetOutputCb(tls, p+44, *(*uintptr)(unsafe.Pointer(bp)))
			for {
				if !(_fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp))) == 0) {
					break
				}
				pSeg = *(*uintptr)(unsafe.Pointer(bp)) + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFirst + 1*4))).FiFirst)*104
				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxSetOutputs})))(tls, *(*uintptr)(unsafe.Pointer(bp)), pSeg)
				if (*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FnData != 0 {
					(*(*func(*libc.TLS, uintptr, Tu64, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{xAppend})))(tls, p, uint64((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FiRowid)-uint64(uint64(iLastRowid)), *(*uintptr)(unsafe.Pointer(bp)), bp+4)
					iLastRowid = (*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FiRowid
				}
				goto _1
			_1:
				;
				_fts5MultiIterNext2(tls, p, *(*uintptr)(unsafe.Pointer(bp)), bp+20)
			}
			_fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		*(*Tu8)(unsafe.Pointer(pToken)) = uint8(int32('0') + iIdx)
		_fts5MultiIterNew(tls, p, pStruct, flags, pColset, pToken, nToken, -int32(1), 0, bp)
		_fts5IterSetOutputCb(tls, p+44, *(*uintptr)(unsafe.Pointer(bp)))
		for {
			if !(_fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp))) == 0) {
				break
			}
			pSeg1 = *(*uintptr)(unsafe.Pointer(bp)) + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFirst + 1*4))).FiFirst)*104
			nTerm = (*TFts5SegIter)(unsafe.Pointer(pSeg1)).Fterm.Fn
			pTerm = (*TFts5SegIter)(unsafe.Pointer(pSeg1)).Fterm.Fp
			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxSetOutputs})))(tls, *(*uintptr)(unsafe.Pointer(bp)), pSeg1)
			if *(*int32)(unsafe.Pointer(bp + 16)) != 0 {
				if nTerm < nToken || libc.Xmemcmp(tls, pToken, pTerm, uint32(uint32(nToken))) != 0 {
					break
				}
			}
			if (*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FnData == 0 {
				goto _2
			}
			if (*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FiRowid <= iLastRowid && (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fn > 0 {
				i = 0
				for {
					if !((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fn != 0) {
						break
					}
					i1 = i * nMerge
					iStore = i1
					for {
						if !(iStore < i1+nMerge) {
							break
						}
						if (*(*TFts5Buffer)(unsafe.Pointer(aBuf + uintptr(iStore)*12))).Fn == 0 {
							_fts5BufferSwap(tls, bp+4, aBuf+uintptr(iStore)*12)
							_sqlite3Fts5BufferZero(tls, bp+4)
							break
						}
						goto _4
					_4:
						;
						iStore++
					}
					if iStore == i1+nMerge {
						(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{xMerge})))(tls, p, bp+4, nMerge, aBuf+uintptr(i1)*12)
						iStore = i1
						for {
							if !(iStore < i1+nMerge) {
								break
							}
							_sqlite3Fts5BufferZero(tls, aBuf+uintptr(iStore)*12)
							goto _5
						_5:
							;
							iStore++
						}
					}
					goto _3
				_3:
					;
					i++
				}
				iLastRowid = 0
			}
			(*(*func(*libc.TLS, uintptr, Tu64, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{xAppend})))(tls, p, uint64((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FiRowid)-uint64(uint64(iLastRowid)), *(*uintptr)(unsafe.Pointer(bp)), bp+4)
			iLastRowid = (*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FiRowid
			goto _2
		_2:
			;
			_fts5MultiIterNext2(tls, p, *(*uintptr)(unsafe.Pointer(bp)), bp+16)
		}
		i = 0
		for {
			if !(i < nBuf) {
				break
			}
			if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{xMerge})))(tls, p, bp+4, nMerge, aBuf+uintptr(i)*12)
			}
			iFree = i
			for {
				if !(iFree < i+nMerge) {
					break
				}
				_sqlite3Fts5BufferFree(tls, aBuf+uintptr(iFree)*12)
				goto _7
			_7:
				;
				iFree++
			}
			goto _6
		_6:
			;
			i += nMerge
		}
		_fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
		pData = _fts5IdxMalloc(tls, p, int64(uint32(12)+uint32((*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fn)+uint32(FTS5_DATA_ZERO_PADDING)))
		if pData != 0 {
			(*TFts5Data)(unsafe.Pointer(pData)).Fp = pData + 1*12
			v8 = (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fn
			(*TFts5Data)(unsafe.Pointer(pData)).FszLeaf = v8
			(*TFts5Data)(unsafe.Pointer(pData)).Fnn = v8
			if (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fn != 0 {
				libc.Xmemcpy(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp, uint32((*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fn))
			}
			_fts5MultiIterNew2(tls, p, pData, bDesc, ppIter)
		}
		_sqlite3Fts5BufferFree(tls, bp+4)
	}
	_fts5StructureRelease(tls, pStruct)
	Xsqlite3_free(tls, aBuf)
}

// C documentation
//
//	/*
//	** Indicate that all subsequent calls to sqlite3Fts5IndexWrite() pertain
//	** to the document with rowid iRowid.
//	*/
func _sqlite3Fts5IndexBeginWrite(tls *libc.TLS, p uintptr, bDelete int32, iRowid Ti64) (r int32) {
	/* Allocate the hash table if it has not already been allocated */
	if (*TFts5Index)(unsafe.Pointer(p)).FpHash == uintptr(0) {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5HashNew(tls, (*TFts5Index)(unsafe.Pointer(p)).FpConfig, p+12, p+16)
	}
	/* Flush the hash table to disk if required */
	if iRowid < (*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid || iRowid == (*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid && (*TFts5Index)(unsafe.Pointer(p)).FbDelete == 0 || (*TFts5Index)(unsafe.Pointer(p)).FnPendingData > (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnHashSize {
		_fts5IndexFlush(tls, p)
	}
	(*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid = iRowid
	(*TFts5Index)(unsafe.Pointer(p)).FbDelete = bDelete
	if bDelete == 0 {
		(*TFts5Index)(unsafe.Pointer(p)).FnPendingRow++
	}
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Commit data to disk.
//	*/
func _sqlite3Fts5IndexSync(tls *libc.TLS, p uintptr) (r int32) {
	_fts5IndexFlush(tls, p)
	_sqlite3Fts5IndexCloseReader(tls, p)
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Discard any data stored in the in-memory hash tables. Do not write it
//	** to the database. Additionally, assume that the contents of the %_data
//	** table may have changed on disk. So any in-memory caches of %_data
//	** records must be invalidated.
//	*/
func _sqlite3Fts5IndexRollback(tls *libc.TLS, p uintptr) (r int32) {
	_sqlite3Fts5IndexCloseReader(tls, p)
	_fts5IndexDiscardData(tls, p)
	_fts5StructureInvalidate(tls, p)
	/* assert( p->rc==SQLITE_OK ); */
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The %_data table is completely empty when this function is called. This
//	** function populates it with the initial structure objects for each index,
//	** and the initial version of the "averages" record (a zero-byte blob).
//	*/
func _sqlite3Fts5IndexReinit(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* s at bp+0 */ TFts5Structure
	_fts5StructureInvalidate(tls, p)
	_fts5IndexDiscardData(tls, p)
	libc.Xmemset(tls, bp, 0, uint32(48))
	if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FbContentlessDelete != 0 {
		(*(*TFts5Structure)(unsafe.Pointer(bp))).FnOriginCntr = uint64(1)
	}
	_fts5DataWrite(tls, p, int64(FTS5_AVERAGES_ROWID), __ccgo_ts+1672, 0)
	_fts5StructureWrite(tls, p, bp)
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Open a new Fts5Index handle. If the bCreate argument is true, create
//	** and initialize the underlying %_data table.
//	**
//	** If successful, set *pp to point to the new object and return SQLITE_OK.
//	** Otherwise, set *pp to NULL and return an SQLite error code.
//	*/
func _sqlite3Fts5IndexOpen(tls *libc.TLS, pConfig uintptr, bCreate int32, pp uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p, v1 uintptr
	var _ /* rc at bp+0 */ int32
	_, _ = p, v1
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK /* New object */
	v1 = _sqlite3Fts5MallocZero(tls, bp, int64(112))
	p = v1
	*(*uintptr)(unsafe.Pointer(pp)) = v1
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*TFts5Index)(unsafe.Pointer(p)).FpConfig = pConfig
		(*TFts5Index)(unsafe.Pointer(p)).FnWorkUnit = int32(FTS5_WORK_UNIT)
		(*TFts5Index)(unsafe.Pointer(p)).FzDataTbl = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38103, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
		if (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl != 0 && bCreate != 0 {
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+27220, __ccgo_ts+38111, 0, pzErr)
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+13227, __ccgo_ts+38146, int32(1), pzErr)
			}
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5IndexReinit(tls, p)
			}
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		_sqlite3Fts5IndexClose(tls, p)
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Close a handle opened by an earlier call to sqlite3Fts5IndexOpen().
//	*/
func _sqlite3Fts5IndexClose(tls *libc.TLS, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if p != 0 {
		_fts5StructureInvalidate(tls, p)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxNextSelect)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion)
		Xsqlite3_finalize(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx)
		_sqlite3Fts5HashFree(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash)
		Xsqlite3_free(tls, (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl)
		Xsqlite3_free(tls, p)
	}
	return rc
}

// C documentation
//
//	/*
//	** Argument p points to a buffer containing utf-8 text that is n bytes in
//	** size. Return the number of bytes in the nChar character prefix of the
//	** buffer, or 0 if there are less than nChar characters in total.
//	*/
func _sqlite3Fts5IndexCharlenToBytelen(tls *libc.TLS, p uintptr, nByte int32, nChar int32) (r int32) {
	var i, n, v2 int32
	_, _, _ = i, n, v2
	n = 0
	i = 0
	for {
		if !(i < nChar) {
			break
		}
		if n >= nByte {
			return 0
		} /* Input contains fewer than nChar chars */
		v2 = n
		n++
		if int32(uint8(*(*int8)(unsafe.Pointer(p + uintptr(v2))))) >= int32(0xc0) {
			if n >= nByte {
				return 0
			}
			for int32(*(*int8)(unsafe.Pointer(p + uintptr(n))))&int32(0xc0) == int32(0x80) {
				n++
				if n >= nByte {
					if i+int32(1) == nChar {
						break
					}
					return 0
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	return n
}

// C documentation
//
//	/*
//	** pIn is a UTF-8 encoded string, nIn bytes in size. Return the number of
//	** unicode characters in the string.
//	*/
func _fts5IndexCharlen(tls *libc.TLS, pIn uintptr, nIn int32) (r int32) {
	var i, nChar, v1 int32
	_, _, _ = i, nChar, v1
	nChar = 0
	i = 0
	for i < nIn {
		v1 = i
		i++
		if int32(uint8(*(*int8)(unsafe.Pointer(pIn + uintptr(v1))))) >= int32(0xc0) {
			for i < nIn && int32(*(*int8)(unsafe.Pointer(pIn + uintptr(i))))&int32(0xc0) == int32(0x80) {
				i++
			}
		}
		nChar++
	}
	return nChar
}

// C documentation
//
//	/*
//	** Insert or remove data to or from the index. Each time a document is
//	** added to or removed from the index, this function is called one or more
//	** times.
//	**
//	** For an insert, it must be called once for each token in the new document.
//	** If the operation is a delete, it must be called (at least) once for each
//	** unique token in the document with an iCol value less than zero. The iPos
//	** argument is ignored for a delete.
//	*/
func _sqlite3Fts5IndexWrite(tls *libc.TLS, p uintptr, iCol int32, iPos int32, pToken uintptr, nToken int32) (r int32) {
	var i, nByte, nChar, rc int32
	var pConfig uintptr
	_, _, _, _, _ = i, nByte, nChar, pConfig, rc /* Used to iterate through indexes */
	rc = SQLITE_OK                               /* Return code */
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
	/* Add the entry to the main terms index. */
	rc = _sqlite3Fts5HashWrite(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash, (*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid, iCol, iPos, int8('0'), pToken, nToken)
	i = 0
	for {
		if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix && rc == SQLITE_OK) {
			break
		}
		nChar = *(*int32)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr(i)*4))
		nByte = _sqlite3Fts5IndexCharlenToBytelen(tls, pToken, nToken, nChar)
		if nByte != 0 {
			rc = _sqlite3Fts5HashWrite(tls, (*TFts5Index)(unsafe.Pointer(p)).FpHash, (*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid, iCol, iPos, int8(libc.Int32FromUint8('0')+i+libc.Int32FromInt32(1)), pToken, nByte)
		}
		goto _1
	_1:
		;
		i++
	}
	return rc
}

// C documentation
//
//	/*
//	** pToken points to a buffer of size nToken bytes containing a search
//	** term, including the index number at the start, used on a tokendata=1
//	** table. This function returns true if the term in buffer pBuf matches
//	** token pToken/nToken.
//	*/
func _fts5IsTokendataPrefix(tls *libc.TLS, pBuf uintptr, pToken uintptr, nToken int32) (r int32) {
	return libc.BoolInt32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn >= nToken && 0 == libc.Xmemcmp(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp, pToken, uint32(uint32(nToken))) && ((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn == nToken || int32(*(*Tu8)(unsafe.Pointer((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(nToken)))) == 0x00))
}

// C documentation
//
//	/*
//	** Ensure the segment-iterator passed as the only argument points to EOF.
//	*/
func _fts5SegIterSetEOF(tls *libc.TLS, pSeg uintptr) {
	_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)
	(*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf = uintptr(0)
}

/*
** Usually, a tokendata=1 iterator (struct Fts5TokenDataIter) accumulates an
** array of these for each row it visits. Or, for an iterator used by an
** "ORDER BY rank" query, it accumulates an array of these for the entire
** query.
**
** Each instance in the array indicates the iterator (and therefore term)
** associated with position iPos of rowid iRowid. This is used by the
** xInstToken() API.
 */
type TFts5TokenDataMap1 = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FiPos         Ti64
	FiIter        int32
	F__ccgo_pad3  [4]byte
}

type Fts5TokenDataMap1 = TFts5TokenDataMap1

/*
** An object used to supplement Fts5Iter for tokendata=1 iterators.
 */
type TFts5TokenDataIter1 = struct {
	FnIter          int32
	FnIterAlloc     int32
	FnMap           int32
	FnMapAlloc      int32
	FaMap           uintptr
	FaPoslistReader uintptr
	FaPoslistToIter uintptr
	FapIter         [1]uintptr
}

type Fts5TokenDataIter1 = TFts5TokenDataIter1

// C documentation
//
//	/*
//	** This function appends iterator pAppend to Fts5TokenDataIter pIn and
//	** returns the result.
//	*/
func _fts5AppendTokendataIter(tls *libc.TLS, p uintptr, pIn uintptr, pAppend uintptr) (r uintptr) {
	var nAlloc, nByte, v1, v2 int32
	var pNew, pRet, v3 uintptr
	_, _, _, _, _, _, _ = nAlloc, nByte, pNew, pRet, v1, v2, v3
	pRet = pIn
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if pIn == uintptr(0) || (*TFts5TokenDataIter)(unsafe.Pointer(pIn)).FnIter == (*TFts5TokenDataIter)(unsafe.Pointer(pIn)).FnIterAlloc {
			if pIn != 0 {
				v1 = (*TFts5TokenDataIter)(unsafe.Pointer(pIn)).FnIterAlloc * int32(2)
			} else {
				v1 = int32(16)
			}
			nAlloc = v1
			nByte = int32(uint32(uint32(nAlloc))*uint32(4) + uint32(32))
			pNew = Xsqlite3_realloc(tls, pIn, nByte)
			if pNew == uintptr(0) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
			} else {
				if pIn == uintptr(0) {
					libc.Xmemset(tls, pNew, 0, uint32(uint32(nByte)))
				}
				pRet = pNew
				(*TFts5TokenDataIter)(unsafe.Pointer(pNew)).FnIterAlloc = nAlloc
			}
		}
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
		_sqlite3Fts5IterClose(tls, pAppend)
	} else {
		v3 = pRet
		v2 = *(*int32)(unsafe.Pointer(v3))
		*(*int32)(unsafe.Pointer(v3))++
		*(*uintptr)(unsafe.Pointer(pRet + 28 + uintptr(v2)*4)) = pAppend
	}
	return pRet
}

// C documentation
//
//	/*
//	** Delete an Fts5TokenDataIter structure and its contents.
//	*/
func _fts5TokendataIterDelete(tls *libc.TLS, pSet uintptr) {
	var ii int32
	_ = ii
	if pSet != 0 {
		ii = 0
		for {
			if !(ii < (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter) {
				break
			}
			_fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(pSet + 28 + uintptr(ii)*4)))
			goto _1
		_1:
			;
			ii++
		}
		Xsqlite3_free(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FaPoslistReader)
		Xsqlite3_free(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FaMap)
		Xsqlite3_free(tls, pSet)
	}
}

// C documentation
//
//	/*
//	** Append a mapping to the token-map belonging to object pT.
//	*/
func _fts5TokendataIterAppendMap(tls *libc.TLS, p uintptr, pT uintptr, iIter int32, iRowid Ti64, iPos Ti64) {
	var aNew uintptr
	var nByte, nNew, v1 int32
	_, _, _, _ = aNew, nByte, nNew, v1
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap == (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMapAlloc {
			if (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMapAlloc != 0 {
				v1 = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMapAlloc * int32(2)
			} else {
				v1 = int32(64)
			}
			nNew = v1
			nByte = int32(uint32(uint32(nNew)) * uint32(24))
			aNew = Xsqlite3_realloc(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap, nByte)
			if aNew == uintptr(0) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
				return
			}
			(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap = aNew
			(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMapAlloc = nNew
		}
		(*(*TFts5TokenDataMap)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap)*24))).FiRowid = iRowid
		(*(*TFts5TokenDataMap)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap)*24))).FiPos = iPos
		(*(*TFts5TokenDataMap)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap)*24))).FiIter = iIter
		(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap++
	}
}

// C documentation
//
//	/*
//	** The iterator passed as the only argument must be a tokendata=1 iterator
//	** (pIter->pTokenDataIter!=0). This function sets the iterator output
//	** variables (pIter->base.*) according to the contents of the current
//	** row.
//	*/
func _fts5IterSetOutputsTokendata(tls *libc.TLS, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aNew, p, p1, pReader, pT uintptr
	var eDetail, iMin, ii, nByte, nHit, nNew, nReader, v3, v4 int32
	var iMinPos, iRowid Ti64
	var _ /* iPrev at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aNew, eDetail, iMin, iMinPos, iRowid, ii, nByte, nHit, nNew, nReader, p, p1, pReader, pT, v3, v4
	nHit = 0
	iRowid = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
	iMin = 0
	pT = (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = 0
	(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = uintptr(0)
	ii = 0
	for {
		if !(ii < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnIter) {
			break
		}
		p = *(*uintptr)(unsafe.Pointer(pT + 28 + uintptr(ii)*4))
		if int32((*TFts5Iter)(unsafe.Pointer(p)).Fbase.FbEof) == 0 {
			if nHit == 0 || (*TFts5Iter)(unsafe.Pointer(p)).Fbase.FiRowid < iRowid {
				iRowid = (*TFts5Iter)(unsafe.Pointer(p)).Fbase.FiRowid
				nHit = int32(1)
				(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(p)).Fbase.FpData
				(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(p)).Fbase.FnData
				iMin = ii
			} else {
				if (*TFts5Iter)(unsafe.Pointer(p)).Fbase.FiRowid == iRowid {
					nHit++
				}
			}
		}
		goto _1
	_1:
		;
		ii++
	}
	if nHit == 0 {
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof = uint8(1)
	} else {
		eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex)).FpConfig)).FeDetail
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof = uint8(0)
		(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = iRowid
		if nHit == int32(1) && eDetail == FTS5_DETAIL_FULL {
			_fts5TokendataIterAppendMap(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex, pT, iMin, iRowid, int64(-int32(1)))
		} else {
			if nHit > int32(1) && eDetail != int32(FTS5_DETAIL_NONE) {
				nReader = 0
				nByte = 0
				*(*Ti64)(unsafe.Pointer(bp)) = 0
				/* Allocate array of iterators if they are not already allocated. */
				if (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistReader == uintptr(0) {
					(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistReader = _sqlite3Fts5MallocZero(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex+44, int64(uint32((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnIter)*(libc.Uint32FromInt64(24)+libc.Uint32FromInt64(4))))
					if (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistReader == uintptr(0) {
						return
					}
					(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistToIter = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistReader + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnIter)*24
				}
				/* Populate an iterator for each poslist that will be merged */
				ii = 0
				for {
					if !(ii < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnIter) {
						break
					}
					p1 = *(*uintptr)(unsafe.Pointer(pT + 28 + uintptr(ii)*4))
					if iRowid == (*TFts5Iter)(unsafe.Pointer(p1)).Fbase.FiRowid {
						*(*int32)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistToIter + uintptr(nReader)*4)) = ii
						v3 = nReader
						nReader++
						_sqlite3Fts5PoslistReaderInit(tls, (*TFts5Iter)(unsafe.Pointer(p1)).Fbase.FpData, (*TFts5Iter)(unsafe.Pointer(p1)).Fbase.FnData, (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistReader+uintptr(v3)*24)
						nByte += (*TFts5Iter)(unsafe.Pointer(p1)).Fbase.FnData
					}
					goto _2
				_2:
					;
					ii++
				}
				/* Ensure the output buffer is large enough */
				if uint32((*TFts5Buffer)(unsafe.Pointer(pIter+32)).Fn)+uint32(nByte+nHit*libc.Int32FromInt32(10)) <= uint32((*TFts5Buffer)(unsafe.Pointer(pIter+32)).FnSpace) {
					v4 = 0
				} else {
					v4 = _sqlite3Fts5BufferSize(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex+44, pIter+32, uint32(nByte+nHit*int32(10)+(*TFts5Buffer)(unsafe.Pointer(pIter+32)).Fn))
				}
				if v4 != 0 {
					return
				}
				/* Ensure the token-mapping is large enough */
				if eDetail == FTS5_DETAIL_FULL && (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMapAlloc < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap+nByte {
					nNew = ((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMapAlloc + nByte) * int32(2)
					aNew = Xsqlite3_realloc(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap, int32(uint32(uint32(nNew))*uint32(24)))
					if aNew == uintptr(0) {
						(*TFts5Index)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex)).Frc = int32(SQLITE_NOMEM)
						return
					}
					(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap = aNew
					(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMapAlloc = nNew
				}
				(*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn = 0
				for int32(1) != 0 {
					iMinPos = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
					/* Find smallest position */
					iMin = 0
					ii = 0
					for {
						if !(ii < nReader) {
							break
						}
						pReader = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistReader + uintptr(ii)*24
						if int32((*TFts5PoslistReader)(unsafe.Pointer(pReader)).FbEof) == 0 {
							if (*TFts5PoslistReader)(unsafe.Pointer(pReader)).FiPos < iMinPos {
								iMinPos = (*TFts5PoslistReader)(unsafe.Pointer(pReader)).FiPos
								iMin = ii
							}
						}
						goto _5
					_5:
						;
						ii++
					}
					/* If all readers were at EOF, break out of the loop. */
					if iMinPos == libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32) {
						break
					}
					_sqlite3Fts5PoslistSafeAppend(tls, pIter+32, bp, iMinPos)
					_sqlite3Fts5PoslistReaderNext(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistReader+uintptr(iMin)*24)
					if eDetail == FTS5_DETAIL_FULL {
						(*(*TFts5TokenDataMap)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap)*24))).FiPos = iMinPos
						(*(*TFts5TokenDataMap)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap)*24))).FiIter = *(*int32)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaPoslistToIter + uintptr(iMin)*4))
						(*(*TFts5TokenDataMap)(unsafe.Pointer((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap)*24))).FiRowid = iRowid
						(*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap++
					}
				}
				(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
				(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
			}
		}
	}
}

// C documentation
//
//	/*
//	** The iterator passed as the only argument must be a tokendata=1 iterator
//	** (pIter->pTokenDataIter!=0). This function advances the iterator. If
//	** argument bFrom is false, then the iterator is advanced to the next
//	** entry. Or, if bFrom is true, it is advanced to the first entry with
//	** a rowid of iFrom or greater.
//	*/
func _fts5TokendataIterNext(tls *libc.TLS, pIter uintptr, bFrom int32, iFrom Ti64) {
	var ii int32
	var p, pIndex, pT uintptr
	_, _, _, _ = ii, p, pIndex, pT
	pT = (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter
	pIndex = (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex
	ii = 0
	for {
		if !(ii < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnIter) {
			break
		}
		p = *(*uintptr)(unsafe.Pointer(pT + 28 + uintptr(ii)*4))
		if int32((*TFts5Iter)(unsafe.Pointer(p)).Fbase.FbEof) == 0 && ((*TFts5Iter)(unsafe.Pointer(p)).Fbase.FiRowid == (*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid || bFrom != 0 && (*TFts5Iter)(unsafe.Pointer(p)).Fbase.FiRowid < iFrom) {
			_fts5MultiIterNext(tls, pIndex, p, bFrom, iFrom)
			for bFrom != 0 && int32((*TFts5Iter)(unsafe.Pointer(p)).Fbase.FbEof) == 0 && (*TFts5Iter)(unsafe.Pointer(p)).Fbase.FiRowid < iFrom && (*TFts5Index)(unsafe.Pointer(pIndex)).Frc == SQLITE_OK {
				_fts5MultiIterNext(tls, pIndex, p, 0, 0)
			}
		}
		goto _1
	_1:
		;
		ii++
	}
	if (*TFts5Index)(unsafe.Pointer(pIndex)).Frc == SQLITE_OK {
		_fts5IterSetOutputsTokendata(tls, pIter)
	}
}

// C documentation
//
//	/*
//	** If the segment-iterator passed as the first argument is at EOF, then
//	** set pIter->term to a copy of buffer pTerm.
//	*/
func _fts5TokendataSetTermIfEof(tls *libc.TLS, pIter uintptr, pTerm uintptr) {
	if pIter != 0 && (*(*TFts5SegIter)(unsafe.Pointer(pIter + 80))).FpLeaf == uintptr(0) {
		_sqlite3Fts5BufferSet(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex+44, pIter+80+72, (*TFts5Buffer)(unsafe.Pointer(pTerm)).Fn, (*TFts5Buffer)(unsafe.Pointer(pTerm)).Fp)
	}
}

// C documentation
//
//	/*
//	** This function sets up an iterator to use for a non-prefix query on a
//	** tokendata=1 table.
//	*/
func _fts5SetupTokendataIter(tls *libc.TLS, p uintptr, pToken uintptr, nToken int32, pColset uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bDone, flags, iLvl, iSeg, iSeg1, ii, ii1 int32
	var pII, pIter, pNew, pNewIter, pPrev, pPrevIter, pRet, pSeg, pSet, pSmall, pStruct, v1, v2 uintptr
	var _ /* bSeek at bp+0 */ TFts5Buffer
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDone, flags, iLvl, iSeg, iSeg1, ii, ii1, pII, pIter, pNew, pNewIter, pPrev, pPrevIter, pRet, pSeg, pSet, pSmall, pStruct, v1, v2
	pRet = uintptr(0)
	pSet = uintptr(0)
	pStruct = uintptr(0)
	flags = libc.Int32FromInt32(FTS5INDEX_QUERY_SCANONETERM) | libc.Int32FromInt32(FTS5INDEX_QUERY_SCAN)
	*(*TFts5Buffer)(unsafe.Pointer(bp)) = TFts5Buffer{}
	pSmall = uintptr(0)
	_fts5IndexFlush(tls, p)
	pStruct = _fts5StructureRead(tls, p)
	for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if pSet != 0 {
			v1 = *(*uintptr)(unsafe.Pointer(pSet + 28 + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter-int32(1))*4))
		} else {
			v1 = uintptr(0)
		}
		pPrev = v1
		pNew = uintptr(0)
		pNewIter = uintptr(0)
		pPrevIter = uintptr(0)
		pNew = _fts5MultiIterAlloc(tls, p, (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment)
		if pSmall != 0 {
			_sqlite3Fts5BufferSet(tls, p+44, bp, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fn, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fp)
			_sqlite3Fts5BufferAppendBlob(tls, p+44, bp, uint32(1), __ccgo_ts+38190)
		} else {
			_sqlite3Fts5BufferSet(tls, p+44, bp, nToken, pToken)
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			_sqlite3Fts5IterClose(tls, pNew)
			break
		}
		pNewIter = pNew + 80
		if pPrev != 0 {
			v2 = pPrev + 80
		} else {
			v2 = uintptr(0)
		}
		pPrevIter = v2
		iLvl = 0
		for {
			if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
				break
			}
			iSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FnSeg - int32(1)
			for {
				if !(iSeg >= 0) {
					break
				}
				pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FaSeg + uintptr(iSeg)*56
				bDone = 0
				if pPrevIter != 0 {
					if _fts5BufferCompare(tls, pSmall, pPrevIter+72) != 0 {
						libc.Xmemcpy(tls, pNewIter, pPrevIter, uint32(104))
						libc.Xmemset(tls, pPrevIter, 0, uint32(104))
						bDone = int32(1)
					} else {
						if (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FiEndofDoclist > (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpLeaf)).FszLeaf {
							_fts5SegIterNextInit(tls, p, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn-int32(1), pSeg, pNewIter)
							bDone = int32(1)
						}
					}
				}
				if bDone == 0 {
					_fts5SegIterSeekInit(tls, p, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn, flags, pSeg, pNewIter)
				}
				if pPrevIter != 0 {
					if (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpTombArray != 0 {
						(*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray = (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpTombArray
						(*TFts5TombstoneArray)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray)).FnRef++
					}
				} else {
					_fts5SegIterAllocTombstone(tls, p, pNewIter)
				}
				pNewIter += 104
				if pPrevIter != 0 {
					pPrevIter += 104
				}
				if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
					break
				}
				goto _4
			_4:
				;
				iSeg--
			}
			goto _3
		_3:
			;
			iLvl++
		}
		_fts5TokendataSetTermIfEof(tls, pPrev, pSmall)
		(*TFts5Iter)(unsafe.Pointer(pNew)).FbSkipEmpty = uint8(1)
		(*TFts5Iter)(unsafe.Pointer(pNew)).FpColset = pColset
		_fts5IterSetOutputCb(tls, p+44, pNew)
		/* Loop through all segments in the new iterator. Find the smallest
		 ** term that any segment-iterator points to. Iterator pNew will be
		 ** used for this term. Also, set any iterator that points to a term that
		 ** does not match pToken/nToken to point to EOF */
		pSmall = uintptr(0)
		ii = 0
		for {
			if !(ii < (*TFts5Iter)(unsafe.Pointer(pNew)).FnSeg) {
				break
			}
			pII = pNew + 80 + uintptr(ii)*104
			if 0 == _fts5IsTokendataPrefix(tls, pII+72, pToken, nToken) {
				_fts5SegIterSetEOF(tls, pII)
			}
			if (*TFts5SegIter)(unsafe.Pointer(pII)).FpLeaf != 0 && (!(pSmall != 0) || _fts5BufferCompare(tls, pSmall, pII+72) > 0) {
				pSmall = pII + 72
			}
			goto _5
		_5:
			;
			ii++
		}
		/* If pSmall is still NULL at this point, then the new iterator does
		 ** not point to any terms that match the query. So delete it and break
		 ** out of the loop - all required iterators have been collected.  */
		if pSmall == uintptr(0) {
			_sqlite3Fts5IterClose(tls, pNew)
			break
		}
		/* Append this iterator to the set and continue. */
		pSet = _fts5AppendTokendataIter(tls, p, pSet, pNew)
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && pSet != 0 {
		ii1 = 0
		for {
			if !(ii1 < (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter) {
				break
			}
			pIter = *(*uintptr)(unsafe.Pointer(pSet + 28 + uintptr(ii1)*4))
			iSeg1 = 0
			for {
				if !(iSeg1 < (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg) {
					break
				}
				(*(*TFts5SegIter)(unsafe.Pointer(pIter + 80 + uintptr(iSeg1)*104))).Fflags |= int32(FTS5_SEGITER_ONETERM)
				goto _7
			_7:
				;
				iSeg1++
			}
			_fts5MultiIterFinishSetup(tls, p, pIter)
			goto _6
		_6:
			;
			ii1++
		}
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pRet = _fts5MultiIterAlloc(tls, p, 0)
	}
	if pRet != 0 {
		(*TFts5Iter)(unsafe.Pointer(pRet)).FpTokenDataIter = pSet
		if pSet != 0 {
			_fts5IterSetOutputsTokendata(tls, pRet)
		} else {
			(*TFts5Iter)(unsafe.Pointer(pRet)).Fbase.FbEof = uint8(1)
		}
	} else {
		_fts5TokendataIterDelete(tls, pSet)
	}
	_fts5StructureRelease(tls, pStruct)
	_sqlite3Fts5BufferFree(tls, bp)
	return pRet
}

// C documentation
//
//	/*
//	** Open a new iterator to iterate though all rowid that match the
//	** specified token or token prefix.
//	*/
func _sqlite3Fts5IndexQuery(tls *libc.TLS, p uintptr, pToken uintptr, nToken int32, flags int32, pColset uintptr, ppIter uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bDesc, bTokendata, iIdx, iPrefixIdx, nChar, nIdxChar int32
	var pConfig, pSeg, pStruct uintptr
	var _ /* buf at bp+4 */ TFts5Buffer
	var _ /* pRet at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _ = bDesc, bTokendata, iIdx, iPrefixIdx, nChar, nIdxChar, pConfig, pSeg, pStruct
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*TFts5Buffer)(unsafe.Pointer(bp + 4)) = TFts5Buffer{}
	/* If the QUERY_SCAN flag is set, all other flags must be clear. */
	if _sqlite3Fts5BufferSize(tls, p+44, bp+4, uint32(nToken+int32(1))) == 0 {
		iIdx = 0       /* Index to search */
		iPrefixIdx = 0 /* +1 prefix index */
		bTokendata = (*TFts5Config)(unsafe.Pointer(pConfig)).FbTokendata
		if nToken > 0 {
			libc.Xmemcpy(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp+1, pToken, uint32(uint32(nToken)))
		}
		if flags&(libc.Int32FromInt32(FTS5INDEX_QUERY_NOTOKENDATA)|libc.Int32FromInt32(FTS5INDEX_QUERY_SCAN)) != 0 {
			bTokendata = 0
		}
		/* Figure out which index to search and set iIdx accordingly. If this
		 ** is a prefix query for which there is no prefix index, set iIdx to
		 ** greater than pConfig->nPrefix to indicate that the query will be
		 ** satisfied by scanning multiple terms in the main index.
		 **
		 ** If the QUERY_TEST_NOIDX flag was specified, then this must be a
		 ** prefix-query. Instead of using a prefix-index (if one exists),
		 ** evaluate the prefix query using the main FTS index. This is used
		 ** for internal sanity checking by the integrity-check in debug
		 ** mode only.  */
		if flags&int32(FTS5INDEX_QUERY_PREFIX) != 0 {
			nChar = _fts5IndexCharlen(tls, pToken, nToken)
			iIdx = int32(1)
			for {
				if !(iIdx <= (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix) {
					break
				}
				nIdxChar = *(*int32)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr(iIdx-int32(1))*4))
				if nIdxChar == nChar {
					break
				}
				if nIdxChar == nChar+int32(1) {
					iPrefixIdx = iIdx
				}
				goto _1
			_1:
				;
				iIdx++
			}
		}
		if bTokendata != 0 && iIdx == 0 {
			*(*Tu8)(unsafe.Pointer((*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp)) = uint8('0')
			*(*uintptr)(unsafe.Pointer(bp)) = _fts5SetupTokendataIter(tls, p, (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp, nToken+int32(1), pColset)
		} else {
			if iIdx <= (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix {
				/* Straight index lookup */
				pStruct = _fts5StructureRead(tls, p)
				*(*Tu8)(unsafe.Pointer((*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp)) = uint8(libc.Int32FromUint8('0') + iIdx)
				if pStruct != 0 {
					_fts5MultiIterNew(tls, p, pStruct, flags|int32(FTS5INDEX_QUERY_SKIPEMPTY), pColset, (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp, nToken+int32(1), -int32(1), 0, bp)
					_fts5StructureRelease(tls, pStruct)
				}
			} else {
				/* Scan multiple terms in the main index */
				bDesc = libc.BoolInt32(flags&int32(FTS5INDEX_QUERY_DESC) != 0)
				_fts5SetupPrefixIter(tls, p, bDesc, iPrefixIdx, (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp, nToken+int32(1), pColset, bp)
				if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
				} else {
					_fts5IterSetOutputCb(tls, p+44, *(*uintptr)(unsafe.Pointer(bp)))
					if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						pSeg = *(*uintptr)(unsafe.Pointer(bp)) + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFirst + 1*4))).FiFirst)*104
						if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 {
							(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxSetOutputs})))(tls, *(*uintptr)(unsafe.Pointer(bp)), pSeg)
						}
					}
				}
			}
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			_sqlite3Fts5IterClose(tls, *(*uintptr)(unsafe.Pointer(bp)))
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			_sqlite3Fts5IndexCloseReader(tls, p)
		}
		*(*uintptr)(unsafe.Pointer(ppIter)) = *(*uintptr)(unsafe.Pointer(bp))
		_sqlite3Fts5BufferFree(tls, bp+4)
	}
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Return true if the iterator passed as the only argument is at EOF.
//	*/
//	/*
//	** Move to the next matching rowid.
//	*/
func _sqlite3Fts5IterNext(tls *libc.TLS, pIndexIter uintptr) (r int32) {
	var pIter uintptr
	_ = pIter
	pIter = pIndexIter
	if (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter != 0 {
		_fts5TokendataIterNext(tls, pIter, 0, 0)
	} else {
		_fts5MultiIterNext(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex, pIter, 0, 0)
	}
	return _fts5IndexReturn(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex)
}

// C documentation
//
//	/*
//	** Move to the next matching term/rowid. Used by the fts5vocab module.
//	*/
func _sqlite3Fts5IterNextScan(tls *libc.TLS, pIndexIter uintptr) (r int32) {
	var p, pIter, pSeg uintptr
	_, _, _ = p, pIter, pSeg
	pIter = pIndexIter
	p = (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex
	_fts5MultiIterNext(tls, p, pIter, 0, 0)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pSeg = pIter + 80 + uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4))).FiFirst)*104
		if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 && int32(*(*Tu8)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp))) != int32('0') {
			_fts5DataRelease(tls, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)
			(*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf = uintptr(0)
			(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof = uint8(1)
		}
	}
	return _fts5IndexReturn(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex)
}

// C documentation
//
//	/*
//	** Move to the next matching rowid that occurs at or after iMatch. The
//	** definition of "at or after" depends on whether this iterator iterates
//	** in ascending or descending rowid order.
//	*/
func _sqlite3Fts5IterNextFrom(tls *libc.TLS, pIndexIter uintptr, iMatch Ti64) (r int32) {
	var pIter uintptr
	_ = pIter
	pIter = pIndexIter
	if (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter != 0 {
		_fts5TokendataIterNext(tls, pIter, int32(1), iMatch)
	} else {
		_fts5MultiIterNextFrom(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex, pIter, iMatch)
	}
	return _fts5IndexReturn(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex)
}

// C documentation
//
//	/*
//	** Return the current term.
//	*/
func _sqlite3Fts5IterTerm(tls *libc.TLS, pIndexIter uintptr, pn uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var z, v1 uintptr
	var _ /* n at bp+0 */ int32
	_, _ = z, v1
	z = _fts5MultiIterTerm(tls, pIndexIter, bp)
	*(*int32)(unsafe.Pointer(pn)) = *(*int32)(unsafe.Pointer(bp)) - int32(1)
	if z != 0 {
		v1 = z + 1
	} else {
		v1 = uintptr(0)
	}
	return v1
}

// C documentation
//
//	/*
//	** This is used by xInstToken() to access the token at offset iOff, column
//	** iCol of row iRowid. The token is returned via output variables *ppOut
//	** and *pnOut. The iterator passed as the first argument must be a tokendata=1
//	** iterator (pIter->pTokenDataIter!=0).
//	*/
func _sqlite3Fts5IterToken(tls *libc.TLS, pIndexIter uintptr, iRowid Ti64, iCol int32, iOff int32, ppOut uintptr, pnOut uintptr) (r int32) {
	var aMap, pIter, pMap, pT uintptr
	var i1, i2, iTest int32
	var iPos Ti64
	_, _, _, _, _, _, _, _ = aMap, i1, i2, iPos, iTest, pIter, pMap, pT
	pIter = pIndexIter
	pT = (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter
	aMap = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap
	iPos = int64(int64(iCol))<<libc.Int32FromInt32(32) + int64(int64(iOff))
	i1 = 0
	i2 = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap
	iTest = 0
	for i2 > i1 {
		iTest = (i1 + i2) / int32(2)
		if (*(*TFts5TokenDataMap)(unsafe.Pointer(aMap + uintptr(iTest)*24))).FiRowid < iRowid {
			i1 = iTest + int32(1)
		} else {
			if (*(*TFts5TokenDataMap)(unsafe.Pointer(aMap + uintptr(iTest)*24))).FiRowid > iRowid {
				i2 = iTest
			} else {
				if (*(*TFts5TokenDataMap)(unsafe.Pointer(aMap + uintptr(iTest)*24))).FiPos < iPos {
					if (*(*TFts5TokenDataMap)(unsafe.Pointer(aMap + uintptr(iTest)*24))).FiPos < 0 {
						break
					}
					i1 = iTest + int32(1)
				} else {
					if (*(*TFts5TokenDataMap)(unsafe.Pointer(aMap + uintptr(iTest)*24))).FiPos > iPos {
						i2 = iTest
					} else {
						break
					}
				}
			}
		}
	}
	if i2 > i1 {
		pMap = *(*uintptr)(unsafe.Pointer(pT + 28 + uintptr((*(*TFts5TokenDataMap)(unsafe.Pointer(aMap + uintptr(iTest)*24))).FiIter)*4))
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*(*TFts5SegIter)(unsafe.Pointer(pMap + 80))).Fterm.Fp + uintptr(1)
		*(*int32)(unsafe.Pointer(pnOut)) = (*(*TFts5SegIter)(unsafe.Pointer(pMap + 80))).Fterm.Fn - int32(1)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Clear any existing entries from the token-map associated with the
//	** iterator passed as the only argument.
//	*/
func _sqlite3Fts5IndexIterClearTokendata(tls *libc.TLS, pIndexIter uintptr) {
	var pIter uintptr
	_ = pIter
	pIter = pIndexIter
	if pIter != 0 && (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter != 0 {
		(*TFts5TokenDataIter)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter)).FnMap = 0
	}
}

// C documentation
//
//	/*
//	** Set a token-mapping for the iterator passed as the first argument. This
//	** is used in detail=column or detail=none mode when a token is requested
//	** using the xInstToken() API. In this case the caller tokenizers the
//	** current row and configures the token-mapping via multiple calls to this
//	** function.
//	*/
func _sqlite3Fts5IndexIterWriteTokendata(tls *libc.TLS, pIndexIter uintptr, pToken uintptr, nToken int32, iRowid Ti64, iCol int32, iOff int32) (r int32) {
	var ii int32
	var p, pIter, pT, pTerm uintptr
	_, _, _, _, _ = ii, p, pIter, pT, pTerm
	pIter = pIndexIter
	pT = (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter
	p = (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex
	ii = 0
	for {
		if !(ii < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnIter) {
			break
		}
		pTerm = *(*uintptr)(unsafe.Pointer(pT + 28 + uintptr(ii)*4)) + 80 + 72
		if nToken == (*TFts5Buffer)(unsafe.Pointer(pTerm)).Fn-int32(1) && libc.Xmemcmp(tls, pToken, (*TFts5Buffer)(unsafe.Pointer(pTerm)).Fp+uintptr(1), uint32(uint32(nToken))) == 0 {
			break
		}
		goto _1
	_1:
		;
		ii++
	}
	if ii < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnIter {
		_fts5TokendataIterAppendMap(tls, p, pT, ii, iRowid, int64(int64(iCol))<<libc.Int32FromInt32(32)+int64(int64(iOff)))
	}
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Close an iterator opened by an earlier call to sqlite3Fts5IndexQuery().
//	*/
func _sqlite3Fts5IterClose(tls *libc.TLS, pIndexIter uintptr) {
	var pIndex, pIter uintptr
	_, _ = pIndex, pIter
	if pIndexIter != 0 {
		pIter = pIndexIter
		pIndex = (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex
		_fts5TokendataIterDelete(tls, (*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter)
		_fts5MultiIterFree(tls, pIter)
		_sqlite3Fts5IndexCloseReader(tls, pIndex)
	}
}

// C documentation
//
//	/*
//	** Read and decode the "averages" record from the database.
//	**
//	** Parameter anSize must point to an array of size nCol, where nCol is
//	** the number of user defined columns in the FTS table.
//	*/
func _sqlite3Fts5IndexGetAverages(tls *libc.TLS, p uintptr, pnRow uintptr, anSize uintptr) (r int32) {
	var i, iCol, nCol int32
	var pData uintptr
	_, _, _, _ = i, iCol, nCol, pData
	nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnCol
	*(*Ti64)(unsafe.Pointer(pnRow)) = 0
	libc.Xmemset(tls, anSize, 0, uint32(8)*uint32(uint32(nCol)))
	pData = _fts5DataRead(tls, p, int64(FTS5_AVERAGES_ROWID))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5Data)(unsafe.Pointer(pData)).Fnn != 0 {
		i = 0
		i += int32(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr(i), pnRow))
		iCol = 0
		for {
			if !(i < (*TFts5Data)(unsafe.Pointer(pData)).Fnn && iCol < nCol) {
				break
			}
			i += int32(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr(i), anSize+uintptr(iCol)*8))
			goto _1
		_1:
			;
			iCol++
		}
	}
	_fts5DataRelease(tls, pData)
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Replace the current "averages" record with the contents of the buffer
//	** supplied as the second argument.
//	*/
func _sqlite3Fts5IndexSetAverages(tls *libc.TLS, p uintptr, pData uintptr, nData int32) (r int32) {
	_fts5DataWrite(tls, p, int64(FTS5_AVERAGES_ROWID), pData, nData)
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Return the total number of blocks this module has read from the %_data
//	** table since it was created.
//	*/
func _sqlite3Fts5IndexReads(tls *libc.TLS, p uintptr) (r int32) {
	return (*TFts5Index)(unsafe.Pointer(p)).FnRead
}

// C documentation
//
//	/*
//	** Set the 32-bit cookie value stored at the start of all structure
//	** records to the value passed as the second argument.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _sqlite3Fts5IndexSetCookie(tls *libc.TLS, p uintptr, iNew int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig uintptr
	var rc int32
	var _ /* aCookie at bp+0 */ [4]Tu8
	var _ /* pBlob at bp+4 */ uintptr
	_, _ = pConfig, rc                                  /* Return code */
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig /* Binary representation of iNew */
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	_sqlite3Fts5Put32(tls, bp, iNew)
	rc = Xsqlite3_blob_open(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl, __ccgo_ts+37645, int64(FTS5_STRUCTURE_ROWID), int32(1), bp+4)
	if rc == SQLITE_OK {
		Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), bp, int32(4), 0)
		rc = Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	return rc
}

func _sqlite3Fts5IndexLoadConfig(tls *libc.TLS, p uintptr) (r int32) {
	var pStruct uintptr
	_ = pStruct
	pStruct = _fts5StructureRead(tls, p)
	_fts5StructureRelease(tls, pStruct)
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Retrieve the origin value that will be used for the segment currently
//	** being accumulated in the in-memory hash table when it is flushed to
//	** disk. If successful, SQLITE_OK is returned and (*piOrigin) set to
//	** the queried value. Or, if an error occurs, an error code is returned
//	** and the final value of (*piOrigin) is undefined.
//	*/
func _sqlite3Fts5IndexGetOrigin(tls *libc.TLS, p uintptr, piOrigin uintptr) (r int32) {
	var pStruct uintptr
	_ = pStruct
	pStruct = _fts5StructureRead(tls, p)
	if pStruct != 0 {
		*(*Ti64)(unsafe.Pointer(piOrigin)) = int64((*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr)
		_fts5StructureRelease(tls, pStruct)
	}
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Buffer pPg contains a page of a tombstone hash table - one of nPg pages
//	** associated with the same segment. This function adds rowid iRowid to
//	** the hash table. The caller is required to guarantee that there is at
//	** least one free slot on the page.
//	**
//	** If parameter bForce is false and the hash table is deemed to be full
//	** (more than half of the slots are occupied), then non-zero is returned
//	** and iRowid not inserted. Or, if bForce is true or if the hash table page
//	** is not full, iRowid is inserted and zero returned.
//	*/
func _fts5IndexTombstoneAddToPage(tls *libc.TLS, pPg uintptr, bForce int32, nPg int32, iRowid Tu64) (r int32) {
	var aSlot, aSlot1 uintptr
	var iSlot, nCollide, nElem, nSlot, szKey, v1, v2, v3, v4, v5 int32
	_, _, _, _, _, _, _, _, _, _, _, _ = aSlot, aSlot1, iSlot, nCollide, nElem, nSlot, szKey, v1, v2, v3, v4, v5
	if int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pPg)).Fp))) == int32(4) {
		v1 = int32(4)
	} else {
		v1 = int32(8)
	}
	szKey = v1
	if (*TFts5Data)(unsafe.Pointer(pPg)).Fnn > int32(16) {
		if int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pPg)).Fp))) == int32(4) {
			v3 = int32(4)
		} else {
			v3 = int32(8)
		}
		v2 = ((*TFts5Data)(unsafe.Pointer(pPg)).Fnn - int32(8)) / v3
	} else {
		v2 = int32(1)
	}
	nSlot = v2
	nElem = int32(_fts5GetU32(tls, (*TFts5Data)(unsafe.Pointer(pPg)).Fp+4))
	iSlot = int32(iRowid / uint64(uint64(nPg)) % uint64(uint64(nSlot)))
	nCollide = nSlot
	if szKey == int32(4) && iRowid > uint64(0xFFFFFFFF) {
		return int32(2)
	}
	if iRowid == uint64(0) {
		*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pPg)).Fp + 1)) = uint8(0x01)
		return 0
	}
	if bForce == 0 && nElem >= nSlot/int32(2) {
		return int32(1)
	}
	_fts5PutU32(tls, (*TFts5Data)(unsafe.Pointer(pPg)).Fp+4, uint32(nElem+int32(1)))
	if szKey == int32(4) {
		aSlot = (*TFts5Data)(unsafe.Pointer(pPg)).Fp + 8
		for *(*Tu32)(unsafe.Pointer(aSlot + uintptr(iSlot)*4)) != 0 {
			iSlot = (iSlot + int32(1)) % nSlot
			v4 = nCollide
			nCollide--
			if v4 == 0 {
				return 0
			}
		}
		_fts5PutU32(tls, aSlot+uintptr(iSlot)*4, uint32(uint32(iRowid)))
	} else {
		aSlot1 = (*TFts5Data)(unsafe.Pointer(pPg)).Fp + 8
		for *(*Tu64)(unsafe.Pointer(aSlot1 + uintptr(iSlot)*8)) != 0 {
			iSlot = (iSlot + int32(1)) % nSlot
			v5 = nCollide
			nCollide--
			if v5 == 0 {
				return 0
			}
		}
		_fts5PutU64(tls, aSlot1+uintptr(iSlot)*8, iRowid)
	}
	return 0
}

// C documentation
//
//	/*
//	** This function attempts to build a new hash containing all the keys
//	** currently in the tombstone hash table for segment pSeg. The new
//	** hash will be stored in the nOut buffers passed in array apOut[].
//	** All pages of the new hash use key-size szKey (4 or 8).
//	**
//	** Return 0 if the hash is successfully rebuilt into the nOut pages.
//	** Or non-zero if it is not (because one page became overfull). In this
//	** case the caller should retry with a larger nOut parameter.
//	**
//	** Parameter pData1 is page iPg1 of the hash table being rebuilt.
//	*/
func _fts5IndexTombstoneRehash(tls *libc.TLS, p uintptr, pSeg uintptr, pData1 uintptr, iPg1 int32, szKey int32, nOut int32, apOut uintptr) (r int32) {
	var aSlot, aSlot1, pData, pFree, pPg, v3 uintptr
	var iIn, ii, nSlotIn, res, szKeyIn, v4 int32
	var iVal Tu64
	_, _, _, _, _, _, _, _, _, _, _, _, _ = aSlot, aSlot1, iIn, iVal, ii, nSlotIn, pData, pFree, pPg, res, szKeyIn, v3, v4
	res = 0
	/* Initialize the headers of all the output pages */
	ii = 0
	for {
		if !(ii < nOut) {
			break
		}
		*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apOut + uintptr(ii)*4)))).Fp)) = uint8(uint8(szKey))
		_fts5PutU32(tls, (*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apOut + uintptr(ii)*4)))).Fp+4, uint32(0))
		goto _1
	_1:
		;
		ii++
	}
	/* Loop through the current pages of the hash table. */
	ii = 0
	for {
		if !(res == 0 && ii < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone) {
			break
		}
		pData = uintptr(0) /* Page ii of the current hash table */
		pFree = uintptr(0) /* Free this at the end of the loop */
		if iPg1 == ii {
			pData = pData1
		} else {
			v3 = _fts5DataRead(tls, p, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(ii))
			pData = v3
			pFree = v3
		}
		if pData != 0 {
			if int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pData)).Fp))) == int32(4) {
				v4 = int32(4)
			} else {
				v4 = int32(8)
			}
			szKeyIn = v4
			nSlotIn = ((*TFts5Data)(unsafe.Pointer(pData)).Fnn - int32(8)) / szKeyIn
			iIn = 0
			for {
				if !(iIn < nSlotIn) {
					break
				}
				iVal = uint64(0)
				/* Read the value from slot iIn of the input page into iVal. */
				if szKeyIn == int32(4) {
					aSlot = (*TFts5Data)(unsafe.Pointer(pData)).Fp + 8
					if *(*Tu32)(unsafe.Pointer(aSlot + uintptr(iIn)*4)) != 0 {
						iVal = uint64(_fts5GetU32(tls, aSlot+uintptr(iIn)*4))
					}
				} else {
					aSlot1 = (*TFts5Data)(unsafe.Pointer(pData)).Fp + 8
					if *(*Tu64)(unsafe.Pointer(aSlot1 + uintptr(iIn)*8)) != 0 {
						iVal = _fts5GetU64(tls, aSlot1+uintptr(iIn)*8)
					}
				}
				/* If iVal is not 0 at this point, insert it into the new hash table */
				if iVal != 0 {
					pPg = *(*uintptr)(unsafe.Pointer(apOut + uintptr(iVal%uint64(uint64(nOut)))*4))
					res = _fts5IndexTombstoneAddToPage(tls, pPg, 0, nOut, iVal)
					if res != 0 {
						break
					}
				}
				goto _5
			_5:
				;
				iIn++
			}
			/* If this is page 0 of the old hash, copy the rowid-0-flag from the
			 ** old hash to the new.  */
			if ii == 0 {
				*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apOut)))).Fp + 1)) = *(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pData)).Fp + 1))
			}
		}
		_fts5DataRelease(tls, pFree)
		goto _2
	_2:
		;
		ii++
	}
	return res
}

// C documentation
//
//	/*
//	** This is called to rebuild the hash table belonging to segment pSeg.
//	** If parameter pData1 is not NULL, then one page of the existing hash table
//	** has already been loaded - pData1, which is page iPg1. The key-size for
//	** the new hash table is szKey (4 or 8).
//	**
//	** If successful, the new hash table is not written to disk. Instead,
//	** output parameter (*pnOut) is set to the number of pages in the new
//	** hash table, and (*papOut) to point to an array of buffers containing
//	** the new page data.
//	**
//	** If an error occurs, an error code is left in the Fts5Index object and
//	** both output parameters set to 0 before returning.
//	*/
func _fts5IndexTombstoneRebuild(tls *libc.TLS, p uintptr, pSeg uintptr, pData1 uintptr, iPg1 int32, szKey int32, pnOut uintptr, papOut uintptr) {
	var MINSLOT, ii, nElem, nOut, nSlot, nSlotPerPage, res, szPage, v1, v2 int32
	var apOut, pNew uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = MINSLOT, apOut, ii, nElem, nOut, nSlot, nSlotPerPage, pNew, res, szPage, v1, v2
	MINSLOT = int32(32)
	if MINSLOT > ((*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz-int32(8))/szKey {
		v1 = MINSLOT
	} else {
		v1 = ((*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz - int32(8)) / szKey
	}
	nSlotPerPage = v1
	nSlot = 0 /* Number of slots in each output page */
	nOut = 0
	/* Figure out how many output pages (nOut) and how many slots per
	 ** page (nSlot).  There are three possibilities:
	 **
	 **   1. The hash table does not yet exist. In this case the new hash
	 **      table will consist of a single page with MINSLOT slots.
	 **
	 **   2. The hash table exists but is currently a single page. In this
	 **      case an attempt is made to grow the page to accommodate the new
	 **      entry. The page is allowed to grow up to nSlotPerPage (see above)
	 **      slots.
	 **
	 **   3. The hash table already consists of more than one page, or of
	 **      a single page already so large that it cannot be grown. In this
	 **      case the new hash consists of (nPg*2+1) pages of nSlotPerPage
	 **      slots each, where nPg is the current number of pages in the
	 **      hash table.
	 */
	if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone == 0 {
		/* Case 1. */
		nOut = int32(1)
		nSlot = MINSLOT
	} else {
		if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone == int32(1) {
			/* Case 2. */
			nElem = int32(_fts5GetU32(tls, (*TFts5Data)(unsafe.Pointer(pData1)).Fp+4))
			nOut = int32(1)
			if nElem*int32(4) > MINSLOT {
				v2 = nElem * int32(4)
			} else {
				v2 = MINSLOT
			}
			nSlot = v2
			if nSlot > nSlotPerPage {
				nOut = 0
			}
		}
	}
	if nOut == 0 {
		/* Case 3. */
		nOut = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone*int32(2) + int32(1)
		nSlot = nSlotPerPage
	}
	/* Allocate the required array and output pages */
	for int32(1) != 0 {
		res = 0
		ii = 0
		szPage = 0
		apOut = uintptr(0)
		/* Allocate space for the new hash table */
		apOut = _sqlite3Fts5MallocZero(tls, p+44, int64(uint32(4)*uint32(uint32(nOut))))
		szPage = int32(8) + nSlot*szKey
		ii = 0
		for {
			if !(ii < nOut) {
				break
			}
			pNew = _sqlite3Fts5MallocZero(tls, p+44, int64(uint32(12)+uint32(uint32(szPage))))
			if pNew != 0 {
				(*TFts5Data)(unsafe.Pointer(pNew)).Fnn = szPage
				(*TFts5Data)(unsafe.Pointer(pNew)).Fp = pNew + 1*12
				*(*uintptr)(unsafe.Pointer(apOut + uintptr(ii)*4)) = pNew
			}
			goto _3
		_3:
			;
			ii++
		}
		/* Rebuild the hash table. */
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			res = _fts5IndexTombstoneRehash(tls, p, pSeg, pData1, iPg1, szKey, nOut, apOut)
		}
		if res == 0 {
			if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
				_fts5IndexFreeArray(tls, apOut, nOut)
				apOut = uintptr(0)
				nOut = 0
			}
			*(*int32)(unsafe.Pointer(pnOut)) = nOut
			*(*uintptr)(unsafe.Pointer(papOut)) = apOut
			break
		}
		/* If control flows to here, it was not possible to rebuild the hash
		 ** table. Free all buffers and then try again with more pages. */
		_fts5IndexFreeArray(tls, apOut, nOut)
		nSlot = nSlotPerPage
		nOut = nOut*int32(2) + int32(1)
	}
}

// C documentation
//
//	/*
//	** Add a tombstone for rowid iRowid to segment pSeg.
//	*/
func _fts5IndexTombstoneAdd(tls *libc.TLS, p uintptr, pSeg uintptr, iRowid Tu64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPg, ii, szKey, v1, v2 int32
	var iTombstoneRowid Ti64
	var pPg uintptr
	var _ /* apHash at bp+4 */ uintptr
	var _ /* nHash at bp+0 */ int32
	_, _, _, _, _, _, _ = iPg, iTombstoneRowid, ii, pPg, szKey, v1, v2
	pPg = uintptr(0)
	iPg = -int32(1)
	szKey = 0
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	(*TFts5Index)(unsafe.Pointer(p)).FnContentlessDelete++
	if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone > 0 {
		iPg = int32(iRowid % uint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone))
		pPg = _fts5DataRead(tls, p, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(iPg))
		if pPg == uintptr(0) {
			return
		}
		if 0 == _fts5IndexTombstoneAddToPage(tls, pPg, 0, (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone, iRowid) {
			_fts5DataWrite(tls, p, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(iPg), (*TFts5Data)(unsafe.Pointer(pPg)).Fp, (*TFts5Data)(unsafe.Pointer(pPg)).Fnn)
			_fts5DataRelease(tls, pPg)
			return
		}
	}
	/* Have to rebuild the hash table. First figure out the key-size (4 or 8). */
	if pPg != 0 {
		if int32(*(*Tu8)(unsafe.Pointer((*TFts5Data)(unsafe.Pointer(pPg)).Fp))) == int32(4) {
			v2 = int32(4)
		} else {
			v2 = int32(8)
		}
		v1 = v2
	} else {
		v1 = int32(4)
	}
	szKey = v1
	if iRowid > uint64(0xFFFFFFFF) {
		szKey = int32(8)
	}
	/* Rebuild the hash table */
	_fts5IndexTombstoneRebuild(tls, p, pSeg, pPg, iPg, szKey, bp, bp+4)
	/* If all has succeeded, write the new rowid into one of the new hash
	 ** table pages, then write them all out to disk. */
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		ii = 0
		_fts5IndexTombstoneAddToPage(tls, *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)) + uintptr(iRowid%uint64(*(*int32)(unsafe.Pointer(bp))))*4)), int32(1), *(*int32)(unsafe.Pointer(bp)), iRowid)
		ii = 0
		for {
			if !(ii < *(*int32)(unsafe.Pointer(bp))) {
				break
			}
			iTombstoneRowid = int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(ii)
			_fts5DataWrite(tls, p, iTombstoneRowid, (*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)) + uintptr(ii)*4)))).Fp, (*TFts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)) + uintptr(ii)*4)))).Fnn)
			goto _3
		_3:
			;
			ii++
		}
		(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone = *(*int32)(unsafe.Pointer(bp))
		_fts5StructureWrite(tls, p, (*TFts5Index)(unsafe.Pointer(p)).FpStruct)
	}
	_fts5DataRelease(tls, pPg)
	_fts5IndexFreeArray(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp)))
}

// C documentation
//
//	/*
//	** Add iRowid to the tombstone list of the segment or segments that contain
//	** rows from origin iOrigin. Return SQLITE_OK if successful, or an SQLite
//	** error code otherwise.
//	*/
func _sqlite3Fts5IndexContentlessDelete(tls *libc.TLS, p uintptr, iOrigin Ti64, iRowid Ti64) (r int32) {
	var bFound, iLvl, iSeg int32
	var pSeg, pStruct uintptr
	_, _, _, _, _ = bFound, iLvl, iSeg, pSeg, pStruct
	pStruct = _fts5StructureRead(tls, p)
	if pStruct != 0 {
		bFound = 0
		iLvl = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel - int32(1)
		for {
			if !(iLvl >= 0) {
				break
			}
			iSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FnSeg - int32(1)
			for {
				if !(iSeg >= 0) {
					break
				}
				pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FaSeg + uintptr(iSeg)*56
				if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1 <= uint64(uint64(iOrigin)) && (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2 >= uint64(uint64(iOrigin)) {
					if bFound == 0 {
						(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntryTombstone++
						bFound = int32(1)
					}
					_fts5IndexTombstoneAdd(tls, p, pSeg, uint64(uint64(iRowid)))
				}
				goto _2
			_2:
				;
				iSeg--
			}
			goto _1
		_1:
			;
			iLvl--
		}
		_fts5StructureRelease(tls, pStruct)
	}
	return _fts5IndexReturn(tls, p)
}

/*************************************************************************
**************************************************************************
** Below this point is the implementation of the integrity-check
** functionality.
 */

// C documentation
//
//	/*
//	** Return a simple checksum value based on the arguments.
//	*/
func _sqlite3Fts5IndexEntryCksum(tls *libc.TLS, iRowid Ti64, iCol int32, iPos int32, iIdx int32, pTerm uintptr, nTerm int32) (r Tu64) {
	var i int32
	var ret Tu64
	_, _ = i, ret
	ret = uint64(uint64(iRowid))
	ret += ret<<libc.Int32FromInt32(3) + uint64(uint64(iCol))
	ret += ret<<libc.Int32FromInt32(3) + uint64(uint64(iPos))
	if iIdx >= 0 {
		ret += ret<<libc.Int32FromInt32(3) + uint64(libc.Int32FromUint8('0')+iIdx)
	}
	i = 0
	for {
		if !(i < nTerm) {
			break
		}
		ret += ret<<libc.Int32FromInt32(3) + uint64(*(*int8)(unsafe.Pointer(pTerm + uintptr(i))))
		goto _1
	_1:
		;
		i++
	}
	return ret
}

// C documentation
//
//	/*
//	** Check that:
//	**
//	**   1) All leaves of pSeg between iFirst and iLast (inclusive) exist and
//	**      contain zero terms.
//	**   2) All leaves of pSeg between iNoRowid and iLast (inclusive) exist and
//	**      contain zero rowids.
//	*/
func _fts5IndexIntegrityCheckEmpty(tls *libc.TLS, p uintptr, pSeg uintptr, iFirst int32, iNoRowid int32, iLast int32) {
	var i int32
	var pLeaf uintptr
	_, _ = i, pLeaf
	/* Now check that the iter.nEmpty leaves following the current leaf
	 ** (a) exist and (b) contain no terms. */
	i = iFirst
	for {
		if !((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && i <= iLast) {
			break
		}
		pLeaf = _fts5DataRead(tls, p, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B)+int64(i))
		if pLeaf != 0 {
			if !((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf >= (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
			if i >= iNoRowid && 0 != int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp)) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		}
		_fts5DataRelease(tls, pLeaf)
		goto _1
	_1:
		;
		i++
	}
}

func _fts5IntegrityCheckPgidx(tls *libc.TLS, p uintptr, pLeaf uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iOff, iTermOff Ti64
	var ii, res int32
	var _ /* buf1 at bp+0 */ TFts5Buffer
	var _ /* buf2 at bp+12 */ TFts5Buffer
	var _ /* nByte at bp+28 */ int32
	var _ /* nByte at bp+36 */ int32
	var _ /* nIncr at bp+24 */ int32
	var _ /* nKeep at bp+32 */ int32
	_, _, _, _ = iOff, iTermOff, ii, res
	iTermOff = 0
	*(*TFts5Buffer)(unsafe.Pointer(bp)) = TFts5Buffer{}
	*(*TFts5Buffer)(unsafe.Pointer(bp + 12)) = TFts5Buffer{}
	ii = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf
	for ii < (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn && (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		ii += _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(ii), bp+24)
		iTermOff += int64(*(*int32)(unsafe.Pointer(bp + 24)))
		iOff = iTermOff
		if iOff >= int64((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf) {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		} else {
			if iTermOff == int64(*(*int32)(unsafe.Pointer(bp + 24))) {
				iOff += int64(_sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+28))
				if iOff+int64(*(*int32)(unsafe.Pointer(bp + 28))) > int64((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf) {
					(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				} else {
					_sqlite3Fts5BufferSet(tls, p+44, bp, *(*int32)(unsafe.Pointer(bp + 28)), (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff))
				}
			} else {
				iOff += int64(_sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+32))
				iOff += int64(_sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+36))
				if *(*int32)(unsafe.Pointer(bp + 32)) > (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn || iOff+int64(*(*int32)(unsafe.Pointer(bp + 36))) > int64((*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf) {
					(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				} else {
					(*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn = *(*int32)(unsafe.Pointer(bp + 32))
					_sqlite3Fts5BufferAppendBlob(tls, p+44, bp, uint32(*(*int32)(unsafe.Pointer(bp + 36))), (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff))
				}
				if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					res = _fts5BufferCompare(tls, bp, bp+12)
					if res <= 0 {
						(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					}
				}
			}
		}
		_sqlite3Fts5BufferSet(tls, p+44, bp+12, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp)
	}
	_sqlite3Fts5BufferFree(tls, bp)
	_sqlite3Fts5BufferFree(tls, bp+12)
}

func _fts5IndexIntegrityCheckSegment(tls *libc.TLS, p uintptr, pSeg uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bIdxDlidx, bSecureDelete, iDlidxPrevLeaf, iIdxLeaf, iIdxPrevLeaf, iOff, iPg, iPrevLeaf, iRowidOff, iRowidOff1, iSegid, nIdxTerm, rc2, res, v1, v2, v3 int32
	var iDlRowid, iKey, iRow Ti64
	var pConfig, pDlidx, pLeaf, zIdxTerm uintptr
	var _ /* iRowid at bp+8 */ Ti64
	var _ /* nTerm at bp+4 */ int32
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bIdxDlidx, bSecureDelete, iDlRowid, iDlidxPrevLeaf, iIdxLeaf, iIdxPrevLeaf, iKey, iOff, iPg, iPrevLeaf, iRow, iRowidOff, iRowidOff1, iSegid, nIdxTerm, pConfig, pDlidx, pLeaf, rc2, res, zIdxTerm, v1, v2, v3
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
	bSecureDelete = libc.BoolInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion == int32(FTS5_CURRENT_VERSION_SECUREDELETE))
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	iIdxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst - int32(1)
	iDlidxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast
	if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst == 0 {
		return
	}
	_fts5IndexPrepareStmt(tls, p, bp, Xsqlite3_mprintf(tls, __ccgo_ts+38192, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)))
	/* Iterate through the b-tree hierarchy.  */
	for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) { /* Data for this leaf */
		zIdxTerm = Xsqlite3_column_blob(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		nIdxTerm = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		iIdxLeaf = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2))
		bIdxDlidx = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(3))
		/* If the leaf in question has already been trimmed from the segment,
		 ** ignore this b-tree entry. Otherwise, load it into memory. */
		if iIdxLeaf < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
			continue
		}
		iRow = int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(iIdxLeaf)
		pLeaf = _fts5LeafRead(tls, p, iRow)
		if pLeaf == uintptr(0) {
			break
		}
		/* Check that the leaf contains at least one term, and that it is equal
		 ** to or larger than the split-key in zIdxTerm.  Also check that if there
		 ** is also a rowid pointer within the leaf page header, it points to a
		 ** location before the term.  */
		if (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn <= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
			if nIdxTerm == 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion == int32(FTS5_CURRENT_VERSION_SECUREDELETE) && (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn == (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf && (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn == int32(4) {
				/* special case - the very first page in a segment keeps its %_idx
				 ** entry even if all the terms are removed from it by secure-delete
				 ** operations. */
			} else {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		} else { /* Comparison of term and split-key */
			iOff = _fts5LeafFirstTermOff(tls, pLeaf)
			iRowidOff = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp))
			if iRowidOff >= iOff || iOff >= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			} else {
				iOff += _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+4)
				if *(*int32)(unsafe.Pointer(bp + 4)) < nIdxTerm {
					v2 = *(*int32)(unsafe.Pointer(bp + 4))
				} else {
					v2 = nIdxTerm
				}
				if v2 <= 0 {
					v1 = 0
				} else {
					if *(*int32)(unsafe.Pointer(bp + 4)) < nIdxTerm {
						v3 = *(*int32)(unsafe.Pointer(bp + 4))
					} else {
						v3 = nIdxTerm
					}
					v1 = libc.Xmemcmp(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), zIdxTerm, uint32(v3))
				}
				res = v1
				if res == 0 {
					res = *(*int32)(unsafe.Pointer(bp + 4)) - nIdxTerm
				}
				if res < 0 {
					(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
			}
			_fts5IntegrityCheckPgidx(tls, p, pLeaf)
		}
		_fts5DataRelease(tls, pLeaf)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}
		/* Now check that the iter.nEmpty leaves following the current leaf
		 ** (a) exist and (b) contain no terms. */
		_fts5IndexIntegrityCheckEmpty(tls, p, pSeg, iIdxPrevLeaf+int32(1), iDlidxPrevLeaf+int32(1), iIdxLeaf-int32(1))
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}
		/* If there is a doclist-index, check that it looks right. */
		if bIdxDlidx != 0 {
			pDlidx = uintptr(0) /* For iterating through doclist index */
			iPrevLeaf = iIdxLeaf
			iSegid = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid
			iPg = 0
			pDlidx = _fts5DlidxIterInit(tls, p, 0, iSegid, iIdxLeaf)
			for {
				if !(_fts5DlidxIterEof(tls, p, pDlidx) == 0) {
					break
				}
				/* Check any rowid-less pages that occur before the current leaf. */
				iPg = iPrevLeaf + int32(1)
				for {
					if !(iPg < _fts5DlidxIterPgno(tls, pDlidx)) {
						break
					}
					iKey = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(iPg)
					pLeaf = _fts5DataRead(tls, p, iKey)
					if pLeaf != 0 {
						if int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp)) != 0 {
							(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						}
						_fts5DataRelease(tls, pLeaf)
					}
					goto _5
				_5:
					;
					iPg++
				}
				iPrevLeaf = _fts5DlidxIterPgno(tls, pDlidx)
				/* Check that the leaf page indicated by the iterator really does
				 ** contain the rowid suggested by the same. */
				iKey = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(iPrevLeaf)
				pLeaf = _fts5DataRead(tls, p, iKey)
				if pLeaf != 0 {
					iRowidOff1 = int32(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp))
					if iRowidOff1 >= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
						(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					} else {
						if bSecureDelete == 0 || iRowidOff1 > 0 {
							iDlRowid = _fts5DlidxIterRowid(tls, pDlidx)
							_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iRowidOff1), bp+8)
							if *(*Ti64)(unsafe.Pointer(bp + 8)) < iDlRowid || bSecureDelete == 0 && *(*Ti64)(unsafe.Pointer(bp + 8)) != iDlRowid {
								(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
							}
						}
					}
					_fts5DataRelease(tls, pLeaf)
				}
				goto _4
			_4:
				;
				_fts5DlidxIterNext(tls, p, pDlidx)
			}
			iDlidxPrevLeaf = iPg
			_fts5DlidxIterFree(tls, pDlidx)
		} else {
			iDlidxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast
			/* TODO: Check there is no doclist index */
		}
		iIdxPrevLeaf = iIdxLeaf
	}
	rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = rc2
	}
	/* Page iter.iLeaf must now be the rightmost leaf-page in the segment */
}

// C documentation
//
//	/*
//	** Run internal checks to ensure that the FTS index (a) is internally
//	** consistent and (b) contains entries for which the XOR of the checksums
//	** as calculated by sqlite3Fts5IndexEntryCksum() is cksum.
//	**
//	** Return SQLITE_CORRUPT if any of the internal checks fail, or if the
//	** checksum does not match. Return SQLITE_OK if all checks pass without
//	** error, or some other SQLite error code if another error (e.g. OOM)
//	** occurs.
//	*/
func _sqlite3Fts5IndexIntegrityCheck(tls *libc.TLS, p uintptr, cksum Tu64, bUseCksum int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var cksum2 Tu64
	var eDetail, flags, iCol, iLvl, iSeg, iTokOff int32
	var iRowid Ti64
	var pSeg, pStruct, z uintptr
	var _ /* iOff at bp+32 */ int32
	var _ /* iPos at bp+24 */ Ti64
	var _ /* n at bp+16 */ int32
	var _ /* pIter at bp+12 */ uintptr
	var _ /* poslist at bp+0 */ TFts5Buffer
	_, _, _, _, _, _, _, _, _, _, _ = cksum2, eDetail, flags, iCol, iLvl, iRowid, iSeg, iTokOff, pSeg, pStruct, z
	eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
	cksum2 = uint64(0) /* Checksum based on contents of indexes */
	*(*TFts5Buffer)(unsafe.Pointer(bp)) = TFts5Buffer{}
	flags = int32(FTS5INDEX_QUERY_NOOUTPUT)
	/* Load the FTS index structure */
	pStruct = _fts5StructureRead(tls, p)
	if pStruct == uintptr(0) {
		return _fts5IndexReturn(tls, p)
	}
	/* Check that the internal nodes of each segment match the leaves */
	iLvl = 0
	for {
		if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
			break
		}
		iSeg = 0
		for {
			if !(iSeg < (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FnSeg) {
				break
			}
			pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*12))).FaSeg + uintptr(iSeg)*56
			_fts5IndexIntegrityCheckSegment(tls, p, pSeg)
			goto _2
		_2:
			;
			iSeg++
		}
		goto _1
	_1:
		;
		iLvl++
	}
	/* The cksum argument passed to this function is a checksum calculated
	 ** based on all expected entries in the FTS index (including prefix index
	 ** entries). This block checks that a checksum calculated based on the
	 ** actual contents of FTS index is identical.
	 **
	 ** Two versions of the same checksum are calculated. The first (stack
	 ** variable cksum2) based on entries extracted from the full-text index
	 ** while doing a linear scan of each individual index in turn.
	 **
	 ** As each term visited by the linear scans, a separate query for the
	 ** same term is performed. cksum3 is calculated based on the entries
	 ** extracted by these queries.
	 */
	_fts5MultiIterNew(tls, p, pStruct, flags, uintptr(0), uintptr(0), 0, -int32(1), 0, bp+12)
	for {
		if !(_fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp + 12))) == 0) {
			break
		} /* Size of term in bytes */
		*(*Ti64)(unsafe.Pointer(bp + 24)) = 0  /* Position read from poslist */
		*(*int32)(unsafe.Pointer(bp + 32)) = 0 /* Offset within poslist */
		iRowid = _fts5MultiIterRowid(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
		z = _fts5MultiIterTerm(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), bp+16)
		/* If this is a new term, query for it. Update cksum3 with the results. */
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}
		if eDetail == int32(FTS5_DETAIL_NONE) {
			if 0 == _fts5MultiIterIsEmpty(tls, p, *(*uintptr)(unsafe.Pointer(bp + 12))) {
				cksum2 ^= _sqlite3Fts5IndexEntryCksum(tls, iRowid, 0, 0, -int32(1), z, *(*int32)(unsafe.Pointer(bp + 16)))
			}
		} else {
			(*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn = 0
			_fts5SegiterPoslist(tls, p, *(*uintptr)(unsafe.Pointer(bp + 12))+80+uintptr((*(*TFts5CResult)(unsafe.Pointer((*TFts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 12)))).FaFirst + 1*4))).FiFirst)*104, uintptr(0), bp)
			_sqlite3Fts5BufferAppendBlob(tls, p+44, bp, uint32(4), __ccgo_ts+38278)
			for 0 == _sqlite3Fts5PoslistNext64(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn, bp+32, bp+24) {
				iCol = int32(*(*Ti64)(unsafe.Pointer(bp + 24)) >> libc.Int32FromInt32(32))
				iTokOff = int32(*(*Ti64)(unsafe.Pointer(bp + 24)) & libc.Int64FromInt32(0x7FFFFFFF))
				cksum2 ^= _sqlite3Fts5IndexEntryCksum(tls, iRowid, iCol, iTokOff, -int32(1), z, *(*int32)(unsafe.Pointer(bp + 16)))
			}
		}
		goto _3
	_3:
		;
		_fts5MultiIterNext(tls, p, *(*uintptr)(unsafe.Pointer(bp + 12)), 0, 0)
	}
	_fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bUseCksum != 0 && cksum != cksum2 {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	}
	_fts5StructureRelease(tls, pStruct)
	_sqlite3Fts5BufferFree(tls, bp)
	return _fts5IndexReturn(tls, p)
}

/*************************************************************************
**************************************************************************
** Below this point is the implementation of the fts5_decode() scalar
** function only.
 */

// C documentation
//
//	/*
//	** This is called as part of registering the FTS5 module with database
//	** connection db. It registers several user-defined scalar functions useful
//	** with FTS5.
//	**
//	** If successful, SQLITE_OK is returned. If an error occurs, some other
//	** SQLite error code is returned instead.
//	*/
func _sqlite3Fts5IndexInit(tls *libc.TLS, db uintptr) (r int32) {
	return SQLITE_OK
	_ = db
	return r
}

func _sqlite3Fts5IndexReset(tls *libc.TLS, p uintptr) (r int32) {
	if _fts5IndexDataVersion(tls, p) != (*TFts5Index)(unsafe.Pointer(p)).FiStructVersion {
		_fts5StructureInvalidate(tls, p)
	}
	return _fts5IndexReturn(tls, p)
}

/*
** 2014 Jun 09
**
** 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 is an SQLite module implementing full-text search.
 */

/* #include "fts5Int.h" */

/*
** This variable is set to false when running tests for which the on disk
** structures should not be corrupt. Otherwise, true. If it is false, extra
** assert() conditions in the fts5 code are activated - conditions that are
** only true if it is guaranteed that the fts5 database is not corrupt.
 */

type TFts5Auxdata = struct {
	FpAux    uintptr
	FpPtr    uintptr
	FxDelete uintptr
	FpNext   uintptr
}

type Fts5Auxdata = TFts5Auxdata

type TFts5Auxiliary = struct {
	FpGlobal   uintptr
	FzFunc     uintptr
	FpUserData uintptr
	FxFunc     Tfts5_extension_function
	FxDestroy  uintptr
	FpNext     uintptr
}

type Fts5Auxiliary = TFts5Auxiliary

type TFts5Cursor = struct {
	F__ccgo_align  [0]uint32
	Fbase          Tsqlite3_vtab_cursor
	FpNext         uintptr
	FaColumnSize   uintptr
	F__ccgo_align3 [4]byte
	FiCsrId        Ti64
	FePlan         int32
	FbDesc         int32
	FiFirstRowid   Ti64
	FiLastRowid    Ti64
	FpStmt         uintptr
	FpExpr         uintptr
	FpSorter       uintptr
	Fcsrflags      int32
	FiSpecial      Ti64
	FzRank         uintptr
	FzRankArgs     uintptr
	FpRank         uintptr
	FnRankArg      int32
	FapRankArg     uintptr
	FpRankArgStmt  uintptr
	FpAux          uintptr
	FpAuxdata      uintptr
	FaInstIter     uintptr
	FnInstAlloc    int32
	FnInstCount    int32
	FaInst         uintptr
}

type Fts5Cursor = TFts5Cursor

type TFts5FullTable = struct {
	Fp          TFts5Table
	FpStorage   uintptr
	FpGlobal    uintptr
	FpSortCsr   uintptr
	FiSavepoint int32
}

type Fts5FullTable = TFts5FullTable

type TFts5Sorter = struct {
	F__ccgo_align  [0]uint32
	FpStmt         uintptr
	F__ccgo_align1 [4]byte
	FiRowid        Ti64
	FaPoslist      uintptr
	FnIdx          int32
	FaIdx          [1]int32
	F__ccgo_pad5   [4]byte
}

type Fts5Sorter = TFts5Sorter

type TFts5TokenizerModule = struct {
	FzName     uintptr
	FpUserData uintptr
	Fx         Tfts5_tokenizer
	FxDestroy  uintptr
	FpNext     uintptr
}

type Fts5TokenizerModule = TFts5TokenizerModule

/*
** NOTES ON TRANSACTIONS:
**
** SQLite invokes the following virtual table methods as transactions are
** opened and closed by the user:
**
**     xBegin():    Start of a new transaction.
**     xSync():     Initial part of two-phase commit.
**     xCommit():   Final part of two-phase commit.
**     xRollback(): Rollback the transaction.
**
** Anything that is required as part of a commit that may fail is performed
** in the xSync() callback. Current versions of SQLite ignore any errors
** returned by xCommit().
**
** And as sub-transactions are opened/closed:
**
**     xSavepoint(int S):  Open savepoint S.
**     xRelease(int S):    Commit and close savepoint S.
**     xRollbackTo(int S): Rollback to start of savepoint S.
**
** During a write-transaction the fts5_index.c module may cache some data
** in-memory. It is flushed to disk whenever xSync(), xRelease() or
** xSavepoint() is called. And discarded whenever xRollback() or xRollbackTo()
** is called.
**
** Additionally, if SQLITE_DEBUG is defined, an instance of the following
** structure is used to record the current transaction state. This information
** is not required, but it is used in the assert() statements executed by
** function fts5CheckTransactionState() (see below).
 */
type TFts5TransactionState = struct {
	FeState     int32
	FiSavepoint int32
}

type Fts5TransactionState = TFts5TransactionState

/*
** A single object of this type is allocated when the FTS5 module is
** registered with a database handle. It is used to store pointers to
** all registered FTS5 extensions - tokenizers and auxiliary functions.
 */
type TFts5Global1 = struct {
	F__ccgo_align  [0]uint32
	Fapi           Tfts5_api
	Fdb            uintptr
	F__ccgo_align2 [4]byte
	FiNextId       Ti64
	FpAux          uintptr
	FpTok          uintptr
	FpDfltTok      uintptr
	FpCsr          uintptr
}

type Fts5Global1 = TFts5Global1

/*
** Each auxiliary function registered with the FTS5 module is represented
** by an object of the following type. All such objects are stored as part
** of the Fts5Global.pAux list.
 */
type TFts5Auxiliary1 = struct {
	FpGlobal   uintptr
	FzFunc     uintptr
	FpUserData uintptr
	FxFunc     Tfts5_extension_function
	FxDestroy  uintptr
	FpNext     uintptr
}

type Fts5Auxiliary1 = TFts5Auxiliary1

/*
** Each tokenizer module registered with the FTS5 module is represented
** by an object of the following type. All such objects are stored as part
** of the Fts5Global.pTok list.
 */
type TFts5TokenizerModule1 = struct {
	FzName     uintptr
	FpUserData uintptr
	Fx         Tfts5_tokenizer
	FxDestroy  uintptr
	FpNext     uintptr
}

type Fts5TokenizerModule1 = TFts5TokenizerModule1

type TFts5FullTable1 = struct {
	Fp          TFts5Table
	FpStorage   uintptr
	FpGlobal    uintptr
	FpSortCsr   uintptr
	FiSavepoint int32
}

type Fts5FullTable1 = TFts5FullTable1

type TFts5MatchPhrase = struct {
	FpPoslist uintptr
	FnTerm    int32
}

type Fts5MatchPhrase = TFts5MatchPhrase

/*
** pStmt:
**   SELECT rowid, <fts> FROM <fts> ORDER BY +rank;
**
** aIdx[]:
**   There is one entry in the aIdx[] array for each phrase in the query,
**   the value of which is the offset within aPoslist[] following the last
**   byte of the position list for the corresponding phrase.
 */
type TFts5Sorter1 = struct {
	F__ccgo_align  [0]uint32
	FpStmt         uintptr
	F__ccgo_align1 [4]byte
	FiRowid        Ti64
	FaPoslist      uintptr
	FnIdx          int32
	FaIdx          [1]int32
	F__ccgo_pad5   [4]byte
}

type Fts5Sorter1 = TFts5Sorter1

/*
** Virtual-table cursor object.
**
** iSpecial:
**   If this is a 'special' query (refer to function fts5SpecialMatch()),
**   then this variable contains the result of the query.
**
** iFirstRowid, iLastRowid:
**   These variables are only used for FTS5_PLAN_MATCH cursors. Assuming the
**   cursor iterates in ascending order of rowids, iFirstRowid is the lower
**   limit of rowids to return, and iLastRowid the upper. In other words, the
**   WHERE clause in the user's query might have been:
**
**       <tbl> MATCH <expr> AND rowid BETWEEN $iFirstRowid AND $iLastRowid
**
**   If the cursor iterates in descending order of rowid, iFirstRowid
**   is the upper limit (i.e. the "first" rowid visited) and iLastRowid
**   the lower.
 */
type TFts5Cursor1 = struct {
	F__ccgo_align  [0]uint32
	Fbase          Tsqlite3_vtab_cursor
	FpNext         uintptr
	FaColumnSize   uintptr
	F__ccgo_align3 [4]byte
	FiCsrId        Ti64
	FePlan         int32
	FbDesc         int32
	FiFirstRowid   Ti64
	FiLastRowid    Ti64
	FpStmt         uintptr
	FpExpr         uintptr
	FpSorter       uintptr
	Fcsrflags      int32
	FiSpecial      Ti64
	FzRank         uintptr
	FzRankArgs     uintptr
	FpRank         uintptr
	FnRankArg      int32
	FapRankArg     uintptr
	FpRankArgStmt  uintptr
	FpAux          uintptr
	FpAuxdata      uintptr
	FaInstIter     uintptr
	FnInstAlloc    int32
	FnInstCount    int32
	FaInst         uintptr
}

type Fts5Cursor1 = TFts5Cursor1

/*
** Bits that make up the "idxNum" parameter passed indirectly by
** xBestIndex() to xFilter().
 */

/*
** Values for Fts5Cursor.csrflags
 */

/*
** Macros to Set(), Clear() and Test() cursor flags.
 */

type TFts5Auxdata1 = struct {
	FpAux    uintptr
	FpPtr    uintptr
	FxDelete uintptr
	FpNext   uintptr
}

type Fts5Auxdata1 = TFts5Auxdata1

// C documentation
//
//	/*
//	** Return true if pTab is a contentless table.
//	*/
func _fts5IsContentless(tls *libc.TLS, pTab uintptr) (r int32) {
	return libc.BoolInt32((*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FeContent == int32(FTS5_CONTENT_NONE))
}

// C documentation
//
//	/*
//	** Delete a virtual table handle allocated by fts5InitVtab().
//	*/
func _fts5FreeVtab(tls *libc.TLS, pTab uintptr) {
	if pTab != 0 {
		_sqlite3Fts5IndexClose(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		_sqlite3Fts5StorageClose(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
		_sqlite3Fts5ConfigFree(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)
		Xsqlite3_free(tls, pTab)
	}
}

// C documentation
//
//	/*
//	** The xDisconnect() virtual table method.
//	*/
func _fts5DisconnectMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	_fts5FreeVtab(tls, pVtab)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The xDestroy() virtual table method.
//	*/
func _fts5DestroyMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	rc = _sqlite3Fts5DropAll(tls, (*TFts5Table)(unsafe.Pointer(pTab)).FpConfig)
	if rc == SQLITE_OK {
		_fts5FreeVtab(tls, pVtab)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is the implementation of both the xConnect and xCreate
//	** methods of the FTS3 virtual table.
//	**
//	** The argv[] array contains the following:
//	**
//	**   argv[0]   -> module name  ("fts5")
//	**   argv[1]   -> database name
//	**   argv[2]   -> table name
//	**   argv[...] -> "column name" and other module argument fields.
//	*/
func _fts5InitVtab(tls *libc.TLS, bCreate int32, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVTab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var azConfig, pGlobal, pTab uintptr
	var _ /* pConfig at bp+4 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _ = azConfig, pGlobal, pTab
	pGlobal = pAux
	azConfig = argv
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK        /* Return code */
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0) /* Results of parsing argc/argv */
	pTab = uintptr(0)                                /* New virtual table object */
	/* Allocate the new vtab object and parse the configuration */
	pTab = _sqlite3Fts5MallocZero(tls, bp, int64(36))
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5ConfigParse(tls, pGlobal, db, argc, azConfig, bp+4, pzErr)
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig = *(*uintptr)(unsafe.Pointer(bp + 4))
		(*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal = pGlobal
	}
	/* Open the index sub-system */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5IndexOpen(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), bCreate, pTab+16, pzErr)
	}
	/* Open the storage sub-system */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageOpen(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex, bCreate, pTab+20, pzErr)
	}
	/* Call sqlite3_declare_vtab() */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5ConfigDeclareVtab(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	/* Load the initial configuration */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*TFts5Config)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpzErrmsg = pzErr
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		_sqlite3Fts5IndexRollback(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		(*TFts5Config)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FpzErrmsg = uintptr(0)
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 4)))).FeContent == FTS5_CONTENT_NORMAL {
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_CONSTRAINT_SUPPORT), libc.VaList(bp+16, libc.Int32FromInt32(1)))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
	}
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		_fts5FreeVtab(tls, pTab)
		pTab = uintptr(0)
	} else {
		if bCreate != 0 {
		}
	}
	*(*uintptr)(unsafe.Pointer(ppVTab)) = pTab
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** The xConnect() and xCreate() methods for the virtual table. All the
//	** work is done in function fts5InitVtab().
//	*/
func _fts5ConnectMethod(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _fts5InitVtab(tls, 0, db, pAux, argc, argv, ppVtab, pzErr)
}

func _fts5CreateMethod(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _fts5InitVtab(tls, int32(1), db, pAux, argc, argv, ppVtab, pzErr)
}

/*
** The different query plans.
 */

// C documentation
//
//	/*
//	** Set the SQLITE_INDEX_SCAN_UNIQUE flag in pIdxInfo->flags. Unless this
//	** extension is currently being used by a version of SQLite too old to
//	** support index-info flags. In that case this function is a no-op.
//	*/
func _fts5SetUniqueFlag(tls *libc.TLS, pIdxInfo uintptr) {
	*(*int32)(unsafe.Pointer(pIdxInfo + 56)) |= int32(SQLITE_INDEX_SCAN_UNIQUE)
}

func _fts5UsePatternMatch(tls *libc.TLS, pConfig uintptr, p uintptr) (r int32) {
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FePattern == int32(FTS5_PATTERN_GLOB) && int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(FTS5_PATTERN_GLOB) {
		return int32(1)
	}
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FePattern == int32(FTS5_PATTERN_LIKE) && (int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(FTS5_PATTERN_LIKE) || int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(FTS5_PATTERN_GLOB)) {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Implementation of the xBestIndex method for FTS5 tables. Within the
//	** WHERE constraint, it searches for the following:
//	**
//	**   1. A MATCH constraint against the table column.
//	**   2. A MATCH constraint against the "rank" column.
//	**   3. A MATCH constraint against some other column.
//	**   4. An == constraint against the rowid column.
//	**   5. A < or <= constraint against the rowid column.
//	**   6. A > or >= constraint against the rowid column.
//	**
//	** Within the ORDER BY, the following are supported:
//	**
//	**   5. ORDER BY rank [ASC|DESC]
//	**   6. ORDER BY rowid [ASC|DESC]
//	**
//	** Information for the xFilter call is passed via both the idxNum and
//	** idxStr variables. Specifically, idxNum is a bitmask of the following
//	** flags used to encode the ORDER BY clause:
//	**
//	**     FTS5_BI_ORDER_RANK
//	**     FTS5_BI_ORDER_ROWID
//	**     FTS5_BI_ORDER_DESC
//	**
//	** idxStr is used to encode data from the WHERE clause. For each argument
//	** passed to the xFilter method, the following is appended to idxStr:
//	**
//	**   Match against table column:            "m"
//	**   Match against rank column:             "r"
//	**   Match against other column:            "M<column-number>"
//	**   LIKE  against other column:            "L<column-number>"
//	**   GLOB  against other column:            "G<column-number>"
//	**   Equality constraint against the rowid: "="
//	**   A < or <= against the rowid:           "<"
//	**   A > or >= against the rowid:           ">"
//	**
//	** This function ensures that there is at most one "r" or "=". And that if
//	** there exists an "=" then there is no "<" or ">".
//	**
//	** Costs are assigned as follows:
//	**
//	**  a) If an unusable MATCH operator is present in the WHERE clause, the
//	**     cost is unconditionally set to 1e50 (a really big number).
//	**
//	**  a) If a MATCH operator is present, the cost depends on the other
//	**     constraints also present. As follows:
//	**
//	**       * No other constraints:         cost=1000.0
//	**       * One rowid range constraint:   cost=750.0
//	**       * Both rowid range constraints: cost=500.0
//	**       * An == rowid constraint:       cost=100.0
//	**
//	**  b) Otherwise, if there is no MATCH:
//	**
//	**       * No other constraints:         cost=1000000.0
//	**       * One rowid range constraint:   cost=750000.0
//	**       * Both rowid range constraints: cost=250000.0
//	**       * An == rowid constraint:       cost=10.0
//	**
//	** Costs are not modified by the ORDER BY clause.
//	*/
func _fts5BestIndexMethod(tls *libc.TLS, pVTab uintptr, pInfo uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bSeenEq, bSeenGt, bSeenLt, bSeenMatch, bSeenRank, i, iCol, iCons, iIdxStr, iSort, idxFlags, nCol, op, v11, v12, v13, v14, v2, v3, v4, v5, v6, v7, v8, v9 int32
	var idxStr, p, p1, pConfig, pTab uintptr
	var v15, v16, v17, v18 float64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bSeenEq, bSeenGt, bSeenLt, bSeenMatch, bSeenRank, i, iCol, iCons, iIdxStr, iSort, idxFlags, idxStr, nCol, op, p, p1, pConfig, pTab, v11, v12, v13, v14, v15, v16, v17, v18, v2, v3, v4, v5, v6, v7, v8, v9
	pTab = pVTab
	pConfig = (*TFts5Table)(unsafe.Pointer(pTab)).FpConfig
	nCol = (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol
	idxFlags = 0
	iIdxStr = 0
	iCons = 0
	bSeenEq = 0
	bSeenGt = 0
	bSeenLt = 0
	bSeenMatch = 0
	bSeenRank = 0
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLock != 0 {
		(*TFts5Table)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+38283, 0)
		return int32(SQLITE_ERROR)
	}
	idxStr = Xsqlite3_malloc(tls, (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint*int32(8)+int32(1))
	if idxStr == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FidxStr = idxStr
	(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FneedToFreeIdxStr = int32(1)
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint) {
			break
		}
		p = (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
		iCol = (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn
		if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_MATCH) || int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) && iCol >= nCol {
			/* A MATCH operator or equivalent */
			if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) == 0 || iCol < 0 {
				/* As there exists an unusable MATCH constraint this is an
				 ** unusable plan. Set a prohibitively high cost. */
				(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(1e+50)
				*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr))) = 0
				return SQLITE_OK
			} else {
				if iCol == nCol+int32(1) {
					if bSeenRank != 0 {
						goto _1
					}
					v2 = iIdxStr
					iIdxStr++
					*(*int8)(unsafe.Pointer(idxStr + uintptr(v2))) = int8('r')
					bSeenRank = int32(1)
				} else {
					if iCol >= 0 {
						bSeenMatch = int32(1)
						v3 = iIdxStr
						iIdxStr++
						*(*int8)(unsafe.Pointer(idxStr + uintptr(v3))) = int8('M')
						Xsqlite3_snprintf(tls, int32(6), idxStr+uintptr(iIdxStr), __ccgo_ts+6511, libc.VaList(bp+8, iCol))
						idxStr += uintptr(libc.Xstrlen(tls, idxStr+uintptr(iIdxStr)))
					}
				}
				iCons++
				v4 = iCons
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v4
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).Fomit = uint8(1)
			}
		} else {
			if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 {
				if iCol >= 0 && iCol < nCol && _fts5UsePatternMatch(tls, pConfig, p) != 0 {
					v5 = iIdxStr
					iIdxStr++
					if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(FTS5_PATTERN_LIKE) {
						v6 = int32('L')
					} else {
						v6 = int32('G')
					}
					*(*int8)(unsafe.Pointer(idxStr + uintptr(v5))) = int8(v6)
					Xsqlite3_snprintf(tls, int32(6), idxStr+uintptr(iIdxStr), __ccgo_ts+6511, libc.VaList(bp+8, iCol))
					idxStr += uintptr(libc.Xstrlen(tls, idxStr+uintptr(iIdxStr)))
					iCons++
					v7 = iCons
					(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v7
				} else {
					if bSeenEq == 0 && int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) && iCol < 0 {
						v8 = iIdxStr
						iIdxStr++
						*(*int8)(unsafe.Pointer(idxStr + uintptr(v8))) = int8('=')
						bSeenEq = int32(1)
						iCons++
						v9 = iCons
						(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v9
					}
				}
			}
		}
		goto _1
	_1:
		;
		i++
	}
	if bSeenEq == 0 {
		i = 0
		for {
			if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint) {
				break
			}
			p1 = (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
			if (*Tsqlite3_index_constraint)(unsafe.Pointer(p1)).FiColumn < 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p1)).Fusable != 0 {
				op = int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p1)).Fop)
				if op == int32(SQLITE_INDEX_CONSTRAINT_LT) || op == int32(SQLITE_INDEX_CONSTRAINT_LE) {
					if bSeenLt != 0 {
						goto _10
					}
					v11 = iIdxStr
					iIdxStr++
					*(*int8)(unsafe.Pointer(idxStr + uintptr(v11))) = int8('<')
					iCons++
					v12 = iCons
					(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v12
					bSeenLt = int32(1)
				} else {
					if op == int32(SQLITE_INDEX_CONSTRAINT_GT) || op == int32(SQLITE_INDEX_CONSTRAINT_GE) {
						if bSeenGt != 0 {
							goto _10
						}
						v13 = iIdxStr
						iIdxStr++
						*(*int8)(unsafe.Pointer(idxStr + uintptr(v13))) = int8('>')
						iCons++
						v14 = iCons
						(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v14
						bSeenGt = int32(1)
					}
				}
			}
			goto _10
		_10:
			;
			i++
		}
	}
	*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr))) = int8('\000')
	/* Set idxFlags flags for the ORDER BY clause
	 **
	 ** Note that tokendata=1 tables cannot currently handle "ORDER BY rowid DESC".
	 */
	if (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnOrderBy == int32(1) {
		iSort = (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).FiColumn
		if iSort == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1) && bSeenMatch != 0 {
			idxFlags |= int32(FTS5_BI_ORDER_RANK)
		} else {
			if iSort == -int32(1) && (!((*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).Fdesc != 0) || !((*TFts5Config)(unsafe.Pointer(pConfig)).FbTokendata != 0)) {
				idxFlags |= int32(FTS5_BI_ORDER_ROWID)
			}
		}
		if idxFlags&(libc.Int32FromInt32(FTS5_BI_ORDER_RANK)|libc.Int32FromInt32(FTS5_BI_ORDER_ROWID)) != 0 {
			(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).ForderByConsumed = int32(1)
			if (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).Fdesc != 0 {
				idxFlags |= int32(FTS5_BI_ORDER_DESC)
			}
		}
	}
	/* Calculate the estimated cost based on the flags set in idxFlags. */
	if bSeenEq != 0 {
		if bSeenMatch != 0 {
			v15 = float64(100)
		} else {
			v15 = float64(10)
		}
		(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = v15
		if bSeenMatch == 0 {
			_fts5SetUniqueFlag(tls, pInfo)
		}
	} else {
		if bSeenLt != 0 && bSeenGt != 0 {
			if bSeenMatch != 0 {
				v16 = float64(500)
			} else {
				v16 = float64(250000)
			}
			(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = v16
		} else {
			if bSeenLt != 0 || bSeenGt != 0 {
				if bSeenMatch != 0 {
					v17 = float64(750)
				} else {
					v17 = float64(750000)
				}
				(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = v17
			} else {
				if bSeenMatch != 0 {
					v18 = float64(1000)
				} else {
					v18 = float64(1e+06)
				}
				(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = v18
			}
		}
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FidxNum = idxFlags
	return SQLITE_OK
}

func _fts5NewTransaction(tls *libc.TLS, pTab uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = (*TFts5Global)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal)).FpCsr
	for {
		if !(pCsr != 0) {
			break
		}
		if (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab == pTab {
			return SQLITE_OK
		}
		goto _1
	_1:
		;
		pCsr = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpNext
	}
	return _sqlite3Fts5StorageReset(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
}

// C documentation
//
//	/*
//	** Implementation of xOpen method.
//	*/
func _fts5OpenMethod(tls *libc.TLS, pVTab uintptr, ppCsr uintptr) (r int32) {
	var nByte Tsqlite3_int64
	var pConfig, pCsr, pGlobal, pTab, v2 uintptr
	var rc int32
	var v1 Ti64
	_, _, _, _, _, _, _, _ = nByte, pConfig, pCsr, pGlobal, pTab, rc, v1, v2
	pTab = pVTab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	pCsr = uintptr(0) /* Return code */
	rc = _fts5NewTransaction(tls, pTab)
	if rc == SQLITE_OK {
		nByte = int64(uint32(120) + uint32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*uint32(4))
		pCsr = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if pCsr != 0 {
			pGlobal = (*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal
			libc.Xmemset(tls, pCsr, 0, uint32(uint32(nByte)))
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize = pCsr + 1*120
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpNext = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpCsr
			(*TFts5Global)(unsafe.Pointer(pGlobal)).FpCsr = pCsr
			v2 = pGlobal + 24
			*(*Ti64)(unsafe.Pointer(v2))++
			v1 = *(*Ti64)(unsafe.Pointer(v2))
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId = v1
		} else {
			rc = int32(SQLITE_NOMEM)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppCsr)) = pCsr
	return rc
}

func _fts5StmtType(tls *libc.TLS, pCsr uintptr) (r int32) {
	var v1 int32
	_ = v1
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SCAN) {
		if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FbDesc != 0 {
			v1 = int32(FTS5_STMT_SCAN_DESC)
		} else {
			v1 = FTS5_STMT_SCAN_ASC
		}
		return v1
	}
	return int32(FTS5_STMT_LOOKUP)
}

// C documentation
//
//	/*
//	** This function is called after the cursor passed as the only argument
//	** is moved to point at a different row. It clears all cached data
//	** specific to the previous row stored by the cursor object.
//	*/
func _fts5CsrNewrow(tls *libc.TLS, pCsr uintptr) {
	*(*int32)(unsafe.Pointer(pCsr + 60)) |= libc.Int32FromInt32(FTS5CSR_REQUIRE_CONTENT) | libc.Int32FromInt32(FTS5CSR_REQUIRE_DOCSIZE) | libc.Int32FromInt32(FTS5CSR_REQUIRE_INST) | libc.Int32FromInt32(FTS5CSR_REQUIRE_POSLIST)
}

func _fts5FreeCursorComponents(tls *libc.TLS, pCsr uintptr) {
	var eStmt int32
	var pData, pNext, pSorter, pTab uintptr
	_, _, _, _, _ = eStmt, pData, pNext, pSorter, pTab
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter)
	Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst)
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt != 0 {
		eStmt = _fts5StmtType(tls, pCsr)
		_sqlite3Fts5StorageStmtRelease(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
	}
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 {
		pSorter = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
		Xsqlite3_finalize(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
		Xsqlite3_free(tls, pSorter)
	}
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan != int32(FTS5_PLAN_SOURCE) {
		_sqlite3Fts5ExprFree(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	}
	pData = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
	for {
		if !(pData != 0) {
			break
		}
		pNext = (*TFts5Auxdata)(unsafe.Pointer(pData)).FpNext
		if (*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete})))(tls, (*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr)
		}
		Xsqlite3_free(tls, pData)
		goto _1
	_1:
		;
		pData = pNext
	}
	Xsqlite3_finalize(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRankArgStmt)
	Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg)
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_FREE_ZRANK) != 0 {
		Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank)
		Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs)
	}
	_sqlite3Fts5IndexCloseReader(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	libc.Xmemset(tls, pCsr+24, 0, uint32(120)-uint32(int32(pCsr+24)-int32(pCsr)))
}

// C documentation
//
//	/*
//	** Close the cursor.  For additional information see the documentation
//	** on the xClose method of the virtual table interface.
//	*/
func _fts5CloseMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	var pCsr, pTab, pp uintptr
	_, _, _ = pCsr, pTab, pp
	if pCursor != 0 {
		pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
		pCsr = pCursor
		_fts5FreeCursorComponents(tls, pCsr)
		/* Remove the cursor from the Fts5Global.pCsr list */
		pp = (*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal + 44
		for {
			if !(*(*uintptr)(unsafe.Pointer(pp)) != pCsr) {
				break
			}
			goto _1
		_1:
			;
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 4
		}
		*(*uintptr)(unsafe.Pointer(pp)) = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpNext
		Xsqlite3_free(tls, pCsr)
	}
	return SQLITE_OK
}

func _fts5SorterNext(tls *libc.TLS, pCsr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, aBlob, pSorter, v1 uintptr
	var i, iOff, nBlob, rc int32
	var _ /* iVal at bp+0 */ int32
	_, _, _, _, _, _, _, _ = a, aBlob, i, iOff, nBlob, pSorter, rc, v1
	pSorter = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
	rc = Xsqlite3_step(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
	if rc == int32(SQLITE_DONE) {
		rc = SQLITE_OK
		*(*int32)(unsafe.Pointer(pCsr + 60)) |= libc.Int32FromInt32(FTS5CSR_EOF) | libc.Int32FromInt32(FTS5CSR_REQUIRE_CONTENT)
	} else {
		if rc == int32(SQLITE_ROW) {
			iOff = 0
			rc = SQLITE_OK
			(*TFts5Sorter)(unsafe.Pointer(pSorter)).FiRowid = Xsqlite3_column_int64(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt, 0)
			nBlob = Xsqlite3_column_bytes(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt, int32(1))
			v1 = Xsqlite3_column_blob(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt, int32(1))
			a = v1
			aBlob = v1
			/* nBlob==0 in detail=none mode. */
			if nBlob > 0 {
				i = 0
				for {
					if !(i < (*TFts5Sorter)(unsafe.Pointer(pSorter)).FnIdx-int32(1)) {
						break
					}
					a += uintptr(_sqlite3Fts5GetVarint32(tls, a, bp))
					iOff += *(*int32)(unsafe.Pointer(bp))
					*(*int32)(unsafe.Pointer(pSorter + 24 + uintptr(i)*4)) = iOff
					goto _2
				_2:
					;
					i++
				}
				*(*int32)(unsafe.Pointer(pSorter + 24 + uintptr(i)*4)) = t__predefined_ptrdiff_t(aBlob+uintptr(nBlob)) - int32(int32(a))
				(*TFts5Sorter)(unsafe.Pointer(pSorter)).FaPoslist = a
			}
			_fts5CsrNewrow(tls, pCsr)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Set the FTS5CSR_REQUIRE_RESEEK flag on all FTS5_PLAN_MATCH cursors
//	** open on table pTab.
//	*/
func _fts5TripCursors(tls *libc.TLS, pTab uintptr) {
	var pCsr uintptr
	_ = pCsr
	pCsr = (*TFts5Global)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal)).FpCsr
	for {
		if !(pCsr != 0) {
			break
		}
		if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_MATCH) && (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab == pTab {
			*(*int32)(unsafe.Pointer(pCsr + 60)) |= int32(FTS5CSR_REQUIRE_RESEEK)
		}
		goto _1
	_1:
		;
		pCsr = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpNext
	}
}

// C documentation
//
//	/*
//	** If the REQUIRE_RESEEK flag is set on the cursor passed as the first
//	** argument, close and reopen all Fts5IndexIter iterators that the cursor
//	** is using. Then attempt to move the cursor to a rowid equal to or laster
//	** (in the cursors sort order - ASC or DESC) than the current rowid.
//	**
//	** If the new rowid is not equal to the old, set output parameter *pbSkip
//	** to 1 before returning. Otherwise, leave it unchanged.
//	**
//	** Return SQLITE_OK if successful or if no reseek was required, or an
//	** error code if an error occurred.
//	*/
func _fts5CursorReseek(tls *libc.TLS, pCsr uintptr, pbSkip uintptr) (r int32) {
	var bDesc, rc int32
	var iRowid Ti64
	var pTab uintptr
	_, _, _, _ = bDesc, iRowid, pTab, rc
	rc = SQLITE_OK
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_RESEEK) != 0 {
		pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		bDesc = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FbDesc
		iRowid = _sqlite3Fts5ExprRowid(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
		rc = _sqlite3Fts5ExprFirst(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex, iRowid, bDesc)
		if rc == SQLITE_OK && iRowid != _sqlite3Fts5ExprRowid(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr) {
			*(*int32)(unsafe.Pointer(pbSkip)) = int32(1)
		}
		*(*int32)(unsafe.Pointer(pCsr + 60)) &= ^libc.Int32FromInt32(FTS5CSR_REQUIRE_RESEEK)
		_fts5CsrNewrow(tls, pCsr)
		if _sqlite3Fts5ExprEof(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr) != 0 {
			*(*int32)(unsafe.Pointer(pCsr + 60)) |= int32(FTS5CSR_EOF)
			*(*int32)(unsafe.Pointer(pbSkip)) = int32(1)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Advance the cursor to the next row in the table that matches the
//	** search criteria.
//	**
//	** Return SQLITE_OK if nothing goes wrong.  SQLITE_OK is returned
//	** even if we reach end-of-file.  The fts5EofMethod() will be called
//	** subsequently to determine whether or not an EOF was hit.
//	*/
func _fts5NextMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig, pCsr uintptr
	var rc, v1 int32
	var _ /* bSkip at bp+0 */ int32
	_, _, _, _ = pConfig, pCsr, rc, v1
	pCsr = pCursor
	/* If this cursor uses FTS5_PLAN_MATCH and this is a tokendata=1 table,
	 ** clear any token mappings accumulated at the fts5_index.c level. In
	 ** other cases, specifically FTS5_PLAN_SOURCE and FTS5_PLAN_SORTED_MATCH,
	 ** we need to retain the mappings for the entire query.  */
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_MATCH) && (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FpConfig)).FbTokendata != 0 {
		_sqlite3Fts5ExprClearTokens(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	}
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan < int32(3) {
		*(*int32)(unsafe.Pointer(bp)) = 0
		v1 = _fts5CursorReseek(tls, pCsr, bp)
		rc = v1
		if v1 != 0 || *(*int32)(unsafe.Pointer(bp)) != 0 {
			return rc
		}
		rc = _sqlite3Fts5ExprNext(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid)
		*(*int32)(unsafe.Pointer(pCsr + 60)) |= _sqlite3Fts5ExprEof(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
		_fts5CsrNewrow(tls, pCsr)
	} else {
		switch (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan {
		case int32(FTS5_PLAN_SPECIAL):
			*(*int32)(unsafe.Pointer(pCsr + 60)) |= int32(FTS5CSR_EOF)
			rc = SQLITE_OK
		case int32(FTS5_PLAN_SORTED_MATCH):
			rc = _fts5SorterNext(tls, pCsr)
		default:
			pConfig = (*TFts5Table)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FpConfig
			(*TFts5Config)(unsafe.Pointer(pConfig)).FbLock++
			rc = Xsqlite3_step(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
			(*TFts5Config)(unsafe.Pointer(pConfig)).FbLock--
			if rc != int32(SQLITE_ROW) {
				*(*int32)(unsafe.Pointer(pCsr + 60)) |= int32(FTS5CSR_EOF)
				rc = Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
				if rc != SQLITE_OK {
					(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)))
				}
			} else {
				rc = SQLITE_OK
			}
			break
		}
	}
	return rc
}

func _fts5PrepareStatement(tls *libc.TLS, ppStmt uintptr, pConfig uintptr, zFmt uintptr, va uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap Tva_list
	var rc int32
	var zSql uintptr
	var _ /* pRet at bp+0 */ uintptr
	_, _, _ = ap, rc, zSql
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), uint32(SQLITE_PREPARE_PERSISTENT), bp, uintptr(0))
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)))
		}
		Xsqlite3_free(tls, zSql)
	}
	_ = ap
	*(*uintptr)(unsafe.Pointer(ppStmt)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

func _fts5CursorFirstSorted(tls *libc.TLS, pTab uintptr, pCsr uintptr, bDesc int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var nByte Tsqlite3_int64
	var nPhrase, rc int32
	var pConfig, pSorter, zRank, zRankArgs, v1, v2, v3 uintptr
	_, _, _, _, _, _, _, _, _, _ = nByte, nPhrase, pConfig, pSorter, rc, zRank, zRankArgs, v1, v2, v3
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	zRank = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank
	zRankArgs = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs
	nPhrase = _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	nByte = int64(uint32(32) + uint32(4)*uint32(nPhrase-libc.Int32FromInt32(1)))
	pSorter = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	if pSorter == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pSorter, 0, uint32(uint32(nByte)))
	(*TFts5Sorter)(unsafe.Pointer(pSorter)).FnIdx = nPhrase
	/* TODO: It would be better to have some system for reusing statement
	 ** handles here, rather than preparing a new one for each query. But that
	 ** is not possible as SQLite reference counts the virtual table objects.
	 ** And since the statement required here reads from this very virtual
	 ** table, saving it creates a circular reference.
	 **
	 ** If SQLite a built-in statement cache, this wouldn't be a problem. */
	if zRankArgs != 0 {
		v1 = __ccgo_ts + 16397
	} else {
		v1 = __ccgo_ts + 1672
	}
	if zRankArgs != 0 {
		v2 = zRankArgs
	} else {
		v2 = __ccgo_ts + 1672
	}
	if bDesc != 0 {
		v3 = __ccgo_ts + 38322
	} else {
		v3 = __ccgo_ts + 38327
	}
	rc = _fts5PrepareStatement(tls, pSorter, pConfig, __ccgo_ts+38331, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zRank, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, v1, v2, v3))
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = pSorter
	if rc == SQLITE_OK {
		(*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = pCsr
		rc = _fts5SorterNext(tls, pCsr)
		(*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = uintptr(0)
	}
	if rc != SQLITE_OK {
		Xsqlite3_finalize(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
		Xsqlite3_free(tls, pSorter)
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = uintptr(0)
	}
	return rc
}

func _fts5CursorFirst(tls *libc.TLS, pTab uintptr, pCsr uintptr, bDesc int32) (r int32) {
	var pExpr uintptr
	var rc int32
	_, _ = pExpr, rc
	pExpr = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr
	rc = _sqlite3Fts5ExprFirst(tls, pExpr, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid, bDesc)
	if _sqlite3Fts5ExprEof(tls, pExpr) != 0 {
		*(*int32)(unsafe.Pointer(pCsr + 60)) |= int32(FTS5CSR_EOF)
	}
	_fts5CsrNewrow(tls, pCsr)
	return rc
}

// C documentation
//
//	/*
//	** Process a "special" query. A special query is identified as one with a
//	** MATCH expression that begins with a '*' character. The remainder of
//	** the text passed to the MATCH operator are used as  the special query
//	** parameters.
//	*/
func _fts5SpecialMatch(tls *libc.TLS, pTab uintptr, pCsr uintptr, zQuery uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var n, rc int32
	var z uintptr
	_, _, _ = n, rc, z
	rc = SQLITE_OK /* Return code */
	z = zQuery     /* Number of bytes in text at z */
	for int32(*(*int8)(unsafe.Pointer(z))) == int32(' ') {
		z++
	}
	n = 0
	for {
		if !(*(*int8)(unsafe.Pointer(z + uintptr(n))) != 0 && int32(*(*int8)(unsafe.Pointer(z + uintptr(n)))) != int32(' ')) {
			break
		}
		goto _1
	_1:
		;
		n++
	}
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_SPECIAL)
	if n == int32(5) && 0 == Xsqlite3_strnicmp(tls, __ccgo_ts+38386, z, n) {
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial = int64(_sqlite3Fts5IndexReads(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex))
	} else {
		if n == int32(2) && 0 == Xsqlite3_strnicmp(tls, __ccgo_ts+6854, z, n) {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId
		} else {
			/* An unrecognized directive. Return an error message. */
			(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+38392, libc.VaList(bp+8, n, z))
			rc = int32(SQLITE_ERROR)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Search for an auxiliary function named zName that can be used with table
//	** pTab. If one is found, return a pointer to the corresponding Fts5Auxiliary
//	** structure. Otherwise, if no such function exists, return NULL.
//	*/
func _fts5FindAuxiliary(tls *libc.TLS, pTab uintptr, zName uintptr) (r uintptr) {
	var pAux uintptr
	_ = pAux
	pAux = (*TFts5Global)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal)).FpAux
	for {
		if !(pAux != 0) {
			break
		}
		if Xsqlite3_stricmp(tls, zName, (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc) == 0 {
			return pAux
		}
		goto _1
	_1:
		;
		pAux = (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpNext
	}
	/* No function of the specified name was found. Return 0. */
	return uintptr(0)
}

func _fts5FindRankFunction(tls *libc.TLS, pCsr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var nByte Tsqlite3_int64
	var pAux, pConfig, pTab, zRank, zRankArgs, zSql uintptr
	var _ /* pStmt at bp+4 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _ = i, nByte, pAux, pConfig, pTab, zRank, zRankArgs, zSql
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	pAux = uintptr(0)
	zRank = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank
	zRankArgs = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs
	if zRankArgs != 0 {
		zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38420, libc.VaList(bp+16, zRankArgs))
		if zSql != 0 {
			*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), uint32(SQLITE_PREPARE_PERSISTENT), bp+4, uintptr(0))
			Xsqlite3_free(tls, zSql)
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4))) {
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg = Xsqlite3_column_count(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
					nByte = int64(uint32(4) * uint32((*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg))
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg = _sqlite3Fts5MallocZero(tls, bp, nByte)
					if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
						i = 0
						for {
							if !(i < (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg) {
								break
							}
							*(*uintptr)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg + uintptr(i)*4)) = Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), i)
							goto _1
						_1:
							;
							i++
						}
					}
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRankArgStmt = *(*uintptr)(unsafe.Pointer(bp + 4))
				} else {
					*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
				}
			}
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		pAux = _fts5FindAuxiliary(tls, pTab, zRank)
		if pAux == uintptr(0) {
			(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+38430, libc.VaList(bp+16, zRank))
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		}
	}
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRank = pAux
	return *(*int32)(unsafe.Pointer(bp))
}

func _fts5CursorParseRank(tls *libc.TLS, pConfig uintptr, pCsr uintptr, pRank uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var z uintptr
	var _ /* zRank at bp+0 */ uintptr
	var _ /* zRankArgs at bp+4 */ uintptr
	_, _ = rc, z
	rc = SQLITE_OK
	if pRank != 0 {
		z = Xsqlite3_value_text(tls, pRank)
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
		if z == uintptr(0) {
			if Xsqlite3_value_type(tls, pRank) == int32(SQLITE_NULL) {
				rc = int32(SQLITE_ERROR)
			}
		} else {
			rc = _sqlite3Fts5ConfigParseRank(tls, z, bp, bp+4)
		}
		if rc == SQLITE_OK {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = *(*uintptr)(unsafe.Pointer(bp))
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = *(*uintptr)(unsafe.Pointer(bp + 4))
			*(*int32)(unsafe.Pointer(pCsr + 60)) |= int32(FTS5CSR_FREE_ZRANK)
		} else {
			if rc == int32(SQLITE_ERROR) {
				(*Tsqlite3_vtab)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+38451, libc.VaList(bp+16, z))
			}
		}
	} else {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank != 0 {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs
		} else {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = __ccgo_ts + 36383
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = uintptr(0)
		}
	}
	return rc
}

func _fts5GetRowidLimit(tls *libc.TLS, pVal uintptr, iDefault Ti64) (r Ti64) {
	var eType int32
	_ = eType
	if pVal != 0 {
		eType = Xsqlite3_value_numeric_type(tls, pVal)
		if eType == int32(SQLITE_INTEGER) {
			return Xsqlite3_value_int64(tls, pVal)
		}
	}
	return iDefault
}

// C documentation
//
//	/*
//	** This is the xFilter interface for the virtual table.  See
//	** the virtual table xFilter method documentation for additional
//	** information.
//	**
//	** There are three possible query strategies:
//	**
//	**   1. Full-text search using a MATCH operator.
//	**   2. A by-rowid lookup.
//	**   3. A full-table scan.
//	*/
func _fts5FilterMethod(tls *libc.TLS, pCursor uintptr, idxNum int32, idxStr uintptr, nVal int32, apVal uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bDesc, bGlob, bOrderByRank, i, iCol, iIdxStr, rc, v2, v3, v4, v5, v7 int32
	var pConfig, pCsr, pRank, pRowidEq, pRowidGe, pRowidLe, pTab, pzErr, pzErrmsg, zText, zText1, v6 uintptr
	var _ /* pExpr at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDesc, bGlob, bOrderByRank, i, iCol, iIdxStr, pConfig, pCsr, pRank, pRowidEq, pRowidGe, pRowidLe, pTab, pzErr, pzErrmsg, rc, zText, zText1, v2, v3, v4, v5, v6, v7
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	pCsr = pCursor
	rc = SQLITE_OK        /* True if ORDER BY rank */
	pRank = uintptr(0)    /* rank MATCH ? expression (or NULL) */
	pRowidEq = uintptr(0) /* rowid = ? expression (or NULL) */
	pRowidLe = uintptr(0) /* rowid <= ? expression (or NULL) */
	pRowidGe = uintptr(0) /* Column on LHS of MATCH operator */
	pzErrmsg = (*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg
	iIdxStr = 0
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLock != 0 {
		(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+38283, 0)
		return int32(SQLITE_ERROR)
	}
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan != 0 {
		_fts5FreeCursorComponents(tls, pCsr)
		libc.Xmemset(tls, pCsr+24, 0, uint32(120)-uint32(int32(pCsr+24)-int32(pCsr)))
	}
	(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pTab + 8
	/* Decode the arguments passed through to this function. */
	i = 0
	for {
		if !(i < nVal) {
			break
		}
		v2 = iIdxStr
		iIdxStr++
		switch int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(v2)))) {
		case int32('r'):
			pRank = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4))
		case int32('M'):
			zText = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4)))
			if zText == uintptr(0) {
				zText = __ccgo_ts + 1672
			}
			iCol = 0
			for cond := true; cond; cond = int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) >= int32('0') && int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) <= int32('9') {
				iCol = iCol*int32(10) + (int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) - int32('0'))
				iIdxStr++
			}
			if int32(*(*int8)(unsafe.Pointer(zText))) == int32('*') {
				/* The user has issued a query of the form "MATCH '*...'". This
				 ** indicates that the MATCH expression is not a full text query,
				 ** but a request for an internal parameter.  */
				rc = _fts5SpecialMatch(tls, pTab, pCsr, zText+1)
				goto filter_out
			} else {
				pzErr = pTab + 8
				rc = _sqlite3Fts5ExprNew(tls, pConfig, 0, iCol, zText, bp, pzErr)
				if rc == SQLITE_OK {
					rc = _sqlite3Fts5ExprAnd(tls, pCsr+52, *(*uintptr)(unsafe.Pointer(bp)))
					*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
				}
				if rc != SQLITE_OK {
					goto filter_out
				}
			}
		case int32('L'):
			fallthrough
		case int32('G'):
			bGlob = libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr-int32(1))))) == int32('G'))
			zText1 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4)))
			iCol = 0
			for cond := true; cond; cond = int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) >= int32('0') && int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) <= int32('9') {
				iCol = iCol*int32(10) + (int32(*(*int8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) - int32('0'))
				iIdxStr++
			}
			if zText1 != 0 {
				rc = _sqlite3Fts5ExprPattern(tls, pConfig, bGlob, iCol, zText1, bp)
			}
			if rc == SQLITE_OK {
				rc = _sqlite3Fts5ExprAnd(tls, pCsr+52, *(*uintptr)(unsafe.Pointer(bp)))
				*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			}
			if rc != SQLITE_OK {
				goto filter_out
			}
		case int32('='):
			pRowidEq = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4))
		case int32('<'):
			pRowidLe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4))
		default:
			pRowidGe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4))
			break
		}
		goto _1
	_1:
		;
		i++
	}
	if idxNum&int32(FTS5_BI_ORDER_RANK) != 0 {
		v3 = int32(1)
	} else {
		v3 = 0
	}
	bOrderByRank = v3
	if idxNum&int32(FTS5_BI_ORDER_DESC) != 0 {
		v5 = int32(1)
	} else {
		v5 = 0
	}
	v4 = v5
	bDesc = v4
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FbDesc = v4
	/* Set the cursor upper and lower rowid limits. Only some strategies
	 ** actually use them. This is ok, as the xBestIndex() method leaves the
	 ** sqlite3_index_constraint.omit flag clear for range constraints
	 ** on the rowid field.  */
	if pRowidEq != 0 {
		v6 = pRowidEq
		pRowidGe = v6
		pRowidLe = v6
	}
	if bDesc != 0 {
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = _fts5GetRowidLimit(tls, pRowidLe, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = _fts5GetRowidLimit(tls, pRowidGe, int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
	} else {
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = _fts5GetRowidLimit(tls, pRowidLe, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = _fts5GetRowidLimit(tls, pRowidGe, int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
	}
	rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	if rc != SQLITE_OK {
		goto filter_out
	}
	if (*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr != 0 {
		/* If pSortCsr is non-NULL, then this call is being made as part of
		 ** processing for a "... MATCH <expr> ORDER BY rank" query (ePlan is
		 ** set to FTS5_PLAN_SORTED_MATCH). pSortCsr is the cursor that will
		 ** return results to the user for this query. The current cursor
		 ** (pCursor) is used to execute the query issued by function
		 ** fts5CursorFirstSorted() above.  */
		if (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FbDesc != 0 {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiFirstRowid
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiLastRowid
		} else {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiLastRowid
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiFirstRowid
		}
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_SOURCE)
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FpExpr
		rc = _fts5CursorFirst(tls, pTab, pCsr, bDesc)
	} else {
		if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr != 0 {
			rc = _fts5CursorParseRank(tls, pConfig, pCsr, pRank)
			if rc == SQLITE_OK {
				if bOrderByRank != 0 {
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_SORTED_MATCH)
					rc = _fts5CursorFirstSorted(tls, pTab, pCsr, bDesc)
				} else {
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_MATCH)
					rc = _fts5CursorFirst(tls, pTab, pCsr, bDesc)
				}
			}
		} else {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FzContent == uintptr(0) {
				*(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+38484, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
				rc = int32(SQLITE_ERROR)
			} else {
				/* This is either a full-table scan (ePlan==FTS5_PLAN_SCAN) or a lookup
				 ** by rowid (ePlan==FTS5_PLAN_ROWID).  */
				if pRowidEq != 0 {
					v7 = int32(FTS5_PLAN_ROWID)
				} else {
					v7 = int32(FTS5_PLAN_SCAN)
				}
				(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = v7
				rc = _sqlite3Fts5StorageStmt(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, _fts5StmtType(tls, pCsr), pCsr+48, pTab+8)
				if rc == SQLITE_OK {
					if pRowidEq != uintptr(0) {
						Xsqlite3_bind_value(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1), pRowidEq)
					} else {
						Xsqlite3_bind_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1), (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid)
						Xsqlite3_bind_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(2), (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid)
					}
					rc = _fts5NextMethod(tls, pCursor)
				}
			}
		}
	}
	goto filter_out
filter_out:
	;
	_sqlite3Fts5ExprFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pzErrmsg
	return rc
}

// C documentation
//
//	/*
//	** This is the xEof method of the virtual table. SQLite calls this
//	** routine to find out if it has reached the end of a result set.
//	*/
func _fts5EofMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	var pCsr uintptr
	var v1 int32
	_, _ = pCsr, v1
	pCsr = pCursor
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_EOF) != 0 {
		v1 = int32(1)
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Return the rowid that the cursor currently points to.
//	*/
func _fts5CursorRowid(tls *libc.TLS, pCsr uintptr) (r Ti64) {
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 {
		return (*TFts5Sorter)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter)).FiRowid
	} else {
		return _sqlite3Fts5ExprRowid(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	}
	return r
}

// C documentation
//
//	/*
//	** This is the xRowid method. The SQLite core calls this routine to
//	** retrieve the rowid for the current row of the result set. fts5
//	** exposes %_content.rowid as the rowid for the virtual table. The
//	** rowid should be written to *pRowid.
//	*/
func _fts5RowidMethod(tls *libc.TLS, pCursor uintptr, pRowid uintptr) (r int32) {
	var ePlan int32
	var pCsr uintptr
	_, _ = ePlan, pCsr
	pCsr = pCursor
	ePlan = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan
	switch ePlan {
	case int32(FTS5_PLAN_SPECIAL):
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = 0
	case int32(FTS5_PLAN_SOURCE):
		fallthrough
	case int32(FTS5_PLAN_MATCH):
		fallthrough
	case int32(FTS5_PLAN_SORTED_MATCH):
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = _fts5CursorRowid(tls, pCsr)
	default:
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = Xsqlite3_column_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
		break
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** If the cursor requires seeking (bSeekRequired flag is set), seek it.
//	** Return SQLITE_OK if no error occurs, or an SQLite error code otherwise.
//	**
//	** If argument bErrormsg is true and an error occurs, an error message may
//	** be left in sqlite3_vtab.zErrMsg.
//	*/
func _fts5SeekCursor(tls *libc.TLS, pCsr uintptr, bErrormsg int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eStmt, rc int32
	var pTab, pTab1, v1 uintptr
	_, _, _, _, _ = eStmt, pTab, pTab1, rc, v1
	rc = SQLITE_OK
	/* If the cursor does not yet have a statement handle, obtain one now. */
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt == uintptr(0) {
		pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		eStmt = _fts5StmtType(tls, pCsr)
		if bErrormsg != 0 {
			v1 = pTab + 8
		} else {
			v1 = uintptr(0)
		}
		rc = _sqlite3Fts5StorageStmt(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, pCsr+48, v1)
	}
	if rc == SQLITE_OK && (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_CONTENT) != 0 {
		pTab1 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
		Xsqlite3_bind_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1), _fts5CursorRowid(tls, pCsr))
		(*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock++
		rc = Xsqlite3_step(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
		(*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock--
		if rc == int32(SQLITE_ROW) {
			rc = SQLITE_OK
			*(*int32)(unsafe.Pointer(pCsr + 60)) &= ^libc.Int32FromInt32(FTS5CSR_REQUIRE_CONTENT)
		} else {
			rc = Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
			if rc == SQLITE_OK {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			} else {
				if (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FpzErrmsg != 0 {
					*(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).Fdb)))
				}
			}
		}
	}
	return rc
}

func _fts5SetVtabError(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Tva_list
	_ = ap /* ... printf arguments */
	ap = va
	(*TFts5FullTable)(unsafe.Pointer(p)).Fp.Fbase.FzErrMsg = Xsqlite3_vmprintf(tls, zFormat, ap)
	_ = ap
}

// C documentation
//
//	/*
//	** This function is called to handle an FTS INSERT command. In other words,
//	** an INSERT statement of the form:
//	**
//	**     INSERT INTO fts(fts) VALUES($pCmd)
//	**     INSERT INTO fts(fts, rank) VALUES($pCmd, $pVal)
//	**
//	** Argument pVal is the value assigned to column "fts" by the INSERT
//	** statement. This function returns SQLITE_OK if successful, or an SQLite
//	** error code if an error occurs.
//	**
//	** The commands implemented by this function are documented in the "Special
//	** INSERT Directives" section of the documentation. It should be updated if
//	** more commands are added to this function.
//	*/
func _fts5SpecialInsert(tls *libc.TLS, pTab uintptr, zCmd uintptr, pVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bLoadConfig, iArg, nMerge, rc int32
	var pConfig uintptr
	var _ /* bError at bp+0 */ int32
	_, _, _, _, _ = bLoadConfig, iArg, nMerge, pConfig, rc
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp)) = 0
	bLoadConfig = 0
	if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+38520, zCmd) {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			_fts5SetVtabError(tls, pTab, __ccgo_ts+38531, 0)
			rc = int32(SQLITE_ERROR)
		} else {
			rc = _sqlite3Fts5StorageDeleteAll(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
		}
		bLoadConfig = int32(1)
	} else {
		if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+38611, zCmd) {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_NONE) {
				_fts5SetVtabError(tls, pTab, __ccgo_ts+38619, 0)
				rc = int32(SQLITE_ERROR)
			} else {
				rc = _sqlite3Fts5StorageRebuild(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
			}
			bLoadConfig = int32(1)
		} else {
			if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+18784, zCmd) {
				rc = _sqlite3Fts5StorageOptimize(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
			} else {
				if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+38675, zCmd) {
					nMerge = Xsqlite3_value_int(tls, pVal)
					rc = _sqlite3Fts5StorageMerge(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, nMerge)
				} else {
					if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+38681, zCmd) {
						iArg = Xsqlite3_value_int(tls, pVal)
						rc = _sqlite3Fts5StorageIntegrity(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iArg)
					} else {
						if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+38697, zCmd) {
							rc = _sqlite3Fts5FlushToDisk(tls, pTab)
						} else {
							rc = _sqlite3Fts5FlushToDisk(tls, pTab)
							if rc == SQLITE_OK {
								rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
							}
							if rc == SQLITE_OK {
								rc = _sqlite3Fts5ConfigSetValue(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig, zCmd, pVal, bp)
							}
							if rc == SQLITE_OK {
								if *(*int32)(unsafe.Pointer(bp)) != 0 {
									rc = int32(SQLITE_ERROR)
								} else {
									rc = _sqlite3Fts5StorageConfigValue(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, zCmd, pVal, 0)
								}
							}
						}
					}
				}
			}
		}
	}
	if rc == SQLITE_OK && bLoadConfig != 0 {
		(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie--
		rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	}
	return rc
}

func _fts5SpecialDelete(tls *libc.TLS, pTab uintptr, apVal uintptr) (r int32) {
	var eType1, rc int32
	var iDel Tsqlite3_int64
	_, _, _ = eType1, iDel, rc
	rc = SQLITE_OK
	eType1 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4)))
	if eType1 == int32(SQLITE_INTEGER) {
		iDel = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4)))
		rc = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iDel, apVal+2*4)
	}
	return rc
}

func _fts5StorageInsert(tls *libc.TLS, pRc uintptr, pTab uintptr, apVal uintptr, piRowid uintptr) {
	var rc int32
	_ = rc
	rc = *(*int32)(unsafe.Pointer(pRc))
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5StorageContentInsert(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, piRowid)
	}
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5StorageIndexInsert(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, *(*Ti64)(unsafe.Pointer(piRowid)))
	}
	*(*int32)(unsafe.Pointer(pRc)) = rc
}

// C documentation
//
//	/*
//	** This function is the implementation of the xUpdate callback used by
//	** FTS3 virtual tables. It is invoked by SQLite each time a row is to be
//	** inserted, updated or deleted.
//	**
//	** A delete specifies a single argument - the rowid of the row to remove.
//	**
//	** Update and insert operations pass:
//	**
//	**   1. The "old" rowid, or NULL.
//	**   2. The "new" rowid.
//	**   3. Values for each of the nCol matchable columns.
//	**   4. Values for the two hidden columns (<tablename> and "rank").
//	*/
func _fts5UpdateMethod(tls *libc.TLS, pVtab uintptr, nArg int32, apVal uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bUpdateOrDelete, eConflict, eType0, eType1 int32
	var iDel, iNew, iNew1, iOld Ti64
	var pConfig, pTab, z, v1 uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _ = bUpdateOrDelete, eConflict, eType0, eType1, iDel, iNew, iNew1, iOld, pConfig, pTab, z, v1
	pTab = pVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig /* value_type() of apVal[0] */
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK                     /* Return code */
	bUpdateOrDelete = 0
	/* A transaction must be open when this is called. */
	if (*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz == 0 {
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
			return *(*int32)(unsafe.Pointer(bp))
		}
	}
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pTab + 8
	/* Put any active cursors into REQUIRE_SEEK state. */
	_fts5TripCursors(tls, pTab)
	eType0 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	if eType0 == int32(SQLITE_NULL) && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*4))) != int32(SQLITE_NULL) {
		/* A "special" INSERT op. These are handled separately. */
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*4)))
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+19294, z) {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
				_fts5SetVtabError(tls, pTab, __ccgo_ts+38703, 0)
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
			} else {
				*(*int32)(unsafe.Pointer(bp)) = _fts5SpecialDelete(tls, pTab, apVal)
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) = _fts5SpecialInsert(tls, pTab, z, *(*uintptr)(unsafe.Pointer(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1))*4)))
		}
	} else {
		/* A regular INSERT, UPDATE or DELETE statement. The trick here is that
		 ** any conflict on the rowid value must be detected before any
		 ** modifications are made to the database file. There are 4 cases:
		 **
		 **   1) DELETE
		 **   2) UPDATE (rowid not modified)
		 **   3) UPDATE (rowid modified)
		 **   4) INSERT
		 **
		 ** Cases 3 and 4 may violate the rowid constraint.
		 */
		eConflict = int32(SQLITE_ABORT)
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
			eConflict = Xsqlite3_vtab_on_conflict(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)
		}
		/* Filter out attempts to run UPDATE or DELETE on contentless tables.
		 ** This is not suported. Except - they are both supported if the CREATE
		 ** VIRTUAL TABLE statement contained "contentless_delete=1". */
		if eType0 == int32(SQLITE_INTEGER) && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_NONE) && (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete == 0 {
			if nArg > int32(1) {
				v1 = __ccgo_ts + 22327
			} else {
				v1 = __ccgo_ts + 38762
			}
			(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+38774, libc.VaList(bp+16, v1, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
			*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
		} else {
			if nArg == int32(1) {
				iDel = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal))) /* Rowid to delete */
				*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iDel, uintptr(0))
				bUpdateOrDelete = int32(1)
			} else {
				eType1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4)))
				if eType1 != int32(SQLITE_INTEGER) && eType1 != int32(SQLITE_NULL) {
					*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_MISMATCH)
				} else {
					if eType0 != int32(SQLITE_INTEGER) {
						/* An INSERT statement. If the conflict-mode is REPLACE, first remove
						 ** the current entry (if any). */
						if eConflict == int32(SQLITE_REPLACE) && eType1 == int32(SQLITE_INTEGER) {
							iNew = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4))) /* Rowid to delete */
							*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iNew, uintptr(0))
							bUpdateOrDelete = int32(1)
						}
						_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
					} else {
						iOld = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal)))        /* Old rowid */
						iNew1 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4))) /* New rowid */
						if eType1 == int32(SQLITE_INTEGER) && iOld != iNew1 {
							if eConflict == int32(SQLITE_REPLACE) {
								*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iOld, uintptr(0))
								if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
									*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iNew1, uintptr(0))
								}
								_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
							} else {
								*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageContentInsert(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, pRowid)
								if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
									*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iOld, uintptr(0))
								}
								if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
									*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageIndexInsert(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, *(*Tsqlite_int64)(unsafe.Pointer(pRowid)))
								}
							}
						} else {
							*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iOld, uintptr(0))
							_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
						}
						bUpdateOrDelete = int32(1)
					}
				}
			}
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && bUpdateOrDelete != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FbSecureDelete != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion == int32(FTS5_CURRENT_VERSION) {
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageConfigValue(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, __ccgo_ts+37311, uintptr(0), int32(FTS5_CURRENT_VERSION_SECUREDELETE))
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			(*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion = int32(FTS5_CURRENT_VERSION_SECUREDELETE)
		}
	}
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Implementation of xSync() method.
//	*/
func _fts5SyncMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pTab + 8
	rc = _sqlite3Fts5FlushToDisk(tls, pTab)
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
	return rc
}

// C documentation
//
//	/*
//	** Implementation of xBegin() method.
//	*/
func _fts5BeginMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	_fts5NewTransaction(tls, pVtab)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Implementation of xCommit() method. This is a no-op. The contents of
//	** the pending-terms hash-table have already been flushed into the database
//	** by fts5SyncMethod().
//	*/
func _fts5CommitMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	_ = pVtab /* Call below is a no-op for NDEBUG builds */
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Implementation of xRollback(). Discard the contents of the pending-terms
//	** hash-table. Any changes made to the database are reverted by SQLite.
//	*/
func _fts5RollbackMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	rc = _sqlite3Fts5StorageRollback(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
	return rc
}

func _fts5ApiUserData(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCtx
	return (*TFts5Auxiliary)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux)).FpUserData
}

func _fts5ApiColumnCount(tls *libc.TLS, pCtx uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCtx
	return (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig)).FnCol
}

func _fts5ApiColumnTotalSize(tls *libc.TLS, pCtx uintptr, iCol int32, pnToken uintptr) (r int32) {
	var pCsr, pTab uintptr
	_, _ = pCsr, pTab
	pCsr = pCtx
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	return _sqlite3Fts5StorageSize(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iCol, pnToken)
}

func _fts5ApiRowCount(tls *libc.TLS, pCtx uintptr, pnRow uintptr) (r int32) {
	var pCsr, pTab uintptr
	_, _ = pCsr, pTab
	pCsr = pCtx
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	return _sqlite3Fts5StorageRowCount(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, pnRow)
}

func _fts5ApiTokenize(tls *libc.TLS, pCtx uintptr, pText uintptr, nText int32, pUserData uintptr, xToken uintptr) (r int32) {
	var pCsr, pTab uintptr
	_, _ = pCsr, pTab
	pCsr = pCtx
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	return _sqlite3Fts5Tokenize(tls, (*TFts5Table)(unsafe.Pointer(pTab)).FpConfig, int32(FTS5_TOKENIZE_AUX), pText, nText, pUserData, xToken)
}

func _fts5ApiPhraseCount(tls *libc.TLS, pCtx uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCtx
	return _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
}

func _fts5ApiPhraseSize(tls *libc.TLS, pCtx uintptr, iPhrase int32) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCtx
	return _sqlite3Fts5ExprPhraseSize(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase)
}

func _fts5ApiColumnText(tls *libc.TLS, pCtx uintptr, iCol int32, pz uintptr, pn uintptr) (r int32) {
	var pCsr, pTab uintptr
	var rc int32
	_, _, _ = pCsr, pTab, rc
	rc = SQLITE_OK
	pCsr = pCtx
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	if iCol < 0 || iCol >= (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab)).FpConfig)).FnCol {
		rc = int32(SQLITE_RANGE)
	} else {
		if _fts5IsContentless(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab) != 0 || (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SPECIAL) {
			*(*uintptr)(unsafe.Pointer(pz)) = uintptr(0)
			*(*int32)(unsafe.Pointer(pn)) = 0
		} else {
			rc = _fts5SeekCursor(tls, pCsr, 0)
			if rc == SQLITE_OK {
				*(*uintptr)(unsafe.Pointer(pz)) = Xsqlite3_column_text(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol+int32(1))
				*(*int32)(unsafe.Pointer(pn)) = Xsqlite3_column_bytes(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol+int32(1))
			}
		}
	}
	return rc
}

func _fts5CsrPoslist(tls *libc.TLS, pCsr uintptr, iPhrase int32, pa uintptr, pn uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aPopulator, pConfig, pSorter uintptr
	var bLive, i, i1, rc, v2 int32
	var _ /* n at bp+0 */ int32
	var _ /* z at bp+4 */ uintptr
	_, _, _, _, _, _, _, _ = aPopulator, bLive, i, i1, pConfig, pSorter, rc, v2
	pConfig = (*TFts5Table)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig
	rc = SQLITE_OK
	bLive = libc.BoolInt32((*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter == uintptr(0))
	if iPhrase < 0 || iPhrase >= _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr) {
		rc = int32(SQLITE_RANGE)
	} else {
		if (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_POSLIST) != 0 {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail != FTS5_DETAIL_FULL {
				aPopulator = _sqlite3Fts5ExprClearPoslists(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, bLive)
				if aPopulator == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				}
				i = 0
				for {
					if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol && rc == SQLITE_OK) {
						break
					}
					rc = _fts5ApiColumnText(tls, pCsr, i, bp+4, bp)
					if rc == SQLITE_OK {
						rc = _sqlite3Fts5ExprPopulatePoslists(tls, pConfig, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, aPopulator, i, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp)))
					}
					goto _1
				_1:
					;
					i++
				}
				Xsqlite3_free(tls, aPopulator)
				if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 {
					_sqlite3Fts5ExprCheckPoslists(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, (*TFts5Sorter)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter)).FiRowid)
				}
			}
			*(*int32)(unsafe.Pointer(pCsr + 60)) &= ^libc.Int32FromInt32(FTS5CSR_REQUIRE_POSLIST)
		}
	}
	if rc == SQLITE_OK {
		if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_FULL {
			pSorter = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
			if iPhrase == 0 {
				v2 = 0
			} else {
				v2 = *(*int32)(unsafe.Pointer(pSorter + 24 + uintptr(iPhrase-int32(1))*4))
			}
			i1 = v2
			*(*int32)(unsafe.Pointer(pn)) = *(*int32)(unsafe.Pointer(pSorter + 24 + uintptr(iPhrase)*4)) - i1
			*(*uintptr)(unsafe.Pointer(pa)) = (*TFts5Sorter)(unsafe.Pointer(pSorter)).FaPoslist + uintptr(i1)
		} else {
			*(*int32)(unsafe.Pointer(pn)) = _sqlite3Fts5ExprPoslist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase, pa)
		}
	} else {
		*(*uintptr)(unsafe.Pointer(pa)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pn)) = 0
	}
	return rc
}

// C documentation
//
//	/*
//	** Ensure that the Fts5Cursor.nInstCount and aInst[] variables are populated
//	** correctly for the current view. Return SQLITE_OK if successful, or an
//	** SQLite error code otherwise.
//	*/
func _fts5CacheInstArray(tls *libc.TLS, pCsr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aInst, aIter uintptr
	var i, iBest, nCol, nInst, nIter, nNewSize, v3 int32
	var nByte Tsqlite3_int64
	var _ /* a at bp+4 */ uintptr
	var _ /* n at bp+8 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = aInst, aIter, i, iBest, nByte, nCol, nInst, nIter, nNewSize, v3
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK /* Number of iterators/phrases */
	nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig)).FnCol
	nIter = _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter == uintptr(0) {
		nByte = int64(uint32(24) * uint32(uint32(nIter)))
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter = _sqlite3Fts5MallocZero(tls, bp, nByte)
	}
	aIter = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter
	if aIter != 0 {
		nInst = 0
		/* Initialize all iterators */
		i = 0
		for {
			if !(i < nIter && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK) {
				break
			}
			*(*int32)(unsafe.Pointer(bp)) = _fts5CsrPoslist(tls, pCsr, i, bp+4, bp+8)
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				_sqlite3Fts5PoslistReaderInit(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), *(*int32)(unsafe.Pointer(bp + 8)), aIter+uintptr(i)*24)
			}
			goto _1
		_1:
			;
			i++
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			for int32(1) != 0 {
				iBest = -int32(1)
				i = 0
				for {
					if !(i < nIter) {
						break
					}
					if int32((*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FbEof) == 0 && (iBest < 0 || (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*24))).FiPos < (*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(iBest)*24))).FiPos) {
						iBest = i
					}
					goto _2
				_2:
					;
					i++
				}
				if iBest < 0 {
					break
				}
				nInst++
				if nInst >= (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc {
					if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc != 0 {
						v3 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc * int32(2)
					} else {
						v3 = int32(32)
					}
					nNewSize = v3
					aInst = Xsqlite3_realloc64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst, uint64(uint32(uint32(nNewSize))*uint32(4)*uint32(3)))
					if aInst != 0 {
						(*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst = aInst
						(*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc = nNewSize
					} else {
						nInst--
						*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_NOMEM)
						break
					}
				}
				aInst = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(int32(3)*(nInst-int32(1)))*4
				*(*int32)(unsafe.Pointer(aInst)) = iBest
				*(*int32)(unsafe.Pointer(aInst + 1*4)) = int32((*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(iBest)*24))).FiPos >> libc.Int32FromInt32(32))
				*(*int32)(unsafe.Pointer(aInst + 2*4)) = int32((*(*TFts5PoslistReader)(unsafe.Pointer(aIter + uintptr(iBest)*24))).FiPos & libc.Int64FromInt32(0x7FFFFFFF))
				if *(*int32)(unsafe.Pointer(aInst + 1*4)) < 0 || *(*int32)(unsafe.Pointer(aInst + 1*4)) >= nCol {
					*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					break
				}
				_sqlite3Fts5PoslistReaderNext(tls, aIter+uintptr(iBest)*24)
			}
		}
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstCount = nInst
		*(*int32)(unsafe.Pointer(pCsr + 60)) &= ^libc.Int32FromInt32(FTS5CSR_REQUIRE_INST)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func _fts5ApiInstCount(tls *libc.TLS, pCtx uintptr, pnInst uintptr) (r int32) {
	var pCsr uintptr
	var rc, v1 int32
	var v2 bool
	_, _, _, _ = pCsr, rc, v1, v2
	pCsr = pCtx
	rc = SQLITE_OK
	if v2 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_INST) == 0; !v2 {
		v1 = _fts5CacheInstArray(tls, pCsr)
		rc = v1
	}
	if v2 || SQLITE_OK == v1 {
		*(*int32)(unsafe.Pointer(pnInst)) = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstCount
	}
	return rc
}

func _fts5ApiInst(tls *libc.TLS, pCtx uintptr, iIdx int32, piPhrase uintptr, piCol uintptr, piOff uintptr) (r int32) {
	var pCsr uintptr
	var rc, v1 int32
	var v2 bool
	_, _, _, _ = pCsr, rc, v1, v2
	pCsr = pCtx
	rc = SQLITE_OK
	if v2 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_INST) == 0; !v2 {
		v1 = _fts5CacheInstArray(tls, pCsr)
		rc = v1
	}
	if v2 || SQLITE_OK == v1 {
		if iIdx < 0 || iIdx >= (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstCount {
			rc = int32(SQLITE_RANGE)
		} else {
			*(*int32)(unsafe.Pointer(piPhrase)) = *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*int32(3))*4))
			*(*int32)(unsafe.Pointer(piCol)) = *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*int32(3)+int32(1))*4))
			*(*int32)(unsafe.Pointer(piOff)) = *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*int32(3)+int32(2))*4))
		}
	}
	return rc
}

func _fts5ApiRowid(tls *libc.TLS, pCtx uintptr) (r Tsqlite3_int64) {
	return _fts5CursorRowid(tls, pCtx)
}

func _fts5ColumnSizeCb(tls *libc.TLS, pContext uintptr, tflags int32, pUnused uintptr, nUnused int32, iUnused1 int32, iUnused2 int32) (r int32) {
	var pCnt uintptr
	_ = pCnt
	pCnt = pContext
	_ = pUnused
	_ = nUnused
	_ = iUnused1
	_ = iUnused2
	if tflags&int32(FTS5_TOKEN_COLOCATED) == 0 {
		*(*int32)(unsafe.Pointer(pCnt))++
	}
	return SQLITE_OK
}

func _fts5ApiColumnSize(tls *libc.TLS, pCtx uintptr, iCol int32, pnToken uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, i1, i2, rc int32
	var iRowid Ti64
	var p, pConfig, pCsr, pTab uintptr
	var _ /* n at bp+4 */ int32
	var _ /* z at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _ = i, i1, i2, iRowid, p, pConfig, pCsr, pTab, rc
	pCsr = pCtx
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	rc = SQLITE_OK
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_DOCSIZE) != 0 {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			iRowid = _fts5CursorRowid(tls, pCsr)
			rc = _sqlite3Fts5StorageDocsize(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iRowid, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize)
		} else {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FzContent == uintptr(0) {
				i = 0
				for {
					if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
						break
					}
					if int32(*(*Tu8)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i)))) == 0 {
						*(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i)*4)) = -int32(1)
					}
					goto _1
				_1:
					;
					i++
				}
			} else {
				i1 = 0
				for {
					if !(rc == SQLITE_OK && i1 < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
						break
					}
					if int32(*(*Tu8)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i1)))) == 0 {
						p = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i1)*4
						*(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i1)*4)) = 0
						rc = _fts5ApiColumnText(tls, pCtx, i1, bp, bp+4)
						if rc == SQLITE_OK {
							rc = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_AUX), *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 4)), p, __ccgo_fp(_fts5ColumnSizeCb))
						}
					}
					goto _2
				_2:
					;
					i1++
				}
			}
		}
		*(*int32)(unsafe.Pointer(pCsr + 60)) &= ^libc.Int32FromInt32(FTS5CSR_REQUIRE_DOCSIZE)
	}
	if iCol < 0 {
		*(*int32)(unsafe.Pointer(pnToken)) = 0
		i2 = 0
		for {
			if !(i2 < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
				break
			}
			*(*int32)(unsafe.Pointer(pnToken)) += *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i2)*4))
			goto _3
		_3:
			;
			i2++
		}
	} else {
		if iCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
			*(*int32)(unsafe.Pointer(pnToken)) = *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(iCol)*4))
		} else {
			*(*int32)(unsafe.Pointer(pnToken)) = 0
			rc = int32(SQLITE_RANGE)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Implementation of the xSetAuxdata() method.
//	*/
func _fts5ApiSetAuxdata(tls *libc.TLS, pCtx uintptr, pPtr uintptr, xDelete uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCsr, pData uintptr
	var _ /* rc at bp+0 */ int32
	_, _ = pCsr, pData
	pCsr = pCtx
	/* Search through the cursors list of Fts5Auxdata objects for one that
	 ** corresponds to the currently executing auxiliary function.  */
	pData = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
	for {
		if !(pData != 0) {
			break
		}
		if (*TFts5Auxdata)(unsafe.Pointer(pData)).FpAux == (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux {
			break
		}
		goto _1
	_1:
		;
		pData = (*TFts5Auxdata)(unsafe.Pointer(pData)).FpNext
	}
	if pData != 0 {
		if (*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete})))(tls, (*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr)
		}
	} else {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
		pData = _sqlite3Fts5MallocZero(tls, bp, int64(16))
		if pData == uintptr(0) {
			if xDelete != 0 {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{xDelete})))(tls, pPtr)
			}
			return *(*int32)(unsafe.Pointer(bp))
		}
		(*TFts5Auxdata)(unsafe.Pointer(pData)).FpAux = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux
		(*TFts5Auxdata)(unsafe.Pointer(pData)).FpNext = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata = pData
	}
	(*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete = xDelete
	(*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr = pPtr
	return SQLITE_OK
}

func _fts5ApiGetAuxdata(tls *libc.TLS, pCtx uintptr, bClear int32) (r uintptr) {
	var pCsr, pData, pRet uintptr
	_, _, _ = pCsr, pData, pRet
	pCsr = pCtx
	pRet = uintptr(0)
	pData = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
	for {
		if !(pData != 0) {
			break
		}
		if (*TFts5Auxdata)(unsafe.Pointer(pData)).FpAux == (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux {
			break
		}
		goto _1
	_1:
		;
		pData = (*TFts5Auxdata)(unsafe.Pointer(pData)).FpNext
	}
	if pData != 0 {
		pRet = (*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr
		if bClear != 0 {
			(*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr = uintptr(0)
			(*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete = uintptr(0)
		}
	}
	return pRet
}

func _fts5ApiPhraseNext(tls *libc.TLS, pUnused uintptr, pIter uintptr, piCol uintptr, piOff uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* iVal at bp+0 */ int32
	_ = pUnused
	if (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa >= (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fb {
		*(*int32)(unsafe.Pointer(piCol)) = -int32(1)
		*(*int32)(unsafe.Pointer(piOff)) = -int32(1)
	} else {
		*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(_sqlite3Fts5GetVarint32(tls, (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp))
		if *(*int32)(unsafe.Pointer(bp)) == int32(1) {
			*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(_sqlite3Fts5GetVarint32(tls, (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp))
			*(*int32)(unsafe.Pointer(piCol)) = *(*int32)(unsafe.Pointer(bp))
			*(*int32)(unsafe.Pointer(piOff)) = 0
			*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(_sqlite3Fts5GetVarint32(tls, (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp))
		}
		*(*int32)(unsafe.Pointer(piOff)) += *(*int32)(unsafe.Pointer(bp)) - int32(2)
	}
}

func _fts5ApiPhraseFirst(tls *libc.TLS, pCtx uintptr, iPhrase int32, pIter uintptr, piCol uintptr, piOff uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCsr, v1 uintptr
	var rc int32
	var _ /* n at bp+0 */ int32
	_, _, _ = pCsr, rc, v1
	pCsr = pCtx
	rc = _fts5CsrPoslist(tls, pCsr, iPhrase, pIter, bp)
	if rc == SQLITE_OK {
		if (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa != 0 {
			v1 = (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa + uintptr(*(*int32)(unsafe.Pointer(bp)))
		} else {
			v1 = uintptr(0)
		}
		(*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fb = v1
		*(*int32)(unsafe.Pointer(piCol)) = 0
		*(*int32)(unsafe.Pointer(piOff)) = 0
		_fts5ApiPhraseNext(tls, pCtx, pIter, piCol, piOff)
	}
	return rc
}

func _fts5ApiPhraseNextColumn(tls *libc.TLS, pCtx uintptr, pIter uintptr, piCol uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig, pCsr uintptr
	var _ /* dummy at bp+4 */ int32
	var _ /* iIncr at bp+0 */ int32
	_, _ = pConfig, pCsr
	pCsr = pCtx
	pConfig = (*TFts5Table)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_COLUMNS) {
		if (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa >= (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fb {
			*(*int32)(unsafe.Pointer(piCol)) = -int32(1)
		} else {
			*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(_sqlite3Fts5GetVarint32(tls, (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp))
			*(*int32)(unsafe.Pointer(piCol)) += *(*int32)(unsafe.Pointer(bp)) - int32(2)
		}
	} else {
		for int32(1) != 0 {
			if (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa >= (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fb {
				*(*int32)(unsafe.Pointer(piCol)) = -int32(1)
				return
			}
			if int32(*(*uint8)(unsafe.Pointer((*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa))) == int32(0x01) {
				break
			}
			*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(_sqlite3Fts5GetVarint32(tls, (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp+4))
		}
		*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(int32(1) + _sqlite3Fts5GetVarint32(tls, (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa+1, piCol))
	}
}

func _fts5ApiPhraseFirstColumn(tls *libc.TLS, pCtx uintptr, iPhrase int32, pIter uintptr, piCol uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i1, rc, v1 int32
	var pConfig, pCsr, pSorter, v2, v3 uintptr
	var _ /* n at bp+0 */ int32
	var _ /* n at bp+4 */ int32
	_, _, _, _, _, _, _, _ = i1, pConfig, pCsr, pSorter, rc, v1, v2, v3
	rc = SQLITE_OK
	pCsr = pCtx
	pConfig = (*TFts5Table)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_COLUMNS) {
		pSorter = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
		if pSorter != 0 {
			if iPhrase == 0 {
				v1 = 0
			} else {
				v1 = *(*int32)(unsafe.Pointer(pSorter + 24 + uintptr(iPhrase-int32(1))*4))
			}
			i1 = v1
			*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(pSorter + 24 + uintptr(iPhrase)*4)) - i1
			(*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa = (*TFts5Sorter)(unsafe.Pointer(pSorter)).FaPoslist + uintptr(i1)
		} else {
			rc = _sqlite3Fts5ExprPhraseCollist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase, pIter, bp)
		}
		if rc == SQLITE_OK {
			if (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa != 0 {
				v2 = (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa + uintptr(*(*int32)(unsafe.Pointer(bp)))
			} else {
				v2 = uintptr(0)
			}
			(*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fb = v2
			*(*int32)(unsafe.Pointer(piCol)) = 0
			_fts5ApiPhraseNextColumn(tls, pCtx, pIter, piCol)
		}
	} else {
		rc = _fts5CsrPoslist(tls, pCsr, iPhrase, pIter, bp+4)
		if rc == SQLITE_OK {
			if (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa != 0 {
				v3 = (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa + uintptr(*(*int32)(unsafe.Pointer(bp + 4)))
			} else {
				v3 = uintptr(0)
			}
			(*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fb = v3
			if *(*int32)(unsafe.Pointer(bp + 4)) <= 0 {
				*(*int32)(unsafe.Pointer(piCol)) = -int32(1)
			} else {
				if int32(*(*uint8)(unsafe.Pointer((*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa))) == int32(0x01) {
					*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(int32(1) + _sqlite3Fts5GetVarint32(tls, (*TFts5PhraseIter)(unsafe.Pointer(pIter)).Fa+1, piCol))
				} else {
					*(*int32)(unsafe.Pointer(piCol)) = 0
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** xQueryToken() API implemenetation.
//	*/
func _fts5ApiQueryToken(tls *libc.TLS, pCtx uintptr, iPhrase int32, iToken int32, ppOut uintptr, pnOut uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCtx
	return _sqlite3Fts5ExprQueryToken(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase, iToken, ppOut, pnOut)
}

// C documentation
//
//	/*
//	** xInstToken() API implemenetation.
//	*/
func _fts5ApiInstToken(tls *libc.TLS, pCtx uintptr, iIdx int32, iToken int32, ppOut uintptr, pnOut uintptr) (r int32) {
	var iCol, iOff, iPhrase, rc, v1 int32
	var iRowid Ti64
	var pCsr uintptr
	var v2 bool
	_, _, _, _, _, _, _, _ = iCol, iOff, iPhrase, iRowid, pCsr, rc, v1, v2
	pCsr = pCtx
	rc = SQLITE_OK
	if v2 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_INST) == 0; !v2 {
		v1 = _fts5CacheInstArray(tls, pCsr)
		rc = v1
	}
	if v2 || SQLITE_OK == v1 {
		if iIdx < 0 || iIdx >= (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnInstCount {
			rc = int32(SQLITE_RANGE)
		} else {
			iPhrase = *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*int32(3))*4))
			iCol = *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*int32(3)+int32(1))*4))
			iOff = *(*int32)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*int32(3)+int32(2))*4))
			iRowid = _fts5CursorRowid(tls, pCsr)
			rc = _sqlite3Fts5ExprInstToken(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iRowid, iPhrase, iCol, iOff, iToken, ppOut, pnOut)
		}
	}
	return rc
}

var _sFts5Api = TFts5ExtensionApi{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_sFts5Api)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_fts5ApiUserData)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_fts5ApiColumnCount)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_fts5ApiRowCount)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_fts5ApiColumnTotalSize)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_fts5ApiTokenize)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_fts5ApiPhraseCount)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_fts5ApiPhraseSize)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_fts5ApiInstCount)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_fts5ApiInst)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_fts5ApiRowid)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_fts5ApiColumnText)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_fts5ApiColumnSize)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_fts5ApiQueryPhrase)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_fts5ApiSetAuxdata)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_fts5ApiGetAuxdata)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_fts5ApiPhraseFirst)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_fts5ApiPhraseNext)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_fts5ApiPhraseFirstColumn)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_fts5ApiPhraseNextColumn)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_fts5ApiQueryToken)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_fts5ApiInstToken)
}

// C documentation
//
//	/*
//	** Implementation of API function xQueryPhrase().
//	*/
func _fts5ApiQueryPhrase(tls *libc.TLS, pCtx uintptr, iPhrase int32, pUserData uintptr, xCallback uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCsr, pTab uintptr
	var rc int32
	var _ /* pNew at bp+0 */ uintptr
	_, _, _ = pCsr, pTab, rc
	pCsr = pCtx
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = _fts5OpenMethod(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab, bp)
	if rc == SQLITE_OK {
		(*TFts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FePlan = int32(FTS5_PLAN_MATCH)
		(*TFts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FiFirstRowid = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
		(*TFts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FiLastRowid = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
		(*TFts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FpVtab = pTab
		rc = _sqlite3Fts5ExprClonePhrase(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase, *(*uintptr)(unsafe.Pointer(bp))+52)
	}
	if rc == SQLITE_OK {
		rc = _fts5CursorFirst(tls, pTab, *(*uintptr)(unsafe.Pointer(bp)), 0)
		for {
			if !(rc == SQLITE_OK && (*TFts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fcsrflags&int32(FTS5CSR_EOF) == 0) {
				break
			}
			rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xCallback})))(tls, uintptr(unsafe.Pointer(&_sFts5Api)), *(*uintptr)(unsafe.Pointer(bp)), pUserData)
			if rc != SQLITE_OK {
				if rc == int32(SQLITE_DONE) {
					rc = SQLITE_OK
				}
				break
			}
			goto _1
		_1:
			;
			rc = _fts5NextMethod(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	_fts5CloseMethod(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func _fts5ApiInvoke(tls *libc.TLS, pAux uintptr, pCsr uintptr, context uintptr, argc int32, argv uintptr) {
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux = pAux
	(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FxFunc})))(tls, uintptr(unsafe.Pointer(&_sFts5Api)), pCsr, context, argc, argv)
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux = uintptr(0)
}

func _fts5CursorFromCsrid(tls *libc.TLS, pGlobal uintptr, iCsrId Ti64) (r uintptr) {
	var pCsr uintptr
	_ = pCsr
	pCsr = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpCsr
	for {
		if !(pCsr != 0) {
			break
		}
		if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId == iCsrId {
			break
		}
		goto _1
	_1:
		;
		pCsr = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpNext
	}
	return pCsr
}

func _fts5ApiCallback(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCsrId Ti64
	var pAux, pCsr, zErr uintptr
	_, _, _, _ = iCsrId, pAux, pCsr, zErr
	pAux = Xsqlite3_user_data(tls, context)
	iCsrId = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
	pCsr = _fts5CursorFromCsrid(tls, (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpGlobal, iCsrId)
	if pCsr == uintptr(0) || (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == 0 {
		zErr = Xsqlite3_mprintf(tls, __ccgo_ts+38811, libc.VaList(bp+8, iCsrId))
		Xsqlite3_result_error(tls, context, zErr, -int32(1))
		Xsqlite3_free(tls, zErr)
	} else {
		_fts5ApiInvoke(tls, pAux, pCsr, context, argc-int32(1), argv+1*4)
	}
}

// C documentation
//
//	/*
//	** Given cursor id iId, return a pointer to the corresponding Fts5Table
//	** object. Or NULL If the cursor id does not exist.
//	*/
func _sqlite3Fts5TableFromCsrid(tls *libc.TLS, pGlobal uintptr, iCsrId Ti64) (r uintptr) {
	var pCsr uintptr
	_ = pCsr
	pCsr = _fts5CursorFromCsrid(tls, pGlobal, iCsrId)
	if pCsr != 0 {
		return (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Return a "position-list blob" corresponding to the current position of
//	** cursor pCsr via sqlite3_result_blob(). A position-list blob contains
//	** the current position-list for each phrase in the query associated with
//	** cursor pCsr.
//	**
//	** A position-list blob begins with (nPhrase-1) varints, where nPhrase is
//	** the number of phrases in the query. Following the varints are the
//	** concatenated position lists for each phrase, in order.
//	**
//	** The first varint (if it exists) contains the size of the position list
//	** for phrase 0. The second (same disclaimer) contains the size of position
//	** list 1. And so on. There is no size field for the final position list,
//	** as it can be derived from the total size of the blob.
//	*/
func _fts5PoslistBlob(tls *libc.TLS, pCtx uintptr, pCsr uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, nByte, nPhrase, nPoslist int32
	var _ /* dummy at bp+16 */ uintptr
	var _ /* dummy at bp+24 */ uintptr
	var _ /* nByte at bp+28 */ int32
	var _ /* nPoslist at bp+36 */ int32
	var _ /* pPoslist at bp+20 */ uintptr
	var _ /* pPoslist at bp+32 */ uintptr
	var _ /* rc at bp+0 */ int32
	var _ /* val at bp+4 */ TFts5Buffer
	_, _, _, _ = i, nByte, nPhrase, nPoslist
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	nPhrase = _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	libc.Xmemset(tls, bp+4, 0, uint32(12))
	switch (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig)).FeDetail {
	case FTS5_DETAIL_FULL:
		goto _1
	case int32(FTS5_DETAIL_COLUMNS):
		goto _2
	default:
		goto _3
	}
	goto _4
_1:
	;
	/* Append the varints */
	i = 0
_7:
	;
	if !(i < nPhrase-int32(1)) {
		goto _5
	}
	nByte = _sqlite3Fts5ExprPoslist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+16)
	_sqlite3Fts5BufferAppendVarint(tls, bp, bp+4, int64(int64(nByte)))
	goto _6
_6:
	;
	i++
	goto _7
	goto _5
_5:
	;
	/* Append the position lists */
	i = 0
	for {
		if !(i < nPhrase) {
			break
		}
		nPoslist = _sqlite3Fts5ExprPoslist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+20)
		_sqlite3Fts5BufferAppendBlob(tls, bp, bp+4, uint32(uint32(nPoslist)), *(*uintptr)(unsafe.Pointer(bp + 20)))
		goto _8
	_8:
		;
		i++
	}
	goto _4
_2:
	;
	/* Append the varints */
	i = 0
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && i < nPhrase-int32(1)) {
			break
		}
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5ExprPhraseCollist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+24, bp+28)
		_sqlite3Fts5BufferAppendVarint(tls, bp, bp+4, int64(*(*int32)(unsafe.Pointer(bp + 28))))
		goto _9
	_9:
		;
		i++
	}
	/* Append the position lists */
	i = 0
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && i < nPhrase) {
			break
		}
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5ExprPhraseCollist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+32, bp+36)
		_sqlite3Fts5BufferAppendBlob(tls, bp, bp+4, uint32(*(*int32)(unsafe.Pointer(bp + 36))), *(*uintptr)(unsafe.Pointer(bp + 32)))
		goto _10
	_10:
		;
		i++
	}
	goto _4
_3:
	;
	goto _4
_4:
	;
	Xsqlite3_result_blob(tls, pCtx, (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp + 4))).Fn, __ccgo_fp(Xsqlite3_free))
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** This is the xColumn method, called by SQLite to request a value from
//	** the row that the supplied cursor currently points to.
//	*/
func _fts5ColumnMethod(tls *libc.TLS, pCursor uintptr, pCtx uintptr, iCol int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig, pCsr, pTab, zErr uintptr
	var rc, v1 int32
	var v2 bool
	_, _, _, _, _, _, _ = pConfig, pCsr, pTab, rc, zErr, v1, v2
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	pCsr = pCursor
	rc = SQLITE_OK
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SPECIAL) {
		if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
			Xsqlite3_result_int64(tls, pCtx, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial)
		}
	} else {
		if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
			/* User is requesting the value of the special column with the same name
			 ** as the table. Return the cursor integer id number. This value is only
			 ** useful in that it may be passed as the first argument to an FTS5
			 ** auxiliary function.  */
			Xsqlite3_result_int64(tls, pCtx, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId)
		} else {
			if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1) {
				/* The value of the "rank" column. */
				if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SOURCE) {
					_fts5PoslistBlob(tls, pCtx, pCsr)
				} else {
					if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_MATCH) || (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SORTED_MATCH) {
						if v2 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRank != 0; !v2 {
							v1 = _fts5FindRankFunction(tls, pCsr)
							rc = v1
						}
						if v2 || SQLITE_OK == v1 {
							_fts5ApiInvoke(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRank, pCsr, pCtx, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg)
						}
					}
				}
			} else {
				if !(_fts5IsContentless(tls, pTab) != 0) {
					(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pTab + 8
					rc = _fts5SeekCursor(tls, pCsr, int32(1))
					if rc == SQLITE_OK {
						Xsqlite3_result_value(tls, pCtx, Xsqlite3_column_value(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol+int32(1)))
					}
					(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = uintptr(0)
				} else {
					if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 && Xsqlite3_vtab_nochange(tls, pCtx) != 0 {
						zErr = Xsqlite3_mprintf(tls, __ccgo_ts+38832, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
						Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
						Xsqlite3_free(tls, zErr)
					}
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This routine implements the xFindFunction method for the FTS3
//	** virtual table.
//	*/
func _fts5FindFunctionMethod(tls *libc.TLS, pVtab uintptr, nUnused int32, zName uintptr, pxFunc uintptr, ppArg uintptr) (r int32) {
	var pAux, pTab uintptr
	_, _ = pAux, pTab
	pTab = pVtab
	_ = nUnused
	pAux = _fts5FindAuxiliary(tls, pTab, zName)
	if pAux != 0 {
		*(*uintptr)(unsafe.Pointer(pxFunc)) = __ccgo_fp(_fts5ApiCallback)
		*(*uintptr)(unsafe.Pointer(ppArg)) = pAux
		return int32(1)
	}
	/* No function of the specified name was found. Return 0. */
	return 0
}

// C documentation
//
//	/*
//	** Implementation of FTS5 xRename method. Rename an fts5 table.
//	*/
func _fts5RenameMethod(tls *libc.TLS, pVtab uintptr, zName uintptr) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	rc = _sqlite3Fts5StorageRename(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, zName)
	return rc
}

func _sqlite3Fts5FlushToDisk(tls *libc.TLS, pTab uintptr) (r int32) {
	_fts5TripCursors(tls, pTab)
	return _sqlite3Fts5StorageSync(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
}

// C documentation
//
//	/*
//	** The xSavepoint() method.
//	**
//	** Flush the contents of the pending-terms table to disk.
//	*/
func _fts5SavepointMethod(tls *libc.TLS, pVtab uintptr, iSavepoint int32) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	rc = SQLITE_OK
	rc = _sqlite3Fts5FlushToDisk(tls, pVtab)
	if rc == SQLITE_OK {
		(*TFts5FullTable)(unsafe.Pointer(pTab)).FiSavepoint = iSavepoint + int32(1)
	}
	return rc
}

// C documentation
//
//	/*
//	** The xRelease() method.
//	**
//	** This is a no-op.
//	*/
func _fts5ReleaseMethod(tls *libc.TLS, pVtab uintptr, iSavepoint int32) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	rc = SQLITE_OK
	if iSavepoint+int32(1) < (*TFts5FullTable)(unsafe.Pointer(pTab)).FiSavepoint {
		rc = _sqlite3Fts5FlushToDisk(tls, pTab)
		if rc == SQLITE_OK {
			(*TFts5FullTable)(unsafe.Pointer(pTab)).FiSavepoint = iSavepoint
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** The xRollbackTo() method.
//	**
//	** Discard the contents of the pending terms table.
//	*/
func _fts5RollbackToMethod(tls *libc.TLS, pVtab uintptr, iSavepoint int32) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	rc = SQLITE_OK
	_fts5TripCursors(tls, pTab)
	if iSavepoint+int32(1) <= (*TFts5FullTable)(unsafe.Pointer(pTab)).FiSavepoint {
		(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).Fpgsz = 0
		rc = _sqlite3Fts5StorageRollback(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
	}
	return rc
}

// C documentation
//
//	/*
//	** Register a new auxiliary function with global context pGlobal.
//	*/
func _fts5CreateAux(tls *libc.TLS, pApi uintptr, zName uintptr, pUserData uintptr, xFunc Tfts5_extension_function, xDestroy uintptr) (r int32) {
	var nByte, nName Tsqlite3_int64
	var pAux, pGlobal uintptr
	var rc int32
	_, _, _, _, _ = nByte, nName, pAux, pGlobal, rc
	pGlobal = pApi
	rc = Xsqlite3_overload_function(tls, (*TFts5Global)(unsafe.Pointer(pGlobal)).Fdb, zName, -int32(1))
	if rc == SQLITE_OK { /* Bytes of space to allocate */
		nName = int64(libc.Xstrlen(tls, zName) + uint32(1))
		nByte = int64(24) + nName
		pAux = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
		if pAux != 0 {
			libc.Xmemset(tls, pAux, 0, uint32(uint32(nByte)))
			(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc = pAux + 1*24
			libc.Xmemcpy(tls, (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc, zName, uint32(uint32(nName)))
			(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpGlobal = pGlobal
			(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpUserData = pUserData
			(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FxFunc = xFunc
			(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FxDestroy = xDestroy
			(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpNext = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpAux
			(*TFts5Global)(unsafe.Pointer(pGlobal)).FpAux = pAux
		} else {
			rc = int32(SQLITE_NOMEM)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Register a new tokenizer. This is the implementation of the
//	** fts5_api.xCreateTokenizer() method.
//	*/
func _fts5CreateTokenizer(tls *libc.TLS, pApi uintptr, zName uintptr, pUserData uintptr, pTokenizer uintptr, xDestroy uintptr) (r int32) {
	var nByte, nName Tsqlite3_int64
	var pGlobal, pNew uintptr
	var rc int32
	_, _, _, _, _ = nByte, nName, pGlobal, pNew, rc
	pGlobal = pApi /* Bytes of space to allocate */
	rc = SQLITE_OK
	nName = int64(libc.Xstrlen(tls, zName) + uint32(1))
	nByte = int64(28) + nName
	pNew = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	if pNew != 0 {
		libc.Xmemset(tls, pNew, 0, uint32(uint32(nByte)))
		(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FzName = pNew + 1*28
		libc.Xmemcpy(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FzName, zName, uint32(uint32(nName)))
		(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FpUserData = pUserData
		(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).Fx = *(*Tfts5_tokenizer)(unsafe.Pointer(pTokenizer))
		(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FxDestroy = xDestroy
		(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FpNext = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpTok
		(*TFts5Global)(unsafe.Pointer(pGlobal)).FpTok = pNew
		if (*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FpNext == uintptr(0) {
			(*TFts5Global)(unsafe.Pointer(pGlobal)).FpDfltTok = pNew
		}
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	return rc
}

func _fts5LocateTokenizer(tls *libc.TLS, pGlobal uintptr, zName uintptr) (r uintptr) {
	var pMod uintptr
	_ = pMod
	pMod = uintptr(0)
	if zName == uintptr(0) {
		pMod = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpDfltTok
	} else {
		pMod = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpTok
		for {
			if !(pMod != 0) {
				break
			}
			if Xsqlite3_stricmp(tls, zName, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FzName) == 0 {
				break
			}
			goto _1
		_1:
			;
			pMod = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpNext
		}
	}
	return pMod
}

// C documentation
//
//	/*
//	** Find a tokenizer. This is the implementation of the
//	** fts5_api.xFindTokenizer() method.
//	*/
func _fts5FindTokenizer(tls *libc.TLS, pApi uintptr, zName uintptr, ppUserData uintptr, pTokenizer uintptr) (r int32) {
	var pMod uintptr
	var rc int32
	_, _ = pMod, rc
	rc = SQLITE_OK
	pMod = _fts5LocateTokenizer(tls, pApi, zName)
	if pMod != 0 {
		*(*Tfts5_tokenizer)(unsafe.Pointer(pTokenizer)) = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx
		*(*uintptr)(unsafe.Pointer(ppUserData)) = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData
	} else {
		libc.Xmemset(tls, pTokenizer, 0, uint32(12))
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

func _sqlite3Fts5GetTokenizer(tls *libc.TLS, pGlobal uintptr, azArg uintptr, nArg int32, pConfig uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pMod, v1, v2 uintptr
	var rc, v3 int32
	_, _, _, _, _ = pMod, rc, v1, v2, v3
	rc = SQLITE_OK
	if nArg == 0 {
		v1 = uintptr(0)
	} else {
		v1 = *(*uintptr)(unsafe.Pointer(azArg))
	}
	pMod = _fts5LocateTokenizer(tls, pGlobal, v1)
	if pMod == uintptr(0) {
		rc = int32(SQLITE_ERROR)
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38903, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(azArg))))
	} else {
		if azArg != 0 {
			v2 = azArg + 1*4
		} else {
			v2 = uintptr(0)
		}
		if nArg != 0 {
			v3 = nArg - int32(1)
		} else {
			v3 = 0
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx.FxCreate})))(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData, v2, v3, pConfig+64)
		(*TFts5Config)(unsafe.Pointer(pConfig)).FpTokApi = pMod + 8
		if rc != SQLITE_OK {
			if pzErr != 0 {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38925, 0)
			}
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).FePattern = _sqlite3Fts5TokenizerPattern(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx.FxCreate, (*TFts5Config)(unsafe.Pointer(pConfig)).FpTok)
		}
	}
	if rc != SQLITE_OK {
		(*TFts5Config)(unsafe.Pointer(pConfig)).FpTokApi = uintptr(0)
		(*TFts5Config)(unsafe.Pointer(pConfig)).FpTok = uintptr(0)
	}
	return rc
}

func _fts5ModuleDestroy(tls *libc.TLS, pCtx uintptr) {
	var pAux, pGlobal, pNextAux, pNextTok, pTok uintptr
	_, _, _, _, _ = pAux, pGlobal, pNextAux, pNextTok, pTok
	pGlobal = pCtx
	pAux = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpAux
	for {
		if !(pAux != 0) {
			break
		}
		pNextAux = (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpNext
		if (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FxDestroy != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FxDestroy})))(tls, (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpUserData)
		}
		Xsqlite3_free(tls, pAux)
		goto _1
	_1:
		;
		pAux = pNextAux
	}
	pTok = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpTok
	for {
		if !(pTok != 0) {
			break
		}
		pNextTok = (*TFts5TokenizerModule)(unsafe.Pointer(pTok)).FpNext
		if (*TFts5TokenizerModule)(unsafe.Pointer(pTok)).FxDestroy != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5TokenizerModule)(unsafe.Pointer(pTok)).FxDestroy})))(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pTok)).FpUserData)
		}
		Xsqlite3_free(tls, pTok)
		goto _2
	_2:
		;
		pTok = pNextTok
	}
	Xsqlite3_free(tls, pGlobal)
}

func _fts5Fts5Func(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var pGlobal, ppApi uintptr
	_, _ = pGlobal, ppApi
	pGlobal = Xsqlite3_user_data(tls, pCtx)
	_ = nArg
	ppApi = Xsqlite3_value_pointer(tls, *(*uintptr)(unsafe.Pointer(apArg)), __ccgo_ts+38956)
	if ppApi != 0 {
		*(*uintptr)(unsafe.Pointer(ppApi)) = pGlobal
	}
}

// C documentation
//
//	/*
//	** Implementation of fts5_source_id() function.
//	*/
func _fts5SourceIdFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apUnused uintptr) {
	_ = nArg
	_ = apUnused
	Xsqlite3_result_text(tls, pCtx, __ccgo_ts+38969, -int32(1), uintptr(-libc.Int32FromInt32(1)))
}

// C documentation
//
//	/*
//	** Return true if zName is the extension on one of the shadow tables used
//	** by this module.
//	*/
func _fts5ShadowName(tls *libc.TLS, zName uintptr) (r int32) {
	var i uint32
	_ = i
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4)) {
			break
		}
		if Xsqlite3_stricmp(tls, zName, _azName2[i]) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

var _azName2 = [5]uintptr{
	0: __ccgo_ts + 39060,
	1: __ccgo_ts + 36572,
	2: __ccgo_ts + 27220,
	3: __ccgo_ts + 37139,
	4: __ccgo_ts + 13227,
}

// C documentation
//
//	/*
//	** Run an integrity check on the FTS5 data structures.  Return a string
//	** if anything is found amiss.  Return a NULL pointer if everything is
//	** OK.
//	*/
func _fts5IntegrityMethod(tls *libc.TLS, pVtab uintptr, zSchema uintptr, zTabname uintptr, isQuick int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pTab uintptr
	var rc, v1 int32
	_, _, _ = pTab, rc, v1
	pTab = pVtab
	_ = isQuick
	rc = _sqlite3Fts5StorageIntegrity(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, 0)
	if rc&int32(0xff) == int32(SQLITE_CORRUPT) {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+39067, libc.VaList(bp+8, zSchema, zTabname))
		if *(*uintptr)(unsafe.Pointer(pzErr)) != 0 {
			v1 = SQLITE_OK
		} else {
			v1 = int32(SQLITE_NOMEM)
		}
		rc = v1
	} else {
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+39113, libc.VaList(bp+8, zSchema, zTabname, Xsqlite3_errstr(tls, rc)))
		}
	}
	_sqlite3Fts5IndexCloseReader(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	return rc
}

func _fts5Init(tls *libc.TLS, db uintptr) (r int32) {
	var p, pGlobal uintptr
	var rc int32
	_, _, _ = p, pGlobal, rc
	pGlobal = uintptr(0)
	pGlobal = Xsqlite3_malloc(tls, int32(48))
	if pGlobal == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		p = pGlobal
		libc.Xmemset(tls, pGlobal, 0, uint32(48))
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fdb = db
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FiVersion = int32(2)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateFunction = __ccgo_fp(_fts5CreateAux)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateTokenizer = __ccgo_fp(_fts5CreateTokenizer)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxFindTokenizer = __ccgo_fp(_fts5FindTokenizer)
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+39176, uintptr(unsafe.Pointer(&_fts5Mod)), p, __ccgo_fp(_fts5ModuleDestroy))
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5IndexInit(tls, db)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5ExprInit(tls, pGlobal, db)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5AuxInit(tls, pGlobal)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5TokenizerInit(tls, pGlobal)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5VocabInit(tls, pGlobal, db)
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_create_function(tls, db, __ccgo_ts+39176, int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_fts5Fts5Func), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_create_function(tls, db, __ccgo_ts+39181, 0, libc.Int32FromInt32(SQLITE_UTF8)|libc.Int32FromInt32(SQLITE_DETERMINISTIC)|libc.Int32FromInt32(SQLITE_INNOCUOUS), p, __ccgo_fp(_fts5SourceIdFunc), uintptr(0), uintptr(0))
		}
	}
	/* If SQLITE_FTS5_ENABLE_TEST_MI is defined, assume that the file
	 ** fts5_test_mi.c is compiled and linked into the executable. And call
	 ** its entry point to enable the matchinfo() demo.  */
	return rc
}

var _fts5Mod = Tsqlite3_module{
	FiVersion: int32(4),
}

func init() {
	p := unsafe.Pointer(&_fts5Mod)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_fts5CreateMethod)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_fts5ConnectMethod)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_fts5BestIndexMethod)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_fts5DisconnectMethod)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_fts5DestroyMethod)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_fts5OpenMethod)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_fts5CloseMethod)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_fts5FilterMethod)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_fts5NextMethod)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_fts5EofMethod)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_fts5ColumnMethod)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_fts5RowidMethod)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_fts5UpdateMethod)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_fts5BeginMethod)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_fts5SyncMethod)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_fts5CommitMethod)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_fts5RollbackMethod)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_fts5FindFunctionMethod)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_fts5RenameMethod)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_fts5SavepointMethod)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_fts5ReleaseMethod)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_fts5RollbackToMethod)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_fts5ShadowName)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_fts5IntegrityMethod)
}

// C documentation
//
//	/*
//	** The following functions are used to register the module with SQLite. If
//	** this module is being built as part of the SQLite core (SQLITE_CORE is
//	** defined), then sqlite3_open() will call sqlite3Fts5Init() directly.
//	**
//	** Or, if this module is being built as a loadable extension,
//	** sqlite3Fts5Init() is omitted and the two standard entry points
//	** sqlite3_fts_init() and sqlite3_fts5_init() defined instead.
//	*/
func _sqlite3Fts5Init(tls *libc.TLS, db uintptr) (r int32) {
	return _fts5Init(tls, db)
}

/*
** 2014 May 31
**
** 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 "fts5Int.h" */

type TFts5Storage1 = struct {
	F__ccgo_align  [0]uint32
	FpConfig       uintptr
	FpIndex        uintptr
	FbTotalsValid  int32
	F__ccgo_align3 [4]byte
	FnTotalRow     Ti64
	FaTotalSize    uintptr
	FaStmt         [11]uintptr
}

type Fts5Storage1 = TFts5Storage1

// C documentation
//
//	/*
//	** Prepare the two insert statements - Fts5Storage.pInsertContent and
//	** Fts5Storage.pInsertDocsize - if they have not already been prepared.
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _fts5StorageGetStmt(tls *libc.TLS, p uintptr, eStmt int32, ppStmt uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var azStmt [11]uintptr
	var f, i, nCol, rc int32
	var pC, zBind, zSql, v2, v3 uintptr
	_, _, _, _, _, _, _, _, _, _ = azStmt, f, i, nCol, pC, rc, zBind, zSql, v2, v3
	rc = SQLITE_OK
	/* If there is no %_docsize table, there should be no requests for
	 ** statements to operate on it.  */
	if *(*uintptr)(unsafe.Pointer(p + 28 + uintptr(eStmt)*4)) == uintptr(0) {
		azStmt = [11]uintptr{
			0:  __ccgo_ts + 39196,
			1:  __ccgo_ts + 39264,
			2:  __ccgo_ts + 39333,
			3:  __ccgo_ts + 39366,
			4:  __ccgo_ts + 39405,
			5:  __ccgo_ts + 39445,
			6:  __ccgo_ts + 39484,
			7:  __ccgo_ts + 39527,
			8:  __ccgo_ts + 39566,
			9:  __ccgo_ts + 39610,
			10: __ccgo_ts + 39650,
		}
		pC = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
		zSql = uintptr(0)
		switch eStmt {
		case int32(FTS5_STMT_SCAN):
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*TFts5Config)(unsafe.Pointer(pC)).FzContent))
		case FTS5_STMT_SCAN_ASC:
			fallthrough
		case int32(FTS5_STMT_SCAN_DESC):
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*TFts5Config)(unsafe.Pointer(pC)).FzContent, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid))
		case int32(FTS5_STMT_LOOKUP):
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*TFts5Config)(unsafe.Pointer(pC)).FzContent, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid))
		case int32(FTS5_STMT_INSERT_CONTENT):
			fallthrough
		case int32(FTS5_STMT_REPLACE_CONTENT):
			nCol = (*TFts5Config)(unsafe.Pointer(pC)).FnCol + int32(1)
			zBind = Xsqlite3_malloc64(tls, uint64(int32(1)+nCol*int32(2)))
			if zBind != 0 {
				i = 0
				for {
					if !(i < nCol) {
						break
					}
					*(*int8)(unsafe.Pointer(zBind + uintptr(i*int32(2)))) = int8('?')
					*(*int8)(unsafe.Pointer(zBind + uintptr(i*int32(2)+int32(1)))) = int8(',')
					goto _1
				_1:
					;
					i++
				}
				*(*int8)(unsafe.Pointer(zBind + uintptr(i*int32(2)-int32(1)))) = int8('\000')
				zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName, zBind))
				Xsqlite3_free(tls, zBind)
			}
		case int32(FTS5_STMT_REPLACE_DOCSIZE):
			if (*TFts5Config)(unsafe.Pointer(pC)).FbContentlessDelete != 0 {
				v2 = __ccgo_ts + 39673
			} else {
				v2 = __ccgo_ts + 1672
			}
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName, v2))
		case int32(FTS5_STMT_LOOKUP_DOCSIZE):
			if (*TFts5Config)(unsafe.Pointer(pC)).FbContentlessDelete != 0 {
				v3 = __ccgo_ts + 39676
			} else {
				v3 = __ccgo_ts + 1672
			}
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+8, v3, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName))
		default:
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName))
			break
		}
		if zSql == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			f = int32(SQLITE_PREPARE_PERSISTENT)
			if eStmt > int32(FTS5_STMT_LOOKUP) {
				f |= int32(SQLITE_PREPARE_NO_VTAB)
			}
			(*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock++
			rc = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer(pC)).Fdb, zSql, -int32(1), uint32(uint32(f)), p+28+uintptr(eStmt)*4, uintptr(0))
			(*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock--
			Xsqlite3_free(tls, zSql)
			if rc != SQLITE_OK && pzErrMsg != 0 {
				*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4709, libc.VaList(bp+8, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pC)).Fdb)))
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppStmt)) = *(*uintptr)(unsafe.Pointer(p + 28 + uintptr(eStmt)*4))
	Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(ppStmt)))
	return rc
}

func _fts5ExecPrintf(tls *libc.TLS, db uintptr, pzErr uintptr, zFormat uintptr, va uintptr) (r int32) {
	var ap Tva_list
	var rc int32
	var zSql uintptr
	_, _, _ = ap, rc, zSql
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFormat, ap)
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_exec(tls, db, zSql, uintptr(0), uintptr(0), pzErr)
		Xsqlite3_free(tls, zSql)
	}
	_ = ap
	return rc
}

// C documentation
//
//	/*
//	** Drop all shadow tables. Return SQLITE_OK if successful or an SQLite error
//	** code otherwise.
//	*/
func _sqlite3Fts5DropAll(tls *libc.TLS, pConfig uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	_ = rc
	rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+39684, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+39788, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+39826, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	return rc
}

func _fts5StorageRenameOne(tls *libc.TLS, pConfig uintptr, pRc uintptr, zTail uintptr, zName uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRc)) = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+39864, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zTail, zName, zTail))
	}
}

func _sqlite3Fts5StorageRename(tls *libc.TLS, pStorage uintptr, zName uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig uintptr
	var _ /* rc at bp+0 */ int32
	_ = pConfig
	pConfig = (*TFts5Storage)(unsafe.Pointer(pStorage)).FpConfig
	*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StorageSync(tls, pStorage)
	_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+27220, zName)
	_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+13227, zName)
	_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+39060, zName)
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+37139, zName)
	}
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+36572, zName)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** Create the shadow table named zPost, with definition zDefn. Return
//	** SQLITE_OK if successful, or an SQLite error code otherwise.
//	*/
func _sqlite3Fts5CreateTable(tls *libc.TLS, pConfig uintptr, zPost uintptr, zDefn uintptr, bWithout int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var v1 uintptr
	var _ /* zErr at bp+0 */ uintptr
	_, _ = rc, v1
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	if bWithout != 0 {
		v1 = __ccgo_ts + 31860
	} else {
		v1 = __ccgo_ts + 1672
	}
	rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, bp, __ccgo_ts+39906, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, zDefn, v1))
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+39936, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, *(*uintptr)(unsafe.Pointer(bp))))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Open a new Fts5Index handle. If the bCreate argument is true, create
//	** and initialize the underlying tables
//	**
//	** If successful, set *pp to point to the new object and return SQLITE_OK.
//	** Otherwise, set *pp to NULL and return an SQLite error code.
//	*/
func _sqlite3Fts5StorageOpen(tls *libc.TLS, pConfig uintptr, pIndex uintptr, bCreate int32, pp uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iOff, nDefn, rc int32
	var nByte Tsqlite3_int64
	var p, zCols, zDefn, v1 uintptr
	_, _, _, _, _, _, _, _, _ = i, iOff, nByte, nDefn, p, rc, zCols, zDefn, v1
	rc = SQLITE_OK                                                                              /* Bytes of space to allocate */
	nByte = int64(uint32(72) + uint32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*uint32(8)) /* Fts5Storage.aTotalSize[] */
	v1 = Xsqlite3_malloc64(tls, uint64(uint64(nByte)))
	p = v1
	*(*uintptr)(unsafe.Pointer(pp)) = v1
	if !(p != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, p, 0, uint32(uint32(nByte)))
	(*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize = p + 1*72
	(*TFts5Storage)(unsafe.Pointer(p)).FpConfig = pConfig
	(*TFts5Storage)(unsafe.Pointer(p)).FpIndex = pIndex
	if bCreate != 0 {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			nDefn = int32(32) + (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol*int32(10)
			zDefn = Xsqlite3_malloc64(tls, uint64(int64(32)+int64((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*int64(10)))
			if zDefn == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				Xsqlite3_snprintf(tls, nDefn, zDefn, __ccgo_ts+39980, 0)
				iOff = int32(libc.Xstrlen(tls, zDefn))
				i = 0
				for {
					if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
						break
					}
					Xsqlite3_snprintf(tls, nDefn-iOff, zDefn+uintptr(iOff), __ccgo_ts+40003, libc.VaList(bp+8, i))
					iOff += int32(libc.Xstrlen(tls, zDefn+uintptr(iOff)))
					goto _2
				_2:
					;
					i++
				}
				rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+36572, zDefn, 0, pzErr)
			}
			Xsqlite3_free(tls, zDefn)
		}
		if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			zCols = __ccgo_ts + 40009
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
				zCols = __ccgo_ts + 40041
			}
			rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+37139, zCols, 0, pzErr)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+39060, __ccgo_ts+40089, int32(1), pzErr)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5StorageConfigValue(tls, p, __ccgo_ts+37311, uintptr(0), int32(FTS5_CURRENT_VERSION))
		}
	}
	if rc != 0 {
		_sqlite3Fts5StorageClose(tls, p)
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Close a handle opened by an earlier call to sqlite3Fts5StorageOpen().
//	*/
func _sqlite3Fts5StorageClose(tls *libc.TLS, p uintptr) (r int32) {
	var i, rc int32
	_, _ = i, rc
	rc = SQLITE_OK
	if p != 0 {
		/* Finalize all SQL statements */
		i = 0
		for {
			if !(i < int32(libc.Uint32FromInt64(44)/libc.Uint32FromInt64(4))) {
				break
			}
			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(p + 28 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		Xsqlite3_free(tls, p)
	}
	return rc
}

type TFts5InsertCtx = struct {
	FpStorage uintptr
	FiCol     int32
	FszCol    int32
}

type Fts5InsertCtx = TFts5InsertCtx

type TFts5InsertCtx1 = struct {
	FpStorage uintptr
	FiCol     int32
	FszCol    int32
}

type Fts5InsertCtx1 = TFts5InsertCtx1

// C documentation
//
//	/*
//	** Tokenization callback used when inserting tokens into the FTS index.
//	*/
func _fts5StorageInsertCallback(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) (r int32) {
	var pCtx, pIdx uintptr
	_, _ = pCtx, pIdx
	pCtx = pContext
	pIdx = (*TFts5Storage)(unsafe.Pointer((*TFts5InsertCtx)(unsafe.Pointer(pCtx)).FpStorage)).FpIndex
	_ = iUnused1
	_ = iUnused2
	if nToken > int32(FTS5_MAX_TOKEN_SIZE) {
		nToken = int32(FTS5_MAX_TOKEN_SIZE)
	}
	if tflags&int32(FTS5_TOKEN_COLOCATED) == 0 || (*TFts5InsertCtx)(unsafe.Pointer(pCtx)).FszCol == 0 {
		(*TFts5InsertCtx)(unsafe.Pointer(pCtx)).FszCol++
	}
	return _sqlite3Fts5IndexWrite(tls, pIdx, (*TFts5InsertCtx)(unsafe.Pointer(pCtx)).FiCol, (*TFts5InsertCtx)(unsafe.Pointer(pCtx)).FszCol-int32(1), pToken, nToken)
}

// C documentation
//
//	/*
//	** If a row with rowid iDel is present in the %_content table, add the
//	** delete-markers to the FTS index necessary to delete it. Do not actually
//	** remove the %_content row at this time though.
//	*/
func _fts5StorageDeleteFromIndex(tls *libc.TLS, p uintptr, iDel Ti64, apVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCol, nText, rc, rc2 int32
	var pConfig, zText uintptr
	var _ /* ctx at bp+4 */ TFts5InsertCtx
	var _ /* pSeek at bp+0 */ uintptr
	_, _, _, _, _, _ = iCol, nText, pConfig, rc, rc2, zText
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* SELECT to read row iDel from %_data */
	rc = SQLITE_OK
	if apVal == uintptr(0) {
		rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_LOOKUP), bp, uintptr(0))
		if rc != SQLITE_OK {
			return rc
		}
		Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), iDel)
		if Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(SQLITE_ROW) {
			return Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FpStorage = p
	(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol = -int32(1)
	iCol = int32(1)
	for {
		if !(rc == SQLITE_OK && iCol <= (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
			break
		}
		if int32(*(*Tu8)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(iCol-int32(1))))) == 0 {
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				zText = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), iCol)
				nText = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)), iCol)
			} else {
				if apVal != 0 {
					zText = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol-int32(1))*4)))
					nText = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol-int32(1))*4)))
				} else {
					goto _1
				}
			}
			(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FszCol = 0
			rc = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), zText, nText, bp+4, __ccgo_fp(_fts5StorageInsertCallback))
			*(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(iCol-int32(1))*8)) -= int64((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FszCol)
			if *(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(iCol-int32(1))*8)) < 0 {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		}
		goto _1
	_1:
		;
		iCol++
	}
	if rc == SQLITE_OK && (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow < int64(1) {
		rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	} else {
		(*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow--
	}
	rc2 = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == SQLITE_OK {
		rc = rc2
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is called to process a DELETE on a contentless_delete=1
//	** table. It adds the tombstone required to delete the entry with rowid
//	** iDel. If successful, SQLITE_OK is returned. Or, if an error occurs,
//	** an SQLite error code.
//	*/
func _fts5StorageContentlessDelete(tls *libc.TLS, p uintptr, iDel Ti64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iOrigin Ti64
	var rc int32
	var _ /* pLookup at bp+0 */ uintptr
	_, _ = iOrigin, rc
	iOrigin = 0
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = SQLITE_OK
	/* Look up the origin of the document in the %_docsize table. Store
	 ** this in stack variable iOrigin.  */
	rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_LOOKUP_DOCSIZE), bp, uintptr(0))
	if rc == SQLITE_OK {
		Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), iDel)
		if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			iOrigin = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
		}
		rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	if rc == SQLITE_OK && iOrigin != 0 {
		rc = _sqlite3Fts5IndexContentlessDelete(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, iOrigin, iDel)
	}
	return rc
}

// C documentation
//
//	/*
//	** Insert a record into the %_docsize table. Specifically, do:
//	**
//	**   INSERT OR REPLACE INTO %_docsize(id, sz) VALUES(iRowid, pBuf);
//	**
//	** If there is no %_docsize table (as happens if the columnsize=0 option
//	** is specified when the FTS5 table is created), this function is a no-op.
//	*/
func _fts5StorageInsertDocsize(tls *libc.TLS, p uintptr, iRowid Ti64, pBuf uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* iOrigin at bp+8 */ Ti64
	var _ /* pReplace at bp+0 */ uintptr
	_ = rc
	rc = SQLITE_OK
	if (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbColumnsize != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_REPLACE_DOCSIZE), bp, uintptr(0))
		if rc == SQLITE_OK {
			Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), iRowid)
			if (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbContentlessDelete != 0 {
				*(*Ti64)(unsafe.Pointer(bp + 8)) = 0
				rc = _sqlite3Fts5IndexGetOrigin(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, bp+8)
				Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(3), *(*Ti64)(unsafe.Pointer(bp + 8)))
			}
			if rc == SQLITE_OK {
				Xsqlite3_bind_blob(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2), (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn, libc.UintptrFromInt32(0))
				Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
				rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
				Xsqlite3_bind_null(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2))
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Load the contents of the "averages" record from disk into the
//	** p->nTotalRow and p->aTotalSize[] variables. If successful, and if
//	** argument bCache is true, set the p->bTotalsValid flag to indicate
//	** that the contents of aTotalSize[] and nTotalRow are valid until
//	** further notice.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _fts5StorageLoadTotals(tls *libc.TLS, p uintptr, bCache int32) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if (*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid == 0 {
		rc = _sqlite3Fts5IndexGetAverages(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, p+16, (*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize)
		(*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid = bCache
	}
	return rc
}

// C documentation
//
//	/*
//	** Store the current contents of the p->nTotalRow and p->aTotalSize[]
//	** variables in the "averages" record on disk.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _fts5StorageSaveTotals(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, nCol int32
	var _ /* buf at bp+0 */ TFts5Buffer
	var _ /* rc at bp+12 */ int32
	_, _ = i, nCol
	nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol
	*(*int32)(unsafe.Pointer(bp + 12)) = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint32(12))
	_sqlite3Fts5BufferAppendVarint(tls, bp+12, bp, (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow)
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		_sqlite3Fts5BufferAppendVarint(tls, bp+12, bp, *(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i)*8)))
		goto _1
	_1:
		;
		i++
	}
	if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 12)) = _sqlite3Fts5IndexSetAverages(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fn)
	}
	Xsqlite3_free(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp)
	return *(*int32)(unsafe.Pointer(bp + 12))
}

// C documentation
//
//	/*
//	** Remove a row from the FTS table.
//	*/
func _sqlite3Fts5StorageDelete(tls *libc.TLS, p uintptr, iDel Ti64, apVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig uintptr
	var rc int32
	var _ /* pDel at bp+0 */ uintptr
	_, _ = pConfig, rc
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = _fts5StorageLoadTotals(tls, p, int32(1))
	/* Delete the index records */
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5IndexBeginWrite(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, int32(1), iDel)
	}
	if rc == SQLITE_OK {
		if (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbContentlessDelete != 0 {
			rc = _fts5StorageContentlessDelete(tls, p, iDel)
		} else {
			rc = _fts5StorageDeleteFromIndex(tls, p, iDel, apVal)
		}
	}
	/* Delete the %_docsize record */
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_DELETE_DOCSIZE), bp, uintptr(0))
		if rc == SQLITE_OK {
			Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), iDel)
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	/* Delete the %_content record */
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		if rc == SQLITE_OK {
			rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_DELETE_CONTENT), bp, uintptr(0))
		}
		if rc == SQLITE_OK {
			Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), iDel)
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Delete all entries in the FTS5 index.
//	*/
func _sqlite3Fts5StorageDeleteAll(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pConfig uintptr
	var rc int32
	_, _ = pConfig, rc
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	(*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0
	/* Delete the contents of the %_data and %_docsize tables. */
	rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+40106, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+40156, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	/* Reinitialize the %_data table. This call creates the initial structure
	 ** and averages records.  */
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5IndexReinit(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex)
	}
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5StorageConfigValue(tls, p, __ccgo_ts+37311, uintptr(0), int32(FTS5_CURRENT_VERSION))
	}
	return rc
}

func _sqlite3Fts5StorageRebuild(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iRowid Ti64
	var nText, rc2 int32
	var pConfig, zText uintptr
	var _ /* buf at bp+0 */ TFts5Buffer
	var _ /* ctx at bp+16 */ TFts5InsertCtx
	var _ /* pScan at bp+12 */ uintptr
	var _ /* rc at bp+28 */ int32
	_, _, _, _, _ = iRowid, nText, pConfig, rc2, zText
	*(*TFts5Buffer)(unsafe.Pointer(bp)) = TFts5Buffer{}
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp + 12)) = uintptr(0)
	libc.Xmemset(tls, bp+16, 0, uint32(12))
	(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FpStorage = p
	*(*int32)(unsafe.Pointer(bp + 28)) = _sqlite3Fts5StorageDeleteAll(tls, p)
	if *(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 28)) = _fts5StorageLoadTotals(tls, p, int32(1))
	}
	if *(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 28)) = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_SCAN), bp+12, (*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)
	}
	for *(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 12))) {
		iRowid = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), 0)
		_sqlite3Fts5BufferZero(tls, bp)
		*(*int32)(unsafe.Pointer(bp + 28)) = _sqlite3Fts5IndexBeginWrite(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, 0, iRowid)
		(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FiCol = 0
		for {
			if !(*(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_OK && (*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FiCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
				break
			}
			(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FszCol = 0
			if int32(*(*Tu8)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FiCol)))) == 0 {
				zText = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), (*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FiCol+int32(1))
				nText = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 12)), (*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FiCol+int32(1))
				*(*int32)(unsafe.Pointer(bp + 28)) = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), zText, nText, bp+16, __ccgo_fp(_fts5StorageInsertCallback))
			}
			_sqlite3Fts5BufferAppendVarint(tls, bp+28, bp, int64((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FszCol))
			*(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FiCol)*8)) += int64((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FszCol)
			goto _1
		_1:
			;
			(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 16))).FiCol++
		}
		(*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow++
		if *(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 28)) = _fts5StorageInsertDocsize(tls, p, iRowid, bp)
		}
	}
	Xsqlite3_free(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp))).Fp)
	rc2 = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 12)))
	if *(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 28)) = rc2
	}
	/* Write the averages record */
	if *(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 28)) = _fts5StorageSaveTotals(tls, p)
	}
	return *(*int32)(unsafe.Pointer(bp + 28))
}

func _sqlite3Fts5StorageOptimize(tls *libc.TLS, p uintptr) (r int32) {
	return _sqlite3Fts5IndexOptimize(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex)
}

func _sqlite3Fts5StorageMerge(tls *libc.TLS, p uintptr, nMerge int32) (r int32) {
	return _sqlite3Fts5IndexMerge(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, nMerge)
}

func _sqlite3Fts5StorageReset(tls *libc.TLS, p uintptr) (r int32) {
	return _sqlite3Fts5IndexReset(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex)
}

// C documentation
//
//	/*
//	** Allocate a new rowid. This is used for "external content" tables when
//	** a NULL value is inserted into the rowid column. The new rowid is allocated
//	** by inserting a dummy row into the %_docsize table. The dummy will be
//	** overwritten later.
//	**
//	** If the %_docsize table does not exist, SQLITE_MISMATCH is returned. In
//	** this case the user is required to provide a rowid explicitly.
//	*/
func _fts5StorageNewRowid(tls *libc.TLS, p uintptr, piRowid uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pReplace at bp+0 */ uintptr
	_ = rc
	rc = int32(SQLITE_MISMATCH)
	if (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbColumnsize != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_REPLACE_DOCSIZE), bp, uintptr(0))
		if rc == SQLITE_OK {
			Xsqlite3_bind_null(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
			Xsqlite3_bind_null(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2))
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		if rc == SQLITE_OK {
			*(*Ti64)(unsafe.Pointer(piRowid)) = Xsqlite3_last_insert_rowid(tls, (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).Fdb)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Insert a new row into the FTS content table.
//	*/
func _sqlite3Fts5StorageContentInsert(tls *libc.TLS, p uintptr, apVal uintptr, piRowid uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var pConfig uintptr
	var _ /* pInsert at bp+0 */ uintptr
	_, _, _ = i, pConfig, rc
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	rc = SQLITE_OK
	/* Insert the new row into the %_content table. */
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL {
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4))) == int32(SQLITE_INTEGER) {
			*(*Ti64)(unsafe.Pointer(piRowid)) = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*4)))
		} else {
			rc = _fts5StorageNewRowid(tls, p, piRowid)
		}
	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0) /* Counter variable */
		rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_INSERT_CONTENT), bp, uintptr(0))
		i = int32(1)
		for {
			if !(rc == SQLITE_OK && i <= (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1)) {
				break
			}
			rc = Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp)), i, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*4)))
			goto _1
		_1:
			;
			i++
		}
		if rc == SQLITE_OK {
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		*(*Ti64)(unsafe.Pointer(piRowid)) = Xsqlite3_last_insert_rowid(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)
	}
	return rc
}

// C documentation
//
//	/*
//	** Insert new entries into the FTS index and %_docsize table.
//	*/
func _sqlite3Fts5StorageIndexInsert(tls *libc.TLS, p uintptr, apVal uintptr, iRowid Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nText int32
	var pConfig, zText uintptr
	var _ /* buf at bp+16 */ TFts5Buffer
	var _ /* ctx at bp+4 */ TFts5InsertCtx
	var _ /* rc at bp+0 */ int32
	_, _, _ = nText, pConfig, zText
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK /* Buffer used to build up %_docsize blob */
	libc.Xmemset(tls, bp+16, 0, uint32(12))
	(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FpStorage = p
	*(*int32)(unsafe.Pointer(bp)) = _fts5StorageLoadTotals(tls, p, int32(1))
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5IndexBeginWrite(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, 0, iRowid)
	}
	(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol = 0
	for {
		if !(*(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
			break
		}
		(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FszCol = 0
		if int32(*(*Tu8)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol)))) == 0 {
			zText = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol+int32(2))*4)))
			nText = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol+int32(2))*4)))
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), zText, nText, bp+4, __ccgo_fp(_fts5StorageInsertCallback))
		}
		_sqlite3Fts5BufferAppendVarint(tls, bp, bp+16, int64((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FszCol))
		*(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol)*8)) += int64((*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FszCol)
		goto _1
	_1:
		;
		(*(*TFts5InsertCtx)(unsafe.Pointer(bp + 4))).FiCol++
	}
	(*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow++
	/* Write the %_docsize record */
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = _fts5StorageInsertDocsize(tls, p, iRowid, bp+16)
	}
	Xsqlite3_free(tls, (*(*TFts5Buffer)(unsafe.Pointer(bp + 16))).Fp)
	return *(*int32)(unsafe.Pointer(bp))
}

func _fts5StorageCount(tls *libc.TLS, p uintptr, zSuffix uintptr, pnRow uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pConfig, zSql uintptr
	var rc int32
	var _ /* pCnt at bp+0 */ uintptr
	_, _, _ = pConfig, rc, zSql
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+40185, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zSuffix))
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = Xsqlite3_prepare_v2(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), bp, uintptr(0))
		if rc == SQLITE_OK {
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				*(*Ti64)(unsafe.Pointer(pnRow)) = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			}
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	Xsqlite3_free(tls, zSql)
	return rc
}

// C documentation
//
//	/*
//	** Context object used by sqlite3Fts5StorageIntegrity().
//	*/
type TFts5IntegrityCtx = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FiCol         int32
	FszCol        int32
	Fcksum        Tu64
	FpTermset     uintptr
	FpConfig      uintptr
}

type Fts5IntegrityCtx = TFts5IntegrityCtx

type TFts5IntegrityCtx1 = struct {
	F__ccgo_align [0]uint32
	FiRowid       Ti64
	FiCol         int32
	FszCol        int32
	Fcksum        Tu64
	FpTermset     uintptr
	FpConfig      uintptr
}

type Fts5IntegrityCtx1 = TFts5IntegrityCtx1

// C documentation
//
//	/*
//	** Tokenization callback used by integrity check.
//	*/
func _fts5StorageIntegrityCallback(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCol, iPos, ii, nByte, nChar, rc int32
	var pCtx, pTermset uintptr
	var _ /* bPresent at bp+0 */ int32
	_, _, _, _, _, _, _, _ = iCol, iPos, ii, nByte, nChar, pCtx, pTermset, rc
	pCtx = pContext
	pTermset = (*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpTermset
	rc = SQLITE_OK
	_ = iUnused1
	_ = iUnused2
	if nToken > int32(FTS5_MAX_TOKEN_SIZE) {
		nToken = int32(FTS5_MAX_TOKEN_SIZE)
	}
	if tflags&int32(FTS5_TOKEN_COLOCATED) == 0 || (*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FszCol == 0 {
		(*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FszCol++
	}
	switch (*TFts5Config)(unsafe.Pointer((*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpConfig)).FeDetail {
	case FTS5_DETAIL_FULL:
		iPos = (*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FszCol - int32(1)
		iCol = (*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiCol
	case int32(FTS5_DETAIL_COLUMNS):
		iPos = (*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiCol
		iCol = 0
	default:
		iPos = 0
		iCol = 0
		break
	}
	rc = _sqlite3Fts5TermsetAdd(tls, pTermset, 0, pToken, nToken, bp)
	if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) == 0 {
		*(*Tu64)(unsafe.Pointer(pCtx + 16)) ^= _sqlite3Fts5IndexEntryCksum(tls, (*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiRowid, iCol, iPos, 0, pToken, nToken)
	}
	ii = 0
	for {
		if !(rc == SQLITE_OK && ii < (*TFts5Config)(unsafe.Pointer((*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpConfig)).FnPrefix) {
			break
		}
		nChar = *(*int32)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer((*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpConfig)).FaPrefix + uintptr(ii)*4))
		nByte = _sqlite3Fts5IndexCharlenToBytelen(tls, pToken, nToken, nChar)
		if nByte != 0 {
			rc = _sqlite3Fts5TermsetAdd(tls, pTermset, ii+int32(1), pToken, nByte, bp)
			if *(*int32)(unsafe.Pointer(bp)) == 0 {
				*(*Tu64)(unsafe.Pointer(pCtx + 16)) ^= _sqlite3Fts5IndexEntryCksum(tls, (*TFts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiRowid, iCol, iPos, ii+int32(1), pToken, nByte)
			}
		}
		goto _1
	_1:
		;
		ii++
	}
	return rc
}

// C documentation
//
//	/*
//	** Check that the contents of the FTS index match that of the %_content
//	** table. Return SQLITE_OK if they do, or SQLITE_CORRUPT if not. Return
//	** some other SQLite error code if an error occurs while attempting to
//	** determine this.
//	*/
func _sqlite3Fts5StorageIntegrity(tls *libc.TLS, p uintptr, iArg int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aColSize, aTotalSize, pConfig, zText uintptr
	var bUseCksum, i, i1, nText, rc, rc2 int32
	var _ /* ctx at bp+0 */ TFts5IntegrityCtx
	var _ /* nRow at bp+40 */ Ti64
	var _ /* nRow at bp+48 */ Ti64
	var _ /* pScan at bp+32 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = aColSize, aTotalSize, bUseCksum, i, i1, nText, pConfig, rc, rc2, zText
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	rc = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint32(32))
	(*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FpConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	aTotalSize = Xsqlite3_malloc64(tls, uint64(uint32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*(libc.Uint32FromInt64(4)+libc.Uint32FromInt64(8))))
	if !(aTotalSize != 0) {
		return int32(SQLITE_NOMEM)
	}
	aColSize = aTotalSize + uintptr((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*8
	libc.Xmemset(tls, aTotalSize, 0, uint32(8)*uint32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol))
	bUseCksum = libc.BoolInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_EXTERNAL) && iArg != 0)
	if bUseCksum != 0 {
		/* Generate the expected index checksum based on the contents of the
		 ** %_content table. This block stores the checksum in ctx.cksum. */
		rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_SCAN), bp+32, uintptr(0))
		if rc == SQLITE_OK {
			for int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 32))) {
				(*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FiRowid = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 32)), 0)
				(*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FszCol = 0
				if (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
					rc = _sqlite3Fts5StorageDocsize(tls, p, (*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FiRowid, aColSize)
				}
				if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
					rc = _sqlite3Fts5TermsetNew(tls, bp+24)
				}
				i = 0
				for {
					if !(rc == SQLITE_OK && i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
						break
					}
					if *(*Tu8)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i))) != 0 {
						goto _1
					}
					(*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FiCol = i
					(*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FszCol = 0
					if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_COLUMNS) {
						rc = _sqlite3Fts5TermsetNew(tls, bp+24)
					}
					if rc == SQLITE_OK {
						zText = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 32)), i+int32(1))
						nText = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 32)), i+int32(1))
						rc = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), zText, nText, bp, __ccgo_fp(_fts5StorageIntegrityCallback))
					}
					if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 && (*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FszCol != *(*int32)(unsafe.Pointer(aColSize + uintptr(i)*4)) {
						rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
					}
					*(*Ti64)(unsafe.Pointer(aTotalSize + uintptr(i)*8)) += int64((*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FszCol)
					if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_COLUMNS) {
						_sqlite3Fts5TermsetFree(tls, (*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FpTermset)
						(*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FpTermset = uintptr(0)
					}
					goto _1
				_1:
					;
					i++
				}
				_sqlite3Fts5TermsetFree(tls, (*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FpTermset)
				(*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).FpTermset = uintptr(0)
				if rc != SQLITE_OK {
					break
				}
			}
			rc2 = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 32)))
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
		/* Test that the "totals" (sometimes called "averages") record looks Ok */
		if rc == SQLITE_OK {
			rc = _fts5StorageLoadTotals(tls, p, 0)
			i1 = 0
			for {
				if !(rc == SQLITE_OK && i1 < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
					break
				}
				if *(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i1)*8)) != *(*Ti64)(unsafe.Pointer(aTotalSize + uintptr(i1)*8)) {
					rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				goto _2
			_2:
				;
				i1++
			}
		}
		/* Check that the %_docsize and %_content tables contain the expected
		 ** number of rows.  */
		if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			*(*Ti64)(unsafe.Pointer(bp + 40)) = 0
			rc = _fts5StorageCount(tls, p, __ccgo_ts+36572, bp+40)
			if rc == SQLITE_OK && *(*Ti64)(unsafe.Pointer(bp + 40)) != (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		}
		if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			*(*Ti64)(unsafe.Pointer(bp + 48)) = 0
			rc = _fts5StorageCount(tls, p, __ccgo_ts+37139, bp+48)
			if rc == SQLITE_OK && *(*Ti64)(unsafe.Pointer(bp + 48)) != (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		}
	}
	/* Pass the expected checksum down to the FTS index module. It will
	 ** verify, amongst other things, that it matches the checksum generated by
	 ** inspecting the index itself.  */
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5IndexIntegrityCheck(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, (*(*TFts5IntegrityCtx)(unsafe.Pointer(bp))).Fcksum, bUseCksum)
	}
	Xsqlite3_free(tls, aTotalSize)
	return rc
}

// C documentation
//
//	/*
//	** Obtain an SQLite statement handle that may be used to read data from the
//	** %_content table.
//	*/
func _sqlite3Fts5StorageStmt(tls *libc.TLS, p uintptr, eStmt int32, pp uintptr, pzErrMsg uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _fts5StorageGetStmt(tls, p, eStmt, pp, pzErrMsg)
	if rc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(p + 28 + uintptr(eStmt)*4)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Release an SQLite statement handle obtained via an earlier call to
//	** sqlite3Fts5StorageStmt(). The eStmt parameter passed to this function
//	** must match that passed to the sqlite3Fts5StorageStmt() call.
//	*/
func _sqlite3Fts5StorageStmtRelease(tls *libc.TLS, p uintptr, eStmt int32, pStmt uintptr) {
	if *(*uintptr)(unsafe.Pointer(p + 28 + uintptr(eStmt)*4)) == uintptr(0) {
		Xsqlite3_reset(tls, pStmt)
		*(*uintptr)(unsafe.Pointer(p + 28 + uintptr(eStmt)*4)) = pStmt
	} else {
		Xsqlite3_finalize(tls, pStmt)
	}
}

func _fts5StorageDecodeSizeArray(tls *libc.TLS, aCol uintptr, nCol int32, aBlob uintptr, nBlob int32) (r int32) {
	var i, iOff int32
	_, _ = i, iOff
	iOff = 0
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		if iOff >= nBlob {
			return int32(1)
		}
		iOff += _sqlite3Fts5GetVarint32(tls, aBlob+uintptr(iOff), aCol+uintptr(i)*4)
		goto _1
	_1:
		;
		i++
	}
	return libc.BoolInt32(iOff != nBlob)
}

// C documentation
//
//	/*
//	** Argument aCol points to an array of integers containing one entry for
//	** each table column. This function reads the %_docsize record for the
//	** specified rowid and populates aCol[] with the results.
//	**
//	** An SQLite error code is returned if an error occurs, or SQLITE_OK
//	** otherwise.
//	*/
func _sqlite3Fts5StorageDocsize(tls *libc.TLS, p uintptr, iRowid Ti64, aCol uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aBlob uintptr
	var bCorrupt, nBlob, nCol, rc int32
	var _ /* pLookup at bp+0 */ uintptr
	_, _, _, _, _ = aBlob, bCorrupt, nBlob, nCol, rc
	nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol /* Number of user columns in table */
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)                                             /* Return Code */
	rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_LOOKUP_DOCSIZE), bp, uintptr(0))
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		bCorrupt = int32(1)
		Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), iRowid)
		if int32(SQLITE_ROW) == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			aBlob = Xsqlite3_column_blob(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			nBlob = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			if 0 == _fts5StorageDecodeSizeArray(tls, aCol, nCol, aBlob, nBlob) {
				bCorrupt = 0
			}
		}
		rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if bCorrupt != 0 && rc == SQLITE_OK {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	} else {
	}
	return rc
}

func _sqlite3Fts5StorageSize(tls *libc.TLS, p uintptr, iCol int32, pnToken uintptr) (r int32) {
	var i, rc int32
	_, _ = i, rc
	rc = _fts5StorageLoadTotals(tls, p, 0)
	if rc == SQLITE_OK {
		*(*Ti64)(unsafe.Pointer(pnToken)) = 0
		if iCol < 0 {
			i = 0
			for {
				if !(i < (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol) {
					break
				}
				*(*Ti64)(unsafe.Pointer(pnToken)) += *(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i)*8))
				goto _1
			_1:
				;
				i++
			}
		} else {
			if iCol < (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol {
				*(*Ti64)(unsafe.Pointer(pnToken)) = *(*Ti64)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(iCol)*8))
			} else {
				rc = int32(SQLITE_RANGE)
			}
		}
	}
	return rc
}

func _sqlite3Fts5StorageRowCount(tls *libc.TLS, p uintptr, pnRow uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _fts5StorageLoadTotals(tls, p, 0)
	if rc == SQLITE_OK {
		/* nTotalRow being zero does not necessarily indicate a corrupt
		 ** database - it might be that the FTS5 table really does contain zero
		 ** rows. However this function is only called from the xRowCount() API,
		 ** and there is no way for that API to be invoked if the table contains
		 ** no rows. Hence the FTS5_CORRUPT return.  */
		*(*Ti64)(unsafe.Pointer(pnRow)) = (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow
		if (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow <= 0 {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Flush any data currently held in-memory to disk.
//	*/
func _sqlite3Fts5StorageSync(tls *libc.TLS, p uintptr) (r int32) {
	var iLastRowid Ti64
	var rc int32
	_, _ = iLastRowid, rc
	rc = SQLITE_OK
	iLastRowid = Xsqlite3_last_insert_rowid(tls, (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).Fdb)
	if (*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid != 0 {
		rc = _fts5StorageSaveTotals(tls, p)
		if rc == SQLITE_OK {
			(*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0
		}
	}
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5IndexSync(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex)
	}
	Xsqlite3_set_last_insert_rowid(tls, (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).Fdb, iLastRowid)
	return rc
}

func _sqlite3Fts5StorageRollback(tls *libc.TLS, p uintptr) (r int32) {
	(*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0
	return _sqlite3Fts5IndexRollback(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex)
}

func _sqlite3Fts5StorageConfigValue(tls *libc.TLS, p uintptr, z uintptr, pVal uintptr, iVal int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iNew, rc int32
	var _ /* pReplace at bp+0 */ uintptr
	_, _ = iNew, rc
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_REPLACE_CONFIG), bp, uintptr(0))
	if rc == SQLITE_OK {
		Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), z, -int32(1), libc.UintptrFromInt32(0))
		if pVal != 0 {
			Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2), pVal)
		} else {
			Xsqlite3_bind_int(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2), iVal)
		}
		Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
		rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		Xsqlite3_bind_null(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1))
	}
	if rc == SQLITE_OK && pVal != 0 {
		iNew = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FiCookie + int32(1)
		rc = _sqlite3Fts5IndexSetCookie(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, iNew)
		if rc == SQLITE_OK {
			(*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FiCookie = iNew
		}
	}
	return rc
}

/*
** 2014 May 31
**
** 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 "fts5Int.h" */

/**************************************************************************
** Start of ascii tokenizer implementation.
 */

// C documentation
//
//	/*
//	** For tokenizers with no "unicode" modifier, the set of token characters
//	** is the same as the set of ASCII range alphanumeric characters.
//	*/
var _aAsciiTokenChar = [128]uint8{
	48:  uint8(1),
	49:  uint8(1),
	50:  uint8(1),
	51:  uint8(1),
	52:  uint8(1),
	53:  uint8(1),
	54:  uint8(1),
	55:  uint8(1),
	56:  uint8(1),
	57:  uint8(1),
	65:  uint8(1),
	66:  uint8(1),
	67:  uint8(1),
	68:  uint8(1),
	69:  uint8(1),
	70:  uint8(1),
	71:  uint8(1),
	72:  uint8(1),
	73:  uint8(1),
	74:  uint8(1),
	75:  uint8(1),
	76:  uint8(1),
	77:  uint8(1),
	78:  uint8(1),
	79:  uint8(1),
	80:  uint8(1),
	81:  uint8(1),
	82:  uint8(1),
	83:  uint8(1),
	84:  uint8(1),
	85:  uint8(1),
	86:  uint8(1),
	87:  uint8(1),
	88:  uint8(1),
	89:  uint8(1),
	90:  uint8(1),
	97:  uint8(1),
	98:  uint8(1),
	99:  uint8(1),
	100: uint8(1),
	101: uint8(1),
	102: uint8(1),
	103: uint8(1),
	104: uint8(1),
	105: uint8(1),
	106: uint8(1),
	107: uint8(1),
	108: uint8(1),
	109: uint8(1),
	110: uint8(1),
	111: uint8(1),
	112: uint8(1),
	113: uint8(1),
	114: uint8(1),
	115: uint8(1),
	116: uint8(1),
	117: uint8(1),
	118: uint8(1),
	119: uint8(1),
	120: uint8(1),
	121: uint8(1),
	122: uint8(1),
}

type TAsciiTokenizer = struct {
	FaTokenChar [128]uint8
}

type AsciiTokenizer = TAsciiTokenizer

type TAsciiTokenizer1 = struct {
	FaTokenChar [128]uint8
}

type AsciiTokenizer1 = TAsciiTokenizer1

func _fts5AsciiAddExceptions(tls *libc.TLS, p uintptr, zArg uintptr, bTokenChars int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(*(*int8)(unsafe.Pointer(zArg + uintptr(i))) != 0) {
			break
		}
		if int32(*(*int8)(unsafe.Pointer(zArg + uintptr(i))))&int32(0x80) == 0 {
			*(*uint8)(unsafe.Pointer(p + uintptr(int32(*(*int8)(unsafe.Pointer(zArg + uintptr(i))))))) = uint8(uint8(bTokenChars))
		}
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Delete a "ascii" tokenizer.
//	*/
func _fts5AsciiDelete(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Create an "ascii" tokenizer.
//	*/
func _fts5AsciiCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
	var i, rc int32
	var p, zArg uintptr
	_, _, _, _ = i, p, rc, zArg
	rc = SQLITE_OK
	p = uintptr(0)
	_ = pUnused
	if nArg%int32(2) != 0 {
		rc = int32(SQLITE_ERROR)
	} else {
		p = Xsqlite3_malloc(tls, int32(128))
		if p == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, p, 0, uint32(128))
			libc.Xmemcpy(tls, p, uintptr(unsafe.Pointer(&_aAsciiTokenChar)), uint32(128))
			i = 0
			for {
				if !(rc == SQLITE_OK && i < nArg) {
					break
				}
				zArg = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+int32(1))*4))
				if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40217) {
					_fts5AsciiAddExceptions(tls, p, zArg, int32(1))
				} else {
					if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40228) {
						_fts5AsciiAddExceptions(tls, p, zArg, 0)
					} else {
						rc = int32(SQLITE_ERROR)
					}
				}
				goto _1
			_1:
				;
				i += int32(2)
			}
			if rc != SQLITE_OK {
				_fts5AsciiDelete(tls, p)
				p = uintptr(0)
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = p
	return rc
}

func _asciiFold(tls *libc.TLS, aOut uintptr, aIn uintptr, nByte int32) {
	var c int8
	var i int32
	_, _ = c, i
	i = 0
	for {
		if !(i < nByte) {
			break
		}
		c = *(*int8)(unsafe.Pointer(aIn + uintptr(i)))
		if int32(int32(c)) >= int32('A') && int32(int32(c)) <= int32('Z') {
			c = int8(int32(c) + libc.Int32FromInt32(32))
		}
		*(*int8)(unsafe.Pointer(aOut + uintptr(i))) = c
		goto _1
	_1:
		;
		i++
	}
}

// C documentation
//
//	/*
//	** Tokenize some text using the ascii tokenizer.
//	*/
func _fts5AsciiTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, iUnused int32, pText uintptr, nText int32, xToken uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var a, p, pFold uintptr
	var ie, is, nByte, nFold, rc int32
	var _ /* aFold at bp+0 */ [64]int8
	_, _, _, _, _, _, _, _ = a, ie, is, nByte, nFold, p, pFold, rc
	p = pTokenizer
	rc = SQLITE_OK
	is = 0
	nFold = int32(64)
	pFold = bp
	a = p
	_ = iUnused
	for is < nText && rc == SQLITE_OK {
		/* Skip any leading divider characters. */
		for is < nText && (int32(*(*int8)(unsafe.Pointer(pText + uintptr(is))))&int32(0x80) == 0 && int32(*(*uint8)(unsafe.Pointer(a + uintptr(int32(*(*int8)(unsafe.Pointer(pText + uintptr(is)))))))) == 0) {
			is++
		}
		if is == nText {
			break
		}
		/* Count the token characters */
		ie = is + int32(1)
		for ie < nText && (int32(*(*int8)(unsafe.Pointer(pText + uintptr(ie))))&int32(0x80) != 0 || *(*uint8)(unsafe.Pointer(a + uintptr(int32(*(*int8)(unsafe.Pointer(pText + uintptr(ie))))))) != 0) {
			ie++
		}
		/* Fold to lower case */
		nByte = ie - is
		if nByte > nFold {
			if pFold != bp {
				Xsqlite3_free(tls, pFold)
			}
			pFold = Xsqlite3_malloc64(tls, uint64(int64(int64(nByte))*int64(2)))
			if pFold == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
				break
			}
			nFold = nByte * int32(2)
		}
		_asciiFold(tls, pFold, pText+uintptr(is), nByte)
		/* Invoke the token callback */
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xToken})))(tls, pCtx, 0, pFold, nByte, is, ie)
		is = ie + int32(1)
	}
	if pFold != bp {
		Xsqlite3_free(tls, pFold)
	}
	if rc == int32(SQLITE_DONE) {
		rc = SQLITE_OK
	}
	return rc
}

/**************************************************************************
** Start of unicode61 tokenizer implementation.
 */

/*
** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
** from the sqlite3 source file utf.c. If this file is compiled as part
** of the amalgamation, they are not required.
 */

type TUnicode61Tokenizer = struct {
	FaTokenChar       [128]uint8
	FaFold            uintptr
	FnFold            int32
	FeRemoveDiacritic int32
	FnException       int32
	FaiException      uintptr
	FaCategory        [32]uint8
}

type Unicode61Tokenizer = TUnicode61Tokenizer

type TUnicode61Tokenizer1 = struct {
	FaTokenChar       [128]uint8
	FaFold            uintptr
	FnFold            int32
	FeRemoveDiacritic int32
	FnException       int32
	FaiException      uintptr
	FaCategory        [32]uint8
}

type Unicode61Tokenizer1 = TUnicode61Tokenizer1

/* Values for eRemoveDiacritic (must match internals of fts5_unicode2.c) */

func _fts5UnicodeAddExceptions(tls *libc.TLS, p uintptr, z uintptr, bTokenChars int32) (r int32) {
	var aNew, zCsr, zTerm, v1, v2 uintptr
	var bToken, i, n, nNew, rc int32
	var iCode Tu32
	_, _, _, _, _, _, _, _, _, _, _ = aNew, bToken, i, iCode, n, nNew, rc, zCsr, zTerm, v1, v2
	rc = SQLITE_OK
	n = int32(libc.Xstrlen(tls, z))
	if n > 0 {
		aNew = Xsqlite3_realloc64(tls, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaiException, uint64(uint32(n+(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException)*uint32(4)))
		if aNew != 0 {
			nNew = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException
			zCsr = z
			zTerm = z + uintptr(n)
			for zCsr < zTerm {
				v1 = zCsr
				zCsr++
				iCode = uint32(*(*uint8)(unsafe.Pointer(v1)))
				if iCode >= uint32(0xc0) {
					iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
					for zCsr != zTerm && int32(*(*uint8)(unsafe.Pointer(zCsr)))&int32(0xc0) == int32(0x80) {
						v2 = zCsr
						zCsr++
						iCode = iCode<<libc.Int32FromInt32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v2))))
					}
					if iCode < uint32(0x80) || iCode&uint32(0xFFFFF800) == uint32(0xD800) || iCode&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
						iCode = uint32(0xFFFD)
					}
				}
				if iCode < uint32(128) {
					*(*uint8)(unsafe.Pointer(p + uintptr(iCode))) = uint8(uint8(bTokenChars))
				} else {
					bToken = int32(*(*uint8)(unsafe.Pointer(p + 148 + uintptr(_sqlite3Fts5UnicodeCategory(tls, iCode)))))
					if bToken != bTokenChars && _sqlite3Fts5UnicodeIsdiacritic(tls, int32(int32(iCode))) == 0 {
						i = 0
						for {
							if !(i < nNew) {
								break
							}
							if uint32(*(*int32)(unsafe.Pointer(aNew + uintptr(i)*4))) > iCode {
								break
							}
							goto _3
						_3:
							;
							i++
						}
						libc.Xmemmove(tls, aNew+uintptr(i+int32(1))*4, aNew+uintptr(i)*4, uint32(nNew-i)*uint32(4))
						*(*int32)(unsafe.Pointer(aNew + uintptr(i)*4)) = int32(int32(iCode))
						nNew++
					}
				}
			}
			(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaiException = aNew
			(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException = nNew
		} else {
			rc = int32(SQLITE_NOMEM)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if the p->aiException[] array contains the value iCode.
//	*/
func _fts5UnicodeIsException(tls *libc.TLS, p uintptr, iCode int32) (r int32) {
	var a uintptr
	var iHi, iLo, iTest int32
	_, _, _, _ = a, iHi, iLo, iTest
	if (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException > 0 {
		a = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaiException
		iLo = 0
		iHi = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException - int32(1)
		for iHi >= iLo {
			iTest = (iHi + iLo) / int32(2)
			if iCode == *(*int32)(unsafe.Pointer(a + uintptr(iTest)*4)) {
				return int32(1)
			} else {
				if iCode > *(*int32)(unsafe.Pointer(a + uintptr(iTest)*4)) {
					iLo = iTest + int32(1)
				} else {
					iHi = iTest - int32(1)
				}
			}
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Delete a "unicode61" tokenizer.
//	*/
func _fts5UnicodeDelete(tls *libc.TLS, pTok uintptr) {
	var p uintptr
	_ = p
	if pTok != 0 {
		p = pTok
		Xsqlite3_free(tls, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaiException)
		Xsqlite3_free(tls, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold)
		Xsqlite3_free(tls, p)
	}
	return
}

func _unicodeSetCategories(tls *libc.TLS, p uintptr, zCat uintptr) (r int32) {
	var z uintptr
	_ = z
	z = zCat
	for *(*int8)(unsafe.Pointer(z)) != 0 {
		for int32(*(*int8)(unsafe.Pointer(z))) == int32(' ') || int32(*(*int8)(unsafe.Pointer(z))) == int32('\t') {
			z++
		}
		if *(*int8)(unsafe.Pointer(z)) != 0 && _sqlite3Fts5UnicodeCatParse(tls, z, p+148) != 0 {
			return int32(SQLITE_ERROR)
		}
		for int32(*(*int8)(unsafe.Pointer(z))) != int32(' ') && int32(*(*int8)(unsafe.Pointer(z))) != int32('\t') && int32(*(*int8)(unsafe.Pointer(z))) != int32('\000') {
			z++
		}
	}
	_sqlite3Fts5UnicodeAscii(tls, p+148, p)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Create a "unicode61" tokenizer.
//	*/
func _fts5UnicodeCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
	var i, rc int32
	var p, zArg, zCat uintptr
	_, _, _, _, _ = i, p, rc, zArg, zCat
	rc = SQLITE_OK /* Return code */
	p = uintptr(0) /* New tokenizer object */
	_ = pUnused
	if nArg%int32(2) != 0 {
		rc = int32(SQLITE_ERROR)
	} else {
		p = Xsqlite3_malloc(tls, int32(180))
		if p != 0 {
			zCat = __ccgo_ts + 40239
			libc.Xmemset(tls, p, 0, uint32(180))
			(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic = int32(FTS5_REMOVE_DIACRITICS_SIMPLE)
			(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold = int32(64)
			(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold = Xsqlite3_malloc64(tls, uint64(uint32((*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold)*uint32(1)))
			if (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			}
			/* Search for a "categories" argument */
			i = 0
			for {
				if !(rc == SQLITE_OK && i < nArg) {
					break
				}
				if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40248) {
					zCat = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+int32(1))*4))
				}
				goto _1
			_1:
				;
				i += int32(2)
			}
			if rc == SQLITE_OK {
				rc = _unicodeSetCategories(tls, p, zCat)
			}
			i = 0
			for {
				if !(rc == SQLITE_OK && i < nArg) {
					break
				}
				zArg = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+int32(1))*4))
				if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40259) {
					if int32(*(*int8)(unsafe.Pointer(zArg))) != int32('0') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('1') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('2') || *(*int8)(unsafe.Pointer(zArg + 1)) != 0 {
						rc = int32(SQLITE_ERROR)
					} else {
						(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic = int32(*(*int8)(unsafe.Pointer(zArg))) - int32('0')
					}
				} else {
					if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40217) {
						rc = _fts5UnicodeAddExceptions(tls, p, zArg, int32(1))
					} else {
						if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40228) {
							rc = _fts5UnicodeAddExceptions(tls, p, zArg, 0)
						} else {
							if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40248) {
								/* no-op */
							} else {
								rc = int32(SQLITE_ERROR)
							}
						}
					}
				}
				goto _2
			_2:
				;
				i += int32(2)
			}
		} else {
			rc = int32(SQLITE_NOMEM)
		}
		if rc != SQLITE_OK {
			_fts5UnicodeDelete(tls, p)
			p = uintptr(0)
		}
		*(*uintptr)(unsafe.Pointer(ppOut)) = p
	}
	return rc
}

// C documentation
//
//	/*
//	** Return true if, for the purposes of tokenizing with the tokenizer
//	** passed as the first argument, codepoint iCode is considered a token
//	** character (not a separator).
//	*/
func _fts5UnicodeIsAlnum(tls *libc.TLS, p uintptr, iCode int32) (r int32) {
	return int32(*(*uint8)(unsafe.Pointer(p + 148 + uintptr(_sqlite3Fts5UnicodeCategory(tls, uint32(uint32(iCode))))))) ^ _fts5UnicodeIsException(tls, p, iCode)
}

func _fts5UnicodeTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, iUnused int32, pText uintptr, nText int32, xToken uintptr) (r int32) {
	var a, aFold, p, pEnd, zCsr, zOut, zTerm, v10, v11, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v26, v27, v3, v4 uintptr
	var iCode Tu32
	var ie, is, nFold, rc, v7 int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, aFold, iCode, ie, is, nFold, p, pEnd, rc, zCsr, zOut, zTerm, v10, v11, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v26, v27, v3, v4, v7
	p = pTokenizer
	rc = SQLITE_OK
	a = p
	zTerm = pText + uintptr(nText)
	zCsr = pText
	/* Output buffer */
	aFold = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold
	nFold = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold
	pEnd = aFold + uintptr(nFold-int32(6))
	_ = iUnused
	/* Each iteration of this loop gobbles up a contiguous run of separators,
	 ** then the next token.  */
_2:
	;
	if !(rc == SQLITE_OK) {
		goto _1
	} /* non-ASCII codepoint read from input */
	zOut = aFold
	/* Skip any separator characters. */
	for int32(1) != 0 {
		if zCsr >= zTerm {
			goto tokenize_done
		}
		if int32(*(*uint8)(unsafe.Pointer(zCsr)))&int32(0x80) != 0 {
			/* A character outside of the ascii range. Skip past it if it is
			 ** a separator character. Or break out of the loop if it is not. */
			is = int32(int32(zCsr)) - int32(pText)
			v3 = zCsr
			zCsr++
			iCode = uint32(*(*uint8)(unsafe.Pointer(v3)))
			if iCode >= uint32(0xc0) {
				iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
				for zCsr != zTerm && int32(*(*uint8)(unsafe.Pointer(zCsr)))&int32(0xc0) == int32(0x80) {
					v4 = zCsr
					zCsr++
					iCode = iCode<<libc.Int32FromInt32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v4))))
				}
				if iCode < uint32(0x80) || iCode&uint32(0xFFFFF800) == uint32(0xD800) || iCode&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
					iCode = uint32(0xFFFD)
				}
			}
			if _fts5UnicodeIsAlnum(tls, p, int32(int32(iCode))) != 0 {
				goto non_ascii_tokenchar
			}
		} else {
			if *(*uint8)(unsafe.Pointer(a + uintptr(*(*uint8)(unsafe.Pointer(zCsr))))) != 0 {
				is = int32(int32(zCsr)) - int32(pText)
				goto ascii_tokenchar
			}
			zCsr++
		}
	}
	/* Run through the tokenchars. Fold them into the output buffer along
	 ** the way.  */
_6:
	;
	if !(zCsr < zTerm) {
		goto _5
	}
	/* Grow the output buffer so that there is sufficient space to fit the
	 ** largest possible utf-8 character.  */
	if zOut > pEnd {
		aFold = Xsqlite3_malloc64(tls, uint64(int64(int64(nFold))*int64(2)))
		if aFold == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
			goto tokenize_done
		}
		zOut = aFold + uintptr(int32(int32(zOut))-int32((*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold))
		libc.Xmemcpy(tls, aFold, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold, uint32(uint32(nFold)))
		Xsqlite3_free(tls, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold)
		(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold = aFold
		v7 = nFold * libc.Int32FromInt32(2)
		nFold = v7
		(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold = v7
		pEnd = aFold + uintptr(nFold-int32(6))
	}
	if !(int32(*(*uint8)(unsafe.Pointer(zCsr)))&int32(0x80) != 0) {
		goto _8
	}
	/* An non-ascii-range character. Fold it into the output buffer if
	 ** it is a token character, or break out of the loop if it is not. */
	v10 = zCsr
	zCsr++
	iCode = uint32(*(*uint8)(unsafe.Pointer(v10)))
	if iCode >= uint32(0xc0) {
		iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
		for zCsr != zTerm && int32(*(*uint8)(unsafe.Pointer(zCsr)))&int32(0xc0) == int32(0x80) {
			v11 = zCsr
			zCsr++
			iCode = iCode<<libc.Int32FromInt32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v11))))
		}
		if iCode < uint32(0x80) || iCode&uint32(0xFFFFF800) == uint32(0xD800) || iCode&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
			iCode = uint32(0xFFFD)
		}
	}
	if !(_fts5UnicodeIsAlnum(tls, p, int32(int32(iCode))) != 0 || _sqlite3Fts5UnicodeIsdiacritic(tls, int32(int32(iCode))) != 0) {
		goto _12
	}
	goto non_ascii_tokenchar
non_ascii_tokenchar:
	;
	iCode = uint32(_sqlite3Fts5UnicodeFold(tls, int32(int32(iCode)), (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic))
	if iCode != 0 {
		if iCode < uint32(0x00080) {
			v14 = zOut
			zOut++
			*(*int8)(unsafe.Pointer(v14)) = int8(uint8(iCode & libc.Uint32FromInt32(0xFF)))
		} else {
			if iCode < uint32(0x00800) {
				v15 = zOut
				zOut++
				*(*int8)(unsafe.Pointer(v15)) = int8(int32(0xC0) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
				v16 = zOut
				zOut++
				*(*int8)(unsafe.Pointer(v16)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
			} else {
				if iCode < uint32(0x10000) {
					v17 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v17)) = int8(int32(0xE0) + int32(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
					v18 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v18)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v19 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v19)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
				} else {
					v20 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v20)) = int8(int32(0xF0) + int32(uint8(iCode>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
					v21 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v21)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
					v22 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v22)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v23 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v23)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
				}
			}
		}
	}
	goto _13
_12:
	;
	goto _5
_13:
	;
	goto _9
_8:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(a + uintptr(*(*uint8)(unsafe.Pointer(zCsr)))))) == 0) {
		goto _24
	}
	/* An ascii-range separator character. End of token. */
	goto _5
	goto _25
_24:
	;
	goto ascii_tokenchar
ascii_tokenchar:
	;
	if int32(*(*uint8)(unsafe.Pointer(zCsr))) >= int32('A') && int32(*(*uint8)(unsafe.Pointer(zCsr))) <= int32('Z') {
		v26 = zOut
		zOut++
		*(*int8)(unsafe.Pointer(v26)) = int8(int32(*(*uint8)(unsafe.Pointer(zCsr))) + int32(32))
	} else {
		v27 = zOut
		zOut++
		*(*int8)(unsafe.Pointer(v27)) = int8(*(*uint8)(unsafe.Pointer(zCsr)))
	}
	zCsr++
_25:
	;
_9:
	;
	ie = int32(int32(zCsr)) - int32(pText)
	goto _6
_5:
	;
	/* Invoke the token callback */
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xToken})))(tls, pCtx, 0, aFold, int32(int32(zOut))-int32(int32(aFold)), is, ie)
	goto _2
_1:
	;
	goto tokenize_done
tokenize_done:
	;
	if rc == int32(SQLITE_DONE) {
		rc = SQLITE_OK
	}
	return rc
}

/**************************************************************************
** Start of porter stemmer implementation.
 */

/* Any tokens larger than this (in bytes) are passed through without
** stemming. */

type TPorterTokenizer = struct {
	Ftokenizer  Tfts5_tokenizer
	FpTokenizer uintptr
	FaBuf       [128]int8
}

type PorterTokenizer = TPorterTokenizer

type TPorterTokenizer1 = struct {
	Ftokenizer  Tfts5_tokenizer
	FpTokenizer uintptr
	FaBuf       [128]int8
}

type PorterTokenizer1 = TPorterTokenizer1

// C documentation
//
//	/*
//	** Delete a "porter" tokenizer.
//	*/
func _fts5PorterDelete(tls *libc.TLS, pTok uintptr) {
	var p uintptr
	_ = p
	if pTok != 0 {
		p = pTok
		if (*TPorterTokenizer)(unsafe.Pointer(p)).FpTokenizer != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TPorterTokenizer)(unsafe.Pointer(p)).Ftokenizer.FxDelete})))(tls, (*TPorterTokenizer)(unsafe.Pointer(p)).FpTokenizer)
		}
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Create a "porter" tokenizer.
//	*/
func _fts5PorterCreate(tls *libc.TLS, pCtx uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azArg2, pApi, pRet, zBase, v2 uintptr
	var nArg2, rc, v1 int32
	var _ /* pUserdata at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = azArg2, nArg2, pApi, pRet, rc, zBase, v1, v2
	pApi = pCtx
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	zBase = __ccgo_ts + 40277
	if nArg > 0 {
		zBase = *(*uintptr)(unsafe.Pointer(azArg))
	}
	pRet = Xsqlite3_malloc(tls, int32(144))
	if pRet != 0 {
		libc.Xmemset(tls, pRet, 0, uint32(144))
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxFindTokenizer})))(tls, pApi, zBase, bp, pRet)
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	if rc == SQLITE_OK {
		if nArg > 0 {
			v1 = nArg - int32(1)
		} else {
			v1 = 0
		}
		nArg2 = v1
		if nArg2 != 0 {
			v2 = azArg + 1*4
		} else {
			v2 = uintptr(0)
		}
		azArg2 = v2
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterTokenizer)(unsafe.Pointer(pRet)).Ftokenizer.FxCreate})))(tls, *(*uintptr)(unsafe.Pointer(bp)), azArg2, nArg2, pRet+12)
	}
	if rc != SQLITE_OK {
		_fts5PorterDelete(tls, pRet)
		pRet = uintptr(0)
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = pRet
	return rc
}

type TPorterContext = struct {
	FpCtx   uintptr
	FxToken uintptr
	FaBuf   uintptr
}

type PorterContext = TPorterContext

type TPorterContext1 = struct {
	FpCtx   uintptr
	FxToken uintptr
	FaBuf   uintptr
}

type PorterContext1 = TPorterContext1

type TPorterRule = struct {
	FzSuffix uintptr
	FnSuffix int32
	FxCond   uintptr
	FzOutput uintptr
	FnOutput int32
}

type PorterRule = TPorterRule

type TPorterRule1 = struct {
	FzSuffix uintptr
	FnSuffix int32
	FxCond   uintptr
	FzOutput uintptr
	FnOutput int32
}

type PorterRule1 = TPorterRule1

func _fts5PorterIsVowel(tls *libc.TLS, c int8, bYIsVowel int32) (r int32) {
	return libc.BoolInt32(int32(int32(c)) == int32('a') || int32(int32(c)) == int32('e') || int32(int32(c)) == int32('i') || int32(int32(c)) == int32('o') || int32(int32(c)) == int32('u') || bYIsVowel != 0 && int32(int32(c)) == int32('y'))
}

func _fts5PorterGobbleVC(tls *libc.TLS, zStem uintptr, nStem int32, bPrevCons int32) (r int32) {
	var bCons, i, v2, v4 int32
	_, _, _, _ = bCons, i, v2, v4
	bCons = bPrevCons
	/* Scan for a vowel */
	i = 0
	for {
		if !(i < nStem) {
			break
		}
		v2 = libc.BoolInt32(!(_fts5PorterIsVowel(tls, *(*int8)(unsafe.Pointer(zStem + uintptr(i))), bCons) != 0))
		bCons = v2
		if 0 == v2 {
			break
		}
		goto _1
	_1:
		;
		i++
	}
	/* Scan for a consonent */
	i++
	for {
		if !(i < nStem) {
			break
		}
		v4 = libc.BoolInt32(!(_fts5PorterIsVowel(tls, *(*int8)(unsafe.Pointer(zStem + uintptr(i))), bCons) != 0))
		bCons = v4
		if v4 != 0 {
			return i + int32(1)
		}
		goto _3
	_3:
		;
		i++
	}
	return 0
}

// C documentation
//
//	/* porter rule condition: (m > 0) */
func _fts5Porter_MGt0(tls *libc.TLS, zStem uintptr, nStem int32) (r int32) {
	return libc.BoolInt32(!!(_fts5PorterGobbleVC(tls, zStem, nStem, 0) != 0))
}

// C documentation
//
//	/* porter rule condition: (m > 1) */
func _fts5Porter_MGt1(tls *libc.TLS, zStem uintptr, nStem int32) (r int32) {
	var n int32
	_ = n
	n = _fts5PorterGobbleVC(tls, zStem, nStem, 0)
	if n != 0 && _fts5PorterGobbleVC(tls, zStem+uintptr(n), nStem-n, int32(1)) != 0 {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/* porter rule condition: (m = 1) */
func _fts5Porter_MEq1(tls *libc.TLS, zStem uintptr, nStem int32) (r int32) {
	var n int32
	_ = n
	n = _fts5PorterGobbleVC(tls, zStem, nStem, 0)
	if n != 0 && 0 == _fts5PorterGobbleVC(tls, zStem+uintptr(n), nStem-n, int32(1)) {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/* porter rule condition: (*o) */
func _fts5Porter_Ostar(tls *libc.TLS, zStem uintptr, nStem int32) (r int32) {
	var bCons, i, mask int32
	_, _, _ = bCons, i, mask
	if int32(*(*int8)(unsafe.Pointer(zStem + uintptr(nStem-int32(1))))) == int32('w') || int32(*(*int8)(unsafe.Pointer(zStem + uintptr(nStem-int32(1))))) == int32('x') || int32(*(*int8)(unsafe.Pointer(zStem + uintptr(nStem-int32(1))))) == int32('y') {
		return 0
	} else {
		mask = 0
		bCons = 0
		i = 0
		for {
			if !(i < nStem) {
				break
			}
			bCons = libc.BoolInt32(!(_fts5PorterIsVowel(tls, *(*int8)(unsafe.Pointer(zStem + uintptr(i))), bCons) != 0))
			mask = mask<<int32(1) + bCons
			goto _1
		_1:
			;
			i++
		}
		return libc.BoolInt32(mask&int32(0x0007) == int32(0x0005))
	}
	return r
}

// C documentation
//
//	/* porter rule condition: (m > 1 and (*S or *T)) */
func _fts5Porter_MGt1_and_S_or_T(tls *libc.TLS, zStem uintptr, nStem int32) (r int32) {
	return libc.BoolInt32((int32(*(*int8)(unsafe.Pointer(zStem + uintptr(nStem-int32(1))))) == int32('s') || int32(*(*int8)(unsafe.Pointer(zStem + uintptr(nStem-int32(1))))) == int32('t')) && _fts5Porter_MGt1(tls, zStem, nStem) != 0)
}

// C documentation
//
//	/* porter rule condition: (*v*) */
func _fts5Porter_Vowel(tls *libc.TLS, zStem uintptr, nStem int32) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < nStem) {
			break
		}
		if _fts5PorterIsVowel(tls, *(*int8)(unsafe.Pointer(zStem + uintptr(i))), libc.BoolInt32(i > 0)) != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i++
	}
	return 0
}

/**************************************************************************
***************************************************************************
** GENERATED CODE STARTS HERE (mkportersteps.tcl)
 */

func _fts5PorterStep4(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
	var nBuf, ret int32
	_, _ = nBuf, ret
	ret = 0
	nBuf = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(2))))) {
	case int32('a'):
		if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40287, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2)
			}
		}
	case int32('c'):
		if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40290, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4)
			}
		} else {
			if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40295, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
				if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4)
				}
			}
		}
	case int32('e'):
		if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40300, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2)
			}
		}
	case int32('i'):
		if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40303, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2)
			}
		}
	case int32('l'):
		if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40306, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4)
			}
		} else {
			if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40311, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
				if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4)
				}
			}
		}
	case int32('n'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40316, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		} else {
			if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40320, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
				if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(5)) != 0 {
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5)
				}
			} else {
				if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40326, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
					if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
						*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4)
					}
				} else {
					if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40331, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
						if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
							*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
						}
					}
				}
			}
		}
	case int32('o'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40335, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt1_and_S_or_T(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		} else {
			if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40339, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
				if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2)
				}
			}
		}
	case int32('s'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40342, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		}
	case int32('t'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40346, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		} else {
			if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40350, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
				if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
				}
			}
		}
	case int32('u'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40354, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		}
	case int32('v'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40358, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		}
	case int32('z'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40362, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		}
		break
	}
	return ret
}

func _fts5PorterStep1B2(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
	var nBuf, ret int32
	_, _ = nBuf, ret
	ret = 0
	nBuf = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(2))))) {
	case int32('a'):
		if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40366, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
			libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+40346, uint32(3))
			*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2) + int32(3)
			ret = int32(1)
		}
	case int32('b'):
		if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40369, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
			libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+40372, uint32(3))
			*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2) + int32(3)
			ret = int32(1)
		}
	case int32('i'):
		if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40376, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
			libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+40362, uint32(3))
			*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2) + int32(3)
			ret = int32(1)
		}
		break
	}
	return ret
}

func _fts5PorterStep2(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
	var nBuf, ret int32
	_, _ = nBuf, ret
	ret = 0
	nBuf = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(2))))) {
	case int32('a'):
		if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40379, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+40346, uint32(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(7) + int32(3)
			}
		} else {
			if nBuf > int32(6) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40387, aBuf+uintptr(nBuf-int32(6)), uint32(6)) {
				if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(6)) != 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(6)), __ccgo_ts+40394, uint32(4))
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(6) + int32(4)
				}
			}
		}
	case int32('c'):
		if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40399, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+40295, uint32(4))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4) + int32(4)
			}
		} else {
			if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40404, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
				if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+40290, uint32(4))
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4) + int32(4)
				}
			}
		}
	case int32('e'):
		if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40409, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+40362, uint32(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4) + int32(3)
			}
		}
	case int32('g'):
		if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40414, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+17300, uint32(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4) + int32(3)
			}
		}
	case int32('l'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40419, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+40372, uint32(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3) + int32(3)
			}
		} else {
			if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40423, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
				if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+40287, uint32(2))
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4) + int32(2)
				}
			} else {
				if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40428, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
					if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
						libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40331, uint32(3))
						*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(3)
					}
				} else {
					if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40434, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
						if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
							libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+40438, uint32(1))
							*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3) + int32(1)
						}
					} else {
						if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40440, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
							if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
								libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40354, uint32(3))
								*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(3)
							}
						}
					}
				}
			}
		}
	case int32('o'):
		if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40446, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+40362, uint32(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(7) + int32(3)
			}
		} else {
			if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40454, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
				if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40346, uint32(3))
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(3)
				}
			} else {
				if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40460, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
					if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
						libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+40346, uint32(3))
						*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4) + int32(3)
					}
				}
			}
		}
	case int32('s'):
		if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40465, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40287, uint32(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(2)
			}
		} else {
			if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40471, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
				if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+40358, uint32(3))
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(7) + int32(3)
				}
			} else {
				if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40479, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
					if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
						libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+40487, uint32(3))
						*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(7) + int32(3)
					}
				} else {
					if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40491, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
						if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
							libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+40354, uint32(3))
							*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(7) + int32(3)
						}
					}
				}
			}
		}
	case int32('t'):
		if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40499, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40287, uint32(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(2)
			}
		} else {
			if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40505, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
				if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40358, uint32(3))
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(3)
				}
			} else {
				if nBuf > int32(6) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40511, aBuf+uintptr(nBuf-int32(6)), uint32(6)) {
					if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(6)) != 0 {
						libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(6)), __ccgo_ts+40372, uint32(3))
						*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(6) + int32(3)
					}
				}
			}
		}
		break
	}
	return ret
}

func _fts5PorterStep3(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
	var nBuf, ret int32
	_, _ = nBuf, ret
	ret = 0
	nBuf = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(2))))) {
	case int32('a'):
		if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40518, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+40303, uint32(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4) + int32(2)
			}
		}
	case int32('s'):
		if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40523, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(4)
			}
		}
	case int32('t'):
		if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40528, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40303, uint32(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(2)
			}
		} else {
			if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40534, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
				if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
					libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40303, uint32(2))
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(2)
				}
			}
		}
	case int32('u'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40487, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
			}
		}
	case int32('v'):
		if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40540, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5)
			}
		}
	case int32('z'):
		if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40546, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+40287, uint32(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(5) + int32(2)
			}
		}
		break
	}
	return ret
}

func _fts5PorterStep1B(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
	var nBuf, ret int32
	_, _ = nBuf, ret
	ret = 0
	nBuf = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(2))))) {
	case int32('e'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40552, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+40556, uint32(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3) + int32(2)
			}
		} else {
			if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40559, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
				if _fts5Porter_Vowel(tls, aBuf, nBuf-int32(2)) != 0 {
					*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2)
					ret = int32(1)
				}
			}
		}
	case int32('n'):
		if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+40562, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
			if _fts5Porter_Vowel(tls, aBuf, nBuf-int32(3)) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(3)
				ret = int32(1)
			}
		}
		break
	}
	return ret
}

/*
** GENERATED CODE ENDS HERE (mkportersteps.tcl)
***************************************************************************
**************************************************************************/

func _fts5PorterStep1A(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) {
	var nBuf int32
	_ = nBuf
	nBuf = *(*int32)(unsafe.Pointer(pnBuf))
	if int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(1))))) == int32('s') {
		if int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(2))))) == int32('e') {
			if nBuf > int32(4) && int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(4))))) == int32('s') && int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(3))))) == int32('s') || nBuf > int32(3) && int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(3))))) == int32('i') {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(2)
			} else {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(1)
			}
		} else {
			if int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(nBuf-int32(2))))) != int32('s') {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - int32(1)
			}
		}
	}
}

func _fts5PorterCb(tls *libc.TLS, pCtx uintptr, tflags int32, pToken uintptr, nToken int32, iStart int32, iEnd int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aBuf, p uintptr
	var c int8
	var v1 int32
	var _ /* nBuf at bp+0 */ int32
	_, _, _, _ = aBuf, c, p, v1
	p = pCtx
	if nToken > int32(FTS5_PORTER_MAX_TOKEN) || nToken < int32(3) {
		goto pass_through
	}
	aBuf = (*TPorterContext)(unsafe.Pointer(p)).FaBuf
	*(*int32)(unsafe.Pointer(bp)) = nToken
	libc.Xmemcpy(tls, aBuf, pToken, uint32(*(*int32)(unsafe.Pointer(bp))))
	/* Step 1. */
	_fts5PorterStep1A(tls, aBuf, bp)
	if _fts5PorterStep1B(tls, aBuf, bp) != 0 {
		if _fts5PorterStep1B2(tls, aBuf, bp) == 0 {
			c = *(*int8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(1))))
			if _fts5PorterIsVowel(tls, c, 0) == 0 && int32(int32(c)) != int32('l') && int32(int32(c)) != int32('s') && int32(int32(c)) != int32('z') && int32(int32(c)) == int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(2))))) {
				*(*int32)(unsafe.Pointer(bp))--
			} else {
				if _fts5Porter_MEq1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))) != 0 && _fts5Porter_Ostar(tls, aBuf, *(*int32)(unsafe.Pointer(bp))) != 0 {
					v1 = *(*int32)(unsafe.Pointer(bp))
					*(*int32)(unsafe.Pointer(bp))++
					*(*int8)(unsafe.Pointer(aBuf + uintptr(v1))) = int8('e')
				}
			}
		}
	}
	/* Step 1C. */
	if int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(1))))) == int32('y') && _fts5Porter_Vowel(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-int32(1)) != 0 {
		*(*int8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(1)))) = int8('i')
	}
	/* Steps 2 through 4. */
	_fts5PorterStep2(tls, aBuf, bp)
	_fts5PorterStep3(tls, aBuf, bp)
	_fts5PorterStep4(tls, aBuf, bp)
	/* Step 5a. */
	if int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(1))))) == int32('e') {
		if _fts5Porter_MGt1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-int32(1)) != 0 || _fts5Porter_MEq1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-int32(1)) != 0 && !(_fts5Porter_Ostar(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-int32(1)) != 0) {
			*(*int32)(unsafe.Pointer(bp))--
		}
	}
	/* Step 5b. */
	if *(*int32)(unsafe.Pointer(bp)) > int32(1) && int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(1))))) == int32('l') && int32(*(*int8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-int32(2))))) == int32('l') && _fts5Porter_MGt1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-int32(1)) != 0 {
		*(*int32)(unsafe.Pointer(bp))--
	}
	return (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterContext)(unsafe.Pointer(p)).FxToken})))(tls, (*TPorterContext)(unsafe.Pointer(p)).FpCtx, tflags, aBuf, *(*int32)(unsafe.Pointer(bp)), iStart, iEnd)
	goto pass_through
pass_through:
	;
	return (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterContext)(unsafe.Pointer(p)).FxToken})))(tls, (*TPorterContext)(unsafe.Pointer(p)).FpCtx, tflags, pToken, nToken, iStart, iEnd)
	return r
}

// C documentation
//
//	/*
//	** Tokenize using the porter tokenizer.
//	*/
func _fts5PorterTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, flags int32, pText uintptr, nText int32, xToken uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	var _ /* sCtx at bp+0 */ TPorterContext
	_ = p
	p = pTokenizer
	(*(*TPorterContext)(unsafe.Pointer(bp))).FxToken = xToken
	(*(*TPorterContext)(unsafe.Pointer(bp))).FpCtx = pCtx
	(*(*TPorterContext)(unsafe.Pointer(bp))).FaBuf = p + 16
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterTokenizer)(unsafe.Pointer(p)).Ftokenizer.FxTokenize})))(tls, (*TPorterTokenizer)(unsafe.Pointer(p)).FpTokenizer, bp, flags, pText, nText, __ccgo_fp(_fts5PorterCb))
}

// C documentation
//
//	/**************************************************************************
//	** Start of trigram implementation.
//	*/
type TTrigramTokenizer = struct {
	FbFold      int32
	FiFoldParam int32
}

type TrigramTokenizer = TTrigramTokenizer

type TTrigramTokenizer1 = struct {
	FbFold      int32
	FiFoldParam int32
}

type TrigramTokenizer1 = TTrigramTokenizer1

// C documentation
//
//	/*
//	** Free a trigram tokenizer.
//	*/
func _fts5TriDelete(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Allocate a trigram tokenizer.
//	*/
func _fts5TriCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
	var i, rc, v2 int32
	var pNew, zArg uintptr
	_, _, _, _, _ = i, pNew, rc, zArg, v2
	rc = SQLITE_OK
	pNew = Xsqlite3_malloc(tls, int32(8))
	_ = pUnused
	if pNew == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FbFold = int32(1)
		(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FiFoldParam = 0
		i = 0
		for {
			if !(rc == SQLITE_OK && i < nArg) {
				break
			}
			zArg = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+int32(1))*4))
			if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40566) {
				if int32(*(*int8)(unsafe.Pointer(zArg))) != int32('0') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('1') || *(*int8)(unsafe.Pointer(zArg + 1)) != 0 {
					rc = int32(SQLITE_ERROR)
				} else {
					(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FbFold = libc.BoolInt32(int32(*(*int8)(unsafe.Pointer(zArg))) == int32('0'))
				}
			} else {
				if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*4)), __ccgo_ts+40259) {
					if int32(*(*int8)(unsafe.Pointer(zArg))) != int32('0') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('1') && int32(*(*int8)(unsafe.Pointer(zArg))) != int32('2') || *(*int8)(unsafe.Pointer(zArg + 1)) != 0 {
						rc = int32(SQLITE_ERROR)
					} else {
						if int32(*(*int8)(unsafe.Pointer(zArg))) != int32('0') {
							v2 = int32(2)
						} else {
							v2 = 0
						}
						(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FiFoldParam = v2
					}
				} else {
					rc = int32(SQLITE_ERROR)
				}
			}
			goto _1
		_1:
			;
			i += int32(2)
		}
		if (*TTrigramTokenizer)(unsafe.Pointer(pNew)).FiFoldParam != 0 && (*TTrigramTokenizer)(unsafe.Pointer(pNew)).FbFold == 0 {
			rc = int32(SQLITE_ERROR)
		}
		if rc != SQLITE_OK {
			_fts5TriDelete(tls, pNew)
			pNew = uintptr(0)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = pNew
	return rc
}

// C documentation
//
//	/*
//	** Trigram tokenizer tokenize routine.
//	*/
func _fts5TriTokenize(tls *libc.TLS, pTok uintptr, pCtx uintptr, unusedFlags int32, pText uintptr, nText int32, xToken uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aStart [3]int32
	var iCode Tu32
	var iNext, ii, rc int32
	var p, z1, zEof, zIn, zOut, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v2, v20, v21, v22, v23, v24, v25, v26, v3, v4, v5, v6, v7, v8, v9 uintptr
	var _ /* aBuf at bp+0 */ [32]int8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aStart, iCode, iNext, ii, p, rc, z1, zEof, zIn, zOut, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v2, v20, v21, v22, v23, v24, v25, v26, v3, v4, v5, v6, v7, v8, v9
	p = pTok
	rc = SQLITE_OK
	zOut = bp
	zIn = pText
	zEof = zIn + uintptr(nText) /* Input offset of each character in aBuf[] */
	_ = unusedFlags
	/* Populate aBuf[] with the characters for the first trigram. */
	ii = 0
	for {
		if !(ii < int32(3)) {
			break
		}
		for cond := true; cond; cond = iCode == uint32(0) {
			aStart[ii] = int32(int32(zIn)) - int32(pText)
			v2 = zIn
			zIn++
			iCode = uint32(*(*uint8)(unsafe.Pointer(v2)))
			if iCode >= uint32(0xc0) {
				iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
				for zIn != zEof && int32(*(*uint8)(unsafe.Pointer(zIn)))&int32(0xc0) == int32(0x80) {
					v3 = zIn
					zIn++
					iCode = iCode<<libc.Int32FromInt32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v3))))
				}
				if iCode < uint32(0x80) || iCode&uint32(0xFFFFF800) == uint32(0xD800) || iCode&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
					iCode = uint32(0xFFFD)
				}
			}
			if iCode == uint32(0) {
				return SQLITE_OK
			}
			if (*TTrigramTokenizer)(unsafe.Pointer(p)).FbFold != 0 {
				iCode = uint32(_sqlite3Fts5UnicodeFold(tls, int32(int32(iCode)), (*TTrigramTokenizer)(unsafe.Pointer(p)).FiFoldParam))
			}
		}
		if iCode < uint32(0x00080) {
			v4 = zOut
			zOut++
			*(*int8)(unsafe.Pointer(v4)) = int8(uint8(iCode & libc.Uint32FromInt32(0xFF)))
		} else {
			if iCode < uint32(0x00800) {
				v5 = zOut
				zOut++
				*(*int8)(unsafe.Pointer(v5)) = int8(int32(0xC0) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
				v6 = zOut
				zOut++
				*(*int8)(unsafe.Pointer(v6)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
			} else {
				if iCode < uint32(0x10000) {
					v7 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v7)) = int8(int32(0xE0) + int32(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
					v8 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v8)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v9 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v9)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
				} else {
					v10 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v10)) = int8(int32(0xF0) + int32(uint8(iCode>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
					v11 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v11)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
					v12 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v12)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v13 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v13)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
				}
			}
		}
		goto _1
	_1:
		;
		ii++
	}
	/* At the start of each iteration of this loop:
	 **
	 **  aBuf:      Contains 3 characters. The 3 characters of the next trigram.
	 **  zOut:      Points to the byte following the last character in aBuf.
	 **  aStart[3]: Contains the byte offset in the input text corresponding
	 **             to the start of each of the three characters in the buffer.
	 */
	for int32(1) != 0 {
		/* Read characters from the input up until the first non-diacritic */
		for cond := true; cond; cond = iCode == uint32(0) {
			iNext = int32(int32(zIn)) - int32(pText)
			v14 = zIn
			zIn++
			iCode = uint32(*(*uint8)(unsafe.Pointer(v14)))
			if iCode >= uint32(0xc0) {
				iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
				for zIn != zEof && int32(*(*uint8)(unsafe.Pointer(zIn)))&int32(0xc0) == int32(0x80) {
					v15 = zIn
					zIn++
					iCode = iCode<<libc.Int32FromInt32(6) + uint32(libc.Int32FromInt32(0x3f)&int32(*(*uint8)(unsafe.Pointer(v15))))
				}
				if iCode < uint32(0x80) || iCode&uint32(0xFFFFF800) == uint32(0xD800) || iCode&uint32(0xFFFFFFFE) == uint32(0xFFFE) {
					iCode = uint32(0xFFFD)
				}
			}
			if iCode == uint32(0) {
				break
			}
			if (*TTrigramTokenizer)(unsafe.Pointer(p)).FbFold != 0 {
				iCode = uint32(_sqlite3Fts5UnicodeFold(tls, int32(int32(iCode)), (*TTrigramTokenizer)(unsafe.Pointer(p)).FiFoldParam))
			}
		}
		/* Pass the current trigram back to fts5 */
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{xToken})))(tls, pCtx, 0, bp, int32(int32(zOut))-t__predefined_ptrdiff_t(bp), aStart[0], iNext)
		if iCode == uint32(0) || rc != SQLITE_OK {
			break
		}
		/* Remove the first character from buffer aBuf[]. Append the character
		 ** with codepoint iCode.  */
		z1 = bp
		v16 = z1
		z1++
		if int32(uint8(*(*int8)(unsafe.Pointer(v16)))) >= int32(0xc0) {
			for int32(uint8(*(*int8)(unsafe.Pointer(z1))))&int32(0xc0) == int32(0x80) {
				z1++
			}
		}
		libc.Xmemmove(tls, bp, z1, uint32(int32(int32(zOut))-int32(int32(z1))))
		zOut -= uintptr(int32(int32(z1)) - t__predefined_ptrdiff_t(bp))
		if iCode < uint32(0x00080) {
			v17 = zOut
			zOut++
			*(*int8)(unsafe.Pointer(v17)) = int8(uint8(iCode & libc.Uint32FromInt32(0xFF)))
		} else {
			if iCode < uint32(0x00800) {
				v18 = zOut
				zOut++
				*(*int8)(unsafe.Pointer(v18)) = int8(int32(0xC0) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
				v19 = zOut
				zOut++
				*(*int8)(unsafe.Pointer(v19)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
			} else {
				if iCode < uint32(0x10000) {
					v20 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v20)) = int8(int32(0xE0) + int32(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
					v21 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v21)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v22 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v22)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
				} else {
					v23 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v23)) = int8(int32(0xF0) + int32(uint8(iCode>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
					v24 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v24)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
					v25 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v25)) = int8(int32(0x80) + int32(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
					v26 = zOut
					zOut++
					*(*int8)(unsafe.Pointer(v26)) = int8(int32(0x80) + int32(uint8(iCode&libc.Uint32FromInt32(0x3F))))
				}
			}
		}
		/* Update the aStart[] array */
		aStart[0] = aStart[int32(1)]
		aStart[int32(1)] = aStart[int32(2)]
		aStart[int32(2)] = iNext
	}
	return rc
}

// C documentation
//
//	/*
//	** Argument xCreate is a pointer to a constructor function for a tokenizer.
//	** pTok is a tokenizer previously created using the same method. This function
//	** returns one of FTS5_PATTERN_NONE, FTS5_PATTERN_LIKE or FTS5_PATTERN_GLOB
//	** indicating the style of pattern matching that the tokenizer can support.
//	** In practice, this is:
//	**
//	**     "trigram" tokenizer, case_sensitive=1 - FTS5_PATTERN_GLOB
//	**     "trigram" tokenizer, case_sensitive=0 (the default) - FTS5_PATTERN_LIKE
//	**     all other tokenizers - FTS5_PATTERN_NONE
//	*/
func _sqlite3Fts5TokenizerPattern(tls *libc.TLS, xCreate uintptr, pTok uintptr) (r int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	if xCreate == __ccgo_fp(_fts5TriCreate) {
		p = pTok
		if (*TTrigramTokenizer)(unsafe.Pointer(p)).FiFoldParam == 0 {
			if (*TTrigramTokenizer)(unsafe.Pointer(p)).FbFold != 0 {
				v1 = int32(FTS5_PATTERN_LIKE)
			} else {
				v1 = int32(FTS5_PATTERN_GLOB)
			}
			return v1
		}
	}
	return FTS5_PATTERN_NONE
}

// C documentation
//
//	/*
//	** Register all built-in tokenizers with FTS5.
//	*/
func _sqlite3Fts5TokenizerInit(tls *libc.TLS, pApi uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var i, rc int32
	var _ /* aBuiltin at bp+0 */ [4]struct {
		FzName uintptr
		Fx     Tfts5_tokenizer
	}
	_, _ = i, rc
	*(*[4]struct {
		FzName uintptr
		Fx     Tfts5_tokenizer
	})(unsafe.Pointer(bp)) = [4]struct {
		FzName uintptr
		Fx     Tfts5_tokenizer
	}{
		0: {
			FzName: __ccgo_ts + 40277,
			Fx: Tfts5_tokenizer{
				FxCreate:   __ccgo_fp(_fts5UnicodeCreate),
				FxDelete:   __ccgo_fp(_fts5UnicodeDelete),
				FxTokenize: __ccgo_fp(_fts5UnicodeTokenize),
			},
		},
		1: {
			FzName: __ccgo_ts + 40581,
			Fx: Tfts5_tokenizer{
				FxCreate:   __ccgo_fp(_fts5AsciiCreate),
				FxDelete:   __ccgo_fp(_fts5AsciiDelete),
				FxTokenize: __ccgo_fp(_fts5AsciiTokenize),
			},
		},
		2: {
			FzName: __ccgo_ts + 40587,
			Fx: Tfts5_tokenizer{
				FxCreate:   __ccgo_fp(_fts5PorterCreate),
				FxDelete:   __ccgo_fp(_fts5PorterDelete),
				FxTokenize: __ccgo_fp(_fts5PorterTokenize),
			},
		},
		3: {
			FzName: __ccgo_ts + 40594,
			Fx: Tfts5_tokenizer{
				FxCreate:   __ccgo_fp(_fts5TriCreate),
				FxDelete:   __ccgo_fp(_fts5TriDelete),
				FxTokenize: __ccgo_fp(_fts5TriTokenize),
			},
		},
	}
	rc = SQLITE_OK /* To iterate through builtin functions */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < int32(libc.Uint32FromInt64(64)/libc.Uint32FromInt64(16))) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxCreateTokenizer})))(tls, pApi, (*(*[4]struct {
			FzName uintptr
			Fx     Tfts5_tokenizer
		})(unsafe.Pointer(bp)))[i].FzName, pApi, bp+uintptr(i)*16+4, uintptr(0))
		goto _1
	_1:
		;
		i++
	}
	return rc
}

/*
** 2012-05-25
**
** 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.
**
******************************************************************************
 */

/*
** DO NOT EDIT THIS MACHINE GENERATED FILE.
 */

/* #include <assert.h> */

// C documentation
//
//	/*
//	** If the argument is a codepoint corresponding to a lowercase letter
//	** in the ASCII range with a diacritic added, return the codepoint
//	** of the ASCII letter only. For example, if passed 235 - "LATIN
//	** SMALL LETTER E WITH DIAERESIS" - return 65 ("LATIN SMALL LETTER
//	** E"). The resuls of passing a codepoint that corresponds to an
//	** uppercase letter are undefined.
//	*/
func _fts5_remove_diacritic(tls *libc.TLS, c int32, bComplex int32) (r int32) {
	var aChar [126]uint8
	var aDia [126]uint16
	var iHi, iLo, iRes, iTest, v1 int32
	var key uint32
	_, _, _, _, _, _, _, _ = aChar, aDia, iHi, iLo, iRes, iTest, key, v1
	aDia = [126]uint16{
		1:   uint16(1797),
		2:   uint16(1848),
		3:   uint16(1859),
		4:   uint16(1891),
		5:   uint16(1928),
		6:   uint16(1940),
		7:   uint16(1995),
		8:   uint16(2024),
		9:   uint16(2040),
		10:  uint16(2060),
		11:  uint16(2110),
		12:  uint16(2168),
		13:  uint16(2206),
		14:  uint16(2264),
		15:  uint16(2286),
		16:  uint16(2344),
		17:  uint16(2383),
		18:  uint16(2472),
		19:  uint16(2488),
		20:  uint16(2516),
		21:  uint16(2596),
		22:  uint16(2668),
		23:  uint16(2732),
		24:  uint16(2782),
		25:  uint16(2842),
		26:  uint16(2894),
		27:  uint16(2954),
		28:  uint16(2984),
		29:  uint16(3000),
		30:  uint16(3028),
		31:  uint16(3336),
		32:  uint16(3456),
		33:  uint16(3696),
		34:  uint16(3712),
		35:  uint16(3728),
		36:  uint16(3744),
		37:  uint16(3766),
		38:  uint16(3832),
		39:  uint16(3896),
		40:  uint16(3912),
		41:  uint16(3928),
		42:  uint16(3944),
		43:  uint16(3968),
		44:  uint16(4008),
		45:  uint16(4040),
		46:  uint16(4056),
		47:  uint16(4106),
		48:  uint16(4138),
		49:  uint16(4170),
		50:  uint16(4202),
		51:  uint16(4234),
		52:  uint16(4266),
		53:  uint16(4296),
		54:  uint16(4312),
		55:  uint16(4344),
		56:  uint16(4408),
		57:  uint16(4424),
		58:  uint16(4442),
		59:  uint16(4472),
		60:  uint16(4488),
		61:  uint16(4504),
		62:  uint16(6148),
		63:  uint16(6198),
		64:  uint16(6264),
		65:  uint16(6280),
		66:  uint16(6360),
		67:  uint16(6429),
		68:  uint16(6505),
		69:  uint16(6529),
		70:  uint16(61448),
		71:  uint16(61468),
		72:  uint16(61512),
		73:  uint16(61534),
		74:  uint16(61592),
		75:  uint16(61610),
		76:  uint16(61642),
		77:  uint16(61672),
		78:  uint16(61688),
		79:  uint16(61704),
		80:  uint16(61726),
		81:  uint16(61784),
		82:  uint16(61800),
		83:  uint16(61816),
		84:  uint16(61836),
		85:  uint16(61880),
		86:  uint16(61896),
		87:  uint16(61914),
		88:  uint16(61948),
		89:  uint16(61998),
		90:  uint16(62062),
		91:  uint16(62122),
		92:  uint16(62154),
		93:  uint16(62184),
		94:  uint16(62200),
		95:  uint16(62218),
		96:  uint16(62252),
		97:  uint16(62302),
		98:  uint16(62364),
		99:  uint16(62410),
		100: uint16(62442),
		101: uint16(62478),
		102: uint16(62536),
		103: uint16(62554),
		104: uint16(62584),
		105: uint16(62604),
		106: uint16(62640),
		107: uint16(62648),
		108: uint16(62656),
		109: uint16(62664),
		110: uint16(62730),
		111: uint16(62766),
		112: uint16(62830),
		113: uint16(62890),
		114: uint16(62924),
		115: uint16(62974),
		116: uint16(63032),
		117: uint16(63050),
		118: uint16(63082),
		119: uint16(63118),
		120: uint16(63182),
		121: uint16(63242),
		122: uint16(63274),
		123: uint16(63310),
		124: uint16(63368),
		125: uint16(63390),
	}
	aChar = [126]uint8{
		1:   uint8('a'),
		2:   uint8('c'),
		3:   uint8('e'),
		4:   uint8('i'),
		5:   uint8('n'),
		6:   uint8('o'),
		7:   uint8('u'),
		8:   uint8('y'),
		9:   uint8('y'),
		10:  uint8('a'),
		11:  uint8('c'),
		12:  uint8('d'),
		13:  uint8('e'),
		14:  uint8('e'),
		15:  uint8('g'),
		16:  uint8('h'),
		17:  uint8('i'),
		18:  uint8('j'),
		19:  uint8('k'),
		20:  uint8('l'),
		21:  uint8('n'),
		22:  uint8('o'),
		23:  uint8('r'),
		24:  uint8('s'),
		25:  uint8('t'),
		26:  uint8('u'),
		27:  uint8('u'),
		28:  uint8('w'),
		29:  uint8('y'),
		30:  uint8('z'),
		31:  uint8('o'),
		32:  uint8('u'),
		33:  uint8('a'),
		34:  uint8('i'),
		35:  uint8('o'),
		36:  uint8('u'),
		37:  uint8(libc.Int32FromUint8('u') | int32(libc.Uint8FromInt32(0x80))),
		38:  uint8(libc.Int32FromUint8('a') | int32(libc.Uint8FromInt32(0x80))),
		39:  uint8('g'),
		40:  uint8('k'),
		41:  uint8('o'),
		42:  uint8(libc.Int32FromUint8('o') | int32(libc.Uint8FromInt32(0x80))),
		43:  uint8('j'),
		44:  uint8('g'),
		45:  uint8('n'),
		46:  uint8(libc.Int32FromUint8('a') | int32(libc.Uint8FromInt32(0x80))),
		47:  uint8('a'),
		48:  uint8('e'),
		49:  uint8('i'),
		50:  uint8('o'),
		51:  uint8('r'),
		52:  uint8('u'),
		53:  uint8('s'),
		54:  uint8('t'),
		55:  uint8('h'),
		56:  uint8('a'),
		57:  uint8('e'),
		58:  uint8(libc.Int32FromUint8('o') | int32(libc.Uint8FromInt32(0x80))),
		59:  uint8('o'),
		60:  uint8(libc.Int32FromUint8('o') | int32(libc.Uint8FromInt32(0x80))),
		61:  uint8('y'),
		70:  uint8('a'),
		71:  uint8('b'),
		72:  uint8(libc.Int32FromUint8('c') | int32(libc.Uint8FromInt32(0x80))),
		73:  uint8('d'),
		74:  uint8('d'),
		75:  uint8(libc.Int32FromUint8('e') | int32(libc.Uint8FromInt32(0x80))),
		76:  uint8('e'),
		77:  uint8(libc.Int32FromUint8('e') | int32(libc.Uint8FromInt32(0x80))),
		78:  uint8('f'),
		79:  uint8('g'),
		80:  uint8('h'),
		81:  uint8('h'),
		82:  uint8('i'),
		83:  uint8(libc.Int32FromUint8('i') | int32(libc.Uint8FromInt32(0x80))),
		84:  uint8('k'),
		85:  uint8('l'),
		86:  uint8(libc.Int32FromUint8('l') | int32(libc.Uint8FromInt32(0x80))),
		87:  uint8('l'),
		88:  uint8('m'),
		89:  uint8('n'),
		90:  uint8(libc.Int32FromUint8('o') | int32(libc.Uint8FromInt32(0x80))),
		91:  uint8('p'),
		92:  uint8('r'),
		93:  uint8(libc.Int32FromUint8('r') | int32(libc.Uint8FromInt32(0x80))),
		94:  uint8('r'),
		95:  uint8('s'),
		96:  uint8(libc.Int32FromUint8('s') | int32(libc.Uint8FromInt32(0x80))),
		97:  uint8('t'),
		98:  uint8('u'),
		99:  uint8(libc.Int32FromUint8('u') | int32(libc.Uint8FromInt32(0x80))),
		100: uint8('v'),
		101: uint8('w'),
		102: uint8('w'),
		103: uint8('x'),
		104: uint8('y'),
		105: uint8('z'),
		106: uint8('h'),
		107: uint8('t'),
		108: uint8('w'),
		109: uint8('y'),
		110: uint8('a'),
		111: uint8(libc.Int32FromUint8('a') | int32(libc.Uint8FromInt32(0x80))),
		112: uint8(libc.Int32FromUint8('a') | int32(libc.Uint8FromInt32(0x80))),
		113: uint8(libc.Int32FromUint8('a') | int32(libc.Uint8FromInt32(0x80))),
		114: uint8('e'),
		115: uint8(libc.Int32FromUint8('e') | int32(libc.Uint8FromInt32(0x80))),
		116: uint8(libc.Int32FromUint8('e') | int32(libc.Uint8FromInt32(0x80))),
		117: uint8('i'),
		118: uint8('o'),
		119: uint8(libc.Int32FromUint8('o') | int32(libc.Uint8FromInt32(0x80))),
		120: uint8(libc.Int32FromUint8('o') | int32(libc.Uint8FromInt32(0x80))),
		121: uint8(libc.Int32FromUint8('o') | int32(libc.Uint8FromInt32(0x80))),
		122: uint8('u'),
		123: uint8(libc.Int32FromUint8('u') | int32(libc.Uint8FromInt32(0x80))),
		124: uint8(libc.Int32FromUint8('u') | int32(libc.Uint8FromInt32(0x80))),
		125: uint8('y'),
	}
	key = uint32(uint32(c))<<int32(3) | uint32(0x00000007)
	iRes = 0
	iHi = int32(libc.Uint32FromInt64(252)/libc.Uint32FromInt64(2) - libc.Uint32FromInt32(1))
	iLo = 0
	for iHi >= iLo {
		iTest = (iHi + iLo) / int32(2)
		if key >= uint32(aDia[iTest]) {
			iRes = iTest
			iLo = iTest + int32(1)
		} else {
			iHi = iTest - int32(1)
		}
	}
	if bComplex == 0 && int32(aChar[iRes])&int32(0x80) != 0 {
		return c
	}
	if c > int32(aDia[iRes])>>int32(3)+int32(aDia[iRes])&int32(0x07) {
		v1 = c
	} else {
		v1 = int32(aChar[iRes]) & int32(0x7F)
	}
	return v1
}

// C documentation
//
//	/*
//	** Return true if the argument interpreted as a unicode codepoint
//	** is a diacritical modifier character.
//	*/
func _sqlite3Fts5UnicodeIsdiacritic(tls *libc.TLS, c int32) (r int32) {
	var mask0, mask1, v1 uint32
	_, _, _ = mask0, mask1, v1
	mask0 = uint32(0x08029FDF)
	mask1 = uint32(0x000361F8)
	if c < int32(768) || c > int32(817) {
		return 0
	}
	if c < libc.Int32FromInt32(768)+libc.Int32FromInt32(32) {
		v1 = mask0 & (libc.Uint32FromInt32(1) << (c - int32(768)))
	} else {
		v1 = mask1 & (libc.Uint32FromInt32(1) << (c - int32(768) - int32(32)))
	}
	return int32(v1)
}

// C documentation
//
//	/*
//	** Interpret the argument as a unicode codepoint. If the codepoint
//	** is an upper case character that has a lower case equivalent,
//	** return the codepoint corresponding to the lower case version.
//	** Otherwise, return a copy of the argument.
//	**
//	** The results are undefined if the value passed to this function
//	** is less than zero.
//	*/
func _sqlite3Fts5UnicodeFold(tls *libc.TLS, c int32, eRemoveDiacritic int32) (r int32) {
	var cmp, iHi, iLo, iRes, iTest, ret int32
	var p uintptr
	_, _, _, _, _, _, _ = cmp, iHi, iLo, iRes, iTest, p, ret
	ret = c
	if c < int32(128) {
		if c >= int32('A') && c <= int32('Z') {
			ret = c + (libc.Int32FromUint8('a') - libc.Int32FromUint8('A'))
		}
	} else {
		if c < int32(65536) {
			iHi = int32(libc.Uint32FromInt64(652)/libc.Uint32FromInt64(4) - libc.Uint32FromInt32(1))
			iLo = 0
			iRes = -int32(1)
			for iHi >= iLo {
				iTest = (iHi + iLo) / int32(2)
				cmp = c - int32(_aEntry[iTest].FiCode)
				if cmp >= 0 {
					iRes = iTest
					iLo = iTest + int32(1)
				} else {
					iHi = iTest - int32(1)
				}
			}
			p = uintptr(unsafe.Pointer(&_aEntry)) + uintptr(iRes)*4
			if c < int32((*struct {
				FiCode  uint16
				Fflags  uint8
				FnRange uint8
			})(unsafe.Pointer(p)).FiCode)+int32((*struct {
				FiCode  uint16
				Fflags  uint8
				FnRange uint8
			})(unsafe.Pointer(p)).FnRange) && 0 == int32(0x01)&int32((*struct {
				FiCode  uint16
				Fflags  uint8
				FnRange uint8
			})(unsafe.Pointer(p)).Fflags)&(int32((*struct {
				FiCode  uint16
				Fflags  uint8
				FnRange uint8
			})(unsafe.Pointer(p)).FiCode)^c) {
				ret = (c + int32(_aiOff[int32((*struct {
					FiCode  uint16
					Fflags  uint8
					FnRange uint8
				})(unsafe.Pointer(p)).Fflags)>>int32(1)])) & int32(0x0000FFFF)
			}
			if eRemoveDiacritic != 0 {
				ret = _fts5_remove_diacritic(tls, ret, libc.BoolInt32(eRemoveDiacritic == int32(2)))
			}
		} else {
			if c >= int32(66560) && c < int32(66600) {
				ret = c + int32(40)
			}
		}
	}
	return ret
}

/* Each entry in the following array defines a rule for folding a range
 ** of codepoints to lower case. The rule applies to a range of nRange
 ** codepoints starting at codepoint iCode.
 **
 ** If the least significant bit in flags is clear, then the rule applies
 ** to all nRange codepoints (i.e. all nRange codepoints are upper case and
 ** need to be folded). Or, if it is set, then the rule only applies to
 ** every second codepoint in the range, starting with codepoint C.
 **
 ** The 7 most significant bits in flags are an index into the aiOff[]
 ** array. If a specific codepoint C does require folding, then its lower
 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
 **
 ** The contents of this array are generated by parsing the CaseFolding.txt
 ** file distributed as part of the "Unicode Character Database". See
 ** http://www.unicode.org for details.
 */
var _aEntry = [163]struct {
	FiCode  uint16
	Fflags  uint8
	FnRange uint8
}{
	0: {
		FiCode:  uint16(65),
		Fflags:  uint8(14),
		FnRange: uint8(26),
	},
	1: {
		FiCode:  uint16(181),
		Fflags:  uint8(64),
		FnRange: uint8(1),
	},
	2: {
		FiCode:  uint16(192),
		Fflags:  uint8(14),
		FnRange: uint8(23),
	},
	3: {
		FiCode:  uint16(216),
		Fflags:  uint8(14),
		FnRange: uint8(7),
	},
	4: {
		FiCode:  uint16(256),
		Fflags:  uint8(1),
		FnRange: uint8(48),
	},
	5: {
		FiCode:  uint16(306),
		Fflags:  uint8(1),
		FnRange: uint8(6),
	},
	6: {
		FiCode:  uint16(313),
		Fflags:  uint8(1),
		FnRange: uint8(16),
	},
	7: {
		FiCode:  uint16(330),
		Fflags:  uint8(1),
		FnRange: uint8(46),
	},
	8: {
		FiCode:  uint16(376),
		Fflags:  uint8(116),
		FnRange: uint8(1),
	},
	9: {
		FiCode:  uint16(377),
		Fflags:  uint8(1),
		FnRange: uint8(6),
	},
	10: {
		FiCode:  uint16(383),
		Fflags:  uint8(104),
		FnRange: uint8(1),
	},
	11: {
		FiCode:  uint16(385),
		Fflags:  uint8(50),
		FnRange: uint8(1),
	},
	12: {
		FiCode:  uint16(386),
		Fflags:  uint8(1),
		FnRange: uint8(4),
	},
	13: {
		FiCode:  uint16(390),
		Fflags:  uint8(44),
		FnRange: uint8(1),
	},
	14: {
		FiCode:  uint16(391),
		FnRange: uint8(1),
	},
	15: {
		FiCode:  uint16(393),
		Fflags:  uint8(42),
		FnRange: uint8(2),
	},
	16: {
		FiCode:  uint16(395),
		FnRange: uint8(1),
	},
	17: {
		FiCode:  uint16(398),
		Fflags:  uint8(32),
		FnRange: uint8(1),
	},
	18: {
		FiCode:  uint16(399),
		Fflags:  uint8(38),
		FnRange: uint8(1),
	},
	19: {
		FiCode:  uint16(400),
		Fflags:  uint8(40),
		FnRange: uint8(1),
	},
	20: {
		FiCode:  uint16(401),
		FnRange: uint8(1),
	},
	21: {
		FiCode:  uint16(403),
		Fflags:  uint8(42),
		FnRange: uint8(1),
	},
	22: {
		FiCode:  uint16(404),
		Fflags:  uint8(46),
		FnRange: uint8(1),
	},
	23: {
		FiCode:  uint16(406),
		Fflags:  uint8(52),
		FnRange: uint8(1),
	},
	24: {
		FiCode:  uint16(407),
		Fflags:  uint8(48),
		FnRange: uint8(1),
	},
	25: {
		FiCode:  uint16(408),
		FnRange: uint8(1),
	},
	26: {
		FiCode:  uint16(412),
		Fflags:  uint8(52),
		FnRange: uint8(1),
	},
	27: {
		FiCode:  uint16(413),
		Fflags:  uint8(54),
		FnRange: uint8(1),
	},
	28: {
		FiCode:  uint16(415),
		Fflags:  uint8(56),
		FnRange: uint8(1),
	},
	29: {
		FiCode:  uint16(416),
		Fflags:  uint8(1),
		FnRange: uint8(6),
	},
	30: {
		FiCode:  uint16(422),
		Fflags:  uint8(60),
		FnRange: uint8(1),
	},
	31: {
		FiCode:  uint16(423),
		FnRange: uint8(1),
	},
	32: {
		FiCode:  uint16(425),
		Fflags:  uint8(60),
		FnRange: uint8(1),
	},
	33: {
		FiCode:  uint16(428),
		FnRange: uint8(1),
	},
	34: {
		FiCode:  uint16(430),
		Fflags:  uint8(60),
		FnRange: uint8(1),
	},
	35: {
		FiCode:  uint16(431),
		FnRange: uint8(1),
	},
	36: {
		FiCode:  uint16(433),
		Fflags:  uint8(58),
		FnRange: uint8(2),
	},
	37: {
		FiCode:  uint16(435),
		Fflags:  uint8(1),
		FnRange: uint8(4),
	},
	38: {
		FiCode:  uint16(439),
		Fflags:  uint8(62),
		FnRange: uint8(1),
	},
	39: {
		FiCode:  uint16(440),
		FnRange: uint8(1),
	},
	40: {
		FiCode:  uint16(444),
		FnRange: uint8(1),
	},
	41: {
		FiCode:  uint16(452),
		Fflags:  uint8(2),
		FnRange: uint8(1),
	},
	42: {
		FiCode:  uint16(453),
		FnRange: uint8(1),
	},
	43: {
		FiCode:  uint16(455),
		Fflags:  uint8(2),
		FnRange: uint8(1),
	},
	44: {
		FiCode:  uint16(456),
		FnRange: uint8(1),
	},
	45: {
		FiCode:  uint16(458),
		Fflags:  uint8(2),
		FnRange: uint8(1),
	},
	46: {
		FiCode:  uint16(459),
		Fflags:  uint8(1),
		FnRange: uint8(18),
	},
	47: {
		FiCode:  uint16(478),
		Fflags:  uint8(1),
		FnRange: uint8(18),
	},
	48: {
		FiCode:  uint16(497),
		Fflags:  uint8(2),
		FnRange: uint8(1),
	},
	49: {
		FiCode:  uint16(498),
		Fflags:  uint8(1),
		FnRange: uint8(4),
	},
	50: {
		FiCode:  uint16(502),
		Fflags:  uint8(122),
		FnRange: uint8(1),
	},
	51: {
		FiCode:  uint16(503),
		Fflags:  uint8(134),
		FnRange: uint8(1),
	},
	52: {
		FiCode:  uint16(504),
		Fflags:  uint8(1),
		FnRange: uint8(40),
	},
	53: {
		FiCode:  uint16(544),
		Fflags:  uint8(110),
		FnRange: uint8(1),
	},
	54: {
		FiCode:  uint16(546),
		Fflags:  uint8(1),
		FnRange: uint8(18),
	},
	55: {
		FiCode:  uint16(570),
		Fflags:  uint8(70),
		FnRange: uint8(1),
	},
	56: {
		FiCode:  uint16(571),
		FnRange: uint8(1),
	},
	57: {
		FiCode:  uint16(573),
		Fflags:  uint8(108),
		FnRange: uint8(1),
	},
	58: {
		FiCode:  uint16(574),
		Fflags:  uint8(68),
		FnRange: uint8(1),
	},
	59: {
		FiCode:  uint16(577),
		FnRange: uint8(1),
	},
	60: {
		FiCode:  uint16(579),
		Fflags:  uint8(106),
		FnRange: uint8(1),
	},
	61: {
		FiCode:  uint16(580),
		Fflags:  uint8(28),
		FnRange: uint8(1),
	},
	62: {
		FiCode:  uint16(581),
		Fflags:  uint8(30),
		FnRange: uint8(1),
	},
	63: {
		FiCode:  uint16(582),
		Fflags:  uint8(1),
		FnRange: uint8(10),
	},
	64: {
		FiCode:  uint16(837),
		Fflags:  uint8(36),
		FnRange: uint8(1),
	},
	65: {
		FiCode:  uint16(880),
		Fflags:  uint8(1),
		FnRange: uint8(4),
	},
	66: {
		FiCode:  uint16(886),
		FnRange: uint8(1),
	},
	67: {
		FiCode:  uint16(902),
		Fflags:  uint8(18),
		FnRange: uint8(1),
	},
	68: {
		FiCode:  uint16(904),
		Fflags:  uint8(16),
		FnRange: uint8(3),
	},
	69: {
		FiCode:  uint16(908),
		Fflags:  uint8(26),
		FnRange: uint8(1),
	},
	70: {
		FiCode:  uint16(910),
		Fflags:  uint8(24),
		FnRange: uint8(2),
	},
	71: {
		FiCode:  uint16(913),
		Fflags:  uint8(14),
		FnRange: uint8(17),
	},
	72: {
		FiCode:  uint16(931),
		Fflags:  uint8(14),
		FnRange: uint8(9),
	},
	73: {
		FiCode:  uint16(962),
		FnRange: uint8(1),
	},
	74: {
		FiCode:  uint16(975),
		Fflags:  uint8(4),
		FnRange: uint8(1),
	},
	75: {
		FiCode:  uint16(976),
		Fflags:  uint8(140),
		FnRange: uint8(1),
	},
	76: {
		FiCode:  uint16(977),
		Fflags:  uint8(142),
		FnRange: uint8(1),
	},
	77: {
		FiCode:  uint16(981),
		Fflags:  uint8(146),
		FnRange: uint8(1),
	},
	78: {
		FiCode:  uint16(982),
		Fflags:  uint8(144),
		FnRange: uint8(1),
	},
	79: {
		FiCode:  uint16(984),
		Fflags:  uint8(1),
		FnRange: uint8(24),
	},
	80: {
		FiCode:  uint16(1008),
		Fflags:  uint8(136),
		FnRange: uint8(1),
	},
	81: {
		FiCode:  uint16(1009),
		Fflags:  uint8(138),
		FnRange: uint8(1),
	},
	82: {
		FiCode:  uint16(1012),
		Fflags:  uint8(130),
		FnRange: uint8(1),
	},
	83: {
		FiCode:  uint16(1013),
		Fflags:  uint8(128),
		FnRange: uint8(1),
	},
	84: {
		FiCode:  uint16(1015),
		FnRange: uint8(1),
	},
	85: {
		FiCode:  uint16(1017),
		Fflags:  uint8(152),
		FnRange: uint8(1),
	},
	86: {
		FiCode:  uint16(1018),
		FnRange: uint8(1),
	},
	87: {
		FiCode:  uint16(1021),
		Fflags:  uint8(110),
		FnRange: uint8(3),
	},
	88: {
		FiCode:  uint16(1024),
		Fflags:  uint8(34),
		FnRange: uint8(16),
	},
	89: {
		FiCode:  uint16(1040),
		Fflags:  uint8(14),
		FnRange: uint8(32),
	},
	90: {
		FiCode:  uint16(1120),
		Fflags:  uint8(1),
		FnRange: uint8(34),
	},
	91: {
		FiCode:  uint16(1162),
		Fflags:  uint8(1),
		FnRange: uint8(54),
	},
	92: {
		FiCode:  uint16(1216),
		Fflags:  uint8(6),
		FnRange: uint8(1),
	},
	93: {
		FiCode:  uint16(1217),
		Fflags:  uint8(1),
		FnRange: uint8(14),
	},
	94: {
		FiCode:  uint16(1232),
		Fflags:  uint8(1),
		FnRange: uint8(88),
	},
	95: {
		FiCode:  uint16(1329),
		Fflags:  uint8(22),
		FnRange: uint8(38),
	},
	96: {
		FiCode:  uint16(4256),
		Fflags:  uint8(66),
		FnRange: uint8(38),
	},
	97: {
		FiCode:  uint16(4295),
		Fflags:  uint8(66),
		FnRange: uint8(1),
	},
	98: {
		FiCode:  uint16(4301),
		Fflags:  uint8(66),
		FnRange: uint8(1),
	},
	99: {
		FiCode:  uint16(7680),
		Fflags:  uint8(1),
		FnRange: uint8(150),
	},
	100: {
		FiCode:  uint16(7835),
		Fflags:  uint8(132),
		FnRange: uint8(1),
	},
	101: {
		FiCode:  uint16(7838),
		Fflags:  uint8(96),
		FnRange: uint8(1),
	},
	102: {
		FiCode:  uint16(7840),
		Fflags:  uint8(1),
		FnRange: uint8(96),
	},
	103: {
		FiCode:  uint16(7944),
		Fflags:  uint8(150),
		FnRange: uint8(8),
	},
	104: {
		FiCode:  uint16(7960),
		Fflags:  uint8(150),
		FnRange: uint8(6),
	},
	105: {
		FiCode:  uint16(7976),
		Fflags:  uint8(150),
		FnRange: uint8(8),
	},
	106: {
		FiCode:  uint16(7992),
		Fflags:  uint8(150),
		FnRange: uint8(8),
	},
	107: {
		FiCode:  uint16(8008),
		Fflags:  uint8(150),
		FnRange: uint8(6),
	},
	108: {
		FiCode:  uint16(8025),
		Fflags:  uint8(151),
		FnRange: uint8(8),
	},
	109: {
		FiCode:  uint16(8040),
		Fflags:  uint8(150),
		FnRange: uint8(8),
	},
	110: {
		FiCode:  uint16(8072),
		Fflags:  uint8(150),
		FnRange: uint8(8),
	},
	111: {
		FiCode:  uint16(8088),
		Fflags:  uint8(150),
		FnRange: uint8(8),
	},
	112: {
		FiCode:  uint16(8104),
		Fflags:  uint8(150),
		FnRange: uint8(8),
	},
	113: {
		FiCode:  uint16(8120),
		Fflags:  uint8(150),
		FnRange: uint8(2),
	},
	114: {
		FiCode:  uint16(8122),
		Fflags:  uint8(126),
		FnRange: uint8(2),
	},
	115: {
		FiCode:  uint16(8124),
		Fflags:  uint8(148),
		FnRange: uint8(1),
	},
	116: {
		FiCode:  uint16(8126),
		Fflags:  uint8(100),
		FnRange: uint8(1),
	},
	117: {
		FiCode:  uint16(8136),
		Fflags:  uint8(124),
		FnRange: uint8(4),
	},
	118: {
		FiCode:  uint16(8140),
		Fflags:  uint8(148),
		FnRange: uint8(1),
	},
	119: {
		FiCode:  uint16(8152),
		Fflags:  uint8(150),
		FnRange: uint8(2),
	},
	120: {
		FiCode:  uint16(8154),
		Fflags:  uint8(120),
		FnRange: uint8(2),
	},
	121: {
		FiCode:  uint16(8168),
		Fflags:  uint8(150),
		FnRange: uint8(2),
	},
	122: {
		FiCode:  uint16(8170),
		Fflags:  uint8(118),
		FnRange: uint8(2),
	},
	123: {
		FiCode:  uint16(8172),
		Fflags:  uint8(152),
		FnRange: uint8(1),
	},
	124: {
		FiCode:  uint16(8184),
		Fflags:  uint8(112),
		FnRange: uint8(2),
	},
	125: {
		FiCode:  uint16(8186),
		Fflags:  uint8(114),
		FnRange: uint8(2),
	},
	126: {
		FiCode:  uint16(8188),
		Fflags:  uint8(148),
		FnRange: uint8(1),
	},
	127: {
		FiCode:  uint16(8486),
		Fflags:  uint8(98),
		FnRange: uint8(1),
	},
	128: {
		FiCode:  uint16(8490),
		Fflags:  uint8(92),
		FnRange: uint8(1),
	},
	129: {
		FiCode:  uint16(8491),
		Fflags:  uint8(94),
		FnRange: uint8(1),
	},
	130: {
		FiCode:  uint16(8498),
		Fflags:  uint8(12),
		FnRange: uint8(1),
	},
	131: {
		FiCode:  uint16(8544),
		Fflags:  uint8(8),
		FnRange: uint8(16),
	},
	132: {
		FiCode:  uint16(8579),
		FnRange: uint8(1),
	},
	133: {
		FiCode:  uint16(9398),
		Fflags:  uint8(10),
		FnRange: uint8(26),
	},
	134: {
		FiCode:  uint16(11264),
		Fflags:  uint8(22),
		FnRange: uint8(47),
	},
	135: {
		FiCode:  uint16(11360),
		FnRange: uint8(1),
	},
	136: {
		FiCode:  uint16(11362),
		Fflags:  uint8(88),
		FnRange: uint8(1),
	},
	137: {
		FiCode:  uint16(11363),
		Fflags:  uint8(102),
		FnRange: uint8(1),
	},
	138: {
		FiCode:  uint16(11364),
		Fflags:  uint8(90),
		FnRange: uint8(1),
	},
	139: {
		FiCode:  uint16(11367),
		Fflags:  uint8(1),
		FnRange: uint8(6),
	},
	140: {
		FiCode:  uint16(11373),
		Fflags:  uint8(84),
		FnRange: uint8(1),
	},
	141: {
		FiCode:  uint16(11374),
		Fflags:  uint8(86),
		FnRange: uint8(1),
	},
	142: {
		FiCode:  uint16(11375),
		Fflags:  uint8(80),
		FnRange: uint8(1),
	},
	143: {
		FiCode:  uint16(11376),
		Fflags:  uint8(82),
		FnRange: uint8(1),
	},
	144: {
		FiCode:  uint16(11378),
		FnRange: uint8(1),
	},
	145: {
		FiCode:  uint16(11381),
		FnRange: uint8(1),
	},
	146: {
		FiCode:  uint16(11390),
		Fflags:  uint8(78),
		FnRange: uint8(2),
	},
	147: {
		FiCode:  uint16(11392),
		Fflags:  uint8(1),
		FnRange: uint8(100),
	},
	148: {
		FiCode:  uint16(11499),
		Fflags:  uint8(1),
		FnRange: uint8(4),
	},
	149: {
		FiCode:  uint16(11506),
		FnRange: uint8(1),
	},
	150: {
		FiCode:  uint16(42560),
		Fflags:  uint8(1),
		FnRange: uint8(46),
	},
	151: {
		FiCode:  uint16(42624),
		Fflags:  uint8(1),
		FnRange: uint8(24),
	},
	152: {
		FiCode:  uint16(42786),
		Fflags:  uint8(1),
		FnRange: uint8(14),
	},
	153: {
		FiCode:  uint16(42802),
		Fflags:  uint8(1),
		FnRange: uint8(62),
	},
	154: {
		FiCode:  uint16(42873),
		Fflags:  uint8(1),
		FnRange: uint8(4),
	},
	155: {
		FiCode:  uint16(42877),
		Fflags:  uint8(76),
		FnRange: uint8(1),
	},
	156: {
		FiCode:  uint16(42878),
		Fflags:  uint8(1),
		FnRange: uint8(10),
	},
	157: {
		FiCode:  uint16(42891),
		FnRange: uint8(1),
	},
	158: {
		FiCode:  uint16(42893),
		Fflags:  uint8(74),
		FnRange: uint8(1),
	},
	159: {
		FiCode:  uint16(42896),
		Fflags:  uint8(1),
		FnRange: uint8(4),
	},
	160: {
		FiCode:  uint16(42912),
		Fflags:  uint8(1),
		FnRange: uint8(10),
	},
	161: {
		FiCode:  uint16(42922),
		Fflags:  uint8(72),
		FnRange: uint8(1),
	},
	162: {
		FiCode:  uint16(65313),
		Fflags:  uint8(14),
		FnRange: uint8(26),
	},
}

var _aiOff = [77]uint16{
	0:  uint16(1),
	1:  uint16(2),
	2:  uint16(8),
	3:  uint16(15),
	4:  uint16(16),
	5:  uint16(26),
	6:  uint16(28),
	7:  uint16(32),
	8:  uint16(37),
	9:  uint16(38),
	10: uint16(40),
	11: uint16(48),
	12: uint16(63),
	13: uint16(64),
	14: uint16(69),
	15: uint16(71),
	16: uint16(79),
	17: uint16(80),
	18: uint16(116),
	19: uint16(202),
	20: uint16(203),
	21: uint16(205),
	22: uint16(206),
	23: uint16(207),
	24: uint16(209),
	25: uint16(210),
	26: uint16(211),
	27: uint16(213),
	28: uint16(214),
	29: uint16(217),
	30: uint16(218),
	31: uint16(219),
	32: uint16(775),
	33: uint16(7264),
	34: uint16(10792),
	35: uint16(10795),
	36: uint16(23228),
	37: uint16(23256),
	38: uint16(30204),
	39: uint16(54721),
	40: uint16(54753),
	41: uint16(54754),
	42: uint16(54756),
	43: uint16(54787),
	44: uint16(54793),
	45: uint16(54809),
	46: uint16(57153),
	47: uint16(57274),
	48: uint16(57921),
	49: uint16(58019),
	50: uint16(58363),
	51: uint16(61722),
	52: uint16(65268),
	53: uint16(65341),
	54: uint16(65373),
	55: uint16(65406),
	56: uint16(65408),
	57: uint16(65410),
	58: uint16(65415),
	59: uint16(65424),
	60: uint16(65436),
	61: uint16(65439),
	62: uint16(65450),
	63: uint16(65462),
	64: uint16(65472),
	65: uint16(65476),
	66: uint16(65478),
	67: uint16(65480),
	68: uint16(65482),
	69: uint16(65488),
	70: uint16(65506),
	71: uint16(65511),
	72: uint16(65514),
	73: uint16(65521),
	74: uint16(65527),
	75: uint16(65528),
	76: uint16(65529),
}

func _sqlite3Fts5UnicodeCatParse(tls *libc.TLS, zCat uintptr, aArray uintptr) (r int32) {
	*(*Tu8)(unsafe.Pointer(aArray)) = uint8(1)
	switch int32(*(*int8)(unsafe.Pointer(zCat))) {
	case int32('C'):
		switch int32(*(*int8)(unsafe.Pointer(zCat + 1))) {
		case int32('c'):
			*(*Tu8)(unsafe.Pointer(aArray + 1)) = uint8(1)
		case int32('f'):
			*(*Tu8)(unsafe.Pointer(aArray + 2)) = uint8(1)
		case int32('n'):
			*(*Tu8)(unsafe.Pointer(aArray + 3)) = uint8(1)
		case int32('s'):
			*(*Tu8)(unsafe.Pointer(aArray + 4)) = uint8(1)
		case int32('o'):
			*(*Tu8)(unsafe.Pointer(aArray + 31)) = uint8(1)
		case int32('*'):
			*(*Tu8)(unsafe.Pointer(aArray + 1)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 2)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 3)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 4)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 31)) = uint8(1)
		default:
			return int32(1)
		}
	case int32('L'):
		switch int32(*(*int8)(unsafe.Pointer(zCat + 1))) {
		case int32('l'):
			*(*Tu8)(unsafe.Pointer(aArray + 5)) = uint8(1)
		case int32('m'):
			*(*Tu8)(unsafe.Pointer(aArray + 6)) = uint8(1)
		case int32('o'):
			*(*Tu8)(unsafe.Pointer(aArray + 7)) = uint8(1)
		case int32('t'):
			*(*Tu8)(unsafe.Pointer(aArray + 8)) = uint8(1)
		case int32('u'):
			*(*Tu8)(unsafe.Pointer(aArray + 9)) = uint8(1)
		case int32('C'):
			*(*Tu8)(unsafe.Pointer(aArray + 30)) = uint8(1)
		case int32('*'):
			*(*Tu8)(unsafe.Pointer(aArray + 5)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 6)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 7)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 8)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 9)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 30)) = uint8(1)
		default:
			return int32(1)
		}
	case int32('M'):
		switch int32(*(*int8)(unsafe.Pointer(zCat + 1))) {
		case int32('c'):
			*(*Tu8)(unsafe.Pointer(aArray + 10)) = uint8(1)
		case int32('e'):
			*(*Tu8)(unsafe.Pointer(aArray + 11)) = uint8(1)
		case int32('n'):
			*(*Tu8)(unsafe.Pointer(aArray + 12)) = uint8(1)
		case int32('*'):
			*(*Tu8)(unsafe.Pointer(aArray + 10)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 11)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 12)) = uint8(1)
		default:
			return int32(1)
		}
	case int32('N'):
		switch int32(*(*int8)(unsafe.Pointer(zCat + 1))) {
		case int32('d'):
			*(*Tu8)(unsafe.Pointer(aArray + 13)) = uint8(1)
		case int32('l'):
			*(*Tu8)(unsafe.Pointer(aArray + 14)) = uint8(1)
		case int32('o'):
			*(*Tu8)(unsafe.Pointer(aArray + 15)) = uint8(1)
		case int32('*'):
			*(*Tu8)(unsafe.Pointer(aArray + 13)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 14)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 15)) = uint8(1)
		default:
			return int32(1)
		}
	case int32('P'):
		switch int32(*(*int8)(unsafe.Pointer(zCat + 1))) {
		case int32('c'):
			*(*Tu8)(unsafe.Pointer(aArray + 16)) = uint8(1)
		case int32('d'):
			*(*Tu8)(unsafe.Pointer(aArray + 17)) = uint8(1)
		case int32('e'):
			*(*Tu8)(unsafe.Pointer(aArray + 18)) = uint8(1)
		case int32('f'):
			*(*Tu8)(unsafe.Pointer(aArray + 19)) = uint8(1)
		case int32('i'):
			*(*Tu8)(unsafe.Pointer(aArray + 20)) = uint8(1)
		case int32('o'):
			*(*Tu8)(unsafe.Pointer(aArray + 21)) = uint8(1)
		case int32('s'):
			*(*Tu8)(unsafe.Pointer(aArray + 22)) = uint8(1)
		case int32('*'):
			*(*Tu8)(unsafe.Pointer(aArray + 16)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 17)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 18)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 19)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 20)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 21)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 22)) = uint8(1)
		default:
			return int32(1)
		}
	case int32('S'):
		switch int32(*(*int8)(unsafe.Pointer(zCat + 1))) {
		case int32('c'):
			*(*Tu8)(unsafe.Pointer(aArray + 23)) = uint8(1)
		case int32('k'):
			*(*Tu8)(unsafe.Pointer(aArray + 24)) = uint8(1)
		case int32('m'):
			*(*Tu8)(unsafe.Pointer(aArray + 25)) = uint8(1)
		case int32('o'):
			*(*Tu8)(unsafe.Pointer(aArray + 26)) = uint8(1)
		case int32('*'):
			*(*Tu8)(unsafe.Pointer(aArray + 23)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 24)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 25)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 26)) = uint8(1)
		default:
			return int32(1)
		}
	case int32('Z'):
		switch int32(*(*int8)(unsafe.Pointer(zCat + 1))) {
		case int32('l'):
			*(*Tu8)(unsafe.Pointer(aArray + 27)) = uint8(1)
		case int32('p'):
			*(*Tu8)(unsafe.Pointer(aArray + 28)) = uint8(1)
		case int32('s'):
			*(*Tu8)(unsafe.Pointer(aArray + 29)) = uint8(1)
		case int32('*'):
			*(*Tu8)(unsafe.Pointer(aArray + 27)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 28)) = uint8(1)
			*(*Tu8)(unsafe.Pointer(aArray + 29)) = uint8(1)
		default:
			return int32(1)
		}
		break
	}
	return 0
}

var _aFts5UnicodeBlock = [17]Tu16{
	1:  uint16(1471),
	2:  uint16(1753),
	3:  uint16(1760),
	4:  uint16(1760),
	5:  uint16(1760),
	6:  uint16(1760),
	7:  uint16(1760),
	8:  uint16(1760),
	9:  uint16(1760),
	10: uint16(1760),
	11: uint16(1760),
	12: uint16(1760),
	13: uint16(1760),
	14: uint16(1760),
	15: uint16(1763),
	16: uint16(1765),
}
var _aFts5UnicodeMap = [1765]Tu16{
	1:    uint16(32),
	2:    uint16(33),
	3:    uint16(36),
	4:    uint16(37),
	5:    uint16(40),
	6:    uint16(41),
	7:    uint16(42),
	8:    uint16(43),
	9:    uint16(44),
	10:   uint16(45),
	11:   uint16(46),
	12:   uint16(48),
	13:   uint16(58),
	14:   uint16(60),
	15:   uint16(63),
	16:   uint16(65),
	17:   uint16(91),
	18:   uint16(92),
	19:   uint16(93),
	20:   uint16(94),
	21:   uint16(95),
	22:   uint16(96),
	23:   uint16(97),
	24:   uint16(123),
	25:   uint16(124),
	26:   uint16(125),
	27:   uint16(126),
	28:   uint16(127),
	29:   uint16(160),
	30:   uint16(161),
	31:   uint16(162),
	32:   uint16(166),
	33:   uint16(167),
	34:   uint16(168),
	35:   uint16(169),
	36:   uint16(170),
	37:   uint16(171),
	38:   uint16(172),
	39:   uint16(173),
	40:   uint16(174),
	41:   uint16(175),
	42:   uint16(176),
	43:   uint16(177),
	44:   uint16(178),
	45:   uint16(180),
	46:   uint16(181),
	47:   uint16(182),
	48:   uint16(184),
	49:   uint16(185),
	50:   uint16(186),
	51:   uint16(187),
	52:   uint16(188),
	53:   uint16(191),
	54:   uint16(192),
	55:   uint16(215),
	56:   uint16(216),
	57:   uint16(223),
	58:   uint16(247),
	59:   uint16(248),
	60:   uint16(256),
	61:   uint16(312),
	62:   uint16(313),
	63:   uint16(329),
	64:   uint16(330),
	65:   uint16(377),
	66:   uint16(383),
	67:   uint16(385),
	68:   uint16(387),
	69:   uint16(388),
	70:   uint16(391),
	71:   uint16(394),
	72:   uint16(396),
	73:   uint16(398),
	74:   uint16(402),
	75:   uint16(403),
	76:   uint16(405),
	77:   uint16(406),
	78:   uint16(409),
	79:   uint16(412),
	80:   uint16(414),
	81:   uint16(415),
	82:   uint16(417),
	83:   uint16(418),
	84:   uint16(423),
	85:   uint16(427),
	86:   uint16(428),
	87:   uint16(431),
	88:   uint16(434),
	89:   uint16(436),
	90:   uint16(437),
	91:   uint16(440),
	92:   uint16(442),
	93:   uint16(443),
	94:   uint16(444),
	95:   uint16(446),
	96:   uint16(448),
	97:   uint16(452),
	98:   uint16(453),
	99:   uint16(454),
	100:  uint16(455),
	101:  uint16(456),
	102:  uint16(457),
	103:  uint16(458),
	104:  uint16(459),
	105:  uint16(460),
	106:  uint16(461),
	107:  uint16(477),
	108:  uint16(478),
	109:  uint16(496),
	110:  uint16(497),
	111:  uint16(498),
	112:  uint16(499),
	113:  uint16(500),
	114:  uint16(503),
	115:  uint16(505),
	116:  uint16(506),
	117:  uint16(564),
	118:  uint16(570),
	119:  uint16(572),
	120:  uint16(573),
	121:  uint16(575),
	122:  uint16(577),
	123:  uint16(580),
	124:  uint16(583),
	125:  uint16(584),
	126:  uint16(592),
	127:  uint16(660),
	128:  uint16(661),
	129:  uint16(688),
	130:  uint16(706),
	131:  uint16(710),
	132:  uint16(722),
	133:  uint16(736),
	134:  uint16(741),
	135:  uint16(748),
	136:  uint16(749),
	137:  uint16(750),
	138:  uint16(751),
	139:  uint16(768),
	140:  uint16(880),
	141:  uint16(884),
	142:  uint16(885),
	143:  uint16(886),
	144:  uint16(890),
	145:  uint16(891),
	146:  uint16(894),
	147:  uint16(900),
	148:  uint16(902),
	149:  uint16(903),
	150:  uint16(904),
	151:  uint16(908),
	152:  uint16(910),
	153:  uint16(912),
	154:  uint16(913),
	155:  uint16(931),
	156:  uint16(940),
	157:  uint16(975),
	158:  uint16(977),
	159:  uint16(978),
	160:  uint16(981),
	161:  uint16(984),
	162:  uint16(1008),
	163:  uint16(1012),
	164:  uint16(1014),
	165:  uint16(1015),
	166:  uint16(1018),
	167:  uint16(1020),
	168:  uint16(1021),
	169:  uint16(1072),
	170:  uint16(1120),
	171:  uint16(1154),
	172:  uint16(1155),
	173:  uint16(1160),
	174:  uint16(1162),
	175:  uint16(1217),
	176:  uint16(1231),
	177:  uint16(1232),
	178:  uint16(1329),
	179:  uint16(1369),
	180:  uint16(1370),
	181:  uint16(1377),
	182:  uint16(1417),
	183:  uint16(1418),
	184:  uint16(1423),
	185:  uint16(1425),
	186:  uint16(1470),
	187:  uint16(1471),
	188:  uint16(1472),
	189:  uint16(1473),
	190:  uint16(1475),
	191:  uint16(1476),
	192:  uint16(1478),
	193:  uint16(1479),
	194:  uint16(1488),
	195:  uint16(1520),
	196:  uint16(1523),
	197:  uint16(1536),
	198:  uint16(1542),
	199:  uint16(1545),
	200:  uint16(1547),
	201:  uint16(1548),
	202:  uint16(1550),
	203:  uint16(1552),
	204:  uint16(1563),
	205:  uint16(1566),
	206:  uint16(1568),
	207:  uint16(1600),
	208:  uint16(1601),
	209:  uint16(1611),
	210:  uint16(1632),
	211:  uint16(1642),
	212:  uint16(1646),
	213:  uint16(1648),
	214:  uint16(1649),
	215:  uint16(1748),
	216:  uint16(1749),
	217:  uint16(1750),
	218:  uint16(1757),
	219:  uint16(1758),
	220:  uint16(1759),
	221:  uint16(1765),
	222:  uint16(1767),
	223:  uint16(1769),
	224:  uint16(1770),
	225:  uint16(1774),
	226:  uint16(1776),
	227:  uint16(1786),
	228:  uint16(1789),
	229:  uint16(1791),
	230:  uint16(1792),
	231:  uint16(1807),
	232:  uint16(1808),
	233:  uint16(1809),
	234:  uint16(1810),
	235:  uint16(1840),
	236:  uint16(1869),
	237:  uint16(1958),
	238:  uint16(1969),
	239:  uint16(1984),
	240:  uint16(1994),
	241:  uint16(2027),
	242:  uint16(2036),
	243:  uint16(2038),
	244:  uint16(2039),
	245:  uint16(2042),
	246:  uint16(2048),
	247:  uint16(2070),
	248:  uint16(2074),
	249:  uint16(2075),
	250:  uint16(2084),
	251:  uint16(2085),
	252:  uint16(2088),
	253:  uint16(2089),
	254:  uint16(2096),
	255:  uint16(2112),
	256:  uint16(2137),
	257:  uint16(2142),
	258:  uint16(2208),
	259:  uint16(2210),
	260:  uint16(2276),
	261:  uint16(2304),
	262:  uint16(2307),
	263:  uint16(2308),
	264:  uint16(2362),
	265:  uint16(2363),
	266:  uint16(2364),
	267:  uint16(2365),
	268:  uint16(2366),
	269:  uint16(2369),
	270:  uint16(2377),
	271:  uint16(2381),
	272:  uint16(2382),
	273:  uint16(2384),
	274:  uint16(2385),
	275:  uint16(2392),
	276:  uint16(2402),
	277:  uint16(2404),
	278:  uint16(2406),
	279:  uint16(2416),
	280:  uint16(2417),
	281:  uint16(2418),
	282:  uint16(2425),
	283:  uint16(2433),
	284:  uint16(2434),
	285:  uint16(2437),
	286:  uint16(2447),
	287:  uint16(2451),
	288:  uint16(2474),
	289:  uint16(2482),
	290:  uint16(2486),
	291:  uint16(2492),
	292:  uint16(2493),
	293:  uint16(2494),
	294:  uint16(2497),
	295:  uint16(2503),
	296:  uint16(2507),
	297:  uint16(2509),
	298:  uint16(2510),
	299:  uint16(2519),
	300:  uint16(2524),
	301:  uint16(2527),
	302:  uint16(2530),
	303:  uint16(2534),
	304:  uint16(2544),
	305:  uint16(2546),
	306:  uint16(2548),
	307:  uint16(2554),
	308:  uint16(2555),
	309:  uint16(2561),
	310:  uint16(2563),
	311:  uint16(2565),
	312:  uint16(2575),
	313:  uint16(2579),
	314:  uint16(2602),
	315:  uint16(2610),
	316:  uint16(2613),
	317:  uint16(2616),
	318:  uint16(2620),
	319:  uint16(2622),
	320:  uint16(2625),
	321:  uint16(2631),
	322:  uint16(2635),
	323:  uint16(2641),
	324:  uint16(2649),
	325:  uint16(2654),
	326:  uint16(2662),
	327:  uint16(2672),
	328:  uint16(2674),
	329:  uint16(2677),
	330:  uint16(2689),
	331:  uint16(2691),
	332:  uint16(2693),
	333:  uint16(2703),
	334:  uint16(2707),
	335:  uint16(2730),
	336:  uint16(2738),
	337:  uint16(2741),
	338:  uint16(2748),
	339:  uint16(2749),
	340:  uint16(2750),
	341:  uint16(2753),
	342:  uint16(2759),
	343:  uint16(2761),
	344:  uint16(2763),
	345:  uint16(2765),
	346:  uint16(2768),
	347:  uint16(2784),
	348:  uint16(2786),
	349:  uint16(2790),
	350:  uint16(2800),
	351:  uint16(2801),
	352:  uint16(2817),
	353:  uint16(2818),
	354:  uint16(2821),
	355:  uint16(2831),
	356:  uint16(2835),
	357:  uint16(2858),
	358:  uint16(2866),
	359:  uint16(2869),
	360:  uint16(2876),
	361:  uint16(2877),
	362:  uint16(2878),
	363:  uint16(2879),
	364:  uint16(2880),
	365:  uint16(2881),
	366:  uint16(2887),
	367:  uint16(2891),
	368:  uint16(2893),
	369:  uint16(2902),
	370:  uint16(2903),
	371:  uint16(2908),
	372:  uint16(2911),
	373:  uint16(2914),
	374:  uint16(2918),
	375:  uint16(2928),
	376:  uint16(2929),
	377:  uint16(2930),
	378:  uint16(2946),
	379:  uint16(2947),
	380:  uint16(2949),
	381:  uint16(2958),
	382:  uint16(2962),
	383:  uint16(2969),
	384:  uint16(2972),
	385:  uint16(2974),
	386:  uint16(2979),
	387:  uint16(2984),
	388:  uint16(2990),
	389:  uint16(3006),
	390:  uint16(3008),
	391:  uint16(3009),
	392:  uint16(3014),
	393:  uint16(3018),
	394:  uint16(3021),
	395:  uint16(3024),
	396:  uint16(3031),
	397:  uint16(3046),
	398:  uint16(3056),
	399:  uint16(3059),
	400:  uint16(3065),
	401:  uint16(3066),
	402:  uint16(3073),
	403:  uint16(3077),
	404:  uint16(3086),
	405:  uint16(3090),
	406:  uint16(3114),
	407:  uint16(3125),
	408:  uint16(3133),
	409:  uint16(3134),
	410:  uint16(3137),
	411:  uint16(3142),
	412:  uint16(3146),
	413:  uint16(3157),
	414:  uint16(3160),
	415:  uint16(3168),
	416:  uint16(3170),
	417:  uint16(3174),
	418:  uint16(3192),
	419:  uint16(3199),
	420:  uint16(3202),
	421:  uint16(3205),
	422:  uint16(3214),
	423:  uint16(3218),
	424:  uint16(3242),
	425:  uint16(3253),
	426:  uint16(3260),
	427:  uint16(3261),
	428:  uint16(3262),
	429:  uint16(3263),
	430:  uint16(3264),
	431:  uint16(3270),
	432:  uint16(3271),
	433:  uint16(3274),
	434:  uint16(3276),
	435:  uint16(3285),
	436:  uint16(3294),
	437:  uint16(3296),
	438:  uint16(3298),
	439:  uint16(3302),
	440:  uint16(3313),
	441:  uint16(3330),
	442:  uint16(3333),
	443:  uint16(3342),
	444:  uint16(3346),
	445:  uint16(3389),
	446:  uint16(3390),
	447:  uint16(3393),
	448:  uint16(3398),
	449:  uint16(3402),
	450:  uint16(3405),
	451:  uint16(3406),
	452:  uint16(3415),
	453:  uint16(3424),
	454:  uint16(3426),
	455:  uint16(3430),
	456:  uint16(3440),
	457:  uint16(3449),
	458:  uint16(3450),
	459:  uint16(3458),
	460:  uint16(3461),
	461:  uint16(3482),
	462:  uint16(3507),
	463:  uint16(3517),
	464:  uint16(3520),
	465:  uint16(3530),
	466:  uint16(3535),
	467:  uint16(3538),
	468:  uint16(3542),
	469:  uint16(3544),
	470:  uint16(3570),
	471:  uint16(3572),
	472:  uint16(3585),
	473:  uint16(3633),
	474:  uint16(3634),
	475:  uint16(3636),
	476:  uint16(3647),
	477:  uint16(3648),
	478:  uint16(3654),
	479:  uint16(3655),
	480:  uint16(3663),
	481:  uint16(3664),
	482:  uint16(3674),
	483:  uint16(3713),
	484:  uint16(3716),
	485:  uint16(3719),
	486:  uint16(3722),
	487:  uint16(3725),
	488:  uint16(3732),
	489:  uint16(3737),
	490:  uint16(3745),
	491:  uint16(3749),
	492:  uint16(3751),
	493:  uint16(3754),
	494:  uint16(3757),
	495:  uint16(3761),
	496:  uint16(3762),
	497:  uint16(3764),
	498:  uint16(3771),
	499:  uint16(3773),
	500:  uint16(3776),
	501:  uint16(3782),
	502:  uint16(3784),
	503:  uint16(3792),
	504:  uint16(3804),
	505:  uint16(3840),
	506:  uint16(3841),
	507:  uint16(3844),
	508:  uint16(3859),
	509:  uint16(3860),
	510:  uint16(3861),
	511:  uint16(3864),
	512:  uint16(3866),
	513:  uint16(3872),
	514:  uint16(3882),
	515:  uint16(3892),
	516:  uint16(3893),
	517:  uint16(3894),
	518:  uint16(3895),
	519:  uint16(3896),
	520:  uint16(3897),
	521:  uint16(3898),
	522:  uint16(3899),
	523:  uint16(3900),
	524:  uint16(3901),
	525:  uint16(3902),
	526:  uint16(3904),
	527:  uint16(3913),
	528:  uint16(3953),
	529:  uint16(3967),
	530:  uint16(3968),
	531:  uint16(3973),
	532:  uint16(3974),
	533:  uint16(3976),
	534:  uint16(3981),
	535:  uint16(3993),
	536:  uint16(4030),
	537:  uint16(4038),
	538:  uint16(4039),
	539:  uint16(4046),
	540:  uint16(4048),
	541:  uint16(4053),
	542:  uint16(4057),
	543:  uint16(4096),
	544:  uint16(4139),
	545:  uint16(4141),
	546:  uint16(4145),
	547:  uint16(4146),
	548:  uint16(4152),
	549:  uint16(4153),
	550:  uint16(4155),
	551:  uint16(4157),
	552:  uint16(4159),
	553:  uint16(4160),
	554:  uint16(4170),
	555:  uint16(4176),
	556:  uint16(4182),
	557:  uint16(4184),
	558:  uint16(4186),
	559:  uint16(4190),
	560:  uint16(4193),
	561:  uint16(4194),
	562:  uint16(4197),
	563:  uint16(4199),
	564:  uint16(4206),
	565:  uint16(4209),
	566:  uint16(4213),
	567:  uint16(4226),
	568:  uint16(4227),
	569:  uint16(4229),
	570:  uint16(4231),
	571:  uint16(4237),
	572:  uint16(4238),
	573:  uint16(4239),
	574:  uint16(4240),
	575:  uint16(4250),
	576:  uint16(4253),
	577:  uint16(4254),
	578:  uint16(4256),
	579:  uint16(4295),
	580:  uint16(4301),
	581:  uint16(4304),
	582:  uint16(4347),
	583:  uint16(4348),
	584:  uint16(4349),
	585:  uint16(4682),
	586:  uint16(4688),
	587:  uint16(4696),
	588:  uint16(4698),
	589:  uint16(4704),
	590:  uint16(4746),
	591:  uint16(4752),
	592:  uint16(4786),
	593:  uint16(4792),
	594:  uint16(4800),
	595:  uint16(4802),
	596:  uint16(4808),
	597:  uint16(4824),
	598:  uint16(4882),
	599:  uint16(4888),
	600:  uint16(4957),
	601:  uint16(4960),
	602:  uint16(4969),
	603:  uint16(4992),
	604:  uint16(5008),
	605:  uint16(5024),
	606:  uint16(5120),
	607:  uint16(5121),
	608:  uint16(5741),
	609:  uint16(5743),
	610:  uint16(5760),
	611:  uint16(5761),
	612:  uint16(5787),
	613:  uint16(5788),
	614:  uint16(5792),
	615:  uint16(5867),
	616:  uint16(5870),
	617:  uint16(5888),
	618:  uint16(5902),
	619:  uint16(5906),
	620:  uint16(5920),
	621:  uint16(5938),
	622:  uint16(5941),
	623:  uint16(5952),
	624:  uint16(5970),
	625:  uint16(5984),
	626:  uint16(5998),
	627:  uint16(6002),
	628:  uint16(6016),
	629:  uint16(6068),
	630:  uint16(6070),
	631:  uint16(6071),
	632:  uint16(6078),
	633:  uint16(6086),
	634:  uint16(6087),
	635:  uint16(6089),
	636:  uint16(6100),
	637:  uint16(6103),
	638:  uint16(6104),
	639:  uint16(6107),
	640:  uint16(6108),
	641:  uint16(6109),
	642:  uint16(6112),
	643:  uint16(6128),
	644:  uint16(6144),
	645:  uint16(6150),
	646:  uint16(6151),
	647:  uint16(6155),
	648:  uint16(6158),
	649:  uint16(6160),
	650:  uint16(6176),
	651:  uint16(6211),
	652:  uint16(6212),
	653:  uint16(6272),
	654:  uint16(6313),
	655:  uint16(6314),
	656:  uint16(6320),
	657:  uint16(6400),
	658:  uint16(6432),
	659:  uint16(6435),
	660:  uint16(6439),
	661:  uint16(6441),
	662:  uint16(6448),
	663:  uint16(6450),
	664:  uint16(6451),
	665:  uint16(6457),
	666:  uint16(6464),
	667:  uint16(6468),
	668:  uint16(6470),
	669:  uint16(6480),
	670:  uint16(6512),
	671:  uint16(6528),
	672:  uint16(6576),
	673:  uint16(6593),
	674:  uint16(6600),
	675:  uint16(6608),
	676:  uint16(6618),
	677:  uint16(6622),
	678:  uint16(6656),
	679:  uint16(6679),
	680:  uint16(6681),
	681:  uint16(6686),
	682:  uint16(6688),
	683:  uint16(6741),
	684:  uint16(6742),
	685:  uint16(6743),
	686:  uint16(6744),
	687:  uint16(6752),
	688:  uint16(6753),
	689:  uint16(6754),
	690:  uint16(6755),
	691:  uint16(6757),
	692:  uint16(6765),
	693:  uint16(6771),
	694:  uint16(6783),
	695:  uint16(6784),
	696:  uint16(6800),
	697:  uint16(6816),
	698:  uint16(6823),
	699:  uint16(6824),
	700:  uint16(6912),
	701:  uint16(6916),
	702:  uint16(6917),
	703:  uint16(6964),
	704:  uint16(6965),
	705:  uint16(6966),
	706:  uint16(6971),
	707:  uint16(6972),
	708:  uint16(6973),
	709:  uint16(6978),
	710:  uint16(6979),
	711:  uint16(6981),
	712:  uint16(6992),
	713:  uint16(7002),
	714:  uint16(7009),
	715:  uint16(7019),
	716:  uint16(7028),
	717:  uint16(7040),
	718:  uint16(7042),
	719:  uint16(7043),
	720:  uint16(7073),
	721:  uint16(7074),
	722:  uint16(7078),
	723:  uint16(7080),
	724:  uint16(7082),
	725:  uint16(7083),
	726:  uint16(7084),
	727:  uint16(7086),
	728:  uint16(7088),
	729:  uint16(7098),
	730:  uint16(7142),
	731:  uint16(7143),
	732:  uint16(7144),
	733:  uint16(7146),
	734:  uint16(7149),
	735:  uint16(7150),
	736:  uint16(7151),
	737:  uint16(7154),
	738:  uint16(7164),
	739:  uint16(7168),
	740:  uint16(7204),
	741:  uint16(7212),
	742:  uint16(7220),
	743:  uint16(7222),
	744:  uint16(7227),
	745:  uint16(7232),
	746:  uint16(7245),
	747:  uint16(7248),
	748:  uint16(7258),
	749:  uint16(7288),
	750:  uint16(7294),
	751:  uint16(7360),
	752:  uint16(7376),
	753:  uint16(7379),
	754:  uint16(7380),
	755:  uint16(7393),
	756:  uint16(7394),
	757:  uint16(7401),
	758:  uint16(7405),
	759:  uint16(7406),
	760:  uint16(7410),
	761:  uint16(7412),
	762:  uint16(7413),
	763:  uint16(7424),
	764:  uint16(7468),
	765:  uint16(7531),
	766:  uint16(7544),
	767:  uint16(7545),
	768:  uint16(7579),
	769:  uint16(7616),
	770:  uint16(7676),
	771:  uint16(7680),
	772:  uint16(7830),
	773:  uint16(7838),
	774:  uint16(7936),
	775:  uint16(7944),
	776:  uint16(7952),
	777:  uint16(7960),
	778:  uint16(7968),
	779:  uint16(7976),
	780:  uint16(7984),
	781:  uint16(7992),
	782:  uint16(8000),
	783:  uint16(8008),
	784:  uint16(8016),
	785:  uint16(8025),
	786:  uint16(8027),
	787:  uint16(8029),
	788:  uint16(8031),
	789:  uint16(8033),
	790:  uint16(8040),
	791:  uint16(8048),
	792:  uint16(8064),
	793:  uint16(8072),
	794:  uint16(8080),
	795:  uint16(8088),
	796:  uint16(8096),
	797:  uint16(8104),
	798:  uint16(8112),
	799:  uint16(8118),
	800:  uint16(8120),
	801:  uint16(8124),
	802:  uint16(8125),
	803:  uint16(8126),
	804:  uint16(8127),
	805:  uint16(8130),
	806:  uint16(8134),
	807:  uint16(8136),
	808:  uint16(8140),
	809:  uint16(8141),
	810:  uint16(8144),
	811:  uint16(8150),
	812:  uint16(8152),
	813:  uint16(8157),
	814:  uint16(8160),
	815:  uint16(8168),
	816:  uint16(8173),
	817:  uint16(8178),
	818:  uint16(8182),
	819:  uint16(8184),
	820:  uint16(8188),
	821:  uint16(8189),
	822:  uint16(8192),
	823:  uint16(8203),
	824:  uint16(8208),
	825:  uint16(8214),
	826:  uint16(8216),
	827:  uint16(8217),
	828:  uint16(8218),
	829:  uint16(8219),
	830:  uint16(8221),
	831:  uint16(8222),
	832:  uint16(8223),
	833:  uint16(8224),
	834:  uint16(8232),
	835:  uint16(8233),
	836:  uint16(8234),
	837:  uint16(8239),
	838:  uint16(8240),
	839:  uint16(8249),
	840:  uint16(8250),
	841:  uint16(8251),
	842:  uint16(8255),
	843:  uint16(8257),
	844:  uint16(8260),
	845:  uint16(8261),
	846:  uint16(8262),
	847:  uint16(8263),
	848:  uint16(8274),
	849:  uint16(8275),
	850:  uint16(8276),
	851:  uint16(8277),
	852:  uint16(8287),
	853:  uint16(8288),
	854:  uint16(8298),
	855:  uint16(8304),
	856:  uint16(8305),
	857:  uint16(8308),
	858:  uint16(8314),
	859:  uint16(8317),
	860:  uint16(8318),
	861:  uint16(8319),
	862:  uint16(8320),
	863:  uint16(8330),
	864:  uint16(8333),
	865:  uint16(8334),
	866:  uint16(8336),
	867:  uint16(8352),
	868:  uint16(8400),
	869:  uint16(8413),
	870:  uint16(8417),
	871:  uint16(8418),
	872:  uint16(8421),
	873:  uint16(8448),
	874:  uint16(8450),
	875:  uint16(8451),
	876:  uint16(8455),
	877:  uint16(8456),
	878:  uint16(8458),
	879:  uint16(8459),
	880:  uint16(8462),
	881:  uint16(8464),
	882:  uint16(8467),
	883:  uint16(8468),
	884:  uint16(8469),
	885:  uint16(8470),
	886:  uint16(8472),
	887:  uint16(8473),
	888:  uint16(8478),
	889:  uint16(8484),
	890:  uint16(8485),
	891:  uint16(8486),
	892:  uint16(8487),
	893:  uint16(8488),
	894:  uint16(8489),
	895:  uint16(8490),
	896:  uint16(8494),
	897:  uint16(8495),
	898:  uint16(8496),
	899:  uint16(8500),
	900:  uint16(8501),
	901:  uint16(8505),
	902:  uint16(8506),
	903:  uint16(8508),
	904:  uint16(8510),
	905:  uint16(8512),
	906:  uint16(8517),
	907:  uint16(8519),
	908:  uint16(8522),
	909:  uint16(8523),
	910:  uint16(8524),
	911:  uint16(8526),
	912:  uint16(8527),
	913:  uint16(8528),
	914:  uint16(8544),
	915:  uint16(8579),
	916:  uint16(8581),
	917:  uint16(8585),
	918:  uint16(8592),
	919:  uint16(8597),
	920:  uint16(8602),
	921:  uint16(8604),
	922:  uint16(8608),
	923:  uint16(8609),
	924:  uint16(8611),
	925:  uint16(8612),
	926:  uint16(8614),
	927:  uint16(8615),
	928:  uint16(8622),
	929:  uint16(8623),
	930:  uint16(8654),
	931:  uint16(8656),
	932:  uint16(8658),
	933:  uint16(8659),
	934:  uint16(8660),
	935:  uint16(8661),
	936:  uint16(8692),
	937:  uint16(8960),
	938:  uint16(8968),
	939:  uint16(8972),
	940:  uint16(8992),
	941:  uint16(8994),
	942:  uint16(9001),
	943:  uint16(9002),
	944:  uint16(9003),
	945:  uint16(9084),
	946:  uint16(9085),
	947:  uint16(9115),
	948:  uint16(9140),
	949:  uint16(9180),
	950:  uint16(9186),
	951:  uint16(9216),
	952:  uint16(9280),
	953:  uint16(9312),
	954:  uint16(9372),
	955:  uint16(9450),
	956:  uint16(9472),
	957:  uint16(9655),
	958:  uint16(9656),
	959:  uint16(9665),
	960:  uint16(9666),
	961:  uint16(9720),
	962:  uint16(9728),
	963:  uint16(9839),
	964:  uint16(9840),
	965:  uint16(9985),
	966:  uint16(10088),
	967:  uint16(10089),
	968:  uint16(10090),
	969:  uint16(10091),
	970:  uint16(10092),
	971:  uint16(10093),
	972:  uint16(10094),
	973:  uint16(10095),
	974:  uint16(10096),
	975:  uint16(10097),
	976:  uint16(10098),
	977:  uint16(10099),
	978:  uint16(10100),
	979:  uint16(10101),
	980:  uint16(10102),
	981:  uint16(10132),
	982:  uint16(10176),
	983:  uint16(10181),
	984:  uint16(10182),
	985:  uint16(10183),
	986:  uint16(10214),
	987:  uint16(10215),
	988:  uint16(10216),
	989:  uint16(10217),
	990:  uint16(10218),
	991:  uint16(10219),
	992:  uint16(10220),
	993:  uint16(10221),
	994:  uint16(10222),
	995:  uint16(10223),
	996:  uint16(10224),
	997:  uint16(10240),
	998:  uint16(10496),
	999:  uint16(10627),
	1000: uint16(10628),
	1001: uint16(10629),
	1002: uint16(10630),
	1003: uint16(10631),
	1004: uint16(10632),
	1005: uint16(10633),
	1006: uint16(10634),
	1007: uint16(10635),
	1008: uint16(10636),
	1009: uint16(10637),
	1010: uint16(10638),
	1011: uint16(10639),
	1012: uint16(10640),
	1013: uint16(10641),
	1014: uint16(10642),
	1015: uint16(10643),
	1016: uint16(10644),
	1017: uint16(10645),
	1018: uint16(10646),
	1019: uint16(10647),
	1020: uint16(10648),
	1021: uint16(10649),
	1022: uint16(10712),
	1023: uint16(10713),
	1024: uint16(10714),
	1025: uint16(10715),
	1026: uint16(10716),
	1027: uint16(10748),
	1028: uint16(10749),
	1029: uint16(10750),
	1030: uint16(11008),
	1031: uint16(11056),
	1032: uint16(11077),
	1033: uint16(11079),
	1034: uint16(11088),
	1035: uint16(11264),
	1036: uint16(11312),
	1037: uint16(11360),
	1038: uint16(11363),
	1039: uint16(11365),
	1040: uint16(11367),
	1041: uint16(11374),
	1042: uint16(11377),
	1043: uint16(11378),
	1044: uint16(11380),
	1045: uint16(11381),
	1046: uint16(11383),
	1047: uint16(11388),
	1048: uint16(11390),
	1049: uint16(11393),
	1050: uint16(11394),
	1051: uint16(11492),
	1052: uint16(11493),
	1053: uint16(11499),
	1054: uint16(11503),
	1055: uint16(11506),
	1056: uint16(11513),
	1057: uint16(11517),
	1058: uint16(11518),
	1059: uint16(11520),
	1060: uint16(11559),
	1061: uint16(11565),
	1062: uint16(11568),
	1063: uint16(11631),
	1064: uint16(11632),
	1065: uint16(11647),
	1066: uint16(11648),
	1067: uint16(11680),
	1068: uint16(11688),
	1069: uint16(11696),
	1070: uint16(11704),
	1071: uint16(11712),
	1072: uint16(11720),
	1073: uint16(11728),
	1074: uint16(11736),
	1075: uint16(11744),
	1076: uint16(11776),
	1077: uint16(11778),
	1078: uint16(11779),
	1079: uint16(11780),
	1080: uint16(11781),
	1081: uint16(11782),
	1082: uint16(11785),
	1083: uint16(11786),
	1084: uint16(11787),
	1085: uint16(11788),
	1086: uint16(11789),
	1087: uint16(11790),
	1088: uint16(11799),
	1089: uint16(11800),
	1090: uint16(11802),
	1091: uint16(11803),
	1092: uint16(11804),
	1093: uint16(11805),
	1094: uint16(11806),
	1095: uint16(11808),
	1096: uint16(11809),
	1097: uint16(11810),
	1098: uint16(11811),
	1099: uint16(11812),
	1100: uint16(11813),
	1101: uint16(11814),
	1102: uint16(11815),
	1103: uint16(11816),
	1104: uint16(11817),
	1105: uint16(11818),
	1106: uint16(11823),
	1107: uint16(11824),
	1108: uint16(11834),
	1109: uint16(11904),
	1110: uint16(11931),
	1111: uint16(12032),
	1112: uint16(12272),
	1113: uint16(12288),
	1114: uint16(12289),
	1115: uint16(12292),
	1116: uint16(12293),
	1117: uint16(12294),
	1118: uint16(12295),
	1119: uint16(12296),
	1120: uint16(12297),
	1121: uint16(12298),
	1122: uint16(12299),
	1123: uint16(12300),
	1124: uint16(12301),
	1125: uint16(12302),
	1126: uint16(12303),
	1127: uint16(12304),
	1128: uint16(12305),
	1129: uint16(12306),
	1130: uint16(12308),
	1131: uint16(12309),
	1132: uint16(12310),
	1133: uint16(12311),
	1134: uint16(12312),
	1135: uint16(12313),
	1136: uint16(12314),
	1137: uint16(12315),
	1138: uint16(12316),
	1139: uint16(12317),
	1140: uint16(12318),
	1141: uint16(12320),
	1142: uint16(12321),
	1143: uint16(12330),
	1144: uint16(12334),
	1145: uint16(12336),
	1146: uint16(12337),
	1147: uint16(12342),
	1148: uint16(12344),
	1149: uint16(12347),
	1150: uint16(12348),
	1151: uint16(12349),
	1152: uint16(12350),
	1153: uint16(12353),
	1154: uint16(12441),
	1155: uint16(12443),
	1156: uint16(12445),
	1157: uint16(12447),
	1158: uint16(12448),
	1159: uint16(12449),
	1160: uint16(12539),
	1161: uint16(12540),
	1162: uint16(12543),
	1163: uint16(12549),
	1164: uint16(12593),
	1165: uint16(12688),
	1166: uint16(12690),
	1167: uint16(12694),
	1168: uint16(12704),
	1169: uint16(12736),
	1170: uint16(12784),
	1171: uint16(12800),
	1172: uint16(12832),
	1173: uint16(12842),
	1174: uint16(12872),
	1175: uint16(12880),
	1176: uint16(12881),
	1177: uint16(12896),
	1178: uint16(12928),
	1179: uint16(12938),
	1180: uint16(12977),
	1181: uint16(12992),
	1182: uint16(13056),
	1183: uint16(13312),
	1184: uint16(19893),
	1185: uint16(19904),
	1186: uint16(19968),
	1187: uint16(40908),
	1188: uint16(40960),
	1189: uint16(40981),
	1190: uint16(40982),
	1191: uint16(42128),
	1192: uint16(42192),
	1193: uint16(42232),
	1194: uint16(42238),
	1195: uint16(42240),
	1196: uint16(42508),
	1197: uint16(42509),
	1198: uint16(42512),
	1199: uint16(42528),
	1200: uint16(42538),
	1201: uint16(42560),
	1202: uint16(42606),
	1203: uint16(42607),
	1204: uint16(42608),
	1205: uint16(42611),
	1206: uint16(42612),
	1207: uint16(42622),
	1208: uint16(42623),
	1209: uint16(42624),
	1210: uint16(42655),
	1211: uint16(42656),
	1212: uint16(42726),
	1213: uint16(42736),
	1214: uint16(42738),
	1215: uint16(42752),
	1216: uint16(42775),
	1217: uint16(42784),
	1218: uint16(42786),
	1219: uint16(42800),
	1220: uint16(42802),
	1221: uint16(42864),
	1222: uint16(42865),
	1223: uint16(42873),
	1224: uint16(42878),
	1225: uint16(42888),
	1226: uint16(42889),
	1227: uint16(42891),
	1228: uint16(42896),
	1229: uint16(42912),
	1230: uint16(43000),
	1231: uint16(43002),
	1232: uint16(43003),
	1233: uint16(43010),
	1234: uint16(43011),
	1235: uint16(43014),
	1236: uint16(43015),
	1237: uint16(43019),
	1238: uint16(43020),
	1239: uint16(43043),
	1240: uint16(43045),
	1241: uint16(43047),
	1242: uint16(43048),
	1243: uint16(43056),
	1244: uint16(43062),
	1245: uint16(43064),
	1246: uint16(43065),
	1247: uint16(43072),
	1248: uint16(43124),
	1249: uint16(43136),
	1250: uint16(43138),
	1251: uint16(43188),
	1252: uint16(43204),
	1253: uint16(43214),
	1254: uint16(43216),
	1255: uint16(43232),
	1256: uint16(43250),
	1257: uint16(43256),
	1258: uint16(43259),
	1259: uint16(43264),
	1260: uint16(43274),
	1261: uint16(43302),
	1262: uint16(43310),
	1263: uint16(43312),
	1264: uint16(43335),
	1265: uint16(43346),
	1266: uint16(43359),
	1267: uint16(43360),
	1268: uint16(43392),
	1269: uint16(43395),
	1270: uint16(43396),
	1271: uint16(43443),
	1272: uint16(43444),
	1273: uint16(43446),
	1274: uint16(43450),
	1275: uint16(43452),
	1276: uint16(43453),
	1277: uint16(43457),
	1278: uint16(43471),
	1279: uint16(43472),
	1280: uint16(43486),
	1281: uint16(43520),
	1282: uint16(43561),
	1283: uint16(43567),
	1284: uint16(43569),
	1285: uint16(43571),
	1286: uint16(43573),
	1287: uint16(43584),
	1288: uint16(43587),
	1289: uint16(43588),
	1290: uint16(43596),
	1291: uint16(43597),
	1292: uint16(43600),
	1293: uint16(43612),
	1294: uint16(43616),
	1295: uint16(43632),
	1296: uint16(43633),
	1297: uint16(43639),
	1298: uint16(43642),
	1299: uint16(43643),
	1300: uint16(43648),
	1301: uint16(43696),
	1302: uint16(43697),
	1303: uint16(43698),
	1304: uint16(43701),
	1305: uint16(43703),
	1306: uint16(43705),
	1307: uint16(43710),
	1308: uint16(43712),
	1309: uint16(43713),
	1310: uint16(43714),
	1311: uint16(43739),
	1312: uint16(43741),
	1313: uint16(43742),
	1314: uint16(43744),
	1315: uint16(43755),
	1316: uint16(43756),
	1317: uint16(43758),
	1318: uint16(43760),
	1319: uint16(43762),
	1320: uint16(43763),
	1321: uint16(43765),
	1322: uint16(43766),
	1323: uint16(43777),
	1324: uint16(43785),
	1325: uint16(43793),
	1326: uint16(43808),
	1327: uint16(43816),
	1328: uint16(43968),
	1329: uint16(44003),
	1330: uint16(44005),
	1331: uint16(44006),
	1332: uint16(44008),
	1333: uint16(44009),
	1334: uint16(44011),
	1335: uint16(44012),
	1336: uint16(44013),
	1337: uint16(44016),
	1338: uint16(44032),
	1339: uint16(55203),
	1340: uint16(55216),
	1341: uint16(55243),
	1342: uint16(55296),
	1343: uint16(56191),
	1344: uint16(56319),
	1345: uint16(57343),
	1346: uint16(57344),
	1347: uint16(63743),
	1348: uint16(63744),
	1349: uint16(64112),
	1350: uint16(64256),
	1351: uint16(64275),
	1352: uint16(64285),
	1353: uint16(64286),
	1354: uint16(64287),
	1355: uint16(64297),
	1356: uint16(64298),
	1357: uint16(64312),
	1358: uint16(64318),
	1359: uint16(64320),
	1360: uint16(64323),
	1361: uint16(64326),
	1362: uint16(64434),
	1363: uint16(64467),
	1364: uint16(64830),
	1365: uint16(64831),
	1366: uint16(64848),
	1367: uint16(64914),
	1368: uint16(65008),
	1369: uint16(65020),
	1370: uint16(65021),
	1371: uint16(65024),
	1372: uint16(65040),
	1373: uint16(65047),
	1374: uint16(65048),
	1375: uint16(65049),
	1376: uint16(65056),
	1377: uint16(65072),
	1378: uint16(65073),
	1379: uint16(65075),
	1380: uint16(65077),
	1381: uint16(65078),
	1382: uint16(65079),
	1383: uint16(65080),
	1384: uint16(65081),
	1385: uint16(65082),
	1386: uint16(65083),
	1387: uint16(65084),
	1388: uint16(65085),
	1389: uint16(65086),
	1390: uint16(65087),
	1391: uint16(65088),
	1392: uint16(65089),
	1393: uint16(65090),
	1394: uint16(65091),
	1395: uint16(65092),
	1396: uint16(65093),
	1397: uint16(65095),
	1398: uint16(65096),
	1399: uint16(65097),
	1400: uint16(65101),
	1401: uint16(65104),
	1402: uint16(65108),
	1403: uint16(65112),
	1404: uint16(65113),
	1405: uint16(65114),
	1406: uint16(65115),
	1407: uint16(65116),
	1408: uint16(65117),
	1409: uint16(65118),
	1410: uint16(65119),
	1411: uint16(65122),
	1412: uint16(65123),
	1413: uint16(65124),
	1414: uint16(65128),
	1415: uint16(65129),
	1416: uint16(65130),
	1417: uint16(65136),
	1418: uint16(65142),
	1419: uint16(65279),
	1420: uint16(65281),
	1421: uint16(65284),
	1422: uint16(65285),
	1423: uint16(65288),
	1424: uint16(65289),
	1425: uint16(65290),
	1426: uint16(65291),
	1427: uint16(65292),
	1428: uint16(65293),
	1429: uint16(65294),
	1430: uint16(65296),
	1431: uint16(65306),
	1432: uint16(65308),
	1433: uint16(65311),
	1434: uint16(65313),
	1435: uint16(65339),
	1436: uint16(65340),
	1437: uint16(65341),
	1438: uint16(65342),
	1439: uint16(65343),
	1440: uint16(65344),
	1441: uint16(65345),
	1442: uint16(65371),
	1443: uint16(65372),
	1444: uint16(65373),
	1445: uint16(65374),
	1446: uint16(65375),
	1447: uint16(65376),
	1448: uint16(65377),
	1449: uint16(65378),
	1450: uint16(65379),
	1451: uint16(65380),
	1452: uint16(65382),
	1453: uint16(65392),
	1454: uint16(65393),
	1455: uint16(65438),
	1456: uint16(65440),
	1457: uint16(65474),
	1458: uint16(65482),
	1459: uint16(65490),
	1460: uint16(65498),
	1461: uint16(65504),
	1462: uint16(65506),
	1463: uint16(65507),
	1464: uint16(65508),
	1465: uint16(65509),
	1466: uint16(65512),
	1467: uint16(65513),
	1468: uint16(65517),
	1469: uint16(65529),
	1470: uint16(65532),
	1472: uint16(13),
	1473: uint16(40),
	1474: uint16(60),
	1475: uint16(63),
	1476: uint16(80),
	1477: uint16(128),
	1478: uint16(256),
	1479: uint16(263),
	1480: uint16(311),
	1481: uint16(320),
	1482: uint16(373),
	1483: uint16(377),
	1484: uint16(394),
	1485: uint16(400),
	1486: uint16(464),
	1487: uint16(509),
	1488: uint16(640),
	1489: uint16(672),
	1490: uint16(768),
	1491: uint16(800),
	1492: uint16(816),
	1493: uint16(833),
	1494: uint16(834),
	1495: uint16(842),
	1496: uint16(896),
	1497: uint16(927),
	1498: uint16(928),
	1499: uint16(968),
	1500: uint16(976),
	1501: uint16(977),
	1502: uint16(1024),
	1503: uint16(1064),
	1504: uint16(1104),
	1505: uint16(1184),
	1506: uint16(2048),
	1507: uint16(2056),
	1508: uint16(2058),
	1509: uint16(2103),
	1510: uint16(2108),
	1511: uint16(2111),
	1512: uint16(2135),
	1513: uint16(2136),
	1514: uint16(2304),
	1515: uint16(2326),
	1516: uint16(2335),
	1517: uint16(2336),
	1518: uint16(2367),
	1519: uint16(2432),
	1520: uint16(2494),
	1521: uint16(2560),
	1522: uint16(2561),
	1523: uint16(2565),
	1524: uint16(2572),
	1525: uint16(2576),
	1526: uint16(2581),
	1527: uint16(2585),
	1528: uint16(2616),
	1529: uint16(2623),
	1530: uint16(2624),
	1531: uint16(2640),
	1532: uint16(2656),
	1533: uint16(2685),
	1534: uint16(2687),
	1535: uint16(2816),
	1536: uint16(2873),
	1537: uint16(2880),
	1538: uint16(2904),
	1539: uint16(2912),
	1540: uint16(2936),
	1541: uint16(3072),
	1542: uint16(3680),
	1543: uint16(4096),
	1544: uint16(4097),
	1545: uint16(4098),
	1546: uint16(4099),
	1547: uint16(4152),
	1548: uint16(4167),
	1549: uint16(4178),
	1550: uint16(4198),
	1551: uint16(4224),
	1552: uint16(4226),
	1553: uint16(4227),
	1554: uint16(4272),
	1555: uint16(4275),
	1556: uint16(4279),
	1557: uint16(4281),
	1558: uint16(4283),
	1559: uint16(4285),
	1560: uint16(4286),
	1561: uint16(4304),
	1562: uint16(4336),
	1563: uint16(4352),
	1564: uint16(4355),
	1565: uint16(4391),
	1566: uint16(4396),
	1567: uint16(4397),
	1568: uint16(4406),
	1569: uint16(4416),
	1570: uint16(4480),
	1571: uint16(4482),
	1572: uint16(4483),
	1573: uint16(4531),
	1574: uint16(4534),
	1575: uint16(4543),
	1576: uint16(4545),
	1577: uint16(4549),
	1578: uint16(4560),
	1579: uint16(5760),
	1580: uint16(5803),
	1581: uint16(5804),
	1582: uint16(5805),
	1583: uint16(5806),
	1584: uint16(5808),
	1585: uint16(5814),
	1586: uint16(5815),
	1587: uint16(5824),
	1588: uint16(8192),
	1589: uint16(9216),
	1590: uint16(9328),
	1591: uint16(12288),
	1592: uint16(26624),
	1593: uint16(28416),
	1594: uint16(28496),
	1595: uint16(28497),
	1596: uint16(28559),
	1597: uint16(28563),
	1598: uint16(45056),
	1599: uint16(53248),
	1600: uint16(53504),
	1601: uint16(53545),
	1602: uint16(53605),
	1603: uint16(53607),
	1604: uint16(53610),
	1605: uint16(53613),
	1606: uint16(53619),
	1607: uint16(53627),
	1608: uint16(53635),
	1609: uint16(53637),
	1610: uint16(53644),
	1611: uint16(53674),
	1612: uint16(53678),
	1613: uint16(53760),
	1614: uint16(53826),
	1615: uint16(53829),
	1616: uint16(54016),
	1617: uint16(54112),
	1618: uint16(54272),
	1619: uint16(54298),
	1620: uint16(54324),
	1621: uint16(54350),
	1622: uint16(54358),
	1623: uint16(54376),
	1624: uint16(54402),
	1625: uint16(54428),
	1626: uint16(54430),
	1627: uint16(54434),
	1628: uint16(54437),
	1629: uint16(54441),
	1630: uint16(54446),
	1631: uint16(54454),
	1632: uint16(54459),
	1633: uint16(54461),
	1634: uint16(54469),
	1635: uint16(54480),
	1636: uint16(54506),
	1637: uint16(54532),
	1638: uint16(54535),
	1639: uint16(54541),
	1640: uint16(54550),
	1641: uint16(54558),
	1642: uint16(54584),
	1643: uint16(54587),
	1644: uint16(54592),
	1645: uint16(54598),
	1646: uint16(54602),
	1647: uint16(54610),
	1648: uint16(54636),
	1649: uint16(54662),
	1650: uint16(54688),
	1651: uint16(54714),
	1652: uint16(54740),
	1653: uint16(54766),
	1654: uint16(54792),
	1655: uint16(54818),
	1656: uint16(54844),
	1657: uint16(54870),
	1658: uint16(54896),
	1659: uint16(54922),
	1660: uint16(54952),
	1661: uint16(54977),
	1662: uint16(54978),
	1663: uint16(55003),
	1664: uint16(55004),
	1665: uint16(55010),
	1666: uint16(55035),
	1667: uint16(55036),
	1668: uint16(55061),
	1669: uint16(55062),
	1670: uint16(55068),
	1671: uint16(55093),
	1672: uint16(55094),
	1673: uint16(55119),
	1674: uint16(55120),
	1675: uint16(55126),
	1676: uint16(55151),
	1677: uint16(55152),
	1678: uint16(55177),
	1679: uint16(55178),
	1680: uint16(55184),
	1681: uint16(55209),
	1682: uint16(55210),
	1683: uint16(55235),
	1684: uint16(55236),
	1685: uint16(55242),
	1686: uint16(55246),
	1687: uint16(60928),
	1688: uint16(60933),
	1689: uint16(60961),
	1690: uint16(60964),
	1691: uint16(60967),
	1692: uint16(60969),
	1693: uint16(60980),
	1694: uint16(60985),
	1695: uint16(60987),
	1696: uint16(60994),
	1697: uint16(60999),
	1698: uint16(61001),
	1699: uint16(61003),
	1700: uint16(61005),
	1701: uint16(61009),
	1702: uint16(61012),
	1703: uint16(61015),
	1704: uint16(61017),
	1705: uint16(61019),
	1706: uint16(61021),
	1707: uint16(61023),
	1708: uint16(61025),
	1709: uint16(61028),
	1710: uint16(61031),
	1711: uint16(61036),
	1712: uint16(61044),
	1713: uint16(61049),
	1714: uint16(61054),
	1715: uint16(61056),
	1716: uint16(61067),
	1717: uint16(61089),
	1718: uint16(61093),
	1719: uint16(61099),
	1720: uint16(61168),
	1721: uint16(61440),
	1722: uint16(61488),
	1723: uint16(61600),
	1724: uint16(61617),
	1725: uint16(61633),
	1726: uint16(61649),
	1727: uint16(61696),
	1728: uint16(61712),
	1729: uint16(61744),
	1730: uint16(61808),
	1731: uint16(61926),
	1732: uint16(61968),
	1733: uint16(62016),
	1734: uint16(62032),
	1735: uint16(62208),
	1736: uint16(62256),
	1737: uint16(62263),
	1738: uint16(62336),
	1739: uint16(62368),
	1740: uint16(62406),
	1741: uint16(62432),
	1742: uint16(62464),
	1743: uint16(62528),
	1744: uint16(62530),
	1745: uint16(62713),
	1746: uint16(62720),
	1747: uint16(62784),
	1748: uint16(62800),
	1749: uint16(62971),
	1750: uint16(63045),
	1751: uint16(63104),
	1752: uint16(63232),
	1754: uint16(42710),
	1755: uint16(42752),
	1756: uint16(46900),
	1757: uint16(46912),
	1758: uint16(47133),
	1759: uint16(63488),
	1760: uint16(1),
	1761: uint16(32),
	1762: uint16(256),
	1764: uint16(65533),
}
var _aFts5UnicodeData = [1765]Tu16{
	0:    uint16(1025),
	1:    uint16(61),
	2:    uint16(117),
	3:    uint16(55),
	4:    uint16(117),
	5:    uint16(54),
	6:    uint16(50),
	7:    uint16(53),
	8:    uint16(57),
	9:    uint16(53),
	10:   uint16(49),
	11:   uint16(85),
	12:   uint16(333),
	13:   uint16(85),
	14:   uint16(121),
	15:   uint16(85),
	16:   uint16(841),
	17:   uint16(54),
	18:   uint16(53),
	19:   uint16(50),
	20:   uint16(56),
	21:   uint16(48),
	22:   uint16(56),
	23:   uint16(837),
	24:   uint16(54),
	25:   uint16(57),
	26:   uint16(50),
	27:   uint16(57),
	28:   uint16(1057),
	29:   uint16(61),
	30:   uint16(53),
	31:   uint16(151),
	32:   uint16(58),
	33:   uint16(53),
	34:   uint16(56),
	35:   uint16(58),
	36:   uint16(39),
	37:   uint16(52),
	38:   uint16(57),
	39:   uint16(34),
	40:   uint16(58),
	41:   uint16(56),
	42:   uint16(58),
	43:   uint16(57),
	44:   uint16(79),
	45:   uint16(56),
	46:   uint16(37),
	47:   uint16(85),
	48:   uint16(56),
	49:   uint16(47),
	50:   uint16(39),
	51:   uint16(51),
	52:   uint16(111),
	53:   uint16(53),
	54:   uint16(745),
	55:   uint16(57),
	56:   uint16(233),
	57:   uint16(773),
	58:   uint16(57),
	59:   uint16(261),
	60:   uint16(1822),
	61:   uint16(37),
	62:   uint16(542),
	63:   uint16(37),
	64:   uint16(1534),
	65:   uint16(222),
	66:   uint16(69),
	67:   uint16(73),
	68:   uint16(37),
	69:   uint16(126),
	70:   uint16(126),
	71:   uint16(73),
	72:   uint16(69),
	73:   uint16(137),
	74:   uint16(37),
	75:   uint16(73),
	76:   uint16(37),
	77:   uint16(105),
	78:   uint16(101),
	79:   uint16(73),
	80:   uint16(37),
	81:   uint16(73),
	82:   uint16(37),
	83:   uint16(190),
	84:   uint16(158),
	85:   uint16(37),
	86:   uint16(126),
	87:   uint16(126),
	88:   uint16(73),
	89:   uint16(37),
	90:   uint16(126),
	91:   uint16(94),
	92:   uint16(37),
	93:   uint16(39),
	94:   uint16(94),
	95:   uint16(69),
	96:   uint16(135),
	97:   uint16(41),
	98:   uint16(40),
	99:   uint16(37),
	100:  uint16(41),
	101:  uint16(40),
	102:  uint16(37),
	103:  uint16(41),
	104:  uint16(40),
	105:  uint16(37),
	106:  uint16(542),
	107:  uint16(37),
	108:  uint16(606),
	109:  uint16(37),
	110:  uint16(41),
	111:  uint16(40),
	112:  uint16(37),
	113:  uint16(126),
	114:  uint16(73),
	115:  uint16(37),
	116:  uint16(1886),
	117:  uint16(197),
	118:  uint16(73),
	119:  uint16(37),
	120:  uint16(73),
	121:  uint16(69),
	122:  uint16(126),
	123:  uint16(105),
	124:  uint16(37),
	125:  uint16(286),
	126:  uint16(2181),
	127:  uint16(39),
	128:  uint16(869),
	129:  uint16(582),
	130:  uint16(152),
	131:  uint16(390),
	132:  uint16(472),
	133:  uint16(166),
	134:  uint16(248),
	135:  uint16(38),
	136:  uint16(56),
	137:  uint16(38),
	138:  uint16(568),
	139:  uint16(3596),
	140:  uint16(158),
	141:  uint16(38),
	142:  uint16(56),
	143:  uint16(94),
	144:  uint16(38),
	145:  uint16(101),
	146:  uint16(53),
	147:  uint16(88),
	148:  uint16(41),
	149:  uint16(53),
	150:  uint16(105),
	151:  uint16(41),
	152:  uint16(73),
	153:  uint16(37),
	154:  uint16(553),
	155:  uint16(297),
	156:  uint16(1125),
	157:  uint16(94),
	158:  uint16(37),
	159:  uint16(105),
	160:  uint16(101),
	161:  uint16(798),
	162:  uint16(133),
	163:  uint16(94),
	164:  uint16(57),
	165:  uint16(126),
	166:  uint16(94),
	167:  uint16(37),
	168:  uint16(1641),
	169:  uint16(1541),
	170:  uint16(1118),
	171:  uint16(58),
	172:  uint16(172),
	173:  uint16(75),
	174:  uint16(1790),
	175:  uint16(478),
	176:  uint16(37),
	177:  uint16(2846),
	178:  uint16(1225),
	179:  uint16(38),
	180:  uint16(213),
	181:  uint16(1253),
	182:  uint16(53),
	183:  uint16(49),
	184:  uint16(55),
	185:  uint16(1452),
	186:  uint16(49),
	187:  uint16(44),
	188:  uint16(53),
	189:  uint16(76),
	190:  uint16(53),
	191:  uint16(76),
	192:  uint16(53),
	193:  uint16(44),
	194:  uint16(871),
	195:  uint16(103),
	196:  uint16(85),
	197:  uint16(162),
	198:  uint16(121),
	199:  uint16(85),
	200:  uint16(55),
	201:  uint16(85),
	202:  uint16(90),
	203:  uint16(364),
	204:  uint16(53),
	205:  uint16(85),
	206:  uint16(1031),
	207:  uint16(38),
	208:  uint16(327),
	209:  uint16(684),
	210:  uint16(333),
	211:  uint16(149),
	212:  uint16(71),
	213:  uint16(44),
	214:  uint16(3175),
	215:  uint16(53),
	216:  uint16(39),
	217:  uint16(236),
	218:  uint16(34),
	219:  uint16(58),
	220:  uint16(204),
	221:  uint16(70),
	222:  uint16(76),
	223:  uint16(58),
	224:  uint16(140),
	225:  uint16(71),
	226:  uint16(333),
	227:  uint16(103),
	228:  uint16(90),
	229:  uint16(39),
	230:  uint16(469),
	231:  uint16(34),
	232:  uint16(39),
	233:  uint16(44),
	234:  uint16(967),
	235:  uint16(876),
	236:  uint16(2855),
	237:  uint16(364),
	238:  uint16(39),
	239:  uint16(333),
	240:  uint16(1063),
	241:  uint16(300),
	242:  uint16(70),
	243:  uint16(58),
	244:  uint16(117),
	245:  uint16(38),
	246:  uint16(711),
	247:  uint16(140),
	248:  uint16(38),
	249:  uint16(300),
	250:  uint16(38),
	251:  uint16(108),
	252:  uint16(38),
	253:  uint16(172),
	254:  uint16(501),
	255:  uint16(807),
	256:  uint16(108),
	257:  uint16(53),
	258:  uint16(39),
	259:  uint16(359),
	260:  uint16(876),
	261:  uint16(108),
	262:  uint16(42),
	263:  uint16(1735),
	264:  uint16(44),
	265:  uint16(42),
	266:  uint16(44),
	267:  uint16(39),
	268:  uint16(106),
	269:  uint16(268),
	270:  uint16(138),
	271:  uint16(44),
	272:  uint16(74),
	273:  uint16(39),
	274:  uint16(236),
	275:  uint16(327),
	276:  uint16(76),
	277:  uint16(85),
	278:  uint16(333),
	279:  uint16(53),
	280:  uint16(38),
	281:  uint16(199),
	282:  uint16(231),
	283:  uint16(44),
	284:  uint16(74),
	285:  uint16(263),
	286:  uint16(71),
	287:  uint16(711),
	288:  uint16(231),
	289:  uint16(39),
	290:  uint16(135),
	291:  uint16(44),
	292:  uint16(39),
	293:  uint16(106),
	294:  uint16(140),
	295:  uint16(74),
	296:  uint16(74),
	297:  uint16(44),
	298:  uint16(39),
	299:  uint16(42),
	300:  uint16(71),
	301:  uint16(103),
	302:  uint16(76),
	303:  uint16(333),
	304:  uint16(71),
	305:  uint16(87),
	306:  uint16(207),
	307:  uint16(58),
	308:  uint16(55),
	309:  uint16(76),
	310:  uint16(42),
	311:  uint16(199),
	312:  uint16(71),
	313:  uint16(711),
	314:  uint16(231),
	315:  uint16(71),
	316:  uint16(71),
	317:  uint16(71),
	318:  uint16(44),
	319:  uint16(106),
	320:  uint16(76),
	321:  uint16(76),
	322:  uint16(108),
	323:  uint16(44),
	324:  uint16(135),
	325:  uint16(39),
	326:  uint16(333),
	327:  uint16(76),
	328:  uint16(103),
	329:  uint16(44),
	330:  uint16(76),
	331:  uint16(42),
	332:  uint16(295),
	333:  uint16(103),
	334:  uint16(711),
	335:  uint16(231),
	336:  uint16(71),
	337:  uint16(167),
	338:  uint16(44),
	339:  uint16(39),
	340:  uint16(106),
	341:  uint16(172),
	342:  uint16(76),
	343:  uint16(42),
	344:  uint16(74),
	345:  uint16(44),
	346:  uint16(39),
	347:  uint16(71),
	348:  uint16(76),
	349:  uint16(333),
	350:  uint16(53),
	351:  uint16(55),
	352:  uint16(44),
	353:  uint16(74),
	354:  uint16(263),
	355:  uint16(71),
	356:  uint16(711),
	357:  uint16(231),
	358:  uint16(71),
	359:  uint16(167),
	360:  uint16(44),
	361:  uint16(39),
	362:  uint16(42),
	363:  uint16(44),
	364:  uint16(42),
	365:  uint16(140),
	366:  uint16(74),
	367:  uint16(74),
	368:  uint16(44),
	369:  uint16(44),
	370:  uint16(42),
	371:  uint16(71),
	372:  uint16(103),
	373:  uint16(76),
	374:  uint16(333),
	375:  uint16(58),
	376:  uint16(39),
	377:  uint16(207),
	378:  uint16(44),
	379:  uint16(39),
	380:  uint16(199),
	381:  uint16(103),
	382:  uint16(135),
	383:  uint16(71),
	384:  uint16(39),
	385:  uint16(71),
	386:  uint16(71),
	387:  uint16(103),
	388:  uint16(391),
	389:  uint16(74),
	390:  uint16(44),
	391:  uint16(74),
	392:  uint16(106),
	393:  uint16(106),
	394:  uint16(44),
	395:  uint16(39),
	396:  uint16(42),
	397:  uint16(333),
	398:  uint16(111),
	399:  uint16(218),
	400:  uint16(55),
	401:  uint16(58),
	402:  uint16(106),
	403:  uint16(263),
	404:  uint16(103),
	405:  uint16(743),
	406:  uint16(327),
	407:  uint16(167),
	408:  uint16(39),
	409:  uint16(108),
	410:  uint16(138),
	411:  uint16(108),
	412:  uint16(140),
	413:  uint16(76),
	414:  uint16(71),
	415:  uint16(71),
	416:  uint16(76),
	417:  uint16(333),
	418:  uint16(239),
	419:  uint16(58),
	420:  uint16(74),
	421:  uint16(263),
	422:  uint16(103),
	423:  uint16(743),
	424:  uint16(327),
	425:  uint16(167),
	426:  uint16(44),
	427:  uint16(39),
	428:  uint16(42),
	429:  uint16(44),
	430:  uint16(170),
	431:  uint16(44),
	432:  uint16(74),
	433:  uint16(74),
	434:  uint16(76),
	435:  uint16(74),
	436:  uint16(39),
	437:  uint16(71),
	438:  uint16(76),
	439:  uint16(333),
	440:  uint16(71),
	441:  uint16(74),
	442:  uint16(263),
	443:  uint16(103),
	444:  uint16(1319),
	445:  uint16(39),
	446:  uint16(106),
	447:  uint16(140),
	448:  uint16(106),
	449:  uint16(106),
	450:  uint16(44),
	451:  uint16(39),
	452:  uint16(42),
	453:  uint16(71),
	454:  uint16(76),
	455:  uint16(333),
	456:  uint16(207),
	457:  uint16(58),
	458:  uint16(199),
	459:  uint16(74),
	460:  uint16(583),
	461:  uint16(775),
	462:  uint16(295),
	463:  uint16(39),
	464:  uint16(231),
	465:  uint16(44),
	466:  uint16(106),
	467:  uint16(108),
	468:  uint16(44),
	469:  uint16(266),
	470:  uint16(74),
	471:  uint16(53),
	472:  uint16(1543),
	473:  uint16(44),
	474:  uint16(71),
	475:  uint16(236),
	476:  uint16(55),
	477:  uint16(199),
	478:  uint16(38),
	479:  uint16(268),
	480:  uint16(53),
	481:  uint16(333),
	482:  uint16(85),
	483:  uint16(71),
	484:  uint16(39),
	485:  uint16(71),
	486:  uint16(39),
	487:  uint16(39),
	488:  uint16(135),
	489:  uint16(231),
	490:  uint16(103),
	491:  uint16(39),
	492:  uint16(39),
	493:  uint16(71),
	494:  uint16(135),
	495:  uint16(44),
	496:  uint16(71),
	497:  uint16(204),
	498:  uint16(76),
	499:  uint16(39),
	500:  uint16(167),
	501:  uint16(38),
	502:  uint16(204),
	503:  uint16(333),
	504:  uint16(135),
	505:  uint16(39),
	506:  uint16(122),
	507:  uint16(501),
	508:  uint16(58),
	509:  uint16(53),
	510:  uint16(122),
	511:  uint16(76),
	512:  uint16(218),
	513:  uint16(333),
	514:  uint16(335),
	515:  uint16(58),
	516:  uint16(44),
	517:  uint16(58),
	518:  uint16(44),
	519:  uint16(58),
	520:  uint16(44),
	521:  uint16(54),
	522:  uint16(50),
	523:  uint16(54),
	524:  uint16(50),
	525:  uint16(74),
	526:  uint16(263),
	527:  uint16(1159),
	528:  uint16(460),
	529:  uint16(42),
	530:  uint16(172),
	531:  uint16(53),
	532:  uint16(76),
	533:  uint16(167),
	534:  uint16(364),
	535:  uint16(1164),
	536:  uint16(282),
	537:  uint16(44),
	538:  uint16(218),
	539:  uint16(90),
	540:  uint16(181),
	541:  uint16(154),
	542:  uint16(85),
	543:  uint16(1383),
	544:  uint16(74),
	545:  uint16(140),
	546:  uint16(42),
	547:  uint16(204),
	548:  uint16(42),
	549:  uint16(76),
	550:  uint16(74),
	551:  uint16(76),
	552:  uint16(39),
	553:  uint16(333),
	554:  uint16(213),
	555:  uint16(199),
	556:  uint16(74),
	557:  uint16(76),
	558:  uint16(135),
	559:  uint16(108),
	560:  uint16(39),
	561:  uint16(106),
	562:  uint16(71),
	563:  uint16(234),
	564:  uint16(103),
	565:  uint16(140),
	566:  uint16(423),
	567:  uint16(44),
	568:  uint16(74),
	569:  uint16(76),
	570:  uint16(202),
	571:  uint16(44),
	572:  uint16(39),
	573:  uint16(42),
	574:  uint16(333),
	575:  uint16(106),
	576:  uint16(44),
	577:  uint16(90),
	578:  uint16(1225),
	579:  uint16(41),
	580:  uint16(41),
	581:  uint16(1383),
	582:  uint16(53),
	583:  uint16(38),
	584:  uint16(10631),
	585:  uint16(135),
	586:  uint16(231),
	587:  uint16(39),
	588:  uint16(135),
	589:  uint16(1319),
	590:  uint16(135),
	591:  uint16(1063),
	592:  uint16(135),
	593:  uint16(231),
	594:  uint16(39),
	595:  uint16(135),
	596:  uint16(487),
	597:  uint16(1831),
	598:  uint16(135),
	599:  uint16(2151),
	600:  uint16(108),
	601:  uint16(309),
	602:  uint16(655),
	603:  uint16(519),
	604:  uint16(346),
	605:  uint16(2727),
	606:  uint16(49),
	607:  uint16(19847),
	608:  uint16(85),
	609:  uint16(551),
	610:  uint16(61),
	611:  uint16(839),
	612:  uint16(54),
	613:  uint16(50),
	614:  uint16(2407),
	615:  uint16(117),
	616:  uint16(110),
	617:  uint16(423),
	618:  uint16(135),
	619:  uint16(108),
	620:  uint16(583),
	621:  uint16(108),
	622:  uint16(85),
	623:  uint16(583),
	624:  uint16(76),
	625:  uint16(423),
	626:  uint16(103),
	627:  uint16(76),
	628:  uint16(1671),
	629:  uint16(76),
	630:  uint16(42),
	631:  uint16(236),
	632:  uint16(266),
	633:  uint16(44),
	634:  uint16(74),
	635:  uint16(364),
	636:  uint16(117),
	637:  uint16(38),
	638:  uint16(117),
	639:  uint16(55),
	640:  uint16(39),
	641:  uint16(44),
	642:  uint16(333),
	643:  uint16(335),
	644:  uint16(213),
	645:  uint16(49),
	646:  uint16(149),
	647:  uint16(108),
	648:  uint16(61),
	649:  uint16(333),
	650:  uint16(1127),
	651:  uint16(38),
	652:  uint16(1671),
	653:  uint16(1319),
	654:  uint16(44),
	655:  uint16(39),
	656:  uint16(2247),
	657:  uint16(935),
	658:  uint16(108),
	659:  uint16(138),
	660:  uint16(76),
	661:  uint16(106),
	662:  uint16(74),
	663:  uint16(44),
	664:  uint16(202),
	665:  uint16(108),
	666:  uint16(58),
	667:  uint16(85),
	668:  uint16(333),
	669:  uint16(967),
	670:  uint16(167),
	671:  uint16(1415),
	672:  uint16(554),
	673:  uint16(231),
	674:  uint16(74),
	675:  uint16(333),
	676:  uint16(47),
	677:  uint16(1114),
	678:  uint16(743),
	679:  uint16(76),
	680:  uint16(106),
	681:  uint16(85),
	682:  uint16(1703),
	683:  uint16(42),
	684:  uint16(44),
	685:  uint16(42),
	686:  uint16(236),
	687:  uint16(44),
	688:  uint16(42),
	689:  uint16(44),
	690:  uint16(74),
	691:  uint16(268),
	692:  uint16(202),
	693:  uint16(332),
	694:  uint16(44),
	695:  uint16(333),
	696:  uint16(333),
	697:  uint16(245),
	698:  uint16(38),
	699:  uint16(213),
	700:  uint16(140),
	701:  uint16(42),
	702:  uint16(1511),
	703:  uint16(44),
	704:  uint16(42),
	705:  uint16(172),
	706:  uint16(42),
	707:  uint16(44),
	708:  uint16(170),
	709:  uint16(44),
	710:  uint16(74),
	711:  uint16(231),
	712:  uint16(333),
	713:  uint16(245),
	714:  uint16(346),
	715:  uint16(300),
	716:  uint16(314),
	717:  uint16(76),
	718:  uint16(42),
	719:  uint16(967),
	720:  uint16(42),
	721:  uint16(140),
	722:  uint16(74),
	723:  uint16(76),
	724:  uint16(42),
	725:  uint16(44),
	726:  uint16(74),
	727:  uint16(71),
	728:  uint16(333),
	729:  uint16(1415),
	730:  uint16(44),
	731:  uint16(42),
	732:  uint16(76),
	733:  uint16(106),
	734:  uint16(44),
	735:  uint16(42),
	736:  uint16(108),
	737:  uint16(74),
	738:  uint16(149),
	739:  uint16(1159),
	740:  uint16(266),
	741:  uint16(268),
	742:  uint16(74),
	743:  uint16(76),
	744:  uint16(181),
	745:  uint16(333),
	746:  uint16(103),
	747:  uint16(333),
	748:  uint16(967),
	749:  uint16(198),
	750:  uint16(85),
	751:  uint16(277),
	752:  uint16(108),
	753:  uint16(53),
	754:  uint16(428),
	755:  uint16(42),
	756:  uint16(236),
	757:  uint16(135),
	758:  uint16(44),
	759:  uint16(135),
	760:  uint16(74),
	761:  uint16(44),
	762:  uint16(71),
	763:  uint16(1413),
	764:  uint16(2022),
	765:  uint16(421),
	766:  uint16(38),
	767:  uint16(1093),
	768:  uint16(1190),
	769:  uint16(1260),
	770:  uint16(140),
	771:  uint16(4830),
	772:  uint16(261),
	773:  uint16(3166),
	774:  uint16(261),
	775:  uint16(265),
	776:  uint16(197),
	777:  uint16(201),
	778:  uint16(261),
	779:  uint16(265),
	780:  uint16(261),
	781:  uint16(265),
	782:  uint16(197),
	783:  uint16(201),
	784:  uint16(261),
	785:  uint16(41),
	786:  uint16(41),
	787:  uint16(41),
	788:  uint16(94),
	789:  uint16(229),
	790:  uint16(265),
	791:  uint16(453),
	792:  uint16(261),
	793:  uint16(264),
	794:  uint16(261),
	795:  uint16(264),
	796:  uint16(261),
	797:  uint16(264),
	798:  uint16(165),
	799:  uint16(69),
	800:  uint16(137),
	801:  uint16(40),
	802:  uint16(56),
	803:  uint16(37),
	804:  uint16(120),
	805:  uint16(101),
	806:  uint16(69),
	807:  uint16(137),
	808:  uint16(40),
	809:  uint16(120),
	810:  uint16(133),
	811:  uint16(69),
	812:  uint16(137),
	813:  uint16(120),
	814:  uint16(261),
	815:  uint16(169),
	816:  uint16(120),
	817:  uint16(101),
	818:  uint16(69),
	819:  uint16(137),
	820:  uint16(40),
	821:  uint16(88),
	822:  uint16(381),
	823:  uint16(162),
	824:  uint16(209),
	825:  uint16(85),
	826:  uint16(52),
	827:  uint16(51),
	828:  uint16(54),
	829:  uint16(84),
	830:  uint16(51),
	831:  uint16(54),
	832:  uint16(52),
	833:  uint16(277),
	834:  uint16(59),
	835:  uint16(60),
	836:  uint16(162),
	837:  uint16(61),
	838:  uint16(309),
	839:  uint16(52),
	840:  uint16(51),
	841:  uint16(149),
	842:  uint16(80),
	843:  uint16(117),
	844:  uint16(57),
	845:  uint16(54),
	846:  uint16(50),
	847:  uint16(373),
	848:  uint16(57),
	849:  uint16(53),
	850:  uint16(48),
	851:  uint16(341),
	852:  uint16(61),
	853:  uint16(162),
	854:  uint16(194),
	855:  uint16(47),
	856:  uint16(38),
	857:  uint16(207),
	858:  uint16(121),
	859:  uint16(54),
	860:  uint16(50),
	861:  uint16(38),
	862:  uint16(335),
	863:  uint16(121),
	864:  uint16(54),
	865:  uint16(50),
	866:  uint16(422),
	867:  uint16(855),
	868:  uint16(428),
	869:  uint16(139),
	870:  uint16(44),
	871:  uint16(107),
	872:  uint16(396),
	873:  uint16(90),
	874:  uint16(41),
	875:  uint16(154),
	876:  uint16(41),
	877:  uint16(90),
	878:  uint16(37),
	879:  uint16(105),
	880:  uint16(69),
	881:  uint16(105),
	882:  uint16(37),
	883:  uint16(58),
	884:  uint16(41),
	885:  uint16(90),
	886:  uint16(57),
	887:  uint16(169),
	888:  uint16(218),
	889:  uint16(41),
	890:  uint16(58),
	891:  uint16(41),
	892:  uint16(58),
	893:  uint16(41),
	894:  uint16(58),
	895:  uint16(137),
	896:  uint16(58),
	897:  uint16(37),
	898:  uint16(137),
	899:  uint16(37),
	900:  uint16(135),
	901:  uint16(37),
	902:  uint16(90),
	903:  uint16(69),
	904:  uint16(73),
	905:  uint16(185),
	906:  uint16(94),
	907:  uint16(101),
	908:  uint16(58),
	909:  uint16(57),
	910:  uint16(90),
	911:  uint16(37),
	912:  uint16(58),
	913:  uint16(527),
	914:  uint16(1134),
	915:  uint16(94),
	916:  uint16(142),
	917:  uint16(47),
	918:  uint16(185),
	919:  uint16(186),
	920:  uint16(89),
	921:  uint16(154),
	922:  uint16(57),
	923:  uint16(90),
	924:  uint16(57),
	925:  uint16(90),
	926:  uint16(57),
	927:  uint16(250),
	928:  uint16(57),
	929:  uint16(1018),
	930:  uint16(89),
	931:  uint16(90),
	932:  uint16(57),
	933:  uint16(58),
	934:  uint16(57),
	935:  uint16(1018),
	936:  uint16(8601),
	937:  uint16(282),
	938:  uint16(153),
	939:  uint16(666),
	940:  uint16(89),
	941:  uint16(250),
	942:  uint16(54),
	943:  uint16(50),
	944:  uint16(2618),
	945:  uint16(57),
	946:  uint16(986),
	947:  uint16(825),
	948:  uint16(1306),
	949:  uint16(217),
	950:  uint16(602),
	951:  uint16(1274),
	952:  uint16(378),
	953:  uint16(1935),
	954:  uint16(2522),
	955:  uint16(719),
	956:  uint16(5882),
	957:  uint16(57),
	958:  uint16(314),
	959:  uint16(57),
	960:  uint16(1754),
	961:  uint16(281),
	962:  uint16(3578),
	963:  uint16(57),
	964:  uint16(4634),
	965:  uint16(3322),
	966:  uint16(54),
	967:  uint16(50),
	968:  uint16(54),
	969:  uint16(50),
	970:  uint16(54),
	971:  uint16(50),
	972:  uint16(54),
	973:  uint16(50),
	974:  uint16(54),
	975:  uint16(50),
	976:  uint16(54),
	977:  uint16(50),
	978:  uint16(54),
	979:  uint16(50),
	980:  uint16(975),
	981:  uint16(1434),
	982:  uint16(185),
	983:  uint16(54),
	984:  uint16(50),
	985:  uint16(1017),
	986:  uint16(54),
	987:  uint16(50),
	988:  uint16(54),
	989:  uint16(50),
	990:  uint16(54),
	991:  uint16(50),
	992:  uint16(54),
	993:  uint16(50),
	994:  uint16(54),
	995:  uint16(50),
	996:  uint16(537),
	997:  uint16(8218),
	998:  uint16(4217),
	999:  uint16(54),
	1000: uint16(50),
	1001: uint16(54),
	1002: uint16(50),
	1003: uint16(54),
	1004: uint16(50),
	1005: uint16(54),
	1006: uint16(50),
	1007: uint16(54),
	1008: uint16(50),
	1009: uint16(54),
	1010: uint16(50),
	1011: uint16(54),
	1012: uint16(50),
	1013: uint16(54),
	1014: uint16(50),
	1015: uint16(54),
	1016: uint16(50),
	1017: uint16(54),
	1018: uint16(50),
	1019: uint16(54),
	1020: uint16(50),
	1021: uint16(2041),
	1022: uint16(54),
	1023: uint16(50),
	1024: uint16(54),
	1025: uint16(50),
	1026: uint16(1049),
	1027: uint16(54),
	1028: uint16(50),
	1029: uint16(8281),
	1030: uint16(1562),
	1031: uint16(697),
	1032: uint16(90),
	1033: uint16(217),
	1034: uint16(346),
	1035: uint16(1513),
	1036: uint16(1509),
	1037: uint16(126),
	1038: uint16(73),
	1039: uint16(69),
	1040: uint16(254),
	1041: uint16(105),
	1042: uint16(37),
	1043: uint16(94),
	1044: uint16(37),
	1045: uint16(94),
	1046: uint16(165),
	1047: uint16(70),
	1048: uint16(105),
	1049: uint16(37),
	1050: uint16(3166),
	1051: uint16(37),
	1052: uint16(218),
	1053: uint16(158),
	1054: uint16(108),
	1055: uint16(94),
	1056: uint16(149),
	1057: uint16(47),
	1058: uint16(85),
	1059: uint16(1221),
	1060: uint16(37),
	1061: uint16(37),
	1062: uint16(1799),
	1063: uint16(38),
	1064: uint16(53),
	1065: uint16(44),
	1066: uint16(743),
	1067: uint16(231),
	1068: uint16(231),
	1069: uint16(231),
	1070: uint16(231),
	1071: uint16(231),
	1072: uint16(231),
	1073: uint16(231),
	1074: uint16(231),
	1075: uint16(1036),
	1076: uint16(85),
	1077: uint16(52),
	1078: uint16(51),
	1079: uint16(52),
	1080: uint16(51),
	1081: uint16(117),
	1082: uint16(52),
	1083: uint16(51),
	1084: uint16(53),
	1085: uint16(52),
	1086: uint16(51),
	1087: uint16(309),
	1088: uint16(49),
	1089: uint16(85),
	1090: uint16(49),
	1091: uint16(53),
	1092: uint16(52),
	1093: uint16(51),
	1094: uint16(85),
	1095: uint16(52),
	1096: uint16(51),
	1097: uint16(54),
	1098: uint16(50),
	1099: uint16(54),
	1100: uint16(50),
	1101: uint16(54),
	1102: uint16(50),
	1103: uint16(54),
	1104: uint16(50),
	1105: uint16(181),
	1106: uint16(38),
	1107: uint16(341),
	1108: uint16(81),
	1109: uint16(858),
	1110: uint16(2874),
	1111: uint16(6874),
	1112: uint16(410),
	1113: uint16(61),
	1114: uint16(117),
	1115: uint16(58),
	1116: uint16(38),
	1117: uint16(39),
	1118: uint16(46),
	1119: uint16(54),
	1120: uint16(50),
	1121: uint16(54),
	1122: uint16(50),
	1123: uint16(54),
	1124: uint16(50),
	1125: uint16(54),
	1126: uint16(50),
	1127: uint16(54),
	1128: uint16(50),
	1129: uint16(90),
	1130: uint16(54),
	1131: uint16(50),
	1132: uint16(54),
	1133: uint16(50),
	1134: uint16(54),
	1135: uint16(50),
	1136: uint16(54),
	1137: uint16(50),
	1138: uint16(49),
	1139: uint16(54),
	1140: uint16(82),
	1141: uint16(58),
	1142: uint16(302),
	1143: uint16(140),
	1144: uint16(74),
	1145: uint16(49),
	1146: uint16(166),
	1147: uint16(90),
	1148: uint16(110),
	1149: uint16(38),
	1150: uint16(39),
	1151: uint16(53),
	1152: uint16(90),
	1153: uint16(2759),
	1154: uint16(76),
	1155: uint16(88),
	1156: uint16(70),
	1157: uint16(39),
	1158: uint16(49),
	1159: uint16(2887),
	1160: uint16(53),
	1161: uint16(102),
	1162: uint16(39),
	1163: uint16(1319),
	1164: uint16(3015),
	1165: uint16(90),
	1166: uint16(143),
	1167: uint16(346),
	1168: uint16(871),
	1169: uint16(1178),
	1170: uint16(519),
	1171: uint16(1018),
	1172: uint16(335),
	1173: uint16(986),
	1174: uint16(271),
	1175: uint16(58),
	1176: uint16(495),
	1177: uint16(1050),
	1178: uint16(335),
	1179: uint16(1274),
	1180: uint16(495),
	1181: uint16(2042),
	1182: uint16(8218),
	1183: uint16(39),
	1184: uint16(39),
	1185: uint16(2074),
	1186: uint16(39),
	1187: uint16(39),
	1188: uint16(679),
	1189: uint16(38),
	1190: uint16(36583),
	1191: uint16(1786),
	1192: uint16(1287),
	1193: uint16(198),
	1194: uint16(85),
	1195: uint16(8583),
	1196: uint16(38),
	1197: uint16(117),
	1198: uint16(519),
	1199: uint16(333),
	1200: uint16(71),
	1201: uint16(1502),
	1202: uint16(39),
	1203: uint16(44),
	1204: uint16(107),
	1205: uint16(53),
	1206: uint16(332),
	1207: uint16(53),
	1208: uint16(38),
	1209: uint16(798),
	1210: uint16(44),
	1211: uint16(2247),
	1212: uint16(334),
	1213: uint16(76),
	1214: uint16(213),
	1215: uint16(760),
	1216: uint16(294),
	1217: uint16(88),
	1218: uint16(478),
	1219: uint16(69),
	1220: uint16(2014),
	1221: uint16(38),
	1222: uint16(261),
	1223: uint16(190),
	1224: uint16(350),
	1225: uint16(38),
	1226: uint16(88),
	1227: uint16(158),
	1228: uint16(158),
	1229: uint16(382),
	1230: uint16(70),
	1231: uint16(37),
	1232: uint16(231),
	1233: uint16(44),
	1234: uint16(103),
	1235: uint16(44),
	1236: uint16(135),
	1237: uint16(44),
	1238: uint16(743),
	1239: uint16(74),
	1240: uint16(76),
	1241: uint16(42),
	1242: uint16(154),
	1243: uint16(207),
	1244: uint16(90),
	1245: uint16(55),
	1246: uint16(58),
	1247: uint16(1671),
	1248: uint16(149),
	1249: uint16(74),
	1250: uint16(1607),
	1251: uint16(522),
	1252: uint16(44),
	1253: uint16(85),
	1254: uint16(333),
	1255: uint16(588),
	1256: uint16(199),
	1257: uint16(117),
	1258: uint16(39),
	1259: uint16(333),
	1260: uint16(903),
	1261: uint16(268),
	1262: uint16(85),
	1263: uint16(743),
	1264: uint16(364),
	1265: uint16(74),
	1266: uint16(53),
	1267: uint16(935),
	1268: uint16(108),
	1269: uint16(42),
	1270: uint16(1511),
	1271: uint16(44),
	1272: uint16(74),
	1273: uint16(140),
	1274: uint16(74),
	1275: uint16(44),
	1276: uint16(138),
	1277: uint16(437),
	1278: uint16(38),
	1279: uint16(333),
	1280: uint16(85),
	1281: uint16(1319),
	1282: uint16(204),
	1283: uint16(74),
	1284: uint16(76),
	1285: uint16(74),
	1286: uint16(76),
	1287: uint16(103),
	1288: uint16(44),
	1289: uint16(263),
	1290: uint16(44),
	1291: uint16(42),
	1292: uint16(333),
	1293: uint16(149),
	1294: uint16(519),
	1295: uint16(38),
	1296: uint16(199),
	1297: uint16(122),
	1298: uint16(39),
	1299: uint16(42),
	1300: uint16(1543),
	1301: uint16(44),
	1302: uint16(39),
	1303: uint16(108),
	1304: uint16(71),
	1305: uint16(76),
	1306: uint16(167),
	1307: uint16(76),
	1308: uint16(39),
	1309: uint16(44),
	1310: uint16(39),
	1311: uint16(71),
	1312: uint16(38),
	1313: uint16(85),
	1314: uint16(359),
	1315: uint16(42),
	1316: uint16(76),
	1317: uint16(74),
	1318: uint16(85),
	1319: uint16(39),
	1320: uint16(70),
	1321: uint16(42),
	1322: uint16(44),
	1323: uint16(199),
	1324: uint16(199),
	1325: uint16(199),
	1326: uint16(231),
	1327: uint16(231),
	1328: uint16(1127),
	1329: uint16(74),
	1330: uint16(44),
	1331: uint16(74),
	1332: uint16(44),
	1333: uint16(74),
	1334: uint16(53),
	1335: uint16(42),
	1336: uint16(44),
	1337: uint16(333),
	1338: uint16(39),
	1339: uint16(39),
	1340: uint16(743),
	1341: uint16(1575),
	1342: uint16(36),
	1343: uint16(68),
	1344: uint16(68),
	1345: uint16(36),
	1346: uint16(63),
	1347: uint16(63),
	1348: uint16(11719),
	1349: uint16(3399),
	1350: uint16(229),
	1351: uint16(165),
	1352: uint16(39),
	1353: uint16(44),
	1354: uint16(327),
	1355: uint16(57),
	1356: uint16(423),
	1357: uint16(167),
	1358: uint16(39),
	1359: uint16(71),
	1360: uint16(71),
	1361: uint16(3463),
	1362: uint16(536),
	1363: uint16(11623),
	1364: uint16(54),
	1365: uint16(50),
	1366: uint16(2055),
	1367: uint16(1735),
	1368: uint16(391),
	1369: uint16(55),
	1370: uint16(58),
	1371: uint16(524),
	1372: uint16(245),
	1373: uint16(54),
	1374: uint16(50),
	1375: uint16(53),
	1376: uint16(236),
	1377: uint16(53),
	1378: uint16(81),
	1379: uint16(80),
	1380: uint16(54),
	1381: uint16(50),
	1382: uint16(54),
	1383: uint16(50),
	1384: uint16(54),
	1385: uint16(50),
	1386: uint16(54),
	1387: uint16(50),
	1388: uint16(54),
	1389: uint16(50),
	1390: uint16(54),
	1391: uint16(50),
	1392: uint16(54),
	1393: uint16(50),
	1394: uint16(54),
	1395: uint16(50),
	1396: uint16(85),
	1397: uint16(54),
	1398: uint16(50),
	1399: uint16(149),
	1400: uint16(112),
	1401: uint16(117),
	1402: uint16(149),
	1403: uint16(49),
	1404: uint16(54),
	1405: uint16(50),
	1406: uint16(54),
	1407: uint16(50),
	1408: uint16(54),
	1409: uint16(50),
	1410: uint16(117),
	1411: uint16(57),
	1412: uint16(49),
	1413: uint16(121),
	1414: uint16(53),
	1415: uint16(55),
	1416: uint16(85),
	1417: uint16(167),
	1418: uint16(4327),
	1419: uint16(34),
	1420: uint16(117),
	1421: uint16(55),
	1422: uint16(117),
	1423: uint16(54),
	1424: uint16(50),
	1425: uint16(53),
	1426: uint16(57),
	1427: uint16(53),
	1428: uint16(49),
	1429: uint16(85),
	1430: uint16(333),
	1431: uint16(85),
	1432: uint16(121),
	1433: uint16(85),
	1434: uint16(841),
	1435: uint16(54),
	1436: uint16(53),
	1437: uint16(50),
	1438: uint16(56),
	1439: uint16(48),
	1440: uint16(56),
	1441: uint16(837),
	1442: uint16(54),
	1443: uint16(57),
	1444: uint16(50),
	1445: uint16(57),
	1446: uint16(54),
	1447: uint16(50),
	1448: uint16(53),
	1449: uint16(54),
	1450: uint16(50),
	1451: uint16(85),
	1452: uint16(327),
	1453: uint16(38),
	1454: uint16(1447),
	1455: uint16(70),
	1456: uint16(999),
	1457: uint16(199),
	1458: uint16(199),
	1459: uint16(199),
	1460: uint16(103),
	1461: uint16(87),
	1462: uint16(57),
	1463: uint16(56),
	1464: uint16(58),
	1465: uint16(87),
	1466: uint16(58),
	1467: uint16(153),
	1468: uint16(90),
	1469: uint16(98),
	1470: uint16(90),
	1471: uint16(391),
	1472: uint16(839),
	1473: uint16(615),
	1474: uint16(71),
	1475: uint16(487),
	1476: uint16(455),
	1477: uint16(3943),
	1478: uint16(117),
	1479: uint16(1455),
	1480: uint16(314),
	1481: uint16(1710),
	1482: uint16(143),
	1483: uint16(570),
	1484: uint16(47),
	1485: uint16(410),
	1486: uint16(1466),
	1487: uint16(44),
	1488: uint16(935),
	1489: uint16(1575),
	1490: uint16(999),
	1491: uint16(143),
	1492: uint16(551),
	1493: uint16(46),
	1494: uint16(263),
	1495: uint16(46),
	1496: uint16(967),
	1497: uint16(53),
	1498: uint16(1159),
	1499: uint16(263),
	1500: uint16(53),
	1501: uint16(174),
	1502: uint16(1289),
	1503: uint16(1285),
	1504: uint16(2503),
	1505: uint16(333),
	1506: uint16(199),
	1507: uint16(39),
	1508: uint16(1415),
	1509: uint16(71),
	1510: uint16(39),
	1511: uint16(743),
	1512: uint16(53),
	1513: uint16(271),
	1514: uint16(711),
	1515: uint16(207),
	1516: uint16(53),
	1517: uint16(839),
	1518: uint16(53),
	1519: uint16(1799),
	1520: uint16(71),
	1521: uint16(39),
	1522: uint16(108),
	1523: uint16(76),
	1524: uint16(140),
	1525: uint16(135),
	1526: uint16(103),
	1527: uint16(871),
	1528: uint16(108),
	1529: uint16(44),
	1530: uint16(271),
	1531: uint16(309),
	1532: uint16(935),
	1533: uint16(79),
	1534: uint16(53),
	1535: uint16(1735),
	1536: uint16(245),
	1537: uint16(711),
	1538: uint16(271),
	1539: uint16(615),
	1540: uint16(271),
	1541: uint16(2343),
	1542: uint16(1007),
	1543: uint16(42),
	1544: uint16(44),
	1545: uint16(42),
	1546: uint16(1703),
	1547: uint16(492),
	1548: uint16(245),
	1549: uint16(655),
	1550: uint16(333),
	1551: uint16(76),
	1552: uint16(42),
	1553: uint16(1447),
	1554: uint16(106),
	1555: uint16(140),
	1556: uint16(74),
	1557: uint16(76),
	1558: uint16(85),
	1559: uint16(34),
	1560: uint16(149),
	1561: uint16(807),
	1562: uint16(333),
	1563: uint16(108),
	1564: uint16(1159),
	1565: uint16(172),
	1566: uint16(42),
	1567: uint16(268),
	1568: uint16(333),
	1569: uint16(149),
	1570: uint16(76),
	1571: uint16(42),
	1572: uint16(1543),
	1573: uint16(106),
	1574: uint16(300),
	1575: uint16(74),
	1576: uint16(135),
	1577: uint16(149),
	1578: uint16(333),
	1579: uint16(1383),
	1580: uint16(44),
	1581: uint16(42),
	1582: uint16(44),
	1583: uint16(74),
	1584: uint16(204),
	1585: uint16(42),
	1586: uint16(44),
	1587: uint16(333),
	1588: uint16(28135),
	1589: uint16(3182),
	1590: uint16(149),
	1591: uint16(34279),
	1592: uint16(18215),
	1593: uint16(2215),
	1594: uint16(39),
	1595: uint16(1482),
	1596: uint16(140),
	1597: uint16(422),
	1598: uint16(71),
	1599: uint16(7898),
	1600: uint16(1274),
	1601: uint16(1946),
	1602: uint16(74),
	1603: uint16(108),
	1604: uint16(122),
	1605: uint16(202),
	1606: uint16(258),
	1607: uint16(268),
	1608: uint16(90),
	1609: uint16(236),
	1610: uint16(986),
	1611: uint16(140),
	1612: uint16(1562),
	1613: uint16(2138),
	1614: uint16(108),
	1615: uint16(58),
	1616: uint16(2810),
	1617: uint16(591),
	1618: uint16(841),
	1619: uint16(837),
	1620: uint16(841),
	1621: uint16(229),
	1622: uint16(581),
	1623: uint16(841),
	1624: uint16(837),
	1625: uint16(41),
	1626: uint16(73),
	1627: uint16(41),
	1628: uint16(73),
	1629: uint16(137),
	1630: uint16(265),
	1631: uint16(133),
	1632: uint16(37),
	1633: uint16(229),
	1634: uint16(357),
	1635: uint16(841),
	1636: uint16(837),
	1637: uint16(73),
	1638: uint16(137),
	1639: uint16(265),
	1640: uint16(233),
	1641: uint16(837),
	1642: uint16(73),
	1643: uint16(137),
	1644: uint16(169),
	1645: uint16(41),
	1646: uint16(233),
	1647: uint16(837),
	1648: uint16(841),
	1649: uint16(837),
	1650: uint16(841),
	1651: uint16(837),
	1652: uint16(841),
	1653: uint16(837),
	1654: uint16(841),
	1655: uint16(837),
	1656: uint16(841),
	1657: uint16(837),
	1658: uint16(841),
	1659: uint16(901),
	1660: uint16(809),
	1661: uint16(57),
	1662: uint16(805),
	1663: uint16(57),
	1664: uint16(197),
	1665: uint16(809),
	1666: uint16(57),
	1667: uint16(805),
	1668: uint16(57),
	1669: uint16(197),
	1670: uint16(809),
	1671: uint16(57),
	1672: uint16(805),
	1673: uint16(57),
	1674: uint16(197),
	1675: uint16(809),
	1676: uint16(57),
	1677: uint16(805),
	1678: uint16(57),
	1679: uint16(197),
	1680: uint16(809),
	1681: uint16(57),
	1682: uint16(805),
	1683: uint16(57),
	1684: uint16(197),
	1685: uint16(94),
	1686: uint16(1613),
	1687: uint16(135),
	1688: uint16(871),
	1689: uint16(71),
	1690: uint16(39),
	1691: uint16(39),
	1692: uint16(327),
	1693: uint16(135),
	1694: uint16(39),
	1695: uint16(39),
	1696: uint16(39),
	1697: uint16(39),
	1698: uint16(39),
	1699: uint16(39),
	1700: uint16(103),
	1701: uint16(71),
	1702: uint16(39),
	1703: uint16(39),
	1704: uint16(39),
	1705: uint16(39),
	1706: uint16(39),
	1707: uint16(39),
	1708: uint16(71),
	1709: uint16(39),
	1710: uint16(135),
	1711: uint16(231),
	1712: uint16(135),
	1713: uint16(135),
	1714: uint16(39),
	1715: uint16(327),
	1716: uint16(551),
	1717: uint16(103),
	1718: uint16(167),
	1719: uint16(551),
	1720: uint16(89),
	1721: uint16(1434),
	1722: uint16(3226),
	1723: uint16(506),
	1724: uint16(474),
	1725: uint16(506),
	1726: uint16(506),
	1727: uint16(367),
	1728: uint16(1018),
	1729: uint16(1946),
	1730: uint16(1402),
	1731: uint16(954),
	1732: uint16(1402),
	1733: uint16(314),
	1734: uint16(90),
	1735: uint16(1082),
	1736: uint16(218),
	1737: uint16(2266),
	1738: uint16(666),
	1739: uint16(1210),
	1740: uint16(186),
	1741: uint16(570),
	1742: uint16(2042),
	1743: uint16(58),
	1744: uint16(5850),
	1745: uint16(154),
	1746: uint16(2010),
	1747: uint16(154),
	1748: uint16(794),
	1749: uint16(2266),
	1750: uint16(378),
	1751: uint16(2266),
	1752: uint16(3738),
	1753: uint16(39),
	1754: uint16(39),
	1755: uint16(39),
	1756: uint16(39),
	1757: uint16(39),
	1758: uint16(39),
	1759: uint16(17351),
	1760: uint16(34),
	1761: uint16(3074),
	1762: uint16(7692),
	1763: uint16(63),
	1764: uint16(63),
}

func _sqlite3Fts5UnicodeCategory(tls *libc.TLS, iCode Tu32) (r int32) {
	var iHi, iLo, iRes, iTest, ret, v1 int32
	var iKey Tu16
	_, _, _, _, _, _, _ = iHi, iKey, iLo, iRes, iTest, ret, v1
	iRes = -int32(1)
	if iCode >= uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(20)) {
		return 0
	}
	iLo = int32(_aFts5UnicodeBlock[iCode>>int32(16)])
	iHi = int32(_aFts5UnicodeBlock[uint32(1)+iCode>>libc.Int32FromInt32(16)])
	iKey = uint16(iCode & libc.Uint32FromInt32(0xFFFF))
	for iHi > iLo {
		iTest = (iHi + iLo) / int32(2)
		if int32(int32(iKey)) >= int32(_aFts5UnicodeMap[iTest]) {
			iRes = iTest
			iLo = iTest + int32(1)
		} else {
			iHi = iTest
		}
	}
	if iRes < 0 {
		return 0
	}
	if int32(int32(iKey)) >= int32(_aFts5UnicodeMap[iRes])+int32(_aFts5UnicodeData[iRes])>>int32(5) {
		return 0
	}
	ret = int32(_aFts5UnicodeData[iRes]) & int32(0x1F)
	if ret != int32(30) {
		return ret
	}
	if (int32(int32(iKey))-int32(_aFts5UnicodeMap[iRes]))&int32(0x01) != 0 {
		v1 = int32(5)
	} else {
		v1 = int32(9)
	}
	return v1
}

func _sqlite3Fts5UnicodeAscii(tls *libc.TLS, aArray uintptr, aAscii uintptr) {
	var bToken, i, iTbl, n int32
	_, _, _, _ = bToken, i, iTbl, n
	i = 0
	iTbl = 0
	for i < int32(128) {
		bToken = int32(*(*Tu8)(unsafe.Pointer(aArray + uintptr(int32(_aFts5UnicodeData[iTbl])&int32(0x1F)))))
		n = int32(_aFts5UnicodeData[iTbl])>>int32(5) + i
		for {
			if !(i < int32(128) && i < n) {
				break
			}
			*(*Tu8)(unsafe.Pointer(aAscii + uintptr(i))) = uint8(uint8(bToken))
			goto _1
		_1:
			;
			i++
		}
		iTbl++
	}
	*(*Tu8)(unsafe.Pointer(aAscii)) = uint8(0) /* 0x00 is never a token character */
}

/*
** 2015 May 30
**
** 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.
**
******************************************************************************
**
** Routines for varint serialization and deserialization.
 */

/* #include "fts5Int.h" */

// C documentation
//
//	/*
//	** This is a copy of the sqlite3GetVarint32() routine from the SQLite core.
//	** Except, this version does handle the single byte case that the core
//	** version depends on being handled before its function is called.
//	*/
func _sqlite3Fts5GetVarint32(tls *libc.TLS, p uintptr, v uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var a, b Tu32
	var n Tu8
	var _ /* v64 at bp+0 */ Tu64
	_, _, _ = a, b, n
	/* The 1-byte case. Overwhelmingly the most common. */
	a = uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p0 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		/* Values between 0 and 127 */
		*(*Tu32)(unsafe.Pointer(v)) = a
		return int32(1)
	}
	/* The 2-byte case */
	p++
	b = uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p1 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		/* Values between 128 and 16383 */
		a &= uint32(0x7f)
		a = a << int32(7)
		*(*Tu32)(unsafe.Pointer(v)) = a | b
		return int32(2)
	}
	/* The 3-byte case */
	p++
	a = a << int32(14)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p0<<14 | p2 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		/* Values between 16384 and 2097151 */
		a &= uint32(libc.Int32FromInt32(0x7f)<<libc.Int32FromInt32(14) | libc.Int32FromInt32(0x7f))
		b &= uint32(0x7f)
		b = b << int32(7)
		*(*Tu32)(unsafe.Pointer(v)) = a | b
		return int32(3)
	}
	/* A 32-bit varint is used to store size information in btrees.
	 ** Objects are rarely larger than 2MiB limit of a 3-byte varint.
	 ** A 3-byte varint is sufficient, for example, to record the size
	 ** of a 1048569-byte BLOB or string.
	 **
	 ** We only unroll the first 1-, 2-, and 3- byte cases.  The very
	 ** rare larger cases can be handled by the slower 64-bit varint
	 ** routine.
	 */
	p -= uintptr(2)
	n = _sqlite3Fts5GetVarint(tls, p, bp)
	*(*Tu32)(unsafe.Pointer(v)) = uint32(*(*Tu64)(unsafe.Pointer(bp))) & uint32(0x7FFFFFFF)
	return int32(int32(n))
	return r
}

/*
** Bitmasks used by sqlite3GetVarint().  These precomputed constants
** are defined here rather than simply putting the constant expressions
** inline in order to work around bugs in the RVT compiler.
**
** SLOT_2_0     A mask for  (0x7f<<14) | 0x7f
**
** SLOT_4_2_0   A mask for  (0x7f<<28) | SLOT_2_0
 */

// C documentation
//
//	/*
//	** Read a 64-bit variable-length integer from memory starting at p[0].
//	** Return the number of bytes read.  The value is stored in *v.
//	*/
func _sqlite3Fts5GetVarint(tls *libc.TLS, p uintptr, v uintptr) (r Tu8) {
	var a, b, s Tu32
	_, _, _ = a, b, s
	a = uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p0 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(a))
		return uint8(1)
	}
	p++
	b = uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p1 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		a &= uint32(0x7f)
		a = a << int32(7)
		a |= b
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(a))
		return uint8(2)
	}
	/* Verify that constants are precomputed correctly */
	p++
	a = a << int32(14)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p0<<14 | p2 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		a &= uint32(SLOT_2_0)
		b &= uint32(0x7f)
		b = b << int32(7)
		a |= b
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(a))
		return uint8(3)
	}
	/* CSE1 from below */
	a &= uint32(SLOT_2_0)
	p++
	b = b << int32(14)
	b |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p1<<14 | p3 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		b &= uint32(SLOT_2_0)
		/* moved CSE1 up */
		/* a &= (0x7f<<14)|(0x7f); */
		a = a << int32(7)
		a |= b
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(a))
		return uint8(4)
	}
	/* a: p0<<14 | p2 (masked) */
	/* b: p1<<14 | p3 (unmasked) */
	/* 1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
	/* moved CSE1 up */
	/* a &= (0x7f<<14)|(0x7f); */
	b &= uint32(SLOT_2_0)
	s = a
	/* s: p0<<14 | p2 (masked) */
	p++
	a = a << int32(14)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p0<<28 | p2<<14 | p4 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		/* we can skip these cause they were (effectively) done above in calc'ing s */
		/* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
		/* b &= (0x7f<<14)|(0x7f); */
		b = b << int32(7)
		a |= b
		s = s >> int32(18)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(5)
	}
	/* 2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
	s = s << int32(7)
	s |= b
	/* s: p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
	p++
	b = b << int32(14)
	b |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p1<<28 | p3<<14 | p5 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		/* we can skip this cause it was (effectively) done above in calc'ing s */
		/* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
		a &= uint32(SLOT_2_0)
		a = a << int32(7)
		a |= b
		s = s >> int32(18)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(6)
	}
	p++
	a = a << int32(14)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p2<<28 | p4<<14 | p6 (unmasked) */
	if !(a&libc.Uint32FromInt32(0x80) != 0) {
		a &= uint32(SLOT_4_2_0)
		b &= uint32(SLOT_2_0)
		b = b << int32(7)
		a |= b
		s = s >> int32(11)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(7)
	}
	/* CSE2 from below */
	a &= uint32(SLOT_2_0)
	p++
	b = b << int32(14)
	b |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* b: p3<<28 | p5<<14 | p7 (unmasked) */
	if !(b&libc.Uint32FromInt32(0x80) != 0) {
		b &= uint32(SLOT_4_2_0)
		/* moved CSE2 up */
		/* a &= (0x7f<<14)|(0x7f); */
		a = a << int32(7)
		a |= b
		s = s >> int32(4)
		*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
		return uint8(8)
	}
	p++
	a = a << int32(15)
	a |= uint32(*(*uint8)(unsafe.Pointer(p)))
	/* a: p4<<29 | p6<<15 | p8 (unmasked) */
	/* moved CSE2 up */
	/* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
	b &= uint32(SLOT_2_0)
	b = b << int32(8)
	a |= b
	s = s << int32(4)
	b = uint32(*(*uint8)(unsafe.Pointer(p + uintptr(-libc.Int32FromInt32(4)))))
	b &= uint32(0x7f)
	b = b >> int32(3)
	s |= b
	*(*Tu64)(unsafe.Pointer(v)) = uint64(uint64(s))<<int32(32) | uint64(uint64(a))
	return uint8(9)
}

/*
** The variable-length integer encoding is as follows:
**
** KEY:
**         A = 0xxxxxxx    7 bits of data and one flag bit
**         B = 1xxxxxxx    7 bits of data and one flag bit
**         C = xxxxxxxx    8 bits of data
**
**  7 bits - A
** 14 bits - BA
** 21 bits - BBA
** 28 bits - BBBA
** 35 bits - BBBBA
** 42 bits - BBBBBA
** 49 bits - BBBBBBA
** 56 bits - BBBBBBBA
** 64 bits - BBBBBBBBC
 */

// C documentation
//
//	/*
//	** Write a 64-bit variable-length integer to memory starting at p[0].
//	** The length of data write will be between 1 and 9 bytes.  The number
//	** of bytes written is returned.
//	**
//	** A variable-length integer consists of the lower 7 bits of each byte
//	** for all bytes that have the 8th bit set and one byte with the 8th
//	** bit clear.  Except, if we get to the 9th byte, it stores the full
//	** 8 bits and is the last byte.
//	*/
func _fts5PutVarint64(tls *libc.TLS, p uintptr, v Tu64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, j, n, v2 int32
	var p3 uintptr
	var _ /* buf at bp+0 */ [10]Tu8
	_, _, _, _, _ = i, j, n, v2, p3
	if v&(libc.Uint64FromUint32(0xff000000)<<libc.Int32FromInt32(32)) != 0 {
		*(*uint8)(unsafe.Pointer(p + 8)) = uint8(uint8(v))
		v >>= uint64(8)
		i = int32(7)
		for {
			if !(i >= 0) {
				break
			}
			*(*uint8)(unsafe.Pointer(p + uintptr(i))) = uint8(v&libc.Uint64FromInt32(0x7f) | libc.Uint64FromInt32(0x80))
			v >>= uint64(7)
			goto _1
		_1:
			;
			i--
		}
		return int32(9)
	}
	n = 0
	for cond := true; cond; cond = v != uint64(0) {
		v2 = n
		n++
		(*(*[10]Tu8)(unsafe.Pointer(bp)))[v2] = uint8(v&libc.Uint64FromInt32(0x7f) | libc.Uint64FromInt32(0x80))
		v >>= uint64(7)
	}
	p3 = bp
	*(*Tu8)(unsafe.Pointer(p3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(p3))) & libc.Int32FromInt32(0x7f))
	i = 0
	j = n - libc.Int32FromInt32(1)
	for {
		if !(j >= 0) {
			break
		}
		*(*uint8)(unsafe.Pointer(p + uintptr(i))) = (*(*[10]Tu8)(unsafe.Pointer(bp)))[j]
		goto _4
	_4:
		;
		j--
		i++
	}
	return n
}

func _sqlite3Fts5PutVarint(tls *libc.TLS, p uintptr, v Tu64) (r int32) {
	if v <= uint64(0x7f) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v & uint64(0x7f))
		return int32(1)
	}
	if v <= uint64(0x3fff) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v>>libc.Int32FromInt32(7)&uint64(0x7f) | uint64(0x80))
		*(*uint8)(unsafe.Pointer(p + 1)) = uint8(v & uint64(0x7f))
		return int32(2)
	}
	return _fts5PutVarint64(tls, p, v)
}

func _sqlite3Fts5GetVarintLen(tls *libc.TLS, iVal Tu32) (r int32) {
	if iVal < uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(14)) {
		return int32(2)
	}
	if iVal < uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(21)) {
		return int32(3)
	}
	if iVal < uint32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(28)) {
		return int32(4)
	}
	return int32(5)
}

/*
** 2015 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.
**
******************************************************************************
**
** This is an SQLite virtual table module implementing direct access to an
** existing FTS5 index. The module may create several different types of
** tables:
**
** col:
**     CREATE TABLE vocab(term, col, doc, cnt, PRIMARY KEY(term, col));
**
**   One row for each term/column combination. The value of $doc is set to
**   the number of fts5 rows that contain at least one instance of term
**   $term within column $col. Field $cnt is set to the total number of
**   instances of term $term in column $col (in any row of the fts5 table).
**
** row:
**     CREATE TABLE vocab(term, doc, cnt, PRIMARY KEY(term));
**
**   One row for each term in the database. The value of $doc is set to
**   the number of fts5 rows that contain at least one instance of term
**   $term. Field $cnt is set to the total number of instances of term
**   $term in the database.
**
** instance:
**     CREATE TABLE vocab(term, doc, col, offset, PRIMARY KEY(<all-fields>));
**
**   One row for each term instance in the database.
 */

/* #include "fts5Int.h" */

type TFts5VocabTable = struct {
	Fbase     Tsqlite3_vtab
	FzFts5Tbl uintptr
	FzFts5Db  uintptr
	Fdb       uintptr
	FpGlobal  uintptr
	FeType    int32
	FbBusy    uint32
}

type Fts5VocabTable = TFts5VocabTable

type TFts5VocabCursor = struct {
	F__ccgo_align   [0]uint32
	Fbase           Tsqlite3_vtab_cursor
	FpStmt          uintptr
	FpFts5          uintptr
	FbEof           int32
	FpIter          uintptr
	FpStruct        uintptr
	FnLeTerm        int32
	FzLeTerm        uintptr
	FiCol           int32
	FaCnt           uintptr
	FaDoc           uintptr
	F__ccgo_align11 [4]byte
	Frowid          Ti64
	Fterm           TFts5Buffer
	F__ccgo_align13 [4]byte
	FiInstPos       Ti64
	FiInstOff       int32
	F__ccgo_pad15   [4]byte
}

type Fts5VocabCursor = TFts5VocabCursor

type TFts5VocabTable1 = struct {
	Fbase     Tsqlite3_vtab
	FzFts5Tbl uintptr
	FzFts5Db  uintptr
	Fdb       uintptr
	FpGlobal  uintptr
	FeType    int32
	FbBusy    uint32
}

type Fts5VocabTable1 = TFts5VocabTable1

type TFts5VocabCursor1 = struct {
	F__ccgo_align   [0]uint32
	Fbase           Tsqlite3_vtab_cursor
	FpStmt          uintptr
	FpFts5          uintptr
	FbEof           int32
	FpIter          uintptr
	FpStruct        uintptr
	FnLeTerm        int32
	FzLeTerm        uintptr
	FiCol           int32
	FaCnt           uintptr
	FaDoc           uintptr
	F__ccgo_align11 [4]byte
	Frowid          Ti64
	Fterm           TFts5Buffer
	F__ccgo_align13 [4]byte
	FiInstPos       Ti64
	FiInstOff       int32
	F__ccgo_pad15   [4]byte
}

type Fts5VocabCursor1 = TFts5VocabCursor1

/*
** Bits for the mask used as the idxNum value by xBestIndex/xFilter.
 */

// C documentation
//
//	/*
//	** Translate a string containing an fts5vocab table type to an
//	** FTS5_VOCAB_XXX constant. If successful, set *peType to the output
//	** value and return SQLITE_OK. Otherwise, set *pzErr to an error message
//	** and return SQLITE_ERROR.
//	*/
func _fts5VocabTableType(tls *libc.TLS, zType uintptr, pzErr uintptr, peType uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zCopy uintptr
	var _ /* rc at bp+0 */ int32
	_ = zCopy
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	zCopy = _sqlite3Fts5Strndup(tls, bp, zType, -int32(1))
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		_sqlite3Fts5Dequote(tls, zCopy)
		if Xsqlite3_stricmp(tls, zCopy, __ccgo_ts+40602) == 0 {
			*(*int32)(unsafe.Pointer(peType)) = FTS5_VOCAB_COL
		} else {
			if Xsqlite3_stricmp(tls, zCopy, __ccgo_ts+40606) == 0 {
				*(*int32)(unsafe.Pointer(peType)) = int32(FTS5_VOCAB_ROW)
			} else {
				if Xsqlite3_stricmp(tls, zCopy, __ccgo_ts+40610) == 0 {
					*(*int32)(unsafe.Pointer(peType)) = int32(FTS5_VOCAB_INSTANCE)
				} else {
					*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+40619, libc.VaList(bp+16, zCopy))
					*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
				}
			}
		}
		Xsqlite3_free(tls, zCopy)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** The xDisconnect() virtual table method.
//	*/
func _fts5VocabDisconnectMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pTab uintptr
	_ = pTab
	pTab = pVtab
	Xsqlite3_free(tls, pTab)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** The xDestroy() virtual table method.
//	*/
func _fts5VocabDestroyMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pTab uintptr
	_ = pTab
	pTab = pVtab
	Xsqlite3_free(tls, pTab)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This function is the implementation of both the xConnect and xCreate
//	** methods of the FTS3 virtual table.
//	**
//	** The argv[] array contains the following:
//	**
//	**   argv[0]   -> module name  ("fts5vocab")
//	**   argv[1]   -> database name
//	**   argv[2]   -> table name
//	**
//	** then:
//	**
//	**   argv[3]   -> name of fts5 table
//	**   argv[4]   -> type of fts5vocab table
//	**
//	** or, for tables in the TEMP schema only.
//	**
//	**   argv[3]   -> name of fts5 tables database
//	**   argv[4]   -> name of fts5 table
//	**   argv[5]   -> type of fts5vocab table
//	*/
func _fts5VocabInitVtab(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVTab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azSchema [3]uintptr
	var bDb, nByte, nDb, nTab int32
	var pRet, zDb, zTab, zType, v1, v2, v3 uintptr
	var _ /* eType at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _ = azSchema, bDb, nByte, nDb, nTab, pRet, zDb, zTab, zType, v1, v2, v3
	azSchema = [3]uintptr{
		0: __ccgo_ts + 40653,
		1: __ccgo_ts + 40693,
		2: __ccgo_ts + 40728,
	}
	pRet = uintptr(0)
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	bDb = libc.BoolInt32(argc == int32(6) && libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 1*4))) == uint32(4) && libc.Xmemcmp(tls, __ccgo_ts+25191, *(*uintptr)(unsafe.Pointer(argv + 1*4)), uint32(4)) == 0)
	if argc != int32(5) && bDb == 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+40771, 0)
		*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
	} else {
		if bDb != 0 {
			v1 = *(*uintptr)(unsafe.Pointer(argv + 3*4))
		} else {
			v1 = *(*uintptr)(unsafe.Pointer(argv + 1*4))
		} /* Bytes of space to allocate */
		zDb = v1
		if bDb != 0 {
			v2 = *(*uintptr)(unsafe.Pointer(argv + 4*4))
		} else {
			v2 = *(*uintptr)(unsafe.Pointer(argv + 3*4))
		}
		zTab = v2
		if bDb != 0 {
			v3 = *(*uintptr)(unsafe.Pointer(argv + 5*4))
		} else {
			v3 = *(*uintptr)(unsafe.Pointer(argv + 4*4))
		}
		zType = v3
		nDb = int32(libc.Xstrlen(tls, zDb)) + int32(1)
		nTab = int32(libc.Xstrlen(tls, zTab)) + int32(1)
		*(*int32)(unsafe.Pointer(bp + 4)) = 0
		*(*int32)(unsafe.Pointer(bp)) = _fts5VocabTableType(tls, zType, pzErr, bp+4)
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_declare_vtab(tls, db, azSchema[*(*int32)(unsafe.Pointer(bp + 4))])
		}
		nByte = int32(uint32(36) + uint32(uint32(nDb)) + uint32(uint32(nTab)))
		pRet = _sqlite3Fts5MallocZero(tls, bp, int64(int64(nByte)))
		if pRet != 0 {
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FpGlobal = pAux
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FeType = *(*int32)(unsafe.Pointer(bp + 4))
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).Fdb = db
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl = pRet + 1*36
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db = (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl + uintptr(nTab)
			libc.Xmemcpy(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl, zTab, uint32(uint32(nTab)))
			libc.Xmemcpy(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db, zDb, uint32(uint32(nDb)))
			_sqlite3Fts5Dequote(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl)
			_sqlite3Fts5Dequote(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppVTab)) = pRet
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** The xConnect() and xCreate() methods for the virtual table. All the
//	** work is done in function fts5VocabInitVtab().
//	*/
func _fts5VocabConnectMethod(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _fts5VocabInitVtab(tls, db, pAux, argc, argv, ppVtab, pzErr)
}

func _fts5VocabCreateMethod(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _fts5VocabInitVtab(tls, db, pAux, argc, argv, ppVtab, pzErr)
}

// C documentation
//
//	/*
//	** Implementation of the xBestIndex method.
//	**
//	** Only constraints of the form:
//	**
//	**     term <= ?
//	**     term == ?
//	**     term >= ?
//	**
//	** are interpreted. Less-than and less-than-or-equal are treated
//	** identically, as are greater-than and greater-than-or-equal.
//	*/
func _fts5VocabBestIndexMethod(tls *libc.TLS, pUnused uintptr, pInfo uintptr) (r int32) {
	var i, iTermEq, iTermGe, iTermLe, idxNum, nArg, v2, v3, v4 int32
	var p uintptr
	_, _, _, _, _, _, _, _, _, _ = i, iTermEq, iTermGe, iTermLe, idxNum, nArg, p, v2, v3, v4
	iTermEq = -int32(1)
	iTermGe = -int32(1)
	iTermLe = -int32(1)
	idxNum = 0
	nArg = 0
	_ = pUnused
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint) {
			break
		}
		p = (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
		if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) == 0 {
			goto _1
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == 0 { /* term column */
			if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) {
				iTermEq = i
			}
			if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_LE) {
				iTermLe = i
			}
			if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_LT) {
				iTermLe = i
			}
			if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_GE) {
				iTermGe = i
			}
			if int32((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_GT) {
				iTermGe = i
			}
		}
		goto _1
	_1:
		;
		i++
	}
	if iTermEq >= 0 {
		idxNum |= int32(FTS5_VOCAB_TERM_EQ)
		nArg++
		v2 = nArg
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(iTermEq)*8))).FargvIndex = v2
		(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = libc.Float64FromInt32(100)
	} else {
		(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = libc.Float64FromInt32(1000000)
		if iTermGe >= 0 {
			idxNum |= int32(FTS5_VOCAB_TERM_GE)
			nArg++
			v3 = nArg
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(iTermGe)*8))).FargvIndex = v3
			(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost / libc.Float64FromInt32(2)
		}
		if iTermLe >= 0 {
			idxNum |= int32(FTS5_VOCAB_TERM_LE)
			nArg++
			v4 = nArg
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(iTermLe)*8))).FargvIndex = v4
			(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost / libc.Float64FromInt32(2)
		}
	}
	/* This virtual table always delivers results in ascending order of
	 ** the "term" column (column 0). So if the user has requested this
	 ** specifically - "ORDER BY term" or "ORDER BY term ASC" - set the
	 ** sqlite3_index_info.orderByConsumed flag to tell the core the results
	 ** are already in sorted order.  */
	if (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnOrderBy == int32(1) && (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).FiColumn == 0 && int32((*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).Fdesc) == 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).ForderByConsumed = int32(1)
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FidxNum = idxNum
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Implementation of xOpen method.
//	*/
func _fts5VocabOpenMethod(tls *libc.TLS, pVTab uintptr, ppCsr uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iId, nByte Ti64
	var pCsr, pFts5, pTab, zSql uintptr
	var _ /* pStmt at bp+4 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _ = iId, nByte, pCsr, pFts5, pTab, zSql
	pTab = pVTab
	pFts5 = uintptr(0)
	pCsr = uintptr(0)
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
	zSql = uintptr(0)
	if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FbBusy != 0 {
		(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+40804, libc.VaList(bp+16, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
		return int32(SQLITE_ERROR)
	}
	zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+40835, libc.VaList(bp+16, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
	if zSql != 0 {
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v2(tls, (*TFts5VocabTable)(unsafe.Pointer(pTab)).Fdb, zSql, -int32(1), bp+4, uintptr(0))
	}
	Xsqlite3_free(tls, zSql)
	if *(*int32)(unsafe.Pointer(bp)) == int32(SQLITE_ERROR) {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	}
	(*TFts5VocabTable)(unsafe.Pointer(pTab)).FbBusy = uint32(1)
	if *(*uintptr)(unsafe.Pointer(bp + 4)) != 0 && Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 4))) == int32(SQLITE_ROW) {
		iId = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 4)), 0)
		pFts5 = _sqlite3Fts5TableFromCsrid(tls, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FpGlobal, iId)
	}
	(*TFts5VocabTable)(unsafe.Pointer(pTab)).FbBusy = uint32(0)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		if pFts5 == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
			*(*uintptr)(unsafe.Pointer(bp + 4)) = uintptr(0)
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+40886, libc.VaList(bp+16, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
				*(*int32)(unsafe.Pointer(bp)) = int32(SQLITE_ERROR)
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5FlushToDisk(tls, pFts5)
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		nByte = int64(uint32((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pFts5)).FpConfig)).FnCol)*uint32(8)*uint32(2) + uint32(88))
		pCsr = _sqlite3Fts5MallocZero(tls, bp, nByte)
	}
	if pCsr != 0 {
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5 = pFts5
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStmt = *(*uintptr)(unsafe.Pointer(bp + 4))
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt = pCsr + 1*88
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pFts5)).FpConfig)).FnCol)*8
	} else {
		Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 4)))
	}
	*(*uintptr)(unsafe.Pointer(ppCsr)) = pCsr
	return *(*int32)(unsafe.Pointer(bp))
}

func _fts5VocabResetCursor(tls *libc.TLS, pCsr uintptr) {
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid = 0
	_sqlite3Fts5IterClose(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)
	_sqlite3Fts5StructureRelease(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct)
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct = uintptr(0)
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter = uintptr(0)
	Xsqlite3_free(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm)
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm = -int32(1)
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm = uintptr(0)
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = 0
}

// C documentation
//
//	/*
//	** Close the cursor.  For additional information see the documentation
//	** on the xClose method of the virtual table interface.
//	*/
func _fts5VocabCloseMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCursor
	_fts5VocabResetCursor(tls, pCsr)
	_sqlite3Fts5BufferFree(tls, pCsr+56)
	Xsqlite3_finalize(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStmt)
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

func _fts5VocabInstanceNewTerm(tls *libc.TLS, pCsr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bCmp, nCmp, v1 int32
	var zTerm uintptr
	var _ /* nTerm at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = bCmp, nCmp, zTerm, v1
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	if (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = int32(1)
	} else {
		zTerm = _sqlite3Fts5IterTerm(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter, bp+4)
		if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm >= 0 {
			if *(*int32)(unsafe.Pointer(bp + 4)) < (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm {
				v1 = *(*int32)(unsafe.Pointer(bp + 4))
			} else {
				v1 = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm
			}
			nCmp = v1
			bCmp = libc.Xmemcmp(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zTerm, uint32(uint32(nCmp)))
			if bCmp < 0 || bCmp == 0 && (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm < *(*int32)(unsafe.Pointer(bp + 4)) {
				(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = int32(1)
			}
		}
		_sqlite3Fts5BufferSet(tls, bp, pCsr+56, *(*int32)(unsafe.Pointer(bp + 4)), zTerm)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func _fts5VocabInstanceNext(tls *libc.TLS, pCsr uintptr) (r int32) {
	var eDetail, rc int32
	var pIter, po, pp uintptr
	_, _, _, _, _ = eDetail, pIter, po, pp, rc
	eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail
	rc = SQLITE_OK
	pIter = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter
	pp = pCsr + 72
	po = pCsr + 80
	for eDetail == int32(FTS5_DETAIL_NONE) || _sqlite3Fts5PoslistNext64(tls, (*TFts5IndexIter)(unsafe.Pointer(pIter)).FpData, (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData, po, pp) != 0 {
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos = 0
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstOff = 0
		rc = _sqlite3Fts5IterNextScan(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)
		if rc == SQLITE_OK {
			rc = _fts5VocabInstanceNewTerm(tls, pCsr)
			if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof != 0 || eDetail == int32(FTS5_DETAIL_NONE) {
				break
			}
		}
		if rc != 0 {
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = int32(1)
			break
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Advance the cursor to the next row in the table.
//	*/
func _fts5VocabNextMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bCmp, eDetail, iCol, ii, nCmp, nCol, nPos, v2 int32
	var pCsr, pPos, pTab, zTerm uintptr
	var _ /* iOff at bp+16 */ int32
	var _ /* iPos at bp+8 */ Ti64
	var _ /* nTerm at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _ = bCmp, eDetail, iCol, ii, nCmp, nCol, nPos, pCsr, pPos, pTab, zTerm, v2
	pCsr = pCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FnCol
	*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5StructureTest(tls, (*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpIndex, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct)
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp))
	}
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid++
	if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType == int32(FTS5_VOCAB_INSTANCE) {
		return _fts5VocabInstanceNext(tls, pCsr)
	}
	if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_COL {
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol++
		for {
			if !((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol < nCol) {
				break
			}
			if *(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8)) != 0 {
				break
			}
			goto _1
		_1:
			;
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol++
		}
	}
	if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType != FTS5_VOCAB_COL || (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol >= nCol {
		if (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = int32(1)
		} else {
			zTerm = _sqlite3Fts5IterTerm(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter, bp+4)
			if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm >= 0 {
				if *(*int32)(unsafe.Pointer(bp + 4)) < (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm {
					v2 = *(*int32)(unsafe.Pointer(bp + 4))
				} else {
					v2 = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm
				}
				nCmp = v2
				bCmp = libc.Xmemcmp(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zTerm, uint32(uint32(nCmp)))
				if bCmp < 0 || bCmp == 0 && (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm < *(*int32)(unsafe.Pointer(bp + 4)) {
					(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = int32(1)
					return SQLITE_OK
				}
			}
			_sqlite3Fts5BufferSet(tls, bp, pCsr+56, *(*int32)(unsafe.Pointer(bp + 4)), zTerm)
			libc.Xmemset(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt, 0, uint32(uint32(nCol))*uint32(8))
			libc.Xmemset(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc, 0, uint32(uint32(nCol))*uint32(8))
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol = 0
			for *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail /* Position list */
				*(*Ti64)(unsafe.Pointer(bp + 8)) = 0                                                                                                        /* 64-bit position read from poslist */
				*(*int32)(unsafe.Pointer(bp + 16)) = 0                                                                                                      /* Current offset within position list */
				pPos = (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FpData
				nPos = (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FnData
				switch (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType {
				case int32(FTS5_VOCAB_ROW):
					if eDetail == FTS5_DETAIL_FULL {
						for 0 == _sqlite3Fts5PoslistNext64(tls, pPos, nPos, bp+16, bp+8) {
							*(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt))++
						}
					}
					*(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc))++
				case FTS5_VOCAB_COL:
					if eDetail == FTS5_DETAIL_FULL {
						iCol = -int32(1)
						for 0 == _sqlite3Fts5PoslistNext64(tls, pPos, nPos, bp+16, bp+8) {
							ii = int32(*(*Ti64)(unsafe.Pointer(bp + 8)) >> libc.Int32FromInt32(32))
							if iCol != ii {
								if ii >= nCol {
									*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
									break
								}
								*(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr(ii)*8))++
								iCol = ii
							}
							*(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr(ii)*8))++
						}
					} else {
						if eDetail == int32(FTS5_DETAIL_COLUMNS) {
							for 0 == _sqlite3Fts5PoslistNext64(tls, pPos, nPos, bp+16, bp+8) {
								if *(*Ti64)(unsafe.Pointer(bp + 8)) >= int64(int64(nCol)) {
									*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
									break
								}
								*(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr(*(*Ti64)(unsafe.Pointer(bp + 8)))*8))++
							}
						} else {
							*(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc))++
						}
					}
				default:
					break
				}
				if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
					*(*int32)(unsafe.Pointer(bp)) = _sqlite3Fts5IterNextScan(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)
				}
				if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType == int32(FTS5_VOCAB_INSTANCE) {
					break
				}
				if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
					zTerm = _sqlite3Fts5IterTerm(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter, bp+4)
					if *(*int32)(unsafe.Pointer(bp + 4)) != (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fn || *(*int32)(unsafe.Pointer(bp + 4)) > 0 && libc.Xmemcmp(tls, zTerm, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fp, uint32(*(*int32)(unsafe.Pointer(bp + 4)))) != 0 {
						break
					}
					if (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
						break
					}
				}
			}
		}
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof == 0 && (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_COL {
		for {
			if !((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol < nCol && *(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8)) == 0) {
				break
			}
			goto _3
		_3:
			;
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol++
		}
		if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol == nCol {
			*(*int32)(unsafe.Pointer(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

// C documentation
//
//	/*
//	** This is the xFilter implementation for the virtual table.
//	*/
func _fts5VocabFilterMethod(tls *libc.TLS, pCursor uintptr, idxNum int32, zUnused uintptr, nUnused int32, apVal uintptr) (r int32) {
	var eType, f, iVal, nTerm, rc, v1, v2, v3 int32
	var pCsr, pEq, pGe, pIndex, pLe, pTab, zCopy, zTerm uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = eType, f, iVal, nTerm, pCsr, pEq, pGe, pIndex, pLe, pTab, rc, zCopy, zTerm, v1, v2, v3
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pCsr = pCursor
	eType = (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType
	rc = SQLITE_OK
	iVal = 0
	f = int32(FTS5INDEX_QUERY_SCAN)
	zTerm = uintptr(0)
	nTerm = 0
	pEq = uintptr(0)
	pGe = uintptr(0)
	pLe = uintptr(0)
	_ = zUnused
	_ = nUnused
	_fts5VocabResetCursor(tls, pCsr)
	if idxNum&int32(FTS5_VOCAB_TERM_EQ) != 0 {
		v1 = iVal
		iVal++
		pEq = *(*uintptr)(unsafe.Pointer(apVal + uintptr(v1)*4))
	}
	if idxNum&int32(FTS5_VOCAB_TERM_GE) != 0 {
		v2 = iVal
		iVal++
		pGe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(v2)*4))
	}
	if idxNum&int32(FTS5_VOCAB_TERM_LE) != 0 {
		v3 = iVal
		iVal++
		pLe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(v3)*4))
	}
	if pEq != 0 {
		zTerm = Xsqlite3_value_text(tls, pEq)
		nTerm = Xsqlite3_value_bytes(tls, pEq)
		f = int32(FTS5INDEX_QUERY_NOTOKENDATA)
	} else {
		if pGe != 0 {
			zTerm = Xsqlite3_value_text(tls, pGe)
			nTerm = Xsqlite3_value_bytes(tls, pGe)
		}
		if pLe != 0 {
			zCopy = Xsqlite3_value_text(tls, pLe)
			if zCopy == uintptr(0) {
				zCopy = __ccgo_ts + 1672
			}
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm = Xsqlite3_value_bytes(tls, pLe)
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm = Xsqlite3_malloc(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm+int32(1))
			if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemcpy(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zCopy, uint32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm+int32(1)))
			}
		}
	}
	if rc == SQLITE_OK {
		pIndex = (*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpIndex
		rc = _sqlite3Fts5IndexQuery(tls, pIndex, zTerm, nTerm, f, uintptr(0), pCsr+16)
		if rc == SQLITE_OK {
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct = _sqlite3Fts5StructureRef(tls, pIndex)
		}
	}
	if rc == SQLITE_OK && eType == int32(FTS5_VOCAB_INSTANCE) {
		rc = _fts5VocabInstanceNewTerm(tls, pCsr)
	}
	if rc == SQLITE_OK && !((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof != 0) && (eType != int32(FTS5_VOCAB_INSTANCE) || (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail != int32(FTS5_DETAIL_NONE)) {
		rc = _fts5VocabNextMethod(tls, pCursor)
	}
	return rc
}

// C documentation
//
//	/*
//	** This is the xEof method of the virtual table. SQLite calls this
//	** routine to find out if it has reached the end of a result set.
//	*/
func _fts5VocabEofMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCursor
	return (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof
}

func _fts5VocabColumnMethod(tls *libc.TLS, pCursor uintptr, pCtx uintptr, iCol int32) (r int32) {
	var eDetail, eType, ii, ii1 int32
	var iVal Ti64
	var pCsr, z, z1 uintptr
	_, _, _, _, _, _, _, _ = eDetail, eType, iVal, ii, ii1, pCsr, z, z1
	pCsr = pCursor
	eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail
	eType = (*TFts5VocabTable)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FeType
	iVal = 0
	if iCol == 0 {
		Xsqlite3_result_text(tls, pCtx, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fp, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fn, uintptr(-libc.Int32FromInt32(1)))
	} else {
		if eType == FTS5_VOCAB_COL {
			if iCol == int32(1) {
				if eDetail != int32(FTS5_DETAIL_NONE) {
					z = *(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FazCol + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*4))
					Xsqlite3_result_text(tls, pCtx, z, -int32(1), libc.UintptrFromInt32(0))
				}
			} else {
				if iCol == int32(2) {
					iVal = *(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8))
				} else {
					iVal = *(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8))
				}
			}
		} else {
			if eType == int32(FTS5_VOCAB_ROW) {
				if iCol == int32(1) {
					iVal = *(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc))
				} else {
					iVal = *(*Ti64)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt))
				}
			} else {
				switch iCol {
				case int32(1):
					Xsqlite3_result_int64(tls, pCtx, (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FiRowid)
				case int32(2):
					ii = -int32(1)
					if eDetail == FTS5_DETAIL_FULL {
						ii = int32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos >> libc.Int32FromInt32(32))
					} else {
						if eDetail == int32(FTS5_DETAIL_COLUMNS) {
							ii = int32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos)
						}
					}
					if ii >= 0 && ii < (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FnCol {
						z1 = *(*uintptr)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FazCol + uintptr(ii)*4))
						Xsqlite3_result_text(tls, pCtx, z1, -int32(1), libc.UintptrFromInt32(0))
					}
				default:
					if eDetail == FTS5_DETAIL_FULL {
						ii1 = int32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos & libc.Int64FromInt32(0x7FFFFFFF))
						Xsqlite3_result_int(tls, pCtx, ii1)
					}
					break
				}
			}
		}
	}
	if iVal > 0 {
		Xsqlite3_result_int64(tls, pCtx, iVal)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This is the xRowid method. The SQLite core calls this routine to
//	** retrieve the rowid for the current row of the result set. The
//	** rowid should be written to *pRowid.
//	*/
func _fts5VocabRowidMethod(tls *libc.TLS, pCursor uintptr, pRowid uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCursor
	*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid
	return SQLITE_OK
}

func _sqlite3Fts5VocabInit(tls *libc.TLS, pGlobal uintptr, db uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pGlobal
	return Xsqlite3_create_module_v2(tls, db, __ccgo_ts+40912, uintptr(unsafe.Pointer(&_fts5Vocab)), p, uintptr(0))
}

var _fts5Vocab = Tsqlite3_module{
	FiVersion: int32(2),
}

func init() {
	p := unsafe.Pointer(&_fts5Vocab)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_fts5VocabCreateMethod)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_fts5VocabConnectMethod)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_fts5VocabBestIndexMethod)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_fts5VocabDisconnectMethod)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_fts5VocabDestroyMethod)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_fts5VocabOpenMethod)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_fts5VocabCloseMethod)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_fts5VocabFilterMethod)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_fts5VocabNextMethod)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_fts5VocabEofMethod)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_fts5VocabColumnMethod)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_fts5VocabRowidMethod)
}

/************** End of fts5.c ************************************************/
/************** Begin file stmt.c ********************************************/
/*
** 2017-05-31
**
** 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 demonstrates an eponymous virtual table that returns information
** about all prepared statements for the database connection.
**
** Usage example:
**
**     .load ./stmt
**     .mode line
**     .header on
**     SELECT * FROM stmt;
 */

// C documentation
//
//	/************** End of stmt.c ************************************************/
//	/* Return the source-id for this library */
func Xsqlite3_sourceid(tls *libc.TLS) (r uintptr) {
	return __ccgo_ts + 40922
}

type TAggInfo_col = struct {
	FpTab          uintptr
	FpCExpr        uintptr
	FiTable        int32
	FiColumn       Ti16
	FiSorterColumn Ti16
}

type AggInfo_col = TAggInfo_col

type TAggInfo_func = struct {
	FpFExpr      uintptr
	FpFunc       uintptr
	FiDistinct   int32
	FiDistAddr   int32
	FiOBTab      int32
	FbOBPayload  Tu8
	FbOBUnique   Tu8
	FbUseSubtype Tu8
}

type AggInfo_func = TAggInfo_func

type TIdList_item = struct {
	FzName uintptr
	Fu4    struct {
		FpExpr [0]uintptr
		Fidx   int32
	}
}

type IdList_item = TIdList_item

type TInLoop = struct {
	FiCur       int32
	FaddrInTop  int32
	FiBase      int32
	FnPrefix    int32
	FeEndLoopOp Tu8
}

type InLoop = TInLoop

type TShmRegion = struct {
	FhMap THANDLE
	FpMap uintptr
}

type ShmRegion = TShmRegion

type TWalSegment = struct {
	FiNext  int32
	FaIndex uintptr
	FaPgno  uintptr
	FnEntry int32
	FiZero  int32
}

type WalSegment = TWalSegment

type T_STGMEDIUM_UNION = struct {
	Ftymed TDWORD
	Fu     t__WIDL_objidl_generated_name_0000000D
}

type _STGMEDIUM_UNION = T_STGMEDIUM_UNION

type T_ht = struct {
	Fcount uint32
	Fchain uintptr
}

type _ht = T_ht

type TsColMap = struct {
	FiFrom int32
	FzCol  uintptr
}

type sColMap = TsColMap

type Tsqlite3InitInfo = struct {
	FnewTnum       TPgno
	FiDb           Tu8
	Fbusy          Tu8
	F__ccgo_align3 [2]byte
	F__ccgo8       uint8
	FazInit        uintptr
}

type sqlite3InitInfo = Tsqlite3InitInfo

type Tsqlite3_index_constraint = struct {
	FiColumn     int32
	Fop          uint8
	Fusable      uint8
	FiTermOffset int32
}

type sqlite3_index_constraint = Tsqlite3_index_constraint

type Tsqlite3_index_constraint_usage = struct {
	FargvIndex int32
	Fomit      uint8
}

type sqlite3_index_constraint_usage = Tsqlite3_index_constraint_usage

type Tsqlite3_index_orderby = struct {
	FiColumn int32
	Fdesc    uint8
}

type sqlite3_index_orderby = Tsqlite3_index_orderby

type TMemValue = struct {
	F__ccgo_align [0]uint32
	Fi            [0]int64
	FnZero        [0]int32
	FzPType       [0]uintptr
	FpDef         [0]uintptr
	Fr            float64
}

type MemValue = TMemValue

type t__WIDL_oaidl_generated_name_0000000E = struct {
	FUnknownStr   [0]TSAFEARR_UNKNOWN
	FDispatchStr  [0]TSAFEARR_DISPATCH
	FVariantStr   [0]TSAFEARR_VARIANT
	FRecordStr    [0]TSAFEARR_BRECORD
	FHaveIidStr   [0]TSAFEARR_HAVEIID
	FByteStr      [0]TBYTE_SIZEDARR
	FWordStr      [0]TWORD_SIZEDARR
	FLongStr      [0]TDWORD_SIZEDARR
	FHyperStr     [0]THYPER_SIZEDARR
	FBstrStr      TSAFEARR_BSTR
	F__ccgo_pad10 [16]byte
}

type t__WIDL_objidl_generated_name_0000000C = struct {
	FhPalette [0]TwireHPALETTE
	FhGeneric [0]TwireHGLOBAL
	FhBitmap  TwireHBITMAP
}

type t__WIDL_objidl_generated_name_0000000D = struct {
	FhHEnhMetaFile [0]TwireHENHMETAFILE
	FhGdiHandle    [0]uintptr
	FhGlobal       [0]TwireHGLOBAL
	FlpszFileName  [0]TLPOLESTR
	Fpstm          [0]uintptr
	Fpstg          [0]uintptr
	FhMetaFilePict TwireHMETAFILEPICT
}

type t__WIDL_wtypes_generated_name_00000001 = struct {
	FpwszName [0]uintptr
	FdwValue  TDWORD
}

type t__WIDL_wtypes_generated_name_00000002 = struct {
	FhRemote [0]uintptr
	FhInproc TLONG
}

type t__WIDL_wtypes_generated_name_00000003 = struct {
	F__ccgo_align [0]uint32
	FhRemote      [0]uintptr
	FhInproc64    [0]TINT64
	FhInproc      TLONG
	F__ccgo_pad3  [4]byte
}

type t__WIDL_wtypes_generated_name_00000004 = struct {
	F__ccgo_align [0]uint32
	FhRemote      [0]uintptr
	FhInproc64    [0]TINT64
	FhInproc      TLONG
	F__ccgo_pad3  [4]byte
}

type t__WIDL_wtypes_generated_name_00000005 = struct {
	F__ccgo_align [0]uint32
	FhRemote      [0]uintptr
	FhInproc64    [0]TINT64
	FhInproc      TLONG
	F__ccgo_pad3  [4]byte
}

type t__WIDL_wtypes_generated_name_00000006 = struct {
	F__ccgo_align [0]uint32
	FhRemote      [0]uintptr
	FhInproc64    [0]TINT64
	FhInproc      TLONG
	F__ccgo_pad3  [4]byte
}

type t__WIDL_wtypes_generated_name_00000007 = struct {
	F__ccgo_align [0]uint32
	FhRemote      [0]uintptr
	FhInproc64    [0]TINT64
	FhInproc      TLONG
	F__ccgo_pad3  [4]byte
}

type t__WIDL_wtypes_generated_name_00000008 = struct {
	F__ccgo_align [0]uint32
	FhRemote      [0]uintptr
	FhInproc64    [0]TINT64
	FhInproc      TLONG
	F__ccgo_pad3  [4]byte
}

type t__WIDL_wtypes_generated_name_00000009 = struct {
	FhRemote [0]TLONG
	FhInproc TLONG
}

type t__WIDL_wtypes_generated_name_0000000A = struct {
	FpFileExt  [0]TLPOLESTR
	FpMimeType [0]TLPOLESTR
	FpProgId   [0]TLPOLESTR
	FpFileName [0]TLPOLESTR
	FByName    [0]struct {
		FpPackageName TLPOLESTR
		FPolicyId     TGUID
	}
	FByObjectId [0]struct {
		FObjectId TGUID
		FPolicyId TGUID
	}
	Fclsid       TCLSID
	F__ccgo_pad7 [16]byte
}

type Tp4union = struct {
	Fp        [0]uintptr
	Fz        [0]uintptr
	FpI64     [0]uintptr
	FpReal    [0]uintptr
	FpFunc    [0]uintptr
	FpCtx     [0]uintptr
	FpColl    [0]uintptr
	FpMem     [0]uintptr
	FpVtab    [0]uintptr
	FpKeyInfo [0]uintptr
	Fai       [0]uintptr
	FpProgram [0]uintptr
	FpTab     [0]uintptr
	Fi        int32
}

type p4union = Tp4union

func __ccgo_fp(f interface{}) uintptr {
	type iface [2]uintptr
	return (*iface)(unsafe.Pointer(&f))[1]
}

// C documentation
//
//	/*
//	** If the following global variable points to a string which is the
//	** name of a directory, then that directory will be used to store
//	** all database files specified with a relative pathname.
//	**
//	** See also the "PRAGMA data_store_directory" SQL command.
//	*/
var Xsqlite3_data_directory uintptr

/*
** When compiling the test fixture or with debugging enabled (on Win32),
** this variable being set to non-zero will cause OSTRACE macros to emit
** extra diagnostic information.
 */

// C documentation
//
//	/*
//	** If the following global variable points to a string which is the
//	** name of a directory, then that directory will be used to store
//	** temporary files.
//	**
//	** See also the "PRAGMA temp_store_directory" SQL command.
//	*/
var Xsqlite3_temp_directory uintptr

/* for backward compatibility */

/* Use GCC builtins */

/* Copyright (C) 1989-2022 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */

/*
 * ISO C Standard:  7.15  Variable arguments  <stdarg.h>
 */

/*
** Make sure we can call this stuff from C++.
 */

/*
** Facilitate override of interface linkage and calling conventions.
** Be aware that these macros may not be used within this particular
** translation of the amalgamation and its associated header file.
**
** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
** compiler that the target identifier should have external linkage.
**
** The SQLITE_CDECL macro is used to set the calling convention for
** public functions that accept a variable number of arguments.
**
** The SQLITE_APICALL macro is used to set the calling convention for
** public functions that accept a fixed number of arguments.
**
** The SQLITE_STDCALL macro is no longer used and is now deprecated.
**
** The SQLITE_CALLBACK macro is used to set the calling convention for
** function pointers.
**
** The SQLITE_SYSAPI macro is used to set the calling convention for
** functions provided by the operating system.
**
** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
** SQLITE_SYSAPI macros are used only when building for environments
** that require non-default calling conventions.
 */

/*
** These no-op macros are used in front of interfaces to mark those
** interfaces as either deprecated or experimental.  New applications
** should not use deprecated interfaces - they are supported for backwards
** compatibility only.  Application writers should be aware that
** experimental interfaces are subject to change in point releases.
**
** These macros used to resolve to various kinds of compiler magic that
** would generate warning messages when they were used.  But that
** compiler magic ended up generating such a flurry of bug reports
** that we have taken it all out and gone back to using simple
** noop macros.
 */

/*
** Ensure these symbols were not defined by some previous header file.
 */

/*
** CAPI3REF: Compile-Time Library Version Numbers
**
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
** evaluates to a string literal that is the SQLite version in the
** format "X.Y.Z" where X is the major version number (always 3 for
** SQLite3) and Y is the minor version number and Z is the release number.)^
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
** numbers used in [SQLITE_VERSION].)^
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
** be larger than the release from which it is derived.  Either Y will
** be held constant and Z will be incremented or else Y will be incremented
** and Z will be reset to zero.
**
** Since [version 3.6.18] ([dateof:3.6.18]),
** SQLite source code has been stored in the
** <a href="http://www.fossil-scm.org/">Fossil configuration management
** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
** a string which identifies a particular check-in of SQLite
** within its configuration management system.  ^The SQLITE_SOURCE_ID
** string contains the date and time of the check-in (UTC) and a SHA1
** or SHA3-256 hash of the entire source tree.  If the source code has
** been edited in any way since it was last checked in, then the last
** four hexadecimal digits of the hash may be modified.
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
 */

// C documentation
//
//	/*
//	** CAPI3REF: Run-Time Library Version Numbers
//	** KEYWORDS: sqlite3_version sqlite3_sourceid
//	**
//	** These interfaces provide the same information as the [SQLITE_VERSION],
//	** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
//	** but are associated with the library instead of the header file.  ^(Cautious
//	** programmers might include assert() statements in their application to
//	** verify that values returned by these interfaces match the macros in
//	** the header, and thus ensure that the application is
//	** compiled with matching library and header files.
//	**
//	** <blockquote><pre>
//	** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
//	** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
//	** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
//	** </pre></blockquote>)^
//	**
//	** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
//	** macro.  ^The sqlite3_libversion() function returns a pointer to the
//	** to the sqlite3_version[] string constant.  The sqlite3_libversion()
//	** function is provided for use in DLLs since DLL users usually do not have
//	** direct access to string constants within the DLL.  ^The
//	** sqlite3_libversion_number() function returns an integer equal to
//	** [SQLITE_VERSION_NUMBER].  ^(The sqlite3_sourceid() function returns
//	** a pointer to a string constant whose value is the same as the
//	** [SQLITE_SOURCE_ID] C preprocessor macro.  Except if SQLite is built
//	** using an edited copy of [the amalgamation], then the last four characters
//	** of the hash might be different from [SQLITE_SOURCE_ID].)^
//	**
//	** See also: [sqlite_version()] and [sqlite_source_id()].
//	*/
var Xsqlite3_version = [7]int8{'3', '.', '4', '6', '.', '0'}

var __ccgo_ts = (*reflect.StringHeader)(unsafe.Pointer(&__ccgo_ts1)).Data

var __ccgo_ts1 = "ATOMIC_INTRINSICS=1\x00COMPILER=gcc-12-win32\x00DEFAULT_AUTOVACUUM\x00DEFAULT_CACHE_SIZE=-2000\x00DEFAULT_FILE_FORMAT=4\x00DEFAULT_JOURNAL_SIZE_LIMIT=-1\x00DEFAULT_MEMSTATUS=0\x00DEFAULT_MMAP_SIZE=0\x00DEFAULT_PAGE_SIZE=4096\x00DEFAULT_PCACHE_INITSZ=20\x00DEFAULT_RECURSIVE_TRIGGERS\x00DEFAULT_SECTOR_SIZE=4096\x00DEFAULT_SYNCHRONOUS=2\x00DEFAULT_WAL_AUTOCHECKPOINT=1000\x00DEFAULT_WAL_SYNCHRONOUS=2\x00DEFAULT_WORKER_THREADS=0\x00DIRECT_OVERFLOW_READ\x00ENABLE_COLUMN_METADATA\x00ENABLE_DBSTAT_VTAB\x00ENABLE_FTS5\x00ENABLE_GEOPOLY\x00ENABLE_MATH_FUNCTIONS\x00ENABLE_MEMORY_MANAGEMENT\x00ENABLE_OFFSET_SQL_FUNC\x00ENABLE_PREUPDATE_HOOK\x00ENABLE_RBU\x00ENABLE_RTREE\x00ENABLE_SESSION\x00ENABLE_SNAPSHOT\x00ENABLE_STAT4\x00ENABLE_UNLOCK_NOTIFY\x00LIKE_DOESNT_MATCH_BLOBS\x00MALLOC_SOFT_LIMIT=1024\x00MAX_ATTACHED=10\x00MAX_COLUMN=2000\x00MAX_COMPOUND_SELECT=500\x00MAX_DEFAULT_PAGE_SIZE=8192\x00MAX_EXPR_DEPTH=1000\x00MAX_FUNCTION_ARG=127\x00MAX_LENGTH=1000000000\x00MAX_LIKE_PATTERN_LENGTH=50000\x00MAX_MMAP_SIZE=0x7fff0000\x00MAX_PAGE_COUNT=0xfffffffe\x00MAX_PAGE_SIZE=65536\x00MAX_SQL_LENGTH=1000000000\x00MAX_TRIGGER_DEPTH=1000\x00MAX_VARIABLE_NUMBER=32766\x00MAX_VDBE_OP=250000000\x00MAX_WORKER_THREADS=8\x00MUTEX_W32\x00OMIT_SEH\x00SOUNDEX\x00SYSTEM_MALLOC\x00TEMP_STORE=1\x00THREADSAFE=1\x00ANY\x00BLOB\x00INT\x00INTEGER\x00REAL\x00TEXT\x0020b:20e\x0020c:20e\x0020e\x0040f-21a-21d\x00now\x00subsec\x00subsecond\x00local time unavailable\x00auto\x00ceiling\x00floor\x00julianday\x00localtime\x00unixepoch\x00utc\x00weekday \x00start of \x00month\x00year\x00day\x0040f\x0050f\x0040f-20a-20d\x0050f-20a-20d\x00%02d\x00%2d\x00%06.3f\x00%04d-%02d-%02d\x00%04d\x00%03d\x00%.16g\x00PM\x00pm\x00AM\x00am\x00%02d:%02d\x00%.3f\x00%lld\x00%02d:%02d:%02d\x00%c%04d-%02d-%02d %02d:%02d:%06.3f\x00date\x00time\x00datetime\x00strftime\x00timediff\x00current_time\x00current_timestamp\x00current_date\x00failed to allocate %u bytes of memory\x00failed memory resize %u to %u bytes\x00out of memory\x00%\x00null\x00NaN\x00-Inf\x00\x00NULL\x00(NULL)\x00.\x00(join-%u)\x00%u-ROW VALUES CLAUSE\x00(subquery-%u)\x00unrecognized token: \"%s\"\x00922337203685477580\x00+- \n\t0123456789\x000\x00API call with %s database connection pointer\x00unopened\x00invalid\x00Savepoint\x00AutoCommit\x00Transaction\x00Checkpoint\x00JournalMode\x00Vacuum\x00VFilter\x00VUpdate\x00Init\x00Goto\x00Gosub\x00InitCoroutine\x00Yield\x00MustBeInt\x00Jump\x00Once\x00If\x00IfNot\x00IsType\x00Not\x00IfNullRow\x00SeekLT\x00SeekLE\x00SeekGE\x00SeekGT\x00IfNotOpen\x00IfNoHope\x00NoConflict\x00NotFound\x00Found\x00SeekRowid\x00NotExists\x00Last\x00IfSizeBetween\x00SorterSort\x00Sort\x00Rewind\x00SorterNext\x00Prev\x00Next\x00IdxLE\x00IdxGT\x00IdxLT\x00Or\x00And\x00IdxGE\x00RowSetRead\x00RowSetTest\x00Program\x00FkIfZero\x00IsNull\x00NotNull\x00Ne\x00Eq\x00Gt\x00Le\x00Lt\x00Ge\x00ElseEq\x00IfPos\x00IfNotZero\x00DecrJumpZero\x00IncrVacuum\x00VNext\x00Filter\x00PureFunc\x00Function\x00Return\x00EndCoroutine\x00HaltIfNull\x00Halt\x00Integer\x00Int64\x00String\x00BeginSubrtn\x00Null\x00SoftNull\x00Blob\x00Variable\x00Move\x00Copy\x00SCopy\x00IntCopy\x00FkCheck\x00ResultRow\x00CollSeq\x00AddImm\x00RealAffinity\x00Cast\x00Permutation\x00Compare\x00IsTrue\x00ZeroOrNull\x00Offset\x00Column\x00TypeCheck\x00Affinity\x00MakeRecord\x00Count\x00ReadCookie\x00SetCookie\x00ReopenIdx\x00BitAnd\x00BitOr\x00ShiftLeft\x00ShiftRight\x00Add\x00Subtract\x00Multiply\x00Divide\x00Remainder\x00Concat\x00OpenRead\x00OpenWrite\x00BitNot\x00OpenDup\x00OpenAutoindex\x00String8\x00OpenEphemeral\x00SorterOpen\x00SequenceTest\x00OpenPseudo\x00Close\x00ColumnsUsed\x00SeekScan\x00SeekHit\x00Sequence\x00NewRowid\x00Insert\x00RowCell\x00Delete\x00ResetCount\x00SorterCompare\x00SorterData\x00RowData\x00Rowid\x00NullRow\x00SeekEnd\x00IdxInsert\x00SorterInsert\x00IdxDelete\x00DeferredSeek\x00IdxRowid\x00FinishSeek\x00Destroy\x00Clear\x00ResetSorter\x00CreateBtree\x00SqlExec\x00ParseSchema\x00LoadAnalysis\x00DropTable\x00DropIndex\x00Real\x00DropTrigger\x00IntegrityCk\x00RowSetAdd\x00Param\x00FkCounter\x00MemMax\x00OffsetLimit\x00AggInverse\x00AggStep\x00AggStep1\x00AggValue\x00AggFinal\x00Expire\x00CursorLock\x00CursorUnlock\x00TableLock\x00VBegin\x00VCreate\x00VDestroy\x00VOpen\x00VCheck\x00VInitIn\x00VColumn\x00VRename\x00Pagecount\x00MaxPgcnt\x00ClrSubtype\x00GetSubtype\x00SetSubtype\x00FilterAdd\x00Trace\x00CursorHint\x00ReleaseReg\x00Noop\x00Explain\x00Abortable\x00AreFileApisANSI\x00CharLowerW\x00CharUpperW\x00CloseHandle\x00CreateFileA\x00CreateFileW\x00CreateFileMappingA\x00CreateFileMappingW\x00CreateMutexW\x00DeleteFileA\x00DeleteFileW\x00FileTimeToLocalFileTime\x00FileTimeToSystemTime\x00FlushFileBuffers\x00FormatMessageA\x00FormatMessageW\x00FreeLibrary\x00GetCurrentProcessId\x00GetDiskFreeSpaceA\x00GetDiskFreeSpaceW\x00GetFileAttributesA\x00GetFileAttributesW\x00GetFileAttributesExW\x00GetFileSize\x00GetFullPathNameA\x00GetFullPathNameW\x00GetLastError\x00GetProcAddressA\x00GetSystemInfo\x00GetSystemTime\x00GetSystemTimeAsFileTime\x00GetTempPathA\x00GetTempPathW\x00GetTickCount\x00GetVersionExA\x00GetVersionExW\x00HeapAlloc\x00HeapCreate\x00HeapDestroy\x00HeapFree\x00HeapReAlloc\x00HeapSize\x00HeapValidate\x00HeapCompact\x00LoadLibraryA\x00LoadLibraryW\x00LocalFree\x00LockFile\x00LockFileEx\x00MapViewOfFile\x00MultiByteToWideChar\x00QueryPerformanceCounter\x00ReadFile\x00SetEndOfFile\x00SetFilePointer\x00Sleep\x00SystemTimeToFileTime\x00UnlockFile\x00UnlockFileEx\x00UnmapViewOfFile\x00WideCharToMultiByte\x00WriteFile\x00CreateEventExW\x00WaitForSingleObject\x00WaitForSingleObjectEx\x00SetFilePointerEx\x00GetFileInformationByHandleEx\x00MapViewOfFileFromApp\x00CreateFile2\x00LoadPackagedLibrary\x00GetTickCount64\x00GetNativeSystemInfo\x00OutputDebugStringA\x00OutputDebugStringW\x00GetProcessHeap\x00CreateFileMappingFromApp\x00InterlockedCompareExchange\x00UuidCreate\x00UuidCreateSequential\x00FlushViewOfFile\x00%s\x00OsError 0x%lx (%lu)\x00os_win.c:%d: (%lu) %s(%s) - %s\x00delayed %dms for lock/sharing conflict at line %d\x00winSeekFile\x00winClose\x00winRead\x00winWrite1\x00winWrite2\x00winTruncate1\x00winTruncate2\x00winSync1\x00winSync2\x00winFileSize\x00winUnlockReadLock\x00winUnlock\x00winLockSharedMemory\x00%s-shm\x00readonly_shm\x00winOpenShm\x00winShmMap1\x00winShmMap2\x00winShmMap3\x00winUnmapfile1\x00winUnmapfile2\x00winMapfile1\x00winMapfile2\x00etilqs_\x00winGetTempname1\x00winGetTempname2\x00winGetTempname3\x00winGetTempname4\x00winGetTempname5\x00exclusive\x00winOpen\x00psow\x00winDelete\x00winAccess\x00%s%c%s\x00winFullPathname1\x00winFullPathname2\x00winFullPathname3\x00winFullPathname4\x00win32\x00win32-longpath\x00win32-none\x00win32-longpath-none\x00memdb\x00memdb(%p,%lld)\x00PRAGMA \"%w\".page_count\x00BEGIN IMMEDIATE; COMMIT;\x00ATTACH x AS %Q\x00recovered %d pages from %s\x00-journal\x00-wal\x00nolock\x00immutable\x00PRAGMA table_list\x00recovered %d frames from WAL file %s\x00cannot limit WAL size: %s\x00:memory:\x00@  \x00\n\x00invalid page number %u\x002nd reference to page %u\x00Failed to read ptrmap key=%u\x00Bad ptr map entry key=%u expected=(%u,%u) got=(%u,%u)\x00failed to get page %u\x00freelist leaf count too big on page %u\x00size\x00overflow list length\x00%s is %u but should be %u\x00Tree %u page %u: \x00unable to get the page. error code=%d\x00btreeInitPage() returns error code %d\x00free space corruption\x00Tree %u page %u cell %u: \x00Tree %u page %u right child: \x00Offset %u out of range %u..%u\x00Extends off end of page\x00Rowid %lld out of order\x00Child page depth differs\x00Multiple uses for byte %u of page %u\x00Fragmentation of %u bytes reported as %u on page %u\x00Freelist: \x00max rootpage (%u) disagrees with header (%u)\x00incremental_vacuum enabled with a max rootpage of zero\x00Page %u: never used\x00Page %u: pointer map referenced\x00unknown database %s\x00destination database is in use\x00source and destination must be distinct\x00%!.15g\x00-\x00%s%s\x00k(%d\x00BINARY\x00B\x00N.\x00,%s%s%s\x00)\x00?\x008\x0016LE\x0016BE\x00%.18s-%s\x00%s(%d)\x00%d\x00(blob)\x00vtab:%p\x00%c%u\x00]\x00program\x00%.4c%s%.16c\x00MJ delete: %s\x00MJ collide: %s\x00-mj%06X9%02X\x00FOREIGN KEY constraint failed\x00a CHECK constraint\x00a generated column\x00an index\x00non-deterministic use of %s() in %s\x00API called with finalized prepared statement\x00API called with NULL prepared statement\x00string or blob too big\x00addr\x00opcode\x00p1\x00p2\x00p3\x00p4\x00p5\x00comment\x00id\x00parent\x00notused\x00detail\x00bind on a busy prepared statement: [%s]\x00-- \x00'%.*q'\x00zeroblob(%d)\x00x'\x00%02x\x00'\x00NOT NULL\x00UNIQUE\x00CHECK\x00FOREIGN KEY\x00%s constraint failed\x00%z: %s\x00abort at %d in [%s]: %s\x00cannot store %s value in %s column %s.%s\x00cannot open savepoint - SQL statements in progress\x00no such savepoint: %s\x00cannot release savepoint - SQL statements in progress\x00cannot commit transaction - SQL statements in progress\x00cannot start a transaction within a transaction\x00cannot rollback - no transaction is active\x00cannot commit - no transaction is active\x00database schema has changed\x00index corruption\x00sqlite_master\x00SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid\x00too many levels of trigger recursion\x00into\x00out of\x00cannot change %s wal mode from within a transaction\x00database table is locked: %s\x00ValueList\x00-- %s\x00statement aborts at %d: [%s] %s\x00real\x00integer\x00cannot open value of type %s\x00no such rowid: %lld\x00cannot open virtual table: %s\x00cannot open table without rowid: %s\x00cannot open view: %s\x00no such column: \"%s\"\x00foreign key\x00indexed\x00cannot open %s column for writing\x00sqlite_\x00sqlite_temp_master\x00sqlite_temp_schema\x00sqlite_schema\x00main\x00*\x00new\x00old\x00excluded\x00misuse of aliased aggregate %s\x00misuse of aliased window function %s\x00row value misused\x00double-quoted string literal: \"%w\"\x00coalesce\x00no such column\x00ambiguous column name\x00%s: %s.%s.%s\x00%s: %s.%s\x00%s: \"%s\" - should this be a string literal in single-quotes?\x00%s: %s\x00partial index WHERE clauses\x00index expressions\x00CHECK constraints\x00generated columns\x00%s prohibited in %s\x00the \".\" operator\x00second argument to %#T() must be a constant between 0.0 and 1.0\x00not authorized to use function: %#T\x00non-deterministic functions\x00%#T() may not be used as a window function\x00window\x00aggregate\x00misuse of %s function %#T()\x00no such function: %#T\x00wrong number of arguments to function %#T()\x00FILTER may not be used with non-aggregate %#T()\x00subqueries\x00parameters\x00%r %s BY term out of range - should be between 1 and %d\x00too many terms in ORDER BY clause\x00ORDER\x00%r ORDER BY term does not match any column in the result set\x00too many terms in %s BY clause\x00HAVING clause on a non-aggregate query\x00GROUP\x00aggregate functions are not allowed in the GROUP BY clause\x00Expression tree is too large (maximum depth %d)\x00s\x00IN(...) element has %d term%s - expected %d\x00too many arguments on function %T\x00ORDER BY may not be used with non-aggregate %#T()\x00unsafe use of %#T()\x00variable number must be between ?1 and ?%d\x00too many SQL variables\x00%d columns assigned %d values\x00too many columns in %s\x00true\x00false\x00_ROWID_\x00ROWID\x00OID\x00USING ROWID SEARCH ON TABLE %s FOR IN-OPERATOR\x00USING INDEX %s FOR IN-OPERATOR\x00sub-select returns %d columns - expected %d\x00REUSE LIST SUBQUERY %d\x00CORRELATED \x00%sLIST SUBQUERY %d\x00REUSE SUBQUERY %d\x00%sSCALAR SUBQUERY %d\x001\x000x\x00hex literal too big: %s%#T\x00generated column loop on \"%s\"\x00blob\x00text\x00numeric\x00flexnum\x00none\x00misuse of aggregate: %#T()\x00unknown function: %#T()\x00RAISE() may only be used within a trigger-program\x00table %s may not be altered\x00SELECT 1 FROM \"%w\".sqlite_master WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%' AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL \x00SELECT 1 FROM temp.sqlite_master WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%' AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL \x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_quotefix(%Q, sql)WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%'\x00UPDATE temp.sqlite_master SET sql = sqlite_rename_quotefix('temp', sql)WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%'\x00there is already another table or index with this name: %s\x00table\x00view %s may not be altered\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)AND   name NOT LIKE 'sqliteX_%%' ESCAPE 'X'\x00UPDATE %Q.sqlite_master SET tbl_name = %Q, name = CASE WHEN type='table' THEN %Q WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X'      AND type='index' THEN 'sqlite_autoindex_' || %Q || substr(name,%d+18) ELSE name END WHERE tbl_name=%Q COLLATE nocase AND (type='table' OR type='index' OR type='trigger');\x00sqlite_sequence\x00UPDATE \"%w\".sqlite_sequence set name = %Q WHERE name = %Q\x00UPDATE sqlite_temp_schema SET sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), tbl_name = CASE WHEN tbl_name=%Q COLLATE nocase AND   sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) THEN %Q ELSE tbl_name END WHERE type IN ('view', 'trigger')\x00after rename\x00SELECT raise(ABORT,%Q) FROM \"%w\".\"%w\"\x00Cannot add a PRIMARY KEY column\x00Cannot add a UNIQUE column\x00Cannot add a REFERENCES column with non-NULL default value\x00Cannot add a NOT NULL column with default value NULL\x00Cannot add a column with non-constant default\x00cannot add a STORED column\x00UPDATE \"%w\".sqlite_master SET sql = printf('%%.%ds, ',sql) || %Q || substr(sql,1+length(printf('%%.%ds',sql))) WHERE type = 'table' AND name = %Q\x00SELECT CASE WHEN quick_check GLOB 'CHECK*' THEN raise(ABORT,'CHECK constraint failed') WHEN quick_check GLOB 'non-* value in*' THEN raise(ABORT,'type mismatch on DEFAULT') ELSE raise(ABORT,'NOT NULL constraint failed') END  FROM pragma_quick_check(%Q,%Q) WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*' OR quick_check GLOB 'non-* value in*'\x00virtual tables may not be altered\x00Cannot add a column to a view\x00sqlite_altertab_%s\x00view\x00virtual table\x00drop column from\x00rename columns of\x00cannot %s %s \"%s\"\x00no such column: \"%T\"\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'  AND (type != 'index' OR tbl_name = %Q)\x00UPDATE temp.sqlite_master SET sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) WHERE type IN ('trigger', 'view')\x00 \x00error in %s %s%s%s: %s\x00CREATE \x00\"%w\" \x00%Q%s\x00%.*s%s\x00PRIMARY KEY\x00cannot drop %s column: \"%s\"\x00cannot drop column \"%s\": no other columns exist\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_drop_column(%d, sql, %d) WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)\x00after drop column\x00sqlite_rename_column\x00sqlite_rename_table\x00sqlite_rename_test\x00sqlite_drop_column\x00sqlite_rename_quotefix\x00sqlite_stat1\x00tbl,idx,stat\x00sqlite_stat4\x00tbl,idx,neq,nlt,ndlt,sample\x00sqlite_stat3\x00CREATE TABLE %Q.%s(%s)\x00DELETE FROM %Q.%s WHERE %s=%Q\x00DELETE FROM %Q.%s\x00stat_init\x00stat_push\x00%llu\x00 %llu\x00%llu \x00stat_get\x00sqlite\\_%\x00BBB\x00idx\x00tbl\x00unordered*\x00sz=[0-9]*\x00noskipscan*\x00SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx COLLATE nocase\x00SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4\x00SELECT tbl,idx,stat FROM %Q.sqlite_stat1\x00x\x00\x00too many attached databases - max %d\x00database %s is already in use\x00database is already attached\x00attached databases must use the same text encoding as main database\x00unable to open database: %s\x00no such database: %s\x00cannot detach database %s\x00database %s is locked\x00sqlite_detach\x00sqlite_attach\x00%s cannot use variables\x00%s %T cannot reference objects in database %s\x00authorizer malfunction\x00%s.%s\x00%s.%z\x00access to %z is prohibited\x00not authorized\x00pragma_\x00no such view\x00no such table\x00corrupt database\x00unknown database %T\x00object name reserved for internal use: %s\x00temporary table name must be unqualified\x00%s %T already exists\x00there is already an index named %s\x00cannot use RETURNING in a trigger\x00sqlite_returning_%p\x00too many columns on %s\x00always\x00generated\x00duplicate column name: %s\x00default value of column [%s] is not constant\x00cannot use DEFAULT on a generated column\x00generated columns cannot be part of the PRIMARY KEY\x00table \"%s\" has more than one primary key\x00AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY\x00virtual tables cannot use computed columns\x00virtual\x00stored\x00error in generated column \"%s\"\x00,\x00\n  \x00,\n  \x00\n)\x00CREATE TABLE \x00 TEXT\x00 NUM\x00 INT\x00 REAL\x00unknown datatype for %s.%s: \"%s\"\x00missing datatype for %s.%s\x00AUTOINCREMENT not allowed on WITHOUT ROWID tables\x00PRIMARY KEY missing on table %s\x00must have at least one non-generated column\x00TABLE\x00VIEW\x00CREATE %s %.*s\x00UPDATE %Q.sqlite_master SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q WHERE rowid=#%d\x00CREATE TABLE %Q.sqlite_sequence(name,seq)\x00tbl_name='%q' AND type!='trigger'\x00SELECT*FROM\"%w\".\"%w\"\x00parameters are not allowed in views\x00view %s is circularly defined\x00corrupt schema\x00UPDATE %Q.sqlite_master SET rootpage=%d WHERE #%d AND rootpage=#%d\x00sqlite_stat%d\x00DELETE FROM %Q.sqlite_sequence WHERE name=%Q\x00DELETE FROM %Q.sqlite_master WHERE tbl_name=%Q and type!='trigger'\x00stat\x00table %s may not be dropped\x00use DROP TABLE to delete table %s\x00use DROP VIEW to delete view %s\x00foreign key on %s should reference only one column of table %T\x00number of columns in foreign key does not match the number of columns in the referenced table\x00unknown column \"%s\" in foreign key definition\x00FIRST\x00LAST\x00unsupported use of NULLS %s\x00index\x00cannot create a TEMP index on non-TEMP table \"%s\"\x00table %s may not be indexed\x00views may not be indexed\x00virtual tables may not be indexed\x00there is already a table named %s\x00index %s already exists\x00sqlite_autoindex_%s_%d\x00expressions prohibited in PRIMARY KEY and UNIQUE constraints\x00conflicting ON CONFLICT clauses specified\x00invalid rootpage\x00 UNIQUE\x00CREATE%s INDEX %.*s\x00INSERT INTO %Q.sqlite_master VALUES('index',%Q,%Q,#%d,%Q);\x00name='%q' AND type='index'\x00no such index: %S\x00index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped\x00DELETE FROM %Q.sqlite_master WHERE name=%Q AND type='index'\x00too many FROM clause terms, max: %d\x00ON\x00USING\x00a JOIN clause is required before %s\x00BEGIN\x00ROLLBACK\x00COMMIT\x00RELEASE\x00unable to open a temporary database file for storing temporary tables\x00index '%q'\x00, \x00%s.rowid\x00unable to identify the object to be reindexed\x00duplicate WITH table name: %s\x00no such collation sequence: %s\x00unsafe use of virtual table \"%s\"\x00table %s may not be modified\x00cannot modify %s because it is a view\x00rows deleted\x00integer overflow\x00%!.*f\x00LIKE or GLOB pattern too complex\x00ESCAPE expression must be a single character\x00%!0.15g\x00%!0.20e\x00%Q\x00?000\x00MATCH\x00like\x00implies_nonnull_row\x00expr_compare\x00expr_implies_expr\x00affinity\x00soundex\x00load_extension\x00sqlite_compileoption_used\x00sqlite_compileoption_get\x00unlikely\x00likelihood\x00likely\x00sqlite_offset\x00ltrim\x00rtrim\x00trim\x00min\x00max\x00typeof\x00subtype\x00length\x00octet_length\x00instr\x00printf\x00format\x00unicode\x00char\x00abs\x00round\x00upper\x00lower\x00hex\x00unhex\x00concat\x00concat_ws\x00ifnull\x00random\x00randomblob\x00nullif\x00sqlite_version\x00sqlite_source_id\x00sqlite_log\x00quote\x00last_insert_rowid\x00changes\x00total_changes\x00replace\x00zeroblob\x00substr\x00substring\x00sum\x00total\x00avg\x00count\x00group_concat\x00string_agg\x00glob\x00ceil\x00trunc\x00ln\x00log\x00log10\x00log2\x00exp\x00pow\x00power\x00mod\x00acos\x00asin\x00atan\x00atan2\x00cos\x00sin\x00tan\x00cosh\x00sinh\x00tanh\x00acosh\x00asinh\x00atanh\x00sqrt\x00radians\x00degrees\x00pi\x00sign\x00iif\x00foreign key mismatch - \"%w\" referencing \"%w\"\x00cannot INSERT into generated column \"%s\"\x00table %S has no column named %s\x00SCAN %S\x00table %S has %d columns but %d values were supplied\x00%d values for %d columns\x00UPSERT not implemented for virtual table \"%s\"\x00cannot UPSERT a view\x00rows inserted\x00dll\x00sqlite3_extension_init\x00sqlite3_\x00lib\x00_init\x00no entry point [%s] in shared library [%s]\x00error during initialization: %s\x00unable to open shared library [%.*s]\x00automatic extension loading failed: %s\x00seq\x00from\x00to\x00on_update\x00on_delete\x00match\x00cid\x00name\x00type\x00notnull\x00dflt_value\x00pk\x00hidden\x00schema\x00ncol\x00wr\x00strict\x00seqno\x00desc\x00coll\x00key\x00builtin\x00enc\x00narg\x00flags\x00wdth\x00hght\x00flgs\x00unique\x00origin\x00partial\x00rowid\x00fkid\x00file\x00busy\x00checkpointed\x00database\x00status\x00cache_size\x00timeout\x00analysis_limit\x00application_id\x00auto_vacuum\x00automatic_index\x00busy_timeout\x00cache_spill\x00case_sensitive_like\x00cell_size_check\x00checkpoint_fullfsync\x00collation_list\x00compile_options\x00count_changes\x00data_store_directory\x00data_version\x00database_list\x00default_cache_size\x00defer_foreign_keys\x00empty_result_callbacks\x00encoding\x00foreign_key_check\x00foreign_key_list\x00foreign_keys\x00freelist_count\x00full_column_names\x00fullfsync\x00function_list\x00hard_heap_limit\x00ignore_check_constraints\x00incremental_vacuum\x00index_info\x00index_list\x00index_xinfo\x00integrity_check\x00journal_mode\x00journal_size_limit\x00legacy_alter_table\x00locking_mode\x00max_page_count\x00mmap_size\x00module_list\x00optimize\x00page_count\x00page_size\x00pragma_list\x00query_only\x00quick_check\x00read_uncommitted\x00recursive_triggers\x00reverse_unordered_selects\x00schema_version\x00secure_delete\x00short_column_names\x00shrink_memory\x00soft_heap_limit\x00synchronous\x00table_info\x00table_list\x00table_xinfo\x00temp_store\x00temp_store_directory\x00threads\x00trusted_schema\x00user_version\x00wal_autocheckpoint\x00wal_checkpoint\x00writable_schema\x00normal\x00full\x00incremental\x00memory\x00temporary storage cannot be changed from within a transaction\x00SET NULL\x00SET DEFAULT\x00CASCADE\x00RESTRICT\x00NO ACTION\x00delete\x00persist\x00off\x00truncate\x00wal\x00utf8\x00utf16le\x00utf16be\x00w\x00a\x00sissii\x00-%T\x00fast\x00not a writable directory\x00Safety level may not be changed inside a transaction\x00reset\x00issisii\x00issisi\x00SELECT*FROM\"%w\"\x00shadow\x00sssiii\x00iisX\x00isiX\x00c\x00u\x00isisi\x00iss\x00is\x00iissssss\x00NONE\x00siX\x00*** in database %s ***\n\x00wrong # of entries in index \x00row not in PRIMARY KEY order for %s\x00NULL value in %s.%s\x00non-%s value in %s.%s\x00NUMERIC value in %s.%s\x00C\x00TEXT value in %s.%s\x00CHECK constraint failed in %s\x00row \x00 missing from index \x00rowid not at end-of-record for row \x00 of index \x00 values differ from index \x00non-unique entry in index \x00ok\x00UTF8\x00UTF-8\x00UTF-16le\x00UTF-16be\x00UTF16le\x00UTF16be\x00UTF-16\x00UTF16\x00unsupported encoding: %s\x00restart\x00ANALYZE \"%w\".\"%w\"\x00CREATE TABLE x\x00%c\"%s\"\x00(\"%s\"\x00,arg HIDDEN\x00,schema HIDDEN\x00PRAGMA \x00%Q.\x00=%Q\x00rename\x00drop column\x00add column\x00error in %s %s after %s: %s\x00malformed database schema (%s)\x00%z - %s\x00orphan index\x00CREATE TABLE x(type text,name text,tbl_name text,rootpage int,sql text)\x00unsupported file format\x00SELECT*FROM\"%w\".%s ORDER BY rowid\x00database schema is locked: %s\x00statement too long\x00unknown join type: %T%s%T%s%T\x00a NATURAL join may not have an ON or USING clause\x00cannot join using column %s - column not present in both tables\x00ambiguous reference to %s in USING()\x00UNION ALL\x00INTERSECT\x00EXCEPT\x00UNION\x00USE TEMP B-TREE FOR %s\x00LAST TERM OF \x00USE TEMP B-TREE FOR %sORDER BY\x00USE TEMP B-TREE FOR LAST %d TERMS OF ORDER BY\x00column%d\x00%.*z:%u\x00NUM\x00cannot use window functions in recursive queries\x00recursive aggregate queries not supported\x00SETUP\x00RECURSIVE STEP\x00S\x00SCAN %d CONSTANT ROW%s\x00COMPOUND QUERY\x00LEFT-MOST SUBQUERY\x00%s USING TEMP B-TREE\x00all VALUES must have the same number of terms\x00SELECTs to the left and right of %s do not have the same number of result columns\x00MERGE (%s)\x00LEFT\x00RIGHT\x00no such index: %s\x00'%s' is not a function\x00no such index: \"%s\"\x00multiple references to recursive table: %s\x00circular reference: %s\x00table %s has %d values for %d columns\x00multiple recursive references: %s\x00recursive reference in a subquery: %s\x00%!S\x00too many references to \"%s\": max 65535\x00access to view \"%s\" prohibited\x00..%s\x00%s.%s.%s\x00no such table: %s\x00no tables specified\x00too many columns in result set\x00DISTINCT aggregates must have exactly one argument\x00USE TEMP B-TREE FOR %s(DISTINCT)\x00USE TEMP B-TREE FOR %s(ORDER BY)\x00 USING COVERING INDEX \x00SCAN %s%s%s\x00target object/alias may not appear in FROM clause: %s\x00expected %d columns for '%s' but got %d\x00CO-ROUTINE %!S\x00MATERIALIZE %!S\x00DISTINCT\x00GROUP BY\x00sqlite3_get_table() called with two or more incompatible queries\x00temporary trigger may not have qualified name\x00trigger\x00cannot create triggers on virtual tables\x00cannot create triggers on shadow tables\x00trigger %T already exists\x00cannot create trigger on system table\x00BEFORE\x00AFTER\x00cannot create %s trigger on view: %S\x00cannot create INSTEAD OF trigger on table: %S\x00trigger \"%s\" may not write to shadow table \"%s\"\x00INSERT INTO %Q.sqlite_master VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')\x00type='trigger' AND name='%q'\x00no such trigger: %S\x00DELETE FROM %Q.sqlite_master WHERE name=%Q AND type='trigger'\x00DELETE\x00UPDATE\x00%s RETURNING is not available on virtual tables\x00RETURNING may not use \"TABLE.*\" wildcards\x00-- TRIGGER %s\x00cannot UPDATE generated column \"%s\"\x00no such column: %s\x00rows updated\x00%r \x00%sON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint\x00CRE\x00INS\x00cannot VACUUM from within a transaction\x00cannot VACUUM - SQL statements in progress\x00non-text filename\x00ATTACH %Q AS vacuum_db\x00output file already exists\x00SELECT sql FROM \"%w\".sqlite_schema WHERE type='table'AND name<>'sqlite_sequence' AND coalesce(rootpage,1)>0\x00SELECT sql FROM \"%w\".sqlite_schema WHERE type='index'\x00SELECT'INSERT INTO vacuum_db.'||quote(name)||' SELECT*FROM\"%w\".'||quote(name)FROM vacuum_db.sqlite_schema WHERE type='table'AND coalesce(rootpage,1)>0\x00INSERT INTO vacuum_db.sqlite_schema SELECT*FROM \"%w\".sqlite_schema WHERE type IN('view','trigger') OR(type='table'AND rootpage=0)\x00CREATE VIRTUAL TABLE %T\x00UPDATE %Q.sqlite_master SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q WHERE rowid=#%d\x00name=%Q AND sql=%Q\x00vtable constructor called recursively: %s\x00vtable constructor failed: %s\x00vtable constructor did not declare schema: %s\x00no such module: %s\x00syntax error\x00<expr>\x00 AND \x00(\x00 (\x00%s=?\x00ANY(%s)\x00>\x00<\x00SEARCH\x00SCAN\x00%s %S\x00AUTOMATIC PARTIAL COVERING INDEX\x00AUTOMATIC COVERING INDEX\x00COVERING INDEX %s\x00INDEX %s\x00 USING \x00 USING INTEGER PRIMARY KEY (%s\x00>? AND %s\x00%c?)\x00 VIRTUAL TABLE INDEX %d:%s\x00 LEFT-JOIN\x00BLOOM FILTER ON %S (\x00rowid=?\x00MULTI-INDEX OR\x00INDEX %d\x00RIGHT-JOIN %s\x00regexp\x00ON clause references tables to its right\x00NOCASE\x00too many arguments on %s() - max %d\x00automatic index on %s(%s)\x00auto-index\x00%s.xBestIndex malfunction\x00abbreviated query algorithm search\x00no query solution\x00at most %d tables in a join\x00SCAN CONSTANT ROW\x00second argument to nth_value must be a positive integer\x00argument of ntile must be a positive integer\x00no such window: %s\x00RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression\x00FILTER clause may only be used with aggregate window functions\x00misuse of aggregate: %s()\x00unsupported frame specification\x00PARTITION clause\x00ORDER BY clause\x00frame specification\x00cannot override %s of window: %s\x00DISTINCT is not supported for window functions\x00frame starting offset must be a non-negative integer\x00frame ending offset must be a non-negative integer\x00frame starting offset must be a non-negative number\x00frame ending offset must be a non-negative number\x00ORDER BY\x00LIMIT\x00%s clause should come after %s not before\x00too many terms in compound SELECT\x00syntax error after column name \"%.*s\"\x00unknown table option: %.*s\x00set list\x00near \"%T\": syntax error\x00qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers\x00the INDEXED BY clause is not allowed on UPDATE or DELETE statements within triggers\x00the NOT INDEXED clause is not allowed on UPDATE or DELETE statements within triggers\x00incomplete input\x00unrecognized token: \"%T\"\x00%s in \"%s\"\x00create\x00temp\x00temporary\x00end\x00explain\x00unable to close due to unfinalized statements or unfinished backups\x00not an error\x00SQL logic error\x00access permission denied\x00query aborted\x00database is locked\x00database table is locked\x00attempt to write a readonly database\x00interrupted\x00disk I/O error\x00database disk image is malformed\x00unknown operation\x00database or disk is full\x00unable to open database file\x00locking protocol\x00constraint failed\x00datatype mismatch\x00bad parameter or other API misuse\x00authorization denied\x00column index out of range\x00file is not a database\x00notification message\x00warning message\x00unknown error\x00abort due to ROLLBACK\x00another row available\x00no more rows available\x00unable to delete/modify user-function due to active statements\x00unable to use function %s in the requested context\x00unknown database: %s\x00unable to delete/modify collation sequence due to active statements\x00file:\x00localhost\x00invalid uri authority: %.*s\x00vfs\x00cache\x00shared\x00private\x00mode\x00ro\x00rw\x00rwc\x00access\x00no such %s mode: %s\x00%s mode not allowed: %s\x00no such vfs: %s\x00RTRIM\x00\x00\x00\x00%s at line %d of [%.10s]\x00database corruption\x00misuse\x00cannot open file\x00no such table column: %s.%s\x00SQLITE_\x00database is deadlocked\x00array\x00object\x000123456789abcdef\x00JSON cannot hold BLOB values\x00malformed JSON\x00inf\x009.0e999\x00infinity\x00QNaN\x00SNaN\x00json_%s() needs an odd number of arguments\x00\"\\/bfnrt\x00-9e999\x009e999\x00inity\x00\\\"\x00\\u0009\x00\\u00\x00\\u0000\x00,\n\x00: \x00bad JSON path: %Q\x00@\x00[\x00.\"\x00\"\x00json_object() requires an even number of arguments\x00json_object() labels must be TEXT\x00set\x00insert\x00    \x00FLAGS parameter to json_valid() must be between 1 and 15\x00[]\x00{}\x00CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,json HIDDEN,root HIDDEN)\x00[%lld]\x00.\"%.*s\"\x00.%.*s\x00$\x00json\x00jsonb\x00json_array\x00jsonb_array\x00json_array_length\x00json_error_position\x00json_extract\x00jsonb_extract\x00->\x00->>\x00json_insert\x00jsonb_insert\x00json_object\x00jsonb_object\x00json_patch\x00jsonb_patch\x00json_pretty\x00json_quote\x00json_remove\x00jsonb_remove\x00json_replace\x00jsonb_replace\x00json_set\x00jsonb_set\x00json_type\x00json_valid\x00json_group_array\x00jsonb_group_array\x00json_group_object\x00jsonb_group_object\x00json_each\x00json_tree\x00data\x00DROP TABLE '%q'.'%q_node';DROP TABLE '%q'.'%q_rowid';DROP TABLE '%q'.'%q_parent';\x00RtreeMatchArg\x00SELECT * FROM %Q.%Q\x00UNIQUE constraint failed: %s.%s\x00rtree constraint failed: %s.(%s<=%s)\x00ALTER TABLE %Q.'%q_node'   RENAME TO \"%w_node\";ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";ALTER TABLE %Q.'%q_rowid'  RENAME TO \"%w_rowid\";\x00SELECT stat FROM %Q.sqlite_stat1 WHERE tbl = '%q_rowid'\x00node\x00INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_node' WHERE nodeno = ?1\x00SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = ?1\x00INSERT OR REPLACE INTO '%q'.'%q_rowid' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_rowid' WHERE rowid = ?1\x00SELECT parentnode FROM '%q'.'%q_parent' WHERE nodeno = ?1\x00INSERT OR REPLACE INTO '%q'.'%q_parent' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_parent' WHERE nodeno = ?1\x00CREATE TABLE \"%w\".\"%w_rowid\"(rowid INTEGER PRIMARY KEY,nodeno\x00,a%d\x00);CREATE TABLE \"%w\".\"%w_node\"(nodeno INTEGER PRIMARY KEY,data);\x00CREATE TABLE \"%w\".\"%w_parent\"(nodeno INTEGER PRIMARY KEY,parentnode);\x00INSERT INTO \"%w\".\"%w_node\"VALUES(1,zeroblob(%d))\x00INSERT INTO\"%w\".\"%w_rowid\"(rowid,nodeno)VALUES(?1,?2)ON CONFLICT(rowid)DO UPDATE SET nodeno=excluded.nodeno\x00SELECT * FROM \"%w\".\"%w_rowid\" WHERE rowid=?1\x00UPDATE \"%w\".\"%w_rowid\"SET \x00a%d=coalesce(?%d,a%d)\x00a%d=?%d\x00 WHERE rowid=?1\x00PRAGMA %Q.page_size\x00SELECT length(data) FROM '%q'.'%q_node' WHERE nodeno = 1\x00undersize RTree blobs in \"%q_node\"\x00Wrong number of columns for an rtree table\x00Too few columns for an rtree table\x00Too many columns for an rtree table\x00Auxiliary rtree columns must be last\x00_node\x00CREATE TABLE x(%.*s INT\x00,%.*s\x00,%.*s REAL\x00,%.*s INT\x00);\x00{%lld\x00 %g\x00}\x00Invalid argument to rtreedepth()\x00%z%s%z\x00SELECT data FROM %Q.'%q_node' WHERE nodeno=?\x00Node %lld missing from database\x00SELECT parentnode FROM %Q.'%q_parent' WHERE nodeno=?1\x00SELECT nodeno FROM %Q.'%q_rowid' WHERE rowid=?1\x00%_rowid\x00%_parent\x00Mapping (%lld -> %lld) missing from %s table\x00Found (%lld -> %lld) in %s table, expected (%lld -> %lld)\x00Dimension %d of cell %d on node %lld is corrupt\x00Dimension %d of cell %d on node %lld is corrupt relative to parent\x00Node %lld is too small (%d bytes)\x00Rtree depth out of range (%d)\x00Node %lld is too small for cell count of %d (%d bytes)\x00SELECT count(*) FROM %Q.'%q%s'\x00Wrong number of entries in %%%s table - expected %lld, actual %lld\x00SELECT * FROM %Q.'%q_rowid'\x00Schema corrupt or not an rtree\x00_rowid\x00_parent\x00In RTree %s.%s:\n%z\x00wrong number of arguments to function rtreecheck()\x00[%!g,%!g],\x00[%!g,%!g]]\x00<polyline points=\x00%c%g,%g\x00 %g,%g'\x00 %s\x00></polyline>\x00CREATE TABLE x(_shape\x00,%s\x00rtree\x00fullscan\x00_shape does not contain a valid polygon\x00geopoly_overlap\x00geopoly_within\x00geopoly_area\x00geopoly_blob\x00geopoly_json\x00geopoly_svg\x00geopoly_contains_point\x00geopoly_debug\x00geopoly_bbox\x00geopoly_xform\x00geopoly_regular\x00geopoly_ccw\x00geopoly_group_bbox\x00geopoly\x00rtreenode\x00rtreedepth\x00rtreecheck\x00rtree_i32\x00corrupt fossil delta\x00DROP TRIGGER IF EXISTS temp.rbu_insert_tr;DROP TRIGGER IF EXISTS temp.rbu_update1_tr;DROP TRIGGER IF EXISTS temp.rbu_update2_tr;DROP TRIGGER IF EXISTS temp.rbu_delete_tr;\x00AND rootpage!=0 AND rootpage IS NOT NULL\x00SELECT rbu_target_name(name, type='view') AS target, name FROM sqlite_schema WHERE type IN ('table', 'view') AND target IS NOT NULL  %s ORDER BY name\x00SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE'   FROM main.sqlite_schema   WHERE type='index' AND tbl_name = ?\x00SELECT  (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM'), rootpage  FROM sqlite_schema WHERE name=%Q\x00PRAGMA index_list=%Q\x00SELECT rootpage FROM sqlite_schema WHERE name = %Q\x00PRAGMA table_info=%Q\x00PRAGMA main.index_list = %Q\x00PRAGMA main.index_xinfo = %Q\x00SELECT * FROM '%q'\x00rbu_\x00rbu_rowid\x00may not have\x00requires\x00table %q %s rbu_rowid column\x00PRAGMA table_info(%Q)\x00column missing from %q: %s\x00%z%s\"%w\"\x00%z%s%s\"%w\"%s\x00SELECT max(_rowid_) FROM \"%s%w\"\x00 WHERE _rowid_ > %lld \x00 DESC\x00quote(\x00||','||\x00SELECT %s FROM \"%s%w\" ORDER BY %s LIMIT 1\x00 WHERE (%s) > (%s) \x00_rowid_\x00%z%s \"%w\" COLLATE %Q\x00%z%s \"rbu_imp_%d%w\" COLLATE %Q DESC\x00%z%s quote(\"rbu_imp_%d%w\")\x00SELECT %s FROM \"rbu_imp_%w\" ORDER BY %s LIMIT 1\x00%z%s%s\x00(%s) > (%s)\x00%z%s(%.*s) COLLATE %Q\x00%z%s\"%w\" COLLATE %Q\x00%z%s\"rbu_imp_%d%w\"%s\x00%z%s\"rbu_imp_%d%w\" %s COLLATE %Q\x00%z%s\"rbu_imp_%d%w\" IS ?\x00%z%s%s.\"%w\"\x00%z%sNULL\x00%z, %s._rowid_\x00_rowid_ = ?%d\x00%z%sc%d=?%d\x00_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)\x00%z%s\"%w\"=?%d\x00invalid rbu_control value\x00%z%s\"%w\"=rbu_delta(\"%w\", ?%d)\x00%z%s\"%w\"=rbu_fossil_delta(\"%w\", ?%d)\x00PRIMARY KEY(\x00%z%s\"%w\"%s\x00%z)\x00SELECT name FROM sqlite_schema WHERE rootpage = ?\x00%z%sc%d %s COLLATE %Q\x00%z%sc%d%s\x00%z, id INTEGER\x00CREATE TABLE rbu_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID\x00PRIMARY KEY \x00 NOT NULL\x00%z%s\"%w\" %s %sCOLLATE %Q%s\x00%z, %z\x00 WITHOUT ROWID\x00CREATE TABLE \"rbu_imp_%w\"(%z)%s\x00INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)\x00SELECT trim(sql) FROM sqlite_schema WHERE type='index' AND name=?\x00 LIMIT -1 OFFSET %d\x00CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID\x00INSERT INTO \"rbu_imp_%w\" VALUES(%s)\x00DELETE FROM \"rbu_imp_%w\" WHERE %s\x00AND\x00WHERE\x00SELECT %s, 0 AS rbu_control FROM '%q' %s %s %s ORDER BY %s%s\x00SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s\x00SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s UNION ALL SELECT %s, rbu_control FROM '%q' %s %s typeof(rbu_control)='integer' AND rbu_control!=1 ORDER BY %s%s\x00rbu_imp_\x00, _rowid_\x00INSERT INTO \"%s%w\"(%s%s) VALUES(%s)\x00DELETE FROM \"%s%w\" WHERE %s\x00, rbu_rowid\x00, 0 AS rbu_rowid\x00CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS SELECT *%s FROM '%q' WHERE 0;\x00CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(3, %s);END;CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(3, %s);END;CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(4, %s);END;\x00CREATE TEMP TRIGGER rbu_insert_tr AFTER INSERT ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(0, %s);END;\x00,_rowid_ \x00,rbu_rowid\x000 AS \x00SELECT %s,%s rbu_control%s FROM '%q'%s %s %s %s\x00UPDATE \"%s%w\" SET %s WHERE %s\x00SELECT k, v FROM %s.rbu_state\x00file:///%s-vacuum?modeof=%s\x00ATTACH %Q AS stat\x00CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)\x00cannot vacuum wal mode database\x00&\x00file:%s-vactmp?rbu_memory=1%s%s\x00rbu_tmp_insert\x00rbu_fossil_delta\x00rbu_target_name\x00SELECT * FROM sqlite_schema\x00rbu vfs not found\x00PRAGMA main.wal_checkpoint=restart\x00rbu_exclusive_checkpoint\x00%s-oal\x00%s-wal\x00PRAGMA schema_version\x00PRAGMA schema_version = %d\x00INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES (%d, %d), (%d, %Q), (%d, %Q), (%d, %d), (%d, %d), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %Q)  \x00PRAGMA main.%s\x00PRAGMA main.%s = %d\x00PRAGMA writable_schema=1\x00SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0 AND name!='sqlite_sequence'  ORDER BY type DESC\x00SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL\x00INSERT INTO sqlite_schema VALUES(?,?,?,?,?)\x00PRAGMA writable_schema=0\x00DELETE FROM %s.'rbu_tmp_%q'\x00rbu_state mismatch error\x00rbu_vfs_%d\x00SELECT count(*) FROM sqlite_schema WHERE type='index' AND tbl_name = %Q\x00rbu_index_cnt\x00SELECT 1 FROM sqlite_schema WHERE tbl_name = 'rbu_count'\x00SELECT sum(cnt * (1 + rbu_index_cnt(rbu_target_name(tbl))))FROM rbu_count\x00cannot update wal mode database\x00vacuum\x00update\x00database modified during rbu %s\x00BEGIN IMMEDIATE\x00PRAGMA journal_mode=off\x00-vactmp\x00DELETE FROM stat.rbu_state\x00rbu/zipvfs setup error\x00rbu(%s)/%z\x00rbu_memory\x00/\x00overflow\x00%s%.3x+%.6x\x00%s%.3x/\x00internal\x00leaf\x00corrupted\x00SELECT * FROM (SELECT 'sqlite_schema' AS name,1 AS rootpage,'table' AS type UNION ALL SELECT name,rootpage,type FROM \"%w\".sqlite_schema WHERE rootpage!=0)\x00WHERE name=%Q\x00 ORDER BY name\x00dbstat\x00SELECT 0, 'tbl',  '', 0, '', 1     UNION ALL SELECT 1, 'idx',  '', 0, '', 2     UNION ALL SELECT 2, 'stat', '', 0, '', 0\x00PRAGMA '%q'.table_info('%q')\x00SELECT\x00%z%s\"%w\".\"%w\".\"%w\"=\"%w\".\"%w\".\"%w\"\x00%z%s\"%w\".\"%w\".\"%w\" IS NOT \"%w\".\"%w\".\"%w\"\x00 OR \x00_rowid_, *\x00SELECT %s FROM \"%w\".\"%w\" WHERE NOT EXISTS (  SELECT 1 FROM \"%w\".\"%w\" WHERE %s)\x00%z%s\"%w\".\"%w\".\"%w\"\x00SELECT %s,%s FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)\x00table schemas do not match\x00, 1\x00 AND (?6 OR ?3 IS stat)\x00tbl, idx\x00?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)\x00tbl, ?2, stat\x00?%d\x00 AND (?%d OR ?%d IS %w.%w)\x00SELECT %s%s FROM %Q.%Q WHERE (%s) IS (%s)\x00SAVEPOINT changeset\x00RELEASE changeset\x00UPDATE main.\x00 SET \x00 = ?\x00 WHERE \x00idx IS CASE WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL ELSE ?4 END \x00 IS ?\x00DELETE FROM main.\x00 AND (?\x00AND \x00INSERT INTO main.\x00) VALUES(?\x00, ?\x00INSERT INTO main.sqlite_stat1 VALUES(?1, CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, ?3)\x00DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END AND (?4 OR stat IS ?3)\x00SAVEPOINT replace_op\x00RELEASE replace_op\x00SAVEPOINT changeset_apply\x00PRAGMA defer_foreign_keys = 1\x00sqlite3changeset_apply(): no such table: %s\x00sqlite3changeset_apply(): table %s has %d columns, expected %d or more\x00sqlite3changeset_apply(): primary key mismatch for table %s\x00PRAGMA defer_foreign_keys = 0\x00RELEASE changeset_apply\x00ROLLBACK TO changeset_apply\x00fts5: parser stack overflow\x00fts5: syntax error near \"%.*s\"\x00%z%.*s\x00wrong number of arguments to function highlight()\x00wrong number of arguments to function snippet()\x00snippet\x00highlight\x00bm25\x00prefix\x00malformed prefix=... directive\x00too many prefix indexes (max %d)\x00prefix length out of range (max 999)\x00tokenize\x00multiple tokenize=... directives\x00parse error in tokenize directive\x00content\x00multiple content=... directives\x00%Q.%Q\x00contentless_delete\x00malformed contentless_delete=... directive\x00content_rowid\x00multiple content_rowid=... directives\x00columnsize\x00malformed columnsize=... directive\x00columns\x00malformed detail=... directive\x00tokendata\x00malformed tokendata=... directive\x00unrecognized option: \"%.*s\"\x00rank\x00reserved fts5 column name: %s\x00unindexed\x00unrecognized column option: %s\x00T.%Q\x00, T.%Q\x00, T.c%d\x00reserved fts5 table name: %s\x00parse error in \"%s\"\x00contentless_delete=1 requires a contentless table\x00contentless_delete=1 is incompatible with columnsize=0\x00docsize\x00%Q.'%q_%s'\x00CREATE TABLE x(\x00%z%s%Q\x00%z, %Q HIDDEN, %s HIDDEN)\x00pgsz\x00hashsize\x00automerge\x00usermerge\x00crisismerge\x00deletemerge\x00secure-delete\x00SELECT k, v FROM %Q.'%q_config'\x00version\x00invalid fts5 file format (found %d, expected %d or %d) - run 'rebuild'\x00unterminated string\x00fts5: syntax error near \"%.1s\"\x00OR\x00NOT\x00NEAR\x00expected integer, got \"%.*s\"\x00fts5: column queries are not supported (detail=none)\x00phrase\x00fts5: %s queries are not supported (detail!=full)\x00fts5 expression tree is too large (maximum depth %d)\x00block\x00REPLACE INTO '%q'.'%q_data'(id, block) VALUES(?,?)\x00DELETE FROM '%q'.'%q_data' WHERE id>=? AND id<=?\x00DELETE FROM '%q'.'%q_idx' WHERE segid=?\x00\xff\x00\x00\x01\x00PRAGMA %Q.data_version\x00SELECT pgno FROM '%q'.'%q_idx' WHERE segid=? AND term<=? ORDER BY term DESC LIMIT 1\x00SELECT pgno FROM '%q'.'%q_idx' WHERE segid=? AND term>? ORDER BY term ASC LIMIT 1\x00INSERT INTO '%q'.'%q_idx'(segid,term,pgno) VALUES(?,?,?)\x00DELETE FROM '%q'.'%q_idx' WHERE (segid, (pgno/2)) = (?1, ?2)\x00%s_data\x00id INTEGER PRIMARY KEY, block BLOB\x00segid, term, pgno, PRIMARY KEY(segid, term)\x00\x00\x00SELECT segid, term, (pgno>>1), (pgno&1) FROM %Q.'%q_idx' WHERE segid=%d ORDER BY 1, 2\x00\x00\x00\x00\x00\x00recursively defined fts5 content table\x00DESC\x00ASC\x00SELECT rowid, rank FROM %Q.%Q ORDER BY %s(\"%w\"%s%s) %s\x00reads\x00unknown special query: %.*s\x00SELECT %s\x00no such function: %s\x00parse error in rank function: %s\x00%s: table does not support scanning\x00delete-all\x00'delete-all' may only be used with a contentless or external content fts5 table\x00rebuild\x00'rebuild' may not be used with a contentless fts5 table\x00merge\x00integrity-check\x00flush\x00'delete' may not be used with a contentless_delete=1 table\x00DELETE from\x00cannot %s contentless fts5 table: %s\x00no such cursor: %lld\x00cannot UPDATE a subset of columns on fts5 contentless-delete table: %s\x00no such tokenizer: %s\x00error in tokenizer constructor\x00fts5_api_ptr\x00fts5: 2024-05-23 13:25:27 96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e\x00config\x00malformed inverted index for FTS5 table %s.%s\x00unable to validate the inverted index for FTS5 table %s.%s: %s\x00fts5\x00fts5_source_id\x00SELECT %s FROM %s T WHERE T.%Q >= ? AND T.%Q <= ? ORDER BY T.%Q ASC\x00SELECT %s FROM %s T WHERE T.%Q <= ? AND T.%Q >= ? ORDER BY T.%Q DESC\x00SELECT %s FROM %s T WHERE T.%Q=?\x00INSERT INTO %Q.'%q_content' VALUES(%s)\x00REPLACE INTO %Q.'%q_content' VALUES(%s)\x00DELETE FROM %Q.'%q_content' WHERE id=?\x00REPLACE INTO %Q.'%q_docsize' VALUES(?,?%s)\x00DELETE FROM %Q.'%q_docsize' WHERE id=?\x00SELECT sz%s FROM %Q.'%q_docsize' WHERE id=?\x00REPLACE INTO %Q.'%q_config' VALUES(?,?)\x00SELECT %s FROM %s AS T\x00,?\x00,origin\x00DROP TABLE IF EXISTS %Q.'%q_data';DROP TABLE IF EXISTS %Q.'%q_idx';DROP TABLE IF EXISTS %Q.'%q_config';\x00DROP TABLE IF EXISTS %Q.'%q_docsize';\x00DROP TABLE IF EXISTS %Q.'%q_content';\x00ALTER TABLE %Q.'%q_%s' RENAME TO '%q_%s';\x00CREATE TABLE %Q.'%q_%q'(%s)%s\x00fts5: error creating shadow table %q_%s: %s\x00id INTEGER PRIMARY KEY\x00, c%d\x00id INTEGER PRIMARY KEY, sz BLOB\x00id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER\x00k PRIMARY KEY, v\x00DELETE FROM %Q.'%q_data';DELETE FROM %Q.'%q_idx';\x00DELETE FROM %Q.'%q_docsize';\x00SELECT count(*) FROM %Q.'%q_%s'\x00tokenchars\x00separators\x00L* N* Co\x00categories\x00remove_diacritics\x00unicode61\x00al\x00ance\x00ence\x00er\x00ic\x00able\x00ible\x00ant\x00ement\x00ment\x00ent\x00ion\x00ou\x00ism\x00ate\x00iti\x00ous\x00ive\x00ize\x00at\x00bl\x00ble\x00iz\x00ational\x00tional\x00tion\x00enci\x00anci\x00izer\x00logi\x00bli\x00alli\x00entli\x00eli\x00e\x00ousli\x00ization\x00ation\x00ator\x00alism\x00iveness\x00fulness\x00ful\x00ousness\x00aliti\x00iviti\x00biliti\x00ical\x00ness\x00icate\x00iciti\x00ative\x00alize\x00eed\x00ee\x00ed\x00ing\x00case_sensitive\x00ascii\x00porter\x00trigram\x00col\x00row\x00instance\x00fts5vocab: unknown table type: %Q\x00CREATE TABlE vocab(term, col, doc, cnt)\x00CREATE TABlE vocab(term, doc, cnt)\x00CREATE TABlE vocab(term, doc, col, offset)\x00wrong number of vtable arguments\x00recursive definition for %s.%s\x00SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'\x00no such fts5 table: %s.%s\x00fts5vocab\x002024-05-23 13:25:27 96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e\x00"

type Sqlite3_int64 = sqlite3_int64
type Sqlite3_mutex_methods = sqlite3_mutex_methods
type Sqlite3_value = sqlite3_value

type Sqlite3_index_info = sqlite3_index_info
type Sqlite3_module = sqlite3_module
type Sqlite3_vtab = sqlite3_vtab
type Sqlite3_vtab_cursor = sqlite3_vtab_cursor
